@weborigami/origami 0.0.64-beta.2 → 0.0.65-beta.1

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.
@@ -4,6 +4,7 @@ export { default as basename } from "../src/builtins/@basename.js";
4
4
  export { default as breakpoint } from "../src/builtins/@breakpoint.js";
5
5
  export { default as builtins } from "../src/builtins/@builtins.js";
6
6
  export { default as cache } from "../src/builtins/@cache.js";
7
+ export { default as calendarTree } from "../src/builtins/@calendarTree.js";
7
8
  export { default as changes } from "../src/builtins/@changes.js";
8
9
  export { default as clean } from "../src/builtins/@clean.js";
9
10
  export { default as concat } from "../src/builtins/@concat.js";
@@ -46,10 +47,11 @@ export { default as inners } from "../src/builtins/@inners.js";
46
47
  export { default as invoke } from "../src/builtins/@invoke.js";
47
48
  export { default as js } from "../src/builtins/@js.js";
48
49
  export { default as json } from "../src/builtins/@json.js";
50
+ export { default as jsonKeys } from "../src/builtins/@jsonKeys.js";
49
51
  export { default as jsonParse } from "../src/builtins/@jsonParse.js";
50
52
  export { default as keys } from "../src/builtins/@keys.js";
51
- export { default as keysJson } from "../src/builtins/@keysJson.js";
52
53
  export { default as length } from "../src/builtins/@length.js";
54
+ export { default as log } from "../src/builtins/@log.js";
53
55
  export { default as map } from "../src/builtins/@map.js";
54
56
  export { default as mapFn } from "../src/builtins/@mapFn.js";
55
57
  export { default as match } from "../src/builtins/@match.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/origami",
3
- "version": "0.0.64-beta.2",
3
+ "version": "0.0.65-beta.1",
4
4
  "description": "Web Origami language, CLI, framework, and server",
5
5
  "type": "module",
