ts-proto 1.122.0 → 1.124.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/CHANGELOG.md +21 -0
- package/README.markdown +4 -1
- package/build/case.js +4 -4
- package/build/encode.js +21 -21
- package/build/enums.js +11 -11
- package/build/generate-generic-service-definition.js +2 -2
- package/build/generate-grpc-js.js +20 -20
- package/build/generate-grpc-web.js +11 -11
- package/build/generate-nestjs.js +15 -15
- package/build/generate-nice-grpc.js +5 -5
- package/build/generate-services.js +27 -27
- package/build/generate-type-registry.js +4 -4
- package/build/main.js +103 -103
- package/build/options.js +16 -12
- package/build/plugin.js +6 -6
- package/build/schema.js +37 -37
- package/build/sourceInfo.js +3 -3
- package/build/types.js +71 -71
- package/build/utils.js +14 -14
- package/build/visit.js +5 -5
- package/package.json +6 -6
|
@@ -6,8 +6,8 @@ const types_1 = require("./types");
|
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
const sourceInfo_1 = require("./sourceInfo");
|
|
8
8
|
const main_1 = require("./main");
|
|
9
|
-
const hash = (0, ts_poet_1.imp)(
|
|
10
|
-
const dataloader = (0, ts_poet_1.imp)(
|
|
9
|
+
const hash = (0, ts_poet_1.imp)("hash*object-hash");
|
|
10
|
+
const dataloader = (0, ts_poet_1.imp)("DataLoader*dataloader");
|
|
11
11
|
/**
|
|
12
12
|
* Generates an interface for `serviceDesc`.
|
|
13
13
|
*
|
|
@@ -23,7 +23,7 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
23
23
|
const { options } = ctx;
|
|
24
24
|
const chunks = [];
|
|
25
25
|
(0, utils_1.maybeAddComment)(sourceInfo, chunks, (_a = serviceDesc.options) === null || _a === void 0 ? void 0 : _a.deprecated);
|
|
26
|
-
const maybeTypeVar = options.context ? `<${main_1.contextTypeVar}>` :
|
|
26
|
+
const maybeTypeVar = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
27
27
|
chunks.push((0, ts_poet_1.code) `export interface ${(0, ts_poet_1.def)(serviceDesc.name)}${maybeTypeVar} {`);
|
|
28
28
|
serviceDesc.method.forEach((methodDesc, index) => {
|
|
29
29
|
var _a;
|
|
@@ -36,17 +36,17 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
36
36
|
}
|
|
37
37
|
// the grpc-web clients auto-`fromPartial` the input before handing off to grpc-web's
|
|
38
38
|
// serde runtime, so it's okay to accept partial results from the client
|
|
39
|
-
const partialInput = options.outputClientImpl ===
|
|
39
|
+
const partialInput = options.outputClientImpl === "grpc-web";
|
|
40
40
|
const inputType = (0, types_1.requestType)(ctx, methodDesc, partialInput);
|
|
41
41
|
params.push((0, ts_poet_1.code) `request: ${inputType}`);
|
|
42
42
|
// Use metadata as last argument for interface only configuration
|
|
43
|
-
if (options.outputClientImpl ===
|
|
43
|
+
if (options.outputClientImpl === "grpc-web") {
|
|
44
44
|
// We have to use grpc.Metadata where grpc will come from @improbable-eng
|
|
45
45
|
params.push((0, ts_poet_1.code) `metadata?: grpc.Metadata`);
|
|
46
46
|
}
|
|
47
47
|
else if (options.addGrpcMetadata) {
|
|
48
|
-
const Metadata = (0, ts_poet_1.imp)(
|
|
49
|
-
const q = options.addNestjsRestParameter ?
|
|
48
|
+
const Metadata = (0, ts_poet_1.imp)("Metadata@@grpc/grpc-js");
|
|
49
|
+
const q = options.addNestjsRestParameter ? "" : "?";
|
|
50
50
|
params.push((0, ts_poet_1.code) `metadata${q}: ${Metadata}`);
|
|
51
51
|
}
|
|
52
52
|
else if (options.metadataType) {
|
|
@@ -56,7 +56,7 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
56
56
|
if (options.addNestjsRestParameter) {
|
|
57
57
|
params.push((0, ts_poet_1.code) `...rest: any`);
|
|
58
58
|
}
|
|
59
|
-
chunks.push((0, ts_poet_1.code) `${methodDesc.formattedName}(${(0, ts_poet_1.joinCode)(params, { on:
|
|
59
|
+
chunks.push((0, ts_poet_1.code) `${methodDesc.formattedName}(${(0, ts_poet_1.joinCode)(params, { on: "," })}): ${(0, types_1.responsePromiseOrObservable)(ctx, methodDesc)};`);
|
|
60
60
|
// If this is a batch method, auto-generate the singular version of it
|
|
61
61
|
if (options.context) {
|
|
62
62
|
const batchMethod = (0, types_1.detectBatchMethod)(ctx, fileDesc, serviceDesc, methodDesc);
|
|
@@ -69,22 +69,22 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
72
|
-
return (0, ts_poet_1.joinCode)(chunks, { on:
|
|
72
|
+
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
73
73
|
}
|
|
74
74
|
exports.generateService = generateService;
|
|
75
75
|
function generateRegularRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
76
76
|
(0, utils_1.assertInstanceOf)(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
77
77
|
const { options, utils } = ctx;
|
|
78
|
-
const Reader = (0, utils_1.impFile)(ctx.options,
|
|
78
|
+
const Reader = (0, utils_1.impFile)(ctx.options, "Reader@protobufjs/minimal");
|
|
79
79
|
const rawInputType = (0, types_1.rawRequestType)(ctx, methodDesc);
|
|
80
80
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
81
81
|
const outputType = (0, types_1.responseType)(ctx, methodDesc);
|
|
82
82
|
const rawOutputType = (0, types_1.responseType)(ctx, methodDesc, { keepValueType: true });
|
|
83
83
|
const params = [...(options.context ? [(0, ts_poet_1.code) `ctx: Context`] : []), (0, ts_poet_1.code) `request: ${inputType}`];
|
|
84
|
-
const maybeCtx = options.context ?
|
|
84
|
+
const maybeCtx = options.context ? "ctx," : "";
|
|
85
85
|
let encode = (0, ts_poet_1.code) `${rawInputType}.encode(request).finish()`;
|
|
86
86
|
let decode = (0, ts_poet_1.code) `data => ${outputType}.decode(new ${Reader}(data))`;
|
|
87
|
-
if (options.useDate && rawOutputType.toString().includes(
|
|
87
|
+
if (options.useDate && rawOutputType.toString().includes("Timestamp")) {
|
|
88
88
|
decode = (0, ts_poet_1.code) `data => ${utils.fromTimestamp}(${rawOutputType}.decode(new ${Reader}(data)))`;
|
|
89
89
|
}
|
|
90
90
|
if (methodDesc.clientStreaming) {
|
|
@@ -92,39 +92,39 @@ function generateRegularRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
92
92
|
encode = (0, ts_poet_1.code) `${rawInputType}.encodeTransform(request)`;
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
|
-
encode = (0, ts_poet_1.code) `request.pipe(${(0, ts_poet_1.imp)(
|
|
95
|
+
encode = (0, ts_poet_1.code) `request.pipe(${(0, ts_poet_1.imp)("map@rxjs/operators")}(request => ${encode}))`;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
let returnVariable;
|
|
99
99
|
if (options.returnObservable || methodDesc.serverStreaming) {
|
|
100
|
-
returnVariable =
|
|
100
|
+
returnVariable = "result";
|
|
101
101
|
if (options.useAsyncIterable) {
|
|
102
102
|
decode = (0, ts_poet_1.code) `${rawOutputType}.decodeTransform(result)`;
|
|
103
103
|
}
|
|
104
104
|
else {
|
|
105
|
-
decode = (0, ts_poet_1.code) `result.pipe(${(0, ts_poet_1.imp)(
|
|
105
|
+
decode = (0, ts_poet_1.code) `result.pipe(${(0, ts_poet_1.imp)("map@rxjs/operators")}(${decode}))`;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
returnVariable =
|
|
109
|
+
returnVariable = "promise";
|
|
110
110
|
decode = (0, ts_poet_1.code) `promise.then(${decode})`;
|
|
111
111
|
}
|
|
112
112
|
let rpcMethod;
|
|
113
113
|
if (methodDesc.clientStreaming && methodDesc.serverStreaming) {
|
|
114
|
-
rpcMethod =
|
|
114
|
+
rpcMethod = "bidirectionalStreamingRequest";
|
|
115
115
|
}
|
|
116
116
|
else if (methodDesc.serverStreaming) {
|
|
117
|
-
rpcMethod =
|
|
117
|
+
rpcMethod = "serverStreamingRequest";
|
|
118
118
|
}
|
|
119
119
|
else if (methodDesc.clientStreaming) {
|
|
120
|
-
rpcMethod =
|
|
120
|
+
rpcMethod = "clientStreamingRequest";
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
-
rpcMethod =
|
|
123
|
+
rpcMethod = "request";
|
|
124
124
|
}
|
|
125
125
|
return (0, ts_poet_1.code) `
|
|
126
126
|
${methodDesc.formattedName}(
|
|
127
|
-
${(0, ts_poet_1.joinCode)(params, { on:
|
|
127
|
+
${(0, ts_poet_1.joinCode)(params, { on: "," })}
|
|
128
128
|
): ${(0, types_1.responsePromiseOrObservable)(ctx, methodDesc)} {
|
|
129
129
|
const data = ${encode};
|
|
130
130
|
const ${returnVariable} = this.rpc.${rpcMethod}(
|
|
@@ -143,10 +143,10 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
|
|
|
143
143
|
// Define the FooServiceImpl class
|
|
144
144
|
const { name } = serviceDesc;
|
|
145
145
|
const i = options.context ? `${name}<Context>` : name;
|
|
146
|
-
const t = options.context ? `<${main_1.contextTypeVar}>` :
|
|
146
|
+
const t = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
147
147
|
chunks.push((0, ts_poet_1.code) `export class ${name}ClientImpl${t} implements ${(0, ts_poet_1.def)(i)} {`);
|
|
148
148
|
// Create the constructor(rpc: Rpc)
|
|
149
|
-
const rpcType = options.context ?
|
|
149
|
+
const rpcType = options.context ? "Rpc<Context>" : "Rpc";
|
|
150
150
|
chunks.push((0, ts_poet_1.code) `private readonly rpc: ${rpcType};`);
|
|
151
151
|
chunks.push((0, ts_poet_1.code) `constructor(rpc: ${rpcType}) {`);
|
|
152
152
|
chunks.push((0, ts_poet_1.code) `this.rpc = rpc;`);
|
|
@@ -222,7 +222,7 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
222
222
|
const inputType = (0, types_1.requestType)(ctx, methodDesc);
|
|
223
223
|
const outputType = (0, types_1.responseType)(ctx, methodDesc);
|
|
224
224
|
const uniqueIdentifier = `${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}.${methodDesc.name}`;
|
|
225
|
-
const Reader = (0, utils_1.impFile)(ctx.options,
|
|
225
|
+
const Reader = (0, utils_1.impFile)(ctx.options, "Reader@protobufjs/minimal");
|
|
226
226
|
const lambda = (0, ts_poet_1.code) `
|
|
227
227
|
(requests) => {
|
|
228
228
|
const responses = requests.map(async request => {
|
|
@@ -262,8 +262,8 @@ function generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
|
262
262
|
*/
|
|
263
263
|
function generateRpcType(ctx, hasStreamingMethods) {
|
|
264
264
|
const { options } = ctx;
|
|
265
|
-
const maybeContext = options.context ?
|
|
266
|
-
const maybeContextParam = options.context ?
|
|
265
|
+
const maybeContext = options.context ? "<Context>" : "";
|
|
266
|
+
const maybeContextParam = options.context ? "ctx: Context," : "";
|
|
267
267
|
const methods = [[(0, ts_poet_1.code) `request`, (0, ts_poet_1.code) `Uint8Array`, (0, ts_poet_1.code) `Promise<Uint8Array>`]];
|
|
268
268
|
if (hasStreamingMethods) {
|
|
269
269
|
const observable = (0, types_1.observableType)(ctx);
|
|
@@ -287,7 +287,7 @@ function generateRpcType(ctx, hasStreamingMethods) {
|
|
|
287
287
|
): ${method[2]};`);
|
|
288
288
|
});
|
|
289
289
|
chunks.push((0, ts_poet_1.code) ` }`);
|
|
290
|
-
return (0, ts_poet_1.joinCode)(chunks, { on:
|
|
290
|
+
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
291
291
|
}
|
|
292
292
|
exports.generateRpcType = generateRpcType;
|
|
293
293
|
function generateDataLoadersType() {
|
|
@@ -13,7 +13,7 @@ function generateTypeRegistry(ctx) {
|
|
|
13
13
|
export const messageTypeRegistry = new Map<string, MessageType>();
|
|
14
14
|
`);
|
|
15
15
|
chunks.push((0, ts_poet_1.code) ` ${ctx.utils.Builtin.ifUsed} ${ctx.utils.DeepPartial.ifUsed}`);
|
|
16
|
-
return (0, ts_poet_1.joinCode)(chunks, { on:
|
|
16
|
+
return (0, ts_poet_1.joinCode)(chunks, { on: "\n\n" });
|
|
17
17
|
}
|
|
18
18
|
exports.generateTypeRegistry = generateTypeRegistry;
|
|
19
19
|
function generateMessageType(ctx) {
|
|
@@ -21,8 +21,8 @@ function generateMessageType(ctx) {
|
|
|
21
21
|
chunks.push((0, ts_poet_1.code) `export interface MessageType<Message extends UnknownMessage = UnknownMessage> {`);
|
|
22
22
|
chunks.push((0, ts_poet_1.code) `$type: Message['$type'];`);
|
|
23
23
|
if (ctx.options.outputEncodeMethods) {
|
|
24
|
-
const Writer = (0, utils_1.impFile)(ctx.options,
|
|
25
|
-
const Reader = (0, utils_1.impFile)(ctx.options,
|
|
24
|
+
const Writer = (0, utils_1.impFile)(ctx.options, "Writer@protobufjs/minimal");
|
|
25
|
+
const Reader = (0, utils_1.impFile)(ctx.options, "Reader@protobufjs/minimal");
|
|
26
26
|
chunks.push((0, ts_poet_1.code) `encode(message: Message, writer?: ${Writer}): ${Writer};`);
|
|
27
27
|
chunks.push((0, ts_poet_1.code) `decode(input: ${Reader} | Uint8Array, length?: number): Message;`);
|
|
28
28
|
}
|
|
@@ -34,5 +34,5 @@ function generateMessageType(ctx) {
|
|
|
34
34
|
chunks.push((0, ts_poet_1.code) `fromPartial(object: ${ctx.utils.DeepPartial}<Message>): Message;`);
|
|
35
35
|
}
|
|
36
36
|
chunks.push((0, ts_poet_1.code) `}`);
|
|
37
|
-
return (0, ts_poet_1.joinCode)(chunks, { on:
|
|
37
|
+
return (0, ts_poet_1.joinCode)(chunks, { on: "\n" });
|
|
38
38
|
}
|