@cloudbitmaps/core 0.25.0 → 0.27.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.
@@ -19,7 +19,7 @@ import {
19
19
  requirePositiveInteger,
20
20
  shown,
21
21
  tailBytesFit
22
- } from "./chunk-2B2QF4FU.js";
22
+ } from "./chunk-UUNBQVKR.js";
23
23
 
24
24
  // src/drivers/_shared/options.ts
25
25
  function checkNow(name, now) {
@@ -638,4 +638,4 @@ export {
638
638
  namespaceKeyPart,
639
639
  namespacePathPart
640
640
  };
641
- //# sourceMappingURL=chunk-45ML6YU4.js.map
641
+ //# sourceMappingURL=chunk-A2UDUKNL.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ValidationError,
3
3
  encodeNameForKey
4
- } from "./chunk-2B2QF4FU.js";
4
+ } from "./chunk-UUNBQVKR.js";
5
5
 
6
6
  // src/core/keys.ts
7
7
  var FIELD = " ";
@@ -118,4 +118,4 @@ export {
118
118
  BufferSink,
119
119
  BufferReader
120
120
  };
121
- //# sourceMappingURL=chunk-WPER7R2R.js.map
121
+ //# sourceMappingURL=chunk-KO3Z2RBA.js.map
@@ -790,6 +790,189 @@ async function releaseLease(ref, deps, holder) {
790
790
  var PREAMBLE_BYTES = 8;
791
791
  var FOOTER_BYTES = 104;
792
792
 
793
+ // src/core/order.ts
794
+ var ascending = (a, b) => a - b;
795
+
796
+ // src/core/crbm/fingerprint.ts
797
+ var sizePart = (size) => `${size}:`;
798
+ var fingerprintFor = (size, footerCrc) => `${sizePart(size)}${footerCrc}`;
799
+ var FINGERPRINT = /^(0|[1-9]\d*):(0|[1-9]\d*)$/;
800
+ function fingerprintParts(fingerprint) {
801
+ const match = typeof fingerprint === "string" ? FINGERPRINT.exec(fingerprint) : null;
802
+ if (match === null) return void 0;
803
+ const size = Number(match[1]);
804
+ const footerCrc = Number(match[2]);
805
+ if (!Number.isSafeInteger(size) || size < PREAMBLE_BYTES + FOOTER_BYTES) return void 0;
806
+ if (footerCrc > 4294967295) return void 0;
807
+ return { size, footerCrc };
808
+ }
809
+ function footerCrcOf(fingerprint) {
810
+ const parts = fingerprintParts(fingerprint);
811
+ if (parts === void 0) {
812
+ throw new IntegrityError(`not an object's fingerprint: ${String(fingerprint).slice(0, 64)}`);
813
+ }
814
+ return parts.footerCrc;
815
+ }
816
+ function compactFingerprint(fingerprint) {
817
+ const colon = fingerprint.indexOf(":");
818
+ const size = Number(fingerprint.slice(0, colon));
819
+ const crc = Number(fingerprint.slice(colon + 1));
820
+ return `${size.toString(36)}.${crc.toString(36)}`;
821
+ }
822
+
823
+ // src/core/known-generations.ts
824
+ var MAX_KEPT_GENERATIONS = 64;
825
+ var KNOWN_FILL = 128;
826
+ var MAX_KNOWN_GENERATIONS = 192;
827
+ var MAX_STORED_KNOWN_GENERATIONS = 384;
828
+ function usableKnownGens(record) {
829
+ const known = record?.knownGens;
830
+ if (record === null || known === void 0 || known.length === 0 || record.status !== "active" || record.currentGen === null) {
831
+ return void 0;
832
+ }
833
+ const last = known[known.length - 1];
834
+ if (last.generation !== record.currentGen) return void 0;
835
+ const summary = record.summary;
836
+ if (summary !== void 0 && summary.generation === record.currentGen && "fingerprint" in summary && fingerprintParts(summary.fingerprint)?.footerCrc !== last.footerCrc) {
837
+ return void 0;
838
+ }
839
+ return known;
840
+ }
841
+ function windowOf(record) {
842
+ const known = usableKnownGens(record);
843
+ if (known === void 0) return void 0;
844
+ const pointer = record.currentGen;
845
+ return known.filter((e) => e.generation < pointer).map((e) => e.generation);
846
+ }
847
+ function carriesWindow(record, leased) {
848
+ const below = windowOf(record);
849
+ return below !== void 0 && below.filter((g) => !leased.has(g)).length <= MAX_KEPT_GENERATIONS;
850
+ }
851
+ var KNOWN_SPAN = 127;
852
+ function keptWindow(below, superseded, keep) {
853
+ const oldestFirst = [...below].sort(ascending);
854
+ const first = keep > 0 && superseded !== void 0 && oldestFirst.includes(superseded) ? superseded : void 0;
855
+ const held = new Set(first === void 0 ? [] : [first]);
856
+ for (let i = oldestFirst.length - 1, room = keep - held.size; i >= 0 && room > 0; i--) {
857
+ if (oldestFirst[i] === first) continue;
858
+ held.add(oldestFirst[i]);
859
+ room -= 1;
860
+ }
861
+ return {
862
+ kept: oldestFirst.filter((g) => held.has(g)),
863
+ evict: oldestFirst.filter((g) => !held.has(g))
864
+ };
865
+ }
866
+ function capKnown(known, protect, leased = /* @__PURE__ */ new Set()) {
867
+ const keep = /* @__PURE__ */ new Set();
868
+ for (const e of known) if (protect.has(e.generation)) keep.add(e.generation);
869
+ for (let i = known.length - 1; i >= 0 && keep.size < MAX_KNOWN_GENERATIONS; i--) {
870
+ if (leased.has(known[i].generation)) keep.add(known[i].generation);
871
+ }
872
+ for (let i = known.length - 1; i >= 0 && keep.size < KNOWN_FILL; i--)
873
+ keep.add(known[i].generation);
874
+ return known.filter((e) => keep.has(e.generation));
875
+ }
876
+ function capInsert(known, protect, leased) {
877
+ const keep = /* @__PURE__ */ new Set();
878
+ let unleased = 0;
879
+ for (const e of known) {
880
+ if (!protect.has(e.generation)) continue;
881
+ keep.add(e.generation);
882
+ if (!leased.has(e.generation)) unleased += 1;
883
+ }
884
+ for (let i = known.length - 1; i >= 0 && unleased < KNOWN_FILL; i--) {
885
+ const g = known[i].generation;
886
+ if (keep.has(g) || leased.has(g)) continue;
887
+ keep.add(g);
888
+ unleased += 1;
889
+ }
890
+ for (let i = known.length - 1; i >= 0 && keep.size < MAX_KNOWN_GENERATIONS; i--) {
891
+ if (leased.has(known[i].generation)) keep.add(known[i].generation);
892
+ }
893
+ return known.filter((e) => keep.has(e.generation));
894
+ }
895
+ function makeCurrent(known, entry) {
896
+ return [...known.filter((e) => e.generation !== entry.generation), entry];
897
+ }
898
+ function nextKnown(prev, generation, footerCrc, keep, options = {}) {
899
+ const self = { generation, footerCrc };
900
+ const clears = options.clearsLeases === true;
901
+ const byName = keep !== void 0 && keep <= MAX_KEPT_GENERATIONS;
902
+ if (options.seed !== void 0 && !clears) {
903
+ const seed = options.seed.filter((e) => e.generation !== generation);
904
+ const protect = /* @__PURE__ */ new Set([...seed.map((e) => e.generation), generation]);
905
+ return {
906
+ known: capKnown([...seed, self], protect, options.leased ?? /* @__PURE__ */ new Set()),
907
+ list: void 0,
908
+ evict: []
909
+ };
910
+ }
911
+ const found = usableKnownGens(prev);
912
+ if (found === void 0 && prev !== null && prev.currentGen !== null) {
913
+ return { known: [self], list: void 0, evict: [] };
914
+ }
915
+ const all = found ?? [];
916
+ const below = all.filter((e) => e.generation < generation);
917
+ const above = clears ? [] : all.filter((e) => e.generation > generation);
918
+ const span = clears ? 0 : Math.min(keep ?? Number.MAX_SAFE_INTEGER, KNOWN_SPAN);
919
+ const vouch = new Set((span === 0 ? [] : below.slice(-span)).map((e) => e.generation));
920
+ const leased = clears ? /* @__PURE__ */ new Set() : options.leased ?? /* @__PURE__ */ new Set();
921
+ const held = below.filter((e) => !vouch.has(e.generation) && leased.has(e.generation));
922
+ const chosen = /* @__PURE__ */ new Set([
923
+ ...vouch,
924
+ ...held.map((e) => e.generation),
925
+ ...above.map((e) => e.generation)
926
+ ]);
927
+ const known = capKnown(
928
+ [...all.filter((e) => chosen.has(e.generation)), self],
929
+ /* @__PURE__ */ new Set([...vouch, generation]),
930
+ leased
931
+ );
932
+ const wide = !clears && found !== void 0 && !carriesWindow(prev, leased);
933
+ if (!byName || wide) return { known, list: void 0, evict: [] };
934
+ const named = new Set(known.map((e) => e.generation));
935
+ return {
936
+ known,
937
+ list: known.filter((e) => e.generation < generation).map((e) => e.generation).sort(ascending),
938
+ evict: below.filter((e) => !named.has(e.generation)).map((e) => e.generation).sort(ascending)
939
+ };
940
+ }
941
+ function rollbackKnown(prev, target) {
942
+ const found = usableKnownGens(prev);
943
+ if (found === void 0) return void 0;
944
+ const moved = makeCurrent(found, target);
945
+ const inserted = !found.some((e) => e.generation === target.generation);
946
+ if (!inserted && moved.length <= MAX_KNOWN_GENERATIONS) return moved;
947
+ return capInsert(moved, /* @__PURE__ */ new Set([target.generation, prev.currentGen]), leasedByRow(prev));
948
+ }
949
+ function sameKnownGens(a, b) {
950
+ if (a === void 0 || b === void 0) return a === b;
951
+ return a.length === b.length && a.every((e, i) => e.generation === b[i].generation && e.footerCrc === b[i].footerCrc);
952
+ }
953
+ function pruneKnown(record, doomed) {
954
+ const found = usableKnownGens(record);
955
+ if (found === void 0) return void 0;
956
+ const rest = found.filter((e) => e.generation === record.currentGen || !doomed.has(e.generation));
957
+ if (rest.length <= MAX_KNOWN_GENERATIONS) return rest;
958
+ return capKnown(rest, /* @__PURE__ */ new Set([record.currentGen]), leasedByRow(record));
959
+ }
960
+ function describingKnown(record, movedTo) {
961
+ const found = usableKnownGens(record);
962
+ if (found === void 0 || found.length <= MAX_KNOWN_GENERATIONS) return found;
963
+ return capKnown(found, /* @__PURE__ */ new Set([record.currentGen, movedTo]), leasedByRow(record));
964
+ }
965
+ function isFullLedger(known) {
966
+ return known.length >= KNOWN_FILL;
967
+ }
968
+ function fallbackBound(record, known) {
969
+ const leased = leasedByRow(record);
970
+ return (known.find((e) => !leased.has(e.generation)) ?? known[0]).generation;
971
+ }
972
+ function leasedByRow(record) {
973
+ return new Set((record.leases ?? []).map((e) => e.generation));
974
+ }
975
+
793
976
  // src/core/metadata.ts
794
977
  var MAX_METADATA_BYTES = 1024;
795
978
  var MAX_METADATA_KEY_BYTES = 128;
@@ -870,33 +1053,6 @@ function metadataFromBytes(bytes, fail) {
870
1053
  return Object.freeze(parsed);
871
1054
  }
872
1055
 
873
- // src/core/crbm/fingerprint.ts
874
- var sizePart = (size) => `${size}:`;
875
- var fingerprintFor = (size, footerCrc) => `${sizePart(size)}${footerCrc}`;
876
- var FINGERPRINT = /^(0|[1-9]\d*):(0|[1-9]\d*)$/;
877
- function fingerprintParts(fingerprint) {
878
- const match = typeof fingerprint === "string" ? FINGERPRINT.exec(fingerprint) : null;
879
- if (match === null) return void 0;
880
- const size = Number(match[1]);
881
- const footerCrc = Number(match[2]);
882
- if (!Number.isSafeInteger(size) || size < PREAMBLE_BYTES + FOOTER_BYTES) return void 0;
883
- if (footerCrc > 4294967295) return void 0;
884
- return { size, footerCrc };
885
- }
886
- function footerCrcOf(fingerprint) {
887
- const parts = fingerprintParts(fingerprint);
888
- if (parts === void 0) {
889
- throw new IntegrityError(`not an object's fingerprint: ${String(fingerprint).slice(0, 64)}`);
890
- }
891
- return parts.footerCrc;
892
- }
893
- function compactFingerprint(fingerprint) {
894
- const colon = fingerprint.indexOf(":");
895
- const size = Number(fingerprint.slice(0, colon));
896
- const crc = Number(fingerprint.slice(colon + 1));
897
- return `${size.toString(36)}.${crc.toString(36)}`;
898
- }
899
-
900
1056
  // src/core/summary.ts
901
1057
  var NONCE_BYTES = 12;
902
1058
  var TAG_BYTES = 16;
@@ -1064,162 +1220,6 @@ function ownSummary(ref, generation, description, aead) {
1064
1220
  return summary;
1065
1221
  }
1066
1222
 
1067
- // src/core/order.ts
1068
- var ascending = (a, b) => a - b;
1069
-
1070
- // src/core/known-generations.ts
1071
- var MAX_KEPT_GENERATIONS = 64;
1072
- var KNOWN_FILL = 128;
1073
- var MAX_KNOWN_GENERATIONS = 192;
1074
- var MAX_STORED_KNOWN_GENERATIONS = 384;
1075
- function usableKnownGens(record) {
1076
- const known = record?.knownGens;
1077
- if (record === null || known === void 0 || known.length === 0 || record.status !== "active" || record.currentGen === null) {
1078
- return void 0;
1079
- }
1080
- const last = known[known.length - 1];
1081
- if (last.generation !== record.currentGen) return void 0;
1082
- const summary = record.summary;
1083
- if (summary !== void 0 && summary.generation === record.currentGen && "fingerprint" in summary && fingerprintParts(summary.fingerprint)?.footerCrc !== last.footerCrc) {
1084
- return void 0;
1085
- }
1086
- return known;
1087
- }
1088
- function windowOf(record) {
1089
- const known = usableKnownGens(record);
1090
- if (known === void 0) return void 0;
1091
- const pointer = record.currentGen;
1092
- return known.filter((e) => e.generation < pointer).map((e) => e.generation);
1093
- }
1094
- function carriesWindow(record, leased) {
1095
- const below = windowOf(record);
1096
- return below !== void 0 && below.filter((g) => !leased.has(g)).length <= MAX_KEPT_GENERATIONS;
1097
- }
1098
- var KNOWN_SPAN = 127;
1099
- function keptWindow(below, superseded, keep) {
1100
- const oldestFirst = [...below].sort(ascending);
1101
- const first = keep > 0 && superseded !== void 0 && oldestFirst.includes(superseded) ? superseded : void 0;
1102
- const held = new Set(first === void 0 ? [] : [first]);
1103
- for (let i = oldestFirst.length - 1, room = keep - held.size; i >= 0 && room > 0; i--) {
1104
- if (oldestFirst[i] === first) continue;
1105
- held.add(oldestFirst[i]);
1106
- room -= 1;
1107
- }
1108
- return {
1109
- kept: oldestFirst.filter((g) => held.has(g)),
1110
- evict: oldestFirst.filter((g) => !held.has(g))
1111
- };
1112
- }
1113
- function capKnown(known, protect, leased = /* @__PURE__ */ new Set()) {
1114
- const keep = /* @__PURE__ */ new Set();
1115
- for (const e of known) if (protect.has(e.generation)) keep.add(e.generation);
1116
- for (let i = known.length - 1; i >= 0 && keep.size < MAX_KNOWN_GENERATIONS; i--) {
1117
- if (leased.has(known[i].generation)) keep.add(known[i].generation);
1118
- }
1119
- for (let i = known.length - 1; i >= 0 && keep.size < KNOWN_FILL; i--)
1120
- keep.add(known[i].generation);
1121
- return known.filter((e) => keep.has(e.generation));
1122
- }
1123
- function capInsert(known, protect, leased) {
1124
- const keep = /* @__PURE__ */ new Set();
1125
- let unleased = 0;
1126
- for (const e of known) {
1127
- if (!protect.has(e.generation)) continue;
1128
- keep.add(e.generation);
1129
- if (!leased.has(e.generation)) unleased += 1;
1130
- }
1131
- for (let i = known.length - 1; i >= 0 && unleased < KNOWN_FILL; i--) {
1132
- const g = known[i].generation;
1133
- if (keep.has(g) || leased.has(g)) continue;
1134
- keep.add(g);
1135
- unleased += 1;
1136
- }
1137
- for (let i = known.length - 1; i >= 0 && keep.size < MAX_KNOWN_GENERATIONS; i--) {
1138
- if (leased.has(known[i].generation)) keep.add(known[i].generation);
1139
- }
1140
- return known.filter((e) => keep.has(e.generation));
1141
- }
1142
- function makeCurrent(known, entry) {
1143
- return [...known.filter((e) => e.generation !== entry.generation), entry];
1144
- }
1145
- function nextKnown(prev, generation, footerCrc, keep, options = {}) {
1146
- const self = { generation, footerCrc };
1147
- const clears = options.clearsLeases === true;
1148
- const byName = keep !== void 0 && keep <= MAX_KEPT_GENERATIONS;
1149
- if (options.seed !== void 0 && !clears) {
1150
- const seed = options.seed.filter((e) => e.generation !== generation);
1151
- const protect = /* @__PURE__ */ new Set([...seed.map((e) => e.generation), generation]);
1152
- return {
1153
- known: capKnown([...seed, self], protect, options.leased ?? /* @__PURE__ */ new Set()),
1154
- list: void 0,
1155
- evict: []
1156
- };
1157
- }
1158
- const found = usableKnownGens(prev);
1159
- if (found === void 0 && prev !== null && prev.currentGen !== null) {
1160
- return { known: [self], list: void 0, evict: [] };
1161
- }
1162
- const all = found ?? [];
1163
- const below = all.filter((e) => e.generation < generation);
1164
- const above = clears ? [] : all.filter((e) => e.generation > generation);
1165
- const span = clears ? 0 : Math.min(keep ?? Number.MAX_SAFE_INTEGER, KNOWN_SPAN);
1166
- const vouch = new Set((span === 0 ? [] : below.slice(-span)).map((e) => e.generation));
1167
- const leased = clears ? /* @__PURE__ */ new Set() : options.leased ?? /* @__PURE__ */ new Set();
1168
- const held = below.filter((e) => !vouch.has(e.generation) && leased.has(e.generation));
1169
- const chosen = /* @__PURE__ */ new Set([
1170
- ...vouch,
1171
- ...held.map((e) => e.generation),
1172
- ...above.map((e) => e.generation)
1173
- ]);
1174
- const known = capKnown(
1175
- [...all.filter((e) => chosen.has(e.generation)), self],
1176
- /* @__PURE__ */ new Set([...vouch, generation]),
1177
- leased
1178
- );
1179
- const wide = !clears && found !== void 0 && !carriesWindow(prev, leased);
1180
- if (!byName || wide) return { known, list: void 0, evict: [] };
1181
- const named = new Set(known.map((e) => e.generation));
1182
- return {
1183
- known,
1184
- list: known.filter((e) => e.generation < generation).map((e) => e.generation).sort(ascending),
1185
- evict: below.filter((e) => !named.has(e.generation)).map((e) => e.generation).sort(ascending)
1186
- };
1187
- }
1188
- function rollbackKnown(prev, target) {
1189
- const found = usableKnownGens(prev);
1190
- if (found === void 0) return void 0;
1191
- const moved = makeCurrent(found, target);
1192
- const inserted = !found.some((e) => e.generation === target.generation);
1193
- if (!inserted && moved.length <= MAX_KNOWN_GENERATIONS) return moved;
1194
- return capInsert(moved, /* @__PURE__ */ new Set([target.generation, prev.currentGen]), leasedByRow(prev));
1195
- }
1196
- function sameKnownGens(a, b) {
1197
- if (a === void 0 || b === void 0) return a === b;
1198
- return a.length === b.length && a.every((e, i) => e.generation === b[i].generation && e.footerCrc === b[i].footerCrc);
1199
- }
1200
- function pruneKnown(record, doomed) {
1201
- const found = usableKnownGens(record);
1202
- if (found === void 0) return void 0;
1203
- const rest = found.filter((e) => e.generation === record.currentGen || !doomed.has(e.generation));
1204
- if (rest.length <= MAX_KNOWN_GENERATIONS) return rest;
1205
- return capKnown(rest, /* @__PURE__ */ new Set([record.currentGen]), leasedByRow(record));
1206
- }
1207
- function describingKnown(record, movedTo) {
1208
- const found = usableKnownGens(record);
1209
- if (found === void 0 || found.length <= MAX_KNOWN_GENERATIONS) return found;
1210
- return capKnown(found, /* @__PURE__ */ new Set([record.currentGen, movedTo]), leasedByRow(record));
1211
- }
1212
- function isFullLedger(known) {
1213
- return known.length >= KNOWN_FILL;
1214
- }
1215
- function fallbackBound(record, known) {
1216
- const leased = leasedByRow(record);
1217
- return (known.find((e) => !leased.has(e.generation)) ?? known[0]).generation;
1218
- }
1219
- function leasedByRow(record) {
1220
- return new Set((record.leases ?? []).map((e) => e.generation));
1221
- }
1222
-
1223
1223
  // src/core/known-generations-shape.ts
1224
1224
  var ENTRY_KEYS = ["generation", "footerCrc"];
1225
1225
  function knownGensShapeFault(value, max, show = String) {
@@ -1319,6 +1319,25 @@ export {
1319
1319
  renewPointer,
1320
1320
  pointerIdOf,
1321
1321
  pointerSetBy,
1322
+ ascending,
1323
+ sizePart,
1324
+ fingerprintFor,
1325
+ fingerprintParts,
1326
+ footerCrcOf,
1327
+ compactFingerprint,
1328
+ MAX_KNOWN_GENERATIONS,
1329
+ MAX_STORED_KNOWN_GENERATIONS,
1330
+ usableKnownGens,
1331
+ windowOf,
1332
+ KNOWN_SPAN,
1333
+ keptWindow,
1334
+ nextKnown,
1335
+ rollbackKnown,
1336
+ sameKnownGens,
1337
+ pruneKnown,
1338
+ describingKnown,
1339
+ isFullLedger,
1340
+ fallbackBound,
1322
1341
  aadFor,
1323
1342
  sameKeys,
1324
1343
  MAX_METADATA_BYTES,
@@ -1326,11 +1345,6 @@ export {
1326
1345
  metadataBytes,
1327
1346
  copiedMetadata,
1328
1347
  metadataFromBytes,
1329
- sizePart,
1330
- fingerprintFor,
1331
- fingerprintParts,
1332
- footerCrcOf,
1333
- compactFingerprint,
1334
1348
  MAX_SUMMARY_CARDINALITY,
1335
1349
  tailBytesFit,
1336
1350
  sizeOfFingerprint,
@@ -1339,7 +1353,6 @@ export {
1339
1353
  metadataToCarry,
1340
1354
  summaryOf,
1341
1355
  ownSummary,
1342
- ascending,
1343
1356
  DEFAULT_RETRY_POLICY,
1344
1357
  jitteredWait,
1345
1358
  retryRead,
@@ -1357,19 +1370,6 @@ export {
1357
1370
  leaseChurn,
1358
1371
  takeLease,
1359
1372
  releaseLease,
1360
- MAX_KNOWN_GENERATIONS,
1361
- MAX_STORED_KNOWN_GENERATIONS,
1362
- usableKnownGens,
1363
- windowOf,
1364
- KNOWN_SPAN,
1365
- keptWindow,
1366
- nextKnown,
1367
- rollbackKnown,
1368
- sameKnownGens,
1369
- pruneKnown,
1370
- describingKnown,
1371
- isFullLedger,
1372
- fallbackBound,
1373
1373
  knownGensShapeFault
1374
1374
  };
1375
- //# sourceMappingURL=chunk-2B2QF4FU.js.map
1375
+ //# sourceMappingURL=chunk-UUNBQVKR.js.map