balda 0.0.44 → 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.cjs.map +1 -1
- package/lib/index.d.cts +20 -5
- package/lib/index.d.ts +20 -5
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
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';
|
|
@@ -24,8 +22,25 @@ import { Transporter } from 'nodemailer';
|
|
|
24
22
|
type AjvInstance = InstanceType<typeof Ajv>;
|
|
25
23
|
type AjvCompileParams = Parameters<AjvInstance["compile"]>;
|
|
26
24
|
|
|
27
|
-
type
|
|
28
|
-
type
|
|
25
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
26
|
+
type ZodSchemaLike = {
|
|
27
|
+
_zod: {
|
|
28
|
+
output: any;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type TypeBoxSchemaLike = {
|
|
32
|
+
static: any;
|
|
33
|
+
params: any;
|
|
34
|
+
};
|
|
35
|
+
type SafeJSONSchema = IsAny<JSONSchema$1> extends true ? never : JSONSchema$1;
|
|
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>;
|
|
29
44
|
interface CustomValidationError {
|
|
30
45
|
status?: number;
|
|
31
46
|
message?: string;
|
|
@@ -62,7 +77,7 @@ type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}
|
|
|
62
77
|
/**
|
|
63
78
|
* Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
|
|
64
79
|
*/
|
|
65
|
-
type InferSchemaType<T> = T extends
|
|
80
|
+
type InferSchemaType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
|
|
66
81
|
/**
|
|
67
82
|
* Maps a responses object (e.g. { 200: ZodSchema, 404: TypeBoxSchema }) to
|
|
68
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';
|
|
@@ -24,8 +22,25 @@ import { Transporter } from 'nodemailer';
|
|
|
24
22
|
type AjvInstance = InstanceType<typeof Ajv>;
|
|
25
23
|
type AjvCompileParams = Parameters<AjvInstance["compile"]>;
|
|
26
24
|
|
|
27
|
-
type
|
|
28
|
-
type
|
|
25
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
26
|
+
type ZodSchemaLike = {
|
|
27
|
+
_zod: {
|
|
28
|
+
output: any;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type TypeBoxSchemaLike = {
|
|
32
|
+
static: any;
|
|
33
|
+
params: any;
|
|
34
|
+
};
|
|
35
|
+
type SafeJSONSchema = IsAny<JSONSchema$1> extends true ? never : JSONSchema$1;
|
|
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>;
|
|
29
44
|
interface CustomValidationError {
|
|
30
45
|
status?: number;
|
|
31
46
|
message?: string;
|
|
@@ -62,7 +77,7 @@ type ExtractParams<T extends string> = T extends `${infer _Start}:${infer Param}
|
|
|
62
77
|
/**
|
|
63
78
|
* Helper type to infer the output type from a Zod schema, TypeBox schema, or any schema with _output
|
|
64
79
|
*/
|
|
65
|
-
type InferSchemaType<T> = T extends
|
|
80
|
+
type InferSchemaType<T> = T extends RequestSchema ? ValidatedData<T> : unknown;
|
|
66
81
|
/**
|
|
67
82
|
* Maps a responses object (e.g. { 200: ZodSchema, 404: TypeBoxSchema }) to
|
|
68
83
|
* an inferred type map (e.g. { 200: InferredType200, 404: InferredType404 }).
|