fetchwork 1.0.10 → 1.0.11

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/README.md CHANGED
@@ -12,54 +12,43 @@
12
12
 
13
13
  ## Features
14
14
 
15
- - **Pure W3C Web Standard Core**: Built 100% on native `Request` and `Response` web interfaces. Exposes a clean `app.fetch` handler.
16
- - **Fast Compiled Regex Engine**: High-performance $O(1)$ `Map` lookups for static routes and single-pass compiled regex matching for dynamic routes (replacing heavy `URLPattern` overhead).
17
- - **Zero URL Overhead**: Direct fast-string parsing that bypasses memory-heavy `new URL()` allocations per request.
18
- - **Unified Modern Context**: Eliminates `c.req` and `c.res` clutter by exposing params, queries, payload helpers, and responses directly on `c`.
19
- - **Ultra-Low Overhead Middleware**: Recursive middleware chain execution with less than 3% total throughput impact.
20
- - **Modular Route Grouping**: Flexible prefixing support via `app.route()` to structure large applications effortlessly.
21
- - **Zod Validation Integration**: Native payload, query, and parameter validation executed before route handlers.
22
- - **Multi-Runtime Ready**: Native support for running under Bun, Node.js (`@hono/node-server` style), or Cloudflare Workers via `app.fetch`.
15
+ - **Pure W3C Web Standard Core**: Built 100% on native `Request` and `Response` web interfaces with zero-copy I/O.
16
+ - **Fast Compiled Regex Engine**: High-performance $O(1)$ `Map` lookups for static routes and single-pass compiled regex matching for dynamic routes.
17
+ - **Standard Schema Interoperability**: First-class validation for `body`, `query`, `params`, and `headers` using Zod, Valibot, or ArkType via Standard Schema (`validateSchema`).
18
+ - **Ultra-Low Latency SSE**: Built-in `c.sse()` streaming helper backed by native `TransformStream` and zero proxy buffering headers.
19
+ - **Gradual Level-Based Rate Limiter**: High-performance multi-level `FloodWait` rate limiter (`app.rateLimit()`) supporting static and wildcard path matching.
20
+ - **Built-in Ultra-Fast CORS**: Zero-overhead CORS middleware supporting static origins and $O(1)$ Set-based whitelist matching.
21
+ - **Custom Not Found & Error Handling**: Flexible `app.notFound()` and `app.onError()` handlers with zero latency penalty on hot paths.
22
+ - **Multi-Runtime Ready**: Seamlessly run under Bun, Node.js, Cloudflare Workers, or Vercel via standard `app.fetch`.
23
23
 
24
24
  ---
25
25
 
26
26
  ## ⚡ Performance & Benchmarks
27
27
 
28
- Benchmarking results using **Autocannon** (100 parallel connections, 10 pipelining factor, 10-second duration) on Bun.
28
+ Benchmarking results measured using **Autocannon** (100 parallel connections, 10 pipelining factor, 10-second duration) running natively on Bun.
29
29
 
30
- ### 1. Static Route Performance Across Adapters (`GET /json`)
30
+ ### 1. Complete Feature Suite Performance (`bench-all`)
31
31
 
32
- _Comparing static JSON response throughput across different server runtime adapters:_
32
+ _Comparing performance across core framework features under heavy load:_
33
33
 
34
- | Adapter / Runtime | Throughput (Avg RPS) | Latency Avg | Latency P50 | Latency P99 | Throughput (MB/s) |
35
- | :---------------------------------- | :------------------- | :----------- | :----------- | :----------- | :---------------- |
36
- | **serveBun (Bun Native)** | **14,702.4 RPS** | **68.30 ms** | **67.00 ms** | **90.00 ms** | **2.55 MB/s** |
37
- | **serveNode (Node.js)** | 5,601.2 RPS | 184.52 ms | 177.00 ms | 314.00 ms | 1.32 MB/s |
38
- | **handleVercel (Serverless Local)** | 5,101.9 RPS | 204.05 ms | 192.00 ms | 379.00 ms | 1.21 MB/s |
34
+ | Feature / Scenario | Throughput (Avg RPS) | Latency Avg | Latency P50 | Latency P99 | Throughput (MB/s) | Total Requests (10s) |
35
+ | :----------------------------- | :------------------- | :----------- | :----------- | :------------ | :---------------- | :------------------- |
36
+ | **Baseline Routing (`/ping`)** | **14,901.6 RPS** | **67.24 ms** | **66.00 ms** | **142.00 ms** | **1.71 MB/s** | **149k req** |
37
+ | **CORS Preflight (`OPTIONS`)** | **15,100.8 RPS** | **66.06 ms** | **65.00 ms** | **82.00 ms** | **3.30 MB/s** | **151k req** |
38
+ | **Validator Standard Schema** | **11,076.0 RPS** | **90.69 ms** | **89.00 ms** | **111.00 ms** | **3.55 MB/s** | **110k req** |
39
+ | **SSE Initial Handshake** | **6,691.2 RPS** | **14.47 ms** | **13.00 ms** | **27.00 ms** | **1.60 MB/s** | **66k req** |
39
40
 
40
- > **Result:** Running FetchWork natively via `serveBun` unlocks maximum zero-copy I/O throughput, outperforming Node.js and Vercel adapters by **~2.6x**.
41
+ ### 2. Multi-Level Rate Limiter Throughput
41
42
 
