joi 17.1.1 → 17.4.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/validator.js CHANGED
@@ -20,6 +20,7 @@ exports.entry = function (value, schema, prefs) {
20
20
  let settings = Common.defaults;
21
21
  if (prefs) {
22
22
  Assert(prefs.warnings === undefined, 'Cannot override warnings preference in synchronous validation');
23
+ Assert(prefs.artifacts === undefined, 'Cannot override artifacts preference in synchronous validation');
23
24
  settings = Common.preferences(Common.defaults, prefs);
24
25
  }
25
26
 
@@ -39,6 +40,10 @@ exports.entry = function (value, schema, prefs) {
39
40
  outcome.debug = result.mainstay.debug;
40
41
  }
41
42
 
43
+ if (result.mainstay.artifacts) {
44
+ outcome.artifacts = result.mainstay.artifacts;
45
+ }
46
+
42
47
  return outcome;
43
48
  };
44
49
 
@@ -74,7 +79,7 @@ exports.entryAsync = async function (value, schema, prefs) {
74
79
  }
75
80
 
76
81
  try {
77
- const output = await method(node);
82
+ const output = await method(node, { prefs });
78
83
  if (output === undefined ||
79
84
  output === node) {
80
85
 
@@ -98,7 +103,8 @@ exports.entryAsync = async function (value, schema, prefs) {
98
103
  }
99
104
 
100
105
  if (!settings.warnings &&
101
- !settings.debug) {
106
+ !settings.debug &&
107
+ !settings.artifacts) {
102
108
 
103
109
  return result.value;
104
110
  }
@@ -112,6 +118,10 @@ exports.entryAsync = async function (value, schema, prefs) {
112
118
  outcome.debug = mainstay.debug;
113
119
  }
114
120
 
121
+ if (mainstay.artifacts) {
122
+ outcome.artifacts = mainstay.artifacts;
123
+ }
124
+
115
125
  return outcome;
116
126
  };
117
127
 
@@ -190,6 +200,7 @@ exports.validate = function (value, schema, state, prefs, overrides = {}) {
190
200
  schema,
191
201
  state,
192
202
  error: createError,
203
+ errorsArray: internals.errorsArray,
193
204
  warn: (code, local, localState) => state.mainstay.warnings.push(createError(code, local, localState)),
194
205
  message: (messages, local) => schema.$_createError('custom', value, local, state, prefs, { messages })
195
206
  };
@@ -244,7 +255,7 @@ exports.validate = function (value, schema, state, prefs, overrides = {}) {
244
255
 
245
256
  // Presence requirements (required, optional, forbidden)
246
257
 
247
- const presence = overrides.presence || schema._flags.presence || (schema._flags._endedSwitch ? 'ignore' : prefs.presence);
258
+ const presence = overrides.presence || schema._flags.presence || (schema._flags._endedSwitch ? null : prefs.presence);
248
259
  if (value === undefined) {
249
260
  if (presence === 'forbidden') {
250
261
  return internals.finalize(value, null, helpers);
@@ -416,7 +427,7 @@ internals.rule = function (ret, rule) {
416
427
  }
417
428
 
418
429
  if (Array.isArray(ret) &&
419
- (ret[0] instanceof Errors.Report || ret[0] instanceof Error)) {
430
+ ret[Common.symbols.errors]) {
420
431
 
421
432
  ret.forEach((report) => internals.error(report, rule));
422
433
  return { errors: ret, value: null };
@@ -523,6 +534,20 @@ internals.finalize = function (value, errors, helpers) {
523
534
  schema._cache.set(helpers.original, result);
524
535
  }
525
536
 
537
+ // Artifacts
538
+
539
+ if (value !== undefined &&
540
+ !result.errors &&
541
+ schema._flags.artifact !== undefined) {
542
+
543
+ state.mainstay.artifacts = state.mainstay.artifacts || new Map();
544
+ if (!state.mainstay.artifacts.has(schema._flags.artifact)) {
545
+ state.mainstay.artifacts.set(schema._flags.artifact, []);
546
+ }
547
+
548
+ state.mainstay.artifacts.get(schema._flags.artifact).push(state.path);
549
+ }
550
+
526
551
  return result;
527
552
  };
528
553
 
@@ -615,3 +640,11 @@ internals.ignore = {
615
640
  resolve: Ignore,
616
641
  value: Ignore
617
642
  };
643
+
644
+
645
+ internals.errorsArray = function () {
646
+
647
+ const errors = [];
648
+ errors[Common.symbols.errors] = true;
649
+ return errors;
650
+ };
package/package.json CHANGED
@@ -1,35 +1,37 @@
1
1
  {
2
- "name": "joi",
3
- "description": "Object schema validation",
4
- "version": "17.1.1",
5
- "repository": "git://github.com/sideway/joi",
6
- "main": "lib/index.js",
7
- "browser": "dist/joi-browser.min.js",
8
- "files": [
9
- "lib/**/*",
10
- "dist/*"
11
- ],
12
- "keywords": [
13
- "schema",
14
- "validation"
15
- ],
16
- "dependencies": {
17
- "@hapi/address": "^4.0.1",
18
- "@hapi/formula": "^2.0.0",
19
- "@hapi/hoek": "^9.0.0",
20
- "@hapi/pinpoint": "^2.0.0",
21
- "@hapi/topo": "^5.0.0"
22
- },
23
- "devDependencies": {
24
- "@hapi/bourne": "2.x.x",
25
- "@hapi/code": "8.x.x",
26
- "@hapi/lab": "22.x.x",
27
- "@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x"
28
- },
29
- "scripts": {
30
- "prepublishOnly": "cd browser && npm install && npm run build",
31
- "test": "lab -t 100 -a @hapi/code -L",
32
- "test-cov-html": "lab -r html -o coverage.html -a @hapi/code"
33
- },
34
- "license": "BSD-3-Clause"
2
+ "name": "joi",
3
+ "description": "Object schema validation",
4
+ "version": "17.4.0",
5
+ "repository": "git://github.com/sideway/joi",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "browser": "dist/joi-browser.min.js",
9
+ "files": [
10
+ "lib/**/*",
11
+ "dist/*"
12
+ ],
13
+ "keywords": [
14
+ "schema",
15
+ "validation"
16
+ ],
17
+ "dependencies": {
18
+ "@hapi/hoek": "^9.0.0",
19
+ "@hapi/topo": "^5.0.0",
20
+ "@sideway/address": "^4.1.0",
21
+ "@sideway/formula": "^3.0.0",
22
+ "@sideway/pinpoint": "^2.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@hapi/bourne": "2.x.x",
26
+ "@hapi/code": "8.x.x",
27
+ "@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x",
28
+ "@hapi/lab": "24.x.x",
29
+ "typescript": "4.0.x"
30
+ },
31
+ "scripts": {
32
+ "prepublishOnly": "cd browser && npm install && npm run build",
33
+ "test": "lab -t 100 -a @hapi/code -L -Y",
34
+ "test-cov-html": "lab -r html -o coverage.html -a @hapi/code"
35
+ },
36
+ "license": "BSD-3-Clause"
35
37
  }