ejv 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-KR.md +47 -1
- package/README.md +47 -0
- package/build/cjs/constants.js +10 -0
- package/build/cjs/constants.js.map +1 -1
- package/build/cjs/ejv.js +83 -4
- package/build/cjs/ejv.js.map +1 -1
- package/build/cjs/interfaces.js.map +1 -1
- package/build/cjs/tester.js +145 -125
- package/build/cjs/tester.js.map +1 -1
- package/build/cjs/util.js +15 -16
- package/build/cjs/util.js.map +1 -1
- package/build/constants.d.ts +11 -1
- package/build/ejv.d.ts +1 -1
- package/build/esm/constants.js +10 -0
- package/build/esm/constants.js.map +1 -1
- package/build/esm/ejv.js +83 -3
- package/build/esm/ejv.js.map +1 -1
- package/build/esm/interfaces.js.map +1 -1
- package/build/esm/tester.js +93 -76
- package/build/esm/tester.js.map +1 -1
- package/build/esm/util.js +8 -8
- package/build/esm/util.js.map +1 -1
- package/build/interfaces.d.ts +7 -1
- package/build/tester.d.ts +38 -34
- package/build/util.d.ts +5 -5
- package/eslint.config.mjs +1 -0
- package/package.json +15 -16
- package/spec/ArrayScheme.ts +113 -12
- package/spec/BufferScheme.ts +406 -0
- package/spec/DateScheme.ts +12 -8
- package/spec/NumberScheme.ts +23 -14
- package/spec/ObjectScheme.ts +12 -9
- package/spec/RegExpScheme.ts +2 -2
- package/spec/StringScheme.ts +34 -18
- package/spec/common-test-util.ts +13 -10
- package/spec/testers.spec.ts +35 -1
- package/src/constants.ts +14 -1
- package/src/ejv.ts +109 -2
- package/src/interfaces.ts +13 -1
- package/src/tester.ts +99 -77
- package/src/util.ts +9 -9
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { describe, it } from 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
import { ejv } from '../src/ejv';
|
|
5
|
+
|
|
6
|
+
import { EjvError } from '../src/interfaces';
|
|
7
|
+
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
|
+
import { createErrorMsg } from '../src/util';
|
|
9
|
+
import { checkSchemeError, TypeTester, TYPE_TESTER_ARR } from './common-test-util';
|
|
10
|
+
|
|
11
|
+
describe('BufferScheme', () => {
|
|
12
|
+
describe('type', () => {
|
|
13
|
+
describe('mismatch', () => {
|
|
14
|
+
TYPE_TESTER_ARR
|
|
15
|
+
.filter((obj: TypeTester): boolean => obj.type !== 'buffer')
|
|
16
|
+
.forEach((obj: TypeTester): void => {
|
|
17
|
+
it(obj.type, () => {
|
|
18
|
+
const testObj = {
|
|
19
|
+
a: obj.value
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const error: EjvError | null = ejv(testObj, [{
|
|
23
|
+
key: 'a',
|
|
24
|
+
type: 'buffer'
|
|
25
|
+
}]);
|
|
26
|
+
|
|
27
|
+
expect(error).to.be.instanceof(EjvError);
|
|
28
|
+
|
|
29
|
+
if (!error) {
|
|
30
|
+
throw new Error('spec failed');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH);
|
|
34
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH, {
|
|
35
|
+
placeholders: ['buffer']
|
|
36
|
+
}));
|
|
37
|
+
expect(error.path).to.be.eql('a');
|
|
38
|
+
expect(error.data).to.be.eql(testObj);
|
|
39
|
+
expect(error.errorData).to.be.eql(obj.value);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('multiple types', () => {
|
|
44
|
+
const value = 'ejv';
|
|
45
|
+
const typeArr: string[] = ['boolean', 'buffer'];
|
|
46
|
+
|
|
47
|
+
const testObj = {
|
|
48
|
+
a: value
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const error: EjvError | null = ejv(testObj, [{
|
|
52
|
+
key: 'a',
|
|
53
|
+
type: typeArr
|
|
54
|
+
}]);
|
|
55
|
+
|
|
56
|
+
expect(error).to.be.instanceof(EjvError);
|
|
57
|
+
|
|
58
|
+
if (!error) {
|
|
59
|
+
throw new Error('spec failed');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
expect(error.type).to.be.eql(ERROR_TYPE.TYPE_MISMATCH_ONE_OF);
|
|
63
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.TYPE_MISMATCH_ONE_OF, {
|
|
64
|
+
placeholders: [JSON.stringify(typeArr)]
|
|
65
|
+
}));
|
|
66
|
+
expect(error.path).to.be.eql('a');
|
|
67
|
+
expect(error.data).to.be.eql(testObj);
|
|
68
|
+
expect(error.errorData).to.be.eql(value);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('match', () => {
|
|
73
|
+
it('optional', () => {
|
|
74
|
+
expect(ejv({
|
|
75
|
+
a: undefined
|
|
76
|
+
}, [{
|
|
77
|
+
key: 'a',
|
|
78
|
+
type: 'buffer',
|
|
79
|
+
optional: true
|
|
80
|
+
}])).to.be.null;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('single type', () => {
|
|
84
|
+
expect(ejv({
|
|
85
|
+
a: new Uint8Array(4)
|
|
86
|
+
}, [{
|
|
87
|
+
key: 'a',
|
|
88
|
+
type: 'buffer'
|
|
89
|
+
}])).to.be.null;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('multiple types', () => {
|
|
93
|
+
expect(ejv({
|
|
94
|
+
a: new Uint8Array(4)
|
|
95
|
+
}, [{
|
|
96
|
+
key: 'a',
|
|
97
|
+
type: ['buffer', 'number']
|
|
98
|
+
}])).to.be.null;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('multiple types', () => {
|
|
102
|
+
expect(ejv({
|
|
103
|
+
a: new Uint8Array(4)
|
|
104
|
+
}, [{
|
|
105
|
+
key: 'a',
|
|
106
|
+
type: ['number', 'buffer']
|
|
107
|
+
}])).to.be.null;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('byteLength', () => {
|
|
113
|
+
describe('check parameter', () => {
|
|
114
|
+
const data = {
|
|
115
|
+
a: new Uint8Array(3)
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
it('undefined is ok', () => {
|
|
119
|
+
expect(ejv(data, [{
|
|
120
|
+
key: 'a',
|
|
121
|
+
type: 'buffer',
|
|
122
|
+
byteLength: undefined
|
|
123
|
+
}])).to.be.null;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('null', () => {
|
|
127
|
+
checkSchemeError({
|
|
128
|
+
data: data,
|
|
129
|
+
errorScheme: {
|
|
130
|
+
key: 'a',
|
|
131
|
+
type: 'buffer',
|
|
132
|
+
// @ts-expect-error: null
|
|
133
|
+
byteLength: null
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
message: createErrorMsg(ERROR_MESSAGE.BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('float number', () => {
|
|
141
|
+
checkSchemeError({
|
|
142
|
+
data: data,
|
|
143
|
+
errorScheme: {
|
|
144
|
+
key: 'a',
|
|
145
|
+
type: 'buffer',
|
|
146
|
+
byteLength: 1.5
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
message: createErrorMsg(ERROR_MESSAGE.BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('string', () => {
|
|
154
|
+
checkSchemeError({
|
|
155
|
+
data: data,
|
|
156
|
+
errorScheme: {
|
|
157
|
+
key: 'a',
|
|
158
|
+
type: 'buffer',
|
|
159
|
+
// @ts-expect-error: type mismatch
|
|
160
|
+
byteLength: '1'
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
message: createErrorMsg(ERROR_MESSAGE.BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('fail', () => {
|
|
169
|
+
const value = new Uint8Array(3);
|
|
170
|
+
const testData = {
|
|
171
|
+
a: value
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const error: EjvError | null = ejv(testData, [{
|
|
175
|
+
key: 'a',
|
|
176
|
+
type: 'buffer',
|
|
177
|
+
byteLength: 2
|
|
178
|
+
}]);
|
|
179
|
+
|
|
180
|
+
expect(error).to.be.instanceof(EjvError);
|
|
181
|
+
|
|
182
|
+
if (!error) {
|
|
183
|
+
throw new Error('spec failed');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
expect(error.type).to.be.eql(ERROR_TYPE.BYTE_LENGTH);
|
|
187
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.BYTE_LENGTH, {
|
|
188
|
+
placeholders: [2]
|
|
189
|
+
}));
|
|
190
|
+
expect(error.path).to.be.eql('a');
|
|
191
|
+
expect(error.data).to.be.deep.equal(testData);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('ok', () => {
|
|
195
|
+
expect(ejv({
|
|
196
|
+
a: new Uint8Array(3)
|
|
197
|
+
}, [{
|
|
198
|
+
key: 'a',
|
|
199
|
+
type: 'buffer',
|
|
200
|
+
byteLength: 3
|
|
201
|
+
}])).to.be.null;
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('minByteLength', () => {
|
|
206
|
+
describe('check parameter', () => {
|
|
207
|
+
const data = {
|
|
208
|
+
a: new Uint8Array(4)
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
it('undefined is ok', () => {
|
|
212
|
+
expect(ejv(data, [{
|
|
213
|
+
key: 'a',
|
|
214
|
+
type: 'buffer',
|
|
215
|
+
minByteLength: undefined
|
|
216
|
+
}])).to.be.null;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('null', () => {
|
|
220
|
+
checkSchemeError({
|
|
221
|
+
data: data,
|
|
222
|
+
errorScheme: {
|
|
223
|
+
key: 'a',
|
|
224
|
+
type: 'buffer',
|
|
225
|
+
// @ts-expect-error: null
|
|
226
|
+
minByteLength: null
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
message: createErrorMsg(ERROR_MESSAGE.MIN_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('float number', () => {
|
|
234
|
+
checkSchemeError({
|
|
235
|
+
data: data,
|
|
236
|
+
errorScheme: {
|
|
237
|
+
key: 'a',
|
|
238
|
+
type: 'buffer',
|
|
239
|
+
minByteLength: 1.5
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
message: createErrorMsg(ERROR_MESSAGE.MIN_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('string', () => {
|
|
247
|
+
checkSchemeError({
|
|
248
|
+
data: data,
|
|
249
|
+
errorScheme: {
|
|
250
|
+
key: 'a',
|
|
251
|
+
type: 'buffer',
|
|
252
|
+
// @ts-expect-error: type mismatch
|
|
253
|
+
minByteLength: '1'
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
message: createErrorMsg(ERROR_MESSAGE.MIN_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('fail', () => {
|
|
262
|
+
const value = new Uint8Array(3);
|
|
263
|
+
const testData = {
|
|
264
|
+
a: value
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const error: EjvError | null = ejv(testData, [{
|
|
268
|
+
key: 'a',
|
|
269
|
+
type: 'buffer',
|
|
270
|
+
minByteLength: 4
|
|
271
|
+
}]);
|
|
272
|
+
|
|
273
|
+
expect(error).to.be.instanceof(EjvError);
|
|
274
|
+
|
|
275
|
+
if (!error) {
|
|
276
|
+
throw new Error('spec failed');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
expect(error.type).to.be.eql(ERROR_TYPE.MIN_BYTE_LENGTH);
|
|
280
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.MIN_BYTE_LENGTH, {
|
|
281
|
+
placeholders: [4]
|
|
282
|
+
}));
|
|
283
|
+
expect(error.path).to.be.eql('a');
|
|
284
|
+
expect(error.data).to.be.deep.equal(testData);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('ok', () => {
|
|
288
|
+
expect(ejv({
|
|
289
|
+
a: new Uint8Array(3)
|
|
290
|
+
}, [{
|
|
291
|
+
key: 'a',
|
|
292
|
+
type: 'buffer',
|
|
293
|
+
minByteLength: 2
|
|
294
|
+
}])).to.be.null;
|
|
295
|
+
|
|
296
|
+
expect(ejv({
|
|
297
|
+
a: new Uint8Array(3)
|
|
298
|
+
}, [{
|
|
299
|
+
key: 'a',
|
|
300
|
+
type: 'buffer',
|
|
301
|
+
minByteLength: 3
|
|
302
|
+
}])).to.be.null;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('maxByteLength', () => {
|
|
307
|
+
describe('check parameter', () => {
|
|
308
|
+
const data = {
|
|
309
|
+
a: new Uint8Array(3)
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
it('undefined is ok', () => {
|
|
313
|
+
expect(ejv(data, [{
|
|
314
|
+
key: 'a',
|
|
315
|
+
type: 'buffer',
|
|
316
|
+
maxByteLength: undefined
|
|
317
|
+
}])).to.be.null;
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('null', () => {
|
|
321
|
+
checkSchemeError({
|
|
322
|
+
data: data,
|
|
323
|
+
errorScheme: {
|
|
324
|
+
key: 'a',
|
|
325
|
+
type: 'buffer',
|
|
326
|
+
// @ts-expect-error: null
|
|
327
|
+
maxByteLength: null
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
message: createErrorMsg(ERROR_MESSAGE.MAX_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('float number', () => {
|
|
335
|
+
checkSchemeError({
|
|
336
|
+
data: data,
|
|
337
|
+
errorScheme: {
|
|
338
|
+
key: 'a',
|
|
339
|
+
type: 'buffer',
|
|
340
|
+
maxByteLength: 1.5
|
|
341
|
+
},
|
|
342
|
+
|
|
343
|
+
message: createErrorMsg(ERROR_MESSAGE.MAX_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('string', () => {
|
|
348
|
+
checkSchemeError({
|
|
349
|
+
data: data,
|
|
350
|
+
errorScheme: {
|
|
351
|
+
key: 'a',
|
|
352
|
+
type: 'buffer',
|
|
353
|
+
// @ts-expect-error: type mismatch
|
|
354
|
+
maxByteLength: '1'
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
message: createErrorMsg(ERROR_MESSAGE.MAX_BYTE_LENGTH_SHOULD_BE_INTEGER)
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('fail', () => {
|
|
363
|
+
const value = new Uint8Array(3);
|
|
364
|
+
const testData = {
|
|
365
|
+
a: value
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const error: EjvError | null = ejv(testData, [{
|
|
369
|
+
key: 'a',
|
|
370
|
+
type: 'buffer',
|
|
371
|
+
maxByteLength: 2
|
|
372
|
+
}]);
|
|
373
|
+
|
|
374
|
+
expect(error).to.be.instanceof(EjvError);
|
|
375
|
+
|
|
376
|
+
if (!error) {
|
|
377
|
+
throw new Error('spec failed');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
expect(error.type).to.be.eql(ERROR_TYPE.MAX_BYTE_LENGTH);
|
|
381
|
+
expect(error.message).to.be.eql(createErrorMsg(ERROR_MESSAGE.MAX_BYTE_LENGTH, {
|
|
382
|
+
placeholders: [2]
|
|
383
|
+
}));
|
|
384
|
+
expect(error.path).to.be.eql('a');
|
|
385
|
+
expect(error.data).to.be.deep.equal(testData);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('ok', () => {
|
|
389
|
+
expect(ejv({
|
|
390
|
+
a: new Uint8Array(3)
|
|
391
|
+
}, [{
|
|
392
|
+
key: 'a',
|
|
393
|
+
type: 'buffer',
|
|
394
|
+
maxByteLength: 3
|
|
395
|
+
}])).to.be.null;
|
|
396
|
+
|
|
397
|
+
expect(ejv({
|
|
398
|
+
a: new Uint8Array(3)
|
|
399
|
+
}, [{
|
|
400
|
+
key: 'a',
|
|
401
|
+
type: 'buffer',
|
|
402
|
+
maxByteLength: 4
|
|
403
|
+
}])).to.be.null;
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
});
|
package/spec/DateScheme.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { DateScheme, EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError, TypeTester,
|
|
9
|
+
import { checkSchemeError, TypeTester, TYPE_TESTER_ARR } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('DateScheme', () => {
|
|
@@ -86,7 +86,7 @@ describe('DateScheme', () => {
|
|
|
86
86
|
|
|
87
87
|
describe('type', () => {
|
|
88
88
|
describe('mismatch', () => {
|
|
89
|
-
|
|
89
|
+
TYPE_TESTER_ARR
|
|
90
90
|
.filter((obj: TypeTester): boolean => obj.type !== 'date')
|
|
91
91
|
.forEach((obj: TypeTester): void => {
|
|
92
92
|
const data = {
|
|
@@ -203,7 +203,8 @@ describe('DateScheme', () => {
|
|
|
203
203
|
const errorScheme: Scheme = {
|
|
204
204
|
key: 'date',
|
|
205
205
|
type: 'date',
|
|
206
|
-
|
|
206
|
+
// @ts-expect-error: null
|
|
207
|
+
min: null
|
|
207
208
|
};
|
|
208
209
|
|
|
209
210
|
checkSchemeError({
|
|
@@ -217,7 +218,7 @@ describe('DateScheme', () => {
|
|
|
217
218
|
const errorScheme: Scheme = {
|
|
218
219
|
key: 'date',
|
|
219
220
|
type: 'date',
|
|
220
|
-
min: 123
|
|
221
|
+
min: 123
|
|
221
222
|
};
|
|
222
223
|
|
|
223
224
|
checkSchemeError({
|
|
@@ -276,7 +277,8 @@ describe('DateScheme', () => {
|
|
|
276
277
|
key: 'date',
|
|
277
278
|
type: 'date',
|
|
278
279
|
min: now,
|
|
279
|
-
|
|
280
|
+
// @ts-expect-error: type mismatch
|
|
281
|
+
exclusiveMin: now.toISOString()
|
|
280
282
|
};
|
|
281
283
|
|
|
282
284
|
checkSchemeError({
|
|
@@ -345,7 +347,8 @@ describe('DateScheme', () => {
|
|
|
345
347
|
const errorScheme: Scheme = {
|
|
346
348
|
key: 'date',
|
|
347
349
|
type: 'date',
|
|
348
|
-
|
|
350
|
+
// @ts-expect-error: null
|
|
351
|
+
max: null
|
|
349
352
|
};
|
|
350
353
|
|
|
351
354
|
checkSchemeError({
|
|
@@ -359,7 +362,7 @@ describe('DateScheme', () => {
|
|
|
359
362
|
const errorScheme: Scheme = {
|
|
360
363
|
key: 'date',
|
|
361
364
|
type: 'date',
|
|
362
|
-
max: 123
|
|
365
|
+
max: 123
|
|
363
366
|
};
|
|
364
367
|
|
|
365
368
|
checkSchemeError({
|
|
@@ -418,7 +421,8 @@ describe('DateScheme', () => {
|
|
|
418
421
|
key: 'date',
|
|
419
422
|
type: 'date',
|
|
420
423
|
max: now,
|
|
421
|
-
|
|
424
|
+
// @ts-expect-error: type mismatch
|
|
425
|
+
exclusiveMax: now.toISOString()
|
|
422
426
|
};
|
|
423
427
|
|
|
424
428
|
checkSchemeError({
|
package/spec/NumberScheme.ts
CHANGED
|
@@ -3,16 +3,16 @@ import { expect } from 'chai';
|
|
|
3
3
|
|
|
4
4
|
import { ejv } from '../src/ejv';
|
|
5
5
|
|
|
6
|
-
import { EjvError, Scheme } from '../src/interfaces';
|
|
6
|
+
import { EjvError, NumberScheme, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError,
|
|
9
|
+
import { checkSchemeError, TYPE_TESTER_ARR, TypeTester } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('NumberScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
TYPE_TESTER_ARR
|
|
16
16
|
.filter((obj: TypeTester): boolean => obj.type !== 'number')
|
|
17
17
|
.forEach((obj: TypeTester): void => {
|
|
18
18
|
const data = {
|
|
@@ -131,7 +131,8 @@ describe('NumberScheme', () => {
|
|
|
131
131
|
const errorScheme: Scheme = {
|
|
132
132
|
key: 'a',
|
|
133
133
|
type: 'number',
|
|
134
|
-
|
|
134
|
+
// @ts-expect-error: null
|
|
135
|
+
enum: null
|
|
135
136
|
};
|
|
136
137
|
|
|
137
138
|
checkSchemeError({
|
|
@@ -149,7 +150,8 @@ describe('NumberScheme', () => {
|
|
|
149
150
|
const errorScheme: Scheme = {
|
|
150
151
|
key: 'a',
|
|
151
152
|
type: 'number',
|
|
152
|
-
|
|
153
|
+
// @ts-expect-error: type mismatch
|
|
154
|
+
enum: 1
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
checkSchemeError({
|
|
@@ -237,7 +239,8 @@ describe('NumberScheme', () => {
|
|
|
237
239
|
const errorScheme: Scheme = {
|
|
238
240
|
key: 'a',
|
|
239
241
|
type: 'number',
|
|
240
|
-
|
|
242
|
+
// @ts-expect-error: null
|
|
243
|
+
notEnum: null
|
|
241
244
|
};
|
|
242
245
|
|
|
243
246
|
checkSchemeError({
|
|
@@ -255,7 +258,8 @@ describe('NumberScheme', () => {
|
|
|
255
258
|
const errorScheme: Scheme = {
|
|
256
259
|
key: 'a',
|
|
257
260
|
type: 'number',
|
|
258
|
-
|
|
261
|
+
// @ts-expect-error: type mismatch
|
|
262
|
+
notEnum: 1
|
|
259
263
|
};
|
|
260
264
|
|
|
261
265
|
checkSchemeError({
|
|
@@ -345,7 +349,8 @@ describe('NumberScheme', () => {
|
|
|
345
349
|
const errorScheme: Scheme = {
|
|
346
350
|
key: 'a',
|
|
347
351
|
type: 'number',
|
|
348
|
-
|
|
352
|
+
// @ts-expect-error: null
|
|
353
|
+
min: null
|
|
349
354
|
};
|
|
350
355
|
|
|
351
356
|
checkSchemeError({
|
|
@@ -429,11 +434,12 @@ describe('NumberScheme', () => {
|
|
|
429
434
|
a: 3
|
|
430
435
|
};
|
|
431
436
|
|
|
432
|
-
const errorScheme:
|
|
437
|
+
const errorScheme: NumberScheme = {
|
|
433
438
|
key: 'a',
|
|
434
439
|
type: 'number',
|
|
435
440
|
min: 3,
|
|
436
|
-
|
|
441
|
+
// @ts-expect-error: type mismatch
|
|
442
|
+
exclusiveMin: '3'
|
|
437
443
|
};
|
|
438
444
|
|
|
439
445
|
checkSchemeError({
|
|
@@ -558,7 +564,8 @@ describe('NumberScheme', () => {
|
|
|
558
564
|
const errorScheme: Scheme = {
|
|
559
565
|
key: 'a',
|
|
560
566
|
type: 'number',
|
|
561
|
-
|
|
567
|
+
// @ts-expect-error: null
|
|
568
|
+
max: null
|
|
562
569
|
};
|
|
563
570
|
|
|
564
571
|
checkSchemeError({
|
|
@@ -642,11 +649,12 @@ describe('NumberScheme', () => {
|
|
|
642
649
|
a: 3
|
|
643
650
|
};
|
|
644
651
|
|
|
645
|
-
const errorScheme:
|
|
652
|
+
const errorScheme: NumberScheme = {
|
|
646
653
|
key: 'a',
|
|
647
654
|
type: 'number',
|
|
648
655
|
max: 3,
|
|
649
|
-
|
|
656
|
+
// @ts-expect-error: type mismatch
|
|
657
|
+
exclusiveMax: '3'
|
|
650
658
|
};
|
|
651
659
|
|
|
652
660
|
checkSchemeError({
|
|
@@ -770,7 +778,8 @@ describe('NumberScheme', () => {
|
|
|
770
778
|
const errorScheme: Scheme = {
|
|
771
779
|
key: 'a',
|
|
772
780
|
type: 'number',
|
|
773
|
-
|
|
781
|
+
// @ts-expect-error: null
|
|
782
|
+
format: null
|
|
774
783
|
};
|
|
775
784
|
|
|
776
785
|
checkSchemeError({
|
package/spec/ObjectScheme.ts
CHANGED
|
@@ -6,15 +6,15 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { EjvError, Scheme } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { checkSchemeError, TypeTester,
|
|
9
|
+
import { checkSchemeError, TypeTester, TYPE_TESTER_ARR } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('ObjectScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
TYPE_TESTER_ARR
|
|
16
16
|
.filter((obj: TypeTester): boolean => {
|
|
17
|
-
return !['null', 'date', 'regexp', 'array', 'object'].includes(obj.type);
|
|
17
|
+
return !['null', 'date', 'regexp', 'array', 'object', 'buffer'].includes(obj.type);
|
|
18
18
|
})
|
|
19
19
|
.forEach((obj: TypeTester): void => {
|
|
20
20
|
const data = {
|
|
@@ -83,9 +83,9 @@ describe('ObjectScheme', () => {
|
|
|
83
83
|
}])).to.be.null;
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
TYPE_TESTER_ARR
|
|
87
87
|
.filter((obj: TypeTester): boolean => {
|
|
88
|
-
return ['null', 'date', 'regexp', 'array', 'object'].includes(obj.type);
|
|
88
|
+
return ['null', 'date', 'regexp', 'array', 'object', 'buffer'].includes(obj.type);
|
|
89
89
|
})
|
|
90
90
|
.forEach((obj: TypeTester): void => {
|
|
91
91
|
it(obj.type, () => {
|
|
@@ -153,7 +153,8 @@ describe('ObjectScheme', () => {
|
|
|
153
153
|
const errorScheme: Scheme = {
|
|
154
154
|
key: 'a',
|
|
155
155
|
type: 'object',
|
|
156
|
-
|
|
156
|
+
// @ts-expect-error: null
|
|
157
|
+
properties: null
|
|
157
158
|
};
|
|
158
159
|
|
|
159
160
|
checkSchemeError({
|
|
@@ -167,7 +168,8 @@ describe('ObjectScheme', () => {
|
|
|
167
168
|
const errorScheme: Scheme = {
|
|
168
169
|
key: 'a',
|
|
169
170
|
type: 'object',
|
|
170
|
-
|
|
171
|
+
// @ts-expect-error: type mismatch
|
|
172
|
+
properties: 'b'
|
|
171
173
|
};
|
|
172
174
|
|
|
173
175
|
checkSchemeError({
|
|
@@ -195,7 +197,7 @@ describe('ObjectScheme', () => {
|
|
|
195
197
|
const errorScheme: Scheme = {
|
|
196
198
|
key: 'a',
|
|
197
199
|
type: 'object',
|
|
198
|
-
properties: ['b']
|
|
200
|
+
properties: ['b']
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
checkSchemeError({
|
|
@@ -396,7 +398,8 @@ describe('ObjectScheme', () => {
|
|
|
396
398
|
const errorScheme: Scheme = {
|
|
397
399
|
key: 'a',
|
|
398
400
|
type: 'object',
|
|
399
|
-
|
|
401
|
+
// @ts-expect-error: null
|
|
402
|
+
allowNoProperty: null
|
|
400
403
|
};
|
|
401
404
|
|
|
402
405
|
checkSchemeError({
|
package/spec/RegExpScheme.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { ejv } from '../src/ejv';
|
|
|
6
6
|
import { EjvError } from '../src/interfaces';
|
|
7
7
|
import { ERROR_MESSAGE, ERROR_TYPE } from '../src/constants';
|
|
8
8
|
import { createErrorMsg } from '../src/util';
|
|
9
|
-
import { TypeTester,
|
|
9
|
+
import { TypeTester, TYPE_TESTER_ARR } from './common-test-util';
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
describe('RegExpScheme', () => {
|
|
13
13
|
describe('type', () => {
|
|
14
14
|
describe('mismatch', () => {
|
|
15
|
-
|
|
15
|
+
TYPE_TESTER_ARR
|
|
16
16
|
.filter((obj: TypeTester): boolean => obj.type !== 'regexp')
|
|
17
17
|
.forEach((obj: TypeTester): void => {
|
|
18
18
|
it(obj.type, () => {
|