@weborigami/origami 0.5.3 → 0.5.5

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 (90) hide show
  1. package/index.ts +0 -4
  2. package/main.js +20 -3
  3. package/package.json +4 -4
  4. package/src/builtinsProgram.js +1 -10
  5. package/src/common/documentObject.js +2 -2
  6. package/src/common/loadJsDom.js +13 -0
  7. package/src/common/utilities.d.ts +0 -1
  8. package/src/common/utilities.js +0 -36
  9. package/src/dev/ExplorableSiteTransform.js +0 -4
  10. package/src/dev/changes.js +10 -5
  11. package/src/dev/code.js +1 -6
  12. package/src/dev/copy.js +4 -8
  13. package/src/dev/crawler/audit.js +8 -8
  14. package/src/dev/crawler/crawl.js +3 -5
  15. package/src/dev/crawler/findPaths.js +9 -3
  16. package/src/dev/crawler/pathsInHtml.js +4 -3
  17. package/src/dev/debug.js +4 -7
  18. package/src/dev/dev.js +4 -2
  19. package/src/dev/explore.js +4 -3
  20. package/src/dev/help.js +0 -4
  21. package/src/dev/help.yaml +14 -13
  22. package/src/dev/log.js +1 -2
  23. package/src/dev/serve.js +5 -18
  24. package/src/dev/treeDot.js +5 -6
  25. package/src/dev/watch.js +8 -12
  26. package/src/handlers/csv.handler.js +3 -0
  27. package/src/handlers/oridocument.handler.js +1 -1
  28. package/src/origami/csv.js +1 -5
  29. package/src/origami/document.js +2 -5
  30. package/src/origami/htmlDom.js +3 -2
  31. package/src/origami/image/format.js +0 -5
  32. package/src/origami/image/resize.js +0 -3
  33. package/src/origami/inline.js +3 -8
  34. package/src/origami/json.js +2 -6
  35. package/src/origami/jsonKeys.js +4 -10
  36. package/src/origami/mdHtml.js +5 -5
  37. package/src/origami/once.js +3 -7
  38. package/src/origami/ori.js +5 -0
  39. package/src/origami/origami.js +1 -2
  40. package/src/origami/pack.js +0 -5
  41. package/src/origami/post.js +4 -3
  42. package/src/origami/rss.js +7 -8
  43. package/src/origami/sitemap.js +5 -7
  44. package/src/origami/static.js +5 -7
  45. package/src/origami/string.js +0 -4
  46. package/src/origami/unpack.js +0 -5
  47. package/src/protocols/explore.js +0 -2
  48. package/src/protocols/httpstree.js +0 -2
  49. package/src/protocols/httptree.js +0 -2
  50. package/src/protocols/package.js +2 -2
  51. package/src/server/constructResponse.js +2 -2
  52. package/src/server/server.js +2 -33
  53. package/src/common/ConstantTree.js +0 -18
  54. package/src/protocols/js.js +0 -13
  55. package/src/tree/addNextPrevious.js +0 -22
  56. package/src/tree/cache.js +0 -22
  57. package/src/tree/calendar.js +0 -1
  58. package/src/tree/clear.js +0 -19
  59. package/src/tree/concat.js +0 -17
  60. package/src/tree/constant.js +0 -1
  61. package/src/tree/deepMap.js +0 -32
  62. package/src/tree/deepMerge.js +0 -18
  63. package/src/tree/deepReverse.js +0 -23
  64. package/src/tree/deepTake.js +0 -26
  65. package/src/tree/deepValues.js +0 -22
  66. package/src/tree/defineds.js +0 -30
  67. package/src/tree/filter.js +0 -19
  68. package/src/tree/first.js +0 -19
  69. package/src/tree/fromFn.js +0 -29
  70. package/src/tree/globKeys.js +0 -19
  71. package/src/tree/group.js +0 -26
  72. package/src/tree/inners.js +0 -30
  73. package/src/tree/keys.js +0 -15
  74. package/src/tree/length.js +0 -15
  75. package/src/tree/map.d.ts +0 -11
  76. package/src/tree/map.js +0 -125
  77. package/src/tree/mask.js +0 -19
  78. package/src/tree/match.js +0 -79
  79. package/src/tree/merge.js +0 -41
  80. package/src/tree/paginate.js +0 -20
  81. package/src/tree/parent.js +0 -15
  82. package/src/tree/plain.js +0 -15
  83. package/src/tree/regExpKeys.js +0 -19
  84. package/src/tree/reverse.js +0 -17
  85. package/src/tree/setDeep.js +0 -49
  86. package/src/tree/shuffle.js +0 -57
  87. package/src/tree/sort.js +0 -52
  88. package/src/tree/take.js +0 -19
  89. package/src/tree/tree.js +0 -52
  90. package/src/tree/values.js +0 -15
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  Tree,
3
+ getTreeArgument,
3
4
  isPlainObject,
