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