@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
package/dist/pull.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pull:
|
|
3
|
-
* (SPEC.md §4, §5).
|
|
2
|
+
* Pull: units, the live section, bootstrap segments (SPEC.md §4, §5).
|
|
4
3
|
*/
|
|
5
|
-
import { type PullHeaderFrame, type ResponseFrame, type ScopeMap, type
|
|
4
|
+
import { type CommitFrame, type FencedRecord, type PullHeaderFrame, type ResponseFrame, type ScopeMap, type UnitScopes } from '@syncular/core';
|
|
6
5
|
import type { SyncRequestContext, SyncServerConfig } from './context.js';
|
|
7
6
|
import type { PullSegmentSummary } from './events.js';
|
|
8
7
|
import { type CompiledSchema, type CompiledTable } from './schema.js';
|
|
8
|
+
import { type ResolvedScopes } from './scopes.js';
|
|
9
9
|
import type { SegmentRecord } from './segment-store.js';
|
|
10
10
|
import type { StoredCommit, StoredRow } from './storage.js';
|
|
11
11
|
/** §4.2 accept bitmask. */
|
|
@@ -19,18 +19,33 @@ export interface PullLimits {
|
|
|
19
19
|
readonly maxSnapshotPages: number;
|
|
20
20
|
readonly accept: number;
|
|
21
21
|
}
|
|
22
|
-
/** §4.2 defaults and silent clamps
|
|
22
|
+
/** §4.2 defaults and silent clamps. */
|
|
23
23
|
export declare function clampPullLimits(header: PullHeaderFrame): PullLimits;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
readonly
|
|
24
|
+
/** One unit of the effective list, resolved against the request (§3.2, §4.1). */
|
|
25
|
+
export interface UnitPlan {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly scopes: UnitScopes;
|
|
28
|
+
/** Covered tables in bootstrap order (§4.1, §4.7). */
|
|
29
|
+
readonly tables: readonly CompiledTable[];
|
|
30
|
+
/** Active (unit, table) pairs: table → effective scopes (§3.2). */
|
|
31
|
+
readonly pairs: ReadonlyMap<string, ScopeMap>;
|
|
27
32
|
readonly status: 'active' | 'revoked';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export interface SubscriptionResult {
|
|
31
|
-
readonly nextCursor: number;
|
|
32
|
-
readonly active: boolean;
|
|
33
|
+
/** The echo (§4.4): ascending table order, empty when revoked. */
|
|
34
|
+
readonly fenced: readonly FencedRecord[];
|
|
33
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* §4.1 unit validation against one schema version: the covered tables, or
|
|
38
|
+
* `sync.invalid_subscription` for an empty scope map, a requested `'*'`, a
|
|
39
|
+
* variable no table declares, or no covered table.
|
|
40
|
+
*/
|
|
41
|
+
export declare function coveredTables(schema: CompiledSchema, scopes: UnitScopes): CompiledTable[];
|
|
42
|
+
/** §3.2 per covered table: the unit's active pairs, status and echo. */
|
|
43
|
+
export declare function planUnit(scopes: UnitScopes, tables: readonly CompiledTable[], resolved: ResolvedScopes): UnitPlan;
|
|
44
|
+
/**
|
|
45
|
+
* The `COMMIT` frame of one live-section commit (§4.5): its frame-local
|
|
46
|
+
* table dictionary and every change, projected onto the client's codec.
|
|
47
|
+
*/
|
|
48
|
+
export declare function commitFrame(commit: StoredCommit, current: CompiledSchema, target: CompiledSchema): CommitFrame;
|
|
34
49
|
/**
|
|
35
50
|
* Mutable per-section collector for the `pull.served` event. Only created
|
|
36
51
|
* when an events sink is configured — with `trace` undefined the pull path
|
|
@@ -39,51 +54,58 @@ export interface SubscriptionResult {
|
|
|
39
54
|
export interface PullSectionTrace {
|
|
40
55
|
readonly segments: PullSegmentSummary[];
|
|
41
56
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
* them for every subscription before awaiting any, so a storage that batches
|
|
45
|
-
* concurrent page reads (PostgreSQL, D1) answers the first pages of every
|
|
46
|
-
* subscription in one statement, and the horizon re-check runs once per pull.
|
|
47
|
-
*/
|
|
48
|
-
export interface PreparedSection {
|
|
49
|
-
/** §4.5 window read for an incremental cursor; empty when none was read. */
|
|
50
|
-
readonly commits: StoredCommit[];
|
|
51
|
-
/** Horizon to judge the cursor against, re-read after any window read. */
|
|
52
|
-
readonly horizonSeq: number;
|
|
53
|
-
/**
|
|
54
|
-
* A bootstrap's first snapshot page (`limitSnapshotRows + 1` rows from the
|
|
55
|
-
* resume cursor), which is also the §5.3 image eligibility probe.
|
|
56
|
-
*/
|
|
57
|
-
readonly firstPage: StoredRow[] | undefined;
|
|
58
|
-
/** §4.7 pin of a fresh bootstrap; absent ⇒ `maxCommitSeq`. */
|
|
59
|
-
readonly pin: number | undefined;
|
|
57
|
+
/** The reads a table's bootstrap needs before its first frame (§4.7, §5.3). */
|
|
58
|
+
interface TableStart {
|
|
60
59
|
/**
|
|
61
|
-
*
|
|
62
|
-
* the eligibility probe
|
|
63
|
-
* smaller table can never match a stored image.
|
|
60
|
+
* `limitSnapshotRows + 1` rows from the start cursor: the first page and
|
|
61
|
+
* the §5.3 image eligibility probe.
|
|
64
62
|
*/
|
|
65
|
-
readonly
|
|
63
|
+
readonly firstPage: StoredRow[];
|
|
64
|
+
/** On the sqlite lane: the §4.7 scope pin and a stored image under it. */
|
|
65
|
+
readonly image?: {
|
|
66
|
+
readonly scopePin: number;
|
|
67
|
+
readonly stored: SegmentRecord | undefined;
|
|
68
|
+
};
|
|
66
69
|
}
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
70
|
+
/** A bootstrapping unit's position and its table starts, read ahead (§4.7). */
|
|
71
|
+
export interface BootstrapPlan {
|
|
72
|
+
readonly unit: UnitPlan;
|
|
73
|
+
/** The unit's pin: a usable resume token's, or `maxCommitSeq`. */
|
|
74
|
+
readonly pin: number;
|
|
75
|
+
readonly tableIndex: number;
|
|
76
|
+
readonly rowCursor: string | null;
|
|
77
|
+
/** Table index → its start reads. */
|
|
78
|
+
readonly starts: ReadonlyMap<number, Promise<TableStart>>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Plan one unit's bootstrap and start the reads of every table it can reach
|
|
82
|
+
* in this section: each visited table costs at least one page, so at most
|
|
83
|
+
* `maxSnapshotPages` tables. The reads of every planned unit start before any
|
|
84
|
+
* is awaited, so a storage that batches concurrent page reads (PostgreSQL,
|
|
85
|
+
* D1) answers them in one statement per table.
|
|
86
|
+
*/
|
|
87
|
+
export declare function planBootstrap(ctx: SyncRequestContext, schema: CompiledSchema, limits: PullLimits, unit: UnitPlan, bootstrapState: string | undefined, maxSeq: number, horizonSeq: number, logEpoch: string): BootstrapPlan;
|
|
69
88
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
89
|
+
* The segments of one bootstrap section (§4.7): tables in bootstrap order,
|
|
90
|
+
* each active pair's rows or image, up to `maxSnapshotPages` pages. Returns
|
|
91
|
+
* the resume token, or `undefined` once every table is exhausted. A pair the
|
|
92
|
+
* wildcard fence revoked receives no segment (§3.3).
|
|
72
93
|
*/
|
|
73
|
-
export declare function
|
|
74
|
-
/** The section of one subscription whose reads `prepareSections` ran. */
|
|
75
|
-
export declare function preparedSection(ctx: SyncRequestContext, schema: CompiledSchema, limits: PullLimits, plan: SubscriptionPlan, maxSeq: number, prepared: PreparedSection, trace?: PullSectionTrace, logEpoch?: string): AsyncGenerator<ResponseFrame, SubscriptionResult>;
|
|
94
|
+
export declare function bootstrapSegments(ctx: SyncRequestContext, schema: CompiledSchema, limits: PullLimits, plan: BootstrapPlan, trace: PullSectionTrace | undefined, logEpoch: string): AsyncGenerator<ResponseFrame, string | undefined>;
|
|
76
95
|
export interface PublishSqliteImageInput {
|
|
77
96
|
/** The sync config the serving host runs, plus a `sqliteImageBuilder`. */
|
|
78
97
|
readonly config: SyncServerConfig;
|
|
79
98
|
readonly partition: string;
|
|
80
99
|
readonly table: string;
|
|
100
|
+
/** The unit whose clients bootstrap the table (§4.1). */
|
|
101
|
+
readonly scopes: UnitScopes;
|
|
81
102
|
/**
|
|
82
|
-
* The
|
|
83
|
-
*
|
|
84
|
-
*
|
|
103
|
+
* The allowed scopes of the actors that register the unit (§3.2). The
|
|
104
|
+
* reuse key carries the digest of the pair's effective scopes, so a
|
|
105
|
+
* wildcard fence on the table changes the image. Default: `'*'` for every
|
|
106
|
+
* declared variable, which leaves the unit's own scope map.
|
|
85
107
|
*/
|
|
86
|
-
readonly
|
|
108
|
+
readonly allowed?: ScopeMap;
|
|
87
109
|
}
|
|
88
110
|
export interface PublishedSqliteImage {
|
|
89
111
|
readonly segmentId: string;
|
|
@@ -96,8 +118,8 @@ export interface PublishedSqliteImage {
|
|
|
96
118
|
readonly origin: 'built' | 'reused';
|
|
97
119
|
}
|
|
98
120
|
/**
|
|
99
|
-
* Publish the §5.3 sqlite image that a pull
|
|
100
|
-
*
|
|
121
|
+
* Publish the §5.3 sqlite image that a pull of (`scopes`, `table`) looks up,
|
|
122
|
+
* from a host with a SQLite engine (a Bun process with the production
|
|
101
123
|
* storage). It runs the pull's own bootstrap path (the §4.7 scope pin, the
|
|
102
124
|
* reuse key, the build), so the stored identity is exactly the one a
|
|
103
125
|
* serving host without a builder finds. The image stays current until a
|
|
@@ -105,3 +127,4 @@ export interface PublishedSqliteImage {
|
|
|
105
127
|
* publication.
|
|
106
128
|
*/
|
|
107
129
|
export declare function publishSqliteImage(input: PublishSqliteImageInput): Promise<PublishedSqliteImage>;
|
|
130
|
+
export {};
|