@vnodes/boot-grpc 0.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 +35 -0
- package/bin/version.mjs +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/boot.d.ts +26 -0
- package/dist/lib/boot.d.ts.map +1 -0
- package/dist/lib/boot.js +80 -0
- package/dist/lib/boot.js.map +1 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img srcset="./assets/favicon.png, https://vnodes.github.io/vnodes/libs/boot-grpc/assets/favicon.png" alt="Logo" width="200" height="200" style="border-radius: 100%"/>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## @vnodes/boot-grpc
|
|
12
|
+
|
|
13
|
+
@vnodes/boot-grpc
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @vnodes/boot-grpc
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 💖 Support My Work
|
|
22
|
+
|
|
23
|
+
If you find my open-source contributions or the **@vnodes/boot-grpc** project helpful, consider supporting my work. Your sponsorship helps me maintain these projects and explore new enterprise patterns.
|
|
24
|
+
|
|
25
|
+
[](https://cash.app/$puqlib)
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🤝 Connect with Me
|
|
30
|
+
|
|
31
|
+
<p align="left">
|
|
32
|
+
<a href="mailto:robert.brightline+vnodes-boot-grpc@gmail.com">
|
|
33
|
+
<img src="https://img.shields.io/badge/Email-D14836?style=for-the-badge&logo=gmail&logoColor=white" />
|
|
34
|
+
</a>
|
|
35
|
+
</p>
|
package/bin/version.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
const packageJsonPath = join(__dirname, '..', 'package.json');
|
|
10
|
+
const packageJson = readFileSync(packageJsonPath, { encoding: 'utf-8' });
|
|
11
|
+
const version = JSON.parse(packageJson).version;
|
|
12
|
+
console.log(version);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './lib/boot.js';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Type } from '@vnodes/nestjs/common';
|
|
2
|
+
export type BootGRpcOptions = {
|
|
3
|
+
appModule: Type;
|
|
4
|
+
};
|
|
5
|
+
export declare function configs(): Promise<{
|
|
6
|
+
APP_ID: any;
|
|
7
|
+
PROTO_DIR: any;
|
|
8
|
+
PROTO_FILE_PATH: any;
|
|
9
|
+
PORT: any;
|
|
10
|
+
GRPC_URL: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Sample env
|
|
14
|
+
*
|
|
15
|
+
* ````env
|
|
16
|
+
* APP_ID="sample"
|
|
17
|
+
* APP_DESC="sample app"
|
|
18
|
+
* DB_URL="postgres://admin:password@localhost:5432/vnodes?schema=sample"
|
|
19
|
+
* DB_SCHEMA="sample"
|
|
20
|
+
* PROTO_DIR=apps/sample-service/proto
|
|
21
|
+
* PROTO_FILE_PATH=sample-service.proto
|
|
22
|
+
* ````
|
|
23
|
+
* @param options
|
|
24
|
+
*/
|
|
25
|
+
export declare function boot(options: BootGRpcOptions): Promise<void>;
|
|
26
|
+
//# sourceMappingURL=boot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boot.d.ts","sourceRoot":"","sources":["../../src/lib/boot.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAMtF,MAAM,MAAM,eAAe,GAAG;IAC1B,SAAS,EAAE,IAAI,CAAC;CACnB,CAAC;AAEF,wBAAsB,OAAO;;;;;;GAkB5B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,eAAe,iBA2ClD"}
|
package/dist/lib/boot.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Env } from '@vnodes/env';
|
|
2
|
+
import { ClassSerializerInterceptor, Logger } from '@vnodes/nestjs/common';
|
|
3
|
+
import { ConfigModule, ConfigService } from '@vnodes/nestjs/config';
|
|
4
|
+
import { NestFactory, Reflector } from '@vnodes/nestjs/core';
|
|
5
|
+
import { Transport } from '@vnodes/nestjs/microservices';
|
|
6
|
+
import { CommonGRpcValidationPipe } from '@vnodes/prop';
|
|
7
|
+
export async function configs() {
|
|
8
|
+
const context = await NestFactory.createApplicationContext(ConfigModule);
|
|
9
|
+
const config = context.get(ConfigService);
|
|
10
|
+
const APP_ID = config.getOrThrow(Env.APP_ID);
|
|
11
|
+
const PROTO_DIR = config.getOrThrow(Env.PROTO_DIR);
|
|
12
|
+
const PROTO_FILE_PATH = config.getOrThrow(Env.PROTO_FILE_PATH);
|
|
13
|
+
const PORT = config.getOrThrow(Env.PORT, 50051);
|
|
14
|
+
const GRPC_URL = `0.0.0.0:${PORT}`;
|
|
15
|
+
await context.close();
|
|
16
|
+
return {
|
|
17
|
+
APP_ID,
|
|
18
|
+
PROTO_DIR,
|
|
19
|
+
PROTO_FILE_PATH,
|
|
20
|
+
PORT,
|
|
21
|
+
GRPC_URL
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sample env
|
|
26
|
+
*
|
|
27
|
+
* ````env
|
|
28
|
+
* APP_ID="sample"
|
|
29
|
+
* APP_DESC="sample app"
|
|
30
|
+
* DB_URL="postgres://admin:password@localhost:5432/vnodes?schema=sample"
|
|
31
|
+
* DB_SCHEMA="sample"
|
|
32
|
+
* PROTO_DIR=apps/sample-service/proto
|
|
33
|
+
* PROTO_FILE_PATH=sample-service.proto
|
|
34
|
+
* ````
|
|
35
|
+
* @param options
|
|
36
|
+
*/ export async function boot(options) {
|
|
37
|
+
const NODE_ENV = process.env[Env.NODE_ENV];
|
|
38
|
+
const IS_PROD = NODE_ENV === 'production';
|
|
39
|
+
const { APP_ID, GRPC_URL, PROTO_DIR, PROTO_FILE_PATH } = await configs();
|
|
40
|
+
const logger = new Logger(APP_ID);
|
|
41
|
+
const app = await NestFactory.createMicroservice(options.appModule, {
|
|
42
|
+
transport: Transport.GRPC,
|
|
43
|
+
logger: IS_PROD ? [
|
|
44
|
+
'fatal',
|
|
45
|
+
'error'
|
|
46
|
+
] : undefined,
|
|
47
|
+
bufferLogs: true,
|
|
48
|
+
options: {
|
|
49
|
+
package: APP_ID,
|
|
50
|
+
url: GRPC_URL,
|
|
51
|
+
protoPath: PROTO_FILE_PATH,
|
|
52
|
+
loader: {
|
|
53
|
+
keepCase: true,
|
|
54
|
+
longs: String,
|
|
55
|
+
enums: String,
|
|
56
|
+
defaults: true,
|
|
57
|
+
oneofs: true,
|
|
58
|
+
includeDirs: [
|
|
59
|
+
PROTO_DIR
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
channelOptions: {
|
|
63
|
+
// Keep-alive: Helps prevent load balancers from dropping idle connections
|
|
64
|
+
'grpc.keepalive_time_ms': 10000,
|
|
65
|
+
'grpc.keepalive_timeout_ms': 5000,
|
|
66
|
+
'grpc.keepalive_permit_without_calls': 1,
|
|
67
|
+
// Maximum message size (standard is 4MB; increase if sending large CRM/HR reports)
|
|
68
|
+
'grpc.max_receive_message_length': 1024 * 1024 * 10,
|
|
69
|
+
'grpc.max_send_message_length': 1024 * 1024 * 10
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
app.enableShutdownHooks();
|
|
74
|
+
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
|
|
75
|
+
app.useGlobalPipes(CommonGRpcValidationPipe);
|
|
76
|
+
await app.listen();
|
|
77
|
+
logger.log(`${NODE_ENV}| gRpc Microservice | Running at ${GRPC_URL}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=boot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/boot.ts"],"sourcesContent":["import { Env } from '@vnodes/env';\nimport { ClassSerializerInterceptor, Logger, type Type } from '@vnodes/nestjs/common';\nimport { ConfigModule, ConfigService } from '@vnodes/nestjs/config';\nimport { NestFactory, Reflector } from '@vnodes/nestjs/core';\nimport { type GrpcOptions, Transport } from '@vnodes/nestjs/microservices';\nimport { CommonGRpcValidationPipe } from '@vnodes/prop';\n\nexport type BootGRpcOptions = {\n appModule: Type;\n};\n\nexport async function configs() {\n const context = await NestFactory.createApplicationContext(ConfigModule);\n const config = context.get(ConfigService);\n const APP_ID = config.getOrThrow(Env.APP_ID);\n const PROTO_DIR = config.getOrThrow(Env.PROTO_DIR);\n const PROTO_FILE_PATH = config.getOrThrow(Env.PROTO_FILE_PATH);\n const PORT = config.getOrThrow(Env.PORT, 50051);\n const GRPC_URL = `0.0.0.0:${PORT}`;\n\n await context.close();\n\n return {\n APP_ID,\n PROTO_DIR,\n PROTO_FILE_PATH,\n PORT,\n GRPC_URL,\n };\n}\n\n/**\n * Sample env\n *\n * ````env\n * APP_ID=\"sample\"\n * APP_DESC=\"sample app\"\n * DB_URL=\"postgres://admin:password@localhost:5432/vnodes?schema=sample\"\n * DB_SCHEMA=\"sample\"\n * PROTO_DIR=apps/sample-service/proto\n * PROTO_FILE_PATH=sample-service.proto\n * ````\n * @param options\n */\nexport async function boot(options: BootGRpcOptions) {\n const NODE_ENV = process.env[Env.NODE_ENV];\n const IS_PROD = NODE_ENV === 'production';\n\n const { APP_ID, GRPC_URL, PROTO_DIR, PROTO_FILE_PATH } = await configs();\n\n const logger = new Logger(APP_ID);\n\n const app = await NestFactory.createMicroservice<GrpcOptions>(options.appModule, {\n transport: Transport.GRPC,\n logger: IS_PROD ? ['fatal', 'error'] : undefined,\n bufferLogs: true,\n options: {\n package: APP_ID,\n url: GRPC_URL,\n protoPath: PROTO_FILE_PATH,\n loader: {\n keepCase: true, // Preserves field_names from .proto (important for some clients)\n longs: String, // Handles large SQL IDs/Numbers safely in JS\n enums: String, // Returns string names of enums for easier debugging\n defaults: true, // Ensures default values are populated in responses\n oneofs: true,\n includeDirs: [PROTO_DIR],\n },\n channelOptions: {\n // Keep-alive: Helps prevent load balancers from dropping idle connections\n 'grpc.keepalive_time_ms': 10000,\n 'grpc.keepalive_timeout_ms': 5000,\n 'grpc.keepalive_permit_without_calls': 1,\n // Maximum message size (standard is 4MB; increase if sending large CRM/HR reports)\n 'grpc.max_receive_message_length': 1024 * 1024 * 10, // 10MB\n 'grpc.max_send_message_length': 1024 * 1024 * 10, // 10MB\n },\n },\n });\n\n app.enableShutdownHooks();\n app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));\n app.useGlobalPipes(CommonGRpcValidationPipe);\n\n await app.listen();\n\n logger.log(`${NODE_ENV}| gRpc Microservice | Running at ${GRPC_URL}`);\n}\n"],"names":["Env","ClassSerializerInterceptor","Logger","ConfigModule","ConfigService","NestFactory","Reflector","Transport","CommonGRpcValidationPipe","configs","context","createApplicationContext","config","get","APP_ID","getOrThrow","PROTO_DIR","PROTO_FILE_PATH","PORT","GRPC_URL","close","boot","options","NODE_ENV","process","env","IS_PROD","logger","app","createMicroservice","appModule","transport","GRPC","undefined","bufferLogs","package","url","protoPath","loader","keepCase","longs","String","enums","defaults","oneofs","includeDirs","channelOptions","enableShutdownHooks","useGlobalInterceptors","useGlobalPipes","listen","log"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc;AAClC,SAASC,0BAA0B,EAAEC,MAAM,QAAmB,wBAAwB;AACtF,SAASC,YAAY,EAAEC,aAAa,QAAQ,wBAAwB;AACpE,SAASC,WAAW,EAAEC,SAAS,QAAQ,sBAAsB;AAC7D,SAA2BC,SAAS,QAAQ,+BAA+B;AAC3E,SAASC,wBAAwB,QAAQ,eAAe;AAMxD,OAAO,eAAeC;IAClB,MAAMC,UAAU,MAAML,YAAYM,wBAAwB,CAACR;IAC3D,MAAMS,SAASF,QAAQG,GAAG,CAACT;IAC3B,MAAMU,SAASF,OAAOG,UAAU,CAACf,IAAIc,MAAM;IAC3C,MAAME,YAAYJ,OAAOG,UAAU,CAACf,IAAIgB,SAAS;IACjD,MAAMC,kBAAkBL,OAAOG,UAAU,CAACf,IAAIiB,eAAe;IAC7D,MAAMC,OAAON,OAAOG,UAAU,CAACf,IAAIkB,IAAI,EAAE;IACzC,MAAMC,WAAW,CAAC,QAAQ,EAAED,MAAM;IAElC,MAAMR,QAAQU,KAAK;IAEnB,OAAO;QACHN;QACAE;QACAC;QACAC;QACAC;IACJ;AACJ;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,eAAeE,KAAKC,OAAwB;IAC/C,MAAMC,WAAWC,QAAQC,GAAG,CAACzB,IAAIuB,QAAQ,CAAC;IAC1C,MAAMG,UAAUH,aAAa;IAE7B,MAAM,EAAET,MAAM,EAAEK,QAAQ,EAAEH,SAAS,EAAEC,eAAe,EAAE,GAAG,MAAMR;IAE/D,MAAMkB,SAAS,IAAIzB,OAAOY;IAE1B,MAAMc,MAAM,MAAMvB,YAAYwB,kBAAkB,CAAcP,QAAQQ,SAAS,EAAE;QAC7EC,WAAWxB,UAAUyB,IAAI;QACzBL,QAAQD,UAAU;YAAC;YAAS;SAAQ,GAAGO;QACvCC,YAAY;QACZZ,SAAS;YACLa,SAASrB;YACTsB,KAAKjB;YACLkB,WAAWpB;YACXqB,QAAQ;gBACJC,UAAU;gBACVC,OAAOC;gBACPC,OAAOD;gBACPE,UAAU;gBACVC,QAAQ;gBACRC,aAAa;oBAAC7B;iBAAU;YAC5B;YACA8B,gBAAgB;gBACZ,0EAA0E;gBAC1E,0BAA0B;gBAC1B,6BAA6B;gBAC7B,uCAAuC;gBACvC,mFAAmF;gBACnF,mCAAmC,OAAO,OAAO;gBACjD,gCAAgC,OAAO,OAAO;YAClD;QACJ;IACJ;IAEAlB,IAAImB,mBAAmB;IACvBnB,IAAIoB,qBAAqB,CAAC,IAAI/C,2BAA2B2B,IAAIf,GAAG,CAACP;IACjEsB,IAAIqB,cAAc,CAACzC;IAEnB,MAAMoB,IAAIsB,MAAM;IAEhBvB,OAAOwB,GAAG,CAAC,GAAG5B,SAAS,iCAAiC,EAAEJ,UAAU;AACxE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnodes/boot-grpc",
|
|
3
|
+
"version": "0.0.23",
|
|
4
|
+
"description": "@vnodes/boot-grpc",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"boot-grpc"
|
|
7
|
+
],
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Robert Brightline",
|
|
10
|
+
"email": "robert.brightline+vnodes-boot-grpc@gmail.com",
|
|
11
|
+
"url": "https://vnodes.github.io/vnodes"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://vnodes.github.io/vnodes/libs/boot-grpc",
|
|
14
|
+
"icon": "https://vnodes.github.io/vnodes/libs/boot-grpc/assets/favicon.png",
|
|
15
|
+
"funding": [
|
|
16
|
+
"https://cash.app/$puqlib"
|
|
17
|
+
],
|
|
18
|
+
"bin": {
|
|
19
|
+
"version": "./bin/version.mjs"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"@vnodes/source": "./src/index.ts",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"bin",
|
|
37
|
+
"!**/*.tsbuildinfo"
|
|
38
|
+
],
|
|
39
|
+
"nx": {
|
|
40
|
+
"sourceRoot": "libs/boot-grpc/src",
|
|
41
|
+
"tags": [
|
|
42
|
+
"lib"
|
|
43
|
+
],
|
|
44
|
+
"targets": {
|
|
45
|
+
"build": {},
|
|
46
|
+
"doc": {},
|
|
47
|
+
"lint": {}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@swc/helpers": "~0.5.18"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@vnodes/nestjs": "0.0.23",
|
|
55
|
+
"@vnodes/prop": "0.0.23",
|
|
56
|
+
"@vnodes/env": "0.0.23"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@vnodes/env": "0.0.23",
|
|
60
|
+
"@vnodes/nestjs": "0.0.23",
|
|
61
|
+
"@vnodes/prop": "0.0.23"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public",
|
|
65
|
+
"tag": "latest"
|
|
66
|
+
}
|
|
67
|
+
}
|