@oddington/sdk 0.1.74 → 0.1.75

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/browser.js CHANGED
@@ -2098,11 +2098,11 @@ var require_luxon = /* @__PURE__ */ __commonJS({
2098
2098
  static invalid(reason, explanation = null) {
2099
2099
  if (!reason)
2100
2100
  throw new InvalidArgumentError("need to specify a reason the Duration is invalid");
2101
- let invalid13 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
2101
+ let invalid14 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
2102
2102
  if (Settings.throwOnInvalid)
2103
- throw new InvalidDurationError(invalid13);
2103
+ throw new InvalidDurationError(invalid14);
2104
2104
  return new _Duration({
2105
- invalid: invalid13
2105
+ invalid: invalid14
2106
2106
  });
2107
2107
  }
2108
2108
  static normalizeUnit(unit) {
@@ -2369,11 +2369,11 @@ var require_luxon = /* @__PURE__ */ __commonJS({
2369
2369
  static invalid(reason, explanation = null) {
2370
2370
  if (!reason)
2371
2371
  throw new InvalidArgumentError("need to specify a reason the Interval is invalid");
2372
- let invalid13 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
2372
+ let invalid14 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
2373
2373
  if (Settings.throwOnInvalid)
2374
- throw new InvalidIntervalError(invalid13);
2374
+ throw new InvalidIntervalError(invalid14);
2375
2375
  return new _Interval({
2376
- invalid: invalid13
2376
+ invalid: invalid14
2377
2377
  });
2378
2378
  }
2379
2379
  static fromDateTimes(start, end) {
@@ -3230,9 +3230,9 @@ var require_luxon = /* @__PURE__ */ __commonJS({
3230
3230
  else {
3231
3231
  for (let u of orderedUnits)
3232
3232
  isUndefined(obj[u]) && (obj[u] = defaultUnitValues[u]);
3233
- let invalid13 = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
3234
- if (invalid13)
3235
- return DateTime.invalid(invalid13);
3233
+ let invalid14 = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
3234
+ if (invalid14)
3235
+ return DateTime.invalid(invalid14);
3236
3236
  let offsetProvis = guessOffsetForZone(zone);
3237
3237
  [ts, o] = objToTS(obj, offsetProvis, zone);
3238
3238
  }
@@ -3260,17 +3260,17 @@ var require_luxon = /* @__PURE__ */ __commonJS({
3260
3260
  }
3261
3261
  var zoneOffsetTs, zoneOffsetGuessCache = /* @__PURE__ */ new Map(), DateTime = class _DateTime {
3262
3262
  constructor(config) {
3263
- let zone = config.zone || Settings.defaultZone, invalid13 = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (zone.isValid ? null : unsupportedZone(zone));
3263
+ let zone = config.zone || Settings.defaultZone, invalid14 = config.invalid || (Number.isNaN(config.ts) ? new Invalid("invalid input") : null) || (zone.isValid ? null : unsupportedZone(zone));
3264
3264
  this.ts = isUndefined(config.ts) ? Settings.now() : config.ts;
3265
3265
  let c = null, o = null;
3266
- if (!invalid13)
3266
+ if (!invalid14)
3267
3267
  if (config.old && config.old.ts === this.ts && config.old.zone.equals(zone))
3268
3268
  [c, o] = [config.old.c, config.old.o];
3269
3269
  else {
3270
3270
  let ot = isNumber(config.o) && !config.old ? config.o : zone.offset(this.ts);
3271
- c = tsToObj(this.ts, ot), invalid13 = Number.isNaN(c.year) ? new Invalid("invalid input") : null, c = invalid13 ? null : c, o = invalid13 ? null : ot;
3271
+ c = tsToObj(this.ts, ot), invalid14 = Number.isNaN(c.year) ? new Invalid("invalid input") : null, c = invalid14 ? null : c, o = invalid14 ? null : ot;
3272
3272
  }
3273
- this._zone = zone, this.loc = config.loc || Locale.create(), this.invalid = invalid13, this.weekData = null, this.localWeekData = null, this.c = c, this.o = o, this.isLuxonDateTime = !0;
3273
+ this._zone = zone, this.loc = config.loc || Locale.create(), this.invalid = invalid14, this.weekData = null, this.localWeekData = null, this.c = c, this.o = o, this.isLuxonDateTime = !0;
3274
3274
  }
3275
3275
  // CONSTRUCT
3276
3276
  static now() {
@@ -3349,9 +3349,9 @@ var require_luxon = /* @__PURE__ */ __commonJS({
3349
3349
  let v = normalized[u];
3350
3350
  isUndefined(v) ? foundFirst ? normalized[u] = defaultValues[u] : normalized[u] = objNow[u] : foundFirst = !0;
3351
3351
  }
3352
- let higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), invalid13 = higherOrderInvalid || hasInvalidTimeData(normalized);
3353
- if (invalid13)
3354
- return _DateTime.invalid(invalid13);
3352
+ let higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), invalid14 = higherOrderInvalid || hasInvalidTimeData(normalized);
3353
+ if (invalid14)
3354
+ return _DateTime.invalid(invalid14);
3355
3355
  let gregorian = useWeekData ? weekToGregorian(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? ordinalToGregorian(normalized) : normalized, [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse), inst = new _DateTime({
3356
3356
  ts: tsFinal,
3357
3357
  zone: zoneToUse,
@@ -3382,8 +3382,8 @@ var require_luxon = /* @__PURE__ */ __commonJS({
3382
3382
  locale,
3383
3383
  numberingSystem,
3384
3384
  defaultToEN: !0
3385
- }), [vals, parsedZone, specificOffset, invalid13] = parseFromTokens(localeToUse, text5, fmt);
3386
- return invalid13 ? _DateTime.invalid(invalid13) : parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text5, specificOffset);
3385
+ }), [vals, parsedZone, specificOffset, invalid14] = parseFromTokens(localeToUse, text5, fmt);
3386
+ return invalid14 ? _DateTime.invalid(invalid14) : parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text5, specificOffset);
3387
3387
  }
3388
3388
  static fromString(text5, fmt, opts = {}) {
3389
3389
  return _DateTime.fromFormat(text5, fmt, opts);
@@ -3395,11 +3395,11 @@ var require_luxon = /* @__PURE__ */ __commonJS({
3395
3395
  static invalid(reason, explanation = null) {
3396
3396
  if (!reason)
3397
3397
  throw new InvalidArgumentError("need to specify a reason the DateTime is invalid");
3398
- let invalid13 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
3398
+ let invalid14 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
3399
3399
  if (Settings.throwOnInvalid)
3400
- throw new InvalidDateTimeError(invalid13);
3400
+ throw new InvalidDateTimeError(invalid14);
3401
3401
  return new _DateTime({
3402
- invalid: invalid13
3402
+ invalid: invalid14
3403
3403
  });
3404
3404
  }
3405
3405
  static isDateTime(o) {
@@ -5039,40 +5039,40 @@ var FileOperationError = class extends Error {
5039
5039
  };
5040
5040
  var FILE_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, FILE_ORIGINAL_MAX_BYTES = 5 * 1024 ** 3;
5041
5041
  function parseFileDescriptor(value) {
5042
- let invalid13 = () => {
5042
+ let invalid14 = () => {
5043
5043
  throw new FileOperationError("unavailable", 503, !0);
5044
5044
  };
5045
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
5045
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
5046
5046
  let f = value;
5047
- if (Object.keys(f).sort().join(",") !== "enrichments,id,mediaType,name,path,sha256,size" || typeof f.id != "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size > FILE_ORIGINAL_MAX_BYTES || typeof f.sha256 != "string" || !/^[0-9a-f]{64}$/.test(f.sha256) || !f.enrichments || typeof f.enrichments != "object" || Array.isArray(f.enrichments) || !isCanonicalOriginalMediaType(f.mediaType)) return invalid13();
5047
+ if (Object.keys(f).sort().join(",") !== "enrichments,id,mediaType,name,path,sha256,size" || typeof f.id != "string" || !FILE_ID_PATTERN.test(f.id) || !safeFileName(f.name) || !safeFilePath(f.path) || !Number.isSafeInteger(f.size) || f.size < 0 || f.size > FILE_ORIGINAL_MAX_BYTES || typeof f.sha256 != "string" || !/^[0-9a-f]{64}$/.test(f.sha256) || !f.enrichments || typeof f.enrichments != "object" || Array.isArray(f.enrichments) || !isCanonicalOriginalMediaType(f.mediaType)) return invalid14();
5048
5048
  for (let [name2, descriptor] of Object.entries(f.enrichments)) {
5049
- if (!safeEnrichmentName(name2)) return invalid13();
5049
+ if (!safeEnrichmentName(name2)) return invalid14();
5050
5050
  parseEnrichmentDescriptor(descriptor);
5051
5051
  }
5052
- return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ? invalid13() : f;
5052
+ return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ? invalid14() : f;
5053
5053
  }
5054
5054
  function parseEnrichmentDescriptor(value) {
5055
- let invalid13 = () => {
5055
+ let invalid14 = () => {
5056
5056
  throw new FileOperationError("unavailable", 503, !0);
5057
5057
  };
5058
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
5058
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
5059
5059
  let d = value;
5060
- return Object.keys(d).sort().join(",") !== "mediaType,sha256,size" || !["application/octet-stream", "text/plain", "text/markdown", "application/json"].includes(d.mediaType) || !Number.isSafeInteger(d.size) || d.size < 0 || d.size > 16 * 1024 * 1024 || typeof d.sha256 != "string" || !/^[0-9a-f]{64}$/.test(d.sha256) ? invalid13() : d;
5060
+ return Object.keys(d).sort().join(",") !== "mediaType,sha256,size" || !["application/octet-stream", "text/plain", "text/markdown", "application/json"].includes(d.mediaType) || !Number.isSafeInteger(d.size) || d.size < 0 || d.size > 16 * 1024 * 1024 || typeof d.sha256 != "string" || !/^[0-9a-f]{64}$/.test(d.sha256) ? invalid14() : d;
5061
5061
  }
5062
5062
  function safeEnrichmentName(value) {
5063
5063
  return safeFileName(value) && !/^original(?:\.|$)/i.test(value);
5064
5064
  }
5065
5065
  function parseFileEnrichMetadata(value, maxBytes) {
5066
- let invalid13 = (reason = "invalid_metadata") => {
5066
+ let invalid14 = (reason = "invalid_metadata") => {
5067
5067
  throw new FileOperationError("invalid_input", 400, !1, { reason });
5068
5068
  };
5069
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
5069
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
5070
5070
  let d = value;
5071
- if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key))) return invalid13();
5072
- if (!safeEnrichmentName(d.name)) return invalid13("invalid_enrichment_name");
5073
- if (!Number.isSafeInteger(d.size) || d.size < 0) return invalid13("invalid_size");
5074
- if (d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType))) return invalid13("invalid_media_type");
5075
- if (d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return invalid13("invalid_replacement");
5071
+ if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key))) return invalid14();
5072
+ if (!safeEnrichmentName(d.name)) return invalid14("invalid_enrichment_name");
5073
+ if (!Number.isSafeInteger(d.size) || d.size < 0) return invalid14("invalid_size");
5074
+ if (d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType))) return invalid14("invalid_media_type");
5075
+ if (d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return invalid14("invalid_replacement");
5076
5076
  if (d.size > maxBytes) throw new FileOperationError(
5077
5077
  "request_too_large",
5078
5078
  413,
@@ -5105,42 +5105,42 @@ function isCanonicalOriginalMediaType(value) {
5105
5105
  }
5106
5106
  }
5107
5107
  function parseFileUpdate(value) {
5108
- let invalid13 = (reason = "invalid_metadata") => {
5108
+ let invalid14 = (reason = "invalid_metadata") => {
5109
5109
  throw new FileOperationError("invalid_input", 400, !1, { reason });
5110
5110
  };
5111
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
5111
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
5112
5112
  let input = value, update = {};
5113
- if (!Object.keys(input).length || Object.keys(input).some((key) => !["name", "path", "mediaType"].includes(key))) return invalid13();
5113
+ if (!Object.keys(input).length || Object.keys(input).some((key) => !["name", "path", "mediaType"].includes(key))) return invalid14();
5114
5114
  if (Object.hasOwn(input, "name")) {
5115
- if (!safeFileName(input.name)) return invalid13("invalid_name");
5115
+ if (!safeFileName(input.name)) return invalid14("invalid_name");
5116
5116
  update.name = input.name;
5117
5117
  }
5118
5118
  if (Object.hasOwn(input, "path")) {
5119
- if (!safeManagedFilePath(input.path)) return invalid13("invalid_path");
5119
+ if (!safeManagedFilePath(input.path)) return invalid14("invalid_path");
5120
5120
  update.path = input.path;
5121
5121
  }
5122
5122
  return Object.hasOwn(input, "mediaType") && (update.mediaType = declaredOriginalMediaType(input.mediaType)), update;
5123
5123
  }
5124
5124
  function parseFileCreateMetadata(value, maxBytes) {
5125
- let invalid13 = (reason = "invalid_metadata") => {
5125
+ let invalid14 = (reason = "invalid_metadata") => {
5126
5126
  throw new FileOperationError("invalid_input", 400, !1, { reason });
5127
5127
  };
5128
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
5128
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
5129
5129
  let input = value;
5130
- if (Object.keys(input).some((key) => !["name", "path", "storage", "mediaType", "size", "requestKey"].includes(key))) return invalid13();
5130
+ if (Object.keys(input).some((key) => !["name", "path", "storage", "mediaType", "size", "requestKey"].includes(key))) return invalid14();
5131
5131
  let path = input.path === void 0 ? "Files" : input.path;
5132
- if (!safeFileName(input.name)) return invalid13("invalid_name");
5133
- if (!safeManagedFilePath(path)) return invalid13("invalid_path");
5134
- if (input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local") return invalid13("invalid_storage");
5132
+ if (!safeFileName(input.name)) return invalid14("invalid_name");
5133
+ if (!safeManagedFilePath(path)) return invalid14("invalid_path");
5134
+ if (input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local") return invalid14("invalid_storage");
5135
5135
  let mediaType = input.mediaType === void 0 ? "application/octet-stream" : declaredOriginalMediaType(input.mediaType);
5136
- if (!Number.isSafeInteger(input.size) || input.size < 0) return invalid13("invalid_size");
5136
+ if (!Number.isSafeInteger(input.size) || input.size < 0) return invalid14("invalid_size");
5137
5137
  if (input.size > maxBytes) throw new FileOperationError(
5138
5138
  "request_too_large",
5139
5139
  413,
5140
5140
  !1,
5141
5141
  { reason: "size_limit", limitBytes: maxBytes, receivedBytes: input.size }
5142
5142
  );
5143
- return typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey) ? invalid13("invalid_request_key") : {
5143
+ return typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey) ? invalid14("invalid_request_key") : {
5144
5144
  name: input.name,
5145
5145
  path,
5146
5146
  ...input.storage ? { storage: input.storage } : {},
@@ -5520,6 +5520,10 @@ function createInboxPublisher(transport) {
5520
5520
  };
5521
5521
  }
5522
5522
 
5523
+ var recordOptionCatalogueByteLimit = 7e6;
5524
+ function normalizeRecordOptionSearch(text5) {
5525
+ return text5.toLowerCase().replace(/\s+/gu, " ").trim();
5526
+ }
5523
5527
  var RecordSelectionError = class extends InboxContractError {
5524
5528
  constructor(problem, source2) {
5525
5529
  let collection = `${source2.collection.repository}/${source2.collection.name}`, messages = {
@@ -5528,7 +5532,6 @@ var RecordSelectionError = class extends InboxContractError {
5528
5532
  filter_fields_invalid: `The filters for ${collection} must use scalar schema fields and matching values. Check the Question\u2019s where fields.`,
5529
5533
  ref_prefix_invalid: `The record reference prefix does not belong to ${collection}. Check refPrefix against the collection\u2019s record references.`,
5530
5534
  suggestion_unavailable: `A suggested record is missing or isn\u2019t eligible for ${collection}. Update the suggestions and try again.`,
5531
- selected_record_unavailable: `The selected record is no longer available in ${collection}. Search again and choose a current record.`,
5532
5535
  label_unavailable: `A record in ${collection} has no value in the configured label fields. Update display.labelFields or the record.`
5533
5536
  };
5534
5537
  super(messages[problem]);
@@ -5790,7 +5793,6 @@ function safeInboxPublicationMessage(value) {
5790
5793
  "filter_fields_invalid",
5791
5794
  "ref_prefix_invalid",
5792
5795
  "suggestion_unavailable",
5793
- "selected_record_unavailable",
5794
5796
  "label_unavailable"
5795
5797
  ])
5796
5798
  if (new RecordSelectionError(problem, source2).message === message2) return message2;
@@ -6188,14 +6190,14 @@ var AIError = class extends Error {
6188
6190
  code;
6189
6191
  detail;
6190
6192
  };
6191
- function capture(value, invalid13, oversized, limit = ROUTINE_AI_VALUE_BYTES) {
6193
+ function capture(value, invalid14, oversized, limit = ROUTINE_AI_VALUE_BYTES) {
6192
6194
  try {
6193
6195
  assertRoutineJson(value);
6194
6196
  let encoded = JSON.stringify(value);
6195
6197
  if (new TextEncoder().encode(encoded).byteLength > limit) throw new AIError(oversized);
6196
6198
  return freezeRoutineMetadata(JSON.parse(encoded));
6197
6199
  } catch (error) {
6198
- throw error instanceof AIError ? error : new AIError(invalid13);
6200
+ throw error instanceof AIError ? error : new AIError(invalid14);
6199
6201
  }
6200
6202
  }
6201
6203
  function parseRoutineAIRequest(value) {
@@ -6260,12 +6262,12 @@ function acceptText(request3, text5) {
6260
6262
 
6261
6263
  var ROUTINE_STEP_SUMMARY_BYTES = 256 * 1024, ROUTINE_STEP_OUTPUT_BYTES = 1024 * 1024;
6262
6264
  function parseRoutineStepOutputDetail(value) {
6263
- let invalid13 = () => {
6265
+ let invalid14 = () => {
6264
6266
  throw new AppRoutineContractError("invalid_value");
6265
6267
  };
6266
6268
  assertRoutineFields(value, ["step", "sizeBytes", "limitBytes", "summaryBytes", "dataBytes"]);
6267
6269
  let { step, sizeBytes, limitBytes, summaryBytes, dataBytes } = value;
6268
- return !isAppRoutineName(step) || ![sizeBytes, limitBytes, summaryBytes, dataBytes].every((bytes) => Number.isSafeInteger(bytes) && bytes > 0) || sizeBytes !== summaryBytes + dataBytes || limitBytes !== (summaryBytes > ROUTINE_STEP_SUMMARY_BYTES ? ROUTINE_STEP_SUMMARY_BYTES : ROUTINE_STEP_OUTPUT_BYTES) || (limitBytes === ROUTINE_STEP_SUMMARY_BYTES ? summaryBytes : sizeBytes) <= limitBytes ? invalid13() : freezeRoutineMetadata({ step, sizeBytes, limitBytes, summaryBytes, dataBytes });
6270
+ return !isAppRoutineName(step) || ![sizeBytes, limitBytes, summaryBytes, dataBytes].every((bytes) => Number.isSafeInteger(bytes) && bytes > 0) || sizeBytes !== summaryBytes + dataBytes || limitBytes !== (summaryBytes > ROUTINE_STEP_SUMMARY_BYTES ? ROUTINE_STEP_SUMMARY_BYTES : ROUTINE_STEP_OUTPUT_BYTES) || (limitBytes === ROUTINE_STEP_SUMMARY_BYTES ? summaryBytes : sizeBytes) <= limitBytes ? invalid14() : freezeRoutineMetadata({ step, sizeBytes, limitBytes, summaryBytes, dataBytes });
6269
6271
  }
6270
6272
  function routineStepOutputMessage(value) {
6271
6273
  let detail = parseRoutineStepOutputDetail(value), size = `${(detail.sizeBytes / (1024 * 1024)).toFixed(1)} MB`, bound = detail.limitBytes === ROUTINE_STEP_SUMMARY_BYTES ? `, including ${(detail.summaryBytes / 1024).toFixed(1)} KB of summary. Each step's summary can return up to 256 KB.` : ". Each step can return up to 1 MB across its summary and data.";
@@ -6279,9 +6281,9 @@ var RoutineStepOutputError = class extends Error {
6279
6281
  super(routineStepOutputMessage(captured)), this.detail = captured, Object.freeze(this);
6280
6282
  }
6281
6283
  };
6282
- function captureRoutineStepOutput(step, summary2, data3) {
6283
- assertRoutineJson(summary2), assertRoutineJson(data3);
6284
- let summaryJson = JSON.stringify(summary2), dataJson = JSON.stringify(data3), summaryBytes = new TextEncoder().encode(summaryJson).byteLength, dataBytes = new TextEncoder().encode(dataJson).byteLength, sizeBytes = summaryBytes + dataBytes, limitBytes = summaryBytes > ROUTINE_STEP_SUMMARY_BYTES ? ROUTINE_STEP_SUMMARY_BYTES : ROUTINE_STEP_OUTPUT_BYTES;
6284
+ function captureRoutineStepOutput(step, summary3, data3) {
6285
+ assertRoutineJson(summary3), assertRoutineJson(data3);
6286
+ let summaryJson = JSON.stringify(summary3), dataJson = JSON.stringify(data3), summaryBytes = new TextEncoder().encode(summaryJson).byteLength, dataBytes = new TextEncoder().encode(dataJson).byteLength, sizeBytes = summaryBytes + dataBytes, limitBytes = summaryBytes > ROUTINE_STEP_SUMMARY_BYTES ? ROUTINE_STEP_SUMMARY_BYTES : ROUTINE_STEP_OUTPUT_BYTES;
6285
6287
  if (summaryBytes > ROUTINE_STEP_SUMMARY_BYTES || sizeBytes > ROUTINE_STEP_OUTPUT_BYTES)
6286
6288
  throw new RoutineStepOutputError({ step, sizeBytes, limitBytes, summaryBytes, dataBytes });
6287
6289
  return freezeRoutineMetadata({ summary: JSON.parse(summaryJson), data: JSON.parse(dataJson) });
@@ -6516,8 +6518,8 @@ async function executeRoutineDefinition(definition, input, runtime) {
6516
6518
  await runtime.step(id3, { status: "running" }), activeStep = id3;
6517
6519
  let output = await steps[id3].run(saved, os2);
6518
6520
  if (assertRoutineFields(output, ["summary", "data"]), !Object.hasOwn(output, "summary") || !Object.hasOwn(output, "data")) return invalid3();
6519
- let { summary: summary2, data: data3 } = captureRoutineStepOutput(id3, output.summary, output.data);
6520
- return await runtime.step(id3, { status: "completed", summary: summary2, data: data3 }), activeStep = void 0, freezeRoutineMetadata({ summary: summary2, data: data3 });
6521
+ let { summary: summary3, data: data3 } = captureRoutineStepOutput(id3, output.summary, output.data);
6522
+ return await runtime.step(id3, { status: "completed", summary: summary3, data: data3 }), activeStep = void 0, freezeRoutineMetadata({ summary: summary3, data: data3 });
6521
6523
  } catch (error) {
6522
6524
  throw error instanceof RoutineStepOutputError && (outputFailure ??= error), broken = !0, activeStep = void 0, await runtime.step(id3, { status: "failed" }), error;
6523
6525
  }
@@ -6638,7 +6640,26 @@ function safeRecordFieldMessage(value) {
6638
6640
  let expected = parseExpectation(/\. (Expected .+) Check its definition in /.exec(value)?.[1]);
6639
6641
  return fieldProblems.map((problem) => recordFieldMessage(parts[1], field, problem, schemaPath, expected)).find((message2) => message2 === value);
6640
6642
  }
6643
+ function parsePublicationConflict(value) {
6644
+ if (!value || typeof value != "object" || Array.isArray(value)) throw new Error("Invalid publication conflict");
6645
+ let row = value;
6646
+ if (Object.keys(row).sort().join(",") !== "code,conflict,record" || row.code !== "publication_conflict" || !["record_version_changed", "record_missing", "create_identity_conflict", "filing_conflict", "schema_changed"].includes(String(row.conflict)) || typeof row.record != "string" || !validRecordRef(row.record)) throw new Error("Invalid publication conflict");
6647
+ return structuredClone(value);
6648
+ }
6641
6649
  function dataValidationMessageFacts(error) {
6650
+ if (["invalid_change", "conflict"].includes(error.code) && error.detail && typeof error.detail == "object" && "code" in error.detail && error.detail.code === "publication_conflict")
6651
+ try {
6652
+ let detail = parsePublicationConflict(error.detail), descriptions = {
6653
+ record_version_changed: "changed after it was reviewed",
6654
+ record_missing: "is missing",
6655
+ create_identity_conflict: "already exists",
6656
+ filing_conflict: "has a conflicting filing path",
6657
+ schema_changed: "has an unavailable or incompatible schema"
6658
+ };
6659
+ return { detail, message: `Record "${detail.record}" ${descriptions[detail.conflict]}. No changes were saved.` };
6660
+ } catch {
6661
+ return {};
6662
+ }
6642
6663
  if (error.code === "invalid_change") {
6643
6664
  let detail = parseDataValidationDetail(error.detail);
6644
6665
  if (detail) {
@@ -6668,22 +6689,24 @@ var localDataPath = (value, repository) => typeof value == "string" && value.len
6668
6689
  return Object.keys(row).sort().join(",") === "action,path" && ["created", "updated", "deleted"].includes(String(row.action)) && localDataPath(row.path, repository);
6669
6690
  };
6670
6691
  function parseDataFailureDetail(value) {
6671
- let invalid13 = () => {
6692
+ let invalid14 = () => {
6672
6693
  throw new Error("Invalid local Data failure detail");
6673
6694
  };
6674
- if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
6695
+ if (!value || typeof value != "object" || Array.isArray(value)) return invalid14();
6675
6696
  let row = value;
6676
- if (Object.keys(row).sort().join(",") !== "cause,code,files,nextAction,operation,repository" || !["local_data_read_failed", "local_data_write_failed", "local_data_write_partial"].includes(String(row.code)) || !["read", "write"].includes(String(row.operation)) || typeof row.repository != "string" || !/^[a-z0-9][a-z0-9._/-]{0,127}$/.test(row.repository) || row.repository.includes("//") || row.repository.includes("..") || !["fix_failed_file_then_rerun", "review_resolve_then_rerun"].includes(String(row.nextAction))) return invalid13();
6697
+ if (Object.keys(row).sort().join(",") !== "cause,code,files,nextAction,operation,repository" || !["local_data_read_failed", "local_data_write_failed", "local_data_write_partial"].includes(String(row.code)) || !["read", "write"].includes(String(row.operation)) || typeof row.repository != "string" || !/^[a-z0-9][a-z0-9._/-]{0,127}$/.test(row.repository) || row.repository.includes("//") || row.repository.includes("..") || !["fix_failed_file_then_rerun", "review_resolve_then_rerun"].includes(String(row.nextAction))) return invalid14();
6677
6698
  let repository = row.repository;
6678
- if (!row.cause || typeof row.cause != "object" || Array.isArray(row.cause)) return invalid13();
6699
+ if (!row.cause || typeof row.cause != "object" || Array.isArray(row.cause)) return invalid14();
6679
6700
  let cause = row.cause;
6680
- if (!["code,message", "code,message,path"].includes(Object.keys(cause).sort().join(",")) || !["schema_validation_failed", "invalid_record", "unsafe_record", "stale_record", "path_conflict", "filesystem_unavailable"].includes(String(cause.code)) || typeof cause.message != "string" || !cause.message || cause.message.length > 512 || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(cause.message) || cause.path !== void 0 && !localDataPath(cause.path, repository) || !row.files || typeof row.files != "object" || Array.isArray(row.files)) return invalid13();
6701
+ if (!["code,message", "code,message,path"].includes(Object.keys(cause).sort().join(",")) || !["schema_validation_failed", "invalid_record", "unsafe_record", "stale_record", "path_conflict", "filesystem_unavailable"].includes(String(cause.code)) || typeof cause.message != "string" || !cause.message || cause.message.length > 512 || /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/.test(cause.message) || cause.path !== void 0 && !localDataPath(cause.path, repository) || !row.files || typeof row.files != "object" || Array.isArray(row.files)) return invalid14();
6681
6702
  let files3 = row.files;
6682
- if (Object.keys(files3).some((key) => !["state", "saved", "failed", "notAttempted", "savedOmitted", "notAttemptedOmitted"].includes(key)) || !["none", "partial"].includes(String(files3.state)) || !Array.isArray(files3.saved) || files3.saved.length > 128 || !files3.saved.every((item) => localDataFile(item, repository)) || files3.failed !== void 0 && !localDataFile(files3.failed, repository) || !Array.isArray(files3.notAttempted) || files3.notAttempted.length > 128 || !files3.notAttempted.every((item) => localDataFile(item, repository))) return invalid13();
6683
- for (let key of ["savedOmitted", "notAttemptedOmitted"]) if (files3[key] !== void 0 && (!Number.isSafeInteger(files3[key]) || Number(files3[key]) < 1 || Number(files3[key]) > 1e4)) return invalid13();
6684
- return row.operation === "read" && (row.code !== "local_data_read_failed" || files3.state !== "none" || files3.saved.length || files3.failed !== void 0 || files3.notAttempted.length) || row.operation === "write" && row.code === "local_data_read_failed" || row.code === "local_data_write_partial" && (files3.state !== "partial" || !files3.saved.length) || row.code !== "local_data_write_partial" && files3.state === "partial" ? invalid13() : structuredClone(value);
6703
+ if (Object.keys(files3).some((key) => !["state", "saved", "failed", "notAttempted", "savedOmitted", "notAttemptedOmitted"].includes(key)) || !["none", "partial"].includes(String(files3.state)) || !Array.isArray(files3.saved) || files3.saved.length > 128 || !files3.saved.every((item) => localDataFile(item, repository)) || files3.failed !== void 0 && !localDataFile(files3.failed, repository) || !Array.isArray(files3.notAttempted) || files3.notAttempted.length > 128 || !files3.notAttempted.every((item) => localDataFile(item, repository))) return invalid14();
6704
+ for (let key of ["savedOmitted", "notAttemptedOmitted"]) if (files3[key] !== void 0 && (!Number.isSafeInteger(files3[key]) || Number(files3[key]) < 1 || Number(files3[key]) > 1e4)) return invalid14();
6705
+ return row.operation === "read" && (row.code !== "local_data_read_failed" || files3.state !== "none" || files3.saved.length || files3.failed !== void 0 || files3.notAttempted.length) || row.operation === "write" && row.code === "local_data_read_failed" || row.code === "local_data_write_partial" && (files3.state !== "partial" || !files3.saved.length) || row.code !== "local_data_write_partial" && files3.state === "partial" ? invalid14() : structuredClone(value);
6685
6706
  }
6686
6707
  function parseDataOperationDetail(value) {
6708
+ if (value && typeof value == "object" && !Array.isArray(value) && value.code === "publication_conflict")
6709
+ return parsePublicationConflict(value);
6687
6710
  let validation = parseDataValidationDetail(value);
6688
6711
  if (validation) return validation;
6689
6712
  if (value && typeof value == "object" && !Array.isArray(value) && value.code === "record_limit_exceeded") {
@@ -6721,7 +6744,7 @@ function dataErrorMessage(code, effect) {
6721
6744
  var DataOperationError = class extends Error {
6722
6745
  constructor(code, retryable = !1, effect, component, detail) {
6723
6746
  let parsed = detail === void 0 ? void 0 : parseDataOperationDetail(detail);
6724
- if (parsed && ("reason" in parsed ? code !== "invalid_change" : parsed.code === "record_limit_exceeded" && code !== "capacity"))
6747
+ if (parsed && ("reason" in parsed ? code !== "invalid_change" : parsed.code === "publication_conflict" ? !["invalid_change", "conflict"].includes(code) : parsed.code === "record_limit_exceeded" && code !== "capacity"))
6725
6748
  throw new Error("Invalid Data operation detail");
6726
6749
  super(parsed && "code" in parsed && parsed.code === "local_data_publication_failed" ? dataPublicationFailureMessage(parsed) : code === "capacity" && parsed && "code" in parsed && parsed.code === "record_limit_exceeded" ? dataRecordLimitMessage(parsed) : dataErrorMessage(code, effect));
6727
6750
  this.code = code;
@@ -6824,21 +6847,21 @@ function captureRecordsQuery(query) {
6824
6847
  return capture3(query);
6825
6848
  }
6826
6849
  function captureRecordsAll(query, options) {
6827
- let invalid13 = () => {
6850
+ let invalid14 = () => {
6828
6851
  throw new DataOperationError("invalid_query");
6829
6852
  };
6830
6853
  try {
6831
6854
  let properties = dataProperties(options), maxRecords = properties.maxRecords?.value;
6832
- if (Object.keys(properties).join(",") !== "maxRecords" || !Number.isSafeInteger(maxRecords) || maxRecords < 1) return invalid13();
6855
+ if (Object.keys(properties).join(",") !== "maxRecords" || !Number.isSafeInteger(maxRecords) || maxRecords < 1) return invalid14();
6833
6856
  let detached = capture3(query), selections = dataProperties(detached);
6834
- if (Object.keys(selections).length < 1 || Object.keys(selections).length > 16) return invalid13();
6857
+ if (Object.keys(selections).length < 1 || Object.keys(selections).length > 16) return invalid14();
6835
6858
  for (let selection2 of Object.values(selections)) {
6836
6859
  let fields4 = dataProperties(selection2.value);
6837
- if (fields4.$ && Object.hasOwn(dataProperties(fields4.$.value), "after")) return invalid13();
6860
+ if (fields4.$ && Object.hasOwn(dataProperties(fields4.$.value), "after")) return invalid14();
6838
6861
  }
6839
6862
  return { query: detached, maxRecords };
6840
6863
  } catch {
6841
- return invalid13();
6864
+ return invalid14();
6842
6865
  }
6843
6866
  }
6844
6867
 
@@ -7046,11 +7069,11 @@ function dataTransportError(status, value) {
7046
7069
  detail = row?.detail === void 0 ? void 0 : parseDataOperationDetail(row.detail);
7047
7070
  } catch {
7048
7071
  }
7049
- return detail && "reason" in detail && code !== "invalid_change" && (detail = void 0), explainDataValidation(new DataOperationError(
7072
+ return detail && ("reason" in detail && code !== "invalid_change" || "code" in detail && detail.code === "publication_conflict" && !["invalid_change", "conflict"].includes(code)) && (detail = void 0), explainDataValidation(new DataOperationError(
7050
7073
  code,
7051
7074
  typeof row?.retryable == "boolean" ? row.retryable : ["capacity", "unavailable", "apply_pending"].includes(code),
7052
7075
  code === "conflict" ? "unapplied" : effect,
7053
- code === "invalid_change" && typeof row?.component == "string" && /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/.test(row.component) ? row.component : void 0,
7076
+ (["invalid_change", "conflict"].includes(code) || code === "unavailable" && row?.component === "deletion_waits_for_current_data") && typeof row?.component == "string" && /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/.test(row.component) ? row.component : void 0,
7054
7077
  detail
7055
7078
  ), row?.message, row?.detail);
7056
7079
  }
@@ -7319,6 +7342,21 @@ function parseStoredRecordLink(value) {
7319
7342
  return typeof value == "string" && value.startsWith("[[") && value.endsWith("]]") ? parseRecordLink(value.slice(2, -2)) : void 0;
7320
7343
  }
7321
7344
 
7345
+ var NAME = /^[a-zA-Z][a-zA-Z0-9_-]*$/, invalid7 = (message2) => {
7346
+ throw new Error(message2);
7347
+ };
7348
+ function parseRecordDisplay(value, definitions2, fail8 = invalid7) {
7349
+ if (value === void 0) return;
7350
+ if (!value || typeof value != "object" || Array.isArray(value)) return fail8("Expected a field mapping");
7351
+ let row = value;
7352
+ if (Object.keys(row).some((key) => key !== "title") || !Object.hasOwn(row, "title") || !Array.isArray(row.title) || row.title.length < 1 || row.title.length > 2 || row.title.some((name2) => typeof name2 != "string" || !NAME.test(name2)) || new Set(row.title).size !== row.title.length) return fail8("Display title requires one or two distinct scalar fields");
7353
+ let title = row.title;
7354
+ return title.some((name2) => {
7355
+ let field = definitions2.find((candidate) => candidate.name === name2);
7356
+ return !field || field.many || ["link", "object", "map"].includes(field.kind);
7357
+ }) ? fail8("Display title requires one or two distinct scalar fields") : { title };
7358
+ }
7359
+
7322
7360
  var RecordValidationError = class extends Error {
7323
7361
  constructor(message2, path) {
7324
7362
  super(message2);
@@ -7351,7 +7389,7 @@ function fieldExpectation(field) {
7351
7389
  ...field.kind === "date" && field.format ? { format: field.format } : {}
7352
7390
  };
7353
7391
  }
7354
- var NAME = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
7392
+ var NAME2 = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
7355
7393
  function fail3(message2) {
7356
7394
  throw new RecordValidationError(message2);
7357
7395
  }
@@ -7364,6 +7402,9 @@ function object3(value) {
7364
7402
  function keys2(row, allowed, required) {
7365
7403
  (Object.keys(row).some((key) => !allowed.includes(key)) || required.some((key) => !Object.hasOwn(row, key))) && fail3("Unsupported or missing schema/record fields");
7366
7404
  }
7405
+ function parseRecordDisplay2(value, definitions2) {
7406
+ return parseRecordDisplay(value, definitions2, fail3);
7407
+ }
7367
7408
  function valueDefinition(value, depth, native, named = !1) {
7368
7409
  depth > 8 && fail3("Invalid field definitions");
7369
7410
  let row = { ...object3(value) };
@@ -7421,7 +7462,7 @@ function valueDefinition(value, depth, native, named = !1) {
7421
7462
  let property = row.kind === "enum" ? "values" : "to";
7422
7463
  check([property]);
7423
7464
  let list2 = row.kind === "link" && typeof row.to == "string" ? [row.to] : row[property];
7424
- return (!Array.isArray(list2) || !list2.length || list2.length > 1e5 || new Set(list2).size !== list2.length || list2.some((item) => typeof item != "string" || !item || row.kind === "link" && !NAME.test(item))) && fail3("Invalid enum/link definition"), row.kind === "enum" ? { ...base, kind: "enum", values: list2 } : { ...base, kind: "link", to: list2 };
7465
+ return (!Array.isArray(list2) || !list2.length || list2.length > 1e5 || new Set(list2).size !== list2.length || list2.some((item) => typeof item != "string" || !item || row.kind === "link" && !NAME2.test(item))) && fail3("Invalid enum/link definition"), row.kind === "enum" ? { ...base, kind: "enum", values: list2 } : { ...base, kind: "link", to: list2 };
7425
7466
  }
7426
7467
  case "object":
7427
7468
  return check(["fields"]), { ...base, kind: "object", fields: fields2(row.fields, depth + 1, native) };
@@ -7439,7 +7480,7 @@ function fields2(value, depth = 0, native = !1) {
7439
7480
  let names = /* @__PURE__ */ new Set();
7440
7481
  return value.map((definition) => {
7441
7482
  let row = object3(definition);
7442
- return (typeof row.name != "string" || !NAME.test(row.name) || ["constructor", "prototype"].includes(row.name) || names.has(row.name)) && fail3("Invalid or duplicate field name"), names.add(row.name), { name: row.name, ...valueDefinition(row, depth, native, !0) };
7483
+ return (typeof row.name != "string" || !NAME2.test(row.name) || ["constructor", "prototype"].includes(row.name) || names.has(row.name)) && fail3("Invalid or duplicate field name"), names.add(row.name), { name: row.name, ...valueDefinition(row, depth, native, !0) };
7443
7484
  });
7444
7485
  }
7445
7486
  function validateRecordFields(value, definitions2, resolveLink, canonical = !1) {
@@ -7538,6 +7579,16 @@ function publicDefinition(field) {
7538
7579
  function publicField(field) {
7539
7580
  return { ...publicDefinition(field), name: field.name };
7540
7581
  }
7582
+ function summary({ name: name2, schema: schema2 }) {
7583
+ return { name: name2, type: schema2.type, ...schema2.description === void 0 ? {} : { description: schema2.description } };
7584
+ }
7585
+ function publicCollectionSchema(collection) {
7586
+ return {
7587
+ ...summary(collection),
7588
+ ...collection.schema.display ? { display: { title: [...collection.schema.display.title] } } : {},
7589
+ fields: collection.schema.fields.map(publicField)
7590
+ };
7591
+ }
7541
7592
  function scalarField(name2, schema2) {
7542
7593
  if (name2 === "$ref") return { name: name2, kind: "string", nullable: !1, many: !1 };
7543
7594
  let field = schema2.fields.find((field2) => field2.name === name2);
@@ -7696,9 +7747,9 @@ function cursorPosition(value, binding, limit) {
7696
7747
  return Object.keys(payload).length !== 4 || payload.format !== 1 || payload.binding !== binding || typeof position != "number" || !Number.isSafeInteger(position) || position <= 0 || position % limit !== 0 || typeof ref != "string" || !validRecordRef(ref) ? fail4("incompatible cursor") : { position, ref };
7697
7748
  }
7698
7749
 
7699
- var invalid7 = () => {
7750
+ var invalid8 = () => {
7700
7751
  throw new DataOperationError("unavailable", !0);
7701
- }, object4 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid7() : value, keys3 = (value, expected) => Object.keys(value).sort().join(",") === expected, hash = (value) => typeof value == "string" && /^[0-9a-f]{40}$/.test(value), time = (value) => typeof value == "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(value) && Number.isFinite(Date.parse(value)), sorted = (values) => values.every((value, i) => i === 0 || values[i - 1] < value);
7752
+ }, object4 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid8() : value, keys3 = (value, expected) => Object.keys(value).sort().join(",") === expected, hash = (value) => typeof value == "string" && /^[0-9a-f]{40}$/.test(value), time = (value) => typeof value == "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(value) && Number.isFinite(Date.parse(value)), sorted = (values) => values.every((value, i) => i === 0 || values[i - 1] < value);
7702
7753
  function json(value) {
7703
7754
  if (!(value === null || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value) || dataText(value))) {
7704
7755
  if (Array.isArray(value)) {
@@ -7706,7 +7757,7 @@ function json(value) {
7706
7757
  return;
7707
7758
  }
7708
7759
  for (let [key, item] of Object.entries(object4(value))) {
7709
- if (!dataText(key)) return invalid7();
7760
+ if (!dataText(key)) return invalid8();
7710
7761
  json(item);
7711
7762
  }
7712
7763
  }
@@ -7718,66 +7769,66 @@ var slot = (values, field) => Object.hasOwn(values, field) ? { present: !0, valu
7718
7769
  function apply(book, event) {
7719
7770
  let records = book.get(event.collection), prior = records.get(event.ref);
7720
7771
  if (event.kind === "create") {
7721
- if (prior) return invalid7();
7772
+ if (prior) return invalid8();
7722
7773
  records.set(event.ref, structuredClone(event.values));
7723
7774
  } else if (event.kind === "delete") {
7724
- if (!prior || stable(prior) !== stable(event.values)) return invalid7();
7775
+ if (!prior || stable(prior) !== stable(event.values)) return invalid8();
7725
7776
  records.delete(event.ref);
7726
7777
  } else if (event.kind === "rename") {
7727
7778
  let before = records.get(event.previousRef);
7728
- if (!before || prior) return invalid7();
7779
+ if (!before || prior) return invalid8();
7729
7780
  records.delete(event.previousRef), records.set(event.ref, before);
7730
7781
  } else if (event.kind === "update") {
7731
- if (!prior || stable(slot(prior, event.field)) !== stable(event.before) || stable(event.before) === stable(event.after)) return invalid7();
7782
+ if (!prior || stable(slot(prior, event.field)) !== stable(event.before) || stable(event.before) === stable(event.after)) return invalid8();
7732
7783
  event.after.present ? Object.defineProperty(prior, event.field, { value: structuredClone(event.after.value), enumerable: !0, configurable: !0, writable: !0 }) : delete prior[event.field];
7733
7784
  }
7734
7785
  }
7735
7786
  function validateSnapshotHistory(input, collections, version) {
7736
7787
  let row = object4(input), selections = object4(row.fields);
7737
- if (!keys3(row, "commits,fields,through") || !hash(row.through) || version !== `current-${row.through}` || !Array.isArray(row.commits) || !row.commits.length || !Object.keys(selections).length || !sorted(Object.keys(selections))) return invalid7();
7788
+ if (!keys3(row, "commits,fields,through") || !hash(row.through) || version !== `current-${row.through}` || !Array.isArray(row.commits) || !row.commits.length || !Object.keys(selections).length || !sorted(Object.keys(selections))) return invalid8();
7738
7789
  let book = /* @__PURE__ */ new Map();
7739
7790
  for (let [collection, selection2] of Object.entries(selections)) {
7740
7791
  let selected = object4(selection2), fields4 = selected.fields;
7741
- if (!Object.hasOwn(collections, collection) || !keys3(selected, "fields") || !Array.isArray(fields4) || !fields4.length || fields4.some((field) => typeof field != "string" || !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(field)) || !sorted(fields4)) return invalid7();
7792
+ if (!Object.hasOwn(collections, collection) || !keys3(selected, "fields") || !Array.isArray(fields4) || !fields4.length || fields4.some((field) => typeof field != "string" || !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(field)) || !sorted(fields4)) return invalid8();
7742
7793
  book.set(collection, /* @__PURE__ */ new Map());
7743
7794
  }
7744
7795
  let history = row, seen = /* @__PURE__ */ new Set(), parent = null;
7745
7796
  for (let group of history.commits) {
7746
- if (!keys3(object4(group), "authoredAt,commit,committedAt,events,firstParent") || !hash(group.commit) || seen.has(group.commit) || group.firstParent !== parent || !time(group.authoredAt) || !time(group.committedAt) || !Array.isArray(group.events)) return invalid7();
7797
+ if (!keys3(object4(group), "authoredAt,commit,committedAt,events,firstParent") || !hash(group.commit) || seen.has(group.commit) || group.firstParent !== parent || !time(group.authoredAt) || !time(group.committedAt) || !Array.isArray(group.events)) return invalid8();
7747
7798
  seen.add(group.commit), parent = group.commit;
7748
7799
  let previous, created = /* @__PURE__ */ new Set();
7749
7800
  for (let event of group.events) {
7750
- if (object4(event), !book.has(event.collection) || !validRecordRef(event.ref) || !event.ref.startsWith(`${event.collection}/`)) return invalid7();
7801
+ if (object4(event), !book.has(event.collection) || !validRecordRef(event.ref) || !event.ref.startsWith(`${event.collection}/`)) return invalid8();
7751
7802
  let fields4 = history.fields[event.collection].fields;
7752
7803
  if (event.kind === "create" || event.kind === "delete") {
7753
- if (!keys3(event, "collection,kind,ref,values") || Object.keys(object4(event.values)).some((field) => !fields4.includes(field))) return invalid7();
7804
+ if (!keys3(event, "collection,kind,ref,values") || Object.keys(object4(event.values)).some((field) => !fields4.includes(field))) return invalid8();
7754
7805
  json(event.values), event.kind === "create" && created.add(event.ref);
7755
7806
  } else if (event.kind === "rename") {
7756
- if (!keys3(event, "collection,kind,previousRef,ref") || !validRecordRef(event.previousRef) || !event.previousRef.startsWith(`${event.collection}/`) || event.previousRef === event.ref) return invalid7();
7807
+ if (!keys3(event, "collection,kind,previousRef,ref") || !validRecordRef(event.previousRef) || !event.previousRef.startsWith(`${event.collection}/`) || event.previousRef === event.ref) return invalid8();
7757
7808
  } else if (event.kind === "update") {
7758
- if (!keys3(event, "after,before,collection,field,kind,ref") || !fields4.includes(event.field) || created.has(event.ref)) return invalid7();
7809
+ if (!keys3(event, "after,before,collection,field,kind,ref") || !fields4.includes(event.field) || created.has(event.ref)) return invalid8();
7759
7810
  for (let value of [event.before, event.after]) {
7760
- if (object4(value), value.present === !1 ? !keys3(value, "present") : value.present !== !0 || !keys3(value, "present,value")) return invalid7();
7811
+ if (object4(value), value.present === !1 ? !keys3(value, "present") : value.present !== !0 || !keys3(value, "present,value")) return invalid8();
7761
7812
  value.present && json(value.value);
7762
7813
  }
7763
- } else return invalid7();
7814
+ } else return invalid8();
7764
7815
  let order = [event.kind === "delete" ? 0 : 1, event.ref, event.kind === "update" ? 1 : 0, event.kind === "update" ? event.field : ""];
7765
7816
  if (previous) {
7766
7817
  let index = order.findIndex((value, i) => value !== previous[i]);
7767
- if (index === -1 || order[index] < previous[index]) return invalid7();
7818
+ if (index === -1 || order[index] < previous[index]) return invalid8();
7768
7819
  }
7769
7820
  previous = order, apply(book, event);
7770
7821
  }
7771
7822
  let refs = /* @__PURE__ */ new Set();
7772
7823
  for (let records of book.values()) for (let ref of records.keys()) {
7773
- if (refs.has(ref)) return invalid7();
7824
+ if (refs.has(ref)) return invalid8();
7774
7825
  refs.add(ref);
7775
7826
  }
7776
7827
  }
7777
- if (parent !== history.through) return invalid7();
7828
+ if (parent !== history.through) return invalid8();
7778
7829
  for (let [collection, records] of book) {
7779
7830
  let expected = collections[collection].map((record4) => [record4.$ref, Object.fromEntries(history.fields[collection].fields.filter((field) => Object.hasOwn(record4, field)).map((field) => [field, record4[field]]))]);
7780
- if (stable([...records].sort(([a], [b]) => a < b ? -1 : 1)) !== stable(expected)) return invalid7();
7831
+ if (stable([...records].sort(([a], [b]) => a < b ? -1 : 1)) !== stable(expected)) return invalid8();
7781
7832
  }
7782
7833
  return history;
7783
7834
  }
@@ -7804,57 +7855,60 @@ function readSnapshotHistory(history, input, operation2) {
7804
7855
  };
7805
7856
  }
7806
7857
 
7807
- var snapshotCollection = (catalogue, ref) => catalogue.filter((c) => ref.startsWith(`${c.name}/`)).sort((a, b) => b.name.length - a.name.length)[0], invalid8 = () => {
7858
+ var snapshotCollection = (catalogue, ref) => catalogue.filter((c) => ref.startsWith(`${c.name}/`)).sort((a, b) => b.name.length - a.name.length)[0], invalid9 = () => {
7808
7859
  throw new DataOperationError("unavailable", !0);
7809
- }, object5 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid8() : value;
7860
+ }, object5 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid9() : value;
7810
7861
  function stable2(value) {
7811
7862
  return Array.isArray(value) ? `[${value.map(stable2).join(",")}]` : value && typeof value == "object" ? `{${Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, entry]) => `${JSON.stringify(key)}:${stable2(entry)}`).join(",")}}` : JSON.stringify(value);
7812
7863
  }
7813
7864
  function schemaText(value) {
7814
- if (typeof value == "string" && !dataText(value)) return invalid8();
7865
+ if (typeof value == "string" && !dataText(value)) return invalid9();
7815
7866
  if (value && typeof value == "object") for (let [key, entry] of Object.entries(value)) {
7816
- if (!dataText(key)) return invalid8();
7867
+ if (!dataText(key)) return invalid9();
7817
7868
  schemaText(entry);
7818
7869
  }
7819
7870
  }
7820
7871
  function validateSnapshotEnvelope(input, repository, name2, bodies = [], timelines = []) {
7821
7872
  try {
7822
7873
  let row = object5(input), legacy = row.format === "data-snapshot.v1";
7823
- if (!["collections,format,name,repository,schemas,version", "collections,format,history,name,repository,schemas,version"].includes(Object.keys(row).sort().join(",")) || !legacy && row.format !== "data-snapshot.v2" || legacy && timelines.length > 0 || row.repository !== repository || row.name !== name2 || !dataVersion(row.version)) return invalid8();
7874
+ if (!["collections,format,name,repository,schemas,version", "collections,format,history,name,repository,schemas,version"].includes(Object.keys(row).sort().join(",")) || !legacy && row.format !== "data-snapshot.v2" || legacy && timelines.length > 0 || row.repository !== repository || row.name !== name2 || !dataVersion(row.version)) return invalid9();
7824
7875
  let schemas2 = object5(row.schemas), collections = object5(row.collections);
7825
7876
  schemaText(schemas2);
7826
7877
  let names = Object.keys(collections);
7827
- for (let subset of [bodies, timelines]) if (new Set(subset).size !== subset.length || subset.some((name3) => !names.includes(name3))) return invalid8();
7828
- if (!names.length || names.join("\0") !== [...names].sort().join("\0") || Object.keys(schemas2).join("\0") !== names.join("\0")) return invalid8();
7878
+ for (let subset of [bodies, timelines]) if (new Set(subset).size !== subset.length || subset.some((name3) => !names.includes(name3))) return invalid9();
7879
+ if (!names.length || names.join("\0") !== [...names].sort().join("\0") || Object.keys(schemas2).join("\0") !== names.join("\0")) return invalid9();
7829
7880
  let catalogue = names.map((name3) => {
7830
7881
  let schema2 = object5(schemas2[name3]);
7831
- if (!validRecordRef(`${name3}/example`) || schema2.name !== name3 || typeof schema2.type != "string" || !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(schema2.type) || schema2.description !== void 0 && !dataText(schema2.description) || Object.keys(schema2).some((key) => !["name", "type", "description", "fields"].includes(key))) return invalid8();
7882
+ if (!validRecordRef(`${name3}/example`) || schema2.name !== name3 || typeof schema2.type != "string" || !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(schema2.type) || schema2.description !== void 0 && !dataText(schema2.description) || Object.keys(schema2).some((key) => !["name", "type", "description", "display", "fields"].includes(key))) return invalid9();
7832
7883
  let definitions2 = fields2(schema2.fields, 0, !0);
7833
- return stable2(definitions2.map(publicField)) !== stable2(schema2.fields) ? invalid8() : { name: name3, schema: {
7884
+ if (stable2(definitions2.map(publicField)) !== stable2(schema2.fields)) return invalid9();
7885
+ let display = parseRecordDisplay2(schema2.display, definitions2);
7886
+ return { name: name3, schema: {
7834
7887
  type: schema2.type,
7835
7888
  fields: definitions2,
7889
+ ...display ? { display } : {},
7836
7890
  ...schema2.description === void 0 ? {} : { description: schema2.description }
7837
7891
  } };
7838
7892
  }), types = /* @__PURE__ */ new Map();
7839
7893
  for (let collection of catalogue) {
7840
7894
  let records = collections[collection.name];
7841
- if (!Array.isArray(records)) return invalid8();
7895
+ if (!Array.isArray(records)) return invalid9();
7842
7896
  let previous = "";
7843
7897
  for (let record4 of records) {
7844
7898
  let value = object5(record4);
7845
- if (!validRecordRef(value.$ref) || snapshotCollection(catalogue, value.$ref)?.name !== collection.name || value.$ref <= previous || types.has(value.$ref) || typeof value.$version != "string" || !/^record-v1:[0-9a-f]{64}$/.test(value.$version)) return invalid8();
7899
+ if (!validRecordRef(value.$ref) || snapshotCollection(catalogue, value.$ref)?.name !== collection.name || value.$ref <= previous || types.has(value.$ref) || typeof value.$version != "string" || !/^record-v1:[0-9a-f]{64}$/.test(value.$version)) return invalid9();
7846
7900
  types.set(value.$ref, collection.schema.type), previous = value.$ref;
7847
7901
  }
7848
7902
  }
7849
7903
  for (let collection of catalogue) for (let record4 of collections[collection.name]) {
7850
7904
  let { $ref: _ref, $version: _version, $body, $signals, $timeline, ...values } = record4;
7851
7905
  if (legacy) {
7852
- if (Object.hasOwn(record4, "$signals") || Object.hasOwn(record4, "$timeline")) return invalid8();
7906
+ if (Object.hasOwn(record4, "$signals") || Object.hasOwn(record4, "$timeline")) return invalid9();
7853
7907
  } else if (captureRecordSignals($signals), timelines.includes(collection.name)) {
7854
- if (!Array.isArray($timeline)) return invalid8();
7908
+ if (!Array.isArray($timeline)) return invalid9();
7855
7909
  $timeline.forEach((value) => captureTimeline(value));
7856
- } else if (Object.hasOwn(record4, "$timeline")) return invalid8();
7857
- if (Object.hasOwn(record4, "$body") && (!bodies.includes(collection.name) || typeof $body != "string")) return invalid8();
7910
+ } else if (Object.hasOwn(record4, "$timeline")) return invalid9();
7911
+ if (Object.hasOwn(record4, "$body") && (!bodies.includes(collection.name) || typeof $body != "string")) return invalid9();
7858
7912
  validateRecordFields(values, collection.schema.fields, (ref, targets) => types.get(ref) ?? targets[0], !0);
7859
7913
  }
7860
7914
  let normalized = legacy ? Object.fromEntries(Object.entries(collections).map(([collection, records]) => [
@@ -7873,7 +7927,7 @@ function validateSnapshotEnvelope(input, repository, name2, bodies = [], timelin
7873
7927
  ...Object.hasOwn(row, "history") ? { history: validateSnapshotHistory(row.history, normalized, row.version) } : {}
7874
7928
  };
7875
7929
  } catch {
7876
- return invalid8();
7930
+ return invalid9();
7877
7931
  }
7878
7932
  }
7879
7933
 
@@ -7980,14 +8034,14 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
7980
8034
 
7981
8035
  var snapshotAcquisitionType = "application/vnd.os.data-snapshot.v2+json", snapshotAcquisitionFormat = "data-snapshot-acquisition.v2", snapshotPairHeader = "Snapshot-Pair", validSnapshotPairToken = (value) => typeof value == "string" && /^snapshot-pair-v1:[0-9a-f]{64}$/.test(value), snapshotArtifactHeader = "Snapshot-Artifact", validSnapshotArtifactToken = (value) => typeof value == "string" && /^snapshot-artifact-v1:[0-9a-f]{64}$/.test(value), snapshotUpdatesProtocol = "os.data-snapshot.updates.v1", snapshotUpdatesCredentialPrefix = "os.member.", snapshotUpdateHint = "update";
7982
8036
 
7983
- var invalid9 = () => {
8037
+ var invalid10 = () => {
7984
8038
  throw new DataOperationError("unavailable", !0);
7985
- }, object6 = (v) => v && typeof v == "object" && !Array.isArray(v) ? v : invalid9(), uuid = (v) => typeof v == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v), time2 = (v) => typeof v == "string" && Number.isFinite(Date.parse(v)), recordVersion = (v) => typeof v == "string" && /^record-v1:[0-9a-f]{64}$/.test(v), keys4 = (v, allowed) => Object.keys(v).every((k) => allowed.includes(k));
8039
+ }, object6 = (v) => v && typeof v == "object" && !Array.isArray(v) ? v : invalid10(), uuid = (v) => typeof v == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v), time2 = (v) => typeof v == "string" && Number.isFinite(Date.parse(v)), recordVersion = (v) => typeof v == "string" && /^record-v1:[0-9a-f]{64}$/.test(v), keys4 = (v, allowed) => Object.keys(v).every((k) => allowed.includes(k));
7986
8040
  function validateAcquisition(input, repository, name2) {
7987
8041
  let row = object6(input), snapshot = object6(row.snapshot);
7988
- if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !keys4(snapshot, ["id", "name", "refreshedAt", "repository", "version", "collections", "bodies", "timelines"]) || !uuid(snapshot.id) || snapshot.repository !== repository || snapshot.name !== name2 || !dataVersion(snapshot.version) || !time2(snapshot.refreshedAt) || !Array.isArray(snapshot.collections) || !snapshot.collections.length || !snapshot.collections.every((c) => typeof c == "string" && validRecordRef(`${c}/example`)) || snapshot.collections.join("\0") !== [...new Set(snapshot.collections)].sort().join("\0") || !Array.isArray(row.changes)) return invalid9();
8042
+ if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !keys4(snapshot, ["id", "name", "refreshedAt", "repository", "version", "collections", "bodies", "timelines"]) || !uuid(snapshot.id) || snapshot.repository !== repository || snapshot.name !== name2 || !dataVersion(snapshot.version) || !time2(snapshot.refreshedAt) || !Array.isArray(snapshot.collections) || !snapshot.collections.length || !snapshot.collections.every((c) => typeof c == "string" && validRecordRef(`${c}/example`)) || snapshot.collections.join("\0") !== [...new Set(snapshot.collections)].sort().join("\0") || !Array.isArray(row.changes)) return invalid10();
7989
8043
  let bodies = snapshot.bodies === void 0 ? [] : snapshot.bodies, timelines = snapshot.timelines === void 0 ? [] : snapshot.timelines;
7990
- for (let subset of [bodies, timelines]) if (!Array.isArray(subset) || subset.some((c) => !snapshot.collections.includes(c)) || subset.join("\0") !== [...new Set(subset)].sort().join("\0")) return invalid9();
8044
+ for (let subset of [bodies, timelines]) if (!Array.isArray(subset) || subset.some((c) => !snapshot.collections.includes(c)) || subset.join("\0") !== [...new Set(subset)].sort().join("\0")) return invalid10();
7991
8045
  return {
7992
8046
  snapshot: { ...snapshot, bodies, timelines },
7993
8047
  changes: validateSnapshotChanges(row.changes, snapshot.collections)
@@ -7995,47 +8049,47 @@ function validateAcquisition(input, repository, name2) {
7995
8049
  }
7996
8050
  function validateSnapshotChanges(input, collections) {
7997
8051
  try {
7998
- if (!Array.isArray(input)) return invalid9();
8052
+ if (!Array.isArray(input)) return invalid10();
7999
8053
  let ids = /* @__PURE__ */ new Set(), unpublished = !1;
8000
8054
  for (let value of input) {
8001
8055
  let c = object6(value), effect = object6(c.effect);
8002
- if (!keys4(c, ["id", "version", "ref", "recordVersion", "effect", "updatedAt", "person", "source", "publication"]) || !uuid(c.id) || ids.has(c.id) || !dataVersion(c.version) || !validRecordRef(c.ref) || !collections.some((name2) => c.ref.startsWith(`${name2}/`)) || !recordVersion(c.recordVersion) || !time2(c.updatedAt)) return invalid9();
8056
+ if (!keys4(c, ["id", "version", "ref", "recordVersion", "effect", "updatedAt", "person", "source", "publication"]) || !uuid(c.id) || ids.has(c.id) || !dataVersion(c.version) || !validRecordRef(c.ref) || !collections.some((name2) => c.ref.startsWith(`${name2}/`)) || !recordVersion(c.recordVersion) || !time2(c.updatedAt)) return invalid10();
8003
8057
  if (ids.add(c.id), c.person !== void 0) {
8004
8058
  let person = object6(c.person);
8005
- if (!keys4(person, ["id", "name", "email"]) || !uuid(person.id) || person.name !== void 0 && !dataText(person.name) || person.email !== void 0 && !dataText(person.email)) return invalid9();
8059
+ if (!keys4(person, ["id", "name", "email"]) || !uuid(person.id) || person.name !== void 0 && !dataText(person.name) || person.email !== void 0 && !dataText(person.email)) return invalid10();
8006
8060
  }
8007
8061
  if (c.source !== void 0) {
8008
8062
  let source2 = object6(c.source);
8009
- if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine" || !dataText(source2.id)) return invalid9();
8063
+ if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine" || !dataText(source2.id)) return invalid10();
8010
8064
  }
8011
8065
  if (c.publication !== void 0) {
8012
8066
  let publication = object6(c.publication);
8013
- if (unpublished || Object.keys(publication).sort().join(",") !== "commit,time" || typeof publication.commit != "string" || !/^[0-9a-f]{40}$/.test(publication.commit) || !time2(publication.time)) return invalid9();
8067
+ if (unpublished || Object.keys(publication).sort().join(",") !== "commit,time" || typeof publication.commit != "string" || !/^[0-9a-f]{40}$/.test(publication.commit) || !time2(publication.time)) return invalid10();
8014
8068
  } else unpublished = !0;
8015
8069
  if (effect.kind === "set") {
8016
- if (Object.keys(effect).sort().join(",") !== "field,kind,value" || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field)) return invalid9();
8070
+ if (Object.keys(effect).sort().join(",") !== "field,kind,value" || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field)) return invalid10();
8017
8071
  } else if (effect.kind === "link" || effect.kind === "unlink") {
8018
- if (!keys4(effect, ["kind", "field", "refs", ...effect.kind === "link" ? ["remove"] : []]) || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field) || !Array.isArray(effect.refs) || !effect.refs.length || effect.refs.length > 1e5 || effect.refs.some((ref) => !validRecordRef(ref)) || new Set(effect.refs).size !== effect.refs.length || effect.remove !== void 0 && (!Array.isArray(effect.remove) || !effect.remove.length || effect.remove.length > 1e5 || effect.remove.some((ref) => !validRecordRef(ref)) || new Set(effect.remove).size !== effect.remove.length)) return invalid9();
8072
+ if (!keys4(effect, ["kind", "field", "refs", ...effect.kind === "link" ? ["remove"] : []]) || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field) || !Array.isArray(effect.refs) || !effect.refs.length || effect.refs.length > 1e5 || effect.refs.some((ref) => !validRecordRef(ref)) || new Set(effect.refs).size !== effect.refs.length || effect.remove !== void 0 && (!Array.isArray(effect.remove) || !effect.remove.length || effect.remove.length > 1e5 || effect.remove.some((ref) => !validRecordRef(ref)) || new Set(effect.remove).size !== effect.remove.length)) return invalid10();
8019
8073
  } else if (effect.kind === "signal") {
8020
- if (Object.keys(effect).sort().join(",") !== "key,kind,value") return invalid9();
8074
+ if (Object.keys(effect).sort().join(",") !== "key,kind,value") return invalid10();
8021
8075
  let value2 = object6(effect.value);
8022
- if (!keys4(value2, ["label", "status", "reason", "related", "asOf", "number"])) return invalid9();
8076
+ if (!keys4(value2, ["label", "status", "reason", "related", "asOf", "number"])) return invalid10();
8023
8077
  let { number, ...assessment } = value2;
8024
8078
  captureSignal({ ...assessment, key: effect.key }), (c.publication || Object.hasOwn(value2, "number")) && captureRecordSignal({ ...value2, key: effect.key });
8025
8079
  } else if (effect.kind === "timeline") {
8026
- if (Object.keys(effect).sort().join(",") !== "entry,kind") return invalid9();
8080
+ if (Object.keys(effect).sort().join(",") !== "entry,kind") return invalid10();
8027
8081
  captureTimeline(effect.entry);
8028
8082
  } else if (effect.kind === "create" || effect.kind === "delete") {
8029
- if (!keys4(effect, ["fields", "kind", "signals", "timeline"])) return invalid9();
8083
+ if (!keys4(effect, ["fields", "kind", "signals", "timeline"])) return invalid10();
8030
8084
  if (object6(effect.fields), Object.hasOwn(effect, "signals") && captureRecordSignals(effect.signals), Object.hasOwn(effect, "timeline")) {
8031
- if (!Array.isArray(effect.timeline)) return invalid9();
8085
+ if (!Array.isArray(effect.timeline)) return invalid10();
8032
8086
  effect.timeline.forEach((value2) => captureTimeline(value2));
8033
8087
  }
8034
- } else return invalid9();
8088
+ } else return invalid10();
8035
8089
  }
8036
8090
  return input;
8037
8091
  } catch {
8038
- return invalid9();
8092
+ return invalid10();
8039
8093
  }
8040
8094
  }
8041
8095
  function materializeSnapshot(envelope, changes, version) {
@@ -8044,13 +8098,13 @@ function materializeSnapshot(envelope, changes, version) {
8044
8098
  let rows = new Map(Object.values(envelope.collections).flat().map((r) => [r.$ref, structuredClone(r)]));
8045
8099
  for (let c of changes) {
8046
8100
  let schema2 = snapshotCollection(envelope.catalogue, c.ref);
8047
- if (!schema2) return invalid9();
8101
+ if (!schema2) return invalid10();
8048
8102
  let effect = c.effect, definitions2 = "field" in effect ? schema2.schema.fields.filter((f) => f.name === effect.field) : schema2.schema.fields;
8049
- if ("field" in effect && !definitions2.length) return invalid9();
8103
+ if ("field" in effect && !definitions2.length) return invalid10();
8050
8104
  let values;
8051
8105
  if (effect.kind === "link" || effect.kind === "unlink") {
8052
8106
  let field = definitions2[0];
8053
- if (field.kind !== "link" || !field.many && effect.kind === "link" && effect.refs.length !== 1) return invalid9();
8107
+ if (field.kind !== "link" || !field.many && effect.kind === "link" && effect.refs.length !== 1) return invalid10();
8054
8108
  let targets = [...effect.refs, ...effect.kind === "link" ? effect.remove ?? [] : []];
8055
8109
  for (let ref of targets) validateRecordFields({ [effect.field]: field.many ? [ref] : ref }, definitions2, (_ref, allowed) => allowed[0], !0);
8056
8110
  values = { [effect.field]: field.many ? effect.refs : effect.refs[0] };
@@ -8063,25 +8117,25 @@ function materializeSnapshot(envelope, changes, version) {
8063
8117
  ), !c.publication) continue;
8064
8118
  let prior = rows.get(c.ref);
8065
8119
  if (effect.kind === "set") {
8066
- if (!prior) return invalid9();
8120
+ if (!prior) return invalid10();
8067
8121
  rows.set(c.ref, { ...prior, [effect.field]: effect.value, $version: c.recordVersion });
8068
8122
  } else if (effect.kind === "link" || effect.kind === "unlink") {
8069
- if (!prior) return invalid9();
8123
+ if (!prior) return invalid10();
8070
8124
  let field = definitions2[0], current2 = prior[effect.field], value = field.many ? effect.kind === "link" ? [.../* @__PURE__ */ new Set([...Array.isArray(current2) ? current2 : [], ...effect.refs])].filter((ref) => !effect.remove?.includes(String(ref))) : (Array.isArray(current2) ? current2 : []).filter((ref) => !effect.refs.includes(String(ref))) : effect.kind === "link" ? effect.remove?.includes(effect.refs[0]) ? null : effect.refs[0] : effect.refs.includes(String(current2)) ? null : current2;
8071
8125
  rows.set(c.ref, { ...prior, [effect.field]: value, $version: c.recordVersion });
8072
8126
  } else if (effect.kind === "signal") {
8073
- if (!prior || !effect.value.number) return invalid9();
8127
+ if (!prior || !effect.value.number) return invalid10();
8074
8128
  let signal = captureRecordSignal({ ...effect.value, key: effect.key }), signals = captureRecordSignals(prior.$signals), index = signals.findIndex((row) => row.key === effect.key);
8075
8129
  index < 0 ? signals.push(signal) : signals[index] = signal, rows.set(c.ref, { ...prior, $signals: captureRecordSignals(signals), $version: c.recordVersion });
8076
8130
  } else if (effect.kind === "timeline") {
8077
- if (!prior) return invalid9();
8131
+ if (!prior) return invalid10();
8078
8132
  rows.set(c.ref, {
8079
8133
  ...prior,
8080
8134
  $version: c.recordVersion,
8081
8135
  ...envelope.timelineCollections.includes(schema2.name) ? { $timeline: [...prior.$timeline, effect.entry] } : {}
8082
8136
  });
8083
8137
  } else if (effect.kind === "create") {
8084
- if (prior) return invalid9();
8138
+ if (prior) return invalid10();
8085
8139
  rows.set(c.ref, {
8086
8140
  ...effect.fields,
8087
8141
  $ref: c.ref,
@@ -8090,7 +8144,7 @@ function materializeSnapshot(envelope, changes, version) {
8090
8144
  ...envelope.timelineCollections.includes(schema2.name) ? { $timeline: effect.timeline ?? [] } : {}
8091
8145
  });
8092
8146
  } else {
8093
- if (!prior) return invalid9();
8147
+ if (!prior) return invalid10();
8094
8148
  rows.delete(c.ref);
8095
8149
  }
8096
8150
  }
@@ -8099,16 +8153,11 @@ function materializeSnapshot(envelope, changes, version) {
8099
8153
  repository: envelope.repository,
8100
8154
  name: envelope.name,
8101
8155
  version,
8102
- schemas: Object.fromEntries(envelope.catalogue.map((c) => [c.name, {
8103
- name: c.name,
8104
- type: c.schema.type,
8105
- ...c.schema.description === void 0 ? {} : { description: c.schema.description },
8106
- fields: c.schema.fields.map(publicField)
8107
- }])),
8156
+ schemas: Object.fromEntries(envelope.catalogue.map((c) => [c.name, publicCollectionSchema(c)])),
8108
8157
  collections: Object.fromEntries(envelope.catalogue.map((c) => [c.name, [...rows.values()].filter((r) => snapshotCollection(envelope.catalogue, r.$ref)?.name === c.name).sort((a, b) => a.$ref < b.$ref ? -1 : 1)]))
8109
8158
  }, envelope.repository, envelope.name, envelope.bodyCollections, envelope.timelineCollections), ...envelope.history ? { history: envelope.history } : {} };
8110
8159
  } catch {
8111
- return invalid9();
8160
+ return invalid10();
8112
8161
  }
8113
8162
  }
8114
8163
 
@@ -8150,12 +8199,7 @@ function applySnapshotMutation(envelope, prior, mutation, installation) {
8150
8199
  repository: envelope.repository,
8151
8200
  name: envelope.name,
8152
8201
  version: `snapshot-${crypto.randomUUID()}`,
8153
- schemas: Object.fromEntries(envelope.catalogue.map((c) => [c.name, {
8154
- name: c.name,
8155
- type: c.schema.type,
8156
- ...c.schema.description === void 0 ? {} : { description: c.schema.description },
8157
- fields: c.schema.fields.map(publicField)
8158
- }])),
8202
+ schemas: Object.fromEntries(envelope.catalogue.map((c) => [c.name, publicCollectionSchema(c)])),
8159
8203
  collections: Object.fromEntries(envelope.catalogue.map((c) => [c.name, [...rows.values()].filter((r) => snapshotCollection(envelope.catalogue, r.$ref)?.name === c.name).sort((a, b) => a.$ref < b.$ref ? -1 : 1)]))
8160
8204
  }, envelope.repository, envelope.name, envelope.bodyCollections, envelope.timelineCollections), { envelope, changes };
8161
8205
  }
@@ -8602,19 +8646,19 @@ function captureSelection(input) {
8602
8646
  }
8603
8647
  }
8604
8648
 
8605
- var invalid10 = () => {
8649
+ var invalid11 = () => {
8606
8650
  throw new DataOperationError("invalid_query");
8607
8651
  };
8608
8652
  function captureSnapshotAll(query, options) {
8609
8653
  let properties = dataProperties(options);
8610
- return Object.keys(properties).some((key) => !["maxRecords", "body", "timeline"].includes(key)) || properties.body && properties.body.value !== !0 || properties.timeline && properties.timeline.value !== !0 ? invalid10() : { ...captureRecordsAll(query, { maxRecords: properties.maxRecords?.value }), body: properties.body?.value === !0, timeline: properties.timeline?.value === !0 };
8654
+ return Object.keys(properties).some((key) => !["maxRecords", "body", "timeline"].includes(key)) || properties.body && properties.body.value !== !0 || properties.timeline && properties.timeline.value !== !0 ? invalid11() : { ...captureRecordsAll(query, { maxRecords: properties.maxRecords?.value }), body: properties.body?.value === !0, timeline: properties.timeline?.value === !0 };
8611
8655
  }
8612
8656
  var safeName = (value) => typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
8613
8657
  function createSnapshotInitializer(resolve = resolveSnapshotContext, open = openSnapshotStore, connect = (url, protocols) => new WebSocket(url, protocols)) {
8614
8658
  let pending = /* @__PURE__ */ new WeakMap();
8615
8659
  return async function(input) {
8616
8660
  let properties = dataProperties(input), repository = properties.repository?.value, snapshot = properties.snapshot?.value;
8617
- if (Object.keys(properties).sort().join(",") !== "repository,snapshot" || !safeName(repository) || !safeName(snapshot)) return invalid10();
8661
+ if (Object.keys(properties).sort().join(",") !== "repository,snapshot" || !safeName(repository) || !safeName(snapshot)) return invalid11();
8618
8662
  let authority2 = await resolve(), invalidated = !1, stopLive, assertCurrent = () => {
8619
8663
  if (invalidated || authority2.signal.aborted || !authority2.isCurrent() || !authority2.refresh && authority2.expiresAt <= Date.now())
8620
8664
  throw invalidated = !0, stopLive?.(), new DataOperationError("context_unavailable");
@@ -8772,7 +8816,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
8772
8816
  let store;
8773
8817
  try {
8774
8818
  let selections = planIndexQuery(captured, pinned.catalogue), checkTimeline = (collection, selection2) => {
8775
- if ((timeline || selection2.timeline) && !pinned.timelineCollections.includes(collection)) return invalid10();
8819
+ if ((timeline || selection2.timeline) && !pinned.timelineCollections.includes(collection)) return invalid11();
8776
8820
  for (let link of selection2.links) for (let [name2, nested] of link.targets) checkTimeline(name2, nested);
8777
8821
  };
8778
8822
  for (let { name: name2, selection: selection2 } of selections) checkTimeline(name2, selection2);
@@ -8850,7 +8894,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
8850
8894
  return snapshotCollection(installation.catalogue, captured) ? writes.then(() => {
8851
8895
  let pinned = installation;
8852
8896
  return localRead(async (store) => {
8853
- if (timeline && !pinned.timelineCollections.includes(snapshotCollection(pinned.catalogue, captured).name)) return invalid10();
8897
+ if (timeline && !pinned.timelineCollections.includes(snapshotCollection(pinned.catalogue, captured).name)) return invalid11();
8854
8898
  let record4 = await store.read(pinned, captured);
8855
8899
  if (!record4) return record4;
8856
8900
  let { $body, $timeline, ...structured } = record4;
@@ -9037,7 +9081,7 @@ async function hostedContent(url, init2, parent, upstream = fetch, check = async
9037
9081
  }
9038
9082
  }
9039
9083
 
9040
- var MAX_BYTES = 16 * 1024 * 1024, PART_BYTES = 8 * 1024 * 1024, METADATA_BYTES = 4096, RESULT_BYTES = 16 * 1024, CONTROL_RESULT_BYTES = 128 * 1024, TIMEOUT_MS = 3e4, MAX_ACTIVE = 4, ATTEMPTS = 2, active = 0, waiters = [], invalid11 = () => new FileOperationError("invalid_input", 400), unavailable4 = () => new FileOperationError("unavailable", 503, !0), failures = {
9084
+ var MAX_BYTES = 16 * 1024 * 1024, PART_BYTES = 8 * 1024 * 1024, METADATA_BYTES = 4096, RESULT_BYTES = 16 * 1024, CONTROL_RESULT_BYTES = 128 * 1024, TIMEOUT_MS = 3e4, MAX_ACTIVE = 4, ATTEMPTS = 2, active = 0, waiters = [], invalid12 = () => new FileOperationError("invalid_input", 400), unavailable4 = () => new FileOperationError("unavailable", 503, !0), failures = {
9041
9085
  400: ["invalid_input", "unsupported_context"],
9042
9086
  401: ["unauthenticated"],
9043
9087
  403: ["access_denied"],
@@ -9193,7 +9237,7 @@ async function send(suffix, init2, descriptor, initial, parent) {
9193
9237
  throw unavailable4();
9194
9238
  }
9195
9239
  function idPath(id3) {
9196
- if (typeof id3 != "string" || !FILE_ID_PATTERN.test(id3)) throw invalid11();
9240
+ if (typeof id3 != "string" || !FILE_ID_PATTERN.test(id3)) throw invalid12();
9197
9241
  return `/${id3}`;
9198
9242
  }
9199
9243
  async function multipartCreate(input, metadata, exchange, release, upload, expectedSha256) {
@@ -9236,18 +9280,18 @@ async function multipartCreate(input, metadata, exchange, release, upload, expec
9236
9280
  if (!chunk || offset === chunk.byteLength) {
9237
9281
  chunk = void 0, offset = 0;
9238
9282
  let value2 = await next();
9239
- if (value2.done || !(value2.value instanceof Uint8Array) || (chunk = value2.value, chunk.byteLength > metadata.size - sent - filled)) throw invalid11();
9283
+ if (value2.done || !(value2.value instanceof Uint8Array) || (chunk = value2.value, chunk.byteLength > metadata.size - sent - filled)) throw invalid12();
9240
9284
  }
9241
9285
  let take = Math.min(length - filled, chunk.byteLength - offset);
9242
9286
  part.set(chunk.subarray(offset, offset + take), filled), filled += take, offset += take, offset === chunk.byteLength && (chunk = void 0, offset = 0);
9243
9287
  }
9244
9288
  }
9245
- if (part.byteLength !== length) throw invalid11();
9289
+ if (part.byteLength !== length) throw invalid12();
9246
9290
  if (reader && sent + length === metadata.size)
9247
9291
  for (lastProgress = Date.now(); ; ) {
9248
9292
  let value2 = await next();
9249
9293
  if (value2.done) break;
9250
- if (!(value2.value instanceof Uint8Array) || value2.value.byteLength) throw invalid11();
9294
+ if (!(value2.value instanceof Uint8Array) || value2.value.byteLength) throw invalid12();
9251
9295
  }
9252
9296
  let value = await request3((signal) => exchange(`${route}/part`, {
9253
9297
  method: "POST",
@@ -9261,7 +9305,7 @@ async function multipartCreate(input, metadata, exchange, release, upload, expec
9261
9305
  }
9262
9306
  if (upload) for (let name2 of Object.keys(upload.file.enrichments)) {
9263
9307
  let bytes = await request3(() => upload.enrichment(name2));
9264
- if (bytes.byteLength !== upload.file.enrichments[name2].size || bytes.byteLength > MAX_BYTES) throw invalid11();
9308
+ if (bytes.byteLength !== upload.file.enrichments[name2].size || bytes.byteLength > MAX_BYTES) throw invalid12();
9265
9309
  await request3((signal) => exchange(`${route}/enrichments/${encodeURIComponent(name2)}`, {
9266
9310
  method: "POST",
9267
9311
  headers: { "content-type": "application/octet-stream", "x-os-transfer": ticket },
@@ -9303,7 +9347,7 @@ async function operation(work, initial, parent) {
9303
9347
  function contentPath(id3, name2) {
9304
9348
  let path = idPath(id3);
9305
9349
  if (name2 === void 0) return `${path}/content`;
9306
- if (!safeEnrichmentName(name2)) throw invalid11();
9350
+ if (!safeEnrichmentName(name2)) throw invalid12();
9307
9351
  return `${path}/enrichments/${encodeURIComponent(name2)}/content`;
9308
9352
  }
9309
9353
  async function read(id3, names) {
@@ -9312,12 +9356,12 @@ async function read(id3, names) {
9312
9356
  let path = contentPath(id3, names);
9313
9357
  return operation((context2, signal) => send(path, { method: "GET" }, !1, context2, signal), context);
9314
9358
  }
9315
- if (!Array.isArray(names)) throw invalid11();
9359
+ if (!Array.isArray(names)) throw invalid12();
9316
9360
  let distinct = [], seen = /* @__PURE__ */ new Set();
9317
9361
  for (let name2 of names) {
9318
- if (typeof name2 != "string" || !safeEnrichmentName(name2)) throw invalid11();
9362
+ if (typeof name2 != "string" || !safeEnrichmentName(name2)) throw invalid12();
9319
9363
  if (!seen.has(name2)) {
9320
- if (seen.size === 16) throw invalid11();
9364
+ if (seen.size === 16) throw invalid12();
9321
9365
  seen.add(name2), distinct.push(name2);
9322
9366
  }
9323
9367
  }
@@ -9357,9 +9401,9 @@ var files = {
9357
9401
  async create(input, options) {
9358
9402
  let context = await resolveFilesContext();
9359
9403
  if (!input || typeof input != "object" || Array.isArray(input) || Object.keys(input).some((key) => !["file", "size", "path", "name", "storage", "mediaType"].includes(key)) || options !== void 0 && (!options || typeof options != "object" || Array.isArray(options) || Object.keys(options).some((key) => key !== "requestKey")))
9360
- throw invalid11();
9404
+ throw invalid12();
9361
9405
  let blob = input.file instanceof Blob, array3 = input.file instanceof Uint8Array, stream = input.file instanceof ReadableStream;
9362
- if (!blob && !array3 && !stream) throw invalid11();
9406
+ if (!blob && !array3 && !stream) throw invalid12();
9363
9407
  let intrinsic = blob ? input.file.size : array3 ? input.file.byteLength : void 0;
9364
9408
  if (intrinsic !== void 0 && input.size !== void 0 && input.size !== intrinsic)
9365
9409
  throw !Number.isSafeInteger(input.size) || input.size < 0 ? new FileOperationError("invalid_input", 400, !1, { reason: "invalid_size" }) : new FileOperationError(
@@ -9380,7 +9424,7 @@ var files = {
9380
9424
  }, FILE_ORIGINAL_MAX_BYTES);
9381
9425
  if (!context.local && !context.localFiles && metadata.storage === "local") throw new FileOperationError("unsupported_context", 400);
9382
9426
  let header = encodeURIComponent(JSON.stringify(metadata));
9383
- if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid11();
9427
+ if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid12();
9384
9428
  let release = await acquireSlot(context.signal);
9385
9429
  if (context.localFiles && !routineTransport() && metadata.size > MAX_BYTES)
9386
9430
  try {
@@ -9429,7 +9473,7 @@ var files = {
9429
9473
  },
9430
9474
  async enrich(input) {
9431
9475
  let context = await resolveFilesContext();
9432
- if (!input || typeof input != "object" || Array.isArray(input) || Object.keys(input).some((key) => !["file", "name", "content", "mediaType", "replace"].includes(key)) || typeof input.content != "string" && !(input.content instanceof Uint8Array)) throw invalid11();
9476
+ if (!input || typeof input != "object" || Array.isArray(input) || Object.keys(input).some((key) => !["file", "name", "content", "mediaType", "replace"].includes(key)) || typeof input.content != "string" && !(input.content instanceof Uint8Array)) throw invalid12();
9433
9477
  let path = `${idPath(input.file)}/enrichments`;
9434
9478
  if (typeof input.content == "string" ? input.content.length > MAX_BYTES : input.content.byteLength > MAX_BYTES)
9435
9479
  throw new FileOperationError("request_too_large", 413);
@@ -9446,7 +9490,7 @@ var files = {
9446
9490
  ...input.mediaType === void 0 ? {} : { mediaType: input.mediaType },
9447
9491
  ...input.replace === void 0 ? {} : { replace: input.replace }
9448
9492
  }, MAX_BYTES), header = encodeURIComponent(JSON.stringify(metadata));
9449
- if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid11();
9493
+ if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid12();
9450
9494
  let result2 = await send(path, { method: "POST", headers: {
9451
9495
  "content-type": "application/octet-stream",
9452
9496
  "x-os-enrichment": header
@@ -9995,9 +10039,17 @@ var recordKey = ({ repository, ref }) => JSON.stringify([repository, ref]);
9995
10039
  function parseInboxRecords(value) {
9996
10040
  let result2 = serializable(value);
9997
10041
  if (!result2 || Object.keys(result2).join() !== "records" || !Array.isArray(result2.records) || result2.records.length > 100) throw new Error("Invalid Record result");
9998
- for (let entry of result2.records)
10042
+ for (let entry of result2.records) {
9999
10043
  if (validateQualifiedRecordRef({ repository: entry.repository, ref: entry.ref }), Object.keys(entry).sort().join() !== "record,ref,repository,schema" || (entry.record === null ? entry.schema !== null : !entry.schema || entry.record.$ref !== entry.ref || typeof entry.record.$version != "string" || !Array.isArray(entry.schema.fields) || typeof entry.schema.name != "string"))
10000
10044
  throw new Error("Invalid current Record");
10045
+ if (entry.schema)
10046
+ try {
10047
+ if (JSON.stringify(parseRecordDisplay(entry.schema.display, entry.schema.fields)) !== JSON.stringify(entry.schema.display))
10048
+ throw new Error("Invalid current Record");
10049
+ } catch {
10050
+ throw new Error("Invalid current Record");
10051
+ }
10052
+ }
10001
10053
  if (new Set(result2.records.map(recordKey)).size !== result2.records.length) throw new Error("Duplicate current Record");
10002
10054
  return result2;
10003
10055
  }
@@ -10046,7 +10098,7 @@ function parseInboxUnavailableFailure(value, status) {
10046
10098
  }
10047
10099
  var INBOX_RESULT_BYTES = 8 * 1024 * 1024, INBOX_INPUT_BYTES = 8192, INBOX_LOCAL_INPUT_BYTES = 256 * 1024, INBOX_QUESTION_CONTRACT = "question-work-v1", INBOX_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
10048
10100
  function isAppQuestionOperation(operation2) {
10049
- return operation2 === "questions.list" || operation2 === "questions.answer" || operation2 === "questions.searchRecords";
10101
+ return operation2 === "questions.list" || operation2 === "questions.answer" || operation2 === "questions.listRecordOptions";
10050
10102
  }
10051
10103
  var operations = {
10052
10104
  current: [],
@@ -10061,7 +10113,7 @@ var operations = {
10061
10113
  "items.listRecipientCandidates": ["itemId"],
10062
10114
  "items.addRecipient": ["itemId", "personId"],
10063
10115
  "questions.answer": ["itemId", "revision", "questionId", "response", "submissionKey"],
10064
- "questions.searchRecords": ["itemId", "revision", "questionId", "query"]
10116
+ "questions.listRecordOptions": ["itemId", "revision", "questionId"]
10065
10117
  };
10066
10118
  function assert(value) {
10067
10119
  if (!value) throw new Error("Invalid Inbox result");
@@ -10163,9 +10215,9 @@ function parseInboxRequest(value) {
10163
10215
  throw new InboxOperationError(426, "client_update_required");
10164
10216
  keys6(envelope, questionOperation ? ["contract", "input", "operation"] : ["input", "operation"]);
10165
10217
  let input = { ...object8(envelope.input) }, required = operations[operation2];
10166
- assert(required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || operation2 === "questions.answer" && key === "label" || operation2 === "questions.searchRecords" && key === "selected" || (operation2 === "items.list" || operation2 === "questions.list") && key === "beforeNumber" || operation2 === "questions.list" && key === "routines")), operation2 === "questions.list" && (assert(Object.hasOwn(input, "routines")), assert(array2(input.routines).every(isAppRoutineName)));
10218
+ assert(required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || operation2 === "questions.answer" && key === "label" || (operation2 === "items.list" || operation2 === "questions.list") && key === "beforeNumber" || operation2 === "questions.list" && key === "routines")), operation2 === "questions.list" && (assert(Object.hasOwn(input, "routines")), assert(array2(input.routines).every(isAppRoutineName)));
10167
10219
  for (let key of ["itemId", "personId", "fileId"]) key in input && assert(id2(input[key]));
10168
- return "revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text4(input.questionId) && input.questionId === input.questionId.trim()), "submissionKey" in input && assert(text4(input.submissionKey) && input.submissionKey.length <= 128 && input.submissionKey === input.submissionKey.trim()), "title" in input && assert(text4(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "query" in input && assert(text4(input.query, !0) && input.query.length <= 256), "records" in input && (input.records = parseInboxRecordRefs(input.records)), "selected" in input && recordReference(input.selected), "response" in input && response(input.response), "label" in input && assert(text4(input.label) && typeof input.response?.selection == "object"), assert(new TextEncoder().encode(JSON.stringify(envelope)).byteLength <= INBOX_INPUT_BYTES), "routines" in input && (input.routines = [...new Set(input.routines)]), { operation: operation2, input, ...isAppQuestionOperation(operation2) ? { contract: INBOX_QUESTION_CONTRACT } : {} };
10220
+ return "revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text4(input.questionId) && input.questionId === input.questionId.trim()), "submissionKey" in input && assert(text4(input.submissionKey) && input.submissionKey.length <= 128 && input.submissionKey === input.submissionKey.trim()), "title" in input && assert(text4(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "records" in input && (input.records = parseInboxRecordRefs(input.records)), "response" in input && response(input.response), "label" in input && assert(text4(input.label) && typeof input.response?.selection == "object"), assert(new TextEncoder().encode(JSON.stringify(envelope)).byteLength <= INBOX_INPUT_BYTES), "routines" in input && (input.routines = [...new Set(input.routines)]), { operation: operation2, input, ...isAppQuestionOperation(operation2) ? { contract: INBOX_QUESTION_CONTRACT } : {} };
10169
10221
  } catch (error) {
10170
10222
  throw error instanceof InboxOperationError ? error : new InboxOperationError(400, "invalid_input");
10171
10223
  }
@@ -10299,14 +10351,18 @@ function parseInboxResult(operation2, value) {
10299
10351
  return assert(id2(addition.addedPersonId) && item.people.some((person) => person.id === addition.addedPersonId)), { ...addition, item };
10300
10352
  }
10301
10353
  if (operation2 === "questions.answer") return parseInboxAcceptance(value);
10302
- if (operation2 === "questions.searchRecords") {
10354
+ if (operation2 === "questions.listRecordOptions") {
10303
10355
  let result2 = object8(value);
10304
- assert(text4(result2.recordType) && integer(result2.eligibleCount, 0) && integer(result2.matchCount, 0) && Number(result2.matchCount) <= Number(result2.eligibleCount));
10305
- let labeled = (value2) => {
10306
- let record4 = object8(value2);
10307
- recordReference({ repository: record4.repository, ref: record4.ref }), assert(text4(record4.label)), "reason" in record4 && assert(text4(record4.reason));
10308
- };
10309
- return array2(result2.matches).forEach(labeled), array2(result2.suggestions).forEach(labeled), "selected" in result2 && labeled(result2.selected), result2;
10356
+ keys6(result2, ["recordType", "eligibleCount", "options"]), assert(text4(result2.recordType) && integer(result2.eligibleCount, 0));
10357
+ let options = array2(result2.options);
10358
+ assert(options.length === result2.eligibleCount);
10359
+ let refs = /* @__PURE__ */ new Set();
10360
+ return options.forEach((value2) => {
10361
+ let option = object8(value2);
10362
+ keys6(option, ["repository", "ref", "label", "searchText"]), recordReference({ repository: option.repository, ref: option.ref }), assert(text4(option.label) && option.searchText === normalizeRecordOptionSearch(option.label));
10363
+ let key = JSON.stringify([option.repository, option.ref]);
10364
+ assert(!refs.has(key)), refs.add(key);
10365
+ }), assert(new TextEncoder().encode(JSON.stringify(result2)).byteLength <= recordOptionCatalogueByteLimit), result2;
10310
10366
  }
10311
10367
  throw new Error("File content is not a JSON result");
10312
10368
  }
@@ -10679,7 +10735,7 @@ function appContext(origin, active2, changed) {
10679
10735
  }
10680
10736
  }
10681
10737
  async function requestInbox(operation2, input, signal) {
10682
- if (!["questions.list", "questions.answer", "questions.searchRecords"].includes(operation2)) throw new Error("Inbox operation unavailable");
10738
+ if (!["questions.list", "questions.answer", "questions.listRecordOptions"].includes(operation2)) throw new Error("Inbox operation unavailable");
10683
10739
  return requestChecked("inbox", { method: "POST", body: JSON.stringify({ contract: INBOX_QUESTION_CONTRACT, operation: operation2, input }), signal }, !0);
10684
10740
  }
10685
10741
  async function requestRoutine(key, suffix, init2 = {}) {
@@ -11034,7 +11090,7 @@ var inbox = {
11034
11090
  } while (!0);
11035
11091
  },
11036
11092
  answer: async (input) => await send2("questions.answer", input),
11037
- searchRecords: async (input) => await send2("questions.searchRecords", input)
11093
+ listRecordOptions: async (input) => await send2("questions.listRecordOptions", input)
11038
11094
  }
11039
11095
  };
11040
11096
 
@@ -11897,11 +11953,11 @@ function routineRunHandle(operations2) {
11897
11953
  });
11898
11954
  }
11899
11955
 
11900
- var name = /^[a-z0-9][a-z0-9-]{0,62}$/, uuid2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, invalid12 = () => {
11956
+ var name = /^[a-z0-9][a-z0-9-]{0,62}$/, uuid2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, invalid13 = () => {
11901
11957
  throw new Error("Run state unavailable");
11902
- }, record3 = (value) => value && typeof value == "object" && !Array.isArray(value) ? value : invalid12();
11958
+ }, record3 = (value) => value && typeof value == "object" && !Array.isArray(value) ? value : invalid13();
11903
11959
  function time3(value) {
11904
- return typeof value != "string" || value.length > 40 || !Number.isFinite(Date.parse(value)) ? invalid12() : value;
11960
+ return typeof value != "string" || value.length > 40 || !Number.isFinite(Date.parse(value)) ? invalid13() : value;
11905
11961
  }
11906
11962
  function times(value) {
11907
11963
  return {
@@ -11910,16 +11966,16 @@ function times(value) {
11910
11966
  };
11911
11967
  }
11912
11968
  function bounded(value) {
11913
- return assertRoutineJson(value), new TextEncoder().encode(JSON.stringify(value)).byteLength > 256 * 1024 ? invalid12() : value;
11969
+ return assertRoutineJson(value), new TextEncoder().encode(JSON.stringify(value)).byteLength > 256 * 1024 ? invalid13() : value;
11914
11970
  }
11915
11971
  function progress(value) {
11916
11972
  if (value === void 0) return {};
11917
11973
  let v = record3(value);
11918
- return Object.keys(v).sort().join(",") !== "completed,total" || !Number.isSafeInteger(v.completed) || !Number.isSafeInteger(v.total) || v.completed < 1 || v.completed > v.total ? invalid12() : { progress: { completed: v.completed, total: v.total } };
11974
+ return Object.keys(v).sort().join(",") !== "completed,total" || !Number.isSafeInteger(v.completed) || !Number.isSafeInteger(v.total) || v.completed < 1 || v.completed > v.total ? invalid13() : { progress: { completed: v.completed, total: v.total } };
11919
11975
  }
11920
11976
  function parseRunStep(value, expected) {
11921
11977
  let v = record3(value);
11922
- if (typeof v.id != "string" || !name.test(v.id) || expected !== void 0 && v.id !== expected || typeof v.title != "string" || !v.title.trim() || v.title.length > 256 || !["pending", "running", "completed", "failed", "skipped"].includes(v.status)) return invalid12();
11978
+ if (typeof v.id != "string" || !name.test(v.id) || expected !== void 0 && v.id !== expected || typeof v.title != "string" || !v.title.trim() || v.title.length > 256 || !["pending", "running", "completed", "failed", "skipped"].includes(v.status)) return invalid13();
11923
11979
  let output = captureRetainedStepOutput(v.id, {
11924
11980
  ...Object.hasOwn(v, "summary") ? { summary: v.summary } : {},
11925
11981
  ...Object.hasOwn(v, "data") ? { data: v.data } : {}
@@ -11936,23 +11992,23 @@ function parseRunStep(value, expected) {
11936
11992
  }
11937
11993
  function parseRemoteRun(value, expected = {}) {
11938
11994
  let v = record3(value);
11939
- if (typeof v.id != "string" || !uuid2.test(v.id) || expected.id !== void 0 && v.id !== expected.id || typeof v.routine != "string" || !name.test(v.routine) || expected.routine !== void 0 && v.routine !== expected.routine || v.placement !== "remote" || !["queued", "running", "succeeded", "failed"].includes(v.status) || !Array.isArray(v.steps) || v.steps.length > 64) return invalid12();
11995
+ if (typeof v.id != "string" || !uuid2.test(v.id) || expected.id !== void 0 && v.id !== expected.id || typeof v.routine != "string" || !name.test(v.routine) || expected.routine !== void 0 && v.routine !== expected.routine || v.placement !== "remote" || !["queued", "running", "succeeded", "failed"].includes(v.status) || !Array.isArray(v.steps) || v.steps.length > 64) return invalid13();
11940
11996
  let steps = v.steps.map((value2) => {
11941
11997
  let step = record3(value2);
11942
- return typeof step.detailAvailable != "boolean" || Object.hasOwn(step, "data") ? invalid12() : { ...parseRunStep(step), detailAvailable: step.detailAvailable };
11998
+ return typeof step.detailAvailable != "boolean" || Object.hasOwn(step, "data") ? invalid13() : { ...parseRunStep(step), detailAvailable: step.detailAvailable };
11943
11999
  });
11944
- if (new Set(steps.map((step) => step.id)).size !== steps.length) return invalid12();
12000
+ if (new Set(steps.map((step) => step.id)).size !== steps.length) return invalid13();
11945
12001
  let failure;
11946
12002
  if (v.failure !== void 0) {
11947
12003
  let f = record3(v.failure);
11948
- if (v.status !== "failed" || typeof f.message != "string" || !f.message || f.message.length > 512) return invalid12();
12004
+ if (v.status !== "failed" || typeof f.message != "string" || !f.message || f.message.length > 512) return invalid13();
11949
12005
  if (f.code === "step_output_too_large") {
11950
12006
  let { code, message: message2, ...facts2 } = f, detail = parseRoutineStepOutputDetail(facts2);
11951
- if (!steps.some((step) => step.id === detail.step && step.status === "failed") || message2 !== routineStepOutputMessage(detail)) return invalid12();
12007
+ if (!steps.some((step) => step.id === detail.step && step.status === "failed") || message2 !== routineStepOutputMessage(detail)) return invalid13();
11952
12008
  failure = { code, message: message2, ...detail };
11953
12009
  } else failure = { message: f.message };
11954
12010
  }
11955
- return Object.hasOwn(v, "result") && v.status !== "succeeded" ? invalid12() : {
12011
+ return Object.hasOwn(v, "result") && v.status !== "succeeded" ? invalid13() : {
11956
12012
  id: v.id,
11957
12013
  routine: v.routine,
11958
12014
  placement: "remote",
@@ -12034,7 +12090,7 @@ async function request2(key, suffix, init2, maximum = SUMMARY_BYTES, retained, r
12034
12090
  clearTimeout(timeout);
12035
12091
  }
12036
12092
  }
12037
- function summary(value, key, context, id3) {
12093
+ function summary2(value, key, context, id3) {
12038
12094
  if (context.kind !== "local")
12039
12095
  try {
12040
12096
  return (!only(value, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure") || !Array.isArray(value.steps) || value.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable")) || value.failure !== void 0 && !validFailure(value.failure, value.steps)) && fail7("execution_unavailable"), parseRemoteRun(value, { routine: key, id: id3 });
@@ -12109,7 +12165,7 @@ function structure(value) {
12109
12165
  }
12110
12166
  function handle(key, id3, context) {
12111
12167
  (!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) && fail7("authority_unavailable"), (typeof id3 != "string" || !uuid3.test(id3)) && fail7("invalid_input");
12112
- let read2 = async () => summary(await request2(key, `runs/${id3}`, void 0, SUMMARY_BYTES, context, !0), key, context, id3);
12168
+ let read2 = async () => summary2(await request2(key, `runs/${id3}`, void 0, SUMMARY_BYTES, context, !0), key, context, id3);
12113
12169
  return routineRunHandle({
12114
12170
  async current() {
12115
12171
  return current(context), read2();
@@ -12172,14 +12228,14 @@ function appRoutineBinding(key) {
12172
12228
  }
12173
12229
  let context = await authority();
12174
12230
  context.kind !== "local" && (encoded = JSON.stringify({ ...JSON.parse(encoded), startKey: crypto.randomUUID() }));
12175
- let run = summary(await request2(key, "runs", { method: "POST", body: encoded }, SUMMARY_BYTES, context), key, context);
12231
+ let run = summary2(await request2(key, "runs", { method: "POST", body: encoded }, SUMMARY_BYTES, context), key, context);
12176
12232
  return handle(key, run.id, context);
12177
12233
  },
12178
12234
  runs: Object.freeze({
12179
12235
  async list() {
12180
12236
  let context = await authority(!0), value = await request2(key, "runs", void 0, 20 * SUMMARY_BYTES, context, !0);
12181
12237
  if (!Array.isArray(value) || value.length > 20) return fail7("execution_unavailable");
12182
- let runs = value.map((run) => summary(run, key, context));
12238
+ let runs = value.map((run) => summary2(run, key, context));
12183
12239
  return new Set(runs.map((run) => run.id)).size !== runs.length && fail7("execution_unavailable"), runs;
12184
12240
  },
12185
12241
  async get(id3) {