42
- ### 2. Nested Dynamic Route Matching (`/:tenant/users/:userId/posts/:postId`)
43
+ _Throughput evaluation when rate limiting is applied across static and wildcard paths:_
43
44
 
44
- _Testing multi-level dynamic parameter extraction throughput:_
45
+ | Scenario | Throughput (Avg RPS) | Latency Avg | Latency P50 | Latency P99 | Throughput (MB/s) | Total Requests (10s) |
46
+ | :------------------------------ | :------------------- | :----------- | :----------- | :------------ | :---------------- | :------------------- |
47
+ | **No Rate Limit (Baseline)** | **15,409.6 RPS** | **64.76 ms** | **64.00 ms** | **82.00 ms** | **1.76 MB/s** | **154k req** |
48
+ | **Static Rate Limit $O(1)$** | **12,703.2 RPS** | **79.15 ms** | **77.00 ms** | **96.00 ms** | **3.44 MB/s** | **127k req** |
49
+ | **Wildcard Rate Limit (Regex)** | **12,674.4 RPS** | **79.26 ms** | **76.00 ms** | **150.00 ms** | **3.31 MB/s** | **126k req** |
45
50
 
46
- | Router Engine | Throughput (Avg RPS) | Latency Avg | Latency P50 | Latency P99 | Total Requests (10s) |
47
- | :----------------------------- | :------------------- | :----------- | :----------- | :----------- | :------------------- |
48
- | **URLPattern Engine (Legacy)** | 9,904.6 RPS | 101.59 ms | 96.00 ms | 210.00 ms | 99k req |
49
- | **FetchWork Compiled Regex** | **14,336.8 RPS** | **69.89 ms** | **69.00 ms** | **91.00 ms** | **143k req** |
50
-
51
- > **Result:** Fast Compiled Regex engine delivers a **+44.7% throughput increase** and stabilizes peak P99 latency down to **91 ms**.
52
-
53
- ### 3. Middleware Chain Overhead
54
-
55
- _Accumulated overhead test comparing a clean route vs. 4 chained middlewares (Logger, CORS, Auth, Rate Limiter):_
56
-
57
- | Scenario | Throughput (Avg RPS) | Latency Avg | Latency P50 | Latency P99 | Throughput (MB/s) |
58
- | :-------------------------------- | :------------------- | :----------- | :----------- | :------------ | :---------------- |
59
- | **Clean Route (0 Middleware)** | 13,203.2 RPS | 76.06 ms | 70.00 ms | 154.00 ms | 1.93 MB/s |
60
- | **Chained Route (4 Middlewares)** | **12,803.2 RPS** | **78.68 ms** | **76.00 ms** | **120.00 ms** | **2.28 MB/s** |
61
-
62
- > **Result:** Running 4 chained middlewares results in less than **~3% throughput drop**, proving the efficiency of FetchWork's recursive dispatch pipeline.
51
+ > **Result:** Static and Wildcard rate limiting maintain high throughput (**12,700+ RPS**) while reliably managing penalty windows with less than 0.2% variance between static and regex matching.
63
52
 
64
53
  ---
65
54
 
@@ -78,11 +67,10 @@ bun add fetchwork
78
67
  import { FetchWork } from "fetchwork";
79
68
 
80
69
  const app = new FetchWork();
81
- let server: Bun.Server<undefined>;
82
70
 
83
71
  // Global Logger Middleware
84
72
  app.use(async (c, next) => {
85
- console.log(`[${c.req.method}] ${c.req.url}`);
73
+ console.log(`[${c.req.method}] ${c.path}`);
86
74
  return next();
87
75
  });
88
76
 
@@ -98,151 +86,194 @@ app.get("/:tenant/users/:userId", (c) => {
98
86
  return c.json({ tenant, userId });
99
87
  });
100
88
 
101
- // Start Server Native via Bun.serve
102
- server = Bun.serve({ port: 3000, fetch: app.fetch });
89
+ // Custom 404 Not Found Handler
90
+ app.notFound((c) => {
91
+ return c.json({ status: 404, error: "Custom Route Not Found" }, 404);
92
+ });
93
+
94
+ export default {
95
+ port: 3000,
96
+ fetch: app.fetch,
97
+ };
103
98
  ```
104
99
 
105
100
  ---
106
101
 
107
- ## Running Across Runtimes
102
+ ## Usage Guide
108
103
 
109
- Because FetchWork core is a pure `(req: Request) => Promise<Response>` handler, running it across different runtimes is completely seamless:
104
+ ### 1. CORS Middleware
110
105
 
111
- ### 1. Bun Adapter
106
+ Apply CORS globally or per route using the built-in `cors` middleware:
112
107
 
113
108
  ```typescript
114
109
  import { FetchWork } from "fetchwork";
115
- import { serveBun } from "fetchwork/adapters";
110
+ import { cors } from "fetchwork/cors";
116
111
 
117
112
  const app = new FetchWork();
118
- let server: Bun.Server<undefined>;
119
113
 
