@cabloy/zod-query 1.0.14 → 1.0.16
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/query.d.ts +1 -0
- package/dist/lib/query.js +5 -0
- package/dist/lib/zodMetadata.d.ts +9 -0
- package/dist/lib/zodMetadata.js +50 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/lib/query.d.ts
CHANGED
package/dist/lib/query.js
CHANGED
|
@@ -185,6 +185,8 @@ export function coerceWithNil(data, fn) {
|
|
|
185
185
|
}
|
|
186
186
|
function _getInnerType(schema) {
|
|
187
187
|
let innerType = schema._def.innerType;
|
|
188
|
+
if (!innerType)
|
|
189
|
+
return schema;
|
|
188
190
|
while (innerType._def.innerType) {
|
|
189
191
|
innerType = innerType._def.innerType;
|
|
190
192
|
}
|
|
@@ -198,6 +200,9 @@ function _getTypeName(schema) {
|
|
|
198
200
|
}
|
|
199
201
|
return typeName;
|
|
200
202
|
}
|
|
203
|
+
export function getTypeName(schema) {
|
|
204
|
+
return _getTypeName(_getInnerType(schema));
|
|
205
|
+
}
|
|
201
206
|
// function _coerce(instance, input, fn) {
|
|
202
207
|
// if (instance._def.coerce !== false) {
|
|
203
208
|
// if (instance._def.coerce === true) instance._def.coerce = undefined as any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class ZodMetadata {
|
|
2
|
+
static unwrapUntil(schema: any, typeName?: any): any;
|
|
3
|
+
static unwrapChained(schema: any): any;
|
|
4
|
+
static getDefaultValue(zodSchema: any): any;
|
|
5
|
+
static getInternalMetadata(zodSchema: any): any;
|
|
6
|
+
static getLazySchema(zodSchema: any): any;
|
|
7
|
+
static getRefId(zodSchema: any): any;
|
|
8
|
+
}
|
|
9
|
+
export declare function isZodType(schema: any, typeName: any): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export class ZodMetadata {
|
|
2
|
+
static unwrapUntil(schema, typeName) {
|
|
3
|
+
if (typeName && isZodType(schema, typeName)) {
|
|
4
|
+
return schema;
|
|
5
|
+
}
|
|
6
|
+
if (isZodType(schema, 'ZodOptional') ||
|
|
7
|
+
isZodType(schema, 'ZodNullable') ||
|
|
8
|
+
isZodType(schema, 'ZodBranded')) {
|
|
9
|
+
return this.unwrapUntil(schema.unwrap(), typeName);
|
|
10
|
+
}
|
|
11
|
+
if (isZodType(schema, 'ZodDefault') || isZodType(schema, 'ZodReadonly')) {
|
|
12
|
+
return this.unwrapUntil(schema._def.innerType, typeName);
|
|
13
|
+
}
|
|
14
|
+
if (isZodType(schema, 'ZodEffects')) {
|
|
15
|
+
return this.unwrapUntil(schema._def.schema, typeName);
|
|
16
|
+
}
|
|
17
|
+
if (isZodType(schema, 'ZodPipeline')) {
|
|
18
|
+
return this.unwrapUntil(schema._def.in, typeName);
|
|
19
|
+
}
|
|
20
|
+
return typeName ? undefined : schema;
|
|
21
|
+
}
|
|
22
|
+
static unwrapChained(schema) {
|
|
23
|
+
return this.unwrapUntil(schema);
|
|
24
|
+
}
|
|
25
|
+
static getDefaultValue(zodSchema) {
|
|
26
|
+
const unwrapped = this.unwrapUntil(zodSchema, 'ZodDefault');
|
|
27
|
+
return unwrapped === null || unwrapped === void 0 ? void 0 : unwrapped._def.defaultValue();
|
|
28
|
+
}
|
|
29
|
+
static getInternalMetadata(zodSchema) {
|
|
30
|
+
const innerSchema = this.unwrapChained(zodSchema);
|
|
31
|
+
const openapi = zodSchema._def.openapi
|
|
32
|
+
? zodSchema._def.openapi
|
|
33
|
+
: innerSchema._def.openapi;
|
|
34
|
+
return openapi === null || openapi === void 0 ? void 0 : openapi._internal;
|
|
35
|
+
}
|
|
36
|
+
static getLazySchema(zodSchema) {
|
|
37
|
+
const innerSchema = this.unwrapChained(zodSchema);
|
|
38
|
+
return zodSchema._def?.getter ?? innerSchema._def?.getter;
|
|
39
|
+
}
|
|
40
|
+
static getRefId(zodSchema) {
|
|
41
|
+
let _a;
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
return (_a = this.getInternalMetadata(zodSchema)) === null || _a === void 0 ? void 0 : _a.refId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function isZodType(schema, typeName) {
|
|
47
|
+
let _a;
|
|
48
|
+
// eslint-disable-next-line
|
|
49
|
+
return ((_a = schema === null || schema === void 0 ? void 0 : schema._def) === null || _a === void 0 ? void 0 : _a.typeName) === typeName;
|
|
50
|
+
}
|