@weborigami/origami 0.2.0 → 0.2.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.
- package/package.json +4 -4
- package/src/calc/calc.js +10 -0
- package/src/help/help.yaml +2 -31
- package/src/js.js +1 -0
- package/src/server/constructResponse.js +3 -0
- package/src/server/server.js +13 -11
- package/src/text/origamiHighlightDefinition.js +7 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weborigami/origami",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Web Origami language, CLI, framework, and server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"typescript": "5.6.2"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@weborigami/async-tree": "0.2.
|
|
21
|
-
"@weborigami/language": "0.2.
|
|
22
|
-
"@weborigami/types": "0.2.
|
|
20
|
+
"@weborigami/async-tree": "0.2.1",
|
|
21
|
+
"@weborigami/language": "0.2.1",
|
|
22
|
+
"@weborigami/types": "0.2.1",
|
|
23
23
|
"exif-parser": "0.1.12",
|
|
24
24
|
"graphviz-wasm": "3.0.2",
|
|
25
25
|
"highlight.js": "11.10.0",
|
package/src/calc/calc.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Tree } from "@weborigami/async-tree";
|
|
|
2
2
|
import assertTreeIsDefined from "../common/assertTreeIsDefined.js";
|
|
3
3
|
|
|
4
4
|
export function add(...args) {
|
|
5
|
+
console.warn(`Warning: "add" is deprecated. Use the "+" operator instead.`);
|
|
5
6
|
const numbers = args.map((arg) => Number(arg));
|
|
6
7
|
return numbers.reduce((acc, val) => acc + val, 0);
|
|
7
8
|
}
|
|
@@ -12,6 +13,9 @@ export function and(...args) {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export function divide(a, b) {
|
|
16
|
+
console.warn(
|
|
17
|
+
`Warning: "divide" is deprecated. Use the "/" operator instead.`
|
|
18
|
+
);
|
|
15
19
|
return Number(a) / Number(b);
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -52,6 +56,9 @@ export async function ifBuiltin(value, trueResult, falseResult) {
|
|
|
52
56
|
ifBuiltin.key = "if";
|
|
53
57
|
|
|
54
58
|
export function multiply(...args) {
|
|
59
|
+
console.warn(
|
|
60
|
+
`Warning: "multiply" is deprecated. Use the "*" operator instead.`
|
|
61
|
+
);
|
|
55
62
|
const numbers = args.map((arg) => Number(arg));
|
|
56
63
|
return numbers.reduce((acc, val) => acc * val, 1);
|
|
57
64
|
}
|
|
@@ -67,5 +74,8 @@ export function or(...args) {
|
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
export function subtract(a, b) {
|
|
77
|
+
console.warn(
|
|
78
|
+
`Warning: "subtract" is deprecated. Use the "-" operator instead.`
|
|
79
|
+
);
|
|
70
80
|
return Number(a) - Number(b);
|
|
71
81
|
}
|
package/src/help/help.yaml
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
calc:
|
|
2
|
-
description: Perform math operations
|
|
3
|
-
commands:
|
|
4
|
-
add:
|
|
5
|
-
args: (a, b, ...)
|
|
6
|
-
description: Add the numbers
|
|
7
|
-
# and:
|
|
8
|
-
# args: (a, b, ...)
|
|
9
|
-
# description: Return true if all the arguments are true
|
|
10
|
-
divide:
|
|
11
|
-
args: (a, b)
|
|
12
|
-
description: Divide a by b
|
|
13
|
-
# equals:
|
|
14
|
-
# args: (a, b)
|
|
15
|
-
# description: Return true if a equals b
|
|
16
|
-
# if:
|
|
17
|
-
# args: (a, b, c)
|
|
18
|
-
# description: If a is true return b, otherwise c
|
|
19
|
-
multiply:
|
|
20
|
-
args: (a, b, ...)
|
|
21
|
-
description: Multiply the numbers
|
|
22
|
-
# not:
|
|
23
|
-
# args: (value)
|
|
24
|
-
# description: Return true if a is false and vice versa
|
|
25
|
-
# or:
|
|
26
|
-
# args: (a, b, ...)
|
|
27
|
-
# description: Return true if any of the arguments are true
|
|
28
|
-
subtract:
|
|
29
|
-
args: (a, b)
|
|
30
|
-
description: Subtract b from a
|
|
31
|
-
|
|
32
1
|
dev:
|
|
33
2
|
description: Develop and debug Origami projects
|
|
34
3
|
commands:
|
|
@@ -97,6 +66,8 @@ js:
|
|
|
97
66
|
commands:
|
|
98
67
|
Array:
|
|
99
68
|
description: JavaScript Array class
|
|
69
|
+
BigInt:
|
|
70
|
+
description: JavaScript BigInt class
|
|
100
71
|
Boolean:
|
|
101
72
|
description: JavaScript Boolean class
|
|
102
73
|
Date:
|
package/src/js.js
CHANGED
|
@@ -43,6 +43,9 @@ export default async function constructResponse(request, resource) {
|
|
|
43
43
|
|
|
44
44
|
if (!isPacked(resource) && typeof resource.pack === "function") {
|
|
45
45
|
resource = await resource.pack();
|
|
46
|
+
if (typeof resource === "function") {
|
|
47
|
+
resource = await resource();
|
|
48
|
+
}
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
let mediaType;
|
package/src/server/server.js
CHANGED
|
@@ -87,26 +87,28 @@ export async function handleRequest(request, response, tree) {
|
|
|
87
87
|
// Ask the tree for the resource with those keys.
|
|
88
88
|
let resource;
|
|
89
89
|
try {
|
|
90
|
-
resource = await Tree.
|
|
90
|
+
resource = await Tree.traverseOrThrow(extendedTree, ...keys);
|
|
91
|
+
|
|
91
92
|
// If resource is a function, invoke to get the object we want to return.
|
|
92
93
|
// For a POST request, pass the data to the function.
|
|
93
94
|
if (typeof resource === "function") {
|
|
94
95
|
resource = data ? await resource(data) : await resource();
|
|
95
96
|
}
|
|
97
|
+
|
|
98
|
+
// Construct the response.
|
|
99
|
+
const constructed = await constructResponse(request, resource);
|
|
100
|
+
if (!constructed) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Copy the construct response to the ServerResponse and return true if
|
|
105
|
+
// the response was valid.
|
|
106
|
+
return copyResponse(constructed, response);
|
|
96
107
|
} catch (/** @type {any} */ error) {
|
|
108
|
+
// Display an error
|
|
97
109
|
respondWithError(response, error);
|
|
98
110
|
return true;
|
|
99
111
|
}
|
|
100
|
-
|
|
101
|
-
// Construct the response.
|
|
102
|
-
const constructed = await constructResponse(request, resource);
|
|
103
|
-
if (!constructed) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Copy the construct response to the ServerResponse and return true if
|
|
108
|
-
// the response was valid.
|
|
109
|
-
return copyResponse(constructed, response);
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
function keysFromUrl(url) {
|
|
@@ -36,7 +36,7 @@ export default function origamiHighlightDefinition(hljs) {
|
|
|
36
36
|
// Treat identifier containing a period before an open paren or backtick as a variable
|
|
37
37
|
className: "variable",
|
|
38
38
|
begin:
|
|
39
|
-
/\b[^(){}\[\]
|
|
39
|
+
/\b[^(){}\[\]<>\?!\|=,/:\`"'«»\\→⇒… \t\n\r]+\.[^(){}\[\]<>\?!\|=,/:\`"'«»\\→⇒… \t\n\r]+(?=(\(|\`))\b/,
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
className: "built_in",
|
|
@@ -44,13 +44,14 @@ export default function origamiHighlightDefinition(hljs) {
|
|
|
44
44
|
begin: /\b[A-Za-z][A-Za-z0-9]*(?=(\(|\`))\b/,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
className: "operator",
|
|
48
|
+
begin:
|
|
49
|
+
/===|!==|==|!=|<=|<|>=|>|\*|\*\*|\/|%|\+|-|=>|⇒|->|→|=|:|\.\.\.|…|&&|&|\|\||\||!|\^|~|\?\?|\?|#!/,
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
// Treat remaining identifiers as variables
|
|
53
|
+
className: "variable",
|
|
54
|
+
begin: /\b[^(){}\[\]<>\?!\|=,/:\`"'«»\\→⇒… \t\n\r]+\b/,
|
|
54
55
|
},
|
|
55
56
|
],
|
|
56
57
|
};
|