@mdbase-dev/sdk 0.2.61 → 0.2.63

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.
@@ -15698,12 +15698,12 @@ function appReleaseTrust() {
15698
15698
  // src/application/asset-pins.json
15699
15699
  var asset_pins_default = {
15700
15700
  runtime: {
15701
- sha256: "18f9cc9ce4e613f23c8d4120fcdd58c7c0865224737e30f905a7173fdb8ada2d",
15702
- bytes: 4093898,
15703
- maxBytes: 4093898,
15701
+ sha256: "d5452814d656c9611d0be04a934278d88ca8c83d3e823353f9842811a63a4795",
15702
+ bytes: 4141990,
15703
+ maxBytes: 4141990,
15704
15704
  source: {
15705
15705
  repository: "mdbase-dev/mdbase-connect",
15706
- commit: "2da2b0bc84ee9ecd0ecdef79ea0e2e1ef334bccd"
15706
+ commit: "1f9c2965a3e7198eb2a2ed0c409dde5dfdef11fc"
15707
15707
  }
15708
15708
  },
15709
15709
  sqlite: {
@@ -15813,6 +15813,12 @@ var Writer = class {
15813
15813
  this.buf.set(b, this.len);
15814
15814
  this.len += b.length;
15815
15815
  }
15816
+ /** For short ASCII text, the UTF-8 length fits in the initial CBOR byte. */
15817
+ shortAscii(s) {
15818
+ this.ensure(1 + s.length);
15819
+ this.buf[this.len++] = 96 | s.length;
15820
+ for (let i = 0; i < s.length; i++) this.buf[this.len++] = s.charCodeAt(i);
15821
+ }
15816
15822
  head(major, arg) {
15817
15823
  const m2 = major << 5;
15818
15824
  if (typeof arg === "number" && arg < 24) {
@@ -15891,6 +15897,7 @@ function encodeMap(w, m2, depth) {
15891
15897
  }
15892
15898
  }
15893
15899
  function encodeText(w, s) {
15900
+ if (s.length < 24 && !/[^\x00-\x7f]/u.test(s)) return w.shortAscii(s);
15894
15901
  if (!isWellFormed(s)) throw new CborError("utf8", "text is not well-formed UTF-16");
15895
15902
  const b = textEncoder.encode(s);
15896
15903
  try {
@@ -16125,9 +16132,10 @@ function structMap(entries) {
16125
16132
  for (const [k, v] of entries) if (v !== void 0) m2.set(k, v);
16126
16133
  return m2;
16127
16134
  }
16135
+ var hexBytes = Array.from({ length: 256 }, (_, n) => n.toString(16).padStart(2, "0"));
16128
16136
  function toHex(b) {
16129
16137
  let s = "";
16130
- for (const x of b) s += x.toString(16).padStart(2, "0");
16138
+ for (const x of b) s += hexBytes[x];
16131
16139
  return s;
16132
16140
  }
16133
16141
  function fromHex(s) {
@@ -19289,6 +19297,12 @@ function timeout(value2) {
19289
19297
  }
19290
19298
 
19291
19299
  // src/records/session.ts
19300
+ function matches(record3, key3, value2) {
19301
+ if (key3 === null) return value2 === record3.body;
19302
+ const actual = fieldOf(record3.frontmatter, key3);
19303
+ if (actual === void 0 || value2 === void 0) return actual === value2;
19304
+ return equal2(toValue(actual), toValue(toPlain(value2)));
19305
+ }
19292
19306
  var RecordSessionImpl = class {
19293
19307
  constructor(client, record3, reserve) {
19294
19308
  this.client = client;
@@ -19296,7 +19310,7 @@ var RecordSessionImpl = class {
19296
19310
  complete(record3);
19297
19311
  this.base = copy(record3);
19298
19312
  this.body = record3.body;
19299
- this.state = isProtected(record3) ? "conflict" : resting(record3);
19313
+ this.state = isProtected(record3) ? "conflict" : this.restState;
19300
19314
  this.publish();
19301
19315
  }
19302
19316
  client;
@@ -19306,6 +19320,8 @@ var RecordSessionImpl = class {
19306
19320
  patch = /* @__PURE__ */ new Map();
19307
19321
  remote = null;
19308
19322
  captured = null;
19323
+ pendingEdits = /* @__PURE__ */ new Map();
19324
+ driveGeneration = 0;
19309
19325
  lastReceipt = null;
19310
19326
  state;
19311
19327
  why = null;
@@ -19346,6 +19362,24 @@ var RecordSessionImpl = class {
19346
19362
  recovery: { ...hint, receipt: null, write: null }
19347
19363
  };
19348
19364
  }
19365
+ if (!this.active && !hint && this.base.state.state === "pending" && !this.pendingEdits.size) {
19366
+ const edits = /* @__PURE__ */ new Map();
19367
+ for (const { ops, receipt: receipt3 } of await this.client.pendingWrites({ signal })) {
19368
+ for (const op2 of ops) {
19369
+ if (op2.kind !== "update" || op2.id !== this.id) continue;
19370
+ const mutation2 = receipt3.mutation;
19371
+ if (op2.body !== void 0 || op2.bodyEdits?.length) {
19372
+ const body = op2.body ?? receipt3.records?.find((record3) => record3.id === this.id)?.body ?? this.base.body;
19373
+ edits.set(null, { mutation: mutation2, value: body });
19374
+ }
19375
+ for (const [key3, value2] of Object.entries(op2.patch ?? {}))
19376
+ edits.set(key3, { mutation: mutation2, value: toValue(value2) });
19377
+ for (const key3 of op2.unset ?? []) edits.set(key3, { mutation: mutation2, value: void 0 });
19378
+ }
19379
+ }
19380
+ this.charge(this.body, this.patch, this.base, this.remote, this.lastReceipt, this.captured, edits);
19381
+ this.pendingEdits = edits;
19382
+ }
19349
19383
  signal?.throwIfAborted();
19350
19384
  if (this.captured) {
19351
19385
  this.state = "recovery";
@@ -19363,8 +19397,11 @@ var RecordSessionImpl = class {
19363
19397
  get dirty() {
19364
19398
  return this.body !== this.base.body || this.patch.size > 0;
19365
19399
  }
19400
+ get restState() {
19401
+ return !this.pendingEdits.size && confirmed(this.base) ? "saved" : "saved_on_device";
19402
+ }
19366
19403
  get retained() {
19367
- return this.dirty || this.captured !== null || !confirmed(this.base);
19404
+ return this.dirty || this.captured !== null || this.pendingEdits.size > 0 || !confirmed(this.base);
19368
19405
  }
19369
19406
  getSnapshot = () => this.snapshot;
19370
19407
  subscribe = (listener) => {
@@ -19414,13 +19451,13 @@ var RecordSessionImpl = class {
19414
19451
  };
19415
19452
  edited() {
19416
19453
  if (!this.captured && this.state !== "conflict" && this.state !== "deleted") {
19417
- this.state = this.dirty ? "unsaved" : resting(this.base);
19454
+ this.state = this.dirty ? "unsaved" : this.restState;
19418
19455
  this.why = null;
19419
19456
  }
19420
19457
  this.publish();
19421
19458
  this.schedule();
19422
19459
  }
19423
- charge(body = this.body, patch = this.patch, base = this.base, remote = this.remote, receipt3 = this.lastReceipt, captured = this.captured) {
19460
+ charge(body = this.body, patch = this.patch, base = this.base, remote = this.remote, receipt3 = this.lastReceipt, captured = this.captured, pendingEdits = this.pendingEdits) {
19424
19461
  let bytes10 = retainedBytes(base) + textBytes(body) + encode(new Map([...patch].map(([k, v]) => [k, v ?? null]))).byteLength * 2;
19425
19462
  if (remote) bytes10 += retainedBytes(remote);
19426
19463
  if (captured)
@@ -19429,6 +19466,8 @@ var RecordSessionImpl = class {
19429
19466
  [...captured.patch].map(([k, v]) => [k, v ?? null])
19430
19467
  )
19431
19468
  ).byteLength * 2;
19469
+ for (const [key3, edit] of pendingEdits)
19470
+ bytes10 += encode([key3, edit.mutation, edit.value ?? null]).byteLength * 2;
19432
19471
  if (receipt3) bytes10 += retainedBytes(receipt3);
19433
19472
  this.reserve(bytes10);
19434
19473
  }
@@ -19479,6 +19518,73 @@ var RecordSessionImpl = class {
19479
19518
  complete(record3, this.id);
19480
19519
  return record3;
19481
19520
  }
19521
+ /** The projection can change after either a refusal or a successful write
19522
+ * followed by a peer edit. Only the original MID distinguishes them. */
19523
+ async readWithReceipts(signal) {
19524
+ const receipts = /* @__PURE__ */ new Map();
19525
+ for (; ; ) {
19526
+ const current2 = await this.read(signal);
19527
+ if (this.captured) return { current: current2, receipts };
19528
+ const count = receipts.size;
19529
+ for (const [key3, { mutation: mutation2, value: value2 }] of this.pendingEdits) {
19530
+ const present = matches(current2, key3, value2);
19531
+ if (!confirmed(current2) && present) continue;
19532
+ if (!receipts.has(mutation2)) {
19533
+ const receipt4 = await this.client.receipt(mutation2, { signal });
19534
+ signal.throwIfAborted();
19535
+ if (receipt4.mutation !== mutation2)
19536
+ throw refusal("outcome_unknown", "native receipt changed identity", "mutation_identity_mismatch");
19537
+ receipts.set(mutation2, receipt4);
19538
+ }
19539
+ const receipt3 = receipts.get(mutation2);
19540
+ if (receipt3.state === "unknown" || receipt3.state === "pending" && !present)
19541
+ throw refusal("outcome_unknown", "the projection does not qualify this device write yet", "unqualified_readback");
19542
+ }
19543
+ if (receipts.size === count) return { current: current2, receipts };
19544
+ }
19545
+ }
19546
+ /** Restore only a refused write's missing edits. Newer typing and field
19547
+ * edits win, including an explicit unset; unrelated remote fields survive. */
19548
+ reconcilePending(current2, receipts) {
19549
+ if (!receipts.size) return;
19550
+ const remaining = new Map(this.pendingEdits);
19551
+ const patch = new Map(this.patch);
19552
+ const bodyEdited = this.body !== this.base.body;
19553
+ let body = bodyEdited ? this.body : current2.body;
19554
+ let rolledBack = false;
19555
+ for (const [key3, { mutation: mutation2, value: value2 }] of this.pendingEdits) {
19556
+ const receipt3 = receipts.get(mutation2);
19557
+ if (!receipt3 || receipt3.state === "pending" || receipt3.state === "unknown") continue;
19558
+ remaining.delete(key3);
19559
+ if (receipt3.state !== "rejected" && receipt3.status !== "conflicted" || matches(current2, key3, value2)) continue;
19560
+ rolledBack = true;
19561
+ if (key3 === null) {
19562
+ if (!bodyEdited) body = value2;
19563
+ } else if (!patch.has(key3)) {
19564
+ patch.set(key3, value2);
19565
+ }
19566
+ }
19567
+ const last = this.lastReceipt && (receipts.get(this.lastReceipt.mutation) ?? this.lastReceipt);
19568
+ if (rolledBack) {
19569
+ for (const [key3, value2] of patch) {
19570
+ if (matches(current2, key3, value2)) patch.delete(key3);
19571
+ }
19572
+ const differs = body !== current2.body || patch.size > 0;
19573
+ this.charge(body, patch, current2, differs ? current2 : null, last, this.captured, remaining);
19574
+ this.base = copy(current2);
19575
+ this.remote = differs ? copy(current2) : null;
19576
+ this.body = body;
19577
+ this.patch = patch;
19578
+ if (differs) {
19579
+ this.state = "conflict";
19580
+ this.why = refusal("conflict", "a device write was refused at head", "record_session_conflict").toProblem();
19581
+ }
19582
+ } else {
19583
+ this.charge(this.body, this.patch, this.base, this.remote, last, this.captured, remaining);
19584
+ }
19585
+ this.pendingEdits = remaining;
19586
+ this.lastReceipt = last;
19587
+ }
19482
19588
  /** Native change notifications are hints only; hydrate the same UUID. */
19483
19589
  refresh = () => {
19484
19590
  if (!this.active) return Promise.resolve();
@@ -19490,20 +19596,26 @@ var RecordSessionImpl = class {
19490
19596
  this.refreshRunning = (async () => {
19491
19597
  do {
19492
19598
  this.refreshAgain = false;
19599
+ const generation = this.driveGeneration;
19493
19600
  try {
19494
- const current2 = await this.read(signal);
19601
+ const { current: current2, receipts } = await this.readWithReceipts(signal);
19602
+ if (generation !== this.driveGeneration) {
19603
+ this.refreshAgain = true;
19604
+ continue;
19605
+ }
19495
19606
  if (this.captured || this.running) {
19496
19607
  if (this.captured && !this.running)
19497
19608
  void this.start(false, {}).catch(() => {
19498
19609
  });
19499
19610
  continue;
19500
19611
  }
19612
+ this.reconcilePending(current2, receipts);
19501
19613
  this.charge(this.body, this.patch, this.base, current2);
19502
19614
  if (!this.dirty) {
19503
19615
  this.base = copy(current2);
19504
19616
  this.body = current2.body;
19505
19617
  this.remote = null;
19506
- this.state = isProtected(current2) ? "conflict" : resting(current2);
19618
+ this.state = isProtected(current2) ? "conflict" : this.restState;
19507
19619
  this.why = null;
19508
19620
  } else if (current2.revision !== this.base.revision || isProtected(current2)) {
19509
19621
  this.remote = copy(current2);
@@ -19517,6 +19629,10 @@ var RecordSessionImpl = class {
19517
19629
  this.publish();
19518
19630
  } catch (error4) {
19519
19631
  if (signal.aborted) return;
19632
+ if (generation !== this.driveGeneration || this.running) {
19633
+ this.refreshAgain = !this.running;
19634
+ continue;
19635
+ }
19520
19636
  this.why = problem2(error4);
19521
19637
  this.state = this.why.code === "not_found" ? "deleted" : this.captured ? "recovery" : "error";
19522
19638
  this.publish();
@@ -19557,8 +19673,12 @@ var RecordSessionImpl = class {
19557
19673
  until: Date.now() + duration,
19558
19674
  margin: Math.min(2e3, Math.floor(duration / 4))
19559
19675
  };
19560
- const drive = () => this.drive(signal, budget, write);
19676
+ const drive = () => {
19677
+ this.driveGeneration++;
19678
+ return this.drive(signal, budget, write);
19679
+ };
19561
19680
  const run2 = (prior ? prior.then(drive, drive) : drive()).finally(() => {
19681
+ this.driveGeneration++;
19562
19682
  limit.clear();
19563
19683
  if (this.running !== run2) return;
19564
19684
  this.running = null;
@@ -19578,12 +19698,13 @@ var RecordSessionImpl = class {
19578
19698
  continue;
19579
19699
  }
19580
19700
  if (!submit)
19581
- return confirmed(this.base) ? { ok: true, record: copy(this.base) } : {
19701
+ return this.restState === "saved" ? { ok: true, record: copy(this.base) } : {
19582
19702
  ok: true,
19583
19703
  record: copy(this.base),
19584
19704
  saved: "on_device"
19585
19705
  };
19586
- const current2 = await this.read(signal);
19706
+ const { current: current2, receipts } = await this.readWithReceipts(signal);
19707
+ this.reconcilePending(current2, receipts);
19587
19708
  if (isProtected(current2)) {
19588
19709
  this.charge(this.body, this.patch, this.base, current2);
19589
19710
  this.remote = copy(current2);
@@ -19604,10 +19725,10 @@ var RecordSessionImpl = class {
19604
19725
  this.base = copy(current2);
19605
19726
  this.body = current2.body;
19606
19727
  this.remote = null;
19607
- this.state = resting(current2);
19728
+ this.state = this.restState;
19608
19729
  this.why = null;
19609
19730
  this.publish();
19610
- return confirmed(current2) ? { ok: true, record: copy(current2) } : { ok: true, record: copy(current2), saved: "on_device" };
19731
+ return this.restState === "saved" ? { ok: true, record: copy(current2) } : { ok: true, record: copy(current2), saved: "on_device" };
19611
19732
  }
19612
19733
  if (current2.revision !== this.base.revision || this.state === "conflict") {
19613
19734
  this.charge(this.body, this.patch, this.base, current2);
@@ -19743,14 +19864,23 @@ var RecordSessionImpl = class {
19743
19864
  }
19744
19865
  const current2 = await this.read(signal);
19745
19866
  const kept = receipt3.state === "pending";
19746
- if (kept ? isProtected(current2) : !confirmed(current2))
19867
+ const edits = new Map(this.pendingEdits);
19868
+ const submitted = new Map(captured.patch);
19869
+ if (captured.body !== this.base.body) submitted.set(null, captured.body);
19870
+ for (const [key3, value2] of submitted) {
19871
+ if (kept) edits.set(key3, { mutation: receipt3.mutation, value: value2 });
19872
+ else edits.delete(key3);
19873
+ }
19874
+ if (kept ? isProtected(current2) || [...submitted].some(([key3, value2]) => !matches(current2, key3, value2)) : !confirmed(current2))
19747
19875
  throw refusal(
19748
19876
  "outcome_unknown",
19749
- "confirmed receipt has pending/protected current readback",
19877
+ "record readback does not qualify the native receipt",
19750
19878
  "unqualified_readback"
19751
19879
  );
19752
- this.charge(this.body, this.patch, current2, null);
19753
19880
  const sameBody = this.body === captured.body;
19881
+ const conflict2 = !kept && !sameBody && current2.body !== captured.body && current2.body !== this.body;
19882
+ this.charge(this.body, this.patch, current2, conflict2 ? current2 : null, receipt3, null, edits);
19883
+ this.pendingEdits = edits;
19754
19884
  for (const [key3, value2] of captured.patch) {
19755
19885
  const latest = this.patch.get(key3);
19756
19886
  if (this.patch.has(key3) && (value2 === void 0 ? latest === void 0 : latest !== void 0 && equal2(value2, latest)))
@@ -19759,8 +19889,10 @@ var RecordSessionImpl = class {
19759
19889
  this.base = copy(current2);
19760
19890
  if (sameBody) this.body = current2.body;
19761
19891
  this.captured = null;
19762
- this.remote = null;
19763
- this.state = this.dirty ? "unsaved" : resting(current2);
19892
+ this.remote = conflict2 ? copy(current2) : null;
19893
+ if (conflict2)
19894
+ throw refusal("conflict", "record body changed while saving an earlier draft", "record_session_conflict");
19895
+ this.state = this.dirty ? "unsaved" : this.restState;
19764
19896
  this.why = null;
19765
19897
  this.publish();
19766
19898
  }
@@ -19779,7 +19911,7 @@ var RecordSessionImpl = class {
19779
19911
  "a confirmed unprotected native record is required for resolution",
19780
19912
  "native_protection_resolution_required"
19781
19913
  );
19782
- const body = "body" in choice ? choice.body : choice.keep === "theirs" ? remote.body : this.body;
19914
+ const body = "body" in choice ? choice.body : choice.keep === "theirs" || this.body === this.base.body ? remote.body : this.body;
19783
19915
  const patch = "keep" in choice && choice.keep === "theirs" ? /* @__PURE__ */ new Map() : this.patch;
19784
19916
  this.charge(body, patch, remote, null);
19785
19917
  this.base = copy(remote);
@@ -19792,9 +19924,6 @@ var RecordSessionImpl = class {
19792
19924
  this.schedule();
19793
19925
  };
19794
19926
  };
19795
- function resting(record3) {
19796
- return confirmed(record3) ? "saved" : "saved_on_device";
19797
- }
19798
19927
  function equal2(a, b) {
19799
19928
  const x = encode(a), y = encode(b);
19800
19929
  return x.length === y.length && x.every((v, i) => v === y[i]);
@@ -40588,9 +40717,9 @@ var SqliteIndex = class _SqliteIndex {
40588
40717
  }
40589
40718
  });
40590
40719
  }
40591
- column(st, i) {
40720
+ column(st, i, tag) {
40592
40721
  const capi = this.sqlite3.capi;
40593
- switch (capi.sqlite3_column_type(st.pointer, i)) {
40722
+ switch (tag) {
40594
40723
  case SQLITE_NULL:
40595
40724
  return { kind: "Null" };
40596
40725
  case SQLITE_INTEGER: {
@@ -40644,9 +40773,9 @@ var SqliteIndex = class _SqliteIndex {
40644
40773
  while (st.step()) {
40645
40774
  if (limits && ++rows2 > limits.maxRows) throw new IndexError("Full", "index reply row budget exceeded");
40646
40775
  for (let c = 0; c < columns; c++) {
40776
+ if (limits && ++valueCount > limits.maxValues) throw new IndexError("Full", "index reply value budget exceeded");
40777
+ const tag = capi.sqlite3_column_type(st.pointer, c);
40647
40778
  if (limits) {
40648
- if (++valueCount > limits.maxValues) throw new IndexError("Full", "index reply value budget exceeded");
40649
- const tag = capi.sqlite3_column_type(st.pointer, c);
40650
40779
  if (tag === SQLITE_TEXT || tag === SQLITE_BLOB) {
40651
40780
  addBytes(5);
40652
40781
  addBytes(capi.sqlite3_column_bytes(st.pointer, c));
@@ -40654,7 +40783,7 @@ var SqliteIndex = class _SqliteIndex {
40654
40783
  else if (tag === SQLITE_NULL) addBytes(1);
40655
40784
  else throw new IndexError("Other", "unknown SQLite value type");
40656
40785
  }
40657
- values.push(this.column(st, c));
40786
+ values.push(this.column(st, c, tag));
40658
40787
  }
40659
40788
  }
40660
40789
  out.push({
@@ -40817,33 +40946,46 @@ function request2(bytes10) {
40817
40946
  return { mode: mode === 0 ? "Transaction" : "Autocommit", stmts };
40818
40947
  }
40819
40948
  var Writer2 = class {
40820
- parts = [];
40949
+ bytes = new Uint8Array(128);
40950
+ view = new DataView(this.bytes.buffer);
40821
40951
  length = 0;
40822
40952
  values = 0;
40823
40953
  constructor(op2) {
40824
40954
  this.put(MAGIC);
40825
40955
  this.byte(op2);
40826
40956
  }
40957
+ reserve(size2) {
40958
+ const start = this.length;
40959
+ const end = start + size2;
40960
+ if (end > APP_INDEX_LIMITS.maxBytes) throw full();
40961
+ if (end > this.bytes.length) {
40962
+ const capacity = Math.min(APP_INDEX_LIMITS.maxBytes, Math.max(end, this.bytes.length * 2));
40963
+ const next = new Uint8Array(capacity);
40964
+ next.set(this.bytes.subarray(0, start));
40965
+ this.bytes = next;
40966
+ this.view = new DataView(next.buffer);
40967
+ }
40968
+ this.length = end;
40969
+ return start;
40970
+ }
40827
40971
  put(b) {
40828
- if (b.length > APP_INDEX_LIMITS.maxBytes - this.length) throw full();
40829
- this.length += b.length;
40830
- this.parts.push(b);
40972
+ const at = this.reserve(b.length);
40973
+ this.bytes.set(b, at);
40831
40974
  }
40832
40975
  byte(n) {
40833
- this.put(Uint8Array.of(n));
40976
+ const at = this.reserve(1);
40977
+ this.bytes[at] = n;
40834
40978
  }
40835
40979
  u32(n) {
40836
40980
  if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295) throw invalid5();
40837
- const b = new Uint8Array(4);
40838
- new DataView(b.buffer).setUint32(0, n, true);
40839
- this.put(b);
40981
+ const at = this.reserve(4);
40982
+ this.view.setUint32(at, n, true);
40840
40983
  }
40841
40984
  int(n, signed) {
40842
40985
  if (typeof n !== "bigint" || n < (signed ? I64_MIN2 : 0n) || n > (signed ? I64_MAX : U64_MAX2)) throw invalid5();
40843
- const b = new Uint8Array(8), v = new DataView(b.buffer);
40844
- if (signed) v.setBigInt64(0, n, true);
40845
- else v.setBigUint64(0, n, true);
40846
- this.put(b);
40986
+ const at = this.reserve(8);
40987
+ if (signed) this.view.setBigInt64(at, n, true);
40988
+ else this.view.setBigUint64(at, n, true);
40847
40989
  }
40848
40990
  data(b) {
40849
40991
  this.u32(b.length);
@@ -40862,9 +41004,8 @@ var Writer2 = class {
40862
41004
  case "Real": {
40863
41005
  if (!Number.isFinite(v.value)) throw invalid5();
40864
41006
  this.byte(2);
40865
- const b = new Uint8Array(8);
40866
- new DataView(b.buffer).setFloat64(0, v.value, true);
40867
- this.put(b);
41007
+ const at = this.reserve(8);
41008
+ this.view.setFloat64(at, v.value, true);
40868
41009
  return;
40869
41010
  }
40870
41011
  case "Text":
@@ -40880,13 +41021,7 @@ var Writer2 = class {
40880
41021
  }
40881
41022
  }
40882
41023
  done() {
40883
- const out = new Uint8Array(this.length);
40884
- let at = 0;
40885
- for (const part of this.parts) {
40886
- out.set(part, at);
40887
- at += part.length;
40888
- }
40889
- return out;
41024
+ return this.bytes.slice(0, this.length);
40890
41025
  }
40891
41026
  };
40892
41027
  function results(out, expected) {
@@ -43205,10 +43340,12 @@ var ApplicationWorkerHost = class {
43205
43340
  const frame = event.data;
43206
43341
  if (Array.isArray(frame) && frame.length === 5 && frame[0] === APPLICATION_WORKER_PROTOCOL && frame[1] === client.binding && frame[2] === "nativeAuthorizationReply") {
43207
43342
  const reply = nativeAuthorizationReply(frame[4]), slot = this.nativeWait;
43343
+ if (!Number.isInteger(frame[3]) || frame[3] < 1 || frame[3] > client.lastId || reply.rpc < 1) throw new ApplicationWorkerError("application_worker_binding");
43208
43344
  if (!slot) {
43209
43345
  if (reply.rpc > this.nativeRpc) throw new ApplicationWorkerError("application_worker_binding");
43210
43346
  return;
43211
43347
  }
43348
+ if (reply.rpc < slot.rpc) return;
43212
43349
  if (slot.client !== client || slot.id !== frame[3] || slot.rpc !== reply.rpc) throw new ApplicationWorkerError("application_worker_binding");
43213
43350
  this.nativeWait = null;
43214
43351
  if (reply.ok) slot.resolve(reply.value);