@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,79 @@
|
|
|
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 util_1 = require('../../compile/util.js');
|
|
6
|
+
const error = {
|
|
7
|
+
message: ({ params: { missingProperty } }) => (0, codegen_1.str) `must have required property '${missingProperty}'`,
|
|
8
|
+
params: ({ params: { missingProperty } }) => (0, codegen_1._) `{missingProperty: ${missingProperty}}`,
|
|
9
|
+
};
|
|
10
|
+
const def = {
|
|
11
|
+
keyword: "required",
|
|
12
|
+
type: "object",
|
|
13
|
+
schemaType: "array",
|
|
14
|
+
$data: true,
|
|
15
|
+
error,
|
|
16
|
+
code(cxt) {
|
|
17
|
+
const { gen, schema, schemaCode, data, $data, it } = cxt;
|
|
18
|
+
const { opts } = it;
|
|
19
|
+
if (!$data && schema.length === 0)
|
|
20
|
+
return;
|
|
21
|
+
const useLoop = schema.length >= opts.loopRequired;
|
|
22
|
+
if (it.allErrors)
|
|
23
|
+
allErrorsMode();
|
|
24
|
+
else
|
|
25
|
+
exitOnErrorMode();
|
|
26
|
+
if (opts.strictRequired) {
|
|
27
|
+
const props = cxt.parentSchema.properties;
|
|
28
|
+
const { definedProperties } = cxt.it;
|
|
29
|
+
for (const requiredKey of schema) {
|
|
30
|
+
if ((props === null || props === void 0 ? void 0 : props[requiredKey]) === undefined && !definedProperties.has(requiredKey)) {
|
|
31
|
+
const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
|
|
32
|
+
const msg = `required property "${requiredKey}" is not defined at "${schemaPath}" (strictRequired)`;
|
|
33
|
+
(0, util_1.checkStrictMode)(it, msg, it.opts.strictRequired);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function allErrorsMode() {
|
|
38
|
+
if (useLoop || $data) {
|
|
39
|
+
cxt.block$data(codegen_1.nil, loopAllRequired);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
for (const prop of schema) {
|
|
43
|
+
(0, code_1.checkReportMissingProp)(cxt, prop);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function exitOnErrorMode() {
|
|
48
|
+
const missing = gen.let("missing");
|
|
49
|
+
if (useLoop || $data) {
|
|
50
|
+
const valid = gen.let("valid", true);
|
|
51
|
+
cxt.block$data(valid, () => loopUntilMissing(missing, valid));
|
|
52
|
+
cxt.ok(valid);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
gen.if((0, code_1.checkMissingProp)(cxt, schema, missing));
|
|
56
|
+
(0, code_1.reportMissingProp)(cxt, missing);
|
|
57
|
+
gen.else();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function loopAllRequired() {
|
|
61
|
+
gen.forOf("prop", schemaCode, (prop) => {
|
|
62
|
+
cxt.setParams({ missingProperty: prop });
|
|
63
|
+
gen.if((0, code_1.noPropertyInData)(gen, data, prop, opts.ownProperties), () => cxt.error());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function loopUntilMissing(missing, valid) {
|
|
67
|
+
cxt.setParams({ missingProperty: missing });
|
|
68
|
+
gen.forOf(missing, schemaCode, () => {
|
|
69
|
+
gen.assign(valid, (0, code_1.propertyInData)(gen, data, missing, opts.ownProperties));
|
|
70
|
+
gen.if((0, codegen_1.not)(valid), () => {
|
|
71
|
+
cxt.error();
|
|
72
|
+
gen.break();
|
|
73
|
+
});
|
|
74
|
+
}, codegen_1.nil);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
exports.default = def;
|
|
79
|
+
//# sourceMappingURL=required.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dataType_1 = require('../../compile/validate/dataType.js');
|
|
4
|
+
const codegen_1 = require('../../compile/codegen/index.js');
|
|
5
|
+
const util_1 = require('../../compile/util.js');
|
|
6
|
+
const equal_1 = require('../../runtime/equal.js');
|
|
7
|
+
const error = {
|
|
8
|
+
message: ({ params: { i, j } }) => (0, codegen_1.str) `must NOT have duplicate items (items ## ${j} and ${i} are identical)`,
|
|
9
|
+
params: ({ params: { i, j } }) => (0, codegen_1._) `{i: ${i}, j: ${j}}`,
|
|
10
|
+
};
|
|
11
|
+
const def = {
|
|
12
|
+
keyword: "uniqueItems",
|
|
13
|
+
type: "array",
|
|
14
|
+
schemaType: "boolean",
|
|
15
|
+
$data: true,
|
|
16
|
+
error,
|
|
17
|
+
code(cxt) {
|
|
18
|
+
const { gen, data, $data, schema, parentSchema, schemaCode, it } = cxt;
|
|
19
|
+
if (!$data && !schema)
|
|
20
|
+
return;
|
|
21
|
+
const valid = gen.let("valid");
|
|
22
|
+
const itemTypes = parentSchema.items ? (0, dataType_1.getSchemaTypes)(parentSchema.items) : [];
|
|
23
|
+
cxt.block$data(valid, validateUniqueItems, (0, codegen_1._) `${schemaCode} === false`);
|
|
24
|
+
cxt.ok(valid);
|
|
25
|
+
function validateUniqueItems() {
|
|
26
|
+
const i = gen.let("i", (0, codegen_1._) `${data}.length`);
|
|
27
|
+
const j = gen.let("j");
|
|
28
|
+
cxt.setParams({ i, j });
|
|
29
|
+
gen.assign(valid, true);
|
|
30
|
+
gen.if((0, codegen_1._) `${i} > 1`, () => (canOptimize() ? loopN : loopN2)(i, j));
|
|
31
|
+
}
|
|
32
|
+
function canOptimize() {
|
|
33
|
+
return itemTypes.length > 0 && !itemTypes.some((t) => t === "object" || t === "array");
|
|
34
|
+
}
|
|
35
|
+
function loopN(i, j) {
|
|
36
|
+
const item = gen.name("item");
|
|
37
|
+
const wrongType = (0, dataType_1.checkDataTypes)(itemTypes, item, it.opts.strictNumbers, dataType_1.DataType.Wrong);
|
|
38
|
+
const indices = gen.const("indices", (0, codegen_1._) `{}`);
|
|
39
|
+
gen.for((0, codegen_1._) `;${i}--;`, () => {
|
|
40
|
+
gen.let(item, (0, codegen_1._) `${data}[${i}]`);
|
|
41
|
+
gen.if(wrongType, (0, codegen_1._) `continue`);
|
|
42
|
+
if (itemTypes.length > 1)
|
|
43
|
+
gen.if((0, codegen_1._) `typeof ${item} == "string"`, (0, codegen_1._) `${item} += "_"`);
|
|
44
|
+
gen
|
|
45
|
+
.if((0, codegen_1._) `typeof ${indices}[${item}] == "number"`, () => {
|
|
46
|
+
gen.assign(j, (0, codegen_1._) `${indices}[${item}]`);
|
|
47
|
+
cxt.error();
|
|
48
|
+
gen.assign(valid, false).break();
|
|
49
|
+
})
|
|
50
|
+
.code((0, codegen_1._) `${indices}[${item}] = ${i}`);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function loopN2(i, j) {
|
|
54
|
+
const eql = (0, util_1.useFunc)(gen, equal_1.default);
|
|
55
|
+
const outer = gen.name("outer");
|
|
56
|
+
gen.label(outer).for((0, codegen_1._) `;${i}--;`, () => gen.for((0, codegen_1._) `${j} = ${i}; ${j}--;`, () => gen.if((0, codegen_1._) `${eql}(${data}[${i}], ${data}[${j}])`, () => {
|
|
57
|
+
cxt.error();
|
|
58
|
+
gen.assign(valid, false).break(outer);
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
exports.default = def;
|
|
64
|
+
//# sourceMappingURL=uniqueItems.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatNames = exports.fastFormats = exports.fullFormats = void 0;
|
|
4
|
+
function fmtDef(validate, compare) {
|
|
5
|
+
return { validate, compare };
|
|
6
|
+
}
|
|
7
|
+
exports.fullFormats = {
|
|
8
|
+
// date: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
9
|
+
date: fmtDef(date, compareDate),
|
|
10
|
+
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
11
|
+
time: fmtDef(time, compareTime),
|
|
12
|
+
"date-time": fmtDef(date_time, compareDateTime),
|
|
13
|
+
// duration: https://tools.ietf.org/html/rfc3339#appendix-A
|
|
14
|
+
duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
|
|
15
|
+
uri,
|
|
16
|
+
"uri-reference": /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
|
|
17
|
+
// uri-template: https://tools.ietf.org/html/rfc6570
|
|
18
|
+
"uri-template": /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,
|
|
19
|
+
// For the source: https://gist.github.com/dperini/729294
|
|
20
|
+
// For test cases: https://mathiasbynens.be/demo/url-regex
|
|
21
|
+
url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,
|
|
22
|
+
email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
|
|
23
|
+
hostname: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,
|
|
24
|
+
// optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
|
|
25
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
|
|
26
|
+
ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,
|
|
27
|
+
regex,
|
|
28
|
+
// uuid: http://tools.ietf.org/html/rfc4122
|
|
29
|
+
uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
|
|
30
|
+
// JSON-pointer: https://tools.ietf.org/html/rfc6901
|
|
31
|
+
// uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
|
|
32
|
+
"json-pointer": /^(?:\/(?:[^~/]|~0|~1)*)*$/,
|
|
33
|
+
"json-pointer-uri-fragment": /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,
|
|
34
|
+
// relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
|
|
35
|
+
"relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
|
|
36
|
+
// the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types
|
|
37
|
+
// byte: https://github.com/miguelmota/is-base64
|
|
38
|
+
byte,
|
|
39
|
+
// signed 32 bit integer
|
|
40
|
+
int32: { type: "number", validate: validateInt32 },
|
|
41
|
+
// signed 64 bit integer
|
|
42
|
+
int64: { type: "number", validate: validateInt64 },
|
|
43
|
+
// C-type float
|
|
44
|
+
float: { type: "number", validate: validateNumber },
|
|
45
|
+
// C-type double
|
|
46
|
+
double: { type: "number", validate: validateNumber },
|
|
47
|
+
// hint to the UI to hide input strings
|
|
48
|
+
password: true,
|
|
49
|
+
// unchecked string payload
|
|
50
|
+
binary: true,
|
|
51
|
+
};
|
|
52
|
+
exports.fastFormats = {
|
|
53
|
+
...exports.fullFormats,
|
|
54
|
+
date: fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d$/, compareDate),
|
|
55
|
+
time: fmtDef(/^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)?$/i, compareTime),
|
|
56
|
+
"date-time": fmtDef(/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i, compareDateTime),
|
|
57
|
+
// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
|
|
58
|
+
uri: /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i,
|
|
59
|
+
"uri-reference": /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i,
|
|
60
|
+
// email (sources from jsen validator):
|
|
61
|
+
// http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
|
|
62
|
+
// http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'wilful violation')
|
|
63
|
+
email: /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
|
|
64
|
+
};
|
|
65
|
+
exports.formatNames = Object.keys(exports.fullFormats);
|
|
66
|
+
function isLeapYear(year) {
|
|
67
|
+
// https://tools.ietf.org/html/rfc3339#appendix-C
|
|
68
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
69
|
+
}
|
|
70
|
+
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
|
|
71
|
+
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
72
|
+
function date(str) {
|
|
73
|
+
// full-date from http://tools.ietf.org/html/rfc3339#section-5.6
|
|
74
|
+
const matches = DATE.exec(str);
|
|
75
|
+
if (!matches)
|
|
76
|
+
return false;
|
|
77
|
+
const year = +matches[1];
|
|
78
|
+
const month = +matches[2];
|
|
79
|
+
const day = +matches[3];
|
|
80
|
+
return (month >= 1 &&
|
|
81
|
+
month <= 12 &&
|
|
82
|
+
day >= 1 &&
|
|
83
|
+
day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]));
|
|
84
|
+
}
|
|
85
|
+
function compareDate(d1, d2) {
|
|
86
|
+
if (!(d1 && d2))
|
|
87
|
+
return undefined;
|
|
88
|
+
if (d1 > d2)
|
|
89
|
+
return 1;
|
|
90
|
+
if (d1 < d2)
|
|
91
|
+
return -1;
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
const TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i;
|
|
95
|
+
function time(str, withTimeZone) {
|
|
96
|
+
const matches = TIME.exec(str);
|
|
97
|
+
if (!matches)
|
|
98
|
+
return false;
|
|
99
|
+
const hour = +matches[1];
|
|
100
|
+
const minute = +matches[2];
|
|
101
|
+
const second = +matches[3];
|
|
102
|
+
const timeZone = matches[5];
|
|
103
|
+
return (((hour <= 23 && minute <= 59 && second <= 59) ||
|
|
104
|
+
(hour === 23 && minute === 59 && second === 60)) &&
|
|
105
|
+
(!withTimeZone || timeZone !== ""));
|
|
106
|
+
}
|
|
107
|
+
function compareTime(t1, t2) {
|
|
108
|
+
if (!(t1 && t2))
|
|
109
|
+
return undefined;
|
|
110
|
+
const a1 = TIME.exec(t1);
|
|
111
|
+
const a2 = TIME.exec(t2);
|
|
112
|
+
if (!(a1 && a2))
|
|
113
|
+
return undefined;
|
|
114
|
+
t1 = a1[1] + a1[2] + a1[3] + (a1[4] || "");
|
|
115
|
+
t2 = a2[1] + a2[2] + a2[3] + (a2[4] || "");
|
|
116
|
+
if (t1 > t2)
|
|
117
|
+
return 1;
|
|
118
|
+
if (t1 < t2)
|
|
119
|
+
return -1;
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
const DATE_TIME_SEPARATOR = /t|\s/i;
|
|
123
|
+
function date_time(str) {
|
|
124
|
+
// http://tools.ietf.org/html/rfc3339#section-5.6
|
|
125
|
+
const dateTime = str.split(DATE_TIME_SEPARATOR);
|
|
126
|
+
return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1], true);
|
|
127
|
+
}
|
|
128
|
+
function compareDateTime(dt1, dt2) {
|
|
129
|
+
if (!(dt1 && dt2))
|
|
130
|
+
return undefined;
|
|
131
|
+
const [d1, t1] = dt1.split(DATE_TIME_SEPARATOR);
|
|
132
|
+
const [d2, t2] = dt2.split(DATE_TIME_SEPARATOR);
|
|
133
|
+
const res = compareDate(d1, d2);
|
|
134
|
+
if (res === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
return res || compareTime(t1, t2);
|
|
137
|
+
}
|
|
138
|
+
const NOT_URI_FRAGMENT = /\/|:/;
|
|
139
|
+
const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
|
|
140
|
+
function uri(str) {
|
|
141
|
+
// http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
|
|
142
|
+
return NOT_URI_FRAGMENT.test(str) && URI.test(str);
|
|
143
|
+
}
|
|
144
|
+
const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
|
|
145
|
+
function byte(str) {
|
|
146
|
+
BYTE.lastIndex = 0;
|
|
147
|
+
return BYTE.test(str);
|
|
148
|
+
}
|
|
149
|
+
const MIN_INT32 = -(2 ** 31);
|
|
150
|
+
const MAX_INT32 = 2 ** 31 - 1;
|
|
151
|
+
function validateInt32(value) {
|
|
152
|
+
return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32;
|
|
153
|
+
}
|
|
154
|
+
function validateInt64(value) {
|
|
155
|
+
// JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64
|
|
156
|
+
return Number.isInteger(value);
|
|
157
|
+
}
|
|
158
|
+
function validateNumber() {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
const Z_ANCHOR = /[^\\]\\Z/;
|
|
162
|
+
function regex(str) {
|
|
163
|
+
if (Z_ANCHOR.test(str))
|
|
164
|
+
return false;
|
|
165
|
+
try {
|
|
166
|
+
new RegExp(str);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=formats.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const formats_1 = require('./formats.js');
|
|
4
|
+
const limit_1 = require('./limit.js');
|
|
5
|
+
const codegen_1 = require('../../ajv/dist/compile/codegen/index.js');
|
|
6
|
+
const fullName = new codegen_1.Name("fullFormats");
|
|
7
|
+
const fastName = new codegen_1.Name("fastFormats");
|
|
8
|
+
const formatsPlugin = (ajv, opts = { keywords: true }) => {
|
|
9
|
+
if (Array.isArray(opts)) {
|
|
10
|
+
addFormats(ajv, opts, formats_1.fullFormats, fullName);
|
|
11
|
+
return ajv;
|
|
12
|
+
}
|
|
13
|
+
const [formats, exportName] = opts.mode === "fast" ? [formats_1.fastFormats, fastName] : [formats_1.fullFormats, fullName];
|
|
14
|
+
const list = opts.formats || formats_1.formatNames;
|
|
15
|
+
addFormats(ajv, list, formats, exportName);
|
|
16
|
+
if (opts.keywords)
|
|
17
|
+
limit_1.default(ajv);
|
|
18
|
+
return ajv;
|
|
19
|
+
};
|
|
20
|
+
formatsPlugin.get = (name, mode = "full") => {
|
|
21
|
+
const formats = mode === "fast" ? formats_1.fastFormats : formats_1.fullFormats;
|
|
22
|
+
const f = formats[name];
|
|
23
|
+
if (!f)
|
|
24
|
+
throw new Error(`Unknown format "${name}"`);
|
|
25
|
+
return f;
|
|
26
|
+
};
|
|
27
|
+
function addFormats(ajv, list, fs, exportName) {
|
|
28
|
+
var _a;
|
|
29
|
+
var _b;
|
|
30
|
+
(_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : (_b.formats = codegen_1._ `require("ajv-formats/dist/formats").${exportName}`);
|
|
31
|
+
for (const f of list)
|
|
32
|
+
ajv.addFormat(f, fs[f]);
|
|
33
|
+
}
|
|
34
|
+
module.exports = exports = formatsPlugin;
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.default = formatsPlugin;
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatLimitDefinition = void 0;
|
|
4
|
+
const ajv_1 = require('../../ajv/dist/ajv.js');
|
|
5
|
+
const codegen_1 = require('../../ajv/dist/compile/codegen/index.js');
|
|
6
|
+
const ops = codegen_1.operators;
|
|
7
|
+
const KWDs = {
|
|
8
|
+
formatMaximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
|
|
9
|
+
formatMinimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
|
|
10
|
+
formatExclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
|
|
11
|
+
formatExclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE },
|
|
12
|
+
};
|
|
13
|
+
const error = {
|
|
14
|
+
message: ({ keyword, schemaCode }) => codegen_1.str `should be ${KWDs[keyword].okStr} ${schemaCode}`,
|
|
15
|
+
params: ({ keyword, schemaCode }) => codegen_1._ `{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`,
|
|
16
|
+
};
|
|
17
|
+
exports.formatLimitDefinition = {
|
|
18
|
+
keyword: Object.keys(KWDs),
|
|
19
|
+
type: "string",
|
|
20
|
+
schemaType: "string",
|
|
21
|
+
$data: true,
|
|
22
|
+
error,
|
|
23
|
+
code(cxt) {
|
|
24
|
+
const { gen, data, schemaCode, keyword, it } = cxt;
|
|
25
|
+
const { opts, self } = it;
|
|
26
|
+
if (!opts.validateFormats)
|
|
27
|
+
return;
|
|
28
|
+
const fCxt = new ajv_1.KeywordCxt(it, self.RULES.all.format.definition, "format");
|
|
29
|
+
if (fCxt.$data)
|
|
30
|
+
validate$DataFormat();
|
|
31
|
+
else
|
|
32
|
+
validateFormat();
|
|
33
|
+
function validate$DataFormat() {
|
|
34
|
+
const fmts = gen.scopeValue("formats", {
|
|
35
|
+
ref: self.formats,
|
|
36
|
+
code: opts.code.formats,
|
|
37
|
+
});
|
|
38
|
+
const fmt = gen.const("fmt", codegen_1._ `${fmts}[${fCxt.schemaCode}]`);
|
|
39
|
+
cxt.fail$data(codegen_1.or(codegen_1._ `typeof ${fmt} != "object"`, codegen_1._ `${fmt} instanceof RegExp`, codegen_1._ `typeof ${fmt}.compare != "function"`, compareCode(fmt)));
|
|
40
|
+
}
|
|
41
|
+
function validateFormat() {
|
|
42
|
+
const format = fCxt.schema;
|
|
43
|
+
const fmtDef = self.formats[format];
|
|
44
|
+
if (!fmtDef || fmtDef === true)
|
|
45
|
+
return;
|
|
46
|
+
if (typeof fmtDef != "object" ||
|
|
47
|
+
fmtDef instanceof RegExp ||
|
|
48
|
+
typeof fmtDef.compare != "function") {
|
|
49
|
+
throw new Error(`"${keyword}": format "${format}" does not define "compare" function`);
|
|
50
|
+
}
|
|
51
|
+
const fmt = gen.scopeValue("formats", {
|
|
52
|
+
key: format,
|
|
53
|
+
ref: fmtDef,
|
|
54
|
+
code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(format)}` : undefined,
|
|
55
|
+
});
|
|
56
|
+
cxt.fail$data(compareCode(fmt));
|
|
57
|
+
}
|
|
58
|
+
function compareCode(fmt) {
|
|
59
|
+
return codegen_1._ `${fmt}.compare(${data}, ${schemaCode}) ${KWDs[keyword].fail} 0`;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
dependencies: ["format"],
|
|
63
|
+
};
|
|
64
|
+
const formatLimitPlugin = (ajv) => {
|
|
65
|
+
ajv.addKeyword(exports.formatLimitDefinition);
|
|
66
|
+
return ajv;
|
|
67
|
+
};
|
|
68
|
+
exports.default = formatLimitPlugin;
|
|
69
|
+
//# sourceMappingURL=limit.js.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
module.exports = function localize_zh(errors) {
|
|
3
|
+
if (!(errors && errors.length)) return
|
|
4
|
+
for (const e of errors) {
|
|
5
|
+
let out
|
|
6
|
+
switch (e.keyword) {
|
|
7
|
+
case "additionalItems":
|
|
8
|
+
case "items":
|
|
9
|
+
out = ""
|
|
10
|
+
var n = e.params.limit
|
|
11
|
+
out += "不允许超过" + n + "个元素"
|
|
12
|
+
break
|
|
13
|
+
case "additionalProperties":
|
|
14
|
+
out = "不允许有额外的属性"
|
|
15
|
+
break
|
|
16
|
+
case "anyOf":
|
|
17
|
+
out = "数据应为 anyOf 所指定的其中一个"
|
|
18
|
+
break
|
|
19
|
+
case "const":
|
|
20
|
+
out = "应当等于常量"
|
|
21
|
+
break
|
|
22
|
+
case "contains":
|
|
23
|
+
out = "应当包含一个有效项"
|
|
24
|
+
break
|
|
25
|
+
case "dependencies":
|
|
26
|
+
case "dependentRequired":
|
|
27
|
+
out = ""
|
|
28
|
+
var n = e.params.depsCount
|
|
29
|
+
out += "应当拥有属性" + e.params.property + "的依赖属性" + e.params.deps
|
|
30
|
+
break
|
|
31
|
+
case "discriminator":
|
|
32
|
+
switch (e.params.error) {
|
|
33
|
+
case "tag":
|
|
34
|
+
out = '标签 "' + e.params.tag + '" 的类型必须为字符串'
|
|
35
|
+
break
|
|
36
|
+
case "mapping":
|
|
37
|
+
out = '标签 "' + e.params.tag + '" 的值必须在 oneOf 之中'
|
|
38
|
+
break
|
|
39
|
+
default:
|
|
40
|
+
out = '应当通过 "' + e.keyword + ' 关键词校验"'
|
|
41
|
+
}
|
|
42
|
+
break
|
|
43
|
+
case "enum":
|
|
44
|
+
out = "应当是预设定的枚举值之一"
|
|
45
|
+
break
|
|
46
|
+
case "false schema":
|
|
47
|
+
out = "布尔模式出错"
|
|
48
|
+
break
|
|
49
|
+
case "format":
|
|
50
|
+
out = '应当匹配格式 "' + e.params.format + '"'
|
|
51
|
+
break
|
|
52
|
+
case "formatMaximum":
|
|
53
|
+
case "formatExclusiveMaximum":
|
|
54
|
+
out = ""
|
|
55
|
+
var cond = e.params.comparison + " " + e.params.limit
|
|
56
|
+
out += "应当是 " + cond
|
|
57
|
+
break
|
|
58
|
+
case "formatMinimum":
|
|
59
|
+
case "formatExclusiveMinimum":
|
|
60
|
+
out = ""
|
|
61
|
+
var cond = e.params.comparison + " " + e.params.limit
|
|
62
|
+
out += "应当是 " + cond
|
|
63
|
+
break
|
|
64
|
+
case "if":
|
|
65
|
+
out = '应当匹配模式 "' + e.params.failingKeyword + '" '
|
|
66
|
+
break
|
|
67
|
+
case "maximum":
|
|
68
|
+
case "exclusiveMaximum":
|
|
69
|
+
out = ""
|
|
70
|
+
var cond = e.params.comparison + " " + e.params.limit
|
|
71
|
+
out += "应当为 " + cond
|
|
72
|
+
break
|
|
73
|
+
case "maxItems":
|
|
74
|
+
out = ""
|
|
75
|
+
var n = e.params.limit
|
|
76
|
+
out += "不应多于 " + n + " 个项"
|
|
77
|
+
break
|
|
78
|
+
case "maxLength":
|
|
79
|
+
out = ""
|
|
80
|
+
var n = e.params.limit
|
|
81
|
+
out += "不应多于 " + n + " 个字符"
|
|
82
|
+
break
|
|
83
|
+
case "maxProperties":
|
|
84
|
+
out = ""
|
|
85
|
+
var n = e.params.limit
|
|
86
|
+
out += "不应有多于 " + n + " 个属性"
|
|
87
|
+
break
|
|
88
|
+
case "minimum":
|
|
89
|
+
case "exclusiveMinimum":
|
|
90
|
+
out = ""
|
|
91
|
+
var cond = e.params.comparison + " " + e.params.limit
|
|
92
|
+
out += "应当为 " + cond
|
|
93
|
+
break
|
|
94
|
+
case "minItems":
|
|
95
|
+
out = ""
|
|
96
|
+
var n = e.params.limit
|
|
97
|
+
out += "不应少于 " + n + " 个项"
|
|
98
|
+
break
|
|
99
|
+
case "minLength":
|
|
100
|
+
out = ""
|
|
101
|
+
var n = e.params.limit
|
|
102
|
+
out += "不应少于 " + n + " 个字符"
|
|
103
|
+
break
|
|
104
|
+
case "minProperties":
|
|
105
|
+
out = ""
|
|
106
|
+
var n = e.params.limit
|
|
107
|
+
out += "不应有少于 " + n + " 个属性"
|
|
108
|
+
break
|
|
109
|
+
case "multipleOf":
|
|
110
|
+
out = "应当是 " + e.params.multipleOf + " 的整数倍"
|
|
111
|
+
break
|
|
112
|
+
case "not":
|
|
113
|
+
out = '不应当匹配 "not" schema'
|
|
114
|
+
break
|
|
115
|
+
case "oneOf":
|
|
116
|
+
out = '只能匹配一个 "oneOf" 中的 schema'
|
|
117
|
+
break
|
|
118
|
+
case "pattern":
|
|
119
|
+
out = '应当匹配模式 "' + e.params.pattern + '"'
|
|
120
|
+
break
|
|
121
|
+
case "patternRequired":
|
|
122
|
+
out = "应当有属性匹配模式 " + e.params.missingPattern
|
|
123
|
+
break
|
|
124
|
+
case "propertyNames":
|
|
125
|
+
out = "属性名 无效"
|
|
126
|
+
break
|
|
127
|
+
case "required":
|
|
128
|
+
out = "应当有必需属性 " + e.params.missingProperty
|
|
129
|
+
break
|
|
130
|
+
case "type":
|
|
131
|
+
out = "应当是 " + e.params.type + " 类型"
|
|
132
|
+
break
|
|
133
|
+
case "unevaluatedItems":
|
|
134
|
+
out = ""
|
|
135
|
+
var n = e.params.len
|
|
136
|
+
out += " 不允许有超过 " + n + " 个元素"
|
|
137
|
+
break
|
|
138
|
+
case "unevaluatedProperties":
|
|
139
|
+
out = "不允许存在未求值的属性"
|
|
140
|
+
break
|
|
141
|
+
case "uniqueItems":
|
|
142
|
+
out =
|
|
143
|
+
"不应当含有重复项 (第 " +
|
|
144
|
+
e.params.j +
|
|
145
|
+
" 项与第 " +
|
|
146
|
+
e.params.i +
|
|
147
|
+
" 项是重复的)"
|
|
148
|
+
break
|
|
149
|
+
default:
|
|
150
|
+
out = '应当通过 "' + e.keyword + ' 关键词校验"'
|
|
151
|
+
}
|
|
152
|
+
e.message = out
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// do not edit .js files directly - edit src/index.jst
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = function equal(a, b) {
|
|
8
|
+
if (a === b) return true;
|
|
9
|
+
|
|
10
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
11
|
+
if (a.constructor !== b.constructor) return false;
|
|
12
|
+
|
|
13
|
+
var length, i, keys;
|
|
14
|
+
if (Array.isArray(a)) {
|
|
15
|
+
length = a.length;
|
|
16
|
+
if (length != b.length) return false;
|
|
17
|
+
for (i = length; i-- !== 0;)
|
|
18
|
+
if (!equal(a[i], b[i])) return false;
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
25
|
+
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
26
|
+
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
27
|
+
|
|
28
|
+
keys = Object.keys(a);
|
|
29
|
+
length = keys.length;
|
|
30
|
+
if (length !== Object.keys(b).length) return false;
|
|
31
|
+
|
|
32
|
+
for (i = length; i-- !== 0;)
|
|
33
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
34
|
+
|
|
35
|
+
for (i = length; i-- !== 0;) {
|
|
36
|
+
var key = keys[i];
|
|
37
|
+
|
|
38
|
+
if (!equal(a[key], b[key])) return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// true if both NaN, false otherwise
|
|
45
|
+
return a!==a && b!==b;
|
|
46
|
+
};
|