@oddington/sdk 0.1.83 → 0.1.85
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 +516 -218
- package/dist/index.js +3 -3
- package/dist/types/packages/sdk/src/data-schema-types.d.ts +4 -1
- package/dist/types/packages/sdk/src/public.d.ts +2 -2
- package/dist/types/shared/data-contract.d.ts +15 -0
- package/dist/types/shared/inbox-contract.d.ts +7 -1
- package/dist/types/shared/inbox-member-contract.d.ts +10 -4
- package/dist/types/shared/inbox-member-types.d.ts +21 -0
- package/package.json +1 -1
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
|
|
2101
|
+
let invalid18 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
|
|
2102
2102
|
if (Settings.throwOnInvalid)
|
|
2103
|
-
throw new InvalidDurationError(
|
|
2103
|
+
throw new InvalidDurationError(invalid18);
|
|
2104
2104
|
return new _Duration({
|
|
2105
|
-
invalid:
|
|
2105
|
+
invalid: invalid18
|
|
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
|
|
2372
|
+
let invalid18 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
|
|
2373
2373
|
if (Settings.throwOnInvalid)
|
|
2374
|
-
throw new InvalidIntervalError(
|
|
2374
|
+
throw new InvalidIntervalError(invalid18);
|
|
2375
2375
|
return new _Interval({
|
|
2376
|
-
invalid:
|
|
2376
|
+
invalid: invalid18
|
|
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
|
|
3234
|
-
if (
|
|
3235
|
-
return DateTime.invalid(
|
|
3233
|
+
let invalid18 = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj);
|
|
3234
|
+
if (invalid18)
|
|
3235
|
+
return DateTime.invalid(invalid18);
|
|
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,
|
|
3263
|
+
let zone = config.zone || Settings.defaultZone, invalid18 = 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 (!
|
|
3266
|
+
if (!invalid18)
|
|
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),
|
|
3271
|
+
c = tsToObj(this.ts, ot), invalid18 = Number.isNaN(c.year) ? new Invalid("invalid input") : null, c = invalid18 ? null : c, o = invalid18 ? null : ot;
|
|
3272
3272
|
}
|
|
3273
|
-
this._zone = zone, this.loc = config.loc || Locale.create(), this.invalid =
|
|
3273
|
+
this._zone = zone, this.loc = config.loc || Locale.create(), this.invalid = invalid18, 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),
|
|
3353
|
-
if (
|
|
3354
|
-
return _DateTime.invalid(
|
|
3352
|
+
let higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized, minDaysInFirstWeek, startOfWeek) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), invalid18 = higherOrderInvalid || hasInvalidTimeData(normalized);
|
|
3353
|
+
if (invalid18)
|
|
3354
|
+
return _DateTime.invalid(invalid18);
|
|
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,
|
|
3386
|
-
return
|
|
3385
|
+
}), [vals, parsedZone, specificOffset, invalid18] = parseFromTokens(localeToUse, text5, fmt);
|
|
3386
|
+
return invalid18 ? _DateTime.invalid(invalid18) : 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
|
|
3398
|
+
let invalid18 = reason instanceof Invalid ? reason : new Invalid(reason, explanation);
|
|
3399
3399
|
if (Settings.throwOnInvalid)
|
|
3400
|
-
throw new InvalidDateTimeError(
|
|
3400
|
+
throw new InvalidDateTimeError(invalid18);
|
|
3401
3401
|
return new _DateTime({
|
|
3402
|
-
invalid:
|
|
3402
|
+
invalid: invalid18
|
|
3403
3403
|
});
|
|
3404
3404
|
}
|
|
3405
3405
|
static isDateTime(o) {
|
|
@@ -5049,40 +5049,40 @@ var FileOperationError = class extends Error {
|
|
|
5049
5049
|
};
|
|
5050
5050
|
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;
|
|
5051
5051
|
function parseFileDescriptor(value) {
|
|
5052
|
-
let
|
|
5052
|
+
let invalid18 = () => {
|
|
5053
5053
|
throw new FileOperationError("unavailable", 503, !0);
|
|
5054
5054
|
};
|
|
5055
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
5055
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
5056
5056
|
let f = value;
|
|
5057
|
-
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
|
|
5057
|
+
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 invalid18();
|
|
5058
5058
|
for (let [name4, descriptor] of Object.entries(f.enrichments)) {
|
|
5059
|
-
if (!safeEnrichmentName(name4)) return
|
|
5059
|
+
if (!safeEnrichmentName(name4)) return invalid18();
|
|
5060
5060
|
parseEnrichmentDescriptor(descriptor);
|
|
5061
5061
|
}
|
|
5062
|
-
return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ?
|
|
5062
|
+
return new TextEncoder().encode(JSON.stringify(f)).byteLength > 16 * 1024 ? invalid18() : f;
|
|
5063
5063
|
}
|
|
5064
5064
|
function parseEnrichmentDescriptor(value) {
|
|
5065
|
-
let
|
|
5065
|
+
let invalid18 = () => {
|
|
5066
5066
|
throw new FileOperationError("unavailable", 503, !0);
|
|
5067
5067
|
};
|
|
5068
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
5068
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
5069
5069
|
let d = value;
|
|
5070
|
-
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) ?
|
|
5070
|
+
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) ? invalid18() : d;
|
|
5071
5071
|
}
|
|
5072
5072
|
function safeEnrichmentName(value) {
|
|
5073
5073
|
return safeFileName(value) && !/^original(?:\.|$)/i.test(value);
|
|
5074
5074
|
}
|
|
5075
5075
|
function parseFileEnrichMetadata(value, maxBytes) {
|
|
5076
|
-
let
|
|
5076
|
+
let invalid18 = (reason = "invalid_metadata") => {
|
|
5077
5077
|
throw new FileOperationError("invalid_input", 400, !1, { reason });
|
|
5078
5078
|
};
|
|
5079
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
5079
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
5080
5080
|
let d = value;
|
|
5081
|
-
if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key))) return
|
|
5082
|
-
if (!safeEnrichmentName(d.name)) return
|
|
5083
|
-
if (!Number.isSafeInteger(d.size) || d.size < 0) return
|
|
5084
|
-
if (d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType))) return
|
|
5085
|
-
if (d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return
|
|
5081
|
+
if (Object.keys(d).some((key) => !["name", "size", "mediaType", "replace"].includes(key))) return invalid18();
|
|
5082
|
+
if (!safeEnrichmentName(d.name)) return invalid18("invalid_enrichment_name");
|
|
5083
|
+
if (!Number.isSafeInteger(d.size) || d.size < 0) return invalid18("invalid_size");
|
|
5084
|
+
if (d.mediaType !== void 0 && (typeof d.mediaType != "string" || d.mediaType.length > 255 || /[\u0000-\u001f\u007f]/.test(d.mediaType))) return invalid18("invalid_media_type");
|
|
5085
|
+
if (d.replace !== void 0 && (typeof d.replace != "string" || !/^[0-9a-f]{64}$/.test(d.replace))) return invalid18("invalid_replacement");
|
|
5086
5086
|
if (d.size > maxBytes) throw new FileOperationError(
|
|
5087
5087
|
"request_too_large",
|
|
5088
5088
|
413,
|
|
@@ -5115,42 +5115,42 @@ function isCanonicalOriginalMediaType(value) {
|
|
|
5115
5115
|
}
|
|
5116
5116
|
}
|
|
5117
5117
|
function parseFileUpdate(value) {
|
|
5118
|
-
let
|
|
5118
|
+
let invalid18 = (reason = "invalid_metadata") => {
|
|
5119
5119
|
throw new FileOperationError("invalid_input", 400, !1, { reason });
|
|
5120
5120
|
};
|
|
5121
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
5121
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
5122
5122
|
let input = value, update = {};
|
|
5123
|
-
if (!Object.keys(input).length || Object.keys(input).some((key) => !["name", "path", "mediaType"].includes(key))) return
|
|
5123
|
+
if (!Object.keys(input).length || Object.keys(input).some((key) => !["name", "path", "mediaType"].includes(key))) return invalid18();
|
|
5124
5124
|
if (Object.hasOwn(input, "name")) {
|
|
5125
|
-
if (!safeFileName(input.name)) return
|
|
5125
|
+
if (!safeFileName(input.name)) return invalid18("invalid_name");
|
|
5126
5126
|
update.name = input.name;
|
|
5127
5127
|
}
|
|
5128
5128
|
if (Object.hasOwn(input, "path")) {
|
|
5129
|
-
if (!safeManagedFilePath(input.path)) return
|
|
5129
|
+
if (!safeManagedFilePath(input.path)) return invalid18("invalid_path");
|
|
5130
5130
|
update.path = input.path;
|
|
5131
5131
|
}
|
|
5132
5132
|
return Object.hasOwn(input, "mediaType") && (update.mediaType = declaredOriginalMediaType(input.mediaType)), update;
|
|
5133
5133
|
}
|
|
5134
5134
|
function parseFileCreateMetadata(value, maxBytes) {
|
|
5135
|
-
let
|
|
5135
|
+
let invalid18 = (reason = "invalid_metadata") => {
|
|
5136
5136
|
throw new FileOperationError("invalid_input", 400, !1, { reason });
|
|
5137
5137
|
};
|
|
5138
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
5138
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
5139
5139
|
let input = value;
|
|
5140
|
-
if (Object.keys(input).some((key) => !["name", "path", "storage", "mediaType", "size", "requestKey"].includes(key))) return
|
|
5140
|
+
if (Object.keys(input).some((key) => !["name", "path", "storage", "mediaType", "size", "requestKey"].includes(key))) return invalid18();
|
|
5141
5141
|
let path = input.path === void 0 ? "Files" : input.path;
|
|
5142
|
-
if (!safeFileName(input.name)) return
|
|
5143
|
-
if (!safeManagedFilePath(path)) return
|
|
5144
|
-
if (input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local") return
|
|
5142
|
+
if (!safeFileName(input.name)) return invalid18("invalid_name");
|
|
5143
|
+
if (!safeManagedFilePath(path)) return invalid18("invalid_path");
|
|
5144
|
+
if (input.storage !== void 0 && input.storage !== "remote" && input.storage !== "local") return invalid18("invalid_storage");
|
|
5145
5145
|
let mediaType = input.mediaType === void 0 ? "application/octet-stream" : declaredOriginalMediaType(input.mediaType);
|
|
5146
|
-
if (!Number.isSafeInteger(input.size) || input.size < 0) return
|
|
5146
|
+
if (!Number.isSafeInteger(input.size) || input.size < 0) return invalid18("invalid_size");
|
|
5147
5147
|
if (input.size > maxBytes) throw new FileOperationError(
|
|
5148
5148
|
"request_too_large",
|
|
5149
5149
|
413,
|
|
5150
5150
|
!1,
|
|
5151
5151
|
{ reason: "size_limit", limitBytes: maxBytes, receivedBytes: input.size }
|
|
5152
5152
|
);
|
|
5153
|
-
return typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey) ?
|
|
5153
|
+
return typeof input.requestKey != "string" || input.requestKey.length < 1 || input.requestKey.length > 256 || input.requestKey !== input.requestKey.trim() || /[\u0000-\u001f\u007f]/.test(input.requestKey) ? invalid18("invalid_request_key") : {
|
|
5154
5154
|
name: input.name,
|
|
5155
5155
|
path,
|
|
5156
5156
|
...input.storage ? { storage: input.storage } : {},
|
|
@@ -5424,6 +5424,16 @@ function selectionOptions(value, published) {
|
|
|
5424
5424
|
...option.description === void 0 ? {} : { description: text(option.description, "Record description") },
|
|
5425
5425
|
...numbered
|
|
5426
5426
|
};
|
|
5427
|
+
case "assign": {
|
|
5428
|
+
keys(option, [...common, "label", "assignee"], "assignment option");
|
|
5429
|
+
let assignee = option.assignee === void 0 ? void 0 : personReference(option.assignee, "assignment target"), isUuid = assignee !== void 0 && /^[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(assignee);
|
|
5430
|
+
return assignee !== void 0 && !isUuid && (published || assignee.length > 320 || !memberEmail.test(assignee)) && fail("Assignment target must be a workspace member UUID or email"), {
|
|
5431
|
+
type: "assign",
|
|
5432
|
+
label: text(option.label, "assignment label"),
|
|
5433
|
+
...assignee === void 0 ? {} : { assignee: isUuid ? assignee.toLowerCase() : assignee },
|
|
5434
|
+
...numbered
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5427
5437
|
case "record-picker":
|
|
5428
5438
|
return keys(option, [...common, "label", "source"], "Record picker option"), {
|
|
5429
5439
|
type: "record-picker",
|
|
@@ -5455,6 +5465,8 @@ function selectionResponse(saved, value) {
|
|
|
5455
5465
|
option || fail("Option was not published");
|
|
5456
5466
|
let answer;
|
|
5457
5467
|
switch (option.type) {
|
|
5468
|
+
case "assign":
|
|
5469
|
+
return fail("Assignment options cannot be answered");
|
|
5458
5470
|
case "choice":
|
|
5459
5471
|
answer = id(response2.value, "choice value"), answer !== option.value && fail("Choice does not match published option");
|
|
5460
5472
|
break;
|
|
@@ -6366,14 +6378,14 @@ var AIError = class extends Error {
|
|
|
6366
6378
|
code;
|
|
6367
6379
|
detail;
|
|
6368
6380
|
};
|
|
6369
|
-
function capture(value,
|
|
6381
|
+
function capture(value, invalid18, oversized, limit = ROUTINE_AI_VALUE_BYTES) {
|
|
6370
6382
|
try {
|
|
6371
6383
|
assertRoutineJson(value);
|
|
6372
6384
|
let encoded = JSON.stringify(value);
|
|
6373
6385
|
if (new TextEncoder().encode(encoded).byteLength > limit) throw new AIError(oversized);
|
|
6374
6386
|
return freezeRoutineMetadata(JSON.parse(encoded));
|
|
6375
6387
|
} catch (error) {
|
|
6376
|
-
throw error instanceof AIError ? error : new AIError(
|
|
6388
|
+
throw error instanceof AIError ? error : new AIError(invalid18);
|
|
6377
6389
|
}
|
|
6378
6390
|
}
|
|
6379
6391
|
function parseRoutineAIRequest(value) {
|
|
@@ -6438,12 +6450,12 @@ function acceptText(request3, text5) {
|
|
|
6438
6450
|
|
|
6439
6451
|
var ROUTINE_STEP_SUMMARY_BYTES = 256 * 1024, ROUTINE_STEP_OUTPUT_BYTES = 1024 * 1024;
|
|
6440
6452
|
function parseRoutineStepOutputDetail(value) {
|
|
6441
|
-
let
|
|
6453
|
+
let invalid18 = () => {
|
|
6442
6454
|
throw new AppRoutineContractError("invalid_value");
|
|
6443
6455
|
};
|
|
6444
6456
|
assertRoutineFields(value, ["step", "sizeBytes", "limitBytes", "summaryBytes", "dataBytes"]);
|
|
6445
6457
|
let { step, sizeBytes, limitBytes, summaryBytes, dataBytes } = value;
|
|
6446
|
-
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 ?
|
|
6458
|
+
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 ? invalid18() : freezeRoutineMetadata({ step, sizeBytes, limitBytes, summaryBytes, dataBytes });
|
|
6447
6459
|
}
|
|
6448
6460
|
function routineStepOutputMessage(value) {
|
|
6449
6461
|
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.";
|
|
@@ -6986,20 +6998,20 @@ var localDataPath = (value, repository) => typeof value == "string" && value.len
|
|
|
6986
6998
|
return Object.keys(row).sort().join(",") === "action,path" && ["created", "updated", "deleted"].includes(String(row.action)) && localDataPath(row.path, repository);
|
|
6987
6999
|
};
|
|
6988
7000
|
function parseDataFailureDetail(value) {
|
|
6989
|
-
let
|
|
7001
|
+
let invalid18 = () => {
|
|
6990
7002
|
throw new Error("Invalid local Data failure detail");
|
|
6991
7003
|
};
|
|
6992
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
7004
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
6993
7005
|
let row = value;
|
|
6994
|
-
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
|
|
7006
|
+
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 invalid18();
|
|
6995
7007
|
let repository = row.repository;
|
|
6996
|
-
if (!row.cause || typeof row.cause != "object" || Array.isArray(row.cause)) return
|
|
7008
|
+
if (!row.cause || typeof row.cause != "object" || Array.isArray(row.cause)) return invalid18();
|
|
6997
7009
|
let cause = row.cause;
|
|
6998
|
-
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
|
|
7010
|
+
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 invalid18();
|
|
6999
7011
|
let files3 = row.files;
|
|
7000
|
-
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
|
|
7001
|
-
for (let key of ["savedOmitted", "notAttemptedOmitted"]) if (files3[key] !== void 0 && (!Number.isSafeInteger(files3[key]) || Number(files3[key]) < 1 || Number(files3[key]) > 1e4)) return
|
|
7002
|
-
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" ?
|
|
7012
|
+
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 invalid18();
|
|
7013
|
+
for (let key of ["savedOmitted", "notAttemptedOmitted"]) if (files3[key] !== void 0 && (!Number.isSafeInteger(files3[key]) || Number(files3[key]) < 1 || Number(files3[key]) > 1e4)) return invalid18();
|
|
7014
|
+
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" ? invalid18() : structuredClone(value);
|
|
7003
7015
|
}
|
|
7004
7016
|
function parseDataOperationDetail(value) {
|
|
7005
7017
|
if (value && typeof value == "object" && !Array.isArray(value) && value.code === "publication_conflict")
|
|
@@ -7135,12 +7147,12 @@ var ConnectionOperationError = class extends Error {
|
|
|
7135
7147
|
|
|
7136
7148
|
var ROUTINE_ERROR_CODE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
7137
7149
|
function parseRoutineErrorDeclaration(value) {
|
|
7138
|
-
let
|
|
7150
|
+
let invalid18 = () => {
|
|
7139
7151
|
throw new TypeError("Invalid RoutineError");
|
|
7140
7152
|
};
|
|
7141
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
7153
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
7142
7154
|
let row = value;
|
|
7143
|
-
return Object.keys(row).some((key) => !["code", "message", "retryable"].includes(key)) || !Object.hasOwn(row, "code") || !Object.hasOwn(row, "message") || typeof row.code != "string" || !ROUTINE_ERROR_CODE_PATTERN.test(row.code) || typeof row.message != "string" || !row.message || row.message.startsWith(" ") || row.message.endsWith(" ") || /[\u0000-\u001f\u007f\u0085\u2028\u2029]/.test(row.message) || /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF])/.test(row.message) || new TextEncoder().encode(row.message).byteLength > 512 || Object.hasOwn(row, "retryable") && typeof row.retryable != "boolean" ?
|
|
7155
|
+
return Object.keys(row).some((key) => !["code", "message", "retryable"].includes(key)) || !Object.hasOwn(row, "code") || !Object.hasOwn(row, "message") || typeof row.code != "string" || !ROUTINE_ERROR_CODE_PATTERN.test(row.code) || typeof row.message != "string" || !row.message || row.message.startsWith(" ") || row.message.endsWith(" ") || /[\u0000-\u001f\u007f\u0085\u2028\u2029]/.test(row.message) || /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF])/.test(row.message) || new TextEncoder().encode(row.message).byteLength > 512 || Object.hasOwn(row, "retryable") && typeof row.retryable != "boolean" ? invalid18() : { code: row.code, message: row.message, retryable: row.retryable === !0 };
|
|
7144
7156
|
}
|
|
7145
7157
|
var RoutineError = class extends Error {
|
|
7146
7158
|
code;
|
|
@@ -7157,17 +7169,17 @@ Anything the routine completed before stopping is safe.`, ROUTINE_RUN_UNCERTAIN_
|
|
|
7157
7169
|
|
|
7158
7170
|
Some work may need review before you try again. Contact support.`;
|
|
7159
7171
|
function parseRoutineAuthoredRunFailure(value) {
|
|
7160
|
-
let
|
|
7172
|
+
let invalid18 = () => {
|
|
7161
7173
|
throw new Error("Invalid authored Run failure");
|
|
7162
7174
|
};
|
|
7163
|
-
if (!value || typeof value != "object" || Array.isArray(value)) return
|
|
7175
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid18();
|
|
7164
7176
|
let row = value;
|
|
7165
|
-
if (Object.keys(row).sort().join(",") !== "code,message,retryable" || typeof row.message != "string" || typeof row.retryable != "boolean") return
|
|
7177
|
+
if (Object.keys(row).sort().join(",") !== "code,message,retryable" || typeof row.message != "string" || typeof row.retryable != "boolean") return invalid18();
|
|
7166
7178
|
let authored = row.message.endsWith(ROUTINE_RUN_UNCERTAIN_SUFFIX) ? row.message.slice(0, -ROUTINE_RUN_UNCERTAIN_SUFFIX.length) : row.message.endsWith(ROUTINE_RUN_COMPLETED_SUFFIX) ? row.message.slice(0, -ROUTINE_RUN_COMPLETED_SUFFIX.length) : row.message;
|
|
7167
7179
|
try {
|
|
7168
7180
|
parseRoutineErrorDeclaration({ code: row.code, message: authored, retryable: row.retryable });
|
|
7169
7181
|
} catch {
|
|
7170
|
-
return
|
|
7182
|
+
return invalid18();
|
|
7171
7183
|
}
|
|
7172
7184
|
return { code: row.code, message: row.message, retryable: row.retryable };
|
|
7173
7185
|
}
|
|
@@ -7289,29 +7301,41 @@ function dataArray(value) {
|
|
|
7289
7301
|
var invalid7 = () => {
|
|
7290
7302
|
throw new DataOperationError("invalid_query");
|
|
7291
7303
|
};
|
|
7304
|
+
function captureRecordsBacklinksInput(ref, value) {
|
|
7305
|
+
if (!validRecordRef(ref)) return invalid7();
|
|
7306
|
+
if (value === void 0) return { ref, options: { limit: 100 } };
|
|
7307
|
+
let descriptors = dataProperties(value);
|
|
7308
|
+
if (Object.keys(descriptors).some((key) => !["limit", "after"].includes(key))) return invalid7();
|
|
7309
|
+
let options = Object.fromEntries(Object.entries(descriptors).map(([key, descriptor]) => [key, descriptor.value])), limit = Object.hasOwn(options, "limit") ? options.limit : 100;
|
|
7310
|
+
return !Number.isSafeInteger(limit) || limit < 1 || limit > 500 || Object.hasOwn(options, "after") && (!dataText(options.after) || !options.after.length || options.after.length > 16384) ? invalid7() : { ref, options: { limit, ...options.after === void 0 ? {} : { after: options.after } } };
|
|
7311
|
+
}
|
|
7312
|
+
|
|
7313
|
+
var invalid8 = () => {
|
|
7314
|
+
throw new DataOperationError("invalid_query");
|
|
7315
|
+
};
|
|
7292
7316
|
function captureRecordsSearchInput(query, options) {
|
|
7293
|
-
if (!dataText(query)) return
|
|
7317
|
+
if (!dataText(query)) return invalid8();
|
|
7294
7318
|
let length = [...query.trim()].length;
|
|
7295
|
-
if (length < 1 || length > 256) return
|
|
7319
|
+
if (length < 1 || length > 256) return invalid8();
|
|
7296
7320
|
if (options === void 0) return { query };
|
|
7297
7321
|
let descriptors = dataProperties(options);
|
|
7298
|
-
if (Object.keys(descriptors).some((key) => !["collections", "limit"].includes(key))) return
|
|
7322
|
+
if (Object.keys(descriptors).some((key) => !["collections", "limit"].includes(key))) return invalid8();
|
|
7299
7323
|
let captured = {};
|
|
7300
7324
|
if (Object.hasOwn(descriptors, "collections")) {
|
|
7301
7325
|
let supplied = descriptors.collections.value;
|
|
7302
|
-
if (!Array.isArray(supplied) || supplied.length < 1 || supplied.length > 16 || Reflect.ownKeys(supplied).length !== supplied.length + 1) return
|
|
7326
|
+
if (!Array.isArray(supplied) || supplied.length < 1 || supplied.length > 16 || Reflect.ownKeys(supplied).length !== supplied.length + 1) return invalid8();
|
|
7303
7327
|
let collections = [];
|
|
7304
7328
|
for (let index = 0; index < supplied.length; index++) {
|
|
7305
7329
|
let descriptor = Object.getOwnPropertyDescriptor(supplied, String(index));
|
|
7306
|
-
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value") || !dataText(descriptor.value)) return
|
|
7330
|
+
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value") || !dataText(descriptor.value)) return invalid8();
|
|
7307
7331
|
collections.push(descriptor.value);
|
|
7308
7332
|
}
|
|
7309
|
-
if (new Set(collections).size !== collections.length) return
|
|
7333
|
+
if (new Set(collections).size !== collections.length) return invalid8();
|
|
7310
7334
|
captured.collections = collections;
|
|
7311
7335
|
}
|
|
7312
7336
|
if (Object.hasOwn(descriptors, "limit")) {
|
|
7313
7337
|
let supplied = descriptors.limit.value;
|
|
7314
|
-
if (!Number.isInteger(supplied) || supplied < 1 || supplied > 100) return
|
|
7338
|
+
if (!Number.isInteger(supplied) || supplied < 1 || supplied > 100) return invalid8();
|
|
7315
7339
|
captured.limit = supplied;
|
|
7316
7340
|
}
|
|
7317
7341
|
return { query, options: captured };
|
|
@@ -7351,21 +7375,21 @@ function captureRecordsQuery(query) {
|
|
|
7351
7375
|
return capture3(query);
|
|
7352
7376
|
}
|
|
7353
7377
|
function captureRecordsAll(query, options) {
|
|
7354
|
-
let
|
|
7378
|
+
let invalid18 = () => {
|
|
7355
7379
|
throw new DataOperationError("invalid_query");
|
|
7356
7380
|
};
|
|
7357
7381
|
try {
|
|
7358
7382
|
let properties = dataProperties(options), maxRecords = properties.maxRecords?.value;
|
|
7359
|
-
if (Object.keys(properties).join(",") !== "maxRecords" || !Number.isSafeInteger(maxRecords) || maxRecords < 1) return
|
|
7383
|
+
if (Object.keys(properties).join(",") !== "maxRecords" || !Number.isSafeInteger(maxRecords) || maxRecords < 1) return invalid18();
|
|
7360
7384
|
let detached = capture3(query), selections = dataProperties(detached);
|
|
7361
|
-
if (Object.keys(selections).length < 1 || Object.keys(selections).length > 16) return
|
|
7385
|
+
if (Object.keys(selections).length < 1 || Object.keys(selections).length > 16) return invalid18();
|
|
7362
7386
|
for (let selection2 of Object.values(selections)) {
|
|
7363
7387
|
let fields4 = dataProperties(selection2.value);
|
|
7364
|
-
if (fields4.$ && Object.hasOwn(dataProperties(fields4.$.value), "after")) return
|
|
7388
|
+
if (fields4.$ && Object.hasOwn(dataProperties(fields4.$.value), "after")) return invalid18();
|
|
7365
7389
|
}
|
|
7366
7390
|
return { query: detached, maxRecords };
|
|
7367
7391
|
} catch {
|
|
7368
|
-
return
|
|
7392
|
+
return invalid18();
|
|
7369
7393
|
}
|
|
7370
7394
|
}
|
|
7371
7395
|
|
|
@@ -7603,10 +7627,10 @@ function parseStoredRecordLink(value) {
|
|
|
7603
7627
|
return typeof value == "string" && value.startsWith("[[") && value.endsWith("]]") ? parseRecordLink(value.slice(2, -2)) : void 0;
|
|
7604
7628
|
}
|
|
7605
7629
|
|
|
7606
|
-
var NAME = /^[a-zA-Z][a-zA-Z0-9_-]*$/,
|
|
7630
|
+
var NAME = /^[a-zA-Z][a-zA-Z0-9_-]*$/, invalid9 = (message2) => {
|
|
7607
7631
|
throw new Error(message2);
|
|
7608
7632
|
};
|
|
7609
|
-
function parseRecordDisplay(value, definitions3, fail9 =
|
|
7633
|
+
function parseRecordDisplay(value, definitions3, fail9 = invalid9) {
|
|
7610
7634
|
if (value === void 0) return;
|
|
7611
7635
|
if (!value || typeof value != "object" || Array.isArray(value)) return fail9("Expected a field mapping");
|
|
7612
7636
|
let row = value;
|
|
@@ -7658,7 +7682,7 @@ function parseInboxRecords(value, maximumRecords = 100) {
|
|
|
7658
7682
|
|
|
7659
7683
|
var InboxOperationError = class extends Error {
|
|
7660
7684
|
constructor(status, reason) {
|
|
7661
|
-
super(reason === "action_processing" ? "The previous answer is still processing. Wait for it to finish." : reason === "action_failed" ? "The previous answer could not be completed. Further answers are on hold." : reason === "handler_unavailable" ? "Deploy the routine that owns this question\u2019s response handler." : reason === "client_update_required" ? "This app must be updated to use Inbox Questions." : reason === "conflict" ? "This question already has an accepted answer" : reason === "unavailable" ? "Inbox request unavailable. Retry the same action." : reason === "invalid_input" ? "Invalid Inbox request" : "Inbox access unavailable");
|
|
7685
|
+
super(reason === "question_unavailable" ? "This Question is missing, changed, answered, or no longer open. Reload before assigning." : reason === "assignment_denied" ? "Only the current assignee can assign this Question." : reason === "assignee_unavailable" ? "The assignee is not a current workspace member." : reason === "action_processing" ? "The previous answer is still processing. Wait for it to finish." : reason === "action_failed" ? "The previous answer could not be completed. Further answers are on hold." : reason === "handler_unavailable" ? "Deploy the routine that owns this question\u2019s response handler." : reason === "client_update_required" ? "This app must be updated to use Inbox Questions." : reason === "conflict" ? "This question already has an accepted answer" : reason === "unavailable" ? "Inbox request unavailable. Retry the same action." : reason === "invalid_input" ? "Invalid Inbox request" : "Inbox access unavailable");
|
|
7662
7686
|
this.status = status;
|
|
7663
7687
|
this.reason = reason;
|
|
7664
7688
|
}
|
|
@@ -7677,6 +7701,11 @@ function questionAvailability(value, available = !1) {
|
|
|
7677
7701
|
function parseInboxUnavailableFailure(value, status) {
|
|
7678
7702
|
try {
|
|
7679
7703
|
let envelope = object5(value);
|
|
7704
|
+
for (let [reason, code] of [["question_unavailable", 409], ["assignment_denied", 403], ["assignee_unavailable", 400]]) {
|
|
7705
|
+
let error = new InboxOperationError(code, reason);
|
|
7706
|
+
if (status === code && envelope.error === error.message)
|
|
7707
|
+
return keys2(envelope, ["error"]), error;
|
|
7708
|
+
}
|
|
7680
7709
|
if (status === 409) {
|
|
7681
7710
|
keys2(envelope, ["error"]);
|
|
7682
7711
|
for (let reason of ["action_processing", "action_failed"]) {
|
|
@@ -7699,6 +7728,9 @@ function parseInboxUnavailableFailure(value, status) {
|
|
|
7699
7728
|
}
|
|
7700
7729
|
}
|
|
7701
7730
|
var INBOX_RESULT_BYTES = 8 * 1024 * 1024, INBOX_INPUT_BYTES = 8192, INBOX_LOCAL_INPUT_BYTES = 256 * 1024, INBOX_QUESTION_CONTRACT = "question-work-v2", 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;
|
|
7731
|
+
function isAssignmentTarget(value) {
|
|
7732
|
+
return typeof value == "string" && value === value.trim() && value.length <= 320 && (INBOX_UUID.test(value) || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value));
|
|
7733
|
+
}
|
|
7702
7734
|
function isAppQuestionOperation(operation2) {
|
|
7703
7735
|
return operation2 === "questions.list" || operation2 === "questions.answer" || operation2 === "questions.listRecordOptions";
|
|
7704
7736
|
}
|
|
@@ -7717,7 +7749,9 @@ var operations = {
|
|
|
7717
7749
|
"items.listRecipientCandidates": ["itemId"],
|
|
7718
7750
|
"items.addRecipient": ["itemId", "personId"],
|
|
7719
7751
|
"questions.answer": ["itemId", "revision", "questionId", "response", "submissionKey"],
|
|
7720
|
-
"questions.listRecordOptions": ["itemId", "revision", "questionId"]
|
|
7752
|
+
"questions.listRecordOptions": ["itemId", "revision", "questionId"],
|
|
7753
|
+
"questions.listAssignmentCandidates": ["itemId", "revision", "questionId"],
|
|
7754
|
+
"questions.assign": ["itemId", "revision", "questionId", "assignee"]
|
|
7721
7755
|
};
|
|
7722
7756
|
function assert(value) {
|
|
7723
7757
|
if (!value) throw new Error("Invalid Inbox result");
|
|
@@ -7796,6 +7830,9 @@ function responseDefinition(value) {
|
|
|
7796
7830
|
[]
|
|
7797
7831
|
), option.type === "choice" ? choiceValue(option.value) : recordReference(option.value), choiceDetails(option);
|
|
7798
7832
|
break;
|
|
7833
|
+
case "assign":
|
|
7834
|
+
keys2(option, ["id", "type", "label", "assignee"], []), "assignee" in option && assert(id4(option.assignee));
|
|
7835
|
+
break;
|
|
7799
7836
|
case "record-picker": {
|
|
7800
7837
|
keys2(option, ["id", "type", "label", "source"]);
|
|
7801
7838
|
let source3 = object5(option.source);
|
|
@@ -7844,7 +7881,7 @@ function response(value, definition, numbered = !1) {
|
|
|
7844
7881
|
if (typeof selected == "string" ? choiceValue(selected) : recordReference(selected), options || numbered) {
|
|
7845
7882
|
if (keys2(answer, ["option", "value", "note"], []), assert(integer(answer.option) && answer.option <= (options?.length ?? 9)), options) {
|
|
7846
7883
|
let option = object5(options[answer.option - 1]);
|
|
7847
|
-
assert(option.type === "choice" == (typeof selected == "string")), assert("note" in answer == (option.type === "choice" && "note" in option));
|
|
7884
|
+
assert(option.type !== "assign"), assert(option.type === "choice" == (typeof selected == "string")), assert("note" in answer == (option.type === "choice" && "note" in option));
|
|
7848
7885
|
}
|
|
7849
7886
|
} else assert(Object.keys(answer).every((key) => ["selection", "note"].includes(key)));
|
|
7850
7887
|
return Object.hasOwn(answer, "note") && assert(text2(answer.note)), answer;
|
|
@@ -7860,7 +7897,7 @@ function parseInboxRequest(value) {
|
|
|
7860
7897
|
let input = { ...object5(envelope.input) }, required = operations[operation2];
|
|
7861
7898
|
assert(required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || operation2 === "questions.answer" && key === "label" || operation2 === "questions.listRecordOptions" && envelope.contract === INBOX_QUESTION_CONTRACT && key === "option" || (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)));
|
|
7862
7899
|
for (let key of ["itemId", "personId", "fileId"]) key in input && assert(id4(input[key]));
|
|
7863
|
-
if ("revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text2(input.questionId) && input.questionId === input.questionId.trim()), "submissionKey" in input && assert(text2(input.submissionKey) && input.submissionKey.length <= 128 && input.submissionKey === input.submissionKey.trim()), "title" in input && assert(text2(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "records" in input && (input.records = parseInboxRecordRefs(input.records)), "option" in input && assert(integer(input.option) && input.option <= 9), "response" in input && response(input.response, void 0, envelope.contract === INBOX_QUESTION_CONTRACT && "option" in object5(input.response)), "label" in input) {
|
|
7900
|
+
if ("revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text2(input.questionId) && input.questionId === input.questionId.trim()), "assignee" in input && assert(isAssignmentTarget(input.assignee)), "submissionKey" in input && assert(text2(input.submissionKey) && input.submissionKey.length <= 128 && input.submissionKey === input.submissionKey.trim()), "title" in input && assert(text2(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "records" in input && (input.records = parseInboxRecordRefs(input.records)), "option" in input && assert(integer(input.option) && input.option <= 9), "response" in input && response(input.response, void 0, envelope.contract === INBOX_QUESTION_CONTRACT && "option" in object5(input.response)), "label" in input) {
|
|
7864
7901
|
let answer = object5(input.response);
|
|
7865
7902
|
assert(text2(input.label) && typeof ("option" in answer ? answer.value : answer.selection) == "object");
|
|
7866
7903
|
}
|
|
@@ -7918,7 +7955,7 @@ function parseInboxItem(value) {
|
|
|
7918
7955
|
let event = object5(value2);
|
|
7919
7956
|
assert(integer(event.id) && text2(event.type) && (event.actorId === null || id4(event.actorId)) && (event.questionId === null || text2(event.questionId)) && integer(event.revision) && date3(event.createdAt));
|
|
7920
7957
|
let data3 = object5(event.data);
|
|
7921
|
-
event.type === "recipient-added" && (keys2(data3, ["personId"]), assert(id4(event.actorId) && id4(data3.personId)));
|
|
7958
|
+
event.type === "question-assigned" && (keys2(data3, ["previousAssigneeId", "assigneeId", "addedRecipient"]), assert(id4(event.actorId) && text2(event.questionId) && id4(data3.previousAssigneeId) && id4(data3.assigneeId) && typeof data3.addedRecipient == "boolean")), event.type === "recipient-added" && (keys2(data3, ["personId"]), assert(id4(event.actorId) && id4(data3.personId)));
|
|
7922
7959
|
}), array2(item.work).forEach((value2) => {
|
|
7923
7960
|
let work = object5(value2);
|
|
7924
7961
|
assert(id4(work.id) && text2(work.questionId) && text2(work.reason) && optionalDate(work.settledAt));
|
|
@@ -7994,13 +8031,21 @@ function parseInboxResult(operation2, value, contract = INBOX_QUESTION_CONTRACT)
|
|
|
7994
8031
|
let update = object5(value), item = parseInboxItem(update.item);
|
|
7995
8032
|
return assert((update.activityId === null || integer(update.activityId)) && optionalDate(update.changedAt)), { ...update, item };
|
|
7996
8033
|
}
|
|
7997
|
-
if (operation2 === "items.listRecipientCandidates") {
|
|
8034
|
+
if (operation2 === "items.listRecipientCandidates" || operation2 === "questions.listAssignmentCandidates") {
|
|
7998
8035
|
let candidates = array2(value);
|
|
7999
8036
|
return candidates.forEach((value2) => {
|
|
8000
8037
|
let person = object5(value2);
|
|
8001
|
-
assert(id4(person.id) && text2(person.name) && text2(person.email));
|
|
8038
|
+
operation2 === "questions.listAssignmentCandidates" && keys2(person, ["id", "name", "email"]), assert(id4(person.id) && text2(person.name) && text2(person.email));
|
|
8002
8039
|
}), assert(new Set(candidates.map((value2) => object5(value2).id)).size === candidates.length), candidates;
|
|
8003
8040
|
}
|
|
8041
|
+
if (operation2 === "questions.assign") {
|
|
8042
|
+
let result2 = object5(value);
|
|
8043
|
+
keys2(result2, ["item", "questionId", "previousAssigneeId", "assigneeId", "activityId", "assignedAt"]);
|
|
8044
|
+
let item = parseInboxItem(result2.item);
|
|
8045
|
+
assert(item.kind === "ask" && text2(result2.questionId) && id4(result2.previousAssigneeId) && id4(result2.assigneeId));
|
|
8046
|
+
let question2 = item.questions.find((question3) => question3.id === result2.questionId);
|
|
8047
|
+
return assert(question2 && question2.to === result2.assigneeId && question2.acceptedResponse === null && question2.execution === null && question2.allowedResponders.includes(result2.previousAssigneeId) && question2.allowedResponders.includes(result2.assigneeId) && item.people.some((person) => person.id === result2.assigneeId) && item.people.some((person) => person.id === result2.previousAssigneeId)), result2.previousAssigneeId === result2.assigneeId ? assert(result2.activityId === null && result2.assignedAt === null) : (assert(integer(result2.activityId) && date3(result2.assignedAt)), assert(item.activity.some((event) => event.id === result2.activityId && event.type === "question-assigned" && event.questionId === result2.questionId && event.revision === item.revision && event.createdAt === result2.assignedAt && event.actorId === result2.previousAssigneeId && event.data.previousAssigneeId === result2.previousAssigneeId && event.data.assigneeId === result2.assigneeId))), { ...result2, item };
|
|
8048
|
+
}
|
|
8004
8049
|
if (operation2 === "items.addRecipient") {
|
|
8005
8050
|
let addition = object5(value), item = parseInboxItem(addition.item);
|
|
8006
8051
|
return assert(id4(addition.addedPersonId) && item.people.some((person) => person.id === addition.addedPersonId)), { ...addition, item };
|
|
@@ -8021,6 +8066,15 @@ function parseInboxResult(operation2, value, contract = INBOX_QUESTION_CONTRACT)
|
|
|
8021
8066
|
}
|
|
8022
8067
|
throw new Error("File content is not a JSON result");
|
|
8023
8068
|
}
|
|
8069
|
+
function assertInboxAssignmentMatches(result2, input) {
|
|
8070
|
+
assert(result2.item.id === input.itemId && result2.item.revision === input.revision && result2.questionId === input.questionId && result2.assigneeId.toLowerCase() === input.assignee.toLowerCase());
|
|
8071
|
+
}
|
|
8072
|
+
function assignmentTargetId(assignee, candidates) {
|
|
8073
|
+
if (INBOX_UUID.test(assignee)) return assignee.toLowerCase();
|
|
8074
|
+
let matches2 = candidates.filter((person) => person.email.toLowerCase() === assignee.toLowerCase());
|
|
8075
|
+
if (matches2.length !== 1) throw new InboxOperationError(400, "assignee_unavailable");
|
|
8076
|
+
return matches2[0].id;
|
|
8077
|
+
}
|
|
8024
8078
|
function parseInboxBootstrap(value) {
|
|
8025
8079
|
let snapshot = object5(value);
|
|
8026
8080
|
keys2(snapshot, ["current", "items", "hydrations"]);
|
|
@@ -8745,16 +8799,16 @@ function inspectRoutineQueueReference(queue) {
|
|
|
8745
8799
|
return id5;
|
|
8746
8800
|
}
|
|
8747
8801
|
|
|
8748
|
-
var definitions2 = /* @__PURE__ */ new WeakMap(),
|
|
8802
|
+
var definitions2 = /* @__PURE__ */ new WeakMap(), invalid10 = () => {
|
|
8749
8803
|
throw new AppRoutineContractError("invalid_contract");
|
|
8750
8804
|
}, defineQuery = (definition) => {
|
|
8751
|
-
if (assertRoutineFields(definition, ["id", "queue", "triggers", "access", "run"]), !isAppRoutineName(definition.id) || typeof definition.run != "function") return
|
|
8805
|
+
if (assertRoutineFields(definition, ["id", "queue", "triggers", "access", "run"]), !isAppRoutineName(definition.id) || typeof definition.run != "function") return invalid10();
|
|
8752
8806
|
let routineId = inspectRoutineQueueReference(definition.queue), triggers;
|
|
8753
8807
|
try {
|
|
8754
|
-
if (assertRoutineJson(definition.triggers), !Array.isArray(definition.triggers)) return
|
|
8808
|
+
if (assertRoutineJson(definition.triggers), !Array.isArray(definition.triggers)) return invalid10();
|
|
8755
8809
|
triggers = definition.triggers.map((trigger) => (assertRoutineFields(trigger, ["schedule"]), { schedule: parseRoutineSchedule(trigger.schedule) }));
|
|
8756
8810
|
} catch {
|
|
8757
|
-
return
|
|
8811
|
+
return invalid10();
|
|
8758
8812
|
}
|
|
8759
8813
|
let access = parseRoutineAccess(definition.access), contract = freezeRoutineMetadata({ id: definition.id, routineId, access, triggers }), captured = Object.freeze({ ...definition, access, triggers: contract.triggers });
|
|
8760
8814
|
return definitions2.set(captured, contract), captured;
|
|
@@ -8863,14 +8917,14 @@ function checked(workspace, endpoint, headers) {
|
|
|
8863
8917
|
return { url: `${origin.origin}/api/data`, headers: { ...headers, "x-os-workspace": workspace } };
|
|
8864
8918
|
}
|
|
8865
8919
|
|
|
8866
|
-
var
|
|
8920
|
+
var invalid11 = () => {
|
|
8867
8921
|
throw new DataOperationError("invalid_query");
|
|
8868
8922
|
}, unavailable = () => {
|
|
8869
8923
|
throw new DataOperationError("unavailable");
|
|
8870
8924
|
}, text3 = (value) => typeof value == "string" && value.length > 0;
|
|
8871
8925
|
function capture4(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
8872
8926
|
if (value === null || typeof value == "string" || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value)) return value;
|
|
8873
|
-
if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) return
|
|
8927
|
+
if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) return invalid11();
|
|
8874
8928
|
ancestors.add(value);
|
|
8875
8929
|
try {
|
|
8876
8930
|
return Array.isArray(value) ? dataArray(value).map((item) => capture4(item, ancestors, depth + 1)) : Object.fromEntries(Object.entries(dataProperties(value)).map(([key, descriptor]) => [key, capture4(descriptor.value, ancestors, depth + 1)]));
|
|
@@ -8885,7 +8939,7 @@ function recordPagination(queryRecords) {
|
|
|
8885
8939
|
let selection2 = dataProperties(captured[name4]);
|
|
8886
8940
|
if (Object.hasOwn(selection2, "$")) {
|
|
8887
8941
|
let options = dataProperties(selection2.$.value);
|
|
8888
|
-
if (Object.hasOwn(options, "after")) return
|
|
8942
|
+
if (Object.hasOwn(options, "after")) return invalid11();
|
|
8889
8943
|
}
|
|
8890
8944
|
}
|
|
8891
8945
|
return iterate();
|
|
@@ -9171,6 +9225,60 @@ function scalarField(name4, schema2) {
|
|
|
9171
9225
|
let field = schema2.fields.find((field2) => field2.name === name4);
|
|
9172
9226
|
return !field || field.many || field.kind === "object" || field.kind === "map" ? fail5(`ineligible scalar field: ${name4}`) : field;
|
|
9173
9227
|
}
|
|
9228
|
+
function linkPath(name4) {
|
|
9229
|
+
if (name4 === "$ref") return;
|
|
9230
|
+
let segments = [], segment = "";
|
|
9231
|
+
for (let index = 0; index < name4.length; index++) {
|
|
9232
|
+
let character = name4[index];
|
|
9233
|
+
if (character === "\\") {
|
|
9234
|
+
let escaped = name4[++index];
|
|
9235
|
+
if (escaped !== "." && escaped !== "\\") return fail5(`invalid link path: ${name4}`);
|
|
9236
|
+
segment += escaped;
|
|
9237
|
+
} else if (character === ".") {
|
|
9238
|
+
if (!segment) return fail5(`invalid link path: ${name4}`);
|
|
9239
|
+
segments.push(segment), segment = "";
|
|
9240
|
+
} else segment += character;
|
|
9241
|
+
}
|
|
9242
|
+
if (!segment) return fail5(`invalid link path: ${name4}`);
|
|
9243
|
+
if (segments.push(segment), segments.length === 1) return;
|
|
9244
|
+
if (segments.at(-1) !== "$ref" || segments.length < 2) return fail5(`invalid link path: ${name4}`);
|
|
9245
|
+
let path = segments.slice(0, -1);
|
|
9246
|
+
return path.length > 4 ? fail5("too many link levels") : path;
|
|
9247
|
+
}
|
|
9248
|
+
function linkCondition(name4, condition, path, schemas2, collections, collectionsByType, allowUnknownTerminalRefs) {
|
|
9249
|
+
let current2 = [...schemas2];
|
|
9250
|
+
for (let [index, part] of path.entries()) {
|
|
9251
|
+
let links = current2.map((schema2) => schema2.fields.find((field) => field.name === part)).filter((field) => !!field);
|
|
9252
|
+
if (links.length !== current2.length || links.some((field) => field.kind !== "link"))
|
|
9253
|
+
return fail5(`ineligible link path: ${name4}`);
|
|
9254
|
+
if (index < path.length - 1) {
|
|
9255
|
+
let targets2 = /* @__PURE__ */ new Map();
|
|
9256
|
+
for (let field of links) for (let type of field.kind === "link" ? field.to : []) {
|
|
9257
|
+
let candidates = collectionsByType.get(type) ?? fail5(`unknown link target type: ${type}`);
|
|
9258
|
+
for (let candidate of candidates) targets2.set(candidate.name, candidate.schema);
|
|
9259
|
+
}
|
|
9260
|
+
current2 = [...targets2.values()];
|
|
9261
|
+
} else {
|
|
9262
|
+
let values = [condition];
|
|
9263
|
+
if (condition !== null && typeof condition == "object") {
|
|
9264
|
+
let expression = mapping3(condition);
|
|
9265
|
+
if (Object.keys(expression).length !== 1 || !Object.hasOwn(expression, "$in") || !Array.isArray(expression.$in) || expression.$in.length < 1 || expression.$in.length > 100)
|
|
9266
|
+
return fail5("invalid link $in");
|
|
9267
|
+
values = expression.$in;
|
|
9268
|
+
}
|
|
9269
|
+
if (values.some((value) => !validRecordRef(value))) return fail5(`invalid reference: ${name4}`);
|
|
9270
|
+
let refs = values;
|
|
9271
|
+
if (new Set(refs).size !== refs.length) return fail5("duplicate $in value");
|
|
9272
|
+
for (let ref of refs) {
|
|
9273
|
+
let target = collections.filter((collection) => ref.startsWith(`${collection.name}/`)).sort((a, b) => b.name.length - a.name.length)[0];
|
|
9274
|
+
if (!target && !allowUnknownTerminalRefs || target && links.some((field) => field.kind !== "link" || !field.to.includes(target.schema.type)))
|
|
9275
|
+
return fail5(`incompatible reference: ${name4}`);
|
|
9276
|
+
}
|
|
9277
|
+
return { path, refs: [...refs] };
|
|
9278
|
+
}
|
|
9279
|
+
}
|
|
9280
|
+
return fail5(`invalid link path: ${name4}`);
|
|
9281
|
+
}
|
|
9174
9282
|
function conditionValue(value, field) {
|
|
9175
9283
|
return (field.kind === "link" || field.name === "$ref") && value !== null && !(field.kind === "link" ? parseRecordLink(value) : validRecordRef(value)) ? fail5(`invalid reference: ${field.name}`) : (validateRecordFields(
|
|
9176
9284
|
{ [field.name]: field.kind === "link" && typeof value == "string" ? `[[${value}]]` : value },
|
|
@@ -9194,13 +9302,13 @@ function preflightSelections(entries) {
|
|
|
9194
9302
|
};
|
|
9195
9303
|
for (let [, value] of entries) visit(value, 0);
|
|
9196
9304
|
}
|
|
9197
|
-
function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1) {
|
|
9305
|
+
function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1, allowUnknownTerminalRefs = !1) {
|
|
9198
9306
|
let selection2 = mapping3(value), options = Object.hasOwn(selection2, "$") ? mapping3(selection2.$) : {}, allowed = depth === 0 ? ["where", "fields", "order", "limit", "count", "after"] : many ? ["where", "fields", "order", "limit"] : ["where", "fields"];
|
|
9199
9307
|
if (allowed.push("timeline"), Object.keys(options).some((key) => !allowed.includes(key)))
|
|
9200
9308
|
return fail5("unsupported option");
|
|
9201
9309
|
let fields4 = Object.hasOwn(options, "fields") ? options.fields : schema2.fields.map((field) => field.name);
|
|
9202
9310
|
if (!Array.isArray(fields4) || fields4.some((name4) => typeof name4 != "string" || !["$ref", "$version"].includes(name4) && !schema2.fields.some((field) => field.name === name4)) || new Set(fields4).size !== fields4.length) return fail5("invalid projection");
|
|
9203
|
-
let conditions = [], signalConditions = [];
|
|
9311
|
+
let conditions = [], linkConditions = [], signalConditions = [];
|
|
9204
9312
|
if (Object.hasOwn(options, "timeline") && options.timeline !== !0) return fail5("invalid timeline option");
|
|
9205
9313
|
if (Object.hasOwn(options, "where")) for (let [name4, condition] of Object.entries(mapping3(options.where))) {
|
|
9206
9314
|
if (name4 === "$signals") {
|
|
@@ -9220,6 +9328,19 @@ function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1)
|
|
|
9220
9328
|
}
|
|
9221
9329
|
continue;
|
|
9222
9330
|
}
|
|
9331
|
+
let path = linkPath(name4);
|
|
9332
|
+
if (path) {
|
|
9333
|
+
linkConditions.push(linkCondition(
|
|
9334
|
+
name4,
|
|
9335
|
+
condition,
|
|
9336
|
+
path,
|
|
9337
|
+
[schema2],
|
|
9338
|
+
[...collectionsByType.values()].flat(),
|
|
9339
|
+
collectionsByType,
|
|
9340
|
+
allowUnknownTerminalRefs
|
|
9341
|
+
));
|
|
9342
|
+
continue;
|
|
9343
|
+
}
|
|
9223
9344
|
let field = scalarField(name4, schema2), values = [condition];
|
|
9224
9345
|
if (condition !== null && typeof condition == "object") {
|
|
9225
9346
|
let expression = mapping3(condition);
|
|
@@ -9263,15 +9384,16 @@ function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1)
|
|
|
9263
9384
|
let field = schema2.fields.find((field2) => field2.name === name4);
|
|
9264
9385
|
if (!field || field.kind !== "link") return fail5(`ineligible link field: ${name4}`);
|
|
9265
9386
|
if (depth >= 4) return fail5("too many link levels");
|
|
9266
|
-
let
|
|
9387
|
+
let targets2 = new Map(field.to.flatMap((type) => (collectionsByType.get(type) ?? fail5(`unknown link target type: ${type}`)).map((target) => [
|
|
9267
9388
|
target.name,
|
|
9268
|
-
selectionTree(nested, target.schema, collectionsByType, depth + 1, field.many)
|
|
9389
|
+
selectionTree(nested, target.schema, collectionsByType, depth + 1, field.many, allowUnknownTerminalRefs)
|
|
9269
9390
|
])));
|
|
9270
|
-
links.push({ name: name4, many: field.many, targets });
|
|
9391
|
+
links.push({ name: name4, many: field.many, targets: targets2 });
|
|
9271
9392
|
}
|
|
9272
9393
|
return {
|
|
9273
9394
|
fields: fields4,
|
|
9274
9395
|
conditions,
|
|
9396
|
+
linkConditions,
|
|
9275
9397
|
...signalConditions.length ? { signalConditions } : {},
|
|
9276
9398
|
...options.timeline === !0 ? { timeline: !0 } : {},
|
|
9277
9399
|
order,
|
|
@@ -9287,6 +9409,7 @@ function selectionBinding(selection2, top = !0, many = !1) {
|
|
|
9287
9409
|
return {
|
|
9288
9410
|
fields: selection2.fields,
|
|
9289
9411
|
conditions: [...selection2.conditions].sort(([a], [b]) => compare(a, b)),
|
|
9412
|
+
linkConditions: [...selection2.linkConditions].sort((a, b) => compare(a.path.join("\0"), b.path.join("\0"))),
|
|
9290
9413
|
...selection2.signalConditions ? { signalConditions: [...selection2.signalConditions].sort(([a], [b]) => compare(a, b)) } : {},
|
|
9291
9414
|
...selection2.timeline ? { timeline: !0 } : {},
|
|
9292
9415
|
order: top || many && selection2.explicitOrder ? selection2.order : null,
|
|
@@ -9299,15 +9422,15 @@ function selectionBinding(selection2, top = !0, many = !1) {
|
|
|
9299
9422
|
}))
|
|
9300
9423
|
};
|
|
9301
9424
|
}
|
|
9302
|
-
function planIndexQuery(query, catalogue) {
|
|
9425
|
+
function planIndexQuery(query, catalogue, options = {}) {
|
|
9303
9426
|
let entries = queryEntries(query), collections = new Map(catalogue.map((collection) => [collection.name, collection])), byType = /* @__PURE__ */ new Map();
|
|
9304
9427
|
for (let collection of catalogue) {
|
|
9305
|
-
let
|
|
9306
|
-
|
|
9428
|
+
let targets2 = byType.get(collection.schema.type) ?? [];
|
|
9429
|
+
targets2.push(collection), byType.set(collection.schema.type, targets2);
|
|
9307
9430
|
}
|
|
9308
9431
|
return entries.map(([name4, value]) => {
|
|
9309
9432
|
let target = collections.get(name4) ?? fail5(`unknown collection: ${name4}`);
|
|
9310
|
-
return { name: name4, selection: selectionTree(value, target.schema, byType) };
|
|
9433
|
+
return { name: name4, selection: selectionTree(value, target.schema, byType, 0, !1, options.allowUnknownTerminalRefs === !0) };
|
|
9311
9434
|
});
|
|
9312
9435
|
}
|
|
9313
9436
|
function indexSelectionBinding(context, collection, selection2) {
|
|
@@ -9324,9 +9447,9 @@ function cursorPosition(value, binding, limit) {
|
|
|
9324
9447
|
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) ? fail5("incompatible cursor") : { position, ref };
|
|
9325
9448
|
}
|
|
9326
9449
|
|
|
9327
|
-
var
|
|
9450
|
+
var invalid12 = () => {
|
|
9328
9451
|
throw new DataOperationError("unavailable", !0);
|
|
9329
|
-
}, object7 = (value) => !value || typeof value != "object" || Array.isArray(value) ?
|
|
9452
|
+
}, object7 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid12() : value, keys4 = (value, expected) => Object.keys(value).sort().join(",") === expected, hash = (value) => typeof value == "string" && /^[0-9a-f]{40}$/.test(value), time2 = (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);
|
|
9330
9453
|
function json3(value) {
|
|
9331
9454
|
if (!(value === null || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value) || dataText(value))) {
|
|
9332
9455
|
if (Array.isArray(value)) {
|
|
@@ -9334,7 +9457,7 @@ function json3(value) {
|
|
|
9334
9457
|
return;
|
|
9335
9458
|
}
|
|
9336
9459
|
for (let [key, item] of Object.entries(object7(value))) {
|
|
9337
|
-
if (!dataText(key)) return
|
|
9460
|
+
if (!dataText(key)) return invalid12();
|
|
9338
9461
|
json3(item);
|
|
9339
9462
|
}
|
|
9340
9463
|
}
|
|
@@ -9346,66 +9469,66 @@ var slot = (values, field) => Object.hasOwn(values, field) ? { present: !0, valu
|
|
|
9346
9469
|
function apply(book, event) {
|
|
9347
9470
|
let records = book.get(event.collection), prior = records.get(event.ref);
|
|
9348
9471
|
if (event.kind === "create") {
|
|
9349
|
-
if (prior) return
|
|
9472
|
+
if (prior) return invalid12();
|
|
9350
9473
|
records.set(event.ref, structuredClone(event.values));
|
|
9351
9474
|
} else if (event.kind === "delete") {
|
|
9352
|
-
if (!prior || stable(prior) !== stable(event.values)) return
|
|
9475
|
+
if (!prior || stable(prior) !== stable(event.values)) return invalid12();
|
|
9353
9476
|
records.delete(event.ref);
|
|
9354
9477
|
} else if (event.kind === "rename") {
|
|
9355
9478
|
let before = records.get(event.previousRef);
|
|
9356
|
-
if (!before || prior) return
|
|
9479
|
+
if (!before || prior) return invalid12();
|
|
9357
9480
|
records.delete(event.previousRef), records.set(event.ref, before);
|
|
9358
9481
|
} else if (event.kind === "update") {
|
|
9359
|
-
if (!prior || stable(slot(prior, event.field)) !== stable(event.before) || stable(event.before) === stable(event.after)) return
|
|
9482
|
+
if (!prior || stable(slot(prior, event.field)) !== stable(event.before) || stable(event.before) === stable(event.after)) return invalid12();
|
|
9360
9483
|
event.after.present ? Object.defineProperty(prior, event.field, { value: structuredClone(event.after.value), enumerable: !0, configurable: !0, writable: !0 }) : delete prior[event.field];
|
|
9361
9484
|
}
|
|
9362
9485
|
}
|
|
9363
9486
|
function validateSnapshotHistory(input, collections, version) {
|
|
9364
9487
|
let row = object7(input), selections = object7(row.fields);
|
|
9365
|
-
if (!keys4(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
|
|
9488
|
+
if (!keys4(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 invalid12();
|
|
9366
9489
|
let book = /* @__PURE__ */ new Map();
|
|
9367
9490
|
for (let [collection, selection2] of Object.entries(selections)) {
|
|
9368
9491
|
let selected = object7(selection2), fields4 = selected.fields;
|
|
9369
|
-
if (!Object.hasOwn(collections, collection) || !keys4(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
|
|
9492
|
+
if (!Object.hasOwn(collections, collection) || !keys4(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 invalid12();
|
|
9370
9493
|
book.set(collection, /* @__PURE__ */ new Map());
|
|
9371
9494
|
}
|
|
9372
9495
|
let history = row, seen = /* @__PURE__ */ new Set(), parent = null;
|
|
9373
9496
|
for (let group of history.commits) {
|
|
9374
|
-
if (!keys4(object7(group), "authoredAt,commit,committedAt,events,firstParent") || !hash(group.commit) || seen.has(group.commit) || group.firstParent !== parent || !time2(group.authoredAt) || !time2(group.committedAt) || !Array.isArray(group.events)) return
|
|
9497
|
+
if (!keys4(object7(group), "authoredAt,commit,committedAt,events,firstParent") || !hash(group.commit) || seen.has(group.commit) || group.firstParent !== parent || !time2(group.authoredAt) || !time2(group.committedAt) || !Array.isArray(group.events)) return invalid12();
|
|
9375
9498
|
seen.add(group.commit), parent = group.commit;
|
|
9376
9499
|
let previous, created = /* @__PURE__ */ new Set();
|
|
9377
9500
|
for (let event of group.events) {
|
|
9378
|
-
if (object7(event), !book.has(event.collection) || !validRecordRef(event.ref) || !event.ref.startsWith(`${event.collection}/`)) return
|
|
9501
|
+
if (object7(event), !book.has(event.collection) || !validRecordRef(event.ref) || !event.ref.startsWith(`${event.collection}/`)) return invalid12();
|
|
9379
9502
|
let fields4 = history.fields[event.collection].fields;
|
|
9380
9503
|
if (event.kind === "create" || event.kind === "delete") {
|
|
9381
|
-
if (!keys4(event, "collection,kind,ref,values") || Object.keys(object7(event.values)).some((field) => !fields4.includes(field))) return
|
|
9504
|
+
if (!keys4(event, "collection,kind,ref,values") || Object.keys(object7(event.values)).some((field) => !fields4.includes(field))) return invalid12();
|
|
9382
9505
|
json3(event.values), event.kind === "create" && created.add(event.ref);
|
|
9383
9506
|
} else if (event.kind === "rename") {
|
|
9384
|
-
if (!keys4(event, "collection,kind,previousRef,ref") || !validRecordRef(event.previousRef) || !event.previousRef.startsWith(`${event.collection}/`) || event.previousRef === event.ref) return
|
|
9507
|
+
if (!keys4(event, "collection,kind,previousRef,ref") || !validRecordRef(event.previousRef) || !event.previousRef.startsWith(`${event.collection}/`) || event.previousRef === event.ref) return invalid12();
|
|
9385
9508
|
} else if (event.kind === "update") {
|
|
9386
|
-
if (!keys4(event, "after,before,collection,field,kind,ref") || !fields4.includes(event.field) || created.has(event.ref)) return
|
|
9509
|
+
if (!keys4(event, "after,before,collection,field,kind,ref") || !fields4.includes(event.field) || created.has(event.ref)) return invalid12();
|
|
9387
9510
|
for (let value of [event.before, event.after]) {
|
|
9388
|
-
if (object7(value), value.present === !1 ? !keys4(value, "present") : value.present !== !0 || !keys4(value, "present,value")) return
|
|
9511
|
+
if (object7(value), value.present === !1 ? !keys4(value, "present") : value.present !== !0 || !keys4(value, "present,value")) return invalid12();
|
|
9389
9512
|
value.present && json3(value.value);
|
|
9390
9513
|
}
|
|
9391
|
-
} else return
|
|
9514
|
+
} else return invalid12();
|
|
9392
9515
|
let order = [event.kind === "delete" ? 0 : 1, event.ref, event.kind === "update" ? 1 : 0, event.kind === "update" ? event.field : ""];
|
|
9393
9516
|
if (previous) {
|
|
9394
9517
|
let index = order.findIndex((value, i) => value !== previous[i]);
|
|
9395
|
-
if (index === -1 || order[index] < previous[index]) return
|
|
9518
|
+
if (index === -1 || order[index] < previous[index]) return invalid12();
|
|
9396
9519
|
}
|
|
9397
9520
|
previous = order, apply(book, event);
|
|
9398
9521
|
}
|
|
9399
9522
|
let refs = /* @__PURE__ */ new Set();
|
|
9400
9523
|
for (let records of book.values()) for (let ref of records.keys()) {
|
|
9401
|
-
if (refs.has(ref)) return
|
|
9524
|
+
if (refs.has(ref)) return invalid12();
|
|
9402
9525
|
refs.add(ref);
|
|
9403
9526
|
}
|
|
9404
9527
|
}
|
|
9405
|
-
if (parent !== history.through) return
|
|
9528
|
+
if (parent !== history.through) return invalid12();
|
|
9406
9529
|
for (let [collection, records] of book) {
|
|
9407
9530
|
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]]))]);
|
|
9408
|
-
if (stable([...records].sort(([a], [b]) => a < b ? -1 : 1)) !== stable(expected)) return
|
|
9531
|
+
if (stable([...records].sort(([a], [b]) => a < b ? -1 : 1)) !== stable(expected)) return invalid12();
|
|
9409
9532
|
}
|
|
9410
9533
|
return history;
|
|
9411
9534
|
}
|
|
@@ -9432,33 +9555,33 @@ function readSnapshotHistory(history, input, operation2) {
|
|
|
9432
9555
|
};
|
|
9433
9556
|
}
|
|
9434
9557
|
|
|
9435
|
-
var snapshotCollection = (catalogue, ref) => catalogue.filter((c) => ref.startsWith(`${c.name}/`)).sort((a, b) => b.name.length - a.name.length)[0],
|
|
9558
|
+
var snapshotCollection = (catalogue, ref) => catalogue.filter((c) => ref.startsWith(`${c.name}/`)).sort((a, b) => b.name.length - a.name.length)[0], invalid13 = () => {
|
|
9436
9559
|
throw new DataOperationError("unavailable", !0);
|
|
9437
|
-
}, object8 = (value) => !value || typeof value != "object" || Array.isArray(value) ?
|
|
9560
|
+
}, object8 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid13() : value;
|
|
9438
9561
|
function stable2(value) {
|
|
9439
9562
|
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);
|
|
9440
9563
|
}
|
|
9441
9564
|
function schemaText(value) {
|
|
9442
|
-
if (typeof value == "string" && !dataText(value)) return
|
|
9565
|
+
if (typeof value == "string" && !dataText(value)) return invalid13();
|
|
9443
9566
|
if (value && typeof value == "object") for (let [key, entry] of Object.entries(value)) {
|
|
9444
|
-
if (!dataText(key)) return
|
|
9567
|
+
if (!dataText(key)) return invalid13();
|
|
9445
9568
|
schemaText(entry);
|
|
9446
9569
|
}
|
|
9447
9570
|
}
|
|
9448
9571
|
function validateSnapshotEnvelope(input, repository, name4, bodies = [], timelines = []) {
|
|
9449
9572
|
try {
|
|
9450
9573
|
let row = object8(input), legacy = row.format === "data-snapshot.v1";
|
|
9451
|
-
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 !== name4 || !dataVersion(row.version)) return
|
|
9574
|
+
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 !== name4 || !dataVersion(row.version)) return invalid13();
|
|
9452
9575
|
let schemas2 = object8(row.schemas), collections = object8(row.collections);
|
|
9453
9576
|
schemaText(schemas2);
|
|
9454
9577
|
let names = Object.keys(collections);
|
|
9455
|
-
for (let subset of [bodies, timelines]) if (new Set(subset).size !== subset.length || subset.some((name5) => !names.includes(name5))) return
|
|
9456
|
-
if (!names.length || names.join("\0") !== [...names].sort().join("\0") || Object.keys(schemas2).join("\0") !== names.join("\0")) return
|
|
9578
|
+
for (let subset of [bodies, timelines]) if (new Set(subset).size !== subset.length || subset.some((name5) => !names.includes(name5))) return invalid13();
|
|
9579
|
+
if (!names.length || names.join("\0") !== [...names].sort().join("\0") || Object.keys(schemas2).join("\0") !== names.join("\0")) return invalid13();
|
|
9457
9580
|
let catalogue = names.map((name5) => {
|
|
9458
9581
|
let schema2 = object8(schemas2[name5]);
|
|
9459
|
-
if (!validRecordRef(`${name5}/example`) || schema2.name !== name5 || 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
|
|
9582
|
+
if (!validRecordRef(`${name5}/example`) || schema2.name !== name5 || 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 invalid13();
|
|
9460
9583
|
let definitions3 = fields2(schema2.fields, 0, !0);
|
|
9461
|
-
if (stable2(definitions3.map(publicField)) !== stable2(schema2.fields)) return
|
|
9584
|
+
if (stable2(definitions3.map(publicField)) !== stable2(schema2.fields)) return invalid13();
|
|
9462
9585
|
let display = parseRecordDisplay2(schema2.display, definitions3);
|
|
9463
9586
|
return { name: name5, schema: {
|
|
9464
9587
|
type: schema2.type,
|
|
@@ -9469,24 +9592,24 @@ function validateSnapshotEnvelope(input, repository, name4, bodies = [], timelin
|
|
|
9469
9592
|
}), types = /* @__PURE__ */ new Map();
|
|
9470
9593
|
for (let collection of catalogue) {
|
|
9471
9594
|
let records = collections[collection.name];
|
|
9472
|
-
if (!Array.isArray(records)) return
|
|
9595
|
+
if (!Array.isArray(records)) return invalid13();
|
|
9473
9596
|
let previous = "";
|
|
9474
9597
|
for (let record4 of records) {
|
|
9475
9598
|
let value = object8(record4);
|
|
9476
|
-
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
|
|
9599
|
+
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 invalid13();
|
|
9477
9600
|
types.set(value.$ref, collection.schema.type), previous = value.$ref;
|
|
9478
9601
|
}
|
|
9479
9602
|
}
|
|
9480
9603
|
for (let collection of catalogue) for (let record4 of collections[collection.name]) {
|
|
9481
9604
|
let { $ref: _ref, $version: _version, $body, $signals, $timeline, ...values } = record4;
|
|
9482
9605
|
if (legacy) {
|
|
9483
|
-
if (Object.hasOwn(record4, "$signals") || Object.hasOwn(record4, "$timeline")) return
|
|
9606
|
+
if (Object.hasOwn(record4, "$signals") || Object.hasOwn(record4, "$timeline")) return invalid13();
|
|
9484
9607
|
} else if (captureRecordSignals($signals), timelines.includes(collection.name)) {
|
|
9485
|
-
if (!Array.isArray($timeline)) return
|
|
9608
|
+
if (!Array.isArray($timeline)) return invalid13();
|
|
9486
9609
|
$timeline.forEach((value) => captureTimeline(value));
|
|
9487
|
-
} else if (Object.hasOwn(record4, "$timeline")) return
|
|
9488
|
-
if (Object.hasOwn(record4, "$body") && (!bodies.includes(collection.name) || typeof $body != "string")) return
|
|
9489
|
-
validateRecordFields(values, collection.schema.fields, (ref,
|
|
9610
|
+
} else if (Object.hasOwn(record4, "$timeline")) return invalid13();
|
|
9611
|
+
if (Object.hasOwn(record4, "$body") && (!bodies.includes(collection.name) || typeof $body != "string")) return invalid13();
|
|
9612
|
+
validateRecordFields(values, collection.schema.fields, (ref, targets2) => types.get(ref) ?? targets2[0], !0);
|
|
9490
9613
|
}
|
|
9491
9614
|
let normalized = legacy ? Object.fromEntries(Object.entries(collections).map(([collection, records]) => [
|
|
9492
9615
|
collection,
|
|
@@ -9504,7 +9627,7 @@ function validateSnapshotEnvelope(input, repository, name4, bodies = [], timelin
|
|
|
9504
9627
|
...Object.hasOwn(row, "history") ? { history: validateSnapshotHistory(row.history, normalized, row.version) } : {}
|
|
9505
9628
|
};
|
|
9506
9629
|
} catch {
|
|
9507
|
-
return
|
|
9630
|
+
return invalid13();
|
|
9508
9631
|
}
|
|
9509
9632
|
}
|
|
9510
9633
|
|
|
@@ -9515,7 +9638,7 @@ function continuation(value, binding, matching, limit) {
|
|
|
9515
9638
|
let { position, ref } = cursorPosition(value, binding, limit);
|
|
9516
9639
|
return position >= matching.length || ref !== matching[position - 1]?.$ref ? fail6("incompatible cursor") : position;
|
|
9517
9640
|
}
|
|
9518
|
-
function
|
|
9641
|
+
function matchesScalar(record4, selection2) {
|
|
9519
9642
|
return (selection2.signalConditions ?? []).every(([key, statuses]) => {
|
|
9520
9643
|
if (!Array.isArray(record4.$signals)) return fail6("Signals are unavailable");
|
|
9521
9644
|
let signal = record4.$signals?.find((row) => row.key === key);
|
|
@@ -9538,14 +9661,45 @@ function matches(record4, selection2) {
|
|
|
9538
9661
|
});
|
|
9539
9662
|
});
|
|
9540
9663
|
}
|
|
9664
|
+
function linkValues(record4, field) {
|
|
9665
|
+
if (!Object.hasOwn(record4, field) || record4[field] === null) return [];
|
|
9666
|
+
let value = record4[field];
|
|
9667
|
+
return Array.isArray(value) ? value.map((item) => typeof item != "string" ? fail6("invalid stored link") : item) : typeof value == "string" ? [value] : fail6("invalid stored link");
|
|
9668
|
+
}
|
|
9669
|
+
function* matches(record4, selection2) {
|
|
9670
|
+
if (!matchesScalar(record4, selection2)) return !1;
|
|
9671
|
+
for (let condition of selection2.linkConditions) {
|
|
9672
|
+
let records = [record4];
|
|
9673
|
+
for (let [index, field] of condition.path.entries()) {
|
|
9674
|
+
let refs = records.flatMap((record5) => linkValues(record5, field).map((value) => parseRecordLink(value) ?? fail6("invalid stored link")));
|
|
9675
|
+
if (index === condition.path.length - 1) {
|
|
9676
|
+
if (!refs.some(({ ref }) => condition.refs.includes(ref))) return !1;
|
|
9677
|
+
break;
|
|
9678
|
+
}
|
|
9679
|
+
let targets2 = [];
|
|
9680
|
+
for (let { ref } of refs) {
|
|
9681
|
+
let target = yield { operation: "lookup", ref };
|
|
9682
|
+
target && targets2.push(target.record);
|
|
9683
|
+
}
|
|
9684
|
+
if (records = targets2, !records.length) return !1;
|
|
9685
|
+
}
|
|
9686
|
+
}
|
|
9687
|
+
return !0;
|
|
9688
|
+
}
|
|
9541
9689
|
function ordered(a, b, { field, direction }) {
|
|
9542
9690
|
let left = a[field], right = b[field], missingLeft = left == null, missingRight = right == null, result2 = 0;
|
|
9543
9691
|
return missingLeft !== missingRight ? missingLeft ? 1 : -1 : (!missingLeft && !missingRight && (result2 = typeof left == "number" && typeof right == "number" ? left - right : typeof left == "boolean" && typeof right == "boolean" ? Number(left) - Number(right) : compare2(left, right), direction === "desc" && (result2 = -result2)), result2 || compare2(a.$ref, b.$ref));
|
|
9544
9692
|
}
|
|
9545
|
-
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue, bodyCollections = []) {
|
|
9546
|
-
let { version } = context, selections = planIndexQuery(query, catalogue), scanned = /* @__PURE__ */ new Map();
|
|
9693
|
+
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue, bodyCollections = [], allowUnknownTerminalRefs = !1) {
|
|
9694
|
+
let { version } = context, selections = planIndexQuery(query, catalogue, { allowUnknownTerminalRefs }), scanned = /* @__PURE__ */ new Map();
|
|
9547
9695
|
for (let { name: name4 } of selections) scanned.set(name4, yield { operation: "scan", collection: name4 });
|
|
9548
|
-
|
|
9696
|
+
let selected = /* @__PURE__ */ new Map();
|
|
9697
|
+
for (let { name: name4, selection: selection2 } of selections) {
|
|
9698
|
+
let matching = [];
|
|
9699
|
+
for (let record4 of scanned.get(name4)) (yield* matches(record4, selection2)) && matching.push(record4);
|
|
9700
|
+
selected.set(name4, matching);
|
|
9701
|
+
}
|
|
9702
|
+
if (maxRecords !== void 0 && selections.reduce((sum, { name: name4 }) => sum + selected.get(name4).length, 0) > maxRecords)
|
|
9549
9703
|
throw new DataOperationError(
|
|
9550
9704
|
"capacity",
|
|
9551
9705
|
!1,
|
|
@@ -9575,7 +9729,7 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
9575
9729
|
let { ref, fragment: fragment2 } = parseRecordLink(value2) ?? fail6("invalid stored link"), target = yield { operation: "lookup", ref };
|
|
9576
9730
|
if (!target) return fail6("unresolved stored link");
|
|
9577
9731
|
let nested = link.targets.get(target.collection) ?? fail6("incompatible stored link");
|
|
9578
|
-
matches(target.record, nested) && matching.push({ record: target.record, collection: target.collection, selection: nested, fragment: fragment2 });
|
|
9732
|
+
(yield* matches(target.record, nested)) && matching.push({ record: target.record, collection: target.collection, selection: nested, fragment: fragment2 });
|
|
9579
9733
|
}
|
|
9580
9734
|
let options = link.targets.values().next().value;
|
|
9581
9735
|
if (options.explicitOrder && matching.sort((a, b) => ordered(a.record, b.record, options.order)), link.many && !options.explicitLimit && matching.length > 100) return fail6("too many matching linked Records");
|
|
@@ -9590,7 +9744,7 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
9590
9744
|
}
|
|
9591
9745
|
let metadata = { version, collections: {} }, results = [];
|
|
9592
9746
|
for (let { name: name4, selection: selection2 } of selections) {
|
|
9593
|
-
let matching =
|
|
9747
|
+
let matching = selected.get(name4).sort((a, b) => ordered(a, b, selection2.order)), binding = indexSelectionBinding(context, name4, selection2), start = selection2.after === void 0 ? 0 : continuation(yield { operation: "open", token: selection2.after }, binding, matching, selection2.limit), end = maxRecords === void 0 ? Math.min(start + selection2.limit, matching.length) : matching.length, records = [];
|
|
9594
9748
|
for (let index = start; index < end; index++)
|
|
9595
9749
|
maxRecords !== void 0 && (index - start) % selection2.limit === 0 && (occurrences = 0), records.push(yield* expand(matching[index], name4, selection2));
|
|
9596
9750
|
let page = selection2.count ? { count: matching.length } : {};
|
|
@@ -9611,14 +9765,14 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
9611
9765
|
|
|
9612
9766
|
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";
|
|
9613
9767
|
|
|
9614
|
-
var
|
|
9768
|
+
var invalid14 = () => {
|
|
9615
9769
|
throw new DataOperationError("unavailable", !0);
|
|
9616
|
-
}, object9 = (v) => v && typeof v == "object" && !Array.isArray(v) ? v :
|
|
9770
|
+
}, object9 = (v) => v && typeof v == "object" && !Array.isArray(v) ? v : invalid14(), uuid5 = (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), time3 = (v) => typeof v == "string" && Number.isFinite(Date.parse(v)), recordVersion = (v) => typeof v == "string" && /^record-v1:[0-9a-f]{64}$/.test(v), keys5 = (v, allowed) => Object.keys(v).every((k) => allowed.includes(k));
|
|
9617
9771
|
function validateAcquisition(input, repository, name4) {
|
|
9618
9772
|
let row = object9(input), snapshot = object9(row.snapshot);
|
|
9619
|
-
if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !keys5(snapshot, ["id", "name", "refreshedAt", "repository", "version", "collections", "bodies", "timelines"]) || !uuid5(snapshot.id) || snapshot.repository !== repository || snapshot.name !== name4 || !dataVersion(snapshot.version) || !time3(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
|
|
9773
|
+
if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !keys5(snapshot, ["id", "name", "refreshedAt", "repository", "version", "collections", "bodies", "timelines"]) || !uuid5(snapshot.id) || snapshot.repository !== repository || snapshot.name !== name4 || !dataVersion(snapshot.version) || !time3(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 invalid14();
|
|
9620
9774
|
let bodies = snapshot.bodies === void 0 ? [] : snapshot.bodies, timelines = snapshot.timelines === void 0 ? [] : snapshot.timelines;
|
|
9621
|
-
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
|
|
9775
|
+
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 invalid14();
|
|
9622
9776
|
return {
|
|
9623
9777
|
snapshot: { ...snapshot, bodies, timelines },
|
|
9624
9778
|
changes: validateSnapshotChanges(row.changes, snapshot.collections)
|
|
@@ -9626,47 +9780,47 @@ function validateAcquisition(input, repository, name4) {
|
|
|
9626
9780
|
}
|
|
9627
9781
|
function validateSnapshotChanges(input, collections) {
|
|
9628
9782
|
try {
|
|
9629
|
-
if (!Array.isArray(input)) return
|
|
9783
|
+
if (!Array.isArray(input)) return invalid14();
|
|
9630
9784
|
let ids = /* @__PURE__ */ new Set(), unpublished = !1;
|
|
9631
9785
|
for (let value of input) {
|
|
9632
9786
|
let c = object9(value), effect = object9(c.effect);
|
|
9633
|
-
if (!keys5(c, ["id", "version", "ref", "recordVersion", "effect", "updatedAt", "person", "source", "publication"]) || !uuid5(c.id) || ids.has(c.id) || !dataVersion(c.version) || !validRecordRef(c.ref) || !collections.some((name4) => c.ref.startsWith(`${name4}/`)) || !recordVersion(c.recordVersion) || !time3(c.updatedAt)) return
|
|
9787
|
+
if (!keys5(c, ["id", "version", "ref", "recordVersion", "effect", "updatedAt", "person", "source", "publication"]) || !uuid5(c.id) || ids.has(c.id) || !dataVersion(c.version) || !validRecordRef(c.ref) || !collections.some((name4) => c.ref.startsWith(`${name4}/`)) || !recordVersion(c.recordVersion) || !time3(c.updatedAt)) return invalid14();
|
|
9634
9788
|
if (ids.add(c.id), c.person !== void 0) {
|
|
9635
9789
|
let person = object9(c.person);
|
|
9636
|
-
if (!keys5(person, ["id", "name", "email"]) || !uuid5(person.id) || person.name !== void 0 && !dataText(person.name) || person.email !== void 0 && !dataText(person.email)) return
|
|
9790
|
+
if (!keys5(person, ["id", "name", "email"]) || !uuid5(person.id) || person.name !== void 0 && !dataText(person.name) || person.email !== void 0 && !dataText(person.email)) return invalid14();
|
|
9637
9791
|
}
|
|
9638
9792
|
if (c.source !== void 0) {
|
|
9639
9793
|
let source2 = object9(c.source);
|
|
9640
|
-
if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine" || !dataText(source2.id)) return
|
|
9794
|
+
if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine" || !dataText(source2.id)) return invalid14();
|
|
9641
9795
|
}
|
|
9642
9796
|
if (c.publication !== void 0) {
|
|
9643
9797
|
let publication = object9(c.publication);
|
|
9644
|
-
if (unpublished || Object.keys(publication).sort().join(",") !== "commit,time" || typeof publication.commit != "string" || !/^[0-9a-f]{40}$/.test(publication.commit) || !time3(publication.time)) return
|
|
9798
|
+
if (unpublished || Object.keys(publication).sort().join(",") !== "commit,time" || typeof publication.commit != "string" || !/^[0-9a-f]{40}$/.test(publication.commit) || !time3(publication.time)) return invalid14();
|
|
9645
9799
|
} else unpublished = !0;
|
|
9646
9800
|
if (effect.kind === "set") {
|
|
9647
|
-
if (Object.keys(effect).sort().join(",") !== "field,kind,value" || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field)) return
|
|
9801
|
+
if (Object.keys(effect).sort().join(",") !== "field,kind,value" || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field)) return invalid14();
|
|
9648
9802
|
} else if (effect.kind === "link" || effect.kind === "unlink") {
|
|
9649
|
-
if (!keys5(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
|
|
9803
|
+
if (!keys5(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 invalid14();
|
|
9650
9804
|
} else if (effect.kind === "signal") {
|
|
9651
|
-
if (Object.keys(effect).sort().join(",") !== "key,kind,value") return
|
|
9805
|
+
if (Object.keys(effect).sort().join(",") !== "key,kind,value") return invalid14();
|
|
9652
9806
|
let value2 = object9(effect.value);
|
|
9653
|
-
if (!keys5(value2, ["label", "status", "reason", "related", "asOf", "number"])) return
|
|
9807
|
+
if (!keys5(value2, ["label", "status", "reason", "related", "asOf", "number"])) return invalid14();
|
|
9654
9808
|
let { number, ...assessment } = value2;
|
|
9655
9809
|
captureSignal({ ...assessment, key: effect.key }), (c.publication || Object.hasOwn(value2, "number")) && captureRecordSignal({ ...value2, key: effect.key });
|
|
9656
9810
|
} else if (effect.kind === "timeline") {
|
|
9657
|
-
if (Object.keys(effect).sort().join(",") !== "entry,kind") return
|
|
9811
|
+
if (Object.keys(effect).sort().join(",") !== "entry,kind") return invalid14();
|
|
9658
9812
|
captureTimeline(effect.entry);
|
|
9659
9813
|
} else if (effect.kind === "create" || effect.kind === "delete") {
|
|
9660
|
-
if (!keys5(effect, ["fields", "kind", "signals", "timeline"])) return
|
|
9814
|
+
if (!keys5(effect, ["fields", "kind", "signals", "timeline"])) return invalid14();
|
|
9661
9815
|
if (object9(effect.fields), Object.hasOwn(effect, "signals") && captureRecordSignals(effect.signals), Object.hasOwn(effect, "timeline")) {
|
|
9662
|
-
if (!Array.isArray(effect.timeline)) return
|
|
9816
|
+
if (!Array.isArray(effect.timeline)) return invalid14();
|
|
9663
9817
|
effect.timeline.forEach((value2) => captureTimeline(value2));
|
|
9664
9818
|
}
|
|
9665
|
-
} else return
|
|
9819
|
+
} else return invalid14();
|
|
9666
9820
|
}
|
|
9667
9821
|
return input;
|
|
9668
9822
|
} catch {
|
|
9669
|
-
return
|
|
9823
|
+
return invalid14();
|
|
9670
9824
|
}
|
|
9671
9825
|
}
|
|
9672
9826
|
function materializeSnapshot(envelope, changes, version) {
|
|
@@ -9675,44 +9829,44 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
9675
9829
|
let rows = new Map(Object.values(envelope.collections).flat().map((r) => [r.$ref, structuredClone(r)]));
|
|
9676
9830
|
for (let c of changes) {
|
|
9677
9831
|
let schema2 = snapshotCollection(envelope.catalogue, c.ref);
|
|
9678
|
-
if (!schema2) return
|
|
9832
|
+
if (!schema2) return invalid14();
|
|
9679
9833
|
let effect = c.effect, definitions3 = "field" in effect ? schema2.schema.fields.filter((f) => f.name === effect.field) : schema2.schema.fields;
|
|
9680
|
-
if ("field" in effect && !definitions3.length) return
|
|
9834
|
+
if ("field" in effect && !definitions3.length) return invalid14();
|
|
9681
9835
|
let values;
|
|
9682
9836
|
if (effect.kind === "link" || effect.kind === "unlink") {
|
|
9683
9837
|
let field = definitions3[0];
|
|
9684
|
-
if (field.kind !== "link" || !field.many && effect.kind === "link" && effect.refs.length !== 1) return
|
|
9685
|
-
let
|
|
9686
|
-
for (let ref of
|
|
9838
|
+
if (field.kind !== "link" || !field.many && effect.kind === "link" && effect.refs.length !== 1) return invalid14();
|
|
9839
|
+
let targets2 = [...effect.refs, ...effect.kind === "link" ? effect.remove ?? [] : []];
|
|
9840
|
+
for (let ref of targets2) validateRecordFields({ [effect.field]: field.many ? [ref] : ref }, definitions3, (_ref, allowed) => allowed[0], !0);
|
|
9687
9841
|
values = { [effect.field]: field.many ? effect.refs : effect.refs[0] };
|
|
9688
9842
|
} else values = effect.kind === "set" ? { [effect.field]: effect.value } : "fields" in effect ? effect.fields : {};
|
|
9689
9843
|
if (effect.kind !== "signal" && effect.kind !== "timeline" && validateRecordFields(
|
|
9690
9844
|
values,
|
|
9691
9845
|
definitions3,
|
|
9692
|
-
(_ref,
|
|
9846
|
+
(_ref, targets2) => targets2[0],
|
|
9693
9847
|
!0
|
|
9694
9848
|
), !c.publication) continue;
|
|
9695
9849
|
let prior = rows.get(c.ref);
|
|
9696
9850
|
if (effect.kind === "set") {
|
|
9697
|
-
if (!prior) return
|
|
9851
|
+
if (!prior) return invalid14();
|
|
9698
9852
|
rows.set(c.ref, { ...prior, [effect.field]: effect.value, $version: c.recordVersion });
|
|
9699
9853
|
} else if (effect.kind === "link" || effect.kind === "unlink") {
|
|
9700
|
-
if (!prior) return
|
|
9854
|
+
if (!prior) return invalid14();
|
|
9701
9855
|
let field = definitions3[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;
|
|
9702
9856
|
rows.set(c.ref, { ...prior, [effect.field]: value, $version: c.recordVersion });
|
|
9703
9857
|
} else if (effect.kind === "signal") {
|
|
9704
|
-
if (!prior || !effect.value.number) return
|
|
9858
|
+
if (!prior || !effect.value.number) return invalid14();
|
|
9705
9859
|
let signal = captureRecordSignal({ ...effect.value, key: effect.key }), signals = captureRecordSignals(prior.$signals), index = signals.findIndex((row) => row.key === effect.key);
|
|
9706
9860
|
index < 0 ? signals.push(signal) : signals[index] = signal, rows.set(c.ref, { ...prior, $signals: captureRecordSignals(signals), $version: c.recordVersion });
|
|
9707
9861
|
} else if (effect.kind === "timeline") {
|
|
9708
|
-
if (!prior) return
|
|
9862
|
+
if (!prior) return invalid14();
|
|
9709
9863
|
rows.set(c.ref, {
|
|
9710
9864
|
...prior,
|
|
9711
9865
|
$version: c.recordVersion,
|
|
9712
9866
|
...envelope.timelineCollections.includes(schema2.name) ? { $timeline: [...prior.$timeline, effect.entry] } : {}
|
|
9713
9867
|
});
|
|
9714
9868
|
} else if (effect.kind === "create") {
|
|
9715
|
-
if (prior) return
|
|
9869
|
+
if (prior) return invalid14();
|
|
9716
9870
|
rows.set(c.ref, {
|
|
9717
9871
|
...effect.fields,
|
|
9718
9872
|
$ref: c.ref,
|
|
@@ -9721,7 +9875,7 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
9721
9875
|
...envelope.timelineCollections.includes(schema2.name) ? { $timeline: effect.timeline ?? [] } : {}
|
|
9722
9876
|
});
|
|
9723
9877
|
} else {
|
|
9724
|
-
if (!prior) return
|
|
9878
|
+
if (!prior) return invalid14();
|
|
9725
9879
|
rows.delete(c.ref);
|
|
9726
9880
|
}
|
|
9727
9881
|
}
|
|
@@ -9734,7 +9888,7 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
9734
9888
|
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)]))
|
|
9735
9889
|
}, envelope.repository, envelope.name, envelope.bodyCollections, envelope.timelineCollections), ...envelope.history ? { history: envelope.history } : {} };
|
|
9736
9890
|
} catch {
|
|
9737
|
-
return
|
|
9891
|
+
return invalid14();
|
|
9738
9892
|
}
|
|
9739
9893
|
}
|
|
9740
9894
|
|
|
@@ -9790,6 +9944,47 @@ function applySnapshotMutation(envelope, prior, mutation, installation) {
|
|
|
9790
9944
|
return { envelope, changes };
|
|
9791
9945
|
}
|
|
9792
9946
|
|
|
9947
|
+
var invalid15 = () => {
|
|
9948
|
+
throw new DataOperationError("unavailable", !0, void 0, "snapshot_cache");
|
|
9949
|
+
};
|
|
9950
|
+
function targets(value, definition, found) {
|
|
9951
|
+
if (value != null) {
|
|
9952
|
+
if (definition.many) {
|
|
9953
|
+
if (!Array.isArray(value)) return invalid15();
|
|
9954
|
+
for (let item of value) targets(item, { ...definition, many: !1 }, found);
|
|
9955
|
+
} else if (definition.kind === "link") {
|
|
9956
|
+
let link = parseRecordLink(value);
|
|
9957
|
+
if (!link) return invalid15();
|
|
9958
|
+
found.add(link.ref);
|
|
9959
|
+
} else if (definition.kind === "object") {
|
|
9960
|
+
if (typeof value != "object" || Array.isArray(value)) return invalid15();
|
|
9961
|
+
for (let field of definition.fields) targets(value[field.name], field, found);
|
|
9962
|
+
} else if (definition.kind === "map") {
|
|
9963
|
+
if (typeof value != "object" || Array.isArray(value)) return invalid15();
|
|
9964
|
+
for (let item of Object.values(value)) targets(item, definition.value, found);
|
|
9965
|
+
}
|
|
9966
|
+
}
|
|
9967
|
+
}
|
|
9968
|
+
function snapshotBacklinkRows(installation, catalogue, collections) {
|
|
9969
|
+
let rows = [];
|
|
9970
|
+
for (let collection of catalogue) for (let record4 of collections[collection.name] ?? []) {
|
|
9971
|
+
let fieldsByTarget = /* @__PURE__ */ new Map();
|
|
9972
|
+
for (let field of collection.schema.fields) {
|
|
9973
|
+
let found = /* @__PURE__ */ new Set();
|
|
9974
|
+
targets(record4[field.name], field, found);
|
|
9975
|
+
for (let target of found) fieldsByTarget.set(target, [...fieldsByTarget.get(target) ?? [], field.name]);
|
|
9976
|
+
}
|
|
9977
|
+
for (let [target, fields4] of fieldsByTarget) rows.push({
|
|
9978
|
+
installation,
|
|
9979
|
+
target,
|
|
9980
|
+
source: record4.$ref,
|
|
9981
|
+
collection: collection.name,
|
|
9982
|
+
fields: fields4
|
|
9983
|
+
});
|
|
9984
|
+
}
|
|
9985
|
+
return rows.sort((left, right) => left.target < right.target ? -1 : left.target > right.target ? 1 : left.source < right.source ? -1 : left.source > right.source ? 1 : 0);
|
|
9986
|
+
}
|
|
9987
|
+
|
|
9793
9988
|
var unavailable2 = () => {
|
|
9794
9989
|
throw new DataOperationError("unavailable", !0);
|
|
9795
9990
|
}, cacheUnavailable = () => new DataOperationError("unavailable", !0, void 0, "snapshot_cache");
|
|
@@ -9809,10 +10004,9 @@ function encode(bytes) {
|
|
|
9809
10004
|
return btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(""));
|
|
9810
10005
|
}
|
|
9811
10006
|
async function openSnapshotStore() {
|
|
9812
|
-
let opening = indexedDB.open("oddington.data.snapshots.v2",
|
|
10007
|
+
let opening = indexedDB.open("oddington.data.snapshots.v2", 3);
|
|
9813
10008
|
opening.onupgradeneeded = () => {
|
|
9814
|
-
|
|
9815
|
-
opening.result.createObjectStore("current"), opening.result.createObjectStore("changes"), opening.result.createObjectStore("records", { keyPath: ["installation", "ref"] }).createIndex("collection", ["installation", "collection"]);
|
|
10009
|
+
opening.result.objectStoreNames.contains("bases") || opening.result.createObjectStore("bases"), opening.result.objectStoreNames.contains("current") || opening.result.createObjectStore("current"), opening.result.objectStoreNames.contains("changes") || opening.result.createObjectStore("changes"), opening.result.objectStoreNames.contains("records") || opening.result.createObjectStore("records", { keyPath: ["installation", "ref"] }).createIndex("collection", ["installation", "collection"]), opening.result.objectStoreNames.contains("backlinks") || opening.result.createObjectStore("backlinks", { keyPath: ["installation", "target", "source"] }).createIndex("installation", "installation");
|
|
9816
10010
|
};
|
|
9817
10011
|
let database = await request(opening);
|
|
9818
10012
|
return database.onversionchange = () => database.close(), {
|
|
@@ -9820,7 +10014,7 @@ async function openSnapshotStore() {
|
|
|
9820
10014
|
database.close();
|
|
9821
10015
|
},
|
|
9822
10016
|
async compact() {
|
|
9823
|
-
let transaction = database.transaction(["current", "records", "changes", "bases"], "readwrite"), done = completed(transaction);
|
|
10017
|
+
let transaction = database.transaction(["current", "records", "backlinks", "changes", "bases"], "readwrite"), done = completed(transaction);
|
|
9824
10018
|
try {
|
|
9825
10019
|
let pointers = transaction.objectStore("current"), current2 = [];
|
|
9826
10020
|
for (let key of await request(pointers.getAllKeys())) {
|
|
@@ -9829,7 +10023,7 @@ async function openSnapshotStore() {
|
|
|
9829
10023
|
}
|
|
9830
10024
|
let installationIds = new Set(current2.map((value) => value.id).filter(Boolean)), recordIds = new Set(current2.map((value) => value.recordsId ?? value.id).filter(Boolean)), artifactTokens = new Set(current2.map((value) => value.artifactToken).filter(Boolean)), changes = transaction.objectStore("changes"), stale2 = (await request(changes.getAllKeys())).filter((key) => typeof key == "string" && !installationIds.has(key));
|
|
9831
10025
|
for (let id5 of stale2)
|
|
9832
|
-
changes.delete(id5), recordIds.has(id5) || transaction.objectStore("records").delete(IDBKeyRange.bound([id5], [id5, []]));
|
|
10026
|
+
changes.delete(id5), recordIds.has(id5) || (transaction.objectStore("records").delete(IDBKeyRange.bound([id5], [id5, []])), transaction.objectStore("backlinks").delete(IDBKeyRange.bound([id5], [id5, []])));
|
|
9833
10027
|
let bases = transaction.objectStore("bases");
|
|
9834
10028
|
for (let key of await request(bases.getAllKeys()))
|
|
9835
10029
|
typeof key == "string" && !artifactTokens.has(key) && bases.delete(key);
|
|
@@ -9844,27 +10038,27 @@ async function openSnapshotStore() {
|
|
|
9844
10038
|
}
|
|
9845
10039
|
},
|
|
9846
10040
|
async current(partition) {
|
|
9847
|
-
let transaction = database.transaction(["current", "records", "changes", "bases"], "readonly"), done = completed(transaction), value = await request(transaction.objectStore("current").get(partition));
|
|
10041
|
+
let transaction = database.transaction(["current", "records", "backlinks", "changes", "bases"], "readonly"), done = completed(transaction), value = await request(transaction.objectStore("current").get(partition));
|
|
9848
10042
|
if (!value) {
|
|
9849
10043
|
await done;
|
|
9850
10044
|
return;
|
|
9851
10045
|
}
|
|
9852
10046
|
let recordsId = value.recordsId ?? value.id;
|
|
9853
|
-
if (value.format !== "data-snapshot.v2" || !Array.isArray(value.timelineCollections) || value.partition !== partition || !value.id || !recordsId || !value.snapshotId || value.pairToken !== "" && !validSnapshotPairToken(value.pairToken) || !validSnapshotArtifactToken(value.artifactToken) || !value.version || !Array.isArray(value.catalogue) || !value.counts || !(value.cursorKey instanceof Uint8Array) || value.cursorKey.length !== 32) {
|
|
10047
|
+
if (value.format !== "data-snapshot.v2" || !Array.isArray(value.timelineCollections) || value.partition !== partition || !value.id || !recordsId || !value.snapshotId || value.pairToken !== "" && !validSnapshotPairToken(value.pairToken) || !validSnapshotArtifactToken(value.artifactToken) || !value.version || !Array.isArray(value.catalogue) || !value.counts || !Number.isSafeInteger(value.backlinkCount) || value.backlinkCount < 0 || !(value.cursorKey instanceof Uint8Array) || value.cursorKey.length !== 32) {
|
|
9854
10048
|
await done;
|
|
9855
10049
|
return;
|
|
9856
10050
|
}
|
|
9857
10051
|
let changes = await request(transaction.objectStore("changes").get(value.id)), complete = !!await request(transaction.objectStore("bases").getKey(value.artifactToken)) && Array.isArray(changes) && changes.length === value.changeCount;
|
|
9858
10052
|
for (let collection of value.catalogue)
|
|
9859
10053
|
await request(transaction.objectStore("records").index("collection").count([recordsId, collection.name])) !== value.counts[collection.name] && (complete = !1);
|
|
9860
|
-
return await done, complete ? { ...value, recordsId } : void 0;
|
|
10054
|
+
return await request(transaction.objectStore("backlinks").index("installation").count(recordsId)) !== value.backlinkCount && (complete = !1), await done, complete ? { ...value, recordsId } : void 0;
|
|
9861
10055
|
},
|
|
9862
10056
|
async base(installation) {
|
|
9863
10057
|
let transaction = database.transaction("bases", "readonly"), done = completed(transaction), base = await request(transaction.objectStore("bases").get(installation.artifactToken));
|
|
9864
10058
|
return await done, base;
|
|
9865
10059
|
},
|
|
9866
10060
|
async install(partition, pairToken, envelope, changes, assertCurrent, snapshotId, artifact, unchangedRecords) {
|
|
9867
|
-
let id5 = crypto.randomUUID(), recordsId = unchangedRecords?.recordsId ?? id5, installation = {
|
|
10061
|
+
let id5 = crypto.randomUUID(), recordsId = unchangedRecords?.recordsId ?? id5, backlinkRows = unchangedRecords ? void 0 : snapshotBacklinkRows(recordsId, envelope.catalogue, envelope.collections), installation = {
|
|
9868
10062
|
id: id5,
|
|
9869
10063
|
recordsId,
|
|
9870
10064
|
partition,
|
|
@@ -9878,16 +10072,18 @@ async function openSnapshotStore() {
|
|
|
9878
10072
|
bodyCollections: envelope.bodyCollections,
|
|
9879
10073
|
timelineCollections: envelope.timelineCollections,
|
|
9880
10074
|
catalogue: envelope.catalogue,
|
|
10075
|
+
backlinkCount: unchangedRecords?.backlinkCount ?? backlinkRows.length,
|
|
9881
10076
|
changeCount: changes.length,
|
|
9882
10077
|
cursorKey: unchangedRecords?.cursorKey ?? crypto.getRandomValues(new Uint8Array(32)),
|
|
9883
10078
|
...unchangedRecords ? { queryIdentity: unchangedRecords.queryIdentity ?? unchangedRecords.id } : {},
|
|
9884
10079
|
counts: Object.fromEntries(Object.entries(envelope.collections).map(([name4, rows]) => [name4, rows.length]))
|
|
9885
|
-
}, transaction = database.transaction(["current", "records", "changes", "bases"], "readwrite"), done = completed(transaction);
|
|
10080
|
+
}, transaction = database.transaction(["current", "records", "backlinks", "changes", "bases"], "readwrite"), done = completed(transaction);
|
|
9886
10081
|
try {
|
|
9887
10082
|
assertCurrent(), transaction.objectStore("bases").put(artifact.base, artifact.token);
|
|
9888
10083
|
let records = transaction.objectStore("records");
|
|
9889
10084
|
if (!unchangedRecords) for (let [collection, rows] of Object.entries(envelope.collections)) for (let record4 of rows)
|
|
9890
10085
|
records.put({ installation: recordsId, collection, ref: record4.$ref, record: record4 });
|
|
10086
|
+
if (backlinkRows) for (let row of backlinkRows) transaction.objectStore("backlinks").put(row);
|
|
9891
10087
|
return await request(transaction.objectStore("changes").put(changes, installation.id)), await request(transaction.objectStore("current").put(installation, partition)), assertCurrent(), await done, assertCurrent(), installation;
|
|
9892
10088
|
} catch (error) {
|
|
9893
10089
|
try {
|
|
@@ -9903,7 +10099,7 @@ async function openSnapshotStore() {
|
|
|
9903
10099
|
transaction.objectStore("changes").delete(installation.id), (await request(transaction.objectStore("current").get(installation.partition)))?.id === installation.id && transaction.objectStore("current").delete(installation.partition), await done;
|
|
9904
10100
|
},
|
|
9905
10101
|
async mutate(installation, mutation, assertCurrent) {
|
|
9906
|
-
let transaction = database.transaction(["current", "records", "changes"], "readwrite"), done = completed(transaction);
|
|
10102
|
+
let transaction = database.transaction(["current", "records", "backlinks", "changes"], "readwrite"), done = completed(transaction);
|
|
9907
10103
|
try {
|
|
9908
10104
|
assertCurrent();
|
|
9909
10105
|
let records = transaction.objectStore("records"), collections = {}, prior = await request(transaction.objectStore("changes").get(installation.id));
|
|
@@ -9922,18 +10118,20 @@ async function openSnapshotStore() {
|
|
|
9922
10118
|
timelineCollections: installation.timelineCollections,
|
|
9923
10119
|
catalogue: installation.catalogue,
|
|
9924
10120
|
collections
|
|
9925
|
-
}, prior, mutation, installation), id5 = crypto.randomUUID(), recordsId = mutation.kind === "publish" ? id5 : installation.recordsId, next = {
|
|
10121
|
+
}, prior, mutation, installation), id5 = crypto.randomUUID(), recordsId = mutation.kind === "publish" ? id5 : installation.recordsId, backlinkRows = mutation.kind === "publish" ? snapshotBacklinkRows(recordsId, envelope.catalogue, envelope.collections) : void 0, next = {
|
|
9926
10122
|
...installation,
|
|
9927
10123
|
id: id5,
|
|
9928
10124
|
recordsId,
|
|
9929
10125
|
pairToken: "",
|
|
9930
10126
|
version: envelope.version,
|
|
9931
10127
|
queryIdentity: mutation.kind === "publish" ? id5 : installation.queryIdentity ?? installation.id,
|
|
10128
|
+
backlinkCount: backlinkRows?.length ?? installation.backlinkCount,
|
|
9932
10129
|
changeCount: changes.length,
|
|
9933
10130
|
counts: Object.fromEntries(Object.entries(envelope.collections).map(([name4, rows]) => [name4, rows.length]))
|
|
9934
10131
|
};
|
|
9935
10132
|
if (mutation.kind === "publish") for (let [collection, rows] of Object.entries(envelope.collections)) for (let record4 of rows)
|
|
9936
10133
|
records.put({ installation: recordsId, collection, ref: record4.$ref, record: record4 });
|
|
10134
|
+
if (backlinkRows) for (let row of backlinkRows) transaction.objectStore("backlinks").put(row);
|
|
9937
10135
|
return transaction.objectStore("changes").put(changes, id5), (await request(transaction.objectStore("current").get(installation.partition)))?.id === installation.id && transaction.objectStore("current").put(next, installation.partition), assertCurrent(), await done, assertCurrent(), next;
|
|
9938
10136
|
} catch (error) {
|
|
9939
10137
|
try {
|
|
@@ -9966,7 +10164,8 @@ async function openSnapshotStore() {
|
|
|
9966
10164
|
},
|
|
9967
10165
|
maxRecords,
|
|
9968
10166
|
(value) => value,
|
|
9969
|
-
body ? installation.bodyCollections : void 0
|
|
10167
|
+
body ? installation.bodyCollections : void 0,
|
|
10168
|
+
!0
|
|
9970
10169
|
);
|
|
9971
10170
|
try {
|
|
9972
10171
|
let step = evaluation.next();
|
|
@@ -10004,6 +10203,62 @@ async function openSnapshotStore() {
|
|
|
10004
10203
|
throw await done?.catch(() => {
|
|
10005
10204
|
}), error;
|
|
10006
10205
|
}
|
|
10206
|
+
},
|
|
10207
|
+
async backlinks(installation, ref, options) {
|
|
10208
|
+
let key = await crypto.subtle.importKey("raw", installation.cursorKey, "AES-GCM", !1, ["encrypt", "decrypt"]), factsTransaction = database.transaction("backlinks", "readonly"), factsDone = completed(factsTransaction), facts2 = factsTransaction.objectStore("backlinks"), rows = await request(facts2.getAll(IDBKeyRange.bound(
|
|
10209
|
+
[installation.recordsId, ref],
|
|
10210
|
+
[installation.recordsId, ref, []]
|
|
10211
|
+
))), backlinkCount = await request(facts2.index("installation").count(installation.recordsId));
|
|
10212
|
+
if (await factsDone, backlinkCount !== installation.backlinkCount) return unavailable2();
|
|
10213
|
+
let binding = JSON.stringify({
|
|
10214
|
+
workspaceId: installation.partition,
|
|
10215
|
+
repository: installation.partition,
|
|
10216
|
+
identity: installation.queryIdentity ?? installation.id,
|
|
10217
|
+
version: installation.version,
|
|
10218
|
+
operation: "records.backlinks",
|
|
10219
|
+
ref,
|
|
10220
|
+
limit: options.limit
|
|
10221
|
+
}), start = 0;
|
|
10222
|
+
if (options.after !== void 0) {
|
|
10223
|
+
let payload;
|
|
10224
|
+
try {
|
|
10225
|
+
let bytes = Uint8Array.from(atob(options.after), (c) => c.charCodeAt(0)), opened = await crypto.subtle.decrypt({ name: "AES-GCM", iv: bytes.slice(0, 12) }, key, bytes.slice(12));
|
|
10226
|
+
payload = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(opened));
|
|
10227
|
+
} catch {
|
|
10228
|
+
throw new DataOperationError("invalid_query");
|
|
10229
|
+
}
|
|
10230
|
+
let cursor = cursorPosition(payload, binding, options.limit);
|
|
10231
|
+
if (cursor.position >= rows.length || rows[cursor.position - 1]?.source !== cursor.ref)
|
|
10232
|
+
throw new RecordValidationError("Invalid Records query: incompatible cursor");
|
|
10233
|
+
start = cursor.position;
|
|
10234
|
+
}
|
|
10235
|
+
let end = Math.min(start + options.limit, rows.length), page = rows.slice(start, end), recordsTransaction = database.transaction("records", "readonly"), recordsDone = completed(recordsTransaction), records = recordsTransaction.objectStore("records"), found = await Promise.all(page.map((row) => request(records.get([installation.recordsId, row.source]))));
|
|
10236
|
+
if (await recordsDone, found.some((row, index) => !row || row.collection !== page[index].collection || row.ref !== page[index].source))
|
|
10237
|
+
return unavailable2();
|
|
10238
|
+
let result2 = found.map((row, index) => {
|
|
10239
|
+
let {
|
|
10240
|
+
$body: _body,
|
|
10241
|
+
$path: _path,
|
|
10242
|
+
$timeline: _timeline,
|
|
10243
|
+
$fragment: _fragment,
|
|
10244
|
+
$backlinks: _backlinks,
|
|
10245
|
+
...structured
|
|
10246
|
+
} = row.record;
|
|
10247
|
+
return {
|
|
10248
|
+
...structured,
|
|
10249
|
+
$signals: Array.isArray(structured.$signals) ? structured.$signals : [],
|
|
10250
|
+
$backlinks: [...page[index].fields]
|
|
10251
|
+
};
|
|
10252
|
+
}), metadata = { version: installation.version };
|
|
10253
|
+
if (end < rows.length) {
|
|
10254
|
+
let iv = crypto.getRandomValues(new Uint8Array(12)), payload = { format: 1, binding, position: end, ref: rows[end - 1].source }, sealed = new Uint8Array(await crypto.subtle.encrypt(
|
|
10255
|
+
{ name: "AES-GCM", iv },
|
|
10256
|
+
key,
|
|
10257
|
+
new TextEncoder().encode(JSON.stringify(payload))
|
|
10258
|
+
));
|
|
10259
|
+
metadata.next = encode(new Uint8Array([...iv, ...sealed]));
|
|
10260
|
+
}
|
|
10261
|
+
return { $meta: metadata, records: result2 };
|
|
10007
10262
|
}
|
|
10008
10263
|
};
|
|
10009
10264
|
}
|
|
@@ -10274,19 +10529,19 @@ function captureSelection(input) {
|
|
|
10274
10529
|
}
|
|
10275
10530
|
}
|
|
10276
10531
|
|
|
10277
|
-
var
|
|
10532
|
+
var invalid16 = () => {
|
|
10278
10533
|
throw new DataOperationError("invalid_query");
|
|
10279
10534
|
};
|
|
10280
10535
|
function captureSnapshotAll(query, options) {
|
|
10281
10536
|
let properties = dataProperties(options);
|
|
10282
|
-
return Object.keys(properties).some((key) => !["maxRecords", "body", "timeline"].includes(key)) || properties.body && properties.body.value !== !0 || properties.timeline && properties.timeline.value !== !0 ?
|
|
10537
|
+
return Object.keys(properties).some((key) => !["maxRecords", "body", "timeline"].includes(key)) || properties.body && properties.body.value !== !0 || properties.timeline && properties.timeline.value !== !0 ? invalid16() : { ...captureRecordsAll(query, { maxRecords: properties.maxRecords?.value }), body: properties.body?.value === !0, timeline: properties.timeline?.value === !0 };
|
|
10283
10538
|
}
|
|
10284
10539
|
var safeName = (value) => typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
|
|
10285
10540
|
function createSnapshotInitializer(resolve = resolveSnapshotContext, open = openSnapshotStore, connect = (url, protocols) => new WebSocket(url, protocols)) {
|
|
10286
10541
|
let pending = /* @__PURE__ */ new WeakMap(), maintenance = /* @__PURE__ */ new WeakMap();
|
|
10287
10542
|
return async function(input) {
|
|
10288
10543
|
let properties = dataProperties(input), repository = properties.repository?.value, snapshot = properties.snapshot?.value;
|
|
10289
|
-
if (Object.keys(properties).sort().join(",") !== "repository,snapshot" || !safeName(repository) || !safeName(snapshot)) return
|
|
10544
|
+
if (Object.keys(properties).sort().join(",") !== "repository,snapshot" || !safeName(repository) || !safeName(snapshot)) return invalid16();
|
|
10290
10545
|
let authority2 = await resolve(), invalidated = !1, stopLive, assertCurrent = () => {
|
|
10291
10546
|
if (invalidated || authority2.signal.aborted || !authority2.isCurrent() || !authority2.refresh && authority2.expiresAt <= Date.now())
|
|
10292
10547
|
throw invalidated = !0, stopLive?.(), new DataOperationError("context_unavailable");
|
|
@@ -10457,8 +10712,8 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
10457
10712
|
});
|
|
10458
10713
|
let store;
|
|
10459
10714
|
try {
|
|
10460
|
-
let selections = planIndexQuery(captured, pinned.catalogue), checkTimeline = (collection, selection2) => {
|
|
10461
|
-
if ((timeline || selection2.timeline) && !pinned.timelineCollections.includes(collection)) return
|
|
10715
|
+
let selections = planIndexQuery(captured, pinned.catalogue, { allowUnknownTerminalRefs: !0 }), checkTimeline = (collection, selection2) => {
|
|
10716
|
+
if ((timeline || selection2.timeline) && !pinned.timelineCollections.includes(collection)) return invalid16();
|
|
10462
10717
|
for (let link of selection2.links) for (let [name4, nested] of link.targets) checkTimeline(name4, nested);
|
|
10463
10718
|
};
|
|
10464
10719
|
for (let { name: name4, selection: selection2 } of selections) checkTimeline(name4, selection2);
|
|
@@ -10530,13 +10785,20 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
10530
10785
|
publication || (publication = { id: crypto.randomUUID() }, publications.set(key, publication)), await write(() => mutate("publish", { selected, ...metadata, publicationId: publication.id }, selected, publication));
|
|
10531
10786
|
}
|
|
10532
10787
|
}, records: {
|
|
10788
|
+
backlinks: async (ref, options) => {
|
|
10789
|
+
let captured = captureRecordsBacklinksInput(ref, options);
|
|
10790
|
+
return checkDataRequestSize({ repository, operation: "records.backlinks", ref: captured.ref, options: captured.options }), writes.then(() => {
|
|
10791
|
+
let pinned = installation;
|
|
10792
|
+
return localRead((store) => store.backlinks(pinned, captured.ref, captured.options));
|
|
10793
|
+
});
|
|
10794
|
+
},
|
|
10533
10795
|
read: async (ref, ...extra) => {
|
|
10534
10796
|
if (typeof ref != "string" || extra.length > 1) return Promise.reject(new DataOperationError("invalid_query"));
|
|
10535
10797
|
let { body, timeline } = captureRecordsReadOptions(extra[0]), [captured] = captureRecordsReadRefs([ref]);
|
|
10536
10798
|
return snapshotCollection(installation.catalogue, captured) ? writes.then(() => {
|
|
10537
10799
|
let pinned = installation;
|
|
10538
10800
|
return localRead(async (store) => {
|
|
10539
|
-
if (timeline && !pinned.timelineCollections.includes(snapshotCollection(pinned.catalogue, captured).name)) return
|
|
10801
|
+
if (timeline && !pinned.timelineCollections.includes(snapshotCollection(pinned.catalogue, captured).name)) return invalid16();
|
|
10540
10802
|
let record4 = await store.read(pinned, captured);
|
|
10541
10803
|
if (!record4) return record4;
|
|
10542
10804
|
let { $body, $timeline, ...structured } = record4;
|
|
@@ -10591,6 +10853,14 @@ var genericData = {
|
|
|
10591
10853
|
query: queryRecords,
|
|
10592
10854
|
...recordPagination(queryRecords),
|
|
10593
10855
|
all: async (query, options) => send3({ operation: "records.all", ...captureRecordsAll(query, options) }),
|
|
10856
|
+
backlinks: async (ref, options) => {
|
|
10857
|
+
let captured = captureRecordsBacklinksInput(ref, options);
|
|
10858
|
+
return send3({
|
|
10859
|
+
operation: "records.backlinks",
|
|
10860
|
+
ref: captured.ref,
|
|
10861
|
+
...options === void 0 ? {} : { options: captured.options }
|
|
10862
|
+
});
|
|
10863
|
+
},
|
|
10594
10864
|
search: async (query, options) => send3({ operation: "records.search", ...captureRecordsSearchInput(query, options) })
|
|
10595
10865
|
},
|
|
10596
10866
|
changes(options) {
|
|
@@ -10665,7 +10935,7 @@ var genericData = {
|
|
|
10665
10935
|
}
|
|
10666
10936
|
}, data = genericData;
|
|
10667
10937
|
|
|
10668
|
-
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 = [],
|
|
10938
|
+
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 = [], invalid17 = () => new FileOperationError("invalid_input", 400), unavailable4 = () => new FileOperationError("unavailable", 503, !0), failures = {
|
|
10669
10939
|
400: ["invalid_input", "unsupported_context"],
|
|
10670
10940
|
401: ["unauthenticated"],
|
|
10671
10941
|
403: ["access_denied"],
|
|
@@ -10821,7 +11091,7 @@ async function send(suffix, init2, descriptor, initial, parent) {
|
|
|
10821
11091
|
throw unavailable4();
|
|
10822
11092
|
}
|
|
10823
11093
|
function idPath(id5) {
|
|
10824
|
-
if (typeof id5 != "string" || !FILE_ID_PATTERN.test(id5)) throw
|
|
11094
|
+
if (typeof id5 != "string" || !FILE_ID_PATTERN.test(id5)) throw invalid17();
|
|
10825
11095
|
return `/${id5}`;
|
|
10826
11096
|
}
|
|
10827
11097
|
async function multipartCreate(input, metadata, exchange, release, upload, expectedSha256) {
|
|
@@ -10864,18 +11134,18 @@ async function multipartCreate(input, metadata, exchange, release, upload, expec
|
|
|
10864
11134
|
if (!chunk || offset === chunk.byteLength) {
|
|
10865
11135
|
chunk = void 0, offset = 0;
|
|
10866
11136
|
let value2 = await next();
|
|
10867
|
-
if (value2.done || !(value2.value instanceof Uint8Array) || (chunk = value2.value, chunk.byteLength > metadata.size - sent - filled)) throw
|
|
11137
|
+
if (value2.done || !(value2.value instanceof Uint8Array) || (chunk = value2.value, chunk.byteLength > metadata.size - sent - filled)) throw invalid17();
|
|
10868
11138
|
}
|
|
10869
11139
|
let take = Math.min(length - filled, chunk.byteLength - offset);
|
|
10870
11140
|
part.set(chunk.subarray(offset, offset + take), filled), filled += take, offset += take, offset === chunk.byteLength && (chunk = void 0, offset = 0);
|
|
10871
11141
|
}
|
|
10872
11142
|
}
|
|
10873
|
-
if (part.byteLength !== length) throw
|
|
11143
|
+
if (part.byteLength !== length) throw invalid17();
|
|
10874
11144
|
if (reader && sent + length === metadata.size)
|
|
10875
11145
|
for (lastProgress = Date.now(); ; ) {
|
|
10876
11146
|
let value2 = await next();
|
|
10877
11147
|
if (value2.done) break;
|
|
10878
|
-
if (!(value2.value instanceof Uint8Array) || value2.value.byteLength) throw
|
|
11148
|
+
if (!(value2.value instanceof Uint8Array) || value2.value.byteLength) throw invalid17();
|
|
10879
11149
|
}
|
|
10880
11150
|
let value = await request3((signal) => exchange(`${route}/part`, {
|
|
10881
11151
|
method: "POST",
|
|
@@ -10889,7 +11159,7 @@ async function multipartCreate(input, metadata, exchange, release, upload, expec
|
|
|
10889
11159
|
}
|
|
10890
11160
|
if (upload) for (let name4 of Object.keys(upload.file.enrichments)) {
|
|
10891
11161
|
let bytes = await request3(() => upload.enrichment(name4));
|
|
10892
|
-
if (bytes.byteLength !== upload.file.enrichments[name4].size || bytes.byteLength > MAX_BYTES) throw
|
|
11162
|
+
if (bytes.byteLength !== upload.file.enrichments[name4].size || bytes.byteLength > MAX_BYTES) throw invalid17();
|
|
10893
11163
|
await request3((signal) => exchange(`${route}/enrichments/${encodeURIComponent(name4)}`, {
|
|
10894
11164
|
method: "POST",
|
|
10895
11165
|
headers: { "content-type": "application/octet-stream", "x-os-transfer": ticket },
|
|
@@ -10931,7 +11201,7 @@ async function operation(work, initial, parent) {
|
|
|
10931
11201
|
function contentPath(id5, name4) {
|
|
10932
11202
|
let path = idPath(id5);
|
|
10933
11203
|
if (name4 === void 0) return `${path}/content`;
|
|
10934
|
-
if (!safeEnrichmentName(name4)) throw
|
|
11204
|
+
if (!safeEnrichmentName(name4)) throw invalid17();
|
|
10935
11205
|
return `${path}/enrichments/${encodeURIComponent(name4)}/content`;
|
|
10936
11206
|
}
|
|
10937
11207
|
async function read(id5, names) {
|
|
@@ -10940,12 +11210,12 @@ async function read(id5, names) {
|
|
|
10940
11210
|
let path = contentPath(id5, names);
|
|
10941
11211
|
return operation((context2, signal) => send(path, { method: "GET" }, !1, context2, signal), context);
|
|
10942
11212
|
}
|
|
10943
|
-
if (!Array.isArray(names)) throw
|
|
11213
|
+
if (!Array.isArray(names)) throw invalid17();
|
|
10944
11214
|
let distinct = [], seen = /* @__PURE__ */ new Set();
|
|
10945
11215
|
for (let name4 of names) {
|
|
10946
|
-
if (typeof name4 != "string" || !safeEnrichmentName(name4)) throw
|
|
11216
|
+
if (typeof name4 != "string" || !safeEnrichmentName(name4)) throw invalid17();
|
|
10947
11217
|
if (!seen.has(name4)) {
|
|
10948
|
-
if (seen.size === 16) throw
|
|
11218
|
+
if (seen.size === 16) throw invalid17();
|
|
10949
11219
|
seen.add(name4), distinct.push(name4);
|
|
10950
11220
|
}
|
|
10951
11221
|
}
|
|
@@ -10985,9 +11255,9 @@ var files = {
|
|
|
10985
11255
|
async create(input, options) {
|
|
10986
11256
|
let context = await resolveFilesContext();
|
|
10987
11257
|
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")))
|
|
10988
|
-
throw
|
|
11258
|
+
throw invalid17();
|
|
10989
11259
|
let blob = input.file instanceof Blob, array3 = input.file instanceof Uint8Array, stream = input.file instanceof ReadableStream;
|
|
10990
|
-
if (!blob && !array3 && !stream) throw
|
|
11260
|
+
if (!blob && !array3 && !stream) throw invalid17();
|
|
10991
11261
|
let intrinsic = blob ? input.file.size : array3 ? input.file.byteLength : void 0;
|
|
10992
11262
|
if (intrinsic !== void 0 && input.size !== void 0 && input.size !== intrinsic)
|
|
10993
11263
|
throw !Number.isSafeInteger(input.size) || input.size < 0 ? new FileOperationError("invalid_input", 400, !1, { reason: "invalid_size" }) : new FileOperationError(
|
|
@@ -11008,7 +11278,7 @@ var files = {
|
|
|
11008
11278
|
}, FILE_ORIGINAL_MAX_BYTES);
|
|
11009
11279
|
if (!context.local && !context.localFiles && metadata.storage === "local") throw new FileOperationError("unsupported_context", 400);
|
|
11010
11280
|
let header = encodeURIComponent(JSON.stringify(metadata));
|
|
11011
|
-
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw
|
|
11281
|
+
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid17();
|
|
11012
11282
|
let release = await acquireSlot(context.signal);
|
|
11013
11283
|
if (context.localFiles && !routineTransport() && metadata.size > MAX_BYTES)
|
|
11014
11284
|
try {
|
|
@@ -11059,7 +11329,7 @@ var files = {
|
|
|
11059
11329
|
},
|
|
11060
11330
|
async enrich(input) {
|
|
11061
11331
|
let context = await resolveFilesContext();
|
|
11062
|
-
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
|
|
11332
|
+
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 invalid17();
|
|
11063
11333
|
let path = `${idPath(input.file)}/enrichments`;
|
|
11064
11334
|
if (typeof input.content == "string" ? input.content.length > MAX_BYTES : input.content.byteLength > MAX_BYTES)
|
|
11065
11335
|
throw new FileOperationError("request_too_large", 413);
|
|
@@ -11076,7 +11346,7 @@ var files = {
|
|
|
11076
11346
|
...input.mediaType === void 0 ? {} : { mediaType: input.mediaType },
|
|
11077
11347
|
...input.replace === void 0 ? {} : { replace: input.replace }
|
|
11078
11348
|
}, MAX_BYTES), header = encodeURIComponent(JSON.stringify(metadata));
|
|
11079
|
-
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw
|
|
11349
|
+
if (new TextEncoder().encode(header).byteLength > METADATA_BYTES) throw invalid17();
|
|
11080
11350
|
let result2 = await send(path, { method: "POST", headers: {
|
|
11081
11351
|
"content-type": "application/octet-stream",
|
|
11082
11352
|
"x-os-enrichment": header
|
|
@@ -11761,12 +12031,17 @@ function subscribeInbox(resolve, authorize, onDirty, onState, rt = runtime, sign
|
|
|
11761
12031
|
return signal?.aborted ? revoked() : (signal?.addEventListener("abort", revoked, { once: !0 }), initialize()), stop;
|
|
11762
12032
|
}
|
|
11763
12033
|
|
|
11764
|
-
async function limitedBody(request3, limit, timeoutMs) {
|
|
12034
|
+
async function limitedBody(request3, limit, timeoutMs, signal) {
|
|
11765
12035
|
if (!request3.body) return new Uint8Array();
|
|
11766
|
-
let reader = request3.body.getReader(), expired = !1,
|
|
12036
|
+
let reader = request3.body.getReader(), expired = !1, abort = () => {
|
|
12037
|
+
expired = !0, reader.cancel(signal?.reason).catch(() => {
|
|
12038
|
+
});
|
|
12039
|
+
}, timer = timeoutMs === void 0 ? void 0 : setTimeout(() => {
|
|
11767
12040
|
expired = !0, reader.cancel().catch(() => {
|
|
11768
12041
|
});
|
|
11769
|
-
}, timeoutMs)
|
|
12042
|
+
}, timeoutMs);
|
|
12043
|
+
signal?.addEventListener("abort", abort, { once: !0 });
|
|
12044
|
+
let chunks = [], length = 0;
|
|
11770
12045
|
try {
|
|
11771
12046
|
for (; ; ) {
|
|
11772
12047
|
let { done, value } = await reader.read();
|
|
@@ -11783,7 +12058,7 @@ async function limitedBody(request3, limit, timeoutMs) {
|
|
|
11783
12058
|
contents.set(chunk, offset), offset += chunk.byteLength;
|
|
11784
12059
|
return contents;
|
|
11785
12060
|
} finally {
|
|
11786
|
-
timer !== void 0 && clearTimeout(timer);
|
|
12061
|
+
timer !== void 0 && clearTimeout(timer), signal?.removeEventListener("abort", abort);
|
|
11787
12062
|
}
|
|
11788
12063
|
}
|
|
11789
12064
|
|
|
@@ -11987,8 +12262,12 @@ async function send2(operation2, input, resolved, admitted) {
|
|
|
11987
12262
|
}
|
|
11988
12263
|
if (operation2 === "current" && parsed.workspace.slug !== context.workspace) throw unavailable5();
|
|
11989
12264
|
if ("itemId" in envelope.input) {
|
|
11990
|
-
let item = operation2 === "items.read" ? parsed : operation2 === "items.rename" || operation2 === "items.setLifecycle" || operation2 === "items.addRecipient" ? parsed.item : void 0;
|
|
12265
|
+
let item = operation2 === "items.read" ? parsed : operation2 === "items.rename" || operation2 === "items.setLifecycle" || operation2 === "items.addRecipient" || operation2 === "questions.assign" ? parsed.item : void 0;
|
|
11991
12266
|
if (item && (item.id !== envelope.input.itemId || "revision" in envelope.input && item.revision !== envelope.input.revision) || operation2 === "items.addRecipient" && parsed.addedPersonId !== envelope.input.personId) throw unavailable5();
|
|
12267
|
+
if (operation2 === "questions.assign") {
|
|
12268
|
+
let result2 = parsed;
|
|
12269
|
+
if (assertInboxAssignmentMatches(result2, envelope.input), result2.item.workspaceId !== host?.context.workspaceId || result2.previousAssigneeId !== context.memberId) throw unavailable5();
|
|
12270
|
+
}
|
|
11992
12271
|
}
|
|
11993
12272
|
return parsed;
|
|
11994
12273
|
} catch (error) {
|
|
@@ -12087,6 +12366,25 @@ var inbox = {
|
|
|
12087
12366
|
addRecipient: async (input) => await send2("items.addRecipient", input)
|
|
12088
12367
|
},
|
|
12089
12368
|
questions: {
|
|
12369
|
+
listAssignmentCandidates: async (input) => await send2("questions.listAssignmentCandidates", input),
|
|
12370
|
+
async assign(input) {
|
|
12371
|
+
let supplied = parseInboxRequest({ operation: "questions.assign", input }).input, initial;
|
|
12372
|
+
try {
|
|
12373
|
+
initial = await resolveAppContext(!1, !0);
|
|
12374
|
+
} catch (error) {
|
|
12375
|
+
throw contextFailure(error);
|
|
12376
|
+
}
|
|
12377
|
+
if (initial.kind === "local") throw new InboxOperationError(403, "access_denied");
|
|
12378
|
+
let host;
|
|
12379
|
+
try {
|
|
12380
|
+
host = await resolveHostedInboxContext(initial, "member");
|
|
12381
|
+
} catch (error) {
|
|
12382
|
+
throw hostFailure(error, initial);
|
|
12383
|
+
}
|
|
12384
|
+
if (host.context.kind !== "inbox") throw new InboxOperationError(403, "access_denied");
|
|
12385
|
+
let assignee = assignmentTargetId(supplied.assignee, INBOX_UUID.test(supplied.assignee) ? [] : await send2("questions.listAssignmentCandidates", { itemId: supplied.itemId, revision: supplied.revision, questionId: supplied.questionId }, initial, host));
|
|
12386
|
+
return await send2("questions.assign", { ...supplied, assignee }, initial, host);
|
|
12387
|
+
},
|
|
12090
12388
|
async list(input) {
|
|
12091
12389
|
let supplied = parseInboxRequest({ contract: INBOX_QUESTION_CONTRACT, operation: "questions.list", input }).input;
|
|
12092
12390
|
if (Object.hasOwn(supplied, "beforeNumber")) throw new InboxOperationError(400, "invalid_input");
|