@trestleinc/replicate 1.1.1 → 1.1.2-preview.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 +395 -146
- package/dist/client/index.d.ts +311 -19
- package/dist/client/index.js +4027 -0
- package/dist/component/_generated/api.d.ts +13 -17
- package/dist/component/_generated/api.js +24 -4
- package/dist/component/_generated/component.d.ts +79 -77
- package/dist/component/_generated/component.js +1 -0
- package/dist/component/_generated/dataModel.d.ts +12 -15
- package/dist/component/_generated/dataModel.js +1 -0
- package/dist/component/_generated/server.d.ts +19 -22
- package/dist/component/_generated/server.js +65 -1
- package/dist/component/_virtual/rolldown_runtime.js +18 -0
- package/dist/component/convex.config.d.ts +6 -2
- package/dist/component/convex.config.js +7 -3
- package/dist/component/logger.d.ts +10 -6
- package/dist/component/logger.js +25 -28
- package/dist/component/public.d.ts +70 -61
- package/dist/component/public.js +311 -295
- package/dist/component/schema.d.ts +53 -45
- package/dist/component/schema.js +26 -32
- package/dist/component/shared/types.d.ts +9 -0
- package/dist/component/shared/types.js +15 -0
- package/dist/server/index.d.ts +134 -13
- package/dist/server/index.js +368 -0
- package/dist/shared/index.d.ts +27 -3
- package/dist/shared/index.js +1 -2
- package/package.json +34 -29
- package/src/client/collection.ts +339 -306
- package/src/client/errors.ts +9 -9
- package/src/client/index.ts +13 -32
- package/src/client/logger.ts +2 -2
- package/src/client/merge.ts +37 -34
- package/src/client/persistence/custom.ts +84 -0
- package/src/client/persistence/index.ts +9 -46
- package/src/client/persistence/indexeddb.ts +111 -84
- package/src/client/persistence/memory.ts +3 -3
- package/src/client/persistence/sqlite/browser.ts +168 -0
- package/src/client/persistence/sqlite/native.ts +29 -0
- package/src/client/persistence/sqlite/schema.ts +124 -0
- package/src/client/persistence/types.ts +32 -28
- package/src/client/prose-schema.ts +55 -0
- package/src/client/prose.ts +28 -25
- package/src/client/replicate.ts +5 -5
- package/src/client/services/cursor.ts +109 -0
- package/src/component/_generated/component.ts +31 -29
- package/src/component/convex.config.ts +2 -2
- package/src/component/logger.ts +7 -7
- package/src/component/public.ts +225 -237
- package/src/component/schema.ts +18 -15
- package/src/server/builder.ts +20 -7
- package/src/server/index.ts +3 -5
- package/src/server/schema.ts +5 -5
- package/src/server/storage.ts +113 -59
- package/src/shared/index.ts +5 -5
- package/src/shared/types.ts +51 -14
- package/dist/client/collection.d.ts +0 -96
- package/dist/client/errors.d.ts +0 -59
- package/dist/client/logger.d.ts +0 -2
- package/dist/client/merge.d.ts +0 -77
- package/dist/client/persistence/adapters/index.d.ts +0 -8
- package/dist/client/persistence/adapters/opsqlite.d.ts +0 -46
- package/dist/client/persistence/adapters/sqljs.d.ts +0 -83
- package/dist/client/persistence/index.d.ts +0 -49
- package/dist/client/persistence/indexeddb.d.ts +0 -17
- package/dist/client/persistence/memory.d.ts +0 -16
- package/dist/client/persistence/sqlite-browser.d.ts +0 -51
- package/dist/client/persistence/sqlite-level.d.ts +0 -63
- package/dist/client/persistence/sqlite-rn.d.ts +0 -36
- package/dist/client/persistence/sqlite.d.ts +0 -47
- package/dist/client/persistence/types.d.ts +0 -42
- package/dist/client/prose.d.ts +0 -56
- package/dist/client/replicate.d.ts +0 -40
- package/dist/client/services/checkpoint.d.ts +0 -18
- package/dist/client/services/reconciliation.d.ts +0 -24
- package/dist/index.js +0 -1618
- package/dist/server/builder.d.ts +0 -94
- package/dist/server/schema.d.ts +0 -27
- package/dist/server/storage.d.ts +0 -80
- package/dist/server.js +0 -281
- package/dist/shared/types.d.ts +0 -50
- package/dist/shared/types.js +0 -6
- package/dist/shared.js +0 -6
- package/src/client/persistence/adapters/index.ts +0 -8
- package/src/client/persistence/adapters/opsqlite.ts +0 -54
- package/src/client/persistence/adapters/sqljs.ts +0 -128
- package/src/client/persistence/sqlite-browser.ts +0 -107
- package/src/client/persistence/sqlite-level.ts +0 -407
- package/src/client/persistence/sqlite-rn.ts +0 -44
- package/src/client/persistence/sqlite.ts +0 -160
- package/src/client/services/checkpoint.ts +0 -86
- package/src/client/services/reconciliation.ts +0 -108
package/dist/client/errors.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
declare const NetworkError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
2
|
-
readonly _tag: "NetworkError";
|
|
3
|
-
} & Readonly<A>;
|
|
4
|
-
export declare class NetworkError extends NetworkError_base<{
|
|
5
|
-
readonly cause: unknown;
|
|
6
|
-
readonly retryable: true;
|
|
7
|
-
readonly operation: string;
|
|
8
|
-
}> {
|
|
9
|
-
}
|
|
10
|
-
declare const IDBError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
11
|
-
readonly _tag: "IDBError";
|
|
12
|
-
} & Readonly<A>;
|
|
13
|
-
export declare class IDBError extends IDBError_base<{
|
|
14
|
-
readonly operation: 'get' | 'set' | 'delete' | 'clear';
|
|
15
|
-
readonly store?: string;
|
|
16
|
-
readonly key?: string;
|
|
17
|
-
readonly cause: unknown;
|
|
18
|
-
}> {
|
|
19
|
-
}
|
|
20
|
-
declare const IDBWriteError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
21
|
-
readonly _tag: "IDBWriteError";
|
|
22
|
-
} & Readonly<A>;
|
|
23
|
-
export declare class IDBWriteError extends IDBWriteError_base<{
|
|
24
|
-
readonly key: string;
|
|
25
|
-
readonly value: unknown;
|
|
26
|
-
readonly cause: unknown;
|
|
27
|
-
}> {
|
|
28
|
-
}
|
|
29
|
-
declare const ReconciliationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
30
|
-
readonly _tag: "ReconciliationError";
|
|
31
|
-
} & Readonly<A>;
|
|
32
|
-
export declare class ReconciliationError extends ReconciliationError_base<{
|
|
33
|
-
readonly collection: string;
|
|
34
|
-
readonly reason: string;
|
|
35
|
-
readonly cause?: unknown;
|
|
36
|
-
}> {
|
|
37
|
-
}
|
|
38
|
-
declare const ProseError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
39
|
-
readonly _tag: "ProseError";
|
|
40
|
-
} & Readonly<A>;
|
|
41
|
-
export declare class ProseError extends ProseError_base<{
|
|
42
|
-
readonly documentId: string;
|
|
43
|
-
readonly field: string;
|
|
44
|
-
readonly collection: string;
|
|
45
|
-
}> {
|
|
46
|
-
}
|
|
47
|
-
declare const CollectionNotReadyError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
48
|
-
readonly _tag: "CollectionNotReadyError";
|
|
49
|
-
} & Readonly<A>;
|
|
50
|
-
export declare class CollectionNotReadyError extends CollectionNotReadyError_base<{
|
|
51
|
-
readonly collection: string;
|
|
52
|
-
readonly reason: string;
|
|
53
|
-
}> {
|
|
54
|
-
}
|
|
55
|
-
/** Error that should not be retried (auth failures, validation errors) */
|
|
56
|
-
export declare class NonRetriableError extends Error {
|
|
57
|
-
constructor(message: string);
|
|
58
|
-
}
|
|
59
|
-
export {};
|
package/dist/client/logger.d.ts
DELETED
package/dist/client/merge.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Merge Helpers - Plain functions for Yjs CRDT operations
|
|
3
|
-
*
|
|
4
|
-
* Provides document creation, state encoding, and merge operations.
|
|
5
|
-
*/
|
|
6
|
-
import * as Y from 'yjs';
|
|
7
|
-
import type { KeyValueStore } from '$/client/persistence/types.js';
|
|
8
|
-
/**
|
|
9
|
-
* Create a Yjs document with a persistent clientId.
|
|
10
|
-
* The clientId ensures consistent identity across sessions for CRDT merging.
|
|
11
|
-
*
|
|
12
|
-
* @param collection - The collection name
|
|
13
|
-
* @param kv - Key-value store for persisting the clientId
|
|
14
|
-
*/
|
|
15
|
-
export declare function createYjsDocument(collection: string, kv: KeyValueStore): Promise<Y.Doc>;
|
|
16
|
-
/**
|
|
17
|
-
* Apply a binary update to a Yjs document.
|
|
18
|
-
* Y.applyUpdateV2 is already atomic, no need for transaction wrapper.
|
|
19
|
-
*/
|
|
20
|
-
export declare function applyUpdate(doc: Y.Doc, update: Uint8Array, origin?: string): void;
|
|
21
|
-
/**
|
|
22
|
-
* Get a Y.Map from a Yjs document by name.
|
|
23
|
-
*/
|
|
24
|
-
export declare function getYMap<T = unknown>(doc: Y.Doc, name: string): Y.Map<T>;
|
|
25
|
-
/**
|
|
26
|
-
* Execute a function within a Yjs transaction.
|
|
27
|
-
*/
|
|
28
|
-
export declare function yjsTransact<A>(doc: Y.Doc, fn: () => A, origin?: string): A;
|
|
29
|
-
/**
|
|
30
|
-
* Execute a function within a Yjs transaction and capture the delta.
|
|
31
|
-
* Returns both the function result and a delta containing only the changes made.
|
|
32
|
-
*/
|
|
33
|
-
export declare function transactWithDelta<A>(doc: Y.Doc, fn: () => A, origin?: string): {
|
|
34
|
-
result: A;
|
|
35
|
-
delta: Uint8Array;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Serialize a Y.Map to a plain object.
|
|
39
|
-
*/
|
|
40
|
-
export declare function serializeYMap(ymap: Y.Map<unknown>): Record<string, unknown>;
|
|
41
|
-
/**
|
|
42
|
-
* Extract all items from a Y.Map as plain objects.
|
|
43
|
-
*/
|
|
44
|
-
export declare function extractItems<T>(ymap: Y.Map<unknown>): T[];
|
|
45
|
-
/**
|
|
46
|
-
* Extract a single item from a Y.Map by key.
|
|
47
|
-
*/
|
|
48
|
-
export declare function extractItem<T>(ymap: Y.Map<unknown>, key: string): T | null;
|
|
49
|
-
import type { XmlFragmentJSON } from '$/shared/types.js';
|
|
50
|
-
/**
|
|
51
|
-
* Check if a value looks like ProseMirror/BlockNote JSON document.
|
|
52
|
-
* Used internally to auto-detect prose fields during insert/update.
|
|
53
|
-
*/
|
|
54
|
-
export declare function isDoc(value: unknown): value is XmlFragmentJSON;
|
|
55
|
-
/**
|
|
56
|
-
* Convert a Y.XmlFragment to ProseMirror-compatible JSON.
|
|
57
|
-
*/
|
|
58
|
-
export declare function fragmentToJSON(fragment: Y.XmlFragment): XmlFragmentJSON;
|
|
59
|
-
/**
|
|
60
|
-
* Initialize a Y.XmlFragment from ProseMirror-compatible JSON.
|
|
61
|
-
*/
|
|
62
|
-
export declare function fragmentFromJSON(fragment: Y.XmlFragment, json: XmlFragmentJSON): void;
|
|
63
|
-
/**
|
|
64
|
-
* Extract plain text from ProseMirror/BlockNote JSON content.
|
|
65
|
-
* Handles various content structures defensively for search and display.
|
|
66
|
-
*/
|
|
67
|
-
export declare function extract(content: unknown): string;
|
|
68
|
-
/**
|
|
69
|
-
* Serialize any value, handling Yjs types specially.
|
|
70
|
-
* Uses our custom serialization system that works across module instances.
|
|
71
|
-
*/
|
|
72
|
-
export declare function serializeYMapValue(value: unknown): unknown;
|
|
73
|
-
/**
|
|
74
|
-
* Get a Y.XmlFragment from a document's field.
|
|
75
|
-
* Returns null if the document or field doesn't exist, or if the field is not an XmlFragment.
|
|
76
|
-
*/
|
|
77
|
-
export declare function getFragmentFromYMap(ymap: Y.Map<unknown>, documentId: string, field: string): Y.XmlFragment | null;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite adapter wrappers for different platforms.
|
|
3
|
-
*
|
|
4
|
-
* These are wrapper classes - the consuming app imports and initializes
|
|
5
|
-
* the actual database packages, then passes them to these wrappers.
|
|
6
|
-
*/
|
|
7
|
-
export { SqlJsAdapter, type SqlJsDatabase, type SqlJsAdapterOptions } from './sqljs.js';
|
|
8
|
-
export { OPSqliteAdapter, type OPSQLiteDatabase } from './opsqlite.js';
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* op-sqlite adapter wrapper for React Native SQLite.
|
|
3
|
-
*
|
|
4
|
-
* The consuming app imports @op-engineering/op-sqlite and opens the database,
|
|
5
|
-
* then passes it to this wrapper.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { open } from '@op-engineering/op-sqlite';
|
|
10
|
-
* import { OPSqliteAdapter } from '@trestleinc/replicate/client';
|
|
11
|
-
*
|
|
12
|
-
* const db = open({ name: 'myapp.db' });
|
|
13
|
-
* const adapter = new OPSqliteAdapter(db);
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
import type { SqliteAdapter } from '../sqlite-level.js';
|
|
17
|
-
/**
|
|
18
|
-
* Interface for op-sqlite Database.
|
|
19
|
-
* Consumer must install @op-engineering/op-sqlite and pass a Database instance.
|
|
20
|
-
*/
|
|
21
|
-
export interface OPSQLiteDatabase {
|
|
22
|
-
execute(sql: string, params?: unknown[]): Promise<{
|
|
23
|
-
rows: Record<string, unknown>[];
|
|
24
|
-
}>;
|
|
25
|
-
close(): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Wraps an op-sqlite Database as a SqliteAdapter.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* import { open } from '@op-engineering/op-sqlite';
|
|
33
|
-
* import { OPSqliteAdapter } from '@trestleinc/replicate/client';
|
|
34
|
-
*
|
|
35
|
-
* const db = open({ name: 'myapp.db' });
|
|
36
|
-
* const adapter = new OPSqliteAdapter(db);
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare class OPSqliteAdapter implements SqliteAdapter {
|
|
40
|
-
private db;
|
|
41
|
-
constructor(db: OPSQLiteDatabase);
|
|
42
|
-
execute(sql: string, params?: unknown[]): Promise<{
|
|
43
|
-
rows: Record<string, unknown>[];
|
|
44
|
-
}>;
|
|
45
|
-
close(): void;
|
|
46
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* sql.js adapter wrapper for browser SQLite.
|
|
3
|
-
*
|
|
4
|
-
* The consuming app imports sql.js and creates the database,
|
|
5
|
-
* then passes it to this wrapper.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import initSqlJs from 'sql.js';
|
|
10
|
-
* import { SqlJsAdapter } from '@trestleinc/replicate/client';
|
|
11
|
-
*
|
|
12
|
-
* const SQL = await initSqlJs({ locateFile: f => `/wasm/${f}` });
|
|
13
|
-
* const db = new SQL.Database();
|
|
14
|
-
* const adapter = new SqlJsAdapter(db, {
|
|
15
|
-
* onPersist: async (data) => {
|
|
16
|
-
* // Persist to OPFS, localStorage, etc.
|
|
17
|
-
* }
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
import type { SqliteAdapter } from '../sqlite-level.js';
|
|
22
|
-
/**
|
|
23
|
-
* Interface for sql.js Database.
|
|
24
|
-
* Consumer must install sql.js and pass a Database instance.
|
|
25
|
-
*/
|
|
26
|
-
export interface SqlJsDatabase {
|
|
27
|
-
run(sql: string, params?: unknown[]): void;
|
|
28
|
-
prepare(sql: string): {
|
|
29
|
-
bind(params?: unknown[]): void;
|
|
30
|
-
step(): boolean;
|
|
31
|
-
getAsObject(): Record<string, unknown>;
|
|
32
|
-
free(): void;
|
|
33
|
-
};
|
|
34
|
-
export(): Uint8Array;
|
|
35
|
-
close(): void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Options for the SqlJsAdapter.
|
|
39
|
-
*/
|
|
40
|
-
export interface SqlJsAdapterOptions {
|
|
41
|
-
/**
|
|
42
|
-
* Callback to persist database after write operations.
|
|
43
|
-
* Called with the exported database bytes.
|
|
44
|
-
*
|
|
45
|
-
* @example OPFS persistence
|
|
46
|
-
* ```typescript
|
|
47
|
-
* onPersist: async (data) => {
|
|
48
|
-
* const root = await navigator.storage.getDirectory();
|
|
49
|
-
* const handle = await root.getFileHandle('myapp.sqlite', { create: true });
|
|
50
|
-
* const writable = await handle.createWritable();
|
|
51
|
-
* await writable.write(data.buffer);
|
|
52
|
-
* await writable.close();
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
onPersist?: (data: Uint8Array) => Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Wraps a sql.js Database as a SqliteAdapter.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* import initSqlJs from 'sql.js';
|
|
64
|
-
* import { SqlJsAdapter } from '@trestleinc/replicate/client';
|
|
65
|
-
*
|
|
66
|
-
* const SQL = await initSqlJs();
|
|
67
|
-
* const db = new SQL.Database();
|
|
68
|
-
* const adapter = new SqlJsAdapter(db);
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export declare class SqlJsAdapter implements SqliteAdapter {
|
|
72
|
-
private db;
|
|
73
|
-
private onPersist?;
|
|
74
|
-
constructor(db: SqlJsDatabase, options?: SqlJsAdapterOptions);
|
|
75
|
-
execute(sql: string, params?: unknown[]): Promise<{
|
|
76
|
-
rows: Record<string, unknown>[];
|
|
77
|
-
}>;
|
|
78
|
-
close(): void;
|
|
79
|
-
/**
|
|
80
|
-
* Persist database using the onPersist callback if provided.
|
|
81
|
-
*/
|
|
82
|
-
private persist;
|
|
83
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Persistence layer exports.
|
|
3
|
-
*
|
|
4
|
-
* Provides swappable storage backends for Y.Doc and key-value data.
|
|
5
|
-
*/
|
|
6
|
-
export type { Persistence, PersistenceProvider, KeyValueStore } from './types.js';
|
|
7
|
-
export type { SqlitePersistenceOptions } from './sqlite.js';
|
|
8
|
-
export type { SqlJsStatic } from './sqlite-browser.js';
|
|
9
|
-
export type { SqliteAdapter } from './sqlite-level.js';
|
|
10
|
-
import { indexeddbPersistence } from './indexeddb.js';
|
|
11
|
-
import { memoryPersistence } from './memory.js';
|
|
12
|
-
import { sqlitePersistence } from './sqlite.js';
|
|
13
|
-
import { createBrowserSqlitePersistence } from './sqlite-browser.js';
|
|
14
|
-
import { createReactNativeSqlitePersistence } from './sqlite-rn.js';
|
|
15
|
-
/**
|
|
16
|
-
* Persistence API - nested object pattern for ergonomic access.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { persistence } from '@trestleinc/replicate/client';
|
|
21
|
-
*
|
|
22
|
-
* // Browser SQLite (recommended for web)
|
|
23
|
-
* const p = await persistence.sqlite.browser(SQL, 'myapp');
|
|
24
|
-
*
|
|
25
|
-
* // React Native SQLite
|
|
26
|
-
* const p = await persistence.sqlite.native(db, 'myapp');
|
|
27
|
-
*
|
|
28
|
-
* // IndexedDB fallback
|
|
29
|
-
* const p = persistence.indexeddb('myapp');
|
|
30
|
-
*
|
|
31
|
-
* // In-memory (testing)
|
|
32
|
-
* const p = persistence.memory();
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare const persistence: {
|
|
36
|
-
/** IndexedDB-backed persistence (browser) */
|
|
37
|
-
readonly indexeddb: typeof indexeddbPersistence;
|
|
38
|
-
/** In-memory persistence (testing/ephemeral) */
|
|
39
|
-
readonly memory: typeof memoryPersistence;
|
|
40
|
-
/** SQLite persistence variants */
|
|
41
|
-
readonly sqlite: {
|
|
42
|
-
/** Browser SQLite with OPFS (sql.js) */
|
|
43
|
-
readonly browser: typeof createBrowserSqlitePersistence;
|
|
44
|
-
/** React Native SQLite (op-sqlite) */
|
|
45
|
-
readonly native: typeof createReactNativeSqlitePersistence;
|
|
46
|
-
/** Custom SQLite adapter */
|
|
47
|
-
readonly create: typeof sqlitePersistence;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Persistence } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Create an IndexedDB persistence factory.
|
|
4
|
-
*
|
|
5
|
-
* Uses y-indexeddb for Y.Doc persistence and browser-level for metadata storage.
|
|
6
|
-
*
|
|
7
|
-
* @param dbName - Name for the LevelDB database (default: 'replicate-kv')
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* convexCollectionOptions<Task>({
|
|
12
|
-
* // ... other options
|
|
13
|
-
* persistence: indexeddbPersistence(),
|
|
14
|
-
* });
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function indexeddbPersistence(dbName?: string): Persistence;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Persistence } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Create an in-memory persistence factory.
|
|
4
|
-
*
|
|
5
|
-
* Useful for testing where you don't want IndexedDB side effects.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // In tests
|
|
10
|
-
* convexCollectionOptions<Task>({
|
|
11
|
-
* // ... other options
|
|
12
|
-
* persistence: memoryPersistence(),
|
|
13
|
-
* });
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export declare function memoryPersistence(): Persistence;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Browser SQLite persistence helper using sql.js and OPFS.
|
|
3
|
-
*
|
|
4
|
-
* Handles all the boilerplate for browser SQLite:
|
|
5
|
-
* - Loading existing database from OPFS
|
|
6
|
-
* - Persisting to OPFS on every write
|
|
7
|
-
* - Creating the SqlJsAdapter
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { createBrowserSqlitePersistence } from '@trestleinc/replicate/client';
|
|
12
|
-
* import initSqlJs from 'sql.js';
|
|
13
|
-
*
|
|
14
|
-
* const SQL = await initSqlJs({ locateFile: f => `https://sql.js.org/dist/${f}` });
|
|
15
|
-
* const persistence = await createBrowserSqlitePersistence(SQL, 'myapp');
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
import { type SqlJsDatabase } from './adapters/sqljs.js';
|
|
19
|
-
import type { Persistence } from './types.js';
|
|
20
|
-
/**
|
|
21
|
-
* Interface for the sql.js module (the result of initSqlJs).
|
|
22
|
-
*/
|
|
23
|
-
export interface SqlJsStatic {
|
|
24
|
-
Database: new (data?: ArrayLike<number>) => SqlJsDatabase;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create browser SQLite persistence with OPFS storage.
|
|
28
|
-
*
|
|
29
|
-
* This helper handles all the OPFS boilerplate:
|
|
30
|
-
* - Loads existing database from OPFS on init
|
|
31
|
-
* - Persists to OPFS after every write operation
|
|
32
|
-
*
|
|
33
|
-
* @param SQL - The initialized sql.js module (from `await initSqlJs()`)
|
|
34
|
-
* @param dbName - Name for the database (used for OPFS filename: `{dbName}.sqlite`)
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* import { createBrowserSqlitePersistence } from '@trestleinc/replicate/client';
|
|
39
|
-
* import initSqlJs from 'sql.js';
|
|
40
|
-
*
|
|
41
|
-
* const SQL = await initSqlJs({ locateFile: f => `https://sql.js.org/dist/${f}` });
|
|
42
|
-
* const persistence = await createBrowserSqlitePersistence(SQL, 'intervals');
|
|
43
|
-
*
|
|
44
|
-
* // Use in collection options
|
|
45
|
-
* convexCollectionOptions<Task>({
|
|
46
|
-
* // ...
|
|
47
|
-
* persistence,
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare function createBrowserSqlitePersistence(SQL: SqlJsStatic, dbName: string): Promise<Persistence>;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite-backed abstract-level implementation.
|
|
3
|
-
*
|
|
4
|
-
* Provides a LevelDB-compatible key-value store backed by SQLite,
|
|
5
|
-
* enabling y-leveldb to work with SQLite databases.
|
|
6
|
-
*
|
|
7
|
-
* Supports both browser (sql.js WASM) and React Native (op-sqlite).
|
|
8
|
-
*/
|
|
9
|
-
import { AbstractLevel, AbstractIterator, AbstractKeyIterator, AbstractValueIterator } from 'abstract-level';
|
|
10
|
-
/**
|
|
11
|
-
* Interface for SQLite database operations.
|
|
12
|
-
* Abstracts over sql.js (browser) and op-sqlite (React Native).
|
|
13
|
-
*/
|
|
14
|
-
export interface SqliteAdapter {
|
|
15
|
-
execute(sql: string, params?: unknown[]): Promise<{
|
|
16
|
-
rows: Record<string, unknown>[];
|
|
17
|
-
}>;
|
|
18
|
-
close(): void;
|
|
19
|
-
}
|
|
20
|
-
interface SqliteLevelOptions {
|
|
21
|
-
/** Custom SQLite adapter (for testing or alternative backends) */
|
|
22
|
-
adapter?: SqliteAdapter;
|
|
23
|
-
/** Value encoding (default: 'utf8') */
|
|
24
|
-
valueEncoding?: string;
|
|
25
|
-
keyEncoding?: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* SQLite-backed implementation of abstract-level.
|
|
29
|
-
*
|
|
30
|
-
* Uses a simple key-value table with lexicographic ordering:
|
|
31
|
-
* CREATE TABLE entries (key BLOB PRIMARY KEY, value BLOB)
|
|
32
|
-
*/
|
|
33
|
-
export declare class SqliteLevel<K = string, V = string> extends AbstractLevel<K, V> {
|
|
34
|
-
private adapter;
|
|
35
|
-
private adapterFactory;
|
|
36
|
-
constructor(_location: string, options?: SqliteLevelOptions);
|
|
37
|
-
/**
|
|
38
|
-
* Set the adapter factory for deferred initialization.
|
|
39
|
-
* Call this before open() to configure the SQLite backend.
|
|
40
|
-
*/
|
|
41
|
-
setAdapterFactory(factory: () => Promise<SqliteAdapter>): void;
|
|
42
|
-
_open(): Promise<void>;
|
|
43
|
-
_close(): Promise<void>;
|
|
44
|
-
_get(key: K): Promise<V | undefined>;
|
|
45
|
-
_put(key: K, value: V): Promise<void>;
|
|
46
|
-
_del(key: K): Promise<void>;
|
|
47
|
-
_batch(operations: Array<{
|
|
48
|
-
type: 'put';
|
|
49
|
-
key: K;
|
|
50
|
-
value: V;
|
|
51
|
-
} | {
|
|
52
|
-
type: 'del';
|
|
53
|
-
key: K;
|
|
54
|
-
}>): Promise<void>;
|
|
55
|
-
_clear(): Promise<void>;
|
|
56
|
-
_iterator(options: Record<string, unknown>): AbstractIterator<typeof this, K, V>;
|
|
57
|
-
_keys(options: Record<string, unknown>): AbstractKeyIterator<typeof this, K>;
|
|
58
|
-
_values(options: Record<string, unknown>): AbstractValueIterator<typeof this, K, V>;
|
|
59
|
-
private encodeKey;
|
|
60
|
-
private encodeValue;
|
|
61
|
-
private decodeValue;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React Native SQLite persistence helper using op-sqlite.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```typescript
|
|
6
|
-
* import { createReactNativeSqlitePersistence } from '@trestleinc/replicate/client';
|
|
7
|
-
* import { open } from '@op-engineering/op-sqlite';
|
|
8
|
-
*
|
|
9
|
-
* const db = open({ name: 'myapp.db' });
|
|
10
|
-
* const persistence = await createReactNativeSqlitePersistence(db, 'myapp');
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
import { type OPSQLiteDatabase } from './adapters/opsqlite.js';
|
|
14
|
-
import type { Persistence } from './types.js';
|
|
15
|
-
/**
|
|
16
|
-
* Create React Native SQLite persistence using op-sqlite.
|
|
17
|
-
*
|
|
18
|
-
* @param db - The opened op-sqlite database instance
|
|
19
|
-
* @param dbName - Name for internal database identification
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* import { createReactNativeSqlitePersistence } from '@trestleinc/replicate/client';
|
|
24
|
-
* import { open } from '@op-engineering/op-sqlite';
|
|
25
|
-
*
|
|
26
|
-
* const db = open({ name: 'myapp.db' });
|
|
27
|
-
* const persistence = await createReactNativeSqlitePersistence(db, 'myapp');
|
|
28
|
-
*
|
|
29
|
-
* // Use in collection options
|
|
30
|
-
* convexCollectionOptions<Task>({
|
|
31
|
-
* // ...
|
|
32
|
-
* persistence,
|
|
33
|
-
* });
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function createReactNativeSqlitePersistence(db: OPSQLiteDatabase, dbName: string): Promise<Persistence>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type SqliteAdapter } from './sqlite-level.js';
|
|
2
|
-
import type { Persistence } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Options for SQLite persistence.
|
|
5
|
-
*/
|
|
6
|
-
export interface SqlitePersistenceOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Pre-created SQLite adapter (required).
|
|
9
|
-
* Use SqlJsAdapter for browser or OPSqliteAdapter for React Native.
|
|
10
|
-
*/
|
|
11
|
-
adapter: SqliteAdapter;
|
|
12
|
-
/**
|
|
13
|
-
* Database name for internal y-leveldb usage.
|
|
14
|
-
* @default 'replicate'
|
|
15
|
-
*/
|
|
16
|
-
dbName?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a universal SQLite persistence factory.
|
|
20
|
-
*
|
|
21
|
-
* Requires a pre-created SqliteAdapter - the replicate package does not
|
|
22
|
-
* import any SQLite packages directly, making it environment-agnostic.
|
|
23
|
-
*
|
|
24
|
-
* @param options - Configuration with required adapter
|
|
25
|
-
*
|
|
26
|
-
* @example Browser (sql.js)
|
|
27
|
-
* ```typescript
|
|
28
|
-
* import initSqlJs from 'sql.js';
|
|
29
|
-
* import { sqlitePersistence, SqlJsAdapter } from '@trestleinc/replicate/client';
|
|
30
|
-
*
|
|
31
|
-
* const SQL = await initSqlJs();
|
|
32
|
-
* const db = new SQL.Database();
|
|
33
|
-
* const adapter = new SqlJsAdapter(db);
|
|
34
|
-
* const persistence = await sqlitePersistence({ adapter });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example React Native (op-sqlite)
|
|
38
|
-
* ```typescript
|
|
39
|
-
* import { open } from '@op-engineering/op-sqlite';
|
|
40
|
-
* import { sqlitePersistence, OPSqliteAdapter } from '@trestleinc/replicate/client';
|
|
41
|
-
*
|
|
42
|
-
* const db = open({ name: 'myapp.db' });
|
|
43
|
-
* const adapter = new OPSqliteAdapter(db);
|
|
44
|
-
* const persistence = await sqlitePersistence({ adapter });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function sqlitePersistence(options: SqlitePersistenceOptions): Promise<Persistence>;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Persistence layer types for swappable storage backends.
|
|
3
|
-
*
|
|
4
|
-
* Supports IndexedDB (browser), SQLite (React Native), and in-memory (testing).
|
|
5
|
-
*/
|
|
6
|
-
import type * as Y from 'yjs';
|
|
7
|
-
/**
|
|
8
|
-
* Provider that persists Y.Doc state to storage.
|
|
9
|
-
*
|
|
10
|
-
* This wraps providers like y-indexeddb or y-op-sqlite, normalizing their APIs.
|
|
11
|
-
*/
|
|
12
|
-
export interface PersistenceProvider {
|
|
13
|
-
/** Promise that resolves when initial sync from storage completes */
|
|
14
|
-
readonly whenSynced: Promise<void>;
|
|
15
|
-
/** Clean up resources (stop observing, close connections) */
|
|
16
|
-
destroy(): void;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Factory that creates persistence providers.
|
|
20
|
-
*
|
|
21
|
-
* Each persistence implementation (IndexedDB, SQLite, memory) exports a
|
|
22
|
-
* factory function that returns this interface.
|
|
23
|
-
*/
|
|
24
|
-
export interface Persistence {
|
|
25
|
-
/** Create a Y.Doc persistence provider for a collection */
|
|
26
|
-
createDocPersistence(collection: string, ydoc: Y.Doc): PersistenceProvider;
|
|
27
|
-
/** Key-value store for metadata (checkpoints, clientID) */
|
|
28
|
-
readonly kv: KeyValueStore;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Simple key-value storage interface.
|
|
32
|
-
*
|
|
33
|
-
* Used for storing metadata like checkpoints and Yjs client IDs.
|
|
34
|
-
*/
|
|
35
|
-
export interface KeyValueStore {
|
|
36
|
-
/** Get a value by key */
|
|
37
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
38
|
-
/** Set a value by key */
|
|
39
|
-
set<T>(key: string, value: T): Promise<void>;
|
|
40
|
-
/** Delete a value by key */
|
|
41
|
-
del(key: string): Promise<void>;
|
|
42
|
-
}
|
package/dist/client/prose.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prose Field Helpers - Document-level state management for rich text sync
|
|
3
|
-
*
|
|
4
|
-
* Manages Y.XmlFragment observation, debounced sync, and pending state.
|
|
5
|
-
* Uses document-level tracking to prevent race conditions.
|
|
6
|
-
*/
|
|
7
|
-
import * as Y from 'yjs';
|
|
8
|
-
import type { Collection } from '@tanstack/db';
|
|
9
|
-
/**
|
|
10
|
-
* Check if a document is currently applying server data.
|
|
11
|
-
* Used to prevent echo loops in onUpdate handlers.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isApplyingFromServer(collection: string, documentId: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Set whether a document is currently applying server data.
|
|
16
|
-
*/
|
|
17
|
-
export declare function setApplyingFromServer(collection: string, documentId: string, value: boolean): void;
|
|
18
|
-
/**
|
|
19
|
-
* Get current pending state for a document.
|
|
20
|
-
*/
|
|
21
|
-
export declare function isPending(collection: string, documentId: string): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Subscribe to pending state changes for a document.
|
|
24
|
-
*/
|
|
25
|
-
export declare function subscribePending(collection: string, documentId: string, callback: (pending: boolean) => void): () => void;
|
|
26
|
-
/**
|
|
27
|
-
* Cancel any pending debounced sync for a document.
|
|
28
|
-
* Called when receiving remote updates to avoid conflicts.
|
|
29
|
-
*/
|
|
30
|
-
export declare function cancelPending(collection: string, documentId: string): void;
|
|
31
|
-
/**
|
|
32
|
-
* Cancel all pending syncs for a collection.
|
|
33
|
-
* Called when receiving a snapshot that replaces all state.
|
|
34
|
-
*/
|
|
35
|
-
export declare function cancelAllPending(collection: string): void;
|
|
36
|
-
/** Configuration for fragment observation */
|
|
37
|
-
export interface ProseObserverConfig {
|
|
38
|
-
collection: string;
|
|
39
|
-
documentId: string;
|
|
40
|
-
field: string;
|
|
41
|
-
fragment: Y.XmlFragment;
|
|
42
|
-
ydoc: Y.Doc;
|
|
43
|
-
ymap: Y.Map<unknown>;
|
|
44
|
-
collectionRef: Collection<any>;
|
|
45
|
-
debounceMs?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Set up observation for a prose field's Y.XmlFragment.
|
|
49
|
-
* Returns a cleanup function.
|
|
50
|
-
*/
|
|
51
|
-
export declare function observeFragment(config: ProseObserverConfig): () => void;
|
|
52
|
-
/**
|
|
53
|
-
* Clean up all prose state for a collection.
|
|
54
|
-
* Called when collection is destroyed.
|
|
55
|
-
*/
|
|
56
|
-
export declare function cleanup(collection: string): void;
|