@pgxsinkit/contracts 0.3.0 → 0.5.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pgxsinkit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Static, type-driven read-path apply ladder (ADR-0009 decision 3).
3
3
  *
4
- * We own the registry's column types ahead of time and only ever target the latest PGlite, so the
4
+ * We own the registry's column types ahead of time and only ever target the latest pgwasm, so the
5
5
  * bulk-insert strategy for a synced table is chosen **once, statically** from its column types —
6
6
  * never by probing `information_schema` at runtime. This module is the pure, dependency-free core
7
7
  * (no registry, no Drizzle import) so it stays in the fast unit lane; {@link deriveSyncColumnTypes}
@@ -32,6 +32,18 @@ export interface SyncColumnType {
32
32
  */
33
33
  isEnum: boolean;
34
34
  }
35
+ /**
36
+ * The Postgres `udt_name` of a `json`/`jsonb` column — `json`/`jsonb` for a scalar one, `_json`/`_jsonb`
37
+ * for an array one — and `undefined` for every other column. The single classifier for "is this a JSON
38
+ * column, and is it an array of them?", shared by the read path's wire decode (which parses the cell of a
39
+ * SCALAR json column — see `envelopeToChange`) and the COPY serializer's `udtName` map, so the two cannot
40
+ * disagree about which columns carry JSON.
41
+ *
42
+ * The array forms are reported but deliberately NOT decoded: an array column arrives (and stays) in
43
+ * Postgres's own `array_out` text, which every apply tier hands straight back to `array_in` — the element
44
+ * JSON inside it is Postgres's business, not ours.
45
+ */
46
+ export declare function jsonUdtName(column: SyncColumnType): "json" | "jsonb" | "_json" | "_jsonb" | undefined;
35
47
  /**
36
48
  * Chooses the bulk-insert strategy for a table from its column types (ADR-0009 decision 3):
37
49
  * - every column COPY-safe → `copy`;
@@ -1 +1 @@
1
- {"version":3,"file":"apply-strategy.d.ts","sourceRoot":"","sources":["../src/apply-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wFAAwF;AACxF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvD,oGAAoG;AACpG,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;;;OAOG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AA2ED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,aAAa,CAwBvF"}
1
+ {"version":3,"file":"apply-strategy.d.ts","sourceRoot":"","sources":["../src/apply-strategy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,wFAAwF;AACxF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvD,oGAAoG;AACpG,MAAM,WAAW,cAAc;IAC7B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;;;OAOG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AA2ED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAMrG;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,GAAG,aAAa,CAwBvF"}
package/dist/config.d.ts CHANGED
@@ -43,7 +43,7 @@ export declare function isSubscriptionTiming(value: unknown): value is Subscript
43
43
  /**
44
44
  * Retention for a synced table (ADR-0021): **whether** its local copy is durable.
45
45
  *
46
- * - `persistent` (default) — the durable PGlite backend with a resumable subscription-state.
46
+ * - `persistent` (default) — the durable pgwasm backend with a resumable subscription-state.
47
47
  * - `ephemeral` — the table's whole per-table local cluster (read cache, overlay, journal, sequence,
48
48
  * views, reconcile trigger/function) is emitted as `TEMP`, so reads **and** writes leave no durable
49
49
  * trace. Consequence: no durable offline write queue — pair a must-not-lose write with a pessimistic
@@ -104,6 +104,49 @@ export type StorageDurability = "relaxed" | "strict";
104
104
  export declare const STORAGE_DURABILITIES: readonly ["relaxed", "strict"];
105
105
  /** Type guard: is `value` a {@link StorageDurability}? */
106
106
  export declare function isStorageDurability(value: unknown): value is StorageDurability;
