apps 0.0.1-beta.3 → 0.0.1-beta.31
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/README.md +68 -44
- package/framework-reference.json +1 -1
- package/js/{chunk-RN2MXB4R.js → chunk-3FJYVAE4.js} +128 -24
- package/js/chunk-4OKYLVU4.js +118 -0
- package/js/{chunk-LGIYBDWA.js → chunk-5DLG2FVN.js} +65 -1
- package/js/{chunk-PLCMJREA.js → chunk-5JVNM3CQ.js} +60 -20
- package/js/chunk-5XJR4XGW.js +254 -0
- package/js/{chunk-FZJOYIZO.js → chunk-6KG4DZD7.js} +1 -1
- package/js/{chunk-EVJUVWN2.js → chunk-6ZJ2H6P4.js} +2 -2
- package/js/{chunk-NQ3OMCA5.js → chunk-AUFVX4KM.js} +2 -2
- package/js/{chunk-D47C7KG5.js → chunk-AYM2FUI5.js} +2 -2
- package/js/{chunk-5MQZEB6Y.js → chunk-BGALSHLT.js} +37 -12
- package/js/{chunk-QKHR7BMF.js → chunk-CJY5X26R.js} +3 -3
- package/js/{chunk-M6ZRRIBI.js → chunk-DASNNAP4.js} +1 -1
- package/js/{chunk-ZCAMUXSG.js → chunk-ETLILMHY.js} +3 -4
- package/js/{chunk-FW5HBOIK.js → chunk-EXGKN554.js} +2005 -1710
- package/js/{chunk-SATWJKN6.js → chunk-FBBXFFFJ.js} +1 -1
- package/js/{chunk-JN55AYQH.js → chunk-FULRJSWU.js} +61 -32
- package/js/{chunk-HDTGZWP2.js → chunk-GG566OOE.js} +139 -32
- package/js/chunk-GZ4UHXRT.js +92 -0
- package/js/{chunk-YEJOQEII.js → chunk-HW3DPBZR.js} +45 -7
- package/js/{chunk-HDJH3RPR.js → chunk-MFHUR5SB.js} +2 -2
- package/js/{chunk-MYYEW3RA.js → chunk-N72RKJ5E.js} +984 -61
- package/js/{chunk-WFSQXYUT.js → chunk-NPGRURDG.js} +390 -18
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-FDNTX5QJ.js → chunk-OX233L7N.js} +2 -2
- package/js/{chunk-G7ZIRKMK.js → chunk-QYM4STZW.js} +118 -197
- package/js/chunk-RULZPNGP.js +801 -0
- package/js/{chunk-BMOIAIVR.js → chunk-UMCMZFXW.js} +49 -1
- package/js/{chunk-J7O55ZV7.js → chunk-W7F23NQ2.js} +419 -191
- package/js/chunk-WG5DFZFT.js +42 -0
- package/js/{chunk-T2LAZCAD.js → chunk-ZOY7PDMI.js} +1 -1
- package/js/client.js +120 -84
- package/js/contracts.js +110 -16
- package/js/effect.js +20 -20
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +58 -54
- package/js/host.js +20 -20
- package/js/index.js +247 -204
- package/js/mcp/effect.js +24 -22
- package/js/mcp/stdio.js +35 -30
- package/js/mcp.js +105 -68
- package/js/openapi.js +4087 -1503
- package/js/react.js +3 -3
- package/js/skills/effect.js +5 -3
- package/js/skills.js +15 -15
- package/js/storage/facet.js +4 -4
- package/js/ui/auth/contracts.js +2 -2
- package/js/ui/auth.js +5 -5
- package/js/ui/contracts.js +5 -4
- package/js/ui/serving.js +8516 -214
- package/package.json +1 -1
- package/runtime.json +1 -1
- package/types/app-data/src/contracts/database.d.ts +33 -6
- package/types/app-data/src/implementation/schema.d.ts +2 -17
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -6
- package/types/apps/src/contracts/failure.d.ts +54 -0
- package/types/apps/src/contracts/graphql.d.ts +2 -1
- package/types/apps/src/contracts/host.d.ts +34 -11
- package/types/apps/src/contracts/mcp.d.ts +91 -10
- package/types/apps/src/contracts/network.d.ts +84 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +31 -3
- package/types/apps/src/contracts/openapi.d.ts +45 -9
- package/types/apps/src/contracts/operations.d.ts +5 -6
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +251 -69
- package/types/apps/src/contracts/protocols/2.d.ts +710 -0
- package/types/apps/src/contracts/protocols/3.d.ts +716 -0
- package/types/apps/src/contracts/protocols/4.d.ts +1298 -0
- package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
- package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1119 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +115 -10
- package/types/apps/src/contracts/router.d.ts +59 -0
- package/types/apps/src/contracts/skills.d.ts +18 -5
- package/types/apps/src/contracts/storage.d.ts +3 -3
- package/types/apps/src/contracts/ui.d.ts +18 -0
- package/types/apps/src/contracts/workflows.d.ts +34 -3
- package/types/apps/src/graphql.d.ts +1 -3
- package/types/apps/src/implementation/account-router.d.ts +12 -0
- package/types/apps/src/implementation/app.d.ts +5 -4
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/catalog-cache.d.ts +34 -4
- package/types/apps/src/implementation/elicitation.d.ts +9 -9
- package/types/apps/src/implementation/failure-detail.d.ts +46 -0
- package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
- package/types/apps/src/implementation/graphql.d.ts +4 -3
- package/types/apps/src/implementation/input-problems.d.ts +4 -1
- package/types/apps/src/implementation/mcp-call.d.ts +6 -5
- package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
- package/types/apps/src/implementation/mcp-client.d.ts +49 -25
- package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
- package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
- package/types/apps/src/implementation/mcp.d.ts +52 -25
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
- package/types/apps/src/implementation/openapi-document.d.ts +46 -19
- package/types/apps/src/implementation/openapi-names.d.ts +9 -4
- package/types/apps/src/implementation/openapi-request.d.ts +10 -2
- package/types/apps/src/implementation/openapi-source.d.ts +8 -6
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +36 -3
- package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +19 -5
- package/types/apps/src/implementation/router-catalog.d.ts +224 -0
- package/types/apps/src/implementation/router.d.ts +68 -0
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schema.d.ts +80 -1
- package/types/apps/src/implementation/skills.d.ts +2 -2
- package/types/apps/src/implementation/storage.d.ts +5 -3
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-client.d.ts +2 -2
- package/types/apps/src/implementation/ui-document.d.ts +5 -0
- package/types/apps/src/implementation/ui-errors.d.ts +1 -1
- package/types/apps/src/implementation/ui-serving.d.ts +10 -4
- package/types/apps/src/implementation/ui-watch.d.ts +1 -1
- package/types/apps/src/implementation/upstream-error.d.ts +7 -0
- package/types/apps/src/implementation/webhooks.d.ts +1 -1
- package/types/apps/src/implementation/workflow-context.d.ts +11 -3
- package/types/apps/src/index.d.ts +29 -11
- package/types/apps/src/mcp-stdio.d.ts +2 -5
- package/types/apps/src/mcp.d.ts +25 -5
- package/types/apps/src/openapi.d.ts +6 -6
- package/types/apps/src/skills.d.ts +4 -4
- package/types/telemetry/src/browser-operations.d.ts +5 -2
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/utils/src/api-error.d.ts +48 -0
- package/js/chunk-PYUYJRSK.js +0 -93
- package/js/chunk-SWPD52J7.js +0 -35
- package/js/chunk-W7D7WVSY.js +0 -18
- package/js/chunk-Z5NMEGJN.js +0 -29
- package/js/chunk-ZJWDMTE3.js +0 -63
- package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
- package/types/apps/src/implementation/account-operations.d.ts +0 -151
- package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
JsonObject,
|
|
2
3
|
ValidationError
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FBBXFFFJ.js";
|
|
4
5
|
import {
|
|
5
6
|
Cause_exports,
|
|
6
7
|
Effect_exports,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
SchemaIssue_exports,
|
|
10
11
|
SchemaParser_exports,
|
|
11
12
|
Schema_exports
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-EXGKN554.js";
|
|
13
14
|
|
|
14
15
|
// ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
|
|
15
16
|
function deepCompareStrict(a, b) {
|
|
@@ -344,7 +345,7 @@ function validate(instance, schema, draft = "2019-09", lookup = dereference(sche
|
|
|
344
345
|
if ($recursiveAnchor === true && recursiveAnchor === null) {
|
|
345
346
|
recursiveAnchor = schema;
|
|
346
347
|
}
|
|
347
|
-
if ($recursiveRef
|
|
348
|
+
if ($recursiveRef !== void 0) {
|
|
348
349
|
const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
|
|
349
350
|
const keywordLocation = `${schemaLocation}/$recursiveRef`;
|
|
350
351
|
const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
|
|
@@ -1144,6 +1145,25 @@ function object(fields) {
|
|
|
1144
1145
|
) : Schema_exports.Struct(Object.fromEntries(entries));
|
|
1145
1146
|
return { ...wrap(decoder, false), fields: Object.freeze({ ...fields }) };
|
|
1146
1147
|
}
|
|
1148
|
+
var Exposure = /* @__PURE__ */ Symbol("apps.FieldExposure");
|
|
1149
|
+
var exposureOf = (schema) => Exposure in schema && (schema[Exposure] === "plain" || schema[Exposure] === "raw") ? schema[Exposure] : void 0;
|
|
1150
|
+
var expose = (schema, exposure) => (
|
|
1151
|
+
// SAFETY: the copy keeps every member of S, and `optional` and `default` keep the marking.
|
|
1152
|
+
{
|
|
1153
|
+
...schema,
|
|
1154
|
+
[Exposure]: exposure,
|
|
1155
|
+
optional: () => expose(schema.optional(), exposure),
|
|
1156
|
+
default: (value) => expose(schema.default(value), exposure)
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1159
|
+
var plain = (schema) => expose(schema, "plain");
|
|
1160
|
+
var raw = (schema) => expose(schema, "raw");
|
|
1161
|
+
var fieldExposure = (fields) => Object.fromEntries(
|
|
1162
|
+
Object.entries(fields).flatMap(([name, field]) => {
|
|
1163
|
+
const exposure = exposureOf(field);
|
|
1164
|
+
return exposure === void 0 ? [] : [[name, exposure]];
|
|
1165
|
+
})
|
|
1166
|
+
);
|
|
1147
1167
|
var ImportedJsonSchema = /* @__PURE__ */ Symbol("apps.JsonSchemaDocument");
|
|
1148
1168
|
var importedJsonSchema = (decoder) => ImportedJsonSchema in decoder ? decoder[ImportedJsonSchema] : void 0;
|
|
1149
1169
|
var withJsonSchemaDocument = (decoder, document) => Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
@@ -1273,18 +1293,334 @@ var containerKeywords = /* @__PURE__ */ new Set([
|
|
|
1273
1293
|
"else",
|
|
1274
1294
|
"dependentSchemas"
|
|
1275
1295
|
]);
|
|
1276
|
-
var
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1296
|
+
var echoableKey = (key) => /^[A-Za-z_$][\w$-]{0,63}$/.test(key);
|
|
1297
|
+
var schemaKey = (name) => echoableKey(name) ? name : JSON.stringify(name.slice(0, 64));
|
|
1298
|
+
var maxShapeKeys = 24;
|
|
1299
|
+
var objectShape = (keys, open, limit = maxShapeKeys) => {
|
|
1300
|
+
const listed = keys.slice(0, limit).map(({ name, optional }) => `${schemaKey(name)}${optional ? "?" : ""}`);
|
|
1301
|
+
const parts = [
|
|
1302
|
+
...listed,
|
|
1303
|
+
...keys.length > limit ? [`${keys.length - limit} more`] : [],
|
|
1304
|
+
...open ? ["..."] : []
|
|
1305
|
+
];
|
|
1306
|
+
return parts.length === 0 ? "object {} with no keys" : `object {${parts.join(", ")}}`;
|
|
1307
|
+
};
|
|
1308
|
+
var maxListedValues = 10;
|
|
1309
|
+
var maxValuesText = 200;
|
|
1310
|
+
var valueText = (value) => typeof value === "bigint" ? `${value}n` : JSON.stringify(value);
|
|
1311
|
+
var allowedValues = (values) => {
|
|
1312
|
+
const texts = [...new Set(values.map(valueText))];
|
|
1313
|
+
const listed = [];
|
|
1314
|
+
for (const text of texts) {
|
|
1315
|
+
if (listed.length === maxListedValues || [...listed, text].join(", ").length > maxValuesText)
|
|
1316
|
+
break;
|
|
1317
|
+
listed.push(text);
|
|
1318
|
+
}
|
|
1319
|
+
const [only] = listed;
|
|
1320
|
+
if (texts.length === 0) return "no value, since the schema allows none";
|
|
1321
|
+
if (only === void 0)
|
|
1322
|
+
return texts.length === 1 ? "a fixed value too long to list" : `one of ${texts.length} values too long to list`;
|
|
1323
|
+
if (texts.length === 1) return only;
|
|
1324
|
+
const rest = texts.length - listed.length;
|
|
1325
|
+
return `one of ${listed.join(", ")}${rest > 0 ? ` and ${rest} more` : ""}`;
|
|
1326
|
+
};
|
|
1327
|
+
var maxAlternativeKeys = 8;
|
|
1328
|
+
var maxAlternativesText = 360;
|
|
1329
|
+
var unionShape = (alternatives, selector) => {
|
|
1330
|
+
const listed = [];
|
|
1331
|
+
for (const alternative of alternatives) {
|
|
1332
|
+
if (listed.length > 0 && [...listed, alternative].join(" or ").length > maxAlternativesText)
|
|
1333
|
+
break;
|
|
1334
|
+
listed.push(alternative);
|
|
1335
|
+
}
|
|
1336
|
+
const rest = alternatives.length - listed.length;
|
|
1337
|
+
return `${[...listed, ...rest > 0 ? [`${rest} more`] : []].join(" or ")}${selector === void 0 ? "" : `, told apart by ${schemaKey(selector)}`}`;
|
|
1338
|
+
};
|
|
1339
|
+
var isJsonRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1340
|
+
var pointerSegments = (pointer) => pointer === "#" || pointer === "" ? [] : pointer.replace(/^#?\//, "").split("/").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
1341
|
+
var resolved = (lookup, uri2) => typeof uri2 === "string" && Object.hasOwn(lookup, uri2) ? lookup[uri2] : void 0;
|
|
1342
|
+
var referenced = (lookup, node) => isJsonRecord(node) ? resolved(lookup, Reflect.get(node, "__absolute_ref__") ?? node.$ref) : void 0;
|
|
1343
|
+
var memberKeywords = /* @__PURE__ */ new Set([...schemaMaps, ...schemaArrays, "dependencies"]);
|
|
1344
|
+
var combinators = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf"]);
|
|
1345
|
+
var schemaAt = (document, lookup, segments) => {
|
|
1346
|
+
const anchoredAt = (node2, anchor2) => anchor2 === null && isJsonRecord(node2) && node2.$recursiveAnchor === true ? node2 : anchor2;
|
|
1347
|
+
const pending = [...segments];
|
|
1348
|
+
let node = document;
|
|
1349
|
+
let anchor = anchoredAt(document, null);
|
|
1350
|
+
for (let keyword = pending.shift(); keyword !== void 0; keyword = pending.shift()) {
|
|
1351
|
+
if (!isJsonRecord(node)) return void 0;
|
|
1352
|
+
if (keyword === "$recursiveRef") {
|
|
1353
|
+
const target = anchor === null ? resolved(lookup, Reflect.get(node, "__absolute_recursive_ref__")) : anchor;
|
|
1354
|
+
if (anchor !== null) node = anchor;
|
|
1355
|
+
anchor = target;
|
|
1356
|
+
continue;
|
|
1357
|
+
}
|
|
1358
|
+
if (keyword === "$ref") node = referenced(lookup, node);
|
|
1359
|
+
else {
|
|
1360
|
+
const value = Object.hasOwn(node, keyword) ? node[keyword] : void 0;
|
|
1361
|
+
if (memberKeywords.has(keyword) || keyword === "items" && Array.isArray(value)) {
|
|
1362
|
+
const member = pending.shift();
|
|
1363
|
+
if (member === void 0) return value;
|
|
1364
|
+
if (combinators.has(keyword) && node.$recursiveAnchor !== true) anchor = null;
|
|
1365
|
+
node = Array.isArray(value) ? /^\d+$/.test(member) ? value[Number(member)] : void 0 : isJsonRecord(value) && Object.hasOwn(value, member) ? value[member] : void 0;
|
|
1366
|
+
} else node = value;
|
|
1367
|
+
}
|
|
1368
|
+
anchor = anchoredAt(node, anchor);
|
|
1369
|
+
}
|
|
1370
|
+
return node;
|
|
1371
|
+
};
|
|
1372
|
+
var jsonObjectShape = (node) => {
|
|
1373
|
+
if (!isJsonRecord(node)) return "object";
|
|
1374
|
+
const properties = isJsonRecord(node.properties) ? Object.keys(node.properties) : [];
|
|
1375
|
+
const required = new Set(Array.isArray(node.required) ? node.required : []);
|
|
1376
|
+
const open = node.additionalProperties !== false || isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0;
|
|
1377
|
+
return properties.length === 0 && open ? "object" : objectShape(
|
|
1378
|
+
properties.map((name) => ({ name, optional: !required.has(name) })),
|
|
1379
|
+
open
|
|
1380
|
+
);
|
|
1381
|
+
};
|
|
1382
|
+
var locationKey = (segments) => JSON.stringify(segments);
|
|
1383
|
+
var emptyOutline = {
|
|
1384
|
+
types: void 0,
|
|
1385
|
+
properties: /* @__PURE__ */ new Map(),
|
|
1386
|
+
required: /* @__PURE__ */ new Set(),
|
|
1387
|
+
closed: false,
|
|
1388
|
+
values: void 0
|
|
1389
|
+
};
|
|
1390
|
+
var commonValues = (a, b) => a === void 0 ? b : b === void 0 ? a : a.filter((value) => b.some((other) => deepCompareStrict(value, other)));
|
|
1391
|
+
var strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1392
|
+
var commonTypes = (a, b) => new Set(
|
|
1393
|
+
[...a].flatMap(
|
|
1394
|
+
(type) => b.has(type) ? [type] : type === "number" && b.has("integer") || type === "integer" && b.has("number") ? ["integer"] : []
|
|
1395
|
+
)
|
|
1396
|
+
);
|
|
1397
|
+
var mergeOutlines = (a, b) => ({
|
|
1398
|
+
types: a.types === void 0 ? b.types : b.types === void 0 ? a.types : commonTypes(a.types, b.types),
|
|
1399
|
+
properties: new Map([...a.properties, ...b.properties]),
|
|
1400
|
+
required: /* @__PURE__ */ new Set([...a.required, ...b.required]),
|
|
1401
|
+
closed: a.closed || b.closed,
|
|
1402
|
+
values: commonValues(a.values, b.values)
|
|
1403
|
+
});
|
|
1404
|
+
var outlineOf = (node, inspection, seen = /* @__PURE__ */ new Set()) => {
|
|
1405
|
+
if (!isJsonRecord(node) || seen.has(node)) return emptyOutline;
|
|
1406
|
+
const within = /* @__PURE__ */ new Set([...seen, node]);
|
|
1407
|
+
const own = {
|
|
1408
|
+
types: typeof node.type === "string" ? /* @__PURE__ */ new Set([node.type]) : Array.isArray(node.type) ? new Set(strings(node.type)) : void 0,
|
|
1409
|
+
properties: new Map(isJsonRecord(node.properties) ? Object.entries(node.properties) : []),
|
|
1410
|
+
required: new Set(strings(node.required)),
|
|
1411
|
+
closed: (node.additionalProperties === false || node.unevaluatedProperties === false) && !(isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0),
|
|
1412
|
+
values: commonValues(
|
|
1413
|
+
Object.hasOwn(node, "const") ? [node.const] : void 0,
|
|
1414
|
+
Array.isArray(node.enum) ? node.enum : void 0
|
|
1415
|
+
)
|
|
1416
|
+
};
|
|
1417
|
+
return [inspection.referenced(node), ...Array.isArray(node.allOf) ? node.allOf : []].reduce(
|
|
1418
|
+
(outline, member) => mergeOutlines(outline, outlineOf(member, inspection, within)),
|
|
1419
|
+
own
|
|
1420
|
+
);
|
|
1421
|
+
};
|
|
1422
|
+
var describeOutline = (outline) => {
|
|
1423
|
+
if (outline.values !== void 0) return allowedValues(outline.values);
|
|
1424
|
+
const names = [
|
|
1425
|
+
...outline.properties.keys(),
|
|
1426
|
+
...[...outline.required].filter((name) => !outline.properties.has(name))
|
|
1427
|
+
];
|
|
1428
|
+
const shape = names.length === 0 && !outline.closed ? "object" : objectShape(
|
|
1429
|
+
names.map((name) => ({ name, optional: !outline.required.has(name) })),
|
|
1430
|
+
!outline.closed,
|
|
1431
|
+
maxAlternativeKeys
|
|
1432
|
+
);
|
|
1433
|
+
if (outline.types === void 0)
|
|
1434
|
+
return names.length > 0 || outline.closed ? shape : "a value with other constraints";
|
|
1435
|
+
return [...outline.types].map((type) => type === "object" ? shape : type).join(" or ");
|
|
1436
|
+
};
|
|
1437
|
+
var overlap = (outline, value, inspection, depth = 0) => !isJsonRecord(value) || depth > 16 ? 0 : Object.entries(value).reduce((total, [key, item]) => {
|
|
1438
|
+
const property = outline.properties.get(key);
|
|
1439
|
+
return property === void 0 ? total : total + 1 + overlap(outlineOf(property, inspection), item, inspection, depth + 1);
|
|
1440
|
+
}, 0);
|
|
1441
|
+
var jsonType = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value === "object" ? "object" : typeof value;
|
|
1442
|
+
var accepted = (outline, value) => {
|
|
1443
|
+
const type = jsonType(value);
|
|
1444
|
+
if (outline.values !== void 0)
|
|
1445
|
+
return outline.values.some((allowed) => jsonType(allowed) === type);
|
|
1446
|
+
if (outline.types === void 0) return true;
|
|
1447
|
+
return outline.types.has(type) || type === "number" && outline.types.has("integer") && Number.isInteger(value);
|
|
1448
|
+
};
|
|
1449
|
+
var valueAt = (input, location2) => location2.reduce(
|
|
1450
|
+
(value, segment) => Array.isArray(value) ? value[Number(segment)] : isJsonRecord(value) && Object.hasOwn(value, segment) ? value[segment] : void 0,
|
|
1451
|
+
input
|
|
1452
|
+
);
|
|
1453
|
+
var discriminatorOf = (holder) => isJsonRecord(holder) && isJsonRecord(holder.discriminator) ? holder.discriminator : void 0;
|
|
1454
|
+
var definitionName = (reference) => {
|
|
1455
|
+
if (typeof reference !== "string" || !reference.startsWith("#/")) return void 0;
|
|
1456
|
+
const segments = pointerSegments(reference);
|
|
1457
|
+
const container = segments.at(-2);
|
|
1458
|
+
return container === "$defs" || container === "definitions" || container === "schemas" && segments.at(-3) === "components" ? segments.at(-1) : void 0;
|
|
1459
|
+
};
|
|
1460
|
+
var discriminatedName = (holder, value) => {
|
|
1461
|
+
const discriminator = discriminatorOf(holder);
|
|
1462
|
+
if (discriminator === void 0 || typeof value !== "string") return void 0;
|
|
1463
|
+
const { mapping } = discriminator;
|
|
1464
|
+
const target = isJsonRecord(mapping) && Object.hasOwn(mapping, value) ? mapping[value] : value;
|
|
1465
|
+
if (typeof target !== "string") return void 0;
|
|
1466
|
+
return /^[\w.-]+$/.test(target) ? target : definitionName(target);
|
|
1467
|
+
};
|
|
1468
|
+
var selectorOf = (holder, alternatives, inspection) => {
|
|
1469
|
+
const declared = discriminatorOf(holder)?.propertyName;
|
|
1470
|
+
if (typeof declared === "string") return declared;
|
|
1471
|
+
const [first] = alternatives;
|
|
1472
|
+
if (first === void 0 || alternatives.length < 2) return void 0;
|
|
1473
|
+
return [...first.properties.keys()].find(
|
|
1474
|
+
(key) => alternatives.every(
|
|
1475
|
+
(alternative) => alternative.properties.has(key) && outlineOf(alternative.properties.get(key), inspection).values !== void 0
|
|
1476
|
+
)
|
|
1477
|
+
);
|
|
1478
|
+
};
|
|
1479
|
+
var alternativeErrors = (errors, head, schemas) => {
|
|
1480
|
+
const prefix = `${errors[head]?.keywordLocation}/`;
|
|
1481
|
+
const alternatives = /* @__PURE__ */ new Map();
|
|
1482
|
+
const settle = (current2, next) => {
|
|
1483
|
+
const collected = alternatives.get(current2);
|
|
1484
|
+
const rejected = Array.isArray(schemas) ? schemas.slice(current2 + 1, next).filter((schema) => schema === false).length : 0;
|
|
1485
|
+
if (collected !== void 0) collected.splice(collected.length - rejected, rejected);
|
|
1486
|
+
};
|
|
1487
|
+
let index = head + 1;
|
|
1488
|
+
let current = -1;
|
|
1489
|
+
for (; index < errors.length; index++) {
|
|
1490
|
+
const error = errors[index];
|
|
1491
|
+
if (error === void 0) break;
|
|
1492
|
+
if (error.keywordLocation.startsWith(prefix)) {
|
|
1493
|
+
const alternative = Number(error.keywordLocation.slice(prefix.length).split("/")[0]);
|
|
1494
|
+
if (alternative !== current) settle(current, alternative);
|
|
1495
|
+
current = alternative;
|
|
1496
|
+
} else if (error.keyword !== "false") break;
|
|
1497
|
+
if (current >= 0) alternatives.set(current, [...alternatives.get(current) ?? [], error]);
|
|
1498
|
+
}
|
|
1499
|
+
settle(current, Array.isArray(schemas) ? schemas.length : current);
|
|
1500
|
+
return { alternatives, end: index };
|
|
1501
|
+
};
|
|
1502
|
+
var pathOf = (location2) => location2.map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
|
|
1503
|
+
var unionProblems = (union, schemas, errorsByAlternative, inspection) => {
|
|
1504
|
+
const location2 = pointerSegments(union.instanceLocation);
|
|
1505
|
+
const path = pathOf(location2);
|
|
1506
|
+
if (!Array.isArray(schemas))
|
|
1507
|
+
return [
|
|
1508
|
+
{ path, issue: `Failed the "${union.keyword}" constraint` },
|
|
1509
|
+
...[...errorsByAlternative.values()].flatMap((errors) => problemsOf(errors, inspection))
|
|
1510
|
+
];
|
|
1511
|
+
const alternatives = schemas.flatMap(
|
|
1512
|
+
(schema, index) => schema === false ? [] : [
|
|
1513
|
+
{
|
|
1514
|
+
schema,
|
|
1515
|
+
matched: !errorsByAlternative.has(index),
|
|
1516
|
+
problems: () => problemsOf(errorsByAlternative.get(index) ?? [], inspection)
|
|
1517
|
+
}
|
|
1518
|
+
]
|
|
1519
|
+
);
|
|
1520
|
+
const [only] = alternatives;
|
|
1521
|
+
if (only === void 0) return [{ path, issue: "No value is allowed here" }];
|
|
1522
|
+
if (alternatives.length === 1) return only.problems();
|
|
1523
|
+
const holder = inspection.schemaAt(pointerSegments(union.keywordLocation).slice(0, -1));
|
|
1524
|
+
const shared = outlineOf(holder, inspection);
|
|
1525
|
+
const own = alternatives.map(({ schema }) => outlineOf(schema, inspection));
|
|
1526
|
+
const outlines = own.map((outline) => mergeOutlines(shared, outline));
|
|
1527
|
+
const fixed = outlines.flatMap(({ values }) => values === void 0 ? [] : [values]);
|
|
1528
|
+
if (fixed.length === outlines.length)
|
|
1529
|
+
return [{ path, issue: `Expected ${allowedValues(fixed.flat())}` }];
|
|
1530
|
+
const selector = selectorOf(holder, own, inspection);
|
|
1531
|
+
const expected = `Expected ${unionShape(outlines.map(describeOutline), selector)}`;
|
|
1532
|
+
const matched = alternatives.filter((alternative) => alternative.matched).length;
|
|
1533
|
+
if (union.keyword === "oneOf" && matched > 1)
|
|
1534
|
+
return [{ path, issue: `${expected}. Exactly one may match, but ${matched} do` }];
|
|
1535
|
+
const value = valueAt(inspection.input, location2);
|
|
1536
|
+
const selectorValue = selector !== void 0 && isJsonRecord(value) && Object.hasOwn(value, selector) ? { value: value[selector] } : void 0;
|
|
1537
|
+
const named = discriminatedName(holder, selectorValue?.value);
|
|
1538
|
+
const ranked = alternatives.map(({ schema, problems }, index) => {
|
|
1539
|
+
const outline = outlines[index] ?? emptyOutline;
|
|
1540
|
+
const property = own[index]?.properties.get(selector ?? "");
|
|
1541
|
+
return {
|
|
1542
|
+
index,
|
|
1543
|
+
problems: problems(),
|
|
1544
|
+
selected: selectorValue !== void 0 && (named !== void 0 && isJsonRecord(schema) && definitionName(schema.$ref) === named || property !== void 0 && outlineOf(property, inspection).values !== void 0 && inspection.accepts(property, selectorValue.value)),
|
|
1545
|
+
typed: accepted(outline, value),
|
|
1546
|
+
overlap: overlap(outline, value, inspection)
|
|
1285
1547
|
};
|
|
1286
|
-
return [issue];
|
|
1287
1548
|
});
|
|
1549
|
+
const closest = ranked.reduce(
|
|
1550
|
+
(best, candidate) => ([
|
|
1551
|
+
Number(candidate.selected) - Number(best.selected),
|
|
1552
|
+
Number(candidate.typed) - Number(best.typed),
|
|
1553
|
+
candidate.overlap - best.overlap,
|
|
1554
|
+
best.problems.length - candidate.problems.length
|
|
1555
|
+
].find((difference) => difference !== 0) ?? 0) > 0 ? candidate : best
|
|
1556
|
+
);
|
|
1557
|
+
return closest.selected || closest.typed ? [
|
|
1558
|
+
{
|
|
1559
|
+
path,
|
|
1560
|
+
issue: `${expected}. Closest is alternative ${closest.index + 1}, whose problems follow`
|
|
1561
|
+
},
|
|
1562
|
+
...closest.problems
|
|
1563
|
+
] : [{ path, issue: expected }];
|
|
1564
|
+
};
|
|
1565
|
+
var problemsOf = (errors, inspection) => {
|
|
1566
|
+
const closed = /* @__PURE__ */ new Map();
|
|
1567
|
+
const problems = [];
|
|
1568
|
+
for (let index = 0; index < errors.length; index++) {
|
|
1569
|
+
const error = errors[index];
|
|
1570
|
+
if (error === void 0) break;
|
|
1571
|
+
const { keyword, instanceLocation, keywordLocation } = error;
|
|
1572
|
+
if (keyword === "anyOf" || keyword === "oneOf") {
|
|
1573
|
+
const schemas = inspection.schemaAt(pointerSegments(keywordLocation));
|
|
1574
|
+
const { alternatives, end } = alternativeErrors(errors, index, schemas);
|
|
1575
|
+
problems.push(...unionProblems(error, schemas, alternatives, inspection));
|
|
1576
|
+
index = end - 1;
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
const location2 = pointerSegments(instanceLocation);
|
|
1580
|
+
const path = pathOf(location2);
|
|
1581
|
+
const problem = (issue, at = path) => problems.push({ path: at, issue });
|
|
1582
|
+
const node = () => inspection.schemaAt(pointerSegments(keywordLocation).slice(0, -1));
|
|
1583
|
+
if (keyword === "additionalProperties" || keyword === "unevaluatedProperties") {
|
|
1584
|
+
closed.set(locationKey(location2), node());
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1587
|
+
if (containerKeywords.has(keyword)) continue;
|
|
1588
|
+
if (keyword === "false") {
|
|
1589
|
+
const key = location2.at(-1);
|
|
1590
|
+
const parent = locationKey(location2.slice(0, -1));
|
|
1591
|
+
if (key === void 0 || !closed.has(parent)) problem("No value is allowed here");
|
|
1592
|
+
else
|
|
1593
|
+
problem(
|
|
1594
|
+
`Unexpected key${echoableKey(key) ? ` "${key}"` : ""}. Expected ${jsonObjectShape(closed.get(parent))}`,
|
|
1595
|
+
path.slice(0, -1)
|
|
1596
|
+
);
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
const required = keyword === "required" ? /required property "([^"]*)"/.exec(error.error) : null;
|
|
1600
|
+
if (required !== null) {
|
|
1601
|
+
problem("Missing key", [...path, required[1] ?? ""]);
|
|
1602
|
+
continue;
|
|
1603
|
+
}
|
|
1604
|
+
const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error.error) : null;
|
|
1605
|
+
if (expected !== null) {
|
|
1606
|
+
const types = (expected[1] ?? "").split('", "').map((type) => type === "object" ? jsonObjectShape(node()) : type);
|
|
1607
|
+
problem(`Expected ${types.join(" or ")}`);
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
if (keyword === "const" || keyword === "enum") {
|
|
1611
|
+
const schema = node();
|
|
1612
|
+
const values = !isJsonRecord(schema) ? void 0 : keyword === "const" ? Object.hasOwn(schema, "const") ? [schema.const] : void 0 : Array.isArray(schema.enum) ? schema.enum : void 0;
|
|
1613
|
+
problem(
|
|
1614
|
+
values === void 0 ? "Expected one of the allowed values" : `Expected ${allowedValues(values)}`
|
|
1615
|
+
);
|
|
1616
|
+
continue;
|
|
1617
|
+
}
|
|
1618
|
+
problem(`Failed the "${keyword}" constraint`);
|
|
1619
|
+
}
|
|
1620
|
+
return problems;
|
|
1621
|
+
};
|
|
1622
|
+
var jsonSchemaProblems = (errors, inspection) => {
|
|
1623
|
+
const problems = problemsOf(errors, inspection);
|
|
1288
1624
|
return problems.length === 0 ? false : problems;
|
|
1289
1625
|
};
|
|
1290
1626
|
var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
@@ -1311,8 +1647,22 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
|
1311
1647
|
throw new ValidationError();
|
|
1312
1648
|
}
|
|
1313
1649
|
}
|
|
1650
|
+
const inspection = (input) => ({
|
|
1651
|
+
schemaAt: (segments) => schemaAt(normalized, lookup, segments),
|
|
1652
|
+
referenced: (node) => referenced(lookup, node),
|
|
1653
|
+
accepts: (node, value) => {
|
|
1654
|
+
if (typeof node !== "boolean" && !isJsonRecord(node)) return false;
|
|
1655
|
+
try {
|
|
1656
|
+
return validate(value, node, draft, lookup).valid;
|
|
1657
|
+
} catch {
|
|
1658
|
+
return false;
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
input
|
|
1662
|
+
});
|
|
1314
1663
|
return {
|
|
1315
|
-
validate: (input) => validate(input, normalized, draft, lookup)
|
|
1664
|
+
validate: (input) => validate(input, normalized, draft, lookup),
|
|
1665
|
+
inspection
|
|
1316
1666
|
};
|
|
1317
1667
|
},
|
|
1318
1668
|
catch: () => new ValidationError()
|
|
@@ -1322,7 +1672,7 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
|
1322
1672
|
(value) => {
|
|
1323
1673
|
try {
|
|
1324
1674
|
const result = validator.validate(value);
|
|
1325
|
-
return result.valid || jsonSchemaProblems(result.errors);
|
|
1675
|
+
return result.valid || jsonSchemaProblems(result.errors, validator.inspection(value));
|
|
1326
1676
|
} catch {
|
|
1327
1677
|
return false;
|
|
1328
1678
|
}
|
|
@@ -1332,7 +1682,7 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
|
1332
1682
|
);
|
|
1333
1683
|
return Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
1334
1684
|
});
|
|
1335
|
-
var
|
|
1685
|
+
var lazyCompiledDecoder = (document) => {
|
|
1336
1686
|
const read = once(document);
|
|
1337
1687
|
let compiled;
|
|
1338
1688
|
const compile = Effect_exports.suspend(
|
|
@@ -1352,9 +1702,11 @@ var lazyDecoder = (document) => {
|
|
|
1352
1702
|
Effect_exports.flatMap((schema) => SchemaParser_exports.decodeUnknownEffect(schema)(input, options))
|
|
1353
1703
|
)
|
|
1354
1704
|
);
|
|
1355
|
-
return withLazyJsonSchemaDocument(decoder, read);
|
|
1705
|
+
return { decoder: withLazyJsonSchemaDocument(decoder, read), compile };
|
|
1356
1706
|
};
|
|
1707
|
+
var lazyDecoder = (document) => lazyCompiledDecoder(document).decoder;
|
|
1357
1708
|
var lazyJsonSchemaDecoder = (document) => Effect_exports.sync(() => lazyDecoder(document));
|
|
1709
|
+
var preparedJsonSchemaDecoder = (document) => lazyCompiledDecoder(() => document);
|
|
1358
1710
|
var isJsonValue = Schema_exports.is(Schema_exports.Json);
|
|
1359
1711
|
var jsonDocument = (input) => {
|
|
1360
1712
|
if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
|
|
@@ -1387,6 +1739,16 @@ var jsonSchema = (input) => {
|
|
|
1387
1739
|
var storageFieldOf = (schema) => schema[StorageField];
|
|
1388
1740
|
var id = (table) => wrap(Schema_exports.NonEmptyString, false, { kind: "id", references: table });
|
|
1389
1741
|
var userId = () => wrap(Schema_exports.NonEmptyString, false, { kind: "userId" });
|
|
1742
|
+
var jsonSchemaDocument = (decoder) => {
|
|
1743
|
+
const imported = importedJsonSchema(decoder);
|
|
1744
|
+
if (imported !== void 0) return Schema_exports.decodeUnknownEffect(JsonObject)(imported);
|
|
1745
|
+
const document = Schema_exports.toJsonSchemaDocument(decoder);
|
|
1746
|
+
return Schema_exports.decodeUnknownEffect(JsonObject)({
|
|
1747
|
+
...document.schema,
|
|
1748
|
+
$defs: document.definitions,
|
|
1749
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
1750
|
+
});
|
|
1751
|
+
};
|
|
1390
1752
|
|
|
1391
1753
|
export {
|
|
1392
1754
|
decoderOf,
|
|
@@ -1401,15 +1763,25 @@ export {
|
|
|
1401
1763
|
literal,
|
|
1402
1764
|
array,
|
|
1403
1765
|
object,
|
|
1766
|
+
plain,
|
|
1767
|
+
raw,
|
|
1768
|
+
fieldExposure,
|
|
1404
1769
|
importedJsonSchema,
|
|
1405
1770
|
once,
|
|
1406
1771
|
withLazyJsonSchemaDocument,
|
|
1407
1772
|
nestJsonSchema,
|
|
1773
|
+
echoableKey,
|
|
1774
|
+
objectShape,
|
|
1775
|
+
allowedValues,
|
|
1776
|
+
maxAlternativeKeys,
|
|
1777
|
+
unionShape,
|
|
1408
1778
|
compileJsonSchemaDecoder,
|
|
1409
1779
|
lazyJsonSchemaDecoder,
|
|
1780
|
+
preparedJsonSchemaDecoder,
|
|
1410
1781
|
jsonSchemaDecoder,
|
|
1411
1782
|
jsonSchema,
|
|
1412
1783
|
storageFieldOf,
|
|
1413
1784
|
id,
|
|
1414
|
-
userId
|
|
1785
|
+
userId,
|
|
1786
|
+
jsonSchemaDocument
|
|
1415
1787
|
};
|