@weborigami/origami 0.7.0-beta.1 → 0.7.0-beta.3
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 +3 -3
- package/src/common/documentObject.js +26 -0
- package/src/dev/ExplorableSiteTransform.js +4 -2
- package/src/dev/debug2/debugTransform.js +4 -3
- package/src/dev/dev.js +1 -0
- package/src/dev/help.yaml +6 -0
- package/src/dev/syscache.js +2 -0
- package/src/dev/syscount.js +5 -0
- package/src/origami/htmlDom.js +4 -1
- package/src/server/constructResponse.js +12 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.3",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@hpcc-js/wasm-graphviz": "1.21.7",
|
|
21
|
-
"@weborigami/async-tree": "0.7.0-beta.
|
|
21
|
+
"@weborigami/async-tree": "0.7.0-beta.3",
|
|
22
22
|
"@weborigami/json-feed-to-rss": "1.0.1",
|
|
23
|
-
"@weborigami/language": "0.7.0-beta.
|
|
23
|
+
"@weborigami/language": "0.7.0-beta.3",
|
|
24
24
|
"css-tree": "3.2.1",
|
|
25
25
|
"highlight.js": "11.11.1",
|
|
26
26
|
"jsdom": "29.1.1",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isPlainObject, isUnpackable, toString } from "@weborigami/async-tree";
|
|
2
|
+
import { toYaml } from "./serialize.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* In Origami, a text document object is any object with a `_body` property.
|
|
@@ -29,6 +30,7 @@ export default async function documentObject(input, data) {
|
|
|
29
30
|
|
|
30
31
|
const result = {};
|
|
31
32
|
Object.assign(result, inputData, data);
|
|
33
|
+
|
|
32
34
|
Object.defineProperty(result, "_body", {
|
|
33
35
|
configurable: true,
|
|
34
36
|
enumerable: true,
|
|
@@ -36,5 +38,29 @@ export default async function documentObject(input, data) {
|
|
|
36
38
|
writable: true,
|
|
37
39
|
});
|
|
38
40
|
|
|
41
|
+
Object.defineProperty(result, "pack", {
|
|
42
|
+
configurable: true,
|
|
43
|
+
enumerable: false,
|
|
44
|
+
value: pack.bind(null, result),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
Object.defineProperty(result, "toString", {
|
|
48
|
+
configurable: true,
|
|
49
|
+
enumerable: false,
|
|
50
|
+
value: pack.bind(null, result),
|
|
51
|
+
});
|
|
52
|
+
|
|
39
53
|
return result;
|
|
40
54
|
}
|
|
55
|
+
|
|
56
|
+
// If the document is just a _body, return its text. Otherwise, return the body
|
|
57
|
+
// as a string with the other properties as YAML front matter.
|
|
58
|
+
async function pack(document) {
|
|
59
|
+
if (Object.keys(document).length === 1 && "_body" in document) {
|
|
60
|
+
return document._body;
|
|
61
|
+
}
|
|
62
|
+
const frontData = { ...document };
|
|
63
|
+
delete frontData._body;
|
|
64
|
+
const frontMatter = await toYaml(frontData);
|
|
65
|
+
return `---\n${frontMatter}---\n\n${document._body}`;
|
|
66
|
+
}
|
|
@@ -68,9 +68,11 @@ export default function ExplorableSiteTransform(Base) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// If this value is given to the server, the server will call this pack()
|
|
71
|
-
// method.
|
|
71
|
+
// method. If the source defines pack(), we use that, otherwise we return
|
|
72
|
+
// undefined. The server will redirect to the URL with a trailing slash,
|
|
73
|
+
// which will call `get("index.html")` (above) to get the index page.
|
|
72
74
|
async pack() {
|
|
73
|
-
return
|
|
75
|
+
return super.pack ? await super.pack() : undefined;
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
78
|
}
|
|
@@ -82,10 +82,11 @@ export default function debugTransform(input) {
|
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
// If this value is given to the server, the server will call this pack()
|
|
85
|
-
// method.
|
|
85
|
+
// method. If the source defines pack(), we use that, otherwise we return
|
|
86
|
+
// undefined. The server will redirect to the URL with a trailing slash,
|
|
87
|
+
// which will call `get("index.html")` (above) to get the index page.
|
|
86
88
|
async pack() {
|
|
87
|
-
|
|
88
|
-
return source.pack?.() ?? this.get("index.html");
|
|
89
|
+
return /** @type {any} */ (source)?.pack?.();
|
|
89
90
|
},
|
|
90
91
|
|
|
91
92
|
// @ts-ignore
|
package/src/dev/dev.js
CHANGED
|
@@ -19,5 +19,6 @@ export { default as serve } from "./serve.js";
|
|
|
19
19
|
export { default as stdin } from "./stdin.js";
|
|
20
20
|
export { default as svg } from "./svg.js";
|
|
21
21
|
export { default as syscache } from "./syscache.js";
|
|
22
|
+
export { default as syscount } from "./syscount.js";
|
|
22
23
|
export { default as version } from "./version.js";
|
|
23
24
|
export { default as watch } from "./watch.js";
|
package/src/dev/help.yaml
CHANGED
|
@@ -247,6 +247,12 @@ Tree:
|
|
|
247
247
|
filter:
|
|
248
248
|
args: (tree, options)
|
|
249
249
|
description: Filter a tree by a condition
|
|
250
|
+
find:
|
|
251
|
+
args: (map, test)
|
|
252
|
+
description: The value of the first entry satisfying the test
|
|
253
|
+
findKey:
|
|
254
|
+
args: (map, test)
|
|
255
|
+
description: The key of the first entry satisfying the test
|
|
250
256
|
first:
|
|
251
257
|
args: (map)
|
|
252
258
|
description: The first value in the map
|
package/src/dev/syscache.js
CHANGED
|
@@ -15,9 +15,11 @@ export default function syscache() {
|
|
|
15
15
|
const result = {};
|
|
16
16
|
if (entry.downstreams) {
|
|
17
17
|
result.downstreams = preferRelativePaths(projectRoot, entry.downstreams);
|
|
18
|
+
result.downstreams.sort((a, b) => a.localeCompare(b));
|
|
18
19
|
}
|
|
19
20
|
if (entry.upstreams) {
|
|
20
21
|
result.upstreams = preferRelativePaths(projectRoot, entry.upstreams);
|
|
22
|
+
result.upstreams.sort((a, b) => a.localeCompare(b));
|
|
21
23
|
}
|
|
22
24
|
return [preferRelativePath(projectRoot, path), result];
|
|
23
25
|
});
|
package/src/origami/htmlDom.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { args } from "@weborigami/async-tree";
|
|
1
|
+
import { args, isUnpackable } from "@weborigami/async-tree";
|
|
2
2
|
import loadJsDom from "../common/loadJsDom.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,6 +7,9 @@ import loadJsDom from "../common/loadJsDom.js";
|
|
|
7
7
|
* @param {import("@weborigami/async-tree").Stringlike} html
|
|
8
8
|
*/
|
|
9
9
|
export default async function htmlDom(html) {
|
|
10
|
+
if (isUnpackable(html)) {
|
|
11
|
+
html = await html.unpack();
|
|
12
|
+
}
|
|
10
13
|
html = args.stringlike(html, "Origami.htmlDom");
|
|
11
14
|
const { JSDOM } = await loadJsDom();
|
|
12
15
|
let dom = JSDOM.fragment(html);
|
|
@@ -22,12 +22,16 @@ export default async function constructResponse(request, resource) {
|
|
|
22
22
|
const url = new URL(request?.url ?? "", `https://${request?.headers.host}`);
|
|
23
23
|
|
|
24
24
|
if (!isPacked(resource) && typeof resource.pack === "function") {
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
let packed = await resource.pack();
|
|
26
|
+
if (packed) {
|
|
27
|
+
if (typeof packed === "function") {
|
|
28
|
+
packed = await packed();
|
|
29
|
+
}
|
|
30
|
+
if (packed instanceof Response) {
|
|
31
|
+
// Already a Response
|
|
32
|
+
return packed;
|
|
33
|
+
}
|
|
34
|
+
resource = packed;
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -104,6 +108,8 @@ export default async function constructResponse(request, resource) {
|
|
|
104
108
|
const hash = createHash("sha1");
|
|
105
109
|
if (typeof body === "string" || body instanceof String) {
|
|
106
110
|
hash.update(String(body), "utf8");
|
|
111
|
+
} else if (body instanceof ArrayBuffer) {
|
|
112
|
+
hash.update(new Uint8Array(body));
|
|
107
113
|
} else {
|
|
108
114
|
hash.update(body);
|
|
109
115
|
}
|