@alexlit/lint-kit 117.2.0 → 117.3.0

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 (169) hide show
  1. package/package.json +2 -2
  2. package/packages/config-commitlint/package.json +2 -2
  3. package/packages/config-eslint/index.js +7 -374
  4. package/packages/config-eslint/legacy.js +3 -0
  5. package/packages/config-eslint/node_modules/@eslint/eslintrc/LICENSE +19 -0
  6. package/packages/config-eslint/node_modules/@eslint/eslintrc/README.md +126 -0
  7. package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
  8. package/packages/config-eslint/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
  9. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1143 -0
  10. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
  11. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4371 -0
  12. package/packages/config-eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
  13. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
  14. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +510 -0
  15. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +124 -0
  16. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
  17. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
  18. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
  19. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
  20. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1155 -0
  21. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
  22. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
  23. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/index.js +58 -0
  24. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
  25. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
  26. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +370 -0
  27. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
  28. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
  29. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
  30. package/packages/config-eslint/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
  31. package/packages/config-eslint/node_modules/@eslint/eslintrc/package.json +82 -0
  32. package/packages/config-eslint/node_modules/@eslint/eslintrc/universal.js +9 -0
  33. package/packages/config-eslint/node_modules/ajv/.tonic_example.js +20 -0
  34. package/packages/config-eslint/node_modules/ajv/LICENSE +22 -0
  35. package/packages/config-eslint/node_modules/ajv/README.md +1497 -0
  36. package/packages/config-eslint/node_modules/ajv/dist/ajv.bundle.js +7189 -0
  37. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js +3 -0
  38. package/packages/config-eslint/node_modules/ajv/dist/ajv.min.js.map +1 -0
  39. package/packages/config-eslint/node_modules/ajv/lib/ajv.d.ts +397 -0
  40. package/packages/config-eslint/node_modules/ajv/lib/ajv.js +506 -0
  41. package/packages/config-eslint/node_modules/ajv/lib/cache.js +26 -0
  42. package/packages/config-eslint/node_modules/ajv/lib/compile/async.js +90 -0
  43. package/packages/config-eslint/node_modules/ajv/lib/compile/equal.js +5 -0
  44. package/packages/config-eslint/node_modules/ajv/lib/compile/error_classes.js +34 -0
  45. package/packages/config-eslint/node_modules/ajv/lib/compile/formats.js +142 -0
  46. package/packages/config-eslint/node_modules/ajv/lib/compile/index.js +387 -0
  47. package/packages/config-eslint/node_modules/ajv/lib/compile/resolve.js +270 -0
  48. package/packages/config-eslint/node_modules/ajv/lib/compile/rules.js +66 -0
  49. package/packages/config-eslint/node_modules/ajv/lib/compile/schema_obj.js +9 -0
  50. package/packages/config-eslint/node_modules/ajv/lib/compile/ucs2length.js +20 -0
  51. package/packages/config-eslint/node_modules/ajv/lib/compile/util.js +239 -0
  52. package/packages/config-eslint/node_modules/ajv/lib/data.js +49 -0
  53. package/packages/config-eslint/node_modules/ajv/lib/definition_schema.js +37 -0
  54. package/packages/config-eslint/node_modules/ajv/lib/dot/_limit.jst +113 -0
  55. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitItems.jst +12 -0
  56. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitLength.jst +12 -0
  57. package/packages/config-eslint/node_modules/ajv/lib/dot/_limitProperties.jst +12 -0
  58. package/packages/config-eslint/node_modules/ajv/lib/dot/allOf.jst +32 -0
  59. package/packages/config-eslint/node_modules/ajv/lib/dot/anyOf.jst +46 -0
  60. package/packages/config-eslint/node_modules/ajv/lib/dot/coerce.def +51 -0
  61. package/packages/config-eslint/node_modules/ajv/lib/dot/comment.jst +9 -0
  62. package/packages/config-eslint/node_modules/ajv/lib/dot/const.jst +11 -0
  63. package/packages/config-eslint/node_modules/ajv/lib/dot/contains.jst +55 -0
  64. package/packages/config-eslint/node_modules/ajv/lib/dot/custom.jst +191 -0
  65. package/packages/config-eslint/node_modules/ajv/lib/dot/defaults.def +47 -0
  66. package/packages/config-eslint/node_modules/ajv/lib/dot/definitions.def +203 -0
  67. package/packages/config-eslint/node_modules/ajv/lib/dot/dependencies.jst +79 -0
  68. package/packages/config-eslint/node_modules/ajv/lib/dot/enum.jst +30 -0
  69. package/packages/config-eslint/node_modules/ajv/lib/dot/errors.def +194 -0
  70. package/packages/config-eslint/node_modules/ajv/lib/dot/format.jst +106 -0
  71. package/packages/config-eslint/node_modules/ajv/lib/dot/if.jst +73 -0
  72. package/packages/config-eslint/node_modules/ajv/lib/dot/items.jst +98 -0
  73. package/packages/config-eslint/node_modules/ajv/lib/dot/missing.def +39 -0
  74. package/packages/config-eslint/node_modules/ajv/lib/dot/multipleOf.jst +22 -0
  75. package/packages/config-eslint/node_modules/ajv/lib/dot/not.jst +43 -0
  76. package/packages/config-eslint/node_modules/ajv/lib/dot/oneOf.jst +54 -0
  77. package/packages/config-eslint/node_modules/ajv/lib/dot/pattern.jst +14 -0
  78. package/packages/config-eslint/node_modules/ajv/lib/dot/properties.jst +245 -0
  79. package/packages/config-eslint/node_modules/ajv/lib/dot/propertyNames.jst +52 -0
  80. package/packages/config-eslint/node_modules/ajv/lib/dot/ref.jst +85 -0
  81. package/packages/config-eslint/node_modules/ajv/lib/dot/required.jst +108 -0
  82. package/packages/config-eslint/node_modules/ajv/lib/dot/uniqueItems.jst +62 -0
  83. package/packages/config-eslint/node_modules/ajv/lib/dot/validate.jst +276 -0
  84. package/packages/config-eslint/node_modules/ajv/lib/dotjs/README.md +3 -0
  85. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limit.js +163 -0
  86. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitItems.js +80 -0
  87. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitLength.js +85 -0
  88. package/packages/config-eslint/node_modules/ajv/lib/dotjs/_limitProperties.js +80 -0
  89. package/packages/config-eslint/node_modules/ajv/lib/dotjs/allOf.js +42 -0
  90. package/packages/config-eslint/node_modules/ajv/lib/dotjs/anyOf.js +73 -0
  91. package/packages/config-eslint/node_modules/ajv/lib/dotjs/comment.js +14 -0
  92. package/packages/config-eslint/node_modules/ajv/lib/dotjs/const.js +56 -0
  93. package/packages/config-eslint/node_modules/ajv/lib/dotjs/contains.js +81 -0
  94. package/packages/config-eslint/node_modules/ajv/lib/dotjs/custom.js +228 -0
  95. package/packages/config-eslint/node_modules/ajv/lib/dotjs/dependencies.js +168 -0
  96. package/packages/config-eslint/node_modules/ajv/lib/dotjs/enum.js +66 -0
  97. package/packages/config-eslint/node_modules/ajv/lib/dotjs/format.js +150 -0
  98. package/packages/config-eslint/node_modules/ajv/lib/dotjs/if.js +103 -0
  99. package/packages/config-eslint/node_modules/ajv/lib/dotjs/index.js +33 -0
  100. package/packages/config-eslint/node_modules/ajv/lib/dotjs/items.js +140 -0
  101. package/packages/config-eslint/node_modules/ajv/lib/dotjs/multipleOf.js +80 -0
  102. package/packages/config-eslint/node_modules/ajv/lib/dotjs/not.js +84 -0
  103. package/packages/config-eslint/node_modules/ajv/lib/dotjs/oneOf.js +73 -0
  104. package/packages/config-eslint/node_modules/ajv/lib/dotjs/pattern.js +75 -0
  105. package/packages/config-eslint/node_modules/ajv/lib/dotjs/properties.js +335 -0
  106. package/packages/config-eslint/node_modules/ajv/lib/dotjs/propertyNames.js +81 -0
  107. package/packages/config-eslint/node_modules/ajv/lib/dotjs/ref.js +124 -0
  108. package/packages/config-eslint/node_modules/ajv/lib/dotjs/required.js +270 -0
  109. package/packages/config-eslint/node_modules/ajv/lib/dotjs/uniqueItems.js +86 -0
  110. package/packages/config-eslint/node_modules/ajv/lib/dotjs/validate.js +482 -0
  111. package/packages/config-eslint/node_modules/ajv/lib/keyword.js +146 -0
  112. package/packages/config-eslint/node_modules/ajv/lib/refs/data.json +17 -0
  113. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-04.json +149 -0
  114. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-06.json +154 -0
  115. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-draft-07.json +168 -0
  116. package/packages/config-eslint/node_modules/ajv/lib/refs/json-schema-secure.json +94 -0
  117. package/packages/config-eslint/node_modules/ajv/package.json +106 -0
  118. package/packages/config-eslint/node_modules/ajv/scripts/.eslintrc.yml +3 -0
  119. package/packages/config-eslint/node_modules/ajv/scripts/bundle.js +61 -0
  120. package/packages/config-eslint/node_modules/ajv/scripts/compile-dots.js +73 -0
  121. package/packages/config-eslint/node_modules/ajv/scripts/info +10 -0
  122. package/packages/config-eslint/node_modules/ajv/scripts/prepare-tests +12 -0
  123. package/packages/config-eslint/node_modules/ajv/scripts/publish-built-version +32 -0
  124. package/packages/config-eslint/node_modules/ajv/scripts/travis-gh-pages +23 -0
  125. package/packages/config-eslint/node_modules/eslint-visitor-keys/LICENSE +201 -0
  126. package/packages/config-eslint/node_modules/eslint-visitor-keys/README.md +105 -0
  127. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.cjs +384 -0
  128. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/eslint-visitor-keys.d.cts +27 -0
  129. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/index.d.ts +16 -0
  130. package/packages/config-eslint/node_modules/eslint-visitor-keys/dist/visitor-keys.d.ts +12 -0
  131. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/index.js +65 -0
  132. package/packages/config-eslint/node_modules/eslint-visitor-keys/lib/visitor-keys.js +315 -0
  133. package/packages/config-eslint/node_modules/eslint-visitor-keys/package.json +74 -0
  134. package/packages/config-eslint/node_modules/espree/LICENSE +25 -0
  135. package/packages/config-eslint/node_modules/espree/README.md +244 -0
  136. package/packages/config-eslint/node_modules/espree/dist/espree.cjs +883 -0
  137. package/packages/config-eslint/node_modules/espree/espree.js +177 -0
  138. package/packages/config-eslint/node_modules/espree/lib/espree.js +349 -0
  139. package/packages/config-eslint/node_modules/espree/lib/features.js +27 -0
  140. package/packages/config-eslint/node_modules/espree/lib/options.js +123 -0
  141. package/packages/config-eslint/node_modules/espree/lib/token-translator.js +263 -0
  142. package/packages/config-eslint/node_modules/espree/lib/version.js +3 -0
  143. package/packages/config-eslint/node_modules/espree/package.json +86 -0
  144. package/packages/config-eslint/node_modules/globals/globals.json +1998 -0
  145. package/packages/config-eslint/node_modules/globals/index.d.ts +2077 -0
  146. package/packages/config-eslint/node_modules/globals/index.js +2 -0
  147. package/packages/config-eslint/node_modules/globals/license +9 -0
  148. package/packages/config-eslint/node_modules/globals/package.json +58 -0
  149. package/packages/config-eslint/node_modules/globals/readme.md +44 -0
  150. package/packages/config-eslint/node_modules/json-schema-traverse/.eslintrc.yml +27 -0
  151. package/packages/config-eslint/node_modules/json-schema-traverse/.travis.yml +8 -0
  152. package/packages/config-eslint/node_modules/json-schema-traverse/LICENSE +21 -0
  153. package/packages/config-eslint/node_modules/json-schema-traverse/README.md +83 -0
  154. package/packages/config-eslint/node_modules/json-schema-traverse/index.js +89 -0
  155. package/packages/config-eslint/node_modules/json-schema-traverse/package.json +43 -0
  156. package/packages/config-eslint/node_modules/json-schema-traverse/spec/.eslintrc.yml +6 -0
  157. package/packages/config-eslint/node_modules/json-schema-traverse/spec/fixtures/schema.js +125 -0
  158. package/packages/config-eslint/node_modules/json-schema-traverse/spec/index.spec.js +171 -0
  159. package/packages/config-eslint/package.json +7 -5
  160. package/packages/config-eslint/plugins/no-await-in-promise.js +2 -2
  161. package/packages/config-eslint/utils/create-config.js +377 -0
  162. package/packages/config-hooks/package.json +1 -1
  163. package/packages/config-htmllint/package.json +1 -1
  164. package/packages/config-markdownlint/package.json +2 -2
  165. package/packages/config-npmlint/package.json +1 -1
  166. package/packages/config-prettier/package.json +2 -2
  167. package/packages/config-stylelint/package.json +2 -2
  168. package/scripts/lint.eslint.sh +1 -1
  169. package/.eslintrc.cjs +0 -16
