ts-proto 2.7.4 → 2.7.6
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/generate-grpc-js.js +2 -2
- package/build/src/generate-nestjs.js +2 -2
- package/build/src/generate-services.js +3 -3
- package/build/src/generate-type-registry.js +2 -2
- package/build/src/main.js +22 -11
- package/build/src/schema.js +1 -1
- package/build/src/types.d.ts +1 -0
- package/build/src/types.js +10 -0
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ const types_1 = require("./types");
|
|
|
7
7
|
const utils_1 = require("./utils");
|
|
8
8
|
const encode_1 = require("./encode");
|
|
9
9
|
const CallOptions = (0, ts_poet_1.imp)("t:CallOptions@@grpc/grpc-js");
|
|
10
|
-
const ChannelCredentials = (0, ts_poet_1.imp)("ChannelCredentials@@grpc/grpc-js");
|
|
10
|
+
const ChannelCredentials = (0, ts_poet_1.imp)("t:ChannelCredentials@@grpc/grpc-js");
|
|
11
11
|
const ClientOptions = (0, ts_poet_1.imp)("t:ClientOptions@@grpc/grpc-js");
|
|
12
12
|
const Client = (0, ts_poet_1.imp)("Client@@grpc/grpc-js");
|
|
13
13
|
const ClientDuplexStream = (0, ts_poet_1.imp)("t:ClientDuplexStream@@grpc/grpc-js");
|
|
@@ -20,7 +20,7 @@ const handleServerStreamingCall = (0, ts_poet_1.imp)("t:handleServerStreamingCal
|
|
|
20
20
|
const handleUnaryCall = (0, ts_poet_1.imp)("t:handleUnaryCall@@grpc/grpc-js");
|
|
21
21
|
const UntypedServiceImplementation = (0, ts_poet_1.imp)("t:UntypedServiceImplementation@@grpc/grpc-js");
|
|
22
22
|
const makeGenericClientConstructor = (0, ts_poet_1.imp)("makeGenericClientConstructor@@grpc/grpc-js");
|
|
23
|
-
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
23
|
+
const Metadata = (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
24
24
|
const ServiceError = (0, ts_poet_1.imp)("t:ServiceError@@grpc/grpc-js");
|
|
25
25
|
/**
|
|
26
26
|
* Generates a service definition and server / client stubs for the
|
|
@@ -11,7 +11,7 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
12
12
|
const { options } = ctx;
|
|
13
13
|
const chunks = [];
|
|
14
|
-
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
14
|
+
const Metadata = (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
15
15
|
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks, serviceDesc.options?.deprecated);
|
|
16
16
|
const t = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
17
17
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -72,7 +72,7 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
|
|
|
72
72
|
function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
73
73
|
const { options } = ctx;
|
|
74
74
|
const chunks = [];
|
|
75
|
-
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
75
|
+
const Metadata = (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
76
76
|
(0, utils_1.maybeAddComment)(options, sourceInfo, chunks);
|
|
77
77
|
const t = options.context ? `<${main_1.contextTypeVar}>` : ``;
|
|
78
78
|
chunks.push((0, ts_poet_1.code) `
|
|
@@ -50,7 +50,7 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
50
50
|
params.push((0, ts_poet_1.code) `metadata?: ${Metadata}`);
|
|
51
51
|
}
|
|
52
52
|
else if (options.addGrpcMetadata) {
|
|
53
|
-
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
53
|
+
const Metadata = (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
54
54
|
params.push((0, ts_poet_1.code) `metadata?: ${Metadata}`);
|
|
55
55
|
}
|
|
56
56
|
if (options.useAbortSignal) {
|
|
@@ -81,7 +81,7 @@ function generateRegularRpcMethod(ctx, methodDesc) {
|
|
|
81
81
|
const rawInputType = (0, types_1.rawRequestType)(ctx, methodDesc, { keepValueType: true });
|
|
82
82
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
83
83
|
const rawOutputType = (0, types_1.responseType)(ctx, methodDesc, { keepValueType: true });
|
|
84
|
-
const metadataType = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
84
|
+
const metadataType = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
85
85
|
const params = [
|
|
86
86
|
...(options.context ? [(0, ts_poet_1.code) `ctx: Context`] : []),
|
|
87
87
|
(0, ts_poet_1.code) `request: ${inputType}`,
|
|
@@ -334,7 +334,7 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
334
334
|
*/
|
|
335
335
|
function generateRpcType(ctx, hasStreamingMethods) {
|
|
336
336
|
const { options } = ctx;
|
|
337
|
-
const metadata = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
337
|
+
const metadata = options.metadataType ? (0, ts_poet_1.imp)(options.metadataType) : (0, ts_poet_1.imp)("t:Metadata@@grpc/grpc-js");
|
|
338
338
|
const metadataType = metadata.symbol;
|
|
339
339
|
const maybeContext = options.context ? "<Context>" : "";
|
|
340
340
|
const maybeContextParam = options.context ? "ctx: Context," : "";
|
|
@@ -32,8 +32,8 @@ function generateMessageType(ctx) {
|
|
|
32
32
|
chunks.push((0, ts_poet_1.code) `$type: string;`);
|
|
33
33
|
}
|
|
34
34
|
if (ctx.options.outputEncodeMethods) {
|
|
35
|
-
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
36
|
-
const BinaryWriter = (0, ts_poet_1.imp)("BinaryWriter@@bufbuild/protobuf/wire");
|
|
35
|
+
const BinaryReader = (0, ts_poet_1.imp)("t:BinaryReader@@bufbuild/protobuf/wire");
|
|
36
|
+
const BinaryWriter = (0, ts_poet_1.imp)("t:BinaryWriter@@bufbuild/protobuf/wire");
|
|
37
37
|
chunks.push((0, ts_poet_1.code) `encode(message: Message, writer?: ${BinaryWriter}): ${BinaryWriter};`);
|
|
38
38
|
chunks.push((0, ts_poet_1.code) `decode(input: ${BinaryReader} | Uint8Array, length?: number): Message;`);
|
|
39
39
|
}
|
package/build/src/main.js
CHANGED
|
@@ -511,8 +511,8 @@ function makeDeepPartial(options, longs) {
|
|
|
511
511
|
return { Builtin, DeepPartial, Exact };
|
|
512
512
|
}
|
|
513
513
|
function makeMessageFns(options, deepPartial, extension) {
|
|
514
|
-
const BinaryWriter = (0, ts_poet_1.imp)("BinaryWriter@@bufbuild/protobuf/wire");
|
|
515
|
-
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
514
|
+
const BinaryWriter = (0, ts_poet_1.imp)("t:BinaryWriter@@bufbuild/protobuf/wire");
|
|
515
|
+
const BinaryReader = (0, ts_poet_1.imp)("t:BinaryReader@@bufbuild/protobuf/wire");
|
|
516
516
|
const { Exact, DeepPartial } = deepPartial;
|
|
517
517
|
const { Extension } = extension;
|
|
518
518
|
const commonStaticMembers = [];
|
|
@@ -800,6 +800,7 @@ function makeExtensionClass(options) {
|
|
|
800
800
|
number: number;
|
|
801
801
|
tag: number;
|
|
802
802
|
singularTag?: number;
|
|
803
|
+
packedTag?: number;
|
|
803
804
|
encode?: (message: T) => Uint8Array[];
|
|
804
805
|
decode?: (tag: number, input: Uint8Array[]) => T;
|
|
805
806
|
repeated: boolean;
|
|
@@ -1009,7 +1010,7 @@ function getDecodeReadSnippet(ctx, field) {
|
|
|
1009
1010
|
return readSnippet;
|
|
1010
1011
|
}
|
|
1011
1012
|
function generateEmptyDecode(fullName) {
|
|
1012
|
-
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
1013
|
+
const BinaryReader = (0, ts_poet_1.imp)("t:BinaryReader@@bufbuild/protobuf/wire");
|
|
1013
1014
|
return (0, ts_poet_1.code) `
|
|
1014
1015
|
decode(
|
|
1015
1016
|
_: ${BinaryReader} | Uint8Array,
|
|
@@ -1340,7 +1341,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1340
1341
|
`);
|
|
1341
1342
|
}
|
|
1342
1343
|
}
|
|
1343
|
-
else if ((0, types_1.
|
|
1344
|
+
else if ((0, types_1.packedField)(field, currentFile.isProto3Syntax) === undefined) {
|
|
1344
1345
|
const listWriteSnippet = (0, ts_poet_1.code) `
|
|
1345
1346
|
for (const v of ${messageProperty}) {
|
|
1346
1347
|
${writeSnippet("v!")};
|
|
@@ -1512,6 +1513,9 @@ function generateSetExtension(ctx, fullName) {
|
|
|
1512
1513
|
if (extension.singularTag !== undefined) {
|
|
1513
1514
|
delete message._unknownFields[extension.singularTag];
|
|
1514
1515
|
}
|
|
1516
|
+
if (extension.packedTag !== undefined) {
|
|
1517
|
+
delete message._unknownFields[extension.packedTag];
|
|
1518
|
+
}
|
|
1515
1519
|
}
|
|
1516
1520
|
|
|
1517
1521
|
if (encoded.length !== 0) {
|
|
@@ -1539,14 +1543,17 @@ function generateGetExtension(ctx, fullName) {
|
|
|
1539
1543
|
results = extension.decode!(extension.tag, list);
|
|
1540
1544
|
}
|
|
1541
1545
|
|
|
1542
|
-
if (extension.singularTag === undefined
|
|
1546
|
+
if (extension.singularTag === undefined ||
|
|
1547
|
+
extension.packedTag === undefined) {
|
|
1543
1548
|
return results;
|
|
1544
1549
|
}
|
|
1545
1550
|
|
|
1546
|
-
|
|
1551
|
+
const nonDefaultTag = (extension.singularTag === extension.tag) ?
|
|
1552
|
+
extension.packedTag : extension.singularTag;
|
|
1553
|
+
list = message._unknownFields[nonDefaultTag];
|
|
1547
1554
|
|
|
1548
1555
|
if (list !== undefined) {
|
|
1549
|
-
const results2 = extension.decode!(
|
|
1556
|
+
const results2 = extension.decode!(nonDefaultTag, list);
|
|
1550
1557
|
|
|
1551
1558
|
if (results !== undefined && (results as any).length !== 0) {
|
|
1552
1559
|
results = (results as any).concat(results2);
|
|
@@ -1561,15 +1568,19 @@ function generateGetExtension(ctx, fullName) {
|
|
|
1561
1568
|
}
|
|
1562
1569
|
function generateExtension(ctx, message, extension) {
|
|
1563
1570
|
const type = (0, types_1.toTypeName)(ctx, message, extension);
|
|
1571
|
+
const { currentFile } = ctx;
|
|
1564
1572
|
const packedTag = (0, types_1.isRepeated)(extension) && (0, types_1.packedType)(extension.type) !== undefined ? ((extension.number << 3) | 2) >>> 0 : undefined;
|
|
1565
1573
|
const singularTag = ((extension.number << 3) | (0, types_1.basicWireType)(extension.type)) >>> 0;
|
|
1566
|
-
const
|
|
1574
|
+
const packed = (0, types_1.isRepeated)(extension) && (0, types_1.packedField)(extension, currentFile.isProto3Syntax);
|
|
1575
|
+
const tag = packed ? packedTag : singularTag;
|
|
1567
1576
|
const chunks = [];
|
|
1568
1577
|
chunks.push((0, ts_poet_1.code) `{`);
|
|
1569
1578
|
chunks.push((0, ts_poet_1.code) `number: ${extension.number},`);
|
|
1570
1579
|
chunks.push((0, ts_poet_1.code) `tag: ${tag},`);
|
|
1571
|
-
if (packedTag !== undefined)
|
|
1580
|
+
if (packedTag !== undefined) {
|
|
1572
1581
|
chunks.push((0, ts_poet_1.code) `singularTag: ${singularTag},`);
|
|
1582
|
+
chunks.push((0, ts_poet_1.code) `packedTag: ${packedTag},`);
|
|
1583
|
+
}
|
|
1573
1584
|
chunks.push((0, ts_poet_1.code) `repeated: ${extension.label == ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED},`);
|
|
1574
1585
|
chunks.push((0, ts_poet_1.code) `packed: ${extension.options?.packed ? true : false},`);
|
|
1575
1586
|
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
@@ -1634,7 +1645,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1634
1645
|
}
|
|
1635
1646
|
const writeSnippet = getEncodeSnippet(ctx, extension);
|
|
1636
1647
|
if ((0, types_1.isRepeated)(extension)) {
|
|
1637
|
-
if (
|
|
1648
|
+
if (!packed) {
|
|
1638
1649
|
chunks.push((0, ts_poet_1.code) `
|
|
1639
1650
|
for (const v of value) {
|
|
1640
1651
|
const writer = new ${BinaryWriter}();
|
|
@@ -1688,7 +1699,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1688
1699
|
for (const buffer of input) {
|
|
1689
1700
|
const reader = new ${BinaryReader}(buffer);
|
|
1690
1701
|
`);
|
|
1691
|
-
if (
|
|
1702
|
+
if (packedTag === undefined) {
|
|
1692
1703
|
chunks.push((0, ts_poet_1.code) `
|
|
1693
1704
|
values.push(${readSnippet});
|
|
1694
1705
|
`);
|
package/build/src/schema.js
CHANGED
|
@@ -8,7 +8,7 @@ const utils_1 = require("./utils");
|
|
|
8
8
|
const types_1 = require("./types");
|
|
9
9
|
const wire_1 = require("@bufbuild/protobuf/wire");
|
|
10
10
|
const options_1 = require("./options");
|
|
11
|
-
const fileDescriptorProto = (0, ts_poet_1.imp)("FileDescriptorProto@ts-proto-descriptors");
|
|
11
|
+
const fileDescriptorProto = (0, ts_poet_1.imp)("t:FileDescriptorProto@ts-proto-descriptors");
|
|
12
12
|
const extensionCache = {};
|
|
13
13
|
function generateSchema(ctx, fileDesc, sourceInfo) {
|
|
14
14
|
const { options } = ctx;
|
package/build/src/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function basicTypeName(ctx: Context, field: FieldDescriptorProto,
|
|
|
11
11
|
}): Code;
|
|
12
12
|
/** Returns the Reader method for the primitive's read/write call. */
|
|
13
13
|
export declare function toReaderCall(field: FieldDescriptorProto): string;
|
|
14
|
+
export declare function packedField(field: FieldDescriptorProto, isProto3Syntax: boolean): number | undefined;
|
|
14
15
|
export declare function packedType(type: FieldDescriptorProto_Type): number | undefined;
|
|
15
16
|
export declare function getFieldOptionsJsType(field: FieldDescriptorProto, options: Options): FieldDescriptorProto_Type | undefined;
|
|
16
17
|
export declare function defaultValue(ctx: Context, field: FieldDescriptorProto): any;
|
package/build/src/types.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.basicWireType = basicWireType;
|
|
|
4
4
|
exports.basicLongWireType = basicLongWireType;
|
|
5
5
|
exports.basicTypeName = basicTypeName;
|
|
6
6
|
exports.toReaderCall = toReaderCall;
|
|
7
|
+
exports.packedField = packedField;
|
|
7
8
|
exports.packedType = packedType;
|
|
8
9
|
exports.getFieldOptionsJsType = getFieldOptionsJsType;
|
|
9
10
|
exports.defaultValue = defaultValue;
|
|
@@ -185,6 +186,15 @@ function toReaderCall(field) {
|
|
|
185
186
|
throw new Error(`Not a primitive field ${field}`);
|
|
186
187
|
}
|
|
187
188
|
}
|
|
189
|
+
function packedField(field, isProto3Syntax) {
|
|
190
|
+
if (isProto3Syntax && field.options?.packed === false) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
else if (!isProto3Syntax && !!field.options?.packed) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
return packedType(field.type);
|
|
197
|
+
}
|
|
188
198
|
function packedType(type) {
|
|
189
199
|
switch (type) {
|
|
190
200
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_DOUBLE:
|