@klum-db/lobby 0.2.0-pre.33 → 0.4.0-pre.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.cjs CHANGED
@@ -72,6 +72,11 @@ function encodeMultiBundle(manifest, inner) {
72
72
  }
73
73
  return out;
74
74
  }
75
+ function hasPodMagic(bytes) {
76
+ if (bytes.length < import_pod.NOYDB_BUNDLE_MAGIC.length) return false;
77
+ for (let i = 0; i < import_pod.NOYDB_BUNDLE_MAGIC.length; i++) if (bytes[i] !== import_pod.NOYDB_BUNDLE_MAGIC[i]) return false;
78
+ return true;
79
+ }
75
80
  function hasMultiMagic(bytes) {
76
81
  if (bytes.length < NOYDB_MULTI_BUNDLE_MAGIC.length) return false;
77
82
  for (let i = 0; i < NOYDB_MULTI_BUNDLE_MAGIC.length; i++) if (bytes[i] !== NOYDB_MULTI_BUNDLE_MAGIC[i]) return false;
@@ -129,13 +134,13 @@ async function writeMultiVaultBundle(compartments, opts = {}) {
129
134
  const inner = [];
130
135
  const entries = [];
131
136
  for (const c of compartments) {
132
- const innerBytes = await (0, import_bundle.writeNoydbBundle)(c.vault, c.bundleOptions ?? {});
133
- const header = (0, import_bundle.readNoydbBundleHeader)(innerBytes);
137
+ const innerBytes = await (0, import_pod.writePod)(c.vault, c.bundleOptions ?? {});
138
+ const header = (0, import_pod.readPodHeader)(innerBytes);
134
139
  const entry = {
135
140
  handle: header.handle,
136
141
  exportedAt: c.exportedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
137
142
  innerBytes: innerBytes.length,
138
- innerSha256: await (0, import_kernel.sha256Hex)(innerBytes)
143
+ innerSha256: await (0, import_cargo.sha256Hex)(innerBytes)
139
144
  };
140
145
  if (c.roleTag !== void 0) entry.roleTag = c.roleTag;
141
146
  if (c.disclose?.name !== void 0 && c.disclose.name !== false) {
@@ -148,7 +153,7 @@ async function writeMultiVaultBundle(compartments, opts = {}) {
148
153
  );
149
154
  }
150
155
  if (c.disclose?.publicEnvelope === true) {
151
- const env = (0, import_hub.readNoydbBundlePublicEnvelope)(innerBytes);
156
+ const env = (0, import_pod.readPodCover)(innerBytes);
152
157
  if (env !== void 0) entry.publicEnvelope = env;
153
158
  }
154
159
  const fence = await c.vault.schemaFenceState();
@@ -158,20 +163,20 @@ async function writeMultiVaultBundle(compartments, opts = {}) {
158
163
  }
159
164
  const manifest = {
160
165
  multiFormatVersion: NOYDB_MULTI_BUNDLE_VERSION,
161
- handle: opts.handle ?? (0, import_kernel.generateULID)(),
166
+ handle: opts.handle ?? (0, import_cargo.generateULID)(),
162
167
  compartments: entries
163
168
  };
164
169
  return encodeMultiBundle(manifest, inner);
165
170
  }
166
171
  async function readNoydbBundleManifest(bytes) {
167
172
  if (hasMultiMagic(bytes)) return [...decodeMultiBundle(bytes).manifest.compartments];
168
- if ((0, import_hub.hasNoydbBundleMagic)(bytes)) {
169
- const header = (0, import_bundle.readNoydbBundleHeader)(bytes);
170
- const env = (0, import_hub.readNoydbBundlePublicEnvelope)(bytes);
173
+ if (hasPodMagic(bytes)) {
174
+ const header = (0, import_pod.readPodHeader)(bytes);
175
+ const env = (0, import_pod.readPodCover)(bytes);
171
176
  const entry = {
172
177
  handle: header.handle,
173
178
  innerBytes: bytes.length,
174
- innerSha256: await (0, import_kernel.sha256Hex)(bytes)
179
+ innerSha256: await (0, import_cargo.sha256Hex)(bytes)
175
180
  };
176
181
  if (env !== void 0) entry.publicEnvelope = env;
177
182
  return [entry];
@@ -182,8 +187,8 @@ function readMultiVaultBundleCompartment(bytes, selector) {
182
187
  if (typeof selector === "number" && !Number.isInteger(selector)) {
183
188
  throw new Error(`readMultiVaultBundleCompartment: numeric selector must be an integer, got ${selector}.`);
184
189
  }
185
- if ((0, import_hub.hasNoydbBundleMagic)(bytes) && !hasMultiMagic(bytes)) {
186
- const header = (0, import_bundle.readNoydbBundleHeader)(bytes);
190
+ if (hasPodMagic(bytes) && !hasMultiMagic(bytes)) {
191
+ const header = (0, import_pod.readPodHeader)(bytes);
187
192
  if (selector === 0 || selector === header.handle) return bytes;
188
193
  throw new Error(`readMultiVaultBundleCompartment: single v1 bundle has only compartment "${header.handle}".`);
189
194
  }
@@ -192,13 +197,12 @@ function readMultiVaultBundleCompartment(bytes, selector) {
192
197
  if (idx < 0 || idx >= inner.length) throw new Error(`readMultiVaultBundleCompartment: no compartment ${typeof selector === "number" ? `at index ${selector}` : `"${selector}"`}.`);
193
198
  return inner[idx];
194
199
  }
195
- var import_kernel, import_bundle, import_hub, NOYDB_MULTI_BUNDLE_MAGIC, NOYDB_MULTI_BUNDLE_PREFIX_BYTES, NOYDB_MULTI_BUNDLE_VERSION;
200
+ var import_cargo, import_pod, NOYDB_MULTI_BUNDLE_MAGIC, NOYDB_MULTI_BUNDLE_PREFIX_BYTES, NOYDB_MULTI_BUNDLE_VERSION;
196
201
  var init_multi_bundle = __esm({
197
202
  "src/bundle/multi-bundle.ts"() {
198
203
  "use strict";
199
- import_kernel = require("@noy-db/hub/kernel");
200
- import_bundle = require("@noy-db/hub/bundle");
201
- import_hub = require("@noy-db/hub");
204
+ import_cargo = require("@noy-db/hub/cargo");
205
+ import_pod = require("@noy-db/hub/pod");
202
206
  init_uint32();
203
207
  NOYDB_MULTI_BUNDLE_MAGIC = new Uint8Array([78, 68, 66, 77]);
204
208
  NOYDB_MULTI_BUNDLE_PREFIX_BYTES = 10;
@@ -271,7 +275,7 @@ async function walkCrossVaultClosure(openVault, opts) {
271
275
  for (const vaultName of batch) {
272
276
  const seeds = perVaultSeeds.get(vaultName);
273
277
  const v = await openVault(vaultName);
274
- const { closure } = await (0, import_bundle2.walkClosure)(v, {
278
+ const { closure } = await (0, import_bundle.walkClosure)(v, {
275
279
  seeds,
276
280
  ...opts.maxDepth !== void 0 ? { maxDepth: opts.maxDepth } : {}
277
281
  });
@@ -323,20 +327,20 @@ async function extractCrossVaultPartition(openVault, opts) {
323
327
  const sealIds = {};
324
328
  for (const [vaultName, seeds] of plan.perVaultSeeds) {
325
329
  const v = await openVault(vaultName);
326
- const { bundleBytes, transferKey, sealId } = await (0, import_bundle2.extractPartition)(v, {
330
+ const { bundleBytes, transferKey, sealId } = await (0, import_bundle.extractPartition)(v, {
327
331
  seeds,
328
332
  ...opts.maxDepth !== void 0 ? { maxDepth: opts.maxDepth } : {},
329
333
  carrySchemas: opts.carrySchemas ?? true,
330
334
  carryLedger: opts.carryLedger ?? false,
331
335
  ...opts.compression !== void 0 ? { compression: opts.compression } : {}
332
336
  });
333
- const header = (0, import_bundle2.readNoydbBundleHeader)(bundleBytes);
337
+ const header = (0, import_pod2.readPodHeader)(bundleBytes);
334
338
  const meta = opts.compartmentMeta?.[vaultName];
335
339
  const entry = {
336
340
  handle: header.handle,
337
341
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
338
342
  innerBytes: bundleBytes.length,
339
- innerSha256: await (0, import_kernel2.sha256Hex)(bundleBytes)
343
+ innerSha256: await (0, import_cargo2.sha256Hex)(bundleBytes)
340
344
  };
341
345
  if (meta?.roleTag !== void 0) entry.roleTag = meta.roleTag;
342
346
  if (meta?.disclose?.name !== void 0 && meta.disclose.name !== false) {
@@ -355,7 +359,7 @@ async function extractCrossVaultPartition(openVault, opts) {
355
359
  }
356
360
  const manifest = {
357
361
  multiFormatVersion: NOYDB_MULTI_BUNDLE_VERSION,
358
- handle: (0, import_kernel2.generateULID)(),
362
+ handle: (0, import_cargo2.generateULID)(),
359
363
  compartments
360
364
  };
361
365
  return { bundle: encodeMultiBundle(manifest, inner), transferKeys, sealIds };
@@ -365,7 +369,7 @@ async function describeCrossVaultExtraction(openVault, opts) {
365
369
  const compartments = [];
366
370
  for (const [vaultName, seeds] of plan.perVaultSeeds) {
367
371
  const v = await openVault(vaultName);
368
- const preview = await (0, import_bundle2.describeExtraction)(v, {
372
+ const preview = await (0, import_bundle.describeExtraction)(v, {
369
373
  seeds,
370
374
  ...opts.maxDepth !== void 0 ? { maxDepth: opts.maxDepth } : {}
371
375
  });
@@ -373,12 +377,13 @@ async function describeCrossVaultExtraction(openVault, opts) {
373
377
  }
374
378
  return { compartments, dangling: plan.dangling };
375
379
  }
376
- var import_bundle2, import_kernel2, CrossVaultDanglingRefError;
380
+ var import_bundle, import_pod2, import_cargo2, CrossVaultDanglingRefError;
377
381
  var init_extract_cross_vault = __esm({
378
382
  "src/interchange/extract-cross-vault.ts"() {
379
383
  "use strict";
380
- import_bundle2 = require("@noy-db/hub/bundle");
381
- import_kernel2 = require("@noy-db/hub/kernel");
384
+ import_bundle = require("@noy-db/hub/bundle");
385
+ import_pod2 = require("@noy-db/hub/pod");
386
+ import_cargo2 = require("@noy-db/hub/cargo");
382
387
  init_multi_bundle();
383
388
  CrossVaultDanglingRefError = class extends Error {
384
389
  constructor(dangling) {
@@ -464,7 +469,7 @@ async function mergeDecryptedRecords(receiver, decrypted, opts) {
464
469
  incomingSource.set(coll, srcMap);
465
470
  incomingSourceTs.set(coll, stsMap);
466
471
  }
467
- const diff = await (0, import_hub2.diffVault)(receiver, candidate);
472
+ const diff = await (0, import_cargo3.diffVault)(receiver, candidate);
468
473
  const byCollection = {};
469
474
  const conflicts = [];
470
475
  const writes = [];
@@ -580,15 +585,15 @@ async function mergeDecryptedRecords(receiver, decrypted, opts) {
580
585
  };
581
586
  }
582
587
  async function mergeCompartment(receiver, compartmentBytes, opts) {
583
- const incoming = await (0, import_bundle3.decryptExtractedPartition)(compartmentBytes, opts.transferKey);
588
+ const incoming = await (0, import_bundle2.decryptExtractedPartition)(compartmentBytes, opts.transferKey);
584
589
  return mergeDecryptedRecords(receiver, incoming, opts);
585
590
  }
586
- var import_hub2, import_bundle3, FieldLevelDeferredError;
591
+ var import_cargo3, import_bundle2, FieldLevelDeferredError;
587
592
  var init_merge_compartment = __esm({
588
593
  "src/interchange/merge-compartment.ts"() {
589
594
  "use strict";
590
- import_hub2 = require("@noy-db/hub");
591
- import_bundle3 = require("@noy-db/hub/bundle");
595
+ import_cargo3 = require("@noy-db/hub/cargo");
596
+ import_bundle2 = require("@noy-db/hub/bundle");
592
597
  init_field_authority();
593
598
  FieldLevelDeferredError = class extends Error {
594
599
  constructor(collection) {
@@ -684,7 +689,7 @@ async function graduate(noydb, docked, opts) {
684
689
  await mergeDecryptedRecords(vault, staged, { strategy: "take-incoming", reason: "dock:graduate" });
685
690
  let deedSealed = false;
686
691
  if (opts.deed) {
687
- await (0, import_hub3.createDeedOwner)(noydb._store, opts.vaultName, opts.deed.ownerId, opts.deed.sealingProvider);
692
+ await (0, import_cargo4.createDeedOwner)(noydb._store, opts.vaultName, opts.deed.ownerId, opts.deed.sealingProvider);
688
693
  deedSealed = true;
689
694
  }
690
695
  if (opts.stateVault) {
@@ -704,11 +709,11 @@ async function graduate(noydb, docked, opts) {
704
709
  event: { type: "unit-graduated", unitId: docked.unitId, vault: opts.vaultName }
705
710
  };
706
711
  }
707
- var import_hub3, UnitGraduationError, ISO_EPOCH;
712
+ var import_cargo4, UnitGraduationError, ISO_EPOCH;
708
713
  var init_graduate = __esm({
709
714
  "src/dock/graduate.ts"() {
710
715
  "use strict";
711
- import_hub3 = require("@noy-db/hub");
716
+ import_cargo4 = require("@noy-db/hub/cargo");
712
717
  init_merge_compartment();
713
718
  init_stage_records();
714
719
  UnitGraduationError = class extends Error {
@@ -738,7 +743,7 @@ __export(surface_exports, {
738
743
  async function proposeSurface(smv, def, proposedBy, now) {
739
744
  const row = {
740
745
  ...def,
741
- id: def.id ?? (0, import_kernel3.generateULID)(),
746
+ id: def.id ?? (0, import_cargo5.generateULID)(),
742
747
  status: "proposed",
743
748
  proposedBy,
744
749
  createdAt: now
@@ -759,7 +764,7 @@ async function exportSurface(source, surface) {
759
764
  throw new SurfaceStateError(surface.id, surface.status, "agreed");
760
765
  }
761
766
  const seeds = Object.fromEntries(surface.collections.map((c) => [c, () => true]));
762
- const { bundleBytes, transferKey } = await (0, import_bundle5.extractPartition)(source, {
767
+ const { bundleBytes, transferKey } = await (0, import_bundle4.extractPartition)(source, {
763
768
  seeds,
764
769
  maxDepth: 0,
765
770
  ...surface.fields ? { fieldProjection: surface.fields } : {},
@@ -797,12 +802,12 @@ async function markSynced(smv, id, now) {
797
802
  nextSyncDueAt: now + cadenceMs
798
803
  });
799
804
  }
800
- var import_kernel3, import_bundle5, SurfaceNotFoundError, SurfaceStateError, SurfaceCadenceScheduler;
805
+ var import_cargo5, import_bundle4, SurfaceNotFoundError, SurfaceStateError, SurfaceCadenceScheduler;
801
806
  var init_surface = __esm({
802
807
  "src/interchange/surface.ts"() {
803
808
  "use strict";
804
- import_kernel3 = require("@noy-db/hub/kernel");
805
- import_bundle5 = require("@noy-db/hub/bundle");
809
+ import_cargo5 = require("@noy-db/hub/cargo");
810
+ import_bundle4 = require("@noy-db/hub/bundle");
806
811
  init_merge_compartment();
807
812
  SurfaceNotFoundError = class extends Error {
808
813
  name = "SurfaceNotFoundError";
@@ -907,38 +912,38 @@ function canonical(value) {
907
912
  return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(obj[k])}`).join(",")}}`;
908
913
  }
909
914
  async function fingerprintBlueprint(bp) {
910
- return (0, import_kernel4.sha256Hex)(new TextEncoder().encode(canonical(bp)));
915
+ return (0, import_cargo6.sha256Hex)(new TextEncoder().encode(canonical(bp)));
911
916
  }
912
- var import_kernel4;
917
+ var import_cargo6;
913
918
  var init_schema_manifest = __esm({
914
919
  "src/federation/schema-manifest.ts"() {
915
920
  "use strict";
916
- import_kernel4 = require("@noy-db/hub/kernel");
921
+ import_cargo6 = require("@noy-db/hub/cargo");
917
922
  }
918
923
  });
919
924
 
920
925
  // src/federation/constants.ts
921
- var import_hub4;
926
+ var import_cargo7;
922
927
  var init_constants = __esm({
923
928
  "src/federation/constants.ts"() {
924
929
  "use strict";
925
- import_hub4 = require("@noy-db/hub");
930
+ import_cargo7 = require("@noy-db/hub/cargo");
926
931
  }
927
932
  });
928
933
 
929
934
  // src/federation/state-vault.ts
930
935
  var state_vault_exports = {};
931
936
  __export(state_vault_exports, {
932
- STATE_VAULT_NAME: () => import_hub4.STATE_VAULT_NAME,
937
+ STATE_VAULT_NAME: () => import_cargo7.STATE_VAULT_NAME,
933
938
  StateManagementVault: () => StateManagementVault
934
939
  });
935
- var import_kernel5, REGISTRY, MANIFEST, EVENTS, MIGRATION_STATUS, SURFACES, StateManagementVault;
940
+ var import_cargo8, REGISTRY, MANIFEST, EVENTS, MIGRATION_STATUS, SURFACES, StateManagementVault;
936
941
  var init_state_vault = __esm({
937
942
  "src/federation/state-vault.ts"() {
938
943
  "use strict";
939
944
  init_schema_manifest();
940
945
  init_constants();
941
- import_kernel5 = require("@noy-db/hub/kernel");
946
+ import_cargo8 = require("@noy-db/hub/cargo");
942
947
  init_constants();
943
948
  REGISTRY = "vaultRegistry";
944
949
  MANIFEST = "schemaManifest";
@@ -968,7 +973,7 @@ var init_state_vault = __esm({
968
973
  #surfaces;
969
974
  /** Idempotently open the reserved state vault and bind the control-plane collections. */
970
975
  static async open(db) {
971
- const vault = await db.openVault(import_hub4.STATE_VAULT_NAME);
976
+ const vault = await db.openVault(import_cargo7.STATE_VAULT_NAME);
972
977
  return new _StateManagementVault(
973
978
  vault.collection(REGISTRY),
974
979
  vault.collection(MANIFEST),
@@ -1028,7 +1033,7 @@ var init_state_vault = __esm({
1028
1033
  */
1029
1034
  async appendEvent(event) {
1030
1035
  const ts = event.ts ?? Date.now();
1031
- const id = (0, import_kernel5.generateULID)();
1036
+ const id = (0, import_cargo8.generateULID)();
1032
1037
  await this.#events.put(id, { ...event, id, ts });
1033
1038
  }
1034
1039
  /**
@@ -1070,13 +1075,13 @@ var init_state_vault = __esm({
1070
1075
 
1071
1076
  // src/federation/classify-skip.ts
1072
1077
  function classifyShardSkip(err) {
1073
- return err instanceof import_kernel6.NoAccessError ? "no-grant" : "error";
1078
+ return err instanceof import_cargo9.NoAccessError ? "no-grant" : "error";
1074
1079
  }
1075
- var import_kernel6;
1080
+ var import_cargo9;
1076
1081
  var init_classify_skip = __esm({
1077
1082
  "src/federation/classify-skip.ts"() {
1078
1083
  "use strict";
1079
- import_kernel6 = require("@noy-db/hub/kernel");
1084
+ import_cargo9 = require("@noy-db/hub/cargo");
1080
1085
  }
1081
1086
  });
1082
1087
 
@@ -1101,7 +1106,7 @@ async function applyBroadcastLegs(rows, legs) {
1101
1106
  for (const leg of legs) {
1102
1107
  const map = /* @__PURE__ */ new Map();
1103
1108
  for (const rec of await leg.from.list()) {
1104
- const k = coerceKey((0, import_kernel7.readPath)(rec, leg.on));
1109
+ const k = coerceKey((0, import_cargo10.readPath)(rec, leg.on));
1105
1110
  if (k !== null && !map.has(k)) map.set(k, rec);
1106
1111
  }
1107
1112
  indexes.push({ leg, map });
@@ -1109,7 +1114,7 @@ async function applyBroadcastLegs(rows, legs) {
1109
1114
  return rows.map((row) => {
1110
1115
  const out = { ...row };
1111
1116
  for (const { leg, map } of indexes) {
1112
- const key = coerceKey((0, import_kernel7.readPath)(row, leg.field));
1117
+ const key = coerceKey((0, import_cargo10.readPath)(row, leg.field));
1113
1118
  const match = key === null ? null : map.get(key) ?? null;
1114
1119
  if (match === null && leg.mode === "warn") {
1115
1120
  warnOnceBroadcastMiss(leg.field, leg.as, key ?? "<null>");
@@ -1119,11 +1124,11 @@ async function applyBroadcastLegs(rows, legs) {
1119
1124
  return out;
1120
1125
  });
1121
1126
  }
1122
- var import_kernel7, warnedBroadcastKeys;
1127
+ var import_cargo10, warnedBroadcastKeys;
1123
1128
  var init_cross_shard_join = __esm({
1124
1129
  "src/federation/cross-shard-join.ts"() {
1125
1130
  "use strict";
1126
- import_kernel7 = require("@noy-db/hub/kernel");
1131
+ import_cargo10 = require("@noy-db/hub/cargo");
1127
1132
  warnedBroadcastKeys = /* @__PURE__ */ new Set();
1128
1133
  }
1129
1134
  });
@@ -1334,12 +1339,12 @@ var init_partial_reduce = __esm({
1334
1339
  });
1335
1340
 
1336
1341
  // src/federation/aggregate-across.ts
1337
- var import_kernel8, import_kernel9, CrossVaultAggregation, CrossVaultGroupedAggregation;
1342
+ var import_cargo11, import_cargo12, CrossVaultAggregation, CrossVaultGroupedAggregation;
1338
1343
  var init_aggregate_across = __esm({
1339
1344
  "src/federation/aggregate-across.ts"() {
1340
1345
  "use strict";
1341
- import_kernel8 = require("@noy-db/hub/kernel");
1342
- import_kernel9 = require("@noy-db/hub/kernel");
1346
+ import_cargo11 = require("@noy-db/hub/cargo");
1347
+ import_cargo12 = require("@noy-db/hub/cargo");
1343
1348
  init_cross_vault_live();
1344
1349
  init_partial_reduce();
1345
1350
  CrossVaultAggregation = class {
@@ -1357,7 +1362,7 @@ var init_aggregate_across = __esm({
1357
1362
  return { result: finalizePartial(this.spec, mergePartials(this.spec, partials)), skippedVaults: skippedVaults2 };
1358
1363
  }
1359
1364
  const { records, skippedVaults } = await this.src.fanoutRecords(options);
1360
- return { result: (0, import_kernel8.reduceRecords)(records, this.spec), skippedVaults };
1365
+ return { result: (0, import_cargo11.reduceRecords)(records, this.spec), skippedVaults };
1361
1366
  }
1362
1367
  live(options = {}) {
1363
1368
  if (!this.bind) throw new Error("CrossVaultAggregation: live() requires a LiveBinding \u2014 use ShardedQuery.aggregate()");
@@ -1368,7 +1373,7 @@ var init_aggregate_across = __esm({
1368
1373
  isRelevant: this.bind.isRelevant,
1369
1374
  compute: async () => {
1370
1375
  const { records, skippedVaults } = await src.fanoutRecords(options);
1371
- return { value: (0, import_kernel8.reduceRecords)(records, spec), skipped: skippedVaults };
1376
+ return { value: (0, import_cargo11.reduceRecords)(records, spec), skipped: skippedVaults };
1372
1377
  },
1373
1378
  initialSnapshot: { value: void 0, skipped: [] },
1374
1379
  ...options.debounceMs !== void 0 ? { debounceMs: options.debounceMs } : {}
@@ -1403,7 +1408,7 @@ var init_aggregate_across = __esm({
1403
1408
  async run(options = {}) {
1404
1409
  const { records, skippedVaults } = await this.src.fanoutRecords(options);
1405
1410
  return {
1406
- results: (0, import_kernel9.groupAndReduce)(records, this.field, this.spec),
1411
+ results: (0, import_cargo12.groupAndReduce)(records, this.field, this.spec),
1407
1412
  skippedVaults
1408
1413
  };
1409
1414
  }
@@ -1418,7 +1423,7 @@ var init_aggregate_across = __esm({
1418
1423
  compute: async () => {
1419
1424
  const { records, skippedVaults } = await src.fanoutRecords(options);
1420
1425
  return {
1421
- records: (0, import_kernel9.groupAndReduce)(records, field, spec),
1426
+ records: (0, import_cargo12.groupAndReduce)(records, field, spec),
1422
1427
  skipped: skippedVaults
1423
1428
  };
1424
1429
  },
@@ -1491,7 +1496,7 @@ async function retrieveAcross(group, collectionName, query, opts = {}) {
1491
1496
  }
1492
1497
  return pv.hits.map((h) => ({ ...h, id: pv.vault + SEP + h.id }));
1493
1498
  });
1494
- const fused = (0, import_kernel10.fuseRetrieval)(lists, {
1499
+ const fused = (0, import_cargo13.fuseRetrieval)(lists, {
1495
1500
  ...opts.limit !== void 0 ? { limit: opts.limit } : {},
1496
1501
  ...opts.rrfK !== void 0 ? { k: opts.rrfK } : {}
1497
1502
  });
@@ -1501,11 +1506,11 @@ async function retrieveAcross(group, collectionName, query, opts = {}) {
1501
1506
  });
1502
1507
  return { hits, skippedVaults };
1503
1508
  }
1504
- var import_kernel10, SEP;
1509
+ var import_cargo13, SEP;
1505
1510
  var init_retrieve_across = __esm({
1506
1511
  "src/federation/retrieve-across.ts"() {
1507
1512
  "use strict";
1508
- import_kernel10 = require("@noy-db/hub/kernel");
1513
+ import_cargo13 = require("@noy-db/hub/cargo");
1509
1514
  init_classify_skip();
1510
1515
  SEP = "\0";
1511
1516
  }
@@ -1525,28 +1530,28 @@ function autoPushConfig(spec) {
1525
1530
  }
1526
1531
  function assertSafePartitionKey(partitionKey) {
1527
1532
  if (partitionKey.length === 0) {
1528
- throw new import_kernel11.ValidationError("partitionKey must be a non-empty string");
1533
+ throw new import_cargo14.ValidationError("partitionKey must be a non-empty string");
1529
1534
  }
1530
- if (partitionKey === import_hub4.STATE_VAULT_NAME) {
1531
- throw new import_kernel11.ReservedVaultNameError(partitionKey);
1535
+ if (partitionKey === import_cargo7.STATE_VAULT_NAME) {
1536
+ throw new import_cargo14.ReservedVaultNameError(partitionKey);
1532
1537
  }
1533
1538
  if (!SAFE_PARTITION_KEY.test(partitionKey)) {
1534
- throw new import_kernel11.ValidationError(
1539
+ throw new import_cargo14.ValidationError(
1535
1540
  `partitionKey "${partitionKey}" contains characters outside [A-Za-z0-9._-]. Map your records to a store-safe key in sharding.keyOf.`
1536
1541
  );
1537
1542
  }
1538
1543
  if (partitionKey.includes(SHARD_SEPARATOR)) {
1539
- throw new import_kernel11.ValidationError(
1544
+ throw new import_cargo14.ValidationError(
1540
1545
  `partitionKey "${partitionKey}" must not contain "--" \u2014 it is reserved as the shard vault-id separator and would risk shard-id collisions.`
1541
1546
  );
1542
1547
  }
1543
1548
  }
1544
- var import_kernel11, SHARD_SEPARATOR, SAFE_PARTITION_KEY, VaultGroup, ShardedCollection, ShardedQuery, ShardedGroupedQuery;
1549
+ var import_cargo14, SHARD_SEPARATOR, SAFE_PARTITION_KEY, VaultGroup, ShardedCollection, ShardedQuery, ShardedGroupedQuery;
1545
1550
  var init_vault_group = __esm({
1546
1551
  "src/federation/vault-group.ts"() {
1547
1552
  "use strict";
1548
1553
  init_state_vault();
1549
- import_kernel11 = require("@noy-db/hub/kernel");
1554
+ import_cargo14 = require("@noy-db/hub/cargo");
1550
1555
  init_constants();
1551
1556
  init_classify_skip();
1552
1557
  init_cross_shard_join();
@@ -1567,7 +1572,7 @@ var init_vault_group = __esm({
1567
1572
  this.cutoverOnOpen = cutoverOnOpen;
1568
1573
  this.meta = meta;
1569
1574
  if (name.includes(SHARD_SEPARATOR)) {
1570
- throw new import_kernel11.ValidationError(
1575
+ throw new import_cargo14.ValidationError(
1571
1576
  `VaultGroup name "${name}" must not contain "--" (reserved shard vault-id separator).`
1572
1577
  );
1573
1578
  }
@@ -1672,11 +1677,11 @@ var init_vault_group = __esm({
1672
1677
  const vaultId = this.shardVaultId(partitionKey);
1673
1678
  const row = await this.registry.get(this.registryId(partitionKey));
1674
1679
  const provisioned = await this.db._shardVaultProvisioned(vaultId);
1675
- if (row && !provisioned) throw new import_kernel11.ShardProvisioningError(vaultId, partitionKey);
1680
+ if (row && !provisioned) throw new import_cargo14.ShardProvisioningError(vaultId, partitionKey);
1676
1681
  if (row && provisioned) return this.openShard(partitionKey);
1677
1682
  if (region !== void 0) {
1678
1683
  const backendRegion = this.db._resolveBackend(vaultId).capabilities?.region;
1679
- if (backendRegion !== region) throw new import_kernel11.DataResidencyError(vaultId, region, backendRegion);
1684
+ if (backendRegion !== region) throw new import_cargo14.DataResidencyError(vaultId, region, backendRegion);
1680
1685
  }
1681
1686
  const vault = await this.db.openVault(vaultId);
1682
1687
  this.template.configure(vault);
@@ -1710,9 +1715,9 @@ var init_vault_group = __esm({
1710
1715
  async shard(partitionKey) {
1711
1716
  const vaultId = this.shardVaultId(partitionKey);
1712
1717
  const row = await this.registry.get(this.registryId(partitionKey));
1713
- if (!row) throw new import_kernel11.UnknownShardError(partitionKey, this.name);
1718
+ if (!row) throw new import_cargo14.UnknownShardError(partitionKey, this.name);
1714
1719
  const provisioned = await this.db._shardVaultProvisioned(vaultId);
1715
- if (!provisioned) throw new import_kernel11.ShardProvisioningError(vaultId, partitionKey);
1720
+ if (!provisioned) throw new import_cargo14.ShardProvisioningError(vaultId, partitionKey);
1716
1721
  return this.openShard(partitionKey);
1717
1722
  }
1718
1723
  /** A sharded view over one logical collection across all shards. */
@@ -1744,7 +1749,7 @@ var init_vault_group = __esm({
1744
1749
  for (const p of probes) {
1745
1750
  if ("error" in p) skipped.push({ vaultId: p.row.vaultId, reason: "error", error: p.error });
1746
1751
  else if (p.provisioned) eligible.push(p.row);
1747
- else skipped.push({ vaultId: p.row.vaultId, reason: "error", error: new import_kernel11.ShardProvisioningError(p.row.vaultId, p.row.partitionKey) });
1752
+ else skipped.push({ vaultId: p.row.vaultId, reason: "error", error: new import_cargo14.ShardProvisioningError(p.row.vaultId, p.row.partitionKey) });
1748
1753
  }
1749
1754
  return { eligible, skipped };
1750
1755
  }
@@ -1781,7 +1786,7 @@ var init_vault_group = __esm({
1781
1786
  withCrossVaultDerivation(spec) {
1782
1787
  const target = spec.target.vault;
1783
1788
  if (target === this.name || target.startsWith(`${this.name}${SHARD_SEPARATOR}`)) {
1784
- throw new import_kernel11.ValidationError(
1789
+ throw new import_cargo14.ValidationError(
1785
1790
  `withCrossVaultDerivation: target.vault "${target}" is the "${this.name}" group itself or one of its shards \u2014 an Insight summary must target a SEPARATE analytics vault, never write back into client-shard data (it would breach the per-shard DEK boundary). Use a distinct vault name.`
1786
1791
  );
1787
1792
  }
@@ -1907,7 +1912,7 @@ var init_vault_group = __esm({
1907
1912
  async cutoverShard(partitionKey) {
1908
1913
  const vaultId = this.shardVaultId(partitionKey);
1909
1914
  const row = await this.registry.get(this.registryId(partitionKey));
1910
- if (!row) throw new import_kernel11.UnknownShardError(partitionKey, this.name);
1915
+ if (!row) throw new import_cargo14.UnknownShardError(partitionKey, this.name);
1911
1916
  const target = this.template.version;
1912
1917
  const sv = await this.ensureStateVault();
1913
1918
  const base = { vaultId, group: this.name, currentVersion: row.schemaVersion, targetVersion: target };
@@ -1990,7 +1995,7 @@ var init_vault_group = __esm({
1990
1995
  let vault;
1991
1996
  if (!row) {
1992
1997
  if (this.group.sharding.autoCreate === false) {
1993
- throw new import_kernel11.UnknownShardError(key, this.group.name);
1998
+ throw new import_cargo14.UnknownShardError(key, this.group.name);
1994
1999
  }
1995
2000
  vault = await this.group.createShard(key, this.group.sharding.regionOf?.(record));
1996
2001
  } else {
@@ -2073,7 +2078,7 @@ var init_vault_group = __esm({
2073
2078
  this.group.template.configure(probe);
2074
2079
  for (const leg of this.coPartitionedLegs) {
2075
2080
  if (!probe.resolveRef(this.collectionName, leg.field)) {
2076
- throw new import_kernel11.CrossShardJoinError(
2081
+ throw new import_cargo14.CrossShardJoinError(
2077
2082
  `crossShardJoin("${leg.field}"): no ref() declared for "${leg.field}" on collection "${this.collectionName}" in template "${this.group.sharding.vaultTemplate}". Add refs: { ${leg.field}: ref('<target>') } to the template's collection options.`
2078
2083
  );
2079
2084
  }
@@ -2238,10 +2243,10 @@ var init_vault_group = __esm({
2238
2243
  // src/index.ts
2239
2244
  var index_exports = {};
2240
2245
  __export(index_exports, {
2241
- CrossShardJoinError: () => import_kernel13.CrossShardJoinError,
2246
+ CrossShardJoinError: () => import_cargo16.CrossShardJoinError,
2242
2247
  CrossVaultDanglingRefError: () => CrossVaultDanglingRefError,
2243
- CustodyApi: () => import_hub6.CustodyApi,
2244
- DataResidencyError: () => import_kernel13.DataResidencyError,
2248
+ CustodyApi: () => import_cargo17.CustodyApi,
2249
+ DataResidencyError: () => import_cargo16.DataResidencyError,
2245
2250
  DockedUnit: () => DockedUnit,
2246
2251
  FieldAuthorityPolicyMissingError: () => FieldAuthorityPolicyMissingError,
2247
2252
  FieldLevelDeferredError: () => FieldLevelDeferredError,
@@ -2252,17 +2257,17 @@ __export(index_exports, {
2252
2257
  NOYDB_MULTI_BUNDLE_MAGIC: () => NOYDB_MULTI_BUNDLE_MAGIC,
2253
2258
  NOYDB_MULTI_BUNDLE_PREFIX_BYTES: () => NOYDB_MULTI_BUNDLE_PREFIX_BYTES,
2254
2259
  NOYDB_MULTI_BUNDLE_VERSION: () => NOYDB_MULTI_BUNDLE_VERSION,
2255
- ReservedVaultNameError: () => import_kernel13.ReservedVaultNameError,
2256
- ShardProvisioningError: () => import_kernel13.ShardProvisioningError,
2260
+ ReservedVaultNameError: () => import_cargo16.ReservedVaultNameError,
2261
+ ShardProvisioningError: () => import_cargo16.ShardProvisioningError,
2257
2262
  SurfaceCadenceScheduler: () => SurfaceCadenceScheduler,
2258
2263
  SurfaceNotFoundError: () => SurfaceNotFoundError,
2259
2264
  SurfaceStateError: () => SurfaceStateError,
2260
2265
  UnitGraduationError: () => UnitGraduationError,
2261
- UnknownShardError: () => import_kernel13.UnknownShardError,
2262
- VaultTemplateNotFoundError: () => import_kernel13.VaultTemplateNotFoundError,
2266
+ UnknownShardError: () => import_cargo16.UnknownShardError,
2267
+ VaultTemplateNotFoundError: () => import_cargo16.VaultTemplateNotFoundError,
2263
2268
  agreeSurface: () => agreeSurface,
2264
2269
  applySurface: () => applySurface,
2265
- createDeedOwner: () => import_hub6.createDeedOwner,
2270
+ createDeedOwner: () => import_cargo17.createDeedOwner,
2266
2271
  createLobby: () => createLobby,
2267
2272
  decodeMultiBundle: () => decodeMultiBundle,
2268
2273
  describeCrossVaultExtraction: () => describeCrossVaultExtraction,
@@ -2270,11 +2275,11 @@ __export(index_exports, {
2270
2275
  exportSurface: () => exportSurface,
2271
2276
  extractCrossVaultPartition: () => extractCrossVaultPartition,
2272
2277
  groupInspector: () => groupInspector,
2273
- isDeedVault: () => import_hub6.isDeedVault,
2278
+ isDeedVault: () => import_cargo17.isDeedVault,
2274
2279
  isSurfaceDue: () => isSurfaceDue,
2275
- liberateVault: () => import_hub6.liberateVault,
2280
+ liberateVault: () => import_cargo17.liberateVault,
2276
2281
  listDueSurfaces: () => listDueSurfaces,
2277
- loadDeedMarker: () => import_hub6.loadDeedMarker,
2282
+ loadDeedMarker: () => import_cargo17.loadDeedMarker,
2278
2283
  markSynced: () => markSynced,
2279
2284
  mergeCompartment: () => mergeCompartment,
2280
2285
  mergeDecryptedRecords: () => mergeDecryptedRecords,
@@ -2289,8 +2294,7 @@ __export(index_exports, {
2289
2294
  writeMultiVaultBundle: () => writeMultiVaultBundle
2290
2295
  });
2291
2296
  module.exports = __toCommonJS(index_exports);
2292
- var import_kernel12 = require("@noy-db/hub/kernel");
2293
- var import_hub5 = require("@noy-db/hub");
2297
+ var import_cargo15 = require("@noy-db/hub/cargo");
2294
2298
 
2295
2299
  // src/dock/docked-unit.ts
2296
2300
  var DockedUnit = class {
@@ -2372,13 +2376,13 @@ async function meterGroup(group, opts = {}) {
2372
2376
  }
2373
2377
 
2374
2378
  // src/index.ts
2375
- var import_kernel13 = require("@noy-db/hub/kernel");
2379
+ var import_cargo16 = require("@noy-db/hub/cargo");
2376
2380
  init_multi_bundle();
2377
2381
  init_extract_cross_vault();
2378
2382
  init_merge_compartment();
2379
2383
 
2380
2384
  // src/interchange/migrate-then-merge.ts
2381
- var import_bundle4 = require("@noy-db/hub/bundle");
2385
+ var import_bundle3 = require("@noy-db/hub/bundle");
2382
2386
  init_merge_compartment();
2383
2387
  init_stage_records();
2384
2388
  init_stage_records();
@@ -2403,7 +2407,7 @@ async function migrateThenMerge(receiver, compartmentBytes, opts) {
2403
2407
  );
2404
2408
  }
2405
2409
  if (fromVersion > toVersion) throw new MinVersionError(fromVersion, toVersion);
2406
- const incoming = await (0, import_bundle4.decryptExtractedPartition)(compartmentBytes, opts.transferKey);
2410
+ const incoming = await (0, import_bundle3.decryptExtractedPartition)(compartmentBytes, opts.transferKey);
2407
2411
  const transformsByCollection = {};
2408
2412
  const migrationByCollection = {};
2409
2413
  for (const [coll, recs] of Object.entries(incoming)) {
@@ -2426,7 +2430,7 @@ async function migrateThenMerge(receiver, compartmentBytes, opts) {
2426
2430
 
2427
2431
  // src/index.ts
2428
2432
  init_field_authority();
2429
- var import_hub6 = require("@noy-db/hub");
2433
+ var import_cargo17 = require("@noy-db/hub/cargo");
2430
2434
 
2431
2435
  // src/dock/unit-driver.ts
2432
2436
  var InMemoryUnitDriver = class {
@@ -2460,10 +2464,10 @@ var Lobby = class {
2460
2464
  }
2461
2465
  async openVaultGroup(name, opts) {
2462
2466
  const db = this.noydb;
2463
- if (db.isClosed) throw new import_kernel12.ValidationError("Instance is closed");
2464
- if (name === import_hub5.STATE_VAULT_NAME) throw new import_kernel12.ReservedVaultNameError(name);
2467
+ if (db.isClosed) throw new import_cargo15.ValidationError("Instance is closed");
2468
+ if (name === import_cargo15.STATE_VAULT_NAME) throw new import_cargo15.ReservedVaultNameError(name);
2465
2469
  const template = this.vaultTemplates.get(opts.sharding.vaultTemplate);
2466
- if (!template) throw new import_kernel12.VaultTemplateNotFoundError(opts.sharding.vaultTemplate);
2470
+ if (!template) throw new import_cargo15.VaultTemplateNotFoundError(opts.sharding.vaultTemplate);
2467
2471
  const { VaultGroup: VaultGroup2 } = await Promise.resolve().then(() => (init_vault_group(), vault_group_exports));
2468
2472
  const { StateManagementVault: StateManagementVault2 } = await Promise.resolve().then(() => (init_state_vault(), state_vault_exports));
2469
2473
  const stateVault = opts.registry ? void 0 : await StateManagementVault2.open(db);
@@ -2482,7 +2486,7 @@ var Lobby = class {
2482
2486
  }
2483
2487
  async openStateManagementVault() {
2484
2488
  const db = this.noydb;
2485
- if (db.isClosed) throw new import_kernel12.ValidationError("Instance is closed");
2489
+ if (db.isClosed) throw new import_cargo15.ValidationError("Instance is closed");
2486
2490
  const { StateManagementVault: StateManagementVault2 } = await Promise.resolve().then(() => (init_state_vault(), state_vault_exports));
2487
2491
  return StateManagementVault2.open(db);
2488
2492
  }