ts-proto 1.147.1 → 1.147.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/README.markdown +2 -2
- package/build/generate-grpc-web.js +9 -13
- package/build/generate-services.js +1 -1
- package/build/main.js +4 -4
- package/build/types.js +7 -2
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -78,7 +78,7 @@ It will also generate client implementations of `PingService`; currently [Twirp]
|
|
|
78
78
|
- `npm install ts-proto`
|
|
79
79
|
- `protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=. ./simple.proto`
|
|
80
80
|
- (Note that the output parameter name, `ts_proto_out`, is named based on the suffix of the plugin's name, i.e. "ts_proto" suffix in the `--plugin=./node_modules/.bin/protoc-gen-ts_proto` parameter becomes the `_out` prefix, per `protoc`'s CLI conventions.)
|
|
81
|
-
- On Windows, use `protoc --plugin=protoc-gen-ts_proto
|
|
81
|
+
- On Windows, use `protoc --plugin=protoc-gen-ts_proto=".\\node_modules\\.bin\\protoc-gen-ts_proto.cmd" --ts_proto_out=. ./simple.proto` (see [#93](https://github.com/stephenh/ts-proto/issues/93))
|
|
82
82
|
- Ensure you're using a modern `protoc`, i.e. the original `protoc` `3.0.0` doesn't support the `_opt` flag
|
|
83
83
|
|
|
84
84
|
This will generate `*.ts` source files for the given `*.proto` types.
|
|
@@ -110,7 +110,7 @@ You can also use the official plugin published to the Buf Registry.
|
|
|
110
110
|
```yaml
|
|
111
111
|
version: v1
|
|
112
112
|
plugins:
|
|
113
|
-
-
|
|
113
|
+
- plugin: buf.build/community/stephenh-ts-proto
|
|
114
114
|
out: ../gen/ts
|
|
115
115
|
opt:
|
|
116
116
|
- outputServices=...
|
|
@@ -214,12 +214,10 @@ function createPromiseUnaryMethod(ctx) {
|
|
|
214
214
|
const { useAbortSignal } = options;
|
|
215
215
|
const maybeAbortSignal = useAbortSignal
|
|
216
216
|
? `
|
|
217
|
-
|
|
217
|
+
if (abortSignal) abortSignal.addEventListener("abort", () => {
|
|
218
218
|
client.close();
|
|
219
|
-
reject(
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (abortSignal) abortSignal.addEventListener("abort", abortHandler);`
|
|
219
|
+
reject(abortSignal.reason);
|
|
220
|
+
});`
|
|
223
221
|
: "";
|
|
224
222
|
return (0, ts_poet_1.code) `
|
|
225
223
|
unary<T extends UnaryMethodDefinitionish>(
|
|
@@ -260,11 +258,10 @@ function createObservableUnaryMethod(ctx) {
|
|
|
260
258
|
const { useAbortSignal } = options;
|
|
261
259
|
const maybeAbortSignal = useAbortSignal
|
|
262
260
|
? `
|
|
263
|
-
|
|
264
|
-
observer.error(
|
|
261
|
+
if (abortSignal) abortSignal.addEventListener("abort", () => {
|
|
262
|
+
observer.error(abortSignal.reason);
|
|
265
263
|
client.close();
|
|
266
|
-
}
|
|
267
|
-
if (abortSignal) abortSignal.addEventListener("abort", abortHandler);`
|
|
264
|
+
});`
|
|
268
265
|
: "";
|
|
269
266
|
return (0, ts_poet_1.code) `
|
|
270
267
|
unary<T extends UnaryMethodDefinitionish>(
|
|
@@ -308,11 +305,10 @@ function createInvokeMethod(ctx) {
|
|
|
308
305
|
const { useAbortSignal } = options;
|
|
309
306
|
const maybeAbortSignal = useAbortSignal
|
|
310
307
|
? `
|
|
311
|
-
|
|
312
|
-
observer.error(
|
|
308
|
+
if (abortSignal) abortSignal.addEventListener("abort", () => {
|
|
309
|
+
observer.error(abortSignal.reason);
|
|
313
310
|
client.close();
|
|
314
|
-
}
|
|
315
|
-
if (abortSignal) abortSignal.addEventListener("abort", abortHandler);`
|
|
311
|
+
});`
|
|
316
312
|
: "";
|
|
317
313
|
return (0, ts_poet_1.code) `
|
|
318
314
|
invoke<T extends UnaryMethodDefinitionish>(
|
|
@@ -278,7 +278,7 @@ function generateRpcType(ctx, hasStreamingMethods) {
|
|
|
278
278
|
const maybeAbortSignalParam = options.useAbortSignal ? "abortSignal?: AbortSignal," : "";
|
|
279
279
|
const methods = [[(0, ts_poet_1.code) `request`, (0, ts_poet_1.code) `Uint8Array`, (0, ts_poet_1.code) `Promise<Uint8Array>`]];
|
|
280
280
|
if (hasStreamingMethods) {
|
|
281
|
-
const observable = (0, types_1.observableType)(ctx);
|
|
281
|
+
const observable = (0, types_1.observableType)(ctx, true);
|
|
282
282
|
methods.push([(0, ts_poet_1.code) `clientStreamingRequest`, (0, ts_poet_1.code) `${observable}<Uint8Array>`, (0, ts_poet_1.code) `Promise<Uint8Array>`]);
|
|
283
283
|
methods.push([(0, ts_poet_1.code) `serverStreamingRequest`, (0, ts_poet_1.code) `Uint8Array`, (0, ts_poet_1.code) `${observable}<Uint8Array>`]);
|
|
284
284
|
methods.push([
|
package/build/main.js
CHANGED
|
@@ -507,15 +507,15 @@ function makeTimestampMethods(options, longs) {
|
|
|
507
507
|
const fromTimestamp = (0, ts_poet_1.conditionalOutput)("fromTimestamp", options.useDate === options_1.DateOption.STRING
|
|
508
508
|
? (0, ts_poet_1.code) `
|
|
509
509
|
function fromTimestamp(t: ${Timestamp}): string {
|
|
510
|
-
let millis = ${toNumberCode} * 1_000;
|
|
511
|
-
millis += t.nanos / 1_000_000;
|
|
510
|
+
let millis = (${toNumberCode} || 0) * 1_000;
|
|
511
|
+
millis += (t.nanos || 0) / 1_000_000;
|
|
512
512
|
return new Date(millis).toISOString();
|
|
513
513
|
}
|
|
514
514
|
`
|
|
515
515
|
: (0, ts_poet_1.code) `
|
|
516
516
|
function fromTimestamp(t: ${Timestamp}): Date {
|
|
517
|
-
let millis = ${toNumberCode} * 1_000;
|
|
518
|
-
millis += t.nanos / 1_000_000;
|
|
517
|
+
let millis = (${toNumberCode} || 0) * 1_000;
|
|
518
|
+
millis += (t.nanos || 0) / 1_000_000;
|
|
519
519
|
return new Date(millis);
|
|
520
520
|
}
|
|
521
521
|
`);
|
package/build/types.js
CHANGED
|
@@ -639,11 +639,16 @@ function rawRequestType(ctx, methodDesc, typeOptions = {}) {
|
|
|
639
639
|
return messageToTypeName(ctx, methodDesc.inputType, typeOptions);
|
|
640
640
|
}
|
|
641
641
|
exports.rawRequestType = rawRequestType;
|
|
642
|
-
function observableType(ctx) {
|
|
642
|
+
function observableType(ctx, asType = false) {
|
|
643
643
|
if (ctx.options.useAsyncIterable) {
|
|
644
644
|
return (0, ts_poet_1.code) `AsyncIterable`;
|
|
645
645
|
}
|
|
646
|
-
|
|
646
|
+
else if (asType) {
|
|
647
|
+
return (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("t:Observable@rxjs")}`;
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
return (0, ts_poet_1.code) `${(0, ts_poet_1.imp)("Observable@rxjs")}`;
|
|
651
|
+
}
|
|
647
652
|
}
|
|
648
653
|
exports.observableType = observableType;
|
|
649
654
|
function requestType(ctx, methodDesc, partial = false) {
|