@syncular/server 0.47.0 → 0.49.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 +17 -2
- package/dist/errors.js +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/local-authority.d.ts +78 -0
- package/dist/local-authority.js +470 -0
- package/dist/operations.d.ts +10 -1
- package/dist/operations.js +17 -0
- package/dist/push.js +44 -1
- package/dist/validate.d.ts +25 -0
- package/package.json +2 -2
- package/src/errors.ts +6 -0
- package/src/index.ts +1 -0
- package/src/local-authority.ts +654 -0
- package/src/operations.ts +40 -0
- package/src/push.ts +55 -1
- package/src/validate.ts +26 -0
package/dist/push.js
CHANGED
|
@@ -696,6 +696,23 @@ function commitValidationReader(tx, schema) {
|
|
|
696
696
|
serverVersion: stored.serverVersion,
|
|
697
697
|
}));
|
|
698
698
|
},
|
|
699
|
+
scanRowsByIndex: async ({ table: tableName, index, values, afterRowId = null, limit = 100, }) => {
|
|
700
|
+
const table = tableFor(tableName);
|
|
701
|
+
if (tx.scanRowsByIndex === undefined) {
|
|
702
|
+
throw new Error('storage transaction does not support commit-validator index scans');
|
|
703
|
+
}
|
|
704
|
+
const rows = await tx.scanRowsByIndex({
|
|
705
|
+
table: tableName,
|
|
706
|
+
index,
|
|
707
|
+
values,
|
|
708
|
+
afterRowId,
|
|
709
|
+
limit,
|
|
710
|
+
});
|
|
711
|
+
return rows.map((stored) => ({
|
|
712
|
+
row: toValidateRow(table.columns, decodeRow(table.columns, stored.payload)),
|
|
713
|
+
serverVersion: stored.serverVersion,
|
|
714
|
+
}));
|
|
715
|
+
},
|
|
699
716
|
queryAuthoritative: (query) => transactionQuery(tx, query),
|
|
700
717
|
};
|
|
701
718
|
}
|
|
@@ -791,6 +808,32 @@ async function enforceReferences(tx, schema, staged, clientOpCount, cascadeLimit
|
|
|
791
808
|
last: write,
|
|
792
809
|
});
|
|
793
810
|
}
|
|
811
|
+
// One candidate-state read per parent table, not one per reference: a
|
|
812
|
+
// commit that points several rows at the same parent (a fight's
|
|
813
|
+
// combatants, its chronicle) reads that parent once. Postgres binds the
|
|
814
|
+
// ids as one array per table; SQLite and D1 answer with one lookup per id.
|
|
815
|
+
const parentIds = new Map();
|
|
816
|
+
for (const { last: write } of finalByRow.values()) {
|
|
817
|
+
if (write.op !== 'upsert' || write.values === undefined)
|
|
818
|
+
continue;
|
|
819
|
+
for (const reference of write.table.references) {
|
|
820
|
+
const value = write.values[reference.columnIndex];
|
|
821
|
+
if (value === null || value === undefined)
|
|
822
|
+
continue;
|
|
823
|
+
const parentRowId = renderScopeValue(value);
|
|
824
|
+
if (parentRowId === undefined)
|
|
825
|
+
continue;
|
|
826
|
+
const ids = parentIds.get(reference.parentTable);
|
|
827
|
+
if (ids === undefined)
|
|
828
|
+
parentIds.set(reference.parentTable, new Set([parentRowId]));
|
|
829
|
+
else
|
|
830
|
+
ids.add(parentRowId);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
const parents = new Map();
|
|
834
|
+
for (const [parentTable, ids] of parentIds) {
|
|
835
|
+
parents.set(parentTable, await readCandidateRows(tx, parentTable, [...ids]));
|
|
836
|
+
}
|
|
794
837
|
for (const { last: write } of finalByRow.values()) {
|
|
795
838
|
if (write.op !== 'upsert' || write.values === undefined)
|
|
796
839
|
continue;
|
|
@@ -801,7 +844,7 @@ async function enforceReferences(tx, schema, staged, clientOpCount, cascadeLimit
|
|
|
801
844
|
const parentRowId = renderScopeValue(value);
|
|
802
845
|
if (parentRowId === undefined)
|
|
803
846
|
continue;
|
|
804
|
-
if (
|
|
847
|
+
if (parents.get(reference.parentTable)?.has(parentRowId) === true) {
|
|
805
848
|
continue;
|
|
806
849
|
}
|
|
807
850
|
return {
|
package/dist/validate.d.ts
CHANGED
|
@@ -74,6 +74,21 @@ export interface CommitValidationScanInput {
|
|
|
74
74
|
/** Bounded per call by the server to 1..1,000; defaults to 100. */
|
|
75
75
|
readonly limit?: number;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* One exact declared-index lookup a push-transaction reader runs (§6.8): the
|
|
79
|
+
* whole-commit reader and a registered command share this shape.
|
|
80
|
+
*/
|
|
81
|
+
export interface IndexScanInput {
|
|
82
|
+
readonly table: string;
|
|
83
|
+
/** `TableSchema.indexes[].name`; never exposed as a client subscription. */
|
|
84
|
+
readonly index: string;
|
|
85
|
+
/** Exact values in the index declaration's column order. */
|
|
86
|
+
readonly values: readonly RowValue[];
|
|
87
|
+
/** Resume after this rowId (exclusive); `null` = start of the match set. */
|
|
88
|
+
readonly afterRowId?: string | null;
|
|
89
|
+
/** Bounded per call by the server to 1..1,000; defaults to 100. */
|
|
90
|
+
readonly limit?: number;
|
|
91
|
+
}
|
|
77
92
|
/**
|
|
78
93
|
* Candidate-state reads bound to the same storage transaction as the commit.
|
|
79
94
|
* Reads observe every staged sibling operation and no uncommitted competing
|
|
@@ -91,6 +106,16 @@ export interface CommitValidationReader {
|
|
|
91
106
|
*/
|
|
92
107
|
getRows(table: string, rowIds: readonly string[]): Promise<ReadonlyMap<string, CommitValidationRow>>;
|
|
93
108
|
scanRows(input: CommitValidationScanInput): Promise<CommitValidationRow[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Candidate-state exact lookup through one declared relational index, with
|
|
111
|
+
* the same read-your-own-writes guarantee as `scanRows`: staged sibling
|
|
112
|
+
* upserts are present and staged deletes are absent. The values form the
|
|
113
|
+
* complete, order-sensitive index tuple and `afterRowId` is an exclusive
|
|
114
|
+
* keyset cursor, so a caller pages without a scope declaration. There is no
|
|
115
|
+
* scope filter and no actor scope authorization: the caller already holds
|
|
116
|
+
* partition authority, exactly as with `scanRows`.
|
|
117
|
+
*/
|
|
118
|
+
scanRowsByIndex(input: IndexScanInput): Promise<CommitValidationRow[]>;
|
|
94
119
|
/**
|
|
95
120
|
* Run a generated registered query on the commit transaction (§6.8). The
|
|
96
121
|
* request has the shape `ServerStorage.queryAuthoritative` takes; the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.1",
|
|
4
4
|
"description": "Syncular server: handleSyncRequest + storage/auth interfaces for the sync protocol",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"verify:node": "cd ../.. && bun build ./packages/server/test/sqlite-runtime/verify-node.mjs --target=node --conditions=bun --outfile=./packages/server/.verify-node.built.mjs && node ./packages/server/.verify-node.built.mjs"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@syncular/core": "0.
|
|
71
|
+
"@syncular/core": "0.49.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@electric-sql/pglite": "^0.5.4"
|
package/src/errors.ts
CHANGED
|
@@ -194,6 +194,12 @@ export const ERROR_CATALOG: Readonly<Record<string, ErrorCatalogEntry>> = {
|
|
|
194
194
|
recommendedAction: 'inspectServer',
|
|
195
195
|
httpStatus: 503,
|
|
196
196
|
},
|
|
197
|
+
'sync.authority_unavailable': {
|
|
198
|
+
category: 'internal',
|
|
199
|
+
retryable: false,
|
|
200
|
+
recommendedAction: 'inspectServer',
|
|
201
|
+
httpStatus: 503,
|
|
202
|
+
},
|
|
197
203
|
'sync.schema_not_ready': {
|
|
198
204
|
category: 'internal',
|
|
199
205
|
retryable: true,
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './events-ring';
|
|
|
24
24
|
export * from './frame-bytes';
|
|
25
25
|
export * from './handler';
|
|
26
26
|
export * from './lease-store';
|
|
27
|
+
export * from './local-authority';
|
|
27
28
|
export * from './operations';
|
|
28
29
|
export * from './operations-realtime';
|
|
29
30
|
// The `PgExecutor` seam + Postgres storage/fanout are driver-agnostic (zero
|