107
+ /**
108
+ * The registry-declared store BUILD (ADR-0063): which pgwasm engine build owns the store's data directory.
109
+ * `c` (default) is the C PostgreSQL build; `pgrust` is the Rust one. Like the engine module, it is part of
110
+ * the store's identity — a datadir belongs to the build that wrote it, so a different build is a DIFFERENT
111
+ * store, minted fresh under a fresh path, never a rehome of an existing one.
112
+ *
113
+ * The declaration only NAMES the build. The build itself is always supplied as code at the minting site,
114
+ * never loaded from this string.
115
+ */
116
+ export type StorageBuild = "c" | "pgrust";
117
+ /** The {@link StorageBuild} values. Source of truth for {@link SyncStorageDeclaration} validation. */
118
+ export declare const STORAGE_BUILDS: readonly ["c", "pgrust"];
119
+ /** Type guard: is `value` a {@link StorageBuild}? */
120
+ export declare function isStorageBuild(value: unknown): value is StorageBuild;
121
+ /**
122
+ * The declared store ENGINE (ADR-0050 addendum 2026-09-08): the module URL of a store factory that answers
123
+ * for the store instead of the toolkit's own `createPgwasmClient`.
124
+ *
125
+ * `module` is an **absolute or origin-relative module URL** the engine home can `import()`. Its default
126
+ * export — or a named `createStore` — is the toolkit's own `createStore` seam (ADR-0036), unchanged:
127
+ * `(storePath: string, backendOverride?: "memory") => Promise<PgwasmClient>`. The module owns everything
128
+ * this declaration does not carry: its own assets (derivable from `import.meta.url`; there is no asset
129
+ * base and there will not be one), its own storage layout under the store path, and its own environment
130
+ * requirements (a threaded engine that needs a cross-origin-isolated page refuses to construct without
131
+ * one, loudly, from inside the module).
132
+ *
133
+ * Nothing in the toolkit knows, names or imports any particular engine — this field is the whole surface.
134
+ */
135
+ export interface StorageEngineDeclaration {
136
+ module: string;
137
+ }
138
+ /**
139
+ * Type guard: is `value` a usable {@link StorageEngineDeclaration.module} — a non-blank string that parses
140
+ * as an ABSOLUTE URL (`https://…/factory.js`) or an ORIGIN-RELATIVE one (`/store-engine/factory.js`)?
141
+ *
142
+ * A document-relative specifier (`./factory.js`, `factory.js`) is deliberately rejected: the declaration
143
+ * crosses a bridge into a worker scope whose base URL is the worker chunk's, not the tab's, so a relative
144
+ * URL would resolve differently on either side of the wire. Source of truth for
145
+ * {@link SyncStorageDeclaration} validation.
146
+ */
147
+ export declare function isStorageEngineModule(value: unknown): value is string;
148
+ /** Type guard: is `value` a well-formed {@link StorageEngineDeclaration}? */
149
+ export declare function isStorageEngineDeclaration(value: unknown): value is StorageEngineDeclaration;
107
150
  /**
108
151
  * The registry's storage contract (ADR-0049 decision 1, ADR-0047). Storage is PART OF THE DATA CONTRACT:
109
152
  * whether losing the last not-yet-flushed action is acceptable, and whether OPFS may be used at all, is
@@ -114,19 +157,33 @@ export declare function isStorageDurability(value: unknown): value is StorageDur
114
157
  * to contradict it; a capability fallback keeps the declared mode. A no-op on `memory` clones.
115
158
  * - {@link StorageBackend backend} defaults to `"opfs"` and scopes the BROWSER store only; Node/`file` and
116
159
  * `memory` clones are unaffected. `"idbfs"` opts the store out of the capability/election machinery.
160
+ * - {@link StorageBuild build} defaults to `"c"` and names the pgwasm build that owns the store's datadir
161
+ * (ADR-0063). It resolves and binds exactly as `durability` does.
162
+ * - {@link StorageEngineDeclaration engine} defaults to ABSENT — the toolkit's own store. Present, its
163
+ * `module` URL is the store factory that mints this store instead (ADR-0050 addendum 2026-09-08). It is
164
+ * part of the declaration for the same reason the other two are: a store's datadir belongs to the engine
165
+ * that wrote it, so a different `module` is a DIFFERENT store, minted fresh under a fresh path, never a
166
+ * rehome of an existing one.
117
167
  */
