ts-proto 1.181.2 → 2.0.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/build/protos/google/protobuf/compiler/plugin.d.ts +185 -0
- package/build/protos/google/protobuf/compiler/plugin.js +501 -0
- package/build/protos/google/protobuf/descriptor.d.ts +1155 -0
- package/build/protos/google/protobuf/descriptor.js +4237 -0
- package/build/protos/index.d.ts +2 -0
- package/build/protos/index.js +18 -0
- package/build/{case.js → src/case.js} +6 -7
- package/build/{context.js → src/context.js} +1 -2
- package/build/{encode.js → src/encode.js} +2 -3
- package/build/{enums.js → src/enums.js} +5 -6
- package/build/{generate-async-iterable.js → src/generate-async-iterable.js} +2 -3
- package/build/{generate-generic-service-definition.js → src/generate-generic-service-definition.js} +1 -2
- package/build/{generate-grpc-js.js → src/generate-grpc-js.js} +1 -2
- package/build/{generate-grpc-web.js → src/generate-grpc-web.js} +4 -5
- package/build/{generate-nestjs.js → src/generate-nestjs.js} +3 -4
- package/build/{generate-nice-grpc.js → src/generate-nice-grpc.js} +1 -2
- package/build/{generate-services.js → src/generate-services.js} +11 -12
- package/build/{generate-struct-wrappers.js → src/generate-struct-wrappers.js} +5 -6
- package/build/{generate-type-registry.js → src/generate-type-registry.js} +5 -7
- package/build/{main.d.ts → src/main.d.ts} +1 -3
- package/build/{main.js → src/main.js} +69 -84
- package/build/{options.js → src/options.js} +5 -5
- package/build/{schema.js → src/schema.js} +5 -7
- package/build/{types.js → src/types.js} +51 -53
- package/build/{utils.d.ts → src/utils.d.ts} +0 -2
- package/build/{utils.js → src/utils.js} +28 -28
- package/build/{visit.js → src/visit.js} +2 -3
- package/package.json +12 -10
- /package/build/{case.d.ts → src/case.d.ts} +0 -0
- /package/build/{context.d.ts → src/context.d.ts} +0 -0
- /package/build/{encode.d.ts → src/encode.d.ts} +0 -0
- /package/build/{enums.d.ts → src/enums.d.ts} +0 -0
- /package/build/{generate-async-iterable.d.ts → src/generate-async-iterable.d.ts} +0 -0
- /package/build/{generate-generic-service-definition.d.ts → src/generate-generic-service-definition.d.ts} +0 -0
- /package/build/{generate-grpc-js.d.ts → src/generate-grpc-js.d.ts} +0 -0
- /package/build/{generate-grpc-web.d.ts → src/generate-grpc-web.d.ts} +0 -0
- /package/build/{generate-nestjs.d.ts → src/generate-nestjs.d.ts} +0 -0
- /package/build/{generate-nice-grpc.d.ts → src/generate-nice-grpc.d.ts} +0 -0
- /package/build/{generate-services.d.ts → src/generate-services.d.ts} +0 -0
- /package/build/{generate-struct-wrappers.d.ts → src/generate-struct-wrappers.d.ts} +0 -0
- /package/build/{generate-type-registry.d.ts → src/generate-type-registry.d.ts} +0 -0
- /package/build/{index.d.ts → src/index.d.ts} +0 -0
- /package/build/{index.js → src/index.js} +0 -0
- /package/build/{options.d.ts → src/options.d.ts} +0 -0
- /package/build/{plugin.d.ts → src/plugin.d.ts} +0 -0
- /package/build/{plugin.js → src/plugin.js} +0 -0
- /package/build/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/build/{sourceInfo.d.ts → src/sourceInfo.d.ts} +0 -0
- /package/build/{sourceInfo.js → src/sourceInfo.js} +0 -0
- /package/build/{types.d.ts → src/types.d.ts} +0 -0
- /package/build/{visit.d.ts → src/visit.d.ts} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.contextTypeVar =
|
|
3
|
+
exports.contextTypeVar = void 0;
|
|
4
|
+
exports.generateFile = generateFile;
|
|
5
|
+
exports.makeUtils = makeUtils;
|
|
4
6
|
const ts_poet_1 = require("ts-poet");
|
|
5
7
|
const ConditionalOutput_1 = require("ts-poet/build/ConditionalOutput");
|
|
6
8
|
const ts_proto_descriptors_1 = require("ts-proto-descriptors");
|
|
@@ -275,7 +277,6 @@ function generateFile(ctx, fileDesc) {
|
|
|
275
277
|
}
|
|
276
278
|
return [moduleName, (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" })];
|
|
277
279
|
}
|
|
278
|
-
exports.generateFile = generateFile;
|
|
279
280
|
/** These are runtime utility methods used by the generated code. */
|
|
280
281
|
function makeUtils(options) {
|
|
281
282
|
const bytes = makeByteUtils(options);
|
|
@@ -293,7 +294,6 @@ function makeUtils(options) {
|
|
|
293
294
|
...makeAssertionUtils(bytes),
|
|
294
295
|
};
|
|
295
296
|
}
|
|
296
|
-
exports.makeUtils = makeUtils;
|
|
297
297
|
function makeProtobufTimestampWrapper() {
|
|
298
298
|
const wrappers = (0, ts_poet_1.imp)("wrappers@protobufjs");
|
|
299
299
|
return (0, ts_poet_1.code) `
|
|
@@ -319,47 +319,25 @@ function makeProtobufStructWrapper(options) {
|
|
|
319
319
|
} as any;`;
|
|
320
320
|
}
|
|
321
321
|
function makeLongUtils(options, bytes) {
|
|
322
|
-
|
|
323
|
-
// the `long` library to either represent or at least sanity-check 64-bit values
|
|
324
|
-
const util = (0, utils_1.impFile)(options, `util@protobufjs/minimal`);
|
|
325
|
-
const configure = (0, utils_1.impFile)(options, `configure@protobufjs/minimal`);
|
|
326
|
-
const LongImp = (0, ts_poet_1.imp)("Long=long");
|
|
327
|
-
// Instead of exposing `LongImp` directly, let callers think that they are getting the
|
|
328
|
-
// `imp(Long)` but really it is that + our long initialization snippet. This means the
|
|
329
|
-
// initialization code will only be emitted in files that actually use the Long import.
|
|
330
|
-
const Long = (0, ts_poet_1.conditionalOutput)("Long", (0, ts_poet_1.code) `
|
|
331
|
-
if (${util}.Long !== ${LongImp}) {
|
|
332
|
-
${util}.Long = ${LongImp} as any;
|
|
333
|
-
${configure}();
|
|
334
|
-
}
|
|
335
|
-
`);
|
|
322
|
+
const Long = (0, ts_poet_1.imp)("Long=long");
|
|
336
323
|
const numberToLong = (0, ts_poet_1.conditionalOutput)("numberToLong", (0, ts_poet_1.code) `
|
|
337
324
|
function numberToLong(number: number) {
|
|
338
325
|
return ${Long}.fromNumber(number);
|
|
339
326
|
}
|
|
340
327
|
`);
|
|
341
|
-
const longToString = (0, ts_poet_1.conditionalOutput)("longToString", (0, ts_poet_1.code) `
|
|
342
|
-
function longToString(long: ${Long}) {
|
|
343
|
-
return long.toString();
|
|
344
|
-
}
|
|
345
|
-
`);
|
|
346
|
-
const longToBigint = (0, ts_poet_1.conditionalOutput)("longToBigint", (0, ts_poet_1.code) `
|
|
347
|
-
function longToBigint(long: ${Long}) {
|
|
348
|
-
return BigInt(long.toString());
|
|
349
|
-
}
|
|
350
|
-
`);
|
|
351
328
|
const longToNumber = (0, ts_poet_1.conditionalOutput)("longToNumber", (0, ts_poet_1.code) `
|
|
352
|
-
function longToNumber(
|
|
353
|
-
|
|
329
|
+
function longToNumber(int64: { toString(): string }): number {
|
|
330
|
+
const num = ${bytes.globalThis}.Number(int64.toString());
|
|
331
|
+
if (num > ${bytes.globalThis}.Number.MAX_SAFE_INTEGER) {
|
|
354
332
|
throw new ${bytes.globalThis}.Error("Value is larger than Number.MAX_SAFE_INTEGER")
|
|
355
333
|
}
|
|
356
|
-
if (
|
|
334
|
+
if (num < ${bytes.globalThis}.Number.MIN_SAFE_INTEGER) {
|
|
357
335
|
throw new ${bytes.globalThis}.Error("Value is smaller than Number.MIN_SAFE_INTEGER")
|
|
358
336
|
}
|
|
359
|
-
return
|
|
337
|
+
return num;
|
|
360
338
|
}
|
|
361
339
|
`);
|
|
362
|
-
return { numberToLong, longToNumber,
|
|
340
|
+
return { numberToLong, longToNumber, Long };
|
|
363
341
|
}
|
|
364
342
|
function makeByteUtils(options) {
|
|
365
343
|
const globalThisPolyfill = (0, ts_poet_1.conditionalOutput)("gt", (0, ts_poet_1.code) `
|
|
@@ -653,8 +631,6 @@ function makeGrpcWebErrorClass(bytes) {
|
|
|
653
631
|
return { GrpcWebError };
|
|
654
632
|
}
|
|
655
633
|
function makeExtensionClass(options) {
|
|
656
|
-
const Reader = (0, utils_1.impFile)(options, "Reader@protobufjs/minimal");
|
|
657
|
-
const Writer = (0, utils_1.impFile)(options, "Writer@protobufjs/minimal");
|
|
658
634
|
const Extension = (0, ts_poet_1.conditionalOutput)("Extension", (0, ts_poet_1.code) `
|
|
659
635
|
export interface Extension <T> {
|
|
660
636
|
number: number;
|
|
@@ -796,31 +772,39 @@ function getDecodeReadSnippet(ctx, field) {
|
|
|
796
772
|
readSnippet = (0, ts_poet_1.code) `reader.${(0, types_1.toReaderCall)(field)}()`;
|
|
797
773
|
if ((0, types_1.isBytes)(field)) {
|
|
798
774
|
if (options.env === options_1.EnvOption.NODE) {
|
|
799
|
-
readSnippet = (0, ts_poet_1.code)
|
|
775
|
+
readSnippet = (0, ts_poet_1.code) `Buffer.from(${readSnippet})`;
|
|
800
776
|
}
|
|
801
777
|
}
|
|
802
778
|
else if ((0, types_1.basicLongWireType)(field.type) !== undefined) {
|
|
803
779
|
if ((0, types_1.isJsTypeFieldOption)(options, field)) {
|
|
804
780
|
switch (field.options.jstype) {
|
|
805
781
|
case ts_proto_descriptors_1.FieldOptions_JSType.JS_NUMBER:
|
|
806
|
-
readSnippet = (0, ts_poet_1.code) `${utils.longToNumber}(${readSnippet}
|
|
782
|
+
readSnippet = (0, ts_poet_1.code) `${utils.longToNumber}(${readSnippet})`;
|
|
807
783
|
break;
|
|
808
784
|
case ts_proto_descriptors_1.FieldOptions_JSType.JS_STRING:
|
|
809
|
-
readSnippet = (0, ts_poet_1.code) `${
|
|
785
|
+
readSnippet = (0, ts_poet_1.code) `${readSnippet}.toString()`;
|
|
810
786
|
break;
|
|
811
787
|
}
|
|
812
788
|
}
|
|
813
789
|
else if (options.forceLong === options_1.LongOption.LONG) {
|
|
814
|
-
|
|
790
|
+
switch (field.type) {
|
|
791
|
+
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_UINT64:
|
|
792
|
+
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_FIXED64:
|
|
793
|
+
readSnippet = (0, ts_poet_1.code) `${utils.Long}.fromString(${readSnippet}.toString(), true)`;
|
|
794
|
+
break;
|
|
795
|
+
default:
|
|
796
|
+
readSnippet = (0, ts_poet_1.code) `${utils.Long}.fromString(${readSnippet}.toString())`;
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
815
799
|
}
|
|
816
800
|
else if (options.forceLong === options_1.LongOption.STRING) {
|
|
817
|
-
readSnippet = (0, ts_poet_1.code) `${
|
|
801
|
+
readSnippet = (0, ts_poet_1.code) `${readSnippet}.toString()`;
|
|
818
802
|
}
|
|
819
803
|
else if (options.forceLong === options_1.LongOption.BIGINT) {
|
|
820
|
-
readSnippet = (0, ts_poet_1.code) `${
|
|
804
|
+
readSnippet = (0, ts_poet_1.code) `${readSnippet} as bigint`;
|
|
821
805
|
}
|
|
822
806
|
else {
|
|
823
|
-
readSnippet = (0, ts_poet_1.code) `${utils.longToNumber}(${readSnippet}
|
|
807
|
+
readSnippet = (0, ts_poet_1.code) `${utils.longToNumber}(${readSnippet})`;
|
|
824
808
|
}
|
|
825
809
|
}
|
|
826
810
|
else if ((0, types_1.isEnum)(field)) {
|
|
@@ -877,14 +861,14 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
877
861
|
if (options.usePrototypeForDefaults) {
|
|
878
862
|
createBase = (0, ts_poet_1.code) `Object.create(${createBase}) as ${fullName}`;
|
|
879
863
|
}
|
|
880
|
-
const
|
|
864
|
+
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
881
865
|
// create the basic function declaration
|
|
882
866
|
chunks.push((0, ts_poet_1.code) `
|
|
883
867
|
decode(
|
|
884
|
-
input: ${
|
|
868
|
+
input: ${BinaryReader} | Uint8Array,
|
|
885
869
|
length?: number,
|
|
886
870
|
): ${fullName} {
|
|
887
|
-
const reader = input instanceof ${
|
|
871
|
+
const reader = input instanceof ${BinaryReader} ? input : new ${BinaryReader}(input);
|
|
888
872
|
let end = length === undefined ? reader.len : reader.pos + length;
|
|
889
873
|
`);
|
|
890
874
|
chunks.push((0, ts_poet_1.code) `const message = ${createBase}${maybeAsAny(options)};`);
|
|
@@ -1019,10 +1003,8 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
1019
1003
|
`;
|
|
1020
1004
|
}
|
|
1021
1005
|
chunks.push((0, ts_poet_1.code) `
|
|
1022
|
-
const
|
|
1023
|
-
|
|
1024
|
-
const buf = reader.buf.slice(startPos, reader.pos);
|
|
1025
|
-
|
|
1006
|
+
const buf = reader.skip(tag & 7);
|
|
1007
|
+
|
|
1026
1008
|
${unknownFieldsInitializerSnippet}
|
|
1027
1009
|
const list = message._unknownFields${maybeNonNullAssertion}[tag];
|
|
1028
1010
|
|
|
@@ -1035,7 +1017,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
1035
1017
|
}
|
|
1036
1018
|
else {
|
|
1037
1019
|
chunks.push((0, ts_poet_1.code) `
|
|
1038
|
-
reader.
|
|
1020
|
+
reader.skip(tag & 7);
|
|
1039
1021
|
`);
|
|
1040
1022
|
}
|
|
1041
1023
|
// and then wrap up the while/return
|
|
@@ -1062,25 +1044,28 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
1062
1044
|
return (place, placeAlt) => (0, ts_poet_1.code) `if (BigInt.asIntN(64, ${place}) !== ${placeAlt ?? place}) {
|
|
1063
1045
|
throw new ${utils.globalThis}.Error('value provided for field ${place} of type ${fieldType} too large');
|
|
1064
1046
|
}
|
|
1065
|
-
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}
|
|
1047
|
+
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place})`;
|
|
1066
1048
|
case "uint64":
|
|
1067
1049
|
case "fixed64":
|
|
1068
1050
|
return (place, placeAlt) => (0, ts_poet_1.code) `if (BigInt.asUintN(64, ${place}) !== ${placeAlt ?? place}) {
|
|
1069
1051
|
throw new ${utils.globalThis}.Error('value provided for field ${place} of type ${fieldType} too large');
|
|
1070
1052
|
}
|
|
1071
|
-
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}
|
|
1053
|
+
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place})`;
|
|
1072
1054
|
default:
|
|
1073
1055
|
throw new Error(`unexpected BigInt type: ${fieldType}`);
|
|
1074
1056
|
}
|
|
1075
1057
|
}
|
|
1076
1058
|
else if ((0, types_1.isScalar)(field) || (0, types_1.isEnum)(field)) {
|
|
1077
1059
|
const tag = ((field.number << 3) | (0, types_1.basicWireType)(field.type)) >>> 0;
|
|
1060
|
+
if ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.LONG) {
|
|
1061
|
+
return (place) => (0, ts_poet_1.code) `writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
1062
|
+
}
|
|
1078
1063
|
return (place) => (0, ts_poet_1.code) `writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place})`;
|
|
1079
1064
|
}
|
|
1080
1065
|
else if ((0, types_1.isObjectId)(field) && options.useMongoObjectId) {
|
|
1081
1066
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1082
1067
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
1083
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toProtoObjectId}(${place}), writer.uint32(${tag}).fork()).
|
|
1068
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toProtoObjectId}(${place}), writer.uint32(${tag}).fork()).join()`;
|
|
1084
1069
|
}
|
|
1085
1070
|
else if ((0, types_1.isTimestamp)(field) &&
|
|
1086
1071
|
(options.useDate === options_1.DateOption.DATE ||
|
|
@@ -1088,7 +1073,7 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
1088
1073
|
options.useDate === options_1.DateOption.STRING_NANO)) {
|
|
1089
1074
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1090
1075
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
1091
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.uint32(${tag}).fork()).
|
|
1076
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.uint32(${tag}).fork()).join()`;
|
|
1092
1077
|
}
|
|
1093
1078
|
else if ((0, types_1.isValueType)(ctx, field)) {
|
|
1094
1079
|
const maybeTypeField = (0, options_1.addTypeToMessages)(options) ? `$type: '${field.typeName.slice(1)}',` : "";
|
|
@@ -1100,7 +1085,7 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
1100
1085
|
return (0, ts_poet_1.code) `{${maybeTypeField} value: ${place}!}`;
|
|
1101
1086
|
};
|
|
1102
1087
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1103
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${wrappedValue(place)}, writer.uint32(${tag}).fork()).
|
|
1088
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${wrappedValue(place)}, writer.uint32(${tag}).fork()).join()`;
|
|
1104
1089
|
}
|
|
1105
1090
|
else if ((0, types_1.isMessage)(field)) {
|
|
1106
1091
|
const type = (0, types_1.basicTypeName)(ctx, field);
|
|
@@ -1109,7 +1094,7 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
1109
1094
|
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer.uint32(${startTag})).uint32(${endTag})`;
|
|
1110
1095
|
}
|
|
1111
1096
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1112
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer.uint32(${tag}).fork()).
|
|
1097
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer.uint32(${tag}).fork()).join()`;
|
|
1113
1098
|
}
|
|
1114
1099
|
else {
|
|
1115
1100
|
throw new Error(`Unhandled field ${field}`);
|
|
@@ -1119,13 +1104,13 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
1119
1104
|
function generateEncode(ctx, fullName, messageDesc) {
|
|
1120
1105
|
const { options, utils, typeMap, currentFile } = ctx;
|
|
1121
1106
|
const chunks = [];
|
|
1122
|
-
const
|
|
1107
|
+
const BinaryWriter = (0, ts_poet_1.imp)("BinaryWriter@@bufbuild/protobuf/wire");
|
|
1123
1108
|
// create the basic function declaration
|
|
1124
1109
|
chunks.push((0, ts_poet_1.code) `
|
|
1125
1110
|
encode(
|
|
1126
1111
|
${messageDesc.field.length > 0 || options.unknownFields ? "message" : "_"}: ${fullName},
|
|
1127
|
-
writer: ${
|
|
1128
|
-
): ${
|
|
1112
|
+
writer: ${BinaryWriter} = new ${BinaryWriter}(),
|
|
1113
|
+
): ${BinaryWriter} {
|
|
1129
1114
|
`);
|
|
1130
1115
|
const processedOneofs = new Set();
|
|
1131
1116
|
const oneOfFieldsDict = messageDesc.field
|
|
@@ -1195,7 +1180,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1195
1180
|
for (const v of ${messageProperty}) {
|
|
1196
1181
|
writer.${(0, types_1.toReaderCall)(field)}(${toNumber}(v));
|
|
1197
1182
|
}
|
|
1198
|
-
writer.
|
|
1183
|
+
writer.join();
|
|
1199
1184
|
`;
|
|
1200
1185
|
if (isOptional) {
|
|
1201
1186
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -1211,13 +1196,13 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1211
1196
|
else {
|
|
1212
1197
|
// Ideally we'd reuse `writeSnippet` but it has tagging embedded inside of it.
|
|
1213
1198
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1214
|
-
const rhs = (x) => ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.
|
|
1199
|
+
const rhs = (x) => ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.LONG ? `${x}.toString()` : x);
|
|
1215
1200
|
let listWriteSnippet = (0, ts_poet_1.code) `
|
|
1216
1201
|
writer.uint32(${tag}).fork();
|
|
1217
1202
|
for (const v of ${messageProperty}) {
|
|
1218
1203
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1219
1204
|
}
|
|
1220
|
-
writer.
|
|
1205
|
+
writer.join();
|
|
1221
1206
|
`;
|
|
1222
1207
|
if ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.BIGINT) {
|
|
1223
1208
|
const fieldType = (0, types_1.toReaderCall)(field);
|
|
@@ -1233,7 +1218,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1233
1218
|
}
|
|
1234
1219
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1235
1220
|
}
|
|
1236
|
-
writer.
|
|
1221
|
+
writer.join();
|
|
1237
1222
|
`;
|
|
1238
1223
|
break;
|
|
1239
1224
|
case "uint64":
|
|
@@ -1246,7 +1231,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1246
1231
|
}
|
|
1247
1232
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1248
1233
|
}
|
|
1249
|
-
writer.
|
|
1234
|
+
writer.join();
|
|
1250
1235
|
`;
|
|
1251
1236
|
break;
|
|
1252
1237
|
default:
|
|
@@ -1318,12 +1303,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1318
1303
|
for (const [key, values] of Object.entries(message._unknownFields)) {
|
|
1319
1304
|
const tag = parseInt(key, 10);
|
|
1320
1305
|
for (const value of values) {
|
|
1321
|
-
writer.uint32(tag);
|
|
1322
|
-
(writer as any)['_push'](
|
|
1323
|
-
(val: Uint8Array, buf: Buffer, pos: number) => buf.set(val, pos),
|
|
1324
|
-
value.length,
|
|
1325
|
-
value
|
|
1326
|
-
);
|
|
1306
|
+
writer.uint32(tag).raw(value);
|
|
1327
1307
|
}
|
|
1328
1308
|
}
|
|
1329
1309
|
}`);
|
|
@@ -1403,8 +1383,8 @@ function generateExtension(ctx, message, extension) {
|
|
|
1403
1383
|
chunks.push((0, ts_poet_1.code) `singularTag: ${singularTag},`);
|
|
1404
1384
|
chunks.push((0, ts_poet_1.code) `repeated: ${extension.label == ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED},`);
|
|
1405
1385
|
chunks.push((0, ts_poet_1.code) `packed: ${extension.options?.packed ? true : false},`);
|
|
1406
|
-
const
|
|
1407
|
-
const
|
|
1386
|
+
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
1387
|
+
const BinaryWriter = (0, ts_poet_1.imp)("BinaryWriter@@bufbuild/protobuf/wire");
|
|
1408
1388
|
if (ctx.options.outputEncodeMethods === true ||
|
|
1409
1389
|
ctx.options.outputEncodeMethods === "encode-only" ||
|
|
1410
1390
|
ctx.options.outputEncodeMethods === "encode-no-creation") {
|
|
@@ -1422,18 +1402,23 @@ function generateExtension(ctx, message, extension) {
|
|
|
1422
1402
|
return (place) => (0, ts_poet_1.code) `writer.${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
1423
1403
|
}
|
|
1424
1404
|
else if ((0, types_1.isScalar)(field) || (0, types_1.isEnum)(field)) {
|
|
1425
|
-
|
|
1405
|
+
if ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.LONG) {
|
|
1406
|
+
return (place) => (0, ts_poet_1.code) `writer.${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
1407
|
+
}
|
|
1408
|
+
else {
|
|
1409
|
+
return (place) => (0, ts_poet_1.code) `writer.${(0, types_1.toReaderCall)(field)}(${place})`;
|
|
1410
|
+
}
|
|
1426
1411
|
}
|
|
1427
1412
|
else if ((0, types_1.isObjectId)(field) && options.useMongoObjectId) {
|
|
1428
1413
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
1429
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toProtoObjectId}(${place}), writer.fork()).
|
|
1414
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toProtoObjectId}(${place}), writer.fork()).join()`;
|
|
1430
1415
|
}
|
|
1431
1416
|
else if ((0, types_1.isTimestamp)(field) &&
|
|
1432
1417
|
(options.useDate === options_1.DateOption.DATE ||
|
|
1433
1418
|
options.useDate === options_1.DateOption.STRING ||
|
|
1434
1419
|
options.useDate === options_1.DateOption.STRING_NANO)) {
|
|
1435
1420
|
const type = (0, types_1.basicTypeName)(ctx, field, { keepValueType: true });
|
|
1436
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.fork()).
|
|
1421
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${utils.toTimestamp}(${place}), writer.fork()).join()`;
|
|
1437
1422
|
}
|
|
1438
1423
|
else if ((0, types_1.isValueType)(ctx, field)) {
|
|
1439
1424
|
const maybeTypeField = (0, options_1.addTypeToMessages)(options) ? `$type: '${field.typeName.slice(1)}',` : "";
|
|
@@ -1444,7 +1429,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1444
1429
|
}
|
|
1445
1430
|
return (0, ts_poet_1.code) `{${maybeTypeField} value: ${place}!}`;
|
|
1446
1431
|
};
|
|
1447
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${wrappedValue(place)}, writer.fork()).
|
|
1432
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${wrappedValue(place)}, writer.fork()).join()`;
|
|
1448
1433
|
}
|
|
1449
1434
|
else if ((0, types_1.isMessage)(field)) {
|
|
1450
1435
|
const type = (0, types_1.basicTypeName)(ctx, field);
|
|
@@ -1452,7 +1437,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1452
1437
|
const endTag = ((field.number << 3) | 4) >>> 0;
|
|
1453
1438
|
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer).uint32(${endTag})`;
|
|
1454
1439
|
}
|
|
1455
|
-
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer.fork()).
|
|
1440
|
+
return (place) => (0, ts_poet_1.code) `${type}.encode(${place}, writer.fork()).join()`;
|
|
1456
1441
|
}
|
|
1457
1442
|
else {
|
|
1458
1443
|
throw new Error(`Unhandled field ${field}`);
|
|
@@ -1463,21 +1448,21 @@ function generateExtension(ctx, message, extension) {
|
|
|
1463
1448
|
if (packedTag === undefined) {
|
|
1464
1449
|
chunks.push((0, ts_poet_1.code) `
|
|
1465
1450
|
for (const v of value) {
|
|
1466
|
-
const writer = ${
|
|
1451
|
+
const writer = new ${BinaryWriter}();
|
|
1467
1452
|
${writeSnippet("v")};
|
|
1468
1453
|
encoded.push(writer.finish());
|
|
1469
1454
|
}
|
|
1470
1455
|
`);
|
|
1471
1456
|
}
|
|
1472
1457
|
else {
|
|
1473
|
-
const rhs = (x) => (0, types_1.isLong)(extension) && ctx.options.forceLong === options_1.LongOption.
|
|
1458
|
+
const rhs = (x) => (0, types_1.isLong)(extension) && ctx.options.forceLong === options_1.LongOption.LONG ? `${x}.toString()` : x;
|
|
1474
1459
|
chunks.push((0, ts_poet_1.code) `
|
|
1475
|
-
const writer = ${
|
|
1460
|
+
const writer = new ${BinaryWriter};
|
|
1476
1461
|
writer.fork();
|
|
1477
1462
|
for (const v of value) {
|
|
1478
1463
|
${writeSnippet(rhs("v"))};
|
|
1479
1464
|
}
|
|
1480
|
-
writer.
|
|
1465
|
+
writer.join();
|
|
1481
1466
|
encoded.push(writer.finish());
|
|
1482
1467
|
`);
|
|
1483
1468
|
}
|
|
@@ -1485,7 +1470,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1485
1470
|
else if ((0, types_1.isScalar)(extension) || (0, types_1.isEnum)(extension)) {
|
|
1486
1471
|
chunks.push((0, ts_poet_1.code) `
|
|
1487
1472
|
if (${(0, types_1.notDefaultCheck)(ctx, extension, message?.options, "value")}) {
|
|
1488
|
-
const writer = ${
|
|
1473
|
+
const writer = new ${BinaryWriter};
|
|
1489
1474
|
${writeSnippet("value")};
|
|
1490
1475
|
encoded.push(writer.finish());
|
|
1491
1476
|
}
|
|
@@ -1493,7 +1478,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1493
1478
|
}
|
|
1494
1479
|
else {
|
|
1495
1480
|
chunks.push((0, ts_poet_1.code) `
|
|
1496
|
-
const writer = ${
|
|
1481
|
+
const writer = new ${BinaryWriter};
|
|
1497
1482
|
${writeSnippet("value")};
|
|
1498
1483
|
encoded.push(writer.finish());
|
|
1499
1484
|
`);
|
|
@@ -1512,7 +1497,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1512
1497
|
// start loop over all buffers
|
|
1513
1498
|
chunks.push((0, ts_poet_1.code) `
|
|
1514
1499
|
for (const buffer of input) {
|
|
1515
|
-
const reader = ${
|
|
1500
|
+
const reader = new ${BinaryReader}(buffer);
|
|
1516
1501
|
`);
|
|
1517
1502
|
if ((0, types_1.packedType)(extension.type) === undefined) {
|
|
1518
1503
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -1541,7 +1526,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1541
1526
|
else {
|
|
1542
1527
|
// pick the last entry, since it overrides all previous entries if not repeated
|
|
1543
1528
|
chunks.push((0, ts_poet_1.code) `
|
|
1544
|
-
const reader = ${
|
|
1529
|
+
const reader = new ${BinaryReader}(input[input.length -1] ?? ${ctx.utils.fail}());
|
|
1545
1530
|
return ${readSnippet};
|
|
1546
1531
|
},
|
|
1547
1532
|
`);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ServiceOption = exports.OneofOption = exports.EnvOption = exports.JsonTimestampOption = exports.DateOption = exports.LongOption = void 0;
|
|
4
|
+
exports.defaultOptions = defaultOptions;
|
|
5
|
+
exports.optionsFromParameter = optionsFromParameter;
|
|
6
|
+
exports.getTsPoetOpts = getTsPoetOpts;
|
|
7
|
+
exports.addTypeToMessages = addTypeToMessages;
|
|
4
8
|
var LongOption;
|
|
5
9
|
(function (LongOption) {
|
|
6
10
|
LongOption["NUMBER"] = "number";
|
|
@@ -110,7 +114,6 @@ function defaultOptions() {
|
|
|
110
114
|
typeSuffix: "",
|
|
111
115
|
};
|
|
112
116
|
}
|
|
113
|
-
exports.defaultOptions = defaultOptions;
|
|
114
117
|
const nestJsOptions = {
|
|
115
118
|
lowerCaseServiceMethods: true,
|
|
116
119
|
outputEncodeMethods: false,
|
|
@@ -215,7 +218,6 @@ function optionsFromParameter(parameter) {
|
|
|
215
218
|
}
|
|
216
219
|
return options;
|
|
217
220
|
}
|
|
218
|
-
exports.optionsFromParameter = optionsFromParameter;
|
|
219
221
|
// A very naive parse function, eventually could/should use iots/runtypes
|
|
220
222
|
function parseParameter(parameter) {
|
|
221
223
|
const options = { M: {} };
|
|
@@ -273,8 +275,6 @@ ${fileName ? `// source: ${fileName}` : ""}
|
|
|
273
275
|
forceModuleImport: esModuleInterop ? [] : [pbjs],
|
|
274
276
|
};
|
|
275
277
|
}
|
|
276
|
-
exports.getTsPoetOpts = getTsPoetOpts;
|
|
277
278
|
function addTypeToMessages(options) {
|
|
278
279
|
return ((options.outputTypeAnnotations || options.outputTypeRegistry) && options.outputTypeAnnotations !== "static-only");
|
|
279
280
|
}
|
|
280
|
-
exports.addTypeToMessages = addTypeToMessages;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateSchema =
|
|
3
|
+
exports.generateSchema = generateSchema;
|
|
4
4
|
const ts_proto_descriptors_1 = require("ts-proto-descriptors");
|
|
5
5
|
const ts_poet_1 = require("ts-poet");
|
|
6
6
|
const visit_1 = require("./visit");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const types_1 = require("./types");
|
|
9
|
-
const
|
|
9
|
+
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
10
10
|
const fileDescriptorProto = (0, ts_poet_1.imp)("FileDescriptorProto@ts-proto-descriptors");
|
|
11
11
|
const extensionCache = {};
|
|
12
12
|
function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
@@ -156,21 +156,19 @@ function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
|
156
156
|
`);
|
|
157
157
|
return chunks;
|
|
158
158
|
}
|
|
159
|
-
exports.generateSchema = generateSchema;
|
|
160
159
|
function getExtensionValue(ctx, extension, data) {
|
|
161
160
|
if (extension.type == ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_MESSAGE) {
|
|
162
161
|
const typeName = (0, types_1.basicTypeName)(ctx, extension);
|
|
163
162
|
const resultBuffer = Buffer.concat(data.map((d) => {
|
|
164
163
|
// Skip length byte
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
return reader.buf.slice(reader.pos);
|
|
164
|
+
const bytes = new wire_1.BinaryReader(d).bytes();
|
|
165
|
+
return Buffer.from(bytes);
|
|
168
166
|
}));
|
|
169
167
|
const result = resultBuffer.toString("base64");
|
|
170
168
|
return (0, ts_poet_1.code) `'${extension.name}': ${typeName}.decode(Buffer.from('${result}', 'base64'))`;
|
|
171
169
|
}
|
|
172
170
|
else {
|
|
173
|
-
const reader = new
|
|
171
|
+
const reader = new wire_1.BinaryReader(data[0]);
|
|
174
172
|
let value = reader[(0, types_1.toReaderCall)(extension)]();
|
|
175
173
|
if (typeof value === "string") {
|
|
176
174
|
value = (0, ts_poet_1.code) `"${value}"`;
|