@substrat-run/adapter-cloudflare 0.229.0 → 0.230.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 (82) hide show
  1. package/dist/broker-lake.d.ts +26 -2
  2. package/dist/broker-lake.d.ts.map +1 -1
  3. package/dist/broker-lake.js +56 -3
  4. package/dist/broker-lake.js.map +1 -1
  5. package/dist/control-plane-do.d.ts +41 -11
  6. package/dist/control-plane-do.d.ts.map +1 -1
  7. package/dist/control-plane-do.js +100 -48
  8. package/dist/control-plane-do.js.map +1 -1
  9. package/dist/delivery-broker-do.d.ts +13 -1
  10. package/dist/delivery-broker-do.d.ts.map +1 -1
  11. package/dist/delivery-broker-do.js +43 -3
  12. package/dist/delivery-broker-do.js.map +1 -1
  13. package/dist/directory-cutover.d.ts +93 -1
  14. package/dist/directory-cutover.d.ts.map +1 -1
  15. package/dist/directory-cutover.js +85 -2
  16. package/dist/directory-cutover.js.map +1 -1
  17. package/dist/directory-objects.d.ts +12 -0
  18. package/dist/directory-objects.d.ts.map +1 -1
  19. package/dist/directory-objects.js +8 -1
  20. package/dist/directory-objects.js.map +1 -1
  21. package/dist/directory-placement.d.ts.map +1 -1
  22. package/dist/directory-placement.js +1 -0
  23. package/dist/directory-placement.js.map +1 -1
  24. package/dist/directory-tenant-identities.d.ts +30 -0
  25. package/dist/directory-tenant-identities.d.ts.map +1 -0
  26. package/dist/directory-tenant-identities.js +64 -0
  27. package/dist/directory-tenant-identities.js.map +1 -0
  28. package/dist/directory-tenant-tuples.d.ts +30 -3
  29. package/dist/directory-tenant-tuples.d.ts.map +1 -1
  30. package/dist/directory-tenant-tuples.js +27 -0
  31. package/dist/directory-tenant-tuples.js.map +1 -1
  32. package/dist/host.d.ts +27 -1
  33. package/dist/host.d.ts.map +1 -1
  34. package/dist/host.js +81 -9
  35. package/dist/host.js.map +1 -1
  36. package/dist/index.d.ts +6 -2
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +8 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/peer-call-target.d.ts +16 -2
  41. package/dist/peer-call-target.d.ts.map +1 -1
  42. package/dist/peer-call-target.js +36 -6
  43. package/dist/peer-call-target.js.map +1 -1
  44. package/dist/route-read-model-publisher.d.ts.map +1 -1
  45. package/dist/route-read-model-publisher.js +4 -0
  46. package/dist/route-read-model-publisher.js.map +1 -1
  47. package/dist/route-resolver.d.ts +19 -2
  48. package/dist/route-resolver.d.ts.map +1 -1
  49. package/dist/route-resolver.js +25 -5
  50. package/dist/route-resolver.js.map +1 -1
  51. package/dist/scope-do.d.ts +19 -0
  52. package/dist/scope-do.d.ts.map +1 -1
  53. package/dist/scope-do.js +294 -8
  54. package/dist/scope-do.js.map +1 -1
  55. package/dist/scope-facets.d.ts +121 -0
  56. package/dist/scope-facets.d.ts.map +1 -0
  57. package/dist/scope-facets.js +98 -0
  58. package/dist/scope-facets.js.map +1 -0
  59. package/dist/scope-supervisor-do.d.ts +93 -0
  60. package/dist/scope-supervisor-do.d.ts.map +1 -0
  61. package/dist/scope-supervisor-do.js +504 -0
  62. package/dist/scope-supervisor-do.js.map +1 -0
  63. package/dist/scope-work.d.ts +1 -1
  64. package/dist/scope-work.js +1 -1
  65. package/dist/scope-work.js.map +1 -1
  66. package/dist/supplied-pass-box.d.ts +77 -0
  67. package/dist/supplied-pass-box.d.ts.map +1 -0
  68. package/dist/supplied-pass-box.js +265 -0
  69. package/dist/supplied-pass-box.js.map +1 -0
  70. package/dist/tenant-due-index-do.d.ts +76 -0
  71. package/dist/tenant-due-index-do.d.ts.map +1 -0
  72. package/dist/tenant-due-index-do.js +90 -0
  73. package/dist/tenant-due-index-do.js.map +1 -0
  74. package/dist/tenant-due-nudge.d.ts +66 -0
  75. package/dist/tenant-due-nudge.d.ts.map +1 -0
  76. package/dist/tenant-due-nudge.js +77 -0
  77. package/dist/tenant-due-nudge.js.map +1 -0
  78. package/dist/tenant-due-work-do.d.ts +26 -0
  79. package/dist/tenant-due-work-do.d.ts.map +1 -1
  80. package/dist/tenant-due-work-do.js +69 -5
  81. package/dist/tenant-due-work-do.js.map +1 -1
  82. package/package.json +12 -12
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Track B (broker RFC §6, #3466): what the scope supervisor and the scope class in facet mode
3
+ * share, and the two fences between a scope as it runs today and a scope as a facet.
4
+ *
5
+ * Imports nothing from `scope-do.ts`, so the scope class can call the rollback fence without a
6
+ * cycle, and the supervisor can read the same names.
7
+ *
8
+ * **Nothing here moves data.** A facet's SQLite is separate from the storage a scope object holds
9
+ * today (D-70), so an existing scope's rows stay where they are. The fences make that safe in both
10
+ * directions, and the move itself is parked (RFC §6.6, `docs/architecture/scope-facets.md`):
11
+ *
12
+ * - **Forward fence.** A supervisor woken on an object whose own storage holds a scope's data (it ran
13
+ * as a scope before facets) refuses every call. Facet mode admits new scopes only. Serving such an
14
+ * object from an empty facet would answer as if the scope had no rows.
15
+ * - **Rollback fence.** A supervisor that serves an object writes `SUPERVISOR_MARKER_TABLE` into the
16
+ * object's own storage before its first call into the facet. The scope class running as an object
17
+ * (today's default) refuses to construct on storage carrying that marker. Rolling a script back to
18
+ * the default class would otherwise answer from the object's empty storage while the scope's rows
19
+ * sit in the facet, and a provision there would split one scope into two.
20
+ */
21
+ /**
22
+ * The table a supervisor keeps in its object's own storage, and the marker the rollback fence reads.
23
+ * Never in a facet's storage, never in the spine a module can see: the supervisor's database is not
24
+ * the scope's.
25
+ */
26
+ export declare const SUPERVISOR_MARKER_TABLE = "_substrat_supervisor";
27
+ /**
28
+ * The tables whose rows mean a scope object holds data — the scope class's own `holdsData` set,
29
+ * which `scope-do.ts` reads from here. A table that exists but is empty means an object woke and
30
+ * made its spine, and nothing more: no row to lose.
31
+ */
32
+ export declare const HOLDS_DATA_TABLES: readonly ['_substrat_migrations', '_substrat_tuples', '_substrat_outbox', '_substrat_schedule_state'];
33
+ /** What the forward fence answers with. A class, so a caller can tell it from an operation's own error. */
34
+ export declare class ScopeFacetFenced extends Error {
35
+ readonly name = "ScopeFacetFenced";
36
+ }
37
+ /** What the rollback fence throws from the scope class's constructor. */
38
+ export declare class ScopeSupervisedFenced extends Error {
39
+ readonly name = "ScopeSupervisedFenced";
40
+ }
41
+ /** The narrow storage read both fences need: synchronous SQL over the object's own database. */
42
+ interface FenceStorage {
43
+ readonly sql: {
44
+ exec(query: string, ...params: unknown[]): {
45
+ toArray(): unknown[];
46
+ };
47
+ };
48
+ }
49
+ /** Does this object's own storage hold a scope's rows (the forward fence's question)? */
50
+ export declare function holdsScopeData(storage: FenceStorage): boolean;
51
+ /** Has a supervisor served this object (the rollback fence's question)? */
52
+ export declare function servedBySupervisor(storage: FenceStorage): boolean;
53
+ /**
54
+ * The rollback fence, run by the scope class as an object before it creates any table of its own.
55
+ * Read-only: one `sqlite_master` lookup per wake, and on an object no supervisor ever served it
56
+ * finds nothing and changes nothing.
57
+ */
58
+ export declare function assertNotSupervised(storage: FenceStorage): void;
59
+ /**
60
+ * The header a live subscriber names the last event it heard with, so a socket opened again after
61
+ * a reset, a deploy or a dropped connection resumes from there rather than from now. Read by the
62
+ * supervisor only; the scope as an object keeps its own rule (the poll is the floor).
63
+ */
64
+ export declare const LIVE_RESUME_HEADER = "x-substrat-live-since";
65
+ /**
66
+ * What the supervisor tells the facet about each socket it holds: the socket's tag, the
67
+ * subscription the facet admitted, and the last event this socket's walk has passed.
68
+ */
69
+ export interface SupervisedLiveSocket {
70
+ readonly sid: string;
71
+ readonly attachment: unknown;
72
+ readonly cursor: string;
73
+ }
74
+ /** The facet's answer to a catch-up pass: each socket's new cursor, and whether rows remain. */
75
+ export interface LiveCatchUp {
76
+ readonly cursors: Record<string, string>;
77
+ readonly behind: boolean;
78
+ }
79
+ /** A subscription request as the supervisor hands it to the facet: plain values, no `Request` object. */
80
+ export interface LiveAdmitRequest {
81
+ readonly url: string;
82
+ readonly headers: [string, string][];
83
+ }
84
+ /** The facet's answer to an admission: a refusal, or the subscription to hold and where it starts. */
85
+ export type LiveAdmission = {
86
+ readonly admitted: false;
87
+ /** The refusal, as plain values: rebuilt into a `Response` by the supervisor. */
88
+ readonly status: number;
89
+ readonly headers: [string, string][];
90
+ readonly body: string;
91
+ } | {
92
+ readonly admitted: true;
93
+ readonly subscription: Record<string, unknown>;
94
+ readonly cursor: string;
95
+ };
96
+ /** What one forwarded call returns besides its value: a wake the facet asked for, and its tenant. */
97
+ export interface SupervisedReply<T = unknown> {
98
+ readonly value: T;
99
+ /** The earliest instant (epoch ms) the facet asked to be woken at during the call, or null. */
100
+ readonly wakeAt: number | null;
101
+ /** The tenant the facet's scope was provisioned for, once it has been. */
102
+ readonly tenant: string | null;
103
+ }
104
+ /** The two calls the facet makes back to the supervisor while it fans out. */
105
+ export interface LiveSocketsHandle {
106
+ liveSend(sid: string, frame: string): void;
107
+ liveClose(sid: string, code: number, reason: string): void;
108
+ }
109
+ /**
110
+ * The scope class's methods a supervisor does not forward as RPC: the ones it answers itself
111
+ * (`fetch`, `alarm`, the socket handlers) and the facet-only entry points it calls by name.
112
+ */
113
+ export declare const SUPERVISOR_OWNED_METHODS: ReadonlySet<string>;
114
+ /**
115
+ * The scope class's RPC surface a supervisor forwards: every method on its prototype but the ones
116
+ * the supervisor answers itself. Read from the platform's own class, never from a bundle, so an app
117
+ * cannot widen what its supervisor forwards.
118
+ */
119
+ export declare function scopeRpcMethods(prototype: object): string[];
120
+ export {};
121
+ //# sourceMappingURL=scope-facets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-facets.d.ts","sourceRoot":"","sources":["../src/scope-facets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,YAAI,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,0BAA0B,CAAU,CAAC;AAEvI,2GAA2G;AAC3G,qBAAa,gBAAiB,SAA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;IACjF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,GACD;IAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzG,qGAAqG;AACrG,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,+FAA+F;IAC/F,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5D;AAED;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,MAAM,CAUvD,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAM3D"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Track B (broker RFC §6, #3466): what the scope supervisor and the scope class in facet mode
3
+ * share, and the two fences between a scope as it runs today and a scope as a facet.
4
+ *
5
+ * Imports nothing from `scope-do.ts`, so the scope class can call the rollback fence without a
6
+ * cycle, and the supervisor can read the same names.
7
+ *
8
+ * **Nothing here moves data.** A facet's SQLite is separate from the storage a scope object holds
9
+ * today (D-70), so an existing scope's rows stay where they are. The fences make that safe in both
10
+ * directions, and the move itself is parked (RFC §6.6, `docs/architecture/scope-facets.md`):
11
+ *
12
+ * - **Forward fence.** A supervisor woken on an object whose own storage holds a scope's data (it ran
13
+ * as a scope before facets) refuses every call. Facet mode admits new scopes only. Serving such an
14
+ * object from an empty facet would answer as if the scope had no rows.
15
+ * - **Rollback fence.** A supervisor that serves an object writes `SUPERVISOR_MARKER_TABLE` into the
16
+ * object's own storage before its first call into the facet. The scope class running as an object
17
+ * (today's default) refuses to construct on storage carrying that marker. Rolling a script back to
18
+ * the default class would otherwise answer from the object's empty storage while the scope's rows
19
+ * sit in the facet, and a provision there would split one scope into two.
20
+ */
21
+ /**
22
+ * The table a supervisor keeps in its object's own storage, and the marker the rollback fence reads.
23
+ * Never in a facet's storage, never in the spine a module can see: the supervisor's database is not
24
+ * the scope's.
25
+ */
26
+ export const SUPERVISOR_MARKER_TABLE = '_substrat_supervisor';
27
+ /**
28
+ * The tables whose rows mean a scope object holds data — the scope class's own `holdsData` set,
29
+ * which `scope-do.ts` reads from here. A table that exists but is empty means an object woke and
30
+ * made its spine, and nothing more: no row to lose.
31
+ */
32
+ export const HOLDS_DATA_TABLES = ['_substrat_migrations', '_substrat_tuples', '_substrat_outbox', '_substrat_schedule_state'];
33
+ /** What the forward fence answers with. A class, so a caller can tell it from an operation's own error. */
34
+ export class ScopeFacetFenced extends Error {
35
+ name = 'ScopeFacetFenced';
36
+ }
37
+ /** What the rollback fence throws from the scope class's constructor. */
38
+ export class ScopeSupervisedFenced extends Error {
39
+ name = 'ScopeSupervisedFenced';
40
+ }
41
+ function hasTable(storage, name) {
42
+ return storage.sql.exec(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`, name).toArray().length > 0;
43
+ }
44
+ /** Does this object's own storage hold a scope's rows (the forward fence's question)? */
45
+ export function holdsScopeData(storage) {
46
+ return HOLDS_DATA_TABLES.some((table) => hasTable(storage, table) && storage.sql.exec(`SELECT 1 FROM ${table} LIMIT 1`).toArray().length > 0);
47
+ }
48
+ /** Has a supervisor served this object (the rollback fence's question)? */
49
+ export function servedBySupervisor(storage) {
50
+ return hasTable(storage, SUPERVISOR_MARKER_TABLE);
51
+ }
52
+ /**
53
+ * The rollback fence, run by the scope class as an object before it creates any table of its own.
54
+ * Read-only: one `sqlite_master` lookup per wake, and on an object no supervisor ever served it
55
+ * finds nothing and changes nothing.
56
+ */
57
+ export function assertNotSupervised(storage) {
58
+ if (servedBySupervisor(storage)) {
59
+ throw new ScopeSupervisedFenced('this scope runs as a facet: its rows are in the facet, not in this object. The scope class ' +
60
+ 'will not serve it as an object, which would answer from empty storage. Serve it through ' +
61
+ 'the scope supervisor again; moving a scope out of its facet is not built');
62
+ }
63
+ }
64
+ /**
65
+ * The header a live subscriber names the last event it heard with, so a socket opened again after
66
+ * a reset, a deploy or a dropped connection resumes from there rather than from now. Read by the
67
+ * supervisor only; the scope as an object keeps its own rule (the poll is the floor).
68
+ */
69
+ export const LIVE_RESUME_HEADER = 'x-substrat-live-since';
70
+ /**
71
+ * The scope class's methods a supervisor does not forward as RPC: the ones it answers itself
72
+ * (`fetch`, `alarm`, the socket handlers) and the facet-only entry points it calls by name.
73
+ */
74
+ export const SUPERVISOR_OWNED_METHODS = new Set([
75
+ 'constructor',
76
+ 'fetch',
77
+ 'alarm',
78
+ 'webSocketMessage',
79
+ 'webSocketClose',
80
+ 'webSocketError',
81
+ 'supervisedCall',
82
+ 'liveAdmit',
83
+ 'liveCatchUp',
84
+ ]);
85
+ /**
86
+ * The scope class's RPC surface a supervisor forwards: every method on its prototype but the ones
87
+ * the supervisor answers itself. Read from the platform's own class, never from a bundle, so an app
88
+ * cannot widen what its supervisor forwards.
89
+ */
90
+ export function scopeRpcMethods(prototype) {
91
+ return Object.getOwnPropertyNames(prototype).filter((name) => {
92
+ if (SUPERVISOR_OWNED_METHODS.has(name))
93
+ return false;
94
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
95
+ return typeof descriptor?.value === 'function';
96
+ });
97
+ }
98
+ //# sourceMappingURL=scope-facets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-facets.js","sourceRoot":"","sources":["../src/scope-facets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,0BAA0B,CAAU,CAAC;AAEvI,2GAA2G;AAC3G,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvB,IAAI,GAAG,kBAAkB,CAAC;CAC7C;AAED,yEAAyE;AACzE,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC5B,IAAI,GAAG,uBAAuB,CAAC;CAClD;AAOD,SAAS,QAAQ,CAAC,OAAqB,EAAE,IAAY;IACnD,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,+DAA+D,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AACtH,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAAC,OAAqB;IAClD,OAAO,iBAAiB,CAAC,IAAI,CAC3B,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,KAAK,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,CAC/G,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,OAAqB;IACtD,OAAO,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAqB;IACvD,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,qBAAqB,CAC7B,6FAA6F;YAC3F,0FAA0F;YAC1F,0EAA0E,CAC7E,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAkD1D;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAAC;IACnE,aAAa;IACb,OAAO;IACP,OAAO;IACP,kBAAkB;IAClB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,WAAW;IACX,aAAa;CACd,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3D,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACrD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACpE,OAAO,OAAO,UAAU,EAAE,KAAK,KAAK,UAAU,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Track B (broker RFC §6, #3466): the scope supervisor — the one class a script executes for its
3
+ * scopes when scopes run as facets. Platform code only. Switched: nothing on `main` exports it as a
4
+ * deployed script's scope class, so every scope still runs `defineScopeDO` as its own object.
5
+ *
6
+ * One object per scope, as today, in two layers (`docs/architecture/scope-facets.md`):
7
+ *
8
+ * - **This supervisor** receives every call, holds the alarm and the live-read sockets, and keeps a
9
+ * table of its own, `_substrat_supervisor` (`SUPERVISOR_MARKER_TABLE`), in the object's storage.
10
+ * Its SQL names that table literally, so `lint:attachment-writers` can see no write here reaches
11
+ * attachment rows.
12
+ * - **The facet** holds the kernel, the app's modules and the scope's data. Its code arrives inert
13
+ * (`ScopeSupervisorOptions.code`, the `defineScopeFacet` class bundled as text), is loaded through
14
+ * the Worker Loader with `globalOutbound: null` and an empty env, and runs as the facet `scope`
15
+ * with a SQLite database of its own the supervisor never reads.
16
+ *
17
+ * **The isolate id** is `(release, tenant, app)` (RFC §6.3): two tenants never share one. A scope
18
+ * is not provisioned for a tenant until its first provision has run in the facet, so until the
19
+ * facet reports its tenant the id names this object instead (`unbound-<object id>`), which shares
20
+ * an isolate with nobody. The first idle moment after the tenant is known, the facet is restarted
21
+ * under the tenant's id; its storage stays, as the spikes showed it does across a restart.
22
+ *
23
+ * **The alarm** (`spikes/scope-facet-wakeups`): a facet cannot set one, and the supervisor's lives
24
+ * in another database than the facet's rows, so no single commit holds both. What holds instead:
25
+ * before ANY call into the facet, the supervisor arms its alarm no later than `prearmMs` from now
26
+ * and waits for `storage.sync()`, so a row the facet commits can never be left without a wake,
27
+ * whatever resets after it. After the call it moves the alarm to what the facet asked for, but only
28
+ * once no other call is in flight, since each in-flight call's commit is protected by that same
29
+ * pre-arm. A call that throws leaves a wake `prearmMs` out. The alarm handler arms again first,
30
+ * then forwards the alarm, so a drain that fails is retried by this alarm, not by the runtime's cap.
31
+ *
32
+ * **The sockets** (`spikes/scope-facet-wakeups` §3): accepted here, hibernatable, each carrying its
33
+ * subscription and a cursor — the last outbox event its walk has passed. After every call and on
34
+ * every alarm the facet decides what each socket is owed since its cursor and the supervisor sends
35
+ * it. A socket survives a facet restart (a rollout), and a revived supervisor rebuilds its roster
36
+ * from `getWebSockets()`. A reset closes every socket (1006); the client opens a new one naming the
37
+ * last event it heard (`LIVE_RESUME_HEADER`), and the walk resumes from there. A committed change
38
+ * is never skipped for a socket; it may be pushed twice.
39
+ */
40
+ import { DurableObject } from 'cloudflare:workers';
41
+ /** What the inert scope bundle is: modules as text, and the export `defineScopeFacet` produced. */
42
+ export interface ScopeFacetCode {
43
+ /** The module the bundle's facet class is exported from. */
44
+ readonly mainModule: string;
45
+ /** Every module of the bundle, as source text. */
46
+ readonly modules: Readonly<Record<string, string>>;
47
+ /** The export naming the `defineScopeFacet` class. Default `ScopeFacet`. */
48
+ readonly className?: string;
49
+ readonly compatibilityDate: string;
50
+ readonly compatibilityFlags?: readonly string[];
51
+ }
52
+ /** The bindings a supervisor reads. The facet gets none of them. */
53
+ export interface ScopeSupervisorEnv {
54
+ /** The Worker Loader the facet's code is loaded through (`worker_loaders` in the upload). */
55
+ SCOPE_LOADER: WorkerLoader;
56
+ /** The release this script serves (#1242): the first part of the isolate id. */
57
+ SUBSTRAT_VERSION_ID?: string;
58
+ /** The app's slug: the last part of the isolate id. */
59
+ SUBSTRAT_VERTICAL?: string;
60
+ }
61
+ export interface ScopeSupervisorOptions {
62
+ /** The facet's code, or how to read it from the env (a Text module, a var). */
63
+ readonly code: ScopeFacetCode | ((env: ScopeSupervisorEnv) => ScopeFacetCode);
64
+ /** The app's slug when the env names none. */
65
+ readonly app: string;
66
+ /**
67
+ * How far ahead the alarm is armed before each call into the facet: the longest a committed row
68
+ * can wait for its wake when the object resets between the commit and the supervisor reading the
69
+ * facet's own wake back. Default `DEFAULT_PREARM_MS`.
70
+ */
71
+ readonly prearmMs?: number;
72
+ /** Limits the Worker Loader applies to the facet's isolate (`cpuMs` bounds one call's CPU). */
73
+ readonly limits?: {
74
+ readonly cpuMs?: number;
75
+ readonly subRequests?: number;
76
+ };
77
+ /**
78
+ * Methods beyond the scope class's own surface to forward: for a bundle whose facet class adds
79
+ * one (a test fixture's probe). Never read from the bundle.
80
+ */
81
+ readonly forward?: readonly string[];
82
+ }
83
+ /** See `ScopeSupervisorOptions.prearmMs`. */
84
+ export declare const DEFAULT_PREARM_MS = 30000;
85
+ /**
86
+ * The module the facet is loaded through: the bundle's class, constructed with the release and the
87
+ * app as constants compiled into code. The Worker Loader's env stays `{}`, so no binding and no
88
+ * secret reaches the facet, and a per-scope value never rides the loader's cache by id (the env
89
+ * trap in `spikes/scope-no-network`). Exported for the test that reads it.
90
+ */
91
+ export declare function facetEntrySource(mainModule: string, className: string, constants: Record<string, string>): string;
92
+ export declare function defineScopeSupervisorDO(options: ScopeSupervisorOptions): new (ctx: DurableObjectState, env: ScopeSupervisorEnv) => DurableObject<ScopeSupervisorEnv>;
93
+ //# sourceMappingURL=scope-supervisor-do.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-supervisor-do.d.ts","sourceRoot":"","sources":["../src/scope-supervisor-do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,aAAa,EAAa,MAAM,oBAAoB,CAAC;AAwB9D,mGAAmG;AACnG,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjD;AAED,oEAAoE;AACpE,MAAM,WAAW,kBAAkB;IACjC,6FAA6F;IAC7F,YAAY,EAAE,YAAY,CAAC;IAC3B,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,CAAC,CAAC,GAAG,EAAE,kBAAkB,KAAK,cAAc,CAAC,CAAC;IAC9E,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,QAA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