@blueking/bkui-form 1.0.1-beta.2 → 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.
Files changed (168) hide show
  1. package/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
  2. package/esm/adapter/field/ArrayField.tsx.js +55 -0
  3. package/esm/adapter/field/BooleanField.tsx.js +41 -0
  4. package/esm/adapter/field/CompositionField.tsx.js +113 -0
  5. package/esm/adapter/field/FieldProps.ts.js +85 -0
  6. package/esm/adapter/field/NumberField.tsx.js +19 -0
  7. package/esm/adapter/field/ObjectField.tsx.js +58 -0
  8. package/esm/adapter/field/SchemaField.tsx.js +28 -0
  9. package/esm/adapter/field/StringField.tsx.js +4 -0
  10. package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
  11. package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
  12. package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
  13. package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
  14. package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
  15. package/esm/adapter/widget/InputWidget.ts.js +79 -0
  16. package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
  17. package/esm/adapter/widget/RadioWidget.ts.js +98 -0
  18. package/esm/adapter/widget/SelectWidget.ts.js +98 -0
  19. package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
  20. package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
  21. package/esm/adapter/widget/TableWidget.ts.js +205 -0
  22. package/esm/adapter/widget/Widget.ts.js +497 -0
  23. package/esm/assets/fonts/iconcool.eot +0 -0
  24. package/esm/assets/fonts/iconcool.ttf +0 -0
  25. package/esm/assets/fonts/iconcool.woff +0 -0
  26. package/esm/assets/style.css +43 -0
  27. package/esm/controller/form.css +164 -0
  28. package/esm/controller/form.tsx.js +159 -0
  29. package/esm/controller/props.ts.js +75 -0
  30. package/esm/core/events.ts.js +74 -0
  31. package/esm/core/expression.ts.js +67 -0
  32. package/esm/core/lang.ts.js +25 -0
  33. package/esm/core/layout.ts.js +149 -0
  34. package/esm/core/path.ts.js +60 -0
  35. package/esm/core/proxy.ts.js +10 -0
  36. package/esm/core/reaction.ts.js +116 -0
  37. package/esm/core/register.ts.js +74 -0
  38. package/esm/core/schema.ts.js +302 -0
  39. package/esm/core/validator.ts.js +248 -0
  40. package/esm/core/widgetTree.ts.js +163 -0
  41. package/esm/index.ts.js +6 -0
  42. package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
  43. package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
  44. package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
  45. package/esm/node_modules/ajv/dist/ajv.js +50 -0
  46. package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
  47. package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
  48. package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
  49. package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
  50. package/esm/node_modules/ajv/dist/compile/index.js +242 -0
  51. package/esm/node_modules/ajv/dist/compile/names.js +28 -0
  52. package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
  53. package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
  54. package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
  55. package/esm/node_modules/ajv/dist/compile/util.js +178 -0
  56. package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
  57. package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
  58. package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
  59. package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
  60. package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
  61. package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
  62. package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
  63. package/esm/node_modules/ajv/dist/core.js +618 -0
  64. package/esm/node_modules/ajv/dist/refs/data.json +13 -0
  65. package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
  66. package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
  67. package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
  68. package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
  69. package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
  70. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
  71. package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
  72. package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
  73. package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
  74. package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
  75. package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
  76. package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
  77. package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
  78. package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
  79. package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
  80. package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
  81. package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
  82. package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
  83. package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
  84. package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
  85. package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
  86. package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
  87. package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
  88. package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
  89. package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
  90. package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
  91. package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
  92. package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
  93. package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
  94. package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
  95. package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
  96. package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
  97. package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
  98. package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
  99. package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
  100. package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
  101. package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
  102. package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
  103. package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
  104. package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
  105. package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
  106. package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
  107. package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
  108. package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
  109. package/esm/node_modules/ajv-formats/dist/index.js +37 -0
  110. package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
  111. package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
  112. package/esm/node_modules/fast-deep-equal/index.js +46 -0
  113. package/esm/node_modules/fast-uri/index.js +303 -0
  114. package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
  115. package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
  116. package/esm/node_modules/fast-uri/lib/utils.js +244 -0
  117. package/esm/node_modules/json-schema-traverse/index.js +89 -0
  118. package/esm/node_modules/semver/classes/comparator.js +143 -0
  119. package/esm/node_modules/semver/classes/range.js +557 -0
  120. package/esm/node_modules/semver/classes/semver.js +333 -0
  121. package/esm/node_modules/semver/functions/clean.js +8 -0
  122. package/esm/node_modules/semver/functions/cmp.js +54 -0
  123. package/esm/node_modules/semver/functions/coerce.js +62 -0
  124. package/esm/node_modules/semver/functions/compare-build.js +9 -0
  125. package/esm/node_modules/semver/functions/compare-loose.js +5 -0
  126. package/esm/node_modules/semver/functions/compare.js +7 -0
  127. package/esm/node_modules/semver/functions/diff.js +60 -0
  128. package/esm/node_modules/semver/functions/eq.js +5 -0
  129. package/esm/node_modules/semver/functions/gt.js +5 -0
  130. package/esm/node_modules/semver/functions/gte.js +5 -0
  131. package/esm/node_modules/semver/functions/inc.js +21 -0
  132. package/esm/node_modules/semver/functions/lt.js +5 -0
  133. package/esm/node_modules/semver/functions/lte.js +5 -0
  134. package/esm/node_modules/semver/functions/major.js +5 -0
  135. package/esm/node_modules/semver/functions/minor.js +5 -0
  136. package/esm/node_modules/semver/functions/neq.js +5 -0
  137. package/esm/node_modules/semver/functions/parse.js +18 -0
  138. package/esm/node_modules/semver/functions/patch.js +5 -0
  139. package/esm/node_modules/semver/functions/prerelease.js +8 -0
  140. package/esm/node_modules/semver/functions/rcompare.js +5 -0
  141. package/esm/node_modules/semver/functions/rsort.js +5 -0
  142. package/esm/node_modules/semver/functions/satisfies.js +12 -0
  143. package/esm/node_modules/semver/functions/sort.js +5 -0
  144. package/esm/node_modules/semver/functions/valid.js +8 -0
  145. package/esm/node_modules/semver/index.js +91 -0
  146. package/esm/node_modules/semver/internal/constants.js +37 -0
  147. package/esm/node_modules/semver/internal/debug.js +11 -0
  148. package/esm/node_modules/semver/internal/identifiers.js +29 -0
  149. package/esm/node_modules/semver/internal/lrucache.js +42 -0
  150. package/esm/node_modules/semver/internal/parse-options.js +17 -0
  151. package/esm/node_modules/semver/internal/re.js +223 -0
  152. package/esm/node_modules/semver/ranges/gtr.js +6 -0
  153. package/esm/node_modules/semver/ranges/intersects.js +9 -0
  154. package/esm/node_modules/semver/ranges/ltr.js +6 -0
  155. package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
  156. package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
  157. package/esm/node_modules/semver/ranges/min-version.js +63 -0
  158. package/esm/node_modules/semver/ranges/outside.js +82 -0
  159. package/esm/node_modules/semver/ranges/simplify.js +49 -0
  160. package/esm/node_modules/semver/ranges/subset.js +249 -0
  161. package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
  162. package/esm/node_modules/semver/ranges/valid.js +13 -0
  163. package/esm/util/fetch.ts.js +190 -0
  164. package/esm/util/index.ts.js +276 -0
  165. package/package.json +3 -3
  166. package/dist/main.css +0 -208
  167. package/dist/main.js +0 -17353
  168. /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
