co.validation 2.7.1 → 3.0.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 (41) hide show
  1. package/lib/createValidation.d.ts +6 -0
  2. package/lib/createValidation.d.ts.map +1 -0
  3. package/lib/createValidation.js +153 -204
  4. package/lib/createValidation.js.map +1 -0
  5. package/lib/helpers.d.ts +2 -0
  6. package/lib/helpers.d.ts.map +1 -0
  7. package/lib/helpers.js +4 -8
  8. package/lib/helpers.js.map +1 -0
  9. package/lib/index.d.ts +7 -0
  10. package/lib/index.d.ts.map +1 -0
  11. package/lib/index.js +18 -38
  12. package/lib/index.js.map +1 -0
  13. package/lib/messageProcessor.d.ts +7 -0
  14. package/lib/messageProcessor.d.ts.map +1 -0
  15. package/lib/messageProcessor.js +45 -51
  16. package/lib/messageProcessor.js.map +1 -0
  17. package/lib/operators.d.ts +4 -0
  18. package/lib/operators.d.ts.map +1 -0
  19. package/lib/operators.js +60 -71
  20. package/lib/operators.js.map +1 -0
  21. package/lib/types.d.ts +123 -0
  22. package/lib/types.d.ts.map +1 -0
  23. package/lib/types.js +3 -0
  24. package/lib/types.js.map +1 -0
  25. package/lib/validators.d.ts +18 -0
  26. package/lib/validators.d.ts.map +1 -0
  27. package/lib/validators.js +164 -196
  28. package/lib/validators.js.map +1 -0
  29. package/package.json +13 -21
  30. package/tsconfig.json +32 -0
  31. package/lib/__tests__/component.arrayValidation.js +0 -201
  32. package/lib/__tests__/component.objectValidation.js +0 -556
  33. package/lib/__tests__/component.reduxFormValidation.js +0 -20
  34. package/lib/__tests__/component.valueValidation.js +0 -923
  35. package/lib/__tests__/integration.objectValidation.js +0 -64
  36. package/lib/__tests__/integration.registrationForm.js +0 -234
  37. package/lib/__tests__/integration.valueValidation.js +0 -448
  38. package/lib/__tests__/operators.js +0 -28
  39. package/lib/__tests__/unit.operators.js +0 -125
  40. package/lib/createObjectValidation.js +0 -34
  41. package/lib/createValueValidation.js +0 -71
