@loro-dev/streams-crdt 0.12.3 → 0.13.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/dist/flock.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-BZhLwAOj.js";
1
+ import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-CvJLq-0s.js";
2
2
  import { Flock } from "@loro-dev/flock-wasm";
3
3
  //#region src/flock.ts
4
4
  function isAfter(entry, current) {
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-BZhLwAOj.js";
1
+ import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-CvJLq-0s.js";
2
2
  export { PayloadProtectionError as E2eeError, PayloadProtectionError, EphemeralStreamCrdt, InMemoryRemoteCursorStore, IndexedDbRemoteCursorStore, StreamsCrdt, createInitialRemoteCursor, createStreamUrl, isValidBucketId, isValidRillId };
package/dist/loro.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-BZhLwAOj.js";
1
+ import { a as InMemoryRemoteCursorStore, c as EphemeralStreamCrdt, i as StreamsCrdt, l as PayloadProtectionError, n as isValidBucketId, o as IndexedDbRemoteCursorStore, r as isValidRillId, s as createInitialRemoteCursor, t as createStreamUrl } from "./stream-id-CvJLq-0s.js";
2
2
  import { LoroDoc, VersionVector, decodeImportBlobMeta } from "loro-crdt";
3
3
  //#region src/loro.ts
4
4
  function batchImportUpdates(doc, updates) {
@@ -1112,6 +1112,11 @@ var StreamsTransportClient = class {
1112
1112
  const snapshotOffset = result.result.snapshotOffset;
1113
1113
  return snapshotOffset == null || snapshotOffset.length === 0 ? null : snapshotOffset;
1114
1114
  }
1115
+ async streamSupportsAppendCas() {
1116
+ const result = await this.client.streamSupportsAppendCas();
1117
+ if (result.ok) return result.result;
1118
+ throw this.toTransportFailure(result.result);
1119
+ }
1115
1120
  async putSnapshotAt(snapshotOffset, snapshot) {
1116
1121
  const result = await this.client.putSnapshot({
1117
1122
  offset: snapshotOffset,
@@ -1151,6 +1156,43 @@ var StreamsTransportClient = class {
1151
1156
  };
1152
1157
  throw this.toTransportFailure(error);
1153
1158
  }
1159
+ async appendUpdatesCas(expectedOffset, updates, producerSession) {
1160
+ const result = await this.client.appendCas({
1161
+ expectedOffset,
1162
+ part: {
1163
+ contentType: BINARY_CONTENT_TYPE,
1164
+ body: encodeItems(updates)
1165
+ },
1166
+ producer: {
1167
+ producerId: producerSession.producerId,
1168
+ epoch: producerSession.producerEpoch,
1169
+ seq: producerSession.nextProducerSeq
1170
+ }
1171
+ });
1172
+ if (result.ok) {
1173
+ if (result.result.kind === "mismatch") return {
1174
+ kind: "cas-mismatch",
1175
+ expectedOffset: result.result.expectedOffset,
1176
+ currentOffset: result.result.currentOffset
1177
+ };
1178
+ return {
1179
+ kind: "ok",
1180
+ ackEpoch: result.result.value.producer?.epoch ?? producerSession.producerEpoch,
1181
+ ackSeq: result.result.value.producer?.seq ?? producerSession.nextProducerSeq,
1182
+ nextOffset: result.result.value.nextOffset
1183
+ };
1184
+ }
1185
+ const error = result.result;
1186
+ if (error.code === "conflict" && error.detail?.kind === "producer_seq_gap") return {
1187
+ kind: "seq-gap",
1188
+ expectedSeq: error.detail.expectedSeq
1189
+ };
1190
+ if (error.code === "forbidden" && error.detail?.kind === "stale_producer_epoch") return {
1191
+ kind: "stale-epoch",
1192
+ serverEpoch: error.detail.serverEpoch
1193
+ };
1194
+ throw this.toTransportFailure(error);
1195
+ }
1154
1196
  async appendItems(updates) {
1155
1197
  const result = await this.client.append({ part: {
1156
1198
  contentType: BINARY_CONTENT_TYPE,
@@ -3157,6 +3199,7 @@ var StreamsCrdt = class StreamsCrdt {
3157
3199
  };
3158
3200
  continue;
3159
3201
  }
3202
+ if (result.kind === "cas-mismatch") throw new Error("unexpected CAS mismatch from unconditional append");
3160
3203
  frozen.producerSession = {
3161
3204
  ...frozen.producerSession,
3162
3205
  producerEpoch: result.serverEpoch + 1,
@@ -3727,4 +3770,4 @@ function createStreamUrl(input) {
3727
3770
  //#endregion
3728
3771
  export { InMemoryRemoteCursorStore as a, EphemeralStreamCrdt as c, StreamsCrdt as i, PayloadProtectionError as l, isValidBucketId as n, IndexedDbRemoteCursorStore as o, isValidRillId as r, createInitialRemoteCursor as s, createStreamUrl as t };
3729
3772
 
3730
- //# sourceMappingURL=stream-id-BZhLwAOj.js.map
3773
+ //# sourceMappingURL=stream-id-CvJLq-0s.js.map