@shivaedev/effect-trpc 0.0.0
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/CHANGELOG.md +6 -0
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/adapter.d.ts +16 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +12 -0
- package/dist/adapter.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/context-bridge.d.ts +7 -0
- package/dist/internal/context-bridge.d.ts.map +1 -0
- package/dist/internal/context-bridge.js +9 -0
- package/dist/internal/context-bridge.js.map +1 -0
- package/dist/internal/procedure-handler.d.ts +13 -0
- package/dist/internal/procedure-handler.d.ts.map +1 -0
- package/dist/internal/procedure-handler.js +12 -0
- package/dist/internal/procedure-handler.js.map +1 -0
- package/dist/internal/procedure-types.d.ts +9 -0
- package/dist/internal/procedure-types.d.ts.map +1 -0
- package/dist/internal/procedure-types.js +2 -0
- package/dist/internal/procedure-types.js.map +1 -0
- package/dist/internal/runtime.d.ts +16 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +60 -0
- package/dist/internal/runtime.js.map +1 -0
- package/dist/internal/stack-trace.d.ts +2 -0
- package/dist/internal/stack-trace.d.ts.map +1 -0
- package/dist/internal/stack-trace.js +19 -0
- package/dist/internal/stack-trace.js.map +1 -0
- package/dist/internal/vitest-trpc.d.ts +18 -0
- package/dist/internal/vitest-trpc.d.ts.map +1 -0
- package/dist/internal/vitest-trpc.js +70 -0
- package/dist/internal/vitest-trpc.js.map +1 -0
- package/dist/procedure.d.ts +27 -0
- package/dist/procedure.d.ts.map +1 -0
- package/dist/procedure.js +34 -0
- package/dist/procedure.js.map +1 -0
- package/dist/request-services.d.ts +7 -0
- package/dist/request-services.d.ts.map +1 -0
- package/dist/request-services.js +4 -0
- package/dist/request-services.js.map +1 -0
- package/dist/testing/caller.d.ts +10 -0
- package/dist/testing/caller.d.ts.map +1 -0
- package/dist/testing/caller.js +41 -0
- package/dist/testing/caller.js.map +1 -0
- package/dist/testing/types.d.ts +31 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/testing/vitest.d.ts +4 -0
- package/dist/testing/vitest.d.ts.map +1 -0
- package/dist/testing/vitest.js +28 -0
- package/dist/testing/vitest.js.map +1 -0
- package/dist/testing.d.ts +4 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -0
- package/src/adapter.ts +85 -0
- package/src/errors.ts +30 -0
- package/src/index.ts +28 -0
- package/src/internal/context-bridge.ts +20 -0
- package/src/internal/procedure-handler.ts +48 -0
- package/src/internal/procedure-types.ts +49 -0
- package/src/internal/runtime.ts +131 -0
- package/src/internal/stack-trace.ts +19 -0
- package/src/internal/vitest-trpc.ts +202 -0
- package/src/procedure.ts +191 -0
- package/src/request-services.ts +43 -0
- package/src/testing/caller.ts +80 -0
- package/src/testing/types.ts +81 -0
- package/src/testing/vitest.ts +64 -0
- package/src/testing.ts +13 -0
- package/src/types.ts +24 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ShivaeDev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# `@shivaedev/effect-trpc`
|
|
2
|
+
|
|
3
|
+
Effect-native query and mutation procedures for tRPC, with an optional Vitest
|
|
4
|
+
harness for calling routers as Effects.
|
|
5
|
+
|
|
6
|
+
This package currently targets exact early-access versions of Effect v4 and
|
|
7
|
+
tRPC. It is built for ShivaeDev applications and may change without a
|
|
8
|
+
deprecation period.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @shivaedev/effect-trpc @trpc/server effect
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Adapter
|
|
17
|
+
|
|
18
|
+
Create one managed Effect runtime for the application, then bind tRPC procedure
|
|
19
|
+
builders to request-scoped Layers:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { initTRPC } from "@trpc/server"
|
|
23
|
+
import { Layer, ManagedRuntime, Schema } from "effect"
|
|
24
|
+
import {
|
|
25
|
+
makeEffectTRPC,
|
|
26
|
+
makeRequestServices,
|
|
27
|
+
} from "@shivaedev/effect-trpc"
|
|
28
|
+
|
|
29
|
+
const runtime = ManagedRuntime.make(ApplicationLive)
|
|
30
|
+
const adapter = makeEffectTRPC({ runtime })
|
|
31
|
+
|
|
32
|
+
const t = initTRPC.context<RequestContext>().create()
|
|
33
|
+
const requestServices = makeRequestServices((context: RequestContext) =>
|
|
34
|
+
Layer.succeed(Session, context.session),
|
|
35
|
+
)
|
|
36
|
+
const procedure = adapter.procedure(t.procedure, requestServices)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The generator receives decoded input and may yield anything supplied by the
|
|
40
|
+
application runtime or request Layer:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const router = t.router({
|
|
44
|
+
movie: procedure
|
|
45
|
+
.input(Schema.Struct({ id: Schema.String }))
|
|
46
|
+
.query(function* ({ id }) {
|
|
47
|
+
const movies = yield* Movies
|
|
48
|
+
return yield* movies.find(id)
|
|
49
|
+
}),
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Effect Schema transformations are preserved across the tRPC boundary. Input
|
|
54
|
+
uses the schema's encoded type at the caller and decoded type in the generator;
|
|
55
|
+
output uses the schema's encoded type in the generator and decoded type at the
|
|
56
|
+
caller.
|
|
57
|
+
|
|
58
|
+
Build middleware, metadata, and other tRPC configuration on the ordinary tRPC
|
|
59
|
+
procedure builder before passing it to `adapter.procedure`. This release wraps
|
|
60
|
+
queries and mutations; subscriptions are not yet supported.
|
|
61
|
+
|
|
62
|
+
## Request services
|
|
63
|
+
|
|
64
|
+
`extendRequestServices` adds services to an existing request Layer while
|
|
65
|
+
retaining its context and requirements:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const adminServices = extendRequestServices(
|
|
69
|
+
requestServices,
|
|
70
|
+
(context: AdminRequestContext) => Layer.succeed(Admin, context.admin),
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Layer construction failures use the same error handling as procedure failures.
|
|
75
|
+
|
|
76
|
+
## Errors and instrumentation
|
|
77
|
+
|
|
78
|
+
Explicit `TRPCError` failures pass through unchanged. The package also exports
|
|
79
|
+
Effect helpers such as `badRequest`, `unauthorized`, `forbidden`, `notFound`,
|
|
80
|
+
and `conflict`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
return yield* notFound("Movie not found")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Unmapped failures and defects become a redacted `INTERNAL_SERVER_ERROR`. Map
|
|
87
|
+
application errors deliberately when they should cross the API boundary:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const adapter = makeEffectTRPC({
|
|
91
|
+
runtime,
|
|
92
|
+
mapError: (error) =>
|
|
93
|
+
error instanceof MovieMissing
|
|
94
|
+
? new TRPCError({ code: "NOT_FOUND", message: error.message })
|
|
95
|
+
: undefined,
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Each procedure runs in a span named after its tRPC path. `instrument` can add
|
|
100
|
+
application-specific Effect logging, metrics, or tracing without changing
|
|
101
|
+
procedure definitions.
|
|
102
|
+
|
|
103
|
+
## Vitest
|
|
104
|
+
|
|
105
|
+
Install `@effect/vitest` to use the optional testing entrypoint:
|
|
106
|
+
|
|
107
|
+
```sh
|
|
108
|
+
pnpm add --save-dev @effect/vitest vitest
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Configure the router caller and test Layer once in the application's test
|
|
112
|
+
support:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { makeTrpcIt } from "@shivaedev/effect-trpc/testing"
|
|
116
|
+
|
|
117
|
+
export const it = makeTrpcIt({
|
|
118
|
+
adapter,
|
|
119
|
+
createCaller: (context = defaultContext) => router.createCaller(context),
|
|
120
|
+
layer: TestLive,
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Tests receive an Effect-shaped caller. Calling the first argument creates a
|
|
125
|
+
caller with different context for that test:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
it.effectTRPC("returns a movie", function* (trpc) {
|
|
129
|
+
const movie = yield* trpc.movie({ id })
|
|
130
|
+
expect(movie.id).toBe(id)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it.effectTRPC("supports another actor", function* (trpc) {
|
|
134
|
+
const movie = yield* trpc({ session: otherSession }).movie({ id })
|
|
135
|
+
expect(movie.id).toBe(id)
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The test Layer is built once per worker. Its services override matching
|
|
140
|
+
application runtime services while all other runtime services remain available.
|
|
141
|
+
Use `around` to add application-wide test behavior such as a rollback wrapper.
|
|
142
|
+
`effectTRPC` supports `skip`, `skipIf`, `runIf`, `only`, `each`, and `fails`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { inferProcedureBuilderResolverOptions, TRPCProcedureBuilder } from "@trpc/server";
|
|
2
|
+
import type { Context, ManagedRuntime } from "effect";
|
|
3
|
+
import { EffectProcedureBuilder } from "./procedure.js";
|
|
4
|
+
import type { EffectProcedureRequestServices } from "./request-services.js";
|
|
5
|
+
import type { EffectTRPCErrorMapper, EffectTRPCInstrument } from "./types.js";
|
|
6
|
+
export interface MakeEffectTRPCOptions<Requirements, RuntimeError> {
|
|
7
|
+
readonly instrument?: EffectTRPCInstrument;
|
|
8
|
+
readonly mapError?: EffectTRPCErrorMapper;
|
|
9
|
+
readonly runtime: ManagedRuntime.ManagedRuntime<Requirements, RuntimeError>;
|
|
10
|
+
}
|
|
11
|
+
export interface EffectTRPCAdapter<Requirements> {
|
|
12
|
+
readonly procedure: <Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, ProvidedServices, LayerError>(builder: TRPCProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, false>, requestServices: EffectProcedureRequestServices<inferProcedureBuilderResolverOptions<TRPCProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, false>>["ctx"], ProvidedServices, LayerError>) => EffectProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, ProvidedServices, LayerError, Requirements>;
|
|
13
|
+
readonly runWithServices: <Services, Value>(services: Context.Context<Services>, evaluate: () => Value) => Value;
|
|
14
|
+
}
|
|
15
|
+
export declare const makeEffectTRPC: <Requirements, RuntimeError = never>(options: MakeEffectTRPCOptions<Requirements, RuntimeError>) => EffectTRPCAdapter<Requirements>;
|
|
16
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oCAAoC,EACpC,oBAAoB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,qBAAqB,CAAC,YAAY,EAAE,YAAY;IAChE,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;CAC5E;AAED,MAAM,WAAW,iBAAiB,CAAC,YAAY;IAC9C,QAAQ,CAAC,SAAS,EAAE,CACnB,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,UAAU,EAEV,OAAO,EAAE,oBAAoB,CAC5B,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,CACL,EACD,eAAe,EAAE,8BAA8B,CAC9C,oCAAoC,CACnC,oBAAoB,CACnB,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,KAAK,CACL,CACD,CAAC,KAAK,CAAC,EACR,gBAAgB,EAChB,UAAU,CACV,KACG,sBAAsB,CAC1B,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,YAAY,CACZ,CAAC;IACF,QAAQ,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE,KAAK,EACzC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnC,QAAQ,EAAE,MAAM,KAAK,KACjB,KAAK,CAAC;CACX;AAED,eAAO,MAAM,cAAc,GAAI,YAAY,EAAE,YAAY,GAAG,KAAK,EAChE,SAAS,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,KACxD,iBAAiB,CAAC,YAAY,CAShC,CAAC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { makeContextBridge } from "./internal/context-bridge.js";
|
|
2
|
+
import { makeRuntimeBridge } from "./internal/runtime.js";
|
|
3
|
+
import { EffectProcedureBuilder } from "./procedure.js";
|
|
4
|
+
export const makeEffectTRPC = (options) => {
|
|
5
|
+
const contextBridge = makeContextBridge();
|
|
6
|
+
const runtime = makeRuntimeBridge(options.runtime, contextBridge, options);
|
|
7
|
+
return {
|
|
8
|
+
procedure: (builder, requestServices) => new EffectProcedureBuilder(builder, requestServices, runtime),
|
|
9
|
+
runWithServices: contextBridge.run,
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAkExD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,OAA0D,EACxB,EAAE;IACpC,MAAM,aAAa,GAAG,iBAAiB,EAAE,CAAC;IAC1C,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAE3E,OAAO;QACN,SAAS,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,CACvC,IAAI,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAU;QACvE,eAAe,EAAE,aAAa,CAAC,GAAG;KAClC,CAAC;AACH,CAAC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TRPCError } from "@trpc/server";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
export declare const fail: (code: TRPCError["code"], message: string, cause?: unknown) => Effect.Effect<never, TRPCError>;
|
|
4
|
+
export declare const badRequest: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
5
|
+
export declare const unauthorized: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
6
|
+
export declare const forbidden: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
7
|
+
export declare const notFound: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
8
|
+
export declare const conflict: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
9
|
+
export declare const preconditionFailed: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
10
|
+
export declare const internalServerError: (message: string, cause?: unknown) => Effect.Effect<never, TRPCError, never>;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,IAAI,GAChB,MAAM,SAAS,CAAC,MAAM,CAAC,EACvB,SAAS,MAAM,EACf,QAAQ,OAAO,KACb,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CACoB,CAAC;AAEtD,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACvB,CAAC;AAErC,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACxB,CAAC;AAEtC,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACxB,CAAC;AAEnC,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACvB,CAAC;AAEnC,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACxB,CAAC;AAElC,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACvB,CAAC;AAE7C,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,EAAE,QAAQ,OAAO,2CACtB,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TRPCError } from "@trpc/server";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
export const fail = (code, message, cause) => Effect.fail(new TRPCError({ cause, code, message }));
|
|
4
|
+
export const badRequest = (message, cause) => fail("BAD_REQUEST", message, cause);
|
|
5
|
+
export const unauthorized = (message, cause) => fail("UNAUTHORIZED", message, cause);
|
|
6
|
+
export const forbidden = (message, cause) => fail("FORBIDDEN", message, cause);
|
|
7
|
+
export const notFound = (message, cause) => fail("NOT_FOUND", message, cause);
|
|
8
|
+
export const conflict = (message, cause) => fail("CONFLICT", message, cause);
|
|
9
|
+
export const preconditionFailed = (message, cause) => fail("PRECONDITION_FAILED", message, cause);
|
|
10
|
+
export const internalServerError = (message, cause) => fail("INTERNAL_SERVER_ERROR", message, cause);
|
|
11
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,IAAI,GAAG,CACnB,IAAuB,EACvB,OAAe,EACf,KAAe,EACmB,EAAE,CACpC,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAEtD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CAC9D,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CAChE,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEtC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CAC7D,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CAC5D,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CAC5D,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CACtE,IAAI,CAAC,qBAAqB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAE,KAAe,EAAE,EAAE,CACvE,IAAI,CAAC,uBAAuB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type EffectTRPCAdapter, type MakeEffectTRPCOptions, makeEffectTRPC, } from "./adapter.js";
|
|
2
|
+
export { badRequest, conflict, fail, forbidden, internalServerError, notFound, preconditionFailed, unauthorized, } from "./errors.js";
|
|
3
|
+
export type { EffectProcedureBuilder } from "./procedure.js";
|
|
4
|
+
export { type EffectProcedureRequestServices, extendRequestServices, makeRequestServices, } from "./request-services.js";
|
|
5
|
+
export type { EffectTRPCErrorContext, EffectTRPCErrorMapper, EffectTRPCInstrument, ProcedureInfo, ProcedureKind, } from "./types.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,YAAY,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EACN,KAAK,8BAA8B,EACnC,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,aAAa,GACb,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { makeEffectTRPC, } from "./adapter.js";
|
|
2
|
+
export { badRequest, conflict, fail, forbidden, internalServerError, notFound, preconditionFailed, unauthorized, } from "./errors.js";
|
|
3
|
+
export { extendRequestServices, makeRequestServices, } from "./request-services.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,cAAc,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EAClB,YAAY,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAEN,qBAAqB,EACrB,mBAAmB,GACnB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from "effect";
|
|
2
|
+
export interface ContextBridge {
|
|
3
|
+
readonly current: () => Context.Context<never> | undefined;
|
|
4
|
+
readonly run: <Services, Value>(services: Context.Context<Services>, evaluate: () => Value) => Value;
|
|
5
|
+
}
|
|
6
|
+
export declare const makeContextBridge: () => ContextBridge;
|
|
7
|
+
//# sourceMappingURL=context-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-bridge.d.ts","sourceRoot":"","sources":["../../src/internal/context-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,EAC7B,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnC,QAAQ,EAAE,MAAM,KAAK,KACjB,KAAK,CAAC;CACX;AAED,eAAO,MAAM,iBAAiB,QAAO,aAQpC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
export const makeContextBridge = () => {
|
|
3
|
+
const storage = new AsyncLocalStorage();
|
|
4
|
+
return {
|
|
5
|
+
current: () => storage.getStore(),
|
|
6
|
+
run: (services, evaluate) => storage.run(services, evaluate),
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=context-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-bridge.js","sourceRoot":"","sources":["../../src/internal/context-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAWrD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAkB,EAAE;IACpD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAA0B,CAAC;IAEhE,OAAO;QACN,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE;QACjC,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAC3B,OAAO,CAAC,GAAG,CAAC,QAAkC,EAAE,QAAQ,CAAC;KAC1D,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EffectProcedureRequestServices } from "../request-services.js";
|
|
2
|
+
import type { ProcedureInfo } from "../types.js";
|
|
3
|
+
import type { EffectProcedureResolver } from "./procedure-types.js";
|
|
4
|
+
import type { RuntimeBridge } from "./runtime.js";
|
|
5
|
+
interface ProcedureInvocation<Context, Input> {
|
|
6
|
+
readonly ctx: Context;
|
|
7
|
+
readonly input: Input;
|
|
8
|
+
readonly path: string;
|
|
9
|
+
readonly signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare const makeProcedureHandler: <RuntimeRequirements, Context, Input, ProvidedServices, LayerError, Output>(runtime: RuntimeBridge<RuntimeRequirements>, resolver: EffectProcedureResolver<Input, ProvidedServices | NoInfer<RuntimeRequirements>, Output>, requestServices: EffectProcedureRequestServices<Context, ProvidedServices, LayerError>, procedure: Omit<ProcedureInfo, "path">) => (invocation: ProcedureInvocation<Context, Input>) => Promise<Output>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=procedure-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-handler.d.ts","sourceRoot":"","sources":["../../src/internal/procedure-handler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,UAAU,mBAAmB,CAAC,OAAO,EAAE,KAAK;IAC3C,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED,eAAO,MAAM,oBAAoB,GAChC,mBAAmB,EACnB,OAAO,EACP,KAAK,EACL,gBAAgB,EAChB,UAAU,EACV,MAAM,EAEN,SAAS,aAAa,CAAC,mBAAmB,CAAC,EAC3C,UAAU,uBAAuB,CAChC,KAAK,EACL,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC,EAC/C,MAAM,CACN,EACD,iBAAiB,8BAA8B,CAC9C,OAAO,EACP,gBAAgB,EAChB,UAAU,CACV,EACD,WAAW,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,MAIxB,YAAY,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,oBAW7D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export const makeProcedureHandler = (runtime, resolver, requestServices, procedure) => {
|
|
3
|
+
const tracedResolver = Effect.fnUntraced(resolver);
|
|
4
|
+
return async (invocation) => {
|
|
5
|
+
const provided = Effect.suspend(() => tracedResolver(invocation.input).pipe(Effect.provide(requestServices.layer(invocation.ctx))));
|
|
6
|
+
return await runtime.runEffect(provided, {
|
|
7
|
+
procedure: { ...procedure, path: invocation.path },
|
|
8
|
+
...(invocation.signal === undefined ? {} : { signal: invocation.signal }),
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=procedure-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-handler.js","sourceRoot":"","sources":["../../src/internal/procedure-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAahC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAQnC,OAA2C,EAC3C,QAIC,EACD,eAIC,EACD,SAAsC,EACrC,EAAE;IACH,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEnD,OAAO,KAAK,EAAE,UAA+C,EAAE,EAAE;QAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CACpC,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CACpC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CACrD,CACD,CAAC;QACF,OAAO,MAAM,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE;YACxC,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE;YAClD,GAAG,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;SACzE,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { inferProcedureBuilderResolverOptions, TRPCProcedureBuilder, TRPCUnsetMarker } from "@trpc/server";
|
|
2
|
+
import type { Effect } from "effect";
|
|
3
|
+
export type AnyProcedureBuilder = TRPCProcedureBuilder<any, any, any, any, any, any, any, false>;
|
|
4
|
+
export type DefaultValue<Value, Fallback> = Value extends TRPCUnsetMarker ? Fallback : Value;
|
|
5
|
+
export type IntersectIfDefined<Value, With> = Value extends TRPCUnsetMarker ? With : With extends TRPCUnsetMarker ? Value : Value & With;
|
|
6
|
+
export type ResolverContext<Builder extends AnyProcedureBuilder> = inferProcedureBuilderResolverOptions<Builder>["ctx"];
|
|
7
|
+
export type ProcedureEffect<Requirements> = Effect.Effect<any, any, Requirements>;
|
|
8
|
+
export type EffectProcedureResolver<Input, Requirements, Output> = (input: Input) => Generator<ProcedureEffect<Requirements>, Output, never>;
|
|
9
|
+
//# sourceMappingURL=procedure-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-types.d.ts","sourceRoot":"","sources":["../../src/internal/procedure-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oCAAoC,EACpC,oBAAoB,EACpB,eAAe,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAErD,GAAG,EAEH,GAAG,EAEH,GAAG,EAEH,GAAG,EAEH,GAAG,EAEH,GAAG,EAEH,GAAG,EACH,KAAK,CACL,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,KAAK,EAAE,QAAQ,IAAI,KAAK,SAAS,eAAe,GACtE,QAAQ,GACR,KAAK,CAAC;AAET,MAAM,MAAM,kBAAkB,CAAC,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,eAAe,GACxE,IAAI,GACJ,IAAI,SAAS,eAAe,GAC3B,KAAK,GACL,KAAK,GAAG,IAAI,CAAC;AAEjB,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,mBAAmB,IAC9D,oCAAoC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AAEtD,MAAM,MAAM,eAAe,CAAC,YAAY,IAAI,MAAM,CAAC,MAAM,CAExD,GAAG,EAEH,GAAG,EACH,YAAY,CACZ,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAClE,KAAK,EAAE,KAAK,KACR,SAAS,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-types.js","sourceRoot":"","sources":["../../src/internal/procedure-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect, type ManagedRuntime } from "effect";
|
|
2
|
+
import type { EffectTRPCErrorMapper, EffectTRPCInstrument, ProcedureInfo } from "../types.js";
|
|
3
|
+
import type { ContextBridge } from "./context-bridge.js";
|
|
4
|
+
interface RunEffectOptions {
|
|
5
|
+
readonly procedure: ProcedureInfo;
|
|
6
|
+
readonly signal?: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface RuntimeBridge<Requirements> {
|
|
9
|
+
readonly runEffect: <Value>(effect: Effect.Effect<Value, unknown, Requirements>, options: RunEffectOptions) => Promise<Value>;
|
|
10
|
+
}
|
|
11
|
+
export declare const makeRuntimeBridge: <Requirements, RuntimeError>(runtime: ManagedRuntime.ManagedRuntime<Requirements, RuntimeError>, contextBridge: ContextBridge, options: {
|
|
12
|
+
readonly instrument?: EffectTRPCInstrument;
|
|
13
|
+
readonly mapError?: EffectTRPCErrorMapper;
|
|
14
|
+
}) => RuntimeBridge<Requirements>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,MAAM,EAEN,KAAK,cAAc,EAGnB,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EACX,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,UAAU,gBAAgB;IACzB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa,CAAC,YAAY;IAC1C,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EACzB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EACnD,OAAO,EAAE,gBAAgB,KACrB,OAAO,CAAC,KAAK,CAAC,CAAC;CACpB;AA4BD,eAAO,MAAM,iBAAiB,GAAI,YAAY,EAAE,YAAY,EAC3D,SAAS,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,EAClE,eAAe,aAAa,EAC5B,SAAS;IACR,QAAQ,CAAC,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAC1C,KACC,aAAa,CAAC,YAAY,CAoE3B,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { TRPCError } from "@trpc/server";
|
|
2
|
+
import { Cause, Context, Effect, Exit, Option, Result, } from "effect";
|
|
3
|
+
const internalError = (cause) => new TRPCError({
|
|
4
|
+
cause,
|
|
5
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
6
|
+
message: "Internal server error",
|
|
7
|
+
});
|
|
8
|
+
const mapError = (error, origin, procedure, consumerMapper) => {
|
|
9
|
+
if (error instanceof TRPCError) {
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return (consumerMapper?.(error, { ...procedure, origin }) ?? internalError(error));
|
|
14
|
+
}
|
|
15
|
+
catch (mapperDefect) {
|
|
16
|
+
return internalError(mapperDefect);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const makeRuntimeBridge = (runtime, contextBridge, options) => ({
|
|
20
|
+
runEffect: async (effect, runOptions) => {
|
|
21
|
+
const traced = effect.pipe(Effect.withSpan(runOptions.procedure.path, {
|
|
22
|
+
attributes: {
|
|
23
|
+
"rpc.method": runOptions.procedure.path,
|
|
24
|
+
"rpc.system": "trpc",
|
|
25
|
+
"trpc.type": runOptions.procedure.type,
|
|
26
|
+
},
|
|
27
|
+
}, {
|
|
28
|
+
captureStackTrace: runOptions.procedure.captureStackTrace,
|
|
29
|
+
}));
|
|
30
|
+
const instrumented = Effect.suspend(() => options.instrument === undefined
|
|
31
|
+
? traced
|
|
32
|
+
: options.instrument(traced, runOptions.procedure));
|
|
33
|
+
const ambient = contextBridge.current();
|
|
34
|
+
const runnable = ambient === undefined
|
|
35
|
+
? instrumented
|
|
36
|
+
: Effect.flatMap(runtime.contextEffect, (base) => Effect.provideContext(instrumented, Context.merge(base, ambient)));
|
|
37
|
+
const exit = await runtime.runPromiseExit(runnable, runOptions.signal === undefined
|
|
38
|
+
? undefined
|
|
39
|
+
: { signal: runOptions.signal });
|
|
40
|
+
if (Exit.isSuccess(exit)) {
|
|
41
|
+
return exit.value;
|
|
42
|
+
}
|
|
43
|
+
if (Cause.hasInterruptsOnly(exit.cause)) {
|
|
44
|
+
throw new TRPCError({
|
|
45
|
+
code: "CLIENT_CLOSED_REQUEST",
|
|
46
|
+
message: "Request cancelled",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const failure = Cause.findErrorOption(exit.cause);
|
|
50
|
+
if (Option.isSome(failure)) {
|
|
51
|
+
throw mapError(failure.value, "failure", runOptions.procedure, options.mapError);
|
|
52
|
+
}
|
|
53
|
+
const defect = Cause.findDefect(exit.cause);
|
|
54
|
+
if (Result.isSuccess(defect)) {
|
|
55
|
+
throw mapError(defect.success, "defect", runOptions.procedure, options.mapError);
|
|
56
|
+
}
|
|
57
|
+
throw internalError();
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,IAAI,EAEJ,MAAM,EACN,MAAM,GACN,MAAM,QAAQ,CAAC;AAoBhB,MAAM,aAAa,GAAG,CAAC,KAAe,EAAa,EAAE,CACpD,IAAI,SAAS,CAAC;IACb,KAAK;IACL,IAAI,EAAE,uBAAuB;IAC7B,OAAO,EAAE,uBAAuB;CAChC,CAAC,CAAC;AAEJ,MAAM,QAAQ,GAAG,CAChB,KAAc,EACd,MAA4B,EAC5B,SAAwB,EACxB,cAAiD,EACrC,EAAE;IACd,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC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sourceRoot":"","sources":["../../src/internal/stack-trace.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,QAAO,CAAC,MAAM,MAAM,GAAG,SAAS,CAkB7D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const captureStackTrace = () => {
|
|
2
|
+
const limit = Error.stackTraceLimit;
|
|
3
|
+
Error.stackTraceLimit = 3;
|
|
4
|
+
const traceError = new Error();
|
|
5
|
+
Error.stackTraceLimit = limit;
|
|
6
|
+
let cache = false;
|
|
7
|
+
return () => {
|
|
8
|
+
if (cache !== false) {
|
|
9
|
+
return cache;
|
|
10
|
+
}
|
|
11
|
+
const frame = traceError.stack?.split("\n")[3];
|
|
12
|
+
if (frame !== undefined) {
|
|
13
|
+
cache = frame.trim();
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=stack-trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack-trace.js","sourceRoot":"","sources":["../../src/internal/stack-trace.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAA+B,EAAE;IACjE,MAAM,KAAK,GAAG,KAAK,CAAC,eAAe,CAAC;IACpC,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,KAAK,EAAE,CAAC;IAC/B,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC;IAE9B,IAAI,KAAK,GAAmB,KAAK,CAAC;IAClC,OAAO,GAAG,EAAE;QACX,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;YACrB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TestContext, TestOptions } from "@effect/vitest";
|
|
2
|
+
import { type Context } from "effect";
|
|
3
|
+
import type { TrpcTester, TrpcTestRuntimeOptions } from "../testing/types.js";
|
|
4
|
+
export declare const fixtureName = "__effectTrpcContext";
|
|
5
|
+
export type TrpcFixture<Provided> = TestContext & {
|
|
6
|
+
readonly [fixtureName]: Context.Context<Provided>;
|
|
7
|
+
};
|
|
8
|
+
export interface FixtureTestApi<Provided> {
|
|
9
|
+
(name: string, options: TestOptions, body: (context: TrpcFixture<Provided>) => Promise<unknown>): void;
|
|
10
|
+
readonly skip: FixtureTestApi<Provided>;
|
|
11
|
+
readonly skipIf: (condition: unknown) => FixtureTestApi<Provided>;
|
|
12
|
+
readonly runIf: (condition: unknown) => FixtureTestApi<Provided>;
|
|
13
|
+
readonly only: FixtureTestApi<Provided>;
|
|
14
|
+
readonly fails: FixtureTestApi<Provided>;
|
|
15
|
+
readonly for: <Item>(cases: ReadonlyArray<Item>) => (name: string, options: TestOptions, body: (item: Item, context: TrpcFixture<Provided>) => Promise<unknown>) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare const makeTrpcTester: <Options, Caller extends object, Provided, LayerError>(fixtureIt: FixtureTestApi<Provided>, options: TrpcTestRuntimeOptions<Options, Caller, Provided, LayerError>) => TrpcTester<Options, Caller, Provided>;
|
|
18
|
+
//# sourceMappingURL=vitest-trpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitest-trpc.d.ts","sourceRoot":"","sources":["../../src/internal/vitest-trpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAA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ACR,UAAU,EAEV,WAAW,cAAc,CAAC,QAAQ,CAAC,EACnC,SAAS,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,KACpE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CA0HtC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Cause, Effect, Exit, Layer } from "effect";
|
|
2
|
+
import * as TestClock from "effect/testing/TestClock";
|
|
3
|
+
import * as TestConsole from "effect/testing/TestConsole";
|
|
4
|
+
import { makeEffectCallerFactory } from "../testing/caller.js";
|
|
5
|
+
export const fixtureName = "__effectTrpcContext";
|
|
6
|
+
const TestEnvironment = Layer.mergeAll(TestConsole.layer, TestClock.layer());
|
|
7
|
+
const normalizeTestOptions = (options) => typeof options === "number" ? { timeout: options } : (options ?? {});
|
|
8
|
+
const restoreContext = (fixture, context) => ({ ...context, [fixtureName]: fixture });
|
|
9
|
+
const contextFrom = (context) => context[fixtureName];
|
|
10
|
+
const runEffectTest = (effect, context) => Effect.runPromise(Effect.gen(function* () {
|
|
11
|
+
const exit = yield* Effect.exit(effect);
|
|
12
|
+
if (Exit.isFailure(exit)) {
|
|
13
|
+
for (const error of Cause.prettyErrors(exit.cause)) {
|
|
14
|
+
yield* Effect.logError(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return yield* exit;
|
|
18
|
+
}).pipe(Effect.scoped, Effect.provide(TestEnvironment)), { signal: context.signal });
|
|
19
|
+
export const makeTrpcTester = (fixtureIt, options) => {
|
|
20
|
+
const run = (body, context) => {
|
|
21
|
+
const program = Effect.gen(function* () {
|
|
22
|
+
const services = yield* Effect.context();
|
|
23
|
+
const trpc = makeEffectCallerFactory(options.adapter, options.createCaller, services);
|
|
24
|
+
return yield* Effect.gen(() => body(trpc, context));
|
|
25
|
+
});
|
|
26
|
+
// The body constraint proves every yielded service is part of Provided.
|
|
27
|
+
// TypeScript cannot reduce that generic generator requirement here.
|
|
28
|
+
const ready = program;
|
|
29
|
+
const wrapped = options.around?.(ready) ?? ready;
|
|
30
|
+
return wrapped.pipe(Effect.provide(contextFrom(context)));
|
|
31
|
+
};
|
|
32
|
+
const register = (current) => (name, body, testOptions) => current(name, normalizeTestOptions(testOptions), ({ __effectTrpcContext, task, signal, onTestFailed, onTestFinished, skip, annotate, expect, _local, }) => {
|
|
33
|
+
const context = restoreContext(__effectTrpcContext, {
|
|
34
|
+
task,
|
|
35
|
+
signal,
|
|
36
|
+
onTestFailed,
|
|
37
|
+
onTestFinished,
|
|
38
|
+
skip,
|
|
39
|
+
annotate,
|
|
40
|
+
expect,
|
|
41
|
+
_local,
|
|
42
|
+
});
|
|
43
|
+
return runEffectTest(run(body, context), context);
|
|
44
|
+
});
|
|
45
|
+
const make = (current) => {
|
|
46
|
+
const test = register(current);
|
|
47
|
+
return Object.assign(test, {
|
|
48
|
+
skip: register(current.skip),
|
|
49
|
+
skipIf: (condition) => register(current.skipIf(condition)),
|
|
50
|
+
runIf: (condition) => register(current.runIf(condition)),
|
|
51
|
+
only: register(current.only),
|
|
52
|
+
each: (cases) => (name, body, testOptions) => fixtureIt.for(cases)(name, normalizeTestOptions(testOptions), (item, { __effectTrpcContext, task, signal, onTestFailed, onTestFinished, skip, annotate, expect, _local, }) => {
|
|
53
|
+
const context = restoreContext(__effectTrpcContext, {
|
|
54
|
+
task,
|
|
55
|
+
signal,
|
|
56
|
+
onTestFailed,
|
|
57
|
+
onTestFinished,
|
|
58
|
+
skip,
|
|
59
|
+
annotate,
|
|
60
|
+
expect,
|
|
61
|
+
_local,
|
|
62
|
+
});
|
|
63
|
+
return runEffectTest(run((trpc, testContext) => body(item, trpc, testContext), context), context);
|
|
64
|
+
}),
|
|
65
|
+
fails: register(current.fails),
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
return make(fixtureIt);
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=vitest-trpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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ACR,MAAM,EACN,MAAM,GACiB,EACvB,EAAE;gBACH,MAAM,OAAO,GAAG,cAAc,CAAC,mBAAmB,EAAE;oBACnD,IAAI;oBACJ,MAAM;oBACN,YAAY;oBACZ,cAAc;oBACd,IAAI;oBACJ,QAAQ;oBACR,MAAM;oBACN,MAAM;iBACN,CAAC,CAAC;gBACH,OAAO,aAAa,CACnB,GAAG,CACF,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,EACpD,OAAO,CACP,EACD,OAAO,CACP,CAAC;YACH,CAAC,CACD;YACH,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;SAC9B,CAAC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC;AACxB,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TRPCMutationProcedure, TRPCProcedureBuilder, TRPCQueryProcedure } from "@trpc/server";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import type { DefaultValue, EffectProcedureResolver, IntersectIfDefined, ResolverContext } from "./internal/procedure-types.js";
|
|
4
|
+
import type { RuntimeBridge } from "./internal/runtime.js";
|
|
5
|
+
import type { EffectProcedureRequestServices } from "./request-services.js";
|
|
6
|
+
type Builder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut> = TRPCProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, false>;
|
|
7
|
+
export declare class EffectProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut, ProvidedServices, LayerError, RuntimeRequirements> {
|
|
8
|
+
private readonly builder;
|
|
9
|
+
private readonly requestServices;
|
|
10
|
+
private readonly runtime;
|
|
11
|
+
constructor(builder: Builder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut>, requestServices: EffectProcedureRequestServices<ResolverContext<Builder<Context, Meta, ContextOverrides, InputIn, InputOut, OutputIn, OutputOut>>, ProvidedServices, LayerError>, runtime: RuntimeBridge<RuntimeRequirements>);
|
|
12
|
+
input<SchemaValue extends Schema.ConstraintDecoder<unknown>>(schema: SchemaValue): EffectProcedureBuilder<Context, Meta, ContextOverrides, IntersectIfDefined<InputIn, SchemaValue["Encoded"]>, IntersectIfDefined<InputOut, SchemaValue["Type"]>, OutputIn, OutputOut, ProvidedServices, LayerError, RuntimeRequirements>;
|
|
13
|
+
output<SchemaValue extends Schema.ConstraintDecoder<unknown>>(schema: SchemaValue): EffectProcedureBuilder<Context, Meta, ContextOverrides, InputIn, InputOut, IntersectIfDefined<OutputIn, SchemaValue["Encoded"]>, IntersectIfDefined<OutputOut, SchemaValue["Type"]>, ProvidedServices, LayerError, RuntimeRequirements>;
|
|
14
|
+
query<Output>(resolver: EffectProcedureResolver<DefaultValue<InputOut, undefined>, ProvidedServices | NoInfer<RuntimeRequirements>, DefaultValue<OutputIn, Output>>): TRPCQueryProcedure<{
|
|
15
|
+
input: DefaultValue<InputIn, void>;
|
|
16
|
+
output: DefaultValue<OutputOut, Output>;
|
|
17
|
+
meta: Meta;
|
|
18
|
+
}>;
|
|
19
|
+
mutation<Output>(resolver: EffectProcedureResolver<DefaultValue<InputOut, undefined>, ProvidedServices | NoInfer<RuntimeRequirements>, DefaultValue<OutputIn, Output>>): TRPCMutationProcedure<{
|
|
20
|
+
input: DefaultValue<InputIn, void>;
|
|
21
|
+
output: DefaultValue<OutputOut, Output>;
|
|
22
|
+
meta: Meta;
|
|
23
|
+
}>;
|
|
24
|
+
private dispatch;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=procedure.d.ts.map
|