@nocobase/plugin-workflow-date-calculation 2.1.0-alpha.10 → 2.1.0-alpha.11

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 (42) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/externalVersion.js +5 -5
  3. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  4. package/dist/node_modules/joi/lib/annotate.js +175 -0
  5. package/dist/node_modules/joi/lib/base.js +1069 -0
  6. package/dist/node_modules/joi/lib/cache.js +143 -0
  7. package/dist/node_modules/joi/lib/common.js +216 -0
  8. package/dist/node_modules/joi/lib/compile.js +283 -0
  9. package/dist/node_modules/joi/lib/errors.js +271 -0
  10. package/dist/node_modules/joi/lib/extend.js +312 -0
  11. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  12. package/dist/node_modules/joi/lib/index.js +1 -0
  13. package/dist/node_modules/joi/lib/manifest.js +476 -0
  14. package/dist/node_modules/joi/lib/messages.js +178 -0
  15. package/dist/node_modules/joi/lib/modify.js +267 -0
  16. package/dist/node_modules/joi/lib/ref.js +414 -0
  17. package/dist/node_modules/joi/lib/schemas.js +302 -0
  18. package/dist/node_modules/joi/lib/state.js +166 -0
  19. package/dist/node_modules/joi/lib/template.js +463 -0
  20. package/dist/node_modules/joi/lib/trace.js +346 -0
  21. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  22. package/dist/node_modules/joi/lib/types/any.js +174 -0
  23. package/dist/node_modules/joi/lib/types/array.js +809 -0
  24. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  25. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  26. package/dist/node_modules/joi/lib/types/date.js +233 -0
  27. package/dist/node_modules/joi/lib/types/function.js +93 -0
  28. package/dist/node_modules/joi/lib/types/keys.js +1067 -0
  29. package/dist/node_modules/joi/lib/types/link.js +168 -0
  30. package/dist/node_modules/joi/lib/types/number.js +363 -0
  31. package/dist/node_modules/joi/lib/types/object.js +22 -0
  32. package/dist/node_modules/joi/lib/types/string.js +850 -0
  33. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  34. package/dist/node_modules/joi/lib/validator.js +750 -0
  35. package/dist/node_modules/joi/lib/values.js +263 -0
  36. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  37. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  38. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  39. package/dist/node_modules/joi/package.json +1 -0
  40. package/dist/server/DateCalculationInstruction.d.ts +2 -0
  41. package/dist/server/DateCalculationInstruction.js +5 -0
  42. package/package.json +3 -2
