@syncular/server 0.58.0 → 0.60.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/README.md +49 -36
- package/dist/admin.d.ts +32 -20
- package/dist/admin.js +46 -40
- package/dist/blob-handlers.d.ts +25 -31
- package/dist/blob-handlers.js +63 -41
- package/dist/blob-store.d.ts +42 -24
- package/dist/blob-store.js +0 -0
- package/dist/bucket-blob-store.d.ts +12 -8
- package/dist/bucket-blob-store.js +54 -45
- package/dist/bucket-segment-store.js +18 -16
- package/dist/content-encoding.d.ts +5 -2
- package/dist/content-encoding.js +42 -13
- package/dist/context.d.ts +19 -5
- package/dist/context.js +19 -1
- package/dist/d1-storage.d.ts +14 -98
- package/dist/d1-storage.js +249 -1119
- package/dist/errors.js +16 -0
- package/dist/events.d.ts +36 -18
- package/dist/frame-bytes.js +24 -6
- package/dist/handler.js +503 -208
- package/dist/local-authority.d.ts +2 -0
- package/dist/local-authority.js +24 -12
- package/dist/object-bucket.d.ts +2 -0
- package/dist/operations-realtime.js +69 -50
- package/dist/operations.d.ts +5 -2
- package/dist/operations.js +20 -29
- package/dist/pg-executor-pglite.d.ts +5 -6
- package/dist/pg-executor-pglite.js +22 -14
- package/dist/pg-executor.d.ts +4 -1
- package/dist/postgres-storage.d.ts +24 -19
- package/dist/postgres-storage.js +420 -262
- package/dist/pull.d.ts +70 -47
- package/dist/pull.js +270 -301
- package/dist/push.d.ts +12 -3
- package/dist/push.js +361 -173
- package/dist/realtime.d.ts +85 -39
- package/dist/realtime.js +355 -219
- package/dist/relational-rows.d.ts +21 -66
- package/dist/relational-rows.js +28 -109
- package/dist/s3-blob-store.d.ts +11 -12
- package/dist/s3-blob-store.js +20 -13
- package/dist/s3-object-bucket.d.ts +8 -1
- package/dist/s3-object-bucket.js +16 -3
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +23 -0
- package/dist/scopes.d.ts +6 -2
- package/dist/scopes.js +22 -4
- package/dist/seed.js +10 -16
- package/dist/segment-download.d.ts +4 -1
- package/dist/segment-download.js +22 -6
- package/dist/signed-url.d.ts +2 -2
- package/dist/signed-url.js +9 -2
- package/dist/sigv4.d.ts +8 -2
- package/dist/sigv4.js +8 -4
- package/dist/sqlite-blob-store.d.ts +1 -1
- package/dist/sqlite-blob-store.js +23 -22
- package/dist/sqlite-dialect.d.ts +164 -84
- package/dist/sqlite-dialect.js +1145 -150
- package/dist/sqlite-lease-store.js +13 -18
- package/dist/sqlite-storage.d.ts +9 -62
- package/dist/sqlite-storage.js +303 -1123
- package/dist/storage-query.d.ts +30 -1
- package/dist/storage-query.js +68 -0
- package/dist/storage.d.ts +185 -63
- package/dist/storage.js +15 -0
- package/package.json +2 -2
- package/src/admin.ts +99 -57
- package/src/blob-handlers.ts +91 -72
- package/src/blob-store.ts +0 -0
- package/src/bucket-blob-store.ts +75 -48
- package/src/bucket-segment-store.ts +20 -15
- package/src/content-encoding.ts +48 -16
- package/src/context.ts +33 -6
- package/src/d1-storage.ts +350 -1700
- package/src/errors.ts +16 -0
- package/src/events.ts +37 -18
- package/src/frame-bytes.ts +26 -6
- package/src/handler.ts +654 -261
- package/src/local-authority.ts +27 -14
- package/src/object-bucket.ts +2 -0
- package/src/operations-realtime.ts +85 -61
- package/src/operations.ts +44 -42
- package/src/pg-executor-pglite.ts +27 -23
- package/src/pg-executor.ts +5 -1
- package/src/postgres-storage.ts +557 -354
- package/src/pull.ts +406 -440
- package/src/push.ts +466 -220
- package/src/realtime.ts +447 -290
- package/src/relational-rows.ts +43 -121
- package/src/s3-blob-store.ts +23 -13
- package/src/s3-object-bucket.ts +20 -2
- package/src/schema.ts +31 -0
- package/src/scopes.ts +23 -3
- package/src/seed.ts +13 -20
- package/src/segment-download.ts +33 -7
- package/src/signed-url.ts +10 -4
- package/src/sigv4.ts +17 -4
- package/src/sqlite-blob-store.ts +27 -26
- package/src/sqlite-dialect.ts +1851 -199
- package/src/sqlite-lease-store.ts +12 -23
- package/src/sqlite-storage.ts +390 -1821
- package/src/storage-query.ts +102 -0
- package/src/storage.ts +215 -67
|
@@ -17,7 +17,6 @@ export class SqliteLeaseStore {
|
|
|
17
17
|
lease_id TEXT NOT NULL, actor_id TEXT NOT NULL,
|
|
18
18
|
allowed_scopes TEXT NOT NULL,
|
|
19
19
|
issued_at_ms INTEGER NOT NULL, expires_at_ms INTEGER NOT NULL,
|
|
20
|
-
revoked INTEGER NOT NULL DEFAULT 0,
|
|
21
20
|
PRIMARY KEY (partition, client_id)
|
|
22
21
|
);
|
|
23
22
|
CREATE TABLE IF NOT EXISTS sync_lease_revocations(
|
|
@@ -28,9 +27,15 @@ export class SqliteLeaseStore {
|
|
|
28
27
|
}
|
|
29
28
|
async get(partition, clientId) {
|
|
30
29
|
const row = this.db
|
|
31
|
-
.query(
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
.query(
|
|
31
|
+
// §7.3.4: the revocation table is the only record of a revocation, so
|
|
32
|
+
// a revoked id stays revoked whatever its lease row says.
|
|
33
|
+
`SELECT l.lease_id, l.actor_id, l.allowed_scopes, l.issued_at_ms,
|
|
34
|
+
l.expires_at_ms,
|
|
35
|
+
EXISTS (SELECT 1 FROM sync_lease_revocations r
|
|
36
|
+
WHERE r.partition=l.partition
|
|
37
|
+
AND r.lease_id=l.lease_id) AS revoked
|
|
38
|
+
FROM sync_leases l WHERE l.partition=? AND l.client_id=?`)
|
|
34
39
|
.get(partition, clientId);
|
|
35
40
|
if (row === null)
|
|
36
41
|
return undefined;
|
|
@@ -43,18 +48,11 @@ export class SqliteLeaseStore {
|
|
|
43
48
|
revoked: row.revoked !== 0,
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
|
-
#isRevoked(partition, leaseId) {
|
|
47
|
-
const row = this.db
|
|
48
|
-
.query('SELECT 1 AS n FROM sync_lease_revocations WHERE partition=? AND lease_id=?')
|
|
49
|
-
.get(partition, leaseId);
|
|
50
|
-
return row !== null;
|
|
51
|
-
}
|
|
52
51
|
async issue(partition, clientId, actorId, allowedScopes, nowMs, ttlMs) {
|
|
53
52
|
const existing = await this.get(partition, clientId);
|
|
54
53
|
const reuse = existing !== undefined &&
|
|
55
54
|
existing.actorId === actorId &&
|
|
56
|
-
!existing.revoked
|
|
57
|
-
!this.#isRevoked(partition, existing.leaseId);
|
|
55
|
+
!existing.revoked;
|
|
58
56
|
const leaseId = reuse ? existing.leaseId : this.#newId();
|
|
59
57
|
const record = {
|
|
60
58
|
leaseId,
|
|
@@ -67,13 +65,13 @@ export class SqliteLeaseStore {
|
|
|
67
65
|
this.db
|
|
68
66
|
.query(`INSERT INTO sync_leases(
|
|
69
67
|
partition, client_id, lease_id, actor_id, allowed_scopes,
|
|
70
|
-
issued_at_ms, expires_at_ms
|
|
71
|
-
) VALUES (
|
|
68
|
+
issued_at_ms, expires_at_ms
|
|
69
|
+
) VALUES (?,?,?,?,?,?,?)
|
|
72
70
|
ON CONFLICT(partition, client_id) DO UPDATE SET
|
|
73
71
|
lease_id=excluded.lease_id, actor_id=excluded.actor_id,
|
|
74
72
|
allowed_scopes=excluded.allowed_scopes,
|
|
75
73
|
issued_at_ms=excluded.issued_at_ms,
|
|
76
|
-
expires_at_ms=excluded.expires_at_ms
|
|
74
|
+
expires_at_ms=excluded.expires_at_ms`)
|
|
77
75
|
.run(partition, clientId, leaseId, actorId, JSON.stringify(allowedScopes), nowMs, record.expiresAtMs);
|
|
78
76
|
return record;
|
|
79
77
|
}
|
|
@@ -82,8 +80,5 @@ export class SqliteLeaseStore {
|
|
|
82
80
|
.query(`INSERT OR IGNORE INTO sync_lease_revocations(partition, lease_id)
|
|
83
81
|
VALUES (?,?)`)
|
|
84
82
|
.run(partition, leaseId);
|
|
85
|
-
this.db
|
|
86
|
-
.query('UPDATE sync_leases SET revoked=1 WHERE partition=? AND lease_id=?')
|
|
87
|
-
.run(partition, leaseId);
|
|
88
83
|
}
|
|
89
84
|
}
|
package/dist/sqlite-storage.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export declare class SqliteServerStorage implements ServerStorage {
|
|
1
|
+
import type { CompiledSchema } from './schema.js';
|
|
2
|
+
import { SqliteFamilyStorage, type SqliteStatementSpec } from './sqlite-dialect.js';
|
|
3
|
+
import { type SqliteDatabase, type SqliteValue } from './sqlite-driver.js';
|
|
4
|
+
import type { AuthoritativeQueryRequest, AuthoritativeQueryResult, CheckpointDeclaration, ServerStorage, ServeGate, StorageTransaction, StoredCheckpoint } from './storage.js';
|
|
5
|
+
export declare class SqliteServerStorage extends SqliteFamilyStorage implements ServerStorage {
|
|
7
6
|
#private;
|
|
8
7
|
readonly db: SqliteDatabase;
|
|
8
|
+
protected readonly maxBindParams: number;
|
|
9
9
|
constructor(db?: SqliteDatabase | string);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
protected all<T>(sql: string, params: readonly SqliteValue[]): Promise<T[]>;
|
|
11
|
+
protected guardedAll<T>(sql: string, params: readonly SqliteValue[]): Promise<T[]>;
|
|
12
|
+
protected atomic(statements: readonly SqliteStatementSpec[]): Promise<unknown[][]>;
|
|
12
13
|
ensureSchema(schema: CompiledSchema, checkpoints?: readonly CheckpointDeclaration[]): Promise<void>;
|
|
13
|
-
touchPartition(partition: string, authenticatedAtMs: number, initialLogEpoch: string): Promise<PartitionRegistryEntry>;
|
|
14
|
-
rotatePartitionLogEpoch(partition: string, logEpoch: string, authenticatedAtMs: number): Promise<PartitionRegistryEntry>;
|
|
15
|
-
listPartitionRegistry(): Promise<PartitionRegistryEntry[]>;
|
|
16
14
|
begin(partition: string): Promise<StorageTransaction>;
|
|
17
|
-
/** Internal: write a row + refresh its scope-index entries. */
|
|
18
|
-
writeRow(partition: string, table: string, row: StoredRow): void;
|
|
19
|
-
getMaxCommitSeq(partition: string): Promise<number>;
|
|
20
15
|
/**
|
|
21
16
|
* Internal: rewrite and run one registered query on the shared connection.
|
|
22
17
|
* The caller owns the transaction: `queryAuthoritative` opens a read
|
|
@@ -25,58 +20,10 @@ export declare class SqliteServerStorage implements ServerStorage {
|
|
|
25
20
|
*/
|
|
26
21
|
runAuthoritativeQuery(partition: string, query: AuthoritativeQueryRequest): AuthoritativeQueryResult;
|
|
27
22
|
queryAuthoritative(partition: string, query: AuthoritativeQueryRequest, checkpoints?: readonly CheckpointDeclaration[]): Promise<AuthoritativeQueryResult>;
|
|
28
|
-
getPartitionLogEpoch(partition: string): Promise<string | undefined>;
|
|
29
|
-
getHorizonSeq(partition: string): Promise<number>;
|
|
30
|
-
setHorizonSeq(partition: string, seq: number): Promise<void>;
|
|
31
|
-
pruneCommitsThrough(partition: string, query: CommitPruneQuery): Promise<CommitPruneResult>;
|
|
32
|
-
getCommitSeqBefore(partition: string, createdBeforeMs: number): Promise<number>;
|
|
33
23
|
readServeGate(partition: string, runningSchemaVersion: number): Promise<ServeGate>;
|
|
34
24
|
readCheckpoints(partition: string): Promise<StoredCheckpoint[]>;
|
|
35
25
|
declareCheckpoint(partition: string, name: string, schemaVersion: number, nowMs: number): Promise<StoredCheckpoint>;
|
|
36
26
|
activateCheckpoint(partition: string, name: string, ownerEpoch: number, watermark: number, sources: readonly string[], nowMs: number): Promise<'activated' | 'stale' | 'unverifiable'>;
|
|
37
27
|
claimCheckpoint(partition: string, name: string, schemaVersion: number, nowMs: number): Promise<StoredCheckpoint>;
|
|
38
28
|
advanceCheckpoint(partition: string, name: string, ownerEpoch: number, watermark: number, observedRows: number, nowMs: number): Promise<boolean>;
|
|
39
|
-
sourceCoverageSeq(partition: string, tables: readonly string[]): Promise<number>;
|
|
40
|
-
hasSourceChangesAbove(partition: string, tables: readonly string[], seq: number): Promise<'clean' | 'changed' | 'unverifiable'>;
|
|
41
|
-
getRow(partition: string, table: string, rowId: string): Promise<StoredRow | undefined>;
|
|
42
|
-
getPushResult(partition: string, clientId: string, clientCommitId: string): Promise<StoredPushResult | undefined>;
|
|
43
|
-
claimReactions(partition: string, query: ReactionClaimQuery): Promise<StoredReaction[]>;
|
|
44
|
-
completeReaction(partition: string, idempotencyKey: string, leaseOwner: string, completedAtMs: number): Promise<boolean>;
|
|
45
|
-
extendReactionLease(partition: string, idempotencyKey: string, leaseOwner: string, leaseExpiresAtMs: number): Promise<boolean>;
|
|
46
|
-
failReaction(partition: string, idempotencyKey: string, update: ReactionFailureUpdate): Promise<boolean>;
|
|
47
|
-
retryReaction(partition: string, idempotencyKey: string, nowMs: number): Promise<boolean>;
|
|
48
|
-
getReaction(partition: string, idempotencyKey: string): Promise<StoredReaction | undefined>;
|
|
49
|
-
listReactions(partition: string, query: ReactionListQuery): Promise<StoredReaction[]>;
|
|
50
|
-
pruneReactions(partition: string, query: ReactionPruneQuery): Promise<PrunedReactionCounts>;
|
|
51
|
-
latestScopedChangeSeq(partition: string, query: {
|
|
52
|
-
readonly table: string;
|
|
53
|
-
readonly scopeFilter: ScopeMap;
|
|
54
|
-
}): Promise<number>;
|
|
55
|
-
readCommitWindow(partition: string, query: CommitWindowQuery): Promise<StoredCommit[]>;
|
|
56
|
-
scanRows(partition: string, query: RowScanQuery): Promise<StoredRow[]>;
|
|
57
|
-
scanRowsByIndex(partition: string, query: IndexRowScanQuery): Promise<StoredRow[]>;
|
|
58
|
-
getClientRecord(partition: string, clientId: string): Promise<ClientRecord | undefined>;
|
|
59
|
-
putClientRecord(partition: string, record: ClientRecord, options?: ClientRecordWriteOptions): Promise<void>;
|
|
60
|
-
recordClientRoundFailure(partition: string, clientId: string, actorId: string, errorCode: string, atMs: number): Promise<void>;
|
|
61
|
-
advanceClientCursor(partition: string, clientId: string, actorId: string, logEpoch: string, cursor: number, updatedAtMs: number): Promise<void>;
|
|
62
|
-
updateClientCursor(partition: string, clientId: string, cursor: number, updatedAtMs: number): Promise<void>;
|
|
63
|
-
getActiveClientCursorFloor(partition: string, cutoffMs: number): Promise<number | null>;
|
|
64
|
-
listClientCursors(partition: string): Promise<ClientCursorInfo[]>;
|
|
65
|
-
listRowsReferencingBlob(partition: string, blobId: string): Promise<{
|
|
66
|
-
readonly table: string;
|
|
67
|
-
readonly rowId: string;
|
|
68
|
-
readonly scopes: Record<string, string>;
|
|
69
|
-
}[]>;
|
|
70
|
-
listReferencedBlobIds(partition: string): Promise<string[]>;
|
|
71
|
-
listScopeValueRows(partition: string, query: ScopeValueQuery): Promise<string[]>;
|
|
72
|
-
eraseScopeValueHistory(partition: string, query: ScopeValueHistoryQuery): Promise<number>;
|
|
73
|
-
listClientRecords(partition: string): Promise<ClientRecord[]>;
|
|
74
|
-
listCommitMetadata(partition: string, query: CommitMetadataQuery): Promise<CommitMetadata[]>;
|
|
75
|
-
getCommit(partition: string, commitSeq: number): Promise<CommitDetail | undefined>;
|
|
76
|
-
listRowChanges(partition: string, query: RowChangesQuery): Promise<RowChangeRecord[]>;
|
|
77
|
-
listRows(partition: string, query: RowListQuery): Promise<StoredRow[]>;
|
|
78
|
-
countRows(partition: string, table: string): Promise<number>;
|
|
79
|
-
listPushResults(partition: string, clientCommitId: string): Promise<ClientPushResult[]>;
|
|
80
|
-
scopeActivity(partition: string, query: ScopeActivityQuery): Promise<ScopeCommitActivity[]>;
|
|
81
|
-
listPartitions(): Promise<string[]>;
|
|
82
29
|
}
|