@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 +201 -0
- package/bin/protoc-gen-effect +6 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.internal.d.ts +8 -0
- package/dist/client.internal.d.ts.map +1 -0
- package/dist/client.internal.js +57 -0
- package/dist/client.internal.js.map +1 -0
- package/dist/client.js +51 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/protoRuntime.d.ts +85 -0
- package/dist/protoRuntime.d.ts.map +1 -0
- package/dist/protoRuntime.internal.d.ts +26 -0
- package/dist/protoRuntime.internal.d.ts.map +1 -0
- package/dist/protoRuntime.internal.js +45 -0
- package/dist/protoRuntime.internal.js.map +1 -0
- package/dist/protoRuntime.js +4 -0
- package/dist/protoRuntime.js.map +1 -0
- package/dist/protocGenPlugin.d.ts +2 -0
- package/dist/protocGenPlugin.d.ts.map +1 -0
- package/dist/protocGenPlugin.js +335 -0
- package/dist/protocGenPlugin.js.map +1 -0
- package/dist/server.d.ts +214 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.internal.d.ts +30 -0
- package/dist/server.internal.d.ts.map +1 -0
- package/dist/server.internal.js +134 -0
- package/dist/server.internal.js.map +1 -0
- package/dist/server.js +49 -0
- package/dist/server.js.map +1 -0
- package/dist/typeUtils.d.ts +21 -0
- package/dist/typeUtils.d.ts.map +1 -0
- package/dist/typeUtils.js +2 -0
- package/dist/typeUtils.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { GenService, GenServiceMethods } from "@bufbuild/protobuf/codegenv2";
|
|
3
|
+
import { HandlerContext, ServiceImpl } from "@connectrpc/connect";
|
|
4
|
+
import * as ProtoRuntime from "./protoRuntime.js";
|
|
5
|
+
import type * as T from "./server.js";
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare const grpcServiceTypeId: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* Internal implementation for creating GrpcService instances.
|
|
13
|
+
* Used by the public GrpcService constructor in the main API.
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeGrpcService<Tag, Proto extends GenService<RuntimeShape>, RuntimeShape extends GenServiceMethods>(tag: Tag, definition: Proto): <Ctx>(implementation: (exec: ProtoRuntime.ServerExecutor<Ctx>) => ServiceImpl<Proto>) => T.GrpcService<Tag, Proto, Ctx>;
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
* Internal implementation of the GrpcServerBuilder interface.
|
|
19
|
+
* Provides the fluent API for building gRPC servers with context transformation.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ConnectEsGprcServerBuilder<Ctx, Services> implements T.GrpcServerBuilder<Ctx, Services> {
|
|
22
|
+
readonly transformCtx: (ctx: HandlerContext) => Effect.Effect<Ctx>;
|
|
23
|
+
readonly services: Record<string, T.GrpcService<any, any, Ctx>>;
|
|
24
|
+
constructor(transformCtx: (ctx: HandlerContext) => Effect.Effect<Ctx>, services: Record<string, T.GrpcService<any, any, Ctx>>);
|
|
25
|
+
static get empty(): T.GrpcServerBuilder<HandlerContext, never>;
|
|
26
|
+
withContextTransformer<This extends T.GrpcServerBuilder<Ctx, Services>, Ctx1>(this: This, f: (ctx: Ctx) => Effect.Effect<Ctx1>): T.GrpcServerBuilder<Ctx1, never>;
|
|
27
|
+
withService<S extends T.GrpcService<any, any, Ctx>>(service: T.UniqueTag<S, Services>): T.GrpcServerBuilder<Ctx, T.ConcatServiceTags<S, Services>>;
|
|
28
|
+
build<This extends T.GrpcServerBuilder<Ctx, Services>>(this: This): T.GrpcServer<Services>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=server.internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.internal.d.ts","sourceRoot":"","sources":["../src/server.internal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAuC,MAAM,QAAQ,CAAC;AAGrE,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAGL,cAAc,EACd,WAAW,EAEZ,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,KAAK,CAAC,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,eAAO,MAAM,iBAAiB,eAA+C,CAAC;AAE9E;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EACH,KAAK,SAAS,UAAU,CAAC,YAAY,CAAC,EACtC,YAAY,SAAS,iBAAiB,EACtC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,IACnB,GAAG,EAAE,gBAAgB,CAAC,IAAI,EAAE,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,KAAK,CAAC,KAQpF,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAEtC;AAuHD;;;;GAIG;AACH,qBAAa,0BAA0B,CAAC,GAAG,EAAE,QAAQ,CACnD,YAAW,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC;aAG3B,YAAY,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;aACzD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;gBADtD,YAAY,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EACzD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAGxE,MAAM,KAAK,KAAK,IAAI,CAAC,CAAC,iBAAiB,CAAC,cAAc,EAAE,KAAK,CAAC,CAE7D;IAED,sBAAsB,CAAC,IAAI,SAAS,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI,EAC1E,IAAI,EAAE,IAAI,EACV,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GACnC,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC;IAOnC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChD,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,GAChC,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,iBAAiB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAO7D,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;CAO3F"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// packages/effect-grpc/src/server.internal.ts
|
|
2
|
+
import { Effect, Layer, ManagedRuntime } from "effect";
|
|
3
|
+
import http2 from "node:http2";
|
|
4
|
+
import { createContextValues, } from "@connectrpc/connect";
|
|
5
|
+
import { connectNodeAdapter } from "@connectrpc/connect-node";
|
|
6
|
+
import * as ProtoRuntime from "./protoRuntime.js";
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const grpcServiceTypeId = Symbol("@dr_nikson/effect-grpc/GrpcService");
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
* Internal implementation for creating GrpcService instances.
|
|
14
|
+
* Used by the public GrpcService constructor in the main API.
|
|
15
|
+
*/
|
|
16
|
+
export function makeGrpcService(tag, definition) {
|
|
17
|
+
return (implementation) => {
|
|
18
|
+
return {
|
|
19
|
+
Type: grpcServiceTypeId,
|
|
20
|
+
_Tag: tag,
|
|
21
|
+
_Ctx: null,
|
|
22
|
+
implementation,
|
|
23
|
+
definition,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
* Live implementation of the GrpcServer interface.
|
|
30
|
+
* Manages the HTTP/2 server and routes gRPC requests to registered services.
|
|
31
|
+
*/
|
|
32
|
+
class EffectGrpcServerLive {
|
|
33
|
+
services;
|
|
34
|
+
transformation;
|
|
35
|
+
constructor(services, transformation) {
|
|
36
|
+
this.services = services;
|
|
37
|
+
this.transformation = transformation;
|
|
38
|
+
}
|
|
39
|
+
_Services = (a) => a;
|
|
40
|
+
run() {
|
|
41
|
+
const routes = this.routes.bind(this);
|
|
42
|
+
const makeExecutor = this.makeExecutor.bind(this);
|
|
43
|
+
const HOST = "localhost";
|
|
44
|
+
const PORT = 8000;
|
|
45
|
+
return Effect.gen(function* () {
|
|
46
|
+
const executor = yield* makeExecutor();
|
|
47
|
+
const handler = yield* Effect.sync(() => connectNodeAdapter({
|
|
48
|
+
routes: routes(executor),
|
|
49
|
+
interceptors: [],
|
|
50
|
+
contextValues(req) {
|
|
51
|
+
// TODO: implement proper request transformations
|
|
52
|
+
console.log("Creating context values for request", req.url);
|
|
53
|
+
return createContextValues();
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
const startServer = Effect.async((resume) => {
|
|
57
|
+
const server = http2
|
|
58
|
+
.createServer(handler)
|
|
59
|
+
.addListener("connect", (req, socket, head) => {
|
|
60
|
+
console.log("Connected to server", req.url, socket, head);
|
|
61
|
+
})
|
|
62
|
+
.addListener("connection", (socket) => {
|
|
63
|
+
console.log("New connection", socket.remoteAddress, socket.remotePort);
|
|
64
|
+
})
|
|
65
|
+
.addListener("error", (err) => {
|
|
66
|
+
console.error("Server error", err);
|
|
67
|
+
})
|
|
68
|
+
.addListener("clientError", (err) => {
|
|
69
|
+
console.error("Client error", err);
|
|
70
|
+
})
|
|
71
|
+
.addListener("dropRequest", (req, socket) => {
|
|
72
|
+
console.warn("Dropped request", req.url, socket);
|
|
73
|
+
})
|
|
74
|
+
.listen({ port: PORT, host: HOST }, () => {
|
|
75
|
+
resume(Effect.logInfo(`gRPC server listening on http://${HOST}:${PORT}`).pipe(Effect.as(server)));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const stopServer = (server) => Effect.async((resume) => {
|
|
79
|
+
// Gracefully stop the server
|
|
80
|
+
server.close(() => resume(Effect.logInfo("gRPC server stopped")));
|
|
81
|
+
});
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
const server = yield* Effect.acquireRelease(startServer, stopServer);
|
|
84
|
+
return yield* Effect.never;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
routes(executor) {
|
|
88
|
+
const allServices = Object.values(this.services);
|
|
89
|
+
return (router) => {
|
|
90
|
+
return allServices.reduce((router, service) => {
|
|
91
|
+
return router.service(service.definition, service.implementation(executor));
|
|
92
|
+
}, router);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
makeExecutor() {
|
|
96
|
+
const { transformation } = this;
|
|
97
|
+
return Effect.gen(function* () {
|
|
98
|
+
const runtime = yield* Effect.acquireRelease(Effect.sync(() => ManagedRuntime.make(Layer.empty)), (runtime) => runtime.disposeEffect);
|
|
99
|
+
const basicExecutor = ProtoRuntime.ServerExecutor(runtime);
|
|
100
|
+
const transformedExecutor = transformation(basicExecutor);
|
|
101
|
+
return transformedExecutor;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @internal
|
|
107
|
+
* Internal implementation of the GrpcServerBuilder interface.
|
|
108
|
+
* Provides the fluent API for building gRPC servers with context transformation.
|
|
109
|
+
*/
|
|
110
|
+
export class ConnectEsGprcServerBuilder {
|
|
111
|
+
transformCtx;
|
|
112
|
+
services;
|
|
113
|
+
constructor(transformCtx, services) {
|
|
114
|
+
this.transformCtx = transformCtx;
|
|
115
|
+
this.services = services;
|
|
116
|
+
}
|
|
117
|
+
static get empty() {
|
|
118
|
+
return new ConnectEsGprcServerBuilder((ctx) => Effect.succeed(ctx), {});
|
|
119
|
+
}
|
|
120
|
+
withContextTransformer(f) {
|
|
121
|
+
return new ConnectEsGprcServerBuilder((ctx) => Effect.flatMap(this.transformCtx(ctx), f), {});
|
|
122
|
+
}
|
|
123
|
+
withService(service) {
|
|
124
|
+
return new ConnectEsGprcServerBuilder(this.transformCtx, {
|
|
125
|
+
...this.services,
|
|
126
|
+
[service._Tag]: service,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
build() {
|
|
130
|
+
const executorTransformation = ProtoRuntime.ServerExecutorTransformer().transformContext(this.transformCtx);
|
|
131
|
+
return new EffectGrpcServerLive(this.services, executorTransformation.transformation);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=server.internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.internal.js","sourceRoot":"","sources":["../src/server.internal.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAgB,MAAM,QAAQ,CAAC;AACrE,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,OAAO,EAKL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAA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
|
2
|
+
/**
|
|
3
|
+
* Creates a new GrpcServerBuilder instance with default HandlerContext.
|
|
4
|
+
* This is the entry point for building a gRPC server.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { EffectGrpcServer } from "@dr_nikson/effect-grpc"
|
|
9
|
+
*
|
|
10
|
+
* // Create a new server builder
|
|
11
|
+
* const builder = EffectGrpcServer.GrpcServerBuilder()
|
|
12
|
+
*
|
|
13
|
+
* // Chain methods to configure the server
|
|
14
|
+
* const server = builder
|
|
15
|
+
* .withService(myService)
|
|
16
|
+
* .build()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const GrpcServerBuilder = () => internal.ConnectEsGprcServerBuilder.empty;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new GrpcService instance with the specified tag and Protocol Buffer definition.
|
|
22
|
+
* This is typically used by code generators rather than being called manually.
|
|
23
|
+
*
|
|
24
|
+
* @template Tag - The service tag identifier
|
|
25
|
+
* @template Proto - The Protocol Buffer service definition
|
|
26
|
+
* @template RuntimeShape - The runtime shape of the service methods
|
|
27
|
+
*
|
|
28
|
+
* @param tag - Unique identifier for this service
|
|
29
|
+
* @param definition - Protocol Buffer service definition
|
|
30
|
+
* @returns A function that takes an implementation and returns a GrpcService
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { EffectGrpcServer } from "@dr_nikson/effect-grpc"
|
|
35
|
+
* import { UserService } from "./gen/user_pb"
|
|
36
|
+
*
|
|
37
|
+
* // Create a service (typically done by code generator)
|
|
38
|
+
* const createUserService = EffectGrpcServer.GrpcService("UserService", UserService)
|
|
39
|
+
*
|
|
40
|
+
* // Provide implementation
|
|
41
|
+
* const userService = createUserService<AppContext>((exec) => ({
|
|
42
|
+
* getUser: (req) => exec.unary(req, ctx, (req, appCtx) =>
|
|
43
|
+
* Effect.succeed({ user: { id: req.userId, name: "John" } })
|
|
44
|
+
* )
|
|
45
|
+
* }))
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export const GrpcService = internal.makeGrpcService;
|
|
49
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AA2IjD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAE1B,GAAG,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC,KAAK,CAAC;AAgDpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,WAAW,GAOpB,QAAQ,CAAC,eAAe,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import type { DescMethod, MessageInitShape } from "@bufbuild/protobuf";
|
|
3
|
+
import type { GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
|
|
4
|
+
export type ExtractMessageType<T extends GenMessage<any>> = T extends GenMessage<infer A> ? A : never;
|
|
5
|
+
export type ServiceServerMethodDefinition<T extends Pick<DescMethod, "input" | "output" | "methodKind">, Ctx> = T extends {
|
|
6
|
+
methodKind: "unary";
|
|
7
|
+
input: GenMessage<infer In>;
|
|
8
|
+
output: GenMessage<infer Out>;
|
|
9
|
+
} ? (request: In, ctx: Ctx) => Effect.Effect<MessageInitShape<GenMessage<Out>>> : "provided methodKind is not supported, expected value: 'unary'";
|
|
10
|
+
export type ExtractServiceServerMethods<T extends GenService<any>, Ctx> = T extends GenService<infer RuntimeShape> ? {
|
|
11
|
+
[K in keyof RuntimeShape]: ServiceServerMethodDefinition<RuntimeShape[K], Ctx>;
|
|
12
|
+
} : "first step";
|
|
13
|
+
export type ServiceClientMethodDefinition<T extends Pick<DescMethod, "input" | "output" | "methodKind">, Meta> = T extends {
|
|
14
|
+
methodKind: "unary";
|
|
15
|
+
input: GenMessage<infer In>;
|
|
16
|
+
output: GenMessage<infer Out>;
|
|
17
|
+
} ? (request: MessageInitShape<GenMessage<In>>, ctx: Meta) => Effect.Effect<Out> : "provided methodKind is not supported, expected value: 'unary'";
|
|
18
|
+
export type ExtractServiceClientMethods<T extends GenService<any>, Meta> = T extends GenService<infer RuntimeShape> ? {
|
|
19
|
+
[K in keyof RuntimeShape]: ServiceClientMethodDefinition<RuntimeShape[K], Meta>;
|
|
20
|
+
} : "first step";
|
|
21
|
+
//# sourceMappingURL=typeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["../src/typeUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE3E,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,IACtD,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5C,MAAM,MAAM,6BAA6B,CACvC,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAC,EAC7D,GAAG,IAEH,CAAC,SAAS;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAA;CAAE,GAC3F,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,GAC3E,+DAA+D,CAAC;AAEpE,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,GAAG,IACpE,CAAC,SAAS,UAAU,CAAC,MAAM,YAAY,CAAC,GACtC;KAAG,CAAC,IAAI,MAAM,YAAY,GAAG,6BAA6B,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;CAAE,GAClF,YAAY,CAAC;AAEjB,MAAM,MAAM,6BAA6B,CACvC,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,GAAG,YAAY,CAAC,EAC7D,IAAI,IAEJ,CAAC,SAAS;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAA;CAAE,GAC3F,CAAC,OAAO,EAAE,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAC5E,+DAA+D,CAAC;AAEpE,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,IACrE,CAAC,SAAS,UAAU,CAAC,MAAM,YAAY,CAAC,GACtC;KAAG,CAAC,IAAI,MAAM,YAAY,GAAG,6BAA6B,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;CAAE,GACnF,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeUtils.js","sourceRoot":"","sources":["../src/typeUtils.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dr_nikson/effect-grpc",
|
|
3
|
+
"version": "0.2.0-mvp-35390ba5835ef85042f042d86878a7e9aee0dad9",
|
|
4
|
+
"description": "gRPC and Protobuf capabilities for the Effect ecosystem",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"provenance": true
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/Dr-Nikson/effect-grpc.git",
|
|
14
|
+
"directory": "packages/effect-grpc"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "dr_nikson",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"bin"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"protoc-gen-effect": "./bin/protoc-gen-effect"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./protoc-gen-effect": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/protocGenPlugin.d.ts",
|
|
39
|
+
"default": "./dist/protocGenPlugin.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/protocGenPlugin.d.ts",
|
|
43
|
+
"default": "./dist/protocGenPlugin.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@bufbuild/protobuf": "2.8.0",
|
|
49
|
+
"@bufbuild/protoplugin": "2.9.0",
|
|
50
|
+
"@connectrpc/connect": "2.1.0",
|
|
51
|
+
"@connectrpc/connect-node": "2.1.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@bufbuild/protobuf": "^2.8.0",
|
|
55
|
+
"@connectrpc/connect": "^2.1.0",
|
|
56
|
+
"effect": "^3.17.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@bufbuild/buf": "1.57.0",
|
|
60
|
+
"@bufbuild/protoc-gen-es": "2.8.0",
|
|
61
|
+
"@effect/platform": "0.90.10",
|
|
62
|
+
"@effect/platform-node": "0.96.1",
|
|
63
|
+
"effect": "3.17.14",
|
|
64
|
+
"typescript": "5.9.2",
|
|
65
|
+
"vitest": "3.2.4"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"compile": "tsc --build tsconfig.json",
|
|
69
|
+
"clean": "rm -rf ./dist ./tsconfig.tsbuildinfo",
|
|
70
|
+
"generate:proto": "pnpm buf generate",
|
|
71
|
+
"build": "pnpm run clean && pnpm run compile",
|
|
72
|
+
"test": "echo \"No test specified\" && exit 0",
|
|
73
|
+
"test:types": "vitest --typecheck.only --watch=false --config vitest.config.ts"
|
|
74
|
+
}
|
|
75
|
+
}
|