@syncular/server 0.83.0 → 0.85.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/dist/d1-storage.js +2 -2
- package/dist/postgres-storage.js +23 -195
- package/dist/push.js +5 -22
- package/dist/schema.d.ts +5 -3
- package/dist/schema.js +16 -7
- package/dist/scopes.d.ts +7 -5
- package/dist/scopes.js +21 -22
- package/dist/sqlite-dialect.d.ts +1 -6
- package/dist/sqlite-dialect.js +3 -186
- package/dist/sqlite-storage.js +8 -2
- package/dist/storage.d.ts +71 -0
- package/dist/storage.js +205 -0
- package/package.json +2 -2
- package/src/d1-storage.ts +6 -4
- package/src/postgres-storage.ts +48 -308
- package/src/push.ts +5 -33
- package/src/schema.ts +32 -10
- package/src/scopes.ts +30 -19
- package/src/sqlite-dialect.ts +18 -257
- package/src/sqlite-storage.ts +8 -6
- package/src/storage.ts +292 -0
package/src/scopes.ts
CHANGED
|
@@ -80,8 +80,9 @@ export function renderScopeValue(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Extract the stored scopes (§3.1) from a decoded row.
|
|
84
|
-
*
|
|
83
|
+
* Extract the stored scopes (§3.1) from a decoded row. A NULL column outside
|
|
84
|
+
* the owner set leaves its variable without a stored scope. Returns the
|
|
85
|
+
* variable name when a column is empty, or NULL in the owner set.
|
|
85
86
|
*/
|
|
86
87
|
export function storedScopesForRow(
|
|
87
88
|
table: CompiledTable,
|
|
@@ -89,7 +90,14 @@ export function storedScopesForRow(
|
|
|
89
90
|
): { scopes: StoredScopes } | { missing: string } {
|
|
90
91
|
const scopes: StoredScopes = {};
|
|
91
92
|
for (const pattern of table.scopePatterns) {
|
|
92
|
-
const
|
|
93
|
+
const raw = values[pattern.columnIndex];
|
|
94
|
+
if (
|
|
95
|
+
(raw === null || raw === undefined) &&
|
|
96
|
+
!table.writeScopeSets[0]!.includes(pattern.variable)
|
|
97
|
+
) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const value = renderScopeValue(raw);
|
|
93
101
|
if (value === undefined) return { missing: pattern.variable };
|
|
94
102
|
scopes[pattern.variable] = value;
|
|
95
103
|
}
|
|
@@ -97,29 +105,32 @@ export function storedScopesForRow(
|
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
/**
|
|
100
|
-
* Write-path authorization (§3.4
|
|
101
|
-
*
|
|
108
|
+
* Write-path authorization (§3.4 step 3): a write set admits the row when
|
|
109
|
+
* each of its variables has a value the actor is allowed (or `'*'`). An
|
|
110
|
+
* insert and a rescope need the owner set; an existing row needs any set.
|
|
102
111
|
*/
|
|
103
112
|
export function authorizeWrite(
|
|
104
113
|
table: CompiledTable,
|
|
105
114
|
rowScopes: StoredScopes,
|
|
106
115
|
resolved: ResolvedScopes,
|
|
116
|
+
ownerOnly = false,
|
|
107
117
|
): boolean {
|
|
108
118
|
if (!resolved.ok) return false;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
const { allowed } = resolved;
|
|
120
|
+
return (
|
|
121
|
+
ownerOnly ? table.writeScopeSets.slice(0, 1) : table.writeScopeSets
|
|
122
|
+
).some((set) =>
|
|
123
|
+
set.every((variable) => {
|
|
124
|
+
const value = rowScopes[variable];
|
|
125
|
+
const values = allowed[variable];
|
|
126
|
+
return (
|
|
127
|
+
value !== undefined &&
|
|
128
|
+
value.length > 0 &&
|
|
129
|
+
values !== undefined &&
|
|
130
|
+
(values.includes('*') || values.includes(value))
|
|
131
|
+
);
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
123
134
|
}
|
|
124
135
|
|
|
125
136
|
/** Does a change's stored scopes match the effective scopes (§3.2)? */
|
package/src/sqlite-dialect.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* promises; the synchronous SQLite driver resolves them with rows it read at
|
|
15
15
|
* call time. Both classes run the identical `test/storage-contract.ts`.
|
|
16
16
|
*/
|
|
17
|
-
import type {
|
|
17
|
+
import type { UnitScopes } from '@syncular/core';
|
|
18
18
|
import {
|
|
19
19
|
bindAuthoritativePartition,
|
|
20
20
|
type BoundAuthoritativeQuery,
|
|
@@ -45,9 +45,18 @@ import type { CompiledTable } from './schema';
|
|
|
45
45
|
import { matchesEffective } from './scopes';
|
|
46
46
|
import type { SqliteValue } from './sqlite-driver';
|
|
47
47
|
import {
|
|
48
|
-
|
|
48
|
+
type ClientRowRecord,
|
|
49
|
+
CLIENT_RECORD_COLUMNS,
|
|
49
50
|
PARTITION_TOUCH_INTERVAL_MS,
|
|
51
|
+
pushResultFromJson,
|
|
52
|
+
pushResultToJson,
|
|
50
53
|
rowsLiveAfterDelete,
|
|
54
|
+
type StoredReactionRecord,
|
|
55
|
+
toClientRecord,
|
|
56
|
+
toStoredChange,
|
|
57
|
+
toStoredReaction,
|
|
58
|
+
toStoredRow,
|
|
59
|
+
toTombstone,
|
|
51
60
|
} from './storage';
|
|
52
61
|
import type {
|
|
53
62
|
AuthoritativeQueryRequest,
|
|
@@ -61,7 +70,6 @@ import type {
|
|
|
61
70
|
CommitMetadataQuery,
|
|
62
71
|
CommitPruneQuery,
|
|
63
72
|
CommitPruneResult,
|
|
64
|
-
DurableJsonValue,
|
|
65
73
|
IndexRowScanQuery,
|
|
66
74
|
LiveWindow,
|
|
67
75
|
LiveWindowQuery,
|
|
@@ -73,7 +81,6 @@ import type {
|
|
|
73
81
|
PrunedReactionCounts,
|
|
74
82
|
PushWatermark,
|
|
75
83
|
ReactionClaimQuery,
|
|
76
|
-
ReactionFailure,
|
|
77
84
|
ReactionFailureUpdate,
|
|
78
85
|
ReactionListQuery,
|
|
79
86
|
ReactionPruneQuery,
|
|
@@ -85,7 +92,6 @@ import type {
|
|
|
85
92
|
ScopeCommitActivity,
|
|
86
93
|
ScopeValueHistoryQuery,
|
|
87
94
|
ScopeValueQuery,
|
|
88
|
-
StoredChange,
|
|
89
95
|
StoredPushResult,
|
|
90
96
|
StoredReaction,
|
|
91
97
|
StoredRow,
|
|
@@ -350,124 +356,15 @@ export function placeholders(count: number): string {
|
|
|
350
356
|
|
|
351
357
|
// -- value (de)serialization, shared by both SQLite storages ----------------
|
|
352
358
|
|
|
353
|
-
/** Runtime-neutral base64 (no `Buffer` — Workers-safe) for push results. */
|
|
354
|
-
function bytesToBase64(bytes: Uint8Array): string {
|
|
355
|
-
let binary = '';
|
|
356
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
357
|
-
return btoa(binary);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function base64ToBytes(text: string): Uint8Array {
|
|
361
|
-
const binary = atob(text);
|
|
362
|
-
const bytes = new Uint8Array(binary.length);
|
|
363
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
364
|
-
return bytes;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
interface SerializedResult {
|
|
368
|
-
opIndex: number;
|
|
369
|
-
status: string;
|
|
370
|
-
code?: string;
|
|
371
|
-
message?: string;
|
|
372
|
-
serverVersion?: number;
|
|
373
|
-
serverRow?: string;
|
|
374
|
-
conflictColumns?: string;
|
|
375
|
-
retryable?: boolean;
|
|
376
|
-
details?: import('@syncular/core').RejectionDetails;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
359
|
/** Serialize a push result to the JSON `TEXT` stored in `sync_push_results`. */
|
|
380
360
|
export function serializePushResult(result: StoredPushResult): string {
|
|
381
|
-
return JSON.stringify(
|
|
382
|
-
status: result.status,
|
|
383
|
-
...(result.commitSeq !== undefined ? { commitSeq: result.commitSeq } : {}),
|
|
384
|
-
...(result.recordedAtMs !== undefined
|
|
385
|
-
? { recordedAtMs: result.recordedAtMs }
|
|
386
|
-
: {}),
|
|
387
|
-
...(result.cacheIdentity !== undefined
|
|
388
|
-
? { cacheIdentity: result.cacheIdentity }
|
|
389
|
-
: {}),
|
|
390
|
-
...(result.conflictAuthorization !== undefined
|
|
391
|
-
? { conflictAuthorization: result.conflictAuthorization }
|
|
392
|
-
: {}),
|
|
393
|
-
results: result.results.map((record) => {
|
|
394
|
-
if (record.status === 'conflict') {
|
|
395
|
-
return {
|
|
396
|
-
opIndex: record.opIndex,
|
|
397
|
-
status: record.status,
|
|
398
|
-
code: record.code,
|
|
399
|
-
message: record.message,
|
|
400
|
-
serverVersion: record.serverVersion,
|
|
401
|
-
serverRow: bytesToBase64(record.serverRow),
|
|
402
|
-
conflictColumns: bytesToBase64(record.conflictColumns),
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
if (record.status === 'error') {
|
|
406
|
-
return {
|
|
407
|
-
opIndex: record.opIndex,
|
|
408
|
-
status: record.status,
|
|
409
|
-
code: record.code,
|
|
410
|
-
message: record.message,
|
|
411
|
-
retryable: record.retryable,
|
|
412
|
-
...(record.details !== undefined ? { details: record.details } : {}),
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
return { opIndex: record.opIndex, status: record.status };
|
|
416
|
-
}),
|
|
417
|
-
});
|
|
361
|
+
return JSON.stringify(pushResultToJson(result));
|
|
418
362
|
}
|
|
419
363
|
|
|
420
364
|
/** Parse a stored push result; an unreadable record is a §6.3 cache miss. */
|
|
421
365
|
export function deserializePushResult(text: string): StoredPushResult {
|
|
422
366
|
try {
|
|
423
|
-
|
|
424
|
-
status: 'applied' | 'rejected';
|
|
425
|
-
commitSeq?: number;
|
|
426
|
-
recordedAtMs?: number;
|
|
427
|
-
cacheIdentity?: string;
|
|
428
|
-
conflictAuthorization?: StoredPushResult['conflictAuthorization'];
|
|
429
|
-
results: SerializedResult[];
|
|
430
|
-
};
|
|
431
|
-
const results: PushOperationResult[] = parsed.results.map((record) => {
|
|
432
|
-
if (record.status === 'conflict') {
|
|
433
|
-
return {
|
|
434
|
-
opIndex: record.opIndex,
|
|
435
|
-
status: 'conflict',
|
|
436
|
-
code: record.code ?? '',
|
|
437
|
-
message: record.message ?? '',
|
|
438
|
-
serverVersion: record.serverVersion ?? 0,
|
|
439
|
-
serverRow: base64ToBytes(record.serverRow ?? ''),
|
|
440
|
-
conflictColumns: base64ToBytes(record.conflictColumns ?? ''),
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
if (record.status === 'error') {
|
|
444
|
-
return {
|
|
445
|
-
opIndex: record.opIndex,
|
|
446
|
-
status: 'error',
|
|
447
|
-
code: record.code ?? '',
|
|
448
|
-
message: record.message ?? '',
|
|
449
|
-
retryable: record.retryable ?? false,
|
|
450
|
-
...(record.details !== undefined ? { details: record.details } : {}),
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
return { opIndex: record.opIndex, status: 'applied' };
|
|
454
|
-
});
|
|
455
|
-
return {
|
|
456
|
-
status: parsed.status,
|
|
457
|
-
...(parsed.commitSeq !== undefined
|
|
458
|
-
? { commitSeq: parsed.commitSeq }
|
|
459
|
-
: {}),
|
|
460
|
-
...(parsed.recordedAtMs !== undefined
|
|
461
|
-
? { recordedAtMs: parsed.recordedAtMs }
|
|
462
|
-
: {}),
|
|
463
|
-
...(parsed.cacheIdentity !== undefined
|
|
464
|
-
? { cacheIdentity: parsed.cacheIdentity }
|
|
465
|
-
: {}),
|
|
466
|
-
...(parsed.conflictAuthorization !== undefined
|
|
467
|
-
? { conflictAuthorization: parsed.conflictAuthorization }
|
|
468
|
-
: {}),
|
|
469
|
-
results,
|
|
470
|
-
};
|
|
367
|
+
return pushResultFromJson(JSON.parse(text));
|
|
471
368
|
} catch {
|
|
472
369
|
throw syncError(
|
|
473
370
|
'sync.idempotency_cache_miss',
|
|
@@ -494,148 +391,12 @@ export interface SqliteChangeRecord {
|
|
|
494
391
|
payload: Uint8Array | null;
|
|
495
392
|
}
|
|
496
393
|
|
|
497
|
-
/** Native SQLite returns `Uint8Array`; D1 returns `ArrayBuffer` for BLOBs. */
|
|
498
|
-
export function asUint8Array(value: unknown): Uint8Array {
|
|
499
|
-
if (value instanceof Uint8Array) return value;
|
|
500
|
-
if (value instanceof ArrayBuffer) return new Uint8Array(value);
|
|
501
|
-
if (Array.isArray(value)) return new Uint8Array(value);
|
|
502
|
-
throw new Error(`expected a BLOB column, got ${typeof value}`);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
export function toStoredRow(record: SqliteRowRecord): StoredRow {
|
|
506
|
-
return {
|
|
507
|
-
rowId: record.row_id,
|
|
508
|
-
serverVersion: record.server_version,
|
|
509
|
-
scopes: JSON.parse(record.scopes) as Record<string, string>,
|
|
510
|
-
payload: asUint8Array(record.payload),
|
|
511
|
-
...(record.column_versions !== null
|
|
512
|
-
? { columnVersions: asUint8Array(record.column_versions) }
|
|
513
|
-
: {}),
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
|
|
517
394
|
export interface SqliteTombstoneRecord {
|
|
518
395
|
commit_seq: number;
|
|
519
396
|
server_version: number | null;
|
|
520
397
|
scopes: string | null;
|
|
521
398
|
}
|
|
522
399
|
|
|
523
|
-
export function toTombstone(record: SqliteTombstoneRecord): Tombstone {
|
|
524
|
-
return {
|
|
525
|
-
commitSeq: record.commit_seq,
|
|
526
|
-
...(record.server_version !== null
|
|
527
|
-
? { serverVersion: record.server_version }
|
|
528
|
-
: {}),
|
|
529
|
-
...(record.scopes !== null
|
|
530
|
-
? { scopes: JSON.parse(record.scopes) as Record<string, string> }
|
|
531
|
-
: {}),
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
export function toStoredChange(record: SqliteChangeRecord): StoredChange {
|
|
536
|
-
return {
|
|
537
|
-
table: record.tbl,
|
|
538
|
-
rowId: record.row_id,
|
|
539
|
-
op: record.op === 1 ? 'upsert' : 'delete',
|
|
540
|
-
...(record.row_version !== null ? { rowVersion: record.row_version } : {}),
|
|
541
|
-
scopes: JSON.parse(record.scopes) as Record<string, string>,
|
|
542
|
-
...(record.payload !== null
|
|
543
|
-
? { payload: asUint8Array(record.payload) }
|
|
544
|
-
: {}),
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
interface SqliteReactionRecord {
|
|
549
|
-
idempotency_key: string;
|
|
550
|
-
type: string;
|
|
551
|
-
version: number;
|
|
552
|
-
payload: string;
|
|
553
|
-
source_client_id: string;
|
|
554
|
-
source_client_commit_id: string;
|
|
555
|
-
source_commit_seq: number;
|
|
556
|
-
created_at_ms: number;
|
|
557
|
-
available_at_ms: number;
|
|
558
|
-
status: StoredReaction['status'];
|
|
559
|
-
attempts: number;
|
|
560
|
-
max_attempts: number;
|
|
561
|
-
lease_owner: string | null;
|
|
562
|
-
lease_expires_at_ms: number | null;
|
|
563
|
-
completed_at_ms: number | null;
|
|
564
|
-
last_failure: string | null;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function toStoredReaction(record: SqliteReactionRecord): StoredReaction {
|
|
568
|
-
return {
|
|
569
|
-
idempotencyKey: record.idempotency_key,
|
|
570
|
-
type: record.type,
|
|
571
|
-
version: record.version,
|
|
572
|
-
payload: JSON.parse(record.payload) as DurableJsonValue,
|
|
573
|
-
sourceClientId: record.source_client_id,
|
|
574
|
-
sourceClientCommitId: record.source_client_commit_id,
|
|
575
|
-
sourceCommitSeq: record.source_commit_seq,
|
|
576
|
-
createdAtMs: record.created_at_ms,
|
|
577
|
-
maxAttempts: record.max_attempts,
|
|
578
|
-
status: record.status,
|
|
579
|
-
attempts: record.attempts,
|
|
580
|
-
availableAtMs: record.available_at_ms,
|
|
581
|
-
...(record.lease_owner !== null ? { leaseOwner: record.lease_owner } : {}),
|
|
582
|
-
...(record.lease_expires_at_ms !== null
|
|
583
|
-
? { leaseExpiresAtMs: record.lease_expires_at_ms }
|
|
584
|
-
: {}),
|
|
585
|
-
...(record.completed_at_ms !== null
|
|
586
|
-
? { completedAtMs: record.completed_at_ms }
|
|
587
|
-
: {}),
|
|
588
|
-
...(record.last_failure !== null
|
|
589
|
-
? { lastFailure: JSON.parse(record.last_failure) as ReactionFailure }
|
|
590
|
-
: {}),
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
interface SqliteClientRecord {
|
|
595
|
-
client_id: string;
|
|
596
|
-
actor_id: string;
|
|
597
|
-
wire_version: number;
|
|
598
|
-
cursor: number;
|
|
599
|
-
updated_at_ms: number;
|
|
600
|
-
schema_version: number | null;
|
|
601
|
-
units: string | null;
|
|
602
|
-
registration_digest: Uint8Array | null;
|
|
603
|
-
catching_up: string;
|
|
604
|
-
last_round_at_ms: number | null;
|
|
605
|
-
last_error_code: string | null;
|
|
606
|
-
consecutive_failures: number;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
const CLIENT_RECORD_COLUMNS =
|
|
610
|
-
'client_id, actor_id, wire_version, cursor, updated_at_ms, schema_version, units, registration_digest, catching_up, last_round_at_ms, last_error_code, consecutive_failures';
|
|
611
|
-
|
|
612
|
-
function toClientRecord(record: SqliteClientRecord): ClientRecord {
|
|
613
|
-
return {
|
|
614
|
-
clientId: record.client_id,
|
|
615
|
-
actorId: record.actor_id,
|
|
616
|
-
wireVersion: record.wire_version,
|
|
617
|
-
cursor: record.cursor,
|
|
618
|
-
updatedAtMs: record.updated_at_ms,
|
|
619
|
-
...(record.schema_version !== null
|
|
620
|
-
? { schemaVersion: record.schema_version }
|
|
621
|
-
: {}),
|
|
622
|
-
...(record.units !== null && record.registration_digest !== null
|
|
623
|
-
? {
|
|
624
|
-
registration: {
|
|
625
|
-
units: JSON.parse(record.units) as UnitScopes[],
|
|
626
|
-
digest: asUint8Array(record.registration_digest),
|
|
627
|
-
},
|
|
628
|
-
}
|
|
629
|
-
: {}),
|
|
630
|
-
catchingUp: JSON.parse(record.catching_up) as ClientRecord['catchingUp'],
|
|
631
|
-
...clientRoundState(
|
|
632
|
-
record.last_round_at_ms,
|
|
633
|
-
record.last_error_code,
|
|
634
|
-
record.consecutive_failures,
|
|
635
|
-
),
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
|
|
639
400
|
interface SqlitePartitionRegistryRecord {
|
|
640
401
|
partition: string;
|
|
641
402
|
log_epoch: string;
|
|
@@ -978,7 +739,7 @@ export abstract class SqliteFamilyStorage {
|
|
|
978
739
|
if (query.types.length + 7 > this.maxBindParams) {
|
|
979
740
|
throw new Error('D1 reaction claim exceeds the bound-parameter limit');
|
|
980
741
|
}
|
|
981
|
-
const records = await this.all<
|
|
742
|
+
const records = await this.all<StoredReactionRecord>(
|
|
982
743
|
`UPDATE sync_reactions
|
|
983
744
|
SET status='leased', attempts=attempts+1,
|
|
984
745
|
lease_owner=?, lease_expires_at_ms=?, completed_at_ms=NULL
|
|
@@ -1092,7 +853,7 @@ export abstract class SqliteFamilyStorage {
|
|
|
1092
853
|
partition: string,
|
|
1093
854
|
idempotencyKey: string,
|
|
1094
855
|
): Promise<StoredReaction | undefined> {
|
|
1095
|
-
const [record] = await this.all<
|
|
856
|
+
const [record] = await this.all<StoredReactionRecord>(
|
|
1096
857
|
'SELECT * FROM sync_reactions WHERE partition=? AND idempotency_key=?',
|
|
1097
858
|
[partition, idempotencyKey],
|
|
1098
859
|
);
|
|
@@ -1117,7 +878,7 @@ export abstract class SqliteFamilyStorage {
|
|
|
1117
878
|
throw new Error('D1 reaction list exceeds the bound-parameter limit');
|
|
1118
879
|
}
|
|
1119
880
|
params.push(query.limit);
|
|
1120
|
-
const records = await this.all<
|
|
881
|
+
const records = await this.all<StoredReactionRecord>(
|
|
1121
882
|
`SELECT * FROM sync_reactions WHERE ${where.join(' AND ')}
|
|
1122
883
|
ORDER BY created_at_ms DESC, idempotency_key DESC LIMIT ?`,
|
|
1123
884
|
params,
|
|
@@ -1348,7 +1109,7 @@ export abstract class SqliteFamilyStorage {
|
|
|
1348
1109
|
partition: string,
|
|
1349
1110
|
clientId: string,
|
|
1350
1111
|
): Promise<ClientRecord | undefined> {
|
|
1351
|
-
const [record] = await this.all<
|
|
1112
|
+
const [record] = await this.all<ClientRowRecord>(
|
|
1352
1113
|
`SELECT ${CLIENT_RECORD_COLUMNS} FROM sync_clients WHERE partition=? AND client_id=?`,
|
|
1353
1114
|
[partition, clientId],
|
|
1354
1115
|
);
|
|
@@ -1582,7 +1343,7 @@ export abstract class SqliteFamilyStorage {
|
|
|
1582
1343
|
|
|
1583
1344
|
async listClientRecords(partition: string): Promise<ClientRecord[]> {
|
|
1584
1345
|
return (
|
|
1585
|
-
await this.all<
|
|
1346
|
+
await this.all<ClientRowRecord>(
|
|
1586
1347
|
`SELECT ${CLIENT_RECORD_COLUMNS} FROM sync_clients WHERE partition=? ORDER BY updated_at_ms DESC`,
|
|
1587
1348
|
[partition],
|
|
1588
1349
|
)
|
package/src/sqlite-storage.ts
CHANGED
|
@@ -511,9 +511,10 @@ END`);
|
|
|
511
511
|
)
|
|
512
512
|
.get();
|
|
513
513
|
if (marker !== null && marker.schema_version > schema.version) {
|
|
514
|
-
throw new
|
|
515
|
-
|
|
516
|
-
|
|
514
|
+
throw new StorageQueryError('sync.storage.schema_changed', {
|
|
515
|
+
storedVersion: String(marker.schema_version),
|
|
516
|
+
configuredVersion: String(schema.version),
|
|
517
|
+
});
|
|
517
518
|
}
|
|
518
519
|
if (marker !== null && marker.schema_version === schema.version) {
|
|
519
520
|
assertStoredLayouts(schema, marker.layouts);
|
|
@@ -627,9 +628,10 @@ END`);
|
|
|
627
628
|
)
|
|
628
629
|
.get();
|
|
629
630
|
if (locked !== null && locked.schema_version > schema.version) {
|
|
630
|
-
throw new
|
|
631
|
-
|
|
632
|
-
|
|
631
|
+
throw new StorageQueryError('sync.storage.schema_changed', {
|
|
632
|
+
storedVersion: String(locked.schema_version),
|
|
633
|
+
configuredVersion: String(schema.version),
|
|
634
|
+
});
|
|
633
635
|
}
|
|
634
636
|
if (locked !== null && locked.schema_version === schema.version) {
|
|
635
637
|
this.db.exec('COMMIT');
|