effect-start 0.18.0 → 0.20.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 (203) hide show
  1. package/README.md +3 -3
  2. package/dist/Development.d.ts +8 -3
  3. package/dist/Development.js +14 -7
  4. package/dist/Effectify.d.ts +212 -0
  5. package/dist/Effectify.js +19 -0
  6. package/dist/FilePathPattern.d.ts +29 -0
  7. package/dist/FilePathPattern.js +86 -0
  8. package/dist/FileRouter.d.ts +39 -41
  9. package/dist/FileRouter.js +104 -158
  10. package/dist/FileRouterCodegen.d.ts +7 -8
  11. package/dist/FileRouterCodegen.js +97 -66
  12. package/dist/PlatformError.d.ts +46 -0
  13. package/dist/PlatformError.js +43 -0
  14. package/dist/PlatformRuntime.d.ts +27 -0
  15. package/dist/PlatformRuntime.js +51 -0
  16. package/dist/Route.d.ts +6 -2
  17. package/dist/Route.js +22 -0
  18. package/dist/RouteBody.d.ts +1 -1
  19. package/dist/RouteHttp.d.ts +1 -1
  20. package/dist/RouteHttp.js +12 -19
  21. package/dist/RouteMount.d.ts +2 -1
  22. package/dist/Start.d.ts +33 -6
  23. package/dist/Start.js +31 -13
  24. package/dist/Unique.d.ts +50 -0
  25. package/dist/Unique.js +187 -0
  26. package/dist/bun/BunHttpServer.js +5 -6
  27. package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
  28. package/dist/bun/BunPlatformHttpServer.js +53 -0
  29. package/dist/bun/BunRoute.d.ts +4 -6
  30. package/dist/bun/BunRoute.js +10 -18
  31. package/dist/bun/BunRuntime.d.ts +2 -1
  32. package/dist/bun/BunRuntime.js +10 -5
  33. package/dist/bun/BunServer.d.ts +33 -0
  34. package/dist/bun/BunServer.js +133 -0
  35. package/dist/bun/BunServerRequest.d.ts +60 -0
  36. package/dist/bun/BunServerRequest.js +252 -0
  37. package/dist/bun/index.d.ts +1 -1
  38. package/dist/bun/index.js +1 -1
  39. package/dist/datastar/actions/fetch.d.ts +30 -0
  40. package/dist/datastar/actions/fetch.js +411 -0
  41. package/dist/datastar/actions/peek.d.ts +1 -0
  42. package/dist/datastar/actions/peek.js +14 -0
  43. package/dist/datastar/actions/setAll.d.ts +1 -0
  44. package/dist/datastar/actions/setAll.js +13 -0
  45. package/dist/datastar/actions/toggleAll.d.ts +1 -0
  46. package/dist/datastar/actions/toggleAll.js +13 -0
  47. package/dist/datastar/attributes/attr.d.ts +1 -0
  48. package/dist/datastar/attributes/attr.js +49 -0
  49. package/dist/datastar/attributes/bind.d.ts +1 -0
  50. package/dist/datastar/attributes/bind.js +183 -0
  51. package/dist/datastar/attributes/class.d.ts +1 -0
  52. package/dist/datastar/attributes/class.js +50 -0
  53. package/dist/datastar/attributes/computed.d.ts +1 -0
  54. package/dist/datastar/attributes/computed.js +27 -0
  55. package/dist/datastar/attributes/effect.d.ts +1 -0
  56. package/dist/datastar/attributes/effect.js +10 -0
  57. package/dist/datastar/attributes/indicator.d.ts +1 -0
  58. package/dist/datastar/attributes/indicator.js +32 -0
  59. package/dist/datastar/attributes/init.d.ts +1 -0
  60. package/dist/datastar/attributes/init.js +27 -0
  61. package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
  62. package/dist/datastar/attributes/jsonSignals.js +31 -0
  63. package/dist/datastar/attributes/on.d.ts +1 -0
  64. package/dist/datastar/attributes/on.js +59 -0
  65. package/dist/datastar/attributes/onIntersect.d.ts +1 -0
  66. package/dist/datastar/attributes/onIntersect.js +54 -0
  67. package/dist/datastar/attributes/onInterval.d.ts +1 -0
  68. package/dist/datastar/attributes/onInterval.js +31 -0
  69. package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
  70. package/dist/datastar/attributes/onSignalPatch.js +44 -0
  71. package/dist/datastar/attributes/ref.d.ts +1 -0
  72. package/dist/datastar/attributes/ref.js +11 -0
  73. package/dist/datastar/attributes/show.d.ts +1 -0
  74. package/dist/datastar/attributes/show.js +32 -0
  75. package/dist/datastar/attributes/signals.d.ts +1 -0
  76. package/dist/datastar/attributes/signals.js +18 -0
  77. package/dist/datastar/attributes/style.d.ts +1 -0
  78. package/dist/datastar/attributes/style.js +56 -0
  79. package/dist/datastar/attributes/text.d.ts +1 -0
  80. package/dist/datastar/attributes/text.js +27 -0
  81. package/dist/datastar/engine.d.ts +156 -0
  82. package/dist/datastar/engine.js +971 -0
  83. package/dist/datastar/index.d.ts +24 -0
  84. package/dist/datastar/index.js +24 -0
  85. package/dist/datastar/load.d.ts +24 -0
  86. package/dist/datastar/load.js +24 -0
  87. package/dist/datastar/utils.d.ts +51 -0
  88. package/dist/datastar/utils.js +205 -0
  89. package/dist/datastar/watchers/patchElements.d.ts +1 -0
  90. package/dist/datastar/watchers/patchElements.js +420 -0
  91. package/dist/datastar/watchers/patchSignals.d.ts +1 -0
  92. package/dist/datastar/watchers/patchSignals.js +15 -0
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.js +1 -0
  95. package/dist/node/Effectify.d.ts +209 -0
  96. package/dist/node/Effectify.js +19 -0
  97. package/dist/node/FileSystem.d.ts +3 -5
  98. package/dist/node/FileSystem.js +42 -62
  99. package/dist/node/NodeFileSystem.d.ts +7 -0
  100. package/dist/node/NodeFileSystem.js +420 -0
  101. package/dist/node/NodeUtils.d.ts +2 -0
  102. package/dist/node/NodeUtils.js +20 -0
  103. package/dist/node/PlatformError.d.ts +46 -0
  104. package/dist/node/PlatformError.js +43 -0
  105. package/dist/testing/TestLogger.js +1 -1
  106. package/dist/x/tailwind/plugin.js +1 -1
  107. package/package.json +18 -7
  108. package/src/Development.ts +36 -40
  109. package/src/Effectify.ts +269 -0
  110. package/src/FilePathPattern.ts +115 -0
  111. package/src/FileRouter.ts +178 -255
  112. package/src/FileRouterCodegen.ts +135 -92
  113. package/src/PlatformError.ts +117 -0
  114. package/src/PlatformRuntime.ts +108 -0
  115. package/src/Route.ts +31 -2
  116. package/src/RouteBody.ts +1 -1
  117. package/src/RouteHttp.ts +15 -29
  118. package/src/RouteMount.ts +1 -1
  119. package/src/Start.ts +61 -27
  120. package/src/Unique.ts +232 -0
  121. package/src/bun/BunPlatformHttpServer.ts +88 -0
  122. package/src/bun/BunRoute.ts +14 -24
  123. package/src/bun/BunRuntime.ts +21 -5
  124. package/src/bun/BunServer.ts +228 -0
  125. package/src/bun/index.ts +1 -1
  126. package/src/datastar/README.md +18 -0
  127. package/src/datastar/actions/fetch.ts +609 -0
  128. package/src/datastar/actions/peek.ts +17 -0
  129. package/src/datastar/actions/setAll.ts +20 -0
  130. package/src/datastar/actions/toggleAll.ts +20 -0
  131. package/src/datastar/attributes/attr.ts +50 -0
  132. package/src/datastar/attributes/bind.ts +220 -0
  133. package/src/datastar/attributes/class.ts +57 -0
  134. package/src/datastar/attributes/computed.ts +33 -0
  135. package/src/datastar/attributes/effect.ts +11 -0
  136. package/src/datastar/attributes/indicator.ts +39 -0
  137. package/src/datastar/attributes/init.ts +35 -0
  138. package/src/datastar/attributes/jsonSignals.ts +38 -0
  139. package/src/datastar/attributes/on.ts +71 -0
  140. package/src/datastar/attributes/onIntersect.ts +65 -0
  141. package/src/datastar/attributes/onInterval.ts +39 -0
  142. package/src/datastar/attributes/onSignalPatch.ts +63 -0
  143. package/src/datastar/attributes/ref.ts +12 -0
  144. package/src/datastar/attributes/show.ts +33 -0
  145. package/src/datastar/attributes/signals.ts +22 -0
  146. package/src/datastar/attributes/style.ts +63 -0
  147. package/src/datastar/attributes/text.ts +30 -0
  148. package/src/datastar/engine.ts +1341 -0
  149. package/src/datastar/index.ts +25 -0
  150. package/src/datastar/utils.ts +286 -0
  151. package/src/datastar/watchers/patchElements.ts +554 -0
  152. package/src/datastar/watchers/patchSignals.ts +15 -0
  153. package/src/index.ts +1 -0
  154. package/src/node/{FileSystem.ts → NodeFileSystem.ts} +59 -97
  155. package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
  156. package/src/testing/TestLogger.ts +1 -1
  157. package/src/x/tailwind/plugin.ts +1 -1
  158. package/dist/Random.d.ts +0 -5
  159. package/dist/Random.js +0 -49
  160. package/src/Commander.test.ts +0 -1639
  161. package/src/ContentNegotiation.test.ts +0 -603
  162. package/src/Development.test.ts +0 -119
  163. package/src/Entity.test.ts +0 -592
  164. package/src/FileRouterCodegen.todo.ts +0 -1133
  165. package/src/FileRouterPattern.test.ts +0 -147
  166. package/src/FileRouterPattern.ts +0 -59
  167. package/src/FileRouter_files.test.ts +0 -64
  168. package/src/FileRouter_path.test.ts +0 -145
  169. package/src/FileRouter_tree.test.ts +0 -132
  170. package/src/Http.test.ts +0 -319
  171. package/src/HttpAppExtra.test.ts +0 -103
  172. package/src/HttpUtils.test.ts +0 -85
  173. package/src/PathPattern.test.ts +0 -648
  174. package/src/Random.ts +0 -59
  175. package/src/RouteBody.test.ts +0 -232
  176. package/src/RouteHook.test.ts +0 -40
  177. package/src/RouteHttp.test.ts +0 -2909
  178. package/src/RouteMount.test.ts +0 -481
  179. package/src/RouteSchema.test.ts +0 -427
  180. package/src/RouteSse.test.ts +0 -249
  181. package/src/RouteTree.test.ts +0 -494
  182. package/src/RouteTrie.test.ts +0 -322
  183. package/src/RouterPattern.test.ts +0 -676
  184. package/src/RouterPattern.ts +0 -416
  185. package/src/StartApp.ts +0 -47
  186. package/src/Values.test.ts +0 -263
  187. package/src/bun/BunBundle.test.ts +0 -268
  188. package/src/bun/BunBundle_imports.test.ts +0 -48
  189. package/src/bun/BunHttpServer.test.ts +0 -251
  190. package/src/bun/BunHttpServer.ts +0 -306
  191. package/src/bun/BunImportTrackerPlugin.test.ts +0 -77
  192. package/src/bun/BunRoute.test.ts +0 -162
  193. package/src/bundler/BundleHttp.test.ts +0 -132
  194. package/src/effect/HttpRouter.test.ts +0 -548
  195. package/src/experimental/EncryptedCookies.test.ts +0 -488
  196. package/src/hyper/HyperHtml.test.ts +0 -209
  197. package/src/hyper/HyperRoute.test.tsx +0 -197
  198. package/src/middlewares/BasicAuthMiddleware.test.ts +0 -84
  199. package/src/testing/TestHttpClient.test.ts +0 -83
  200. package/src/testing/TestLogger.test.ts +0 -51
  201. package/src/x/datastar/Datastar.test.ts +0 -266
  202. package/src/x/tailwind/TailwindPlugin.test.ts +0 -333
  203. /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
