@drupflare/spool 0.3.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.
- package/README.md +279 -1607
- package/dist/angular/index.d.ts +13 -0
- package/dist/angular/index.js +25 -0
- package/dist/angular/pages.d.ts +28 -0
- package/dist/angular/pages.js +85 -0
- package/dist/cdn/client.js +1 -1
- package/dist/cdn/location.d.ts +6 -0
- package/dist/cdn/location.js +8 -0
- package/dist/cdn/manifest.json +7 -7
- package/dist/cdn/spool-sw.js +1 -1
- package/dist/client/bootstrap.d.ts +57 -0
- package/dist/client/bootstrap.js +307 -0
- package/dist/client/contact.d.ts +24 -0
- package/dist/client/contact.js +66 -0
- package/dist/client/declared.d.ts +23 -0
- package/dist/client/declared.js +68 -0
- package/dist/client/entry.js +123 -2
- package/dist/client/gate.d.ts +1 -0
- package/dist/client/gate.js +148 -0
- package/dist/client/index.d.ts +25 -0
- package/dist/client/index.js +1 -0
- package/dist/client/live.d.ts +66 -0
- package/dist/client/live.js +225 -0
- package/dist/client/navigate-entry.d.ts +1 -0
- package/dist/client/navigate-entry.js +4 -0
- package/dist/client/navigate.d.ts +54 -0
- package/dist/client/navigate.js +272 -0
- package/dist/client/persist.d.ts +2 -0
- package/dist/client/persist.js +9 -0
- package/dist/client/register.d.ts +34 -2
- package/dist/client/register.js +64 -7
- package/dist/express/index.d.ts +11 -0
- package/dist/express/index.js +209 -0
- package/dist/hono/index.d.ts +19 -0
- package/dist/hono/index.js +49 -0
- package/dist/next/index.d.ts +33 -0
- package/dist/next/index.js +41 -0
- package/dist/next/pages.d.ts +22 -0
- package/dist/next/pages.js +39 -0
- package/dist/node/listener.d.ts +3 -0
- package/dist/node/listener.js +57 -2
- package/dist/nuxt/index.d.ts +22 -0
- package/dist/nuxt/index.js +104 -0
- package/dist/nuxt/pages.d.ts +26 -0
- package/dist/nuxt/pages.js +48 -0
- package/dist/nuxt/runtime/index.d.ts +24 -0
- package/dist/nuxt/runtime/index.js +58 -0
- package/dist/plugins/coverage.d.ts +14 -0
- package/dist/plugins/coverage.js +27 -0
- package/dist/plugins/mode.d.ts +19 -0
- package/dist/plugins/mode.js +20 -0
- package/dist/plugins/path.d.ts +16 -0
- package/dist/plugins/path.js +139 -0
- package/dist/plugins/report.d.ts +22 -0
- package/dist/plugins/report.js +18 -0
- package/dist/plugins/routes.d.ts +38 -0
- package/dist/plugins/routes.js +52 -0
- package/dist/plugins/static.d.ts +42 -0
- package/dist/plugins/static.js +97 -0
- package/dist/protocol/bundle.d.ts +111 -0
- package/dist/protocol/bundle.js +428 -0
- package/dist/protocol/config.d.ts +80 -1
- package/dist/protocol/config.js +31 -1
- package/dist/protocol/dataset.d.ts +189 -0
- package/dist/protocol/dataset.js +212 -0
- package/dist/protocol/envelope.d.ts +34 -1
- package/dist/protocol/envelope.js +16 -1
- package/dist/protocol/errors.d.ts +1 -1
- package/dist/protocol/graph.d.ts +23 -4
- package/dist/protocol/graph.js +34 -3
- package/dist/protocol/index-rows.d.ts +22 -0
- package/dist/protocol/index-rows.js +53 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +5 -0
- package/dist/protocol/normalise.d.ts +4 -4
- package/dist/protocol/normalise.js +9 -5
- package/dist/protocol/plan.d.ts +100 -0
- package/dist/protocol/plan.js +661 -0
- package/dist/protocol/provision.d.ts +46 -0
- package/dist/protocol/provision.js +38 -0
- package/dist/protocol/query.d.ts +66 -5
- package/dist/protocol/query.js +103 -4
- package/dist/protocol/ring.d.ts +58 -0
- package/dist/protocol/ring.js +6 -0
- package/dist/protocol/route.d.ts +63 -13
- package/dist/protocol/route.js +126 -6
- package/dist/protocol/tag.d.ts +22 -2
- package/dist/protocol/tag.js +25 -4
- package/dist/protocol/view.d.ts +2 -0
- package/dist/protocol/view.js +8 -2
- package/dist/protocol/views.d.ts +6 -0
- package/dist/protocol/views.js +15 -0
- package/dist/protocol/write.d.ts +234 -0
- package/dist/protocol/write.js +343 -0
- package/dist/proxy/eligible.d.ts +22 -1
- package/dist/proxy/eligible.js +62 -15
- package/dist/proxy/proxy.js +28 -18
- package/dist/react-router/index.d.ts +20 -0
- package/dist/react-router/index.js +60 -0
- package/dist/react-router/pages.d.ts +34 -0
- package/dist/react-router/pages.js +83 -0
- package/dist/report/dataset.d.ts +48 -0
- package/dist/report/dataset.js +93 -0
- package/dist/report/demand.d.ts +49 -0
- package/dist/report/demand.js +60 -0
- package/dist/report/derive.d.ts +285 -0
- package/dist/report/derive.js +676 -1
- package/dist/report/economics.d.ts +66 -1
- package/dist/report/economics.js +208 -1
- package/dist/report/headline.d.ts +158 -0
- package/dist/report/headline.js +473 -0
- package/dist/report/index.d.ts +4 -0
- package/dist/report/index.js +4 -0
- package/dist/report/inputs.d.ts +176 -0
- package/dist/report/inputs.js +248 -0
- package/dist/report/institution.d.ts +188 -1
- package/dist/report/institution.js +146 -0
- package/dist/report/loops.d.ts +73 -0
- package/dist/report/loops.js +101 -0
- package/dist/report/measurement.d.ts +1 -1
- package/dist/report/measurement.js +7 -1
- package/dist/report/model.d.ts +2 -0
- package/dist/report/model.js +4 -0
- package/dist/report/thirdparty.d.ts +57 -0
- package/dist/report/thirdparty.js +111 -0
- package/dist/report/traffic.d.ts +8 -0
- package/dist/report/traffic.js +7 -0
- package/dist/report/trim.d.ts +56 -0
- package/dist/report/trim.js +83 -1
- package/dist/server/bundle.d.ts +55 -0
- package/dist/server/bundle.js +172 -0
- package/dist/server/dataset.d.ts +54 -0
- package/dist/server/dataset.js +355 -0
- package/dist/server/embedded.d.ts +7 -3
- package/dist/server/embedded.js +7 -3
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +6 -0
- package/dist/server/live-sockets.d.ts +54 -0
- package/dist/server/live-sockets.js +131 -0
- package/dist/server/live.d.ts +146 -0
- package/dist/server/live.js +228 -0
- package/dist/server/ring.d.ts +77 -0
- package/dist/server/ring.js +311 -0
- package/dist/server/spool.d.ts +158 -3
- package/dist/server/spool.js +578 -41
- package/dist/server/static.d.ts +42 -0
- package/dist/server/static.js +29 -0
- package/dist/server/stub.d.ts +43 -5
- package/dist/server/stub.js +126 -8
- package/dist/server/write.d.ts +49 -0
- package/dist/server/write.js +223 -0
- package/dist/stores/durable-object.d.ts +46 -0
- package/dist/stores/durable-object.js +114 -0
- package/dist/sw/analytics.d.ts +7 -1
- package/dist/sw/analytics.js +16 -2
- package/dist/sw/coverage.d.ts +6 -0
- package/dist/sw/coverage.js +34 -0
- package/dist/sw/dataset-sync.d.ts +76 -0
- package/dist/sw/dataset-sync.js +149 -0
- package/dist/sw/dataset.d.ts +91 -0
- package/dist/sw/dataset.js +318 -0
- package/dist/sw/family.d.ts +15 -0
- package/dist/sw/family.js +48 -0
- package/dist/sw/graph/index.d.ts +31 -1
- package/dist/sw/graph/index.js +57 -5
- package/dist/sw/graph/invalidate.d.ts +15 -3
- package/dist/sw/graph/invalidate.js +42 -4
- package/dist/sw/idb.d.ts +2 -0
- package/dist/sw/idb.js +80 -11
- package/dist/sw/index.d.ts +2 -0
- package/dist/sw/index.js +1 -0
- package/dist/sw/pack/store.d.ts +128 -0
- package/dist/sw/pack/store.js +737 -0
- package/dist/sw/partition.d.ts +6 -1
- package/dist/sw/partition.js +21 -2
- package/dist/sw/policy.d.ts +2 -0
- package/dist/sw/policy.js +11 -0
- package/dist/sw/principal-dataset.d.ts +64 -0
- package/dist/sw/principal-dataset.js +254 -0
- package/dist/sw/probe.d.ts +16 -0
- package/dist/sw/probe.js +25 -0
- package/dist/sw/render.d.ts +7 -2
- package/dist/sw/render.js +19 -5
- package/dist/sw/replica.d.ts +12 -3
- package/dist/sw/replica.js +40 -5
- package/dist/sw/router.d.ts +3 -2
- package/dist/sw/router.js +15 -2
- package/dist/sw/runtime.d.ts +90 -2
- package/dist/sw/runtime.js +857 -61
- package/dist/sw/scheduler.d.ts +6 -1
- package/dist/sw/scheduler.js +22 -5
- package/dist/sw/seal.d.ts +13 -0
- package/dist/sw/seal.js +13 -4
- package/dist/sw/static.d.ts +18 -0
- package/dist/sw/static.js +84 -1
- package/dist/sw/storage.d.ts +51 -1
- package/dist/sw/storage.js +33 -1
- package/dist/sw/write.d.ts +147 -0
- package/dist/sw/write.js +625 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -2
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.js +66 -0
- package/dist/vue/index.d.ts +36 -0
- package/dist/vue/index.js +53 -0
- package/package.json +65 -4
package/dist/sw/router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CollectorConfig } from '../protocol/collector.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type SwConfig } from '../protocol/config.js';
|
|
3
3
|
import { type Params } from '../protocol/pattern.js';
|
|
4
4
|
import { type SerializedRoute } from '../protocol/route.js';
|
|
5
5
|
/** how the worker treats a request; a `static` hit keys its file by pathname plus query string */
|
|
@@ -34,7 +34,8 @@ export type Classified = {
|
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Sorts a request without touching it. A request to another origin is a held collector hit, a
|
|
37
|
-
* file of an allowed third-party origin, or ignored so
|
|
37
|
+
* GET a data family answers for that origin, a file of an allowed third-party origin, or ignored so
|
|
38
|
+
* the browser handles it natively. A
|
|
38
39
|
* same-origin one is a logout request, a queued beacon, a navigation on a declared route, a GET for
|
|
39
40
|
* a JSON route, a GET for a subresource (cache-first when immutable), a GET of a file a static
|
|
40
41
|
* route keeps, or a pass-through that the worker still observes for spool headers.
|
package/dist/sw/router.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { matchCollector } from '../protocol/collector.js';
|
|
2
|
+
import { LIVE_PATH } from '../protocol/config.js';
|
|
2
3
|
import { matchPattern } from '../protocol/pattern.js';
|
|
3
4
|
import { matchRoute } from '../protocol/route.js';
|
|
4
5
|
/** whether `url` falls under an origin the worker may cache files from */
|
|
@@ -7,7 +8,8 @@ function thirdPartyOrigin(config, url) {
|
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Sorts a request without touching it. A request to another origin is a held collector hit, a
|
|
10
|
-
* file of an allowed third-party origin, or ignored so
|
|
11
|
+
* GET a data family answers for that origin, a file of an allowed third-party origin, or ignored so
|
|
12
|
+
* the browser handles it natively. A
|
|
11
13
|
* same-origin one is a logout request, a queued beacon, a navigation on a declared route, a GET for
|
|
12
14
|
* a JSON route, a GET for a subresource (cache-first when immutable), a GET of a file a static
|
|
13
15
|
* route keeps, or a pass-through that the worker still observes for spool headers.
|
|
@@ -19,10 +21,20 @@ export function classify(config, request, origin) {
|
|
|
19
21
|
if (collector && (request.method === 'POST' || request.method === 'GET')) {
|
|
20
22
|
return { kind: 'collector', collector };
|
|
21
23
|
}
|
|
24
|
+
if (request.method === 'GET' && !request.headers.has('range')) {
|
|
25
|
+
const remote = config.routes.filter((route) => route.origin === url.origin);
|
|
26
|
+
const hit = matchRoute(remote, url.pathname);
|
|
27
|
+
if (hit?.route.strategy === 'data' && (url.search === '' || hit.route.query)) {
|
|
28
|
+
return { kind: 'data', route: hit.route, path: url.pathname };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
22
31
|
if (request.method === 'GET' && thirdPartyOrigin(config, url))
|
|
23
32
|
return { kind: 'thirdparty' };
|
|
24
33
|
return { kind: 'ignore' };
|
|
25
34
|
}
|
|
35
|
+
// the stream is the browser's own long-lived request; the worker never sits in it
|
|
36
|
+
if (url.pathname === LIVE_PATH)
|
|
37
|
+
return { kind: 'ignore' };
|
|
26
38
|
if (config.logout?.some((pattern) => matchPattern(pattern, url.pathname))) {
|
|
27
39
|
return { kind: 'logout' };
|
|
28
40
|
}
|
|
@@ -30,7 +42,8 @@ export function classify(config, request, origin) {
|
|
|
30
42
|
return { kind: 'beacon' };
|
|
31
43
|
if (request.method !== 'GET')
|
|
32
44
|
return { kind: 'pass' };
|
|
33
|
-
|
|
45
|
+
// a cross-origin family answers only its own origin's GETs, never the page's paths
|
|
46
|
+
const hit = matchRoute(config.routes.filter((route) => route.origin === undefined), url.pathname);
|
|
34
47
|
// an artifact is keyed by path alone, so only a route with a query schema answers a query
|
|
35
48
|
const queried = url.search !== '' && !hit?.route.query;
|
|
36
49
|
if (request.mode !== 'navigate') {
|
package/dist/sw/runtime.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { type AssetMode, type SwConfig } from '../protocol/config.js';
|
|
2
|
+
import { type LiveDelta } from '../protocol/envelope.js';
|
|
3
|
+
import { type WriteFlush, type WriteQueued, type WriteRefusal, type WriteResolved, type WriteStatus } from '../protocol/write.js';
|
|
4
|
+
import { type DatasetRefusal } from './dataset-sync.js';
|
|
5
|
+
import { type PackStore } from './pack/store.js';
|
|
2
6
|
import type { PartitionHost } from './partition.js';
|
|
3
7
|
import { Ledger, type LedgerEntry, type LedgerTotals } from './provision.js';
|
|
4
8
|
import { type Renderers } from './render.js';
|
|
5
9
|
import { Replica } from './replica.js';
|
|
6
10
|
import { type RoutableInstall } from './routing.js';
|
|
7
|
-
import type { ReplicaStorage } from './storage.js';
|
|
11
|
+
import type { DatasetMeta, ReplicaStorage } from './storage.js';
|
|
12
|
+
import { type WriteTimers } from './write.js';
|
|
8
13
|
/** the slice of a `Cache` the runtime uses */
|
|
9
14
|
export type CacheLike = {
|
|
10
15
|
match(request: Request): Promise<Response | undefined>;
|
|
@@ -22,6 +27,11 @@ export type CachesLike = {
|
|
|
22
27
|
export type RuntimeDeps = {
|
|
23
28
|
config: SwConfig;
|
|
24
29
|
storage: ReplicaStorage;
|
|
30
|
+
/**
|
|
31
|
+
* the pack store family routes read their rows from and a served pack is adopted into; default the
|
|
32
|
+
* browser's IndexedDB, and none where there is none, so family routes go to the network
|
|
33
|
+
*/
|
|
34
|
+
pack?: PackStore;
|
|
25
35
|
fetch(input: Request | string, init?: RequestInit): Promise<Response>;
|
|
26
36
|
caches: CachesLike;
|
|
27
37
|
/** the worker's own origin */
|
|
@@ -39,6 +49,15 @@ export type RuntimeDeps = {
|
|
|
39
49
|
partitions?: PartitionHost;
|
|
40
50
|
/** tells every page of the origin something, such as that a wipe happened */
|
|
41
51
|
broadcast?(message: unknown): void;
|
|
52
|
+
/** the storage the origin may use and has used; default `navigator.storage.estimate` */
|
|
53
|
+
estimate?(): Promise<{
|
|
54
|
+
quota?: number;
|
|
55
|
+
usage?: number;
|
|
56
|
+
}>;
|
|
57
|
+
/** the timers the declared-write deadlines run on; default the global timers */
|
|
58
|
+
timers?: WriteTimers;
|
|
59
|
+
/** how long the second lease renewal waits for a page to open the stream before it renews; default 3000 */
|
|
60
|
+
liveWaitMs?: number;
|
|
42
61
|
};
|
|
43
62
|
/** the worker's answer to a page's `spool:hello` */
|
|
44
63
|
export type Hello = {
|
|
@@ -46,6 +65,10 @@ export type Hello = {
|
|
|
46
65
|
protocol: number;
|
|
47
66
|
version: string;
|
|
48
67
|
compatible: boolean;
|
|
68
|
+
/** seconds the browser holds the worker script; absent from a worker built before the lease */
|
|
69
|
+
lease?: number;
|
|
70
|
+
/** epoch milliseconds of the worker's last server answer; absent until it has one */
|
|
71
|
+
contact?: number;
|
|
49
72
|
};
|
|
50
73
|
/** the worker's answer to `spool:status` */
|
|
51
74
|
export type Status = {
|
|
@@ -80,6 +103,39 @@ export type PartitionStatus = {
|
|
|
80
103
|
artifacts: string[];
|
|
81
104
|
records: string[];
|
|
82
105
|
projections: string[];
|
|
106
|
+
/** the principal datasets held for this partition; always empty while the flag is off */
|
|
107
|
+
datasets: DatasetMeta[];
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* the worker's answer to `spool:live-state`: the site's stream setting (null when it has none), the
|
|
111
|
+
* partition held and the lowest cursor a side holds, which a stream starts its catch-up from
|
|
112
|
+
*/
|
|
113
|
+
export type LiveState = {
|
|
114
|
+
type: 'spool:live-state';
|
|
115
|
+
live: NonNullable<SwConfig['live']> | null;
|
|
116
|
+
partition: string | null;
|
|
117
|
+
have: number | null;
|
|
118
|
+
};
|
|
119
|
+
/** what a page tells the worker it read from its stream; `partition` is the one the stream was opened for */
|
|
120
|
+
export type LiveMessage = {
|
|
121
|
+
partition: string | null;
|
|
122
|
+
} & ({
|
|
123
|
+
event: 'delta';
|
|
124
|
+
delta: LiveDelta;
|
|
125
|
+
} | {
|
|
126
|
+
event: 'lease';
|
|
127
|
+
leaseMs: number;
|
|
128
|
+
} | {
|
|
129
|
+
event: 'revoked';
|
|
130
|
+
}
|
|
131
|
+
/** a visible session began: the worker counts lease renewals from zero */
|
|
132
|
+
| {
|
|
133
|
+
event: 'session';
|
|
134
|
+
});
|
|
135
|
+
/** the worker's answer to `spool:live`: false when a delta did not follow the cursor the worker holds, so the page connects again */
|
|
136
|
+
export type LiveAck = {
|
|
137
|
+
type: 'spool:live';
|
|
138
|
+
ok: boolean;
|
|
83
139
|
};
|
|
84
140
|
/** the worker's answer to `spool:assets`: the mode asked for and whether Static Routing took effect */
|
|
85
141
|
export type AssetsStatus = {
|
|
@@ -93,8 +149,40 @@ export type HeldStatus = {
|
|
|
93
149
|
dropped: Record<string, number>;
|
|
94
150
|
third: string[];
|
|
95
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* the worker's answer to `spool:datasets`: what it holds, how each sync ended (counts by
|
|
154
|
+
* `<name>:<status>` or `<name>:refused:<reason>`), the datasets it will not retry this run, the
|
|
155
|
+
* datasets it found damaged and cleared, and whether a page was granted persistent storage
|
|
156
|
+
*/
|
|
157
|
+
export type DatasetStatus = {
|
|
158
|
+
type: 'spool:datasets';
|
|
159
|
+
datasets: DatasetMeta[];
|
|
160
|
+
outcomes: Record<string, number>;
|
|
161
|
+
refused: Record<string, DatasetRefusal>;
|
|
162
|
+
evicted: number;
|
|
163
|
+
persisted: boolean | null;
|
|
164
|
+
};
|
|
165
|
+
/** the worker's answer to `spool:write`, `spool:flush`, `spool:writes` and `spool:resolve` */
|
|
166
|
+
export type WriteReply = {
|
|
167
|
+
type: 'spool:write';
|
|
168
|
+
result: WriteQueued | WriteRefusal;
|
|
169
|
+
} | {
|
|
170
|
+
type: 'spool:flush';
|
|
171
|
+
result: ({
|
|
172
|
+
ok: true;
|
|
173
|
+
} & WriteFlush) | WriteRefusal;
|
|
174
|
+
} | {
|
|
175
|
+
type: 'spool:writes';
|
|
176
|
+
result: {
|
|
177
|
+
ok: true;
|
|
178
|
+
writes: WriteStatus[];
|
|
179
|
+
} | WriteRefusal;
|
|
180
|
+
} | {
|
|
181
|
+
type: 'spool:resolve';
|
|
182
|
+
result: WriteResolved | WriteRefusal;
|
|
183
|
+
};
|
|
96
184
|
/** every reply the worker gives a page */
|
|
97
|
-
export type Reply = Hello | Status | ViewId | GraphStatus | LedgerStatus | PartitionStatus | AssetsStatus | HeldStatus;
|
|
185
|
+
export type Reply = WriteReply | Hello | Status | ViewId | DatasetStatus | GraphStatus | LedgerStatus | PartitionStatus | LiveState | LiveAck | AssetsStatus | HeldStatus;
|
|
98
186
|
/** the object `serve` wires to service worker events */
|
|
99
187
|
export type Runtime = {
|
|
100
188
|
/** a response promise for a request the worker handles, `undefined` for one it leaves alone */
|