effect-start 0.20.1 → 0.22.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 (105) hide show
  1. package/README.md +1 -4
  2. package/dist/Cookies.js +392 -0
  3. package/dist/FileSystem.js +131 -0
  4. package/dist/Socket.js +37 -0
  5. package/package.json +39 -40
  6. package/src/Commander.ts +73 -130
  7. package/src/ContentNegotiation.ts +68 -100
  8. package/src/Cookies.ts +408 -0
  9. package/src/Development.ts +48 -63
  10. package/src/Effectify.ts +222 -206
  11. package/src/Entity.ts +59 -86
  12. package/src/FilePathPattern.ts +5 -5
  13. package/src/FileRouter.ts +38 -63
  14. package/src/FileRouterCodegen.ts +64 -56
  15. package/src/FileSystem.ts +390 -0
  16. package/src/Http.ts +17 -50
  17. package/src/PathPattern.ts +33 -41
  18. package/src/PlatformError.ts +29 -50
  19. package/src/PlatformRuntime.ts +39 -47
  20. package/src/Route.ts +68 -187
  21. package/src/RouteBody.ts +45 -161
  22. package/src/RouteHook.ts +22 -45
  23. package/src/RouteHttp.ts +88 -142
  24. package/src/RouteHttpTracer.ts +25 -26
  25. package/src/RouteMount.ts +100 -238
  26. package/src/RouteSchema.ts +67 -201
  27. package/src/RouteSse.ts +28 -82
  28. package/src/RouteTree.ts +31 -79
  29. package/src/RouteTrie.ts +13 -32
  30. package/src/SchemaExtra.ts +3 -5
  31. package/src/Socket.ts +51 -0
  32. package/src/Start.ts +20 -21
  33. package/src/StreamExtra.ts +93 -96
  34. package/src/TuplePathPattern.ts +54 -43
  35. package/src/Unique.ts +9 -15
  36. package/src/Values.ts +26 -30
  37. package/src/bun/BunBundle.ts +27 -73
  38. package/src/bun/BunImportTrackerPlugin.ts +67 -65
  39. package/src/bun/BunRoute.ts +12 -31
  40. package/src/bun/BunRuntime.ts +3 -10
  41. package/src/bun/BunServer.ts +50 -60
  42. package/src/bun/BunVirtualFilesPlugin.ts +1 -4
  43. package/src/bun/_BunEnhancedResolve.ts +17 -42
  44. package/src/bun/_empty.html +0 -1
  45. package/src/bundler/Bundle.ts +20 -36
  46. package/src/bundler/BundleFiles.ts +36 -56
  47. package/src/client/Overlay.ts +1 -2
  48. package/src/client/ScrollState.ts +5 -9
  49. package/src/client/index.ts +10 -13
  50. package/src/datastar/actions/fetch.ts +29 -48
  51. package/src/datastar/actions/peek.ts +1 -5
  52. package/src/datastar/actions/setAll.ts +2 -2
  53. package/src/datastar/actions/toggleAll.ts +2 -2
  54. package/src/datastar/attributes/attr.ts +17 -18
  55. package/src/datastar/attributes/bind.ts +41 -61
  56. package/src/datastar/attributes/class.ts +2 -5
  57. package/src/datastar/attributes/computed.ts +2 -10
  58. package/src/datastar/attributes/effect.ts +1 -2
  59. package/src/datastar/attributes/indicator.ts +2 -8
  60. package/src/datastar/attributes/init.ts +2 -10
  61. package/src/datastar/attributes/jsonSignals.ts +1 -6
  62. package/src/datastar/attributes/on.ts +4 -13
  63. package/src/datastar/attributes/onIntersect.ts +10 -22
  64. package/src/datastar/attributes/onInterval.ts +2 -10
  65. package/src/datastar/attributes/onSignalPatch.ts +18 -28
  66. package/src/datastar/attributes/ref.ts +1 -2
  67. package/src/datastar/attributes/show.ts +1 -2
  68. package/src/datastar/attributes/signals.ts +1 -5
  69. package/src/datastar/attributes/style.ts +6 -12
  70. package/src/datastar/attributes/text.ts +1 -2
  71. package/src/datastar/engine.ts +102 -158
  72. package/src/datastar/index.ts +2 -2
  73. package/src/datastar/utils.ts +16 -51
  74. package/src/datastar/watchers/patchElements.ts +35 -93
  75. package/src/datastar/watchers/patchSignals.ts +1 -2
  76. package/src/experimental/EncryptedCookies.ts +81 -175
  77. package/src/experimental/index.ts +0 -1
  78. package/src/hyper/Hyper.ts +14 -33
  79. package/src/hyper/HyperHtml.ts +13 -10
  80. package/src/hyper/HyperNode.ts +2 -7
  81. package/src/hyper/HyperRoute.ts +2 -5
  82. package/src/hyper/jsx-runtime.ts +2 -10
  83. package/src/hyper/jsx.d.ts +171 -440
  84. package/src/lint/plugin.js +276 -0
  85. package/src/node/NodeFileSystem.ts +140 -202
  86. package/src/node/NodeUtils.ts +1 -3
  87. package/src/testing/TestLogger.ts +9 -22
  88. package/src/testing/index.ts +0 -1
  89. package/src/testing/utils.ts +30 -31
  90. package/src/x/cloudflare/CloudflareTunnel.ts +53 -65
  91. package/src/x/datastar/Datastar.ts +3 -10
  92. package/src/x/datastar/index.ts +1 -3
  93. package/src/x/datastar/jsx-datastar.d.ts +1 -4
  94. package/src/x/tailwind/TailwindPlugin.ts +119 -112
  95. package/src/x/tailwind/compile.ts +10 -33
  96. package/src/x/tailwind/plugin.ts +2 -2
  97. package/src/HttpAppExtra.ts +0 -478
  98. package/src/HttpUtils.ts +0 -17
  99. package/src/bun/BunPlatformHttpServer.ts +0 -88
  100. package/src/bun/BunServerRequest.ts +0 -396
  101. package/src/bundler/BundleHttp.ts +0 -259
  102. package/src/experimental/SseHttpResponse.ts +0 -55
  103. package/src/middlewares/BasicAuthMiddleware.ts +0 -36
  104. package/src/middlewares/index.ts +0 -1
  105. package/src/testing/TestHttpClient.ts +0 -148