120
- app.get("/api", (c) => c.json({ runtime: "Bun" }));
121
-
122
- server = serveBun(app, { port: 3000 });
114
+ app.use(
115
+ cors({
116
+ origin: [
117
+ "[https://tinylink.dev](https://tinylink.dev)",
118
+ "[https://app.tinylink.dev](https://app.tinylink.dev)",
119
+ ],
120
+ credentials: true,
121
+ methods: ["GET", "POST", "PUT", "DELETE"],
122
+ allowedHeaders: ["Content-Type", "Authorization"],
123
+ maxAge: 86400,
124
+ }),
125
+ );
123
126
  ```
124
127
 
125
- ### 2. Cloudflare Workers / Edge
128
+ ### 2. Multi-Level Rate Limiter
129
+
130
+ Protect specific static or wildcard paths with level-based penalty windows (`FloodWait`):
126
131
 
127
132
  ```typescript
128
133
  import { FetchWork } from "fetchwork";
129
- import { serveCloudflare } from "fetchwork/adapters";
134
+ import { rateLimit } from "fetchwork/rate-limiter";
130
135
 
131
136
  const app = new FetchWork();
132
- app.get("/api", (c) => c.json({ runtime: "Cloudflare Workers" }));
133
137
 
134
- export default serveCloudflare(app);
138
+ // Rate limit specific static route
139
+ app.rateLimit(
140
+ "/api/v1/auth/login",
141
+ rateLimit({
142
+ keyPrefix: "auth-login",
143
+ limit: [5, 2], // Level 0: 5 reqs, Level 1+: 2 reqs
144
+ windowMs: { minutes: 1 },
145
+ floodwaitMs: [{ seconds: 30 }, { minutes: 5 }], // Penalties increase per violation level
146
+ }),
147
+ );
148
+
149
+ // Rate limit wildcard paths
150
+ app.rateLimit(
151
+ "/api/v1/data/*",
152
+ rateLimit({
153
+ keyPrefix: "api-data",
154
+ limit: 100,
155
+ windowMs: { minutes: 1 },
156
+ floodwaitMs: { minutes: 1 },
157
+ }),
158
+ );
135
159
  ```
136
160
 
137
- ### 3. Node.js Adapter
161
+ ### 3. Input Validation (Standard Schema)
162
+
163
+ Validate incoming payloads with Zod, Valibot, or ArkType using `validateSchema`:
138
164
 
139
165
  ```typescript
140
- import { FetchWork } from "fetchwork";
141
- import { serveNode } from "fetchwork/adapters";
166
+ import { z } from "zod";
167
+ import { validateSchema } from "fetchwork/validator";
142
168
 
143
- const app = new FetchWork();
144
- app.get("/api", (c) => c.json({ runtime: "Node.js" }));
169
+ const RegisterSchema = z.object({
170
+ name: z.string().min(2),
171
+ email: z.string().email(),
172
+ password: z.string().min(6),
173
+ });
145
174
 
146
- serveNode(app, { port: 3000 });
175
+ app.post(
176
+ "/api/v1/register",
177
+ validateSchema("body", RegisterSchema),
178
+ async (c) => {
179
+ const payload = c.validData?.body;
180
+ return c.json({ success: true, data: payload }, 201);
181
+ },
182
+ );
147
183
  ```
148
184
 
149
- ### 4. Vercel Adapter
150
-
151
- ```typescript
152
- import { FetchWork } from "fetchwork";
153
- import { serveVercel } from "fetchwork/adapters";
185
+ ### 4. Server-Sent Events (SSE)
154
186
 
155
- const app = new FetchWork();
156
- app.get("/api", (c) => c.json({ runtime: "Vercel Serverless" }));
187
+ Stream real-time updates seamlessly with non-blocking `c.sse()`:
157
188
 
158
- export default serveVercel(app, { port: 3000 });
189
+ ```typescript
190
+ app.get("/api/v1/stream", (c) => {
191
+ c.timeout(0);
192
+
193
+ return c.sse(async (sse) => {
194
+ // Send initial handshake
195
+ await sse.send({
196
+ event: "connected",
197
+ data: { status: "online" },
198
+ });
199
+
200
+ // Push periodic updates
201
+ const interval = setInterval(async () => {
202
+ await sse.send({
203
+ event: "ping",
204
+ data: { time: Date.now() },
205
+ });
206
+ }, 1000);
207
+
208
+ // Clean up when client disconnects
209
+ c.req.signal.addEventListener("abort", () => {
210
+ clearInterval(interval);
211
+ });
212
+ });
213
+ });
159
214
  ```
160
215
 
161
216
  ---
162
217
 
163
- ## Modular Routing & Prefixes
218
+ ## Running Across Runtimes
164
219
 
165
- Organize your codebase cleanly using `app.route()` with path prefixes (e.g., `/api`):
220
+ FetchWork core uses standard W3C interfaces, allowing it to run across any modern JS runtime:
166
221
 
167
- ```typescript
168
- // src/routes/user.router.ts
169
- import type { FetchWork } from "fetchwork";
170
-
171
- export function registerUserRoutes(app: FetchWork) {
172
- app.get("/users/me", (c) => c.json({ user: "Ayiin" }));
173
- app.post("/users", async (c) => {
174
- const body = await c.reqBody();
175
- return c.json({ created: true, data: body }, 201);
176
- });
177
- }
178
- ```
222
+ ### Bun Adapter
179
223
 