4
- isStringLike,
5
+ isStringlike,
5
6
  toString,
6
7
  trailingSlash,
7
8
  } from "@weborigami/async-tree";
@@ -11,16 +12,14 @@ import { getDescriptor } from "../common/utilities.js";
11
12
  /**
12
13
  * Render a tree in DOT format.
13
14
  *
14
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
15
15
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
16
16
  * @typedef {import("@weborigami/async-tree").PlainObject} PlainObject
17
17
  *
18
- * @this {AsyncTree|null}
19
- * @param {Treelike} [treelike]
18
+ * @param {Treelike} treelike
20
19
  * @param {PlainObject} [options]
21
20
  */
22
21
  export default async function dot(treelike, options = {}) {
23
- const tree = Tree.from(treelike, { deep: true });
22
+ const tree = await getTreeArgument(treelike, "treeDot", { deep: true });
24
23
  const rootLabel = getDescriptor(tree) ?? "";
25
24
  const treeArcs = await statements(tree, "", rootLabel, options);
26
25
  return `digraph g {
@@ -74,7 +73,7 @@ async function statements(tree, nodePath, nodeLabel, options) {
74
73
  const subStatements = await statements(subtree, destPath, null, options);
75
74
  result = result.concat(subStatements);
76
75
  } else {
77
- const label = isStringLike(value)
76
+ const label = isStringlike(value)
78
77
  ? toString(value)
79
78
  : value !== undefined
80
79
  ? await serialize.toYaml(value)
package/src/dev/watch.js CHANGED
@@ -1,22 +1,19 @@
1
- import { Tree } from "@weborigami/async-tree";
1
+ import { constant, getTreeArgument, Tree } from "@weborigami/async-tree";
2
2
  import { formatError, moduleCache } from "@weborigami/language";
3
- import ConstantTree from "../common/ConstantTree.js";
4
- import getTreeArgument from "../common/getTreeArgument.js";
5
3
 
6
4
  /**
7
5
  * Let a tree (e.g., of files) respond to changes.
8
6
  *
9
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
7
+ * @typedef {import("@weborigami/async-tree").Invocable} Invocable
10
8
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
11
- * @typedef {import("../../index.ts").Invocable} Invocable
9
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
10
  *
13
- * @this {AsyncTree|null}
14
- * @param {Treelike} [treelike]
11
+ * @param {Treelike} treelike
15
12
  * @param {Invocable} [fn]
13
+ * @returns {Promise<AsyncTree>}
16
14
  */
17
15
  export default async function watch(treelike, fn) {
18
- /** @type {any} */
19
- const container = await getTreeArgument(this, arguments, treelike, "watch");
16
+ const container = await getTreeArgument(treelike, "watch");
20
17
 
21
18
  // Watch the indicated tree.
22
19
  await /** @type {any} */ (container).watch?.();
@@ -35,7 +32,7 @@ export default async function watch(treelike, fn) {
35
32
  const handle = Object.create(tree);
36
33
 
37
34
  // Reevaluate the function whenever the tree changes.
38
- container.addEventListener?.("change", async () => {
35
+ /** @type {any} */ (container).addEventListener?.("change", async () => {
39
36
  const tree = await evaluateTree(container, fn);
40
37
  moduleCache.resetTimestamp();
41
38
  updateIndirectPointer(handle, tree);
@@ -61,8 +58,7 @@ async function evaluateTree(parent, fn) {
61
58
  message = `Warning: watch expression did not return a tree`;
62
59
  }
63
60
  console.warn(message);
64
- tree = new ConstantTree(message);
65
- tree.parent = parent;
61
+ tree = constant(message);
66
62
  return tree;
67
63
  }
68
64
 
@@ -6,6 +6,9 @@ export default {
6
6
  unpack(packed, options = {}) {
7
7
  const parent = options.parent ?? null;
8
8
  const text = toString(packed);
9
+ if (text === null) {
10
+ throw new TypeError("CSV handler can only unpack text");
11
+ }
9
12
  const data = csvParse(text);
10
13
  // Define `parent` as non-enumerable property
11
14
  Object.defineProperty(data, symbols.parent, {
@@ -64,7 +64,7 @@ export default {
64
64
 
65
65
  // Return a function that adds the given extension
66
66
  function addExtension(resultExtension) {
67
- return (sourceKey) => {
67
+ return (sourceValue, sourceKey) => {
68
68
  if (sourceKey === undefined) {
69
69
  return undefined;
70
70
  }
@@ -1,5 +1,4 @@
1
1
  import { isUnpackable, toPlainValue } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Render the object as text in CSV format.
@@ -7,12 +6,9 @@ import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
7
6
  * The object should a treelike object such as an array. The output will include
8
7
  * a header row with field names taken from the first item in the tree/array.
9
8
  *
10
- * @this {import("@weborigami/types").AsyncTree|null}
11
- * @param {any} [object]
9
+ * @param {any} object
12
10
  */
13
11
  export default async function csv(object) {
14
- assertTreeIsDefined(this, "csv");
15
- object = object ?? this;
16
12
  if (object === undefined) {
17
13
  return undefined;
18
14
  }
@@ -1,15 +1,12 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
1
  import documentObject from "../common/documentObject.js";
3
2
 
4
3
  /**
5
4
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
6
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
5
+ * @typedef {import("@weborigami/async-tree").Stringlike} Stringlike
7
6
  *
8
- * @this {AsyncTree|null}
9
- * @param {StringLike} text
7
+ * @param {Stringlike} text
10
8
  * @param {any} [data]
11
9
  */
12
10
  export default async function documentBuiltin(text, data) {
13
- assertTreeIsDefined(this, "document");
14
11
  return documentObject(text, data);
15
12
  }
@@ -1,6 +1,7 @@
1
- import { JSDOM } from "jsdom";
1
+ import loadJsDom from "../common/loadJsDom.js";
2
2
 
3
- export default function htmlDom(html) {
3
+ export default async function htmlDom(html) {
4
+ const { JSDOM } = await loadJsDom();
4
5
  const dom = JSDOM.fragment(html);
5
6
  return dom;
6
7
  }
@@ -1,19 +1,14 @@
1
1
  import sharp from "sharp";
2
- import assertTreeIsDefined from "../../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Return the image in a different format.
6
5
  *
7
- * @this {import("@weborigami/types").AsyncTree|null}
8
- *
9
- * @this {import("@weborigami/types").AsyncTree|null}
10
6
  * @param {import("@weborigami/async-tree").Packed} input
11
7
  * @param {keyof import("sharp").FormatEnum|import("sharp").AvailableFormatInfo}
12
8
  * format
13
9
  * @param {any} options
14
10
  */
15
11
  export default async function imageFormat(input, format, options) {
16
- assertTreeIsDefined(this, "format");
17
12
  return input instanceof Uint8Array || input instanceof ArrayBuffer
18
13
  ? sharp(input).toFormat(format, options).toBuffer()
19
14
  : undefined;
@@ -1,15 +1,12 @@
1
1
  import sharp from "sharp";
2
- import assertTreeIsDefined from "../../common/assertTreeIsDefined.js";
3
2
 
4
3
  /**
5
4
  * Resize an image.
6
5
  *
7
- * @this {import("@weborigami/types").AsyncTree|null}
8
6
  * @param {import("@weborigami/async-tree").Packed} input
9
7
  * @param {import("sharp").ResizeOptions} options
10
8
  */
11
9
  export default async function resize(input, options) {
12
- assertTreeIsDefined(this, "resize");
13
10
  return input instanceof Uint8Array || input instanceof ArrayBuffer
14
11
  ? sharp(input).rotate().resize(options).toBuffer()
15
12
  : undefined;
@@ -1,5 +1,4 @@
1
1
  import { isUnpackable, symbols, toString } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
3
2
  import documentObject from "../common/documentObject.js";
4
3
  import { oridocumentHandler } from "../handlers/handlers.js";
5
4
 
@@ -8,14 +7,11 @@ import { oridocumentHandler } from "../handlers/handlers.js";
8
7
  * text.
9
8
  *
10
9
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
11
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
10
+ * @typedef {import("@weborigami/async-tree").Stringlike} Stringlike
12
11
  *
13
- * @this {AsyncTree|null}
14
- * @param {StringLike & {_body?: StringLike}} input
12
+ * @param {Stringlike & {_body?: Stringlike}} input
15
13
  */
16
14
  export default async function inline(input) {
17
- assertTreeIsDefined(this, "inline");
18
-
19
15
  // Get the input text and any attached front matter.
20
16
  if (isUnpackable(input)) {
21
17
  input = await input.unpack();
@@ -28,8 +24,7 @@ export default async function inline(input) {
28
24
 
29
25
  const parent =
30
26
  /** @type {any} */ (input).parent ??
31
- /** @type {any} */ (input)[symbols.parent] ??
32
- this;
27
+ /** @type {any} */ (input)[symbols.parent];
33
28
 
34
29
  let front;
35
30
  if (inputIsDocument) {
@@ -1,22 +1,18 @@
1
- /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
2
1
  import { isUnpackable, toPlainValue } from "@weborigami/async-tree";
3
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
4
2
 
5
3
  /**
6
4
  * Render the given object in JSON format.
7
5
  *
8
- * @this {AsyncTree|null}
6
+ * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
7
+ *
9
8
  * @param {any} [obj]
10
9
  */
11
10
  export default async function json(obj) {
12
- assertTreeIsDefined(this, "json");
13
- // A fragment of the logic from getTreeArgument.js
14
11
  if (arguments.length > 0 && obj === undefined) {
15
12
  throw new Error(
16
13
  "An Origami function was called with an initial argument, but its value is undefined."
17
14
  );
18
15
  }
19
- obj = obj ?? this;
20
16
  if (obj === undefined) {
21
17
  return undefined;
22
18
  }
@@ -1,22 +1,16 @@
1
- import { Tree, jsonKeys } from "@weborigami/async-tree";
2
- import getTreeArgument from "../common/getTreeArgument.js";
1
+ import { Tree, getTreeArgument, jsonKeys } from "@weborigami/async-tree";
3
2
 
4
3
  /**
5
4
  * Expose .keys.json for a tree.
6
5
  *
7
6
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
7
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
9
- * @this {AsyncTree|null}
8
+ *
10
9
  * @param {Treelike} treelike
10
+ * @returns {Promise<AsyncTree>}
11
11
  */
12
12
  export default async function jsonKeysBuiltin(treelike) {
13
- const tree = await getTreeArgument(
14
- this,
15
- arguments,
16
- treelike,
17
- "jsonKeys",
18
- true
19
- );
13
+ const tree = await getTreeArgument(treelike, "jsonKeys");
20
14
  return jsonKeysTree(tree);
21
15
  }
22
16
 
@@ -32,11 +32,10 @@ marked.use(
32
32
  /**
33
33
  * Transform markdown to HTML.
34
34
  *
35
- * @typedef {import("@weborigami/async-tree").StringLike} StringLike
36
- * @typedef {import("@weborigami/async-tree").Unpackable<StringLike>} UnpackableStringlike
35
+ * @typedef {import("@weborigami/async-tree").Stringlike} Stringlike
36
+ * @typedef {import("@weborigami/async-tree").Unpackable} Unpackable
37
37
  *
38
- * @this {import("@weborigami/types").AsyncTree|null|void}
39
- * @param {StringLike|UnpackableStringlike} input
38
+ * @param {Stringlike|Unpackable} input
40
39
  */
41
40
  export default async function mdHtml(input) {
42
41
  if (input == null) {
@@ -56,5 +55,6 @@ export default async function mdHtml(input) {
56
55
  return inputIsDocument ? documentObject(html, input) : html;
57
56
  }
58
57
 
59
- mdHtml.key = (sourceKey) => extension.replace(sourceKey, ".md", ".html");
58
+ mdHtml.key = (sourceValue, sourceKey) =>
59
+ extension.replace(sourceKey, ".md", ".html");
60
60
  mdHtml.inverseKey = (resultKey) => extension.replace(resultKey, ".html", ".md");
@@ -1,5 +1,3 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
-
3
1
  const fnPromiseMap = new Map();
4
2
  const codePromiseMap = new Map();
5
3
 
@@ -7,18 +5,16 @@ const codePromiseMap = new Map();
7
5
  * Evaluate the given function only once and cache the result.
8
6
  *
9
7
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
10
- * @this {AsyncTree|null}
8
+ *
11
9
  * @param {Function} fn
12
10
  */
13
11
  export default async function once(fn) {
14
- assertTreeIsDefined(this, "once");
15
-
16
12
  const code = /** @type {any} */ (fn).code;
17
13
  if (code) {
18
14
  // Origami function, cache by code
19
15
  if (!codePromiseMap.has(code)) {
20
16
  // Don't wait for promise to resolve
21
- const promise = fn.call(this);
17
+ const promise = fn();
22
18
  codePromiseMap.set(code, promise);
23
19
  }
24
20
  return codePromiseMap.get(code);
@@ -27,7 +23,7 @@ export default async function once(fn) {
27
23
  // Regular function, cache by function
28
24
  if (!fnPromiseMap.has(fn)) {
29
25
  // Don't wait for promise to resolve
30
- const promise = fn.call(this);
26
+ const promise = fn();
31
27
  fnPromiseMap.set(fn, promise);
32
28
  }
33
29
  return fnPromiseMap.get(fn);
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Tree,
3
3
  getRealmObjectPrototype,
4
+ isStringlike,
4
5
  toString,
5
6
  } from "@weborigami/async-tree";
6
7
  import { compile } from "@weborigami/language";
@@ -27,6 +28,10 @@ export default async function ori(
27
28
  assertTreeIsDefined(this, "ori");
28
29
 
29
30
  // In case expression has come from a file, cast it to a string.
31
+ if (!isStringlike(expression)) {
32
+ throw new TypeError("ori: The expression is not text.");
33
+ }
34
+ // @ts-ignore
30
35
  expression = toString(expression);
31
36
 
32
37
  // Run in the context of `this` if defined
@@ -1,8 +1,7 @@
1
1
  export { extension } from "@weborigami/async-tree";
2
- export { toFunction } from "../common/utilities.js";
3
2
  export { default as help } from "../dev/help.js"; // Alias
4
3
  export { default as document } from "../origami/document.js";
5
- export { default as htmlDom } from "../origami/htmlDom.js";
4
+ // export { default as htmlDom } from "../origami/htmlDom.js";
6
5
  export { default as indexPage } from "../origami/indexPage.js";
7
6
  export { default as inline } from "../origami/inline.js";
8
7
  export { default as jsonKeys } from "../origami/jsonKeys.js";
@@ -1,13 +1,8 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
-
3
1
  /**
4
2
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
5
3
  *
6
- * @this {AsyncTree|null}
7
4
  * @param {any} obj
8
- * @returns
9
5
  */
10
6
  export default function pack(obj) {
11
- assertTreeIsDefined(this, "pack");
12
7
  return obj?.pack?.();
13
8
  }
@@ -1,5 +1,5 @@
1
1
  import {
2
- isStringLike,
2
+ isStringlike,
3
3
  isUnpackable,
4
4
  toPlainValue,
5
5
  toString,
@@ -7,7 +7,8 @@ import {
7
7
  } from "@weborigami/async-tree";
8
8
 
9
9
  /**
10
- * @this {import("@weborigami/types").AsyncTree|null}
10
+ * POST data to the indicated URL.
11
+ *
11
12
  * @param {string} url
12
13
  * @param {any} data
13
14
  */
@@ -23,7 +24,7 @@ export default async function post(url, data) {
23
24
  headers = {
24
25
  "Content-Type": "application/json",
25
26
  };
26
- } else if (isStringLike(data)) {
27
+ } else if (isStringlike(data)) {
27
28
  body = toString(data);
28
29
  headers = {
29
30
  "Content-Type": "text/plain",
@@ -1,16 +1,15 @@
1
- import { Tree } from "@weborigami/async-tree";
1
+ import { getTreeArgument, Tree } from "@weborigami/async-tree";
2
2
  import jsonFeedToRss from "@weborigami/json-feed-to-rss";
3
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
4
3
 
5
4
  /**
6
5
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
7
6
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
8
- * @this {AsyncTree|null}
9
- * @param {Treelike} jsonFeedTree
7
+ *
8
+ * @param {Treelike} jsonFeed
10
9
  * @param {any} options
11
10
  */
12
- export default async function rss(jsonFeedTree, options = {}) {
13
- assertTreeIsDefined(this, "rss");
14
- const jsonFeed = await Tree.plain(jsonFeedTree);
15
- return jsonFeedToRss(jsonFeed, options);
11
+ export default async function rss(jsonFeed, options = {}) {
12
+ const tree = await getTreeArgument(jsonFeed, "rss");
13
+ const jsonFeedPlain = await Tree.plain(tree);
14
+ return jsonFeedToRss(jsonFeedPlain, options);
16
15
  }
@@ -1,6 +1,4 @@
1
- import { Tree } from "@weborigami/async-tree";
2
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
3
- import getTreeArgument from "../common/getTreeArgument.js";
1
+ import { getTreeArgument, Tree } from "@weborigami/async-tree";
4
2
  import { oriHandler } from "../handlers/handlers.js";
5
3
 
6
4
  const templateText = `(urls) => \`<?xml version="1.0" encoding="UTF-8"?>
@@ -15,13 +13,13 @@ const templateText = `(urls) => \`<?xml version="1.0" encoding="UTF-8"?>
15
13
  /**
16
14
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
17
15
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
18
- * @this {AsyncTree|null}
16
+ *
19
17
  * @param {Treelike} treelike
20
18
  * @param {{ assumeSlashes?: boolean, base?: string }} options
19
+ * @returns {Promise<string>}
21
20
  */
22
21
  export default async function sitemap(treelike, options = {}) {
23
- assertTreeIsDefined(this, "sitemap");
24
- const tree = await getTreeArgument(this, arguments, treelike, "sitemap");
22
+ const tree = await getTreeArgument(treelike, "sitemap");
25
23
 
26
24
  // We're only interested in keys that end in .html or with no extension.
27
25
  function test(key) {
@@ -48,6 +46,6 @@ export default async function sitemap(treelike, options = {}) {
48
46
  .map((path) => (path.endsWith("index.html") ? path.slice(0, -10) : path));
49
47
 
50
48
  const templateFn = await oriHandler.unpack(templateText);
51
- const templateResult = await templateFn.call(this, htmlPaths);
49
+ const templateResult = await templateFn(htmlPaths);
52
50
  return String(templateResult);
53
51
  }
@@ -1,5 +1,4 @@
1
- import { Tree, jsonKeys } from "@weborigami/async-tree";
2
- import getTreeArgument from "../common/getTreeArgument.js";
1
+ import { Tree, getTreeArgument, jsonKeys } from "@weborigami/async-tree";
3
2
  import index from "./indexPage.js";
4
3
 
5
4
  /**
@@ -7,14 +6,13 @@ import index from "./indexPage.js";
7
6
  *
8
7
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
8
  * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @this {AsyncTree|null}
9
+ *
11
10
  * @param {Treelike} treelike
11
+ * @returns {Promise<AsyncTree>}
12
12
  */
13
13
  export default async function staticBuiltin(treelike) {
14
- const tree = await getTreeArgument(this, arguments, treelike, "static");
15
- const result = staticTree(tree);
16
- result.parent = this;
17
- return result;
14
+ const tree = await getTreeArgument(treelike, "static");
15
+ return staticTree(tree);
18
16
  }
19
17
 
20
18
  // The name we'll register as a builtin
@@ -1,14 +1,10 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
1
  import { toString } from "../common/utilities.js";
3
2
 
4
3
  /**
5
4
  * Convert an object to a string.
6
5
  *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- * @this {AsyncTree|null}
9
6
  * @param {any} object
10
7
  */
11
8
  export default function stringBuiltin(object) {
12
- assertTreeIsDefined(this, "string");
13
9
  return toString(object);
14
10
  }
@@ -1,14 +1,9 @@
1
- import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
2
-
3
1
  /**
4
2
  * Unpack a packed format like a Uint8Array or ArrayBuffer to a usable form like
5
3
  * text or a plain JavaScript object.
6
4
  *
7
- * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
8
- * @this {AsyncTree|null}
9
5
  * @param {any} obj
10
6
  */
11
7
  export default function unpack(obj) {
12
- assertTreeIsDefined(this, "unpack");
13
8
  return obj?.unpack?.() ?? obj;
14
9
  }
@@ -6,8 +6,6 @@ import constructSiteTree from "../common/constructSiteTree.js";
6
6
  * A site tree with JSON Keys via HTTPS.
7
7
  *
8
8
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @typedef {import("../../index.ts").Invocable} Invocable
11
9
  *
12
10
  * @this {AsyncTree|null}
13
11
  * @param {string} host
@@ -6,8 +6,6 @@ import constructSiteTree from "../common/constructSiteTree.js";
6
6
  * Return a website tree via HTTPS.
7
7
  *
8
8
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @typedef {import("../../index.ts").Invocable} Invocable
11
9
  *
12
10
  * @this {AsyncTree|null}
13
11
  * @param {string} host
@@ -6,8 +6,6 @@ import constructSiteTree from "../common/constructSiteTree.js";
6
6
  * Return a website tree via HTTP.
7
7
  *
8
8
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
9
- * @typedef {import("@weborigami/async-tree").Treelike} Treelike
10
- * @typedef {import("../../index.ts").Invocable} Invocable
11
9
  *
12
10
  * @this {AsyncTree|null}
13
11
  * @param {string} host
@@ -1,4 +1,4 @@
1
- import { Tree, keysFromPath, scope } from "@weborigami/async-tree";
1
+ import { Tree, keysFromPath } from "@weborigami/async-tree";
2
2
  import project from "../origami/project.js";
3
3
 
4
4
  /**
@@ -31,7 +31,7 @@ async function getPackage(parent, organization, name, keys) {
31
31
  }
32
32
  packagePath.push(name);
33
33
 
34
- const parentScope = scope(parent);
34
+ const parentScope = await Tree.scope(parent);
35
35
  const packageRoot = await Tree.traverse(
36
36
  // @ts-ignore
37
37
  parentScope,
@@ -2,7 +2,7 @@ import {
2
2
  extension,
3
3
  isPacked,
4
4
  isPlainObject,
5
- isStringLike,
5
+ isStringlike,
6
6
  SiteTree,
7
7
  Tree,
8
8
  } from "@weborigami/async-tree";
@@ -63,7 +63,7 @@ export default async function constructResponse(request, resource) {
63
63
 
64
64
  if (
65
65
  (mediaType === "application/json" || mediaType === "text/yaml") &&
66
- !isStringLike(resource)
66
+ !isStringlike(resource)
67
67
  ) {
68
68
  // The request is for a JSON or YAML result, and the resource we got isn't
69
69
  // yet a string: convert the resource to JSON or YAML now.
@@ -1,4 +1,4 @@
1
- import { ObjectTree, Tree, keysFromPath } from "@weborigami/async-tree";
1
+ import { Tree, keysFromPath } from "@weborigami/async-tree";
2
2
  import { formatError } from "@weborigami/language";
3
3
  import { ServerResponse } from "node:http";
4
4
  import constructResponse from "./constructResponse.js";
@@ -39,32 +39,6 @@ async function copyResponse(constructed, response) {
39
39
  return true;
40
40
  }
41
41
 
42
- // Extend the tree's scope with the URL's search parameters.
43
- function extendTreeScopeWithParams(tree, url) {
44
- // Create a tree that includes the URL's search parameters.
45
- const params = {};
46
- for (const [key, value] of url.searchParams) {
47
- params[key] = value;
48
- }
49
-
50
- if (Object.keys(params).length === 0) {
51
- // No search parameters, so return the tree as is.
52
- return tree;
53
- }
54
-
55
- const paramTree = new ObjectTree({
56
- "@params": params,
57
- });
58
-
59
- // Create a new tree that's like the original one, but has the parameters in
60
- // its parent hierarchy.
61
- const extendedTree = Object.create(tree);
62
- const realParent = tree.parent;
63
- paramTree.parent = realParent;
64
- extendedTree.parent = paramTree;
65
- return extendedTree;
66
- }
67
-
68
42
  /**
69
43
  * Handle a client request.
70
44
  *
@@ -77,17 +51,12 @@ export async function handleRequest(request, response, tree) {
77
51
  const url = new URL(request.url ?? "", `https://${request.headers.host}`);
78
52
  const keys = keysFromUrl(url);
79
53
 
80
- const extendedTree =
81
- url.searchParams && "parent" in tree
82
- ? extendTreeScopeWithParams(tree, url)
83
- : tree;
84
-
85
54
  const data = request.method === "POST" ? await parsePostData(request) : null;
86
55
 
87
56
  // Ask the tree for the resource with those keys.
88
57
  let resource;
89
58
  try {
90
- resource = await Tree.traverseOrThrow(extendedTree, ...keys);
59
+ resource = await Tree.traverseOrThrow(tree, ...keys);
91
60
 
92
61
  // If resource is a function, invoke to get the object we want to return.
93
62
  // For a POST request, pass the data to the function.