ts-proto 1.149.0 → 1.150.1
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/generate-services.js +7 -3
- package/build/plugin.js +21 -4
- package/package.json +1 -1
|
@@ -146,8 +146,13 @@ function generateRegularRpcMethod(ctx, methodDesc) {
|
|
|
146
146
|
function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
|
|
147
147
|
const { options } = ctx;
|
|
148
148
|
const chunks = [];
|
|
149
|
-
//
|
|
149
|
+
// Determine information about the service.
|
|
150
150
|
const { name } = serviceDesc;
|
|
151
|
+
const serviceName = (0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name);
|
|
152
|
+
// Define the service name constant.
|
|
153
|
+
const serviceNameConst = `${name}ServiceName`;
|
|
154
|
+
chunks.push((0, ts_poet_1.code) `export const ${serviceNameConst} = "${serviceName}";`);
|
|
155
|
+
// Define the FooServiceImpl class
|
|
151
156
|
const i = options.context ? `${name}<Context>` : name;
|
|
152
157
|
const t = options.context ? `<${main_1.contextTypeVar}>` : "";
|
|
153
158
|
chunks.push((0, ts_poet_1.code) `export class ${name}ClientImpl${t} implements ${(0, ts_poet_1.def)(i)} {`);
|
|
@@ -156,8 +161,7 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
|
|
|
156
161
|
chunks.push((0, ts_poet_1.code) `private readonly rpc: ${rpcType};`);
|
|
157
162
|
chunks.push((0, ts_poet_1.code) `private readonly service: string;`);
|
|
158
163
|
chunks.push((0, ts_poet_1.code) `constructor(rpc: ${rpcType}, opts?: {service?: string}) {`);
|
|
159
|
-
|
|
160
|
-
chunks.push((0, ts_poet_1.code) `this.service = opts?.service || "${serviceID}";`);
|
|
164
|
+
chunks.push((0, ts_poet_1.code) `this.service = opts?.service || ${serviceNameConst};`);
|
|
161
165
|
chunks.push((0, ts_poet_1.code) `this.rpc = rpc;`);
|
|
162
166
|
// Bind each FooService method to the FooServiceImpl class
|
|
163
167
|
for (const methodDesc of serviceDesc.method) {
|
package/build/plugin.js
CHANGED
|
@@ -17,10 +17,27 @@ async function main() {
|
|
|
17
17
|
const typeMap = (0, types_1.createTypeMap)(request, options);
|
|
18
18
|
const utils = (0, main_1.makeUtils)(options);
|
|
19
19
|
const ctx = { typeMap, options, utils };
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
let filesToGenerate;
|
|
21
|
+
if (options.emitImportedFiles) {
|
|
22
|
+
const fileSet = new Set();
|
|
23
|
+
const addFilesUnlessAliased = (filenames) => {
|
|
24
|
+
filenames
|
|
25
|
+
.filter((name) => !options.M[name])
|
|
26
|
+
.forEach((name) => {
|
|
27
|
+
fileSet.add(name);
|
|
28
|
+
const file = request.protoFile.find((file) => file.name === name);
|
|
29
|
+
if (file && file.dependency.length > 0) {
|
|
30
|
+
addFilesUnlessAliased(file.dependency);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
addFilesUnlessAliased(request.fileToGenerate);
|
|
35
|
+
filesToGenerate = request.protoFile.filter((file) => fileSet.has(file.name));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
filesToGenerate = (0, utils_1.protoFilesToGenerate)(request).filter((file) => !options.M[file.name]);
|
|
39
|
+
}
|
|
40
|
+
const files = await Promise.all(filesToGenerate.map(async (file) => {
|
|
24
41
|
const [path, code] = (0, main_1.generateFile)(ctx, file);
|
|
25
42
|
const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
|
|
26
43
|
return { name: path, content };
|