@dr_nikson/effect-grpc 0.2.0-mvp-35390ba5835ef85042f042d86878a7e9aee0dad9 → 3.0.0-alpha.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.
Files changed (42) hide show
  1. package/README.md +928 -0
  2. package/dist/client.d.ts +38 -3
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.internal.d.ts.map +1 -1
  5. package/dist/client.internal.js +36 -9
  6. package/dist/client.internal.js.map +1 -1
  7. package/dist/client.js +2 -0
  8. package/dist/client.js.map +1 -1
  9. package/dist/grpcException.d.ts +243 -0
  10. package/dist/grpcException.d.ts.map +1 -0
  11. package/dist/grpcException.internal.d.ts +28 -0
  12. package/dist/grpcException.internal.d.ts.map +1 -0
  13. package/dist/grpcException.internal.js +72 -0
  14. package/dist/grpcException.internal.js.map +1 -0
  15. package/dist/grpcException.js +218 -0
  16. package/dist/grpcException.js.map +1 -0
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/protoRuntime.d.ts +7 -6
  22. package/dist/protoRuntime.d.ts.map +1 -1
  23. package/dist/protoRuntime.internal.d.ts +8 -7
  24. package/dist/protoRuntime.internal.d.ts.map +1 -1
  25. package/dist/protoRuntime.internal.js +16 -2
  26. package/dist/protoRuntime.internal.js.map +1 -1
  27. package/dist/protoRuntime.js +2 -0
  28. package/dist/protoRuntime.js.map +1 -1
  29. package/dist/protocGenPlugin.d.ts.map +1 -1
  30. package/dist/protocGenPlugin.js +6 -5
  31. package/dist/protocGenPlugin.js.map +1 -1
  32. package/dist/server.d.ts +8 -4
  33. package/dist/server.d.ts.map +1 -1
  34. package/dist/server.internal.d.ts +5 -4
  35. package/dist/server.internal.d.ts.map +1 -1
  36. package/dist/server.internal.js +50 -13
  37. package/dist/server.internal.js.map +1 -1
  38. package/dist/server.js +4 -0
  39. package/dist/server.js.map +1 -1
  40. package/dist/typeUtils.js +1 -1
  41. package/dist/typeUtils.js.map +1 -1
  42. package/package.json +1 -1
package/dist/client.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { Context, Effect, Layer, Types } from "effect";
1
+ import type * as http2 from "node:http2";
2
+ import { Context, Effect, Layer, Scope, Types } from "effect";
2
3
  import type { BinaryReadOptions, BinaryWriteOptions } from "@bufbuild/protobuf";
3
4
  import type { GenService, GenServiceMethods } from "@bufbuild/protobuf/codegenv2";
4
5
  import { type ContextValues } from "@connectrpc/connect";
6
+ import type { Http2SessionOptions } from "@connectrpc/connect-node";
5
7
  import type { Compression } from "@connectrpc/connect/protocol";
6
8
  import * as internal from "./client.internal.js";
7
9
  import type * as ProtoRuntime from "./protoRuntime.js";
@@ -34,7 +36,7 @@ export type GrpcClientRuntimeTypeId = typeof internal.grpcClientRuntimeTypeId;
34
36
  */
35
37
  export interface GrpcClientRuntime {
36
38
  readonly Type: GrpcClientRuntimeTypeId;
37
- makeExecutor<Shape extends GenServiceMethods>(serviceDefinition: GenService<Shape>, methodNames: ReadonlyArray<keyof GenService<Shape>["method"]>, config: GrpcClientConfig<any>): Effect.Effect<ProtoRuntime.ClientExecutor<Shape>>;
39
+ makeExecutor<Shape extends GenServiceMethods>(serviceDefinition: GenService<Shape>, methodNames: ReadonlyArray<keyof GenService<Shape>["method"]>, config: GrpcClientConfig<any>): Effect.Effect<ProtoRuntime.ClientExecutor<Shape>, never, Scope.Scope>;
38
40
  }
39
41
  /**
40
42
  * Context tag for accessing the GrpcClient service.
@@ -101,7 +103,7 @@ export interface GrpcClientConfig<in Service extends string> {
101
103
  * This will make a `POST /my-api/my_package.MyService/Foo` to
102
104
  * `example.com`
103
105
  */
