@relate/contrib-web 0.0.0-stage → 0.1.0

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 (191) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +242 -2
  3. package/conformance/example-site/blank.html +2 -0
  4. package/conformance/example-site/broken.html +35 -0
  5. package/conformance/example-site/index.html +35 -0
  6. package/conformance/example-site/notes.html +35 -0
  7. package/conformance/example-site/page-1.html +35 -0
  8. package/conformance/example-site/page-2.html +35 -0
  9. package/conformance/example-site/public/descriptor-b.json +16 -0
  10. package/conformance/example-site/public/descriptor-broken.json +16 -0
  11. package/conformance/example-site/public/descriptor-mismatch.json +16 -0
  12. package/conformance/example-site/public/descriptor.json +16 -0
  13. package/conformance/example-site/public/graph-b.json +14408 -0
  14. package/conformance/example-site/public/graph.json +10808 -0
  15. package/conformance/example-site/rel-page.ts +147 -0
  16. package/conformance/example-site/vite.config.ts +23 -0
  17. package/conformance/make-example.ts +22 -0
  18. package/conformance/run.ts +152 -0
  19. package/conformance/scenarios.ts +285 -0
  20. package/dist/application/options.d.ts +9 -0
  21. package/dist/application/options.js +64 -0
  22. package/dist/application/options.js.map +1 -0
  23. package/dist/application/ranges.d.ts +7 -0
  24. package/dist/application/ranges.js +14 -0
  25. package/dist/application/ranges.js.map +1 -0
  26. package/dist/application/storage.d.ts +34 -0
  27. package/dist/application/storage.js +60 -0
  28. package/dist/application/storage.js.map +1 -0
  29. package/dist/application/types.d.ts +49 -0
  30. package/dist/application/types.js +2 -0
  31. package/dist/application/types.js.map +1 -0
  32. package/dist/build/canonical.d.ts +5 -0
  33. package/dist/build/canonical.js +26 -0
  34. package/dist/build/canonical.js.map +1 -0
  35. package/dist/build/descriptor.d.ts +16 -0
  36. package/dist/build/descriptor.js +13 -0
  37. package/dist/build/descriptor.js.map +1 -0
  38. package/dist/build/index.d.ts +6 -0
  39. package/dist/build/index.js +6 -0
  40. package/dist/build/index.js.map +1 -0
  41. package/dist/build/inline.d.ts +16 -0
  42. package/dist/build/inline.js +44 -0
  43. package/dist/build/inline.js.map +1 -0
  44. package/dist/build/prepare.d.ts +11 -0
  45. package/dist/build/prepare.js +25 -0
  46. package/dist/build/prepare.js.map +1 -0
  47. package/dist/catalog/api.d.ts +30 -0
  48. package/dist/catalog/api.js +56 -0
  49. package/dist/catalog/api.js.map +1 -0
  50. package/dist/catalog/catalog.d.ts +51 -0
  51. package/dist/catalog/catalog.js +104 -0
  52. package/dist/catalog/catalog.js.map +1 -0
  53. package/dist/catalog/directory.d.ts +30 -0
  54. package/dist/catalog/directory.js +116 -0
  55. package/dist/catalog/directory.js.map +1 -0
  56. package/dist/catalog/file.d.ts +12 -0
  57. package/dist/catalog/file.js +84 -0
  58. package/dist/catalog/file.js.map +1 -0
  59. package/dist/catalog/index.d.ts +10 -0
  60. package/dist/catalog/index.js +12 -0
  61. package/dist/catalog/index.js.map +1 -0
  62. package/dist/catalog/memory-storage.d.ts +16 -0
  63. package/dist/catalog/memory-storage.js +56 -0
  64. package/dist/catalog/memory-storage.js.map +1 -0
  65. package/dist/catalog/opfs-storage.d.ts +10 -0
  66. package/dist/catalog/opfs-storage.js +71 -0
  67. package/dist/catalog/opfs-storage.js.map +1 -0
  68. package/dist/catalog/remove.d.ts +21 -0
  69. package/dist/catalog/remove.js +85 -0
  70. package/dist/catalog/remove.js.map +1 -0
  71. package/dist/catalog/storage.d.ts +11 -0
  72. package/dist/catalog/storage.js +4 -0
  73. package/dist/catalog/storage.js.map +1 -0
  74. package/dist/catalog/types.d.ts +68 -0
  75. package/dist/catalog/types.js +4 -0
  76. package/dist/catalog/types.js.map +1 -0
  77. package/dist/client/application.d.ts +32 -0
  78. package/dist/client/application.js +99 -0
  79. package/dist/client/application.js.map +1 -0
  80. package/dist/client/client.d.ts +2 -0
  81. package/dist/client/client.js +445 -0
  82. package/dist/client/client.js.map +1 -0
  83. package/dist/client/diagnostic.d.ts +6 -0
  84. package/dist/client/diagnostic.js +35 -0
  85. package/dist/client/diagnostic.js.map +1 -0
  86. package/dist/client/events.d.ts +27 -0
  87. package/dist/client/events.js +31 -0
  88. package/dist/client/events.js.map +1 -0
  89. package/dist/client/failure.d.ts +13 -0
  90. package/dist/client/failure.js +40 -0
  91. package/dist/client/failure.js.map +1 -0
  92. package/dist/client/scope.d.ts +15 -0
  93. package/dist/client/scope.js +39 -0
  94. package/dist/client/scope.js.map +1 -0
  95. package/dist/client/status.d.ts +14 -0
  96. package/dist/client/status.js +34 -0
  97. package/dist/client/status.js.map +1 -0
  98. package/dist/client/subscriptions.d.ts +31 -0
  99. package/dist/client/subscriptions.js +64 -0
  100. package/dist/client/subscriptions.js.map +1 -0
  101. package/dist/client/types.d.ts +82 -0
  102. package/dist/client/types.js +2 -0
  103. package/dist/client/types.js.map +1 -0
  104. package/dist/config.d.ts +30 -0
  105. package/dist/config.js +28 -0
  106. package/dist/config.js.map +1 -0
  107. package/dist/conformance/run.d.ts +61 -0
  108. package/dist/conformance/run.js +121 -0
  109. package/dist/conformance/run.js.map +1 -0
  110. package/dist/conformance/scenarios.d.ts +25 -0
  111. package/dist/conformance/scenarios.js +257 -0
  112. package/dist/conformance/scenarios.js.map +1 -0
  113. package/dist/data/descriptor.d.ts +20 -0
  114. package/dist/data/descriptor.js +75 -0
  115. package/dist/data/descriptor.js.map +1 -0
  116. package/dist/data/types.d.ts +41 -0
  117. package/dist/data/types.js +3 -0
  118. package/dist/data/types.js.map +1 -0
  119. package/dist/data/validate.d.ts +22 -0
  120. package/dist/data/validate.js +118 -0
  121. package/dist/data/validate.js.map +1 -0
  122. package/dist/errors.d.ts +9 -0
  123. package/dist/errors.js +14 -0
  124. package/dist/errors.js.map +1 -0
  125. package/dist/index.d.ts +17 -0
  126. package/dist/index.js +8 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/profiles/index.d.ts +5 -0
  129. package/dist/profiles/index.js +9 -0
  130. package/dist/profiles/index.js.map +1 -0
  131. package/dist/profiles/per-page.d.ts +2 -0
  132. package/dist/profiles/per-page.js +11 -0
  133. package/dist/profiles/per-page.js.map +1 -0
  134. package/dist/profiles/persistent.d.ts +5 -0
  135. package/dist/profiles/persistent.js +14 -0
  136. package/dist/profiles/persistent.js.map +1 -0
  137. package/dist/validate.d.ts +5 -0
  138. package/dist/validate.js +4 -0
  139. package/dist/validate.js.map +1 -0
  140. package/dist/worker/application/classify.d.ts +30 -0
  141. package/dist/worker/application/classify.js +57 -0
  142. package/dist/worker/application/classify.js.map +1 -0
  143. package/dist/worker/application/init.d.ts +12 -0
  144. package/dist/worker/application/init.js +64 -0
  145. package/dist/worker/application/init.js.map +1 -0
  146. package/dist/worker/application/lifecycle.d.ts +29 -0
  147. package/dist/worker/application/lifecycle.js +86 -0
  148. package/dist/worker/application/lifecycle.js.map +1 -0
  149. package/dist/worker/application/losses.d.ts +11 -0
  150. package/dist/worker/application/losses.js +61 -0
  151. package/dist/worker/application/losses.js.map +1 -0
  152. package/dist/worker/application/migrate.d.ts +16 -0
  153. package/dist/worker/application/migrate.js +54 -0
  154. package/dist/worker/application/migrate.js.map +1 -0
  155. package/dist/worker/application/open-store.d.ts +31 -0
  156. package/dist/worker/application/open-store.js +60 -0
  157. package/dist/worker/application/open-store.js.map +1 -0
  158. package/dist/worker/application/seed.d.ts +14 -0
  159. package/dist/worker/application/seed.js +50 -0
  160. package/dist/worker/application/seed.js.map +1 -0
  161. package/dist/worker/application/transfer.d.ts +31 -0
  162. package/dist/worker/application/transfer.js +134 -0
  163. package/dist/worker/application/transfer.js.map +1 -0
  164. package/dist/worker/cache.d.ts +15 -0
  165. package/dist/worker/cache.js +45 -0
  166. package/dist/worker/cache.js.map +1 -0
  167. package/dist/worker/encode.d.ts +1 -0
  168. package/dist/worker/encode.js +43 -0
  169. package/dist/worker/encode.js.map +1 -0
  170. package/dist/worker/engine.d.ts +35 -0
  171. package/dist/worker/engine.js +99 -0
  172. package/dist/worker/engine.js.map +1 -0
  173. package/dist/worker/legacy-copy.d.ts +2 -0
  174. package/dist/worker/legacy-copy.js +19 -0
  175. package/dist/worker/legacy-copy.js.map +1 -0
  176. package/dist/worker/loader.d.ts +40 -0
  177. package/dist/worker/loader.js +96 -0
  178. package/dist/worker/loader.js.map +1 -0
  179. package/dist/worker/protocol.d.ts +121 -0
  180. package/dist/worker/protocol.js +2 -0
  181. package/dist/worker/protocol.js.map +1 -0
  182. package/dist/worker/store.d.ts +12 -0
  183. package/dist/worker/store.js +39 -0
  184. package/dist/worker/store.js.map +1 -0
  185. package/dist/worker/sweep.d.ts +8 -0
  186. package/dist/worker/sweep.js +21 -0
  187. package/dist/worker/sweep.js.map +1 -0
  188. package/dist/worker/worker.d.ts +1 -0
  189. package/dist/worker/worker.js +198 -0
  190. package/dist/worker/worker.js.map +1 -0
  191. package/package.json +81 -3
