@dr_nikson/effect-grpc 0.2.0-mvp-9971208edee70b39058f12d8c2a1fcfaeecd3b51 → 3.0.0-alpha.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/README.md +863 -0
- package/dist/client.d.ts +38 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.internal.d.ts.map +1 -1
- package/dist/client.internal.js +36 -9
- package/dist/client.internal.js.map +1 -1
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -1
- package/dist/grpcException.d.ts +243 -0
- package/dist/grpcException.d.ts.map +1 -0
- package/dist/grpcException.internal.d.ts +28 -0
- package/dist/grpcException.internal.d.ts.map +1 -0
- package/dist/grpcException.internal.js +72 -0
- package/dist/grpcException.internal.js.map +1 -0
- package/dist/grpcException.js +218 -0
- package/dist/grpcException.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/protoRuntime.d.ts +7 -6
- package/dist/protoRuntime.d.ts.map +1 -1
- package/dist/protoRuntime.internal.d.ts +7 -6
- package/dist/protoRuntime.internal.d.ts.map +1 -1
- package/dist/protoRuntime.internal.js +20 -6
- package/dist/protoRuntime.internal.js.map +1 -1
- package/dist/protoRuntime.js +2 -0
- package/dist/protoRuntime.js.map +1 -1
- package/dist/protocGenPlugin.d.ts.map +1 -1
- package/dist/protocGenPlugin.js +360 -147
- package/dist/protocGenPlugin.js.map +1 -1
- package/dist/server.d.ts +10 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/server.internal.d.ts +6 -5
- package/dist/server.internal.d.ts.map +1 -1
- package/dist/server.internal.js +51 -14
- package/dist/server.internal.js.map +1 -1
- package/dist/server.js +5 -1
- package/dist/server.js.map +1 -1
- package/dist/typeUtils.js +1 -1
- package/dist/typeUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// packages/effect-grpc/src/grpcException.ts
|
|
2
|
+
import { Data } from "effect";
|
|
3
|
+
import * as internal from "./grpcException.internal.js";
|
|
4
|
+
/**
|
|
5
|
+
* A high-level error type for gRPC operations in Effect programs.
|
|
6
|
+
*
|
|
7
|
+
* GrpcException is a tagged error that extends Data.TaggedError, designed as part of the DSL
|
|
8
|
+
* for gRPC error handling. It focuses on application-level concerns (code, message, description, cause)
|
|
9
|
+
* rather than low-level wire-format details.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Effect } from "effect";
|
|
14
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
15
|
+
* import { Code } from "@connectrpc/connect";
|
|
16
|
+
*
|
|
17
|
+
* // Create an exception with a code and message
|
|
18
|
+
* const notFoundError = GrpcException.create(
|
|
19
|
+
* Code.NotFound,
|
|
20
|
+
* "User not found"
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* // Use in Effect programs with catchTag
|
|
24
|
+
* const program = Effect.gen(function* () {
|
|
25
|
+
* yield* notFoundError; // The error is yieldable
|
|
26
|
+
* yield* Effect.fail(notFoundError);
|
|
27
|
+
* }).pipe(
|
|
28
|
+
* Effect.catchTag(GrpcException, (error) => {
|
|
29
|
+
* console.log(`gRPC error [${Code[error.code]}]: ${error.message}`);
|
|
30
|
+
* return Effect.succeed("recovered");
|
|
31
|
+
* })
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // Convert from unknown error
|
|
35
|
+
* try {
|
|
36
|
+
* // some operation
|
|
37
|
+
* } catch (error) {
|
|
38
|
+
* yield* GrpcException.from(Code.Internal, error);
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Add context with description
|
|
42
|
+
* const enriched = GrpcException.withDescription(
|
|
43
|
+
* notFoundError,
|
|
44
|
+
* "Database query failed"
|
|
45
|
+
* );
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @category Error Handling
|
|
49
|
+
* @since 0.2.0
|
|
50
|
+
*/
|
|
51
|
+
export class GrpcException extends Data.TaggedError("@dr_nikson/effect-grpc/grpcException/GrpcException") {
|
|
52
|
+
/**
|
|
53
|
+
* Returns a formatted error message including the status code, message, and description (if present).
|
|
54
|
+
* This is called automatically when the error is converted to a string.
|
|
55
|
+
*
|
|
56
|
+
* Format:
|
|
57
|
+
* - Without description: "[code] message"
|
|
58
|
+
* - With description: "[code] message (description)"
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
63
|
+
* import { Code } from "@connectrpc/connect";
|
|
64
|
+
*
|
|
65
|
+
* const error1 = GrpcException.create(
|
|
66
|
+
* Code.NotFound,
|
|
67
|
+
* "User not found"
|
|
68
|
+
* );
|
|
69
|
+
* console.log(error1.toString());
|
|
70
|
+
* // Output: "[not_found] User not found"
|
|
71
|
+
*
|
|
72
|
+
* const error2 = GrpcException.withDescription(
|
|
73
|
+
* error1,
|
|
74
|
+
* "Database query failed"
|
|
75
|
+
* );
|
|
76
|
+
* console.log(error2.toString());
|
|
77
|
+
* // Output: "[not_found] User not found (Database query failed)"
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
toString() {
|
|
81
|
+
return internal.toString(this);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Custom inspection for Node.js util.inspect
|
|
85
|
+
*/
|
|
86
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
87
|
+
return internal.inspect(this);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new GrpcException from the provided parameters.
|
|
92
|
+
*
|
|
93
|
+
* This is the primary constructor for creating GrpcException instances.
|
|
94
|
+
* Code and message are required; cause is optional.
|
|
95
|
+
*
|
|
96
|
+
* @param code - The gRPC status code (required)
|
|
97
|
+
* @param message - The error message (required)
|
|
98
|
+
* @param cause - Optional cause of the error
|
|
99
|
+
* @returns A new GrpcException instance
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
104
|
+
* import { Code } from "@connectrpc/connect";
|
|
105
|
+
*
|
|
106
|
+
* // Simple error
|
|
107
|
+
* const error1 = GrpcException.create(
|
|
108
|
+
* Code.NotFound,
|
|
109
|
+
* "User not found"
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* // With cause
|
|
113
|
+
* try {
|
|
114
|
+
* // some operation
|
|
115
|
+
* } catch (err) {
|
|
116
|
+
* const error2 = GrpcException.create(
|
|
117
|
+
* Code.Internal,
|
|
118
|
+
* "Operation failed",
|
|
119
|
+
* err
|
|
120
|
+
* );
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export const create = internal.create;
|
|
125
|
+
/**
|
|
126
|
+
* Converts any value into a GrpcException, following these rules:
|
|
127
|
+
* - If the cause is a ConnectError, wraps it preserving code and message
|
|
128
|
+
* - For other Errors, creates a GrpcException with the error message and sets it as cause
|
|
129
|
+
* - For other values, converts to string and uses as message
|
|
130
|
+
*
|
|
131
|
+
* @param code - The gRPC status code to use (required)
|
|
132
|
+
* @param cause - The error/value to convert (native Error, ConnectError, or any value)
|
|
133
|
+
* @returns A GrpcException instance
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* import { Effect } from "effect";
|
|
138
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
139
|
+
* import { Code, ConnectError } from "@connectrpc/connect";
|
|
140
|
+
*
|
|
141
|
+
* const handleError = (error: unknown) =>
|
|
142
|
+
* Effect.fail(GrpcException.from(Code.Internal, error));
|
|
143
|
+
*
|
|
144
|
+
* // From ConnectError - preserves code and message
|
|
145
|
+
* const connectErr = new ConnectError("Not found", Code.NotFound);
|
|
146
|
+
* const grpcErr1 = GrpcException.from(Code.Internal, connectErr);
|
|
147
|
+
* // grpcErr1.code === Code.NotFound (from ConnectError, not the parameter)
|
|
148
|
+
* // grpcErr1.message === "Not found"
|
|
149
|
+
*
|
|
150
|
+
* // From regular Error - sets as cause
|
|
151
|
+
* const regularErr = new Error("Network timeout");
|
|
152
|
+
* const grpcErr2 = GrpcException.from(Code.Unavailable, regularErr);
|
|
153
|
+
* // grpcErr2.code === Code.Unavailable
|
|
154
|
+
* // grpcErr2.message === "Network timeout"
|
|
155
|
+
* // grpcErr2.cause === regularErr
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export const from = internal.from;
|
|
159
|
+
/**
|
|
160
|
+
* Sets or replaces the description field of a GrpcException.
|
|
161
|
+
* Returns a new GrpcException with the specified description.
|
|
162
|
+
*
|
|
163
|
+
* @param error - The GrpcException to modify
|
|
164
|
+
* @param description - The description to set
|
|
165
|
+
* @returns A new GrpcException with the description
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
170
|
+
* import { Code } from "@connectrpc/connect";
|
|
171
|
+
*
|
|
172
|
+
* const error = GrpcException.create(
|
|
173
|
+
* Code.NotFound,
|
|
174
|
+
* "User not found"
|
|
175
|
+
* );
|
|
176
|
+
* const enriched = GrpcException.withDescription(
|
|
177
|
+
* error,
|
|
178
|
+
* "Database query failed"
|
|
179
|
+
* );
|
|
180
|
+
* // enriched.description === "Database query failed"
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export const withDescription = internal.withDescription;
|
|
184
|
+
/**
|
|
185
|
+
* Converts a GrpcException to a ConnectError for use with Connect-RPC.
|
|
186
|
+
* This is useful when you need to throw or return errors in Connect-RPC handlers.
|
|
187
|
+
*
|
|
188
|
+
* Only the code, message, and cause are preserved. Description is not included
|
|
189
|
+
* as ConnectError doesn't have a corresponding field.
|
|
190
|
+
*
|
|
191
|
+
* @param error - The GrpcException to convert
|
|
192
|
+
* @returns A ConnectError instance
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* import { GrpcException } from "@dr_nikson/effect-grpc";
|
|
197
|
+
* import { Code } from "@connectrpc/connect";
|
|
198
|
+
*
|
|
199
|
+
* const error = GrpcException.create(
|
|
200
|
+
* Code.NotFound,
|
|
201
|
+
* "User not found"
|
|
202
|
+
* );
|
|
203
|
+
* const withDesc = GrpcException.withDescription(
|
|
204
|
+
* error,
|
|
205
|
+
* "Database query failed"
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* const connectError = GrpcException.toConnectError(withDesc);
|
|
209
|
+
* // connectError.code === Code.NotFound
|
|
210
|
+
* // connectError.rawMessage === "User not found"
|
|
211
|
+
* // Note: description is lost in conversion
|
|
212
|
+
*
|
|
213
|
+
* // Can be thrown in Connect-RPC handlers
|
|
214
|
+
* throw GrpcException.toConnectError(error);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export const toConnectError = internal.toConnectError;
|
|
218
|
+
//# sourceMappingURL=grpcException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpcException.js","sourceRoot":"","sources":["../src/grpcException.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI9B,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,aAAc,SAAQ,IAAI,CAAC,WAAW,CACjD,oDAAoD,CA2BpD;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,QAAQ;QACN,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QACxC,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,MAAM,GAEf,QAAQ,CAAC,MAAM,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,IAAI,GAEb,QAAQ,CAAC,IAAI,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,eAAe,GAExB,QAAQ,CAAC,eAAe,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,cAAc,GAEvB,QAAQ,CAAC,cAAc,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,gBAAgB,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC"}
|
package/dist/protoRuntime.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Effect, Runtime } from "effect";
|
|
2
2
|
import type { DescMessage, MessageInitShape, MessageShape } from "@bufbuild/protobuf";
|
|
3
3
|
import type { GenMessage, GenServiceMethods } from "@bufbuild/protobuf/codegenv2";
|
|
4
|
-
import { HandlerContext } from "@connectrpc/connect";
|
|
5
|
-
import
|
|
4
|
+
import type { HandlerContext } from "@connectrpc/connect";
|
|
5
|
+
import * as GrpcException from "./grpcException.js";
|
|
6
|
+
import type { RequestMeta } from "./client.js";
|
|
6
7
|
/**
|
|
7
8
|
* Type-safe executor interface for gRPC service methods.
|
|
8
9
|
*
|
|
@@ -69,17 +70,17 @@ type UnaryClientExecutorFn<I extends DescMessage, O extends DescMessage> = (requ
|
|
|
69
70
|
* ```
|
|
70
71
|
*/
|
|
71
72
|
export interface ServerExecutor<Ctx> {
|
|
72
|
-
unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx: Ctx) => Effect.Effect<Out>): Promise<Out>;
|
|
73
|
+
unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx: Ctx) => Effect.Effect<Out, GrpcException.GrpcException>): Promise<Out>;
|
|
73
74
|
}
|
|
74
75
|
export declare const ServerExecutor: {
|
|
75
|
-
(runtime: Runtime.Runtime<never>): ServerExecutor<
|
|
76
|
+
(runtime: Runtime.Runtime<never>): ServerExecutor<any>;
|
|
76
77
|
};
|
|
77
78
|
export interface ServerExecutorTransformer<Ctx> {
|
|
78
79
|
readonly transformation: (underlying: ServerExecutor<HandlerContext>) => ServerExecutor<Ctx>;
|
|
79
|
-
transformContext<Ctx1>(f: (
|
|
80
|
+
transformContext<Ctx1>(f: (handlerCtx: HandlerContext) => Effect.Effect<Ctx1, GrpcException.GrpcException>): ServerExecutorTransformer<Ctx1>;
|
|
80
81
|
}
|
|
81
82
|
export declare const ServerExecutorTransformer: {
|
|
82
|
-
(): ServerExecutorTransformer<
|
|
83
|
+
(): ServerExecutorTransformer<any>;
|
|
83
84
|
};
|
|
84
85
|
export {};
|
|
85
86
|
//# sourceMappingURL=protoRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protoRuntime.d.ts","sourceRoot":"","sources":["../src/protoRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"protoRuntime.d.ts","sourceRoot":"","sources":["../src/protoRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,cAAc,CAAC,YAAY,SAAS,iBAAiB,IAAI;KAClE,CAAC,IAAI,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,S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AAa,CAAC,aAAa,CAAC,GAClF,yBAAyB,CAAC,IAAI,CAAC,CAAC;CACpC;AACD,eAAO,MAAM,yBAAyB,EAAE;IACtC,IAAI,yBAAyB,CAAC,GAAG,CAAC,CAAC;CACW,CAAC"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Effect, Runtime } from "effect";
|
|
2
|
-
import { HandlerContext } from "@connectrpc/connect";
|
|
2
|
+
import type { HandlerContext } from "@connectrpc/connect";
|
|
3
|
+
import * as GrpcException from "./grpcException.js";
|
|
3
4
|
import type * as T from "./protoRuntime.js";
|
|
4
5
|
/**
|
|
5
6
|
* @internal
|
|
6
7
|
* Live implementation of the Executor interface using Effect's ManagedRuntime.
|
|
7
8
|
* Handles the execution of Effect programs within gRPC service handlers.
|
|
8
9
|
*/
|
|
9
|
-
export declare class ServerExecutorLive implements T.ServerExecutor<
|
|
10
|
+
export declare class ServerExecutorLive implements T.ServerExecutor<any> {
|
|
10
11
|
readonly runtime: Runtime.Runtime<never>;
|
|
11
12
|
constructor(runtime: Runtime.Runtime<never>);
|
|
12
|
-
static make(runtime: Runtime.Runtime<never>): T.ServerExecutor<
|
|
13
|
-
unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx:
|
|
13
|
+
static make(runtime: Runtime.Runtime<never>): T.ServerExecutor<any>;
|
|
14
|
+
unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx: any) => Effect.Effect<Out, GrpcException.GrpcException>): Promise<Out>;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* @internal
|
|
@@ -20,7 +21,7 @@ export declare class ServerExecutorLive implements T.ServerExecutor<HandlerConte
|
|
|
20
21
|
export declare class ServerExecutorTransformerLive<Ctx> implements T.ServerExecutorTransformer<Ctx> {
|
|
21
22
|
readonly transformation: (underlying: T.ServerExecutor<HandlerContext>) => T.ServerExecutor<Ctx>;
|
|
22
23
|
constructor(transformation: (underlying: T.ServerExecutor<HandlerContext>) => T.ServerExecutor<Ctx>);
|
|
23
|
-
static empty(): ServerExecutorTransformerLive<
|
|
24
|
-
transformContext<Ctx1>(f: (
|
|
24
|
+
static empty(): ServerExecutorTransformerLive<any>;
|
|
25
|
+
transformContext<Ctx1>(f: (handlerCtx: HandlerContext) => Effect.Effect<Ctx1, GrpcException.GrpcException>): ServerExecutorTransformerLive<Ctx1>;
|
|
25
26
|
}
|
|
26
27
|
//# sourceMappingURL=protoRuntime.internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protoRuntime.internal.d.ts","sourceRoot":"","sources":["../src/protoRuntime.internal.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"protoRuntime.internal.d.ts","sourceRoot":"","sources":["../src/protoRuntime.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAQ,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,KAAK,CAAC,MAAM,mBAAmB,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;aAClC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;gBAA/B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;IAE3D,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;IAInE,KAAK,CAAC,EAAE,EAAE,GAAG,EACX,GAAG,EAAE,EAAE,EACP,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,aAAa,CAAC,GAC3E,OAAO,CAAC,GAAG,CAAC;CA2BhB;AAED;;;;GAIG;AACH,qBAAa,6BAA6B,CAAC,GAAG,CAAE,YAAW,CAAC,CAAC,yBAAyB,CAAC,GAAG,CAAC;aAEvE,cAAc,EAAE,CAC9B,UAAU,EAAE,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,KACzC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;gBAFV,cAAc,EAAE,CAC9B,UAAU,EAAE,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,KACzC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC;IAG5B,MAAM,CAAC,KAAK,IAAI,6BAA6B,CAAC,GAAG,CAAC;IAIlD,gBAAgB,CAAC,IAAI,EACnB,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,GAClF,6BAA6B,CAAC,IAAI,CAAC;CAevC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Effect, Runtime } from "effect";
|
|
1
|
+
import { Cause, Effect, Exit, Runtime } from "effect";
|
|
2
|
+
import { Code, ConnectError } from "@connectrpc/connect";
|
|
3
|
+
import * as GrpcException from "./grpcException.js";
|
|
2
4
|
/**
|
|
3
5
|
* @internal
|
|
4
6
|
* Live implementation of the Executor interface using Effect's ManagedRuntime.
|
|
@@ -13,7 +15,20 @@ export class ServerExecutorLive {
|
|
|
13
15
|
return new ServerExecutorLive(runtime);
|
|
14
16
|
}
|
|
15
17
|
unary(req, ctx, prog) {
|
|
16
|
-
|
|
18
|
+
// Pass undefined as the context since the default is 'any' and no transformation has been applied
|
|
19
|
+
return Runtime.runPromiseExit(this.runtime, prog(req, undefined), { signal: ctx.signal }).then(Exit.match({
|
|
20
|
+
onFailure: (cause) => {
|
|
21
|
+
throw Cause.match(cause, {
|
|
22
|
+
onEmpty: new ConnectError("Unknown error", Code.Unknown),
|
|
23
|
+
onFail: (error) => GrpcException.toConnectError(error),
|
|
24
|
+
onDie: (defect) => new ConnectError("Internal server error", Code.Internal, undefined, undefined, defect),
|
|
25
|
+
onInterrupt: () => new ConnectError("Request was canceled", Code.Aborted),
|
|
26
|
+
onSequential: (left, right) => new ConnectError(`${left.rawMessage}; ${right.rawMessage}`, Code.Internal),
|
|
27
|
+
onParallel: (left, right) => new ConnectError(`${left.rawMessage} | ${right.rawMessage}`, Code.Internal),
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
onSuccess: (value) => value,
|
|
31
|
+
}));
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
/**
|
|
@@ -31,11 +46,10 @@ export class ServerExecutorTransformerLive {
|
|
|
31
46
|
}
|
|
32
47
|
transformContext(f) {
|
|
33
48
|
return new ServerExecutorTransformerLive((underlying) => {
|
|
34
|
-
const executor = this.transformation(underlying);
|
|
35
49
|
return {
|
|
36
|
-
unary(req,
|
|
37
|
-
return
|
|
38
|
-
return Effect.flatMap(f(
|
|
50
|
+
unary(req, handlerCtx, prog) {
|
|
51
|
+
return underlying.unary(req, handlerCtx, (req) => {
|
|
52
|
+
return Effect.flatMap(f(handlerCtx), (ctx1) => prog(req, ctx1));
|
|
39
53
|
});
|
|
40
54
|
},
|
|
41
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protoRuntime.internal.js","sourceRoot":"","sources":["../src/protoRuntime.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"protoRuntime.internal.js","sourceRoot":"","sources":["../src/protoRuntime.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,KAAK,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AI,CAAC,UAAU,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC;iBAC9E,CAAC,CAAC;YACL,CAAC;YACD,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;SAC5B,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,6BAA6B;IAEtB;IADlB,YACkB,cAEU;QAFV,mBAAc,GAAd,cAAc,CAEJ;IACzB,CAAC;IAEJ,MAAM,CAAC,KAAK;QACV,OAAO,IAAI,6BAA6B,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;IACvE,CAAC;IAED,gBAAgB,CACd,CAAmF;QAEnF,OAAO,IAAI,6BAA6B,CAAO,CAAC,UAAU,EAAE,EAAE;YAC5D,OAAO;gBACL,KAAK,CACH,GAAO,EACP,UAA0B,EAC1B,IAA6E;oBAE7E,OAAO,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;wBAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;oBAClE,CAAC,CAAC,CAAC;gBACL,CAAC;aACwB,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/protoRuntime.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Effect, Runtime } from "effect";
|
|
2
|
+
import * as GrpcException from "./grpcException.js";
|
|
1
3
|
import * as internal from "./protoRuntime.internal.js";
|
|
2
4
|
export const ServerExecutor = internal.ServerExecutorLive.make;
|
|
3
5
|
export const ServerExecutorTransformer = internal.ServerExecutorTransformerLive.empty;
|
package/dist/protoRuntime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protoRuntime.js","sourceRoot":"","sources":["../src/protoRuntime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protoRuntime.js","sourceRoot":"","sources":["../src/protoRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAMzC,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAgFvD,MAAM,CAAC,MAAM,cAAc,GAEvB,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC;AASrC,MAAM,CAAC,MAAM,yBAAyB,GAElC,QAAQ,CAAC,6BAA6B,CAAC,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocGenPlugin.d.ts","sourceRoot":"","sources":["../src/protocGenPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"protocGenPlugin.d.ts","sourceRoot":"","sources":["../src/protocGenPlugin.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,wCAI9B,CAAC"}
|