erpnext-queue-client 2.5.4 → 2.5.5
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/dist/utils/zodUtils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { z, ZodObject, ZodRawShape } from "zod";
|
|
2
2
|
export declare function validateData<T extends z.ZodTypeAny>(data: unknown, ValidationModel: T, isDebug?: boolean): z.infer<T>;
|
|
3
3
|
export declare function pickFromSchema<T extends ZodRawShape, K extends keyof T>(schema: ZodObject<T>, keys: readonly K[]): ZodObject<Pick<T, K>>;
|
|
4
|
-
export type KeysOf<T> = T extends ZodObject<any> ? keyof z.infer<T> : string;
|
|
4
|
+
export type KeysOf<T extends z.ZodTypeAny> = T extends z.ZodObject<any> ? keyof z.infer<T> : string;
|
package/dist/utils/zodUtils.js
CHANGED
|
@@ -4,12 +4,16 @@ exports.validateData = validateData;
|
|
|
4
4
|
exports.pickFromSchema = pickFromSchema;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const constants_1 = require("../constants");
|
|
7
|
+
const logger_1 = require("./logger");
|
|
7
8
|
function validateData(data, ValidationModel, isDebug) {
|
|
8
9
|
if (!ValidationModel.description)
|
|
9
10
|
throw new Error("ValidationModel.description is required");
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Avoid `instanceof` checks: they can fail when schemas come from a different
|
|
12
|
+
// zod package instance (e.g. host app vs this package dependency).
|
|
13
|
+
if (!ValidationModel ||
|
|
14
|
+
typeof ValidationModel !== "object" ||
|
|
15
|
+
typeof ValidationModel.safeParse !== "function") {
|
|
16
|
+
logger_1.lg.error("Invalid Zod Model", ValidationModel);
|
|
13
17
|
throw new Error("Invalid Zod Model");
|
|
14
18
|
}
|
|
15
19
|
const validationResult = ValidationModel.safeParse(data);
|