@pgxsinkit/contracts 0.2.7 → 0.5.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/LICENSE +21 -0
- package/dist/apply-strategy.d.ts +13 -1
- package/dist/apply-strategy.d.ts.map +1 -1
- package/dist/config.d.ts +256 -87
- package/dist/config.d.ts.map +1 -1
- package/dist/convergence-model.d.ts +2 -2
- package/dist/convergence-model.d.ts.map +1 -1
- package/dist/event-stream.d.ts +1 -1
- package/dist/fingerprint.d.ts +31 -11
- package/dist/fingerprint.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +480 -202
- package/dist/index.js.map +16 -14
- package/dist/predicate.d.ts +162 -0
- package/dist/predicate.d.ts.map +1 -0
- package/dist/projection.d.ts +2 -2
- package/dist/projection.d.ts.map +1 -1
- package/dist/registry-diff.d.ts.map +1 -1
- package/dist/registry-invariant.d.ts +26 -14
- package/dist/registry-invariant.d.ts.map +1 -1
- package/dist/registry.d.ts +74 -48
- package/dist/registry.d.ts.map +1 -1
- package/dist/sql-role-guard.d.ts +1 -1
- package/dist/stream-envelope.d.ts +84 -0
- package/dist/stream-envelope.d.ts.map +1 -0
- package/dist/supabase-rls.d.ts +32 -36
- package/dist/supabase-rls.d.ts.map +1 -1
- package/package.json +3 -2
- package/skills/registry-authoring/SKILL.md +185 -185
- package/skills/registry-authoring/references/storage-engine-and-build.md +29 -0
- package/src/apply-strategy.ts +23 -4
- package/src/config.ts +340 -116
- package/src/convergence-model.ts +2 -2
- package/src/event-stream.ts +1 -1
- package/src/fingerprint.ts +76 -14
- package/src/index.ts +2 -0
- package/src/predicate.ts +274 -0
- package/src/projection.ts +6 -2
- package/src/registry-diff.ts +15 -4
- package/src/registry-invariant.ts +34 -19
- package/src/registry.ts +324 -78
- package/src/sql-role-guard.ts +1 -1
- package/src/stream-envelope.ts +91 -0
- package/src/supabase-rls.ts +76 -74
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.
|
package/dist/apply-strategy.d.ts
CHANGED
|
@@ -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
|
|
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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AnyColumn } from "drizzle-orm";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { type Predicate } from "./predicate";
|
|
3
4
|
export type TableMode = "readonly" | "writeonly" | "readwrite";
|
|
4
5
|
/**
|
|
5
6
|
* The per-writable-table Conflict policy (ADR-0015): what happens to a **stale** write — one whose
|
|
@@ -23,7 +24,7 @@ export declare const CONFLICT_POLICIES: readonly ["last-write-wins", "reject-if-
|
|
|
23
24
|
/** Type guard: is `value` one of the v1 {@link ConflictPolicy} values? */
|
|
24
25
|
export declare function isConflictPolicy(value: unknown): value is ConflictPolicy;
|
|
25
26
|
/**
|
|
26
|
-
* Subscription timing for a synced table (ADR-0021): **when** its
|
|
27
|
+
* Subscription timing for a synced table (ADR-0021): **when** its read-path shape subscribes.
|
|
27
28
|
*
|
|
28
29
|
* - `eager` (default) — subscribed in the boot set, as today.
|
|
29
30
|
* - `lazy` — excluded from boot; subscribed on first query-reference. With `persistent` retention,
|
|
@@ -31,7 +32,8 @@ export declare function isConflictPolicy(value: unknown): value is ConflictPolic
|
|
|
31
32
|
* sessions; with `ephemeral` retention it is session-scoped.
|
|
32
33
|
*
|
|
33
34
|
* A property of the **consistency group**: every table sharing a `consistencyGroup` must agree, since
|
|
34
|
-
* a group
|
|
35
|
+
* a group's streams commit atomically together — all up-to-date, then one transaction (ADR-0056) — so
|
|
36
|
+
* it cannot be partly lazy (ADR-0021 §4).
|
|
35
37
|
*/
|
|
36
38
|
export type SubscriptionTiming = "eager" | "lazy";
|
|
37
39
|
/** The {@link SubscriptionTiming} values. Source of truth for registry validation. */
|
|
@@ -41,7 +43,7 @@ export declare function isSubscriptionTiming(value: unknown): value is Subscript
|
|
|
41
43
|
/**
|
|
42
44
|
* Retention for a synced table (ADR-0021): **whether** its local copy is durable.
|
|
43
45
|
*
|
|
44
|
-
* - `persistent` (default) — the durable
|
|
46
|
+
* - `persistent` (default) — the durable pgwasm backend with a resumable subscription-state.
|
|
45
47
|
* - `ephemeral` — the table's whole per-table local cluster (read cache, overlay, journal, sequence,
|
|
46
48
|
* views, reconcile trigger/function) is emitted as `TEMP`, so reads **and** writes leave no durable
|
|
47
49
|
* trace. Consequence: no durable offline write queue — pair a must-not-lose write with a pessimistic
|
|
@@ -102,6 +104,49 @@ export type StorageDurability = "relaxed" | "strict";
|
|
|
102
104
|
export declare const STORAGE_DURABILITIES: readonly ["relaxed", "strict"];
|
|
103
105
|
/** Type guard: is `value` a {@link StorageDurability}? */
|
|
104
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;
|
|
105
150
|
/**
|
|
106
151
|
* The registry's storage contract (ADR-0049 decision 1, ADR-0047). Storage is PART OF THE DATA CONTRACT:
|
|
107
152
|
* whether losing the last not-yet-flushed action is acceptable, and whether OPFS may be used at all, is
|
|
@@ -112,19 +157,33 @@ export declare function isStorageDurability(value: unknown): value is StorageDur
|
|
|
112
157
|
* to contradict it; a capability fallback keeps the declared mode. A no-op on `memory` clones.
|
|
113
158
|
* - {@link StorageBackend backend} defaults to `"opfs"` and scopes the BROWSER store only; Node/`file` and
|
|
114
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.
|
|
115
167
|
*/
|
|
116
168
|
export interface SyncStorageDeclaration {
|
|
117
169
|
backend?: StorageBackend;
|
|
118
170
|
durability?: StorageDurability;
|
|
171
|
+
build?: StorageBuild;
|
|
172
|
+
engine?: StorageEngineDeclaration;
|
|
119
173
|
}
|
|
120
174
|
/**
|
|
121
175
|
* A {@link SyncStorageDeclaration} with every field resolved (ADR-0050) — the store's BOUND declaration.
|
|
122
176
|
* Produced once per store by {@link resolveStorageDeclaration} and immutable for the store's lifetime: a
|
|
123
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".
|
|
124
181
|
*/
|
|
125
182
|
export interface ResolvedStorageDeclaration {
|
|
126
183
|
backend: StorageBackend;
|
|
127
184
|
durability: StorageDurability;
|
|
185
|
+
build: StorageBuild;
|
|
186
|
+
engine?: StorageEngineDeclaration;
|
|
128
187
|
}
|
|
129
188
|
/**
|
|
130
189
|
* A storage declaration was refused (ADR-0050): two sources explicitly disagree on a field, or a later
|
|
@@ -135,18 +194,50 @@ export interface ResolvedStorageDeclaration {
|
|
|
135
194
|
export declare class StorageDeclarationRefusedError extends Error {
|
|
136
195
|
constructor(message: string);
|
|
137
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
|
+
}
|
|
138
221
|
/**
|
|
139
222
|
* Resolve a store's storage declaration from its two sources (ADR-0050): the registry-attached STATIC
|
|
140
223
|
* declaration (authoritative) and the tab's WIRE declaration (honoured only where the registry is silent).
|
|
141
224
|
* Per field: an unset field is "no opinion" and can never conflict; both explicit and disagreeing is a
|
|
142
225
|
* {@link StorageDeclarationRefusedError}; unresolved fields take the capability defaults
|
|
143
|
-
* (`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.
|
|
144
230
|
*/
|
|
145
231
|
export declare function resolveStorageDeclaration(staticDeclaration: SyncStorageDeclaration | undefined, wireDeclaration: SyncStorageDeclaration | undefined): ResolvedStorageDeclaration;
|
|
146
232
|
/**
|
|
147
233
|
* Check a LATER declaration against a store's bound resolution (ADR-0050): an unset or equal field is
|
|
148
234
|
* idempotent; an explicit field disagreeing with the bound value is a {@link StorageDeclarationRefusedError}.
|
|
149
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.)
|
|
150
241
|
*/
|
|
151
242
|
export declare function assertStorageDeclarationCompatible(bound: ResolvedStorageDeclaration, incoming: SyncStorageDeclaration | undefined): void;
|
|
152
243
|
/**
|
|
@@ -171,23 +262,83 @@ export interface ShapeSpec {
|
|
|
171
262
|
/**
|
|
172
263
|
* INTERNAL / resolved — the physical Postgres table this shape reads, when it differs from the
|
|
173
264
|
* shape's own `tableName`. A read PROJECTION (`defineReadProjection`) sets it to the OWNING table's
|
|
174
|
-
* name so several shapes can read one physical table under distinct `shapeKey`s; the
|
|
175
|
-
* an incoming
|
|
176
|
-
* `table`
|
|
265
|
+
* name so several shapes can read one physical table under distinct `shapeKey`s; the control plane
|
|
266
|
+
* resolves an incoming subscription by `shapeKey` and consults this only when it creates the shape, as
|
|
267
|
+
* the source `table` it hands the engine. `attachSyncRegistrySchema` also fills/qualifies it for
|
|
268
|
+
* schema-bound registries.
|
|
177
269
|
*
|
|
178
270
|
* Not a consumer input — there is no valid reason to hand-set it (it can only be redundant with, or
|
|
179
271
|
* wrong about, the table you are reading), so it is omitted from {@link ShapeSpecInput}. The
|
|
180
272
|
* combinator derives it from the owner; `defineSyncTable` never sets it from input.
|
|
181
273
|
*/
|
|
182
|
-
|
|
274
|
+
physicalTable?: string;
|
|
183
275
|
rowFilter?: RowFilterSpec;
|
|
276
|
+
/**
|
|
277
|
+
* SHARED TIER (ADR-0055) — the scope columns, resolved to column names, whose values key this
|
|
278
|
+
* shape family. The predicate is *generated* as an `AND` of equalities over them, so disjointness
|
|
279
|
+
* is a property of the construction rather than something a checker has to enforce: a row carries
|
|
280
|
+
* exactly one value per scope column, so it falls in exactly one shape of the family, and an
|
|
281
|
+
* overlapping pair is not expressible at all.
|
|
282
|
+
*
|
|
283
|
+
* `NULL` is a legal scope value and compiles to `IS NULL` — which is how an offering-wide row gets
|
|
284
|
+
* its own scope `(O, null)` rather than appearing in every group's shape. The tempting
|
|
285
|
+
* `group_id IS NULL OR group_id = $G` form is not merely disallowed here; it is wrong, because it
|
|
286
|
+
* places one row in every group shape at once.
|
|
287
|
+
*
|
|
288
|
+
* Its presence is what makes this a shared-tier shape. Declaring it alongside `rowFilter` is
|
|
289
|
+
* refused at definition time — see {@link readShapeTier}.
|
|
290
|
+
*/
|
|
291
|
+
scope?: readonly string[];
|
|
292
|
+
/**
|
|
293
|
+
* The **static** half of the shape's predicate: subscriber-independent, identical for every
|
|
294
|
+
* reader, and therefore safe in either tier. On the shared tier it is conjoined with the generated
|
|
295
|
+
* scope equalities; on the private tier, with whatever `rowFilter` resolves to for the subject.
|
|
296
|
+
*
|
|
297
|
+
* Native AST, not SQL text — see {@link Predicate}.
|
|
298
|
+
*/
|
|
299
|
+
where?: Predicate;
|
|
184
300
|
}
|
|
301
|
+
/** Which read tier a shape belongs to (ADR-0055 decision 2). */
|
|
302
|
+
export type ShapeTier = "shared" | "private";
|
|
303
|
+
/**
|
|
304
|
+
* The tier a shape declares, or a refusal.
|
|
305
|
+
*
|
|
306
|
+
* The tier is not configured; it is *read off* which field the author declared — `scope` for shared,
|
|
307
|
+
* `rowFilter` for private. That makes a shape's tier evident from its authoring and impossible to
|
|
308
|
+
* leave ambiguous, which matters because the two differ in whether their bytes are user-independent,
|
|
309
|
+
* and so in whether they may be shared and cached at all.
|
|
310
|
+
*
|
|
311
|
+
* Declaring both is refused rather than resolved by precedence. A `rowFilter` fuses the subject into
|
|
312
|
+
* the predicate, which is exactly what makes a stream unshareable; silently letting it ride along on
|
|
313
|
+
* a shape declared as shared would produce a stream that is cached under a scope key while carrying
|
|
314
|
+
* subject-dependent bytes — a disclosure, not a stale row.
|
|
315
|
+
*/
|
|
316
|
+
export declare function readShapeTier(shape: ShapeSpec): ShapeTier;
|
|
317
|
+
/**
|
|
318
|
+
* Refuse a shape whose `rowFilter` cannot actually filter.
|
|
319
|
+
*
|
|
320
|
+
* The control plane compiles a private-tier shape from `customPredicate` alone, so a filter that does
|
|
321
|
+
* not supply one is created with no subject test and streams **every** row to whoever subscribed. That
|
|
322
|
+
* is the precise shape of a silent authorization bypass: the registry says "filtered", the wire says
|
|
323
|
+
* "all rows", and nothing anywhere reports a discrepancy.
|
|
324
|
+
*
|
|
325
|
+
* The way to land there is a `rowFilter` that filters nothing at all — no predicate and no column
|
|
326
|
+
* allow-list — so it asserts a restriction it does not carry. (A filter holding *only* `columns` is
|
|
327
|
+
* legitimate: that is how `defineReadProjection` narrows a projection's wire columns without
|
|
328
|
+
* restricting its rows.)
|
|
329
|
+
*
|
|
330
|
+
* Refused at DEFINITION time, not at the first subscribe: declaring a `rowFilter` asserts that these
|
|
331
|
+
* rows are not for everyone, and there is no input for which a filter that cannot run could later turn
|
|
332
|
+
* out to be fine. A shape that genuinely serves every row omits `rowFilter` entirely — the difference
|
|
333
|
+
* between "no filter" and "a filter that does nothing" is exactly what this keeps expressible.
|
|
334
|
+
*/
|
|
335
|
+
export declare function assertShapeFilterIsEnforceable(shape: ShapeSpec): void;
|
|
185
336
|
/** Input variant of {@link ShapeSpec} where `tableName` and `shapeKey` are optional.
|
|
186
337
|
* When omitted, both default to the top-level `tableName` of the `defineSyncTable` call.
|
|
187
|
-
* `
|
|
188
|
-
* (see {@link ShapeSpec.
|
|
338
|
+
* `physicalTable` is deliberately absent — it is a resolved/internal field, never a consumer input
|
|
339
|
+
* (see {@link ShapeSpec.physicalTable}); a read projection over an existing table is authored with
|
|
189
340
|
* `defineReadProjection`, which derives it from the owner. */
|
|
190
|
-
export type ShapeSpecInput = Omit<ShapeSpec, "tableName" | "shapeKey" | "
|
|
341
|
+
export type ShapeSpecInput = Omit<ShapeSpec, "tableName" | "shapeKey" | "physicalTable"> & {
|
|
191
342
|
tableName?: string;
|
|
192
343
|
shapeKey?: string;
|
|
193
344
|
};
|
|
@@ -197,32 +348,71 @@ export interface RowTransformContext {
|
|
|
197
348
|
params?: Record<string, unknown>;
|
|
198
349
|
}
|
|
199
350
|
/**
|
|
200
|
-
* Per-row rewrite applied
|
|
201
|
-
* column omission). Receives a
|
|
351
|
+
* Per-row rewrite applied on the server's read egress path (after the row filter, before
|
|
352
|
+
* column omission). Receives a streamed row's column map (keys are wire/column names)
|
|
202
353
|
* and returns a possibly-rewritten one — letting the server strip a *sub-document* of a
|
|
203
354
|
* jsonb column, or otherwise rewrite a value, *conditionally on row data*. This expresses
|
|
204
355
|
* what a static, whole-column `omitColumns` cannot.
|
|
205
356
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
357
|
+
* Server authority only: it never alters the local pgwasm schema and never alters the shape
|
|
358
|
+
* definition — the engine ref-counts shapes by definition (ADR-0055), so a transform can
|
|
359
|
+
* neither change which stream a subject reads nor split one that would otherwise be shared.
|
|
360
|
+
* Return the same `row` reference to signal "no change".
|
|
209
361
|
*/
|
|
210
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
|
+
}
|
|
211
385
|
export interface ClientProjectionSpec {
|
|
212
386
|
syncedTable?: string;
|
|
213
387
|
overlayTable?: string;
|
|
214
388
|
journalTable?: string;
|
|
215
389
|
omitColumns?: readonly string[];
|
|
216
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[];
|
|
217
407
|
}
|
|
218
408
|
/**
|
|
219
|
-
* Server-side projection applied
|
|
220
|
-
* authority, not client shape — it never alters the local
|
|
221
|
-
*
|
|
409
|
+
* Server-side projection applied on the read egress path. This is server
|
|
410
|
+
* authority, not client shape — it never alters the local pgwasm schema or the
|
|
411
|
+
* shape definition — so it lives apart from {@link ClientProjectionSpec} (ADR-0004).
|
|
222
412
|
*/
|
|
223
413
|
export interface ServerProjectionSpec {
|
|
224
414
|
/**
|
|
225
|
-
* Optional per-row rewrite applied
|
|
415
|
+
* Optional per-row rewrite applied on the read egress path. Runs before column
|
|
226
416
|
* omission, so it may read a column (e.g. a control flag) that
|
|
227
417
|
* `clientProjection.omitColumns` then removes from the client-visible row. See
|
|
228
418
|
* {@link RowTransform}.
|
|
@@ -277,8 +467,9 @@ export interface TableSpecInput {
|
|
|
277
467
|
clientProjection?: ClientProjectionSpec;
|
|
278
468
|
governance?: TableGovernanceSpec;
|
|
279
469
|
/**
|
|
280
|
-
* Consistency group (ADR-0009 decision 2): tables sharing a group sync on one
|
|
281
|
-
*
|
|
470
|
+
* Consistency group (ADR-0009 decision 2): tables sharing a group sync on one set of streams and
|
|
471
|
+
* commit atomically — every stream up-to-date, then one transaction (ADR-0056). Absent → the table is
|
|
472
|
+
* its own singleton group.
|
|
282
473
|
*/
|
|
283
474
|
consistencyGroup?: string;
|
|
284
475
|
/**
|
|
@@ -298,11 +489,6 @@ export interface TableSpecInput {
|
|
|
298
489
|
*/
|
|
299
490
|
writeMode?: WriteMode;
|
|
300
491
|
}
|
|
301
|
-
export interface SyncConfigInput<TTables extends Record<string, TableSpecInput> = Record<string, TableSpecInput>> {
|
|
302
|
-
electricUrl: string;
|
|
303
|
-
localSchema?: string;
|
|
304
|
-
tables: TTables;
|
|
305
|
-
}
|
|
306
492
|
export declare function getLocalSyncPrimaryKey(source: {
|
|
307
493
|
primaryKey: PrimaryKeySpec;
|
|
308
494
|
clientProjection?: Pick<ClientProjectionSpec, "localPrimaryKey">;
|
|
@@ -313,86 +499,69 @@ export declare function getLocalSyncPrimaryKeyColumns(source: {
|
|
|
313
499
|
}): string[];
|
|
314
500
|
export interface RowFilterSpec {
|
|
315
501
|
/**
|
|
316
|
-
* The row filter:
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
* embed request-derived values directly — they become **bound `$n` params**, never hand-escaped
|
|
320
|
-
* literals. Enum columns must be cast to text (`${c(col)}::text = 'x'`) for Electric's grammar,
|
|
321
|
-
* and subqueries must be self-contained (not correlated), since Electric needs plain column refs.
|
|
502
|
+
* The PRIVATE-TIER row filter (ADR-0055): the predicate fused with the caller's claims, compiled
|
|
503
|
+
* into the shape at subscribe. `null` bypasses filtering (all rows); {@link DENY_ALL_PREDICATE}
|
|
504
|
+
* denies.
|
|
322
505
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
506
|
+
* Authored with the `p.*` builders over real Drizzle column objects, so a comparison is checked
|
|
507
|
+
* against the column's own TypeScript type — a mistyped enum label, a `null` against a NOT NULL
|
|
508
|
+
* column, or a `jsonb`/`Date` column with no scalar wire form are all compile errors rather than
|
|
509
|
+
* silently-wrong filters.
|
|
327
510
|
*
|
|
328
|
-
* **Must be pure
|
|
329
|
-
*
|
|
330
|
-
* {@link isClaimsDependentRowFilter}). Do not memoize, mutate external state, or assume it runs once.
|
|
511
|
+
* **Must be pure**: it is called fresh per shape creation, and probed with empty claims to detect
|
|
512
|
+
* claims-dependence (ADR-0039 — {@link isClaimsDependentRowFilter}).
|
|
331
513
|
*/
|
|
332
|
-
|
|
514
|
+
customPredicate?: (claims: JwtClaims, params?: Record<string, unknown>) => Predicate | null;
|
|
333
515
|
/** Column projection for the shape URL (e.g. ["id", "source_text"]). */
|
|
334
516
|
columns?: string[];
|
|
335
517
|
/**
|
|
336
|
-
* An opaque version tag for the part of this filter the fingerprint cannot see — the
|
|
337
|
-
* body (you cannot hash a closure; only its *presence* is fingerprinted). Bump
|
|
338
|
-
* string/number) whenever you change that logic so the fingerprint shifts and the
|
|
339
|
-
* rebuilds + the shape subscription resets. Leaving it unchanged after a
|
|
340
|
-
* authorization change would silently serve the stale shape.
|
|
518
|
+
* An opaque version tag for the part of this filter the fingerprint cannot see — the
|
|
519
|
+
* `customPredicate` body (you cannot hash a closure; only its *presence* is fingerprinted). Bump
|
|
520
|
+
* this (any new string/number) whenever you change that logic so the fingerprint shifts and the
|
|
521
|
+
* local read cache rebuilds + the shape subscription resets. Leaving it unchanged after a
|
|
522
|
+
* `customPredicate` authorization change would silently serve the stale shape.
|
|
341
523
|
*/
|
|
342
524
|
revision?: string | number;
|
|
343
525
|
}
|
|
344
526
|
/**
|
|
345
|
-
*
|
|
346
|
-
* `"work_items"."workspace_id"`. Electric's shape `where` grammar requires *plain* column references
|
|
347
|
-
* (it rejects a qualified one with "Expected a plain column reference"), and Drizzle qualifies columns
|
|
348
|
-
* by default — so reference columns through `c()` when authoring a `customWhere` Drizzle fragment. The
|
|
349
|
-
* column object keeps the reference rename-safe and existence-checked at compile time; only the bare
|
|
350
|
-
* name reaches the wire. Subqueries must stay self-contained (not correlated), since bare names then
|
|
351
|
-
* resolve unambiguously to each FROM — a correlated subquery would need qualification Electric rejects.
|
|
352
|
-
*/
|
|
353
|
-
export declare function c(column: AnyColumn): SQL;
|
|
354
|
-
/**
|
|
355
|
-
* The deny-all row filter: a `customWhere` returns this to make **no** rows visible (e.g. an
|
|
527
|
+
* The deny-all predicate: a `customPredicate` returns this to make **no** rows visible (e.g. an
|
|
356
528
|
* unauthenticated request), the counterpart to returning `null` (which bypasses filtering — all rows
|
|
357
|
-
* visible).
|
|
358
|
-
*
|
|
359
|
-
*
|
|
529
|
+
* visible).
|
|
530
|
+
*
|
|
531
|
+
* An empty `OR` rather than a synthetic always-false comparison: the engine evaluates it as FALSE by
|
|
532
|
+
* construction (`Or` starts at FALSE and only TRUE dominates), it needs no column to name, and it
|
|
533
|
+
* cannot be made accidentally true by a NULL cell the way `col <> col` can.
|
|
534
|
+
*
|
|
535
|
+
* The control plane recognises it **by reference identity** and declines to create the shape at all,
|
|
536
|
+
* so a denied subject holds no handle and no stream is materialised — a stronger outcome than an
|
|
537
|
+
* empty stream, and the reason this is a frozen singleton rather than a shape a caller might
|
|
538
|
+
* reconstruct. A structurally equal but distinct `{ or: [] }` is still correct on the wire; it just
|
|
539
|
+
* costs an empty shape instead of a refusal.
|
|
360
540
|
*/
|
|
361
|
-
export declare const
|
|
541
|
+
export declare const DENY_ALL_PREDICATE: Predicate;
|
|
362
542
|
/**
|
|
363
543
|
* Whether a row filter denies (or cannot serve) an unauthenticated caller — a *claims-dependent*
|
|
364
544
|
* filter (ADR-0039). The client probes this at lazy-group activation: a group whose members probe
|
|
365
545
|
* claims-dependent, activated with no auth token, opens an empty subscription by construction, so
|
|
366
546
|
* the client warns.
|
|
367
547
|
*
|
|
368
|
-
* A filter is claims-dependent when its `
|
|
369
|
-
* exactly what the
|
|
370
|
-
* returns the {@link
|
|
371
|
-
* {@link
|
|
372
|
-
* the documented deny-anonymous pattern). Any other result — `null` (no
|
|
373
|
-
* different
|
|
548
|
+
* A filter is claims-dependent when its `customPredicate`, evaluated with **empty claims** (`{}` —
|
|
549
|
+
* exactly what the control plane passes for an unauthenticated request) and no params, either
|
|
550
|
+
* **throws** or returns the {@link DENY_ALL_PREDICATE} sentinel by **reference identity** (which every
|
|
551
|
+
* contracts helper — {@link buildOwnershipShapePredicate} and friends — returns for a missing subject,
|
|
552
|
+
* and which is already the documented deny-anonymous pattern). Any other result — `null` (no
|
|
553
|
+
* filtering) or a different predicate — is not claims-dependent as far as this probe can tell.
|
|
374
554
|
*
|
|
375
|
-
* Requires `
|
|
555
|
+
* Requires `customPredicate` to be pure (its contract; see {@link RowFilterSpec.customPredicate}).
|
|
376
556
|
*/
|
|
377
557
|
export declare function isClaimsDependentRowFilter(filter: RowFilterSpec | undefined): boolean;
|
|
378
558
|
/**
|
|
379
|
-
* The ownership
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
|
|
385
|
-
export declare function buildOwnershipShapeWhere(ownerColumn: AnyColumn, subject: string | null | undefined): SQL;
|
|
386
|
-
/** The parameterized shape filter the proxy sends to Electric: a `where` and its positional params. */
|
|
387
|
-
export interface RowFilterShape {
|
|
388
|
-
where: string;
|
|
389
|
-
params: string[];
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* The shape filter the proxy sends to Electric: the `where` plus its positional `params` (`$1`, `$2`,
|
|
393
|
-
* …). A `customWhere` returning a Drizzle `SQL` fragment is serialized here, so request-derived values
|
|
394
|
-
* become **bound params** — never hand-escaped literals; a string `customWhere` is the raw escape
|
|
395
|
-
* hatch (no params). Returns `null` when there is no filter (all rows visible).
|
|
559
|
+
* The ownership **predicate** the read path filters on: rows whose owner column equals the caller's
|
|
560
|
+
* subject, {@link DENY_ALL_PREDICATE} for an unauthenticated caller (by reference, so a
|
|
561
|
+
* `customPredicate` built on it probes claims-dependent).
|
|
562
|
+
*
|
|
563
|
+
* Takes the real Drizzle owner column, so the reference is rename-safe, and the subject rides as a
|
|
564
|
+
* typed JSON scalar rather than text that has to be escaped and re-parsed.
|
|
396
565
|
*/
|
|
397
|
-
export declare function
|
|
566
|
+
export declare function buildOwnershipShapePredicate(ownerColumn: AnyColumn, subject: string | null | undefined): Predicate;
|
|
398
567
|
//# sourceMappingURL=config.d.ts.map
|
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,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAK,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,cAA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M,EAAE;IAC7C,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"}
|
|
@@ -85,10 +85,10 @@ export declare const CONVERGENCE_EVENTS: readonly [{
|
|
|
85
85
|
readonly event: "mutation acked";
|
|
86
86
|
readonly effect: "journal row → acked, server_updated_at_us stamped; entity shows acked_unobserved until the echo catches up";
|
|
87
87
|
}, {
|
|
88
|
-
readonly event: "
|
|
88
|
+
readonly event: "synced upsert observed";
|
|
89
89
|
readonly effect: "synced row applied; the barrier predicate runs; resolved entities clear overlay + acked journal";
|
|
90
90
|
}, {
|
|
91
|
-
readonly event: "
|
|
91
|
+
readonly event: "synced delete observed";
|
|
92
92
|
readonly effect: "resolved by synced-row absence (deletes carry no Server version — ADR-0010)";
|
|
93
93
|
}, {
|
|
94
94
|
readonly event: "resolution";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convergence-model.d.ts","sourceRoot":"","sources":["../src/convergence-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,qBAAqB,CAAC;AAEtE,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjF;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,SAAS,UAAU,EACrE,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,MAAM,CAWR;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,UAAU,EAC1D,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAC7B,UAAU,EAAE,uBAAuB,GAClC,MAAM,CA6DR;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;aAE3B,KAAK,EAAE,qCAAqC;aAC5C,MAAM,EAAE,0FAA0F;;aAElG,KAAK,EAAE,eAAe;aAAE,MAAM,EAAE,uBAAuB;;aAEvD,KAAK,EAAE,gBAAgB;aACvB,MAAM,EACJ,4GAA4G;;aAG9G,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"convergence-model.d.ts","sourceRoot":"","sources":["../src/convergence-model.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,oBAAoB;aAC3B,MAAM,EAAE,6FAA6F;EAE/F,CAAC"}
|
package/dist/event-stream.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export interface EventStreamEntry<TPayload extends z.ZodType = z.ZodType> {
|
|
|
69
69
|
identity: Record<string, EventStreamIdentityField>;
|
|
70
70
|
/**
|
|
71
71
|
* An opaque version counter for the part of this payload contract the lock's hash cannot see — the same
|
|
72
|
-
* role `RowFilterSpec.revision` plays for a `
|
|
72
|
+
* role `RowFilterSpec.revision` plays for a `customPredicate` closure. The lock hashes the payload schema as
|
|
73
73
|
* a **JSON Schema**, and refinements/transforms are simply not representable there: a reviewer
|
|
74
74
|
* demonstrated that `z.string().refine(v => v.length >= 3)` and the INCOMPATIBLE `>= 10` version produce
|
|
75
75
|
* the identical stream hash, so the `risky` diff the ADR relies on never fires.
|