apps 0.0.1-beta.7 → 0.0.1-beta.70
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 +25 -22
- package/framework-reference.json +1 -1
- package/js/{chunk-UESPOTUI.js → chunk-2YSTJMBD.js} +899 -190
- package/js/{chunk-RJDDBDSN.js → chunk-3CVQ3VPP.js} +762 -171
- package/js/chunk-3R3KFCDU.js +426 -0
- package/js/{chunk-FL2QR3XW.js → chunk-4NCIPADO.js} +326 -69
- package/js/chunk-5FHWNLCI.js +88 -0
- package/js/{chunk-M3B3DE4K.js → chunk-74YVXBKY.js} +463 -218
- package/js/chunk-7LMU3ER3.js +274 -0
- package/js/chunk-CDXQDN7W.js +92 -0
- package/js/{chunk-RFVIONFX.js → chunk-ECCWT5GJ.js} +79 -41
- package/js/{chunk-UK573G7W.js → chunk-EOPQ727L.js} +87 -51
- package/js/{chunk-27F7W2LG.js → chunk-H2CJWXA3.js} +2 -2
- package/js/{chunk-JU7VHODU.js → chunk-H72MEDMN.js} +65 -10
- package/js/{chunk-CDL5PM2Q.js → chunk-IFJU5SYQ.js} +19082 -18402
- package/js/{chunk-VFZKSM3T.js → chunk-JPEUKEV4.js} +3 -3
- package/js/{chunk-WLE7WX2U.js → chunk-JW5LYSER.js} +2262 -474
- package/js/{chunk-5T57N25Q.js → chunk-KGCTYL2S.js} +511 -63
- package/js/{chunk-KUMBKVJD.js → chunk-KLYSEHUD.js} +2 -2
- package/js/chunk-M5OLYYNU.js +347 -0
- package/js/chunk-MHB7IFG7.js +49 -0
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-57RKNWL2.js → chunk-PD6I2SDG.js} +4 -4
- package/js/{chunk-NKLWZJLE.js → chunk-RUP4JMKO.js} +25 -14
- package/js/{chunk-IJX4CYZO.js → chunk-TUMGL2OC.js} +228 -264
- package/js/{chunk-72JNVHPK.js → chunk-WDIVWSDG.js} +4 -3
- package/js/{chunk-CMYUWAX7.js → chunk-WGQP62EG.js} +126 -31
- package/js/{chunk-IPI4MFSN.js → chunk-XBG7HHXC.js} +2 -2
- package/js/{chunk-Z5M2LQOZ.js → chunk-ZEJ3IKEC.js} +67 -55
- package/js/chunk-ZR7QAG67.js +171 -0
- package/js/client.js +142 -94
- package/js/contracts.js +125 -26
- package/js/effect.js +19 -19
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +50 -40
- package/js/host.js +83 -58
- package/js/index.js +131 -46
- package/js/mcp/effect.js +23 -21
- package/js/mcp/stdio.js +44 -34
- package/js/mcp.js +76 -53
- package/js/openapi.js +4063 -1359
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +208 -81
- 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 +3 -4
- package/runtime.json +1 -1
- package/types/app-cache/src/contracts/cache.d.ts +2 -0
- package/types/app-cache/src/index.d.ts +10 -1
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -3
- package/types/apps/src/contracts/cache.d.ts +20 -0
- package/types/apps/src/contracts/context.d.ts +19 -11
- package/types/apps/src/contracts/elicitation.d.ts +6 -6
- package/types/apps/src/contracts/events.d.ts +93 -0
- package/types/apps/src/contracts/failure.d.ts +30 -1
- package/types/apps/src/contracts/graphql.d.ts +2 -1
- package/types/apps/src/contracts/host.d.ts +641 -16
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +80 -10
- package/types/apps/src/contracts/network.d.ts +120 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +82 -3
- package/types/apps/src/contracts/openapi.d.ts +41 -9
- package/types/apps/src/contracts/operations.d.ts +8 -4
- package/types/apps/src/contracts/placement.d.ts +102 -0
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +733 -81
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/2.d.ts +69 -26
- package/types/apps/src/contracts/protocols/3.d.ts +133 -33
- package/types/apps/src/contracts/protocols/4.d.ts +122 -45
- package/types/apps/src/contracts/protocols/5.d.ts +157 -47
- package/types/apps/src/contracts/protocols/6.d.ts +1629 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1785 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1182 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1104 -0
- package/types/apps/src/contracts/protocols/current.d.ts +3842 -0
- package/types/apps/src/contracts/protocols/oauth-6.d.ts +74 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +134 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +90 -6
- package/types/apps/src/contracts/skills.d.ts +50 -13
- package/types/apps/src/contracts/sql.d.ts +63 -0
- package/types/apps/src/contracts/ui.d.ts +19 -1
- package/types/apps/src/contracts/workflows.d.ts +6 -0
- package/types/apps/src/facet.d.ts +4 -5
- package/types/apps/src/host.d.ts +5 -0
- package/types/apps/src/implementation/account-router.d.ts +4 -3
- package/types/apps/src/implementation/authoring.d.ts +25 -5
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/cache.d.ts +4 -0
- package/types/apps/src/implementation/catalog-cache.d.ts +35 -4
- package/types/apps/src/implementation/elicitation.d.ts +18 -15
- package/types/apps/src/implementation/events.d.ts +59 -0
- package/types/apps/src/implementation/failure-detail.d.ts +25 -3
- package/types/apps/src/implementation/graphql-catalog.d.ts +3 -3
- 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/invocation-timing.d.ts +16 -0
- 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 +6 -4
- package/types/apps/src/implementation/mcp-client.d.ts +17 -9
- 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 +20 -9
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +26 -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 +18 -0
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +17 -2
- package/types/apps/src/implementation/optimistic.d.ts +1 -1
- package/types/apps/src/implementation/placement.d.ts +60 -0
- package/types/apps/src/implementation/protocol-operations.d.ts +3 -0
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +18 -3
- package/types/apps/src/implementation/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +11 -13
- package/types/apps/src/implementation/router.d.ts +16 -5
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schema.d.ts +90 -10
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +71 -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/workflows.d.ts +1 -1
- package/types/apps/src/index.d.ts +55 -13
- package/types/apps/src/mcp.d.ts +20 -1
- package/types/apps/src/openapi.d.ts +1 -1
- 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 +7 -4
- package/types/telemetry/src/browser.d.ts +8 -3
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/index.d.ts +2 -1
- package/types/telemetry/src/layer.d.ts +2 -2
- package/types/telemetry/src/measurements.d.ts +1 -1
- package/types/telemetry/src/ownership.d.ts +56 -0
- package/types/telemetry/src/recorded-failure.d.ts +29 -0
- package/types/telemetry/src/relay.d.ts +16 -6
- package/types/telemetry/src/span-attributes.d.ts +17 -1
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +55 -0
- package/types/utils/src/connection-failure.d.ts +33 -0
- package/types/utils/src/recorded-message.d.ts +18 -0
- package/types/utils/src/user-facing-error.d.ts +83 -0
- package/js/chunk-MKWZPDR6.js +0 -63
- package/js/chunk-N7YDVXYJ.js +0 -186
- package/js/chunk-OCYUEU47.js +0 -224
- package/js/chunk-PJJ24GU7.js +0 -877
- package/js/chunk-PZB6T6KU.js +0 -19
- package/js/chunk-R3EV5FTO.js +0 -97
- package/js/chunk-YXQHV65J.js +0 -242
- package/js/chunk-ZQINWV4W.js +0 -630
- 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 -18
- 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/storage.d.ts +0 -68
- package/types/apps/src/implementation/storage.d.ts +0 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JsonObject,
|
|
3
3
|
ValidationError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-H2CJWXA3.js";
|
|
5
5
|
import {
|
|
6
6
|
Cause_exports,
|
|
7
7
|
Effect_exports,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
SchemaIssue_exports,
|
|
11
11
|
SchemaParser_exports,
|
|
12
12
|
Schema_exports
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-IFJU5SYQ.js";
|
|
14
14
|
|
|
15
15
|
// ../../node_modules/.bun/@cfworker+json-schema@4.1.1/node_modules/@cfworker/json-schema/dist/esm/deep-compare-strict.js
|
|
16
16
|
function deepCompareStrict(a, b) {
|
|
@@ -107,9 +107,9 @@ var ignoredKeyword = {
|
|
|
107
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");
|
|
108
108
|
function dereference(schema, lookup = /* @__PURE__ */ Object.create(null), baseURI = initialBaseURI, basePointer = "") {
|
|
109
109
|
if (schema && typeof schema === "object" && !Array.isArray(schema)) {
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
const url = new URL(
|
|
110
|
+
const id = schema.$id || schema.id;
|
|
111
|
+
if (id) {
|
|
112
|
+
const url = new URL(id, baseURI.href);
|
|
113
113
|
if (url.hash.length > 1) {
|
|
114
114
|
lookup[url.href] = schema;
|
|
115
115
|
} else {
|
|
@@ -345,7 +345,7 @@ function validate(instance, schema, draft = "2019-09", lookup = dereference(sche
|
|
|
345
345
|
if ($recursiveAnchor === true && recursiveAnchor === null) {
|
|
346
346
|
recursiveAnchor = schema;
|
|
347
347
|
}
|
|
348
|
-
if ($recursiveRef
|
|
348
|
+
if ($recursiveRef !== void 0) {
|
|
349
349
|
const refSchema = recursiveAnchor === null ? lookup[__absolute_recursive_ref__] : recursiveAnchor;
|
|
350
350
|
const keywordLocation = `${schemaLocation}/$recursiveRef`;
|
|
351
351
|
const result = validate(instance, recursiveAnchor === null ? schema : recursiveAnchor, draft, lookup, shortCircuit, refSchema, instanceLocation, keywordLocation, evaluated);
|
|
@@ -1069,40 +1069,31 @@ function schemaPattern(pattern) {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
1071
|
// src/implementation/schema.ts
|
|
1072
|
-
var StorageField = /* @__PURE__ */ Symbol("apps.StorageField");
|
|
1073
1072
|
var Decoder = /* @__PURE__ */ Symbol("apps.Schema");
|
|
1074
1073
|
var decoderOf = (schema) => schema[Decoder];
|
|
1075
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
|
+
};
|
|
1076
1082
|
var parse = (decoder, input) => Effect_exports.suspend(() => Schema_exports.decodeUnknownEffect(decoder)(input)).pipe(
|
|
1077
1083
|
Effect_exports.mapError(() => new ValidationError())
|
|
1078
1084
|
);
|
|
1079
|
-
function wrap(decoder, optionalValue
|
|
1085
|
+
function wrap(decoder, optionalValue) {
|
|
1080
1086
|
return {
|
|
1081
1087
|
[Decoder]: decoder,
|
|
1082
|
-
...field === void 0 ? {} : { [StorageField]: field },
|
|
1083
1088
|
optionalValue,
|
|
1084
1089
|
parse: (input) => Effect_exports.runSync(parse(decoder, input)),
|
|
1085
|
-
optional: () => wrap(
|
|
1086
|
-
Schema_exports.optional(decoder),
|
|
1087
|
-
true,
|
|
1088
|
-
field === void 0 ? void 0 : { ...field, optional: true }
|
|
1089
|
-
),
|
|
1090
|
+
optional: () => wrap(Schema_exports.optional(decoder), true),
|
|
1090
1091
|
default: (value) => {
|
|
1091
1092
|
const parsed = Effect_exports.runSync(parse(decoder, value));
|
|
1092
1093
|
return {
|
|
1093
1094
|
...wrap(
|
|
1094
1095
|
decoder.annotate({ default: parsed }).pipe(Schema_exports.withDecodingDefault(Effect_exports.succeed(parsed))),
|
|
1095
|
-
false
|
|
1096
|
-
field === void 0 || parsed === void 0 ? void 0 : {
|
|
1097
|
-
...field,
|
|
1098
|
-
default: Schema_exports.decodeUnknownSync(
|
|
1099
|
-
Schema_exports.Union([
|
|
1100
|
-
Schema_exports.String,
|
|
1101
|
-
Schema_exports.Finite,
|
|
1102
|
-
Schema_exports.Boolean
|
|
1103
|
-
])
|
|
1104
|
-
)(parsed)
|
|
1105
|
-
}
|
|
1096
|
+
false
|
|
1106
1097
|
),
|
|
1107
1098
|
hasDefault: true,
|
|
1108
1099
|
inputOptional: optionalValue
|
|
@@ -1113,14 +1104,19 @@ function wrap(decoder, optionalValue, field) {
|
|
|
1113
1104
|
function string(options = {}) {
|
|
1114
1105
|
return wrap(
|
|
1115
1106
|
options.minLength === void 0 ? Schema_exports.String : Schema_exports.String.check(Schema_exports.isMinLength(options.minLength)),
|
|
1116
|
-
false
|
|
1117
|
-
{ kind: "string" }
|
|
1107
|
+
false
|
|
1118
1108
|
);
|
|
1119
1109
|
}
|
|
1120
|
-
var number = () => wrap(Schema_exports.Finite, false
|
|
1121
|
-
var boolean = () => wrap(Schema_exports.Boolean, false
|
|
1110
|
+
var number = () => wrap(Schema_exports.Finite, false);
|
|
1111
|
+
var boolean = () => wrap(Schema_exports.Boolean, false);
|
|
1122
1112
|
var json = () => wrap(Schema_exports.Json, false);
|
|
1123
|
-
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
|
+
);
|
|
1124
1120
|
function literal(value) {
|
|
1125
1121
|
if (typeof value === "number") Effect_exports.runSync(parse(Schema_exports.Finite, value));
|
|
1126
1122
|
return wrap(
|
|
@@ -1128,10 +1124,13 @@ function literal(value) {
|
|
|
1128
1124
|
false
|
|
1129
1125
|
);
|
|
1130
1126
|
}
|
|
1131
|
-
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);
|
|
1132
1128
|
function object(fields) {
|
|
1133
1129
|
const entries = Object.entries(fields).map(
|
|
1134
|
-
([key, field]) => [
|
|
1130
|
+
([key, field]) => [
|
|
1131
|
+
key,
|
|
1132
|
+
decoderOf(schemaArgument(field, `The object() field ${JSON.stringify(key)}`))
|
|
1133
|
+
]
|
|
1135
1134
|
);
|
|
1136
1135
|
const decoder = entries.length === 0 ? withJsonSchemaDocument(
|
|
1137
1136
|
// Native Struct({}) accepts every non-null value and retains undeclared fields.
|
|
@@ -1145,6 +1144,25 @@ function object(fields) {
|
|
|
1145
1144
|
) : Schema_exports.Struct(Object.fromEntries(entries));
|
|
1146
1145
|
return { ...wrap(decoder, false), fields: Object.freeze({ ...fields }) };
|
|
1147
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
|
+
);
|
|
1148
1166
|
var ImportedJsonSchema = /* @__PURE__ */ Symbol("apps.JsonSchemaDocument");
|
|
1149
1167
|
var importedJsonSchema = (decoder) => ImportedJsonSchema in decoder ? decoder[ImportedJsonSchema] : void 0;
|
|
1150
1168
|
var withJsonSchemaDocument = (decoder, document) => Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
@@ -1274,18 +1292,425 @@ var containerKeywords = /* @__PURE__ */ new Set([
|
|
|
1274
1292
|
"else",
|
|
1275
1293
|
"dependentSchemas"
|
|
1276
1294
|
]);
|
|
1277
|
-
var
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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)
|
|
1286
1605
|
};
|
|
1287
|
-
return [issue];
|
|
1288
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);
|
|
1289
1714
|
return problems.length === 0 ? false : problems;
|
|
1290
1715
|
};
|
|
1291
1716
|
var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
@@ -1312,28 +1737,42 @@ var compileJsonSchemaDecoder = (document) => Effect_exports.gen(function* () {
|
|
|
1312
1737
|
throw new ValidationError();
|
|
1313
1738
|
}
|
|
1314
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
|
+
});
|
|
1315
1753
|
return {
|
|
1316
|
-
validate: (input) => validate(input, normalized, draft, lookup)
|
|
1754
|
+
validate: (input) => validate(input, normalized, draft, lookup),
|
|
1755
|
+
inspection
|
|
1317
1756
|
};
|
|
1318
1757
|
},
|
|
1319
1758
|
catch: () => new ValidationError()
|
|
1320
1759
|
});
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
{ expected: "a value matching a supported imported JSON Schema" }
|
|
1332
|
-
)
|
|
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" }
|
|
1333
1770
|
);
|
|
1771
|
+
importedKeys.set(check, documentKeys(document));
|
|
1772
|
+
const decoder = Schema_exports.Json.check(check);
|
|
1334
1773
|
return Object.assign(decoder, { [ImportedJsonSchema]: document });
|
|
1335
1774
|
});
|
|
1336
|
-
var
|
|
1775
|
+
var lazyCompiledDecoder = (document) => {
|
|
1337
1776
|
const read = once(document);
|
|
1338
1777
|
let compiled;
|
|
1339
1778
|
const compile = Effect_exports.suspend(
|
|
@@ -1353,9 +1792,11 @@ var lazyDecoder = (document) => {
|
|
|
1353
1792
|
Effect_exports.flatMap((schema) => SchemaParser_exports.decodeUnknownEffect(schema)(input, options))
|
|
1354
1793
|
)
|
|
1355
1794
|
);
|
|
1356
|
-
return withLazyJsonSchemaDocument(decoder, read);
|
|
1795
|
+
return { decoder: withLazyJsonSchemaDocument(decoder, read), compile };
|
|
1357
1796
|
};
|
|
1797
|
+
var lazyDecoder = (document) => lazyCompiledDecoder(document).decoder;
|
|
1358
1798
|
var lazyJsonSchemaDecoder = (document) => Effect_exports.sync(() => lazyDecoder(document));
|
|
1799
|
+
var preparedJsonSchemaDecoder = (document) => lazyCompiledDecoder(() => document);
|
|
1359
1800
|
var isJsonValue = Schema_exports.is(Schema_exports.Json);
|
|
1360
1801
|
var jsonDocument = (input) => {
|
|
1361
1802
|
if (typeof input !== "object" || input === null || Array.isArray(input)) return void 0;
|
|
@@ -1385,9 +1826,6 @@ var jsonSchema = (input) => {
|
|
|
1385
1826
|
false
|
|
1386
1827
|
);
|
|
1387
1828
|
};
|
|
1388
|
-
var storageFieldOf = (schema) => schema[StorageField];
|
|
1389
|
-
var id = (table) => wrap(Schema_exports.NonEmptyString, false, { kind: "id", references: table });
|
|
1390
|
-
var userId = () => wrap(Schema_exports.NonEmptyString, false, { kind: "userId" });
|
|
1391
1829
|
var jsonSchemaDocument = (decoder) => {
|
|
1392
1830
|
const imported = importedJsonSchema(decoder);
|
|
1393
1831
|
if (imported !== void 0) return Schema_exports.decodeUnknownEffect(JsonObject)(imported);
|
|
@@ -1402,6 +1840,7 @@ var jsonSchemaDocument = (decoder) => {
|
|
|
1402
1840
|
export {
|
|
1403
1841
|
decoderOf,
|
|
1404
1842
|
isSchema,
|
|
1843
|
+
schemaArgument,
|
|
1405
1844
|
parse,
|
|
1406
1845
|
wrap,
|
|
1407
1846
|
string,
|
|
@@ -1412,16 +1851,25 @@ export {
|
|
|
1412
1851
|
literal,
|
|
1413
1852
|
array,
|
|
1414
1853
|
object,
|
|
1854
|
+
plain,
|
|
1855
|
+
raw,
|
|
1856
|
+
fieldExposure,
|
|
1415
1857
|
importedJsonSchema,
|
|
1416
1858
|
once,
|
|
1417
1859
|
withLazyJsonSchemaDocument,
|
|
1418
1860
|
nestJsonSchema,
|
|
1861
|
+
echoableKey,
|
|
1862
|
+
objectShape,
|
|
1863
|
+
allowedValues,
|
|
1864
|
+
maxAlternativeKeys,
|
|
1865
|
+
unionShape,
|
|
1866
|
+
missingKey,
|
|
1867
|
+
missingKeyText,
|
|
1868
|
+
importedSchemaKeys,
|
|
1419
1869
|
compileJsonSchemaDecoder,
|
|
1420
1870
|
lazyJsonSchemaDecoder,
|
|
1871
|
+
preparedJsonSchemaDecoder,
|
|
1421
1872
|
jsonSchemaDecoder,
|
|
1422
1873
|
jsonSchema,
|
|
1423
|
-
storageFieldOf,
|
|
1424
|
-
id,
|
|
1425
|
-
userId,
|
|
1426
1874
|
jsonSchemaDocument
|
|
1427
1875
|
};
|