ts-proto 2.17.0 → 2.18.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
@@ -372,6 +372,8 @@ Generated code will be placed in the Gradle build directory.
372
372
 
373
373
  - With `--ts_proto_opt=exportCommonSymbols=false`, utility types like `DeepPartial` and `protobufPackage` won't be `export`d.
374
374
 
375
+ Each generated file also exports `protobufFileName`, the path of the `.proto` file it was generated from (for example `export const protobufFileName = "company/foo.proto";`), next to `protobufPackage`; neither is exported with `exportCommonSymbols=false`.
376
+
375
377
  This should make it possible to use create barrel imports of the generated output, i.e. `import * from ./foo` and `import * from ./bar`.
376
378
 
377
379
  Note that if you have the same message name used in multiple `*.proto` files, you will still get import conflicts.
package/build/src/main.js CHANGED
@@ -49,6 +49,8 @@ function generateFile(ctx, fileDesc) {
49
49
  // Indicate this file's source protobuf package for reflective use with google.protobuf.Any
50
50
  if (options.exportCommonSymbols) {
51
51
  chunks.push((0, ts_poet_1.code) `export const protobufPackage = '${fileDesc.package}';`);
52
+ // The source .proto path, e.g. for NestJS's `protoPath` or @grpc/proto-loader
53
+ chunks.push((0, ts_poet_1.code) `export const protobufFileName = '${fileDesc.name}';`);
52
54
  }
53
55
  // Syntax, unlike most fields, is not repeated and thus does not use an index
54
56
  const sourceInfo = sourceInfo_1.default.fromDescriptor(fileDesc);
@@ -521,10 +523,10 @@ function makeDeepPartial(options, longs) {
521
523
  const maybeExcludeType = (0, options_1.addTypeToMessages)(options) ? `| '$type'` : "";
522
524
  const Exact = (0, ts_poet_1.conditionalOutput)("Exact", (0, ts_poet_1.code) `
523
525
  type KeysOfUnion<T> = T extends T ? keyof T : never;
524
- ${maybeExport} type Exact<P, I extends P> = ${maybeUnknownP}P extends ${Builtin}
526
+ ${maybeExport} type Exact<P, I> = ${maybeUnknownP}P extends ${Builtin}
525
527
  ? P
526
528
  : P &
527
- { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
529
+ { [K in keyof P as Extract<K, keyof I>]: Exact<P[K], I[K & keyof I]> } & { [K in Exclude<keyof I, KeysOfUnion<P> ${maybeExcludeType}>]: never };
528
530
  `);
529
531
  // Based on the type from ts-essentials
530
532
  const keys = (0, options_1.addTypeToMessages)(options) ? (0, ts_poet_1.code) `Exclude<keyof T, '$type'>` : (0, ts_poet_1.code) `keyof T`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",