ts-proto 1.150.1 → 1.151.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/README.markdown +1 -1
- package/build/main.js +12 -9
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -414,7 +414,7 @@ Generated code will be placed in the Gradle build directory.
|
|
|
414
414
|
|
|
415
415
|
- With `--ts_proto_opt=outputSchema=true`, meta typings will be generated that can later be used in other code generators.
|
|
416
416
|
|
|
417
|
-
- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name.
|
|
417
|
+
- With `--ts_proto_opt=outputTypeAnnotations=true`, each message will be given a `$type` field containing its fully-qualified name. You can use `--ts_proto_opt=outputTypeAnnotations=static-only` to omit it from the `interface` declaration.
|
|
418
418
|
|
|
419
419
|
- With `--ts_proto_opt=outputTypeRegistry=true`, the type registry will be generated that can be used to resolve message types by fully-qualified name. Also, each message will be given a `$type` field containing its fully-qualified name.
|
|
420
420
|
|
package/build/main.js
CHANGED
|
@@ -418,7 +418,7 @@ function makeDeepPartial(options, longs) {
|
|
|
418
418
|
const maybeLong = options.forceLong === options_1.LongOption.LONG ? (0, ts_poet_1.code) ` : T extends ${longs.Long} ? string | number | Long ` : "";
|
|
419
419
|
const Builtin = (0, ts_poet_1.conditionalOutput)("Builtin", (0, ts_poet_1.code) `type Builtin = Date | Function | Uint8Array | string | number | boolean |${options.forceLong === options_1.LongOption.BIGINT ? " bigint |" : ""} undefined;`);
|
|
420
420
|
// Based on https://github.com/sindresorhus/type-fest/pull/259
|
|
421
|
-
const maybeExcludeType = options
|
|
421
|
+
const maybeExcludeType = addTypeToMessages(options) ? `| '$type'` : "";
|
|
422
422
|
const Exact = (0, ts_poet_1.conditionalOutput)("Exact", (0, ts_poet_1.code) `
|
|
423
423
|
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
424
424
|
${maybeExport} type Exact<P, I extends P> = P extends ${Builtin}
|
|
@@ -427,7 +427,7 @@ function makeDeepPartial(options, longs) {
|
|
|
427
427
|
{ [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
|
|
428
428
|
`);
|
|
429
429
|
// Based on the type from ts-essentials
|
|
430
|
-
const keys = options
|
|
430
|
+
const keys = addTypeToMessages(options) ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
|
|
431
431
|
const DeepPartial = (0, ts_poet_1.conditionalOutput)("DeepPartial", (0, ts_poet_1.code) `
|
|
432
432
|
${maybeExport} type DeepPartial<T> = T extends ${Builtin}
|
|
433
433
|
? T
|
|
@@ -487,7 +487,7 @@ function makeTimestampMethods(options, longs) {
|
|
|
487
487
|
// (note this only occurs when the string is > 8 characters)
|
|
488
488
|
seconds = "Math.trunc(date.getTime() / 1_000).toString()";
|
|
489
489
|
}
|
|
490
|
-
const maybeTypeField = options
|
|
490
|
+
const maybeTypeField = addTypeToMessages(options) ? `$type: 'google.protobuf.Timestamp',` : "";
|
|
491
491
|
const toTimestamp = (0, ts_poet_1.conditionalOutput)("toTimestamp", options.useDate === options_1.DateOption.STRING
|
|
492
492
|
? (0, ts_poet_1.code) `
|
|
493
493
|
function toTimestamp(dateStr: string): ${Timestamp} {
|
|
@@ -597,7 +597,7 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
|
|
|
597
597
|
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = messageDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
598
598
|
// interface name should be defined to avoid import collisions
|
|
599
599
|
chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(fullName)} {`);
|
|
600
|
-
if (
|
|
600
|
+
if (addTypeToMessages(options)) {
|
|
601
601
|
chunks.push((0, ts_poet_1.code) `$type: '${fullTypeName}',`);
|
|
602
602
|
}
|
|
603
603
|
// When oneof=unions, we generate a single property with an ADT per `oneof` clause.
|
|
@@ -688,7 +688,7 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
688
688
|
: (0, types_1.defaultValue)(ctx, field);
|
|
689
689
|
fields.push((0, ts_poet_1.code) `${name}: ${val}`);
|
|
690
690
|
}
|
|
691
|
-
if (
|
|
691
|
+
if (addTypeToMessages(options)) {
|
|
692
692
|
fields.unshift((0, ts_poet_1.code) `$type: '${fullTypeName}'`);
|
|
693
693
|
}
|
|
694
694
|
if (ctx.options.unknownFields && ctx.options.initializeFieldsAsUndefined) {
|
|
@@ -954,7 +954,7 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
954
954
|
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.uint32(${tag}).fork()).ldelim()`;
|
|
955
955
|
}
|
|
956
956
|
else if ((0, types_1.isValueType)(ctx, field)) {
|
|
957
|
-
const maybeTypeField = options
|
|
957
|
+
const maybeTypeField = addTypeToMessages(options) ? `$type: '${field.typeName.slice(1)}',` : "";
|
|
958
958
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
959
959
|
const wrappedValue = (place) => {
|
|
960
960
|
if ((0, types_1.isAnyValueType)(field) || (0, types_1.isListValueType)(field) || (0, types_1.isStructType)(field) || (0, types_1.isFieldMaskType)(field)) {
|
|
@@ -1003,7 +1003,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1003
1003
|
if ((0, types_1.isRepeated)(field)) {
|
|
1004
1004
|
if ((0, types_1.isMapType)(ctx, messageDesc, field)) {
|
|
1005
1005
|
const valueType = typeMap.get(field.typeName)[2].field[1];
|
|
1006
|
-
const maybeTypeField = options
|
|
1006
|
+
const maybeTypeField = addTypeToMessages(options) ? `$type: '${field.typeName.slice(1)}',` : "";
|
|
1007
1007
|
const entryWriteSnippet = (0, types_1.isValueType)(ctx, valueType)
|
|
1008
1008
|
? (0, ts_poet_1.code) `
|
|
1009
1009
|
if (value !== undefined) {
|
|
@@ -1255,7 +1255,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1255
1255
|
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.fork()).ldelim()`;
|
|
1256
1256
|
}
|
|
1257
1257
|
else if ((0, types_1.isValueType)(ctx, field)) {
|
|
1258
|
-
const maybeTypeField = options
|
|
1258
|
+
const maybeTypeField = addTypeToMessages(options) ? `$type: '${field.typeName.slice(1)}',` : "";
|
|
1259
1259
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
1260
1260
|
const wrappedValue = (place) => {
|
|
1261
1261
|
if ((0, types_1.isAnyValueType)(field) || (0, types_1.isListValueType)(field) || (0, types_1.isStructType)(field) || (0, types_1.isFieldMaskType)(field)) {
|
|
@@ -1387,7 +1387,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1387
1387
|
fromJSON(${messageDesc.field.length > 0 ? "object" : "_"}: any): ${fullName} {
|
|
1388
1388
|
return {
|
|
1389
1389
|
`);
|
|
1390
|
-
if (
|
|
1390
|
+
if (addTypeToMessages(options)) {
|
|
1391
1391
|
chunks.push((0, ts_poet_1.code) `$type: ${fullName}.$type,`);
|
|
1392
1392
|
}
|
|
1393
1393
|
const oneofFieldsCases = messageDesc.oneofDecl.map((oneof, oneofIndex) => messageDesc.field.filter(types_1.isWithinOneOf).filter((field) => field.oneofIndex === oneofIndex));
|
|
@@ -2014,3 +2014,6 @@ function maybeReadonly(options) {
|
|
|
2014
2014
|
function maybeAsAny(options) {
|
|
2015
2015
|
return options.useReadonlyTypes ? " as any" : "";
|
|
2016
2016
|
}
|
|
2017
|
+
function addTypeToMessages(options) {
|
|
2018
|
+
return ((options.outputTypeAnnotations || options.outputTypeRegistry) && options.outputTypeAnnotations !== "static-only");
|
|
2019
|
+
}
|