@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.
- package/exports/exports.js +2 -6
- package/package.json +4 -4
- package/src/builtins/@arrowsMap.js +4 -5
- package/src/builtins/@breakpoint.js +12 -0
- package/src/builtins/@cache.js +3 -6
- package/src/builtins/@concat.js +3 -4
- package/src/builtins/@config.js +3 -12
- package/src/builtins/@constructor.js +3 -7
- package/src/builtins/@copy.js +2 -2
- package/src/builtins/@crawl.js +4 -6
- package/src/builtins/@debug.js +5 -6
- package/src/builtins/@deepMap.js +2 -2
- package/src/builtins/@deepMapFn.js +2 -2
- package/src/builtins/@deepMerge.js +3 -18
- package/src/builtins/@deepReverse.js +1 -3
- package/src/builtins/@deepTakeFn.js +5 -6
- package/src/builtins/@defineds.js +4 -7
- package/src/builtins/@document.js +2 -2
- package/src/builtins/@exceptions.js +1 -5
- package/src/builtins/@explore.js +15 -14
- package/src/builtins/@files.js +4 -6
- package/src/builtins/@filter.js +3 -6
- package/src/builtins/@fnTree.js +8 -22
- package/src/builtins/@globs.js +3 -6
- package/src/builtins/@groupFn.js +7 -8
- package/src/builtins/@help.js +2 -2
- package/src/builtins/@http.js +2 -2
- package/src/builtins/@https.js +2 -2
- package/src/builtins/@if.js +2 -2
- package/src/builtins/@image/format.js +2 -2
- package/src/builtins/@image/formatFn.js +6 -3
- package/src/builtins/@image/resize.js +2 -2
- package/src/builtins/@image/resizeFn.js +6 -3
- package/src/builtins/@inherited.js +2 -2
- package/src/builtins/@inline.js +5 -9
- package/src/builtins/@inners.js +0 -1
- package/src/builtins/@invoke.js +4 -7
- package/src/builtins/@json.js +3 -3
- package/src/builtins/@map.js +2 -2
- package/src/builtins/@mapFn.js +9 -10
- package/src/builtins/@match.js +17 -16
- package/src/builtins/@mdHtml.js +4 -1
- package/src/builtins/@merge.js +3 -18
- package/src/builtins/@once.js +2 -2
- package/src/builtins/@ori.js +6 -6
- package/src/builtins/@pack.js +2 -2
- package/src/builtins/@package.js +4 -8
- package/src/builtins/@paginateFn.js +1 -6
- package/src/builtins/@perf.js +2 -2
- package/src/builtins/@project.js +31 -22
- package/src/builtins/@reverse.js +1 -3
- package/src/builtins/@rss.js +2 -2
- package/src/builtins/@serve.js +2 -2
- package/src/builtins/@sitemap.js +4 -1
- package/src/builtins/@sortFn.js +6 -7
- package/src/builtins/@string.js +2 -2
- package/src/builtins/@takeFn.js +5 -6
- package/src/builtins/@treeHttp.js +2 -2
- package/src/builtins/@treeHttps.js +2 -2
- package/src/builtins/@unpack.js +2 -2
- package/src/builtins/@watch.js +5 -12
- package/src/builtins/@yaml.js +3 -3
- package/src/builtins/ori_handler.js +3 -3
- package/src/builtins/~.js +3 -3
- package/src/cli/cli.js +6 -19
- package/src/common/ConstantTree.js +1 -0
- package/src/common/ExplorableSiteTransform.js +9 -12
- package/src/common/documentObject.js +2 -2
- package/src/common/processUnpackedContent.js +12 -18
- package/src/misc/OriCommandTransform.js +1 -9
- package/src/misc/assertTreeIsDefined.d.ts +1 -0
- package/src/misc/assertTreeIsDefined.js +7 -0
- package/src/misc/getTreeArgument.js +11 -12
- package/src/server/server.js +3 -10
- package/src/builtins/@scope/extend.js +0 -22
- package/src/builtins/@scope/get.js +0 -25
- package/src/builtins/@scope/invoke.js +0 -22
- package/src/builtins/@scope/set.js +0 -25
- package/src/common/addValueKeyToScope.js +0 -23
- 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
|
|
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}
|
|
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
|
-
|
|
24
|
+
parent,
|
|
26
25
|
args,
|
|
27
26
|
treelike,
|
|
28
27
|
methodName
|
|
29
28
|
) {
|
|
30
|
-
|
|
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
|
|
40
|
-
if (!tree.parent
|
|
41
|
-
tree =
|
|
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 (!
|
|
52
|
-
// Should never happen because
|
|
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
|
|
53
|
+
`${methodName} was called with no tree argument and no parent.`
|
|
55
54
|
);
|
|
56
55
|
}
|
|
57
|
-
return
|
|
56
|
+
return parent;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
throw new Error(`${methodName}: The first argument was undefined.`);
|
package/src/server/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepObjectTree, Tree, keysFromPath } from "@weborigami/async-tree";
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
}
|