ts-proto 1.105.1 → 1.105.2
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/README.markdown +47 -0
- package/build/options.js +11 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.105.2](https://github.com/stephenh/ts-proto/compare/v1.105.1...v1.105.2) (2022-02-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Fix snakeToCamel single value parsing. ([#513](https://github.com/stephenh/ts-proto/issues/513)) ([e1ad866](https://github.com/stephenh/ts-proto/commit/e1ad866c95751c37ed13f02f4da2dc9076ab4758))
|
|
7
|
+
|
|
1
8
|
## [1.105.1](https://github.com/stephenh/ts-proto/compare/v1.105.0...v1.105.1) (2022-02-14)
|
|
2
9
|
|
|
3
10
|
|
package/README.markdown
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
- [Only Types](#only-types)
|
|
24
24
|
- [NestJS Support](#nestjs-support)
|
|
25
25
|
- [Watch Mode](#watch-mode)
|
|
26
|
+
- [Basic gRPC implementation](#basic-grpc-implementation)
|
|
26
27
|
- [Sponsors](#sponsors)
|
|
27
28
|
- [Development](#development)
|
|
28
29
|
- [Assumptions](#assumptions)
|
|
@@ -406,6 +407,51 @@ If you want to run `ts-proto` on every change of a proto file, you'll need to us
|
|
|
406
407
|
"proto:watch": "chokidar \"**/*.proto\" -c \"npm run proto:generate\""
|
|
407
408
|
```
|
|
408
409
|
|
|
410
|
+
### Basic gRPC implementation
|
|
411
|
+
|
|
412
|
+
`ts-proto` is RPC framework agnostic - how you transmit your data to and from
|
|
413
|
+
your data source is up to you. The generated client implementations all expect
|
|
414
|
+
a `rpc` parameter, which type is defined like this:
|
|
415
|
+
|
|
416
|
+
```ts
|
|
417
|
+
interface Rpc {
|
|
418
|
+
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
If you're working with gRPC, a simple implementation could look like this:
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
type RpcImpl = (service: string, method: string, data: Uint8Array) => Promise<Uint8Array>;
|
|
426
|
+
|
|
427
|
+
const sendRequest: RpcImpl = (service, method, data) => {
|
|
428
|
+
// Conventionally in gRPC, the request path looks like
|
|
429
|
+
// "package.names.ServiceName/MethodName",
|
|
430
|
+
// we therefore construct such a string
|
|
431
|
+
const path = `${service}/${method}`;
|
|
432
|
+
|
|
433
|
+
return new Promise((resolve, reject) => {
|
|
434
|
+
// makeUnaryRequest transmits the result (and error) with a callback
|
|
435
|
+
// transform this into a promise!
|
|
436
|
+
const resultCallback: UnaryCallback<any> = (err, res) => {
|
|
437
|
+
if (err) {
|
|
438
|
+
return reject(err);
|
|
439
|
+
}
|
|
440
|
+
resolve(res);
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
function passThrough(argument: any) {
|
|
444
|
+
return argument;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Using passThrough as the serialize and deserialize functions
|
|
448
|
+
conn.makeUnaryRequest(path, passThrough, passThrough, data, resultCallback);
|
|
449
|
+
});
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const rpc: Rpc = { request: sendRequest }
|
|
453
|
+
```
|
|
454
|
+
|
|
409
455
|
# Sponsors
|
|
410
456
|
|
|
411
457
|
Kudos to our sponsors:
|
|
@@ -591,6 +637,7 @@ Their interpretation is defined by the Protobuf specification, and libraries are
|
|
|
591
637
|
* [google.protobuf.Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#Value) ⇆ `any | undefined` (i.e. `number | string | boolean | null | array | object`)
|
|
592
638
|
* [google.protobuf.ListValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#ListValue) ⇆ `any[]`
|
|
593
639
|
* [google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#Struct) ⇆ `{ [key: string]: any } | undefined`
|
|
640
|
+
* [google.protobuf.FieldMask](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask) ⇆ `string[]` (only in the JSON, `FieldMask` is still a message)
|
|
594
641
|
|
|
595
642
|
## Wrapper Types
|
|
596
643
|
|
package/build/options.js
CHANGED
|
@@ -111,6 +111,9 @@ function optionsFromParameter(parameter) {
|
|
|
111
111
|
else if (options.snakeToCamel === true) {
|
|
112
112
|
options.snakeToCamel = ['keys', 'json'];
|
|
113
113
|
}
|
|
114
|
+
else if (typeof options.snakeToCamel === 'string') {
|
|
115
|
+
options.snakeToCamel = [options.snakeToCamel];
|
|
116
|
+
}
|
|
114
117
|
return options;
|
|
115
118
|
}
|
|
116
119
|
exports.optionsFromParameter = optionsFromParameter;
|
|
@@ -118,8 +121,14 @@ exports.optionsFromParameter = optionsFromParameter;
|
|
|
118
121
|
function parseParameter(parameter) {
|
|
119
122
|
const options = {};
|
|
120
123
|
const pairs = parameter.split(',').map((s) => s.split('='));
|
|
121
|
-
pairs.forEach(([key,
|
|
122
|
-
|
|
124
|
+
pairs.forEach(([key, _value]) => {
|
|
125
|
+
const value = _value === 'true' ? true : _value === 'false' ? false : _value;
|
|
126
|
+
if (options[key]) {
|
|
127
|
+
options[key] = [options[key], value];
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
options[key] = value;
|
|
131
|
+
}
|
|
123
132
|
});
|
|
124
133
|
return options;
|
|
125
134
|
}
|