@rexeus/typeweaver-core 0.1.0 → 0.1.2

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
@@ -6,7 +6,8 @@ type HttpBodySchema = ZodType;
6
6
 
7
7
  type IHttpHeader = Record<string, string | string[]> | undefined;
8
8
  type HttpHeaderValue = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
9
- type HttpHeaderSchema = ZodObject<Record<string, HttpHeaderValue | ZodOptional<HttpHeaderValue> | ZodArray<HttpHeaderValue> | ZodOptional<ZodArray<HttpHeaderValue>>>>;
9
+ type HttpHeaderObject = ZodObject<Record<string, HttpHeaderValue | ZodOptional<HttpHeaderValue> | ZodArray<HttpHeaderValue> | ZodOptional<ZodArray<HttpHeaderValue>>>>;
10
+ type HttpHeaderSchema = HttpHeaderObject | ZodOptional<HttpHeaderObject>;
10
11
 
11
12
  declare enum HttpMethod {
12
13
  GET = "GET",
@@ -24,7 +25,8 @@ type HttpParamSchema = ZodObject<Record<string, HttpParamValue>>;
24
25
 
25
26
  type IHttpQuery = Record<string, string | string[]> | undefined;
26
27
  type HttpQueryValue = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
27
- type HttpQuerySchema = ZodObject<Record<string, HttpQueryValue | ZodOptional<HttpQueryValue> | ZodArray<HttpQueryValue> | ZodOptional<ZodArray<HttpQueryValue>>>>;
28
+ type HttpQueryObject = ZodObject<Record<string, HttpQueryValue | ZodOptional<HttpQueryValue> | ZodArray<HttpQueryValue> | ZodOptional<ZodArray<HttpQueryValue>>>>;
29
+ type HttpQuerySchema = HttpQueryObject | ZodOptional<HttpQueryObject>;
28
30
 
29
31
  type IHttpRequest<Header extends IHttpHeader = IHttpHeader, Param extends IHttpParam = IHttpParam, Query extends IHttpQuery = IHttpQuery, Body extends IHttpBody = IHttpBody> = {
30
32
  body?: Body;
package/dist/index.js CHANGED
@@ -170,10 +170,16 @@ class HttpResponseDefinition {
170
170
  if (!this.header && !definition.header) return void 0;
171
171
  if (!this.header) return definition.header;
172
172
  if (!definition.header) return this.header;
173
- return z.object({
174
- ...this.header.shape,
175
- ...definition.header.shape
173
+ const mergedHeader2 = z.object({
174
+ ...this.header instanceof z.ZodObject ? this.header.shape : this.header.unwrap().shape,
175
+ ...definition.header instanceof z.ZodObject ? definition.header.shape : definition.header.unwrap().shape
176
176
  });
177
+ if (Object.values(mergedHeader2.shape).every(
178
+ (schema) => schema instanceof z.ZodOptional
179
+ )) {
180
+ return mergedHeader2.optional();
181
+ }
182
+ return mergedHeader2;
177
183
  })();
178
184
  const mergedBody = (() => {
179
185
  if (!this.body && !definition.body) return void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexeus/typeweaver-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Core TypeScript and Zod utilities for typeweaver API framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",