balda 0.0.45 → 0.0.46

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/lib/index.d.cts CHANGED
@@ -1,6 +1,4 @@
1
- import { TSchema, Static } from '@sinclair/typebox';
2
1
  import { JSONSchema as JSONSchema$1, FromSchema } from 'json-schema-to-ts';
3
- import { ZodType, z } from 'zod';
4
2
  import { Ajv } from 'ajv';
5
3
  import { IncomingMessage, ServerResponse, Server as Server$2 } from 'node:http';
6
4
  import { schedule, TaskContext } from 'node-cron';
@@ -25,11 +23,24 @@ type AjvInstance = InstanceType<typeof Ajv>;
25
23
  type AjvCompileParams = Parameters<AjvInstance["compile"]>;
26
24
 
27
25
  type IsAny<T> = 0 extends 1 & T ? true : false;
28
- type SafeTSchema = IsAny<TSchema> extends true ? never : TSchema;
26
+ type ZodSchemaLike = {
27
+ _zod: {
28
+ output: any;
29
+ };
30
+ };
31
+ type TypeBoxSchemaLike = {
32
+ static: any;
33
+ params: any;
34
+ };
29
35
  type SafeJSONSchema = IsAny<JSONSchema$1> extends true ? never : JSONSchema$1;
30
- type SafeZodType = IsAny<ZodType> extends true ? never : ZodType;
31
- type RequestSchema = SafeZodType | SafeTSchema | AjvCompileParams[0];
32
- type ValidatedData<T extends RequestSchema> = T extends SafeZodType ? z.infer<T> : T extends SafeTSchema ? Static<T> : T extends SafeJSONSchema ? SafeJSONSchema extends T ? Record<string, unknown> : FromSchema<T> : unknown;
36
+ type RequestSchema = ZodSchemaLike | TypeBoxSchemaLike | AjvCompileParams[0];
37
+ type ValidatedData<T extends RequestSchema> = T extends {
38
+ _zod: {
39
+ output: infer O;
40
+ };
41
+ } ? O : T extends {
42
+ static: infer O;
43
+ } ? O : T extends SafeJSONSchema ? SafeJSONSchema extends T ? Record<string, unknown> : FromSchema<T> : Record<string, unknown>;
33
44
  interface CustomValidationError {
34
45
  status?: number;
35
46
  message?: string;
@@ -66,7 +77,7 @@ type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}
66
77
  /**
67
78
  * Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
68
79
  */
69
- type InferSchemaType<T> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : T extends JSONSchema$1 ? JSONSchema$1 extends T ? Record<string, unknown> : FromSchema<T> : any;
80
+ type InferSchemaType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
70
81
  /**
71
82
  * Maps a responses object (e.g. { 200: ZodSchema, 404: TypeBoxSchema }) to
72
83
  * an inferred type map (e.g. { 200: InferredType200, 404: InferredType404 }).
package/lib/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { TSchema, Static } from '@sinclair/typebox';
2
1
  import { JSONSchema as JSONSchema$1, FromSchema } from 'json-schema-to-ts';
3
- import { ZodType, z } from 'zod';
4
2
  import { Ajv } from 'ajv';
5
3
  import { IncomingMessage, ServerResponse, Server as Server$2 } from 'node:http';
6
4
  import { schedule, TaskContext } from 'node-cron';
@@ -25,11 +23,24 @@ type AjvInstance = InstanceType<typeof Ajv>;
25
23
  type AjvCompileParams = Parameters<AjvInstance["compile"]>;
26
24
 
27
25
  type IsAny<T> = 0 extends 1 & T ? true : false;
28
- type SafeTSchema = IsAny<TSchema> extends true ? never : TSchema;
26
+ type ZodSchemaLike = {
27
+ _zod: {
28
+ output: any;
29
+ };
30
+ };
31
+ type TypeBoxSchemaLike = {
32
+ static: any;
33
+ params: any;
34
+ };
29
35
  type SafeJSONSchema = IsAny<JSONSchema$1> extends true ? never : JSONSchema$1;
30
- type SafeZodType = IsAny<ZodType> extends true ? never : ZodType;
31
- type RequestSchema = SafeZodType | SafeTSchema | AjvCompileParams[0];
32
- type ValidatedData<T extends RequestSchema> = T extends SafeZodType ? z.infer<T> : T extends SafeTSchema ? Static<T> : T extends SafeJSONSchema ? SafeJSONSchema extends T ? Record<string, unknown> : FromSchema<T> : unknown;
36
+ type RequestSchema = ZodSchemaLike | TypeBoxSchemaLike | AjvCompileParams[0];
37
+ type ValidatedData<T extends RequestSchema> = T extends {
38
+ _zod: {
39
+ output: infer O;
40
+ };
41
+ } ? O : T extends {
42
+ static: infer O;
43
+ } ? O : T extends SafeJSONSchema ? SafeJSONSchema extends T ? Record<string, unknown> : FromSchema<T> : Record<string, unknown>;
33
44
  interface CustomValidationError {
34
45
  status?: number;
35
46
  message?: string;
@@ -66,7 +77,7 @@ type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}
66
77
  /**
67
78
  * Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
68
79
  */
69
- type InferSchemaType<T> = T extends ZodType ? z.infer<T> : T extends TSchema ? Static<T> : T extends JSONSchema$1 ? JSONSchema$1 extends T ? Record<string, unknown> : FromSchema<T> : any;
80
+ type InferSchemaType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
70
81
  /**
71
82
  * Maps a responses object (e.g. { 200: ZodSchema, 404: TypeBoxSchema }) to
72
83
  * an inferred type map (e.g. { 200: InferredType200, 404: InferredType404 }).