msgpackr 1.11.13 → 1.12.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/index.js CHANGED
@@ -1295,7 +1295,13 @@
1295
1295
  hasSharedUpdate = false;
1296
1296
  let encodingError;
1297
1297
  try {
1298
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1298
+ // readOnlyStructures: skip the random-access struct write path so NO new struct is
1299
+ // minted. randomAccessStructure stays true (the struct READ path and the struct-safe
1300
+ // integer boundary are preserved, so existing struct data still decodes), but objects
1301
+ // fall through to the normal pack()->writeObject->writeRecord path and are written as
1302
+ // classic shared-structure records (byte range 0x40-0x7f, disjoint from struct headers
1303
+ // at 0x20-0x3f) — the bounded, width-agnostic encoding used before struct mode.
1304
+ if (packr.randomAccessStructure && !packr.readOnlyStructures && value && typeof value === 'object') {
1299
1305
  if (value.constructor === Object) writeStruct(value); // simple object
1300
1306
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1301
1307
  // allow user classes, if they don't need special handling (but do use toJSON if available)
@@ -1361,7 +1367,14 @@
1361
1367
  let newSharedData = prepareStructures(structures, packr);
1362
1368
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1363
1369
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1364
- // get updated structures and try again if the update failed
1370
+ // The save was declined (a concurrent writer updated the shared structures,
1371
+ // or the store transaction did not durably commit). Our in-memory
1372
+ // structures + transition trie may now reference record ids that were
1373
+ // never persisted; re-packing as-is would re-emit the same record pointing
1374
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
1375
+ // Mark structures uninitialized so the re-pack reloads durable structures
1376
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
1377
+ structures.uninitialized = true;
1365
1378
  return packr.pack(value, encodeOptions)
1366
1379
  }
1367
1380
  packr.lastNamedStructuresLength = sharedLength;