@@ -0,0 +1,1069 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+ const Clone = require('@hapi/hoek/lib/clone');
5
+ const DeepEqual = require('@hapi/hoek/lib/deepEqual');
6
+ const Merge = require('@hapi/hoek/lib/merge');
7
+
8
+ const Cache = require('./cache');
9
+ const Common = require('./common');
10
+ const Compile = require('./compile');
11
+ const Errors = require('./errors');
12
+ const Extend = require('./extend');
13
+ const Manifest = require('./manifest');
14
+ const Messages = require('./messages');
15
+ const Modify = require('./modify');
16
+ const Ref = require('./ref');
17
+ const Trace = require('./trace');
18
+ const Validator = require('./validator');
19
+ const Values = require('./values');
20
+
21
+
22
+ const internals = {};
23
+
24
+
25
+ internals.Base = class {
26
+
27
+ constructor(type) {
28
+
29
+ // Naming: public, _private, $_extension, $_mutate{action}
30
+
31
+ this.type = type;
32
+
33
+ this.$_root = null;
34
+ this._definition = {};
35
+ this._reset();
36
+ }
37
+
38
+ _reset() {
39
+
40
+ this._ids = new Modify.Ids();
41
+ this._preferences = null;
42
+ this._refs = new Ref.Manager();
43
+ this._cache = null;
44
+
45
+ this._valids = null;
46
+ this._invalids = null;
47
+
48
+ this._flags = {};
49
+ this._rules = [];
50
+ this._singleRules = new Map(); // The rule options passed for non-multi rules
51
+
52
+ this.$_terms = {}; // Hash of arrays of immutable objects (extended by other types)
53
+
54
+ this.$_temp = { // Runtime state (not cloned)
55
+ ruleset: null, // null: use last, false: error, number: start position
56
+ whens: {} // Runtime cache of generated whens
57
+ };
58
+ }
59
+
60
+ // Manifest
61
+
62
+ describe() {
63
+
64
+ Assert(typeof Manifest.describe === 'function', 'Manifest functionality disabled');
65
+ return Manifest.describe(this);
66
+ }
67
+
68
+ // Rules
69
+
70
+ allow(...values) {
71
+
72
+ Common.verifyFlat(values, 'allow');
73
+ return this._values(values, '_valids');
74
+ }
75
+
76
+ alter(targets) {
77
+
78
+ Assert(targets && typeof targets === 'object' && !Array.isArray(targets), 'Invalid targets argument');
79
+ Assert(!this._inRuleset(), 'Cannot set alterations inside a ruleset');
80
+
81
+ const obj = this.clone();
82
+ obj.$_terms.alterations = obj.$_terms.alterations || [];
83
+ for (const target in targets) {
84
+ const adjuster = targets[target];
85
+ Assert(typeof adjuster === 'function', 'Alteration adjuster for', target, 'must be a function');
86
+ obj.$_terms.alterations.push({ target, adjuster });
87
+ }
88
+
89
+ obj.$_temp.ruleset = false;
90
+ return obj;
91
+ }
92
+
93
+ artifact(id) {
94
+
95
+ Assert(id !== undefined, 'Artifact cannot be undefined');
96
+ Assert(!this._cache, 'Cannot set an artifact with a rule cache');
97
+
98
+ return this.$_setFlag('artifact', id);
99
+ }
100
+
101
+ cast(to) {
102
+
103
+ Assert(to === false || typeof to === 'string', 'Invalid to value');
104
+ Assert(to === false || this._definition.cast[to], 'Type', this.type, 'does not support casting to', to);
105
+
106
+ return this.$_setFlag('cast', to === false ? undefined : to);
107
+ }
108
+
109
+ default(value, options) {
110
+
111
+ return this._default('default', value, options);
112
+ }
113
+
114
+ description(desc) {
115
+
116
+ Assert(desc && typeof desc === 'string', 'Description must be a non-empty string');
117
+
118
+ return this.$_setFlag('description', desc);
119
+ }
120
+
121
+ empty(schema) {
122
+
123
+ const obj = this.clone();
124
+
125
+ if (schema !== undefined) {
126
+ schema = obj.$_compile(schema, { override: false });
127
+ }
128
+
129
+ return obj.$_setFlag('empty', schema, { clone: false });
130
+ }
131
+
132
+ error(err) {
133
+
134
+ Assert(err, 'Missing error');
135
+ Assert(err instanceof Error || typeof err === 'function', 'Must provide a valid Error object or a function');
136
+
137
+ return this.$_setFlag('error', err);
138
+ }
139
+
140
+ example(example, options = {}) {
141
+
142
+ Assert(example !== undefined, 'Missing example');
143
+ Common.assertOptions(options, ['override']);
144
+
145
+ return this._inner('examples', example, { single: true, override: options.override });
146
+ }
147
+
148
+ external(method, description) {
149
+
150
+ if (typeof method === 'object') {
151
+ Assert(!description, 'Cannot combine options with description');
152
+ description = method.description;
153
+ method = method.method;
154
+ }
155
+
156
+ Assert(typeof method === 'function', 'Method must be a function');
157
+ Assert(description === undefined || description && typeof description === 'string', 'Description must be a non-empty string');
158
+
159
+ return this._inner('externals', { method, description }, { single: true });
160
+ }
161
+
162
+ failover(value, options) {
163
+
164
+ return this._default('failover', value, options);
165
+ }
166
+
167
+ forbidden() {
168
+
169
+ return this.presence('forbidden');
170
+ }
171
+
172
+ id(id) {
173
+
174
+ if (!id) {
175
+ return this.$_setFlag('id', undefined);
176
+ }
177
+
178
+ Assert(typeof id === 'string', 'id must be a non-empty string');
179
+ Assert(/^[^\.]+$/.test(id), 'id cannot contain period character');
180
+
181
+ return this.$_setFlag('id', id);
182
+ }
183
+
184
+ invalid(...values) {
185
+
186
+ return this._values(values, '_invalids');
187
+ }
188
+
189
+ label(name) {
190
+
191
+ Assert(name && typeof name === 'string', 'Label name must be a non-empty string');
192
+
193
+ return this.$_setFlag('label', name);
194
+ }
195
+
196
+ meta(meta) {
197
+
198
+ Assert(meta !== undefined, 'Meta cannot be undefined');
199
+
200
+ return this._inner('metas', meta, { single: true });
201
+ }
202
+
203
+ note(...notes) {
204
+
205
+ Assert(notes.length, 'Missing notes');
206
+ for (const note of notes) {
207
+ Assert(note && typeof note === 'string', 'Notes must be non-empty strings');
208
+ }
209
+
210
+ return this._inner('notes', notes);
211
+ }
212
+
213
+ only(mode = true) {
214
+
215
+ Assert(typeof mode === 'boolean', 'Invalid mode:', mode);
216
+
217
+ return this.$_setFlag('only', mode);
218
+ }
219
+
220
+ optional() {
221
+
222
+ return this.presence('optional');
223
+ }
224
+
225
+ prefs(prefs) {
226
+
227
+ Assert(prefs, 'Missing preferences');
228
+ Assert(prefs.context === undefined, 'Cannot override context');
229
+ Assert(prefs.externals === undefined, 'Cannot override externals');
230
+ Assert(prefs.warnings === undefined, 'Cannot override warnings');
231
+ Assert(prefs.debug === undefined, 'Cannot override debug');
232
+
233
+ Common.checkPreferences(prefs);
234
+
235
+ const obj = this.clone();
236
+ obj._preferences = Common.preferences(obj._preferences, prefs);
237
+ return obj;
238
+ }
239
+
240
+ presence(mode) {
241
+
242
+ Assert(['optional', 'required', 'forbidden'].includes(mode), 'Unknown presence mode', mode);
243
+
244
+ return this.$_setFlag('presence', mode);
245
+ }
246
+
247
+ raw(enabled = true) {
248
+
249
+ return this.$_setFlag('result', enabled ? 'raw' : undefined);
250
+ }
251
+
252
+ result(mode) {
253
+
254
+ Assert(['raw', 'strip'].includes(mode), 'Unknown result mode', mode);
255
+
256
+ return this.$_setFlag('result', mode);
257
+ }
258
+
259
+ required() {
260
+
261
+ return this.presence('required');
262
+ }
263
+
264
+ strict(enabled) {
265
+
266
+ const obj = this.clone();
267
+
268
+ const convert = enabled === undefined ? false : !enabled;
269
+ obj._preferences = Common.preferences(obj._preferences, { convert });
270
+ return obj;
271
+ }
272
+
273
+ strip(enabled = true) {
274
+
275
+ return this.$_setFlag('result', enabled ? 'strip' : undefined);
276
+ }
277
+
278
+ tag(...tags) {
279
+
280
+ Assert(tags.length, 'Missing tags');
281
+ for (const tag of tags) {
282
+ Assert(tag && typeof tag === 'string', 'Tags must be non-empty strings');
283
+ }
284
+
285
+ return this._inner('tags', tags);
286
+ }
287
+
288
+ unit(name) {
289
+
290
+ Assert(name && typeof name === 'string', 'Unit name must be a non-empty string');
291
+
292
+ return this.$_setFlag('unit', name);
293
+ }
294
+
295
+ valid(...values) {
296
+
297
+ Common.verifyFlat(values, 'valid');
298
+
299
+ const obj = this.allow(...values);
300
+ obj.$_setFlag('only', !!obj._valids, { clone: false });
301
+ return obj;
302
+ }
303
+
304
+ when(condition, options) {
305
+
306
+ const obj = this.clone();
307
+
308
+ if (!obj.$_terms.whens) {
309
+ obj.$_terms.whens = [];
310
+ }
311
+
312
+ const when = Compile.when(obj, condition, options);
313
+ if (!['any', 'link'].includes(obj.type)) {
314
+ const conditions = when.is ? [when] : when.switch;
315
+ for (const item of conditions) {
316
+ Assert(!item.then || item.then.type === 'any' || item.then.type === obj.type, 'Cannot combine', obj.type, 'with', item.then && item.then.type);
317
+ Assert(!item.otherwise || item.otherwise.type === 'any' || item.otherwise.type === obj.type, 'Cannot combine', obj.type, 'with', item.otherwise && item.otherwise.type);
318
+
319
+ }
320
+ }
321
+
322
+ obj.$_terms.whens.push(when);
323
+ return obj.$_mutateRebuild();
324
+ }
325
+
326
+ // Helpers
327
+
328
+ cache(cache) {
329
+
330
+ Assert(!this._inRuleset(), 'Cannot set caching inside a ruleset');
331
+ Assert(!this._cache, 'Cannot override schema cache');
332
+ Assert(this._flags.artifact === undefined, 'Cannot cache a rule with an artifact');
333
+
334
+ const obj = this.clone();
335
+ obj._cache = cache || Cache.provider.provision();
336
+ obj.$_temp.ruleset = false;
337
+ return obj;
338
+ }
339
+
340
+ clone() {
341
+
342
+ const obj = Object.create(Object.getPrototypeOf(this));
343
+ return this._assign(obj);
344
+ }
345
+
346
+ concat(source) {
347
+
348
+ Assert(Common.isSchema(source), 'Invalid schema object');
349
+ Assert(this.type === 'any' || source.type === 'any' || source.type === this.type, 'Cannot merge type', this.type, 'with another type:', source.type);
350
+ Assert(!this._inRuleset(), 'Cannot concatenate onto a schema with open ruleset');
351
+ Assert(!source._inRuleset(), 'Cannot concatenate a schema with open ruleset');
352
+
353
+ let obj = this.clone();
354
+
355
+ if (this.type === 'any' &&
356
+ source.type !== 'any') {
357
+
358
+ // Change obj to match source type
359
+
360
+ const tmpObj = source.clone();
361
+ for (const key of Object.keys(obj)) {
362
+ if (key !== 'type') {
363
+ tmpObj[key] = obj[key];
364
+ }
365
+ }
366
+
367
+ obj = tmpObj;
368
+ }
369
+
370
+ obj._ids.concat(source._ids);
371
+ obj._refs.register(source, Ref.toSibling);
372
+
373
+ obj._preferences = obj._preferences ? Common.preferences(obj._preferences, source._preferences) : source._preferences;
374
+ obj._valids = Values.merge(obj._valids, source._valids, source._invalids);
375
+ obj._invalids = Values.merge(obj._invalids, source._invalids, source._valids);
376
+
377
+ // Remove unique rules present in source
378
+
379
+ for (const name of source._singleRules.keys()) {
380
+ if (obj._singleRules.has(name)) {
381
+ obj._rules = obj._rules.filter((target) => target.keep || target.name !== name);
382
+ obj._singleRules.delete(name);
383
+ }
384
+ }
385
+
386
+ // Rules
387
+
388
+ for (const test of source._rules) {
389
+ if (!source._definition.rules[test.method].multi) {
390
+ obj._singleRules.set(test.name, test);
391
+ }
392
+
393
+ obj._rules.push(test);
394
+ }
395
+
396
+ // Flags
397
+
398
+ if (obj._flags.empty &&
399
+ source._flags.empty) {
400
+
401
+ obj._flags.empty = obj._flags.empty.concat(source._flags.empty);
402
+ const flags = Object.assign({}, source._flags);
403
+ delete flags.empty;
404
+ Merge(obj._flags, flags);
405
+ }
406
+ else if (source._flags.empty) {
407
+ obj._flags.empty = source._flags.empty;
408
+ const flags = Object.assign({}, source._flags);
409
+ delete flags.empty;
410
+ Merge(obj._flags, flags);
411
+ }
412
+ else {
413
+ Merge(obj._flags, source._flags);
414
+ }
415
+
416
+ // Terms
417
+
418
+ for (const key in source.$_terms) {
419
+ const terms = source.$_terms[key];
420
+ if (!terms) {
421
+ if (!obj.$_terms[key]) {
422
+ obj.$_terms[key] = terms;
423
+ }
424
+
425
+ continue;
426
+ }
427
+
428
+ if (!obj.$_terms[key]) {
429
+ obj.$_terms[key] = terms.slice();
430
+ continue;
431
+ }
432
+
433
+ obj.$_terms[key] = obj.$_terms[key].concat(terms);
434
+ }
435
+
436
+ // Tracing
437
+
438
+ if (this.$_root._tracer) {
439
+ this.$_root._tracer._combine(obj, [this, source]);
440
+ }
441
+
442
+ // Rebuild
443
+
444
+ return obj.$_mutateRebuild();
445
+ }
446
+
447
+ extend(options) {
448
+
449
+ Assert(!options.base, 'Cannot extend type with another base');
450
+
451
+ return Extend.type(this, options);
452
+ }
453
+
454
+ extract(path) {
455
+
456
+ path = Array.isArray(path) ? path : path.split('.');
457
+ return this._ids.reach(path);
458
+ }
459
+
460
+ fork(paths, adjuster) {
461
+
462
+ Assert(!this._inRuleset(), 'Cannot fork inside a ruleset');
463
+
464
+ let obj = this; // eslint-disable-line consistent-this
465
+ for (let path of [].concat(paths)) {
466
+ path = Array.isArray(path) ? path : path.split('.');
467
+ obj = obj._ids.fork(path, adjuster, obj);
468
+ }
469
+
470
+ obj.$_temp.ruleset = false;
471
+ return obj;
472
+ }
473
+
474
+ rule(options) {
475
+
476
+ const def = this._definition;
477
+ Common.assertOptions(options, Object.keys(def.modifiers));
478
+
479
+ Assert(this.$_temp.ruleset !== false, 'Cannot apply rules to empty ruleset or the last rule added does not support rule properties');
480
+ const start = this.$_temp.ruleset === null ? this._rules.length - 1 : this.$_temp.ruleset;
481
+ Assert(start >= 0 && start < this._rules.length, 'Cannot apply rules to empty ruleset');
482
+
483
+ const obj = this.clone();
484
+
485
+ for (let i = start; i < obj._rules.length; ++i) {
486
+ const original = obj._rules[i];
487
+ const rule = Clone(original);
488
+
489
+ for (const name in options) {
490
+ def.modifiers[name](rule, options[name]);
491
+ Assert(rule.name === original.name, 'Cannot change rule name');
492
+ }
493
+
494
+ obj._rules[i] = rule;
495
+
496
+ if (obj._singleRules.get(rule.name) === original) {
497
+ obj._singleRules.set(rule.name, rule);
498
+ }
499
+ }
500
+
501
+ obj.$_temp.ruleset = false;
502
+ return obj.$_mutateRebuild();
503
+ }
504
+
505
+ get ruleset() {
506
+
507
+ Assert(!this._inRuleset(), 'Cannot start a new ruleset without closing the previous one');
508
+
509
+ const obj = this.clone();
510
+ obj.$_temp.ruleset = obj._rules.length;
511
+ return obj;
512
+ }
513
+
514
+ get $() {
515
+
516
+ return this.ruleset;
517
+ }
518
+
519
+ tailor(targets) {
520
+
521
+ targets = [].concat(targets);
522
+
523
+ Assert(!this._inRuleset(), 'Cannot tailor inside a ruleset');
524
+
525
+ let obj = this; // eslint-disable-line consistent-this
526
+
527
+ if (this.$_terms.alterations) {
528
+ for (const { target, adjuster } of this.$_terms.alterations) {
529
+ if (targets.includes(target)) {
530
+ obj = adjuster(obj);
531
+ Assert(Common.isSchema(obj), 'Alteration adjuster for', target, 'failed to return a schema object');
532
+ }
533
+ }
534
+ }
535
+
536
+ obj = obj.$_modify({ each: (item) => item.tailor(targets), ref: false });
537
+ obj.$_temp.ruleset = false;
538
+ return obj.$_mutateRebuild();
539
+ }
540
+
541
+ tracer() {
542
+
543
+ return Trace.location ? Trace.location(this) : this; // $lab:coverage:ignore$
544
+ }
545
+
546
+ validate(value, options) {
547
+
548
+ return Validator.entry(value, this, options);
549
+ }
550
+
551
+ validateAsync(value, options) {
552
+
553
+ return Validator.entryAsync(value, this, options);
554
+ }
555
+
556
+ // Extensions
557
+
558
+ $_addRule(options) {
559
+
560
+ // Normalize rule
561
+
562
+ if (typeof options === 'string') {
563
+ options = { name: options };
564
+ }
565
+
566
+ Assert(options && typeof options === 'object', 'Invalid options');
567
+ Assert(options.name && typeof options.name === 'string', 'Invalid rule name');
568
+
569
+ for (const key in options) {
570
+ Assert(key[0] !== '_', 'Cannot set private rule properties');
571
+ }
572
+
573
+ const rule = Object.assign({}, options); // Shallow cloned
574
+ rule._resolve = [];
575
+ rule.method = rule.method || rule.name;
576
+
577
+ const definition = this._definition.rules[rule.method];
578
+ const args = rule.args;
579
+
580
+ Assert(definition, 'Unknown rule', rule.method);
581
+
582
+ // Args
583
+
584
+ const obj = this.clone();
585
+
586
+ if (args) {
587
+ Assert(Object.keys(args).length === 1 || Object.keys(args).length === this._definition.rules[rule.name].args.length, 'Invalid rule definition for', this.type, rule.name);
588
+
589
+ for (const key in args) {
590
+ let arg = args[key];
591
+
592
+ if (definition.argsByName) {
593
+ const resolver = definition.argsByName.get(key);
594
+
595
+ if (resolver.ref &&
596
+ Common.isResolvable(arg)) {
597
+
598
+ rule._resolve.push(key);
599
+ obj.$_mutateRegister(arg);
600
+ }
601
+ else {
602
+ if (resolver.normalize) {
603
+ arg = resolver.normalize(arg);
604
+ args[key] = arg;
605
+ }
606
+
607
+ if (resolver.assert) {
608
+ const error = Common.validateArg(arg, key, resolver);
609
+ Assert(!error, error, 'or reference');
610
+ }
611
+ }
612
+ }
613
+
614
+ if (arg === undefined) {
615
+ delete args[key];
616
+ continue;
617
+ }
618
+
619
+ args[key] = arg;
620
+ }
621
+ }
622
+
623
+ // Unique rules
624
+
625
+ if (!definition.multi) {
626
+ obj._ruleRemove(rule.name, { clone: false });
627
+ obj._singleRules.set(rule.name, rule);
628
+ }
629
+
630
+ if (obj.$_temp.ruleset === false) {
631
+ obj.$_temp.ruleset = null;
632
+ }
633
+
634
+ if (definition.priority) {
635
+ obj._rules.unshift(rule);
636
+ }
637
+ else {
638
+ obj._rules.push(rule);
639
+ }
640
+
641
+ return obj;
642
+ }
643
+
644
+ $_compile(schema, options) {
645
+
646
+ return Compile.schema(this.$_root, schema, options);
647
+ }
648
+
649
+ $_createError(code, value, local, state, prefs, options = {}) {
650
+
651
+ const flags = options.flags !== false ? this._flags : {};
652
+ const messages = options.messages ? Messages.merge(this._definition.messages, options.messages) : this._definition.messages;
653
+ return new Errors.Report(code, value, local, flags, messages, state, prefs);
654
+ }
655
+
656
+ $_getFlag(name) {
657
+
658
+ return this._flags[name];
659
+ }
660
+
661
+ $_getRule(name) {
662
+
663
+ return this._singleRules.get(name);
664
+ }
665
+
666
+ $_mapLabels(path) {
667
+
668
+ path = Array.isArray(path) ? path : path.split('.');
669
+ return this._ids.labels(path);
670
+ }
671
+
672
+ $_match(value, state, prefs, overrides) {
673
+
674
+ prefs = Object.assign({}, prefs); // Shallow cloned
675
+ prefs.abortEarly = true;
676
+ prefs._externals = false;
677
+
678
+ state.snapshot();
679
+ const result = !Validator.validate(value, this, state, prefs, overrides).errors;
680
+ state.restore();
681
+
682
+ return result;
683
+ }
684
+
685
+ $_modify(options) {
686
+
687
+ Common.assertOptions(options, ['each', 'once', 'ref', 'schema']);
688
+ return Modify.schema(this, options) || this;
689
+ }
690
+
691
+ $_mutateRebuild() {
692
+
693
+ Assert(!this._inRuleset(), 'Cannot add this rule inside a ruleset');
694
+
695
+ this._refs.reset();
696
+ this._ids.reset();
697
+
698
+ const each = (item, { source, name, path, key }) => {
699
+
700
+ const family = this._definition[source][name] && this._definition[source][name].register;
701
+ if (family !== false) {
702
+ this.$_mutateRegister(item, { family, key });
703
+ }
704
+ };
705
+
706
+ this.$_modify({ each });
707
+
708
+ if (this._definition.rebuild) {
709
+ this._definition.rebuild(this);
710
+ }
711
+
712
+ this.$_temp.ruleset = false;
713
+ return this;
714
+ }
715
+
716
+ $_mutateRegister(schema, { family, key } = {}) {
717
+
718
+ this._refs.register(schema, family);
719
+ this._ids.register(schema, { key });
720
+ }
721
+
722
+ $_property(name) {
723
+
724
+ return this._definition.properties[name];
725
+ }
726
+
727
+ $_reach(path) {
728
+
729
+ return this._ids.reach(path);
730
+ }
731
+
732
+ $_rootReferences() {
733
+
734
+ return this._refs.roots();
735
+ }
736
+
737
+ $_setFlag(name, value, options = {}) {
738
+
739
+ Assert(name[0] === '_' || !this._inRuleset(), 'Cannot set flag inside a ruleset');
740
+
741
+ const flag = this._definition.flags[name] || {};
742
+ if (DeepEqual(value, flag.default)) {
743
+ value = undefined;
744
+ }
745
+
746
+ if (DeepEqual(value, this._flags[name])) {
747
+ return this;
748
+ }
749
+
750
+ const obj = options.clone !== false ? this.clone() : this;
751
+
752
+ if (value !== undefined) {
753
+ obj._flags[name] = value;
754
+ obj.$_mutateRegister(value);
755
+ }
756
+ else {
757
+ delete obj._flags[name];
758
+ }
759
+
760
+ if (name[0] !== '_') {
761
+ obj.$_temp.ruleset = false;
762
+ }
763
+
764
+ return obj;
765
+ }
766
+
767
+ $_parent(method, ...args) {
768
+
769
+ return this[method][Common.symbols.parent].call(this, ...args);
770
+ }
771
+
772
+ $_validate(value, state, prefs) {
773
+
774
+ return Validator.validate(value, this, state, prefs);
775
+ }
776
+
777
+ // Internals
778
+
779
+ _assign(target) {
780
+
781
+ target.type = this.type;
782
+
783
+ target.$_root = this.$_root;
784
+
785
+ target.$_temp = Object.assign({}, this.$_temp);
786
+ target.$_temp.whens = {};
787
+
788
+ target._ids = this._ids.clone();
789
+ target._preferences = this._preferences;
790
+ target._valids = this._valids && this._valids.clone();
791
+ target._invalids = this._invalids && this._invalids.clone();
792
+ target._rules = this._rules.slice();
793
+ target._singleRules = Clone(this._singleRules, { shallow: true });
794
+ target._refs = this._refs.clone();
795
+ target._flags = Object.assign({}, this._flags);
796
+ target._cache = null;
797
+
798
+ target.$_terms = {};
799
+ for (const key in this.$_terms) {
800
+ target.$_terms[key] = this.$_terms[key] ? this.$_terms[key].slice() : null;
801
+ }
802
+
803
+ // Backwards compatibility
804
+
805
+ target.$_super = {};
806
+ for (const override in this.$_super) {
807
+ target.$_super[override] = this._super[override].bind(target);
808
+ }
809
+
810
+ return target;
811
+ }
812
+
813
+ _bare() {
814
+
815
+ const obj = this.clone();
816
+ obj._reset();
817
+
818
+ const terms = obj._definition.terms;
819
+ for (const name in terms) {
820
+ const term = terms[name];
821
+ obj.$_terms[name] = term.init;
822
+ }
823
+
824
+ return obj.$_mutateRebuild();
825
+ }
826
+
827
+ _default(flag, value, options = {}) {
828
+
829
+ Common.assertOptions(options, 'literal');
830
+
831
+ Assert(value !== undefined, 'Missing', flag, 'value');
832
+ Assert(typeof value === 'function' || !options.literal, 'Only function value supports literal option');
833
+
834
+ if (typeof value === 'function' &&
835
+ options.literal) {
836
+
837
+ value = {
838
+ [Common.symbols.literal]: true,
839
+ literal: value
840
+ };
841
+ }
842
+
843
+ const obj = this.$_setFlag(flag, value);
844
+ return obj;
845
+ }
846
+
847
+ _generate(value, state, prefs) {
848
+
849
+ if (!this.$_terms.whens) {
850
+ return { schema: this };
851
+ }
852
+
853
+ // Collect matching whens
854
+
855
+ const whens = [];
856
+ const ids = [];
857
+ for (let i = 0; i < this.$_terms.whens.length; ++i) {
858
+ const when = this.$_terms.whens[i];
859
+
860
+ if (when.concat) {
861
+ whens.push(when.concat);
862
+ ids.push(`${i}.concat`);
863
+ continue;
864
+ }
865
+
866
+ const input = when.ref ? when.ref.resolve(value, state, prefs) : value;
867
+ const tests = when.is ? [when] : when.switch;
868
+ const before = ids.length;
869
+
870
+ for (let j = 0; j < tests.length; ++j) {
871
+ const { is, then, otherwise } = tests[j];
872
+
873
+ const baseId = `${i}${when.switch ? '.' + j : ''}`;
874
+ if (is.$_match(input, state.nest(is, `${baseId}.is`), prefs)) {
875
+ if (then) {
876
+ const localState = state.localize([...state.path, `${baseId}.then`], state.ancestors, state.schemas);
877
+ const { schema: generated, id } = then._generate(value, localState, prefs);
878
+ whens.push(generated);
879
+ ids.push(`${baseId}.then${id ? `(${id})` : ''}`);
880
+ break;
881
+ }
882
+ }
883
+ else if (otherwise) {
884
+ const localState = state.localize([...state.path, `${baseId}.otherwise`], state.ancestors, state.schemas);
885
+ const { schema: generated, id } = otherwise._generate(value, localState, prefs);
886
+ whens.push(generated);
887
+ ids.push(`${baseId}.otherwise${id ? `(${id})` : ''}`);
888
+ break;
889
+ }
890
+ }
891
+
892
+ if (when.break &&
893
+ ids.length > before) { // Something matched
894
+
895
+ break;
896
+ }
897
+ }
898
+
899
+ // Check cache
900
+
901
+ const id = ids.join(', ');
902
+ state.mainstay.tracer.debug(state, 'rule', 'when', id);
903
+
904
+ if (!id) {
905
+ return { schema: this };
906
+ }
907
+
908
+ if (!state.mainstay.tracer.active &&
909
+ this.$_temp.whens[id]) {
910
+
911
+ return { schema: this.$_temp.whens[id], id };
912
+ }
913
+
914
+ // Generate dynamic schema
915
+
916
+ let obj = this; // eslint-disable-line consistent-this
917
+ if (this._definition.generate) {
918
+ obj = this._definition.generate(this, value, state, prefs);
919
+ }
920
+
921
+ // Apply whens
922
+
923
+ for (const when of whens) {
924
+ obj = obj.concat(when);
925
+ }
926
+
927
+ // Tracing
928
+
929
+ if (this.$_root._tracer) {
930
+ this.$_root._tracer._combine(obj, [this, ...whens]);
931
+ }
932
+
933
+ // Cache result
934
+
935
+ this.$_temp.whens[id] = obj;
936
+ return { schema: obj, id };
937
+ }
938
+
939
+ _inner(type, values, options = {}) {
940
+
941
+ Assert(!this._inRuleset(), `Cannot set ${type} inside a ruleset`);
942
+
943
+ const obj = this.clone();
944
+ if (!obj.$_terms[type] ||
945
+ options.override) {
946
+
947
+ obj.$_terms[type] = [];
948
+ }
949
+
950
+ if (options.single) {
951
+ obj.$_terms[type].push(values);
952
+ }
953
+ else {
954
+ obj.$_terms[type].push(...values);
955
+ }
956
+
957
+ obj.$_temp.ruleset = false;
958
+ return obj;
959
+ }
960
+
961
+ _inRuleset() {
962
+
963
+ return this.$_temp.ruleset !== null && this.$_temp.ruleset !== false;
964
+ }
965
+
966
+ _ruleRemove(name, options = {}) {
967
+
968
+ if (!this._singleRules.has(name)) {
969
+ return this;
970
+ }
971
+
972
+ const obj = options.clone !== false ? this.clone() : this;
973
+
974
+ obj._singleRules.delete(name);
975
+
976
+ const filtered = [];
977
+ for (let i = 0; i < obj._rules.length; ++i) {
978
+ const test = obj._rules[i];
979
+ if (test.name === name &&
980
+ !test.keep) {
981
+
982
+ if (obj._inRuleset() &&
983
+ i < obj.$_temp.ruleset) {
984
+
985
+ --obj.$_temp.ruleset;
986
+ }
987
+
988
+ continue;
989
+ }
990
+
991
+ filtered.push(test);
992
+ }
993
+
994
+ obj._rules = filtered;
995
+ return obj;
996
+ }
997
+
998
+ _values(values, key) {
999
+
1000
+ Common.verifyFlat(values, key.slice(1, -1));
1001
+
1002
+ const obj = this.clone();
1003
+
1004
+ const override = values[0] === Common.symbols.override;
1005
+ if (override) {
1006
+ values = values.slice(1);
1007
+ }
1008
+
1009
+ if (!obj[key] &&
1010
+ values.length) {
1011
+
1012
+ obj[key] = new Values();
1013
+ }
1014
+ else if (override) {
1015
+ obj[key] = values.length ? new Values() : null;
1016
+ obj.$_mutateRebuild();
1017
+ }
1018
+
1019
+ if (!obj[key]) {
1020
+ return obj;
1021
+ }
1022
+
1023
+ if (override) {
1024
+ obj[key].override();
1025
+ }
1026
+
1027
+ for (const value of values) {
1028
+ Assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined');
1029
+ Assert(value !== Common.symbols.override, 'Override must be the first value');
1030
+
1031
+ const other = key === '_invalids' ? '_valids' : '_invalids';
1032
+ if (obj[other]) {
1033
+ obj[other].remove(value);
1034
+ if (!obj[other].length) {
1035
+ Assert(key === '_valids' || !obj._flags.only, 'Setting invalid value', value, 'leaves schema rejecting all values due to previous valid rule');
1036
+ obj[other] = null;
1037
+ }
1038
+ }
1039
+
1040
+ obj[key].add(value, obj._refs);
1041
+ }
1042
+
1043
+ return obj;
1044
+ }
1045
+ };
1046
+
1047
+
1048
+ internals.Base.prototype[Common.symbols.any] = {
1049
+ version: Common.version,
1050
+ compile: Compile.compile,
1051
+ root: '$_root'
1052
+ };
1053
+
1054
+
1055
+ internals.Base.prototype.isImmutable = true; // Prevents Hoek from deep cloning schema objects (must be on prototype)
1056
+
1057
+
1058
+ // Aliases
1059
+
1060
+ internals.Base.prototype.deny = internals.Base.prototype.invalid;
1061
+ internals.Base.prototype.disallow = internals.Base.prototype.invalid;
1062
+ internals.Base.prototype.equal = internals.Base.prototype.valid;
1063
+ internals.Base.prototype.exist = internals.Base.prototype.required;
1064
+ internals.Base.prototype.not = internals.Base.prototype.invalid;
1065
+ internals.Base.prototype.options = internals.Base.prototype.prefs;
1066
+ internals.Base.prototype.preferences = internals.Base.prototype.prefs;
1067
+
1068
+
1069
+ module.exports = new internals.Base();