@cabloy/zod-query 1.0.15 → 1.0.17

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 CHANGED
@@ -1 +1,2 @@
1
1
  export * from './lib/query.ts';
2
+ export * from './lib/zodMetadata.ts';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./lib/query.js";
2
+ export * from "./lib/zodMetadata.js";
package/dist/lib/query.js CHANGED
@@ -106,7 +106,7 @@ const _parseArray = z.ZodArray.prototype._parse;
106
106
  z.ZodArray.prototype._parse = function (input) {
107
107
  _coerceWithNil(input, () => {
108
108
  if (typeof input.data === 'string') {
109
- if (input.data[0] === '[') {
109
+ if (input.data.startsWith('[') && input.data.endsWith(']')) {
110
110
  input.data = JSON.parse(input.data);
111
111
  }
112
112
  else {
@@ -0,0 +1,12 @@
1
+ import type z from 'zod';
2
+ export declare class ZodMetadata {
3
+ static unwrapUntil(schema: any, typeName?: any): any;
4
+ static unwrapChained(schema: any): any;
5
+ static getDefaultValue(zodSchema: any): any;
6
+ static getInternalMetadata(zodSchema: any): any;
7
+ static getLazySchema(zodSchema: any): any;
8
+ static getRefId(zodSchema: any): any;
9
+ static getFieldSchema(schema: any, key: string): z.ZodSchema;
10
+ static getOpenapiMetadata(schema: any): any;
11
+ }
12
+ export declare function isZodType(schema: any, typeName: any): boolean;
@@ -0,0 +1,56 @@
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
+ static getFieldSchema(schema, key) {
46
+ return schema.shape[key];
47
+ }
48
+ static getOpenapiMetadata(schema) {
49
+ return schema._def.openapi?.metadata;
50
+ }
51
+ }
52
+ export function isZodType(schema, typeName) {
53
+ let _a;
54
+ // eslint-disable-next-line
55
+ return ((_a = schema === null || schema === void 0 ? void 0 : schema._def) === null || _a === void 0 ? void 0 : _a.typeName) === typeName;
56
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/zod-query",
3
3
  "type": "module",
4
- "version": "1.0.15",
4
+ "version": "1.0.17",
5
5
  "description": "zod-query",
6
6
  "publishConfig": {
7
7
  "access": "public"