118
168
  export interface SyncStorageDeclaration {
119
169
  backend?: StorageBackend;
120
170
  durability?: StorageDurability;
171
+ build?: StorageBuild;
172
+ engine?: StorageEngineDeclaration;
121
173
  }
122
174
  /**
123
175
  * A {@link SyncStorageDeclaration} with every field resolved (ADR-0050) — the store's BOUND declaration.
124
176
  * Produced once per store by {@link resolveStorageDeclaration} and immutable for the store's lifetime: a
125
177
  * preference change mints a fresh store under a fresh path, never rebinds an existing one.
178
+ *
179
+ * `engine` is the one field that stays OPTIONAL after resolution, because the toolkit's own store has no
180
+ * module URL to name: absent IS the resolved value of "the built-in engine".
126
181
  */
127
182
  export interface ResolvedStorageDeclaration {
128
183
  backend: StorageBackend;
129
184
  durability: StorageDurability;
185
+ build: StorageBuild;
186
+ engine?: StorageEngineDeclaration;
130
187
  }
131
188
  /**
132
189
  * A storage declaration was refused (ADR-0050): two sources explicitly disagree on a field, or a later
@@ -137,18 +194,50 @@ export interface ResolvedStorageDeclaration {
137
194
  export declare class StorageDeclarationRefusedError extends Error {
138
195
  constructor(message: string);
139
196
  }
197
+ /**
198
+ * Where a store's Postgres build was checked against its declaration (ADR-0063): before a mint by the
199
+ * build a site supplies (`createSyncClient`, `defineSyncWorker`, `createPgwasmClient`), or on an instance a
200
+ * site adopts (`pgwasmInstance`, `precreatedPgwasm`, the result of a worker's `createStore`).
201
+ */
202
+ export type StoreBuildCheckSite = "createSyncClient" | "defineSyncWorker" | "createPgwasmClient" | "pgwasmInstance" | "precreatedPgwasm" | "createStore";
203
+ /**
204
+ * The registry declares one Postgres build (`storage.build`, ADR-0063) and the code supplied or adopted
205
+ * another. Thrown before any store is touched. A store's build is code, never a declared string: pass the
206
+ * declared build (e.g. `defineSyncWorker({ build })`, `createSyncClient({ build })`), or fix the declaration.
207
+ * The stable `name` survives bridge serialization (`BridgeErrorWire.name`), and `detail` carries the three
208
+ * fields across it, so a tab can detect the refusal typed.
209
+ */
210
+ export declare class StorageBuildMismatchError extends Error {
211
+ readonly declared: StorageBuild;
212
+ readonly supplied: string;
213
+ readonly site: StoreBuildCheckSite;
214
+ readonly detail: {
215
+ readonly declared: StorageBuild;
216
+ readonly supplied: string;
217
+ readonly site: StoreBuildCheckSite;
218
+ };
219
+ constructor(declared: StorageBuild, supplied: string, site: StoreBuildCheckSite);
220
+ }
140
221
  /**
141
222
  * Resolve a store's storage declaration from its two sources (ADR-0050): the registry-attached STATIC
142
223
  * declaration (authoritative) and the tab's WIRE declaration (honoured only where the registry is silent).
143
224
  * Per field: an unset field is "no opinion" and can never conflict; both explicit and disagreeing is a
144
225
  * {@link StorageDeclarationRefusedError}; unresolved fields take the capability defaults
145
- * (`backend: "opfs"`, `durability: "relaxed"`).
226
+ * (`backend: "opfs"`, `durability: "relaxed"`, `build: "c"`, and NO engine module — the toolkit's own store).
227
+ *
228
+ * The `engine` field resolves on its `module` URL, which is the identity that matters: two declarations
229
+ * naming the same module are the same engine, and a disagreement refuses exactly as the other fields do.
146
230
  */
147
231
  export declare function resolveStorageDeclaration(staticDeclaration: SyncStorageDeclaration | undefined, wireDeclaration: SyncStorageDeclaration | undefined): ResolvedStorageDeclaration;
