@deployforme/adapter-nest 1.0.0

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.
@@ -0,0 +1,9 @@
1
+ import { HttpAdapter, RouteDefinition } from '@deploy4me/core';
2
+ import { INestApplication } from '@nestjs/common';
3
+ export declare class NestAdapter implements HttpAdapter {
4
+ private app;
5
+ private routes;
6
+ constructor(app: INestApplication);
7
+ registerRoute(definition: RouteDefinition): void;
8
+ unregisterRoute(id: string): void;
9
+ }
package/dist/index.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestAdapter = void 0;
4
+ class NestAdapter {
5
+ constructor(app) {
6
+ this.routes = new Map();
7
+ this.app = app;
8
+ }
9
+ registerRoute(definition) {
10
+ const { id, method, path, handler } = definition;
11
+ const httpAdapter = this.app.getHttpAdapter();
12
+ const instance = httpAdapter.getInstance();
13
+ const methodLower = method.toLowerCase();
14
+ instance[methodLower](path, async (req, res, next) => {
15
+ try {
16
+ const result = await handler(req, res);
17
+ if (result !== undefined && !res.headersSent) {
18
+ res.json(result);
19
+ }
20
+ }
21
+ catch (error) {
22
+ next(error);
23
+ }
24
+ });
25
+ this.routes.set(id, { method, path });
26
+ }
27
+ unregisterRoute(id) {
28
+ const route = this.routes.get(id);
29
+ if (!route)
30
+ return;
31
+ const httpAdapter = this.app.getHttpAdapter();
32
+ const instance = httpAdapter.getInstance();
33
+ // Remove from Express/Fastify stack
34
+ const stack = instance._router?.stack;
35
+ if (stack) {
36
+ const routeIndex = stack.findIndex((layer) => layer.route?.path === route.path &&
37
+ layer.route?.methods[route.method.toLowerCase()]);
38
+ if (routeIndex > -1) {
39
+ stack.splice(routeIndex, 1);
40
+ }
41
+ }
42
+ this.routes.delete(id);
43
+ }
44
+ }
45
+ exports.NestAdapter = NestAdapter;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@deployforme/adapter-nest",
3
+ "version": "1.0.0",
4
+ "description": "NestJS adapter for Deploy4Me",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "keywords": ["deploy4me", "nestjs", "adapter"],
8
+ "author": "Your Name <your.email@example.com>",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/yourusername/deploy4me.git",
13
+ "directory": "packages/adapter-nest"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "tsc --watch",
22
+ "prepublishOnly": "pnpm build"
23
+ },
24
+ "dependencies": {
25
+ "@deploy4me/core": "^1.0.0"
26
+ },
27
+ "peerDependencies": {
28
+ "@nestjs/common": "^10.0.0",
29
+ "@nestjs/core": "^10.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@nestjs/common": "^10.0.0",
33
+ "@nestjs/core": "^10.0.0",
34
+ "typescript": "^5.3.0"
35
+ }
36
+ }