@shock-cinema/contracts 1.0.1 → 1.0.3

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/gen/test.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
2
  // versions:
3
3
  // protoc-gen-ts_proto v2.10.1
4
- // protoc v6.33.2
4
+ // protoc v6.33.1
5
5
  // source: test.proto
6
6
 
7
7
  /* eslint-disable */
8
- import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
8
+ import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
9
+ import { Observable } from "rxjs";
9
10
  import { Duration } from "./google/protobuf/duration";
10
11
  import { Empty } from "./google/protobuf/empty";
11
12
  import { Timestamp } from "./google/protobuf/timestamp";
@@ -19,44 +20,12 @@ export enum Status {
19
20
  UNRECOGNIZED = -1,
20
21
  }
21
22
 
22
- export function statusFromJSON(object: any): Status {
23
- switch (object) {
24
- case 0:
25
- case "STATUS_UNKNOWN":
26
- return Status.STATUS_UNKNOWN;
27
- case 1:
28
- case "STATUS_ACTIVE":
29
- return Status.STATUS_ACTIVE;
30
- case 2:
31
- case "STATUS_BANNED":
32
- return Status.STATUS_BANNED;
33
- case -1:
34
- case "UNRECOGNIZED":
35
- default:
36
- return Status.UNRECOGNIZED;
37
- }
38
- }
39
-
40
- export function statusToJSON(object: Status): string {
41
- switch (object) {
42
- case Status.STATUS_UNKNOWN:
43
- return "STATUS_UNKNOWN";
44
- case Status.STATUS_ACTIVE:
45
- return "STATUS_ACTIVE";
46
- case Status.STATUS_BANNED:
47
- return "STATUS_BANNED";
48
- case Status.UNRECOGNIZED:
49
- default:
50
- return "UNRECOGNIZED";
51
- }
52
- }
53
-
54
23
  export interface PingResponse {
55
24
  }
56
25
 
57
26
  export interface UserSession {
58
27
  id: string;
59
- createdAt: Date | undefined;
28
+ createdAt: Timestamp | undefined;
60
29
  duration: Duration | undefined;
61
30
  }
62
31
 
@@ -77,513 +46,29 @@ export interface UserProfile_MetaEntry {
77
46
  value: string;
78
47
  }
79
48
 
