@drupflare/spool 0.4.0 → 1.0.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 (162) hide show
  1. package/README.md +206 -1756
  2. package/dist/angular/index.d.ts +13 -0
  3. package/dist/angular/index.js +25 -0
  4. package/dist/angular/pages.d.ts +28 -0
  5. package/dist/angular/pages.js +85 -0
  6. package/dist/cdn/client.js +1 -1
  7. package/dist/cdn/location.d.ts +6 -0
  8. package/dist/cdn/location.js +8 -0
  9. package/dist/cdn/manifest.json +7 -7
  10. package/dist/cdn/spool-sw.js +1 -1
  11. package/dist/client/bootstrap.d.ts +57 -0
  12. package/dist/client/bootstrap.js +307 -0
  13. package/dist/client/contact.d.ts +24 -0
  14. package/dist/client/contact.js +66 -0
  15. package/dist/client/declared.d.ts +23 -0
  16. package/dist/client/declared.js +68 -0
  17. package/dist/client/entry.js +91 -2
  18. package/dist/client/gate.d.ts +1 -0
  19. package/dist/client/gate.js +148 -0
  20. package/dist/client/index.d.ts +25 -0
  21. package/dist/client/index.js +1 -0
  22. package/dist/client/live.d.ts +66 -0
  23. package/dist/client/live.js +225 -0
  24. package/dist/client/navigate-entry.d.ts +1 -0
  25. package/dist/client/navigate-entry.js +4 -0
  26. package/dist/client/navigate.d.ts +54 -0
  27. package/dist/client/navigate.js +272 -0
  28. package/dist/client/persist.d.ts +2 -0
  29. package/dist/client/persist.js +9 -0
  30. package/dist/client/register.d.ts +11 -1
  31. package/dist/client/register.js +19 -8
  32. package/dist/express/index.d.ts +11 -0
  33. package/dist/express/index.js +209 -0
  34. package/dist/hono/index.d.ts +19 -0
  35. package/dist/hono/index.js +49 -0
  36. package/dist/next/index.d.ts +33 -0
  37. package/dist/next/index.js +41 -0
  38. package/dist/next/pages.d.ts +22 -0
  39. package/dist/next/pages.js +39 -0
  40. package/dist/node/listener.d.ts +3 -0
  41. package/dist/node/listener.js +57 -2
  42. package/dist/nuxt/index.d.ts +22 -0
  43. package/dist/nuxt/index.js +104 -0
  44. package/dist/nuxt/pages.d.ts +26 -0
  45. package/dist/nuxt/pages.js +48 -0
  46. package/dist/nuxt/runtime/index.d.ts +24 -0
  47. package/dist/nuxt/runtime/index.js +58 -0
  48. package/dist/plugins/coverage.d.ts +14 -0
  49. package/dist/plugins/coverage.js +27 -0
  50. package/dist/plugins/mode.d.ts +19 -0
  51. package/dist/plugins/mode.js +20 -0
  52. package/dist/plugins/path.d.ts +16 -0
  53. package/dist/plugins/path.js +139 -0
  54. package/dist/plugins/report.d.ts +22 -0
  55. package/dist/plugins/report.js +18 -0
  56. package/dist/plugins/routes.d.ts +38 -0
  57. package/dist/plugins/routes.js +52 -0
  58. package/dist/plugins/static.d.ts +42 -0
  59. package/dist/plugins/static.js +97 -0
  60. package/dist/protocol/bundle.d.ts +111 -0
  61. package/dist/protocol/bundle.js +428 -0
  62. package/dist/protocol/config.d.ts +65 -1
  63. package/dist/protocol/config.js +28 -0
  64. package/dist/protocol/dataset.d.ts +6 -0
  65. package/dist/protocol/dataset.js +6 -0
  66. package/dist/protocol/envelope.d.ts +33 -1
  67. package/dist/protocol/envelope.js +15 -1
  68. package/dist/protocol/errors.d.ts +1 -1
  69. package/dist/protocol/index-rows.d.ts +22 -0
  70. package/dist/protocol/index-rows.js +53 -0
  71. package/dist/protocol/index.d.ts +2 -0
  72. package/dist/protocol/index.js +2 -0
  73. package/dist/protocol/normalise.d.ts +4 -4
  74. package/dist/protocol/normalise.js +9 -5
  75. package/dist/protocol/ring.d.ts +58 -0
  76. package/dist/protocol/ring.js +6 -0
  77. package/dist/protocol/route.d.ts +57 -11
  78. package/dist/protocol/route.js +95 -3
  79. package/dist/protocol/tag.d.ts +22 -2
  80. package/dist/protocol/tag.js +25 -4
  81. package/dist/protocol/view.d.ts +2 -0
  82. package/dist/protocol/view.js +8 -2
  83. package/dist/protocol/views.d.ts +6 -0
  84. package/dist/protocol/views.js +15 -0
  85. package/dist/protocol/write.d.ts +92 -4
  86. package/dist/protocol/write.js +251 -9
  87. package/dist/proxy/eligible.d.ts +22 -1
  88. package/dist/proxy/eligible.js +62 -15
  89. package/dist/proxy/proxy.js +28 -18
  90. package/dist/react-router/index.d.ts +20 -0
  91. package/dist/react-router/index.js +60 -0
  92. package/dist/react-router/pages.d.ts +34 -0
  93. package/dist/react-router/pages.js +83 -0
  94. package/dist/report/demand.d.ts +49 -0
  95. package/dist/report/demand.js +60 -0
  96. package/dist/report/economics.d.ts +55 -0
  97. package/dist/report/economics.js +189 -0
  98. package/dist/report/headline.d.ts +158 -0
  99. package/dist/report/headline.js +473 -0
  100. package/dist/report/index.d.ts +2 -0
  101. package/dist/report/index.js +2 -0
  102. package/dist/report/inputs.d.ts +79 -0
  103. package/dist/report/inputs.js +115 -0
  104. package/dist/report/measurement.d.ts +1 -1
  105. package/dist/report/measurement.js +5 -1
  106. package/dist/report/traffic.d.ts +8 -0
  107. package/dist/report/traffic.js +7 -0
  108. package/dist/server/bundle.d.ts +55 -0
  109. package/dist/server/bundle.js +172 -0
  110. package/dist/server/dataset.d.ts +8 -2
  111. package/dist/server/dataset.js +51 -4
  112. package/dist/server/embedded.d.ts +7 -3
  113. package/dist/server/embedded.js +7 -3
  114. package/dist/server/index.d.ts +5 -1
  115. package/dist/server/index.js +5 -1
  116. package/dist/server/live-sockets.d.ts +54 -0
  117. package/dist/server/live-sockets.js +131 -0
  118. package/dist/server/live.d.ts +146 -0
  119. package/dist/server/live.js +228 -0
  120. package/dist/server/ring.d.ts +77 -0
  121. package/dist/server/ring.js +311 -0
  122. package/dist/server/spool.d.ts +139 -4
  123. package/dist/server/spool.js +457 -28
  124. package/dist/server/static.d.ts +42 -0
  125. package/dist/server/static.js +29 -0
  126. package/dist/server/stub.d.ts +43 -5
  127. package/dist/server/stub.js +126 -8
  128. package/dist/server/write.d.ts +23 -1
  129. package/dist/server/write.js +96 -0
  130. package/dist/stores/durable-object.d.ts +46 -0
  131. package/dist/stores/durable-object.js +114 -0
  132. package/dist/sw/analytics.d.ts +1 -1
  133. package/dist/sw/analytics.js +2 -2
  134. package/dist/sw/coverage.d.ts +6 -0
  135. package/dist/sw/coverage.js +34 -0
  136. package/dist/sw/family.d.ts +15 -0
  137. package/dist/sw/family.js +48 -0
  138. package/dist/sw/idb.d.ts +2 -0
  139. package/dist/sw/idb.js +2 -2
  140. package/dist/sw/index.d.ts +2 -0
  141. package/dist/sw/index.js +1 -0
  142. package/dist/sw/pack/store.d.ts +128 -0
  143. package/dist/sw/pack/store.js +737 -0
  144. package/dist/sw/policy.d.ts +2 -0
  145. package/dist/sw/policy.js +11 -0
  146. package/dist/sw/probe.d.ts +16 -0
  147. package/dist/sw/probe.js +25 -0
  148. package/dist/sw/router.d.ts +3 -2
  149. package/dist/sw/router.js +15 -2
  150. package/dist/sw/runtime.d.ts +48 -1
  151. package/dist/sw/runtime.js +548 -68
  152. package/dist/sw/scheduler.d.ts +6 -1
  153. package/dist/sw/scheduler.js +22 -5
  154. package/dist/sw/write.d.ts +41 -1
  155. package/dist/sw/write.js +188 -5
  156. package/dist/version.d.ts +1 -1
  157. package/dist/version.js +1 -2
  158. package/dist/vite/index.d.ts +26 -0
  159. package/dist/vite/index.js +66 -0
  160. package/dist/vue/index.d.ts +36 -0
  161. package/dist/vue/index.js +53 -0
  162. package/package.json +64 -4
