@sqlite-sync/core 0.9.1 → 0.9.3
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/{index-BB-tsxEF.d.ts → index-iXdCBXzB.d.ts} +35 -29
- package/dist/index.d.ts +2 -2
- package/dist/index.js +20 -37
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/{reset-state-D3nsfx_t.js → reset-state-4Hn95CKG.js} +24 -14
- package/dist/reset-state-4Hn95CKG.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/reset-state-D3nsfx_t.js.map +0 -1
|
@@ -149,16 +149,18 @@ type SyncDbMigrator = ReturnType<typeof createMigrator>;
|
|
|
149
149
|
type ColumnKind = "text" | "integer" | "real" | "boolean" | "enum";
|
|
150
150
|
type SqliteStorageType = "text" | "integer" | "real";
|
|
151
151
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
152
|
+
* What `@sqlite-sync/ai` may do with a table.
|
|
153
|
+
* `read-only`: documented and queryable; mutations rejected.
|
|
154
|
+
* `hidden`: omitted from the schema doc; reads rejected.
|
|
155
155
|
*/
|
|
156
156
|
type AiAccess = "read-write" | "read-only" | "hidden";
|
|
157
157
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
158
|
+
* Who may author CRDT events for a table.
|
|
159
|
+
* `"any"` (default): every replica. `"server"`: client pushes drop these events.
|
|
160
160
|
*/
|
|
161
161
|
type WriteOrigin = "any" | "server";
|
|
162
|
+
/** Whether backup and restore include a table. */
|
|
163
|
+
type ExportImportMode = "include" | "ignore";
|
|
162
164
|
type ColumnMeta = {
|
|
163
165
|
kind: ColumnKind;
|
|
164
166
|
/** Storage type used in generated DDL. Booleans store as integer 0/1. */
|
|
@@ -189,12 +191,18 @@ declare class ColumnBuilder<Value, HasDefault extends boolean = false> {
|
|
|
189
191
|
}
|
|
190
192
|
type AnyColumnBuilder = ColumnBuilder<any, boolean>;
|
|
191
193
|
type TableColumns = Record<string, AnyColumnBuilder>;
|
|
192
|
-
type AnyTableBuilder = TableBuilder<any, any>;
|
|
194
|
+
type AnyTableBuilder = TableBuilder<any, any, WriteOrigin>;
|
|
193
195
|
type SyncSchemaTables = Record<string, AnyTableBuilder>;
|
|
194
|
-
type TableOptions<BaseName extends string | undefined = string | undefined> = {
|
|
196
|
+
type TableOptions<BaseName extends string | undefined = string | undefined, Writes extends WriteOrigin = "any"> = {
|
|
195
197
|
/** Override the materialized base table name (defaults to the crdt table name prefixed with "_"). */
|
|
196
198
|
baseName?: BaseName;
|
|
197
199
|
description?: string;
|
|
200
|
+
/** Defaults to `"read-write"`. See {@link AiAccess}. */
|
|
201
|
+
ai?: AiAccess;
|
|
202
|
+
/** Defaults to `"any"`. See {@link WriteOrigin}. */
|
|
203
|
+
writes?: Writes;
|
|
204
|
+
/** Defaults to `"include"`. Ignored tables are omitted from export and skipped on import. */
|
|
205
|
+
exportImport?: ExportImportMode;
|
|
198
206
|
};
|
|
199
207
|
type Simplify$1<T> = { [K in keyof T]: T[K]; } & {};
|
|
200
208
|
type ColumnValue<Column> = Column extends ColumnBuilder<infer Value, boolean> ? Value : never;
|
|
@@ -209,26 +217,22 @@ type PayloadValidationResult = {
|
|
|
209
217
|
success: false;
|
|
210
218
|
errors: string[];
|
|
211
219
|
};
|
|
212
|
-
declare class TableBuilder<Cols extends TableColumns, BaseName extends string | undefined = undefined> {
|
|
213
|
-
#private;
|
|
220
|
+
declare class TableBuilder<Cols extends TableColumns, BaseName extends string | undefined = undefined, Writes extends WriteOrigin = "any"> {
|
|
214
221
|
readonly userColumns: Cols;
|
|
215
222
|
readonly "~baseName": BaseName;
|
|
223
|
+
readonly "~writeOrigin": Writes;
|
|
216
224
|
/** All columns in DDL order, including the auto-injected `id` and `tombstone`. */
|
|
217
225
|
readonly columns: Record<string, ColumnMeta>;
|
|
218
226
|
readonly baseName: BaseName;
|
|
219
227
|
readonly description: string | undefined;
|
|
220
|
-
/**
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
describe(description: string): TableBuilder<Cols, BaseName>;
|
|
228
|
-
/** Restrict what an AI agent may do with this table; see {@link AiAccess}. */
|
|
229
|
-
ai(access: AiAccess): TableBuilder<Cols, BaseName>;
|
|
230
|
-
/** Restrict which replicas may author events for this table; see {@link WriteOrigin}. */
|
|
231
|
-
writes(origin: WriteOrigin): TableBuilder<Cols, BaseName>;
|
|
228
|
+
/** Resolved {@link AiAccess}; defaults to `"read-write"`. */
|
|
229
|
+
readonly aiAccess: AiAccess;
|
|
230
|
+
/** Resolved {@link WriteOrigin}; defaults to `"any"`. */
|
|
231
|
+
readonly writeOrigin: Writes;
|
|
232
|
+
/** Resolved {@link ExportImportMode}; defaults to `"include"`. */
|
|
233
|
+
readonly exportImport: ExportImportMode;
|
|
234
|
+
constructor(userColumns: Cols, options?: TableOptions<BaseName, Writes>);
|
|
235
|
+
describe(description: string): TableBuilder<Cols, BaseName, Writes>;
|
|
232
236
|
/** Type-only: the row shape returned by queries. Do not access at runtime. */
|
|
233
237
|
get $row(): InferRow<Cols>;
|
|
234
238
|
/**
|
|
@@ -252,13 +256,15 @@ declare const t: {
|
|
|
252
256
|
* For an open-ended set, use `t.text().$type<"idle" | (string & {})>()` instead.
|
|
253
257
|
*/
|
|
254
258
|
enum: <const Values extends readonly [string, ...string[]]>(values: Values) => ColumnBuilder<Values[number], false>;
|
|
255
|
-
table: <Cols extends TableColumns, const BaseName extends string | undefined = undefined>(columns: Cols, options?: TableOptions<BaseName>) => TableBuilder<Cols, BaseName>;
|
|
259
|
+
table: <Cols extends TableColumns, const BaseName extends string | undefined = undefined, const Writes extends WriteOrigin = "any">(columns: Cols, options?: TableOptions<BaseName, Writes>) => TableBuilder<Cols, BaseName, Writes>;
|
|
256
260
|
};
|
|
257
261
|
//#endregion
|
|
258
262
|
//#region src/sqlite-crdt/crdt-schema.d.ts
|
|
259
263
|
type CrdtTableConfig = {
|
|
260
264
|
baseTableName: string;
|
|
261
265
|
crdtTableName: string;
|
|
266
|
+
/** Defaults to `"include"`. */
|
|
267
|
+
exportImport?: ExportImportMode;
|
|
262
268
|
};
|
|
263
269
|
interface SyncDbSchema<ClientDB = {}, ServerDB = {}, MutationsDB = {}> {
|
|
264
270
|
get tablesConfig(): CrdtTableConfig[];
|
|
@@ -764,8 +770,8 @@ type SchemaForAdmitClientEvents = Pick<SyncDbSchema, "tables" | "tablesConfig">
|
|
|
764
770
|
writeOriginByName?: ReadonlyMap<string, WriteOrigin>;
|
|
765
771
|
};
|
|
766
772
|
/**
|
|
767
|
-
* Splits a client push into events the hub should persist and events for tables
|
|
768
|
-
*
|
|
773
|
+
* Splits a client push into events the hub should persist and events for tables with
|
|
774
|
+
* `{ writes: "server" }`. Unknown datasets stay admitted. Matches either the crdt or the base
|
|
769
775
|
* table name.
|
|
770
776
|
*/
|
|
771
777
|
declare function admitClientEvents<T extends {
|
|
@@ -777,10 +783,10 @@ declare function admitClientEvents<T extends {
|
|
|
777
783
|
//#endregion
|
|
778
784
|
//#region src/schema/define-sync-schema.d.ts
|
|
779
785
|
type Simplify<T> = { [K in keyof T]: T[K]; } & {};
|
|
780
|
-
type RowOf<Table extends AnyTableBuilder> = Table extends TableBuilder<infer Cols extends TableColumns, any> ? InferRow<Cols> : never;
|
|
786
|
+
type RowOf<Table extends AnyTableBuilder> = Table extends TableBuilder<infer Cols extends TableColumns, any, WriteOrigin> ? InferRow<Cols> : never;
|
|
781
787
|
type BaseNameOf<CrdtName, Table extends AnyTableBuilder> = string extends Table["~baseName"] ? `_${CrdtName & string}` : [Table["~baseName"]] extends [string] ? Table["~baseName"] : `_${CrdtName & string}`;
|
|
782
|
-
type ClientSchemaOf<Tables extends SyncSchemaTables> = Simplify<{ [K in keyof Tables]: RowOf<Tables[K]>; } & { [K in keyof Tables as BaseNameOf<K, Tables[K]>]: ReadonlyTable<RowOf<Tables[K]>>; }>;
|
|
783
|
-
type ServerSchemaOf<Tables extends SyncSchemaTables> = Simplify<{ [K in keyof Tables]:
|
|
788
|
+
type ClientSchemaOf<Tables extends SyncSchemaTables> = Simplify<{ [K in keyof Tables]: Tables[K]["~writeOrigin"] extends "server" ? ReadonlyTable<RowOf<Tables[K]>> : RowOf<Tables[K]>; } & { [K in keyof Tables as BaseNameOf<K, Tables[K]>]: ReadonlyTable<RowOf<Tables[K]>>; }>;
|
|
789
|
+
type ServerSchemaOf<Tables extends SyncSchemaTables> = Simplify<{ [K in keyof Tables]: RowOf<Tables[K]>; } & { [K in keyof Tables as BaseNameOf<K, Tables[K]>]: ReadonlyTable<RowOf<Tables[K]>>; }>;
|
|
784
790
|
type MutationsSchemaOf<Tables extends SyncSchemaTables> = Simplify<{ [K in keyof Tables as BaseNameOf<K, Tables[K]>]: RowOf<Tables[K]>; }>;
|
|
785
791
|
interface DefinedSyncSchema<Tables extends SyncSchemaTables> extends SyncDbSchema<ClientSchemaOf<Tables>, ServerSchemaOf<Tables>, MutationsSchemaOf<Tables>> {
|
|
786
792
|
/** The table builders, for type extraction (`typeof schema.tables.item.$row`) and runtime metadata. */
|
|
@@ -1199,5 +1205,5 @@ type ResetStore = {
|
|
|
1199
1205
|
*/
|
|
1200
1206
|
declare const RESET_REQUEST_TTL_MS: number;
|
|
1201
1207
|
//#endregion
|
|
1202
|
-
export { CrdtChangeIntent as $, AnyColumnBuilder as $t, createCrdtApplyFunction as A, InternalSQLiteWrapper as At, defineSyncSchema as B, ColumnMetadata as Bt, WorkerNotificationMessage as C,
|
|
1203
|
-
//# sourceMappingURL=index-
|
|
1208
|
+
export { CrdtChangeIntent as $, AnyColumnBuilder as $t, createCrdtApplyFunction as A, dummyKysely as An, InternalSQLiteWrapper as At, defineSyncSchema as B, ColumnMetadata as Bt, WorkerNotificationMessage as C, CrdtEventOrigin as Cn, tryCatch as Ct, SnapshotOptions as D, CrdtUpdateLogPayload as Dn, createSQLiteKvStore as Dt, CrdtStorageMutator as E, CrdtUpdateLogItem as En, createKvStoreTableQuery as Et, CrdtEventValidationError as F, SQLiteDbWrapper as Ft, SharedLiveQuerySnapshot as G, HLCCounter as Gt, admitClientEvents as H, TableMetadata as Ht, NewCrdtEventValidationResult as I, SQLiteTransactionWrapper as It, ImportDataOptions as J, serializeHLC as Jt, parametersAreEqual as K, compareHLC as Kt, validateNewCrdtEvent as L, LogLevel as Lt, SchemaVerificationIssue as M, KyselyStatementFactory as Mt, formatSchemaVerificationIssues as N, PreparedStatement as Nt, createCrdtStorageMutator as O, PersistedCrdtEvent as On, ExecuteParams as Ot, verifySyncSchema as P, QueryBuilderOutput as Pt, createImportData as Q, AiAccess as Qt, DefineSyncSchemaConfig as R, Logger as Rt, WorkerConfig as S, CRDT_EVENT_NO_OP_PAYLOAD as Sn, quoteId as St, createCrdtSyncProducer as T, CrdtEventType as Tn, KvStoreItem as Tt, SQLiteReactiveDb as U, introspectDb as Ut, AdmitClientEventsResult as V, DatabaseIntrospection as Vt, SharedLiveQuery as W, HLC as Wt, SyncedDbExport as X, ReadonlyTable as Xt, ImportDataResult as Y, CrdtTableConfig as Yt, createExportData as Z, SyncDbSchema as Zt, EventsPullRequest as _, SyncDbMigrator as _n, TypedEventTarget as _t, SyncedDbDatabase as a, InferRow as an, SystemDbConfig as at, createCrdtSyncRemoteSource as b, StoredValue as bn, generateId as bt, SyncedDbTransaction as c, SyncSchemaTables as cn, applyMemoryDbSchema as ct, CRDT_CHANGE_INTENTS_TABLE as d, TableOptions as dn, createSystemDbConfig as dt, AnyTableBuilder as en, CrdtStorage as et, createCrdtViewStatements as f, WriteOrigin as fn, runSystemMigrations as ft, CreateRemoteSourceFactory as g, MigrationsDb as gn, TypedEvent as gt, CrdtSyncRemoteSource as h, Migrations as hn, TypedBroadcastChannel as ht, SyncedDb as i, ExportImportMode as in, createCrdtStorage as it, createSQLiteCrdtApplyFunction as j, KyselyQueryFactory as jt, PendingCrdtEvent as k, isNoOpCrdtEventPayload as kn, ExecuteResult as kt, UnsafeSyncedDbSqlExecutor as l, TableBuilder as ln, applyWorkerDbSchema as lt, makeCrdtTable as m, MigratableEvent as mn, DistributiveOmit as mt, ResetRequest as n, ColumnKind as nn, OwnCrdtEvent as nt, SyncedDbOptions as o, PayloadValidationResult as on, SystemMigration as ot, drainCrdtChangeIntents as p, t as pn, DeferredPromise as pt, xxhash as q, deserializeHLC as qt, ResetStore as r, ColumnMeta as rn, OwnCrdtSnapshot as rt, SyncedDbSqlExecutor as s, SqliteStorageType as sn, SystemMigrationContext as st, RESET_REQUEST_TTL_MS as t, ColumnBuilder as tn, GetEventsBatch as tt, createSyncedDb as u, TableColumns as un, baseSystemMigrations as ut, EventsPushRequest as v, createMigrations as vn, createDeferredPromise as vt, WorkerState as w, CrdtEventStatus as wn, tryCatchAsync as wt, EventsPullResponse as x, createStoredValue as xn, jsonSafeParse as xt, EventsPushResponse as y, createMigrator as yn, createTypedEventTarget as yt, DefinedSyncSchema as z, startPerformanceLogger as zt };
|
|
1209
|
+
//# sourceMappingURL=index-iXdCBXzB.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $t as AnyColumnBuilder, A as createCrdtApplyFunction, B as defineSyncSchema, Bt as ColumnMetadata, C as WorkerNotificationMessage, Cn as
|
|
2
|
-
export { type AdmitClientEventsResult, type AiAccess, type AnyColumnBuilder, type AnyTableBuilder, CRDT_EVENT_NO_OP_PAYLOAD, ColumnBuilder, type ColumnKind, type ColumnMeta, type ColumnMetadata, type CrdtEventOrigin, type CrdtEventStatus, type CrdtEventType, CrdtEventValidationError, type CrdtStorage, type CrdtStorageMutator, type CrdtSyncRemoteSource, type CrdtTableConfig, type CrdtUpdateLogItem, type CrdtUpdateLogPayload, type DatabaseIntrospection, type DeferredPromise, type DefineSyncSchemaConfig, type DefinedSyncSchema, type DistributiveOmit, type EventsPullRequest, type EventsPushRequest, type EventsPushResponse, type ExecuteParams, type ExecuteResult, type HLC, HLCCounter, type ImportDataOptions, type ImportDataResult, type InferRow, type KvStoreItem, type KyselyQueryFactory, type LogLevel, type Logger, type MigratableEvent, type Migrations, type MigrationsDb, type NewCrdtEventValidationResult, type OwnCrdtEvent, type OwnCrdtSnapshot, type PayloadValidationResult, type PendingCrdtEvent, type PersistedCrdtEvent, type PreparedStatement, type QueryBuilderOutput, RESET_REQUEST_TTL_MS, type ReadonlyTable, type ResetRequest, type ResetStore, SQLiteDbWrapper, SQLiteReactiveDb, type SQLiteTransactionWrapper, type SchemaVerificationIssue, type SharedLiveQuery, type SharedLiveQuerySnapshot, type SnapshotOptions, type SqliteStorageType, type StoredValue, type SyncDbMigrator, type SyncDbSchema, type SyncSchemaTables, type SyncedDb, type SyncedDbDatabase, type SyncedDbExport, type SyncedDbOptions, type SyncedDbSqlExecutor, type SyncedDbTransaction, type SystemDbConfig, type SystemMigration, type SystemMigrationContext, TableBuilder, type TableColumns, type TableMetadata, type TableOptions, TypedBroadcastChannel, TypedEvent, type TypedEventTarget, type UnsafeSyncedDbSqlExecutor, type WorkerConfig, type WorkerNotificationMessage, type WorkerState, type WriteOrigin, admitClientEvents, applyMemoryDbSchema, applyWorkerDbSchema, compareHLC, createCrdtApplyFunction, createCrdtStorage, createCrdtStorageMutator, createCrdtSyncProducer, createCrdtSyncRemoteSource, createDeferredPromise, createExportData, createImportData, createKvStoreTableQuery, createMigrations, createMigrator, createSQLiteCrdtApplyFunction, createSQLiteKvStore, createStoredValue, createSyncedDb, createTypedEventTarget, defineSyncSchema, deserializeHLC, dummyKysely, formatSchemaVerificationIssues, generateId, introspectDb, isNoOpCrdtEventPayload, jsonSafeParse, makeCrdtTable, parametersAreEqual, quoteId, serializeHLC, startPerformanceLogger, t, tryCatch, tryCatchAsync, validateNewCrdtEvent, verifySyncSchema, xxhash };
|
|
1
|
+
import { $t as AnyColumnBuilder, A as createCrdtApplyFunction, An as dummyKysely, B as defineSyncSchema, Bt as ColumnMetadata, C as WorkerNotificationMessage, Cn as CrdtEventOrigin, Ct as tryCatch, D as SnapshotOptions, Dn as CrdtUpdateLogPayload, Dt as createSQLiteKvStore, E as CrdtStorageMutator, En as CrdtUpdateLogItem, Et as createKvStoreTableQuery, F as CrdtEventValidationError, Ft as SQLiteDbWrapper, G as SharedLiveQuerySnapshot, Gt as HLCCounter, H as admitClientEvents, Ht as TableMetadata, I as NewCrdtEventValidationResult, It as SQLiteTransactionWrapper, J as ImportDataOptions, Jt as serializeHLC, K as parametersAreEqual, Kt as compareHLC, L as validateNewCrdtEvent, Lt as LogLevel, M as SchemaVerificationIssue, N as formatSchemaVerificationIssues, Nt as PreparedStatement, O as createCrdtStorageMutator, On as PersistedCrdtEvent, Ot as ExecuteParams, P as verifySyncSchema, Pt as QueryBuilderOutput, Q as createImportData, Qt as AiAccess, R as DefineSyncSchemaConfig, Rt as Logger, S as WorkerConfig, Sn as CRDT_EVENT_NO_OP_PAYLOAD, St as quoteId, T as createCrdtSyncProducer, Tn as CrdtEventType, Tt as KvStoreItem, U as SQLiteReactiveDb, Ut as introspectDb, V as AdmitClientEventsResult, Vt as DatabaseIntrospection, W as SharedLiveQuery, Wt as HLC, X as SyncedDbExport, Xt as ReadonlyTable, Y as ImportDataResult, Yt as CrdtTableConfig, Z as createExportData, Zt as SyncDbSchema, _ as EventsPullRequest, _n as SyncDbMigrator, _t as TypedEventTarget, a as SyncedDbDatabase, an as InferRow, at as SystemDbConfig, b as createCrdtSyncRemoteSource, bn as StoredValue, bt as generateId, c as SyncedDbTransaction, cn as SyncSchemaTables, ct as applyMemoryDbSchema, dn as TableOptions, en as AnyTableBuilder, et as CrdtStorage, fn as WriteOrigin, gn as MigrationsDb, gt as TypedEvent, h as CrdtSyncRemoteSource, hn as Migrations, ht as TypedBroadcastChannel, i as SyncedDb, in as ExportImportMode, it as createCrdtStorage, j as createSQLiteCrdtApplyFunction, jt as KyselyQueryFactory, k as PendingCrdtEvent, kn as isNoOpCrdtEventPayload, kt as ExecuteResult, l as UnsafeSyncedDbSqlExecutor, ln as TableBuilder, lt as applyWorkerDbSchema, m as makeCrdtTable, mn as MigratableEvent, mt as DistributiveOmit, n as ResetRequest, nn as ColumnKind, nt as OwnCrdtEvent, o as SyncedDbOptions, on as PayloadValidationResult, ot as SystemMigration, pn as t, pt as DeferredPromise, q as xxhash, qt as deserializeHLC, r as ResetStore, rn as ColumnMeta, rt as OwnCrdtSnapshot, s as SyncedDbSqlExecutor, sn as SqliteStorageType, st as SystemMigrationContext, t as RESET_REQUEST_TTL_MS, tn as ColumnBuilder, u as createSyncedDb, un as TableColumns, v as EventsPushRequest, vn as createMigrations, vt as createDeferredPromise, w as WorkerState, wn as CrdtEventStatus, wt as tryCatchAsync, xn as createStoredValue, xt as jsonSafeParse, y as EventsPushResponse, yn as createMigrator, yt as createTypedEventTarget, z as DefinedSyncSchema, zt as startPerformanceLogger } from "./index-iXdCBXzB.js";
|
|
2
|
+
export { type AdmitClientEventsResult, type AiAccess, type AnyColumnBuilder, type AnyTableBuilder, CRDT_EVENT_NO_OP_PAYLOAD, ColumnBuilder, type ColumnKind, type ColumnMeta, type ColumnMetadata, type CrdtEventOrigin, type CrdtEventStatus, type CrdtEventType, CrdtEventValidationError, type CrdtStorage, type CrdtStorageMutator, type CrdtSyncRemoteSource, type CrdtTableConfig, type CrdtUpdateLogItem, type CrdtUpdateLogPayload, type DatabaseIntrospection, type DeferredPromise, type DefineSyncSchemaConfig, type DefinedSyncSchema, type DistributiveOmit, type EventsPullRequest, type EventsPushRequest, type EventsPushResponse, type ExecuteParams, type ExecuteResult, type ExportImportMode, type HLC, HLCCounter, type ImportDataOptions, type ImportDataResult, type InferRow, type KvStoreItem, type KyselyQueryFactory, type LogLevel, type Logger, type MigratableEvent, type Migrations, type MigrationsDb, type NewCrdtEventValidationResult, type OwnCrdtEvent, type OwnCrdtSnapshot, type PayloadValidationResult, type PendingCrdtEvent, type PersistedCrdtEvent, type PreparedStatement, type QueryBuilderOutput, RESET_REQUEST_TTL_MS, type ReadonlyTable, type ResetRequest, type ResetStore, SQLiteDbWrapper, SQLiteReactiveDb, type SQLiteTransactionWrapper, type SchemaVerificationIssue, type SharedLiveQuery, type SharedLiveQuerySnapshot, type SnapshotOptions, type SqliteStorageType, type StoredValue, type SyncDbMigrator, type SyncDbSchema, type SyncSchemaTables, type SyncedDb, type SyncedDbDatabase, type SyncedDbExport, type SyncedDbOptions, type SyncedDbSqlExecutor, type SyncedDbTransaction, type SystemDbConfig, type SystemMigration, type SystemMigrationContext, TableBuilder, type TableColumns, type TableMetadata, type TableOptions, TypedBroadcastChannel, TypedEvent, type TypedEventTarget, type UnsafeSyncedDbSqlExecutor, type WorkerConfig, type WorkerNotificationMessage, type WorkerState, type WriteOrigin, admitClientEvents, applyMemoryDbSchema, applyWorkerDbSchema, compareHLC, createCrdtApplyFunction, createCrdtStorage, createCrdtStorageMutator, createCrdtSyncProducer, createCrdtSyncRemoteSource, createDeferredPromise, createExportData, createImportData, createKvStoreTableQuery, createMigrations, createMigrator, createSQLiteCrdtApplyFunction, createSQLiteKvStore, createStoredValue, createSyncedDb, createTypedEventTarget, defineSyncSchema, deserializeHLC, dummyKysely, formatSchemaVerificationIssues, generateId, introspectDb, isNoOpCrdtEventPayload, jsonSafeParse, makeCrdtTable, parametersAreEqual, quoteId, serializeHLC, startPerformanceLogger, t, tryCatch, tryCatchAsync, validateNewCrdtEvent, verifySyncSchema, xxhash };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as serializeHLC, C as createMigrator, D as HLCCounter, E as introspectDb, M as createExportData, N as createImportData, O as compareHLC, P as dummyKysely, S as createMigrations, T as startPerformanceLogger, _ as createSQLiteCrdtApplyFunction, a as createBroadcastChannels, b as CrdtEventValidationError, c as isWorkerNotificationMessage, d as syncDbClientLockName, g as createCrdtApplyFunction, h as createCrdtStorage, j as xxhash, k as deserializeHLC, m as createCrdtSyncProducer, o as isWorkerErrorResponseMessage, p as createCrdtSyncRemoteSource, t as RESET_REQUEST_TTL_MS, u as isWorkerResponseMessage, v as formatSchemaVerificationIssues, w as SQLiteDbWrapper, x as validateNewCrdtEvent, y as verifySyncSchema } from "./reset-state-
|
|
1
|
+
import { A as serializeHLC, C as createMigrator, D as HLCCounter, E as introspectDb, M as createExportData, N as createImportData, O as compareHLC, P as dummyKysely, S as createMigrations, T as startPerformanceLogger, _ as createSQLiteCrdtApplyFunction, a as createBroadcastChannels, b as CrdtEventValidationError, c as isWorkerNotificationMessage, d as syncDbClientLockName, g as createCrdtApplyFunction, h as createCrdtStorage, j as xxhash, k as deserializeHLC, m as createCrdtSyncProducer, o as isWorkerErrorResponseMessage, p as createCrdtSyncRemoteSource, t as RESET_REQUEST_TTL_MS, u as isWorkerResponseMessage, v as formatSchemaVerificationIssues, w as SQLiteDbWrapper, x as validateNewCrdtEvent, y as verifySyncSchema } from "./reset-state-4Hn95CKG.js";
|
|
2
2
|
import { c as noop, d as tryCatch, f as tryCatchAsync, i as createTypedEventTarget, n as TypedEvent, o as generateId, r as createDeferredPromise, s as jsonSafeParse, t as TypedBroadcastChannel, u as quoteId } from "./utils-Dr5JwcTP.js";
|
|
3
3
|
import { a as memoryDbConfig, c as createKvStoreTableQuery, d as CRDT_EVENT_NO_OP_PAYLOAD, f as isNoOpCrdtEventPayload, l as createSQLiteKvStore, n as applyWorkerDbSchema, t as applyMemoryDbSchema, u as createStoredValue } from "./system-schema-CkglcfTS.js";
|
|
4
4
|
import { a as registerCrdtIntentDrainer, i as makeCrdtTable } from "./make-crdt-table-CvpTHmRY.js";
|
|
@@ -344,8 +344,8 @@ function buildWriteOriginByName(schema) {
|
|
|
344
344
|
return writeOriginByName;
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
|
-
* Splits a client push into events the hub should persist and events for tables
|
|
348
|
-
*
|
|
347
|
+
* Splits a client push into events the hub should persist and events for tables with
|
|
348
|
+
* `{ writes: "server" }`. Unknown datasets stay admitted. Matches either the crdt or the base
|
|
349
349
|
* table name.
|
|
350
350
|
*/
|
|
351
351
|
function admitClientEvents(opts) {
|
|
@@ -379,7 +379,8 @@ const RESERVED_TABLE_NAMES = /* @__PURE__ */ new Set([
|
|
|
379
379
|
function defineSyncSchema({ tables, migrations }) {
|
|
380
380
|
const tablesConfig = Object.entries(tables).map(([crdtTableName, table]) => ({
|
|
381
381
|
crdtTableName,
|
|
382
|
-
baseTableName: table.baseName ?? `_${crdtTableName}
|
|
382
|
+
baseTableName: table.baseName ?? `_${crdtTableName}`,
|
|
383
|
+
...table.exportImport === "ignore" ? { exportImport: "ignore" } : {}
|
|
383
384
|
}));
|
|
384
385
|
const seenNames = /* @__PURE__ */ new Set();
|
|
385
386
|
for (const { crdtTableName, baseTableName } of tablesConfig) for (const name of [crdtTableName, baseTableName]) {
|
|
@@ -470,16 +471,12 @@ var TableBuilder = class TableBuilder {
|
|
|
470
471
|
columns;
|
|
471
472
|
baseName;
|
|
472
473
|
description;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
/** Who may author events for this table; "any" unless narrowed via `.writes()`. */
|
|
480
|
-
get writeOrigin() {
|
|
481
|
-
return this.#writeOrigin;
|
|
482
|
-
}
|
|
474
|
+
/** Resolved {@link AiAccess}; defaults to `"read-write"`. */
|
|
475
|
+
aiAccess;
|
|
476
|
+
/** Resolved {@link WriteOrigin}; defaults to `"any"`. */
|
|
477
|
+
writeOrigin;
|
|
478
|
+
/** Resolved {@link ExportImportMode}; defaults to `"include"`. */
|
|
479
|
+
exportImport;
|
|
483
480
|
constructor(userColumns, options) {
|
|
484
481
|
this.userColumns = userColumns;
|
|
485
482
|
for (const reserved of RESERVED_COLUMNS) if (reserved in userColumns) throw new Error(`Column "${reserved}" is added automatically to every synced table and cannot be declared`);
|
|
@@ -490,32 +487,18 @@ var TableBuilder = class TableBuilder {
|
|
|
490
487
|
};
|
|
491
488
|
this.baseName = options?.baseName;
|
|
492
489
|
this.description = options?.description;
|
|
490
|
+
this.aiAccess = options?.ai ?? "read-write";
|
|
491
|
+
this.writeOrigin = options?.writes ?? "any";
|
|
492
|
+
this.exportImport = options?.exportImport ?? "include";
|
|
493
493
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const next = new TableBuilder(this.userColumns, {
|
|
494
|
+
describe(description) {
|
|
495
|
+
return new TableBuilder(this.userColumns, {
|
|
497
496
|
baseName: this.baseName,
|
|
498
|
-
description
|
|
499
|
-
|
|
497
|
+
description,
|
|
498
|
+
ai: this.aiAccess,
|
|
499
|
+
writes: this.writeOrigin,
|
|
500
|
+
exportImport: this.exportImport
|
|
500
501
|
});
|
|
501
|
-
next.#aiAccess = this.#aiAccess;
|
|
502
|
-
next.#writeOrigin = this.#writeOrigin;
|
|
503
|
-
return next;
|
|
504
|
-
}
|
|
505
|
-
describe(description) {
|
|
506
|
-
return this.withOptions({ description });
|
|
507
|
-
}
|
|
508
|
-
/** Restrict what an AI agent may do with this table; see {@link AiAccess}. */
|
|
509
|
-
ai(access) {
|
|
510
|
-
const next = this.withOptions({});
|
|
511
|
-
next.#aiAccess = access;
|
|
512
|
-
return next;
|
|
513
|
-
}
|
|
514
|
-
/** Restrict which replicas may author events for this table; see {@link WriteOrigin}. */
|
|
515
|
-
writes(origin) {
|
|
516
|
-
const next = this.withOptions({});
|
|
517
|
-
next.#writeOrigin = origin;
|
|
518
|
-
return next;
|
|
519
502
|
}
|
|
520
503
|
/** Type-only: the row shape returned by queries. Do not access at runtime. */
|
|
521
504
|
get $row() {
|