104
- readonly baseUrl: string;
106
+ readonly baseUrl: URL;
105
107
  /**
106
108
  * Options for the binary wire format.
107
109
  */
@@ -142,6 +144,39 @@ export interface GrpcClientConfig<in Service extends string> {
142
144
  * This can be overridden on a per-request basis by passing a timeoutMs.
143
145
  */
144
146
  readonly defaultTimeoutMs?: number;
147
+ /**
148
+ * Options for HTTP/2 session keepalive behavior.
149
+ *
150
+ * Configure PING frame intervals and timeouts to maintain long-lived
151
+ * HTTP/2 connections. This is important for detecting dead connections
152
+ * and preventing resource exhaustion.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const config = GrpcClientConfig({
157
+ * baseUrl: new URL("http://localhost:8080"),
158
+ * pingOptions: {
159
+ * pingIntervalMs: 30000, // Send PING every 30 seconds
160
+ * pingTimeoutMs: 15000, // Timeout after 15 seconds
161
+ * pingIdleConnection: true,
162
+ * idleConnectionTimeoutMs: 900000, // Close idle connections after 15 minutes
163
+ * }
164
+ * });
165
+ * ```
166
+ *
167
+ * @see [Http2SessionOptions]{@link https://connectrpc.com/docs/node/using-clients}
168
+ */
169
+ readonly pingOptions?: Http2SessionOptions;
170
+ /**
171
+ * Advanced options for the underlying Node.js HTTP/2 client session.
172
+ *
173
+ * These options are passed directly to Node.js's `http2.connect()`.
174
+ * Use this to configure TLS settings, ALPN protocols, and other
175
+ * low-level HTTP/2 behavior.
176
+ *
177
+ * @see [Node.js HTTP/2 ClientSessionOptions]{@link https://nodejs.org/api/http2.html#http2connectauthority-options-listener}
178
+ */
179
+ readonly http2SessionOptions?: http2.ClientSessionOptions | http2.SecureClientSessionOptions;
145
180
  }