80
- function createBasePingResponse(): PingResponse {
81
- return {};
82
- }
83
-
84
- export const PingResponse: MessageFns<PingResponse> = {
85
- encode(_: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
86
- return writer;
87
- },
49
+ export const TEST_V1_PACKAGE_NAME = "test.v1";
88
50
 
89
- decode(input: BinaryReader | Uint8Array, length?: number): PingResponse {
90
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
91
- const end = length === undefined ? reader.len : reader.pos + length;
92
- const message = createBasePingResponse();
93
- while (reader.pos < end) {
94
- const tag = reader.uint32();
95
- switch (tag >>> 3) {
96
- }
97
- if ((tag & 7) === 4 || tag === 0) {
98
- break;
99
- }
100
- reader.skip(tag & 7);
101
- }
102
- return message;
103
- },
104
-
105
- fromJSON(_: any): PingResponse {
106
- return {};
107
- },
108
-
109
- toJSON(_: PingResponse): unknown {
110
- const obj: any = {};
111
- return obj;
112
- },
113
-
114
- create<I extends Exact<DeepPartial<PingResponse>, I>>(base?: I): PingResponse {
115
- return PingResponse.fromPartial(base ?? ({} as any));
116
- },
117
- fromPartial<I extends Exact<DeepPartial<PingResponse>, I>>(_: I): PingResponse {
118
- const message = createBasePingResponse();
119
- return message;
120
- },
121
- };
122
-
123
- function createBaseUserSession(): UserSession {
124
- return { id: "", createdAt: undefined, duration: undefined };
51
+ export interface TestServiceClient {
52
+ ping(request: Empty): Observable<PingResponse>;
125
53
  }
126
54
 
127
- export const UserSession: MessageFns<UserSession> = {
128
- encode(message: UserSession, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
129
- if (message.id !== "") {
130
- writer.uint32(10).string(message.id);
131
- }
132
- if (message.createdAt !== undefined) {
133
- Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(18).fork()).join();
134
- }
135
- if (message.duration !== undefined) {
136
- Duration.encode(message.duration, writer.uint32(26).fork()).join();
137
- }
138
- return writer;
139
- },
140
-
141
- decode(input: BinaryReader | Uint8Array, length?: number): UserSession {
142
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
143
- const end = length === undefined ? reader.len : reader.pos + length;
144
- const message = createBaseUserSession();
145
- while (reader.pos < end) {
146
- const tag = reader.uint32();
147
- switch (tag >>> 3) {
148
- case 1: {
149
- if (tag !== 10) {
150
- break;
151
- }
152
-
153
- message.id = reader.string();
154
- continue;
155
- }
156
- case 2: {
157
- if (tag !== 18) {
158
- break;
159
- }
160
-
161
- message.createdAt = fromTimestamp(Timestamp.decode(reader, reader.uint32()));
162
- continue;
163
- }
164
- case 3: {
165
- if (tag !== 26) {
166
- break;
167
- }
168
-
169
- message.duration = Duration.decode(reader, reader.uint32());
170
- continue;
171
- }
172
- }
173
- if ((tag & 7) === 4 || tag === 0) {
174
- break;
175
- }
176
- reader.skip(tag & 7);
177
- }
178
- return message;
179
- },
180
-
181
- fromJSON(object: any): UserSession {
182
- return {
183
- id: isSet(object.id) ? globalThis.String(object.id) : "",
184
- createdAt: isSet(object.createdAt) ? fromJsonTimestamp(object.createdAt) : undefined,
185
- duration: isSet(object.duration) ? Duration.fromJSON(object.duration) : undefined,
186
- };
187
- },
188
-
189
- toJSON(message: UserSession): unknown {
190
- const obj: any = {};
191
- if (message.id !== "") {
192
- obj.id = message.id;
193
- }
194
- if (message.createdAt !== undefined) {
195
- obj.createdAt = message.createdAt.toISOString();
196
- }
197
- if (message.duration !== undefined) {
198
- obj.duration = Duration.toJSON(message.duration);
199
- }
200
- return obj;
201
- },
202
-
203
- create<I extends Exact<DeepPartial<UserSession>, I>>(base?: I): UserSession {
204
- return UserSession.fromPartial(base ?? ({} as any));
205
- },
206
- fromPartial<I extends Exact<DeepPartial<UserSession>, I>>(object: I): UserSession {
207
- const message = createBaseUserSession();
208
- message.id = object.id ?? "";
209
- message.createdAt = object.createdAt ?? undefined;
210
- message.duration = (object.duration !== undefined && object.duration !== null)
211
- ? Duration.fromPartial(object.duration)
212
- : undefined;
213
- return message;
214
- },
215
- };
216
-
217
- function createBaseUserProfile(): UserProfile {
218
- return {
219
- id: "",
220
- age: 0,
221
- rating: 0,
222
- verified: false,
223
- roles: [],
224
- meta: {},
225
- status: 0,
226
- phone: undefined,
227
- email: undefined,
228
- };
229
- }
230
-
231
- export const UserProfile: MessageFns<UserProfile> = {
232
- encode(message: UserProfile, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
233
- if (message.id !== "") {
234
- writer.uint32(10).string(message.id);
235
- }
236
- if (message.age !== 0) {
237
- writer.uint32(16).int32(message.age);
238
- }
239
- if (message.rating !== 0) {
240
- writer.uint32(25).double(message.rating);
241
- }
242
- if (message.verified !== false) {
243
- writer.uint32(32).bool(message.verified);
244
- }
245
- for (const v of message.roles) {
246
- writer.uint32(42).string(v!);
247
- }
248
- globalThis.Object.entries(message.meta).forEach(([key, value]: [string, string]) => {
249
- UserProfile_MetaEntry.encode({ key: key as any, value }, writer.uint32(50).fork()).join();
250
- });
251
- if (message.status !== 0) {
252
- writer.uint32(56).int32(message.status);
253
- }
254
- if (message.phone !== undefined) {
255
- writer.uint32(66).string(message.phone);
256
- }
257
- if (message.email !== undefined) {
258
- writer.uint32(74).string(message.email);
259
- }
260
- return writer;
261
- },
262
-
263
- decode(input: BinaryReader | Uint8Array, length?: number): UserProfile {
264
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
265
- const end = length === undefined ? reader.len : reader.pos + length;
266
- const message = createBaseUserProfile();
267
- while (reader.pos < end) {
268
- const tag = reader.uint32();
269
- switch (tag >>> 3) {
270
- case 1: {
271
- if (tag !== 10) {
272
- break;
273
- }
274
-
275
- message.id = reader.string();
276
- continue;
277
- }
278
- case 2: {
279
- if (tag !== 16) {
280
- break;
281
- }
282
-
283
- message.age = reader.int32();
284
- continue;
285
- }
286
- case 3: {
287
- if (tag !== 25) {
288
- break;
289
- }
290
-
291
- message.rating = reader.double();
292
- continue;
293
- }
294
- case 4: {
295
- if (tag !== 32) {
296
- break;
297
- }
298
-
299
- message.verified = reader.bool();
300
- continue;
301
- }
302
- case 5: {
303
- if (tag !== 42) {
304
- break;
305
- }
306
-
307
- message.roles.push(reader.string());
308
- continue;
309
- }
310
- case 6: {
311
- if (tag !== 50) {
312
- break;
313
- }
314
-
315
- const entry6 = UserProfile_MetaEntry.decode(reader, reader.uint32());
316
- if (entry6.value !== undefined) {
317
- message.meta[entry6.key] = entry6.value;
318
- }
319
- continue;
320
- }
321
- case 7: {
322
- if (tag !== 56) {
323
- break;
324
- }
325
-
326
- message.status = reader.int32() as any;
327
- continue;
328
- }
329
- case 8: {
330
- if (tag !== 66) {
331
- break;
332
- }
333
-
334
- message.phone = reader.string();
335
- continue;
336
- }
337
- case 9: {
338
- if (tag !== 74) {
339
- break;
340
- }
341
-
342
- message.email = reader.string();
343
- continue;
344
- }
345
- }
346
- if ((tag & 7) === 4 || tag === 0) {
347
- break;
348
- }
349
- reader.skip(tag & 7);
350
- }
351
- return message;
352
- },
353
-
354
- fromJSON(object: any): UserProfile {
355
- return {
356
- id: isSet(object.id) ? globalThis.String(object.id) : "",
357
- age: isSet(object.age) ? globalThis.Number(object.age) : 0,
358
- rating: isSet(object.rating) ? globalThis.Number(object.rating) : 0,
359
- verified: isSet(object.verified) ? globalThis.Boolean(object.verified) : false,
360
- roles: globalThis.Array.isArray(object?.roles) ? object.roles.map((e: any) => globalThis.String(e)) : [],
361
- meta: isObject(object.meta)
362
- ? (globalThis.Object.entries(object.meta) as [string, any][]).reduce(
363
- (acc: { [key: string]: string }, [key, value]: [string, any]) => {
364
- acc[key] = globalThis.String(value);
365
- return acc;
366
- },
367
- {},
368
- )
369
- : {},
370
- status: isSet(object.status) ? statusFromJSON(object.status) : 0,
371
- phone: isSet(object.phone) ? globalThis.String(object.phone) : undefined,
372
- email: isSet(object.email) ? globalThis.String(object.email) : undefined,
373
- };
374
- },
375
-
376
- toJSON(message: UserProfile): unknown {
377
- const obj: any = {};
378
- if (message.id !== "") {
379
- obj.id = message.id;
380
- }
381
- if (message.age !== 0) {
382
- obj.age = Math.round(message.age);
383
- }
384
- if (message.rating !== 0) {
385
- obj.rating = message.rating;
386
- }
387
- if (message.verified !== false) {
388
- obj.verified = message.verified;
389
- }
390
- if (message.roles?.length) {
391
- obj.roles = message.roles;
392
- }
393
- if (message.meta) {
394
- const entries = globalThis.Object.entries(message.meta) as [string, string][];
395
- if (entries.length > 0) {
396
- obj.meta = {};
397
- entries.forEach(([k, v]) => {
398
- obj.meta[k] = v;
399
- });
400
- }
401
- }
402
- if (message.status !== 0) {
403
- obj.status = statusToJSON(message.status);
404
- }
405
- if (message.phone !== undefined) {
406
- obj.phone = message.phone;
407
- }
408
- if (message.email !== undefined) {
409
- obj.email = message.email;
410
- }
411
- return obj;
412
- },
413
-
414
- create<I extends Exact<DeepPartial<UserProfile>, I>>(base?: I): UserProfile {
415
- return UserProfile.fromPartial(base ?? ({} as any));
416
- },
417
- fromPartial<I extends Exact<DeepPartial<UserProfile>, I>>(object: I): UserProfile {
418
- const message = createBaseUserProfile();
419
- message.id = object.id ?? "";
420
- message.age = object.age ?? 0;
421
- message.rating = object.rating ?? 0;
422
- message.verified = object.verified ?? false;
423
- message.roles = object.roles?.map((e) => e) || [];
424
- message.meta = (globalThis.Object.entries(object.meta ?? {}) as [string, string][]).reduce(
425
- (acc: { [key: string]: string }, [key, value]: [string, string]) => {
426
- if (value !== undefined) {
427
- acc[key] = globalThis.String(value);
428
- }
429
- return acc;
430
- },
431
- {},
432
- );
433
- message.status = object.status ?? 0;
434
- message.phone = object.phone ?? undefined;
435
- message.email = object.email ?? undefined;
436
- return message;
437
- },
438
- };
439
-
440
- function createBaseUserProfile_MetaEntry(): UserProfile_MetaEntry {
441
- return { key: "", value: "" };
55
+ export interface TestServiceController {
56
+ ping(request: Empty): Promise<PingResponse> | Observable<PingResponse> | PingResponse;
442
57
  }
443
58
 
444
- export const UserProfile_MetaEntry: MessageFns<UserProfile_MetaEntry> = {
445
- encode(message: UserProfile_MetaEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
446
- if (message.key !== "") {
447
- writer.uint32(10).string(message.key);
448
- }
449
- if (message.value !== "") {
450
- writer.uint32(18).string(message.value);
59
+ export function TestServiceControllerMethods() {
60
+ return function (constructor: Function) {
61
+ const grpcMethods: string[] = ["ping"];
62
+ for (const method of grpcMethods) {
63
+ const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
64
+ GrpcMethod("TestService", method)(constructor.prototype[method], method, descriptor);
451
65
  }
452
- return writer;
453
- },
454
-
455
- decode(input: BinaryReader | Uint8Array, length?: number): UserProfile_MetaEntry {
456
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
457
- const end = length === undefined ? reader.len : reader.pos + length;
458
- const message = createBaseUserProfile_MetaEntry();
459
- while (reader.pos < end) {
460
- const tag = reader.uint32();
461
- switch (tag >>> 3) {
462
- case 1: {
463
- if (tag !== 10) {
464
- break;
465
- }
466
-
467
- message.key = reader.string();
468
- continue;
469
- }
470
- case 2: {
471
- if (tag !== 18) {
472
- break;
473
- }
474
-
475
- message.value = reader.string();
476
- continue;
477
- }
478
- }
479
- if ((tag & 7) === 4 || tag === 0) {
480
- break;
481
- }
482
- reader.skip(tag & 7);
483
- }
484
- return message;
485
- },
486
-
487
- fromJSON(object: any): UserProfile_MetaEntry {
488
- return {
489
- key: isSet(object.key) ? globalThis.String(object.key) : "",
490
- value: isSet(object.value) ? globalThis.String(object.value) : "",
491
- };
492
- },
493
-
494
- toJSON(message: UserProfile_MetaEntry): unknown {
495
- const obj: any = {};
496
- if (message.key !== "") {
497
- obj.key = message.key;
66
+ const grpcStreamMethods: string[] = [];
67
+ for (const method of grpcStreamMethods) {
68
+ const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
69
+ GrpcStreamMethod("TestService", method)(constructor.prototype[method], method, descriptor);
498
70
  }
499
- if (message.value !== "") {
500
- obj.value = message.value;
501
- }
502
- return obj;
503
- },
504
-
505
- create<I extends Exact<DeepPartial<UserProfile_MetaEntry>, I>>(base?: I): UserProfile_MetaEntry {
506
- return UserProfile_MetaEntry.fromPartial(base ?? ({} as any));
507
- },
508
- fromPartial<I extends Exact<DeepPartial<UserProfile_MetaEntry>, I>>(object: I): UserProfile_MetaEntry {
509
- const message = createBaseUserProfile_MetaEntry();
510
- message.key = object.key ?? "";
511
- message.value = object.value ?? "";
512
- return message;
513
- },
514
- };
515
-
516
- export interface TestService {
517
- Ping(request: Empty): Promise<PingResponse>;
518
- }
519
-
520
- export const TestServiceServiceName = "test.v1.TestService";
521
- export class TestServiceClientImpl implements TestService {
522
- private readonly rpc: Rpc;
523
- private readonly service: string;
524
- constructor(rpc: Rpc, opts?: { service?: string }) {
525
- this.service = opts?.service || TestServiceServiceName;
526
- this.rpc = rpc;
527
- this.Ping = this.Ping.bind(this);
528
- }
529
- Ping(request: Empty): Promise<PingResponse> {
530
- const data = Empty.encode(request).finish();
531
- const promise = this.rpc.request(this.service, "Ping", data);
532
- return promise.then((data) => PingResponse.decode(new BinaryReader(data)));
533
- }
534
- }
535
-
536
- interface Rpc {
537
- request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
538
- }
539
-
540
- type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
541
-
542
- export type DeepPartial<T> = T extends Builtin ? T
543
- : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
544
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
545
- : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
546
- : Partial<T>;
547
-
548
- type KeysOfUnion<T> = T extends T ? keyof T : never;
549
- export type Exact<P, I extends P> = P extends Builtin ? P
550
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
551
-
552
- function toTimestamp(date: Date): Timestamp {
553
- const seconds = Math.trunc(date.getTime() / 1_000);
554
- const nanos = (date.getTime() % 1_000) * 1_000_000;
555
- return { seconds, nanos };
556
- }
557
-
558
- function fromTimestamp(t: Timestamp): Date {
559
- let millis = (t.seconds || 0) * 1_000;
560
- millis += (t.nanos || 0) / 1_000_000;
561
- return new globalThis.Date(millis);
562
- }
563
-
564
- function fromJsonTimestamp(o: any): Date {
565
- if (o instanceof globalThis.Date) {
566
- return o;
567
- } else if (typeof o === "string") {
568
- return new globalThis.Date(o);
569
- } else {
570
- return fromTimestamp(Timestamp.fromJSON(o));
571
- }
572
- }
573
-
574
- function isObject(value: any): boolean {
575
- return typeof value === "object" && value !== null;
576
- }
577
-
578
- function isSet(value: any): boolean {
579
- return value !== null && value !== undefined;
71
+ };
580
72
  }
581
73
 
582
- export interface MessageFns<T> {
583
- encode(message: T, writer?: BinaryWriter): BinaryWriter;
584
- decode(input: BinaryReader | Uint8Array, length?: number): T;
585
- fromJSON(object: any): T;
586
- toJSON(message: T): unknown;
587
- create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
588
- fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
589
- }
74
+ export const TEST_SERVICE_NAME = "TestService";
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@shock-cinema/contracts",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Protobuf definitions and generated TypeScript types",
5
5
  "scripts": {
6
- "generate": "protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen --ts_proto_opt=nestJS=true,package=omit"
6
+ "generate": "protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen --ts_proto_opt=nestJs=true,package=omit"
7
7
  },
8
8
  "files": [
9
9
  "proto",
@@ -13,10 +13,8 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@bufbuild/protobuf": "^2.10.2",
17
- "@grpc/grpc-js": "^1.14.3",
18
16
  "@nestjs/microservices": "^11.1.11",
19
17
  "rxjs": "^7.8.2",
20
- "ts-proto": "^2.10.1"
18
+ "ts-proto": "^2.8.3"
21
19
  }
22
20
  }