@prisma-idb/sync-server 0.5.0 → 0.6.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/README.md +14 -0
- package/dist/server.d.mts +19 -4
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +94 -15
- package/dist/server.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,9 +17,23 @@ const syncServer = createSyncServer({
|
|
|
17
17
|
getKeyField: sqlGetKeyField, // for a SQL contract
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
// payloads use native application values (Date, bigint, Uint8Array).
|
|
20
21
|
const checks = syncServer.validatePush(events, { scopeKey: signedInUserId });
|
|
22
|
+
for (const { check } of checks) {
|
|
23
|
+
if (check.kind === "validation-failure") {
|
|
24
|
+
// Reject with check.error: RECORD_VALIDATION_FAILURE or KEYPATH_VALIDATION_FAILURE.
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
// Execute the ownership check using your database.
|
|
28
|
+
}
|
|
21
29
|
```
|
|
22
30
|
|
|
31
|
+
Records validate against the client projection and reject extra fields and undeclared enum values. Creates require all client-visible non-nullable fields; updates validate supplied fields, and deletes validate only keys. Validation failures occur before ownership paths are resolved. The server builds validators for every client-visible model at construction and throws with the model and codec ID if a validator is unavailable. Server-only models and fields are excluded from this check. Key validation and ownership checks use the full server contract. The server must fill required server-only fields before insertion; omitting them can still fail at the database boundary.
|
|
32
|
+
|
|
33
|
+
The default SQL lookup validates Date codecs (including legacy `pg/date@1`, `pg/timestamp@1`, `pg/timestamptz@1` and `sql/timestamp@1`), string date/time codecs, primitive scalars, JSON, bytes and text arrays against their application values. `pg/*-temporal@1` values are Temporal objects, and `pg/interval@1` values are `{ months, days, micros }` objects; neither has a default validator. Choose Date/string representations for synced date/time fields. Historical codec validation does not restore codecs removed from the installed SQL runtime: re-emit old contracts before using them with rc.12.
|
|
34
|
+
|
|
35
|
+
Other families can extend the exported `defaultValidationCodecs` with a `codecLookup` that returns supported application names: `string`, `string[]`, `number`, `boolean`, `bigint`, `Date`, `Uint8Array` or `unknown`. Names such as `Temporal.Instant` are rejected at construction. `unknown` deliberately skips scalar type checking and requires the caller to validate that codec's value before pushing; it is not a Temporal or interval validator.
|
|
36
|
+
|
|
23
37
|
For a SQL database, [`@prisma-idb/sync-server-sql`](https://www.npmjs.com/package/@prisma-idb/sync-server-sql) runs the checks and writes for you.
|
|
24
38
|
|
|
25
39
|
## Entry points
|
package/dist/server.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Contract } from "@prisma/orm-framework/contract/types";
|
|
2
|
+
import { ValidationCodecLookup } from "@prisma-idb/target-idb/runtime";
|
|
2
3
|
//#region src/core/ownership-dag.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* The contract shape `sync-server` operates on — any family's `Contract`
|
|
@@ -56,7 +57,10 @@ interface SyncPushEvent {
|
|
|
56
57
|
readonly id: string;
|
|
57
58
|
readonly model: string;
|
|
58
59
|
readonly operation: "create" | "update" | "delete";
|
|
60
|
+
/** Native application values used for contract validation. */
|
|
59
61
|
readonly payload: Record<string, unknown>;
|
|
62
|
+
/** Pre-revival payload; supply when native keys differ from their JSON wire form. */
|
|
63
|
+
readonly wirePayload?: Record<string, unknown>;
|
|
60
64
|
}
|
|
61
65
|
/**
|
|
62
66
|
* A changelog row pending pull; `key` is the row's own primary-key value.
|
|
@@ -101,10 +105,15 @@ type OwnershipCheck = {
|
|
|
101
105
|
*/
|
|
102
106
|
readonly paths: readonly (readonly string[])[];
|
|
103
107
|
};
|
|
108
|
+
type PushCheck = OwnershipCheck | {
|
|
109
|
+
readonly kind: "validation-failure";
|
|
110
|
+
readonly error: "RECORD_VALIDATION_FAILURE" | "KEYPATH_VALIDATION_FAILURE";
|
|
111
|
+
readonly issues: readonly string[];
|
|
112
|
+
};
|
|
104
113
|
interface PushValidationResult {
|
|
105
114
|
readonly eventId: string;
|
|
106
115
|
readonly model: string;
|
|
107
|
-
readonly check:
|
|
116
|
+
readonly check: PushCheck;
|
|
108
117
|
}
|
|
109
118
|
interface PullScopeResult {
|
|
110
119
|
readonly changelogId: string;
|
|
@@ -130,8 +139,9 @@ type GetKeyField = (contract: SyncServerContract, modelName: string) => string;
|
|
|
130
139
|
* `getKeyField` instead of silently misresolving.
|
|
131
140
|
*/
|
|
132
141
|
declare const defaultGetKeyField: GetKeyField;
|
|
133
|
-
declare function validatePush(dag: OwnershipDag, contract: SyncServerContract, getKeyField: GetKeyField, events: readonly SyncPushEvent[], options: {
|
|
142
|
+
declare function validatePush(dag: OwnershipDag, contract: SyncServerContract, clientContract: SyncServerContract, getKeyField: GetKeyField, events: readonly SyncPushEvent[], options: {
|
|
134
143
|
readonly scopeKey: string;
|
|
144
|
+
readonly codecLookup?: ValidationCodecLookup;
|
|
135
145
|
}): readonly PushValidationResult[];
|
|
136
146
|
declare function buildPullQueries(dag: OwnershipDag, contract: SyncServerContract, getKeyField: GetKeyField, logs: readonly SyncPullLogEntry[], options: {
|
|
137
147
|
readonly scopeKey: string;
|
|
@@ -139,11 +149,13 @@ declare function buildPullQueries(dag: OwnershipDag, contract: SyncServerContrac
|
|
|
139
149
|
interface CreateSyncServerOptions {
|
|
140
150
|
/** The full server-side contract (ADR 012) — includes client-excluded models. Any family. */
|
|
141
151
|
readonly contract: SyncServerContract;
|
|
142
|
-
/** The client-projected contract (ADR 012) — defines
|
|
152
|
+
/** The client-projected contract (ADR 012) — defines the synced models and fields to validate. Any family. */
|
|
143
153
|
readonly clientContract: SyncServerContract;
|
|
144
154
|
readonly rootModel: string;
|
|
145
155
|
/** @default defaultGetKeyField (IDB-shaped storage.keyPath) */
|
|
146
156
|
readonly getKeyField?: GetKeyField;
|
|
157
|
+
/** Native application types; unsupported validators throw at construction. */
|
|
158
|
+
readonly codecLookup?: ValidationCodecLookup;
|
|
147
159
|
}
|
|
148
160
|
interface SyncServer {
|
|
149
161
|
readonly rootModel: string;
|
|
@@ -162,5 +174,8 @@ interface SyncServer {
|
|
|
162
174
|
*/
|
|
163
175
|
declare function createSyncServer(options: CreateSyncServerOptions): SyncServer;
|
|
164
176
|
//#endregion
|
|
165
|
-
|
|
177
|
+
//#region src/core/validation-codecs.d.ts
|
|
178
|
+
declare const defaultValidationCodecs: ValidationCodecLookup;
|
|
179
|
+
//#endregion
|
|
180
|
+
export { type CreateSyncServerOptions, type GetKeyField, type OwnershipCheck, type OwnershipDag, type PullScopeResult, type PushCheck, type PushValidationResult, type SyncPullLogEntry, type SyncPushEvent, type SyncServer, type SyncServerContract, buildOwnershipDag, buildPullQueries, createSyncServer, defaultGetKeyField, defaultValidationCodecs, resolveAuthorizationPaths, validatePush };
|
|
166
181
|
//# sourceMappingURL=server.d.mts.map
|
package/dist/server.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/core/ownership-dag.ts","../src/core/authorization-paths.ts","../src/core/sync-server.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/core/ownership-dag.ts","../src/core/authorization-paths.ts","../src/core/sync-server.ts","../src/core/validation-codecs.ts"],"mappings":";;;;;;;;;;;;KAYY,qBAAqB;;;;;;;UAQhB;WACN;WACA,OAAO,oBAAoB;;WAE3B,cAAc;;;;;;;;;;;;;;iBAeT,kBACd,UAAU,oBACV,gBAAgB,oBAChB,oBACC;;;;;;;;;;;;;;iBC7Ba,0BACd,UAAU,oBACV,mBACA;;;;UCRe;WACN;WACA;WACA;;WAEA,SAAS;;WAET,cAAc;;;;;;;;;;;;;UAcR;WACN;WACA;WACA;;;;;;;KAQC;WACG;;WAEA;WACA;WACA;WACA;;WAEA;;WAGA;WACA;WACA;WACA;WACA;;;;;;WAMA;;KAGH,YACR;WAEW;WACA;WACA;;UAGE;WACN;WACA;WACA,OAAO;;UAGD;WACN;WACA;WACA,OAAO;;;;;;;;;;;KAYN,eAAe,UAAU,oBAAoB;;;;;;;;;cAU5C,oBAAoB;iBAmCjB,aACd,KAAK,cACL,UAAU,oBACV,gBAAgB,oBAChB,aAAa,aACb,iBAAiB,iBACjB;WAAoB;WAA2B,cAAc;aACnD;iBA6CI,iBACd,KAAK,cACL,UAAU,oBACV,aAAa,aACb,eAAe,oBACf;WAAoB;aACV;UAaK;;WAEN,UAAU;;WAEV,gBAAgB;WAChB;;WAEA,cAAc;;WAEd,cAAc;;UAGR;WACN;;EAET,aACE,iBAAiB,iBACjB;aAAoB;eACV;;EAEZ,iBACE,eAAe,oBACf;aAAoB;eACV;;;;;;iBAOE,iBAAiB,SAAS,0BAA0B;;;cClMvD,yBAAyB"}
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { domainModelsAtDefaultNamespace } from "@prisma/orm-framework/contract/types";
|
|
2
|
+
import { assertRecordValidator, idbCodecLookup, validateKeyFields, validateRecord } from "@prisma-idb/target-idb/runtime";
|
|
2
3
|
//#region src/core/ownership-dag.ts
|
|
3
4
|
/**
|
|
4
5
|
* Builds the ownership DAG from the full server-side contract, walking
|
|
@@ -93,6 +94,56 @@ function resolveAuthorizationPaths(contract, rootModel, modelName) {
|
|
|
93
94
|
return paths.sort((a, b) => a.length - b.length || a.join(".").localeCompare(b.join(".")));
|
|
94
95
|
}
|
|
95
96
|
//#endregion
|
|
97
|
+
//#region src/core/validation-codecs.ts
|
|
98
|
+
const sqlApplicationTypes = {};
|
|
99
|
+
for (const name of [
|
|
100
|
+
"text",
|
|
101
|
+
"char",
|
|
102
|
+
"varchar"
|
|
103
|
+
]) sqlApplicationTypes[`sql/${name}@1`] = ["string"];
|
|
104
|
+
for (const name of ["int", "float"]) sqlApplicationTypes[`sql/${name}@1`] = ["number"];
|
|
105
|
+
for (const name of [
|
|
106
|
+
"text",
|
|
107
|
+
"enum",
|
|
108
|
+
"char",
|
|
109
|
+
"varchar",
|
|
110
|
+
"uuid",
|
|
111
|
+
"numeric",
|
|
112
|
+
"inet",
|
|
113
|
+
"bit",
|
|
114
|
+
"varbit",
|
|
115
|
+
"time",
|
|
116
|
+
"timetz",
|
|
117
|
+
"date-string",
|
|
118
|
+
"timestamp-string",
|
|
119
|
+
"timestamptz-string",
|
|
120
|
+
"time-string",
|
|
121
|
+
"tsquery"
|
|
122
|
+
]) sqlApplicationTypes[`pg/${name}@1`] = ["string"];
|
|
123
|
+
for (const name of [
|
|
124
|
+
"int",
|
|
125
|
+
"int2",
|
|
126
|
+
"int4",
|
|
127
|
+
"int8number",
|
|
128
|
+
"float",
|
|
129
|
+
"float4",
|
|
130
|
+
"float8"
|
|
131
|
+
]) sqlApplicationTypes[`pg/${name}@1`] = ["number"];
|
|
132
|
+
for (const name of ["int8", "unboundedint"]) sqlApplicationTypes[`pg/${name}@1`] = ["bigint"];
|
|
133
|
+
sqlApplicationTypes["pg/bool@1"] = ["boolean"];
|
|
134
|
+
for (const name of [
|
|
135
|
+
"date",
|
|
136
|
+
"timestamp",
|
|
137
|
+
"timestamptz",
|
|
138
|
+
"timestamptz-date"
|
|
139
|
+
]) sqlApplicationTypes[`pg/${name}@1`] = ["Date"];
|
|
140
|
+
sqlApplicationTypes["sql/timestamp@1"] = ["Date"];
|
|
141
|
+
sqlApplicationTypes["pg/text-array@1"] = ["string[]"];
|
|
142
|
+
sqlApplicationTypes["pg/bytea@1"] = ["Uint8Array"];
|
|
143
|
+
sqlApplicationTypes["pg/json@1"] = ["unknown"];
|
|
144
|
+
sqlApplicationTypes["pg/jsonb@1"] = ["unknown"];
|
|
145
|
+
const defaultValidationCodecs = { targetTypesFor: (id) => idbCodecLookup.targetTypesFor(id) ?? sqlApplicationTypes[id] };
|
|
146
|
+
//#endregion
|
|
96
147
|
//#region src/core/sync-server.ts
|
|
97
148
|
/**
|
|
98
149
|
* Default resolver: duck-types `model.storage.keyPath` as a string. This
|
|
@@ -124,22 +175,40 @@ function buildOwnershipCheck(dag, contract, getKeyField, modelName, keyField, ke
|
|
|
124
175
|
paths: resolveAuthorizationPaths(contract, dag.rootModel, modelName)
|
|
125
176
|
};
|
|
126
177
|
}
|
|
127
|
-
function validatePush(dag, contract, getKeyField, events, options) {
|
|
178
|
+
function validatePush(dag, contract, clientContract, getKeyField, events, options) {
|
|
128
179
|
const models = domainModelsAtDefaultNamespace(contract.domain);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
check: { kind: "unknown-model" }
|
|
134
|
-
};
|
|
180
|
+
const clientModels = domainModelsAtDefaultNamespace(clientContract.domain);
|
|
181
|
+
const codecLookup = options.codecLookup ?? defaultValidationCodecs;
|
|
182
|
+
function checkEvent(event) {
|
|
183
|
+
if (!dag.clientModels.has(event.model) || !models[event.model] || !clientModels[event.model]) return { kind: "unknown-model" };
|
|
135
184
|
const keyField = getKeyField(contract, event.model);
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
185
|
+
const keyValue = event.payload?.[keyField];
|
|
186
|
+
const keyResult = validateKeyFields(contract, event.model, { [keyField]: keyValue }, [keyField], { codecLookup });
|
|
187
|
+
if (!keyResult.ok) return {
|
|
188
|
+
kind: "validation-failure",
|
|
189
|
+
error: "KEYPATH_VALIDATION_FAILURE",
|
|
190
|
+
issues: keyResult.issues
|
|
141
191
|
};
|
|
142
|
-
|
|
192
|
+
if (event.operation !== "delete") {
|
|
193
|
+
const optionalFields = Object.entries(clientModels[event.model].fields).filter(([, field]) => field.nullable).map(([name]) => name);
|
|
194
|
+
const result = validateRecord(clientContract, event.model, event.payload, {
|
|
195
|
+
codecLookup,
|
|
196
|
+
partial: event.operation === "update",
|
|
197
|
+
optionalFields
|
|
198
|
+
});
|
|
199
|
+
if (!result.ok) return {
|
|
200
|
+
kind: "validation-failure",
|
|
201
|
+
error: "RECORD_VALIDATION_FAILURE",
|
|
202
|
+
issues: result.issues
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return buildOwnershipCheck(dag, contract, getKeyField, event.model, keyField, (event.wirePayload ?? event.payload)[keyField], options.scopeKey);
|
|
206
|
+
}
|
|
207
|
+
return events.map((event) => ({
|
|
208
|
+
eventId: event.id,
|
|
209
|
+
model: event.model,
|
|
210
|
+
check: checkEvent(event)
|
|
211
|
+
}));
|
|
143
212
|
}
|
|
144
213
|
function buildPullQueries(dag, contract, getKeyField, logs, options) {
|
|
145
214
|
const models = domainModelsAtDefaultNamespace(contract.domain);
|
|
@@ -165,13 +234,23 @@ function buildPullQueries(dag, contract, getKeyField, logs, options) {
|
|
|
165
234
|
function createSyncServer(options) {
|
|
166
235
|
const dag = buildOwnershipDag(options.contract, options.clientContract, options.rootModel);
|
|
167
236
|
const getKeyField = options.getKeyField ?? defaultGetKeyField;
|
|
237
|
+
const codecLookup = options.codecLookup ?? defaultValidationCodecs;
|
|
238
|
+
for (const model of dag.clientModels) try {
|
|
239
|
+
assertRecordValidator(options.clientContract, model, { codecLookup });
|
|
240
|
+
} catch (error) {
|
|
241
|
+
const reason = error instanceof Error ? error.message : "Unable to build record validator";
|
|
242
|
+
throw new Error(`createSyncServer: cannot validate model "${model}": ${reason}. Provide a codecLookup with supported application types or select a Date/string codec. Temporal and interval objects have no default validator.`);
|
|
243
|
+
}
|
|
168
244
|
return {
|
|
169
245
|
rootModel: dag.rootModel,
|
|
170
|
-
validatePush: (events, pushOptions) => validatePush(dag, options.contract, getKeyField, events,
|
|
246
|
+
validatePush: (events, pushOptions) => validatePush(dag, options.contract, options.clientContract, getKeyField, events, {
|
|
247
|
+
...pushOptions,
|
|
248
|
+
codecLookup
|
|
249
|
+
}),
|
|
171
250
|
buildPullQueries: (logs, pullOptions) => buildPullQueries(dag, options.contract, getKeyField, logs, pullOptions)
|
|
172
251
|
};
|
|
173
252
|
}
|
|
174
253
|
//#endregion
|
|
175
|
-
export { buildOwnershipDag, buildPullQueries, createSyncServer, defaultGetKeyField, resolveAuthorizationPaths, validatePush };
|
|
254
|
+
export { buildOwnershipDag, buildPullQueries, createSyncServer, defaultGetKeyField, defaultValidationCodecs, resolveAuthorizationPaths, validatePush };
|
|
176
255
|
|
|
177
256
|
//# sourceMappingURL=server.mjs.map
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":[],"sources":["../src/core/ownership-dag.ts","../src/core/authorization-paths.ts","../src/core/sync-server.ts"],"sourcesContent":["import type { Contract } from \"@prisma/orm-framework/contract/types\";\nimport { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\n\n/**\n * The contract shape `sync-server` operates on — any family's `Contract`\n * (see ADR 014's \"Genuinely family-agnostic\"). The DAG only ever walks\n * `contract.domain` (relations, model names), which is framework-level and\n * identical in shape across IDB, SQL, Mongo, or any future family — nothing\n * here reads `contract.storage` except through the injectable `getKeyField`\n * resolver in `sync-server.ts`, which is the one place storage shape\n * actually varies by family.\n */\nexport type SyncServerContract = Contract;\n\n/**\n * The ownership graph: `edges.get(model)` is every model reachable from\n * `model` via one of its own `N:1` relations (the models it could be\n * \"owned by\"). Built once, at `createSyncServer()` construction — never\n * per-request (ADR 014).\n */\nexport interface OwnershipDag {\n readonly rootModel: string;\n readonly edges: ReadonlyMap<string, ReadonlySet<string>>;\n /** Model names present in the client-projected contract (ADR 012). */\n readonly clientModels: ReadonlySet<string>;\n}\n\n/**\n * Builds the ownership DAG from the full server-side contract, walking\n * `model.relations` for every domain model. Throws if the graph has a\n * cycle, or if any *client* model (a model that survives ADR 012's\n * projection) has no chain of owning relations back to `rootModel`.\n *\n * Server-only models (present in `contract` but not `clientContract`) are\n * exempt from the reachability requirement — they can never appear in an\n * outbox event or a pull scope check, so there's nothing to authorize. They\n * still count as graph nodes, since a client model's authorization chain\n * may legitimately pass through one (see ADR 014's \"why the full graph\").\n */\nexport function buildOwnershipDag(\n contract: SyncServerContract,\n clientContract: SyncServerContract,\n rootModel: string\n): OwnershipDag {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n const clientModels = new Set(Object.keys(domainModelsAtDefaultNamespace(clientContract.domain)));\n\n if (!(rootModel in models)) {\n throw new Error(`Root model \"${rootModel}\" is not present in the contract's domain models.`);\n }\n if (!clientModels.has(rootModel)) {\n throw new Error(`Root model \"${rootModel}\" is not present in the client contract's domain models.`);\n }\n\n const edges = new Map<string, Set<string>>();\n for (const modelName of Object.keys(models)) {\n edges.set(modelName, new Set());\n }\n for (const [modelName, model] of Object.entries(models)) {\n for (const relation of Object.values(model.relations)) {\n if (relation.cardinality === \"N:1\" && models[relation.to.model]) {\n edges.get(modelName)?.add(relation.to.model);\n }\n }\n }\n\n validateAcyclic(edges);\n validateClientReachability(edges, clientModels, rootModel);\n\n return { rootModel, edges, clientModels };\n}\n\nfunction validateAcyclic(edges: ReadonlyMap<string, ReadonlySet<string>>): void {\n const state = new Map<string, \"visiting\" | \"done\">();\n\n function visit(node: string): void {\n if (state.get(node) === \"done\") return;\n if (state.get(node) === \"visiting\") {\n throw new Error(`Cycle detected in the ownership graph involving model \"${node}\".`);\n }\n state.set(node, \"visiting\");\n for (const neighbor of edges.get(node) ?? []) {\n visit(neighbor);\n }\n state.set(node, \"done\");\n }\n\n for (const node of edges.keys()) {\n visit(node);\n }\n}\n\nfunction validateClientReachability(\n edges: ReadonlyMap<string, ReadonlySet<string>>,\n clientModels: ReadonlySet<string>,\n rootModel: string\n): void {\n const reverseEdges = new Map<string, Set<string>>();\n for (const modelName of edges.keys()) {\n reverseEdges.set(modelName, new Set());\n }\n for (const [modelName, targets] of edges) {\n for (const target of targets) {\n reverseEdges.get(target)?.add(modelName);\n }\n }\n\n const visited = new Set<string>([rootModel]);\n const stack = [rootModel];\n while (stack.length > 0) {\n const current = stack.pop();\n if (current === undefined) continue;\n for (const neighbor of reverseEdges.get(current) ?? []) {\n if (!visited.has(neighbor)) {\n visited.add(neighbor);\n stack.push(neighbor);\n }\n }\n }\n\n for (const modelName of clientModels) {\n if (!visited.has(modelName)) {\n throw new Error(\n `Model \"${modelName}\" has no path of owning relations back to root model \"${rootModel}\". ` +\n `Add a relation chain to \"${rootModel}\", or exclude the model from the client contract if it shouldn't sync.`\n );\n }\n }\n}\n","import { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\nimport type { SyncServerContract } from \"./ownership-dag\";\n\n/**\n * Every structural path of `N:1` relation names from `modelName` back to\n * `rootModel` — not just the shortest. A record legitimately reachable\n * through relation A *or* relation B is authorized either way (ADR 014's\n * \"any one path, not shortest path\"), so callers must check all of them.\n *\n * Sorted shortest-first, then lexicographically by relation-name chain, for\n * deterministic output — matches the old generator's `buildAllAuthorizationPaths`\n * precedent, minus the \"prefer required\" tiebreak (this DAG doesn't\n * distinguish nullable from required FKs; see ADR 014's rationale).\n */\nexport function resolveAuthorizationPaths(\n contract: SyncServerContract,\n rootModel: string,\n modelName: string\n): readonly (readonly string[])[] {\n if (modelName === rootModel) return [];\n\n const models = domainModelsAtDefaultNamespace(contract.domain);\n const paths: string[][] = [];\n\n const dfs = (current: string, path: string[], visited: Set<string>): void => {\n const model = models[current];\n if (!model) return;\n\n for (const [relationName, relation] of Object.entries(model.relations)) {\n if (relation.cardinality !== \"N:1\") continue;\n const target = relation.to.model;\n if (!models[target] || visited.has(target)) continue;\n\n path.push(relationName);\n if (target === rootModel) {\n paths.push([...path]);\n } else {\n visited.add(target);\n dfs(target, path, visited);\n visited.delete(target);\n }\n path.pop();\n }\n };\n\n dfs(modelName, [], new Set([modelName]));\n\n return paths.sort((a, b) => a.length - b.length || a.join(\".\").localeCompare(b.join(\".\")));\n}\n","import { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\nimport { resolveAuthorizationPaths } from \"./authorization-paths\";\nimport { buildOwnershipDag } from \"./ownership-dag\";\nimport type { OwnershipDag, SyncServerContract } from \"./ownership-dag\";\n\n/** An outbox event pending push, transport-agnostic (no browser types). */\nexport interface SyncPushEvent {\n readonly id: string;\n readonly model: string;\n readonly operation: \"create\" | \"update\" | \"delete\";\n readonly payload: Record<string, unknown>;\n}\n\n/**\n * A changelog row pending pull; `key` is the row's own primary-key value.\n *\n * Expected to already be pre-filtered to the caller — e.g. by a `scopeKey`\n * column the caller stamped on the changelog row at push time (reusing the\n * `scopeKey` that authorized it) and queried flatly (`WHERE scopeKey = ?`).\n * `buildPullQueries` doesn't repeat that filter; it re-derives ownership\n * live, since the stamped value is a push-time snapshot and can go stale if\n * the record's ownership chain changes afterward (e.g. a `Board` handed to\n * a different owner after a `Todo` under it was already pushed).\n */\nexport interface SyncPullLogEntry {\n readonly changelogId: string;\n readonly model: string;\n readonly key: unknown;\n}\n\n/**\n * What the caller must check to authorize a record. Never a query result —\n * `sync-server` never touches a database (ADR 014's transport-agnostic\n * boundary). The caller executes the check against whatever storage it uses.\n */\nexport type OwnershipCheck =\n | { readonly kind: \"unknown-model\" }\n | {\n readonly kind: \"root\";\n readonly keyField: string;\n readonly key: unknown;\n readonly scopeKey: string;\n /** The row *is* the root — no query needed, this is already decided. */\n readonly authorized: boolean;\n }\n | {\n readonly kind: \"scoped\";\n readonly keyField: string;\n readonly key: unknown;\n readonly rootKeyField: string;\n readonly scopeKey: string;\n /**\n * Every relation-name chain from this model to `rootModel`. The\n * caller is authorized via *any one* resolving to `scopeKey`\n * (ADR 014) — e.g. `findFirst` with an `OR` across paths.\n */\n readonly paths: readonly (readonly string[])[];\n };\n\nexport interface PushValidationResult {\n readonly eventId: string;\n readonly model: string;\n readonly check: OwnershipCheck;\n}\n\nexport interface PullScopeResult {\n readonly changelogId: string;\n readonly model: string;\n readonly check: OwnershipCheck;\n}\n\n/**\n * Resolves a model's primary-key field name from the contract. Storage\n * shape is the one thing that genuinely varies by family (IDB: a flat\n * `model.storage.keyPath` string; SQL: a possibly-compound\n * `contract.storage.namespaces[ns].entries.table[table].primaryKey.columns`\n * array; Mongo, whatever Mongo does) — so this is the sole extension point\n * `createSyncServer` exposes (`CreateSyncServerOptions.getKeyField`) rather\n * than something the DAG tries to introspect generically.\n */\nexport type GetKeyField = (contract: SyncServerContract, modelName: string) => string;\n\n/**\n * Default resolver: duck-types `model.storage.keyPath` as a string. This\n * happens to be exactly IDB's storage shape, but nothing here imports an\n * IDB type to know that — a family whose storage shape doesn't expose a\n * flat `keyPath` (SQL's compound-capable `primaryKey.columns`, for one)\n * simply won't match, and `createSyncServer` throws asking for an explicit\n * `getKeyField` instead of silently misresolving.\n */\nexport const defaultGetKeyField: GetKeyField = (contract, modelName) => {\n const model = domainModelsAtDefaultNamespace(contract.domain)[modelName];\n const keyPath = (model?.storage as { readonly keyPath?: unknown } | undefined)?.keyPath;\n if (typeof keyPath !== \"string\") {\n const hint = Array.isArray(keyPath)\n ? \"This model has a compound primary key (an array keyPath) — sync-server does not support compound-key \" +\n \"models yet. Pass a getKeyField option to createSyncServer, or keep this model out of the sync scope.\"\n : \"This contract's storage shape isn't IDB's — pass a getKeyField option to createSyncServer.\";\n throw new Error(`Model \"${modelName}\" has no single string storage.keyPath in the contract. ${hint}`);\n }\n return keyPath;\n};\n\nfunction buildOwnershipCheck(\n dag: OwnershipDag,\n contract: SyncServerContract,\n getKeyField: GetKeyField,\n modelName: string,\n keyField: string,\n key: unknown,\n scopeKey: string\n): OwnershipCheck {\n if (modelName === dag.rootModel) {\n return { kind: \"root\", keyField, key, scopeKey, authorized: key === scopeKey };\n }\n return {\n kind: \"scoped\",\n keyField,\n key,\n rootKeyField: getKeyField(contract, dag.rootModel),\n scopeKey,\n paths: resolveAuthorizationPaths(contract, dag.rootModel, modelName),\n };\n}\n\nexport function validatePush(\n dag: OwnershipDag,\n contract: SyncServerContract,\n getKeyField: GetKeyField,\n events: readonly SyncPushEvent[],\n options: { readonly scopeKey: string }\n): readonly PushValidationResult[] {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n\n return events.map((event) => {\n if (!dag.clientModels.has(event.model) || !models[event.model]) {\n return { eventId: event.id, model: event.model, check: { kind: \"unknown-model\" } };\n }\n const keyField = getKeyField(contract, event.model);\n const check = buildOwnershipCheck(\n dag,\n contract,\n getKeyField,\n event.model,\n keyField,\n event.payload[keyField],\n options.scopeKey\n );\n return { eventId: event.id, model: event.model, check };\n });\n}\n\nexport function buildPullQueries(\n dag: OwnershipDag,\n contract: SyncServerContract,\n getKeyField: GetKeyField,\n logs: readonly SyncPullLogEntry[],\n options: { readonly scopeKey: string }\n): readonly PullScopeResult[] {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n\n return logs.map((log) => {\n if (!dag.clientModels.has(log.model) || !models[log.model]) {\n return { changelogId: log.changelogId, model: log.model, check: { kind: \"unknown-model\" } };\n }\n const keyField = getKeyField(contract, log.model);\n const check = buildOwnershipCheck(dag, contract, getKeyField, log.model, keyField, log.key, options.scopeKey);\n return { changelogId: log.changelogId, model: log.model, check };\n });\n}\n\nexport interface CreateSyncServerOptions {\n /** The full server-side contract (ADR 012) — includes client-excluded models. Any family. */\n readonly contract: SyncServerContract;\n /** The client-projected contract (ADR 012) — defines which models are ever synced. Any family. */\n readonly clientContract: SyncServerContract;\n readonly rootModel: string;\n /** @default defaultGetKeyField (IDB-shaped storage.keyPath) */\n readonly getKeyField?: GetKeyField;\n}\n\nexport interface SyncServer {\n readonly rootModel: string;\n /** Resolve every event's ownership check. Pure — never touches a database. */\n validatePush(\n events: readonly SyncPushEvent[],\n options: { readonly scopeKey: string }\n ): readonly PushValidationResult[];\n /** Resolve every changelog row's pull-scope check. Pure — never touches a database. */\n buildPullQueries(\n logs: readonly SyncPullLogEntry[],\n options: { readonly scopeKey: string }\n ): readonly PullScopeResult[];\n}\n\n/**\n * Builds the ownership DAG once (throws on a broken schema — see\n * `buildOwnershipDag`) and returns a `SyncServer` bound to it.\n */\nexport function createSyncServer(options: CreateSyncServerOptions): SyncServer {\n const dag = buildOwnershipDag(options.contract, options.clientContract, options.rootModel);\n const getKeyField = options.getKeyField ?? defaultGetKeyField;\n\n return {\n rootModel: dag.rootModel,\n validatePush: (events, pushOptions) => validatePush(dag, options.contract, getKeyField, events, pushOptions),\n buildPullQueries: (logs, pullOptions) => buildPullQueries(dag, options.contract, getKeyField, logs, p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,OAAO;GAAE,SAAS,MAAM;GAAI,OAAO,MAAM;GAAO;EAAM;CACxD,CAAC;AACH;AAEA,SAAgB,iBACd,KACA,UACA,aACA,MACA,SAC4B;CAC5B,MAAM,SAAS,+BAA+B,SAAS,MAAM;CAE7D,OAAO,KAAK,KAAK,QAAQ;EACvB,IAAI,CAAC,IAAI,aAAa,IAAI,IAAI,KAAK,KAAK,CAAC,OAAO,IAAI,QAClD,OAAO;GAAE,aAAa,IAAI;GAAa,OAAO,IAAI;GAAO,OAAO,EAAE,MAAM,gBAAgB;EAAE;EAE5F,MAAM,WAAW,YAAY,UAAU,IAAI,KAAK;EAChD,MAAM,QAAQ,oBAAoB,KAAK,UAAU,aAAa,IAAI,OAAO,UAAU,IAAI,KAAK,QAAQ,QAAQ;EAC5G,OAAO;GAAE,aAAa,IAAI;GAAa,OAAO,IAAI;GAAO;EAAM;CACjE,CAAC;AACH;;;;;AA8BA,SAAgB,iBAAiB,SAA8C;CAC7E,MAAM,MAAM,kBAAkB,QAAQ,UAAU,QAAQ,gBAAgB,QAAQ,SAAS;CACzF,MAAM,cAAc,QAAQ,eAAe;CAE3C,OAAO;EACL,WAAW,IAAI;EACf,eAAe,QAAQ,gBAAgB,aAAa,KAAK,QAAQ,UAAU,aAAa,QAAQ,WAAW;EAC3G,mBAAmB,MAAM,gBAAgB,iBAAiB,KAAK,QAAQ,UAAU,aAAa,MAAM,WAAW;CACjH;AACF"}
|
|
1
|
+
{"version":3,"file":"server.mjs","names":[],"sources":["../src/core/ownership-dag.ts","../src/core/authorization-paths.ts","../src/core/validation-codecs.ts","../src/core/sync-server.ts"],"sourcesContent":["import type { Contract } from \"@prisma/orm-framework/contract/types\";\nimport { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\n\n/**\n * The contract shape `sync-server` operates on — any family's `Contract`\n * (see ADR 014's \"Genuinely family-agnostic\"). The DAG only ever walks\n * `contract.domain` (relations, model names), which is framework-level and\n * identical in shape across IDB, SQL, Mongo, or any future family — nothing\n * here reads `contract.storage` except through the injectable `getKeyField`\n * resolver in `sync-server.ts`, which is the one place storage shape\n * actually varies by family.\n */\nexport type SyncServerContract = Contract;\n\n/**\n * The ownership graph: `edges.get(model)` is every model reachable from\n * `model` via one of its own `N:1` relations (the models it could be\n * \"owned by\"). Built once, at `createSyncServer()` construction — never\n * per-request (ADR 014).\n */\nexport interface OwnershipDag {\n readonly rootModel: string;\n readonly edges: ReadonlyMap<string, ReadonlySet<string>>;\n /** Model names present in the client-projected contract (ADR 012). */\n readonly clientModels: ReadonlySet<string>;\n}\n\n/**\n * Builds the ownership DAG from the full server-side contract, walking\n * `model.relations` for every domain model. Throws if the graph has a\n * cycle, or if any *client* model (a model that survives ADR 012's\n * projection) has no chain of owning relations back to `rootModel`.\n *\n * Server-only models (present in `contract` but not `clientContract`) are\n * exempt from the reachability requirement — they can never appear in an\n * outbox event or a pull scope check, so there's nothing to authorize. They\n * still count as graph nodes, since a client model's authorization chain\n * may legitimately pass through one (see ADR 014's \"why the full graph\").\n */\nexport function buildOwnershipDag(\n contract: SyncServerContract,\n clientContract: SyncServerContract,\n rootModel: string\n): OwnershipDag {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n const clientModels = new Set(Object.keys(domainModelsAtDefaultNamespace(clientContract.domain)));\n\n if (!(rootModel in models)) {\n throw new Error(`Root model \"${rootModel}\" is not present in the contract's domain models.`);\n }\n if (!clientModels.has(rootModel)) {\n throw new Error(`Root model \"${rootModel}\" is not present in the client contract's domain models.`);\n }\n\n const edges = new Map<string, Set<string>>();\n for (const modelName of Object.keys(models)) {\n edges.set(modelName, new Set());\n }\n for (const [modelName, model] of Object.entries(models)) {\n for (const relation of Object.values(model.relations)) {\n if (relation.cardinality === \"N:1\" && models[relation.to.model]) {\n edges.get(modelName)?.add(relation.to.model);\n }\n }\n }\n\n validateAcyclic(edges);\n validateClientReachability(edges, clientModels, rootModel);\n\n return { rootModel, edges, clientModels };\n}\n\nfunction validateAcyclic(edges: ReadonlyMap<string, ReadonlySet<string>>): void {\n const state = new Map<string, \"visiting\" | \"done\">();\n\n function visit(node: string): void {\n if (state.get(node) === \"done\") return;\n if (state.get(node) === \"visiting\") {\n throw new Error(`Cycle detected in the ownership graph involving model \"${node}\".`);\n }\n state.set(node, \"visiting\");\n for (const neighbor of edges.get(node) ?? []) {\n visit(neighbor);\n }\n state.set(node, \"done\");\n }\n\n for (const node of edges.keys()) {\n visit(node);\n }\n}\n\nfunction validateClientReachability(\n edges: ReadonlyMap<string, ReadonlySet<string>>,\n clientModels: ReadonlySet<string>,\n rootModel: string\n): void {\n const reverseEdges = new Map<string, Set<string>>();\n for (const modelName of edges.keys()) {\n reverseEdges.set(modelName, new Set());\n }\n for (const [modelName, targets] of edges) {\n for (const target of targets) {\n reverseEdges.get(target)?.add(modelName);\n }\n }\n\n const visited = new Set<string>([rootModel]);\n const stack = [rootModel];\n while (stack.length > 0) {\n const current = stack.pop();\n if (current === undefined) continue;\n for (const neighbor of reverseEdges.get(current) ?? []) {\n if (!visited.has(neighbor)) {\n visited.add(neighbor);\n stack.push(neighbor);\n }\n }\n }\n\n for (const modelName of clientModels) {\n if (!visited.has(modelName)) {\n throw new Error(\n `Model \"${modelName}\" has no path of owning relations back to root model \"${rootModel}\". ` +\n `Add a relation chain to \"${rootModel}\", or exclude the model from the client contract if it shouldn't sync.`\n );\n }\n }\n}\n","import { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\nimport type { SyncServerContract } from \"./ownership-dag\";\n\n/**\n * Every structural path of `N:1` relation names from `modelName` back to\n * `rootModel` — not just the shortest. A record legitimately reachable\n * through relation A *or* relation B is authorized either way (ADR 014's\n * \"any one path, not shortest path\"), so callers must check all of them.\n *\n * Sorted shortest-first, then lexicographically by relation-name chain, for\n * deterministic output — matches the old generator's `buildAllAuthorizationPaths`\n * precedent, minus the \"prefer required\" tiebreak (this DAG doesn't\n * distinguish nullable from required FKs; see ADR 014's rationale).\n */\nexport function resolveAuthorizationPaths(\n contract: SyncServerContract,\n rootModel: string,\n modelName: string\n): readonly (readonly string[])[] {\n if (modelName === rootModel) return [];\n\n const models = domainModelsAtDefaultNamespace(contract.domain);\n const paths: string[][] = [];\n\n const dfs = (current: string, path: string[], visited: Set<string>): void => {\n const model = models[current];\n if (!model) return;\n\n for (const [relationName, relation] of Object.entries(model.relations)) {\n if (relation.cardinality !== \"N:1\") continue;\n const target = relation.to.model;\n if (!models[target] || visited.has(target)) continue;\n\n path.push(relationName);\n if (target === rootModel) {\n paths.push([...path]);\n } else {\n visited.add(target);\n dfs(target, path, visited);\n visited.delete(target);\n }\n path.pop();\n }\n };\n\n dfs(modelName, [], new Set([modelName]));\n\n return paths.sort((a, b) => a.length - b.length || a.join(\".\").localeCompare(b.join(\".\")));\n}\n","import { idbCodecLookup } from \"@prisma-idb/target-idb/runtime\";\nimport type { ValidationCodecLookup } from \"@prisma-idb/target-idb/runtime\";\n\n// SQL descriptors' targetTypes are database type names, unlike IDB's JS names.\n// Map codec identities to their application representations, never storage types.\nconst sqlApplicationTypes: Record<string, readonly string[]> = {};\nfor (const name of [\"text\", \"char\", \"varchar\"]) sqlApplicationTypes[`sql/${name}@1`] = [\"string\"];\nfor (const name of [\"int\", \"float\"]) sqlApplicationTypes[`sql/${name}@1`] = [\"number\"];\nfor (const name of [\n \"text\",\n \"enum\",\n \"char\",\n \"varchar\",\n \"uuid\",\n \"numeric\",\n \"inet\",\n \"bit\",\n \"varbit\",\n \"time\",\n \"timetz\",\n \"date-string\",\n \"timestamp-string\",\n \"timestamptz-string\",\n \"time-string\",\n \"tsquery\",\n]) {\n sqlApplicationTypes[`pg/${name}@1`] = [\"string\"];\n}\nfor (const name of [\"int\", \"int2\", \"int4\", \"int8number\", \"float\", \"float4\", \"float8\"]) {\n sqlApplicationTypes[`pg/${name}@1`] = [\"number\"];\n}\nfor (const name of [\"int8\", \"unboundedint\"]) sqlApplicationTypes[`pg/${name}@1`] = [\"bigint\"];\nsqlApplicationTypes[\"pg/bool@1\"] = [\"boolean\"];\n// rc.5 date/timestamp codecs carry Date; pg/time carries string. rc.6 removed\n// these IDs, but historical contracts still need the same native validation.\nfor (const name of [\"date\", \"timestamp\", \"timestamptz\", \"timestamptz-date\"]) {\n sqlApplicationTypes[`pg/${name}@1`] = [\"Date\"];\n}\nsqlApplicationTypes[\"sql/timestamp@1\"] = [\"Date\"];\nsqlApplicationTypes[\"pg/text-array@1\"] = [\"string[]\"];\n// Temporal codecs and pg/interval@1 carry objects, not Date/string. They have\n// no default validator; createSyncServer rejects them before accepting pushes.\nsqlApplicationTypes[\"pg/bytea@1\"] = [\"Uint8Array\"];\nsqlApplicationTypes[\"pg/json@1\"] = [\"unknown\"];\nsqlApplicationTypes[\"pg/jsonb@1\"] = [\"unknown\"];\n\nexport const defaultValidationCodecs: ValidationCodecLookup = {\n targetTypesFor: (id) => idbCodecLookup.targetTypesFor(id) ?? sqlApplicationTypes[id],\n};\n","import { domainModelsAtDefaultNamespace } from \"@prisma/orm-framework/contract/types\";\nimport { assertRecordValidator, validateRecord, validateKeyFields } from \"@prisma-idb/target-idb/runtime\";\nimport type { ValidationCodecLookup } from \"@prisma-idb/target-idb/runtime\";\nimport { defaultValidationCodecs } from \"./validation-codecs\";\nimport { resolveAuthorizationPaths } from \"./authorization-paths\";\nimport { buildOwnershipDag } from \"./ownership-dag\";\nimport type { OwnershipDag, SyncServerContract } from \"./ownership-dag\";\n\n/** An outbox event pending push, transport-agnostic (no browser types). */\nexport interface SyncPushEvent {\n readonly id: string;\n readonly model: string;\n readonly operation: \"create\" | \"update\" | \"delete\";\n /** Native application values used for contract validation. */\n readonly payload: Record<string, unknown>;\n /** Pre-revival payload; supply when native keys differ from their JSON wire form. */\n readonly wirePayload?: Record<string, unknown>;\n}\n\n/**\n * A changelog row pending pull; `key` is the row's own primary-key value.\n *\n * Expected to already be pre-filtered to the caller — e.g. by a `scopeKey`\n * column the caller stamped on the changelog row at push time (reusing the\n * `scopeKey` that authorized it) and queried flatly (`WHERE scopeKey = ?`).\n * `buildPullQueries` doesn't repeat that filter; it re-derives ownership\n * live, since the stamped value is a push-time snapshot and can go stale if\n * the record's ownership chain changes afterward (e.g. a `Board` handed to\n * a different owner after a `Todo` under it was already pushed).\n */\nexport interface SyncPullLogEntry {\n readonly changelogId: string;\n readonly model: string;\n readonly key: unknown;\n}\n\n/**\n * What the caller must check to authorize a record. Never a query result —\n * `sync-server` never touches a database (ADR 014's transport-agnostic\n * boundary). The caller executes the check against whatever storage it uses.\n */\nexport type OwnershipCheck =\n | { readonly kind: \"unknown-model\" }\n | {\n readonly kind: \"root\";\n readonly keyField: string;\n readonly key: unknown;\n readonly scopeKey: string;\n /** The row *is* the root — no query needed, this is already decided. */\n readonly authorized: boolean;\n }\n | {\n readonly kind: \"scoped\";\n readonly keyField: string;\n readonly key: unknown;\n readonly rootKeyField: string;\n readonly scopeKey: string;\n /**\n * Every relation-name chain from this model to `rootModel`. The\n * caller is authorized via *any one* resolving to `scopeKey`\n * (ADR 014) — e.g. `findFirst` with an `OR` across paths.\n */\n readonly paths: readonly (readonly string[])[];\n };\n\nexport type PushCheck =\n | OwnershipCheck\n | {\n readonly kind: \"validation-failure\";\n readonly error: \"RECORD_VALIDATION_FAILURE\" | \"KEYPATH_VALIDATION_FAILURE\";\n readonly issues: readonly string[];\n };\n\nexport interface PushValidationResult {\n readonly eventId: string;\n readonly model: string;\n readonly check: PushCheck;\n}\n\nexport interface PullScopeResult {\n readonly changelogId: string;\n readonly model: string;\n readonly check: OwnershipCheck;\n}\n\n/**\n * Resolves a model's primary-key field name from the contract. Storage\n * shape is the one thing that genuinely varies by family (IDB: a flat\n * `model.storage.keyPath` string; SQL: a possibly-compound\n * `contract.storage.namespaces[ns].entries.table[table].primaryKey.columns`\n * array; Mongo, whatever Mongo does) — so this is the sole extension point\n * `createSyncServer` exposes (`CreateSyncServerOptions.getKeyField`) rather\n * than something the DAG tries to introspect generically.\n */\nexport type GetKeyField = (contract: SyncServerContract, modelName: string) => string;\n\n/**\n * Default resolver: duck-types `model.storage.keyPath` as a string. This\n * happens to be exactly IDB's storage shape, but nothing here imports an\n * IDB type to know that — a family whose storage shape doesn't expose a\n * flat `keyPath` (SQL's compound-capable `primaryKey.columns`, for one)\n * simply won't match, and `createSyncServer` throws asking for an explicit\n * `getKeyField` instead of silently misresolving.\n */\nexport const defaultGetKeyField: GetKeyField = (contract, modelName) => {\n const model = domainModelsAtDefaultNamespace(contract.domain)[modelName];\n const keyPath = (model?.storage as { readonly keyPath?: unknown } | undefined)?.keyPath;\n if (typeof keyPath !== \"string\") {\n const hint = Array.isArray(keyPath)\n ? \"This model has a compound primary key (an array keyPath) — sync-server does not support compound-key \" +\n \"models yet. Pass a getKeyField option to createSyncServer, or keep this model out of the sync scope.\"\n : \"This contract's storage shape isn't IDB's — pass a getKeyField option to createSyncServer.\";\n throw new Error(`Model \"${modelName}\" has no single string storage.keyPath in the contract. ${hint}`);\n }\n return keyPath;\n};\n\nfunction buildOwnershipCheck(\n dag: OwnershipDag,\n contract: SyncServerContract,\n getKeyField: GetKeyField,\n modelName: string,\n keyField: string,\n key: unknown,\n scopeKey: string\n): OwnershipCheck {\n if (modelName === dag.rootModel) {\n return { kind: \"root\", keyField, key, scopeKey, authorized: key === scopeKey };\n }\n return {\n kind: \"scoped\",\n keyField,\n key,\n rootKeyField: getKeyField(contract, dag.rootModel),\n scopeKey,\n paths: resolveAuthorizationPaths(contract, dag.rootModel, modelName),\n };\n}\n\nexport function validatePush(\n dag: OwnershipDag,\n contract: SyncServerContract,\n clientContract: SyncServerContract,\n getKeyField: GetKeyField,\n events: readonly SyncPushEvent[],\n options: { readonly scopeKey: string; readonly codecLookup?: ValidationCodecLookup }\n): readonly PushValidationResult[] {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n const clientModels = domainModelsAtDefaultNamespace(clientContract.domain);\n const codecLookup = options.codecLookup ?? defaultValidationCodecs;\n\n // Shape checks run before the ownership walk (ADR 015), so a malformed\n // event never reaches an ownership query.\n function checkEvent(event: SyncPushEvent): PushCheck {\n if (!dag.clientModels.has(event.model) || !models[event.model] || !clientModels[event.model]) {\n return { kind: \"unknown-model\" };\n }\n const keyField = getKeyField(contract, event.model);\n const keyValue = event.payload?.[keyField];\n const keyResult = validateKeyFields(contract, event.model, { [keyField]: keyValue }, [keyField], { codecLookup });\n if (!keyResult.ok) {\n return { kind: \"validation-failure\", error: \"KEYPATH_VALIDATION_FAILURE\", issues: keyResult.issues };\n }\n if (event.operation !== \"delete\") {\n // SQL creates may omit nullable fields; patches validate only supplied fields.\n const optionalFields = Object.entries(clientModels[event.model]!.fields)\n .filter(([, field]) => field.nullable)\n .map(([name]) => name);\n const result = validateRecord(clientContract, event.model, event.payload, {\n codecLookup,\n partial: event.operation === \"update\",\n optionalFields,\n });\n if (!result.ok) {\n return { kind: \"validation-failure\", error: \"RECORD_VALIDATION_FAILURE\", issues: result.issues };\n }\n }\n return buildOwnershipCheck(\n dag,\n contract,\n getKeyField,\n event.model,\n keyField,\n (event.wirePayload ?? event.payload)[keyField],\n options.scopeKey\n );\n }\n\n return events.map((event) => ({ eventId: event.id, model: event.model, check: checkEvent(event) }));\n}\n\nexport function buildPullQueries(\n dag: OwnershipDag,\n contract: SyncServerContract,\n getKeyField: GetKeyField,\n logs: readonly SyncPullLogEntry[],\n options: { readonly scopeKey: string }\n): readonly PullScopeResult[] {\n const models = domainModelsAtDefaultNamespace(contract.domain);\n\n return logs.map((log) => {\n if (!dag.clientModels.has(log.model) || !models[log.model]) {\n return { changelogId: log.changelogId, model: log.model, check: { kind: \"unknown-model\" } };\n }\n const keyField = getKeyField(contract, log.model);\n const check = buildOwnershipCheck(dag, contract, getKeyField, log.model, keyField, log.key, options.scopeKey);\n return { changelogId: log.changelogId, model: log.model, check };\n });\n}\n\nexport interface CreateSyncServerOptions {\n /** The full server-side contract (ADR 012) — includes client-excluded models. Any family. */\n readonly contract: SyncServerContract;\n /** The client-projected contract (ADR 012) — defines the synced models and fields to validate. Any family. */\n readonly clientContract: SyncServerContract;\n readonly rootModel: string;\n /** @default defaultGetKeyField (IDB-shaped storage.keyPath) */\n readonly getKeyField?: GetKeyField;\n /** Native application types; unsupported validators throw at construction. */\n readonly codecLookup?: ValidationCodecLookup;\n}\n\nexport interface SyncServer {\n readonly rootModel: string;\n /** Resolve every event's ownership check. Pure — never touches a database. */\n validatePush(\n events: readonly SyncPushEvent[],\n options: { readonly scopeKey: string }\n ): readonly PushValidationResult[];\n /** Resolve every changelog row's pull-scope check. Pure — never touches a database. */\n buildPullQueries(\n logs: readonly SyncPullLogEntry[],\n options: { readonly scopeKey: string }\n ): readonly PullScopeResult[];\n}\n\n/**\n * Builds the ownership DAG once (throws on a broken schema — see\n * `buildOwnershipDag`) and returns a `SyncServer` bound to it.\n */\nexport function createSyncServer(options: CreateSyncServerOptions): SyncServer {\n const dag = buildOwnershipDag(options.contract, options.clientContract, options.rootModel);\n const getKeyField = options.getKeyField ?? defaultGetKeyField;\n const codecLookup = options.codecLookup ?? defaultValidationCodecs;\n for (const model of dag.clientModels) {\n try {\n assertRecordValidator(options.clientContract, model, { codecLookup });\n } catch (error) {\n const reason = error instanceof Error ? error.message : \"Unable to build record validator\";\n throw new Error(\n `createSyncServer: cannot validate model \"${model}\": ${reason}. ` +\n \"Provide a codecLookup with supported application types or select a Date/string codec. \" +\n \"Temporal and interval objects have no default validator.\"\n );\n }\n }\n\n return {\n rootModel: dag.rootModel,\n validatePush: (events, pushOptions) =>\n validatePush(dag, options.contract, options.clientContract, getKeyField, events, {\n ...pushOptions,\n codecLookup,\n }),\n buildPullQueries: (logs, pullOptions) => buildPullQueries(dag, options.contract, getKeyField, logs, pullOptions),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAgB,kBACd,UACA,gBACA,WACc;CACd,MAAM,SAAS,+BAA+B,SAAS,MAAM;CAC7D,MAAM,eAAe,IAAI,IAAI,OAAO,KAAK,+BAA+B,eAAe,MAAM,CAAC,CAAC;CAE/F,IAAI,EAAE,aAAa,SACjB,MAAM,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AAQ,gBAAgB,aAAa,QAAQ;GAC/E,GAAG;GACH;EACF,CAAC;EACH,mBAAmB,MAAM,gBAAgB,iBAAiB,KAAK,QAAQ,UAAU,aAAa,MAAM,WAAW;CACjH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-idb/sync-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Prisma 8 IDB — sync ownership DAG (server-side push authorization + pull scoping, ADR 014)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@prisma-idb/family-idb": "0.
|
|
44
|
+
"@prisma-idb/family-idb": "0.9.0",
|
|
45
45
|
"@prisma/orm-family-sql": "8.0.0-rc.12",
|
|
46
46
|
"@prisma/orm-framework": "8.0.0-rc.12",
|
|
47
|
-
"@prisma/orm-postgres": "8.0.0-rc.12"
|
|
47
|
+
"@prisma/orm-postgres": "8.0.0-rc.12",
|
|
48
|
+
"@prisma-idb/target-idb": "0.9.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@prisma-idb/target-idb": "0.8.0",
|
|
51
51
|
"@types/node": "^24.13.3",
|
|
52
52
|
"tsdown": "^0.22.14",
|
|
53
53
|
"typescript": "^6.0.3",
|