@@ -0,0 +1,17 @@
1
+ export { createClient } from "./client/client.js";
2
+ export { createSiteClient, resetPersistentClient } from "./profiles/index.js";
3
+ export { attachView, newScope } from "./client/scope.js";
4
+ export type { View } from "./client/scope.js";
5
+ export type { Client, ClientOptions, Diagnostic, GraphSource, Run } from "./client/types.js";
6
+ export type { Events } from "./client/events.js";
7
+ export type { Status } from "./client/status.js";
8
+ export type { Unsubscribe, Update } from "./client/subscriptions.js";
9
+ export { inRanges } from "./application/ranges.js";
10
+ export { CatalogError, listGraphs, removeGraph, resetCatalog } from "./catalog/api.js";
11
+ export type { CatalogErrorReason, ListOptions, Listing, RemoveOptions, RemoveResult } from "./catalog/api.js";
12
+ export type { ListingItem } from "./catalog/types.js";
13
+ export type { ApplicationOptions, ExportEnvelope, LossKind, LossReport, MigrationStep, RangeStep, StorageStatus, } from "./application/types.js";
14
+ export { GraphError } from "./errors.js";
15
+ export type { Reason } from "./errors.js";
16
+ export { validate, validateDescriptor, checkAgreement } from "./validate.js";
17
+ export type { AgreementResult, Descriptor, DescriptorValidationResult, GraphDocument, GraphLink, GraphNode, IndexSpec, Properties, PropertyValue, ValidationResult, } from "./validate.js";
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { createClient } from "./client/client.js";
2
+ export { createSiteClient, resetPersistentClient } from "./profiles/index.js";
3
+ export { attachView, newScope } from "./client/scope.js";
4
+ export { inRanges } from "./application/ranges.js";
5
+ export { CatalogError, listGraphs, removeGraph, resetCatalog } from "./catalog/api.js";
6
+ export { GraphError } from "./errors.js";
7
+ export { validate, validateDescriptor, checkAgreement } from "./validate.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAMzD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAYvF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Client, ClientOptions } from "../client/types.js";
2
+ /** The client for this page under the configured profile; the configured `navigation` value decides. */
3
+ export declare function createSiteClient(options: ClientOptions): Client;
4
+ export { perPageClient } from "./per-page.js";
5
+ export { persistentClient, resetPersistentClient } from "./persistent.js";
@@ -0,0 +1,9 @@
1
+ import { perPageClient } from "./per-page.js";
2
+ import { persistentClient } from "./persistent.js";
3
+ /** The client for this page under the configured profile; the configured `navigation` value decides. */
4
+ export function createSiteClient(options) {
5
+ return options.navigation === "client-routing" ? persistentClient(options) : perPageClient(options);
6
+ }
7
+ export { perPageClient } from "./per-page.js";
8
+ export { persistentClient, resetPersistentClient } from "./persistent.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/profiles/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,wGAAwG;AACxG,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,OAAO,OAAO,CAAC,UAAU,KAAK,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACtG,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Client, ClientOptions } from "../client/types.js";
2
+ export declare function perPageClient(options: ClientOptions): Client;
@@ -0,0 +1,11 @@
1
+ // The `per-page` profile (multi-page, no router, ADR-001 2.4): each page starts its own client, and a departing
2
+ // page drops its views' data when it is hidden.
3
+ import { createClient } from "../client/client.js";
4
+ export function perPageClient(options) {
5
+ const client = createClient({ ...options, navigation: "multi-page" });
6
+ // A multi-page navigation fires no router event, so `pagehide` is the departure. Dropping is best effort: data
7
+ // that outlives the page is removed by the sweep when the next worker starts.
8
+ globalThis.addEventListener?.("pagehide", () => void client.dropAllScopes());
9
+ return client;
10
+ }
11
+ //# sourceMappingURL=per-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"per-page.js","sourceRoot":"","sources":["../../src/profiles/per-page.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,gDAAgD;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,MAAM,UAAU,aAAa,CAAC,OAAsB;IAClD,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;IACtE,+GAA+G;IAC/G,8EAA8E;IAC9E,UAAU,CAAC,gBAAgB,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Client, ClientOptions } from "../client/types.js";
2
+ /** The visit's client; created on the first call, with that call's options. Later calls return it unchanged. */
3
+ export declare function persistentClient(options: ClientOptions): Client;
4
+ /** Destroy the visit's client and forget it (tests, and sites that tear the graph down). */
5
+ export declare function resetPersistentClient(): void;
@@ -0,0 +1,14 @@
1
+ // The `persistent` profile (client-side routing, ADR-001 2.3): one client for the visit, held in module state, so
2
+ // it survives route changes. A page that remounts its islands keeps the same client.
3
+ import { createClient } from "../client/client.js";
4
+ let visitClient = null;
5
+ /** The visit's client; created on the first call, with that call's options. Later calls return it unchanged. */
6
+ export function persistentClient(options) {
7
+ return (visitClient ??= createClient({ ...options, navigation: "client-routing" }));
8
+ }
9
+ /** Destroy the visit's client and forget it (tests, and sites that tear the graph down). */
10
+ export function resetPersistentClient() {
11
+ visitClient?.destroy();
12
+ visitClient = null;
13
+ }
14
+ //# sourceMappingURL=persistent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persistent.js","sourceRoot":"","sources":["../../src/profiles/persistent.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,qFAAqF;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,IAAI,WAAW,GAAkB,IAAI,CAAC;AAEtC,gHAAgH;AAChH,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,OAAO,CAAC,WAAW,KAAK,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;AACtF,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,qBAAqB;IACnC,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { validate } from "./data/validate.js";
2
+ export type { ValidationResult } from "./data/validate.js";
3
+ export { validateDescriptor, checkAgreement } from "./data/descriptor.js";
4
+ export type { DescriptorValidationResult, AgreementResult } from "./data/descriptor.js";
5
+ export type { Descriptor, GraphDocument, GraphLink, GraphNode, IndexSpec, Properties, PropertyValue } from "./data/types.js";
@@ -0,0 +1,4 @@
1
+ // The Node-only entry (`@relate/contrib-web/validate`): validators for build steps. No browser APIs.
2
+ export { validate } from "./data/validate.js";
3
+ export { validateDescriptor, checkAgreement } from "./data/descriptor.js";
4
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Lookup } from "../../catalog/catalog.js";
2
+ /** The label the earlier form of an application store carried on its record node. Named only in a message. */
3
+ export declare const LEGACY_MARKER_LABEL = "_RelateApplication";
4
+ export interface StoreFacts {
5
+ nodeCount: number;
6
+ indexCount: number;
7
+ /** Whether a node carries {@link LEGACY_MARKER_LABEL}; read only for a store with data and no entry. */
8
+ legacyMarker: boolean;
9
+ }
10
+ export type FailureReason = "store-unmarked" | "store-newer" | "import-interrupted" | "store-unreadable" | "store-lost";
11
+ export type Action = {
12
+ action: "first-run";
13
+ } | {
14
+ action: "reset-and-seed";
15
+ intent: "seeding" | "resetting";
16
+ } | {
17
+ action: "finish-removal";
18
+ } | {
19
+ action: "open";
20
+ } | {
21
+ action: "migrate";
22
+ from: number;
23
+ } | {
24
+ action: "fail";
25
+ reason: FailureReason;
26
+ message: string;
27
+ };
28
+ export declare function classify(lookup: Lookup, readFacts: () => StoreFacts, code: {
29
+ version: number;
30
+ }): Action;
@@ -0,0 +1,57 @@
1
+ /** The label the earlier form of an application store carried on its record node. Named only in a message. */
2
+ export const LEGACY_MARKER_LABEL = "_RelateApplication";
3
+ const isEmpty = (facts) => facts.nodeCount === 0 && facts.indexCount === 0;
4
+ export function classify(lookup, readFacts, code) {
5
+ switch (lookup.status) {
6
+ case "catalog-unreadable":
7
+ return { action: "fail", reason: "store-unreadable", message: `the catalog could not be read: ${lookup.message}` };
8
+ case "catalog-newer":
9
+ return { action: "fail", reason: "store-newer", message: `the catalog's format ${lookup.format} is newer than this code's` };
10
+ case "invalid":
11
+ return { action: "fail", reason: "store-unreadable", message: `the catalog's entry for this application is not valid: ${lookup.reason}` };
12
+ case "none": {
13
+ const facts = readFacts();
14
+ if (isEmpty(facts))
15
+ return { action: "first-run" };
16
+ const legacy = facts.legacyMarker ? ` It holds a node labelled ${LEGACY_MARKER_LABEL}, the record an earlier form of this package kept inside the graph; that form is not read any more.` : "";
17
+ return {
18
+ action: "fail",
19
+ reason: "store-unmarked",
20
+ message: `the store holds ${facts.nodeCount} nodes and the catalog has no entry for it; it was not created by this application, or its entry was removed.${legacy}`,
21
+ };
22
+ }
23
+ case "entry":
24
+ break;
25
+ }
26
+ const entry = lookup.entry;
27
+ if (entry.kind !== "application")
28
+ return { action: "fail", reason: "store-unreadable", message: "the catalog's entry for this store is not an application's" };
29
+ // A newer release's store is refused whatever state it is in, so older code never resets it.
30
+ if (entry.version > code.version) {
31
+ return { action: "fail", reason: "store-newer", message: `the store is at version ${entry.version}, newer than this code's ${code.version}` };
32
+ }
33
+ // A migration to a version above this code's has started, and some of its changes may already be applied: this code
34
+ // cannot finish it, and must not report the data ready.
35
+ if (entry.state === "migrating" && entry.target !== undefined && entry.target > code.version) {
36
+ return { action: "fail", reason: "store-newer", message: `a migration of this store to version ${entry.target} started and did not finish; this code is at version ${code.version}` };
37
+ }
38
+ switch (entry.state) {
39
+ case "seeding":
40
+ return { action: "reset-and-seed", intent: "seeding" };
41
+ case "resetting":
42
+ return { action: "reset-and-seed", intent: "resetting" };
43
+ case "importing":
44
+ return { action: "fail", reason: "import-interrupted", message: "an import into this store did not finish" };
45
+ case "removing":
46
+ return { action: "finish-removal" };
47
+ case "migrating":
48
+ return { action: "migrate", from: entry.version };
49
+ case "ready":
50
+ break;
51
+ }
52
+ if (entry.seeded && isEmpty(readFacts())) {
53
+ return { action: "fail", reason: "store-lost", message: "the catalog says this store was filled, and it is empty: its data is gone" };
54
+ }
55
+ return entry.version < code.version ? { action: "migrate", from: entry.version } : { action: "open" };
56
+ }
57
+ //# sourceMappingURL=classify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classify.js","sourceRoot":"","sources":["../../../src/worker/application/classify.ts"],"names":[],"mappings":"AAKA,8GAA8G;AAC9G,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CAAC;AAmBxD,MAAM,OAAO,GAAG,CAAC,KAAiB,EAAW,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,CAAC;AAEhG,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,SAA2B,EAAE,IAAyB;IAC7F,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,oBAAoB;YACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,kCAAkC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACrH,KAAK,eAAe;YAClB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,wBAAwB,MAAM,CAAC,MAAM,4BAA4B,EAAE,CAAC;QAC/H,KAAK,SAAS;YACZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,0DAA0D,M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OAAO,EAAE,EAAE,CAAC;IACxL,CAAC;IACD,QAAQ,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,SAAS;YACZ,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QACzD,KAAK,WAAW;YACd,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QAC3D,KAAK,WAAW;YACd,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,0CAA0C,EAAE,CAAC;QAC/G,KAAK,UAAU;YACb,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QACtC,KAAK,WAAW;YACd,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;QACpD,KAAK,OAAO;YACV,MAAM;IACV,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;QACzC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,2EAA2E,EAAE,CAAC;IACxI,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACxG,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Catalog } from "../../catalog/catalog.js";
2
+ import type { Engine } from "../engine.js";
3
+ import type { InitMessage, WorkerMessage } from "../protocol.js";
4
+ /** What the worker serves queries and later transfers with. */
5
+ export interface ApplicationSession {
6
+ engine: Engine;
7
+ catalog: Catalog;
8
+ /** The store's name in the catalog, `app-<name>`. */
9
+ store: string;
10
+ }
11
+ /** Returns the session to serve with, or null after sending `init-failed`. */
12
+ export declare function initApplication(msg: InitMessage, send: (m: WorkerMessage) => void): Promise<ApplicationSession | null>;
@@ -0,0 +1,64 @@
1
+ import { openCatalog } from "../../catalog/index.js";
2
+ import { APP_STORE_PREFIX } from "../../config.js";
3
+ import { Engine as EngineClass } from "../engine.js";
4
+ import { needsSeed, openApplication } from "./lifecycle.js";
5
+ import { loadSeed, SeedError } from "./seed.js";
6
+ import { openApplicationStore } from "./open-store.js";
7
+ const since = (t0) => Math.round((performance.now() - t0) * 10) / 10;
8
+ const messageOf = (e) => (e instanceof Error ? e.message : String(e));
9
+ /** Returns the session to serve with, or null after sending `init-failed`. */
10
+ export async function initApplication(msg, send) {
11
+ const app = msg.application;
12
+ const t0 = performance.now();
13
+ const timings = { total: 0 };
14
+ const fail = (reason, message) => {
15
+ send({ type: "init-failed", reason, message });
16
+ return null;
17
+ };
18
+ let t = performance.now();
19
+ await EngineClass.load(msg.engineUrl);
20
+ timings.init = since(t);
21
+ t = performance.now();
22
+ const outcome = await openApplicationStore(app, { report: (r) => send({ type: "storage", ...r }) });
23
+ timings.open = since(t);
24
+ if ("fail" in outcome)
25
+ return fail(outcome.fail, outcome.message);
26
+ const store = `${APP_STORE_PREFIX}${app.name}`;
27
+ const catalog = openCatalog(outcome.storage.kind === "durable");
28
+ const lifecycle = { catalog, store, name: app.name, version: app.version, intent: app.intent };
29
+ // The seed is fetched only when it will be used: a ready store restores without it.
30
+ let seed = app.seed.document;
31
+ let descriptor = app.seed.descriptor;
32
+ if (seed === null && (await needsSeed(outcome.engine, lifecycle))) {
33
+ try {
34
+ const loaded = await loadSeed(app.seed);
35
+ seed = loaded.document;
36
+ descriptor = loaded.descriptor;
37
+ }
38
+ catch (e) {
39
+ outcome.engine.release();
40
+ return fail(e instanceof SeedError ? e.reason : "worker-error", messageOf(e));
41
+ }
42
+ }
43
+ t = performance.now();
44
+ const result = await openApplication(outcome.engine, {
45
+ ...lifecycle,
46
+ seed,
47
+ descriptor,
48
+ indexes: app.indexes,
49
+ migrations: app.migrations,
50
+ });
51
+ if (!result.ok) {
52
+ outcome.engine.release();
53
+ return fail(result.reason, result.message);
54
+ }
55
+ if (result.restored)
56
+ timings.restore = since(t);
57
+ else
58
+ timings.load = since(t);
59
+ timings.total = since(t0);
60
+ send({ type: "storage", ...outcome.storage });
61
+ send({ type: "ready", restored: result.restored, timings });
62
+ return { engine: outcome.engine, catalog, store };
63
+ }
64
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/worker/application/init.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,KAAK,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AACrF,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAUvF,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAgB,EAAE,IAAgC;IACtF,MAAM,GAAG,GAAG,GAAG,CAAC,WAAY,CAAC;IAC7B,MAAM,EAAE,GAAG,WAAW,CAAC,G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OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5D,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACpD,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { type Catalog } from "../../catalog/catalog.js";
2
+ import type { MigrationStep } from "../../application/types.js";
3
+ import type { Descriptor, IndexSpec } from "../../data/types.js";
4
+ import type { Engine } from "../engine.js";
5
+ import { type FailureReason } from "./classify.js";
6
+ export interface LifecycleInput {
7
+ /** The catalog and the store's name in it (`app-<name>`), with the application's name. */
8
+ catalog: Catalog;
9
+ store: string;
10
+ name: string;
11
+ version: number;
12
+ intent: "open" | "reset";
13
+ /** The seed's data document, already fetched. */
14
+ seed: unknown;
15
+ descriptor: Descriptor | null;
16
+ indexes: IndexSpec[];
17
+ migrations: Record<string, MigrationStep[]>;
18
+ }
19
+ export type LifecycleResult = {
20
+ ok: true;
21
+ restored: boolean;
22
+ } | {
23
+ ok: false;
24
+ reason: FailureReason | "migration-failed" | "invalid-document" | "mismatch";
25
+ message: string;
26
+ };
27
+ /** Whether opening this store will load the seed, so a ready store does not fetch it. */
28
+ export declare function needsSeed(engine: Engine, input: Pick<LifecycleInput, "catalog" | "store" | "version" | "intent">): Promise<boolean>;
29
+ export declare function openApplication(engine: Engine, input: LifecycleInput): Promise<LifecycleResult>;
@@ -0,0 +1,86 @@
1
+ // The lifecycle of an application store (ADR-010 2.2, 2.3): classify what was opened from its catalog entry, then seed,
2
+ // recover, migrate or stop. An operation writes its intent to the entry before it changes data and its outcome after.
3
+ // Engine calls stay synchronous; the catalog calls between them are awaited. Everything takes an `Engine` and a
4
+ // `Catalog`, so it is tested in Node with the real engine and the in-memory catalog storage.
5
+ import { CatalogUnavailable } from "../../catalog/catalog.js";
6
+ import { LoadError, loadGraph, prepare, run } from "../loader.js";
7
+ import { userIndexCount } from "../sweep.js";
8
+ import { classify, LEGACY_MARKER_LABEL } from "./classify.js";
9
+ import { migrate, MigrationError } from "./migrate.js";
10
+ const count = (engine, statement) => {
11
+ const v = Object.values(run(engine, statement).rows[0] ?? {})[0];
12
+ return typeof v === "number" ? v : 0;
13
+ };
14
+ /** The facts about the store the classifier asks for; none is read for a store whose entry decides on its own. */
15
+ function readFacts(engine) {
16
+ const nodeCount = count(engine, "MATCH (n) RETURN count(n) AS c");
17
+ const indexCount = userIndexCount(engine);
18
+ const legacyMarker = nodeCount > 0 && count(engine, `MATCH (n:${LEGACY_MARKER_LABEL}) RETURN count(n) AS c`) > 0;
19
+ return { nodeCount, indexCount, legacyMarker };
20
+ }
21
+ async function inspect(engine, input) {
22
+ const lookup = await input.catalog.lookup(input.store);
23
+ return classify(lookup, () => readFacts(engine), { version: input.version });
24
+ }
25
+ /**
26
+ * Fill a store from the seed: validate, write the intent (`seeding` or `resetting`), reset when the store may hold
27
+ * other data, load the seed and its indexes, then write `ready`. An invalid seed fails before anything is written.
28
+ */
29
+ async function seedStore(engine, input, intent, reset) {
30
+ const document = prepare(input.seed, { descriptor: input.descriptor });
31
+ const seeded = document.nodes.length > 0;
32
+ const base = { kind: "application", name: input.name, version: input.version, seeded };
33
+ await input.catalog.set(input.store, { ...base, state: intent });
34
+ if (reset)
35
+ engine.reset();
36
+ loadGraph(engine, document, { descriptor: input.descriptor, indexes: input.indexes });
37
+ await input.catalog.set(input.store, { ...base, state: "ready" });
38
+ }
39
+ /** Whether opening this store will load the seed, so a ready store does not fetch it. */
40
+ export async function needsSeed(engine, input) {
41
+ if (input.intent === "reset")
42
+ return true;
43
+ const action = (await inspect(engine, input)).action;
44
+ return action === "first-run" || action === "reset-and-seed" || action === "finish-removal";
45
+ }
46
+ export async function openApplication(engine, input) {
47
+ try {
48
+ if (input.intent === "reset") {
49
+ await seedStore(engine, input, "resetting", true);
50
+ return { ok: true, restored: false };
51
+ }
52
+ const action = await inspect(engine, input);
53
+ switch (action.action) {
54
+ case "fail":
55
+ return { ok: false, reason: action.reason, message: action.message };
56
+ case "open":
57
+ return { ok: true, restored: true };
58
+ case "migrate":
59
+ await migrate(engine, { catalog: input.catalog, store: input.store, name: input.name }, action.from, input.version, input.migrations);
60
+ return { ok: true, restored: true };
61
+ case "reset-and-seed":
62
+ await seedStore(engine, input, action.intent, true);
63
+ return { ok: true, restored: false };
64
+ case "finish-removal":
65
+ // The directory cannot be removed while this worker holds it, so the removal is finished by a reset.
66
+ engine.reset();
67
+ await input.catalog.delete(input.store);
68
+ await seedStore(engine, input, "seeding", false);
69
+ return { ok: true, restored: false };
70
+ case "first-run":
71
+ await seedStore(engine, input, "seeding", false);
72
+ return { ok: true, restored: false };
73
+ }
74
+ }
75
+ catch (e) {
76
+ // A catalog that does not parse, or was written by a newer format, is never written over (ADR-010 2.3).
77
+ if (e instanceof CatalogUnavailable)
78
+ return { ok: false, reason: e.reason === "newer" ? "store-newer" : "store-unreadable", message: e.message };
79
+ if (e instanceof MigrationError)
80
+ return { ok: false, reason: "migration-failed", message: e.message };
81
+ if (e instanceof LoadError)
82
+ return { ok: false, reason: e.reason, message: e.message };
83
+ throw e;
84
+ }
85
+ }
86
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../../src/worker/application/lifecycle.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,sHAAsH;AACtH,gHAAgH;AAChH,6FAA6F;AAC7F,OAAO,EAAE,kBAAkB,EAAgB,MAAM,0BAA0B,CAAC;AAI5E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,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AS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACjD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;YACvC,KAAK,WAAW;gBACd,MAAM,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACjD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,wGAAwG;QACxG,IAAI,CAAC,YAAY,kBAAkB;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,kBAAkB,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACjJ,IAAI,CAAC,YAAY,cAAc;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACtG,IAAI,CAAC,YAAY,SAAS;YAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACvF,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { LossKind } from "../../application/types.js";
2
+ /** One property as the typed read returns it: the key, the engine's type name, the value's exact text. */
3
+ export type TypedValue = [key: string, type: string, text: string];
4
+ export interface Converted {
5
+ /** True when the value goes into the document; false when it is left out. */
6
+ keep: boolean;
7
+ value?: unknown;
8
+ loss?: LossKind;
9
+ }
10
+ /** `json` is the value as the properties read gives it (numbers pass through JSON, so large integers are inexact there). */
11
+ export declare function convert(type: string, text: string, json: unknown): Converted;
@@ -0,0 +1,61 @@
1
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
2
+ /** An engine type name without nullability: `LIST<INTEGER NOT NULL> NOT NULL` is `LIST<INTEGER>`. */
3
+ function base(type) {
4
+ return type.replace(/ NOT NULL/g, "").trim();
5
+ }
6
+ const isTemporal = (t) => /^(DATE|ZONED DATETIME|LOCAL DATETIME|ZONED TIME|LOCAL TIME)$/.test(t);
7
+ /** The elements of a list's text, `[1, 2]`, as strings. A list holds one kind of value, so a split on ", " is exact for numbers. */
8
+ const listElements = (text) => text.slice(1, -1).split(", ").filter((x) => x !== "");
9
+ const beyond = (text) => {
10
+ try {
11
+ const n = BigInt(text);
12
+ return n > MAX_SAFE || n < -MAX_SAFE;
13
+ }
14
+ catch {
15
+ return false;
16
+ }
17
+ };
18
+ /** `json` is the value as the properties read gives it (numbers pass through JSON, so large integers are inexact there). */
19
+ export function convert(type, text, json) {
20
+ const t = base(type);
21
+ switch (t) {
22
+ case "STRING":
23
+ case "BOOLEAN":
24
+ return { keep: true, value: json };
25
+ case "INTEGER":
26
+ return beyond(text) ? { keep: true, value: Number(text), loss: "integer-beyond-2^53" } : { keep: true, value: json };
27
+ case "FLOAT":
28
+ return Number.isInteger(Number(text)) && Number.isFinite(Number(text))
29
+ ? { keep: true, value: Number(text), loss: "whole-number-float" }
30
+ : { keep: true, value: json };
31
+ case "DURATION":
32
+ return { keep: true, value: text, loss: "duration" };
33
+ case "POINT":
34
+ return { keep: false, loss: "point" };
35
+ case "LIST<NOTHING>":
36
+ return { keep: false, loss: "empty-list" };
37
+ }
38
+ if (isTemporal(t))
39
+ return { keep: true, value: json ?? text, loss: "date" };
40
+ const list = /^LIST<(.*)>$/.exec(t);
41
+ if (list) {
42
+ const element = list[1];
43
+ if (element === "STRING" || element === "BOOLEAN")
44
+ return { keep: true, value: json };
45
+ if (element === "INTEGER")
46
+ return listElements(text).some(beyond) ? { keep: true, value: listElements(text).map(Number), loss: "integer-beyond-2^53" } : { keep: true, value: json };
47
+ if (element === "FLOAT") {
48
+ const items = listElements(text);
49
+ // a list with any fractional element is written as floats on load; only an all-whole list reads back as integers
50
+ return items.length > 0 && items.every((x) => Number.isInteger(Number(x))) ? { keep: true, value: items.map(Number), loss: "whole-number-float" } : { keep: true, value: json };
51
+ }
52
+ if (isTemporal(element))
53
+ return { keep: true, value: json, loss: "date" };
54
+ if (element === "DURATION")
55
+ return { keep: true, value: json, loss: "duration" };
56
+ if (element === "POINT")
57
+ return { keep: false, loss: "point" };
58
+ }
59
+ throw new Error(`export cannot read a value of type ${type}`);
60
+ }
61
+ //# sourceMappingURL=losses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"losses.js","sourceRoot":"","sources":["../../../src/worker/application/losses.ts"],"names":[],"mappings":"AAeA,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEjD,qGAAqG;AACrG,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,CAAS,EAAW,EAAE,CAAC,8DAA8D,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAElH,oIAAoI;AACpI,MAAM,YAAY,GAAG,CAAC,IAAY,EAAY,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAEvG,MAAM,MAAM,GAAG,CAAC,IAAY,EAAW,EAAE;IACvC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QACvB,OAAO,CAAC,GAAG,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IACvC,CAAC;IAA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,CAAC;QACD,IAAI,UAAU,CAAC,OAAO,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1E,IAAI,OAAO,KAAK,UAAU;YAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QACjF,IAAI,OAAO,KAAK,OAAO;YAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACjE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Catalog } from "../../catalog/catalog.js";
2
+ import type { MigrationStep } from "../../application/types.js";
3
+ import type { Engine } from "../engine.js";
4
+ /** A migration statement failed; the entry is at the last completed version. */
5
+ export declare class MigrationError extends Error {
6
+ readonly version: number;
7
+ readonly statement: string;
8
+ constructor(version: number, statement: string, cause: string);
9
+ }
10
+ export interface MigrationTarget {
11
+ catalog: Catalog;
12
+ store: string;
13
+ name: string;
14
+ }
15
+ /** For each version from `from + 1` to `to`: `migrating`, its steps in order, then `ready` at that version. */
16
+ export declare function migrate(engine: Engine, target: MigrationTarget, from: number, to: number, migrations: Record<string, MigrationStep[]>): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import { run } from "../loader.js";
2
+ /** A migration statement failed; the entry is at the last completed version. */
3
+ export class MigrationError extends Error {
4
+ version;
5
+ statement;
6
+ constructor(version, statement, cause) {
7
+ super(`migration to version ${version} failed: ${cause} (statement: ${statement})`);
8
+ this.name = "MigrationError";
9
+ this.version = version;
10
+ this.statement = statement;
11
+ }
12
+ }
13
+ const quote = (name) => `\`${name.replace(/`/g, "``")}\``;
14
+ function runRange(engine, step) {
15
+ const bounds = run(engine, `MATCH (n:${quote(step.label)}) RETURN min(n.${quote(step.property)}) AS lo, max(n.${quote(step.property)}) AS hi`).rows[0];
16
+ const lo = bounds?.lo;
17
+ const hi = bounds?.hi;
18
+ if (typeof lo !== "number" || typeof hi !== "number")
19
+ return; // no node has the property: nothing to do
20
+ for (let from = Math.floor(lo); from <= hi; from += step.step)
21
+ run(engine, step.statement, { from, to: from + step.step });
22
+ }
23
+ function runStep(engine, version, step) {
24
+ const text = typeof step === "string" ? step : step.statement;
25
+ try {
26
+ if (typeof step === "string")
27
+ run(engine, step);
28
+ else
29
+ runRange(engine, step);
30
+ }
31
+ catch (e) {
32
+ throw new MigrationError(version, text, e instanceof Error ? e.message : String(e));
33
+ }
34
+ }
35
+ /** For each version from `from + 1` to `to`: `migrating`, its steps in order, then `ready` at that version. */
36
+ export async function migrate(engine, target, from, to, migrations) {
37
+ for (let version = from + 1; version <= to; version++) {
38
+ const steps = migrations[String(version)];
39
+ // Advancing the version without running anything would record data as migrated that never was.
40
+ if (!steps)
41
+ throw new MigrationError(version, "", "the application gives no migration for this version, so the store cannot be carried forward");
42
+ const base = (current) => ({ kind: "application", name: target.name, seeded: current?.seeded ?? true });
43
+ await target.catalog.update(target.store, (current) => ({
44
+ ...base(current),
45
+ state: "migrating",
46
+ version: version - 1,
47
+ target: version,
48
+ }));
49
+ for (const step of steps)
50
+ runStep(engine, version, step);
51
+ await target.catalog.update(target.store, (current) => ({ ...base(current), state: "ready", version }));
52
+ }
53
+ }
54
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../../src/worker/application/migrate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,gFAAgF;AAChF,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,OAAO,CAAS;IAChB,SAAS,CAAS;IAC3B,YAAY,OAAe,EAAE,SAAiB,EAAE,KAAa;QAC3D,KAAK,CAAC,wBAAwB,OAAO,YAAY,KAAK,gBAAgB,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KAAK;YAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACzD,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,OAA0C,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC7I,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ApplicationInit } from "../protocol.js";
2
+ import { Engine } from "../engine.js";
3
+ export type StorageReport = {
4
+ kind: "durable";
5
+ } | {
6
+ kind: "memory";
7
+ reason: "unavailable" | "locked" | "error";
8
+ } | {
9
+ kind: "waiting";
10
+ reason: "locked";
11
+ };
12
+ export type OpenOutcome = {
13
+ engine: Engine;
14
+ storage: Exclude<StorageReport, {
15
+ kind: "waiting";
16
+ }>;
17
+ } | {
18
+ fail: "unavailable" | "store-unreadable";
19
+ message: string;
20
+ };
21
+ export interface OpenHooks {
22
+ /** Tell the page the state changed (only `waiting` is sent from here; the caller reports the outcome). */
23
+ report(report: StorageReport): void;
24
+ open?: (name: string) => Promise<Engine>;
25
+ hasStorage?: () => Promise<boolean>;
26
+ sleep?: (ms: number) => Promise<void>;
27
+ waits?: () => Iterable<number>;
28
+ }
29
+ /** True when the browser gives this worker an origin-private file system and Web Locks, which the catalog needs (ADR-010 2.2). */
30
+ export declare function storageAvailable(): Promise<boolean>;
31
+ export declare function openApplicationStore(app: Pick<ApplicationInit, "name" | "onUnavailable" | "onError" | "whenLocked">, hooks: OpenHooks): Promise<OpenOutcome>;