@syncular/client 0.70.2 → 0.70.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +5 -1
- package/dist/outcomes.d.ts +6 -0
- package/dist/outcomes.js +64 -0
- package/package.json +3 -3
- package/src/client.ts +12 -0
- package/src/outcomes.ts +83 -0
package/dist/client.js
CHANGED
|
@@ -27,7 +27,7 @@ import { compileLocalDataPurge, localDataPurgeMetaKey, localDataPurgeTargetMatch
|
|
|
27
27
|
import { compileLocalDataRebootstrap, localDataRebootstrapMetaKey, } from './local-rebootstrap.js';
|
|
28
28
|
import { decodeLocalDataRebootstrapReceipt, encodeLocalDataRebootstrapReceipt, } from './local-rebootstrap-receipt.js';
|
|
29
29
|
import { appendOutboxCommit, chainsOn, deleteOutboxCommit, encodeOutboxCommit, listOutbox, iterateOutbox, countOutbox, listOutboxBeforeImages, OutboxEncodeError, replaceOutboxBeforeImages, } from './outbox.js';
|
|
30
|
-
import { activeFailureRecords, isStoredOperation, listCommitOutcomes, persistCommitOutcomeResolution, persistedCommitOutcome, pruneCommitOutcomes, commitOutcome as readCommitOutcome, recordCommitOutcome, } from './outcomes.js';
|
|
30
|
+
import { activeFailureRecords, isStoredOperation, listCommitOutcomes, persistCommitOutcomeResolution, persistedCommitOutcome, pruneCommitOutcomes, commitOutcome as readCommitOutcome, recordCommitOutcome, scrubPurgedOutcomes, } from './outcomes.js';
|
|
31
31
|
import { buildPreviousVersionAudit, capturePreviousVersion, clearPreviousVersionAudit, clearPreviousVersionRefusal, dropPreviousVersionContainer, loadLocalSchemaDescriptor, PREVIOUS_VERSION_CONTAINER_NAME, PREVIOUS_VERSION_MAX_LIMIT, readPreviousVersionContainer, readPreviousVersionRows, setLocalSchemaDescriptor, storedPreviousVersionAudit, storedPreviousVersionRefusal, withPreviousVersionContainer, writePreviousVersionAudit, writePreviousVersionRefusal, } from './previous-version.js';
|
|
32
32
|
import { bytesToHex, compileClientSchema, hexToBytes, matchesLocalScopes, dropAndRecreateSyncedTables, ensureLocalBookkeepingSchema, ensureLocalSyncedSchema, fromSqlValue, coerceSqlRepresentation, localColumnType, jsonToRowValue, LOCAL_SCHEMA_VERSION_KEY, normalizeRecordKeys, OPTIMISTIC_VERSION, quoteIdent, recordToRowValues, rowValueToJson, SYNC_VERSION_COLUMN, stripSyncColumns, } from './schema.js';
|
|
33
33
|
import { bootstrapping, bumpLocalRevision, covers, deleteUnit, ECHO_DIGEST_KEY, getLocalRevision, getMeta, getUnit, loadUnits, META_TABLE, owning, pairScopes, pruneUnknownUnits, REGISTERED_DIGEST_KEY, REPLICA_CURSOR_KEY, replicaCursor, resetUnits, saveUnit, saveUnitScopeSchema, setMeta, unitOwners, } from './state.js';
|
|
@@ -2508,6 +2508,10 @@ export class SyncClient {
|
|
|
2508
2508
|
this.#db.exec(`DELETE FROM ${quoteIdent(tableName)} WHERE ${quoteIdent(table.primaryKey)} IN(${chunk.map(() => '?').join(', ')})`, chunk);
|
|
2509
2509
|
}
|
|
2510
2510
|
}
|
|
2511
|
+
if (scrubPurgedOutcomes(this.#db, (table, rowId, values) => (targetsByTable.get(table) ?? []).some((target) => rowIds.get(table)?.has(rowId) === true ||
|
|
2512
|
+
(values !== undefined &&
|
|
2513
|
+
localDataPurgeTargetMatches(target, values)))))
|
|
2514
|
+
batch.outcomes();
|
|
2511
2515
|
if (doomed.length > 0) {
|
|
2512
2516
|
// §5.11 purge erasure: the journal keeps a dropped commit's identity and codes,
|
|
2513
2517
|
// never its operations, so no purged value survives in it.
|
package/dist/outcomes.d.ts
CHANGED
|
@@ -118,3 +118,9 @@ export declare function activeFailureRecords(outcomes: readonly CommitOutcome[])
|
|
|
118
118
|
readonly conflicts: ConflictRecord[];
|
|
119
119
|
readonly rejections: RejectionRecord[];
|
|
120
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* §5.11 purge erasure: every journal entry with an operation, or a conflict
|
|
123
|
+
* row, that `touches` accepts keeps its identity, status, ids and codes only.
|
|
124
|
+
* Returns whether an entry changed.
|
|
125
|
+
*/
|
|
126
|
+
export declare function scrubPurgedOutcomes(db: ClientDatabase, touches: (table: string, rowId: string, values: Readonly<Record<string, unknown>> | undefined) => boolean): boolean;
|
package/dist/outcomes.js
CHANGED
|
@@ -306,3 +306,67 @@ export function activeFailureRecords(outcomes) {
|
|
|
306
306
|
}
|
|
307
307
|
return { conflicts, rejections };
|
|
308
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* §5.11 purge erasure: every journal entry with an operation, or a conflict
|
|
311
|
+
* row, that `touches` accepts keeps its identity, status, ids and codes only.
|
|
312
|
+
* Returns whether an entry changed.
|
|
313
|
+
*/
|
|
314
|
+
export function scrubPurgedOutcomes(db, touches) {
|
|
315
|
+
let changed = false;
|
|
316
|
+
for (const row of db.query(`SELECT client_commit_id,results,operations FROM ${OUTCOMES_TABLE}`)) {
|
|
317
|
+
const results = JSON.parse(String(row.results));
|
|
318
|
+
const operations = typeof row.operations === 'string'
|
|
319
|
+
? JSON.parse(row.operations)
|
|
320
|
+
: [];
|
|
321
|
+
const named = [
|
|
322
|
+
...operations,
|
|
323
|
+
...results.flatMap((result) => result.status === 'conflict'
|
|
324
|
+
? [
|
|
325
|
+
{
|
|
326
|
+
table: result.conflict.table,
|
|
327
|
+
rowId: result.conflict.rowId,
|
|
328
|
+
values: result.conflict.serverRow,
|
|
329
|
+
},
|
|
330
|
+
...(result.conflict.operation === undefined
|
|
331
|
+
? []
|
|
332
|
+
: [result.conflict.operation]),
|
|
333
|
+
]
|
|
334
|
+
: result.status === 'error' &&
|
|
335
|
+
result.rejection.operation !== undefined
|
|
336
|
+
? [result.rejection.operation]
|
|
337
|
+
: []),
|
|
338
|
+
];
|
|
339
|
+
if (!named.some((op) => touches(op.table, op.rowId, op.values)))
|
|
340
|
+
continue;
|
|
341
|
+
const scrubbed = results.map((result) => {
|
|
342
|
+
if (result.status === 'conflict') {
|
|
343
|
+
const { clientCommitId, opIndex, table, rowId, code, message } = result.conflict;
|
|
344
|
+
return {
|
|
345
|
+
status: 'conflict',
|
|
346
|
+
conflict: {
|
|
347
|
+
clientCommitId,
|
|
348
|
+
opIndex,
|
|
349
|
+
table,
|
|
350
|
+
rowId,
|
|
351
|
+
code,
|
|
352
|
+
message,
|
|
353
|
+
serverVersion: result.conflict.serverVersion,
|
|
354
|
+
serverRow: {},
|
|
355
|
+
conflictColumns: [],
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
if (result.status === 'error') {
|
|
360
|
+
const { clientCommitId, opIndex, code, message, retryable } = result.rejection;
|
|
361
|
+
return {
|
|
362
|
+
status: 'error',
|
|
363
|
+
rejection: { clientCommitId, opIndex, code, message, retryable },
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
});
|
|
368
|
+
db.exec(`UPDATE ${OUTCOMES_TABLE} SET results=?,operations=NULL WHERE client_commit_id=?`, [JSON.stringify(scrubbed), String(row.client_commit_id)]);
|
|
369
|
+
changed = true;
|
|
370
|
+
}
|
|
371
|
+
return changed;
|
|
372
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncular/client",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.3",
|
|
4
4
|
"description": "Syncular TypeScript client core — offline-first sync over SQLite (WASM/OPFS, Bun, Node)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Benjamin Kniffler",
|
|
@@ -121,11 +121,11 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@sqlite.org/sqlite-wasm": "^3.53.0-build1",
|
|
124
|
-
"@syncular/core": "0.70.
|
|
124
|
+
"@syncular/core": "0.70.3"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|
|
127
127
|
"@electric-sql/pglite": "^0.5.4",
|
|
128
|
-
"@syncular/server": "0.70.
|
|
128
|
+
"@syncular/server": "0.70.3",
|
|
129
129
|
"playwright": "1.63.0",
|
|
130
130
|
"vite": "8.3.4"
|
|
131
131
|
}
|
package/src/client.ts
CHANGED
|
@@ -191,6 +191,7 @@ import {
|
|
|
191
191
|
type ResolveCommitOutcomeInput,
|
|
192
192
|
commitOutcome as readCommitOutcome,
|
|
193
193
|
recordCommitOutcome,
|
|
194
|
+
scrubPurgedOutcomes,
|
|
194
195
|
} from './outcomes';
|
|
195
196
|
import {
|
|
196
197
|
buildPreviousVersionAudit,
|
|
@@ -3781,6 +3782,17 @@ export class SyncClient {
|
|
|
3781
3782
|
);
|
|
3782
3783
|
}
|
|
3783
3784
|
}
|
|
3785
|
+
if (
|
|
3786
|
+
scrubPurgedOutcomes(this.#db, (table, rowId, values) =>
|
|
3787
|
+
(targetsByTable.get(table) ?? []).some(
|
|
3788
|
+
(target) =>
|
|
3789
|
+
rowIds.get(table)?.has(rowId) === true ||
|
|
3790
|
+
(values !== undefined &&
|
|
3791
|
+
localDataPurgeTargetMatches(target, values)),
|
|
3792
|
+
),
|
|
3793
|
+
)
|
|
3794
|
+
)
|
|
3795
|
+
batch.outcomes();
|
|
3784
3796
|
|
|
3785
3797
|
if (doomed.length > 0) {
|
|
3786
3798
|
// §5.11 purge erasure: the journal keeps a dropped commit's identity and codes,
|
package/src/outcomes.ts
CHANGED
|
@@ -530,3 +530,86 @@ export function activeFailureRecords(outcomes: readonly CommitOutcome[]): {
|
|
|
530
530
|
}
|
|
531
531
|
return { conflicts, rejections };
|
|
532
532
|
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* §5.11 purge erasure: every journal entry with an operation, or a conflict
|
|
536
|
+
* row, that `touches` accepts keeps its identity, status, ids and codes only.
|
|
537
|
+
* Returns whether an entry changed.
|
|
538
|
+
*/
|
|
539
|
+
export function scrubPurgedOutcomes(
|
|
540
|
+
db: ClientDatabase,
|
|
541
|
+
touches: (
|
|
542
|
+
table: string,
|
|
543
|
+
rowId: string,
|
|
544
|
+
values: Readonly<Record<string, unknown>> | undefined,
|
|
545
|
+
) => boolean,
|
|
546
|
+
): boolean {
|
|
547
|
+
let changed = false;
|
|
548
|
+
for (const row of db.query(
|
|
549
|
+
`SELECT client_commit_id,results,operations FROM ${OUTCOMES_TABLE}`,
|
|
550
|
+
)) {
|
|
551
|
+
const results = JSON.parse(
|
|
552
|
+
String(row.results),
|
|
553
|
+
) as StoredCommitOperationOutcome[];
|
|
554
|
+
const operations =
|
|
555
|
+
typeof row.operations === 'string'
|
|
556
|
+
? (JSON.parse(row.operations) as OutboxOperation[])
|
|
557
|
+
: [];
|
|
558
|
+
const named = [
|
|
559
|
+
...operations,
|
|
560
|
+
...results.flatMap((result) =>
|
|
561
|
+
result.status === 'conflict'
|
|
562
|
+
? [
|
|
563
|
+
{
|
|
564
|
+
table: result.conflict.table,
|
|
565
|
+
rowId: result.conflict.rowId,
|
|
566
|
+
values: result.conflict.serverRow,
|
|
567
|
+
},
|
|
568
|
+
...(result.conflict.operation === undefined
|
|
569
|
+
? []
|
|
570
|
+
: [result.conflict.operation]),
|
|
571
|
+
]
|
|
572
|
+
: result.status === 'error' &&
|
|
573
|
+
result.rejection.operation !== undefined
|
|
574
|
+
? [result.rejection.operation]
|
|
575
|
+
: [],
|
|
576
|
+
),
|
|
577
|
+
];
|
|
578
|
+
if (!named.some((op) => touches(op.table, op.rowId, op.values))) continue;
|
|
579
|
+
const scrubbed: StoredCommitOperationOutcome[] = results.map((result) => {
|
|
580
|
+
if (result.status === 'conflict') {
|
|
581
|
+
const { clientCommitId, opIndex, table, rowId, code, message } =
|
|
582
|
+
result.conflict;
|
|
583
|
+
return {
|
|
584
|
+
status: 'conflict',
|
|
585
|
+
conflict: {
|
|
586
|
+
clientCommitId,
|
|
587
|
+
opIndex,
|
|
588
|
+
table,
|
|
589
|
+
rowId,
|
|
590
|
+
code,
|
|
591
|
+
message,
|
|
592
|
+
serverVersion: result.conflict.serverVersion,
|
|
593
|
+
serverRow: {},
|
|
594
|
+
conflictColumns: [],
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
if (result.status === 'error') {
|
|
599
|
+
const { clientCommitId, opIndex, code, message, retryable } =
|
|
600
|
+
result.rejection;
|
|
601
|
+
return {
|
|
602
|
+
status: 'error',
|
|
603
|
+
rejection: { clientCommitId, opIndex, code, message, retryable },
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
return result;
|
|
607
|
+
});
|
|
608
|
+
db.exec(
|
|
609
|
+
`UPDATE ${OUTCOMES_TABLE} SET results=?,operations=NULL WHERE client_commit_id=?`,
|
|
610
|
+
[JSON.stringify(scrubbed), String(row.client_commit_id)],
|
|
611
|
+
);
|
|
612
|
+
changed = true;
|
|
613
|
+
}
|
|
614
|
+
return changed;
|
|
615
|
+
}
|