immosquare-cleaner 0.1.38 → 0.1.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-cleaner/version.rb +1 -1
- data/node_modules/@eslint/config-array/LICENSE +201 -0
- data/node_modules/@eslint/config-array/README.md +340 -0
- data/node_modules/@eslint/config-array/dist/cjs/index.cjs +1260 -0
- data/node_modules/@eslint/config-array/dist/cjs/index.d.cts +146 -0
- data/node_modules/@eslint/config-array/dist/cjs/types.ts +24 -0
- data/node_modules/@eslint/config-array/dist/esm/index.d.ts +146 -0
- data/node_modules/@eslint/config-array/dist/esm/index.js +1258 -0
- data/node_modules/@eslint/config-array/dist/esm/types.d.ts +19 -0
- data/node_modules/@eslint/config-array/dist/esm/types.ts +24 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/README.md +230 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/minimatch.js +947 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/node_modules/brace-expansion/LICENSE +21 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/node_modules/brace-expansion/README.md +129 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/node_modules/brace-expansion/package.json +47 -0
- data/node_modules/@eslint/config-array/node_modules/minimatch/package.json +33 -0
- data/node_modules/@eslint/config-array/package.json +60 -0
- data/node_modules/@eslint/js/package.json +1 -1
- data/node_modules/@eslint/object-schema/LICENSE +201 -0
- data/node_modules/@eslint/object-schema/README.md +224 -0
- data/node_modules/@eslint/object-schema/dist/cjs/index.cjs +455 -0
- data/node_modules/@eslint/object-schema/dist/cjs/index.d.cts +123 -0
- data/node_modules/@eslint/object-schema/dist/cjs/types.ts +55 -0
- data/node_modules/@eslint/object-schema/dist/esm/index.d.ts +123 -0
- data/node_modules/@eslint/object-schema/dist/esm/index.js +452 -0
- data/node_modules/@eslint/object-schema/dist/esm/types.d.ts +40 -0
- data/node_modules/@eslint/object-schema/dist/esm/types.ts +55 -0
- data/node_modules/@eslint/object-schema/package.json +56 -0
- data/node_modules/eslint/lib/cli.js +2 -2
- data/node_modules/eslint/lib/config/flat-config-array.js +1 -1
- data/node_modules/eslint/lib/eslint/eslint-helpers.js +7 -7
- data/node_modules/eslint/lib/eslint/eslint.js +1 -10
- data/node_modules/eslint/lib/rule-tester/rule-tester.js +1 -1
- data/node_modules/eslint/lib/rules/func-style.js +4 -4
- data/node_modules/eslint/lib/rules/no-constructor-return.js +1 -1
- data/node_modules/eslint/lib/rules/no-loop-func.js +161 -129
- data/node_modules/eslint/package.json +3 -3
- data/node_modules/prettier/LICENSE +56 -535
- data/node_modules/prettier/bin/prettier.cjs +4 -8
- data/node_modules/prettier/doc.js +20 -29
- data/node_modules/prettier/doc.mjs +20 -29
- data/node_modules/prettier/index.cjs +1 -1
- data/node_modules/prettier/index.d.ts +4 -2
- data/node_modules/prettier/index.mjs +3109 -4509
- data/node_modules/prettier/internal/cli.mjs +339 -3544
- data/node_modules/prettier/package.json +1 -1
- data/node_modules/prettier/plugins/acorn.js +11 -11
- data/node_modules/prettier/plugins/acorn.mjs +11 -11
- data/node_modules/prettier/plugins/angular.js +1 -1
- data/node_modules/prettier/plugins/angular.mjs +1 -1
- data/node_modules/prettier/plugins/babel.js +11 -11
- data/node_modules/prettier/plugins/babel.mjs +11 -11
- data/node_modules/prettier/plugins/estree.js +28 -28
- data/node_modules/prettier/plugins/estree.mjs +28 -28
- data/node_modules/prettier/plugins/flow.js +16 -17
- data/node_modules/prettier/plugins/flow.mjs +16 -17
- data/node_modules/prettier/plugins/glimmer.js +22 -22
- data/node_modules/prettier/plugins/glimmer.mjs +22 -22
- data/node_modules/prettier/plugins/graphql.js +4 -4
- data/node_modules/prettier/plugins/graphql.mjs +4 -4
- data/node_modules/prettier/plugins/html.js +15 -15
- data/node_modules/prettier/plugins/html.mjs +15 -15
- data/node_modules/prettier/plugins/markdown.js +42 -42
- data/node_modules/prettier/plugins/markdown.mjs +42 -42
- data/node_modules/prettier/plugins/meriyah.js +5 -5
- data/node_modules/prettier/plugins/meriyah.mjs +5 -5
- data/node_modules/prettier/plugins/postcss.js +26 -26
- data/node_modules/prettier/plugins/postcss.mjs +26 -26
- data/node_modules/prettier/plugins/typescript.js +20 -20
- data/node_modules/prettier/plugins/typescript.mjs +20 -20
- data/node_modules/prettier/plugins/yaml.js +32 -32
- data/node_modules/prettier/plugins/yaml.mjs +32 -32
- data/node_modules/prettier/standalone.js +26 -26
- data/node_modules/prettier/standalone.mjs +26 -26
- data/package.json +3 -3
- metadata +30 -2
@@ -0,0 +1,455 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @filedescription Merge Strategy
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
//-----------------------------------------------------------------------------
|
9
|
+
// Class
|
10
|
+
//-----------------------------------------------------------------------------
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Container class for several different merge strategies.
|
14
|
+
*/
|
15
|
+
class MergeStrategy {
|
16
|
+
/**
|
17
|
+
* Merges two keys by overwriting the first with the second.
|
18
|
+
* @param {*} value1 The value from the first object key.
|
19
|
+
* @param {*} value2 The value from the second object key.
|
20
|
+
* @returns {*} The second value.
|
21
|
+
*/
|
22
|
+
static overwrite(value1, value2) {
|
23
|
+
return value2;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Merges two keys by replacing the first with the second only if the
|
28
|
+
* second is defined.
|
29
|
+
* @param {*} value1 The value from the first object key.
|
30
|
+
* @param {*} value2 The value from the second object key.
|
31
|
+
* @returns {*} The second value if it is defined.
|
32
|
+
*/
|
33
|
+
static replace(value1, value2) {
|
34
|
+
if (typeof value2 !== "undefined") {
|
35
|
+
return value2;
|
36
|
+
}
|
37
|
+
|
38
|
+
return value1;
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Merges two properties by assigning properties from the second to the first.
|
43
|
+
* @param {*} value1 The value from the first object key.
|
44
|
+
* @param {*} value2 The value from the second object key.
|
45
|
+
* @returns {*} A new object containing properties from both value1 and
|
46
|
+
* value2.
|
47
|
+
*/
|
48
|
+
static assign(value1, value2) {
|
49
|
+
return Object.assign({}, value1, value2);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @filedescription Validation Strategy
|
55
|
+
*/
|
56
|
+
|
57
|
+
|
58
|
+
//-----------------------------------------------------------------------------
|
59
|
+
// Class
|
60
|
+
//-----------------------------------------------------------------------------
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Container class for several different validation strategies.
|
64
|
+
*/
|
65
|
+
class ValidationStrategy {
|
66
|
+
/**
|
67
|
+
* Validates that a value is an array.
|
68
|
+
* @param {*} value The value to validate.
|
69
|
+
* @returns {void}
|
70
|
+
* @throws {TypeError} If the value is invalid.
|
71
|
+
*/
|
72
|
+
static array(value) {
|
73
|
+
if (!Array.isArray(value)) {
|
74
|
+
throw new TypeError("Expected an array.");
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Validates that a value is a boolean.
|
80
|
+
* @param {*} value The value to validate.
|
81
|
+
* @returns {void}
|
82
|
+
* @throws {TypeError} If the value is invalid.
|
83
|
+
*/
|
84
|
+
static boolean(value) {
|
85
|
+
if (typeof value !== "boolean") {
|
86
|
+
throw new TypeError("Expected a Boolean.");
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Validates that a value is a number.
|
92
|
+
* @param {*} value The value to validate.
|
93
|
+
* @returns {void}
|
94
|
+
* @throws {TypeError} If the value is invalid.
|
95
|
+
*/
|
96
|
+
static number(value) {
|
97
|
+
if (typeof value !== "number") {
|
98
|
+
throw new TypeError("Expected a number.");
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Validates that a value is a object.
|
104
|
+
* @param {*} value The value to validate.
|
105
|
+
* @returns {void}
|
106
|
+
* @throws {TypeError} If the value is invalid.
|
107
|
+
*/
|
108
|
+
static object(value) {
|
109
|
+
if (!value || typeof value !== "object") {
|
110
|
+
throw new TypeError("Expected an object.");
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Validates that a value is a object or null.
|
116
|
+
* @param {*} value The value to validate.
|
117
|
+
* @returns {void}
|
118
|
+
* @throws {TypeError} If the value is invalid.
|
119
|
+
*/
|
120
|
+
static "object?"(value) {
|
121
|
+
if (typeof value !== "object") {
|
122
|
+
throw new TypeError("Expected an object or null.");
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Validates that a value is a string.
|
128
|
+
* @param {*} value The value to validate.
|
129
|
+
* @returns {void}
|
130
|
+
* @throws {TypeError} If the value is invalid.
|
131
|
+
*/
|
132
|
+
static string(value) {
|
133
|
+
if (typeof value !== "string") {
|
134
|
+
throw new TypeError("Expected a string.");
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Validates that a value is a non-empty string.
|
140
|
+
* @param {*} value The value to validate.
|
141
|
+
* @returns {void}
|
142
|
+
* @throws {TypeError} If the value is invalid.
|
143
|
+
*/
|
144
|
+
static "string!"(value) {
|
145
|
+
if (typeof value !== "string" || value.length === 0) {
|
146
|
+
throw new TypeError("Expected a non-empty string.");
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @filedescription Object Schema
|
153
|
+
*/
|
154
|
+
|
155
|
+
|
156
|
+
//-----------------------------------------------------------------------------
|
157
|
+
// Types
|
158
|
+
//-----------------------------------------------------------------------------
|
159
|
+
|
160
|
+
/** @typedef {import("./types.ts").ObjectDefinition} ObjectDefinition */
|
161
|
+
/** @typedef {import("./types.ts").PropertyDefinition} PropertyDefinition */
|
162
|
+
|
163
|
+
//-----------------------------------------------------------------------------
|
164
|
+
// Private
|
165
|
+
//-----------------------------------------------------------------------------
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Validates a schema strategy.
|
169
|
+
* @param {string} name The name of the key this strategy is for.
|
170
|
+
* @param {PropertyDefinition} definition The strategy for the object key.
|
171
|
+
* @returns {void}
|
172
|
+
* @throws {Error} When the strategy is missing a name.
|
173
|
+
* @throws {Error} When the strategy is missing a merge() method.
|
174
|
+
* @throws {Error} When the strategy is missing a validate() method.
|
175
|
+
*/
|
176
|
+
function validateDefinition(name, definition) {
|
177
|
+
let hasSchema = false;
|
178
|
+
if (definition.schema) {
|
179
|
+
if (typeof definition.schema === "object") {
|
180
|
+
hasSchema = true;
|
181
|
+
} else {
|
182
|
+
throw new TypeError("Schema must be an object.");
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
if (typeof definition.merge === "string") {
|
187
|
+
if (!(definition.merge in MergeStrategy)) {
|
188
|
+
throw new TypeError(
|
189
|
+
`Definition for key "${name}" missing valid merge strategy.`,
|
190
|
+
);
|
191
|
+
}
|
192
|
+
} else if (!hasSchema && typeof definition.merge !== "function") {
|
193
|
+
throw new TypeError(
|
194
|
+
`Definition for key "${name}" must have a merge property.`,
|
195
|
+
);
|
196
|
+
}
|
197
|
+
|
198
|
+
if (typeof definition.validate === "string") {
|
199
|
+
if (!(definition.validate in ValidationStrategy)) {
|
200
|
+
throw new TypeError(
|
201
|
+
`Definition for key "${name}" missing valid validation strategy.`,
|
202
|
+
);
|
203
|
+
}
|
204
|
+
} else if (!hasSchema && typeof definition.validate !== "function") {
|
205
|
+
throw new TypeError(
|
206
|
+
`Definition for key "${name}" must have a validate() method.`,
|
207
|
+
);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
//-----------------------------------------------------------------------------
|
212
|
+
// Errors
|
213
|
+
//-----------------------------------------------------------------------------
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Error when an unexpected key is found.
|
217
|
+
*/
|
218
|
+
class UnexpectedKeyError extends Error {
|
219
|
+
/**
|
220
|
+
* Creates a new instance.
|
221
|
+
* @param {string} key The key that was unexpected.
|
222
|
+
*/
|
223
|
+
constructor(key) {
|
224
|
+
super(`Unexpected key "${key}" found.`);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Error when a required key is missing.
|
230
|
+
*/
|
231
|
+
class MissingKeyError extends Error {
|
232
|
+
/**
|
233
|
+
* Creates a new instance.
|
234
|
+
* @param {string} key The key that was missing.
|
235
|
+
*/
|
236
|
+
constructor(key) {
|
237
|
+
super(`Missing required key "${key}".`);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Error when a key requires other keys that are missing.
|
243
|
+
*/
|
244
|
+
class MissingDependentKeysError extends Error {
|
245
|
+
/**
|
246
|
+
* Creates a new instance.
|
247
|
+
* @param {string} key The key that was unexpected.
|
248
|
+
* @param {Array<string>} requiredKeys The keys that are required.
|
249
|
+
*/
|
250
|
+
constructor(key, requiredKeys) {
|
251
|
+
super(`Key "${key}" requires keys "${requiredKeys.join('", "')}".`);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Wrapper error for errors occuring during a merge or validate operation.
|
257
|
+
*/
|
258
|
+
class WrapperError extends Error {
|
259
|
+
/**
|
260
|
+
* Creates a new instance.
|
261
|
+
* @param {string} key The object key causing the error.
|
262
|
+
* @param {Error} source The source error.
|
263
|
+
*/
|
264
|
+
constructor(key, source) {
|
265
|
+
super(`Key "${key}": ${source.message}`, { cause: source });
|
266
|
+
|
267
|
+
// copy over custom properties that aren't represented
|
268
|
+
for (const key of Object.keys(source)) {
|
269
|
+
if (!(key in this)) {
|
270
|
+
this[key] = source[key];
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
//-----------------------------------------------------------------------------
|
277
|
+
// Main
|
278
|
+
//-----------------------------------------------------------------------------
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Represents an object validation/merging schema.
|
282
|
+
*/
|
283
|
+
class ObjectSchema {
|
284
|
+
/**
|
285
|
+
* Track all definitions in the schema by key.
|
286
|
+
* @type {Map<string, PropertyDefinition>}
|
287
|
+
*/
|
288
|
+
#definitions = new Map();
|
289
|
+
|
290
|
+
/**
|
291
|
+
* Separately track any keys that are required for faster validtion.
|
292
|
+
* @type {Map<string, PropertyDefinition>}
|
293
|
+
*/
|
294
|
+
#requiredKeys = new Map();
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Creates a new instance.
|
298
|
+
* @param {ObjectDefinition} definitions The schema definitions.
|
299
|
+
*/
|
300
|
+
constructor(definitions) {
|
301
|
+
if (!definitions) {
|
302
|
+
throw new Error("Schema definitions missing.");
|
303
|
+
}
|
304
|
+
|
305
|
+
// add in all strategies
|
306
|
+
for (const key of Object.keys(definitions)) {
|
307
|
+
validateDefinition(key, definitions[key]);
|
308
|
+
|
309
|
+
// normalize merge and validate methods if subschema is present
|
310
|
+
if (typeof definitions[key].schema === "object") {
|
311
|
+
const schema = new ObjectSchema(definitions[key].schema);
|
312
|
+
definitions[key] = {
|
313
|
+
...definitions[key],
|
314
|
+
merge(first = {}, second = {}) {
|
315
|
+
return schema.merge(first, second);
|
316
|
+
},
|
317
|
+
validate(value) {
|
318
|
+
ValidationStrategy.object(value);
|
319
|
+
schema.validate(value);
|
320
|
+
},
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
// normalize the merge method in case there's a string
|
325
|
+
if (typeof definitions[key].merge === "string") {
|
326
|
+
definitions[key] = {
|
327
|
+
...definitions[key],
|
328
|
+
merge: MergeStrategy[
|
329
|
+
/** @type {string} */ (definitions[key].merge)
|
330
|
+
],
|
331
|
+
};
|
332
|
+
}
|
333
|
+
|
334
|
+
// normalize the validate method in case there's a string
|
335
|
+
if (typeof definitions[key].validate === "string") {
|
336
|
+
definitions[key] = {
|
337
|
+
...definitions[key],
|
338
|
+
validate:
|
339
|
+
ValidationStrategy[
|
340
|
+
/** @type {string} */ (definitions[key].validate)
|
341
|
+
],
|
342
|
+
};
|
343
|
+
}
|
344
|
+
|
345
|
+
this.#definitions.set(key, definitions[key]);
|
346
|
+
|
347
|
+
if (definitions[key].required) {
|
348
|
+
this.#requiredKeys.set(key, definitions[key]);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Determines if a strategy has been registered for the given object key.
|
355
|
+
* @param {string} key The object key to find a strategy for.
|
356
|
+
* @returns {boolean} True if the key has a strategy registered, false if not.
|
357
|
+
*/
|
358
|
+
hasKey(key) {
|
359
|
+
return this.#definitions.has(key);
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Merges objects together to create a new object comprised of the keys
|
364
|
+
* of the all objects. Keys are merged based on the each key's merge
|
365
|
+
* strategy.
|
366
|
+
* @param {...Object} objects The objects to merge.
|
367
|
+
* @returns {Object} A new object with a mix of all objects' keys.
|
368
|
+
* @throws {Error} If any object is invalid.
|
369
|
+
*/
|
370
|
+
merge(...objects) {
|
371
|
+
// double check arguments
|
372
|
+
if (objects.length < 2) {
|
373
|
+
throw new TypeError("merge() requires at least two arguments.");
|
374
|
+
}
|
375
|
+
|
376
|
+
if (
|
377
|
+
objects.some(object => object == null || typeof object !== "object")
|
378
|
+
) {
|
379
|
+
throw new TypeError("All arguments must be objects.");
|
380
|
+
}
|
381
|
+
|
382
|
+
return objects.reduce((result, object) => {
|
383
|
+
this.validate(object);
|
384
|
+
|
385
|
+
for (const [key, strategy] of this.#definitions) {
|
386
|
+
try {
|
387
|
+
if (key in result || key in object) {
|
388
|
+
const merge = /** @type {Function} */ (strategy.merge);
|
389
|
+
const value = merge.call(
|
390
|
+
this,
|
391
|
+
result[key],
|
392
|
+
object[key],
|
393
|
+
);
|
394
|
+
if (value !== undefined) {
|
395
|
+
result[key] = value;
|
396
|
+
}
|
397
|
+
}
|
398
|
+
} catch (ex) {
|
399
|
+
throw new WrapperError(key, ex);
|
400
|
+
}
|
401
|
+
}
|
402
|
+
return result;
|
403
|
+
}, {});
|
404
|
+
}
|
405
|
+
|
406
|
+
/**
|
407
|
+
* Validates an object's keys based on the validate strategy for each key.
|
408
|
+
* @param {Object} object The object to validate.
|
409
|
+
* @returns {void}
|
410
|
+
* @throws {Error} When the object is invalid.
|
411
|
+
*/
|
412
|
+
validate(object) {
|
413
|
+
// check existing keys first
|
414
|
+
for (const key of Object.keys(object)) {
|
415
|
+
// check to see if the key is defined
|
416
|
+
if (!this.hasKey(key)) {
|
417
|
+
throw new UnexpectedKeyError(key);
|
418
|
+
}
|
419
|
+
|
420
|
+
// validate existing keys
|
421
|
+
const definition = this.#definitions.get(key);
|
422
|
+
|
423
|
+
// first check to see if any other keys are required
|
424
|
+
if (Array.isArray(definition.requires)) {
|
425
|
+
if (
|
426
|
+
!definition.requires.every(otherKey => otherKey in object)
|
427
|
+
) {
|
428
|
+
throw new MissingDependentKeysError(
|
429
|
+
key,
|
430
|
+
definition.requires,
|
431
|
+
);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
|
435
|
+
// now apply remaining validation strategy
|
436
|
+
try {
|
437
|
+
const validate = /** @type {Function} */ (definition.validate);
|
438
|
+
validate.call(definition, object[key]);
|
439
|
+
} catch (ex) {
|
440
|
+
throw new WrapperError(key, ex);
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
// ensure required keys aren't missing
|
445
|
+
for (const [key] of this.#requiredKeys) {
|
446
|
+
if (!(key in object)) {
|
447
|
+
throw new MissingKeyError(key);
|
448
|
+
}
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
|
453
|
+
exports.MergeStrategy = MergeStrategy;
|
454
|
+
exports.ObjectSchema = ObjectSchema;
|
455
|
+
exports.ValidationStrategy = ValidationStrategy;
|
@@ -0,0 +1,123 @@
|
|
1
|
+
export type ObjectDefinition = import("./types.ts").ObjectDefinition;
|
2
|
+
export type PropertyDefinition = import("./types.ts").PropertyDefinition;
|
3
|
+
/**
|
4
|
+
* @filedescription Merge Strategy
|
5
|
+
*/
|
6
|
+
/**
|
7
|
+
* Container class for several different merge strategies.
|
8
|
+
*/
|
9
|
+
export class MergeStrategy {
|
10
|
+
/**
|
11
|
+
* Merges two keys by overwriting the first with the second.
|
12
|
+
* @param {*} value1 The value from the first object key.
|
13
|
+
* @param {*} value2 The value from the second object key.
|
14
|
+
* @returns {*} The second value.
|
15
|
+
*/
|
16
|
+
static overwrite(value1: any, value2: any): any;
|
17
|
+
/**
|
18
|
+
* Merges two keys by replacing the first with the second only if the
|
19
|
+
* second is defined.
|
20
|
+
* @param {*} value1 The value from the first object key.
|
21
|
+
* @param {*} value2 The value from the second object key.
|
22
|
+
* @returns {*} The second value if it is defined.
|
23
|
+
*/
|
24
|
+
static replace(value1: any, value2: any): any;
|
25
|
+
/**
|
26
|
+
* Merges two properties by assigning properties from the second to the first.
|
27
|
+
* @param {*} value1 The value from the first object key.
|
28
|
+
* @param {*} value2 The value from the second object key.
|
29
|
+
* @returns {*} A new object containing properties from both value1 and
|
30
|
+
* value2.
|
31
|
+
*/
|
32
|
+
static assign(value1: any, value2: any): any;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Represents an object validation/merging schema.
|
36
|
+
*/
|
37
|
+
export class ObjectSchema {
|
38
|
+
/**
|
39
|
+
* Creates a new instance.
|
40
|
+
* @param {ObjectDefinition} definitions The schema definitions.
|
41
|
+
*/
|
42
|
+
constructor(definitions: ObjectDefinition);
|
43
|
+
/**
|
44
|
+
* Determines if a strategy has been registered for the given object key.
|
45
|
+
* @param {string} key The object key to find a strategy for.
|
46
|
+
* @returns {boolean} True if the key has a strategy registered, false if not.
|
47
|
+
*/
|
48
|
+
hasKey(key: string): boolean;
|
49
|
+
/**
|
50
|
+
* Merges objects together to create a new object comprised of the keys
|
51
|
+
* of the all objects. Keys are merged based on the each key's merge
|
52
|
+
* strategy.
|
53
|
+
* @param {...Object} objects The objects to merge.
|
54
|
+
* @returns {Object} A new object with a mix of all objects' keys.
|
55
|
+
* @throws {Error} If any object is invalid.
|
56
|
+
*/
|
57
|
+
merge(...objects: any[]): any;
|
58
|
+
/**
|
59
|
+
* Validates an object's keys based on the validate strategy for each key.
|
60
|
+
* @param {Object} object The object to validate.
|
61
|
+
* @returns {void}
|
62
|
+
* @throws {Error} When the object is invalid.
|
63
|
+
*/
|
64
|
+
validate(object: any): void;
|
65
|
+
#private;
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* @filedescription Validation Strategy
|
69
|
+
*/
|
70
|
+
/**
|
71
|
+
* Container class for several different validation strategies.
|
72
|
+
*/
|
73
|
+
export class ValidationStrategy {
|
74
|
+
/**
|
75
|
+
* Validates that a value is an array.
|
76
|
+
* @param {*} value The value to validate.
|
77
|
+
* @returns {void}
|
78
|
+
* @throws {TypeError} If the value is invalid.
|
79
|
+
*/
|
80
|
+
static array(value: any): void;
|
81
|
+
/**
|
82
|
+
* Validates that a value is a boolean.
|
83
|
+
* @param {*} value The value to validate.
|
84
|
+
* @returns {void}
|
85
|
+
* @throws {TypeError} If the value is invalid.
|
86
|
+
*/
|
87
|
+
static boolean(value: any): void;
|
88
|
+
/**
|
89
|
+
* Validates that a value is a number.
|
90
|
+
* @param {*} value The value to validate.
|
91
|
+
* @returns {void}
|
92
|
+
* @throws {TypeError} If the value is invalid.
|
93
|
+
*/
|
94
|
+
static number(value: any): void;
|
95
|
+
/**
|
96
|
+
* Validates that a value is a object.
|
97
|
+
* @param {*} value The value to validate.
|
98
|
+
* @returns {void}
|
99
|
+
* @throws {TypeError} If the value is invalid.
|
100
|
+
*/
|
101
|
+
static object(value: any): void;
|
102
|
+
/**
|
103
|
+
* Validates that a value is a object or null.
|
104
|
+
* @param {*} value The value to validate.
|
105
|
+
* @returns {void}
|
106
|
+
* @throws {TypeError} If the value is invalid.
|
107
|
+
*/
|
108
|
+
static "object?"(value: any): void;
|
109
|
+
/**
|
110
|
+
* Validates that a value is a string.
|
111
|
+
* @param {*} value The value to validate.
|
112
|
+
* @returns {void}
|
113
|
+
* @throws {TypeError} If the value is invalid.
|
114
|
+
*/
|
115
|
+
static string(value: any): void;
|
116
|
+
/**
|
117
|
+
* Validates that a value is a non-empty string.
|
118
|
+
* @param {*} value The value to validate.
|
119
|
+
* @returns {void}
|
120
|
+
* @throws {TypeError} If the value is invalid.
|
121
|
+
*/
|
122
|
+
static "string!"(value: any): void;
|
123
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
/**
|
2
|
+
* @filedescription Types for object-schema package.
|
3
|
+
*/
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Built-in validation strategies.
|
7
|
+
*/
|
8
|
+
export type BuiltInValidationStrategy =
|
9
|
+
| "array"
|
10
|
+
| "boolean"
|
11
|
+
| "number"
|
12
|
+
| "object"
|
13
|
+
| "object?"
|
14
|
+
| "string"
|
15
|
+
| "string!";
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Built-in merge strategies.
|
19
|
+
*/
|
20
|
+
export type BuiltInMergeStrategy = "assign" | "overwrite" | "replace";
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Property definition.
|
24
|
+
*/
|
25
|
+
export interface PropertyDefinition {
|
26
|
+
/**
|
27
|
+
* Indicates if the property is required.
|
28
|
+
*/
|
29
|
+
required: boolean;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* The other properties that must be present when this property is used.
|
33
|
+
*/
|
34
|
+
requires?: string[];
|
35
|
+
|
36
|
+
/**
|
37
|
+
* The strategy to merge the property.
|
38
|
+
*/
|
39
|
+
merge: BuiltInMergeStrategy | ((target: any, source: any) => any);
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The strategy to validate the property.
|
43
|
+
*/
|
44
|
+
validate: BuiltInValidationStrategy | ((value: any) => void);
|
45
|
+
|
46
|
+
/**
|
47
|
+
* The schema for the object value of this property.
|
48
|
+
*/
|
49
|
+
schema?: ObjectDefinition;
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Object definition.
|
54
|
+
*/
|
55
|
+
export type ObjectDefinition = Record<string, PropertyDefinition>;
|