@loro-dev/streams-crdt 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -3
- package/dist/flock.d.ts +2 -2
- package/dist/flock.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/loro.d.ts +2 -2
- package/dist/loro.js +1 -1
- package/dist/{stream-id-BfuQIfcB.d.ts → stream-id-BxGVitUa.d.ts} +30 -9
- package/dist/{stream-id-YOFZ4I6Y.js → stream-id-kM9JM1F7.js} +78 -244
- package/dist/stream-id-kM9JM1F7.js.map +1 -0
- package/package.json +1 -1
- package/dist/stream-id-YOFZ4I6Y.js.map +0 -1
package/README.md
CHANGED
|
@@ -184,8 +184,31 @@ the transport also clears the stored replay cursor for that stream.
|
|
|
184
184
|
- a sync callback returning a string
|
|
185
185
|
- an async callback returning a string
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
`StreamsCrdt` asks for a token before each request. If a request comes back
|
|
188
|
+
with `401` or `403`, it calls `auth` one more time with
|
|
189
|
+
`{ reason: "unauthorized", status, previousToken }` and retries that request
|
|
190
|
+
once.
|
|
191
|
+
|
|
192
|
+
This lets the caller keep a cached token in the normal path, and only refresh
|
|
193
|
+
after the server rejects it:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
let token = readCachedGatewayJwt();
|
|
197
|
+
|
|
198
|
+
const transport = new StreamsCrdt({
|
|
199
|
+
streamUrl,
|
|
200
|
+
adapter,
|
|
201
|
+
auth: async (context) => {
|
|
202
|
+
if (context?.reason === "unauthorized") {
|
|
203
|
+
token = await refreshGatewayJwt();
|
|
204
|
+
}
|
|
205
|
+
return token;
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
If your callback already returns a fresh token every time, you can ignore the
|
|
211
|
+
`context` argument.
|
|
189
212
|
|
|
190
213
|
## Remote Cursor Store
|
|
191
214
|
|
|
@@ -491,7 +514,7 @@ const transport = new StreamsCrdt({
|
|
|
491
514
|
- `createStreamIfMissing` defaults to `false` and only affects the initial sync/join bootstrap
|
|
492
515
|
- `deleteStream()` returns `{ deleted: false }` when the target stream is already missing
|
|
493
516
|
- `sync()` and `join()` return `Result` objects instead of implicitly creating missing streams
|
|
494
|
-
- `join()` resolves only after the initial replay has succeeded; without a stored remote cursor it prefers
|
|
517
|
+
- `join()` resolves only after the initial replay has succeeded; without a stored remote cursor it bootstraps once, then prefers ordinary live SSE and falls back sticky to long-poll
|
|
495
518
|
- One transport instance maps to one DS stream
|
|
496
519
|
- One adapter instance maps to one local CRDT instance
|
|
497
520
|
- Built-in remote cursor stores implement `delete(streamUrl)` so `deleteStream()` can reset replay state cleanly
|
package/dist/flock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as RemoteCursorStore, C as BeforeRemoteCursorSaveContext, D as IndexedDbRemoteCursorStoreOptions, E as IndexedDbRemoteCursorStore, O as RemoteCursor, S as TransportSyncSuccess, T as InMemoryRemoteCursorStore, _ as TransportDeleteStreamSuccess, a as CrdtAdapter, b as TransportRoomStatus, c as JsonValue, d as SnapshotTransformHook, f as SnapshotUploadOptions, g as TransportCreateStreamSuccess, h as StreamsCrdtOptions, i as StreamsCrdt, j as createInitialRemoteCursor, k as RemoteCursorSaveSource, l as Result, m as StreamsAuthProvider, n as isValidBucketId, o as CrdtUpdateBatch, p as StreamsAuthContext, r as isValidRillId, s as JsonObject, t as createStreamUrl, u as SnapshotCodec, v as TransportError, w as BeforeRemoteCursorSaveHook, x as TransportSubscription, y as TransportJoinParams } from "./stream-id-BxGVitUa.js";
|
|
2
2
|
import { ExportBundle, Flock, VersionVector, VersionVector as VersionVector$1 } from "@loro-dev/flock-wasm";
|
|
3
3
|
|
|
4
4
|
//#region src/flock.d.ts
|
|
@@ -7,5 +7,5 @@ import { ExportBundle, Flock, VersionVector, VersionVector as VersionVector$1 }
|
|
|
7
7
|
*/
|
|
8
8
|
declare function createFlockAdapter(flock: Flock): CrdtAdapter<VersionVector$1>;
|
|
9
9
|
//#endregion
|
|
10
|
-
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, type ExportBundle, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, type VersionVector, createFlockAdapter, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
|
|
10
|
+
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, type ExportBundle, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthContext, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, type VersionVector, createFlockAdapter, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
|
|
11
11
|
//# sourceMappingURL=flock.d.ts.map
|
package/dist/flock.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-
|
|
1
|
+
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-kM9JM1F7.js";
|
|
2
2
|
//#region src/flock.ts
|
|
3
3
|
function isAfter(entry, current) {
|
|
4
4
|
return entry.physicalTime > current.physicalTime || entry.physicalTime === current.physicalTime && entry.logicalCounter > current.logicalCounter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
|
|
1
|
+
import { A as RemoteCursorStore, C as BeforeRemoteCursorSaveContext, D as IndexedDbRemoteCursorStoreOptions, E as IndexedDbRemoteCursorStore, O as RemoteCursor, S as TransportSyncSuccess, T as InMemoryRemoteCursorStore, _ as TransportDeleteStreamSuccess, a as CrdtAdapter, b as TransportRoomStatus, c as JsonValue, d as SnapshotTransformHook, f as SnapshotUploadOptions, g as TransportCreateStreamSuccess, h as StreamsCrdtOptions, i as StreamsCrdt, j as createInitialRemoteCursor, k as RemoteCursorSaveSource, l as Result, m as StreamsAuthProvider, n as isValidBucketId, o as CrdtUpdateBatch, p as StreamsAuthContext, r as isValidRillId, s as JsonObject, t as createStreamUrl, u as SnapshotCodec, v as TransportError, w as BeforeRemoteCursorSaveHook, x as TransportSubscription, y as TransportJoinParams } from "./stream-id-BxGVitUa.js";
|
|
2
|
+
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthContext, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-
|
|
1
|
+
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-kM9JM1F7.js";
|
|
2
2
|
export { InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, StreamsCrdt, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
|
package/dist/loro.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as RemoteCursorStore, C as BeforeRemoteCursorSaveContext, D as IndexedDbRemoteCursorStoreOptions, E as IndexedDbRemoteCursorStore, O as RemoteCursor, S as TransportSyncSuccess, T as InMemoryRemoteCursorStore, _ as TransportDeleteStreamSuccess, a as CrdtAdapter, b as TransportRoomStatus, c as JsonValue, d as SnapshotTransformHook, f as SnapshotUploadOptions, g as TransportCreateStreamSuccess, h as StreamsCrdtOptions, i as StreamsCrdt, j as createInitialRemoteCursor, k as RemoteCursorSaveSource, l as Result, m as StreamsAuthProvider, n as isValidBucketId, o as CrdtUpdateBatch, p as StreamsAuthContext, r as isValidRillId, s as JsonObject, t as createStreamUrl, u as SnapshotCodec, v as TransportError, w as BeforeRemoteCursorSaveHook, x as TransportSubscription, y as TransportJoinParams } from "./stream-id-BxGVitUa.js";
|
|
2
2
|
import { LoroDoc } from "loro-crdt";
|
|
3
3
|
|
|
4
4
|
//#region src/loro.d.ts
|
|
@@ -18,5 +18,5 @@ import { LoroDoc } from "loro-crdt";
|
|
|
18
18
|
*/
|
|
19
19
|
declare function createLoroDocAdapter(doc: LoroDoc): CrdtAdapter<JsonObject>;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, createInitialRemoteCursor, createLoroDocAdapter, createStreamUrl, isValidBucketId, isValidRillId };
|
|
21
|
+
export { BeforeRemoteCursorSaveContext, BeforeRemoteCursorSaveHook, CrdtAdapter, CrdtUpdateBatch, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, IndexedDbRemoteCursorStoreOptions, JsonObject, JsonValue, RemoteCursor, RemoteCursorSaveSource, RemoteCursorStore, Result, SnapshotCodec, SnapshotTransformHook, SnapshotUploadOptions, StreamsAuthContext, StreamsAuthProvider, StreamsCrdt, StreamsCrdtOptions, TransportCreateStreamSuccess, TransportDeleteStreamSuccess, TransportError, TransportJoinParams, TransportRoomStatus, TransportSubscription, TransportSyncSuccess, createInitialRemoteCursor, createLoroDocAdapter, createStreamUrl, isValidBucketId, isValidRillId };
|
|
22
22
|
//# sourceMappingURL=loro.d.ts.map
|
package/dist/loro.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-
|
|
1
|
+
import { a as InMemoryRemoteCursorStore, i as StreamsCrdt, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-kM9JM1F7.js";
|
|
2
2
|
import { VersionVector, decodeImportBlobMeta } from "loro-crdt";
|
|
3
3
|
//#region src/loro.ts
|
|
4
4
|
function toDocVersionRecord(version) {
|
|
@@ -130,7 +130,27 @@ type JsonObject = {
|
|
|
130
130
|
/**
|
|
131
131
|
* Authorization source for gateway requests.
|
|
132
132
|
*/
|
|
133
|
-
type
|
|
133
|
+
type StreamsAuthContext = {
|
|
134
|
+
/** Default path before sending a request. */readonly reason: "request";
|
|
135
|
+
} | {
|
|
136
|
+
/**
|
|
137
|
+
* The previous request was rejected by the server with 401/403.
|
|
138
|
+
*
|
|
139
|
+
* Return a freshly refreshed token here when the caller keeps its own
|
|
140
|
+
* token cache.
|
|
141
|
+
*/
|
|
142
|
+
readonly reason: "unauthorized";
|
|
143
|
+
readonly status: 401 | 403;
|
|
144
|
+
readonly previousToken?: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Authorization source for gateway requests.
|
|
148
|
+
*
|
|
149
|
+
* The callback is invoked before each request. When a request comes back with
|
|
150
|
+
* 401/403, transport invokes it one more time with `reason: "unauthorized"`
|
|
151
|
+
* and retries that request once.
|
|
152
|
+
*/
|
|
153
|
+
type StreamsAuthProvider = string | ((context?: StreamsAuthContext) => MaybePromise<string | null | undefined>);
|
|
134
154
|
/**
|
|
135
155
|
* Rust-style result for transport operations that may fail for expected reasons.
|
|
136
156
|
*/
|
|
@@ -333,6 +353,13 @@ interface StreamsCrdtOptions<TVersion extends JsonObject> {
|
|
|
333
353
|
* Defaults to false so missing streams are surfaced explicitly.
|
|
334
354
|
*/
|
|
335
355
|
readonly createStreamIfMissing?: boolean;
|
|
356
|
+
/**
|
|
357
|
+
* Auth token source.
|
|
358
|
+
*
|
|
359
|
+
* String and zero-arg callback forms keep the old behavior. Callbacks may
|
|
360
|
+
* also inspect `context.reason` to refresh a cached token only after the
|
|
361
|
+
* server rejects the current one.
|
|
362
|
+
*/
|
|
336
363
|
readonly auth?: StreamsAuthProvider;
|
|
337
364
|
readonly fetch?: (input: string, init?: RequestInit) => Promise<Response>;
|
|
338
365
|
/**
|
|
@@ -436,10 +463,6 @@ declare class StreamsCrdt<TVersion extends JsonObject> implements StreamsCrdtLik
|
|
|
436
463
|
private syncOnce;
|
|
437
464
|
private performInitialJoinSync;
|
|
438
465
|
private bootstrapIntoState;
|
|
439
|
-
private bootstrapIntoJoinedState;
|
|
440
|
-
private bootstrapIntoJoinedStateViaSse;
|
|
441
|
-
private continueJoinedSseSessionUntilCaughtUp;
|
|
442
|
-
private bootstrapIntoJoinedStateViaLongPoll;
|
|
443
466
|
private catchup;
|
|
444
467
|
private appendLocalBatch;
|
|
445
468
|
private exportUpdates;
|
|
@@ -461,8 +484,6 @@ declare class StreamsCrdt<TVersion extends JsonObject> implements StreamsCrdtLik
|
|
|
461
484
|
private createStreamRequest;
|
|
462
485
|
private deleteStreamRequest;
|
|
463
486
|
private readFromOffsetSseItems;
|
|
464
|
-
private openBootstrapSseSession;
|
|
465
|
-
private readBootstrapLongPoll;
|
|
466
487
|
private readFromOffset;
|
|
467
488
|
private bootstrap;
|
|
468
489
|
private readSnapshotOffsetValue;
|
|
@@ -491,5 +512,5 @@ declare function createStreamUrl(input: {
|
|
|
491
512
|
baseUrl?: string;
|
|
492
513
|
}): string;
|
|
493
514
|
//#endregion
|
|
494
|
-
export {
|
|
495
|
-
//# sourceMappingURL=stream-id-
|
|
515
|
+
export { RemoteCursorStore as A, BeforeRemoteCursorSaveContext as C, IndexedDbRemoteCursorStoreOptions as D, IndexedDbRemoteCursorStore as E, RemoteCursor as O, TransportSyncSuccess as S, InMemoryRemoteCursorStore as T, TransportDeleteStreamSuccess as _, CrdtAdapter as a, TransportRoomStatus as b, JsonValue as c, SnapshotTransformHook as d, SnapshotUploadOptions as f, TransportCreateStreamSuccess as g, StreamsCrdtOptions as h, StreamsCrdt as i, createInitialRemoteCursor as j, RemoteCursorSaveSource as k, Result as l, StreamsAuthProvider as m, isValidBucketId as n, CrdtUpdateBatch as o, StreamsAuthContext as p, isValidRillId as r, JsonObject as s, createStreamUrl as t, SnapshotCodec as u, TransportError as v, BeforeRemoteCursorSaveHook as w, TransportSubscription as x, TransportJoinParams as y };
|
|
516
|
+
//# sourceMappingURL=stream-id-BxGVitUa.d.ts.map
|