loro-repo 0.19.0 → 0.19.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/README.md +4 -0
- package/dist/index.cjs +58 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +58 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,6 +97,10 @@ Key points:
|
|
|
97
97
|
which transports join each room. It may return ids that are not registered
|
|
98
98
|
yet (they attach when added) or an empty list (the room stays pending until
|
|
99
99
|
a later `refreshTransportRoutes()`).
|
|
100
|
+
- Rooms can be joined before ANY transport is registered (offline-first
|
|
101
|
+
startup): the join resolves as a pending room whose classic surface reads
|
|
102
|
+
`"disconnected"`, and it attaches automatically when the first transport
|
|
103
|
+
is added. Only `joinEphemeralRoom` requires a registered transport.
|
|
100
104
|
- Room handles returned by `joinMetaRoom` / `joinDocRoom` /
|
|
101
105
|
`joinFlockDocRoom` expose stable per-transport subscriptions via
|
|
102
106
|
`subscription(transportId)` / `subscriptions()`. A handle survives
|
package/dist/index.cjs
CHANGED
|
@@ -1626,6 +1626,13 @@ var RoomRecord = class {
|
|
|
1626
1626
|
classicBinding;
|
|
1627
1627
|
classicUnsubscribe;
|
|
1628
1628
|
classicLastStatus;
|
|
1629
|
+
/**
|
|
1630
|
+
* Classic-surface `firstSyncedWithRemote` deferred handed out while the
|
|
1631
|
+
* room is pending (no routed transport yet, e.g. joined before any
|
|
1632
|
+
* transport was registered). Resolved the first time a forwarder target
|
|
1633
|
+
* reports synced; never rejected, and never settled by room teardown.
|
|
1634
|
+
*/
|
|
1635
|
+
classicFirstSynced;
|
|
1629
1636
|
closed = false;
|
|
1630
1637
|
constructor(kind, id, params) {
|
|
1631
1638
|
this.kind = kind;
|
|
@@ -2028,7 +2035,6 @@ var SyncRunner = class {
|
|
|
2028
2035
|
}
|
|
2029
2036
|
async joinRoom(kind, id, params) {
|
|
2030
2037
|
await this.ready();
|
|
2031
|
-
if (this.transports.size === 0) throw new Error("Transport adapter not configured");
|
|
2032
2038
|
const key = this.roomKey(kind, id);
|
|
2033
2039
|
const existing = this.rooms.get(key);
|
|
2034
2040
|
if (existing && bytesEqual(existing.params?.auth, params?.auth)) {
|
|
@@ -2294,15 +2300,46 @@ var SyncRunner = class {
|
|
|
2294
2300
|
};
|
|
2295
2301
|
record.classicUnsubscribe = target.onStatusChange(deliver);
|
|
2296
2302
|
deliver(target.status);
|
|
2303
|
+
const pendingFirstSynced = record.classicFirstSynced;
|
|
2304
|
+
if (pendingFirstSynced && !pendingFirstSynced.settled) target.firstSyncedWithRemote.then(() => {
|
|
2305
|
+
if (!pendingFirstSynced.settled) {
|
|
2306
|
+
pendingFirstSynced.settled = true;
|
|
2307
|
+
pendingFirstSynced.resolve();
|
|
2308
|
+
}
|
|
2309
|
+
}).catch(() => {});
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Classic-surface `firstSyncedWithRemote` for a pending room (no routed
|
|
2313
|
+
* transport yet): a promise that resolves once some later forwarder
|
|
2314
|
+
* target reports its first sync. Mirrors the per-transport binding's
|
|
2315
|
+
* detached deferred semantics — pending, resolve-only.
|
|
2316
|
+
*/
|
|
2317
|
+
ensureClassicFirstSynced(record) {
|
|
2318
|
+
let deferred = record.classicFirstSynced;
|
|
2319
|
+
if (!deferred) {
|
|
2320
|
+
let resolve;
|
|
2321
|
+
deferred = {
|
|
2322
|
+
promise: new Promise((res) => {
|
|
2323
|
+
resolve = res;
|
|
2324
|
+
}),
|
|
2325
|
+
resolve,
|
|
2326
|
+
settled: false
|
|
2327
|
+
};
|
|
2328
|
+
record.classicFirstSynced = deferred;
|
|
2329
|
+
}
|
|
2330
|
+
return deferred.promise;
|
|
2297
2331
|
}
|
|
2298
2332
|
createRoomLease(record, generation) {
|
|
2299
2333
|
const isCurrent = () => this.rooms.get(this.roomKey(record.kind, record.id)) === record && record.generation === generation;
|
|
2300
|
-
const
|
|
2334
|
+
const throwMultiRouted = () => {
|
|
2335
|
+
throw new Error(`Room "${record.id}" is routed to multiple transports (${record.route.join(", ")}); use subscription(transportId) for per-transport state`);
|
|
2336
|
+
};
|
|
2337
|
+
const classicTarget = () => {
|
|
2301
2338
|
const binding = this.classicTargetBinding(record);
|
|
2302
|
-
if (binding)
|
|
2303
|
-
|
|
2304
|
-
throw new Error(route.length === 0 ? `Room "${record.id}" has no routed transports; use subscription(transportId) for per-transport state` : `Room "${record.id}" is routed to multiple transports (${route.join(", ")}); use subscription(transportId) for per-transport state`);
|
|
2339
|
+
if (!binding && record.route.length > 1) throwMultiRouted();
|
|
2340
|
+
return binding;
|
|
2305
2341
|
};
|
|
2342
|
+
const classicFirstSynced = () => this.ensureClassicFirstSynced(record);
|
|
2306
2343
|
const toRoomStatus = (status) => status === "detached" ? "disconnected" : status;
|
|
2307
2344
|
let released = false;
|
|
2308
2345
|
return {
|
|
@@ -2313,9 +2350,15 @@ var SyncRunner = class {
|
|
|
2313
2350
|
this.releaseRoomRef(record, generation);
|
|
2314
2351
|
},
|
|
2315
2352
|
get firstSyncedWithRemote() {
|
|
2316
|
-
|
|
2353
|
+
const target = classicTarget();
|
|
2354
|
+
if (target) return target.firstSyncedWithRemote;
|
|
2355
|
+
return classicFirstSynced();
|
|
2356
|
+
},
|
|
2357
|
+
waitUntilSynced: () => {
|
|
2358
|
+
const target = classicTarget();
|
|
2359
|
+
if (!target) throw new Error(`Room "${record.id}" has no routed transports; use subscription(transportId) for per-transport state`);
|
|
2360
|
+
return target.waitUntilSynced();
|
|
2317
2361
|
},
|
|
2318
|
-
waitUntilSynced: () => single().waitUntilSynced(),
|
|
2319
2362
|
rejoin: async () => {
|
|
2320
2363
|
let firstError;
|
|
2321
2364
|
for (const transportId of [...record.route]) {
|
|
@@ -2329,10 +2372,11 @@ var SyncRunner = class {
|
|
|
2329
2372
|
if (firstError !== void 0) throw firstError;
|
|
2330
2373
|
},
|
|
2331
2374
|
get status() {
|
|
2332
|
-
|
|
2375
|
+
const target = classicTarget();
|
|
2376
|
+
return target ? toRoomStatus(target.status) : "disconnected";
|
|
2333
2377
|
},
|
|
2334
2378
|
onStatusChange: (listener) => {
|
|
2335
|
-
|
|
2379
|
+
classicTarget();
|
|
2336
2380
|
this.syncClassicForwarder(record);
|
|
2337
2381
|
record.classicListeners.add(listener);
|
|
2338
2382
|
return () => {
|
|
@@ -2787,6 +2831,11 @@ var LoroRepo = class LoroRepo {
|
|
|
2787
2831
|
* Joins an ephemeral room on the transport designated for ephemeral
|
|
2788
2832
|
* delivery (`addTransport(..., { ephemeral: true })`). With exactly one
|
|
2789
2833
|
* registered transport, that transport is used.
|
|
2834
|
+
*
|
|
2835
|
+
* Unlike the persistent `join*Room` APIs (which join as pending rooms
|
|
2836
|
+
* when no transport is registered yet), this throws with zero registered
|
|
2837
|
+
* transports: ephemeral state is not persisted, so there is no meaningful
|
|
2838
|
+
* pending delivery to defer to a later transport.
|
|
2790
2839
|
*/
|
|
2791
2840
|
async joinEphemeralRoom(roomId) {
|
|
2792
2841
|
const transport = this.syncRunner.getEphemeralTransport();
|