180
224
  ```typescript
181
- // src/index.ts
182
225
  import { FetchWork } from "fetchwork";
183
- import { registerUserRoutes } from "./routes/user.router";
226
+ import { serveBun } from "fetchwork/adapters";
184
227
 
185
228
  const app = new FetchWork();
229
+ app.get("/api", (c) => c.json({ runtime: "Bun" }));
186
230
 
187
- // Mount all user routes under the /api prefix (/api/users/me, /api/users)
188
- app.route("/api", registerUserRoutes);
189
-
190
- export default {
191
- port: 3000,
192
- fetch: app.fetch,
193
- };
231
+ serveBun(app, { port: 3000 });
194
232
  ```
195
233
 
196
- ---
197
-
198
- ## Input Validation (Zod)
199
-
200
- Validate request bodies, query params, or URL params seamlessly before executing controllers:
234
+ ### Cloudflare Workers
201
235
 
202
236
  ```typescript
203
- import { z } from "zod";
204
- import { validator } from "fetchwork/validator";
237
+ import { FetchWork } from "fetchwork";
238
+ import { serveCloudflare } from "fetchwork/adapters";
205
239
 
206
- const CreateUserSchema = z.object({
207
- name: z.string(),
208
- email: z.string().email(),
209
- });
240
+ const app = new FetchWork();
241
+ app.get("/api", (c) => c.json({ runtime: "Cloudflare Workers" }));
210
242
 
211
- app.post({
212
- path: "/users",
213
- validator: validator("body", CreateUserSchema),
214
- controller: (c) => {
215
- // Validated data is fully typed
216
- const payload = c.validData?.body;
217
- return c.json({ success: true, data: payload }, 201);
218
- },
219
- });
243
+ export default serveCloudflare(app);
220
244
  ```
221
245
 
222
246
  ---
223
247
 
224
- ## Development & Building
248
+ ## **FetchWork Progress Checklist**
225
249
 
226
- To contribute or build the package locally:
250
+ **Core & Routing**
227
251
 
228
- ```bash
229
- # Install dependencies
230
- bun install
252
+ - [x] **High-Performance Router**: Static $O(1)$ map lookups and single-pass compiled regex matching.
253
+ - [x] **W3C Standard Context**: Native `Context` abstraction built on standard `Request` and `Response`.
254
+ - [x] **Scoped Routing / Prefixing**: Modular route prefixing via `app.route('/v1', ...)`.
255
+ - [x] **Flexible Error Handling**: Exception management via `app.onError()`.
256
+ - [x] **Custom Not Found Handler**: `app.notFound()` with zero latency penalty on hot paths.
231
257
 
232
- # Run example server
233
- bun run example/server.ts
258
+ **Type Safety & DX**
234
259
 
235
- # Run benchmark tests
236
- bun run benchmark/dynamic.ts
237
- bun run benchmark/middleware.ts
260
+ - [x] **Standard Schema Interoperability**: Validation support for `body`, `query`, `params`, and `headers` via `validateSchema()`.
261
+ - [x] **Route Parameter Inferencing**: Automatic type inferencing for `c.params`.
238
262
 
239
- # Build ESM, CJS, and .d.ts files into dist/
240
- bun run build
263
+ **Streaming & Real-Time Utilities**
241
264
 
242
- ```
265
+ - [x] **Ultra-Low Latency SSE**: `c.sse()` helper powered by `TransformStream` with zero proxy buffering.
266
+ - [ ] **WebSockets Adapter**: Light abstraction for bidirectional WebSocket connections.
267
+
268
+ **Security & Production Ready**
269
+
270
+ - [x] **Built-in CORS Helper**: Optimized CORS middleware supporting static and $O(1)$ set matching.
271
+ - [x] **Multi-Level Rate Limiter**: Path-based `FloodWait` rate limiter (`app.rateLimit()`).
272
+ - [x] **OpenAPI / Swagger Generator**: Automatic OpenAPI doc generator reading route metadata and schemas.
273
+ - [x] **Body Size Limits**: Memory protection for large `reqBody()` payloads.
243
274
 
244
275
  ---
245
276
 
246
277
  ## License
247
278
 
