@pgxsinkit/contracts 0.1.53 → 0.2.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/dist/config.d.ts CHANGED
@@ -7,14 +7,15 @@ export type TableMode = "readonly" | "writeonly" | "readwrite";
7
7
  * interleaved). It is a **required** declaration on every writable table; there is no silent default
8
8
  * (registry validation rejects an undeclared writable table — the third hard-require). v1:
9
9
  *
10
- * - `last-write-wins` — apply the stale write anyway. This is today's implicit behaviour, but now a
11
- * conscious, named choice rather than silent clobbering.
10
+ * - `last-write-wins` — apply the stale write anyway. A required, named declaration: the toolkit never
11
+ * silently clobbers under an unspecified default, so choosing this is an explicit acceptance of the
12
+ * stale-overwrite semantics.
12
13
  * - `reject-if-stale` — do not apply; surface the conflict so the user's edit is kept (the optimistic
13
14
  * Overlay stays, marked conflicted) and resolved as a new write.
14
15
  *
15
16
  * `field-merge` (apply only the changed fields over the current row) and `custom-resolver` (a client
16
- * re-resolution protocol) are reserved; the union is additive so they slot in without a breaking
17
- * change.
17
+ * re-resolution protocol) are reserved values for future policies — declared here so the policy surface
18
+ * names its full intended range.
18
19
  */
19
20
  export type ConflictPolicy = "last-write-wins" | "reject-if-stale";
20
21
  /** The Conflict policy values accepted in v1 (ADR-0015). Source of truth for registry validation. */
@@ -74,6 +75,48 @@ export type WriteMode = "optimistic" | "pessimistic";
74
75
  export declare const WRITE_MODES: readonly ["optimistic", "pessimistic"];
75
76
  /** Type guard: is `value` a {@link WriteMode}? */
76
77
  export declare function isWriteMode(value: unknown): value is WriteMode;
78
+ /**
79
+ * The registry-declared BROWSER storage backend (ADR-0049 decision 1). `opfs` (default) is the store's
80
+ * normal boot on every platform — the capability machinery selects the `opfs-repacked` VFS where a home
81
+ * can hold sync-access handles, and falls back to in-SharedWorker `idbfs` when no home can. `idbfs` is the
82
+ * one way to opt out of that machinery entirely: no probe, no election, the engine boots on idb.
83
+ *
84
+ * Scopes the BROWSER store only. Environment resolution is orthogonal and unchanged (ADR-0049 decision 14):
85
+ * a Node mint stays `file://` and the export clone stays memory regardless of this declaration.
86
+ */
87
+ export type StorageBackend = "opfs" | "idbfs";
88
+ /** The {@link StorageBackend} values. Source of truth for {@link SyncStorageDeclaration} validation. */
89
+ export declare const STORAGE_BACKENDS: readonly ["opfs", "idbfs"];
90
+ /** Type guard: is `value` a {@link StorageBackend}? */
91
+ export declare function isStorageBackend(value: unknown): value is StorageBackend;
92
+ /**
93
+ * The registry-declared durability mode (ADR-0047; ADR-0049 decision 9). `relaxed` (default) returns a
94
+ * write before its durable flush and schedules the flush asynchronously — the local-first "instant write"
95
+ * the toolkit exists to deliver. `strict` reinstates the synchronous flush boundary (a ~50ms+ per-statement
96
+ * floor on idb; cheap on `opfs-repacked`). It binds EVERY open of EVERY store minted from the registry, so
97
+ * no minting/open site takes a durability option to contradict it, and an opfs→idbfs capability fallback
98
+ * keeps the declared mode.
99
+ */
100
+ export type StorageDurability = "relaxed" | "strict";
101
+ /** The {@link StorageDurability} values. Source of truth for {@link SyncStorageDeclaration} validation. */
102
+ export declare const STORAGE_DURABILITIES: readonly ["relaxed", "strict"];
103
+ /** Type guard: is `value` a {@link StorageDurability}? */
104
+ export declare function isStorageDurability(value: unknown): value is StorageDurability;
105
+ /**
106
+ * The registry's storage contract (ADR-0049 decision 1, ADR-0047). Storage is PART OF THE DATA CONTRACT:
107
+ * whether losing the last not-yet-flushed action is acceptable, and whether OPFS may be used at all, is
108
+ * decided by what the data IS — so it is declared once on the registry, not at any minting/open site.
109
+ *
110
+ * - {@link StorageDurability durability} defaults to `"relaxed"` and binds every toolkit-minted open of
111
+ * every store the registry mints (its own boot AND the provision/spare path). No open-site option exists
112
+ * to contradict it; a capability fallback keeps the declared mode. A no-op on `memory` clones.
113
+ * - {@link StorageBackend backend} defaults to `"opfs"` and scopes the BROWSER store only; Node/`file` and
114
+ * `memory` clones are unaffected. `"idbfs"` opts the store out of the capability/election machinery.
115
+ */
116
+ export interface SyncStorageDeclaration {
117
+ backend?: StorageBackend;
118
+ durability?: StorageDurability;
119
+ }
77
120
  /**
78
121
  * Minimal verified-JWT claim shape the sync layer understands. Providers may
79
122
  * attach arbitrary extra claims; those stay reachable through index access and
@@ -266,13 +309,6 @@ export interface RowFilterSpec {
266
309
  */
