+2
-2
| 'use strict'; | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { clone } = require('@hapi/hoek'); | ||
@@ -25,3 +25,3 @@ const Common = require('./common'); | ||
| const obj = Clone(this._original); | ||
| const obj = clone(this._original); | ||
@@ -28,0 +28,0 @@ for (let i = this.details.length - 1; i >= 0; --i) { // Reverse order to process deepest child first |
+151
-74
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const DeepEqual = require('@hapi/hoek/lib/deepEqual'); | ||
| const Merge = require('@hapi/hoek/lib/merge'); | ||
| const { assert, clone, deepEqual, merge } = require('@hapi/hoek'); | ||
@@ -64,3 +61,3 @@ const Cache = require('./cache'); | ||
| Assert(typeof Manifest.describe === 'function', 'Manifest functionality disabled'); | ||
| assert(typeof Manifest.describe === 'function', 'Manifest functionality disabled'); | ||
| return Manifest.describe(this); | ||
@@ -79,4 +76,4 @@ } | ||
| Assert(targets && typeof targets === 'object' && !Array.isArray(targets), 'Invalid targets argument'); | ||
| Assert(!this._inRuleset(), 'Cannot set alterations inside a ruleset'); | ||
| assert(targets && typeof targets === 'object' && !Array.isArray(targets), 'Invalid targets argument'); | ||
| assert(!this._inRuleset(), 'Cannot set alterations inside a ruleset'); | ||
@@ -87,3 +84,3 @@ const obj = this.clone(); | ||
| const adjuster = targets[target]; | ||
| Assert(typeof adjuster === 'function', 'Alteration adjuster for', target, 'must be a function'); | ||
| assert(typeof adjuster === 'function', 'Alteration adjuster for', target, 'must be a function'); | ||
| obj.$_terms.alterations.push({ target, adjuster }); | ||
@@ -98,4 +95,4 @@ } | ||
| Assert(id !== undefined, 'Artifact cannot be undefined'); | ||
| Assert(!this._cache, 'Cannot set an artifact with a rule cache'); | ||
| assert(id !== undefined, 'Artifact cannot be undefined'); | ||
| assert(!this._cache, 'Cannot set an artifact with a rule cache'); | ||
@@ -107,4 +104,4 @@ return this.$_setFlag('artifact', id); | ||
| Assert(to === false || typeof to === 'string', 'Invalid to value'); | ||
| Assert(to === false || this._definition.cast[to], 'Type', this.type, 'does not support casting to', to); | ||
| assert(to === false || typeof to === 'string', 'Invalid to value'); | ||
| assert(to === false || this._definition.cast[to], 'Type', this.type, 'does not support casting to', to); | ||
@@ -121,3 +118,3 @@ return this.$_setFlag('cast', to === false ? undefined : to); | ||
| Assert(desc && typeof desc === 'string', 'Description must be a non-empty string'); | ||
| assert(desc && typeof desc === 'string', 'Description must be a non-empty string'); | ||
@@ -140,4 +137,4 @@ return this.$_setFlag('description', desc); | ||
| Assert(err, 'Missing error'); | ||
| Assert(err instanceof Error || typeof err === 'function', 'Must provide a valid Error object or a function'); | ||
| assert(err, 'Missing error'); | ||
| assert(err instanceof Error || typeof err === 'function', 'Must provide a valid Error object or a function'); | ||
@@ -149,3 +146,3 @@ return this.$_setFlag('error', err); | ||
| Assert(example !== undefined, 'Missing example'); | ||
| assert(example !== undefined, 'Missing example'); | ||
| Common.assertOptions(options, ['override']); | ||
@@ -159,3 +156,3 @@ | ||
| if (typeof method === 'object') { | ||
| Assert(!description, 'Cannot combine options with description'); | ||
| assert(!description, 'Cannot combine options with description'); | ||
| description = method.description; | ||
@@ -165,4 +162,4 @@ method = method.method; | ||
| Assert(typeof method === 'function', 'Method must be a function'); | ||
| Assert(description === undefined || description && typeof description === 'string', 'Description must be a non-empty string'); | ||
| assert(typeof method === 'function', 'Method must be a function'); | ||
| assert(description === undefined || description && typeof description === 'string', 'Description must be a non-empty string'); | ||
@@ -188,4 +185,4 @@ return this._inner('externals', { method, description }, { single: true }); | ||
| Assert(typeof id === 'string', 'id must be a non-empty string'); | ||
| Assert(/^[^\.]+$/.test(id), 'id cannot contain period character'); | ||
| assert(typeof id === 'string', 'id must be a non-empty string'); | ||
| assert(/^[^\.]+$/.test(id), 'id cannot contain period character'); | ||
@@ -202,3 +199,3 @@ return this.$_setFlag('id', id); | ||
| Assert(name && typeof name === 'string', 'Label name must be a non-empty string'); | ||
| assert(name && typeof name === 'string', 'Label name must be a non-empty string'); | ||
@@ -210,3 +207,3 @@ return this.$_setFlag('label', name); | ||
| Assert(meta !== undefined, 'Meta cannot be undefined'); | ||
| assert(meta !== undefined, 'Meta cannot be undefined'); | ||
@@ -218,5 +215,5 @@ return this._inner('metas', meta, { single: true }); | ||
| Assert(notes.length, 'Missing notes'); | ||
| assert(notes.length, 'Missing notes'); | ||
| for (const note of notes) { | ||
| Assert(note && typeof note === 'string', 'Notes must be non-empty strings'); | ||
| assert(note && typeof note === 'string', 'Notes must be non-empty strings'); | ||
| } | ||
@@ -229,3 +226,3 @@ | ||
| Assert(typeof mode === 'boolean', 'Invalid mode:', mode); | ||
| assert(typeof mode === 'boolean', 'Invalid mode:', mode); | ||
@@ -242,7 +239,7 @@ return this.$_setFlag('only', mode); | ||
| Assert(prefs, 'Missing preferences'); | ||
| Assert(prefs.context === undefined, 'Cannot override context'); | ||
| Assert(prefs.externals === undefined, 'Cannot override externals'); | ||
| Assert(prefs.warnings === undefined, 'Cannot override warnings'); | ||
| Assert(prefs.debug === undefined, 'Cannot override debug'); | ||
| assert(prefs, 'Missing preferences'); | ||
| assert(prefs.context === undefined, 'Cannot override context'); | ||
| assert(prefs.externals === undefined, 'Cannot override externals'); | ||
| assert(prefs.warnings === undefined, 'Cannot override warnings'); | ||
| assert(prefs.debug === undefined, 'Cannot override debug'); | ||
@@ -258,3 +255,3 @@ Common.checkPreferences(prefs); | ||
| Assert(['optional', 'required', 'forbidden'].includes(mode), 'Unknown presence mode', mode); | ||
| assert(['optional', 'required', 'forbidden'].includes(mode), 'Unknown presence mode', mode); | ||
@@ -271,3 +268,3 @@ return this.$_setFlag('presence', mode); | ||
| Assert(['raw', 'strip'].includes(mode), 'Unknown result mode', mode); | ||
| assert(['raw', 'strip'].includes(mode), 'Unknown result mode', mode); | ||
@@ -298,5 +295,5 @@ return this.$_setFlag('result', mode); | ||
| Assert(tags.length, 'Missing tags'); | ||
| assert(tags.length, 'Missing tags'); | ||
| for (const tag of tags) { | ||
| Assert(tag && typeof tag === 'string', 'Tags must be non-empty strings'); | ||
| assert(tag && typeof tag === 'string', 'Tags must be non-empty strings'); | ||
| } | ||
@@ -309,3 +306,3 @@ | ||
| Assert(name && typeof name === 'string', 'Unit name must be a non-empty string'); | ||
| assert(name && typeof name === 'string', 'Unit name must be a non-empty string'); | ||
@@ -336,4 +333,4 @@ return this.$_setFlag('unit', name); | ||
| for (const item of conditions) { | ||
| Assert(!item.then || item.then.type === 'any' || item.then.type === obj.type, 'Cannot combine', obj.type, 'with', item.then && item.then.type); | ||
| Assert(!item.otherwise || item.otherwise.type === 'any' || item.otherwise.type === obj.type, 'Cannot combine', obj.type, 'with', item.otherwise && item.otherwise.type); | ||
| assert(!item.then || item.then.type === 'any' || item.then.type === obj.type, 'Cannot combine', obj.type, 'with', item.then && item.then.type); | ||
| assert(!item.otherwise || item.otherwise.type === 'any' || item.otherwise.type === obj.type, 'Cannot combine', obj.type, 'with', item.otherwise && item.otherwise.type); | ||
@@ -351,5 +348,5 @@ } | ||
| Assert(!this._inRuleset(), 'Cannot set caching inside a ruleset'); | ||
| Assert(!this._cache, 'Cannot override schema cache'); | ||
| Assert(this._flags.artifact === undefined, 'Cannot cache a rule with an artifact'); | ||
| assert(!this._inRuleset(), 'Cannot set caching inside a ruleset'); | ||
| assert(!this._cache, 'Cannot override schema cache'); | ||
| assert(this._flags.artifact === undefined, 'Cannot cache a rule with an artifact'); | ||
@@ -370,6 +367,6 @@ const obj = this.clone(); | ||
| Assert(Common.isSchema(source), 'Invalid schema object'); | ||
| Assert(this.type === 'any' || source.type === 'any' || source.type === this.type, 'Cannot merge type', this.type, 'with another type:', source.type); | ||
| Assert(!this._inRuleset(), 'Cannot concatenate onto a schema with open ruleset'); | ||
| Assert(!source._inRuleset(), 'Cannot concatenate a schema with open ruleset'); | ||
| assert(Common.isSchema(source), 'Invalid schema object'); | ||
| assert(this.type === 'any' || source.type === 'any' || source.type === this.type, 'Cannot merge type', this.type, 'with another type:', source.type); | ||
| assert(!this._inRuleset(), 'Cannot concatenate onto a schema with open ruleset'); | ||
| assert(!source._inRuleset(), 'Cannot concatenate a schema with open ruleset'); | ||
@@ -427,3 +424,3 @@ let obj = this.clone(); | ||
| delete flags.empty; | ||
| Merge(obj._flags, flags); | ||
| merge(obj._flags, flags); | ||
| } | ||
@@ -434,6 +431,6 @@ else if (source._flags.empty) { | ||
| delete flags.empty; | ||
| Merge(obj._flags, flags); | ||
| merge(obj._flags, flags); | ||
| } | ||
| else { | ||
| Merge(obj._flags, source._flags); | ||
| merge(obj._flags, source._flags); | ||
| } | ||
@@ -474,3 +471,3 @@ | ||
| Assert(!options.base, 'Cannot extend type with another base'); | ||
| assert(!options.base, 'Cannot extend type with another base'); | ||
@@ -488,3 +485,3 @@ return Extend.type(this, options); | ||
| Assert(!this._inRuleset(), 'Cannot fork inside a ruleset'); | ||
| assert(!this._inRuleset(), 'Cannot fork inside a ruleset'); | ||
@@ -501,2 +498,35 @@ let obj = this; // eslint-disable-line consistent-this | ||
| isAsync() { | ||
| if (Boolean(this.$_terms.externals?.length)) { | ||
| return true; | ||
| } | ||
| if (this.$_terms.whens) { | ||
| for (const when of this.$_terms.whens) { | ||
| if (when.then?.isAsync()) { | ||
| return true; | ||
| } | ||
| if (when.otherwise?.isAsync()) { | ||
| return true; | ||
| } | ||
| if (when.switch) { | ||
| for (const item of when.switch) { | ||
| if (item.then?.isAsync()) { | ||
| return true; | ||
| } | ||
| if (item.otherwise?.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| rule(options) { | ||
@@ -507,5 +537,5 @@ | ||
| Assert(this.$_temp.ruleset !== false, 'Cannot apply rules to empty ruleset or the last rule added does not support rule properties'); | ||
| assert(this.$_temp.ruleset !== false, 'Cannot apply rules to empty ruleset or the last rule added does not support rule properties'); | ||
| const start = this.$_temp.ruleset === null ? this._rules.length - 1 : this.$_temp.ruleset; | ||
| Assert(start >= 0 && start < this._rules.length, 'Cannot apply rules to empty ruleset'); | ||
| assert(start >= 0 && start < this._rules.length, 'Cannot apply rules to empty ruleset'); | ||
@@ -516,7 +546,7 @@ const obj = this.clone(); | ||
| const original = obj._rules[i]; | ||
| const rule = Clone(original); | ||
| const rule = clone(original); | ||
| for (const name in options) { | ||
| def.modifiers[name](rule, options[name]); | ||
| Assert(rule.name === original.name, 'Cannot change rule name'); | ||
| assert(rule.name === original.name, 'Cannot change rule name'); | ||
| } | ||
@@ -537,3 +567,3 @@ | ||
| Assert(!this._inRuleset(), 'Cannot start a new ruleset without closing the previous one'); | ||
| assert(!this._inRuleset(), 'Cannot start a new ruleset without closing the previous one'); | ||
@@ -554,3 +584,3 @@ const obj = this.clone(); | ||
| Assert(!this._inRuleset(), 'Cannot tailor inside a ruleset'); | ||
| assert(!this._inRuleset(), 'Cannot tailor inside a ruleset'); | ||
@@ -563,3 +593,3 @@ let obj = this; // eslint-disable-line consistent-this | ||
| obj = adjuster(obj); | ||
| Assert(Common.isSchema(obj), 'Alteration adjuster for', target, 'failed to return a schema object'); | ||
| assert(Common.isSchema(obj), 'Alteration adjuster for', target, 'failed to return a schema object'); | ||
| } | ||
@@ -599,7 +629,7 @@ } | ||
| Assert(options && typeof options === 'object', 'Invalid options'); | ||
| Assert(options.name && typeof options.name === 'string', 'Invalid rule name'); | ||
| assert(options && typeof options === 'object', 'Invalid options'); | ||
| assert(options.name && typeof options.name === 'string', 'Invalid rule name'); | ||
| for (const key in options) { | ||
| Assert(key[0] !== '_', 'Cannot set private rule properties'); | ||
| assert(key[0] !== '_', 'Cannot set private rule properties'); | ||
| } | ||
@@ -614,3 +644,3 @@ | ||
| Assert(definition, 'Unknown rule', rule.method); | ||
| assert(definition, 'Unknown rule', rule.method); | ||
@@ -622,3 +652,3 @@ // Args | ||
| if (args) { | ||
| 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); | ||
| 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); | ||
@@ -645,3 +675,3 @@ for (const key in args) { | ||
| const error = Common.validateArg(arg, key, resolver); | ||
| Assert(!error, error, 'or reference'); | ||
| assert(!error, error, 'or reference'); | ||
| } | ||
@@ -730,3 +760,3 @@ } | ||
| Assert(!this._inRuleset(), 'Cannot add this rule inside a ruleset'); | ||
| assert(!this._inRuleset(), 'Cannot add this rule inside a ruleset'); | ||
@@ -777,10 +807,10 @@ this._refs.reset(); | ||
| Assert(name[0] === '_' || !this._inRuleset(), 'Cannot set flag inside a ruleset'); | ||
| assert(name[0] === '_' || !this._inRuleset(), 'Cannot set flag inside a ruleset'); | ||
| const flag = this._definition.flags[name] || {}; | ||
| if (DeepEqual(value, flag.default)) { | ||
| if (deepEqual(value, flag.default)) { | ||
| value = undefined; | ||
| } | ||
| if (DeepEqual(value, this._flags[name])) { | ||
| if (deepEqual(value, this._flags[name])) { | ||
| return this; | ||
@@ -832,3 +862,3 @@ } | ||
| target._rules = this._rules.slice(); | ||
| target._singleRules = Clone(this._singleRules, { shallow: true }); | ||
| target._singleRules = clone(this._singleRules, { shallow: true }); | ||
| target._refs = this._refs.clone(); | ||
@@ -871,4 +901,4 @@ target._flags = Object.assign({}, this._flags); | ||
| Assert(value !== undefined, 'Missing', flag, 'value'); | ||
| Assert(typeof value === 'function' || !options.literal, 'Only function value supports literal option'); | ||
| assert(value !== undefined, 'Missing', flag, 'value'); | ||
| assert(typeof value === 'function' || !options.literal, 'Only function value supports literal option'); | ||
@@ -982,3 +1012,3 @@ if (typeof value === 'function' && | ||
| Assert(!this._inRuleset(), `Cannot set ${type} inside a ruleset`); | ||
| assert(!this._inRuleset(), `Cannot set ${type} inside a ruleset`); | ||
@@ -1070,4 +1100,4 @@ const obj = this.clone(); | ||
| for (const value of values) { | ||
| Assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined'); | ||
| Assert(value !== Common.symbols.override, 'Override must be the first value'); | ||
| assert(value !== undefined, 'Cannot call allow/valid/invalid with undefined'); | ||
| assert(value !== Common.symbols.override, 'Override must be the first value'); | ||
@@ -1078,3 +1108,3 @@ const other = key === '_invalids' ? '_valids' : '_invalids'; | ||
| if (!obj[other].length) { | ||
| Assert(key === '_valids' || !obj._flags.only, 'Setting invalid value', value, 'leaves schema rejecting all values due to previous valid rule'); | ||
| assert(key === '_valids' || !obj._flags.only, 'Setting invalid value', value, 'leaves schema rejecting all values due to previous valid rule'); | ||
| obj[other] = null; | ||
@@ -1089,2 +1119,49 @@ } | ||
| } | ||
| // Standard Schema | ||
| get '~standard'() { | ||
| const mapToStandardError = (error) => { | ||
| let issues; | ||
| if (Errors.ValidationError.isError(error)) { | ||
| issues = error.details.map(({ message, path }) => ({ | ||
| message, | ||
| path | ||
| })); | ||
| } | ||
| else { | ||
| issues = [{ | ||
| message: error.message | ||
| }]; | ||
| } | ||
| return { | ||
| issues | ||
| }; | ||
| }; | ||
| const mapToStandardValue = (value) => ({ value }); | ||
| return { | ||
| version: 1, | ||
| vendor: 'joi', | ||
| validate: (value) => { | ||
| const result = Validator.standard(value, this); | ||
| if (result instanceof Promise) { | ||
| return result | ||
| .then(mapToStandardValue, mapToStandardError); | ||
| } | ||
| if (!result.error) { | ||
| return mapToStandardValue(result.value); | ||
| } | ||
| return mapToStandardError(result.error); | ||
| } | ||
| }; | ||
| } | ||
| }; | ||
@@ -1091,0 +1168,0 @@ |
+3
-4
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { assert, clone } = require('@hapi/hoek'); | ||
@@ -31,3 +30,3 @@ const Common = require('./common'); | ||
| Common.assertOptions(options, ['max']); | ||
| Assert(options.max === undefined || options.max && options.max > 0 && isFinite(options.max), 'Invalid max cache size'); | ||
| assert(options.max === undefined || options.max && options.max > 0 && isFinite(options.max), 'Invalid max cache size'); | ||
@@ -70,3 +69,3 @@ this._max = options.max || internals.max; | ||
| this._list.first(node); | ||
| return Clone(node.value); | ||
| return clone(node.value); | ||
| } | ||
@@ -73,0 +72,0 @@ } |
+1
-2
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const AssertError = require('@hapi/hoek/lib/error'); | ||
| const { assert: Assert, AssertError } = require('@hapi/hoek'); | ||
@@ -6,0 +5,0 @@ const Pkg = require('../package.json'); |
+23
-23
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -33,6 +33,6 @@ const Common = require('./common'); | ||
| Assert(config !== undefined, 'Invalid undefined schema'); | ||
| assert(config !== undefined, 'Invalid undefined schema'); | ||
| if (Array.isArray(config)) { | ||
| Assert(config.length, 'Invalid empty array schema'); | ||
| assert(config.length, 'Invalid empty array schema'); | ||
@@ -61,3 +61,3 @@ if (config.length === 1) { | ||
| Assert(typeof config === 'object', 'Invalid schema content:', typeof config); | ||
| assert(typeof config === 'object', 'Invalid schema content:', typeof config); | ||
@@ -90,3 +90,3 @@ if (Common.isResolvable(config)) { | ||
| Assert(Object.getPrototypeOf(config) === Object.getPrototypeOf({}), 'Schema can only contain plain objects'); | ||
| assert(Object.getPrototypeOf(config) === Object.getPrototypeOf({}), 'Schema can only contain plain objects'); | ||
@@ -111,3 +111,3 @@ return Joi.object().keys(config); | ||
| if (any) { | ||
| Assert(options.legacy || any.version === Common.version, 'Cannot mix different versions of joi schemas:', any.version, Common.version); | ||
| assert(options.legacy || any.version === Common.version, 'Cannot mix different versions of joi schemas:', any.version, Common.version); | ||
| return schema; | ||
@@ -157,3 +157,3 @@ } | ||
| Assert(Object.getPrototypeOf(schema) === Object.getPrototypeOf({}), 'Schema can only contain plain objects'); | ||
| assert(Object.getPrototypeOf(schema) === Object.getPrototypeOf({}), 'Schema can only contain plain objects'); | ||
@@ -180,3 +180,3 @@ for (const key in schema) { | ||
| if (options === undefined) { | ||
| Assert(condition && typeof condition === 'object', 'Missing options'); | ||
| assert(condition && typeof condition === 'object', 'Missing options'); | ||
@@ -196,5 +196,5 @@ options = condition; | ||
| if (Common.isSchema(condition)) { | ||
| Assert(options.is === undefined, '"is" can not be used with a schema condition'); | ||
| Assert(options.not === undefined, '"not" can not be used with a schema condition'); | ||
| Assert(options.switch === undefined, '"switch" can not be used with a schema condition'); | ||
| assert(options.is === undefined, '"is" can not be used with a schema condition'); | ||
| assert(options.not === undefined, '"not" can not be used with a schema condition'); | ||
| assert(options.switch === undefined, '"switch" can not be used with a schema condition'); | ||
@@ -206,4 +206,4 @@ return internals.condition(schema, { is: condition, then: options.then, otherwise: options.otherwise, break: options.break }); | ||
| Assert(Ref.isRef(condition) || typeof condition === 'string', 'Invalid condition:', condition); | ||
| Assert(options.not === undefined || options.is === undefined, 'Cannot combine "is" with "not"'); | ||
| assert(Ref.isRef(condition) || typeof condition === 'string', 'Invalid condition:', condition); | ||
| assert(options.not === undefined || options.is === undefined, 'Cannot combine "is" with "not"'); | ||
@@ -217,4 +217,4 @@ if (options.switch === undefined) { | ||
| let is = rule.is !== undefined ? schema.$_compile(rule.is) : schema.$_root.invalid(null, false, 0, '').required(); | ||
| Assert(rule.then !== undefined || rule.otherwise !== undefined, 'options must have at least one of "then", "otherwise", or "switch"'); | ||
| Assert(rule.break === undefined || rule.then === undefined || rule.otherwise === undefined, 'Cannot specify then, otherwise, and break all together'); | ||
| assert(rule.then !== undefined || rule.otherwise !== undefined, 'options must have at least one of "then", "otherwise", or "switch"'); | ||
| assert(rule.break === undefined || rule.then === undefined || rule.otherwise === undefined, 'Cannot specify then, otherwise, and break all together'); | ||
@@ -233,6 +233,6 @@ if (options.is !== undefined && | ||
| Assert(Array.isArray(options.switch), '"switch" must be an array'); | ||
| Assert(options.is === undefined, 'Cannot combine "switch" with "is"'); | ||
| Assert(options.not === undefined, 'Cannot combine "switch" with "not"'); | ||
| Assert(options.then === undefined, 'Cannot combine "switch" with "then"'); | ||
| assert(Array.isArray(options.switch), '"switch" must be an array'); | ||
| assert(options.is === undefined, 'Cannot combine "switch" with "is"'); | ||
| assert(options.not === undefined, 'Cannot combine "switch" with "not"'); | ||
| assert(options.then === undefined, 'Cannot combine "switch" with "then"'); | ||
@@ -251,4 +251,4 @@ const rule = { | ||
| Assert(test.is !== undefined, 'Switch statement missing "is"'); | ||
| Assert(test.then !== undefined, 'Switch statement missing "then"'); | ||
| assert(test.is !== undefined, 'Switch statement missing "is"'); | ||
| assert(test.then !== undefined, 'Switch statement missing "then"'); | ||
@@ -267,6 +267,6 @@ const item = { | ||
| if (last) { | ||
| Assert(options.otherwise === undefined || test.otherwise === undefined, 'Cannot specify "otherwise" inside and outside a "switch"'); | ||
| assert(options.otherwise === undefined || test.otherwise === undefined, 'Cannot specify "otherwise" inside and outside a "switch"'); | ||
| const otherwise = options.otherwise !== undefined ? options.otherwise : test.otherwise; | ||
| if (otherwise !== undefined) { | ||
| Assert(rule.break === undefined, 'Cannot specify both otherwise and break'); | ||
| assert(rule.break === undefined, 'Cannot specify both otherwise and break'); | ||
| item.otherwise = schema.$_compile(otherwise); | ||
@@ -273,0 +273,0 @@ } |
+10
-11
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { assert, clone } = require('@hapi/hoek'); | ||
@@ -16,3 +15,3 @@ const Common = require('./common'); | ||
| const base = Object.getPrototypeOf(from); | ||
| const prototype = Clone(base); | ||
| const prototype = clone(base); | ||
| const schema = from._assign(Object.create(prototype)); | ||
@@ -42,3 +41,3 @@ const def = Object.assign({}, options); // Shallow cloned | ||
| const term = def.terms[name]; | ||
| Assert(schema.$_terms[name] === undefined, 'Invalid term override for', def.type, name); | ||
| assert(schema.$_terms[name] === undefined, 'Invalid term override for', def.type, name); | ||
| schema.$_terms[name] = term.init; | ||
@@ -87,3 +86,3 @@ terms[name] = term; | ||
| const rule = def.rules[name]; | ||
| Assert(typeof rule === 'object', 'Invalid rule definition for', def.type, name); | ||
| assert(typeof rule === 'object', 'Invalid rule definition for', def.type, name); | ||
@@ -99,7 +98,7 @@ let method = rule.method; | ||
| if (method) { | ||
| Assert(!prototype[name], 'Rule conflict in', def.type, name); | ||
| assert(!prototype[name], 'Rule conflict in', def.type, name); | ||
| prototype[name] = method; | ||
| } | ||
| Assert(!rules[name], 'Rule conflict in', def.type, name); | ||
| assert(!rules[name], 'Rule conflict in', def.type, name); | ||
| rules[name] = rule; | ||
@@ -122,3 +121,3 @@ | ||
| Assert(!rule.argsByName.has(arg.name), 'Duplicated argument name', arg.name); | ||
| assert(!rule.argsByName.has(arg.name), 'Duplicated argument name', arg.name); | ||
@@ -143,6 +142,6 @@ if (Common.isSchema(arg.assert)) { | ||
| for (const name in def.modifiers) { | ||
| Assert(!prototype[name], 'Rule conflict in', def.type, name); | ||
| assert(!prototype[name], 'Rule conflict in', def.type, name); | ||
| const modifier = def.modifiers[name]; | ||
| Assert(typeof modifier === 'function', 'Invalid modifier definition for', def.type, name); | ||
| assert(typeof modifier === 'function', 'Invalid modifier definition for', def.type, name); | ||
@@ -167,3 +166,3 @@ const method = function (arg) { | ||
| for (const override in def.overrides) { | ||
| Assert(base[override], 'Cannot override missing', override); | ||
| assert(base[override], 'Cannot override missing', override); | ||
| def.overrides[override][Common.symbols.parent] = base[override]; | ||
@@ -170,0 +169,0 @@ schema.$_super[override] = base[override].bind(schema); // Backwards compatibility |
+9
-10
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { assert, clone } = require('@hapi/hoek'); | ||
@@ -57,3 +56,3 @@ const Cache = require('./cache'); | ||
| Assert(!args.length || ['alternatives', 'link', 'object'].includes(type), 'The', type, 'type does not allow arguments'); | ||
| assert(!args.length || ['alternatives', 'link', 'object'].includes(type), 'The', type, 'type does not allow arguments'); | ||
| return internals.generate(this, internals.types[type], args); | ||
@@ -113,3 +112,3 @@ }; | ||
| Assert(typeof Manifest.build === 'function', 'Manifest functionality disabled'); | ||
| assert(typeof Manifest.build === 'function', 'Manifest functionality disabled'); | ||
| return Manifest.build(this, desc); | ||
@@ -130,3 +129,3 @@ }, | ||
| Assert(typeof modifier === 'function', 'modifier must be a function'); | ||
| assert(typeof modifier === 'function', 'modifier must be a function'); | ||
@@ -136,3 +135,3 @@ const joi = Object.assign({}, this); | ||
| const schema = modifier(joi[type]()); | ||
| Assert(Common.isSchema(schema), 'modifier must return a valid schema object'); | ||
| assert(Common.isSchema(schema), 'modifier must return a valid schema object'); | ||
@@ -159,3 +158,3 @@ joi[type] = function (...args) { | ||
| Assert(extensions.length, 'You need to provide at least one extension'); | ||
| assert(extensions.length, 'You need to provide at least one extension'); | ||
| this.assert(extensions, Schemas.extensions); | ||
@@ -175,3 +174,3 @@ | ||
| for (const item of expanded) { | ||
| Assert(joi[item.type] === undefined || joi._types.has(item.type), 'Cannot override name', item.type); | ||
| assert(joi[item.type] === undefined || joi._types.has(item.type), 'Cannot override name', item.type); | ||
@@ -245,3 +244,3 @@ const base = item.base || this.any(); | ||
| if (error instanceof Errors.ValidationError === false) { | ||
| error = Clone(error); | ||
| error = clone(error); | ||
| } | ||
@@ -256,3 +255,3 @@ | ||
| Assert(root, 'Must be invoked on a Joi instance.'); | ||
| assert(root, 'Must be invoked on a Joi instance.'); | ||
@@ -259,0 +258,0 @@ schema.$_root = root; |
+15
-16
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { assert, clone } = require('@hapi/hoek'); | ||
@@ -44,3 +43,3 @@ const Common = require('./common'); | ||
| if (schema._preferences) { | ||
| desc.preferences = Clone(schema._preferences, { shallow: ['messages'] }); | ||
| desc.preferences = clone(schema._preferences, { shallow: ['messages'] }); | ||
| delete desc.preferences[Common.symbols.prefs]; | ||
@@ -110,3 +109,3 @@ if (desc.preferences.messages) { | ||
| Assert(!desc[term], 'Cannot describe schema due to internal name conflict with', term); | ||
| assert(!desc[term], 'Cannot describe schema due to internal name conflict with', term); | ||
@@ -131,3 +130,3 @@ const items = schema.$_terms[term]; | ||
| Assert(def.terms[term], 'Term', term, 'missing configuration'); | ||
| assert(def.terms[term], 'Term', term, 'missing configuration'); | ||
| const manifest = def.terms[term].manifest; | ||
@@ -161,3 +160,3 @@ const mapped = typeof manifest === 'object'; | ||
| if (manifest === 'single') { | ||
| Assert(normalized.length === 1, 'Term', term, 'contains more than one item'); | ||
| assert(normalized.length === 1, 'Term', term, 'contains more than one item'); | ||
| desc[term] = normalized[0]; | ||
@@ -194,3 +193,3 @@ continue; | ||
| if (options.assign === 'options') { | ||
| return Clone(item); | ||
| return clone(item); | ||
| } | ||
@@ -272,3 +271,3 @@ | ||
| const setter = def.flags[flag] && def.flags[flag].setter || flag; | ||
| Assert(typeof schema[setter] === 'function', 'Invalid flag', flag, 'for type', desc.type); | ||
| assert(typeof schema[setter] === 'function', 'Invalid flag', flag, 'for type', desc.type); | ||
| schema = schema[setter](this.build(desc.flags[flag])); | ||
@@ -298,3 +297,3 @@ } | ||
| for (const rule of desc.rules) { | ||
| Assert(typeof schema[rule.name] === 'function', 'Invalid rule', rule.name, 'for type', desc.type); | ||
| assert(typeof schema[rule.name] === 'function', 'Invalid rule', rule.name, 'for type', desc.type); | ||
@@ -311,3 +310,3 @@ const args = []; | ||
| if (definition) { | ||
| Assert(keys.length <= definition.length, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to', definition.length, ', found', keys.length, ')'); | ||
| assert(keys.length <= definition.length, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to', definition.length, ', found', keys.length, ')'); | ||
| for (const { name } of definition) { | ||
@@ -318,3 +317,3 @@ args.push(built[name]); | ||
| else { | ||
| Assert(keys.length === 1, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to 1, found', keys.length, ')'); | ||
| assert(keys.length === 1, 'Invalid number of arguments for', desc.type, rule.name, '(expected up to 1, found', keys.length, ')'); | ||
| args.push(built[keys[0]]); | ||
@@ -351,3 +350,3 @@ } | ||
| Assert(def.terms[key], 'Term', key, 'missing configuration'); | ||
| assert(def.terms[key], 'Term', key, 'missing configuration'); | ||
| const manifest = def.terms[key].manifest; | ||
@@ -407,3 +406,3 @@ | ||
| if (options.assign === 'options') { | ||
| return Clone(desc); | ||
| return clone(desc); | ||
| } | ||
@@ -425,3 +424,3 @@ | ||
| if (desc.buffer) { | ||
| Assert(Buffer, 'Buffers are not supported'); | ||
| assert(Buffer, 'Buffers are not supported'); | ||
| return Buffer && Buffer.from(desc.buffer, 'binary'); // $lab:coverage:ignore$ | ||
@@ -447,3 +446,3 @@ } | ||
| if (desc.special) { | ||
| Assert(['deep'].includes(desc.special), 'Unknown special value', desc.special); | ||
| assert(['deep'].includes(desc.special), 'Unknown special value', desc.special); | ||
| return Common.symbols.deepDefault; | ||
@@ -453,3 +452,3 @@ } | ||
| if (desc.value) { | ||
| return Clone(desc.value); | ||
| return clone(desc.value); | ||
| } | ||
@@ -456,0 +455,0 @@ } |
+10
-11
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { assert, clone } = require('@hapi/hoek'); | ||
@@ -17,3 +16,3 @@ const Template = require('./template'); | ||
| if (typeof messages === 'string') { | ||
| Assert(!target, 'Cannot set single message string'); | ||
| assert(!target, 'Cannot set single message string'); | ||
| return new Template(messages); | ||
@@ -25,3 +24,3 @@ } | ||
| if (Template.isTemplate(messages)) { | ||
| Assert(!target, 'Cannot set single message template'); | ||
| assert(!target, 'Cannot set single message template'); | ||
| return messages; | ||
@@ -32,5 +31,5 @@ } | ||
| Assert(typeof messages === 'object' && !Array.isArray(messages), 'Invalid message options'); | ||
| assert(typeof messages === 'object' && !Array.isArray(messages), 'Invalid message options'); | ||
| target = target ? Clone(target) : {}; | ||
| target = target ? clone(target) : {}; | ||
@@ -54,3 +53,3 @@ for (let code in messages) { | ||
| Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code); | ||
| assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code); | ||
@@ -70,3 +69,3 @@ const language = code; | ||
| Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language); | ||
| assert(typeof localized === 'string', 'Invalid message for', code, 'in', language); | ||
| target[language][code] = new Template(localized); | ||
@@ -143,3 +142,3 @@ } | ||
| const target = Clone(base); | ||
| const target = clone(base); | ||
@@ -163,3 +162,3 @@ for (let code in extended) { | ||
| Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code); | ||
| assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code); | ||
@@ -179,3 +178,3 @@ const language = code; | ||
| Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language); | ||
| assert(typeof localized === 'string', 'Invalid message for', code, 'in', language); | ||
| target[language][code] = new Template(localized); | ||
@@ -182,0 +181,0 @@ } |
+10
-10
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -38,3 +38,3 @@ const Common = require('./common'); | ||
| for (const [id, value] of source._byId.entries()) { | ||
| Assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id); | ||
| assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id); | ||
| this._byId.set(id, value); | ||
@@ -44,3 +44,3 @@ } | ||
| for (const [key, value] of source._byKey.entries()) { | ||
| Assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key); | ||
| assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key); | ||
| this._byKey.set(key, value); | ||
@@ -57,3 +57,3 @@ } | ||
| Assert(Common.isSchema(adjusted.schema), 'adjuster function failed to return a joi schema type'); | ||
| assert(Common.isSchema(adjusted.schema), 'adjuster function failed to return a joi schema type'); | ||
@@ -88,3 +88,3 @@ for (const node of chain) { | ||
| const node = this._get(current); | ||
| Assert(node, 'Schema does not contain path', [...behind, ...path].join('.')); | ||
| assert(node, 'Schema does not contain path', [...behind, ...path].join('.')); | ||
@@ -116,4 +116,4 @@ const forward = path.slice(1); | ||
| const existing = this._byId.get(id); | ||
| Assert(!existing || existing.schema === schema, 'Cannot add different schemas with the same id:', id); | ||
| Assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id); | ||
| assert(!existing || existing.schema === schema, 'Cannot add different schemas with the same id:', id); | ||
| assert(!this._byKey.has(id), 'Schema id conflicts with existing key:', id); | ||
@@ -124,4 +124,4 @@ this._byId.set(id, { schema, id }); | ||
| if (key) { | ||
| Assert(!this._byKey.has(key), 'Schema already contains key:', key); | ||
| Assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key); | ||
| assert(!this._byKey.has(key), 'Schema already contains key:', key); | ||
| assert(!this._byId.has(key), 'Schema key conflicts with existing id:', key); | ||
@@ -143,3 +143,3 @@ this._byKey.set(key, { schema, id: key }); | ||
| const node = this._get(current); | ||
| Assert(node, 'Schema does not contain path', [...behind, ...path].join('.')); | ||
| assert(node, 'Schema does not contain path', [...behind, ...path].join('.')); | ||
@@ -146,0 +146,0 @@ nodes = [node, ...nodes]; |
+15
-17
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const Reach = require('@hapi/hoek/lib/reach'); | ||
| const { assert, clone, reach } = require('@hapi/hoek'); | ||
@@ -27,5 +25,5 @@ const Common = require('./common'); | ||
| Assert(typeof key === 'string', 'Invalid reference key:', key); | ||
| assert(typeof key === 'string', 'Invalid reference key:', key); | ||
| Common.assertOptions(options, ['adjust', 'ancestor', 'in', 'iterables', 'map', 'prefix', 'render', 'separator']); | ||
| Assert(!options.prefix || typeof options.prefix === 'object', 'options.prefix must be of type object'); | ||
| assert(!options.prefix || typeof options.prefix === 'object', 'options.prefix must be of type object'); | ||
@@ -42,3 +40,3 @@ const ref = Object.assign({}, internals.defaults, options); | ||
| if (context.root) { | ||
| Assert(!separator || key[0] !== separator, 'Cannot specify relative path with root prefix'); | ||
| assert(!separator || key[0] !== separator, 'Cannot specify relative path with root prefix'); | ||
| ref.ancestor = 'root'; | ||
@@ -58,3 +56,3 @@ if (!key) { | ||
| if (ref.ancestor !== undefined) { | ||
| Assert(!separator || !key || key[0] !== separator, 'Cannot combine prefix with ancestor option'); | ||
| assert(!separator || !key || key[0] !== separator, 'Cannot combine prefix with ancestor option'); | ||
| } | ||
@@ -97,3 +95,3 @@ else { | ||
| Assert(typeof options === 'object', 'Invalid reference construction'); | ||
| assert(typeof options === 'object', 'Invalid reference construction'); | ||
| Common.assertOptions(options, [ | ||
@@ -104,10 +102,10 @@ 'adjust', 'ancestor', 'in', 'iterables', 'map', 'path', 'render', 'separator', 'type', // Copied | ||
| Assert([false, undefined].includes(options.separator) || typeof options.separator === 'string' && options.separator.length === 1, 'Invalid separator'); | ||
| Assert(!options.adjust || typeof options.adjust === 'function', 'options.adjust must be a function'); | ||
| Assert(!options.map || Array.isArray(options.map), 'options.map must be an array'); | ||
| Assert(!options.map || !options.adjust, 'Cannot set both map and adjust options'); | ||
| assert([false, undefined].includes(options.separator) || typeof options.separator === 'string' && options.separator.length === 1, 'Invalid separator'); | ||
| assert(!options.adjust || typeof options.adjust === 'function', 'options.adjust must be a function'); | ||
| assert(!options.map || Array.isArray(options.map), 'options.map must be an array'); | ||
| assert(!options.map || !options.adjust, 'Cannot set both map and adjust options'); | ||
| Object.assign(this, internals.defaults, options); | ||
| Assert(this.type === 'value' || this.ancestor === undefined, 'Non-value references cannot reference ancestors'); | ||
| assert(this.type === 'value' || this.ancestor === undefined, 'Non-value references cannot reference ancestors'); | ||
@@ -127,3 +125,3 @@ if (Array.isArray(this.map)) { | ||
| Assert(!this.in || options.in, 'Invalid in() reference usage'); | ||
| assert(!this.in || options.in, 'Invalid in() reference usage'); | ||
@@ -146,3 +144,3 @@ if (this.type === 'global') { | ||
| Assert(this.ancestor <= state.ancestors.length, 'Invalid reference exceeds the schema root:', this.display); | ||
| assert(this.ancestor <= state.ancestors.length, 'Invalid reference exceeds the schema root:', this.display); | ||
| return this._resolve(state.ancestors[this.ancestor - 1], state, options); | ||
@@ -163,3 +161,3 @@ } | ||
| if (resolved === undefined) { | ||
| resolved = Reach(target, this.path, { iterables: this.iterables, functions: true }); | ||
| resolved = reach(target, this.path, { iterables: this.iterables, functions: true }); | ||
| } | ||
@@ -409,3 +407,3 @@ | ||
| const copy = new exports.Manager(); | ||
| copy.refs = Clone(this.refs); | ||
| copy.refs = clone(this.refs); | ||
| return copy; | ||
@@ -412,0 +410,0 @@ } |
+4
-5
| 'use strict'; | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const Reach = require('@hapi/hoek/lib/reach'); | ||
| const { clone, reach } = require('@hapi/hoek'); | ||
@@ -56,3 +55,3 @@ const Common = require('./common'); | ||
| if (this.mainstay.shadow) { | ||
| this._snapshot = Clone(this.mainstay.shadow.node(this.path)); | ||
| this._snapshot = clone(this.mainstay.shadow.node(this.path)); | ||
| } | ||
@@ -145,3 +144,3 @@ | ||
| return Reach(this._values, path, { iterables: true }); | ||
| return reach(this._values, path, { iterables: true }); | ||
| } | ||
@@ -157,3 +156,3 @@ | ||
| const own = path[path.length - 1]; | ||
| const parent = Reach(this._values, parents, { iterables: true }); | ||
| const parent = reach(this._values, parents, { iterables: true }); | ||
@@ -160,0 +159,0 @@ if (node) { |
+8
-10
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const EscapeHtml = require('@hapi/hoek/lib/escapeHtml'); | ||
| const Formula = require('@sideway/formula'); | ||
| const { assert, clone, escapeHtml } = require('@hapi/hoek'); | ||
| const Formula = require('@hapi/formula'); | ||
@@ -33,4 +31,4 @@ const Common = require('./common'); | ||
| Assert(typeof source === 'string', 'Template source must be a string'); | ||
| Assert(!source.includes('\u0000') && !source.includes('\u0001'), 'Template source cannot contain reserved control characters'); | ||
| assert(typeof source === 'string', 'Template source must be a string'); | ||
| assert(!source.includes('\u0000') && !source.includes('\u0001'), 'Template source cannot contain reserved control characters'); | ||
@@ -44,7 +42,7 @@ this.source = source; | ||
| const { functions, ...opts } = options; | ||
| this._settings = Object.keys(opts).length ? Clone(opts) : undefined; | ||
| this._settings = Object.keys(opts).length ? clone(opts) : undefined; | ||
| this._functions = functions; | ||
| if (this._functions) { | ||
| Assert(Object.keys(this._functions).every((key) => typeof key === 'string'), 'Functions keys must be strings'); | ||
| Assert(Object.values(this._functions).every((key) => typeof key === 'function'), 'Functions values must be functions'); | ||
| assert(Object.keys(this._functions).every((key) => typeof key === 'string'), 'Functions keys must be strings'); | ||
| assert(Object.values(this._functions).every((key) => typeof key === 'function'), 'Functions values must be functions'); | ||
| } | ||
@@ -213,3 +211,3 @@ } | ||
| if (string !== undefined) { | ||
| const result = part.raw || (options.errors && options.errors.escapeHtml) === false ? string : EscapeHtml(string); | ||
| const result = part.raw || (options.errors && options.errors.escapeHtml) === false ? string : escapeHtml(string); | ||
| parts.push(internals.wrap(result, part.wrapped && prefs.errors.wrap.label)); | ||
@@ -216,0 +214,0 @@ } |
+4
-4
| 'use strict'; | ||
| const DeepEqual = require('@hapi/hoek/lib/deepEqual'); | ||
| const Pinpoint = require('@sideway/pinpoint'); | ||
| const { deepEqual } = require('@hapi/hoek'); | ||
| const Pinpoint = require('@hapi/pinpoint'); | ||
@@ -235,3 +235,3 @@ const Errors = require('./errors'); | ||
| if (!state.mainstay.debug || | ||
| DeepEqual(from, to)) { | ||
| deepEqual(from, to)) { | ||
@@ -331,3 +331,3 @@ return; | ||
| for (const skip of skipped) { | ||
| if (DeepEqual(path.slice(0, skip.length), skip)) { | ||
| if (deepEqual(path.slice(0, skip.length), skip)) { | ||
| return true; | ||
@@ -334,0 +334,0 @@ } |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Merge = require('@hapi/hoek/lib/merge'); | ||
| const { assert, merge } = require('@hapi/hoek'); | ||
@@ -100,3 +99,3 @@ const Any = require('./any'); | ||
| return isAnyObj(schema) ? { value: matched.reduce((acc, v) => Merge(acc, v, { mergeArrays: false })) } : { value: matched[matched.length - 1] }; | ||
| return isAnyObj(schema) ? { value: matched.reduce((acc, v) => merge(acc, v, { mergeArrays: false })) } : { value: matched[matched.length - 1] }; | ||
| } | ||
@@ -156,5 +155,5 @@ | ||
| Assert(!this._flags._endedSwitch, 'Unreachable condition'); | ||
| Assert(!this._flags.match, 'Cannot combine match mode', this._flags.match, 'with conditional rule'); | ||
| Assert(options.break === undefined, 'Cannot use break option with alternatives conditional'); | ||
| assert(!this._flags._endedSwitch, 'Unreachable condition'); | ||
| assert(!this._flags.match, 'Cannot combine match mode', this._flags.match, 'with conditional rule'); | ||
| assert(options.break === undefined, 'Cannot use break option with alternatives conditional'); | ||
@@ -182,7 +181,7 @@ const obj = this.clone(); | ||
| Assert(['any', 'one', 'all'].includes(mode), 'Invalid alternatives match mode', mode); | ||
| assert(['any', 'one', 'all'].includes(mode), 'Invalid alternatives match mode', mode); | ||
| if (mode !== 'any') { | ||
| for (const match of this.$_terms.matches) { | ||
| Assert(match.schema, 'Cannot combine match mode', mode, 'with conditional rules'); | ||
| assert(match.schema, 'Cannot combine match mode', mode, 'with conditional rules'); | ||
| } | ||
@@ -198,6 +197,6 @@ } | ||
| Assert(schemas.length, 'Missing alternative schemas'); | ||
| assert(schemas.length, 'Missing alternative schemas'); | ||
| Common.verifyFlat(schemas, 'try'); | ||
| Assert(!this._flags._endedSwitch, 'Unreachable condition'); | ||
| assert(!this._flags._endedSwitch, 'Unreachable condition'); | ||
@@ -225,2 +224,26 @@ const obj = this.clone(); | ||
| return obj.$_modify({ each, ref: false }); | ||
| }, | ||
| isAsync() { | ||
| if (this.$_terms.externals?.length) { | ||
| return true; | ||
| } | ||
| for (const match of this.$_terms.matches) { | ||
| if (match.schema?.isAsync()) { | ||
| return true; | ||
| } | ||
| if (match.then?.isAsync()) { | ||
| return true; | ||
| } | ||
| if (match.otherwise?.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
@@ -227,0 +250,0 @@ }, |
+5
-5
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -39,4 +39,4 @@ const Base = require('../base'); | ||
| Assert(typeof method === 'function', 'Method must be a function'); | ||
| Assert(description === undefined || description && typeof description === 'string', 'Description must be a non-empty string'); | ||
| assert(typeof method === 'function', 'Method must be a function'); | ||
| assert(description === undefined || description && typeof description === 'string', 'Description must be a non-empty string'); | ||
@@ -68,3 +68,3 @@ return this.$_addRule({ name: 'custom', args: { method, description } }); | ||
| Assert(Common.isSchema(schema) && schema._flags.id, 'Schema must be a schema with an id'); | ||
| assert(Common.isSchema(schema) && schema._flags.id, 'Schema must be a schema with an id'); | ||
@@ -82,3 +82,3 @@ const obj = this.clone(); | ||
| Assert(code && typeof code === 'string', 'Invalid warning code'); | ||
| assert(code && typeof code === 'string', 'Invalid warning code'); | ||
@@ -85,0 +85,0 @@ return this.$_addRule({ name: 'warning', args: { code, local }, warn: true }); |
+32
-10
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const DeepEqual = require('@hapi/hoek/lib/deepEqual'); | ||
| const Reach = require('@hapi/hoek/lib/reach'); | ||
| const { assert, deepEqual, reach } = require('@hapi/hoek'); | ||
@@ -420,3 +418,3 @@ const Any = require('./any'); | ||
| const value = enabled === undefined ? true : !!enabled; | ||
| Assert(!value || !this._flags._arrayItems, 'Cannot specify single rule when array has array items'); | ||
| assert(!value || !this._flags._arrayItems, 'Cannot specify single rule when array has array items'); | ||
@@ -438,3 +436,3 @@ return this.$_setFlag('single', value); | ||
| settings.by = Compile.ref(options.by, { ancestor: 0 }); | ||
| Assert(!settings.by.ancestor, 'Cannot sort by ancestor'); | ||
| assert(!settings.by.ancestor, 'Cannot sort by ancestor'); | ||
| } | ||
@@ -479,3 +477,3 @@ | ||
| Assert(!comparator || typeof comparator === 'function' || typeof comparator === 'string', 'comparator must be a function or a string'); | ||
| assert(!comparator || typeof comparator === 'function' || typeof comparator === 'string', 'comparator must be a function or a string'); | ||
| Common.assertOptions(options, ['ignoreUndefined', 'separator']); | ||
@@ -510,9 +508,9 @@ | ||
| const compare = comparator || DeepEqual; | ||
| const compare = comparator || deepEqual; | ||
| const ignoreUndefined = options.ignoreUndefined; | ||
| for (let i = 0; i < value.length; ++i) { | ||
| const item = path ? Reach(value[i], path) : value[i]; | ||
| const item = path ? reach(value[i], path) : value[i]; | ||
| const records = comparator ? found.custom : found[typeof item]; | ||
| Assert(records, 'Failed to find unique map container for type', typeof item); | ||
| assert(records, 'Failed to find unique map container for type', typeof item); | ||
@@ -572,2 +570,26 @@ if (records instanceof Map) { | ||
| overrides: { | ||
| isAsync() { | ||
| if (this.$_terms.externals?.length) { | ||
| return true; | ||
| } | ||
| for (const item of this.$_terms.items) { | ||
| if (item.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| for (const item of this.$_terms.ordered) { | ||
| if (item.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| }, | ||
| cast: { | ||
@@ -735,3 +757,3 @@ set: { | ||
| Assert(!obj._flags.single, 'Cannot specify array item with single rule enabled'); | ||
| assert(!obj._flags.single, 'Cannot specify array item with single rule enabled'); | ||
| obj.$_setFlag('_arrayItems', true, { clone: false }); | ||
@@ -738,0 +760,0 @@ } |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -24,3 +24,3 @@ const Any = require('./any'); | ||
| } | ||
| catch (ignoreErr) { } | ||
| catch { } | ||
| } | ||
@@ -41,3 +41,3 @@ } | ||
| Assert(Buffer.isEncoding(encoding), 'Invalid encoding:', encoding); | ||
| assert(Buffer.isEncoding(encoding), 'Invalid encoding:', encoding); | ||
@@ -44,0 +44,0 @@ return this.$_setFlag('encoding', encoding); |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -79,3 +79,3 @@ const Any = require('./any'); | ||
| Assert(value !== undefined, 'Cannot call truthy with undefined'); | ||
| assert(value !== undefined, 'Cannot call truthy with undefined'); | ||
| obj.$_terms.truthy.add(value); | ||
@@ -99,3 +99,3 @@ } | ||
| Assert(value !== undefined, 'Cannot call falsy with undefined'); | ||
| assert(value !== undefined, 'Cannot call falsy with undefined'); | ||
| obj.$_terms.falsy.add(value); | ||
@@ -102,0 +102,0 @@ } |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -81,3 +81,3 @@ const Any = require('./any'); | ||
| Assert(['iso', 'javascript', 'unix'].includes(format), 'Unknown date format', format); | ||
| assert(['iso', 'javascript', 'unix'].includes(format), 'Unknown date format', format); | ||
@@ -126,3 +126,3 @@ return this.$_setFlag('format', format); | ||
| Assert(['javascript', 'unix'].includes(type), '"type" must be one of "javascript, unix"'); | ||
| assert(['javascript', 'unix'].includes(type), '"type" must be one of "javascript, unix"'); | ||
@@ -129,0 +129,0 @@ return this.format(type); |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -23,3 +23,3 @@ const Keys = require('./keys'); | ||
| Assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer'); | ||
| assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer'); | ||
@@ -56,3 +56,3 @@ return this.$_addRule({ name: 'arity', args: { n } }); | ||
| Assert(Number.isSafeInteger(n) && n > 0, 'n must be a strict positive integer'); | ||
| assert(Number.isSafeInteger(n) && n > 0, 'n must be a strict positive integer'); | ||
@@ -74,3 +74,3 @@ return this.$_addRule({ name: 'minArity', args: { n } }); | ||
| Assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer'); | ||
| assert(Number.isSafeInteger(n) && n >= 0, 'n must be a positive integer'); | ||
@@ -77,0 +77,0 @@ return this.$_addRule({ name: 'maxArity', args: { n } }); |
+39
-16
| 'use strict'; | ||
| const ApplyToDefaults = require('@hapi/hoek/lib/applyToDefaults'); | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const { applyToDefaults, assert, clone: Clone } = require('@hapi/hoek'); | ||
| const Topo = require('@hapi/topo'); | ||
@@ -202,3 +200,3 @@ | ||
| Assert(message === undefined || typeof message === 'string', 'Message must be a string'); | ||
| assert(message === undefined || typeof message === 'string', 'Message must be a string'); | ||
@@ -229,3 +227,3 @@ schema = this.$_compile(schema, { appendPath: true }); | ||
| Assert(typeof constructor === 'function', 'constructor must be a function'); | ||
| assert(typeof constructor === 'function', 'constructor must be a function'); | ||
@@ -250,4 +248,4 @@ name = name || constructor.name; | ||
| Assert(schema === undefined || typeof schema === 'object', 'Object schema must be a valid object'); | ||
| Assert(!Common.isSchema(schema), 'Object schema cannot be a joi schema'); | ||
| assert(schema === undefined || typeof schema === 'object', 'Object schema must be a valid object'); | ||
| assert(!Common.isSchema(schema), 'Object schema cannot be a joi schema'); | ||
@@ -343,7 +341,7 @@ const obj = this.clone(); | ||
| Assert(schema !== undefined, 'Invalid rule'); | ||
| assert(schema !== undefined, 'Invalid rule'); | ||
| Common.assertOptions(options, ['fallthrough', 'matches']); | ||
| if (isRegExp) { | ||
| Assert(!pattern.flags.includes('g') && !pattern.flags.includes('y'), 'pattern should not use global or sticky mode'); | ||
| assert(!pattern.flags.includes('g') && !pattern.flags.includes('y'), 'pattern should not use global or sticky mode'); | ||
| } | ||
@@ -409,5 +407,5 @@ | ||
| Assert(typeof from === 'string' || from instanceof RegExp, 'Rename missing the from argument'); | ||
| Assert(typeof to === 'string' || to instanceof Template, 'Invalid rename to argument'); | ||
| Assert(to !== from, 'Cannot rename key to same name:', from); | ||
| assert(typeof from === 'string' || from instanceof RegExp, 'Rename missing the from argument'); | ||
| assert(typeof to === 'string' || to instanceof Template, 'Invalid rename to argument'); | ||
| assert(to !== from, 'Cannot rename key to same name:', from); | ||
@@ -420,3 +418,3 @@ Common.assertOptions(options, ['alias', 'ignoreUndefined', 'override', 'multiple']); | ||
| for (const rename of obj.$_terms.renames) { | ||
| Assert(rename.from !== from, 'Cannot rename the same key multiple times'); | ||
| assert(rename.from !== from, 'Cannot rename the same key multiple times'); | ||
| } | ||
@@ -431,3 +429,3 @@ | ||
| to, | ||
| options: ApplyToDefaults(internals.renameDefaults, options) | ||
| options: applyToDefaults(internals.renameDefaults, options) | ||
| }); | ||
@@ -496,2 +494,27 @@ | ||
| return this.$_parent('default', value, options); | ||
| }, | ||
| isAsync() { | ||
| if (this.$_terms.externals?.length) { | ||
| return true; | ||
| } | ||
| if (this.$_terms.keys?.length) { | ||
| for (const key of this.$_terms.keys) { | ||
| if (key.schema.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| if (this.$_terms.patterns?.length) { | ||
| for (const pattern of this.$_terms.patterns) { | ||
| if (pattern.rule.isAsync()) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
@@ -600,3 +623,3 @@ }, | ||
| Assert(key === null || typeof key === 'string', rel, 'key must be a strings'); | ||
| assert(key === null || typeof key === 'string', rel, 'key must be a strings'); | ||
@@ -618,3 +641,3 @@ // Extract options from peers array | ||
| for (const peer of peers) { | ||
| Assert(typeof peer === 'string', rel, 'peers must be strings'); | ||
| assert(typeof peer === 'string', rel, 'peers must be strings'); | ||
| paths.push(Compile.ref(peer, { separator, ancestor: 0, prefix: false })); | ||
@@ -621,0 +644,0 @@ } |
+11
-11
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -34,3 +34,3 @@ const Any = require('./any'); | ||
| Assert(schema.$_terms.link, 'Uninitialized link schema'); | ||
| assert(schema.$_terms.link, 'Uninitialized link schema'); | ||
@@ -52,8 +52,8 @@ const linked = internals.generate(schema, value, state, prefs); | ||
| Assert(!this.$_terms.link, 'Cannot reinitialize schema'); | ||
| assert(!this.$_terms.link, 'Cannot reinitialize schema'); | ||
| ref = Compile.ref(ref); | ||
| Assert(ref.type === 'value' || ref.type === 'local', 'Invalid reference type:', ref.type); | ||
| Assert(ref.type === 'local' || ref.ancestor === 'root' || ref.ancestor > 0, 'Link cannot reference itself'); | ||
| assert(ref.type === 'value' || ref.type === 'local', 'Invalid reference type:', ref.type); | ||
| assert(ref.type === 'local' || ref.ancestor === 'root' || ref.ancestor > 0, 'Link cannot reference itself'); | ||
@@ -78,5 +78,5 @@ const obj = this.clone(); | ||
| Assert(this.$_terms.link, 'Uninitialized link schema'); | ||
| Assert(Common.isSchema(source), 'Invalid schema object'); | ||
| Assert(source.type !== 'link', 'Cannot merge type link with another link'); | ||
| assert(this.$_terms.link, 'Uninitialized link schema'); | ||
| assert(Common.isSchema(source), 'Invalid schema object'); | ||
| assert(source.type !== 'link', 'Cannot merge type link with another link'); | ||
@@ -98,3 +98,3 @@ const obj = this.clone(); | ||
| Assert(desc.link, 'Invalid link description missing link'); | ||
| assert(desc.link, 'Invalid link description missing link'); | ||
| return obj.ref(desc.link); | ||
@@ -122,3 +122,3 @@ } | ||
| } | ||
| catch (ignoreErr) { | ||
| catch { | ||
| internals.assert(false, 'to non-existing schema', ref, schema, state, prefs); | ||
@@ -172,3 +172,3 @@ } | ||
| Assert(false, `"${Errors.label(schema._flags, state, prefs)}" contains link reference "${ref.display}" ${message}`); | ||
| assert(false, `"${Errors.label(schema._flags, state, prefs)}" contains link reference "${ref.display}" ${message}`); | ||
| }; |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -254,3 +254,3 @@ const Any = require('./any'); | ||
| Assert(Number.isSafeInteger(limit), 'limit must be an integer'); | ||
| assert(Number.isSafeInteger(limit), 'limit must be an integer'); | ||
@@ -275,3 +275,3 @@ return this.$_addRule({ name: 'precision', args: { limit } }); | ||
| Assert(['negative', 'positive'].includes(sign), 'Invalid sign', sign); | ||
| assert(['negative', 'positive'].includes(sign), 'Invalid sign', sign); | ||
@@ -295,3 +295,3 @@ return this.$_addRule({ name: 'sign', args: { sign } }); | ||
| Assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
| assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
@@ -298,0 +298,0 @@ return this.$_setFlag('unsafe', enabled); |
+84
-52
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Domain = require('@sideway/address/lib/domain'); | ||
| const Email = require('@sideway/address/lib/email'); | ||
| const Ip = require('@sideway/address/lib/ip'); | ||
| const EscapeRegex = require('@hapi/hoek/lib/escapeRegex'); | ||
| const Tlds = require('@sideway/address/lib/tlds'); | ||
| const Uri = require('@sideway/address/lib/uri'); | ||
| const { assert, escapeRegex } = require('@hapi/hoek'); | ||
| const { isDomainValid, isEmailValid, ipRegex, uriRegex } = require('@hapi/address'); | ||
| const Tlds = require('@hapi/tlds'); | ||
@@ -16,3 +12,3 @@ const Any = require('./any'); | ||
| const internals = { | ||
| tlds: Tlds instanceof Set ? { tlds: { allow: Tlds, deny: null } } : false, // $lab:coverage:ignore$ | ||
| tlds: Tlds.tlds instanceof Set ? { tlds: { allow: Tlds.tlds, deny: null } } : false, // $lab:coverage:ignore$ | ||
| base64Regex: { | ||
@@ -36,3 +32,3 @@ // paddingRequired | ||
| }, | ||
| ipRegex: Ip.regex({ cidr: 'forbidden' }).regex, | ||
| ipRegex: ipRegex({ cidr: 'forbidden' }).regex, | ||
| isoDurationRegex: /^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$/, | ||
@@ -176,4 +172,4 @@ | ||
| options = { urlSafe: false, paddingRequired: true, ...options }; | ||
| Assert(typeof options.paddingRequired === 'boolean', 'paddingRequired must be boolean'); | ||
| Assert(typeof options.urlSafe === 'boolean', 'urlSafe must be boolean'); | ||
| assert(typeof options.paddingRequired === 'boolean', 'paddingRequired must be boolean'); | ||
| assert(typeof options.urlSafe === 'boolean', 'urlSafe must be boolean'); | ||
@@ -196,3 +192,3 @@ return this.$_addRule({ name: 'base64', args: { options } }); | ||
| Assert(['lower', 'upper'].includes(direction), 'Invalid case:', direction); | ||
| assert(['lower', 'upper'].includes(direction), 'Invalid case:', direction); | ||
@@ -247,3 +243,3 @@ return this.$_addRule({ name: 'case', args: { direction } }); | ||
| options = { paddingRequired: true, ...options }; | ||
| Assert(typeof options.paddingRequired === 'boolean', 'paddingRequired must be boolean'); | ||
| assert(typeof options.paddingRequired === 'boolean', 'paddingRequired must be boolean'); | ||
@@ -279,3 +275,3 @@ return this.$_addRule({ name: 'dataUri', args: { options } }); | ||
| if (options) { | ||
| Common.assertOptions(options, ['allowFullyQualified', 'allowUnicode', 'maxDomainSegments', 'minDomainSegments', 'tlds']); | ||
| Common.assertOptions(options, ['allowFullyQualified', 'allowUnicode', 'allowUnderscore', 'maxDomainSegments', 'minDomainSegments', 'tlds']); | ||
| } | ||
@@ -288,3 +284,3 @@ | ||
| if (Domain.isValid(value, address)) { | ||
| if (isDomainValid(value, address)) { | ||
| return value; | ||
@@ -301,6 +297,6 @@ } | ||
| Common.assertOptions(options, ['allowFullyQualified', 'allowUnicode', 'ignoreLength', 'maxDomainSegments', 'minDomainSegments', 'multiple', 'separator', 'tlds']); | ||
| Assert(options.multiple === undefined || typeof options.multiple === 'boolean', 'multiple option must be an boolean'); | ||
| assert(options.multiple === undefined || typeof options.multiple === 'boolean', 'multiple option must be an boolean'); | ||
| const address = internals.addressOptions(options); | ||
| const regex = new RegExp(`\\s*[${options.separator ? EscapeRegex(options.separator) : ','}]\\s*`); | ||
| const regex = new RegExp(`\\s*[${options.separator ? escapeRegex(options.separator) : ','}]\\s*`); | ||
@@ -314,3 +310,3 @@ return this.$_addRule({ name: 'email', args: { options }, regex, address }); | ||
| for (const email of emails) { | ||
| if (!Email.isValid(email, address)) { | ||
| if (!isEmailValid(email, address)) { | ||
| invalids.push(email); | ||
@@ -332,4 +328,11 @@ } | ||
| Common.assertOptions(options, ['version', 'separator']); | ||
| Common.assertOptions(options, ['version', 'separator', 'wrapper']); | ||
| assert( | ||
| options.wrapper === undefined || | ||
| typeof options.wrapper === 'boolean' || | ||
| (typeof options.wrapper === 'string' && typeof internals.guidBrackets[options.wrapper] === 'string'), | ||
| `"wrapper" must be true, false, or one of "${Object.keys(internals.guidBrackets).filter(Boolean).join('", "')}"` | ||
| ); | ||
| let versionNumbers = ''; | ||
@@ -340,3 +343,3 @@ | ||
| Assert(versions.length >= 1, 'version must have at least 1 valid version specified'); | ||
| assert(versions.length >= 1, 'version must have at least 1 valid version specified'); | ||
| const set = new Set(); | ||
@@ -346,6 +349,6 @@ | ||
| const version = versions[i]; | ||
| Assert(typeof version === 'string', 'version at position ' + i + ' must be a string'); | ||
| assert(typeof version === 'string', 'version at position ' + i + ' must be a string'); | ||
| const versionNumber = internals.guidVersions[version.toLowerCase()]; | ||
| Assert(versionNumber, 'version at position ' + i + ' must be one of ' + Object.keys(internals.guidVersions).join(', ')); | ||
| Assert(!set.has(versionNumber), 'version at position ' + i + ' must not be a duplicate'); | ||
| assert(versionNumber, 'version at position ' + i + ' must be one of ' + Object.keys(internals.guidVersions).join(', ')); | ||
| assert(!set.has(versionNumber), 'version at position ' + i + ' must not be a duplicate'); | ||
@@ -357,3 +360,3 @@ versionNumbers += versionNumber; | ||
| Assert(internals.guidSeparators.has(options.separator), 'separator must be one of true, false, "-", or ":"'); | ||
| assert(internals.guidSeparators.has(options.separator), 'separator must be one of true, false, "-", or ":"'); | ||
| const separator = options.separator === undefined ? '[:-]?' : | ||
@@ -363,6 +366,34 @@ options.separator === true ? '[:-]' : | ||
| const regex = new RegExp(`^([\\[{\\(]?)[0-9A-F]{8}(${separator})[0-9A-F]{4}\\2?[${versionNumbers || '0-9A-F'}][0-9A-F]{3}\\2?[${versionNumbers ? '89AB' : '0-9A-F'}][0-9A-F]{3}\\2?[0-9A-F]{12}([\\]}\\)]?)$`, 'i'); | ||
| let wrapperStart; | ||
| let wrapperEnd; | ||
| if (options.wrapper === undefined) { | ||
| wrapperStart = '[\\[{\\(]?'; | ||
| wrapperEnd = '[\\]}\\)]?'; | ||
| } | ||
| else if (options.wrapper === true) { | ||
| wrapperStart = '[\\[{\\(]'; | ||
| wrapperEnd = '[\\]}\\)]'; | ||
| } | ||
| else if (options.wrapper === false) { | ||
| wrapperStart = ''; | ||
| wrapperEnd = ''; | ||
| } | ||
| else { | ||
| wrapperStart = escapeRegex(options.wrapper); | ||
| wrapperEnd = escapeRegex(internals.guidBrackets[options.wrapper]); | ||
| } | ||
| const regex = new RegExp( | ||
| `^(${wrapperStart})[0-9A-F]{8}(${separator})[0-9A-F]{4}\\2?[${ | ||
| versionNumbers || '0-9A-F' | ||
| }][0-9A-F]{3}\\2?[${ | ||
| versionNumbers ? '89AB' : '0-9A-F' | ||
| }][0-9A-F]{3}\\2?[0-9A-F]{12}(${wrapperEnd})$`, | ||
| 'i' | ||
| ); | ||
| return this.$_addRule({ name: 'guid', args: { options }, regex }); | ||
| }, | ||
| validate(value, helpers, args, { regex }) { | ||
@@ -376,5 +407,6 @@ | ||
| // Matching braces | ||
| const open = results[1]; | ||
| const close = results[results.length - 1]; | ||
| if (internals.guidBrackets[results[1]] !== results[results.length - 1]) { | ||
| if ((open || close) && internals.guidBrackets[open] !== close) { | ||
| return helpers.error('string.guid'); | ||
@@ -393,4 +425,4 @@ } | ||
| options = { byteAligned: false, prefix: false, ...options }; | ||
| Assert(typeof options.byteAligned === 'boolean', 'byteAligned must be boolean'); | ||
| Assert(typeof options.prefix === 'boolean' || options.prefix === 'optional', 'prefix must be boolean or "optional"'); | ||
| assert(typeof options.byteAligned === 'boolean', 'byteAligned must be boolean'); | ||
| assert(typeof options.prefix === 'boolean' || options.prefix === 'optional', 'prefix must be boolean or "optional"'); | ||
@@ -427,3 +459,3 @@ return this.$_addRule({ name: 'hex', args: { options } }); | ||
| if (Domain.isValid(value, { minDomainSegments: 1 }) || | ||
| if (isDomainValid(value, { minDomainSegments: 1 }) || | ||
| internals.ipRegex.test(value)) { | ||
@@ -450,3 +482,3 @@ | ||
| const { cidr, versions, regex } = Ip.regex(options); | ||
| const { cidr, versions, regex } = ipRegex(options); | ||
| const version = options.version ? versions : undefined; | ||
@@ -550,3 +582,3 @@ return this.$_addRule({ name: 'ip', args: { options: { cidr, version } }, regex }); | ||
| Assert(internals.normalizationForms.includes(form), 'normalization form must be one of ' + internals.normalizationForms.join(', ')); | ||
| assert(internals.normalizationForms.includes(form), 'normalization form must be one of ' + internals.normalizationForms.join(', ')); | ||
@@ -570,4 +602,4 @@ return this.$_addRule({ name: 'normalize', args: { form } }); | ||
| Assert(regex instanceof RegExp, 'regex must be a RegExp'); | ||
| Assert(!regex.flags.includes('g') && !regex.flags.includes('y'), 'regex should not use global or sticky mode'); | ||
| assert(regex instanceof RegExp, 'regex must be a RegExp'); | ||
| assert(!regex.flags.includes('g') && !regex.flags.includes('y'), 'regex should not use global or sticky mode'); | ||
@@ -601,7 +633,7 @@ if (typeof options === 'string') { | ||
| if (typeof pattern === 'string') { | ||
| pattern = new RegExp(EscapeRegex(pattern), 'g'); | ||
| pattern = new RegExp(escapeRegex(pattern), 'g'); | ||
| } | ||
| Assert(pattern instanceof RegExp, 'pattern must be a RegExp'); | ||
| Assert(typeof replacement === 'string', 'replacement must be a String'); | ||
| assert(pattern instanceof RegExp, 'pattern must be a RegExp'); | ||
| assert(typeof replacement === 'string', 'replacement must be a String'); | ||
@@ -637,3 +669,3 @@ const obj = this.clone(); | ||
| Assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
| assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
@@ -658,3 +690,3 @@ return this.$_addRule({ name: 'trim', args: { enabled } }); | ||
| Assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
| assert(typeof enabled === 'boolean', 'enabled must be a boolean'); | ||
@@ -681,3 +713,3 @@ return this.$_setFlag('truncate', enabled); | ||
| const { regex, scheme } = Uri.regex(options); | ||
| const { regex, scheme } = uriRegex(options); | ||
| const domain = options.domain ? internals.addressOptions(options.domain) : null; | ||
@@ -706,3 +738,3 @@ return this.$_addRule({ name: 'uri', args: { options }, regex, domain, scheme }); | ||
| (!options.allowRelative || matched) && | ||
| !Domain.isValid(matched, domain)) { | ||
| !isDomainValid(matched, domain)) { | ||
@@ -788,3 +820,3 @@ return helpers.error('string.domain', { value: matched }); | ||
| Assert(options.minDomainSegments === undefined || | ||
| assert(options.minDomainSegments === undefined || | ||
| Number.isSafeInteger(options.minDomainSegments) && options.minDomainSegments > 0, 'minDomainSegments must be a positive integer'); | ||
@@ -794,3 +826,3 @@ | ||
| Assert(options.maxDomainSegments === undefined || | ||
| assert(options.maxDomainSegments === undefined || | ||
| Number.isSafeInteger(options.maxDomainSegments) && options.maxDomainSegments > 0, 'maxDomainSegments must be a positive integer'); | ||
@@ -807,7 +839,7 @@ | ||
| Assert(internals.tlds, 'Built-in TLD list disabled'); | ||
| assert(internals.tlds, 'Built-in TLD list disabled'); | ||
| return Object.assign({}, options, internals.tlds); | ||
| } | ||
| Assert(typeof options.tlds === 'object', 'tlds must be true, false, or an object'); | ||
| assert(typeof options.tlds === 'object', 'tlds must be true, false, or an object'); | ||
@@ -820,4 +852,4 @@ const deny = options.tlds.deny; | ||
| Assert(options.tlds.deny instanceof Set, 'tlds.deny must be an array, Set, or boolean'); | ||
| Assert(!options.tlds.allow, 'Cannot specify both tlds.allow and tlds.deny lists'); | ||
| assert(options.tlds.deny instanceof Set, 'tlds.deny must be an array, Set, or boolean'); | ||
| assert(!options.tlds.allow, 'Cannot specify both tlds.allow and tlds.deny lists'); | ||
| internals.validateTlds(options.tlds.deny, 'tlds.deny'); | ||
@@ -829,7 +861,7 @@ return options; | ||
| if (!allow) { | ||
| return options; | ||
| return { ...options, tlds: false }; | ||
| } | ||
| if (allow === true) { | ||
| Assert(internals.tlds, 'Built-in TLD list disabled'); | ||
| assert(internals.tlds, 'Built-in TLD list disabled'); | ||
| return Object.assign({}, options, internals.tlds); | ||
@@ -842,3 +874,3 @@ } | ||
| Assert(options.tlds.allow instanceof Set, 'tlds.allow must be an array, Set, or boolean'); | ||
| assert(options.tlds.allow instanceof Set, 'tlds.allow must be an array, Set, or boolean'); | ||
| internals.validateTlds(options.tlds.allow, 'tlds.allow'); | ||
@@ -852,3 +884,3 @@ return options; | ||
| for (const tld of set) { | ||
| Assert(Domain.isValid(tld, { minDomainSegments: 1, maxDomainSegments: 1 }), `${source} must contain valid top level domain names`); | ||
| assert(isDomainValid(tld, { minDomainSegments: 1, maxDomainSegments: 1 }), `${source} must contain valid top level domain names`); | ||
| } | ||
@@ -879,5 +911,5 @@ }; | ||
| Assert(!encoding || Buffer && Buffer.isEncoding(encoding), 'Invalid encoding:', encoding); // $lab:coverage:ignore$ | ||
| assert(!encoding || Buffer && Buffer.isEncoding(encoding), 'Invalid encoding:', encoding); // $lab:coverage:ignore$ | ||
| return schema.$_addRule({ name, method: 'length', args: { limit, encoding }, operator }); | ||
| }; |
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const { assert } = require('@hapi/hoek'); | ||
@@ -65,3 +65,3 @@ const Any = require('./any'); | ||
| Assert(iterable && iterable[Symbol.iterator], 'Iterable must be an iterable or object'); | ||
| assert(iterable && iterable[Symbol.iterator], 'Iterable must be an iterable or object'); | ||
@@ -72,7 +72,7 @@ const obj = this.clone(); | ||
| for (const entry of iterable) { | ||
| Assert(entry && entry[Symbol.iterator], 'Entry must be an iterable'); | ||
| assert(entry && entry[Symbol.iterator], 'Entry must be an iterable'); | ||
| const [key, value] = entry; | ||
| Assert(typeof key !== 'object' && typeof key !== 'function' && typeof key !== 'symbol', 'Key must not be of type object, function, or Symbol'); | ||
| Assert(typeof value === 'symbol', 'Value must be a Symbol'); | ||
| assert(typeof key !== 'object' && typeof key !== 'function' && typeof key !== 'symbol', 'Key must not be of type object, function, or Symbol'); | ||
| assert(typeof value === 'symbol', 'Value must be a Symbol'); | ||
@@ -79,0 +79,0 @@ obj.$_terms.map.set(key, value); |
+26
-18
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const Clone = require('@hapi/hoek/lib/clone'); | ||
| const Ignore = require('@hapi/hoek/lib/ignore'); | ||
| const Reach = require('@hapi/hoek/lib/reach'); | ||
| const { assert, clone, ignore, reach } = require('@hapi/hoek'); | ||
@@ -22,4 +19,4 @@ const Common = require('./common'); | ||
| if (prefs) { | ||
| Assert(prefs.warnings === undefined, 'Cannot override warnings preference in synchronous validation'); | ||
| Assert(prefs.artifacts === undefined, 'Cannot override artifacts preference in synchronous validation'); | ||
| assert(prefs.warnings === undefined, 'Cannot override warnings preference in synchronous validation'); | ||
| assert(prefs.artifacts === undefined, 'Cannot override artifacts preference in synchronous validation'); | ||
| settings = Common.preferences(Common.defaults, prefs); | ||
@@ -29,3 +26,3 @@ } | ||
| const result = internals.entry(value, schema, settings); | ||
| Assert(!result.mainstay.externals.length, 'Schema with external rules must use validateAsync()'); | ||
| assert(!result.mainstay.externals.length, 'Schema with external rules must use validateAsync()'); | ||
| const outcome = { value: result.value }; | ||
@@ -81,3 +78,3 @@ | ||
| const ancestors = path.length ? [root] : []; | ||
| const original = path.length ? Reach(value, path) : value; | ||
| const original = path.length ? reach(value, path) : value; | ||
@@ -195,2 +192,13 @@ if (path.length) { | ||
| exports.standard = function (value, schema) { | ||
| if (schema.isAsync()) { | ||
| return exports.entryAsync(value, schema); | ||
| } | ||
| return exports.entry(value, schema); | ||
| }; | ||
| internals.Mainstay = class { | ||
@@ -266,3 +274,3 @@ | ||
| if (prefs.debug) { | ||
| Assert(schema.$_root.trace, 'Debug mode not supported'); | ||
| assert(schema.$_root.trace, 'Debug mode not supported'); | ||
| return { tracer: schema.$_root.trace()._register(schema), cleanup: true }; | ||
@@ -583,3 +591,3 @@ } | ||
| for (const error of errors) { | ||
| Assert(error instanceof Error || error instanceof Errors.Report, 'error() must return an Error object'); | ||
| assert(error instanceof Error || error instanceof Errors.Report, 'error() must return an Error object'); | ||
| } | ||
@@ -696,3 +704,3 @@ } | ||
| if (typeof source === 'function') { | ||
| const args = source.length ? [Clone(state.ancestors[0]), helpers] : []; | ||
| const args = source.length ? [clone(state.ancestors[0]), helpers] : []; | ||
@@ -720,3 +728,3 @@ try { | ||
| return Clone(source); | ||
| return clone(source); | ||
| }; | ||
@@ -744,8 +752,8 @@ | ||
| active: false, | ||
| debug: Ignore, | ||
| entry: Ignore, | ||
| filter: Ignore, | ||
| log: Ignore, | ||
| resolve: Ignore, | ||
| value: Ignore | ||
| debug: ignore, | ||
| entry: ignore, | ||
| filter: ignore, | ||
| log: ignore, | ||
| resolve: ignore, | ||
| value: ignore | ||
| }; | ||
@@ -752,0 +760,0 @@ |
+4
-5
| 'use strict'; | ||
| const Assert = require('@hapi/hoek/lib/assert'); | ||
| const DeepEqual = require('@hapi/hoek/lib/deepEqual'); | ||
| const { assert, deepEqual } = require('@hapi/hoek'); | ||
@@ -135,3 +134,3 @@ const Common = require('./common'); | ||
| for (const item of this._values) { | ||
| if (DeepEqual(item, value)) { | ||
| if (deepEqual(item, value)) { | ||
| return { value: item }; | ||
@@ -169,3 +168,3 @@ } | ||
| else { | ||
| if (DeepEqual(item, value)) { | ||
| if (deepEqual(item, value)) { | ||
| return { value: item, ref }; | ||
@@ -214,3 +213,3 @@ } | ||
| Assert(!source._override, 'Cannot concat override set of values'); | ||
| assert(!source._override, 'Cannot concat override set of values'); | ||
@@ -217,0 +216,0 @@ const set = new internals.Values([...this._values, ...source._values], [...this._refs, ...source._refs]); |
+21
-12
| { | ||
| "name": "joi", | ||
| "description": "Object schema validation", | ||
| "version": "17.13.3", | ||
| "repository": "git://github.com/hapijs/joi", | ||
| "version": "18.0.0", | ||
| "repository": { | ||
| "url": "git://github.com/hapijs/joi", | ||
| "type": "git" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 20" | ||
| }, | ||
| "main": "lib/index.js", | ||
@@ -18,15 +24,18 @@ "types": "lib/index.d.ts", | ||
| "dependencies": { | ||
| "@hapi/hoek": "^9.3.0", | ||
| "@hapi/topo": "^5.1.0", | ||
| "@sideway/address": "^4.1.5", | ||
| "@sideway/formula": "^3.0.1", | ||
| "@sideway/pinpoint": "^2.0.0" | ||
| "@hapi/address": "^5.1.1", | ||
| "@hapi/formula": "^3.0.2", | ||
| "@hapi/hoek": "^11.0.7", | ||
| "@hapi/pinpoint": "^2.0.1", | ||
| "@hapi/tlds": "^1.1.1", | ||
| "@hapi/topo": "^6.0.2", | ||
| "@standard-schema/spec": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@hapi/bourne": "2.x.x", | ||
| "@hapi/code": "8.x.x", | ||
| "@hapi/bourne": "^3.0.0", | ||
| "@hapi/code": "^9.0.3", | ||
| "@hapi/eslint-plugin": "^7.0.0", | ||
| "@hapi/joi-legacy-test": "npm:@hapi/joi@15.x.x", | ||
| "@hapi/lab": "^25.1.3", | ||
| "@types/node": "^14.18.63", | ||
| "typescript": "4.3.x" | ||
| "@hapi/lab": "^26.0.0", | ||
| "@types/node": "^20.17.47", | ||
| "typescript": "^5.8.3" | ||
| }, | ||
@@ -33,0 +42,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
557849
5.03%10099
1.87%7
40%7
16.67%50
31.58%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated