joi 17.1.1 → 17.2.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.
package/lib/base.js CHANGED
@@ -32,6 +32,11 @@ internals.Base = class {
32
32
 
33
33
  this.$_root = null;
34
34
  this._definition = {};
35
+ this._reset();
36
+ }
37
+
38
+ _reset() {
39
+
35
40
  this._ids = new Modify.Ids();
36
41
  this._preferences = null;
37
42
  this._refs = new Ref.Manager();
@@ -85,6 +90,14 @@ internals.Base = class {
85
90
  return obj;
86
91
  }
87
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
+
88
101
  cast(to) {
89
102
 
90
103
  Assert(to === false || typeof to === 'string', 'Invalid to value');
@@ -316,6 +329,7 @@ internals.Base = class {
316
329
 
317
330
  Assert(!this._inRuleset(), 'Cannot set caching inside a ruleset');
318
331
  Assert(!this._cache, 'Cannot override schema cache');
332
+ Assert(this._flags.artifact === undefined, 'Cannot cache a rule with an artifact');
319
333
 
320
334
  const obj = this.clone();
321
335
  obj._cache = cache || Cache.provider.provision();
@@ -749,6 +763,11 @@ internals.Base = class {
749
763
  return obj;
750
764
  }
751
765
 
766
+ $_parent(method, ...args) {
767
+
768
+ return this[method][Common.symbols.parent].call(this, ...args);
769
+ }
770
+
752
771
  $_validate(value, state, prefs) {
753
772
 
754
773
  return Validator.validate(value, this, state, prefs);
@@ -780,6 +799,8 @@ internals.Base = class {
780
799
  target.$_terms[key] = this.$_terms[key] ? this.$_terms[key].slice() : null;
781
800
  }
782
801
 
802
+ // Backwards compatibility
803
+
783
804
  target.$_super = {};
784
805
  for (const override in this.$_super) {
785
806
  target.$_super[override] = this._super[override].bind(target);
@@ -788,6 +809,20 @@ internals.Base = class {
788
809
  return target;
789
810
  }
790
811
 
812
+ _bare() {
813
+
814
+ const obj = this.clone();
815
+ obj._reset();
816
+
817
+ const terms = obj._definition.terms;
818
+ for (const name in terms) {
819
+ const term = terms[name];
820
+ obj.$_terms[name] = term.init;
821
+ }
822
+
823
+ return obj.$_mutateRebuild();
824
+ }
825
+
791
826
  _default(flag, value, options = {}) {
792
827
 
793
828
  Common.assertOptions(options, 'literal');
package/lib/common.js CHANGED
@@ -20,6 +20,7 @@ exports.version = Pkg.version;
20
20
  exports.defaults = {
21
21
  abortEarly: true,
22
22
  allowUnknown: false,
23
+ artifacts: false,
23
24
  cache: true,
24
25
  context: null,
25
26
  convert: true,
@@ -50,12 +51,14 @@ exports.symbols = {
50
51
  any: Symbol.for('@hapi/joi/schema'), // Used to internally identify any-based types (shared with other joi versions)
51
52
  arraySingle: Symbol('arraySingle'),
52
53
  deepDefault: Symbol('deepDefault'),
54
+ errors: Symbol('errors'),
53
55
  literal: Symbol('literal'),
54
56
  override: Symbol('override'),
57
+ parent: Symbol('parent'),
55
58
  prefs: Symbol('prefs'),
56
59
  ref: Symbol('ref'),
57
- values: Symbol('values'),
58
- template: Symbol('template')
60
+ template: Symbol('template'),
61
+ values: Symbol('values')
59
62
  };
60
63
 
61
64
 
package/lib/extend.js CHANGED
@@ -156,10 +156,11 @@ exports.type = function (from, options) {
156
156
 
157
157
  if (def.overrides) {
158
158
  prototype._super = base;
159
- schema.$_super = {};
159
+ schema.$_super = {}; // Backwards compatibility
160
160
  for (const override in def.overrides) {
161
161
  Assert(base[override], 'Cannot override missing', override);
162
- schema.$_super[override] = base[override].bind(schema);
162
+ def.overrides[override][Common.symbols.parent] = base[override];
163
+ schema.$_super[override] = base[override].bind(schema); // Backwards compatibility
163
164
  }
164
165
 
165
166
  Object.assign(prototype, def.overrides);