@funduck/connectrpc-fastify-nestjs 1.0.7 → 1.0.8

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # Connectrpc Fastify Wrapper For Nestjs
2
2
  <img src="./coverage/badge.svg" alt="Coverage Badge" />
3
3
 
4
+ [github](https://github.com/funduck/connectrpc-fastify-nestjs)
5
+
4
6
  !BETA
5
7
 
6
8
  Code is not production ready.
@@ -0,0 +1,26 @@
1
+ import { DynamicModule, Logger, OnModuleInit } from '@nestjs/common';
2
+ import { HttpAdapterHost } from '@nestjs/core';
3
+ import type { ConnectRPCModuleOptions } from './interfaces';
4
+ /**
5
+ * NestJS module for ConnectRPC integration
6
+ *
7
+ * Call registerPlugin() after app initialization and before server starts listening
8
+ *
9
+ */
10
+ export declare class ConnectRPCModule implements OnModuleInit {
11
+ private readonly httpAdapterHost;
12
+ private readonly options;
13
+ static readonly logger: Logger;
14
+ private readonly logger;
15
+ /**
16
+ * Configure the ConnectRPC module with options
17
+ */
18
+ static forRoot(options?: ConnectRPCModuleOptions): DynamicModule;
19
+ constructor(httpAdapterHost: HttpAdapterHost, options: ConnectRPCModuleOptions);
20
+ private getServer;
21
+ private registerPluginCalled;
22
+ /** This must be called after app is initialized and before server starts listening */
23
+ registerPlugin(): Promise<void>;
24
+ /** This is called by NestJS after the module has been initialized */
25
+ onModuleInit(): Promise<void>;
26
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var ConnectRPCModule_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.ConnectRPCModule = void 0;
17
+ const connectrpc_fastify_1 = require("@funduck/connectrpc-fastify");
18
+ const common_1 = require("@nestjs/common");
19
+ const core_1 = require("@nestjs/core");
20
+ const platform_fastify_1 = require("@nestjs/platform-fastify");
21
+ const CONNECTRPC_MODULE_OPTIONS = Symbol('CONNECTRPC_MODULE_OPTIONS');
22
+ /**
23
+ * NestJS module for ConnectRPC integration
24
+ *
25
+ * Call registerPlugin() after app initialization and before server starts listening
26
+ *
27
+ */
28
+ let ConnectRPCModule = ConnectRPCModule_1 = class ConnectRPCModule {
29
+ /**
30
+ * Configure the ConnectRPC module with options
31
+ */
32
+ static forRoot(options = {}) {
33
+ if (options.logger) {
34
+ connectrpc_fastify_1.ConnectRPC.setLogger(options.logger);
35
+ }
36
+ return {
37
+ module: ConnectRPCModule_1,
38
+ global: true,
39
+ providers: [
40
+ {
41
+ provide: CONNECTRPC_MODULE_OPTIONS,
42
+ useValue: options,
43
+ },
44
+ ],
45
+ exports: [CONNECTRPC_MODULE_OPTIONS],
46
+ };
47
+ }
48
+ // For injections
49
+ constructor(httpAdapterHost, options) {
50
+ this.httpAdapterHost = httpAdapterHost;
51
+ this.options = options;
52
+ this.logger = ConnectRPCModule_1.logger;
53
+ this.registerPluginCalled = false;
54
+ }
55
+ getServer() {
56
+ const httpAdapter = this.httpAdapterHost.httpAdapter;
57
+ if (!httpAdapter) {
58
+ throw new Error('HTTP Adapter not found');
59
+ }
60
+ // For now, only Fastify is supported
61
+ if (!(httpAdapter instanceof platform_fastify_1.FastifyAdapter)) {
62
+ throw new Error('Only FastifyAdapter is supported');
63
+ }
64
+ const fastifyAdapter = httpAdapter;
65
+ const server = fastifyAdapter.getInstance();
66
+ return server;
67
+ }
68
+ /** This must be called after app is initialized and before server starts listening */
69
+ async registerPlugin() {
70
+ if (this.registerPluginCalled) {
71
+ this.logger.warn('registerPlugin() has already been called');
72
+ return;
73
+ }
74
+ this.registerPluginCalled = true;
75
+ const server = this.getServer();
76
+ if (!server) {
77
+ throw new Error('Fastify server instance not found');
78
+ }
79
+ connectrpc_fastify_1.ConnectRPC.initInterceptors(this.options.interceptors || []);
80
+ await connectrpc_fastify_1.ConnectRPC.registerFastifyPlugin(server);
81
+ }
82
+ /** This is called by NestJS after the module has been initialized */
83
+ async onModuleInit() {
84
+ if (!this.registerPluginCalled) {
85
+ throw new Error('ConnectRPCModule.onModuleInit: registerPlugin() has not been called. Please call registerPlugin() after app initialization and before server starts listening.');
86
+ }
87
+ const server = this.getServer();
88
+ // Initialize middlewares first
89
+ await connectrpc_fastify_1.ConnectRPC.initMiddlewares(server, this.options.middlewares || []);
90
+ }
91
+ };
92
+ exports.ConnectRPCModule = ConnectRPCModule;
93
+ ConnectRPCModule.logger = new common_1.Logger(ConnectRPCModule_1.name, {
94
+ timestamp: true,
95
+ });
96
+ exports.ConnectRPCModule = ConnectRPCModule = ConnectRPCModule_1 = __decorate([
97
+ (0, common_1.Module)({}),
98
+ __param(0, (0, common_1.Inject)(core_1.HttpAdapterHost)),
99
+ __param(1, (0, common_1.Inject)(CONNECTRPC_MODULE_OPTIONS)),
100
+ __metadata("design:paramtypes", [core_1.HttpAdapterHost, Object])
101
+ ], ConnectRPCModule);
102
+ //# sourceMappingURL=connectrpc.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connectrpc.module.js","sourceRoot":"","sources":["../src/connectrpc.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAyD;AACzD,2CAMwB;AACxB,uCAA+C;AAC/C,+DAA0D;AAG1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B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAC7D,OAAO;QACT,CAAC;QACD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,+BAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;QAE7D,MAAM,+BAAU,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAED,qEAAqE;IACrE,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,gKAAgK,CACjK,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAEhC,+BAA+B;QAC/B,MAAM,+BAAU,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;IAC3E,CAAC;;AAnFU,4CAAgB;AACX,uBAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,EAAE;IACzD,SAAS,EAAE,IAAI;CAChB,CAAC,AAFoB,CAEnB;2BAHQ,gBAAgB;IAD5B,IAAA,eAAM,EAAC,EAAE,CAAC;IA6BN,WAAA,IAAA,eAAM,EAAC,sBAAe,CAAC,CAAA;IAEvB,WAAA,IAAA,eAAM,EAAC,yBAAyB,CAAC,CAAA;qCADA,sBAAe;GA7BxC,gBAAgB,CAoF5B"}
@@ -0,0 +1,3 @@
1
+ export declare function printMsg(): void;
2
+ export { ConnectRPCModule } from './connectrpc.module';
3
+ export type { ConnectRPCModuleOptions } from './interfaces';
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectRPCModule = void 0;
4
+ exports.printMsg = printMsg;
5
+ function printMsg() {
6
+ console.error('connectrpc-fastify-nestjs is in development mode! not ready for production yet!');
7
+ }
8
+ var connectrpc_module_1 = require("./connectrpc.module");
9
+ Object.defineProperty(exports, "ConnectRPCModule", { enumerable: true, get: function () { return connectrpc_module_1.ConnectRPCModule; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4BAIC;AAJD,SAAgB,QAAQ;IACtB,OAAO,CAAC,KAAK,CACX,iFAAiF,CAClF,CAAC;AACJ,CAAC;AAED,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,16 @@
1
+ import { Logger, MiddlewareConfigUnion } from '@funduck/connectrpc-fastify';
2
+ import { InterceptorConfigUnion } from '@funduck/connectrpc-fastify/dist/interfaces';
3
+ /**
4
+ * Options for configuring ConnectRPC module
5
+ */
6
+ export interface ConnectRPCModuleOptions {
7
+ logger?: Logger;
8
+ /**
9
+ * Middleware configurations to apply to ConnectRPC routes
10
+ */
11
+ middlewares?: MiddlewareConfigUnion[];
12
+ /**
13
+ * Interceptor configurations to apply to ConnectRPC routes
14
+ */
15
+ interceptors?: InterceptorConfigUnion[];
16
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funduck/connectrpc-fastify-nestjs",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "author": "Oleg Milekhin <qlfunduck@gmail.com>",
5
5
  "description": "Wrapper for official @connectrpc/connect and fastify integrated into Nestjs. Simplifies configuration, type safe binding to controller, simplifies use of middlewares.",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "peerDependencies": {
19
- "@funduck/connectrpc-fastify": "^1.0.17",
19
+ "@funduck/connectrpc-fastify": "^1.0.20",
20
20
  "@nestjs/common": "^11.1.12",
21
21
  "@nestjs/core": "^11.1.12",
22
22
  "@nestjs/platform-fastify": "^11.1.12",
@@ -28,7 +28,7 @@
28
28
  "@bufbuild/protoc-gen-es": "^2.10.2",
29
29
  "@connectrpc/connect": "^2.1.1",
30
30
  "@connectrpc/connect-node": "^2.1.1",
31
- "@funduck/connectrpc-fastify": "^1.0.17",
31
+ "@funduck/connectrpc-fastify": "^1.0.20",
32
32
  "@nestjs/common": "^11.1.12",
33
33
  "@nestjs/core": "^11.1.12",
34
34
  "@nestjs/platform-fastify": "^11.1.12",