@weborigami/origami 0.0.59 → 0.0.61
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 +3 -7
- package/package.json +4 -4
- 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 +7 -1
- package/src/builtins/@merge.js +3 -18
- package/src/builtins/@once.js +2 -2
- package/src/builtins/@ori.js +12 -8
- 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 +78 -24
- 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/common/utilities.js +2 -3
- 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/misc/origamiHighlightDefinition.js +36 -0
- package/src/server/server.js +3 -10
- package/src/builtins/@arrowsMap.js +0 -25
- 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,5 +1,4 @@
|
|
|
1
1
|
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import { Scope } from "@weborigami/language";
|
|
3
2
|
import builtins from "../builtins/@builtins.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -15,23 +14,18 @@ import builtins from "../builtins/@builtins.js";
|
|
|
15
14
|
*/
|
|
16
15
|
export default function processUnpackedContent(content, parent, attachedData) {
|
|
17
16
|
if (typeof content === "function") {
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return boundFn;
|
|
31
|
-
} else if (
|
|
32
|
-
Tree.isAsyncTree(content) &&
|
|
33
|
-
!(/** @type {any} */ (content).scope)
|
|
34
|
-
) {
|
|
17
|
+
// Bind the function to a target that's the attached data (if it exists) or
|
|
18
|
+
// the parent.
|
|
19
|
+
const base = parent ?? builtins;
|
|
20
|
+
let target;
|
|
21
|
+
if (attachedData) {
|
|
22
|
+
target = Tree.from(attachedData);
|
|
23
|
+
target.parent = base;
|
|
24
|
+
} else {
|
|
25
|
+
target = base;
|
|
26
|
+
}
|
|
27
|
+
return content.bind(target);
|
|
28
|
+
} else if (Tree.isAsyncTree(content) && !content.parent) {
|
|
35
29
|
const result = Object.create(content);
|
|
36
30
|
result.parent = parent;
|
|
37
31
|
return result;
|
package/src/common/utilities.js
CHANGED
|
@@ -91,10 +91,9 @@ export function toFunction(obj) {
|
|
|
91
91
|
*/
|
|
92
92
|
export function toString(object) {
|
|
93
93
|
if (isPlainObject(object) && "@text" in object) {
|
|
94
|
-
|
|
95
|
-
} else {
|
|
96
|
-
return asyncTreeToString(object);
|
|
94
|
+
object = object["@text"];
|
|
97
95
|
}
|
|
96
|
+
return asyncTreeToString(object);
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
/**
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
|
|
2
|
-
import { ObjectTree } from "@weborigami/async-tree";
|
|
3
|
-
import { Scope } from "@weborigami/language";
|
|
4
2
|
import ori from "../builtins/@ori.js";
|
|
5
|
-
import { keySymbol } from "../common/utilities.js";
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* Add support for commands prefixed with `!`.
|
|
@@ -27,13 +24,8 @@ export default function OriCommandTransform(Base) {
|
|
|
27
24
|
return undefined;
|
|
28
25
|
}
|
|
29
26
|
// Key is an Origami command; invoke it.
|
|
30
|
-
const ambientsTree = new ObjectTree({
|
|
31
|
-
"@current": this,
|
|
32
|
-
});
|
|
33
|
-
ambientsTree[keySymbol] = "ori command";
|
|
34
|
-
const extendedScope = new Scope(ambientsTree, Scope.getScope(this));
|
|
35
27
|
const source = key.slice(1).trim();
|
|
36
|
-
value = await ori.call(
|
|
28
|
+
value = await ori.call(this, source, { formatResult: false });
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
return value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function assertTreeIsDefined(tree: any, methodName: string): asserts tree is object
|
|
@@ -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.`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origami language definition for highlight.js
|
|
3
|
+
*/
|
|
4
|
+
export default function origamiHighlightDefinition(hljs) {
|
|
5
|
+
return {
|
|
6
|
+
name: "Origami",
|
|
7
|
+
contains: [
|
|
8
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
9
|
+
hljs.C_BLOCK_COMMENT_MODE,
|
|
10
|
+
hljs.C_NUMBER_MODE,
|
|
11
|
+
hljs.APOS_STRING_MODE,
|
|
12
|
+
hljs.QUOTE_STRING_MODE,
|
|
13
|
+
hljs.BACKSLASH_ESCAPE,
|
|
14
|
+
{
|
|
15
|
+
// Backtick template strings
|
|
16
|
+
className: "string",
|
|
17
|
+
begin: "`",
|
|
18
|
+
end: "`",
|
|
19
|
+
contains: [
|
|
20
|
+
hljs.BACKSLASH_ESCAPE,
|
|
21
|
+
{
|
|
22
|
+
className: "subst",
|
|
23
|
+
begin: "\\$\\{",
|
|
24
|
+
end: "\\}",
|
|
25
|
+
contains: [hljs.C_NUMBER_MODE, hljs.QUOTE_STRING_MODE],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
// Treat all `@` builtins as keywords.
|
|
31
|
+
className: "keyword",
|
|
32
|
+
begin: /@\w+\b/,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
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,25 +0,0 @@
|
|
|
1
|
-
import { Scope, functionResultsMap } from "@weborigami/language";
|
|
2
|
-
import arrowsMapFn from "../common/arrowsMapFn.js";
|
|
3
|
-
import { keySymbol } from "../common/utilities.js";
|
|
4
|
-
import getTreeArgument from "../misc/getTreeArgument.js";
|
|
5
|
-
import builtins from "./@builtins.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Interpret arrow keys in the tree as function calls.
|
|
9
|
-
*
|
|
10
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
11
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
12
|
-
* @this {AsyncTree|null}
|
|
13
|
-
* @param {Treelike} [treelike]
|
|
14
|
-
*/
|
|
15
|
-
export default async function arrowsMap(treelike) {
|
|
16
|
-
const tree = await getTreeArgument(this, arguments, treelike, "arrowsMap");
|
|
17
|
-
const mapped = functionResultsMap(arrowsMapFn()(tree));
|
|
18
|
-
const scope = this ?? builtins;
|
|
19
|
-
const scoped = Scope.treeWithScope(mapped, scope);
|
|
20
|
-
scoped[keySymbol] = "@arrowsMap";
|
|
21
|
-
return scoped;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
arrowsMap.usage = `@arrowsMap <obj>\tInterpret arrow keys in the tree as function calls`;
|
|
25
|
-
arrowsMap.documentation = "https://weborigami.org/language/@arrowsMap.html";
|
|
@@ -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
|
-
}
|