korajs 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -17
- package/dist/chunk-WALHLVVF.js +683 -0
- package/dist/chunk-WALHLVVF.js.map +1 -0
- package/dist/index.cjs +1316 -347
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -37
- package/dist/index.d.ts +92 -37
- package/dist/index.js +687 -376
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +47 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +3 -0
- package/dist/react.d.ts +3 -0
- package/dist/react.js +24 -0
- package/dist/react.js.map +1 -0
- package/dist/svelte.cjs +71 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +1 -0
- package/dist/svelte.d.ts +1 -0
- package/dist/svelte.js +48 -0
- package/dist/svelte.js.map +1 -0
- 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/dist/vue.cjs +57 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +1 -0
- package/dist/vue.d.ts +1 -0
- package/dist/vue.js +34 -0
- package/dist/vue.js.map +1 -0
- package/package.json +83 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
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 { AppNotReadyError, 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';
|
|
10
|
+
import { AuthSyncBinding } from '@korajs/core/bindings';
|
|
11
|
+
export { AuthSyncBinding } from '@korajs/core/bindings';
|
|
9
12
|
export { MergeEngine, MergeInput, MergeResult } from '@korajs/merge';
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -24,9 +27,19 @@ interface StoreOptions {
|
|
|
24
27
|
adapter?: AdapterType;
|
|
25
28
|
/** Database name. Defaults to 'kora-db'. */
|
|
26
29
|
name?: string;
|
|
30
|
+
/**
|
|
31
|
+
* `shared` (default): one sync node id per database.
|
|
32
|
+
* `per-tab`: unique node id per browser tab (sessionStorage).
|
|
33
|
+
*/
|
|
34
|
+
isolation?: _korajs_store.StoreIsolation;
|
|
27
35
|
/** URL to the SQLite WASM worker script. Required for browser adapters (sqlite-wasm, indexeddb). */
|
|
28
36
|
workerUrl?: string | URL;
|
|
37
|
+
/** Optional SharedWorker host for multi-tab SQLite (see `@korajs/store/sqlite-wasm/shared-host`). */
|
|
38
|
+
sharedWorkerUrl?: string | URL;
|
|
39
|
+
/** Max wait for a worker RPC (e.g. `open`). Defaults to 30000ms. */
|
|
40
|
+
workerResponseTimeoutMs?: number;
|
|
29
41
|
}
|
|
42
|
+
|
|
30
43
|
/**
|
|
31
44
|
* Sync configuration within createApp.
|
|
32
45
|
*/
|
|
@@ -39,6 +52,11 @@ interface SyncOptions {
|
|
|
39
52
|
auth?: () => Promise<{
|
|
40
53
|
token: string;
|
|
41
54
|
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Pre-built auth binding from `createKoraAuthSync({ authClient, schema })`.
|
|
57
|
+
* When set, overrides `auth`, auto-builds `scopeMap`, and binds store node id to `dev`.
|
|
58
|
+
*/
|
|
59
|
+
authClient?: AuthSyncBinding;
|
|
42
60
|
/** Sync scopes per collection. */
|
|
43
61
|
scopes?: Record<string, (ctx: Record<string, unknown>) => Record<string, unknown>>;
|
|
44
62
|
/**
|
|
@@ -61,12 +79,23 @@ interface SyncOptions {
|
|
|
61
79
|
batchSize?: number;
|
|
62
80
|
/** Schema version of this client. */
|
|
63
81
|
schemaVersion?: number;
|
|
82
|
+
/** Connect to the sync server automatically after `app.ready`. Defaults to false. */
|
|
83
|
+
autoConnect?: boolean;
|
|
84
|
+
/** Wait for server ACK on each handshake delta batch before streaming. Defaults to false. */
|
|
85
|
+
strictHandshake?: boolean;
|
|
86
|
+
/** Rewrites legacy operations during sync when schema versions differ. */
|
|
87
|
+
operationTransforms?: _korajs_core.OperationTransform[];
|
|
64
88
|
/** Enable auto-reconnection on unexpected disconnect. Defaults to true. */
|
|
65
89
|
autoReconnect?: boolean;
|
|
66
90
|
/** Initial reconnection delay in ms. Defaults to 1000. */
|
|
67
91
|
reconnectInterval?: number;
|
|
68
92
|
/** Maximum reconnection delay in ms. Defaults to 30000. */
|
|
69
93
|
maxReconnectInterval?: number;
|
|
94
|
+
/**
|
|
95
|
+
* End-to-end encryption for operation payloads on the sync wire.
|
|
96
|
+
* When enabled, `data` and `previousData` are encrypted before send.
|
|
97
|
+
*/
|
|
98
|
+
encryption?: _korajs_sync.SyncEncryptionConfig;
|
|
70
99
|
}
|
|
71
100
|
/**
|
|
72
101
|
* Full configuration passed to createApp().
|
|
@@ -80,7 +109,15 @@ interface KoraConfig {
|
|
|
80
109
|
sync?: SyncOptions;
|
|
81
110
|
/** Enable DevTools instrumentation. Defaults to false. */
|
|
82
111
|
devtools?: boolean;
|
|
112
|
+
/** Called for each sync-related framework event. */
|
|
113
|
+
onSyncEvent?: (event: Extract<KoraEvent, {
|
|
114
|
+
type: `sync:${string}`;
|
|
115
|
+
}>) => void;
|
|
83
116
|
}
|
|
117
|
+
/** Sync event types delivered to {@link KoraConfig.onSyncEvent}. */
|
|
118
|
+
type KoraSyncEvent = Extract<KoraEvent, {
|
|
119
|
+
type: `sync:${string}`;
|
|
120
|
+
}>;
|
|
84
121
|
/**
|
|
85
122
|
* Typed configuration passed to createApp() when using a TypedSchemaDefinition.
|
|
86
123
|
*/
|
|
@@ -95,6 +132,8 @@ interface TypedKoraConfig<S extends SchemaInput> {
|
|
|
95
132
|
sync?: SyncOptions;
|
|
96
133
|
/** Enable DevTools instrumentation. Defaults to false. */
|
|
97
134
|
devtools?: boolean;
|
|
135
|
+
/** Called for each sync-related framework event. */
|
|
136
|
+
onSyncEvent?: (event: KoraSyncEvent) => void;
|
|
98
137
|
}
|
|
99
138
|
/**
|
|
100
139
|
* Controls for the sync subsystem exposed on the KoraApp.
|
|
@@ -104,10 +143,16 @@ interface SyncControl {
|
|
|
104
143
|
connect(): Promise<void>;
|
|
105
144
|
/** Disconnect from the sync server. */
|
|
106
145
|
disconnect(): Promise<void>;
|
|
146
|
+
/** Current sync status snapshot (updates on sync events). */
|
|
147
|
+
readonly status: SyncStatusInfo;
|
|
107
148
|
/** Get the current developer-facing sync status. */
|
|
108
149
|
getStatus(): SyncStatusInfo;
|
|
150
|
+
/** Subscribe to status changes (event-driven, no polling). */
|
|
151
|
+
subscribeStatus(listener: (status: SyncStatusInfo) => void): () => void;
|
|
109
152
|
/** Force an immediate reconnection attempt. No-op if already connected. */
|
|
110
153
|
retryNow(): Promise<void>;
|
|
154
|
+
/** Clear schema-mismatch block after upgrading schema; then call `connect()`. */
|
|
155
|
+
clearSchemaBlock(): void;
|
|
111
156
|
/** Export a diagnostics snapshot for debugging and support tickets. */
|
|
112
157
|
exportDiagnostics(): _korajs_sync.SyncDiagnostics;
|
|
113
158
|
}
|
|
@@ -189,6 +234,8 @@ interface KoraApp {
|
|
|
189
234
|
getStore(): _korajs_store.Store;
|
|
190
235
|
/** Get the underlying SyncEngine instance. Null if sync not configured. */
|
|
191
236
|
getSyncEngine(): SyncEngine | null;
|
|
237
|
+
/** Per-app reference-counted cache for framework query subscriptions. */
|
|
238
|
+
getQueryStoreCache(): _korajs_store.QueryStoreCache;
|
|
192
239
|
/** Gracefully close the app: stop sync, close store. */
|
|
193
240
|
close(): Promise<void>;
|
|
194
241
|
/**
|
|
@@ -218,6 +265,35 @@ interface KoraApp {
|
|
|
218
265
|
* ```
|
|
219
266
|
*/
|
|
220
267
|
mutation(name: string, fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
268
|
+
/**
|
|
269
|
+
* Export all data as a portable backup binary.
|
|
270
|
+
* Delegates to the underlying store's exportBackup.
|
|
271
|
+
*
|
|
272
|
+
* @param options - Backup options (includeRecords, collections, onProgress)
|
|
273
|
+
* @returns Backup as a Uint8Array
|
|
274
|
+
*/
|
|
275
|
+
exportBackup(options?: BackupOptions): Promise<Uint8Array>;
|
|
276
|
+
/**
|
|
277
|
+
* Restore data from a backup binary.
|
|
278
|
+
* Delegates to the underlying store's importBackup.
|
|
279
|
+
*
|
|
280
|
+
* @param data - The backup data
|
|
281
|
+
* @param options - Restore options (merge, collections, onProgress)
|
|
282
|
+
* @returns Result of the restore operation
|
|
283
|
+
*/
|
|
284
|
+
importBackup(data: Uint8Array, options?: RestoreOptions): Promise<RestoreResult>;
|
|
285
|
+
/**
|
|
286
|
+
* Rebuild an in-memory snapshot at a causal cut in the operation log.
|
|
287
|
+
* Does not mutate live data — for DevTools time-travel and audit inspection.
|
|
288
|
+
*
|
|
289
|
+
* @param operationId - Content-addressed operation id to replay through (inclusive)
|
|
290
|
+
*/
|
|
291
|
+
replayTo(operationId: string): Promise<ReplaySnapshot>;
|
|
292
|
+
/**
|
|
293
|
+
* Export the operation log and persisted merge traces as a portable audit bundle.
|
|
294
|
+
* Merge traces are recorded automatically when conflicts are resolved.
|
|
295
|
+
*/
|
|
296
|
+
exportAudit(options?: AuditExportOptions): Promise<Uint8Array>;
|
|
221
297
|
/** Dynamic collection accessors (e.g., app.todos). Typed via Object.defineProperty. */
|
|
222
298
|
[collection: string]: unknown;
|
|
223
299
|
}
|
|
@@ -254,12 +330,22 @@ type TypedKoraApp<S extends SchemaInput> = {
|
|
|
254
330
|
getStore(): _korajs_store.Store;
|
|
255
331
|
/** Get the underlying SyncEngine instance. Null if sync not configured. */
|
|
256
332
|
getSyncEngine(): SyncEngine | null;
|
|
333
|
+
/** Per-app reference-counted cache for framework query subscriptions. */
|
|
334
|
+
getQueryStoreCache(): _korajs_store.QueryStoreCache;
|
|
257
335
|
/** Gracefully close the app: stop sync, close store. */
|
|
258
336
|
close(): Promise<void>;
|
|
259
337
|
/** Execute multiple mutations atomically within a transaction. */
|
|
260
338
|
transaction(fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
261
339
|
/** Execute a named mutation — a transaction with a DevTools-visible name. */
|
|
262
340
|
mutation(name: string, fn: (tx: TransactionProxy) => Promise<void>): Promise<Operation[]>;
|
|
341
|
+
/** Export all data as a portable backup binary. */
|
|
342
|
+
exportBackup(options?: BackupOptions): Promise<Uint8Array>;
|
|
343
|
+
/** Restore data from a backup binary. */
|
|
344
|
+
importBackup(data: Uint8Array, options?: RestoreOptions): Promise<RestoreResult>;
|
|
345
|
+
/** Rebuild an in-memory snapshot at a causal cut in the operation log. */
|
|
346
|
+
replayTo(operationId: string): Promise<ReplaySnapshot>;
|
|
347
|
+
/** Export the operation log and persisted merge traces as a portable audit bundle. */
|
|
348
|
+
exportAudit(options?: AuditExportOptions): Promise<Uint8Array>;
|
|
263
349
|
} & {
|
|
264
350
|
readonly [C in keyof S['collections'] & string]: S['collections'][C] extends {
|
|
265
351
|
fields: infer F extends Record<string, FieldBuilder<any, any, any>>;
|
|
@@ -272,39 +358,8 @@ type TypedKoraApp<S extends SchemaInput> = {
|
|
|
272
358
|
* Wires together store, merge engine, event emitter, and optionally sync
|
|
273
359
|
* into a single developer-facing `KoraApp` object. Collection accessors
|
|
274
360
|
* (e.g. `app.todos`) are defined as properties for immediate use after `await app.ready`.
|
|
275
|
-
*
|
|
276
|
-
* @param config - Application configuration including schema and optional sync settings
|
|
277
|
-
* @returns A KoraApp instance with reactive collections ready for use
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* const app = createApp({
|
|
282
|
-
* schema: defineSchema({
|
|
283
|
-
* version: 1,
|
|
284
|
-
* collections: {
|
|
285
|
-
* todos: {
|
|
286
|
-
* fields: {
|
|
287
|
-
* title: t.string(),
|
|
288
|
-
* completed: t.boolean().default(false)
|
|
289
|
-
* }
|
|
290
|
-
* }
|
|
291
|
-
* }
|
|
292
|
-
* })
|
|
293
|
-
* })
|
|
294
|
-
*
|
|
295
|
-
* await app.ready
|
|
296
|
-
* const todo = await app.todos.insert({ title: 'Hello' })
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
/**
|
|
300
|
-
* Creates a new typed Kora application instance.
|
|
301
|
-
* When the schema is created with `defineSchema()`, full type inference flows through
|
|
302
|
-
* to collection accessors, providing autocomplete and type checking for all CRUD operations.
|
|
303
361
|
*/
|
|
304
362
|
declare function createApp<const S extends SchemaInput>(config: TypedKoraConfig<S>): TypedKoraApp<S>;
|
|
305
|
-
/**
|
|
306
|
-
* Creates a new Kora application instance (untyped fallback).
|
|
307
|
-
*/
|
|
308
363
|
declare function createApp(config: KoraConfig): KoraApp;
|
|
309
364
|
|
|
310
365
|
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 };
|