ts-proto 2.11.6 → 2.11.7
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/src/main.js +11 -3
- package/package.json +1 -1
package/build/src/main.js
CHANGED
|
@@ -72,8 +72,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
72
72
|
const prefix = (0, case_1.camelToSnake)(fileDesc.package.replace(/\./g, "_"));
|
|
73
73
|
chunks.push((0, ts_poet_1.code) `export const ${prefix}_PACKAGE_NAME = '${fileDesc.package}';`);
|
|
74
74
|
}
|
|
75
|
-
if (options.useDate === options_1.DateOption.DATE &&
|
|
76
|
-
fileDesc.messageType.find((message) => message.field.find((field) => field.typeName === ".google.protobuf.Timestamp"))) {
|
|
75
|
+
if (options.useDate === options_1.DateOption.DATE && fileDesc.messageType.find(hasTimestampField)) {
|
|
77
76
|
chunks.push(makeProtobufTimestampWrapper());
|
|
78
77
|
}
|
|
79
78
|
}
|
|
@@ -220,7 +219,7 @@ function generateFile(ctx, fileDesc) {
|
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
if (options.nestJs) {
|
|
223
|
-
if (fileDesc.messageType.find(
|
|
222
|
+
if (fileDesc.messageType.find(hasStructTypeField)) {
|
|
224
223
|
chunks.push(makeProtobufStructWrapper(options));
|
|
225
224
|
}
|
|
226
225
|
}
|
|
@@ -358,6 +357,15 @@ function makeProtobufTimestampWrapper() {
|
|
|
358
357
|
},
|
|
359
358
|
} as any;`;
|
|
360
359
|
}
|
|
360
|
+
function hasField(message, predicate) {
|
|
361
|
+
return (message.field.some(predicate) || message.nestedType.some((nestedMessage) => hasField(nestedMessage, predicate)));
|
|
362
|
+
}
|
|
363
|
+
function hasTimestampField(message) {
|
|
364
|
+
return hasField(message, types_1.isTimestamp);
|
|
365
|
+
}
|
|
366
|
+
function hasStructTypeField(message) {
|
|
367
|
+
return hasField(message, types_1.isStructType);
|
|
368
|
+
}
|
|
361
369
|
function makeProtobufStructWrapper(options) {
|
|
362
370
|
const wrappers = (0, ts_poet_1.imp)("wrappers@protobufjs");
|
|
363
371
|
const Struct = (0, utils_1.impProto)(options, "google/protobuf/struct", (0, utils_1.wrapTypeName)(options, "Struct"));
|