effect-start 0.21.0 → 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.
- package/README.md +1 -4
- package/dist/Cookies.js +392 -0
- package/dist/FileSystem.js +131 -0
- package/dist/Socket.js +37 -0
- package/package.json +35 -36
- package/src/Commander.ts +73 -130
- package/src/ContentNegotiation.ts +64 -95
- package/src/Cookies.ts +36 -57
- package/src/Development.ts +47 -62
- package/src/Effectify.ts +222 -206
- package/src/Entity.ts +59 -86
- package/src/FilePathPattern.ts +5 -5
- package/src/FileRouter.ts +37 -62
- package/src/FileRouterCodegen.ts +63 -55
- package/src/FileSystem.ts +46 -59
- package/src/Http.ts +17 -50
- package/src/PathPattern.ts +33 -41
- package/src/PlatformError.ts +29 -50
- package/src/PlatformRuntime.ts +39 -47
- package/src/Route.ts +68 -187
- package/src/RouteBody.ts +45 -161
- package/src/RouteHook.ts +22 -45
- package/src/RouteHttp.ts +88 -142
- package/src/RouteHttpTracer.ts +25 -26
- package/src/RouteMount.ts +100 -238
- package/src/RouteSchema.ts +67 -201
- package/src/RouteSse.ts +28 -82
- package/src/RouteTree.ts +31 -79
- package/src/RouteTrie.ts +13 -32
- package/src/SchemaExtra.ts +3 -5
- package/src/Socket.ts +5 -2
- package/src/Start.ts +20 -21
- package/src/StreamExtra.ts +93 -96
- package/src/TuplePathPattern.ts +54 -43
- package/src/Unique.ts +9 -15
- package/src/Values.ts +26 -30
- package/src/bun/BunBundle.ts +27 -73
- package/src/bun/BunImportTrackerPlugin.ts +67 -65
- package/src/bun/BunRoute.ts +12 -31
- package/src/bun/BunRuntime.ts +3 -10
- package/src/bun/BunServer.ts +55 -91
- package/src/bun/BunVirtualFilesPlugin.ts +1 -4
- package/src/bun/_BunEnhancedResolve.ts +17 -42
- package/src/bun/_empty.html +0 -1
- package/src/bundler/Bundle.ts +20 -36
- package/src/bundler/BundleFiles.ts +35 -55
- package/src/client/Overlay.ts +1 -2
- package/src/client/ScrollState.ts +5 -9
- package/src/client/index.ts +10 -13
- package/src/datastar/actions/fetch.ts +29 -48
- package/src/datastar/actions/peek.ts +1 -5
- package/src/datastar/actions/setAll.ts +2 -2
- package/src/datastar/actions/toggleAll.ts +2 -2
- package/src/datastar/attributes/attr.ts +17 -18
- package/src/datastar/attributes/bind.ts +41 -61
- package/src/datastar/attributes/class.ts +2 -5
- package/src/datastar/attributes/computed.ts +2 -10
- package/src/datastar/attributes/effect.ts +1 -2
- package/src/datastar/attributes/indicator.ts +2 -8
- package/src/datastar/attributes/init.ts +2 -10
- package/src/datastar/attributes/jsonSignals.ts +1 -6
- package/src/datastar/attributes/on.ts +4 -13
- package/src/datastar/attributes/onIntersect.ts +10 -22
- package/src/datastar/attributes/onInterval.ts +2 -10
- package/src/datastar/attributes/onSignalPatch.ts +18 -28
- package/src/datastar/attributes/ref.ts +1 -2
- package/src/datastar/attributes/show.ts +1 -2
- package/src/datastar/attributes/signals.ts +1 -5
- package/src/datastar/attributes/style.ts +6 -12
- package/src/datastar/attributes/text.ts +1 -2
- package/src/datastar/engine.ts +102 -158
- package/src/datastar/index.ts +2 -2
- package/src/datastar/utils.ts +16 -51
- package/src/datastar/watchers/patchElements.ts +35 -93
- package/src/datastar/watchers/patchSignals.ts +1 -2
- package/src/experimental/EncryptedCookies.ts +79 -142
- package/src/hyper/Hyper.ts +14 -33
- package/src/hyper/HyperHtml.ts +9 -10
- package/src/hyper/HyperNode.ts +2 -7
- package/src/hyper/HyperRoute.ts +2 -5
- package/src/hyper/jsx-runtime.ts +2 -10
- package/src/hyper/jsx.d.ts +171 -440
- package/src/lint/plugin.js +276 -0
- package/src/node/NodeFileSystem.ts +138 -186
- package/src/node/NodeUtils.ts +1 -3
- package/src/testing/TestLogger.ts +9 -22
- package/src/testing/utils.ts +30 -31
- package/src/x/cloudflare/CloudflareTunnel.ts +37 -54
- package/src/x/datastar/Datastar.ts +3 -10
- package/src/x/datastar/index.ts +1 -3
- package/src/x/datastar/jsx-datastar.d.ts +1 -4
- package/src/x/tailwind/TailwindPlugin.ts +119 -112
- package/src/x/tailwind/compile.ts +10 -33
- package/src/x/tailwind/plugin.ts +2 -2
package/src/RouteHttp.ts
CHANGED
|
@@ -4,16 +4,16 @@ import * as FiberId from "effect/FiberId"
|
|
|
4
4
|
import * as FiberRef from "effect/FiberRef"
|
|
5
5
|
import * as HashSet from "effect/HashSet"
|
|
6
6
|
import * as Option from "effect/Option"
|
|
7
|
-
import * as ParseResult from "effect/ParseResult"
|
|
7
|
+
import type * as ParseResult from "effect/ParseResult"
|
|
8
8
|
import * as Runtime from "effect/Runtime"
|
|
9
9
|
import * as Stream from "effect/Stream"
|
|
10
10
|
import * as ContentNegotiation from "./ContentNegotiation.ts"
|
|
11
11
|
import * as Entity from "./Entity.ts"
|
|
12
|
-
import * as Http from "./Http.ts"
|
|
12
|
+
import type * as Http from "./Http.ts"
|
|
13
13
|
import * as Route from "./Route.ts"
|
|
14
|
-
import * as RouteBody from "./RouteBody.ts"
|
|
14
|
+
import type * as RouteBody from "./RouteBody.ts"
|
|
15
15
|
import * as RouteHttpTracer from "./RouteHttpTracer.ts"
|
|
16
|
-
import * as RouteMount from "./RouteMount.ts"
|
|
16
|
+
import type * as RouteMount from "./RouteMount.ts"
|
|
17
17
|
import * as RouteTree from "./RouteTree.ts"
|
|
18
18
|
import * as StreamExtra from "./StreamExtra.ts"
|
|
19
19
|
|
|
@@ -47,11 +47,8 @@ const mediaTypeToFormat = {
|
|
|
47
47
|
export const clientAbortFiberId = FiberId.runtime(-499, 0)
|
|
48
48
|
|
|
49
49
|
const isClientAbort = (cause: Cause.Cause<unknown>): boolean =>
|
|
50
|
-
Cause.isInterruptedOnly(cause)
|
|
51
|
-
|
|
52
|
-
Cause.interruptors(cause),
|
|
53
|
-
(id) => id === clientAbortFiberId,
|
|
54
|
-
)
|
|
50
|
+
Cause.isInterruptedOnly(cause) &&
|
|
51
|
+
HashSet.some(Cause.interruptors(cause), (id) => id === clientAbortFiberId)
|
|
55
52
|
|
|
56
53
|
const getStatusFromCause = (cause: Cause.Cause<unknown>): number => {
|
|
57
54
|
const failure = Cause.failureOption(cause)
|
|
@@ -80,21 +77,18 @@ function streamResponse(
|
|
|
80
77
|
): Response {
|
|
81
78
|
const encoder = new TextEncoder()
|
|
82
79
|
const byteStream = (stream as Stream.Stream<unknown, unknown, never>).pipe(
|
|
83
|
-
Stream.map(
|
|
84
|
-
|
|
85
|
-
? encoder.encode(chunk)
|
|
86
|
-
: chunk as Uint8Array
|
|
80
|
+
Stream.map(
|
|
81
|
+
(chunk): Uint8Array =>
|
|
82
|
+
typeof chunk === "string" ? encoder.encode(chunk) : (chunk as Uint8Array),
|
|
87
83
|
),
|
|
88
84
|
Stream.catchAll((error) =>
|
|
89
|
-
Stream.fail(
|
|
90
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
91
|
-
)
|
|
85
|
+
Stream.fail(error instanceof Error ? error : new Error(String(error))),
|
|
92
86
|
),
|
|
93
87
|
)
|
|
94
|
-
return new Response(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
88
|
+
return new Response(Stream.toReadableStreamRuntime(byteStream, runtime), {
|
|
89
|
+
status,
|
|
90
|
+
headers: headers as Record<string, string>,
|
|
91
|
+
})
|
|
98
92
|
}
|
|
99
93
|
|
|
100
94
|
function toResponse(
|
|
@@ -131,9 +125,7 @@ function toResponse(
|
|
|
131
125
|
)
|
|
132
126
|
}
|
|
133
127
|
|
|
134
|
-
return Effect.succeed(
|
|
135
|
-
streamResponse(entity.stream, headers, status, runtime),
|
|
136
|
-
)
|
|
128
|
+
return Effect.succeed(streamResponse(entity.stream, headers, status, runtime))
|
|
137
129
|
}
|
|
138
130
|
|
|
139
131
|
type Handler = (
|
|
@@ -143,7 +135,7 @@ type Handler = (
|
|
|
143
135
|
|
|
144
136
|
function determineSelectedFormat(
|
|
145
137
|
accept: string | null,
|
|
146
|
-
routes: UnboundedRouteWithMethod
|
|
138
|
+
routes: Array<UnboundedRouteWithMethod>,
|
|
147
139
|
): RouteBody.Format | undefined {
|
|
148
140
|
const formats = routes
|
|
149
141
|
.filter((r) => Route.descriptor(r).method !== "*")
|
|
@@ -151,9 +143,7 @@ function determineSelectedFormat(
|
|
|
151
143
|
.filter((f): f is Exclude<RouteBody.Format, "*"> => Boolean(f) && f !== "*")
|
|
152
144
|
|
|
153
145
|
const uniqueFormats = [...new Set(formats)]
|
|
154
|
-
const mediaTypes = uniqueFormats
|
|
155
|
-
.map((f) => formatToMediaType[f])
|
|
156
|
-
.filter(Boolean)
|
|
146
|
+
const mediaTypes = uniqueFormats.map((f) => formatToMediaType[f]).filter(Boolean)
|
|
157
147
|
|
|
158
148
|
if (mediaTypes.length === 0) {
|
|
159
149
|
return undefined
|
|
@@ -171,21 +161,17 @@ function determineSelectedFormat(
|
|
|
171
161
|
return undefined
|
|
172
162
|
}
|
|
173
163
|
|
|
174
|
-
export const toWebHandlerRuntime = <R>(
|
|
175
|
-
runtime: Runtime.Runtime<R>,
|
|
176
|
-
) => {
|
|
164
|
+
export const toWebHandlerRuntime = <R>(runtime: Runtime.Runtime<R>) => {
|
|
177
165
|
const runFork = Runtime.runFork(runtime)
|
|
178
166
|
|
|
179
|
-
return (
|
|
180
|
-
routes: Iterable<UnboundedRouteWithMethod>,
|
|
181
|
-
): Http.WebHandler => {
|
|
167
|
+
return (routes: Iterable<UnboundedRouteWithMethod>): Http.WebHandler => {
|
|
182
168
|
const grouped = Object.groupBy(
|
|
183
169
|
routes,
|
|
184
170
|
(route) => Route.descriptor(route).method?.toUpperCase() ?? "*",
|
|
185
171
|
)
|
|
186
172
|
const wildcards = grouped["*"] ?? []
|
|
187
173
|
const methodGroups: {
|
|
188
|
-
[method in Http.Method]?: UnboundedRouteWithMethod
|
|
174
|
+
[method in Http.Method]?: Array<UnboundedRouteWithMethod>
|
|
189
175
|
} = {
|
|
190
176
|
GET: undefined,
|
|
191
177
|
POST: undefined,
|
|
@@ -208,9 +194,7 @@ export const toWebHandlerRuntime = <R>(
|
|
|
208
194
|
const methodRoutes = methodGroups[method] ?? []
|
|
209
195
|
|
|
210
196
|
if (methodRoutes.length === 0 && wildcards.length === 0) {
|
|
211
|
-
return Promise.resolve(
|
|
212
|
-
respondError({ status: 405, message: "method not allowed" }),
|
|
213
|
-
)
|
|
197
|
+
return Promise.resolve(respondError({ status: 405, message: "method not allowed" }))
|
|
214
198
|
}
|
|
215
199
|
|
|
216
200
|
const allRoutes = [...wildcards, ...methodRoutes]
|
|
@@ -220,40 +204,25 @@ export const toWebHandlerRuntime = <R>(
|
|
|
220
204
|
const format = Route.descriptor(r).format
|
|
221
205
|
return format && format !== "*"
|
|
222
206
|
})
|
|
223
|
-
const hasWildcardFormatRoutes = allRoutes.some((r) =>
|
|
224
|
-
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
if (
|
|
228
|
-
selectedFormat === undefined
|
|
229
|
-
&& hasSpecificFormatRoutes
|
|
230
|
-
&& !hasWildcardFormatRoutes
|
|
231
|
-
) {
|
|
232
|
-
return Promise.resolve(
|
|
233
|
-
respondError({ status: 406, message: "not acceptable" }),
|
|
234
|
-
)
|
|
207
|
+
const hasWildcardFormatRoutes = allRoutes.some((r) => Route.descriptor(r).format === "*")
|
|
208
|
+
|
|
209
|
+
if (selectedFormat === undefined && hasSpecificFormatRoutes && !hasWildcardFormatRoutes) {
|
|
210
|
+
return Promise.resolve(respondError({ status: 406, message: "not acceptable" }))
|
|
235
211
|
}
|
|
236
212
|
|
|
237
|
-
const createChain = (
|
|
238
|
-
initialContext: any,
|
|
239
|
-
): Effect.Effect<Entity.Entity<any>, any, any> => {
|
|
213
|
+
const createChain = (initialContext: any): Effect.Effect<Entity.Entity<any>, any, any> => {
|
|
240
214
|
let index = 0
|
|
241
215
|
let currentContext = initialContext
|
|
242
216
|
let routePathSet = false
|
|
243
217
|
|
|
244
|
-
const runNext = (
|
|
245
|
-
passedContext?: any,
|
|
246
|
-
): Effect.Effect<Entity.Entity<any>, any, any> => {
|
|
218
|
+
const runNext = (passedContext?: any): Effect.Effect<Entity.Entity<any>, any, any> => {
|
|
247
219
|
if (passedContext !== undefined) {
|
|
248
220
|
currentContext = passedContext
|
|
249
221
|
}
|
|
250
222
|
|
|
251
223
|
if (index >= allRoutes.length) {
|
|
252
224
|
return Effect.succeed(
|
|
253
|
-
Entity.make(
|
|
254
|
-
{ status: 404, message: "route not found" },
|
|
255
|
-
{ status: 404 },
|
|
256
|
-
),
|
|
225
|
+
Entity.make({ status: 404, message: "route not found" }, { status: 404 }),
|
|
257
226
|
)
|
|
258
227
|
}
|
|
259
228
|
|
|
@@ -268,21 +237,17 @@ export const toWebHandlerRuntime = <R>(
|
|
|
268
237
|
|
|
269
238
|
currentContext = { ...currentContext, ...descriptor }
|
|
270
239
|
|
|
271
|
-
const nextArg = (ctx?: any) =>
|
|
272
|
-
Entity.effect(Effect.suspend(() => runNext(ctx)))
|
|
240
|
+
const nextArg = (ctx?: any) => Entity.effect(Effect.suspend(() => runNext(ctx)))
|
|
273
241
|
|
|
274
242
|
const routePath = descriptor["path"]
|
|
275
243
|
if (!routePathSet && routePath !== undefined) {
|
|
276
244
|
routePathSet = true
|
|
277
|
-
return Effect.flatMap(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return handler(currentContext, nextArg)
|
|
284
|
-
},
|
|
285
|
-
)
|
|
245
|
+
return Effect.flatMap(Effect.currentSpan.pipe(Effect.option), (spanOption) => {
|
|
246
|
+
if (Option.isSome(spanOption)) {
|
|
247
|
+
spanOption.value.attribute("http.route", routePath)
|
|
248
|
+
}
|
|
249
|
+
return handler(currentContext, nextArg)
|
|
250
|
+
})
|
|
286
251
|
}
|
|
287
252
|
|
|
288
253
|
return handler(currentContext, nextArg)
|
|
@@ -291,90 +256,74 @@ export const toWebHandlerRuntime = <R>(
|
|
|
291
256
|
return runNext()
|
|
292
257
|
}
|
|
293
258
|
|
|
294
|
-
const effect = Effect.withFiberRuntime<Response, unknown, R>(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|| fiber.getFiberRef(RouteHttpTracer.currentTracerDisabledWhen)(
|
|
299
|
-
request,
|
|
300
|
-
)
|
|
259
|
+
const effect = Effect.withFiberRuntime<Response, unknown, R>((fiber) => {
|
|
260
|
+
const tracerDisabled =
|
|
261
|
+
!fiber.getFiberRef(FiberRef.currentTracerEnabled) ||
|
|
262
|
+
fiber.getFiberRef(RouteHttpTracer.currentTracerDisabledWhen)(request)
|
|
301
263
|
|
|
302
|
-
|
|
264
|
+
const url = new URL(request.url)
|
|
303
265
|
|
|
304
|
-
|
|
305
|
-
|
|
266
|
+
const innerEffect = Effect.gen(function* () {
|
|
267
|
+
const result = yield* createChain({ request, selectedFormat })
|
|
306
268
|
|
|
307
|
-
|
|
308
|
-
? result
|
|
309
|
-
: Entity.make(result, { status: 200 })
|
|
269
|
+
const entity = Entity.isEntity(result) ? result : Entity.make(result, { status: 200 })
|
|
310
270
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
271
|
+
if (entity.status === 404 && entity.body === undefined) {
|
|
272
|
+
return respondError({ status: 406, message: "not acceptable" })
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return yield* toResponse(entity, selectedFormat, runtime)
|
|
276
|
+
})
|
|
314
277
|
|
|
315
|
-
|
|
316
|
-
|
|
278
|
+
if (tracerDisabled) {
|
|
279
|
+
return innerEffect
|
|
280
|
+
}
|
|
317
281
|
|
|
318
|
-
|
|
319
|
-
return innerEffect
|
|
320
|
-
}
|
|
282
|
+
const spanNameGenerator = fiber.getFiberRef(RouteHttpTracer.currentSpanNameGenerator)
|
|
321
283
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
span.attribute("url.path", url.pathname)
|
|
339
|
-
const query = url.search.slice(1)
|
|
340
|
-
if (query !== "") {
|
|
341
|
-
span.attribute("url.query", query)
|
|
342
|
-
}
|
|
343
|
-
span.attribute("url.scheme", url.protocol.slice(0, -1))
|
|
284
|
+
return Effect.useSpan(
|
|
285
|
+
spanNameGenerator(request),
|
|
286
|
+
{
|
|
287
|
+
parent: Option.getOrUndefined(RouteHttpTracer.parentSpanFromHeaders(request.headers)),
|
|
288
|
+
kind: "server",
|
|
289
|
+
captureStackTrace: false,
|
|
290
|
+
},
|
|
291
|
+
(span) => {
|
|
292
|
+
span.attribute("http.request.method", request.method)
|
|
293
|
+
span.attribute("url.full", url.toString())
|
|
294
|
+
span.attribute("url.path", url.pathname)
|
|
295
|
+
const query = url.search.slice(1)
|
|
296
|
+
if (query !== "") {
|
|
297
|
+
span.attribute("url.query", query)
|
|
298
|
+
}
|
|
299
|
+
span.attribute("url.scheme", url.protocol.slice(0, -1))
|
|
344
300
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
301
|
+
const userAgent = request.headers.get("user-agent")
|
|
302
|
+
if (userAgent !== null) {
|
|
303
|
+
span.attribute("user_agent.original", userAgent)
|
|
304
|
+
}
|
|
349
305
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
(exit)
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
return exit
|
|
360
|
-
},
|
|
361
|
-
)
|
|
362
|
-
},
|
|
363
|
-
)
|
|
364
|
-
},
|
|
365
|
-
)
|
|
306
|
+
return Effect.flatMap(Effect.exit(Effect.withParentSpan(innerEffect, span)), (exit) => {
|
|
307
|
+
if (exit._tag === "Success") {
|
|
308
|
+
span.attribute("http.response.status_code", exit.value.status)
|
|
309
|
+
}
|
|
310
|
+
return exit
|
|
311
|
+
})
|
|
312
|
+
},
|
|
313
|
+
)
|
|
314
|
+
})
|
|
366
315
|
|
|
367
316
|
return new Promise((resolve) => {
|
|
368
317
|
const fiber = runFork(
|
|
369
318
|
effect.pipe(
|
|
370
319
|
Effect.scoped,
|
|
371
320
|
Effect.catchAllCause((cause) =>
|
|
372
|
-
Effect.gen(function*() {
|
|
321
|
+
Effect.gen(function* () {
|
|
373
322
|
yield* Effect.logError(cause)
|
|
374
323
|
const status = getStatusFromCause(cause)
|
|
375
324
|
const message = Cause.pretty(cause, { renderErrorCause: true })
|
|
376
325
|
return respondError({ status, message })
|
|
377
|
-
})
|
|
326
|
+
}),
|
|
378
327
|
),
|
|
379
328
|
),
|
|
380
329
|
)
|
|
@@ -391,9 +340,7 @@ export const toWebHandlerRuntime = <R>(
|
|
|
391
340
|
if (exit._tag === "Success") {
|
|
392
341
|
resolve(exit.value)
|
|
393
342
|
} else if (isClientAbort(exit.cause)) {
|
|
394
|
-
resolve(
|
|
395
|
-
respondError({ status: 499, message: "client closed request" }),
|
|
396
|
-
)
|
|
343
|
+
resolve(respondError({ status: 499, message: "client closed request" }))
|
|
397
344
|
} else {
|
|
398
345
|
const status = getStatusFromCause(exit.cause)
|
|
399
346
|
const message = Cause.pretty(exit.cause, { renderErrorCause: true })
|
|
@@ -405,15 +352,14 @@ export const toWebHandlerRuntime = <R>(
|
|
|
405
352
|
}
|
|
406
353
|
}
|
|
407
354
|
|
|
408
|
-
export const toWebHandler: (
|
|
409
|
-
|
|
410
|
-
) => Http.WebHandler = toWebHandlerRuntime(Runtime.defaultRuntime)
|
|
355
|
+
export const toWebHandler: (routes: Iterable<UnboundedRouteWithMethod>) => Http.WebHandler =
|
|
356
|
+
toWebHandlerRuntime(Runtime.defaultRuntime)
|
|
411
357
|
|
|
412
358
|
export function* walkHandles(
|
|
413
359
|
tree: RouteTree.RouteTree,
|
|
414
360
|
runtime: Runtime.Runtime<never> = Runtime.defaultRuntime,
|
|
415
361
|
): Generator<[path: string, handler: Http.WebHandler]> {
|
|
416
|
-
const pathGroups = new Map<string, RouteMount.MountedRoute
|
|
362
|
+
const pathGroups = new Map<string, Array<RouteMount.MountedRoute>>()
|
|
417
363
|
|
|
418
364
|
for (const route of RouteTree.walk(tree)) {
|
|
419
365
|
const path = Route.descriptor(route).path
|
package/src/RouteHttpTracer.ts
CHANGED
|
@@ -13,15 +13,12 @@ export const currentTracerDisabledWhen = GlobalValue.globalValue(
|
|
|
13
13
|
export const withTracerDisabledWhen = <A, E, R>(
|
|
14
14
|
effect: Effect.Effect<A, E, R>,
|
|
15
15
|
predicate: Predicate.Predicate<Request>,
|
|
16
|
-
): Effect.Effect<A, E, R> =>
|
|
17
|
-
Effect.locally(effect, currentTracerDisabledWhen, predicate)
|
|
16
|
+
): Effect.Effect<A, E, R> => Effect.locally(effect, currentTracerDisabledWhen, predicate)
|
|
18
17
|
|
|
19
18
|
export const currentSpanNameGenerator = GlobalValue.globalValue(
|
|
20
19
|
Symbol.for("effect-start/RouteHttp/spanNameGenerator"),
|
|
21
20
|
() =>
|
|
22
|
-
FiberRef.unsafeMake<(request: Request) => string>(
|
|
23
|
-
(request) => `http.server ${request.method}`,
|
|
24
|
-
),
|
|
21
|
+
FiberRef.unsafeMake<(request: Request) => string>((request) => `http.server ${request.method}`),
|
|
25
22
|
)
|
|
26
23
|
|
|
27
24
|
export const withSpanNameGenerator = <A, E, R>(
|
|
@@ -29,9 +26,7 @@ export const withSpanNameGenerator = <A, E, R>(
|
|
|
29
26
|
f: (request: Request) => string,
|
|
30
27
|
): Effect.Effect<A, E, R> => Effect.locally(effect, currentSpanNameGenerator, f)
|
|
31
28
|
|
|
32
|
-
const w3cTraceparent = (
|
|
33
|
-
headers: Headers,
|
|
34
|
-
): Option.Option<Tracer.ExternalSpan> => {
|
|
29
|
+
const w3cTraceparent = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
35
30
|
const header = headers.get("traceparent")
|
|
36
31
|
if (header === null) return Option.none()
|
|
37
32
|
|
|
@@ -41,11 +36,13 @@ const w3cTraceparent = (
|
|
|
41
36
|
const [_version, traceId, spanId, flags] = parts
|
|
42
37
|
if (!traceId || !spanId) return Option.none()
|
|
43
38
|
|
|
44
|
-
return Option.some(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
return Option.some(
|
|
40
|
+
Tracer.externalSpan({
|
|
41
|
+
spanId,
|
|
42
|
+
traceId,
|
|
43
|
+
sampled: flags === "01",
|
|
44
|
+
}),
|
|
45
|
+
)
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
const b3Single = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
@@ -58,11 +55,13 @@ const b3Single = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
|
58
55
|
const [traceId, spanId, sampledStr] = parts
|
|
59
56
|
if (!traceId || !spanId) return Option.none()
|
|
60
57
|
|
|
61
|
-
return Option.some(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
return Option.some(
|
|
59
|
+
Tracer.externalSpan({
|
|
60
|
+
spanId,
|
|
61
|
+
traceId,
|
|
62
|
+
sampled: sampledStr === "1",
|
|
63
|
+
}),
|
|
64
|
+
)
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
const xb3 = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
@@ -72,16 +71,16 @@ const xb3 = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
|
72
71
|
|
|
73
72
|
const sampled = headers.get("x-b3-sampled")
|
|
74
73
|
|
|
75
|
-
return Option.some(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
return Option.some(
|
|
75
|
+
Tracer.externalSpan({
|
|
76
|
+
spanId,
|
|
77
|
+
traceId,
|
|
78
|
+
sampled: sampled === "1",
|
|
79
|
+
}),
|
|
80
|
+
)
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
export const parentSpanFromHeaders = (
|
|
83
|
-
headers: Headers,
|
|
84
|
-
): Option.Option<Tracer.ExternalSpan> => {
|
|
83
|
+
export const parentSpanFromHeaders = (headers: Headers): Option.Option<Tracer.ExternalSpan> => {
|
|
85
84
|
let span = w3cTraceparent(headers)
|
|
86
85
|
if (span._tag === "Some") return span
|
|
87
86
|
|