6
6
  "repository": {
@@ -13,22 +13,22 @@
13
13
  "main": "./exports/exports.js",
14
14
  "types": "./index.ts",
15
15
  "devDependencies": {
16
- "@types/node": "20.14.9",
17
- "typescript": "5.5.3"
16
+ "@types/node": "22.5.4",
17
+ "typescript": "5.5.4"
18
18
  },
19
19
  "dependencies": {
20
- "@weborigami/async-tree": "0.0.64-beta.2",
21
- "@weborigami/language": "0.0.64-beta.2",
22
- "@weborigami/types": "0.0.64-beta.2",
20
+ "@weborigami/async-tree": "https://gitpkg.vercel.app/WebOrigami/origami/async-tree?b5d8eebf",
21
+ "@weborigami/language": "https://gitpkg.vercel.app/WebOrigami/origami/language?b5d8eebf",
22
+ "@weborigami/types": "0.0.65-beta.1",
23
23
  "exif-parser": "0.1.12",
24
24
  "graphviz-wasm": "3.0.2",
25
- "highlight.js": "11.9.0",
26
- "marked": "13.0.1",
27
- "marked-gfm-heading-id": "4.0.0",
28
- "marked-highlight": "2.1.3",
29
- "marked-smartypants": "1.1.7",
30
- "sharp": "0.33.4",
31
- "yaml": "2.4.5"
25
+ "highlight.js": "11.10.0",
26
+ "marked": "14.1.1",
27
+ "marked-gfm-heading-id": "4.1.0",
28
+ "marked-highlight": "2.1.4",
29
+ "marked-smartypants": "1.1.8",
30
+ "sharp": "0.33.5",
31
+ "yaml": "2.5.1"
32
32
  },
33
33
  "scripts": {
34
34
  "build": "ori exports/buildExports.js src > exports/exports.js",
@@ -0,0 +1,5 @@
1
+ import calendarTree from "@weborigami/async-tree/src/calendarTree.js";
2
+
3
+ export default function calendarTreeBuiltin(start, end) {
4
+ return calendarTree(start, end);
5
+ }
@@ -6,11 +6,13 @@ const js = {
6
6
  Infinity,
7
7
  Intl,
8
8
  JSON,
9
+ Map,
9
10
  Math,
10
11
  NaN,
11
12
  Number,
12
13
  Object,
13
14
  RegExp,
15
+ Set,
14
16
  String,
15
17
  Symbol,
16
18
  decodeURI,
@@ -1,4 +1,4 @@
1
- import { Tree, keysJson } from "@weborigami/async-tree";
1
+ import { Tree, jsonKeys } from "@weborigami/async-tree";
2
2
  import { transformObject } from "../common/utilities.js";
3
3
  import getTreeArgument from "../misc/getTreeArgument.js";
4
4
 
@@ -10,7 +10,7 @@ import getTreeArgument from "../misc/getTreeArgument.js";
10
10
  * @this {AsyncTree|null}
11
11
  * @param {Treelike} treelike
12
12
  */
13
- export default async function treeKeysJson(treelike) {
13
+ export default async function jsonKeysBuiltin(treelike) {
14
14
  const tree = await getTreeArgument(
15
15
  this,
16
16
  arguments,
@@ -26,7 +26,7 @@ function KeysJsonTransform(Base) {
26
26
  async get(key) {
27
27
  let value = await super.get(key);
28
28
  if (value === undefined && key === ".keys.json") {
29
- value = await keysJson.stringify(this);
29
+ value = await jsonKeys.stringify(this);
30
30
  } else if (Tree.isTreelike(value)) {
31
31
  const tree = Tree.from(value, { deep: true });
32
32
  value = transformObject(KeysJsonTransform, tree);
@@ -0,0 +1,16 @@
1
+ import yaml from "./@yaml.js";
2
+
3
+ /**
4
+ * Log the first argument to the console as a side effect and return the second
5
+ * argument. If no second argument is provided, return the first argument.
6
+ *
7
+ * @this {import("@weborigami/types").AsyncTree|null}
8
+ * @param {any} object
9
+ * @param {any} [result]
10
+ */
11
+ export default async function log(result, object = result) {
12
+ let text = object !== undefined ? await yaml.call(this, object) : "undefined";
13
+ text = text?.trim();
14
+ console.log(text);
15
+ return result;
16
+ }
@@ -79,13 +79,15 @@ export default function mapFnBuiltin(operation) {
79
79
  extendedInverseKeyFn = keyFns.inverseKey;
80
80
  } else if (keyFn) {
81
81
  const resolvedKeyFn = toFunction(keyFn);
82
- async function scopedKeyFn(sourceKey, tree) {
83
- const sourceValue = await tree.get(sourceKey);
82
+ async function scopedKeyFn(sourceKey, sourceTree) {
83
+ const sourceValue = await sourceTree.get(sourceKey);
84
+ // The key function will be given the source tree, but will run with the
85
+ // scope of this tree.
84
86
  const resultKey = await resolvedKeyFn.call(
85
87
  tree,
86
88
  sourceValue,
87
89
  sourceKey,
88
- tree
90
+ sourceTree
89
91
  );
90
92
  return resultKey;
91
93
  }
@@ -1,4 +1,4 @@
1
- import { Tree, keysJson } from "@weborigami/async-tree";
1
+ import { Tree, jsonKeys } from "@weborigami/async-tree";
2
2
  import { transformObject } from "../common/utilities.js";
3
3
  import getTreeArgument from "../misc/getTreeArgument.js";
4
4
  import index from "./@index.js";
@@ -24,7 +24,7 @@ function StaticTransform(Base) {
24
24
  if (value === undefined && key === "index.html") {
25
25
  value = index.call(this, this);
26
26
  } else if (value === undefined && key === ".keys.json") {
27
- value = keysJson.stringify(this);
27
+ value = jsonKeys.stringify(this);
28
28
  } else if (Tree.isAsyncTree(value)) {
29
29
  value = transformObject(StaticTransform, value);
30
30
  }
@@ -1,4 +1,4 @@
1
- import { Tree, keysJson } from "@weborigami/async-tree";
1
+ import { Tree, jsonKeys } from "@weborigami/async-tree";
2
2
  import index from "../builtins/@index.js";
3
3
  import { isTransformApplied, transformObject } from "../common/utilities.js";
4
4
 
@@ -39,7 +39,7 @@ export default function ExplorableSiteTransform(Base) {
39
39
  // This tree is both the function call target and the parameter.
40
40
  value = await index.call(this, this);
41
41
  } else if (key === ".keys.json") {
42
- value = await keysJson.stringify(this);
42
+ value = await jsonKeys.stringify(this);
43
43
  }
44
44
  }
45
45
 
@@ -47,7 +47,7 @@ async function statements(tree, nodePath, nodeLabel, options) {
47
47
  );
48
48
 
49
49
  // Draw edges and collect labels for the nodes they lead to.
50
- let nodes = {};
50
+ let nodes = new Map();
51
51
  for (const key of await tree.keys()) {
52
52
  const destPath = nodePath ? `${nodePath}/${key}` : key;
53
53
  const arc = ` "${nodePath}" -> "${destPath}" [label="${key}"];`;
@@ -80,27 +80,29 @@ async function statements(tree, nodePath, nodeLabel, options) {
80
80
  if (value === undefined) {
81
81
  isError = true;
82
82
  }
83
- nodes[key] = { label };
83
+
84
+ const data = { label };
84
85
  if (isError) {
85
- nodes[key].isError = true;
86
+ data.isError = true;
86
87
  }
88
+ nodes.set(key, data);
87
89
  }
88
90
  }
89
91
 
90
92
  // If we have more than one label, we'll focus on the labels' differences.
91
93
  // We'll use the first label as a representative baseline for all labels but
92
94
  // the first (which will use the second label as a baseline).
93
- const values = Object.values(nodes);
95
+ const values = [...nodes.values()];
94
96
  const showLabelDiffs = values.length > 1;
95
97
  const label1 = showLabelDiffs ? String(values[0].label) : undefined;
96
98
  const label2 = showLabelDiffs ? String(values[1].label) : undefined;
97
99
 
98
100
  // Trim labels.
99
101
  let i = 0;
100
- for (const key of Object.keys(nodes)) {
101
- let label = nodes[key].label;
102
+ for (const data of nodes.values()) {
103
+ let label = data.label;
102
104
  if (label === null) {
103
- nodes[key].label = "[binary data]";
105
+ data.label = "[binary data]";
104
106
  } else if (label) {
105
107
  let clippedStart = false;
106
108
  let clippedEnd = false;
@@ -146,14 +148,13 @@ async function statements(tree, nodePath, nodeLabel, options) {
146
148
  label += "\\l";
147
149
  }
148
150
 
149
- nodes[key].label = label;
151
+ data.label = label;
150
152
  }
151
153
  i++;
152
154
  }
153
155
 
154
156
  // Draw labels.
155
- for (const key in nodes) {
156
- const node = nodes[key];
157
+ for (const [key, node] of nodes.entries()) {
157
158
  const icon = node.isError ? "⚠️ " : "";
158
159
  // GraphViz has trouble rendering DOT nodes whose labels contain ellipsis
159
160
  // characters, so we map those to three periods. GraphViz appears to turn
@@ -44,7 +44,7 @@ export default async function constructResponse(request, resource) {
44
44
 
45
45
  if (!url.pathname.endsWith("/") && Tree.isTreelike(resource)) {
46
46
  // Treelike resource: redirect to its index page.
47
- const Location = `${request.url}/`;
47
+ const Location = `${url.pathname}/`;
48
48
  return new Response("ok", {
49
49
  headers: {
50
50
  Location,
@@ -1,4 +1,4 @@
1
- import { DeepObjectTree, Tree, keysFromPath } from "@weborigami/async-tree";
1
+ import { ObjectTree, 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";
@@ -51,11 +51,17 @@ function extendTreeScopeWithParams(tree, url) {
51
51
  return tree;
52
52
  }
53
53
 
54
- const paramTree = new DeepObjectTree({
54
+ const paramTree = new ObjectTree({
55
55
  "@params": params,
56
56
  });
57
- paramTree.parent = tree;
58
- return paramTree;
57
+
58
+ // Create a new tree that's like the original one, but has the parameters in
59
+ // its parent hierarchy.
60
+ const extendedTree = Object.create(tree);
61
+ const realParent = tree.parent;
62
+ paramTree.parent = realParent;
63
+ extendedTree.parent = paramTree;
64
+ return extendedTree;
59
65
  }
60
66
 
61
67
  /**