@weborigami/origami 0.0.40 → 0.0.42

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 (90) hide show
  1. package/exports/exports.js +33 -34
  2. package/package.json +4 -4
  3. package/src/builtins/@arrows.js +2 -11
  4. package/src/builtins/@builtins.js +2 -5
  5. package/src/builtins/@cache.js +1 -1
  6. package/src/builtins/{@tree/concat.js → @concat.js} +3 -3
  7. package/src/builtins/@copy.js +2 -2
  8. package/src/builtins/{@tree/count.js → @count.js} +3 -9
  9. package/src/builtins/@crawl.js +1 -1
  10. package/src/builtins/@debug.js +2 -8
  11. package/src/builtins/{@tree/defineds.js → @defineds.js} +3 -7
  12. package/src/builtins/@document.js +1 -1
  13. package/src/builtins/{@tree/exceptions.js → @exceptions.js} +7 -8
  14. package/src/builtins/@explore.js +2 -5
  15. package/src/builtins/@files.js +1 -1
  16. package/src/builtins/@filter.js +1 -1
  17. package/src/builtins/{@tree/first.js → @first.js} +3 -9
  18. package/src/builtins/{@tree/fn.js → @fnTree.js} +13 -7
  19. package/src/builtins/@globs.js +1 -1
  20. package/src/builtins/{@tree/groupBy.js → @groupBy.js} +7 -9
  21. package/src/builtins/@help.js +1 -1
  22. package/src/builtins/@http.js +1 -1
  23. package/src/builtins/@https.js +1 -1
  24. package/src/builtins/@if.js +1 -1
  25. package/src/builtins/@image/format.js +36 -2
  26. package/src/builtins/@image/resize.js +30 -2
  27. package/src/builtins/@index.js +2 -8
  28. package/src/builtins/@inherited.js +1 -1
  29. package/src/builtins/@inline.js +1 -1
  30. package/src/builtins/{@tree/inners.js → @inners.js} +3 -8
  31. package/src/builtins/@invoke.js +8 -0
  32. package/src/builtins/{@tree/isAsyncTree.js → @isAsyncTree.js} +1 -1
  33. package/src/builtins/@json.js +7 -1
  34. package/src/builtins/{@tree/keys.js → @keys.js} +3 -9
  35. package/src/builtins/{@tree/keysJson.js → @keysJson.js} +3 -8
  36. package/src/builtins/@loaders/ori.js +18 -18
  37. package/src/builtins/@map.js +17 -19
  38. package/src/builtins/@match.js +1 -1
  39. package/src/builtins/{@tree/merge.js → @merge.js} +2 -2
  40. package/src/builtins/{@tree/mergeDeep.js → @mergeDeep.js} +3 -3
  41. package/src/builtins/@once.js +1 -1
  42. package/src/builtins/@ori.js +1 -1
  43. package/src/builtins/@pack.js +1 -1
  44. package/src/builtins/{@tree/parent.js → @parent.js} +3 -9
  45. package/src/builtins/{@tree/paths.js → @paths.js} +3 -8
  46. package/src/builtins/@perf.js +18 -0
  47. package/src/builtins/{@tree/plain.js → @plain.js} +4 -8
  48. package/src/builtins/@project.js +1 -1
  49. package/src/builtins/@redirect.js +8 -0
  50. package/src/builtins/{@tree/reverse.js → @reverse.js} +3 -8
  51. package/src/builtins/@rss.js +1 -1
  52. package/src/builtins/@scope/extend.js +6 -6
  53. package/src/builtins/@scope/get.js +1 -1
  54. package/src/builtins/@scope/set.js +4 -4
  55. package/src/builtins/@serve.js +1 -1
  56. package/src/builtins/{@tree/setDeep.js → @setDeep.js} +1 -1
  57. package/src/builtins/{@tree/shuffle.js → @shuffle.js} +5 -11
  58. package/src/builtins/{@tree/sitemap.js → @sitemap.js} +5 -8
  59. package/src/builtins/{@tree/sort.js → @sort.js} +5 -7
  60. package/src/builtins/{@tree/sortBy.js → @sortBy.js} +7 -9
  61. package/src/builtins/{@tree/static.js → @static.js} +5 -10
  62. package/src/builtins/@svg.js +3 -9
  63. package/src/builtins/{@tree/table.js → @table.js} +3 -8
  64. package/src/builtins/{@tree/take.js → @take.js} +3 -9
  65. package/src/builtins/@tree.js +19 -0
  66. package/src/builtins/@treeHttp.js +1 -1
  67. package/src/builtins/@treeHttps.js +1 -1
  68. package/src/builtins/@unpack.js +1 -1
  69. package/src/builtins/{@tree/values.js → @values.js} +3 -8
  70. package/src/builtins/{@tree/valuesDeep.js → @valuesDeep.js} +4 -8
  71. package/src/builtins/@watch.js +3 -8
  72. package/src/builtins/@with.js +1 -1
  73. package/src/builtins/@yaml.js +7 -1
  74. package/src/builtins/{@tree/map.d.ts → map.d.ts} +1 -3
  75. package/src/cli/cli.js +2 -15
  76. package/src/common/ExplorableSiteTransform.js +6 -4
  77. package/src/common/addValueKeyToScope.js +3 -11
  78. package/src/common/processUnpackedContent.js +2 -7
  79. package/src/misc/assertScopeIsDefined.js +2 -2
  80. package/src/misc/getTreeArgument.js +51 -0
  81. package/src/{builtins/@tree/dot.js → misc/treeDot.js} +2 -11
  82. package/src/server/constructResponse.js +126 -0
  83. package/src/server/mediaTypes.js +0 -16
  84. package/src/server/server.js +62 -131
  85. package/src/builtins/@tree/flowSvg.js +0 -55
  86. package/src/builtins/@tree/from.js +0 -27
  87. package/src/builtins/@tree/fromJson.js +0 -6
  88. package/src/builtins/@tree/fromYaml.js +0 -24
  89. package/src/builtins/@tree/nextKey.js +0 -29
  90. package/src/builtins/@tree/previousKey.js +0 -29
