ts-proto 1.162.0 → 1.162.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/build/encode.js +2 -2
- package/build/generate-struct-wrappers.js +9 -6
- package/build/main.js +41 -40
- package/build/types.js +1 -0
- package/build/utils.js +13 -19
- package/package.json +1 -1
package/build/encode.js
CHANGED
|
@@ -18,7 +18,7 @@ function generateEncoder(ctx, typeName) {
|
|
|
18
18
|
}
|
|
19
19
|
return (0, ts_poet_1.code) `${TimestampValue}.encode(${value}).finish()`;
|
|
20
20
|
}
|
|
21
|
-
if (name == "Struct") {
|
|
21
|
+
if (name == "Struct" || name == "Value") {
|
|
22
22
|
const StructType = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
|
|
23
23
|
return (0, ts_poet_1.code) `${StructType}.encode(${StructType}.wrap(value)).finish()`;
|
|
24
24
|
}
|
|
@@ -64,7 +64,7 @@ function generateDecoder(ctx, typeName) {
|
|
|
64
64
|
}
|
|
65
65
|
return decoder;
|
|
66
66
|
}
|
|
67
|
-
if (name == "Struct" || name == "ListValue") {
|
|
67
|
+
if (name == "Struct" || name == "ListValue" || name == "Value") {
|
|
68
68
|
TypeValue = (0, utils_1.impProto)(ctx.options, "google/protobuf/struct", name);
|
|
69
69
|
return (0, ts_poet_1.code) `${TypeValue}.unwrap(${TypeValue}.decode(value))`;
|
|
70
70
|
}
|
|
@@ -134,9 +134,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
|
|
|
134
134
|
}`);
|
|
135
135
|
}
|
|
136
136
|
if ((0, types_1.isFieldMaskTypeName)(fullProtoTypeName)) {
|
|
137
|
-
chunks.push((
|
|
138
|
-
return message.paths;
|
|
139
|
-
}`);
|
|
137
|
+
chunks.push(generateFieldMaskUnwrap(ctx));
|
|
140
138
|
}
|
|
141
139
|
return chunks;
|
|
142
140
|
}
|
|
@@ -303,13 +301,18 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
|
|
|
303
301
|
}`);
|
|
304
302
|
}
|
|
305
303
|
if ((0, types_1.isFieldMaskTypeName)(fullProtoTypeName)) {
|
|
306
|
-
chunks.push((
|
|
307
|
-
return message.paths;
|
|
308
|
-
}`);
|
|
304
|
+
chunks.push(generateFieldMaskUnwrap(ctx));
|
|
309
305
|
}
|
|
310
306
|
return chunks;
|
|
311
307
|
}
|
|
312
308
|
exports.generateUnwrapShallow = generateUnwrapShallow;
|
|
309
|
+
function generateFieldMaskUnwrap(ctx) {
|
|
310
|
+
const returnType = ctx.options.useOptionals === "all" ? "string[] | undefined" : "string[]";
|
|
311
|
+
const pathModifier = ctx.options.useOptionals === "all" ? "?" : "";
|
|
312
|
+
return (0, ts_poet_1.code) `unwrap(message: ${ctx.options.useReadonlyTypes ? "any" : "FieldMask"}): ${returnType} {
|
|
313
|
+
return message${pathModifier}.paths;
|
|
314
|
+
}`;
|
|
315
|
+
}
|
|
313
316
|
function maybeReadonly(options) {
|
|
314
317
|
return options.useReadonlyTypes ? "readonly " : "";
|
|
315
318
|
}
|
package/build/main.js
CHANGED
|
@@ -615,10 +615,10 @@ function generateInterfaceDeclaration(ctx, fullName, messageDesc, sourceInfo, fu
|
|
|
615
615
|
}
|
|
616
616
|
const info = sourceInfo.lookup(sourceInfo_1.Fields.message.field, index);
|
|
617
617
|
(0, utils_1.maybeAddComment)(info, chunks, (_a = fieldDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
618
|
-
const
|
|
618
|
+
const fieldKey = (0, utils_1.safeAccessor)((0, utils_1.getFieldName)(fieldDesc, options));
|
|
619
619
|
const isOptional = (0, types_1.isOptionalProperty)(fieldDesc, messageDesc.options, options);
|
|
620
620
|
const type = (0, types_1.toTypeName)(ctx, messageDesc, fieldDesc, isOptional);
|
|
621
|
-
chunks.push((0, ts_poet_1.code) `${maybeReadonly(options)}${
|
|
621
|
+
chunks.push((0, ts_poet_1.code) `${maybeReadonly(options)}${fieldKey}${isOptional ? "?" : ""}: ${type}, `);
|
|
622
622
|
});
|
|
623
623
|
if (ctx.options.unknownFields) {
|
|
624
624
|
chunks.push((0, ts_poet_1.code) `_unknownFields?: {[key: number]: Uint8Array[]} | undefined,`);
|
|
@@ -670,16 +670,16 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
670
670
|
if (!processedOneofs.has(oneofIndex)) {
|
|
671
671
|
processedOneofs.add(oneofIndex);
|
|
672
672
|
const name = options.useJsonName
|
|
673
|
-
? (0, utils_1.
|
|
673
|
+
? (0, utils_1.getFieldName)(field, options)
|
|
674
674
|
: (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[oneofIndex].name, ctx.options);
|
|
675
|
-
fields.push((0, ts_poet_1.code) `${name}: undefined`);
|
|
675
|
+
fields.push((0, ts_poet_1.code) `${(0, utils_1.safeAccessor)(name)}: undefined`);
|
|
676
676
|
}
|
|
677
677
|
continue;
|
|
678
678
|
}
|
|
679
679
|
if (!options.initializeFieldsAsUndefined && (0, types_1.isOptionalProperty)(field, messageDesc.options, options)) {
|
|
680
680
|
continue;
|
|
681
681
|
}
|
|
682
|
-
const
|
|
682
|
+
const fieldKey = (0, utils_1.safeAccessor)((0, utils_1.getFieldName)(field, options));
|
|
683
683
|
const val = (0, types_1.isWithinOneOf)(field)
|
|
684
684
|
? "undefined"
|
|
685
685
|
: (0, types_1.isMapType)(ctx, messageDesc, field)
|
|
@@ -689,7 +689,7 @@ function generateBaseInstanceFactory(ctx, fullName, messageDesc, fullTypeName) {
|
|
|
689
689
|
: (0, types_1.isRepeated)(field)
|
|
690
690
|
? "[]"
|
|
691
691
|
: (0, types_1.defaultValue)(ctx, field);
|
|
692
|
-
fields.push((0, ts_poet_1.code) `${
|
|
692
|
+
fields.push((0, ts_poet_1.code) `${fieldKey}: ${val}`);
|
|
693
693
|
}
|
|
694
694
|
if ((0, options_1.addTypeToMessages)(options)) {
|
|
695
695
|
fields.unshift((0, ts_poet_1.code) `$type: '${fullTypeName}'`);
|
|
@@ -797,8 +797,8 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
797
797
|
`);
|
|
798
798
|
// add a case for each incoming field
|
|
799
799
|
messageDesc.field.forEach((field) => {
|
|
800
|
-
const
|
|
801
|
-
const messageProperty = (0, utils_1.getPropertyAccessor)("message",
|
|
800
|
+
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
801
|
+
const messageProperty = (0, utils_1.getPropertyAccessor)("message", fieldName);
|
|
802
802
|
chunks.push((0, ts_poet_1.code) `case ${field.number}:`);
|
|
803
803
|
const tag = ((field.number << 3) | (0, types_1.basicWireType)(field.type)) >>> 0;
|
|
804
804
|
const tagCheck = (0, ts_poet_1.code) `
|
|
@@ -884,7 +884,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
884
884
|
: (0, utils_1.getPropertyAccessor)("message", (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[field.oneofIndex].name, options));
|
|
885
885
|
chunks.push((0, ts_poet_1.code) `
|
|
886
886
|
${tagCheck}
|
|
887
|
-
${oneofNameWithMessage} = { $case: '${
|
|
887
|
+
${oneofNameWithMessage} = { $case: '${fieldName}', ${fieldName}: ${readSnippet} };
|
|
888
888
|
`);
|
|
889
889
|
}
|
|
890
890
|
else {
|
|
@@ -1025,8 +1025,8 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1025
1025
|
.reduce((result, field) => ((result[field.oneofIndex] || (result[field.oneofIndex] = [])).push(field), result), {});
|
|
1026
1026
|
// then add a case for each field
|
|
1027
1027
|
messageDesc.field.forEach((field) => {
|
|
1028
|
-
const
|
|
1029
|
-
const messageProperty = (0, utils_1.getPropertyAccessor)("message",
|
|
1028
|
+
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
1029
|
+
const messageProperty = (0, utils_1.getPropertyAccessor)("message", fieldName);
|
|
1030
1030
|
// get a generic writer.doSomething based on the basic type
|
|
1031
1031
|
const writeSnippet = getEncodeWriteSnippet(ctx, field);
|
|
1032
1032
|
const isOptional = (0, types_1.isOptionalProperty)(field, messageDesc.options, options);
|
|
@@ -1121,7 +1121,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1121
1121
|
writer.uint32(${tag}).fork();
|
|
1122
1122
|
for (const v of ${messageProperty}) {
|
|
1123
1123
|
if (BigInt.asIntN(64, v) !== v) {
|
|
1124
|
-
throw new Error('a value provided in array field ${
|
|
1124
|
+
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1125
1125
|
}
|
|
1126
1126
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1127
1127
|
}
|
|
@@ -1134,7 +1134,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1134
1134
|
writer.uint32(${tag}).fork();
|
|
1135
1135
|
for (const v of ${messageProperty}) {
|
|
1136
1136
|
if (BigInt.asUintN(64, v) !== v) {
|
|
1137
|
-
throw new Error('a value provided in array field ${
|
|
1137
|
+
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1138
1138
|
}
|
|
1139
1139
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1140
1140
|
}
|
|
@@ -1469,7 +1469,8 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1469
1469
|
// add a check for each incoming field
|
|
1470
1470
|
messageDesc.field.forEach((field) => {
|
|
1471
1471
|
var _a;
|
|
1472
|
-
const
|
|
1472
|
+
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
1473
|
+
const fieldKey = (0, utils_1.safeAccessor)(fieldName);
|
|
1473
1474
|
const jsonName = (0, utils_1.getFieldJsonName)(field, options);
|
|
1474
1475
|
const jsonProperty = (0, utils_1.getPropertyAccessor)("object", jsonName);
|
|
1475
1476
|
const jsonPropertyOptional = (0, utils_1.getPropertyAccessor)("object", jsonName, true);
|
|
@@ -1605,7 +1606,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1605
1606
|
if ((0, types_1.shouldGenerateJSMapType)(ctx, messageDesc, field)) {
|
|
1606
1607
|
const fallback = noDefaultValue ? "undefined" : "new Map()";
|
|
1607
1608
|
chunks.push((0, ts_poet_1.code) `
|
|
1608
|
-
${
|
|
1609
|
+
${fieldKey}: ${ctx.utils.isObject}(${jsonProperty})
|
|
1609
1610
|
? Object.entries(${jsonProperty}).reduce<${fieldType}>((acc, [key, value]) => {
|
|
1610
1611
|
acc.set(${i}, ${readSnippet("value")});
|
|
1611
1612
|
return acc;
|
|
@@ -1616,7 +1617,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1616
1617
|
else {
|
|
1617
1618
|
const fallback = noDefaultValue ? "undefined" : "{}";
|
|
1618
1619
|
chunks.push((0, ts_poet_1.code) `
|
|
1619
|
-
${
|
|
1620
|
+
${fieldKey}: ${ctx.utils.isObject}(${jsonProperty})
|
|
1620
1621
|
? Object.entries(${jsonProperty}).reduce<${fieldType}>((acc, [key, value]) => {
|
|
1621
1622
|
acc[${i}] = ${readSnippet("value")};
|
|
1622
1623
|
return acc;
|
|
@@ -1629,12 +1630,12 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1629
1630
|
const fallback = noDefaultValue ? "undefined" : "[]";
|
|
1630
1631
|
const readValueSnippet = readSnippet("e");
|
|
1631
1632
|
if (readValueSnippet.toString() === (0, ts_poet_1.code) `e`.toString()) {
|
|
1632
|
-
chunks.push((0, ts_poet_1.code) `${
|
|
1633
|
+
chunks.push((0, ts_poet_1.code) `${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonPropertyOptional}) ? [...${jsonProperty}] : [],`);
|
|
1633
1634
|
}
|
|
1634
1635
|
else {
|
|
1635
1636
|
// Explicit `any` type required to make TS with noImplicitAny happy. `object` is also `any` here.
|
|
1636
1637
|
chunks.push((0, ts_poet_1.code) `
|
|
1637
|
-
${
|
|
1638
|
+
${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonPropertyOptional}) ? ${jsonProperty}.map((e: any) => ${readValueSnippet}): ${fallback},
|
|
1638
1639
|
`);
|
|
1639
1640
|
}
|
|
1640
1641
|
}
|
|
@@ -1648,26 +1649,26 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1648
1649
|
chunks.push((0, ts_poet_1.code) `${fieldName}: `);
|
|
1649
1650
|
}
|
|
1650
1651
|
const ternaryIf = (0, ts_poet_1.code) `${ctx.utils.isSet}(${jsonProperty})`;
|
|
1651
|
-
const ternaryThen = (0, ts_poet_1.code) `{ $case: '${fieldName}', ${
|
|
1652
|
+
const ternaryThen = (0, ts_poet_1.code) `{ $case: '${fieldName}', ${fieldKey}: ${readSnippet(`${jsonProperty}`)}`;
|
|
1652
1653
|
chunks.push((0, ts_poet_1.code) `${ternaryIf} ? ${ternaryThen}} : `);
|
|
1653
1654
|
if (field === lastCase) {
|
|
1654
1655
|
chunks.push((0, ts_poet_1.code) `undefined,`);
|
|
1655
1656
|
}
|
|
1656
1657
|
}
|
|
1657
1658
|
else if ((0, types_1.isAnyValueType)(field)) {
|
|
1658
|
-
chunks.push((0, ts_poet_1.code) `${
|
|
1659
|
+
chunks.push((0, ts_poet_1.code) `${fieldKey}: ${ctx.utils.isSet}(${jsonPropertyOptional})
|
|
1659
1660
|
? ${readSnippet(`${jsonProperty}`)}
|
|
1660
1661
|
: undefined,
|
|
1661
1662
|
`);
|
|
1662
1663
|
}
|
|
1663
1664
|
else if ((0, types_1.isStructType)(field)) {
|
|
1664
|
-
chunks.push((0, ts_poet_1.code) `${
|
|
1665
|
+
chunks.push((0, ts_poet_1.code) `${fieldKey}: ${ctx.utils.isObject}(${jsonProperty})
|
|
1665
1666
|
? ${readSnippet(`${jsonProperty}`)}
|
|
1666
1667
|
: undefined,`);
|
|
1667
1668
|
}
|
|
1668
1669
|
else if ((0, types_1.isListValueType)(field)) {
|
|
1669
1670
|
chunks.push((0, ts_poet_1.code) `
|
|
1670
|
-
${
|
|
1671
|
+
${fieldKey}: ${ctx.utils.globalThis}.Array.isArray(${jsonProperty})
|
|
1671
1672
|
? ${readSnippet(`${jsonProperty}`)}
|
|
1672
1673
|
: undefined,
|
|
1673
1674
|
`);
|
|
@@ -1675,7 +1676,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1675
1676
|
else {
|
|
1676
1677
|
const fallback = (0, types_1.isWithinOneOf)(field) || noDefaultValue ? "undefined" : (0, types_1.defaultValue)(ctx, field);
|
|
1677
1678
|
chunks.push((0, ts_poet_1.code) `
|
|
1678
|
-
${
|
|
1679
|
+
${fieldKey}: ${ctx.utils.isSet}(${jsonProperty})
|
|
1679
1680
|
? ${readSnippet(`${jsonProperty}`)}
|
|
1680
1681
|
: ${fallback},
|
|
1681
1682
|
`);
|
|
@@ -1686,11 +1687,13 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
1686
1687
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
1687
1688
|
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
1688
1689
|
}
|
|
1689
|
-
function generateCanonicalToJson(fullName, fullProtobufTypeName) {
|
|
1690
|
+
function generateCanonicalToJson(fullName, fullProtobufTypeName, { useOptionals }) {
|
|
1690
1691
|
if ((0, types_1.isFieldMaskTypeName)(fullProtobufTypeName)) {
|
|
1692
|
+
const returnType = useOptionals === "all" ? "string | undefined" : "string";
|
|
1693
|
+
const pathModifier = useOptionals === "all" ? "?" : "";
|
|
1691
1694
|
return (0, ts_poet_1.code) `
|
|
1692
|
-
toJSON(message: ${fullName}):
|
|
1693
|
-
return message.paths.join(',');
|
|
1695
|
+
toJSON(message: ${fullName}): ${returnType} {
|
|
1696
|
+
return message.paths${pathModifier}.join(',');
|
|
1694
1697
|
}
|
|
1695
1698
|
`;
|
|
1696
1699
|
}
|
|
@@ -1699,7 +1702,7 @@ function generateCanonicalToJson(fullName, fullProtobufTypeName) {
|
|
|
1699
1702
|
function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
1700
1703
|
const { options, utils, typeMap } = ctx;
|
|
1701
1704
|
const chunks = [];
|
|
1702
|
-
const canonicalToJson = generateCanonicalToJson(fullName, fullProtobufTypeName);
|
|
1705
|
+
const canonicalToJson = generateCanonicalToJson(fullName, fullProtobufTypeName, options);
|
|
1703
1706
|
if (canonicalToJson) {
|
|
1704
1707
|
chunks.push(canonicalToJson);
|
|
1705
1708
|
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
@@ -1711,10 +1714,10 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
|
1711
1714
|
`);
|
|
1712
1715
|
// then add a case for each field
|
|
1713
1716
|
messageDesc.field.forEach((field) => {
|
|
1714
|
-
const
|
|
1717
|
+
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
1715
1718
|
const jsonName = (0, utils_1.getFieldJsonName)(field, options);
|
|
1716
1719
|
const jsonProperty = (0, utils_1.getPropertyAccessor)("obj", jsonName);
|
|
1717
|
-
const messageProperty = (0, utils_1.getPropertyAccessor)("message",
|
|
1720
|
+
const messageProperty = (0, utils_1.getPropertyAccessor)("message", fieldName);
|
|
1718
1721
|
const readSnippet = (from) => {
|
|
1719
1722
|
if ((0, types_1.isEnum)(field)) {
|
|
1720
1723
|
const toJson = (0, types_1.getEnumMethod)(ctx, field.typeName, "ToJSON");
|
|
@@ -1902,9 +1905,9 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1902
1905
|
chunks.push((0, ts_poet_1.code) `const message = ${createBase}${maybeAsAny(options)};`);
|
|
1903
1906
|
// add a check for each incoming field
|
|
1904
1907
|
messageDesc.field.forEach((field) => {
|
|
1905
|
-
const
|
|
1906
|
-
const messageProperty = (0, utils_1.getPropertyAccessor)("message",
|
|
1907
|
-
const objectProperty = (0, utils_1.getPropertyAccessor)("object",
|
|
1908
|
+
const fieldName = (0, utils_1.getFieldName)(field, options);
|
|
1909
|
+
const messageProperty = (0, utils_1.getPropertyAccessor)("message", fieldName);
|
|
1910
|
+
const objectProperty = (0, utils_1.getPropertyAccessor)("object", fieldName);
|
|
1908
1911
|
const readSnippet = (from) => {
|
|
1909
1912
|
if (((0, types_1.isLong)(field) || (0, types_1.isLongValueType)(field)) && options.forceLong === options_1.LongOption.LONG) {
|
|
1910
1913
|
return (0, ts_poet_1.code) `Long.fromValue(${from})`;
|
|
@@ -2009,19 +2012,17 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
2009
2012
|
}
|
|
2010
2013
|
}
|
|
2011
2014
|
else if ((0, types_1.isWithinOneOfThatShouldBeUnion)(options, field)) {
|
|
2012
|
-
const oneofName = options
|
|
2013
|
-
? propertyName
|
|
2014
|
-
: (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[field.oneofIndex].name, options);
|
|
2015
|
+
const oneofName = (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[field.oneofIndex].name, options);
|
|
2015
2016
|
const oneofNameWithMessage = (0, utils_1.getPropertyAccessor)("message", oneofName);
|
|
2016
2017
|
const oneofNameWithObject = (0, utils_1.getPropertyAccessor)("object", oneofName);
|
|
2017
|
-
const v = readSnippet(`${oneofNameWithObject}.${
|
|
2018
|
+
const v = readSnippet(`${oneofNameWithObject}.${fieldName}`);
|
|
2018
2019
|
chunks.push((0, ts_poet_1.code) `
|
|
2019
2020
|
if (
|
|
2020
|
-
${oneofNameWithObject}?.$case === '${
|
|
2021
|
-
&& ${oneofNameWithObject}?.${
|
|
2022
|
-
&& ${oneofNameWithObject}?.${
|
|
2021
|
+
${oneofNameWithObject}?.$case === '${fieldName}'
|
|
2022
|
+
&& ${oneofNameWithObject}?.${fieldName} !== undefined
|
|
2023
|
+
&& ${oneofNameWithObject}?.${fieldName} !== null
|
|
2023
2024
|
) {
|
|
2024
|
-
${oneofNameWithMessage} = { $case: '${
|
|
2025
|
+
${oneofNameWithMessage} = { $case: '${fieldName}', ${fieldName}: ${v} };
|
|
2025
2026
|
}
|
|
2026
2027
|
`);
|
|
2027
2028
|
}
|
package/build/types.js
CHANGED
|
@@ -512,6 +512,7 @@ function wrapperTypeName(typeName) {
|
|
|
512
512
|
case ".google.protobuf.ListValue":
|
|
513
513
|
case ".google.protobuf.Timestamp":
|
|
514
514
|
case ".google.protobuf.Struct":
|
|
515
|
+
case ".google.protobuf.Value":
|
|
515
516
|
return typeName.split(".")[3];
|
|
516
517
|
default:
|
|
517
518
|
return undefined;
|
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.impFile = exports.getPropertyAccessor = exports.
|
|
3
|
+
exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const ts_poet_1 = require("ts-poet");
|
|
6
6
|
const options_1 = require("./options");
|
|
@@ -199,30 +199,24 @@ function getFieldJsonName(field, options) {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
exports.getFieldJsonName = getFieldJsonName;
|
|
202
|
-
function
|
|
202
|
+
function getFieldName(field, options) {
|
|
203
203
|
if (options.useJsonName) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
validatedPropertyName: validateObjectProperty(jsonName),
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
const propertyName = (0, case_1.maybeSnakeToCamel)(field.name, options);
|
|
211
|
-
return {
|
|
212
|
-
propertyName,
|
|
213
|
-
validatedPropertyName: propertyName,
|
|
214
|
-
};
|
|
204
|
+
return field.jsonName;
|
|
205
|
+
}
|
|
206
|
+
return (0, case_1.maybeSnakeToCamel)(field.name, options);
|
|
215
207
|
}
|
|
216
|
-
exports.
|
|
208
|
+
exports.getFieldName = getFieldName;
|
|
217
209
|
/**
|
|
218
210
|
* https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/the-dangers-of-square-bracket-notation.md
|
|
219
211
|
*/
|
|
220
|
-
function
|
|
212
|
+
function isValidIdentifier(propertyName) {
|
|
221
213
|
return /^[a-zA-Z_$][\w$]*$/.test(propertyName);
|
|
222
214
|
}
|
|
223
|
-
|
|
224
|
-
|
|
215
|
+
/** Returns `bar` or `"bar"` if `propertyName` isn't a safe property name. */
|
|
216
|
+
function safeAccessor(propertyName) {
|
|
217
|
+
return isValidIdentifier(propertyName) ? propertyName : JSON.stringify(propertyName);
|
|
225
218
|
}
|
|
219
|
+
exports.safeAccessor = safeAccessor;
|
|
226
220
|
/**
|
|
227
221
|
* Returns a snippet for reading an object's property, such as `foo.bar`, or `foo['bar']` if the property name contains unusual characters.
|
|
228
222
|
* For simplicity, we don't match the ECMA 5/6 rules for valid identifiers exactly, and return array syntax liberally.
|
|
@@ -231,9 +225,9 @@ function validateObjectProperty(propertyName) {
|
|
|
231
225
|
* @param optional
|
|
232
226
|
*/
|
|
233
227
|
function getPropertyAccessor(objectName, propertyName, optional = false) {
|
|
234
|
-
return
|
|
228
|
+
return isValidIdentifier(propertyName)
|
|
235
229
|
? `${objectName}${optional ? "?" : ""}.${propertyName}`
|
|
236
|
-
: `${objectName}${optional ? "?." : ""}[${
|
|
230
|
+
: `${objectName}${optional ? "?." : ""}[${safeAccessor(propertyName)}]`;
|
|
237
231
|
}
|
|
238
232
|
exports.getPropertyAccessor = getPropertyAccessor;
|
|
239
233
|
function impFile(options, spec) {
|