148
232
  /**
149
233
  * Check a LATER declaration against a store's bound resolution (ADR-0050): an unset or equal field is
150
234
  * idempotent; an explicit field disagreeing with the bound value is a {@link StorageDeclarationRefusedError}.
151
235
  * The bound declaration is immutable — first arrival binds, later arrivals only confirm.
236
+ *
237
+ * `engine` is checked on its `module` URL, and only when the incoming declaration names one: an incoming
238
+ * declaration with NO engine is "no opinion" exactly like an unset `backend`, never an assertion that the
239
+ * store is on the built-in engine. (Absence is how the built-in engine is spelled, so it cannot double as
240
+ * an explicit contradiction; a consumer switching back mints a fresh store rather than redeclaring one.)
152
241
  */
153
242
  export declare function assertStorageDeclarationCompatible(bound: ResolvedStorageDeclaration, incoming: SyncStorageDeclaration | undefined): void;
154
243
  /**
@@ -265,22 +354,60 @@ export interface RowTransformContext {
265
354
  * jsonb column, or otherwise rewrite a value, *conditionally on row data*. This expresses
266
355
  * what a static, whole-column `omitColumns` cannot.
267
356
  *
268
- * Server authority only: it never alters the local PGlite schema and never alters the shape
357
+ * Server authority only: it never alters the local pgwasm schema and never alters the shape
269
358
  * definition — the engine ref-counts shapes by definition (ADR-0055), so a transform can
270
359
  * neither change which stream a subject reads nor split one that would otherwise be shared.
271
360
  * Return the same `row` reference to signal "no change".
272
361
  */
273
362
  export type RowTransform = (row: Record<string, unknown>, context: RowTransformContext) => Record<string, unknown>;
363
+ /**
364
+ * One index the LOCAL store should carry on a synced table (see {@link ClientProjectionSpec.localIndexes}).
365
+ * A plain ascending btree over projected columns — deliberately the same expressiveness the local schema
366
+ * generator's shared `CREATE INDEX` core has for the journal indexes, and no more.
367
+ */
368
+ export interface LocalIndexSpec {
369
+ /** The index's name. Unique within the entry, and a plain identifier — it is emitted into DDL. */
370
+ name: string;
371
+ /**
372
+ * The indexed columns, in order. Each names a column of the entry's table by DB column name or by
373
+ * Drizzle property key (the same either/or the primary-key specs accept), and must survive the client
374
+ * projection: naming an `omitColumns` column is a registry error, because the local table has no such
375
+ * column to index.
376
+ */
377
+ columns: readonly string[];
378
+ /**
379
+ * Emit `CREATE UNIQUE INDEX`. Note what that means for a synced cache: uniqueness is the SERVER's
380
+ * guarantee, and a local unique index turns a violation into a failed apply rather than a rejected
381
+ * write. Declare it only where the server constraint genuinely holds for the projected rows.
382
+ */
383
+ unique?: boolean;
384
+ }
274
385
  export interface ClientProjectionSpec {
275
386
  syncedTable?: string;
276
387
  overlayTable?: string;
277
388
  journalTable?: string;
278
389
  omitColumns?: readonly string[];
279
390
  localPrimaryKey?: PrimaryKeySpec;
391
+ /**
392
+ * OPT-IN local indexes for this entry's synced table (ADR-0029 D3's renderer, consumer-declared).
393
+ *
394
+ * The local store renders a table's PRIMARY KEY and nothing else — a synced table's server-side indexes
395
+ * are NOT mirrored, deliberately: they serve server loads, and half of them cover columns a client
396
+ * projection omits. So a local read path that needs an index has to say so here, and only here.
397
+ *
398
+ * Declare what the CLIENT's queries need, not what the server has: a scan the app runs on every render
399
+ * over a large synced table (the motivating case: a `due_at` window over 100k rows — ~13 ms sequential
400
+ * vs ~0.1 ms indexed on pgwasm, logged by `tests/unit/read-model-overlay-plan`). Each index costs write
401
+ * time on every applied batch and space in the user's store, so an index nothing queries is a straight loss.
402
+ *
403
+ * Rendered on the synced table ONLY — never on the overlay, whose primary key is already its index and
404
+ * whose plan problem is not an index problem (see the read model's non-membership test).
405
+ */
406
+ localIndexes?: readonly LocalIndexSpec[];
280
407
  }
