effect-start 0.10.0 → 0.11.0
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/package.json +5 -3
- package/src/FileHttpRouter.test.ts +4 -4
- package/src/FileHttpRouter.ts +6 -8
- package/src/FileRouter.ts +4 -6
- package/src/FileRouterCodegen.test.ts +2 -2
- package/src/HttpAppExtra.test.ts +84 -0
- package/src/HttpAppExtra.ts +399 -47
- package/src/Route.test.ts +59 -33
- package/src/Route.ts +59 -49
- package/src/RouteRender.ts +6 -4
- package/src/Router.test.ts +416 -0
- package/src/Router.ts +279 -0
- package/src/RouterPattern.test.ts +29 -3
- package/src/RouterPattern.ts +30 -5
- package/src/TestHttpClient.test.ts +29 -0
- package/src/TestHttpClient.ts +122 -73
- package/src/assets.d.ts +39 -0
- package/src/bun/BunHttpServer.test.ts +74 -0
- package/src/bun/BunHttpServer.ts +22 -9
- package/src/bun/BunRoute.test.ts +307 -134
- package/src/bun/BunRoute.ts +240 -139
- package/src/bun/BunRoute_bundles.test.ts +181 -181
- package/src/index.ts +14 -14
- package/src/middlewares/BasicAuthMiddleware.test.ts +74 -0
- package/src/middlewares/BasicAuthMiddleware.ts +36 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as t from "bun:test"
|
|
2
|
+
import * as Effect from "effect/Effect"
|
|
3
|
+
import * as BunHttpServer from "./BunHttpServer.ts"
|
|
4
|
+
|
|
5
|
+
t.describe("BunHttpServer smart port selection", () => {
|
|
6
|
+
// Skip when running in TTY because the random port logic requires !isTTY && CLAUDECODE,
|
|
7
|
+
// and process.stdout.isTTY cannot be mocked
|
|
8
|
+
t.test.skipIf(process.stdout.isTTY)(
|
|
9
|
+
"uses random port when PORT not set, isTTY=false, CLAUDECODE set",
|
|
10
|
+
async () => {
|
|
11
|
+
const originalPort = process.env.PORT
|
|
12
|
+
const originalClaudeCode = process.env.CLAUDECODE
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
delete process.env.PORT
|
|
16
|
+
process.env.CLAUDECODE = "1"
|
|
17
|
+
|
|
18
|
+
const port = await Effect.runPromise(
|
|
19
|
+
Effect.scoped(
|
|
20
|
+
Effect.gen(function*() {
|
|
21
|
+
const bunServer = yield* BunHttpServer.make({})
|
|
22
|
+
return bunServer.server.port
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
t.expect(port).not.toBe(3000)
|
|
28
|
+
} finally {
|
|
29
|
+
if (originalPort !== undefined) {
|
|
30
|
+
process.env.PORT = originalPort
|
|
31
|
+
} else {
|
|
32
|
+
delete process.env.PORT
|
|
33
|
+
}
|
|
34
|
+
if (originalClaudeCode !== undefined) {
|
|
35
|
+
process.env.CLAUDECODE = originalClaudeCode
|
|
36
|
+
} else {
|
|
37
|
+
delete process.env.CLAUDECODE
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
t.test("uses explicit PORT even when CLAUDECODE is set", async () => {
|
|
44
|
+
const originalPort = process.env.PORT
|
|
45
|
+
const originalClaudeCode = process.env.CLAUDECODE
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
process.env.PORT = "5678"
|
|
49
|
+
process.env.CLAUDECODE = "1"
|
|
50
|
+
|
|
51
|
+
const port = await Effect.runPromise(
|
|
52
|
+
Effect.scoped(
|
|
53
|
+
Effect.gen(function*() {
|
|
54
|
+
const bunServer = yield* BunHttpServer.make({})
|
|
55
|
+
return bunServer.server.port
|
|
56
|
+
}),
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
t.expect(port).toBe(5678)
|
|
61
|
+
} finally {
|
|
62
|
+
if (originalPort !== undefined) {
|
|
63
|
+
process.env.PORT = originalPort
|
|
64
|
+
} else {
|
|
65
|
+
delete process.env.PORT
|
|
66
|
+
}
|
|
67
|
+
if (originalClaudeCode !== undefined) {
|
|
68
|
+
process.env.CLAUDECODE = originalClaudeCode
|
|
69
|
+
} else {
|
|
70
|
+
delete process.env.CLAUDECODE
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
})
|
package/src/bun/BunHttpServer.ts
CHANGED
|
@@ -63,7 +63,17 @@ export const make = (
|
|
|
63
63
|
> =>
|
|
64
64
|
Effect.gen(function*() {
|
|
65
65
|
const port = yield* Config.number("PORT").pipe(
|
|
66
|
-
Effect.catchTag("ConfigError", () =>
|
|
66
|
+
Effect.catchTag("ConfigError", () => {
|
|
67
|
+
if (
|
|
68
|
+
typeof process !== "undefined"
|
|
69
|
+
&& !process.stdout.isTTY
|
|
70
|
+
&& process.env.CLAUDECODE
|
|
71
|
+
) {
|
|
72
|
+
return Effect.succeed(0)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Effect.succeed(3000)
|
|
76
|
+
}),
|
|
67
77
|
)
|
|
68
78
|
const hostname = yield* Config.string("HOSTNAME").pipe(
|
|
69
79
|
Effect.catchTag("ConfigError", () => Effect.succeed(undefined)),
|
|
@@ -226,15 +236,18 @@ export const layerServer = (
|
|
|
226
236
|
)
|
|
227
237
|
|
|
228
238
|
export function layerRoutes() {
|
|
229
|
-
return Layer.effectDiscard(
|
|
230
|
-
|
|
231
|
-
|
|
239
|
+
return Layer.effectDiscard(
|
|
240
|
+
Effect.gen(function*() {
|
|
241
|
+
const bunServer = yield* BunServer
|
|
242
|
+
const routerContext = yield* Effect.serviceOption(Router.Router)
|
|
232
243
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
244
|
+
if (Option.isSome(routerContext)) {
|
|
245
|
+
const router = yield* Router.fromManifest(routerContext.value)
|
|
246
|
+
const bunRoutes = yield* BunRoute.routesFromRouter(router)
|
|
247
|
+
bunServer.addRoutes(bunRoutes)
|
|
248
|
+
}
|
|
249
|
+
}),
|
|
250
|
+
)
|
|
238
251
|
}
|
|
239
252
|
|
|
240
253
|
const removeHost = (url: string) => {
|