fetchwork 1.0.9 → 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 +153 -113
- package/dist/adapters/bun.cjs.map +1 -1
- package/dist/adapters/bun.mjs.map +1 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/index.cjs +2 -2
- package/dist/adapters/index.cjs.map +6 -6
- package/dist/adapters/index.mjs +2 -2
- package/dist/adapters/index.mjs.map +6 -6
- package/dist/adapters/node.cjs.map +2 -2
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.mjs.map +2 -2
- package/dist/adapters/vercel.cjs.map +2 -2
- package/dist/adapters/vercel.d.ts.map +1 -1
- package/dist/adapters/vercel.mjs.map +2 -2
- package/dist/context.d.ts +4 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/index.cjs +8 -3
- package/dist/index.cjs.map +12 -9
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +12 -9
- package/dist/middlewares/bodyLimit.d.ts +11 -0
- package/dist/middlewares/bodyLimit.d.ts.map +1 -0
- package/dist/middlewares/bodyParser.d.ts.map +1 -1
- package/dist/middlewares/docs.d.ts.map +1 -1
- package/dist/middlewares/index.d.ts +2 -0
- package/dist/middlewares/index.d.ts.map +1 -1
- package/dist/middlewares/rateLimiter.d.ts +40 -0
- package/dist/middlewares/rateLimiter.d.ts.map +1 -0
- package/dist/middlewares/validator.d.ts +27 -4
- package/dist/middlewares/validator.d.ts.map +1 -1
- package/dist/sse.d.ts +17 -0
- package/dist/sse.d.ts.map +1 -0
- package/package.json +1 -1
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
|
|
16
|
-
- **Fast Compiled Regex Engine**: High-performance $O(1)$ `Map` lookups for static routes and single-pass compiled regex matching for dynamic routes
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
22
|
-
- **Multi-Runtime Ready**:
|
|
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.
|
|
30
|
+
### 1. Complete Feature Suite Performance (`bench-all`)
|
|
31
31
|
|
|
32
|
-
_Comparing
|
|
32
|
+
_Comparing performance across core framework features under heavy load:_
|
|
33
33
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
| **
|
|
37
|
-
| **
|
|
38
|
-
| **
|
|
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
|
-
|
|
41
|
+
### 2. Multi-Level Rate Limiter Throughput
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
_Throughput evaluation when rate limiting is applied across static and wildcard paths:_
|
|
43
44
|
|
|
44
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -81,7 +70,7 @@ const app = new FetchWork();
|
|
|
81
70
|
|
|
82
71
|
// Global Logger Middleware
|
|
83
72
|
app.use(async (c, next) => {
|
|
84
|
-
console.log(`[${c.req.method}] ${c.
|
|
73
|
+
console.log(`[${c.req.method}] ${c.path}`);
|
|
85
74
|
return next();
|
|
86
75
|
});
|
|
87
76
|
|
|
@@ -97,7 +86,11 @@ app.get("/:tenant/users/:userId", (c) => {
|
|
|
97
86
|
return c.json({ tenant, userId });
|
|
98
87
|
});
|
|
99
88
|
|
|
100
|
-
//
|
|
89
|
+
// Custom 404 Not Found Handler
|
|
90
|
+
app.notFound((c) => {
|
|
91
|
+
return c.json({ status: 404, error: "Custom Route Not Found" }, 404);
|
|
92
|
+
});
|
|
93
|
+
|
|
101
94
|
export default {
|
|
102
95
|
port: 3000,
|
|
103
96
|
fetch: app.fetch,
|
|
@@ -106,134 +99,181 @@ export default {
|
|
|
106
99
|
|
|
107
100
|
---
|
|
108
101
|
|
|
109
|
-
##
|
|
102
|
+
## Usage Guide
|
|
110
103
|
|
|
111
|
-
|
|
104
|
+
### 1. CORS Middleware
|
|
112
105
|
|
|
113
|
-
|
|
106
|
+
Apply CORS globally or per route using the built-in `cors` middleware:
|
|
114
107
|
|
|
115
108
|
```typescript
|
|
116
109
|
import { FetchWork } from "fetchwork";
|
|
110
|
+
import { cors } from "fetchwork/cors";
|
|
117
111
|
|
|
118
112
|
const app = new FetchWork();
|
|
119
|
-
app.get("/api", (c) => c.json({ runtime: "Bun" }));
|
|
120
113
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
);
|
|
125
126
|
```
|
|
126
127
|
|
|
127
|
-
### 2.
|
|
128
|
+
### 2. Multi-Level Rate Limiter
|
|
129
|
+
|
|
130
|
+
Protect specific static or wildcard paths with level-based penalty windows (`FloodWait`):
|
|
128
131
|
|
|
129
132
|
```typescript
|
|
130
133
|
import { FetchWork } from "fetchwork";
|
|
134
|
+
import { rateLimit } from "fetchwork/rate-limiter";
|
|
131
135
|
|
|
132
136
|
const app = new FetchWork();
|
|
133
|
-
app.get("/api", (c) => c.json({ runtime: "Cloudflare Workers" }));
|
|
134
137
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
);
|
|
138
159
|
```
|
|
139
160
|
|
|
140
|
-
### 3.
|
|
161
|
+
### 3. Input Validation (Standard Schema)
|
|
162
|
+
|
|
163
|
+
Validate incoming payloads with Zod, Valibot, or ArkType using `validateSchema`:
|
|
141
164
|
|
|
142
165
|
```typescript
|
|
143
|
-
import {
|
|
144
|
-
import {
|
|
166
|
+
import { z } from "zod";
|
|
167
|
+
import { validateSchema } from "fetchwork/validator";
|
|
145
168
|
|
|
146
|
-
const
|
|
147
|
-
|
|
169
|
+
const RegisterSchema = z.object({
|
|
170
|
+
name: z.string().min(2),
|
|
171
|
+
email: z.string().email(),
|
|
172
|
+
password: z.string().min(6),
|
|
173
|
+
});
|
|
148
174
|
|
|
149
|
-
|
|
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
|
+
);
|
|
150
183
|
```
|
|
151
184
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
## Modular Routing & Prefixes
|
|
185
|
+
### 4. Server-Sent Events (SSE)
|
|
155
186
|
|
|
156
|
-
|
|
187
|
+
Stream real-time updates seamlessly with non-blocking `c.sse()`:
|
|
157
188
|
|
|
158
189
|
```typescript
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
});
|
|
167
212
|
});
|
|
168
|
-
}
|
|
213
|
+
});
|
|
169
214
|
```
|
|
170
215
|
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Running Across Runtimes
|
|
219
|
+
|
|
220
|
+
FetchWork core uses standard W3C interfaces, allowing it to run across any modern JS runtime:
|
|
221
|
+
|
|
222
|
+
### Bun Adapter
|
|
223
|
+
|
|
171
224
|
```typescript
|
|
172
|
-
// src/index.ts
|
|
173
225
|
import { FetchWork } from "fetchwork";
|
|
174
|
-
import {
|
|
226
|
+
import { serveBun } from "fetchwork/adapters";
|
|
175
227
|
|
|
176
228
|
const app = new FetchWork();
|
|
229
|
+
app.get("/api", (c) => c.json({ runtime: "Bun" }));
|
|
177
230
|
|
|
178
|
-
|
|
179
|
-
app.route("/api", registerUserRoutes);
|
|
180
|
-
|
|
181
|
-
export default {
|
|
182
|
-
port: 3000,
|
|
183
|
-
fetch: app.fetch,
|
|
184
|
-
};
|
|
231
|
+
serveBun(app, { port: 3000 });
|
|
185
232
|
```
|
|
186
233
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
## Input Validation (Zod)
|
|
190
|
-
|
|
191
|
-
Validate request bodies, query params, or URL params seamlessly before executing controllers:
|
|
234
|
+
### Cloudflare Workers
|
|
192
235
|
|
|
193
236
|
```typescript
|
|
194
|
-
import {
|
|
195
|
-
import {
|
|
237
|
+
import { FetchWork } from "fetchwork";
|
|
238
|
+
import { serveCloudflare } from "fetchwork/adapters";
|
|
196
239
|
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
email: z.string().email(),
|
|
200
|
-
});
|
|
240
|
+
const app = new FetchWork();
|
|
241
|
+
app.get("/api", (c) => c.json({ runtime: "Cloudflare Workers" }));
|
|
201
242
|
|
|
202
|
-
app
|
|
203
|
-
path: "/users",
|
|
204
|
-
validator: zValidator("body", CreateUserSchema),
|
|
205
|
-
controller: (c) => {
|
|
206
|
-
// Validated data is fully typed
|
|
207
|
-
const payload = c.validData?.body;
|
|
208
|
-
return c.json({ success: true, data: payload }, 201);
|
|
209
|
-
},
|
|
210
|
-
});
|
|
243
|
+
export default serveCloudflare(app);
|
|
211
244
|
```
|
|
212
245
|
|
|
213
246
|
---
|
|
214
247
|
|
|
215
|
-
##
|
|
248
|
+
## **FetchWork Progress Checklist**
|
|
216
249
|
|
|
217
|
-
|
|
250
|
+
**Core & Routing**
|
|
218
251
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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.
|
|
222
257
|
|
|
223
|
-
|
|
224
|
-
bun run example/server.ts
|
|
258
|
+
**Type Safety & DX**
|
|
225
259
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
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`.
|
|
229
262
|
|
|
230
|
-
|
|
231
|
-
bun run build
|
|
263
|
+
**Streaming & Real-Time Utilities**
|
|
232
264
|
|
|
233
|
-
|
|
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.
|
|
234
274
|
|
|
235
275
|
---
|
|
236
276
|
|
|
237
277
|
## License
|
|
238
278
|
|
|
239
|
-
[MIT](
|
|
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
|
|
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
|
|
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;
|
|
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"}
|
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var H=Object.create;var{getPrototypeOf:O,defineProperty:f,getOwnPropertyNames:x,getOwnPropertyDescriptor:B}=Object,m=Object.prototype.hasOwnProperty;function b(e){return this[e]}var F,W,w=(e,r,t)=>{var o=e!=null&&typeof e==="object";if(o){var n=r?F??=new WeakMap:W??=new WeakMap,s=n.get(e);if(s)return s}t=e!=null?H(O(e)):{};let d=r||!e||!e.__esModule||!m.call(e,"default")?f(t,"default",{value:e,enumerable:!0}):t;if(e&&typeof e==="object"||typeof e==="function"){for(let a of x(e))if(!m.call(d,a))f(d,a,{get:b.bind(e,a),enumerable:!0})}if(o)n.set(e,d);return d},h=(e)=>{var r=(v??=new WeakMap).get(e),t;if(r)return r;if(r=f({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var o of x(e))if(!m.call(r,o))f(r,o,{get:b.bind(e,o),enumerable:!(t=B(e,o))||t.enumerable})}return v.set(e,r),r},v;var P=(e)=>e;function V(e,r){this[e]=P.bind(null,r)}var p=(e,r)=>{for(var t in r)f(e,t,{get:r[t],enumerable:!0,configurable:!0,set:V.bind(r,t)})};var D={};p(D,{serveBun:()=>R,serveCloudflare:()=>N,serveNode:()=>k,serveVercel:()=>C});module.exports=h(D);var I={};p(I,{serveBun:()=>R});var T={};p(T,{serveNode:()=>k});var A={};p(A,{serveVercel:()=>C});function R(e,r){let t=globalThis;if(!t.Bun)throw Error("Runtime Bun tidak terdeteksi.");return t.Bun.serve({...r,fetch:e.fetch})}function N(e){return{fetch:async(r,t,o)=>e.fetch(r)}}var E=w(require("node:http"),1),g=w(require("node:https"),1);function k(e,r){let t=async(n,s)=>{try{let d=r.tls?"https":"http",a=n.headers.host||"localhost",y=`${d}://${a}${n.url}`,u=new Request(y,{method:n.method,headers:n.headers,body:["GET","HEAD"].includes(n.method||"")?null:n,duplex:"half"}),
|
|
1
|
+
var H=Object.create;var{getPrototypeOf:O,defineProperty:f,getOwnPropertyNames:x,getOwnPropertyDescriptor:B}=Object,m=Object.prototype.hasOwnProperty;function b(e){return this[e]}var F,W,w=(e,r,t)=>{var o=e!=null&&typeof e==="object";if(o){var n=r?F??=new WeakMap:W??=new WeakMap,s=n.get(e);if(s)return s}t=e!=null?H(O(e)):{};let d=r||!e||!e.__esModule||!m.call(e,"default")?f(t,"default",{value:e,enumerable:!0}):t;if(e&&typeof e==="object"||typeof e==="function"){for(let a of x(e))if(!m.call(d,a))f(d,a,{get:b.bind(e,a),enumerable:!0})}if(o)n.set(e,d);return d},h=(e)=>{var r=(v??=new WeakMap).get(e),t;if(r)return r;if(r=f({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var o of x(e))if(!m.call(r,o))f(r,o,{get:b.bind(e,o),enumerable:!(t=B(e,o))||t.enumerable})}return v.set(e,r),r},v;var P=(e)=>e;function V(e,r){this[e]=P.bind(null,r)}var p=(e,r)=>{for(var t in r)f(e,t,{get:r[t],enumerable:!0,configurable:!0,set:V.bind(r,t)})};var D={};p(D,{serveBun:()=>R,serveCloudflare:()=>N,serveNode:()=>k,serveVercel:()=>C});module.exports=h(D);var I={};p(I,{serveBun:()=>R});var T={};p(T,{serveNode:()=>k});var A={};p(A,{serveVercel:()=>C});function R(e,r){let t=globalThis;if(!t.Bun)throw Error("Runtime Bun tidak terdeteksi.");return t.Bun.serve({...r,fetch:e.fetch})}function N(e){return{fetch:async(r,t,o)=>e.fetch(r,t,o)}}var E=w(require("node:http"),1),g=w(require("node:https"),1);function k(e,r){let t=async(n,s)=>{try{let d=r.tls?"https":"http",a=n.headers.host||"localhost",y=`${d}://${a}${n.url}`,u=new Request(y,{method:n.method,headers:n.headers,body:["GET","HEAD"].includes(n.method||"")?null:n,duplex:"half"}),i=await e.fetch(u);if(s.statusCode=i.status,i.headers.forEach((c,l)=>{s.setHeader(l,c)}),i.body){let c=i.body.getReader();while(!0){let{done:l,value:S}=await c.read();if(l)break;s.write(S)}}s.end()}catch(d){s.statusCode=500,s.end("Internal Server Error")}},o=r.tls?g.default.createServer(r.tls,t):E.default.createServer(t);return o.listen(r.port,r.hostname),o}function C(e){return async function(t,o){if(t instanceof Request||t&&typeof t.arrayBuffer==="function"&&!o)return e.fetch(t);if(o&&typeof o.setHeader==="function"){try{let n=t.headers.host||"localhost",d=`${t.headers["x-forwarded-proto"]||"http"}://${n}${t.url}`,a=null;if(!["GET","HEAD"].includes(t.method||""))if(typeof t.body==="string"||Buffer.isBuffer(t.body))a=t.body;else if(t.body&&typeof t.body==="object")a=JSON.stringify(t.body);else a=t;let y=new Request(d,{method:t.method,headers:t.headers,body:a,duplex:"half"}),u=await e.fetch(y);if(o.statusCode=u.status,u.headers.forEach((i,c)=>{o.setHeader(c,i)}),u.body){let i=u.body.getReader();while(!0){let{done:c,value:l}=await i.read();if(c)break;o.write(l)}}o.end()}catch(n){if(!o.headersSent)o.statusCode=500;o.end("Internal Server Error")}return}throw Error("Invalid request/response arguments passed to handleVercel")}}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=64942FBF5FD39F0364756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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,+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,
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": "kpCAOO,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,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I,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
|
+
"debugId": "64942FBF5FD39F0364756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/dist/adapters/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
function m(n,r){let e=globalThis;if(!e.Bun)throw Error("Runtime Bun tidak terdeteksi.");return e.Bun.serve({...r,fetch:n.fetch})}function x(n){return{fetch:async(r,e,t)=>n.fetch(r)}}import p from"http";import y from"https";function E(n,r){let e=async(o,a)=>{try{let l=r.tls?"https":"http",
|
|
2
|
+
function m(n,r){let e=globalThis;if(!e.Bun)throw Error("Runtime Bun tidak terdeteksi.");return e.Bun.serve({...r,fetch:n.fetch})}function x(n){return{fetch:async(r,e,t)=>n.fetch(r,e,t)}}import p from"http";import y from"https";function E(n,r){let e=async(o,a)=>{try{let l=r.tls?"https":"http",i=o.headers.host||"localhost",f=`${l}://${i}${o.url}`,c=new Request(f,{method:o.method,headers:o.headers,body:["GET","HEAD"].includes(o.method||"")?null:o,duplex:"half"}),s=await n.fetch(c);if(a.statusCode=s.status,s.headers.forEach((d,u)=>{a.setHeader(u,d)}),s.body){let d=s.body.getReader();while(!0){let{done:u,value:h}=await d.read();if(u)break;a.write(h)}}a.end()}catch(l){a.statusCode=500,a.end("Internal Server Error")}},t=r.tls?y.createServer(r.tls,e):p.createServer(e);return t.listen(r.port,r.hostname),t}function k(n){return async function(e,t){if(e instanceof Request||e&&typeof e.arrayBuffer==="function"&&!t)return n.fetch(e);if(t&&typeof t.setHeader==="function"){try{let o=e.headers.host||"localhost",l=`${e.headers["x-forwarded-proto"]||"http"}://${o}${e.url}`,i=null;if(!["GET","HEAD"].includes(e.method||""))if(typeof e.body==="string"||Buffer.isBuffer(e.body))i=e.body;else if(e.body&&typeof e.body==="object")i=JSON.stringify(e.body);else i=e;let f=new Request(l,{method:e.method,headers:e.headers,body:i,duplex:"half"}),c=await n.fetch(f);if(t.statusCode=c.status,c.headers.forEach((s,d)=>{t.setHeader(d,s)}),c.body){let s=c.body.getReader();while(!0){let{done:d,value:u}=await s.read();if(d)break;t.write(u)}}t.end()}catch(o){if(!t.headersSent)t.statusCode=500;t.end("Internal Server Error")}return}throw Error("Invalid request/response arguments passed to handleVercel")}}export{m as serveBun,x as serveCloudflare,E as serveNode,k as serveVercel};
|
|
3
3
|
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=3C6780C371BF7B6C64756E2164756E21
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
11
|
-
"debugId": "
|
|
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,IAEO,EAAI,MAAM,EAAK,EAAK,CAAG,CAElC,EC7BF,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,OAA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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
|
+
"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
|
|
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,
|
|
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,IAA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"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
|
|
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,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,
|
|
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,MAAQ,YAC3B,EAAM,GAAG,OAAc,IAAO,EAAI,MAGlC,EAAS,IAAI,QAAQ,EAAK,CAC9B,OAAQ,EAAI,OACZ,QAAS,EAAI,QACb,KAAM,CAAC,M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