@pgxsinkit/contracts 0.1.53 → 0.2.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/dist/config.d.ts +79 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/index.js +92 -14
- package/dist/index.js.map +5 -5
- package/dist/mutation.d.ts.map +1 -1
- package/dist/registry.d.ts +35 -11
- package/dist/registry.d.ts.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/package.json +1 -1
- package/skills/registry-authoring/SKILL.md +33 -10
- package/src/config.ts +143 -19
- package/src/mutation.ts +1 -2
- package/src/registry.ts +129 -34
- package/src/runtime.ts +1 -1
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.
|
|
11
|
-
*
|
|
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
|
|
17
|
-
*
|
|
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,80 @@ 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
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A {@link SyncStorageDeclaration} with every field resolved (ADR-0050) — the store's BOUND declaration.
|
|
122
|
+
* Produced once per store by {@link resolveStorageDeclaration} and immutable for the store's lifetime: a
|
|
123
|
+
* preference change mints a fresh store under a fresh path, never rebinds an existing one.
|
|
124
|
+
*/
|
|
125
|
+
export interface ResolvedStorageDeclaration {
|
|
126
|
+
backend: StorageBackend;
|
|
127
|
+
durability: StorageDurability;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* A storage declaration was refused (ADR-0050): two sources explicitly disagree on a field, or a later
|
|
131
|
+
* declaration explicitly contradicts the store's bound declaration. Never resolved silently — the store's
|
|
132
|
+
* storage contract has exactly one value per field, and a disagreement means one side is wrong. The stable
|
|
133
|
+
* `name` survives bridge serialization (`BridgeErrorWire.name`), so a tab can detect the refusal typed.
|
|
134
|
+
*/
|
|
135
|
+
export declare class StorageDeclarationRefusedError extends Error {
|
|
136
|
+
constructor(message: string);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Resolve a store's storage declaration from its two sources (ADR-0050): the registry-attached STATIC
|
|
140
|
+
* declaration (authoritative) and the tab's WIRE declaration (honoured only where the registry is silent).
|
|
141
|
+
* Per field: an unset field is "no opinion" and can never conflict; both explicit and disagreeing is a
|
|
142
|
+
* {@link StorageDeclarationRefusedError}; unresolved fields take the capability defaults
|
|
143
|
+
* (`backend: "opfs"`, `durability: "relaxed"`).
|
|
144
|
+
*/
|
|
145
|
+
export declare function resolveStorageDeclaration(staticDeclaration: SyncStorageDeclaration | undefined, wireDeclaration: SyncStorageDeclaration | undefined): ResolvedStorageDeclaration;
|
|
146
|
+
/**
|
|
147
|
+
* Check a LATER declaration against a store's bound resolution (ADR-0050): an unset or equal field is
|
|
148
|
+
* idempotent; an explicit field disagreeing with the bound value is a {@link StorageDeclarationRefusedError}.
|
|
149
|
+
* The bound declaration is immutable — first arrival binds, later arrivals only confirm.
|
|
150
|
+
*/
|
|
151
|
+
export declare function assertStorageDeclarationCompatible(bound: ResolvedStorageDeclaration, incoming: SyncStorageDeclaration | undefined): void;
|
|
77
152
|
/**
|
|
78
153
|
* Minimal verified-JWT claim shape the sync layer understands. Providers may
|
|
79
154
|
* attach arbitrary extra claims; those stay reachable through index access and
|
|
@@ -266,13 +341,6 @@ export interface RowFilterSpec {
|
|
|
266
341
|
*/
|
|
267
342
|
revision?: string | number;
|
|
268
343
|
}
|
|
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
344
|
/**
|
|
277
345
|
* A **bare** (table-unqualified) quoted identifier for a Drizzle column — `"workspace_id"`, never
|
|
278
346
|
* `"work_items"."workspace_id"`. Electric's shape `where` grammar requires *plain* column references
|
package/dist/config.d.ts.map
CHANGED
|
@@ -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
|
|
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;;;;;;;;;;;;;;;GAeG;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;AAC3D,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A0B,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,OAAO,CAUrF;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,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,43 @@ 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
|
+
}
|
|
101
|
+
|
|
102
|
+
class StorageDeclarationRefusedError extends Error {
|
|
103
|
+
constructor(message) {
|
|
104
|
+
super(message);
|
|
105
|
+
this.name = "StorageDeclarationRefusedError";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function resolveDeclarationField(field, staticValue, wireValue, defaultValue) {
|
|
109
|
+
if (staticValue !== undefined && wireValue !== undefined && staticValue !== wireValue) {
|
|
110
|
+
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)`);
|
|
111
|
+
}
|
|
112
|
+
return staticValue ?? wireValue ?? defaultValue;
|
|
113
|
+
}
|
|
114
|
+
function resolveStorageDeclaration(staticDeclaration, wireDeclaration) {
|
|
115
|
+
return {
|
|
116
|
+
backend: resolveDeclarationField("backend", staticDeclaration?.backend, wireDeclaration?.backend, "opfs"),
|
|
117
|
+
durability: resolveDeclarationField("durability", staticDeclaration?.durability, wireDeclaration?.durability, "relaxed")
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function assertStorageDeclarationCompatible(bound, incoming) {
|
|
121
|
+
if (incoming === undefined)
|
|
122
|
+
return;
|
|
123
|
+
for (const field of ["backend", "durability"]) {
|
|
124
|
+
const value = incoming[field];
|
|
125
|
+
if (value !== undefined && value !== bound[field]) {
|
|
126
|
+
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`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
93
130
|
var jwtClaimsSchema = z2.looseObject({
|
|
94
131
|
sub: z2.string().optional(),
|
|
95
132
|
app_metadata: z2.looseObject({
|
|
@@ -102,10 +139,6 @@ function getLocalSyncPrimaryKey(source) {
|
|
|
102
139
|
function getLocalSyncPrimaryKeyColumns(source) {
|
|
103
140
|
return [...getLocalSyncPrimaryKey(source).columns];
|
|
104
141
|
}
|
|
105
|
-
function buildRowFilterWhere(filter, claims, params) {
|
|
106
|
-
const custom = filter.customWhere?.(claims ?? {}, params);
|
|
107
|
-
return typeof custom === "string" && custom ? custom : null;
|
|
108
|
-
}
|
|
109
142
|
function c(column) {
|
|
110
143
|
return sql`${sql.identifier(column.name)}`;
|
|
111
144
|
}
|
|
@@ -149,6 +182,7 @@ import {
|
|
|
149
182
|
import { varchar } from "drizzle-orm/pg-core";
|
|
150
183
|
import { getColumns } from "drizzle-orm/utils";
|
|
151
184
|
var syncRegistrySchemaSymbol = Symbol.for("@pgxsinkit/contracts/syncRegistrySchema");
|
|
185
|
+
var syncRegistryStorageSymbol = Symbol.for("@pgxsinkit/contracts/syncRegistryStorage");
|
|
152
186
|
function viewColumnsForProjection(columns, omittedColumns) {
|
|
153
187
|
if (omittedColumns.length === 0) {
|
|
154
188
|
return columns;
|
|
@@ -223,7 +257,7 @@ function defineSyncTable(input) {
|
|
|
223
257
|
return [...consumerExtras, pgPrimaryKey({ name: primaryKeyConstraintName, columns: pkColumns })];
|
|
224
258
|
} : undefined;
|
|
225
259
|
const table = schema ? schema.table(tableName, makeColumns(), extrasFn) : pgTable(tableName, makeColumns(), extrasFn);
|
|
226
|
-
const resolvedRowFilter =
|
|
260
|
+
const resolvedRowFilter = shape?.rowFilter?.(getColumns(table));
|
|
227
261
|
const resolvedShape = resolvedMode !== "writeonly" || shape != null ? {
|
|
228
262
|
tableName: shape?.tableName ?? tableName,
|
|
229
263
|
shapeKey: shape?.shapeKey ?? shape?.tableName ?? tableName,
|
|
@@ -308,7 +342,7 @@ function defineReadProjection(owner, opts) {
|
|
|
308
342
|
...opts.subscription != null ? { subscription: opts.subscription } : {},
|
|
309
343
|
...opts.retention != null ? { retention: opts.retention } : {}
|
|
310
344
|
});
|
|
311
|
-
const resolvedRowFilter =
|
|
345
|
+
const resolvedRowFilter = opts.rowFilter?.(getColumns(owner.table));
|
|
312
346
|
const ownerColumns = getColumns(owner.table);
|
|
313
347
|
const serverOnlyColumnNames = serverOnlyColumns.map((key) => ownerColumns[key].name);
|
|
314
348
|
const allowListColumns = omittedKeys.length > 0 ? [...getProjectedColumnNames(built), ...serverOnlyColumnNames] : undefined;
|
|
@@ -338,7 +372,8 @@ function defineSyncRegistry(input) {
|
|
|
338
372
|
}
|
|
339
373
|
validateRegistryTableUniqueness(input.tables);
|
|
340
374
|
validateRegistryLifecycleGroups(input.tables);
|
|
341
|
-
|
|
375
|
+
validateStorageDeclaration(input.storage);
|
|
376
|
+
return attachSyncRegistryStorage(attachSyncRegistrySchema(input.tables, input.schema), input.storage);
|
|
342
377
|
}
|
|
343
378
|
for (const entry of getRegistryEntries(input)) {
|
|
344
379
|
validateSyncTableEntry(entry);
|
|
@@ -457,11 +492,7 @@ function resolveServerVersionColumnName(entry) {
|
|
|
457
492
|
return;
|
|
458
493
|
}
|
|
459
494
|
const columns = getColumns(entry.table);
|
|
460
|
-
|
|
461
|
-
if (byProperty) {
|
|
462
|
-
return byProperty.name;
|
|
463
|
-
}
|
|
464
|
-
return Object.values(columns).find((column) => column.name === field.column)?.name;
|
|
495
|
+
return columns[field.column]?.name;
|
|
465
496
|
}
|
|
466
497
|
function attachSyncRegistrySchema(registry, schema) {
|
|
467
498
|
const normalizedSchema = normalizeSchemaName(schema);
|
|
@@ -496,6 +527,40 @@ function getSyncRegistrySchema(registry) {
|
|
|
496
527
|
const schema = Reflect.get(registry, syncRegistrySchemaSymbol);
|
|
497
528
|
return typeof schema === "string" && schema.length > 0 ? schema : "public";
|
|
498
529
|
}
|
|
530
|
+
function attachSyncRegistryStorage(registry, storage) {
|
|
531
|
+
if (storage == null) {
|
|
532
|
+
return registry;
|
|
533
|
+
}
|
|
534
|
+
const existing = getSyncRegistryStorage(registry);
|
|
535
|
+
if (existing != null) {
|
|
536
|
+
if (existing.backend !== storage.backend || existing.durability !== storage.durability) {
|
|
537
|
+
throw new Error(`conflicting storage declaration for registry: already ${JSON.stringify(existing)}, cannot re-declare ` + `${JSON.stringify(storage)}`);
|
|
538
|
+
}
|
|
539
|
+
return registry;
|
|
540
|
+
}
|
|
541
|
+
Object.defineProperty(registry, syncRegistryStorageSymbol, {
|
|
542
|
+
value: storage,
|
|
543
|
+
enumerable: false,
|
|
544
|
+
configurable: false,
|
|
545
|
+
writable: false
|
|
546
|
+
});
|
|
547
|
+
return registry;
|
|
548
|
+
}
|
|
549
|
+
function getSyncRegistryStorage(registry) {
|
|
550
|
+
const storage = Reflect.get(registry, syncRegistryStorageSymbol);
|
|
551
|
+
return storage != null && typeof storage === "object" ? storage : undefined;
|
|
552
|
+
}
|
|
553
|
+
function validateStorageDeclaration(storage) {
|
|
554
|
+
if (storage == null) {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (storage.backend !== undefined && !isStorageBackend(storage.backend)) {
|
|
558
|
+
throw new Error(`invalid storage.backend "${String(storage.backend)}": must be one of ${STORAGE_BACKENDS.join(", ")}`);
|
|
559
|
+
}
|
|
560
|
+
if (storage.durability !== undefined && !isStorageDurability(storage.durability)) {
|
|
561
|
+
throw new Error(`invalid storage.durability "${String(storage.durability)}": must be one of ${STORAGE_DURABILITIES.join(", ")}`);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
499
564
|
function isSyncRegistryDefinition(input) {
|
|
500
565
|
return typeof input === "object" && input !== null && "tables" in input && typeof input.tables === "object" && input.tables !== null;
|
|
501
566
|
}
|
|
@@ -529,7 +594,11 @@ function validateSyncTableEntry(entry) {
|
|
|
529
594
|
if (entry.writeMode === "pessimistic" && entry.mode === "readonly") {
|
|
530
595
|
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
596
|
}
|
|
597
|
+
const managedFieldPropertyKeys = new Set(Object.keys(getColumns(entry.table)));
|
|
532
598
|
for (const field of entry.governance?.managedFields ?? []) {
|
|
599
|
+
if (!managedFieldPropertyKeys.has(field.column)) {
|
|
600
|
+
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)`);
|
|
601
|
+
}
|
|
533
602
|
if (field.strategy === "authClaim") {
|
|
534
603
|
if (!Array.isArray(field.claimPath) || field.claimPath.length === 0) {
|
|
535
604
|
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,10 +1494,12 @@ function buildGrantScopeShapeWhere(scopeColumn, ids) {
|
|
|
1425
1494
|
export {
|
|
1426
1495
|
withRetention,
|
|
1427
1496
|
unixMicrosecondsSchema,
|
|
1497
|
+
syncRegistryStorageSymbol,
|
|
1428
1498
|
syncRegistrySchemaSymbol,
|
|
1429
1499
|
supabaseOwnerOrAdminDefaults,
|
|
1430
1500
|
summarizeRegistryDiff,
|
|
1431
1501
|
runRegistryCheck,
|
|
1502
|
+
resolveStorageDeclaration,
|
|
1432
1503
|
resolveServerVersionColumnName,
|
|
1433
1504
|
resolveGrantScopeIds,
|
|
1434
1505
|
quoteSqlLiteral,
|
|
@@ -1444,10 +1515,13 @@ export {
|
|
|
1444
1515
|
jwtClaimsSchema,
|
|
1445
1516
|
isWriteMode,
|
|
1446
1517
|
isSubscriptionTiming,
|
|
1518
|
+
isStorageDurability,
|
|
1519
|
+
isStorageBackend,
|
|
1447
1520
|
isRetention,
|
|
1448
1521
|
isConflictPolicy,
|
|
1449
1522
|
isClaimsDependentRowFilter,
|
|
1450
1523
|
hashString,
|
|
1524
|
+
getSyncRegistryStorage,
|
|
1451
1525
|
getSyncRegistrySchema,
|
|
1452
1526
|
getProjectedColumns,
|
|
1453
1527
|
getProjectedColumnNames,
|
|
@@ -1480,7 +1554,6 @@ export {
|
|
|
1480
1554
|
buildSupabaseOwnerOrAdminNativePolicies,
|
|
1481
1555
|
buildSupabaseMembershipNativePolicies,
|
|
1482
1556
|
buildSupabaseGrantScopeNativePolicies,
|
|
1483
|
-
buildRowFilterWhere,
|
|
1484
1557
|
buildRowFilterShape,
|
|
1485
1558
|
buildRegistryLock,
|
|
1486
1559
|
buildOwnershipShapeWhere,
|
|
@@ -1490,12 +1563,17 @@ export {
|
|
|
1490
1563
|
batchMutationErrorSchema,
|
|
1491
1564
|
batchMutationAckSchema,
|
|
1492
1565
|
authoritativeWriteRequestSchema,
|
|
1566
|
+
attachSyncRegistryStorage,
|
|
1493
1567
|
attachSyncRegistrySchema,
|
|
1568
|
+
assertStorageDeclarationCompatible,
|
|
1494
1569
|
assertReadContractPreserved,
|
|
1495
1570
|
asReadonly,
|
|
1496
1571
|
asEphemeral,
|
|
1497
1572
|
WRITE_MODES,
|
|
1573
|
+
StorageDeclarationRefusedError,
|
|
1498
1574
|
SUBSCRIPTION_TIMINGS,
|
|
1575
|
+
STORAGE_DURABILITIES,
|
|
1576
|
+
STORAGE_BACKENDS,
|
|
1499
1577
|
RETENTIONS,
|
|
1500
1578
|
NOW_MICROSECONDS_SQL_TEXT,
|
|
1501
1579
|
DENY_ALL,
|
|
@@ -1504,4 +1582,4 @@ export {
|
|
|
1504
1582
|
CLOCK_US_CALL_SQL_TEXT
|
|
1505
1583
|
};
|
|
1506
1584
|
|
|
1507
|
-
//# debugId=
|
|
1585
|
+
//# debugId=7579888044BDBAD564756E2164756E21
|