@blueking/bkui-form 1.0.1-beta.1 → 1.0.1-beta.3
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/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
- package/esm/adapter/field/ArrayField.tsx.js +55 -0
- package/esm/adapter/field/BooleanField.tsx.js +41 -0
- package/esm/adapter/field/CompositionField.tsx.js +113 -0
- package/esm/adapter/field/FieldProps.ts.js +85 -0
- package/esm/adapter/field/NumberField.tsx.js +19 -0
- package/esm/adapter/field/ObjectField.tsx.js +58 -0
- package/esm/adapter/field/SchemaField.tsx.js +28 -0
- package/esm/adapter/field/StringField.tsx.js +4 -0
- package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
- package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
- package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
- package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
- package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
- package/esm/adapter/widget/InputWidget.ts.js +79 -0
- package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
- package/esm/adapter/widget/RadioWidget.ts.js +98 -0
- package/esm/adapter/widget/SelectWidget.ts.js +98 -0
- package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
- package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
- package/esm/adapter/widget/TableWidget.ts.js +205 -0
- package/esm/adapter/widget/Widget.ts.js +497 -0
- package/esm/assets/fonts/iconcool.eot +0 -0
- package/esm/assets/fonts/iconcool.ttf +0 -0
- package/esm/assets/fonts/iconcool.woff +0 -0
- package/esm/assets/style.css +43 -0
- package/esm/controller/form.css +164 -0
- package/esm/controller/form.tsx.js +159 -0
- package/esm/controller/props.ts.js +75 -0
- package/esm/core/events.ts.js +74 -0
- package/esm/core/expression.ts.js +67 -0
- package/esm/core/lang.ts.js +25 -0
- package/esm/core/layout.ts.js +149 -0
- package/esm/core/path.ts.js +60 -0
- package/esm/core/proxy.ts.js +10 -0
- package/esm/core/reaction.ts.js +116 -0
- package/esm/core/register.ts.js +74 -0
- package/esm/core/schema.ts.js +302 -0
- package/esm/core/validator.ts.js +248 -0
- package/esm/core/widgetTree.ts.js +163 -0
- package/esm/index.ts.js +6 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
- package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
- package/esm/node_modules/ajv/dist/ajv.js +50 -0
- package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
- package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
- package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
- package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
- package/esm/node_modules/ajv/dist/compile/index.js +242 -0
- package/esm/node_modules/ajv/dist/compile/names.js +28 -0
- package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
- package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
- package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
- package/esm/node_modules/ajv/dist/compile/util.js +178 -0
- package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
- package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
- package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
- package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
- package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
- package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
- package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
- package/esm/node_modules/ajv/dist/core.js +618 -0
- package/esm/node_modules/ajv/dist/refs/data.json +13 -0
- package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
- package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
- package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
- package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
- package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
- package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
- package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
- package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
- package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
- package/esm/node_modules/ajv-formats/dist/index.js +37 -0
- package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
- package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
- package/esm/node_modules/fast-deep-equal/index.js +46 -0
- package/esm/node_modules/fast-uri/index.js +303 -0
- package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
- package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/esm/node_modules/fast-uri/lib/utils.js +244 -0
- package/esm/node_modules/json-schema-traverse/index.js +89 -0
- package/esm/node_modules/semver/classes/comparator.js +143 -0
- package/esm/node_modules/semver/classes/range.js +557 -0
- package/esm/node_modules/semver/classes/semver.js +333 -0
- package/esm/node_modules/semver/functions/clean.js +8 -0
- package/esm/node_modules/semver/functions/cmp.js +54 -0
- package/esm/node_modules/semver/functions/coerce.js +62 -0
- package/esm/node_modules/semver/functions/compare-build.js +9 -0
- package/esm/node_modules/semver/functions/compare-loose.js +5 -0
- package/esm/node_modules/semver/functions/compare.js +7 -0
- package/esm/node_modules/semver/functions/diff.js +60 -0
- package/esm/node_modules/semver/functions/eq.js +5 -0
- package/esm/node_modules/semver/functions/gt.js +5 -0
- package/esm/node_modules/semver/functions/gte.js +5 -0
- package/esm/node_modules/semver/functions/inc.js +21 -0
- package/esm/node_modules/semver/functions/lt.js +5 -0
- package/esm/node_modules/semver/functions/lte.js +5 -0
- package/esm/node_modules/semver/functions/major.js +5 -0
- package/esm/node_modules/semver/functions/minor.js +5 -0
- package/esm/node_modules/semver/functions/neq.js +5 -0
- package/esm/node_modules/semver/functions/parse.js +18 -0
- package/esm/node_modules/semver/functions/patch.js +5 -0
- package/esm/node_modules/semver/functions/prerelease.js +8 -0
- package/esm/node_modules/semver/functions/rcompare.js +5 -0
- package/esm/node_modules/semver/functions/rsort.js +5 -0
- package/esm/node_modules/semver/functions/satisfies.js +12 -0
- package/esm/node_modules/semver/functions/sort.js +5 -0
- package/esm/node_modules/semver/functions/valid.js +8 -0
- package/esm/node_modules/semver/index.js +91 -0
- package/esm/node_modules/semver/internal/constants.js +37 -0
- package/esm/node_modules/semver/internal/debug.js +11 -0
- package/esm/node_modules/semver/internal/identifiers.js +29 -0
- package/esm/node_modules/semver/internal/lrucache.js +42 -0
- package/esm/node_modules/semver/internal/parse-options.js +17 -0
- package/esm/node_modules/semver/internal/re.js +223 -0
- package/esm/node_modules/semver/ranges/gtr.js +6 -0
- package/esm/node_modules/semver/ranges/intersects.js +9 -0
- package/esm/node_modules/semver/ranges/ltr.js +6 -0
- package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/esm/node_modules/semver/ranges/min-version.js +63 -0
- package/esm/node_modules/semver/ranges/outside.js +82 -0
- package/esm/node_modules/semver/ranges/simplify.js +49 -0
- package/esm/node_modules/semver/ranges/subset.js +249 -0
- package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
- package/esm/node_modules/semver/ranges/valid.js +13 -0
- package/esm/util/fetch.ts.js +190 -0
- package/esm/util/index.ts.js +276 -0
- package/package.json +3 -4
- package/dist/main.css +0 -208
- package/dist/main.js +0 -17353
- /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callRef = exports.getValidate = void 0;
|
|
4
|
+
const ref_error_1 = require('../../compile/ref_error.js');
|
|
5
|
+
const code_1 = require('../code.js');
|
|
6
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
7
|
+
const names_1 = require('../../compile/names.js');
|
|
8
|
+
const compile_1 = require('../../compile/index.js');
|
|
9
|
+
const util_1 = require('../../compile/util.js');
|
|
10
|
+
const def = {
|
|
11
|
+
keyword: "$ref",
|
|
12
|
+
schemaType: "string",
|
|
13
|
+
code(cxt) {
|
|
14
|
+
const { gen, schema: $ref, it } = cxt;
|
|
15
|
+
const { baseId, schemaEnv: env, validateName, opts, self } = it;
|
|
16
|
+
const { root } = env;
|
|
17
|
+
if (($ref === "#" || $ref === "#/") && baseId === root.baseId)
|
|
18
|
+
return callRootRef();
|
|
19
|
+
const schOrEnv = compile_1.resolveRef.call(self, root, baseId, $ref);
|
|
20
|
+
if (schOrEnv === undefined)
|
|
21
|
+
throw new ref_error_1.default(it.opts.uriResolver, baseId, $ref);
|
|
22
|
+
if (schOrEnv instanceof compile_1.SchemaEnv)
|
|
23
|
+
return callValidate(schOrEnv);
|
|
24
|
+
return inlineRefSchema(schOrEnv);
|
|
25
|
+
function callRootRef() {
|
|
26
|
+
if (env === root)
|
|
27
|
+
return callRef(cxt, validateName, env, env.$async);
|
|
28
|
+
const rootName = gen.scopeValue("root", { ref: root });
|
|
29
|
+
return callRef(cxt, (0, codegen_1._) `${rootName}.validate`, root, root.$async);
|
|
30
|
+
}
|
|
31
|
+
function callValidate(sch) {
|
|
32
|
+
const v = getValidate(cxt, sch);
|
|
33
|
+
callRef(cxt, v, sch, sch.$async);
|
|
34
|
+
}
|
|
35
|
+
function inlineRefSchema(sch) {
|
|
36
|
+
const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: (0, codegen_1.stringify)(sch) } : { ref: sch });
|
|
37
|
+
const valid = gen.name("valid");
|
|
38
|
+
const schCxt = cxt.subschema({
|
|
39
|
+
schema: sch,
|
|
40
|
+
dataTypes: [],
|
|
41
|
+
schemaPath: codegen_1.nil,
|
|
42
|
+
topSchemaRef: schName,
|
|
43
|
+
errSchemaPath: $ref,
|
|
44
|
+
}, valid);
|
|
45
|
+
cxt.mergeEvaluated(schCxt);
|
|
46
|
+
cxt.ok(valid);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
function getValidate(cxt, sch) {
|
|
51
|
+
const { gen } = cxt;
|
|
52
|
+
return sch.validate
|
|
53
|
+
? gen.scopeValue("validate", { ref: sch.validate })
|
|
54
|
+
: (0, codegen_1._) `${gen.scopeValue("wrapper", { ref: sch })}.validate`;
|
|
55
|
+
}
|
|
56
|
+
exports.getValidate = getValidate;
|
|
57
|
+
function callRef(cxt, v, sch, $async) {
|
|
58
|
+
const { gen, it } = cxt;
|
|
59
|
+
const { allErrors, schemaEnv: env, opts } = it;
|
|
60
|
+
const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
|
|
61
|
+
if ($async)
|
|
62
|
+
callAsyncRef();
|
|
63
|
+
else
|
|
64
|
+
callSyncRef();
|
|
65
|
+
function callAsyncRef() {
|
|
66
|
+
if (!env.$async)
|
|
67
|
+
throw new Error("async schema referenced by sync schema");
|
|
68
|
+
const valid = gen.let("valid");
|
|
69
|
+
gen.try(() => {
|
|
70
|
+
gen.code((0, codegen_1._) `await ${(0, code_1.callValidateCode)(cxt, v, passCxt)}`);
|
|
71
|
+
addEvaluatedFrom(v); // TODO will not work with async, it has to be returned with the result
|
|
72
|
+
if (!allErrors)
|
|
73
|
+
gen.assign(valid, true);
|
|
74
|
+
}, (e) => {
|
|
75
|
+
gen.if((0, codegen_1._) `!(${e} instanceof ${it.ValidationError})`, () => gen.throw(e));
|
|
76
|
+
addErrorsFrom(e);
|
|
77
|
+
if (!allErrors)
|
|
78
|
+
gen.assign(valid, false);
|
|
79
|
+
});
|
|
80
|
+
cxt.ok(valid);
|
|
81
|
+
}
|
|
82
|
+
function callSyncRef() {
|
|
83
|
+
cxt.result((0, code_1.callValidateCode)(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
|
|
84
|
+
}
|
|
85
|
+
function addErrorsFrom(source) {
|
|
86
|
+
const errs = (0, codegen_1._) `${source}.errors`;
|
|
87
|
+
gen.assign(names_1.default.vErrors, (0, codegen_1._) `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`); // TODO tagged
|
|
88
|
+
gen.assign(names_1.default.errors, (0, codegen_1._) `${names_1.default.vErrors}.length`);
|
|
89
|
+
}
|
|
90
|
+
function addEvaluatedFrom(source) {
|
|
91
|
+
var _a;
|
|
92
|
+
if (!it.opts.unevaluated)
|
|
93
|
+
return;
|
|
94
|
+
const schEvaluated = (_a = sch === null || sch === void 0 ? void 0 : sch.validate) === null || _a === void 0 ? void 0 : _a.evaluated;
|
|
95
|
+
// TODO refactor
|
|
96
|
+
if (it.props !== true) {
|
|
97
|
+
if (schEvaluated && !schEvaluated.dynamicProps) {
|
|
98
|
+
if (schEvaluated.props !== undefined) {
|
|
99
|
+
it.props = util_1.mergeEvaluated.props(gen, schEvaluated.props, it.props);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const props = gen.var("props", (0, codegen_1._) `${source}.evaluated.props`);
|
|
104
|
+
it.props = util_1.mergeEvaluated.props(gen, props, it.props, codegen_1.Name);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (it.items !== true) {
|
|
108
|
+
if (schEvaluated && !schEvaluated.dynamicItems) {
|
|
109
|
+
if (schEvaluated.items !== undefined) {
|
|
110
|
+
it.items = util_1.mergeEvaluated.items(gen, schEvaluated.items, it.items);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const items = gen.var("items", (0, codegen_1._) `${source}.evaluated.items`);
|
|
115
|
+
it.items = util_1.mergeEvaluated.items(gen, items, it.items, codegen_1.Name);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.callRef = callRef;
|
|
121
|
+
exports.default = def;
|
|
122
|
+
//# sourceMappingURL=ref.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const types_1 = require('./types.js');
|
|
5
|
+
const compile_1 = require('../../compile/index.js');
|
|
6
|
+
const ref_error_1 = require('../../compile/ref_error.js');
|
|
7
|
+
const util_1 = require('../../compile/util.js');
|
|
8
|
+
const error = {
|
|
9
|
+
message: ({ params: { discrError, tagName } }) => discrError === types_1.DiscrError.Tag
|
|
10
|
+
? `tag "${tagName}" must be string`
|
|
11
|
+
: `value of tag "${tagName}" must be in oneOf`,
|
|
12
|
+
params: ({ params: { discrError, tag, tagName } }) => (0, codegen_1._) `{error: ${discrError}, tag: ${tagName}, tagValue: ${tag}}`,
|
|
13
|
+
};
|
|
14
|
+
const def = {
|
|
15
|
+
keyword: "discriminator",
|
|
16
|
+
type: "object",
|
|
17
|
+
schemaType: "object",
|
|
18
|
+
error,
|
|
19
|
+
code(cxt) {
|
|
20
|
+
const { gen, data, schema, parentSchema, it } = cxt;
|
|
21
|
+
const { oneOf } = parentSchema;
|
|
22
|
+
if (!it.opts.discriminator) {
|
|
23
|
+
throw new Error("discriminator: requires discriminator option");
|
|
24
|
+
}
|
|
25
|
+
const tagName = schema.propertyName;
|
|
26
|
+
if (typeof tagName != "string")
|
|
27
|
+
throw new Error("discriminator: requires propertyName");
|
|
28
|
+
if (schema.mapping)
|
|
29
|
+
throw new Error("discriminator: mapping is not supported");
|
|
30
|
+
if (!oneOf)
|
|
31
|
+
throw new Error("discriminator: requires oneOf keyword");
|
|
32
|
+
const valid = gen.let("valid", false);
|
|
33
|
+
const tag = gen.const("tag", (0, codegen_1._) `${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
34
|
+
gen.if((0, codegen_1._) `typeof ${tag} == "string"`, () => validateMapping(), () => cxt.error(false, { discrError: types_1.DiscrError.Tag, tag, tagName }));
|
|
35
|
+
cxt.ok(valid);
|
|
36
|
+
function validateMapping() {
|
|
37
|
+
const mapping = getMapping();
|
|
38
|
+
gen.if(false);
|
|
39
|
+
for (const tagValue in mapping) {
|
|
40
|
+
gen.elseIf((0, codegen_1._) `${tag} === ${tagValue}`);
|
|
41
|
+
gen.assign(valid, applyTagSchema(mapping[tagValue]));
|
|
42
|
+
}
|
|
43
|
+
gen.else();
|
|
44
|
+
cxt.error(false, { discrError: types_1.DiscrError.Mapping, tag, tagName });
|
|
45
|
+
gen.endIf();
|
|
46
|
+
}
|
|
47
|
+
function applyTagSchema(schemaProp) {
|
|
48
|
+
const _valid = gen.name("valid");
|
|
49
|
+
const schCxt = cxt.subschema({ keyword: "oneOf", schemaProp }, _valid);
|
|
50
|
+
cxt.mergeEvaluated(schCxt, codegen_1.Name);
|
|
51
|
+
return _valid;
|
|
52
|
+
}
|
|
53
|
+
function getMapping() {
|
|
54
|
+
var _a;
|
|
55
|
+
const oneOfMapping = {};
|
|
56
|
+
const topRequired = hasRequired(parentSchema);
|
|
57
|
+
let tagRequired = true;
|
|
58
|
+
for (let i = 0; i < oneOf.length; i++) {
|
|
59
|
+
let sch = oneOf[i];
|
|
60
|
+
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it.self.RULES)) {
|
|
61
|
+
const ref = sch.$ref;
|
|
62
|
+
sch = compile_1.resolveRef.call(it.self, it.schemaEnv.root, it.baseId, ref);
|
|
63
|
+
if (sch instanceof compile_1.SchemaEnv)
|
|
64
|
+
sch = sch.schema;
|
|
65
|
+
if (sch === undefined)
|
|
66
|
+
throw new ref_error_1.default(it.opts.uriResolver, it.baseId, ref);
|
|
67
|
+
}
|
|
68
|
+
const propSch = (_a = sch === null || sch === void 0 ? void 0 : sch.properties) === null || _a === void 0 ? void 0 : _a[tagName];
|
|
69
|
+
if (typeof propSch != "object") {
|
|
70
|
+
throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${tagName}"`);
|
|
71
|
+
}
|
|
72
|
+
tagRequired = tagRequired && (topRequired || hasRequired(sch));
|
|
73
|
+
addMappings(propSch, i);
|
|
74
|
+
}
|
|
75
|
+
if (!tagRequired)
|
|
76
|
+
throw new Error(`discriminator: "${tagName}" must be required`);
|
|
77
|
+
return oneOfMapping;
|
|
78
|
+
function hasRequired({ required }) {
|
|
79
|
+
return Array.isArray(required) && required.includes(tagName);
|
|
80
|
+
}
|
|
81
|
+
function addMappings(sch, i) {
|
|
82
|
+
if (sch.const) {
|
|
83
|
+
addMapping(sch.const, i);
|
|
84
|
+
}
|
|
85
|
+
else if (sch.enum) {
|
|
86
|
+
for (const tagValue of sch.enum) {
|
|
87
|
+
addMapping(tagValue, i);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`discriminator: "properties/${tagName}" must have "const" or "enum"`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function addMapping(tagValue, i) {
|
|
95
|
+
if (typeof tagValue != "string" || tagValue in oneOfMapping) {
|
|
96
|
+
throw new Error(`discriminator: "${tagName}" values must be unique strings`);
|
|
97
|
+
}
|
|
98
|
+
oneOfMapping[tagValue] = i;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
exports.default = def;
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscrError = void 0;
|
|
4
|
+
var DiscrError;
|
|
5
|
+
(function (DiscrError) {
|
|
6
|
+
DiscrError["Tag"] = "tag";
|
|
7
|
+
DiscrError["Mapping"] = "mapping";
|
|
8
|
+
})(DiscrError || (exports.DiscrError = DiscrError = {}));
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require('./core/index.js');
|
|
4
|
+
const validation_1 = require('./validation/index.js');
|
|
5
|
+
const applicator_1 = require('./applicator/index.js');
|
|
6
|
+
const format_1 = require('./format/index.js');
|
|
7
|
+
const metadata_1 = require('./metadata.js');
|
|
8
|
+
const draft7Vocabularies = [
|
|
9
|
+
core_1.default,
|
|
10
|
+
validation_1.default,
|
|
11
|
+
(0, applicator_1.default)(),
|
|
12
|
+
format_1.default,
|
|
13
|
+
metadata_1.metadataVocabulary,
|
|
14
|
+
metadata_1.contentVocabulary,
|
|
15
|
+
];
|
|
16
|
+
exports.default = draft7Vocabularies;
|
|
17
|
+
//# sourceMappingURL=draft7.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const error = {
|
|
5
|
+
message: ({ schemaCode }) => (0, codegen_1.str) `must match format "${schemaCode}"`,
|
|
6
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{format: ${schemaCode}}`,
|
|
7
|
+
};
|
|
8
|
+
const def = {
|
|
9
|
+
keyword: "format",
|
|
10
|
+
type: ["number", "string"],
|
|
11
|
+
schemaType: "string",
|
|
12
|
+
$data: true,
|
|
13
|
+
error,
|
|
14
|
+
code(cxt, ruleType) {
|
|
15
|
+
const { gen, data, $data, schema, schemaCode, it } = cxt;
|
|
16
|
+
const { opts, errSchemaPath, schemaEnv, self } = it;
|
|
17
|
+
if (!opts.validateFormats)
|
|
18
|
+
return;
|
|
19
|
+
if ($data)
|
|
20
|
+
validate$DataFormat();
|
|
21
|
+
else
|
|
22
|
+
validateFormat();
|
|
23
|
+
function validate$DataFormat() {
|
|
24
|
+
const fmts = gen.scopeValue("formats", {
|
|
25
|
+
ref: self.formats,
|
|
26
|
+
code: opts.code.formats,
|
|
27
|
+
});
|
|
28
|
+
const fDef = gen.const("fDef", (0, codegen_1._) `${fmts}[${schemaCode}]`);
|
|
29
|
+
const fType = gen.let("fType");
|
|
30
|
+
const format = gen.let("format");
|
|
31
|
+
// TODO simplify
|
|
32
|
+
gen.if((0, codegen_1._) `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, (0, codegen_1._) `${fDef}.type || "string"`).assign(format, (0, codegen_1._) `${fDef}.validate`), () => gen.assign(fType, (0, codegen_1._) `"string"`).assign(format, fDef));
|
|
33
|
+
cxt.fail$data((0, codegen_1.or)(unknownFmt(), invalidFmt()));
|
|
34
|
+
function unknownFmt() {
|
|
35
|
+
if (opts.strictSchema === false)
|
|
36
|
+
return codegen_1.nil;
|
|
37
|
+
return (0, codegen_1._) `${schemaCode} && !${format}`;
|
|
38
|
+
}
|
|
39
|
+
function invalidFmt() {
|
|
40
|
+
const callFormat = schemaEnv.$async
|
|
41
|
+
? (0, codegen_1._) `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
|
|
42
|
+
: (0, codegen_1._) `${format}(${data})`;
|
|
43
|
+
const validData = (0, codegen_1._) `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
|
|
44
|
+
return (0, codegen_1._) `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function validateFormat() {
|
|
48
|
+
const formatDef = self.formats[schema];
|
|
49
|
+
if (!formatDef) {
|
|
50
|
+
unknownFormat();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (formatDef === true)
|
|
54
|
+
return;
|
|
55
|
+
const [fmtType, format, fmtRef] = getFormat(formatDef);
|
|
56
|
+
if (fmtType === ruleType)
|
|
57
|
+
cxt.pass(validCondition());
|
|
58
|
+
function unknownFormat() {
|
|
59
|
+
if (opts.strictSchema === false) {
|
|
60
|
+
self.logger.warn(unknownMsg());
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
throw new Error(unknownMsg());
|
|
64
|
+
function unknownMsg() {
|
|
65
|
+
return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function getFormat(fmtDef) {
|
|
69
|
+
const code = fmtDef instanceof RegExp
|
|
70
|
+
? (0, codegen_1.regexpCode)(fmtDef)
|
|
71
|
+
: opts.code.formats
|
|
72
|
+
? (0, codegen_1._) `${opts.code.formats}${(0, codegen_1.getProperty)(schema)}`
|
|
73
|
+
: undefined;
|
|
74
|
+
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
|
|
75
|
+
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
|
|
76
|
+
return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._) `${fmt}.validate`];
|
|
77
|
+
}
|
|
78
|
+
return ["string", fmtDef, fmt];
|
|
79
|
+
}
|
|
80
|
+
function validCondition() {
|
|
81
|
+
if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
|
|
82
|
+
if (!schemaEnv.$async)
|
|
83
|
+
throw new Error("async format in sync schema");
|
|
84
|
+
return (0, codegen_1._) `await ${fmtRef}(${data})`;
|
|
85
|
+
}
|
|
86
|
+
return typeof format == "function" ? (0, codegen_1._) `${fmtRef}(${data})` : (0, codegen_1._) `${fmtRef}.test(${data})`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
exports.default = def;
|
|
92
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contentVocabulary = exports.metadataVocabulary = void 0;
|
|
4
|
+
exports.metadataVocabulary = [
|
|
5
|
+
"title",
|
|
6
|
+
"description",
|
|
7
|
+
"default",
|
|
8
|
+
"deprecated",
|
|
9
|
+
"readOnly",
|
|
10
|
+
"writeOnly",
|
|
11
|
+
"examples",
|
|
12
|
+
];
|
|
13
|
+
exports.contentVocabulary = [
|
|
14
|
+
"contentMediaType",
|
|
15
|
+
"contentEncoding",
|
|
16
|
+
"contentSchema",
|
|
17
|
+
];
|
|
18
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const util_1 = require('../../compile/util.js');
|
|
5
|
+
const equal_1 = require('../../runtime/equal.js');
|
|
6
|
+
const error = {
|
|
7
|
+
message: "must be equal to constant",
|
|
8
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{allowedValue: ${schemaCode}}`,
|
|
9
|
+
};
|
|
10
|
+
const def = {
|
|
11
|
+
keyword: "const",
|
|
12
|
+
$data: true,
|
|
13
|
+
error,
|
|
14
|
+
code(cxt) {
|
|
15
|
+
const { gen, data, $data, schemaCode, schema } = cxt;
|
|
16
|
+
if ($data || (schema && typeof schema == "object")) {
|
|
17
|
+
cxt.fail$data((0, codegen_1._) `!${(0, util_1.useFunc)(gen, equal_1.default)}(${data}, ${schemaCode})`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
cxt.fail((0, codegen_1._) `${schema} !== ${data}`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
exports.default = def;
|
|
25
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const util_1 = require('../../compile/util.js');
|
|
5
|
+
const equal_1 = require('../../runtime/equal.js');
|
|
6
|
+
const error = {
|
|
7
|
+
message: "must be equal to one of the allowed values",
|
|
8
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{allowedValues: ${schemaCode}}`,
|
|
9
|
+
};
|
|
10
|
+
const def = {
|
|
11
|
+
keyword: "enum",
|
|
12
|
+
schemaType: "array",
|
|
13
|
+
$data: true,
|
|
14
|
+
error,
|
|
15
|
+
code(cxt) {
|
|
16
|
+
const { gen, data, $data, schema, schemaCode, it } = cxt;
|
|
17
|
+
if (!$data && schema.length === 0)
|
|
18
|
+
throw new Error("enum must have non-empty array");
|
|
19
|
+
const useLoop = schema.length >= it.opts.loopEnum;
|
|
20
|
+
let eql;
|
|
21
|
+
const getEql = () => (eql !== null && eql !== void 0 ? eql : (eql = (0, util_1.useFunc)(gen, equal_1.default)));
|
|
22
|
+
let valid;
|
|
23
|
+
if (useLoop || $data) {
|
|
24
|
+
valid = gen.let("valid");
|
|
25
|
+
cxt.block$data(valid, loopEnum);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
/* istanbul ignore if */
|
|
29
|
+
if (!Array.isArray(schema))
|
|
30
|
+
throw new Error("ajv implementation error");
|
|
31
|
+
const vSchema = gen.const("vSchema", schemaCode);
|
|
32
|
+
valid = (0, codegen_1.or)(...schema.map((_x, i) => equalCode(vSchema, i)));
|
|
33
|
+
}
|
|
34
|
+
cxt.pass(valid);
|
|
35
|
+
function loopEnum() {
|
|
36
|
+
gen.assign(valid, false);
|
|
37
|
+
gen.forOf("v", schemaCode, (v) => gen.if((0, codegen_1._) `${getEql()}(${data}, ${v})`, () => gen.assign(valid, true).break()));
|
|
38
|
+
}
|
|
39
|
+
function equalCode(vSchema, i) {
|
|
40
|
+
const sch = schema[i];
|
|
41
|
+
return typeof sch === "object" && sch !== null
|
|
42
|
+
? (0, codegen_1._) `${getEql()}(${data}, ${vSchema}[${i}])`
|
|
43
|
+
: (0, codegen_1._) `${data} === ${sch}`;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
exports.default = def;
|
|
48
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const limitNumber_1 = require('./limitNumber.js');
|
|
4
|
+
const multipleOf_1 = require('./multipleOf.js');
|
|
5
|
+
const limitLength_1 = require('./limitLength.js');
|
|
6
|
+
const pattern_1 = require('./pattern.js');
|
|
7
|
+
const limitProperties_1 = require('./limitProperties.js');
|
|
8
|
+
const required_1 = require('./required.js');
|
|
9
|
+
const limitItems_1 = require('./limitItems.js');
|
|
10
|
+
const uniqueItems_1 = require('./uniqueItems.js');
|
|
11
|
+
const const_1 = require('./const.js');
|
|
12
|
+
const enum_1 = require('./enum.js');
|
|
13
|
+
const validation = [
|
|
14
|
+
// number
|
|
15
|
+
limitNumber_1.default,
|
|
16
|
+
multipleOf_1.default,
|
|
17
|
+
// string
|
|
18
|
+
limitLength_1.default,
|
|
19
|
+
pattern_1.default,
|
|
20
|
+
// object
|
|
21
|
+
limitProperties_1.default,
|
|
22
|
+
required_1.default,
|
|
23
|
+
// array
|
|
24
|
+
limitItems_1.default,
|
|
25
|
+
uniqueItems_1.default,
|
|
26
|
+
// any
|
|
27
|
+
{ keyword: "type", schemaType: ["string", "array"] },
|
|
28
|
+
{ keyword: "nullable", schemaType: "boolean" },
|
|
29
|
+
const_1.default,
|
|
30
|
+
enum_1.default,
|
|
31
|
+
];
|
|
32
|
+
exports.default = validation;
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const error = {
|
|
5
|
+
message({ keyword, schemaCode }) {
|
|
6
|
+
const comp = keyword === "maxItems" ? "more" : "fewer";
|
|
7
|
+
return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} items`;
|
|
8
|
+
},
|
|
9
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
|
|
10
|
+
};
|
|
11
|
+
const def = {
|
|
12
|
+
keyword: ["maxItems", "minItems"],
|
|
13
|
+
type: "array",
|
|
14
|
+
schemaType: "number",
|
|
15
|
+
$data: true,
|
|
16
|
+
error,
|
|
17
|
+
code(cxt) {
|
|
18
|
+
const { keyword, data, schemaCode } = cxt;
|
|
19
|
+
const op = keyword === "maxItems" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
20
|
+
cxt.fail$data((0, codegen_1._) `${data}.length ${op} ${schemaCode}`);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
exports.default = def;
|
|
24
|
+
//# sourceMappingURL=limitItems.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const util_1 = require('../../compile/util.js');
|
|
5
|
+
const ucs2length_1 = require('../../runtime/ucs2length.js');
|
|
6
|
+
const error = {
|
|
7
|
+
message({ keyword, schemaCode }) {
|
|
8
|
+
const comp = keyword === "maxLength" ? "more" : "fewer";
|
|
9
|
+
return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} characters`;
|
|
10
|
+
},
|
|
11
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
|
|
12
|
+
};
|
|
13
|
+
const def = {
|
|
14
|
+
keyword: ["maxLength", "minLength"],
|
|
15
|
+
type: "string",
|
|
16
|
+
schemaType: "number",
|
|
17
|
+
$data: true,
|
|
18
|
+
error,
|
|
19
|
+
code(cxt) {
|
|
20
|
+
const { keyword, data, schemaCode, it } = cxt;
|
|
21
|
+
const op = keyword === "maxLength" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
22
|
+
const len = it.opts.unicode === false ? (0, codegen_1._) `${data}.length` : (0, codegen_1._) `${(0, util_1.useFunc)(cxt.gen, ucs2length_1.default)}(${data})`;
|
|
23
|
+
cxt.fail$data((0, codegen_1._) `${len} ${op} ${schemaCode}`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
exports.default = def;
|
|
27
|
+
//# sourceMappingURL=limitLength.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const ops = codegen_1.operators;
|
|
5
|
+
const KWDs = {
|
|
6
|
+
maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
|
|
7
|
+
minimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
|
|
8
|
+
exclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
|
|
9
|
+
exclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE },
|
|
10
|
+
};
|
|
11
|
+
const error = {
|
|
12
|
+
message: ({ keyword, schemaCode }) => (0, codegen_1.str) `must be ${KWDs[keyword].okStr} ${schemaCode}`,
|
|
13
|
+
params: ({ keyword, schemaCode }) => (0, codegen_1._) `{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`,
|
|
14
|
+
};
|
|
15
|
+
const def = {
|
|
16
|
+
keyword: Object.keys(KWDs),
|
|
17
|
+
type: "number",
|
|
18
|
+
schemaType: "number",
|
|
19
|
+
$data: true,
|
|
20
|
+
error,
|
|
21
|
+
code(cxt) {
|
|
22
|
+
const { keyword, data, schemaCode } = cxt;
|
|
23
|
+
cxt.fail$data((0, codegen_1._) `${data} ${KWDs[keyword].fail} ${schemaCode} || isNaN(${data})`);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
exports.default = def;
|
|
27
|
+
//# sourceMappingURL=limitNumber.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const error = {
|
|
5
|
+
message({ keyword, schemaCode }) {
|
|
6
|
+
const comp = keyword === "maxProperties" ? "more" : "fewer";
|
|
7
|
+
return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} properties`;
|
|
8
|
+
},
|
|
9
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
|
|
10
|
+
};
|
|
11
|
+
const def = {
|
|
12
|
+
keyword: ["maxProperties", "minProperties"],
|
|
13
|
+
type: "object",
|
|
14
|
+
schemaType: "number",
|
|
15
|
+
$data: true,
|
|
16
|
+
error,
|
|
17
|
+
code(cxt) {
|
|
18
|
+
const { keyword, data, schemaCode } = cxt;
|
|
19
|
+
const op = keyword === "maxProperties" ? codegen_1.operators.GT : codegen_1.operators.LT;
|
|
20
|
+
cxt.fail$data((0, codegen_1._) `Object.keys(${data}).length ${op} ${schemaCode}`);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
exports.default = def;
|
|
24
|
+
//# sourceMappingURL=limitProperties.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
4
|
+
const error = {
|
|
5
|
+
message: ({ schemaCode }) => (0, codegen_1.str) `must be multiple of ${schemaCode}`,
|
|
6
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{multipleOf: ${schemaCode}}`,
|
|
7
|
+
};
|
|
8
|
+
const def = {
|
|
9
|
+
keyword: "multipleOf",
|
|
10
|
+
type: "number",
|
|
11
|
+
schemaType: "number",
|
|
12
|
+
$data: true,
|
|
13
|
+
error,
|
|
14
|
+
code(cxt) {
|
|
15
|
+
const { gen, data, schemaCode, it } = cxt;
|
|
16
|
+
// const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
|
|
17
|
+
const prec = it.opts.multipleOfPrecision;
|
|
18
|
+
const res = gen.let("res");
|
|
19
|
+
const invalid = prec
|
|
20
|
+
? (0, codegen_1._) `Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}`
|
|
21
|
+
: (0, codegen_1._) `${res} !== parseInt(${res})`;
|
|
22
|
+
cxt.fail$data((0, codegen_1._) `(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid}))`);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.default = def;
|
|
26
|
+
//# sourceMappingURL=multipleOf.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const code_1 = require('../code.js');
|
|
4
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
5
|
+
const error = {
|
|
6
|
+
message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
|
|
7
|
+
params: ({ schemaCode }) => (0, codegen_1._) `{pattern: ${schemaCode}}`,
|
|
8
|
+
};
|
|
9
|
+
const def = {
|
|
10
|
+
keyword: "pattern",
|
|
11
|
+
type: "string",
|
|
12
|
+
schemaType: "string",
|
|
13
|
+
$data: true,
|
|
14
|
+
error,
|
|
15
|
+
code(cxt) {
|
|
16
|
+
const { data, $data, schema, schemaCode, it } = cxt;
|
|
17
|
+
// TODO regexp should be wrapped in try/catchs
|
|
18
|
+
const u = it.opts.unicodeRegExp ? "u" : "";
|
|
19
|
+
const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
|
|
20
|
+
cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
exports.default = def;
|
|
24
|
+
//# sourceMappingURL=pattern.js.map
|