@tcinema-pro/common 1.0.1 → 1.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/common/convert-enum.d.ts +1 -0
- package/dist/common/convert-enum.js +7 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +17 -0
- package/dist/grpc/grpc.constants.d.ts +1 -0
- package/dist/grpc/grpc.constants.js +4 -0
- package/dist/grpc/grpc.factory.d.ts +13 -0
- package/dist/grpc/grpc.factory.js +74 -0
- package/dist/grpc/grpc.module.d.ts +5 -0
- package/dist/grpc/grpc.module.js +87 -0
- package/dist/grpc/grpc.registry.d.ts +17 -0
- package/dist/grpc/grpc.registry.js +21 -0
- package/dist/grpc/index.d.ts +2 -0
- package/dist/grpc/index.js +18 -0
- package/dist/grpc/inject-grpc-client.decorator.d.ts +1 -0
- package/dist/grpc/inject-grpc-client.decorator.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +6 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertEnum: <T extends Object>(target: T, value: string) => [keyof T];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './convert-enum';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./convert-enum"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GRPC_CLIENT_PREFIX = "GRPC_CLIENT";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ClientGrpc } from '@nestjs/microservices';
|
|
2
|
+
interface ClientOptions {
|
|
3
|
+
protoPath: string;
|
|
4
|
+
package: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class GrpcClientFactory {
|
|
8
|
+
private clients;
|
|
9
|
+
createClient(options: ClientOptions): import("@nestjs/microservices").ClientGrpcProxy;
|
|
10
|
+
register(token: string, client: ClientGrpc): void;
|
|
11
|
+
getClient<T extends ClientGrpc = ClientGrpc>(token: string): T;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.GrpcClientFactory = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
40
|
+
let GrpcClientFactory = (() => {
|
|
41
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
42
|
+
let _classDescriptor;
|
|
43
|
+
let _classExtraInitializers = [];
|
|
44
|
+
let _classThis;
|
|
45
|
+
var GrpcClientFactory = class {
|
|
46
|
+
static { _classThis = this; }
|
|
47
|
+
static {
|
|
48
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
49
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
50
|
+
GrpcClientFactory = _classThis = _classDescriptor.value;
|
|
51
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
52
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
53
|
+
}
|
|
54
|
+
clients = new Map();
|
|
55
|
+
createClient(options) {
|
|
56
|
+
return microservices_1.ClientProxyFactory.create({
|
|
57
|
+
transport: microservices_1.Transport.GRPC,
|
|
58
|
+
options,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
register(token, client) {
|
|
62
|
+
this.clients.set(token, client);
|
|
63
|
+
}
|
|
64
|
+
getClient(token) {
|
|
65
|
+
const client = this.clients.get(token);
|
|
66
|
+
if (!client) {
|
|
67
|
+
throw new Error('Such client not found');
|
|
68
|
+
}
|
|
69
|
+
return client;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return GrpcClientFactory = _classThis;
|
|
73
|
+
})();
|
|
74
|
+
exports.GrpcClientFactory = GrpcClientFactory;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.GrpcModule = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
const grpc_registry_1 = require("./grpc.registry");
|
|
40
|
+
const grpc_factory_1 = require("./grpc.factory");
|
|
41
|
+
const grpc_constants_1 = require("./grpc.constants");
|
|
42
|
+
let GrpcModule = (() => {
|
|
43
|
+
let _classDecorators = [(0, common_1.Module)({})];
|
|
44
|
+
let _classDescriptor;
|
|
45
|
+
let _classExtraInitializers = [];
|
|
46
|
+
let _classThis;
|
|
47
|
+
var GrpcModule = class {
|
|
48
|
+
static { _classThis = this; }
|
|
49
|
+
static {
|
|
50
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
51
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
52
|
+
GrpcModule = _classThis = _classDescriptor.value;
|
|
53
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
54
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
55
|
+
}
|
|
56
|
+
static register(clientNames) {
|
|
57
|
+
return {
|
|
58
|
+
module: GrpcModule,
|
|
59
|
+
providers: [
|
|
60
|
+
grpc_factory_1.GrpcClientFactory,
|
|
61
|
+
...clientNames.map((token) => {
|
|
62
|
+
const cfg = grpc_registry_1.grpcRegistry[token];
|
|
63
|
+
return {
|
|
64
|
+
provide: `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`,
|
|
65
|
+
useFactory: (factory) => {
|
|
66
|
+
const client = factory.createClient({
|
|
67
|
+
package: cfg.package,
|
|
68
|
+
protoPath: cfg.protoPath,
|
|
69
|
+
url: cfg.url,
|
|
70
|
+
});
|
|
71
|
+
factory.register(`${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`, client);
|
|
72
|
+
return client;
|
|
73
|
+
},
|
|
74
|
+
inject: [grpc_factory_1.GrpcClientFactory],
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
exports: [
|
|
79
|
+
grpc_factory_1.GrpcClientFactory,
|
|
80
|
+
...clientNames.map((item) => `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${item}`),
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return GrpcModule = _classThis;
|
|
86
|
+
})();
|
|
87
|
+
exports.GrpcModule = GrpcModule;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const grpcRegistry: {
|
|
2
|
+
ACCOUNT_PACKAGE: {
|
|
3
|
+
package: string;
|
|
4
|
+
protoPath: string;
|
|
5
|
+
url: string;
|
|
6
|
+
};
|
|
7
|
+
AUTH_PACKAGE: {
|
|
8
|
+
package: string;
|
|
9
|
+
protoPath: string;
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
USERS_PACKAGE: {
|
|
13
|
+
package: string;
|
|
14
|
+
protoPath: string;
|
|
15
|
+
url: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grpcRegistry = void 0;
|
|
4
|
+
const contracts_1 = require("@tcinema-pro/contracts");
|
|
5
|
+
exports.grpcRegistry = {
|
|
6
|
+
ACCOUNT_PACKAGE: {
|
|
7
|
+
package: 'account.v1',
|
|
8
|
+
protoPath: contracts_1.PROTO_PATHS.ACCOUNT,
|
|
9
|
+
url: 'localhost:50051',
|
|
10
|
+
},
|
|
11
|
+
AUTH_PACKAGE: {
|
|
12
|
+
package: 'auth.v1',
|
|
13
|
+
protoPath: contracts_1.PROTO_PATHS.AUTH,
|
|
14
|
+
url: 'localhost:50051',
|
|
15
|
+
},
|
|
16
|
+
USERS_PACKAGE: {
|
|
17
|
+
package: 'users.v1',
|
|
18
|
+
protoPath: contracts_1.PROTO_PATHS.USERS,
|
|
19
|
+
url: 'localhost:50052',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./grpc.module"), exports);
|
|
18
|
+
__exportStar(require("./inject-grpc-client.decorator"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const InjectGrpcClient: (name: string) => PropertyDecorator & ParameterDecorator;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectGrpcClient = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const grpc_constants_1 = require("./grpc.constants");
|
|
6
|
+
const InjectGrpcClient = (name) => (0, common_1.Inject)(`${grpc_constants_1.GRPC_CLIENT_PREFIX}_${name}`);
|
|
7
|
+
exports.InjectGrpcClient = InjectGrpcClient;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./enums"), exports);
|
|
18
|
+
__exportStar(require("./common"), exports);
|
|
19
|
+
__exportStar(require("./grpc"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tcinema-pro/common",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Common core shared components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,5 +23,10 @@
|
|
|
23
23
|
"@types/node": "^25.3.0",
|
|
24
24
|
"prettier": "^3.8.1",
|
|
25
25
|
"typescript": "^5.9.3"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@nestjs/common": "^11.1.16",
|
|
29
|
+
"@nestjs/microservices": "^11.1.16",
|
|
30
|
+
"@tcinema-pro/contracts": "^1.2.2"
|
|
26
31
|
}
|
|
27
32
|
}
|