@rym-lib/inversify-bundler-express 0.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.
- package/README.md +36 -0
- package/build/index.d.ts +13 -0
- package/build/index.js +47 -0
- package/build/index.js.map +1 -0
- package/build/index.mjs +23 -0
- package/build/index.mjs.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @rym-lib/inversify-bundler-express
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm i @rym-lib/inversify-bundler
|
|
7
|
+
npm i @rym-lib/inversify-bundler-express
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import 'reflect-metadata'
|
|
14
|
+
|
|
15
|
+
import express, { Request, Response } from 'express'
|
|
16
|
+
|
|
17
|
+
import { Bundler, ContainerModule } from '@rym-lib/inversify-bundler'
|
|
18
|
+
import { container } from '@rym-lib/inversify-bundler-express'
|
|
19
|
+
|
|
20
|
+
const app = express()
|
|
21
|
+
|
|
22
|
+
app.use(
|
|
23
|
+
container((req, res) => {
|
|
24
|
+
return new Bundler(
|
|
25
|
+
new ContainerModule((bind) => {
|
|
26
|
+
bind<Request>('Request').toDynamicValue(() => req)
|
|
27
|
+
bind<Response>('Response').toDynamicValue(() => res)
|
|
28
|
+
}),
|
|
29
|
+
)
|
|
30
|
+
}),
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
app.get('/example', (req) => {
|
|
34
|
+
const response = req.container.get<Response>('Response')
|
|
35
|
+
})
|
|
36
|
+
```
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as qs from 'qs';
|
|
2
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
3
|
+
import { Request, Response, RequestHandler } from 'express';
|
|
4
|
+
import { ContainerInterface, ModuleInput, Bundler } from '@rym-lib/inversify-bundler';
|
|
5
|
+
|
|
6
|
+
declare module 'express-serve-static-core' {
|
|
7
|
+
interface Request {
|
|
8
|
+
container: ContainerInterface;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare const container: (...modules: (ModuleInput | ((req: Request, res: Response) => Bundler))[]) => RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
12
|
+
|
|
13
|
+
export { container };
|
package/build/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
container: () => container
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/express.ts
|
|
28
|
+
var import_inversify_bundler = require("@rym-lib/inversify-bundler");
|
|
29
|
+
var container = (...modules) => {
|
|
30
|
+
const handler = (req, res, next) => {
|
|
31
|
+
const bundler = new import_inversify_bundler.Bundler(
|
|
32
|
+
...modules.map(
|
|
33
|
+
(module2) => typeof module2 === "function" ? module2(req, res) : module2
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
const container2 = new import_inversify_bundler.Container();
|
|
37
|
+
container2.load(...bundler.resolve());
|
|
38
|
+
req.container = container2;
|
|
39
|
+
next();
|
|
40
|
+
};
|
|
41
|
+
return handler;
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
container
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/express.ts"],"sourcesContent":["export * from './express'\n","import { Request, RequestHandler, Response } from 'express'\n\nimport {\n Bundler,\n Container,\n ContainerInterface,\n ModuleInput,\n} from '@rym-lib/inversify-bundler'\n\ndeclare module 'express-serve-static-core' {\n interface Request {\n container: ContainerInterface\n }\n}\n\nexport const container = (\n ...modules: (ModuleInput | ((req: Request, res: Response) => Bundler))[]\n) => {\n const handler: RequestHandler = (req, res, next) => {\n const bundler = new Bundler(\n ...modules.map((module) =>\n typeof module === 'function' ? module(req, res) : module,\n ),\n )\n\n const container = new Container()\n container.load(...bundler.resolve())\n\n req.container = container\n\n next()\n }\n\n return handler\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,+BAKO;AAQA,IAAM,YAAY,IACpB,YACA;AACH,QAAM,UAA0B,CAAC,KAAK,KAAK,SAAS;AAClD,UAAM,UAAU,IAAI;AAAA,MAClB,GAAG,QAAQ;AAAA,QAAI,CAACA,YACd,OAAOA,YAAW,aAAaA,QAAO,KAAK,GAAG,IAAIA;AAAA,MACpD;AAAA,IACF;AAEA,UAAMC,aAAY,IAAI,mCAAU;AAChC,IAAAA,WAAU,KAAK,GAAG,QAAQ,QAAQ,CAAC;AAEnC,QAAI,YAAYA;AAEhB,SAAK;AAAA,EACP;AAEA,SAAO;AACT;","names":["module","container"]}
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/express.ts
|
|
2
|
+
import {
|
|
3
|
+
Bundler,
|
|
4
|
+
Container
|
|
5
|
+
} from "@rym-lib/inversify-bundler";
|
|
6
|
+
var container = (...modules) => {
|
|
7
|
+
const handler = (req, res, next) => {
|
|
8
|
+
const bundler = new Bundler(
|
|
9
|
+
...modules.map(
|
|
10
|
+
(module) => typeof module === "function" ? module(req, res) : module
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
const container2 = new Container();
|
|
14
|
+
container2.load(...bundler.resolve());
|
|
15
|
+
req.container = container2;
|
|
16
|
+
next();
|
|
17
|
+
};
|
|
18
|
+
return handler;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
container
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/express.ts"],"sourcesContent":["import { Request, RequestHandler, Response } from 'express'\n\nimport {\n Bundler,\n Container,\n ContainerInterface,\n ModuleInput,\n} from '@rym-lib/inversify-bundler'\n\ndeclare module 'express-serve-static-core' {\n interface Request {\n container: ContainerInterface\n }\n}\n\nexport const container = (\n ...modules: (ModuleInput | ((req: Request, res: Response) => Bundler))[]\n) => {\n const handler: RequestHandler = (req, res, next) => {\n const bundler = new Bundler(\n ...modules.map((module) =>\n typeof module === 'function' ? module(req, res) : module,\n ),\n )\n\n const container = new Container()\n container.load(...bundler.resolve())\n\n req.container = container\n\n next()\n }\n\n return handler\n}\n"],"mappings":";AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAQA,IAAM,YAAY,IACpB,YACA;AACH,QAAM,UAA0B,CAAC,KAAK,KAAK,SAAS;AAClD,UAAM,UAAU,IAAI;AAAA,MAClB,GAAG,QAAQ;AAAA,QAAI,CAAC,WACd,OAAO,WAAW,aAAa,OAAO,KAAK,GAAG,IAAI;AAAA,MACpD;AAAA,IACF;AAEA,UAAMA,aAAY,IAAI,UAAU;AAChC,IAAAA,WAAU,KAAK,GAAG,QAAQ,QAAQ,CAAC;AAEnC,QAAI,YAAYA;AAEhB,SAAK;AAAA,EACP;AAEA,SAAO;AACT;","names":["container"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rym-lib/inversify-bundler-express",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./build/index.mjs",
|
|
10
|
+
"require": "./build/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "mizuki_r",
|
|
15
|
+
"email": "rymizuki.lib@gmail.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"description": "",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"build/index.js",
|
|
24
|
+
"build/index.js.map",
|
|
25
|
+
"build/index.mjs",
|
|
26
|
+
"build/index.mjs.map",
|
|
27
|
+
"build/index.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"lint": "eslint --max-warnings 0 .",
|
|
33
|
+
"format": "prettier -w './**/*.{ts,tsx,js,json,css}' --check",
|
|
34
|
+
"ncu": "npm-check-updates"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@rym-lib/dev-config": "*",
|
|
38
|
+
"@rym-lib/inversify-bundler": "*",
|
|
39
|
+
"@types/express": "^5.0.0",
|
|
40
|
+
"@types/node": "^22.9.0",
|
|
41
|
+
"express": "^4.21.1",
|
|
42
|
+
"npm-check-updates": "^17.1.11",
|
|
43
|
+
"tsup": "^8.3.5",
|
|
44
|
+
"vitest": "^2.1.5"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@rym-lib/inversify-bundler": ">=0.0.5",
|
|
48
|
+
"express": ">=4.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|