effect-orpc 0.2.0 → 0.2.1

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.
@@ -19,6 +19,7 @@ import {
19
19
  import type { ManagedRuntime } from "effect/ManagedRuntime";
20
20
 
21
21
  import { EffectProcedure } from "./effect-procedure";
22
+ import { getEffectErrorMap, unwrapEffectUpstream } from "./extension/state";
22
23
  import { effectErrorMapToErrorMap, type EffectErrorMap } from "./tagged-error";
23
24
  import type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from "./types";
24
25
 
@@ -51,14 +52,14 @@ export function enhanceEffectRouter<
51
52
  if (isLazy(router)) {
52
53
  const laziedMeta = getLazyMeta(router);
53
54
  const enhancedPrefix = laziedMeta?.prefix
54
- ? mergePrefix(options.prefix, laziedMeta?.prefix)
55
+ ? mergePrefix(options.prefix, laziedMeta.prefix)
55
56
  : options.prefix;
56
57
 
57
58
  const enhanced = lazy(
58
59
  async () => {
59
60
  const { default: unlaziedRouter } = await unlazy(router);
60
- const enhanced = enhanceEffectRouter(unlaziedRouter, options);
61
- return unlazy(enhanced);
61
+ const wrappedRouter = enhanceEffectRouter(unlaziedRouter, options);
62
+ return unlazy(wrappedRouter);
62
63
  },
63
64
  {
64
65
  ...laziedMeta,
@@ -66,43 +67,41 @@ export function enhanceEffectRouter<
66
67
  },
67
68
  );
68
69
 
69
- const accessible = createAccessibleLazyRouter(enhanced);
70
-
71
- return accessible as any;
70
+ return createAccessibleLazyRouter(enhanced) as any;
72
71
  }
73
72
 
74
73
  if (isProcedure(router)) {
75
- const newMiddlewares = mergeMiddlewares(
74
+ const source = unwrapEffectUpstream(router);
75
+ const sourceEffectErrorMap = getEffectErrorMap(router);
76
+ const middlewares = mergeMiddlewares(
76
77
  options.middlewares,
77
- router["~orpc"].middlewares,
78
+ source["~orpc"].middlewares,
78
79
  { dedupeLeading: options.dedupeLeadingMiddlewares },
79
80
  );
80
81
  const newMiddlewareAdded =
81
- newMiddlewares.length - router["~orpc"].middlewares.length;
82
-
82
+ middlewares.length - source["~orpc"].middlewares.length;
83
83
  const effectErrorMap = {
84
84
  ...options.errorMap,
85
- ...router["~orpc"].errorMap,
85
+ ...sourceEffectErrorMap,
86
86
  };
87
87
  const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =
88
88
  effectErrorMapToErrorMap(effectErrorMap);
89
- const enhanced = new EffectProcedure({
90
- ...router["~orpc"],
91
- route: enhanceRoute(router["~orpc"].route, options),
89
+
90
+ return new EffectProcedure({
91
+ ...source["~orpc"],
92
+ route: enhanceRoute(source["~orpc"].route, options),
92
93
  effectErrorMap,
93
94
  errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,
94
- middlewares: newMiddlewares,
95
+ middlewares,
95
96
  inputValidationIndex:
96
- router["~orpc"].inputValidationIndex + newMiddlewareAdded,
97
+ source["~orpc"].inputValidationIndex + newMiddlewareAdded,
97
98
  outputValidationIndex:
98
- router["~orpc"].outputValidationIndex + newMiddlewareAdded,
99
+ source["~orpc"].outputValidationIndex + newMiddlewareAdded,
99
100
  runtime: options.runtime,
100
- });
101
-
102
- return enhanced as any;
101
+ }) as any;
103
102
  }
104
103
 
105
- const enhanced = {} as Record<string, any>;
104
+ const enhanced: Record<string, any> = {};
106
105
 
107
106
  for (const key in router) {
108
107
  enhanced[key] = enhanceEffectRouter(router[key]!, options);