ts-proto 1.147.3 → 1.148.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/README.markdown CHANGED
@@ -509,6 +509,10 @@ Generated code will be placed in the Gradle build directory.
509
509
  Extension encode/decode methods are compliant with the `outputEncodeMethods` option, and if `unknownFields=true`,
510
510
  the `setExtension` and `getExtension` methods will be created for extendable messages, also compliant with `outputEncodeMethods` (setExtension = encode, getExtension = decode).
511
511
 
512
+ - With `--ts_proto_opt=outputIndex=true`, index files will be generated based on the proto package namespaces.
513
+
514
+ This will disable `exportCommonSymbols` to avoid name collisions on the common symbols.
515
+
512
516
  ### NestJS Support
513
517
 
514
518
  We have a great way of working together with [nestjs](https://docs.nestjs.com/microservices/grpc). `ts-proto` generates `interfaces` and `decorators` for you controller, client. For more information see the [nestjs readme](NESTJS.markdown).
@@ -347,7 +347,10 @@ function createInvokeMethod(ctx) {
347
347
  },
348
348
  });
349
349
  observer.add(() => {
350
- if (!observer.closed) return client.close()
350
+ ${!useAbortSignal
351
+ ? `return client.close();`
352
+ : `if (!abortSignal || !abortSignal.aborted)
353
+ return client.close();`}
351
354
  });
352
355
 
353
356
  ${maybeAbortSignal}
package/build/options.js CHANGED
@@ -80,6 +80,7 @@ function defaultOptions() {
80
80
  useReadonlyTypes: false,
81
81
  useSnakeTypeName: true,
82
82
  outputExtensions: false,
83
+ outputIndex: false,
83
84
  M: {},
84
85
  };
85
86
  }
@@ -160,6 +161,9 @@ function optionsFromParameter(parameter) {
160
161
  if (options.nestJs) {
161
162
  options.initializeFieldsAsUndefined = false;
162
163
  }
164
+ if (options.outputIndex) {
165
+ options.exportCommonSymbols = false;
166
+ }
163
167
  return options;
164
168
  }
165
169
  exports.optionsFromParameter = optionsFromParameter;
package/build/plugin.js CHANGED
@@ -33,6 +33,12 @@ async function main() {
33
33
  const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
34
34
  files.push({ name: path, content });
35
35
  }
36
+ if (options.outputIndex) {
37
+ for (const [path, code] of (0, utils_1.generateIndexFiles)(filesToGenerate, options)) {
38
+ const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
39
+ files.push({ name: path, content });
40
+ }
41
+ }
36
42
  const response = ts_proto_descriptors_1.CodeGeneratorResponse.fromPartial({
37
43
  file: files,
38
44
  supportedFeatures: ts_proto_descriptors_1.CodeGeneratorResponse_Feature.FEATURE_PROTO3_OPTIONAL,
package/build/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.protoFilesToGenerate = void 0;
3
+ exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.prefixDisableLinter = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0;
4
+ const path = require("path");
4
5
  const ts_poet_1 = require("ts-poet");
5
6
  const options_1 = require("./options");
6
7
  const case_1 = require("./case");
@@ -8,6 +9,40 @@ function protoFilesToGenerate(request) {
8
9
  return request.protoFile.filter((f) => request.fileToGenerate.includes(f.name));
9
10
  }
10
11
  exports.protoFilesToGenerate = protoFilesToGenerate;
12
+ function generateIndexFiles(files, options) {
13
+ const packageTree = {
14
+ index: "index.ts",
15
+ leaves: {},
16
+ chunks: [],
17
+ };
18
+ for (const { name, package: pkg } of files) {
19
+ const moduleName = name.replace(".proto", options.fileSuffix);
20
+ const pkgParts = pkg.length > 0 ? pkg.split(".") : [];
21
+ const branch = pkgParts.reduce((branch, part, i) => {
22
+ if (!(part in branch.leaves)) {
23
+ const prePkgParts = pkgParts.slice(0, i + 1);
24
+ const index = `index.${prePkgParts.join(".")}.ts`;
25
+ branch.chunks.push((0, ts_poet_1.code) `export * as ${part} from "./${path.basename(index, ".ts")}";`);
26
+ branch.leaves[part] = {
27
+ index,
28
+ leaves: {},
29
+ chunks: [],
30
+ };
31
+ }
32
+ return branch.leaves[part];
33
+ }, packageTree);
34
+ branch.chunks.push((0, ts_poet_1.code) `export * from "./${moduleName}";`);
35
+ }
36
+ const indexFiles = [];
37
+ let branches = [packageTree];
38
+ let currentBranch;
39
+ while ((currentBranch = branches.pop())) {
40
+ indexFiles.push([currentBranch.index, (0, ts_poet_1.joinCode)(currentBranch.chunks)]);
41
+ branches.push(...Object.values(currentBranch.leaves));
42
+ }
43
+ return indexFiles;
44
+ }
45
+ exports.generateIndexFiles = generateIndexFiles;
11
46
  function readToBuffer(stream) {
12
47
  return new Promise((resolve) => {
13
48
  const ret = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.147.3",
3
+ "version": "1.148.1",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",