@nhtio/validation 0.1.0-master-67185cae → 0.1.0-master-effacff6
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/index.cjs +135 -17
- package/index.cjs.map +1 -1
- package/index.mjs +135 -17
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/private/schemas/datetime.d.ts +108 -40
- package/private/schemas.d.ts +1 -1
package/index.mjs
CHANGED
|
@@ -93982,6 +93982,87 @@ Settings.defaultWeekSettings = {
|
|
|
93982
93982
|
weekend: [6, 7]
|
|
93983
93983
|
};
|
|
93984
93984
|
Settings.throwOnInvalid = false;
|
|
93985
|
+
const removeComments = (str) => {
|
|
93986
|
+
str = str.replace(/\/\/.*$/gm, "");
|
|
93987
|
+
str = str.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
93988
|
+
return str;
|
|
93989
|
+
};
|
|
93990
|
+
const extractFunctionBody = (fn$1) => {
|
|
93991
|
+
const fnString = fn$1.toString();
|
|
93992
|
+
if (fnString.includes("[native code]")) throw new Error("Cannot extract body from native function");
|
|
93993
|
+
const cleanedString = removeComments(fnString);
|
|
93994
|
+
const arrowMatch = cleanedString.match(/^\s*(?:async\s+)?(?:\([^)]*\)|[^=]+)\s*=>\s*(.+)$/s);
|
|
93995
|
+
if (arrowMatch && !arrowMatch[1].trim().startsWith("{")) {
|
|
93996
|
+
const expression = arrowMatch[1].trim().replace(/;?\s*$/, "");
|
|
93997
|
+
if (expression.startsWith("(") && expression.endsWith(")")) {
|
|
93998
|
+
const unwrapped = expression.slice(1, -1).trim();
|
|
93999
|
+
if (unwrapped.startsWith("{") && unwrapped.endsWith("}")) return `return ${unwrapped}`;
|
|
94000
|
+
}
|
|
94001
|
+
return `return ${expression}`;
|
|
94002
|
+
}
|
|
94003
|
+
let braceCount = 0;
|
|
94004
|
+
let inString = false;
|
|
94005
|
+
let stringChar = "";
|
|
94006
|
+
let inTemplate = false;
|
|
94007
|
+
let escaped = false;
|
|
94008
|
+
let firstBrace = -1;
|
|
94009
|
+
let lastBrace = -1;
|
|
94010
|
+
for (const [i$3, char] of Array.from(cleanedString).entries()) {
|
|
94011
|
+
if (escaped) {
|
|
94012
|
+
escaped = false;
|
|
94013
|
+
continue;
|
|
94014
|
+
}
|
|
94015
|
+
if (char === "\\") {
|
|
94016
|
+
escaped = true;
|
|
94017
|
+
continue;
|
|
94018
|
+
}
|
|
94019
|
+
if (!inString && !inTemplate) {
|
|
94020
|
+
if (char === "\"" || char === "'") {
|
|
94021
|
+
inString = true;
|
|
94022
|
+
stringChar = char;
|
|
94023
|
+
continue;
|
|
94024
|
+
}
|
|
94025
|
+
if (char === "`") {
|
|
94026
|
+
inTemplate = true;
|
|
94027
|
+
continue;
|
|
94028
|
+
}
|
|
94029
|
+
} else if (inString && char === stringChar) {
|
|
94030
|
+
inString = false;
|
|
94031
|
+
continue;
|
|
94032
|
+
} else if (inTemplate && char === "`") {
|
|
94033
|
+
inTemplate = false;
|
|
94034
|
+
continue;
|
|
94035
|
+
}
|
|
94036
|
+
if (!inString && !inTemplate) {
|
|
94037
|
+
if (char === "{") {
|
|
94038
|
+
if (firstBrace === -1) firstBrace = i$3;
|
|
94039
|
+
braceCount++;
|
|
94040
|
+
} else if (char === "}") {
|
|
94041
|
+
braceCount--;
|
|
94042
|
+
if (braceCount === 0 && firstBrace !== -1) {
|
|
94043
|
+
lastBrace = i$3;
|
|
94044
|
+
break;
|
|
94045
|
+
}
|
|
94046
|
+
}
|
|
94047
|
+
}
|
|
94048
|
+
}
|
|
94049
|
+
if (firstBrace === -1 || lastBrace === -1 || firstBrace >= lastBrace) throw new Error("Unable to extract function body - no valid braces found");
|
|
94050
|
+
const body = cleanedString.slice(firstBrace + 1, lastBrace).trim();
|
|
94051
|
+
if (/\breturn\b/.test(body)) return body;
|
|
94052
|
+
const beforeBrace = cleanedString.slice(0, firstBrace).trim();
|
|
94053
|
+
if (beforeBrace.endsWith("=>") || beforeBrace.endsWith("=> (") || beforeBrace.endsWith("=>(")) {
|
|
94054
|
+
const objectLiteralPattern = /^\s*(?:[a-zA-Z_$][\w$]*\s*:|["'`][^"'`]+["'`]\s*:|get\s+|set\s+|\[)/;
|
|
94055
|
+
if (objectLiteralPattern.test(body)) return `return {${body}}`;
|
|
94056
|
+
}
|
|
94057
|
+
return `return ${body}`;
|
|
94058
|
+
};
|
|
94059
|
+
const compileCallback = (body) => {
|
|
94060
|
+
try {
|
|
94061
|
+
return new Function("dt", "helpers", body);
|
|
94062
|
+
} catch (error) {
|
|
94063
|
+
throw new Error(`Failed to compile callback: ${error instanceof Error ? error.message : String(error)}`);
|
|
94064
|
+
}
|
|
94065
|
+
};
|
|
93985
94066
|
const messages$2 = {
|
|
93986
94067
|
"datetime.base": "{{#label}} must be a datetime value",
|
|
93987
94068
|
"datetime.exactly": "{{#label}} must be a datetime exactly equal to {{#limit}}",
|
|
@@ -94028,8 +94109,9 @@ const toDateTime = (value, format) => {
|
|
|
94028
94109
|
const dateTime = DateTime.fromFormat(value, format, { zone: "utc" });
|
|
94029
94110
|
if (dateTime.isValid) return dateTime;
|
|
94030
94111
|
}
|
|
94112
|
+
const isoDateTime = DateTime.fromISO(value, { setZone: true });
|
|
94113
|
+
if (isoDateTime.isValid) return isoDateTime;
|
|
94031
94114
|
const luxonMethods = [
|
|
94032
|
-
DateTime.fromISO,
|
|
94033
94115
|
DateTime.fromRFC2822,
|
|
94034
94116
|
DateTime.fromHTTP,
|
|
94035
94117
|
DateTime.fromSQL
|
|
@@ -94049,10 +94131,27 @@ const coerce$2 = (value, helpers) => {
|
|
|
94049
94131
|
const { schema, prefs } = helpers;
|
|
94050
94132
|
if (prefs.convert) {
|
|
94051
94133
|
let returnable = converted;
|
|
94052
|
-
if (schema._flags.setZone && Array.isArray(schema._flags.setZone)) {
|
|
94134
|
+
if (schema._flags.setZone && Array.isArray(schema._flags.setZone)) if (Array.isArray(schema._flags.setZone[0])) Array.from(schema._flags.setZone).forEach((f) => {
|
|
94135
|
+
if (!f) return;
|
|
94136
|
+
const [zone, opts] = Array.from(f);
|
|
94137
|
+
switch (zone) {
|
|
94138
|
+
case "utc":
|
|
94139
|
+
case "UTC":
|
|
94140
|
+
returnable = returnable.toUTC();
|
|
94141
|
+
break;
|
|
94142
|
+
case "local":
|
|
94143
|
+
returnable = returnable.toLocal();
|
|
94144
|
+
break;
|
|
94145
|
+
default:
|
|
94146
|
+
returnable = returnable.setZone(zone, opts);
|
|
94147
|
+
break;
|
|
94148
|
+
}
|
|
94149
|
+
});
|
|
94150
|
+
else {
|
|
94053
94151
|
const [zone, opts] = Array.from(schema._flags.setZone);
|
|
94054
94152
|
switch (zone) {
|
|
94055
94153
|
case "utc":
|
|
94154
|
+
case "UTC":
|
|
94056
94155
|
returnable = returnable.toUTC();
|
|
94057
94156
|
break;
|
|
94058
94157
|
case "local":
|
|
@@ -94068,8 +94167,19 @@ const coerce$2 = (value, helpers) => {
|
|
|
94068
94167
|
if (Array.isArray(schema._flags.toFormat)) {
|
|
94069
94168
|
const fmt = Array.from(schema._flags.toFormat);
|
|
94070
94169
|
const method = fmt.shift();
|
|
94071
|
-
|
|
94072
|
-
|
|
94170
|
+
const processedArgs = fmt.map((arg) => {
|
|
94171
|
+
if (typeof arg === "string" && arg.includes("return")) {
|
|
94172
|
+
const compiledFn = compileCallback(arg);
|
|
94173
|
+
return compiledFn(returnable, helpers);
|
|
94174
|
+
}
|
|
94175
|
+
return arg;
|
|
94176
|
+
});
|
|
94177
|
+
returnable = returnable[method](...processedArgs);
|
|
94178
|
+
} else if (typeof schema._flags.toFormat === "string") if (schema._flags.toFormat.includes("return")) {
|
|
94179
|
+
const compiledFn = compileCallback(schema._flags.toFormat);
|
|
94180
|
+
const result = compiledFn(returnable, helpers);
|
|
94181
|
+
returnable = returnable.toFormat(result);
|
|
94182
|
+
} else returnable = returnable.toFormat(schema._flags.toFormat);
|
|
94073
94183
|
}
|
|
94074
94184
|
return { value: returnable };
|
|
94075
94185
|
}
|
|
@@ -94225,22 +94335,27 @@ const datetime = function(joi) {
|
|
|
94225
94335
|
return this.$_setFlag("setZone", [zone, opts]);
|
|
94226
94336
|
} },
|
|
94227
94337
|
toFormat: { method(format) {
|
|
94228
|
-
|
|
94338
|
+
const processedFormat = typeof format === "function" ? extractFunctionBody(format) : format;
|
|
94339
|
+
return this.$_setFlag("toFormat", processedFormat, { clone: true });
|
|
94229
94340
|
} },
|
|
94230
94341
|
toLocalizedString: { method(formatOpts) {
|
|
94231
|
-
|
|
94342
|
+
const processedOpts = typeof formatOpts === "function" ? extractFunctionBody(formatOpts) : formatOpts;
|
|
94343
|
+
return this.$_setFlag("toFormat", ["toLocaleString", processedOpts], { clone: true });
|
|
94232
94344
|
} },
|
|
94233
94345
|
toISO: { method(opts) {
|
|
94234
|
-
|
|
94346
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94347
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toISO", processedOpts] : ["toISO"], { clone: true });
|
|
94235
94348
|
} },
|
|
94236
94349
|
toISODate: { method(opts) {
|
|
94237
|
-
|
|
94350
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94351
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toISODate", processedOpts] : ["toISODate"], { clone: true });
|
|
94238
94352
|
} },
|
|
94239
94353
|
toISOWeekDate: { method() {
|
|
94240
94354
|
return this.$_setFlag("toFormat", ["toISOWeekDate"], { clone: true });
|
|
94241
94355
|
} },
|
|
94242
94356
|
toISOTime: { method(opts) {
|
|
94243
|
-
|
|
94357
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94358
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toISOTime", processedOpts] : ["toISOTime"], { clone: true });
|
|
94244
94359
|
} },
|
|
94245
94360
|
toRFC2822: { method() {
|
|
94246
94361
|
return this.$_setFlag("toFormat", ["toRFC2822"], { clone: true });
|
|
@@ -94252,10 +94367,12 @@ const datetime = function(joi) {
|
|
|
94252
94367
|
return this.$_setFlag("toFormat", ["toSQLDate"], { clone: true });
|
|
94253
94368
|
} },
|
|
94254
94369
|
toSQLTime: { method(opts) {
|
|
94255
|
-
|
|
94370
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94371
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toSQLTime", processedOpts] : ["toSQLTime"], { clone: true });
|
|
94256
94372
|
} },
|
|
94257
94373
|
toSQL: { method(opts) {
|
|
94258
|
-
|
|
94374
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94375
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toSQL", processedOpts] : ["toSQL"], { clone: true });
|
|
94259
94376
|
} },
|
|
94260
94377
|
toMillis: { method() {
|
|
94261
94378
|
return this.$_setFlag("toFormat", ["toMillis"], { clone: true });
|
|
@@ -94273,14 +94390,15 @@ const datetime = function(joi) {
|
|
|
94273
94390
|
return this.$_setFlag("toFormat", ["toBSON"], { clone: true });
|
|
94274
94391
|
} },
|
|
94275
94392
|
toObject: { method(opts) {
|
|
94276
|
-
const config = opts?.includeConfig !== void 0 ? { includeConfig: opts.includeConfig } : { includeConfig: false };
|
|
94393
|
+
const config = typeof opts === "function" ? extractFunctionBody(opts) : opts?.includeConfig !== void 0 ? { includeConfig: opts.includeConfig } : { includeConfig: false };
|
|
94277
94394
|
return this.$_setFlag("toFormat", ["toObject", config], { clone: true });
|
|
94278
94395
|
} },
|
|
94279
94396
|
toJSDate: { method() {
|
|
94280
94397
|
return this.$_setFlag("toFormat", ["toJSDate"], { clone: true });
|
|
94281
94398
|
} },
|
|
94282
94399
|
toRelative: { method(opts) {
|
|
94283
|
-
|
|
94400
|
+
const processedOpts = opts && typeof opts === "function" ? extractFunctionBody(opts) : opts;
|
|
94401
|
+
return this.$_setFlag("toFormat", processedOpts ? ["toRelative", processedOpts] : ["toRelative"], { clone: true });
|
|
94284
94402
|
} },
|
|
94285
94403
|
setLocale: { method(locale) {
|
|
94286
94404
|
return this.$_setFlag("setLocale", locale);
|
|
@@ -109523,7 +109641,7 @@ const encode = (schema) => {
|
|
|
109523
109641
|
});
|
|
109524
109642
|
}
|
|
109525
109643
|
const json$1 = JSON.stringify({
|
|
109526
|
-
version: "0.1.0-master-
|
|
109644
|
+
version: "0.1.0-master-effacff6",
|
|
109527
109645
|
schema: description$1
|
|
109528
109646
|
}, (_, value) => {
|
|
109529
109647
|
if (typeof value === "bigint") return value.toString();
|
|
@@ -109539,9 +109657,9 @@ const decode = (base64) => {
|
|
|
109539
109657
|
const description$1 = JSON.parse(json$1);
|
|
109540
109658
|
if (!isPlainObject(description$1) || !("version" in description$1) || !("schema" in description$1) || typeof description$1.version !== "string" || !isPlainObject(description$1.schema)) throw new TypeError("Not a valid encoded schema");
|
|
109541
109659
|
const { version: schemaVersion, schema } = description$1;
|
|
109542
|
-
if (import_semver.valid("0.1.0-master-
|
|
109660
|
+
if (import_semver.valid("0.1.0-master-effacff6")) {
|
|
109543
109661
|
if (!import_semver.valid(import_semver.coerce(schemaVersion))) throw new TypeError(`Invalid schema version: ${schemaVersion}`);
|
|
109544
|
-
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-
|
|
109662
|
+
if (import_semver.gt(import_semver.coerce(schemaVersion), "0.1.0-master-effacff6")) throw new TypeError(`Schema version ${schemaVersion} is not compatible with current version 0.1.0-master-effacff6`);
|
|
109545
109663
|
}
|
|
109546
109664
|
return validator.build(schema);
|
|
109547
109665
|
};
|
|
@@ -112807,7 +112925,7 @@ const tlds = new Set(TLDS.map((tld) => tld.toLowerCase()));
|
|
|
112807
112925
|
var import_lib = __toESM(require_lib$1());
|
|
112808
112926
|
var import_lib$1 = __toESM(require_lib());
|
|
112809
112927
|
var import_lib$2 = __toESM(require_lib$2());
|
|
112810
|
-
const version = "0.1.0-master-
|
|
112928
|
+
const version = "0.1.0-master-effacff6";
|
|
112811
112929
|
var ValidationError = import_lib$2.ValidationError;
|
|
112812
112930
|
var location = import_lib$1.location;
|
|
112813
112931
|
export { ValidationError, esm_exports as address, decode, encode, import_lib as formula, location, tlds, validator, version };
|