@shmidko61/cinema-contracts 1.1.2 → 1.2.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.
@@ -0,0 +1 @@
1
+ export declare const GRPC_CLIENT_PREFIX = "GRPC_CLIENT";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRPC_CLIENT_PREFIX = void 0;
4
+ exports.GRPC_CLIENT_PREFIX = "GRPC_CLIENT";
@@ -0,0 +1 @@
1
+ export * from "./inject-grpc-client.decorator";
@@ -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("./inject-grpc-client.decorator"), exports);
@@ -0,0 +1 @@
1
+ export declare const InjectGrpcClient: (name: string) => PropertyDecorator & ParameterDecorator;
@@ -0,0 +1,9 @@
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("../constants/grpc-constants");
6
+ const InjectGrpcClient = (name) => {
7
+ return (0, common_1.Inject)(`${grpc_constants_1.GRPC_CLIENT_PREFIX}_${name}`);
8
+ };
9
+ exports.InjectGrpcClient = InjectGrpcClient;
@@ -0,0 +1,11 @@
1
+ import { ClientGrpc } from "@nestjs/microservices";
2
+ export declare class GrpcClientFactory {
3
+ private clients;
4
+ createClient(options: {
5
+ package: string;
6
+ protoPath: string;
7
+ url: string;
8
+ }): ClientGrpc;
9
+ register(token: string, client: ClientGrpc): void;
10
+ getClient<T extends ClientGrpc = ClientGrpc>(token: string): T;
11
+ }
@@ -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(`Client does not exist: ${token}`);
68
+ }
69
+ return client;
70
+ }
71
+ };
72
+ return GrpcClientFactory = _classThis;
73
+ })();
74
+ exports.GrpcClientFactory = GrpcClientFactory;
@@ -0,0 +1 @@
1
+ export * from "./grpc-client.factory";
@@ -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("./grpc-client.factory"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./registry";
2
+ export * from "./factory";
3
+ export * from "./decorators";
4
+ export * from "./module";
@@ -0,0 +1,20 @@
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("./registry"), exports);
18
+ __exportStar(require("./factory"), exports);
19
+ __exportStar(require("./decorators"), exports);
20
+ __exportStar(require("./module"), exports);
@@ -0,0 +1,11 @@
1
+ import { type DynamicModule } from "@nestjs/common";
2
+ import { GRPC_CLIENTS } from "../registry";
3
+ export declare class GrpcModule {
4
+ /**
5
+ * Регистрирует gRPC-клиенты динамически.
6
+ *
7
+ * @param clients список ключей из GRPC_CLIENTS,
8
+ * например: ['USERS_PACKAGE', 'AUTH_PACKAGE']
9
+ */
10
+ static register(clients: Array<keyof typeof GRPC_CLIENTS>): DynamicModule;
11
+ }
@@ -0,0 +1,117 @@
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 config_1 = require("@nestjs/config");
40
+ const registry_1 = require("../registry");
41
+ const factory_1 = require("../factory");
42
+ const grpc_constants_1 = require("../constants/grpc-constants");
43
+ let GrpcModule = (() => {
44
+ let _classDecorators = [(0, common_1.Module)({})];
45
+ let _classDescriptor;
46
+ let _classExtraInitializers = [];
47
+ let _classThis;
48
+ var GrpcModule = class {
49
+ static { _classThis = this; }
50
+ static {
51
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
52
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
53
+ GrpcModule = _classThis = _classDescriptor.value;
54
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
+ __runInitializers(_classThis, _classExtraInitializers);
56
+ }
57
+ /**
58
+ * Регистрирует gRPC-клиенты динамически.
59
+ *
60
+ * @param clients список ключей из GRPC_CLIENTS,
61
+ * например: ['USERS_PACKAGE', 'AUTH_PACKAGE']
62
+ */
63
+ static register(clients) {
64
+ return {
65
+ // Указываем Nest, что это динамическая конфигурация GrpcModule
66
+ module: GrpcModule,
67
+ // Providers формируются динамически на основе списка clients
68
+ providers: [
69
+ // Фабрика создаётся как singleton и используется
70
+ // для создания и регистрации gRPC-клиентов
71
+ factory_1.GrpcClientFactory,
72
+ // Для каждого клиента из списка создаём отдельный provider
73
+ ...clients.map((token) => {
74
+ // Берём конфигурацию клиента из реестра
75
+ const config = registry_1.GRPC_CLIENTS[token];
76
+ return {
77
+ // Формируем уникальный DI-токен клиента
78
+ // Пример: GRPC_CLIENT_USERS_PACKAGE
79
+ provide: `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`,
80
+ /**
81
+ * Фабрика создания gRPC-клиента
82
+ *
83
+ * factory — GrpcClientFactory (создаёт ClientGrpc)
84
+ * configService — доступ к env / конфигу приложения
85
+ */
86
+ useFactory: (factory, configService) => {
87
+ // Получаем URL gRPC-сервиса из env
88
+ // Если переменная не определена — приложение не стартует
89
+ const url = configService.getOrThrow(config.env);
90
+ // Создаём gRPC-клиент на основе конфигурации
91
+ const client = factory.createClient({
92
+ url,
93
+ package: config.package,
94
+ protoPath: config.protoPath,
95
+ });
96
+ // Регистрируем клиента во внутреннем реестре фабрики
97
+ // (может использоваться для кеширования или доступа по ключу)
98
+ factory.register(token, client);
99
+ // Возвращаем клиента — он будет доступен через DI
100
+ return client;
101
+ },
102
+ inject: [factory_1.GrpcClientFactory, config_1.ConfigService],
103
+ };
104
+ }),
105
+ ],
106
+ exports: [
107
+ factory_1.GrpcClientFactory,
108
+ ...clients.map((token) => {
109
+ return `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`;
110
+ }),
111
+ ],
112
+ };
113
+ }
114
+ };
115
+ return GrpcModule = _classThis;
116
+ })();
117
+ exports.GrpcModule = GrpcModule;
@@ -0,0 +1 @@
1
+ export * from "./grpc.module";
@@ -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("./grpc.module"), exports);
@@ -0,0 +1,17 @@
1
+ export declare const GRPC_CLIENTS: {
2
+ readonly AUTH_PACKAGE: {
3
+ readonly package: "auth.v1";
4
+ readonly protoPath: string;
5
+ readonly env: "AUTH_GRPC_URL";
6
+ };
7
+ readonly ACCOUNT_PACKAGE: {
8
+ readonly package: "account.v1";
9
+ readonly protoPath: string;
10
+ readonly env: "ACCOUNT_GRPC_URL";
11
+ };
12
+ readonly USERS_PACKAGE: {
13
+ readonly package: "users.v1";
14
+ readonly protoPath: string;
15
+ readonly env: "USERS_GRPC_URL";
16
+ };
17
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRPC_CLIENTS = void 0;
4
+ const proto_1 = require("../../proto");
5
+ exports.GRPC_CLIENTS = {
6
+ AUTH_PACKAGE: {
7
+ package: "auth.v1",
8
+ protoPath: proto_1.PROTO_PATHS.AUTH,
9
+ env: "AUTH_GRPC_URL",
10
+ },
11
+ ACCOUNT_PACKAGE: {
12
+ package: "account.v1",
13
+ protoPath: proto_1.PROTO_PATHS.ACCOUNT,
14
+ env: "ACCOUNT_GRPC_URL",
15
+ },
16
+ USERS_PACKAGE: {
17
+ package: "users.v1",
18
+ protoPath: proto_1.PROTO_PATHS.USERS,
19
+ env: "USERS_GRPC_URL",
20
+ },
21
+ };
@@ -0,0 +1 @@
1
+ export * from "./grpc.registry";
@@ -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("./grpc.registry"), exports);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./proto";
2
2
  export * from "./events";
