@interocitor/core 0.0.0-beta.2
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/LICENSE +21 -0
- package/README.md +178 -0
- package/dist/adapters/cloudflare.d.ts +72 -0
- package/dist/adapters/cloudflare.d.ts.map +1 -0
- package/dist/adapters/cloudflare.js +227 -0
- package/dist/adapters/cloudflare.js.map +1 -0
- package/dist/adapters/google-drive.d.ts +64 -0
- package/dist/adapters/google-drive.d.ts.map +1 -0
- package/dist/adapters/google-drive.js +340 -0
- package/dist/adapters/google-drive.js.map +1 -0
- package/dist/adapters/memory.d.ts +45 -0
- package/dist/adapters/memory.d.ts.map +1 -0
- package/dist/adapters/memory.js +129 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/webdav.d.ts +59 -0
- package/dist/adapters/webdav.d.ts.map +1 -0
- package/dist/adapters/webdav.js +247 -0
- package/dist/adapters/webdav.js.map +1 -0
- package/dist/core/codec.d.ts +20 -0
- package/dist/core/codec.d.ts.map +1 -0
- package/dist/core/codec.js +66 -0
- package/dist/core/codec.js.map +1 -0
- package/dist/core/compaction.d.ts +37 -0
- package/dist/core/compaction.d.ts.map +1 -0
- package/dist/core/compaction.js +134 -0
- package/dist/core/compaction.js.map +1 -0
- package/dist/core/crdt.d.ts +33 -0
- package/dist/core/crdt.d.ts.map +1 -0
- package/dist/core/crdt.js +188 -0
- package/dist/core/crdt.js.map +1 -0
- package/dist/core/flush.d.ts +9 -0
- package/dist/core/flush.d.ts.map +1 -0
- package/dist/core/flush.js +41 -0
- package/dist/core/flush.js.map +1 -0
- package/dist/core/hlc.d.ts +25 -0
- package/dist/core/hlc.d.ts.map +1 -0
- package/dist/core/hlc.js +76 -0
- package/dist/core/hlc.js.map +1 -0
- package/dist/core/internals.d.ts +25 -0
- package/dist/core/internals.d.ts.map +1 -0
- package/dist/core/internals.js +54 -0
- package/dist/core/internals.js.map +1 -0
- package/dist/core/manifest.d.ts +31 -0
- package/dist/core/manifest.d.ts.map +1 -0
- package/dist/core/manifest.js +111 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/pull.d.ts +26 -0
- package/dist/core/pull.d.ts.map +1 -0
- package/dist/core/pull.js +98 -0
- package/dist/core/pull.js.map +1 -0
- package/dist/core/row-id.d.ts +12 -0
- package/dist/core/row-id.d.ts.map +1 -0
- package/dist/core/row-id.js +12 -0
- package/dist/core/row-id.js.map +1 -0
- package/dist/core/schema-types.d.ts +13 -0
- package/dist/core/schema-types.d.ts.map +1 -0
- package/dist/core/schema-types.js +18 -0
- package/dist/core/schema-types.js.map +1 -0
- package/dist/core/schema-types.type-test.d.ts +2 -0
- package/dist/core/schema-types.type-test.d.ts.map +1 -0
- package/dist/core/schema-types.type-test.js +149 -0
- package/dist/core/schema-types.type-test.js.map +1 -0
- package/dist/core/sync-engine.d.ts +158 -0
- package/dist/core/sync-engine.d.ts.map +1 -0
- package/dist/core/sync-engine.js +714 -0
- package/dist/core/sync-engine.js.map +1 -0
- package/dist/core/table.d.ts +60 -0
- package/dist/core/table.d.ts.map +1 -0
- package/dist/core/table.js +106 -0
- package/dist/core/table.js.map +1 -0
- package/dist/core/types.d.ts +478 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +7 -0
- package/dist/core/types.js.map +1 -0
- package/dist/crypto/encryption.d.ts +57 -0
- package/dist/crypto/encryption.d.ts.map +1 -0
- package/dist/crypto/encryption.js +195 -0
- package/dist/crypto/encryption.js.map +1 -0
- package/dist/crypto/keys.d.ts +48 -0
- package/dist/crypto/keys.d.ts.map +1 -0
- package/dist/crypto/keys.js +55 -0
- package/dist/crypto/keys.js.map +1 -0
- package/dist/handshake/channel.d.ts +117 -0
- package/dist/handshake/channel.d.ts.map +1 -0
- package/dist/handshake/channel.js +246 -0
- package/dist/handshake/channel.js.map +1 -0
- package/dist/handshake/index.d.ts +213 -0
- package/dist/handshake/index.d.ts.map +1 -0
- package/dist/handshake/index.js +182 -0
- package/dist/handshake/index.js.map +1 -0
- package/dist/handshake/qr.d.ts +100 -0
- package/dist/handshake/qr.d.ts.map +1 -0
- package/dist/handshake/qr.js +103 -0
- package/dist/handshake/qr.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/credential-store.d.ts +99 -0
- package/dist/storage/credential-store.d.ts.map +1 -0
- package/dist/storage/credential-store.js +309 -0
- package/dist/storage/credential-store.js.map +1 -0
- package/dist/storage/local-store.d.ts +56 -0
- package/dist/storage/local-store.d.ts.map +1 -0
- package/dist/storage/local-store.js +411 -0
- package/dist/storage/local-store.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* interocitor — encrypted local-first CRDT sync over cloud storage
|
|
3
|
+
*
|
|
4
|
+
* Core type definitions
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Stable identity metadata for a client device participating in a mesh.
|
|
8
|
+
*/
|
|
9
|
+
export interface DeviceInfo {
|
|
10
|
+
deviceId: string;
|
|
11
|
+
userId?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hybrid logical clock state used to order CRDT writes across devices.
|
|
16
|
+
*/
|
|
17
|
+
export interface HLC {
|
|
18
|
+
ts: number;
|
|
19
|
+
counter: number;
|
|
20
|
+
nodeId: string;
|
|
21
|
+
}
|
|
22
|
+
export type ColumnValue = string | number | boolean | null | object;
|
|
23
|
+
/**
|
|
24
|
+
* CRDT cell value paired with the HLC timestamp that last wrote it.
|
|
25
|
+
*/
|
|
26
|
+
export interface ColumnEntry {
|
|
27
|
+
value: ColumnValue;
|
|
28
|
+
hlc: string;
|
|
29
|
+
}
|
|
30
|
+
export interface UpsertOp {
|
|
31
|
+
type: 'upsert';
|
|
32
|
+
table: string;
|
|
33
|
+
rowId: string;
|
|
34
|
+
columns: Record<string, ColumnEntry>;
|
|
35
|
+
}
|
|
36
|
+
export interface DeleteOp {
|
|
37
|
+
type: 'delete';
|
|
38
|
+
table: string;
|
|
39
|
+
rowId: string;
|
|
40
|
+
hlc: string;
|
|
41
|
+
}
|
|
42
|
+
export type Op = UpsertOp | DeleteOp;
|
|
43
|
+
/**
|
|
44
|
+
* Serialized batch of CRDT operations written to a device-specific change log.
|
|
45
|
+
*/
|
|
46
|
+
export interface ChangeEntry {
|
|
47
|
+
id: string;
|
|
48
|
+
ts: number;
|
|
49
|
+
device: string;
|
|
50
|
+
user?: string;
|
|
51
|
+
hlc: string;
|
|
52
|
+
ops: Op[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Row representation as stored in the local CRDT cache.
|
|
56
|
+
*
|
|
57
|
+
* Public table APIs usually return plain objects rather than this internal
|
|
58
|
+
* metadata-rich shape.
|
|
59
|
+
*/
|
|
60
|
+
export interface Row {
|
|
61
|
+
_table: string;
|
|
62
|
+
_rowId: string;
|
|
63
|
+
_deleted: boolean;
|
|
64
|
+
_deletedHlc?: string;
|
|
65
|
+
_schemaVersion: number;
|
|
66
|
+
[column: string]: ColumnEntry | string | boolean | number | undefined;
|
|
67
|
+
}
|
|
68
|
+
export interface TableIndexDefinition {
|
|
69
|
+
/** Stable index id used for migration and diagnostics. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** Top-level column name to index (plain row field, e.g. "status"). */
|
|
72
|
+
field: string;
|
|
73
|
+
unique?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Built-in column merge strategies (git-style):
|
|
77
|
+
*
|
|
78
|
+
* - `'remote-wins'` — Like git `--theirs`. Remote always overwrites local. Default.
|
|
79
|
+
* - `'lww'` — Last-Writer-Wins. Highest HLC wins.
|
|
80
|
+
* - `'local-wins'` — Like git `--ours`. Keep local value on conflict.
|
|
81
|
+
*/
|
|
82
|
+
export type BuiltinMergeStrategy = 'lww' | 'local-wins' | 'remote-wins';
|
|
83
|
+
/**
|
|
84
|
+
* Custom merge function. Receives the local and incoming column entries
|
|
85
|
+
* plus context, returns the winning entry.
|
|
86
|
+
*
|
|
87
|
+
* Called only when both local and remote have a value for the column.
|
|
88
|
+
* Return `local` to keep, `remote` to accept, or a new ColumnEntry to
|
|
89
|
+
* produce a merged result.
|
|
90
|
+
*/
|
|
91
|
+
export type MergeFunction = (local: ColumnEntry, remote: ColumnEntry, context: MergeContext) => ColumnEntry;
|
|
92
|
+
export interface MergeContext {
|
|
93
|
+
table: string;
|
|
94
|
+
rowId: string;
|
|
95
|
+
field: string;
|
|
96
|
+
}
|
|
97
|
+
/** Per-column merge strategy — builtin name or custom function. */
|
|
98
|
+
export type MergeStrategy = BuiltinMergeStrategy | MergeFunction;
|
|
99
|
+
/**
|
|
100
|
+
* Table-level merge config.
|
|
101
|
+
*
|
|
102
|
+
* - Set `strategy` for a table-wide default.
|
|
103
|
+
* - Set `fields` to override per column (like `.gitattributes` per file).
|
|
104
|
+
*
|
|
105
|
+
* Unspecified = inherits from {@link DatabaseSchemaDefinition.mergeStrategy},
|
|
106
|
+
* which itself defaults to `'remote-wins'`.
|
|
107
|
+
*/
|
|
108
|
+
export interface TableMergeConfig {
|
|
109
|
+
/** Default strategy for all fields in this table. */
|
|
110
|
+
strategy?: MergeStrategy;
|
|
111
|
+
/** Per-field overrides. */
|
|
112
|
+
fields?: Record<string, MergeStrategy>;
|
|
113
|
+
}
|
|
114
|
+
export type SchemaFieldKind = 'string' | 'number' | 'boolean' | 'date' | 'json' | 'enum';
|
|
115
|
+
export type IndexableSchemaFieldKind = Exclude<SchemaFieldKind, 'json'>;
|
|
116
|
+
/** A field descriptor — carries kind, optional index flags, and a phantom TS type. */
|
|
117
|
+
export interface SchemaField<T = unknown, K extends SchemaFieldKind = SchemaFieldKind> {
|
|
118
|
+
readonly kind: K;
|
|
119
|
+
readonly index?: boolean;
|
|
120
|
+
readonly unique?: boolean;
|
|
121
|
+
/** @internal phantom — never assigned at runtime */
|
|
122
|
+
readonly _type?: T;
|
|
123
|
+
}
|
|
124
|
+
/** Narrows kind to the set that IndexedDB can use as a key. */
|
|
125
|
+
export type IndexableSchemaField<T = unknown> = SchemaField<T, IndexableSchemaFieldKind>;
|
|
126
|
+
/**
|
|
127
|
+
* Schema metadata for a single table, including field kinds and local indexes.
|
|
128
|
+
*
|
|
129
|
+
* @typeParam T — plain record type for rows in this table, e.g.
|
|
130
|
+
* `{ title: string; status: 'open' | 'done' }`.
|
|
131
|
+
* When omitted, defaults to `Record<string, unknown>` (untyped).
|
|
132
|
+
*/
|
|
133
|
+
export interface TableSchemaDefinition<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
134
|
+
/**
|
|
135
|
+
* Production style: define field kind + index intent in one place.
|
|
136
|
+
* Keys must match keys of T; values carry the phantom TS type via SchemaField<T[K]>.
|
|
137
|
+
*/
|
|
138
|
+
fields?: {
|
|
139
|
+
[K in keyof T]?: SchemaField<T[K]>;
|
|
140
|
+
} & Record<string, SchemaField>;
|
|
141
|
+
/** Legacy style: kept for compatibility. */
|
|
142
|
+
indexes?: TableIndexDefinition[];
|
|
143
|
+
/** Merge strategy for this table. Overrides the database-level default. */
|
|
144
|
+
merge?: MergeStrategy | TableMergeConfig;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Versioned schema definition used for local index planning and migrations.
|
|
148
|
+
*
|
|
149
|
+
* @typeParam S — database shape: `{ tableName: { fieldName: FieldType } }`.
|
|
150
|
+
* Inferred automatically when you pass a schema literal to `SyncConfig`.
|
|
151
|
+
* Omit for untyped usage.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const schema = {
|
|
155
|
+
* version: 1,
|
|
156
|
+
* tables: {
|
|
157
|
+
* tasks: { fields: { title: types.string, status: types.enum('open', 'done') } },
|
|
158
|
+
* },
|
|
159
|
+
* } satisfies DatabaseSchemaDefinition;
|
|
160
|
+
* // → DatabaseSchemaDefinition<{ tasks: { title: string; status: 'open' | 'done' } }>
|
|
161
|
+
*/
|
|
162
|
+
export interface DatabaseSchemaDefinition<S extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> {
|
|
163
|
+
/** Increment when index/table metadata changes. */
|
|
164
|
+
version: number;
|
|
165
|
+
tables: {
|
|
166
|
+
[K in keyof S]: TableSchemaDefinition<S[K]>;
|
|
167
|
+
} & Record<string, TableSchemaDefinition>;
|
|
168
|
+
/** Default merge strategy for all tables. Default: `'remote-wins'`. */
|
|
169
|
+
mergeStrategy?: MergeStrategy;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extracts the database shape `S` from a `DatabaseSchemaDefinition<S>`.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* const schema = { version: 1, tables: { tasks: { fields: { title: types.string } } } }
|
|
176
|
+
* satisfies DatabaseSchemaDefinition;
|
|
177
|
+
* type DB = InferSchemaType<typeof schema>;
|
|
178
|
+
* // → { tasks: { title: string } } (via field phantom types)
|
|
179
|
+
*
|
|
180
|
+
* // Simpler — use InferTableType per table:
|
|
181
|
+
* type TaskRow = InferTableType<typeof schema, 'tasks'>;
|
|
182
|
+
* // → { title: string }
|
|
183
|
+
*/
|
|
184
|
+
export type InferSchemaType<D extends DatabaseSchemaDefinition> = D extends DatabaseSchemaDefinition<infer S> ? S : Record<string, Record<string, unknown>>;
|
|
185
|
+
/**
|
|
186
|
+
* Extracts the row type for a single table `K` from a `DatabaseSchemaDefinition`.
|
|
187
|
+
*/
|
|
188
|
+
export type InferTableType<D extends DatabaseSchemaDefinition, K extends keyof InferSchemaType<D> & string> = InferSchemaType<D>[K];
|
|
189
|
+
export type WherePrimitive = string | number | boolean | Date;
|
|
190
|
+
export type WhereOperator = 'equals' | 'above' | 'aboveOrEqual' | 'below' | 'belowOrEqual' | 'between' | 'startsWith' | 'anyOf';
|
|
191
|
+
/**
|
|
192
|
+
* Dexie-style predicate description used by {@link Table.where} and
|
|
193
|
+
* {@link SyncEngine.queryWhere}.
|
|
194
|
+
*/
|
|
195
|
+
export interface WhereClause {
|
|
196
|
+
field: string;
|
|
197
|
+
op: WhereOperator;
|
|
198
|
+
value?: WherePrimitive;
|
|
199
|
+
values?: WherePrimitive[];
|
|
200
|
+
lower?: WherePrimitive;
|
|
201
|
+
upper?: WherePrimitive;
|
|
202
|
+
lowerOpen?: boolean;
|
|
203
|
+
upperOpen?: boolean;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Compacted mesh snapshot containing the full row set at a given epoch.
|
|
207
|
+
*/
|
|
208
|
+
export interface Snapshot {
|
|
209
|
+
snapshotId: string;
|
|
210
|
+
timestamp: string;
|
|
211
|
+
hlc: string;
|
|
212
|
+
epoch: number;
|
|
213
|
+
schemaVersion: number;
|
|
214
|
+
tables: Record<string, Record<string, Row>>;
|
|
215
|
+
}
|
|
216
|
+
export interface MeshChangePayload {
|
|
217
|
+
meshId: string;
|
|
218
|
+
kind: 'change';
|
|
219
|
+
entry: ChangeEntry;
|
|
220
|
+
}
|
|
221
|
+
export interface MeshSnapshotPayload {
|
|
222
|
+
meshId: string;
|
|
223
|
+
kind: 'snapshot';
|
|
224
|
+
snapshot: Snapshot;
|
|
225
|
+
}
|
|
226
|
+
export interface ServerConfig {
|
|
227
|
+
managed: boolean;
|
|
228
|
+
relayUrl: string | null;
|
|
229
|
+
serverId: string;
|
|
230
|
+
}
|
|
231
|
+
export interface ManifestPointer {
|
|
232
|
+
currentGeneration: number;
|
|
233
|
+
file: string;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Authoritative mesh manifest describing the latest generation and snapshot state.
|
|
237
|
+
*/
|
|
238
|
+
export interface Manifest {
|
|
239
|
+
generation: number;
|
|
240
|
+
parentGeneration: number;
|
|
241
|
+
writtenBy: string;
|
|
242
|
+
writtenAt: string;
|
|
243
|
+
contentHash: string;
|
|
244
|
+
version: number;
|
|
245
|
+
meshId: string;
|
|
246
|
+
schema: number;
|
|
247
|
+
encrypted: boolean;
|
|
248
|
+
server: ServerConfig;
|
|
249
|
+
createdAt: string;
|
|
250
|
+
/** Compaction epoch — incremented on each snapshot. */
|
|
251
|
+
epoch: number;
|
|
252
|
+
/** HLC watermark — all data ≤ this HLC is captured in the snapshot. */
|
|
253
|
+
watermarkHlc: string;
|
|
254
|
+
/** Cloud path to the latest snapshot file, or null before first compaction. */
|
|
255
|
+
snapshotPath: string | null;
|
|
256
|
+
/** Reserved for future delta-based catch-up. */
|
|
257
|
+
deltaPath: string | null;
|
|
258
|
+
}
|
|
259
|
+
export interface DeviceMetadata extends DeviceInfo {
|
|
260
|
+
registeredAt: string;
|
|
261
|
+
lastSeenAt: string;
|
|
262
|
+
retired?: boolean;
|
|
263
|
+
}
|
|
264
|
+
export interface DeviceHead {
|
|
265
|
+
device: string;
|
|
266
|
+
latestHlc: string;
|
|
267
|
+
latestDate: string;
|
|
268
|
+
fileCount: number;
|
|
269
|
+
}
|
|
270
|
+
/** Global change-folder head — monotonic HLC hint for fast poll skipping. */
|
|
271
|
+
export interface ChangesHead {
|
|
272
|
+
latestHlc: string;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Normalized remote file metadata returned by a storage adapter.
|
|
276
|
+
*/
|
|
277
|
+
export interface FileEntry {
|
|
278
|
+
name: string;
|
|
279
|
+
path: string;
|
|
280
|
+
size: number;
|
|
281
|
+
modifiedTime: string;
|
|
282
|
+
etag?: string;
|
|
283
|
+
revision?: string;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Contract implemented by remote backends such as WebDAV, Google Drive,
|
|
287
|
+
* Cloudflare, or in-memory test adapters.
|
|
288
|
+
*/
|
|
289
|
+
export interface StorageAdapter {
|
|
290
|
+
readonly name: string;
|
|
291
|
+
authenticate(): Promise<void>;
|
|
292
|
+
isAuthenticated(): boolean;
|
|
293
|
+
ensureFolder(path: string): Promise<void>;
|
|
294
|
+
listFiles(path: string): Promise<FileEntry[]>;
|
|
295
|
+
listFolders(path: string): Promise<string[]>;
|
|
296
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
297
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
298
|
+
deleteFile(path: string): Promise<void>;
|
|
299
|
+
getFileMetadata(path: string): Promise<FileEntry | null>;
|
|
300
|
+
/**
|
|
301
|
+
* Return an opaque config string describing how to reach this backend,
|
|
302
|
+
* suitable for embedding in a handshake QR code payload.
|
|
303
|
+
*
|
|
304
|
+
* Must NOT include credentials (passwords, tokens, OAuth secrets).
|
|
305
|
+
* The scanner uses this to configure their own adapter instance before
|
|
306
|
+
* starting the ECDH relay exchange.
|
|
307
|
+
*
|
|
308
|
+
* Returns undefined for adapters where the backend address is already
|
|
309
|
+
* baked into the app (e.g. a fixed Cloudflare Worker URL known to all
|
|
310
|
+
* app users). In that case the scanner configures their adapter independently.
|
|
311
|
+
*
|
|
312
|
+
* The returned string should be treated as opaque by the handshake layer;
|
|
313
|
+
* only the same adapter class knows how to parse it.
|
|
314
|
+
*/
|
|
315
|
+
getHandshakeConfig?(): string;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Contract every local store implementation must satisfy.
|
|
319
|
+
* Implement this interface to plug in a custom local backend
|
|
320
|
+
* (e.g. in-memory for tests, SQLite via OPFS, etc.).
|
|
321
|
+
*/
|
|
322
|
+
export interface LocalStoreAdapter {
|
|
323
|
+
open(): Promise<void>;
|
|
324
|
+
close(): void;
|
|
325
|
+
getRow(table: string, rowId: string): Promise<Row | undefined>;
|
|
326
|
+
putRow(row: Row): Promise<void>;
|
|
327
|
+
putRows(rows: Row[]): Promise<void>;
|
|
328
|
+
getTable(table: string): Promise<Row[]>;
|
|
329
|
+
queryWhere(table: string, clause: WhereClause): Promise<Row[]>;
|
|
330
|
+
getAllRows(): Promise<Row[]>;
|
|
331
|
+
clearRows(): Promise<void>;
|
|
332
|
+
getTableNames(): Promise<string[]>;
|
|
333
|
+
pushOutbox(entry: ChangeEntry): Promise<void>;
|
|
334
|
+
drainOutbox(): Promise<ChangeEntry[]>;
|
|
335
|
+
outboxSize(): Promise<number>;
|
|
336
|
+
getCursor(deviceId: string): Promise<number>;
|
|
337
|
+
setCursor(deviceId: string, offset: number): Promise<void>;
|
|
338
|
+
getAllCursors(): Promise<Record<string, number>>;
|
|
339
|
+
getMeta(key: string): Promise<unknown>;
|
|
340
|
+
setMeta(key: string, value: unknown): Promise<void>;
|
|
341
|
+
clearAll(): Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
/** Factory that creates a local store instance for this engine. */
|
|
344
|
+
export type LocalStoreFactory = () => LocalStoreAdapter;
|
|
345
|
+
/** Write-only replica adapter for backup. */
|
|
346
|
+
export interface ReplicaConfig {
|
|
347
|
+
adapter: StorageAdapter;
|
|
348
|
+
/** Override remotePath for this replica. Defaults to the primary remotePath. */
|
|
349
|
+
remotePath?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Configuration for a {@link SyncEngine} instance.
|
|
353
|
+
*
|
|
354
|
+
* Supports both fully local startup and immediate sync with a remote adapter.
|
|
355
|
+
*/
|
|
356
|
+
export interface SyncConfig<S extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> {
|
|
357
|
+
/** Cloud folder path prefix, e.g. "/Interocitor" */
|
|
358
|
+
remotePath: string;
|
|
359
|
+
/**
|
|
360
|
+
* Base58 passphrase for mesh encryption.
|
|
361
|
+
* When set, the engine derives the AES-256 key internally and persists
|
|
362
|
+
* it via the credential store. Implies encrypted = true.
|
|
363
|
+
*/
|
|
364
|
+
passphrase?: string;
|
|
365
|
+
/**
|
|
366
|
+
* Encryption is on by default. Set to false to opt out.
|
|
367
|
+
* When enabled without a passphrase, the engine generates a fresh key
|
|
368
|
+
* on first init (retrieve via getPassphrase()).
|
|
369
|
+
*/
|
|
370
|
+
encrypted?: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* Override the auto-generated device ID.
|
|
373
|
+
* Primarily for tests. In production, omit — the engine generates
|
|
374
|
+
* and persists a unique ID per origin automatically.
|
|
375
|
+
*/
|
|
376
|
+
deviceId?: string;
|
|
377
|
+
/** If true, only serverId may publish manifests/compaction */
|
|
378
|
+
serverManaged?: boolean;
|
|
379
|
+
/** Authorized writer identity when serverManaged=true */
|
|
380
|
+
serverId?: string;
|
|
381
|
+
/** Polling interval in ms (default 30000) */
|
|
382
|
+
pollInterval?: number;
|
|
383
|
+
/** Flush debounce in ms (default 2000) */
|
|
384
|
+
flushDebounce?: number;
|
|
385
|
+
/** Max pending ops before forced flush (default 50) */
|
|
386
|
+
flushThreshold?: number;
|
|
387
|
+
/**
|
|
388
|
+
* Local database name for this engine's local cache.
|
|
389
|
+
* Use distinct names to isolate multiple engine instances on the same origin.
|
|
390
|
+
* Default: "interocitor"
|
|
391
|
+
*/
|
|
392
|
+
dbName?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Factory that produces the local store for this engine.
|
|
395
|
+
* When provided, dbName is ignored — the factory is fully responsible
|
|
396
|
+
* for constructing the store.
|
|
397
|
+
*/
|
|
398
|
+
localStoreFactory?: LocalStoreFactory;
|
|
399
|
+
/** Optional table/index metadata for local query planning and migrations. */
|
|
400
|
+
schema?: DatabaseSchemaDefinition<S>;
|
|
401
|
+
/**
|
|
402
|
+
* Write-only replica adapters for backup.
|
|
403
|
+
* Flush writes to primary + all replicas. Pull reads primary only.
|
|
404
|
+
* Replica failures are emitted as 'replica:error' events but do not
|
|
405
|
+
* fail the primary flush.
|
|
406
|
+
*/
|
|
407
|
+
replicas?: ReplicaConfig[];
|
|
408
|
+
/**
|
|
409
|
+
* Credential store for persisting key material (passphrase + device ID).
|
|
410
|
+
*
|
|
411
|
+
* Default: auto-detecting store that tries WebAuthn largeBlob (OS keychain,
|
|
412
|
+
* survives Safari ITP) and falls back to localStorage.
|
|
413
|
+
*
|
|
414
|
+
* Pass a custom `CredentialStore` implementation or `null` to disable
|
|
415
|
+
* credential persistence entirely.
|
|
416
|
+
*/
|
|
417
|
+
credentialStore?: import('../storage/credential-store.ts').CredentialStore | null;
|
|
418
|
+
/**
|
|
419
|
+
* Human-readable app name shown in biometric prompts (Touch ID / Face ID)
|
|
420
|
+
* and OS keychain entries. Used by the default credential store.
|
|
421
|
+
*/
|
|
422
|
+
appName: string;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Union of lifecycle, sync, auth, and replication events emitted by the engine.
|
|
426
|
+
*/
|
|
427
|
+
export type SyncEvent = {
|
|
428
|
+
type: 'sync:start';
|
|
429
|
+
} | {
|
|
430
|
+
type: 'sync:complete';
|
|
431
|
+
entriesMerged: number;
|
|
432
|
+
} | {
|
|
433
|
+
type: 'sync:error';
|
|
434
|
+
error: Error;
|
|
435
|
+
} | {
|
|
436
|
+
type: 'remote:poisoned';
|
|
437
|
+
error: Error;
|
|
438
|
+
path?: string;
|
|
439
|
+
} | {
|
|
440
|
+
type: 'flush:start';
|
|
441
|
+
entryCount: number;
|
|
442
|
+
} | {
|
|
443
|
+
type: 'flush:complete';
|
|
444
|
+
} | {
|
|
445
|
+
type: 'flush:error';
|
|
446
|
+
error: Error;
|
|
447
|
+
} | {
|
|
448
|
+
type: 'change';
|
|
449
|
+
table: string;
|
|
450
|
+
rowId: string;
|
|
451
|
+
row: Row;
|
|
452
|
+
} | {
|
|
453
|
+
type: 'delete';
|
|
454
|
+
table: string;
|
|
455
|
+
rowId: string;
|
|
456
|
+
} | {
|
|
457
|
+
type: 'rehydrate:start';
|
|
458
|
+
} | {
|
|
459
|
+
type: 'rehydrate:complete';
|
|
460
|
+
rowCount: number;
|
|
461
|
+
} | {
|
|
462
|
+
type: 'auth:required';
|
|
463
|
+
} | {
|
|
464
|
+
type: 'auth:complete';
|
|
465
|
+
} | {
|
|
466
|
+
type: 'schema:mismatch';
|
|
467
|
+
local: number;
|
|
468
|
+
remote: number;
|
|
469
|
+
} | {
|
|
470
|
+
type: 'replica:error';
|
|
471
|
+
adapter: string;
|
|
472
|
+
error: Error;
|
|
473
|
+
};
|
|
474
|
+
/**
|
|
475
|
+
* Listener callback registered with {@link SyncEngine.on}.
|
|
476
|
+
*/
|
|
477
|
+
export type SyncEventListener = (event: SyncEvent) => void;
|
|
478
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAID;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAID,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,WAAW,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,EAAE,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,E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E,GACzB;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encryption layer — AES-256-GCM via Web Crypto API
|
|
3
|
+
*
|
|
4
|
+
* The key is a 256-bit symmetric key. It never leaves the device.
|
|
5
|
+
* Each entry is independently encrypted with a random 96-bit IV.
|
|
6
|
+
*
|
|
7
|
+
* The key can be transferred as:
|
|
8
|
+
* - base58 string (~43 chars, copy-pasteable)
|
|
9
|
+
* - URL fragment (#key=base64url)
|
|
10
|
+
* - QR code containing either of the above
|
|
11
|
+
*/
|
|
12
|
+
/** Generate a new 256-bit AES-GCM key. */
|
|
13
|
+
export declare function generateKey(): Promise<CryptoKey>;
|
|
14
|
+
/** Export key to raw bytes. */
|
|
15
|
+
export declare function exportKeyRaw(key: CryptoKey): Promise<Uint8Array>;
|
|
16
|
+
/** Import key from raw bytes. */
|
|
17
|
+
export declare function importKeyRaw(raw: Uint8Array): Promise<CryptoKey>;
|
|
18
|
+
/** Export key as a base58 string (~43 chars, human-transferable). */
|
|
19
|
+
export declare function keyToPassphrase(key: CryptoKey): Promise<string>;
|
|
20
|
+
/** Import key from a base58 passphrase. */
|
|
21
|
+
export declare function passphraseToKey(passphrase: string): Promise<CryptoKey>;
|
|
22
|
+
/**
|
|
23
|
+
* Export key as a URL fragment (never hits server).
|
|
24
|
+
* @param baseUrl - e.g. "https://yourapp.com/join"
|
|
25
|
+
*/
|
|
26
|
+
export declare function keyToShareUrl(raw: Uint8Array, baseUrl: string): string;
|
|
27
|
+
/** Extract key bytes from a URL fragment. */
|
|
28
|
+
export declare function keyFromFragment(hash: string): Uint8Array | null;
|
|
29
|
+
export interface EncryptedEnvelope {
|
|
30
|
+
v: number;
|
|
31
|
+
iv: string;
|
|
32
|
+
ct: string;
|
|
33
|
+
}
|
|
34
|
+
/** Encrypt a single plaintext string. */
|
|
35
|
+
export declare function encryptEntry(key: CryptoKey, plaintext: string): Promise<string>;
|
|
36
|
+
/** Decrypt a single encrypted envelope back to plaintext. */
|
|
37
|
+
export declare function decryptEntry(key: CryptoKey, envelopeStr: string): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Encrypt multiple plaintext lines independently and join them as NDJSON.
|
|
40
|
+
*
|
|
41
|
+
* Each line gets its own IV and auth tag, so corruption is isolated to the
|
|
42
|
+
* affected entry.
|
|
43
|
+
*/
|
|
44
|
+
export declare function encryptNdjson(key: CryptoKey, lines: string[]): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Decrypt newline-delimited encrypted entries.
|
|
47
|
+
*
|
|
48
|
+
* Invalid or corrupted lines are returned as `null` instead of throwing so the
|
|
49
|
+
* caller can recover as much of the stream as possible.
|
|
50
|
+
*/
|
|
51
|
+
export declare function decryptNdjson(key: CryptoKey, content: string): Promise<Array<string | null>>;
|
|
52
|
+
/** Quick verification: try decrypting a single line to confirm key is correct. */
|
|
53
|
+
export declare function verifyKey(key: CryptoKey, sampleEncrypted: string): Promise<boolean>;
|
|
54
|
+
export declare function storeKeyLocally(key: CryptoKey): Promise<void>;
|
|
55
|
+
export declare function loadKeyLocally(): Promise<CryptoKey | null>;
|
|
56
|
+
export declare function clearKeyLocally(): void;
|
|
57
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","source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