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.
- package/README.md +3 -3
- package/dist/Development.d.ts +8 -3
- package/dist/Development.js +14 -7
- package/dist/Effectify.d.ts +212 -0
- package/dist/Effectify.js +19 -0
- package/dist/FilePathPattern.d.ts +29 -0
- package/dist/FilePathPattern.js +86 -0
- package/dist/FileRouter.d.ts +39 -41
- package/dist/FileRouter.js +104 -158
- package/dist/FileRouterCodegen.d.ts +7 -8
- package/dist/FileRouterCodegen.js +97 -66
- package/dist/PlatformError.d.ts +46 -0
- package/dist/PlatformError.js +43 -0
- package/dist/PlatformRuntime.d.ts +27 -0
- package/dist/PlatformRuntime.js +51 -0
- package/dist/Route.d.ts +6 -2
- package/dist/Route.js +22 -0
- package/dist/RouteBody.d.ts +1 -1
- package/dist/RouteHttp.d.ts +1 -1
- package/dist/RouteHttp.js +12 -19
- package/dist/RouteMount.d.ts +2 -1
- package/dist/Start.d.ts +33 -6
- package/dist/Start.js +31 -13
- package/dist/Unique.d.ts +50 -0
- package/dist/Unique.js +187 -0
- package/dist/bun/BunHttpServer.js +5 -6
- package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
- package/dist/bun/BunPlatformHttpServer.js +53 -0
- package/dist/bun/BunRoute.d.ts +4 -6
- package/dist/bun/BunRoute.js +10 -18
- package/dist/bun/BunRuntime.d.ts +2 -1
- package/dist/bun/BunRuntime.js +10 -5
- package/dist/bun/BunServer.d.ts +33 -0
- package/dist/bun/BunServer.js +133 -0
- package/dist/bun/BunServerRequest.d.ts +60 -0
- package/dist/bun/BunServerRequest.js +252 -0
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +1 -1
- package/dist/datastar/actions/fetch.d.ts +30 -0
- package/dist/datastar/actions/fetch.js +411 -0
- package/dist/datastar/actions/peek.d.ts +1 -0
- package/dist/datastar/actions/peek.js +14 -0
- package/dist/datastar/actions/setAll.d.ts +1 -0
- package/dist/datastar/actions/setAll.js +13 -0
- package/dist/datastar/actions/toggleAll.d.ts +1 -0
- package/dist/datastar/actions/toggleAll.js +13 -0
- package/dist/datastar/attributes/attr.d.ts +1 -0
- package/dist/datastar/attributes/attr.js +49 -0
- package/dist/datastar/attributes/bind.d.ts +1 -0
- package/dist/datastar/attributes/bind.js +183 -0
- package/dist/datastar/attributes/class.d.ts +1 -0
- package/dist/datastar/attributes/class.js +50 -0
- package/dist/datastar/attributes/computed.d.ts +1 -0
- package/dist/datastar/attributes/computed.js +27 -0
- package/dist/datastar/attributes/effect.d.ts +1 -0
- package/dist/datastar/attributes/effect.js +10 -0
- package/dist/datastar/attributes/indicator.d.ts +1 -0
- package/dist/datastar/attributes/indicator.js +32 -0
- package/dist/datastar/attributes/init.d.ts +1 -0
- package/dist/datastar/attributes/init.js +27 -0
- package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
- package/dist/datastar/attributes/jsonSignals.js +31 -0
- package/dist/datastar/attributes/on.d.ts +1 -0
- package/dist/datastar/attributes/on.js +59 -0
- package/dist/datastar/attributes/onIntersect.d.ts +1 -0
- package/dist/datastar/attributes/onIntersect.js +54 -0
- package/dist/datastar/attributes/onInterval.d.ts +1 -0
- package/dist/datastar/attributes/onInterval.js +31 -0
- package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
- package/dist/datastar/attributes/onSignalPatch.js +44 -0
- package/dist/datastar/attributes/ref.d.ts +1 -0
- package/dist/datastar/attributes/ref.js +11 -0
- package/dist/datastar/attributes/show.d.ts +1 -0
- package/dist/datastar/attributes/show.js +32 -0
- package/dist/datastar/attributes/signals.d.ts +1 -0
- package/dist/datastar/attributes/signals.js +18 -0
- package/dist/datastar/attributes/style.d.ts +1 -0
- package/dist/datastar/attributes/style.js +56 -0
- package/dist/datastar/attributes/text.d.ts +1 -0
- package/dist/datastar/attributes/text.js +27 -0
- package/dist/datastar/engine.d.ts +156 -0
- package/dist/datastar/engine.js +971 -0
- package/dist/datastar/index.d.ts +24 -0
- package/dist/datastar/index.js +24 -0
- package/dist/datastar/load.d.ts +24 -0
- package/dist/datastar/load.js +24 -0
- package/dist/datastar/utils.d.ts +51 -0
- package/dist/datastar/utils.js +205 -0
- package/dist/datastar/watchers/patchElements.d.ts +1 -0
- package/dist/datastar/watchers/patchElements.js +420 -0
- package/dist/datastar/watchers/patchSignals.d.ts +1 -0
- package/dist/datastar/watchers/patchSignals.js +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/node/Effectify.d.ts +209 -0
- package/dist/node/Effectify.js +19 -0
- package/dist/node/FileSystem.d.ts +3 -5
- package/dist/node/FileSystem.js +42 -62
- package/dist/node/NodeFileSystem.d.ts +7 -0
- package/dist/node/NodeFileSystem.js +420 -0
- package/dist/node/NodeUtils.d.ts +2 -0
- package/dist/node/NodeUtils.js +20 -0
- package/dist/node/PlatformError.d.ts +46 -0
- package/dist/node/PlatformError.js +43 -0
- package/dist/testing/TestLogger.js +1 -1
- package/dist/x/tailwind/plugin.js +1 -1
- package/package.json +18 -7
- package/src/Development.ts +36 -40
- package/src/Effectify.ts +269 -0
- package/src/FilePathPattern.ts +115 -0
- package/src/FileRouter.ts +178 -255
- package/src/FileRouterCodegen.ts +135 -92
- package/src/PlatformError.ts +117 -0
- package/src/PlatformRuntime.ts +108 -0
- package/src/Route.ts +31 -2
- package/src/RouteBody.ts +1 -1
- package/src/RouteHttp.ts +15 -29
- package/src/RouteMount.ts +1 -1
- package/src/Start.ts +61 -27
- package/src/Unique.ts +232 -0
- package/src/bun/BunPlatformHttpServer.ts +88 -0
- package/src/bun/BunRoute.ts +14 -24
- package/src/bun/BunRuntime.ts +21 -5
- package/src/bun/BunServer.ts +228 -0
- package/src/bun/index.ts +1 -1
- package/src/datastar/README.md +18 -0
- package/src/datastar/actions/fetch.ts +609 -0
- package/src/datastar/actions/peek.ts +17 -0
- package/src/datastar/actions/setAll.ts +20 -0
- package/src/datastar/actions/toggleAll.ts +20 -0
- package/src/datastar/attributes/attr.ts +50 -0
- package/src/datastar/attributes/bind.ts +220 -0
- package/src/datastar/attributes/class.ts +57 -0
- package/src/datastar/attributes/computed.ts +33 -0
- package/src/datastar/attributes/effect.ts +11 -0
- package/src/datastar/attributes/indicator.ts +39 -0
- package/src/datastar/attributes/init.ts +35 -0
- package/src/datastar/attributes/jsonSignals.ts +38 -0
- package/src/datastar/attributes/on.ts +71 -0
- package/src/datastar/attributes/onIntersect.ts +65 -0
- package/src/datastar/attributes/onInterval.ts +39 -0
- package/src/datastar/attributes/onSignalPatch.ts +63 -0
- package/src/datastar/attributes/ref.ts +12 -0
- package/src/datastar/attributes/show.ts +33 -0
- package/src/datastar/attributes/signals.ts +22 -0
- package/src/datastar/attributes/style.ts +63 -0
- package/src/datastar/attributes/text.ts +30 -0
- package/src/datastar/engine.ts +1341 -0
- package/src/datastar/index.ts +25 -0
- package/src/datastar/utils.ts +286 -0
- package/src/datastar/watchers/patchElements.ts +554 -0
- package/src/datastar/watchers/patchSignals.ts +15 -0
- package/src/index.ts +1 -0
- package/src/node/{FileSystem.ts → NodeFileSystem.ts} +59 -97
- package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
- package/src/testing/TestLogger.ts +1 -1
- package/src/x/tailwind/plugin.ts +1 -1
- package/dist/Random.d.ts +0 -5
- package/dist/Random.js +0 -49
- package/src/Commander.test.ts +0 -1639
- package/src/ContentNegotiation.test.ts +0 -603
- package/src/Development.test.ts +0 -119
- package/src/Entity.test.ts +0 -592
- package/src/FileRouterCodegen.todo.ts +0 -1133
- package/src/FileRouterPattern.test.ts +0 -147
- package/src/FileRouterPattern.ts +0 -59
- package/src/FileRouter_files.test.ts +0 -64
- package/src/FileRouter_path.test.ts +0 -145
- package/src/FileRouter_tree.test.ts +0 -132
- package/src/Http.test.ts +0 -319
- package/src/HttpAppExtra.test.ts +0 -103
- package/src/HttpUtils.test.ts +0 -85
- package/src/PathPattern.test.ts +0 -648
- package/src/Random.ts +0 -59
- package/src/RouteBody.test.ts +0 -232
- package/src/RouteHook.test.ts +0 -40
- package/src/RouteHttp.test.ts +0 -2909
- package/src/RouteMount.test.ts +0 -481
- package/src/RouteSchema.test.ts +0 -427
- package/src/RouteSse.test.ts +0 -249
- package/src/RouteTree.test.ts +0 -494
- package/src/RouteTrie.test.ts +0 -322
- package/src/RouterPattern.test.ts +0 -676
- package/src/RouterPattern.ts +0 -416
- package/src/StartApp.ts +0 -47
- package/src/Values.test.ts +0 -263
- package/src/bun/BunBundle.test.ts +0 -268
- package/src/bun/BunBundle_imports.test.ts +0 -48
- package/src/bun/BunHttpServer.test.ts +0 -251
- package/src/bun/BunHttpServer.ts +0 -306
- package/src/bun/BunImportTrackerPlugin.test.ts +0 -77
- package/src/bun/BunRoute.test.ts +0 -162
- package/src/bundler/BundleHttp.test.ts +0 -132
- package/src/effect/HttpRouter.test.ts +0 -548
- package/src/experimental/EncryptedCookies.test.ts +0 -488
- package/src/hyper/HyperHtml.test.ts +0 -209
- package/src/hyper/HyperRoute.test.tsx +0 -197
- package/src/middlewares/BasicAuthMiddleware.test.ts +0 -84
- package/src/testing/TestHttpClient.test.ts +0 -83
- package/src/testing/TestLogger.test.ts +0 -51
- package/src/x/datastar/Datastar.test.ts +0 -266
- package/src/x/tailwind/TailwindPlugin.test.ts +0 -333
- /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
package/src/RouteMount.test.ts
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
import * as HttpServerRequest from "@effect/platform/HttpServerRequest"
|
|
2
|
-
import * as test from "bun:test"
|
|
3
|
-
import * as Effect from "effect/Effect"
|
|
4
|
-
import * as ParseResult from "effect/ParseResult"
|
|
5
|
-
import * as Schema from "effect/Schema"
|
|
6
|
-
import * as Route from "./Route.ts"
|
|
7
|
-
import * as RouteMount from "./RouteMount.ts"
|
|
8
|
-
|
|
9
|
-
test.it("uses GET method", async () => {
|
|
10
|
-
const route = Route.get(
|
|
11
|
-
Route.text((context) =>
|
|
12
|
-
Effect.gen(function*() {
|
|
13
|
-
test
|
|
14
|
-
.expectTypeOf(context)
|
|
15
|
-
.toMatchObjectType<{
|
|
16
|
-
method: "GET"
|
|
17
|
-
format: "text"
|
|
18
|
-
request: Request
|
|
19
|
-
}>()
|
|
20
|
-
test
|
|
21
|
-
.expect(context.method)
|
|
22
|
-
.toEqual("GET")
|
|
23
|
-
test
|
|
24
|
-
.expect(context.format)
|
|
25
|
-
.toEqual("text")
|
|
26
|
-
|
|
27
|
-
return "Hello, World!"
|
|
28
|
-
})
|
|
29
|
-
),
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
test
|
|
33
|
-
.expectTypeOf(route)
|
|
34
|
-
.toMatchTypeOf<
|
|
35
|
-
Route.RouteSet.RouteSet<
|
|
36
|
-
{},
|
|
37
|
-
{},
|
|
38
|
-
[
|
|
39
|
-
Route.Route.Route<
|
|
40
|
-
{
|
|
41
|
-
method: "GET"
|
|
42
|
-
format: "text"
|
|
43
|
-
},
|
|
44
|
-
{},
|
|
45
|
-
string
|
|
46
|
-
>,
|
|
47
|
-
]
|
|
48
|
-
>
|
|
49
|
-
>()
|
|
50
|
-
|
|
51
|
-
test
|
|
52
|
-
.expect(Route.items(route))
|
|
53
|
-
.toHaveLength(1)
|
|
54
|
-
|
|
55
|
-
test
|
|
56
|
-
.expectTypeOf<Route.Route.Context<typeof route>>()
|
|
57
|
-
.toMatchTypeOf<{
|
|
58
|
-
method: "GET"
|
|
59
|
-
format: "text"
|
|
60
|
-
}>()
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test.it("uses GET & POST method", async () => {
|
|
64
|
-
const route = Route
|
|
65
|
-
.get(
|
|
66
|
-
Route.text((r) => {
|
|
67
|
-
test
|
|
68
|
-
.expectTypeOf(r.method)
|
|
69
|
-
.toEqualTypeOf<"GET">()
|
|
70
|
-
test
|
|
71
|
-
.expectTypeOf(r.format)
|
|
72
|
-
.toEqualTypeOf<"text">()
|
|
73
|
-
|
|
74
|
-
return Effect.succeed("get")
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
.post(
|
|
78
|
-
Route.text((r) => {
|
|
79
|
-
test
|
|
80
|
-
.expectTypeOf(r.method)
|
|
81
|
-
.toEqualTypeOf<"POST">()
|
|
82
|
-
test
|
|
83
|
-
.expectTypeOf(r.format)
|
|
84
|
-
.toEqualTypeOf<"text">()
|
|
85
|
-
|
|
86
|
-
return Effect.succeed("post")
|
|
87
|
-
}),
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
test
|
|
91
|
-
.expect(Route.items(route))
|
|
92
|
-
.toHaveLength(2)
|
|
93
|
-
|
|
94
|
-
type Items = Route.RouteSet.Items<typeof route>
|
|
95
|
-
|
|
96
|
-
test
|
|
97
|
-
.expectTypeOf<Items[0]>()
|
|
98
|
-
.toExtend<
|
|
99
|
-
Route.Route.Route<
|
|
100
|
-
{
|
|
101
|
-
method: "GET"
|
|
102
|
-
format: "text"
|
|
103
|
-
},
|
|
104
|
-
{},
|
|
105
|
-
string
|
|
106
|
-
>
|
|
107
|
-
>()
|
|
108
|
-
|
|
109
|
-
test
|
|
110
|
-
.expectTypeOf<Items[1]>()
|
|
111
|
-
.toExtend<
|
|
112
|
-
Route.Route.Route<
|
|
113
|
-
{
|
|
114
|
-
method: "POST"
|
|
115
|
-
format: "text"
|
|
116
|
-
},
|
|
117
|
-
{},
|
|
118
|
-
string
|
|
119
|
-
>
|
|
120
|
-
>()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
test.describe("use", () => {
|
|
124
|
-
test.it(`infers context`, () => {
|
|
125
|
-
const routes = Route
|
|
126
|
-
.use(
|
|
127
|
-
Route.filter({
|
|
128
|
-
context: {
|
|
129
|
-
answer: 42,
|
|
130
|
-
},
|
|
131
|
-
}),
|
|
132
|
-
)
|
|
133
|
-
.use(
|
|
134
|
-
Route.filter((ctx) => {
|
|
135
|
-
test
|
|
136
|
-
.expectTypeOf(ctx)
|
|
137
|
-
.toMatchObjectType<{
|
|
138
|
-
answer: number
|
|
139
|
-
}>()
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
context: {
|
|
143
|
-
doubledAnswer: ctx.answer * 2,
|
|
144
|
-
},
|
|
145
|
-
}
|
|
146
|
-
}),
|
|
147
|
-
)
|
|
148
|
-
.get(
|
|
149
|
-
Route.filter({
|
|
150
|
-
context: {
|
|
151
|
-
getter: true,
|
|
152
|
-
},
|
|
153
|
-
}),
|
|
154
|
-
Route.text(function*(ctx) {
|
|
155
|
-
test
|
|
156
|
-
.expectTypeOf(ctx)
|
|
157
|
-
.toMatchObjectType<{
|
|
158
|
-
method: "GET"
|
|
159
|
-
format: "text"
|
|
160
|
-
answer: number
|
|
161
|
-
doubledAnswer: number
|
|
162
|
-
getter: boolean
|
|
163
|
-
}>()
|
|
164
|
-
|
|
165
|
-
return `The answer is ${ctx.answer}`
|
|
166
|
-
}),
|
|
167
|
-
)
|
|
168
|
-
.post(
|
|
169
|
-
Route.json(function*(ctx) {
|
|
170
|
-
test
|
|
171
|
-
.expectTypeOf(ctx)
|
|
172
|
-
.not
|
|
173
|
-
.toHaveProperty("getter")
|
|
174
|
-
|
|
175
|
-
test
|
|
176
|
-
.expectTypeOf(ctx)
|
|
177
|
-
.toMatchObjectType<{
|
|
178
|
-
method: "POST"
|
|
179
|
-
answer: number
|
|
180
|
-
doubledAnswer: number
|
|
181
|
-
format: "json"
|
|
182
|
-
}>()
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
ok: true,
|
|
186
|
-
answer: ctx.answer,
|
|
187
|
-
}
|
|
188
|
-
}),
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
type Items = Route.RouteSet.Items<typeof routes>
|
|
192
|
-
|
|
193
|
-
test
|
|
194
|
-
.expect(Route.items(routes))
|
|
195
|
-
.toHaveLength(5)
|
|
196
|
-
|
|
197
|
-
// First use() - adds answer context (method flattened into Route descriptor)
|
|
198
|
-
test
|
|
199
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[0]>>()
|
|
200
|
-
.toMatchObjectType<{ method: "*" }>()
|
|
201
|
-
|
|
202
|
-
test
|
|
203
|
-
.expectTypeOf<Route.Route.Bindings<Items[0]>>()
|
|
204
|
-
.toMatchTypeOf<{ answer: number }>()
|
|
205
|
-
|
|
206
|
-
test
|
|
207
|
-
.expectTypeOf<Route.Route.Context<Items[0]>>()
|
|
208
|
-
.toMatchTypeOf<{
|
|
209
|
-
method: "*"
|
|
210
|
-
answer: number
|
|
211
|
-
}>()
|
|
212
|
-
|
|
213
|
-
// Second use() - adds doubledAnswer context, inherits answer binding (method flattened into Route descriptor)
|
|
214
|
-
test
|
|
215
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[1]>>()
|
|
216
|
-
.toMatchObjectType<{ method: "*" }>()
|
|
217
|
-
|
|
218
|
-
test
|
|
219
|
-
.expectTypeOf<Route.Route.Bindings<Items[1]>>()
|
|
220
|
-
.toMatchTypeOf<{
|
|
221
|
-
answer: number
|
|
222
|
-
doubledAnswer: number
|
|
223
|
-
}>()
|
|
224
|
-
|
|
225
|
-
test
|
|
226
|
-
.expectTypeOf<Route.Route.Context<Items[1]>>()
|
|
227
|
-
.toMatchTypeOf<{
|
|
228
|
-
method: "*"
|
|
229
|
-
answer: number
|
|
230
|
-
doubledAnswer: number
|
|
231
|
-
}>()
|
|
232
|
-
|
|
233
|
-
// GET filter route
|
|
234
|
-
test
|
|
235
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[2]>>()
|
|
236
|
-
.toMatchObjectType<{ method: "GET" }>()
|
|
237
|
-
|
|
238
|
-
test
|
|
239
|
-
.expectTypeOf<Route.Route.Bindings<Items[2]>>()
|
|
240
|
-
.toMatchTypeOf<{
|
|
241
|
-
answer: number
|
|
242
|
-
doubledAnswer: number
|
|
243
|
-
getter: boolean
|
|
244
|
-
}>()
|
|
245
|
-
|
|
246
|
-
test
|
|
247
|
-
.expectTypeOf<Route.Route.Context<Items[2]>>()
|
|
248
|
-
.toMatchTypeOf<{
|
|
249
|
-
method: "GET"
|
|
250
|
-
answer: number
|
|
251
|
-
doubledAnswer: number
|
|
252
|
-
getter: boolean
|
|
253
|
-
}>()
|
|
254
|
-
|
|
255
|
-
// GET text route
|
|
256
|
-
test
|
|
257
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[3]>>()
|
|
258
|
-
.toMatchObjectType<{
|
|
259
|
-
method: "GET"
|
|
260
|
-
format: "text"
|
|
261
|
-
}>()
|
|
262
|
-
|
|
263
|
-
test
|
|
264
|
-
.expectTypeOf<Route.Route.Bindings<Items[3]>>()
|
|
265
|
-
.toMatchTypeOf<{
|
|
266
|
-
answer: number
|
|
267
|
-
doubledAnswer: number
|
|
268
|
-
getter: boolean
|
|
269
|
-
}>()
|
|
270
|
-
|
|
271
|
-
test
|
|
272
|
-
.expectTypeOf<Route.Route.Context<Items[3]>>()
|
|
273
|
-
.toMatchTypeOf<{
|
|
274
|
-
method: "GET"
|
|
275
|
-
format: "text"
|
|
276
|
-
answer: number
|
|
277
|
-
doubledAnswer: number
|
|
278
|
-
getter: boolean
|
|
279
|
-
}>()
|
|
280
|
-
|
|
281
|
-
// POST route - inherits answer/doubledAnswer only (no getter since that was in GET branch)
|
|
282
|
-
test
|
|
283
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[4]>>()
|
|
284
|
-
.toMatchObjectType<{
|
|
285
|
-
method: "POST"
|
|
286
|
-
format: "json"
|
|
287
|
-
}>()
|
|
288
|
-
|
|
289
|
-
test
|
|
290
|
-
.expectTypeOf<Route.Route.Bindings<Items[4]>>()
|
|
291
|
-
.toMatchTypeOf<{
|
|
292
|
-
answer: number
|
|
293
|
-
doubledAnswer: number
|
|
294
|
-
}>()
|
|
295
|
-
|
|
296
|
-
test
|
|
297
|
-
.expectTypeOf<Route.Route.Context<Items[4]>>()
|
|
298
|
-
.toMatchTypeOf<{
|
|
299
|
-
method: "POST"
|
|
300
|
-
format: "json"
|
|
301
|
-
answer: number
|
|
302
|
-
doubledAnswer: number
|
|
303
|
-
}>()
|
|
304
|
-
})
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
test.it("Builder extends RouteSet", () => {
|
|
308
|
-
const builder = Route
|
|
309
|
-
.use(
|
|
310
|
-
Route.filter({
|
|
311
|
-
context: { answer: 42 },
|
|
312
|
-
}),
|
|
313
|
-
)
|
|
314
|
-
.get(Route.text("Hello"))
|
|
315
|
-
|
|
316
|
-
test
|
|
317
|
-
.expectTypeOf(builder)
|
|
318
|
-
.toExtend<Route.RouteSet.Any>()
|
|
319
|
-
|
|
320
|
-
test
|
|
321
|
-
.expectTypeOf(builder)
|
|
322
|
-
.toExtend<Route.RouteSet.RouteSet<any, any, any>>()
|
|
323
|
-
|
|
324
|
-
// Verify it has the TypeId
|
|
325
|
-
test
|
|
326
|
-
.expect(builder[Route.TypeId])
|
|
327
|
-
.toBe(Route.TypeId)
|
|
328
|
-
|
|
329
|
-
// Verify it's iterable (from RouteSet.Proto)
|
|
330
|
-
test
|
|
331
|
-
.expect(Symbol.iterator in builder)
|
|
332
|
-
.toBe(true)
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
test.it("schemaHeaders flattens method into route descriptor", () => {
|
|
336
|
-
const routes = Route
|
|
337
|
-
.use(
|
|
338
|
-
Route.schemaHeaders(
|
|
339
|
-
Schema.Struct({
|
|
340
|
-
"hello": Schema.String,
|
|
341
|
-
}),
|
|
342
|
-
),
|
|
343
|
-
)
|
|
344
|
-
.get(
|
|
345
|
-
Route.schemaHeaders(
|
|
346
|
-
Schema.Struct({
|
|
347
|
-
"x-custom-header": Schema.String,
|
|
348
|
-
}),
|
|
349
|
-
),
|
|
350
|
-
Route.html(function*(_ctx) {
|
|
351
|
-
return `<h1>Hello, world!</h1>`
|
|
352
|
-
}),
|
|
353
|
-
)
|
|
354
|
-
.post(
|
|
355
|
-
Route.filter({
|
|
356
|
-
context: {
|
|
357
|
-
postOnly: "yo",
|
|
358
|
-
},
|
|
359
|
-
}),
|
|
360
|
-
Route.text(function*(ctx) {
|
|
361
|
-
return "hello"
|
|
362
|
-
}),
|
|
363
|
-
)
|
|
364
|
-
|
|
365
|
-
type Items = Route.RouteSet.Items<typeof routes>
|
|
366
|
-
|
|
367
|
-
// Assert routes is a Builder with specific descriptor
|
|
368
|
-
test
|
|
369
|
-
.expectTypeOf(routes)
|
|
370
|
-
.toExtend<
|
|
371
|
-
RouteMount.RouteMount.Builder<
|
|
372
|
-
{},
|
|
373
|
-
Items
|
|
374
|
-
>
|
|
375
|
-
>()
|
|
376
|
-
|
|
377
|
-
test
|
|
378
|
-
.expect(Route.items(routes))
|
|
379
|
-
.toHaveLength(5)
|
|
380
|
-
|
|
381
|
-
// First use() - schemaHeaders with method "*"
|
|
382
|
-
test
|
|
383
|
-
.expectTypeOf<Items[0]>()
|
|
384
|
-
.toExtend<
|
|
385
|
-
Route.Route.Route<
|
|
386
|
-
{ method: "*" },
|
|
387
|
-
{
|
|
388
|
-
headers: {
|
|
389
|
-
readonly hello: string
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
unknown,
|
|
393
|
-
ParseResult.ParseError,
|
|
394
|
-
HttpServerRequest.HttpServerRequest
|
|
395
|
-
>
|
|
396
|
-
>()
|
|
397
|
-
|
|
398
|
-
// GET schemaHeaders
|
|
399
|
-
test
|
|
400
|
-
.expectTypeOf<Items[1]>()
|
|
401
|
-
.toExtend<
|
|
402
|
-
Route.Route.Route<
|
|
403
|
-
{ method: "GET" },
|
|
404
|
-
{
|
|
405
|
-
headers: {
|
|
406
|
-
readonly hello: string
|
|
407
|
-
readonly "x-custom-header": string
|
|
408
|
-
}
|
|
409
|
-
},
|
|
410
|
-
unknown,
|
|
411
|
-
ParseResult.ParseError,
|
|
412
|
-
HttpServerRequest.HttpServerRequest
|
|
413
|
-
>
|
|
414
|
-
>()
|
|
415
|
-
|
|
416
|
-
// GET html route
|
|
417
|
-
test
|
|
418
|
-
.expectTypeOf<Items[2]>()
|
|
419
|
-
.toExtend<
|
|
420
|
-
Route.Route.Route<
|
|
421
|
-
{
|
|
422
|
-
method: "GET"
|
|
423
|
-
format: "html"
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
headers: {
|
|
427
|
-
readonly hello: string
|
|
428
|
-
readonly "x-custom-header": string
|
|
429
|
-
}
|
|
430
|
-
},
|
|
431
|
-
any
|
|
432
|
-
>
|
|
433
|
-
>()
|
|
434
|
-
|
|
435
|
-
// POST filter route
|
|
436
|
-
test
|
|
437
|
-
.expectTypeOf<Items[3]>()
|
|
438
|
-
.toExtend<
|
|
439
|
-
Route.Route.Route<
|
|
440
|
-
{ method: "POST" },
|
|
441
|
-
{
|
|
442
|
-
headers: {
|
|
443
|
-
readonly hello: string
|
|
444
|
-
}
|
|
445
|
-
postOnly: string
|
|
446
|
-
},
|
|
447
|
-
unknown
|
|
448
|
-
>
|
|
449
|
-
>()
|
|
450
|
-
|
|
451
|
-
// POST text route - verify descriptor and bindings separately
|
|
452
|
-
test
|
|
453
|
-
.expectTypeOf<Route.RouteSet.Descriptor<Items[4]>>()
|
|
454
|
-
.toMatchObjectType<{
|
|
455
|
-
method: "POST"
|
|
456
|
-
format: "text"
|
|
457
|
-
}>()
|
|
458
|
-
|
|
459
|
-
test
|
|
460
|
-
.expectTypeOf<Route.Route.Context<Items[4]>>()
|
|
461
|
-
.toMatchTypeOf<{
|
|
462
|
-
method: "POST"
|
|
463
|
-
format: "text"
|
|
464
|
-
headers: {
|
|
465
|
-
readonly hello: string
|
|
466
|
-
}
|
|
467
|
-
postOnly: string
|
|
468
|
-
}>()
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
test.it("provides request in default bindings", () => {
|
|
472
|
-
Route.get(
|
|
473
|
-
Route.text((ctx) => {
|
|
474
|
-
test
|
|
475
|
-
.expectTypeOf(ctx.request)
|
|
476
|
-
.toEqualTypeOf<Request>()
|
|
477
|
-
|
|
478
|
-
return Effect.succeed("ok")
|
|
479
|
-
}),
|
|
480
|
-
)
|
|
481
|
-
})
|