267
310
  revision?: string | number;
268
311
  }
269
- /**
270
- * The non-parameterized inline `where` for a filter: the string a `customWhere` returns (the raw
271
- * escape hatch), or `null` when there is no filter or `customWhere` returns a Drizzle `SQL` fragment
272
- * (which is parameterized by {@link buildRowFilterShape}, not inlined here). Most callers want
273
- * `buildRowFilterShape` — this is the inline-string view it composes from.
274
- */
275
- export declare function buildRowFilterWhere(filter: RowFilterSpec, claims: JwtClaims | null, params?: Record<string, unknown>): string | null;
276
312
  /**
277
313
  * A **bare** (table-unqualified) quoted identifier for a Drizzle column — `"workspace_id"`, never
278
314
  * `"work_items"."workspace_id"`. Electric's shape `where` grammar requires *plain* column references
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAEnE,qGAAqG;AACrG,eAAO,MAAM,iBAAiB,iDAAsF,CAAC;AAErH,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAC;AAElD,sFAAsF;AACtF,eAAO,MAAM,oBAAoB,4BAAqE,CAAC;AAEvG,2DAA2D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AG,GAAG,CAExG;AAED,uGAAuG;AACvG,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,cAAc,GAAG,IAAI,CAavB"}
package/dist/index.js CHANGED
@@ -90,6 +90,14 @@ var WRITE_MODES = ["optimistic", "pessimistic"];
90
90
  function isWriteMode(value) {
91
91
  return typeof value === "string" && WRITE_MODES.includes(value);
92
92
  }
93
+ var STORAGE_BACKENDS = ["opfs", "idbfs"];
94
+ function isStorageBackend(value) {
95
+ return typeof value === "string" && STORAGE_BACKENDS.includes(value);
96
+ }
97
+ var STORAGE_DURABILITIES = ["relaxed", "strict"];
98
+ function isStorageDurability(value) {
99
+ return typeof value === "string" && STORAGE_DURABILITIES.includes(value);
100
+ }
93
101
  var jwtClaimsSchema = z2.looseObject({
94
102
  sub: z2.string().optional(),
95
103
  app_metadata: z2.looseObject({
@@ -102,10 +110,6 @@ function getLocalSyncPrimaryKey(source) {
102
110
  function getLocalSyncPrimaryKeyColumns(source) {
103
111
  return [...getLocalSyncPrimaryKey(source).columns];
104
112
  }
105
- function buildRowFilterWhere(filter, claims, params) {
106
- const custom = filter.customWhere?.(claims ?? {}, params);
107
- return typeof custom === "string" && custom ? custom : null;
108
- }
109
113
  function c(column) {
110
114
  return sql`${sql.identifier(column.name)}`;
111
115
  }
@@ -149,6 +153,7 @@ import {
149
153
  import { varchar } from "drizzle-orm/pg-core";
150
154
  import { getColumns } from "drizzle-orm/utils";
151
155
  var syncRegistrySchemaSymbol = Symbol.for("@pgxsinkit/contracts/syncRegistrySchema");
156
+ var syncRegistryStorageSymbol = Symbol.for("@pgxsinkit/contracts/syncRegistryStorage");
152
157
  function viewColumnsForProjection(columns, omittedColumns) {
153
158
  if (omittedColumns.length === 0) {
154
159
  return columns;
@@ -223,7 +228,7 @@ function defineSyncTable(input) {
223
228
  return [...consumerExtras, pgPrimaryKey({ name: primaryKeyConstraintName, columns: pkColumns })];
224
229
  } : undefined;
225
230
  const table = schema ? schema.table(tableName, makeColumns(), extrasFn) : pgTable(tableName, makeColumns(), extrasFn);
226
- const resolvedRowFilter = typeof shape?.rowFilter === "function" ? shape.rowFilter(getColumns(table)) : shape?.rowFilter ?? undefined;
231
+ const resolvedRowFilter = shape?.rowFilter?.(getColumns(table));
227
232
  const resolvedShape = resolvedMode !== "writeonly" || shape != null ? {
228
233
  tableName: shape?.tableName ?? tableName,
229
234
  shapeKey: shape?.shapeKey ?? shape?.tableName ?? tableName,
@@ -308,7 +313,7 @@ function defineReadProjection(owner, opts) {
308
313
  ...opts.subscription != null ? { subscription: opts.subscription } : {},
309
314
  ...opts.retention != null ? { retention: opts.retention } : {}
310
315
  });
311
- const resolvedRowFilter = typeof opts.rowFilter === "function" ? opts.rowFilter(getColumns(owner.table)) : opts.rowFilter;
316
+ const resolvedRowFilter = opts.rowFilter?.(getColumns(owner.table));
312
317
  const ownerColumns = getColumns(owner.table);
313
318
  const serverOnlyColumnNames = serverOnlyColumns.map((key) => ownerColumns[key].name);
314
319
  const allowListColumns = omittedKeys.length > 0 ? [...getProjectedColumnNames(built), ...serverOnlyColumnNames] : undefined;
@@ -338,7 +343,8 @@ function defineSyncRegistry(input) {
338
343
  }
339
344
  validateRegistryTableUniqueness(input.tables);
340
345
  validateRegistryLifecycleGroups(input.tables);
341
- return attachSyncRegistrySchema(input.tables, input.schema);
346
+ validateStorageDeclaration(input.storage);
347
+ return attachSyncRegistryStorage(attachSyncRegistrySchema(input.tables, input.schema), input.storage);
342
348
  }
343
349
  for (const entry of getRegistryEntries(input)) {
344
350
  validateSyncTableEntry(entry);
@@ -457,11 +463,7 @@ function resolveServerVersionColumnName(entry) {
457
463
  return;
458
464
  }
459
465
  const columns = getColumns(entry.table);
460
- const byProperty = columns[field.column];
461
- if (byProperty) {
462
- return byProperty.name;
463
- }
464
- return Object.values(columns).find((column) => column.name === field.column)?.name;
466
+ return columns[field.column]?.name;
465
467
  }
466
468
  function attachSyncRegistrySchema(registry, schema) {
467
469
  const normalizedSchema = normalizeSchemaName(schema);
@@ -496,6 +498,40 @@ function getSyncRegistrySchema(registry) {
496
498
  const schema = Reflect.get(registry, syncRegistrySchemaSymbol);
497
499
  return typeof schema === "string" && schema.length > 0 ? schema : "public";
498
500
  }
501
+ function attachSyncRegistryStorage(registry, storage) {
502
+ if (storage == null) {
503
+ return registry;
504
+ }
505
+ const existing = getSyncRegistryStorage(registry);
506
+ if (existing != null) {
507
+ if (existing.backend !== storage.backend || existing.durability !== storage.durability) {
508
+ throw new Error(`conflicting storage declaration for registry: already ${JSON.stringify(existing)}, cannot re-declare ` + `${JSON.stringify(storage)}`);
509
+ }
510
+ return registry;
511
+ }
512
+ Object.defineProperty(registry, syncRegistryStorageSymbol, {
513
+ value: storage,
514
+ enumerable: false,
515
+ configurable: false,
516
+ writable: false
517
+ });
518
+ return registry;
519
+ }
520
+ function getSyncRegistryStorage(registry) {
521
+ const storage = Reflect.get(registry, syncRegistryStorageSymbol);
522
+ return storage != null && typeof storage === "object" ? storage : undefined;
523
+ }
524
+ function validateStorageDeclaration(storage) {
525
+ if (storage == null) {
526
+ return;
527
+ }
528
+ if (storage.backend !== undefined && !isStorageBackend(storage.backend)) {
529
+ throw new Error(`invalid storage.backend "${String(storage.backend)}": must be one of ${STORAGE_BACKENDS.join(", ")}`);
530
+ }
531
+ if (storage.durability !== undefined && !isStorageDurability(storage.durability)) {
532
+ throw new Error(`invalid storage.durability "${String(storage.durability)}": must be one of ${STORAGE_DURABILITIES.join(", ")}`);
533
+ }
534
+ }
499
535
  function isSyncRegistryDefinition(input) {
500
536
  return typeof input === "object" && input !== null && "tables" in input && typeof input.tables === "object" && input.tables !== null;
501
537
  }
@@ -529,7 +565,11 @@ function validateSyncTableEntry(entry) {
529
565
  if (entry.writeMode === "pessimistic" && entry.mode === "readonly") {
530
566
  throw new Error(`readonly table ${tableName} cannot be pessimistic (ADR-0022): write-mode governs the write path, ` + `which a readonly table does not have. Declare writeMode only on a writable table.`);
531
567
  }
568
+ const managedFieldPropertyKeys = new Set(Object.keys(getColumns(entry.table)));
532
569
  for (const field of entry.governance?.managedFields ?? []) {
570
+ if (!managedFieldPropertyKeys.has(field.column)) {
571
+ throw new Error(`managed field ${tableName}.${String(field.column)} names an unknown column: field.column must be the ` + `drizzle PROPERTY KEY of the target column, not its SQL column name (ADR-0012)`);
572
+ }
533
573
  if (field.strategy === "authClaim") {
534
574
  if (!Array.isArray(field.claimPath) || field.claimPath.length === 0) {
535
575
  throw new Error(`managed field ${tableName}.${String(field.column)} (strategy "authClaim") must declare a non-empty ` + `claimPath (e.g. ["sub"] or ["app_metadata","person_id"]) \u2014 ADR-0026`);
@@ -1425,6 +1465,7 @@ function buildGrantScopeShapeWhere(scopeColumn, ids) {
1425
1465
  export {
1426
1466
  withRetention,
1427
1467
  unixMicrosecondsSchema,
1468
+ syncRegistryStorageSymbol,
1428
1469
  syncRegistrySchemaSymbol,
1429
1470
  supabaseOwnerOrAdminDefaults,
1430
1471
  summarizeRegistryDiff,
@@ -1444,10 +1485,13 @@ export {
1444
1485
  jwtClaimsSchema,
1445
1486
  isWriteMode,
1446
1487
  isSubscriptionTiming,
1488
+ isStorageDurability,
1489
+ isStorageBackend,
1447
1490
  isRetention,
1448
1491
  isConflictPolicy,
1449
1492
  isClaimsDependentRowFilter,
1450
1493
  hashString,
1494
+ getSyncRegistryStorage,
1451
1495
  getSyncRegistrySchema,
1452
1496
  getProjectedColumns,
1453
1497
  getProjectedColumnNames,
@@ -1480,7 +1524,6 @@ export {
1480
1524
  buildSupabaseOwnerOrAdminNativePolicies,
1481
1525
  buildSupabaseMembershipNativePolicies,
1482
1526
  buildSupabaseGrantScopeNativePolicies,
1483
- buildRowFilterWhere,
1484
1527
  buildRowFilterShape,
1485
1528
  buildRegistryLock,
1486
1529
  buildOwnershipShapeWhere,
@@ -1490,12 +1533,15 @@ export {
1490
1533
  batchMutationErrorSchema,
1491
1534
  batchMutationAckSchema,
1492
1535
  authoritativeWriteRequestSchema,
1536
+ attachSyncRegistryStorage,
1493
1537
  attachSyncRegistrySchema,
1494
1538
  assertReadContractPreserved,
1495
1539
  asReadonly,
1496
1540
  asEphemeral,
1497
1541
  WRITE_MODES,
1498
1542
  SUBSCRIPTION_TIMINGS,
1543
+ STORAGE_DURABILITIES,
1544
+ STORAGE_BACKENDS,
1499
1545
  RETENTIONS,
1500
1546
  NOW_MICROSECONDS_SQL_TEXT,
1501
1547
  DENY_ALL,
@@ -1504,4 +1550,4 @@ export {
1504
1550
  CLOCK_US_CALL_SQL_TEXT
1505
1551
  };
1506
1552
 
1507
- //# debugId=92A50F53676F654B64756E2164756E21
1553
+ //# debugId=F0D61A9CF519A39664756E2164756E21