effect-orpc 1.0.0-effect-v4.2 → 1.0.0-effect-v4.4

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.
@@ -0,0 +1,144 @@
1
+ import { ORPCError } from "@orpc/contract";
2
+ import type {
3
+ Context as ORPCContext,
4
+ ProcedureHandler,
5
+ ProcedureHandlerOptions,
6
+ } from "@orpc/server";
7
+ import type { ManagedRuntime } from "effect";
8
+ import { Cause, Effect, Exit, Result, Context } from "effect";
9
+
10
+ import { getCurrentServices } from "./service-context-bridge";
11
+ import type { EffectErrorConstructorMap, EffectErrorMap } from "./tagged-error";
12
+ import {
13
+ createEffectErrorConstructorMap,
14
+ isORPCTaggedError,
15
+ } from "./tagged-error";
16
+ import type { EffectProcedureHandler, EffectSpanConfig } from "./types";
17
+
18
+ export function toORPCErrorFromCause(
19
+ cause: Cause.Cause<unknown>,
20
+ ): ORPCError<string, unknown> {
21
+ if (Cause.hasFails(cause)) {
22
+ const reason = Cause.findFail(cause);
23
+ if (Result.isFailure(reason)) {
24
+ return new ORPCError("INTERNAL_SERVER_ERROR");
25
+ }
26
+
27
+ const error = reason.success.error;
28
+ if (isORPCTaggedError(error)) {
29
+ return error.toORPCError();
30
+ }
31
+ if (error instanceof ORPCError) {
32
+ return error;
33
+ }
34
+
35
+ return new ORPCError("INTERNAL_SERVER_ERROR", {
36
+ cause: error,
37
+ });
38
+ }
39
+
40
+ if (Cause.hasDies(cause)) {
41
+ const reason = Cause.findDie(cause);
42
+ if (Result.isFailure(reason)) {
43
+ return new ORPCError("INTERNAL_SERVER_ERROR", {
44
+ cause: new Error(`Died by unknown reason`),
45
+ });
46
+ }
47
+ return new ORPCError("INTERNAL_SERVER_ERROR", {
48
+ cause: reason.success.defect,
49
+ });
50
+ }
51
+
52
+ if (Cause.hasInterrupts(cause)) {
53
+ const reason = Cause.findInterrupt(cause);
54
+ if (Result.isFailure(reason)) {
55
+ return new ORPCError("INTERNAL_SERVER_ERROR", {
56
+ cause: new Error(`Unknown fiber got interrupted`),
57
+ });
58
+ }
59
+ return new ORPCError("INTERNAL_SERVER_ERROR", {
60
+ cause: new Error(`${reason.success.fiberId} got interrupted`),
61
+ });
62
+ }
63
+
64
+ return new ORPCError("INTERNAL_SERVER_ERROR");
65
+ }
66
+
67
+ export function createEffectProcedureHandler<
68
+ TCurrentContext extends ORPCContext,
69
+ TInput,
70
+ TOutput,
71
+ TEffectErrorMap extends EffectErrorMap,
72
+ TRequirementsProvided,
73
+ TRuntimeError,
74
+ TMeta,
75
+ >(options: {
76
+ runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
77
+ effectErrorMap: TEffectErrorMap;
78
+ effectFn: EffectProcedureHandler<
79
+ TCurrentContext,
80
+ TInput,
81
+ TOutput,
82
+ TEffectErrorMap,
83
+ TRequirementsProvided,
84
+ any
85
+ >;
86
+ spanConfig?: EffectSpanConfig;
87
+ defaultCaptureStackTrace: () => string | undefined;
88
+ }): ProcedureHandler<
89
+ TCurrentContext,
90
+ TInput,
91
+ TOutput,
92
+ any,
93
+ TMeta & Record<never, never>
94
+ > {
95
+ const {
96
+ runtime,
97
+ effectErrorMap,
98
+ effectFn,
99
+ spanConfig,
100
+ defaultCaptureStackTrace,
101
+ } = options;
102
+
103
+ return async (opts) => {
104
+ const effectOpts: ProcedureHandlerOptions<
105
+ TCurrentContext,
106
+ TInput,
107
+ EffectErrorConstructorMap<TEffectErrorMap>,
108
+ TMeta & Record<never, never>
109
+ > = {
110
+ context: opts.context,
111
+ input: opts.input,
112
+ path: opts.path,
113
+ procedure: opts.procedure,
114
+ signal: opts.signal,
115
+ lastEventId: opts.lastEventId,
116
+ errors: createEffectErrorConstructorMap(effectErrorMap),
117
+ };
118
+
119
+ const spanName = spanConfig?.name ?? opts.path.join(".");
120
+ const captureStackTrace =
121
+ spanConfig?.captureStackTrace ?? defaultCaptureStackTrace;
122
+ const resolver = Effect.fnUntraced(effectFn as any);
123
+ const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {
124
+ captureStackTrace,
125
+ });
126
+
127
+ const parentServices = getCurrentServices();
128
+ const exit = parentServices
129
+ ? await Effect.runPromiseExitWith(
130
+ Context.merge(await runtime.context(), parentServices),
131
+ )(tracedEffect, {
132
+ signal: opts.signal,
133
+ })
134
+ : await runtime.runPromiseExit(tracedEffect, {
135
+ signal: opts.signal,
136
+ });
137
+
138
+ if (Exit.isFailure(exit)) {
139
+ throw toORPCErrorFromCause(exit.cause);
140
+ }
141
+
142
+ return exit.value as TOutput;
143
+ };
144
+ }
package/src/eoc.ts ADDED
@@ -0,0 +1,499 @@
1
+ import type {
2
+ AnySchema,
3
+ ContractProcedure,
4
+ ContractRouter,
5
+ ErrorMap,
6
+ HTTPPath,
7
+ Meta,
8
+ Route,
9
+ Schema,
10
+ } from "@orpc/contract";
11
+ import { isContractProcedure, oc } from "@orpc/contract";
12
+
13
+ import type { EffectErrorMap, MergedEffectErrorMap } from "./tagged-error";
14
+ import { effectErrorMapToErrorMap } from "./tagged-error";
15
+ import type { EffectErrorMapToErrorMap } from "./types";
16
+
17
+ export const effectContractSymbol: unique symbol = Symbol.for(
18
+ "@orpc/effect/contract",
19
+ );
20
+
21
+ interface EffectContractMetadata<TEffectErrorMap extends EffectErrorMap> {
22
+ readonly [effectContractSymbol]: {
23
+ readonly errorMap: TEffectErrorMap;
24
+ };
25
+ }
26
+
27
+ type LocalEffectErrorMap<T> =
28
+ T extends EffectContractMetadata<infer TEffectErrorMap extends EffectErrorMap>
29
+ ? TEffectErrorMap
30
+ : Record<never, never>;
31
+
32
+ type ContractWithEffectErrorMap<T, TEffectErrorMap extends EffectErrorMap> =
33
+ T extends ContractProcedure<
34
+ infer TInputSchema,
35
+ infer TOutputSchema,
36
+ infer TErrorMap extends ErrorMap,
37
+ infer TMeta extends Meta
38
+ >
39
+ ? ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> &
40
+ EffectContractMetadata<
41
+ MergedEffectErrorMap<TEffectErrorMap, LocalEffectErrorMap<T>>
42
+ >
43
+ : T extends ContractRouter<Meta>
44
+ ? {
45
+ [K in keyof T]: ContractWithEffectErrorMap<T[K], TEffectErrorMap>;
46
+ }
47
+ : never;
48
+
49
+ export interface EffectContractProcedureBuilder<
50
+ TInputSchema extends AnySchema,
51
+ TOutputSchema extends AnySchema,
52
+ TEffectErrorMap extends EffectErrorMap,
53
+ TMeta extends Meta,
54
+ >
55
+ extends
56
+ ContractProcedure<
57
+ TInputSchema,
58
+ TOutputSchema,
59
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
60
+ TMeta
61
+ >,
62
+ EffectContractMetadata<TEffectErrorMap> {
63
+ errors<U extends EffectErrorMap>(
64
+ errors: U,
65
+ ): EffectContractProcedureBuilder<
66
+ TInputSchema,
67
+ TOutputSchema,
68
+ MergedEffectErrorMap<TEffectErrorMap, U>,
69
+ TMeta
70
+ >;
71
+ meta(
72
+ meta: TMeta,
73
+ ): EffectContractProcedureBuilder<
74
+ TInputSchema,
75
+ TOutputSchema,
76
+ TEffectErrorMap,
77
+ TMeta
78
+ >;
79
+ route(
80
+ route: Route,
81
+ ): EffectContractProcedureBuilder<
82
+ TInputSchema,
83
+ TOutputSchema,
84
+ TEffectErrorMap,
85
+ TMeta
86
+ >;
87
+ input<U extends AnySchema>(
88
+ schema: U,
89
+ ): EffectContractProcedureBuilderWithInput<
90
+ U,
91
+ TOutputSchema,
92
+ TEffectErrorMap,
93
+ TMeta
94
+ >;
95
+ output<U extends AnySchema>(
96
+ schema: U,
97
+ ): EffectContractProcedureBuilderWithOutput<
98
+ TInputSchema,
99
+ U,
100
+ TEffectErrorMap,
101
+ TMeta
102
+ >;
103
+ }
104
+
105
+ export interface EffectContractProcedureBuilderWithInput<
106
+ TInputSchema extends AnySchema,
107
+ TOutputSchema extends AnySchema,
108
+ TEffectErrorMap extends EffectErrorMap,
109
+ TMeta extends Meta,
110
+ >
111
+ extends
112
+ ContractProcedure<
113
+ TInputSchema,
114
+ TOutputSchema,
115
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
116
+ TMeta
117
+ >,
118
+ EffectContractMetadata<TEffectErrorMap> {
119
+ errors<U extends EffectErrorMap>(
120
+ errors: U,
121
+ ): EffectContractProcedureBuilderWithInput<
122
+ TInputSchema,
123
+ TOutputSchema,
124
+ MergedEffectErrorMap<TEffectErrorMap, U>,
125
+ TMeta
126
+ >;
127
+ meta(
128
+ meta: TMeta,
129
+ ): EffectContractProcedureBuilderWithInput<
130
+ TInputSchema,
131
+ TOutputSchema,
132
+ TEffectErrorMap,
133
+ TMeta
134
+ >;
135
+ route(
136
+ route: Route,
137
+ ): EffectContractProcedureBuilderWithInput<
138
+ TInputSchema,
139
+ TOutputSchema,
140
+ TEffectErrorMap,
141
+ TMeta
142
+ >;
143
+ output<U extends AnySchema>(
144
+ schema: U,
145
+ ): EffectContractProcedureBuilderWithInputOutput<
146
+ TInputSchema,
147
+ U,
148
+ TEffectErrorMap,
149
+ TMeta
150
+ >;
151
+ }
152
+
153
+ export interface EffectContractProcedureBuilderWithOutput<
154
+ TInputSchema extends AnySchema,
155
+ TOutputSchema extends AnySchema,
156
+ TEffectErrorMap extends EffectErrorMap,
157
+ TMeta extends Meta,
158
+ >
159
+ extends
160
+ ContractProcedure<
161
+ TInputSchema,
162
+ TOutputSchema,
163
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
164
+ TMeta
165
+ >,
166
+ EffectContractMetadata<TEffectErrorMap> {
167
+ errors<U extends EffectErrorMap>(
168
+ errors: U,
169
+ ): EffectContractProcedureBuilderWithOutput<
170
+ TInputSchema,
171
+ TOutputSchema,
172
+ MergedEffectErrorMap<TEffectErrorMap, U>,
173
+ TMeta
174
+ >;
175
+ meta(
176
+ meta: TMeta,
177
+ ): EffectContractProcedureBuilderWithOutput<
178
+ TInputSchema,
179
+ TOutputSchema,
180
+ TEffectErrorMap,
181
+ TMeta
182
+ >;
183
+ route(
184
+ route: Route,
185
+ ): EffectContractProcedureBuilderWithOutput<
186
+ TInputSchema,
187
+ TOutputSchema,
188
+ TEffectErrorMap,
189
+ TMeta
190
+ >;
191
+ input<U extends AnySchema>(
192
+ schema: U,
193
+ ): EffectContractProcedureBuilderWithInputOutput<
194
+ U,
195
+ TOutputSchema,
196
+ TEffectErrorMap,
197
+ TMeta
198
+ >;
199
+ }
200
+
201
+ export interface EffectContractProcedureBuilderWithInputOutput<
202
+ TInputSchema extends AnySchema,
203
+ TOutputSchema extends AnySchema,
204
+ TEffectErrorMap extends EffectErrorMap,
205
+ TMeta extends Meta,
206
+ >
207
+ extends
208
+ ContractProcedure<
209
+ TInputSchema,
210
+ TOutputSchema,
211
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
212
+ TMeta
213
+ >,
214
+ EffectContractMetadata<TEffectErrorMap> {
215
+ errors<U extends EffectErrorMap>(
216
+ errors: U,
217
+ ): EffectContractProcedureBuilderWithInputOutput<
218
+ TInputSchema,
219
+ TOutputSchema,
220
+ MergedEffectErrorMap<TEffectErrorMap, U>,
221
+ TMeta
222
+ >;
223
+ meta(
224
+ meta: TMeta,
225
+ ): EffectContractProcedureBuilderWithInputOutput<
226
+ TInputSchema,
227
+ TOutputSchema,
228
+ TEffectErrorMap,
229
+ TMeta
230
+ >;
231
+ route(
232
+ route: Route,
233
+ ): EffectContractProcedureBuilderWithInputOutput<
234
+ TInputSchema,
235
+ TOutputSchema,
236
+ TEffectErrorMap,
237
+ TMeta
238
+ >;
239
+ }
240
+
241
+ export interface EffectContractRouterBuilder<
242
+ TEffectErrorMap extends EffectErrorMap,
243
+ TMeta extends Meta,
244
+ > extends EffectContractMetadata<TEffectErrorMap> {
245
+ errors<U extends EffectErrorMap>(
246
+ errors: U,
247
+ ): EffectContractRouterBuilder<
248
+ MergedEffectErrorMap<TEffectErrorMap, U>,
249
+ TMeta
250
+ >;
251
+ prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;
252
+ tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;
253
+ router<T extends ContractRouter<TMeta>>(
254
+ router: T,
255
+ ): ContractWithEffectErrorMap<T, TEffectErrorMap>;
256
+ }
257
+
258
+ export interface EffectContractBuilder<
259
+ TInputSchema extends AnySchema,
260
+ TOutputSchema extends AnySchema,
261
+ TEffectErrorMap extends EffectErrorMap,
262
+ TMeta extends Meta,
263
+ >
264
+ extends
265
+ ContractProcedure<
266
+ TInputSchema,
267
+ TOutputSchema,
268
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
269
+ TMeta
270
+ >,
271
+ EffectContractMetadata<TEffectErrorMap> {
272
+ $meta<U extends Meta>(
273
+ initialMeta: U,
274
+ ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, U>;
275
+ $route(
276
+ initialRoute: Route,
277
+ ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, TMeta>;
278
+ $input<U extends AnySchema>(
279
+ initialInputSchema?: U,
280
+ ): EffectContractBuilder<U, TOutputSchema, TEffectErrorMap, TMeta>;
281
+ errors<U extends EffectErrorMap>(
282
+ errors: U,
283
+ ): EffectContractBuilder<
284
+ TInputSchema,
285
+ TOutputSchema,
286
+ MergedEffectErrorMap<TEffectErrorMap, U>,
287
+ TMeta
288
+ >;
289
+ meta(
290
+ meta: TMeta,
291
+ ): EffectContractProcedureBuilder<
292
+ TInputSchema,
293
+ TOutputSchema,
294
+ TEffectErrorMap,
295
+ TMeta
296
+ >;
297
+ route(
298
+ route: Route,
299
+ ): EffectContractProcedureBuilder<
300
+ TInputSchema,
301
+ TOutputSchema,
302
+ TEffectErrorMap,
303
+ TMeta
304
+ >;
305
+ input<U extends AnySchema>(
306
+ schema: U,
307
+ ): EffectContractProcedureBuilderWithInput<
308
+ U,
309
+ TOutputSchema,
310
+ TEffectErrorMap,
311
+ TMeta
312
+ >;
313
+ output<U extends AnySchema>(
314
+ schema: U,
315
+ ): EffectContractProcedureBuilderWithOutput<
316
+ TInputSchema,
317
+ U,
318
+ TEffectErrorMap,
319
+ TMeta
320
+ >;
321
+ prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;
322
+ tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;
323
+ router<T extends ContractRouter<TMeta>>(
324
+ router: T,
325
+ ): ContractWithEffectErrorMap<T, TEffectErrorMap>;
326
+ }
327
+
328
+ function isWrappableContractBuilder(value: unknown): value is {
329
+ "~orpc": { errorMap: ErrorMap };
330
+ } {
331
+ return typeof value === "object" && value !== null && "~orpc" in value;
332
+ }
333
+
334
+ function mergeEffectErrorMaps(
335
+ left: EffectErrorMap | undefined,
336
+ right: EffectErrorMap | undefined,
337
+ ): EffectErrorMap | undefined {
338
+ if (!left) {
339
+ return right;
340
+ }
341
+
342
+ if (!right) {
343
+ return left;
344
+ }
345
+
346
+ return {
347
+ ...left,
348
+ ...right,
349
+ };
350
+ }
351
+
352
+ function setEffectContractErrorMap(
353
+ value: object,
354
+ effectErrorMap: EffectErrorMap | undefined,
355
+ ): void {
356
+ if (!effectErrorMap) {
357
+ return;
358
+ }
359
+
360
+ Object.defineProperty(value, effectContractSymbol, {
361
+ value: { errorMap: effectErrorMap },
362
+ enumerable: false,
363
+ configurable: true,
364
+ });
365
+ }
366
+
367
+ export function getEffectContractErrorMap(
368
+ value: unknown,
369
+ ): EffectErrorMap | undefined {
370
+ if (typeof value !== "object" || value === null) {
371
+ return undefined;
372
+ }
373
+
374
+ return (value as Partial<EffectContractMetadata<EffectErrorMap>>)[
375
+ effectContractSymbol
376
+ ]?.errorMap;
377
+ }
378
+
379
+ function applyEffectContractErrorMapToRouter(
380
+ router: ContractRouter<Meta>,
381
+ source: ContractRouter<Meta> | undefined,
382
+ inheritedEffectErrorMap: EffectErrorMap | undefined,
383
+ ): void {
384
+ const routerRecord = router as Record<string, ContractRouter<Meta>>;
385
+ const sourceRecord = source as
386
+ | Record<string, ContractRouter<Meta>>
387
+ | undefined;
388
+
389
+ for (const key of Object.keys(routerRecord)) {
390
+ const routerValue = routerRecord[key];
391
+ const sourceValue =
392
+ sourceRecord && typeof sourceRecord === "object"
393
+ ? sourceRecord[key]
394
+ : undefined;
395
+
396
+ if (!routerValue) {
397
+ continue;
398
+ }
399
+
400
+ if (isContractProcedure(routerValue)) {
401
+ const sourceEffectErrorMap = getEffectContractErrorMap(sourceValue);
402
+ setEffectContractErrorMap(
403
+ routerValue,
404
+ mergeEffectErrorMaps(inheritedEffectErrorMap, sourceEffectErrorMap),
405
+ );
406
+ continue;
407
+ }
408
+
409
+ if (typeof routerValue === "object") {
410
+ applyEffectContractErrorMapToRouter(
411
+ routerValue,
412
+ sourceValue as ContractRouter<Meta> | undefined,
413
+ inheritedEffectErrorMap,
414
+ );
415
+ }
416
+ }
417
+ }
418
+
419
+ function wrapEffectContractBuilder<T>(
420
+ builder: T,
421
+ inheritedEffectErrorMap?: EffectErrorMap,
422
+ ): T {
423
+ const currentEffectErrorMap =
424
+ inheritedEffectErrorMap ?? getEffectContractErrorMap(builder);
425
+
426
+ if (typeof builder === "object" && builder !== null) {
427
+ setEffectContractErrorMap(builder as object, currentEffectErrorMap);
428
+ }
429
+
430
+ const proxy = new Proxy(builder as object, {
431
+ get(target, prop, receiver) {
432
+ if (prop === effectContractSymbol) {
433
+ return currentEffectErrorMap
434
+ ? { errorMap: currentEffectErrorMap }
435
+ : undefined;
436
+ }
437
+
438
+ if (prop === "errors") {
439
+ return (errors: EffectErrorMap) => {
440
+ const nextEffectErrorMap = mergeEffectErrorMaps(
441
+ currentEffectErrorMap,
442
+ errors,
443
+ );
444
+
445
+ return wrapEffectContractBuilder(
446
+ Reflect.apply(Reflect.get(target, prop, receiver), target, [
447
+ effectErrorMapToErrorMap(errors),
448
+ ]),
449
+ nextEffectErrorMap,
450
+ );
451
+ };
452
+ }
453
+
454
+ if (prop === "router") {
455
+ return (router: ContractRouter<Meta>) => {
456
+ const result = Reflect.apply(
457
+ Reflect.get(target, prop, receiver),
458
+ target,
459
+ [router],
460
+ ) as ContractRouter<Meta>;
461
+
462
+ applyEffectContractErrorMapToRouter(
463
+ result,
464
+ router,
465
+ currentEffectErrorMap,
466
+ );
467
+
468
+ return result;
469
+ };
470
+ }
471
+
472
+ const value = Reflect.get(target, prop, receiver);
473
+ if (typeof value !== "function") {
474
+ return value;
475
+ }
476
+
477
+ return (...args: unknown[]) => {
478
+ const result = Reflect.apply(value, target, args);
479
+ return isWrappableContractBuilder(result)
480
+ ? wrapEffectContractBuilder(result, currentEffectErrorMap)
481
+ : result;
482
+ };
483
+ },
484
+ }) as T;
485
+
486
+ setEffectContractErrorMap(proxy as object, currentEffectErrorMap);
487
+
488
+ return proxy;
489
+ }
490
+
491
+ export const eoc = wrapEffectContractBuilder(
492
+ oc,
493
+ {},
494
+ ) as unknown as EffectContractBuilder<
495
+ Schema<unknown, unknown>,
496
+ Schema<unknown, unknown>,
497
+ Record<never, never>,
498
+ Record<never, never>
499
+ >;
package/src/index.ts CHANGED
@@ -1,3 +1,18 @@
1
+ export { implementEffect } from "./contract";
2
+ export type {
3
+ EffectImplementer,
4
+ EffectImplementerInternal,
5
+ EffectProcedureImplementer,
6
+ } from "./contract";
7
+ export { eoc } from "./eoc";
8
+ export type {
9
+ EffectContractBuilder,
10
+ EffectContractProcedureBuilder,
11
+ EffectContractProcedureBuilderWithInput,
12
+ EffectContractProcedureBuilderWithInputOutput,
13
+ EffectContractProcedureBuilderWithOutput,
14
+ EffectContractRouterBuilder,
15
+ } from "./eoc";
1
16
  export {
2
17
  addSpanStackTrace,
3
18
  EffectBuilder,
@@ -40,10 +55,10 @@ export type {
40
55
  EffectProcedureHandler,
41
56
  EffectRouterBuilder,
42
57
  EffectSpanConfig,
43
- InferBuilderInitialContext,
44
58
  InferBuilderCurrentContext,
45
- InferBuilderInputSchema,
46
- InferBuilderOutputSchema,
47
59
  InferBuilderErrorMap,
60
+ InferBuilderInitialContext,
61
+ InferBuilderInputSchema,
48
62
  InferBuilderMeta,
63
+ InferBuilderOutputSchema,
49
64
  } from "./types";
package/src/node.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
 
3
- import type { ServiceMap } from "effect";
3
+ import type { Context } from "effect";
4
4
  import { Effect } from "effect";
5
5
 
6
6
  import {
@@ -8,7 +8,7 @@ import {
8
8
  type ServiceContextBridge,
9
9
  } from "./service-context-bridge";
10
10
 
11
- const servicesStorage = new AsyncLocalStorage<ServiceMap.ServiceMap<any>>();
11
+ const servicesStorage = new AsyncLocalStorage<Context.Context<any>>();
12
12
 
13
13
  const bridge: ServiceContextBridge = {
14
14
  getCurrentServices: () => servicesStorage.getStore(),
@@ -19,7 +19,7 @@ installServiceContextBridge(bridge);
19
19
  export function withFiberContext<T, R = never>(
20
20
  fn: () => Promise<T>,
21
21
  ): Effect.Effect<T, never, R> {
22
- return Effect.flatMap(Effect.services<R>(), (services) =>
22
+ return Effect.flatMap(Effect.context<R>(), (services) =>
23
23
  Effect.promise(() => servicesStorage.run(services, fn)),
24
24
  );
25
25
  }
@@ -1,7 +1,7 @@
1
- import type { ServiceMap } from "effect";
1
+ import type { Context } from "effect";
2
2
 
3
3
  export interface ServiceContextBridge {
4
- readonly getCurrentServices: () => ServiceMap.ServiceMap<any> | undefined;
4
+ readonly getCurrentServices: () => Context.Context<any> | undefined;
5
5
  }
6
6
 
7
7
  let bridge: ServiceContextBridge | undefined;
@@ -12,6 +12,6 @@ export function installServiceContextBridge(
12
12
  bridge = nextBridge;
13
13
  }
14
14
 
15
- export function getCurrentServices(): ServiceMap.ServiceMap<any> | undefined {
15
+ export function getCurrentServices(): Context.Context<any> | undefined {
16
16
  return bridge?.getCurrentServices();
17
17
  }