@deployforme/adapter-express 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 { Application } from 'express';
3
+ export declare class ExpressAdapter implements HttpAdapter {
4
+ private app;
5
+ private routes;
6
+ constructor(app: Application);
7
+ registerRoute(definition: RouteDefinition): void;
8
+ unregisterRoute(id: string): void;
9
+ }
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpressAdapter = void 0;
4
+ class ExpressAdapter {
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 expressHandler = async (req, res, next) => {
12
+ try {
13
+ const result = await handler(req, res);
14
+ if (result !== undefined && !res.headersSent) {
15
+ res.json(result);
16
+ }
17
+ }
18
+ catch (error) {
19
+ next(error);
20
+ }
21
+ };
22
+ // Register route
23
+ const methodLower = method.toLowerCase();
24
+ this.app[methodLower](path, expressHandler);
25
+ // Track for unregistration
26
+ const stack = this.app._router.stack;
27
+ const layer = stack[stack.length - 1];
28
+ this.routes.set(id, { method, path, layer });
29
+ }
30
+ unregisterRoute(id) {
31
+ const route = this.routes.get(id);
32
+ if (!route)
33
+ return;
34
+ // Remove from Express router stack
35
+ const stack = this.app._router.stack;
36
+ const index = stack.indexOf(route.layer);
37
+ if (index > -1) {
38
+ stack.splice(index, 1);
39
+ }
40
+ this.routes.delete(id);
41
+ }
42
+ }
43
+ exports.ExpressAdapter = ExpressAdapter;
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@deployforme/adapter-express",
3
+ "version": "1.0.0",
4
+ "description": "Express adapter for Deploy4Me",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "keywords": ["deploy4me", "express", "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-express"
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
+ "express": "^4.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/express": "^4.17.21",
32
+ "express": "^4.18.2",
33
+ "typescript": "^5.3.0"
34
+ }
35
+ }