@weborigami/origami 0.5.7 → 0.6.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.
- package/package.json +11 -12
- package/src/cli/cli.js +1 -1
- package/src/common/assertTreeIsDefined.js +1 -1
- package/src/common/documentObject.js +1 -8
- package/src/common/serialize.d.ts +4 -4
- package/src/common/serialize.js +20 -24
- package/src/dev/ExplorableSiteTransform.js +6 -4
- package/src/dev/OriCommandTransform.js +4 -4
- package/src/dev/changes.js +9 -9
- package/src/dev/code.js +0 -1
- package/src/dev/copy.js +32 -6
- package/src/dev/crawler/audit.js +5 -6
- package/src/dev/crawler/crawl.js +10 -11
- package/src/dev/crawler/crawlResources.js +1 -1
- package/src/dev/debug.js +12 -10
- package/src/dev/explore.js +4 -5
- package/src/dev/help.js +0 -1
- package/src/dev/help.yaml +57 -54
- package/src/dev/serve.js +4 -5
- package/src/dev/svg.js +4 -5
- package/src/dev/treeDot.js +6 -6
- package/src/dev/watch.js +8 -8
- package/src/origami/csv.js +1 -1
- package/src/origami/document.js +0 -1
- package/src/origami/indexPage.js +7 -8
- package/src/origami/inline.js +0 -1
- package/src/origami/json.js +0 -1
- package/src/origami/jsonKeys.js +29 -18
- package/src/origami/once.js +0 -1
- package/src/origami/ori.js +2 -3
- package/src/origami/origami.js +1 -0
- package/src/origami/pack.js +0 -1
- package/src/origami/post.js +1 -1
- package/src/origami/rss.js +2 -3
- package/src/origami/sitemap.js +9 -19
- package/src/origami/static.js +44 -19
- package/src/origami/tsv.js +43 -0
- package/src/origami/yaml.js +0 -1
- package/src/server/constructResponse.js +6 -6
- package/src/server/server.js +9 -9
- package/src/common/getTreeArgument.js +0 -67
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,23 +13,22 @@
|
|
|
13
13
|
"main": "./main.js",
|
|
14
14
|
"types": "./index.ts",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@types/node": "24.
|
|
17
|
-
"typescript": "5.9.
|
|
16
|
+
"@types/node": "24.10.1",
|
|
17
|
+
"typescript": "5.9.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@weborigami/async-tree": "0.
|
|
20
|
+
"@weborigami/async-tree": "0.6.0",
|
|
21
21
|
"@weborigami/json-feed-to-rss": "1.0.0",
|
|
22
|
-
"@weborigami/language": "0.
|
|
23
|
-
"@weborigami/types": "0.5.7",
|
|
22
|
+
"@weborigami/language": "0.6.0",
|
|
24
23
|
"css-tree": "3.1.0",
|
|
25
24
|
"graphviz-wasm": "3.0.2",
|
|
26
25
|
"highlight.js": "11.11.1",
|
|
27
|
-
"jsdom": "
|
|
28
|
-
"marked": "
|
|
29
|
-
"marked-gfm-heading-id": "4.1.
|
|
30
|
-
"marked-highlight": "2.2.
|
|
31
|
-
"marked-smartypants": "1.1.
|
|
32
|
-
"sharp": "0.34.
|
|
26
|
+
"jsdom": "27.2.0",
|
|
27
|
+
"marked": "17.0.0",
|
|
28
|
+
"marked-gfm-heading-id": "4.1.3",
|
|
29
|
+
"marked-highlight": "2.2.3",
|
|
30
|
+
"marked-smartypants": "1.1.11",
|
|
31
|
+
"sharp": "0.34.5",
|
|
33
32
|
"yaml": "2.8.1"
|
|
34
33
|
},
|
|
35
34
|
"scripts": {
|
package/src/cli/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ async function main(...args) {
|
|
|
14
14
|
const expression = args.join(" ");
|
|
15
15
|
|
|
16
16
|
// Need to initialize builtins before calling projectRoot, which instantiates
|
|
17
|
-
// an
|
|
17
|
+
// an OrigamiFileMap object that handles extensions, which requires builtins.
|
|
18
18
|
initializeBuiltins();
|
|
19
19
|
|
|
20
20
|
// Find the project root.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tree } from "@weborigami/async-tree";
|
|
2
2
|
|
|
3
3
|
export default function assertTreeIsDefined(tree, methodName) {
|
|
4
|
-
const isValid = tree === null || Tree.
|
|
4
|
+
const isValid = tree === null || Tree.isMap(tree);
|
|
5
5
|
if (!isValid) {
|
|
6
6
|
throw new Error(
|
|
7
7
|
`${methodName} must be called with a tree target. If you don't want to pass a tree, invoke with: ${methodName}.call(null)`
|
|
@@ -26,14 +26,7 @@ export default async function documentObject(input, data) {
|
|
|
26
26
|
text = toString(input);
|
|
27
27
|
inputData = null;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
// document to HandleExtensionsTransform set().
|
|
31
|
-
// const base = {
|
|
32
|
-
// pack() {
|
|
33
|
-
// return txt_handler.pack(this);
|
|
34
|
-
// },
|
|
35
|
-
// };
|
|
36
|
-
// const result = Object.create(base);
|
|
29
|
+
|
|
37
30
|
const result = {};
|
|
38
31
|
Object.assign(result, inputData, data);
|
|
39
32
|
Object.defineProperty(result, "_body", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SyncOrAsyncMap } from "@weborigami/async-tree";
|
|
2
2
|
import type { JsonValue } from "../../index.ts";
|
|
3
3
|
|
|
4
|
-
export function evaluateYaml(text: string, parent?:
|
|
4
|
+
export function evaluateYaml(text: string, parent?: SyncOrAsyncMap|null): Promise<JsonValue>;
|
|
5
5
|
export function parseYaml(text: string): JsonValue;
|
|
6
|
-
export function toJson(
|
|
7
|
-
export function toYaml(
|
|
6
|
+
export function toJson(object: any): Promise<string>;
|
|
7
|
+
export function toYaml(object: any): Promise<string>;
|
package/src/common/serialize.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import("../../index.ts").JsonValue} JsonValue
|
|
3
3
|
* @typedef {import("@weborigami/async-tree").PlainObject} PlainObject
|
|
4
|
-
* @typedef {import("@weborigami/async-tree").
|
|
5
|
-
* @typedef {import("@weborigami/
|
|
4
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
5
|
+
* @typedef {import("@weborigami/async-tree").SyncOrAsyncMap} SyncOrAsyncMap
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
castArraylike,
|
|
10
|
+
SyncMap,
|
|
11
|
+
toPlainValue,
|
|
12
|
+
trailingSlash,
|
|
13
|
+
} from "@weborigami/async-tree";
|
|
9
14
|
import * as YAMLModule from "yaml";
|
|
10
15
|
|
|
11
16
|
// The "yaml" package doesn't seem to provide a default export that the browser can
|
|
@@ -13,21 +18,6 @@ import * as YAMLModule from "yaml";
|
|
|
13
18
|
// @ts-ignore
|
|
14
19
|
const YAML = YAMLModule.default ?? YAMLModule.YAML;
|
|
15
20
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {string} text
|
|
19
|
-
* @param {AsyncTree|null} [parent]
|
|
20
|
-
*/
|
|
21
|
-
export async function evaluateYaml(text, parent) {
|
|
22
|
-
const data = parseYaml(String(text));
|
|
23
|
-
if (Tree.isAsyncTree(data)) {
|
|
24
|
-
data.parent = parent;
|
|
25
|
-
return Tree.plain(data);
|
|
26
|
-
} else {
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
21
|
/**
|
|
32
22
|
* @param {string} text
|
|
33
23
|
* @returns {JsonValue}
|
|
@@ -36,23 +26,29 @@ export function parseYaml(text) {
|
|
|
36
26
|
return YAML.parse(text);
|
|
37
27
|
}
|
|
38
28
|
|
|
29
|
+
function reduceToMap(values, keys, map) {
|
|
30
|
+
// Normalize slashes in keys.
|
|
31
|
+
keys = keys.map(trailingSlash.remove);
|
|
32
|
+
return castArraylike(keys, values, (entries) => new SyncMap(entries));
|
|
33
|
+
}
|
|
34
|
+
|
|
39
35
|
/**
|
|
40
36
|
* Serializes an object as a JSON string.
|
|
41
37
|
*
|
|
42
|
-
* @param {any}
|
|
38
|
+
* @param {any} object
|
|
43
39
|
*/
|
|
44
|
-
export async function toJson(
|
|
45
|
-
const serializable = await toPlainValue(
|
|
40
|
+
export async function toJson(object) {
|
|
41
|
+
const serializable = await toPlainValue(object);
|
|
46
42
|
return JSON.stringify(serializable, null, 2);
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
/**
|
|
50
46
|
* Serializes an object as a JSON string.
|
|
51
47
|
*
|
|
52
|
-
* @param {any}
|
|
48
|
+
* @param {any} object
|
|
53
49
|
* @returns {Promise<string>}
|
|
54
50
|
*/
|
|
55
|
-
export async function toYaml(
|
|
56
|
-
const serializable = await toPlainValue(
|
|
51
|
+
export async function toYaml(object) {
|
|
52
|
+
const serializable = await toPlainValue(object, reduceToMap);
|
|
57
53
|
return YAML.stringify(serializable);
|
|
58
54
|
}
|
|
@@ -18,9 +18,11 @@ import indexPage from "../origami/indexPage.js";
|
|
|
18
18
|
* As a convenience, this transform also provides a default index.html page if
|
|
19
19
|
* the tree doesn't define one.
|
|
20
20
|
*
|
|
21
|
-
* @typedef {import("@weborigami/
|
|
22
|
-
* @typedef {import("../../index.ts").Constructor<
|
|
23
|
-
* @
|
|
21
|
+
* @typedef {import("@weborigami/async-tree").AsyncMap} AsyncMap
|
|
22
|
+
* @typedef {import("../../index.ts").Constructor<Map>} MapConstructor
|
|
23
|
+
* @typedef {import("../../index.ts").Constructor<AsyncMap>} AsyncMapConstructor
|
|
24
|
+
*
|
|
25
|
+
* @param {MapConstructor|AsyncMapConstructor} Base
|
|
24
26
|
*/
|
|
25
27
|
export default function ExplorableSiteTransform(Base) {
|
|
26
28
|
return class ExplorableSite extends Base {
|
|
@@ -38,7 +40,7 @@ export default function ExplorableSiteTransform(Base) {
|
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
if (Tree.
|
|
43
|
+
if (Tree.isMap(value)) {
|
|
42
44
|
// Ensure this transform is applied to any tree result so the user
|
|
43
45
|
// browse into data and trees of classes other than the current class.
|
|
44
46
|
if (!isTransformApplied(ExplorableSiteTransform, value)) {
|
|
@@ -7,11 +7,11 @@ import { projectGlobals } from "@weborigami/language";
|
|
|
7
7
|
* E.g., asking this tree for `!yaml` will invoke the yaml() builtin function,
|
|
8
8
|
* passing the current tree as the first argument.
|
|
9
9
|
*
|
|
10
|
-
* @typedef {import("@weborigami/
|
|
11
|
-
* @typedef {import("../../index.ts").Constructor<
|
|
12
|
-
*
|
|
10
|
+
* @typedef {import("@weborigami/async-tree").AsyncMap} AsyncMap
|
|
11
|
+
* @typedef {import("../../index.ts").Constructor<Map>} MapConstructor
|
|
12
|
+
* @typedef {import("../../index.ts").Constructor<AsyncMap>} AsyncMapConstructor
|
|
13
13
|
*
|
|
14
|
-
* @param {
|
|
14
|
+
* @param {MapConstructor|AsyncMapConstructor} Base
|
|
15
15
|
*/
|
|
16
16
|
export default function OriCommandTransform(Base) {
|
|
17
17
|
return class OriCommand extends Base {
|
package/src/dev/changes.js
CHANGED
|
@@ -4,23 +4,23 @@ import { getTreeArgument, trailingSlash, Tree } from "@weborigami/async-tree";
|
|
|
4
4
|
* Given an old tree and a new tree, return a tree of changes indicated
|
|
5
5
|
* by the values: "added", "changed", or "deleted".
|
|
6
6
|
*
|
|
7
|
-
* @typedef {import("@weborigami/async-tree").
|
|
7
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
8
8
|
*
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
9
|
+
* @param {Maplike} oldMaplike
|
|
10
|
+
* @param {Maplike} newMaplike
|
|
11
11
|
*/
|
|
12
|
-
export default async function changes(
|
|
13
|
-
const oldTree = await getTreeArgument(
|
|
12
|
+
export default async function changes(oldMaplike, newMaplike) {
|
|
13
|
+
const oldTree = await getTreeArgument(oldMaplike, "changes", {
|
|
14
14
|
deep: true,
|
|
15
15
|
position: 0,
|
|
16
16
|
});
|
|
17
|
-
const newTree = await getTreeArgument(
|
|
17
|
+
const newTree = await getTreeArgument(newMaplike, "changes", {
|
|
18
18
|
deep: true,
|
|
19
19
|
position: 1,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const oldKeys =
|
|
23
|
-
const newKeys =
|
|
22
|
+
const oldKeys = await Tree.keys(oldTree);
|
|
23
|
+
const newKeys = await Tree.keys(newTree);
|
|
24
24
|
|
|
25
25
|
const oldKeysNormalized = oldKeys.map(trailingSlash.remove);
|
|
26
26
|
const newKeysNormalized = newKeys.map(trailingSlash.remove);
|
|
@@ -38,7 +38,7 @@ export default async function changes(oldTreelike, newTreelike) {
|
|
|
38
38
|
const oldValue = await oldTree.get(oldKey);
|
|
39
39
|
const newValue = await newTree.get(oldKey);
|
|
40
40
|
|
|
41
|
-
if (Tree.
|
|
41
|
+
if (Tree.isMap(oldValue) && Tree.isMap(newValue)) {
|
|
42
42
|
const treeChanges = await changes(oldValue, newValue);
|
|
43
43
|
if (treeChanges && Object.keys(treeChanges).length > 0) {
|
|
44
44
|
result ??= {};
|
package/src/dev/code.js
CHANGED
package/src/dev/copy.js
CHANGED
|
@@ -4,18 +4,20 @@ import process, { stdout } from "node:process";
|
|
|
4
4
|
import { transformObject } from "../common/utilities.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @typedef {import("@weborigami/
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
7
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
9
8
|
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {
|
|
9
|
+
* @param {Maplike} source
|
|
10
|
+
* @param {Maplike} target
|
|
12
11
|
*/
|
|
13
12
|
export default async function copy(source, target) {
|
|
14
13
|
const sourceTree = await getTreeArgument(source, "copy", { position: 0 });
|
|
15
14
|
let targetTree = await getTreeArgument(target, "copy", { position: 1 });
|
|
16
15
|
|
|
17
16
|
if (stdout.isTTY) {
|
|
18
|
-
targetTree =
|
|
17
|
+
targetTree =
|
|
18
|
+
targetTree instanceof Map
|
|
19
|
+
? transformObject(SyncProgressTransform, targetTree)
|
|
20
|
+
: transformObject(AsyncProgressTransform, targetTree);
|
|
19
21
|
copyRoot = targetTree;
|
|
20
22
|
countFiles = 0;
|
|
21
23
|
countCopied = 0;
|
|
@@ -36,7 +38,7 @@ let countFiles;
|
|
|
36
38
|
let countCopied;
|
|
37
39
|
let copyRoot;
|
|
38
40
|
|
|
39
|
-
function
|
|
41
|
+
function AsyncProgressTransform(Base) {
|
|
40
42
|
return class Progress extends Base {
|
|
41
43
|
async set(...args) {
|
|
42
44
|
countFiles++;
|
|
@@ -59,3 +61,27 @@ function ProgressTransform(Base) {
|
|
|
59
61
|
}
|
|
60
62
|
};
|
|
61
63
|
}
|
|
64
|
+
|
|
65
|
+
function SyncProgressTransform(Base) {
|
|
66
|
+
return class Progress extends Base {
|
|
67
|
+
set(...args) {
|
|
68
|
+
countFiles++;
|
|
69
|
+
copyRoot.showProgress();
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = super.set(...args);
|
|
73
|
+
countCopied++;
|
|
74
|
+
} catch (/** @type {any} */ error) {
|
|
75
|
+
console.error(formatError(error));
|
|
76
|
+
}
|
|
77
|
+
copyRoot.showProgress();
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
showProgress() {
|
|
82
|
+
process.stdout.clearLine(0);
|
|
83
|
+
process.stdout.cursorTo(0);
|
|
84
|
+
process.stdout.write(`Copied ${countCopied} of ${countFiles}`);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
package/src/dev/crawler/audit.js
CHANGED
|
@@ -11,15 +11,14 @@ import { getBaseUrl } from "./utilities.js";
|
|
|
11
11
|
* Crawl the indicated tree and return an audit of any broken links to internal
|
|
12
12
|
* pages or other resources.
|
|
13
13
|
*
|
|
14
|
-
* @typedef
|
|
15
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
14
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
16
15
|
*
|
|
17
|
-
* @param {
|
|
16
|
+
* @param {Maplike} maplike
|
|
18
17
|
* @param {string} [baseHref]
|
|
19
18
|
*/
|
|
20
|
-
export default async function audit(
|
|
21
|
-
const tree = await getTreeArgument(
|
|
22
|
-
const baseUrl = getBaseUrl(baseHref,
|
|
19
|
+
export default async function audit(maplike, baseHref) {
|
|
20
|
+
const tree = await getTreeArgument(maplike, "audit");
|
|
21
|
+
const baseUrl = getBaseUrl(baseHref, maplike);
|
|
23
22
|
|
|
24
23
|
let errors = {};
|
|
25
24
|
let report;
|
package/src/dev/crawler/crawl.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
DeepObjectMap,
|
|
3
3
|
Tree,
|
|
4
4
|
getTreeArgument,
|
|
5
5
|
keysFromPath,
|
|
6
6
|
} from "@weborigami/async-tree";
|
|
7
|
-
import { InvokeFunctionsTransform } from "@weborigami/language";
|
|
8
7
|
import crawlResources from "./crawlResources.js";
|
|
9
8
|
import { addValueToObject, getBaseUrl } from "./utilities.js";
|
|
10
9
|
|
|
@@ -16,16 +15,16 @@ import { addValueToObject, getBaseUrl } from "./utilities.js";
|
|
|
16
15
|
* in-memory. Referenced resources like images will be represented as functions
|
|
17
16
|
* that obtain the requested value from the original site.
|
|
18
17
|
*
|
|
19
|
-
* @typedef
|
|
20
|
-
* @typedef {import("@weborigami/async-tree").
|
|
18
|
+
* @typedef {import("@weborigami/async-tree").AsyncMap} AsyncMap
|
|
19
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
21
20
|
*
|
|
22
|
-
* @param {
|
|
21
|
+
* @param {Maplike} maplike
|
|
23
22
|
* @param {string} [baseHref]
|
|
24
|
-
* @returns {Promise<
|
|
23
|
+
* @returns {Promise<AsyncMap>}
|
|
25
24
|
*/
|
|
26
|
-
export default async function crawlBuiltin(
|
|
27
|
-
const tree = await getTreeArgument(
|
|
28
|
-
const baseUrl = getBaseUrl(baseHref,
|
|
25
|
+
export default async function crawlBuiltin(maplike, baseHref) {
|
|
26
|
+
const tree = await getTreeArgument(maplike, "crawl");
|
|
27
|
+
const baseUrl = getBaseUrl(baseHref, maplike);
|
|
29
28
|
|
|
30
29
|
const cache = {};
|
|
31
30
|
const resources = {};
|
|
@@ -54,8 +53,8 @@ export default async function crawlBuiltin(treelike, baseHref) {
|
|
|
54
53
|
// for something already, that's better than a function that will get that
|
|
55
54
|
// value.
|
|
56
55
|
const result = Tree.deepMerge(
|
|
57
|
-
new
|
|
58
|
-
|
|
56
|
+
new DeepObjectMap(cache),
|
|
57
|
+
await Tree.invokeFunctions(resources)
|
|
59
58
|
);
|
|
60
59
|
return result;
|
|
61
60
|
}
|
|
@@ -136,7 +136,7 @@ async function processPath(tree, path, baseUrl) {
|
|
|
136
136
|
value = await Tree.traverse(tree, ...keys);
|
|
137
137
|
normalizedKeys = keys.slice();
|
|
138
138
|
normalizedPath = path;
|
|
139
|
-
if (Tree.
|
|
139
|
+
if (Tree.isMaplike(value)) {
|
|
140
140
|
// Path is actually a directory. See if we can get the empty string or
|
|
141
141
|
// "index.html".
|
|
142
142
|
value =
|
package/src/dev/debug.js
CHANGED
|
@@ -6,14 +6,14 @@ import OriCommandTransform from "./OriCommandTransform.js";
|
|
|
6
6
|
/**
|
|
7
7
|
* Add debugging features to the indicated tree.
|
|
8
8
|
*
|
|
9
|
-
* @typedef
|
|
10
|
-
* @typedef {import("@weborigami/async-tree").
|
|
9
|
+
* @typedef {import("@weborigami/async-tree").AsyncMap} AsyncMap
|
|
10
|
+
* @typedef {import("@weborigami/async-tree").Maplike} Maplike
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @returns {Promise<
|
|
12
|
+
* @param {Maplike} maplike
|
|
13
|
+
* @returns {Promise<Map|AsyncMap>}
|
|
14
14
|
*/
|
|
15
|
-
export default async function debug(
|
|
16
|
-
let tree = await getTreeArgument(
|
|
15
|
+
export default async function debug(maplike) {
|
|
16
|
+
let tree = await getTreeArgument(maplike, "debug");
|
|
17
17
|
|
|
18
18
|
if (!isTransformApplied(DebugTransform, tree)) {
|
|
19
19
|
tree = transformObject(DebugTransform, tree);
|
|
@@ -26,8 +26,8 @@ export default async function debug(treelike) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* @typedef {import("../../index.ts").Constructor<
|
|
30
|
-
* @param {
|
|
29
|
+
* @typedef {import("../../index.ts").Constructor<AsyncMap>} AsyncMapConstructor
|
|
30
|
+
* @param {AsyncMapConstructor} Base
|
|
31
31
|
*/
|
|
32
32
|
function DebugTransform(Base) {
|
|
33
33
|
return class Debug extends OriCommandTransform(Base) {
|
|
@@ -35,11 +35,12 @@ function DebugTransform(Base) {
|
|
|
35
35
|
let value = await super.get(key);
|
|
36
36
|
const parent = this;
|
|
37
37
|
|
|
38
|
-
// Since this transform is for diagnostic purposes, cast any
|
|
38
|
+
// Since this transform is for diagnostic purposes, cast any maplike
|
|
39
39
|
// result to a tree so we can debug the result too. (Don't do this for
|
|
40
40
|
// functions, as that can be undesirable, e.g., when writing functions
|
|
41
41
|
// that handle POST requests.)
|
|
42
|
-
if (Tree.
|
|
42
|
+
if (Tree.isMaplike(value) && typeof value !== "function") {
|
|
43
|
+
// @ts-ignore
|
|
43
44
|
value = Tree.from(value, { parent });
|
|
44
45
|
if (!isTransformApplied(DebugTransform, value)) {
|
|
45
46
|
value = transformObject(DebugTransform, value);
|
|
@@ -54,6 +55,7 @@ function DebugTransform(Base) {
|
|
|
54
55
|
return content;
|
|
55
56
|
}
|
|
56
57
|
/** @type {any} */
|
|
58
|
+
// @ts-ignore
|
|
57
59
|
let tree = Tree.from(content, { parent });
|
|
58
60
|
if (!isTransformApplied(DebugTransform, tree)) {
|
|
59
61
|
tree = transformObject(DebugTransform, tree);
|
package/src/dev/explore.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
|
|
2
1
|
import { getTreeArgument, Tree } from "@weborigami/async-tree";
|
|
3
|
-
import { Handlers,
|
|
2
|
+
import { Handlers, OrigamiFileMap } from "@weborigami/language";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { fileURLToPath } from "node:url";
|
|
6
5
|
import { getDescriptor } from "../common/utilities.js";
|
|
@@ -11,8 +10,8 @@ let templatePromise;
|
|
|
11
10
|
/**
|
|
12
11
|
* Display a debug/explore page for the current tree.
|
|
13
12
|
*/
|
|
14
|
-
export default async function explore(
|
|
15
|
-
const tree = await getTreeArgument(
|
|
13
|
+
export default async function explore(maplike) {
|
|
14
|
+
const tree = await getTreeArgument(maplike, "explore");
|
|
16
15
|
|
|
17
16
|
// Construct the template page
|
|
18
17
|
const scope = await Tree.scope(tree);
|
|
@@ -44,7 +43,7 @@ async function getScopeData(scope) {
|
|
|
44
43
|
|
|
45
44
|
async function loadTemplate() {
|
|
46
45
|
const folderPath = path.resolve(fileURLToPath(import.meta.url), "..");
|
|
47
|
-
const folder = new
|
|
46
|
+
const folder = new OrigamiFileMap(folderPath);
|
|
48
47
|
const templateFile = await folder.get("explore.ori");
|
|
49
48
|
const template = await Handlers.ori_handler.unpack(templateFile, {
|
|
50
49
|
parent: folder,
|