ts-proto 2.18.0 → 2.18.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/README.markdown +1 -1
- package/build/src/main.js +2 -2
- package/build/src/types.js +6 -0
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -548,7 +548,7 @@ With `--ts_proto_opt=protoJsonFormat=false`, strict proto3 compliance is disable
|
|
|
548
548
|
|
|
549
549
|
- With `--ts_proto_opt=useJsonWireFormat=true`, the generated code will reflect the JSON representation of Protobuf messages.
|
|
550
550
|
|
|
551
|
-
Requires `onlyTypes=true`. Implies `useDate=string` and `stringEnums=true
|
|
551
|
+
Requires `onlyTypes=true`. Implies `useDate=string` and `stringEnums=true`, and types `bytes` fields as base64-encoded `string`s. This option is to generate types that can be directly used with marshalling/unmarshalling Protobuf messages serialized as JSON.
|
|
552
552
|
You may also want to set `useOptionals=all`, as gRPC gateways are not required to send default value for scalar values.
|
|
553
553
|
|
|
554
554
|
- With `--ts_proto_opt=useNumericEnumForJson=true`, the JSON converter (`toJSON`) will encode enum values as int, rather than a string literal.
|
package/build/src/main.js
CHANGED
|
@@ -523,10 +523,10 @@ function makeDeepPartial(options, longs) {
|
|
|
523
523
|
const maybeExcludeType = (0, options_1.addTypeToMessages)(options) ? `| '$type'` : "";
|
|
524
524
|
const Exact = (0, ts_poet_1.conditionalOutput)("Exact", (0, ts_poet_1.code) `
|
|
525
525
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
526
|
-
${maybeExport} type Exact<P, I
|
|
526
|
+
${maybeExport} type Exact<P, I> = ${maybeUnknownP}P extends ${Builtin}
|
|
527
527
|
? P
|
|
528
528
|
: P &
|
|
529
|
-
{ [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
|
|
529
|
+
{ [K in keyof P as Extract<K, keyof I>]: Exact<P[K], I[K & keyof I]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
|
|
530
530
|
`);
|
|
531
531
|
// Based on the type from ts-essentials
|
|
532
532
|
const keys = (0, options_1.addTypeToMessages)(options) ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
|
package/build/src/types.js
CHANGED
|
@@ -138,6 +138,9 @@ function basicTypeName(ctx, field, typeOptions = {}) {
|
|
|
138
138
|
if (options.env === options_1.EnvOption.NODE) {
|
|
139
139
|
return (0, ts_poet_1.code) `Buffer`;
|
|
140
140
|
}
|
|
141
|
+
else if (options.useJsonWireFormat) {
|
|
142
|
+
return (0, ts_poet_1.code) `string`;
|
|
143
|
+
}
|
|
141
144
|
else {
|
|
142
145
|
return (0, ts_poet_1.code) `Uint8Array`;
|
|
143
146
|
}
|
|
@@ -303,6 +306,9 @@ function defaultValue(ctx, field) {
|
|
|
303
306
|
if (options.env === options_1.EnvOption.NODE) {
|
|
304
307
|
return "Buffer.alloc(0)";
|
|
305
308
|
}
|
|
309
|
+
if (options.useJsonWireFormat) {
|
|
310
|
+
return '""';
|
|
311
|
+
}
|
|
306
312
|
return "new Uint8Array(0)";
|
|
307
313
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE:
|
|
308
314
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_GROUP:
|