@weborigami/origami 0.5.4 → 0.5.6
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/index.ts +0 -4
- package/main.js +2 -9
- package/package.json +4 -5
- package/src/cli/cli.js +10 -8
- package/src/common/documentObject.js +3 -3
- package/src/common/loadJsDom.js +13 -0
- package/src/common/utilities.d.ts +0 -2
- package/src/common/utilities.js +1 -55
- package/src/dev/ExplorableSiteTransform.js +2 -6
- package/src/dev/OriCommandTransform.js +25 -7
- package/src/dev/changes.js +10 -5
- package/src/dev/code.js +1 -6
- package/src/dev/copy.js +4 -8
- package/src/dev/crawler/audit.js +8 -8
- package/src/dev/crawler/crawl.js +3 -5
- package/src/dev/crawler/findPaths.js +9 -3
- package/src/dev/crawler/pathsInHtml.js +4 -3
- package/src/dev/debug.js +4 -7
- package/src/dev/dev.js +4 -2
- package/src/dev/explore.js +17 -39
- package/src/dev/help.js +0 -4
- package/src/dev/help.yaml +18 -14
- package/src/dev/log.js +1 -2
- package/src/dev/serve.js +5 -18
- package/src/dev/svg.js +5 -5
- package/src/dev/treeDot.js +5 -6
- package/src/dev/watch.js +8 -12
- package/src/initializeBuiltins.js +23 -0
- package/src/origami/csv.js +1 -5
- package/src/origami/document.js +2 -5
- package/src/origami/fetch.js +4 -8
- package/src/origami/htmlDom.js +3 -2
- package/src/origami/image/format.js +0 -5
- package/src/origami/image/resize.js +0 -3
- package/src/origami/indexPage.js +4 -4
- package/src/origami/inline.js +4 -10
- package/src/origami/json.js +2 -6
- package/src/origami/jsonKeys.js +4 -10
- package/src/origami/jsonParse.js +1 -1
- package/src/origami/mdHtml.js +5 -9
- package/src/origami/mdOutline.js +3 -3
- package/src/origami/once.js +3 -7
- package/src/origami/ori.js +21 -24
- package/src/origami/origami.js +1 -4
- package/src/origami/pack.js +0 -5
- package/src/origami/post.js +4 -3
- package/src/origami/rss.js +7 -8
- package/src/origami/sitemap.js +7 -9
- package/src/origami/static.js +7 -9
- package/src/origami/string.js +1 -14
- package/src/origami/unpack.js +0 -5
- package/src/origami/yaml.js +1 -5
- package/src/origami/yamlParse.js +1 -1
- package/src/server/constructResponse.js +3 -3
- package/src/server/server.js +8 -59
- package/src/builtinsProgram.js +0 -65
- package/src/builtinsShell.js +0 -18
- package/src/cli/getConfig.js +0 -11
- package/src/common/ConstantTree.js +0 -18
- package/src/common/constructHref.js +0 -20
- package/src/common/constructSiteTree.js +0 -34
- package/src/common/fetchAndHandleExtension.js +0 -27
- package/src/handlers/css.handler.js +0 -7
- package/src/handlers/csv.handler.js +0 -126
- package/src/handlers/handlerBuiltins.js +0 -27
- package/src/handlers/handlers.js +0 -33
- package/src/handlers/htm.handler.js +0 -2
- package/src/handlers/html.handler.js +0 -7
- package/src/handlers/jpeg.handler.js +0 -62
- package/src/handlers/jpg.handler.js +0 -2
- package/src/handlers/js.handler.js +0 -20
- package/src/handlers/json.handler.js +0 -27
- package/src/handlers/md.handler.js +0 -7
- package/src/handlers/mjs.handler.js +0 -2
- package/src/handlers/ori.handler.js +0 -55
- package/src/handlers/oridocument.handler.js +0 -78
- package/src/handlers/parseFrontMatter.js +0 -16
- package/src/handlers/processUnpackedContent.js +0 -35
- package/src/handlers/ts.handler.js +0 -1
- package/src/handlers/txt.handler.js +0 -91
- package/src/handlers/wasm.handler.js +0 -17
- package/src/handlers/xhtml.handler.js +0 -2
- package/src/handlers/yaml.handler.js +0 -36
- package/src/handlers/yml.handler.js +0 -2
- package/src/origami/config.js +0 -18
- package/src/origami/project.js +0 -111
- package/src/protocols/explore.js +0 -19
- package/src/protocols/files.js +0 -31
- package/src/protocols/http.js +0 -18
- package/src/protocols/https.js +0 -18
- package/src/protocols/httpstree.js +0 -19
- package/src/protocols/httptree.js +0 -19
- package/src/protocols/js.js +0 -13
- package/src/protocols/node.js +0 -13
- package/src/protocols/package.js +0 -70
- package/src/tree/addNextPrevious.js +0 -22
- package/src/tree/cache.js +0 -22
- package/src/tree/calendar.js +0 -1
- package/src/tree/clear.js +0 -19
- package/src/tree/concat.js +0 -17
- package/src/tree/constant.js +0 -1
- package/src/tree/deepMap.js +0 -32
- package/src/tree/deepMerge.js +0 -18
- package/src/tree/deepReverse.js +0 -23
- package/src/tree/deepTake.js +0 -26
- package/src/tree/deepValues.js +0 -22
- package/src/tree/defineds.js +0 -30
- package/src/tree/filter.js +0 -19
- package/src/tree/first.js +0 -19
- package/src/tree/fromFn.js +0 -29
- package/src/tree/globKeys.js +0 -19
- package/src/tree/group.js +0 -26
- package/src/tree/inners.js +0 -30
- package/src/tree/keys.js +0 -15
- package/src/tree/length.js +0 -15
- package/src/tree/map.d.ts +0 -11
- package/src/tree/map.js +0 -125
- package/src/tree/mask.js +0 -19
- package/src/tree/match.js +0 -79
- package/src/tree/merge.js +0 -41
- package/src/tree/paginate.js +0 -20
- package/src/tree/parent.js +0 -15
- package/src/tree/plain.js +0 -15
- package/src/tree/regExpKeys.js +0 -19
- package/src/tree/reverse.js +0 -17
- package/src/tree/setDeep.js +0 -49
- package/src/tree/shuffle.js +0 -57
- package/src/tree/sort.js +0 -52
- package/src/tree/take.js +0 -19
- package/src/tree/tree.js +0 -52
- package/src/tree/values.js +0 -15
package/src/origami/config.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import project from "./project.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the configuration for the current project.
|
|
5
|
-
*
|
|
6
|
-
* The configuration is the project's config.ori file (if defined in the project
|
|
7
|
-
* root) plus the Origami builtins.
|
|
8
|
-
*
|
|
9
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
10
|
-
*
|
|
11
|
-
* @this {AsyncTree|null}
|
|
12
|
-
* @param {any} [key]
|
|
13
|
-
*/
|
|
14
|
-
export default async function config(key) {
|
|
15
|
-
const projectTree = await project.call(this);
|
|
16
|
-
const projectConfig = projectTree.config;
|
|
17
|
-
return key === undefined ? projectConfig : projectConfig[key];
|
|
18
|
-
}
|
package/src/origami/project.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
|
|
2
|
-
import { OrigamiFiles } from "@weborigami/language";
|
|
3
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
4
|
-
import handlerBuiltins from "../handlers/handlerBuiltins.js";
|
|
5
|
-
import { oriHandler } from "../handlers/handlers.js";
|
|
6
|
-
|
|
7
|
-
const configFileName = "config.ori";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Return an object for the current project including
|
|
11
|
-
*
|
|
12
|
-
* `config`: the evaluated config.ori file
|
|
13
|
-
* `root`: the project's root folder
|
|
14
|
-
*
|
|
15
|
-
* This searches the current directory and its ancestors for an Origami file
|
|
16
|
-
* called `config.ori`. If an Origami configuration file is found, the
|
|
17
|
-
* containing folder is considered to be the project root. This returns a tree
|
|
18
|
-
* for that folder, with the exported configuration as the context for that
|
|
19
|
-
* folder — that is, the tree exported by the configuration will be the scope.
|
|
20
|
-
*
|
|
21
|
-
* If no Origami configuration file is found, the current folder will be
|
|
22
|
-
* returned as a tree, with the builtins as its parent.
|
|
23
|
-
*
|
|
24
|
-
* @this {AsyncTree|null}
|
|
25
|
-
*/
|
|
26
|
-
export default async function project() {
|
|
27
|
-
assertTreeIsDefined(this, "project");
|
|
28
|
-
|
|
29
|
-
const dirname = process.cwd();
|
|
30
|
-
const currentTree = new OrigamiFiles(dirname);
|
|
31
|
-
let config;
|
|
32
|
-
|
|
33
|
-
// Search up the tree for the configuration file or package.json to determine
|
|
34
|
-
// the project root.
|
|
35
|
-
let root;
|
|
36
|
-
const foundConfig = await findAncestorFile(currentTree, configFileName);
|
|
37
|
-
if (foundConfig) {
|
|
38
|
-
root = foundConfig.container;
|
|
39
|
-
// Attach standard extension handlers so config can use them
|
|
40
|
-
root.handlers = handlerBuiltins();
|
|
41
|
-
// Unpack Origami configuration file
|
|
42
|
-
const buffer = foundConfig.value;
|
|
43
|
-
config = await oriHandler.unpack(buffer, {
|
|
44
|
-
key: configFileName,
|
|
45
|
-
parent: root,
|
|
46
|
-
});
|
|
47
|
-
root.config = config;
|
|
48
|
-
} else {
|
|
49
|
-
// No Origami configuration file, look for package.json
|
|
50
|
-
const foundPackageJson = await findAncestorFile(
|
|
51
|
-
currentTree,
|
|
52
|
-
"package.json"
|
|
53
|
-
);
|
|
54
|
-
if (foundPackageJson) {
|
|
55
|
-
// Found package.json; use its parent as the project root
|
|
56
|
-
root = foundPackageJson.container;
|
|
57
|
-
} else {
|
|
58
|
-
// No package.json found; use the current directory as root
|
|
59
|
-
root = currentTree;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Merge config if present into handlers
|
|
64
|
-
root.handlers = config
|
|
65
|
-
? {
|
|
66
|
-
...handlerBuiltins(),
|
|
67
|
-
...configHandlers(config),
|
|
68
|
-
}
|
|
69
|
-
: handlerBuiltins();
|
|
70
|
-
|
|
71
|
-
return root;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Find the first ancestor of the given folder that contains a file with the
|
|
75
|
-
// given name. Return the container and the file contents.
|
|
76
|
-
async function findAncestorFile(start, fileName) {
|
|
77
|
-
let container = start;
|
|
78
|
-
while (container) {
|
|
79
|
-
const value = await container.get(fileName);
|
|
80
|
-
if (value) {
|
|
81
|
-
// Found the desired file
|
|
82
|
-
return {
|
|
83
|
-
container,
|
|
84
|
-
value,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
// Not found; try the parent
|
|
88
|
-
const parent = await container.get("..");
|
|
89
|
-
if (
|
|
90
|
-
!parent ||
|
|
91
|
-
(parent.path && container.path && parent.path === container.path)
|
|
92
|
-
) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
container = parent;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Not found
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Return an object with all `.handler` keys from the config
|
|
103
|
-
function configHandlers(config) {
|
|
104
|
-
const handlers = {};
|
|
105
|
-
for (const key in config) {
|
|
106
|
-
if (key.endsWith(".handler")) {
|
|
107
|
-
handlers[key] = config[key];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return handlers;
|
|
111
|
-
}
|
package/src/protocols/explore.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ExplorableSiteTree } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
import constructSiteTree from "../common/constructSiteTree.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A site tree with JSON Keys via HTTPS.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
* @typedef {import("../../index.ts").Invocable} Invocable
|
|
11
|
-
*
|
|
12
|
-
* @this {AsyncTree|null}
|
|
13
|
-
* @param {string} host
|
|
14
|
-
* @param {...string} keys
|
|
15
|
-
*/
|
|
16
|
-
export default function explore(host, ...keys) {
|
|
17
|
-
assertTreeIsDefined(this, "explore");
|
|
18
|
-
return constructSiteTree("https:", ExplorableSiteTree, this, host, ...keys);
|
|
19
|
-
}
|
package/src/protocols/files.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { OrigamiFiles, getHandlers } from "@weborigami/language";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {string[]} keys
|
|
12
|
-
*/
|
|
13
|
-
export default async function files(...keys) {
|
|
14
|
-
assertTreeIsDefined(this, "files");
|
|
15
|
-
|
|
16
|
-
// If path begins with `~`, treat it relative to the home directory.
|
|
17
|
-
// Otherwise, treat it relative to the current working directory.
|
|
18
|
-
let relativePath = keys.join(path.sep);
|
|
19
|
-
let basePath;
|
|
20
|
-
if (relativePath.startsWith("~")) {
|
|
21
|
-
basePath = os.homedir();
|
|
22
|
-
relativePath = relativePath.slice(2);
|
|
23
|
-
} else {
|
|
24
|
-
basePath = process.cwd();
|
|
25
|
-
}
|
|
26
|
-
const resolved = path.resolve(basePath, relativePath);
|
|
27
|
-
|
|
28
|
-
const result = new OrigamiFiles(resolved);
|
|
29
|
-
/** @type {any} */ (result).handlers = getHandlers(this);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
package/src/protocols/http.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
2
|
-
import constructHref from "../common/constructHref.js";
|
|
3
|
-
import fetchAndHandleExtension from "../common/fetchAndHandleExtension.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Retrieve the indicated web resource via HTTP.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {string} host
|
|
12
|
-
* @param {...string} keys
|
|
13
|
-
*/
|
|
14
|
-
export default async function http(host, ...keys) {
|
|
15
|
-
assertTreeIsDefined(this, "http");
|
|
16
|
-
const href = constructHref("http:", host, ...keys);
|
|
17
|
-
return fetchAndHandleExtension.call(this, href);
|
|
18
|
-
}
|
package/src/protocols/https.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
2
|
-
import constructHref from "../common/constructHref.js";
|
|
3
|
-
import fetchAndHandleExtension from "../common/fetchAndHandleExtension.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Retrieve the indicated web resource via HTTPS.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {string} host
|
|
12
|
-
* @param {...string} keys
|
|
13
|
-
*/
|
|
14
|
-
export default async function https(host, ...keys) {
|
|
15
|
-
assertTreeIsDefined(this, "https");
|
|
16
|
-
const href = constructHref("https:", host, ...keys);
|
|
17
|
-
return fetchAndHandleExtension.call(this, href);
|
|
18
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SiteTree } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
import constructSiteTree from "../common/constructSiteTree.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Return a website tree via HTTPS.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
* @typedef {import("../../index.ts").Invocable} Invocable
|
|
11
|
-
*
|
|
12
|
-
* @this {AsyncTree|null}
|
|
13
|
-
* @param {string} host
|
|
14
|
-
* @param {...string} keys
|
|
15
|
-
*/
|
|
16
|
-
export default function httpstree(host, ...keys) {
|
|
17
|
-
assertTreeIsDefined(this, "treehttps");
|
|
18
|
-
return constructSiteTree("https:", SiteTree, this, host, ...keys);
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SiteTree } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
import constructSiteTree from "../common/constructSiteTree.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Return a website tree via HTTP.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
* @typedef {import("../../index.ts").Invocable} Invocable
|
|
11
|
-
*
|
|
12
|
-
* @this {AsyncTree|null}
|
|
13
|
-
* @param {string} host
|
|
14
|
-
* @param {...string} keys
|
|
15
|
-
*/
|
|
16
|
-
export default function httptree(host, ...keys) {
|
|
17
|
-
assertTreeIsDefined(this, "httptree");
|
|
18
|
-
return constructSiteTree("http:", SiteTree, this, host, ...keys);
|
|
19
|
-
}
|
package/src/protocols/js.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import { attachWarning, jsGlobals } from "@weborigami/language";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @this {import("@weborigami/types").AsyncTree}
|
|
6
|
-
*/
|
|
7
|
-
export default async function js(...keys) {
|
|
8
|
-
const result = await Tree.traverseOrThrow.call(this, jsGlobals, ...keys);
|
|
9
|
-
return attachWarning(
|
|
10
|
-
result,
|
|
11
|
-
"The js:<name> protocol is deprecated. Drop the js: and just use <name> instead."
|
|
12
|
-
);
|
|
13
|
-
}
|
package/src/protocols/node.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { trailingSlash, Tree } from "@weborigami/async-tree";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The node: protocol does a dynamic import from the `node:` namespace.
|
|
5
|
-
*
|
|
6
|
-
* @param {string[]} keys
|
|
7
|
-
*/
|
|
8
|
-
export default async function node(...keys) {
|
|
9
|
-
const key = keys.shift();
|
|
10
|
-
const normalized = trailingSlash.remove(key);
|
|
11
|
-
const module = await import(`node:${normalized}`);
|
|
12
|
-
return keys.length > 0 ? Tree.traverse(module, ...keys) : module;
|
|
13
|
-
}
|
package/src/protocols/package.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Tree, keysFromPath, scope } from "@weborigami/async-tree";
|
|
2
|
-
import project from "../origami/project.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @this {import("@weborigami/types").AsyncTree|null}
|
|
6
|
-
* @param {string[]} keys
|
|
7
|
-
*/
|
|
8
|
-
export default async function packageNamespace(...keys) {
|
|
9
|
-
const parent = this ?? (await project.call(null));
|
|
10
|
-
|
|
11
|
-
let name = keys.shift();
|
|
12
|
-
let organization;
|
|
13
|
-
if (name?.startsWith("@")) {
|
|
14
|
-
// First key is an npm organization
|
|
15
|
-
organization = name;
|
|
16
|
-
if (keys.length === 0) {
|
|
17
|
-
// Return a function that will process the next key
|
|
18
|
-
return async (name, ...keys) =>
|
|
19
|
-
getPackage(parent, organization, name, keys);
|
|
20
|
-
}
|
|
21
|
-
name = keys.shift();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return getPackage(parent, organization, name, keys);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function getPackage(parent, organization, name, keys) {
|
|
28
|
-
const packagePath = ["node_modules"];
|
|
29
|
-
if (organization) {
|
|
30
|
-
packagePath.push(organization);
|
|
31
|
-
}
|
|
32
|
-
packagePath.push(name);
|
|
33
|
-
|
|
34
|
-
const parentScope = scope(parent);
|
|
35
|
-
const packageRoot = await Tree.traverse(
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
parentScope,
|
|
38
|
-
...packagePath
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
if (!packageRoot) {
|
|
42
|
-
throw new Error(`Can't find ${packagePath.join("/")}`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const mainPath = await Tree.traverse(packageRoot, "package.json", "main");
|
|
46
|
-
if (!mainPath) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
`node_modules/${keys.join(
|
|
49
|
-
"/"
|
|
50
|
-
)} doesn't contain a package.json with a "main" entry.`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const mainKeys = keysFromPath(mainPath);
|
|
55
|
-
const mainContainerKeys = mainKeys.slice(0, -1);
|
|
56
|
-
const mainFileName = mainKeys[mainKeys.length - 1];
|
|
57
|
-
const mainContainer = await Tree.traverse(packageRoot, ...mainContainerKeys);
|
|
58
|
-
const packageExports = await mainContainer.import(mainFileName);
|
|
59
|
-
|
|
60
|
-
const result =
|
|
61
|
-
keys.length > 0
|
|
62
|
-
? await Tree.traverse(packageExports, ...keys)
|
|
63
|
-
: packageExports;
|
|
64
|
-
|
|
65
|
-
if (Tree.isAsyncTree(result)) {
|
|
66
|
-
result.parent = parent;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { addNextPrevious, symbols } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Add nextKey/previousKey properties to values.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
*
|
|
9
|
-
* @this {AsyncTree|null}
|
|
10
|
-
* @param {import("@weborigami/async-tree").Treelike} treelike
|
|
11
|
-
*/
|
|
12
|
-
export default async function addNextPreviousBuiltin(treelike) {
|
|
13
|
-
const tree = await getTreeArgument(
|
|
14
|
-
this,
|
|
15
|
-
arguments,
|
|
16
|
-
treelike,
|
|
17
|
-
"addNextPrevious"
|
|
18
|
-
);
|
|
19
|
-
const result = await addNextPrevious(tree);
|
|
20
|
-
result[symbols.parent] = this;
|
|
21
|
-
return result;
|
|
22
|
-
}
|
package/src/tree/cache.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Tree, cache } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Caches tree values in a storable cache.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncMutableTree} AsyncMutableTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
* @param {Treelike} sourceTreelike
|
|
11
|
-
* @param {Treelike} [cacheTreelike]
|
|
12
|
-
* @this {AsyncTree|null}
|
|
13
|
-
*/
|
|
14
|
-
export default async function cacheBuiltin(sourceTreelike, cacheTreelike) {
|
|
15
|
-
assertTreeIsDefined(this, "cache");
|
|
16
|
-
/** @type {any} */
|
|
17
|
-
const cacheTree = cacheTreelike
|
|
18
|
-
? Tree.from(cacheTreelike, { parent: this })
|
|
19
|
-
: undefined;
|
|
20
|
-
const result = cache(sourceTreelike, cacheTree);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
package/src/tree/calendar.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { calendarTree as default } from "@weborigami/async-tree";
|
package/src/tree/clear.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
6
|
-
*
|
|
7
|
-
* @this {AsyncTree|null}
|
|
8
|
-
* @param {import("@weborigami/async-tree").Treelike} treelike
|
|
9
|
-
*/
|
|
10
|
-
export default async function clear(treelike) {
|
|
11
|
-
const tree = await getTreeArgument(this, arguments, treelike, "clear");
|
|
12
|
-
if (!Tree.isAsyncMutableTree(tree)) {
|
|
13
|
-
throw new TypeError("clean: the given tree is read-only.");
|
|
14
|
-
}
|
|
15
|
-
const keys = Array.from(await tree.keys());
|
|
16
|
-
const promises = keys.map((key) => tree.set(key, undefined));
|
|
17
|
-
await Promise.all(promises);
|
|
18
|
-
return tree;
|
|
19
|
-
}
|
package/src/tree/concat.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import { ops } from "@weborigami/language";
|
|
3
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Concatenate the text content of objects or trees.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {any[]} args
|
|
12
|
-
*/
|
|
13
|
-
export default async function concat(...args) {
|
|
14
|
-
assertTreeIsDefined(this, "concat");
|
|
15
|
-
const tree = args.length === 0 ? this : Tree.from(args, { parent: this });
|
|
16
|
-
return ops.concat.call(this, tree);
|
|
17
|
-
}
|
package/src/tree/constant.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { constantTree as default } from "@weborigami/async-tree";
|
package/src/tree/deepMap.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
import map from "./map.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Shorthand for calling `map` with `deep: true` option.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
* @typedef {import("@weborigami/async-tree").ValueKeyFn} ValueKeyFn
|
|
11
|
-
* @typedef {import("./map.d.ts").TreeMapOptions} TreeMapOptions
|
|
12
|
-
*
|
|
13
|
-
* @this {AsyncTree|null}
|
|
14
|
-
* @param {Treelike} treelike
|
|
15
|
-
* @param {ValueKeyFn|TreeMapOptions} operation
|
|
16
|
-
*/
|
|
17
|
-
export default async function deepMap(treelike, operation) {
|
|
18
|
-
const tree = await getTreeArgument(
|
|
19
|
-
this,
|
|
20
|
-
arguments,
|
|
21
|
-
treelike,
|
|
22
|
-
"deepMap",
|
|
23
|
-
true
|
|
24
|
-
);
|
|
25
|
-
/** @type {TreeMapOptions} */
|
|
26
|
-
const options = isPlainObject(operation)
|
|
27
|
-
? // Dictionary
|
|
28
|
-
{ ...operation, deep: true }
|
|
29
|
-
: // Function
|
|
30
|
-
{ deep: true, value: operation };
|
|
31
|
-
return map.call(this, tree, options);
|
|
32
|
-
}
|
package/src/tree/deepMerge.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { deepMerge } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a tree that's the result of deep merging the given trees.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
|
-
* @this {AsyncTree|null}
|
|
10
|
-
* @param {Treelike[]} trees
|
|
11
|
-
*/
|
|
12
|
-
export default async function treeDeepMerge(...trees) {
|
|
13
|
-
assertTreeIsDefined(this, "deepMerge");
|
|
14
|
-
// Merge the trees.
|
|
15
|
-
const result = deepMerge(...trees);
|
|
16
|
-
result.parent = this;
|
|
17
|
-
return result;
|
|
18
|
-
}
|
package/src/tree/deepReverse.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { deepReverse } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Reverse the order of keys at all levels of the tree.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {Treelike} [treelike]
|
|
12
|
-
*/
|
|
13
|
-
export default async function deepReverseBuiltin(treelike) {
|
|
14
|
-
const tree = await getTreeArgument(
|
|
15
|
-
this,
|
|
16
|
-
arguments,
|
|
17
|
-
treelike,
|
|
18
|
-
"deepReverse",
|
|
19
|
-
true
|
|
20
|
-
);
|
|
21
|
-
const reversed = deepReverse(tree);
|
|
22
|
-
return reversed;
|
|
23
|
-
}
|
package/src/tree/deepTake.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { deepTake as deepTakeTransform } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Returns a function that traverses a tree deeply and returns the values of the
|
|
6
|
-
* first `count` keys.
|
|
7
|
-
*
|
|
8
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
9
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
10
|
-
*
|
|
11
|
-
* @this {AsyncTree|null}
|
|
12
|
-
* @param {Treelike} treelike
|
|
13
|
-
* @param {number} count
|
|
14
|
-
*/
|
|
15
|
-
export default async function deepTake(treelike, count) {
|
|
16
|
-
const tree = await getTreeArgument(
|
|
17
|
-
this,
|
|
18
|
-
arguments,
|
|
19
|
-
treelike,
|
|
20
|
-
"deepTake",
|
|
21
|
-
true
|
|
22
|
-
);
|
|
23
|
-
const taken = await deepTakeTransform(tree, count);
|
|
24
|
-
taken.parent = this;
|
|
25
|
-
return taken;
|
|
26
|
-
}
|
package/src/tree/deepValues.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { deepValues } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Return the in-order exterior values of a tree as a flat array.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {Treelike} [treelike]
|
|
12
|
-
*/
|
|
13
|
-
export default async function deepValuesBuiltin(treelike) {
|
|
14
|
-
const tree = await getTreeArgument(
|
|
15
|
-
this,
|
|
16
|
-
arguments,
|
|
17
|
-
treelike,
|
|
18
|
-
"deepValues",
|
|
19
|
-
true
|
|
20
|
-
);
|
|
21
|
-
return deepValues(tree);
|
|
22
|
-
}
|
package/src/tree/defineds.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@weborigami/async-tree";
|
|
2
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Return only the defined (not `undefined`) values in the tree.
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {Treelike} treelike
|
|
12
|
-
*/
|
|
13
|
-
export default async function defineds(treelike) {
|
|
14
|
-
const tree = await getTreeArgument(this, arguments, treelike, "defineds");
|
|
15
|
-
|
|
16
|
-
const result = await Tree.mapReduce(tree, null, async (values, keys) => {
|
|
17
|
-
const object = {};
|
|
18
|
-
let someValuesExist = false;
|
|
19
|
-
for (let i = 0; i < keys.length; i++) {
|
|
20
|
-
const value = values[i];
|
|
21
|
-
if (value != null) {
|
|
22
|
-
someValuesExist = true;
|
|
23
|
-
object[keys[i]] = values[i];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return someValuesExist ? object : null;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return result;
|
|
30
|
-
}
|
package/src/tree/filter.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { filter } from "@weborigami/async-tree";
|
|
2
|
-
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Apply a filter to a tree
|
|
6
|
-
*
|
|
7
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
8
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
9
|
-
*
|
|
10
|
-
* @this {AsyncTree|null}
|
|
11
|
-
* @param {Treelike} sourceTreelike
|
|
12
|
-
* @param {Treelike} filterTreelike
|
|
13
|
-
*/
|
|
14
|
-
export default async function filterBuiltin(sourceTreelike, filterTreelike) {
|
|
15
|
-
assertTreeIsDefined(this, "filter");
|
|
16
|
-
const result = filter(sourceTreelike, filterTreelike);
|
|
17
|
-
result.parent = this;
|
|
18
|
-
return result;
|
|
19
|
-
}
|
package/src/tree/first.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import getTreeArgument from "../common/getTreeArgument.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return the first value in the tree.
|
|
5
|
-
*
|
|
6
|
-
* @typedef {import("@weborigami/types").AsyncTree} AsyncTree
|
|
7
|
-
* @typedef {import("@weborigami/async-tree").Treelike} Treelike
|
|
8
|
-
* @this {AsyncTree|null}
|
|
9
|
-
* @param {Treelike} [treelike]
|
|
10
|
-
*/
|
|
11
|
-
export default async function first(treelike) {
|
|
12
|
-
const tree = await getTreeArgument(this, arguments, treelike, "first");
|
|
13
|
-
for (const key of await tree.keys()) {
|
|
14
|
-
// Just return first value immediately.
|
|
15
|
-
const value = await tree.get(key);
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|