@effect/platform 0.58.4 → 0.58.6
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/dist/cjs/HttpRouter.js +11 -1
- package/dist/cjs/HttpRouter.js.map +1 -1
- package/dist/cjs/UrlParams.js +5 -5
- package/dist/cjs/UrlParams.js.map +1 -1
- package/dist/cjs/internal/httpRouter.js +78 -2
- package/dist/cjs/internal/httpRouter.js.map +1 -1
- package/dist/dts/HttpRouter.d.ts +64 -2
- package/dist/dts/HttpRouter.d.ts.map +1 -1
- package/dist/dts/UrlParams.d.ts +10 -5
- package/dist/dts/UrlParams.d.ts.map +1 -1
- package/dist/dts/internal/httpRouter.d.ts.map +1 -1
- package/dist/esm/HttpRouter.js +10 -0
- package/dist/esm/HttpRouter.js.map +1 -1
- package/dist/esm/UrlParams.js +5 -5
- package/dist/esm/UrlParams.js.map +1 -1
- package/dist/esm/internal/httpRouter.js +76 -1
- package/dist/esm/internal/httpRouter.js.map +1 -1
- package/package.json +3 -3
- package/src/HttpRouter.ts +101 -6
- package/src/UrlParams.ts +36 -61
- package/src/internal/httpRouter.ts +101 -4
|
@@ -8,6 +8,7 @@ import * as Effectable from "effect/Effectable"
|
|
|
8
8
|
import * as FiberRef from "effect/FiberRef"
|
|
9
9
|
import { dual } from "effect/Function"
|
|
10
10
|
import * as Inspectable from "effect/Inspectable"
|
|
11
|
+
import * as Layer from "effect/Layer"
|
|
11
12
|
import * as Option from "effect/Option"
|
|
12
13
|
import * as Predicate from "effect/Predicate"
|
|
13
14
|
import * as Tracer from "effect/Tracer"
|
|
@@ -317,17 +318,30 @@ export const makeRoute = <E, R>(
|
|
|
317
318
|
method: Method.HttpMethod,
|
|
318
319
|
path: Router.PathInput,
|
|
319
320
|
handler: Router.Route.Handler<E, R>,
|
|
320
|
-
|
|
321
|
-
|
|
321
|
+
options?: {
|
|
322
|
+
readonly prefix?: string | undefined
|
|
323
|
+
readonly uninterruptible?: boolean | undefined
|
|
324
|
+
} | undefined
|
|
322
325
|
): Router.Route<E, Router.HttpRouter.ExcludeProvided<R>> =>
|
|
323
326
|
new RouteImpl(
|
|
324
327
|
method,
|
|
325
328
|
path,
|
|
326
329
|
handler,
|
|
327
|
-
prefix,
|
|
328
|
-
uninterruptible
|
|
330
|
+
options?.prefix ? Option.some(options.prefix) : Option.none(),
|
|
331
|
+
options?.uninterruptible ?? false
|
|
329
332
|
) as any
|
|
330
333
|
|
|
334
|
+
/** @internal */
|
|
335
|
+
export const append = dual<
|
|
336
|
+
<R1, E1>(
|
|
337
|
+
route: Router.Route<E1, R1>
|
|
338
|
+
) => <E, R>(self: Router.HttpRouter<E, R>) => Router.HttpRouter<E | E1, R | Router.HttpRouter.ExcludeProvided<R1>>,
|
|
339
|
+
<E, R, E1, R1>(
|
|
340
|
+
self: Router.HttpRouter<E, R>,
|
|
341
|
+
route: Router.Route<E1, R1>
|
|
342
|
+
) => Router.HttpRouter<E | E1, R | Router.HttpRouter.ExcludeProvided<R1>>
|
|
343
|
+
>(2, (self, route) => new RouterImpl(Chunk.append(self.routes, route) as any, self.mounts))
|
|
344
|
+
|
|
331
345
|
/** @internal */
|
|
332
346
|
export const concat = dual<
|
|
333
347
|
<R1, E1>(
|
|
@@ -645,3 +659,86 @@ export const provideServiceEffect = dual<
|
|
|
645
659
|
Context.Tag.Identifier<T>
|
|
646
660
|
>
|
|
647
661
|
> => use(self, Effect.provideServiceEffect(tag, effect)) as any)
|
|
662
|
+
|
|
663
|
+
const makeService = <E, R>(): Router.HttpRouter.Service<E, R> => {
|
|
664
|
+
let router = empty as Router.HttpRouter<E, R>
|
|
665
|
+
return {
|
|
666
|
+
addRoute(route) {
|
|
667
|
+
return Effect.sync(() => {
|
|
668
|
+
router = append(router, route)
|
|
669
|
+
})
|
|
670
|
+
},
|
|
671
|
+
all(path, handler, options) {
|
|
672
|
+
return Effect.sync(() => {
|
|
673
|
+
router = all(router, path, handler, options)
|
|
674
|
+
})
|
|
675
|
+
},
|
|
676
|
+
get(path, handler, options) {
|
|
677
|
+
return Effect.sync(() => {
|
|
678
|
+
router = get(router, path, handler, options)
|
|
679
|
+
})
|
|
680
|
+
},
|
|
681
|
+
post(path, handler, options) {
|
|
682
|
+
return Effect.sync(() => {
|
|
683
|
+
router = post(router, path, handler, options)
|
|
684
|
+
})
|
|
685
|
+
},
|
|
686
|
+
put(path, handler, options) {
|
|
687
|
+
return Effect.sync(() => {
|
|
688
|
+
router = put(router, path, handler, options)
|
|
689
|
+
})
|
|
690
|
+
},
|
|
691
|
+
patch(path, handler, options) {
|
|
692
|
+
return Effect.sync(() => {
|
|
693
|
+
router = patch(router, path, handler, options)
|
|
694
|
+
})
|
|
695
|
+
},
|
|
696
|
+
del(path, handler, options) {
|
|
697
|
+
return Effect.sync(() => {
|
|
698
|
+
router = del(router, path, handler, options)
|
|
699
|
+
})
|
|
700
|
+
},
|
|
701
|
+
head(path, handler, options) {
|
|
702
|
+
return Effect.sync(() => {
|
|
703
|
+
router = head(router, path, handler, options)
|
|
704
|
+
})
|
|
705
|
+
},
|
|
706
|
+
options(path, handler, opts) {
|
|
707
|
+
return Effect.sync(() => {
|
|
708
|
+
router = options(router, path, handler, opts)
|
|
709
|
+
})
|
|
710
|
+
},
|
|
711
|
+
router: Effect.sync(() => router)
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/* @internal */
|
|
716
|
+
export const Tag =
|
|
717
|
+
<const Name extends string>(id: Name) =>
|
|
718
|
+
<Self, E = never, R = never>(): Router.HttpRouter.TagClass<Self, Name, E, R> => {
|
|
719
|
+
const Err = globalThis.Error as any
|
|
720
|
+
const limit = Err.stackTraceLimit
|
|
721
|
+
Err.stackTraceLimit = 2
|
|
722
|
+
const creationError = new Err()
|
|
723
|
+
Err.stackTraceLimit = limit
|
|
724
|
+
|
|
725
|
+
function TagClass() {}
|
|
726
|
+
Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id)))
|
|
727
|
+
TagClass.key = id
|
|
728
|
+
Object.defineProperty(TagClass, "stack", {
|
|
729
|
+
get() {
|
|
730
|
+
return creationError.stack
|
|
731
|
+
}
|
|
732
|
+
})
|
|
733
|
+
TagClass.Live = Layer.sync(TagClass as any, makeService)
|
|
734
|
+
TagClass.router = Effect.flatMap(TagClass as any, (_: any) => _.router)
|
|
735
|
+
TagClass.use = (f: any) =>
|
|
736
|
+
Layer.effectDiscard(Effect.flatMap(TagClass as any, f)).pipe(
|
|
737
|
+
Layer.provide(TagClass.Live)
|
|
738
|
+
)
|
|
739
|
+
TagClass.useScoped = (f: any) =>
|
|
740
|
+
Layer.scopedDiscard(Effect.flatMap(TagClass as any, f)).pipe(
|
|
741
|
+
Layer.provide(TagClass.Live)
|
|
742
|
+
)
|
|
743
|
+
return TagClass as any
|
|
744
|
+
}
|