@funduck/connectrpc-fastify-nestjs 1.0.4 → 1.0.6

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
@@ -9,7 +9,7 @@ This package allows to add [Connectrpc](https://github.com/connectrpc/connect-es
9
9
 
10
10
  If you are comfortable with HTTP/1 only and want a compact, ready-to-use setup, this repository is for you.
11
11
 
12
- It simplifies the binding of controllers, middlewares, and guards.
12
+ It simplifies the binding of controllers and middlewares.
13
13
 
14
14
  It uses my another package [Connectrpc Fastify Wrapper](https://github.com/funduck/connectrpc-fastify).
15
15
 
@@ -21,14 +21,14 @@ This library allows you to:
21
21
  * Perform RPC with streaming responses
22
22
  * Perform RPC with streaming requests
23
23
  * Use middlewares
24
- * Use global guards
24
+ * Use interceptors
25
25
 
26
26
  *Bidirectional streaming RPC is currently out of scope because it requires HTTP/2, which is unstable on public networks. In practice, HTTP/1 provides more consistent performance.*
27
27
 
28
28
 
29
29
  ## How To Use
30
30
 
31
- You can check out the `test` directory for a complete example of server and client integration using NestJS and Fastify. Start reading from `test/app.module.ts`.
31
+ You can check out the `test/demo` directory for a complete example of server and client integration using NestJS and Fastify. Start reading from `test/demo/app.module.ts`.
32
32
 
33
33
  Except the bootstrap instructions are pretty much the same as in [Connectrpc Fastify Wrapper](https://github.com/funduck/connectrpc-fastify#how-to-use).
34
34
 
@@ -75,26 +75,30 @@ export class TestMiddleware1 implements Middleware {
75
75
 
76
76
  ```
77
77
 
78
- ### Guards
79
- Guard must implement `Guard` interface and register itself using `ConnectRPC.registerGuard`:
78
+ ### Interceptors
79
+ Interceptor must implement `Interceptor` interface and register itself using `ConnectRPC.registerInterceptor`:
80
80
  ```TS
81
81
  @Injectable()
82
- export class TestGuard1 implements Guard {
82
+ export class TestInterceptor1 implements Interceptor {
83
83
  @Inject(Logger)
84
84
  private logger: Logger;
85
85
 
86
86
  constructor() {
87
- ConnectRPC.registerGuard(this);
87
+ ConnectRPC.registerInterceptor(this);
88
88
  }
89
89
 
90
- canActivate(context: ExecutionContext): boolean {
91
- return true;
90
+ use(next: AnyFn): AnyFn {
91
+ return async (req) => {
92
+ this.logger.log(`TestInterceptor1 invoked`);
93
+ return await next(req);
94
+ };
92
95
  }
93
96
  }
97
+
94
98
  ```
95
99
 
96
100
  ### Module Setup
97
- Configure your NestJS module to use `ConnectRPCModule.forRoot` and register middlewares/guards as providers if necessary:
101
+ Configure your NestJS module to use `ConnectRPCModule.forRoot` and register middlewares and interceptors as providers if necessary:
98
102
 
99
103
  ```typescript
100
104
  @Module({
@@ -107,14 +111,16 @@ Configure your NestJS module to use `ConnectRPCModule.forRoot` and register midd
107
111
  middlewareConfig(TestMiddleware2, ElizaService),
108
112
  middlewareConfig(TestMiddleware3, ElizaService, ['say']),
109
113
  ],
114
+ interceptors: [
115
+ interceptorConfig(TestInterceptor1),
116
+ interceptorConfig(TestInterceptor2, ElizaService),
117
+ interceptorConfig(TestInterceptor3, ElizaService, ['say']),
118
+ ],
110
119
  }),
111
120
  ],
112
121
  providers: [
113
122
  Logger,
114
123
 
115
- // Guard is provided the NestJS way
116
- { provide: APP_GUARD, useClass: TestGuard1 },
117
-
118
124
  // Controllers are provided here instead of `controllers` array
119
125
  ElizaController,
120
126
 
@@ -124,6 +130,11 @@ Configure your NestJS module to use `ConnectRPCModule.forRoot` and register midd
124
130
 
125
131
  // Middlewares that are applied via `consumer.apply()` should NOT be provided here
126
132
  // Do not instantiate TestMiddleware3 twice!
133
+
134
+ // Interceptors specific for ConnectRPC are provided here
135
+ TestInterceptor1,
136
+ TestInterceptor2,
137
+ TestInterceptor3,
127
138
  ],
128
139
  })
129
140
  export class AppModule implements NestModule {
@@ -76,6 +76,7 @@ let ConnectRPCModule = ConnectRPCModule_1 = class ConnectRPCModule {
76
76
  if (!server) {
77
77
  throw new Error('Fastify server instance not found');
78
78
  }
79
+ connectrpc_fastify_1.ConnectRPC.initInterceptors(this.options.interceptors || []);
79
80
  await connectrpc_fastify_1.ConnectRPC.registerFastifyPlugin(server);
80
81
  }
81
82
  /** This is called by NestJS after the module has been initialized */
@@ -86,8 +87,6 @@ let ConnectRPCModule = ConnectRPCModule_1 = class ConnectRPCModule {
86
87
  const server = this.getServer();
87
88
  // Initialize middlewares first
88
89
  await connectrpc_fastify_1.ConnectRPC.initMiddlewares(server, this.options.middlewares || []);
89
- // Initialize guards after middlewares
90
- await connectrpc_fastify_1.ConnectRPC.initGuards(server);
91
90
  }
92
91
  };
93
92
  exports.ConnectRPCModule = ConnectRPCModule;
@@ -1 +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;AAG1D,MAAM,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;;;;GAKG;AAEI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAM3B;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,UAAmC,EAAE;QAClD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,+BAAU,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,yBAAyB;oBAClC,QAAQ,EAAE,OAAO;iBAClB;aACF;YACD,OAAO,EAAE,CAAC,yBAAyB,CAAC;SACrC,CAAC;IACJ,CAAC;IAED,iBAAiB;IACjB,YAEE,eAAiD,EAEjD,OAAiD;QAFhC,oBAAe,GAAf,eAAe,CAAiB;QAEhC,YAAO,GAAP,OAAO,CAAyB;QA3BlC,WAAM,GAAG,kBAAgB,CAAC,MAAM,CAAC;QA+C1C,yBAAoB,GAAG,KAAK,CAAC;IAnBlC,CAAC;IAEI,SAAS;QACf,M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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"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export declare function printMsg(): void;
1
2
  export { ConnectRPCModule } from './connectrpc.module';
2
3
  export type { ConnectRPCModuleOptions } from './interfaces';
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectRPCModule = void 0;
4
- // Export nestjs module
4
+ exports.printMsg = printMsg;
5
+ function printMsg() {
6
+ console.error('connectrpc-fastify-nestjs is in development mode! not ready for production yet!');
7
+ }
5
8
  var connectrpc_module_1 = require("./connectrpc.module");
6
9
  Object.defineProperty(exports, "ConnectRPCModule", { enumerable: true, get: function () { return connectrpc_module_1.ConnectRPCModule; } });
7
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA"}
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"}
@@ -1,4 +1,5 @@
1
1
  import { Logger, MiddlewareConfigUnion } from '@funduck/connectrpc-fastify';
2
+ import { InterceptorConfigUnion } from '@funduck/connectrpc-fastify/dist/interfaces';
2
3
  /**
3
4
  * Options for configuring ConnectRPC module
4
5
  */
@@ -8,4 +9,8 @@ export interface ConnectRPCModuleOptions {
8
9
  * Middleware configurations to apply to ConnectRPC routes
9
10
  */
10
11
  middlewares?: MiddlewareConfigUnion[];
12
+ /**
13
+ * Interceptor configurations to apply to ConnectRPC routes
14
+ */
15
+ interceptors?: InterceptorConfigUnion[];
11
16
  }
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "@funduck/connectrpc-fastify-nestjs",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "author": "Oleg Milekhin <qlfunduck@gmail.com>",
5
- "description": "Wrapper for official @connectrpc/connect and fastify integrated into Nestjs. Simplifies configuration, type safe binding to controller, simplifies use of middlewares and guards.",
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",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
9
  "build": "npx rimraf dist; tsc -p tsconfig.build.json",
10
- "compile-proto": "cd test && npx buf dep update; npx buf lint; npx buf generate",
11
- "test": "npm run compile-proto && cd test && DEBUG=true npx tsx e2e-demo.ts",
12
- "publish:check": "npm test && npm run build && npm publish --tag latest --access public --dry-run",
13
- "publish:latest": "npm publish --tag latest --access public"
10
+ "compile-proto": "cd test/demo && npx buf dep update; npx buf lint; npx buf generate",
11
+ "test:demo": "npm run compile-proto && cd test/demo && DEBUG=true npx tsx e2e-demo.ts",
12
+ "test": "npm run compile-proto && jest --verbose",
13
+ "test:coverage": "npm run compile-proto && jest --coverage --runInBand",
14
+ "publish:check": "npm test && npm run test:demo && npm run build && npm publish --tag latest --access public --dry-run",
15
+ "publish:latest": "npm test && npm run test:demo && npm run build && npm publish --tag latest --access public"
14
16
  },
15
17
  "license": "MIT",
16
18
  "peerDependencies": {
17
- "@funduck/connectrpc-fastify": "^1.0.11",
19
+ "@funduck/connectrpc-fastify": "^1.0.17",
18
20
  "@nestjs/common": "^11.1.12",
19
21
  "@nestjs/core": "^11.1.12",
20
- "@nestjs/platform-fastify": "^11.1.12"
22
+ "@nestjs/platform-fastify": "^11.1.12",
23
+ "fastify": "^5.6.2"
21
24
  },
22
25
  "devDependencies": {
23
26
  "@bufbuild/buf": "^1.64.0",
@@ -25,8 +28,16 @@
25
28
  "@bufbuild/protoc-gen-es": "^2.10.2",
26
29
  "@connectrpc/connect": "^2.1.1",
27
30
  "@connectrpc/connect-node": "^2.1.1",
31
+ "@funduck/connectrpc-fastify": "^1.0.17",
32
+ "@nestjs/common": "^11.1.12",
33
+ "@nestjs/core": "^11.1.12",
34
+ "@nestjs/platform-fastify": "^11.1.12",
35
+ "@types/jest": "^30.0.0",
28
36
  "@types/node": "^25.0.9",
37
+ "fastify": "^5.6.2",
38
+ "jest": "^30.2.0",
29
39
  "prettier-plugin-organize-imports": "^4.3.0",
40
+ "ts-jest": "^29.4.6",
30
41
  "ts-node": "^10.9.2",
31
42
  "typescript": "^5.9.3"
32
43
  }