@@ -1,36 +0,0 @@
1
- import * as HttpMiddleware from "@effect/platform/HttpMiddleware"
2
- import * as HttpServerRequest from "@effect/platform/HttpServerRequest"
3
- import * as HttpServerResponse from "@effect/platform/HttpServerResponse"
4
- import * as Effect from "effect/Effect"
5
-
6
- export interface BasicAuthConfig {
7
- readonly username: string
8
- readonly password: string
9
- }
10
-
11
- const unauthorizedResponse = HttpServerResponse.empty({
12
- status: 401,
13
- headers: { "WWW-Authenticate": "Basic" },
14
- })
15
-
16
- export const make = (config: BasicAuthConfig) =>
17
- HttpMiddleware.make((app) =>
18
- Effect.gen(function*() {
19
- const request = yield* HttpServerRequest.HttpServerRequest
20
- const authHeader = request.headers.authorization
21
-
22
- if (!authHeader || !authHeader.startsWith("Basic ")) {
23
- return unauthorizedResponse
24
- }
25
-
26
- const base64Credentials = authHeader.slice(6)
27
- const credentials = atob(base64Credentials)
28
- const [username, password] = credentials.split(":")
29
-
30
- if (username !== config.username || password !== config.password) {
31
- return unauthorizedResponse
32
- }
33
-
34
- return yield* app
35
- })
36
- )
@@ -1 +0,0 @@
1
- export * as BasicAuthMiddleware from "./BasicAuthMiddleware.ts"
@@ -1,148 +0,0 @@
1
- import * as HttpApp from "@effect/platform/HttpApp"
2
- import * as HttpClient from "@effect/platform/HttpClient"
3
- import * as HttpClientError from "@effect/platform/HttpClientError"
4
- import * as HttpClientRequest from "@effect/platform/HttpClientRequest"
5
- import * as HttpClientResponse from "@effect/platform/HttpClientResponse"
6
- import { RouteNotFound } from "@effect/platform/HttpServerError"
7
- import * as HttpServerRequest from "@effect/platform/HttpServerRequest"
8
- import * as HttpServerResponse from "@effect/platform/HttpServerResponse"
9
- import * as UrlParams from "@effect/platform/UrlParams"
10
- import * as Effect from "effect/Effect"
11
- import * as Either from "effect/Either"
12
- import * as Function from "effect/Function"
13
- import * as Stream from "effect/Stream"
14
-
15
- const WebHeaders = globalThis.Headers
16
-
17
- export type FetchHandler = (req: Request) => Response | Promise<Response>
18
-
19
- export const isFetchHandler = (
20
- app: unknown,
21
- ): app is FetchHandler => typeof app === "function" && !Effect.isEffect(app)
22
-
23
- const fromFetchHandler = (
24
- handler: FetchHandler,
25
- ): HttpApp.Default<never, never> =>
26
- Effect.gen(function*() {
27
- const serverRequest = yield* HttpServerRequest.HttpServerRequest
28
- const webRequest = serverRequest.source as Request
29
- const response = yield* Effect.promise(async () => handler(webRequest))
30
- const body = yield* Effect.promise(() => response.arrayBuffer())
31
- return HttpServerResponse.raw(new Uint8Array(body), {
32
- status: response.status,
33
- statusText: response.statusText,
34
- headers: Object.fromEntries(response.headers.entries()),
35
- })
36
- })
37
-
38
- export const make = <E, R>(
39
- appOrHandler: HttpApp.Default<E, R> | FetchHandler,
40
- opts?: {
41
- baseUrl?: string | null
42
- handleRouteNotFound?: (
43
- e: RouteNotFound,
44
- ) => Effect.Effect<HttpClientResponse.HttpClientResponse> | null
45
- },
46
- ): HttpClient.HttpClient.With<
47
- HttpClientError.HttpClientError | E,
48
- Exclude<R, HttpServerRequest.HttpServerRequest>
49
- > => {
50
- const httpApp: HttpApp.Default<E, R> = isFetchHandler(appOrHandler)
51
- ? fromFetchHandler(appOrHandler) as HttpApp.Default<E, R>
52
- : appOrHandler
53
-
54
- const execute = (
55
- request: HttpClientRequest.HttpClientRequest,
56
- ): Effect.Effect<
57
- HttpClientResponse.HttpClientResponse,
58
- HttpClientError.HttpClientError | E,
59
- Exclude<R, HttpServerRequest.HttpServerRequest>
60
- > => {
61
- const urlResult = UrlParams.makeUrl(
62
- request.url,
63
- request.urlParams,
64
- request.hash,
65
- )
66
- if (Either.isLeft(urlResult)) {
67
- return Effect.die(urlResult.left)
68
- }
69
- const url = urlResult.right
70
- const controller = new AbortController()
71
- const signal = controller.signal
72
-
73
- const send = (
74
- body: BodyInit | undefined,
75
- ): Effect.Effect<
76
- HttpClientResponse.HttpClientResponse,
77
- E,
78
- Exclude<R, HttpServerRequest.HttpServerRequest>
79
- > => {
80
- const serverRequest = HttpServerRequest.fromWeb(
81
- new Request(url.toString(), {
82
- method: request.method,
83
- headers: new WebHeaders(request.headers),
84
- body,
85
- duplex: request.body._tag === "Stream" ? "half" : undefined,
86
- signal,
87
- } as RequestInit),
88
- )
89
-
90
- return Function.pipe(
91
- httpApp,
92
- Effect.provideService(
93
- HttpServerRequest.HttpServerRequest,
94
- serverRequest,
95
- ),
96
- Effect.andThen(HttpServerResponse.toWeb),
97
- Effect.andThen(res => HttpClientResponse.fromWeb(request, res)),
98
- opts?.handleRouteNotFound === null
99
- ? Function.identity
100
- : Effect.catchAll((e) =>
101
- e instanceof RouteNotFound
102
- ? Effect.succeed(HttpClientResponse.fromWeb(
103
- request,
104
- new Response("Failed with RouteNotFound", {
105
- status: 404,
106
- }),
107
- ))
108
- : Effect.fail(e)
109
- ),
110
- ) as Effect.Effect<
111
- HttpClientResponse.HttpClientResponse,
112
- E,
113
- Exclude<R, HttpServerRequest.HttpServerRequest>
114
- >
115
- }
116
-
117
- switch (request.body._tag) {
118
- case "Raw":
119
- case "Uint8Array":
120
- return send(request.body.body as BodyInit)
121
- case "FormData":
122
- return send(request.body.formData)
123
- case "Stream":
124
- return Effect.flatMap(
125
- Stream.toReadableStreamEffect(request.body.stream),
126
- send,
127
- )
128
- }
129
-
130
- return send(undefined)
131
- }
132
-
133
- const client = HttpClient.makeWith(
134
- (requestEffect) => Effect.flatMap(requestEffect, execute),
135
- (request) => Effect.succeed(request),
136
- )
137
-
138
- return client.pipe(
139
- opts?.baseUrl === null
140
- ? Function.identity
141
- : HttpClient.mapRequest(
142
- HttpClientRequest.prependUrl(opts?.baseUrl ?? "http://localhost"),
143
- ),
144
- ) as HttpClient.HttpClient.With<
145
- HttpClientError.HttpClientError | E,
146
- Exclude<R, HttpServerRequest.HttpServerRequest>
147
- >
148
- }