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