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.
- package/dist/index.js +472 -422
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/effect-builder.ts +348 -570
- package/src/effect-enhance-router.ts +20 -21
- package/src/effect-procedure.ts +274 -263
- package/src/extension/compose-surfaces.ts +15 -0
- package/src/extension/create-node-proxy.ts +270 -0
- package/src/extension/state.ts +108 -0
- package/src/index.ts +2 -0
- package/src/tests/effect-builder.proxy.test.ts +253 -0
- package/src/tests/parity.effect-builder.test.ts +17 -0
- package/src/types/effect-builder-surface.ts +441 -0
- package/src/types/effect-procedure-surface.ts +243 -0
- package/src/types/index.ts +22 -10
- package/src/types/variants.ts +75 -0
|
@@ -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
|
|
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
|
|
61
|
-
return unlazy(
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
return accessible as any;
|
|
70
|
+
return createAccessibleLazyRouter(enhanced) as any;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
if (isProcedure(router)) {
|
|
75
|
-
const
|
|
74
|
+
const source = unwrapEffectUpstream(router);
|
|
75
|
+
const sourceEffectErrorMap = getEffectErrorMap(router);
|
|
76
|
+
const middlewares = mergeMiddlewares(
|
|
76
77
|
options.middlewares,
|
|
77
|
-
|
|
78
|
+
source["~orpc"].middlewares,
|
|
78
79
|
{ dedupeLeading: options.dedupeLeadingMiddlewares },
|
|
79
80
|
);
|
|
80
81
|
const newMiddlewareAdded =
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
middlewares.length - source["~orpc"].middlewares.length;
|
|
83
83
|
const effectErrorMap = {
|
|
84
84
|
...options.errorMap,
|
|
85
|
-
...
|
|
85
|
+
...sourceEffectErrorMap,
|
|
86
86
|
};
|
|
87
87
|
const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =
|
|
88
88
|
effectErrorMapToErrorMap(effectErrorMap);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
95
|
+
middlewares,
|
|
95
96
|
inputValidationIndex:
|
|
96
|
-
|
|
97
|
+
source["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
97
98
|
outputValidationIndex:
|
|
98
|
-
|
|
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
|
|
104
|
+
const enhanced: Record<string, any> = {};
|
|
106
105
|
|
|
107
106
|
for (const key in router) {
|
|
108
107
|
enhanced[key] = enhanceEffectRouter(router[key]!, options);
|