korajs 0.4.0 → 0.5.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/chunk-WALHLVVF.js +683 -0
- package/dist/chunk-WALHLVVF.js.map +1 -0
- package/dist/index.cjs +1090 -136
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -7
- package/dist/index.d.ts +105 -7
- package/dist/index.js +450 -149
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +700 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +111 -0
- package/dist/testing.d.ts +111 -0
- package/dist/testing.js +13 -0
- package/dist/testing.js.map +1 -0
- package/package.json +19 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { CollectionRecord, QueryBuilder, CollectionAccessor } from '@korajs/store';
|
|
5
|
-
export { CollectionAccessor, CollectionRecord, SequenceManager, StorageAdapter, Store, StoreConfig, TransactionCollectionAccessor, TransactionContext, TransactionContextConfig } from '@korajs/store';
|
|
1
|
+
import * as _korajs_core from '@korajs/core';
|
|
2
|
+
import { KoraEventEmitter, SequenceConfig, Operation, SchemaDefinition, KoraEvent, SchemaInput, FieldBuilder, InferRecord, InferInsertInput, InferUpdateInput } from '@korajs/core';
|
|
3
|
+
export { AtomicOp, AtomicOpType, CollectionDefinition, ConnectionQuality, Constraint, FieldDescriptor, FieldKindToType, HLCTimestamp, HybridLogicalClock, InferFieldType, InferInsertInput, InferRecord, InferUpdateInput, KoraError, KoraEvent, KoraEventEmitter, KoraEventListener, KoraEventType, MergeStrategy, MergeTrace, MigrationDefinition, MigrationStep, Operation, SchemaDefinition, SchemaInput, SequenceConfig, SyncRuleDefinition, TypedSchemaDefinition, VersionVector, createOperation, defineSchema, generateUUIDv7, migrate, op, t } from '@korajs/core';
|
|
6
4
|
import * as _korajs_sync from '@korajs/sync';
|
|
7
5
|
import { SyncStatusInfo, SyncEngine } from '@korajs/sync';
|
|
8
|
-
export { SyncConfig, SyncDiagnostics, SyncEngine, SyncState, SyncStatus, SyncStatusInfo, SyncStore, WebSocketTransport } from '@korajs/sync';
|
|
6
|
+
export { SyncConfig, SyncDiagnostics, SyncEncryptionConfig, SyncEngine, SyncState, SyncStatus, SyncStatusInfo, SyncStore, WebSocketTransport } from '@korajs/sync';
|
|
7
|
+
import * as _korajs_store from '@korajs/store';
|
|
8
|
+
import { CollectionRecord, BackupOptions, RestoreOptions, RestoreResult, ReplaySnapshot, AuditExportOptions, QueryBuilder, CollectionAccessor } from '@korajs/store';
|
|
9
|
+
export { AuditExportManifest, AuditExportOptions, AuditExportPayload, BackupManifest, BackupOptions, BackupProgress, CollectionAccessor, CollectionRecord, PersistedAuditTrace, ReplaySnapshot, RestoreOptions, RestoreResult, SequenceManager, StorageAdapter, Store, StoreConfig, TransactionCollectionAccessor, TransactionContext, TransactionContextConfig, decodeAuditExport, exportBackup, readAuditExportManifest, readBackupManifest, restoreBackup, verifyAuditExportChecksum, verifyBackupChecksum } from '@korajs/store';
|
|
9
10
|
export { MergeEngine, MergeInput, MergeResult } from '@korajs/merge';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -24,8 +25,36 @@ interface StoreOptions {
|
|
|
24
25
|
adapter?: AdapterType;
|
|
25
26
|
/** Database name. Defaults to 'kora-db'. */
|
|
26
27
|
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* `shared` (default): one sync node id per database.
|
|
30
|
+
* `per-tab`: unique node id per browser tab (sessionStorage).
|
|
31
|
+
*/
|
|
32
|
+
isolation?: _korajs_store.StoreIsolation;
|
|
27
33
|
/** URL to the SQLite WASM worker script. Required for browser adapters (sqlite-wasm, indexeddb). */
|
|
28
34
|
workerUrl?: string | URL;
|
|
35
|
+
/** Optional SharedWorker host for multi-tab SQLite (see `@korajs/store/sqlite-wasm/shared-host`). */
|
|
36
|
+
sharedWorkerUrl?: string | URL;
|
|
37
|
+
/** Max wait for a worker RPC (e.g. `open`). Defaults to 30000ms. */
|
|
38
|
+
workerResponseTimeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pre-built auth binding from `createKoraAuthSync()` in `@korajs/auth`.
|
|
42
|
+
* Wires token refresh, JWT scope maps, and device-bound sync node ids.
|
|
43
|
+
*/
|
|
44
|
+
interface AuthSyncBinding {
|
|
45
|
+
/** Returns the access token for sync handshake (empty string when signed out). */
|
|
46
|
+
auth: () => Promise<{
|
|
47
|
+
token: string;
|
|
48
|
+
}>;
|
|
49
|
+
/** Builds a scope map from the current token and schema. */
|
|
50
|
+
resolveScopeMap?: () => Promise<Record<string, Record<string, unknown>> | undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the device-bound sync node id from the token `dev` claim.
|
|
53
|
+
* Separate from the user id (`sub`).
|
|
54
|
+
*/
|
|
55
|
+
resolveNodeId?: () => Promise<string | undefined>;
|
|
56
|
+
/** Notifies when auth state changes so sync can refresh scope or reconnect. */
|
|
57
|
+
subscribe?: (listener: () => void) => () => void;
|
|
29
58
|
}
|
|
30
59
|
/**
|
|
31
60
|
* Sync configuration within createApp.
|
|
@@ -39,6 +68,11 @@ interface SyncOptions {
|
|
|
39
68
|
auth?: () => Promise<{
|
|
40
69
|
token: string;
|
|
41
70
|
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Pre-built auth binding from `createKoraAuthSync({ authClient, schema })`.
|
|
73
|
+
* When set, overrides `auth`, auto-builds `scopeMap`, and binds store node id to `dev`.
|
|
74
|
+
*/
|
|
75
|
+
authClient?: AuthSyncBinding;
|
|
42
76
|
/** Sync scopes per collection. */
|
|
43
77
|
scopes?: Record<string, (ctx: Record<string, unknown>) => Record<string, unknown>>;
|
|
44
78
|
/**
|
|
@@ -61,12 +95,23 @@ interface SyncOptions {
|
|
|
61
95
|
batchSize?: number;
|
|
62
96
|
/** Schema version of this client. */
|
|
63
97
|
schemaVersion?: number;
|
|
98
|
+
/** Connect to the sync server automatically after `app.ready`. Defaults to false. */
|
|
99
|
+
autoConnect?: boolean;
|
|
100
|
+
/** Wait for server ACK on each handshake delta batch before streaming. Defaults to false. */
|
|
101
|
+
strictHandshake?: boolean;
|
|
102
|
+
/** Rewrites legacy operations during sync when schema versions differ. */
|
|
103
|
+
operationTransforms?: _korajs_core.OperationTransform[];
|
|
64
104
|
/** Enable auto-reconnection on unexpected disconnect. Defaults to true. */
|
|
65
105
|
autoReconnect?: boolean;
|
|
66
106
|
/** Initial reconnection delay in ms. Defaults to 1000. */
|
|
67
107
|
reconnectInterval?: number;
|
|
68
108
|
/** Maximum reconnection delay in ms. Defaults to 30000. */
|
|
69
109
|
maxReconnectInterval?: number;
|
|
110
|
+
/**
|
|
111
|
+
* End-to-end encryption for operation payloads on the sync wire.
|
|
112
|
+
* When enabled, `data` and `previousData` are encrypted before send.
|
|
113
|
+
*/
|
|
114
|
+
encryption?: _korajs_sync.SyncEncryptionConfig;
|
|
70
115
|
}
|
|
71
116
|
/**
|
|
72
117
|
* Full configuration passed to createApp().
|
|
@@ -80,7 +125,15 @@ interface KoraConfig {
|
|
|
80
125
|
sync?: SyncOptions;
|
|
81
126
|
/** Enable DevTools instrumentation. Defaults to false. */
|
|
82
127
|
devtools?: boolean;
|
|
128
|
+
/** Called for each sync-related framework event. */
|
|
129
|
+
onSyncEvent?: (event: Extract<KoraEvent, {
|
|
130
|
+
type: `sync:${string}`;
|
|
131
|
+
}>) => void;
|
|
83
132
|
}
|
|
133
|
+
/** Sync event types delivered to {@link KoraConfig.onSyncEvent}. */
|
|
134
|
+
type KoraSyncEvent = Extract<KoraEvent, {
|
|
135
|
+
type: `sync:${string}`;
|
|
136
|
+
}>;
|
|
84
137
|
/**
|
|
85
138
|
* Typed configuration passed to createApp() when using a TypedSchemaDefinition.
|
|
86
139
|
*/
|
|
@@ -95,6 +148,8 @@ interface TypedKoraConfig<S extends SchemaInput> {
|
|
|
95
148
|
sync?: SyncOptions;
|
|
96
149
|
/** Enable DevTools instrumentation. Defaults to false. */
|
|
97
150
|
devtools?: boolean;
|
|
151
|
+
/** Called for each sync-related framework event. */
|
|
152
|
+
onSyncEvent?: (event: KoraSyncEvent) => void;
|
|
98
153
|
}
|
|
99
154
|
/**
|
|
100
155
|
* Controls for the sync subsystem exposed on the KoraApp.
|
|
@@ -104,10 +159,16 @@ interface SyncControl {
|
|
|
104
159
|
connect(): Promise<void>;
|
|
105
160
|
/** Disconnect from the sync server. */
|
|
106
161
|
disconnect(): Promise<void>;
|
|
162
|
+
/** Current sync status snapshot (updates on sync events). */
|
|
163
|
+
readonly status: SyncStatusInfo;
|
|
107
164
|
/** Get the current developer-facing sync status. */
|
|
108
165
|
getStatus(): SyncStatusInfo;
|
|
166
|
+
/** Subscribe to status changes (event-driven, no polling). */
|
|
167
|
+
subscribeStatus(listener: (status: SyncStatusInfo) => void): () => void;
|
|
109
168
|
/** Force an immediate reconnection attempt. No-op if already connected. */
|
|
110
169
|
retryNow(): Promise<void>;
|
|
170
|
+
/** Clear schema-mismatch block after upgrading schema; then call `connect()`. */
|
|
171
|
+
clearSchemaBlock(): void;
|
|
111
172
|
/** Export a diagnostics snapshot for debugging and support tickets. */
|
|
112
173
|
exportDiagnostics(): _korajs_sync.SyncDiagnostics;
|
|
113
174
|
}
|
|
@@ -218,6 +279,35 @@ interface KoraApp {
|
|
|
218
279
|
* ```
|
|
219
280
|
*/
|
|
220
281
|
mutation(name: string, fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
282
|
+
/**
|
|
283
|
+
* Export all data as a portable backup binary.
|
|
284
|
+
* Delegates to the underlying store's exportBackup.
|
|
285
|
+
*
|
|
286
|
+
* @param options - Backup options (includeRecords, collections, onProgress)
|
|
287
|
+
* @returns Backup as a Uint8Array
|
|
288
|
+
*/
|
|
289
|
+
exportBackup(options?: BackupOptions): Promise<Uint8Array>;
|
|
290
|
+
/**
|
|
291
|
+
* Restore data from a backup binary.
|
|
292
|
+
* Delegates to the underlying store's importBackup.
|
|
293
|
+
*
|
|
294
|
+
* @param data - The backup data
|
|
295
|
+
* @param options - Restore options (merge, collections, onProgress)
|
|
296
|
+
* @returns Result of the restore operation
|
|
297
|
+
*/
|
|
298
|
+
importBackup(data: Uint8Array, options?: RestoreOptions): Promise<RestoreResult>;
|
|
299
|
+
/**
|
|
300
|
+
* Rebuild an in-memory snapshot at a causal cut in the operation log.
|
|
301
|
+
* Does not mutate live data — for DevTools time-travel and audit inspection.
|
|
302
|
+
*
|
|
303
|
+
* @param operationId - Content-addressed operation id to replay through (inclusive)
|
|
304
|
+
*/
|
|
305
|
+
replayTo(operationId: string): Promise<ReplaySnapshot>;
|
|
306
|
+
/**
|
|
307
|
+
* Export the operation log and persisted merge traces as a portable audit bundle.
|
|
308
|
+
* Merge traces are recorded automatically when conflicts are resolved.
|
|
309
|
+
*/
|
|
310
|
+
exportAudit(options?: AuditExportOptions): Promise<Uint8Array>;
|
|
221
311
|
/** Dynamic collection accessors (e.g., app.todos). Typed via Object.defineProperty. */
|
|
222
312
|
[collection: string]: unknown;
|
|
223
313
|
}
|
|
@@ -260,6 +350,14 @@ type TypedKoraApp<S extends SchemaInput> = {
|
|
|
260
350
|
transaction(fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
261
351
|
/** Execute a named mutation — a transaction with a DevTools-visible name. */
|
|
262
352
|
mutation(name: string, fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
353
|
+
/** Export all data as a portable backup binary. */
|
|
354
|
+
exportBackup(options?: BackupOptions): Promise<Uint8Array>;
|
|
355
|
+
/** Restore data from a backup binary. */
|
|
356
|
+
importBackup(data: Uint8Array, options?: RestoreOptions): Promise<RestoreResult>;
|
|
357
|
+
/** Rebuild an in-memory snapshot at a causal cut in the operation log. */
|
|
358
|
+
replayTo(operationId: string): Promise<ReplaySnapshot>;
|
|
359
|
+
/** Export the operation log and persisted merge traces as a portable audit bundle. */
|
|
360
|
+
exportAudit(options?: AuditExportOptions): Promise<Uint8Array>;
|
|
263
361
|
} & {
|
|
264
362
|
readonly [C in keyof S['collections'] & string]: S['collections'][C] extends {
|
|
265
363
|
fields: infer F extends Record<string, FieldBuilder<any, any, any>>;
|
|
@@ -307,4 +405,4 @@ declare function createApp<const S extends SchemaInput>(config: TypedKoraConfig<
|
|
|
307
405
|
*/
|
|
308
406
|
declare function createApp(config: KoraConfig): KoraApp;
|
|
309
407
|
|
|
310
|
-
export { type AdapterType, type KoraApp, type KoraConfig, type SequenceAccessor, type StoreOptions, type SyncControl, type SyncOptions, type TransactionCollectionProxy, type TransactionProxy, type TypedCollectionAccessor, type TypedKoraApp, type TypedKoraConfig, createApp };
|
|
408
|
+
export { type AdapterType, type AuthSyncBinding, type KoraApp, type KoraConfig, type SequenceAccessor, type StoreOptions, type SyncControl, type SyncOptions, type TransactionCollectionProxy, type TransactionProxy, type TypedCollectionAccessor, type TypedKoraApp, type TypedKoraConfig, createApp };
|