@oddington/sdk 0.1.67 → 0.1.69
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 +543 -312
- package/dist/index.js +5 -5
- package/dist/types/packages/sdk/src/data-schema-types.d.ts +19 -3
- package/dist/types/packages/sdk/src/public.d.ts +4 -2
- package/dist/types/shared/data-contract.d.ts +31 -2
- package/dist/types/shared/data-input.d.ts +6 -0
- package/dist/types/shared/data-signals.d.ts +59 -0
- package/dist/types/shared/files-contract.d.ts +7 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -5054,6 +5054,23 @@ function isCanonicalOriginalMediaType(value) {
|
|
|
5054
5054
|
return !1;
|
|
5055
5055
|
}
|
|
5056
5056
|
}
|
|
5057
|
+
function parseFileUpdate(value) {
|
|
5058
|
+
let invalid13 = (reason = "invalid_metadata") => {
|
|
5059
|
+
throw new FileOperationError("invalid_input", 400, !1, { reason });
|
|
5060
|
+
};
|
|
5061
|
+
if (!value || typeof value != "object" || Array.isArray(value)) return invalid13();
|
|
5062
|
+
let input = value, update = {};
|
|
5063
|
+
if (!Object.keys(input).length || Object.keys(input).some((key) => !["name", "path", "mediaType"].includes(key))) return invalid13();
|
|
5064
|
+
if (Object.hasOwn(input, "name")) {
|
|
5065
|
+
if (!safeFileName(input.name)) return invalid13("invalid_name");
|
|
5066
|
+
update.name = input.name;
|
|
5067
|
+
}
|
|
5068
|
+
if (Object.hasOwn(input, "path")) {
|
|
5069
|
+
if (!safeManagedFilePath(input.path)) return invalid13("invalid_path");
|
|
5070
|
+
update.path = input.path;
|
|
5071
|
+
}
|
|
5072
|
+
return Object.hasOwn(input, "mediaType") && (update.mediaType = declaredOriginalMediaType(input.mediaType)), update;
|
|
5073
|
+
}
|
|
5057
5074
|
function parseFileCreateMetadata(value, maxBytes) {
|
|
5058
5075
|
let invalid13 = (reason = "invalid_metadata") => {
|
|
5059
5076
|
throw new FileOperationError("invalid_input", 400, !1, { reason });
|
|
@@ -5172,39 +5189,39 @@ function jsonData(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
5172
5189
|
function validateRoutineSchemaValue(schema2, value, rejected) {
|
|
5173
5190
|
let type = (value2) => value2 === null ? "null" : Array.isArray(value2) ? "array" : ["object", "boolean", "string", "number"].includes(typeof value2) ? typeof value2 : "other";
|
|
5174
5191
|
function check(schema3, value2, path) {
|
|
5175
|
-
let
|
|
5192
|
+
let fail8 = (reason, extra = {}) => (rejected?.({ reason, path: path.length <= 256 ? path : "$", expected: schema3.type, received: type(value2), ...extra }), invalidValue());
|
|
5176
5193
|
switch (schema3.type) {
|
|
5177
5194
|
case "object":
|
|
5178
|
-
if (!record(value2)) return
|
|
5179
|
-
for (let key of schema3.required ?? []) if (!owns(value2, key)) return
|
|
5195
|
+
if (!record(value2)) return fail8("wrong_type");
|
|
5196
|
+
for (let key of schema3.required ?? []) if (!owns(value2, key)) return fail8("missing_field", {
|
|
5180
5197
|
path: `${path}.${key}`.length <= 256 ? `${path}.${key}` : "$",
|
|
5181
5198
|
expected: schema3.properties[key].type,
|
|
5182
5199
|
received: "missing"
|
|
5183
5200
|
});
|
|
5184
|
-
if (Object.keys(value2).some((key) => !owns(schema3.properties, key))) return
|
|
5201
|
+
if (Object.keys(value2).some((key) => !owns(schema3.properties, key))) return fail8("unexpected_field");
|
|
5185
5202
|
for (let [key, child] of Object.entries(value2)) check(schema3.properties[key], child, `${path}.${key}`);
|
|
5186
5203
|
return;
|
|
5187
5204
|
case "array":
|
|
5188
|
-
if (!denseArray(value2)) return
|
|
5205
|
+
if (!denseArray(value2)) return fail8("wrong_type");
|
|
5189
5206
|
if (schema3.maxItems !== void 0 && value2.length > schema3.maxItems)
|
|
5190
|
-
return
|
|
5207
|
+
return fail8("out_of_bounds", { constraint: "maxItems", limit: schema3.maxItems });
|
|
5191
5208
|
value2.forEach((child, index) => check(schema3.items, child, `${path}[${index}]`));
|
|
5192
5209
|
return;
|
|
5193
5210
|
case "boolean":
|
|
5194
|
-
return typeof value2 != "boolean" ?
|
|
5211
|
+
return typeof value2 != "boolean" ? fail8("wrong_type") : void 0;
|
|
5195
5212
|
case "string":
|
|
5196
|
-
return typeof value2 != "string" ?
|
|
5213
|
+
return typeof value2 != "string" ? fail8("wrong_type") : Array.from(value2).length > (schema3.maxLength ?? 4096) ? fail8("out_of_bounds", { constraint: "maxLength", limit: schema3.maxLength ?? 4096 }) : void 0;
|
|
5197
5214
|
case "integer":
|
|
5198
5215
|
case "number":
|
|
5199
|
-
return typeof value2 != "number" || !(schema3.type === "integer" ? Number.isSafeInteger(value2) : Number.isFinite(value2)) ?
|
|
5216
|
+
return typeof value2 != "number" || !(schema3.type === "integer" ? Number.isSafeInteger(value2) : Number.isFinite(value2)) ? fail8("wrong_type") : schema3.minimum !== void 0 && value2 < schema3.minimum ? fail8("out_of_bounds", { constraint: "minimum", limit: schema3.minimum }) : schema3.maximum !== void 0 && value2 > schema3.maximum ? fail8("out_of_bounds", { constraint: "maximum", limit: schema3.maximum }) : void 0;
|
|
5200
5217
|
case "file": {
|
|
5201
5218
|
let file2;
|
|
5202
5219
|
try {
|
|
5203
5220
|
jsonData(value2), file2 = parseFileDescriptor(value2);
|
|
5204
5221
|
} catch {
|
|
5205
|
-
return
|
|
5222
|
+
return fail8("invalid_file");
|
|
5206
5223
|
}
|
|
5207
|
-
if (schema3.path !== void 0 && file2.path !== schema3.path) return
|
|
5224
|
+
if (schema3.path !== void 0 && file2.path !== schema3.path) return fail8("invalid_file");
|
|
5208
5225
|
}
|
|
5209
5226
|
}
|
|
5210
5227
|
}
|
|
@@ -6488,9 +6505,9 @@ function captureRecordsReadOptions(value) {
|
|
|
6488
6505
|
} catch {
|
|
6489
6506
|
throw new DataOperationError("invalid_query");
|
|
6490
6507
|
}
|
|
6491
|
-
if (!value || typeof value != "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)) || Reflect.ownKeys(value).some((key) => key !== "body") || Object.
|
|
6508
|
+
if (!value || typeof value != "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)) || Reflect.ownKeys(value).some((key) => key !== "body" && key !== "timeline") || Object.values(value).some((option) => option !== !0))
|
|
6492
6509
|
throw new DataOperationError("invalid_query");
|
|
6493
|
-
return Object.hasOwn(value, "body") ? { body: !0 } : {};
|
|
6510
|
+
return { ...Object.hasOwn(value, "body") ? { body: !0 } : {}, ...Object.hasOwn(value, "timeline") ? { timeline: !0 } : {} };
|
|
6494
6511
|
}
|
|
6495
6512
|
|
|
6496
6513
|
function capture3(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
@@ -6530,23 +6547,116 @@ function validRecordBody(value) {
|
|
|
6530
6547
|
}
|
|
6531
6548
|
var RECORD_BODY_READ_BYTES = 8 * 1024 * 1024;
|
|
6532
6549
|
|
|
6533
|
-
var
|
|
6550
|
+
var fail2 = () => {
|
|
6534
6551
|
throw new DataOperationError("invalid_change", !1, "unapplied");
|
|
6535
6552
|
};
|
|
6536
6553
|
function mapping(value) {
|
|
6554
|
+
try {
|
|
6555
|
+
return dataProperties(value), value;
|
|
6556
|
+
} catch {
|
|
6557
|
+
return fail2();
|
|
6558
|
+
}
|
|
6559
|
+
}
|
|
6560
|
+
var validSignalKey = (value) => typeof value == "string" && /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(value), validSignalText = (value) => typeof value == "string" && !!value.trim() && !/[\r\n\u0000\uD800-\uDFFF]/u.test(value);
|
|
6561
|
+
function validSignalInstant(value) {
|
|
6562
|
+
if (typeof value != "string") return !1;
|
|
6563
|
+
let match = /^(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)(?:\.(\d+))?Z$/.exec(value);
|
|
6564
|
+
if (!match) return !1;
|
|
6565
|
+
let normalized = `${match[1]}.${(match[2] ?? "").padEnd(3, "0").slice(0, 3)}Z`;
|
|
6566
|
+
return Number.isFinite(Date.parse(normalized)) && new Date(normalized).toISOString() === normalized;
|
|
6567
|
+
}
|
|
6568
|
+
var positive = (value) => Number.isSafeInteger(value) && Number(value) > 0;
|
|
6569
|
+
function references(value, compact) {
|
|
6570
|
+
if (value === void 0 && compact) return [];
|
|
6571
|
+
if (!Array.isArray(value)) return fail2();
|
|
6572
|
+
let items;
|
|
6573
|
+
try {
|
|
6574
|
+
items = dataArray(value);
|
|
6575
|
+
} catch {
|
|
6576
|
+
return fail2();
|
|
6577
|
+
}
|
|
6578
|
+
return items.map((item) => {
|
|
6579
|
+
let row = mapping(item), keys7 = Object.keys(row).sort().join(",");
|
|
6580
|
+
if (compact) {
|
|
6581
|
+
if (keys7 === "record" && validRecordRef(row.record)) return { type: "record", ref: row.record };
|
|
6582
|
+
if (keys7 === "ask" && positive(row.ask)) return { type: "ask", number: row.ask };
|
|
6583
|
+
if (keys7 === "signal") {
|
|
6584
|
+
let signal = mapping(row.signal);
|
|
6585
|
+
if (Object.keys(signal).sort().join(",") === "number,record" && validRecordRef(signal.record) && positive(signal.number))
|
|
6586
|
+
return { type: "signal", record: signal.record, number: signal.number };
|
|
6587
|
+
}
|
|
6588
|
+
} else {
|
|
6589
|
+
if (keys7 === "ref,type" && row.type === "record" && validRecordRef(row.ref)) return { type: "record", ref: row.ref };
|
|
6590
|
+
if (keys7 === "number,type" && row.type === "ask" && positive(row.number)) return { type: "ask", number: row.number };
|
|
6591
|
+
if (keys7 === "number,record,type" && row.type === "signal" && validRecordRef(row.record) && positive(row.number))
|
|
6592
|
+
return { type: "signal", record: row.record, number: row.number };
|
|
6593
|
+
}
|
|
6594
|
+
return fail2();
|
|
6595
|
+
});
|
|
6596
|
+
}
|
|
6597
|
+
function captureSignal(value, acceptedAt) {
|
|
6598
|
+
let row = mapping(value), compact = acceptedAt !== void 0;
|
|
6599
|
+
return Object.keys(row).some((key) => !["key", "label", "status", "reason", "related", ...compact ? [] : ["asOf"]].includes(key)) || !validSignalKey(row.key) || !validSignalText(row.label) || !validSignalText(row.status) || row.reason !== void 0 && (typeof row.reason != "string" || /[\r\n\u0000\uD800-\uDFFF]/u.test(row.reason)) || !validSignalInstant(acceptedAt ?? row.asOf) ? fail2() : {
|
|
6600
|
+
key: row.key,
|
|
6601
|
+
label: row.label,
|
|
6602
|
+
status: row.status,
|
|
6603
|
+
...row.reason ? { reason: row.reason } : {},
|
|
6604
|
+
related: references(row.related, compact),
|
|
6605
|
+
asOf: acceptedAt ?? row.asOf
|
|
6606
|
+
};
|
|
6607
|
+
}
|
|
6608
|
+
function captureTimeline(value, compact = !1) {
|
|
6609
|
+
let row = mapping(value);
|
|
6610
|
+
return Object.keys(row).some((key) => !["when", "event", "activity", "related"].includes(key)) || !validSignalInstant(row.when) || !validSignalText(row.activity) || row.event !== void 0 && !validSignalKey(row.event) ? fail2() : { when: row.when, ...row.event !== void 0 ? { event: row.event } : {}, activity: row.activity, related: references(row.related, compact) };
|
|
6611
|
+
}
|
|
6612
|
+
function captureRecordSignal(value) {
|
|
6613
|
+
let row = mapping(value), { number, ...assessment } = row;
|
|
6614
|
+
return positive(number) ? { number, ...captureSignal(assessment) } : fail2();
|
|
6615
|
+
}
|
|
6616
|
+
function captureRecordSignals(value) {
|
|
6617
|
+
if (!Array.isArray(value)) return fail2();
|
|
6618
|
+
let rows = dataArray(value).map(captureRecordSignal);
|
|
6619
|
+
return new Set(rows.map((row) => row.key)).size !== rows.length || new Set(rows.map((row) => row.number)).size !== rows.length ? fail2() : rows;
|
|
6620
|
+
}
|
|
6621
|
+
|
|
6622
|
+
var DATA_REQUEST_LIMIT = 256 * 1024, LOCAL_DATA_CHANGE_REQUEST_LIMIT = 32 * 1024 * 1024, invalidChange = () => {
|
|
6623
|
+
throw new DataOperationError("invalid_change", !1, "unapplied");
|
|
6624
|
+
};
|
|
6625
|
+
function mapping2(value) {
|
|
6537
6626
|
try {
|
|
6538
6627
|
return dataProperties(value), value;
|
|
6539
6628
|
} catch {
|
|
6540
6629
|
return invalidChange();
|
|
6541
6630
|
}
|
|
6542
6631
|
}
|
|
6632
|
+
function captureDataTables(value) {
|
|
6633
|
+
let row = mapping2(value), result2 = {};
|
|
6634
|
+
if (Object.hasOwn(row, "signals")) {
|
|
6635
|
+
if (!Array.isArray(row.signals) || !row.signals.length || row.signals.length > 1e4) return invalidChange();
|
|
6636
|
+
try {
|
|
6637
|
+
result2.signals = dataArray(row.signals).map((value2) => captureSignal(value2));
|
|
6638
|
+
} catch {
|
|
6639
|
+
return invalidChange();
|
|
6640
|
+
}
|
|
6641
|
+
if (new Set(result2.signals.map((value2) => value2.key)).size !== result2.signals.length) return invalidChange();
|
|
6642
|
+
}
|
|
6643
|
+
if (Object.hasOwn(row, "timeline")) {
|
|
6644
|
+
if (!Array.isArray(row.timeline) || !row.timeline.length || row.timeline.length > 1e4) return invalidChange();
|
|
6645
|
+
try {
|
|
6646
|
+
result2.timeline = dataArray(row.timeline).map((value2) => captureTimeline(value2));
|
|
6647
|
+
} catch {
|
|
6648
|
+
return invalidChange();
|
|
6649
|
+
}
|
|
6650
|
+
}
|
|
6651
|
+
return result2;
|
|
6652
|
+
}
|
|
6543
6653
|
function captureDataChangeOptions(value) {
|
|
6544
6654
|
if (value === void 0) return {};
|
|
6545
|
-
let options =
|
|
6655
|
+
let options = mapping2(value);
|
|
6546
6656
|
if (Object.keys(options).some((key) => !["summary", "source"].includes(key))) return invalidChange();
|
|
6547
6657
|
let line = (value2) => !dataText(value2) || !value2.trim().length || [...value2].length > 120 || /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(value2) ? invalidChange() : value2, captured = {};
|
|
6548
6658
|
if (Object.hasOwn(options, "summary") && (captured.summary = line(options.summary)), Object.hasOwn(options, "source")) {
|
|
6549
|
-
let source2 =
|
|
6659
|
+
let source2 = mapping2(options.source);
|
|
6550
6660
|
if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine") return invalidChange();
|
|
6551
6661
|
captured.source = { kind: source2.kind, id: line(source2.id) };
|
|
6552
6662
|
}
|
|
@@ -6557,30 +6667,30 @@ function captureValue(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
6557
6667
|
if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) return invalidChange();
|
|
6558
6668
|
ancestors.add(value);
|
|
6559
6669
|
try {
|
|
6560
|
-
return Array.isArray(value) ? value.length > 1e5 || Object.keys(value).length !== value.length || Object.getOwnPropertySymbols(value).length ? invalidChange() : Array.from(value, (item) => captureValue(item, ancestors, depth + 1)) : Object.fromEntries(Object.entries(
|
|
6670
|
+
return Array.isArray(value) ? value.length > 1e5 || Object.keys(value).length !== value.length || Object.getOwnPropertySymbols(value).length ? invalidChange() : Array.from(value, (item) => captureValue(item, ancestors, depth + 1)) : Object.fromEntries(Object.entries(mapping2(value)).map(([key, item]) => ["__proto__", "constructor", "prototype"].includes(key) ? invalidChange() : [key, captureValue(item, ancestors, depth + 1)]));
|
|
6561
6671
|
} finally {
|
|
6562
6672
|
ancestors.delete(value);
|
|
6563
6673
|
}
|
|
6564
6674
|
}
|
|
6565
6675
|
function captureDataDelete(record4) {
|
|
6566
|
-
let identity =
|
|
6676
|
+
let identity = mapping2(record4);
|
|
6567
6677
|
return !validRecordRef(identity.$ref) || typeof identity.$version != "string" || !identity.$version.length || identity.$version.length > 512 ? invalidChange() : { ref: identity.$ref, expectedVersion: identity.$version };
|
|
6568
6678
|
}
|
|
6569
6679
|
function captureDataUpdate(record4, set) {
|
|
6570
6680
|
if (!validRecordRef(record4)) return invalidChange();
|
|
6571
|
-
let input =
|
|
6681
|
+
let input = mapping2(set), { $body, ...fields4 } = input, body = Object.hasOwn(input, "$body");
|
|
6572
6682
|
return body && !validRecordBody($body) || !Object.keys(fields4).length && !body || Object.keys(fields4).some((key) => key.startsWith("$") || ["id", "type"].includes(key)) ? invalidChange() : { ref: record4, set: captureValue(fields4), ...body ? { body: $body } : {} };
|
|
6573
6683
|
}
|
|
6574
6684
|
function captureIdentities(value, update, allowEmpty = !0) {
|
|
6575
6685
|
if (!Array.isArray(value) || !allowEmpty && !value.length || value.length > 1e4) return invalidChange();
|
|
6576
6686
|
let captured = value.map((item) => {
|
|
6577
|
-
let row =
|
|
6578
|
-
if (Object.keys(row).filter((key) => !update || !["body", "expectedVersion"].includes(key)).sort().join(",") !== (update ? "ref,set" : "expectedVersion,ref")) return invalidChange();
|
|
6687
|
+
let row = mapping2(item);
|
|
6688
|
+
if (Object.keys(row).filter((key) => !update || !["body", "expectedVersion", "signals", "timeline"].includes(key)).sort().join(",") !== (update ? "ref,set" : "expectedVersion,ref")) return invalidChange();
|
|
6579
6689
|
let identity = { $ref: row.ref, $version: row.expectedVersion };
|
|
6580
|
-
if (update && Object.keys(
|
|
6690
|
+
if (update && Object.keys(mapping2(row.set)).some((key) => key.startsWith("$"))) return invalidChange();
|
|
6581
6691
|
if (!update) return captureDataDelete(identity);
|
|
6582
|
-
let
|
|
6583
|
-
return Object.hasOwn(row, "
|
|
6692
|
+
let tables = captureDataTables(row);
|
|
6693
|
+
return { ...Object.keys(mapping2(row.set)).length || Object.hasOwn(row, "body") ? captureDataUpdate(row.ref, { ...mapping2(row.set), ...Object.hasOwn(row, "body") ? { $body: row.body } : {} }) : validRecordRef(row.ref) && Object.keys(tables).length ? { ref: row.ref, set: {} } : invalidChange(), ...tables, ...Object.hasOwn(row, "expectedVersion") ? { expectedVersion: captureDataDelete(identity).expectedVersion } : {} };
|
|
6584
6694
|
});
|
|
6585
6695
|
return new Set(captured.map((item) => item.ref)).size !== captured.length ? invalidChange() : captured;
|
|
6586
6696
|
}
|
|
@@ -6588,14 +6698,14 @@ function captureDataUpdates(value, allowEmpty = !1) {
|
|
|
6588
6698
|
return captureIdentities(value, !0, allowEmpty);
|
|
6589
6699
|
}
|
|
6590
6700
|
function captureDataCreate(value) {
|
|
6591
|
-
let row =
|
|
6701
|
+
let row = mapping2(value);
|
|
6592
6702
|
if (!validRecordRef(row.$ref) || Object.keys(row).some((key) => key.startsWith("$") && !["$ref", "$filing", "$body"].includes(key)))
|
|
6593
6703
|
return invalidChange();
|
|
6594
6704
|
let { $ref: ref, $filing, $body, ...fields4 } = row, body = Object.hasOwn(row, "$body");
|
|
6595
6705
|
if (body && !validRecordBody($body)) return invalidChange();
|
|
6596
6706
|
let filing;
|
|
6597
6707
|
if ($filing !== void 0) {
|
|
6598
|
-
let components =
|
|
6708
|
+
let components = mapping2($filing);
|
|
6599
6709
|
if (Object.entries(components).some(([name2, value2]) => !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(name2) || ["constructor", "prototype"].includes(name2) || typeof value2 != "string" || !/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(value2)))
|
|
6600
6710
|
return invalidChange();
|
|
6601
6711
|
filing = { ...components };
|
|
@@ -6606,15 +6716,15 @@ function captureDataChanges(updatesValue, createsValue = [], deletesValue = [])
|
|
|
6606
6716
|
let updates = captureDataUpdates(updatesValue, !0);
|
|
6607
6717
|
if (!Array.isArray(createsValue) || createsValue.length > 1e4) return invalidChange();
|
|
6608
6718
|
let creates = createsValue.map((item) => {
|
|
6609
|
-
let row =
|
|
6610
|
-
if (Object.keys(row).some((key) => !["ref", "fields", "filing", "body"].includes(key)) || !Object.hasOwn(row, "ref") || !Object.hasOwn(row, "fields")) return invalidChange();
|
|
6611
|
-
let fields4 =
|
|
6612
|
-
return Object.keys(fields4).some((key) => key.startsWith("$")) ? invalidChange() : captureDataCreate({
|
|
6719
|
+
let row = mapping2(item);
|
|
6720
|
+
if (Object.keys(row).some((key) => !["ref", "fields", "filing", "body", "signals", "timeline"].includes(key)) || !Object.hasOwn(row, "ref") || !Object.hasOwn(row, "fields")) return invalidChange();
|
|
6721
|
+
let fields4 = mapping2(row.fields);
|
|
6722
|
+
return Object.keys(fields4).some((key) => key.startsWith("$")) ? invalidChange() : { ...captureDataCreate({
|
|
6613
6723
|
...fields4,
|
|
6614
6724
|
$ref: row.ref,
|
|
6615
6725
|
...Object.hasOwn(row, "filing") ? { $filing: row.filing } : {},
|
|
6616
6726
|
...Object.hasOwn(row, "body") ? { $body: row.body } : {}
|
|
6617
|
-
});
|
|
6727
|
+
}), ...captureDataTables(row) };
|
|
6618
6728
|
}), deletes = captureIdentities(deletesValue, !1), refs = [...updates, ...creates, ...deletes].map((item) => item.ref);
|
|
6619
6729
|
return !refs.length || refs.length > 1e4 || new Set(refs).size !== refs.length ? invalidChange() : { updates, creates, deletes };
|
|
6620
6730
|
}
|
|
@@ -6868,22 +6978,22 @@ function fieldExpectation(field) {
|
|
|
6868
6978
|
};
|
|
6869
6979
|
}
|
|
6870
6980
|
var NAME = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
6871
|
-
function
|
|
6981
|
+
function fail3(message2) {
|
|
6872
6982
|
throw new RecordValidationError(message2);
|
|
6873
6983
|
}
|
|
6874
6984
|
function validateRecordText(value) {
|
|
6875
|
-
/[\u0000\uD800-\uDFFF]/u.test(value) &&
|
|
6985
|
+
/[\u0000\uD800-\uDFFF]/u.test(value) && fail3("Record text must contain Unicode scalar values excluding U+0000");
|
|
6876
6986
|
}
|
|
6877
6987
|
function object3(value) {
|
|
6878
|
-
return (!value || typeof value != "object" || Array.isArray(value)) &&
|
|
6988
|
+
return (!value || typeof value != "object" || Array.isArray(value)) && fail3("Expected a field mapping"), value;
|
|
6879
6989
|
}
|
|
6880
6990
|
function keys2(row, allowed, required) {
|
|
6881
|
-
(Object.keys(row).some((key) => !allowed.includes(key)) || required.some((key) => !Object.hasOwn(row, key))) &&
|
|
6991
|
+
(Object.keys(row).some((key) => !allowed.includes(key)) || required.some((key) => !Object.hasOwn(row, key))) && fail3("Unsupported or missing schema/record fields");
|
|
6882
6992
|
}
|
|
6883
6993
|
function valueDefinition(value, depth, native, named = !1) {
|
|
6884
|
-
depth > 8 &&
|
|
6994
|
+
depth > 8 && fail3("Invalid field definitions");
|
|
6885
6995
|
let row = { ...object3(value) };
|
|
6886
|
-
switch (["enum_list", "links", "list"].includes(String(row.kind)) && row.many !== void 0 && row.many !== !0 &&
|
|
6996
|
+
switch (["enum_list", "links", "list"].includes(String(row.kind)) && row.many !== void 0 && row.many !== !0 && fail3("Conflicting cardinality"), Object.hasOwn(row, "inline") && ((row.kind !== "list" || typeof row.inline != "boolean" || Object.hasOwn(row, "style")) && fail3("Unsupported or conflicting inline style"), row.inline && (row.style = "inline"), delete row.inline), row.kind) {
|
|
6887
6997
|
case "bool":
|
|
6888
6998
|
row.kind = "boolean";
|
|
6889
6999
|
break;
|
|
@@ -6897,19 +7007,19 @@ function valueDefinition(value, depth, native, named = !1) {
|
|
|
6897
7007
|
row.kind = "link", row.many = !0;
|
|
6898
7008
|
break;
|
|
6899
7009
|
case "month":
|
|
6900
|
-
row.format !== void 0 && row.format !== "month" &&
|
|
7010
|
+
row.format !== void 0 && row.format !== "month" && fail3("Conflicting date format"), row.kind = "date", row.format = "month";
|
|
6901
7011
|
break;
|
|
6902
7012
|
case "list": {
|
|
6903
|
-
Object.hasOwn(row, "items") && Object.hasOwn(row, "fields") &&
|
|
7013
|
+
Object.hasOwn(row, "items") && Object.hasOwn(row, "fields") && fail3("Conflicting list definitions");
|
|
6904
7014
|
let nested = Object.hasOwn(row, "items") ? row.items : row.fields;
|
|
6905
7015
|
row.kind = nested === void 0 ? "string" : "object", row.many = !0, Object.hasOwn(row, "items") && delete row.items, nested !== void 0 && (row.fields = nested);
|
|
6906
7016
|
break;
|
|
6907
7017
|
}
|
|
6908
7018
|
case "map":
|
|
6909
|
-
(Object.hasOwn(row, "keys") || Object.hasOwn(row, "values")) && ((Object.hasOwn(row, "key") || Object.hasOwn(row, "value") || row.keys !== "YYYY-MM" || row.values !== "number") &&
|
|
7019
|
+
(Object.hasOwn(row, "keys") || Object.hasOwn(row, "values")) && ((Object.hasOwn(row, "key") || Object.hasOwn(row, "value") || row.keys !== "YYYY-MM" || row.values !== "number") && fail3("Unsupported or conflicting map definitions"), row.key = { kind: "date", format: "month" }, row.value = { kind: "number", ...Object.hasOwn(row, "precision") ? { precision: row.precision } : {} }, delete row.keys, delete row.values, delete row.precision);
|
|
6910
7020
|
break;
|
|
6911
7021
|
}
|
|
6912
|
-
row.nullable !== void 0 && typeof row.nullable != "boolean" &&
|
|
7022
|
+
row.nullable !== void 0 && typeof row.nullable != "boolean" && fail3("Invalid nullability"), row.many !== void 0 && typeof row.many != "boolean" && fail3("Invalid cardinality"), ["description", "term"].some((key) => row[key] !== void 0 && typeof row[key] != "string") && fail3("Invalid field documentation");
|
|
6913
7023
|
let base = {
|
|
6914
7024
|
nullable: row.nullable === !0,
|
|
6915
7025
|
many: row.many === !0,
|
|
@@ -6918,7 +7028,7 @@ function valueDefinition(value, depth, native, named = !1) {
|
|
|
6918
7028
|
...typeof row.term == "string" ? { term: row.term } : {},
|
|
6919
7029
|
...row.style === "inline" ? { style: "inline" } : {}
|
|
6920
7030
|
};
|
|
6921
|
-
row.style !== void 0 && (row.style !== "inline" || !base.many) &&
|
|
7031
|
+
row.style !== void 0 && (row.style !== "inline" || !base.many) && fail3("Unsupported storage style");
|
|
6922
7032
|
let common = ["kind", "nullable", "many", "style", "description", "term", ...named ? ["name"] : []], check = (owned = []) => keys2(row, [...common, ...owned], ["kind", ...owned]);
|
|
6923
7033
|
switch (row.kind) {
|
|
6924
7034
|
case "string":
|
|
@@ -6927,35 +7037,35 @@ function valueDefinition(value, depth, native, named = !1) {
|
|
|
6927
7037
|
case "datetime":
|
|
6928
7038
|
return check(), { ...base, kind: row.kind };
|
|
6929
7039
|
case "number":
|
|
6930
|
-
return keys2(row, [...common, "precision"], ["kind"]), row.precision !== void 0 && (!Number.isInteger(row.precision) || Number(row.precision) < 0 || Number(row.precision) > 6) &&
|
|
7040
|
+
return keys2(row, [...common, "precision"], ["kind"]), row.precision !== void 0 && (!Number.isInteger(row.precision) || Number(row.precision) < 0 || Number(row.precision) > 6) && fail3("Unsupported decimal precision"), { ...base, kind: "number", ...row.precision !== void 0 ? { precision: row.precision } : {} };
|
|
6931
7041
|
case "date":
|
|
6932
|
-
return keys2(row, [...common, "format"], ["kind"]), row.format !== void 0 && row.format !== "month" &&
|
|
7042
|
+
return keys2(row, [...common, "format"], ["kind"]), row.format !== void 0 && row.format !== "month" && fail3("Unsupported date format"), { ...base, kind: "date", ...row.format === "month" ? { format: "month" } : {} };
|
|
6933
7043
|
case "const":
|
|
6934
|
-
return check(["value"]), (base.many || !["string", "number", "boolean"].includes(typeof row.value) || typeof row.value == "number" && !Number.isFinite(row.value)) &&
|
|
7044
|
+
return check(["value"]), (base.many || !["string", "number", "boolean"].includes(typeof row.value) || typeof row.value == "number" && !Number.isFinite(row.value)) && fail3("Invalid constant"), { ...base, kind: "const", value: row.value };
|
|
6935
7045
|
case "enum":
|
|
6936
7046
|
case "link": {
|
|
6937
7047
|
let property = row.kind === "enum" ? "values" : "to";
|
|
6938
7048
|
check([property]);
|
|
6939
7049
|
let list2 = row.kind === "link" && typeof row.to == "string" ? [row.to] : row[property];
|
|
6940
|
-
return (!Array.isArray(list2) || !list2.length || list2.length > 1e5 || new Set(list2).size !== list2.length || list2.some((item) => typeof item != "string" || !item || row.kind === "link" && !NAME.test(item))) &&
|
|
7050
|
+
return (!Array.isArray(list2) || !list2.length || list2.length > 1e5 || new Set(list2).size !== list2.length || list2.some((item) => typeof item != "string" || !item || row.kind === "link" && !NAME.test(item))) && fail3("Invalid enum/link definition"), row.kind === "enum" ? { ...base, kind: "enum", values: list2 } : { ...base, kind: "link", to: list2 };
|
|
6941
7051
|
}
|
|
6942
7052
|
case "object":
|
|
6943
7053
|
return check(["fields"]), { ...base, kind: "object", fields: fields2(row.fields, depth + 1, native) };
|
|
6944
7054
|
case "map": {
|
|
6945
7055
|
check(["key", "value"]);
|
|
6946
7056
|
let key = valueDefinition(row.key, depth + 1, native), value2 = valueDefinition(row.value, depth + 1, native);
|
|
6947
|
-
return (!["string", "integer", "date", "enum"].includes(key.kind) || key.nullable || key.many) &&
|
|
7057
|
+
return (!["string", "integer", "date", "enum"].includes(key.kind) || key.nullable || key.many) && fail3("Unsupported map key definition"), { ...base, kind: "map", key, value: value2 };
|
|
6948
7058
|
}
|
|
6949
7059
|
default:
|
|
6950
|
-
return
|
|
7060
|
+
return fail3("Unsupported field kind");
|
|
6951
7061
|
}
|
|
6952
7062
|
}
|
|
6953
7063
|
function fields2(value, depth = 0, native = !1) {
|
|
6954
|
-
(depth > 8 || !Array.isArray(value) || !value.length || value.length > 256) &&
|
|
7064
|
+
(depth > 8 || !Array.isArray(value) || !value.length || value.length > 256) && fail3("Invalid field definitions");
|
|
6955
7065
|
let names = /* @__PURE__ */ new Set();
|
|
6956
7066
|
return value.map((definition) => {
|
|
6957
7067
|
let row = object3(definition);
|
|
6958
|
-
return (typeof row.name != "string" || !NAME.test(row.name) || ["constructor", "prototype"].includes(row.name) || names.has(row.name)) &&
|
|
7068
|
+
return (typeof row.name != "string" || !NAME.test(row.name) || ["constructor", "prototype"].includes(row.name) || names.has(row.name)) && fail3("Invalid or duplicate field name"), names.add(row.name), { name: row.name, ...valueDefinition(row, depth, native, !0) };
|
|
6959
7069
|
});
|
|
6960
7070
|
}
|
|
6961
7071
|
function validateRecordFields(value, definitions2, resolveLink, canonical = !1) {
|
|
@@ -7023,11 +7133,11 @@ function validateRecordFields(value, definitions2, resolveLink, canonical = !1)
|
|
|
7023
7133
|
case "map": {
|
|
7024
7134
|
if (!value2 || typeof value2 != "object" || Array.isArray(value2)) break;
|
|
7025
7135
|
let entries = Object.entries(value2);
|
|
7026
|
-
entries.length > 1e5 &&
|
|
7136
|
+
entries.length > 1e5 && fail3("Record map is too large");
|
|
7027
7137
|
for (let [key, entry] of entries) {
|
|
7028
|
-
["<<", "__proto__", "constructor", "prototype"].includes(key) &&
|
|
7138
|
+
["<<", "__proto__", "constructor", "prototype"].includes(key) && fail3("Unsupported record map key");
|
|
7029
7139
|
let keyValue = field.key.kind === "integer" ? Number(key) : key;
|
|
7030
|
-
field.key.kind === "integer" && String(keyValue) !== key &&
|
|
7140
|
+
field.key.kind === "integer" && String(keyValue) !== key && fail3("Invalid integer map key"), validateRecordFields({ key: keyValue }, [{ ...field.key, name: "key" }], resolveLink, canonical), validateRecordFields({ value: entry }, [{ ...field.value, name: "value" }], resolveLink, canonical);
|
|
7031
7141
|
}
|
|
7032
7142
|
valid = !0;
|
|
7033
7143
|
break;
|
|
@@ -7037,11 +7147,11 @@ function validateRecordFields(value, definitions2, resolveLink, canonical = !1)
|
|
|
7037
7147
|
}
|
|
7038
7148
|
}
|
|
7039
7149
|
|
|
7040
|
-
var boundOperators = ["$gt", "$gte", "$lt", "$lte"], compare = (a, b) => a < b ? -1 : a > b ? 1 : 0,
|
|
7150
|
+
var boundOperators = ["$gt", "$gte", "$lt", "$lte"], compare = (a, b) => a < b ? -1 : a > b ? 1 : 0, fail4 = (message2) => {
|
|
7041
7151
|
throw new RecordValidationError(`Invalid Records query: ${message2}`);
|
|
7042
7152
|
};
|
|
7043
|
-
function
|
|
7044
|
-
return !value || typeof value != "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)) ?
|
|
7153
|
+
function mapping3(value) {
|
|
7154
|
+
return !value || typeof value != "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)) ? fail4("expected a mapping") : value;
|
|
7045
7155
|
}
|
|
7046
7156
|
function publicDefinition(field) {
|
|
7047
7157
|
let { optional: _optional, style: _style, ...definition } = field;
|
|
@@ -7057,83 +7167,101 @@ function publicField(field) {
|
|
|
7057
7167
|
function scalarField(name2, schema2) {
|
|
7058
7168
|
if (name2 === "$ref") return { name: name2, kind: "string", nullable: !1, many: !1 };
|
|
7059
7169
|
let field = schema2.fields.find((field2) => field2.name === name2);
|
|
7060
|
-
return !field || field.many || field.kind === "object" || field.kind === "map" ?
|
|
7170
|
+
return !field || field.many || field.kind === "object" || field.kind === "map" ? fail4(`ineligible scalar field: ${name2}`) : field;
|
|
7061
7171
|
}
|
|
7062
7172
|
function conditionValue(value, field) {
|
|
7063
|
-
return (field.kind === "link" || field.name === "$ref") && value !== null && !(field.kind === "link" ? parseRecordLink(value) : validRecordRef(value)) ?
|
|
7173
|
+
return (field.kind === "link" || field.name === "$ref") && value !== null && !(field.kind === "link" ? parseRecordLink(value) : validRecordRef(value)) ? fail4(`invalid reference: ${field.name}`) : (validateRecordFields(
|
|
7064
7174
|
{ [field.name]: field.kind === "link" && typeof value == "string" ? `[[${value}]]` : value },
|
|
7065
7175
|
[{ ...field, optional: !1 }]
|
|
7066
7176
|
), value);
|
|
7067
7177
|
}
|
|
7068
7178
|
function queryEntries(query) {
|
|
7069
|
-
let entries = Object.entries(
|
|
7179
|
+
let entries = Object.entries(mapping3(query));
|
|
7070
7180
|
return preflightSelections(entries), entries;
|
|
7071
7181
|
}
|
|
7072
7182
|
function preflightSelections(entries) {
|
|
7073
|
-
if (entries.length < 1 || entries.length > 16) return
|
|
7183
|
+
if (entries.length < 1 || entries.length > 16) return fail4("expected 1\u201316 collections");
|
|
7074
7184
|
let nodes = 0, visit = (value, depth) => {
|
|
7075
|
-
if (++nodes > 256) return
|
|
7076
|
-
let selection2 =
|
|
7185
|
+
if (++nodes > 256) return fail4("too many selection nodes");
|
|
7186
|
+
let selection2 = mapping3(value);
|
|
7077
7187
|
for (let [name2, nested] of Object.entries(selection2))
|
|
7078
7188
|
if (name2 !== "$") {
|
|
7079
|
-
if (depth >= 4) return
|
|
7189
|
+
if (depth >= 4) return fail4("too many link levels");
|
|
7080
7190
|
visit(nested, depth + 1);
|
|
7081
7191
|
}
|
|
7082
7192
|
};
|
|
7083
7193
|
for (let [, value] of entries) visit(value, 0);
|
|
7084
7194
|
}
|
|
7085
7195
|
function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1) {
|
|
7086
|
-
let selection2 =
|
|
7087
|
-
if (Object.keys(options).some((key) => !allowed.includes(key)))
|
|
7088
|
-
return
|
|
7196
|
+
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"];
|
|
7197
|
+
if (allowed.push("timeline"), Object.keys(options).some((key) => !allowed.includes(key)))
|
|
7198
|
+
return fail4("unsupported option");
|
|
7089
7199
|
let fields4 = Object.hasOwn(options, "fields") ? options.fields : schema2.fields.map((field) => field.name);
|
|
7090
|
-
if (!Array.isArray(fields4) || fields4.some((name2) => typeof name2 != "string" || !["$ref", "$version"].includes(name2) && !schema2.fields.some((field) => field.name === name2)) || new Set(fields4).size !== fields4.length) return
|
|
7091
|
-
let conditions = [];
|
|
7092
|
-
if (Object.hasOwn(options, "
|
|
7200
|
+
if (!Array.isArray(fields4) || fields4.some((name2) => typeof name2 != "string" || !["$ref", "$version"].includes(name2) && !schema2.fields.some((field) => field.name === name2)) || new Set(fields4).size !== fields4.length) return fail4("invalid projection");
|
|
7201
|
+
let conditions = [], signalConditions = [];
|
|
7202
|
+
if (Object.hasOwn(options, "timeline") && options.timeline !== !0) return fail4("invalid timeline option");
|
|
7203
|
+
if (Object.hasOwn(options, "where")) for (let [name2, condition] of Object.entries(mapping3(options.where))) {
|
|
7204
|
+
if (name2 === "$signals") {
|
|
7205
|
+
for (let [key, signalCondition] of Object.entries(mapping3(condition))) {
|
|
7206
|
+
if (!validSignalKey(key)) return fail4("invalid Signal key");
|
|
7207
|
+
if (typeof signalCondition == "string") {
|
|
7208
|
+
if (!validSignalText(signalCondition)) return fail4("invalid Signal status");
|
|
7209
|
+
signalConditions.push([key, [signalCondition]]);
|
|
7210
|
+
} else {
|
|
7211
|
+
let expression = mapping3(signalCondition);
|
|
7212
|
+
if (Object.keys(expression).length !== 1) return fail4("invalid Signal condition");
|
|
7213
|
+
if (Object.hasOwn(expression, "$exists") && expression.$exists === !1) signalConditions.push([key, !1]);
|
|
7214
|
+
else if (Object.hasOwn(expression, "$in") && Array.isArray(expression.$in) && expression.$in.length >= 1 && expression.$in.length <= 100 && expression.$in.every(validSignalText) && new Set(expression.$in).size === expression.$in.length)
|
|
7215
|
+
signalConditions.push([key, [...expression.$in]]);
|
|
7216
|
+
else return fail4("invalid Signal condition");
|
|
7217
|
+
}
|
|
7218
|
+
}
|
|
7219
|
+
continue;
|
|
7220
|
+
}
|
|
7093
7221
|
let field = scalarField(name2, schema2), values = [condition];
|
|
7094
7222
|
if (condition !== null && typeof condition == "object") {
|
|
7095
|
-
let expression =
|
|
7223
|
+
let expression = mapping3(condition);
|
|
7096
7224
|
if (!Object.hasOwn(expression, "$in")) {
|
|
7097
7225
|
let keys7 = Object.keys(expression);
|
|
7098
|
-
if (keys7.length === 0 || keys7.some((key) => !boundOperators.includes(key)) || Object.hasOwn(expression, "$gt") && Object.hasOwn(expression, "$gte") || Object.hasOwn(expression, "$lt") && Object.hasOwn(expression, "$lte")) return
|
|
7226
|
+
if (keys7.length === 0 || keys7.some((key) => !boundOperators.includes(key)) || Object.hasOwn(expression, "$gt") && Object.hasOwn(expression, "$gte") || Object.hasOwn(expression, "$lt") && Object.hasOwn(expression, "$lte")) return fail4("invalid bounds");
|
|
7099
7227
|
if (field.name === "$ref" || !["integer", "number", "date", "datetime"].includes(field.kind))
|
|
7100
|
-
return
|
|
7228
|
+
return fail4(`ineligible range field: ${name2}`);
|
|
7101
7229
|
let bounds = boundOperators.filter((operator) => Object.hasOwn(expression, operator)).map((operator) => {
|
|
7102
7230
|
let value2 = expression[operator];
|
|
7103
|
-
return value2 === null ?
|
|
7231
|
+
return value2 === null ? fail4("null bound") : [operator, conditionValue(value2, field)];
|
|
7104
7232
|
});
|
|
7105
7233
|
conditions.push([name2, { bounds }]);
|
|
7106
7234
|
continue;
|
|
7107
7235
|
}
|
|
7108
7236
|
if (Object.keys(expression).length !== 1 || !Object.hasOwn(expression, "$in") || !Array.isArray(expression.$in) || expression.$in.length < 1 || expression.$in.length > 100)
|
|
7109
|
-
return
|
|
7237
|
+
return fail4("invalid $in");
|
|
7110
7238
|
values = expression.$in;
|
|
7111
7239
|
}
|
|
7112
7240
|
let checked2 = values.map((value2) => conditionValue(value2, field));
|
|
7113
|
-
if (new Set(checked2).size !== checked2.length) return
|
|
7241
|
+
if (new Set(checked2).size !== checked2.length) return fail4("duplicate $in value");
|
|
7114
7242
|
conditions.push([name2, checked2]);
|
|
7115
7243
|
}
|
|
7116
7244
|
let order = { field: "$ref", direction: "asc" };
|
|
7117
7245
|
if (Object.hasOwn(options, "order")) {
|
|
7118
|
-
let entries = Object.entries(
|
|
7119
|
-
if (entries.length !== 1) return
|
|
7246
|
+
let entries = Object.entries(mapping3(options.order));
|
|
7247
|
+
if (entries.length !== 1) return fail4("order requires one field");
|
|
7120
7248
|
let [name2, direction] = entries[0];
|
|
7121
|
-
if (scalarField(name2, schema2), direction !== "asc" && direction !== "desc") return
|
|
7249
|
+
if (scalarField(name2, schema2), direction !== "asc" && direction !== "desc") return fail4("invalid order direction");
|
|
7122
7250
|
order = { field: name2, direction };
|
|
7123
7251
|
}
|
|
7124
7252
|
let limit = Object.hasOwn(options, "limit") ? options.limit : 100;
|
|
7125
7253
|
if (typeof limit != "number" || !Number.isInteger(limit) || limit < 1 || limit > (depth === 0 ? 500 : 100))
|
|
7126
|
-
return
|
|
7127
|
-
if (Object.hasOwn(options, "count") && typeof options.count != "boolean") return
|
|
7254
|
+
return fail4("invalid limit");
|
|
7255
|
+
if (Object.hasOwn(options, "count") && typeof options.count != "boolean") return fail4("invalid count");
|
|
7128
7256
|
if (Object.hasOwn(options, "after") && (typeof options.after != "string" || options.after.length === 0))
|
|
7129
|
-
return
|
|
7257
|
+
return fail4("invalid cursor");
|
|
7130
7258
|
let links = [];
|
|
7131
7259
|
for (let [name2, nested] of Object.entries(selection2)) {
|
|
7132
7260
|
if (name2 === "$") continue;
|
|
7133
7261
|
let field = schema2.fields.find((field2) => field2.name === name2);
|
|
7134
|
-
if (!field || field.kind !== "link") return
|
|
7135
|
-
if (depth >= 4) return
|
|
7136
|
-
let targets = new Map(field.to.flatMap((type) => (collectionsByType.get(type) ??
|
|
7262
|
+
if (!field || field.kind !== "link") return fail4(`ineligible link field: ${name2}`);
|
|
7263
|
+
if (depth >= 4) return fail4("too many link levels");
|
|
7264
|
+
let targets = new Map(field.to.flatMap((type) => (collectionsByType.get(type) ?? fail4(`unknown link target type: ${type}`)).map((target) => [
|
|
7137
7265
|
target.name,
|
|
7138
7266
|
selectionTree(nested, target.schema, collectionsByType, depth + 1, field.many)
|
|
7139
7267
|
])));
|
|
@@ -7142,6 +7270,8 @@ function selectionTree(value, schema2, collectionsByType, depth = 0, many = !1)
|
|
|
7142
7270
|
return {
|
|
7143
7271
|
fields: fields4,
|
|
7144
7272
|
conditions,
|
|
7273
|
+
...signalConditions.length ? { signalConditions } : {},
|
|
7274
|
+
...options.timeline === !0 ? { timeline: !0 } : {},
|
|
7145
7275
|
order,
|
|
7146
7276
|
limit,
|
|
7147
7277
|
count: options.count === !0,
|
|
@@ -7155,6 +7285,8 @@ function selectionBinding(selection2, top = !0, many = !1) {
|
|
|
7155
7285
|
return {
|
|
7156
7286
|
fields: selection2.fields,
|
|
7157
7287
|
conditions: [...selection2.conditions].sort(([a], [b]) => compare(a, b)),
|
|
7288
|
+
...selection2.signalConditions ? { signalConditions: [...selection2.signalConditions].sort(([a], [b]) => compare(a, b)) } : {},
|
|
7289
|
+
...selection2.timeline ? { timeline: !0 } : {},
|
|
7158
7290
|
order: top || many && selection2.explicitOrder ? selection2.order : null,
|
|
7159
7291
|
limit: top || many && selection2.explicitLimit ? selection2.limit : null,
|
|
7160
7292
|
count: selection2.count,
|
|
@@ -7172,7 +7304,7 @@ function planIndexQuery(query, catalogue) {
|
|
|
7172
7304
|
targets.push(collection), byType.set(collection.schema.type, targets);
|
|
7173
7305
|
}
|
|
7174
7306
|
return entries.map(([name2, value]) => {
|
|
7175
|
-
let target = collections.get(name2) ??
|
|
7307
|
+
let target = collections.get(name2) ?? fail4(`unknown collection: ${name2}`);
|
|
7176
7308
|
return { name: name2, selection: selectionTree(value, target.schema, byType) };
|
|
7177
7309
|
});
|
|
7178
7310
|
}
|
|
@@ -7182,109 +7314,14 @@ function indexSelectionBinding(context, collection, selection2) {
|
|
|
7182
7314
|
function cursorPosition(value, binding, limit) {
|
|
7183
7315
|
let payload;
|
|
7184
7316
|
try {
|
|
7185
|
-
payload =
|
|
7317
|
+
payload = mapping3(value);
|
|
7186
7318
|
} catch {
|
|
7187
|
-
return
|
|
7319
|
+
return fail4("invalid cursor");
|
|
7188
7320
|
}
|
|
7189
7321
|
let { position, ref } = payload;
|
|
7190
|
-
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) ?
|
|
7322
|
+
return Object.keys(payload).length !== 4 || payload.format !== 1 || payload.binding !== binding || typeof position != "number" || !Number.isSafeInteger(position) || position <= 0 || position % limit !== 0 || typeof ref != "string" || !validRecordRef(ref) ? fail4("incompatible cursor") : { position, ref };
|
|
7191
7323
|
}
|
|
7192
7324
|
|
|
7193
|
-
var compare2 = (a, b) => a < b ? -1 : a > b ? 1 : 0, fail4 = (message2) => {
|
|
7194
|
-
throw new RecordValidationError(`Invalid Records query: ${message2}`);
|
|
7195
|
-
};
|
|
7196
|
-
function continuation(value, binding, matching, limit) {
|
|
7197
|
-
let { position, ref } = cursorPosition(value, binding, limit);
|
|
7198
|
-
return position >= matching.length || ref !== matching[position - 1]?.$ref ? fail4("incompatible cursor") : position;
|
|
7199
|
-
}
|
|
7200
|
-
function matches(record4, selection2) {
|
|
7201
|
-
return selection2.conditions.every(([field, condition]) => {
|
|
7202
|
-
if (!Object.hasOwn(record4, field)) return !1;
|
|
7203
|
-
let value = record4[field];
|
|
7204
|
-
return Array.isArray(condition) ? condition.some((candidate) => candidate === value) : value === null ? !1 : condition.bounds.every(([operator, bound]) => {
|
|
7205
|
-
let result2 = typeof value == "number" && typeof bound == "number" ? value - bound : compare2(value, bound);
|
|
7206
|
-
switch (operator) {
|
|
7207
|
-
case "$gt":
|
|
7208
|
-
return result2 > 0;
|
|
7209
|
-
case "$gte":
|
|
7210
|
-
return result2 >= 0;
|
|
7211
|
-
case "$lt":
|
|
7212
|
-
return result2 < 0;
|
|
7213
|
-
case "$lte":
|
|
7214
|
-
return result2 <= 0;
|
|
7215
|
-
}
|
|
7216
|
-
});
|
|
7217
|
-
});
|
|
7218
|
-
}
|
|
7219
|
-
function ordered(a, b, { field, direction }) {
|
|
7220
|
-
let left = a[field], right = b[field], missingLeft = left == null, missingRight = right == null, result2 = 0;
|
|
7221
|
-
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));
|
|
7222
|
-
}
|
|
7223
|
-
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue, bodyCollections = []) {
|
|
7224
|
-
let { version } = context, selections = planIndexQuery(query, catalogue), scanned = /* @__PURE__ */ new Map();
|
|
7225
|
-
for (let { name: name2 } of selections) scanned.set(name2, yield { operation: "scan", collection: name2 });
|
|
7226
|
-
if (maxRecords !== void 0 && selections.reduce((sum, { name: name2, selection: selection2 }) => sum + scanned.get(name2).filter((record4) => matches(record4, selection2)).length, 0) > maxRecords)
|
|
7227
|
-
throw new DataOperationError(
|
|
7228
|
-
"capacity",
|
|
7229
|
-
!1,
|
|
7230
|
-
void 0,
|
|
7231
|
-
void 0,
|
|
7232
|
-
{ code: "record_limit_exceeded", maxRecords, collections: selections.map((row) => row.name) }
|
|
7233
|
-
);
|
|
7234
|
-
let occurrences = 0;
|
|
7235
|
-
function* expand(record4, collection, selection2, fragment) {
|
|
7236
|
-
if (++occurrences > 2e3) return fail4("too many returned Record occurrences");
|
|
7237
|
-
let result2 = Object.fromEntries(["$ref", "$version", ...selection2.fields.filter((field) => !["$ref", "$version"].includes(field))].filter((field) => Object.hasOwn(record4, field)).map((field) => [
|
|
7238
|
-
field,
|
|
7239
|
-
cloneValue(record4[field])
|
|
7240
|
-
]));
|
|
7241
|
-
bodyCollections.includes(collection) && typeof record4.$body == "string" && (result2.$body = record4.$body), fragment !== void 0 && (result2.$fragment = fragment);
|
|
7242
|
-
for (let link of selection2.links) {
|
|
7243
|
-
if (!Object.hasOwn(record4, link.name)) continue;
|
|
7244
|
-
let value = record4[link.name], expanded;
|
|
7245
|
-
if (value === null) expanded = null;
|
|
7246
|
-
else {
|
|
7247
|
-
let refs = link.many ? value : [value], matching = [];
|
|
7248
|
-
for (let value2 of refs) {
|
|
7249
|
-
let { ref, fragment: fragment2 } = parseRecordLink(value2) ?? fail4("invalid stored link"), target = yield { operation: "lookup", ref };
|
|
7250
|
-
if (!target) return fail4("unresolved stored link");
|
|
7251
|
-
let nested = link.targets.get(target.collection) ?? fail4("incompatible stored link");
|
|
7252
|
-
matches(target.record, nested) && matching.push({ record: target.record, collection: target.collection, selection: nested, fragment: fragment2 });
|
|
7253
|
-
}
|
|
7254
|
-
let options = link.targets.values().next().value;
|
|
7255
|
-
if (options.explicitOrder && matching.sort((a, b) => ordered(a.record, b.record, options.order)), link.many && !options.explicitLimit && matching.length > 100) return fail4("too many matching linked Records");
|
|
7256
|
-
options.explicitLimit && (matching = matching.slice(0, options.limit));
|
|
7257
|
-
let records = [];
|
|
7258
|
-
for (let { record: record5, collection: collection2, selection: selection3, fragment: fragment2 } of matching) records.push(yield* expand(record5, collection2, selection3, fragment2));
|
|
7259
|
-
expanded = link.many ? records : records[0] ?? null;
|
|
7260
|
-
}
|
|
7261
|
-
Object.defineProperty(result2, link.name, { value: expanded, enumerable: !0, writable: !0, configurable: !0 });
|
|
7262
|
-
}
|
|
7263
|
-
return result2;
|
|
7264
|
-
}
|
|
7265
|
-
let metadata = { version, collections: {} }, results = [];
|
|
7266
|
-
for (let { name: name2, selection: selection2 } of selections) {
|
|
7267
|
-
let matching = scanned.get(name2).filter((record4) => matches(record4, selection2)).sort((a, b) => ordered(a, b, selection2.order)), binding = indexSelectionBinding(context, name2, 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 = [];
|
|
7268
|
-
for (let index = start; index < end; index++)
|
|
7269
|
-
maxRecords !== void 0 && (index - start) % selection2.limit === 0 && (occurrences = 0), records.push(yield* expand(matching[index], name2, selection2));
|
|
7270
|
-
let page = selection2.count ? { count: matching.length } : {};
|
|
7271
|
-
if (maxRecords === void 0 && end < matching.length) {
|
|
7272
|
-
let token = yield { operation: "seal", payload: { format: 1, binding, position: end, ref: matching[end - 1].$ref } };
|
|
7273
|
-
if (typeof token != "string" || token.length === 0) return fail4("invalid sealed cursor");
|
|
7274
|
-
page.next = token;
|
|
7275
|
-
}
|
|
7276
|
-
Object.keys(page).length && Object.defineProperty(metadata.collections, name2, {
|
|
7277
|
-
value: page,
|
|
7278
|
-
enumerable: !0,
|
|
7279
|
-
writable: !0,
|
|
7280
|
-
configurable: !0
|
|
7281
|
-
}), results.push([name2, records]);
|
|
7282
|
-
}
|
|
7283
|
-
return { ...Object.fromEntries(results), $meta: metadata };
|
|
7284
|
-
}
|
|
7285
|
-
|
|
7286
|
-
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";
|
|
7287
|
-
|
|
7288
7325
|
var invalid7 = () => {
|
|
7289
7326
|
throw new DataOperationError("unavailable", !0);
|
|
7290
7327
|
}, object4 = (value) => !value || typeof value != "object" || Array.isArray(value) ? invalid7() : value, keys3 = (value, expected) => Object.keys(value).sort().join(",") === expected, hash = (value) => typeof value == "string" && /^[0-9a-f]{40}$/.test(value), time = (value) => typeof value == "string" && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/.test(value) && Number.isFinite(Date.parse(value)), sorted = (values) => values.every((value, i) => i === 0 || values[i - 1] < value);
|
|
@@ -7406,13 +7443,14 @@ function schemaText(value) {
|
|
|
7406
7443
|
schemaText(entry);
|
|
7407
7444
|
}
|
|
7408
7445
|
}
|
|
7409
|
-
function validateSnapshotEnvelope(input, repository, name2, bodies = []) {
|
|
7446
|
+
function validateSnapshotEnvelope(input, repository, name2, bodies = [], timelines = []) {
|
|
7410
7447
|
try {
|
|
7411
|
-
let row = object5(input);
|
|
7412
|
-
if (!["collections,format,name,repository,schemas,version", "collections,format,history,name,repository,schemas,version"].includes(Object.keys(row).sort().join(",")) || row.format !== "data-snapshot.
|
|
7448
|
+
let row = object5(input), legacy = row.format === "data-snapshot.v1";
|
|
7449
|
+
if (!["collections,format,name,repository,schemas,version", "collections,format,history,name,repository,schemas,version"].includes(Object.keys(row).sort().join(",")) || !legacy && row.format !== "data-snapshot.v2" || legacy && timelines.length > 0 || row.repository !== repository || row.name !== name2 || !dataVersion(row.version)) return invalid8();
|
|
7413
7450
|
let schemas2 = object5(row.schemas), collections = object5(row.collections);
|
|
7414
7451
|
schemaText(schemas2);
|
|
7415
7452
|
let names = Object.keys(collections);
|
|
7453
|
+
for (let subset of [bodies, timelines]) if (new Set(subset).size !== subset.length || subset.some((name3) => !names.includes(name3))) return invalid8();
|
|
7416
7454
|
if (!names.length || names.join("\0") !== [...names].sort().join("\0") || Object.keys(schemas2).join("\0") !== names.join("\0")) return invalid8();
|
|
7417
7455
|
let catalogue = names.map((name3) => {
|
|
7418
7456
|
let schema2 = object5(schemas2[name3]);
|
|
@@ -7435,65 +7473,196 @@ function validateSnapshotEnvelope(input, repository, name2, bodies = []) {
|
|
|
7435
7473
|
}
|
|
7436
7474
|
}
|
|
7437
7475
|
for (let collection of catalogue) for (let record4 of collections[collection.name]) {
|
|
7438
|
-
let { $ref: _ref, $version: _version, $body, ...values } = record4;
|
|
7476
|
+
let { $ref: _ref, $version: _version, $body, $signals, $timeline, ...values } = record4;
|
|
7477
|
+
if (legacy) {
|
|
7478
|
+
if (Object.hasOwn(record4, "$signals") || Object.hasOwn(record4, "$timeline")) return invalid8();
|
|
7479
|
+
} else if (captureRecordSignals($signals), timelines.includes(collection.name)) {
|
|
7480
|
+
if (!Array.isArray($timeline)) return invalid8();
|
|
7481
|
+
$timeline.forEach((value) => captureTimeline(value));
|
|
7482
|
+
} else if (Object.hasOwn(record4, "$timeline")) return invalid8();
|
|
7439
7483
|
if (Object.hasOwn(record4, "$body") && (!bodies.includes(collection.name) || typeof $body != "string")) return invalid8();
|
|
7440
7484
|
validateRecordFields(values, collection.schema.fields, (ref, targets) => types.get(ref) ?? targets[0], !0);
|
|
7441
7485
|
}
|
|
7486
|
+
let normalized = legacy ? Object.fromEntries(Object.entries(collections).map(([collection, records]) => [
|
|
7487
|
+
collection,
|
|
7488
|
+
records.map((record4) => ({ ...record4, $signals: [] }))
|
|
7489
|
+
])) : collections;
|
|
7442
7490
|
return {
|
|
7443
|
-
format: "data-snapshot.
|
|
7491
|
+
format: "data-snapshot.v2",
|
|
7444
7492
|
repository,
|
|
7445
7493
|
name: name2,
|
|
7446
7494
|
version: row.version,
|
|
7447
7495
|
bodyCollections: [...bodies],
|
|
7496
|
+
timelineCollections: [...timelines],
|
|
7448
7497
|
catalogue,
|
|
7449
|
-
collections,
|
|
7450
|
-
...Object.hasOwn(row, "history") ? { history: validateSnapshotHistory(row.history,
|
|
7498
|
+
collections: normalized,
|
|
7499
|
+
...Object.hasOwn(row, "history") ? { history: validateSnapshotHistory(row.history, normalized, row.version) } : {}
|
|
7451
7500
|
};
|
|
7452
7501
|
} catch {
|
|
7453
7502
|
return invalid8();
|
|
7454
7503
|
}
|
|
7455
7504
|
}
|
|
7456
7505
|
|
|
7506
|
+
var compare2 = (a, b) => a < b ? -1 : a > b ? 1 : 0, fail5 = (message2) => {
|
|
7507
|
+
throw new RecordValidationError(`Invalid Records query: ${message2}`);
|
|
7508
|
+
};
|
|
7509
|
+
function continuation(value, binding, matching, limit) {
|
|
7510
|
+
let { position, ref } = cursorPosition(value, binding, limit);
|
|
7511
|
+
return position >= matching.length || ref !== matching[position - 1]?.$ref ? fail5("incompatible cursor") : position;
|
|
7512
|
+
}
|
|
7513
|
+
function matches(record4, selection2) {
|
|
7514
|
+
return (selection2.signalConditions ?? []).every(([key, statuses]) => {
|
|
7515
|
+
if (!Array.isArray(record4.$signals)) return fail5("Signals are unavailable");
|
|
7516
|
+
let signal = record4.$signals?.find((row) => row.key === key);
|
|
7517
|
+
return statuses === !1 ? signal === void 0 : signal !== void 0 && statuses.includes(signal.status);
|
|
7518
|
+
}) && selection2.conditions.every(([field, condition]) => {
|
|
7519
|
+
if (!Object.hasOwn(record4, field)) return !1;
|
|
7520
|
+
let value = record4[field];
|
|
7521
|
+
return Array.isArray(condition) ? condition.some((candidate) => candidate === value) : value === null ? !1 : condition.bounds.every(([operator, bound]) => {
|
|
7522
|
+
let result2 = typeof value == "number" && typeof bound == "number" ? value - bound : compare2(value, bound);
|
|
7523
|
+
switch (operator) {
|
|
7524
|
+
case "$gt":
|
|
7525
|
+
return result2 > 0;
|
|
7526
|
+
case "$gte":
|
|
7527
|
+
return result2 >= 0;
|
|
7528
|
+
case "$lt":
|
|
7529
|
+
return result2 < 0;
|
|
7530
|
+
case "$lte":
|
|
7531
|
+
return result2 <= 0;
|
|
7532
|
+
}
|
|
7533
|
+
});
|
|
7534
|
+
});
|
|
7535
|
+
}
|
|
7536
|
+
function ordered(a, b, { field, direction }) {
|
|
7537
|
+
let left = a[field], right = b[field], missingLeft = left == null, missingRight = right == null, result2 = 0;
|
|
7538
|
+
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));
|
|
7539
|
+
}
|
|
7540
|
+
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue, bodyCollections = []) {
|
|
7541
|
+
let { version } = context, selections = planIndexQuery(query, catalogue), scanned = /* @__PURE__ */ new Map();
|
|
7542
|
+
for (let { name: name2 } of selections) scanned.set(name2, yield { operation: "scan", collection: name2 });
|
|
7543
|
+
if (maxRecords !== void 0 && selections.reduce((sum, { name: name2, selection: selection2 }) => sum + scanned.get(name2).filter((record4) => matches(record4, selection2)).length, 0) > maxRecords)
|
|
7544
|
+
throw new DataOperationError(
|
|
7545
|
+
"capacity",
|
|
7546
|
+
!1,
|
|
7547
|
+
void 0,
|
|
7548
|
+
void 0,
|
|
7549
|
+
{ code: "record_limit_exceeded", maxRecords, collections: selections.map((row) => row.name) }
|
|
7550
|
+
);
|
|
7551
|
+
let occurrences = 0;
|
|
7552
|
+
function* expand(record4, collection, selection2, fragment) {
|
|
7553
|
+
if (++occurrences > 2e3) return fail5("too many returned Record occurrences");
|
|
7554
|
+
let result2 = Object.fromEntries(["$ref", "$version", ...selection2.fields.filter((field) => !["$ref", "$version"].includes(field))].filter((field) => Object.hasOwn(record4, field)).map((field) => [
|
|
7555
|
+
field,
|
|
7556
|
+
cloneValue(record4[field])
|
|
7557
|
+
]));
|
|
7558
|
+
if (Object.hasOwn(record4, "$signals") && (result2.$signals = cloneValue(record4.$signals)), selection2.timeline) {
|
|
7559
|
+
if (!Array.isArray(record4.$timeline)) return fail5("Timeline is unavailable");
|
|
7560
|
+
result2.$timeline = cloneValue(record4.$timeline);
|
|
7561
|
+
}
|
|
7562
|
+
bodyCollections.includes(collection) && typeof record4.$body == "string" && (result2.$body = record4.$body), fragment !== void 0 && (result2.$fragment = fragment);
|
|
7563
|
+
for (let link of selection2.links) {
|
|
7564
|
+
if (!Object.hasOwn(record4, link.name)) continue;
|
|
7565
|
+
let value = record4[link.name], expanded;
|
|
7566
|
+
if (value === null) expanded = null;
|
|
7567
|
+
else {
|
|
7568
|
+
let refs = link.many ? value : [value], matching = [];
|
|
7569
|
+
for (let value2 of refs) {
|
|
7570
|
+
let { ref, fragment: fragment2 } = parseRecordLink(value2) ?? fail5("invalid stored link"), target = yield { operation: "lookup", ref };
|
|
7571
|
+
if (!target) return fail5("unresolved stored link");
|
|
7572
|
+
let nested = link.targets.get(target.collection) ?? fail5("incompatible stored link");
|
|
7573
|
+
matches(target.record, nested) && matching.push({ record: target.record, collection: target.collection, selection: nested, fragment: fragment2 });
|
|
7574
|
+
}
|
|
7575
|
+
let options = link.targets.values().next().value;
|
|
7576
|
+
if (options.explicitOrder && matching.sort((a, b) => ordered(a.record, b.record, options.order)), link.many && !options.explicitLimit && matching.length > 100) return fail5("too many matching linked Records");
|
|
7577
|
+
options.explicitLimit && (matching = matching.slice(0, options.limit));
|
|
7578
|
+
let records = [];
|
|
7579
|
+
for (let { record: record5, collection: collection2, selection: selection3, fragment: fragment2 } of matching) records.push(yield* expand(record5, collection2, selection3, fragment2));
|
|
7580
|
+
expanded = link.many ? records : records[0] ?? null;
|
|
7581
|
+
}
|
|
7582
|
+
Object.defineProperty(result2, link.name, { value: expanded, enumerable: !0, writable: !0, configurable: !0 });
|
|
7583
|
+
}
|
|
7584
|
+
return result2;
|
|
7585
|
+
}
|
|
7586
|
+
let metadata = { version, collections: {} }, results = [];
|
|
7587
|
+
for (let { name: name2, selection: selection2 } of selections) {
|
|
7588
|
+
let matching = scanned.get(name2).filter((record4) => matches(record4, selection2)).sort((a, b) => ordered(a, b, selection2.order)), binding = indexSelectionBinding(context, name2, 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 = [];
|
|
7589
|
+
for (let index = start; index < end; index++)
|
|
7590
|
+
maxRecords !== void 0 && (index - start) % selection2.limit === 0 && (occurrences = 0), records.push(yield* expand(matching[index], name2, selection2));
|
|
7591
|
+
let page = selection2.count ? { count: matching.length } : {};
|
|
7592
|
+
if (maxRecords === void 0 && end < matching.length) {
|
|
7593
|
+
let token = yield { operation: "seal", payload: { format: 1, binding, position: end, ref: matching[end - 1].$ref } };
|
|
7594
|
+
if (typeof token != "string" || token.length === 0) return fail5("invalid sealed cursor");
|
|
7595
|
+
page.next = token;
|
|
7596
|
+
}
|
|
7597
|
+
Object.keys(page).length && Object.defineProperty(metadata.collections, name2, {
|
|
7598
|
+
value: page,
|
|
7599
|
+
enumerable: !0,
|
|
7600
|
+
writable: !0,
|
|
7601
|
+
configurable: !0
|
|
7602
|
+
}), results.push([name2, records]);
|
|
7603
|
+
}
|
|
7604
|
+
return { ...Object.fromEntries(results), $meta: metadata };
|
|
7605
|
+
}
|
|
7606
|
+
|
|
7607
|
+
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";
|
|
7608
|
+
|
|
7457
7609
|
var invalid9 = () => {
|
|
7458
7610
|
throw new DataOperationError("unavailable", !0);
|
|
7459
7611
|
}, object6 = (v) => v && typeof v == "object" && !Array.isArray(v) ? v : invalid9(), uuid = (v) => typeof v == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v), time2 = (v) => typeof v == "string" && Number.isFinite(Date.parse(v)), recordVersion = (v) => typeof v == "string" && /^record-v1:[0-9a-f]{64}$/.test(v), keys4 = (v, allowed) => Object.keys(v).every((k) => allowed.includes(k));
|
|
7460
7612
|
function validateAcquisition(input, repository, name2) {
|
|
7461
7613
|
let row = object6(input), snapshot = object6(row.snapshot);
|
|
7462
|
-
if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !["
|
|
7463
|
-
let bodies = snapshot.bodies === void 0 ? [] : snapshot.bodies;
|
|
7464
|
-
|
|
7465
|
-
|
|
7614
|
+
if (Object.keys(row).sort().join(",") !== "changes,format,snapshot" || row.format !== snapshotAcquisitionFormat || !keys4(snapshot, ["id", "name", "refreshedAt", "repository", "version", "collections", "bodies", "timelines"]) || !uuid(snapshot.id) || snapshot.repository !== repository || snapshot.name !== name2 || !dataVersion(snapshot.version) || !time2(snapshot.refreshedAt) || !Array.isArray(snapshot.collections) || !snapshot.collections.length || !snapshot.collections.every((c) => typeof c == "string" && validRecordRef(`${c}/example`)) || snapshot.collections.join("\0") !== [...new Set(snapshot.collections)].sort().join("\0") || !Array.isArray(row.changes)) return invalid9();
|
|
7615
|
+
let bodies = snapshot.bodies === void 0 ? [] : snapshot.bodies, timelines = snapshot.timelines === void 0 ? [] : snapshot.timelines;
|
|
7616
|
+
for (let subset of [bodies, timelines]) if (!Array.isArray(subset) || subset.some((c) => !snapshot.collections.includes(c)) || subset.join("\0") !== [...new Set(subset)].sort().join("\0")) return invalid9();
|
|
7617
|
+
return {
|
|
7618
|
+
snapshot: { ...snapshot, bodies, timelines },
|
|
7466
7619
|
changes: validateSnapshotChanges(row.changes, snapshot.collections)
|
|
7467
7620
|
};
|
|
7468
7621
|
}
|
|
7469
7622
|
function validateSnapshotChanges(input, collections) {
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
let
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
if (
|
|
7489
|
-
|
|
7490
|
-
if (
|
|
7491
|
-
|
|
7492
|
-
if (
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7623
|
+
try {
|
|
7624
|
+
if (!Array.isArray(input)) return invalid9();
|
|
7625
|
+
let ids = /* @__PURE__ */ new Set(), unpublished = !1;
|
|
7626
|
+
for (let value of input) {
|
|
7627
|
+
let c = object6(value), effect = object6(c.effect);
|
|
7628
|
+
if (!keys4(c, ["id", "version", "ref", "recordVersion", "effect", "updatedAt", "person", "source", "publication"]) || !uuid(c.id) || ids.has(c.id) || !dataVersion(c.version) || !validRecordRef(c.ref) || !collections.some((name2) => c.ref.startsWith(`${name2}/`)) || !recordVersion(c.recordVersion) || !time2(c.updatedAt)) return invalid9();
|
|
7629
|
+
if (ids.add(c.id), c.person !== void 0) {
|
|
7630
|
+
let person = object6(c.person);
|
|
7631
|
+
if (!keys4(person, ["id", "name", "email"]) || !uuid(person.id) || person.name !== void 0 && !dataText(person.name) || person.email !== void 0 && !dataText(person.email)) return invalid9();
|
|
7632
|
+
}
|
|
7633
|
+
if (c.source !== void 0) {
|
|
7634
|
+
let source2 = object6(c.source);
|
|
7635
|
+
if (Object.keys(source2).sort().join(",") !== "id,kind" || source2.kind !== "app" && source2.kind !== "routine" || !dataText(source2.id)) return invalid9();
|
|
7636
|
+
}
|
|
7637
|
+
if (c.publication !== void 0) {
|
|
7638
|
+
let publication = object6(c.publication);
|
|
7639
|
+
if (unpublished || Object.keys(publication).sort().join(",") !== "commit,time" || typeof publication.commit != "string" || !/^[0-9a-f]{40}$/.test(publication.commit) || !time2(publication.time)) return invalid9();
|
|
7640
|
+
} else unpublished = !0;
|
|
7641
|
+
if (effect.kind === "set") {
|
|
7642
|
+
if (Object.keys(effect).sort().join(",") !== "field,kind,value" || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field)) return invalid9();
|
|
7643
|
+
} else if (effect.kind === "link" || effect.kind === "unlink") {
|
|
7644
|
+
if (!keys4(effect, ["kind", "field", "refs", ...effect.kind === "link" ? ["remove"] : []]) || !dataText(effect.field) || effect.field.startsWith("$") || ["id", "type", "__proto__", "constructor", "prototype"].includes(effect.field) || !Array.isArray(effect.refs) || !effect.refs.length || effect.refs.length > 1e5 || effect.refs.some((ref) => !validRecordRef(ref)) || new Set(effect.refs).size !== effect.refs.length || effect.remove !== void 0 && (!Array.isArray(effect.remove) || !effect.remove.length || effect.remove.length > 1e5 || effect.remove.some((ref) => !validRecordRef(ref)) || new Set(effect.remove).size !== effect.remove.length)) return invalid9();
|
|
7645
|
+
} else if (effect.kind === "signal") {
|
|
7646
|
+
if (Object.keys(effect).sort().join(",") !== "key,kind,value") return invalid9();
|
|
7647
|
+
let value2 = object6(effect.value);
|
|
7648
|
+
if (!keys4(value2, ["label", "status", "reason", "related", "asOf", "number"])) return invalid9();
|
|
7649
|
+
let { number, ...assessment } = value2;
|
|
7650
|
+
captureSignal({ ...assessment, key: effect.key }), (c.publication || Object.hasOwn(value2, "number")) && captureRecordSignal({ ...value2, key: effect.key });
|
|
7651
|
+
} else if (effect.kind === "timeline") {
|
|
7652
|
+
if (Object.keys(effect).sort().join(",") !== "entry,kind") return invalid9();
|
|
7653
|
+
captureTimeline(effect.entry);
|
|
7654
|
+
} else if (effect.kind === "create" || effect.kind === "delete") {
|
|
7655
|
+
if (!keys4(effect, ["fields", "kind", "signals", "timeline"])) return invalid9();
|
|
7656
|
+
if (object6(effect.fields), Object.hasOwn(effect, "signals") && captureRecordSignals(effect.signals), Object.hasOwn(effect, "timeline")) {
|
|
7657
|
+
if (!Array.isArray(effect.timeline)) return invalid9();
|
|
7658
|
+
effect.timeline.forEach((value2) => captureTimeline(value2));
|
|
7659
|
+
}
|
|
7660
|
+
} else return invalid9();
|
|
7661
|
+
}
|
|
7662
|
+
return input;
|
|
7663
|
+
} catch {
|
|
7664
|
+
return invalid9();
|
|
7665
|
+
}
|
|
7497
7666
|
}
|
|
7498
7667
|
function materializeSnapshot(envelope, changes, version) {
|
|
7499
7668
|
try {
|
|
@@ -7511,8 +7680,8 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
7511
7680
|
let targets = [...effect.refs, ...effect.kind === "link" ? effect.remove ?? [] : []];
|
|
7512
7681
|
for (let ref of targets) validateRecordFields({ [effect.field]: field.many ? [ref] : ref }, definitions2, (_ref, allowed) => allowed[0], !0);
|
|
7513
7682
|
values = { [effect.field]: field.many ? effect.refs : effect.refs[0] };
|
|
7514
|
-
} else values = effect.kind === "set" ? { [effect.field]: effect.value } : "fields" in effect ? effect.fields :
|
|
7515
|
-
if (validateRecordFields(
|
|
7683
|
+
} else values = effect.kind === "set" ? { [effect.field]: effect.value } : "fields" in effect ? effect.fields : {};
|
|
7684
|
+
if (effect.kind !== "signal" && effect.kind !== "timeline" && validateRecordFields(
|
|
7516
7685
|
values,
|
|
7517
7686
|
definitions2,
|
|
7518
7687
|
(_ref, targets) => targets[0],
|
|
@@ -7526,15 +7695,32 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
7526
7695
|
if (!prior) return invalid9();
|
|
7527
7696
|
let field = definitions2[0], current2 = prior[effect.field], value = field.many ? effect.kind === "link" ? [.../* @__PURE__ */ new Set([...Array.isArray(current2) ? current2 : [], ...effect.refs])].filter((ref) => !effect.remove?.includes(String(ref))) : (Array.isArray(current2) ? current2 : []).filter((ref) => !effect.refs.includes(String(ref))) : effect.kind === "link" ? effect.remove?.includes(effect.refs[0]) ? null : effect.refs[0] : effect.refs.includes(String(current2)) ? null : current2;
|
|
7528
7697
|
rows.set(c.ref, { ...prior, [effect.field]: value, $version: c.recordVersion });
|
|
7698
|
+
} else if (effect.kind === "signal") {
|
|
7699
|
+
if (!prior || !effect.value.number) return invalid9();
|
|
7700
|
+
let signal = captureRecordSignal({ ...effect.value, key: effect.key }), signals = captureRecordSignals(prior.$signals), index = signals.findIndex((row) => row.key === effect.key);
|
|
7701
|
+
index < 0 ? signals.push(signal) : signals[index] = signal, rows.set(c.ref, { ...prior, $signals: captureRecordSignals(signals), $version: c.recordVersion });
|
|
7702
|
+
} else if (effect.kind === "timeline") {
|
|
7703
|
+
if (!prior) return invalid9();
|
|
7704
|
+
rows.set(c.ref, {
|
|
7705
|
+
...prior,
|
|
7706
|
+
$version: c.recordVersion,
|
|
7707
|
+
...envelope.timelineCollections.includes(schema2.name) ? { $timeline: [...prior.$timeline, effect.entry] } : {}
|
|
7708
|
+
});
|
|
7529
7709
|
} else if (effect.kind === "create") {
|
|
7530
7710
|
if (prior) return invalid9();
|
|
7531
|
-
rows.set(c.ref, {
|
|
7711
|
+
rows.set(c.ref, {
|
|
7712
|
+
...effect.fields,
|
|
7713
|
+
$ref: c.ref,
|
|
7714
|
+
$version: c.recordVersion,
|
|
7715
|
+
$signals: effect.signals ?? [],
|
|
7716
|
+
...envelope.timelineCollections.includes(schema2.name) ? { $timeline: effect.timeline ?? [] } : {}
|
|
7717
|
+
});
|
|
7532
7718
|
} else {
|
|
7533
7719
|
if (!prior) return invalid9();
|
|
7534
7720
|
rows.delete(c.ref);
|
|
7535
7721
|
}
|
|
7536
7722
|
}
|
|
7537
|
-
return validateSnapshotEnvelope({
|
|
7723
|
+
return { ...validateSnapshotEnvelope({
|
|
7538
7724
|
format: envelope.format,
|
|
7539
7725
|
repository: envelope.repository,
|
|
7540
7726
|
name: envelope.name,
|
|
@@ -7546,7 +7732,7 @@ function materializeSnapshot(envelope, changes, version) {
|
|
|
7546
7732
|
fields: c.schema.fields.map(publicField)
|
|
7547
7733
|
}])),
|
|
7548
7734
|
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)]))
|
|
7549
|
-
}, envelope.repository, envelope.name, envelope.bodyCollections);
|
|
7735
|
+
}, envelope.repository, envelope.name, envelope.bodyCollections, envelope.timelineCollections), ...envelope.history ? { history: envelope.history } : {} };
|
|
7550
7736
|
} catch {
|
|
7551
7737
|
return invalid9();
|
|
7552
7738
|
}
|
|
@@ -7567,19 +7753,23 @@ function applySnapshotMutation(envelope, prior, mutation, installation) {
|
|
|
7567
7753
|
if (accepted.some((c) => !c.publication) || !Array.isArray(mutation.effects)) return rejected();
|
|
7568
7754
|
let effects = mutation.effects.map((e) => {
|
|
7569
7755
|
let source2 = accepted.find((c) => c.ref === e.ref);
|
|
7570
|
-
return !source2 || snapshotCollection(envelope.catalogue, e.ref)?.name !== e.collection || !["set", "create", "delete"].includes(e.effect.kind) ? rejected() : { ...source2, id: crypto.randomUUID(), recordVersion: e.version, effect: e.effect };
|
|
7756
|
+
return !source2 || snapshotCollection(envelope.catalogue, e.ref)?.name !== e.collection || !["set", "signal", "timeline", "create", "delete"].includes(e.effect.kind) ? rejected() : { ...source2, id: crypto.randomUUID(), recordVersion: e.version, effect: e.effect };
|
|
7571
7757
|
});
|
|
7572
7758
|
if (validateSnapshotChanges(effects, installation.catalogue.map((c) => c.name)), mutation.records !== void 0) {
|
|
7573
7759
|
if (materializeSnapshot(envelope, [...accepted, ...effects].map(({ publication: _publication, ...c }) => c), envelope.version), !Array.isArray(mutation.records) || new Set(mutation.records.map((r) => r.$ref)).size !== mutation.records.length) return rejected();
|
|
7574
7760
|
let refs = new Set(mutation.records.map((r) => r.$ref));
|
|
7575
|
-
if ([...accepted, ...prior.filter((c) => mutation.selected.some((s) => s.id === c.id && s.version === c.version))].some((c) => c.effect.kind !== "delete" && !refs.has(c.ref)) || accepted.some((c) => !mutation.effects.some((e) => e.ref === c.ref && ("field" in c.effect ? "field" in e.effect && e.effect.field === c.effect.field : e.effect.kind === c.effect.kind))) || mutation.effects.some((e) => !accepted.some((c) => c.ref === e.ref) || snapshotCollection(envelope.catalogue, e.ref)?.name !== e.collection || !["set", "create", "delete"].includes(e.effect.kind) || e.effect.kind !== "delete" && !mutation.records.some((r) => r.$ref === e.ref && r.$version === e.version))) return rejected();
|
|
7761
|
+
if ([...accepted, ...prior.filter((c) => mutation.selected.some((s) => s.id === c.id && s.version === c.version))].some((c) => c.effect.kind !== "delete" && !refs.has(c.ref)) || accepted.some((c) => !mutation.effects.some((e) => e.ref === c.ref && ("field" in c.effect ? "field" in e.effect && e.effect.field === c.effect.field : c.effect.kind === "signal" ? e.effect.kind === "signal" && e.effect.key === c.effect.key : e.effect.kind === c.effect.kind))) || mutation.effects.some((e) => !accepted.some((c) => c.ref === e.ref) || snapshotCollection(envelope.catalogue, e.ref)?.name !== e.collection || !["set", "signal", "timeline", "create", "delete"].includes(e.effect.kind) || e.effect.kind !== "delete" && !mutation.records.some((r) => r.$ref === e.ref && r.$version === e.version))) return rejected();
|
|
7576
7762
|
let rows = new Map(Object.values(envelope.collections).flat().map((r) => [r.$ref, r]));
|
|
7577
7763
|
for (let e of mutation.effects) e.effect.kind === "delete" && rows.delete(e.ref);
|
|
7578
7764
|
for (let record4 of mutation.records) {
|
|
7579
7765
|
let collection = snapshotCollection(envelope.catalogue, record4.$ref)?.name;
|
|
7580
7766
|
if (!collection) return rejected();
|
|
7581
|
-
let { $body, ...fields4 } = record4;
|
|
7582
|
-
rows.set(record4.$ref,
|
|
7767
|
+
let { $body, $timeline, ...fields4 } = record4;
|
|
7768
|
+
rows.set(record4.$ref, {
|
|
7769
|
+
...fields4,
|
|
7770
|
+
...envelope.bodyCollections?.includes(collection) && $body !== void 0 ? { $body } : {},
|
|
7771
|
+
...envelope.timelineCollections.includes(collection) ? { $timeline } : {}
|
|
7772
|
+
});
|
|
7583
7773
|
}
|
|
7584
7774
|
return envelope = validateSnapshotEnvelope({
|
|
7585
7775
|
format: envelope.format,
|
|
@@ -7593,7 +7783,7 @@ function applySnapshotMutation(envelope, prior, mutation, installation) {
|
|
|
7593
7783
|
fields: c.schema.fields.map(publicField)
|
|
7594
7784
|
}])),
|
|
7595
7785
|
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)]))
|
|
7596
|
-
}, envelope.repository, envelope.name, envelope.bodyCollections), { envelope, changes };
|
|
7786
|
+
}, envelope.repository, envelope.name, envelope.bodyCollections, envelope.timelineCollections), { envelope, changes };
|
|
7597
7787
|
}
|
|
7598
7788
|
if (!accepted.length || !mutation.effects.length) return rejected();
|
|
7599
7789
|
envelope = materializeSnapshot(envelope, effects, `snapshot-${crypto.randomUUID()}`);
|
|
@@ -7640,7 +7830,7 @@ async function openSnapshotStore() {
|
|
|
7640
7830
|
await done;
|
|
7641
7831
|
return;
|
|
7642
7832
|
}
|
|
7643
|
-
if (value.partition !== partition || !value.id || !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) {
|
|
7833
|
+
if (value.format !== "data-snapshot.v2" || !Array.isArray(value.timelineCollections) || value.partition !== partition || !value.id || !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) {
|
|
7644
7834
|
await done;
|
|
7645
7835
|
return;
|
|
7646
7836
|
}
|
|
@@ -7663,7 +7853,9 @@ async function openSnapshotStore() {
|
|
|
7663
7853
|
snapshotId,
|
|
7664
7854
|
repository: envelope.repository,
|
|
7665
7855
|
name: envelope.name,
|
|
7856
|
+
format: envelope.format,
|
|
7666
7857
|
bodyCollections: envelope.bodyCollections,
|
|
7858
|
+
timelineCollections: envelope.timelineCollections,
|
|
7667
7859
|
catalogue: envelope.catalogue,
|
|
7668
7860
|
changeCount: changes.length,
|
|
7669
7861
|
cursorKey: unchangedRecords?.cursorKey ?? crypto.getRandomValues(new Uint8Array(32)),
|
|
@@ -7701,11 +7893,12 @@ async function openSnapshotStore() {
|
|
|
7701
7893
|
collections[c.name] = rows.map((r) => r.record);
|
|
7702
7894
|
}
|
|
7703
7895
|
let { envelope, changes } = applySnapshotMutation({
|
|
7704
|
-
format: "data-snapshot.
|
|
7896
|
+
format: "data-snapshot.v2",
|
|
7705
7897
|
repository: installation.repository,
|
|
7706
7898
|
name: installation.name,
|
|
7707
7899
|
version: installation.version,
|
|
7708
7900
|
bodyCollections: installation.bodyCollections,
|
|
7901
|
+
timelineCollections: installation.timelineCollections,
|
|
7709
7902
|
catalogue: installation.catalogue,
|
|
7710
7903
|
collections
|
|
7711
7904
|
}, prior, mutation, installation), id3 = crypto.randomUUID(), next = {
|
|
@@ -7804,7 +7997,9 @@ function snapshotDifference(before, after) {
|
|
|
7804
7997
|
return { records: facts(before, !0) !== facts(after, !0), changes: facts(before) !== facts(after) };
|
|
7805
7998
|
}
|
|
7806
7999
|
async function acquireSnapshot(store, partition, url, headers, repository, snapshot, assertCurrent, signal, prior) {
|
|
7807
|
-
let candidate = prior === null ? void 0 : prior ?? await store.current(partition), cached = candidate && validSnapshotArtifactToken(candidate.artifactToken) && (candidate.pairToken === "" || validSnapshotPairToken(candidate.pairToken)) ? candidate : void 0, base = cached ? await store.base(cached) : void 0
|
|
8000
|
+
let candidate = prior === null ? void 0 : prior ?? await store.current(partition), cached = candidate?.format === "data-snapshot.v2" && validSnapshotArtifactToken(candidate.artifactToken) && (candidate.pairToken === "" || validSnapshotPairToken(candidate.pairToken)) ? candidate : void 0, base = cached ? await store.base(cached) : void 0;
|
|
8001
|
+
base?.format !== "data-snapshot.v2" && (base = void 0);
|
|
8002
|
+
let reusable = base ? cached : void 0;
|
|
7808
8003
|
assertCurrent();
|
|
7809
8004
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
7810
8005
|
let response2 = await fetch(url, {
|
|
@@ -7845,9 +8040,9 @@ async function acquireSnapshot(store, partition, url, headers, repository, snaps
|
|
|
7845
8040
|
}));
|
|
7846
8041
|
(artifact.status !== 200 || artifact.headers.get(snapshotPairHeader) !== pairToken || artifact.headers.get(snapshotArtifactHeader) !== artifactToken || !artifact.body || artifact.headers.get("content-type")?.split(";")[0] !== "application/gzip") && unavailable3();
|
|
7847
8042
|
let bytes = await new Response(artifact.body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer();
|
|
7848
|
-
base = validateSnapshotEnvelope(JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(bytes)), repository, snapshot, acquired.snapshot.bodies);
|
|
8043
|
+
base = validateSnapshotEnvelope(JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(bytes)), repository, snapshot, acquired.snapshot.bodies, acquired.snapshot.timelines);
|
|
7849
8044
|
}
|
|
7850
|
-
(!base || base.version !== acquired.snapshot.version || (base.bodyCollections ?? []).join("\0") !== acquired.snapshot.bodies.join("\0") || base.catalogue.map((c) => c.name).join("\0") !== acquired.snapshot.collections.join("\0") || reusable?.artifactToken === artifactToken && reusable.snapshotId !== acquired.snapshot.id) && unavailable3();
|
|
8045
|
+
(!base || base.version !== acquired.snapshot.version || (base.bodyCollections ?? []).join("\0") !== acquired.snapshot.bodies.join("\0") || base.timelineCollections.join("\0") !== acquired.snapshot.timelines.join("\0") || base.catalogue.map((c) => c.name).join("\0") !== acquired.snapshot.collections.join("\0") || reusable?.artifactToken === artifactToken && reusable.snapshotId !== acquired.snapshot.id) && unavailable3();
|
|
7851
8046
|
let update = reusable ? snapshotDifference(await store.changes(reusable), acquired.changes) : { records: !0, changes: !0 };
|
|
7852
8047
|
update.records ||= reusable?.artifactToken !== artifactToken;
|
|
7853
8048
|
let published = acquired.changes.filter((c) => c.publication), version = base.version;
|
|
@@ -7987,10 +8182,15 @@ function captureTransaction(callback, installation) {
|
|
|
7987
8182
|
return typeof name2 != "string" || unsafe(name2) || !installation.catalogue.some((c) => c.name === name2) ? invalidChange2() : new Proxy(/* @__PURE__ */ Object.create(null), { get(_target2, id3) {
|
|
7988
8183
|
let ref = `${name2}/${String(id3)}`;
|
|
7989
8184
|
if (typeof id3 != "string" || !validRecordRef(ref) || snapshotCollection(installation.catalogue, ref)?.name !== name2) return invalidChange2();
|
|
7990
|
-
let schema2 = installation.catalogue.find((c) => c.name === name2).schema, builder = Object.fromEntries(["create", "update", "link", "unlink", "delete"].map((kind) => [kind, (...args) => {
|
|
8185
|
+
let schema2 = installation.catalogue.find((c) => c.name === name2).schema, builder = Object.fromEntries(["create", "update", "link", "unlink", "delete", "setSignal", "appendTimeline"].map((kind) => [kind, (...args) => {
|
|
7991
8186
|
if (!active2 || args.length !== (kind === "delete" ? 0 : 1) || operations2.length >= 1e4) return invalidChange2();
|
|
8187
|
+
let table;
|
|
8188
|
+
if (kind === "setSignal") {
|
|
8189
|
+
let { asOf: _time, ...signal } = captureSignal(args[0], (/* @__PURE__ */ new Date()).toISOString());
|
|
8190
|
+
table = { kind: "signal", ref, signal };
|
|
8191
|
+
} else kind === "appendTimeline" && (table = { kind: "timeline", ref, entry: captureTimeline(args[0], !0) });
|
|
7992
8192
|
let fields4;
|
|
7993
|
-
if (kind !== "delete") {
|
|
8193
|
+
if (kind !== "delete" && !table) {
|
|
7994
8194
|
if (dataProperties(args[0]), fields4 = capture5(args[0]), !Object.keys(fields4).length || Object.keys(fields4).some((key) => unsafe(key) || kind !== "create" && ["id", "type"].includes(key))) return invalidChange2();
|
|
7995
8195
|
let definitions2 = kind === "create" ? schema2.fields : schema2.fields.filter((f) => Object.hasOwn(fields4, f.name));
|
|
7996
8196
|
if (kind === "link" || kind === "unlink")
|
|
@@ -8002,7 +8202,7 @@ function captureTransaction(callback, installation) {
|
|
|
8002
8202
|
validateRecordFields(fields4, definitions2, (ref2) => snapshotCollection(installation.catalogue, ref2)?.schema.type, !0), fields4 = captureDataCreate({ ...fields4, $ref: ref }).fields;
|
|
8003
8203
|
}
|
|
8004
8204
|
let prior = operations2.filter((op) => op.ref === ref);
|
|
8005
|
-
return kind === "delete" && prior.length || prior.some((op) => op.kind === "delete") || kind === "create" && prior.length ? invalidChange2() : (operations2.push({ kind, ref, ...fields4 ? { fields: fields4 } : {} }), builder);
|
|
8205
|
+
return kind === "delete" && prior.length || prior.some((op) => op.kind === "delete") || kind === "create" && prior.length ? invalidChange2() : (operations2.push(table ?? { kind, ref, ...fields4 ? { fields: fields4 } : {} }), builder);
|
|
8006
8206
|
}]));
|
|
8007
8207
|
return builder;
|
|
8008
8208
|
} });
|
|
@@ -8033,7 +8233,7 @@ var invalid10 = () => {
|
|
|
8033
8233
|
};
|
|
8034
8234
|
function captureSnapshotAll(query, options) {
|
|
8035
8235
|
let properties = dataProperties(options);
|
|
8036
|
-
return Object.keys(properties).some((key) =>
|
|
8236
|
+
return Object.keys(properties).some((key) => !["maxRecords", "body", "timeline"].includes(key)) || properties.body && properties.body.value !== !0 || properties.timeline && properties.timeline.value !== !0 ? invalid10() : { ...captureRecordsAll(query, { maxRecords: properties.maxRecords?.value }), body: properties.body?.value === !0, timeline: properties.timeline?.value === !0 };
|
|
8037
8237
|
}
|
|
8038
8238
|
var safeName = (value) => typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
|
|
8039
8239
|
function createSnapshotInitializer(resolve = resolveSnapshotContext, open = openSnapshotStore, connect = (url, protocols) => new WebSocket(url, protocols)) {
|
|
@@ -8060,7 +8260,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
8060
8260
|
} finally {
|
|
8061
8261
|
store.close();
|
|
8062
8262
|
}
|
|
8063
|
-
assertAccess(), cached && (cached.repository !== repository || cached.name !== snapshot || !validSnapshotArtifactToken(cached.artifactToken) || cached.pairToken !== "" && !validSnapshotPairToken(cached.pairToken)) && (cached = void 0);
|
|
8263
|
+
assertAccess(), cached && (cached.format !== "data-snapshot.v2" || !Array.isArray(cached.timelineCollections) || cached.repository !== repository || cached.name !== snapshot || !validSnapshotArtifactToken(cached.artifactToken) || cached.pairToken !== "" && !validSnapshotPairToken(cached.pairToken)) && (cached = void 0);
|
|
8064
8264
|
} catch (error) {
|
|
8065
8265
|
throw assertCurrent(), error instanceof DataOperationError ? error : new DataOperationError("unavailable", !0);
|
|
8066
8266
|
}
|
|
@@ -8185,7 +8385,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
8185
8385
|
} finally {
|
|
8186
8386
|
store?.close();
|
|
8187
8387
|
}
|
|
8188
|
-
}, query = async (query2, maxRecords, body = !1) => {
|
|
8388
|
+
}, query = async (query2, maxRecords, body = !1, timeline = !1) => {
|
|
8189
8389
|
let pinned = installation;
|
|
8190
8390
|
await ensureAccess();
|
|
8191
8391
|
let captured = captureRecordsQuery(query2);
|
|
@@ -8197,6 +8397,18 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
8197
8397
|
});
|
|
8198
8398
|
let store;
|
|
8199
8399
|
try {
|
|
8400
|
+
let selections = planIndexQuery(captured, pinned.catalogue), checkTimeline = (collection, selection2) => {
|
|
8401
|
+
if ((timeline || selection2.timeline) && !pinned.timelineCollections.includes(collection)) return invalid10();
|
|
8402
|
+
for (let link of selection2.links) for (let [name2, nested] of link.targets) checkTimeline(name2, nested);
|
|
8403
|
+
};
|
|
8404
|
+
for (let { name: name2, selection: selection2 } of selections) checkTimeline(name2, selection2);
|
|
8405
|
+
if (timeline) {
|
|
8406
|
+
let include = (selection2) => {
|
|
8407
|
+
selection2.$ = { ...selection2.$, timeline: !0 };
|
|
8408
|
+
for (let [key, nested] of Object.entries(selection2)) key !== "$" && include(nested);
|
|
8409
|
+
};
|
|
8410
|
+
for (let selection2 of Object.values(captured)) include(selection2);
|
|
8411
|
+
}
|
|
8200
8412
|
store = await open(), assertAccess();
|
|
8201
8413
|
let result2 = await store.query(pinned, captured, maxRecords, body);
|
|
8202
8414
|
return assertAccess(), result2;
|
|
@@ -8260,14 +8472,15 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
8260
8472
|
}, records: {
|
|
8261
8473
|
read: async (ref, ...extra) => {
|
|
8262
8474
|
if (typeof ref != "string" || extra.length > 1) return Promise.reject(new DataOperationError("invalid_query"));
|
|
8263
|
-
let { body } = captureRecordsReadOptions(extra[0]), [captured] = captureRecordsReadRefs([ref]);
|
|
8264
|
-
return installation.catalogue
|
|
8475
|
+
let { body, timeline } = captureRecordsReadOptions(extra[0]), [captured] = captureRecordsReadRefs([ref]);
|
|
8476
|
+
return snapshotCollection(installation.catalogue, captured) ? writes.then(() => {
|
|
8265
8477
|
let pinned = installation;
|
|
8266
8478
|
return localRead(async (store) => {
|
|
8479
|
+
if (timeline && !pinned.timelineCollections.includes(snapshotCollection(pinned.catalogue, captured).name)) return invalid10();
|
|
8267
8480
|
let record4 = await store.read(pinned, captured);
|
|
8268
|
-
if (!record4
|
|
8269
|
-
let { $body
|
|
8270
|
-
return structured;
|
|
8481
|
+
if (!record4) return record4;
|
|
8482
|
+
let { $body, $timeline, ...structured } = record4;
|
|
8483
|
+
return { ...structured, ...body && $body !== void 0 ? { $body } : {}, ...timeline ? { $timeline } : {} };
|
|
8271
8484
|
});
|
|
8272
8485
|
}) : Promise.reject(new DataOperationError("invalid_query"));
|
|
8273
8486
|
},
|
|
@@ -8275,7 +8488,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
8275
8488
|
...recordPagination(queryRecords),
|
|
8276
8489
|
all: async (input2, options) => {
|
|
8277
8490
|
let captured = captureSnapshotAll(input2, options);
|
|
8278
|
-
return writes.then(() => query(captured.query, captured.maxRecords, captured.body));
|
|
8491
|
+
return writes.then(() => query(captured.query, captured.maxRecords, captured.body, captured.timeline));
|
|
8279
8492
|
}
|
|
8280
8493
|
} };
|
|
8281
8494
|
};
|
|
@@ -8354,6 +8567,10 @@ var genericData = {
|
|
|
8354
8567
|
});
|
|
8355
8568
|
}
|
|
8356
8569
|
return pending.then((result2) => structuredClone(result2));
|
|
8570
|
+
}, authorTable = (ref, patch) => {
|
|
8571
|
+
if (assertMutable(), !validRecordRef(ref)) throw new DataOperationError("invalid_change", !1, "unapplied");
|
|
8572
|
+
let nextUpdates = structuredClone(updates), nextCreates = structuredClone(creates), target = nextCreates.find((row) => row.ref === ref) ?? nextUpdates.find((row) => row.ref === ref);
|
|
8573
|
+
target || (target = { ref, set: {} }, nextUpdates.push(target)), patch.signals && (target.signals = [...target.signals ?? [], ...patch.signals]), patch.timeline && (target.timeline = [...target.timeline ?? [], ...patch.timeline]), snapshot(nextUpdates, nextCreates, deletes), updates = nextUpdates, creates = nextCreates;
|
|
8357
8574
|
};
|
|
8358
8575
|
return {
|
|
8359
8576
|
create(record4) {
|
|
@@ -8363,9 +8580,15 @@ var genericData = {
|
|
|
8363
8580
|
},
|
|
8364
8581
|
update(record4, set) {
|
|
8365
8582
|
assertMutable();
|
|
8366
|
-
let
|
|
8583
|
+
let edit = captureDataUpdate(record4, set), prior = updates.find((row) => row.ref === record4), next = prior && !Object.keys(prior.set).length && prior.body === void 0 ? updates.map((row) => row === prior ? { ...prior, ...edit } : row) : [...updates, edit];
|
|
8367
8584
|
snapshot(next, creates, deletes), updates = next;
|
|
8368
8585
|
},
|
|
8586
|
+
setSignal(ref, input) {
|
|
8587
|
+
authorTable(ref, { signals: [captureSignal(input, (/* @__PURE__ */ new Date()).toISOString())] });
|
|
8588
|
+
},
|
|
8589
|
+
appendTimeline(ref, input) {
|
|
8590
|
+
authorTable(ref, { timeline: [captureTimeline(input, !0)] });
|
|
8591
|
+
},
|
|
8369
8592
|
delete(record4) {
|
|
8370
8593
|
assertMutable();
|
|
8371
8594
|
let next = [...deletes, captureDataDelete(record4)];
|
|
@@ -8738,6 +8961,14 @@ async function read(id3, names) {
|
|
|
8738
8961
|
});
|
|
8739
8962
|
}
|
|
8740
8963
|
var files = {
|
|
8964
|
+
async update(id3, changes) {
|
|
8965
|
+
let path = idPath(id3), body = JSON.stringify(parseFileUpdate(changes));
|
|
8966
|
+
return operation(async (context, signal) => {
|
|
8967
|
+
let file2 = await send(path, { method: "PATCH", headers: { "content-type": "application/json" }, body }, !0, context, signal);
|
|
8968
|
+
if (file2.id !== id3) throw unavailable4();
|
|
8969
|
+
return file2;
|
|
8970
|
+
});
|
|
8971
|
+
},
|
|
8741
8972
|
async upload(id3) {
|
|
8742
8973
|
return operation(async (context, signal) => {
|
|
8743
8974
|
let file2 = await send(`${idPath(id3)}/upload`, { method: "POST" }, !0, context, signal);
|
|
@@ -8944,30 +9175,30 @@ var AirtableOperationError = class extends Error {
|
|
|
8944
9175
|
};
|
|
8945
9176
|
|
|
8946
9177
|
var recordId = (v) => typeof v == "string" && /^rec[A-Za-z0-9]+$/.test(v), tableId = (v) => typeof v == "string" && /^tbl[A-Za-z0-9]+$/.test(v);
|
|
8947
|
-
function
|
|
9178
|
+
function fail6(message2) {
|
|
8948
9179
|
throw new AirtableOperationError(message2);
|
|
8949
9180
|
}
|
|
8950
9181
|
function object7(v) {
|
|
8951
|
-
return (!v || typeof v != "object" || Array.isArray(v) || ![null, Object.prototype].includes(Object.getPrototypeOf(v))) &&
|
|
9182
|
+
return (!v || typeof v != "object" || Array.isArray(v) || ![null, Object.prototype].includes(Object.getPrototypeOf(v))) && fail6("Invalid Airtable data"), v;
|
|
8952
9183
|
}
|
|
8953
9184
|
function keys5(v, allowed, required = allowed) {
|
|
8954
|
-
(Object.keys(v).some((k) => !allowed.includes(k)) || required.some((k) => !Object.hasOwn(v, k))) &&
|
|
9185
|
+
(Object.keys(v).some((k) => !allowed.includes(k)) || required.some((k) => !Object.hasOwn(v, k))) && fail6("Invalid Airtable input");
|
|
8955
9186
|
}
|
|
8956
9187
|
function text3(v) {
|
|
8957
9188
|
return typeof v == "string" && v.length > 0 && v.length <= 1024;
|
|
8958
9189
|
}
|
|
8959
9190
|
function fields3(v, nonempty = !1) {
|
|
8960
9191
|
let result2 = object7(v);
|
|
8961
|
-
(nonempty && !Object.keys(result2).length || Object.keys(result2).some((k) => !text3(k))) &&
|
|
9192
|
+
(nonempty && !Object.keys(result2).length || Object.keys(result2).some((k) => !text3(k))) && fail6("Invalid Airtable fields");
|
|
8962
9193
|
try {
|
|
8963
9194
|
return serializable(result2);
|
|
8964
9195
|
} catch {
|
|
8965
|
-
return
|
|
9196
|
+
return fail6("Invalid Airtable fields");
|
|
8966
9197
|
}
|
|
8967
9198
|
}
|
|
8968
9199
|
function record2(v) {
|
|
8969
9200
|
let r = object7(v);
|
|
8970
|
-
return (!recordId(r.id) || r.createdTime !== void 0 && (typeof r.createdTime != "string" || !Number.isFinite(Date.parse(r.createdTime)))) &&
|
|
9201
|
+
return (!recordId(r.id) || r.createdTime !== void 0 && (typeof r.createdTime != "string" || !Number.isFinite(Date.parse(r.createdTime)))) && fail6("Malformed Airtable record"), { id: r.id, ...r.createdTime === void 0 ? {} : { createdTime: r.createdTime }, fields: fields3(r.fields) };
|
|
8971
9202
|
}
|
|
8972
9203
|
function equal(a, b) {
|
|
8973
9204
|
if (a === b) return !0;
|
|
@@ -8982,7 +9213,7 @@ function createConnections(transport) {
|
|
|
8982
9213
|
return { async get() {
|
|
8983
9214
|
throw new Error("Connection unavailable");
|
|
8984
9215
|
}, airtable(name2) {
|
|
8985
|
-
(typeof name2 != "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(name2)) &&
|
|
9216
|
+
(typeof name2 != "string" || !/^[a-z0-9][a-z0-9-]{0,62}$/.test(name2)) && fail6("Invalid Airtable connection name");
|
|
8986
9217
|
let call = (operation2, input) => transport(name2, operation2, input);
|
|
8987
9218
|
return {
|
|
8988
9219
|
tables: { list: async () => await call("tables.list", {}) },
|
|
@@ -8998,12 +9229,12 @@ function createConnections(transport) {
|
|
|
8998
9229
|
}
|
|
8999
9230
|
async function executeAirtableOperation(authority2, operation2, raw, options = {}) {
|
|
9000
9231
|
let { name: name2, baseId, accessToken } = authority2;
|
|
9001
|
-
(!/^[a-z0-9][a-z0-9-]{0,62}$/.test(name2) || !/^app[A-Za-z0-9]+$/.test(baseId) || !/^[A-Za-z0-9._~+/-]{1,8192}={0,2}$/.test(accessToken)) &&
|
|
9232
|
+
(!/^[a-z0-9][a-z0-9-]{0,62}$/.test(name2) || !/^app[A-Za-z0-9]+$/.test(baseId) || !/^[A-Za-z0-9._~+/-]{1,8192}={0,2}$/.test(accessToken)) && fail6("Airtable connection unavailable");
|
|
9002
9233
|
let input;
|
|
9003
9234
|
try {
|
|
9004
9235
|
input = object7(serializable(raw));
|
|
9005
9236
|
} catch {
|
|
9006
|
-
return
|
|
9237
|
+
return fail6("Invalid Airtable input");
|
|
9007
9238
|
}
|
|
9008
9239
|
let mutation = ["records.create", "records.update", "records.delete"].includes(operation2), receipt = (ids2) => ({
|
|
9009
9240
|
provider: "airtable",
|
|
@@ -9042,58 +9273,58 @@ async function executeAirtableOperation(authority2, operation2, raw, options = {
|
|
|
9042
9273
|
let tables = [], seen = /* @__PURE__ */ new Set(), offset;
|
|
9043
9274
|
do {
|
|
9044
9275
|
let query2 = new URLSearchParams(offset ? { offset } : {}), page = await request3(`meta/bases/${baseId}/tables?${query2}`);
|
|
9045
|
-
Array.isArray(page.tables) ||
|
|
9276
|
+
Array.isArray(page.tables) || fail6("Malformed Airtable tables");
|
|
9046
9277
|
for (let value of page.tables) {
|
|
9047
9278
|
let t = object7(value);
|
|
9048
|
-
(!tableId(t.id) || !text3(t.name) || !text3(t.primaryFieldId) || !Array.isArray(t.fields) || tables.some((existing) => existing.id === t.id)) &&
|
|
9279
|
+
(!tableId(t.id) || !text3(t.name) || !text3(t.primaryFieldId) || !Array.isArray(t.fields) || tables.some((existing) => existing.id === t.id)) && fail6("Malformed Airtable table");
|
|
9049
9280
|
let metadata = t.fields.map((value2) => {
|
|
9050
9281
|
let f = object7(value2);
|
|
9051
|
-
return (typeof f.id != "string" || !/^fld[A-Za-z0-9]+$/.test(f.id) || !text3(f.name) || !text3(f.type)) &&
|
|
9282
|
+
return (typeof f.id != "string" || !/^fld[A-Za-z0-9]+$/.test(f.id) || !text3(f.name) || !text3(f.type)) && fail6("Malformed Airtable field"), { id: f.id, name: f.name, type: f.type, ...f.options === void 0 ? {} : { options: serializable(f.options) } };
|
|
9052
9283
|
});
|
|
9053
|
-
(!metadata.some((f) => f.id === t.primaryFieldId) || new Set(metadata.map((f) => f.id)).size !== metadata.length) &&
|
|
9284
|
+
(!metadata.some((f) => f.id === t.primaryFieldId) || new Set(metadata.map((f) => f.id)).size !== metadata.length) && fail6("Malformed Airtable fields"), tables.push({ id: t.id, name: t.name, primaryFieldId: t.primaryFieldId, fields: metadata });
|
|
9054
9285
|
}
|
|
9055
9286
|
offset = nextOffset(page.offset, seen);
|
|
9056
9287
|
} while (offset);
|
|
9057
9288
|
return tables;
|
|
9058
9289
|
}
|
|
9059
|
-
(!text3(input.table) || input.table === "." || input.table === "..") &&
|
|
9290
|
+
(!text3(input.table) || input.table === "." || input.table === "..") && fail6("Invalid Airtable table"), mutation && !tableId(input.table) && fail6("Airtable writes require a stable table ID");
|
|
9060
9291
|
let path = `${baseId}/${encodeURIComponent(input.table)}`;
|
|
9061
9292
|
if (operation2 === "records.get") {
|
|
9062
|
-
keys5(input, ["table", "id"]), recordId(input.id) ||
|
|
9293
|
+
keys5(input, ["table", "id"]), recordId(input.id) || fail6("Invalid Airtable record ID");
|
|
9063
9294
|
let result3 = record2(await request3(`${path}/${input.id}`));
|
|
9064
|
-
return result3.id !== input.id &&
|
|
9295
|
+
return result3.id !== input.id && fail6("Malformed Airtable record"), result3;
|
|
9065
9296
|
}
|
|
9066
9297
|
if (operation2 === "records.list") {
|
|
9067
|
-
keys5(input, ["table", "fields"], ["table"]), input.fields !== void 0 && (!Array.isArray(input.fields) || !input.fields.length || input.fields.some((f) => !text3(f)) || new Set(input.fields).size !== input.fields.length) &&
|
|
9298
|
+
keys5(input, ["table", "fields"], ["table"]), input.fields !== void 0 && (!Array.isArray(input.fields) || !input.fields.length || input.fields.some((f) => !text3(f)) || new Set(input.fields).size !== input.fields.length) && fail6("Invalid Airtable field selection");
|
|
9068
9299
|
let records2 = [], ids2 = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new Set(), offset;
|
|
9069
9300
|
do {
|
|
9070
9301
|
let query2 = new URLSearchParams();
|
|
9071
9302
|
for (let field of input.fields ?? []) query2.append("fields[]", field);
|
|
9072
9303
|
offset && query2.set("offset", offset);
|
|
9073
9304
|
let page = await request3(`${path}?${query2}`);
|
|
9074
|
-
Array.isArray(page.records) ||
|
|
9305
|
+
Array.isArray(page.records) || fail6("Malformed Airtable records");
|
|
9075
9306
|
for (let value of page.records) {
|
|
9076
9307
|
let r = record2(value);
|
|
9077
|
-
ids2.has(r.id) &&
|
|
9308
|
+
ids2.has(r.id) && fail6("Malformed Airtable pagination"), ids2.add(r.id), records2.push(r);
|
|
9078
9309
|
}
|
|
9079
9310
|
offset = nextOffset(page.offset, seen);
|
|
9080
9311
|
} while (offset);
|
|
9081
9312
|
return records2;
|
|
9082
9313
|
}
|
|
9083
|
-
mutation ||
|
|
9314
|
+
mutation || fail6("Unsupported Airtable operation"), keys5(input, ["table", "records"]), (!Array.isArray(input.records) || !input.records.length || input.records.length > 10) && fail6("Invalid Airtable batch");
|
|
9084
9315
|
let kind = operation2.slice(8), ids = /* @__PURE__ */ new Set(), records = input.records.map((value) => {
|
|
9085
9316
|
let r = object7(value);
|
|
9086
9317
|
if (keys5(r, kind === "create" ? ["fields"] : kind === "update" ? ["id", "expected", "set"] : ["id", "expected"]), kind === "create") return { fields: fields3(r.fields, !0) };
|
|
9087
|
-
(!recordId(r.id) || ids.has(r.id)) &&
|
|
9318
|
+
(!recordId(r.id) || ids.has(r.id)) && fail6("Invalid Airtable batch record ID"), ids.add(r.id);
|
|
9088
9319
|
let set = kind === "update" ? fields3(r.set, !0) : void 0;
|
|
9089
|
-
return set && Object.values(set).some((value2) => value2 === null) &&
|
|
9320
|
+
return set && Object.values(set).some((value2) => value2 === null) && fail6("Airtable guard null cannot be an update value"), { id: r.id, expected: fields3(r.expected), ...set ? { set } : {} };
|
|
9090
9321
|
});
|
|
9091
9322
|
for (let r of records) {
|
|
9092
9323
|
if (!("id" in r)) continue;
|
|
9093
9324
|
let current2 = record2(await request3(`${path}/${r.id}`));
|
|
9094
|
-
current2.id !== r.id &&
|
|
9325
|
+
current2.id !== r.id && fail6("Malformed Airtable record");
|
|
9095
9326
|
for (let [key, value] of Object.entries(r.expected))
|
|
9096
|
-
(value === null ? Object.hasOwn(current2.fields, key) : !Object.hasOwn(current2.fields, key) || !equal(current2.fields[key], value)) &&
|
|
9327
|
+
(value === null ? Object.hasOwn(current2.fields, key) : !Object.hasOwn(current2.fields, key) || !equal(current2.fields[key], value)) && fail6("Airtable reviewed values are stale");
|
|
9097
9328
|
}
|
|
9098
9329
|
await options.beforeMutation?.();
|
|
9099
9330
|
let query = new URLSearchParams();
|
|
@@ -9121,7 +9352,7 @@ async function executeAirtableOperation(authority2, operation2, raw, options = {
|
|
|
9121
9352
|
}
|
|
9122
9353
|
function nextOffset(value, seen) {
|
|
9123
9354
|
if (value !== void 0)
|
|
9124
|
-
return (!text3(value) || seen.has(value)) &&
|
|
9355
|
+
return (!text3(value) || seen.has(value)) && fail6("Malformed Airtable pagination"), seen.add(value), value;
|
|
9125
9356
|
}
|
|
9126
9357
|
|
|
9127
9358
|
var MANAGED_CONNECTION_CAPABILITY_ENV = "OS_MANAGED_CONNECTION_CAPABILITY";
|
|
@@ -10693,14 +10924,14 @@ function createBrowserAuth(runtime) {
|
|
|
10693
10924
|
let revision = c.revision, person = c.session.user.id, controller = new AbortController(), deadline = Date.now() + 15e3, finish, promise = new Promise((resolve) => {
|
|
10694
10925
|
finish = resolve;
|
|
10695
10926
|
}), resolution2 = { promise, checkBound() {
|
|
10696
|
-
Date.now() >= deadline &&
|
|
10927
|
+
Date.now() >= deadline && fail8();
|
|
10697
10928
|
}, complete() {
|
|
10698
10929
|
c.resolution === resolution2 && (clearTimeout(timer), c.resolution = void 0, finish());
|
|
10699
10930
|
}, cancel() {
|
|
10700
10931
|
c.resolution === resolution2 && (resolution2.complete(), controller.abort());
|
|
10701
10932
|
} };
|
|
10702
10933
|
c.resolution = resolution2;
|
|
10703
|
-
let
|
|
10934
|
+
let fail8 = (error) => {
|
|
10704
10935
|
if (c.resolution === resolution2) {
|
|
10705
10936
|
if (terminalSessionFailure(error)) {
|
|
10706
10937
|
expire(c);
|
|
@@ -10712,7 +10943,7 @@ function createBrowserAuth(runtime) {
|
|
|
10712
10943
|
}
|
|
10713
10944
|
c.revision++, resolution2.cancel(), c.timer && clearTimeout(c.timer), publish2(c, { status: "unavailable", account: c.state.account, error: "unavailable" });
|
|
10714
10945
|
}
|
|
10715
|
-
}, timer = setTimeout(() =>
|
|
10946
|
+
}, timer = setTimeout(() => fail8(), 15e3);
|
|
10716
10947
|
return validSession(c.session) || publish2(c, { status: "reconnecting", account: c.state.account, pending: c.state.pending }), Promise.resolve().then(async () => {
|
|
10717
10948
|
if (c.resolution === resolution2)
|
|
10718
10949
|
try {
|
|
@@ -10723,16 +10954,16 @@ function createBrowserAuth(runtime) {
|
|
|
10723
10954
|
return;
|
|
10724
10955
|
}
|
|
10725
10956
|
if (result2.error) {
|
|
10726
|
-
|
|
10957
|
+
fail8(result2.error);
|
|
10727
10958
|
return;
|
|
10728
10959
|
}
|
|
10729
10960
|
if (!result2.data.session || !validSession(result2.data.session)) {
|
|
10730
|
-
|
|
10961
|
+
fail8();
|
|
10731
10962
|
return;
|
|
10732
10963
|
}
|
|
10733
10964
|
accept(c, result2.data.session.user.id === person ? "TOKEN_REFRESHED" : "SIGNED_IN", result2.data.session), resolution2.complete();
|
|
10734
10965
|
} catch (error) {
|
|
10735
|
-
|
|
10966
|
+
fail8(error);
|
|
10736
10967
|
}
|
|
10737
10968
|
}), promise;
|
|
10738
10969
|
}
|
|
@@ -11299,26 +11530,26 @@ var identifier = /^[a-z0-9]+(?:-[a-z0-9]+)*(?![\s\S])/, uuid3 = /^[0-9a-f]{8}-[0
|
|
|
11299
11530
|
this.name = "AppRoutineError";
|
|
11300
11531
|
}
|
|
11301
11532
|
reason;
|
|
11302
|
-
},
|
|
11533
|
+
}, fail7 = (reason) => {
|
|
11303
11534
|
throw new AppRoutineError(reason);
|
|
11304
11535
|
};
|
|
11305
11536
|
function current(context) {
|
|
11306
|
-
(!context.isCurrent() || context.kind === "local" && context.signal.aborted) &&
|
|
11537
|
+
(!context.isCurrent() || context.kind === "local" && context.signal.aborted) && fail7("authority_unavailable");
|
|
11307
11538
|
}
|
|
11308
11539
|
function appDescriptors() {
|
|
11309
11540
|
return globalThis[/* @__PURE__ */ Symbol.for("oddington.app.descriptor")]?.routines ?? [];
|
|
11310
11541
|
}
|
|
11311
11542
|
async function authority(retained = !1) {
|
|
11312
|
-
let context = await resolveAppContext(retained).catch(() =>
|
|
11313
|
-
return current(context), context.kind !== "local" && (!context.binding || !context.memberId || !identifier.test(context.workspace) || context.workspace.length > 63 || ["auth", "api", "os", "www"].includes(context.workspace) || context.endpoint !== `https://${context.workspace}.oddington.ai`) &&
|
|
11543
|
+
let context = await resolveAppContext(retained).catch(() => fail7("authority_unavailable"));
|
|
11544
|
+
return current(context), context.kind !== "local" && (!context.binding || !context.memberId || !identifier.test(context.workspace) || context.workspace.length > 63 || ["auth", "api", "os", "www"].includes(context.workspace) || context.endpoint !== `https://${context.workspace}.oddington.ai`) && fail7("authority_unavailable"), context;
|
|
11314
11545
|
}
|
|
11315
11546
|
async function live(context, read2) {
|
|
11316
11547
|
if (current(context), context.kind === "local") return context;
|
|
11317
11548
|
let resolved = await authority(read2);
|
|
11318
|
-
return current(context), (resolved.kind === "local" || resolved.binding !== context.binding || resolved.memberId !== context.memberId || resolved.workspace !== context.workspace || resolved.endpoint !== context.endpoint) &&
|
|
11549
|
+
return current(context), (resolved.kind === "local" || resolved.binding !== context.binding || resolved.memberId !== context.memberId || resolved.workspace !== context.workspace || resolved.endpoint !== context.endpoint) && fail7("authority_unavailable"), resolved;
|
|
11319
11550
|
}
|
|
11320
11551
|
async function request2(key, suffix, init2, maximum = SUMMARY_BYTES, retained, read2 = !1) {
|
|
11321
|
-
(!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) &&
|
|
11552
|
+
(!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) && fail7("authority_unavailable");
|
|
11322
11553
|
let context = retained ? await live(retained, read2) : await authority(read2);
|
|
11323
11554
|
current(context);
|
|
11324
11555
|
let deadline = new AbortController(), timeout = context.kind === "local" ? void 0 : setTimeout(() => deadline.abort(), 2e4);
|
|
@@ -11330,22 +11561,22 @@ async function request2(key, suffix, init2, maximum = SUMMARY_BYTES, retained, r
|
|
|
11330
11561
|
signal: deadline.signal,
|
|
11331
11562
|
headers: { authorization: `Bearer ${context.accessToken}`, ...init2?.body ? { "content-type": "application/json" } : {} }
|
|
11332
11563
|
}));
|
|
11333
|
-
response2.redirected &&
|
|
11564
|
+
response2.redirected && fail7("execution_unavailable");
|
|
11334
11565
|
let value = await appResponse(response2, maximum, context.kind === "local" ? context.signal : deadline.signal);
|
|
11335
11566
|
if (current(context), context.kind !== "local" && await live(context, read2), !response2.ok) {
|
|
11336
11567
|
if (context.kind !== "local") {
|
|
11337
11568
|
let code = value?.code;
|
|
11338
|
-
if ((code === "authentication_required" || code === "access_denied") &&
|
|
11569
|
+
if ((code === "authentication_required" || code === "access_denied") && fail7("authority_unavailable"), (code === "input_invalid" || code === "file_not_remote") && fail7("invalid_input"), suffix === "describe" && (code === "current_deployment_unavailable" || code === "capability_unavailable"))
|
|
11339
11570
|
return unavailable6(key, code === "current_deployment_unavailable" ? "not_deployed" : "capability_unavailable");
|
|
11340
|
-
|
|
11571
|
+
fail7("execution_unavailable");
|
|
11341
11572
|
}
|
|
11342
11573
|
let reason = value?.error;
|
|
11343
|
-
reason === "authority_unavailable" && (context.kind === "local" && context.invalidate(),
|
|
11574
|
+
reason === "authority_unavailable" && (context.kind === "local" && context.invalidate(), fail7(reason)), (reason === "invalid_input" || reason === "execution_unavailable") && fail7(reason), fail7("execution_unavailable");
|
|
11344
11575
|
}
|
|
11345
11576
|
return value;
|
|
11346
11577
|
} catch (error) {
|
|
11347
11578
|
if (current(context), error instanceof AppRoutineError) throw error;
|
|
11348
|
-
|
|
11579
|
+
fail7("execution_unavailable");
|
|
11349
11580
|
} finally {
|
|
11350
11581
|
clearTimeout(timeout);
|
|
11351
11582
|
}
|
|
@@ -11353,12 +11584,12 @@ async function request2(key, suffix, init2, maximum = SUMMARY_BYTES, retained, r
|
|
|
11353
11584
|
function summary(value, key, context, id3) {
|
|
11354
11585
|
if (context.kind !== "local")
|
|
11355
11586
|
try {
|
|
11356
|
-
return (!only(value, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure") || !Array.isArray(value.steps) || value.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable")) || value.failure !== void 0 && !validFailure(value.failure, value.steps)) &&
|
|
11587
|
+
return (!only(value, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure") || !Array.isArray(value.steps) || value.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable")) || value.failure !== void 0 && !validFailure(value.failure, value.steps)) && fail7("execution_unavailable"), parseRemoteRun(value, { routine: key, id: id3 });
|
|
11357
11588
|
} catch {
|
|
11358
|
-
return
|
|
11589
|
+
return fail7("execution_unavailable");
|
|
11359
11590
|
}
|
|
11360
11591
|
let run = value;
|
|
11361
|
-
return (!only(run, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure,local") || typeof run.id != "string" || !uuid3.test(run.id) || id3 !== void 0 && run.id !== id3 || run.routine !== key || run.placement !== "local" || !["queued", "running", "succeeded", "failed", "legacy"].includes(run.status) || !timestamp(run.createdAt) || !optionalTimes(run) || !Array.isArray(run.steps) || run.steps.length > 64 || run.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable") || typeof step.detailAvailable != "boolean" || !validStep(step)) || new Set(run.steps.map((step) => step.id)).size !== run.steps.length || Object.hasOwn(run, "result") && (run.status !== "succeeded" || !bounded2(run.result)) || run.failure !== void 0 && (run.status !== "failed" || !validFailure(run.failure, run.steps)) || run.local !== void 0 && !validLocalActivity(run.local)) &&
|
|
11592
|
+
return (!only(run, "id,routine,placement,status,createdAt,startedAt,finishedAt,steps,result,failure,local") || typeof run.id != "string" || !uuid3.test(run.id) || id3 !== void 0 && run.id !== id3 || run.routine !== key || run.placement !== "local" || !["queued", "running", "succeeded", "failed", "legacy"].includes(run.status) || !timestamp(run.createdAt) || !optionalTimes(run) || !Array.isArray(run.steps) || run.steps.length > 64 || run.steps.some((step) => !only(step, "id,title,status,startedAt,finishedAt,progress,summary,detailAvailable") || typeof step.detailAvailable != "boolean" || !validStep(step)) || new Set(run.steps.map((step) => step.id)).size !== run.steps.length || Object.hasOwn(run, "result") && (run.status !== "succeeded" || !bounded2(run.result)) || run.failure !== void 0 && (run.status !== "failed" || !validFailure(run.failure, run.steps)) || run.local !== void 0 && !validLocalActivity(run.local)) && fail7("execution_unavailable"), run;
|
|
11362
11593
|
}
|
|
11363
11594
|
function validFailure(value, steps) {
|
|
11364
11595
|
if (!only(value, "message,code,step,sizeBytes,limitBytes,summaryBytes,dataBytes") || !message(value.message)) return !1;
|
|
@@ -11402,14 +11633,14 @@ function validLocalActivity(value) {
|
|
|
11402
11633
|
}
|
|
11403
11634
|
function jsonInput(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
11404
11635
|
if (value === null || typeof value == "string" || typeof value == "boolean" || typeof value == "number" && Number.isFinite(value)) return;
|
|
11405
|
-
if (!value || typeof value != "object" || ancestors.has(value)) return
|
|
11636
|
+
if (!value || typeof value != "object" || ancestors.has(value)) return fail7("invalid_input");
|
|
11406
11637
|
let array3 = Array.isArray(value), keys7 = Reflect.ownKeys(value);
|
|
11407
|
-
if (!array3 && ![Object.prototype, null].includes(Object.getPrototypeOf(value)) || array3 && (keys7.length !== value.length + 1 || !Array.from({ length: value.length }, (_, index) => Object.hasOwn(value, index)).every(Boolean))) return
|
|
11638
|
+
if (!array3 && ![Object.prototype, null].includes(Object.getPrototypeOf(value)) || array3 && (keys7.length !== value.length + 1 || !Array.from({ length: value.length }, (_, index) => Object.hasOwn(value, index)).every(Boolean))) return fail7("invalid_input");
|
|
11408
11639
|
ancestors.add(value);
|
|
11409
11640
|
for (let key of keys7) {
|
|
11410
11641
|
if (array3 && key === "length") continue;
|
|
11411
11642
|
let descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
11412
|
-
if (typeof key != "string" || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) return
|
|
11643
|
+
if (typeof key != "string" || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) return fail7("invalid_input");
|
|
11413
11644
|
jsonInput(descriptor.value, ancestors);
|
|
11414
11645
|
}
|
|
11415
11646
|
ancestors.delete(value);
|
|
@@ -11418,22 +11649,22 @@ function structure(value) {
|
|
|
11418
11649
|
return JSON.stringify(value, (_key, item) => item && typeof item == "object" && !Array.isArray(item) ? Object.fromEntries(Object.keys(item).sort().map((key) => [key, item[key]])) : item);
|
|
11419
11650
|
}
|
|
11420
11651
|
function handle(key, id3, context) {
|
|
11421
|
-
(!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) &&
|
|
11652
|
+
(!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) && fail7("authority_unavailable"), (typeof id3 != "string" || !uuid3.test(id3)) && fail7("invalid_input");
|
|
11422
11653
|
let read2 = async () => summary(await request2(key, `runs/${id3}`, void 0, SUMMARY_BYTES, context, !0), key, context, id3);
|
|
11423
11654
|
return routineRunHandle({
|
|
11424
11655
|
async current() {
|
|
11425
11656
|
return current(context), read2();
|
|
11426
11657
|
},
|
|
11427
11658
|
async step(step) {
|
|
11428
|
-
(typeof step != "string" || !identifier.test(step)) &&
|
|
11659
|
+
(typeof step != "string" || !identifier.test(step)) && fail7("invalid_input");
|
|
11429
11660
|
let value = await request2(key, `runs/${id3}/steps/${step}`, void 0, ROUTINE_STEP_OUTPUT_BYTES + 4096, context, !0);
|
|
11430
11661
|
if (context.kind !== "local")
|
|
11431
11662
|
try {
|
|
11432
|
-
return only(value, "id,title,status,startedAt,finishedAt,progress,summary,data") ||
|
|
11663
|
+
return only(value, "id,title,status,startedAt,finishedAt,progress,summary,data") || fail7("execution_unavailable"), parseRunStep(value, step);
|
|
11433
11664
|
} catch {
|
|
11434
|
-
return
|
|
11665
|
+
return fail7("execution_unavailable");
|
|
11435
11666
|
}
|
|
11436
|
-
return (!only(value, "id,title,status,startedAt,finishedAt,progress,summary,data") || value.id !== step || !validStep(value)) &&
|
|
11667
|
+
return (!only(value, "id,title,status,startedAt,finishedAt,progress,summary,data") || value.id !== step || !validStep(value)) && fail7("execution_unavailable"), value;
|
|
11437
11668
|
}
|
|
11438
11669
|
});
|
|
11439
11670
|
}
|
|
@@ -11446,7 +11677,7 @@ function unavailable6(key, reason) {
|
|
|
11446
11677
|
};
|
|
11447
11678
|
}
|
|
11448
11679
|
function deployedDescription(value, key) {
|
|
11449
|
-
(!only(value, "id,title,input,connections,steps,readiness") || value.id !== key || value.title !== void 0 && (typeof value.title != "string" || !value.title.trim() || value.title.length > 256) || !only(value.input, "type,properties,required,additionalProperties,items,maxItems,maxLength,minimum,maximum,storage,path,default") || !Array.isArray(value.steps) || value.steps.length > 64 || value.steps.some((step) => !only(step, "id,title") || typeof step.title != "string" || !step.title.trim() || step.title.length > 256) || !Array.isArray(value.connections) || value.connections.length > 64 || value.connections.some((item) => !only(item, "id,provider,name,available") || typeof item.available != "boolean" || typeof item.provider != "string" || !identifier.test(item.provider) || typeof item.name != "string" || !identifier.test(item.name) || item.id !== `${item.provider}/${item.name}`) || new Set(value.connections.map((item) => item.id)).size !== value.connections.length) &&
|
|
11680
|
+
(!only(value, "id,title,input,connections,steps,readiness") || value.id !== key || value.title !== void 0 && (typeof value.title != "string" || !value.title.trim() || value.title.length > 256) || !only(value.input, "type,properties,required,additionalProperties,items,maxItems,maxLength,minimum,maximum,storage,path,default") || !Array.isArray(value.steps) || value.steps.length > 64 || value.steps.some((step) => !only(step, "id,title") || typeof step.title != "string" || !step.title.trim() || step.title.length > 256) || !Array.isArray(value.connections) || value.connections.length > 64 || value.connections.some((item) => !only(item, "id,provider,name,available") || typeof item.available != "boolean" || typeof item.provider != "string" || !identifier.test(item.provider) || typeof item.name != "string" || !identifier.test(item.name) || item.id !== `${item.provider}/${item.name}`) || new Set(value.connections.map((item) => item.id)).size !== value.connections.length) && fail7("execution_unavailable");
|
|
11450
11681
|
let { default: inputDefault, ...input } = value.input, contract = parseAppRoutineContract({
|
|
11451
11682
|
routine: key,
|
|
11452
11683
|
input,
|
|
@@ -11456,29 +11687,29 @@ function deployedDescription(value, key) {
|
|
|
11456
11687
|
}
|
|
11457
11688
|
async function describeAppRoutine(key) {
|
|
11458
11689
|
let descriptor = appDescriptors().find((item) => item.id === key);
|
|
11459
|
-
if (!descriptor) return
|
|
11690
|
+
if (!descriptor) return fail7("authority_unavailable");
|
|
11460
11691
|
try {
|
|
11461
11692
|
let context = await authority(), value = await request2(key, "describe", void 0, 1024 * 1024, context);
|
|
11462
|
-
return context.kind !== "local" && deployedDescription(value, key), (!only(value, "id,title,input,connections,steps,readiness") || !value.readiness || !Array.isArray(value.connections) || context.kind === "local" && structure({ ...value, readiness: void 0, connections: value.connections.map(({ available, ...item }) => item) }) !== structure(descriptor) || value.connections.some((item) => typeof item.available != "boolean") || !(value.readiness.state === "ready" && only(value.readiness, "state,placement") && value.readiness.placement === (context.kind === "local" ? "local" : "remote") || value.readiness.state === "unavailable" && only(value.readiness, "state,reason,message") && ["not_deployed", "definition_invalid", "capability_unavailable"].includes(value.readiness.reason) && message(value.readiness.message))) &&
|
|
11693
|
+
return context.kind !== "local" && deployedDescription(value, key), (!only(value, "id,title,input,connections,steps,readiness") || !value.readiness || !Array.isArray(value.connections) || context.kind === "local" && structure({ ...value, readiness: void 0, connections: value.connections.map(({ available, ...item }) => item) }) !== structure(descriptor) || value.connections.some((item) => typeof item.available != "boolean") || !(value.readiness.state === "ready" && only(value.readiness, "state,placement") && value.readiness.placement === (context.kind === "local" ? "local" : "remote") || value.readiness.state === "unavailable" && only(value.readiness, "state,reason,message") && ["not_deployed", "definition_invalid", "capability_unavailable"].includes(value.readiness.reason) && message(value.readiness.message))) && fail7("execution_unavailable"), value;
|
|
11463
11694
|
} catch {
|
|
11464
11695
|
return unavailable6(key, "capability_unavailable");
|
|
11465
11696
|
}
|
|
11466
11697
|
}
|
|
11467
11698
|
function appRoutineBinding(key) {
|
|
11468
|
-
return (typeof key != "string" || !identifier.test(key) || !appDescriptors().some((item) => item.id === key)) &&
|
|
11699
|
+
return (typeof key != "string" || !identifier.test(key) || !appDescriptors().some((item) => item.id === key)) && fail7("authority_unavailable"), Object.freeze({
|
|
11469
11700
|
describe: () => describeAppRoutine(key),
|
|
11470
11701
|
async run(...args) {
|
|
11471
|
-
args.length > 1 &&
|
|
11702
|
+
args.length > 1 && fail7("invalid_input");
|
|
11472
11703
|
let encoded;
|
|
11473
11704
|
try {
|
|
11474
11705
|
if (args[0] === void 0) encoded = "{}";
|
|
11475
11706
|
else {
|
|
11476
11707
|
jsonInput(args[0]);
|
|
11477
11708
|
let input = JSON.stringify(args[0]);
|
|
11478
|
-
new TextEncoder().encode(input).byteLength > 256 * 1024 &&
|
|
11709
|
+
new TextEncoder().encode(input).byteLength > 256 * 1024 && fail7("invalid_input"), encoded = `{"input":${input}}`;
|
|
11479
11710
|
}
|
|
11480
11711
|
} catch {
|
|
11481
|
-
return
|
|
11712
|
+
return fail7("invalid_input");
|
|
11482
11713
|
}
|
|
11483
11714
|
let context = await authority();
|
|
11484
11715
|
context.kind !== "local" && (encoded = JSON.stringify({ ...JSON.parse(encoded), startKey: crypto.randomUUID() }));
|
|
@@ -11488,12 +11719,12 @@ function appRoutineBinding(key) {
|
|
|
11488
11719
|
runs: Object.freeze({
|
|
11489
11720
|
async list() {
|
|
11490
11721
|
let context = await authority(!0), value = await request2(key, "runs", void 0, 20 * SUMMARY_BYTES, context, !0);
|
|
11491
|
-
if (!Array.isArray(value) || value.length > 20) return
|
|
11722
|
+
if (!Array.isArray(value) || value.length > 20) return fail7("execution_unavailable");
|
|
11492
11723
|
let runs = value.map((run) => summary(run, key, context));
|
|
11493
|
-
return new Set(runs.map((run) => run.id)).size !== runs.length &&
|
|
11724
|
+
return new Set(runs.map((run) => run.id)).size !== runs.length && fail7("execution_unavailable"), runs;
|
|
11494
11725
|
},
|
|
11495
11726
|
async get(id3) {
|
|
11496
|
-
return (typeof id3 != "string" || !uuid3.test(id3)) &&
|
|
11727
|
+
return (typeof id3 != "string" || !uuid3.test(id3)) && fail7("invalid_input"), (!identifier.test(key) || !appDescriptors().some((item) => item.id === key)) && fail7("authority_unavailable"), handle(key, id3, await authority(!0));
|
|
11497
11728
|
}
|
|
11498
11729
|
})
|
|
11499
11730
|
});
|