@@ -0,0 +1,15 @@
1
+ import type { DatasetRow } from '../protocol/dataset.js';
2
+ import type { SerializedRoute } from '../protocol/route.js';
3
+ import type { StoredArtifact } from './storage.js';
4
+ /**
5
+ * The page a family route answers for `path`, built from the row `held` finds under its key. The
6
+ * template or renderer gets `{ params, row }` in the artifact's data, the same context the server
7
+ * builds; a data route gets the row itself, since its answer is the row's JSON. Undefined when no
8
+ * row is held under that key; the network answers.
9
+ */
10
+ export declare function familyPage(held: (key: string) => Promise<DatasetRow | undefined>, route: SerializedRoute, path: string, now: number): Promise<StoredArtifact | undefined>;
11
+ /**
12
+ * The page of a cross-origin collection. Its list is the held rows of `query.dataset`, which the
13
+ * route's query runs over at render time, so the artifact carries no items of its own.
14
+ */
15
+ export declare function collectionPage(path: string, now: number): StoredArtifact;
@@ -0,0 +1,48 @@
1
+ import { PROTOCOL_VERSION } from '../protocol/artifact.js';
2
+ import { matchPattern } from '../protocol/pattern.js';
3
+ /**
4
+ * The page a family route answers for `path`, built from the row `held` finds under its key. The
5
+ * template or renderer gets `{ params, row }` in the artifact's data, the same context the server
6
+ * builds; a data route gets the row itself, since its answer is the row's JSON. Undefined when no
7
+ * row is held under that key; the network answers.
8
+ */
9
+ export async function familyPage(held, route, path, now) {
10
+ const family = route.family;
11
+ if (family === undefined)
12
+ return undefined;
13
+ if (!['template', 'projection', 'data'].includes(route.strategy))
14
+ return undefined;
15
+ const params = matchPattern(route.pattern, path);
16
+ const key = params?.[family.key];
17
+ if (params === null || key === undefined)
18
+ return undefined;
19
+ const row = await held(key);
20
+ if (row === undefined)
21
+ return undefined;
22
+ const artifact = {
23
+ protocol: PROTOCOL_VERSION,
24
+ id: path,
25
+ scope: route.scope,
26
+ strategy: route.strategy,
27
+ deps: [],
28
+ vector: 0,
29
+ body: { data: route.strategy === 'data' ? row : { params, row } }
30
+ };
31
+ return { artifact, fetchedAt: now };
32
+ }
33
+ /**
34
+ * The page of a cross-origin collection. Its list is the held rows of `query.dataset`, which the
35
+ * route's query runs over at render time, so the artifact carries no items of its own.
36
+ */
37
+ export function collectionPage(path, now) {
38
+ const artifact = {
39
+ protocol: PROTOCOL_VERSION,
40
+ id: path,
41
+ scope: 'public',
42
+ strategy: 'data',
43
+ deps: [],
44
+ vector: 0,
45
+ body: { data: {} }
46
+ };
47
+ return { artifact, fetchedAt: now };
48
+ }
package/dist/sw/idb.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { ReplicaStorage } from './storage.js';
2
+ export declare function wrap<T>(request: IDBRequest<T>): Promise<T>;
3
+ export declare function done(tx: IDBTransaction): Promise<void>;
2
4
  /**
3
5
  * The replica in IndexedDB: artifacts by id, one meta record and an auto-numbered beacon queue.
4
6
  * `factory` is the `indexedDB` global unless a test passes `fake-indexeddb`.
package/dist/sw/idb.js CHANGED
@@ -8,13 +8,13 @@ const DATASET_ROWS = 'datasetRows';
8
8
  const DATASET_META = 'datasetMeta';
9
9
  const META_KEY = 'replica';
10
10
  const FLUSH_KEY = 'flush';
11
- function wrap(request) {
11
+ export function wrap(request) {
12
12
  return new Promise((resolve, reject) => {
13
13
  request.onsuccess = () => resolve(request.result);
14
14
  request.onerror = () => reject(request.error);
15
15
  });
16
16
  }
17
- function done(tx) {
17
+ export function done(tx) {
18
18
  return new Promise((resolve, reject) => {
19
19
  tx.oncomplete = () => resolve();
20
20
  tx.onerror = () => reject(tx.error);
@@ -1,2 +1,4 @@
1
+ export { QUOTA_MARGIN_BYTES, createPackStore } from './pack/store.js';
2
+ export type { FitOutcome, InstallOptions, InstallOutcome, PackCounters, PackHead, PackIndex, PackStore, PackStoreOptions, Predicted, RecordCounts, RingOutcome, StorageEstimate } from './pack/store.js';
1
3
  export type { Renderer, Renderers } from './render.js';
2
4
  export { MANIFEST_FILE, manifestConfig, serve } from './serve.js';
package/dist/sw/index.js CHANGED
@@ -1 +1,2 @@
1
+ export { QUOTA_MARGIN_BYTES, createPackStore } from './pack/store.js';
1
2
  export { MANIFEST_FILE, manifestConfig, serve } from './serve.js';
@@ -0,0 +1,128 @@
1
+ import { type BundleDelta, type BundleRows } from '../../protocol/bundle.js';
2
+ import type { DatasetRow } from '../../protocol/dataset.js';
3
+ import type { Ring } from '../../protocol/ring.js';
4
+ import type { SerializedRoute } from '../../protocol/route.js';
5
+ import type { CompiledTemplate } from '../../protocol/template/compile.js';
6
+ type Bytes = Uint8Array<ArrayBuffer>;
7
+ /**
8
+ * the active pack: version, set digest, generation (the key space of its records) and layout. A
9
+ * partial head is a ring: its rows sit in the overlay and it has no blocks, so a key it does not
10
+ * hold is a miss.
11
+ */
12
+ export type PackHead = StoredHead & {
13
+ /** rows a write predicted and no verified delta has confirmed or dropped yet */
14
+ unconfirmed: number;
15
+ };
16
+ type StoredHead = {
17
+ version: number;
18
+ digest: string;
19
+ generation: number;
20
+ blockRows: number;
21
+ codec: 'gzip';
22
+ tables: string[];
23
+ partial?: true;
24
+ };
25
+ /** rows a write's answer predicts: a row to put, or a key to delete, per table */
26
+ export type Predicted = {
27
+ puts: Array<[table: string, key: string, row: DatasetRow]>;
28
+ deletes: Array<[table: string, key: string]>;
29
+ };
30
+ /** one table of one generation: its row count and, per block, first key, last key and hash */
31
+ export type PackIndex = {
32
+ rows: number;
33
+ first: string[];
34
+ last: string[];
35
+ hashes: string[];
36
+ };
37
+ export type PackCounters = {
38
+ blockReads: number;
39
+ blockInflates: number;
40
+ overlayReads: number;
41
+ };
42
+ export type RecordCounts = {
43
+ blocks: number;
44
+ index: number;
45
+ overlay: number;
46
+ head: number;
47
+ };
48
+ export type FitOutcome = {
49
+ checked: false;
50
+ fits: true;
51
+ } | {
52
+ checked: true;
53
+ fits: true;
54
+ } | {
55
+ checked: true;
56
+ fits: false;
57
+ bytes: number;
58
+ usage: number;
59
+ quota: number;
60
+ };
61
+ export type InstallOutcome = {
62
+ installed: true;
63
+ version: number;
64
+ tables: number;
65
+ rows: number;
66
+ blocks: number;
67
+ } | {
68
+ installed: false;
69
+ fit: Extract<FitOutcome, {
70
+ fits: false;
71
+ }>;
72
+ };
73
+ /** a ring is refused when it is older than the held pack, or names the complete pack already held */
74
+ export type RingOutcome = {
75
+ installed: true;
76
+ version: number;
77
+ rows: number;
78
+ complete: boolean;
79
+ } | {
80
+ installed: false;
81
+ reason: 'older' | 'held';
82
+ };
83
+ export type InstallOptions = {
84
+ /** the pack's size in bytes; when given, the install is refused if it would not fit */
85
+ bytes?: number;
86
+ };
87
+ export type StorageEstimate = {
88
+ usage?: number;
89
+ quota?: number;
90
+ };
91
+ export type PackStoreOptions = {
92
+ /** the database name; `spool-bundle` unless a test names its own */
93
+ name?: string;
94
+ /** the storage estimate; defaults to `navigator.storage.estimate` where the browser has it */
95
+ estimate?: () => Promise<StorageEstimate | undefined>;
96
+ };
97
+ export type PackStore = {
98
+ readonly counters: PackCounters;
99
+ head(): Promise<PackHead | undefined>;
100
+ recordCounts(): Promise<RecordCounts>;
101
+ installPack(source: AsyncIterable<Bytes>, options?: InstallOptions): Promise<InstallOutcome>;
102
+ /** holds a ring as a partial or a complete head; its routes and templates are replaced */
103
+ installRing(ring: Ring): Promise<RingOutcome>;
104
+ estimateBeforeInstall(bytes: number): Promise<FitOutcome>;
105
+ applyDelta(delta: BundleDelta): Promise<void>;
106
+ /** lays predicted rows over the pack without moving its version; a no-op when no pack is held */
107
+ applyPredicted(predicted: Predicted): Promise<void>;
108
+ /** moves to `to` with the predicted rows as the change; throws and keeps them when `digest` is not theirs */
109
+ confirmPredicted(to: number, digest: string): Promise<void>;
110
+ /** removes every predicted row and keeps the version */
111
+ dropPredicted(): Promise<void>;
112
+ getRow(table: string, key: string): Promise<DatasetRow | undefined>;
113
+ scanTable(table: string): Promise<BundleRows>;
114
+ compact(): Promise<boolean>;
115
+ /** replaces the held routes with `routes`, kept in the order given */
116
+ /** `templates` holds the compiled template of each route that has one, keyed by pattern */
117
+ putRoutes(routes: SerializedRoute[], templates?: Record<string, CompiledTemplate>): Promise<void>;
118
+ getRoutes(): Promise<SerializedRoute[]>;
119
+ getTemplates(): Promise<Record<string, CompiledTemplate>>;
120
+ };
121
+ /** bytes kept free past an install's own size; a default, not measured */
122
+ export declare const QUOTA_MARGIN_BYTES: number;
123
+ /**
124
+ * A device's site pack in IndexedDB `spool-bundle`: compressed blocks of sorted rows, an overlay of
125
+ * changed rows, and one head record that names the active pack. A read inflates at most one block.
126
+ */
127
+ export declare function createPackStore(factory?: IDBFactory, options?: PackStoreOptions): PackStore;
128
+ export {};