@sqlite-sync/core 0.12.2 → 0.13.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/{reset-state-t0tTGqoh.js → crdt-sync-producer-BY-WobgO.js} +55 -241
- package/dist/crdt-sync-producer-BY-WobgO.js.map +1 -0
- package/dist/{crdt-sync-remote-source-CPXzmSIS.js → crdt-sync-remote-source-yeTEkOjH.js} +344 -12
- package/dist/crdt-sync-remote-source-yeTEkOjH.js.map +1 -0
- package/dist/{crdt-table-schema-BRm_WdcW.js → crdt-table-schema-D6Yf61Ex.js} +37 -13
- package/dist/crdt-table-schema-D6Yf61Ex.js.map +1 -0
- package/dist/{index-BHsKLqcK.d.ts → index-CH4lf3iX.d.ts} +166 -72
- package/dist/index.common-C8W9VKSY.js +276 -0
- package/dist/index.common-C8W9VKSY.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +20 -677
- package/dist/index.js.map +1 -1
- package/dist/index.native.d.ts +2 -0
- package/dist/index.native.js +9 -0
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +2 -2
- package/dist/local.d.ts +48 -0
- package/dist/local.js +255 -0
- package/dist/local.js.map +1 -0
- package/dist/{make-crdt-table-C6l0F-o_.js → make-crdt-table-DYCXOYB7.js} +13 -14
- package/dist/make-crdt-table-DYCXOYB7.js.map +1 -0
- package/dist/reset-state-CPOi_45B.js +220 -0
- package/dist/reset-state-CPOi_45B.js.map +1 -0
- package/dist/server.d.ts +8 -3
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/sqlite-reactive-db-DLS1xRZp.js +296 -0
- package/dist/sqlite-reactive-db-DLS1xRZp.js.map +1 -0
- package/dist/synced-db-database-B5M7MrBD.js +81 -0
- package/dist/synced-db-database-B5M7MrBD.js.map +1 -0
- package/dist/{system-schema-Dvl_BLId.js → system-schema-CXf3FmxN.js} +142 -58
- package/dist/system-schema-CXf3FmxN.js.map +1 -0
- package/dist/worker.d.ts +2 -10
- package/dist/worker.js +11 -177
- package/dist/worker.js.map +1 -1
- package/dist/ws-remote-source-BbPWrHB6.js +161 -0
- package/dist/ws-remote-source-BbPWrHB6.js.map +1 -0
- package/dist/ws-remote-source-DFBhDc6Z.d.ts +12 -0
- package/package.json +9 -1
- package/dist/crdt-sync-remote-source-CPXzmSIS.js.map +0 -1
- package/dist/crdt-table-schema-BRm_WdcW.js.map +0 -1
- package/dist/make-crdt-table-C6l0F-o_.js.map +0 -1
- package/dist/reset-state-t0tTGqoh.js.map +0 -1
- package/dist/system-schema-Dvl_BLId.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnDataType, ColumnDefinitionBuilderCallback, ColumnType, Compilable, CompiledQuery, CreateIndexBuilder, CreateTableBuilder, Expression, Kysely, SchemaModule } from "kysely";
|
|
2
|
-
import { Database,
|
|
2
|
+
import { Database, Sqlite3Static } from "@sqlite.org/sqlite-wasm";
|
|
3
3
|
//#region src/dummy-kysely.d.ts
|
|
4
4
|
declare const dummyKysely: Kysely<any>;
|
|
5
5
|
//#endregion
|
|
@@ -182,7 +182,7 @@ declare class ColumnBuilder<Value, HasDefault extends boolean = false> {
|
|
|
182
182
|
constructor(meta: ColumnMeta);
|
|
183
183
|
/** Allow SQL NULL; widens the value type with `null`. */
|
|
184
184
|
nullable(): ColumnBuilder<Value | null, HasDefault>;
|
|
185
|
-
/** Declare a column default.
|
|
185
|
+
/** Declare a column default. Creates may omit the column; it must match the migrated DDL default. */
|
|
186
186
|
default(value: Value): ColumnBuilder<Value, true>;
|
|
187
187
|
/** Narrow the TypeScript value type without changing storage, e.g. `t.text().$type<"movie" | "tv">()`. */
|
|
188
188
|
$type<Narrowed extends Value>(): ColumnBuilder<Narrowed, HasDefault>;
|
|
@@ -329,6 +329,52 @@ type PerformanceLogger = {
|
|
|
329
329
|
};
|
|
330
330
|
declare const startPerformanceLogger: (logger: Logger | undefined, level?: LogLevel) => PerformanceLogger;
|
|
331
331
|
//#endregion
|
|
332
|
+
//#region src/sqlite-driver.d.ts
|
|
333
|
+
type SqliteDriverValue = string | number | bigint | Uint8Array | null;
|
|
334
|
+
type SqliteDriverRows = {
|
|
335
|
+
columns: string[];
|
|
336
|
+
rows: SqliteDriverValue[][];
|
|
337
|
+
};
|
|
338
|
+
type SqliteDriverStatement = {
|
|
339
|
+
/** Binds, steps to completion and resets the statement. Must run synchronously. */
|
|
340
|
+
run: (parameters: readonly unknown[]) => SqliteDriverRows;
|
|
341
|
+
finalize: () => void;
|
|
342
|
+
/**
|
|
343
|
+
* `sqlite3_stmt_readonly`. Drivers that cannot report it leave it undefined
|
|
344
|
+
* and the wrapper classifies the statement through `tables_used`.
|
|
345
|
+
*/
|
|
346
|
+
readonly?: boolean;
|
|
347
|
+
};
|
|
348
|
+
type SqliteDriverHooks = {
|
|
349
|
+
onUpdate: (table: string) => void;
|
|
350
|
+
onCommit: () => void;
|
|
351
|
+
onRollback: () => void;
|
|
352
|
+
};
|
|
353
|
+
type SqliteDriver = {
|
|
354
|
+
prepare: (sql: string) => SqliteDriverStatement;
|
|
355
|
+
totalChanges: () => number;
|
|
356
|
+
/**
|
|
357
|
+
* Installs update/commit/rollback hooks. Pass `null` to remove them.
|
|
358
|
+
*
|
|
359
|
+
* Hooks may be delivered after the statement that caused them returns, but
|
|
360
|
+
* they must be delivered in the order SQLite raised them.
|
|
361
|
+
*/
|
|
362
|
+
setHooks: (hooks: SqliteDriverHooks | null) => void;
|
|
363
|
+
/** Whether hooks run inside the statement that raised them, before it returns. */
|
|
364
|
+
readonly synchronousHooks: boolean;
|
|
365
|
+
close: () => void;
|
|
366
|
+
serialize?: () => Uint8Array<ArrayBufferLike>;
|
|
367
|
+
deserialize?: (snapshot: Uint8Array<ArrayBufferLike>) => void;
|
|
368
|
+
createScalarFunction?: (options: {
|
|
369
|
+
name: string;
|
|
370
|
+
callback: (...args: SqliteDriverValue[]) => SqliteDriverValue | undefined;
|
|
371
|
+
arity: number;
|
|
372
|
+
deterministic?: boolean;
|
|
373
|
+
directOnly?: boolean;
|
|
374
|
+
innocuous?: boolean;
|
|
375
|
+
}) => void;
|
|
376
|
+
};
|
|
377
|
+
//#endregion
|
|
332
378
|
//#region src/sqlite-db-wrapper.d.ts
|
|
333
379
|
type ExecuteParams = {
|
|
334
380
|
sql: string;
|
|
@@ -342,15 +388,17 @@ type PreparedStatement<TParams extends unknown[], TResult> = {
|
|
|
342
388
|
finalize: () => void;
|
|
343
389
|
isFinalized: boolean;
|
|
344
390
|
};
|
|
345
|
-
type ScalarFunctionOptions<TArgs extends readonly
|
|
391
|
+
type ScalarFunctionOptions<TArgs extends readonly SqliteDriverValue[], TResult extends SqliteDriverValue | undefined> = {
|
|
346
392
|
name: string;
|
|
347
393
|
callback: (...args: TArgs) => TResult;
|
|
348
|
-
|
|
394
|
+
deterministic?: boolean;
|
|
395
|
+
directOnly?: boolean;
|
|
396
|
+
innocuous?: boolean;
|
|
397
|
+
};
|
|
349
398
|
type SqliteWrapperOptions = {
|
|
350
399
|
logger?: Logger;
|
|
351
400
|
loggerPrefix?: string;
|
|
352
|
-
|
|
353
|
-
db: () => Database;
|
|
401
|
+
driver: SqliteDriver;
|
|
354
402
|
};
|
|
355
403
|
type SQLiteTransactionWrapper<TDatabase = unknown> = Pick<SQLiteDbWrapper<TDatabase>, "sql" | "execute" | "executePrepared" | "executePreparedRaw" | "executeKysely">;
|
|
356
404
|
type InternalSQLiteTransactionWrapper<TDatabase = unknown> = Pick<SQLiteDbWrapper<TDatabase>, "executePrepared" | "executePreparedRaw">;
|
|
@@ -367,24 +415,24 @@ type ExecuteOptions = QueryMetaOpts & {
|
|
|
367
415
|
skipAfterMutatingStatement?: boolean;
|
|
368
416
|
};
|
|
369
417
|
declare class SQLiteDbWrapper<TDatabase = unknown> {
|
|
370
|
-
private
|
|
371
|
-
private sqlite3;
|
|
418
|
+
private driver;
|
|
372
419
|
private logger?;
|
|
373
420
|
private loggerPrefix?;
|
|
374
421
|
private loadedDbSchema;
|
|
375
|
-
private readonly dataPointers;
|
|
376
422
|
private preparedStatements;
|
|
377
423
|
private preparedStatementsMap;
|
|
378
424
|
private preparedRawStatementsMap;
|
|
425
|
+
private readonlyStatementCache;
|
|
379
426
|
private afterMutatingStatement;
|
|
380
427
|
constructor(opts: SqliteWrapperOptions);
|
|
381
|
-
get
|
|
428
|
+
get ensureDriver(): SqliteDriver;
|
|
382
429
|
get dbSchema(): DatabaseIntrospection;
|
|
383
430
|
private executeSql;
|
|
431
|
+
private isReadonlyStatement;
|
|
432
|
+
private isReadonlyByTablesUsed;
|
|
384
433
|
execute<T = unknown>(opts: ExecuteParams | string | CompiledQuery<T>, options?: ExecuteOptions): ExecuteResult<T>;
|
|
385
434
|
setAfterMutatingStatement(callback: AfterMutatingStatement<TDatabase>): void;
|
|
386
435
|
executeTransaction<T>(callback: (db: SQLiteTransactionWrapper<TDatabase>) => T): T;
|
|
387
|
-
isInTransaction(): boolean;
|
|
388
436
|
beginTransaction(): {
|
|
389
437
|
commit: () => void;
|
|
390
438
|
rollback: () => void;
|
|
@@ -401,9 +449,9 @@ declare class SQLiteDbWrapper<TDatabase = unknown> {
|
|
|
401
449
|
meta?: QueryMetaOpts;
|
|
402
450
|
}): TResult[];
|
|
403
451
|
sql<T = unknown>(templateOrString: TemplateStringsArray | string, ...parameters: unknown[]): ExecuteResult<T>;
|
|
404
|
-
createScalarFunction<TArgs extends
|
|
452
|
+
createScalarFunction<TArgs extends SqliteDriverValue[], TResult extends SqliteDriverValue | undefined>({ name, callback, deterministic, directOnly, innocuous }: ScalarFunctionOptions<TArgs, TResult>): void;
|
|
405
453
|
useSnapshot(snapshot: Uint8Array<ArrayBufferLike>): void;
|
|
406
|
-
createSnapshot(): Uint8Array<
|
|
454
|
+
createSnapshot(): Uint8Array<ArrayBufferLike>;
|
|
407
455
|
invalidateDbSchema(): void;
|
|
408
456
|
cleanup(): void;
|
|
409
457
|
close(): void;
|
|
@@ -420,6 +468,42 @@ declare function compileKyselyStatement<TParams extends Record<string, unknown>,
|
|
|
420
468
|
bindParameters: (parameters: TParams) => unknown[];
|
|
421
469
|
};
|
|
422
470
|
//#endregion
|
|
471
|
+
//#region src/sqlite-crdt/state-hash.d.ts
|
|
472
|
+
/**
|
|
473
|
+
* Persistence for the state hash. Reads and writes must go through the same
|
|
474
|
+
* transaction that changes the update log, so a rollback reverts both.
|
|
475
|
+
*/
|
|
476
|
+
type StateHashStore = {
|
|
477
|
+
read: () => string | null;
|
|
478
|
+
write: (value: string) => void;
|
|
479
|
+
};
|
|
480
|
+
/** Returns the hashed columns for a dataset, or null to hash whichever cells the update log holds. */
|
|
481
|
+
type StateHashColumns = (dataset: string) => readonly string[] | null;
|
|
482
|
+
type StateHashAccumulator = ReturnType<typeof createStateHashAccumulator>;
|
|
483
|
+
/**
|
|
484
|
+
* The state hash is a sum of per-cell hashes over the CRDT update log, tagged with
|
|
485
|
+
* the schema version it was computed for. It depends only on current state, not on
|
|
486
|
+
* history, so replicas that converged agree on it no matter how they got there.
|
|
487
|
+
*
|
|
488
|
+
* Cells are the dataset's schema columns except `id`. A cell missing from the
|
|
489
|
+
* update log hashes as written by the item's latest create (the HLC stored under
|
|
490
|
+
* `id`). Older builds filled column defaults into creates migrated through an
|
|
491
|
+
* add-column migration, so replicas that replayed history hold such cells while
|
|
492
|
+
* replicas that applied the creates earlier never stored them.
|
|
493
|
+
*/
|
|
494
|
+
declare function createStateHashAccumulator({ sum, getColumns }: {
|
|
495
|
+
sum: bigint;
|
|
496
|
+
getColumns: StateHashColumns;
|
|
497
|
+
}): {
|
|
498
|
+
readonly sum: bigint;
|
|
499
|
+
addItem(dataset: string, itemId: string, meta: CrdtUpdateLogPayload): void;
|
|
500
|
+
/**
|
|
501
|
+
* `meta` is the item's update log after the write. `replacedCells` holds each written
|
|
502
|
+
* cell's HLC from before it, and `previousCreateHlc` the item's create HLC from before.
|
|
503
|
+
*/
|
|
504
|
+
updateItem(dataset: string, itemId: string, meta: CrdtUpdateLogPayload, previousCreateHlc: string | undefined, replacedCells: readonly [column: string, previousHlc: string | undefined][]): void;
|
|
505
|
+
};
|
|
506
|
+
//#endregion
|
|
423
507
|
//#region src/sqlite-kv-store.d.ts
|
|
424
508
|
type KvStoreItem = {
|
|
425
509
|
key: string;
|
|
@@ -448,7 +532,7 @@ type DeferredPromiseOptions = {
|
|
|
448
532
|
onTimeout?: () => void;
|
|
449
533
|
};
|
|
450
534
|
declare function createDeferredPromise<T>(opts?: DeferredPromiseOptions): DeferredPromise<T>;
|
|
451
|
-
declare const generateId: () =>
|
|
535
|
+
declare const generateId: () => string;
|
|
452
536
|
type DistributiveOmit<T, K extends keyof T> = T extends any ? Omit<T, K> : never;
|
|
453
537
|
declare class TypedBroadcastChannel<TMessage> {
|
|
454
538
|
private readonly channel;
|
|
@@ -457,7 +541,8 @@ declare class TypedBroadcastChannel<TMessage> {
|
|
|
457
541
|
set onmessage(callback: ((event: MessageEvent<TMessage>) => void) | null);
|
|
458
542
|
close(): void;
|
|
459
543
|
}
|
|
460
|
-
declare class TypedEvent<T = unknown>
|
|
544
|
+
declare class TypedEvent<T = unknown> {
|
|
545
|
+
readonly type: string;
|
|
461
546
|
readonly payload: T;
|
|
462
547
|
constructor(type: string, payload: T);
|
|
463
548
|
}
|
|
@@ -468,6 +553,7 @@ type TypedEventTarget<T extends Record<string, unknown>> = {
|
|
|
468
553
|
removeEventListener: <K extends keyof T & string>(type: K, listener: (event: TypedEvent<T[K]>) => void) => void;
|
|
469
554
|
dispatchEvent: <K extends keyof T & string>(type: K, payload: T[K]) => void;
|
|
470
555
|
};
|
|
556
|
+
/** Follows EventTarget semantics without requiring the global, which React Native lacks. */
|
|
471
557
|
declare const createTypedEventTarget: <T extends Record<string, unknown>>() => TypedEventTarget<T>;
|
|
472
558
|
type TryCatchResult<T> = {
|
|
473
559
|
success: true;
|
|
@@ -590,7 +676,7 @@ type DbSyncerStorage = {
|
|
|
590
676
|
db: InternalSQLiteWrapper<any>;
|
|
591
677
|
dbConfig: SystemDbConfig;
|
|
592
678
|
hlc: StorageHLC;
|
|
593
|
-
|
|
679
|
+
stateHash?: StateHashStore;
|
|
594
680
|
onEventApplied?: (event: PersistedCrdtEvent) => void;
|
|
595
681
|
schema: Pick<SyncDbSchema, "tables" | "tablesConfig">;
|
|
596
682
|
};
|
|
@@ -598,7 +684,7 @@ type CrdtStorage = Omit<ReturnType<typeof createCrdtStorage>, "internal">;
|
|
|
598
684
|
type InternalCrdtStorage = ReturnType<typeof createCrdtStorage>;
|
|
599
685
|
type EventsAppliedPayload = {
|
|
600
686
|
syncId: number;
|
|
601
|
-
|
|
687
|
+
stateHash: string | null;
|
|
602
688
|
};
|
|
603
689
|
type InternalDbSchema = {
|
|
604
690
|
_crdt_events: PersistedCrdtEvent;
|
|
@@ -611,7 +697,7 @@ declare function createCrdtStorage(storage: DbSyncerStorage): {
|
|
|
611
697
|
applyOwnEvents: (events: OwnCrdtEvent[]) => void;
|
|
612
698
|
applyOwnSnapshot: (snapshot: OwnCrdtSnapshot) => void;
|
|
613
699
|
checkIsQuiescent: (pushedSyncId: number) => boolean;
|
|
614
|
-
|
|
700
|
+
getStateHash: () => string | null;
|
|
615
701
|
addEventListener: <K extends "events-applied" | "remote-event-apply-failed">(type: K, listener: (event: TypedEvent<{
|
|
616
702
|
"events-applied": EventsAppliedPayload;
|
|
617
703
|
"remote-event-apply-failed": {
|
|
@@ -691,8 +777,10 @@ declare const xxhash: {
|
|
|
691
777
|
//#endregion
|
|
692
778
|
//#region src/memory-db/sqlite-reactive-db.d.ts
|
|
693
779
|
type SQLiteReactiveDbOptions = {
|
|
694
|
-
|
|
780
|
+
driver: SqliteDriver;
|
|
781
|
+
snapshot?: Uint8Array<ArrayBufferLike>;
|
|
695
782
|
logger: Logger;
|
|
783
|
+
loggerPrefix?: string;
|
|
696
784
|
};
|
|
697
785
|
type EventsMap = {
|
|
698
786
|
"transaction-committed": undefined;
|
|
@@ -716,14 +804,20 @@ type SharedLiveQuerySnapshot = {
|
|
|
716
804
|
};
|
|
717
805
|
declare class SQLiteReactiveDb<Database> {
|
|
718
806
|
readonly db: SQLiteDbWrapper<Database>;
|
|
719
|
-
private
|
|
807
|
+
private readonly driver;
|
|
720
808
|
private readonly logger;
|
|
721
809
|
private tablesUsedStatement;
|
|
722
810
|
private eventTarget;
|
|
811
|
+
private isDisposed;
|
|
723
812
|
private mutationVersion;
|
|
724
813
|
private tableMutationVersions;
|
|
725
814
|
private constructor();
|
|
726
|
-
static create<Database>(opts: SQLiteReactiveDbOptions):
|
|
815
|
+
static create<Database>(opts: SQLiteReactiveDbOptions): SQLiteReactiveDb<Database>;
|
|
816
|
+
/**
|
|
817
|
+
* When false, table mutation versions only advance after the writing statement
|
|
818
|
+
* returns, so they cannot tell whether that statement wrote to a table.
|
|
819
|
+
*/
|
|
820
|
+
get hasSynchronousHooks(): boolean;
|
|
727
821
|
private liveQueryStatements;
|
|
728
822
|
private sharedLiveQueries;
|
|
729
823
|
createLiveQuery<TResult>(query: {
|
|
@@ -762,7 +856,7 @@ declare class SQLiteReactiveDb<Database> {
|
|
|
762
856
|
getTableMutationVersion(table: string): number;
|
|
763
857
|
private notifyTableSubscribers;
|
|
764
858
|
private registerDbHooks;
|
|
765
|
-
createSnapshot(): Uint8Array<
|
|
859
|
+
createSnapshot(): Uint8Array<ArrayBufferLike>;
|
|
766
860
|
useSnapshot(snapshot: Uint8Array<ArrayBufferLike>): void;
|
|
767
861
|
dispose(): void;
|
|
768
862
|
}
|
|
@@ -836,15 +930,15 @@ type SchemaVerificationIssue = {
|
|
|
836
930
|
};
|
|
837
931
|
/**
|
|
838
932
|
* Verify that replaying the full migration history on a fresh database produces
|
|
839
|
-
* exactly the declared table schema.
|
|
840
|
-
*
|
|
841
|
-
* `t.table()` declarations.
|
|
933
|
+
* exactly the declared table schema. Applies all migrations to `driver`, which
|
|
934
|
+
* must be an empty throwaway database (it is closed afterwards), introspects the
|
|
935
|
+
* result, and diffs it against the `t.table()` declarations.
|
|
842
936
|
*
|
|
843
937
|
* Returns an empty array when migrations and schema agree. Intended for dev-time
|
|
844
938
|
* checks (`startDbWorker({ verifySchema: true })`) and tests:
|
|
845
939
|
* `expect(await verifySyncSchema(syncDbSchema)).toEqual([])`.
|
|
846
940
|
*/
|
|
847
|
-
declare function
|
|
941
|
+
declare function verifySyncSchemaWithDriver(schema: SyncDbSchema, driver: SqliteDriver): SchemaVerificationIssue[];
|
|
848
942
|
declare function formatSchemaVerificationIssues(issues: SchemaVerificationIssue[]): string;
|
|
849
943
|
//#endregion
|
|
850
944
|
//#region src/sqlite-crdt/apply-crdt-event.d.ts
|
|
@@ -855,11 +949,13 @@ type PendingCrdtEvent = {
|
|
|
855
949
|
timestamp: string;
|
|
856
950
|
payload: string;
|
|
857
951
|
};
|
|
858
|
-
declare const createSQLiteCrdtApplyFunction: ({ db, dbConfig }: {
|
|
952
|
+
declare const createSQLiteCrdtApplyFunction: ({ db, dbConfig, getStateHash }: {
|
|
859
953
|
db: InternalSQLiteWrapper<any>;
|
|
860
954
|
dbConfig: SystemDbConfig;
|
|
955
|
+
getStateHash?: () => StateHashAccumulator | null;
|
|
861
956
|
}) => (event: PendingCrdtEvent) => void;
|
|
862
957
|
type CreateCrdtApplyOpts = {
|
|
958
|
+
getStateHash?: () => StateHashAccumulator | null;
|
|
863
959
|
getCrdtUpdateLog: (opts: {
|
|
864
960
|
itemId: string;
|
|
865
961
|
dataset: string;
|
|
@@ -884,7 +980,7 @@ type CreateCrdtApplyOpts = {
|
|
|
884
980
|
payload: string;
|
|
885
981
|
}) => void;
|
|
886
982
|
};
|
|
887
|
-
declare function createCrdtApplyFunction({ getCrdtUpdateLog, insertItem, insertCrdtUpdateLog, updateItem, updateCrdtUpdateLog }: CreateCrdtApplyOpts): (event: PendingCrdtEvent) => void;
|
|
983
|
+
declare function createCrdtApplyFunction({ getStateHash, getCrdtUpdateLog, insertItem, insertCrdtUpdateLog, updateItem, updateCrdtUpdateLog }: CreateCrdtApplyOpts): (event: PendingCrdtEvent) => void;
|
|
888
984
|
//#endregion
|
|
889
985
|
//#region src/sqlite-crdt/crdt-storage-mutator.d.ts
|
|
890
986
|
type CrdtStorageMutator<Database> = ReturnType<typeof createCrdtStorageMutator<Database>>;
|
|
@@ -924,7 +1020,7 @@ type CrdtSyncProducer = {
|
|
|
924
1020
|
storage: CrdtStorage;
|
|
925
1021
|
broadcastEvents: (request: {
|
|
926
1022
|
newSyncId: number;
|
|
927
|
-
|
|
1023
|
+
stateHash: string | null;
|
|
928
1024
|
}) => void;
|
|
929
1025
|
};
|
|
930
1026
|
declare const createCrdtSyncProducer: ({ storage, broadcastEvents }: CrdtSyncProducer) => void;
|
|
@@ -933,8 +1029,8 @@ declare const createCrdtSyncProducer: ({ storage, broadcastEvents }: CrdtSyncPro
|
|
|
933
1029
|
type WorkerNotificationMessage = {
|
|
934
1030
|
notificationType: "new-event-chunk-applied";
|
|
935
1031
|
newSyncId: number;
|
|
936
|
-
/** Worker's
|
|
937
|
-
|
|
1032
|
+
/** Worker's state hash after applying up to `newSyncId`. */
|
|
1033
|
+
stateHash: string | null;
|
|
938
1034
|
} | {
|
|
939
1035
|
notificationType: "state-changed";
|
|
940
1036
|
state: WorkerState;
|
|
@@ -952,6 +1048,9 @@ type WorkerNotificationMessage = {
|
|
|
952
1048
|
remoteSchemaVersion: number;
|
|
953
1049
|
localSchemaVersion: number;
|
|
954
1050
|
};
|
|
1051
|
+
type WorkerNotificationEvents = { [K in WorkerNotificationMessage["notificationType"]]: Extract<WorkerNotificationMessage, {
|
|
1052
|
+
notificationType: K;
|
|
1053
|
+
}>; };
|
|
955
1054
|
type WorkerState = {
|
|
956
1055
|
remoteState: "online" | "offline" | "connecting";
|
|
957
1056
|
deSynced: boolean;
|
|
@@ -1005,7 +1104,7 @@ type EventsPushResponse = {
|
|
|
1005
1104
|
type CrdtSyncRemoteSource = ReturnType<typeof createCrdtSyncRemoteSource>;
|
|
1006
1105
|
type EventsAvailable = {
|
|
1007
1106
|
newSyncId: number;
|
|
1008
|
-
|
|
1107
|
+
remoteStateHash: string | null;
|
|
1009
1108
|
};
|
|
1010
1109
|
/**
|
|
1011
1110
|
* Opens one connection to the remote. Each call must return a new source: the library calls `disconnect` on every
|
|
@@ -1075,36 +1174,33 @@ declare const createCrdtSyncRemoteSource: ({ bufferSize, storage, migrator, pull
|
|
|
1075
1174
|
//#endregion
|
|
1076
1175
|
//#region src/sqlite-crdt/make-crdt-table.d.ts
|
|
1077
1176
|
declare const CRDT_CHANGE_INTENTS_TABLE = "crdt_change_intents";
|
|
1078
|
-
declare function makeCrdtTable({ db, baseTableName, crdtTableName }: {
|
|
1177
|
+
declare function makeCrdtTable({ db, baseTableName, crdtTableName, temp }: {
|
|
1079
1178
|
db: SQLiteDbWrapper<any>;
|
|
1080
1179
|
baseTableName: string;
|
|
1081
1180
|
crdtTableName: string;
|
|
1181
|
+
temp?: boolean;
|
|
1082
1182
|
}): void;
|
|
1083
1183
|
type CrdtViewColumn = {
|
|
1084
1184
|
name: string;
|
|
1085
1185
|
nullable: boolean;
|
|
1086
1186
|
};
|
|
1087
1187
|
declare function crdtViewColumnsFromTable(table: AnyTableBuilder): CrdtViewColumn[];
|
|
1088
|
-
declare function createCrdtViewStatements({ baseTableName, crdtTableName, columns }: {
|
|
1188
|
+
declare function createCrdtViewStatements({ baseTableName, crdtTableName, columns, temp }: {
|
|
1089
1189
|
baseTableName: string;
|
|
1090
1190
|
crdtTableName: string;
|
|
1091
1191
|
columns: CrdtViewColumn[];
|
|
1192
|
+
/**
|
|
1193
|
+
* Create the view, its triggers and the intents table in the connection's temp schema,
|
|
1194
|
+
* so a persisted database never stores them and they always match the current schema.
|
|
1195
|
+
*/
|
|
1196
|
+
temp?: boolean;
|
|
1092
1197
|
}): string[];
|
|
1093
1198
|
declare function drainCrdtChangeIntents({ tx, storage }: {
|
|
1094
1199
|
tx: InternalSQLiteTransactionWrapper<any>;
|
|
1095
1200
|
storage: InternalCrdtStorage;
|
|
1096
1201
|
}): boolean;
|
|
1097
1202
|
//#endregion
|
|
1098
|
-
//#region src/
|
|
1099
|
-
type SyncedDbOptions<Database, Props = undefined> = {
|
|
1100
|
-
dbId: string;
|
|
1101
|
-
worker: Worker;
|
|
1102
|
-
syncDbSchema: SyncDbSchema<Database>;
|
|
1103
|
-
} & (undefined extends Props ? {
|
|
1104
|
-
workerProps?: Props;
|
|
1105
|
-
} : {
|
|
1106
|
-
workerProps: Props;
|
|
1107
|
-
});
|
|
1203
|
+
//#region src/synced-db-database.d.ts
|
|
1108
1204
|
/** SQL execution that participates in CRDT intent draining. */
|
|
1109
1205
|
type SyncedDbSqlExecutor<Database> = {
|
|
1110
1206
|
execute<TResult = unknown>(query: ExecuteParams | string | CompiledQuery<TResult>): ExecuteResult<TResult>;
|
|
@@ -1137,6 +1233,17 @@ type SyncedDbDatabase<Database> = SyncedDbSqlExecutor<Database> & {
|
|
|
1137
1233
|
parameters: readonly unknown[];
|
|
1138
1234
|
}): SharedLiveQuery<TResult>;
|
|
1139
1235
|
};
|
|
1236
|
+
//#endregion
|
|
1237
|
+
//#region src/sync-db.d.ts
|
|
1238
|
+
type SyncedDbOptions<Database, Props = undefined> = {
|
|
1239
|
+
dbId: string;
|
|
1240
|
+
worker: Worker;
|
|
1241
|
+
syncDbSchema: SyncDbSchema<Database>;
|
|
1242
|
+
} & (undefined extends Props ? {
|
|
1243
|
+
workerProps?: Props;
|
|
1244
|
+
} : {
|
|
1245
|
+
workerProps: Props;
|
|
1246
|
+
});
|
|
1140
1247
|
declare function createSyncedDb<Database, Props = undefined>(options: SyncedDbOptions<Database, Props>): Promise<{
|
|
1141
1248
|
db: SyncedDbDatabase<Database>;
|
|
1142
1249
|
state: {
|
|
@@ -1160,32 +1267,7 @@ declare function createSyncedDb<Database, Props = undefined>(options: SyncedDbOp
|
|
|
1160
1267
|
requestReload: (options: {
|
|
1161
1268
|
clean: boolean;
|
|
1162
1269
|
}) => Promise<void>;
|
|
1163
|
-
subscribe: <K extends "state-changed" | "de-sync-detected" | "remote-schema-version-mismatch" | "new-event-chunk-applied" | "reload-requested">(type: K, listener: (event: TypedEvent<{
|
|
1164
|
-
"state-changed": {
|
|
1165
|
-
notificationType: "state-changed";
|
|
1166
|
-
state: WorkerState;
|
|
1167
|
-
storageGeneration: string;
|
|
1168
|
-
};
|
|
1169
|
-
"de-sync-detected": {
|
|
1170
|
-
notificationType: "de-sync-detected";
|
|
1171
|
-
reason: DeSyncDetectedReason;
|
|
1172
|
-
};
|
|
1173
|
-
"remote-schema-version-mismatch": {
|
|
1174
|
-
notificationType: "remote-schema-version-mismatch";
|
|
1175
|
-
remoteSchemaVersion: number;
|
|
1176
|
-
localSchemaVersion: number;
|
|
1177
|
-
};
|
|
1178
|
-
"new-event-chunk-applied": {
|
|
1179
|
-
notificationType: "new-event-chunk-applied";
|
|
1180
|
-
newSyncId: number;
|
|
1181
|
-
eventHlcSum: string | null;
|
|
1182
|
-
};
|
|
1183
|
-
"reload-requested": {
|
|
1184
|
-
notificationType: "reload-requested";
|
|
1185
|
-
reloadEpoch: string;
|
|
1186
|
-
clean: boolean;
|
|
1187
|
-
};
|
|
1188
|
-
}[K]>) => void) => {
|
|
1270
|
+
subscribe: <K extends "state-changed" | "de-sync-detected" | "remote-schema-version-mismatch" | "new-event-chunk-applied" | "reload-requested">(type: K, listener: (event: TypedEvent<WorkerNotificationEvents[K]>) => void) => {
|
|
1189
1271
|
unsubscribe: () => void;
|
|
1190
1272
|
};
|
|
1191
1273
|
exportData: (opts?: {
|
|
@@ -1228,5 +1310,17 @@ type ResetStore = {
|
|
|
1228
1310
|
*/
|
|
1229
1311
|
declare const RESET_REQUEST_TTL_MS: number;
|
|
1230
1312
|
//#endregion
|
|
1231
|
-
|
|
1232
|
-
|
|
1313
|
+
//#region src/memory-db/wasm-reactive-db.d.ts
|
|
1314
|
+
declare function createSQLiteReactiveDb<Database>(opts: Omit<SQLiteReactiveDbOptions, "driver">): Promise<SQLiteReactiveDb<Database>>;
|
|
1315
|
+
//#endregion
|
|
1316
|
+
//#region src/schema/verify-sync-schema-wasm.d.ts
|
|
1317
|
+
/** {@link verifySyncSchemaWithDriver} on a throwaway in-memory sqlite-wasm database. */
|
|
1318
|
+
declare function verifySyncSchema(schema: SyncDbSchema): Promise<SchemaVerificationIssue[]>;
|
|
1319
|
+
//#endregion
|
|
1320
|
+
//#region src/wasm-driver.d.ts
|
|
1321
|
+
declare function loadSqliteWasm(): Promise<Sqlite3Static>;
|
|
1322
|
+
declare function createWasmMemoryDriver(): Promise<SqliteDriver>;
|
|
1323
|
+
declare function createWasmSqliteDriver(sqlite3: Sqlite3Static, db: Database): SqliteDriver;
|
|
1324
|
+
//#endregion
|
|
1325
|
+
export { parametersAreEqual as $, ColumnMetadata as $t, WorkerState as A, SyncDbMigrator as An, tryCatch as At, verifySyncSchemaWithDriver as B, CrdtUpdateLogPayload as Bn, PreparedStatement as Bt, EventsPullRequest as C, TableColumns as Cn, TypedEvent as Ct, EventsPullResponse as D, MigratableEvent as Dn, generateId as Dt, createCrdtSyncRemoteSource as E, t as En, createTypedEventTarget as Et, PendingCrdtEvent as F, CRDT_EVENT_NO_OP_PAYLOAD as Fn, ExecuteParams as Ft, DefinedSyncSchema as G, SqliteDriver as Gt, NewCrdtEventValidationResult as H, isNoOpCrdtEventPayload as Hn, SQLiteDbWrapper as Ht, createCrdtApplyFunction as I, CrdtEventOrigin as In, ExecuteResult as It, ClientDatasetRejectionReason as J, SqliteDriverStatement as Jt, defineSyncSchema as K, SqliteDriverHooks as Kt, createSQLiteCrdtApplyFunction as L, CrdtEventStatus as Ln, InternalSQLiteWrapper as Lt, CrdtStorageMutator as M, createMigrator as Mn, KvStoreItem as Mt, SnapshotOptions as N, StoredValue as Nn, createKvStoreTableQuery as Nt, WorkerConfig as O, Migrations as On, jsonSafeParse as Ot, createCrdtStorageMutator as P, createStoredValue as Pn, createSQLiteKvStore as Pt, SharedLiveQuerySnapshot as Q, startPerformanceLogger as Qt, SchemaVerificationIssue as R, CrdtEventType as Rn, KyselyQueryFactory as Rt, CreateRemoteSourceFactory as S, TableBuilder as Sn, TypedBroadcastChannel as St, EventsPushResponse as T, WriteOrigin as Tn, createDeferredPromise as Tt, validateNewCrdtEvent as U, dummyKysely as Un, SQLiteTransactionWrapper as Ut, CrdtEventValidationError as V, PersistedCrdtEvent as Vn, QueryBuilderOutput as Vt, DefineSyncSchemaConfig as W, compileKyselyStatement as Wt, SQLiteReactiveDb as X, LogLevel as Xt, admitClientEvents as Y, SqliteDriverValue as Yt, SharedLiveQuery as Z, Logger as Zt, crdtViewColumnsFromTable as _, ExportImportMode as _n, baseSystemMigrations as _t, createSQLiteReactiveDb as a, compareHLC as an, createImportData as at, makeCrdtTable as b, SqliteStorageType as bn, DeferredPromise as bt, ResetStore as c, CrdtTableConfig as cn, GetEventsBatch as ct, createSyncedDb as d, AiAccess as dn, createCrdtStorage as dt, DatabaseIntrospection as en, xxhash as et, SyncedDbDatabase as f, AnyColumnBuilder as fn, SystemDbConfig as ft, CRDT_CHANGE_INTENTS_TABLE as g, ColumnMeta as gn, applyWorkerDbSchema as gt, UnsafeSyncedDbSqlExecutor as h, ColumnKind as hn, applyMemoryDbSchema as ht, verifySyncSchema as i, HLCCounter as in, createExportData as it, createCrdtSyncProducer as j, createMigrations as jn, tryCatchAsync as jt, WorkerNotificationMessage as k, MigrationsDb as kn, quoteId as kt, SyncedDb as l, ReadonlyTable as ln, OwnCrdtEvent as lt, SyncedDbTransaction as m, ColumnBuilder as mn, SystemMigrationContext as mt, createWasmSqliteDriver as n, introspectDb as nn, ImportDataResult as nt, RESET_REQUEST_TTL_MS as o, deserializeHLC as on, CrdtChangeIntent as ot, SyncedDbSqlExecutor as p, AnyTableBuilder as pn, SystemMigration as pt, AdmitClientEventsResult as q, SqliteDriverRows as qt, loadSqliteWasm as r, HLC as rn, SyncedDbExport as rt, ResetRequest as s, serializeHLC as sn, CrdtStorage as st, createWasmMemoryDriver as t, TableMetadata as tn, ImportDataOptions as tt, SyncedDbOptions as u, SyncDbSchema as un, OwnCrdtSnapshot as ut, createCrdtViewStatements as v, InferRow as vn, createSystemDbConfig as vt, EventsPushRequest as w, TableOptions as wn, TypedEventTarget as wt, CrdtSyncRemoteSource as x, SyncSchemaTables as xn, DistributiveOmit as xt, drainCrdtChangeIntents as y, PayloadValidationResult as yn, runSystemMigrations as yt, formatSchemaVerificationIssues as z, CrdtUpdateLogItem as zn, KyselyStatementFactory as zt };
|
|
1326
|
+
//# sourceMappingURL=index-CH4lf3iX.d.ts.map
|