apps 0.0.1-beta.4 → 0.0.1-beta.41
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-QKHR7BMF.js → chunk-3MMG2H6M.js} +89 -53
- package/js/{chunk-EQB7JMAL.js → chunk-6XGB4BAL.js} +146 -31
- package/js/chunk-ADD6H64X.js +729 -0
- package/js/{chunk-6VRYO2BG.js → chunk-AHGGO2VY.js} +837 -254
- package/js/{chunk-FDNTX5QJ.js → chunk-CQD3WSYH.js} +2 -2
- package/js/{chunk-EVJUVWN2.js → chunk-DKUEYTYD.js} +463 -218
- package/js/chunk-EM4UL26F.js +118 -0
- package/js/{chunk-2VPJHFOU.js → chunk-FXWRE655.js} +128 -24
- package/js/{chunk-5MQZEB6Y.js → chunk-JI3EP2GL.js} +40 -12
- package/js/chunk-JJSLEJ6T.js +156 -0
- package/js/chunk-KAQD3DTI.js +16 -0
- package/js/chunk-KIM5HXNK.js +49 -0
- package/js/chunk-MJZYV7IO.js +255 -0
- package/js/{chunk-FW5HBOIK.js → chunk-MXDKXAY4.js} +19117 -18309
- package/js/{chunk-T2LAZCAD.js → chunk-NKWWPJYX.js} +3 -3
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-3M2MEDNL.js → chunk-OTCLXFLL.js} +1337 -188
- package/js/chunk-P7MGDPFD.js +240 -0
- package/js/{chunk-ZCAMUXSG.js → chunk-PNVCCB4L.js} +432 -79
- package/js/{chunk-D47C7KG5.js → chunk-RIXVGVA6.js} +2 -2
- package/js/{chunk-NQ3OMCA5.js → chunk-TT6OU4UG.js} +2 -2
- package/js/{chunk-YEJOQEII.js → chunk-UOZMSUJ2.js} +61 -9
- package/js/chunk-UTJIGUSS.js +42 -0
- package/js/{chunk-G7ZIRKMK.js → chunk-VIU2XXA7.js} +228 -264
- package/js/{chunk-HDJH3RPR.js → chunk-VJQXXOQ3.js} +4 -4
- package/js/{chunk-WFSQXYUT.js → chunk-WPBR4AWB.js} +523 -63
- package/js/{chunk-SATWJKN6.js → chunk-YQ35E7KS.js} +2 -2
- package/js/chunk-ZUKBIHMK.js +92 -0
- package/js/client.js +122 -88
- package/js/contracts.js +116 -25
- package/js/effect.js +19 -20
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +57 -55
- package/js/host.js +19 -20
- package/js/index.js +245 -212
- package/js/mcp/effect.js +23 -22
- package/js/mcp/stdio.js +34 -30
- package/js/mcp.js +104 -68
- package/js/openapi.js +4087 -1503
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +147 -65
- package/js/storage/facet.js +1 -540
- 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 +8517 -214
- package/package.json +2 -3
- package/runtime.json +1 -1
- package/types/app-data/src/contracts/database.d.ts +33 -6
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -8
- package/types/apps/src/contracts/cache.d.ts +14 -0
- package/types/apps/src/contracts/context.d.ts +12 -11
- package/types/apps/src/contracts/elicitation.d.ts +6 -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 +44 -17
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +96 -10
- package/types/apps/src/contracts/network.d.ts +84 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +32 -3
- package/types/apps/src/contracts/openapi.d.ts +45 -9
- package/types/apps/src/contracts/operations.d.ts +8 -9
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +263 -74
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/2.d.ts +66 -24
- package/types/apps/src/contracts/protocols/3.d.ts +715 -0
- package/types/apps/src/contracts/protocols/4.d.ts +1297 -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 +1130 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1106 -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 +39 -9
- package/types/apps/src/contracts/sql.d.ts +58 -0
- package/types/apps/src/contracts/ui.d.ts +19 -1
- package/types/apps/src/contracts/workflows.d.ts +40 -3
- package/types/apps/src/facet.d.ts +4 -5
- 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 +32 -5
- package/types/apps/src/implementation/elicitation.d.ts +12 -12
- package/types/apps/src/implementation/failure-detail.d.ts +47 -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 +6 -2
- package/types/apps/src/implementation/live.d.ts +2 -2
- 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/optimistic.d.ts +1 -1
- 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/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +223 -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 +95 -11
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +66 -0
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-auth.d.ts +1 -1
- 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 +11 -5
- 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 +30 -13
- 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/react.d.ts +1 -1
- package/types/apps/src/skills.d.ts +10 -8
- package/types/telemetry/src/app-records.d.ts +42 -0
- package/types/telemetry/src/browser-operations.d.ts +6 -3
- package/types/telemetry/src/browser.d.ts +2 -2
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/layer.d.ts +2 -2
- package/types/telemetry/src/recorded-failure.d.ts +20 -0
- package/types/telemetry/src/relay.d.ts +2 -2
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +53 -0
- package/types/utils/src/recorded-message.d.ts +15 -0
- package/js/chunk-BMOIAIVR.js +0 -138
- package/js/chunk-DHUDODG5.js +0 -213
- package/js/chunk-FZJOYIZO.js +0 -19
- package/js/chunk-LGIYBDWA.js +0 -85
- package/js/chunk-M6ZRRIBI.js +0 -877
- package/js/chunk-PLCMJREA.js +0 -590
- 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/app-data/src/implementation/cursor.d.ts +0 -10
- package/types/app-data/src/implementation/index-key.d.ts +0 -7
- package/types/app-data/src/implementation/promise.d.ts +0 -68
- package/types/app-data/src/implementation/range.d.ts +0 -8
- package/types/app-data/src/implementation/schema.d.ts +0 -33
- package/types/app-data/src/implementation/sqlite.d.ts +0 -11
- package/types/app-data/src/index.d.ts +0 -4
- package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
- package/types/apps/src/contracts/storage.d.ts +0 -68
- package/types/apps/src/implementation/account-operations.d.ts +0 -151
- package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
- package/types/apps/src/implementation/storage.d.ts +0 -13
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
JsonObject,
|
|
2
3
|
ValidationError
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YQ35E7KS.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-MXDKXAY4.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) {
|
|
@@ -106,9 +107,9 @@ var ignoredKeyword = {
|
|
|
106
107
|
var initialBaseURI = typeof self !== "undefined" && self.location && self.location.origin !== "null" ? new URL(self.location.origin + self.location.pathname + location.search) : new URL("https://github.com/cfworker");
|
|
107
108
|
function dereference(schema, lookup = /* @__PURE__ */ Object.create(null), baseURI = initialBaseURI, basePointer = "") {
|
|
108
109
|
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
const url = new URL(
|
|
110
|
+
const id = schema.$id || schema.id;
|
|
111
|
+
if (id) {
|
|
112
|
+
const url = new URL(id, baseURI.href);
|
|
112
113
|
if (url.hash.length > 1) {
|
|
113
114
|
lookup[url.href] = schema;
|
|
114
115
|
} else {
|
|
@@ -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);
|
|
@@ -1068,40 +1069,31 @@ function schemaPattern(pattern) {
|
|
|
1068
1069
|
}
|
|
1069
1070
|
|
|
1070
1071
|
// src/implementation/schema.ts
|
|
1071
|
-
var StorageField = /* @__PURE__ */ Symbol("apps.StorageField");
|
|
1072
1072
|
var Decoder = /* @__PURE__ */ Symbol("apps.Schema");
|
|
1073
1073
|
var decoderOf = (schema) => schema[Decoder];
|
|
1074
1074
|
var isSchema = (value) => typeof value === "object" && value !== null && Decoder in value;
|
|
1075
|
+
var schemaArgument = (value, role) => {
|
|
1076
|
+
if (isSchema(value)) return value;
|
|
1077
|
+
const received = value;
|
|
1078
|
+
throw new TypeError(
|
|
1079
|
+
`${role} must be a schema, such as string() or object({ ... }), but ${typeof received === "function" ? "it is a function. Call it, as in string()." : received === void 0 ? "it is undefined. Check that it is defined and imported before this declaration." : typeof received === "object" && received !== null && Object.getPrototypeOf(received) === Object.prototype ? "it is a plain object. Wrap its fields in object({ ... })." : "no apps schema constructor created it."}`
|
|
1080
|
+
);
|
|
1081
|
+
};
|
|
1075
1082
|
var parse = (decoder, input) => Effect_exports.suspend(() => Schema_exports.decodeUnknownEffect(decoder)(input)).pipe(
|
|
1076
1083
|
Effect_exports.mapError(() => new ValidationError())
|
|
1077
1084
|
);
|
|
1078
|
-
function wrap(decoder, optionalValue
|
|
1085
|
+
function wrap(decoder, optionalValue) {
|
|
1079
1086
|
return {
|
|
1080
1087
|
[Decoder]: decoder,
|
|
1081
|
-
...field === void 0 ? {} : { [StorageField]: field },
|
|
1082
1088
|
optionalValue,
|
|
1083
1089
|
parse: (input) => Effect_exports.runSync(parse(decoder, input)),
|
|
1084
|
-
optional: () => wrap(
|
|
1085
|
-
Schema_exports.optional(decoder),
|
|
1086
|
-
true,
|
|
1087
|
-
field === void 0 ? void 0 : { ...field, optional: true }
|
|
1088
|
-
),
|
|
1090
|
+
optional: () => wrap(Schema_exports.optional(decoder), true),
|
|
1089
1091
|
default: (value) => {
|
|
1090
1092
|
const parsed = Effect_exports.runSync(parse(decoder, value));
|
|
1091
1093
|
return {
|
|
1092
1094
|
...wrap(
|
|
1093
1095
|
decoder.annotate({ default: parsed }).pipe(Schema_exports.withDecodingDefault(Effect_exports.succeed(parsed))),
|
|
1094
|
-
false
|
|
1095
|
-
field === void 0 || parsed === void 0 ? void 0 : {
|
|
1096
|
-
...field,
|
|
1097
|
-
default: Schema_exports.decodeUnknownSync(
|
|
1098
|
-
Schema_exports.Union([
|
|
1099
|
-
Schema_exports.String,
|
|
1100
|
-
Schema_exports.Finite,
|
|
1101
|
-
Schema_exports.Boolean
|
|
1102
|
-
])
|
|
1103
|
-
)(parsed)
|
|
1104
|
-
}
|
|
1096
|
+
false
|
|
1105
1097
|
),
|
|
1106
1098
|
hasDefault: true,
|
|
1107
1099
|
inputOptional: optionalValue
|
|
@@ -1112,14 +1104,19 @@ function wrap(decoder, optionalValue, field) {
|
|
|
1112
1104
|
function string(options = {}) {
|
|
1113
1105
|
return wrap(
|
|
1114
1106
|
options.minLength === void 0 ? Schema_exports.String : Schema_exports.String.check(Schema_exports.isMinLength(options.minLength)),
|
|
1115
|
-
false
|
|
1116
|
-
{ kind: "string" }
|
|
1107
|
+
false
|
|
1117
1108
|
);
|
|
1118
1109
|
}
|
|
1119
|
-
var number = () => wrap(Schema_exports.Finite, false
|
|
1120
|
-
var boolean = () => wrap(Schema_exports.Boolean, false
|
|
1110
|
+
var number = () => wrap(Schema_exports.Finite, false);
|
|
1111
|
+
var boolean = () => wrap(Schema_exports.Boolean, false);
|
|
1121
1112
|
var json = () => wrap(Schema_exports.Json, false);
|
|
1122
|
-
var record = (value) => wrap(
|
|
1113
|
+
var record = (value) => wrap(
|
|
1114
|
+
Schema_exports.Record(
|
|
1115
|
+
Schema_exports.String,
|
|
1116
|
+
decoderOf(schemaArgument(value, "The record() value"))
|
|
1117
|
+
),
|
|
1118
|
+
false
|
|
1119
|
+
);
|
|
1123
1120
|
function literal(value) {
|
|
1124
1121
|
if (typeof value === "number") Effect_exports.runSync(parse(Schema_exports.Finite, value));
|
|
1125
1122
|
return wrap(
|
|
@@ -1127,10 +1124,13 @@ function literal(value) {
|
|
|
1127
1124
|
false
|
|
1128
1125
|
);
|
|
1129
1126
|
}
|
|
1130
|
-
var array = (item) => wrap(Schema_exports.Array(decoderOf(item)), false);
|
|
1127
|
+
var array = (item) => wrap(Schema_exports.Array(decoderOf(schemaArgument(item, "The array() item"))), false);
|
|
1131
1128
|
function object(fields) {
|
|
1132
1129
|
const entries = Object.entries(fields).map(
|
|
1133
|
-
([key, field]) => [
|
|
1130
|
+
([key, field]) => [
|
|
1131
|
+
key,
|
|
1132
|
+
decoderOf(schemaArgument(field, `The object() field ${JSON.stringify(key)}`))
|
|
1133
|
+
]
|
|
1134
1134
|
);
|
|
1135
1135
|
const decoder = entries.length === 0 ? withJsonSchemaDocument(
|
|
1136
1136
|
// Native Struct({}) accepts every non-null value and retains undeclared fields.
|
|
@@ -1144,6 +1144,25 @@ function object(fields) {
|
|
|
1144
1144
|
) : Schema_exports.Struct(Object.fromEntries(entries));
|
|
1145
1145
|
return { ...wrap(decoder, false), fields: Object.freeze({ ...fields }) };
|
|
1146
1146
|
}
|
|
1147
|
+
var Exposure = /* @__PURE__ */ Symbol("apps.FieldExposure");
|
|
1148
|
+
var exposureOf = (schema) => Exposure in schema && (schema[Exposure] === "plain" || schema[Exposure] === "raw") ? schema[Exposure] : void 0;
|
|
1149
|
+
var expose = (schema, exposure) => (
|
|
1150
|
+
// SAFETY: the copy keeps every member of S, and `optional` and `default` keep the marking.
|
|
1151
|
+
{
|
|
1152
|
+
...schema,
|
|
1153
|
+
[Exposure]: exposure,
|
|
1154
|
+
optional: () => expose(schema.optional(), exposure),
|
|
1155
|
+
default: (value) => expose(schema.default(value), exposure)
|
|
1156
|
+
}
|
|
1157
|
+
);
|
|
1158
|
+
var plain = (schema) => expose(schema, "plain");
|
|
1159
|
+
var raw = (schema) => expose(schema, "raw");
|
|
1160
|
+
var fieldExposure = (fields) => Object.fromEntries(
|
|
1161
|
+
Object.entries(fields).flatMap(([name, field]) => {
|
|
1162
|
+
const exposure = exposureOf(field);
|
|
1163
|
+
return exposure === void 0 ? [] : [[name, exposure]];
|
|
1164
|
+
})
|
|
1165
|
+
);
|
|
1147
1166
|
var ImportedJsonSchema = /* @__PURE__ */ Symbol("apps.JsonSchemaDocument");
|
|
1148
1167
|
var importedJsonSchema = (decoder) => ImportedJsonSchema in decoder ? decoder[ImportedJsonSchema] : void 0;
|
|
1149
1168
|
var withJsonSchemaDocument = (decoder, document) => Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
@@ -1273,18 +1292,425 @@ var containerKeywords = /* @__PURE__ */ new Set([
|
|
|
1273
1292
|
"else",
|
|
1274
1293
|
"dependentSchemas"
|
|
1275
1294
|
]);
|
|
1276
|
-
var
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1295
|
+
var echoableKey = (key) => /^[A-Za-z_$][\w$-]{0,63}$/.test(key);
|
|
1296
|
+
var schemaKey = (name) => echoableKey(name) ? name : JSON.stringify(name.slice(0, 64));
|
|
1297
|
+
var maxShapeKeys = 24;
|
|
1298
|
+
var objectShape = (keys, open, limit = maxShapeKeys) => {
|
|
1299
|
+
const listed = keys.slice(0, limit).map(({ name, optional }) => `${schemaKey(name)}${optional ? "?" : ""}`);
|
|
1300
|
+
const parts = [
|
|
1301
|
+
...listed,
|
|
1302
|
+
...keys.length > limit ? [`${keys.length - limit} more`] : [],
|
|
1303
|
+
...open ? ["..."] : []
|
|
1304
|
+
];
|
|
1305
|
+
return parts.length === 0 ? "object {} with no keys" : `object {${parts.join(", ")}}`;
|
|
1306
|
+
};
|
|
1307
|
+
var maxListedValues = 10;
|
|
1308
|
+
var maxValuesText = 200;
|
|
1309
|
+
var valueText = (value) => typeof value === "bigint" ? `${value}n` : JSON.stringify(value);
|
|
1310
|
+
var allowedValues = (values) => {
|
|
1311
|
+
const texts = [...new Set(values.map(valueText))];
|
|
1312
|
+
const listed = [];
|
|
1313
|
+
for (const text of texts) {
|
|
1314
|
+
if (listed.length === maxListedValues || [...listed, text].join(", ").length > maxValuesText)
|
|
1315
|
+
break;
|
|
1316
|
+
listed.push(text);
|
|
1317
|
+
}
|
|
1318
|
+
const [only] = listed;
|
|
1319
|
+
if (texts.length === 0) return "no value, since the schema allows none";
|
|
1320
|
+
if (only === void 0)
|
|
1321
|
+
return texts.length === 1 ? "a fixed value too long to list" : `one of ${texts.length} values too long to list`;
|
|
1322
|
+
if (texts.length === 1) return only;
|
|
1323
|
+
const rest = texts.length - listed.length;
|
|
1324
|
+
return `one of ${listed.join(", ")}${rest > 0 ? ` and ${rest} more` : ""}`;
|
|
1325
|
+
};
|
|
1326
|
+
var maxAlternativeKeys = 8;
|
|
1327
|
+
var maxAlternativesText = 360;
|
|
1328
|
+
var unionShape = (alternatives, selector) => {
|
|
1329
|
+
const listed = [];
|
|
1330
|
+
for (const alternative of alternatives) {
|
|
1331
|
+
if (listed.length > 0 && [...listed, alternative].join(" or ").length > maxAlternativesText)
|
|
1332
|
+
break;
|
|
1333
|
+
listed.push(alternative);
|
|
1334
|
+
}
|
|
1335
|
+
const rest = alternatives.length - listed.length;
|
|
1336
|
+
return `${[...listed, ...rest > 0 ? [`${rest} more`] : []].join(" or ")}${selector === void 0 ? "" : `, told apart by ${schemaKey(selector)}`}`;
|
|
1337
|
+
};
|
|
1338
|
+
var missingKey = (expected) => expected === void 0 ? missingKeyText : `${missingKeyText}. Expected ${expected}`;
|
|
1339
|
+
var missingKeyText = "Missing key";
|
|
1340
|
+
var isJsonRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1341
|
+
var pointerSegments = (pointer) => pointer === "#" || pointer === "" ? [] : pointer.replace(/^#?\//, "").split("/").map((segment) => decodeURIComponent(segment).replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
1342
|
+
var resolved = (lookup, uri2) => typeof uri2 === "string" && Object.hasOwn(lookup, uri2) ? lookup[uri2] : void 0;
|
|
1343
|
+
var referenced = (lookup, node) => isJsonRecord(node) ? resolved(lookup, Reflect.get(node, "__absolute_ref__") ?? node.$ref) : void 0;
|
|
1344
|
+
var memberKeywords = /* @__PURE__ */ new Set([...schemaMaps, ...schemaArrays, "dependencies"]);
|
|
1345
|
+
var combinators = /* @__PURE__ */ new Set(["allOf", "anyOf", "oneOf"]);
|
|
1346
|
+
var schemaAt = (document, lookup, segments) => {
|
|
1347
|
+
const anchoredAt = (node2, anchor2) => anchor2 === null && isJsonRecord(node2) && node2.$recursiveAnchor === true ? node2 : anchor2;
|
|
1348
|
+
const pending = [...segments];
|
|
1349
|
+
let node = document;
|
|
1350
|
+
let anchor = anchoredAt(document, null);
|
|
1351
|
+
for (let keyword = pending.shift(); keyword !== void 0; keyword = pending.shift()) {
|
|
1352
|
+
if (!isJsonRecord(node)) return void 0;
|
|
1353
|
+
if (keyword === "$recursiveRef") {
|
|
1354
|
+
const target = anchor === null ? resolved(lookup, Reflect.get(node, "__absolute_recursive_ref__")) : anchor;
|
|
1355
|
+
if (anchor !== null) node = anchor;
|
|
1356
|
+
anchor = target;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (keyword === "$ref") node = referenced(lookup, node);
|
|
1360
|
+
else {
|
|
1361
|
+
const value = Object.hasOwn(node, keyword) ? node[keyword] : void 0;
|
|
1362
|
+
if (memberKeywords.has(keyword) || keyword === "items" && Array.isArray(value)) {
|
|
1363
|
+
const member = pending.shift();
|
|
1364
|
+
if (member === void 0) return value;
|
|
1365
|
+
if (combinators.has(keyword) && node.$recursiveAnchor !== true) anchor = null;
|
|
1366
|
+
node = Array.isArray(value) ? /^\d+$/.test(member) ? value[Number(member)] : void 0 : isJsonRecord(value) && Object.hasOwn(value, member) ? value[member] : void 0;
|
|
1367
|
+
} else node = value;
|
|
1368
|
+
}
|
|
1369
|
+
anchor = anchoredAt(node, anchor);
|
|
1370
|
+
}
|
|
1371
|
+
return node;
|
|
1372
|
+
};
|
|
1373
|
+
var jsonObjectShape = (node) => {
|
|
1374
|
+
if (!isJsonRecord(node)) return "object";
|
|
1375
|
+
const properties = isJsonRecord(node.properties) ? Object.keys(node.properties) : [];
|
|
1376
|
+
const required = new Set(Array.isArray(node.required) ? node.required : []);
|
|
1377
|
+
const open = node.additionalProperties !== false || isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0;
|
|
1378
|
+
return properties.length === 0 && open ? "object" : objectShape(
|
|
1379
|
+
properties.map((name) => ({ name, optional: !required.has(name) })),
|
|
1380
|
+
open
|
|
1381
|
+
);
|
|
1382
|
+
};
|
|
1383
|
+
var locationKey = (segments) => JSON.stringify(segments);
|
|
1384
|
+
var emptyOutline = {
|
|
1385
|
+
types: void 0,
|
|
1386
|
+
properties: /* @__PURE__ */ new Map(),
|
|
1387
|
+
required: /* @__PURE__ */ new Set(),
|
|
1388
|
+
closed: false,
|
|
1389
|
+
values: void 0
|
|
1390
|
+
};
|
|
1391
|
+
var commonValues = (a, b) => a === void 0 ? b : b === void 0 ? a : a.filter((value) => b.some((other) => deepCompareStrict(value, other)));
|
|
1392
|
+
var strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1393
|
+
var commonTypes = (a, b) => new Set(
|
|
1394
|
+
[...a].flatMap(
|
|
1395
|
+
(type) => b.has(type) ? [type] : type === "number" && b.has("integer") || type === "integer" && b.has("number") ? ["integer"] : []
|
|
1396
|
+
)
|
|
1397
|
+
);
|
|
1398
|
+
var mergeOutlines = (a, b) => ({
|
|
1399
|
+
types: a.types === void 0 ? b.types : b.types === void 0 ? a.types : commonTypes(a.types, b.types),
|
|
1400
|
+
properties: new Map([...a.properties, ...b.properties]),
|
|
1401
|
+
required: /* @__PURE__ */ new Set([...a.required, ...b.required]),
|
|
1402
|
+
closed: a.closed || b.closed,
|
|
1403
|
+
values: commonValues(a.values, b.values)
|
|
1404
|
+
});
|
|
1405
|
+
var outlineOf = (node, inspection, seen = /* @__PURE__ */ new Set()) => {
|
|
1406
|
+
if (!isJsonRecord(node) || seen.has(node)) return emptyOutline;
|
|
1407
|
+
const within = /* @__PURE__ */ new Set([...seen, node]);
|
|
1408
|
+
const own = {
|
|
1409
|
+
types: typeof node.type === "string" ? /* @__PURE__ */ new Set([node.type]) : Array.isArray(node.type) ? new Set(strings(node.type)) : void 0,
|
|
1410
|
+
properties: new Map(isJsonRecord(node.properties) ? Object.entries(node.properties) : []),
|
|
1411
|
+
required: new Set(strings(node.required)),
|
|
1412
|
+
closed: (node.additionalProperties === false || node.unevaluatedProperties === false) && !(isJsonRecord(node.patternProperties) && Object.keys(node.patternProperties).length > 0),
|
|
1413
|
+
values: commonValues(
|
|
1414
|
+
Object.hasOwn(node, "const") ? [node.const] : void 0,
|
|
1415
|
+
Array.isArray(node.enum) ? node.enum : void 0
|
|
1416
|
+
)
|
|
1417
|
+
};
|
|
1418
|
+
return [inspection.referenced(node), ...Array.isArray(node.allOf) ? node.allOf : []].reduce(
|
|
1419
|
+
(outline, member) => mergeOutlines(outline, outlineOf(member, inspection, within)),
|
|
1420
|
+
own
|
|
1421
|
+
);
|
|
1422
|
+
};
|
|
1423
|
+
var otherConstraints = "a value with other constraints";
|
|
1424
|
+
var outlineText = (outline, limit) => {
|
|
1425
|
+
if (outline.values !== void 0) return allowedValues(outline.values);
|
|
1426
|
+
const names = [
|
|
1427
|
+
...outline.properties.keys(),
|
|
1428
|
+
...[...outline.required].filter((name) => !outline.properties.has(name))
|
|
1429
|
+
];
|
|
1430
|
+
const shape = names.length === 0 && !outline.closed ? "object" : objectShape(
|
|
1431
|
+
names.map((name) => ({ name, optional: !outline.required.has(name) })),
|
|
1432
|
+
!outline.closed,
|
|
1433
|
+
limit
|
|
1434
|
+
);
|
|
1435
|
+
if (outline.types === void 0)
|
|
1436
|
+
return names.length > 0 || outline.closed ? shape : otherConstraints;
|
|
1437
|
+
return [...outline.types].map((type) => type === "object" ? shape : type).join(" or ");
|
|
1438
|
+
};
|
|
1439
|
+
var describeOutline = (outline) => outlineText(outline, maxAlternativeKeys);
|
|
1440
|
+
var typed = (outline) => outline.values !== void 0 || outline.types !== void 0;
|
|
1441
|
+
var describeProperty = (node, inspection) => {
|
|
1442
|
+
const target = inspection.referenced(node) ?? node;
|
|
1443
|
+
if (isJsonRecord(target) && Object.hasOwn(target, "oneOf")) return void 0;
|
|
1444
|
+
const outline = outlineOf(node, inspection);
|
|
1445
|
+
if (typed(outline)) return outlineText(outline, maxShapeKeys);
|
|
1446
|
+
const members = isJsonRecord(target) && Array.isArray(target.anyOf) ? target.anyOf : [];
|
|
1447
|
+
const outlines = members.filter((member) => member !== false).map((member) => outlineOf(member, inspection));
|
|
1448
|
+
return outlines.length === 0 || !outlines.every(typed) ? void 0 : unionShape([...new Set(outlines.map(describeOutline))], void 0);
|
|
1449
|
+
};
|
|
1450
|
+
var maxPatternText = 160;
|
|
1451
|
+
var count = (amount, noun) => `${amount} ${noun}${amount === 1 ? "" : "s"}`;
|
|
1452
|
+
var constraintProblem = (keyword, node) => {
|
|
1453
|
+
if (!isJsonRecord(node)) return void 0;
|
|
1454
|
+
const value = node[keyword];
|
|
1455
|
+
if (keyword === "pattern")
|
|
1456
|
+
return typeof value !== "string" ? void 0 : value.length <= maxPatternText ? `Expected a string matching the pattern ${JSON.stringify(value)}` : "Expected a string matching the schema's pattern, which is too long to show";
|
|
1457
|
+
if (keyword === "format")
|
|
1458
|
+
return typeof value === "string" ? `Expected a string in the ${JSON.stringify(value.slice(0, 64))} format` : void 0;
|
|
1459
|
+
if (keyword === "uniqueItems") return "Expected an array without repeated items";
|
|
1460
|
+
if (typeof value !== "number") return void 0;
|
|
1461
|
+
switch (keyword) {
|
|
1462
|
+
// Draft 4's boolean `exclusiveMinimum` is not applied: imported schemas validate as draft 7
|
|
1463
|
+
// or 2020-12, where `minimum` and `maximum` always include their bound.
|
|
1464
|
+
case "minimum":
|
|
1465
|
+
return `Expected a number of at least ${value}`;
|
|
1466
|
+
case "maximum":
|
|
1467
|
+
return `Expected a number of at most ${value}`;
|
|
1468
|
+
case "exclusiveMinimum":
|
|
1469
|
+
return `Expected a number greater than ${value}`;
|
|
1470
|
+
case "exclusiveMaximum":
|
|
1471
|
+
return `Expected a number less than ${value}`;
|
|
1472
|
+
case "multipleOf":
|
|
1473
|
+
return `Expected a multiple of ${value}`;
|
|
1474
|
+
case "minLength":
|
|
1475
|
+
return `Expected a string of at least ${count(value, "character")}`;
|
|
1476
|
+
case "maxLength":
|
|
1477
|
+
return `Expected a string of at most ${count(value, "character")}`;
|
|
1478
|
+
case "minItems":
|
|
1479
|
+
return `Expected an array of at least ${count(value, "item")}`;
|
|
1480
|
+
case "maxItems":
|
|
1481
|
+
return `Expected an array of at most ${count(value, "item")}`;
|
|
1482
|
+
case "minProperties":
|
|
1483
|
+
return `Expected an object with at least ${count(value, "key")}`;
|
|
1484
|
+
case "maxProperties":
|
|
1485
|
+
return `Expected an object with at most ${count(value, "key")}`;
|
|
1486
|
+
default:
|
|
1487
|
+
return void 0;
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
var overlap = (outline, value, inspection, depth = 0) => !isJsonRecord(value) || depth > 16 ? 0 : Object.entries(value).reduce((total, [key, item]) => {
|
|
1491
|
+
const property = outline.properties.get(key);
|
|
1492
|
+
return property === void 0 ? total : total + 1 + overlap(outlineOf(property, inspection), item, inspection, depth + 1);
|
|
1493
|
+
}, 0);
|
|
1494
|
+
var jsonType = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value === "object" ? "object" : typeof value;
|
|
1495
|
+
var accepted = (outline, value) => {
|
|
1496
|
+
const type = jsonType(value);
|
|
1497
|
+
if (outline.values !== void 0)
|
|
1498
|
+
return outline.values.some((allowed) => jsonType(allowed) === type);
|
|
1499
|
+
if (outline.types === void 0) return true;
|
|
1500
|
+
return outline.types.has(type) || type === "number" && outline.types.has("integer") && Number.isInteger(value);
|
|
1501
|
+
};
|
|
1502
|
+
var valueAt = (input, location2) => location2.reduce(
|
|
1503
|
+
(value, segment) => Array.isArray(value) ? value[Number(segment)] : isJsonRecord(value) && Object.hasOwn(value, segment) ? value[segment] : void 0,
|
|
1504
|
+
input
|
|
1505
|
+
);
|
|
1506
|
+
var discriminatorOf = (holder) => isJsonRecord(holder) && isJsonRecord(holder.discriminator) ? holder.discriminator : void 0;
|
|
1507
|
+
var definitionName = (reference) => {
|
|
1508
|
+
if (typeof reference !== "string" || !reference.startsWith("#/")) return void 0;
|
|
1509
|
+
const segments = pointerSegments(reference);
|
|
1510
|
+
const container = segments.at(-2);
|
|
1511
|
+
return container === "$defs" || container === "definitions" || container === "schemas" && segments.at(-3) === "components" ? segments.at(-1) : void 0;
|
|
1512
|
+
};
|
|
1513
|
+
var discriminatedName = (holder, value) => {
|
|
1514
|
+
const discriminator = discriminatorOf(holder);
|
|
1515
|
+
if (discriminator === void 0 || typeof value !== "string") return void 0;
|
|
1516
|
+
const { mapping } = discriminator;
|
|
1517
|
+
const target = isJsonRecord(mapping) && Object.hasOwn(mapping, value) ? mapping[value] : value;
|
|
1518
|
+
if (typeof target !== "string") return void 0;
|
|
1519
|
+
return /^[\w.-]+$/.test(target) ? target : definitionName(target);
|
|
1520
|
+
};
|
|
1521
|
+
var selectorOf = (holder, alternatives, inspection) => {
|
|
1522
|
+
const declared = discriminatorOf(holder)?.propertyName;
|
|
1523
|
+
if (typeof declared === "string") return declared;
|
|
1524
|
+
const [first] = alternatives;
|
|
1525
|
+
if (first === void 0 || alternatives.length < 2) return void 0;
|
|
1526
|
+
return [...first.properties.keys()].find(
|
|
1527
|
+
(key) => alternatives.every(
|
|
1528
|
+
(alternative) => alternative.properties.has(key) && outlineOf(alternative.properties.get(key), inspection).values !== void 0
|
|
1529
|
+
)
|
|
1530
|
+
);
|
|
1531
|
+
};
|
|
1532
|
+
var alternativeErrors = (errors, head, schemas) => {
|
|
1533
|
+
const prefix = `${errors[head]?.keywordLocation}/`;
|
|
1534
|
+
const alternatives = /* @__PURE__ */ new Map();
|
|
1535
|
+
const settle = (current2, next) => {
|
|
1536
|
+
const collected = alternatives.get(current2);
|
|
1537
|
+
const rejected = Array.isArray(schemas) ? schemas.slice(current2 + 1, next).filter((schema) => schema === false).length : 0;
|
|
1538
|
+
if (collected !== void 0) collected.splice(collected.length - rejected, rejected);
|
|
1539
|
+
};
|
|
1540
|
+
let index = head + 1;
|
|
1541
|
+
let current = -1;
|
|
1542
|
+
for (; index < errors.length; index++) {
|
|
1543
|
+
const error = errors[index];
|
|
1544
|
+
if (error === void 0) break;
|
|
1545
|
+
if (error.keywordLocation.startsWith(prefix)) {
|
|
1546
|
+
const alternative = Number(error.keywordLocation.slice(prefix.length).split("/")[0]);
|
|
1547
|
+
if (alternative !== current) settle(current, alternative);
|
|
1548
|
+
current = alternative;
|
|
1549
|
+
} else if (error.keyword !== "false") break;
|
|
1550
|
+
if (current >= 0) alternatives.set(current, [...alternatives.get(current) ?? [], error]);
|
|
1551
|
+
}
|
|
1552
|
+
settle(current, Array.isArray(schemas) ? schemas.length : current);
|
|
1553
|
+
return { alternatives, end: index };
|
|
1554
|
+
};
|
|
1555
|
+
var pathOf = (location2) => location2.map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
|
|
1556
|
+
var unionProblems = (union, schemas, errorsByAlternative, inspection) => {
|
|
1557
|
+
const location2 = pointerSegments(union.instanceLocation);
|
|
1558
|
+
const path = pathOf(location2);
|
|
1559
|
+
if (!Array.isArray(schemas))
|
|
1560
|
+
return [
|
|
1561
|
+
{ path, issue: `Failed the "${union.keyword}" constraint` },
|
|
1562
|
+
...[...errorsByAlternative.values()].flatMap((errors) => problemsOf(errors, inspection))
|
|
1563
|
+
];
|
|
1564
|
+
const alternatives = schemas.flatMap(
|
|
1565
|
+
(schema, index) => schema === false ? [] : [
|
|
1566
|
+
{
|
|
1567
|
+
schema,
|
|
1568
|
+
matched: !errorsByAlternative.has(index),
|
|
1569
|
+
problems: () => problemsOf(errorsByAlternative.get(index) ?? [], inspection)
|
|
1570
|
+
}
|
|
1571
|
+
]
|
|
1572
|
+
);
|
|
1573
|
+
const [only] = alternatives;
|
|
1574
|
+
if (only === void 0) return [{ path, issue: "No value is allowed here" }];
|
|
1575
|
+
if (alternatives.length === 1) return only.problems();
|
|
1576
|
+
const holder = inspection.schemaAt(pointerSegments(union.keywordLocation).slice(0, -1));
|
|
1577
|
+
const shared = outlineOf(holder, inspection);
|
|
1578
|
+
const own = alternatives.map(({ schema }) => outlineOf(schema, inspection));
|
|
1579
|
+
const outlines = own.map((outline) => mergeOutlines(shared, outline));
|
|
1580
|
+
const selector = selectorOf(holder, own, inspection);
|
|
1581
|
+
const expected = `Expected ${unionShape(outlines.map(describeOutline), selector)}`;
|
|
1582
|
+
const matched = alternatives.filter((alternative) => alternative.matched).length;
|
|
1583
|
+
if (union.keyword === "oneOf" && matched > 1)
|
|
1584
|
+
return [{ path, issue: `${expected}. Exactly one may match, but ${matched} do` }];
|
|
1585
|
+
const fixed = outlines.flatMap(({ values }) => values === void 0 ? [] : [values]);
|
|
1586
|
+
if (fixed.length === outlines.length)
|
|
1587
|
+
return [
|
|
1588
|
+
{
|
|
1589
|
+
path,
|
|
1590
|
+
issue: union.keyword === "oneOf" ? `${expected}. Exactly one alternative must match` : `Expected ${allowedValues(fixed.flat())}`
|
|
1591
|
+
}
|
|
1592
|
+
];
|
|
1593
|
+
const value = valueAt(inspection.input, location2);
|
|
1594
|
+
const selectorValue = selector !== void 0 && isJsonRecord(value) && Object.hasOwn(value, selector) ? { value: value[selector] } : void 0;
|
|
1595
|
+
const named = discriminatedName(holder, selectorValue?.value);
|
|
1596
|
+
const ranked = alternatives.map(({ schema, problems }, index) => {
|
|
1597
|
+
const outline = outlines[index] ?? emptyOutline;
|
|
1598
|
+
const property = own[index]?.properties.get(selector ?? "");
|
|
1599
|
+
return {
|
|
1600
|
+
index,
|
|
1601
|
+
problems: problems(),
|
|
1602
|
+
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)),
|
|
1603
|
+
typed: accepted(outline, value),
|
|
1604
|
+
overlap: overlap(outline, value, inspection)
|
|
1285
1605
|
};
|
|
1286
|
-
return [issue];
|
|
1287
1606
|
});
|
|
1607
|
+
const closest = ranked.reduce(
|
|
1608
|
+
(best, candidate) => ([
|
|
1609
|
+
Number(candidate.selected) - Number(best.selected),
|
|
1610
|
+
Number(candidate.typed) - Number(best.typed),
|
|
1611
|
+
candidate.overlap - best.overlap,
|
|
1612
|
+
best.problems.length - candidate.problems.length
|
|
1613
|
+
].find((difference) => difference !== 0) ?? 0) > 0 ? candidate : best
|
|
1614
|
+
);
|
|
1615
|
+
return closest.selected || closest.typed ? [
|
|
1616
|
+
{
|
|
1617
|
+
path,
|
|
1618
|
+
issue: `${expected}. Closest is alternative ${closest.index + 1}, whose problems follow`
|
|
1619
|
+
},
|
|
1620
|
+
...closest.problems
|
|
1621
|
+
] : [{ path, issue: expected }];
|
|
1622
|
+
};
|
|
1623
|
+
var problemsOf = (errors, inspection) => {
|
|
1624
|
+
const closed = /* @__PURE__ */ new Map();
|
|
1625
|
+
const problems = [];
|
|
1626
|
+
for (let index = 0; index < errors.length; index++) {
|
|
1627
|
+
const error = errors[index];
|
|
1628
|
+
if (error === void 0) break;
|
|
1629
|
+
const { keyword, instanceLocation, keywordLocation } = error;
|
|
1630
|
+
if (keyword === "anyOf" || keyword === "oneOf") {
|
|
1631
|
+
const schemas = inspection.schemaAt(pointerSegments(keywordLocation));
|
|
1632
|
+
const { alternatives, end } = alternativeErrors(errors, index, schemas);
|
|
1633
|
+
problems.push(...unionProblems(error, schemas, alternatives, inspection));
|
|
1634
|
+
index = end - 1;
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
const location2 = pointerSegments(instanceLocation);
|
|
1638
|
+
const path = pathOf(location2);
|
|
1639
|
+
const problem = (issue, at = path) => problems.push({ path: at, issue });
|
|
1640
|
+
const node = () => inspection.schemaAt(pointerSegments(keywordLocation).slice(0, -1));
|
|
1641
|
+
if (keyword === "additionalProperties" || keyword === "unevaluatedProperties") {
|
|
1642
|
+
closed.set(locationKey(location2), node());
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
if (containerKeywords.has(keyword)) continue;
|
|
1646
|
+
if (keyword === "false") {
|
|
1647
|
+
const key = location2.at(-1);
|
|
1648
|
+
const parent = locationKey(location2.slice(0, -1));
|
|
1649
|
+
if (key === void 0 || !closed.has(parent)) problem("No value is allowed here");
|
|
1650
|
+
else
|
|
1651
|
+
problem(
|
|
1652
|
+
`Unexpected key${echoableKey(key) ? ` "${key}"` : ""}. Expected ${jsonObjectShape(closed.get(parent))}`,
|
|
1653
|
+
path.slice(0, -1)
|
|
1654
|
+
);
|
|
1655
|
+
continue;
|
|
1656
|
+
}
|
|
1657
|
+
const required = keyword === "required" ? /required property "([^"]*)"/.exec(error.error) : null;
|
|
1658
|
+
if (required !== null) {
|
|
1659
|
+
const name = required[1] ?? "";
|
|
1660
|
+
const property = outlineOf(node(), inspection).properties.get(name);
|
|
1661
|
+
problem(
|
|
1662
|
+
missingKey(property === void 0 ? void 0 : describeProperty(property, inspection)),
|
|
1663
|
+
[...path, name]
|
|
1664
|
+
);
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
const expected = keyword === "type" ? /Expected "([^.]*)"\.?$/.exec(error.error) : null;
|
|
1668
|
+
if (expected !== null) {
|
|
1669
|
+
const types = (expected[1] ?? "").split('", "').map((type) => type === "object" ? jsonObjectShape(node()) : type);
|
|
1670
|
+
problem(`Expected ${types.join(" or ")}`);
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
if (keyword === "const" || keyword === "enum") {
|
|
1674
|
+
const schema = node();
|
|
1675
|
+
const values = !isJsonRecord(schema) ? void 0 : keyword === "const" ? Object.hasOwn(schema, "const") ? [schema.const] : void 0 : Array.isArray(schema.enum) ? schema.enum : void 0;
|
|
1676
|
+
problem(
|
|
1677
|
+
values === void 0 ? "Expected one of the allowed values" : `Expected ${allowedValues(values)}`
|
|
1678
|
+
);
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
problem(constraintProblem(keyword, node()) ?? `Failed the "${keyword}" constraint`);
|
|
1682
|
+
}
|
|
1683
|
+
return problems;
|
|
1684
|
+
};
|
|
1685
|
+
var documentKeys = (document) => {
|
|
1686
|
+
const named = /* @__PURE__ */ new Set();
|
|
1687
|
+
let any = false;
|
|
1688
|
+
const visit = (node, depth) => {
|
|
1689
|
+
if (depth > 64 || typeof node !== "object" || node === null) return;
|
|
1690
|
+
if (Array.isArray(node)) {
|
|
1691
|
+
for (const item of node) visit(item, depth + 1);
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
const record2 = node;
|
|
1695
|
+
if (isJsonRecord(record2.properties))
|
|
1696
|
+
for (const name of Object.keys(record2.properties)) named.add(name);
|
|
1697
|
+
for (const name of strings(record2.required)) named.add(name);
|
|
1698
|
+
if (isJsonRecord(record2.dependentRequired))
|
|
1699
|
+
for (const [name, names] of Object.entries(record2.dependentRequired)) {
|
|
1700
|
+
named.add(name);
|
|
1701
|
+
for (const other of strings(names)) named.add(other);
|
|
1702
|
+
}
|
|
1703
|
+
if (isJsonRecord(record2.patternProperties) && Object.keys(record2.patternProperties).length > 0 || isJsonRecord(record2.additionalProperties) || isJsonRecord(record2.unevaluatedProperties))
|
|
1704
|
+
any = true;
|
|
1705
|
+
for (const value of Object.values(record2)) visit(value, depth + 1);
|
|
1706
|
+
};
|
|
1707
|
+
visit(document, 0);
|
|
1708
|
+
return (key) => any || named.has(key);
|
|
1709
|
+
};
|
|
1710
|
+
var importedKeys = /* @__PURE__ */ new WeakMap();
|
|
1711
|
+
var importedSchemaKeys = (check) => importedKeys.get(check);
|
|
1712
|
+
var jsonSchemaProblems = (errors, inspection) => {
|
|
1713
|
+
const problems = problemsOf(errors, inspection);
|
|
1288
1714
|
return problems.length === 0 ? false : problems;
|
|
1289
1715
|
};
|
|
1290
1716
|
var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
@@ -1311,28 +1737,42 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
|
1311
1737
|
throw new ValidationError();
|
|
1312
1738
|
}
|
|
1313
1739
|
}
|
|
1740
|
+
const inspection = (input) => ({
|
|
1741
|
+
schemaAt: (segments) => schemaAt(normalized, lookup, segments),
|
|
1742
|
+
referenced: (node) => referenced(lookup, node),
|
|
1743
|
+
accepts: (node, value) => {
|
|
1744
|
+
if (typeof node !== "boolean" && !isJsonRecord(node)) return false;
|
|
1745
|
+
try {
|
|
1746
|
+
return validate(value, node, draft, lookup).valid;
|
|
1747
|
+
} catch {
|
|
1748
|
+
return false;
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
input
|
|
1752
|
+
});
|
|
1314
1753
|
return {
|
|
1315
|
-
validate: (input) => validate(input, normalized, draft, lookup)
|
|
1754
|
+
validate: (input) => validate(input, normalized, draft, lookup),
|
|
1755
|
+
inspection
|
|
1316
1756
|
};
|
|
1317
1757
|
},
|
|
1318
1758
|
catch: () => new ValidationError()
|
|
1319
1759
|
});
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
{ expected: "a value matching a supported imported JSON Schema" }
|
|
1331
|
-
)
|
|
1760
|
+
const check = Schema_exports.makeFilter(
|
|
1761
|
+
(value) => {
|
|
1762
|
+
try {
|
|
1763
|
+
const result = validator.validate(value);
|
|
1764
|
+
return result.valid || jsonSchemaProblems(result.errors, validator.inspection(value));
|
|
1765
|
+
} catch {
|
|
1766
|
+
return false;
|
|
1767
|
+
}
|
|
1768
|
+
},
|
|
1769
|
+
{ expected: "a value matching a supported imported JSON Schema" }
|
|
1332
1770
|
);
|
|
1771
|
+
importedKeys.set(check, documentKeys(document));
|
|
1772
|
+
const decoder = Schema_exports.Json.check(check);
|
|
1333
1773
|
return Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
1334
1774
|
});
|
|
1335
|
-
var
|
|
1775
|
+
var lazyCompiledDecoder = (document) => {
|
|
1336
1776
|
const read = once(document);
|
|
1337
1777
|
let compiled;
|
|
1338
1778
|
const compile = Effect_exports.suspend(
|
|
@@ -1352,9 +1792,11 @@ var lazyDecoder = (document) => {
|
|
|
1352
1792
|
Effect_exports.flatMap((schema) => SchemaParser_exports.decodeUnknownEffect(schema)(input, options))
|
|
1353
1793
|
)
|
|
1354
1794
|
);
|
|
1355
|
-
return withLazyJsonSchemaDocument(decoder, read);
|
|
1795
|
+
return { decoder: withLazyJsonSchemaDocument(decoder, read), compile };
|
|
1356
1796
|
};
|
|
1797
|
+
var lazyDecoder = (document) => lazyCompiledDecoder(document).decoder;
|
|
1357
1798
|
var lazyJsonSchemaDecoder = (document) => Effect_exports.sync(() => lazyDecoder(document));
|
|
1799
|
+
var preparedJsonSchemaDecoder = (document) => lazyCompiledDecoder(() => document);
|
|
1358
1800
|
var isJsonValue = Schema_exports.is(Schema_exports.Json);
|
|
1359
1801
|
var jsonDocument = (input) => {
|
|
1360
1802
|
if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
|
|
@@ -1384,13 +1826,21 @@ var jsonSchema = (input) => {
|
|
|
1384
1826
|
false
|
|
1385
1827
|
);
|
|
1386
1828
|
};
|
|
1387
|
-
var
|
|
1388
|
-
|
|
1389
|
-
|
|
1829
|
+
var jsonSchemaDocument = (decoder) => {
|
|
1830
|
+
const imported = importedJsonSchema(decoder);
|
|
1831
|
+
if (imported !== void 0) return Schema_exports.decodeUnknownEffect(JsonObject)(imported);
|
|
1832
|
+
const document = Schema_exports.toJsonSchemaDocument(decoder);
|
|
1833
|
+
return Schema_exports.decodeUnknownEffect(JsonObject)({
|
|
1834
|
+
...document.schema,
|
|
1835
|
+
$defs: document.definitions,
|
|
1836
|
+
$schema: "https://json-schema.org/draft/2020-12/schema"
|
|
1837
|
+
});
|
|
1838
|
+
};
|
|
1390
1839
|
|
|
1391
1840
|
export {
|
|
1392
1841
|
decoderOf,
|
|
1393
1842
|
isSchema,
|
|
1843
|
+
schemaArgument,
|
|
1394
1844
|
parse,
|
|
1395
1845
|
wrap,
|
|
1396
1846
|
string,
|
|
@@ -1401,15 +1851,25 @@ export {
|
|
|
1401
1851
|
literal,
|
|
1402
1852
|
array,
|
|
1403
1853
|
object,
|
|
1854
|
+
plain,
|
|
1855
|
+
raw,
|
|
1856
|
+
fieldExposure,
|
|
1404
1857
|
importedJsonSchema,
|
|
1405
1858
|
once,
|
|
1406
1859
|
withLazyJsonSchemaDocument,
|
|
1407
1860
|
nestJsonSchema,
|
|
1861
|
+
echoableKey,
|
|
1862
|
+
objectShape,
|
|
1863
|
+
allowedValues,
|
|
1864
|
+
maxAlternativeKeys,
|
|
1865
|
+
unionShape,
|
|
1866
|
+
missingKey,
|
|
1867
|
+
missingKeyText,
|
|
1868
|
+
importedSchemaKeys,
|
|
1408
1869
|
compileJsonSchemaDecoder,
|
|
1409
1870
|
lazyJsonSchemaDecoder,
|
|
1871
|
+
preparedJsonSchemaDecoder,
|
|
1410
1872
|
jsonSchemaDecoder,
|
|
1411
1873
|
jsonSchema,
|
|
1412
|
-
|
|
1413
|
-
id,
|
|
1414
|
-
userId
|
|
1874
|
+
jsonSchemaDocument
|
|
1415
1875
|
};
|