@celljs/grpc 0.0.0-stage → 4.3.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/README.md +123 -2
- package/cell.yml +12 -0
- package/esm/node/call/async-queue.d.ts +31 -0
- package/esm/node/call/async-queue.js +80 -0
- package/esm/node/call/async-queue.js.map +1 -0
- package/esm/node/call/grpc-status.d.ts +33 -0
- package/esm/node/call/grpc-status.js +48 -0
- package/esm/node/call/grpc-status.js.map +1 -0
- package/esm/node/call/message-framer.d.ts +24 -0
- package/esm/node/call/message-framer.js +105 -0
- package/esm/node/call/message-framer.js.map +1 -0
- package/esm/node/call/metadata.d.ts +15 -0
- package/esm/node/call/metadata.js +81 -0
- package/esm/node/call/metadata.js.map +1 -0
- package/esm/node/client/grpc-channel.d.ts +64 -0
- package/esm/node/client/grpc-channel.js +285 -0
- package/esm/node/client/grpc-channel.js.map +1 -0
- package/esm/node/codec/proto-reader.d.ts +26 -0
- package/esm/node/codec/proto-reader.js +153 -0
- package/esm/node/codec/proto-reader.js.map +1 -0
- package/esm/node/codec/proto-writer.d.ts +29 -0
- package/esm/node/codec/proto-writer.js +150 -0
- package/esm/node/codec/proto-writer.js.map +1 -0
- package/esm/node/index.d.ts +15 -0
- package/esm/node/index.js +16 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/proto/proto-ast.d.ts +46 -0
- package/esm/node/proto/proto-ast.js +2 -0
- package/esm/node/proto/proto-ast.js.map +1 -0
- package/esm/node/proto/proto-parser.d.ts +45 -0
- package/esm/node/proto/proto-parser.js +451 -0
- package/esm/node/proto/proto-parser.js.map +1 -0
- package/esm/node/proto/proto-types.d.ts +76 -0
- package/esm/node/proto/proto-types.js +444 -0
- package/esm/node/proto/proto-types.js.map +1 -0
- package/esm/node/proto/proto.d.ts +57 -0
- package/esm/node/proto/proto.js +174 -0
- package/esm/node/proto/proto.js.map +1 -0
- package/esm/node/proto/well-known.d.ts +5 -0
- package/esm/node/proto/well-known.js +41 -0
- package/esm/node/proto/well-known.js.map +1 -0
- package/esm/node/server/grpc-server-lifecycle.d.ts +21 -0
- package/esm/node/server/grpc-server-lifecycle.js +65 -0
- package/esm/node/server/grpc-server-lifecycle.js.map +1 -0
- package/esm/node/server/grpc-server.d.ts +60 -0
- package/esm/node/server/grpc-server.js +312 -0
- package/esm/node/server/grpc-server.js.map +1 -0
- package/esm/node/server/grpc-service.d.ts +24 -0
- package/esm/node/server/grpc-service.js +38 -0
- package/esm/node/server/grpc-service.js.map +1 -0
- package/esm/node/test/proto-loader.d.ts +2 -0
- package/esm/node/test/proto-loader.js +13 -0
- package/esm/node/test/proto-loader.js.map +1 -0
- package/esm/node/test/test-protos.d.ts +28 -0
- package/esm/node/test/test-protos.js +145 -0
- package/esm/node/test/test-protos.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/call/async-queue.d.ts +32 -0
- package/lib/node/call/async-queue.d.ts.map +1 -0
- package/lib/node/call/async-queue.js +84 -0
- package/lib/node/call/async-queue.js.map +1 -0
- package/lib/node/call/grpc-status.d.ts +34 -0
- package/lib/node/call/grpc-status.d.ts.map +1 -0
- package/lib/node/call/grpc-status.js +52 -0
- package/lib/node/call/grpc-status.js.map +1 -0
- package/lib/node/call/message-framer.d.ts +25 -0
- package/lib/node/call/message-framer.d.ts.map +1 -0
- package/lib/node/call/message-framer.js +109 -0
- package/lib/node/call/message-framer.js.map +1 -0
- package/lib/node/call/metadata.d.ts +16 -0
- package/lib/node/call/metadata.d.ts.map +1 -0
- package/lib/node/call/metadata.js +84 -0
- package/lib/node/call/metadata.js.map +1 -0
- package/lib/node/client/grpc-channel.d.ts +65 -0
- package/lib/node/client/grpc-channel.d.ts.map +1 -0
- package/lib/node/client/grpc-channel.js +289 -0
- package/lib/node/client/grpc-channel.js.map +1 -0
- package/lib/node/codec/proto-reader.d.ts +27 -0
- package/lib/node/codec/proto-reader.d.ts.map +1 -0
- package/lib/node/codec/proto-reader.js +157 -0
- package/lib/node/codec/proto-reader.js.map +1 -0
- package/lib/node/codec/proto-writer.d.ts +30 -0
- package/lib/node/codec/proto-writer.d.ts.map +1 -0
- package/lib/node/codec/proto-writer.js +154 -0
- package/lib/node/codec/proto-writer.js.map +1 -0
- package/lib/node/grpc.spec.d.ts +2 -0
- package/lib/node/grpc.spec.d.ts.map +1 -0
- package/lib/node/grpc.spec.js +148 -0
- package/lib/node/grpc.spec.js.map +1 -0
- package/lib/node/index.d.ts +16 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +32 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/interop.spec.d.ts +2 -0
- package/lib/node/interop.spec.d.ts.map +1 -0
- package/lib/node/interop.spec.js +194 -0
- package/lib/node/interop.spec.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/proto/proto-ast.d.ts +47 -0
- package/lib/node/proto/proto-ast.d.ts.map +1 -0
- package/lib/node/proto/proto-ast.js +3 -0
- package/lib/node/proto/proto-ast.js.map +1 -0
- package/lib/node/proto/proto-parser.d.ts +46 -0
- package/lib/node/proto/proto-parser.d.ts.map +1 -0
- package/lib/node/proto/proto-parser.js +455 -0
- package/lib/node/proto/proto-parser.js.map +1 -0
- package/lib/node/proto/proto-parser.spec.d.ts +2 -0
- package/lib/node/proto/proto-parser.spec.d.ts.map +1 -0
- package/lib/node/proto/proto-parser.spec.js +95 -0
- package/lib/node/proto/proto-parser.spec.js.map +1 -0
- package/lib/node/proto/proto-types.d.ts +77 -0
- package/lib/node/proto/proto-types.d.ts.map +1 -0
- package/lib/node/proto/proto-types.js +449 -0
- package/lib/node/proto/proto-types.js.map +1 -0
- package/lib/node/proto/proto-types.spec.d.ts +2 -0
- package/lib/node/proto/proto-types.spec.d.ts.map +1 -0
- package/lib/node/proto/proto-types.spec.js +120 -0
- package/lib/node/proto/proto-types.spec.js.map +1 -0
- package/lib/node/proto/proto.d.ts +58 -0
- package/lib/node/proto/proto.d.ts.map +1 -0
- package/lib/node/proto/proto.js +178 -0
- package/lib/node/proto/proto.js.map +1 -0
- package/lib/node/proto/well-known.d.ts +6 -0
- package/lib/node/proto/well-known.d.ts.map +1 -0
- package/lib/node/proto/well-known.js +44 -0
- package/lib/node/proto/well-known.js.map +1 -0
- package/lib/node/server/grpc-server-lifecycle.d.ts +22 -0
- package/lib/node/server/grpc-server-lifecycle.d.ts.map +1 -0
- package/lib/node/server/grpc-server-lifecycle.js +68 -0
- package/lib/node/server/grpc-server-lifecycle.js.map +1 -0
- package/lib/node/server/grpc-server-lifecycle.spec.d.ts +2 -0
- package/lib/node/server/grpc-server-lifecycle.spec.d.ts.map +1 -0
- package/lib/node/server/grpc-server-lifecycle.spec.js +100 -0
- package/lib/node/server/grpc-server-lifecycle.spec.js.map +1 -0
- package/lib/node/server/grpc-server.d.ts +61 -0
- package/lib/node/server/grpc-server.d.ts.map +1 -0
- package/lib/node/server/grpc-server.js +316 -0
- package/lib/node/server/grpc-server.js.map +1 -0
- package/lib/node/server/grpc-service.d.ts +25 -0
- package/lib/node/server/grpc-service.d.ts.map +1 -0
- package/lib/node/server/grpc-service.js +42 -0
- package/lib/node/server/grpc-service.js.map +1 -0
- package/lib/node/test/proto-loader.d.ts +3 -0
- package/lib/node/test/proto-loader.d.ts.map +1 -0
- package/lib/node/test/proto-loader.js +16 -0
- package/lib/node/test/proto-loader.js.map +1 -0
- package/lib/node/test/test-protos.d.ts +29 -0
- package/lib/node/test/test-protos.d.ts.map +1 -0
- package/lib/node/test/test-protos.js +150 -0
- package/lib/node/test/test-protos.js.map +1 -0
- package/lib/package.spec.d.ts +2 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +7 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +69 -4
- package/src/node/call/async-queue.ts +79 -0
- package/src/node/call/grpc-status.ts +49 -0
- package/src/node/call/message-framer.ts +109 -0
- package/src/node/call/metadata.ts +85 -0
- package/src/node/client/grpc-channel.ts +327 -0
- package/src/node/codec/proto-reader.ts +172 -0
- package/src/node/codec/proto-writer.ts +170 -0
- package/src/node/grpc.spec.ts +160 -0
- package/src/node/index.ts +15 -0
- package/src/node/interop.spec.ts +174 -0
- package/src/node/module.ts +4 -0
- package/src/node/proto/proto-ast.ts +48 -0
- package/src/node/proto/proto-parser.spec.ts +104 -0
- package/src/node/proto/proto-parser.ts +477 -0
- package/src/node/proto/proto-types.spec.ts +128 -0
- package/src/node/proto/proto-types.ts +497 -0
- package/src/node/proto/proto.ts +218 -0
- package/src/node/proto/well-known.ts +40 -0
- package/src/node/server/grpc-server-lifecycle.spec.ts +88 -0
- package/src/node/server/grpc-server-lifecycle.ts +56 -0
- package/src/node/server/grpc-server.ts +368 -0
- package/src/node/server/grpc-service.ts +40 -0
- package/src/node/test/proto-loader.ts +13 -0
- package/src/node/test/test-protos.ts +159 -0
- package/src/package.spec.ts +5 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { createServer } from 'node:http2';
|
|
2
|
+
import { AsyncQueue } from '../call/async-queue.js';
|
|
3
|
+
import { GrpcError, GrpcStatus } from '../call/grpc-status.js';
|
|
4
|
+
import { ACCEPT_ENCODING, DEFAULT_MAX_RECEIVE_MESSAGE_SIZE, MessageDeframer, MessageFramer } from '../call/message-framer.js';
|
|
5
|
+
import { MetadataUtil } from '../call/metadata.js';
|
|
6
|
+
/**
|
|
7
|
+
* A gRPC server on `node:http2` (cleartext HTTP/2). Each method of a service is the method of the
|
|
8
|
+
* implementation named after it in lowerCamelCase (`SayHello` → `sayHello`); see {@link UnaryHandler}
|
|
9
|
+
* and the other handler types for their signatures. Methods without an implementation answer
|
|
10
|
+
* `UNIMPLEMENTED`.
|
|
11
|
+
*
|
|
12
|
+
* In a Cell application, use {@link GrpcService} instead: the application starts the server.
|
|
13
|
+
*/
|
|
14
|
+
export class GrpcServer {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.handlers = new Map();
|
|
18
|
+
this.sessions = new Set();
|
|
19
|
+
}
|
|
20
|
+
addService(service, implementation) {
|
|
21
|
+
var _a;
|
|
22
|
+
for (const method of service.methods) {
|
|
23
|
+
const impl = implementation;
|
|
24
|
+
const fn = (_a = impl[method.jsName]) !== null && _a !== void 0 ? _a : impl[method.name];
|
|
25
|
+
if (this.handlers.has(method.path)) {
|
|
26
|
+
throw new Error(`${method.path} is served twice: add ${service.fullName} to the server once.`);
|
|
27
|
+
}
|
|
28
|
+
if (typeof fn === 'function') {
|
|
29
|
+
this.handlers.set(method.path, { method, fn: fn.bind(implementation) });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/** Starts listening; resolves to the port, which is a free one when `port` is 0. */
|
|
35
|
+
listen(port = 50051, host = '127.0.0.1') {
|
|
36
|
+
if (this.server) {
|
|
37
|
+
throw new Error('The gRPC server is already listening.');
|
|
38
|
+
}
|
|
39
|
+
const server = createServer();
|
|
40
|
+
this.server = server;
|
|
41
|
+
server.on('session', session => {
|
|
42
|
+
this.sessions.add(session);
|
|
43
|
+
session.on('close', () => this.sessions.delete(session));
|
|
44
|
+
session.on('error', () => undefined);
|
|
45
|
+
});
|
|
46
|
+
server.on('stream', (stream, headers) => this.handleStream(stream, headers));
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
server.once('error', reject);
|
|
49
|
+
server.listen(port, host, () => {
|
|
50
|
+
server.off('error', reject);
|
|
51
|
+
resolve(server.address().port);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
get port() {
|
|
56
|
+
var _a;
|
|
57
|
+
const address = (_a = this.server) === null || _a === void 0 ? void 0 : _a.address();
|
|
58
|
+
return address && typeof address === 'object' ? address.port : undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Stops accepting connections and closes the open ones; `force` also cancels the calls in progress. */
|
|
61
|
+
close(force = false) {
|
|
62
|
+
const server = this.server;
|
|
63
|
+
this.server = undefined;
|
|
64
|
+
if (!server) {
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
const closed = new Promise(resolve => server.close(() => resolve()));
|
|
68
|
+
for (const session of this.sessions) {
|
|
69
|
+
if (force) {
|
|
70
|
+
session.destroy();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
session.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return closed;
|
|
77
|
+
}
|
|
78
|
+
/** Serves one HTTP/2 stream; for servers of your own (`server.on('stream', ...)`). */
|
|
79
|
+
handleStream(stream, headers) {
|
|
80
|
+
stream.on('error', () => undefined);
|
|
81
|
+
const contentType = headers['content-type'];
|
|
82
|
+
if (headers[':method'] !== 'POST' || typeof contentType !== 'string' || !contentType.startsWith('application/grpc')) {
|
|
83
|
+
stream.respond({ ':status': 415, 'grpc-status': String(GrpcStatus.UNKNOWN), 'grpc-message': 'Not a gRPC request' }, { endStream: true });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const path = String(headers[':path']);
|
|
87
|
+
const handler = this.handlers.get(path);
|
|
88
|
+
if (!handler) {
|
|
89
|
+
stream.respond({
|
|
90
|
+
':status': 200,
|
|
91
|
+
'content-type': 'application/grpc+proto',
|
|
92
|
+
'grpc-status': String(GrpcStatus.UNIMPLEMENTED),
|
|
93
|
+
'grpc-message': MetadataUtil.encodeMessage(`The server does not implement ${path}`),
|
|
94
|
+
}, { endStream: true });
|
|
95
|
+
stream.resume();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const call = new GrpcServerCall(stream, headers, handler.method, this.options);
|
|
99
|
+
call.run(handler.fn).catch(error => call.fail(error));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class GrpcServerCall {
|
|
103
|
+
constructor(stream, headers, method, options) {
|
|
104
|
+
this.stream = stream;
|
|
105
|
+
this.headers = headers;
|
|
106
|
+
this.method = method;
|
|
107
|
+
this.options = options;
|
|
108
|
+
this.controller = new AbortController();
|
|
109
|
+
this.responseHeaders = {};
|
|
110
|
+
this.trailers = {};
|
|
111
|
+
this.headersSent = false;
|
|
112
|
+
this.finished = false;
|
|
113
|
+
this.requestsRead = false;
|
|
114
|
+
this.metadata = MetadataUtil.fromHeaders(headers);
|
|
115
|
+
const timeout = MetadataUtil.parseTimeout(headers['grpc-timeout']);
|
|
116
|
+
if (timeout !== undefined) {
|
|
117
|
+
this.deadline = new Date(Date.now() + timeout);
|
|
118
|
+
this.timer = setTimeout(() => this.finish(new GrpcError(GrpcStatus.DEADLINE_EXCEEDED, 'Deadline exceeded')), timeout);
|
|
119
|
+
}
|
|
120
|
+
stream.once('close', () => {
|
|
121
|
+
clearTimeout(this.timer);
|
|
122
|
+
if (!this.finished) {
|
|
123
|
+
this.finished = true;
|
|
124
|
+
this.controller.abort(new GrpcError(GrpcStatus.CANCELLED, 'The call was cancelled'));
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
get signal() {
|
|
129
|
+
return this.controller.signal;
|
|
130
|
+
}
|
|
131
|
+
setHeader(key, value) {
|
|
132
|
+
if (this.headersSent) {
|
|
133
|
+
throw new Error('Response metadata is sent with the first response message; set it before.');
|
|
134
|
+
}
|
|
135
|
+
this.responseHeaders[key.toLowerCase()] = value;
|
|
136
|
+
}
|
|
137
|
+
setTrailer(key, value) {
|
|
138
|
+
this.trailers[key.toLowerCase()] = value;
|
|
139
|
+
}
|
|
140
|
+
async run(fn) {
|
|
141
|
+
var _a;
|
|
142
|
+
const { method } = this;
|
|
143
|
+
const input = method.requestStream ? this.requests() : await this.single();
|
|
144
|
+
const output = await fn(input, this);
|
|
145
|
+
if (method.responseStream) {
|
|
146
|
+
const iterator = toAsyncIterator(output, method);
|
|
147
|
+
try {
|
|
148
|
+
for (let r = await iterator.next(); !r.done; r = await iterator.next()) {
|
|
149
|
+
if (this.finished) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
await this.write(r.value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
if (this.finished) {
|
|
157
|
+
await ((_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
await this.write(output !== null && output !== void 0 ? output : {});
|
|
163
|
+
}
|
|
164
|
+
this.finish();
|
|
165
|
+
}
|
|
166
|
+
/** Ends the call with the status of `error`, reporting errors that are not gRPC statuses. */
|
|
167
|
+
fail(error) {
|
|
168
|
+
var _a;
|
|
169
|
+
const status = GrpcError.from(error);
|
|
170
|
+
if (status !== error && status.code === GrpcStatus.UNKNOWN && !this.finished) {
|
|
171
|
+
((_a = this.options.onError) !== null && _a !== void 0 ? _a : console.error)(error, this.method);
|
|
172
|
+
}
|
|
173
|
+
this.finish(status);
|
|
174
|
+
}
|
|
175
|
+
/** Sends the status (OK when `error` is undefined) in the trailers and ends the call. */
|
|
176
|
+
finish(error) {
|
|
177
|
+
var _a;
|
|
178
|
+
if (this.finished) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
this.finished = true;
|
|
182
|
+
clearTimeout(this.timer);
|
|
183
|
+
if (error) {
|
|
184
|
+
this.controller.abort(error);
|
|
185
|
+
}
|
|
186
|
+
if (this.stream.destroyed || this.stream.closed) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const trailers = MetadataUtil.toHeaders({ ...this.trailers, ...error === null || error === void 0 ? void 0 : error.metadata }, { 'grpc-status': String((_a = error === null || error === void 0 ? void 0 : error.code) !== null && _a !== void 0 ? _a : GrpcStatus.OK) });
|
|
190
|
+
if (error === null || error === void 0 ? void 0 : error.details) {
|
|
191
|
+
trailers['grpc-message'] = MetadataUtil.encodeMessage(error.details);
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
if (this.headersSent) {
|
|
195
|
+
this.stream.once('wantTrailers', () => this.stream.sendTrailers(trailers));
|
|
196
|
+
this.stream.end();
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Trailers-Only: the status in the only HEADERS frame.
|
|
200
|
+
this.stream.respond({ ...this.responseHeaderBlock(), ...trailers }, { endStream: true });
|
|
201
|
+
}
|
|
202
|
+
if (!this.stream.readableEnded) {
|
|
203
|
+
this.stream.resume();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (_b) {
|
|
207
|
+
// The client went away meanwhile.
|
|
208
|
+
this.stream.destroy();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
responseHeaderBlock() {
|
|
212
|
+
return MetadataUtil.toHeaders(this.responseHeaders, {
|
|
213
|
+
':status': 200,
|
|
214
|
+
'content-type': 'application/grpc+proto',
|
|
215
|
+
'grpc-accept-encoding': ACCEPT_ENCODING,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async write(message) {
|
|
219
|
+
if (this.finished) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
let framed;
|
|
223
|
+
try {
|
|
224
|
+
framed = MessageFramer.frame(this.method.responseType.encode(message));
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new GrpcError(GrpcStatus.INTERNAL, `Could not encode the response of ${this.method.path}: ${error.message}`);
|
|
228
|
+
}
|
|
229
|
+
if (!this.headersSent) {
|
|
230
|
+
this.headersSent = true;
|
|
231
|
+
this.stream.respond(this.responseHeaderBlock(), { waitForTrailers: true });
|
|
232
|
+
}
|
|
233
|
+
if (!this.stream.write(framed)) {
|
|
234
|
+
await new Promise(resolve => {
|
|
235
|
+
const done = () => {
|
|
236
|
+
this.stream.off('drain', done);
|
|
237
|
+
this.stream.off('close', done);
|
|
238
|
+
resolve();
|
|
239
|
+
};
|
|
240
|
+
this.stream.on('drain', done);
|
|
241
|
+
this.stream.on('close', done);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async single() {
|
|
246
|
+
let request;
|
|
247
|
+
let count = 0;
|
|
248
|
+
for await (const message of this.requests()) {
|
|
249
|
+
request = message;
|
|
250
|
+
count++;
|
|
251
|
+
}
|
|
252
|
+
if (count !== 1) {
|
|
253
|
+
throw new GrpcError(GrpcStatus.INTERNAL, `${this.method.path} takes one request message, received ${count}`);
|
|
254
|
+
}
|
|
255
|
+
return request;
|
|
256
|
+
}
|
|
257
|
+
requests() {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
if (this.requestsRead) {
|
|
260
|
+
throw new Error('The request stream can be read once.');
|
|
261
|
+
}
|
|
262
|
+
this.requestsRead = true;
|
|
263
|
+
const { stream } = this;
|
|
264
|
+
const type = this.method.requestType;
|
|
265
|
+
const queue = new AsyncQueue({ pause: () => stream.pause(), resume: () => stream.resume() });
|
|
266
|
+
let deframer;
|
|
267
|
+
try {
|
|
268
|
+
deframer = new MessageDeframer(String((_a = this.headers['grpc-encoding']) !== null && _a !== void 0 ? _a : 'identity'), (_b = this.options.maxReceiveMessageSize) !== null && _b !== void 0 ? _b : DEFAULT_MAX_RECEIVE_MESSAGE_SIZE);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
queue.end(error);
|
|
272
|
+
return queue;
|
|
273
|
+
}
|
|
274
|
+
let failed = false;
|
|
275
|
+
stream.on('data', (chunk) => {
|
|
276
|
+
if (failed) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
for (const message of deframer.push(chunk)) {
|
|
281
|
+
queue.push(decode(type, message));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
failed = true;
|
|
286
|
+
queue.end(error);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
stream.once('end', () => queue.end(deframer.pending ? new GrpcError(GrpcStatus.INTERNAL, 'The request stream ended in the middle of a message') : undefined));
|
|
290
|
+
this.signal.addEventListener('abort', () => queue.end(this.signal.reason), { once: true });
|
|
291
|
+
return queue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function decode(type, message) {
|
|
295
|
+
try {
|
|
296
|
+
return type.decode(message);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
throw new GrpcError(GrpcStatus.INTERNAL, `Could not parse a ${type.fullName}: ${error.message}`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function toAsyncIterator(output, method) {
|
|
303
|
+
if (output && typeof output[Symbol.asyncIterator] === 'function') {
|
|
304
|
+
return output[Symbol.asyncIterator]();
|
|
305
|
+
}
|
|
306
|
+
if (output && typeof output[Symbol.iterator] === 'function') {
|
|
307
|
+
const iterator = output[Symbol.iterator]();
|
|
308
|
+
return { next: async () => iterator.next(), return: async () => { var _a; var _b; return (_b = (_a = iterator.return) === null || _a === void 0 ? void 0 : _a.call(iterator)) !== null && _b !== void 0 ? _b : { done: true, value: undefined }; } };
|
|
309
|
+
}
|
|
310
|
+
throw new GrpcError(GrpcStatus.INTERNAL, `${method.path} streams its responses: the method must return an (async) iterable, such as an async generator.`);
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=grpc-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-server.js","sourceRoot":"","sources":["../../../src/node/server/grpc-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA+F,MAAM,YAAY,CAAC;AAEvI,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC3H,OAAO,EAAiB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAyC/D;;;;;;;GAOG;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
1
|
+
import { type ComponentOption } from '@celljs/core';
|
|
2
|
+
import type { ServiceDefinition } from '../proto/proto.js';
|
|
3
|
+
/** DI id of every {@link GrpcService} component. */
|
|
4
|
+
export declare const GRPC_SERVICE: unique symbol;
|
|
5
|
+
export declare const GRPC_SERVICE_TAG = "GrpcService";
|
|
6
|
+
/**
|
|
7
|
+
* Serves the class as the implementation of a gRPC service on the application's gRPC server
|
|
8
|
+
* (`cell.grpc.server`, port 50051 by default). Methods are named after the .proto methods in
|
|
9
|
+
* lowerCamelCase; the class is a component, so it can `@Autowired` others.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* @GrpcService(Greeter)
|
|
13
|
+
* export class GreeterService {
|
|
14
|
+
* sayHello({ name }: HelloRequest): HelloReply {
|
|
15
|
+
* return { message: `Hello ${name}` };
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function GrpcService(service: ServiceDefinition, option?: ComponentOption): ClassDecorator;
|
|
21
|
+
export declare namespace GrpcServiceUtil {
|
|
22
|
+
/** The service a {@link GrpcService} class implements. */
|
|
23
|
+
function getService(target: object): ServiceDefinition | undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Component, parseComponentOption } from '@celljs/core';
|
|
2
|
+
/** DI id of every {@link GrpcService} component. */
|
|
3
|
+
export const GRPC_SERVICE = Symbol('GrpcService');
|
|
4
|
+
export const GRPC_SERVICE_TAG = 'GrpcService';
|
|
5
|
+
const SERVICE_KEY = 'cell:grpc-service';
|
|
6
|
+
/**
|
|
7
|
+
* Serves the class as the implementation of a gRPC service on the application's gRPC server
|
|
8
|
+
* (`cell.grpc.server`, port 50051 by default). Methods are named after the .proto methods in
|
|
9
|
+
* lowerCamelCase; the class is a component, so it can `@Autowired` others.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* @GrpcService(Greeter)
|
|
13
|
+
* export class GreeterService {
|
|
14
|
+
* sayHello({ name }: HelloRequest): HelloReply {
|
|
15
|
+
* return { message: `Hello ${name}` };
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function GrpcService(service, option) {
|
|
21
|
+
return target => {
|
|
22
|
+
var _a;
|
|
23
|
+
const parsed = parseComponentOption(target, option !== null && option !== void 0 ? option : {});
|
|
24
|
+
parsed.id.push(GRPC_SERVICE);
|
|
25
|
+
parsed.sysTags = [...((_a = parsed.sysTags) !== null && _a !== void 0 ? _a : []), GRPC_SERVICE_TAG];
|
|
26
|
+
Reflect.defineMetadata(SERVICE_KEY, service, target);
|
|
27
|
+
Component(parsed)(target);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export var GrpcServiceUtil;
|
|
31
|
+
(function (GrpcServiceUtil) {
|
|
32
|
+
/** The service a {@link GrpcService} class implements. */
|
|
33
|
+
function getService(target) {
|
|
34
|
+
return Reflect.getOwnMetadata(SERVICE_KEY, target);
|
|
35
|
+
}
|
|
36
|
+
GrpcServiceUtil.getService = getService;
|
|
37
|
+
})(GrpcServiceUtil || (GrpcServiceUtil = {}));
|
|
38
|
+
//# sourceMappingURL=grpc-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grpc-service.js","sourceRoot":"","sources":["../../../src/node/server/grpc-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA0C,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGvG,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAE9C,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,OAA0B,EAAE,MAAwB;IAC5E,OAAO,MAAM,CAAC,EAAE;;QACZ,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC;QACzD,MAAM,CAAC,EAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAG,OAAC,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;QAC/D,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC;AACN,CAAC;AAED,MAAM,KAAW,eAAe,CAK/B;AALD,WAAiB,eAAe;IAC5B,0DAA0D;IAC1D,SAAgB,UAAU,CAAC,MAAc;QACrC,OAAO,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;IAFe,gBAAA,UAAU,aAEzB,CAAA;AACL,CAAC,EALgB,eAAe,KAAf,eAAe,QAK/B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mkdtempSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { loadSync } from '@grpc/proto-loader';
|
|
5
|
+
import { TEST_PROTO } from './test-protos.js';
|
|
6
|
+
/** TEST_PROTO loaded by @grpc/proto-loader (protobuf.js), the reference implementation of the tests. */
|
|
7
|
+
export function loadTestProto() {
|
|
8
|
+
const dir = mkdtempSync(join(tmpdir(), 'cell-grpc-'));
|
|
9
|
+
const file = join(dir, 'test.proto');
|
|
10
|
+
writeFileSync(file, TEST_PROTO);
|
|
11
|
+
return loadSync(file, { keepCase: false, longs: String, enums: String, defaults: true, oneofs: true });
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=proto-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto-loader.js","sourceRoot":"","sources":["../../../src/node/test/proto-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,wGAAwG;AACxG,MAAM,UAAU,aAAa;IACzB,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACrC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAChC,OAAO,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ServerCall } from '../server/grpc-server.js';
|
|
2
|
+
/** The .proto of the package's tests: every field kind, and a service with every kind of method. */
|
|
3
|
+
export declare const TEST_PROTO = "\nsyntax = \"proto3\";\npackage cell.test;\n\nimport \"google/protobuf/empty.proto\";\nimport \"google/protobuf/timestamp.proto\";\n\n// Colors.\nenum Color {\n COLOR_UNSPECIFIED = 0;\n RED = 1;\n GREEN = 2 [deprecated = true];\n}\n\nmessage Scalars {\n double d = 1;\n float f = 2;\n int32 i32 = 3;\n int64 i64 = 4;\n uint32 u32 = 5;\n uint64 u64 = 6;\n sint32 s32 = 7;\n sint64 s64 = 8;\n fixed32 fx32 = 9;\n fixed64 fx64 = 10;\n sfixed32 sfx32 = 11;\n sfixed64 sfx64 = 12;\n bool flag = 13;\n string text = 14;\n bytes data = 15;\n Color color = 16;\n}\n\n/* Everything else. */\nmessage Everything {\n option deprecated = false;\n Scalars scalars = 1;\n repeated int32 numbers = 2;\n repeated string names = 3;\n repeated Scalars items = 4;\n map<string, int32> counts = 5;\n map<int64, Scalars> by_id = 6;\n oneof choice {\n string label = 7;\n int32 code = 8;\n Scalars nested = 9;\n }\n optional int32 maybe = 10;\n google.protobuf.Timestamp at = 11;\n repeated Color colors = 12;\n message Inner { string value = 1; }\n Inner inner = 13;\n string snake_case_name = 14;\n reserved 100 to 110;\n}\n\nmessage HelloRequest {\n string name = 1;\n int32 count = 2;\n bytes payload = 3;\n}\n\nmessage HelloReply {\n string message = 1;\n bytes payload = 2;\n}\n\nservice Greeter {\n option deprecated = false;\n rpc SayHello (HelloRequest) returns (HelloReply);\n rpc SayHellos (HelloRequest) returns (stream HelloReply);\n rpc CollectHellos (stream HelloRequest) returns (HelloReply);\n rpc Chat (stream HelloRequest) returns (stream HelloReply) {\n option deprecated = false;\n }\n rpc Echo (Everything) returns (Everything);\n rpc Nothing (google.protobuf.Empty) returns (google.protobuf.Empty);\n}\n";
|
|
4
|
+
interface HelloRequest {
|
|
5
|
+
name: string;
|
|
6
|
+
count: number;
|
|
7
|
+
payload: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
/** An implementation of cell.test.Greeter whose answers depend on the request, for the tests. */
|
|
10
|
+
export declare class TestGreeter {
|
|
11
|
+
sayHello(request: HelloRequest, call: ServerCall): Promise<unknown> | {
|
|
12
|
+
message: string;
|
|
13
|
+
payload: Uint8Array<ArrayBufferLike>;
|
|
14
|
+
};
|
|
15
|
+
sayHellos(request: HelloRequest, call: ServerCall): AsyncGenerator<{
|
|
16
|
+
message: string;
|
|
17
|
+
}, void, unknown>;
|
|
18
|
+
collectHellos(requests: AsyncIterable<HelloRequest>): Promise<{
|
|
19
|
+
message: string;
|
|
20
|
+
}>;
|
|
21
|
+
chat(requests: AsyncIterable<HelloRequest>): AsyncGenerator<{
|
|
22
|
+
message: string;
|
|
23
|
+
}, void, unknown>;
|
|
24
|
+
echo(message: unknown): unknown;
|
|
25
|
+
nothing(): {};
|
|
26
|
+
}
|
|
27
|
+
export declare function collect<T>(iterable: AsyncIterable<T>): Promise<T[]>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { GrpcError, GrpcStatus } from '../call/grpc-status.js';
|
|
2
|
+
/** The .proto of the package's tests: every field kind, and a service with every kind of method. */
|
|
3
|
+
export const TEST_PROTO = `
|
|
4
|
+
syntax = "proto3";
|
|
5
|
+
package cell.test;
|
|
6
|
+
|
|
7
|
+
import "google/protobuf/empty.proto";
|
|
8
|
+
import "google/protobuf/timestamp.proto";
|
|
9
|
+
|
|
10
|
+
// Colors.
|
|
11
|
+
enum Color {
|
|
12
|
+
COLOR_UNSPECIFIED = 0;
|
|
13
|
+
RED = 1;
|
|
14
|
+
GREEN = 2 [deprecated = true];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
message Scalars {
|
|
18
|
+
double d = 1;
|
|
19
|
+
float f = 2;
|
|
20
|
+
int32 i32 = 3;
|
|
21
|
+
int64 i64 = 4;
|
|
22
|
+
uint32 u32 = 5;
|
|
23
|
+
uint64 u64 = 6;
|
|
24
|
+
sint32 s32 = 7;
|
|
25
|
+
sint64 s64 = 8;
|
|
26
|
+
fixed32 fx32 = 9;
|
|
27
|
+
fixed64 fx64 = 10;
|
|
28
|
+
sfixed32 sfx32 = 11;
|
|
29
|
+
sfixed64 sfx64 = 12;
|
|
30
|
+
bool flag = 13;
|
|
31
|
+
string text = 14;
|
|
32
|
+
bytes data = 15;
|
|
33
|
+
Color color = 16;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/* Everything else. */
|
|
37
|
+
message Everything {
|
|
38
|
+
option deprecated = false;
|
|
39
|
+
Scalars scalars = 1;
|
|
40
|
+
repeated int32 numbers = 2;
|
|
41
|
+
repeated string names = 3;
|
|
42
|
+
repeated Scalars items = 4;
|
|
43
|
+
map<string, int32> counts = 5;
|
|
44
|
+
map<int64, Scalars> by_id = 6;
|
|
45
|
+
oneof choice {
|
|
46
|
+
string label = 7;
|
|
47
|
+
int32 code = 8;
|
|
48
|
+
Scalars nested = 9;
|
|
49
|
+
}
|
|
50
|
+
optional int32 maybe = 10;
|
|
51
|
+
google.protobuf.Timestamp at = 11;
|
|
52
|
+
repeated Color colors = 12;
|
|
53
|
+
message Inner { string value = 1; }
|
|
54
|
+
Inner inner = 13;
|
|
55
|
+
string snake_case_name = 14;
|
|
56
|
+
reserved 100 to 110;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
message HelloRequest {
|
|
60
|
+
string name = 1;
|
|
61
|
+
int32 count = 2;
|
|
62
|
+
bytes payload = 3;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
message HelloReply {
|
|
66
|
+
string message = 1;
|
|
67
|
+
bytes payload = 2;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
service Greeter {
|
|
71
|
+
option deprecated = false;
|
|
72
|
+
rpc SayHello (HelloRequest) returns (HelloReply);
|
|
73
|
+
rpc SayHellos (HelloRequest) returns (stream HelloReply);
|
|
74
|
+
rpc CollectHellos (stream HelloRequest) returns (HelloReply);
|
|
75
|
+
rpc Chat (stream HelloRequest) returns (stream HelloReply) {
|
|
76
|
+
option deprecated = false;
|
|
77
|
+
}
|
|
78
|
+
rpc Echo (Everything) returns (Everything);
|
|
79
|
+
rpc Nothing (google.protobuf.Empty) returns (google.protobuf.Empty);
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
/** An implementation of cell.test.Greeter whose answers depend on the request, for the tests. */
|
|
83
|
+
export class TestGreeter {
|
|
84
|
+
sayHello(request, call) {
|
|
85
|
+
if (request.name === 'fail') {
|
|
86
|
+
throw new GrpcError(GrpcStatus.INVALID_ARGUMENT, 'name must not be "fail" — ünïcode', { 'x-reason': 'bad name' });
|
|
87
|
+
}
|
|
88
|
+
if (request.name === 'crash') {
|
|
89
|
+
throw new Error('boom');
|
|
90
|
+
}
|
|
91
|
+
if (request.name === 'slow') {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const timer = setTimeout(() => resolve({ message: 'late' }), 2000);
|
|
94
|
+
call.signal.addEventListener('abort', () => {
|
|
95
|
+
clearTimeout(timer);
|
|
96
|
+
reject(call.signal.reason);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
call.setHeader('x-greeting', 'hi');
|
|
101
|
+
call.setTrailer('x-done', 'yes');
|
|
102
|
+
const user = call.metadata['x-user'];
|
|
103
|
+
const token = call.metadata['x-token-bin'];
|
|
104
|
+
const suffix = (user ? ` (${user})` : '') + (token instanceof Uint8Array ? ` [${[...token].join(',')}]` : '');
|
|
105
|
+
return { message: `Hello ${request.name}${suffix}`, payload: request.payload };
|
|
106
|
+
}
|
|
107
|
+
async *sayHellos(request, call) {
|
|
108
|
+
for (let i = 0; i < request.count; i++) {
|
|
109
|
+
if (call.signal.aborted) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (request.name === 'fail' && i === 2) {
|
|
113
|
+
throw new GrpcError(GrpcStatus.ABORTED, 'stopped at 2');
|
|
114
|
+
}
|
|
115
|
+
yield { message: `Hello ${request.name} ${i}` };
|
|
116
|
+
await new Promise(r => setTimeout(r, 1));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async collectHellos(requests) {
|
|
120
|
+
const names = [];
|
|
121
|
+
for await (const request of requests) {
|
|
122
|
+
names.push(request.name);
|
|
123
|
+
}
|
|
124
|
+
return { message: `Hello ${names.join(', ')}` };
|
|
125
|
+
}
|
|
126
|
+
async *chat(requests) {
|
|
127
|
+
for await (const request of requests) {
|
|
128
|
+
yield { message: `> ${request.name}` };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
echo(message) {
|
|
132
|
+
return message;
|
|
133
|
+
}
|
|
134
|
+
nothing() {
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function collect(iterable) {
|
|
139
|
+
const items = [];
|
|
140
|
+
for await (const item of iterable) {
|
|
141
|
+
items.push(item);
|
|
142
|
+
}
|
|
143
|
+
return items;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=test-protos.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-protos.js","sourceRoot":"","sources":["../../../src/node/test/test-protos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAG5D,oGAAoG;AACpG,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8EzB,CAAC;AAQF,iGAAiG;AACjG,MAAM,OAAO,WAAW;IACpB,QAAQ,CAAC,OAAqB,EAAE,IAAgB;QAC5C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,MAAM,IAAI,SAAS,CAAC,UAAU,CAAC,gBAAgB,EAAE,mCAAmC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QACtH,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACnC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;gBACnE,IAAI,C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CAAC,CAAC;YAC5D,CAAC;YACD,MAAM,EAAE,OAAO,EAAE,SAAS,OAAO,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YAChD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAAqC;QACrD,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,SAAS,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,CAAC,IAAI,CAAC,QAAqC;QAC7C,IAAI,KAAK,EAAE,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YACnC,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAgB;QACjB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,OAAO;QACH,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAI,QAA0B;IACvD,MAAM,KAAK,GAAQ,EAAE,CAAC;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The messages of a stream as an async iterable. `pause` is called when `highWaterMark` messages are
|
|
3
|
+
* waiting, `resume` once the consumer has taken them all; `onReturn` when the consumer stops early.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AsyncQueue<T> implements AsyncIterable<T> {
|
|
6
|
+
protected readonly options: {
|
|
7
|
+
highWaterMark?: number;
|
|
8
|
+
pause?: () => void;
|
|
9
|
+
resume?: () => void;
|
|
10
|
+
onReturn?: () => void;
|
|
11
|
+
};
|
|
12
|
+
protected readonly items: T[];
|
|
13
|
+
protected waiter?: {
|
|
14
|
+
resolve: (result: IteratorResult<T>) => void;
|
|
15
|
+
reject: (error: unknown) => void;
|
|
16
|
+
};
|
|
17
|
+
protected ended: boolean;
|
|
18
|
+
protected error: unknown;
|
|
19
|
+
protected paused: boolean;
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
highWaterMark?: number;
|
|
22
|
+
pause?: () => void;
|
|
23
|
+
resume?: () => void;
|
|
24
|
+
onReturn?: () => void;
|
|
25
|
+
});
|
|
26
|
+
push(item: T): void;
|
|
27
|
+
/** Ends the iteration, with `error` thrown to the consumer once the waiting messages are taken. */
|
|
28
|
+
end(error?: unknown): void;
|
|
29
|
+
next(): Promise<IteratorResult<T>>;
|
|
30
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=async-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-queue.d.ts","sourceRoot":"","sources":["../../../src/node/call/async-queue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAOtC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;KAAE;IANlI,SAAS,CAAC,QAAQ,CA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