spiceflow 1.0.1 → 1.0.3

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.
Files changed (42) hide show
  1. package/README.md +148 -1
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/types.d.ts +2 -6
  4. package/dist/client/types.d.ts.map +1 -1
  5. package/dist/client.test.js +26 -22
  6. package/dist/client.test.js.map +1 -1
  7. package/dist/elysia-fork/context.d.ts +6 -22
  8. package/dist/elysia-fork/context.d.ts.map +1 -1
  9. package/dist/elysia-fork/error.d.ts +2 -226
  10. package/dist/elysia-fork/error.d.ts.map +1 -1
  11. package/dist/elysia-fork/error.js +13 -166
  12. package/dist/elysia-fork/error.js.map +1 -1
  13. package/dist/elysia-fork/types.d.ts +20 -30
  14. package/dist/elysia-fork/types.d.ts.map +1 -1
  15. package/dist/elysia-fork/types.js +1 -2
  16. package/dist/elysia-fork/types.js.map +1 -1
  17. package/dist/elysia-fork/utils.d.ts +1 -62
  18. package/dist/elysia-fork/utils.d.ts.map +1 -1
  19. package/dist/openapi.d.ts +67 -0
  20. package/dist/openapi.d.ts.map +1 -0
  21. package/dist/openapi.js +250 -0
  22. package/dist/openapi.js.map +1 -0
  23. package/dist/spiceflow.d.ts +35 -23
  24. package/dist/spiceflow.d.ts.map +1 -1
  25. package/dist/spiceflow.js +214 -111
  26. package/dist/spiceflow.js.map +1 -1
  27. package/dist/spiceflow.test.js +135 -31
  28. package/dist/spiceflow.test.js.map +1 -1
  29. package/dist/zod.test.d.ts +2 -0
  30. package/dist/zod.test.d.ts.map +1 -0
  31. package/dist/zod.test.js +61 -0
  32. package/dist/zod.test.js.map +1 -0
  33. package/package.json +7 -3
  34. package/src/client/types.ts +14 -19
  35. package/src/client.test.ts +34 -25
  36. package/src/elysia-fork/context.ts +19 -49
  37. package/src/elysia-fork/error.ts +6 -259
  38. package/src/elysia-fork/types.ts +115 -188
  39. package/src/openapi.ts +426 -0
  40. package/src/spiceflow.test.ts +188 -51
  41. package/src/spiceflow.ts +312 -183
  42. package/src/zod.test.ts +73 -0
@@ -1,246 +1,22 @@
1
- import type { TSchema } from '@sinclair/typebox';
2
- import type { TypeCheck, ValueError } from '@sinclair/typebox/compiler';
3
1
  export declare const ERROR_CODE: unique symbol;
4
2
  export type ERROR_CODE = typeof ERROR_CODE;
5
3
  export declare const ELYSIA_RESPONSE: unique symbol;
6
4
  export type ELYSIA_RESPONSE = typeof ELYSIA_RESPONSE;
7
5
  export declare const isProduction: boolean;