248
- [MIT](.\LICENSE) © Ayiin
279
+ [MIT](https://www.google.com/search?q=./LICENSE) © Ayiin
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/bun.ts"],
4
4
  "sourcesContent": [
5
- "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch, // Mengakses Web Standard Fetch Handler dari FetchWork\n });\n\n return server;\n}\n"
5
+ "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch,\n });\n\n return server;\n}\n"
6
6
  ],
7
7
  "mappings": "y/BAOO,SAAS,CAAQ,CAAC,EAAgB,EAA6B,CACpE,IAAM,EAAgB,WAEtB,GAAI,CAAC,EAAc,IACjB,MAAU,MAAM,+BAA+B,EAQjD,OALe,EAAc,IAAI,MAAM,IAClC,EACH,MAAO,EAAI,KACb,CAAC",
8
8
  "debugId": "2A336670799FDA3264756E2164756E21",
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/bun.ts"],
4
4
  "sourcesContent": [
5
- "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch, // Mengakses Web Standard Fetch Handler dari FetchWork\n });\n\n return server;\n}\n"
5
+ "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch,\n });\n\n return server;\n}\n"
6
6
  ],
7
7
  "mappings": ";AAOO,SAAS,CAAQ,CAAC,EAAgB,EAA6B,CACpE,IAAM,EAAgB,WAEtB,GAAI,CAAC,EAAc,IACjB,MAAU,MAAM,+BAA+B,EAQjD,OALe,EAAc,IAAI,MAAM,IAClC,EACH,MAAO,EAAI,KACb,CAAC",
8
8
  "debugId": "DD099E0E78AD86B064756E2164756E21",
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/adapters/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,OAAO,EACZ,GAAG,CAAC,EAAE,aAAa,EACnB,GAAG,CAAC,EAAE,gBAAgB,KACnB,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS;IAE1C,KAAK,QACE,OAAO,QACN,aAAa,QACb,gBAAgB,KACrB,OAAO,CAAC,QAAQ,CAAC;EAKvB"}
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/adapters/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvC,sBAAsB,IAAI,IAAI,CAAC;CAChC;AAED,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,OAAO,EACZ,GAAG,CAAC,EAAE,aAAa,EACnB,GAAG,CAAC,EAAE,gBAAgB,KACnB,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS;IAE1C,KAAK,QACE,OAAO,QACN,aAAa,QACb,gBAAgB,KACrB,OAAO,CAAC,QAAQ,CAAC;EAIvB"}
@@ -2,12 +2,12 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/bun.ts", "../src/adapters/cloudflare.ts", "../src/adapters/node.ts", "../src/adapters/vercel.ts"],
4
4
  "sourcesContent": [
5
- "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch, // Mengakses Web Standard Fetch Handler dari FetchWork\n });\n\n return server;\n}\n",
6
- "import type { FetchWork } from \"..\";\n\nexport interface CloudflareEnv {\n [key: string]: any;\n}\n\nexport interface ExecutionContext {\n waitUntil(promise: Promise<any>): void;\n passThroughOnException(): void;\n}\n\nexport type CloudflareHandler = (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n) => Promise<Response>;\n\n/**\n * Adapter untuk menjalankan FetchWork di Cloudflare Workers / Pages Functions\n */\nexport function serveCloudflare(app: FetchWork) {\n return {\n fetch: async (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n ): Promise<Response> => {\n // Menjalankan fetch handler W3C bawaan FetchWork\n return app.fetch(req, env, ctx);\n },\n };\n}\n",
7
- "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n // Panggil FetchWork Handler\n const webRes = await app.fetch(webReq);\n\n // Kirim Web Standard Response balik ke ServerResponse Node\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n",
8
- "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n // 1. Jika dipanggil dengan Web Standard Fetch API (misal: export const GET = handleVercel(app))\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n // 2. Jika dipanggil dengan Node.js Classic Signature (misal: export default handleVercel(app))\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Normalisasi Body untuk Request Web Standard\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n // Eksekusi aplikasi FetchWork\n const webRes = await app.fetch(webReq);\n\n // Set status code dan headers ke objek response Node.js\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n // Alirkan response body ke res\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
5
+ "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch,\n });\n\n return server;\n}\n",
6
+ "import type { FetchWork } from \"..\";\n\nexport interface CloudflareEnv {\n [key: string]: any;\n}\n\nexport interface ExecutionContext {\n waitUntil(promise: Promise<any>): void;\n passThroughOnException(): void;\n}\n\nexport type CloudflareHandler = (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n) => Promise<Response>;\n\n/**\n * Adapter untuk menjalankan FetchWork di Cloudflare Workers / Pages Functions\n */\nexport function serveCloudflare(app: FetchWork) {\n return {\n fetch: async (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n ): Promise<Response> => {\n return app.fetch(req, env, ctx);\n },\n };\n}\n",
7
+ "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n",
8
+ "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
9
9
  ],
10
- "mappings": "kpCAOO,SAAS,CAAQ,CAAC,EAAgB,EAA6B,CACpE,IAAM,EAAgB,WAEtB,GAAI,CAAC,EAAc,IACjB,MAAU,MAAM,+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wB,YACxB,IAAO,EAAI,MAEpC,EAAY,KAChB,GAAI,CAAC,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAC5C,GAAI,OAAO,EAAI,OAAS,UAAY,OAAO,SAAS,EAAI,IAAI,EAC1D,EAAO,EAAI,KACN,QAAI,EAAI,MAAQ,OAAO,EAAI,OAAS,SACzC,EAAO,KAAK,UAAU,EAAI,IAAI,EAE9B,OAAO,EAIX,IAAM,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,OAEA,OAAQ,MACV,CAAC,EAEK,EAAS,MAAM,EAAI,MAAM,CAAM,EAOrC,GALA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAInB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,GAAI,CAAC,EAAI,YACP,EAAI,WAAa,IAEnB,EAAI,IAAI,uBAAuB,EAEjC,OAGF,MAAU,MACR,2DACF",
11
11
  "debugId": "64942FBF5FD39F0364756E2164756E21",
12
12
  "names": []
13
13
  }
