ts-proto 1.173.0 → 1.174.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/README.markdown CHANGED
@@ -305,6 +305,8 @@ Generated code will be placed in the Gradle build directory.
305
305
 
306
306
  The default behavior is `forceLong=number`, which will internally still use the `long` library to encode/decode values on the wire (so you will still see a `util.Long = Long` line in your output), but will convert the `long` values to `number` automatically for you. Note that a runtime error is thrown if, while doing this conversion, a 64-bit value is larger than can be correctly stored as a `number`.
307
307
 
308
+ - With `--ts_proto_opt=useJsTypeOverride`, 64-bit numbers will be ouput as the [FieldOption.JSType](https://protobuf.dev/reference/java/api-docs/com/google/protobuf/DescriptorProtos.FieldOptions.JSType) specified on the field. This takes precendence over the `forceLong` option provided.
309
+
308
310
  - With `--ts_proto_opt=esModuleInterop=true` changes output to be `esModuleInterop` compliant.
309
311
 
310
312
  Specifically the `Long` imports will be generated as `import Long from 'long'` instead of `import * as Long from 'long'`.
@@ -98,5 +98,5 @@ export type Options = {
98
98
  };
99
99
  export declare function defaultOptions(): Options;
100
100
  export declare function optionsFromParameter(parameter: string | undefined): Options;
101
- export declare function getTsPoetOpts(options: Options): ToStringOpts;
101
+ export declare function getTsPoetOpts(options: Options, tsProtoVersion: string, protocVersion: string, fileName?: string): ToStringOpts;
102
102
  export declare function addTypeToMessages(options: Options): boolean;
package/build/options.js CHANGED
@@ -245,11 +245,20 @@ function parseParameter(parameter) {
245
245
  function parseParamValue(value) {
246
246
  return value === "true" ? true : value === "false" ? false : value;
247
247
  }
248
- function getTsPoetOpts(options) {
248
+ function getTsPoetOpts(options, tsProtoVersion, protocVersion, fileName) {
249
249
  const { importSuffix, esModuleInterop } = options;
250
250
  const pbjs = "protobufjs/minimal" + importSuffix;
251
251
  return {
252
- prefix: `/* eslint-disable */`,
252
+ // Comment block at the top of every source file, since these comments require specific
253
+ // syntax incompatible with ts-poet, we will hard-code the string and prepend to the
254
+ // generator output.
255
+ prefix: `// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
256
+ // versions:
257
+ // protoc-gen-ts_proto ${tsProtoVersion}
258
+ // protoc ${protocVersion}
259
+ ${fileName ? `// source: ${fileName}` : ""}
260
+
261
+ /* eslint-disable */`,
253
262
  dprintOptions: { preferSingleLine: true, lineWidth: 120 },
254
263
  forceRequireImport: esModuleInterop ? [] : ["long"],
255
264
  forceDefaultImport: esModuleInterop ? [pbjs] : [],
package/build/plugin.js CHANGED
@@ -14,6 +14,7 @@ async function main() {
14
14
  // const json = JSON.parse(stdin.toString());
15
15
  // const request = CodeGeneratorRequest.fromObject(json);
16
16
  const request = ts_proto_descriptors_1.CodeGeneratorRequest.decode(stdin);
17
+ const { protocVersion, tsProtoVersion } = await (0, utils_1.getVersions)(request);
17
18
  const options = (0, options_1.optionsFromParameter)(request.parameter);
18
19
  const typeMap = (0, types_1.createTypeMap)(request, options);
19
20
  const utils = (0, main_1.makeUtils)(options);
@@ -42,7 +43,7 @@ async function main() {
42
43
  }
43
44
  const files = await Promise.all(filesToGenerate.map(async (file) => {
44
45
  const [path, code] = (0, main_1.generateFile)({ ...ctx, currentFile: (0, context_1.createFileContext)(file) }, file);
45
- const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
46
+ const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options, tsProtoVersion, protocVersion, file.name), path });
46
47
  return { name: path, content };
47
48
  }));
48
49
  if (options.outputTypeRegistry) {
@@ -50,12 +51,12 @@ async function main() {
50
51
  const ctx = { options, typeMap, utils };
51
52
  const path = "typeRegistry.ts";
52
53
  const code = (0, generate_type_registry_1.generateTypeRegistry)(ctx);
53
- const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
54
+ const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options, tsProtoVersion, protocVersion), path });
54
55
  files.push({ name: path, content });
55
56
  }
56
57
  if (options.outputIndex) {
57
58
  for (const [path, code] of (0, utils_1.generateIndexFiles)(filesToGenerate, options)) {
58
- const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options), path });
59
+ const content = code.toString({ ...(0, options_1.getTsPoetOpts)(options, tsProtoVersion, protocVersion), path });
59
60
  files.push({ name: path, content });
60
61
  }
61
62
  }
package/build/utils.d.ts CHANGED
@@ -14,7 +14,6 @@ export declare function lowerFirst(name: string): string;
14
14
  export declare function upperFirst(name: string): string;
15
15
  /** Removes potentially harmful characters from comments and pushes it into chunks. */
16
16
  export declare function maybeAddComment(options: Pick<Options, "comments">, desc: Partial<Pick<SourceDescription, "leadingComments" | "trailingComments">>, chunks: Code[], deprecated?: boolean, prefix?: string): void;
17
- export declare function prefixDisableLinter(spec: string): string;
18
17
  export declare function maybePrefixPackage(fileDesc: FileDescriptorProto, rest: string): string;
19
18
  /**
20
19
  * Asserts that an object is an instance of a certain class
@@ -78,3 +77,7 @@ export declare function withOrMaybeCheckIsNotNull(options: Pick<Options, "useNul
78
77
  export declare function withOrMaybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
79
78
  export declare function withAndMaybeCheckIsNotNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
80
79
  export declare function withAndMaybeCheckIsNull(options: Pick<Options, "useNullAsOptional">, typeName: string): string;
80
+ export declare function getVersions(request: CodeGeneratorRequest): Promise<{
81
+ protocVersion: string;
82
+ tsProtoVersion: string;
83
+ }>;
package/build/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withAndMaybeCheckIsNull = exports.withAndMaybeCheckIsNotNull = exports.withOrMaybeCheckIsNull = exports.withOrMaybeCheckIsNotNull = exports.maybeCheckIsNull = exports.maybeCheckIsNotNull = exports.nullOrUndefined = exports.arrowFunction = exports.tryCatchBlock = exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = 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;
3
+ exports.getVersions = exports.withAndMaybeCheckIsNull = exports.withAndMaybeCheckIsNotNull = exports.withOrMaybeCheckIsNull = exports.withOrMaybeCheckIsNotNull = exports.maybeCheckIsNull = exports.maybeCheckIsNotNull = exports.nullOrUndefined = exports.arrowFunction = exports.tryCatchBlock = exports.impProto = exports.impFile = exports.getPropertyAccessor = exports.safeAccessor = exports.getFieldName = exports.getFieldJsonName = exports.FormattedMethodDescriptor = exports.assertInstanceOf = exports.maybePrefixPackage = exports.maybeAddComment = exports.upperFirst = exports.lowerFirst = exports.singular = exports.fail = exports.readToBuffer = exports.generateIndexFiles = exports.protoFilesToGenerate = void 0;
4
4
  const path = require("path");
5
5
  const ts_poet_1 = require("ts-poet");
6
6
  const options_1 = require("./options");
@@ -116,13 +116,6 @@ function maybeAddComment(options, desc, chunks, deprecated, prefix = "") {
116
116
  }
117
117
  }
118
118
  exports.maybeAddComment = maybeAddComment;
119
- // Comment block at the top of every source file, since these comments require specific
120
- // syntax incompatible with ts-poet, we will hard-code the string and prepend to the
121
- // generator output.
122
- function prefixDisableLinter(spec) {
123
- return `/* eslint-disable */\n${spec}`;
124
- }
125
- exports.prefixDisableLinter = prefixDisableLinter;
126
119
  function maybePrefixPackage(fileDesc, rest) {
127
120
  const prefix = fileDesc.package === "" ? "" : `${fileDesc.package}.`;
128
121
  return `${prefix}${rest}`;
@@ -289,3 +282,19 @@ function withAndMaybeCheckIsNull(options, typeName) {
289
282
  return maybeCheckIsNotNull(options, typeName, "&&");
290
283
  }
291
284
  exports.withAndMaybeCheckIsNull = withAndMaybeCheckIsNull;
285
+ async function getVersions(request) {
286
+ var _a;
287
+ let protocVersion = "unknown";
288
+ if (request.compilerVersion) {
289
+ const { major, minor, patch } = request.compilerVersion;
290
+ protocVersion = `v${major}.${minor}.${patch}`;
291
+ }
292
+ const path = "../package.json";
293
+ const packageJson = await Promise.resolve(`${path}`).then(s => require(s));
294
+ const tsProtoVersion = `v${(_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.version) !== null && _a !== void 0 ? _a : "unknown"}`;
295
+ return {
296
+ protocVersion,
297
+ tsProtoVersion,
298
+ };
299
+ }
300
+ exports.getVersions = getVersions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.173.0",
3
+ "version": "1.174.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",