@loro-dev/streams-crdt 0.11.1 → 0.12.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.
@@ -104,10 +104,29 @@ declare function createInitialRemoteCursor<TVersion extends JsonObject = JsonObj
104
104
  * Retry and timeout settings used by `StreamsCrdt`.
105
105
  */
106
106
  interface ReconnectConfig {
107
+ /** Retry delay schedule in milliseconds, indexed by retry attempt and clamped at the last entry. */
107
108
  readonly delays: readonly number[];
109
+ /** Fractional +/- jitter applied to scheduled retry delays. */
108
110
  readonly jitterFraction: number;
111
+ /** Maximum retry attempts for background live loops. Use `Infinity` to retry forever. */
109
112
  readonly maxAttempts: number;
113
+ /** Connect deadline for ordinary transport requests. */
110
114
  readonly connectTimeoutMs: number;
115
+ /**
116
+ * Soft diagnostic threshold for initial bootstrap/catch-up.
117
+ *
118
+ * Crossing this threshold does not abort or reject the in-flight request.
119
+ * Set to 0 or `Infinity` to disable it.
120
+ */
121
+ readonly initialSyncSlowAfterMs?: number;
122
+ /**
123
+ * Hard cap for initial bootstrap/catch-up before aborting with
124
+ * `initial_sync_timeout`.
125
+ *
126
+ * Set to 0 or `Infinity` to disable it.
127
+ */
128
+ readonly initialSyncHardTimeoutMs?: number;
129
+ /** Poll deadline for ordinary long-poll/read requests. */
111
130
  readonly pollTimeoutMs: number;
112
131
  /** SSE inactivity timeout. Aborts and reconnects if no event arrives within this period. */
113
132
  readonly liveInactivityTimeoutMs?: number;
@@ -186,6 +205,7 @@ type TransportRoomStatus = "joined" | "reconnecting" | "disconnected" | "error";
186
205
  * - `protocol_error` — 400/405/409 or malformed response; treat as a bug.
187
206
  * - `network_error` — fetch-level failure (DNS, connection refused). Retry.
188
207
  * - `timeout` — connect or poll deadline exceeded. Retry.
208
+ * - `initial_sync_timeout` — initial bootstrap/catch-up exceeded its hard cap.
189
209
  * - `gone` — 410; persisted cursor is no longer valid. Bootstrap from scratch.
190
210
  * - `apply_incomplete` — a CRDT adapter could not fully apply remote data.
191
211
  * - `server_error` — 5xx; transient backend failure, retry with backoff.
@@ -272,6 +292,18 @@ type TransportError =
272
292
  readonly phase: "connect" | "poll";
273
293
  readonly message: string;
274
294
  }
295
+ /**
296
+ * Initial bootstrap/catch-up exceeded its hard timeout. The request was allowed
297
+ * past the slow diagnostic threshold first; this only fires at the hard cap.
298
+ */
299
+ | {
300
+ readonly code: "initial_sync_timeout";
301
+ readonly retryable: true;
302
+ readonly operation: string;
303
+ readonly timeoutMs: number;
304
+ readonly elapsedMs: number;
305
+ readonly message: string;
306
+ }
275
307
  /**
276
308
  * The server indicated the persisted cursor is no longer valid (410). The
277
309
  * runtime will bootstrap from scratch on the next `join()`/`sync()` —
@@ -418,19 +450,32 @@ interface StreamsCrdtShardUrlsOptions {
418
450
  * Origin URLs used for `GET <stream>/bootstrap`.
419
451
  *
420
452
  * Each entry should be an origin URL such as
421
- * `https://control-a.streams-api-proxy.loro.dev`. The transport keeps the
453
+ * `https://control-a.api.streams-api-x.loro.dev`. The transport keeps the
422
454
  * stream path and query from `streamUrl` and only replaces the request origin.
455
+ * If omitted, `other` is used as the fallback pool for bootstrap requests.
423
456
  */
424
457
  readonly bootstrap?: readonly string[];
425
458
  /**
426
459
  * Origin URLs used for non-SSE catch-up reads:
427
460
  * `GET <stream>?offset=...` and long-poll fallback reads.
461
+ *
462
+ * If omitted, `other` is used as the fallback pool for catch-up requests.
428
463
  */
429
464
  readonly catchup?: readonly string[];
430
465
  /**
431
466
  * Origin URLs used for large `POST <stream>` append requests.
467
+ *
468
+ * If omitted, `other` is used as the fallback pool for large append requests.
432
469
  */
433
470
  readonly largePost?: readonly string[];
471
+ /**
472
+ * Origin URLs used when no operation-specific shard pool routes the request.
473
+ *
474
+ * This covers live SSE reads, create/delete/head requests, snapshot uploads,
475
+ * append POSTs not routed by `largePost`, and any future request shape not
476
+ * listed above.
477
+ */
478
+ readonly other?: readonly string[];
434
479
  /**
435
480
  * Minimum request body size before `largePost` routing applies.
436
481
  *
@@ -670,6 +715,8 @@ interface EphemeralStreamCrdtOptions {
670
715
  readonly auth?: StreamsAuthProvider;
671
716
  /** Optional fetch implementation for tests, workers, or custom runtimes. */
672
717
  readonly fetch?: (input: string, init?: RequestInit) => Promise<Response>;
