@weborigami/origami 0.0.73 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/main.js +12 -0
  2. package/package.json +5 -7
  3. package/src/builtins.js +62 -0
  4. package/src/builtinsTree.js +36 -0
  5. package/src/calc/calc.js +71 -0
  6. package/src/cli/cli.js +6 -4
  7. package/src/{misc → common}/assertTreeIsDefined.js +4 -1
  8. package/src/common/constructHref.js +20 -0
  9. package/src/common/constructSiteTree.js +34 -0
  10. package/src/common/fetchAndHandleExtension.js +26 -0
  11. package/src/{misc → common}/getTreeArgument.js +11 -5
  12. package/src/common/processUnpackedContent.js +4 -13
  13. package/src/common/utilities.d.ts +1 -2
  14. package/src/common/utilities.js +24 -31
  15. package/src/deprecated.js +140 -0
  16. package/src/{common → dev}/ExplorableSiteTransform.js +1 -1
  17. package/src/{misc → dev}/OriCommandTransform.js +2 -2
  18. package/src/{builtins/@code.js → dev/code.js} +2 -2
  19. package/src/{builtins/@debug.js → dev/debug.js} +4 -7
  20. package/src/dev/dev.js +9 -0
  21. package/src/{builtins/@explore.js → dev/explore.js} +24 -30
  22. package/src/{misc → dev}/explore.js.inline +4 -4
  23. package/src/{misc → dev}/explore.ori +4 -4
  24. package/src/{builtins/@log.js → dev/log.js} +1 -1
  25. package/src/{builtins/@serve.js → dev/serve.js} +5 -8
  26. package/src/{builtins/@svg.js → dev/svg.js} +9 -6
  27. package/src/{misc → dev}/treeDot.js +2 -5
  28. package/src/{builtins/@watch.js → dev/watch.js} +8 -6
  29. package/src/handlers/handlerExports.js +16 -0
  30. package/src/handlers/handlers.js +37 -0
  31. package/src/{builtins → handlers}/js.handler.js +1 -1
  32. package/src/{builtins → handlers}/json.handler.js +9 -1
  33. package/src/handlers/mjs.handler.js +2 -0
  34. package/src/{builtins → handlers}/ori.handler.js +5 -7
  35. package/src/{builtins → handlers}/oridocument.handler.js +1 -1
  36. package/src/{builtins → handlers}/wasm.handler.js +1 -1
  37. package/src/{builtins → handlers}/yaml.handler.js +8 -1
  38. package/src/handlers/yml.handler.js +2 -0
  39. package/src/help/help.js +103 -0
  40. package/src/help/help.yaml +428 -0
  41. package/src/{builtins/@image → image}/format.js +2 -2
  42. package/src/{builtins/@image → image}/formatFn.js +1 -1
  43. package/src/image/image.js +2 -0
  44. package/src/{builtins/@image → image}/resize.js +2 -2
  45. package/src/{builtins/@image → image}/resizeFn.js +1 -1
  46. package/src/internal.js +24 -0
  47. package/src/{builtins/@js.js → js.js} +7 -6
  48. package/src/{builtins/@node.js → node.js} +1 -6
  49. package/src/{builtins/@basename.js → origami/basename.js} +2 -2
  50. package/src/{builtins/@config.js → origami/config.js} +1 -4
  51. package/src/{builtins/@json.js → origami/json.js} +2 -5
  52. package/src/{builtins/@jsonParse.js → origami/jsonParse.js} +0 -3
  53. package/src/{builtins/@once.js → origami/once.js} +2 -2
  54. package/src/{builtins/@ori.js → origami/ori.js} +4 -7
  55. package/src/origami/origami.js +29 -0
  56. package/src/{builtins/@pack.js → origami/pack.js} +2 -2
  57. package/src/{builtins/@project.js → origami/project.js} +7 -11
  58. package/src/{builtins/@regexMatch.js → origami/regexMatch.js} +1 -1
  59. package/src/origami/repeat.js +5 -0
  60. package/src/{builtins/@shell.js → origami/shell.js} +0 -3
  61. package/src/{builtins/@stdin.js → origami/stdin.js} +0 -3
  62. package/src/{builtins/@string.js → origami/string.js} +2 -2
  63. package/src/{builtins/@unpack.js → origami/unpack.js} +2 -2
  64. package/src/{builtins/@yaml.js → origami/yaml.js} +2 -5
  65. package/src/{builtins/@yamlParse.js → origami/yamlParse.js} +0 -3
  66. package/src/protocols/explore.js +19 -0
  67. package/src/{builtins/@files.js → protocols/files.js} +2 -5
  68. package/src/protocols/http.js +18 -0
  69. package/src/protocols/https.js +18 -0
  70. package/src/protocols/httpstree.js +19 -0
  71. package/src/protocols/httptree.js +19 -0
  72. package/src/protocols/inherited.js +18 -0
  73. package/src/protocols/new.js +42 -0
  74. package/src/{builtins/@package.js → protocols/package.js} +32 -10
  75. package/src/protocols/scope.js +24 -0
  76. package/src/server/constructResponse.js +5 -5
  77. package/src/{builtins/@siteAudit.js → site/audit.js} +4 -4
  78. package/src/{builtins/@crawl.js → site/crawler/crawl.js} +3 -6
  79. package/src/{crawler → site/crawler}/findPaths.js +2 -3
  80. package/src/{crawler → site/crawler}/utilities.js +2 -3
  81. package/src/{builtins/@index.js → site/index.js} +4 -7
  82. package/src/{builtins/@jsonKeys.js → site/jsonKeys.js} +5 -5
  83. package/src/{builtins/@rss.js → site/rss.js} +2 -5
  84. package/src/site/site.js +9 -0
  85. package/src/{builtins/@sitemap.js → site/sitemap.js} +8 -12
  86. package/src/{builtins/@static.js → site/static.js} +7 -7
  87. package/src/{builtins/@document.js → text/document.js} +2 -2
  88. package/src/{builtins/@inline.js → text/inline.js} +10 -13
  89. package/src/{builtins/@mdHtml.js → text/mdHtml.js} +7 -10
  90. package/src/text/origamiHighlightDefinition.js +57 -0
  91. package/src/text/text.js +4 -0
  92. package/src/{builtins/@addNextPrevious.js → tree/addNextPrevious.js} +7 -2
  93. package/src/{builtins/@cache.js → tree/cache.js} +2 -5
  94. package/src/{builtins/@clean.js → tree/clear.js} +4 -4
  95. package/src/{builtins/@concat.js → tree/concat.js} +2 -5
  96. package/src/{builtins/@copy.js → tree/copy.js} +3 -10
  97. package/src/{builtins/@deepMapFn.js → tree/deepMap.js} +13 -6
  98. package/src/{builtins/@deepMerge.js → tree/deepMerge.js} +4 -7
  99. package/src/{builtins/@deepReverse.js → tree/deepReverse.js} +8 -2
  100. package/src/tree/deepTake.js +26 -0
  101. package/src/{builtins/@deepValues.js → tree/deepValues.js} +2 -6
  102. package/src/{builtins/@defineds.js → tree/defineds.js} +7 -2
  103. package/src/{builtins/@filter.js → tree/filter.js} +3 -6
  104. package/src/{builtins/@first.js → tree/first.js} +2 -5
  105. package/src/{builtins/@fnTree.js → tree/fromFn.js} +3 -6
  106. package/src/{builtins/@globs.js → tree/globs.js} +3 -6
  107. package/src/tree/group.js +26 -0
  108. package/src/{builtins/@inners.js → tree/inners.js} +2 -5
  109. package/src/{builtins/@keys.js → tree/keys.js} +2 -5
  110. package/src/{builtins/@length.js → tree/length.js} +2 -2
  111. package/src/{builtins → tree}/map.d.ts +3 -6
  112. package/src/tree/map.js +154 -0
  113. package/src/{builtins/@mapFn.js → tree/mapFn.js} +14 -6
  114. package/src/{builtins/@match.js → tree/match.js} +2 -5
  115. package/src/{builtins/@merge.js → tree/merge.js} +2 -5
  116. package/src/tree/paginate.js +61 -0
  117. package/src/{builtins/@parent.js → tree/parent.js} +2 -5
  118. package/src/{builtins/@plain.js → tree/plain.js} +2 -5
  119. package/src/{builtins/@reverse.js → tree/reverse.js} +2 -5
  120. package/src/{builtins/@setDeep.js → tree/setDeep.js} +0 -3
  121. package/src/{builtins/@shuffle.js → tree/shuffle.js} +3 -9
  122. package/src/{builtins/@sortFn.js → tree/sort.js} +12 -17
  123. package/src/tree/take.js +19 -0
  124. package/src/tree/tree.js +50 -0
  125. package/src/{builtins/@values.js → tree/values.js} +2 -5
  126. package/exports/PathTransform.d.ts +0 -5
  127. package/exports/PathTransform.js +0 -20
  128. package/exports/buildExports.js +0 -112
  129. package/exports/exports.js +0 -148
  130. package/src/builtins/@builtins.js +0 -15
  131. package/src/builtins/@deepMap.js +0 -19
  132. package/src/builtins/@deepTake.js +0 -21
  133. package/src/builtins/@deepTakeFn.js +0 -21
  134. package/src/builtins/@equals.js +0 -6
  135. package/src/builtins/@exploreSite.js +0 -16
  136. package/src/builtins/@false.js +0 -1
  137. package/src/builtins/@fetch.js +0 -7
  138. package/src/builtins/@group.js +0 -20
  139. package/src/builtins/@groupFn.js +0 -33
  140. package/src/builtins/@help.js +0 -49
  141. package/src/builtins/@http.js +0 -19
  142. package/src/builtins/@https.js +0 -19
  143. package/src/builtins/@if.js +0 -28
  144. package/src/builtins/@inherited.js +0 -17
  145. package/src/builtins/@map.js +0 -19
  146. package/src/builtins/@math.js +0 -17
  147. package/src/builtins/@not.js +0 -6
  148. package/src/builtins/@or.js +0 -6
  149. package/src/builtins/@paginate.js +0 -18
  150. package/src/builtins/@paginateFn.js +0 -58
  151. package/src/builtins/@repeat.js +0 -8
  152. package/src/builtins/@sort.js +0 -23
  153. package/src/builtins/@table.js +0 -69
  154. package/src/builtins/@take.js +0 -20
  155. package/src/builtins/@takeFn.js +0 -20
  156. package/src/builtins/@tree.js +0 -4
  157. package/src/builtins/@treeHttp.js +0 -19
  158. package/src/builtins/@treeHttps.js +0 -19
  159. package/src/builtins/@true.js +0 -1
  160. package/src/builtins/mjs.handler.js +0 -2
  161. package/src/builtins/yml.handler.js +0 -2
  162. package/src/builtins/~.js +0 -9
  163. package/src/cli/showUsage.js +0 -86
  164. package/src/common/CommandModulesTransform.d.ts +0 -5
  165. package/src/common/CommandModulesTransform.js +0 -39
  166. package/src/common/arrowsMapFn.js +0 -35
  167. package/src/misc/origamiHighlightDefinition.js +0 -36
  168. /package/src/{misc → common}/assertTreeIsDefined.d.ts +0 -0
  169. /package/src/{common → dev}/ExplorableSiteTransform.d.ts +0 -0
  170. /package/src/{misc → dev}/OriCommandTransform.d.ts +0 -0
  171. /package/src/{builtins/@breakpoint.js → dev/breakpoint.js} +0 -0
  172. /package/src/{builtins/@changes.js → dev/changes.js} +0 -0
  173. /package/src/{misc → dev}/explore.css +0 -0
  174. /package/src/{builtins → handlers}/css.handler.js +0 -0
  175. /package/src/{builtins → handlers}/htm.handler.js +0 -0
  176. /package/src/{builtins → handlers}/html.handler.js +0 -0
  177. /package/src/{builtins → handlers}/jpeg.handler.js +0 -0
  178. /package/src/{builtins → handlers}/jpg.handler.js +0 -0
  179. /package/src/{builtins → handlers}/md.handler.js +0 -0
  180. /package/src/{builtins → handlers}/txt.handler.js +0 -0
  181. /package/src/{builtins → handlers}/xhtml.handler.js +0 -0
  182. /package/src/{builtins/@naturalOrder.js → origami/naturalOrder.js} +0 -0
  183. /package/src/{builtins/@post.js → origami/post.js} +0 -0
  184. /package/src/{builtins/@regexMatchFn.js → origami/regexMatchFn.js} +0 -0
  185. /package/src/{builtins/@slash.js → origami/slash.js} +0 -0
  186. /package/src/{builtins/@version.js → origami/version.js} +0 -0
  187. /package/src/{crawler → site/crawler}/crawlResources.js +0 -0
  188. /package/src/{builtins/@redirect.js → site/redirect.js} +0 -0
  189. /package/src/{builtins/@slug.js → site/slug.js} +0 -0
  190. /package/src/{builtins/@indent.js → text/indent.js} +0 -0
  191. /package/src/{common → tree}/FilterTree.js +0 -0
  192. /package/src/{common → tree}/GlobTree.js +0 -0
  193. /package/src/{common → tree}/ShuffleTransform.js +0 -0
  194. /package/src/{builtins/@calendarTree.js → tree/calendar.js} +0 -0
