@effect-app/infra 4.0.0 → 4.0.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.
package/src/routing.ts CHANGED
@@ -14,12 +14,13 @@ import { Invalidation } from "effect-app/rpc"
14
14
  import { type GetEffectContext, type GetEffectError, type RpcContextMap } from "effect-app/rpc/RpcContextMap"
15
15
  import * as S from "effect-app/Schema"
16
16
  import { type TypeTestId } from "effect-app/TypeTest"
17
- import { typedKeysOf, typedValuesOf } from "effect-app/utils"
18
17
  import * as Predicate from "effect/Predicate"
18
+ import * as Record from "effect/Record"
19
19
  import * as Ref from "effect/Ref"
20
20
  import { Rpc, RpcGroup, type RpcSerialization, RpcServer } from "effect/rpc"
21
21
  import type * as Scope from "effect/Scope"
22
22
  import * as Stream from "effect/Stream"
23
+ import * as Struct from "effect/Struct"
23
24
  import { type LayerUtils } from "./layerUtils.ts"
24
25
  import { RequestType as RequestTypeAnnotation } from "./routing/middleware.ts"
25
26
 
@@ -321,14 +322,14 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
321
322
  const meta = getMeta(rsc)
322
323
 
323
324
  type RequestModules = FilterRequestModules<Resource>
324
- const requestModules = typedKeysOf(rsc).reduce((acc, cur) => {
325
+ const requestModules = Struct.keys(rsc).reduce((acc, cur) => {
325
326
  if (Predicate.isObjectKeyword(rsc[cur]) && rsc[cur]["success"]) {
326
327
  acc[cur as keyof RequestModules] = rsc[cur]
327
328
  }
328
329
  return acc
329
330
  }, {} as RequestModules)
330
331
 
331
- const routeMatcher = typedKeysOf(requestModules).reduce(
332
+ const routeMatcher = Struct.keys(requestModules).reduce(
332
333
  (prev, cur) => {
333
334
  ;(prev as any)[cur] = Object.assign((handlerImpl: any) => {
334
335
  // handlerImpl is the actual handler implementation
@@ -398,7 +399,7 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
398
399
  >
399
400
  >
400
401
  } = (impl: Record<keyof RequestModules, any>) =>
401
- typedKeysOf(impl).reduce((acc, cur) => {
402
+ Struct.keys(impl).reduce((acc, cur) => {
402
403
  acc[cur] = "raw" in impl[cur] ? routeMatcher[cur].raw(impl[cur].raw) : routeMatcher[cur](impl[cur])
403
404
  return acc
404
405
  }, {} as any)
@@ -437,7 +438,7 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
437
438
  const mw = meta.middleware as any
438
439
 
439
440
  // return make.pipe(Effect.map((c) => controllers(c, dependencies)))
440
- const mapped = typedKeysOf(requestModules).reduce((acc, cur) => {
441
+ const mapped = Struct.keys(requestModules).reduce((acc, cur) => {
441
442
  const handler = controllers[cur as keyof typeof controllers]
442
443
  const resource = rsc[cur]
443
444
 
@@ -623,7 +624,7 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
623
624
 
624
625
  const rpcs = RpcGroup
625
626
  .make(
626
- ...typedValuesOf(mapped).map(([resource]) => {
627
+ ...(Object.values(mapped) as Array<(typeof mapped)[keyof typeof mapped]>).map(([resource]) => {
627
628
  const isStream = resource.stream
628
629
  const isCommand = resource.type === "command"
629
630
  return (isCommand
@@ -654,10 +655,13 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
654
655
 
655
656
  const rpc = rpcs
656
657
  .toLayer(Effect.gen(function*() {
657
- return typedValuesOf(mapped).reduce((acc, [resource, handler]) => {
658
- acc[`${meta.moduleName}.${resource._tag}`] = handler
659
- return acc
660
- }, {} as Record<string, any>) as any // TODO
658
+ return (Object.values(mapped) as Array<(typeof mapped)[keyof typeof mapped]>).reduce(
659
+ (acc, [resource, handler]) => {
660
+ acc[`${meta.moduleName}.${resource._tag}`] = handler
661
+ return acc
662
+ },
663
+ {} as Record<string, any>
664
+ ) as any // TODO
661
665
  })) as unknown as Layer.Layer<
662
666
  { [K in keyof RequestModules]: Rpc.Handler<K> },
663
667
  MakeE,
@@ -774,7 +778,7 @@ export const makeRouter = <Live extends Layer.Layer<any, any, any> = Layer.Layer
774
778
  >(
775
779
  handlers: T
776
780
  ) {
777
- const routers = typedValuesOf(handlers)
781
+ const routers = Record.values(handlers)
778
782
 
779
783
  return Layer.mergeAll(...routers as [any]) as unknown as Layer.Layer<
780
784
  never,