@@ -1,548 +0,0 @@
1
- /**
2
- * This file tests `@effect/platform/HttpRouter`, not our code.
3
- * Since Platform code is still unstable and we relay heavily on its
4
- * chaining/fallback behavior in `BundleHttp`
5
- * We want to ensure the behavior doesn't change across versions.
6
- */
7
- import * as HttpRouter from "@effect/platform/HttpRouter"
8
- import * as HttpServerResponse from "@effect/platform/HttpServerResponse"
9
- import * as test from "bun:test"
10
- import {
11
- effectFn,
12
- TestHttpClient,
13
- } from "../testing"
14
-
15
- const effect = effectFn()
16
-
17
- test.it("Single app mounted on path", () =>
18
- effect(function*() {
19
- const app1 = HttpRouter.empty.pipe(
20
- HttpRouter.get("/hello", HttpServerResponse.text("Hello from app1")),
21
- )
22
-
23
- const router = HttpRouter.empty.pipe(
24
- HttpRouter.mount("/api", app1),
25
- )
26
-
27
- const client = TestHttpClient.make(router)
28
- const response = yield* client.get("/api/hello")
29
-
30
- test
31
- .expect(response.status)
32
- .toBe(200)
33
- test
34
- .expect(yield* response.text)
35
- .toBe("Hello from app1")
36
- }))
37
-
38
- test.it(
39
- "Multiple apps mounted on same path chain together",
40
- () =>
41
- effect(function*() {
42
- const app1 = HttpRouter.empty.pipe(
43
- HttpRouter.get("/hello", HttpServerResponse.text("Hello from app1")),
44
- )
45
-
46
- const app2 = HttpRouter.empty.pipe(
47
- HttpRouter.get("/world", HttpServerResponse.text("World from app2")),
48
- )
49
-
50
- const router = HttpRouter.empty.pipe(
51
- HttpRouter.mount("/api", app1),
52
- HttpRouter.mount("/api", app2),
53
- )
54
-
55
- const client = TestHttpClient.make(router)
56
-
57
- const response1 = yield* client.get("/api/hello")
58
-
59
- test
60
- .expect(response1.status)
61
- .toBe(200)
62
- test
63
- .expect(yield* response1.text)
64
- .toBe("Hello from app1")
65
-
66
- const response2 = yield* client.get("/api/world")
67
-
68
- test
69
- .expect(response2.status)
70
- .toBe(200)
71
- test
72
- .expect(yield* response2.text)
73
- .toBe("World from app2")
74
- }),
75
- )
76
-
77
- test.it(
78
- "First app has no matching route - second app should be called",
79
- () =>
80
- effect(function*() {
81
- const app1 = HttpRouter.empty.pipe(
82
- HttpRouter.get("/hello", HttpServerResponse.text("Hello from app1")),
83
- )
84
-
85
- const app2 = HttpRouter.empty.pipe(
86
- HttpRouter.get("/missing", HttpServerResponse.text("Found in app2")),
87
- )
88
-
89
- const router = HttpRouter.empty.pipe(
90
- HttpRouter.mount("/api", app1),
91
- HttpRouter.mount("/api", app2),
92
- )
93
-
94
- const client = TestHttpClient.make(router)
95
- const response = yield* client.get("/api/missing")
96
-
97
- test
98
- .expect(response.status)
99
- .toBe(200)
100
- test
101
- .expect(yield* response.text)
102
- .toBe("Found in app2")
103
- }),
104
- )
105
-
106
- test.it(
107
- "First app has no matching route - second app should be called",
108
- () =>
109
- effect(function*() {
110
- const app1 = HttpRouter.empty.pipe(
111
- HttpRouter.get("/specific", HttpServerResponse.text("Specific route")),
112
- )
113
-
114
- const app2 = HttpRouter.empty.pipe(
115
- HttpRouter.get(
116
- "/different",
117
- HttpServerResponse.text("Different route"),
118
- ),
119
- )
120
-
121
- const router = HttpRouter.empty.pipe(
122
- HttpRouter.mount("/api", app1),
123
- HttpRouter.mount("/api", app2),
124
- )
125
-
126
- const client = TestHttpClient.make(router)
127
- const response = yield* client.get("/api/different")
128
-
129
- test
130
- .expect(response.status)
131
- .toBe(200)
132
- test
133
- .expect(yield* response.text)
134
- .toBe("Different route")
135
- }),
136
- )
137
-
138
- test.it("Multiple mounts with different methods", () =>
139
- effect(function*() {
140
- const app1 = HttpRouter.empty.pipe(
141
- HttpRouter.get("/data", HttpServerResponse.text("GET data")),
142
- )
143
-
144
- const app2 = HttpRouter.empty.pipe(
145
- HttpRouter.post("/data", HttpServerResponse.text("POST data")),
146
- )
147
-
148
- const router = HttpRouter.empty.pipe(
149
- HttpRouter.mount("/api", app1),
150
- HttpRouter.mount("/api", app2),
151
- )
152
-
153
- const client = TestHttpClient.make(router)
154
-
155
- const getResponse = yield* client.get("/api/data")
156
-
157
- test
158
- .expect(getResponse.status)
159
- .toBe(200)
160
- test
161
- .expect(yield* getResponse.text)
162
- .toBe("GET data")
163
-
164
- const postResponse = yield* client.post("/api/data")
165
-
166
- test
167
- .expect(postResponse.status)
168
- .toBe(200)
169
- test
170
- .expect(yield* postResponse.text)
171
- .toBe("POST data")
172
- }))
173
-
174
- test.it(
175
- "Route chaining: RouteNotFound error chains to next router (root mount)",
176
- () =>
177
- effect(function*() {
178
- const subApp1 = HttpRouter.empty.pipe(
179
- HttpRouter.get(
180
- "/admin/dashboard",
181
- HttpServerResponse.text("Dashboard from subApp1"),
182
- ),
183
- )
184
-
185
- const subApp2 = HttpRouter.empty.pipe(
186
- HttpRouter.get(
187
- "/admin/page",
188
- HttpServerResponse.text("Page from subApp2"),
189
- ),
190
- )
191
-
192
- const router = HttpRouter.empty.pipe(
193
- HttpRouter.mount("/", subApp1),
194
- HttpRouter.mount("/", subApp2),
195
- )
196
-
197
- const client = TestHttpClient.make(router)
198
- const response = yield* client.get("/admin/page")
199
-
200
- test
201
- .expect(response.status)
202
- .toBe(200)
203
- test
204
- .expect(yield* response.text)
205
- .toBe("Page from subApp2")
206
- }),
207
- )
208
-
209
- test.it(
210
- "Route chaining: explicit 404 response does not chain to next router (root mount)",
211
- () =>
212
- effect(function*() {
213
- const subApp1 = HttpRouter.empty.pipe(
214
- HttpRouter.get(
215
- "/admin/page",
216
- HttpServerResponse.empty({ status: 404 }),
217
- ),
218
- )
219
-
220
- const subApp2 = HttpRouter.empty.pipe(
221
- HttpRouter.get(
222
- "/admin/fallback",
223
- HttpServerResponse.text("Fallback from subApp2"),
224
- ),
225
- )
226
-
227
- const router = HttpRouter.empty.pipe(
228
- HttpRouter.mount("/", subApp1),
229
- HttpRouter.mount("/", subApp2),
230
- )
231
-
232
- const client = TestHttpClient.make(router)
233
- const response = yield* client.get("/admin/page")
234
-
235
- test
236
- .expect(response.status)
237
- .toBe(404)
238
- test
239
- .expect(yield* response.text)
240
- .toBe("")
241
- }),
242
- )
243
-
244
- test.it(
245
- "Route conflicts: direct handlers win when defined before root mount",
246
- () =>
247
- effect(function*() {
248
- const subApp = HttpRouter.empty.pipe(
249
- HttpRouter.get(
250
- "/admin/dashboard",
251
- HttpServerResponse.text("Dashboard from subApp"),
252
- ),
253
- HttpRouter.get(
254
- "/admin/profile",
255
- HttpServerResponse.text("Profile from subApp"),
256
- ),
257
- )
258
-
259
- const router = HttpRouter.empty.pipe(
260
- HttpRouter.get(
261
- "/admin/settings",
262
- HttpServerResponse.text("Settings from direct handler"),
263
- ),
264
- HttpRouter.get(
265
- "/admin/users",
266
- HttpServerResponse.text("Users from direct handler"),
267
- ),
268
- HttpRouter.mount("/", subApp),
269
- )
270
-
271
- const client = TestHttpClient.make(router)
272
-
273
- const settingsResponse = yield* client.get("/admin/settings")
274
-
275
- test
276
- .expect(settingsResponse.status)
277
- .toBe(200)
278
- test
279
- .expect(yield* settingsResponse.text)
280
- .toBe("Settings from direct handler")
281
-
282
- const usersResponse = yield* client.get("/admin/users")
283
-
284
- test
285
- .expect(usersResponse.status)
286
- .toBe(200)
287
- test
288
- .expect(yield* usersResponse.text)
289
- .toBe("Users from direct handler")
290
-
291
- const dashboardResponse = yield* client.get("/admin/dashboard")
292
-
293
- test
294
- .expect(dashboardResponse.status)
295
- .toBe(200)
296
- test
297
- .expect(yield* dashboardResponse.text)
298
- .toBe("Dashboard from subApp")
299
- }),
300
- )
301
-
302
- test.it(
303
- "Route conflicts: root mount wins when defined before direct handlers",
304
- () =>
305
- effect(function*() {
306
- const subApp = HttpRouter.empty.pipe(
307
- HttpRouter.get(
308
- "/admin/dashboard",
309
- HttpServerResponse.text("Dashboard from subApp"),
310
- ),
311
- HttpRouter.get(
312
- "/admin/profile",
313
- HttpServerResponse.text("Profile from subApp"),
314
- ),
315
- )
316
-
317
- const router = HttpRouter.empty.pipe(
318
- HttpRouter.mount("/", subApp),
319
- HttpRouter.get(
320
- "/admin/settings",
321
- HttpServerResponse.text("Settings from direct handler"),
322
- ),
323
- HttpRouter.get(
324
- "/admin/users",
325
- HttpServerResponse.text("Users from direct handler"),
326
- ),
327
- )
328
-
329
- const client = TestHttpClient.make(router)
330
-
331
- const profileResponse = yield* client.get("/admin/profile")
332
-
333
- test
334
- .expect(profileResponse.status)
335
- .toBe(200)
336
- test
337
- .expect(yield* profileResponse.text)
338
- .toBe("Profile from subApp")
339
-
340
- const usersResponse = yield* client.get("/admin/users")
341
-
342
- test
343
- .expect(usersResponse.status)
344
- .toBe(200)
345
- test
346
- .expect(yield* usersResponse.text)
347
- .toBe("Users from direct handler")
348
-
349
- const dashboardResponse = yield* client.get("/admin/dashboard")
350
-
351
- test
352
- .expect(dashboardResponse.status)
353
- .toBe(200)
354
- test
355
- .expect(yield* dashboardResponse.text)
356
- .toBe("Dashboard from subApp")
357
- }),
358
- )
359
-
360
- test.it(
361
- "Route conflicts: mountApp does not chain with direct handlers defined before",
362
- () =>
363
- effect(function*() {
364
- const subApp = HttpRouter.empty.pipe(
365
- HttpRouter.get(
366
- "/admin/dashboard",
367
- HttpServerResponse.text("Dashboard from subApp"),
368
- ),
369
- HttpRouter.get(
370
- "/admin/profile",
371
- HttpServerResponse.text("Profile from subApp"),
372
- ),
373
- )
374
-
375
- const router = HttpRouter.empty.pipe(
376
- HttpRouter.get(
377
- "/admin/settings",
378
- HttpServerResponse.text("Settings from direct handler"),
379
- ),
380
- HttpRouter.get(
381
- "/admin/users",
382
- HttpServerResponse.text("Users from direct handler"),
383
- ),
384
- HttpRouter.mountApp("/", subApp),
385
- )
386
-
387
- const client = TestHttpClient.make(router)
388
-
389
- const settingsResponse = yield* client.get("/admin/settings")
390
-
391
- test
392
- .expect(settingsResponse.status)
393
- .toBe(404)
394
-
395
- const usersResponse = yield* client.get("/admin/users")
396
-
397
- test
398
- .expect(usersResponse.status)
399
- .toBe(404)
400
-
401
- const dashboardResponse = yield* client.get("/admin/dashboard")
402
-
403
- test
404
- .expect(dashboardResponse.status)
405
- .toBe(200)
406
- test
407
- .expect(yield* dashboardResponse.text)
408
- .toBe("Dashboard from subApp")
409
- }),
410
- )
411
-
412
- test.it(
413
- "Route conflicts: mountApp does not chain with direct handlers defined after",
414
- () =>
415
- effect(function*() {
416
- const subApp = HttpRouter.empty.pipe(
417
- HttpRouter.get(
418
- "/admin/dashboard",
419
- HttpServerResponse.text("Dashboard from subApp"),
420
- ),
421
- HttpRouter.get(
422
- "/admin/profile",
423
- HttpServerResponse.text("Profile from subApp"),
424
- ),
425
- )
426
-
427
- const router = HttpRouter.empty.pipe(
428
- HttpRouter.mountApp("/", subApp),
429
- HttpRouter.get(
430
- "/admin/settings",
431
- HttpServerResponse.text("Settings from direct handler"),
432
- ),
433
- HttpRouter.get(
434
- "/admin/users",
435
- HttpServerResponse.text("Users from direct handler"),
436
- ),
437
- )
438
-
439
- const client = TestHttpClient.make(router)
440
-
441
- const profileResponse = yield* client.get("/admin/profile")
442
-
443
- test
444
- .expect(profileResponse.status)
445
- .toBe(200)
446
- test
447
- .expect(yield* profileResponse.text)
448
- .toBe("Profile from subApp")
449
-
450
- const settingsResponse = yield* client.get("/admin/settings")
451
-
452
- test
453
- .expect(settingsResponse.status)
454
- .toBe(404)
455
-
456
- const dashboardResponse = yield* client.get("/admin/dashboard")
457
-
458
- test
459
- .expect(dashboardResponse.status)
460
- .toBe(200)
461
- test
462
- .expect(yield* dashboardResponse.text)
463
- .toBe("Dashboard from subApp")
464
- }),
465
- )
466
-
467
- test.it(
468
- "Wildcard routes: single asterisk wildcard handler",
469
- () =>
470
- effect(function*() {
471
- const router = HttpRouter.empty.pipe(
472
- HttpRouter.get("*", HttpServerResponse.text("Wildcard handler")),
473
- )
474
-
475
- const client = TestHttpClient.make(router)
476
-
477
- const response = yield* client.get("/anything")
478
-
479
- test
480
- .expect(response.status)
481
- .toBe(200)
482
- test
483
- .expect(yield* response.text)
484
- .toBe("Wildcard handler")
485
- }),
486
- )
487
-
488
- test.it(
489
- "Wildcard routes: wildcard defined before literal route",
490
- () =>
491
- effect(function*() {
492
- const router = HttpRouter.empty.pipe(
493
- HttpRouter.get("*", HttpServerResponse.text("Wildcard handler")),
494
- HttpRouter.get("/specific", HttpServerResponse.text("Literal handler")),
495
- )
496
-
497
- const client = TestHttpClient.make(router)
498
-
499
- const wildcardResponse = yield* client.get("/anything")
500
-
501
- test
502
- .expect(wildcardResponse.status)
503
- .toBe(200)
504
- test
505
- .expect(yield* wildcardResponse.text)
506
- .toBe("Wildcard handler")
507
-
508
- const literalResponse = yield* client.get("/specific")
509
-
510
- test
511
- .expect(literalResponse.status)
512
- .toBe(200)
513
- test
514
- .expect(yield* literalResponse.text)
515
- .toBe("Literal handler")
516
- }),
517
- )
518
-
519
- test.it(
520
- "Wildcard routes: literal route defined before wildcard",
521
- () =>
522
- effect(function*() {
523
- const router = HttpRouter.empty.pipe(
524
- HttpRouter.get("/specific", HttpServerResponse.text("Literal handler")),
525
- HttpRouter.get("*", HttpServerResponse.text("Wildcard handler")),
526
- )
527
-
528
- const client = TestHttpClient.make(router)
529
-
530
- const literalResponse = yield* client.get("/specific")
531
-
532
- test
533
- .expect(literalResponse.status)
534
- .toBe(200)
535
- test
536
- .expect(yield* literalResponse.text)
537
- .toBe("Literal handler")
538
-
539
- const wildcardResponse = yield* client.get("/anything")
540
-
541
- test
542
- .expect(wildcardResponse.status)
543
- .toBe(200)
544
- test
545
- .expect(yield* wildcardResponse.text)
546
- .toBe("Wildcard handler")
547
- }),
548
- )