718
+ /** Optional origin pools for routing ephemeral POST/SSE requests. */
719
+ readonly shardUrls?: StreamsCrdtShardUrlsOptions;
673
720
  /** Reconnect policy for the SSE read loop and local POST retry loop. */
674
721
  readonly reconnectConfig?: Partial<ReconnectConfig>;
675
722
  /** Enables diagnostic console logging for terminal read/write failures. */
@@ -690,6 +737,15 @@ interface StreamsCrdtOptions<TVersion extends JsonObject> {
690
737
  * Defaults to false so missing streams are surfaced explicitly.
691
738
  */
692
739
  readonly createStreamIfMissing?: boolean;
740
+ /**
741
+ * Optional stream time-to-live in seconds used when creating the stream.
742
+ *
743
+ * Applies to both explicit `createStream()` calls and automatic stream
744
+ * creation through `createStreamIfMissing`. The value must be a non-negative
745
+ * safe integer. Updating this option on an existing stream has no effect
746
+ * until the transport creates that stream again.
747
+ */
748
+ readonly streamTtlSeconds?: number;
693
749
  /**
694
750
  * Auth token source.
695
751
  *
@@ -741,8 +797,16 @@ interface StreamsCrdtOptions<TVersion extends JsonObject> {
741
797
  */
742
798
  readonly payloadProtection?: PayloadProtectionOptions;
743
799
  readonly snapshotUpload?: SnapshotUploadOptions;
744
- /** Optional origin pools for routing bootstrap/catch-up and large append requests. */
800
+ /** Optional origin pools for routing transport requests. */
745
801
  readonly shardUrls?: StreamsCrdtShardUrlsOptions;
802
+ /**
803
+ * Partial override for retry, ordinary request timeout, live SSE inactivity,
804
+ * and initial bootstrap/catch-up deadline behavior.
805
+ *
806
+ * The runtime merges this with its defaults. `initialSyncSlowAfterMs` is only
807
+ * a diagnostic threshold; it does not abort the request. `initialSyncHardTimeoutMs`
808
+ * aborts initial bootstrap/catch-up and returns `initial_sync_timeout`.
809
+ */
746
810
  readonly reconnectConfig?: Partial<ReconnectConfig>;
747
811
  readonly debug?: boolean;
748
812
  }
@@ -897,6 +961,7 @@ declare class StreamsCrdt<TVersion extends JsonObject> implements StreamsCrdtLik
897
961
  join(params?: TransportJoinParams): Promise<Result<TransportSubscription, TransportError>>;
898
962
  private createSubscription;
899
963
  private disposeJoinState;
964
+ private runInitialSyncWithDeadline;
900
965
  private startJoin;
901
966
  private syncOnce;
902
967
  private performInitialJoinSync;
@@ -1051,4 +1116,4 @@ declare function createStreamUrl(input: {
1051
1116
  }): string;
1052
1117
  //#endregion
1053
1118
  export { BeforeRemoteCursorSaveHook as $, PayloadProtectionReadPolicy as A, StreamsCrdtShardUrlsOptions as B, IsolatedCrdtAdapter as C, PayloadProtectionKey as D, PayloadProtectionEncryptionOptions as E, SnapshotTransformHook as F, TransportError as G, TransportCatchupSuccess as H, SnapshotUploadOptions as I, TransportSnapshotUploadSuccess as J, TransportJoinParams as K, StreamsAuthContext as L, PayloadProtectionWritePolicy as M, Result as N, PayloadProtectionKeyProvider as O, SnapshotCodec as P, BeforeRemoteCursorSaveContext as Q, StreamsAuthProvider as R, EphemeralStreamSubscription as S, JsonValue as T, TransportCreateStreamSuccess as U, TransportCatchupParams as V, TransportDeleteStreamSuccess as W, TransportSyncSuccess as X, TransportSubscription as Y, WriteOnlyAppendResult as Z, E2eeScope as _, EphemeralStreamCrdt as a, RemoteCursorStore as at, EphemeralStreamCrdtOptions as b, CrdtApplyOutcome as c, CrdtUpdateBatch as d, InMemoryRemoteCursorStore as et, E2eeEncryptionOptions as f, E2eeReadPolicy as g, E2eeOptions as h, PayloadProtectionError as i, RemoteCursorSaveSource as it, PayloadProtectionScope as j, PayloadProtectionOptions as k, CrdtApplyReturn as l, E2eeKeyProvider as m, isValidBucketId as n, IndexedDbRemoteCursorStoreOptions as nt, StreamsCrdt as o, createInitialRemoteCursor as ot, E2eeKey as p, TransportRoomStatus as q, isValidRillId as r, RemoteCursor as rt, CrdtAdapter as s, createStreamUrl as t, IndexedDbRemoteCursorStore as tt, CrdtUnresolvedSpan as u, E2eeWritePolicy as v, JsonObject as w, EphemeralStreamJoinParams as x, EphemeralStreamAdaptor as y, StreamsCrdtOptions as z };
1054
- //# sourceMappingURL=stream-id-DAAMJlvT.d.ts.map
1119
+ //# sourceMappingURL=stream-id-DJYQlTE2.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loro-dev/streams-crdt",
3
3
  "description": "Transport/runtime layer for synchronizing CRDT state over Durable Streams.",
4
- "version": "0.11.1",
4
+ "version": "0.12.1",
5
5
  "license": "MIT",
6
6
  "author": "Loro Team",
7
7
  "homepage": "https://streams.loro.dev",