ts-proto 2.11.5 → 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 +13 -5
- 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"));
|
|
@@ -422,7 +430,7 @@ function makeByteUtils(options) {
|
|
|
422
430
|
default:
|
|
423
431
|
return (0, ts_poet_1.code) `
|
|
424
432
|
if ((${globalThis} as any).Buffer) {
|
|
425
|
-
${
|
|
433
|
+
return Uint8Array.from((${globalThis} as any).Buffer.from(b64, 'base64'));
|
|
426
434
|
} else {
|
|
427
435
|
${bytesFromBase64BrowserSnippet}
|
|
428
436
|
}
|
|
@@ -453,7 +461,7 @@ function makeByteUtils(options) {
|
|
|
453
461
|
default:
|
|
454
462
|
return (0, ts_poet_1.code) `
|
|
455
463
|
if ((${globalThis} as any).Buffer) {
|
|
456
|
-
${
|
|
464
|
+
return (${globalThis} as any).Buffer.from(arr).toString('base64');
|
|
457
465
|
} else {
|
|
458
466
|
${base64FromBytesBrowserSnippet}
|
|
459
467
|
}
|