@@ -4,17 +4,24 @@ export { default as arrows } from "../src/builtins/@arrows.js";
4
4
  export { default as basename } from "../src/builtins/@basename.js";
5
5
  export { default as builtins } from "../src/builtins/@builtins.js";
6
6
  export { default as cache } from "../src/builtins/@cache.js";
7
+ export { default as concat } from "../src/builtins/@concat.js";
7
8
  export { default as config } from "../src/builtins/@config.js";
8
9
  export { default as copy } from "../src/builtins/@copy.js";
10
+ export { default as count } from "../src/builtins/@count.js";
9
11
  export { default as crawl } from "../src/builtins/@crawl.js";
10
12
  export { default as debug } from "../src/builtins/@debug.js";
13
+ export { default as defineds } from "../src/builtins/@defineds.js";
11
14
  export { default as document } from "../src/builtins/@document.js";
12
15
  export { default as equals } from "../src/builtins/@equals.js";
16
+ export { default as exceptions } from "../src/builtins/@exceptions.js";
13
17
  export { default as explore } from "../src/builtins/@explore.js";
14
18
  export { default as fetch } from "../src/builtins/@fetch.js";
15
19
  export { default as files } from "../src/builtins/@files.js";
16
20
  export { default as filter } from "../src/builtins/@filter.js";
21
+ export { default as first } from "../src/builtins/@first.js";
22
+ export { default as fnTree } from "../src/builtins/@fnTree.js";
17
23
  export { default as globs } from "../src/builtins/@globs.js";
24
+ export { default as groupBy } from "../src/builtins/@groupBy.js";
18
25
  export { default as help } from "../src/builtins/@help.js";
19
26
  export { default as http } from "../src/builtins/@http.js";
20
27
  export { default as https } from "../src/builtins/@https.js";
@@ -24,9 +31,13 @@ export { default as imageResize } from "../src/builtins/@image/resize.js";
24
31
  export { default as index } from "../src/builtins/@index.js";
25
32
  export { default as inherited } from "../src/builtins/@inherited.js";
26
33
  export { default as inline } from "../src/builtins/@inline.js";
34
+ export { default as inners } from "../src/builtins/@inners.js";
27
35
  export { default as invoke } from "../src/builtins/@invoke.js";
36
+ export { default as isAsyncTree } from "../src/builtins/@isAsyncTree.js";
28
37
  export { default as js } from "../src/builtins/@js.js";
29
38
  export { default as json } from "../src/builtins/@json.js";
39
+ export { default as keys } from "../src/builtins/@keys.js";
40
+ export { default as keysJson } from "../src/builtins/@keysJson.js";
30
41
  export { default as loadersCss } from "../src/builtins/@loaders/css.js";
31
42
  export { default as loadersHtm } from "../src/builtins/@loaders/htm.js";
32
43
  export { default as loadersHtml } from "../src/builtins/@loaders/html.js";
@@ -43,6 +54,8 @@ export { default as map } from "../src/builtins/@map.js";
43
54
  export { default as mapDeep } from "../src/builtins/@mapDeep.js";
44
55
  export { default as match } from "../src/builtins/@match.js";
45
56
  export { default as mdHtml } from "../src/builtins/@mdHtml.js";
57
+ export { default as merge } from "../src/builtins/@merge.js";
58
+ export { default as mergeDeep } from "../src/builtins/@mergeDeep.js";
46
59
  export { default as node } from "../src/builtins/@node.js";
