rjutils-collection
Advanced tools
Comparing version 1.7.0 to 1.7.1
{ | ||
"name": "rjutils-collection", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
@@ -41,13 +41,13 @@ "use strict"; | ||
} | ||
function zValidate() { | ||
function zValidate(validations = []) { | ||
return function(target, context) { | ||
const fn = arguments[2].value; | ||
(0, import__.as)(arguments[2]).value = function(...args) { | ||
var _a; | ||
var _a, _b, _c; | ||
const finalArgs = []; | ||
const zTypes = (0, import__.as)((_a = Object.getOwnPropertyDescriptor(target, zodValidateSymbol)) == null ? void 0 : _a.value).reverse(); | ||
const zTypes = (0, import__.as)((_c = (_b = (_a = Object.getOwnPropertyDescriptor(target, zodValidateSymbol)) == null ? void 0 : _a.value) == null ? void 0 : _b.reverse()) != null ? _c : validations.map((v, i) => ({ param: i, type: typeof v === "function" ? v(import_zod.z) : v }))); | ||
for (let i = 0; i < zTypes.length; i++) { | ||
const infos = zTypes[i].type.safeParse(args[zTypes[i].param]); | ||
if (!infos.success) | ||
throw new Error(`${context}(${"!, ".repeat(i)}X${", ?".repeat(zTypes.length - 1 - i)}) | ${infos.error.errors[0].message}`); | ||
throw new Error(`${context}(${"X, ".repeat(i)}!${", x".repeat(zTypes.length - 1 - i)}) | ${infos.error.errors[0].message}`); | ||
else | ||
@@ -54,0 +54,0 @@ finalArgs.push(infos.data); |
{ | ||
"name": "rjutils-collection", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
@@ -17,13 +17,13 @@ import { as } from ".."; | ||
} | ||
function zValidate() { | ||
function zValidate(validations = []) { | ||
return function(target, context) { | ||
const fn = arguments[2].value; | ||
as(arguments[2]).value = function(...args) { | ||
var _a; | ||
var _a, _b, _c; | ||
const finalArgs = []; | ||
const zTypes = as((_a = Object.getOwnPropertyDescriptor(target, zodValidateSymbol)) == null ? void 0 : _a.value).reverse(); | ||
const zTypes = as((_c = (_b = (_a = Object.getOwnPropertyDescriptor(target, zodValidateSymbol)) == null ? void 0 : _a.value) == null ? void 0 : _b.reverse()) != null ? _c : validations.map((v, i) => ({ param: i, type: typeof v === "function" ? v(z) : v }))); | ||
for (let i = 0; i < zTypes.length; i++) { | ||
const infos = zTypes[i].type.safeParse(args[zTypes[i].param]); | ||
if (!infos.success) | ||
throw new Error(`${context}(${"!, ".repeat(i)}X${", ?".repeat(zTypes.length - 1 - i)}) | ${infos.error.errors[0].message}`); | ||
throw new Error(`${context}(${"X, ".repeat(i)}!${", x".repeat(zTypes.length - 1 - i)}) | ${infos.error.errors[0].message}`); | ||
else | ||
@@ -30,0 +30,0 @@ finalArgs.push(infos.data); |
@@ -35,5 +35,14 @@ import { z } from "zod"; | ||
* } | ||
* | ||
* // or | ||
* | ||
* class MyClass { | ||
* @zValidate([ (z) => z.number() ]) | ||
* public getAsHex(num: number): string { | ||
* return num.toString(16) | ||
* } | ||
* } | ||
* ``` | ||
* @since 1.7.0 | ||
*/ export declare function zValidate(): <This, Args extends any[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => void; | ||
*/ export declare function zValidate(validations?: (z.ZodType | ((z: Zod['z']) => z.ZodType))[]): <This, Args extends any[], Return>(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => void; | ||
export {}; |
{ | ||
"name": "rjutils-collection", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Easy and Lightweight Utilities", | ||
@@ -5,0 +5,0 @@ "module": "lib/esm/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59120
1731