@spooky-sync/core 0.0.1-canary.6 → 0.0.1-canary.60

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.
Files changed (47) hide show
  1. package/dist/index.d.ts +103 -367
  2. package/dist/index.js +595 -289
  3. package/dist/otel/index.d.ts +21 -0
  4. package/dist/otel/index.js +86 -0
  5. package/dist/types.d.ts +361 -0
  6. package/package.json +35 -5
  7. package/skills/sp00ky-core/SKILL.md +258 -0
  8. package/skills/sp00ky-core/references/auth.md +98 -0
  9. package/skills/sp00ky-core/references/config.md +76 -0
  10. package/src/events/events.test.ts +2 -1
  11. package/src/index.ts +3 -2
  12. package/src/modules/auth/events/index.ts +2 -1
  13. package/src/modules/auth/index.ts +17 -20
  14. package/src/modules/cache/index.ts +23 -23
  15. package/src/modules/cache/types.ts +2 -2
  16. package/src/modules/crdt/crdt-field.ts +189 -0
  17. package/src/modules/crdt/index.ts +178 -0
  18. package/src/modules/data/index.ts +64 -43
  19. package/src/modules/devtools/index.ts +23 -20
  20. package/src/modules/sync/engine.ts +31 -21
  21. package/src/modules/sync/events/index.ts +3 -2
  22. package/src/modules/sync/queue/queue-down.ts +5 -4
  23. package/src/modules/sync/queue/queue-up.ts +14 -13
  24. package/src/modules/sync/scheduler.ts +2 -2
  25. package/src/modules/sync/sync.ts +49 -36
  26. package/src/modules/sync/utils.test.ts +2 -2
  27. package/src/modules/sync/utils.ts +15 -17
  28. package/src/otel/index.ts +127 -0
  29. package/src/services/database/database.ts +11 -11
  30. package/src/services/database/events/index.ts +2 -1
  31. package/src/services/database/local-migrator.ts +21 -21
  32. package/src/services/database/local.ts +16 -15
  33. package/src/services/database/remote.ts +13 -13
  34. package/src/services/logger/index.ts +6 -101
  35. package/src/services/persistence/localstorage.ts +2 -2
  36. package/src/services/persistence/resilient.ts +34 -0
  37. package/src/services/persistence/surrealdb.ts +9 -9
  38. package/src/services/stream-processor/index.ts +32 -31
  39. package/src/services/stream-processor/stream-processor.test.ts +1 -1
  40. package/src/services/stream-processor/wasm-types.ts +2 -2
  41. package/src/{spooky.ts → sp00ky.ts} +67 -38
  42. package/src/types.ts +18 -11
  43. package/src/utils/index.ts +22 -10
  44. package/src/utils/parser.ts +3 -2
  45. package/src/utils/surql.ts +15 -15
  46. package/src/utils/withRetry.test.ts +1 -1
  47. package/tsdown.config.ts +1 -1
package/dist/index.d.ts CHANGED
@@ -1,132 +1,10 @@
1
+ import { C as Logger$1, S as UpdateOptions, T as EventSystem, _ as RunOptions, a as MutationEvent, b as Sp00kyQueryResultPromise, c as PinoTransmit, d as QueryHash, f as QueryState, g as RecordVersionDiff, h as RecordVersionArray, i as MutationCallback, l as QueryConfig, m as QueryUpdateCallback, n as EventSubscriptionOptions, o as MutationEventType, p as QueryTimeToLive, r as Level, s as PersistenceClient, t as DebounceOptions, u as QueryConfigRecord, v as Sp00kyConfig, w as EventDefinition, x as StoreType, y as Sp00kyQueryResult } from "./types.js";
1
2
  import * as surrealdb0 from "surrealdb";
2
- import { Duration, RecordId, Surreal, SurrealTransaction } from "surrealdb";
3
- import { AccessDefinition, BackendNames, BackendRoutes, BucketNames, ColumnSchema, GetTable, QueryBuilder, QueryOptions, RecordId as RecordId$1, RoutePayload, SchemaStructure, TableModel, TableNames, TypeNameToTypeMap } from "@spooky-sync/query-builder";
4
- import { Level, Level as Level$1, Logger } from "pino";
3
+ import { Duration, RecordId, Surreal as Surreal$1, SurrealTransaction } from "surrealdb";
4
+ import { AccessDefinition, BackendNames, BackendRoutes, BucketNames, ColumnSchema, GetTable, QueryBuilder, QueryOptions, RoutePayload, SchemaStructure, TableModel, TableNames, TypeNameToTypeMap } from "@spooky-sync/query-builder";
5
+ import { Logger } from "pino";
6
+ import { LoroDoc } from "loro-crdt";
5
7
 
