From 35968aed1e24d1802ce5f555be74da1cafb8ce22 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 16:23:14 -0300 Subject: [PATCH 01/14] Complements js0 pr --- src/fusion/jsheaders.nim | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/fusion/jsheaders.nim diff --git a/src/fusion/jsheaders.nim b/src/fusion/jsheaders.nim new file mode 100644 index 00000000..4877937b --- /dev/null +++ b/src/fusion/jsheaders.nim @@ -0,0 +1,58 @@ +## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers +when not defined(js) and not defined(nimdoc): + {.fatal: "Module jsheaders is designed to be used with the JavaScript backend.".} + +type Headers* = ref object ## HTTP Headers for the JavaScript target. + +func newHeaders*(): Headers {.importjs: "new Headers()".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers + +func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: """ +(() => { + const header = new Headers(); + #.forEach((item) => header.append(item[0], item[1])); + return header; +})()""".} + ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. + +func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append + +func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete + +func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get + +func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has + +func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set + +func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys + +func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values + +func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries + +func clear*(this: Headers) {.importjs: """ +(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()""".} + ## Convenience func to delete all items from `Headers`. + + +runnableExamples: + if defined(nimJsHeadersTests): + var header = newHeaders() + header.append(r"key", r"value") + doAssert header.has(r"key") + doAssert header.keys() == @["key".cstring] + doAssert header.values() == @["value".cstring] + doAssert header.get(r"key") == "value".cstring + header.set(r"other", r"another") + doAssert header.get(r"other") == "another".cstring + doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] + header.delete(r"other") From 6443b2a4ebaf576bb9f4c74f3387dccbcff2b5ad Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 16:25:13 -0300 Subject: [PATCH 02/14] Bump changelol --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 7ceb6a55..1c4cfb90 100644 --- a/changelog.md +++ b/changelog.md @@ -7,3 +7,6 @@ convenience functions to change file permissions using Unix like octal file permissions. - Added module `scripting` providing `withDir` to switch the directory temporarily. This was previously only available in the `nimscript` module. + + +- Added `jsheaders` module for [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) for the JavaScript target. From d727d3a43b470f6e8806fe6b385d89d6ffc68b68 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 17:28:31 -0300 Subject: [PATCH 03/14] Copy stdlib and use a javascript dedicated folder --- src/fusion/js/jsheaders.nim | 53 +++++++++++++++++++++++++++++++++ src/fusion/jsheaders.nim | 58 ------------------------------------- 2 files changed, 53 insertions(+), 58 deletions(-) create mode 100644 src/fusion/js/jsheaders.nim delete mode 100644 src/fusion/jsheaders.nim diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim new file mode 100644 index 00000000..7974c4f7 --- /dev/null +++ b/src/fusion/js/jsheaders.nim @@ -0,0 +1,53 @@ +## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers +when defined(js): + type Headers* = ref object ## HTTP Headers for the JavaScript target. + + func newHeaders*(): Headers {.importjs: "new Headers()".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers + + func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: """( + () => { const header = new Headers(); #.forEach((item) => header.append(item[0], item[1])); return header })()""".} + ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. + + func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append + + func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete + + func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get + + func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has + + func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set + + func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys + + func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values + + func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries + + func clear*(this: Headers) {.importjs: "(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()".} + ## Convenience func to delete all items from `Headers`. + + + runnableExamples: + if defined(nimJsHeadersTests): + var header = newHeaders() + header.append(r"key", r"value") + doAssert header.has(r"key") + doAssert header.keys() == @["key".cstring] + doAssert header.values() == @["value".cstring] + doAssert header.get(r"key") == "value".cstring + header.set(r"other", r"another") + doAssert header.get(r"other") == "another".cstring + doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] + header.delete(r"other") +else: + {.warning: "Module jsheaders is designed to be used with the JavaScript backend.".} diff --git a/src/fusion/jsheaders.nim b/src/fusion/jsheaders.nim deleted file mode 100644 index 4877937b..00000000 --- a/src/fusion/jsheaders.nim +++ /dev/null @@ -1,58 +0,0 @@ -## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers -when not defined(js) and not defined(nimdoc): - {.fatal: "Module jsheaders is designed to be used with the JavaScript backend.".} - -type Headers* = ref object ## HTTP Headers for the JavaScript target. - -func newHeaders*(): Headers {.importjs: "new Headers()".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers - -func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: """ -(() => { - const header = new Headers(); - #.forEach((item) => header.append(item[0], item[1])); - return header; -})()""".} - ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. - -func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append - -func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete - -func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get - -func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has - -func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set - -func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys - -func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values - -func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries - -func clear*(this: Headers) {.importjs: """ -(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()""".} - ## Convenience func to delete all items from `Headers`. - - -runnableExamples: - if defined(nimJsHeadersTests): - var header = newHeaders() - header.append(r"key", r"value") - doAssert header.has(r"key") - doAssert header.keys() == @["key".cstring] - doAssert header.values() == @["value".cstring] - doAssert header.get(r"key") == "value".cstring - header.set(r"other", r"another") - doAssert header.get(r"other") == "another".cstring - doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] - header.delete(r"other") From 95d7193b604540c20c2c6b495d740e56bab37285 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 18:37:00 -0300 Subject: [PATCH 04/14] Fix doc --- src/fusion/js/jsheaders.nim | 79 +++++++++++++++++---------------- src/fusion/js/jsheaders.nim.cfg | 1 + 2 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 src/fusion/js/jsheaders.nim.cfg diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index 7974c4f7..7ac9fa55 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -1,53 +1,54 @@ ## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers -when defined(js): - type Headers* = ref object ## HTTP Headers for the JavaScript target. +when not defined(js) and not defined(nimdoc): + {.fatal: "Module jsfetch is designed to be used with the JavaScript backend.".} - func newHeaders*(): Headers {.importjs: "new Headers()".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers +type Headers* = ref object ## HTTP Headers for the JavaScript target. - func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: """( - () => { const header = new Headers(); #.forEach((item) => header.append(item[0], item[1])); return header })()""".} - ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. +func newHeaders*(): Headers {.importjs: "new Headers()".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers - func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append +func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: + "(() => { const header = new Headers(); #.forEach((item) => header.append(item[0], item[1])); return header })()".} + ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. - func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete +func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append - func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get +func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete - func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has +func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get - func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set +func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has - func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys +func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set - func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values +func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys - func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries +func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values - func clear*(this: Headers) {.importjs: "(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()".} - ## Convenience func to delete all items from `Headers`. +func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries +func clear*(this: Headers) {.importjs: + "(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()".} + ## Convenience func to delete all items from `Headers`. - runnableExamples: - if defined(nimJsHeadersTests): - var header = newHeaders() - header.append(r"key", r"value") - doAssert header.has(r"key") - doAssert header.keys() == @["key".cstring] - doAssert header.values() == @["value".cstring] - doAssert header.get(r"key") == "value".cstring - header.set(r"other", r"another") - doAssert header.get(r"other") == "another".cstring - doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] - header.delete(r"other") -else: - {.warning: "Module jsheaders is designed to be used with the JavaScript backend.".} + +runnableExamples: + if defined(nimJsHeadersTests): + var header = newHeaders() + header.append(r"key", r"value") + doAssert header.has(r"key") + doAssert header.keys() == @["key".cstring] + doAssert header.values() == @["value".cstring] + doAssert header.get(r"key") == "value".cstring + header.set(r"other", r"another") + doAssert header.get(r"other") == "another".cstring + doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] + header.delete(r"other") diff --git a/src/fusion/js/jsheaders.nim.cfg b/src/fusion/js/jsheaders.nim.cfg new file mode 100644 index 00000000..7fbff7c7 --- /dev/null +++ b/src/fusion/js/jsheaders.nim.cfg @@ -0,0 +1 @@ +--backend:js From 865b9f56c84eb57c1b5f7451ab65543134452c94 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 18:38:51 -0300 Subject: [PATCH 05/14] Fix doc --- src/fusion/js/jsheaders.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index 7ac9fa55..c1a9eb2c 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -1,6 +1,6 @@ ## - HTTP Headers for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/Headers when not defined(js) and not defined(nimdoc): - {.fatal: "Module jsfetch is designed to be used with the JavaScript backend.".} + {.fatal: "Module jsheaders is designed to be used with the JavaScript backend.".} type Headers* = ref object ## HTTP Headers for the JavaScript target. From f3cfdac2af84847895a44cb41f3b5fa0cc76f8e1 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 19:09:55 -0300 Subject: [PATCH 06/14] This should use testament instead :| --- src/fusion/docutils.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fusion/docutils.nim b/src/fusion/docutils.nim index 78bd1025..8032aa04 100644 --- a/src/fusion/docutils.nim +++ b/src/fusion/docutils.nim @@ -3,7 +3,7 @@ import std/private/globs iterator findNimSrcFiles*(dir: string): string = proc follow(a: PathEntry): bool = - a.path.lastPathPart notin ["nimcache", "htmldocs"] + a.path.lastPathPart notin ["nimcache", "htmldocs", "js"] for entry in walkDirRecFilter(dir, follow = follow): if entry.path.splitFile.ext == ".nim" and entry.kind == pcFile: yield entry.path From f58ab6b8d19eadcab79f91392663411f4624d702 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 14 Dec 2020 19:23:56 -0300 Subject: [PATCH 07/14] Clean out --- src/fusion/js/jsheaders.nim.cfg | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/fusion/js/jsheaders.nim.cfg diff --git a/src/fusion/js/jsheaders.nim.cfg b/src/fusion/js/jsheaders.nim.cfg deleted file mode 100644 index 7fbff7c7..00000000 --- a/src/fusion/js/jsheaders.nim.cfg +++ /dev/null @@ -1 +0,0 @@ ---backend:js From b531d34ce5d7e00f3500b48358acd377c4e81e9d Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Sat, 19 Dec 2020 04:21:16 -0300 Subject: [PATCH 08/14] moar fixes --- src/fusion/js/jsheaders.nim | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index c1a9eb2c..e76e890c 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -2,15 +2,11 @@ when not defined(js) and not defined(nimdoc): {.fatal: "Module jsheaders is designed to be used with the JavaScript backend.".} -type Headers* = ref object ## HTTP Headers for the JavaScript target. +type Headers* = ref object of JsRoot ## HTTP Headers for the JavaScript target. func newHeaders*(): Headers {.importjs: "new Headers()".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers -func newHeaders*(keyValuePairs: openArray[array[2, cstring]]): Headers {.importjs: - "(() => { const header = new Headers(); #.forEach((item) => header.append(item[0], item[1])); return header })()".} - ## Same as `newHeaders` but initializes `Headers` with `keyValuePairs`. - func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append @@ -41,8 +37,8 @@ func clear*(this: Headers) {.importjs: runnableExamples: - if defined(nimJsHeadersTests): - var header = newHeaders() + if defined(fusionJsHeadersTests): + let header = newHeaders() header.append(r"key", r"value") doAssert header.has(r"key") doAssert header.keys() == @["key".cstring] From a5fcb635c02406cbcb438fc031343998592f2b62 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Sat, 19 Dec 2020 04:27:07 -0300 Subject: [PATCH 09/14] moar fixes --- src/fusion/docutils.nim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/fusion/docutils.nim b/src/fusion/docutils.nim index 8032aa04..266bee98 100644 --- a/src/fusion/docutils.nim +++ b/src/fusion/docutils.nim @@ -1,19 +1,26 @@ -import std/[os,strformat,sugar,osproc] +import std/[os, strformat, sugar, osproc] import std/private/globs + iterator findNimSrcFiles*(dir: string): string = proc follow(a: PathEntry): bool = - a.path.lastPathPart notin ["nimcache", "htmldocs", "js"] + let dir = a.path.lastPathPart + if dir in ["nimcache", "htmldocs"]: return false + when not defined(js): return true + else: return dir != "js" + for entry in walkDirRecFilter(dir, follow = follow): if entry.path.splitFile.ext == ".nim" and entry.kind == pcFile: yield entry.path + proc genCodeImportAll*(dir: string): string = result = "{.warning[UnusedImport]: off.}\n" for a in findNimSrcFiles(dir): let s = "".dup(addQuoted(a)) result.add &"import {s}\n" + proc genDocs(dir: string, nim = "", args: seq[string]) = let code = genCodeImportAll(dir) let extra = quoteShellCommand(args) @@ -22,6 +29,7 @@ proc genDocs(dir: string, nim = "", args: seq[string]) = if ret.exitCode != 0: doAssert false, ret.output & "\n" & code + when isMainModule: let args = commandLineParams() doAssert args.len >= 1 From be2f5c3f7b39812af78c5b23448d9490a6078af5 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Sat, 19 Dec 2020 04:42:21 -0300 Subject: [PATCH 10/14] Error: importjs pragma requires the JavaScript target --- src/fusion/docutils.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fusion/docutils.nim b/src/fusion/docutils.nim index 266bee98..f7cf7bd1 100644 --- a/src/fusion/docutils.nim +++ b/src/fusion/docutils.nim @@ -2,12 +2,13 @@ import std/[os, strformat, sugar, osproc] import std/private/globs +const blockList = + when not defined(js): ["nimcache", "htmldocs", "js"] + else: ["nimcache", "htmldocs"] + iterator findNimSrcFiles*(dir: string): string = proc follow(a: PathEntry): bool = - let dir = a.path.lastPathPart - if dir in ["nimcache", "htmldocs"]: return false - when not defined(js): return true - else: return dir != "js" + a.path.lastPathPart notin blockList for entry in walkDirRecFilter(dir, follow = follow): if entry.path.splitFile.ext == ".nim" and entry.kind == pcFile: From 0f50584a76f35c8ed0dc07193ab7eda06ed9c267 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Sat, 19 Dec 2020 18:48:24 -0300 Subject: [PATCH 11/14] https://github.com/nim-lang/fusion/pull/56#discussion_r546265516 --- src/fusion/js/jsheaders.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index e76e890c..f5303d6c 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -48,3 +48,4 @@ runnableExamples: doAssert header.get(r"other") == "another".cstring doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] header.delete(r"other") + doAssert header.entries() == @[] From cb763ca17c3a2962bce81b7ee047f1e65210314f Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 21 Dec 2020 06:38:11 -0300 Subject: [PATCH 12/14] https://github.com/nim-lang/fusion/pull/56#discussion_r546586774 --- src/fusion/js/jsheaders.nim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index f5303d6c..24b274a1 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -7,30 +7,30 @@ type Headers* = ref object of JsRoot ## HTTP Headers for the JavaScript target. func newHeaders*(): Headers {.importjs: "new Headers()".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers -func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} +func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.$1(#, #)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append -func delete*(this: Headers; key: cstring) {.importjs: "#.delete(#)".} +func delete*(this: Headers; key: cstring) {.importjs: "#.$1(#)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete -func get*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get - -func has*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} +func has*(this: Headers; key: cstring): bool {.importjs: "#.$1(#)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has -func set*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} - ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set - -func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.keys())".} +func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.$1())".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys -func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.values())".} +func values*(this: Headers): seq[cstring] {.importjs: "Array.from(#.$1())".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/values -func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.entries())".} +func entries*(this: Headers): seq[array[2, cstring]] {.importjs: "Array.from(#.$1())".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries +func `[]`*(this: Headers; key: cstring): cstring {.importjs: "#.get(#)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/get + +func `[]=`*(this: Headers; key: cstring; value: cstring) {.importjs: "#.set(#, #)".} + ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/set + func clear*(this: Headers) {.importjs: "(() => { const header = #; Array.from(header.keys()).forEach((key) => header.delete(key)) })()".} ## Convenience func to delete all items from `Headers`. @@ -43,9 +43,9 @@ runnableExamples: doAssert header.has(r"key") doAssert header.keys() == @["key".cstring] doAssert header.values() == @["value".cstring] - doAssert header.get(r"key") == "value".cstring - header.set(r"other", r"another") - doAssert header.get(r"other") == "another".cstring + doAssert header[r"key"] == "value".cstring + header[r"other"] = r"another" + doAssert header[r"other"] == "another".cstring doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] header.delete(r"other") doAssert header.entries() == @[] From 7bde43d9ba03e08e9933daeb60706eb20df2b808 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Mon, 21 Dec 2020 06:52:47 -0300 Subject: [PATCH 13/14] Use to prevent Tipos --- src/fusion/js/jsheaders.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index 24b274a1..d83c00dd 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -7,13 +7,13 @@ type Headers* = ref object of JsRoot ## HTTP Headers for the JavaScript target. func newHeaders*(): Headers {.importjs: "new Headers()".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers -func append*(this: Headers; key: cstring; value: cstring) {.importjs: "#.$1(#, #)".} +func add*(this: Headers; key: cstring; value: cstring) {.importjs: "#.append(#, #)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/append func delete*(this: Headers; key: cstring) {.importjs: "#.$1(#)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete -func has*(this: Headers; key: cstring): bool {.importjs: "#.$1(#)".} +func hasKey*(this: Headers; key: cstring): bool {.importjs: "#.has(#)".} ## https://developer.mozilla.org/en-US/docs/Web/API/Headers/has func keys*(this: Headers): seq[cstring] {.importjs: "Array.from(#.$1())".} @@ -39,8 +39,8 @@ func clear*(this: Headers) {.importjs: runnableExamples: if defined(fusionJsHeadersTests): let header = newHeaders() - header.append(r"key", r"value") - doAssert header.has(r"key") + header.add(r"key", r"value") + doAssert header.hasKey(r"key") doAssert header.keys() == @["key".cstring] doAssert header.values() == @["value".cstring] doAssert header[r"key"] == "value".cstring From 494db08ce137dcb862ace6607f490073a2d072b3 Mon Sep 17 00:00:00 2001 From: Juan Carlos Date: Sat, 26 Dec 2020 16:25:58 -0300 Subject: [PATCH 14/14] Fixes --- src/fusion/js/jsheaders.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fusion/js/jsheaders.nim b/src/fusion/js/jsheaders.nim index d83c00dd..203489c5 100644 --- a/src/fusion/js/jsheaders.nim +++ b/src/fusion/js/jsheaders.nim @@ -39,13 +39,13 @@ func clear*(this: Headers) {.importjs: runnableExamples: if defined(fusionJsHeadersTests): let header = newHeaders() - header.add(r"key", r"value") - doAssert header.hasKey(r"key") + header.add("key", "value") + doAssert header.hasKey("key") doAssert header.keys() == @["key".cstring] doAssert header.values() == @["value".cstring] - doAssert header[r"key"] == "value".cstring - header[r"other"] = r"another" - doAssert header[r"other"] == "another".cstring + doAssert header["key"] == "value".cstring + header["other"] = "another".cstring + doAssert header["other"] == "another".cstring doAssert header.entries() == @[["key".cstring, "value"], ["other".cstring, "another"]] - header.delete(r"other") + header.delete("other") doAssert header.entries() == @[]