ts-proto 1.104.1 → 1.106.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 +28 -0
- package/README.markdown +48 -1
- package/build/main.js +27 -19
- package/build/options.js +11 -2
- package/build/schema.js +2 -1
- package/build/types.js +9 -1
- package/build/utils.js +16 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.106.0](https://github.com/stephenh/ts-proto/compare/v1.105.2...v1.106.0) (2022-02-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Support json names containing non-alphanumeric characters ([#520](https://github.com/stephenh/ts-proto/issues/520)) ([ce44668](https://github.com/stephenh/ts-proto/commit/ce44668b8fe01b14f50ac3c5c950f73db769fa76))
|
|
7
|
+
|
|
8
|
+
## [1.105.2](https://github.com/stephenh/ts-proto/compare/v1.105.1...v1.105.2) (2022-02-17)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* Fix snakeToCamel single value parsing. ([#513](https://github.com/stephenh/ts-proto/issues/513)) ([e1ad866](https://github.com/stephenh/ts-proto/commit/e1ad866c95751c37ed13f02f4da2dc9076ab4758))
|
|
14
|
+
|
|
15
|
+
## [1.105.1](https://github.com/stephenh/ts-proto/compare/v1.105.0...v1.105.1) (2022-02-14)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* generate canonical JSON encoding for FieldMasks ([#510](https://github.com/stephenh/ts-proto/issues/510)) ([0ec4e97](https://github.com/stephenh/ts-proto/commit/0ec4e97a2649dc15af1c925f8a2ff6adf1e17d9b))
|
|
21
|
+
|
|
22
|
+
# [1.105.0](https://github.com/stephenh/ts-proto/compare/v1.104.1...v1.105.0) (2022-02-12)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* Bump ts-proto-descriptors. ([#489](https://github.com/stephenh/ts-proto/issues/489)) ([d454448](https://github.com/stephenh/ts-proto/commit/d454448b1889b1576c1ebcc6964a55a03af7d921)), closes [#493](https://github.com/stephenh/ts-proto/issues/493)
|
|
28
|
+
|
|
1
29
|
## [1.104.1](https://github.com/stephenh/ts-proto/compare/v1.104.0...v1.104.1) (2022-02-12)
|
|
2
30
|
|
|
3
31
|
|
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)
|
|
@@ -331,7 +332,7 @@ Generated code will be placed in the Gradle build directory.
|
|
|
331
332
|
|
|
332
333
|
(Note that this only uses the grpc-web runtime, you don't need to use any of their generated code, i.e. the ts-proto output replaces their `ts-protoc-gen` output.)
|
|
333
334
|
|
|
334
|
-
You'll need to add the `@improbable-eng/grpc-web` and a transport to your project's `package.json`; see the `integration/grpc-web` directory for a working example.
|
|
335
|
+
You'll need to add the `@improbable-eng/grpc-web` and a transport to your project's `package.json`; see the `integration/grpc-web` directory for a working example. Also see [#504](https://github.com/stephenh/ts-proto/issues/504) for integrating with [grpc-web-devtools](https://github.com/SafetyCulture/grpc-web-devtools).
|
|
335
336
|
|
|
336
337
|
- With `--ts_proto_opt=returnObservable=true`, the return type of service methods will be `Observable<T>` instead of `Promise<T>`.
|
|
337
338
|
|
|
@@ -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/main.js
CHANGED
|
@@ -895,7 +895,8 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
895
895
|
// add a check for each incoming field
|
|
896
896
|
messageDesc.field.forEach((field) => {
|
|
897
897
|
const fieldName = case_1.maybeSnakeToCamel(field.name, options);
|
|
898
|
-
const jsonName = utils_1.
|
|
898
|
+
const jsonName = utils_1.getFieldJsonName(field, options);
|
|
899
|
+
const jsonProperty = utils_1.getPropertyAccessor('object', jsonName);
|
|
899
900
|
// get code that extracts value from incoming object
|
|
900
901
|
const readSnippet = (from) => {
|
|
901
902
|
if (types_1.isEnum(field)) {
|
|
@@ -934,6 +935,9 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
934
935
|
else if (types_1.isAnyValueType(field) || types_1.isStructType(field)) {
|
|
935
936
|
return ts_poet_1.code `${from}`;
|
|
936
937
|
}
|
|
938
|
+
else if (types_1.isFieldMaskType(field)) {
|
|
939
|
+
return ts_poet_1.code `{paths: ${from}.split(",")}`;
|
|
940
|
+
}
|
|
937
941
|
else if (types_1.isListValueType(field)) {
|
|
938
942
|
return ts_poet_1.code `[...${from}]`;
|
|
939
943
|
}
|
|
@@ -1010,8 +1014,8 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1010
1014
|
const fieldType = types_1.toTypeName(ctx, messageDesc, field);
|
|
1011
1015
|
const i = maybeCastToNumber(ctx, messageDesc, field, 'key');
|
|
1012
1016
|
chunks.push(ts_poet_1.code `
|
|
1013
|
-
${fieldName}: ${ctx.utils.isObject}(
|
|
1014
|
-
? Object.entries(
|
|
1017
|
+
${fieldName}: ${ctx.utils.isObject}(${jsonProperty})
|
|
1018
|
+
? Object.entries(${jsonProperty}).reduce<${fieldType}>((acc, [key, value]) => {
|
|
1015
1019
|
acc[${i}] = ${readSnippet('value')};
|
|
1016
1020
|
return acc;
|
|
1017
1021
|
}, {})
|
|
@@ -1021,12 +1025,12 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1021
1025
|
else {
|
|
1022
1026
|
const readValueSnippet = readSnippet('e');
|
|
1023
1027
|
if (readValueSnippet.toString() === ts_poet_1.code `e`.toString()) {
|
|
1024
|
-
chunks.push(ts_poet_1.code `${fieldName}: Array.isArray(object?.${jsonName}) ? [
|
|
1028
|
+
chunks.push(ts_poet_1.code `${fieldName}: Array.isArray(object?.${jsonName}) ? [...${jsonProperty}] : [],`);
|
|
1025
1029
|
}
|
|
1026
1030
|
else {
|
|
1027
1031
|
// Explicit `any` type required to make TS with noImplicitAny happy. `object` is also `any` here.
|
|
1028
1032
|
chunks.push(ts_poet_1.code `
|
|
1029
|
-
${fieldName}: Array.isArray(object?.${jsonName}) ?
|
|
1033
|
+
${fieldName}: Array.isArray(object?.${jsonName}) ? ${jsonProperty}.map((e: any) => ${readValueSnippet}): [],
|
|
1030
1034
|
`);
|
|
1031
1035
|
}
|
|
1032
1036
|
}
|
|
@@ -1039,8 +1043,8 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1039
1043
|
const fieldName = case_1.maybeSnakeToCamel(messageDesc.oneofDecl[field.oneofIndex].name, options);
|
|
1040
1044
|
chunks.push(ts_poet_1.code `${fieldName}: `);
|
|
1041
1045
|
}
|
|
1042
|
-
const ternaryIf = ts_poet_1.code `${ctx.utils.isSet}(
|
|
1043
|
-
const ternaryThen = ts_poet_1.code `{ $case: '${fieldName}', ${fieldName}: ${readSnippet(
|
|
1046
|
+
const ternaryIf = ts_poet_1.code `${ctx.utils.isSet}(${jsonProperty})`;
|
|
1047
|
+
const ternaryThen = ts_poet_1.code `{ $case: '${fieldName}', ${fieldName}: ${readSnippet(`${jsonProperty}`)}`;
|
|
1044
1048
|
chunks.push(ts_poet_1.code `${ternaryIf} ? ${ternaryThen}} : `);
|
|
1045
1049
|
if (field === lastCase) {
|
|
1046
1050
|
chunks.push(ts_poet_1.code `undefined,`);
|
|
@@ -1048,27 +1052,27 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1048
1052
|
}
|
|
1049
1053
|
else if (types_1.isAnyValueType(field)) {
|
|
1050
1054
|
chunks.push(ts_poet_1.code `${fieldName}: ${ctx.utils.isSet}(object?.${jsonName})
|
|
1051
|
-
? ${readSnippet(
|
|
1055
|
+
? ${readSnippet(`${jsonProperty}`)}
|
|
1052
1056
|
: undefined,
|
|
1053
1057
|
`);
|
|
1054
1058
|
}
|
|
1055
1059
|
else if (types_1.isStructType(field)) {
|
|
1056
|
-
chunks.push(ts_poet_1.code `${fieldName}: ${ctx.utils.isObject}(
|
|
1057
|
-
? ${readSnippet(
|
|
1060
|
+
chunks.push(ts_poet_1.code `${fieldName}: ${ctx.utils.isObject}(${jsonProperty})
|
|
1061
|
+
? ${readSnippet(`${jsonProperty}`)}
|
|
1058
1062
|
: undefined,`);
|
|
1059
1063
|
}
|
|
1060
1064
|
else if (types_1.isListValueType(field)) {
|
|
1061
1065
|
chunks.push(ts_poet_1.code `
|
|
1062
|
-
${fieldName}: Array.isArray(
|
|
1063
|
-
? ${readSnippet(
|
|
1066
|
+
${fieldName}: Array.isArray(${jsonProperty})
|
|
1067
|
+
? ${readSnippet(`${jsonProperty}`)}
|
|
1064
1068
|
: undefined,
|
|
1065
1069
|
`);
|
|
1066
1070
|
}
|
|
1067
1071
|
else {
|
|
1068
1072
|
const fallback = types_1.isWithinOneOf(field) ? 'undefined' : types_1.defaultValue(ctx, field);
|
|
1069
1073
|
chunks.push(ts_poet_1.code `
|
|
1070
|
-
${fieldName}: ${ctx.utils.isSet}(
|
|
1071
|
-
? ${readSnippet(
|
|
1074
|
+
${fieldName}: ${ctx.utils.isSet}(${jsonProperty})
|
|
1075
|
+
? ${readSnippet(`${jsonProperty}`)}
|
|
1072
1076
|
: ${fallback},
|
|
1073
1077
|
`);
|
|
1074
1078
|
}
|
|
@@ -1089,7 +1093,8 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1089
1093
|
// then add a case for each field
|
|
1090
1094
|
messageDesc.field.forEach((field) => {
|
|
1091
1095
|
const fieldName = case_1.maybeSnakeToCamel(field.name, options);
|
|
1092
|
-
const jsonName = utils_1.
|
|
1096
|
+
const jsonName = utils_1.getFieldJsonName(field, options);
|
|
1097
|
+
const jsonProperty = utils_1.getPropertyAccessor('obj', jsonName);
|
|
1093
1098
|
const readSnippet = (from) => {
|
|
1094
1099
|
if (types_1.isEnum(field)) {
|
|
1095
1100
|
const toJson = types_1.getEnumMethod(ctx, field.typeName, 'ToJSON');
|
|
@@ -1151,6 +1156,9 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1151
1156
|
else if (types_1.isAnyValueType(field)) {
|
|
1152
1157
|
return ts_poet_1.code `${from}`;
|
|
1153
1158
|
}
|
|
1159
|
+
else if (types_1.isFieldMaskType(field)) {
|
|
1160
|
+
return ts_poet_1.code `${from}.paths.join()`;
|
|
1161
|
+
}
|
|
1154
1162
|
else if (types_1.isMessage(field) && !types_1.isValueType(ctx, field) && !types_1.isMapType(ctx, messageDesc, field)) {
|
|
1155
1163
|
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
1156
1164
|
return ts_poet_1.code `${from} ? ${type}.toJSON(${from}) : ${types_1.defaultValue(ctx, field)}`;
|
|
@@ -1199,11 +1207,11 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1199
1207
|
// oneofs in a union are only output as `oneof name = ...`
|
|
1200
1208
|
const oneofName = case_1.maybeSnakeToCamel(messageDesc.oneofDecl[field.oneofIndex].name, options);
|
|
1201
1209
|
const v = readSnippet(`message.${oneofName}?.${fieldName}`);
|
|
1202
|
-
chunks.push(ts_poet_1.code `message.${oneofName}?.$case === '${fieldName}' && (
|
|
1210
|
+
chunks.push(ts_poet_1.code `message.${oneofName}?.$case === '${fieldName}' && (${jsonProperty} = ${v});`);
|
|
1203
1211
|
}
|
|
1204
1212
|
else {
|
|
1205
1213
|
const v = readSnippet(`message.${fieldName}`);
|
|
1206
|
-
chunks.push(ts_poet_1.code `message.${fieldName} !== undefined && (
|
|
1214
|
+
chunks.push(ts_poet_1.code `message.${fieldName} !== undefined && (${jsonProperty} = ${v});`);
|
|
1207
1215
|
}
|
|
1208
1216
|
});
|
|
1209
1217
|
chunks.push(ts_poet_1.code `return obj;`);
|
|
@@ -1323,7 +1331,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1323
1331
|
&& object.${oneofName}?.${fieldName} !== null
|
|
1324
1332
|
) {
|
|
1325
1333
|
message.${oneofName} = { $case: '${fieldName}', ${fieldName}: ${v} };
|
|
1326
|
-
}
|
|
1334
|
+
}
|
|
1327
1335
|
`);
|
|
1328
1336
|
}
|
|
1329
1337
|
else if (readSnippet(`x`).toCodeString() == 'x') {
|
|
@@ -1362,7 +1370,7 @@ function generateWrap(ctx, fullProtoTypeName) {
|
|
|
1362
1370
|
if (ctx.options.oneof === options_1.OneofOption.UNIONS) {
|
|
1363
1371
|
chunks.push(ts_poet_1.code `wrap(value: any): Value {
|
|
1364
1372
|
const result = createBaseValue();
|
|
1365
|
-
|
|
1373
|
+
|
|
1366
1374
|
if (value === null) {
|
|
1367
1375
|
result.kind = {$case: 'nullValue', nullValue: NullValue.NULL_VALUE};
|
|
1368
1376
|
} else if (typeof value === 'boolean') {
|
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
|
}
|
package/build/schema.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateSchema = void 0;
|
|
4
|
+
const ts_proto_descriptors_1 = require("ts-proto-descriptors");
|
|
4
5
|
const ts_poet_1 = require("ts-poet");
|
|
5
6
|
const visit_1 = require("./visit");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
@@ -36,7 +37,7 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
36
37
|
return ts_poet_1.code `${ts_poet_1.imp(`protoMetadata@./${dep.replace('.proto', '')}`)}`;
|
|
37
38
|
});
|
|
38
39
|
// Use toObject so that we get enums as numbers (instead of the default toJSON behavior)
|
|
39
|
-
const descriptor =
|
|
40
|
+
const descriptor = ts_proto_descriptors_1.FileDescriptorProto.fromPartial(fileDesc);
|
|
40
41
|
// Only keep locations that include comments
|
|
41
42
|
descriptor.sourceCodeInfo = {
|
|
42
43
|
location: ((_a = descriptor.sourceCodeInfo) === null || _a === void 0 ? void 0 : _a.location.filter((loc) => loc['leadingComments'] || loc['trailingComments'])) || [],
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.detectBatchMethod = exports.responsePromiseOrObservable = exports.responseObservable = exports.responsePromise = exports.responseType = exports.requestType = exports.rawRequestType = exports.detectMapType = exports.toTypeName = exports.getEnumMethod = exports.messageToTypeName = exports.wrapperTypeName = exports.valueTypeName = exports.isEmptyType = exports.isLongValueType = exports.isStructTypeName = exports.isStructType = exports.isListValueTypeName = exports.isListValueType = exports.isBytesValueType = exports.isAnyValueTypeName = exports.isAnyValueType = exports.isValueType = exports.isTimestamp = exports.isObjectId = exports.isMapType = exports.isWholeNumber = exports.isLong = exports.isRepeated = exports.isWithinOneOfThatShouldBeUnion = exports.isWithinOneOf = exports.isEnum = exports.isMessage = exports.isBytes = exports.isPrimitive = exports.isOptionalProperty = exports.isScalar = exports.createTypeMap = exports.notDefaultCheck = exports.defaultValue = exports.packedType = exports.toReaderCall = exports.basicTypeName = exports.basicLongWireType = exports.basicWireType = void 0;
|
|
3
|
+
exports.detectBatchMethod = exports.responsePromiseOrObservable = exports.responseObservable = exports.responsePromise = exports.responseType = exports.requestType = exports.rawRequestType = exports.detectMapType = exports.toTypeName = exports.getEnumMethod = exports.messageToTypeName = exports.wrapperTypeName = exports.valueTypeName = exports.isEmptyType = exports.isLongValueType = exports.isStructTypeName = exports.isStructType = exports.isListValueTypeName = exports.isListValueType = exports.isFieldMaskTypeName = exports.isFieldMaskType = exports.isBytesValueType = exports.isAnyValueTypeName = exports.isAnyValueType = exports.isValueType = exports.isTimestamp = exports.isObjectId = exports.isMapType = exports.isWholeNumber = exports.isLong = exports.isRepeated = exports.isWithinOneOfThatShouldBeUnion = exports.isWithinOneOf = exports.isEnum = exports.isMessage = exports.isBytes = exports.isPrimitive = exports.isOptionalProperty = exports.isScalar = exports.createTypeMap = exports.notDefaultCheck = exports.defaultValue = exports.packedType = exports.toReaderCall = exports.basicTypeName = exports.basicLongWireType = exports.basicWireType = void 0;
|
|
4
4
|
const ts_proto_descriptors_1 = require("ts-proto-descriptors");
|
|
5
5
|
const ts_poet_1 = require("ts-poet");
|
|
6
6
|
const options_1 = require("./options");
|
|
@@ -403,6 +403,14 @@ function isBytesValueType(field) {
|
|
|
403
403
|
return field.typeName === '.google.protobuf.BytesValue';
|
|
404
404
|
}
|
|
405
405
|
exports.isBytesValueType = isBytesValueType;
|
|
406
|
+
function isFieldMaskType(field) {
|
|
407
|
+
return isFieldMaskTypeName(field.typeName);
|
|
408
|
+
}
|
|
409
|
+
exports.isFieldMaskType = isFieldMaskType;
|
|
410
|
+
function isFieldMaskTypeName(typeName) {
|
|
411
|
+
return typeName === 'google.protobuf.FieldMask' || typeName === '.google.protobuf.FieldMask';
|
|
412
|
+
}
|
|
413
|
+
exports.isFieldMaskTypeName = isFieldMaskTypeName;
|
|
406
414
|
function isListValueType(field) {
|
|
407
415
|
return isListValueTypeName(field.typeName);
|
|
408
416
|
}
|
package/build/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.impProto = exports.
|
|
3
|
+
exports.impProto = exports.getPropertyAccessor = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
|
|
4
4
|
const ts_poet_1 = require("ts-poet");
|
|
5
5
|
const options_1 = require("./options");
|
|
6
6
|
const case_1 = require("./case");
|
|
@@ -144,7 +144,7 @@ class FormattedMethodDescriptor {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
exports.FormattedMethodDescriptor = FormattedMethodDescriptor;
|
|
147
|
-
function
|
|
147
|
+
function getFieldJsonName(field, options) {
|
|
148
148
|
// jsonName will be camelCased by the protocol compiler, plus can be overridden by the user,
|
|
149
149
|
// so just use that instead of our own maybeSnakeToCamel
|
|
150
150
|
if (options.snakeToCamel.includes('json')) {
|
|
@@ -154,7 +154,20 @@ function determineFieldJsonName(field, options) {
|
|
|
154
154
|
return field.name;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
exports.
|
|
157
|
+
exports.getFieldJsonName = getFieldJsonName;
|
|
158
|
+
/**
|
|
159
|
+
* Returns a snippet for reading an object's property, such as `foo.bar`, or `foo['bar']` if the property name contains unusual characters.
|
|
160
|
+
* For simplicity, we don't match the ECMA 5/6 rules for valid identifiers exactly, and return array syntax liberally.
|
|
161
|
+
* @param objectName
|
|
162
|
+
* @param propertyName
|
|
163
|
+
*/
|
|
164
|
+
function getPropertyAccessor(objectName, propertyName) {
|
|
165
|
+
let validIdentifier = /^[a-zA-Z_$][\w$]*$/;
|
|
166
|
+
return validIdentifier.test(propertyName)
|
|
167
|
+
? `${objectName}.${propertyName}`
|
|
168
|
+
: `${objectName}[${JSON.stringify(propertyName)}]`;
|
|
169
|
+
}
|
|
170
|
+
exports.getPropertyAccessor = getPropertyAccessor;
|
|
158
171
|
function impProto(options, module, type) {
|
|
159
172
|
return ts_poet_1.imp(`${type}@./${module}${options.fileSuffix}`);
|
|
160
173
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.106.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -64,6 +64,6 @@
|
|
|
64
64
|
"object-hash": "^1.3.1",
|
|
65
65
|
"protobufjs": "^6.8.8",
|
|
66
66
|
"ts-poet": "^4.5.0",
|
|
67
|
-
"ts-proto-descriptors": "1.
|
|
67
|
+
"ts-proto-descriptors": "1.6.0"
|
|
68
68
|
}
|
|
69
69
|
}
|