3
3
  export * from "./enum";
4
+ export * from "./grpc";
package/dist/index.js CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./proto"), exports);
18
18
  __exportStar(require("./events"), exports);
19
19
  __exportStar(require("./enum"), exports);
20
+ __exportStar(require("./grpc"), exports);
package/gen/users.ts CHANGED
@@ -26,6 +26,15 @@ export interface CreateUserResponse {
26
26
  ok: boolean;
27
27
  }
28
28
 
29
+ export interface PatchUserRequest {
30
+ userId: string;
31
+ name?: string | undefined;
32
+ }
33
+
34
+ export interface PatchUserResponse {
35
+ ok: boolean;
36
+ }
37
+
29
38
  export interface User {
30
39
  id: string;
31
40
  name?: string | undefined;
@@ -40,6 +49,8 @@ export interface UsersServiceClient {
40
49
  getMe(request: GetMeRequest): Observable<GetMeResponse>;
41
50
 
42
51
  createUser(request: CreateUserRequest): Observable<CreateUserResponse>;
52
+
53
+ patchUser(request: PatchUserRequest): Observable<PatchUserResponse>;
43
54
  }
44
55
 
45
56
  export interface UsersServiceController {
@@ -48,11 +59,13 @@ export interface UsersServiceController {
48
59
  createUser(
49
60
  request: CreateUserRequest,
50
61
  ): Promise<CreateUserResponse> | Observable<CreateUserResponse> | CreateUserResponse;
62
+
63
+ patchUser(request: PatchUserRequest): Promise<PatchUserResponse> | Observable<PatchUserResponse> | PatchUserResponse;
51
64
  }
52
65
 
53
66
  export function UsersServiceControllerMethods() {
54
67
  return function (constructor: Function) {
55
- const grpcMethods: string[] = ["getMe", "createUser"];
68
+ const grpcMethods: string[] = ["getMe", "createUser", "patchUser"];
56
69
  for (const method of grpcMethods) {
57
70
  const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
58
71
  GrpcMethod("UsersService", method)(constructor.prototype[method], method, descriptor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shmidko61/cinema-contracts",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Protobuf definitions and generated TS files",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,7 +8,6 @@
8
8
  "build": "tsc -p tsconfig.build.json",
9
9
  "generate": "protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen --ts_proto_opt=nestJs=true,package=omit"
10
10
  },
11
-
12
11
  "files": [
13
12
  "dist",
14
13
  "proto",
@@ -23,7 +22,9 @@
23
22
  "access": "public"
24
23
  },
25
24
  "dependencies": {
26
- "@nestjs/microservices": "^11.1.11",
25
+ "@nestjs/common": "^11.1.12",
26
+ "@nestjs/config": "^4.0.2",
27
+ "@nestjs/microservices": "^11.1.12",
27
28
  "rxjs": "^7.8.2"
28
29
  }
29
30
  }
package/proto/users.proto CHANGED
@@ -5,6 +5,7 @@ package users.v1;
5
5
  service UsersService {
6
6
  rpc GetMe (GetMeRequest) returns (GetMeResponse);
7
7
  rpc CreateUser (CreateUserRequest) returns (CreateUserResponse);
8
+ rpc PatchUser (PatchUserRequest) returns (PatchUserResponse);
8
9
  }
9
10
 
10
11
  message GetMeRequest {
@@ -21,6 +22,13 @@ message CreateUserRequest {
21
22
  message CreateUserResponse {
22
23
  bool ok = 1;
23
24
  }
25
+ message PatchUserRequest {
26
+ string user_id = 1;
27
+ optional string name = 2;
28
+ }
29
+ message PatchUserResponse {
30
+ bool ok = 1;
31
+ }
24
32
 
25
33
  message User {
26
34
  string id = 1;