@weborigami/origami 0.0.59 → 0.0.60

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 (80) hide show
  1. package/exports/exports.js +2 -6
  2. package/package.json +4 -4
  3. package/src/builtins/@arrowsMap.js +4 -5
  4. package/src/builtins/@breakpoint.js +12 -0
  5. package/src/builtins/@cache.js +3 -6
  6. package/src/builtins/@concat.js +3 -4
  7. package/src/builtins/@config.js +3 -12
  8. package/src/builtins/@constructor.js +3 -7
  9. package/src/builtins/@copy.js +2 -2
  10. package/src/builtins/@crawl.js +4 -6
  11. package/src/builtins/@debug.js +5 -6
  12. package/src/builtins/@deepMap.js +2 -2
  13. package/src/builtins/@deepMapFn.js +2 -2
  14. package/src/builtins/@deepMerge.js +3 -18
  15. package/src/builtins/@deepReverse.js +1 -3
  16. package/src/builtins/@deepTakeFn.js +5 -6
  17. package/src/builtins/@defineds.js +4 -7
  18. package/src/builtins/@document.js +2 -2
  19. package/src/builtins/@exceptions.js +1 -5
  20. package/src/builtins/@explore.js +15 -14
  21. package/src/builtins/@files.js +4 -6
  22. package/src/builtins/@filter.js +3 -6
  23. package/src/builtins/@fnTree.js +8 -22
  24. package/src/builtins/@globs.js +3 -6
  25. package/src/builtins/@groupFn.js +7 -8
  26. package/src/builtins/@help.js +2 -2
  27. package/src/builtins/@http.js +2 -2
  28. package/src/builtins/@https.js +2 -2
  29. package/src/builtins/@if.js +2 -2
  30. package/src/builtins/@image/format.js +2 -2
  31. package/src/builtins/@image/formatFn.js +6 -3
  32. package/src/builtins/@image/resize.js +2 -2
  33. package/src/builtins/@image/resizeFn.js +6 -3
  34. package/src/builtins/@inherited.js +2 -2
  35. package/src/builtins/@inline.js +5 -9
  36. package/src/builtins/@inners.js +0 -1
  37. package/src/builtins/@invoke.js +4 -7
  38. package/src/builtins/@json.js +3 -3
  39. package/src/builtins/@map.js +2 -2
  40. package/src/builtins/@mapFn.js +9 -10
  41. package/src/builtins/@match.js +17 -16
  42. package/src/builtins/@mdHtml.js +4 -1
  43. package/src/builtins/@merge.js +3 -18
  44. package/src/builtins/@once.js +2 -2
  45. package/src/builtins/@ori.js +6 -6
  46. package/src/builtins/@pack.js +2 -2
  47. package/src/builtins/@package.js +4 -8
  48. package/src/builtins/@paginateFn.js +1 -6
  49. package/src/builtins/@perf.js +2 -2
  50. package/src/builtins/@project.js +31 -22
  51. package/src/builtins/@reverse.js +1 -3
  52. package/src/builtins/@rss.js +2 -2
  53. package/src/builtins/@serve.js +2 -2
  54. package/src/builtins/@sitemap.js +4 -1
  55. package/src/builtins/@sortFn.js +6 -7
  56. package/src/builtins/@string.js +2 -2
  57. package/src/builtins/@takeFn.js +5 -6
  58. package/src/builtins/@treeHttp.js +2 -2
  59. package/src/builtins/@treeHttps.js +2 -2
  60. package/src/builtins/@unpack.js +2 -2
  61. package/src/builtins/@watch.js +5 -12
  62. package/src/builtins/@yaml.js +3 -3
  63. package/src/builtins/ori_handler.js +3 -3
  64. package/src/builtins/~.js +3 -3
  65. package/src/cli/cli.js +6 -19
  66. package/src/common/ConstantTree.js +1 -0
  67. package/src/common/ExplorableSiteTransform.js +9 -12
  68. package/src/common/documentObject.js +2 -2
  69. package/src/common/processUnpackedContent.js +12 -18
  70. package/src/misc/OriCommandTransform.js +1 -9
  71. package/src/misc/assertTreeIsDefined.d.ts +1 -0
  72. package/src/misc/assertTreeIsDefined.js +7 -0
  73. package/src/misc/getTreeArgument.js +11 -12
  74. package/src/server/server.js +3 -10
  75. package/src/builtins/@scope/extend.js +0 -22
  76. package/src/builtins/@scope/get.js +0 -25
  77. package/src/builtins/@scope/invoke.js +0 -22
  78. package/src/builtins/@scope/set.js +0 -25
  79. package/src/common/addValueKeyToScope.js +0 -23
  80. package/src/misc/assertScopeIsDefined.js +0 -7