47
60
  export { default as not } from "../src/builtins/@not.js";
48
61
  export { default as once } from "../src/builtins/@once.js";
@@ -50,56 +63,39 @@ export { default as or } from "../src/builtins/@or.js";
50
63
  export { default as ori } from "../src/builtins/@ori.js";
51
64
  export { default as pack } from "../src/builtins/@pack.js";
52
65
  export { default as package } from "../src/builtins/@package.js";
66
+ export { default as parent } from "../src/builtins/@parent.js";
53
67
  export { default as parseJson } from "../src/builtins/@parse/json.js";
54
68
  export { default as parseYaml } from "../src/builtins/@parse/yaml.js";
69
+ export { default as paths } from "../src/builtins/@paths.js";
70
+ export { default as perf } from "../src/builtins/@perf.js";
71
+ export { default as plain } from "../src/builtins/@plain.js";
55
72
  export { default as project } from "../src/builtins/@project.js";
73
+ export { default as redirect } from "../src/builtins/@redirect.js";
56
74
  export { default as repeat } from "../src/builtins/@repeat.js";
75
+ export { default as reverse } from "../src/builtins/@reverse.js";
57
76
  export { default as rss } from "../src/builtins/@rss.js";
58
77
  export { default as scopeExtend } from "../src/builtins/@scope/extend.js";
59
78
  export { default as scopeGet } from "../src/builtins/@scope/get.js";
60
79
  export { default as scopeInvoke } from "../src/builtins/@scope/invoke.js";
61
80
  export { default as scopeSet } from "../src/builtins/@scope/set.js";
62
81
  export { default as serve } from "../src/builtins/@serve.js";
82
+ export { default as setDeep } from "../src/builtins/@setDeep.js";
63
83
  export { default as shell } from "../src/builtins/@shell.js";
84
+ export { default as shuffle } from "../src/builtins/@shuffle.js";
85
+ export { default as sitemap } from "../src/builtins/@sitemap.js";
86
+ export { default as sort } from "../src/builtins/@sort.js";
87
+ export { default as sortBy } from "../src/builtins/@sortBy.js";
88
+ export { default as static } from "../src/builtins/@static.js";
64
89
  export { default as stdin } from "../src/builtins/@stdin.js";
65
90
  export { default as svg } from "../src/builtins/@svg.js";
66
- export { default as treeConcat } from "../src/builtins/@tree/concat.js";
67
- export { default as treeCount } from "../src/builtins/@tree/count.js";
68
- export { default as treeDefineds } from "../src/builtins/@tree/defineds.js";
69
- export { default as treeDot } from "../src/builtins/@tree/dot.js";
70
- export { default as treeExceptions } from "../src/builtins/@tree/exceptions.js";
71
- export { default as treeFirst } from "../src/builtins/@tree/first.js";
72
- export { default as treeFlowSvg } from "../src/builtins/@tree/flowSvg.js";
73
- export { default as treeFn } from "../src/builtins/@tree/fn.js";
74
- export { default as treeFrom } from "../src/builtins/@tree/from.js";
75
- export { default as treeFromJson } from "../src/builtins/@tree/fromJson.js";
76
- export { default as treeFromYaml } from "../src/builtins/@tree/fromYaml.js";
77
- export { default as treeGroupBy } from "../src/builtins/@tree/groupBy.js";
78
- export { default as treeInners } from "../src/builtins/@tree/inners.js";
79
- export { default as treeIsAsyncTree } from "../src/builtins/@tree/isAsyncTree.js";
80
- export { default as treeKeys } from "../src/builtins/@tree/keys.js";
81
- export { default as treeKeysJson } from "../src/builtins/@tree/keysJson.js";
82
- export { default as treeMerge } from "../src/builtins/@tree/merge.js";
83
- export { default as treeMergeDeep } from "../src/builtins/@tree/mergeDeep.js";
84
- export { default as treeNextKey } from "../src/builtins/@tree/nextKey.js";
85
- export { default as treeParent } from "../src/builtins/@tree/parent.js";
86
- export { default as treePaths } from "../src/builtins/@tree/paths.js";
87
- export { default as treePlain } from "../src/builtins/@tree/plain.js";
88
- export { default as treePreviousKey } from "../src/builtins/@tree/previousKey.js";
89
- export { default as treeReverse } from "../src/builtins/@tree/reverse.js";
90
- export { default as treeSetDeep } from "../src/builtins/@tree/setDeep.js";
91
- export { default as treeShuffle } from "../src/builtins/@tree/shuffle.js";
92
- export { default as treeSitemap } from "../src/builtins/@tree/sitemap.js";
93
- export { default as treeSort } from "../src/builtins/@tree/sort.js";
94
- export { default as treeSortBy } from "../src/builtins/@tree/sortBy.js";
95
- export { default as treeStatic } from "../src/builtins/@tree/static.js";
96
- export { default as treeTable } from "../src/builtins/@tree/table.js";
97
- export { default as treeTake } from "../src/builtins/@tree/take.js";
98
- export { default as treeValues } from "../src/builtins/@tree/values.js";
99
- export { default as treeValuesDeep } from "../src/builtins/@tree/valuesDeep.js";
91
+ export { default as table } from "../src/builtins/@table.js";
92
+ export { default as take } from "../src/builtins/@take.js";
93
+ export { default as tree } from "../src/builtins/@tree.js";
100
94
  export { default as treeHttp } from "../src/builtins/@treeHttp.js";