@@ -2,12 +2,12 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/bun.ts", "../src/adapters/cloudflare.ts", "../src/adapters/node.ts", "../src/adapters/vercel.ts"],
4
4
  "sourcesContent": [
5
- "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch, // Mengakses Web Standard Fetch Handler dari FetchWork\n });\n\n return server;\n}\n",
6
- "import type { FetchWork } from \"..\";\n\nexport interface CloudflareEnv {\n [key: string]: any;\n}\n\nexport interface ExecutionContext {\n waitUntil(promise: Promise<any>): void;\n passThroughOnException(): void;\n}\n\nexport type CloudflareHandler = (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n) => Promise<Response>;\n\n/**\n * Adapter untuk menjalankan FetchWork di Cloudflare Workers / Pages Functions\n */\nexport function serveCloudflare(app: FetchWork) {\n return {\n fetch: async (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n ): Promise<Response> => {\n // Menjalankan fetch handler W3C bawaan FetchWork\n return app.fetch(req, env, ctx);\n },\n };\n}\n",
7
- "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n // Panggil FetchWork Handler\n const webRes = await app.fetch(webReq);\n\n // Kirim Web Standard Response balik ke ServerResponse Node\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n",
8
- "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n // 1. Jika dipanggil dengan Web Standard Fetch API (misal: export const GET = handleVercel(app))\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n // 2. Jika dipanggil dengan Node.js Classic Signature (misal: export default handleVercel(app))\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Normalisasi Body untuk Request Web Standard\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n // Eksekusi aplikasi FetchWork\n const webRes = await app.fetch(webReq);\n\n // Set status code dan headers ke objek response Node.js\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n // Alirkan response body ke res\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
5
+ "import type { FetchWork } from \"../index\";\n\ntype CustomServeOptions = Omit<\n Bun.Serve.Options<undefined>,\n \"fetch\" | \"websocket\" | \"routes\" | \"error\"\n>;\n\nexport function serveBun(app: FetchWork, options: CustomServeOptions) {\n const globalRuntime = globalThis as any;\n\n if (!globalRuntime.Bun) {\n throw new Error(\"Runtime Bun tidak terdeteksi.\");\n }\n\n const server = globalRuntime.Bun.serve({\n ...options,\n fetch: app.fetch,\n });\n\n return server;\n}\n",
6
+ "import type { FetchWork } from \"..\";\n\nexport interface CloudflareEnv {\n [key: string]: any;\n}\n\nexport interface ExecutionContext {\n waitUntil(promise: Promise<any>): void;\n passThroughOnException(): void;\n}\n\nexport type CloudflareHandler = (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n) => Promise<Response>;\n\n/**\n * Adapter untuk menjalankan FetchWork di Cloudflare Workers / Pages Functions\n */\nexport function serveCloudflare(app: FetchWork) {\n return {\n fetch: async (\n req: Request,\n env?: CloudflareEnv,\n ctx?: ExecutionContext,\n ): Promise<Response> => {\n return app.fetch(req, env, ctx);\n },\n };\n}\n",
7
+ "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n",
8
+ "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
9
9
  ],
10
- "mappings": ";AAOO,SAAS,CAAQ,CAAC,EAAgB,EAA6B,CACpE,IAAM,EAAgB,WAEtB,GAAI,CAAC,EAAc,IACjB,MAAU,MAAM,+BAA+B,EAQjD,OALe,EAAc,IAAI,MAAM,IAClC,EACH,MAAO,EAAI,KACb,CAAC,ECGI,SAAS,CAAe,CAAC,EAAgB,CAC9C,MAAO,CACL,MAAO,MACL,EACA,EACA,IAGO,EAAI,MAAM,EAAK,EAAK,CAAG,CAElC,EC9BF,oBACA,qBASO,SAAS,CAAS,CAAC,EAAgB,EAA2B,CACnE,IAAM,EAAwC,MAAO,EAAK,IAAQ,CAChE,GAAI,CACF,IAAM,EAAW,EAAQ,IAAM,QAAU,OACnC,EAAO,EAAI,QAAQ,MAAQ,YAC3B,EAAM,GAAG,OAAc,IAAO,EAAI,MAGlC,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,KAAM,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAAI,KAAQ,EAC3D,OAAQ,MACV,CAAgB,EAGV,EAAS,MAAM,EAAI,MAAM,CAAM,EAQrC,GALA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAGnB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,EAAI,WAAa,IACjB,EAAI,IAAI,uBAAuB,IAI7B,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EAA+B,CACzD,OAAO,cAA4B,CAAC,EAAU,EAAyB,CACrE,GACE,aAAe,SACd,GAAO,OAAO,EAAI,cAAgB,YAAc,CAAC,EAElD,OAAO,EAAI,MAAM,CAAG,EAGtB,GAAI,GAAO,OAAO,EAAI,YAAc,WAAY,CAC9C,GAAI,CACF,IAAM,EAAO,EAAI,QAAQ,MAAQ,YAE3B,EAAM,GADK,EAAI,QAAQ,sBAAwB,YACxB,IAAO,EAAI,MAEpC,EAAY,KAChB,GAAI,CAAC,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAC5C,GAAI,OAAO,EAAI,OAAS,UAAY,OAAO,SAAS,EAAI,IAAI,EAC1D,EAAO,EAAI,KACN,QAAI,EAAI,MAAQ,OAAO,EAAI,OAAS,SACzC,EAAO,KAAK,UAAU,EAAI,IAAI,EAE9B,OAAO,EAIX,IAAM,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,OAEA,OAAQ,MACV,CAAC,EAEK,EAAS,MAAM,EAAI,MAAM,CAAM,EAOrC,GALA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAInB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,GAAI,CAAC,EAAI,YACP,EAAI,WAAa,IAEnB,EAAI,IAAI,uBAAuB,EAEjC,OAGF,MAAU,MACR,2DACF",
11
11
  "debugId": "3C6780C371BF7B6C64756E2164756E21",
