@funduck/connectrpc-fastify 1.0.21 → 1.0.23
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 +7 -0
- package/dist/connectrpc.d.ts +7 -1
- package/dist/connectrpc.js +13 -1
- package/dist/connectrpc.js.map +1 -1
- package/dist/controllers.d.ts +4 -0
- package/dist/controllers.js +36 -0
- package/dist/controllers.js.map +1 -0
- package/dist/fastify-plugin.js +2 -28
- package/dist/fastify-plugin.js.map +1 -1
- package/dist/helpers.d.ts +7 -9
- package/dist/helpers.js +22 -65
- package/dist/helpers.js.map +1 -1
- package/dist/interceptors.js +2 -1
- package/dist/interceptors.js.map +1 -1
- package/dist/middlewares.js +20 -2
- package/dist/middlewares.js.map +1 -1
- package/dist/route-config-checker.d.ts +3 -0
- package/dist/route-config-checker.js +37 -0
- package/dist/route-config-checker.js.map +1 -0
- package/dist/stores.d.ts +1 -1
- package/dist/stores.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -210,5 +210,12 @@ const authValue = context.values.get(authKey);
|
|
|
210
210
|
|
|
211
211
|
**Note:** Context values set in middlewares are automatically available in interceptors and controllers. Interceptors can also access and modify context values using `req.contextValues`.
|
|
212
212
|
|
|
213
|
+
## Strict Mode
|
|
214
|
+
If **strict mode** is enabled the library will cause process to exit on errors such as missing middleware or interceptor instances.
|
|
215
|
+
By default, strict mode is disabled to allow more flexibility during development.
|
|
216
|
+
|
|
217
|
+
To enable it call `ConnectRPC.setStrictMode(true)` before registering any middlewares or interceptors.
|
|
218
|
+
To check it read `ConnectRPC.isStrictMode` property.
|
|
219
|
+
|
|
213
220
|
## Feedback
|
|
214
221
|
Please use [Discussions](https://github.com/funduck/connectrpc-fastify/discussions) or email me.
|
package/dist/connectrpc.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ import { Interceptor, InterceptorConfigUnion, Logger, Middleware, MiddlewareConf
|
|
|
4
4
|
declare class ConnectRPCClass {
|
|
5
5
|
setLogger(customLogger: Logger | boolean): void;
|
|
6
6
|
setStrictMode(isStrict: boolean): void;
|
|
7
|
+
get isStrictMode(): boolean;
|
|
7
8
|
/** Should be called in middleware constructor */
|
|
8
9
|
registerMiddleware(self: Middleware): void;
|
|
9
10
|
/** Should be called in interceptor constructor */
|
|
10
11
|
registerInterceptor(self: Interceptor): void;
|
|
11
12
|
/** Should be called in controller constructor */
|
|
12
13
|
registerController<T extends GenServiceMethods>(self: Service<GenService<T>>, service: GenService<T>): void;
|
|
13
|
-
/** Initialize ConnectRPC with interceptors, Fastify plugin, and middlewares */
|
|
14
|
+
/** Initialize ConnectRPC with controllers, interceptors, Fastify plugin, and middlewares */
|
|
14
15
|
init(server: FastifyInstance, options?: {
|
|
15
16
|
logger?: Logger | false;
|
|
16
17
|
interceptors?: InterceptorConfigUnion[];
|
|
@@ -18,8 +19,13 @@ declare class ConnectRPCClass {
|
|
|
18
19
|
}): Promise<void>;
|
|
19
20
|
/** Clear all registered controllers, routes, middlewares, and interceptors, reset strict mode. Useful for testing */
|
|
20
21
|
clear(): void;
|
|
22
|
+
/** Initialize controllers. Should be called before initInterceptors because they need registered routes. */
|
|
23
|
+
initControllers(): void;
|
|
24
|
+
/** Initialize interceptors. Should be called after initControllers because needs registered routes. */
|
|
21
25
|
initInterceptors(configs: InterceptorConfigUnion[]): void;
|
|
26
|
+
/** Register Fastify plugin. Requires initialized server, controllers and interceptors. */
|
|
22
27
|
registerFastifyPlugin(server: FastifyInstance): Promise<void>;
|
|
28
|
+
/** Initialize middlewares. Should be called after registerFastifyPlugin because requires initialized server with registered plugin */
|
|
23
29
|
initMiddlewares(server: FastifyInstance, middlewareConfigs: MiddlewareConfigUnion[]): Promise<void>;
|
|
24
30
|
}
|
|
25
31
|
/**
|
package/dist/connectrpc.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectRPC = void 0;
|
|
4
4
|
const config_1 = require("./config");
|
|
5
|
+
const controllers_1 = require("./controllers");
|
|
5
6
|
const fastify_plugin_1 = require("./fastify-plugin");
|
|
6
7
|
const helpers_1 = require("./helpers");
|
|
7
8
|
const interceptors_1 = require("./interceptors");
|
|
@@ -14,6 +15,9 @@ class ConnectRPCClass {
|
|
|
14
15
|
setStrictMode(isStrict) {
|
|
15
16
|
(0, config_1.setStrictMode)(isStrict);
|
|
16
17
|
}
|
|
18
|
+
get isStrictMode() {
|
|
19
|
+
return config_1.isStrictMode;
|
|
20
|
+
}
|
|
17
21
|
/** Should be called in middleware constructor */
|
|
18
22
|
registerMiddleware(self) {
|
|
19
23
|
stores_1.MiddlewareStore.registerInstance(self);
|
|
@@ -26,11 +30,12 @@ class ConnectRPCClass {
|
|
|
26
30
|
registerController(self, service) {
|
|
27
31
|
stores_1.ControllersStore.registerInstance(self, service);
|
|
28
32
|
}
|
|
29
|
-
/** Initialize ConnectRPC with interceptors, Fastify plugin, and middlewares */
|
|
33
|
+
/** Initialize ConnectRPC with controllers, interceptors, Fastify plugin, and middlewares */
|
|
30
34
|
async init(server, options) {
|
|
31
35
|
if (options?.logger != null) {
|
|
32
36
|
this.setLogger(options.logger);
|
|
33
37
|
}
|
|
38
|
+
this.initControllers();
|
|
34
39
|
if (options?.interceptors) {
|
|
35
40
|
this.initInterceptors(options.interceptors);
|
|
36
41
|
}
|
|
@@ -47,12 +52,19 @@ class ConnectRPCClass {
|
|
|
47
52
|
stores_1.InterceptorStore.clear();
|
|
48
53
|
(0, config_1.setStrictMode)(false);
|
|
49
54
|
}
|
|
55
|
+
/** Initialize controllers. Should be called before initInterceptors because they need registered routes. */
|
|
56
|
+
initControllers() {
|
|
57
|
+
(0, controllers_1.initControllers)();
|
|
58
|
+
}
|
|
59
|
+
/** Initialize interceptors. Should be called after initControllers because needs registered routes. */
|
|
50
60
|
initInterceptors(configs) {
|
|
51
61
|
(0, interceptors_1.initInterceptors)(configs);
|
|
52
62
|
}
|
|
63
|
+
/** Register Fastify plugin. Requires initialized server, controllers and interceptors. */
|
|
53
64
|
registerFastifyPlugin(server) {
|
|
54
65
|
return (0, fastify_plugin_1.registerFastifyPlugin)(server);
|
|
55
66
|
}
|
|
67
|
+
/** Initialize middlewares. Should be called after registerFastifyPlugin because requires initialized server with registered plugin */
|
|
56
68
|
initMiddlewares(server, middlewareConfigs) {
|
|
57
69
|
return (0, middlewares_1.initMiddlewares)(server, middlewareConfigs);
|
|
58
70
|
}
|
package/dist/connectrpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectrpc.js","sourceRoot":"","sources":["../src/connectrpc.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"connectrpc.js","sourceRoot":"","sources":["../src/connectrpc.ts"],"names":[],"mappings":";;;AAEA,qCAAuD;AACvD,+CAAgD;AAChD,qDAAyD;AACzD,uCAAsC;AACtC,iDAAkD;AASlD,+CAAgD;AAChD,qCAKkB;AAElB,MAAM,eAAe;IACnB,SAAS,CAAC,YAA8B;QACtC,IAAA,mBAAS,EAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;IAED,aAAa,CAAC,QAAiB;QAC7B,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,YAAY;QACd,OAAO,qBAAY,CAAC;IACtB,CAAC;IAED,iDAAiD;IACjD,kBAAkB,CAAC,IAAgB;QACjC,wBAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,kDAAkD;IAClD,mBAAmB,CAAC,IAAiB;QACnC,yBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,iDAAiD;IACjD,kBAAkB,CAChB,IAA4B,EAC5B,OAAsB;QAEtB,yBAAgB,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,4FAA4F;IAC5F,KAAK,CAAC,IAAI,CACR,MAAuB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
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.implementations = void 0;
|
|
4
|
+
exports.initControllers = initControllers;
|
|
5
|
+
const helpers_1 = require("./helpers");
|
|
6
|
+
const stores_1 = require("./stores");
|
|
7
|
+
/** Here we will setup initialized implementstions for services */
|
|
8
|
+
exports.implementations = new Map();
|
|
9
|
+
function initControllers() {
|
|
10
|
+
// Create implementations from controller instances
|
|
11
|
+
for (const { instance, service } of stores_1.ControllersStore.values()) {
|
|
12
|
+
// Create the implementation object
|
|
13
|
+
const implementation = {};
|
|
14
|
+
// Bind each method from the service
|
|
15
|
+
for (const methodDesc of service.methods) {
|
|
16
|
+
const { name: methodName } = methodDesc; // This is in PascalCase, e.g., "Say" as in service .proto file
|
|
17
|
+
const controllerMethodName = (0, helpers_1.methodNameInController)(methodName);
|
|
18
|
+
if (controllerMethodName) {
|
|
19
|
+
const controllerMethod = instance[controllerMethodName];
|
|
20
|
+
if (controllerMethod) {
|
|
21
|
+
// Bind the method with proper 'this' context
|
|
22
|
+
const bindedMethod = controllerMethod.bind(instance);
|
|
23
|
+
implementation[controllerMethodName] = bindedMethod;
|
|
24
|
+
// Store route metadata for interceptors
|
|
25
|
+
stores_1.RouteMetadataStore.registerRoute(service.typeName, methodName, instance.constructor, controllerMethod, controllerMethodName, instance);
|
|
26
|
+
helpers_1.logger.log(`Binding ${instance.constructor.name}.${controllerMethodName} to ${service.typeName}.${methodName}`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
helpers_1.logger.warn(`Method ${controllerMethodName} not found in ${instance.constructor.name}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.implementations.set(service, implementation);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=controllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controllers.js","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":";;;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ACH,CAAC;QAED,uBAAe,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
package/dist/fastify-plugin.js
CHANGED
|
@@ -2,38 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerFastifyPlugin = registerFastifyPlugin;
|
|
4
4
|
const connect_fastify_1 = require("@connectrpc/connect-fastify");
|
|
5
|
+
const controllers_1 = require("./controllers");
|
|
5
6
|
const helpers_1 = require("./helpers");
|
|
6
7
|
const interceptors_1 = require("./interceptors");
|
|
7
|
-
const stores_1 = require("./stores");
|
|
8
8
|
async function registerFastifyPlugin(server, options = {}) {
|
|
9
|
-
// Create implementations from controller instances
|
|
10
|
-
const implementations = new Map();
|
|
11
|
-
for (const { instance, service } of stores_1.ControllersStore.values()) {
|
|
12
|
-
// Create the implementation object
|
|
13
|
-
const implementation = {};
|
|
14
|
-
// Bind each method from the service
|
|
15
|
-
for (const methodDesc of service.methods) {
|
|
16
|
-
const { name: methodName } = methodDesc; // This is in PascalCase, e.g., "Say" as in service .proto file
|
|
17
|
-
const controllerMethodName = methodName[0].toLowerCase() + methodName.slice(1); // This is in camelCase, e.g., "say" as in controller
|
|
18
|
-
if (controllerMethodName) {
|
|
19
|
-
const controllerMethod = instance[controllerMethodName];
|
|
20
|
-
if (controllerMethod) {
|
|
21
|
-
// Bind the method with proper 'this' context
|
|
22
|
-
const bindedMethod = controllerMethod.bind(instance);
|
|
23
|
-
implementation[controllerMethodName] = bindedMethod;
|
|
24
|
-
// Store route metadata for interceptors
|
|
25
|
-
stores_1.RouteMetadataStore.registerRoute(service.typeName, methodName, instance.constructor, controllerMethod, controllerMethodName, instance);
|
|
26
|
-
helpers_1.logger.log(`Binding ${instance.constructor.name}.${controllerMethodName} to ${service.typeName}.${methodName}`);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
helpers_1.logger.warn(`Method ${controllerMethodName} not found in ${instance.constructor.name}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
implementations.set(service, implementation);
|
|
34
|
-
}
|
|
35
9
|
const routes = (router) => {
|
|
36
|
-
for (const [service, implementation] of implementations.entries()) {
|
|
10
|
+
for (const [service, implementation] of controllers_1.implementations.entries()) {
|
|
37
11
|
router.service(service, implementation);
|
|
38
12
|
helpers_1.logger.log(`Registered {/${service.typeName}} route`);
|
|
39
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-plugin.js","sourceRoot":"","sources":["../src/fastify-plugin.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"fastify-plugin.js","sourceRoot":"","sources":["../src/fastify-plugin.ts"],"names":[],"mappings":";;AAQA,sDAgCC;AAvCD,iEAAmE;AAGnE,+CAAgD;AAChD,uCAAmC;AACnC,iDAA6E;AAEtE,KAAK,UAAU,qBAAqB,CACzC,MAAuB,EACvB,UAEI,EAAE;IAEN,MAAM,MAAM,GAAG,CAAC,MAAqB,EAAE,EAAE;QACvC,KAAK,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,6BAAe,CAAC,OAAO,EAAE,EAAE,CAAC;YAClE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YACxC,gBAAM,CAAC,GAAG,CAAC,gBAAgB,OAAO,CAAC,QAAQ,SAAS,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,gBAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAChD,OAAO;IACT,CAAC;IAED,MAAM,MAAM,CAAC,QAAQ,CAAC,sCAAoB,EAAE;QAC1C,yEAAyE;QACzE,oCAAoC;QACpC,0CAA0C;QAC1C,yCAAyC;QACzC,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,IAAI;QACb,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE;QAClD,YAAY,EAAE,CAAC,iCAAkB,EAAE,GAAG,sCAAuB,CAAC;QAC9D,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;IAEH,gBAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Logger,
|
|
3
|
-
export declare function callMiddlewareAsync(middleware: Middleware, req: FastifyRequest, res: FastifyReply): Promise<void>;
|
|
4
|
-
/**
|
|
5
|
-
* Helper to convert NestJS middleware to Fastify hook
|
|
6
|
-
*/
|
|
7
|
-
export declare function convertMiddlewareToHook(middlewareInstance: any): (request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
1
|
+
import { GenService } from '@bufbuild/protobuf/codegenv2';
|
|
2
|
+
import { Logger, RouteConfigGlobal, RouteConfigService } from './interfaces';
|
|
8
3
|
export declare let logger: Logger;
|
|
9
4
|
export declare function setLogger(customLogger: Logger | boolean): void;
|
|
10
5
|
/**
|
|
11
6
|
* Generate a unique request ID
|
|
12
7
|
*/
|
|
13
8
|
export declare function generateRequestId(): string;
|
|
14
|
-
/** Returns checker function for url */
|
|
15
|
-
export declare function buildRouteConfigChecker<T extends RouteConfigGlobal | RouteConfigService<any>>(configs: T[]): (url: string, checkConfig?: T) => T[];
|
|
16
9
|
/** Returns the pathname part of a URL which should be used to parse service name and method name */
|
|
17
10
|
export declare function getURLPath(url: string): string;
|
|
11
|
+
/** Converts a method name to camelCase - a convention for controller methods */
|
|
12
|
+
export declare function methodNameInController(methodName: string): string;
|
|
13
|
+
/** Converts a method name to PascalCase - a convention for .proto files */
|
|
14
|
+
export declare function methodNameInService(methodName: string): string;
|
|
15
|
+
export declare function routeConfigToString<T extends GenService<any>>(c: RouteConfigGlobal | RouteConfigService<T>): string;
|
package/dist/helpers.js
CHANGED
|
@@ -1,37 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logger = void 0;
|
|
4
|
-
exports.callMiddlewareAsync = callMiddlewareAsync;
|
|
5
|
-
exports.convertMiddlewareToHook = convertMiddlewareToHook;
|
|
6
4
|
exports.setLogger = setLogger;
|
|
7
5
|
exports.generateRequestId = generateRequestId;
|
|
8
|
-
exports.buildRouteConfigChecker = buildRouteConfigChecker;
|
|
9
6
|
exports.getURLPath = getURLPath;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
middleware.use(req.raw, res.raw, (err) => {
|
|
14
|
-
if (err) {
|
|
15
|
-
reject(err);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
resolve();
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
reject(error);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Helper to convert NestJS middleware to Fastify hook
|
|
29
|
-
*/
|
|
30
|
-
function convertMiddlewareToHook(middlewareInstance) {
|
|
31
|
-
return async (request, reply) => {
|
|
32
|
-
await callMiddlewareAsync(middlewareInstance, request, reply);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
7
|
+
exports.methodNameInController = methodNameInController;
|
|
8
|
+
exports.methodNameInService = methodNameInService;
|
|
9
|
+
exports.routeConfigToString = routeConfigToString;
|
|
35
10
|
exports.logger = {
|
|
36
11
|
log: (...args) => {
|
|
37
12
|
console.info(...args);
|
|
@@ -71,45 +46,27 @@ function setLogger(customLogger) {
|
|
|
71
46
|
function generateRequestId() {
|
|
72
47
|
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
73
48
|
}
|
|
74
|
-
/** Returns checker function for url */
|
|
75
|
-
function buildRouteConfigChecker(configs) {
|
|
76
|
-
const configMethods = configs.map((config) => ({
|
|
77
|
-
config: config,
|
|
78
|
-
methods: new Set(
|
|
79
|
-
// Convert method names to set with PascalCase
|
|
80
|
-
(config.methods || []).map((m) => m[0].toUpperCase() + m.slice(1))),
|
|
81
|
-
}));
|
|
82
|
-
/** Returns matched route configs for a given URL */
|
|
83
|
-
return (url, checkConfig) => {
|
|
84
|
-
// Parse the URL to get service and method
|
|
85
|
-
// Format: /package.ServiceName/MethodName
|
|
86
|
-
const match = url.match(/^\/([^/]+)\/([^/]+)$/);
|
|
87
|
-
if (!match) {
|
|
88
|
-
// Not a ConnectRPC route, skip
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
const [, serviceName, methodName] = match;
|
|
92
|
-
const matchedConfigs = [];
|
|
93
|
-
for (const { config, methods } of configMethods) {
|
|
94
|
-
// If checkConfig is provided, only match that specific config
|
|
95
|
-
if (checkConfig && config !== checkConfig) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
// Check if config should apply to this service
|
|
99
|
-
if (config.on && config.on.typeName !== serviceName) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
// Check if config should apply to this method
|
|
103
|
-
if (methods.size && !methods.has(methodName)) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
matchedConfigs.push(config);
|
|
107
|
-
}
|
|
108
|
-
return matchedConfigs;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
49
|
/** Returns the pathname part of a URL which should be used to parse service name and method name */
|
|
112
50
|
function getURLPath(url) {
|
|
113
51
|
return URL.parse(url)?.pathname || url;
|
|
114
52
|
}
|
|
53
|
+
/** Converts a method name to camelCase - a convention for controller methods */
|
|
54
|
+
function methodNameInController(methodName) {
|
|
55
|
+
// Convert first character to lowercase to match typical controller method naming: camelCase
|
|
56
|
+
return methodName.charAt(0).toLowerCase() + methodName.slice(1);
|
|
57
|
+
}
|
|
58
|
+
/** Converts a method name to PascalCase - a convention for .proto files */
|
|
59
|
+
function methodNameInService(methodName) {
|
|
60
|
+
// Convert first character to uppercase to match typical service method naming: PascalCase
|
|
61
|
+
return methodName.charAt(0).toUpperCase() + methodName.slice(1);
|
|
62
|
+
}
|
|
63
|
+
function routeConfigToString(c) {
|
|
64
|
+
if (!c.on) {
|
|
65
|
+
return 'global';
|
|
66
|
+
}
|
|
67
|
+
if (!c.methods) {
|
|
68
|
+
return c.on.typeName;
|
|
69
|
+
}
|
|
70
|
+
return `${c.on.typeName}(${c.methods.join(',')})`;
|
|
71
|
+
}
|
|
115
72
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAqBA,8BAeC;AAKD,8CAEC;AAGD,gCAEC;AAGD,wDAGC;AAGD,kDAGC;AAED,kDAUC;AArEU,QAAA,MAAM,GAAW;IAC1B,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACtB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,KAAK,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACvB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,KAAK,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACvB,CAAC;CACF,CAAC;AAEF,SAAgB,SAAS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E,CAAC;QACV,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC;IACvB,CAAC;IACD,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACpD,CAAC"}
|
package/dist/interceptors.js
CHANGED
|
@@ -6,6 +6,7 @@ const config_1 = require("./config");
|
|
|
6
6
|
const context_values_1 = require("./context-values");
|
|
7
7
|
const helpers_1 = require("./helpers");
|
|
8
8
|
const middlewares_1 = require("./middlewares");
|
|
9
|
+
const route_config_checker_1 = require("./route-config-checker");
|
|
9
10
|
const stores_1 = require("./stores");
|
|
10
11
|
/**
|
|
11
12
|
* ContextInterceptor - copies context values from MiddlewareContextStore to HandlerContext
|
|
@@ -55,7 +56,7 @@ function initInterceptors(configs) {
|
|
|
55
56
|
exports.initializedInterceptors = [];
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
const routeChecker = (0,
|
|
59
|
+
const routeChecker = (0, route_config_checker_1.buildRouteConfigChecker)(checkedConfigs);
|
|
59
60
|
exports.initializedInterceptors = [];
|
|
60
61
|
for (const config of checkedConfigs) {
|
|
61
62
|
const interceptorInstance = stores_1.InterceptorStore.getInstance(config.use);
|
package/dist/interceptors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":";;;AAqDA,4CAyDC;AA7GD,qCAAwC;AACxC,qDAG0B;AAC1B,uCAA+C;AAE/C,+CAAuD;AACvD,iEAAiE;AACjE,qCAIkB;AAElB;;;;GAIG;AACI,MAAM,kBAAkB,GAAgB,CAAC,I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AAC,CAAC;QAE1C,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE;YAC3B,CAAC,CAAC,eAAe,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;YACrC,CAAC,CAAC,kBAAkB,CAAC;QACvB,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO;YAC/B,CAAC,CAAC,aAAa,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC3C,CAAC,CAAC,cAAc,CAAC;QACnB,gBAAM,CAAC,GAAG,CACR,2BAA2B,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,WAAW,GAAG,UAAU,EAAE,CACxE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/middlewares.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.initMiddlewares = initMiddlewares;
|
|
|
6
6
|
const config_1 = require("./config");
|
|
7
7
|
const context_values_1 = require("./context-values");
|
|
8
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const route_config_checker_1 = require("./route-config-checker");
|
|
9
10
|
const stores_1 = require("./stores");
|
|
10
11
|
exports.xServerRequestIdHeader = 'x-server-request-id';
|
|
11
12
|
function setupCustomContextValues(req) {
|
|
@@ -67,14 +68,14 @@ async function initMiddlewares(server, configs) {
|
|
|
67
68
|
clearCustomContextValues(request.raw);
|
|
68
69
|
});
|
|
69
70
|
});
|
|
70
|
-
const routeChecker = (0,
|
|
71
|
+
const routeChecker = (0, route_config_checker_1.buildRouteConfigChecker)(checkedConfigs);
|
|
71
72
|
server.addHook('onRequest', async (request, reply) => {
|
|
72
73
|
const url = request.url;
|
|
73
74
|
const configs = routeChecker(url);
|
|
74
75
|
try {
|
|
75
76
|
for (const config of configs) {
|
|
76
77
|
const middlewareInstance = stores_1.MiddlewareStore.getInstance(config.use);
|
|
77
|
-
await
|
|
78
|
+
await callMiddlewareAsync(middlewareInstance, request, reply);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
catch (error) {
|
|
@@ -85,4 +86,21 @@ async function initMiddlewares(server, configs) {
|
|
|
85
86
|
}
|
|
86
87
|
});
|
|
87
88
|
}
|
|
89
|
+
function callMiddlewareAsync(middleware, req, res) {
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
try {
|
|
92
|
+
middleware.use(req.raw, res.raw, (err) => {
|
|
93
|
+
if (err) {
|
|
94
|
+
reject(err);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
resolve();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
reject(error);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
88
106
|
//# sourceMappingURL=middlewares.js.map
|
package/dist/middlewares.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"middlewares.js","sourceRoot":"","sources":["../src/middlewares.ts"],"names":[],"mappings":";;;AAsBA,wDAYC;AAUD,0CAoEC;AA/GD,qCAAwC;AACxC,qDAA6D;AAC7D,uCAAsD;AAEtD,iEAAiE;AACjE,qCAAmE;AAEtD,QAAA,sBAAsB,GAAG,qBAAqB,CAAC;AAE5D,SAAS,wBAAwB,CAAC,GAA0B;IAC1D,MAAM,SAAS,GAAG,IAAA,2BAAiB,GAAE,CAAC;IACtC,0CAA0C;IAC1C,GAAG,CAAC,OAAO,CAAC,8BAAsB,CAAC,GAAG,SAAS,CAAC;IAEhD,6DAA6D;IAC7D,+BAAsB,CAAC,GAAG,CAAC,SAAS,EAAE;QACpC,aAAa,EAAE,IAAA,0CAAyB,GAAE;KAC3C,CAAC,CAAC;AACL,CAAC;AAED,8FAA8F;AAC9F,SAAgB,sBAAsB,CAAC,GAA0B;IAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,8BAAsB,CAAW,CAAC;IAEhE,IAAI,SAAS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AC;gBAChB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAC1B,UAAsB,EACtB,GAAmB,EACnB,GAAiB;IAEjB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,IAAI,CAAC;YACH,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAS,EAAE,EAAE;gBAC7C,IAAI,GAAG,EAAE,CAAC;oBACR,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRouteConfigChecker = buildRouteConfigChecker;
|
|
4
|
+
const stores_1 = require("./stores");
|
|
5
|
+
/** Returns checker function for url */
|
|
6
|
+
function buildRouteConfigChecker(configs) {
|
|
7
|
+
const lookupMap = new Map();
|
|
8
|
+
const routes = stores_1.RouteMetadataStore.getAllRoutes();
|
|
9
|
+
// Building lookup map, for faster checking later
|
|
10
|
+
for (const [url, meta] of routes) {
|
|
11
|
+
const matchedConfigs = [];
|
|
12
|
+
for (const config of configs) {
|
|
13
|
+
// Skip if service name does not match
|
|
14
|
+
if (config.on && config.on.typeName !== meta.serviceName) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
// Skip if method name does not match
|
|
18
|
+
if (config.methods?.length &&
|
|
19
|
+
!config.methods.includes(meta.controllerMethodName)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
matchedConfigs.push(config);
|
|
23
|
+
}
|
|
24
|
+
if (matchedConfigs.length > 0) {
|
|
25
|
+
lookupMap.set(url, matchedConfigs);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Returns matched route configs for a given URL */
|
|
29
|
+
return (url, checkConfig) => {
|
|
30
|
+
const configs = lookupMap.get(url) || [];
|
|
31
|
+
if (checkConfig) {
|
|
32
|
+
return configs.filter((cfg) => cfg === checkConfig);
|
|
33
|
+
}
|
|
34
|
+
return configs;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=route-config-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-config-checker.js","sourceRoot":"","sources":["../src/route-config-checker.ts"],"names":[],"mappings":";;AAIA,0DA0CC;AA7CD,qCAA8C;AAE9C,uCAAuC;AACvC,SAAgB,uBAAuB,CAErC,OAAY;IACZ,MAAM,SAAS,GAAG,IAAI,GAAG,EAAe,CAAC;IACzC,MAAM,MAAM,GAAG,2BAAkB,CAAC,YAAY,EAAE,CAAC;IAEjD,iDAAiD;IACjD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,EAAE,CAAC;QACjC,MAAM,cAAc,GAAQ,EAAE,CAAC;QAE/B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,sCAAsC;YACtC,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC,QAAQ,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;gBACzD,SAAS;YACX,CAAC;YAED,qCAAqC;YACrC,IACE,MAAM,CAAC,OAAO,EAAE,MAAM;gBACtB,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,oBAAoB,CAAC,EACnD,CAAC;gBACD,SAAS;YACX,CAAC;YAED,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,oDAAoD;IACpD,OAAO,CAAC,GAAW,EAAE,WAAe,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAEzC,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/stores.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ declare class RouteMetadataStoreClass {
|
|
|
40
40
|
* @param methodName - The method name in PascalCase (e.g., "Say")
|
|
41
41
|
* @param controllerClass - The controller class
|
|
42
42
|
* @param controllerMethod - The bound controller method
|
|
43
|
-
* @param controllerMethodName - The name of the controller method
|
|
43
|
+
* @param controllerMethodName - The name of the controller method (e.g., "say")
|
|
44
44
|
* @param instance - The controller instance
|
|
45
45
|
*/
|
|
46
46
|
registerRoute(serviceName: string, methodName: string, controllerClass: Type<any>, controllerMethod: Function, controllerMethodName: string, instance: any): void;
|
package/dist/stores.js
CHANGED
|
@@ -74,7 +74,7 @@ class RouteMetadataStoreClass {
|
|
|
74
74
|
* @param methodName - The method name in PascalCase (e.g., "Say")
|
|
75
75
|
* @param controllerClass - The controller class
|
|
76
76
|
* @param controllerMethod - The bound controller method
|
|
77
|
-
* @param controllerMethodName - The name of the controller method
|
|
77
|
+
* @param controllerMethodName - The name of the controller method (e.g., "say")
|
|
78
78
|
* @param instance - The controller instance
|
|
79
79
|
*/
|
|
80
80
|
registerRoute(serviceName, methodName, controllerClass, controllerMethod, controllerMethodName, instance) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funduck/connectrpc-fastify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"author": "Oleg Milekhin <qlfunduck@gmail.com>",
|
|
5
5
|
"description": "Wrapper for official @connectrpc/connect and fastify. Simplifies configuration, type safe binding to controller, simplifies use of middlewares and guards.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "npx rimraf dist; tsc -p tsconfig.build.json",
|
|
10
10
|
"compile-proto": "cd test/demo && npx buf dep update; npx buf lint; npx buf generate",
|
|
11
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",
|
|
12
|
+
"test": "npm run compile-proto && jest --verbose --runInBand",
|
|
13
13
|
"test:coverage": "npm run compile-proto && jest --coverage --coverageReporters=json-summary --runInBand ; npx make-coverage-badge",
|
|
14
14
|
"publish:check": "npm run test && npm run test:demo && npm run build && npm publish --tag latest --access public --dry-run",
|
|
15
15
|
"publish:latest": "npm run test:coverage && npm run test:demo && npm run build && npm publish --tag latest --access public"
|