6
- //#region src/events/index.d.ts
7
- /**
8
- * Utility type to define the payload structure of an event.
9
- * If the payload type P is never, it defines payload as undefined.
10
- */
11
- type EventPayloadDefinition<P> = [P] extends [never] ? {
12
- payload: undefined;
13
- } : {
14
- payload: P;
15
- };
16
- /**
17
- * Defines the structure of an event with a specific type and payload.
18
- * @template T The string literal type of the event.
19
- * @template P The type of the event payload.
20
- */
21
- type EventDefinition<T extends string, P> = {
22
- type: T;
23
- } & EventPayloadDefinition<P>;
24
- /**
25
- * A map of event types to their definitions.
26
- * Keys are event names, values are EventDefinitions.
27
- */
28
- type EventTypeMap = Record<string, EventDefinition<any, unknown> | EventDefinition<any, never>>;
29
- /**
30
- * Options for pushing/emitting events.
31
- */
32
- interface PushEventOptions {
33
- /** Configuration for debouncing the event. */
34
- debounced?: {
35
- key: string;
36
- delay: number;
37
- };
38
- }
39
- /**
40
- * Extracts the full Event object type from the map for a given key.
41
- */
42
- type Event<E extends EventTypeMap, T extends EventType<E>> = E[T];
43
- /**
44
- * Extracts the payload type from the map for a given key.
45
- */
46
- type EventPayload<E extends EventTypeMap, T extends EventType<E>> = E[T]['payload'];
47
- /**
48
- * Array of available event type keys.
49
- */
50
- type EventTypes<E extends EventTypeMap> = (keyof E)[];
51
- /**
52
- * Represents a valid key (event name) from the EventTypeMap.
53
- */
54
- type EventType<E extends EventTypeMap> = keyof E;
55
- /**
56
- * Function signature for an event handler.
57
- */
58
- type EventHandler<E extends EventTypeMap, T extends EventType<E>> = (event: Event<E, T>) => void;
59
- /**
60
- * Options when subscribing to an event.
61
- */
62
- type EventSubscriptionOptions$1 = {
63
- /** If true, the handler will be called immediately with the last emitted event of this type (if any). */
64
- immediately?: boolean;
65
- /** If true, the subscription will be automatically removed after the first event is handled. */
66
- once?: boolean;
67
- };
68
- /**
69
- * A type-safe event system that handles subscription, emission (including debouncing), and buffering of events.
70
- * @template E The EventTypeMap defining all supported events.
71
- */
72
- declare class EventSystem<E extends EventTypeMap> {
73
- private _eventTypes;
74
- private subscriberId;
75
- private isProcessing;
76
- private buffer;
77
- private subscribers;
78
- private subscribersTypeMap;
79
- private lastEvents;
80
- private debouncedEvents;
81
- constructor(_eventTypes: EventTypes<E>);
82
- get eventTypes(): EventTypes<E>;
83
- /**
84
- * Subscribes a handler to a specific event type.
85
- * @param type The event type to subscribe to.
86
- * @param handler The function to call when the event occurs.
87
- * @param options Subscription options (once, immediately).
88
- * @returns A subscription ID that can be used to unsubscribe.
89
- */
90
- subscribe<T extends EventType<E>>(type: T, handler: EventHandler<E, T>, options?: EventSubscriptionOptions$1): number;
91
- /**
92
- * Subscribes a handler to multiple event types.
93
- * @param types An array of event types to subscribe to.
94
- * @param handler The function to call when any of the events occur.
95
- * @param options Subscription options.
96
- * @returns An array of subscription IDs.
97
- */
98
- subscribeMany<T extends EventType<E>>(types: T[], handler: EventHandler<E, T>, options?: EventSubscriptionOptions$1): number[];
99
- /**
100
- * Unsubscribes a specific subscription by ID.
101
- * @param id The subscription ID returned by subscribe().
102
- * @returns True if the subscription was found and removed, false otherwise.
103
- */
104
- unsubscribe(id: number): boolean;
105
- /**
106
- * Emits an event with the given type and payload.
107
- * @param type The type of event to emit.
108
- * @param payload The data associated with the event.
109
- */
110
- emit<T extends EventType<E>, P extends EventPayload<E, T>>(type: T, payload: P): void;
111
- /**
112
- * Adds a fully constructed event object to the system.
113
- * Similar to emit, but takes the full event object directly.
114
- * Supports debouncing if options are provided.
115
- * @param event The event object.
116
- * @param options Options for the event push (e.g., debouncing).
117
- */
118
- addEvent<T extends EventType<E>>(event: Event<E, T>, options?: PushEventOptions): void;
119
- private handleDebouncedEvent;
120
- private scheduleProcessing;
121
- private processEvents;
122
- private dequeue;
123
- private setLastEvent;
124
- private broadcastEvent;
125
- }
126
- //#endregion
127
- //#region src/services/logger/index.d.ts
128
- type Logger$1 = Logger;
129
- //#endregion
130
8
  //#region src/services/database/events/index.d.ts
