@zmdb/transport-grpc 1.0.0-beta.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 ADDED
@@ -0,0 +1,83 @@
1
+ # @zmdb/transport-grpc
2
+
3
+ `@zmdb/transport-grpc` binds generated `@zmdb/protobuf` service artifacts to real grpc-js servers and typed clients. It owns deadlines, cancellation, metadata validation, streaming and bounded
4
+ application shutdown without parsing `.proto` files at runtime.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ yarn add @zmdb/app@1.0.0-beta.1 @zmdb/protobuf@1.0.0-beta.1 @zmdb/transport-grpc@1.0.0-beta.1 @grpc/grpc-js@^1.14.4
10
+ yarn add @zmdb/validator@1.0.0-beta.1
11
+ yarn add --dev @zmdb/compiler@1.0.0-beta.1
12
+ ```
13
+
14
+ > **Prerelease** (`1.0.0-beta.1`). Requires **Node.js 26+** and is **ESM-only**. Ships built ESM `.js` + `.d.ts` under `./dist`.
15
+
16
+ The sole peer is `@grpc/grpc-js@^1.14.4`. The package is not installed by `yarn add zmdb@1.0.0-beta.1`; `@zmdb/protobuf` supplies the source-level service artifact, `@zmdb/compiler` emits it at build
17
+ time, and the generated validators import the `@zmdb/validator` runtime ABI.
18
+
19
+ ## Usage
20
+
21
+ ```ts
22
+ import { Module, createApplication } from '@zmdb/app';
23
+ import { loadGrpcService } from '@zmdb/protobuf';
24
+ import { type ProtoField } from '@zmdb/schema/tags';
25
+ import { bindGrpcService, grpcExtension, type GrpcMetadata } from '@zmdb/transport-grpc';
26
+
27
+ interface GetOrder {
28
+ readonly id: string & ProtoField<1>;
29
+ }
30
+
31
+ interface Order {
32
+ readonly id: string & ProtoField<1>;
33
+ }
34
+
35
+ type Orders = {
36
+ readonly get: { readonly request: GetOrder; readonly response: Order };
37
+ };
38
+
39
+ const ordersService = loadGrpcService<Orders>('Orders', 'orders');
40
+
41
+ const orders = bindGrpcService(
42
+ {
43
+ definition: ordersService,
44
+ validateMetadata: (metadata: GrpcMetadata) => metadata,
45
+ onError: failure => console.error(failure.error),
46
+ },
47
+ {
48
+ get: async call => ({ id: call.payload.id }),
49
+ },
50
+ );
51
+
52
+ @Module({})
53
+ class AppModule {}
54
+
55
+ await using app = createApplication(AppModule, {
56
+ extensions: [
57
+ grpcExtension({
58
+ address: '0.0.0.0:50051',
59
+ bindings: [orders],
60
+ credentials: 'insecure',
61
+ }),
62
+ ],
63
+ });
64
+
65
+ await app.init();
66
+ ```
67
+
68
+ The caller owns every client returned by `createGrpcClient` and closes it with `close()` or `Symbol.dispose`. The application owns the server extension and applies its configured grace budget during
69
+ shutdown. The extension owns its grpc-js server; it attempts graceful shutdown, then forces closure when the grace budget expires.
70
+
71
+ ## Entry points
72
+
73
+ - `@zmdb/transport-grpc` — server bindings, `grpcExtension`, typed clients, status errors and application-facing gRPC types.
74
+
75
+ ## Documentation
76
+
77
+ Typed gRPC guide: **https://ambasta.github.io/zmdb/docs/web-microservices-grpc.html**
78
+
79
+ Full docs: **https://ambasta.github.io/zmdb/**
80
+
81
+ ## License
82
+
83
+ GNU General Public License v3.0 or later (GPL-3.0-or-later) — see [LICENSE](./LICENSE).
@@ -0,0 +1,3 @@
1
+ export { bindGrpcService, createGrpcClient, grpcExtension } from './runtime.js';
2
+ export { GrpcError, type GrpcBinding, type GrpcCall, type GrpcCaller, type GrpcClient, type GrpcClientCallOptions, type GrpcClientOptions, type GrpcClientTlsOptions, type GrpcFailure, type GrpcHandler, type GrpcHandlers, type GrpcKeyCertPair, type GrpcMetadata, type GrpcMetadataValidator, type GrpcServerOptions, type GrpcServerTlsOptions, type GrpcServiceSpec, type GrpcStatus, type GrpcTlsOptions, } from './types.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,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { bindGrpcService, createGrpcClient, grpcExtension } from './runtime.js';
2
+ export { GrpcError, } from './types.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EACL,SAAS,GAmBV,MAAM,YAAY,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ApplicationExtension } from '@zmdb/app';
2
+ import type { GrpcServiceDef } from '@zmdb/protobuf';
3
+ import { type GrpcBinding, type GrpcClient, type GrpcClientOptions, type GrpcHandlers, type GrpcServerOptions, type GrpcServiceSpec } from './types.js';
4
+ export interface OpenedGrpcServer {
5
+ readonly port: number;
6
+ close(graceMs: number): Promise<void>;
7
+ }
8
+ /** Bind one generated service definition to its exhaustive typed handler map. */
9
+ export declare function bindGrpcService<S extends GrpcServiceDef>(service: GrpcServiceSpec<S>, handlers: GrpcHandlers<S>): GrpcBinding;
10
+ /** Attach one gRPC server to the protocol-neutral application lifecycle. */
11
+ export declare function grpcExtension(options: GrpcServerOptions): ApplicationExtension;
12
+ /** Create a typed client from the same generated service artifact used by the server. */
13
+ export declare function createGrpcClient<S extends GrpcServiceDef>(options: GrpcClientOptions<S>): GrpcClient<S>;
14
+ /** Start all bound services. Kept internal to the application lifecycle. */
15
+ export declare function openGrpcServer(options: GrpcServerOptions): Promise<OpenedGrpcServer>;
16
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAmC,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtF,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,UAAU,EAEf,KAAK,iBAAiB,EAEtB,KAAK,YAAY,EAGjB,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EAErB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAgFD,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,EACtD,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAC3B,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GACxB,WAAW,CAGb;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,oBAAoB,CAe9E;AAED,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,cAAc,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA4BvG;AAED,4EAA4E;AAC5E,wBAAsB,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA6B1F"}