joi 14.2.0 → 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.
Files changed (59) hide show
  1. package/LICENSE.md +10 -0
  2. package/README.md +9 -118
  3. package/dist/joi-browser.min.js +1 -0
  4. package/lib/annotate.js +175 -0
  5. package/lib/base.js +1068 -0
  6. package/lib/cache.js +143 -0
  7. package/lib/common.js +216 -0
  8. package/lib/compile.js +283 -0
  9. package/lib/errors.js +160 -269
  10. package/lib/extend.js +312 -0
  11. package/lib/index.d.ts +2200 -0
  12. package/lib/index.js +179 -347
  13. package/lib/manifest.js +476 -0
  14. package/lib/messages.js +178 -0
  15. package/lib/modify.js +267 -0
  16. package/lib/ref.js +386 -25
  17. package/lib/schemas.js +291 -15
  18. package/lib/state.js +152 -0
  19. package/lib/template.js +427 -0
  20. package/lib/trace.js +346 -0
  21. package/lib/types/alternatives.js +329 -0
  22. package/lib/types/any.js +174 -0
  23. package/lib/types/array.js +775 -0
  24. package/lib/types/binary.js +98 -0
  25. package/lib/types/boolean.js +150 -0
  26. package/lib/types/date.js +233 -0
  27. package/lib/types/function.js +93 -0
  28. package/lib/types/keys.js +1043 -0
  29. package/lib/types/link.js +168 -0
  30. package/lib/types/number.js +335 -0
  31. package/lib/types/object.js +22 -0
  32. package/lib/types/string.js +820 -0
  33. package/lib/types/symbol.js +102 -0
  34. package/lib/validator.js +650 -0
  35. package/lib/values.js +263 -0
  36. package/package.json +34 -29
  37. package/CHANGELOG.md +0 -3
  38. package/LICENSE +0 -25
  39. package/lib/cast.js +0 -64
  40. package/lib/language.js +0 -166
  41. package/lib/set.js +0 -191
  42. package/lib/types/alternatives/index.js +0 -218
  43. package/lib/types/any/index.js +0 -978
  44. package/lib/types/any/settings.js +0 -36
  45. package/lib/types/array/index.js +0 -707
  46. package/lib/types/binary/index.js +0 -100
  47. package/lib/types/boolean/index.js +0 -100
  48. package/lib/types/date/index.js +0 -182
  49. package/lib/types/func/index.js +0 -90
  50. package/lib/types/lazy/index.js +0 -82
  51. package/lib/types/number/index.js +0 -248
  52. package/lib/types/object/index.js +0 -957
  53. package/lib/types/state.js +0 -11
  54. package/lib/types/string/index.js +0 -703
  55. package/lib/types/string/ip.js +0 -54
  56. package/lib/types/string/rfc3986.js +0 -219
  57. package/lib/types/string/uri.js +0 -46
  58. package/lib/types/symbol/index.js +0 -93
  59. package/lib/types/symbols.js +0 -5
@@ -0,0 +1,102 @@
1
+ 'use strict';
2
+
3
+ const Assert = require('@hapi/hoek/lib/assert');
4
+
5
+ const Any = require('./any');
6
+
7
+
8
+ const internals = {};
9
+
10
+
11
+ internals.Map = class extends Map {
12
+
13
+ slice() {
14
+
15
+ return new internals.Map(this);
16
+ }
17
+ };
18
+
19
+
20
+ module.exports = Any.extend({
21
+
22
+ type: 'symbol',
23
+
24
+ terms: {
25
+
26
+ map: { init: new internals.Map() }
27
+ },
28
+
29
+ coerce: {
30
+ method(value, { schema, error }) {
31
+
32
+ const lookup = schema.$_terms.map.get(value);
33
+ if (lookup) {
34
+ value = lookup;
35
+ }
36
+
37
+ if (!schema._flags.only ||
38
+ typeof value === 'symbol') {
39
+
40
+ return { value };
41
+ }
42
+
43
+ return { value, errors: error('symbol.map', { map: schema.$_terms.map }) };
44
+ }
45
+ },
46
+
47
+ validate(value, { error }) {
48
+
49
+ if (typeof value !== 'symbol') {
50
+ return { value, errors: error('symbol.base') };
51
+ }
52
+ },
53
+
54
+ rules: {
55
+ map: {
56
+ method(iterable) {
57
+
58
+ if (iterable &&
59
+ !iterable[Symbol.iterator] &&
60
+ typeof iterable === 'object') {
61
+
62
+ iterable = Object.entries(iterable);
63
+ }
64
+
65
+ Assert(iterable && iterable[Symbol.iterator], 'Iterable must be an iterable or object');
66
+
67
+ const obj = this.clone();
68
+
69
+ const symbols = [];
70
+ for (const entry of iterable) {
71
+ Assert(entry && entry[Symbol.iterator], 'Entry must be an iterable');
72
+ const [key, value] = entry;
73
+
74
+ Assert(typeof key !== 'object' && typeof key !== 'function' && typeof key !== 'symbol', 'Key must not be of type object, function, or Symbol');
75
+ Assert(typeof value === 'symbol', 'Value must be a Symbol');
76
+
77
+ obj.$_terms.map.set(key, value);
78
+ symbols.push(value);
79
+ }
80
+
81
+ return obj.valid(...symbols);
82
+ }
83
+ }
84
+ },
85
+
86
+ manifest: {
87
+
88
+ build(obj, desc) {
89
+
90
+ if (desc.map) {
91
+ obj = obj.map(desc.map);
92
+ }
93
+
94
+ return obj;
95
+ }
96
+ },
97
+
98
+ messages: {
99
+ 'symbol.base': '{{#label}} must be a symbol',
100
+ 'symbol.map': '{{#label}} must be one of {{#map}}'
101
+ }
102
+ });