@@ -1,112 +0,0 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
- import {
3
- keyFunctionsForExtensions,
4
- map,
5
- toString,
6
- } from "@weborigami/async-tree";
7
- import fileTypeOrigami from "../src/builtins/ori.handler.js";
8
- import { transformObject } from "../src/common/utilities.js";
9
- import PathTransform from "./PathTransform.js";
10
-
11
- // For builtins that should be renamed or not exported
12
- const specialBuiltinNames = {
13
- constructor: null,
14
- false: null,
15
- true: null,
16
- };
17
-
18
- // Top-level template for the export file
19
- const templateText = `=\`// This file is generated by running buildExports.js -- do not edit by hand.
20
- \${ _ }\``;
21
-
22
- // Generate a top-level export file for the entire project. For each .js file in
23
- // the given source tree, generate an appropriate statement that includes that
24
- // file's export(s) in the top-level export file.
25
- export default async function exportFile(src) {
26
- const statements = await exportStatements(src);
27
- const templateFn = await fileTypeOrigami.unpack(templateText);
28
- const result = await templateFn(statements);
29
- return result;
30
- }
31
-
32
- /**
33
- * Given a buffer containing the code for a JavaScript file, generate an
34
- * appropriate export statement for that file.
35
- *
36
- * @this {AsyncTree}
37
- */
38
- async function exportStatementForCode(codeBuffer, key) {
39
- const code = toString(codeBuffer);
40
-
41
- const exportsAnything = code.match(/^export /m);
42
- if (!exportsAnything) {
43
- // Has no exports
44
- return "";
45
- }
46
-
47
- // @ts-ignore
48
- const path = codeBuffer[PathTransform.pathKey] ?? "";
49
-
50
- const exportsDefault =
51
- code.match(/^export default /m) || code.match(/^export { default } /m);
52
- if (!exportsDefault) {
53
- // Export everything.
54
- return `export * from "../src/${path}";\n`;
55
- }
56
-
57
- // Single export
58
-
59
- // We construct an identifier for the export based on the path to the file and
60
- // the file name. This omits the first part of the path, which is the name of
61
- // a folder that's a direct child of the `src` folder. We omit the `.js`
62
- // extension, and remove any characters that aren't valid in JS identifiers.
63
- // We use camelCase to combine the parts. As an example, the file inside the
64
- // src folder at `builtins/@image/format.js` will be identified as
65
- // `imageFormat`.
66
-
67
- // Split the name into parts wherever there are characters that can't be in
68
- // JavaScript identifiers; drop any empty parts.
69
- const parts = path.split(/[^a-zA-Z0-9]/g).filter(Boolean);
70
-
71
- // Drop the first (folder) part and the last (`.js`) part.
72
- parts.shift();
73
- parts.pop();
74
-
75
- // Join the parts in camelCase to form the identifier.
76
- let identifier = parts
77
- .map((part, index) =>
78
- index === 0 ? part : part[0].toUpperCase() + part.slice(1)
79
- )
80
- .join("");
81
-
82
- if (!identifier) {
83
- // Name is entirely non-JS characters, like `~`. For now we ignore it.
84
- return "";
85
- }
86
-
87
- // Ignore certain builtins like `@true` and `@false` that would conflict with
88
- // JavaScript keywords. Developers can use those JavaScript keywords directly.
89
- const specialName = specialBuiltinNames[identifier];
90
- if (specialName === null) {
91
- return "";
92
- }
93
- if (specialName) {
94
- identifier = specialName;
95
- }
96
-
97
- return `export { default as ${identifier} } from "../src/${path}";\n`;
98
- }
99
-
100
- function exportStatements(src) {
101
- // Add paths to the source tree so they can be used in the export statements.
102
- const withPaths = transformObject(PathTransform, src);
103
-
104
- // Map each source file to an export statement.
105
- const mapped = map(withPaths, {
106
- deep: true,
107
- value: exportStatementForCode,
108
- ...keyFunctionsForExtensions({ sourceExtension: "js" }),
109
- });
110
-
111
- return mapped;
112
- }
@@ -1,148 +0,0 @@
1
- // This file is generated by running buildExports.js -- do not edit by hand.
2
- export { default as addNextPrevious } from "../src/builtins/@addNextPrevious.js";
3
- export { default as basename } from "../src/builtins/@basename.js";
4
- export { default as breakpoint } from "../src/builtins/@breakpoint.js";
5
- export { default as builtins } from "../src/builtins/@builtins.js";
6
- export { default as cache } from "../src/builtins/@cache.js";
7
- export * from "../src/builtins/@calendarTree.js";
8
- export { default as changes } from "../src/builtins/@changes.js";
9
- export { default as clean } from "../src/builtins/@clean.js";
10
- export { default as code } from "../src/builtins/@code.js";
11
- export { default as concat } from "../src/builtins/@concat.js";
12
- export { default as config } from "../src/builtins/@config.js";
13
- export { default as copy } from "../src/builtins/@copy.js";
14
- export { default as crawl } from "../src/builtins/@crawl.js";
15
- export { default as debug } from "../src/builtins/@debug.js";
16
- export { default as deepMap } from "../src/builtins/@deepMap.js";
17
- export { default as deepMapFn } from "../src/builtins/@deepMapFn.js";
18
- export { default as deepMerge } from "../src/builtins/@deepMerge.js";
19
- export { default as deepReverse } from "../src/builtins/@deepReverse.js";
20
- export { default as deepTake } from "../src/builtins/@deepTake.js";
21
- export { default as deepTakeFn } from "../src/builtins/@deepTakeFn.js";
22
- export { default as deepValues } from "../src/builtins/@deepValues.js";
23
- export { default as defineds } from "../src/builtins/@defineds.js";
24
- export { default as document } from "../src/builtins/@document.js";
25
- export { default as equals } from "../src/builtins/@equals.js";
26
- export { default as explore } from "../src/builtins/@explore.js";
27
- export { default as exploreSite } from "../src/builtins/@exploreSite.js";
28
- export { default as fetch } from "../src/builtins/@fetch.js";
29
- export { default as files } from "../src/builtins/@files.js";
30
- export { default as filter } from "../src/builtins/@filter.js";
31
- export { default as first } from "../src/builtins/@first.js";
32
- export { default as fnTree } from "../src/builtins/@fnTree.js";
33
- export { default as globs } from "../src/builtins/@globs.js";
34
- export { default as group } from "../src/builtins/@group.js";
35
- export { default as groupFn } from "../src/builtins/@groupFn.js";
36
- export { default as help } from "../src/builtins/@help.js";
37
- export { default as http } from "../src/builtins/@http.js";
38
- export { default as https } from "../src/builtins/@https.js";
39
- export { default as if } from "../src/builtins/@if.js";
40
- export { default as imageFormat } from "../src/builtins/@image/format.js";
41
- export { default as imageFormatFn } from "../src/builtins/@image/formatFn.js";
42
- export { default as imageResize } from "../src/builtins/@image/resize.js";
43
- export { default as imageResizeFn } from "../src/builtins/@image/resizeFn.js";
44
- export { default as indent } from "../src/builtins/@indent.js";
45
- export { default as index } from "../src/builtins/@index.js";
46
- export { default as inherited } from "../src/builtins/@inherited.js";
47
- export { default as inline } from "../src/builtins/@inline.js";
48
- export { default as inners } from "../src/builtins/@inners.js";
49
- export { default as js } from "../src/builtins/@js.js";
50
- export { default as json } from "../src/builtins/@json.js";
51
- export { default as jsonKeys } from "../src/builtins/@jsonKeys.js";
52
- export { default as jsonParse } from "../src/builtins/@jsonParse.js";
53
- export { default as keys } from "../src/builtins/@keys.js";
54
- export { default as length } from "../src/builtins/@length.js";
55
- export { default as log } from "../src/builtins/@log.js";
56
- export { default as map } from "../src/builtins/@map.js";
57
- export { default as mapFn } from "../src/builtins/@mapFn.js";
58
- export { default as match } from "../src/builtins/@match.js";
59
- export * from "../src/builtins/@math.js";
60
- export { default as mdHtml } from "../src/builtins/@mdHtml.js";
61
- export { default as merge } from "../src/builtins/@merge.js";
62
- export * from "../src/builtins/@naturalOrder.js";
63
- export { default as node } from "../src/builtins/@node.js";
64
- export { default as not } from "../src/builtins/@not.js";
65
- export { default as once } from "../src/builtins/@once.js";
66
- export { default as or } from "../src/builtins/@or.js";
67
- export { default as ori } from "../src/builtins/@ori.js";
68
- export { default as pack } from "../src/builtins/@pack.js";
69
- export { default as package } from "../src/builtins/@package.js";
70
- export { default as paginate } from "../src/builtins/@paginate.js";
71
- export { default as paginateFn } from "../src/builtins/@paginateFn.js";
72
- export { default as parent } from "../src/builtins/@parent.js";
73
- export { default as plain } from "../src/builtins/@plain.js";
74
- export { default as post } from "../src/builtins/@post.js";
75
- export { default as project } from "../src/builtins/@project.js";
76
- export { default as redirect } from "../src/builtins/@redirect.js";
77
- export { default as regexMatch } from "../src/builtins/@regexMatch.js";
78
- export { default as regexMatchFn } from "../src/builtins/@regexMatchFn.js";
79
- export { default as repeat } from "../src/builtins/@repeat.js";
80
- export { default as reverse } from "../src/builtins/@reverse.js";
81
- export { default as rss } from "../src/builtins/@rss.js";
82
- export { default as serve } from "../src/builtins/@serve.js";
83
- export { default as setDeep } from "../src/builtins/@setDeep.js";
84
- export { default as shell } from "../src/builtins/@shell.js";
85
- export { default as shuffle } from "../src/builtins/@shuffle.js";
86
- export { default as siteAudit } from "../src/builtins/@siteAudit.js";
87
- export { default as sitemap } from "../src/builtins/@sitemap.js";
88
- export * from "../src/builtins/@slash.js";
89
- export { default as slug } from "../src/builtins/@slug.js";
90
- export { default as sort } from "../src/builtins/@sort.js";
91
- export { default as sortFn } from "../src/builtins/@sortFn.js";
92
- export { default as static } from "../src/builtins/@static.js";
93
- export { default as stdin } from "../src/builtins/@stdin.js";
94
- export { default as string } from "../src/builtins/@string.js";
95
- export { default as svg } from "../src/builtins/@svg.js";
96
- export { default as table } from "../src/builtins/@table.js";
97
- export { default as take } from "../src/builtins/@take.js";
98
- export { default as takeFn } from "../src/builtins/@takeFn.js";
99
- export * from "../src/builtins/@tree.js";
100
- export { default as treeHttp } from "../src/builtins/@treeHttp.js";
101
- export { default as treeHttps } from "../src/builtins/@treeHttps.js";
102
- export { default as unpack } from "../src/builtins/@unpack.js";
103
- export { default as values } from "../src/builtins/@values.js";
104
- export { default as version } from "../src/builtins/@version.js";
105
- export { default as watch } from "../src/builtins/@watch.js";
106
- export { default as yaml } from "../src/builtins/@yaml.js";
107
- export { default as yamlParse } from "../src/builtins/@yamlParse.js";
108
- export { default as cssHandler } from "../src/builtins/css.handler.js";
109
- export { default as htmHandler } from "../src/builtins/htm.handler.js";
110
- export { default as htmlHandler } from "../src/builtins/html.handler.js";
111
- export { default as jpegHandler } from "../src/builtins/jpeg.handler.js";
112
- export { default as jpgHandler } from "../src/builtins/jpg.handler.js";
113
- export { default as jsHandler } from "../src/builtins/js.handler.js";
114
- export { default as jsonHandler } from "../src/builtins/json.handler.js";
115
- export { default as mdHandler } from "../src/builtins/md.handler.js";
116
- export { default as mjsHandler } from "../src/builtins/mjs.handler.js";
117
- export { default as oriHandler } from "../src/builtins/ori.handler.js";
118
- export { default as oridocumentHandler } from "../src/builtins/oridocument.handler.js";
119
- export { default as txtHandler } from "../src/builtins/txt.handler.js";
120
- export { default as wasmHandler } from "../src/builtins/wasm.handler.js";
121
- export { default as xhtmlHandler } from "../src/builtins/xhtml.handler.js";
122
- export { default as yamlHandler } from "../src/builtins/yaml.handler.js";
123
- export { default as ymlHandler } from "../src/builtins/yml.handler.js";
124
- export { default as defaultModuleExport } from "../src/cli/defaultModuleExport.js";
125
- export { default as showUsage } from "../src/cli/showUsage.js";
126
- export { default as arrowsMapFn } from "../src/common/arrowsMapFn.js";
127
- export { default as CommandModulesTransform } from "../src/common/CommandModulesTransform.js";
128
- export { default as ConstantTree } from "../src/common/ConstantTree.js";
129
- export { default as documentObject } from "../src/common/documentObject.js";
130
- export { default as ExplorableSiteTransform } from "../src/common/ExplorableSiteTransform.js";
131
- export { default as FilterTree } from "../src/common/FilterTree.js";
132
- export { default as GlobTree } from "../src/common/GlobTree.js";
133
- export { default as processUnpackedContent } from "../src/common/processUnpackedContent.js";
134
- export * from "../src/common/serialize.js";
135
- export { default as ShuffleTransform } from "../src/common/ShuffleTransform.js";
136
- export * from "../src/common/utilities.js";
137
- export { default as crawlResources } from "../src/crawler/crawlResources.js";
138
- export { default as findPaths } from "../src/crawler/findPaths.js";
139
- export * from "../src/crawler/utilities.js";
140
- export { default as assertTreeIsDefined } from "../src/misc/assertTreeIsDefined.js";
141
- export { default as getTreeArgument } from "../src/misc/getTreeArgument.js";
142
- export { default as OriCommandTransform } from "../src/misc/OriCommandTransform.js";
143
- export { default as origamiHighlightDefinition } from "../src/misc/origamiHighlightDefinition.js";
144
- export { default as treeDot } from "../src/misc/treeDot.js";
145
- export { default as constructResponse } from "../src/server/constructResponse.js";
146
- export * from "../src/server/mediaTypes.js";
147
- export { default as parsePostData } from "../src/server/parsePostData.js";
148
- export * from "../src/server/server.js";
@@ -1,15 +0,0 @@
1
- import { FileTree } from "@weborigami/async-tree";
2
- import { ImportModulesMixin } from "@weborigami/language";
3
- import CommandModulesTransform from "../common/CommandModulesTransform.js";
4
-
5
- const commandsUrl = new URL("../builtins", import.meta.url);
6
-
7
- /** @type {any} */
8
- const builtins = new (CommandModulesTransform(ImportModulesMixin(FileTree)))(
9
- commandsUrl
10
- );
11
-
12
- builtins.usage = `@builtins\tThe Tree Origami built-in functions`;
13
- builtins.documentation = "https://weborigami.org/language/@builtins.html";
14
-
15
- export default builtins;
@@ -1,19 +0,0 @@
1
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
2
- import deepMapFn from "./@deepMapFn.js";
3
-
4
- /**
5
- * Shorthand for calling `@map` with `deep: true` option.
6
- *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
9
- * @typedef {import("@weborigami/async-tree").ValueKeyFn} ValueKeyFn
10
- * @typedef {import("./map.d.ts").TreeMapOptions} TreeMapOptions
11
- *
12
- * @this {AsyncTree|null}
13
- * @param {Treelike} source
14
- * @param {ValueKeyFn|TreeMapOptions} operation
15
- */
16
- export default function deepMap(source, operation) {
17
- assertTreeIsDefined(this, "deepMap");
18
- return deepMapFn.call(this, operation)(source);
19
- }
@@ -1,21 +0,0 @@
1
- import getTreeArgument from "../misc/getTreeArgument.js";
2
- import deepTakeFn from "./@deepTakeFn.js";
3
-
4
- /**
5
- * Returns a function that traverses a tree deeply and returns the values of the
6
- * first `count` keys.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- *
11
- * @this {AsyncTree|null}
12
- * @param {Treelike} treelike
13
- * @param {number} n
14
- */
15
- export default async function deepTake(treelike, n) {
16
- const tree = await getTreeArgument(this, arguments, treelike, "@deepTake");
17
- return deepTakeFn.call(this, n)(tree);
18
- }
19
-
20
- deepTake.usage = `@deepTake tree, n\tReturn the first n values from the deep tree`;
21
- deepTake.documentation = "https://weborigami.org/builtins/deepTake.html";
@@ -1,21 +0,0 @@
1
- import { deepTakeFn } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
3
-
4
- /**
5
- * Returns a function that traverses a tree deeply and returns the values of the
6
- * first `count` keys.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- *
10
- * @this {AsyncTree|null}
11
- * @param {number} count
12
- */
13
- export default function deepTakeFnBuiltin(count) {
14
- assertTreeIsDefined(this, "deepTakeFn");
15
- const parent = this;
16
- return async (treelike) => {
17
- const taken = await deepTakeFn(count)(treelike);
18
- taken.parent = parent;
19
- return taken;
20
- };
21
- }
@@ -1,6 +0,0 @@
1
- export default function equals(a, b) {
2
- return a === b;
3
- }
4
-
5
- equals.usage = `@equals <a>, <b>\tTrue if a strictly equals b`;
6
- equals.documentation = "https://weborigami.org/language/@equals.html";
@@ -1,16 +0,0 @@
1
- import { ops } from "@weborigami/language";
2
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
3
-
4
- /**
5
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
6
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
7
- * @typedef {import("../../index.ts").Invocable} Invocable
8
- *
9
- * @this {AsyncTree|null}
10
- * @param {string} host
11
- * @param {...string} keys
12
- */
13
- export default function exploreSite(host, ...keys) {
14
- assertTreeIsDefined(this, "exploreSite");
15
- return ops.explorableSite.call(this, host, ...keys);
16
- }
@@ -1 +0,0 @@
1
- export default false;
@@ -1,7 +0,0 @@
1
- export default async function fetchBuiltin(href) {
2
- const response = await fetch(href);
3
- return response.ok ? await response.arrayBuffer() : undefined;
4
- }
5
-
6
- fetchBuiltin.usage = `@fetch href\tReturns the contents of the given URL as an ArrayBuffer`;
7
- fetchBuiltin.documentation = "https://weborigami.org/languages/@fetch.html";
@@ -1,20 +0,0 @@
1
- import getTreeArgument from "../misc/getTreeArgument.js";
2
- import groupFn from "./@groupFn.js";
3
-
4
- /**
5
- * Map a tree to a new tree with the values from the original tree grouped by
6
- * the given function.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- *
10
- * @this {AsyncTree|null}
11
- * @param {import("@weborigami/async-tree").Treelike} treelike
12
- * @param {import("../../index.ts").Invocable} groupKey
13
- */
14
- export default async function groupBuiltin(treelike, groupKey) {
15
- const tree = await getTreeArgument(this, arguments, treelike, "@sort");
16
- return groupFn.call(this, groupKey)(tree);
17
- }
18
-
19
- groupBuiltin.usage = `@group <tree>, <fn>\tGroup a tree's values using the given function`;
20
- groupBuiltin.documentation = "https://weborigami.org/builtins/@group.html";
@@ -1,33 +0,0 @@
1
- import { groupFn } from "@weborigami/async-tree";
2
- import { toFunction } from "../common/utilities.js";
3
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
4
-
5
- /**
6
- * Return a function that maps a tree to a new tree with the values from the
7
- * original tree grouped by the given function.
8
- *
9
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
- *
11
- * @this {AsyncTree|null}
12
- * @param {import("../../index.ts").Invocable} groupKey
13
- */
14
- export default function groupFnBuiltin(groupKey) {
15
- assertTreeIsDefined(this, "groupFn");
16
- const tree = this;
17
-
18
- const groupKeyFn = toFunction(groupKey);
19
- // Have the group key function run in this tree.
20
- const extendedGroupKeyFn = groupKeyFn.bind(tree);
21
-
22
- // @ts-ignore
23
- const fn = groupFn(extendedGroupKeyFn);
24
- return async (treelike) => {
25
- const grouped = await fn(treelike);
26
- grouped.parent = tree;
27
- return grouped;
28
- };
29
- }
30
-
31
- groupFnBuiltin.usage = `@groupBy <tree>, [groupKeyFn]\tReturn a new tree with the original's values grouped`;
32
- groupFnBuiltin.documentation =
33
- "https://weborigami.org/cli/builtins.html#@group";
@@ -1,49 +0,0 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
- import child_process from "node:child_process";
3
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
4
-
5
- const groupUrls = {
6
- "@cache": "https://weborigami.org/language/@cache.html",
7
- "@tree": "https://weborigami.org/language/@tree.html",
8
- "@image": "https://weborigami.org/language/@image.html",
9
- "@parse": "https://weborigami.org/language/@parse.html",
10
- "@scope": "https://weborigami.org/language/@scope.html",
11
- };
12
-
13
- /**
14
- * @this {AsyncTree|null}
15
- * @param {string} [name]
16
- */
17
- export default async function help(name) {
18
- assertTreeIsDefined(this, "help");
19
- let url;
20
- const scope = this;
21
- if (scope && name) {
22
- if (groupUrls[name]) {
23
- url = groupUrls[name];
24
- } else {
25
- const fn = await scope.get(name);
26
- url = fn?.documentation;
27
- }
28
- if (!url) {
29
- console.error(
30
- `help: ${name} does not have a property called "documentation" linking to its documentation`
31
- );
32
- return;
33
- }
34
- } else {
35
- url = "https://weborigami.org/cli/";
36
- }
37
- const platform = process.platform;
38
- const start =
39
- platform === "darwin"
40
- ? "open"
41
- : platform === "win32"
42
- ? "start"
43
- : "xdg-open";
44
- const command = `${start} ${url}`;
45
- child_process.exec(command);
46
- }
47
-
48
- help.usage = `@help/<name>\tOpens documentation for the named built-in command`;
49
- help.documentation = "https://weborigami.org/language/@help.html";
@@ -1,19 +0,0 @@
1
- import { ops } from "@weborigami/language";
2
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
3
-
4
- /**
5
- * Retrieve the indicated web resource via HTTP.
6
- *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- *
9
- * @this {AsyncTree|null}
10
- * @param {string} host
11
- * @param {...string} keys
12
- */
13
- export default async function http(host, ...keys) {
14
- assertTreeIsDefined(this, "http");
15
- return ops.http.call(this, host, ...keys);
16
- }
17
-
18
- http.usage = `@http <host>, <...keys>\tA web resource via HTTP`;
19
- http.documentation = "https://weborigami.org/language/@http.html";
@@ -1,19 +0,0 @@
1
- import { ops } from "@weborigami/language";
2
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
3
-
4
- /**
5
- * Retrieve the indicated web resource via HTTPS.
6
- *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- *
9
- * @this {AsyncTree|null}
10
- * @param {string} host
11
- * @param {...string} keys
12
- */
13
- export default async function https(host, ...keys) {
14
- assertTreeIsDefined(this, "https");
15
- return ops.https.call(this, host, ...keys);
16
- }
17
-
18
- https.usage = `@https <host>, <...keys>\tA web resource via HTTPS`;
19
- https.documentation = "https://weborigami.org/language/@https.html";
@@ -1,28 +0,0 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
- import { Tree } from "@weborigami/async-tree";
3
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
4
-
5
- /**
6
- * @this {AsyncTree|null}
7
- * @param {any} value
8
- * @param {any} trueResult
9
- * @param {any} [falseResult]
10
- */
11
- export default async function ifCommand(value, trueResult, falseResult) {
12
- assertTreeIsDefined(this, "if");
13
- let condition = await value;
14
- if (Tree.isAsyncTree(condition)) {
15
- const keys = Array.from(await condition.keys());
16
- condition = keys.length > 0;
17
- }
18
-
19
- // 0 is true, null/undefined/false is false
20
- let result = condition || condition === 0 ? trueResult : falseResult;
21
- if (typeof result === "function") {
22
- result = await result.call(this);
23
- }
24
- return result;
25
- }
26
-
27
- ifCommand.usage = `@if <value>, <true>, [<false>]\tThe true or false result based on the value`;
28
- ifCommand.documentation = "https://weborigami.org/language/@if.html";
@@ -1,17 +0,0 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
- import { ops } from "@weborigami/language";
3
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
4
-
5
- /**
6
- * Return the inherited value (if any) for the indicated key.
7
- *
8
- * @param {any} key
9
- * @this {AsyncTree|null}
10
- */
11
- export default async function inherited(key) {
12
- assertTreeIsDefined(this, "inherited");
13
- return ops.inherited.call(this, key);
14
- }
15
-
16
- inherited.usage = `@inherited <key>\tThe value of the key in the tree's inherited scope`;
17
- inherited.documentation = "https://weborigami.org/language/@inherited.html";
@@ -1,19 +0,0 @@
1
- import assertTreeIsDefined from "../misc/assertTreeIsDefined.js";
2
- import mapFn from "./@mapFn.js";
3
-
4
- /**
5
- * Map a hierarchical tree of keys and values to a new tree of keys and values.
6
- *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
9
- * @typedef {import("@weborigami/async-tree").ValueKeyFn} ValueKeyFn
10
- * @typedef {import("./map.d.ts").TreeMapOptions} TreeMapOptions
11
- *
12
- * @this {AsyncTree|null}
13
- * @param {Treelike} source
14
- * @param {ValueKeyFn|TreeMapOptions} operation
15
- */
16
- export default function map(source, operation) {
17
- assertTreeIsDefined(this, "map");
18
- return mapFn.call(this, operation)(source);
19
- }
@@ -1,17 +0,0 @@
1
- export function add(...args) {
2
- const numbers = args.map((arg) => Number(arg));
3
- return numbers.reduce((acc, val) => acc + val, 0);
4
- }
5
-
6
- export function subtract(a, b) {
7
- return Number(a) - Number(b);
8
- }
9
-
10
- export function multiply(...args) {
11
- const numbers = args.map((arg) => Number(arg));
12
- return numbers.reduce((acc, val) => acc * val, 1);
13
- }
14
-
15
- export function divide(a, b) {
16
- return Number(a) / Number(b);
17
- }
@@ -1,6 +0,0 @@
1
- export default function not(value) {
2
- return !value;
3
- }
4
-
5
- not.usage = `@not <value>\tThe logical inverse of the value`;
6
- not.documentation = "https://weborigami.org/language/@not.html";
@@ -1,6 +0,0 @@
1
- export default function or(...args) {
2
- return args.find((arg) => arg);
3
- }
4
-
5
- or.usage = `@or ...values\tReturns the first truthy value`;
6
- or.documentation = "https://weborigami.org/language/@or.html";
@@ -1,18 +0,0 @@
1
- import getTreeArgument from "../misc/getTreeArgument.js";
2
- import paginateFn from "./@paginateFn.js";
3
-
4
- /**
5
- * Return a new grouping of the treelike's values into chunks of the specified
6
- * size.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- *
11
- * @this {AsyncTree|null}
12
- * @param {Treelike} [treelike]
13
- * @param {number} [size=10]
14
- */
15
- export default async function paginate(treelike, size = 10) {
16
- const tree = await getTreeArgument(this, arguments, treelike, "@count");
17
- return paginateFn.call(this, size)(tree);
18
- }