@blueking/bkui-form 1.0.1-beta.3 → 1.0.1-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/common/FieldGroupWrap.d.ts +209 -0
- package/dist/adapter/field/ArrayField.d.ts +147 -0
- package/dist/adapter/field/BooleanField.d.ts +145 -0
- package/dist/adapter/field/CompositionField.d.ts +151 -0
- package/dist/adapter/field/FieldProps.d.ts +70 -0
- package/dist/adapter/field/NumberField.d.ts +145 -0
- package/dist/adapter/field/ObjectField.d.ts +147 -0
- package/dist/adapter/field/SchemaField.d.ts +145 -0
- package/dist/adapter/field/StringField.d.ts +4 -0
- package/dist/adapter/widget/ArrayWidget.d.ts +154 -0
- package/dist/adapter/widget/ButtonWidget.d.ts +16 -0
- package/dist/adapter/widget/CheckboxWidget.d.ts +34 -0
- package/dist/adapter/widget/CollapseGroupWidget.d.ts +196 -0
- package/dist/adapter/widget/ColorPickerWidget.d.ts +8 -0
- package/dist/adapter/widget/InputWidget.d.ts +30 -0
- package/dist/adapter/widget/KeyValueArrayWidget.d.ts +157 -0
- package/dist/adapter/widget/RadioWidget.d.ts +37 -0
- package/dist/adapter/widget/SelectWidget.d.ts +37 -0
- package/dist/adapter/widget/SwitchWidget.d.ts +10 -0
- package/dist/adapter/widget/TabGroupWidget.d.ts +187 -0
- package/dist/adapter/widget/TableWidget.d.ts +154 -0
- package/dist/adapter/widget/Widget.d.ts +182 -0
- package/dist/controller/form.d.ts +141 -0
- package/dist/controller/props.d.ts +62 -0
- package/dist/core/events.d.ts +10 -0
- package/dist/core/expression.d.ts +13 -0
- package/dist/core/form.d.ts +5 -0
- package/dist/core/lang.d.ts +1 -0
- package/dist/core/layout.d.ts +20 -0
- package/dist/core/lifecycle.d.ts +0 -0
- package/dist/core/path.d.ts +9 -0
- package/dist/core/proxy.d.ts +3 -0
- package/dist/core/reaction.d.ts +5 -0
- package/dist/core/register.d.ts +19 -0
- package/dist/core/schema.d.ts +26 -0
- package/dist/core/validator.d.ts +35 -0
- package/dist/core/widgetTree.d.ts +40 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.es.js +7443 -0
- package/dist/index.umd.js +12 -0
- package/dist/style.css +1 -0
- package/dist/util/fetch.d.ts +10 -0
- package/dist/util/index.d.ts +23 -0
- package/package.json +24 -12
- package/esm/adapter/common/FieldGroupWrap.tsx.js +0 -199
- package/esm/adapter/field/ArrayField.tsx.js +0 -55
- package/esm/adapter/field/BooleanField.tsx.js +0 -41
- package/esm/adapter/field/CompositionField.tsx.js +0 -113
- package/esm/adapter/field/FieldProps.ts.js +0 -85
- package/esm/adapter/field/NumberField.tsx.js +0 -19
- package/esm/adapter/field/ObjectField.tsx.js +0 -58
- package/esm/adapter/field/SchemaField.tsx.js +0 -28
- package/esm/adapter/field/StringField.tsx.js +0 -4
- package/esm/adapter/widget/ArrayWidget.ts.js +0 -196
- package/esm/adapter/widget/ButtonWidget.ts.js +0 -76
- package/esm/adapter/widget/CheckboxWidget.ts.js +0 -101
- package/esm/adapter/widget/CollapseGroupWidget.ts.js +0 -140
- package/esm/adapter/widget/ColorPickerWidget.ts.js +0 -71
- package/esm/adapter/widget/InputWidget.ts.js +0 -79
- package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +0 -156
- package/esm/adapter/widget/RadioWidget.ts.js +0 -98
- package/esm/adapter/widget/SelectWidget.ts.js +0 -98
- package/esm/adapter/widget/SwitchWidget.ts.js +0 -73
- package/esm/adapter/widget/TabGroupWidget.ts.js +0 -145
- package/esm/adapter/widget/TableWidget.ts.js +0 -205
- package/esm/adapter/widget/Widget.ts.js +0 -497
- package/esm/assets/fonts/iconcool.eot +0 -0
- package/esm/assets/fonts/iconcool.svg +0 -53
- package/esm/assets/fonts/iconcool.ttf +0 -0
- package/esm/assets/fonts/iconcool.woff +0 -0
- package/esm/assets/style.css +0 -43
- package/esm/controller/form.css +0 -164
- package/esm/controller/form.tsx.js +0 -159
- package/esm/controller/props.ts.js +0 -75
- package/esm/core/events.ts.js +0 -74
- package/esm/core/expression.ts.js +0 -67
- package/esm/core/lang.ts.js +0 -25
- package/esm/core/layout.ts.js +0 -149
- package/esm/core/path.ts.js +0 -60
- package/esm/core/proxy.ts.js +0 -10
- package/esm/core/reaction.ts.js +0 -116
- package/esm/core/register.ts.js +0 -74
- package/esm/core/schema.ts.js +0 -302
- package/esm/core/validator.ts.js +0 -248
- package/esm/core/widgetTree.ts.js +0 -163
- package/esm/index.ts.js +0 -6
- package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +0 -35
- package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +0 -233
- package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +0 -172
- package/esm/node_modules/ajv/dist/ajv.js +0 -50
- package/esm/node_modules/ajv/dist/compile/codegen/code.js +0 -156
- package/esm/node_modules/ajv/dist/compile/codegen/index.js +0 -697
- package/esm/node_modules/ajv/dist/compile/codegen/scope.js +0 -143
- package/esm/node_modules/ajv/dist/compile/errors.js +0 -123
- package/esm/node_modules/ajv/dist/compile/index.js +0 -242
- package/esm/node_modules/ajv/dist/compile/names.js +0 -28
- package/esm/node_modules/ajv/dist/compile/ref_error.js +0 -12
- package/esm/node_modules/ajv/dist/compile/resolve.js +0 -155
- package/esm/node_modules/ajv/dist/compile/rules.js +0 -26
- package/esm/node_modules/ajv/dist/compile/util.js +0 -178
- package/esm/node_modules/ajv/dist/compile/validate/applicability.js +0 -19
- package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +0 -50
- package/esm/node_modules/ajv/dist/compile/validate/dataType.js +0 -203
- package/esm/node_modules/ajv/dist/compile/validate/defaults.js +0 -35
- package/esm/node_modules/ajv/dist/compile/validate/index.js +0 -520
- package/esm/node_modules/ajv/dist/compile/validate/keyword.js +0 -124
- package/esm/node_modules/ajv/dist/compile/validate/subschema.js +0 -81
- package/esm/node_modules/ajv/dist/core.js +0 -618
- package/esm/node_modules/ajv/dist/refs/data.json +0 -13
- package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +0 -151
- package/esm/node_modules/ajv/dist/runtime/equal.js +0 -7
- package/esm/node_modules/ajv/dist/runtime/ucs2length.js +0 -24
- package/esm/node_modules/ajv/dist/runtime/uri.js +0 -6
- package/esm/node_modules/ajv/dist/runtime/validation_error.js +0 -11
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +0 -49
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +0 -106
- package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +0 -23
- package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +0 -12
- package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +0 -95
- package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +0 -85
- package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +0 -66
- package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +0 -44
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +0 -52
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +0 -30
- package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +0 -26
- package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +0 -60
- package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +0 -75
- package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +0 -12
- package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +0 -54
- package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +0 -38
- package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +0 -13
- package/esm/node_modules/ajv/dist/vocabularies/code.js +0 -131
- package/esm/node_modules/ajv/dist/vocabularies/core/id.js +0 -10
- package/esm/node_modules/ajv/dist/vocabularies/core/index.js +0 -16
- package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +0 -122
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +0 -104
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +0 -9
- package/esm/node_modules/ajv/dist/vocabularies/draft7.js +0 -17
- package/esm/node_modules/ajv/dist/vocabularies/format/format.js +0 -92
- package/esm/node_modules/ajv/dist/vocabularies/format/index.js +0 -6
- package/esm/node_modules/ajv/dist/vocabularies/metadata.js +0 -18
- package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +0 -25
- package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +0 -48
- package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +0 -33
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +0 -24
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +0 -27
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +0 -27
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +0 -24
- package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +0 -26
- package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +0 -24
- package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +0 -79
- package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +0 -64
- package/esm/node_modules/ajv-formats/dist/formats.js +0 -173
- package/esm/node_modules/ajv-formats/dist/index.js +0 -37
- package/esm/node_modules/ajv-formats/dist/limit.js +0 -69
- package/esm/node_modules/ajv-i18n/localize/zh/index.js +0 -154
- package/esm/node_modules/fast-deep-equal/index.js +0 -46
- package/esm/node_modules/fast-uri/index.js +0 -303
- package/esm/node_modules/fast-uri/lib/schemes.js +0 -188
- package/esm/node_modules/fast-uri/lib/scopedChars.js +0 -30
- package/esm/node_modules/fast-uri/lib/utils.js +0 -244
- package/esm/node_modules/json-schema-traverse/index.js +0 -89
- package/esm/node_modules/semver/classes/comparator.js +0 -143
- package/esm/node_modules/semver/classes/range.js +0 -557
- package/esm/node_modules/semver/classes/semver.js +0 -333
- package/esm/node_modules/semver/functions/clean.js +0 -8
- package/esm/node_modules/semver/functions/cmp.js +0 -54
- package/esm/node_modules/semver/functions/coerce.js +0 -62
- package/esm/node_modules/semver/functions/compare-build.js +0 -9
- package/esm/node_modules/semver/functions/compare-loose.js +0 -5
- package/esm/node_modules/semver/functions/compare.js +0 -7
- package/esm/node_modules/semver/functions/diff.js +0 -60
- package/esm/node_modules/semver/functions/eq.js +0 -5
- package/esm/node_modules/semver/functions/gt.js +0 -5
- package/esm/node_modules/semver/functions/gte.js +0 -5
- package/esm/node_modules/semver/functions/inc.js +0 -21
- package/esm/node_modules/semver/functions/lt.js +0 -5
- package/esm/node_modules/semver/functions/lte.js +0 -5
- package/esm/node_modules/semver/functions/major.js +0 -5
- package/esm/node_modules/semver/functions/minor.js +0 -5
- package/esm/node_modules/semver/functions/neq.js +0 -5
- package/esm/node_modules/semver/functions/parse.js +0 -18
- package/esm/node_modules/semver/functions/patch.js +0 -5
- package/esm/node_modules/semver/functions/prerelease.js +0 -8
- package/esm/node_modules/semver/functions/rcompare.js +0 -5
- package/esm/node_modules/semver/functions/rsort.js +0 -5
- package/esm/node_modules/semver/functions/satisfies.js +0 -12
- package/esm/node_modules/semver/functions/sort.js +0 -5
- package/esm/node_modules/semver/functions/valid.js +0 -8
- package/esm/node_modules/semver/index.js +0 -91
- package/esm/node_modules/semver/internal/constants.js +0 -37
- package/esm/node_modules/semver/internal/debug.js +0 -11
- package/esm/node_modules/semver/internal/identifiers.js +0 -29
- package/esm/node_modules/semver/internal/lrucache.js +0 -42
- package/esm/node_modules/semver/internal/parse-options.js +0 -17
- package/esm/node_modules/semver/internal/re.js +0 -223
- package/esm/node_modules/semver/ranges/gtr.js +0 -6
- package/esm/node_modules/semver/ranges/intersects.js +0 -9
- package/esm/node_modules/semver/ranges/ltr.js +0 -6
- package/esm/node_modules/semver/ranges/max-satisfying.js +0 -27
- package/esm/node_modules/semver/ranges/min-satisfying.js +0 -26
- package/esm/node_modules/semver/ranges/min-version.js +0 -63
- package/esm/node_modules/semver/ranges/outside.js +0 -82
- package/esm/node_modules/semver/ranges/simplify.js +0 -49
- package/esm/node_modules/semver/ranges/subset.js +0 -249
- package/esm/node_modules/semver/ranges/to-comparators.js +0 -10
- package/esm/node_modules/semver/ranges/valid.js +0 -13
- package/esm/util/fetch.ts.js +0 -190
- package/esm/util/index.ts.js +0 -276
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getData = exports.KeywordCxt = exports.validateFunctionCode = void 0;
|
|
4
|
-
const boolSchema_1 = require('./boolSchema.js');
|
|
5
|
-
const dataType_1 = require('./dataType.js');
|
|
6
|
-
const applicability_1 = require('./applicability.js');
|
|
7
|
-
const dataType_2 = require('./dataType.js');
|
|
8
|
-
const defaults_1 = require('./defaults.js');
|
|
9
|
-
const keyword_1 = require('./keyword.js');
|
|
10
|
-
const subschema_1 = require('./subschema.js');
|
|
11
|
-
const codegen_1 = require('../codegen/index.js');
|
|
12
|
-
const names_1 = require('../names.js');
|
|
13
|
-
const resolve_1 = require('../resolve.js');
|
|
14
|
-
const util_1 = require('../util.js');
|
|
15
|
-
const errors_1 = require('../errors.js');
|
|
16
|
-
// schema compilation - generates validation function, subschemaCode (below) is used for subschemas
|
|
17
|
-
function validateFunctionCode(it) {
|
|
18
|
-
if (isSchemaObj(it)) {
|
|
19
|
-
checkKeywords(it);
|
|
20
|
-
if (schemaCxtHasRules(it)) {
|
|
21
|
-
topSchemaObjCode(it);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
validateFunction(it, () => (0, boolSchema_1.topBoolOrEmptySchema)(it));
|
|
26
|
-
}
|
|
27
|
-
exports.validateFunctionCode = validateFunctionCode;
|
|
28
|
-
function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
|
|
29
|
-
if (opts.code.es5) {
|
|
30
|
-
gen.func(validateName, (0, codegen_1._) `${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
|
|
31
|
-
gen.code((0, codegen_1._) `"use strict"; ${funcSourceUrl(schema, opts)}`);
|
|
32
|
-
destructureValCxtES5(gen, opts);
|
|
33
|
-
gen.code(body);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
gen.func(validateName, (0, codegen_1._) `${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function destructureValCxt(opts) {
|
|
41
|
-
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}}={}`;
|
|
42
|
-
}
|
|
43
|
-
function destructureValCxtES5(gen, opts) {
|
|
44
|
-
gen.if(names_1.default.valCxt, () => {
|
|
45
|
-
gen.var(names_1.default.instancePath, (0, codegen_1._) `${names_1.default.valCxt}.${names_1.default.instancePath}`);
|
|
46
|
-
gen.var(names_1.default.parentData, (0, codegen_1._) `${names_1.default.valCxt}.${names_1.default.parentData}`);
|
|
47
|
-
gen.var(names_1.default.parentDataProperty, (0, codegen_1._) `${names_1.default.valCxt}.${names_1.default.parentDataProperty}`);
|
|
48
|
-
gen.var(names_1.default.rootData, (0, codegen_1._) `${names_1.default.valCxt}.${names_1.default.rootData}`);
|
|
49
|
-
if (opts.dynamicRef)
|
|
50
|
-
gen.var(names_1.default.dynamicAnchors, (0, codegen_1._) `${names_1.default.valCxt}.${names_1.default.dynamicAnchors}`);
|
|
51
|
-
}, () => {
|
|
52
|
-
gen.var(names_1.default.instancePath, (0, codegen_1._) `""`);
|
|
53
|
-
gen.var(names_1.default.parentData, (0, codegen_1._) `undefined`);
|
|
54
|
-
gen.var(names_1.default.parentDataProperty, (0, codegen_1._) `undefined`);
|
|
55
|
-
gen.var(names_1.default.rootData, names_1.default.data);
|
|
56
|
-
if (opts.dynamicRef)
|
|
57
|
-
gen.var(names_1.default.dynamicAnchors, (0, codegen_1._) `{}`);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function topSchemaObjCode(it) {
|
|
61
|
-
const { schema, opts, gen } = it;
|
|
62
|
-
validateFunction(it, () => {
|
|
63
|
-
if (opts.$comment && schema.$comment)
|
|
64
|
-
commentKeyword(it);
|
|
65
|
-
checkNoDefault(it);
|
|
66
|
-
gen.let(names_1.default.vErrors, null);
|
|
67
|
-
gen.let(names_1.default.errors, 0);
|
|
68
|
-
if (opts.unevaluated)
|
|
69
|
-
resetEvaluated(it);
|
|
70
|
-
typeAndKeywords(it);
|
|
71
|
-
returnResults(it);
|
|
72
|
-
});
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
function resetEvaluated(it) {
|
|
76
|
-
// TODO maybe some hook to execute it in the end to check whether props/items are Name, as in assignEvaluated
|
|
77
|
-
const { gen, validateName } = it;
|
|
78
|
-
it.evaluated = gen.const("evaluated", (0, codegen_1._) `${validateName}.evaluated`);
|
|
79
|
-
gen.if((0, codegen_1._) `${it.evaluated}.dynamicProps`, () => gen.assign((0, codegen_1._) `${it.evaluated}.props`, (0, codegen_1._) `undefined`));
|
|
80
|
-
gen.if((0, codegen_1._) `${it.evaluated}.dynamicItems`, () => gen.assign((0, codegen_1._) `${it.evaluated}.items`, (0, codegen_1._) `undefined`));
|
|
81
|
-
}
|
|
82
|
-
function funcSourceUrl(schema, opts) {
|
|
83
|
-
const schId = typeof schema == "object" && schema[opts.schemaId];
|
|
84
|
-
return schId && (opts.code.source || opts.code.process) ? (0, codegen_1._) `/*# sourceURL=${schId} */` : codegen_1.nil;
|
|
85
|
-
}
|
|
86
|
-
// schema compilation - this function is used recursively to generate code for sub-schemas
|
|
87
|
-
function subschemaCode(it, valid) {
|
|
88
|
-
if (isSchemaObj(it)) {
|
|
89
|
-
checkKeywords(it);
|
|
90
|
-
if (schemaCxtHasRules(it)) {
|
|
91
|
-
subSchemaObjCode(it, valid);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
(0, boolSchema_1.boolOrEmptySchema)(it, valid);
|
|
96
|
-
}
|
|
97
|
-
function schemaCxtHasRules({ schema, self }) {
|
|
98
|
-
if (typeof schema == "boolean")
|
|
99
|
-
return !schema;
|
|
100
|
-
for (const key in schema)
|
|
101
|
-
if (self.RULES.all[key])
|
|
102
|
-
return true;
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
function isSchemaObj(it) {
|
|
106
|
-
return typeof it.schema != "boolean";
|
|
107
|
-
}
|
|
108
|
-
function subSchemaObjCode(it, valid) {
|
|
109
|
-
const { schema, gen, opts } = it;
|
|
110
|
-
if (opts.$comment && schema.$comment)
|
|
111
|
-
commentKeyword(it);
|
|
112
|
-
updateContext(it);
|
|
113
|
-
checkAsyncSchema(it);
|
|
114
|
-
const errsCount = gen.const("_errs", names_1.default.errors);
|
|
115
|
-
typeAndKeywords(it, errsCount);
|
|
116
|
-
// TODO var
|
|
117
|
-
gen.var(valid, (0, codegen_1._) `${errsCount} === ${names_1.default.errors}`);
|
|
118
|
-
}
|
|
119
|
-
function checkKeywords(it) {
|
|
120
|
-
(0, util_1.checkUnknownRules)(it);
|
|
121
|
-
checkRefsAndKeywords(it);
|
|
122
|
-
}
|
|
123
|
-
function typeAndKeywords(it, errsCount) {
|
|
124
|
-
if (it.opts.jtd)
|
|
125
|
-
return schemaKeywords(it, [], false, errsCount);
|
|
126
|
-
const types = (0, dataType_1.getSchemaTypes)(it.schema);
|
|
127
|
-
const checkedTypes = (0, dataType_1.coerceAndCheckDataType)(it, types);
|
|
128
|
-
schemaKeywords(it, types, !checkedTypes, errsCount);
|
|
129
|
-
}
|
|
130
|
-
function checkRefsAndKeywords(it) {
|
|
131
|
-
const { schema, errSchemaPath, opts, self } = it;
|
|
132
|
-
if (schema.$ref && opts.ignoreKeywordsWithRef && (0, util_1.schemaHasRulesButRef)(schema, self.RULES)) {
|
|
133
|
-
self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function checkNoDefault(it) {
|
|
137
|
-
const { schema, opts } = it;
|
|
138
|
-
if (schema.default !== undefined && opts.useDefaults && opts.strictSchema) {
|
|
139
|
-
(0, util_1.checkStrictMode)(it, "default is ignored in the schema root");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function updateContext(it) {
|
|
143
|
-
const schId = it.schema[it.opts.schemaId];
|
|
144
|
-
if (schId)
|
|
145
|
-
it.baseId = (0, resolve_1.resolveUrl)(it.opts.uriResolver, it.baseId, schId);
|
|
146
|
-
}
|
|
147
|
-
function checkAsyncSchema(it) {
|
|
148
|
-
if (it.schema.$async && !it.schemaEnv.$async)
|
|
149
|
-
throw new Error("async schema in sync schema");
|
|
150
|
-
}
|
|
151
|
-
function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
|
|
152
|
-
const msg = schema.$comment;
|
|
153
|
-
if (opts.$comment === true) {
|
|
154
|
-
gen.code((0, codegen_1._) `${names_1.default.self}.logger.log(${msg})`);
|
|
155
|
-
}
|
|
156
|
-
else if (typeof opts.$comment == "function") {
|
|
157
|
-
const schemaPath = (0, codegen_1.str) `${errSchemaPath}/$comment`;
|
|
158
|
-
const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
|
|
159
|
-
gen.code((0, codegen_1._) `${names_1.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function returnResults(it) {
|
|
163
|
-
const { gen, schemaEnv, validateName, ValidationError, opts } = it;
|
|
164
|
-
if (schemaEnv.$async) {
|
|
165
|
-
// TODO assign unevaluated
|
|
166
|
-
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})`));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
gen.assign((0, codegen_1._) `${validateName}.errors`, names_1.default.vErrors);
|
|
170
|
-
if (opts.unevaluated)
|
|
171
|
-
assignEvaluated(it);
|
|
172
|
-
gen.return((0, codegen_1._) `${names_1.default.errors} === 0`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function assignEvaluated({ gen, evaluated, props, items }) {
|
|
176
|
-
if (props instanceof codegen_1.Name)
|
|
177
|
-
gen.assign((0, codegen_1._) `${evaluated}.props`, props);
|
|
178
|
-
if (items instanceof codegen_1.Name)
|
|
179
|
-
gen.assign((0, codegen_1._) `${evaluated}.items`, items);
|
|
180
|
-
}
|
|
181
|
-
function schemaKeywords(it, types, typeErrors, errsCount) {
|
|
182
|
-
const { gen, schema, data, allErrors, opts, self } = it;
|
|
183
|
-
const { RULES } = self;
|
|
184
|
-
if (schema.$ref && (opts.ignoreKeywordsWithRef || !(0, util_1.schemaHasRulesButRef)(schema, RULES))) {
|
|
185
|
-
gen.block(() => keywordCode(it, "$ref", RULES.all.$ref.definition)); // TODO typecast
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (!opts.jtd)
|
|
189
|
-
checkStrictTypes(it, types);
|
|
190
|
-
gen.block(() => {
|
|
191
|
-
for (const group of RULES.rules)
|
|
192
|
-
groupKeywords(group);
|
|
193
|
-
groupKeywords(RULES.post);
|
|
194
|
-
});
|
|
195
|
-
function groupKeywords(group) {
|
|
196
|
-
if (!(0, applicability_1.shouldUseGroup)(schema, group))
|
|
197
|
-
return;
|
|
198
|
-
if (group.type) {
|
|
199
|
-
gen.if((0, dataType_2.checkDataType)(group.type, data, opts.strictNumbers));
|
|
200
|
-
iterateKeywords(it, group);
|
|
201
|
-
if (types.length === 1 && types[0] === group.type && typeErrors) {
|
|
202
|
-
gen.else();
|
|
203
|
-
(0, dataType_2.reportTypeError)(it);
|
|
204
|
-
}
|
|
205
|
-
gen.endIf();
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
iterateKeywords(it, group);
|
|
209
|
-
}
|
|
210
|
-
// TODO make it "ok" call?
|
|
211
|
-
if (!allErrors)
|
|
212
|
-
gen.if((0, codegen_1._) `${names_1.default.errors} === ${errsCount || 0}`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
function iterateKeywords(it, group) {
|
|
216
|
-
const { gen, schema, opts: { useDefaults }, } = it;
|
|
217
|
-
if (useDefaults)
|
|
218
|
-
(0, defaults_1.assignDefaults)(it, group.type);
|
|
219
|
-
gen.block(() => {
|
|
220
|
-
for (const rule of group.rules) {
|
|
221
|
-
if ((0, applicability_1.shouldUseRule)(schema, rule)) {
|
|
222
|
-
keywordCode(it, rule.keyword, rule.definition, group.type);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
function checkStrictTypes(it, types) {
|
|
228
|
-
if (it.schemaEnv.meta || !it.opts.strictTypes)
|
|
229
|
-
return;
|
|
230
|
-
checkContextTypes(it, types);
|
|
231
|
-
if (!it.opts.allowUnionTypes)
|
|
232
|
-
checkMultipleTypes(it, types);
|
|
233
|
-
checkKeywordTypes(it, it.dataTypes);
|
|
234
|
-
}
|
|
235
|
-
function checkContextTypes(it, types) {
|
|
236
|
-
if (!types.length)
|
|
237
|
-
return;
|
|
238
|
-
if (!it.dataTypes.length) {
|
|
239
|
-
it.dataTypes = types;
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
types.forEach((t) => {
|
|
243
|
-
if (!includesType(it.dataTypes, t)) {
|
|
244
|
-
strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
narrowSchemaTypes(it, types);
|
|
248
|
-
}
|
|
249
|
-
function checkMultipleTypes(it, ts) {
|
|
250
|
-
if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
|
|
251
|
-
strictTypesError(it, "use allowUnionTypes to allow union type keyword");
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
function checkKeywordTypes(it, ts) {
|
|
255
|
-
const rules = it.self.RULES.all;
|
|
256
|
-
for (const keyword in rules) {
|
|
257
|
-
const rule = rules[keyword];
|
|
258
|
-
if (typeof rule == "object" && (0, applicability_1.shouldUseRule)(it.schema, rule)) {
|
|
259
|
-
const { type } = rule.definition;
|
|
260
|
-
if (type.length && !type.some((t) => hasApplicableType(ts, t))) {
|
|
261
|
-
strictTypesError(it, `missing type "${type.join(",")}" for keyword "${keyword}"`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function hasApplicableType(schTs, kwdT) {
|
|
267
|
-
return schTs.includes(kwdT) || (kwdT === "number" && schTs.includes("integer"));
|
|
268
|
-
}
|
|
269
|
-
function includesType(ts, t) {
|
|
270
|
-
return ts.includes(t) || (t === "integer" && ts.includes("number"));
|
|
271
|
-
}
|
|
272
|
-
function narrowSchemaTypes(it, withTypes) {
|
|
273
|
-
const ts = [];
|
|
274
|
-
for (const t of it.dataTypes) {
|
|
275
|
-
if (includesType(withTypes, t))
|
|
276
|
-
ts.push(t);
|
|
277
|
-
else if (withTypes.includes("integer") && t === "number")
|
|
278
|
-
ts.push("integer");
|
|
279
|
-
}
|
|
280
|
-
it.dataTypes = ts;
|
|
281
|
-
}
|
|
282
|
-
function strictTypesError(it, msg) {
|
|
283
|
-
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
284
|
-
msg += ` at "${schemaPath}" (strictTypes)`;
|
|
285
|
-
(0, util_1.checkStrictMode)(it, msg, it.opts.strictTypes);
|
|
286
|
-
}
|
|
287
|
-
class KeywordCxt {
|
|
288
|
-
constructor(it, def, keyword) {
|
|
289
|
-
(0, keyword_1.validateKeywordUsage)(it, def, keyword);
|
|
290
|
-
this.gen = it.gen;
|
|
291
|
-
this.allErrors = it.allErrors;
|
|
292
|
-
this.keyword = keyword;
|
|
293
|
-
this.data = it.data;
|
|
294
|
-
this.schema = it.schema[keyword];
|
|
295
|
-
this.$data = def.$data && it.opts.$data && this.schema && this.schema.$data;
|
|
296
|
-
this.schemaValue = (0, util_1.schemaRefOrVal)(it, this.schema, keyword, this.$data);
|
|
297
|
-
this.schemaType = def.schemaType;
|
|
298
|
-
this.parentSchema = it.schema;
|
|
299
|
-
this.params = {};
|
|
300
|
-
this.it = it;
|
|
301
|
-
this.def = def;
|
|
302
|
-
if (this.$data) {
|
|
303
|
-
this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
this.schemaCode = this.schemaValue;
|
|
307
|
-
if (!(0, keyword_1.validSchemaType)(this.schema, def.schemaType, def.allowUndefined)) {
|
|
308
|
-
throw new Error(`${keyword} value must be ${JSON.stringify(def.schemaType)}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if ("code" in def ? def.trackErrors : def.errors !== false) {
|
|
312
|
-
this.errsCount = it.gen.const("_errs", names_1.default.errors);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
result(condition, successAction, failAction) {
|
|
316
|
-
this.failResult((0, codegen_1.not)(condition), successAction, failAction);
|
|
317
|
-
}
|
|
318
|
-
failResult(condition, successAction, failAction) {
|
|
319
|
-
this.gen.if(condition);
|
|
320
|
-
if (failAction)
|
|
321
|
-
failAction();
|
|
322
|
-
else
|
|
323
|
-
this.error();
|
|
324
|
-
if (successAction) {
|
|
325
|
-
this.gen.else();
|
|
326
|
-
successAction();
|
|
327
|
-
if (this.allErrors)
|
|
328
|
-
this.gen.endIf();
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
if (this.allErrors)
|
|
332
|
-
this.gen.endIf();
|
|
333
|
-
else
|
|
334
|
-
this.gen.else();
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
pass(condition, failAction) {
|
|
338
|
-
this.failResult((0, codegen_1.not)(condition), undefined, failAction);
|
|
339
|
-
}
|
|
340
|
-
fail(condition) {
|
|
341
|
-
if (condition === undefined) {
|
|
342
|
-
this.error();
|
|
343
|
-
if (!this.allErrors)
|
|
344
|
-
this.gen.if(false); // this branch will be removed by gen.optimize
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
this.gen.if(condition);
|
|
348
|
-
this.error();
|
|
349
|
-
if (this.allErrors)
|
|
350
|
-
this.gen.endIf();
|
|
351
|
-
else
|
|
352
|
-
this.gen.else();
|
|
353
|
-
}
|
|
354
|
-
fail$data(condition) {
|
|
355
|
-
if (!this.$data)
|
|
356
|
-
return this.fail(condition);
|
|
357
|
-
const { schemaCode } = this;
|
|
358
|
-
this.fail((0, codegen_1._) `${schemaCode} !== undefined && (${(0, codegen_1.or)(this.invalid$data(), condition)})`);
|
|
359
|
-
}
|
|
360
|
-
error(append, errorParams, errorPaths) {
|
|
361
|
-
if (errorParams) {
|
|
362
|
-
this.setParams(errorParams);
|
|
363
|
-
this._error(append, errorPaths);
|
|
364
|
-
this.setParams({});
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
this._error(append, errorPaths);
|
|
368
|
-
}
|
|
369
|
-
_error(append, errorPaths) {
|
|
370
|
-
;
|
|
371
|
-
(append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error, errorPaths);
|
|
372
|
-
}
|
|
373
|
-
$dataError() {
|
|
374
|
-
(0, errors_1.reportError)(this, this.def.$dataError || errors_1.keyword$DataError);
|
|
375
|
-
}
|
|
376
|
-
reset() {
|
|
377
|
-
if (this.errsCount === undefined)
|
|
378
|
-
throw new Error('add "trackErrors" to keyword definition');
|
|
379
|
-
(0, errors_1.resetErrorsCount)(this.gen, this.errsCount);
|
|
380
|
-
}
|
|
381
|
-
ok(cond) {
|
|
382
|
-
if (!this.allErrors)
|
|
383
|
-
this.gen.if(cond);
|
|
384
|
-
}
|
|
385
|
-
setParams(obj, assign) {
|
|
386
|
-
if (assign)
|
|
387
|
-
Object.assign(this.params, obj);
|
|
388
|
-
else
|
|
389
|
-
this.params = obj;
|
|
390
|
-
}
|
|
391
|
-
block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
|
|
392
|
-
this.gen.block(() => {
|
|
393
|
-
this.check$data(valid, $dataValid);
|
|
394
|
-
codeBlock();
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
check$data(valid = codegen_1.nil, $dataValid = codegen_1.nil) {
|
|
398
|
-
if (!this.$data)
|
|
399
|
-
return;
|
|
400
|
-
const { gen, schemaCode, schemaType, def } = this;
|
|
401
|
-
gen.if((0, codegen_1.or)((0, codegen_1._) `${schemaCode} === undefined`, $dataValid));
|
|
402
|
-
if (valid !== codegen_1.nil)
|
|
403
|
-
gen.assign(valid, true);
|
|
404
|
-
if (schemaType.length || def.validateSchema) {
|
|
405
|
-
gen.elseIf(this.invalid$data());
|
|
406
|
-
this.$dataError();
|
|
407
|
-
if (valid !== codegen_1.nil)
|
|
408
|
-
gen.assign(valid, false);
|
|
409
|
-
}
|
|
410
|
-
gen.else();
|
|
411
|
-
}
|
|
412
|
-
invalid$data() {
|
|
413
|
-
const { gen, schemaCode, schemaType, def, it } = this;
|
|
414
|
-
return (0, codegen_1.or)(wrong$DataType(), invalid$DataSchema());
|
|
415
|
-
function wrong$DataType() {
|
|
416
|
-
if (schemaType.length) {
|
|
417
|
-
/* istanbul ignore if */
|
|
418
|
-
if (!(schemaCode instanceof codegen_1.Name))
|
|
419
|
-
throw new Error("ajv implementation error");
|
|
420
|
-
const st = Array.isArray(schemaType) ? schemaType : [schemaType];
|
|
421
|
-
return (0, codegen_1._) `${(0, dataType_2.checkDataTypes)(st, schemaCode, it.opts.strictNumbers, dataType_2.DataType.Wrong)}`;
|
|
422
|
-
}
|
|
423
|
-
return codegen_1.nil;
|
|
424
|
-
}
|
|
425
|
-
function invalid$DataSchema() {
|
|
426
|
-
if (def.validateSchema) {
|
|
427
|
-
const validateSchemaRef = gen.scopeValue("validate$data", { ref: def.validateSchema }); // TODO value.code for standalone
|
|
428
|
-
return (0, codegen_1._) `!${validateSchemaRef}(${schemaCode})`;
|
|
429
|
-
}
|
|
430
|
-
return codegen_1.nil;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
subschema(appl, valid) {
|
|
434
|
-
const subschema = (0, subschema_1.getSubschema)(this.it, appl);
|
|
435
|
-
(0, subschema_1.extendSubschemaData)(subschema, this.it, appl);
|
|
436
|
-
(0, subschema_1.extendSubschemaMode)(subschema, appl);
|
|
437
|
-
const nextContext = { ...this.it, ...subschema, items: undefined, props: undefined };
|
|
438
|
-
subschemaCode(nextContext, valid);
|
|
439
|
-
return nextContext;
|
|
440
|
-
}
|
|
441
|
-
mergeEvaluated(schemaCxt, toName) {
|
|
442
|
-
const { it, gen } = this;
|
|
443
|
-
if (!it.opts.unevaluated)
|
|
444
|
-
return;
|
|
445
|
-
if (it.props !== true && schemaCxt.props !== undefined) {
|
|
446
|
-
it.props = util_1.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
|
|
447
|
-
}
|
|
448
|
-
if (it.items !== true && schemaCxt.items !== undefined) {
|
|
449
|
-
it.items = util_1.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
mergeValidEvaluated(schemaCxt, valid) {
|
|
453
|
-
const { it, gen } = this;
|
|
454
|
-
if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
|
|
455
|
-
gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1.Name));
|
|
456
|
-
return true;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
exports.KeywordCxt = KeywordCxt;
|
|
461
|
-
function keywordCode(it, keyword, def, ruleType) {
|
|
462
|
-
const cxt = new KeywordCxt(it, def, keyword);
|
|
463
|
-
if ("code" in def) {
|
|
464
|
-
def.code(cxt, ruleType);
|
|
465
|
-
}
|
|
466
|
-
else if (cxt.$data && def.validate) {
|
|
467
|
-
(0, keyword_1.funcKeywordCode)(cxt, def);
|
|
468
|
-
}
|
|
469
|
-
else if ("macro" in def) {
|
|
470
|
-
(0, keyword_1.macroKeywordCode)(cxt, def);
|
|
471
|
-
}
|
|
472
|
-
else if (def.compile || def.validate) {
|
|
473
|
-
(0, keyword_1.funcKeywordCode)(cxt, def);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
|
|
477
|
-
const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
|
|
478
|
-
function getData($data, { dataLevel, dataNames, dataPathArr }) {
|
|
479
|
-
let jsonPointer;
|
|
480
|
-
let data;
|
|
481
|
-
if ($data === "")
|
|
482
|
-
return names_1.default.rootData;
|
|
483
|
-
if ($data[0] === "/") {
|
|
484
|
-
if (!JSON_POINTER.test($data))
|
|
485
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
486
|
-
jsonPointer = $data;
|
|
487
|
-
data = names_1.default.rootData;
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
const matches = RELATIVE_JSON_POINTER.exec($data);
|
|
491
|
-
if (!matches)
|
|
492
|
-
throw new Error(`Invalid JSON-pointer: ${$data}`);
|
|
493
|
-
const up = +matches[1];
|
|
494
|
-
jsonPointer = matches[2];
|
|
495
|
-
if (jsonPointer === "#") {
|
|
496
|
-
if (up >= dataLevel)
|
|
497
|
-
throw new Error(errorMsg("property/index", up));
|
|
498
|
-
return dataPathArr[dataLevel - up];
|
|
499
|
-
}
|
|
500
|
-
if (up > dataLevel)
|
|
501
|
-
throw new Error(errorMsg("data", up));
|
|
502
|
-
data = dataNames[dataLevel - up];
|
|
503
|
-
if (!jsonPointer)
|
|
504
|
-
return data;
|
|
505
|
-
}
|
|
506
|
-
let expr = data;
|
|
507
|
-
const segments = jsonPointer.split("/");
|
|
508
|
-
for (const segment of segments) {
|
|
509
|
-
if (segment) {
|
|
510
|
-
data = (0, codegen_1._) `${data}${(0, codegen_1.getProperty)((0, util_1.unescapeJsonPointer)(segment))}`;
|
|
511
|
-
expr = (0, codegen_1._) `${expr} && ${data}`;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
return expr;
|
|
515
|
-
function errorMsg(pointerType, up) {
|
|
516
|
-
return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
exports.getData = getData;
|
|
520
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateKeywordUsage = exports.validSchemaType = exports.funcKeywordCode = exports.macroKeywordCode = void 0;
|
|
4
|
-
const codegen_1 = require('../codegen/index.js');
|
|
5
|
-
const names_1 = require('../names.js');
|
|
6
|
-
const code_1 = require('../../vocabularies/code.js');
|
|
7
|
-
const errors_1 = require('../errors.js');
|
|
8
|
-
function macroKeywordCode(cxt, def) {
|
|
9
|
-
const { gen, keyword, schema, parentSchema, it } = cxt;
|
|
10
|
-
const macroSchema = def.macro.call(it.self, schema, parentSchema, it);
|
|
11
|
-
const schemaRef = useKeyword(gen, keyword, macroSchema);
|
|
12
|
-
if (it.opts.validateSchema !== false)
|
|
13
|
-
it.self.validateSchema(macroSchema, true);
|
|
14
|
-
const valid = gen.name("valid");
|
|
15
|
-
cxt.subschema({
|
|
16
|
-
schema: macroSchema,
|
|
17
|
-
schemaPath: codegen_1.nil,
|
|
18
|
-
errSchemaPath: `${it.errSchemaPath}/${keyword}`,
|
|
19
|
-
topSchemaRef: schemaRef,
|
|
20
|
-
compositeRule: true,
|
|
21
|
-
}, valid);
|
|
22
|
-
cxt.pass(valid, () => cxt.error(true));
|
|
23
|
-
}
|
|
24
|
-
exports.macroKeywordCode = macroKeywordCode;
|
|
25
|
-
function funcKeywordCode(cxt, def) {
|
|
26
|
-
var _a;
|
|
27
|
-
const { gen, keyword, schema, parentSchema, $data, it } = cxt;
|
|
28
|
-
checkAsyncKeyword(it, def);
|
|
29
|
-
const validate = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate;
|
|
30
|
-
const validateRef = useKeyword(gen, keyword, validate);
|
|
31
|
-
const valid = gen.let("valid");
|
|
32
|
-
cxt.block$data(valid, validateKeyword);
|
|
33
|
-
cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid);
|
|
34
|
-
function validateKeyword() {
|
|
35
|
-
if (def.errors === false) {
|
|
36
|
-
assignValid();
|
|
37
|
-
if (def.modifying)
|
|
38
|
-
modifyData(cxt);
|
|
39
|
-
reportErrs(() => cxt.error());
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const ruleErrs = def.async ? validateAsync() : validateSync();
|
|
43
|
-
if (def.modifying)
|
|
44
|
-
modifyData(cxt);
|
|
45
|
-
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function validateAsync() {
|
|
49
|
-
const ruleErrs = gen.let("ruleErrs", null);
|
|
50
|
-
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)));
|
|
51
|
-
return ruleErrs;
|
|
52
|
-
}
|
|
53
|
-
function validateSync() {
|
|
54
|
-
const validateErrs = (0, codegen_1._) `${validateRef}.errors`;
|
|
55
|
-
gen.assign(validateErrs, null);
|
|
56
|
-
assignValid(codegen_1.nil);
|
|
57
|
-
return validateErrs;
|
|
58
|
-
}
|
|
59
|
-
function assignValid(_await = def.async ? (0, codegen_1._) `await ` : codegen_1.nil) {
|
|
60
|
-
const passCxt = it.opts.passContext ? names_1.default.this : names_1.default.self;
|
|
61
|
-
const passSchema = !(("compile" in def && !$data) || def.schema === false);
|
|
62
|
-
gen.assign(valid, (0, codegen_1._) `${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
|
|
63
|
-
}
|
|
64
|
-
function reportErrs(errors) {
|
|
65
|
-
var _a;
|
|
66
|
-
gen.if((0, codegen_1.not)((_a = def.valid) !== null && _a !== void 0 ? _a : valid), errors);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.funcKeywordCode = funcKeywordCode;
|
|
70
|
-
function modifyData(cxt) {
|
|
71
|
-
const { gen, data, it } = cxt;
|
|
72
|
-
gen.if(it.parentData, () => gen.assign(data, (0, codegen_1._) `${it.parentData}[${it.parentDataProperty}]`));
|
|
73
|
-
}
|
|
74
|
-
function addErrs(cxt, errs) {
|
|
75
|
-
const { gen } = cxt;
|
|
76
|
-
gen.if((0, codegen_1._) `Array.isArray(${errs})`, () => {
|
|
77
|
-
gen
|
|
78
|
-
.assign(names_1.default.vErrors, (0, codegen_1._) `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`)
|
|
79
|
-
.assign(names_1.default.errors, (0, codegen_1._) `${names_1.default.vErrors}.length`);
|
|
80
|
-
(0, errors_1.extendErrors)(cxt);
|
|
81
|
-
}, () => cxt.error());
|
|
82
|
-
}
|
|
83
|
-
function checkAsyncKeyword({ schemaEnv }, def) {
|
|
84
|
-
if (def.async && !schemaEnv.$async)
|
|
85
|
-
throw new Error("async keyword in sync schema");
|
|
86
|
-
}
|
|
87
|
-
function useKeyword(gen, keyword, result) {
|
|
88
|
-
if (result === undefined)
|
|
89
|
-
throw new Error(`keyword "${keyword}" failed to compile`);
|
|
90
|
-
return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: (0, codegen_1.stringify)(result) });
|
|
91
|
-
}
|
|
92
|
-
function validSchemaType(schema, schemaType, allowUndefined = false) {
|
|
93
|
-
// TODO add tests
|
|
94
|
-
return (!schemaType.length ||
|
|
95
|
-
schemaType.some((st) => st === "array"
|
|
96
|
-
? Array.isArray(schema)
|
|
97
|
-
: st === "object"
|
|
98
|
-
? schema && typeof schema == "object" && !Array.isArray(schema)
|
|
99
|
-
: typeof schema == st || (allowUndefined && typeof schema == "undefined")));
|
|
100
|
-
}
|
|
101
|
-
exports.validSchemaType = validSchemaType;
|
|
102
|
-
function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def, keyword) {
|
|
103
|
-
/* istanbul ignore if */
|
|
104
|
-
if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) {
|
|
105
|
-
throw new Error("ajv implementation error");
|
|
106
|
-
}
|
|
107
|
-
const deps = def.dependencies;
|
|
108
|
-
if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
|
|
109
|
-
throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`);
|
|
110
|
-
}
|
|
111
|
-
if (def.validateSchema) {
|
|
112
|
-
const valid = def.validateSchema(schema[keyword]);
|
|
113
|
-
if (!valid) {
|
|
114
|
-
const msg = `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` +
|
|
115
|
-
self.errorsText(def.validateSchema.errors);
|
|
116
|
-
if (opts.validateSchema === "log")
|
|
117
|
-
self.logger.error(msg);
|
|
118
|
-
else
|
|
119
|
-
throw new Error(msg);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
exports.validateKeywordUsage = validateKeywordUsage;
|
|
124
|
-
//# sourceMappingURL=keyword.js.map
|