@hodfords/nestjs-grpc-helper 10.0.0-rc.1
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 +89 -0
- package/clients/custom-grpc.client.d.ts +27 -0
- package/clients/custom-grpc.client.js +265 -0
- package/clients/custom-grpc.client.js.map +1 -0
- package/commands/generate-sdk.command.d.ts +4 -0
- package/commands/generate-sdk.command.js +28 -0
- package/commands/generate-sdk.command.js.map +1 -0
- package/decorators/grpc-value.decorator.d.ts +1 -0
- package/decorators/grpc-value.decorator.js +12 -0
- package/decorators/grpc-value.decorator.js.map +1 -0
- package/decorators/microservice.decorator.d.ts +2 -0
- package/decorators/microservice.decorator.js +22 -0
- package/decorators/microservice.decorator.js.map +1 -0
- package/decorators/mock.decorator.d.ts +4 -0
- package/decorators/mock.decorator.js +34 -0
- package/decorators/mock.decorator.js.map +1 -0
- package/decorators/property.decorator.d.ts +2 -0
- package/decorators/property.decorator.js +21 -0
- package/decorators/property.decorator.js.map +1 -0
- package/documents/grpc-test.dto.d.ts +6 -0
- package/documents/grpc-test.dto.js +42 -0
- package/documents/grpc-test.dto.js.map +1 -0
- package/documents/microservice-document.controller.d.ts +10 -0
- package/documents/microservice-document.controller.js +59 -0
- package/documents/microservice-document.controller.js.map +1 -0
- package/documents/microservice-document.module.d.ts +5 -0
- package/documents/microservice-document.module.js +60 -0
- package/documents/microservice-document.module.js.map +1 -0
- package/frontend/3rdpartylicenses.txt +393 -0
- package/frontend/assets/config.json +1 -0
- package/frontend/chunk-5FZOKLP6.js +1 -0
- package/frontend/chunk-IKVALLPG.js +9 -0
- package/frontend/favicon.ico +0 -0
- package/frontend/index.html +14 -0
- package/frontend/main-GUJBJU47.js +21 -0
- package/frontend/polyfills-BJX5WH5B.js +2 -0
- package/frontend/styles-GLNRDJWV.css +1 -0
- package/helpers/api-property.helper.d.ts +2 -0
- package/helpers/api-property.helper.js +9 -0
- package/helpers/api-property.helper.js.map +1 -0
- package/helpers/generate.helper.d.ts +3 -0
- package/helpers/generate.helper.js +19 -0
- package/helpers/generate.helper.js.map +1 -0
- package/helpers/mock.helper.d.ts +1 -0
- package/helpers/mock.helper.js +61 -0
- package/helpers/mock.helper.js.map +1 -0
- package/helpers/property.helper.d.ts +8 -0
- package/helpers/property.helper.js +92 -0
- package/helpers/property.helper.js.map +1 -0
- package/helpers/proto-type.helper.d.ts +3 -0
- package/helpers/proto-type.helper.js +36 -0
- package/helpers/proto-type.helper.js.map +1 -0
- package/index.d.ts +11 -0
- package/index.js +28 -0
- package/index.js.map +1 -0
- package/package.json +107 -0
- package/sdk-stub/constants/multi-language-key.constant.d.ts +3 -0
- package/sdk-stub/constants/multi-language-key.constant.js +7 -0
- package/sdk-stub/constants/multi-language-key.constant.js.map +1 -0
- package/sdk-stub/constants/multi-language-key.constant.ts +3 -0
- package/sdk-stub/helpers/grpc.helper.d.ts +25 -0
- package/sdk-stub/helpers/grpc.helper.js +106 -0
- package/sdk-stub/helpers/grpc.helper.js.map +1 -0
- package/sdk-stub/helpers/grpc.helper.ts +129 -0
- package/sdk-stub/types/microservice-option.type.d.ts +12 -0
- package/sdk-stub/types/microservice-option.type.js +3 -0
- package/sdk-stub/types/microservice-option.type.js.map +1 -0
- package/sdk-stub/types/microservice-option.type.ts +13 -0
- package/services/generate-document.service.d.ts +12 -0
- package/services/generate-document.service.js +121 -0
- package/services/generate-document.service.js.map +1 -0
- package/services/generate-microservice.service.d.ts +23 -0
- package/services/generate-microservice.service.js +200 -0
- package/services/generate-microservice.service.js.map +1 -0
- package/services/generate-proto.service.d.ts +12 -0
- package/services/generate-proto.service.js +132 -0
- package/services/generate-proto.service.js.map +1 -0
- package/services/method-template.service.d.ts +5 -0
- package/services/method-template.service.js +50 -0
- package/services/method-template.service.js.map +1 -0
- package/services/mock-method-template.service.d.ts +5 -0
- package/services/mock-method-template.service.js +32 -0
- package/services/mock-method-template.service.js.map +1 -0
- package/services/mock-module-template.service.d.ts +6 -0
- package/services/mock-module-template.service.js +37 -0
- package/services/mock-module-template.service.js.map +1 -0
- package/services/module-template.service.d.ts +6 -0
- package/services/module-template.service.js +60 -0
- package/services/module-template.service.js.map +1 -0
- package/services/service-template.service.d.ts +10 -0
- package/services/service-template.service.js +105 -0
- package/services/service-template.service.js.map +1 -0
- package/storages/microservice.storage.d.ts +1 -0
- package/storages/microservice.storage.js +5 -0
- package/storages/microservice.storage.js.map +1 -0
- package/storages/property.storage.d.ts +3 -0
- package/storages/property.storage.js +6 -0
- package/storages/property.storage.js.map +1 -0
- package/types/document-module-option.type.d.ts +8 -0
- package/types/document-module-option.type.js +3 -0
- package/types/document-module-option.type.js.map +1 -0
- package/types/document.type.d.ts +40 -0
- package/types/document.type.js +3 -0
- package/types/document.type.js.map +1 -0
- package/types/mock-option.type.d.ts +12 -0
- package/types/mock-option.type.js +3 -0
- package/types/mock-option.type.js.map +1 -0
- package/types/property-option.type.d.ts +15 -0
- package/types/property-option.type.js +3 -0
- package/types/property-option.type.js.map +1 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.sample = void 0;
|
|
27
|
+
const property_helper_1 = require("./property.helper");
|
|
28
|
+
const class_transformer_1 = require("class-transformer");
|
|
29
|
+
const faker = __importStar(require("faker"));
|
|
30
|
+
const lodash_1 = require("lodash");
|
|
31
|
+
function getData(option) {
|
|
32
|
+
const { mock } = option;
|
|
33
|
+
if (mock.sample) {
|
|
34
|
+
return mock.sample;
|
|
35
|
+
}
|
|
36
|
+
if (mock.nestedMaxSize) {
|
|
37
|
+
if (option.isArray) {
|
|
38
|
+
return new Array(mock.nestedMaxSize).fill(0).map(() => sample(option.type));
|
|
39
|
+
}
|
|
40
|
+
return sample(option.type);
|
|
41
|
+
}
|
|
42
|
+
if (mock.method && mock.method.startsWith('faker.')) {
|
|
43
|
+
const method = (0, lodash_1.get)({ faker }, mock.method);
|
|
44
|
+
return method(...mock.args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function sample(dto) {
|
|
48
|
+
const data = {};
|
|
49
|
+
const properties = (0, property_helper_1.getPropertiesOfClass)(dto);
|
|
50
|
+
for (const property of properties) {
|
|
51
|
+
if (property.option.mock) {
|
|
52
|
+
data[property.name] = getData(property.option);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
data[property.name] = property.option.example;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return (0, class_transformer_1.plainToInstance)(dto, data);
|
|
59
|
+
}
|
|
60
|
+
exports.sample = sample;
|
|
61
|
+
//# sourceMappingURL=mock.helper.js.map
|
|
@@ -0,0 +1 @@
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C,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAClD,CAAC;IACL,CAAC;IACD,OAAO,IAAA,mCAAe,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAXD,wBAWC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PropertyOptionType, PropertyType } from '@hodfords/nestjs-grpc-helper';
|
|
2
|
+
export declare function getClassHasProperties(): IterableIterator<Function>;
|
|
3
|
+
export declare function addPropertyToStorage(constructor: Function, propertyName: string, option: PropertyOptionType): void;
|
|
4
|
+
export declare function extractProperties(): Record<string, {
|
|
5
|
+
option: PropertyOptionType;
|
|
6
|
+
}[]>;
|
|
7
|
+
export declare function getPropertiesOfClass(constructor: Function, properties?: any[]): PropertyType[];
|
|
8
|
+
export declare function traverseSDKProperties(): Function[];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseSDKProperties = exports.getPropertiesOfClass = exports.extractProperties = exports.addPropertyToStorage = exports.getClassHasProperties = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
+
const property_storage_1 = require("../storages/property.storage");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
function getClassHasProperties() {
|
|
8
|
+
return property_storage_1.propertyStorage.keys();
|
|
9
|
+
}
|
|
10
|
+
exports.getClassHasProperties = getClassHasProperties;
|
|
11
|
+
function addPropertyToStorage(constructor, propertyName, option) {
|
|
12
|
+
if (property_storage_1.propertyStorage.has(constructor)) {
|
|
13
|
+
const properties = property_storage_1.propertyStorage.get(constructor);
|
|
14
|
+
const property = properties.find(({ name }) => name === propertyName);
|
|
15
|
+
if (property) {
|
|
16
|
+
property.option = { ...property.option, ...option };
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
properties.push({
|
|
20
|
+
name: propertyName,
|
|
21
|
+
option
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
property_storage_1.propertyStorage.set(constructor, [
|
|
27
|
+
{
|
|
28
|
+
name: propertyName,
|
|
29
|
+
option
|
|
30
|
+
}
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
if (!option.isAutoGenerated) {
|
|
34
|
+
property_storage_1.sdkDtos.add(constructor);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.addPropertyToStorage = addPropertyToStorage;
|
|
38
|
+
function removeOverridableProperties(validProperties, overridableProperties) {
|
|
39
|
+
return (0, lodash_1.differenceBy)(validProperties, overridableProperties, (item) => item.name);
|
|
40
|
+
}
|
|
41
|
+
function extractProperties() {
|
|
42
|
+
const dtos = traverseSDKProperties();
|
|
43
|
+
const dtoWithProperties = {};
|
|
44
|
+
for (const dto of dtos) {
|
|
45
|
+
const properties = getPropertiesOfClass(dto);
|
|
46
|
+
if (!dtoWithProperties[dto.name]) {
|
|
47
|
+
dtoWithProperties[dto.name] = properties;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const existedProperties = dtoWithProperties[dto.name].map((property) => property.name);
|
|
51
|
+
const newProperties = properties.filter((property) => !existedProperties.includes(property.name));
|
|
52
|
+
const overridableProperties = properties.filter((property) => existedProperties.includes(property.name) && !property.option?.isAutoGenerated);
|
|
53
|
+
const validProperties = removeOverridableProperties(dtoWithProperties[dto.name], overridableProperties);
|
|
54
|
+
dtoWithProperties[dto.name] = validProperties.concat(newProperties).concat(overridableProperties);
|
|
55
|
+
}
|
|
56
|
+
return dtoWithProperties;
|
|
57
|
+
}
|
|
58
|
+
exports.extractProperties = extractProperties;
|
|
59
|
+
function getPropertiesOfClass(constructor, properties = []) {
|
|
60
|
+
if (!property_storage_1.propertyStorage.get(constructor)) {
|
|
61
|
+
return properties;
|
|
62
|
+
}
|
|
63
|
+
properties = properties.concat(property_storage_1.propertyStorage.get(constructor));
|
|
64
|
+
const parentClass = Object.getPrototypeOf(constructor);
|
|
65
|
+
if (parentClass.name) {
|
|
66
|
+
return getPropertiesOfClass(parentClass, properties);
|
|
67
|
+
}
|
|
68
|
+
return properties;
|
|
69
|
+
}
|
|
70
|
+
exports.getPropertiesOfClass = getPropertiesOfClass;
|
|
71
|
+
function traverseSDKProperties() {
|
|
72
|
+
const queue = Array.from(property_storage_1.sdkDtos.keys());
|
|
73
|
+
const auditor = new Set(property_storage_1.sdkDtos);
|
|
74
|
+
const responses = [];
|
|
75
|
+
while (queue.length) {
|
|
76
|
+
const dto = queue.shift();
|
|
77
|
+
const properties = getPropertiesOfClass(dto);
|
|
78
|
+
for (const { option } of properties) {
|
|
79
|
+
if ((0, shared_utils_1.isFunction)(option.type)) {
|
|
80
|
+
const constructor = option.type.name === 'type' ? option.type() : option.type;
|
|
81
|
+
if (!auditor.has(constructor)) {
|
|
82
|
+
queue.push(constructor);
|
|
83
|
+
auditor.add(constructor);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
responses.push(dto);
|
|
88
|
+
}
|
|
89
|
+
return responses.reverse();
|
|
90
|
+
}
|
|
91
|
+
exports.traverseSDKProperties = traverseSDKProperties;
|
|
92
|
+
//# sourceMappingURL=property.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.helper.js","sourceRoot":"","sources":["../../../libs/helpers/property.helper.ts"],"names":[],"mappings":";;;AAAA,oEAA+D;AAC/D,mEAAwE;AAExE,mCAAsC;AAEtC,SAAgB,qBAAqB;IACjC,OAAO,kCAAe,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC;AAFD,sDAEC;AAED,SAAgB,oBAAoB,CAAC,WAAqB,EAAE,YAAoB,EAAE,MAA0B;IACxG,IAAI,kCAAe,CAAC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AW,EAAE,UAAU,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,UAAU,CAAC;AACtB,CAAC;AAVD,oDAUC;AAED,SAAgB,qBAAqB;IACjC,MAAM,KAAK,GAAe,KAAK,CAAC,IAAI,CAAC,0BAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,0BAAO,CAAC,CAAC;IACjC,MAAM,SAAS,GAAe,EAAE,CAAC;IAEjC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,UAAU,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC7C,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;YAClC,IAAI,IAAA,yBAAU,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC9E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;oBAC5B,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;oBACxB,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAC7B,CAAC;YACL,CAAC;QACL,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,SAAS,CAAC,OAAO,EAAE,CAAC;AAC/B,CAAC;AArBD,sDAqBC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ApiPropertyOptions } from '@nestjs/swagger/dist/decorators/api-property.decorator';
|
|
2
|
+
export declare function convertProtoTypeToSwagger(option: ApiPropertyOptions): ApiPropertyOptions['type'];
|
|
3
|
+
export declare function convertProtoTypeToTypescript(option: ApiPropertyOptions, isGenerate?: boolean): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertProtoTypeToTypescript = exports.convertProtoTypeToSwagger = void 0;
|
|
4
|
+
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
5
|
+
const api_property_helper_1 = require("./api-property.helper");
|
|
6
|
+
function convertProtoTypeToSwagger(option) {
|
|
7
|
+
if ((0, shared_utils_1.isFunction)(option.type)) {
|
|
8
|
+
return option.type;
|
|
9
|
+
}
|
|
10
|
+
return convertProtoTypeToTypescript(option, false);
|
|
11
|
+
}
|
|
12
|
+
exports.convertProtoTypeToSwagger = convertProtoTypeToSwagger;
|
|
13
|
+
function convertProtoTypeToTypescript(option, isGenerate) {
|
|
14
|
+
let type = option.type;
|
|
15
|
+
if ((0, shared_utils_1.isFunction)(type)) {
|
|
16
|
+
if (type.name === 'type' && isGenerate) {
|
|
17
|
+
return option.type().name;
|
|
18
|
+
}
|
|
19
|
+
return type.name;
|
|
20
|
+
}
|
|
21
|
+
if ((0, api_property_helper_1.isEnumProperty)(option)) {
|
|
22
|
+
return option.enumName;
|
|
23
|
+
}
|
|
24
|
+
if ((0, shared_utils_1.isString)(option.type)) {
|
|
25
|
+
const numberTypes = ['int32', 'fixed32', 'uint32', 'int64', 'fixed64', 'uint64', 'float', 'double', 'float'];
|
|
26
|
+
if (numberTypes.includes(option.type)) {
|
|
27
|
+
type = 'number';
|
|
28
|
+
}
|
|
29
|
+
if (option.type == 'bool') {
|
|
30
|
+
type = 'boolean';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return type.toString();
|
|
34
|
+
}
|
|
35
|
+
exports.convertProtoTypeToTypescript = convertProtoTypeToTypescript;
|
|
36
|
+
//# sourceMappingURL=proto-type.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pro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Q,EAAE,CAAC;AAC3B,CAAC;AAzBD,oEAyBC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './decorators/microservice.decorator';
|
|
2
|
+
export * from './decorators/property.decorator';
|
|
3
|
+
export * from './decorators/mock.decorator';
|
|
4
|
+
export * from './decorators/grpc-value.decorator';
|
|
5
|
+
export * from './helpers/generate.helper';
|
|
6
|
+
export * from './helpers/mock.helper';
|
|
7
|
+
export * from './types/property-option.type';
|
|
8
|
+
export * from './sdk-stub/helpers/grpc.helper';
|
|
9
|
+
export * from './documents/microservice-document.module';
|
|
10
|
+
export * from './clients/custom-grpc.client';
|
|
11
|
+
export * from './helpers/property.helper';
|
package/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decorators/microservice.decorator"), exports);
|
|
18
|
+
__exportStar(require("./decorators/property.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/mock.decorator"), exports);
|
|
20
|
+
__exportStar(require("./decorators/grpc-value.decorator"), exports);
|
|
21
|
+
__exportStar(require("./helpers/generate.helper"), exports);
|
|
22
|
+
__exportStar(require("./helpers/mock.helper"), exports);
|
|
23
|
+
__exportStar(require("./types/property-option.type"), exports);
|
|
24
|
+
__exportStar(require("./sdk-stub/helpers/grpc.helper"), exports);
|
|
25
|
+
__exportStar(require("./documents/microservice-document.module"), exports);
|
|
26
|
+
__exportStar(require("./clients/custom-grpc.client"), exports);
|
|
27
|
+
__exportStar(require("./helpers/property.helper"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../libs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,kEAAgD;AAChD,8DAA4C;AAC5C,oEAAkD;AAClD,4DAA0C;AAC1C,wDAAsC;AACtC,+DAA6C;AAC7C,iEAA+C;AAC/C,2EAAyD;AACzD,+DAA6C;AAC7C,4DAA0C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hodfords/nestjs-grpc-helper",
|
|
3
|
+
"version": "10.0.0-rc.1",
|
|
4
|
+
"description": "Grpc helper for nestjs",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/hodfords-solutions/nestjs-grpc-helper.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"prebuild": "rimraf dist",
|
|
13
|
+
"build": "nest build",
|
|
14
|
+
"format": "prettier --write \"src/**/*.ts\" \"libs/**/*.ts\"",
|
|
15
|
+
"start": "nest start",
|
|
16
|
+
"start:dev": "npm run prebuild && nest start --watch",
|
|
17
|
+
"start:debug": "nest start --debug --watch",
|
|
18
|
+
"start:prod": "node dist/main",
|
|
19
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
20
|
+
"test": "jest",
|
|
21
|
+
"test:watch": "jest --watch",
|
|
22
|
+
"test:cov": "jest --coverage",
|
|
23
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
24
|
+
"test:e2e": "jest --config ./test/jest-e2e.json",
|
|
25
|
+
"wz-command": "wz-command",
|
|
26
|
+
"prepare": "is-ci || husky install",
|
|
27
|
+
"version": "auto-changelog && git add CHANGELOG.md",
|
|
28
|
+
"release:patch": "git add CHANGELOG.md && npm version patch --tag-version-prefix='' -f -m 'chore: release to %s'",
|
|
29
|
+
"release:push": "git push --no-verify && git push --tags --no-verify",
|
|
30
|
+
"build-sdk": "nestjs-grpc-helper",
|
|
31
|
+
"cspell": "cspell",
|
|
32
|
+
"lint-staged": "lint-staged"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@hodfords/nestjs-cls-translation": "10.0.0",
|
|
36
|
+
"@hodfords/nestjs-command": "10.0.0",
|
|
37
|
+
"@hodfords/nestjs-response": "10.0.0",
|
|
38
|
+
"@grpc/grpc-js": "1.9.14",
|
|
39
|
+
"@grpc/proto-loader": "0.7.10",
|
|
40
|
+
"@nestjs/cli": "10.3.2",
|
|
41
|
+
"@nestjs/common": "10.3.3",
|
|
42
|
+
"@nestjs/core": "10.3.3",
|
|
43
|
+
"@nestjs/microservices": "10.3.3",
|
|
44
|
+
"@nestjs/platform-express": "10.3.3",
|
|
45
|
+
"@nestjs/schematics": "10.1.1",
|
|
46
|
+
"@nestjs/serve-static": "4.0.1",
|
|
47
|
+
"@nestjs/swagger": "7.3.0",
|
|
48
|
+
"@nestjs/testing": "10.3.3",
|
|
49
|
+
"@nestjs/typeorm": "10.0.2",
|
|
50
|
+
"@types/express": "4.17.21",
|
|
51
|
+
"@types/faker": "5.5.9",
|
|
52
|
+
"@types/jest": "29.5.12",
|
|
53
|
+
"@types/lodash": "4.14.202",
|
|
54
|
+
"@types/node": "20.11.19",
|
|
55
|
+
"@types/supertest": "6.0.2",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "7.0.1",
|
|
57
|
+
"@typescript-eslint/parser": "7.0.1",
|
|
58
|
+
"auto-changelog": "2.4.0",
|
|
59
|
+
"class-transformer": "0.5.1",
|
|
60
|
+
"class-validator": "0.14.0",
|
|
61
|
+
"cspell": "8.4.0",
|
|
62
|
+
"eslint": "8.56.0",
|
|
63
|
+
"eslint-config-prettier": "9.1.0",
|
|
64
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
65
|
+
"faker": "5.5.3",
|
|
66
|
+
"husky": "9.0.11",
|
|
67
|
+
"is-ci": "3.0.1",
|
|
68
|
+
"jest": "29.7.0",
|
|
69
|
+
"lint-staged": "15.2.2",
|
|
70
|
+
"lodash": "4.17.21",
|
|
71
|
+
"reflect-metadata": "0.2.1",
|
|
72
|
+
"rimraf": "5.0.5",
|
|
73
|
+
"rxjs": "7.8.1",
|
|
74
|
+
"source-map-support": "0.5.21",
|
|
75
|
+
"supertest": "6.3.4",
|
|
76
|
+
"ts-jest": "29.1.2",
|
|
77
|
+
"ts-loader": "9.5.1",
|
|
78
|
+
"ts-node": "10.9.2",
|
|
79
|
+
"tsconfig-paths": "4.2.0",
|
|
80
|
+
"typeorm": "0.3.19",
|
|
81
|
+
"typescript": "5.3.3"
|
|
82
|
+
},
|
|
83
|
+
"jest": {
|
|
84
|
+
"moduleFileExtensions": [
|
|
85
|
+
"js",
|
|
86
|
+
"json",
|
|
87
|
+
"ts"
|
|
88
|
+
],
|
|
89
|
+
"rootDir": ".",
|
|
90
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
91
|
+
"transform": {
|
|
92
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
93
|
+
},
|
|
94
|
+
"collectCoverageFrom": [
|
|
95
|
+
"**/*.(t|j)s"
|
|
96
|
+
],
|
|
97
|
+
"coverageDirectory": "./coverage",
|
|
98
|
+
"testEnvironment": "node",
|
|
99
|
+
"roots": [
|
|
100
|
+
"<rootDir>/src/",
|
|
101
|
+
"<rootDir>/libs/"
|
|
102
|
+
],
|
|
103
|
+
"moduleNameMapper": {
|
|
104
|
+
"^@hodfords/nestjs-grpc-helper(|/.*)$": "<rootDir>/libs/nestjs-grpc-helper/src/$1"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLATFORM_LANGUAGE_KEY = exports.REPORT_LANGUAGE_KEY = exports.COMMUNICATION_LANGUAGE = void 0;
|
|
4
|
+
exports.COMMUNICATION_LANGUAGE = 'communication-language';
|
|
5
|
+
exports.REPORT_LANGUAGE_KEY = 'report-language';
|
|
6
|
+
exports.PLATFORM_LANGUAGE_KEY = 'platform-language';
|
|
7
|
+
//# sourceMappingURL=multi-language-key.constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-language-key.constant.js","sourceRoot":"","sources":["../../../../libs/sdk-stub/constants/multi-language-key.constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAClD,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AACxC,QAAA,qBAAqB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ClientGrpc } from '@nestjs/microservices';
|
|
2
|
+
import { MicroserviceClientOptionType } from '../types/microservice-option.type';
|
|
3
|
+
export declare class GrpcHelper<Model> {
|
|
4
|
+
private client;
|
|
5
|
+
private model;
|
|
6
|
+
private options;
|
|
7
|
+
private serviceGrpc;
|
|
8
|
+
private methodName;
|
|
9
|
+
private payload;
|
|
10
|
+
private metadata;
|
|
11
|
+
static with<Model>(client: ClientGrpc, model: {
|
|
12
|
+
new (): Model;
|
|
13
|
+
}, options: MicroserviceClientOptionType): GrpcHelper<Model>;
|
|
14
|
+
private constructor();
|
|
15
|
+
private currentPriorityLanguage;
|
|
16
|
+
private appendLanguages;
|
|
17
|
+
service(name: string): GrpcHelper<Model>;
|
|
18
|
+
method(name: string): GrpcHelper<Model>;
|
|
19
|
+
data(data: any): GrpcHelper<Model>;
|
|
20
|
+
getOne(): Promise<Model>;
|
|
21
|
+
getMany(): Promise<Model[]>;
|
|
22
|
+
private execute;
|
|
23
|
+
private toPromise;
|
|
24
|
+
private handelError;
|
|
25
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GrpcHelper = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
|
+
const nestjs_cls_translation_1 = require("@hodfords/nestjs-cls-translation");
|
|
8
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
9
|
+
const multi_language_key_constant_1 = require("../constants/multi-language-key.constant");
|
|
10
|
+
class GrpcHelper {
|
|
11
|
+
static with(client, model, options) {
|
|
12
|
+
return new GrpcHelper(client, model, options);
|
|
13
|
+
}
|
|
14
|
+
constructor(client, model, options) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.model = model;
|
|
17
|
+
this.options = options;
|
|
18
|
+
this.metadata = new grpc_js_1.Metadata();
|
|
19
|
+
if (this.options.enableLanguageMetaData) {
|
|
20
|
+
this.appendLanguages();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
currentPriorityLanguage(key = multi_language_key_constant_1.REPORT_LANGUAGE_KEY) {
|
|
24
|
+
return nestjs_cls_translation_1.CLS_TRANSLATION_NAMESPACE.get(key);
|
|
25
|
+
}
|
|
26
|
+
appendLanguages() {
|
|
27
|
+
const platformLanguage = (0, nestjs_cls_translation_1.currentLanguage)();
|
|
28
|
+
const reportLanguage = this.currentPriorityLanguage();
|
|
29
|
+
const communicationLanguage = (0, nestjs_cls_translation_1.getLanguageByKey)(multi_language_key_constant_1.COMMUNICATION_LANGUAGE);
|
|
30
|
+
if (platformLanguage) {
|
|
31
|
+
this.metadata.add(multi_language_key_constant_1.PLATFORM_LANGUAGE_KEY, platformLanguage);
|
|
32
|
+
}
|
|
33
|
+
if (reportLanguage) {
|
|
34
|
+
this.metadata.add(multi_language_key_constant_1.REPORT_LANGUAGE_KEY, reportLanguage);
|
|
35
|
+
}
|
|
36
|
+
if (communicationLanguage) {
|
|
37
|
+
this.metadata.add(multi_language_key_constant_1.COMMUNICATION_LANGUAGE, communicationLanguage);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
service(name) {
|
|
41
|
+
this.serviceGrpc = this.client.getService(name);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
method(name) {
|
|
45
|
+
this.methodName = name;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
data(data) {
|
|
49
|
+
this.payload = data;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
async getOne() {
|
|
53
|
+
const data = await this.getMany();
|
|
54
|
+
return data[0];
|
|
55
|
+
}
|
|
56
|
+
async getMany() {
|
|
57
|
+
try {
|
|
58
|
+
let data = await this.execute();
|
|
59
|
+
if (data.grpcArray) {
|
|
60
|
+
data = data.items || [];
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(data)) {
|
|
63
|
+
return (0, class_transformer_1.plainToInstance)(this.model, data);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return [(0, class_transformer_1.plainToInstance)(this.model, data)];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (exception) {
|
|
70
|
+
console.log(this.methodName, exception);
|
|
71
|
+
throw exception;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async execute() {
|
|
75
|
+
const handler = () => this.toPromise(this.serviceGrpc[this.methodName](this.payload, this.metadata).pipe((0, rxjs_1.timeout)(this.options.timeout)));
|
|
76
|
+
return handler();
|
|
77
|
+
}
|
|
78
|
+
async toPromise(observe) {
|
|
79
|
+
try {
|
|
80
|
+
return await (0, rxjs_1.firstValueFrom)(observe);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.handelError(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
handelError(error) {
|
|
87
|
+
if (error.code) {
|
|
88
|
+
if (error.code == grpc_js_1.status.ABORTED) {
|
|
89
|
+
const responseError = JSON.parse(error.details);
|
|
90
|
+
const httpError = new common_1.HttpException(responseError.message, responseError.code);
|
|
91
|
+
httpError['response'] = responseError.errors;
|
|
92
|
+
httpError.message = responseError.message;
|
|
93
|
+
throw httpError;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.error(error);
|
|
97
|
+
throw new common_1.HttpException((0, nestjs_cls_translation_1.trans)('error.an_error_occurred'), common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.GrpcHelper = GrpcHelper;
|
|
106
|
+
//# sourceMappingURL=grpc.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc.helper.js","sourceRoot":"","sources":["../../../../libs/sdk-stub/helpers/grpc.helper.ts"],"names":[],"mappings":";;;AACA,+BAA2D;AAC3D,2CAA2D;AAC3D,yDAAoD;AACpD,6EAAuH;AACvH,2CAAiD;AAEjD,0FAIkD;AAElD,MAAa,UAAU;IAMnB,MAAM,CAAC,IAAI,CACP,MAAkB,EAClB,KAAwB,EACxB,OAAqC;QAErC,OAAO,IAAI,UAAU,CAAQ,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,YACY,MAAkB,EAClB,KAAwB,EACxB,OAAqC;QAFrC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