12
12
  "names": []
13
13
  }
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/node.ts"],
4
4
  "sourcesContent": [
5
- "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n // Panggil FetchWork Handler\n const webRes = await app.fetch(webReq);\n\n // Kirim Web Standard Response balik ke ServerResponse Node\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n"
5
+ "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n"
6
6
  ],
7
- "mappings": "0/BAAiB,IAAjB,4BACA,6BASO,SAAS,CAAS,CAAC,EAAgB,EAA2B,CACnE,IAAM,EAAwC,MAAO,EAAK,IAAQ,CAChE,GAAI,CACF,IAAM,EAAW,EAAQ,IAAM,QAAU,OACnC,EAAO,EAAI,QAAQ,MAAQ,YAC3B,EAAM,GAAG,OAAc,IAAO,EAAI,MAGlC,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,KAAM,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAAI,KAAQ,EAC3D,OAAQ,MACV,CAAgB,EAGV,EAAS,MAAM,EAAI,MAAM,CAAM,EAQrC,GALA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAGnB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,EAAI,WAAa,IACjB,EAAI,IAAI,uBAAuB,IAI7B,EAAS,EAAQ,IACnB,UAAM,aAAa,EAAQ,IAAK,CAAe,EAC/C,UAAK,aAAa,CAAe,EAGrC,OADA,EAAO,OAAO,EAAQ,KAAM,EAAQ,QAAQ,EACrC",
7
+ "mappings": "0/BAAiB,IAAjB,4BACA,6BASO,SAAS,CAAS,CAAC,EAAgB,EAA2B,CACnE,IAAM,EAAwC,MAAO,EAAK,IAAQ,CAChE,GAAI,CACF,IAAM,EAAW,EAAQ,IAAM,QAAU,OACnC,EAAO,EAAI,QAAQ,MAAQ,YAC3B,EAAM,GAAG,OAAc,IAAO,EAAI,MAGlC,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,KAAM,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAAI,KAAQ,EAC3D,OAAQ,MACV,CAAgB,EAEV,EAAS,MAAM,EAAI,MAAM,CAAM,EAOrC,GALA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAGnB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,EAAI,WAAa,IACjB,EAAI,IAAI,uBAAuB,IAI7B,EAAS,EAAQ,IACnB,UAAM,aAAa,EAAQ,IAAK,CAAe,EAC/C,UAAK,aAAa,CAAe,EAGrC,OADA,EAAO,OAAO,EAAQ,KAAM,EAAQ,QAAQ,EACrC",
8
8
  "debugId": "AEF7EA4D2826799964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/adapters/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC3B,CAAC;AAEF,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,wEA6ClE"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/adapters/node.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC3B,CAAC;AAEF,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,wEA2ClE"}
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/node.ts"],
4
4
  "sourcesContent": [
5
- "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n // Panggil FetchWork Handler\n const webRes = await app.fetch(webReq);\n\n // Kirim Web Standard Response balik ke ServerResponse Node\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n"
5
+ "import http from \"node:http\";\nimport https from \"node:https\";\nimport type { FetchWork } from \"..\";\n\nexport type NodeServeOptions = {\n port: number;\n hostname?: string;\n tls?: https.ServerOptions;\n};\n\nexport function serveNode(app: FetchWork, options: NodeServeOptions) {\n const requestListener: http.RequestListener = async (req, res) => {\n try {\n const protocol = options.tls ? \"https\" : \"http\";\n const host = req.headers.host || \"localhost\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Tambahkan `as RequestInit` di akhir objek opsi\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body: [\"GET\", \"HEAD\"].includes(req.method || \"\") ? null : (req as any),\n duplex: \"half\",\n } as RequestInit);\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n res.end();\n } catch (err) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n };\n\n const server = options.tls\n ? https.createServer(options.tls, requestListener)\n : http.createServer(requestListener);\n\n server.listen(options.port, options.hostname);\n return server;\n}\n"
6
6
  ],
7
- "mappings": ";AAAA,oBACA,qBASO,SAAS,CAAS,CAAC,EAAgB,EAA2B,CACnE,IAAM,EAAwC,MAAO,EAAK,IAAQ,CAChE,GAAI,CACF,IAAM,EAAW,EAAQ,IAAM,QAAU,OACnC,EAAO,EAAI,QAAQ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AAO,IAAQ,CACrC,EAAI,UAAU,EAAK,CAAK,EACzB,EAEG,EAAO,KAAM,CACf,IAAM,EAAS,EAAO,KAAK,UAAU,EACrC,MAAO,GAAM,CACX,IAAQ,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAGnB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,EAAI,WAAa,IACjB,EAAI,IAAI,uBAAuB,IAI7B,EAAS,EAAQ,IACnB,EAAM,aAAa,EAAQ,IAAK,CAAe,EAC/C,EAAK,aAAa,CAAe,EAGrC,OADA,EAAO,OAAO,EAAQ,KAAM,EAAQ,QAAQ,EACrC",
8
8
  "debugId": "E6E1BAA6ACA9DAB264756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/vercel.ts"],
