1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | exports.ClientDuplexStreamImpl = exports.ClientWritableStreamImpl = exports.ClientReadableStreamImpl = exports.ClientUnaryCallImpl = exports.callErrorFromStatus = void 0;
|
20 | const events_1 = require("events");
|
21 | const stream_1 = require("stream");
|
22 | const constants_1 = require("./constants");
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function callErrorFromStatus(status) {
|
30 | const message = `${status.code} ${constants_1.Status[status.code]}: ${status.details}`;
|
31 | return Object.assign(new Error(message), status);
|
32 | }
|
33 | exports.callErrorFromStatus = callErrorFromStatus;
|
34 | class ClientUnaryCallImpl extends events_1.EventEmitter {
|
35 | constructor() {
|
36 | super();
|
37 | }
|
38 | cancel() {
|
39 | var _a;
|
40 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.cancelWithStatus(constants_1.Status.CANCELLED, 'Cancelled on client');
|
41 | }
|
42 | getPeer() {
|
43 | var _a, _b;
|
44 | return (_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.getPeer()) !== null && _b !== void 0 ? _b : 'unknown';
|
45 | }
|
46 | }
|
47 | exports.ClientUnaryCallImpl = ClientUnaryCallImpl;
|
48 | class ClientReadableStreamImpl extends stream_1.Readable {
|
49 | constructor(deserialize) {
|
50 | super({ objectMode: true });
|
51 | this.deserialize = deserialize;
|
52 | }
|
53 | cancel() {
|
54 | var _a;
|
55 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.cancelWithStatus(constants_1.Status.CANCELLED, 'Cancelled on client');
|
56 | }
|
57 | getPeer() {
|
58 | var _a, _b;
|
59 | return (_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.getPeer()) !== null && _b !== void 0 ? _b : 'unknown';
|
60 | }
|
61 | _read(_size) {
|
62 | var _a;
|
63 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.startRead();
|
64 | }
|
65 | }
|
66 | exports.ClientReadableStreamImpl = ClientReadableStreamImpl;
|
67 | class ClientWritableStreamImpl extends stream_1.Writable {
|
68 | constructor(serialize) {
|
69 | super({ objectMode: true });
|
70 | this.serialize = serialize;
|
71 | }
|
72 | cancel() {
|
73 | var _a;
|
74 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.cancelWithStatus(constants_1.Status.CANCELLED, 'Cancelled on client');
|
75 | }
|
76 | getPeer() {
|
77 | var _a, _b;
|
78 | return (_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.getPeer()) !== null && _b !== void 0 ? _b : 'unknown';
|
79 | }
|
80 | _write(chunk, encoding, cb) {
|
81 | var _a;
|
82 | const context = {
|
83 | callback: cb,
|
84 | };
|
85 | const flags = Number(encoding);
|
86 | if (!Number.isNaN(flags)) {
|
87 | context.flags = flags;
|
88 | }
|
89 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.sendMessageWithContext(context, chunk);
|
90 | }
|
91 | _final(cb) {
|
92 | var _a;
|
93 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.halfClose();
|
94 | cb();
|
95 | }
|
96 | }
|
97 | exports.ClientWritableStreamImpl = ClientWritableStreamImpl;
|
98 | class ClientDuplexStreamImpl extends stream_1.Duplex {
|
99 | constructor(serialize, deserialize) {
|
100 | super({ objectMode: true });
|
101 | this.serialize = serialize;
|
102 | this.deserialize = deserialize;
|
103 | }
|
104 | cancel() {
|
105 | var _a;
|
106 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.cancelWithStatus(constants_1.Status.CANCELLED, 'Cancelled on client');
|
107 | }
|
108 | getPeer() {
|
109 | var _a, _b;
|
110 | return (_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.getPeer()) !== null && _b !== void 0 ? _b : 'unknown';
|
111 | }
|
112 | _read(_size) {
|
113 | var _a;
|
114 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.startRead();
|
115 | }
|
116 | _write(chunk, encoding, cb) {
|
117 | var _a;
|
118 | const context = {
|
119 | callback: cb,
|
120 | };
|
121 | const flags = Number(encoding);
|
122 | if (!Number.isNaN(flags)) {
|
123 | context.flags = flags;
|
124 | }
|
125 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.sendMessageWithContext(context, chunk);
|
126 | }
|
127 | _final(cb) {
|
128 | var _a;
|
129 | (_a = this.call) === null || _a === void 0 ? void 0 : _a.halfClose();
|
130 | cb();
|
131 | }
|
132 | }
|
133 | exports.ClientDuplexStreamImpl = ClientDuplexStreamImpl;
|
134 |
|
\ | No newline at end of file |