effect-start 0.14.0 → 0.16.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 +8 -9
- package/src/Commander.test.ts +507 -245
- package/src/ContentNegotiation.test.ts +603 -0
- package/src/ContentNegotiation.ts +542 -0
- package/src/Entity.test.ts +592 -0
- package/src/Entity.ts +362 -0
- package/src/FileRouter.ts +16 -12
- package/src/{FileRouterCodegen.test.ts → FileRouterCodegen.todo.ts} +384 -219
- package/src/FileRouterCodegen.ts +6 -6
- package/src/FileRouterPattern.test.ts +93 -62
- package/src/FileRouter_files.test.ts +5 -5
- package/src/FileRouter_path.test.ts +121 -69
- package/src/FileRouter_tree.test.ts +62 -56
- package/src/FileSystemExtra.test.ts +46 -30
- package/src/Http.test.ts +319 -0
- package/src/Http.ts +167 -0
- package/src/HttpAppExtra.test.ts +39 -20
- package/src/HttpAppExtra.ts +0 -1
- package/src/HttpUtils.test.ts +35 -18
- package/src/HttpUtils.ts +2 -0
- package/src/PathPattern.test.ts +648 -0
- package/src/PathPattern.ts +485 -0
- package/src/Route.ts +266 -1069
- package/src/RouteBody.test.ts +234 -0
- package/src/RouteBody.ts +193 -0
- package/src/RouteHook.test.ts +40 -0
- package/src/RouteHook.ts +106 -0
- package/src/RouteHttp.test.ts +2906 -0
- package/src/RouteHttp.ts +427 -0
- package/src/RouteHttpTracer.ts +92 -0
- package/src/RouteMount.test.ts +481 -0
- package/src/RouteMount.ts +470 -0
- package/src/RouteSchema.test.ts +427 -0
- package/src/RouteSchema.ts +423 -0
- package/src/RouteTree.test.ts +494 -0
- package/src/RouteTree.ts +219 -0
- package/src/RouteTrie.test.ts +322 -0
- package/src/RouteTrie.ts +224 -0
- package/src/RouterPattern.test.ts +569 -548
- package/src/RouterPattern.ts +7 -7
- package/src/Start.ts +3 -3
- package/src/StreamExtra.ts +21 -1
- package/src/TuplePathPattern.ts +64 -0
- package/src/Values.test.ts +263 -0
- package/src/Values.ts +76 -0
- package/src/bun/BunBundle.test.ts +36 -42
- package/src/bun/BunBundle.ts +2 -2
- package/src/bun/BunBundle_imports.test.ts +4 -6
- package/src/bun/BunHttpServer.test.ts +183 -6
- package/src/bun/BunHttpServer.ts +72 -32
- package/src/bun/BunHttpServer_web.ts +18 -6
- package/src/bun/BunImportTrackerPlugin.test.ts +3 -3
- package/src/bun/BunRoute.test.ts +124 -442
- package/src/bun/BunRoute.ts +146 -286
- package/src/{BundleHttp.test.ts → bundler/BundleHttp.test.ts} +34 -60
- package/src/{BundleHttp.ts → bundler/BundleHttp.ts} +1 -2
- package/src/client/index.ts +1 -1
- package/src/{Effect_HttpRouter.test.ts → effect/HttpRouter.test.ts} +69 -90
- package/src/experimental/EncryptedCookies.test.ts +125 -64
- package/src/experimental/SseHttpResponse.ts +0 -1
- package/src/hyper/Hyper.ts +89 -0
- package/src/{HyperHtml.test.ts → hyper/HyperHtml.test.ts} +13 -13
- package/src/{HyperHtml.ts → hyper/HyperHtml.ts} +2 -2
- package/src/{jsx.d.ts → hyper/jsx.d.ts} +1 -1
- package/src/index.ts +3 -4
- package/src/middlewares/BasicAuthMiddleware.test.ts +29 -19
- package/src/{NodeFileSystem.ts → node/FileSystem.ts} +6 -2
- package/src/testing/TestHttpClient.test.ts +26 -26
- package/src/testing/TestLogger.test.ts +27 -14
- package/src/testing/TestLogger.ts +15 -9
- package/src/x/datastar/Datastar.test.ts +47 -48
- package/src/x/datastar/Datastar.ts +1 -1
- package/src/x/tailwind/TailwindPlugin.test.ts +56 -58
- package/src/x/tailwind/plugin.ts +1 -1
- package/src/FileHttpRouter.test.ts +0 -239
- package/src/FileHttpRouter.ts +0 -194
- package/src/Hyper.ts +0 -194
- package/src/Route.test.ts +0 -1370
- package/src/RouteRender.ts +0 -40
- package/src/Router.test.ts +0 -375
- package/src/Router.ts +0 -255
- package/src/bun/BunRoute_bundles.test.ts +0 -219
- /package/src/{Bundle.ts → bundler/Bundle.ts} +0 -0
- /package/src/{BundleFiles.ts → bundler/BundleFiles.ts} +0 -0
- /package/src/{HyperNode.ts → hyper/HyperNode.ts} +0 -0
- /package/src/{jsx-runtime.ts → hyper/jsx-runtime.ts} +0 -0
- /package/src/{NodeUtils.ts → node/Utils.ts} +0 -0
package/src/HttpAppExtra.test.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { HttpServerRequest } from "@effect/platform"
|
|
2
2
|
import { RouteNotFound } from "@effect/platform/HttpServerError"
|
|
3
|
-
import * as
|
|
3
|
+
import * as test from "bun:test"
|
|
4
4
|
import {
|
|
5
|
-
Effect,
|
|
6
5
|
Layer,
|
|
6
|
+
Logger,
|
|
7
7
|
} from "effect"
|
|
8
8
|
import * as Cause from "effect/Cause"
|
|
9
|
+
import * as LogLevel from "effect/LogLevel"
|
|
9
10
|
import * as HttpAppExtra from "./HttpAppExtra.ts"
|
|
10
11
|
import { effectFn } from "./testing"
|
|
11
12
|
|
|
@@ -18,60 +19,76 @@ const mockRequest = HttpServerRequest.HttpServerRequest.of({
|
|
|
18
19
|
},
|
|
19
20
|
} as any)
|
|
20
21
|
|
|
21
|
-
const mockRequestLayer = Layer.
|
|
22
|
-
HttpServerRequest.HttpServerRequest,
|
|
23
|
-
|
|
22
|
+
const mockRequestLayer = Layer.mergeAll(
|
|
23
|
+
Layer.succeed(HttpServerRequest.HttpServerRequest, mockRequest),
|
|
24
|
+
Logger.minimumLogLevel(LogLevel.None),
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
const effect = effectFn(mockRequestLayer)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
test.describe("renderError", () => {
|
|
29
30
|
const routeNotFoundCause = Cause.fail(
|
|
30
31
|
new RouteNotFound({ request: {} as any }),
|
|
31
32
|
)
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
test.it("returns JSON for Accept: application/json", () =>
|
|
34
35
|
effect(function*() {
|
|
35
36
|
const response = yield* HttpAppExtra.renderError(
|
|
36
37
|
routeNotFoundCause,
|
|
37
38
|
"application/json",
|
|
38
39
|
)
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
test
|
|
42
|
+
.expect(response.status)
|
|
43
|
+
.toEqual(404)
|
|
44
|
+
test
|
|
45
|
+
.expect(response.headers["content-type"])
|
|
46
|
+
.toContain("application/json")
|
|
42
47
|
}))
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
test.it("returns HTML for Accept: text/html", () =>
|
|
45
50
|
effect(function*() {
|
|
46
51
|
const response = yield* HttpAppExtra.renderError(
|
|
47
52
|
routeNotFoundCause,
|
|
48
53
|
"text/html",
|
|
49
54
|
)
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
test
|
|
57
|
+
.expect(response.status)
|
|
58
|
+
.toEqual(404)
|
|
59
|
+
test
|
|
60
|
+
.expect(response.headers["content-type"])
|
|
61
|
+
.toContain("text/html")
|
|
53
62
|
}))
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
test.it("returns plain text for Accept: text/plain", () =>
|
|
56
65
|
effect(function*() {
|
|
57
66
|
const response = yield* HttpAppExtra.renderError(
|
|
58
67
|
routeNotFoundCause,
|
|
59
68
|
"text/plain",
|
|
60
69
|
)
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
test
|
|
72
|
+
.expect(response.status)
|
|
73
|
+
.toEqual(404)
|
|
74
|
+
test
|
|
75
|
+
.expect(response.headers["content-type"])
|
|
76
|
+
.toContain("text/plain")
|
|
64
77
|
}))
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
test.it("returns JSON by default (no Accept header)", () =>
|
|
67
80
|
effect(function*() {
|
|
68
81
|
const response = yield* HttpAppExtra.renderError(routeNotFoundCause, "")
|
|
69
82
|
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
test
|
|
84
|
+
.expect(response.status)
|
|
85
|
+
.toEqual(404)
|
|
86
|
+
test
|
|
87
|
+
.expect(response.headers["content-type"])
|
|
88
|
+
.toContain("application/json")
|
|
72
89
|
}))
|
|
73
90
|
|
|
74
|
-
|
|
91
|
+
test.it("returns 500 for unexpected errors", () =>
|
|
75
92
|
effect(function*() {
|
|
76
93
|
const unexpectedCause = Cause.fail({ message: "Something went wrong" })
|
|
77
94
|
const response = yield* HttpAppExtra.renderError(
|
|
@@ -79,6 +96,8 @@ t.describe("renderError", () => {
|
|
|
79
96
|
"application/json",
|
|
80
97
|
)
|
|
81
98
|
|
|
82
|
-
|
|
99
|
+
test
|
|
100
|
+
.expect(response.status)
|
|
101
|
+
.toEqual(500)
|
|
83
102
|
}))
|
|
84
103
|
})
|
package/src/HttpAppExtra.ts
CHANGED
package/src/HttpUtils.test.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as HttpServerRequest from "@effect/platform/HttpServerRequest"
|
|
2
|
-
import * as
|
|
3
|
-
|
|
2
|
+
import * as test from "bun:test"
|
|
4
3
|
import * as HttpUtils from "./HttpUtils.ts"
|
|
5
4
|
|
|
6
5
|
const makeRequest = (url: string, headers: Record<string, string> = {}) =>
|
|
@@ -8,61 +7,79 @@ const makeRequest = (url: string, headers: Record<string, string> = {}) =>
|
|
|
8
7
|
new Request(`http://test${url}`, { headers }),
|
|
9
8
|
)
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
test.describe("makeUrlFromRequest", () => {
|
|
11
|
+
test.it("uses Host header for relative URL", () => {
|
|
13
12
|
const request = makeRequest("/api/users", {
|
|
14
13
|
host: "example.com",
|
|
15
14
|
})
|
|
16
15
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
test
|
|
18
|
+
.expect(url.href)
|
|
19
|
+
.toBe("http://example.com/api/users")
|
|
19
20
|
})
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
test.it("uses Origin header when present (takes precedence over Host)", () => {
|
|
22
23
|
const request = makeRequest("/api/users", {
|
|
23
24
|
origin: "https://app.example.com",
|
|
24
25
|
host: "example.com",
|
|
25
26
|
})
|
|
26
27
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
test
|
|
30
|
+
.expect(url.href)
|
|
31
|
+
.toBe("https://app.example.com/api/users")
|
|
29
32
|
})
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
test.it("uses X-Forwarded-Proto for protocol behind reverse proxy", () => {
|
|
32
35
|
const request = makeRequest("/api/users", {
|
|
33
36
|
host: "example.com",
|
|
34
37
|
"x-forwarded-proto": "https",
|
|
35
38
|
})
|
|
36
39
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
test
|
|
42
|
+
.expect(url.href)
|
|
43
|
+
.toBe("https://example.com/api/users")
|
|
39
44
|
})
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
test.it("falls back to http://localhost when no headers", () => {
|
|
42
47
|
const request = makeRequest("/api/users", {})
|
|
43
48
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
test
|
|
51
|
+
.expect(url.href)
|
|
52
|
+
.toBe("http://localhost/api/users")
|
|
46
53
|
})
|
|
47
54
|
|
|
48
|
-
|
|
55
|
+
test.it("handles URL with query parameters", () => {
|
|
49
56
|
const request = makeRequest("/search?q=test&page=1", {
|
|
50
57
|
host: "example.com",
|
|
51
58
|
})
|
|
52
59
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
test
|
|
62
|
+
.expect(url.href)
|
|
63
|
+
.toBe("http://example.com/search?q=test&page=1")
|
|
64
|
+
test
|
|
65
|
+
.expect(url.searchParams.get("q"))
|
|
66
|
+
.toBe("test")
|
|
67
|
+
test
|
|
68
|
+
.expect(url.searchParams.get("page"))
|
|
69
|
+
.toBe("1")
|
|
57
70
|
})
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
test.it("handles root path", () => {
|
|
60
73
|
const request = makeRequest("/", {
|
|
61
74
|
host: "example.com",
|
|
62
75
|
})
|
|
63
76
|
const url = HttpUtils.makeUrlFromRequest(request)
|
|
64
77
|
|
|
65
|
-
|
|
66
|
-
|
|
78
|
+
test
|
|
79
|
+
.expect(url.href)
|
|
80
|
+
.toBe("http://example.com/")
|
|
81
|
+
test
|
|
82
|
+
.expect(url.pathname)
|
|
83
|
+
.toBe("/")
|
|
67
84
|
})
|
|
68
85
|
})
|
package/src/HttpUtils.ts
CHANGED