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
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- // Load modules
4
-
5
- const RFC3986 = require('./rfc3986');
6
-
7
-
8
- // Declare internals
9
-
10
- const internals = {
11
- Ip: {
12
- cidrs: {
13
- ipv4: {
14
- required: '\\/(?:' + RFC3986.ipv4Cidr + ')',
15
- optional: '(?:\\/(?:' + RFC3986.ipv4Cidr + '))?',
16
- forbidden: ''
17
- },
18
- ipv6: {
19
- required: '\\/' + RFC3986.ipv6Cidr,
20
- optional: '(?:\\/' + RFC3986.ipv6Cidr + ')?',
21
- forbidden: ''
22
- },
23
- ipvfuture: {
24
- required: '\\/' + RFC3986.ipv6Cidr,
25
- optional: '(?:\\/' + RFC3986.ipv6Cidr + ')?',
26
- forbidden: ''
27
- }
28
- },
29
- versions: {
30
- ipv4: RFC3986.IPv4address,
31
- ipv6: RFC3986.IPv6address,
32
- ipvfuture: RFC3986.IPvFuture
33
- }
34
- }
35
- };
36
-
37
-
38
- internals.Ip.createIpRegex = function (versions, cidr) {
39
-
40
- let regex;
41
- for (let i = 0; i < versions.length; ++i) {
42
- const version = versions[i];
43
- if (!regex) {
44
- regex = '^(?:' + internals.Ip.versions[version] + internals.Ip.cidrs[version][cidr];
45
- }
46
- else {
47
- regex += '|' + internals.Ip.versions[version] + internals.Ip.cidrs[version][cidr];
48
- }
49
- }
50
-
51
- return new RegExp(regex + ')$');
52
- };
53
-
54
- module.exports = internals.Ip;
@@ -1,219 +0,0 @@
1
- 'use strict';
2
-
3
- // Load modules
4
-
5
-
6
- // Delcare internals
7
-
8
- const internals = {
9
- rfc3986: {}
10
- };
11
-
12
-
13
- internals.generate = function () {
14
-
15
- /**
16
- * elements separated by forward slash ("/") are alternatives.
17
- */
18
- const or = '|';
19
-
20
- /**
21
- * Rule to support zero-padded addresses.
22
- */
23
- const zeroPad = '0?';
24
-
25
- /**
26
- * DIGIT = %x30-39 ; 0-9
27
- */
28
- const digit = '0-9';
29
- const digitOnly = '[' + digit + ']';
30
-
31
- /**
32
- * ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
33
- */
34
- const alpha = 'a-zA-Z';
35
- const alphaOnly = '[' + alpha + ']';
36
-
37
- /**
38
- * IPv4
39
- * cidr = DIGIT ; 0-9
40
- * / %x31-32 DIGIT ; 10-29
41
- * / "3" %x30-32 ; 30-32
42
- */
43
- internals.rfc3986.ipv4Cidr = digitOnly + or + '[1-2]' + digitOnly + or + '3' + '[0-2]';
44
-
45
- /**
46
- * IPv6
47
- * cidr = DIGIT ; 0-9
48
- * / %x31-39 DIGIT ; 10-99
49
- * / "1" %x0-1 DIGIT ; 100-119
50
- * / "12" %x0-8 ; 120-128
51
- */
52
- internals.rfc3986.ipv6Cidr = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + '[01]' + digitOnly + or + '12[0-8])';
53
-
54
- /**
55
- * HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
56
- */
57
- const hexDigit = digit + 'A-Fa-f';
58
- const hexDigitOnly = '[' + hexDigit + ']';
59
-
60
- /**
61
- * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
62
- */
63
- const unreserved = alpha + digit + '-\\._~';
64
-
65
- /**
66
- * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
67
- */
68
- const subDelims = '!\\$&\'\\(\\)\\*\\+,;=';
69
-
70
- /**
71
- * pct-encoded = "%" HEXDIG HEXDIG
72
- */
73
- const pctEncoded = '%' + hexDigit;
74
-
75
- /**
76
- * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
77
- */
78
- const pchar = unreserved + pctEncoded + subDelims + ':@';
79
- const pcharOnly = '[' + pchar + ']';
80
-
81
- /**
82
- * squareBrackets example: []
83
- */
84
- const squareBrackets = '\\[\\]';
85
-
86
- /**
87
- * dec-octet = DIGIT ; 0-9
88
- * / %x31-39 DIGIT ; 10-99
89
- * / "1" 2DIGIT ; 100-199
90
- * / "2" %x30-34 DIGIT ; 200-249
91
- * / "25" %x30-35 ; 250-255
92
- */
93
- const decOctect = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + digitOnly + digitOnly + or + '2' + '[0-4]' + digitOnly + or + '25' + '[0-5])';
94
-
95
- /**
96
- * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
97
- */
98
- internals.rfc3986.IPv4address = '(?:' + decOctect + '\\.){3}' + decOctect;
99
-
100
- /**
101
- * h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
102
- * ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
103
- * IPv6address = 6( h16 ":" ) ls32
104
- * / "::" 5( h16 ":" ) ls32
105
- * / [ h16 ] "::" 4( h16 ":" ) ls32
106
- * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
107
- * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
108
- * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
109
- * / [ *4( h16 ":" ) h16 ] "::" ls32
110
- * / [ *5( h16 ":" ) h16 ] "::" h16
111
- * / [ *6( h16 ":" ) h16 ] "::"
112
- */
113
- const h16 = hexDigitOnly + '{1,4}';
114
- const ls32 = '(?:' + h16 + ':' + h16 + '|' + internals.rfc3986.IPv4address + ')';
115
- const IPv6SixHex = '(?:' + h16 + ':){6}' + ls32;
116
- const IPv6FiveHex = '::(?:' + h16 + ':){5}' + ls32;
117
- const IPv6FourHex = '(?:' + h16 + ')?::(?:' + h16 + ':){4}' + ls32;
118
- const IPv6ThreeHex = '(?:(?:' + h16 + ':){0,1}' + h16 + ')?::(?:' + h16 + ':){3}' + ls32;
119
- const IPv6TwoHex = '(?:(?:' + h16 + ':){0,2}' + h16 + ')?::(?:' + h16 + ':){2}' + ls32;
120
- const IPv6OneHex = '(?:(?:' + h16 + ':){0,3}' + h16 + ')?::' + h16 + ':' + ls32;
121
- const IPv6NoneHex = '(?:(?:' + h16 + ':){0,4}' + h16 + ')?::' + ls32;
122
- const IPv6NoneHex2 = '(?:(?:' + h16 + ':){0,5}' + h16 + ')?::' + h16;
123
- const IPv6NoneHex3 = '(?:(?:' + h16 + ':){0,6}' + h16 + ')?::';
124
- internals.rfc3986.IPv6address = '(?:' + IPv6SixHex + or + IPv6FiveHex + or + IPv6FourHex + or + IPv6ThreeHex + or + IPv6TwoHex + or + IPv6OneHex + or + IPv6NoneHex + or + IPv6NoneHex2 + or + IPv6NoneHex3 + ')';
125
-
126
- /**
127
- * IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
128
- */
129
- internals.rfc3986.IPvFuture = 'v' + hexDigitOnly + '+\\.[' + unreserved + subDelims + ':]+';
130
-
131
- /**
132
- * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
133
- */
134
- internals.rfc3986.scheme = alphaOnly + '[' + alpha + digit + '+-\\.]*';
135
-
136
- /**
137
- * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
138
- */
139
- const userinfo = '[' + unreserved + pctEncoded + subDelims + ':]*';
140
-
141
- /**
142
- * IP-literal = "[" ( IPv6address / IPvFuture ) "]"
143
- */
144
- const IPLiteral = '\\[(?:' + internals.rfc3986.IPv6address + or + internals.rfc3986.IPvFuture + ')\\]';
145
-
146
- /**
147
- * reg-name = *( unreserved / pct-encoded / sub-delims )
148
- */
149
- const regName = '[' + unreserved + pctEncoded + subDelims + ']{0,255}';
150
-
151
- /**
152
- * host = IP-literal / IPv4address / reg-name
153
- */
154
- const host = '(?:' + IPLiteral + or + internals.rfc3986.IPv4address + or + regName + ')';
155
-
156
- /**
157
- * port = *DIGIT
158
- */
159
- const port = digitOnly + '*';
160
-
161
- /**
162
- * authority = [ userinfo "@" ] host [ ":" port ]
163
- */
164
- const authority = '(?:' + userinfo + '@)?' + host + '(?::' + port + ')?';
165
-
166
- /**
167
- * segment = *pchar
168
- * segment-nz = 1*pchar
169
- * path = path-abempty ; begins with "/" or is empty
170
- * / path-absolute ; begins with "/" but not "//"
171
- * / path-noscheme ; begins with a non-colon segment
172
- * / path-rootless ; begins with a segment
173
- * / path-empty ; zero characters
174
- * path-abempty = *( "/" segment )
175
- * path-absolute = "/" [ segment-nz *( "/" segment ) ]
176
- * path-rootless = segment-nz *( "/" segment )
177
- */
178
- const segment = pcharOnly + '*';
179
- const segmentNz = pcharOnly + '+';
180
- const segmentNzNc = '[' + unreserved + pctEncoded + subDelims + '@' + ']+';
181
- const pathEmpty = '';
182
- const pathAbEmpty = '(?:\\/' + segment + ')*';
183
- const pathAbsolute = '\\/(?:' + segmentNz + pathAbEmpty + ')?';
184
- const pathRootless = segmentNz + pathAbEmpty;
185
- const pathNoScheme = segmentNzNc + pathAbEmpty;
186
-
187
- /**
188
- * hier-part = "//" authority path
189
- */
190
- internals.rfc3986.hierPart = '(?:' + '(?:\\/\\/' + authority + pathAbEmpty + ')' + or + pathAbsolute + or + pathRootless + ')';
191
-
192
- /**
193
- * relative-part = "//" authority path-abempty
194
- * / path-absolute
195
- * / path-noscheme
196
- * / path-empty
197
- */
198
- internals.rfc3986.relativeRef = '(?:' + '(?:\\/\\/' + authority + pathAbEmpty + ')' + or + pathAbsolute + or + pathNoScheme + or + pathEmpty + ')';
199
-
200
- /**
201
- * query = *( pchar / "/" / "?" )
202
- */
203
- internals.rfc3986.query = '[' + pchar + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
204
-
205
- /**
206
- * query = *( pchar / "[" / "]" / "/" / "?" )
207
- */
208
- internals.rfc3986.queryWithSquareBrackets = '[' + pchar + squareBrackets + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
209
-
210
- /**
211
- * fragment = *( pchar / "/" / "?" )
212
- */
213
- internals.rfc3986.fragment = '[' + pchar + '\\/\\?]*';
214
- };
215
-
216
-
217
- internals.generate();
218
-
219
- module.exports = internals.rfc3986;
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- // Load Modules
4
-
5
- const RFC3986 = require('./rfc3986');
6
-
7
-
8
- // Declare internals
9
-
10
- const internals = {
11
- Uri: {
12
- createUriRegex: function (optionalScheme, allowRelative, relativeOnly, allowQuerySquareBrackets) {
13
-
14
- let scheme = RFC3986.scheme;
15
- let prefix;
16
-
17
- if (relativeOnly) {
18
- prefix = '(?:' + RFC3986.relativeRef + ')';
19
- }
20
- else {
21
- // If we were passed a scheme, use it instead of the generic one
22
- if (optionalScheme) {
23
-
24
- // Have to put this in a non-capturing group to handle the OR statements
25
- scheme = '(?:' + optionalScheme + ')';
26
- }
27
-
28
- const withScheme = '(?:' + scheme + ':' + RFC3986.hierPart + ')';
29
-
30
- prefix = allowRelative ? '(?:' + withScheme + '|' + RFC3986.relativeRef + ')' : withScheme;
31
- }
32
-
33
- /**
34
- * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
35
- *
36
- * OR
37
- *
38
- * relative-ref = relative-part [ "?" query ] [ "#" fragment ]
39
- */
40
- return new RegExp('^' + prefix + '(?:\\?' + (allowQuerySquareBrackets ? RFC3986.queryWithSquareBrackets : RFC3986.query) + ')?' + '(?:#' + RFC3986.fragment + ')?$');
41
- }
42
- }
43
- };
44
-
45
-
46
- module.exports = internals.Uri;
@@ -1,93 +0,0 @@
1
- 'use strict';
2
-
3
- // Load modules
4
-
5
- const Util = require('util');
6
-
7
- const Any = require('../any');
8
- const Hoek = require('hoek');
9
-
10
-
11
- // Declare internals
12
-
13
- const internals = {};
14
-
15
-
16
- internals.Map = class extends Map {
17
-
18
- slice() {
19
-
20
- return new internals.Map(this);
21
- }
22
-
23
- toString() {
24
-
25
- return Util.inspect(this);
26
- }
27
- };
28
-
29
-
30
- internals.Symbol = class extends Any {
31
-
32
- constructor() {
33
-
34
- super();
35
- this._type = 'symbol';
36
- this._inner.map = new internals.Map();
37
- }
38
-
39
- _base(value, state, options) {
40
-
41
- if (options.convert) {
42
- const lookup = this._inner.map.get(value);
43
- if (lookup) {
44
- value = lookup;
45
- }
46
-
47
- if (this._flags.allowOnly) {
48
- return {
49
- value,
50
- errors: (typeof value === 'symbol') ? null : this.createError('symbol.map', { value, map: this._inner.map }, state, options)
51
- };
52
- }
53
- }
54
-
55
- return {
56
- value,
57
- errors: (typeof value === 'symbol') ? null : this.createError('symbol.base', { value }, state, options)
58
- };
59
- }
60
-
61
- map(iterable) {
62
-
63
- if (iterable && !iterable[Symbol.iterator] && typeof iterable === 'object') {
64
- iterable = Object.entries(iterable);
65
- }
66
-
67
- Hoek.assert(iterable && iterable[Symbol.iterator], 'Iterable must be an iterable or object');
68
- const obj = this.clone();
69
-
70
- const symbols = [];
71
- for (const entry of iterable) {
72
- Hoek.assert(entry && entry[Symbol.iterator], 'Entry must be an iterable');
73
- const [key, value] = entry;
74
-
75
- Hoek.assert(typeof key !== 'object' && typeof key !== 'function' && typeof key !== 'symbol', 'Key must not be an object, function, or Symbol');
76
- Hoek.assert(typeof value === 'symbol', 'Value must be a Symbol');
77
- obj._inner.map.set(key, value);
78
- symbols.push(value);
79
- }
80
-
81
- return obj.valid(...symbols);
82
- }
83
-
84
- describe() {
85
-
86
- const description = super.describe();
87
- description.map = new Map(this._inner.map);
88
- return description;
89
- }
90
- };
91
-
92
-
93
- module.exports = new internals.Symbol();
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- settingsCache: Symbol('settingsCache')
5
- };