@spooky-sync/core 0.0.1-canary.323 → 0.0.1-canary.325
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/AGENTS.md +4 -3
- package/dist/index.d.ts +152 -161
- package/dist/index.js +796 -482
- package/dist/types.d.ts +7 -6
- package/package.json +4 -4
- package/src/boot/preload.saga.test.ts +29 -0
- package/src/boot/preload.saga.ts +11 -2
- package/src/client/services.ts +1 -1
- package/src/client/sp00ky-client.test.ts +4 -1
- package/src/client/sp00ky-client.ts +37 -4
- package/src/modules/crdt/acceptance.ts +75 -0
- package/src/modules/crdt/bytes.ts +50 -0
- package/src/modules/crdt/crdt-field.ts +48 -255
- package/src/modules/crdt/crdt.test.ts +365 -0
- package/src/modules/crdt/hash.ts +103 -0
- package/src/modules/crdt/index.ts +610 -363
- package/src/modules/crdt/mirror.ts +37 -0
- package/src/mutation/push.saga.test.ts +16 -0
- package/src/mutation/push.saga.ts +9 -1
- package/src/query/anon-query-isolation.integration.test.ts +31 -0
- package/src/query/env.ts +9 -0
- package/src/services/database/local-migrator.ts +5 -3
- package/src/services/database/sqlite-cache-engine.ts +2 -0
- package/src/testing/fake-services.ts +1 -1
- package/src/types.ts +7 -6
- package/src/utils/surql.ts +3 -4
- package/src/modules/crdt/crdt-hydration.test.ts +0 -210
- package/src/modules/crdt/crdt-reconnect.test.ts +0 -195
package/AGENTS.md
CHANGED
|
@@ -38,7 +38,7 @@ re-materialized from state, never patched in place.
|
|
|
38
38
|
- `BucketHandle` — file storage handle (`put`, `get`, `delete`, `exists`), plus the cache-aware `read`, `url`, `pin`/`unpin`, `evict`, `prefetch`. `get` is always remote; `read`/`url` go through the blob cache.
|
|
39
39
|
- `services/blobs/` — durable cache for bucket bytes: OPFS holds the files, `_00_blob` holds a manifest that reconcile rebuilds from disk (so a wiped local store costs metadata, not the offline cache). Nothing expires on a timer; eviction is LRU under a byte budget only, skipping pinned and on-screen entries. Config: `blobCache` in `types.ts`.
|
|
40
40
|
- `AuthService` — token management, sign-in/sign-out events.
|
|
41
|
-
- `CrdtManager`, `CrdtField`, `cursorColorFromName`, `CURSOR_COLORS`
|
|
41
|
+
- `CrdtManager`, `CrdtField`, `cursorColorFromName`, `CURSOR_COLORS`: collaborative `@crdt` fields on Loro. Client methods: `openCrdtField(table, recordId, field, draft?)` -> `Promise<CrdtField>` (every open of one field in a tab shares one `LoroDoc`; pair each with a close), `closeCrdtField(table, recordId, field)` -> `Promise<void>` (resolves once unsent edits are in the outbox), `createCrdtDraft(table, field)` -> a detached `CrdtField` for a record not created yet (`db.create` first, then pass it to `openCrdtField` as `draft`). `CrdtField`: `getDoc()`, `hasContent()`, `pushCursorState(bytes)`, `onCursorUpdate = cb` (a setter). Config: `crdt: true` preloads Loro, `crdtDebounceMs` (default 300, max wait 2 s). Design: `docs/crdt-v2.md` at the repo root.
|
|
42
42
|
- Types: `Sp00kyConfig` (client-solid wraps it as `SyncedDbConfig`), `QueryTimeToLive`, `PersistenceClient`, `StoreType`, `UpdateOptions`, `RunOptions`, `PreloadOptions`.
|
|
43
43
|
- Subpath: `@spooky-sync/core/otel` — `createOtelTransmit(endpoint)` for piping pino logs to OpenTelemetry.
|
|
44
44
|
- `client.webPush` (`WebPushModule`, `db.webPush` in the Solid bindings) - Web Push on the page: `support()`, `info()`, `subscribe(opts)` (call from a click), `unsubscribe(opts)`, `sync()`, `isSubscribed()`, `update(opts)`, `devices()`, `notify(msg)`, `cancel(id)`, `test()`, `bridge()`, `onMessage(cb)`. Server calls are `fn::push::*`; typed `WebPushError`; config `webPush` in `types.ts`. Sign-out runs through `AuthService.onBeforeSignOut`.
|
|
@@ -49,12 +49,13 @@ re-materialized from state, never patched in place.
|
|
|
49
49
|
- **Use UI hooks, not the client directly.** In a Solid app, call `useDb()` from `@spooky-sync/client-solid`. Touch `Sp00kyClient` only inside `provider.client` for advanced flows.
|
|
50
50
|
- **Mutations are optimistic.** `db.create` / `db.update` / `db.delete` return immediately; the queue drains in the background. Inspect progress via `pendingMutationCount`.
|
|
51
51
|
- **Record IDs are full strings.** `db.create('thread:abc123', {...})` — *not* `db.create('thread', { id: 'abc123' })`. The first arg is `'<table>:<id>'`. Generate IDs with `Uuid` from `surrealdb` (re-exported by `client-solid`).
|
|
52
|
-
- **`db.update` takes `(table, id, payload, options?)`**. The `debounced` option (`{ debounced: true }` or `{ debounced: { delay, key, flushOnHide } }`) coalesces rapid updates
|
|
52
|
+
- **`db.update` takes `(table, id, payload, options?)`**. The `debounced` option (`{ debounced: true }` or `{ debounced: { delay, key, flushOnHide } }`) coalesces rapid updates, e.g. a plain text input saved as you type (never for `@crdt` fields, which are not written with `db.update`). With `flushOnHide` (default `true`) the merged patch is also kept in the local `_00_pending_writes` table and pushed as soon as the page is hidden, so a reload or closed tab inside the delay does not lose it (the next boot moves a leftover patch into the outbox). `flushOnHide: false` keeps the patch in memory only.
|
|
53
53
|
- **`db.remoteQuery(sql, vars?)` is the one-shot remote read.** It runs one SurrealQL statement through the client's remote path (connect gate, per-statement timeout, concurrency limit) and returns the SurrealDB result array; results are not synced into the local cache. Use it for counts and other reads the query builder can't express.
|
|
54
54
|
- **`db.useRemote(fn)` hands out the bare SDK client.** Same cache bypass, but it skips the connect gate (a call during a reconnect fails with "Specify a namespace to use"). Reserve it for SDK features `remoteQuery` cannot reach (transactions, `live`).
|
|
55
55
|
- **Raw remote calls are gated by the query allowlist.** When the generated schema carries `policy.queryAllowlist: 'warn' | 'enforce'` (from `sync.queryAllowlist` in `sp00ky.yml`), `remoteQuery`, `useRemote` and `queryRaw` throw unless the client config sets `allowRawRemote: true`; builder queries are unaffected. A registration the SSP refuses as not allowlisted (403 `not_allowlisted`) is marked `remote: 'failed'` after one attempt with an error-level log carrying the surql and a `spky generate` hint; the view stays cold (`membershipKnown` false), it is never read as confirmed empty.
|
|
56
|
+
- **A `@crdt` field is server-written plain text.** Edit it only through `openCrdtField` / `useCrdtField`; leave it out of `db.create` / `db.update` payloads (a client write keeps the old value). Reading it (lists, search, `where`) is fine, but it trails live edits until the SSP folds the edit log (about a minute after the last edit by default). Edits travel as `<table>__crdt_log` rows through the ordinary outbox; each tab claims a random Loro peer in `_00_crdt_peer`, and log rows whose blob is not an update made by that peer are refused everywhere (`modules/crdt/acceptance.ts`, mirrored in Rust). Unsent edits survive reloads in `_00_crdt_local`. Dart (`spooky_core`) does not implement CRDT fields yet.
|
|
56
57
|
- **`@parent` columns are auto-populated.** Defined in the `.surql` schema as `record<user>` with the `-- @parent` annotation; never write them yourself — they're set from the auth context server-side.
|
|
57
|
-
- **`db.preload` is a registered query.** Resolved before on this device (a `_00_view` row exists) it returns at once; never resolved it waits until the server's membership and every body are local. It holds no subscriber, so it is evicted a ttl after registration unless a view mounts the same query. `refresh`/`staleTime` are ignored; pass `signal` to abort a cold wait.
|
|
58
|
+
- **`db.preload` is a registered query.** Resolved before on this device (a `_00_view` row exists) it returns at once; never resolved it waits until the server's membership and every body are local. A signed-out session without `enableAnonymousLiveQueries` is never sent membership, so its preload returns at once instead of blocking. It holds no subscriber, so it is evicted a ttl after registration unless a view mounts the same query. `refresh`/`staleTime` are ignored; pass `signal` to abort a cold wait.
|
|
58
59
|
- **A never-resolved query paints only vouched rows.** Before the server answers (`cold`), the local predicate scan shows a cached body only if some `_00_view` row names it (as a member or subquery child) or a write for it is in flight. A body no view names is an orphan (deleted upstream while nothing watched it): it stays hidden, and the GC deletes it 30 s after boot and then hourly. A `_00_view` row no query has resolved for 14 days is retired by the same sweep, so that query paints cold again.
|
|
59
60
|
- **A rejected write is not lost.** Application errors roll the local row back (create/update/delete) and move the mutation to `_00_failed_mutations`; the tray API above lists, retries (as a fresh write) or discards it. Network errors keep the row queued.
|
|
60
61
|
|
package/dist/index.d.ts
CHANGED
|
@@ -498,189 +498,185 @@ declare class StreamProcessorService {
|
|
|
498
498
|
private normalizeValue;
|
|
499
499
|
}
|
|
500
500
|
//#endregion
|
|
501
|
+
//#region src/utils/index.d.ts
|
|
502
|
+
declare function fileToUint8Array(file: File | Blob): Promise<Uint8Array>;
|
|
503
|
+
/**
|
|
504
|
+
* Convert plain text to simple HTML paragraphs.
|
|
505
|
+
* Useful for seeding a rich-text editor (e.g. TipTap/ProseMirror) with fallback content.
|
|
506
|
+
*/
|
|
507
|
+
declare function textToHtml(text: string): string;
|
|
508
|
+
/**
|
|
509
|
+
* Helper for retrying DB operations with exponential backoff
|
|
510
|
+
*/
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region src/modules/crdt/mirror.d.ts
|
|
513
|
+
/**
|
|
514
|
+
* The plain text a `@crdt` field shows as its column value, rendered the same
|
|
515
|
+
* way the SSP fold renders it (`packages/ssp-node/src/crdt/mirror.rs`).
|
|
516
|
+
*/
|
|
517
|
+
type CrdtKind = 'text' | 'prosemirror';
|
|
518
|
+
//#endregion
|
|
501
519
|
//#region src/modules/crdt/crdt-field.d.ts
|
|
502
520
|
declare const CURSOR_COLORS: string[];
|
|
503
521
|
declare function cursorColorFromName(name: string): string;
|
|
522
|
+
/** What a field handle needs from the manager that owns its session. */
|
|
523
|
+
interface CrdtFieldHost {
|
|
524
|
+
pushPresence(state: Uint8Array): void;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* An open collaborative field: the Loro document an editor binds to. Edits
|
|
528
|
+
* made on it are sent as the client's own edit-log rows; other clients' rows
|
|
529
|
+
* are imported into it as they arrive. Every open of the same field in one tab
|
|
530
|
+
* shares this document.
|
|
531
|
+
*/
|
|
504
532
|
declare class CrdtField {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
private
|
|
511
|
-
private
|
|
512
|
-
private unsubscribe;
|
|
513
|
-
private lastPushTime;
|
|
514
|
-
private lastCursorPushTime;
|
|
515
|
-
private loadedFromCrdt;
|
|
516
|
-
private pushRetryCount;
|
|
517
|
-
private logger;
|
|
518
|
-
private cursorsEnabled;
|
|
519
|
-
/** Remote-push debounce. Local writes happen immediately on every Loro
|
|
520
|
-
* update; the remote UPSERT is coalesced over this window. Configured
|
|
521
|
-
* via `Sp00kyConfig.crdtDebounceMs`, default 500. */
|
|
522
|
-
private remoteDebounceMs;
|
|
533
|
+
readonly table: string;
|
|
534
|
+
readonly recordId: string;
|
|
535
|
+
readonly fieldName: string;
|
|
536
|
+
readonly kind: CrdtKind;
|
|
537
|
+
readonly cursorsEnabled: boolean;
|
|
538
|
+
private readonly doc;
|
|
539
|
+
private readonly host;
|
|
523
540
|
private _onCursorUpdate;
|
|
524
541
|
private pendingCursorUpdate;
|
|
525
|
-
|
|
526
|
-
* Any cursor data that arrived before this callback was set will be replayed. */
|
|
527
|
-
set onCursorUpdate(cb: ((data: Uint8Array) => void) | null);
|
|
528
|
-
get onCursorUpdate(): ((data: Uint8Array) => void) | null;
|
|
529
|
-
/**
|
|
530
|
-
* @param LoroDocClass the `LoroDoc` constructor, injected by the caller after
|
|
531
|
-
* awaiting {@link loadLoro} — keeps `loro-crdt` out of this module's static
|
|
532
|
-
* import graph so it only ships to apps that use CRDT fields.
|
|
533
|
-
*/
|
|
534
|
-
constructor(fieldName: string, cursorsEnabled: boolean, LoroDocClass: typeof LoroDoc, initialState?: Uint8Array, logger?: Logger$1 | null);
|
|
542
|
+
constructor(table: string, recordId: string, fieldName: string, kind: CrdtKind, cursorsEnabled: boolean, doc: LoroDoc, host: CrdtFieldHost);
|
|
535
543
|
getDoc(): LoroDoc;
|
|
536
|
-
/** Whether the
|
|
544
|
+
/** Whether the document holds anything yet (local state or edits). */
|
|
537
545
|
hasContent(): boolean;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
* the
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}): void;
|
|
548
|
-
importRemote(state: Uint8Array): void;
|
|
549
|
-
exportSnapshot(): Uint8Array;
|
|
550
|
-
/** Push this session's cursor blob into the parent row at
|
|
551
|
-
* `<field>.cursors[$sid]`. No-op when cursors aren't enabled on this
|
|
552
|
-
* field — the editor still calls this method optimistically, but
|
|
553
|
-
* without `@cursor` on the schema there's nowhere to store the blob.
|
|
554
|
-
* The UPDATE itself fires the parent table's LIVE feed, so other
|
|
555
|
-
* browsers receive the cursor change without a separate `_00_rv` bump. */
|
|
556
|
-
pushCursorState(encoded: Uint8Array): Promise<void>;
|
|
557
|
-
/** Import remote cursor state (called by CrdtManager from LIVE SELECT) */
|
|
558
|
-
importRemoteCursor(base64State: string): void;
|
|
559
|
-
private scheduleRemotePush;
|
|
560
|
-
/** SET path inside a parent row for the current snapshot. `@crdt`-only
|
|
561
|
-
* fields hold the snapshot directly (`<field>`); `@crdt @cursor`
|
|
562
|
-
* fields hold a `{ state, cursors }` object so the snapshot lives at
|
|
563
|
-
* `<field>.state` next to per-session cursor blobs. */
|
|
564
|
-
private statePath;
|
|
565
|
-
/** Mirror the LoroDoc snapshot into the parent row locally. Runs on
|
|
566
|
-
* every local update and every remote import so reloads (online or
|
|
567
|
-
* offline) see the freshest content immediately. Failures are
|
|
568
|
-
* swallowed — a stale local write must never block user input. */
|
|
569
|
-
private persistLocal;
|
|
570
|
-
private pushToRemote;
|
|
546
|
+
/** Publish this session's presence (an `EphemeralStore` encoding, e.g. the
|
|
547
|
+
* editor's cursor). No-op unless the field is `@cursor`. */
|
|
548
|
+
pushCursorState(encoded: Uint8Array): void;
|
|
549
|
+
/** Called with every other session's presence blob. A blob that arrives
|
|
550
|
+
* before the editor sets this is replayed when it does. */
|
|
551
|
+
set onCursorUpdate(cb: ((data: Uint8Array) => void) | null);
|
|
552
|
+
get onCursorUpdate(): ((data: Uint8Array) => void) | null;
|
|
553
|
+
/** @internal Deliver one remote presence blob. */
|
|
554
|
+
deliverPresence(data: Uint8Array): void;
|
|
571
555
|
}
|
|
572
556
|
//#endregion
|
|
573
557
|
//#region src/modules/crdt/index.d.ts
|
|
574
558
|
/**
|
|
575
|
-
*
|
|
559
|
+
* Collaborative (`@crdt`) fields.
|
|
576
560
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
561
|
+
* Each open field is a Loro document. The client never sends the document,
|
|
562
|
+
* only its own edits: every batch of local edits becomes one row of the
|
|
563
|
+
* generated `<table>__crdt_log` table, written through the ordinary outbox
|
|
564
|
+
* (so it survives offline, reloads and retries), and every client receives
|
|
565
|
+
* the other rows through an ordinary query and merges them. Nobody writes the
|
|
566
|
+
* canonical state but the SSP, which folds the log into `_00_crdt_doc` and the
|
|
567
|
+
* parent field's plain text (see `packages/ssp-node/src/crdt`).
|
|
582
568
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
* collide on the parent's last-write-wins semantics.
|
|
569
|
+
* A row is imported only if it passes the acceptance rule the fold applies
|
|
570
|
+
* (`./acceptance`), so this tab and the server always hold the same ops.
|
|
586
571
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* via subquery. Permission inheritance happens server-side via
|
|
593
|
-
* `record_id.id != NONE` (SELECT) and `fn::can_update_record` (UPDATE).
|
|
572
|
+
* Edits carry this tab's Loro peer id, claimed for the signed-in user in
|
|
573
|
+
* `_00_crdt_peer` before the first row is sent; the database refuses a row
|
|
574
|
+
* whose peer its author does not own. A tab picks a fresh peer per session.
|
|
575
|
+
* Offline, edits stay local (and in the local snapshot) until the claim and
|
|
576
|
+
* the outbox can go through.
|
|
594
577
|
*/
|
|
578
|
+
/** A followed query: stop following it, and know when the server answered. */
|
|
579
|
+
interface Watch {
|
|
580
|
+
stop: () => void;
|
|
581
|
+
/** Resolves once the server's membership for the query is known and its
|
|
582
|
+
* rows have landed locally (never rejects; may never resolve offline). */
|
|
583
|
+
settled: Promise<void>;
|
|
584
|
+
}
|
|
585
|
+
/** The runtime pieces the manager needs from the client facade. */
|
|
586
|
+
interface CrdtPorts {
|
|
587
|
+
/** Register a query on `table` filtered by `where` and follow its rows. */
|
|
588
|
+
watch(table: string, where: Record<string, unknown>, onRows: (rows: Record<string, unknown>[]) => void): Promise<Watch>;
|
|
589
|
+
/** Optimistic create through the outbox. */
|
|
590
|
+
create(id: string, data: Record<string, unknown>): Promise<unknown>;
|
|
591
|
+
}
|
|
595
592
|
declare class CrdtManager {
|
|
596
593
|
private schema;
|
|
597
594
|
private local;
|
|
598
595
|
private remote;
|
|
599
596
|
private debounceMs;
|
|
600
|
-
private
|
|
601
|
-
private
|
|
602
|
-
private
|
|
603
|
-
private staleTables;
|
|
604
|
-
private connectionGeneration;
|
|
605
|
-
private connectionUnsubscribes;
|
|
597
|
+
private sessions;
|
|
598
|
+
private opening;
|
|
599
|
+
private ports;
|
|
606
600
|
private logger;
|
|
607
|
-
private
|
|
601
|
+
private peer;
|
|
602
|
+
/** The current peer's claim: settled once the database holds it for us. */
|
|
603
|
+
private claim;
|
|
604
|
+
private claimRetry;
|
|
605
|
+
private connectionUnsubscribes;
|
|
608
606
|
constructor(schema: SchemaStructure, local: LocalStore, remote: RemoteDatabaseService, logger: Logger$1, debounceMs?: number);
|
|
607
|
+
/** Hand over the runtime ports. Called once by the client facade. */
|
|
608
|
+
attach(ports: CrdtPorts): void;
|
|
609
609
|
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
* `ensureTableSubscription` is memoized on `liveByTable` — so without this,
|
|
614
|
-
* the first reconnect leaves CRDT realtime permanently dead: the map still
|
|
615
|
-
* holds a uuid for a subscription the server has forgotten, so every later
|
|
616
|
-
* `open()` short-circuits and no LIVE is ever re-issued.
|
|
617
|
-
*
|
|
618
|
-
* Both drop events matter: the SDK publishes `reconnecting` (not
|
|
619
|
-
* `disconnected`) when it intends to recover on its own, and `disconnected`
|
|
620
|
-
* only once it has given up.
|
|
610
|
+
* A new signed-in identity (boot, sign-in, sign-out): edits from here on
|
|
611
|
+
* belong to it, under a peer it claims. Edits already made stay with the
|
|
612
|
+
* peer they were made under.
|
|
621
613
|
*/
|
|
622
|
-
|
|
623
|
-
/** Stop observing transport events. Separate from {@link closeAll}, which also
|
|
624
|
-
* runs on a bucket switch where the manager keeps being used. */
|
|
614
|
+
setSessionId(_salt: string): void;
|
|
625
615
|
dispose(): void;
|
|
626
|
-
private hasOpenFieldFor;
|
|
627
|
-
/** Set the session id that scopes this client's cursor entries. Must be
|
|
628
|
-
* called before `open()` for cursors to be pushed under a stable key.
|
|
629
|
-
* Passed in from `sp00ky.ts` at boot (it already fetches `session::id()`
|
|
630
|
-
* for the data-module salt). */
|
|
631
|
-
setSessionId(sessionId: string): void;
|
|
632
616
|
/**
|
|
633
|
-
* Open a
|
|
617
|
+
* Open a collaborative field. Every open of the same field shares one
|
|
618
|
+
* document; close each open with {@link close}.
|
|
634
619
|
*
|
|
635
|
-
* @
|
|
636
|
-
*
|
|
637
|
-
* @param field - Field name (e.g., "title", "content")
|
|
638
|
-
* @param fallbackText - Current plain text from the record, used to seed the
|
|
639
|
-
* LoroDoc if no CRDT state exists yet (migration path)
|
|
620
|
+
* `draft` (from {@link createDraft}) hands over edits made before the record
|
|
621
|
+
* existed: they are merged in and sent like this tab's own.
|
|
640
622
|
*/
|
|
641
|
-
open(table: string, recordId: string, field: string,
|
|
642
|
-
close(table: string, recordId: string, field: string): void;
|
|
623
|
+
open(table: string, recordId: string, field: string, draft?: CrdtField): Promise<CrdtField>;
|
|
643
624
|
/**
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
625
|
+
* A detached document for a field of a record that does not exist yet (a
|
|
626
|
+
* "new thread" form). Nothing is sent; pass it to {@link open} once the
|
|
627
|
+
* record is created and its edits become the record's first ones.
|
|
647
628
|
*/
|
|
629
|
+
createDraft(table: string, field: string): Promise<CrdtField>;
|
|
630
|
+
private adopt;
|
|
631
|
+
/** Close one open. The last close of a field resolves once its unsent
|
|
632
|
+
* edits are in the outbox (or are left for a later session, offline). */
|
|
633
|
+
close(table: string, recordId: string, field: string): Promise<void>;
|
|
634
|
+
/** Close every field. `flush: false` (a bucket switch) drops unsent edits
|
|
635
|
+
* from this session's memory; they stay in the local snapshot of the
|
|
636
|
+
* bucket they belong to. */
|
|
648
637
|
closeAll(options?: {
|
|
649
638
|
flush?: boolean;
|
|
650
639
|
}): void;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
private
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
applyRow(table: string, row: Record<string, unknown>): void;
|
|
659
|
-
/** Dispatch a parent-row LIVE event to every open CrdtField on that
|
|
660
|
-
* record. Each open field reads its slice of the row directly — the
|
|
661
|
-
* CRDT snapshot is a column on the parent now, so there is no
|
|
662
|
-
* follow-up subquery. */
|
|
663
|
-
private dispatchRow;
|
|
664
|
-
/** One-shot remote fetch for a row whose CRDT field hasn't synced
|
|
665
|
-
* locally yet (fresh device, memory-backed local DB after reload, …).
|
|
666
|
-
* Used by `open()` when the local read came up empty. Subsequent
|
|
667
|
-
* cross-browser updates ride `dispatchRow` via the parent LIVE feed. */
|
|
668
|
-
private fetchAndDispatchRow;
|
|
669
|
-
/** Schema lookup: does `<table>.<field>` carry a `@cursor` annotation?
|
|
670
|
-
* Determines the on-disk shape (plain snapshot vs. `{ state, cursors }`). */
|
|
671
|
-
private fieldHasCursor;
|
|
672
|
-
/** Pull the LoroDoc snapshot bytes out of a row slice. For `@crdt`-only
|
|
673
|
-
* the slice IS the snapshot (Uint8Array); for `@crdt @cursor` it's
|
|
674
|
-
* `{ state, cursors }` where `state` carries the snapshot bytes. */
|
|
675
|
-
private extractSnapshot;
|
|
676
|
-
private killTableSubscription;
|
|
677
|
-
private makeKey;
|
|
640
|
+
private fieldSpec;
|
|
641
|
+
private start;
|
|
642
|
+
private stop;
|
|
643
|
+
private ingest;
|
|
644
|
+
private tryImport;
|
|
645
|
+
private refetchCanonical;
|
|
646
|
+
private scheduleVerify;
|
|
678
647
|
/**
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
648
|
+
* After a fold: compare this device's document with the one the server
|
|
649
|
+
* published, at the version the server published. Missing ops (rows this
|
|
650
|
+
* device never got before they were folded away) are repaired by merging
|
|
651
|
+
* the published snapshot in. The same ops giving a different state cannot
|
|
652
|
+
* be merged away; that is logged.
|
|
682
653
|
*/
|
|
683
|
-
private
|
|
654
|
+
private verify;
|
|
655
|
+
private scheduleFlush;
|
|
656
|
+
private flush;
|
|
657
|
+
/** Send every own peer's ops that are not in the outbox yet, one row per
|
|
658
|
+
* peer. Only the peer's own ops travel (`updates-in-range`): a plain
|
|
659
|
+
* `from: version` export would carry ops imported from others too, and
|
|
660
|
+
* the acceptance rule refuses such a row. */
|
|
661
|
+
private sendOwnEdits;
|
|
662
|
+
private retryLater;
|
|
663
|
+
/** Claim this session's peer once; a failure (offline, signed out) is retried. */
|
|
664
|
+
private ensureClaimed;
|
|
665
|
+
private claimPeer;
|
|
666
|
+
private localId;
|
|
667
|
+
private readLocal;
|
|
668
|
+
private schedulePersist;
|
|
669
|
+
/** Save the merged document. Another tab may have saved too: merge with
|
|
670
|
+
* its snapshot rather than overwrite it, and keep the further of the two
|
|
671
|
+
* outbox marks per peer. */
|
|
672
|
+
private persist;
|
|
673
|
+
private pushPresence;
|
|
674
|
+
/** Presence is the latest state only: no outbox, no offline queue. */
|
|
675
|
+
private sendPresence;
|
|
676
|
+
/** Remove this session's cursor when the field closes; the server's TTL
|
|
677
|
+
* sweep covers a tab that never gets here. */
|
|
678
|
+
private dropPresence;
|
|
679
|
+
private ingestPresence;
|
|
684
680
|
}
|
|
685
681
|
//#endregion
|
|
686
682
|
//#region src/modules/feature-flag/index.d.ts
|
|
@@ -2118,8 +2114,15 @@ declare class Sp00kyClient<S extends SchemaStructure> {
|
|
|
2118
2114
|
clearFeatureOverrides(): void;
|
|
2119
2115
|
getFeatureOverrides(): Record<string, FeatureFlagOverride>;
|
|
2120
2116
|
appRelease(app: string, options?: AppReleaseOptions): AppReleaseHandle;
|
|
2121
|
-
|
|
2122
|
-
|
|
2117
|
+
/** Open a `@crdt` field for editing. `draft` (from {@link createCrdtDraft})
|
|
2118
|
+
* hands over edits made before the record existed. */
|
|
2119
|
+
openCrdtField(table: string, recordId: string, field: string, draft?: CrdtField): Promise<CrdtField>;
|
|
2120
|
+
/** A detached `@crdt` document for a record not created yet; see
|
|
2121
|
+
* {@link openCrdtField}. */
|
|
2122
|
+
createCrdtDraft(table: string, field: string): Promise<CrdtField>;
|
|
2123
|
+
/** Close a `@crdt` field. The last close resolves once its unsent edits
|
|
2124
|
+
* are queued in the outbox. */
|
|
2125
|
+
closeCrdtField(table: string, recordId: string, field: string): Promise<void>;
|
|
2123
2126
|
bucket<B extends BucketNames<S>>(name: B): BucketHandle;
|
|
2124
2127
|
getBlobCacheStats(): BlobCacheStats;
|
|
2125
2128
|
}
|
|
@@ -2157,17 +2160,5 @@ declare class LocalOpTimeoutError extends Error {
|
|
|
2157
2160
|
/** Default deadline for one local-store operation. Generous: a cold 4k-row
|
|
2158
2161
|
* select on a throttled tab is seconds, not tens of seconds. */
|
|
2159
2162
|
declare const DEFAULT_LOCAL_OP_TIMEOUT_MS = 30000;
|
|
2160
|
-
//#endregion
|
|
2161
|
-
//#region src/utils/index.d.ts
|
|
2162
|
-
declare function fileToUint8Array(file: File | Blob): Promise<Uint8Array>;
|
|
2163
|
-
/**
|
|
2164
|
-
* Convert plain text to simple HTML paragraphs.
|
|
2165
|
-
* Useful for seeding a rich-text editor (e.g. TipTap/ProseMirror) with fallback content.
|
|
2166
|
-
*/
|
|
2167
|
-
declare function textToHtml(text: string): string;
|
|
2168
|
-
/**
|
|
2169
|
-
* Helper for retrying DB operations with exponential backoff
|
|
2170
|
-
*/
|
|
2171
|
-
|
|
2172
2163
|
//#endregion
|
|
2173
2164
|
export { ActiveImpersonation, AppReleaseHandle, AppReleaseModule, type AppReleaseOptions, type AppReleaseSnapshot, AuthEventSystem, AuthEventTypeMap, AuthEventTypes, AuthService, BLURHASH_IMAGE_EXTENSIONS, type BlobCacheStats, type BlobEntry, type BlobKey, type BlobReadOptions, type BlobUrlLease, type BlurhashEncodeOptions, type BlurhashSetting, type BridgeSignOutMessage, type BridgeTokenMessage, BucketHandle, BucketPutOptions, BucketPutResult, CURSOR_COLORS, ConnectionState, CrdtField, CrdtManager, DEFAULT_LOCAL_OP_TIMEOUT_MS, DebounceOptions, EventSubscriptionOptions, type FailedMutationRow as FailedMutation, FeatureFlagHandle, FeatureFlagModule, type FeatureFlagOptions, type FeatureFlagOverride, type FeatureFlagSnapshot, IMPERSONATION_ACCESS, ImpersonationCandidate, ImpersonationInfo, ImpersonationTimerHost, ImpersonationTimers, InlineRow, Level, LocalOpTimeoutError, MATERIALIZATION_SAMPLE_WINDOW, MembershipOutcome, MutationCallback, MutationEvent, MutationEventType, ORIGIN_TOKEN_KEY, PUSH_ENDPOINT_KEY, PUSH_PAYLOAD_VERSION, PersistenceClient, PhaseStat, PinoTransmit, PreloadOptions, PreloadRefresh, type PushDeviceKind, type PushNotification, type PushNotificationAction, type PushOp, type PushPayload, type PushPayloadKind, type PushUrgency, QueryAuthorityCallback, QueryConfig, QueryConfigRecord, QueryHash, QueryState, QueryStatus, QueryStatusCallback, QueryTimeToLive, QueryTimings, QueryUpdateCallback, ReconnectConfig, RecordVersionArray, RecordVersionDiff, RegistrationTimings, RunOptions, SESSION_POLL_MS, SIGN_OUT_HOOK_TIMEOUT_MS, ServerViewMeta, SignOutContext, SignOutHook, Sp00kyClient, Sp00kyClientDeps, Sp00kyConfig, Sp00kyQueryResult, Sp00kyQueryResultPromise, StorageHealth, StorageHealthStatus, StoreType, SyncHealth, SyncHealthConfig, SyncHealthStatus, TimingPhase, TokenClaims, UpdateOptions, type WebPushClientMessage, type WebPushConfig, type WebPushDevice, WebPushError, type WebPushErrorCode, type WebPushInfo, type WebPushMessage, type WebPushMessageInput, WebPushModule, type WebPushSubscribeOptions, type WebPushSupport, type WebPushSyncOptions, type WebPushSyncStatus, type WebPushUnsubscribeOptions, type WebPushUnsupportedReason, type WebPushUpdateOptions, blurhashSidecarPath, bucketContentToBlob, createAuthEventSystem, cursorColorFromName, decode as decodeBlurhash, decodeTokenClaims, detectWebPushSupport, encode as encodeBlurhash, encodeImageToBlurhash, fileToUint8Array, impersonationFromToken, isBlurhashValid, isImagePath, isPushPayload, renewDelayMs, sameImpersonation, semverGt, textToHtml };
|