@dr_nikson/effect-grpc 0.2.0-mvp-35390ba5835ef85042f042d86878a7e9aee0dad9

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {runNodeJs} from "@bufbuild/protoplugin";
4
+ import {protocGenEffectGrpc} from "../dist/protocGenPlugin.js";
5
+
6
+ runNodeJs(protocGenEffectGrpc);
@@ -0,0 +1,176 @@
1
+ import { Context, Effect, Layer, Types } from "effect";
2
+ import type { BinaryReadOptions, BinaryWriteOptions } from "@bufbuild/protobuf";
3
+ import type { GenService, GenServiceMethods } from "@bufbuild/protobuf/codegenv2";
4
+ import { type ContextValues } from "@connectrpc/connect";
5
+ import type { Compression } from "@connectrpc/connect/protocol";
6
+ import * as internal from "./client.internal.js";
7
+ import type * as ProtoRuntime from "./protoRuntime.js";
8
+ export type GrpcClientRuntimeTypeId = typeof internal.grpcClientRuntimeTypeId;
9
+ /**
10
+ * Core interface for gRPC client operations in the Effect ecosystem.
11
+ *
12
+ * The GrpcClient provides underlying executor implementation for gRPC service methods,
13
+ * allowing type-safe invocation of remote procedures through Effect. This entity is
14
+ * used in Codegen and Configurations to generate type-safe client code.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // This code is usually generated by protoc-gen-effect
19
+ * // See packages/effect-grpc/src-template/hello_world_api_effect.ts
20
+ * const prog = Effect.gen(function* () {
21
+ * const grpcService = yield* EffectGrpcClient.GrpcClient;
22
+ * const executor = grpcService.makeExecutor(HelloWorldAPI, ["getGreeting"]);
23
+ *
24
+ * return {
25
+ * getGreeting(req, meta) {
26
+ * return executor.getGreeting(req, transformMeta(meta));
27
+ * }
28
+ * };
29
+ * });
30
+ * ```
31
+ *
32
+ * @category Client
33
+ * @since 0.2.0
34
+ */
35
+ export interface GrpcClientRuntime {
36
+ 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>>;
38
+ }
39
+ /**
40
+ * Context tag for accessing the GrpcClient service.
41
+ *
42
+ * Use this tag to access the GrpcClient implementation in your Effect programs.
43
+ * The tag provides dependency injection for the gRPC client functionality.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * import { Effect } from "effect";
48
+ * import { GrpcClient, liveGrpcClientLayer } from "@dr_nikson/effect-grpc";
49
+ *
50
+ * const program = Effect.gen(function* () {
51
+ * const client = yield* GrpcClient;
52
+ * return client;
53
+ * }).pipe(
54
+ * Effect.provide(liveGrpcClientLayer())
55
+ * );
56
+ * ```
57
+ *
58
+ * @category Client
59
+ * @since 0.2.0
60
+ */
61
+ export declare const GrpcClientRuntime: Context.Tag<GrpcClientRuntime, GrpcClientRuntime>;
62
+ /**
63
+ * Creates a live layer implementation for the GrpcClient service.
64
+ *
65
+ * This layer provides the default implementation of the GrpcClient interface,
66
+ * enabling gRPC client functionality in your Effect applications.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { Effect } from "effect";
71
+ * import { GrpcClient, liveGrpcClientLayer } from "@dr_nikson/effect-grpc";
72
+ *
73
+ * const program = Effect.gen(function* () {
74
+ * const client = yield* GrpcClient;
75
+ * return client.makeExecutor(serviceDefinition, ["methodName"]);
76
+ * }).pipe(
77
+ * Effect.provide(liveGrpcClientLayer())
78
+ * );
79
+ * ```
80
+ *
81
+ * @category Client
82
+ * @since 0.2.0
83
+ */
84
+ export declare const liveGrpcClientRuntimeLayer: {
85
+ (): Layer.Layer<GrpcClientRuntime>;
86
+ };
87
+ /**
88
+ * TODO: mention in the example services here is like "com.example.v1.GetGreetingResponse"
89
+ * @see [GrpcTransportOptions]{@link https://github.com/connectrpc/connect-es/blob/78b40abd3ecd2f4fa2dda6382e371be8e9de3f6d/packages/connect-node/src/grpc-transport.ts#L34}
90
+ *
91
+ */
92
+ export interface GrpcClientConfig<in Service extends string> {
93
+ readonly _Service: Types.Contravariant<Service>;
94
+ /**
95
+ * Base URI for all requests.
96
+ *
97
+ * Requests will be made to <baseUrl>/<package>.<service>/method
98
+ *
99
+ * Example: `baseUrl: "https://example.com/my-api"`
100
+ *
101
+ * This will make a `POST /my-api/my_package.MyService/Foo` to
102
+ * `example.com`
103
+ */
104
+ readonly baseUrl: string;
105
+ /**
106
+ * Options for the binary wire format.
107
+ */
108
+ readonly binaryOptions?: Partial<BinaryReadOptions & BinaryWriteOptions>;
109
+ /**
110
+ * Compression algorithms available to a client. Clients ask servers to
111
+ * compress responses using any of the registered algorithms. The first
112
+ * registered algorithm is the most preferred.
113
+ *
114
+ * It is safe to use this option liberally: servers will ignore any
115
+ * compression algorithms they don't support. To compress requests, pair this
116
+ * option with `sendCompression`.
117
+ *
118
+ * If this option is not provided, the compression algorithms "gzip" and "br"
119
+ * (Brotli) are accepted. To opt out of response compression, pass an
120
+ * empty array.
121
+ */
122
+ readonly acceptCompression?: Compression[];
123
+ /**
124
+ * Configures the client to use the specified algorithm to compress request
125
+ * messages.
126
+ *
127
+ * Because some servers don't support compression, clients default to sending
128
+ * uncompressed requests.
129
+ */
130
+ readonly sendCompression?: Compression;
131
+ /**
132
+ * Sets a minimum size threshold for compression: Messages that are smaller
133
+ * than the configured minimum are sent uncompressed.
134
+ *
135
+ * The default value is 1 kibibyte, because the CPU cost of compressing very
136
+ * small messages usually isn't worth the small reduction in network I/O.
137
+ */
138
+ readonly compressMinBytes?: number;
139
+ /**
140
+ * The timeout in milliseconds to apply to all requests.
141
+ *
142
+ * This can be overridden on a per-request basis by passing a timeoutMs.
143
+ */
144
+ readonly defaultTimeoutMs?: number;
145
+ }
146
+ export declare const GrpcClientConfig: {
147
+ <Service extends string>(opts: Omit<GrpcClientConfig<Service>, "_Service">): GrpcClientConfig<Service>;
148
+ makeTag<Service extends string>(service: Service): Context.Tag<GrpcClientConfig<Service>, GrpcClientConfig<Service>>;
149
+ };
150
+ /**
151
+ * Metadata that can be attached to gRPC requests.
152
+ *
153
+ * This type defines the structure for additional information that can be sent
154
+ * with gRPC calls, including Connect-RPC context values and HTTP headers.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * import { RequestMeta } from "@dr_nikson/effect-grpc";
159
+ *
160
+ * const meta: RequestMeta = {
161
+ * headers: new Headers({ "Authorization": "Bearer token" }),
162
+ * contextValues: { timeout: 5000 }
163
+ * };
164
+ *
165
+ * // Used in generated client code
166
+ * const result = yield* client.getGreeting(request, meta);
167
+ * ```
168
+ *
169
+ * @category Client
170
+ * @since 0.2.0
171
+ */
172
+ export type RequestMeta = {
173
+ readonly contextValues?: ContextValues;
174
+ readonly headers?: Headers;
175
+ };
176
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAEvD,MAAM,MAAM,uBAAuB,GAAG,OAAO,QAAQ,CAAC,uBAAuB,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM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C;AACD,eAAO,MAAM,gBAAgB,EAAE;IAC7B,CAAC,OAAO,SAAS,MAAM,EACrB,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,GAChD,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7B,OAAO,CAAC,OAAO,SAAS,MAAM,EAC5B,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;CAGrE,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Context, Layer } from "effect";
2
+ import type * as T from "./client.js";
3
+ export declare const grpcClientRuntimeTypeId: unique symbol;
4
+ export declare const grpcClientRuntimeTag: Context.Tag<T.GrpcClientRuntime, T.GrpcClientRuntime>;
5
+ export declare function liveGrpcClientRuntime(): Layer.Layer<T.GrpcClientRuntime>;
6
+ export declare function makeGrpcClientConfigTag<Service extends string>(service: Service): Context.Tag<T.GrpcClientConfig<Service>, T.GrpcClientConfig<Service>>;
7
+ export declare function makeGrpcClientConfig<Service extends string>(opts: Omit<T.GrpcClientConfig<Service>, "_Service">): T.GrpcClientConfig<Service>;
8
+ //# sourceMappingURL=client.internal.d.ts.map
@@ -0,0 +1 @@
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;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"}
@@ -0,0 +1,57 @@
1
+ import { Context, Effect, Layer } from "effect";
2
+ import { createClient, createContextValues, } from "@connectrpc/connect";
3
+ import { createGrpcTransport } from "@connectrpc/connect-node";
4
+ export const grpcClientRuntimeTypeId = Symbol("@dr_nikson/effect-grpc/GrpcClientRuntime");
5
+ export const grpcClientRuntimeTag = Context.GenericTag(grpcClientRuntimeTypeId.toString());
6
+ // TODO: this abstraction is kinda useless, right? We can make more in use .. can we?
7
+ export function liveGrpcClientRuntime() {
8
+ const instance = {
9
+ Type: grpcClientRuntimeTypeId,
10
+ makeExecutor(serviceDefinition, methodNames) {
11
+ return Effect.gen(function* () {
12
+ const transport = yield* Effect.sync(() => createGrpcTransport({
13
+ baseUrl: "http://localhost:8000",
14
+ }));
15
+ const client = createClient(serviceDefinition, transport);
16
+ const instance = methodNames.reduce((acc, methodName) => {
17
+ const method = makeExecutorMethod(client, methodName, serviceDefinition);
18
+ return method === null ? acc : { ...acc, [methodName]: method };
19
+ }, {});
20
+ return instance;
21
+ });
22
+ },
23
+ };
24
+ return Layer.succeed(grpcClientRuntimeTag, instance);
25
+ }
26
+ function makeExecutorMethod(client, methodName, serviceDefinition) {
27
+ const method = serviceDefinition.method[methodName];
28
+ switch (method.methodKind) {
29
+ case "unary":
30
+ return (req, opts) => {
31
+ return Effect.promise((signal) => {
32
+ const method = client[methodName].bind(client);
33
+ return method(req, {
34
+ // timeoutMs: null,
35
+ // TODO: tracing
36
+ headers: opts.headers,
37
+ signal,
38
+ // onHeader: null,
39
+ // onTrailer: null,
40
+ contextValues: createContextValues(),
41
+ });
42
+ });
43
+ };
44
+ default:
45
+ return null;
46
+ }
47
+ }
48
+ export function makeGrpcClientConfigTag(service) {
49
+ return Context.GenericTag(`@dr_nikson/effect-grpc/GrpcClientConfig<${service}>`);
50
+ }
51
+ export function makeGrpcClientConfig(opts) {
52
+ return {
53
+ ...opts,
54
+ _Service: () => void 0,
55
+ };
56
+ }
57
+ //# sourceMappingURL=client.internal.js.map
@@ -0,0 +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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E,OAAO,OAAO,CAAC,UAAU,CACvB,2CAA2C,OAAO,GAAG,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 ADDED
@@ -0,0 +1,51 @@
1
+ import * as internal from "./client.internal.js";
2
+ /**
3
+ * Context tag for accessing the GrpcClient service.
4
+ *
5
+ * Use this tag to access the GrpcClient implementation in your Effect programs.
6
+ * The tag provides dependency injection for the gRPC client functionality.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Effect } from "effect";
11
+ * import { GrpcClient, liveGrpcClientLayer } from "@dr_nikson/effect-grpc";
12
+ *
13
+ * const program = Effect.gen(function* () {
14
+ * const client = yield* GrpcClient;
15
+ * return client;
16
+ * }).pipe(
17
+ * Effect.provide(liveGrpcClientLayer())
18
+ * );
19
+ * ```
20
+ *
21
+ * @category Client
22
+ * @since 0.2.0
23
+ */
24
+ export const GrpcClientRuntime = internal.grpcClientRuntimeTag;
25
+ /**
26
+ * Creates a live layer implementation for the GrpcClient service.
27
+ *
28
+ * This layer provides the default implementation of the GrpcClient interface,
29
+ * enabling gRPC client functionality in your Effect applications.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { Effect } from "effect";
34
+ * import { GrpcClient, liveGrpcClientLayer } from "@dr_nikson/effect-grpc";
35
+ *
36
+ * const program = Effect.gen(function* () {
37
+ * const client = yield* GrpcClient;
38
+ * return client.makeExecutor(serviceDefinition, ["methodName"]);
39
+ * }).pipe(
40
+ * Effect.provide(liveGrpcClientLayer())
41
+ * );
42
+ * ```
43
+ *
44
+ * @category Client
45
+ * @since 0.2.0
46
+ */
47
+ export const liveGrpcClientRuntimeLayer = internal.liveGrpcClientRuntime;
48
+ export const GrpcClientConfig = Object.assign(internal.makeGrpcClientConfig.bind(null), {
49
+ makeTag: internal.makeGrpcClientConfigTag,
50
+ });
51
+ //# sourceMappingURL=client.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ export * as EffectGrpcServer from "./server.js";
2
+ export * as EffectGrpcClient from "./client.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * as EffectGrpcServer from "./server.js";
2
+ export * as EffectGrpcClient from "./client.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,85 @@
1
+ import { Effect, ManagedRuntime } from "effect";
2
+ import type { DescMessage, MessageInitShape, MessageShape } from "@bufbuild/protobuf";
3
+ import type { GenMessage, GenServiceMethods } from "@bufbuild/protobuf/codegenv2";
4
+ import { HandlerContext } from "@connectrpc/connect";
5
+ import { RequestMeta } from "./client.js";
6
+ /**
7
+ * Type-safe executor interface for gRPC service methods.
8
+ *
9
+ * Maps gRPC service method shapes to their corresponding executor functions,
10
+ * providing type safety for method calls. Currently, supports unary RPC calls.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { EffectGrpcClient } from "@dr_nikson/effect-grpc";
15
+ *
16
+ * // This type is usually inferred from service definitions
17
+ * declare const serviceDefinition: GenService<MyServiceMethods>;
18
+ * declare const client: EffectGrpcClient.GrpcClient;
19
+ *
20
+ * const executor = client.makeExecutor(serviceDefinition, ["getGreeting"]);
21
+ * // executor.getGreeting is now type-safe based on the service definition
22
+ * ```
23
+ *
24
+ * @category Client
25
+ * @since 0.2.0
26
+ */
27
+ export type ClientExecutor<RuntimeShape extends GenServiceMethods> = {
28
+ [P in keyof RuntimeShape]: RuntimeShape[P] extends ({
29
+ methodKind: "unary";
30
+ input: GenMessage<infer In>;
31
+ output: GenMessage<infer Out>;
32
+ }) ? UnaryClientExecutorFn<GenMessage<In>, GenMessage<Out>> : "provided methodKind is not yet supported";
33
+ };
34
+ type UnaryClientExecutorFn<I extends DescMessage, O extends DescMessage> = (request: MessageInitShape<I>, meta?: RequestMeta) => Effect.Effect<MessageShape<O>>;
35
+ /**
36
+ * Executor interface that provides methods for executing gRPC service operations within Effect programs.
37
+ * The executor handles the bridge between the gRPC handler context and your custom context type.
38
+ *
39
+ * @template Ctx - The custom context type that will be provided to your service implementations
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { Effect } from "effect"
44
+ * import { EffectGrpcServer } from "@dr_nikson/effect-grpc"
45
+ *
46
+ * interface AppContext {
47
+ * db: Database
48
+ * logger: Logger
49
+ * }
50
+ *
51
+ * const userService = EffectGrpcServer.GrpcService("UserService", UserService)<AppContext>((exec) => ({
52
+ * // Use executor to run Effect programs
53
+ * getUser: (req) => exec.unary(req, ctx, (request, appCtx) =>
54
+ * Effect.gen(function* () {
55
+ * yield* appCtx.logger.info(`Getting user ${request.userId}`)
56
+ * const user = yield* appCtx.db.findUser(request.userId)
57
+ * return { user }
58
+ * })
59
+ * ),
60
+ *
61
+ * // Executor handles errors and context transformation automatically
62
+ * createUser: (req) => exec.unary(req, ctx, (request, appCtx) =>
63
+ * Effect.gen(function* () {
64
+ * const user = yield* appCtx.db.createUser(request.userData)
65
+ * return { user }
66
+ * })
67
+ * )
68
+ * }))
69
+ * ```
70
+ */
71
+ export interface ServerExecutor<Ctx> {
72
+ unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx: Ctx) => Effect.Effect<Out>): Promise<Out>;
73
+ }
74
+ export declare const ServerExecutor: {
75
+ (runtime: ManagedRuntime.ManagedRuntime<never, never>): ServerExecutor<HandlerContext>;
76
+ };
77
+ export interface ServerExecutorTransformer<Ctx> {
78
+ readonly transformation: (underlying: ServerExecutor<HandlerContext>) => ServerExecutor<Ctx>;
79
+ transformContext<Ctx1>(f: (ctx: Ctx) => Effect.Effect<Ctx1>): ServerExecutorTransformer<Ctx1>;
80
+ }
81
+ export declare const ServerExecutorTransformer: {
82
+ (): ServerExecutorTransformer<HandlerContext>;
83
+ };
84
+ export {};
85
+ //# sourceMappingURL=protoRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protoRuntime.d.ts","sourceRoot":"","sources":["../src/protoRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAEhD,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;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,a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AC,KAAK,cAAc,CAAC,GAAG,CAAC,CAAC;IAE7F,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;CAC/F;AACD,eAAO,MAAM,yBAAyB,EAAE;IACtC,IAAI,yBAAyB,CAAC,cAAc,CAAC,CAAC;CACA,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Effect, ManagedRuntime } from "effect";
2
+ import { HandlerContext } from "@connectrpc/connect";
3
+ import type * as T from "./protoRuntime.js";
4
+ /**
5
+ * @internal
6
+ * Live implementation of the Executor interface using Effect's ManagedRuntime.
7
+ * Handles the execution of Effect programs within gRPC service handlers.
8
+ */
9
+ export declare class ServerExecutorLive implements T.ServerExecutor<HandlerContext> {
10
+ readonly runtime: ManagedRuntime.ManagedRuntime<never, never>;
11
+ constructor(runtime: ManagedRuntime.ManagedRuntime<never, never>);
12
+ static make(runtime: ManagedRuntime.ManagedRuntime<never, never>): T.ServerExecutor<HandlerContext>;
13
+ unary<In, Out>(req: In, ctx: HandlerContext, prog: (req: In, ctx: HandlerContext) => Effect.Effect<Out>): Promise<Out>;
14
+ }
15
+ /**
16
+ * @internal
17
+ * Transformer class that handles context transformations for executors.
18
+ * Allows chaining context transformations in a type-safe manner.
19
+ */
20
+ export declare class ServerExecutorTransformerLive<Ctx> implements T.ServerExecutorTransformer<Ctx> {
21
+ readonly transformation: (underlying: T.ServerExecutor<HandlerContext>) => T.ServerExecutor<Ctx>;
22
+ constructor(transformation: (underlying: T.ServerExecutor<HandlerContext>) => T.ServerExecutor<Ctx>);
23
+ static empty(): ServerExecutorTransformerLive<HandlerContext>;
24
+ transformContext<Ctx1>(f: (ctx: Ctx) => Effect.Effect<Ctx1>): ServerExecutorTransformerLive<Ctx1>;
25
+ }
26
+ //# sourceMappingURL=protoRuntime.internal.d.ts.map