ts-proto 1.121.6 → 1.122.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/CHANGELOG.md +7 -0
- package/build/generate-grpc-web.js +5 -6
- package/build/main.js +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.122.0](https://github.com/stephenh/ts-proto/compare/v1.121.6...v1.122.0) (2022-08-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **Grpc-Web:** Add & export GrpcWebError type ([#593](https://github.com/stephenh/ts-proto/issues/593)) ([645987d](https://github.com/stephenh/ts-proto/commit/645987d023e666290e87086f5a0770c34e2fe978))
|
|
7
|
+
|
|
1
8
|
## [1.121.6](https://github.com/stephenh/ts-proto/compare/v1.121.5...v1.121.6) (2022-08-14)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -188,7 +188,7 @@ function generateGrpcWebImpl(ctx, returnObservable, hasStreamingMethods) {
|
|
|
188
188
|
chunks.push(createObservableUnaryMethod(ctx));
|
|
189
189
|
}
|
|
190
190
|
else {
|
|
191
|
-
chunks.push(createPromiseUnaryMethod());
|
|
191
|
+
chunks.push(createPromiseUnaryMethod(ctx));
|
|
192
192
|
}
|
|
193
193
|
if (hasStreamingMethods) {
|
|
194
194
|
chunks.push(createInvokeMethod(ctx));
|
|
@@ -196,7 +196,7 @@ function generateGrpcWebImpl(ctx, returnObservable, hasStreamingMethods) {
|
|
|
196
196
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
197
197
|
return (0, ts_poet_1.joinCode)(chunks, { trim: false });
|
|
198
198
|
}
|
|
199
|
-
function createPromiseUnaryMethod() {
|
|
199
|
+
function createPromiseUnaryMethod(ctx) {
|
|
200
200
|
return (0, ts_poet_1.code) `
|
|
201
201
|
unary<T extends UnaryMethodDefinitionish>(
|
|
202
202
|
methodDesc: T,
|
|
@@ -219,9 +219,7 @@ function createPromiseUnaryMethod() {
|
|
|
219
219
|
if (response.status === grpc.Code.OK) {
|
|
220
220
|
resolve(response.message);
|
|
221
221
|
} else {
|
|
222
|
-
const err = new
|
|
223
|
-
err.code = response.status;
|
|
224
|
-
err.metadata = response.trailers;
|
|
222
|
+
const err = new ${ctx.utils.GrpcWebError}(response.statusMessage, response.status, response.trailers);
|
|
225
223
|
reject(err);
|
|
226
224
|
}
|
|
227
225
|
},
|
|
@@ -251,7 +249,8 @@ function createObservableUnaryMethod(ctx) {
|
|
|
251
249
|
debug: this.options.debug,
|
|
252
250
|
onEnd: (next) => {
|
|
253
251
|
if (next.status !== 0) {
|
|
254
|
-
|
|
252
|
+
const err = new ${ctx.utils.GrpcWebError}(next.statusMessage, next.status, next.trailers);
|
|
253
|
+
observer.error(err);
|
|
255
254
|
} else {
|
|
256
255
|
observer.next(next.message as any);
|
|
257
256
|
observer.complete();
|
package/build/main.js
CHANGED
|
@@ -221,6 +221,7 @@ function makeUtils(options) {
|
|
|
221
221
|
...longs,
|
|
222
222
|
...makeComparisonUtils(),
|
|
223
223
|
...makeNiceGrpcServerStreamingMethodResult(),
|
|
224
|
+
...makeGrpcWebErrorClass(),
|
|
224
225
|
};
|
|
225
226
|
}
|
|
226
227
|
exports.makeUtils = makeUtils;
|
|
@@ -472,6 +473,16 @@ function makeNiceGrpcServerStreamingMethodResult() {
|
|
|
472
473
|
`);
|
|
473
474
|
return { NiceGrpcServerStreamingMethodResult };
|
|
474
475
|
}
|
|
476
|
+
function makeGrpcWebErrorClass() {
|
|
477
|
+
const GrpcWebError = (0, ts_poet_1.conditionalOutput)('GrpcWebError', (0, ts_poet_1.code) `
|
|
478
|
+
export class GrpcWebError extends Error {
|
|
479
|
+
constructor(message: string, public code: grpc.Code, public metadata: grpc.Metadata) {
|
|
480
|
+
super(message);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
`);
|
|
484
|
+
return { GrpcWebError };
|
|
485
|
+
}
|
|
475
486
|
// Create the interface with properties
|
|
476
487
|
function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fullTypeName) {
|
|
477
488
|
var _a;
|