131
9
  declare const DatabaseEventTypes: {
132
10
  readonly LocalQuery: "DATABASE_LOCAL_QUERY";
@@ -154,13 +32,13 @@ interface SealedQuery<T = void> {
154
32
  //#endregion
155
33
  //#region src/services/database/database.d.ts
156
34
  declare abstract class AbstractDatabaseService {
157
- protected client: Surreal;
35
+ protected client: Surreal$1;
158
36
  protected logger: Logger$1;
159
37
  protected events: DatabaseEventSystem;
160
38
  protected abstract eventType: typeof DatabaseEventTypes.LocalQuery | typeof DatabaseEventTypes.RemoteQuery;
161
- constructor(client: Surreal, logger: Logger$1, events: DatabaseEventSystem);
39
+ constructor(client: Surreal$1, logger: Logger$1, events: DatabaseEventSystem);
162
40
  abstract connect(): Promise<void>;
163
- getClient(): Surreal;
41
+ getClient(): Surreal$1;
164
42
  getEvents(): DatabaseEventSystem;
165
43
  tx(): Promise<SurrealTransaction>;
166
44
  private queryQueue;
@@ -176,8 +54,8 @@ declare abstract class AbstractDatabaseService {
176
54
  declare class LocalDatabaseService extends AbstractDatabaseService {
177
55
  private config;
178
56
  protected eventType: "DATABASE_LOCAL_QUERY";
179
- constructor(config: SpookyConfig<any>['database'], logger: Logger$1);
180
- getConfig(): SpookyConfig<any>['database'];
57
+ constructor(config: Sp00kyConfig<any>['database'], logger: Logger$1);
58
+ getConfig(): Sp00kyConfig<any>['database'];
181
59
  connect(): Promise<void>;
182
60
  }
183
61
  //#endregion
@@ -185,8 +63,8 @@ declare class LocalDatabaseService extends AbstractDatabaseService {
185
63
  declare class RemoteDatabaseService extends AbstractDatabaseService {
186
64
  private config;
187
65
  protected eventType: "DATABASE_REMOTE_QUERY";
188
- constructor(config: SpookyConfig<any>['database'], logger: Logger$1);
189
- getConfig(): SpookyConfig<any>['database'];
66
+ constructor(config: Sp00kyConfig<any>['database'], logger: Logger$1);
67
+ getConfig(): Sp00kyConfig<any>['database'];
190
68
  connect(): Promise<void>;
191
69
  signin(params: any): Promise<any>;
192
70
  signup(params: any): Promise<any>;
@@ -194,33 +72,6 @@ declare class RemoteDatabaseService extends AbstractDatabaseService {
194
72
  invalidate(): Promise<void>;
195
73
  }
196
74
  //#endregion
197
- //#region src/modules/sync/queue/queue-up.d.ts
198
- type CreateEvent = {
199
- type: 'create';
200
- mutation_id: RecordId;
201
- record_id: RecordId;
202
- data: Record<string, unknown>;
203
- record?: Record<string, unknown>;
204
- tableName?: string;
205
- options?: PushEventOptions;
206
- };
207
- type UpdateEvent = {
208
- type: 'update';
209
- mutation_id: RecordId;
210
- record_id: RecordId;
211
- data: Record<string, unknown>;
212
- record?: Record<string, unknown>;
213
- beforeRecord?: Record<string, unknown>;
214
- options?: PushEventOptions;
215
- };
216
- type DeleteEvent = {
217
- type: 'delete';
218
- mutation_id: RecordId;
219
- record_id: RecordId;
220
- options?: PushEventOptions;
221
- };
222
- type UpEvent = CreateEvent | UpdateEvent | DeleteEvent;
223
- //#endregion
224
75
  //#region src/services/stream-processor/wasm-types.d.ts
225
76
  interface WasmStreamUpdate {
226
77
  query_id: string;
@@ -297,205 +148,6 @@ declare class StreamProcessorService {
297
148
  private normalizeValue;
298
149
  }
299
150
  //#endregion
300
- //#region src/types.d.ts
301
- /**
302
- * The type of storage backend to use for the local database.
303
- * - 'memory': In-memory storage (transient).
304
- * - 'indexeddb': IndexedDB storage (persistent).
305
- */
306
- type StoreType = 'memory' | 'indexeddb';
307
- /**
308
- * Interface for a custom persistence client.
309
- * Allows providing a custom storage mechanism for the local database.
310
- */
311
- interface PersistenceClient {
312
- /**
313
- * Sets a value in the storage.
314
- * @param key The key to set.
315
- * @param value The value to store.
316
- */
317
- set<T>(key: string, value: T): Promise<void>;
318
- /**
319
- * Gets a value from the storage.
320
- * @param key The key to retrieve.
321
- * @returns The stored value or null if not found.
322
- */
323
- get<T>(key: string): Promise<T | null>;
324
- /**
325
- * Removes a value from the storage.
326
- * @param key The key to remove.
327
- */
328
- remove(key: string): Promise<void>;
329
- }
330
- /**
331
- * Supported Time-To-Live (TTL) values for cached queries.
332
- * Format: number + unit (m=minutes, h=hours, d=days).
333
- */
334
- type QueryTimeToLive = '1m' | '5m' | '10m' | '15m' | '20m' | '25m' | '30m' | '1h' | '2h' | '3h' | '4h' | '5h' | '6h' | '7h' | '8h' | '9h' | '10h' | '11h' | '12h' | '1d';
335
- /**
336
- * Result object returned when a query is registered or executed.
337
- */
338
- interface SpookyQueryResult {
339
- /** The unique hash identifier for the query. */
340
- hash: string;
341
- }
342
- type SpookyQueryResultPromise = Promise<SpookyQueryResult>;
343
- interface EventSubscriptionOptions {
344
- priority?: number;
345
- }
346
- /**
347
- * Configuration options for the Spooky client.
348
- * @template S The schema structure type.
349
- */
350
- interface SpookyConfig<S extends SchemaStructure> {
351
- /** Database connection configuration. */
352
- database: {
353
- /** The SurrealDB endpoint URL. */
354
- endpoint?: string;
355
- /** The namespace to use. */
356
- namespace: string;
357
- /** The database name. */
358
- database: string;
359
- /** The local store type implementation. */
360
- store?: StoreType;
361
- /** Authentication token. */
362
- token?: string;
363
- };
364
- /** Unique client identifier. If not provided, one will be generated. */
365
- clientId?: string;
366
- /** The schema definition. */
367
- schema: S;
368
- /** The compiled SURQL schema string. */
369
- schemaSurql: string;
370
- /** Logging level. */
371
- logLevel: Level$1;
372
- /**
373
- * Persistence client to use.
374
- * Can be a custom implementation, 'surrealdb' (default), or 'localstorage'.
375
- */
376
- persistenceClient?: PersistenceClient | 'surrealdb' | 'localstorage';
377
- /** OpenTelemetry collector endpoint for telemetry data. */
378
- otelEndpoint?: string;
379
- /**
380
- * Debounce time in milliseconds for stream updates.
381
- * Defaults to 100ms.
382
- */
383
- streamDebounceTime?: number;
384
- }
385
- type QueryHash = string;
386
- type RecordVersionArray = Array<[string, number]>;
387
- /**
388
- * Represents the difference between two record version sets.
389
- * Used for synchronizing local and remote states.
390
- */
391
- interface RecordVersionDiff {
392
- /** List of records added. */
393
- added: Array<{
394
- id: RecordId$1<string>;
395
- version: number;
396
- }>;
397
- /** List of records updated. */
398
- updated: Array<{
399
- id: RecordId$1<string>;
400
- version: number;
401
- }>;
402
- /** List of record IDs removed. */
403
- removed: RecordId$1<string>[];
404
- }
405
- /**
406
- * Configuration for a specific query instance.
407
- * Stores metadata about the query's state, parameters, and versioning.
408
- */
409
- interface QueryConfig {
410
- /** The unique ID of the query config record. */
411
- id: RecordId$1<string>;
412
- /** The SURQL query string. */
413
- surql: string;
414
- /** Parameters used in the query. */
415
- params: Record<string, any>;
416
- /** The version array representing the local state of results. */
417
- localArray: RecordVersionArray;
418
- /** The version array representing the remote (server) state of results. */
419
- remoteArray: RecordVersionArray;
420
- /** Time-To-Live for this query. */
421
- ttl: QueryTimeToLive;
422
- /** Timestamp when the query was last accessed/active. */
423
- lastActiveAt: Date;
424
- /** The name of the table this query targets (if applicable). */
425
- tableName: string;
426
- }
427
- type QueryConfigRecord = QueryConfig & {
428
- id: string;
429
- };
430
- /**
431
- * Internal state of a live query.
432
- */
433
- interface QueryState {
434
- /** The configuration for this query. */
435
- config: QueryConfig;
436
- /** The current cached records for this query. */
437
- records: Record<string, any>[];
438
- /** Timer for TTL expiration. */
439
- ttlTimer: NodeJS.Timeout | null;
440
- /** TTL duration in milliseconds. */
441
- ttlDurationMs: number;
442
- /** Number of times the query has been updated. */
443
- updateCount: number;
444
- }
445
- type QueryUpdateCallback = (records: Record<string, any>[]) => void;
446
- type MutationCallback = (mutations: UpEvent[]) => void;
447
- type MutationEventType = 'create' | 'update' | 'delete';
448
- /**
449
- * Represents a mutation event (create, update, delete) to be synchronized.
450
- */
451
- interface MutationEvent {
452
- /** Example: 'create', 'update', or 'delete'. */
453
- type: MutationEventType;
454
- /** unique id of the mutation */
455
- mutation_id: RecordId$1<string>;
456
- /** The ID of the record being mutated. */
457
- record_id: RecordId$1<string>;
458
- /** The data payload for create/update operations. */
459
- data?: any;
460
- /** The full record data (optional context). */
461
- record?: any;
462
- /** Options for the mutation event (e.g., debounce settings). */
463
- options?: PushEventOptions;
464
- /** Timestamp when the event was created. */
465
- createdAt: Date;
466
- }
467
- /**
468
- * Options for run operations.
469
- */
470
- interface RunOptions {
471
- assignedTo?: string;
472
- max_retries?: number;
473
- retry_strategy?: 'linear' | 'exponential';
474
- }
475
- /**
476
- * Options for update operations.
477
- */
478
- interface UpdateOptions {
479
- /**
480
- * Debounce configuration for the update.
481
- * If boolean, enables default debounce behavior.
482
- */
483
- debounced?: boolean | DebounceOptions;
484
- }
485
- /**
486
- * Configuration options for debouncing updates.
487
- */
488
- interface DebounceOptions {
489
- /**
490
- * The key to use for debouncing.
491
- * - 'recordId': Debounce based on the specific record ID. WARNING: IT WILL ONLY ACCEPT THE LATEST CHANGE AND DOES *NOT* MERGE THE PREVIOUS ONCES. IF YOU ARE UNSURE JUST USE 'recordId_x_fields'.
492
- * - 'recordId_x_fields': Debounce based on record ID and specific fields.
493
- */
494
- key?: 'recordId' | 'recordId_x_fields';
495
- /** The debounce delay in milliseconds. */
496
- delay?: number;
497
- }
498
- //#endregion
499
151
  //#region src/modules/auth/events/index.d.ts
500
152
  declare const AuthEventTypes: {
501
153
  readonly AuthStateChanged: "AUTH_STATE_CHANGED";
@@ -543,7 +195,75 @@ declare class AuthService<S extends SchemaStructure> {
543
195
  signIn<Name extends keyof S['access'] & string>(accessName: Name, params: ExtractAccessParams<S, Name, 'signIn'>): Promise<void>;
544
196
  }
545
197
  //#endregion
546
- //#region src/spooky.d.ts
198
+ //#region src/modules/crdt/crdt-field.d.ts
199
+ declare const CURSOR_COLORS: string[];
200
+ declare function cursorColorFromName(name: string): string;
201
+ declare class CrdtField {
202
+ private fieldName;
203
+ private doc;
204
+ private pushTimer;
205
+ private remote;
206
+ private recordId;
207
+ private unsubscribe;
208
+ private lastPushTime;
209
+ private lastCursorPushTime;
210
+ private loadedFromCrdt;
211
+ private pushRetryCount;
212
+ private logger;
213
+ private _onCursorUpdate;
214
+ private pendingCursorUpdate;
215
+ /** Callback set by the editor to receive remote cursor updates.
216
+ * Any cursor data that arrived before this callback was set will be replayed. */
217
+ set onCursorUpdate(cb: ((data: Uint8Array) => void) | null);
218
+ get onCursorUpdate(): ((data: Uint8Array) => void) | null;
219
+ constructor(fieldName: string, initialState?: string, logger?: Logger$1 | null);
220
+ getDoc(): LoroDoc;
221
+ /** Whether the LoroDoc was loaded from saved CRDT state */
222
+ hasContent(): boolean;
223
+ startSync(remote: RemoteDatabaseService, recordId: string): void;
224
+ stopSync(): void;
225
+ importRemote(base64State: string): void;
226
+ exportSnapshot(): string;
227
+ /** Push cursor ephemeral state to _00_crdt as a "_cursor_<fieldName>" entry */
228
+ pushCursorState(encoded: Uint8Array): Promise<void>;
229
+ /** Import remote cursor state (called by CrdtManager from LIVE SELECT) */
230
+ importRemoteCursor(base64State: string): void;
231
+ private schedulePush;
232
+ private pushToRemote;
233
+ }
234
+ //#endregion
235
+ //#region src/modules/crdt/index.d.ts
236
+ /**
237
+ * CrdtManager manages active CrdtField instances and their sync channels.
238
+ *
239
+ * Each open record gets a LIVE SELECT on _00_crdt that delivers remote
240
+ * changes in real time.
241
+ */
242
+ declare class CrdtManager {
243
+ private schema;
244
+ private remote;
245
+ private fields;
246
+ private liveQueries;
247
+ private logger;
248
+ constructor(schema: SchemaStructure, remote: RemoteDatabaseService, logger: Logger$1);
249
+ /**
250
+ * Open a CRDT field for collaborative editing.
251
+ *
252
+ * @param table - Table name
253
+ * @param recordId - Full record ID (e.g., "thread:abc")
254
+ * @param field - Field name (e.g., "title", "content")
255
+ * @param fallbackText - Current plain text from the record, used to seed the
256
+ * LoroDoc if no CRDT state exists yet (migration path)
257
+ */
258
+ open(table: string, recordId: string, field: string, fallbackText?: string): Promise<CrdtField>;
259
+ close(table: string, recordId: string, field: string): void;
260
+ closeAll(): void;
261
+ private ensureLiveSelect;
262
+ private killLiveSelect;
263
+ private makeKey;
264
+ }
265
+ //#endregion
266
+ //#region src/sp00ky.d.ts
547
267
  declare class BucketHandle {
548
268
  private bucketName;
549
269
  private remote;
@@ -557,7 +277,7 @@ declare class BucketHandle {
557
277
  rename(sourcePath: string, targetPath: string): Promise<void>;
558
278
  list(prefix?: string): Promise<string[]>;
559
279
  }
560
- declare class SpookyClient<S extends SchemaStructure> {
280
+ declare class Sp00kyClient<S extends SchemaStructure> {
561
281
  private config;
562
282
  private local;
563
283
  private remote;
@@ -567,14 +287,15 @@ declare class SpookyClient<S extends SchemaStructure> {
567
287
  private dataModule;
568
288
  private sync;
569
289
  private devTools;
290
+ private crdtManager;
570
291
  private logger;
571
292
  auth: AuthService<S>;
572
293
  streamProcessor: StreamProcessorService;
573
- get remoteClient(): Surreal;
574
- get localClient(): Surreal;
294
+ get remoteClient(): surrealdb0.Surreal;
295
+ get localClient(): surrealdb0.Surreal;
575
296
  get pendingMutationCount(): number;
576
297
  subscribeToPendingMutations(cb: (count: number) => void): () => void;
577
- constructor(config: SpookyConfig<S>);
298
+ constructor(config: Sp00kyConfig<S>);
578
299
  /**
579
300
  * Setup direct callbacks instead of event subscriptions
580
301
  */
@@ -582,8 +303,18 @@ declare class SpookyClient<S extends SchemaStructure> {
582
303
  init(): Promise<void>;
583
304
  close(): Promise<void>;
584
305
  authenticate(token: string): Promise<surrealdb0.Tokens>;
306
+ /**
307
+ * Open a CRDT field for collaborative editing.
308
+ * Returns a CrdtField with a LoroDoc that can be bound to any editor.
309
+ * Also starts a LIVE SELECT on _00_crdt for real-time sync.
310
+ */
311
+ openCrdtField(table: string, recordId: string, field: string, fallbackText?: string): Promise<CrdtField>;
312
+ /**
313
+ * Close a CRDT field when editing is done.
314
+ */
315
+ closeCrdtField(table: string, recordId: string, field: string): void;
585
316
  deauthenticate(): Promise<void>;
586
- query<Table extends TableNames<S>>(table: Table, options: QueryOptions<TableModel<GetTable<S, Table>>, false>, ttl?: QueryTimeToLive): QueryBuilder<S, Table, SpookyQueryResultPromise>;
317
+ query<Table extends TableNames<S>>(table: Table, options: QueryOptions<TableModel<GetTable<S, Table>>, false>, ttl?: QueryTimeToLive): QueryBuilder<S, Table, Sp00kyQueryResultPromise>;
587
318
  private initQuery;
588
319
  queryRaw(sql: string, params: Record<string, any>, ttl: QueryTimeToLive): Promise<string>;
589
320
  subscribe(queryHash: string, callback: (records: Record<string, any>[]) => void, options?: {
@@ -603,9 +334,14 @@ declare class SpookyClient<S extends SchemaStructure> {
603
334
  //#endregion
604
335
  //#region src/utils/index.d.ts
605
336
  declare function fileToUint8Array(file: File | Blob): Promise<Uint8Array>;
337
+ /**
338
+ * Convert plain text to simple HTML paragraphs.
339
+ * Useful for seeding a rich-text editor (e.g. TipTap/ProseMirror) with fallback content.
340
+ */
341
+ declare function textToHtml(text: string): string;
606
342
  /**
607
343
  * Helper for retrying DB operations with exponential backoff
608
344
  */
609
345
 
610
346
  //#endregion
611
- export { AuthEventSystem, AuthEventTypeMap, AuthEventTypes, AuthService, BucketHandle, DebounceOptions, EventSubscriptionOptions, type Level, MutationCallback, MutationEvent, MutationEventType, PersistenceClient, QueryConfig, QueryConfigRecord, QueryHash, QueryState, QueryTimeToLive, QueryUpdateCallback, RecordVersionArray, RecordVersionDiff, RunOptions, SpookyClient, SpookyConfig, SpookyQueryResult, SpookyQueryResultPromise, StoreType, UpdateOptions, createAuthEventSystem, fileToUint8Array };
347
+ export { AuthEventSystem, AuthEventTypeMap, AuthEventTypes, AuthService, BucketHandle, CURSOR_COLORS, CrdtField, CrdtManager, DebounceOptions, EventSubscriptionOptions, Level, MutationCallback, MutationEvent, MutationEventType, PersistenceClient, PinoTransmit, QueryConfig, QueryConfigRecord, QueryHash, QueryState, QueryTimeToLive, QueryUpdateCallback, RecordVersionArray, RecordVersionDiff, RunOptions, Sp00kyClient, Sp00kyConfig, Sp00kyQueryResult, Sp00kyQueryResultPromise, StoreType, UpdateOptions, createAuthEventSystem, cursorColorFromName, fileToUint8Array, textToHtml };