fumadocs-openapi 10.8.4 → 10.8.6
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/css/generated/shared.css +22 -1
- package/dist/generate-file.d.ts +1 -1
- package/dist/generate-file.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/general/create-limiter.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/is-object.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/queue/queue.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/string/generate-hash.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/bundle.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +1 -1
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.14/node_modules/@scalar/json-magic/dist/helpers/normalize.js +33 -0
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +2 -2
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +1 -1
- package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +1 -1
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/2020.js +110 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/code.js +138 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/index.js +674 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/codegen/scope.js +141 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/errors.js +102 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/index.js +223 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/names.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/ref_error.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/resolve.js +133 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/rules.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/util.js +146 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/applicability.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/boolSchema.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/dataType.js +172 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/defaults.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js +433 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js +113 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/core.js +583 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/data.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/index.js +42 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/applicator.js +50 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/content.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/core.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/format-annotation.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/meta-data.js +36 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/unevaluated.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/meta/validation.js +85 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/refs/json-schema-2020-12/schema.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/equal.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/ucs2length.js +25 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/uri.js +12 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/runtime/validation_error.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +57 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +96 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/allOf.js +29 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/contains.js +89 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +87 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/dependentSchemas.js +16 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/if.js +62 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/index.js +60 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/items2020.js +34 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/not.js +31 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +51 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +61 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/properties.js +52 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +41 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/code.js +130 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/id.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/core/ref.js +112 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/index.js +101 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/discriminator/types.js +14 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/draft2020.js +35 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicAnchor.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/dynamicRef.js +45 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/index.js +22 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveAnchor.js +20 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/dynamic/recursiveRef.js +15 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/format/index.js +10 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/metadata.js +23 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/next.js +19 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/index.js +13 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedItems.js +46 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/unevaluated/unevaluatedProperties.js +59 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/const.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/dependentRequired.js +17 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/enum.js +49 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/index.js +48 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitContains.js +18 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitItems.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitLength.js +33 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +47 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +28 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +27 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/pattern.js +38 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/required.js +72 -0
- package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +70 -0
- package/dist/node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js +33 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/index.js +236 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/schemes.js +187 -0
- package/dist/node_modules/.pnpm/fast-uri@3.1.0/node_modules/fast-uri/lib/utils.js +282 -0
- package/dist/node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js +78 -0
- package/dist/playground/client.js +1 -1
- package/dist/playground/schema.d.ts +0 -2
- package/dist/playground/schema.js +3 -2
- package/dist/server/index.d.ts +108 -3
- package/dist/server/index.js +181 -2
- package/dist/server/proxy.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/ui/base.d.ts +1 -1
- package/dist/ui/components/method-label.js +1 -4
- package/dist/ui/index.d.ts +1 -1
- package/dist/utils/document/process.js +4 -4
- package/dist/utils/pages/builder.d.ts +4 -3
- package/dist/utils/pages/builder.js +20 -1
- package/dist/utils/pages/to-text.d.ts +1 -1
- package/dist/utils/pages/to-text.js +23 -42
- package/package.json +12 -8
- package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.12/node_modules/@scalar/json-magic/dist/helpers/normalize.js +0 -26
- package/dist/server/create.d.ts +0 -40
- package/dist/server/create.js +0 -42
- package/dist/server/source-api.d.ts +0 -55
- package/dist/server/source-api.js +0 -149
- /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +0 -0
- /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +0 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../../../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { require_codegen } from "../codegen/index.js";
|
|
3
|
+
import { require_util } from "../util.js";
|
|
4
|
+
import { require_names } from "../names.js";
|
|
5
|
+
import { require_errors } from "../errors.js";
|
|
6
|
+
import { require_boolSchema } from "./boolSchema.js";
|
|
7
|
+
import { require_applicability } from "./applicability.js";
|
|
8
|
+
import { require_dataType } from "./dataType.js";
|
|
9
|
+
import { require_defaults } from "./defaults.js";
|
|
10
|
+
import { require_keyword } from "./keyword.js";
|
|
11
|
+
import { require_subschema } from "./subschema.js";
|
|
12
|
+
import { require_resolve } from "../resolve.js";
|
|
13
|
+
//#region ../../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/index.js
|
|
14
|
+
var require_validate = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.getData = exports.KeywordCxt = exports.validateFunctionCode = void 0;
|
|
17
|
+
const boolSchema_1 = require_boolSchema();
|
|
18
|
+
const dataType_1 = require_dataType();
|
|
19
|
+
const applicability_1 = require_applicability();
|
|
20
|
+
const dataType_2 = require_dataType();
|
|
21
|
+
const defaults_1 = require_defaults();
|
|
22
|
+
const keyword_1 = require_keyword();
|
|
23
|
+
const subschema_1 = require_subschema();
|
|
24
|
+
const codegen_1 = require_codegen();
|
|
25
|
+
const names_1 = require_names();
|
|
26
|
+
const resolve_1 = require_resolve();
|
|
27
|
+
const util_1 = require_util();
|
|
28
|
+
const errors_1 = require_errors();
|
|
29
|
+
function validateFunctionCode(it) {
|
|
30
|
+
if (isSchemaObj(it)) {
|
|
31
|
+
checkKeywords(it);
|
|
32
|
+
if (schemaCxtHasRules(it)) {
|
|
33
|
+
topSchemaObjCode(it);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
38
|
+
}
|
|
39
|
+
exports.validateFunctionCode = validateFunctionCode;
|
|
40
|
+
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
41
|
+
if (opts.code.es5) gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
|
|
42
|
+
gen.code((0, codegen_1._)`"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
43
|
+
destructureValCxtES5(gen, opts);
|
|
44
|
+
gen.code(body);
|
|
45
|
+
});
|
|
46
|
+
else gen.func(validateName, (0, codegen_1._)`${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
47
|
+
}
|
|
48
|
+
function destructureValCxt(opts) {
|
|
49
|
+
return (0, codegen_1._)`{${names_1.default.instancePath}="", ${names_1.default.parentData}, ${names_1.default.parentDataProperty}, ${names_1.default.rootData}=${names_1.default.data}${opts.dynamicRef ? (0, codegen_1._)`, ${names_1.default.dynamicAnchors}={}` : codegen_1.nil}}={}`;
|
|
50
|
+
}
|
|
51
|
+
function destructureValCxtES5(gen, opts) {
|
|
52
|
+
gen.if(names_1.default.valCxt, () => {
|
|
53
|
+
gen.var(names_1.default.instancePath, (0, codegen_1._)`${names_1.default.valCxt}.${names_1.default.instancePath}`);
|
|
54
|
+
gen.var(names_1.default.parentData, (0, codegen_1._)`${names_1.default.valCxt}.${names_1.default.parentData}`);
|
|
55
|
+
gen.var(names_1.default.parentDataProperty, (0, codegen_1._)`${names_1.default.valCxt}.${names_1.default.parentDataProperty}`);
|
|
56
|
+
gen.var(names_1.default.rootData, (0, codegen_1._)`${names_1.default.valCxt}.${names_1.default.rootData}`);
|
|
57
|
+
if (opts.dynamicRef) gen.var(names_1.default.dynamicAnchors, (0, codegen_1._)`${names_1.default.valCxt}.${names_1.default.dynamicAnchors}`);
|
|
58
|
+
}, () => {
|
|
59
|
+
gen.var(names_1.default.instancePath, (0, codegen_1._)`""`);
|
|
60
|
+
gen.var(names_1.default.parentData, (0, codegen_1._)`undefined`);
|
|
61
|
+
gen.var(names_1.default.parentDataProperty, (0, codegen_1._)`undefined`);
|
|
62
|
+
gen.var(names_1.default.rootData, names_1.default.data);
|
|
63
|
+
if (opts.dynamicRef) gen.var(names_1.default.dynamicAnchors, (0, codegen_1._)`{}`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function topSchemaObjCode(it) {
|
|
67
|
+
const { schema, opts, gen } = it;
|
|
68
|
+
validateFunction(it, () => {
|
|
69
|
+
if (opts.$comment && schema.$comment) commentKeyword(it);
|
|
70
|
+
checkNoDefault(it);
|
|
71
|
+
gen.let(names_1.default.vErrors, null);
|
|
72
|
+
gen.let(names_1.default.errors, 0);
|
|
73
|
+
if (opts.unevaluated) resetEvaluated(it);
|
|
74
|
+
typeAndKeywords(it);
|
|
75
|
+
returnResults(it);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function resetEvaluated(it) {
|
|
79
|
+
const { gen, validateName } = it;
|
|
80
|
+
it.evaluated = gen.const("evaluated", (0, codegen_1._)`${validateName}.evaluated`);
|
|
81
|
+
gen.if((0, codegen_1._)`${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1._)`${it.evaluated}.props`, (0, codegen_1._)`undefined`));
|
|
82
|
+
gen.if((0, codegen_1._)`${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1._)`${it.evaluated}.items`, (0, codegen_1._)`undefined`));
|
|
83
|
+
}
|
|
84
|
+
function funcSourceUrl(schema, opts) {
|
|
85
|
+
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
86
|
+
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1._)`/*# sourceURL=${schId} */` : codegen_1.nil;
|
|
87
|
+
}
|
|
88
|
+
function subschemaCode(it, valid) {
|
|
89
|
+
if (isSchemaObj(it)) {
|
|
90
|
+
checkKeywords(it);
|
|
91
|
+
if (schemaCxtHasRules(it)) {
|
|
92
|
+
subSchemaObjCode(it, valid);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
97
|
+
}
|
|
98
|
+
function schemaCxtHasRules({ schema, self }) {
|
|
99
|
+
if (typeof schema == "boolean") return !schema;
|
|
100
|
+
for (const key in schema) if (self.RULES.all[key]) return true;
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
function isSchemaObj(it) {
|
|
104
|
+
return typeof it.schema != "boolean";
|
|
105
|
+
}
|
|
106
|
+
function subSchemaObjCode(it, valid) {
|
|
107
|
+
const { schema, gen, opts } = it;
|
|
108
|
+
if (opts.$comment && schema.$comment) commentKeyword(it);
|
|
109
|
+
updateContext(it);
|
|
110
|
+
checkAsyncSchema(it);
|
|
111
|
+
const errsCount = gen.const("_errs", names_1.default.errors);
|
|
112
|
+
typeAndKeywords(it, errsCount);
|
|
113
|
+
gen.var(valid, (0, codegen_1._)`${errsCount} === ${names_1.default.errors}`);
|
|
114
|
+
}
|
|
115
|
+
function checkKeywords(it) {
|
|
116
|
+
(0, util_1.checkUnknownRules)(it);
|
|
117
|
+
checkRefsAndKeywords(it);
|
|
118
|
+
}
|
|
119
|
+
function typeAndKeywords(it, errsCount) {
|
|
120
|
+
if (it.opts.jtd) return schemaKeywords(it, [], false, errsCount);
|
|
121
|
+
const types = (0, dataType_1.getSchemaTypes)(it.schema);
|
|
122
|
+
schemaKeywords(it, types, !(0, dataType_1.coerceAndCheckDataType)(it, types), errsCount);
|
|
123
|
+
}
|
|
124
|
+
function checkRefsAndKeywords(it) {
|
|
125
|
+
const { schema, errSchemaPath, opts, self } = it;
|
|
126
|
+
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1.schemaHasRulesButRef)(schema, self.RULES)) self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
127
|
+
}
|
|
128
|
+
function checkNoDefault(it) {
|
|
129
|
+
const { schema, opts } = it;
|
|
130
|
+
if (schema.default !== void 0 && opts.useDefaults && opts.strictSchema) (0, util_1.checkStrictMode)(it, "default is ignored in the schema root");
|
|
131
|
+
}
|
|
132
|
+
function updateContext(it) {
|
|
133
|
+
const schId = it.schema[it.opts.schemaId];
|
|
134
|
+
if (schId) it.baseId = (0, resolve_1.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
135
|
+
}
|
|
136
|
+
function checkAsyncSchema(it) {
|
|
137
|
+
if (it.schema.$async && !it.schemaEnv.$async) throw new Error("async schema in sync schema");
|
|
138
|
+
}
|
|
139
|
+
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
140
|
+
const msg = schema.$comment;
|
|
141
|
+
if (opts.$comment === true) gen.code((0, codegen_1._)`${names_1.default.self}.logger.log(${msg})`);
|
|
142
|
+
else if (typeof opts.$comment == "function") {
|
|
143
|
+
const schemaPath = (0, codegen_1.str)`${errSchemaPath}/$comment`;
|
|
144
|
+
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
145
|
+
gen.code((0, codegen_1._)`${names_1.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function returnResults(it) {
|
|
149
|
+
const { gen, schemaEnv, validateName, ValidationError, opts } = it;
|
|
150
|
+
if (schemaEnv.$async) gen.if((0, codegen_1._)`${names_1.default.errors} === 0`, () => gen.return(names_1.default.data), () => gen.throw((0, codegen_1._)`new ${ValidationError}(${names_1.default.vErrors})`));
|
|
151
|
+
else {
|
|
152
|
+
gen.assign((0, codegen_1._)`${validateName}.errors`, names_1.default.vErrors);
|
|
153
|
+
if (opts.unevaluated) assignEvaluated(it);
|
|
154
|
+
gen.return((0, codegen_1._)`${names_1.default.errors} === 0`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function assignEvaluated({ gen, evaluated, props, items }) {
|
|
158
|
+
if (props instanceof codegen_1.Name) gen.assign((0, codegen_1._)`${evaluated}.props`, props);
|
|
159
|
+
if (items instanceof codegen_1.Name) gen.assign((0, codegen_1._)`${evaluated}.items`, items);
|
|
160
|
+
}
|
|
161
|
+
function schemaKeywords(it, types, typeErrors, errsCount) {
|
|
162
|
+
const { gen, schema, data, allErrors, opts, self } = it;
|
|
163
|
+
const { RULES } = self;
|
|
164
|
+
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1.schemaHasRulesButRef)(schema, RULES))) {
|
|
165
|
+
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (!opts.jtd) checkStrictTypes(it, types);
|
|
169
|
+
gen.block(() => {
|
|
170
|
+
for (const group of RULES.rules) groupKeywords(group);
|
|
171
|
+
groupKeywords(RULES.post);
|
|
172
|
+
});
|
|
173
|
+
function groupKeywords(group) {
|
|
174
|
+
if (!(0, applicability_1.shouldUseGroup)(schema, group)) return;
|
|
175
|
+
if (group.type) {
|
|
176
|
+
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
177
|
+
iterateKeywords(it, group);
|
|
178
|
+
if (types.length === 1 && types[0] === group.type && typeErrors) {
|
|
179
|
+
gen.else();
|
|
180
|
+
(0, dataType_2.reportTypeError)(it);
|
|
181
|
+
}
|
|
182
|
+
gen.endIf();
|
|
183
|
+
} else iterateKeywords(it, group);
|
|
184
|
+
if (!allErrors) gen.if((0, codegen_1._)`${names_1.default.errors} === ${errsCount || 0}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function iterateKeywords(it, group) {
|
|
188
|
+
const { gen, schema, opts: { useDefaults } } = it;
|
|
189
|
+
if (useDefaults) (0, defaults_1.assignDefaults)(it, group.type);
|
|
190
|
+
gen.block(() => {
|
|
191
|
+
for (const rule of group.rules) if ((0, applicability_1.shouldUseRule)(schema, rule)) keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function checkStrictTypes(it, types) {
|
|
195
|
+
if (it.schemaEnv.meta || !it.opts.strictTypes) return;
|
|
196
|
+
checkContextTypes(it, types);
|
|
197
|
+
if (!it.opts.allowUnionTypes) checkMultipleTypes(it, types);
|
|
198
|
+
checkKeywordTypes(it, it.dataTypes);
|
|
199
|
+
}
|
|
200
|
+
function checkContextTypes(it, types) {
|
|
201
|
+
if (!types.length) return;
|
|
202
|
+
if (!it.dataTypes.length) {
|
|
203
|
+
it.dataTypes = types;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
types.forEach((t) => {
|
|
207
|
+
if (!includesType(it.dataTypes, t)) strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
208
|
+
});
|
|
209
|
+
narrowSchemaTypes(it, types);
|
|
210
|
+
}
|
|
211
|
+
function checkMultipleTypes(it, ts) {
|
|
212
|
+
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
213
|
+
}
|
|
214
|
+
function checkKeywordTypes(it, ts) {
|
|
215
|
+
const rules = it.self.RULES.all;
|
|
216
|
+
for (const keyword in rules) {
|
|
217
|
+
const rule = rules[keyword];
|
|
218
|
+
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
219
|
+
const { type } = rule.definition;
|
|
220
|
+
if (type.length && !type.some((t) => hasApplicableType(ts, t))) strictTypesError(it, `missing type "${type.join(",")}" for keyword "${keyword}"`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function hasApplicableType(schTs, kwdT) {
|
|
225
|
+
return schTs.includes(kwdT) || kwdT === "number" && schTs.includes("integer");
|
|
226
|
+
}
|
|
227
|
+
function includesType(ts, t) {
|
|
228
|
+
return ts.includes(t) || t === "integer" && ts.includes("number");
|
|
229
|
+
}
|
|
230
|
+
function narrowSchemaTypes(it, withTypes) {
|
|
231
|
+
const ts = [];
|
|
232
|
+
for (const t of it.dataTypes) if (includesType(withTypes, t)) ts.push(t);
|
|
233
|
+
else if (withTypes.includes("integer") && t === "number") ts.push("integer");
|
|
234
|
+
it.dataTypes = ts;
|
|
235
|
+
}
|
|
236
|
+
function strictTypesError(it, msg) {
|
|
237
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
238
|
+
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
239
|
+
(0, util_1.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
240
|
+
}
|
|
241
|
+
var KeywordCxt = class {
|
|
242
|
+
constructor(it, def, keyword) {
|
|
243
|
+
(0, keyword_1.validateKeywordUsage)(it, def, keyword);
|
|
244
|
+
this.gen = it.gen;
|
|
245
|
+
this.allErrors = it.allErrors;
|
|
246
|
+
this.keyword = keyword;
|
|
247
|
+
this.data = it.data;
|
|
248
|
+
this.schema = it.schema[keyword];
|
|
249
|
+
this.$data = def.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
250
|
+
this.schemaValue = (0, util_1.schemaRefOrVal)(it, this.schema, keyword, this.$data);
|
|
251
|
+
this.schemaType = def.schemaType;
|
|
252
|
+
this.parentSchema = it.schema;
|
|
253
|
+
this.params = {};
|
|
254
|
+
this.it = it;
|
|
255
|
+
this.def = def;
|
|
256
|
+
if (this.$data) this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
257
|
+
else {
|
|
258
|
+
this.schemaCode = this.schemaValue;
|
|
259
|
+
if (!(0, keyword_1.validSchemaType)(this.schema, def.schemaType, def.allowUndefined)) throw new Error(`${keyword} value must be ${JSON.stringify(def.schemaType)}`);
|
|
260
|
+
}
|
|
261
|
+
if ("code" in def ? def.trackErrors : def.errors !== false) this.errsCount = it.gen.const("_errs", names_1.default.errors);
|
|
262
|
+
}
|
|
263
|
+
result(condition, successAction, failAction) {
|
|
264
|
+
this.failResult((0, codegen_1.not)(condition), successAction, failAction);
|
|
265
|
+
}
|
|
266
|
+
failResult(condition, successAction, failAction) {
|
|
267
|
+
this.gen.if(condition);
|
|
268
|
+
if (failAction) failAction();
|
|
269
|
+
else this.error();
|
|
270
|
+
if (successAction) {
|
|
271
|
+
this.gen.else();
|
|
272
|
+
successAction();
|
|
273
|
+
if (this.allErrors) this.gen.endIf();
|
|
274
|
+
} else if (this.allErrors) this.gen.endIf();
|
|
275
|
+
else this.gen.else();
|
|
276
|
+
}
|
|
277
|
+
pass(condition, failAction) {
|
|
278
|
+
this.failResult((0, codegen_1.not)(condition), void 0, failAction);
|
|
279
|
+
}
|
|
280
|
+
fail(condition) {
|
|
281
|
+
if (condition === void 0) {
|
|
282
|
+
this.error();
|
|
283
|
+
if (!this.allErrors) this.gen.if(false);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.gen.if(condition);
|
|
287
|
+
this.error();
|
|
288
|
+
if (this.allErrors) this.gen.endIf();
|
|
289
|
+
else this.gen.else();
|
|
290
|
+
}
|
|
291
|
+
fail$data(condition) {
|
|
292
|
+
if (!this.$data) return this.fail(condition);
|
|
293
|
+
const { schemaCode } = this;
|
|
294
|
+
this.fail((0, codegen_1._)`${schemaCode} !== undefined && (${(0, codegen_1.or)(this.invalid$data(), condition)})`);
|
|
295
|
+
}
|
|
296
|
+
error(append, errorParams, errorPaths) {
|
|
297
|
+
if (errorParams) {
|
|
298
|
+
this.setParams(errorParams);
|
|
299
|
+
this._error(append, errorPaths);
|
|
300
|
+
this.setParams({});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this._error(append, errorPaths);
|
|
304
|
+
}
|
|
305
|
+
_error(append, errorPaths) {
|
|
306
|
+
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
307
|
+
}
|
|
308
|
+
$dataError() {
|
|
309
|
+
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
310
|
+
}
|
|
311
|
+
reset() {
|
|
312
|
+
if (this.errsCount === void 0) throw new Error("add \"trackErrors\" to keyword definition");
|
|
313
|
+
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
314
|
+
}
|
|
315
|
+
ok(cond) {
|
|
316
|
+
if (!this.allErrors) this.gen.if(cond);
|
|
317
|
+
}
|
|
318
|
+
setParams(obj, assign) {
|
|
319
|
+
if (assign) Object.assign(this.params, obj);
|
|
320
|
+
else this.params = obj;
|
|
321
|
+
}
|
|
322
|
+
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
323
|
+
this.gen.block(() => {
|
|
324
|
+
this.check$data(valid, $dataValid);
|
|
325
|
+
codeBlock();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
check$data(valid = codegen_1.nil, $dataValid = codegen_1.nil) {
|
|
329
|
+
if (!this.$data) return;
|
|
330
|
+
const { gen, schemaCode, schemaType, def } = this;
|
|
331
|
+
gen.if((0, codegen_1.or)((0, codegen_1._)`${schemaCode} === undefined`, $dataValid));
|
|
332
|
+
if (valid !== codegen_1.nil) gen.assign(valid, true);
|
|
333
|
+
if (schemaType.length || def.validateSchema) {
|
|
334
|
+
gen.elseIf(this.invalid$data());
|
|
335
|
+
this.$dataError();
|
|
336
|
+
if (valid !== codegen_1.nil) gen.assign(valid, false);
|
|
337
|
+
}
|
|
338
|
+
gen.else();
|
|
339
|
+
}
|
|
340
|
+
invalid$data() {
|
|
341
|
+
const { gen, schemaCode, schemaType, def, it } = this;
|
|
342
|
+
return (0, codegen_1.or)(wrong$DataType(), invalid$DataSchema());
|
|
343
|
+
function wrong$DataType() {
|
|
344
|
+
if (schemaType.length) {
|
|
345
|
+
/* istanbul ignore if */
|
|
346
|
+
if (!(schemaCode instanceof codegen_1.Name)) throw new Error("ajv implementation error");
|
|
347
|
+
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
348
|
+
return (0, codegen_1._)`${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
349
|
+
}
|
|
350
|
+
return codegen_1.nil;
|
|
351
|
+
}
|
|
352
|
+
function invalid$DataSchema() {
|
|
353
|
+
if (def.validateSchema) {
|
|
354
|
+
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def.validateSchema });
|
|
355
|
+
return (0, codegen_1._)`!${validateSchemaRef}(${schemaCode})`;
|
|
356
|
+
}
|
|
357
|
+
return codegen_1.nil;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
subschema(appl, valid) {
|
|
361
|
+
const subschema = (0, subschema_1.getSubschema)(this.it, appl);
|
|
362
|
+
(0, subschema_1.extendSubschemaData)(subschema, this.it, appl);
|
|
363
|
+
(0, subschema_1.extendSubschemaMode)(subschema, appl);
|
|
364
|
+
const nextContext = {
|
|
365
|
+
...this.it,
|
|
366
|
+
...subschema,
|
|
367
|
+
items: void 0,
|
|
368
|
+
props: void 0
|
|
369
|
+
};
|
|
370
|
+
subschemaCode(nextContext, valid);
|
|
371
|
+
return nextContext;
|
|
372
|
+
}
|
|
373
|
+
mergeEvaluated(schemaCxt, toName) {
|
|
374
|
+
const { it, gen } = this;
|
|
375
|
+
if (!it.opts.unevaluated) return;
|
|
376
|
+
if (it.props !== true && schemaCxt.props !== void 0) it.props = util_1.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
377
|
+
if (it.items !== true && schemaCxt.items !== void 0) it.items = util_1.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
378
|
+
}
|
|
379
|
+
mergeValidEvaluated(schemaCxt, valid) {
|
|
380
|
+
const { it, gen } = this;
|
|
381
|
+
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
382
|
+
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1.Name));
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
exports.KeywordCxt = KeywordCxt;
|
|
388
|
+
function keywordCode(it, keyword, def, ruleType) {
|
|
389
|
+
const cxt = new KeywordCxt(it, def, keyword);
|
|
390
|
+
if ("code" in def) def.code(cxt, ruleType);
|
|
391
|
+
else if (cxt.$data && def.validate) (0, keyword_1.funcKeywordCode)(cxt, def);
|
|
392
|
+
else if ("macro" in def) (0, keyword_1.macroKeywordCode)(cxt, def);
|
|
393
|
+
else if (def.compile || def.validate) (0, keyword_1.funcKeywordCode)(cxt, def);
|
|
394
|
+
}
|
|
395
|
+
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
396
|
+
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
397
|
+
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
398
|
+
let jsonPointer;
|
|
399
|
+
let data;
|
|
400
|
+
if ($data === "") return names_1.default.rootData;
|
|
401
|
+
if ($data[0] === "/") {
|
|
402
|
+
if (!JSON_POINTER.test($data)) throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
403
|
+
jsonPointer = $data;
|
|
404
|
+
data = names_1.default.rootData;
|
|
405
|
+
} else {
|
|
406
|
+
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
407
|
+
if (!matches) throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
408
|
+
const up = +matches[1];
|
|
409
|
+
jsonPointer = matches[2];
|
|
410
|
+
if (jsonPointer === "#") {
|
|
411
|
+
if (up >= dataLevel) throw new Error(errorMsg("property/index", up));
|
|
412
|
+
return dataPathArr[dataLevel - up];
|
|
413
|
+
}
|
|
414
|
+
if (up > dataLevel) throw new Error(errorMsg("data", up));
|
|
415
|
+
data = dataNames[dataLevel - up];
|
|
416
|
+
if (!jsonPointer) return data;
|
|
417
|
+
}
|
|
418
|
+
let expr = data;
|
|
419
|
+
const segments = jsonPointer.split("/");
|
|
420
|
+
for (const segment of segments) if (segment) {
|
|
421
|
+
data = (0, codegen_1._)`${data}${(0, codegen_1.getProperty)((0, util_1.unescapeJsonPointer)(segment))}`;
|
|
422
|
+
expr = (0, codegen_1._)`${expr} && ${data}`;
|
|
423
|
+
}
|
|
424
|
+
return expr;
|
|
425
|
+
function errorMsg(pointerType, up) {
|
|
426
|
+
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
exports.getData = getData;
|
|
430
|
+
}));
|
|
431
|
+
//#endregion
|
|
432
|
+
export default require_validate();
|
|
433
|
+
export { require_validate };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../../../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { require_codegen } from "../codegen/index.js";
|
|
3
|
+
import { require_names } from "../names.js";
|
|
4
|
+
import { require_errors } from "../errors.js";
|
|
5
|
+
import { require_code } from "../../vocabularies/code.js";
|
|
6
|
+
//#region ../../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/keyword.js
|
|
7
|
+
var require_keyword = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateKeywordUsage = exports.validSchemaType = exports.funcKeywordCode = exports.macroKeywordCode = void 0;
|
|
10
|
+
const codegen_1 = require_codegen();
|
|
11
|
+
const names_1 = require_names();
|
|
12
|
+
const code_1 = require_code();
|
|
13
|
+
const errors_1 = require_errors();
|
|
14
|
+
function macroKeywordCode(cxt, def) {
|
|
15
|
+
const { gen, keyword, schema, parentSchema, it } = cxt;
|
|
16
|
+
const macroSchema = def.macro.call(it.self, schema, parentSchema, it);
|
|
17
|
+
const schemaRef = useKeyword(gen, keyword, macroSchema);
|
|
18
|
+
if (it.opts.validateSchema !== false) it.self.validateSchema(macroSchema, true);
|
|
19
|
+
const valid = gen.name("valid");
|
|
20
|
+
cxt.subschema({
|
|
21
|
+
schema: macroSchema,
|
|
22
|
+
schemaPath: codegen_1.nil,
|
|
23
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword}`,
|
|
24
|
+
topSchemaRef: schemaRef,
|
|
25
|
+
compositeRule: true
|
|
26
|
+
}, valid);
|
|
27
|
+
cxt.pass(valid, () => cxt.error(true));
|
|
28
|
+
}
|
|
29
|
+
exports.macroKeywordCode = macroKeywordCode;
|
|
30
|
+
function funcKeywordCode(cxt, def) {
|
|
31
|
+
var _a;
|
|
32
|
+
const { gen, keyword, schema, parentSchema, $data, it } = cxt;
|
|
33
|
+
checkAsyncKeyword(it, def);
|
|
34
|
+
const validateRef = useKeyword(gen, keyword, !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate);
|
|
35
|
+
const valid = gen.let("valid");
|
|
36
|
+
cxt.block$data(valid, validateKeyword);
|
|
37
|
+
cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid);
|
|
38
|
+
function validateKeyword() {
|
|
39
|
+
if (def.errors === false) {
|
|
40
|
+
assignValid();
|
|
41
|
+
if (def.modifying) modifyData(cxt);
|
|
42
|
+
reportErrs(() => cxt.error());
|
|
43
|
+
} else {
|
|
44
|
+
const ruleErrs = def.async ? validateAsync() : validateSync();
|
|
45
|
+
if (def.modifying) modifyData(cxt);
|
|
46
|
+
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function validateAsync() {
|
|
50
|
+
const ruleErrs = gen.let("ruleErrs", null);
|
|
51
|
+
gen.try(() => assignValid((0, codegen_1._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._)`${e}.errors`), () => gen.throw(e)));
|
|
52
|
+
return ruleErrs;
|
|
53
|
+
}
|
|
54
|
+
function validateSync() {
|
|
55
|
+
const validateErrs = (0, codegen_1._)`${validateRef}.errors`;
|
|
56
|
+
gen.assign(validateErrs, null);
|
|
57
|
+
assignValid(codegen_1.nil);
|
|
58
|
+
return validateErrs;
|
|
59
|
+
}
|
|
60
|
+
function assignValid(_await = def.async ? (0, codegen_1._)`await ` : codegen_1.nil) {
|
|
61
|
+
const passCxt = it.opts.passContext ? names_1.default.this : names_1.default.self;
|
|
62
|
+
const passSchema = !("compile" in def && !$data || def.schema === false);
|
|
63
|
+
gen.assign(valid, (0, codegen_1._)`${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
|
|
64
|
+
}
|
|
65
|
+
function reportErrs(errors) {
|
|
66
|
+
var _a;
|
|
67
|
+
gen.if((0, codegen_1.not)((_a = def.valid) !== null && _a !== void 0 ? _a : valid), errors);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.funcKeywordCode = funcKeywordCode;
|
|
71
|
+
function modifyData(cxt) {
|
|
72
|
+
const { gen, data, it } = cxt;
|
|
73
|
+
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1._)`${it.parentData}[${it.parentDataProperty}]`));
|
|
74
|
+
}
|
|
75
|
+
function addErrs(cxt, errs) {
|
|
76
|
+
const { gen } = cxt;
|
|
77
|
+
gen.if((0, codegen_1._)`Array.isArray(${errs})`, () => {
|
|
78
|
+
gen.assign(names_1.default.vErrors, (0, codegen_1._)`${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`).assign(names_1.default.errors, (0, codegen_1._)`${names_1.default.vErrors}.length`);
|
|
79
|
+
(0, errors_1.extendErrors)(cxt);
|
|
80
|
+
}, () => cxt.error());
|
|
81
|
+
}
|
|
82
|
+
function checkAsyncKeyword({ schemaEnv }, def) {
|
|
83
|
+
if (def.async && !schemaEnv.$async) throw new Error("async keyword in sync schema");
|
|
84
|
+
}
|
|
85
|
+
function useKeyword(gen, keyword, result) {
|
|
86
|
+
if (result === void 0) throw new Error(`keyword "${keyword}" failed to compile`);
|
|
87
|
+
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : {
|
|
88
|
+
ref: result,
|
|
89
|
+
code: (0, codegen_1.stringify)(result)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
93
|
+
return !schemaType.length || schemaType.some((st) => st === "array" ? Array.isArray(schema) : st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema) : typeof schema == st || allowUndefined && typeof schema == "undefined");
|
|
94
|
+
}
|
|
95
|
+
exports.validSchemaType = validSchemaType;
|
|
96
|
+
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def, keyword) {
|
|
97
|
+
/* istanbul ignore if */
|
|
98
|
+
if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) throw new Error("ajv implementation error");
|
|
99
|
+
const deps = def.dependencies;
|
|
100
|
+
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`);
|
|
101
|
+
if (def.validateSchema) {
|
|
102
|
+
if (!def.validateSchema(schema[keyword])) {
|
|
103
|
+
const msg = `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` + self.errorsText(def.validateSchema.errors);
|
|
104
|
+
if (opts.validateSchema === "log") self.logger.error(msg);
|
|
105
|
+
else throw new Error(msg);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.validateKeywordUsage = validateKeywordUsage;
|
|
110
|
+
}));
|
|
111
|
+
//#endregion
|
|
112
|
+
export default require_keyword();
|
|
113
|
+
export { require_keyword };
|
package/dist/node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../../../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { require_codegen } from "../codegen/index.js";
|
|
3
|
+
import { require_util } from "../util.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/ajv@8.20.0/node_modules/ajv/dist/compile/validate/subschema.js
|
|
5
|
+
var require_subschema = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.extendSubschemaMode = exports.extendSubschemaData = exports.getSubschema = void 0;
|
|
8
|
+
const codegen_1 = require_codegen();
|
|
9
|
+
const util_1 = require_util();
|
|
10
|
+
function getSubschema(it, { keyword, schemaProp, schema, schemaPath, errSchemaPath, topSchemaRef }) {
|
|
11
|
+
if (keyword !== void 0 && schema !== void 0) throw new Error("both \"keyword\" and \"schema\" passed, only one allowed");
|
|
12
|
+
if (keyword !== void 0) {
|
|
13
|
+
const sch = it.schema[keyword];
|
|
14
|
+
return schemaProp === void 0 ? {
|
|
15
|
+
schema: sch,
|
|
16
|
+
schemaPath: (0, codegen_1._)`${it.schemaPath}${(0, codegen_1.getProperty)(keyword)}`,
|
|
17
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword}`
|
|
18
|
+
} : {
|
|
19
|
+
schema: sch[schemaProp],
|
|
20
|
+
schemaPath: (0, codegen_1._)`${it.schemaPath}${(0, codegen_1.getProperty)(keyword)}${(0, codegen_1.getProperty)(schemaProp)}`,
|
|
21
|
+
errSchemaPath: `${it.errSchemaPath}/${keyword}/${(0, util_1.escapeFragment)(schemaProp)}`
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (schema !== void 0) {
|
|
25
|
+
if (schemaPath === void 0 || errSchemaPath === void 0 || topSchemaRef === void 0) throw new Error("\"schemaPath\", \"errSchemaPath\" and \"topSchemaRef\" are required with \"schema\"");
|
|
26
|
+
return {
|
|
27
|
+
schema,
|
|
28
|
+
schemaPath,
|
|
29
|
+
topSchemaRef,
|
|
30
|
+
errSchemaPath
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
throw new Error("either \"keyword\" or \"schema\" must be passed");
|
|
34
|
+
}
|
|
35
|
+
exports.getSubschema = getSubschema;
|
|
36
|
+
function extendSubschemaData(subschema, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
|
|
37
|
+
if (data !== void 0 && dataProp !== void 0) throw new Error("both \"data\" and \"dataProp\" passed, only one allowed");
|
|
38
|
+
const { gen } = it;
|
|
39
|
+
if (dataProp !== void 0) {
|
|
40
|
+
const { errorPath, dataPathArr, opts } = it;
|
|
41
|
+
dataContextProps(gen.let("data", (0, codegen_1._)`${it.data}${(0, codegen_1.getProperty)(dataProp)}`, true));
|
|
42
|
+
subschema.errorPath = (0, codegen_1.str)`${errorPath}${(0, util_1.getErrorPath)(dataProp, dpType, opts.jsPropertySyntax)}`;
|
|
43
|
+
subschema.parentDataProperty = (0, codegen_1._)`${dataProp}`;
|
|
44
|
+
subschema.dataPathArr = [...dataPathArr, subschema.parentDataProperty];
|
|
45
|
+
}
|
|
46
|
+
if (data !== void 0) {
|
|
47
|
+
dataContextProps(data instanceof codegen_1.Name ? data : gen.let("data", data, true));
|
|
48
|
+
if (propertyName !== void 0) subschema.propertyName = propertyName;
|
|
49
|
+
}
|
|
50
|
+
if (dataTypes) subschema.dataTypes = dataTypes;
|
|
51
|
+
function dataContextProps(_nextData) {
|
|
52
|
+
subschema.data = _nextData;
|
|
53
|
+
subschema.dataLevel = it.dataLevel + 1;
|
|
54
|
+
subschema.dataTypes = [];
|
|
55
|
+
it.definedProperties = /* @__PURE__ */ new Set();
|
|
56
|
+
subschema.parentData = it.data;
|
|
57
|
+
subschema.dataNames = [...it.dataNames, _nextData];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.extendSubschemaData = extendSubschemaData;
|
|
61
|
+
function extendSubschemaMode(subschema, { jtdDiscriminator, jtdMetadata, compositeRule, createErrors, allErrors }) {
|
|
62
|
+
if (compositeRule !== void 0) subschema.compositeRule = compositeRule;
|
|
63
|
+
if (createErrors !== void 0) subschema.createErrors = createErrors;
|
|
64
|
+
if (allErrors !== void 0) subschema.allErrors = allErrors;
|
|
65
|
+
subschema.jtdDiscriminator = jtdDiscriminator;
|
|
66
|
+
subschema.jtdMetadata = jtdMetadata;
|
|
67
|
+
}
|
|
68
|
+
exports.extendSubschemaMode = extendSubschemaMode;
|
|
69
|
+
}));
|
|
70
|
+
//#endregion
|
|
71
|
+
export default require_subschema();
|
|
72
|
+
export { require_subschema };
|