@cabloy/zod-query 1.0.2 → 1.0.4

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,2 +1 @@
1
- export * from './lib/query.js';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './lib/query.ts';
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- export * from './lib/query.js';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./lib/query.js";
@@ -1,2 +1 @@
1
1
  export declare function coerceWithNil(data: any, fn?: Function): any;
2
- //# sourceMappingURL=query.d.ts.map
package/dist/lib/query.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { z } from 'zod';
2
- import { isNil } from './utils.js';
2
+ import { isNil } from "./utils.js";
3
3
  /////////////////////////////////////////
4
4
  /////////////////////////////////////////
5
- ////////// //////////
6
- ////////// ZodString //////////
7
- ////////// //////////
5
+ /// /////// /////////
6
+ /// /////// ZodString /////////
7
+ /// /////// /////////
8
8
  /////////////////////////////////////////
9
9
  /////////////////////////////////////////
10
10
  const _parseString = z.ZodString.prototype._parse;
11
11
  z.ZodString.prototype._parse = function (input) {
12
+ if (this._def?.openapi?.metadata?.format === 'binary' && !isNil(input.data)) {
13
+ // ignore upload file
14
+ return { status: 'valid', value: input.data };
15
+ }
12
16
  _coerce(input, () => {
13
17
  input.data = String(input.data);
14
18
  });
@@ -16,9 +20,9 @@ z.ZodString.prototype._parse = function (input) {
16
20
  };
17
21
  /////////////////////////////////////////
18
22
  /////////////////////////////////////////
19
- ////////// //////////
20
- ////////// ZodNumber //////////
21
- ////////// //////////
23
+ /// /////// /////////
24
+ /// /////// ZodNumber /////////
25
+ /// /////// /////////
22
26
  /////////////////////////////////////////
23
27
  /////////////////////////////////////////
24
28
  const _parseNumber = z.ZodNumber.prototype._parse;
@@ -30,9 +34,9 @@ z.ZodNumber.prototype._parse = function (input) {
30
34
  };
31
35
  /////////////////////////////////////////
32
36
  /////////////////////////////////////////
33
- ////////// //////////
34
- ////////// ZodBigInt //////////
35
- ////////// //////////
37
+ /// /////// /////////
38
+ /// /////// ZodBigInt /////////
39
+ /// /////// /////////
36
40
  /////////////////////////////////////////
37
41
  /////////////////////////////////////////
38
42
  const _parseBigInt = z.ZodBigInt.prototype._parse;
@@ -44,9 +48,9 @@ z.ZodBigInt.prototype._parse = function (input) {
44
48
  };
45
49
  //////////////////////////////////////////
46
50
  //////////////////////////////////////////
47
- ////////// ///////////
48
- ////////// ZodBoolean //////////
49
- ////////// ///////////
51
+ /// /////// //////////
52
+ /// /////// ZodBoolean /////////
53
+ /// /////// //////////
50
54
  //////////////////////////////////////////
51
55
  //////////////////////////////////////////
52
56
  const _parseBoolean = z.ZodBoolean.prototype._parse;
@@ -63,9 +67,9 @@ z.ZodBoolean.prototype._parse = function (input) {
63
67
  };
64
68
  ///////////////////////////////////////
65
69
  ///////////////////////////////////////
66
- ////////// ////////
67
- ////////// ZodDate ////////
68
- ////////// ////////
70
+ /// /////// ///////
71
+ /// /////// ZodDate ///////
72
+ /// /////// ///////
69
73
  ///////////////////////////////////////
70
74
  ///////////////////////////////////////
71
75
  const _parseDate = z.ZodDate.prototype._parse;
@@ -77,9 +81,9 @@ z.ZodDate.prototype._parse = function (input) {
77
81
  };
78
82
  /////////////////////////////////////////
79
83
  /////////////////////////////////////////
80
- ////////// //////////
81
- ////////// ZodObject //////////
82
- ////////// //////////
84
+ /// /////// /////////
85
+ /// /////// ZodObject /////////
86
+ /// /////// /////////
83
87
  /////////////////////////////////////////
84
88
  /////////////////////////////////////////
85
89
  const _parseObject = z.ZodObject.prototype._parse;
@@ -93,9 +97,9 @@ z.ZodObject.prototype._parse = function (input) {
93
97
  };
94
98
  ////////////////////////////////////////
95
99
  ////////////////////////////////////////
96
- ////////// //////////
97
- ////////// ZodArray //////////
98
- ////////// //////////
100
+ /// /////// /////////
101
+ /// /////// ZodArray /////////
102
+ /// /////// /////////
99
103
  ////////////////////////////////////////
100
104
  ////////////////////////////////////////
101
105
  const _parseArray = z.ZodArray.prototype._parse;
@@ -114,31 +118,34 @@ z.ZodArray.prototype._parse = function (input) {
114
118
  };
115
119
  ///////////////////////////////////////////
116
120
  ///////////////////////////////////////////
117
- ////////// //////////
118
- ////////// ZodOptional //////////
119
- ////////// //////////
121
+ /// /////// /////////
122
+ /// /////// ZodOptional /////////
123
+ /// /////// /////////
120
124
  ///////////////////////////////////////////
121
125
  ///////////////////////////////////////////
122
126
  const _parseOptional = z.ZodOptional.prototype._parse;
123
127
  z.ZodOptional.prototype._parse = function (input) {
124
- if (_getInnerType(this).typeName === 'ZodString') {
128
+ if (_getTypeName(_getInnerType(this)) === 'ZodString') {
125
129
  _coerce(input);
126
130
  }
127
131
  else {
128
132
  _coerceWithNil(input);
129
133
  }
134
+ if (input.data === null) {
135
+ input.data = undefined;
136
+ }
130
137
  return _parseOptional.call(this, input);
131
138
  };
132
139
  ////////////////////////////////////////////
133
140
  ////////////////////////////////////////////
134
- ////////// //////////
135
- ////////// ZodDefault //////////
136
- ////////// //////////
141
+ /// /////// /////////
142
+ /// /////// ZodDefault /////////
143
+ /// /////// /////////
137
144
  ////////////////////////////////////////////
138
145
  ////////////////////////////////////////////
139
146
  const _parseDefault = z.ZodDefault.prototype._parse;
140
147
  z.ZodDefault.prototype._parse = function (input) {
141
- if (_getInnerType(this).typeName === 'ZodString') {
148
+ if (_getTypeName(_getInnerType(this)) === 'ZodString') {
142
149
  _coerce(input);
143
150
  }
144
151
  else {
@@ -148,9 +155,9 @@ z.ZodDefault.prototype._parse = function (input) {
148
155
  };
149
156
  ///////////////////////////////////////
150
157
  ///////////////////////////////////////
151
- ////////// ////////
152
- ////////// coerce ////////
153
- ////////// ////////
158
+ /// /////// ///////
159
+ /// /////// coerce ///////
160
+ /// /////// ///////
154
161
  ///////////////////////////////////////
155
162
  ///////////////////////////////////////
156
163
  function _coerce(input, fn) {
@@ -183,6 +190,14 @@ function _getInnerType(schema) {
183
190
  }
184
191
  return innerType;
185
192
  }
193
+ function _getTypeName(schema) {
194
+ let typeName = schema.typeName;
195
+ while (!typeName) {
196
+ schema = schema._def;
197
+ typeName = schema.typeName;
198
+ }
199
+ return typeName;
200
+ }
186
201
  // function _coerce(instance, input, fn) {
187
202
  // if (instance._def.coerce !== false) {
188
203
  // if (instance._def.coerce === true) instance._def.coerce = undefined as any;
@@ -191,4 +206,3 @@ function _getInnerType(schema) {
191
206
  // }
192
207
  // }
193
208
  // }
194
- //# sourceMappingURL=query.js.map
@@ -1,3 +1,2 @@
1
1
  export declare const isUndefined: (obj: any) => obj is undefined;
2
2
  export declare const isNil: (val: any) => val is null | undefined;
3
- //# sourceMappingURL=utils.d.ts.map
package/dist/lib/utils.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export const isUndefined = (obj) => typeof obj === 'undefined';
2
2
  export const isNil = (val) => isUndefined(val) || val === null;
3
- //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,45 +1,37 @@
1
1
  {
2
2
  "name": "@cabloy/zod-query",
3
- "version": "1.0.2",
3
+ "type": "module",
4
+ "version": "1.0.4",
4
5
  "description": "zod-query",
5
6
  "publishConfig": {
6
7
  "access": "public"
7
8
  },
8
- "type": "module",
9
+ "author": "zhennann",
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/cabloy/zova#readme",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/cabloy/zova.git"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/cabloy/zova/issues"
18
+ },
19
+ "keywords": [
20
+ "vue3",
21
+ "ioc",
22
+ "zova"
23
+ ],
9
24
  "exports": {
10
25
  ".": {
11
26
  "types": [
12
27
  "./src/index.ts",
13
28
  "./dist/index.d.ts"
14
29
  ],
15
- "development": "./src/index.ts",
16
- "import": "./dist/index.js",
17
- "default": "./src/index.ts"
30
+ "default": "./dist/index.js"
18
31
  },
19
32
  "./package.json": "./package.json"
20
33
  },
21
34
  "files": [
22
- "dist",
23
- "src"
24
- ],
25
- "author": "zhennann",
26
- "license": "MIT",
27
- "keywords": [
28
- "vue3",
29
- "ioc",
30
- "zova"
31
- ],
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/cabloy/zova.git"
35
- },
36
- "homepage": "https://github.com/cabloy/zova#readme",
37
- "bugs": {
38
- "url": "https://github.com/cabloy/zova/issues"
39
- },
40
- "scripts": {
41
- "lint": "eslint .",
42
- "clean": "tsc -b --clean",
43
- "tsc:publish": "npm run clean && tsc -b"
44
- }
35
+ "dist"
36
+ ]
45
37
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/lib/query.ts"],"names":[],"mappings":"AA6LA,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,QAAQ,OAIrD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/lib/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AACzC,yCAAyC;AAEzC,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC;AAClD,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,UAA6B,KAAK;IAC/D,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE;QAClB,KAAK,CAAC,IAAI,GA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AK,CAAC,IAAI,KAAK,EAAE,EAAE,CAAC;YACpD,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC;QACzB,CAAC;aAAM,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACjC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,EAAE,EAAE,EAAE,CAAC;QACT,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAS,EAAE,EAAa;IACpD,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC;IACvB,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,IAAI,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;IACtC,OAAO,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,0CAA0C;AAC1C,0CAA0C;AAC1C,kFAAkF;AAClF,gCAAgC;AAChC,cAAc;AACd,QAAQ;AACR,MAAM;AACN,IAAI"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAS,GAAG,KAAG,GAAG,IAAI,SAAuC,CAAC;AACtF,eAAO,MAAM,KAAK,QAAS,GAAG,KAAG,GAAG,IAAI,IAAI,GAAG,SAA6C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAoB,EAAE,CAAC,OAAO,GAAG,KAAK,WAAW,CAAC;AACtF,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAQ,EAA2B,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,IAAI,CAAC"}
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './lib/query.js';
package/src/lib/query.ts DELETED
@@ -1,211 +0,0 @@
1
- import { z } from 'zod';
2
- import { isNil } from './utils.js';
3
-
4
- /////////////////////////////////////////
5
- /////////////////////////////////////////
6
- ////////// //////////
7
- ////////// ZodString //////////
8
- ////////// //////////
9
- /////////////////////////////////////////
10
- /////////////////////////////////////////
11
-
12
- const _parseString = z.ZodString.prototype._parse;
13
- z.ZodString.prototype._parse = function (this: z.ZodString, input) {
14
- _coerce(input, () => {
15
- input.data = String(input.data);
16
- });
17
- return _parseString.call(this, input);
18
- };
19
-
20
- /////////////////////////////////////////
21
- /////////////////////////////////////////
22
- ////////// //////////
23
- ////////// ZodNumber //////////
24
- ////////// //////////
25
- /////////////////////////////////////////
26
- /////////////////////////////////////////
27
-
28
- const _parseNumber = z.ZodNumber.prototype._parse;
29
- z.ZodNumber.prototype._parse = function (this: z.ZodNumber, input) {
30
- _coerceWithNil(input, () => {
31
- input.data = Number(input.data);
32
- });
33
- return _parseNumber.call(this, input);
34
- };
35
-
36
- /////////////////////////////////////////
37
- /////////////////////////////////////////
38
- ////////// //////////
39
- ////////// ZodBigInt //////////
40
- ////////// //////////
41
- /////////////////////////////////////////
42
- /////////////////////////////////////////
43
-
44
- const _parseBigInt = z.ZodBigInt.prototype._parse;
45
- z.ZodBigInt.prototype._parse = function (this: z.ZodBigInt, input) {
46
- _coerceWithNil(input, () => {
47
- input.data = BigInt(input.data);
48
- });
49
- return _parseBigInt.call(this, input);
50
- };
51
-
52
- //////////////////////////////////////////
53
- //////////////////////////////////////////
54
- ////////// ///////////
55
- ////////// ZodBoolean //////////
56
- ////////// ///////////
57
- //////////////////////////////////////////
58
- //////////////////////////////////////////
59
-
60
- const _parseBoolean = z.ZodBoolean.prototype._parse;
61
- z.ZodBoolean.prototype._parse = function (this: z.ZodBoolean, input) {
62
- _coerceWithNil(input, () => {
63
- if (input.data === 'false' || input.data === '0') {
64
- input.data = false;
65
- } else {
66
- input.data = Boolean(input.data);
67
- }
68
- });
69
- return _parseBoolean.call(this, input);
70
- };
71
-
72
- ///////////////////////////////////////
73
- ///////////////////////////////////////
74
- ////////// ////////
75
- ////////// ZodDate ////////
76
- ////////// ////////
77
- ///////////////////////////////////////
78
- ///////////////////////////////////////
79
-
80
- const _parseDate = z.ZodDate.prototype._parse;
81
- z.ZodDate.prototype._parse = function (this: z.ZodDate, input) {
82
- _coerceWithNil(input, () => {
83
- input.data = new Date(input.data);
84
- });
85
- return _parseDate.call(this, input);
86
- };
87
-
88
- /////////////////////////////////////////
89
- /////////////////////////////////////////
90
- ////////// //////////
91
- ////////// ZodObject //////////
92
- ////////// //////////
93
- /////////////////////////////////////////
94
- /////////////////////////////////////////
95
-
96
- const _parseObject = z.ZodObject.prototype._parse;
97
- z.ZodObject.prototype._parse = function (input) {
98
- _coerceWithNil(input, () => {
99
- if (typeof input.data === 'string') {
100
- input.data = JSON.parse(input.data);
101
- }
102
- });
103
- return _parseObject.call(this, input);
104
- };
105
-
106
- ////////////////////////////////////////
107
- ////////////////////////////////////////
108
- ////////// //////////
109
- ////////// ZodArray //////////
110
- ////////// //////////
111
- ////////////////////////////////////////
112
- ////////////////////////////////////////
113
-
114
- const _parseArray = z.ZodArray.prototype._parse;
115
- z.ZodArray.prototype._parse = function (input) {
116
- _coerceWithNil(input, () => {
117
- if (typeof input.data === 'string') {
118
- if (input.data[0] === '[') {
119
- input.data = JSON.parse(input.data);
120
- } else {
121
- input.data = input.data.split(',');
122
- }
123
- }
124
- });
125
- return _parseArray.call(this, input);
126
- };
127
-
128
- ///////////////////////////////////////////
129
- ///////////////////////////////////////////
130
- ////////// //////////
131
- ////////// ZodOptional //////////
132
- ////////// //////////
133
- ///////////////////////////////////////////
134
- ///////////////////////////////////////////
135
-
136
- const _parseOptional = z.ZodOptional.prototype._parse;
137
- z.ZodOptional.prototype._parse = function (this: z.ZodOptional<any>, input) {
138
- if (_getInnerType(this).typeName === 'ZodString') {
139
- _coerce(input);
140
- } else {
141
- _coerceWithNil(input);
142
- }
143
- return _parseOptional.call(this, input);
144
- };
145
-
146
- ////////////////////////////////////////////
147
- ////////////////////////////////////////////
148
- ////////// //////////
149
- ////////// ZodDefault //////////
150
- ////////// //////////
151
- ////////////////////////////////////////////
152
- ////////////////////////////////////////////
153
-
154
- const _parseDefault = z.ZodDefault.prototype._parse;
155
- z.ZodDefault.prototype._parse = function (this: z.ZodDefault<any>, input) {
156
- if (_getInnerType(this).typeName === 'ZodString') {
157
- _coerce(input);
158
- } else {
159
- _coerceWithNil(input);
160
- }
161
- return _parseDefault.call(this, input);
162
- };
163
-
164
- ///////////////////////////////////////
165
- ///////////////////////////////////////
166
- ////////// ////////
167
- ////////// coerce ////////
168
- ////////// ////////
169
- ///////////////////////////////////////
170
- ///////////////////////////////////////
171
-
172
- function _coerce(input, fn?: Function) {
173
- if (!isNil(input.data)) {
174
- fn?.();
175
- }
176
- }
177
-
178
- function _coerceWithNil(input, fn?: Function) {
179
- if (!isNil(input.data)) {
180
- if (input.data === 'undefined' || input.data === '') {
181
- input.data = undefined;
182
- } else if (input.data === 'null') {
183
- input.data = null;
184
- } else {
185
- fn?.();
186
- }
187
- }
188
- }
189
-
190
- export function coerceWithNil(data: any, fn?: Function) {
191
- const input = { data };
192
- _coerceWithNil(input, fn);
193
- return data;
194
- }
195
-
196
- function _getInnerType(schema: any) {
197
- let innerType = schema._def.innerType;
198
- while (innerType._def.innerType) {
199
- innerType = innerType._def.innerType;
200
- }
201
- return innerType;
202
- }
203
-
204
- // function _coerce(instance, input, fn) {
205
- // if (instance._def.coerce !== false) {
206
- // if (instance._def.coerce === true) instance._def.coerce = undefined as any;
207
- // if (!isNil(input.data)) {
208
- // fn();
209
- // }
210
- // }
211
- // }
package/src/lib/utils.ts DELETED
@@ -1,2 +0,0 @@
1
- export const isUndefined = (obj: any): obj is undefined => typeof obj === 'undefined';
2
- export const isNil = (val: any): val is null | undefined => isUndefined(val) || val === null;