@wisemen/app-container 6.0.3 → 6.1.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/dist/node/index.d.ts +3 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/job.d.ts +6 -0
- package/dist/node/job.js +9 -0
- package/dist/node/job.js.map +1 -0
- package/dist/node/node.d.ts +18 -0
- package/dist/node/node.js +101 -0
- package/dist/node/node.js.map +1 -0
- package/dist/node/worker.d.ts +3 -0
- package/dist/node/worker.js +4 -0
- package/dist/node/worker.js.map +1 -0
- package/package.json +10 -1
- package/skills/getting-started/SKILL.md +5 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { INestApplicationContext } from '@nestjs/common';
|
|
2
|
+
import { NodeContainer } from '#lib/node/node.js';
|
|
3
|
+
export declare abstract class JobContainer extends NodeContainer {
|
|
4
|
+
abstract execute(nest: INestApplicationContext): Promise<void>;
|
|
5
|
+
protected init(): Promise<void>;
|
|
6
|
+
}
|
package/dist/node/job.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.js","sourceRoot":"","sources":["../../lib/node/job.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,OAAgB,YAAa,SAAQ,aAAa;IAG5C,KAAK,CAAC,IAAI;QAClB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;QAElB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAK,CAAC,CAAA;QAE9B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { INestApplicationContext } from '@nestjs/common';
|
|
2
|
+
import { NodeAdapter, type NodeAdapterOptions } from '@nestjs/platform-node';
|
|
3
|
+
export declare abstract class NodeContainer {
|
|
4
|
+
private adapter?;
|
|
5
|
+
private state;
|
|
6
|
+
protected nest?: INestApplicationContext;
|
|
7
|
+
protected getNodeOptions(): NodeAdapterOptions;
|
|
8
|
+
abstract bootstrap(app: NodeAdapter): Promise<INestApplicationContext>;
|
|
9
|
+
constructor();
|
|
10
|
+
private _init;
|
|
11
|
+
protected init(): Promise<void>;
|
|
12
|
+
protected close(): Promise<void>;
|
|
13
|
+
private enableShutdownHooks;
|
|
14
|
+
private enableProbes;
|
|
15
|
+
private liveness;
|
|
16
|
+
private readiness;
|
|
17
|
+
private version;
|
|
18
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { NodeAdapter } from '@nestjs/platform-node';
|
|
2
|
+
const port = Number(process.env.PORT) || 3000;
|
|
3
|
+
export class NodeContainer {
|
|
4
|
+
adapter;
|
|
5
|
+
state;
|
|
6
|
+
nest;
|
|
7
|
+
getNodeOptions() {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
constructor() {
|
|
11
|
+
this.state = 'starting';
|
|
12
|
+
this.enableShutdownHooks();
|
|
13
|
+
void this._init();
|
|
14
|
+
}
|
|
15
|
+
async _init() {
|
|
16
|
+
try {
|
|
17
|
+
await this.init();
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
await this.close();
|
|
21
|
+
console.log(e);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
const adapter = new NodeAdapter(this.getNodeOptions());
|
|
27
|
+
this.adapter = adapter;
|
|
28
|
+
this.enableProbes();
|
|
29
|
+
this.nest = await this.bootstrap(adapter);
|
|
30
|
+
await this.nest.init();
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const server = adapter.listen(port, '0.0.0.0', () => {
|
|
33
|
+
server.off('error', reject);
|
|
34
|
+
resolve();
|
|
35
|
+
});
|
|
36
|
+
server.once('error', reject);
|
|
37
|
+
});
|
|
38
|
+
console.log('server started');
|
|
39
|
+
this.state = 'ready';
|
|
40
|
+
}
|
|
41
|
+
async close() {
|
|
42
|
+
if (this.state === 'shutdown') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.state = 'shutdown';
|
|
46
|
+
try {
|
|
47
|
+
await this.adapter?.close();
|
|
48
|
+
await this.nest?.close();
|
|
49
|
+
console.log('application closed');
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
console.error('error shutting down', e);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
enableShutdownHooks() {
|
|
57
|
+
process.on('SIGTERM', () => void this.close());
|
|
58
|
+
process.on('SIGINT', () => void this.close());
|
|
59
|
+
process.on('SIGUSR2', () => void this.close());
|
|
60
|
+
process.on('SIGHUP', () => void this.close());
|
|
61
|
+
process.on('exit', () => void this.close());
|
|
62
|
+
}
|
|
63
|
+
enableProbes() {
|
|
64
|
+
if (this.adapter == null)
|
|
65
|
+
return;
|
|
66
|
+
const router = this.adapter.getInstance();
|
|
67
|
+
router.get('/', (_, res) => {
|
|
68
|
+
this.version(res);
|
|
69
|
+
});
|
|
70
|
+
router.get('/health', (_, res) => {
|
|
71
|
+
this.liveness(res);
|
|
72
|
+
});
|
|
73
|
+
router.get('/ready', (_, res) => {
|
|
74
|
+
this.readiness(res);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
liveness(res) {
|
|
78
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
79
|
+
res.end('OK');
|
|
80
|
+
}
|
|
81
|
+
readiness(res) {
|
|
82
|
+
if (this.state === 'ready') {
|
|
83
|
+
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
84
|
+
res.end('OK');
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
|
88
|
+
res.end('not OK');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
version(res) {
|
|
92
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
93
|
+
res.end(JSON.stringify({
|
|
94
|
+
env: process.env.NODE_ENV,
|
|
95
|
+
commit: process.env.COMMIT,
|
|
96
|
+
build: process.env.BUILD_NUMBER,
|
|
97
|
+
version: process.env.VERSION
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../lib/node/node.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EAKZ,MAAM,uBAAuB,CAAA;AAE9B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAI7C,MAAM,OAAgB,aAAa;IACzB,OAAO,CAAc;IACrB,KAAK,CAAO;IAEV,IAAI,CAA0B;IAC9B,cAAc;QACtB,OAAO,EAAE,CAAA;IACX,CAAC;IAID;QACE,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;QAEvB,IAAI,CAAC,mBAAmB,EAAE,CAAA;QAE1B,KAAK,IAAI,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;IAEO,KAAK,CAAC,KAAK;QACjB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;YAElB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YAEd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IAES,KAAK,CA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AE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAA;QACpD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IAEO,SAAS,CAAE,GAAiB;QAClC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAC3B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAA;YACpD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAA;YACpD,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IAEO,OAAO,CAAE,GAAiB;QAChC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;QAC1D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;YACrB,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;YACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM;YAC1B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;YAC/B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;SAC7B,CAAC,CAAC,CAAA;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../lib/node/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,OAAgB,eAAgB,SAAQ,aAAa;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wisemen/app-container",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"./fastify": {
|
|
21
21
|
"types": "./dist/fastify/index.d.ts",
|
|
22
22
|
"import": "./dist/fastify/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./node": {
|
|
25
|
+
"types": "./dist/node/index.d.ts",
|
|
26
|
+
"import": "./dist/node/index.js"
|
|
23
27
|
}
|
|
24
28
|
},
|
|
25
29
|
"files": [
|
|
@@ -30,6 +34,7 @@
|
|
|
30
34
|
"@nestjs/common": "12.0.1",
|
|
31
35
|
"@nestjs/core": "12.0.1",
|
|
32
36
|
"@nestjs/platform-fastify": "12.0.1",
|
|
37
|
+
"@nestjs/platform-node": "12.3.2",
|
|
33
38
|
"@types/express": "5.0.6",
|
|
34
39
|
"@types/node": "25.3.0",
|
|
35
40
|
"eslint": "10.2.1",
|
|
@@ -43,6 +48,7 @@
|
|
|
43
48
|
"@nestjs/common": "^11.1.28 || ^12.0.0",
|
|
44
49
|
"@nestjs/platform-express": "^11.1.28 || ^12.0.0",
|
|
45
50
|
"@nestjs/platform-fastify": ">=11.1.28",
|
|
51
|
+
"@nestjs/platform-node": "^12.3.0",
|
|
46
52
|
"express": "^5.2.1",
|
|
47
53
|
"fastify": "^5.12.5"
|
|
48
54
|
},
|
|
@@ -53,6 +59,9 @@
|
|
|
53
59
|
"@nestjs/platform-fastify": {
|
|
54
60
|
"optional": true
|
|
55
61
|
},
|
|
62
|
+
"@nestjs/platform-node": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
56
65
|
"express": {
|
|
57
66
|
"optional": true
|
|
58
67
|
},
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: getting-started
|
|
3
|
-
description: Use when bootstrapping NestJS api, worker, or job containers with Express or
|
|
3
|
+
description: Use when bootstrapping NestJS api, worker, or job containers with Express, Fastify, or the Nest Node adapter.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# @wisemen/app-container - Getting Started
|
|
7
7
|
|
|
8
|
-
Extend `ExpressContainer` or `
|
|
8
|
+
Extend `ExpressContainer`, `FastifyContainer`, or `NodeContainer` to bootstrap a Nest app with
|
|
9
9
|
built-in startup, shutdown, and probe endpoints. Use `JobContainer` for
|
|
10
10
|
run-once processes and `WorkerContainer` for long-running consumers.
|
|
11
11
|
|
|
@@ -32,6 +32,8 @@ class Api extends FastifyContainer {
|
|
|
32
32
|
const _api = new Api()
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Use `@wisemen/app-container/express` for Express-based apps
|
|
35
|
+
Use `@wisemen/app-container/express` for Express-based apps, or
|
|
36
|
+
`@wisemen/app-container/node` with `NodeAdapter` from `@nestjs/platform-node`
|
|
37
|
+
(Nest 12.3+) to run on plain Node.js `http` without a framework. Switch to
|
|
36
38
|
`JobContainer` when the process should execute work once and shut down after
|
|
37
39
|
`execute()`.
|