101
95
  export { default as treeHttps } from "../src/builtins/@treeHttps.js";
102
96
  export { default as unpack } from "../src/builtins/@unpack.js";
97
+ export { default as values } from "../src/builtins/@values.js";
98
+ export { default as valuesDeep } from "../src/builtins/@valuesDeep.js";
103
99
  export { default as watch } from "../src/builtins/@watch.js";
104
100
  export { default as with } from "../src/builtins/@with.js";
105
101
  export { default as yaml } from "../src/builtins/@yaml.js";
@@ -119,7 +115,10 @@ export { default as ShuffleTransform } from "../src/common/ShuffleTransform.js";
119
115
  export { default as TextDocument } from "../src/common/TextDocument.js";
120
116
  export * from "../src/common/utilities.js";
121
117
  export { default as assertScopeIsDefined } from "../src/misc/assertScopeIsDefined.js";
118
+ export { default as getTreeArgument } from "../src/misc/getTreeArgument.js";
122
119
  export { default as OriCommandTransform } from "../src/misc/OriCommandTransform.js";
120
+ export { default as treeDot } from "../src/misc/treeDot.js";
123
121
  export { default as yamlOrigamiTag } from "../src/misc/yamlOrigamiTag.js";
122
+ export { default as constructResponse } from "../src/server/constructResponse.js";
124
123
  export * from "../src/server/mediaTypes.js";
125
124
  export * from "../src/server/server.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -19,9 +19,9 @@
19
19
  "typescript": "5.3.3"
20
20
  },