4
4
  "sourcesContent": [
5
- "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n // 1. Jika dipanggil dengan Web Standard Fetch API (misal: export const GET = handleVercel(app))\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n // 2. Jika dipanggil dengan Node.js Classic Signature (misal: export default handleVercel(app))\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n // Normalisasi Body untuk Request Web Standard\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n // Eksekusi aplikasi FetchWork\n const webRes = await app.fetch(webReq);\n\n // Set status code dan headers ke objek response Node.js\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n // Alirkan response body ke res\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
5
+ "import type { FetchWork } from \"..\";\n\nexport type VercelHandler = {\n (req: Request): Promise<Response>;\n (req: any, res: any): Promise<void>;\n};\n\n/**\n * Adapter serveVercel hybrid\n * Mendukung Web Standard Request/Response (App Router / Edge)\n * sekaligus Node.js (req, res) Serverless Functions (Pages Router / api/*.ts)\n */\nexport function serveVercel(app: FetchWork): VercelHandler {\n return async function vercelAdapter(req: any, res?: any): Promise<any> {\n if (\n req instanceof Request ||\n (req && typeof req.arrayBuffer === \"function\" && !res)\n ) {\n return app.fetch(req);\n }\n\n if (res && typeof res.setHeader === \"function\") {\n try {\n const host = req.headers.host || \"localhost\";\n const protocol = req.headers[\"x-forwarded-proto\"] || \"http\";\n const url = `${protocol}://${host}${req.url}`;\n\n let body: any = null;\n if (![\"GET\", \"HEAD\"].includes(req.method || \"\")) {\n if (typeof req.body === \"string\" || Buffer.isBuffer(req.body)) {\n body = req.body;\n } else if (req.body && typeof req.body === \"object\") {\n body = JSON.stringify(req.body);\n } else {\n body = req;\n }\n }\n\n const webReq = new Request(url, {\n method: req.method,\n headers: req.headers as Record<string, string>,\n body,\n // @ts-ignore - duplex dibutuhkan untuk Node.js streaming request body\n duplex: \"half\",\n });\n\n const webRes = await app.fetch(webReq);\n\n res.statusCode = webRes.status;\n webRes.headers.forEach((value, key) => {\n res.setHeader(key, value);\n });\n\n if (webRes.body) {\n const reader = webRes.body.getReader();\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n res.write(value);\n }\n }\n\n res.end();\n } catch (err) {\n if (!res.headersSent) {\n res.statusCode = 500;\n }\n res.end(\"Internal Server Error\");\n }\n return;\n }\n\n throw new Error(\n \"Invalid request/response arguments passed to handleVercel\",\n );\n } as VercelHandler;\n}\n"
6
6
  ],
7
- "mappings": "4/BAYO,SAAS,CAAW,CAAC,EAA+B,CACzD,OAAO,cAA4B,CAAC,EAAU,EAAyB,CAErE,GACE,aAAe,SACd,GAAO,OAAO,EAAI,cAAgB,YAAc,CAAC,EAElD,OAAO,EAAI,MAAM,CAAG,EAItB,GAAI,GAAO,OAAO,EAAI,YAAc,WAAY,CAC9C,GAAI,CACF,IAAM,EAAO,EAAI,QAAQ,MAAQ,YAE3B,EAAM,GADK,EAAI,QAAQ,sBAAwB,YACxB,IAAO,EAAI,MAGpC,EAAY,KAChB,GAAI,CAAC,CAAC,MAAO,MAAM,EAAE,SAAS,EAAI,QAAU,EAAE,EAC5C,GAAI,OAAO,EAAI,OAAS,UAAY,OAAO,SAAS,EAAI,IAAI,EAC1D,EAAO,EAAI,KACN,QAAI,EAAI,MAAQ,OAAO,EAAI,OAAS,SACzC,EAAO,KAAK,UAAU,EAAI,IAAI,EAE9B,OAAO,EAIX,IAAM,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,OAEA,OAAQ,MACV,CAAC,EAGK,EAAS,MAAM,EAAI,MAAM,CAAM,EASrC,GANA,EAAI,WAAa,EAAO,OACxB,EAAO,QAAQ,QAAQ,CAAC,EAAO,IAAQ,CAC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Q,OAAM,SAAU,MAAM,EAAO,KAAK,EAC1C,GAAI,EAAM,MACV,EAAI,MAAM,CAAK,GAInB,EAAI,IAAI,EACR,MAAO,EAAK,CACZ,GAAI,CAAC,EAAI,YACP,EAAI,WAAa,IAEnB,EAAI,IAAI,uBAAuB,EAEjC,OAGF,MAAU,MACR,2DACF",
8
8
  "debugId": "5892A35B9E12186464756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../src/adapters/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,GAAG,aAAa,CAsEzD"}
1
+ {"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../src/adapters/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG;IAC1B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,GAAG,aAAa,CAgEzD"}