146
181
  export declare const GrpcClientConfig: {
147
182
  <Service extends string>(opts: Omit<GrpcClientConfig<Service>, "_Service">): GrpcClientConfig<Service>;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAA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A,OAAO,EAAE,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAahD,OAAO,KAAK,KAAK,CAAC,MAAM,aAAa,CAAC;AAGtC,eAAO,MAAM,uBAAuB,eAAqD,CAAC;AAE1F,eAAO,MAAM,oBAAoB,uDAEhC,CAAC;AAGF,wBAAgB,qBAAqB,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CA8BxE;AAoCD,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,yEAI/E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,MAAM,EACzD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,GAK9C,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CACjC"}
1
+ {"version":3,"file":"client.internal.d.ts","sourceRoot":"","sources":["../src/client.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAQhD,OAAO,KAAK,KAAK,CAAC,MAAM,aAAa,CAAC;AAGtC,eAAO,MAAM,uBAAuB,eAAqD,CAAC;AAE1F,eAAO,MAAM,oBAAoB,uDAEhC,CAAC;AAsBF,wBAAgB,qBAAqB,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAkDxE;AAoCD,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,MAAM,EAAE,OAAO,EAAE,OAAO,yEAI/E;AAED,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,MAAM,EACzD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,GAK9C,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CACjC"}
@@ -1,23 +1,50 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
- import { createClient, createContextValues, } from "@connectrpc/connect";
3
- import { createGrpcTransport } from "@connectrpc/connect-node";
2
+ import { createClient, createContextValues } from "@connectrpc/connect";
3
+ import { Http2SessionManager, createGrpcTransport } from "@connectrpc/connect-node";
4
+ import * as protoRuntime from "./protoRuntime.js";
4
5
  export const grpcClientRuntimeTypeId = Symbol("@dr_nikson/effect-grpc/GrpcClientRuntime");
5
6
  export const grpcClientRuntimeTag = Context.GenericTag(grpcClientRuntimeTypeId.toString());
6
- // TODO: this abstraction is kinda useless, right? We can make more in use .. can we?
7
+ /**
8
+ * @internal
9
+ * Creates a managed HTTP/2 session manager as an Effect resource.
10
+ * The session manager is automatically aborted when the scope closes.
11
+ * This is important because otherwise we might stuck waiting for the connections to timeout
12
+ */
13
+ function createManagedSessionManager(config) {
14
+ return Effect.acquireRelease(Effect.sync(() => new Http2SessionManager(config.baseUrl, config.pingOptions, config.http2SessionOptions)), (sessionManager) => Effect.gen(function* () {
15
+ yield* Effect.logInfo("ManagedSessionManager is being released...");
16
+ return yield* Effect.sync(() => sessionManager.abort());
17
+ }));
18
+ }
7
19
  export function liveGrpcClientRuntime() {
8
20
  const instance = {
9
21
  Type: grpcClientRuntimeTypeId,
10
- makeExecutor(serviceDefinition, methodNames) {
22
+ makeExecutor(serviceDefinition, methodNames, config) {
11
23
  return Effect.gen(function* () {
12
- const transport = yield* Effect.sync(() => createGrpcTransport({
13
- baseUrl: "http://localhost:8000",
14
- }));
24
+ // Create managed HTTP/2 session manager as a resource
25
+ // This will be released when the scope closes
26
+ const sessionManager = yield* createManagedSessionManager(config);
27
+ // Build transport options
28
+ const transportOptions = {
29
+ httpVersion: "2",
30
+ baseUrl: config.baseUrl.toString(),
31
+ sessionManager,
32
+ ...(config.binaryOptions && { binaryOptions: config.binaryOptions }),
33
+ ...(config.acceptCompression && { acceptCompression: config.acceptCompression }),
34
+ ...(config.sendCompression && { sendCompression: config.sendCompression }),
35
+ ...(config.compressMinBytes && { compressMinBytes: config.compressMinBytes }),
36
+ ...(config.defaultTimeoutMs && { defaultTimeoutMs: config.defaultTimeoutMs }),
37
+ };
38
+ // Create transport with the managed session manager
39
+ const transport = yield* Effect.sync(() => createGrpcTransport(transportOptions));
40
+ // Create the client
15
41
  const client = createClient(serviceDefinition, transport);
16
- const instance = methodNames.reduce((acc, methodName) => {
42
+ // Build executor methods
43
+ const executor = methodNames.reduce((acc, methodName) => {
17
44
  const method = makeExecutorMethod(client, methodName, serviceDefinition);
18
45
  return method === null ? acc : { ...acc, [methodName]: method };
19
46
  }, {});
20
- return instance;
47
+ return executor;
21
48
  });
22
49
  },
23
50
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.internal.js","sourceRoot":"","sources":["../src/client.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAIhD,OAAO,EAIL,YAAY,EACZ,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,0CAA0C,CAAC,CAAC;AAE1F,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,UAAU,CACpD,uBAAuB,CAAC,QAAQ,EAAE,CACnC,CAAC;AAEF,qFAAqF;AACrF,MAAM,UAAU,qBAAqB;IACnC,MAAM,QAAQ,GAAwB;QACpC,IAAI,EAAE,uBAAuB;QAE7B,YAAY,CACV,iBAAoC,EACpC,WAA6D;YAE7D,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;gBACzB,MAAM,SAAS,GAAc,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CACnD,mBAAmB,CAAC;oBAClB,OAAO,EAAE,uBAAuB;iBACjC,CAAC,CACH,CAAC;gBACF,MAAM,MAAM,GAA8B,YAAY,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;gBACrF,M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AAG,CACtD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,IAAmD;IAEnD,OAAO;QACL,GAAG,IAAI;QACP,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC;KACQ,CAAC;AACnC,CAAC"}
package/dist/client.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { Context, Effect, Layer, Scope, Types } from "effect";
2
+ import {} from "@connectrpc/connect";
1
3
  import * as internal from "./client.internal.js";
2
4
  /**
3
5
  * Context tag for accessing the GrpcClient service.
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAwCjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,QAAQ,CAAC,oBAAoB,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAEnC,QAAQ,CAAC,qBAAqB,CAAC;AAmEnC,MAAM,CAAC,MAAM,gBAAgB,GAQzB,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;IAC1D,OAAO,EAAE,QAAQ,CAAC,uBAAuB;CAC1C,CAAC,CAAC"}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI9D,OAAO,EAAsB,MAAM,qBAAqB,CAAC;AAIzD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAwCjD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,QAAQ,CAAC,oBAAoB,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAEnC,QAAQ,CAAC,qBAAqB,CAAC;AAsGnC,MAAM,CAAC,MAAM,gBAAgB,GAQzB,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;IAC1D,OAAO,EAAE,QAAQ,CAAC,uBAAuB;CAC1C,CAAC,CAAC"}
@@ -0,0 +1,243 @@
1
+ import type { Code, ConnectError } from "@connectrpc/connect";
2
+ declare const GrpcException_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
3
+ readonly _tag: "@dr_nikson/effect-grpc/grpcException/GrpcException";
4
+ } & Readonly<A>;
5
+ /**
6
+ * A high-level error type for gRPC operations in Effect programs.
7
+ *
8
+ * GrpcException is a tagged error that extends Data.TaggedError, designed as part of the DSL
9
+ * for gRPC error handling. It focuses on application-level concerns (code, message, description, cause)
10
+ * rather than low-level wire-format details.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { Effect } from "effect";
15
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
16
+ * import { Code } from "@connectrpc/connect";
17
+ *
18
+ * // Create an exception with a code and message
19
+ * const notFoundError = GrpcException.create(
20
+ * Code.NotFound,
21
+ * "User not found"
22
+ * );
23
+ *
24
+ * // Use in Effect programs with catchTag
25
+ * const program = Effect.gen(function* () {
26
+ * yield* notFoundError; // The error is yieldable
27
+ * yield* Effect.fail(notFoundError);
28
+ * }).pipe(
29
+ * Effect.catchTag(GrpcException, (error) => {
30
+ * console.log(`gRPC error [${Code[error.code]}]: ${error.message}`);
31
+ * return Effect.succeed("recovered");
32
+ * })
33
+ * );
34
+ *
35
+ * // Convert from unknown error
36
+ * try {
37
+ * // some operation
38
+ * } catch (error) {
39
+ * yield* GrpcException.from(Code.Internal, error);
40
+ * }
41
+ *
42
+ * // Add context with description
43
+ * const enriched = GrpcException.withDescription(
44
+ * notFoundError,
45
+ * "Database query failed"
46
+ * );
47
+ * ```
48
+ *
49
+ * @category Error Handling
50
+ * @since 0.2.0
51
+ */
52
+ export declare class GrpcException extends GrpcException_base<{
53
+ /**
54
+ * The gRPC status code for this error.
55
+ */
56
+ readonly code: Code;
57
+ /**
58
+ * The error message describing what went wrong.
59
+ */
60
+ readonly message: string;
61
+ /**
62
+ * Optional description providing additional context about the error.
63
+ * This can be used to add higher-level context without modifying the original message.
64
+ *
65
+ * Unlike the message field, description can be easily modified as errors bubble up
66
+ * through the call stack using withDescription.
67
+ */
68
+ readonly description?: string;
69
+ /**
70
+ * Optional cause of this error.
71
+ * Used to chain errors and preserve the original error that caused this exception.
72
+ * Can be a native Error, Effect tagged error.
73
+ */
74
+ readonly cause?: unknown;
75
+ }> {
76
+ /**
77
+ * Returns a formatted error message including the status code, message, and description (if present).
78
+ * This is called automatically when the error is converted to a string.
79
+ *
80
+ * Format:
81
+ * - Without description: "[code] message"
82
+ * - With description: "[code] message (description)"
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
87
+ * import { Code } from "@connectrpc/connect";
88
+ *
89
+ * const error1 = GrpcException.create(
90
+ * Code.NotFound,
91
+ * "User not found"
92
+ * );
93
+ * console.log(error1.toString());
94
+ * // Output: "[not_found] User not found"
95
+ *
96
+ * const error2 = GrpcException.withDescription(
97
+ * error1,
98
+ * "Database query failed"
99
+ * );
100
+ * console.log(error2.toString());
101
+ * // Output: "[not_found] User not found (Database query failed)"
102
+ * ```
103
+ */
104
+ toString(): string;
105
+ }
106
+ /**
107
+ * Creates a new GrpcException from the provided parameters.
108
+ *
109
+ * This is the primary constructor for creating GrpcException instances.
110
+ * Code and message are required; cause is optional.
111
+ *
112
+ * @param code - The gRPC status code (required)
113
+ * @param message - The error message (required)
114
+ * @param cause - Optional cause of the error
115
+ * @returns A new GrpcException instance
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
120
+ * import { Code } from "@connectrpc/connect";
121
+ *
122
+ * // Simple error
123
+ * const error1 = GrpcException.create(
124
+ * Code.NotFound,
125
+ * "User not found"
126
+ * );
127
+ *
128
+ * // With cause
129
+ * try {
130
+ * // some operation
131
+ * } catch (err) {
132
+ * const error2 = GrpcException.create(
133
+ * Code.Internal,
134
+ * "Operation failed",
135
+ * err
136
+ * );
137
+ * }
138
+ * ```
139
+ */
140
+ export declare const create: {
141
+ (code: Code, message: string, cause?: unknown): GrpcException;
142
+ };
143
+ /**
144
+ * Converts any value into a GrpcException, following these rules:
145
+ * - If the cause is a ConnectError, wraps it preserving code and message
146
+ * - For other Errors, creates a GrpcException with the error message and sets it as cause
147
+ * - For other values, converts to string and uses as message
148
+ *
149
+ * @param code - The gRPC status code to use (required)
150
+ * @param cause - The error/value to convert (native Error, ConnectError, or any value)
151
+ * @returns A GrpcException instance
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { Effect } from "effect";
156
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
157
+ * import { Code, ConnectError } from "@connectrpc/connect";
158
+ *
159
+ * const handleError = (error: unknown) =>
160
+ * Effect.fail(GrpcException.from(Code.Internal, error));
161
+ *
162
+ * // From ConnectError - preserves code and message
163
+ * const connectErr = new ConnectError("Not found", Code.NotFound);
164
+ * const grpcErr1 = GrpcException.from(Code.Internal, connectErr);
165
+ * // grpcErr1.code === Code.NotFound (from ConnectError, not the parameter)
166
+ * // grpcErr1.message === "Not found"
167
+ *
168
+ * // From regular Error - sets as cause
169
+ * const regularErr = new Error("Network timeout");
170
+ * const grpcErr2 = GrpcException.from(Code.Unavailable, regularErr);
171
+ * // grpcErr2.code === Code.Unavailable
172
+ * // grpcErr2.message === "Network timeout"
173
+ * // grpcErr2.cause === regularErr
174
+ * ```
175
+ */
176
+ export declare const from: {
177
+ (code: Code, cause: unknown): GrpcException;
178
+ };
179
+ /**
180
+ * Sets or replaces the description field of a GrpcException.
181
+ * Returns a new GrpcException with the specified description.
182
+ *
183
+ * @param error - The GrpcException to modify
184
+ * @param description - The description to set
185
+ * @returns A new GrpcException with the description
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
190
+ * import { Code } from "@connectrpc/connect";
191
+ *
192
+ * const error = GrpcException.create(
193
+ * Code.NotFound,
194
+ * "User not found"
195
+ * );
196
+ * const enriched = GrpcException.withDescription(
197
+ * error,
198
+ * "Database query failed"
199
+ * );
200
+ * // enriched.description === "Database query failed"
201
+ * ```
202
+ */
203
+ export declare const withDescription: {
204
+ (error: GrpcException, description: string): GrpcException;
205
+ };
206
+ /**
207
+ * Converts a GrpcException to a ConnectError for use with Connect-RPC.
208
+ * This is useful when you need to throw or return errors in Connect-RPC handlers.
209
+ *
210
+ * Only the code, message, and cause are preserved. Description is not included
211
+ * as ConnectError doesn't have a corresponding field.
212
+ *
213
+ * @param error - The GrpcException to convert
214
+ * @returns A ConnectError instance
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * import { GrpcException } from "@dr_nikson/effect-grpc";
219
+ * import { Code } from "@connectrpc/connect";
220
+ *
221
+ * const error = GrpcException.create(
222
+ * Code.NotFound,
223
+ * "User not found"
224
+ * );
225
+ * const withDesc = GrpcException.withDescription(
226
+ * error,
227
+ * "Database query failed"
228
+ * );
229
+ *
230
+ * const connectError = GrpcException.toConnectError(withDesc);
231
+ * // connectError.code === Code.NotFound
232
+ * // connectError.rawMessage === "User not found"
233
+ * // Note: description is lost in conversion
234
+ *
235
+ * // Can be thrown in Connect-RPC handlers
236
+ * throw GrpcException.toConnectError(error);
237
+ * ```
238
+ */
239
+ export declare const toConnectError: {
240
+ (error: GrpcException): ConnectError;
241
+ };
242
+ export {};
243
+ //# sourceMappingURL=grpcException.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpcException.d.ts","sourceRoot":"","sources":["../src/grpcException.ts"],"names":[],"m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"@connectrpc/connect";
3
+ import { GrpcException } from "./grpcException.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare const create: (code: Code, message: string, cause?: unknown) => GrpcException;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare const from: (code: Code, cause: unknown) => GrpcException;
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare const withDescription: (error: GrpcException, description: string) => GrpcException;
16
+ /**
17
+ * @internal
18
+ */
19
+ export declare const toConnectError: (error: GrpcException) => ConnectError;
20
+ /**
21
+ * @internal
22
+ */
23
+ export declare const toString: (error: GrpcException) => string;
24
+ /**
25
+ * @internal
26
+ */
27
+ export declare const inspect: (error: GrpcException) => string;
28
+ //# sourceMappingURL=grpcException.internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpcException.internal.d.ts","sourceRoot":"","sources":["../src/grpcException.internal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,IAAI,EAAE,SAAS,MAAM,EAAE,QAAQ,OAAO,KAAG,aAErE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,IAAI,GAAI,MAAM,IAAI,EAAE,OAAO,OAAO,KAAG,aA2BjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,aAAa,EAAE,aAAa,MAAM,KAAG,aAO3E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,aAAa,KAAG,YAErD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,aAAa,KAAG,MAO/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,aAAa,KAAG,MAE9C,CAAC"}
@@ -0,0 +1,72 @@
1
+ // packages/effect-grpc/src/grpcException.internal.ts
2
+ import { ConnectError } from "@connectrpc/connect";
3
+ import { GrpcException } from "./grpcException.js";
4
+ /**
5
+ * @internal
6
+ */
7
+ export const create = (code, message, cause) => {
8
+ return new GrpcException({ code, message, cause });
9
+ };
10
+ /**
11
+ * @internal
12
+ */
13
+ export const from = (code, cause) => {
14
+ // Handle ConnectError - preserve code and message
15
+ if (cause instanceof ConnectError) {
16
+ return new GrpcException({
17
+ code: cause.code,
18
+ message: cause.rawMessage,
19
+ cause,
20
+ });
21
+ }
22
+ // Handle regular Error - use error message and set as cause
23
+ if (cause instanceof Error) {
24
+ return new GrpcException({
25
+ code,
26
+ message: cause.message,
27
+ cause,
28
+ });
29
+ }
30
+ // For other values, convert to string and use as message
31
+ const message = String(cause);
32
+ return new GrpcException({
33
+ code,
34
+ message,
35
+ cause,
36
+ });
37
+ };
38
+ /**
39
+ * @internal
40
+ */
41
+ export const withDescription = (error, description) => {
42
+ return new GrpcException({
43
+ code: error.code,
44
+ message: error.message,
45
+ description,
46
+ cause: error.cause,
47
+ });
48
+ };
49
+ /**
50
+ * @internal
51
+ */
52
+ export const toConnectError = (error) => {
53
+ return new ConnectError(error.message, error.code, undefined, undefined, error.cause);
54
+ };
55
+ /**
56
+ * @internal
57
+ */
58
+ export const toString = (error) => {
59
+ const codeStr = error.code;
60
+ const parts = [`[${codeStr}]`, error.message];
61
+ if (error.description) {
62
+ parts.push(`(${error.description})`);
63
+ }
64
+ return parts.join(" ");
65
+ };
66
+ /**
67
+ * @internal
68
+ */
69
+ export const inspect = (error) => {
70
+ return toString(error);
71
+ };
72
+ //# sourceMappingURL=grpcException.internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpcException.internal.js","sourceRoot":"","sources":["../src/grpcException.internal.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,aAAa,EAA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