281
408
  /**
282
409
  * Server-side projection applied on the read egress path. This is server
283
- * authority, not client shape — it never alters the local PGlite schema or the
410
+ * authority, not client shape — it never alters the local pgwasm schema or the
284
411
  * shape definition — so it lives apart from {@link ClientProjectionSpec} (ADR-0004).
285
412
  */
286
413
  export interface ServerProjectionSpec {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,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UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;CAClE,kBAEA;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,UAAU,EAAE,cAAc,CAAC;IAC3B,gBAAgB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;CAClE,YAEA;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,SAAS,GAAG,IAAI,CAAC;IAC5F,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAoD,CAAC;AAEtF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAUrF;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAElH"}
package/dist/index.js CHANGED
@@ -44,6 +44,13 @@ function isJsonSafe(column) {
44
44
  const base = normalizeBaseType(column.sqlType);
45
45
  return base === "json" || base === "jsonb";
46
46
  }
47
+ function jsonUdtName(column) {
48
+ const base = normalizeBaseType(column.sqlType);
49
+ if (base !== "json" && base !== "jsonb") {
50
+ return;
51
+ }
52
+ return column.isArray ? `_${base}` : base;
53
+ }
47
54
  function classifyApplyStrategy(columns) {
48
55
  if (columns.length === 0) {
49
56
  return "insert";
@@ -176,6 +183,23 @@ var STORAGE_DURABILITIES = ["relaxed", "strict"];
176
183
  function isStorageDurability(value) {
177
184
  return typeof value === "string" && STORAGE_DURABILITIES.includes(value);
178
185
  }
186
+ var STORAGE_BUILDS = ["c", "pgrust"];
187
+ function isStorageBuild(value) {
188
+ return typeof value === "string" && STORAGE_BUILDS.includes(value);
189
+ }
190
+ function isStorageEngineModule(value) {
191
+ if (typeof value !== "string" || value.trim() === "")
192
+ return false;
193
+ try {
194
+ const url = new URL(value, "https://storage-engine.invalid/");
195
+ return value.startsWith("/") || url.href === new URL(value).href;
196
+ } catch {
197
+ return false;
198
+ }
199
+ }
200
+ function isStorageEngineDeclaration(value) {
201
+ return typeof value === "object" && value !== null && isStorageEngineModule(value.module);
202
+ }
179
203
 
180
204
  class StorageDeclarationRefusedError extends Error {
181
205
  constructor(message) {
@@ -183,6 +207,21 @@ class StorageDeclarationRefusedError extends Error {
183
207
  this.name = "StorageDeclarationRefusedError";
184
208
  }
185
209
  }
210
+
211
+ class StorageBuildMismatchError extends Error {
212
+ declared;
213
+ supplied;
214
+ site;
215
+ detail;
216
+ constructor(declared, supplied, site) {
217
+ super(`storage build mismatch at ${site}: the registry declares the "${declared}" Postgres build but the ` + `store's build is "${supplied}" \u2014 supply the declared build (a \`build\` option), or fix \`storage.build\``);
218
+ this.name = "StorageBuildMismatchError";
219
+ this.declared = declared;
220
+ this.supplied = supplied;
221
+ this.site = site;
222
+ this.detail = { declared, supplied, site };
223
+ }
224
+ }
186
225
  function resolveDeclarationField(field, staticValue, wireValue, defaultValue) {
187
226
  if (staticValue !== undefined && wireValue !== undefined && staticValue !== wireValue) {
188
227
  throw new StorageDeclarationRefusedError(`storage declaration disagreement on "${field}": the registry-attached declaration says ` + `"${String(staticValue)}" but the wire declaration says "${String(wireValue)}" \u2014 a store's storage ` + `contract has one value per field; fix the declaring side (a preference change mints a fresh store, ` + `it never redeclares an existing one)`);
@@ -190,20 +229,27 @@ function resolveDeclarationField(field, staticValue, wireValue, defaultValue) {
190
229
  return staticValue ?? wireValue ?? defaultValue;
191
230
  }
192
231
  function resolveStorageDeclaration(staticDeclaration, wireDeclaration) {
232
+ const engineModule = resolveDeclarationField("engine", staticDeclaration?.engine?.module, wireDeclaration?.engine?.module, undefined);
193
233
  return {
194
234
  backend: resolveDeclarationField("backend", staticDeclaration?.backend, wireDeclaration?.backend, "opfs"),
195
- durability: resolveDeclarationField("durability", staticDeclaration?.durability, wireDeclaration?.durability, "relaxed")
235
+ durability: resolveDeclarationField("durability", staticDeclaration?.durability, wireDeclaration?.durability, "relaxed"),
236
+ build: resolveDeclarationField("build", staticDeclaration?.build, wireDeclaration?.build, "c"),
237
+ ...engineModule === undefined ? {} : { engine: { module: engineModule } }
196
238
  };
197
239
  }
198
240
  function assertStorageDeclarationCompatible(bound, incoming) {
199
241
  if (incoming === undefined)
200
242
  return;
201
- for (const field of ["backend", "durability"]) {
243
+ for (const field of ["backend", "durability", "build"]) {
202
244
  const value = incoming[field];
203
245
  if (value !== undefined && value !== bound[field]) {
204
246
  throw new StorageDeclarationRefusedError(`storage declaration disagreement on "${field}": the store is bound to "${bound[field]}" but a later ` + `declaration says "${value}" \u2014 a store's declaration is immutable; a preference change mints a ` + `fresh store under a fresh path`);
205
247
  }
206
248
  }
249
+ const incomingEngine = incoming.engine?.module;
250
+ if (incomingEngine !== undefined && incomingEngine !== bound.engine?.module) {
251
+ throw new StorageDeclarationRefusedError(`storage declaration disagreement on "engine": the store is bound to ` + `${bound.engine === undefined ? "the built-in store engine" : `"${bound.engine.module}"`} but a later ` + `declaration says "${incomingEngine}" \u2014 a store's declaration is immutable; a store's datadir belongs ` + `to the engine that wrote it, so an engine change mints a fresh store under a fresh path`);
252
+ }
207
253
  }
208
254
  var jwtClaimsSchema = z2.looseObject({
209
255
  sub: z2.string().optional(),
@@ -524,6 +570,7 @@ function defineSyncRegistry(input) {
524
570
  }
525
571
  validateRegistryTableUniqueness(input.tables);
526
572
  validateRegistryShapeKeyUniqueness(input.tables);
573
+ validateRegistryLocalIndexNames(input.tables);
527
574
  validateRegistryLifecycleGroups(input.tables);
528
575
  validateStorageDeclaration(input.storage);
529
576
  validateRowClassification(input.tables, input.rowClasses);
@@ -535,6 +582,7 @@ function defineSyncRegistry(input) {
535
582
  }
536
583
  validateRegistryTableUniqueness(input);
537
584
  validateRegistryShapeKeyUniqueness(input);
585
+ validateRegistryLocalIndexNames(input);
538
586
  validateRegistryLifecycleGroups(input);
539
587
  return input;
540
588
  }
@@ -552,6 +600,18 @@ function validateRegistryTableUniqueness(registry) {
552
600
  declaredBy.set(identity, key);
553
601
  }
554
602
  }
603
+ function validateRegistryLocalIndexNames(registry) {
604
+ const declaredBy = new Map;
605
+ for (const [key, entry] of Object.entries(registry)) {
606
+ for (const index of entry.clientProjection?.localIndexes ?? []) {
607
+ const firstKey = declaredBy.get(index.name);
608
+ if (firstKey !== undefined) {
609
+ throw new Error(`local index "${index.name}" is declared by two registry entries ("${firstKey}" and "${key}"): ` + `an index name is a schema-level object name, and the generator's CREATE INDEX IF NOT EXISTS ` + `would silently skip the second one. Name each local index after its own table.`);
610
+ }
611
+ declaredBy.set(index.name, key);
612
+ }
613
+ }
614
+ }
555
615
  function validateRegistryShapeKeyUniqueness(registry) {
556
616
  const declaredBy = new Map;
557
617
  for (const [key, entry] of Object.entries(registry)) {
@@ -702,7 +762,7 @@ function attachSyncRegistryStorage(registry, storage) {
702
762
  }
703
763
  const existing = getSyncRegistryStorage(registry);
704
764
  if (existing != null) {
705
- if (existing.backend !== storage.backend || existing.durability !== storage.durability) {
765
+ if (existing.backend !== storage.backend || existing.durability !== storage.durability || existing.engine?.module !== storage.engine?.module) {
706
766
  throw new Error(`conflicting storage declaration for registry: already ${JSON.stringify(existing)}, cannot re-declare ` + `${JSON.stringify(storage)}`);
707
767
  }
708
768
  return registry;
@@ -867,6 +927,12 @@ function validateStorageDeclaration(storage) {
867
927
  if (storage.durability !== undefined && !isStorageDurability(storage.durability)) {
868
928
  throw new Error(`invalid storage.durability "${String(storage.durability)}": must be one of ${STORAGE_DURABILITIES.join(", ")}`);
869
929
  }
930
+ if (storage.build !== undefined && !isStorageBuild(storage.build)) {
931
+ throw new Error(`invalid storage.build "${String(storage.build)}": must be one of ${STORAGE_BUILDS.join(", ")}`);
932
+ }
933
+ if (storage.engine !== undefined && !isStorageEngineDeclaration(storage.engine)) {
934
+ throw new Error(`invalid storage.engine ${JSON.stringify(storage.engine)}: must be { module } naming an ABSOLUTE ` + `("https://host/factory.js") or ORIGIN-RELATIVE ("/store-engine/factory.js") module URL the engine ` + `home can import \u2014 a document-relative specifier resolves differently in a worker scope`);
935
+ }
870
936
  }
871
937
  function isSyncRegistryDefinition(input) {
872
938
  return typeof input === "object" && input !== null && "tables" in input && typeof input.tables === "object" && input.tables !== null;
@@ -934,6 +1000,7 @@ function validateSyncTableEntry(entry) {
934
1000
  const columnsByColumnName = new Map(columns.map((column) => [column.columnName, column]));
935
1001
  const omitColumns = entry.clientProjection?.omitColumns ?? [];
936
1002
  const localPrimaryKeyColumns = entry.clientProjection?.localPrimaryKey?.columns ?? [];
1003
+ validateLocalIndexes(entry, tableName, columnsByPropertyKey, columnsByColumnName, omitColumns);
937
1004
  if (omitColumns.length === 0 && localPrimaryKeyColumns.length === 0) {
938
1005
  return;
939
1006
  }
@@ -978,6 +1045,40 @@ function validateSyncTableEntry(entry) {
978
1045
  throw new Error(`clientProjection.omitColumns must only omit create-safe columns for writable table ${tableName}: ${createRequiredOmissions.join(", ")}`);
979
1046
  }
980
1047
  }
1048
+ function validateLocalIndexes(entry, tableName, columnsByPropertyKey, columnsByColumnName, omitColumns) {
1049
+ const localIndexes = entry.clientProjection?.localIndexes ?? [];
1050
+ if (localIndexes.length === 0) {
1051
+ return;
1052
+ }
1053
+ const omitted = new Set;
1054
+ for (const propertyKey of omitColumns) {
1055
+ omitted.add(propertyKey);
1056
+ const column = columnsByPropertyKey.get(propertyKey);
1057
+ if (column)
1058
+ omitted.add(column.columnName);
1059
+ }
1060
+ const seenNames = new Set;
1061
+ for (const index of localIndexes) {
1062
+ if (typeof index.name !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(index.name)) {
1063
+ throw new Error(`clientProjection.localIndexes on ${tableName} declares an invalid index name ${JSON.stringify(index.name)}: ` + `it is emitted into DDL, so it must be a plain identifier ([A-Za-z_][A-Za-z0-9_]*)`);
1064
+ }
1065
+ if (seenNames.has(index.name)) {
1066
+ throw new Error(`clientProjection.localIndexes on ${tableName} declares the index name "${index.name}" twice: ` + `an index name must be unique (it is a schema-level object name)`);
1067
+ }
1068
+ seenNames.add(index.name);
1069
+ if (index.columns.length === 0) {
1070
+ throw new Error(`clientProjection.localIndexes on ${tableName}: index "${index.name}" declares no columns`);
1071
+ }
1072
+ for (const column of index.columns) {
1073
+ if (omitted.has(column)) {
1074
+ throw new Error(`clientProjection.localIndexes on ${tableName}: index "${index.name}" names column "${column}", which ` + `clientProjection.omitColumns removes from the local table \u2014 index only projected columns`);
1075
+ }
1076
+ if (!columnsByPropertyKey.has(column) && !columnsByColumnName.has(column)) {
1077
+ throw new Error(`clientProjection.localIndexes on ${tableName}: index "${index.name}" names unknown column "${column}"`);
1078
+ }
1079
+ }
1080
+ }
1081
+ }
981
1082
 
982
1083
  // packages/contracts/src/sql-identifier.ts
983
1084
  var RESERVED_SQL_KEYWORDS = new Set([
@@ -1705,7 +1806,8 @@ function asReadonly(entry) {
1705
1806
  const readonlyProjection = clientProjection != null ? {
1706
1807
  ...clientProjection.syncedTable != null ? { syncedTable: clientProjection.syncedTable } : {},
1707
1808
  ...clientProjection.omitColumns != null ? { omitColumns: clientProjection.omitColumns } : {},
1708
- ...clientProjection.localPrimaryKey != null ? { localPrimaryKey: clientProjection.localPrimaryKey } : {}
1809
+ ...clientProjection.localPrimaryKey != null ? { localPrimaryKey: clientProjection.localPrimaryKey } : {},
1810
+ ...clientProjection.localIndexes != null ? { localIndexes: clientProjection.localIndexes } : {}
1709
1811
  } : undefined;
1710
1812
  return {
1711
1813
  table: entry.table,
@@ -2163,8 +2265,10 @@ export {
2163
2265
  NOW_MICROSECONDS_SQL_TEXT,
2164
2266
  RETENTIONS,
2165
2267
  STORAGE_BACKENDS,
2268
+ STORAGE_BUILDS,
2166
2269
  STORAGE_DURABILITIES,
2167
2270
  SUBSCRIPTION_TIMINGS,
2271
+ StorageBuildMismatchError,
2168
2272
  StorageDeclarationRefusedError,
2169
2273
  WRITE_MODES,
2170
2274
  asEphemeral,
@@ -2248,10 +2352,14 @@ export {
2248
2352
  isOrPredicate,
2249
2353
  isRetention,
2250
2354
  isStorageBackend,
2355
+ isStorageBuild,
2251
2356
  isStorageDurability,
2357
+ isStorageEngineDeclaration,
2358
+ isStorageEngineModule,
2252
2359
  isSubscriptionTiming,
2253
2360
  isWriteMode,
2254
2361
  isZodSchema,
2362
+ jsonUdtName,
2255
2363
  jwtClaimsSchema,
2256
2364
  maybeQuoteIdentifier,
2257
2365
  mutationAckSchema,
@@ -2284,4 +2392,4 @@ export {
2284
2392
  withRetention
2285
2393
  };
2286
2394
 
2287
- //# debugId=55BBD8D000C5BC3D64756E2164756E21
2395
+ //# debugId=68C3BDD5068DEA1A64756E2164756E21