21
21
  "dependencies": {
22
- "@weborigami/async-tree": "0.0.40",
23
- "@weborigami/language": "0.0.40",
24
- "@weborigami/types": "0.0.40",
22
+ "@weborigami/async-tree": "https://gitpkg.now.sh/WebOrigami/origami/async-tree?e08c2451",
23
+ "@weborigami/language": "https://gitpkg.now.sh/WebOrigami/origami/language?e08c2451",
24
+ "@weborigami/types": "0.0.42",
25
25
  "graphviz-wasm": "3.0.1",
26
26
  "highlight.js": "11.9.0",
27
27
  "marked": "11.1.1",
@@ -1,9 +1,8 @@
1
- import { Tree } from "@weborigami/async-tree";
2
1
  import { Scope, functionResultsMap } from "@weborigami/language";
3
2
  import builtins from "../../src/builtins/@builtins.js";
4
3
  import arrowFunctionsMap from "../common/arrowFunctionsMap.js";
5
4
  import { keySymbol } from "../common/utilities.js";
6
- import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
5
+ import getTreeArgument from "../misc/getTreeArgument.js";
7
6
 
8
7
  /**
9
8
  * Interpret arrow keys in the tree as function calls.
@@ -14,15 +13,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
14
13
  * @param {Treelike} [treelike]
15
14
  */
16
15
  export default async function arrows(treelike) {
17
- assertScopeIsDefined(this);
18
- treelike = treelike ?? (await this?.get("@current"));
19
- if (treelike === undefined) {
20
- throw TypeError(
21
- "@arrows requires a treelike argument, but received undefined"
22
- );
23
- }
24
- /** @type {AsyncTree} */
25
- const tree = Tree.from(treelike);
16
+ const tree = await getTreeArgument(this, arguments, treelike, "@arrows");
26
17
  const mapped = functionResultsMap(arrowFunctionsMap()(tree));
27
18
  const scope = this ?? builtins;
28
19
  const scoped = Scope.treeWithScope(mapped, scope);
@@ -1,15 +1,12 @@
1
1
  import { FileTree } from "@weborigami/async-tree";
2
2
  import { ImportModulesMixin } from "@weborigami/language";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
3
  import CommandModulesTransform from "../common/CommandModulesTransform.js";
6
4
 
7
- const dirname = path.dirname(fileURLToPath(import.meta.url));
8
- const commandsFolder = path.resolve(dirname, "../builtins");
5
+ const commandsUrl = new URL("../builtins", import.meta.url);
9
6
 
10
7
  /** @type {any} */
11
8
  const builtins = new (CommandModulesTransform(ImportModulesMixin(FileTree)))(
12
- commandsFolder
9
+ commandsUrl
13
10
  );
14
11
 
15
12
  builtins.usage = `@builtins\tThe Tree Origami built-in functions`;
@@ -18,7 +18,7 @@ export default async function cacheBuiltin(
18
18
  cacheTreelike,
19
19
  filterTreelike
20
20
  ) {
21
- assertScopeIsDefined(this);
21
+ assertScopeIsDefined(this, "cache");
22
22
 
23
23
  const sourceTree = Tree.from(sourceTreelike);
24
24
  /** @type {any} */
@@ -1,6 +1,6 @@
1
1
  import { Tree } from "@weborigami/async-tree";
2
2
  import { ops } from "@weborigami/language";
3
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
3
+ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
4
4
 
5
5
  /**
6
6
  * Concatenate the text content of objects or trees.
@@ -11,11 +11,11 @@ import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
11
11
  * @param {any[]} args
12
12
  */
13
13
  export default async function concat(...args) {
14
- assertScopeIsDefined(this);
14
+ assertScopeIsDefined(this, "concat");
15
15
  const tree =
16
16
  args.length === 0 ? await this?.get("@current") : Tree.from(args);
17
17
  return ops.concat.call(this, tree);
18
18
  }
19
19
 
20
- concat.usage = `concat <...objs>\tConcatenate text and/or trees of text`;
20
+ concat.usage = `@concat <...objs>\tConcatenate text and/or trees of text`;
21
21
  concat.documentation = "https://weborigami.org/cli/@tree.html#concat";
@@ -2,7 +2,7 @@ import { Tree } from "@weborigami/async-tree";
2
2
  import process, { stdout } from "node:process";
3
3
  import { transformObject } from "../common/utilities.js";
4
4
  import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
5
- import setDeep from "./@tree/setDeep.js";
5
+ import setDeep from "./@setDeep.js";
6
6
 
7
7
  /**
8
8
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
@@ -13,7 +13,7 @@ import setDeep from "./@tree/setDeep.js";
13
13
  * @param {Treelike} target
14
14
  */
15
15
  export default async function copy(source, target) {
16
- assertScopeIsDefined(this);
16
+ assertScopeIsDefined(this, "copy");
17
17
  // const start = performance.now();
18
18
  const sourceTree = Tree.from(source);
19
19
  /** @type {any} */ let targetTree = Tree.from(target);
@@ -1,5 +1,4 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
1
+ import getTreeArgument from "../misc/getTreeArgument.js";
3
2
 
4
3
  /**
5
4
  * Return the number of keys in the tree.
@@ -10,15 +9,10 @@ import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
10
9
  * @param {Treelike} [treelike]
11
10
  */
12
11
  export default async function count(treelike) {
13
- assertScopeIsDefined(this);
14
- treelike = treelike ?? (await this?.get("@current"));
15
- if (treelike === undefined) {
16
- return undefined;
17
- }
18
- const tree = await Tree.from(treelike);
12
+ const tree = await getTreeArgument(this, arguments, treelike, "@count");
19
13
  const keys = [...(await tree.keys())];
20
14
  return keys.length;
21
15
  }
22
16
 
23
- count.usage = `count <treelike>\tReturn the number of keys in the tree`;
17
+ count.usage = `@count <treelike>\tReturn the number of keys in the tree`;
24
18
  count.documentation = "https://weborigami.org/cli/@tree.html#count";
@@ -30,7 +30,7 @@ const fakeBaseUrl = new URL("https://fake");
30
30
  * @returns {Promise<AsyncTree>}
31
31
  */
32
32
  export default async function crawl(treelike, baseHref) {
33
- assertScopeIsDefined(this);
33
+ assertScopeIsDefined(this, "crawl");
34
34
  const tree =
35
35
  typeof treelike === "string"
36
36
  ? treeHttps.call(this, treelike)
@@ -2,7 +2,7 @@ import { Tree, isPlainObject } from "@weborigami/async-tree";
2
2
  import ExplorableSiteTransform from "../common/ExplorableSiteTransform.js";
3
3
  import { isTransformApplied, transformObject } from "../common/utilities.js";
4
4
  import OriCommandTransform from "../misc/OriCommandTransform.js";
5
- import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
5
+ import getTreeArgument from "../misc/getTreeArgument.js";
6
6
 
7
7
  /**
8
8
  * Add debugging features to the indicated tree.
@@ -14,15 +14,9 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
14
14
  * @param {Treelike} [treelike]
15
15
  */
16
16
  export default async function debug(treelike) {
17
- assertScopeIsDefined(this);
18
- treelike = treelike ?? (await this?.get("@current"));
19
- if (treelike === undefined) {
20
- return;
21
- }
22
-
23
17
  // The debug command leaves the tree's existing scope intact; it does not
24
18
  // apply its own scope to the tree.
25
- let tree = Tree.from(treelike);
19
+ let tree = await getTreeArgument(this, arguments, treelike, "@debug");
26
20
 
27
21
  if (!isTransformApplied(ExplorableSiteTransform, tree)) {
28
22
  tree = transformObject(ExplorableSiteTransform, tree);
@@ -1,6 +1,6 @@
1
1
  import { Tree } from "@weborigami/async-tree";
2
2
  import { Scope } from "@weborigami/language";
3
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
3
+ import getTreeArgument from "../misc/getTreeArgument.js";
4
4
 
5
5
  /**
6
6
  * Return only the defined (not `undefined`) values in the tree.
@@ -12,14 +12,10 @@ import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
12
12
  * @param {Treelike} treelike
13
13
  */
14
14
  export default async function defineds(treelike) {
15
- assertScopeIsDefined(this);
16
- treelike = treelike ?? (await this?.get("@current"));
17
- if (treelike === undefined) {
18
- throw new TypeError("A treelike argument is required");
19
- }
15
+ const tree = await getTreeArgument(this, arguments, treelike, "@defineds");
20
16
 
21
17
  /** @type {AsyncTree} */
22
- let result = await Tree.mapReduce(treelike, null, async (values, keys) => {
18
+ let result = await Tree.mapReduce(tree, null, async (values, keys) => {
23
19
  const result = {};
24
20
  let someValuesExist = false;
25
21
  for (let i = 0; i < keys.length; i++) {
@@ -12,7 +12,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
12
12
  * @returns
13
13
  */
14
14
  export default function document(text, data, parent) {
15
- assertScopeIsDefined(this);
15
+ assertScopeIsDefined(this, "document");
16
16
  const merged = Object.assign({}, data, { "@text": text });
17
17
  return new TextDocument(merged, parent ?? this);
18
18
  }
@@ -1,7 +1,7 @@
1
1
  import { Tree } from "@weborigami/async-tree";
2
2
  import { Scope } from "@weborigami/language";
3
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
4
- import defineds from "./defineds.js";
3
+ import getTreeArgument from "../misc/getTreeArgument.js";
4
+ import defineds from "./@defineds.js";
5
5
 
6
6
  /**
7
7
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
@@ -10,11 +10,10 @@ import defineds from "./defineds.js";
10
10
  * @param {Treelike} treelike
11
11
  */
12
12
  export default async function exceptions(treelike) {
13
- assertScopeIsDefined(this);
14
- treelike = treelike ?? (await this?.get("@current"));
13
+ const tree = await getTreeArgument(this, arguments, treelike, "@exceptions");
15
14
 
16
15
  /** @type {AsyncTree} */
17
- let exceptionsTree = new ExceptionsTree(treelike);
16
+ let exceptionsTree = new ExceptionsTree(tree);
18
17
  exceptionsTree = Scope.treeWithScope(exceptionsTree, this);
19
18
  return defineds.call(this, exceptionsTree);
20
19
  }
@@ -23,8 +22,8 @@ export default async function exceptions(treelike) {
23
22
  * @implements {AsyncTree}
24
23
  */
25
24
  class ExceptionsTree {
26
- constructor(treelike) {
27
- this.tree = Tree.from(treelike);
25
+ constructor(tree) {
26
+ this.tree = tree;
28
27
  }
29
28
 
30
29
  async get(key) {
@@ -45,6 +44,6 @@ class ExceptionsTree {
45
44
  }
46
45
  }
47
46
 
48
- exceptions.usage = `exceptions tree\tReturn a tree of exceptions thrown in the tree`;
47
+ exceptions.usage = `@exceptions tree\tReturn a tree of exceptions thrown in the tree`;
49
48
  exceptions.documentation =
50
49
  "https://weborigami.org/cli/builtins.html#exceptions";
@@ -1,15 +1,12 @@
1
1
  /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
2
  import { ObjectTree, Tree } from "@weborigami/async-tree";
3
3
  import { OrigamiFiles, Scope } from "@weborigami/language";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
4
  import builtins from "../builtins/@builtins.js";
7
5
  import { keySymbol } from "../common/utilities.js";
8
6
  import debug from "./@debug.js";
9
7
 
10
- const dirname = path.dirname(fileURLToPath(import.meta.url));
11
- const miscDir = path.resolve(dirname, "../misc");
12
- const miscFiles = Scope.treeWithScope(new OrigamiFiles(miscDir), builtins);
8
+ const miscUrl = new URL("../misc", import.meta.url);
9
+ const miscFiles = Scope.treeWithScope(new OrigamiFiles(miscUrl), builtins);
13
10
 
14
11
  /**
15
12
  * @this {AsyncTree|null}
@@ -10,7 +10,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
10
10
  * @param {string[]} keys
11
11
  */
12
12
  export default async function files(...keys) {
13
- assertScopeIsDefined(this);
13
+ assertScopeIsDefined(this, "files");
14
14
  const resolved = path.resolve(process.cwd(), ...keys);
15
15
  /** @type {AsyncTree} */
16
16
  let result = new OrigamiFiles(resolved);
@@ -12,7 +12,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
12
12
  * @param {Treelike} filterVariant
13
13
  */
14
14
  export default async function filter(treelike, filterVariant) {
15
- assertScopeIsDefined(this);
15
+ assertScopeIsDefined(this, "filter");
16
16
  /** @type {AsyncTree} */
17
17
  let result = new FilterTree(treelike, filterVariant);
18
18
  result = Scope.treeWithScope(result, this);
@@ -1,5 +1,4 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
1
+ import getTreeArgument from "../misc/getTreeArgument.js";
3
2
 
4
3
  /**
5
4
  * Return the first value in the tree.
@@ -10,12 +9,7 @@ import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
10
9
  * @param {Treelike} [treelike]
11
10
  */
12
11
  export default async function first(treelike) {
13
- assertScopeIsDefined(this);
14
- treelike = treelike ?? (await this?.get("@current"));
15
- if (treelike === undefined) {
16
- return undefined;
17
- }
18
- const tree = Tree.from(treelike);
12
+ const tree = await getTreeArgument(this, arguments, treelike, "@first");
19
13
  for (const key of await tree.keys()) {
20
14
  // Just return first value immediately.
21
15
  const value = await tree.get(key);
@@ -24,5 +18,5 @@ export default async function first(treelike) {
24
18
  return undefined;
25
19
  }
26
20
 
27
- first.usage = `first <tree>\tReturns the first value in the tree.`;
21
+ first.usage = `@first <tree>\tReturns the first value in the tree.`;
28
22
  first.documentation = "https://weborigami.org/cli/builtins.html#first";
@@ -1,20 +1,26 @@
1
1
  import { FunctionTree } from "@weborigami/async-tree";
2
2
  import { Scope } from "@weborigami/language";
3
- import { toFunction } from "../../common/utilities.js";
4
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
3
+ import { toFunction } from "../common/utilities.js";
4
+ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
5
5
 
6
6
  /**
7
7
  * Create a tree from a function and a set of keys.
8
8
  *
9
9
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
10
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
11
- * @typedef {import("../../../index.ts").Invocable} Invocable
11
+ * @typedef {import("../../index.ts").Invocable} Invocable
12
12
  *
13
13
  * @this {AsyncTree|null}
14
14
  * @param {Invocable} [invocable]
15
15
  */
16
- export default async function fn(invocable, keys = []) {
17
- assertScopeIsDefined(this);
16
+ export default async function fnTree(invocable, keys = []) {
17
+ assertScopeIsDefined(this, "fnTree");
18
+ // A fragment of the logic from getTreeArgument.js
19
+ if (arguments.length > 0 && invocable === undefined) {
20
+ throw new Error(
21
+ "An Origami function was called with an initial argument, but its value is undefined."
22
+ );
23
+ }
18
24
  invocable = invocable ?? (await this?.get("@current"));
19
25
  if (invocable === undefined) {
20
26
  return undefined;
@@ -30,5 +36,5 @@ export default async function fn(invocable, keys = []) {
30
36
  return new FunctionTree(extendedFn, keys);
31
37
  }
32
38
 
33
- fn.usage = `fn <fn>, [<keys>]\tCreate a tree from a function and a set of keys`;
34
- fn.documentation = "https://weborigami.org/cli/tree.html#fn";
39
+ fnTree.usage = `@fnTree <fn>, [<keys>]\tCreate a tree from a function and a set of keys`;
40
+ fnTree.documentation = "https://weborigami.org/cli/tree.html#fn";
@@ -12,7 +12,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
12
12
  * @this {AsyncTree|null}
13
13
  */
14
14
  export default async function globs(tree) {
15
- assertScopeIsDefined(this);
15
+ assertScopeIsDefined(this, "globs");
16
16
  /** @type {AsyncTree} */
17
17
  let result = new GlobTree(tree);
18
18
  result = Scope.treeWithScope(result, this);
@@ -1,8 +1,8 @@
1
- import { Tree, groupBy } from "@weborigami/async-tree";
1
+ import { groupBy } from "@weborigami/async-tree";
2
2
  import { Scope } from "@weborigami/language";
3
- import addValueKeyToScope from "../../common/addValueKeyToScope.js";
4
- import { toFunction } from "../../common/utilities.js";
5
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
3
+ import addValueKeyToScope from "../common/addValueKeyToScope.js";
4
+ import { toFunction } from "../common/utilities.js";
5
+ import getTreeArgument from "../misc/getTreeArgument.js";
6
6
 
7
7
  /**
8
8
  * Return a new tree with the values from the original tree in groups.
@@ -10,16 +10,14 @@ import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
10
10
  *
11
11
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
12
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
13
- * @typedef {import("../../../index.ts").Invocable} Invocable
13
+ * @typedef {import("../../index.ts").Invocable} Invocable
14
14
  *
15
15
  * @this {AsyncTree|null}
16
16
  * @param {Treelike} treelike
17
17
  * @param {Invocable} groupKeyFn
18
18
  */
19
19
  export default async function groupByBuiltin(treelike, groupKeyFn) {
20
- assertScopeIsDefined(this);
21
- treelike = treelike ?? (await this?.get("@current"));
22
- const tree = Tree.from(treelike);
20
+ const tree = await getTreeArgument(this, arguments, treelike, "@groupBy");
23
21
 
24
22
  const fn = toFunction(groupKeyFn);
25
23
  const baseScope = Scope.getScope(this);
@@ -34,6 +32,6 @@ export default async function groupByBuiltin(treelike, groupKeyFn) {
34
32
  return scoped;
35
33
  }
36
34
 
37
- groupByBuiltin.usage = `groupBy <tree>, [groupKeyFn]\tReturn a new tree with the original's values grouped`;
35
+ groupByBuiltin.usage = `@groupBy <tree>, [groupKeyFn]\tReturn a new tree with the original's values grouped`;
38
36
  groupByBuiltin.documentation =
39
37
  "https://weborigami.org/cli/builtins.html#@group";
@@ -15,7 +15,7 @@ const groupUrls = {
15
15
  * @param {string} [name]
16
16
  */
17
17
  export default async function help(name) {
18
- assertScopeIsDefined(this);
18
+ assertScopeIsDefined(this, "help");
19
19
  let url;
20
20
  const scope = this;
21
21
  if (scope && name) {
@@ -11,7 +11,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
11
11
  * @param {...string} keys
12
12
  */
13
13
  export default async function http(host, ...keys) {
14
- assertScopeIsDefined(this);
14
+ assertScopeIsDefined(this, "http");
15
15
  return ops.http.call(this, host, ...keys);
16
16
  }
17
17
 
@@ -11,7 +11,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
11
11
  * @param {...string} keys
12
12
  */
13
13
  export default async function https(host, ...keys) {
14
- assertScopeIsDefined(this);
14
+ assertScopeIsDefined(this, "https");
15
15
  return ops.https.call(this, host, ...keys);
16
16
  }
17
17
 
@@ -9,7 +9,7 @@ import assertScopeIsDefined from "../misc/assertScopeIsDefined.js";
9
9
  * @param {any} [falseResult]
10
10
  */
11
11
  export default async function ifCommand(value, trueResult, falseResult) {
12
- assertScopeIsDefined(this);
12
+ assertScopeIsDefined(this, "if");
13
13
  let condition = await value;
14
14
  if (Tree.isAsyncTree(condition)) {
15
15
  const keys = Array.from(await condition.keys());
@@ -1,5 +1,39 @@
1
1
  import sharp from "sharp";
2
2
 
3
- export default function format(buffer, format, options) {
4
- return sharp(buffer).toFormat(format, options).toBuffer();
3
+ /**
4
+ * Return the image in a different format.
5
+ *
6
+ * @this {import("@weborigami/types").AsyncTree|null}
7
+ *
8
+ * @typedef {import("sharp").ResizeOptions} ResizeOptions
9
+ *
10
+ * @overload
11
+ * @param {any} param1
12
+ * @param {any} param2
13
+ * @returns {(buffer: Buffer) => Promise<Buffer>}
14
+ *
15
+ * @overload
16
+ * @param {Buffer} param1
17
+ * @param {any} param2
18
+ * @param {any} param3
19
+ * @returns {Promise<Buffer>}
20
+ */
21
+ export default function format(param1, param2, param3) {
22
+ // Identify which overload was used.
23
+ let buffer;
24
+ let format;
25
+ let options;
26
+ if (param1 instanceof Buffer) {
27
+ buffer = param1;
28
+ format = param2;
29
+ options = param3;
30
+ } else {
31
+ format = param1;
32
+ options = param2;
33
+ }
34
+
35
+ const transform = (buffer) =>
36
+ sharp(buffer).toFormat(format, options).toBuffer();
37
+
38
+ return buffer ? transform(buffer) : transform;
5
39
  }