@trestleinc/replicate 1.2.0-preview.2 → 2.0.0-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/dist/client/index.d.ts +683 -170
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1993 -3139
- package/dist/client/index.js.map +1 -0
- package/dist/client/persistence/sqlite/worker.js +138 -0
- package/dist/component/_generated/api.d.ts +4 -3
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +2 -1
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +76 -19
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +2 -1
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/server.d.ts +2 -1
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +2 -1
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +2 -1
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +2 -1
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/encryption.d.ts +93 -0
- package/dist/component/encryption.d.ts.map +1 -0
- package/dist/component/encryption.js +138 -0
- package/dist/component/encryption.js.map +1 -0
- package/dist/component/mutations.d.ts +65 -42
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +325 -171
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/schema.d.ts +96 -8
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +62 -13
- package/dist/component/schema.js.map +1 -0
- package/dist/component/shared/index.d.ts +13 -0
- package/dist/component/shared/index.d.ts.map +1 -0
- package/dist/component/shared/index.js +154 -0
- package/dist/component/shared/index.js.map +1 -0
- package/dist/component/shared/logger.d.ts +1 -0
- package/dist/component/shared/logger.js +11 -0
- package/dist/component/shared/logger.js.map +1 -0
- package/dist/component/test.setup.d.ts +5 -0
- package/dist/component/test.setup.d.ts.map +1 -0
- package/dist/component/test.setup.js +6 -0
- package/dist/component/test.setup.js.map +1 -0
- package/dist/server/index.d.ts +292 -58
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +631 -270
- package/dist/server/index.js.map +1 -0
- package/dist/shared/index.d.ts +332 -13
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +172 -1
- package/dist/shared/index.js.map +1 -0
- package/package.json +114 -123
- package/src/client/collection.ts +1194 -779
- package/src/client/deltas.ts +52 -0
- package/src/client/documents.ts +204 -0
- package/src/client/errors.ts +97 -41
- package/src/client/identity.ts +89 -0
- package/src/client/index.ts +82 -23
- package/src/client/merge.ts +192 -225
- package/src/client/migration.ts +444 -0
- package/src/client/ops.ts +40 -40
- package/src/client/persistence/custom.ts +86 -66
- package/src/client/persistence/encrypted/crypto.ts +77 -0
- package/src/client/persistence/encrypted/index.ts +20 -0
- package/src/client/persistence/encrypted/keys.ts +127 -0
- package/src/client/persistence/encrypted/manager.ts +219 -0
- package/src/client/persistence/encrypted/types.ts +56 -0
- package/src/client/persistence/encrypted/web.ts +319 -0
- package/src/client/persistence/encrypted/webauthn.ts +187 -0
- package/src/client/persistence/index.ts +51 -7
- package/src/client/persistence/memory.ts +22 -19
- package/src/client/persistence/sqlite/native.ts +15 -15
- package/src/client/persistence/sqlite/schema.ts +150 -87
- package/src/client/persistence/sqlite/web.ts +125 -0
- package/src/client/persistence/sqlite/worker.ts +118 -0
- package/src/client/persistence/types.ts +29 -14
- package/src/client/prose.ts +104 -276
- package/src/client/services/context.ts +76 -81
- package/src/client/services/presence.ts +581 -0
- package/src/client/services/seq.ts +21 -70
- package/src/client/services/session.ts +24 -14
- package/src/client/services/sync.ts +158 -112
- package/src/client/types.ts +19 -0
- package/src/client/validators.ts +45 -0
- package/src/component/_generated/api.ts +7 -14
- package/src/component/_generated/component.ts +236 -127
- package/src/component/_generated/dataModel.ts +6 -10
- package/src/component/_generated/server.ts +19 -27
- package/src/component/encryption.ts +202 -0
- package/src/component/mutations.ts +931 -680
- package/src/component/schema.ts +95 -44
- package/src/component/test.setup.ts +6 -0
- package/src/env.d.ts +12 -12
- package/src/server/collection.ts +58 -83
- package/src/server/index.ts +721 -2
- package/src/server/migration.ts +364 -0
- package/src/server/schema.ts +11 -15
- package/src/shared/index.ts +323 -5
- package/src/shared/logger.ts +9 -0
- package/src/test/component.test.ts +200 -0
- package/src/test/e2e/compaction.test.ts +195 -0
- package/src/test/helpers/convex.ts +24 -0
- package/src/test/helpers/persistence.ts +19 -0
- package/src/test/helpers/test-database.ts +308 -0
- package/src/test/helpers/yjs.ts +18 -0
- package/src/test/migration.test.ts +390 -0
- package/src/test/setup.ts +28 -0
- package/src/test/unit/actor.test.ts +84 -0
- package/src/test/unit/mutations.test.ts +140 -0
- package/src/test/unit/sync.test.ts +608 -0
- package/LICENSE +0 -201
- package/README.md +0 -992
- package/dist/component/logger.d.ts +0 -12
- package/dist/component/logger.js +0 -27
- package/dist/component/shared/types.d.ts +0 -9
- package/dist/component/shared/types.js +0 -15
- package/src/client/logger.ts +0 -5
- package/src/client/persistence/pglite.ts +0 -168
- package/src/client/services/awareness.ts +0 -398
- package/src/client/subdocs.ts +0 -263
- package/src/component/logger.ts +0 -36
- package/src/server/replicate.ts +0 -529
- package/src/shared/types.ts +0 -89
package/dist/client/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as Y from "yjs";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import * as convex_server0 from "convex/server";
|
|
3
|
+
import { DataModelFromSchemaDefinition, DocumentByName, FunctionReference, GenericDataModel, GenericMutationCtx, SchemaDefinition, TableNamesInDataModel, WithOptionalSystemFields } from "convex/server";
|
|
4
|
+
import { Collection, NonSingleResult } from "@tanstack/db";
|
|
5
|
+
import { Logger } from "@logtape/logtape";
|
|
5
6
|
import { Awareness } from "y-protocols/awareness";
|
|
7
|
+
import * as convex_browser0 from "convex/browser";
|
|
6
8
|
import { ConvexClient } from "convex/browser";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import * as effect_Cause0 from "effect/Cause";
|
|
10
|
-
import { z } from "zod";
|
|
9
|
+
import * as convex_values0 from "convex/values";
|
|
10
|
+
import { GenericValidator, Infer } from "convex/values";
|
|
11
11
|
|
|
12
12
|
//#region src/client/persistence/types.d.ts
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Low-level storage adapter for custom backends (Chrome extension, localStorage, cloud).
|
|
16
|
-
* For SQLite, use `persistence.sqlite()` directly.
|
|
16
|
+
* For SQLite, use `persistence.web.sqlite.create()` or `persistence.native.sqlite.create()` directly.
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
@@ -45,121 +45,381 @@ interface StorageAdapter {
|
|
|
45
45
|
interface PersistenceProvider {
|
|
46
46
|
readonly whenSynced: Promise<void>;
|
|
47
47
|
destroy(): void;
|
|
48
|
+
flush?(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* SQLite database interface for migrations.
|
|
52
|
+
* Provides direct SQL access for schema migrations.
|
|
53
|
+
*/
|
|
54
|
+
interface MigrationDatabase {
|
|
55
|
+
run(sql: string, params?: unknown[]): Promise<void>;
|
|
56
|
+
exec(sql: string): Promise<void>;
|
|
57
|
+
get<T$1>(sql: string, params?: unknown[]): Promise<T$1 | undefined>;
|
|
58
|
+
all<T$1>(sql: string, params?: unknown[]): Promise<T$1[]>;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* High-level persistence interface for collections.
|
|
51
|
-
* Create via `persistence.sqlite()`, `persistence.memory()`, or `persistence.custom()`.
|
|
62
|
+
* Create via `persistence.web.sqlite.create()`, `persistence.memory.create()`, or `persistence.custom.create()`.
|
|
52
63
|
*/
|
|
53
64
|
interface Persistence {
|
|
54
65
|
createDocPersistence(collection: string, ydoc: Y.Doc): PersistenceProvider;
|
|
66
|
+
listDocuments(prefix: string): Promise<string[]>;
|
|
55
67
|
readonly kv: KeyValueStore;
|
|
68
|
+
/** Direct SQL access for migrations (only available with SQLite persistence) */
|
|
69
|
+
readonly db?: MigrationDatabase;
|
|
56
70
|
}
|
|
57
71
|
interface KeyValueStore {
|
|
58
|
-
get<T>(key: string): Promise<T | undefined>;
|
|
59
|
-
set<T>(key: string, value: T): Promise<void>;
|
|
72
|
+
get<T$1>(key: string): Promise<T$1 | undefined>;
|
|
73
|
+
set<T$1>(key: string, value: T$1): Promise<void>;
|
|
60
74
|
del(key: string): Promise<void>;
|
|
61
75
|
}
|
|
62
76
|
//#endregion
|
|
63
|
-
//#region src/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
readonly
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
|
|
77
|
+
//#region src/server/migration.d.ts
|
|
78
|
+
/** Field type for schema operations */
|
|
79
|
+
type FieldType = "string" | "number" | "boolean" | "null" | "array" | "object" | "prose";
|
|
80
|
+
/** Individual diff operation detected between schema versions */
|
|
81
|
+
type SchemaDiffOperation = {
|
|
82
|
+
type: "add_column";
|
|
83
|
+
column: string;
|
|
84
|
+
fieldType: FieldType;
|
|
85
|
+
defaultValue: unknown;
|
|
86
|
+
} | {
|
|
87
|
+
type: "remove_column";
|
|
88
|
+
column: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "rename_column";
|
|
91
|
+
from: string;
|
|
92
|
+
to: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "change_type";
|
|
95
|
+
column: string;
|
|
96
|
+
from: FieldType;
|
|
97
|
+
to: FieldType;
|
|
98
|
+
};
|
|
99
|
+
/** Result of diffing two schema versions */
|
|
100
|
+
interface SchemaDiff {
|
|
101
|
+
fromVersion: number;
|
|
102
|
+
toVersion: number;
|
|
103
|
+
operations: SchemaDiffOperation[];
|
|
104
|
+
isBackwardsCompatible: boolean;
|
|
105
|
+
generatedSQL: string[];
|
|
106
|
+
}
|
|
107
|
+
/** Context passed to server migration functions */
|
|
108
|
+
interface MigrationContext<DataModel extends GenericDataModel = GenericDataModel> {
|
|
109
|
+
db: GenericMutationCtx<DataModel>["db"];
|
|
110
|
+
}
|
|
111
|
+
/** Single migration definition */
|
|
112
|
+
interface MigrationDefinition<T$1 = unknown> {
|
|
113
|
+
name: string;
|
|
114
|
+
batchSize?: number;
|
|
115
|
+
parallelize?: boolean;
|
|
116
|
+
migrate: (ctx: MigrationContext, doc: T$1) => Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
/** Map of version numbers to migration definitions */
|
|
119
|
+
type MigrationMap<T$1 = unknown> = Record<number, MigrationDefinition<T$1>>;
|
|
120
|
+
/** Versioned schema with migration capabilities */
|
|
121
|
+
interface VersionedSchema<TShape extends GenericValidator> {
|
|
122
|
+
/** Current schema version */
|
|
123
|
+
readonly version: number;
|
|
124
|
+
/** Convex validator for the document shape */
|
|
125
|
+
readonly shape: TShape;
|
|
126
|
+
/** Default values for optional fields */
|
|
127
|
+
readonly defaults: Partial<Infer<TShape>>;
|
|
128
|
+
/** Previous schema versions */
|
|
129
|
+
readonly history: Record<number, GenericValidator>;
|
|
130
|
+
/** Get validator for a specific version */
|
|
131
|
+
getVersion(version: number): GenericValidator;
|
|
132
|
+
/** Compute diff between two versions */
|
|
133
|
+
diff(fromVersion: number, toVersion: number): SchemaDiff;
|
|
134
|
+
/** Define server migrations for this schema */
|
|
135
|
+
migrations(definitions: MigrationMap<Infer<TShape>>): SchemaMigrations<TShape>;
|
|
136
|
+
}
|
|
137
|
+
/** Schema migrations wrapper */
|
|
138
|
+
interface SchemaMigrations<TShape extends GenericValidator> {
|
|
139
|
+
/** The versioned schema */
|
|
140
|
+
readonly schema: VersionedSchema<TShape>;
|
|
141
|
+
/** Migration definitions by version */
|
|
142
|
+
readonly definitions: MigrationMap<Infer<TShape>>;
|
|
115
143
|
}
|
|
116
144
|
//#endregion
|
|
117
|
-
//#region src/client/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
//#region src/client/identity.d.ts
|
|
146
|
+
/**
|
|
147
|
+
* User identity for presence and collaborative features.
|
|
148
|
+
*/
|
|
121
149
|
interface UserIdentity {
|
|
150
|
+
id?: string;
|
|
122
151
|
name?: string;
|
|
123
152
|
color?: string;
|
|
124
153
|
avatar?: string;
|
|
125
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Configuration for anonymous presence names and colors.
|
|
157
|
+
* Allows applications to customize the adjectives, nouns, and colors
|
|
158
|
+
* used when generating anonymous user identities.
|
|
159
|
+
*/
|
|
160
|
+
interface AnonymousPresenceConfig {
|
|
161
|
+
/** List of adjectives for anonymous names (e.g., ["Swift", "Bright", "Calm"]) */
|
|
162
|
+
adjectives?: string[];
|
|
163
|
+
/** List of nouns for anonymous names (e.g., ["Fox", "Owl", "Bear"]) */
|
|
164
|
+
nouns?: string[];
|
|
165
|
+
/** List of hex colors for anonymous users (e.g., ["#9F5944", "#A9704D"]) */
|
|
166
|
+
colors?: string[];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Identity namespace for creating user identities and generating stable anonymous identifiers.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { identity } from "@trestleinc/replicate/client";
|
|
174
|
+
*
|
|
175
|
+
* // Create from your auth provider
|
|
176
|
+
* const user = identity.from({
|
|
177
|
+
* id: authSession.user.id,
|
|
178
|
+
* name: authSession.user.name,
|
|
179
|
+
* avatar: authSession.user.image,
|
|
180
|
+
* color: identity.color.generate(authSession.user.id),
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* // Generate stable anonymous identifiers
|
|
184
|
+
* identity.color.generate("seed-123") // Deterministic color
|
|
185
|
+
* identity.name.anonymous("seed-123") // "Swift Fox", "Calm Bear", etc.
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare const identity: {
|
|
189
|
+
/**
|
|
190
|
+
* Create a user identity from auth provider data.
|
|
191
|
+
* Pass-through helper that ensures type safety.
|
|
192
|
+
*/
|
|
193
|
+
readonly from: (user: UserIdentity) => UserIdentity;
|
|
194
|
+
/**
|
|
195
|
+
* Color utilities for generating stable, deterministic colors.
|
|
196
|
+
*/
|
|
197
|
+
readonly color: {
|
|
198
|
+
/**
|
|
199
|
+
* Generate a deterministic color from any seed string.
|
|
200
|
+
* Same seed always produces the same color.
|
|
201
|
+
*
|
|
202
|
+
* @param seed - Any string (user ID, client ID, etc.)
|
|
203
|
+
* @param config - Optional custom colors configuration
|
|
204
|
+
* @returns Hex color string (e.g., "#9F5944")
|
|
205
|
+
*/
|
|
206
|
+
readonly generate: (seed: string, config?: AnonymousPresenceConfig) => string;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Name utilities for generating stable anonymous names.
|
|
210
|
+
*/
|
|
211
|
+
readonly name: {
|
|
212
|
+
/**
|
|
213
|
+
* Generate a stable anonymous name from any seed string.
|
|
214
|
+
* Same seed always produces the same name.
|
|
215
|
+
*
|
|
216
|
+
* @param seed - Any string (user ID, client ID, etc.)
|
|
217
|
+
* @param config - Optional custom adjectives/nouns configuration
|
|
218
|
+
* @returns Anonymous name (e.g., "Swift Fox", "Calm Bear")
|
|
219
|
+
*/
|
|
220
|
+
readonly anonymous: (seed: string, config?: AnonymousPresenceConfig) => string;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
126
223
|
//#endregion
|
|
127
|
-
//#region src/
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
224
|
+
//#region src/client/migration.d.ts
|
|
225
|
+
/** Error codes for migration failures */
|
|
226
|
+
type MigrationErrorCode = "SCHEMA_MISMATCH" | "SQLITE_ERROR" | "YJS_ERROR" | "NETWORK_ERROR";
|
|
227
|
+
/** Error details for migration failures */
|
|
228
|
+
interface MigrationError {
|
|
229
|
+
code: MigrationErrorCode;
|
|
230
|
+
message: string;
|
|
231
|
+
fromVersion: number;
|
|
232
|
+
toVersion: number;
|
|
233
|
+
operation?: SchemaDiffOperation;
|
|
234
|
+
}
|
|
235
|
+
/** Context for migration error recovery */
|
|
236
|
+
interface RecoveryContext {
|
|
237
|
+
error: MigrationError;
|
|
238
|
+
/** True if no unsynced local changes exist */
|
|
239
|
+
canResetSafely: boolean;
|
|
240
|
+
/** Count of unsynced local changes */
|
|
241
|
+
pendingChanges: number;
|
|
242
|
+
/** Timestamp of last successful sync */
|
|
243
|
+
lastSyncedAt: Date | null;
|
|
244
|
+
}
|
|
245
|
+
/** Available recovery actions */
|
|
246
|
+
type RecoveryAction = {
|
|
247
|
+
action: "reset";
|
|
248
|
+
} | {
|
|
249
|
+
action: "keep-old-schema";
|
|
250
|
+
} | {
|
|
251
|
+
action: "retry";
|
|
252
|
+
} | {
|
|
253
|
+
action: "custom";
|
|
254
|
+
handler: () => Promise<void>;
|
|
255
|
+
};
|
|
256
|
+
/** Handler for migration errors */
|
|
257
|
+
type MigrationErrorHandler = (error: MigrationError, context: RecoveryContext) => Promise<RecoveryAction>;
|
|
258
|
+
/** Yjs document info for migrations */
|
|
259
|
+
interface MigrationDoc {
|
|
260
|
+
id: string;
|
|
261
|
+
fields: Map<string, unknown>;
|
|
262
|
+
}
|
|
263
|
+
/** Context for custom client migrations */
|
|
264
|
+
interface ClientMigrationContext {
|
|
265
|
+
/** Documents that need migration */
|
|
266
|
+
dirtyDocs: MigrationDoc[];
|
|
267
|
+
/** Get Yjs document for a specific ID */
|
|
268
|
+
getYDoc(id: string): Y.Doc | null;
|
|
269
|
+
/** Schema diff being applied */
|
|
270
|
+
diff: SchemaDiff;
|
|
271
|
+
}
|
|
272
|
+
/** Custom client migration function */
|
|
273
|
+
type ClientMigrationFn = (db: MigrationDatabase, ctx: ClientMigrationContext) => Promise<void>;
|
|
274
|
+
/** Map of version numbers to custom client migrations */
|
|
275
|
+
type ClientMigrationMap = Record<number, ClientMigrationFn>;
|
|
276
|
+
/** Options for collection.create() with versioned schema */
|
|
277
|
+
interface VersionedCollectionOptions<T$1 extends object> {
|
|
278
|
+
/** Versioned schema definition */
|
|
279
|
+
schema: VersionedSchema<GenericValidator>;
|
|
280
|
+
/** Persistence provider factory */
|
|
281
|
+
persistence: () => Promise<Persistence>;
|
|
282
|
+
/** Collection configuration */
|
|
283
|
+
config: () => VersionedCollectionConfig<T$1>;
|
|
284
|
+
/** Custom client migrations (override auto-generated) */
|
|
285
|
+
clientMigrations?: ClientMigrationMap;
|
|
286
|
+
/** Handler for migration errors */
|
|
287
|
+
onMigrationError?: MigrationErrorHandler;
|
|
288
|
+
}
|
|
289
|
+
/** Configuration for versioned collection */
|
|
290
|
+
interface VersionedCollectionConfig<T$1 extends object> {
|
|
291
|
+
/** Convex client instance */
|
|
292
|
+
convexClient: convex_browser0.ConvexClient;
|
|
293
|
+
/** Collection API endpoints */
|
|
294
|
+
api: {
|
|
295
|
+
material: convex_server0.FunctionReference<"query">;
|
|
296
|
+
delta: convex_server0.FunctionReference<"query">;
|
|
297
|
+
replicate: convex_server0.FunctionReference<"mutation">;
|
|
298
|
+
presence: convex_server0.FunctionReference<"mutation">;
|
|
299
|
+
session: convex_server0.FunctionReference<"query">;
|
|
300
|
+
};
|
|
301
|
+
/** Get document key */
|
|
302
|
+
getKey: (doc: T$1) => string | number;
|
|
303
|
+
/** User identity provider */
|
|
304
|
+
user?: () => UserIdentity | undefined;
|
|
305
|
+
}
|
|
306
|
+
/** Metadata stored in SQLite for schema versioning */
|
|
307
|
+
interface SchemaMetadata {
|
|
308
|
+
collection: string;
|
|
309
|
+
version: number;
|
|
310
|
+
migratedAt: number;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the current schema version from SQLite.
|
|
314
|
+
*/
|
|
315
|
+
declare function getStoredSchemaVersion(db: MigrationDatabase, collection: string): Promise<number | null>;
|
|
316
|
+
/**
|
|
317
|
+
* Store the current schema version in SQLite.
|
|
318
|
+
*/
|
|
319
|
+
declare function setStoredSchemaVersion(db: MigrationDatabase, collection: string, version: number): Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Run auto-generated SQL migration.
|
|
322
|
+
*/
|
|
323
|
+
declare function runAutoMigration(db: MigrationDatabase, tableName: string, diff: SchemaDiff): Promise<void>;
|
|
324
|
+
/**
|
|
325
|
+
* Create a migration error.
|
|
326
|
+
*/
|
|
327
|
+
declare function createMigrationError(code: MigrationErrorCode, message: string, fromVersion: number, toVersion: number, operation?: SchemaDiffOperation): MigrationError;
|
|
328
|
+
/** Options for running migrations */
|
|
329
|
+
interface RunMigrationsOptions<_T extends object = object> {
|
|
330
|
+
/** Collection name */
|
|
331
|
+
collection: string;
|
|
332
|
+
/** Versioned schema */
|
|
333
|
+
schema: VersionedSchema<GenericValidator>;
|
|
334
|
+
/** SQLite database interface */
|
|
335
|
+
db: MigrationDatabase;
|
|
336
|
+
/** Custom client migrations (override auto-generated) */
|
|
337
|
+
clientMigrations?: ClientMigrationMap;
|
|
338
|
+
/** Handler for migration errors */
|
|
339
|
+
onError?: MigrationErrorHandler;
|
|
340
|
+
/** Get Yjs document for a specific ID (for custom migrations) */
|
|
341
|
+
getYDoc?: (id: string) => Y.Doc | null;
|
|
342
|
+
/** List all document IDs in the collection */
|
|
343
|
+
listDocuments?: () => Promise<string[]>;
|
|
344
|
+
}
|
|
345
|
+
/** Result of running migrations */
|
|
346
|
+
interface MigrationResult {
|
|
347
|
+
/** Whether migration was needed and ran */
|
|
348
|
+
migrated: boolean;
|
|
349
|
+
/** Previous schema version (null if first run) */
|
|
350
|
+
fromVersion: number | null;
|
|
351
|
+
/** Current schema version */
|
|
352
|
+
toVersion: number;
|
|
353
|
+
/** Schema diff that was applied (null if no migration needed) */
|
|
354
|
+
diff: SchemaDiff | null;
|
|
355
|
+
/** Error if migration failed */
|
|
356
|
+
error?: MigrationError;
|
|
132
357
|
}
|
|
133
|
-
declare const PROSE_BRAND: unique symbol;
|
|
134
358
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
359
|
+
* Run migrations for a collection if needed.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const result = await runMigrations({
|
|
364
|
+
* collection: "tasks",
|
|
365
|
+
* schema: taskSchema,
|
|
366
|
+
* db: persistence.db!,
|
|
367
|
+
* });
|
|
368
|
+
*
|
|
369
|
+
* if (result.migrated) {
|
|
370
|
+
* console.log(`Migrated from v${result.fromVersion} to v${result.toVersion}`);
|
|
371
|
+
* }
|
|
372
|
+
* ```
|
|
138
373
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
374
|
+
declare function runMigrations(options: RunMigrationsOptions): Promise<MigrationResult>;
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/client/services/seq.d.ts
|
|
377
|
+
type Seq = number;
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/client/services/presence.d.ts
|
|
380
|
+
interface PresenceState {
|
|
381
|
+
local: UserIdentity | null;
|
|
382
|
+
remote: UserIdentity[];
|
|
383
|
+
}
|
|
384
|
+
interface Presence {
|
|
385
|
+
join(options?: {
|
|
386
|
+
cursor?: unknown;
|
|
387
|
+
}): void;
|
|
388
|
+
leave(): void;
|
|
389
|
+
update(options: {
|
|
390
|
+
cursor?: unknown;
|
|
391
|
+
}): void;
|
|
392
|
+
get(): PresenceState;
|
|
393
|
+
subscribe(callback: (state: PresenceState) => void): () => void;
|
|
152
394
|
}
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/shared/logger.d.ts
|
|
397
|
+
declare function getLogger(category: string[]): Logger;
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/shared/index.d.ts
|
|
400
|
+
/**
|
|
401
|
+
* Prose validator for ProseMirror-compatible rich text JSON.
|
|
402
|
+
* Used for collaborative rich text editing fields.
|
|
403
|
+
*/
|
|
404
|
+
declare const proseValidator: convex_values0.VObject<{
|
|
405
|
+
content?: any[] | undefined;
|
|
406
|
+
type: "doc";
|
|
407
|
+
}, {
|
|
408
|
+
type: convex_values0.VLiteral<"doc", "required">;
|
|
409
|
+
content: convex_values0.VArray<any[] | undefined, convex_values0.VAny<any, "required", string>, "optional">;
|
|
410
|
+
}, "required", "type" | "content">;
|
|
411
|
+
/** ProseMirror-compatible JSON structure. */
|
|
412
|
+
type ProseValue = Infer<typeof proseValidator>;
|
|
153
413
|
/**
|
|
154
414
|
* Extract prose field names from T (fields typed as ProseValue).
|
|
155
415
|
* Used internally for type-safe prose field operations.
|
|
156
416
|
*/
|
|
157
|
-
type ProseFields<T> = { [K in keyof T]: T[K] extends ProseValue ? K : never }[keyof T];
|
|
417
|
+
type ProseFields<T$1> = { [K in keyof T$1]: T$1[K] extends ProseValue ? K : never }[keyof T$1];
|
|
158
418
|
//#endregion
|
|
159
419
|
//#region src/client/collection.d.ts
|
|
160
420
|
/** Server-rendered material data for SSR hydration */
|
|
161
|
-
interface Materialized<T> {
|
|
162
|
-
documents: readonly T[];
|
|
421
|
+
interface Materialized<T$1> {
|
|
422
|
+
documents: readonly T$1[];
|
|
163
423
|
cursor?: Seq;
|
|
164
424
|
count?: number;
|
|
165
425
|
crdt?: Record<string, {
|
|
@@ -167,26 +427,32 @@ interface Materialized<T> {
|
|
|
167
427
|
seq: number;
|
|
168
428
|
}>;
|
|
169
429
|
}
|
|
170
|
-
|
|
430
|
+
interface PaginatedPage<T$1> {
|
|
431
|
+
page: readonly T$1[];
|
|
432
|
+
isDone: boolean;
|
|
433
|
+
continueCursor: string;
|
|
434
|
+
}
|
|
435
|
+
interface PaginatedMaterial<T$1> {
|
|
436
|
+
pages: readonly PaginatedPage<T$1>[];
|
|
437
|
+
cursor: string;
|
|
438
|
+
isDone: boolean;
|
|
439
|
+
}
|
|
440
|
+
interface PaginationConfig {
|
|
441
|
+
pageSize?: number;
|
|
442
|
+
}
|
|
443
|
+
type PaginationStatus = "idle" | "busy" | "done" | "error";
|
|
444
|
+
interface PaginationState {
|
|
445
|
+
status: PaginationStatus;
|
|
446
|
+
count: number;
|
|
447
|
+
cursor: string | null;
|
|
448
|
+
error?: Error;
|
|
449
|
+
}
|
|
171
450
|
interface ConvexCollectionApi {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
mark: FunctionReference<"mutation">;
|
|
178
|
-
compact: FunctionReference<"mutation">;
|
|
179
|
-
material?: FunctionReference<"query">;
|
|
180
|
-
sessions?: FunctionReference<"query">;
|
|
181
|
-
cursors?: FunctionReference<"query">;
|
|
182
|
-
leave?: FunctionReference<"mutation">;
|
|
183
|
-
}
|
|
184
|
-
interface ConvexCollectionConfig<T extends object = object, TSchema extends StandardSchemaV1 = never, TKey extends string | number = string | number> extends BaseCollectionConfig<T, TKey, TSchema> {
|
|
185
|
-
schema: TSchema;
|
|
186
|
-
convexClient: ConvexClient;
|
|
187
|
-
api: ConvexCollectionApi;
|
|
188
|
-
persistence: Persistence;
|
|
189
|
-
material?: Materialized<T>;
|
|
451
|
+
material: FunctionReference<"query">;
|
|
452
|
+
delta: FunctionReference<"query">;
|
|
453
|
+
replicate: FunctionReference<"mutation">;
|
|
454
|
+
presence: FunctionReference<"mutation">;
|
|
455
|
+
session: FunctionReference<"query">;
|
|
190
456
|
}
|
|
191
457
|
/**
|
|
192
458
|
* Binding returned by collection.utils.prose() for collaborative editing.
|
|
@@ -214,25 +480,190 @@ interface EditorBinding {
|
|
|
214
480
|
destroy(): void;
|
|
215
481
|
}
|
|
216
482
|
interface ProseOptions {
|
|
217
|
-
|
|
483
|
+
/** User identity getter for collaborative presence */
|
|
484
|
+
user?: () => UserIdentity | undefined;
|
|
485
|
+
/**
|
|
486
|
+
* Debounce delay in milliseconds before syncing changes to server.
|
|
487
|
+
* Local changes are batched during this window for efficiency.
|
|
488
|
+
* @default 50
|
|
489
|
+
*/
|
|
490
|
+
debounceMs?: number;
|
|
491
|
+
/**
|
|
492
|
+
* Throttle delay in milliseconds for presence/cursor position updates.
|
|
493
|
+
* Lower values mean faster cursor sync but more network traffic.
|
|
494
|
+
* @default 50
|
|
495
|
+
*/
|
|
496
|
+
throttleMs?: number;
|
|
497
|
+
}
|
|
498
|
+
interface ConvexCollectionUtils<T$1 extends object> {
|
|
499
|
+
prose(document: string, field: ProseFields<T$1>, options?: ProseOptions): Promise<EditorBinding>;
|
|
500
|
+
}
|
|
501
|
+
interface SessionInfo {
|
|
502
|
+
client: string;
|
|
503
|
+
document: string;
|
|
504
|
+
user?: string;
|
|
505
|
+
profile?: {
|
|
506
|
+
name?: string;
|
|
507
|
+
color?: string;
|
|
508
|
+
avatar?: string;
|
|
509
|
+
};
|
|
510
|
+
cursor?: unknown;
|
|
511
|
+
connected: boolean;
|
|
512
|
+
}
|
|
513
|
+
interface SessionAPI {
|
|
514
|
+
get(docId?: string): SessionInfo[];
|
|
515
|
+
subscribe(callback: (sessions: SessionInfo[]) => void): () => void;
|
|
218
516
|
}
|
|
219
|
-
interface
|
|
220
|
-
|
|
517
|
+
interface DocumentHandle<T$1 extends object> {
|
|
518
|
+
readonly id: string;
|
|
519
|
+
readonly presence: Presence;
|
|
520
|
+
readonly awareness: Awareness;
|
|
521
|
+
prose(field: ProseFields<T$1>, options?: ProseOptions): Promise<EditorBinding>;
|
|
221
522
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
get(): Collection<T, string, ConvexCollectionUtils<T>, any, T> & NonSingleResult;
|
|
523
|
+
interface ConvexCollectionExtensions<T$1 extends object> {
|
|
524
|
+
doc(id: string): DocumentHandle<T$1>;
|
|
525
|
+
readonly session: SessionAPI;
|
|
226
526
|
}
|
|
227
|
-
|
|
228
|
-
|
|
527
|
+
interface LazyCollection<T$1 extends object> {
|
|
528
|
+
init(material?: Materialized<T$1> | PaginatedMaterial<T$1>): Promise<void>;
|
|
529
|
+
get(): Collection<T$1, string, ConvexCollectionUtils<T$1>, never, T$1> & NonSingleResult & ConvexCollectionExtensions<T$1>;
|
|
530
|
+
readonly $docType?: T$1;
|
|
531
|
+
readonly pagination: {
|
|
532
|
+
load(): Promise<PaginatedPage<T$1> | null>;
|
|
533
|
+
readonly status: PaginationStatus;
|
|
534
|
+
readonly canLoadMore: boolean;
|
|
535
|
+
readonly count: number;
|
|
536
|
+
subscribe(callback: (state: PaginationState) => void): () => void;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
type ConvexCollection<T$1 extends object> = Collection<T$1, any, ConvexCollectionUtils<T$1>, never, T$1> & NonSingleResult & ConvexCollectionExtensions<T$1>;
|
|
540
|
+
/** Options for collection.create() */
|
|
541
|
+
interface CreateCollectionOptions<T$1 extends object> {
|
|
542
|
+
schema: VersionedSchema<GenericValidator>;
|
|
229
543
|
persistence: () => Promise<Persistence>;
|
|
230
|
-
config: () =>
|
|
544
|
+
config: () => {
|
|
545
|
+
convexClient: ConvexClient;
|
|
546
|
+
api: ConvexCollectionApi;
|
|
547
|
+
getKey: (doc: T$1) => string;
|
|
548
|
+
user?: () => UserIdentity | undefined;
|
|
549
|
+
};
|
|
550
|
+
clientMigrations?: ClientMigrationMap;
|
|
551
|
+
onMigrationError?: MigrationErrorHandler;
|
|
552
|
+
pagination?: PaginationConfig;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Create a collection with versioned schema support.
|
|
556
|
+
* Handles automatic client-side migrations when schema version changes.
|
|
557
|
+
*/
|
|
558
|
+
declare function createVersionedCollection<T$1 extends object>(options: CreateCollectionOptions<T$1>): LazyCollection<T$1>;
|
|
559
|
+
declare namespace collection {
|
|
560
|
+
type Infer<C> = C extends {
|
|
561
|
+
$docType?: infer T;
|
|
562
|
+
} ? NonNullable<T> : never;
|
|
231
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Create a collection with versioned schema (new API).
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* const tasks = collection.create({
|
|
570
|
+
* schema: taskSchema,
|
|
571
|
+
* persistence: () => persistence.web.sqlite.create(),
|
|
572
|
+
* config: () => ({
|
|
573
|
+
* convexClient: new ConvexClient(url),
|
|
574
|
+
* api: api.tasks,
|
|
575
|
+
* getKey: (t) => t.id,
|
|
576
|
+
* }),
|
|
577
|
+
* onMigrationError: async (error, ctx) => {
|
|
578
|
+
* if (ctx.canResetSafely) return { action: "reset" };
|
|
579
|
+
* return { action: "keep-old-schema" };
|
|
580
|
+
* },
|
|
581
|
+
* });
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
232
584
|
declare const collection: {
|
|
233
|
-
create
|
|
585
|
+
create: typeof createVersionedCollection;
|
|
234
586
|
};
|
|
235
587
|
//#endregion
|
|
588
|
+
//#region src/client/types.d.ts
|
|
589
|
+
type TableNamesFromSchema<Schema extends SchemaDefinition<any, any>> = TableNamesInDataModel<DataModelFromSchemaDefinition<Schema>>;
|
|
590
|
+
type DocFromSchema<Schema extends SchemaDefinition<any, any>, TableName extends TableNamesFromSchema<Schema>> = WithOptionalSystemFields<DocumentByName<DataModelFromSchemaDefinition<Schema>, TableName>>;
|
|
591
|
+
/** Extract document type from a LazyCollection instance. */
|
|
592
|
+
type InferDoc<C> = C extends {
|
|
593
|
+
$docType?: infer T;
|
|
594
|
+
} ? T : never;
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region src/client/errors.d.ts
|
|
597
|
+
declare class NetworkError extends Error {
|
|
598
|
+
readonly _tag: "NetworkError";
|
|
599
|
+
readonly retryable: true;
|
|
600
|
+
readonly cause: unknown;
|
|
601
|
+
readonly operation: string;
|
|
602
|
+
constructor(props: {
|
|
603
|
+
operation: string;
|
|
604
|
+
cause: unknown;
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
declare class IDBError extends Error {
|
|
608
|
+
readonly _tag: "IDBError";
|
|
609
|
+
readonly operation: "get" | "set" | "delete" | "clear";
|
|
610
|
+
readonly cause: unknown;
|
|
611
|
+
readonly store?: string;
|
|
612
|
+
readonly key?: string;
|
|
613
|
+
constructor(props: {
|
|
614
|
+
operation: "get" | "set" | "delete" | "clear";
|
|
615
|
+
cause: unknown;
|
|
616
|
+
store?: string;
|
|
617
|
+
key?: string;
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
declare class IDBWriteError extends Error {
|
|
621
|
+
readonly _tag: "IDBWriteError";
|
|
622
|
+
readonly key: string;
|
|
623
|
+
readonly value: unknown;
|
|
624
|
+
readonly cause: unknown;
|
|
625
|
+
constructor(props: {
|
|
626
|
+
key: string;
|
|
627
|
+
value: unknown;
|
|
628
|
+
cause: unknown;
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
declare class ReconciliationError extends Error {
|
|
632
|
+
readonly _tag: "ReconciliationError";
|
|
633
|
+
readonly collection: string;
|
|
634
|
+
readonly reason: string;
|
|
635
|
+
readonly cause?: unknown;
|
|
636
|
+
constructor(props: {
|
|
637
|
+
collection: string;
|
|
638
|
+
reason: string;
|
|
639
|
+
cause?: unknown;
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
declare class ProseError extends Error {
|
|
643
|
+
readonly _tag: "ProseError";
|
|
644
|
+
readonly document: string;
|
|
645
|
+
readonly field: string;
|
|
646
|
+
readonly collection: string;
|
|
647
|
+
constructor(props: {
|
|
648
|
+
document: string;
|
|
649
|
+
field: string;
|
|
650
|
+
collection: string;
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
declare class CollectionNotReadyError extends Error {
|
|
654
|
+
readonly _tag: "CollectionNotReadyError";
|
|
655
|
+
readonly collection: string;
|
|
656
|
+
readonly reason: string;
|
|
657
|
+
constructor(props: {
|
|
658
|
+
collection: string;
|
|
659
|
+
reason: string;
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/** Error that should not be retried (auth failures, validation errors) */
|
|
663
|
+
declare class NonRetriableError extends Error {
|
|
664
|
+
constructor(message: string);
|
|
665
|
+
}
|
|
666
|
+
//#endregion
|
|
236
667
|
//#region src/client/merge.d.ts
|
|
237
668
|
/**
|
|
238
669
|
* Extract plain text from ProseMirror/BlockNote JSON content.
|
|
@@ -240,12 +671,11 @@ declare const collection: {
|
|
|
240
671
|
*/
|
|
241
672
|
declare function extract(content: unknown): string;
|
|
242
673
|
//#endregion
|
|
243
|
-
//#region src/client/
|
|
244
|
-
declare function emptyProse():
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
674
|
+
//#region src/client/validators.d.ts
|
|
675
|
+
declare function emptyProse(): {
|
|
676
|
+
type: "doc";
|
|
677
|
+
content: never[];
|
|
678
|
+
};
|
|
249
679
|
//#endregion
|
|
250
680
|
//#region src/client/persistence/memory.d.ts
|
|
251
681
|
/**
|
|
@@ -273,53 +703,132 @@ interface OPSQLiteDatabase {
|
|
|
273
703
|
}
|
|
274
704
|
declare function createNativeSqlitePersistence(db: OPSQLiteDatabase, _dbName: string): Promise<Persistence>;
|
|
275
705
|
//#endregion
|
|
706
|
+
//#region src/client/persistence/sqlite/web.d.ts
|
|
707
|
+
interface WebSqliteOptions {
|
|
708
|
+
name: string;
|
|
709
|
+
worker: Worker | (() => Worker | Promise<Worker>);
|
|
710
|
+
}
|
|
711
|
+
declare function createWebSqlitePersistence(options: WebSqliteOptions): Promise<Persistence>;
|
|
712
|
+
declare function onceWebSqlitePersistence(options: WebSqliteOptions): () => Promise<Persistence>;
|
|
713
|
+
//#endregion
|
|
276
714
|
//#region src/client/persistence/custom.d.ts
|
|
277
715
|
declare function createCustomPersistence(adapter: StorageAdapter): Persistence;
|
|
278
716
|
//#endregion
|
|
279
|
-
//#region src/client/persistence/
|
|
280
|
-
interface
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}>;
|
|
284
|
-
exec(sql: string): Promise<unknown>;
|
|
285
|
-
close(): Promise<void>;
|
|
717
|
+
//#region src/client/persistence/encrypted/types.d.ts
|
|
718
|
+
interface PassphraseConfig {
|
|
719
|
+
get: () => Promise<string>;
|
|
720
|
+
setup: (recoveryKey: string) => Promise<string>;
|
|
286
721
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
722
|
+
interface RecoveryConfig {
|
|
723
|
+
onSetup: (key: string) => Promise<void>;
|
|
724
|
+
onRecover: () => Promise<string>;
|
|
725
|
+
}
|
|
726
|
+
interface LockConfig {
|
|
727
|
+
idle: number;
|
|
728
|
+
}
|
|
729
|
+
interface WebUnlockConfig {
|
|
730
|
+
webauthn?: true;
|
|
731
|
+
passphrase?: PassphraseConfig;
|
|
732
|
+
}
|
|
733
|
+
interface NativeUnlockConfig {
|
|
734
|
+
biometric?: true;
|
|
735
|
+
passphrase?: PassphraseConfig;
|
|
736
|
+
}
|
|
737
|
+
interface WebEncryptionConfig {
|
|
738
|
+
storage: Persistence;
|
|
739
|
+
user: string;
|
|
740
|
+
mode?: "local" | "e2e";
|
|
741
|
+
unlock: WebUnlockConfig;
|
|
742
|
+
recovery?: RecoveryConfig;
|
|
743
|
+
lock?: LockConfig;
|
|
744
|
+
onLock?: () => void;
|
|
745
|
+
onUnlock?: () => void;
|
|
746
|
+
}
|
|
747
|
+
interface NativeEncryptionConfig {
|
|
748
|
+
storage: Persistence;
|
|
749
|
+
user: string;
|
|
750
|
+
mode?: "local" | "e2e";
|
|
751
|
+
unlock: NativeUnlockConfig;
|
|
752
|
+
recovery?: RecoveryConfig;
|
|
753
|
+
lock?: LockConfig;
|
|
754
|
+
onLock?: () => void;
|
|
755
|
+
onUnlock?: () => void;
|
|
756
|
+
}
|
|
757
|
+
type EncryptionState = "locked" | "unlocked" | "setup";
|
|
758
|
+
interface EncryptionPersistence extends Persistence {
|
|
759
|
+
readonly state: EncryptionState;
|
|
760
|
+
lock(): Promise<void>;
|
|
761
|
+
unlock(): Promise<void>;
|
|
762
|
+
isSupported(): Promise<boolean>;
|
|
763
|
+
}
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region src/client/persistence/encrypted/web.d.ts
|
|
766
|
+
declare function createWebEncryptionPersistence(config: WebEncryptionConfig): Promise<EncryptionPersistence>;
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region src/client/persistence/encrypted/webauthn.d.ts
|
|
769
|
+
declare function isPRFSupported(): Promise<boolean>;
|
|
770
|
+
//#endregion
|
|
771
|
+
//#region src/client/persistence/encrypted/manager.d.ts
|
|
772
|
+
type EncryptionPreference = "webauthn" | "passphrase" | "none";
|
|
773
|
+
interface EncryptionManagerHooks {
|
|
774
|
+
change?: (state: EncryptionManagerState) => void;
|
|
775
|
+
passphrase?: () => Promise<string>;
|
|
776
|
+
recovery?: (key: string) => void;
|
|
777
|
+
}
|
|
778
|
+
interface EncryptionManagerConfig {
|
|
779
|
+
storage: Persistence;
|
|
780
|
+
user: string;
|
|
781
|
+
preference?: EncryptionPreference;
|
|
782
|
+
hooks?: EncryptionManagerHooks;
|
|
783
|
+
}
|
|
784
|
+
interface EncryptionManagerState {
|
|
785
|
+
state: EncryptionState | "disabled";
|
|
786
|
+
error?: Error;
|
|
787
|
+
persistence: Persistence;
|
|
788
|
+
}
|
|
789
|
+
interface EncryptionManager {
|
|
790
|
+
get(): EncryptionManagerState;
|
|
791
|
+
enable(): Promise<void>;
|
|
792
|
+
disable(): Promise<void>;
|
|
793
|
+
unlock(): Promise<void>;
|
|
794
|
+
lock(): Promise<void>;
|
|
795
|
+
subscribe(callback: (state: EncryptionManagerState) => void): () => void;
|
|
796
|
+
destroy(): void;
|
|
797
|
+
}
|
|
798
|
+
declare function createEncryptionManager(config: EncryptionManagerConfig): Promise<EncryptionManager>;
|
|
314
799
|
//#endregion
|
|
315
800
|
//#region src/client/persistence/index.d.ts
|
|
316
801
|
declare const persistence: {
|
|
317
|
-
readonly
|
|
318
|
-
|
|
802
|
+
readonly web: {
|
|
803
|
+
readonly sqlite: {
|
|
804
|
+
readonly create: typeof createWebSqlitePersistence;
|
|
805
|
+
readonly once: typeof onceWebSqlitePersistence;
|
|
806
|
+
};
|
|
807
|
+
readonly encryption: {
|
|
808
|
+
readonly create: typeof createWebEncryptionPersistence;
|
|
809
|
+
readonly manager: typeof createEncryptionManager;
|
|
810
|
+
readonly webauthn: {
|
|
811
|
+
readonly supported: typeof isPRFSupported;
|
|
812
|
+
};
|
|
813
|
+
};
|
|
814
|
+
};
|
|
815
|
+
readonly native: {
|
|
816
|
+
readonly sqlite: {
|
|
817
|
+
readonly create: typeof createNativeSqlitePersistence;
|
|
818
|
+
};
|
|
819
|
+
readonly encryption: {
|
|
820
|
+
readonly create: () => never;
|
|
821
|
+
readonly biometric: {
|
|
822
|
+
readonly supported: () => Promise<boolean>;
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
};
|
|
826
|
+
readonly memory: {
|
|
827
|
+
readonly create: typeof memoryPersistence;
|
|
828
|
+
};
|
|
829
|
+
readonly custom: {
|
|
830
|
+
readonly create: typeof createCustomPersistence;
|
|
319
831
|
};
|
|
320
|
-
readonly sqlite: typeof createNativeSqlitePersistence;
|
|
321
|
-
readonly memory: typeof memoryPersistence;
|
|
322
|
-
readonly custom: typeof createCustomPersistence;
|
|
323
832
|
};
|
|
324
833
|
//#endregion
|
|
325
834
|
//#region src/client/index.d.ts
|
|
@@ -332,8 +841,12 @@ declare const errors: {
|
|
|
332
841
|
readonly CollectionNotReady: typeof CollectionNotReadyError;
|
|
333
842
|
readonly NonRetriable: typeof NonRetriableError;
|
|
334
843
|
};
|
|
335
|
-
declare const
|
|
336
|
-
|
|
844
|
+
declare const schema: {
|
|
845
|
+
readonly prose: {
|
|
846
|
+
readonly extract: typeof extract;
|
|
847
|
+
readonly empty: typeof emptyProse;
|
|
848
|
+
};
|
|
337
849
|
};
|
|
338
850
|
//#endregion
|
|
339
|
-
export { type ConvexCollection, type EditorBinding, type Materialized, type Persistence, type ProseOptions, type Seq, type StorageAdapter, type UserIdentity, collection, errors, persistence,
|
|
851
|
+
export { type AnonymousPresenceConfig, type ClientMigrationContext, type ClientMigrationFn, type ClientMigrationMap, type ConvexCollection, type DocFromSchema, type DocumentHandle, type Presence as DocumentPresence, type EditorBinding, type EncryptionManager, type EncryptionManagerConfig, type EncryptionManagerHooks, type EncryptionManagerState, type EncryptionPersistence, type EncryptionPreference, type EncryptionState, type InferDoc, type LazyCollection, type Logger, type Materialized, type MigrationDatabase, type MigrationDoc, type MigrationError, type MigrationErrorCode, type MigrationErrorHandler, type MigrationResult, type NativeEncryptionConfig, type PaginatedMaterial, type PaginatedPage, type PaginationConfig, type PaginationStatus, type Persistence, type PresenceState, type ProseOptions, type RecoveryAction, type RecoveryContext, type RunMigrationsOptions, type SchemaMetadata, type Seq, type SessionAPI, type SessionInfo, type StorageAdapter, type TableNamesFromSchema, type UserIdentity, type VersionedCollectionConfig, type VersionedCollectionOptions, type WebEncryptionConfig, collection, createMigrationError, errors, getLogger, getStoredSchemaVersion, identity, persistence, runAutoMigration, runMigrations, schema, setStoredSchemaVersion };
|
|
852
|
+
//# sourceMappingURL=index.d.ts.map
|