@@ -1,7 +1,6 @@
1
1
  import { Tree, isUnpackable } from "@weborigami/async-tree";
2
2
  import { isTreelike } from "@weborigami/async-tree/src/Tree.js";
3
- import { Scope } from "@weborigami/language";
4
- import assertScopeIsDefined from "./assertScopeIsDefined.js";
3
+ import assertTreeIsDefined from "./assertTreeIsDefined.js";
5
4
 
6
5
  /**
7
6
  * Many Origami built-in functions accept an optional treelike object as their
@@ -15,19 +14,19 @@ import assertScopeIsDefined from "./assertScopeIsDefined.js";
15
14
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
16
15
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
17
16
  *
18
- * @param {AsyncTree|null} scope
17
+ * @param {AsyncTree|null} parent
19
18
  * @param {IArguments} args
20
19
  * @param {Treelike|undefined} treelike
21
20
  * @param {string} methodName
22
21
  * @returns {Promise<AsyncTree>}
23
22
  */
24
23
  export default async function getTreeArgument(
25
- scope,
24
+ parent,
26
25
  args,
27
26
  treelike,
28
27
  methodName
29
28
  ) {
30
- assertScopeIsDefined(scope);
29
+ assertTreeIsDefined(parent, methodName);
31
30
 
32
31
  if (treelike !== undefined) {
33
32
  if (isUnpackable(treelike)) {
@@ -36,9 +35,9 @@ export default async function getTreeArgument(
36
35
  if (isTreelike(treelike)) {
37
36
  let tree = Tree.from(treelike);
38
37
  // If the tree was created from a treelike object and does not yet have a
39
- // parent or scope, put it in the current scope.
40
- if (!tree.parent && !(/** @type {any} */ (tree).scope)) {
41
- tree = Scope.treeWithScope(tree, scope);
38
+ // parent, make the current tree its parent.
39
+ if (!tree.parent) {
40
+ tree.parent = parent;
42
41
  }
43
42
  return tree;
44
43
  }
@@ -48,13 +47,13 @@ export default async function getTreeArgument(
48
47
  }
49
48
 
50
49
  if (args.length === 0) {
51
- if (!scope) {
52
- // Should never happen because assertScopeIsDefined throws an exception.
50
+ if (!parent) {
51
+ // Should never happen because assertTreeIsDefined throws an exception.
53
52
  throw new Error(
54
- `${methodName} was called with no tree argument and no scope.`
53
+ `${methodName} was called with no tree argument and no parent.`
55
54
  );
56
55
  }
57
- return scope.get("@current");
56
+ return parent;
58
57
  }
59
58
 
60
59
  throw new Error(`${methodName}: The first argument was undefined.`);
@@ -1,5 +1,5 @@
1
1
  import { DeepObjectTree, Tree, keysFromPath } from "@weborigami/async-tree";
2
- import { Scope, formatError } from "@weborigami/language";
2
+ import { formatError } from "@weborigami/language";
3
3
  import { ServerResponse } from "node:http";
4
4
  import constructResponse from "./constructResponse.js";
5
5
 
@@ -53,15 +53,8 @@ function extendTreeScopeWithParams(tree, url) {
53
53
  const paramTree = new DeepObjectTree({
54
54
  "@params": params,
55
55
  });
56
-
57
- // Create a new scope that includes search parameter tree.
58
- const scope = Scope.getScope(tree);
59
- const extendedScope = new Scope(paramTree, scope);
60
-
61
- // Create a new tree that extends the prototype chain of the supplied tree.
62
- const extendedTree = Scope.treeWithScope(tree, extendedScope);
63
-
64
- return extendedTree;
56
+ paramTree.parent = tree;
57
+ return paramTree;
65
58
  }
66
59
 
67
60
  /**
@@ -1,22 +0,0 @@
1
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
2
- import scopeSet from "./set.js";
3
-
4
- /**
5
- * Return a copy of the given tree whose scope includes the given trees *and*
6
- * the current scope.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @this {AsyncTree|null}
11
- * @param {Treelike} treelike
12
- * @param {...Treelike} scopeTrees
13
- * @this {AsyncTree|null}
14
- */
15
- export default function scopeExtend(treelike, ...scopeTrees) {
16
- assertScopeIsDefined(this, "scopeExtend");
17
- const scope = this;
18
- return scopeSet.call(scope, treelike, ...scopeTrees, scope);
19
- }
20
-
21
- scopeExtend.usage = `@scope/extend <tree>, <...trees>\tExtends tree's scope with the given trees`;
22
- scopeExtend.documentation = "https://weborigami.org/cli/builtins.html#@scope";
@@ -1,25 +0,0 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
4
-
5
- /**
6
- * Returns the scope of the indicated tree or the current scope.
7
- *
8
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @this {AsyncTree|null}
11
- * @param {any} [obj]
12
- */
13
- export default async function getScope(obj) {
14
- assertScopeIsDefined(this, "getScope");
15
- if (obj) {
16
- /** @type {any} */
17
- const tree = Tree.from(obj);
18
- return Scope.getScope(tree);
19
- } else {
20
- return this;
21
- }
22
- }
23
-
24
- getScope.usage = `@scope/get [<tree>]\tReturns the scope of the tree or the current scope`;
25
- getScope.documentation = "https://weborigami.org/cli/builtins.html#@scope";
@@ -1,22 +0,0 @@
1
- import { Scope } from "@weborigami/language";
2
- import { toFunction } from "../../common/utilities.js";
3
-
4
- /**
5
- * Invokes the given function in the context of the current scope.
6
- *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- * @typedef {import("../../../index.ts").Invocable} Invocable
9
- *
10
- * @this {AsyncTree|null}
11
- * @param {AsyncTree} context
12
- * @param {Invocable} invocable
13
- */
14
- export default async function invoke(context, invocable, ...args) {
15
- const scope = Scope.getScope(context);
16
- const fn = toFunction(invocable);
17
- const result = await fn.call(scope, ...args);
18
- return result;
19
- }
20
-
21
- invoke.usage = `@scope/invoke fn, <...args>\tInvoke the function in the current scope`;
22
- invoke.documentation = "https://weborigami.org/cli/builtins.html#@scope";
@@ -1,25 +0,0 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
- import { keySymbol } from "../../common/utilities.js";
4
- import assertScopeIsDefined from "../../misc/assertScopeIsDefined.js";
5
-
6
- /**
7
- * Return a copy of the given tree that has the indicated trees as its scope.
8
- *
9
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
11
- * @param {Treelike} treelike
12
- * @param {...(Treelike|null)} scopeTrees
13
- * @this {AsyncTree|null}
14
- */
15
- export default function scopeSet(treelike, ...scopeTrees) {
16
- assertScopeIsDefined(this, "scopeSet");
17
- const tree = Tree.from(treelike);
18
- const scope = scopeTrees.length === 0 ? this : new Scope(...scopeTrees);
19
- const result = Scope.treeWithScope(tree, scope);
20
- result[keySymbol] = tree[keySymbol];
21
- return result;
22
- }
23
-
24
- scopeSet.usage = `@scope/set <tree>, <...trees>\tReturns a tree copy with the given scope`;
25
- scopeSet.documentation = "https://weborigami.org/cli/builtins.html#@scope";
@@ -1,23 +0,0 @@
1
- import { ObjectTree } from "@weborigami/async-tree";
2
- import { Scope } from "@weborigami/language";
3
-
4
- /**
5
- * A number of transforms accept functions that can accept a single value. This
6
- * helper adds the value and key to the scope as ambients.
7
- *
8
- *
9
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
- * @typedef {import("../../index.js").Invocable} Invocable
11
- *
12
- * @param {AsyncTree|null} scope
13
- * @param {any} value
14
- * @param {any} key
15
- */
16
- export default function addValueKeyToScope(scope, value, key) {
17
- // Add the key and value to the scope as ambients.
18
- const ambients = new ObjectTree({
19
- "@key": key,
20
- _: value,
21
- });
22
- return new Scope(ambients, scope);
23
- }
@@ -1,7 +0,0 @@
1
- export default function assertScopeIsDefined(scope, methodName) {
2
- if (scope === undefined) {
3
- throw new Error(
4
- `${methodName} must be called with a scope. If you don't want to pass a scope, invoke with: ${methodName}.call(null)`
5
- );
6
- }
7
- }