@nhtio/validation 0.1.0-master-87fc6cd7 → 0.1.0-master-06559f66
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/README.md +0 -4
- package/index.cjs +81 -21
- package/index.cjs.map +1 -1
- package/index.mjs +81 -21
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/private/patches/fqdn.d.ts +5 -0
- package/private/schemas/datetime.d.ts +1 -1
- package/private/schemas.d.ts +6 -0
package/README.md
CHANGED
package/index.cjs
CHANGED
|
@@ -37166,7 +37166,7 @@ var require_messages = __commonJSMin((exports) => {
|
|
|
37166
37166
|
var require_extend = __commonJSMin((exports) => {
|
|
37167
37167
|
const { assert: assert$23, clone: clone$10 } = require_lib$4();
|
|
37168
37168
|
const Common$19 = require_common();
|
|
37169
|
-
const Messages$
|
|
37169
|
+
const Messages$6 = require_messages();
|
|
37170
37170
|
const internals$21 = {};
|
|
37171
37171
|
exports.type = function(from$2, options) {
|
|
37172
37172
|
const base$3 = Object.getPrototypeOf(from$2);
|
|
@@ -37176,7 +37176,7 @@ var require_extend = __commonJSMin((exports) => {
|
|
|
37176
37176
|
delete def.base;
|
|
37177
37177
|
prototype._definition = def;
|
|
37178
37178
|
const parent = base$3._definition || {};
|
|
37179
|
-
def.messages = Messages$
|
|
37179
|
+
def.messages = Messages$6.merge(parent.messages, def.messages);
|
|
37180
37180
|
def.properties = Object.assign({}, parent.properties, def.properties);
|
|
37181
37181
|
schema$2.type = def.type;
|
|
37182
37182
|
def.flags = Object.assign({}, parent.flags, def.flags);
|
|
@@ -37319,7 +37319,7 @@ var require_manifest = __commonJSMin((exports) => {
|
|
|
37319
37319
|
init_dist();
|
|
37320
37320
|
const { assert: assert$22, clone: clone$9 } = require_lib$4();
|
|
37321
37321
|
const Common$18 = require_common();
|
|
37322
|
-
const Messages$
|
|
37322
|
+
const Messages$5 = require_messages();
|
|
37323
37323
|
const Ref$6 = require_ref();
|
|
37324
37324
|
const Template$5 = require_template();
|
|
37325
37325
|
let Schemas$3;
|
|
@@ -37336,7 +37336,7 @@ var require_manifest = __commonJSMin((exports) => {
|
|
|
37336
37336
|
if (schema$2._preferences) {
|
|
37337
37337
|
desc$1.preferences = clone$9(schema$2._preferences, { shallow: ["messages"] });
|
|
37338
37338
|
delete desc$1.preferences[Common$18.symbols.prefs];
|
|
37339
|
-
if (desc$1.preferences.messages) desc$1.preferences.messages = Messages$
|
|
37339
|
+
if (desc$1.preferences.messages) desc$1.preferences.messages = Messages$5.decompile(desc$1.preferences.messages);
|
|
37340
37340
|
}
|
|
37341
37341
|
if (schema$2._valids) desc$1.allow = schema$2._valids.describe();
|
|
37342
37342
|
if (schema$2._invalids) desc$1.invalid = schema$2._invalids.describe();
|
|
@@ -38617,7 +38617,7 @@ var require_base = __commonJSMin((exports, module) => {
|
|
|
38617
38617
|
const Errors$5 = require_errors();
|
|
38618
38618
|
const Extend$2 = require_extend();
|
|
38619
38619
|
const Manifest$2 = require_manifest();
|
|
38620
|
-
const Messages$
|
|
38620
|
+
const Messages$4 = require_messages();
|
|
38621
38621
|
const Modify = require_modify();
|
|
38622
38622
|
const Ref$4 = require_ref();
|
|
38623
38623
|
const Trace$2 = require_trace();
|
|
@@ -39022,7 +39022,7 @@ var require_base = __commonJSMin((exports, module) => {
|
|
|
39022
39022
|
}
|
|
39023
39023
|
$_createError(code$2, value, local, state, prefs, options = {}) {
|
|
39024
39024
|
const flags = options.flags !== false ? this._flags : {};
|
|
39025
|
-
const messages$3 = options.messages ? Messages$
|
|
39025
|
+
const messages$3 = options.messages ? Messages$4.merge(this._definition.messages, options.messages) : this._definition.messages;
|
|
39026
39026
|
return new Errors$5.Report(code$2, value, local, flags, messages$3, state, prefs);
|
|
39027
39027
|
}
|
|
39028
39028
|
$_getFlag(name$2) {
|
|
@@ -39291,7 +39291,7 @@ var require_any = __commonJSMin((exports, module) => {
|
|
|
39291
39291
|
const { assert: assert$17 } = require_lib$4();
|
|
39292
39292
|
const Base = require_base();
|
|
39293
39293
|
const Common$12 = require_common();
|
|
39294
|
-
const Messages$
|
|
39294
|
+
const Messages$3 = require_messages();
|
|
39295
39295
|
module.exports = Base.extend({
|
|
39296
39296
|
type: "any",
|
|
39297
39297
|
flags: { only: { default: false } },
|
|
@@ -39363,7 +39363,7 @@ var require_any = __commonJSMin((exports, module) => {
|
|
|
39363
39363
|
rule.keep = enabled;
|
|
39364
39364
|
},
|
|
39365
39365
|
message(rule, message) {
|
|
39366
|
-
rule.message = Messages$
|
|
39366
|
+
rule.message = Messages$3.compile(message);
|
|
39367
39367
|
},
|
|
39368
39368
|
warn(rule, enabled = true) {
|
|
39369
39369
|
rule.warn = enabled;
|
|
@@ -45239,7 +45239,7 @@ var require_schemas = __commonJSMin((exports) => {
|
|
|
45239
45239
|
var require_common = __commonJSMin((exports) => {
|
|
45240
45240
|
const { assert: Assert, AssertError } = require_lib$4();
|
|
45241
45241
|
const Pkg = (init_package(), __toCommonJS(package_exports).default);
|
|
45242
|
-
let Messages$
|
|
45242
|
+
let Messages$2;
|
|
45243
45243
|
let Schemas$1;
|
|
45244
45244
|
const internals$1 = { isoDate: /^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/ };
|
|
45245
45245
|
exports.version = Pkg.version;
|
|
@@ -45329,7 +45329,7 @@ var require_common = __commonJSMin((exports) => {
|
|
|
45329
45329
|
return Number.isSafeInteger(value) && value >= 0;
|
|
45330
45330
|
};
|
|
45331
45331
|
exports.preferences = function(target, source) {
|
|
45332
|
-
Messages$
|
|
45332
|
+
Messages$2 = Messages$2 || require_messages();
|
|
45333
45333
|
target = target || {};
|
|
45334
45334
|
source = source || {};
|
|
45335
45335
|
const merged = Object.assign({}, target, source);
|
|
@@ -45337,7 +45337,7 @@ var require_common = __commonJSMin((exports) => {
|
|
|
45337
45337
|
merged.errors = Object.assign({}, target.errors, source.errors);
|
|
45338
45338
|
merged.errors.wrap = Object.assign({}, target.errors.wrap, source.errors.wrap);
|
|
45339
45339
|
}
|
|
45340
|
-
if (source.messages) merged.messages = Messages$
|
|
45340
|
+
if (source.messages) merged.messages = Messages$2.compile(source.messages, target.messages);
|
|
45341
45341
|
delete merged[exports.symbols.prefs];
|
|
45342
45342
|
return merged;
|
|
45343
45343
|
};
|
|
@@ -45807,7 +45807,7 @@ var RootFactory = class RootFactory {
|
|
|
45807
45807
|
return instance;
|
|
45808
45808
|
}
|
|
45809
45809
|
};
|
|
45810
|
-
var import_messages = __toESM(require_messages());
|
|
45810
|
+
var import_messages$1 = __toESM(require_messages());
|
|
45811
45811
|
const knexMessages = {
|
|
45812
45812
|
"knex.unique": "The {{#label}} has already been taken",
|
|
45813
45813
|
"knex.exists": "The selected {{#label}} is invalid",
|
|
@@ -45855,7 +45855,7 @@ const resolveQueryBuilder = (connection, table$2) => {
|
|
|
45855
45855
|
query: conn.table(table$2)
|
|
45856
45856
|
};
|
|
45857
45857
|
};
|
|
45858
|
-
const getMergableMessages = (schema$2) => {
|
|
45858
|
+
const getMergableMessages$1 = (schema$2) => {
|
|
45859
45859
|
if ("_definition" in schema$2) {
|
|
45860
45860
|
const def = schema$2._definition;
|
|
45861
45861
|
if ("messages" in def && def.messages) if ("string" === typeof def.messages) return {};
|
|
@@ -45902,8 +45902,8 @@ function findKnexConnection() {
|
|
|
45902
45902
|
}
|
|
45903
45903
|
const knex = (schema$2, root$11, args$1) => {
|
|
45904
45904
|
const prototype = Object.getPrototypeOf(schema$2);
|
|
45905
|
-
const originalMessages = getMergableMessages(schema$2);
|
|
45906
|
-
const mergedMessages = import_messages.merge(originalMessages, knexMessages);
|
|
45905
|
+
const originalMessages = getMergableMessages$1(schema$2);
|
|
45906
|
+
const mergedMessages = import_messages$1.merge(originalMessages, knexMessages);
|
|
45907
45907
|
prototype._definition.messages = mergedMessages;
|
|
45908
45908
|
prototype._definition.flags.knexConnection = {
|
|
45909
45909
|
default: void 0,
|
|
@@ -46047,6 +46047,43 @@ const knex = (schema$2, root$11, args$1) => {
|
|
|
46047
46047
|
};
|
|
46048
46048
|
return RootFactory.generate(root$11, schema$2, args$1);
|
|
46049
46049
|
};
|
|
46050
|
+
var import_messages = __toESM(require_messages());
|
|
46051
|
+
const fqdnMessages = { "string.fqdn": "{{#label}} must be a valid fully qualified domain name" };
|
|
46052
|
+
const getMergableMessages = (schema$2) => {
|
|
46053
|
+
if ("_definition" in schema$2) {
|
|
46054
|
+
const def = schema$2._definition;
|
|
46055
|
+
if ("messages" in def && def.messages) if ("string" === typeof def.messages) return {};
|
|
46056
|
+
else return def.messages;
|
|
46057
|
+
}
|
|
46058
|
+
return {};
|
|
46059
|
+
};
|
|
46060
|
+
const fqdn = (schema$2, root$11, args$1) => {
|
|
46061
|
+
if (schema$2.type !== "string") return schema$2;
|
|
46062
|
+
const prototype = Object.getPrototypeOf(schema$2);
|
|
46063
|
+
const originalMessages = getMergableMessages(schema$2);
|
|
46064
|
+
const mergedMessages = import_messages.merge(originalMessages, fqdnMessages);
|
|
46065
|
+
prototype._definition.messages = mergedMessages;
|
|
46066
|
+
prototype._definition.rules.fqdn = {
|
|
46067
|
+
method() {
|
|
46068
|
+
return this.addRule("fqdn");
|
|
46069
|
+
},
|
|
46070
|
+
validate(value, helpers$8) {
|
|
46071
|
+
if ("string" !== typeof value || value.trim().length === 0) return void 0;
|
|
46072
|
+
if (value.includes("..")) return helpers$8.error("string.fqdn");
|
|
46073
|
+
const labels = value.split(".");
|
|
46074
|
+
for (const label of labels) {
|
|
46075
|
+
if (label.length === 0 || label.length > 63) return helpers$8.error("string.fqdn");
|
|
46076
|
+
if (label.startsWith("-") || label.endsWith("-")) return helpers$8.error("string.fqdn");
|
|
46077
|
+
if (!/^[a-zA-Z0-9-]+$/.test(label)) return helpers$8.error("string.fqdn");
|
|
46078
|
+
}
|
|
46079
|
+
return value;
|
|
46080
|
+
}
|
|
46081
|
+
};
|
|
46082
|
+
if (!prototype.fqdn) prototype.fqdn = function() {
|
|
46083
|
+
return this.$_addRule({ name: "fqdn" });
|
|
46084
|
+
};
|
|
46085
|
+
return RootFactory.generate(root$11, schema$2, args$1);
|
|
46086
|
+
};
|
|
46050
46087
|
var De = (t$7) => {
|
|
46051
46088
|
throw TypeError(t$7);
|
|
46052
46089
|
};
|
|
@@ -134809,6 +134846,13 @@ const phone = function(joi) {
|
|
|
134809
134846
|
type: "phone",
|
|
134810
134847
|
base: joi.any(),
|
|
134811
134848
|
validate(value, { error, schema: schema$2, prefs, state }) {
|
|
134849
|
+
const isEmpty$13 = value === null || value === void 0;
|
|
134850
|
+
const isRequired = schema$2._flags.presence === "required";
|
|
134851
|
+
if (isEmpty$13 && !isRequired) return { value: null };
|
|
134852
|
+
if (isEmpty$13 && isRequired) return {
|
|
134853
|
+
value,
|
|
134854
|
+
errors: [error("any.required", { label: schema$2._flags.label })]
|
|
134855
|
+
};
|
|
134812
134856
|
const arg = schema$2.$_getFlag("country");
|
|
134813
134857
|
const country = joi.isRef(arg) ? arg.resolve(value, state, prefs) : arg;
|
|
134814
134858
|
const pObj = getPhoneObject(value, country);
|
|
@@ -135517,6 +135561,13 @@ const bigint = function(joi) {
|
|
|
135517
135561
|
compare: {
|
|
135518
135562
|
method: false,
|
|
135519
135563
|
validate(value, helpers$8, { limit }, { name: name$2, operator: operator$1 }) {
|
|
135564
|
+
const isEmpty$13 = value === null || value === void 0;
|
|
135565
|
+
const isRequired = helpers$8.schema._flags.presence === "required";
|
|
135566
|
+
if (isEmpty$13 && !isRequired) return null;
|
|
135567
|
+
if (isEmpty$13 && isRequired) return {
|
|
135568
|
+
value,
|
|
135569
|
+
errors: [helpers$8.error("any.required", { label: helpers$8.schema._flags.label })]
|
|
135570
|
+
};
|
|
135520
135571
|
const big = big_default(value.toString());
|
|
135521
135572
|
const threshold = big_default(limit.toString());
|
|
135522
135573
|
const valid$2 = compare$13(big, threshold, operator$1);
|
|
@@ -140136,6 +140187,13 @@ const toDateTime = (value, format) => {
|
|
|
140136
140187
|
return false;
|
|
140137
140188
|
};
|
|
140138
140189
|
const coerce$2 = (value, helpers$8) => {
|
|
140190
|
+
const isEmpty$13 = value === null || value === void 0;
|
|
140191
|
+
const isRequired = helpers$8.schema._flags.presence === "required";
|
|
140192
|
+
if (isEmpty$13 && !isRequired) return { value: null };
|
|
140193
|
+
if (isEmpty$13 && isRequired) return {
|
|
140194
|
+
value,
|
|
140195
|
+
errors: [helpers$8.error("any.required", { label: helpers$8.schema._flags.label })]
|
|
140196
|
+
};
|
|
140139
140197
|
const converted = toDateTime(value);
|
|
140140
140198
|
if (converted) {
|
|
140141
140199
|
const { schema: schema$2, prefs } = helpers$8;
|
|
@@ -140540,7 +140598,8 @@ const knownMessages = {
|
|
|
140540
140598
|
...messages$1,
|
|
140541
140599
|
...messages$2,
|
|
140542
140600
|
...messages,
|
|
140543
|
-
...knexMessages
|
|
140601
|
+
...knexMessages,
|
|
140602
|
+
...fqdnMessages
|
|
140544
140603
|
};
|
|
140545
140604
|
countries.forEach((name$2, iso) => {
|
|
140546
140605
|
knownMessages[`country.${iso}`] = name$2;
|
|
@@ -140731,6 +140790,7 @@ const i18n = (toPatch) => {
|
|
|
140731
140790
|
"string.uriCustomScheme": $t("string.uriCustomScheme"),
|
|
140732
140791
|
"string.uriRelativeOnly": $t("string.uriRelativeOnly"),
|
|
140733
140792
|
"string.uppercase": $t("string.uppercase"),
|
|
140793
|
+
...fqdnMessages,
|
|
140734
140794
|
...knexTranslations
|
|
140735
140795
|
});
|
|
140736
140796
|
case "symbol": return applyMessagesToSchema(schema$2, {
|
|
@@ -143076,7 +143136,7 @@ const encode = (schema$2, options = {}) => {
|
|
|
143076
143136
|
});
|
|
143077
143137
|
}
|
|
143078
143138
|
const json$1 = JSON.stringify({
|
|
143079
|
-
version: "0.1.0-master-
|
|
143139
|
+
version: "0.1.0-master-06559f66",
|
|
143080
143140
|
schema: description$2
|
|
143081
143141
|
}, (key, value) => {
|
|
143082
143142
|
if (typeof value === "bigint") return value.toString();
|
|
@@ -143124,14 +143184,14 @@ const decode = (base64, options = {}) => {
|
|
|
143124
143184
|
});
|
|
143125
143185
|
if (!isPlainObject(description$2) || !("version" in description$2) || !("schema" in description$2) || typeof description$2.version !== "string" || !isPlainObject(description$2.schema)) throw new TypeError("Not a valid encoded schema");
|
|
143126
143186
|
const { version: schemaVersion, schema: schema$2 } = description$2;
|
|
143127
|
-
if (import_semver.valid("0.1.0-master-
|
|
143187
|
+
if (import_semver.valid("0.1.0-master-06559f66")) {
|
|
143128
143188
|
if (!import_semver.valid(import_semver.coerce(schemaVersion))) throw new TypeError(`Invalid schema version: ${schemaVersion}`);
|
|
143129
|
-
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-
|
|
143189
|
+
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-06559f66")) throw new TypeError(`Schema version ${schemaVersion} is not compatible with current version 0.1.0-master-06559f66`);
|
|
143130
143190
|
}
|
|
143131
143191
|
return validator.build(schema$2);
|
|
143132
143192
|
};
|
|
143133
143193
|
const Joi = RootFactory.create({
|
|
143134
|
-
schemaTypeModifiers: [knex],
|
|
143194
|
+
schemaTypeModifiers: [knex, fqdn],
|
|
143135
143195
|
shortcutsModifiers: []
|
|
143136
143196
|
});
|
|
143137
143197
|
const validator = patch(Joi.extend(bigint).extend(datetime).extend(phone));
|
|
@@ -144580,7 +144640,7 @@ init_esm();
|
|
|
144580
144640
|
var import_lib = __toESM(require_lib$3());
|
|
144581
144641
|
var import_lib$1 = __toESM(require_lib$2());
|
|
144582
144642
|
var import_lib$2 = __toESM(require_lib());
|
|
144583
|
-
const version = "0.1.0-master-
|
|
144643
|
+
const version = "0.1.0-master-06559f66";
|
|
144584
144644
|
Object.defineProperty(exports, "ValidationError", {
|
|
144585
144645
|
enumerable: true,
|
|
144586
144646
|
get: function() {
|