@weborigami/language 0.6.17 → 0.7.0-beta.2
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 +1 -0
- package/main.js +7 -1
- package/package.json +7 -6
- package/src/compiler/compile.js +10 -3
- package/src/compiler/optimize.js +71 -40
- package/src/compiler/parse.js +1 -1
- package/src/compiler/parserHelpers.js +5 -3
- package/src/handlers/addExtensionKeyFn.js +18 -0
- package/src/handlers/epub_handler.js +54 -0
- package/src/handlers/getSource.js +11 -0
- package/src/handlers/handlers.js +2 -0
- package/src/handlers/htm_handler.js +1 -1
- package/src/handlers/js_handler.js +13 -4
- package/src/handlers/mediaTypeExtensions.json +15 -0
- package/src/handlers/ori_handler.js +8 -7
- package/src/handlers/oridocument_handler.js +19 -28
- package/src/handlers/processOriExport.js +17 -0
- package/src/handlers/tsv_handler.js +1 -1
- package/src/handlers/txt_handler.js +4 -2
- package/src/handlers/xhtml_handler.js +1 -1
- package/src/handlers/yaml_handler.js +6 -3
- package/src/handlers/zip_handler.js +112 -0
- package/src/project/activeProjectRoot.js +9 -0
- package/src/project/getGlobalsForTree.js +5 -0
- package/src/project/{projectGlobals.js → initializeGlobalsForTree.js} +8 -13
- package/src/project/jsGlobals.js +1 -0
- package/src/project/projectConfig.js +2 -2
- package/src/project/projectRootFromPath.js +2 -0
- package/src/protocols/constructHref.js +3 -3
- package/src/protocols/constructSiteTree.js +11 -2
- package/src/protocols/explore.js +1 -1
- package/src/protocols/explorehttp.js +1 -1
- package/src/protocols/fetchAndHandleExtension.js +23 -11
- package/src/protocols/files.js +1 -0
- package/src/protocols/http.js +4 -1
- package/src/protocols/https.js +4 -1
- package/src/protocols/httpstree.js +1 -1
- package/src/protocols/httptree.js +1 -1
- package/src/protocols/package.js +15 -3
- package/src/runtime/AsyncCacheTransform.d.ts +5 -0
- package/src/runtime/AsyncCacheTransform.js +134 -0
- package/src/runtime/HandleExtensionsTransform.d.ts +3 -1
- package/src/runtime/HandleExtensionsTransform.js +18 -2
- package/src/runtime/OrigamiFileMap.d.ts +5 -2
- package/src/runtime/OrigamiFileMap.js +27 -4
- package/src/runtime/ScopeMap.js +72 -0
- package/src/runtime/SyncCacheTransform.d.ts +8 -0
- package/src/runtime/SyncCacheTransform.js +133 -0
- package/src/runtime/SystemCacheMap.js +259 -0
- package/src/runtime/WatchFilesMixin.js +52 -19
- package/src/runtime/enableValueCaching.js +192 -0
- package/src/runtime/execute.js +2 -2
- package/src/runtime/executionContext.js +7 -0
- package/src/runtime/explainReferenceError.js +7 -2
- package/src/runtime/expressionObject.js +54 -46
- package/src/runtime/handleExtension.js +65 -34
- package/src/runtime/interop.js +2 -2
- package/src/runtime/mergeTrees.js +1 -1
- package/src/runtime/ops.js +28 -33
- package/src/runtime/symbols.js +3 -0
- package/src/runtime/systemCache.js +3 -0
- package/src/runtime/volatile.js +14 -0
- package/test/compiler/codeHelpers.js +2 -1
- package/test/compiler/optimize.test.js +62 -54
- package/test/handlers/epub_handler.test.js +27 -0
- package/test/handlers/fixtures/test.zip +0 -0
- package/test/handlers/ori_handler.test.js +22 -3
- package/test/handlers/oridocument_handler.test.js +1 -1
- package/test/handlers/zip_handler.test.js +45 -0
- package/test/protocols/https.test.js +19 -0
- package/test/protocols/package.test.js +7 -2
- package/test/runtime/AsyncCacheTransform.test.js +91 -0
- package/test/runtime/OrigamiFileMap.test.js +26 -23
- package/test/runtime/ScopeMap.test.js +49 -0
- package/test/runtime/SyncCacheTransform.test.js +93 -0
- package/test/runtime/SystemCacheMap.test.js +239 -0
- package/test/runtime/asyncCalcs.js +28 -0
- package/test/runtime/enableValueCaching.test.js +55 -0
- package/test/runtime/errors.test.js +53 -30
- package/test/runtime/evaluate.test.js +9 -4
- package/test/runtime/execute.test.js +6 -1
- package/test/runtime/expressionObject.test.js +55 -15
- package/test/runtime/fetchAndHandleExtension.test.js +24 -0
- package/test/runtime/fixtures/unpack/hello.json +1 -0
- package/test/runtime/handleExtension.test.js +12 -1
- package/test/runtime/ops.test.js +70 -65
- package/test/runtime/syncCalcs.js +27 -0
- package/test/runtime/systemCache.test.js +66 -0
- package/src/runtime/assignPropertyDescriptors.js +0 -23
- package/src/runtime/asyncStorage.js +0 -7
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests of several forms of caching using the system cache
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SyncMap, Tree } from "@weborigami/async-tree";
|
|
6
|
+
import assert from "node:assert";
|
|
7
|
+
import { describe, test } from "node:test";
|
|
8
|
+
import * as handlers from "../../src/handlers/handlers.js";
|
|
9
|
+
import HandleExtensionsTransform from "../../src/runtime/HandleExtensionsTransform.js";
|
|
10
|
+
import SyncCacheTransform from "../../src/runtime/SyncCacheTransform.js";
|
|
11
|
+
import { cachePathSymbol } from "../../src/runtime/symbols.js";
|
|
12
|
+
|
|
13
|
+
describe("systemCache", () => {
|
|
14
|
+
test("property based on external scope recalculates when scope changes", async () => {
|
|
15
|
+
// Virtual src folder
|
|
16
|
+
const src = new OrigamiSyncMap([
|
|
17
|
+
[
|
|
18
|
+
"site.ori",
|
|
19
|
+
`
|
|
20
|
+
{
|
|
21
|
+
value = data.json/
|
|
22
|
+
}
|
|
23
|
+
`,
|
|
24
|
+
],
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
// Virtual project root folder
|
|
28
|
+
const project = new OrigamiSyncMap([
|
|
29
|
+
["data.json", "1"],
|
|
30
|
+
["src", src],
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
// Make src a child of the project root
|
|
34
|
+
src.parent = project;
|
|
35
|
+
|
|
36
|
+
// Paths are optional but make cache keys more meaningful
|
|
37
|
+
src[cachePathSymbol] = "project/src";
|
|
38
|
+
project[cachePathSymbol] = "project";
|
|
39
|
+
|
|
40
|
+
// Add handlers so we can unpack values
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
project.globals = handlers;
|
|
43
|
+
|
|
44
|
+
const site = await Tree.traverseOrThrow(project, "src/", "site.ori/");
|
|
45
|
+
|
|
46
|
+
const value1 = await site.value;
|
|
47
|
+
assert.equal(value1, 1);
|
|
48
|
+
|
|
49
|
+
// Add new data.json to src folder, overriding the one in project root
|
|
50
|
+
src.set("data.json", "2");
|
|
51
|
+
|
|
52
|
+
const value2 = await site.value;
|
|
53
|
+
assert.equal(value2, 2);
|
|
54
|
+
|
|
55
|
+
// Delete data.json from src folder, reverting to the one in project root
|
|
56
|
+
src.delete("data.json");
|
|
57
|
+
|
|
58
|
+
const value3 = await site.value;
|
|
59
|
+
assert.equal(value3, 1);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Like OrigamiFileMap, but in memory
|
|
64
|
+
class OrigamiSyncMap extends SyncCacheTransform(
|
|
65
|
+
HandleExtensionsTransform(SyncMap),
|
|
66
|
+
) {}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is an analogue of Object.assign that destructively copies properties to
|
|
3
|
-
* a target object -- but avoids invoking property getters. Instead, it copies
|
|
4
|
-
* property descriptors over to the target object.
|
|
5
|
-
*
|
|
6
|
-
* @param {any} target
|
|
7
|
-
* @param {...any} sources
|
|
8
|
-
*/
|
|
9
|
-
export default function assignPropertyDescriptors(target, ...sources) {
|
|
10
|
-
for (const source of sources) {
|
|
11
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
12
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
13
|
-
if (descriptor.value !== undefined) {
|
|
14
|
-
// Simple value, copy it
|
|
15
|
-
target[key] = descriptor.value;
|
|
16
|
-
} else {
|
|
17
|
-
// Getter and/or setter, copy the descriptor
|
|
18
|
-
Object.defineProperty(target, key, descriptor);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return target;
|
|
23
|
-
}
|