@@ -0,0 +1,151 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "http://json-schema.org/draft-07/schema#",
4
+ "title": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": {"$ref": "#"}
10
+ },
11
+ "nonNegativeInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "nonNegativeIntegerDefault0": {
16
+ "allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": {"type": "string"},
24
+ "uniqueItems": true,
25
+ "default": []
26
+ }
27
+ },
28
+ "type": ["object", "boolean"],
29
+ "properties": {
30
+ "$id": {
31
+ "type": "string",
32
+ "format": "uri-reference"
33
+ },
34
+ "$schema": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "$ref": {
39
+ "type": "string",
40
+ "format": "uri-reference"
41
+ },
42
+ "$comment": {
43
+ "type": "string"
44
+ },
45
+ "title": {
46
+ "type": "string"
47
+ },
48
+ "description": {
49
+ "type": "string"
50
+ },
51
+ "default": true,
52
+ "readOnly": {
53
+ "type": "boolean",
54
+ "default": false
55
+ },
56
+ "examples": {
57
+ "type": "array",
58
+ "items": true
59
+ },
60
+ "multipleOf": {
61
+ "type": "number",
62
+ "exclusiveMinimum": 0
63
+ },
64
+ "maximum": {
65
+ "type": "number"
66
+ },
67
+ "exclusiveMaximum": {
68
+ "type": "number"
69
+ },
70
+ "minimum": {
71
+ "type": "number"
72
+ },
73
+ "exclusiveMinimum": {
74
+ "type": "number"
75
+ },
76
+ "maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
77
+ "minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
78
+ "pattern": {
79
+ "type": "string",
80
+ "format": "regex"
81
+ },
82
+ "additionalItems": {"$ref": "#"},
83
+ "items": {
84
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
85
+ "default": true
86
+ },
87
+ "maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
88
+ "minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
89
+ "uniqueItems": {
90
+ "type": "boolean",
91
+ "default": false
92
+ },
93
+ "contains": {"$ref": "#"},
94
+ "maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
95
+ "minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
96
+ "required": {"$ref": "#/definitions/stringArray"},
97
+ "additionalProperties": {"$ref": "#"},
98
+ "definitions": {
99
+ "type": "object",
100
+ "additionalProperties": {"$ref": "#"},
101
+ "default": {}
102
+ },
103
+ "properties": {
104
+ "type": "object",
105
+ "additionalProperties": {"$ref": "#"},
106
+ "default": {}
107
+ },
108
+ "patternProperties": {
109
+ "type": "object",
110
+ "additionalProperties": {"$ref": "#"},
111
+ "propertyNames": {"format": "regex"},
112
+ "default": {}
113
+ },
114
+ "dependencies": {
115
+ "type": "object",
116
+ "additionalProperties": {
117
+ "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
118
+ }
119
+ },
120
+ "propertyNames": {"$ref": "#"},
121
+ "const": true,
122
+ "enum": {
123
+ "type": "array",
124
+ "items": true,
125
+ "minItems": 1,
126
+ "uniqueItems": true
127
+ },
128
+ "type": {
129
+ "anyOf": [
130
+ {"$ref": "#/definitions/simpleTypes"},
131
+ {
132
+ "type": "array",
133
+ "items": {"$ref": "#/definitions/simpleTypes"},
134
+ "minItems": 1,
135
+ "uniqueItems": true
136
+ }
137
+ ]
138
+ },
139
+ "format": {"type": "string"},
140
+ "contentMediaType": {"type": "string"},
141
+ "contentEncoding": {"type": "string"},
142
+ "if": {"$ref": "#"},
143
+ "then": {"$ref": "#"},
144
+ "else": {"$ref": "#"},
145
+ "allOf": {"$ref": "#/definitions/schemaArray"},
146
+ "anyOf": {"$ref": "#/definitions/schemaArray"},
147
+ "oneOf": {"$ref": "#/definitions/schemaArray"},
148
+ "not": {"$ref": "#"}
149
+ },
150
+ "default": true
151
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // https://github.com/ajv-validator/ajv/issues/889
4
+ const equal = require('../../../fast-deep-equal/index.js');
5
+ equal.code = 'require("ajv/dist/runtime/equal").default';
6
+ exports.default = equal;
7
+ //# sourceMappingURL=equal.js.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // https://mathiasbynens.be/notes/javascript-encoding
4
+ // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
5
+ function ucs2length(str) {
6
+ const len = str.length;
7
+ let length = 0;
8
+ let pos = 0;
9
+ let value;
10
+ while (pos < len) {
11
+ length++;
12
+ value = str.charCodeAt(pos++);
13
+ if (value >= 0xd800 && value <= 0xdbff && pos < len) {
14
+ // high surrogate, and there is a next character
15
+ value = str.charCodeAt(pos);
16
+ if ((value & 0xfc00) === 0xdc00)
17
+ pos++; // low surrogate
18
+ }
19
+ }
20
+ return length;
21
+ }
22
+ exports.default = ucs2length;
23
+ ucs2length.code = 'require("ajv/dist/runtime/ucs2length").default';
24
+ //# sourceMappingURL=ucs2length.js.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const uri = require('../../../fast-uri/index.js');
4
+ uri.code = 'require("ajv/dist/runtime/uri").default';
5
+ exports.default = uri;
6
+ //# sourceMappingURL=uri.js.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ValidationError extends Error {
4
+ constructor(errors) {
5
+ super("validation failed");
6
+ this.errors = errors;
7
+ this.ajv = this.validation = true;
8
+ }
9
+ }
10
+ exports.default = ValidationError;
11
+ //# sourceMappingURL=validation_error.js.map
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAdditionalItems = void 0;
4
+ const codegen_1 = require('../../compile/codegen/index.js');
5
+ const util_1 = require('../../compile/util.js');
6
+ const error = {
7
+ message: ({ params: { len } }) => (0, codegen_1.str) `must NOT have more than ${len} items`,
8
+ params: ({ params: { len } }) => (0, codegen_1._) `{limit: ${len}}`,
9
+ };
10
+ const def = {
11
+ keyword: "additionalItems",
12
+ type: "array",
13
+ schemaType: ["boolean", "object"],
14
+ before: "uniqueItems",
15
+ error,
16
+ code(cxt) {
17
+ const { parentSchema, it } = cxt;
18
+ const { items } = parentSchema;
19
+ if (!Array.isArray(items)) {
20
+ (0, util_1.checkStrictMode)(it, '"additionalItems" is ignored when "items" is not an array of schemas');
21
+ return;
22
+ }
23
+ validateAdditionalItems(cxt, items);
24
+ },
25
+ };
26
+ function validateAdditionalItems(cxt, items) {
27
+ const { gen, schema, data, keyword, it } = cxt;
28
+ it.items = true;
29
+ const len = gen.const("len", (0, codegen_1._) `${data}.length`);
30
+ if (schema === false) {
31
+ cxt.setParams({ len: items.length });
32
+ cxt.pass((0, codegen_1._) `${len} <= ${items.length}`);
33
+ }
34
+ else if (typeof schema == "object" && !(0, util_1.alwaysValidSchema)(it, schema)) {
35
+ const valid = gen.var("valid", (0, codegen_1._) `${len} <= ${items.length}`); // TODO var
36
+ gen.if((0, codegen_1.not)(valid), () => validateItems(valid));
37
+ cxt.ok(valid);
38
+ }
39
+ function validateItems(valid) {
40
+ gen.forRange("i", items.length, len, (i) => {
41
+ cxt.subschema({ keyword, dataProp: i, dataPropType: util_1.Type.Num }, valid);
42
+ if (!it.allErrors)
43
+ gen.if((0, codegen_1.not)(valid), () => gen.break());
44
+ });
45
+ }
46
+ }
47
+ exports.validateAdditionalItems = validateAdditionalItems;
48
+ exports.default = def;
49
+ //# sourceMappingURL=additionalItems.js.map
@@ -0,0 +1,106 @@
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 names_1 = require('../../compile/names.js');
6
+ const util_1 = require('../../compile/util.js');
7
+ const error = {
8
+ message: "must NOT have additional properties",
9
+ params: ({ params }) => (0, codegen_1._) `{additionalProperty: ${params.additionalProperty}}`,
10
+ };
11
+ const def = {
12
+ keyword: "additionalProperties",
13
+ type: ["object"],
14
+ schemaType: ["boolean", "object"],
15
+ allowUndefined: true,
16
+ trackErrors: true,
17
+ error,
18
+ code(cxt) {
19
+ const { gen, schema, parentSchema, data, errsCount, it } = cxt;
20
+ /* istanbul ignore if */
21
+ if (!errsCount)
22
+ throw new Error("ajv implementation error");
23
+ const { allErrors, opts } = it;
24
+ it.props = true;
25
+ if (opts.removeAdditional !== "all" && (0, util_1.alwaysValidSchema)(it, schema))
26
+ return;
27
+ const props = (0, code_1.allSchemaProperties)(parentSchema.properties);
28
+ const patProps = (0, code_1.allSchemaProperties)(parentSchema.patternProperties);
29
+ checkAdditionalProperties();
30
+ cxt.ok((0, codegen_1._) `${errsCount} === ${names_1.default.errors}`);
31
+ function checkAdditionalProperties() {
32
+ gen.forIn("key", data, (key) => {
33
+ if (!props.length && !patProps.length)
34
+ additionalPropertyCode(key);
35
+ else
36
+ gen.if(isAdditional(key), () => additionalPropertyCode(key));
37
+ });
38
+ }
39
+ function isAdditional(key) {
40
+ let definedProp;
41
+ if (props.length > 8) {
42
+ // TODO maybe an option instead of hard-coded 8?
43
+ const propsSchema = (0, util_1.schemaRefOrVal)(it, parentSchema.properties, "properties");
44
+ definedProp = (0, code_1.isOwnProperty)(gen, propsSchema, key);
45
+ }
46
+ else if (props.length) {
47
+ definedProp = (0, codegen_1.or)(...props.map((p) => (0, codegen_1._) `${key} === ${p}`));
48
+ }
49
+ else {
50
+ definedProp = codegen_1.nil;
51
+ }
52
+ if (patProps.length) {
53
+ definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((p) => (0, codegen_1._) `${(0, code_1.usePattern)(cxt, p)}.test(${key})`));
54
+ }
55
+ return (0, codegen_1.not)(definedProp);
56
+ }
57
+ function deleteAdditional(key) {
58
+ gen.code((0, codegen_1._) `delete ${data}[${key}]`);
59
+ }
60
+ function additionalPropertyCode(key) {
61
+ if (opts.removeAdditional === "all" || (opts.removeAdditional && schema === false)) {
62
+ deleteAdditional(key);
63
+ return;
64
+ }
65
+ if (schema === false) {
66
+ cxt.setParams({ additionalProperty: key });
67
+ cxt.error();
68
+ if (!allErrors)
69
+ gen.break();
70
+ return;
71
+ }
72
+ if (typeof schema == "object" && !(0, util_1.alwaysValidSchema)(it, schema)) {
73
+ const valid = gen.name("valid");
74
+ if (opts.removeAdditional === "failing") {
75
+ applyAdditionalSchema(key, valid, false);
76
+ gen.if((0, codegen_1.not)(valid), () => {
77
+ cxt.reset();
78
+ deleteAdditional(key);
79
+ });
80
+ }
81
+ else {
82
+ applyAdditionalSchema(key, valid);
83
+ if (!allErrors)
84
+ gen.if((0, codegen_1.not)(valid), () => gen.break());
85
+ }
86
+ }
87
+ }
88
+ function applyAdditionalSchema(key, valid, errors) {
89
+ const subschema = {
90
+ keyword: "additionalProperties",
91
+ dataProp: key,
92
+ dataPropType: util_1.Type.Str,
93
+ };
94
+ if (errors === false) {
95
+ Object.assign(subschema, {
96
+ compositeRule: true,
97
+ createErrors: false,
98
+ allErrors: false,
99
+ });
100
+ }
101
+ cxt.subschema(subschema, valid);
102
+ }
103
+ },
104
+ };
105
+ exports.default = def;
106
+ //# sourceMappingURL=additionalProperties.js.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require('../../compile/util.js');
4
+ const def = {
5
+ keyword: "allOf",
6
+ schemaType: "array",
7
+ code(cxt) {
8
+ const { gen, schema, it } = cxt;
9
+ /* istanbul ignore if */
10
+ if (!Array.isArray(schema))
11
+ throw new Error("ajv implementation error");
12
+ const valid = gen.name("valid");
13
+ schema.forEach((sch, i) => {
14
+ if ((0, util_1.alwaysValidSchema)(it, sch))
15
+ return;
16
+ const schCxt = cxt.subschema({ keyword: "allOf", schemaProp: i }, valid);
17
+ cxt.ok(valid);
18
+ cxt.mergeEvaluated(schCxt);
19
+ });
20
+ },
21
+ };
22
+ exports.default = def;
23
+ //# sourceMappingURL=allOf.js.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const code_1 = require('../code.js');
4
+ const def = {
5
+ keyword: "anyOf",
6
+ schemaType: "array",
7
+ trackErrors: true,
8
+ code: code_1.validateUnion,
9
+ error: { message: "must match a schema in anyOf" },
10
+ };
11
+ exports.default = def;
12
+ //# sourceMappingURL=anyOf.js.map
@@ -0,0 +1,95 @@
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 error = {
6
+ message: ({ params: { min, max } }) => max === undefined
7
+ ? (0, codegen_1.str) `must contain at least ${min} valid item(s)`
8
+ : (0, codegen_1.str) `must contain at least ${min} and no more than ${max} valid item(s)`,
9
+ params: ({ params: { min, max } }) => max === undefined ? (0, codegen_1._) `{minContains: ${min}}` : (0, codegen_1._) `{minContains: ${min}, maxContains: ${max}}`,
10
+ };
11
+ const def = {
12
+ keyword: "contains",
13
+ type: "array",
14
+ schemaType: ["object", "boolean"],
15
+ before: "uniqueItems",
16
+ trackErrors: true,
17
+ error,
18
+ code(cxt) {
19
+ const { gen, schema, parentSchema, data, it } = cxt;
20
+ let min;
21
+ let max;
22
+ const { minContains, maxContains } = parentSchema;
23
+ if (it.opts.next) {
24
+ min = minContains === undefined ? 1 : minContains;
25
+ max = maxContains;
26
+ }
27
+ else {
28
+ min = 1;
29
+ }
30
+ const len = gen.const("len", (0, codegen_1._) `${data}.length`);
31
+ cxt.setParams({ min, max });
32
+ if (max === undefined && min === 0) {
33
+ (0, util_1.checkStrictMode)(it, `"minContains" == 0 without "maxContains": "contains" keyword ignored`);
34
+ return;
35
+ }
36
+ if (max !== undefined && min > max) {
37
+ (0, util_1.checkStrictMode)(it, `"minContains" > "maxContains" is always invalid`);
38
+ cxt.fail();
39
+ return;
40
+ }
41
+ if ((0, util_1.alwaysValidSchema)(it, schema)) {
42
+ let cond = (0, codegen_1._) `${len} >= ${min}`;
43
+ if (max !== undefined)
44
+ cond = (0, codegen_1._) `${cond} && ${len} <= ${max}`;
45
+ cxt.pass(cond);
46
+ return;
47
+ }
48
+ it.items = true;
49
+ const valid = gen.name("valid");
50
+ if (max === undefined && min === 1) {
51
+ validateItems(valid, () => gen.if(valid, () => gen.break()));
52
+ }
53
+ else if (min === 0) {
54
+ gen.let(valid, true);
55
+ if (max !== undefined)
56
+ gen.if((0, codegen_1._) `${data}.length > 0`, validateItemsWithCount);
57
+ }
58
+ else {
59
+ gen.let(valid, false);
60
+ validateItemsWithCount();
61
+ }
62
+ cxt.result(valid, () => cxt.reset());
63
+ function validateItemsWithCount() {
64
+ const schValid = gen.name("_valid");
65
+ const count = gen.let("count", 0);
66
+ validateItems(schValid, () => gen.if(schValid, () => checkLimits(count)));
67
+ }
68
+ function validateItems(_valid, block) {
69
+ gen.forRange("i", 0, len, (i) => {
70
+ cxt.subschema({
71
+ keyword: "contains",
72
+ dataProp: i,
73
+ dataPropType: util_1.Type.Num,
74
+ compositeRule: true,
75
+ }, _valid);
76
+ block();
77
+ });
78
+ }
79
+ function checkLimits(count) {
80
+ gen.code((0, codegen_1._) `${count}++`);
81
+ if (max === undefined) {
82
+ gen.if((0, codegen_1._) `${count} >= ${min}`, () => gen.assign(valid, true).break());
83
+ }
84
+ else {
85
+ gen.if((0, codegen_1._) `${count} > ${max}`, () => gen.assign(valid, false).break());
86
+ if (min === 1)
87
+ gen.assign(valid, true);
88
+ else
89
+ gen.if((0, codegen_1._) `${count} >= ${min}`, () => gen.assign(valid, true));
90
+ }
91
+ }
92
+ },
93
+ };
94
+ exports.default = def;
95
+ //# sourceMappingURL=contains.js.map
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = void 0;
4
+ const codegen_1 = require('../../compile/codegen/index.js');
5
+ const util_1 = require('../../compile/util.js');
6
+ const code_1 = require('../code.js');
7
+ exports.error = {
8
+ message: ({ params: { property, depsCount, deps } }) => {
9
+ const property_ies = depsCount === 1 ? "property" : "properties";
10
+ return (0, codegen_1.str) `must have ${property_ies} ${deps} when property ${property} is present`;
11
+ },
12
+ params: ({ params: { property, depsCount, deps, missingProperty } }) => (0, codegen_1._) `{property: ${property},
13
+ missingProperty: ${missingProperty},
14
+ depsCount: ${depsCount},
15
+ deps: ${deps}}`, // TODO change to reference
16
+ };
17
+ const def = {
18
+ keyword: "dependencies",
19
+ type: "object",
20
+ schemaType: "object",
21
+ error: exports.error,
22
+ code(cxt) {
23
+ const [propDeps, schDeps] = splitDependencies(cxt);
24
+ validatePropertyDeps(cxt, propDeps);
25
+ validateSchemaDeps(cxt, schDeps);
26
+ },
27
+ };
28
+ function splitDependencies({ schema }) {
29
+ const propertyDeps = {};
30
+ const schemaDeps = {};
31
+ for (const key in schema) {
32
+ if (key === "__proto__")
33
+ continue;
34
+ const deps = Array.isArray(schema[key]) ? propertyDeps : schemaDeps;
35
+ deps[key] = schema[key];
36
+ }
37
+ return [propertyDeps, schemaDeps];
38
+ }
39
+ function validatePropertyDeps(cxt, propertyDeps = cxt.schema) {
40
+ const { gen, data, it } = cxt;
41
+ if (Object.keys(propertyDeps).length === 0)
42
+ return;
43
+ const missing = gen.let("missing");
44
+ for (const prop in propertyDeps) {
45
+ const deps = propertyDeps[prop];
46
+ if (deps.length === 0)
47
+ continue;
48
+ const hasProperty = (0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties);
49
+ cxt.setParams({
50
+ property: prop,
51
+ depsCount: deps.length,
52
+ deps: deps.join(", "),
53
+ });
54
+ if (it.allErrors) {
55
+ gen.if(hasProperty, () => {
56
+ for (const depProp of deps) {
57
+ (0, code_1.checkReportMissingProp)(cxt, depProp);
58
+ }
59
+ });
60
+ }
61
+ else {
62
+ gen.if((0, codegen_1._) `${hasProperty} && (${(0, code_1.checkMissingProp)(cxt, deps, missing)})`);
63
+ (0, code_1.reportMissingProp)(cxt, missing);
64
+ gen.else();
65
+ }
66
+ }
67
+ }
68
+ exports.validatePropertyDeps = validatePropertyDeps;
69
+ function validateSchemaDeps(cxt, schemaDeps = cxt.schema) {
70
+ const { gen, data, keyword, it } = cxt;
71
+ const valid = gen.name("valid");
72
+ for (const prop in schemaDeps) {
73
+ if ((0, util_1.alwaysValidSchema)(it, schemaDeps[prop]))
74
+ continue;
75
+ gen.if((0, code_1.propertyInData)(gen, data, prop, it.opts.ownProperties), () => {
76
+ const schCxt = cxt.subschema({ keyword, schemaProp: prop }, valid);
77
+ cxt.mergeValidEvaluated(schCxt, valid);
78
+ }, () => gen.var(valid, true) // TODO var
79
+ );
80
+ cxt.ok(valid);
81
+ }
82
+ }
83
+ exports.validateSchemaDeps = validateSchemaDeps;
84
+ exports.default = def;
85
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1,66 @@
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 error = {
6
+ message: ({ params }) => (0, codegen_1.str) `must match "${params.ifClause}" schema`,
7
+ params: ({ params }) => (0, codegen_1._) `{failingKeyword: ${params.ifClause}}`,
8
+ };
9
+ const def = {
10
+ keyword: "if",
11
+ schemaType: ["object", "boolean"],
12
+ trackErrors: true,
13
+ error,
14
+ code(cxt) {
15
+ const { gen, parentSchema, it } = cxt;
16
+ if (parentSchema.then === undefined && parentSchema.else === undefined) {
17
+ (0, util_1.checkStrictMode)(it, '"if" without "then" and "else" is ignored');
18
+ }
19
+ const hasThen = hasSchema(it, "then");
20
+ const hasElse = hasSchema(it, "else");
21
+ if (!hasThen && !hasElse)
22
+ return;
23
+ const valid = gen.let("valid", true);
24
+ const schValid = gen.name("_valid");
25
+ validateIf();
26
+ cxt.reset();
27
+ if (hasThen && hasElse) {
28
+ const ifClause = gen.let("ifClause");
29
+ cxt.setParams({ ifClause });
30
+ gen.if(schValid, validateClause("then", ifClause), validateClause("else", ifClause));
31
+ }
32
+ else if (hasThen) {
33
+ gen.if(schValid, validateClause("then"));
34
+ }
35
+ else {
36
+ gen.if((0, codegen_1.not)(schValid), validateClause("else"));
37
+ }
38
+ cxt.pass(valid, () => cxt.error(true));
39
+ function validateIf() {
40
+ const schCxt = cxt.subschema({
41
+ keyword: "if",
42
+ compositeRule: true,
43
+ createErrors: false,
44
+ allErrors: false,
45
+ }, schValid);
46
+ cxt.mergeEvaluated(schCxt);
47
+ }
48
+ function validateClause(keyword, ifClause) {
49
+ return () => {
50
+ const schCxt = cxt.subschema({ keyword }, schValid);
51
+ gen.assign(valid, schValid);
52
+ cxt.mergeValidEvaluated(schCxt, valid);
53
+ if (ifClause)
54
+ gen.assign(ifClause, (0, codegen_1._) `${keyword}`);
55
+ else
56
+ cxt.setParams({ ifClause: keyword });
57
+ };
58
+ }
59
+ },
60
+ };
61
+ function hasSchema(it, keyword) {
62
+ const schema = it.schema[keyword];
63
+ return schema !== undefined && !(0, util_1.alwaysValidSchema)(it, schema);
64
+ }
65
+ exports.default = def;
66
+ //# sourceMappingURL=if.js.map