8
- export type SpiceflowErrors = InternalServerError | NotFoundError | ParseError | ValidationError | InvalidCookieSignature;
9
- export declare const error: <const Code extends number | "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required", const T = Code extends 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 304 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
10
- readonly 100: "Continue";
11
- readonly 101: "Switching Protocols";
12
- readonly 102: "Processing";
13
- readonly 103: "Early Hints";
14
- readonly 200: "OK";
15
- readonly 201: "Created";
16
- readonly 202: "Accepted";
17
- readonly 203: "Non-Authoritative Information";
18
- readonly 204: "No Content";
19
- readonly 205: "Reset Content";
20
- readonly 206: "Partial Content";
21
- readonly 207: "Multi-Status";
22
- readonly 208: "Already Reported";
23
- readonly 300: "Multiple Choices";
24
- readonly 301: "Moved Permanently";
25
- readonly 302: "Found";
26
- readonly 303: "See Other";
27
- readonly 304: "Not Modified";
28
- readonly 307: "Temporary Redirect";
29
- readonly 308: "Permanent Redirect";
30
- readonly 400: "Bad Request";
31
- readonly 401: "Unauthorized";
32
- readonly 402: "Payment Required";
33
- readonly 403: "Forbidden";
34
- readonly 404: "Not Found";
35
- readonly 405: "Method Not Allowed";
36
- readonly 406: "Not Acceptable";
37
- readonly 407: "Proxy Authentication Required";
38
- readonly 408: "Request Timeout";
39
- readonly 409: "Conflict";
40
- readonly 410: "Gone";
41
- readonly 411: "Length Required";
42
- readonly 412: "Precondition Failed";
43
- readonly 413: "Payload Too Large";
44
- readonly 414: "URI Too Long";
45
- readonly 415: "Unsupported Media Type";
46
- readonly 416: "Range Not Satisfiable";
47
- readonly 417: "Expectation Failed";
48
- readonly 418: "I'm a teapot";
49
- readonly 421: "Misdirected Request";
50
- readonly 422: "Unprocessable Content";
51
- readonly 423: "Locked";
52
- readonly 424: "Failed Dependency";
53
- readonly 425: "Too Early";
54
- readonly 426: "Upgrade Required";
55
- readonly 428: "Precondition Required";
56
- readonly 429: "Too Many Requests";
57
- readonly 431: "Request Header Fields Too Large";
58
- readonly 451: "Unavailable For Legal Reasons";
59
- readonly 500: "Internal Server Error";
60
- readonly 501: "Not Implemented";
61
- readonly 502: "Bad Gateway";
62
- readonly 503: "Service Unavailable";
63
- readonly 504: "Gateway Timeout";
64
- readonly 505: "HTTP Version Not Supported";
65
- readonly 506: "Variant Also Negotiates";
66
- readonly 507: "Insufficient Storage";
67
- readonly 508: "Loop Detected";
68
- readonly 510: "Not Extended";
69
- readonly 511: "Network Authentication Required";
70
- }[Code] : Code, const Status extends Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
71
- readonly Continue: 100;
72
- readonly 'Switching Protocols': 101;
73
- readonly Processing: 102;
74
- readonly 'Early Hints': 103;
75
- readonly OK: 200;
76
- readonly Created: 201;
77
- readonly Accepted: 202;
78
- readonly 'Non-Authoritative Information': 203;
79
- readonly 'No Content': 204;
80
- readonly 'Reset Content': 205;
81
- readonly 'Partial Content': 206;
82
- readonly 'Multi-Status': 207;
83
- readonly 'Already Reported': 208;
84
- readonly 'Multiple Choices': 300;
85
- readonly 'Moved Permanently': 301;
86
- readonly Found: 302;
87
- readonly 'See Other': 303;
88
- readonly 'Not Modified': 304;
89
- readonly 'Temporary Redirect': 307;
90
- readonly 'Permanent Redirect': 308;
91
- readonly 'Bad Request': 400;
92
- readonly Unauthorized: 401;
93
- readonly 'Payment Required': 402;
94
- readonly Forbidden: 403;
95
- readonly 'Not Found': 404;
96
- readonly 'Method Not Allowed': 405;
97
- readonly 'Not Acceptable': 406;
98
- readonly 'Proxy Authentication Required': 407;
99
- readonly 'Request Timeout': 408;
100
- readonly Conflict: 409;
101
- readonly Gone: 410;
102
- readonly 'Length Required': 411;
103
- readonly 'Precondition Failed': 412;
104
- readonly 'Payload Too Large': 413;
105
- readonly 'URI Too Long': 414;
106
- readonly 'Unsupported Media Type': 415;
107
- readonly 'Range Not Satisfiable': 416;
108
- readonly 'Expectation Failed': 417;
109
- readonly "I'm a teapot": 418;
110
- readonly 'Misdirected Request': 421;
111
- readonly 'Unprocessable Content': 422;
112
- readonly Locked: 423;
113
- readonly 'Failed Dependency': 424;
114
- readonly 'Too Early': 425;
115
- readonly 'Upgrade Required': 426;
116
- readonly 'Precondition Required': 428;
117
- readonly 'Too Many Requests': 429;
118
- readonly 'Request Header Fields Too Large': 431;
119
- readonly 'Unavailable For Legal Reasons': 451;
120
- readonly 'Internal Server Error': 500;
121
- readonly 'Not Implemented': 501;
122
- readonly 'Bad Gateway': 502;
123
- readonly 'Service Unavailable': 503;
124
- readonly 'Gateway Timeout': 504;
125
- readonly 'HTTP Version Not Supported': 505;
126
- readonly 'Variant Also Negotiates': 506;
127
- readonly 'Insufficient Storage': 507;
128
- readonly 'Loop Detected': 508;
129
- readonly 'Not Extended': 510;
130
- readonly 'Network Authentication Required': 511;
131
- }[Code] : Code = Code extends "Continue" | "Switching Protocols" | "Processing" | "Early Hints" | "OK" | "Created" | "Accepted" | "Non-Authoritative Information" | "No Content" | "Reset Content" | "Partial Content" | "Multi-Status" | "Already Reported" | "Multiple Choices" | "Moved Permanently" | "Found" | "See Other" | "Not Modified" | "Temporary Redirect" | "Permanent Redirect" | "Bad Request" | "Unauthorized" | "Payment Required" | "Forbidden" | "Not Found" | "Method Not Allowed" | "Not Acceptable" | "Proxy Authentication Required" | "Request Timeout" | "Conflict" | "Gone" | "Length Required" | "Precondition Failed" | "Payload Too Large" | "URI Too Long" | "Unsupported Media Type" | "Range Not Satisfiable" | "Expectation Failed" | "I'm a teapot" | "Misdirected Request" | "Unprocessable Content" | "Locked" | "Failed Dependency" | "Too Early" | "Upgrade Required" | "Precondition Required" | "Too Many Requests" | "Request Header Fields Too Large" | "Unavailable For Legal Reasons" | "Internal Server Error" | "Not Implemented" | "Bad Gateway" | "Service Unavailable" | "Gateway Timeout" | "HTTP Version Not Supported" | "Variant Also Negotiates" | "Insufficient Storage" | "Loop Detected" | "Not Extended" | "Network Authentication Required" ? {
132
- readonly Continue: 100;
133
- readonly 'Switching Protocols': 101;
134
- readonly Processing: 102;
135
- readonly 'Early Hints': 103;
136
- readonly OK: 200;
137
- readonly Created: 201;
138
- readonly Accepted: 202;
139
- readonly 'Non-Authoritative Information': 203;
140
- readonly 'No Content': 204;
141
- readonly 'Reset Content': 205;
142
- readonly 'Partial Content': 206;
143
- readonly 'Multi-Status': 207;
144
- readonly 'Already Reported': 208;
145
- readonly 'Multiple Choices': 300;
146
- readonly 'Moved Permanently': 301;
147
- readonly Found: 302;
148
- readonly 'See Other': 303;
149
- readonly 'Not Modified': 304;
150
- readonly 'Temporary Redirect': 307;
151
- readonly 'Permanent Redirect': 308;
152
- readonly 'Bad Request': 400;
153
- readonly Unauthorized: 401;
154
- readonly 'Payment Required': 402;
155
- readonly Forbidden: 403;
156
- readonly 'Not Found': 404;
157
- readonly 'Method Not Allowed': 405;
158
- readonly 'Not Acceptable': 406;
159
- readonly 'Proxy Authentication Required': 407;
160
- readonly 'Request Timeout': 408;
161
- readonly Conflict: 409;
162
- readonly Gone: 410;
163
- readonly 'Length Required': 411;
164
- readonly 'Precondition Failed': 412;
165
- readonly 'Payload Too Large': 413;
166
- readonly 'URI Too Long': 414;
167
- readonly 'Unsupported Media Type': 415;
168
- readonly 'Range Not Satisfiable': 416;
169
- readonly 'Expectation Failed': 417;
170
- readonly "I'm a teapot": 418;
171
- readonly 'Misdirected Request': 421;
172
- readonly 'Unprocessable Content': 422;
173
- readonly Locked: 423;
174
- readonly 'Failed Dependency': 424;
175
- readonly 'Too Early': 425;
176
- readonly 'Upgrade Required': 426;
177
- readonly 'Precondition Required': 428;
178
- readonly 'Too Many Requests': 429;
179
- readonly 'Request Header Fields Too Large': 431;
180
- readonly 'Unavailable For Legal Reasons': 451;
181
- readonly 'Internal Server Error': 500;
182
- readonly 'Not Implemented': 501;
183
- readonly 'Bad Gateway': 502;
184
- readonly 'Service Unavailable': 503;
185
- readonly 'Gateway Timeout': 504;
186
- readonly 'HTTP Version Not Supported': 505;
187
- readonly 'Variant Also Negotiates': 506;
188
- readonly 'Insufficient Storage': 507;
189
- readonly 'Loop Detected': 508;
190
- readonly 'Not Extended': 510;
191
- readonly 'Network Authentication Required': 511;
192
- }[Code] : Code>(code: Code, response?: T) => {
193
- response: T;
194
- _type: { [ERROR_CODE in Status]: T; };
195
- error: Error;
196
- [ELYSIA_RESPONSE]: Status;
197
- };
198
- export declare class InternalServerError extends Error {
6
+ export declare class ValidationError extends Error {
199
7
  code: string;
200
8
  status: number;
201
- constructor(message?: string);
202
9
  }
203
10
  export declare class NotFoundError extends Error {
204
11
  code: string;
205
12
  status: number;
206
- constructor(message?: string);
207
13
  }
208
14
  export declare class ParseError extends Error {
209
15
  code: string;
210
16
  status: number;
211
- constructor();
212
17
  }
213
- export declare class InvalidCookieSignature extends Error {
214
- key: string;
215
- code: string;
216
- status: number;
217
- constructor(key: string, message?: string);
218
- }
219
- export declare const mapValueError: (error: ValueError) => {
220
- summary: string;
221
- type: import("@sinclair/typebox/build/cjs/value").ValueErrorType;
222
- schema: TSchema;
223
- path: string;
224
- value: unknown;
225
- message: string;
226
- };
227
- export declare class ValidationError extends Error {
228
- type: string;
229
- validator: TSchema | TypeCheck<any>;
230
- value: unknown;
18
+ export declare class InternalServerError extends Error {
231
19
  code: string;
232
20
  status: number;
233
- constructor(type: string, validator: TSchema | TypeCheck<any>, value: unknown);
234
- get all(): {
235
- summary: string;
236
- type: import("@sinclair/typebox/build/cjs/value").ValueErrorType;
237
- schema: TSchema;
238
- path: string;
239
- value: unknown;
240
- message: string;
241
- }[];
242
- static simplifyModel(validator: TSchema | TypeCheck<any>): any;
243
- get model(): any;
244
- toResponse(headers?: Record<string, any>): Response;
245
21
  }
246
22
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/elysia-fork/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAcvE,eAAO,MAAM,UAAU,eAA+B,CAAA;AACtD,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAA;AAE1C,eAAO,MAAM,eAAe,eAA8B,CAAA;AAC1D,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAA;AAEpD,eAAO,MAAM,YAAY,SAA+C,CAAA;AAExE,MAAM,MAAM,eAAe,GACxB,mBAAmB,GACnB,aAAa,GACb,UAAU,GACV,eAAe,GACf,sBAAsB,CAAA;AAEzB,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBASX,IAAI,aACC,CAAC;cAGF,CAAC;;WAIJ,KAAK;uBALO,MAAM;CAqBzB,CAAA;AAED,qBAAa,mBAAo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EpD,eAAO,MAAM,YAAY,SAA+C,CAAA;AAExE,qBAAa,eAAgB,SAAQ,KAAK;IACzC,IAAI,SAAe;IACnB,MAAM,SAAM;CACZ;AAED,qBAAa,aAAc,SAAQ,KAAK;IACvC,IAAI,SAAc;IAClB,MAAM,SAAM;CACZ;AAED,qBAAa,UAAW,SAAQ,KAAK;IACpC,IAAI,SAAU;IACd,MAAM,SAAM;CACZ;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,IAAI,SAA0B;IAC9B,MAAM,SAAM;CACZ"}
@@ -1,6 +1,4 @@
1
1
  var _a;
2
- import { Value } from '@sinclair/typebox/value';
3
- import { StatusMap, InvertedStatusMap } from './utils';
4
2
  // ? Cloudflare worker support
5
3
  const env =
6
4
  // @ts-ignore
@@ -13,183 +11,32 @@ typeof Bun !== 'undefined'
13
11
  export const ERROR_CODE = Symbol('SpiceflowErrorCode');
14
12
  export const ELYSIA_RESPONSE = Symbol('SpiceflowResponse');
15
13
  export const isProduction = ((_a = env === null || env === void 0 ? void 0 : env.NODE_ENV) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.ENV) === 'production';
16
- export const error = (code, response) => {
17
- var _a;
18
- const res = response !== null && response !== void 0 ? response : (code in InvertedStatusMap
19
- ? // @ts-expect-error Always correct
20
- InvertedStatusMap[code]
21
- : code);
22
- return {
23
- // @ts-expect-error trust me bro
24
- [ELYSIA_RESPONSE]: (_a = StatusMap[code]) !== null && _a !== void 0 ? _a : code,
25
- response: res,
26
- _type: undefined,
27
- error: new Error(res)
28
- };
29
- };
30
- export class InternalServerError extends Error {
31
- constructor(message) {
32
- super(message !== null && message !== void 0 ? message : 'INTERNAL_SERVER_ERROR');
33
- this.code = 'INTERNAL_SERVER_ERROR';
34
- this.status = 500;
14
+ export class ValidationError extends Error {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.code = 'VALIDATION';
18
+ this.status = 422;
35
19
  }
36
20
  }
37
21
  export class NotFoundError extends Error {
38
- constructor(message) {
39
- super(message !== null && message !== void 0 ? message : 'NOT_FOUND');
22
+ constructor() {
23
+ super(...arguments);
40
24
  this.code = 'NOT_FOUND';
41
25
  this.status = 404;
42
26
  }
43
27
  }
44
28
  export class ParseError extends Error {
45
29
  constructor() {
46
- super('Failed to parse body');
30
+ super(...arguments);
47
31
  this.code = 'PARSE';
48
32
  this.status = 400;
49
33
  }
50
34
  }
51
- export class InvalidCookieSignature extends Error {
52
- constructor(key, message) {
53
- super(message !== null && message !== void 0 ? message : `"${key}" has invalid cookie signature`);
54
- this.key = key;
55
- this.code = 'INVALID_COOKIE_SIGNATURE';
56
- this.status = 400;
57
- }
58
- }
59
- export const mapValueError = (error) => {
60
- const { message, path, value, type } = error;
61
- const property = path.slice(1).replaceAll('/', '.');
62
- const isRoot = path === '';
63
- switch (type) {
64
- case 42:
65
- return Object.assign(Object.assign({}, error), { summary: isRoot
66
- ? `Value should not be provided`
67
- : `Property '${property}' should not be provided` });
68
- case 45:
69
- return Object.assign(Object.assign({}, error), { summary: isRoot
70
- ? `Value is missing`
71
- : `Property '${property}' is missing` });
72
- case 50:
73
- // Expected string to match 'email' format
74
- const quoteIndex = message.indexOf("'");
75
- const format = message.slice(quoteIndex + 1, message.indexOf("'", quoteIndex + 1));
76
- return Object.assign(Object.assign({}, error), { summary: isRoot
77
- ? `Value should be an email`
78
- : `Property '${property}' should be ${format}` });
79
- case 54:
80
- return Object.assign(Object.assign({}, error), { summary: `${message.slice(0, 9)} property '${property}' to be ${message.slice(8)} but found: ${value}` });
81
- case 62:
82
- const union = error.schema.anyOf
83
- .map((x) => { var _a; return `'${(_a = x === null || x === void 0 ? void 0 : x.format) !== null && _a !== void 0 ? _a : x.type}'`; })
84
- .join(', ');
85
- return Object.assign(Object.assign({}, error), { summary: isRoot
86
- ? `Value should be one of ${union}`
87
- : `Property '${property}' should be one of: ${union}` });
88
- default:
89
- return Object.assign({ summary: message }, error);
90
- }
91
- };
92
- export class ValidationError extends Error {
93
- constructor(type, validator, value) {
94
- var _a, _b;
95
- if (value && typeof value === 'object' && ELYSIA_RESPONSE in value)
96
- // @ts-expect-error
97
- value = value.response;
98
- const error = isProduction
99
- ? undefined
100
- : 'Errors' in validator
101
- ? validator.Errors(value).First()
102
- : Value.Errors(validator, value).First();
103
- const customError = (error === null || error === void 0 ? void 0 : error.schema.error) !== undefined
104
- ? typeof error.schema.error === 'function'
105
- ? error.schema.error({
106
- type,
107
- validator,
108
- value,
109
- get errors() {
110
- return [...validator.Errors(value)].map(mapValueError);
111
- }
112
- })
113
- : error.schema.error
114
- : undefined;
115
- const accessor = (error === null || error === void 0 ? void 0 : error.path) || 'root';
116
- let message = '';
117
- if (customError !== undefined) {
118
- message =
119
- typeof customError === 'object'
120
- ? JSON.stringify(customError)
121
- : customError + '';
122
- }
123
- else if (isProduction) {
124
- message = JSON.stringify({
125
- type: 'validation',
126
- on: type,
127
- summary: mapValueError(error).summary,
128
- message: error === null || error === void 0 ? void 0 : error.message,
129
- found: value
130
- });
131
- }
132
- else {
133
- // @ts-ignore private field
134
- const schema = (_a = validator === null || validator === void 0 ? void 0 : validator.schema) !== null && _a !== void 0 ? _a : validator;
135
- const errors = 'Errors' in validator
136
- ? [...validator.Errors(value)].map(mapValueError)
137
- : [...Value.Errors(validator, value)].map(mapValueError);
138
- let expected;
139
- try {
140
- expected = Value.Create(schema);
141
- }
142
- catch (error) {
143
- expected = {
144
- type: 'Could not create expected value',
145
- // @ts-expect-error
146
- message: error === null || error === void 0 ? void 0 : error.message,
147
- error
148
- };
149
- }
150
- message = JSON.stringify({
151
- type: 'validation',
152
- on: type,
153
- summary: (_b = errors[0]) === null || _b === void 0 ? void 0 : _b.summary,
154
- property: accessor,
155
- message: error === null || error === void 0 ? void 0 : error.message,
156
- expected,
157
- found: value,
158
- errors
159
- }, null, 2);
160
- }
161
- super(message);
162
- this.type = type;
163
- this.validator = validator;
164
- this.value = value;
165
- this.code = 'VALIDATION';
166
- this.status = 422;
167
- Object.setPrototypeOf(this, ValidationError.prototype);
168
- }
169
- get all() {
170
- return 'Errors' in this.validator
171
- ? [...this.validator.Errors(this.value)].map(mapValueError)
172
- : // @ts-ignore
173
- [...Value.Errors(this.validator, this.value)].map(mapValueError);
174
- }
175
- static simplifyModel(validator) {
176
- // @ts-ignore
177
- const model = 'schema' in validator ? validator.schema : validator;
178
- try {
179
- return Value.Create(model);
180
- }
181
- catch (_a) {
182
- return model;
183
- }
184
- }
185
- get model() {
186
- return ValidationError.simplifyModel(this.validator);
187
- }
188
- toResponse(headers) {
189
- return new Response(this.message, {
190
- status: 400,
191
- headers: Object.assign(Object.assign({}, headers), { 'content-type': 'application/json' })
192
- });
35
+ export class InternalServerError extends Error {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.code = 'INTERNAL_SERVER_ERROR';
39
+ this.status = 500;
193
40
  }
194
41
  }
195
42
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/elysia-fork/error.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAG/C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEtD,8BAA8B;AAC9B,MAAM,GAAG;AACR,aAAa;AACb,OAAO,GAAG,KAAK,WAAW;IACzB,CAAC,CAAC,aAAa;QACb,GAAG,CAAC,GAAG;IACT,CAAC,CAAC,OAAO,OAAO,KAAK,WAAW;QAChC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG;QACd,CAAC,CAAC,SAAS,CAAA;AAEb,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAA;AAGtD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAG1D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,mCAAI,G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AAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,mCAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,GAAG,CAAC,KAAK,YAAY,CAAA;AAExE,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAA1C;;QACC,SAAI,GAAG,YAAY,CAAA;QACnB,WAAM,GAAG,GAAG,CAAA;IACb,CAAC;CAAA;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IAAxC;;QACC,SAAI,GAAG,WAAW,CAAA;QAClB,WAAM,GAAG,GAAG,CAAA;IACb,CAAC;CAAA;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IAArC;;QACC,SAAI,GAAG,OAAO,CAAA;QACd,WAAM,GAAG,GAAG,CAAA;IACb,CAAC;CAAA;AAED,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAA9C;;QACC,SAAI,GAAG,uBAAuB,CAAA;QAC9B,WAAM,GAAG,GAAG,CAAA;IACb,CAAC;CAAA"}
@@ -1,12 +1,12 @@
1
- /// <reference types="bun-types" />
2
- /// <reference types="bun-types" />
3
- import type { BunFile, Server } from 'bun';
4
- import type { TSchema, Static, TAnySchema, StaticDecode, OptionalKind } from '@sinclair/typebox';
1
+ import z from 'zod';
2
+ import type { OptionalKind, Static, StaticDecode, TObject, TSchema } from '@sinclair/typebox';
5
3
  import type { TypeCheck, ValueError } from '@sinclair/typebox/compiler';
4
+ import type { BunFile, Server } from 'bun';
6
5
  import type { OpenAPIV3 } from 'openapi-types';
7
- import type { Context, ErrorContext, PreContext } from './context';
8
- import { ELYSIA_RESPONSE, InternalServerError, InvalidCookieSignature, NotFoundError, ParseError, ValidationError } from './error';
9
6
  import { Spiceflow } from '../spiceflow';
7
+ import type { Context, ErrorContext, PreContext } from './context';
8
+ import { ELYSIA_RESPONSE, InternalServerError, NotFoundError, ParseError, ValidationError } from './error';
9
+ import { ZodTypeAny, ZodObject } from 'zod';
10
10
  export type MaybeArray<T> = T | T[];
11
11
  export type MaybePromise<T> = T | Promise<T>;
12
12
  export type ObjectValues<T extends object> = T[keyof T];
@@ -73,22 +73,23 @@ export interface MetadataBase {
73
73
  }
74
74
  export interface RouteSchema {
75
75
  body?: unknown;
76
- headers?: unknown;
77
76
  query?: unknown;
78
77
  params?: unknown;
79
- cookie?: unknown;
80
78
  response?: unknown;
81
79
  }
82
80
  type OptionalField = {
83
81
  [OptionalKind]: 'Optional';
84
82
  };
85
- export type UnwrapSchema<Schema extends TSchema | string | undefined, Definitions extends Record<string, unknown> = {}> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Definitions : unknown;
86
- export type UnwrapBodySchema<Schema extends TSchema | string | undefined, Definitions extends Record<string, unknown> = {}> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> | null : StaticDecode<Schema> : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Definitions : unknown;
83
+ export type TypeSchema = TSchema | ZodTypeAny;
84
+ export type TypeObject = TObject | ZodObject<any, any, any>;
85
+ export type UnwrapSchema<Schema extends TypeSchema | string | undefined, Definitions extends Record<string, unknown> = {}> = undefined extends Schema ? unknown : Schema extends ZodTypeAny ? z.infer<Schema> : Schema extends TSchema ? Schema extends OptionalField ? Prettify<Partial<Static<Schema>>> : StaticDecode<Schema> : Schema extends string ? Definitions extends Record<Schema, infer NamedSchema> ? NamedSchema : Definitions : unknown;
87
86
  export interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['type'] = {}> {
88
- body: UnwrapBodySchema<Schema['body'], Definitions>;
89
- response: Schema['response'] extends TSchema | string ? {
87
+ body: UnwrapSchema<Schema['body'], Definitions>;
88
+ query: UnwrapSchema<Schema['query'], Definitions>;
89
+ params: UnwrapSchema<Schema['params'], Definitions>;
90
+ response: Schema['response'] extends TypeSchema | string ? {
90
91
  200: CoExist<UnwrapSchema<Schema['response'], Definitions>, File, BunFile>;
91
- } : Schema['response'] extends Record<number, TAnySchema | string> ? {
92
+ } : Schema['response'] extends Record<number, TypeSchema | string> ? {
92
93
  [k in keyof Schema['response']]: CoExist<UnwrapSchema<Schema['response'][k], Definitions>, File, BunFile>;
93
94
  } : unknown | void;
94
95
  }
@@ -115,15 +116,15 @@ export type LifeCycleEvent = 'start' | 'request' | 'parse' | 'transform' | 'befo
115
116
  export type ContentType = MaybeArray<(string & {}) | 'none' | 'text' | 'json' | 'formdata' | 'urlencoded' | 'arrayBuffer' | 'text/plain' | 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded'>;
116
117
  export type HTTPMethod = (string & {}) | 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE' | 'ALL';
117
118
  export interface InputSchema<Name extends string = string> {
118
- body?: TSchema | Name;
119
- response?: TSchema | Record<number, TSchema> | Name | Record<number, Name | TSchema>;
119
+ body?: TypeSchema | Name;
120
+ query?: TypeObject | Name;
121
+ params?: TypeObject | Name;
122
+ response?: TypeSchema | Record<number, TypeSchema> | Name | Record<number, Name | TypeSchema>;
120
123
  }
121
124
  export interface MergeSchema<in out A extends RouteSchema, in out B extends RouteSchema> {
122
125
  body: undefined extends A['body'] ? B['body'] : A['body'];
123
- headers: undefined extends A['headers'] ? B['headers'] : A['headers'];
124
126
  query: undefined extends A['query'] ? B['query'] : A['query'];
125
127
  params: undefined extends A['params'] ? B['params'] : A['params'];
126
- cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie'];
127
128
  response: {} extends A['response'] ? {} extends B['response'] ? {} : B['response'] : {} extends B['response'] ? A['response'] : A['response'] & Omit<B['response'], keyof A['response']>;
128
129
  }
129
130
  export type Handler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
@@ -144,21 +145,14 @@ export type InlineHandler<Route extends RouteSchema = {}, Singleton extends Sing
144
145
  store: {};
145
146
  derive: {};
146
147
  resolve: {};
147
- }, Path extends string = '', MacroContext = {}> = ((context: MacroContext extends Record<string | number | symbol, unknown> ? Prettify<MacroContext & Context<Route, Singleton, Path>> : Context<Route, Singleton, Path>) => Response | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
148
- 200: any;
149
- } ? Route['response'] : string | number | boolean | Object) | Route['response'][keyof Route['response']] | {
150
- [Status in keyof Route['response']]: {
151
- _type: Record<Status, Route['response'][Status]>;
152
- [ELYSIA_RESPONSE]: Status;
153
- };
154
- }[keyof Route['response']]>) | ({} extends Route['response'] ? string | number | boolean | Object : (Route['response'] extends {
148
+ }, Path extends string = '', MacroContext = {}> = (context: MacroContext extends Record<string | number | symbol, unknown> ? Prettify<MacroContext & Context<Route, Singleton, Path>> : Context<Route, Singleton, Path>) => Response | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
155
149
  200: any;
156
150
  } ? Route['response'] : string | number | boolean | Object) | Route['response'][keyof Route['response']] | {
157
151
  [Status in keyof Route['response']]: {
158
152
  _type: Record<Status, Route['response'][Status]>;
159
153
  [ELYSIA_RESPONSE]: Status;
160
154
  };
161
- }[keyof Route['response']]);
155
+ }[keyof Route['response']]>;
162
156
  export type OptionalHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
163
157
  decorator: {};
164
158
  store: {};
@@ -278,10 +272,6 @@ export type ErrorHandler<in out T extends Record<string, Error> = {}, in out Rou
278
272
  code: 'INTERNAL_SERVER_ERROR';
279
273
  error: Readonly<InternalServerError>;
280
274
  } & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & Partial<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
281
- request: Request;
282
- code: 'INVALID_COOKIE_SIGNATURE';
283
- error: Readonly<InvalidCookieSignature>;
284
- } & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & NeverKey<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
285
275
  [K in keyof T]: {
286
276
  request: Request;
287
277
  code: K;