@effect/platform 0.88.1 → 0.88.2

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.
@@ -179,8 +179,8 @@ class RouterImpl<E = never, R = never> extends Effectable.StructuralClass<
179
179
  ) {
180
180
  super()
181
181
  this[TypeId] = TypeId
182
- this.httpApp = FiberRef.get(currentRouterConfig).pipe(
183
- Effect.flatMap((config) => this.httpApp = toHttpApp(this, config) as any)
182
+ this.httpApp = toHttpApp(this).pipe(
183
+ Effect.flatMap((app) => this.httpApp = app as any)
184
184
  ) as any
185
185
  }
186
186
  private httpApp: Effect.Effect<
@@ -206,95 +206,96 @@ class RouterImpl<E = never, R = never> extends Effectable.StructuralClass<
206
206
  }
207
207
  }
208
208
 
209
- const toHttpApp = <E, R>(
210
- self: Router.HttpRouter<E, R>,
211
- config: Partial<FindMyWay.RouterConfig>
212
- ): App.Default<E | Error.RouteNotFound, R> => {
213
- const router = FindMyWay.make<Router.Route<E, R>>(config)
214
- const mounts = Chunk.toReadonlyArray(self.mounts).map(([path, app, options]) =>
215
- [
216
- path,
217
- new RouteContextImpl(
218
- new RouteImpl(
219
- "*",
220
- options?.includePrefix ? `${path}/*` as Router.PathInput : "/*",
221
- app,
222
- options?.includePrefix ? Option.none() : Option.some(path),
223
- false
209
+ /** @internal */
210
+ export const toHttpApp = <E, R>(
211
+ self: Router.HttpRouter<E, R>
212
+ ): Effect.Effect<App.Default<E | Error.RouteNotFound, R>> =>
213
+ Effect.map(FiberRef.get(currentRouterConfig), (config) => {
214
+ const router = FindMyWay.make<Router.Route<E, R>>(config)
215
+ const mounts = Chunk.toReadonlyArray(self.mounts).map(([path, app, options]) =>
216
+ [
217
+ path,
218
+ new RouteContextImpl(
219
+ new RouteImpl(
220
+ "*",
221
+ options?.includePrefix ? `${path}/*` as Router.PathInput : "/*",
222
+ app,
223
+ options?.includePrefix ? Option.none() : Option.some(path),
224
+ false
225
+ ),
226
+ {}
224
227
  ),
225
- {}
226
- ),
227
- options
228
- ] as const
229
- )
230
- const mountsLen = mounts.length
231
- Chunk.forEach(self.routes, (route) => {
232
- if (route.method === "*") {
233
- router.all(route.path, route)
234
- } else {
235
- router.on(route.method, route.path, route)
236
- }
237
- })
238
- return Effect.withFiberRuntime<
239
- ServerResponse.HttpServerResponse,
240
- E | Error.RouteNotFound,
241
- R | ServerRequest.HttpServerRequest
242
- >((fiber) => {
243
- const context = Context.unsafeMake(new Map(fiber.getFiberRef(FiberRef.currentContext).unsafeMap))
244
- const request = Context.unsafeGet(context, ServerRequest.HttpServerRequest)
245
- if (mountsLen > 0) {
246
- const searchIndex = request.url.indexOf("?")
247
- const pathname = searchIndex === -1 ? request.url : request.url.slice(0, searchIndex)
248
-
249
- for (let i = 0; i < mountsLen; i++) {
250
- const [path, routeContext, options] = mounts[i]
251
- if (pathname === path || pathname.startsWith(path + "/")) {
252
- context.unsafeMap.set(RouteContext.key, routeContext)
253
- if (options?.includePrefix !== true) {
254
- context.unsafeMap.set(ServerRequest.HttpServerRequest.key, sliceRequestUrl(request, path))
228
+ options
229
+ ] as const
230
+ )
231
+ const mountsLen = mounts.length
232
+ Chunk.forEach(self.routes, (route) => {
233
+ if (route.method === "*") {
234
+ router.all(route.path, route)
235
+ } else {
236
+ router.on(route.method, route.path, route)
237
+ }
238
+ })
239
+ return Effect.withFiberRuntime<
240
+ ServerResponse.HttpServerResponse,
241
+ E | Error.RouteNotFound,
242
+ R | ServerRequest.HttpServerRequest
243
+ >((fiber) => {
244
+ const context = Context.unsafeMake(new Map(fiber.getFiberRef(FiberRef.currentContext).unsafeMap))
245
+ const request = Context.unsafeGet(context, ServerRequest.HttpServerRequest)
246
+ if (mountsLen > 0) {
247
+ const searchIndex = request.url.indexOf("?")
248
+ const pathname = searchIndex === -1 ? request.url : request.url.slice(0, searchIndex)
249
+
250
+ for (let i = 0; i < mountsLen; i++) {
251
+ const [path, routeContext, options] = mounts[i]
252
+ if (pathname === path || pathname.startsWith(path + "/")) {
253
+ context.unsafeMap.set(RouteContext.key, routeContext)
254
+ if (options?.includePrefix !== true) {
255
+ context.unsafeMap.set(ServerRequest.HttpServerRequest.key, sliceRequestUrl(request, path))
256
+ }
257
+ return Effect.locally(
258
+ Effect.flatMap(routeContext.route.handler, Respondable.toResponse) as App.Default<E, R>,
259
+ FiberRef.currentContext,
260
+ context
261
+ )
255
262
  }
256
- return Effect.locally(
257
- Effect.flatMap(routeContext.route.handler, Respondable.toResponse) as App.Default<E, R>,
258
- FiberRef.currentContext,
259
- context
260
- )
261
263
  }
262
264
  }
263
- }
264
265
 
265
- let result = router.find(request.method, request.url)
266
- if (result === undefined && request.method === "HEAD") {
267
- result = router.find("GET", request.url)
268
- }
269
- if (result === undefined) {
270
- return Effect.fail(new Error.RouteNotFound({ request }))
271
- }
272
- const route = result.handler
273
- if (route.prefix._tag === "Some") {
274
- context.unsafeMap.set(ServerRequest.HttpServerRequest.key, sliceRequestUrl(request, route.prefix.value))
275
- }
276
- context.unsafeMap.set(ServerRequest.ParsedSearchParams.key, result.searchParams)
277
- context.unsafeMap.set(RouteContext.key, new RouteContextImpl(route, result.params))
266
+ let result = router.find(request.method, request.url)
267
+ if (result === undefined && request.method === "HEAD") {
268
+ result = router.find("GET", request.url)
269
+ }
270
+ if (result === undefined) {
271
+ return Effect.fail(new Error.RouteNotFound({ request }))
272
+ }
273
+ const route = result.handler
274
+ if (route.prefix._tag === "Some") {
275
+ context.unsafeMap.set(ServerRequest.HttpServerRequest.key, sliceRequestUrl(request, route.prefix.value))
276
+ }
277
+ context.unsafeMap.set(ServerRequest.ParsedSearchParams.key, result.searchParams)
278
+ context.unsafeMap.set(RouteContext.key, new RouteContextImpl(route, result.params))
278
279
 
279
- const span = Context.getOption(context, Tracer.ParentSpan)
280
- if (span._tag === "Some" && span.value._tag === "Span") {
281
- span.value.attribute("http.route", route.path)
282
- }
280
+ const span = Context.getOption(context, Tracer.ParentSpan)
281
+ if (span._tag === "Some" && span.value._tag === "Span") {
282
+ span.value.attribute("http.route", route.path)
283
+ }
283
284
 
284
- const handlerResponse = Effect.flatMap(route.handler, Respondable.toResponse)
285
- return Effect.locally(
286
- (route.uninterruptible ?
287
- handlerResponse :
288
- Effect.interruptible(handlerResponse)) as Effect.Effect<
289
- ServerResponse.HttpServerResponse,
290
- E,
291
- Router.HttpRouter.ExcludeProvided<R>
292
- >,
293
- FiberRef.currentContext,
294
- context
295
- )
285
+ const handlerResponse = Effect.flatMap(route.handler, Respondable.toResponse)
286
+ return Effect.locally(
287
+ (route.uninterruptible ?
288
+ handlerResponse :
289
+ Effect.interruptible(handlerResponse)) as Effect.Effect<
290
+ ServerResponse.HttpServerResponse,
291
+ E,
292
+ Router.HttpRouter.ExcludeProvided<R>
293
+ >,
294
+ FiberRef.currentContext,
295
+ context
296
+ )
297
+ })
296
298
  })
297
- }
298
299
 
299
300
  function sliceRequestUrl(request: ServerRequest.HttpServerRequest, prefix: string) {
300
301
  const prefexLen = prefix.length
@@ -83,7 +83,7 @@ function normalizeStringPosix(path: string, allowAboveRoot: boolean) {
83
83
  lastSlash = i
84
84
  dots = 0
85
85
  } else if (code === 46 /*.*/ && dots !== -1) {
86
- ;++dots
86
+ ++dots
87
87
  } else {
88
88
  dots = -1
89
89
  }
@@ -361,7 +361,7 @@ const posixImpl = Path.of({
361
361
  } else {
362
362
  toStart += lastCommonSep
363
363
  if (to.charCodeAt(toStart) === 47 /*/*/) {
364
- ;++toStart
364
+ ++toStart
365
365
  }
366
366
  return to.slice(toStart)
367
367
  }