@@ -1,556 +0,0 @@
1
- "use strict";
2
-
3
- var _ = require("..");
4
-
5
- describe('createObjectValidation', () => {
6
- it('supports not an object check', () => {
7
- expect((0, _.createValidation)({
8
- type: 'object',
9
- rules: {
10
- login: {
11
- type: 'required'
12
- }
13
- }
14
- })(undefined)).toEqual({
15
- data: undefined,
16
- errors: undefined
17
- });
18
- expect((0, _.createValidation)({
19
- type: 'object',
20
- rules: {
21
- login: {
22
- type: 'required'
23
- }
24
- }
25
- })(null)).toEqual({
26
- data: null,
27
- errors: undefined
28
- });
29
- expect((0, _.createValidation)({
30
- type: 'object',
31
- rules: {
32
- login: {
33
- type: 'required'
34
- }
35
- }
36
- })('')).toEqual({
37
- data: undefined,
38
- errors: ['Must be an object']
39
- });
40
- expect((0, _.createValidation)({
41
- type: 'object',
42
- rules: {
43
- login: {
44
- type: 'required'
45
- }
46
- }
47
- })(1)).toEqual({
48
- data: undefined,
49
- errors: ['Must be an object']
50
- });
51
- expect((0, _.createValidation)({
52
- type: 'object',
53
- rules: {
54
- login: {
55
- type: 'required'
56
- }
57
- },
58
- getMessage: obj => obj
59
- })('test')).toEqual({
60
- data: undefined,
61
- errors: ['test']
62
- });
63
- });
64
- it('supports check just field to be an object if null rules are passed', () => {
65
- const validatedObject = {
66
- login: ''
67
- };
68
- const validationResult = (0, _.createValidation)({
69
- type: 'object',
70
- rules: null
71
- })(validatedObject);
72
- expect(validationResult.errors).toEqual(undefined);
73
- expect(validationResult.data).toEqual(validatedObject);
74
- });
75
- it('supports property validation for invalid object', () => {
76
- const validatedObject = {
77
- login: ''
78
- };
79
- const validationResult = (0, _.createValidation)({
80
- type: 'object',
81
- rules: {
82
- login: {
83
- type: 'required'
84
- }
85
- }
86
- })(validatedObject);
87
- expect(validationResult.errors).toEqual({
88
- login: ['Required']
89
- });
90
- expect(validationResult.data).toEqual(undefined);
91
- });
92
- it('supports property validation for invalid object and omits extra properties', () => {
93
- const validatedObject = {
94
- login: '',
95
- password: ''
96
- };
97
- const validationResult = (0, _.createValidation)({
98
- type: 'object',
99
- rules: {
100
- login: {
101
- type: 'required'
102
- }
103
- }
104
- })(validatedObject);
105
- expect(validationResult.errors).toEqual({
106
- login: ['Required']
107
- });
108
- expect(validationResult.data).toEqual(undefined);
109
- });
110
- it('supports property validation for valid object', () => {
111
- const validatedObject = {
112
- login: 'asd'
113
- };
114
- const validationResult = (0, _.createValidation)({
115
- type: 'object',
116
- rules: {
117
- login: {
118
- type: 'required'
119
- }
120
- }
121
- })(validatedObject);
122
- expect(validationResult.errors).toEqual(undefined);
123
- expect(validationResult.data).toEqual(validatedObject);
124
- });
125
- it('supports property validation for valid object and omits extra properties', () => {
126
- const validatedObject = {
127
- login: 'login',
128
- password: 'password'
129
- };
130
- const validationResult = (0, _.createValidation)({
131
- type: 'object',
132
- rules: {
133
- login: {
134
- type: 'required'
135
- }
136
- }
137
- })(validatedObject);
138
- expect(validationResult.errors).toEqual(undefined);
139
- expect(validationResult.data).toEqual({
140
- login: 'login'
141
- });
142
- });
143
- it('supports property validation for valid object and custom prop validation and omits extra properties', () => {
144
- const validatedObject = {
145
- login: 'login',
146
- password: 'password',
147
- 5: true,
148
- 123: true,
149
- '2020-03-05': {
150
- hz: 1
151
- }
152
- };
153
- const validationResult = (0, _.createValidation)({
154
- type: 'object',
155
- rules: {
156
- login: {
157
- type: 'required'
158
- }
159
- },
160
- customPropRules: [{
161
- nameRule: {
162
- type: 'number'
163
- },
164
- valueRule: {
165
- type: 'boolean'
166
- }
167
- }, {
168
- nameRule: {
169
- type: 'regex',
170
- regex: /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/
171
- },
172
- valueRule: {
173
- type: 'object'
174
- }
175
- }]
176
- })(validatedObject);
177
- expect(validationResult.errors).toEqual(undefined);
178
- expect(validationResult.data).toEqual({
179
- login: 'login',
180
- 5: true,
181
- 123: true,
182
- '2020-03-05': {
183
- hz: 1
184
- }
185
- });
186
- });
187
- it('supports property validation for valid object and only custom prop validation and omits extra properties', () => {
188
- const validatedObject = {
189
- login: 'login',
190
- password: 'password',
191
- 5: true,
192
- 123: true,
193
- '2020-03-05': {
194
- hz: 1
195
- },
196
- '2020-03-a2': 'skip'
197
- };
198
- const validationResult = (0, _.createValidation)({
199
- type: 'object',
200
- customPropRules: [{
201
- nameRule: {
202
- type: 'number'
203
- },
204
- valueRule: {
205
- type: 'boolean'
206
- }
207
- }, {
208
- nameRule: {
209
- type: 'regex',
210
- regex: /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/
211
- },
212
- valueRule: {
213
- type: 'object'
214
- }
215
- }]
216
- })(validatedObject);
217
- expect(validationResult.errors).toEqual(undefined);
218
- expect(validationResult.data).toEqual({
219
- 5: true,
220
- 123: true,
221
- '2020-03-05': {
222
- hz: 1
223
- }
224
- });
225
- });
226
- it('is beatiful', () => {
227
- const validatedObject = {
228
- weekly: {
229
- mon: {
230
- intervals: [{
231
- from: '09:00',
232
- to: '12:00'
233
- }, {
234
- from: '13:00',
235
- to: '21:00'
236
- }]
237
- },
238
- tue: {
239
- intervals: [{
240
- from: '09:00',
241
- to: '12:00'
242
- }, {
243
- from: '13:00',
244
- to: '21:00'
245
- }]
246
- },
247
- wed: {
248
- intervals: [{
249
- from: '09:00',
250
- to: '12:00'
251
- }, {
252
- from: '13:00',
253
- to: '21:00'
254
- }]
255
- },
256
- thu: {
257
- intervals: [{
258
- from: '09:00',
259
- to: '12:00'
260
- }, {
261
- from: '13:00',
262
- to: '21:00'
263
- }]
264
- },
265
- fri: {
266
- intervals: [{
267
- from: '09:00',
268
- to: '12:00'
269
- }, {
270
- from: '13:00',
271
- to: '21:00'
272
- }]
273
- },
274
- sat: {
275
- intervals: [{
276
- from: '09:00',
277
- to: '12:00'
278
- }, {
279
- from: '13:00',
280
- to: '17:00'
281
- }]
282
- },
283
- sun: {
284
- intervals: []
285
- }
286
- }
287
- };
288
- const daySchedule = {
289
- type: 'all',
290
- validators: [{
291
- type: 'required'
292
- }, {
293
- type: 'object',
294
- rules: {
295
- intervals: {
296
- type: 'all',
297
- validators: [{
298
- type: 'required'
299
- }, {
300
- type: 'array',
301
- itemRule: {
302
- type: 'all',
303
- validators: [{
304
- type: 'required'
305
- }, {
306
- type: 'object',
307
- rules: {
308
- from: {
309
- type: 'all',
310
- validators: [{
311
- type: 'required'
312
- }, {
313
- type: 'regex',
314
- regex: /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
315
- }]
316
- },
317
- to: {
318
- type: 'all',
319
- validators: [{
320
- type: 'required'
321
- }, {
322
- type: 'regex',
323
- regex: /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
324
- }]
325
- }
326
- }
327
- }]
328
- }
329
- }]
330
- }
331
- }
332
- }]
333
- };
334
- const validationResult = (0, _.createValidation)({
335
- type: 'object',
336
- rules: {
337
- weekly: {
338
- type: 'all',
339
- validators: [{
340
- type: 'required'
341
- }, {
342
- type: 'object',
343
- rules: {
344
- mon: daySchedule,
345
- tue: daySchedule,
346
- wed: daySchedule,
347
- thu: daySchedule,
348
- fri: daySchedule,
349
- sat: daySchedule,
350
- sun: daySchedule
351
- }
352
- }]
353
- }
354
- }
355
- })(validatedObject);
356
- expect(validationResult.errors).toEqual(undefined);
357
- expect(validationResult.data).toEqual({
358
- weekly: {
359
- mon: {
360
- intervals: [{
361
- from: '09:00',
362
- to: '12:00'
363
- }, {
364
- from: '13:00',
365
- to: '21:00'
366
- }]
367
- },
368
- tue: {
369
- intervals: [{
370
- from: '09:00',
371
- to: '12:00'
372
- }, {
373
- from: '13:00',
374
- to: '21:00'
375
- }]
376
- },
377
- wed: {
378
- intervals: [{
379
- from: '09:00',
380
- to: '12:00'
381
- }, {
382
- from: '13:00',
383
- to: '21:00'
384
- }]
385
- },
386
- thu: {
387
- intervals: [{
388
- from: '09:00',
389
- to: '12:00'
390
- }, {
391
- from: '13:00',
392
- to: '21:00'
393
- }]
394
- },
395
- fri: {
396
- intervals: [{
397
- from: '09:00',
398
- to: '12:00'
399
- }, {
400
- from: '13:00',
401
- to: '21:00'
402
- }]
403
- },
404
- sat: {
405
- intervals: [{
406
- from: '09:00',
407
- to: '12:00'
408
- }, {
409
- from: '13:00',
410
- to: '17:00'
411
- }]
412
- },
413
- sun: {
414
- intervals: []
415
- }
416
- }
417
- });
418
- });
419
- it('supports property validation for invalidvalid object and custom prop validation and omits extra properties', () => {
420
- const validatedObject = {
421
- login: 'login',
422
- password: 'password',
423
- 5: true,
424
- 123: true,
425
- 562: 'wrong'
426
- };
427
- const validationResult = (0, _.createValidation)({
428
- type: 'object',
429
- rules: {
430
- login: {
431
- type: 'required'
432
- }
433
- },
434
- customPropRules: [{
435
- nameRule: {
436
- type: 'number'
437
- },
438
- valueRule: {
439
- type: 'boolean'
440
- }
441
- }]
442
- })(validatedObject);
443
- expect(validationResult.errors).toEqual({
444
- 562: ['Must be a boolean']
445
- });
446
- expect(validationResult.data).toEqual({
447
- login: 'login',
448
- 5: true,
449
- 123: true
450
- });
451
- });
452
- const objectWithInnerObjectValidation = (0, _.createValidation)({
453
- type: 'object',
454
- rules: {
455
- login: {
456
- type: 'required'
457
- },
458
- profile: {
459
- type: 'object',
460
- rules: {
461
- firstName: {
462
- type: 'required'
463
- },
464
- lastName: {
465
- type: 'required'
466
- }
467
- }
468
- }
469
- }
470
- });
471
- it('supports validation and filtering of inner object', () => {
472
- const validatedObject = {
473
- login: 'login',
474
- password: 'password',
475
- profile: {
476
- firstName: 'firstName',
477
- lastName: 'lastName',
478
- age: 23
479
- }
480
- };
481
- const validationResult = objectWithInnerObjectValidation(validatedObject);
482
- expect(validationResult.errors).toEqual(undefined);
483
- expect(validationResult.data).toEqual({
484
- login: 'login',
485
- profile: {
486
- firstName: 'firstName',
487
- lastName: 'lastName'
488
- }
489
- });
490
- });
491
- it('supports errors + filtering of inner object', () => {
492
- const validatedObject = {
493
- login: 'login',
494
- password: 'password',
495
- profile: {
496
- firstName: 'firstName',
497
- lastName: null,
498
- age: 23
499
- }
500
- };
501
- const validationResult = objectWithInnerObjectValidation(validatedObject);
502
- expect(validationResult.errors).toEqual({
503
- profile: {
504
- lastName: ['Required']
505
- }
506
- });
507
- expect(validationResult.data).toEqual({
508
- login: 'login',
509
- profile: {
510
- firstName: 'firstName'
511
- }
512
- });
513
- });
514
- const objectWithInnerArrayValidation = (0, _.createValidation)({
515
- type: 'object',
516
- rules: {
517
- login: {
518
- type: 'required'
519
- },
520
- tags: {
521
- type: 'array',
522
- itemRule: {
523
- type: 'required'
524
- }
525
- }
526
- }
527
- });
528
- it('supports validation of inner array', () => {
529
- const validatedObject = {
530
- login: 'login',
531
- password: 'password',
532
- tags: [1, true, [], {}]
533
- };
534
- const validationResult = objectWithInnerArrayValidation(validatedObject);
535
- expect(validationResult.errors).toEqual(undefined);
536
- expect(validationResult.data).toEqual({
537
- login: 'login',
538
- tags: [1, true, [], {}]
539
- });
540
- });
541
- it('supports errors + filtering of inner array', () => {
542
- const validatedObject = {
543
- login: 'login',
544
- password: 'password',
545
- tags: [1, true, null, 5, {}, null]
546
- };
547
- const validationResult = objectWithInnerArrayValidation(validatedObject);
548
- expect(validationResult.errors).toEqual({
549
- tags: [null, null, ['Required'], null, null, ['Required']]
550
- });
551
- expect(validationResult.data).toEqual({
552
- login: 'login',
553
- tags: [1, true, 5, {}]
554
- });
555
- });
556
- });
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _ = require("..");
4
-
5
- describe('createReduxFormValidation', () => {
6
- it('supports property validation for invalid object', () => {
7
- const validatedObject = {
8
- login: ''
9
- };
10
- const validate = (0, _.createReduxFormValidation)({
11
- login: {
12
- type: 'required'
13
- }
14
- });
15
- const validationResult = validate(validatedObject);
16
- expect(validationResult).toEqual({
17
- login: ['Required']
18
- });
19
- });
20
- });