@@ -0,0 +1,270 @@
1
+ 'use strict';
2
+
3
+ var URI = require('uri-js')
4
+ , equal = require('fast-deep-equal')
5
+ , util = require('./util')
6
+ , SchemaObject = require('./schema_obj')
7
+ , traverse = require('json-schema-traverse');
8
+
9
+ module.exports = resolve;
10
+
11
+ resolve.normalizeId = normalizeId;
12
+ resolve.fullPath = getFullPath;
13
+ resolve.url = resolveUrl;
14
+ resolve.ids = resolveIds;
15
+ resolve.inlineRef = inlineRef;
16
+ resolve.schema = resolveSchema;
17
+
18
+ /**
19
+ * [resolve and compile the references ($ref)]
20
+ * @this Ajv
21
+ * @param {Function} compile reference to schema compilation funciton (localCompile)
22
+ * @param {Object} root object with information about the root schema for the current schema
23
+ * @param {String} ref reference to resolve
24
+ * @return {Object|Function} schema object (if the schema can be inlined) or validation function
25
+ */
26
+ function resolve(compile, root, ref) {
27
+ /* jshint validthis: true */
28
+ var refVal = this._refs[ref];
29
+ if (typeof refVal == 'string') {
30
+ if (this._refs[refVal]) refVal = this._refs[refVal];
31
+ else return resolve.call(this, compile, root, refVal);
32
+ }
33
+
34
+ refVal = refVal || this._schemas[ref];
35
+ if (refVal instanceof SchemaObject) {
36
+ return inlineRef(refVal.schema, this._opts.inlineRefs)
37
+ ? refVal.schema
38
+ : refVal.validate || this._compile(refVal);
39
+ }
40
+
41
+ var res = resolveSchema.call(this, root, ref);
42
+ var schema, v, baseId;
43
+ if (res) {
44
+ schema = res.schema;
45
+ root = res.root;
46
+ baseId = res.baseId;
47
+ }
48
+
49
+ if (schema instanceof SchemaObject) {
50
+ v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
51
+ } else if (schema !== undefined) {
52
+ v = inlineRef(schema, this._opts.inlineRefs)
53
+ ? schema
54
+ : compile.call(this, schema, root, undefined, baseId);
55
+ }
56
+
57
+ return v;
58
+ }
59
+
60
+
61
+ /**
62
+ * Resolve schema, its root and baseId
63
+ * @this Ajv
64
+ * @param {Object} root root object with properties schema, refVal, refs
65
+ * @param {String} ref reference to resolve
66
+ * @return {Object} object with properties schema, root, baseId
67
+ */
68
+ function resolveSchema(root, ref) {
69
+ /* jshint validthis: true */
70
+ var p = URI.parse(ref)
71
+ , refPath = _getFullPath(p)
72
+ , baseId = getFullPath(this._getId(root.schema));
73
+ if (Object.keys(root.schema).length === 0 || refPath !== baseId) {
74
+ var id = normalizeId(refPath);
75
+ var refVal = this._refs[id];
76
+ if (typeof refVal == 'string') {
77
+ return resolveRecursive.call(this, root, refVal, p);
78
+ } else if (refVal instanceof SchemaObject) {
79
+ if (!refVal.validate) this._compile(refVal);
80
+ root = refVal;
81
+ } else {
82
+ refVal = this._schemas[id];
83
+ if (refVal instanceof SchemaObject) {
84
+ if (!refVal.validate) this._compile(refVal);
85
+ if (id == normalizeId(ref))
86
+ return { schema: refVal, root: root, baseId: baseId };
87
+ root = refVal;
88
+ } else {
89
+ return;
90
+ }
91
+ }
92
+ if (!root.schema) return;
93
+ baseId = getFullPath(this._getId(root.schema));
94
+ }
95
+ return getJsonPointer.call(this, p, baseId, root.schema, root);
96
+ }
97
+
98
+
99
+ /* @this Ajv */
100
+ function resolveRecursive(root, ref, parsedRef) {
101
+ /* jshint validthis: true */
102
+ var res = resolveSchema.call(this, root, ref);
103
+ if (res) {
104
+ var schema = res.schema;
105
+ var baseId = res.baseId;
106
+ root = res.root;
107
+ var id = this._getId(schema);
108
+ if (id) baseId = resolveUrl(baseId, id);
109
+ return getJsonPointer.call(this, parsedRef, baseId, schema, root);
110
+ }
111
+ }
112
+
113
+
114
+ var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
115
+ /* @this Ajv */
116
+ function getJsonPointer(parsedRef, baseId, schema, root) {
117
+ /* jshint validthis: true */
118
+ parsedRef.fragment = parsedRef.fragment || '';
119
+ if (parsedRef.fragment.slice(0,1) != '/') return;
120
+ var parts = parsedRef.fragment.split('/');
121
+
122
+ for (var i = 1; i < parts.length; i++) {
123
+ var part = parts[i];
124
+ if (part) {
125
+ part = util.unescapeFragment(part);
126
+ schema = schema[part];
127
+ if (schema === undefined) break;
128
+ var id;
129
+ if (!PREVENT_SCOPE_CHANGE[part]) {
130
+ id = this._getId(schema);
131
+ if (id) baseId = resolveUrl(baseId, id);
132
+ if (schema.$ref) {
133
+ var $ref = resolveUrl(baseId, schema.$ref);
134
+ var res = resolveSchema.call(this, root, $ref);
135
+ if (res) {
136
+ schema = res.schema;
137
+ root = res.root;
138
+ baseId = res.baseId;
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ if (schema !== undefined && schema !== root.schema)
145
+ return { schema: schema, root: root, baseId: baseId };
146
+ }
147
+
148
+
149
+ var SIMPLE_INLINED = util.toHash([
150
+ 'type', 'format', 'pattern',
151
+ 'maxLength', 'minLength',
152
+ 'maxProperties', 'minProperties',
153
+ 'maxItems', 'minItems',
154
+ 'maximum', 'minimum',
155
+ 'uniqueItems', 'multipleOf',
156
+ 'required', 'enum'
157
+ ]);
158
+ function inlineRef(schema, limit) {
159
+ if (limit === false) return false;
160
+ if (limit === undefined || limit === true) return checkNoRef(schema);
161
+ else if (limit) return countKeys(schema) <= limit;
162
+ }
163
+
164
+
165
+ function checkNoRef(schema) {
166
+ var item;
167
+ if (Array.isArray(schema)) {
168
+ for (var i=0; i<schema.length; i++) {
169
+ item = schema[i];
170
+ if (typeof item == 'object' && !checkNoRef(item)) return false;
171
+ }
172
+ } else {
173
+ for (var key in schema) {
174
+ if (key == '$ref') return false;
175
+ item = schema[key];
176
+ if (typeof item == 'object' && !checkNoRef(item)) return false;
177
+ }
178
+ }
179
+ return true;
180
+ }
181
+
182
+
183
+ function countKeys(schema) {
184
+ var count = 0, item;
185
+ if (Array.isArray(schema)) {
186
+ for (var i=0; i<schema.length; i++) {
187
+ item = schema[i];
188
+ if (typeof item == 'object') count += countKeys(item);
189
+ if (count == Infinity) return Infinity;
190
+ }
191
+ } else {
192
+ for (var key in schema) {
193
+ if (key == '$ref') return Infinity;
194
+ if (SIMPLE_INLINED[key]) {
195
+ count++;
196
+ } else {
197
+ item = schema[key];
198
+ if (typeof item == 'object') count += countKeys(item) + 1;
199
+ if (count == Infinity) return Infinity;
200
+ }
201
+ }
202
+ }
203
+ return count;
204
+ }
205
+
206
+
207
+ function getFullPath(id, normalize) {
208
+ if (normalize !== false) id = normalizeId(id);
209
+ var p = URI.parse(id);
210
+ return _getFullPath(p);
211
+ }
212
+
213
+
214
+ function _getFullPath(p) {
215
+ return URI.serialize(p).split('#')[0] + '#';
216
+ }
217
+
218
+
219
+ var TRAILING_SLASH_HASH = /#\/?$/;
220
+ function normalizeId(id) {
221
+ return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
222
+ }
223
+
224
+
225
+ function resolveUrl(baseId, id) {
226
+ id = normalizeId(id);
227
+ return URI.resolve(baseId, id);
228
+ }
229
+
230
+
231
+ /* @this Ajv */
232
+ function resolveIds(schema) {
233
+ var schemaId = normalizeId(this._getId(schema));
234
+ var baseIds = {'': schemaId};
235
+ var fullPaths = {'': getFullPath(schemaId, false)};
236
+ var localRefs = {};
237
+ var self = this;
238
+
239
+ traverse(schema, {allKeys: true}, function(sch, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
240
+ if (jsonPtr === '') return;
241
+ var id = self._getId(sch);
242
+ var baseId = baseIds[parentJsonPtr];
243
+ var fullPath = fullPaths[parentJsonPtr] + '/' + parentKeyword;
244
+ if (keyIndex !== undefined)
245
+ fullPath += '/' + (typeof keyIndex == 'number' ? keyIndex : util.escapeFragment(keyIndex));
246
+
247
+ if (typeof id == 'string') {
248
+ id = baseId = normalizeId(baseId ? URI.resolve(baseId, id) : id);
249
+
250
+ var refVal = self._refs[id];
251
+ if (typeof refVal == 'string') refVal = self._refs[refVal];
252
+ if (refVal && refVal.schema) {
253
+ if (!equal(sch, refVal.schema))
254
+ throw new Error('id "' + id + '" resolves to more than one schema');
255
+ } else if (id != normalizeId(fullPath)) {
256
+ if (id[0] == '#') {
257
+ if (localRefs[id] && !equal(sch, localRefs[id]))
258
+ throw new Error('id "' + id + '" resolves to more than one schema');
259
+ localRefs[id] = sch;
260
+ } else {
261
+ self._refs[id] = fullPath;
262
+ }
263
+ }
264
+ }
265
+ baseIds[jsonPtr] = baseId;
266
+ fullPaths[jsonPtr] = fullPath;
267
+ });
268
+
269
+ return localRefs;
270
+ }
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ var ruleModules = require('../dotjs')
4
+ , toHash = require('./util').toHash;
5
+
6
+ module.exports = function rules() {
7
+ var RULES = [
8
+ { type: 'number',
9
+ rules: [ { 'maximum': ['exclusiveMaximum'] },
10
+ { 'minimum': ['exclusiveMinimum'] }, 'multipleOf', 'format'] },
11
+ { type: 'string',
12
+ rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
13
+ { type: 'array',
14
+ rules: [ 'maxItems', 'minItems', 'items', 'contains', 'uniqueItems' ] },
15
+ { type: 'object',
16
+ rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'propertyNames',
17
+ { 'properties': ['additionalProperties', 'patternProperties'] } ] },
18
+ { rules: [ '$ref', 'const', 'enum', 'not', 'anyOf', 'oneOf', 'allOf', 'if' ] }
19
+ ];
20
+
21
+ var ALL = [ 'type', '$comment' ];
22
+ var KEYWORDS = [
23
+ '$schema', '$id', 'id', '$data', '$async', 'title',
24
+ 'description', 'default', 'definitions',
25
+ 'examples', 'readOnly', 'writeOnly',
26
+ 'contentMediaType', 'contentEncoding',
27
+ 'additionalItems', 'then', 'else'
28
+ ];
29
+ var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
30
+ RULES.all = toHash(ALL);
31
+ RULES.types = toHash(TYPES);
32
+
33
+ RULES.forEach(function (group) {
34
+ group.rules = group.rules.map(function (keyword) {
35
+ var implKeywords;
36
+ if (typeof keyword == 'object') {
37
+ var key = Object.keys(keyword)[0];
38
+ implKeywords = keyword[key];
39
+ keyword = key;
40
+ implKeywords.forEach(function (k) {
41
+ ALL.push(k);
42
+ RULES.all[k] = true;
43
+ });
44
+ }
45
+ ALL.push(keyword);
46
+ var rule = RULES.all[keyword] = {
47
+ keyword: keyword,
48
+ code: ruleModules[keyword],
49
+ implements: implKeywords
50
+ };
51
+ return rule;
52
+ });
53
+
54
+ RULES.all.$comment = {
55
+ keyword: '$comment',
56
+ code: ruleModules.$comment
57
+ };
58
+
59
+ if (group.type) RULES.types[group.type] = group;
60
+ });
61
+
62
+ RULES.keywords = toHash(ALL.concat(KEYWORDS));
63
+ RULES.custom = {};
64
+
65
+ return RULES;
66
+ };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var util = require('./util');
4
+
5
+ module.exports = SchemaObject;
6
+
7
+ function SchemaObject(obj) {
8
+ util.copy(obj, this);
9
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ // https://mathiasbynens.be/notes/javascript-encoding
4
+ // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
5
+ module.exports = function ucs2length(str) {
6
+ var length = 0
7
+ , len = str.length
8
+ , pos = 0
9
+ , 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) pos++; // low surrogate
17
+ }
18
+ }
19
+ return length;
20
+ };
@@ -0,0 +1,239 @@
1
+ 'use strict';
2
+
3
+
4
+ module.exports = {
5
+ copy: copy,
6
+ checkDataType: checkDataType,
7
+ checkDataTypes: checkDataTypes,
8
+ coerceToTypes: coerceToTypes,
9
+ toHash: toHash,
10
+ getProperty: getProperty,
11
+ escapeQuotes: escapeQuotes,
12
+ equal: require('fast-deep-equal'),
13
+ ucs2length: require('./ucs2length'),
14
+ varOccurences: varOccurences,
15
+ varReplace: varReplace,
16
+ schemaHasRules: schemaHasRules,
17
+ schemaHasRulesExcept: schemaHasRulesExcept,
18
+ schemaUnknownRules: schemaUnknownRules,
19
+ toQuotedString: toQuotedString,
20
+ getPathExpr: getPathExpr,
21
+ getPath: getPath,
22
+ getData: getData,
23
+ unescapeFragment: unescapeFragment,
24
+ unescapeJsonPointer: unescapeJsonPointer,
25
+ escapeFragment: escapeFragment,
26
+ escapeJsonPointer: escapeJsonPointer
27
+ };
28
+
29
+
30
+ function copy(o, to) {
31
+ to = to || {};
32
+ for (var key in o) to[key] = o[key];
33
+ return to;
34
+ }
35
+
36
+
37
+ function checkDataType(dataType, data, strictNumbers, negate) {
38
+ var EQUAL = negate ? ' !== ' : ' === '
39
+ , AND = negate ? ' || ' : ' && '
40
+ , OK = negate ? '!' : ''
41
+ , NOT = negate ? '' : '!';
42
+ switch (dataType) {
43
+ case 'null': return data + EQUAL + 'null';
44
+ case 'array': return OK + 'Array.isArray(' + data + ')';
45
+ case 'object': return '(' + OK + data + AND +
46
+ 'typeof ' + data + EQUAL + '"object"' + AND +
47
+ NOT + 'Array.isArray(' + data + '))';
48
+ case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
49
+ NOT + '(' + data + ' % 1)' +
50
+ AND + data + EQUAL + data +
51
+ (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
52
+ case 'number': return '(typeof ' + data + EQUAL + '"' + dataType + '"' +
53
+ (strictNumbers ? (AND + OK + 'isFinite(' + data + ')') : '') + ')';
54
+ default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
55
+ }
56
+ }
57
+
58
+
59
+ function checkDataTypes(dataTypes, data, strictNumbers) {
60
+ switch (dataTypes.length) {
61
+ case 1: return checkDataType(dataTypes[0], data, strictNumbers, true);
62
+ default:
63
+ var code = '';
64
+ var types = toHash(dataTypes);
65
+ if (types.array && types.object) {
66
+ code = types.null ? '(': '(!' + data + ' || ';
67
+ code += 'typeof ' + data + ' !== "object")';
68
+ delete types.null;
69
+ delete types.array;
70
+ delete types.object;
71
+ }
72
+ if (types.number) delete types.integer;
73
+ for (var t in types)
74
+ code += (code ? ' && ' : '' ) + checkDataType(t, data, strictNumbers, true);
75
+
76
+ return code;
77
+ }
78
+ }
79
+
80
+
81
+ var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
82
+ function coerceToTypes(optionCoerceTypes, dataTypes) {
83
+ if (Array.isArray(dataTypes)) {
84
+ var types = [];
85
+ for (var i=0; i<dataTypes.length; i++) {
86
+ var t = dataTypes[i];
87
+ if (COERCE_TO_TYPES[t]) types[types.length] = t;
88
+ else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
89
+ }
90
+ if (types.length) return types;
91
+ } else if (COERCE_TO_TYPES[dataTypes]) {
92
+ return [dataTypes];
93
+ } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
94
+ return ['array'];
95
+ }
96
+ }
97
+
98
+
99
+ function toHash(arr) {
100
+ var hash = {};
101
+ for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
102
+ return hash;
103
+ }
104
+
105
+
106
+ var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
107
+ var SINGLE_QUOTE = /'|\\/g;
108
+ function getProperty(key) {
109
+ return typeof key == 'number'
110
+ ? '[' + key + ']'
111
+ : IDENTIFIER.test(key)
112
+ ? '.' + key
113
+ : "['" + escapeQuotes(key) + "']";
114
+ }
115
+
116
+
117
+ function escapeQuotes(str) {
118
+ return str.replace(SINGLE_QUOTE, '\\$&')
119
+ .replace(/\n/g, '\\n')
120
+ .replace(/\r/g, '\\r')
121
+ .replace(/\f/g, '\\f')
122
+ .replace(/\t/g, '\\t');
123
+ }
124
+
125
+
126
+ function varOccurences(str, dataVar) {
127
+ dataVar += '[^0-9]';
128
+ var matches = str.match(new RegExp(dataVar, 'g'));
129
+ return matches ? matches.length : 0;
130
+ }
131
+
132
+
133
+ function varReplace(str, dataVar, expr) {
134
+ dataVar += '([^0-9])';
135
+ expr = expr.replace(/\$/g, '$$$$');
136
+ return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
137
+ }
138
+
139
+
140
+ function schemaHasRules(schema, rules) {
141
+ if (typeof schema == 'boolean') return !schema;
142
+ for (var key in schema) if (rules[key]) return true;
143
+ }
144
+
145
+
146
+ function schemaHasRulesExcept(schema, rules, exceptKeyword) {
147
+ if (typeof schema == 'boolean') return !schema && exceptKeyword != 'not';
148
+ for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
149
+ }
150
+
151
+
152
+ function schemaUnknownRules(schema, rules) {
153
+ if (typeof schema == 'boolean') return;
154
+ for (var key in schema) if (!rules[key]) return key;
155
+ }
156
+
157
+
158
+ function toQuotedString(str) {
159
+ return '\'' + escapeQuotes(str) + '\'';
160
+ }
161
+
162
+
163
+ function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
164
+ var path = jsonPointers // false by default
165
+ ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
166
+ : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
167
+ return joinPaths(currentPath, path);
168
+ }
169
+
170
+
171
+ function getPath(currentPath, prop, jsonPointers) {
172
+ var path = jsonPointers // false by default
173
+ ? toQuotedString('/' + escapeJsonPointer(prop))
174
+ : toQuotedString(getProperty(prop));
175
+ return joinPaths(currentPath, path);
176
+ }
177
+
178
+
179
+ var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
180
+ var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
181
+ function getData($data, lvl, paths) {
182
+ var up, jsonPointer, data, matches;
183
+ if ($data === '') return 'rootData';
184
+ if ($data[0] == '/') {
185
+ if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
186
+ jsonPointer = $data;
187
+ data = 'rootData';
188
+ } else {
189
+ matches = $data.match(RELATIVE_JSON_POINTER);
190
+ if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
191
+ up = +matches[1];
192
+ jsonPointer = matches[2];
193
+ if (jsonPointer == '#') {
194
+ if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
195
+ return paths[lvl - up];
196
+ }
197
+
198
+ if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
199
+ data = 'data' + ((lvl - up) || '');
200
+ if (!jsonPointer) return data;
201
+ }
202
+
203
+ var expr = data;
204
+ var segments = jsonPointer.split('/');
205
+ for (var i=0; i<segments.length; i++) {
206
+ var segment = segments[i];
207
+ if (segment) {
208
+ data += getProperty(unescapeJsonPointer(segment));
209
+ expr += ' && ' + data;
210
+ }
211
+ }
212
+ return expr;
213
+ }
214
+
215
+
216
+ function joinPaths (a, b) {
217
+ if (a == '""') return b;
218
+ return (a + ' + ' + b).replace(/([^\\])' \+ '/g, '$1');
219
+ }
220
+
221
+
222
+ function unescapeFragment(str) {
223
+ return unescapeJsonPointer(decodeURIComponent(str));
224
+ }
225
+
226
+
227
+ function escapeFragment(str) {
228
+ return encodeURIComponent(escapeJsonPointer(str));
229
+ }
230
+
231
+
232
+ function escapeJsonPointer(str) {
233
+ return str.replace(/~/g, '~0').replace(/\//g, '~1');
234
+ }
235
+
236
+
237
+ function unescapeJsonPointer(str) {
238
+ return str.replace(/~1/g, '/').replace(/~0/g, '~');
239
+ }
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ var KEYWORDS = [
4
+ 'multipleOf',
5
+ 'maximum',
6
+ 'exclusiveMaximum',
7
+ 'minimum',
8
+ 'exclusiveMinimum',
9
+ 'maxLength',
10
+ 'minLength',
11
+ 'pattern',
12
+ 'additionalItems',
13
+ 'maxItems',
14
+ 'minItems',
15
+ 'uniqueItems',
16
+ 'maxProperties',
17
+ 'minProperties',
18
+ 'required',
19
+ 'additionalProperties',
20
+ 'enum',
21
+ 'format',
22
+ 'const'
23
+ ];
24
+
25
+ module.exports = function (metaSchema, keywordsJsonPointers) {
26
+ for (var i=0; i<keywordsJsonPointers.length; i++) {
27
+ metaSchema = JSON.parse(JSON.stringify(metaSchema));
28
+ var segments = keywordsJsonPointers[i].split('/');
29
+ var keywords = metaSchema;
30
+ var j;
31
+ for (j=1; j<segments.length; j++)
32
+ keywords = keywords[segments[j]];
33
+
34
+ for (j=0; j<KEYWORDS.length; j++) {
35
+ var key = KEYWORDS[j];
36
+ var schema = keywords[key];
37
+ if (schema) {
38
+ keywords[key] = {
39
+ anyOf: [
40
+ schema,
41
+ { $ref: 'https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#' }
42
+ ]
43
+ };
44
+ }
45
+ }
46
+ }
47
+
48
+ return metaSchema;
49
+ };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var metaSchema = require('./refs/json-schema-draft-07.json');
4
+
5
+ module.exports = {
6
+ $id: 'https://github.com/ajv-validator/ajv/blob/master/lib/definition_schema.js',
7
+ definitions: {
8
+ simpleTypes: metaSchema.definitions.simpleTypes
9
+ },
10
+ type: 'object',
11
+ dependencies: {
12
+ schema: ['validate'],
13
+ $data: ['validate'],
14
+ statements: ['inline'],
15
+ valid: {not: {required: ['macro']}}
16
+ },
17
+ properties: {
18
+ type: metaSchema.properties.type,
19
+ schema: {type: 'boolean'},
20
+ statements: {type: 'boolean'},
21
+ dependencies: {
22
+ type: 'array',
23
+ items: {type: 'string'}
24
+ },
25
+ metaSchema: {type: 'object'},
26
+ modifying: {type: 'boolean'},
27
+ valid: {type: 'boolean'},
28
+ $data: {type: 'boolean'},
29
+ async: {type: 'boolean'},
30
+ errors: {
31
+ anyOf: [
32
+ {type: 'boolean'},
33
+ {const: 'full'}
34
+ ]
35
+ }
36
+ }
37
+ };