@20baht/elysia-idempotency 0.0.0-stage → 0.1.1

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/pg.js ADDED
@@ -0,0 +1,57 @@
1
+ // @bun
2
+ // src/pg.ts
3
+ import { and, eq, lt } from "drizzle-orm";
4
+ import {
5
+ index,
6
+ jsonb,
7
+ pgTable,
8
+ text,
9
+ timestamp
10
+ } from "drizzle-orm/pg-core";
11
+ var idempotencyTable = (name = "idempotency_keys") => pgTable(name, {
12
+ key: text("key").primaryKey(),
13
+ fingerprint: text("fingerprint").notNull(),
14
+ status: text("status", { enum: ["pending", "completed"] }).notNull(),
15
+ response: jsonb("response").$type(),
16
+ createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }).notNull()
17
+ }, (table) => [index(`${name}_created_at_idx`).on(table.createdAt)]);
18
+ var pgStore = ({
19
+ db,
20
+ table
21
+ }) => ({
22
+ async get(key) {
23
+ const [row] = await db.select().from(table).where(eq(table.key, key)).limit(1);
24
+ if (!row)
25
+ return;
26
+ const record = {
27
+ key: row.key,
28
+ fingerprint: row.fingerprint,
29
+ status: row.status,
30
+ createdAt: row.createdAt
31
+ };
32
+ if (row.response)
33
+ record.response = row.response;
34
+ return record;
35
+ },
36
+ async reserve(key, fingerprint, createdAt) {
37
+ const inserted = await db.insert(table).values({ key, fingerprint, status: "pending", createdAt }).onConflictDoNothing().returning({ key: table.key });
38
+ return inserted.length > 0;
39
+ },
40
+ async complete(key, createdAt, response) {
41
+ await db.update(table).set({ status: "completed", response }).where(and(eq(table.key, key), eq(table.createdAt, createdAt)));
42
+ },
43
+ async remove(key, createdAt) {
44
+ await db.delete(table).where(and(eq(table.key, key), eq(table.createdAt, createdAt)));
45
+ },
46
+ async purge(before) {
47
+ const gone = await db.delete(table).where(lt(table.createdAt, before)).returning({ key: table.key });
48
+ return gone.length;
49
+ }
50
+ });
51
+ export {
52
+ pgStore,
53
+ idempotencyTable
54
+ };
55
+
56
+ //# debugId=2E64800C7C8CEDFE64756E2164756E21
57
+ //# sourceMappingURL=pg.js.map
package/dist/pg.js.map ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/pg.ts"],
4
+ "sourcesContent": [
5
+ "// Keys kept in Postgres through drizzle-orm. The table goes into the host's own schema, so\n// drizzle-kit writes its migration with the rest.\nimport { and, eq, lt } from 'drizzle-orm';\nimport {\n index,\n jsonb,\n pgTable,\n text,\n timestamp,\n type PgDatabase,\n type PgQueryResultHKT,\n} from 'drizzle-orm/pg-core';\nimport type { IdempotencyRecord, IdempotencyStore, StoredResponse } from './core.ts';\n\n/** The table of keys, for the host's drizzle schema. */\nexport const idempotencyTable = (name = 'idempotency_keys') =>\n pgTable(\n name,\n {\n key: text('key').primaryKey(),\n fingerprint: text('fingerprint').notNull(),\n status: text('status', { enum: ['pending', 'completed'] }).notNull(),\n response: jsonb('response').$type<StoredResponse>(),\n createdAt: timestamp('created_at', { withTimezone: true, mode: 'date' }).notNull(),\n },\n (table) => [index(`${name}_created_at_idx`).on(table.createdAt)],\n );\n\nexport type IdempotencyTable = ReturnType<typeof idempotencyTable>;\n\n/** Any drizzle Postgres database (node-postgres, postgres.js, PGlite, Neon, …), whatever its schema. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- the host's schema type is its own; no query here reads it\nexport type IdempotencyDatabase = PgDatabase<PgQueryResultHKT, any>;\n\n/** The store on a drizzle Postgres database. */\nexport const pgStore = ({\n db,\n table,\n}: {\n db: IdempotencyDatabase;\n table: IdempotencyTable;\n}): IdempotencyStore => ({\n async get(key) {\n const [row] = await db.select().from(table).where(eq(table.key, key)).limit(1);\n if (!row) return undefined;\n const record: IdempotencyRecord = {\n key: row.key,\n fingerprint: row.fingerprint,\n status: row.status,\n createdAt: row.createdAt,\n };\n if (row.response) record.response = row.response;\n return record;\n },\n async reserve(key, fingerprint, createdAt) {\n const inserted = await db\n .insert(table)\n .values({ key, fingerprint, status: 'pending', createdAt })\n .onConflictDoNothing()\n .returning({ key: table.key });\n return inserted.length > 0;\n },\n async complete(key, createdAt, response) {\n await db\n .update(table)\n .set({ status: 'completed', response })\n .where(and(eq(table.key, key), eq(table.createdAt, createdAt)));\n },\n async remove(key, createdAt) {\n await db.delete(table).where(and(eq(table.key, key), eq(table.createdAt, createdAt)));\n },\n async purge(before) {\n const gone = await db\n .delete(table)\n .where(lt(table.createdAt, before))\n .returning({ key: table.key });\n return gone.length;\n },\n});\n"
6
+ ],
7
+ "mappings": ";;AAEA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,IAAM,mBAAmB,CAAC,OAAO,uBACtC,QACE,MACA;AAAA,EACE,KAAK,KAAK,KAAK,EAAE,WAAW;AAAA,EAC5B,aAAa,KAAK,aAAa,EAAE,QAAQ;AAAA,EACzC,QAAQ,KAAK,UAAU,EAAE,MAAM,CAAC,WAAW,WAAW,EAAE,CAAC,EAAE,QAAQ;AAAA,EACnE,UAAU,MAAM,UAAU,EAAE,MAAsB;AAAA,EAClD,WAAW,UAAU,cAAc,EAAE,cAAc,MAAM,MAAM,OAAO,CAAC,EAAE,QAAQ;AACnF,GACA,CAAC,UAAU,CAAC,MAAM,GAAG,qBAAqB,EAAE,GAAG,MAAM,SAAS,CAAC,CACjE;AASK,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,OAIuB;AAAA,OACjB,IAAG,CAAC,KAAK;AAAA,IACb,OAAO,OAAO,MAAM,GAAG,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC;AAAA,IAC7E,IAAI,CAAC;AAAA,MAAK;AAAA,IACV,MAAM,SAA4B;AAAA,MAChC,KAAK,IAAI;AAAA,MACT,aAAa,IAAI;AAAA,MACjB,QAAQ,IAAI;AAAA,MACZ,WAAW,IAAI;AAAA,IACjB;AAAA,IACA,IAAI,IAAI;AAAA,MAAU,OAAO,WAAW,IAAI;AAAA,IACxC,OAAO;AAAA;AAAA,OAEH,QAAO,CAAC,KAAK,aAAa,WAAW;AAAA,IACzC,MAAM,WAAW,MAAM,GACpB,OAAO,KAAK,EACZ,OAAO,EAAE,KAAK,aAAa,QAAQ,WAAW,UAAU,CAAC,EACzD,oBAAoB,EACpB,UAAU,EAAE,KAAK,MAAM,IAAI,CAAC;AAAA,IAC/B,OAAO,SAAS,SAAS;AAAA;AAAA,OAErB,SAAQ,CAAC,KAAK,WAAW,UAAU;AAAA,IACvC,MAAM,GACH,OAAO,KAAK,EACZ,IAAI,EAAE,QAAQ,aAAa,SAAS,CAAC,EACrC,MAAM,IAAI,GAAG,MAAM,KAAK,GAAG,GAAG,GAAG,MAAM,WAAW,SAAS,CAAC,CAAC;AAAA;AAAA,OAE5D,OAAM,CAAC,KAAK,WAAW;AAAA,IAC3B,MAAM,GAAG,OAAO,KAAK,EAAE,MAAM,IAAI,GAAG,MAAM,KAAK,GAAG,GAAG,GAAG,MAAM,WAAW,SAAS,CAAC,CAAC;AAAA;AAAA,OAEhF,MAAK,CAAC,QAAQ;AAAA,IAClB,MAAM,OAAO,MAAM,GAChB,OAAO,KAAK,EACZ,MAAM,GAAG,MAAM,WAAW,MAAM,CAAC,EACjC,UAAU,EAAE,KAAK,MAAM,IAAI,CAAC;AAAA,IAC/B,OAAO,KAAK;AAAA;AAEhB;",
8
+ "debugId": "2E64800C7C8CEDFE64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,541 @@
1
+ import { Elysia, ElysiaCustomStatusResponse } from 'elysia';
2
+ import { type IdempotencyOptions } from './core.js';
3
+ /** What `scope` is handed: the route's context, with whatever earlier plugins put on it (a `caller`). */
4
+ export type ScopeContext = Readonly<Record<string, unknown>> & {
5
+ readonly request: Request;
6
+ readonly headers: Readonly<Record<string, string | undefined>>;
7
+ };
8
+ export interface IdempotencyPluginOptions extends IdempotencyOptions {
9
+ /** The header the key comes in. Default `idempotency-key`. */
10
+ header?: string;
11
+ /** The longest key taken. Default 255. */
12
+ maxKeyLength?: number;
13
+ /**
14
+ * Whose key it is: the signed-in caller (`({ caller }) => caller.subject`), so two callers' keys
15
+ * never meet. It is handed the route's context after every `resolve` (an `auth` or `scope` option
16
+ * included, whatever their order on the route). Without one, every caller shares one set of keys.
17
+ */
18
+ scope?: (context: ScopeContext) => string | undefined | Promise<string | undefined>;
19
+ /** The response headers kept and sent again. Default `content-type` and `location`. */
20
+ replayHeaders?: readonly string[];
21
+ }
22
+ /** The body of a refusal: a code to branch on, and a sentence. */
23
+ export interface IdempotencyError {
24
+ code: 'IDEMPOTENCY_KEY_MISSING' | 'IDEMPOTENCY_KEY_INVALID' | 'IDEMPOTENCY_KEY_REUSED' | 'IDEMPOTENCY_IN_PROGRESS';
25
+ message: string;
26
+ }
27
+ /**
28
+ * The route option `idempotent`: `true` takes an `Idempotency-Key` when one is sent, `'required'`
29
+ * refuses a request without one (400). A retry with the same key and request gets the first response
30
+ * again (`Idempotent-Replayed: true`); the same key with another request is a 422, and while the first
31
+ * is running a 409. A handler that throws, or answers 5xx, gives its key up so a retry runs again.
32
+ */
33
+ export declare const idempotency: (options: IdempotencyPluginOptions) => Elysia<"", {
34
+ decorator: {};
35
+ store: {};
36
+ derive: {};
37
+ resolve: {};
38
+ }, {
39
+ typebox: {};
40
+ error: {};
41
+ }, {
42
+ schema: {};
43
+ standaloneSchema: {};
44
+ macro: Partial<{
45
+ readonly idempotent: boolean | "required";
46
+ }>;
47
+ macroFn: {
48
+ readonly idempotent: (mode: boolean | "required") => {
49
+ readonly beforeHandle: (context: {
50
+ body: unknown;
51
+ query: Record<string, string>;
52
+ params: {};
53
+ headers: Record<string, string | undefined>;
54
+ cookie: Record<string, import("elysia").Cookie<unknown>>;
55
+ server: import("elysia/universal/server").Server | null;
56
+ redirect: import("elysia").redirect;
57
+ set: {
58
+ headers: import("elysia").HTTPHeaders;
59
+ status?: number | keyof import("elysia").StatusMap;
60
+ redirect?: string;
61
+ cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
62
+ };
63
+ path: string;
64
+ route: string;
65
+ request: Request;
66
+ store: {};
67
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 400 | 422 | 409 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
68
+ readonly 100: "Continue";
69
+ readonly 101: "Switching Protocols";
70
+ readonly 102: "Processing";
71
+ readonly 103: "Early Hints";
72
+ readonly 200: "OK";
73
+ readonly 201: "Created";
74
+ readonly 202: "Accepted";
75
+ readonly 203: "Non-Authoritative Information";
76
+ readonly 204: "No Content";
77
+ readonly 205: "Reset Content";
78
+ readonly 206: "Partial Content";
79
+ readonly 207: "Multi-Status";
80
+ readonly 208: "Already Reported";
81
+ readonly 300: "Multiple Choices";
82
+ readonly 301: "Moved Permanently";
83
+ readonly 302: "Found";
84
+ readonly 303: "See Other";
85
+ readonly 304: "Not Modified";
86
+ readonly 307: "Temporary Redirect";
87
+ readonly 308: "Permanent Redirect";
88
+ readonly 400: "Bad Request";
89
+ readonly 401: "Unauthorized";
90
+ readonly 402: "Payment Required";
91
+ readonly 403: "Forbidden";
92
+ readonly 404: "Not Found";
93
+ readonly 405: "Method Not Allowed";
94
+ readonly 406: "Not Acceptable";
95
+ readonly 407: "Proxy Authentication Required";
96
+ readonly 408: "Request Timeout";
97
+ readonly 409: "Conflict";
98
+ readonly 410: "Gone";
99
+ readonly 411: "Length Required";
100
+ readonly 412: "Precondition Failed";
101
+ readonly 413: "Payload Too Large";
102
+ readonly 414: "URI Too Long";
103
+ readonly 415: "Unsupported Media Type";
104
+ readonly 416: "Range Not Satisfiable";
105
+ readonly 417: "Expectation Failed";
106
+ readonly 418: "I'm a teapot";
107
+ readonly 420: "Enhance Your Calm";
108
+ readonly 421: "Misdirected Request";
109
+ readonly 422: "Unprocessable Content";
110
+ readonly 423: "Locked";
111
+ readonly 424: "Failed Dependency";
112
+ readonly 425: "Too Early";
113
+ readonly 426: "Upgrade Required";
114
+ readonly 428: "Precondition Required";
115
+ readonly 429: "Too Many Requests";
116
+ readonly 431: "Request Header Fields Too Large";
117
+ readonly 451: "Unavailable For Legal Reasons";
118
+ readonly 500: "Internal Server Error";
119
+ readonly 501: "Not Implemented";
120
+ readonly 502: "Bad Gateway";
121
+ readonly 503: "Service Unavailable";
122
+ readonly 504: "Gateway Timeout";
123
+ readonly 505: "HTTP Version Not Supported";
124
+ readonly 506: "Variant Also Negotiates";
125
+ readonly 507: "Insufficient Storage";
126
+ readonly 508: "Loop Detected";
127
+ readonly 510: "Not Extended";
128
+ readonly 511: "Network Authentication Required";
129
+ }[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, 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" | "Enhance Your Calm" | "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" ? {
130
+ readonly Continue: 100;
131
+ readonly "Switching Protocols": 101;
132
+ readonly Processing: 102;
133
+ readonly "Early Hints": 103;
134
+ readonly OK: 200;
135
+ readonly Created: 201;
136
+ readonly Accepted: 202;
137
+ readonly "Non-Authoritative Information": 203;
138
+ readonly "No Content": 204;
139
+ readonly "Reset Content": 205;
140
+ readonly "Partial Content": 206;
141
+ readonly "Multi-Status": 207;
142
+ readonly "Already Reported": 208;
143
+ readonly "Multiple Choices": 300;
144
+ readonly "Moved Permanently": 301;
145
+ readonly Found: 302;
146
+ readonly "See Other": 303;
147
+ readonly "Not Modified": 304;
148
+ readonly "Temporary Redirect": 307;
149
+ readonly "Permanent Redirect": 308;
150
+ readonly "Bad Request": 400;
151
+ readonly Unauthorized: 401;
152
+ readonly "Payment Required": 402;
153
+ readonly Forbidden: 403;
154
+ readonly "Not Found": 404;
155
+ readonly "Method Not Allowed": 405;
156
+ readonly "Not Acceptable": 406;
157
+ readonly "Proxy Authentication Required": 407;
158
+ readonly "Request Timeout": 408;
159
+ readonly Conflict: 409;
160
+ readonly Gone: 410;
161
+ readonly "Length Required": 411;
162
+ readonly "Precondition Failed": 412;
163
+ readonly "Payload Too Large": 413;
164
+ readonly "URI Too Long": 414;
165
+ readonly "Unsupported Media Type": 415;
166
+ readonly "Range Not Satisfiable": 416;
167
+ readonly "Expectation Failed": 417;
168
+ readonly "I'm a teapot": 418;
169
+ readonly "Enhance Your Calm": 420;
170
+ readonly "Misdirected Request": 421;
171
+ readonly "Unprocessable Content": 422;
172
+ readonly Locked: 423;
173
+ readonly "Failed Dependency": 424;
174
+ readonly "Too Early": 425;
175
+ readonly "Upgrade Required": 426;
176
+ readonly "Precondition Required": 428;
177
+ readonly "Too Many Requests": 429;
178
+ readonly "Request Header Fields Too Large": 431;
179
+ readonly "Unavailable For Legal Reasons": 451;
180
+ readonly "Internal Server Error": 500;
181
+ readonly "Not Implemented": 501;
182
+ readonly "Bad Gateway": 502;
183
+ readonly "Service Unavailable": 503;
184
+ readonly "Gateway Timeout": 504;
185
+ readonly "HTTP Version Not Supported": 505;
186
+ readonly "Variant Also Negotiates": 506;
187
+ readonly "Insufficient Storage": 507;
188
+ readonly "Loop Detected": 508;
189
+ readonly "Not Extended": 510;
190
+ readonly "Network Authentication Required": 511;
191
+ }[Code] : Code>;
192
+ }) => Promise<Response | undefined>;
193
+ readonly afterHandle: ({ request, responseValue, set }: {
194
+ body: unknown;
195
+ query: Record<string, string>;
196
+ params: {};
197
+ headers: Record<string, string | undefined>;
198
+ cookie: Record<string, import("elysia").Cookie<unknown>>;
199
+ server: import("elysia/universal/server").Server | null;
200
+ redirect: import("elysia").redirect;
201
+ set: {
202
+ headers: import("elysia").HTTPHeaders;
203
+ status?: number | keyof import("elysia").StatusMap;
204
+ redirect?: string;
205
+ cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
206
+ };
207
+ path: string;
208
+ route: string;
209
+ request: Request;
210
+ store: {};
211
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 400 | 422 | 409 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
212
+ readonly 100: "Continue";
213
+ readonly 101: "Switching Protocols";
214
+ readonly 102: "Processing";
215
+ readonly 103: "Early Hints";
216
+ readonly 200: "OK";
217
+ readonly 201: "Created";
218
+ readonly 202: "Accepted";
219
+ readonly 203: "Non-Authoritative Information";
220
+ readonly 204: "No Content";
221
+ readonly 205: "Reset Content";
222
+ readonly 206: "Partial Content";
223
+ readonly 207: "Multi-Status";
224
+ readonly 208: "Already Reported";
225
+ readonly 300: "Multiple Choices";
226
+ readonly 301: "Moved Permanently";
227
+ readonly 302: "Found";
228
+ readonly 303: "See Other";
229
+ readonly 304: "Not Modified";
230
+ readonly 307: "Temporary Redirect";
231
+ readonly 308: "Permanent Redirect";
232
+ readonly 400: "Bad Request";
233
+ readonly 401: "Unauthorized";
234
+ readonly 402: "Payment Required";
235
+ readonly 403: "Forbidden";
236
+ readonly 404: "Not Found";
237
+ readonly 405: "Method Not Allowed";
238
+ readonly 406: "Not Acceptable";
239
+ readonly 407: "Proxy Authentication Required";
240
+ readonly 408: "Request Timeout";
241
+ readonly 409: "Conflict";
242
+ readonly 410: "Gone";
243
+ readonly 411: "Length Required";
244
+ readonly 412: "Precondition Failed";
245
+ readonly 413: "Payload Too Large";
246
+ readonly 414: "URI Too Long";
247
+ readonly 415: "Unsupported Media Type";
248
+ readonly 416: "Range Not Satisfiable";
249
+ readonly 417: "Expectation Failed";
250
+ readonly 418: "I'm a teapot";
251
+ readonly 420: "Enhance Your Calm";
252
+ readonly 421: "Misdirected Request";
253
+ readonly 422: "Unprocessable Content";
254
+ readonly 423: "Locked";
255
+ readonly 424: "Failed Dependency";
256
+ readonly 425: "Too Early";
257
+ readonly 426: "Upgrade Required";
258
+ readonly 428: "Precondition Required";
259
+ readonly 429: "Too Many Requests";
260
+ readonly 431: "Request Header Fields Too Large";
261
+ readonly 451: "Unavailable For Legal Reasons";
262
+ readonly 500: "Internal Server Error";
263
+ readonly 501: "Not Implemented";
264
+ readonly 502: "Bad Gateway";
265
+ readonly 503: "Service Unavailable";
266
+ readonly 504: "Gateway Timeout";
267
+ readonly 505: "HTTP Version Not Supported";
268
+ readonly 506: "Variant Also Negotiates";
269
+ readonly 507: "Insufficient Storage";
270
+ readonly 508: "Loop Detected";
271
+ readonly 510: "Not Extended";
272
+ readonly 511: "Network Authentication Required";
273
+ }[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, 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" | "Enhance Your Calm" | "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" ? {
274
+ readonly Continue: 100;
275
+ readonly "Switching Protocols": 101;
276
+ readonly Processing: 102;
277
+ readonly "Early Hints": 103;
278
+ readonly OK: 200;
279
+ readonly Created: 201;
280
+ readonly Accepted: 202;
281
+ readonly "Non-Authoritative Information": 203;
282
+ readonly "No Content": 204;
283
+ readonly "Reset Content": 205;
284
+ readonly "Partial Content": 206;
285
+ readonly "Multi-Status": 207;
286
+ readonly "Already Reported": 208;
287
+ readonly "Multiple Choices": 300;
288
+ readonly "Moved Permanently": 301;
289
+ readonly Found: 302;
290
+ readonly "See Other": 303;
291
+ readonly "Not Modified": 304;
292
+ readonly "Temporary Redirect": 307;
293
+ readonly "Permanent Redirect": 308;
294
+ readonly "Bad Request": 400;
295
+ readonly Unauthorized: 401;
296
+ readonly "Payment Required": 402;
297
+ readonly Forbidden: 403;
298
+ readonly "Not Found": 404;
299
+ readonly "Method Not Allowed": 405;
300
+ readonly "Not Acceptable": 406;
301
+ readonly "Proxy Authentication Required": 407;
302
+ readonly "Request Timeout": 408;
303
+ readonly Conflict: 409;
304
+ readonly Gone: 410;
305
+ readonly "Length Required": 411;
306
+ readonly "Precondition Failed": 412;
307
+ readonly "Payload Too Large": 413;
308
+ readonly "URI Too Long": 414;
309
+ readonly "Unsupported Media Type": 415;
310
+ readonly "Range Not Satisfiable": 416;
311
+ readonly "Expectation Failed": 417;
312
+ readonly "I'm a teapot": 418;
313
+ readonly "Enhance Your Calm": 420;
314
+ readonly "Misdirected Request": 421;
315
+ readonly "Unprocessable Content": 422;
316
+ readonly Locked: 423;
317
+ readonly "Failed Dependency": 424;
318
+ readonly "Too Early": 425;
319
+ readonly "Upgrade Required": 426;
320
+ readonly "Precondition Required": 428;
321
+ readonly "Too Many Requests": 429;
322
+ readonly "Request Header Fields Too Large": 431;
323
+ readonly "Unavailable For Legal Reasons": 451;
324
+ readonly "Internal Server Error": 500;
325
+ readonly "Not Implemented": 501;
326
+ readonly "Bad Gateway": 502;
327
+ readonly "Service Unavailable": 503;
328
+ readonly "Gateway Timeout": 504;
329
+ readonly "HTTP Version Not Supported": 505;
330
+ readonly "Variant Also Negotiates": 506;
331
+ readonly "Insufficient Storage": 507;
332
+ readonly "Loop Detected": 508;
333
+ readonly "Not Extended": 510;
334
+ readonly "Network Authentication Required": 511;
335
+ }[Code] : Code>;
336
+ } & {
337
+ responseValue: unknown;
338
+ response: unknown;
339
+ }) => Promise<void>;
340
+ readonly error: ({ request }: {
341
+ body: unknown;
342
+ query: Record<string, string | undefined>;
343
+ params: {};
344
+ headers: Record<string, string | undefined>;
345
+ cookie: Record<string, import("elysia").Cookie<string | undefined>>;
346
+ server: import("elysia/universal/server").Server | null;
347
+ redirect: import("elysia").redirect;
348
+ set: {
349
+ headers: import("elysia").HTTPHeaders;
350
+ status?: number | keyof import("elysia").StatusMap;
351
+ redirect?: string;
352
+ cookie?: Record<string, import("elysia/cookies").ElysiaCookie>;
353
+ };
354
+ status: <const Code extends number | keyof import("elysia").StatusMap, const T = Code extends 200 | 204 | 304 | 400 | 422 | 409 | 100 | 101 | 102 | 103 | 201 | 202 | 203 | 205 | 206 | 207 | 208 | 300 | 301 | 302 | 303 | 307 | 308 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 ? {
355
+ readonly 100: "Continue";
356
+ readonly 101: "Switching Protocols";
357
+ readonly 102: "Processing";
358
+ readonly 103: "Early Hints";
359
+ readonly 200: "OK";
360
+ readonly 201: "Created";
361
+ readonly 202: "Accepted";
362
+ readonly 203: "Non-Authoritative Information";
363
+ readonly 204: "No Content";
364
+ readonly 205: "Reset Content";
365
+ readonly 206: "Partial Content";
366
+ readonly 207: "Multi-Status";
367
+ readonly 208: "Already Reported";
368
+ readonly 300: "Multiple Choices";
369
+ readonly 301: "Moved Permanently";
370
+ readonly 302: "Found";
371
+ readonly 303: "See Other";
372
+ readonly 304: "Not Modified";
373
+ readonly 307: "Temporary Redirect";
374
+ readonly 308: "Permanent Redirect";
375
+ readonly 400: "Bad Request";
376
+ readonly 401: "Unauthorized";
377
+ readonly 402: "Payment Required";
378
+ readonly 403: "Forbidden";
379
+ readonly 404: "Not Found";
380
+ readonly 405: "Method Not Allowed";
381
+ readonly 406: "Not Acceptable";
382
+ readonly 407: "Proxy Authentication Required";
383
+ readonly 408: "Request Timeout";
384
+ readonly 409: "Conflict";
385
+ readonly 410: "Gone";
386
+ readonly 411: "Length Required";
387
+ readonly 412: "Precondition Failed";
388
+ readonly 413: "Payload Too Large";
389
+ readonly 414: "URI Too Long";
390
+ readonly 415: "Unsupported Media Type";
391
+ readonly 416: "Range Not Satisfiable";
392
+ readonly 417: "Expectation Failed";
393
+ readonly 418: "I'm a teapot";
394
+ readonly 420: "Enhance Your Calm";
395
+ readonly 421: "Misdirected Request";
396
+ readonly 422: "Unprocessable Content";
397
+ readonly 423: "Locked";
398
+ readonly 424: "Failed Dependency";
399
+ readonly 425: "Too Early";
400
+ readonly 426: "Upgrade Required";
401
+ readonly 428: "Precondition Required";
402
+ readonly 429: "Too Many Requests";
403
+ readonly 431: "Request Header Fields Too Large";
404
+ readonly 451: "Unavailable For Legal Reasons";
405
+ readonly 500: "Internal Server Error";
406
+ readonly 501: "Not Implemented";
407
+ readonly 502: "Bad Gateway";
408
+ readonly 503: "Service Unavailable";
409
+ readonly 504: "Gateway Timeout";
410
+ readonly 505: "HTTP Version Not Supported";
411
+ readonly 506: "Variant Also Negotiates";
412
+ readonly 507: "Insufficient Storage";
413
+ readonly 508: "Loop Detected";
414
+ readonly 510: "Not Extended";
415
+ readonly 511: "Network Authentication Required";
416
+ }[Code] : Code>(code: Code, response?: T) => ElysiaCustomStatusResponse<Code, T, 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" | "Enhance Your Calm" | "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" ? {
417
+ readonly Continue: 100;
418
+ readonly "Switching Protocols": 101;
419
+ readonly Processing: 102;
420
+ readonly "Early Hints": 103;
421
+ readonly OK: 200;
422
+ readonly Created: 201;
423
+ readonly Accepted: 202;
424
+ readonly "Non-Authoritative Information": 203;
425
+ readonly "No Content": 204;
426
+ readonly "Reset Content": 205;
427
+ readonly "Partial Content": 206;
428
+ readonly "Multi-Status": 207;
429
+ readonly "Already Reported": 208;
430
+ readonly "Multiple Choices": 300;
431
+ readonly "Moved Permanently": 301;
432
+ readonly Found: 302;
433
+ readonly "See Other": 303;
434
+ readonly "Not Modified": 304;
435
+ readonly "Temporary Redirect": 307;
436
+ readonly "Permanent Redirect": 308;
437
+ readonly "Bad Request": 400;
438
+ readonly Unauthorized: 401;
439
+ readonly "Payment Required": 402;
440
+ readonly Forbidden: 403;
441
+ readonly "Not Found": 404;
442
+ readonly "Method Not Allowed": 405;
443
+ readonly "Not Acceptable": 406;
444
+ readonly "Proxy Authentication Required": 407;
445
+ readonly "Request Timeout": 408;
446
+ readonly Conflict: 409;
447
+ readonly Gone: 410;
448
+ readonly "Length Required": 411;
449
+ readonly "Precondition Failed": 412;
450
+ readonly "Payload Too Large": 413;
451
+ readonly "URI Too Long": 414;
452
+ readonly "Unsupported Media Type": 415;
453
+ readonly "Range Not Satisfiable": 416;
454
+ readonly "Expectation Failed": 417;
455
+ readonly "I'm a teapot": 418;
456
+ readonly "Enhance Your Calm": 420;
457
+ readonly "Misdirected Request": 421;
458
+ readonly "Unprocessable Content": 422;
459
+ readonly Locked: 423;
460
+ readonly "Failed Dependency": 424;
461
+ readonly "Too Early": 425;
462
+ readonly "Upgrade Required": 426;
463
+ readonly "Precondition Required": 428;
464
+ readonly "Too Many Requests": 429;
465
+ readonly "Request Header Fields Too Large": 431;
466
+ readonly "Unavailable For Legal Reasons": 451;
467
+ readonly "Internal Server Error": 500;
468
+ readonly "Not Implemented": 501;
469
+ readonly "Bad Gateway": 502;
470
+ readonly "Service Unavailable": 503;
471
+ readonly "Gateway Timeout": 504;
472
+ readonly "HTTP Version Not Supported": 505;
473
+ readonly "Variant Also Negotiates": 506;
474
+ readonly "Insufficient Storage": 507;
475
+ readonly "Loop Detected": 508;
476
+ readonly "Not Extended": 510;
477
+ readonly "Network Authentication Required": 511;
478
+ }[Code] : Code>;
479
+ path: string;
480
+ route: string;
481
+ request: Request;
482
+ store: {};
483
+ } & ({
484
+ request: Request;
485
+ code: "UNKNOWN";
486
+ error: Readonly<Error>;
487
+ set: import("elysia").Context["set"];
488
+ } | {
489
+ request: Request;
490
+ code: "VALIDATION";
491
+ error: Readonly<import("elysia").ValidationError>;
492
+ set: import("elysia").Context["set"];
493
+ } | {
494
+ request: Request;
495
+ code: "NOT_FOUND";
496
+ error: Readonly<import("elysia").NotFoundError>;
497
+ set: import("elysia").Context["set"];
498
+ } | {
499
+ request: Request;
500
+ code: "PARSE";
501
+ error: Readonly<import("elysia").ParseError>;
502
+ set: import("elysia").Context["set"];
503
+ } | {
504
+ request: Request;
505
+ code: "INTERNAL_SERVER_ERROR";
506
+ error: Readonly<import("elysia").InternalServerError>;
507
+ set: import("elysia").Context["set"];
508
+ } | {
509
+ request: Request;
510
+ code: "INVALID_COOKIE_SIGNATURE";
511
+ error: Readonly<import("elysia").InvalidCookieSignature>;
512
+ set: import("elysia").Context["set"];
513
+ } | {
514
+ request: Request;
515
+ code: "INVALID_FILE_TYPE";
516
+ error: Readonly<import("elysia").InvalidFileType>;
517
+ set: import("elysia").Context["set"];
518
+ } | {
519
+ request: Request;
520
+ code: number;
521
+ error: Readonly<ElysiaCustomStatusResponse<number>>;
522
+ set: import("elysia").Context["set"];
523
+ })) => Promise<void>;
524
+ };
525
+ };
526
+ parser: {};
527
+ response: {};
528
+ }, {}, {
529
+ derive: {};
530
+ resolve: {};
531
+ schema: {};
532
+ standaloneSchema: {};
533
+ response: {};
534
+ }, {
535
+ derive: {};
536
+ resolve: {};
537
+ schema: {};
538
+ standaloneSchema: {};
539
+ response: {};
540
+ }>;
541
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,WAAW,CAAC;AAEnB,yGAAyG;AACzG,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG;IAC7D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IAClE,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACpF,uFAAuF;IACvF,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED,kEAAkE;AAClE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EACA,yBAAyB,GACzB,yBAAyB,GACzB,wBAAwB,GACxB,yBAAyB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAwFD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,SAAS,wBAAwB;;;;;;;;;;;;;;;oCAWtC,OAAO,GAAG,UAAU;;;;;;;;;;;0BAtCV,CAAC;4BAQhC,CAAD;0BAEQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAVuB,CAAC;4BAQhC,CAAD;0BAEQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BA/EN,CAAF;4BACW,CAAC;0BAKU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmKxB,CAAC"}