@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.
Files changed (90) hide show
  1. package/index.ts +1 -0
  2. package/main.js +7 -1
  3. package/package.json +7 -6
  4. package/src/compiler/compile.js +10 -3
  5. package/src/compiler/optimize.js +71 -40
  6. package/src/compiler/parse.js +1 -1
  7. package/src/compiler/parserHelpers.js +5 -3
  8. package/src/handlers/addExtensionKeyFn.js +18 -0
  9. package/src/handlers/epub_handler.js +54 -0
  10. package/src/handlers/getSource.js +11 -0
  11. package/src/handlers/handlers.js +2 -0
  12. package/src/handlers/htm_handler.js +1 -1
  13. package/src/handlers/js_handler.js +13 -4
  14. package/src/handlers/mediaTypeExtensions.json +15 -0
  15. package/src/handlers/ori_handler.js +8 -7
  16. package/src/handlers/oridocument_handler.js +19 -28
  17. package/src/handlers/processOriExport.js +17 -0
  18. package/src/handlers/tsv_handler.js +1 -1
  19. package/src/handlers/txt_handler.js +4 -2
  20. package/src/handlers/xhtml_handler.js +1 -1
  21. package/src/handlers/yaml_handler.js +6 -3
  22. package/src/handlers/zip_handler.js +112 -0
  23. package/src/project/activeProjectRoot.js +9 -0
  24. package/src/project/getGlobalsForTree.js +5 -0
  25. package/src/project/{projectGlobals.js → initializeGlobalsForTree.js} +8 -13
  26. package/src/project/jsGlobals.js +1 -0
  27. package/src/project/projectConfig.js +2 -2
  28. package/src/project/projectRootFromPath.js +2 -0
  29. package/src/protocols/constructHref.js +3 -3
  30. package/src/protocols/constructSiteTree.js +11 -2
  31. package/src/protocols/explore.js +1 -1
  32. package/src/protocols/explorehttp.js +1 -1
  33. package/src/protocols/fetchAndHandleExtension.js +23 -11
  34. package/src/protocols/files.js +1 -0
  35. package/src/protocols/http.js +4 -1
  36. package/src/protocols/https.js +4 -1
  37. package/src/protocols/httpstree.js +1 -1
  38. package/src/protocols/httptree.js +1 -1
  39. package/src/protocols/package.js +15 -3
  40. package/src/runtime/AsyncCacheTransform.d.ts +5 -0
  41. package/src/runtime/AsyncCacheTransform.js +134 -0
  42. package/src/runtime/HandleExtensionsTransform.d.ts +3 -1
  43. package/src/runtime/HandleExtensionsTransform.js +18 -2
  44. package/src/runtime/OrigamiFileMap.d.ts +5 -2
  45. package/src/runtime/OrigamiFileMap.js +27 -4
  46. package/src/runtime/ScopeMap.js +72 -0
  47. package/src/runtime/SyncCacheTransform.d.ts +8 -0
  48. package/src/runtime/SyncCacheTransform.js +133 -0
  49. package/src/runtime/SystemCacheMap.js +259 -0
  50. package/src/runtime/WatchFilesMixin.js +52 -19
  51. package/src/runtime/enableValueCaching.js +192 -0
  52. package/src/runtime/execute.js +2 -2
  53. package/src/runtime/executionContext.js +7 -0
  54. package/src/runtime/explainReferenceError.js +7 -2
  55. package/src/runtime/expressionObject.js +54 -46
  56. package/src/runtime/handleExtension.js +65 -34
  57. package/src/runtime/interop.js +2 -2
  58. package/src/runtime/mergeTrees.js +1 -1
  59. package/src/runtime/ops.js +28 -33
  60. package/src/runtime/symbols.js +3 -0
  61. package/src/runtime/systemCache.js +3 -0
  62. package/src/runtime/volatile.js +14 -0
  63. package/test/compiler/codeHelpers.js +2 -1
  64. package/test/compiler/optimize.test.js +62 -54
  65. package/test/handlers/epub_handler.test.js +27 -0
  66. package/test/handlers/fixtures/test.zip +0 -0
  67. package/test/handlers/ori_handler.test.js +22 -3
  68. package/test/handlers/oridocument_handler.test.js +1 -1
  69. package/test/handlers/zip_handler.test.js +45 -0
  70. package/test/protocols/https.test.js +19 -0
  71. package/test/protocols/package.test.js +7 -2
  72. package/test/runtime/AsyncCacheTransform.test.js +91 -0
  73. package/test/runtime/OrigamiFileMap.test.js +26 -23
  74. package/test/runtime/ScopeMap.test.js +49 -0
  75. package/test/runtime/SyncCacheTransform.test.js +93 -0
  76. package/test/runtime/SystemCacheMap.test.js +239 -0
  77. package/test/runtime/asyncCalcs.js +28 -0
  78. package/test/runtime/enableValueCaching.test.js +55 -0
  79. package/test/runtime/errors.test.js +53 -30
  80. package/test/runtime/evaluate.test.js +9 -4
  81. package/test/runtime/execute.test.js +6 -1
  82. package/test/runtime/expressionObject.test.js +55 -15
  83. package/test/runtime/fetchAndHandleExtension.test.js +24 -0
  84. package/test/runtime/fixtures/unpack/hello.json +1 -0
  85. package/test/runtime/handleExtension.test.js +12 -1
  86. package/test/runtime/ops.test.js +70 -65
  87. package/test/runtime/syncCalcs.js +27 -0
  88. package/test/runtime/systemCache.test.js +66 -0
  89. package/src/runtime/assignPropertyDescriptors.js +0 -23
  90. 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
- }
@@ -1,7 +0,0 @@
1
- import { AsyncLocalStorage } from "node:async_hooks";
2
-
3
- /**
4
- * Storage maintained by the execute() function and accessible to async
5
- * functions called during evaluation.
6
- */
7
- export default new AsyncLocalStorage();