@camstack/addon-waste-collections 0.1.7 → 0.1.8

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.
@@ -4126,6 +4126,12 @@ var numberProcessor = (schema, ctx, _json, _params) => {
4126
4126
  var booleanProcessor = (_schema, _ctx, json, _params) => {
4127
4127
  json.type = "boolean";
4128
4128
  };
4129
+ var bigintProcessor = (_schema, ctx, _json, _params) => {
4130
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt cannot be represented in JSON Schema");
4131
+ };
4132
+ var symbolProcessor = (_schema, ctx, _json, _params) => {
4133
+ if (ctx.unrepresentable === "throw") throw new Error("Symbols cannot be represented in JSON Schema");
4134
+ };
4129
4135
  var nullProcessor = (_schema, ctx, json, _params) => {
4130
4136
  if (ctx.target === "openapi-3.0") {
4131
4137
  json.type = "string";
@@ -4133,12 +4139,17 @@ var nullProcessor = (_schema, ctx, json, _params) => {
4133
4139
  json.enum = [null];
4134
4140
  } else json.type = "null";
4135
4141
  };
4142
+ var undefinedProcessor = (_schema, ctx, _json, _params) => {
4143
+ if (ctx.unrepresentable === "throw") throw new Error("Undefined cannot be represented in JSON Schema");
4144
+ };
4136
4145
  var voidProcessor = (_schema, ctx, _json, _params) => {
4137
4146
  if (ctx.unrepresentable === "throw") throw new Error("Void cannot be represented in JSON Schema");
4138
4147
  };
4139
4148
  var neverProcessor = (_schema, _ctx, json, _params) => {
4140
4149
  json.not = {};
4141
4150
  };
4151
+ var anyProcessor = (_schema, _ctx, _json, _params) => {};
4152
+ var unknownProcessor = (_schema, _ctx, _json, _params) => {};
4142
4153
  var dateProcessor = (_schema, ctx, _json, _params) => {
4143
4154
  if (ctx.unrepresentable === "throw") throw new Error("Date cannot be represented in JSON Schema");
4144
4155
  };
@@ -4170,12 +4181,53 @@ var literalProcessor = (schema, ctx, json, _params) => {
4170
4181
  json.enum = vals;
4171
4182
  }
4172
4183
  };
4184
+ var nanProcessor = (_schema, ctx, _json, _params) => {
4185
+ if (ctx.unrepresentable === "throw") throw new Error("NaN cannot be represented in JSON Schema");
4186
+ };
4187
+ var templateLiteralProcessor = (schema, _ctx, json, _params) => {
4188
+ const _json = json;
4189
+ const pattern = schema._zod.pattern;
4190
+ if (!pattern) throw new Error("Pattern not found in template literal");
4191
+ _json.type = "string";
4192
+ _json.pattern = pattern.source;
4193
+ };
4194
+ var fileProcessor = (schema, _ctx, json, _params) => {
4195
+ const _json = json;
4196
+ const file = {
4197
+ type: "string",
4198
+ format: "binary",
4199
+ contentEncoding: "binary"
4200
+ };
4201
+ const { minimum, maximum, mime } = schema._zod.bag;
4202
+ if (minimum !== void 0) file.minLength = minimum;
4203
+ if (maximum !== void 0) file.maxLength = maximum;
4204
+ if (mime) if (mime.length === 1) {
4205
+ file.contentMediaType = mime[0];
4206
+ Object.assign(_json, file);
4207
+ } else {
4208
+ Object.assign(_json, file);
4209
+ _json.anyOf = mime.map((m) => ({ contentMediaType: m }));
4210
+ }
4211
+ else Object.assign(_json, file);
4212
+ };
4213
+ var successProcessor = (_schema, _ctx, json, _params) => {
4214
+ json.type = "boolean";
4215
+ };
4173
4216
  var customProcessor = (_schema, ctx, _json, _params) => {
4174
4217
  if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
4175
4218
  };
4219
+ var functionProcessor = (_schema, ctx, _json, _params) => {
4220
+ if (ctx.unrepresentable === "throw") throw new Error("Function types cannot be represented in JSON Schema");
4221
+ };
4176
4222
  var transformProcessor = (_schema, ctx, _json, _params) => {
4177
4223
  if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
4178
4224
  };
4225
+ var mapProcessor = (_schema, ctx, _json, _params) => {
4226
+ if (ctx.unrepresentable === "throw") throw new Error("Map cannot be represented in JSON Schema");
4227
+ };
4228
+ var setProcessor = (_schema, ctx, _json, _params) => {
4229
+ if (ctx.unrepresentable === "throw") throw new Error("Set cannot be represented in JSON Schema");
4230
+ };
4179
4231
  var arrayProcessor = (schema, ctx, _json, params) => {
4180
4232
  const json = _json;
4181
4233
  const def = schema._zod.def;
@@ -4380,6 +4432,12 @@ var readonlyProcessor = (schema, ctx, json, params) => {
4380
4432
  seen.ref = def.innerType;
4381
4433
  json.readOnly = true;
4382
4434
  };
4435
+ var promiseProcessor = (schema, ctx, _json, params) => {
4436
+ const def = schema._zod.def;
4437
+ process(def.innerType, ctx, params);
4438
+ const seen = ctx.seen.get(schema);
4439
+ seen.ref = def.innerType;
4440
+ };
4383
4441
  var optionalProcessor = (schema, ctx, _json, params) => {
4384
4442
  const def = schema._zod.def;
4385
4443
  process(def.innerType, ctx, params);
@@ -4392,6 +4450,81 @@ var lazyProcessor = (schema, ctx, _json, params) => {
4392
4450
  const seen = ctx.seen.get(schema);
4393
4451
  seen.ref = innerType;
4394
4452
  };
4453
+ var allProcessors = {
4454
+ string: stringProcessor,
4455
+ number: numberProcessor,
4456
+ boolean: booleanProcessor,
4457
+ bigint: bigintProcessor,
4458
+ symbol: symbolProcessor,
4459
+ null: nullProcessor,
4460
+ undefined: undefinedProcessor,
4461
+ void: voidProcessor,
4462
+ never: neverProcessor,
4463
+ any: anyProcessor,
4464
+ unknown: unknownProcessor,
4465
+ date: dateProcessor,
4466
+ enum: enumProcessor,
4467
+ literal: literalProcessor,
4468
+ nan: nanProcessor,
4469
+ template_literal: templateLiteralProcessor,
4470
+ file: fileProcessor,
4471
+ success: successProcessor,
4472
+ custom: customProcessor,
4473
+ function: functionProcessor,
4474
+ transform: transformProcessor,
4475
+ map: mapProcessor,
4476
+ set: setProcessor,
4477
+ array: arrayProcessor,
4478
+ object: objectProcessor,
4479
+ union: unionProcessor,
4480
+ intersection: intersectionProcessor,
4481
+ tuple: tupleProcessor,
4482
+ record: recordProcessor,
4483
+ nullable: nullableProcessor,
4484
+ nonoptional: nonoptionalProcessor,
4485
+ default: defaultProcessor,
4486
+ prefault: prefaultProcessor,
4487
+ catch: catchProcessor,
4488
+ pipe: pipeProcessor,
4489
+ readonly: readonlyProcessor,
4490
+ promise: promiseProcessor,
4491
+ optional: optionalProcessor,
4492
+ lazy: lazyProcessor
4493
+ };
4494
+ function toJSONSchema(input, params) {
4495
+ if ("_idmap" in input) {
4496
+ const registry = input;
4497
+ const ctx = initializeContext({
4498
+ ...params,
4499
+ processors: allProcessors
4500
+ });
4501
+ const defs = {};
4502
+ for (const entry of registry._idmap.entries()) {
4503
+ const [_, schema] = entry;
4504
+ process(schema, ctx);
4505
+ }
4506
+ const schemas = {};
4507
+ ctx.external = {
4508
+ registry,
4509
+ uri: params?.uri,
4510
+ defs
4511
+ };
4512
+ for (const entry of registry._idmap.entries()) {
4513
+ const [key, schema] = entry;
4514
+ extractDefs(ctx, schema);
4515
+ schemas[key] = finalize(ctx, schema);
4516
+ }
4517
+ if (Object.keys(defs).length > 0) schemas.__shared = { [ctx.target === "draft-2020-12" ? "$defs" : "definitions"]: defs };
4518
+ return { schemas };
4519
+ }
4520
+ const ctx = initializeContext({
4521
+ ...params,
4522
+ processors: allProcessors
4523
+ });
4524
+ process(input, ctx);
4525
+ extractDefs(ctx, input);
4526
+ return finalize(ctx, input);
4527
+ }
4395
4528
  //#endregion
4396
4529
  //#region ../../node_modules/zod/v4/classic/iso.js
4397
4530
  var ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
@@ -5408,7 +5541,7 @@ var ZodIssueCode = {
5408
5541
  var ZodFirstPartyTypeKind;
5409
5542
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5410
5543
  //#endregion
5411
- //#region ../types/dist/sleep-D-Q2_Mcd.mjs
5544
+ //#region ../types/dist/sleep-bZIhUvjd.mjs
5412
5545
  /**
5413
5546
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5414
5547
  * window to float samples (D455).
@@ -5535,7 +5668,7 @@ function isKeychainStoredField(field) {
5535
5668
  var SECRET_CLEAR = { $secretClear: true };
5536
5669
  /** The `'***'` token D634 redaction writes for non-admins. */
5537
5670
  var LEGACY_DEVICE_REDACTION = "***";
5538
- function isRecord$2(value) {
5671
+ function isRecord$5(value) {
5539
5672
  return typeof value === "object" && value !== null && !Array.isArray(value);
5540
5673
  }
5541
5674
  function makeSecretMarker(ref) {
@@ -5546,12 +5679,12 @@ function makeSecretMarker(ref) {
5546
5679
  }
5547
5680
  /** A stored marker: an object whose `$secret` is a non-empty string. */
5548
5681
  function isSecretMarker(value) {
5549
- if (!isRecord$2(value)) return false;
5682
+ if (!isRecord$5(value)) return false;
5550
5683
  const ref = value["$secret"];
5551
5684
  return typeof ref === "string" && ref.length > 0;
5552
5685
  }
5553
5686
  function isSecretClear(value) {
5554
- return isRecord$2(value) && value["$secretClear"] === true;
5687
+ return isRecord$5(value) && value["$secretClear"] === true;
5555
5688
  }
5556
5689
  /**
5557
5690
  * The UI view of a stored secret field value: a marker becomes "set", inline
@@ -6161,7 +6294,7 @@ var KeychainWriteRefusedError = class extends Error {
6161
6294
  }
6162
6295
  };
6163
6296
  var KEEP = { kind: "keep" };
6164
- function isRecord$1(value) {
6297
+ function isRecord$4(value) {
6165
6298
  return typeof value === "object" && value !== null && !Array.isArray(value);
6166
6299
  }
6167
6300
  function defaultMintId() {
@@ -6174,7 +6307,7 @@ function collectSecretMarkerRefs(value, out = []) {
6174
6307
  return out;
6175
6308
  }
6176
6309
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6177
- else if (isRecord$1(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6310
+ else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6178
6311
  return out;
6179
6312
  }
6180
6313
  async function storedValueEquals(secrets, marker, candidate) {
@@ -6229,7 +6362,7 @@ function rowId(row, idKey) {
6229
6362
  return null;
6230
6363
  }
6231
6364
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
6232
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$1) : [];
6365
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
6233
6366
  if (!Array.isArray(incoming)) {
6234
6367
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
6235
6368
  return {
@@ -6245,7 +6378,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
6245
6378
  const kept = /* @__PURE__ */ new Set();
6246
6379
  const rows = [];
6247
6380
  for (const row of incoming) {
6248
- if (!isRecord$1(row)) {
6381
+ if (!isRecord$4(row)) {
6249
6382
  rows.push(row);
6250
6383
  continue;
6251
6384
  }
@@ -6270,7 +6403,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6270
6403
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
6271
6404
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
6272
6405
  case "object": {
6273
- if (!isRecord$1(incoming)) {
6406
+ if (!isRecord$4(incoming)) {
6274
6407
  if (incoming === void 0) return KEEP;
6275
6408
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
6276
6409
  return {
@@ -6278,7 +6411,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
6278
6411
  value: incoming
6279
6412
  };
6280
6413
  }
6281
- const storedObj = isRecord$1(stored) ? stored : {};
6414
+ const storedObj = isRecord$4(stored) ? stored : {};
6282
6415
  return {
6283
6416
  kind: "value",
6284
6417
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -6401,7 +6534,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
6401
6534
  value: items
6402
6535
  };
6403
6536
  }
6404
- if (isRecord$1(v)) {
6537
+ if (isRecord$4(v)) {
6405
6538
  const out = {};
6406
6539
  for (const [k, child] of Object.entries(v)) {
6407
6540
  const s = substitute(child);
@@ -6433,7 +6566,7 @@ var SecretOverwriteRefusedError = class extends Error {
6433
6566
  this.name = "SecretOverwriteRefusedError";
6434
6567
  }
6435
6568
  };
6436
- function isRecord(value) {
6569
+ function isRecord$3(value) {
6437
6570
  return typeof value === "object" && value !== null && !Array.isArray(value);
6438
6571
  }
6439
6572
  function resolvedValue(pass, marker) {
@@ -6462,7 +6595,7 @@ function inArray(pass, incoming, stored) {
6462
6595
  return incoming.map((item, index) => {
6463
6596
  const twin = stored[index];
6464
6597
  if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
6465
- if (isRecord(item) && isRecord(twin)) return inArrayRow(pass, item, twin);
6598
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
6466
6599
  if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
6467
6600
  return item;
6468
6601
  });
@@ -6473,7 +6606,7 @@ function inArrayRow(pass, incoming, stored) {
6473
6606
  const twin = stored[key];
6474
6607
  if (isSecretMarker(twin)) {
6475
6608
  if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
6476
- } else if (isRecord(value) && isRecord(twin)) out[key] = inArrayRow(pass, value, twin);
6609
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
6477
6610
  else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
6478
6611
  }
6479
6612
  return out;
@@ -6481,7 +6614,7 @@ function inArrayRow(pass, incoming, stored) {
6481
6614
  async function walk(pass, incoming, stored) {
6482
6615
  if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
6483
6616
  if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
6484
- if (!isRecord(incoming) || !isRecord(stored)) return incoming;
6617
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
6485
6618
  const out = { ...incoming };
6486
6619
  for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
6487
6620
  return out;
@@ -6512,7 +6645,7 @@ async function restoreUnchangedSecrets(input) {
6512
6645
  function isJsonEqual(a, b) {
6513
6646
  if (Object.is(a, b)) return true;
6514
6647
  if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
6515
- if (isRecord(a) && isRecord(b)) {
6648
+ if (isRecord$3(a) && isRecord$3(b)) {
6516
6649
  const keys = Object.keys(a);
6517
6650
  if (keys.length !== Object.keys(b).length) return false;
6518
6651
  return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
@@ -6536,7 +6669,7 @@ function markerKeysOf(blob, owner) {
6536
6669
  }
6537
6670
  function nodeFromStored(value, owner) {
6538
6671
  if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
6539
- if (!isRecord(value)) return null;
6672
+ if (!isRecord$3(value)) return null;
6540
6673
  const children = /* @__PURE__ */ new Map();
6541
6674
  for (const [key, child] of Object.entries(value)) {
6542
6675
  const node = nodeFromStored(child, owner);
@@ -7324,7 +7457,7 @@ var BaseAddon = class {
7324
7457
  if (!ctx) return;
7325
7458
  const addonId = ctx.id;
7326
7459
  setImmediate(() => {
7327
- ctx.api.addons?.restartAddon?.mutate({ addonId }).then(() => {
7460
+ ctx.api.addons.restartAddon.mutate({ addonId }).then(() => {
7328
7461
  ctx.logger.info("addon auto-restart triggered by restart-required setting change", { meta: { changedFields: patchKeys.filter((k) => restartKeys.has(k)) } });
7329
7462
  }).catch((err) => {
7330
7463
  ctx.logger.error("addon auto-restart failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
@@ -7818,6 +7951,355 @@ var PeerBytesTicketSchema = object({
7818
7951
  */
7819
7952
  declaredBytes: number().int().nonnegative().nullable()
7820
7953
  });
7954
+ /** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
7955
+ /** The files a kind may live in. `history` is device-history's (D850), never records. */
7956
+ var RECORD_DATABASES = ["settings", "events"];
7957
+ /** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
7958
+ var RECORD_CLASSES = [
7959
+ "config",
7960
+ "ledger",
7961
+ "audit",
7962
+ "mirror",
7963
+ "ephemeral"
7964
+ ];
7965
+ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
7966
+ var RECORD_MAX_DATA_BYTES = 1024 * 1024;
7967
+ var RECORD_BATCH_MAX = 1e3;
7968
+ var RECORD_QUERY_MAX = 1e3;
7969
+ /** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
7970
+ var RECORD_SETTINGS_MAX_ROWS = 5e4;
7971
+ var PREFIX = "records/";
7972
+ /** The base of every records failure. `detail` is the human part of the message. */
7973
+ var RecordsError = class extends Error {
7974
+ code;
7975
+ detail;
7976
+ constructor(code, detail) {
7977
+ super(`${PREFIX}${code}: ${detail}`);
7978
+ this.name = "RecordsError";
7979
+ this.code = code;
7980
+ this.detail = detail;
7981
+ }
7982
+ };
7983
+ /** The keychain could not store or serve a value: explicit, never an empty string. */
7984
+ var RecordSecretUnavailableError = class extends RecordsError {
7985
+ constructor(detail) {
7986
+ super("secret-unavailable", detail);
7987
+ this.name = "RecordSecretUnavailableError";
7988
+ }
7989
+ };
7990
+ var InvalidRecordError = class extends RecordsError {
7991
+ constructor(detail) {
7992
+ super("invalid-record", detail);
7993
+ this.name = "InvalidRecordError";
7994
+ }
7995
+ };
7996
+ /** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
7997
+ var DeclarationRefusedError = class extends RecordsError {
7998
+ constructor(detail) {
7999
+ super("declaration-refused", detail);
8000
+ this.name = "DeclarationRefusedError";
8001
+ }
8002
+ };
8003
+ function defOf(schema) {
8004
+ const zodBag = Reflect.get(schema, "_zod");
8005
+ if (typeof zodBag !== "object" || zodBag === null) return {};
8006
+ const def = Reflect.get(zodBag, "def");
8007
+ if (typeof def !== "object" || def === null) return {};
8008
+ return def;
8009
+ }
8010
+ function declaredHere(schema) {
8011
+ return globalRegistry.get(schema)?.secret === true;
8012
+ }
8013
+ /** Wrapper kinds whose `innerType` is the field itself. */
8014
+ var WRAPPERS = new Set([
8015
+ "optional",
8016
+ "nullable",
8017
+ "default",
8018
+ "prefault",
8019
+ "catch",
8020
+ "readonly",
8021
+ "nonoptional"
8022
+ ]);
8023
+ /**
8024
+ * The schema layers that make up ONE field: the schema itself and every
8025
+ * wrapper below it (optional / default / nullable / readonly / catch), plus
8026
+ * both sides of a pipe (`z.preprocess` puts the real schema on `out`,
8027
+ * `.transform` on `in`).
8028
+ */
8029
+ function layersOf(schema) {
8030
+ const out = [];
8031
+ const queue = [schema];
8032
+ while (queue.length > 0) {
8033
+ const s = queue.shift();
8034
+ if (!s || out.includes(s)) continue;
8035
+ out.push(s);
8036
+ const def = defOf(s);
8037
+ if (def.type !== void 0 && WRAPPERS.has(def.type) && def.innerType) queue.push(def.innerType);
8038
+ if (def.type === "pipe") {
8039
+ if (def.in) queue.push(def.in);
8040
+ if (def.out) queue.push(def.out);
8041
+ }
8042
+ }
8043
+ return out;
8044
+ }
8045
+ /** True when any layer of this field declares `.meta({ secret: true })`. */
8046
+ function isZodSecret(schema) {
8047
+ return layersOf(schema).some(declaredHere);
8048
+ }
8049
+ /**
8050
+ * Every declared secret path in a config schema: dotted keys, `[]` for "each
8051
+ * element of this array" (`connection.password`, `rows[].token`). A declared
8052
+ * object or array is reported as one path and not descended into — everything
8053
+ * under it is secret.
8054
+ */
8055
+ function collectZodSecretPaths(schema, prefix = "") {
8056
+ if (isZodSecret(schema)) return prefix.length > 0 ? [prefix] : [];
8057
+ const paths = [];
8058
+ for (const layer of layersOf(schema)) {
8059
+ const def = defOf(layer);
8060
+ if (def.type === "object" && def.shape) for (const [key, child] of Object.entries(def.shape)) paths.push(...collectZodSecretPaths(child, prefix ? `${prefix}.${key}` : key));
8061
+ else if (def.type === "array" && def.element) paths.push(...collectZodSecretPaths(def.element, `${prefix}[]`));
8062
+ else if (def.type === "union" && def.options) for (const option of def.options) paths.push(...collectZodSecretPaths(option, prefix));
8063
+ else if (def.type === "intersection") {
8064
+ if (def.left) paths.push(...collectZodSecretPaths(def.left, prefix));
8065
+ if (def.right) paths.push(...collectZodSecretPaths(def.right, prefix));
8066
+ }
8067
+ }
8068
+ return [...new Set(paths)];
8069
+ }
8070
+ /**
8071
+ * Secret fields of a record, addressed the way a Zod schema declares them
8072
+ * (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
8073
+ * (`auth.accessToken`, `headers[].value`).
8074
+ *
8075
+ * Array elements are matched by a DECLARED id key (`secretArrayKeys`:
8076
+ * `{ headers: 'name' }`), never by index, so reordering a list keeps every
8077
+ * keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
8078
+ * leaf names its element: `headers[X-Api].value`.
8079
+ *
8080
+ * Pure and browser-safe. Nothing here mutates: every transform returns a new value.
8081
+ */
8082
+ /** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
8083
+ function parseSecretPath(path) {
8084
+ if (path.length === 0) throw new InvalidRecordError("an empty secret path");
8085
+ return path.split(".").map((raw) => {
8086
+ const each = raw.endsWith("[]");
8087
+ const key = each ? raw.slice(0, -2) : raw;
8088
+ if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
8089
+ return {
8090
+ key,
8091
+ each
8092
+ };
8093
+ });
8094
+ }
8095
+ /** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
8096
+ function secretArrayPrefixes(path) {
8097
+ const segments = parseSecretPath(path);
8098
+ const prefixes = [];
8099
+ const walked = [];
8100
+ for (const segment of segments) {
8101
+ walked.push(segment.key);
8102
+ if (segment.each) prefixes.push(walked.join("."));
8103
+ }
8104
+ return prefixes;
8105
+ }
8106
+ /**
8107
+ * Record kinds (D881): the declaration an addon makes of one kind of fact, the
8108
+ * Zod row schema that describes it, and the helper that turns the two into the
8109
+ * JSON the engine stores.
8110
+ *
8111
+ * A kind is declared ONCE, next to the code that owns it, and the engine's
8112
+ * reconciler creates its indexes - nothing creates DDL at runtime from a write.
8113
+ * Everything the generic machinery needs (secret fields, the entry descriptor)
8114
+ * is DERIVED from the Zod schema: `.meta({ secret: true })` marks a credential,
8115
+ * never a field name (D879).
8116
+ */
8117
+ /** A JSON field path: `trackId`, `auth.accessToken`. Charset-restricted: it is rendered into DDL. */
8118
+ var RecordFieldPathSchema = string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}(\.[A-Za-z_][A-Za-z0-9_]{0,63}){0,3}$/);
8119
+ var RecordIndexSchema = object({
8120
+ name: string().regex(/^[a-z][a-z0-9_]{0,31}$/),
8121
+ fields: array(RecordFieldPathSchema).min(1).max(4),
8122
+ unique: boolean().optional()
8123
+ }).strict();
8124
+ var RecordRetentionSchema = union([
8125
+ object({
8126
+ ttlMs: number().int().positive(),
8127
+ from: _enum(["at", "write"])
8128
+ }).strict(),
8129
+ object({
8130
+ maxRows: number().int().positive().optional(),
8131
+ maxRowsPerDevice: number().int().positive().optional()
8132
+ }).strict().refine((r) => r.maxRows !== void 0 || r.maxRowsPerDevice !== void 0, { message: "name maxRows, maxRowsPerDevice or both" }),
8133
+ object({
8134
+ owner: string().min(1),
8135
+ reason: string().min(1)
8136
+ }).strict(),
8137
+ object({ none: string().min(1) }).strict()
8138
+ ]);
8139
+ /** The descriptor a generic entries UI reads (D881 "generic entries"). */
8140
+ var EntryDescriptorSchema = object({
8141
+ title: string().min(1),
8142
+ /** The record body field shown as the entry's name. */
8143
+ nameField: string().min(1),
8144
+ /** JSON Schema of the entry body; `secret: true` marks a password field. */
8145
+ fields: record(string(), unknown())
8146
+ }).strict();
8147
+ /** What crosses the wire and sits in the engine's catalog: JSON only, no Zod. */
8148
+ var RecordKindDeclarationSchema = object({
8149
+ database: _enum(RECORD_DATABASES).default("settings"),
8150
+ class: _enum(RECORD_CLASSES),
8151
+ writeTrigger: string().min(1),
8152
+ device: _enum([
8153
+ "required",
8154
+ "optional",
8155
+ "none"
8156
+ ]).default("none"),
8157
+ at: _enum(["required", "none"]).default("none"),
8158
+ indexes: array(RecordIndexSchema).max(8).default([]),
8159
+ retention: RecordRetentionSchema,
8160
+ deviceRemoval: _enum(["delete", "none"]).default("none"),
8161
+ maxDataBytes: number().int().positive().max(RECORD_MAX_DATA_BYTES).default(RECORD_DEFAULT_MAX_DATA_BYTES),
8162
+ /** Derived from the Zod schema; never written by hand. */
8163
+ secretPaths: array(string().min(1)).default([]),
8164
+ /** The id key of each array that carries a secret (`{ headers: 'name' }`). */
8165
+ secretArrayKeys: record(string(), string()).default({}),
8166
+ /** The legacy table this kind adopts from; the boot guard reads it (D853: no migration code). */
8167
+ adoptsFrom: string().min(1).optional(),
8168
+ /** Kinds that must agree through `transact` sit in one file under one family name. */
8169
+ transactFamily: string().min(1).optional(),
8170
+ entry: EntryDescriptorSchema.optional()
8171
+ }).strict();
8172
+ /** The kind names: lower-case, dash separated, short enough for an index name. */
8173
+ var RecordKindNameSchema = string().regex(/^[a-z][a-z0-9-]{0,47}$/);
8174
+ /** Cross-field rules a declaration must satisfy. Throws {@link DeclarationRefusedError}. */
8175
+ function assertValidDeclaration(name, decl) {
8176
+ const refuse = (why) => {
8177
+ throw new DeclarationRefusedError(`kind "${name}": ${why}`);
8178
+ };
8179
+ if (!RecordKindNameSchema.safeParse(name).success) refuse("the name must be lower-case-dashed");
8180
+ const seen = /* @__PURE__ */ new Set();
8181
+ for (const index of decl.indexes) {
8182
+ if (seen.has(index.name)) refuse(`index name "${index.name}" is declared twice`);
8183
+ seen.add(index.name);
8184
+ }
8185
+ const { retention } = decl;
8186
+ const hasSecrets = decl.secretPaths.length > 0;
8187
+ if ("ttlMs" in retention) {
8188
+ if (retention.from === "at" && decl.at !== "required") refuse("a ttl from \"at\" needs at: \"required\"");
8189
+ if (hasSecrets) refuse("a kind with secret fields cannot use engine TTL (its keychain values would be orphaned)");
8190
+ }
8191
+ if ("maxRows" in retention || "maxRowsPerDevice" in retention) {
8192
+ if (retention.maxRowsPerDevice !== void 0 && decl.device !== "required") refuse("maxRowsPerDevice needs device: \"required\"");
8193
+ if (decl.at !== "required") refuse("a row bound trims the oldest \"at\": it needs at: \"required\"");
8194
+ if (hasSecrets) refuse("a kind with secret fields cannot use an engine row bound");
8195
+ const bound = Math.max(retention.maxRows ?? 0, retention.maxRowsPerDevice ?? 0);
8196
+ if (decl.database === "settings" && bound > 5e4) refuse(`a row bound above ${RECORD_SETTINGS_MAX_ROWS} belongs in database: "events" (a big delete on the settings thread stalls every configuration read)`);
8197
+ }
8198
+ if (decl.deviceRemoval === "delete" && decl.device === "none") refuse("deviceRemoval: \"delete\" needs a device: \"required\" or \"optional\"");
8199
+ for (const path of decl.secretPaths) for (const prefix of secretArrayPrefixes(path)) if (decl.secretArrayKeys[prefix] === void 0) refuse(`secret path "${path}" crosses the array "${prefix}": declare its id key in secretArrayKeys`);
8200
+ }
8201
+ function bodyFieldsOf(schema) {
8202
+ return { ...toJSONSchema(schema, {
8203
+ unrepresentable: "any",
8204
+ io: "input"
8205
+ }) };
8206
+ }
8207
+ function isRecordLike(value) {
8208
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8209
+ }
8210
+ /** Does every branch of the body schema carry `field`? (A discriminated union has several.) */
8211
+ function hasNameField(json, field) {
8212
+ const branches = json["oneOf"] ?? json["anyOf"];
8213
+ if (Array.isArray(branches)) return branches.length > 0 && branches.every((b) => isRecordLike(b) && hasNameField(b, field));
8214
+ const properties = json["properties"];
8215
+ return isRecordLike(properties) && Object.prototype.hasOwnProperty.call(properties, field);
8216
+ }
8217
+ /**
8218
+ * Declare the kinds of a package. The keys are the kind names. The result is
8219
+ * what `ctx.records.declare` sends to the engine and what `ctx.records.kind`
8220
+ * types its handle from.
8221
+ */
8222
+ function defineRecordKinds(specs) {
8223
+ const out = {};
8224
+ for (const [name, spec] of Object.entries(specs)) {
8225
+ const secretPaths = collectZodSecretPaths(spec.schema);
8226
+ const nameField = spec.entry?.nameField ?? "name";
8227
+ const fields = bodyFieldsOf(spec.schema);
8228
+ if (spec.entry !== void 0 && !hasNameField(fields, nameField)) throw new DeclarationRefusedError(`kind "${name}": an entry kind's schema needs a "${nameField}" field`);
8229
+ const parsed = RecordKindDeclarationSchema.parse({
8230
+ database: spec.database,
8231
+ class: spec.class,
8232
+ writeTrigger: spec.writeTrigger,
8233
+ device: spec.device,
8234
+ at: spec.at,
8235
+ indexes: spec.indexes === void 0 ? void 0 : [...spec.indexes],
8236
+ retention: spec.retention,
8237
+ deviceRemoval: spec.deviceRemoval,
8238
+ maxDataBytes: spec.maxDataBytes,
8239
+ secretPaths: [...secretPaths],
8240
+ secretArrayKeys: spec.secretArrayKeys === void 0 ? void 0 : { ...spec.secretArrayKeys },
8241
+ adoptsFrom: spec.adoptsFrom,
8242
+ transactFamily: spec.transactFamily,
8243
+ entry: spec.entry === void 0 ? void 0 : {
8244
+ title: spec.entry.title,
8245
+ nameField,
8246
+ fields
8247
+ }
8248
+ });
8249
+ assertValidDeclaration(name, parsed);
8250
+ out[name] = {
8251
+ name,
8252
+ schema: spec.schema,
8253
+ declaration: parsed
8254
+ };
8255
+ }
8256
+ return out;
8257
+ }
8258
+ /**
8259
+ * Entry kinds (D881): every list of user-created entries (notification
8260
+ * targets, brokers, LLM profiles) is ONE record kind with an id, a name and a
8261
+ * kind-specific body, and the admin UI lists/adds/edits/deletes all of them
8262
+ * through the `record-entries` capability with password fields derived from
8263
+ * the schema (`.meta({ secret: true })`).
8264
+ */
8265
+ /** The body of a plain entry: a name and the fields the kind adds. */
8266
+ function entryBody(shape) {
8267
+ return object({
8268
+ name: string().min(1),
8269
+ ...shape
8270
+ });
8271
+ }
8272
+ /**
8273
+ * Declare one entry kind. An entry is configuration: never trimmed by the
8274
+ * engine, never aged, belonging to no device.
8275
+ */
8276
+ function defineEntryKind(name, spec) {
8277
+ const defined = defineRecordKinds({ [name]: {
8278
+ schema: spec.schema,
8279
+ class: "config",
8280
+ writeTrigger: spec.writeTrigger ?? "an operator adds or edits an entry in the entries UI",
8281
+ retention: { none: "an entry goes only when the operator deletes it" },
8282
+ ...spec.database === void 0 ? {} : { database: spec.database },
8283
+ ...spec.indexes === void 0 ? {} : { indexes: spec.indexes },
8284
+ ...spec.secretArrayKeys === void 0 ? {} : { secretArrayKeys: spec.secretArrayKeys },
8285
+ ...spec.adoptsFrom === void 0 ? {} : { adoptsFrom: spec.adoptsFrom },
8286
+ entry: {
8287
+ title: spec.title,
8288
+ ...spec.nameField === void 0 ? {} : { nameField: spec.nameField }
8289
+ }
8290
+ } })[name];
8291
+ if (defined === void 0) throw new DeclarationRefusedError(`entry kind "${name}" was not built`);
8292
+ return defined;
8293
+ }
8294
+ /**
8295
+ * Legacy source for entry adoption (B3): a list stored under addon-settings
8296
+ * `<addonId>.<key>` until records-adopt copies rows into the entry kind.
8297
+ */
8298
+ var SETTINGS_ARRAY_ADOPTS_PREFIX = "@settings-array/";
8299
+ /** The `adoptsFrom` value for an addon-settings array field. */
8300
+ function settingsArrayAdoptsFrom(addonId, settingsKey) {
8301
+ return `${SETTINGS_ARRAY_ADOPTS_PREFIX}${addonId}/${settingsKey}`;
8302
+ }
7821
8303
  /** Shared Zod schemas used across streaming capabilities. */
7822
8304
  var CamProfileSchema = _enum([
7823
8305
  "high",
@@ -16004,6 +16486,222 @@ id: union([string(), number()]) }), {
16004
16486
  kind: "mutation",
16005
16487
  auth: "admin"
16006
16488
  });
16489
+ /**
16490
+ * records - an addon's own facts and documents (D881): ledgers, audit rows,
16491
+ * config documents, mirrors. The third storage API next to `ctx.settings`
16492
+ * (operator intent, D870) and device-history (numbers over time, D850).
16493
+ *
16494
+ * Who the OWNER is: `callerAddonId`, stamped by the transport on a call that
16495
+ * crossed a process and stated by a hub in-process caller (`ctx.records` does
16496
+ * that with the addon id closed over). It is deliberately NOT in any input
16497
+ * schema, so a session can never supply it, and a call with no stamp is refused
16498
+ * `records/no-caller`. A kind is readable and writable only by its owner; other
16499
+ * addons go through the owner's capability.
16500
+ *
16501
+ * Every read is three-way: a row, `null`, or the call THROWS. A failed read is
16502
+ * never `[]`. Secret fields are never on the wire: a read shows the
16503
+ * redaction token, `secretRefs` hands the owner's `ctx.secrets` the refs it
16504
+ * resolves itself, and a write may carry only a keychain marker bound to the
16505
+ * row's own ref.
16506
+ *
16507
+ * Internal: addons reach it through `ctx.records`, never directly.
16508
+ */
16509
+ var RecordIdSchema = string().min(1).max(256);
16510
+ /** A JSON object body. Size is the engine's check (`maxDataBytes`), not a schema's. */
16511
+ var RecordBodySchema = record(string(), unknown());
16512
+ var RecordInputSchema = object({
16513
+ id: RecordIdSchema,
16514
+ /** The device this row belongs to (D865 removal, per-device reads). */
16515
+ deviceId: number().int().optional(),
16516
+ /** The domain clock, ms: observed / created / opened. */
16517
+ at: number().int().optional(),
16518
+ /** Producer-set expiry, ms. Refused on a kind whose retention is an engine TTL. */
16519
+ expiresAt: number().int().optional(),
16520
+ data: RecordBodySchema
16521
+ });
16522
+ var RecordViewSchema = object({
16523
+ id: string(),
16524
+ deviceId: number().int().nullable(),
16525
+ at: number().nullable(),
16526
+ expiresAt: number().nullable(),
16527
+ rev: number().int(),
16528
+ updatedAt: number(),
16529
+ data: RecordBodySchema
16530
+ });
16531
+ /** Declared index fields only. Anything else does not compile, by design. */
16532
+ var RecordWhereSchema = record(RecordFieldPathSchema, union([
16533
+ string(),
16534
+ number(),
16535
+ boolean(),
16536
+ object({ in: array(union([
16537
+ string(),
16538
+ number(),
16539
+ boolean()
16540
+ ])).min(1).max(RECORD_BATCH_MAX) }),
16541
+ object({
16542
+ gt: union([string(), number()]).optional(),
16543
+ gte: union([string(), number()]).optional(),
16544
+ lt: union([string(), number()]).optional(),
16545
+ lte: union([string(), number()]).optional()
16546
+ }).refine((r) => Object.keys(r).length > 0, { message: "name at least one bound" })
16547
+ ]));
16548
+ var KindShape = { kind: RecordKindNameSchema };
16549
+ var TimeWindowShape = {
16550
+ deviceId: number().int().optional(),
16551
+ atFrom: number().optional(),
16552
+ atTo: number().optional()
16553
+ };
16554
+ var RecordQueryInputSchema = object({
16555
+ ...KindShape,
16556
+ ...TimeWindowShape,
16557
+ where: RecordWhereSchema.optional(),
16558
+ /** Without `where`: `at` (default for a kind with a clock) or `id`. With `where` the order is the index's. */
16559
+ order: _enum(["at", "id"]).optional(),
16560
+ desc: boolean().optional(),
16561
+ limit: number().int().min(1).max(RECORD_QUERY_MAX).default(100),
16562
+ /** Opaque keyset cursor from a previous answer. There is no offset. */
16563
+ cursor: string().min(1).optional()
16564
+ });
16565
+ var RecordQueryResultSchema = object({
16566
+ records: array(RecordViewSchema),
16567
+ nextCursor: string().nullable()
16568
+ });
16569
+ var RecordKindStateSchema = _enum([
16570
+ "created",
16571
+ "unchanged",
16572
+ "updated"
16573
+ ]);
16574
+ var DeclareKindResultSchema = object({
16575
+ kindId: number().int(),
16576
+ state: RecordKindStateSchema,
16577
+ createdIndexes: array(string()),
16578
+ /** The boot guard: the kind is empty while its legacy table still holds rows. */
16579
+ adoptionPending: object({
16580
+ legacyTable: string(),
16581
+ legacyRows: number().int()
16582
+ }).nullable()
16583
+ });
16584
+ /** Keychain refs a write released (the old marker is gone from the row): the owner deletes the values. */
16585
+ var SecretRefsList = array(string());
16586
+ var RecordSecretRefsSchema = record(string(), record(string(), string()));
16587
+ method(object({ kinds: record(RecordKindNameSchema, RecordKindDeclarationSchema) }), object({ kinds: record(string(), DeclareKindResultSchema) }), {
16588
+ kind: "mutation",
16589
+ auth: "admin"
16590
+ }), method(object({
16591
+ ...KindShape,
16592
+ id: RecordIdSchema
16593
+ }), RecordViewSchema.nullable(), { auth: "admin" }), method(object({
16594
+ ...KindShape,
16595
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
16596
+ }), array(RecordViewSchema), { auth: "admin" }), method(object({
16597
+ ...KindShape,
16598
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
16599
+ }), RecordSecretRefsSchema, { auth: "admin" }), method(object({
16600
+ ...KindShape,
16601
+ record: RecordInputSchema,
16602
+ /** Compare-and-set. `0` means "the row must not exist". */
16603
+ ifRev: number().int().min(0).optional()
16604
+ }), object({
16605
+ rev: number().int(),
16606
+ releasedRefs: SecretRefsList
16607
+ }), {
16608
+ kind: "mutation",
16609
+ auth: "admin"
16610
+ }), method(object({
16611
+ ...KindShape,
16612
+ records: array(RecordInputSchema).min(1).max(RECORD_BATCH_MAX)
16613
+ }), object({
16614
+ count: number().int(),
16615
+ releasedRefs: SecretRefsList
16616
+ }), {
16617
+ kind: "mutation",
16618
+ auth: "admin"
16619
+ }), method(object({
16620
+ ...KindShape,
16621
+ id: RecordIdSchema,
16622
+ data: RecordBodySchema,
16623
+ at: number().int().nullable().optional(),
16624
+ expiresAt: number().int().nullable().optional(),
16625
+ ifRev: number().int().min(1).optional()
16626
+ }), object({
16627
+ rev: number().int(),
16628
+ releasedRefs: SecretRefsList
16629
+ }), {
16630
+ kind: "mutation",
16631
+ auth: "admin"
16632
+ }), method(object({
16633
+ ...KindShape,
16634
+ id: RecordIdSchema
16635
+ }), object({
16636
+ deleted: boolean(),
16637
+ secretRefs: SecretRefsList
16638
+ }), {
16639
+ kind: "mutation",
16640
+ auth: "admin"
16641
+ }), method(object({
16642
+ ...KindShape,
16643
+ ids: array(RecordIdSchema).min(1).max(RECORD_BATCH_MAX)
16644
+ }), object({
16645
+ deleted: number().int(),
16646
+ secretRefs: SecretRefsList
16647
+ }), {
16648
+ kind: "mutation",
16649
+ auth: "admin"
16650
+ }), method(RecordQueryInputSchema, RecordQueryResultSchema, { auth: "admin" }), method(object({
16651
+ ...KindShape,
16652
+ ...TimeWindowShape,
16653
+ where: RecordWhereSchema.optional()
16654
+ }), object({ count: number().int() }), { auth: "admin" }), method(object({
16655
+ ...KindShape,
16656
+ deviceId: number().int().optional(),
16657
+ from: number(),
16658
+ to: number(),
16659
+ bucketMs: number().int().positive()
16660
+ }), object({ buckets: array(object({
16661
+ bucketStart: number(),
16662
+ count: number().int()
16663
+ })) }), { auth: "admin" }), method(object({
16664
+ ...KindShape,
16665
+ op: _enum([
16666
+ "sum",
16667
+ "min",
16668
+ "max",
16669
+ "count"
16670
+ ]),
16671
+ field: RecordFieldPathSchema.optional(),
16672
+ groupBy: RecordFieldPathSchema.optional(),
16673
+ where: RecordWhereSchema.optional()
16674
+ }), object({ rows: array(object({
16675
+ group: union([
16676
+ string(),
16677
+ number(),
16678
+ _null()
16679
+ ]),
16680
+ value: number().nullable()
16681
+ })) }), { auth: "admin" }), method(object({
16682
+ ...KindShape,
16683
+ deviceId: number().int().optional(),
16684
+ atBefore: number().optional(),
16685
+ where: RecordWhereSchema.optional()
16686
+ }), object({
16687
+ deleted: number().int(),
16688
+ secretRefs: SecretRefsList
16689
+ }), {
16690
+ kind: "mutation",
16691
+ auth: "admin"
16692
+ }), method(object({
16693
+ deviceId: number().int(),
16694
+ kinds: array(RecordKindNameSchema).optional()
16695
+ }), object({
16696
+ deleted: record(string(), number().int()),
16697
+ secretRefs: SecretRefsList
16698
+ }), {
16699
+ kind: "mutation",
16700
+ auth: "admin"
16701
+ }), method(object(KindShape), object({ id: number().int() }), {
16702
+ kind: "mutation",
16703
+ auth: "admin"
16704
+ });
16007
16705
  /** One table of the settings database. */
16008
16706
  var StorageTableSchema = object({
16009
16707
  /** The table's full name, e.g. `recorder:addon-settings` or `addon-device-settings`. */
@@ -16016,6 +16714,28 @@ var StorageTableSchema = object({
16016
16714
  /** Declared by an addon since this engine process started (a running addon claims it). */
16017
16715
  declaredThisBoot: boolean()
16018
16716
  });
16717
+ /** One declared record kind (D881) as System -> Data shows it. */
16718
+ var StorageKindSchema = object({
16719
+ owner: string(),
16720
+ kind: string(),
16721
+ database: _enum(["settings", "events"]),
16722
+ class: string(),
16723
+ state: _enum([
16724
+ "declared",
16725
+ "orphaned",
16726
+ "dropped"
16727
+ ]),
16728
+ /** `null` when the caller asked for no counts (`counts: false`). */
16729
+ rows: number().int().nonnegative().nullable(),
16730
+ /** Rows x the average size of a sample; null for an empty kind. */
16731
+ bytesEstimate: number().int().nonnegative().nullable(),
16732
+ writeTrigger: string(),
16733
+ retention: RecordRetentionSchema,
16734
+ /** `true` when the kind is an entry kind (the generic entries UI lists it). */
16735
+ entry: boolean(),
16736
+ /** The whole declaration, secret paths and entry descriptor included (the entries service builds its handle from it). */
16737
+ declaration: RecordKindDeclarationSchema
16738
+ });
16019
16739
  method(object({ ownerPrefix: string().min(1).optional() }), object({ tables: array(StorageTableSchema) }), { auth: "admin" }), method(object({
16020
16740
  collection: string().min(1),
16021
16741
  expectRows: number().int().nonnegative()
@@ -16025,6 +16745,87 @@ method(object({ ownerPrefix: string().min(1).optional() }), object({ tables: arr
16025
16745
  }), {
16026
16746
  kind: "mutation",
16027
16747
  auth: "admin"
16748
+ }), method(object({
16749
+ owner: string().min(1).optional(),
16750
+ /** `false` skips the per-kind row count (a catalog read only). Default true. */
16751
+ counts: boolean().optional()
16752
+ }), object({ kinds: array(StorageKindSchema) }), { auth: "admin" }), method(RecordQueryInputSchema.extend({
16753
+ owner: string().min(1),
16754
+ kind: RecordKindNameSchema
16755
+ }), RecordQueryResultSchema, { auth: "admin" }), method(object({
16756
+ owner: string().min(1),
16757
+ kind: RecordKindNameSchema,
16758
+ records: array(RecordInputSchema).max(RECORD_BATCH_MAX),
16759
+ /** The LAST batch: the copy is complete, the boot guard stops asking. */
16760
+ complete: boolean().optional()
16761
+ }).refine((input) => input.records.length > 0 || input.complete === true, { message: "records must be non-empty unless complete is true" }), object({ adopted: number().int() }), {
16762
+ kind: "mutation",
16763
+ auth: "admin"
16764
+ }), method(object({
16765
+ collection: string().min(1),
16766
+ cursor: string().optional(),
16767
+ limit: number().int().min(1).max(1e3).optional()
16768
+ }), object({
16769
+ rows: array(object({
16770
+ id: string(),
16771
+ data: record(string(), unknown())
16772
+ })),
16773
+ nextCursor: string().nullable()
16774
+ }), { auth: "admin" }), method(object({ collection: string().min(1) }), object({ adopted: boolean() }), { auth: "admin" });
16775
+ /**
16776
+ * record-entries - the ONE admin surface for every list of user-created entries
16777
+ * (D881): notification targets, brokers, LLM profiles, anything an addon
16778
+ * declares as an ENTRY kind (`entry: { title }` in `defineRecordKinds`).
16779
+ *
16780
+ * The UI is generic. `listEntryKinds` hands it, per kind, the JSON Schema of
16781
+ * the entry body with `secret: true` on every credential field, so a password
16782
+ * field is derived from the schema and never from a name. `putEntry` takes the
16783
+ * redaction token for an untouched secret (the stored value is kept), a string
16784
+ * for a new one, and the clear instruction to remove one. A read never carries
16785
+ * a secret value, and a locked keychain refuses the write with
16786
+ * `records/secret-unavailable` instead of storing plaintext.
16787
+ *
16788
+ * Hub-only, served in-process (it acts for each entry's owner on the keychain).
16789
+ */
16790
+ var EntryKindInfoSchema = object({
16791
+ owner: string(),
16792
+ kind: RecordKindNameSchema,
16793
+ title: string(),
16794
+ nameField: string(),
16795
+ /** JSON Schema of the body; `secret: true` marks a password field. */
16796
+ fields: record(string(), unknown()),
16797
+ secretPaths: array(string()),
16798
+ rows: number().int().nonnegative()
16799
+ });
16800
+ var EntryViewSchema = object({
16801
+ id: RecordIdSchema,
16802
+ name: string(),
16803
+ rev: number().int(),
16804
+ updatedAt: number(),
16805
+ /** Secret fields hold the redaction token. */
16806
+ data: RecordBodySchema
16807
+ });
16808
+ var EntryAddress = {
16809
+ owner: string().min(1),
16810
+ kind: RecordKindNameSchema
16811
+ };
16812
+ method(object({}), object({ kinds: array(EntryKindInfoSchema) }), { auth: "admin" }), method(object({ ...EntryAddress }), object({ entries: array(EntryViewSchema) }), { auth: "admin" }), method(object({
16813
+ ...EntryAddress,
16814
+ id: RecordIdSchema.optional(),
16815
+ data: RecordBodySchema,
16816
+ ifRev: number().int().min(1).optional()
16817
+ }), object({
16818
+ id: string(),
16819
+ rev: number().int()
16820
+ }), {
16821
+ kind: "mutation",
16822
+ auth: "admin"
16823
+ }), method(object({
16824
+ ...EntryAddress,
16825
+ id: RecordIdSchema
16826
+ }), object({ deleted: boolean() }), {
16827
+ kind: "mutation",
16828
+ auth: "admin"
16028
16829
  });
16029
16830
  /**
16030
16831
  * `keychain` — the hub's encrypted store of secret values (D787).
@@ -67088,6 +67889,30 @@ Object.freeze({
67088
67889
  addonId: null,
67089
67890
  access: "create"
67090
67891
  },
67892
+ "recordEntries.deleteEntry": {
67893
+ capName: "record-entries",
67894
+ capScope: "system",
67895
+ addonId: null,
67896
+ access: "delete"
67897
+ },
67898
+ "recordEntries.listEntries": {
67899
+ capName: "record-entries",
67900
+ capScope: "system",
67901
+ addonId: null,
67902
+ access: "view"
67903
+ },
67904
+ "recordEntries.listEntryKinds": {
67905
+ capName: "record-entries",
67906
+ capScope: "system",
67907
+ addonId: null,
67908
+ access: "view"
67909
+ },
67910
+ "recordEntries.putEntry": {
67911
+ capName: "record-entries",
67912
+ capScope: "system",
67913
+ addonId: null,
67914
+ access: "create"
67915
+ },
67091
67916
  "recording.getAvailability": {
67092
67917
  capName: "recording",
67093
67918
  capScope: "device",
@@ -67388,6 +68213,102 @@ Object.freeze({
67388
68213
  addonId: null,
67389
68214
  access: "view"
67390
68215
  },
68216
+ "records.aggregate": {
68217
+ capName: "records",
68218
+ capScope: "system",
68219
+ addonId: null,
68220
+ access: "view"
68221
+ },
68222
+ "records.allocateId": {
68223
+ capName: "records",
68224
+ capScope: "system",
68225
+ addonId: null,
68226
+ access: "create"
68227
+ },
68228
+ "records.count": {
68229
+ capName: "records",
68230
+ capScope: "system",
68231
+ addonId: null,
68232
+ access: "view"
68233
+ },
68234
+ "records.declareKinds": {
68235
+ capName: "records",
68236
+ capScope: "system",
68237
+ addonId: null,
68238
+ access: "create"
68239
+ },
68240
+ "records.delete": {
68241
+ capName: "records",
68242
+ capScope: "system",
68243
+ addonId: null,
68244
+ access: "delete"
68245
+ },
68246
+ "records.deleteDevice": {
68247
+ capName: "records",
68248
+ capScope: "system",
68249
+ addonId: null,
68250
+ access: "delete"
68251
+ },
68252
+ "records.deleteMany": {
68253
+ capName: "records",
68254
+ capScope: "system",
68255
+ addonId: null,
68256
+ access: "delete"
68257
+ },
68258
+ "records.deleteWhere": {
68259
+ capName: "records",
68260
+ capScope: "system",
68261
+ addonId: null,
68262
+ access: "delete"
68263
+ },
68264
+ "records.get": {
68265
+ capName: "records",
68266
+ capScope: "system",
68267
+ addonId: null,
68268
+ access: "view"
68269
+ },
68270
+ "records.getMany": {
68271
+ capName: "records",
68272
+ capScope: "system",
68273
+ addonId: null,
68274
+ access: "view"
68275
+ },
68276
+ "records.histogram": {
68277
+ capName: "records",
68278
+ capScope: "system",
68279
+ addonId: null,
68280
+ access: "view"
68281
+ },
68282
+ "records.patch": {
68283
+ capName: "records",
68284
+ capScope: "system",
68285
+ addonId: null,
68286
+ access: "create"
68287
+ },
68288
+ "records.put": {
68289
+ capName: "records",
68290
+ capScope: "system",
68291
+ addonId: null,
68292
+ access: "create"
68293
+ },
68294
+ "records.putMany": {
68295
+ capName: "records",
68296
+ capScope: "system",
68297
+ addonId: null,
68298
+ access: "create"
68299
+ },
68300
+ "records.query": {
68301
+ capName: "records",
68302
+ capScope: "system",
68303
+ addonId: null,
68304
+ access: "view"
68305
+ },
68306
+ "records.secretRefs": {
68307
+ capName: "records",
68308
+ capScope: "system",
68309
+ addonId: null,
68310
+ access: "view"
68311
+ },
67391
68312
  "sceneMonitor.captureReference": {
67392
68313
  capName: "scene-monitor",
67393
68314
  capScope: "device",
@@ -67820,18 +68741,48 @@ Object.freeze({
67820
68741
  addonId: null,
67821
68742
  access: "create"
67822
68743
  },
68744
+ "storageAdmin.adoptRecords": {
68745
+ capName: "storage-admin",
68746
+ capScope: "system",
68747
+ addonId: null,
68748
+ access: "create"
68749
+ },
67823
68750
  "storageAdmin.dropCollection": {
67824
68751
  capName: "storage-admin",
67825
68752
  capScope: "system",
67826
68753
  addonId: null,
67827
68754
  access: "delete"
67828
68755
  },
68756
+ "storageAdmin.isAdoptedLegacyTable": {
68757
+ capName: "storage-admin",
68758
+ capScope: "system",
68759
+ addonId: null,
68760
+ access: "view"
68761
+ },
68762
+ "storageAdmin.listKinds": {
68763
+ capName: "storage-admin",
68764
+ capScope: "system",
68765
+ addonId: null,
68766
+ access: "view"
68767
+ },
67829
68768
  "storageAdmin.listTables": {
67830
68769
  capName: "storage-admin",
67831
68770
  capScope: "system",
67832
68771
  addonId: null,
67833
68772
  access: "view"
67834
68773
  },
68774
+ "storageAdmin.readLegacyCollection": {
68775
+ capName: "storage-admin",
68776
+ capScope: "system",
68777
+ addonId: null,
68778
+ access: "view"
68779
+ },
68780
+ "storageAdmin.readRecords": {
68781
+ capName: "storage-admin",
68782
+ capScope: "system",
68783
+ addonId: null,
68784
+ access: "view"
68785
+ },
67835
68786
  "storageEvictable.evict": {
67836
68787
  capName: "storage-evictable",
67837
68788
  capScope: "system",
@@ -71426,6 +72377,37 @@ Object.freeze({
71426
72377
  form: "single",
71427
72378
  optional: false
71428
72379
  }],
72380
+ "records.count": [{
72381
+ name: "deviceId",
72382
+ form: "single",
72383
+ optional: true
72384
+ }],
72385
+ "records.deleteDevice": [{
72386
+ name: "deviceId",
72387
+ form: "single",
72388
+ optional: false
72389
+ }],
72390
+ "records.deleteWhere": [{
72391
+ name: "deviceId",
72392
+ form: "single",
72393
+ optional: true
72394
+ }],
72395
+ "records.histogram": [{
72396
+ name: "deviceId",
72397
+ form: "single",
72398
+ optional: true
72399
+ }],
72400
+ "records.putMany": [{
72401
+ name: "records",
72402
+ form: "object-array",
72403
+ optional: false,
72404
+ itemField: "deviceId"
72405
+ }],
72406
+ "records.query": [{
72407
+ name: "deviceId",
72408
+ form: "single",
72409
+ optional: true
72410
+ }],
71429
72411
  "sceneMonitor.captureReference": [{
71430
72412
  name: "deviceId",
71431
72413
  form: "single",
@@ -71542,6 +72524,17 @@ Object.freeze({
71542
72524
  form: "single",
71543
72525
  optional: false
71544
72526
  }],
72527
+ "storageAdmin.adoptRecords": [{
72528
+ name: "records",
72529
+ form: "object-array",
72530
+ optional: false,
72531
+ itemField: "deviceId"
72532
+ }],
72533
+ "storageAdmin.readRecords": [{
72534
+ name: "deviceId",
72535
+ form: "single",
72536
+ optional: true
72537
+ }],
71545
72538
  "streamBroker.acquireEgressTranscode": [{
71546
72539
  name: "deviceId",
71547
72540
  form: "single",
@@ -73372,7 +74365,31 @@ function createWasteCalendarSource(deps) {
73372
74365
  }
73373
74366
  //#endregion
73374
74367
  //#region src/waste-catalog.ts
73375
- var catalog = {
74368
+ var catalog = object({
74369
+ generatedAt: string(),
74370
+ sourceHash: string(),
74371
+ countries: array(object({
74372
+ id: string(),
74373
+ label: string()
74374
+ })),
74375
+ services: array(object({
74376
+ id: string(),
74377
+ countryId: string(),
74378
+ label: string(),
74379
+ module: string(),
74380
+ defaultArgs: record(string(), string()),
74381
+ fields: array(object({
74382
+ key: string(),
74383
+ label: string(),
74384
+ required: boolean(),
74385
+ kind: _enum([
74386
+ "text",
74387
+ "number",
74388
+ "boolean"
74389
+ ])
74390
+ }))
74391
+ }))
74392
+ }).parse({
73376
74393
  generatedAt: "2026-10-12T16:54:36.612Z",
73377
74394
  sourceHash: "35f2f21decca0a4beae07ec89164a2ae5ea34ff5832c440a046d79d69b5963ea",
73378
74395
  entries: [
@@ -159239,7 +160256,7 @@ var catalog = {
159239
160256
  }]
159240
160257
  }
159241
160258
  ]
159242
- };
160259
+ });
159243
160260
  function listCatalogCountries() {
159244
160261
  return catalog.countries;
159245
160262
  }
@@ -159366,6 +160383,79 @@ function allocateSourceId(label, existingIds) {
159366
160383
  throw new Error("could not allocate a unique source id");
159367
160384
  }
159368
160385
  //#endregion
160386
+ //#region src/waste-source-record-kinds.ts
160387
+ var WASTE_COLLECTIONS_OWNER = "waste-collections";
160388
+ var WasteSourceBodySchema = entryBody({
160389
+ module: string().min(1),
160390
+ args: preprocess((v) => v ?? {}, record(string(), WasteArgValueSchema)),
160391
+ enabled: boolean().default(true)
160392
+ });
160393
+ var wasteSourceEntryKind = defineEntryKind("waste-source", {
160394
+ title: "Waste collection sources",
160395
+ schema: WasteSourceBodySchema,
160396
+ writeTrigger: "an operator adds or edits a municipal waste calendar source",
160397
+ adoptsFrom: settingsArrayAdoptsFrom(WASTE_COLLECTIONS_OWNER, "sources")
160398
+ });
160399
+ //#endregion
160400
+ //#region src/waste-source-store.ts
160401
+ function rowToSource(id, data) {
160402
+ const parsed = WasteSourceConfigSchema.safeParse({
160403
+ id,
160404
+ label: data.name,
160405
+ module: data.module,
160406
+ args: data.args,
160407
+ enabled: data.enabled
160408
+ });
160409
+ return parsed.success ? parsed.data : null;
160410
+ }
160411
+ var WasteSourceStore = class WasteSourceStore {
160412
+ kind;
160413
+ constructor(kind) {
160414
+ this.kind = kind;
160415
+ }
160416
+ static of(records) {
160417
+ return new WasteSourceStore(records.kind(wasteSourceEntryKind));
160418
+ }
160419
+ async listResolved() {
160420
+ const page = await this.kind.query({ limit: 1e3 });
160421
+ const out = [];
160422
+ for (const record of page.records) {
160423
+ let data = record.data;
160424
+ try {
160425
+ const resolved = await this.kind.getResolved(record.id);
160426
+ if (resolved !== null) data = resolved.data;
160427
+ } catch (err) {
160428
+ if (!(err instanceof RecordSecretUnavailableError)) throw err;
160429
+ }
160430
+ const parsed = WasteSourceBodySchema.safeParse(data);
160431
+ if (!parsed.success) continue;
160432
+ const row = rowToSource(record.id, parsed.data);
160433
+ if (row !== null) out.push(row);
160434
+ }
160435
+ return out;
160436
+ }
160437
+ async replaceAll(sources) {
160438
+ const page = await this.kind.query({ limit: 1e3 });
160439
+ const nextIds = new Set(sources.map((s) => s.id));
160440
+ for (const row of page.records) if (!nextIds.has(row.id)) await this.kind.delete(row.id);
160441
+ for (const source of sources) {
160442
+ const { id, label, module, args, enabled } = source;
160443
+ const body = {
160444
+ name: label,
160445
+ module,
160446
+ args,
160447
+ enabled
160448
+ };
160449
+ const parsed = wasteSourceEntryKind.schema.safeParse(body);
160450
+ if (!parsed.success) throw new Error(`invalid waste source '${id}': ${parsed.error.message}`);
160451
+ await this.kind.put({
160452
+ id,
160453
+ data: parsed.data
160454
+ });
160455
+ }
160456
+ }
160457
+ };
160458
+ //#endregion
159369
160459
  //#region src/waste-collections.addon.ts
159370
160460
  /**
159371
160461
  * Waste Collections — hub-only calendar-source over the vendored HACS
@@ -159380,12 +160470,23 @@ var WasteCollectionsAddon = class extends BaseAddon {
159380
160470
  cache = /* @__PURE__ */ new Map();
159381
160471
  refreshTimer = null;
159382
160472
  refreshInFlight = null;
160473
+ sourceStore = null;
160474
+ activeSources = [];
159383
160475
  constructor() {
159384
160476
  super({ ...DEFAULT_WASTE_CONFIG });
159385
160477
  }
159386
160478
  async onInitialize() {
159387
160479
  this.scriptPath = resolveFetchScript();
159388
160480
  this.loadCacheFromDisk();
160481
+ const records = this.ctx.records;
160482
+ if (records === void 0) throw new Error("waste-collections: ctx.records is required (hub-only addon)");
160483
+ await records.declare({ "waste-source": wasteSourceEntryKind });
160484
+ this.sourceStore = WasteSourceStore.of(records);
160485
+ this.activeSources = await this.loadPersistedSources();
160486
+ if ((await this.sourceStore.listResolved()).length === 0 && this.config.sources.length > 0) {
160487
+ await this.sourceStore.replaceAll(this.parseConfigSources(this.config.sources));
160488
+ this.activeSources = await this.loadPersistedSources();
160489
+ }
159389
160490
  try {
159390
160491
  this.pythonPath = await this.ctx.deps.ensurePython();
159391
160492
  } catch (err) {
@@ -159443,6 +160544,7 @@ var WasteCollectionsAddon = class extends BaseAddon {
159443
160544
  };
159444
160545
  }
159445
160546
  async onConfigChanged() {
160547
+ this.activeSources = await this.loadPersistedSources();
159446
160548
  const ids = new Set(this.configuredSources().map((s) => s.id));
159447
160549
  for (const key of [...this.cache.keys()]) if (!ids.has(key)) this.cache.delete(key);
159448
160550
  this.persistCache();
@@ -159453,15 +160555,36 @@ var WasteCollectionsAddon = class extends BaseAddon {
159453
160555
  * is skipped AND logged: a source that silently vanishes reads as a calendar
159454
160556
  * that never existed.
159455
160557
  */
159456
- configuredSources() {
160558
+ parseConfigSources(rawList) {
159457
160559
  const out = [];
159458
- for (const raw of this.config.sources) {
160560
+ for (const raw of rawList) {
159459
160561
  const parsed = WasteSourceConfigSchema.safeParse(raw);
159460
160562
  if (parsed.success) out.push(parsed.data);
159461
- else this.ctx.logger.warn("waste-collections: a stored source does not parse - skipped", { meta: { sourceId: typeof raw?.id === "string" ? raw.id : null } });
160563
+ else this.ctx.logger.warn("waste-collections: a stored source does not parse - skipped", { meta: { sourceId: typeof raw === "object" && raw !== null && "id" in raw && typeof raw.id === "string" ? raw.id : null } });
159462
160564
  }
159463
160565
  return out;
159464
160566
  }
160567
+ async loadPersistedSources() {
160568
+ const store = this.sourceStore;
160569
+ if (store !== null) {
160570
+ const fromRecords = await store.listResolved();
160571
+ if (fromRecords.length > 0) return fromRecords;
160572
+ }
160573
+ return this.parseConfigSources(this.config.sources);
160574
+ }
160575
+ async persistSources(sources) {
160576
+ this.activeSources = [...sources];
160577
+ const store = this.sourceStore;
160578
+ if (store !== null) {
160579
+ await store.replaceAll(sources);
160580
+ return;
160581
+ }
160582
+ await this.updateGlobalSettings({ sources: [...sources] });
160583
+ }
160584
+ configuredSources() {
160585
+ if (this.activeSources.length > 0) return this.activeSources;
160586
+ return this.parseConfigSources(this.config.sources);
160587
+ }
159465
160588
  listSources() {
159466
160589
  return this.configuredSources().map((s) => {
159467
160590
  let args = {};
@@ -159505,7 +160628,7 @@ var WasteCollectionsAddon = class extends BaseAddon {
159505
160628
  args: this.typedArgs(mergeServiceArgs(service, restoreRedactedArgs(input.args, {}))),
159506
160629
  enabled: input.enabled ?? true
159507
160630
  });
159508
- await this.updateGlobalSettings({ sources: [...this.configuredSources(), row] });
160631
+ await this.persistSources([...this.configuredSources(), row]);
159509
160632
  return { id };
159510
160633
  }
159511
160634
  async updateSource(input) {
@@ -159541,7 +160664,7 @@ var WasteCollectionsAddon = class extends BaseAddon {
159541
160664
  args: this.typedArgs(args),
159542
160665
  enabled: input.enabled ?? prev.enabled
159543
160666
  });
159544
- await this.updateGlobalSettings({ sources: sources.map((s, i) => i === idx ? next : s) });
160667
+ await this.persistSources(sources.map((s, i) => i === idx ? next : s));
159545
160668
  return { ok: true };
159546
160669
  }
159547
160670
  /** Validate an argument bag against the typed value schema (a nested object is refused). */
@@ -159608,7 +160731,7 @@ var WasteCollectionsAddon = class extends BaseAddon {
159608
160731
  remainingRaw: legacy.length
159609
160732
  });
159610
160733
  try {
159611
- await this.updateGlobalSettings({ sources: migrated });
160734
+ await this.persistSources(migrated);
159612
160735
  } catch {
159613
160736
  return report({ failed: legacy.length });
159614
160737
  }
@@ -159648,7 +160771,7 @@ var WasteCollectionsAddon = class extends BaseAddon {
159648
160771
  async deleteSource(input) {
159649
160772
  const sources = this.configuredSources();
159650
160773
  if (!sources.some((s) => s.id === input.id)) throw new Error(`source '${input.id}' not found`);
159651
- await this.updateGlobalSettings({ sources: sources.filter((s) => s.id !== input.id) });
160774
+ await this.persistSources(sources.filter((s) => s.id !== input.id));
159652
160775
  return { ok: true };
159653
160776
  }
159654
160777
  async fetchNow(input) {