@bufbuild/protoplugin 1.7.2 → 1.9.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.
Files changed (55) hide show
  1. package/dist/cjs/create-es-plugin.d.ts +1 -1
  2. package/dist/cjs/ecmascript/file-preamble.d.ts +2 -0
  3. package/dist/cjs/ecmascript/file-preamble.js +74 -0
  4. package/dist/cjs/ecmascript/generated-file.d.ts +2 -2
  5. package/dist/cjs/ecmascript/generated-file.js +90 -31
  6. package/dist/cjs/ecmascript/import-path.d.ts +1 -1
  7. package/dist/cjs/ecmascript/index.d.ts +4 -8
  8. package/dist/cjs/ecmascript/index.js +10 -17
  9. package/dist/cjs/ecmascript/jsdoc.d.ts +6 -0
  10. package/dist/cjs/ecmascript/jsdoc.js +1 -0
  11. package/dist/cjs/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +2 -2
  12. package/dist/cjs/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -7
  13. package/dist/cjs/ecmascript/{gencommon.js → legacy-gencommon.js} +50 -98
  14. package/dist/cjs/ecmascript/opaque-printables.d.ts +27 -0
  15. package/dist/{esm/ecmascript/export-declaration.js → cjs/ecmascript/opaque-printables.js} +2 -7
  16. package/dist/cjs/ecmascript/parameter.d.ts +2 -2
  17. package/dist/cjs/ecmascript/schema.d.ts +2 -2
  18. package/dist/cjs/ecmascript/schema.js +2 -2
  19. package/dist/cjs/ecmascript/transpile.js +1 -1
  20. package/dist/cjs/error.d.ts +2 -0
  21. package/dist/cjs/error.js +9 -1
  22. package/dist/cjs/index.d.ts +2 -2
  23. package/dist/cjs/run-node.js +1 -1
  24. package/dist/esm/create-es-plugin.d.ts +1 -1
  25. package/dist/esm/ecmascript/file-preamble.d.ts +2 -0
  26. package/dist/esm/ecmascript/file-preamble.js +70 -0
  27. package/dist/esm/ecmascript/generated-file.d.ts +2 -2
  28. package/dist/esm/ecmascript/generated-file.js +90 -31
  29. package/dist/esm/ecmascript/import-path.d.ts +1 -1
  30. package/dist/esm/ecmascript/index.d.ts +4 -8
  31. package/dist/esm/ecmascript/index.js +3 -10
  32. package/dist/esm/ecmascript/jsdoc.d.ts +6 -0
  33. package/dist/esm/ecmascript/jsdoc.js +1 -0
  34. package/dist/esm/ecmascript/{custom-options.d.ts → legacy-custom-options.d.ts} +2 -2
  35. package/dist/esm/ecmascript/{custom-options.js → legacy-custom-options.js} +1 -1
  36. package/dist/esm/ecmascript/{gencommon.d.ts → legacy-gencommon.d.ts} +12 -7
  37. package/dist/esm/ecmascript/{gencommon.js → legacy-gencommon.js} +49 -95
  38. package/dist/esm/ecmascript/opaque-printables.d.ts +27 -0
  39. package/dist/{cjs/ecmascript/export-declaration.js → esm/ecmascript/opaque-printables.js} +1 -11
  40. package/dist/esm/ecmascript/parameter.d.ts +2 -2
  41. package/dist/esm/ecmascript/schema.d.ts +2 -2
  42. package/dist/esm/ecmascript/schema.js +2 -2
  43. package/dist/esm/ecmascript/transpile.js +1 -1
  44. package/dist/esm/error.d.ts +2 -0
  45. package/dist/esm/error.js +7 -0
  46. package/dist/esm/index.d.ts +2 -2
  47. package/dist/esm/run-node.js +2 -2
  48. package/package.json +5 -16
  49. package/dist/cjs/ecmascript/export-declaration.d.ts +0 -7
  50. package/dist/esm/ecmascript/export-declaration.d.ts +0 -7
  51. package/dist/proxy/ecmascript/index.d.ts +0 -1
  52. package/dist/proxy/ecmascript/index.js +0 -1
  53. package/dist/proxy/index.d.ts +0 -1
  54. package/dist/proxy/index.js +0 -1
  55. /package/dist/cjs/ecmascript/{custom-options.js → legacy-custom-options.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { Schema } from "./ecmascript/schema.js";
1
+ import type { Schema } from "./ecmascript/schema.js";
2
2
  import type { FileInfo } from "./ecmascript/generated-file.js";
3
3
  import type { Plugin } from "./plugin.js";
4
4
  import type { FeatureSetDefaults } from "@bufbuild/protobuf";
@@ -0,0 +1,2 @@
1
+ import type { DescFile } from "@bufbuild/protobuf";
2
+ export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.makeFilePreamble = void 0;
17
+ const protobuf_1 = require("@bufbuild/protobuf");
18
+ function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
19
+ const builder = [];
20
+ const trimSuffix = (str, suffix) => str.endsWith(suffix) ? str.substring(0, str.length - suffix.length) : str;
21
+ const writeLeadingComments = (comments) => {
22
+ for (let comment of comments.leadingDetached) {
23
+ comment = trimSuffix(comment, "\n");
24
+ for (const line of comment.split("\n")) {
25
+ builder.push(`//${line}\n`);
26
+ }
27
+ builder.push("\n");
28
+ }
29
+ if (comments.leading !== undefined) {
30
+ const comment = trimSuffix(comments.leading, "\n");
31
+ for (const line of comment.split("\n")) {
32
+ builder.push(`//${line}\n`);
33
+ }
34
+ builder.push("\n");
35
+ }
36
+ };
37
+ writeLeadingComments(file.getSyntaxComments());
38
+ builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
39
+ if (parameter !== "") {
40
+ builder.push(` with parameter "${parameter}"`);
41
+ }
42
+ builder.push("\n");
43
+ builder.push(`// @generated from file ${file.name}.proto (`);
44
+ if (file.proto.package !== undefined) {
45
+ builder.push(`package ${file.proto.package}, `);
46
+ }
47
+ switch (file.edition) {
48
+ case protobuf_1.Edition.EDITION_PROTO2:
49
+ builder.push(`syntax proto2)\n`);
50
+ break;
51
+ case protobuf_1.Edition.EDITION_PROTO3:
52
+ builder.push(`syntax proto3)\n`);
53
+ break;
54
+ default: {
55
+ const editionString = protobuf_1.Edition[file.edition];
56
+ if (typeof editionString == "string") {
57
+ const e = editionString.replace("EDITION_", "").toLowerCase();
58
+ builder.push(`edition ${e})\n`);
59
+ }
60
+ else {
61
+ builder.push(`unknown edition\n`);
62
+ }
63
+ break;
64
+ }
65
+ }
66
+ builder.push("/* eslint-disable */\n");
67
+ if (tsNoCheck) {
68
+ builder.push("// @ts-nocheck\n");
69
+ }
70
+ builder.push("\n");
71
+ writeLeadingComments(file.getPackageComments());
72
+ return trimSuffix(builder.join(""), "\n");
73
+ }
74
+ exports.makeFilePreamble = makeFilePreamble;
@@ -1,12 +1,12 @@
1
1
  import type { AnyDesc, DescEnum, DescExtension, DescFile, DescMessage } from "@bufbuild/protobuf";
2
2
  import type { ImportSymbol } from "./import-symbol.js";
3
3
  import type { RuntimeImports } from "./runtime-imports.js";
4
- import type { ExportDeclaration } from "./export-declaration.js";
5
4
  import type { JSDocBlock } from "./jsdoc.js";
5
+ import type { ExportDeclaration, LiteralProtoInt64, LiteralString, RefDescEnum, RefDescMessage } from "./opaque-printables.js";
6
6
  /**
7
7
  * All types that can be passed to GeneratedFile.print()
8
8
  */
9
- export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | DescMessage | DescEnum | DescExtension | Printable[];
9
+ export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | LiteralString | LiteralProtoInt64 | RefDescMessage | RefDescEnum | DescMessage | DescEnum | DescExtension | Printable[];
10
10
  /**
11
11
  * FileInfo represents an intermediate type using for transpiling TypeScript internally.
12
12
  */
@@ -14,10 +14,9 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.createGeneratedFile = void 0;
17
+ const protobuf_1 = require("@bufbuild/protobuf");
17
18
  const import_symbol_js_1 = require("./import-symbol.js");
18
- const gencommon_js_1 = require("./gencommon.js");
19
19
  const import_path_js_1 = require("./import-path.js");
20
- const export_declaration_js_1 = require("./export-declaration.js");
21
20
  const jsdoc_js_1 = require("./jsdoc.js");
22
21
  function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
23
22
  let preamble;
@@ -47,10 +46,15 @@ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath,
47
46
  return (0, import_symbol_js_1.createImportSymbol)(name, importPath);
48
47
  },
49
48
  exportDecl(declaration, name) {
50
- return (0, export_declaration_js_1.createExportDeclaration)(declaration, name);
49
+ return {
50
+ kind: "es_export_decl",
51
+ declaration,
52
+ name,
53
+ };
51
54
  },
52
55
  string(string) {
53
- return (0, gencommon_js_1.literalString)(string);
56
+ // We do not use LiteralString, which was added later, to maintain backwards compatibility
57
+ return escapeString(string);
54
58
  },
55
59
  jsDoc(textOrDesc, indentation) {
56
60
  return (0, jsdoc_js_1.createJsDocBlock)(textOrDesc, indentation);
@@ -87,16 +91,16 @@ function elToContent(el, importerPath, rewriteImportPath, legacyCommonJs) {
87
91
  if (legacyCommonJs) {
88
92
  const p = names.map(({ name, alias }) => alias == undefined ? name : `${name}: ${alias}`);
89
93
  const what = `{ ${p.join(", ")} }`;
90
- c.push(`const ${what} = require(${(0, gencommon_js_1.literalString)(from)});\n`);
94
+ c.push(`const ${what} = require(${escapeString(from)});\n`);
91
95
  }
92
96
  else {
93
97
  const p = names.map(({ name, alias }) => alias == undefined ? name : `${name} as ${alias}`);
94
98
  const what = `{ ${p.join(", ")} }`;
95
99
  if (typeOnly) {
96
- c.push(`import type ${what} from ${(0, gencommon_js_1.literalString)(from)};\n`);
100
+ c.push(`import type ${what} from ${escapeString(from)};\n`);
97
101
  }
98
102
  else {
99
- c.push(`import ${what} from ${(0, gencommon_js_1.literalString)(from)};\n`);
103
+ c.push(`import ${what} from ${escapeString(from)};\n`);
100
104
  }
101
105
  }
102
106
  });
@@ -153,17 +157,17 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
153
157
  el.push(p);
154
158
  break;
155
159
  case "number":
156
- el.push(...literalNumber(p, runtimeImports));
160
+ elNumber(el, p, runtimeImports);
157
161
  break;
158
162
  case "boolean":
159
163
  el.push(p.toString());
160
164
  break;
161
165
  case "bigint":
162
- el.push(...literalBigint(p, runtimeImports));
166
+ elBigint(el, p, runtimeImports);
163
167
  break;
164
168
  case "object":
165
169
  if (p instanceof Uint8Array) {
166
- el.push(literalUint8Array(p));
170
+ elUint8Array(el, p);
167
171
  break;
168
172
  }
169
173
  switch (p.kind) {
@@ -173,6 +177,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
173
177
  case "es_jsdoc":
174
178
  el.push(p.toString());
175
179
  break;
180
+ case "es_string":
181
+ el.push(escapeString(p.value));
182
+ break;
183
+ case "es_proto_int64":
184
+ elProtoInt64(el, p, runtimeImports);
185
+ break;
176
186
  case "es_export_decl":
177
187
  el.push({
178
188
  kind: "es_export_stmt",
@@ -182,6 +192,12 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
182
192
  : createTypeImport(p.name).name,
183
193
  });
184
194
  break;
195
+ case "es_ref_message":
196
+ case "es_ref_enum":
197
+ el.push(p.typeOnly
198
+ ? createTypeImport(p.type).toTypeOnly()
199
+ : createTypeImport(p.type));
200
+ break;
185
201
  case "message":
186
202
  case "extension":
187
203
  case "enum":
@@ -311,37 +327,80 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
311
327
  }
312
328
  return symbolToIdentifier;
313
329
  }
314
- function literalNumber(value, runtimeImports) {
330
+ function elBigint(el, value, runtimeImports) {
331
+ if (value == protobuf_1.protoInt64.zero) {
332
+ // Loose comparison will match between 0n and 0.
333
+ el.push(runtimeImports.protoInt64, ".zero");
334
+ }
335
+ else {
336
+ el.push(runtimeImports.protoInt64, value > 0 ? ".uParse(" : ".parse(", escapeString(value.toString()), ")");
337
+ }
338
+ }
339
+ function elNumber(el, value, runtimeImports) {
315
340
  if (Number.isNaN(value)) {
316
- return [runtimeImports.protoDouble, ".NaN"];
341
+ el.push(runtimeImports.protoDouble, ".NaN");
317
342
  }
318
- if (value === Number.POSITIVE_INFINITY) {
319
- return [runtimeImports.protoDouble, ".POSITIVE_INFINITY"];
343
+ else if (value === Number.POSITIVE_INFINITY) {
344
+ el.push(runtimeImports.protoDouble, ".POSITIVE_INFINITY");
320
345
  }
321
- if (value === Number.NEGATIVE_INFINITY) {
322
- return [runtimeImports.protoDouble, ".NEGATIVE_INFINITY"];
346
+ else if (value === Number.NEGATIVE_INFINITY) {
347
+ el.push(runtimeImports.protoDouble, ".NEGATIVE_INFINITY");
323
348
  }
324
- return value.toString(10);
325
- }
326
- function literalBigint(value, runtimeImports) {
327
- // Loose comparison will match between 0n and 0.
328
- if (value == 0) {
329
- return [runtimeImports.protoInt64, ".zero"];
349
+ else {
350
+ el.push(value.toString(10));
330
351
  }
331
- return [
332
- runtimeImports.protoInt64,
333
- value > 0 ? ".uParse(" : ".parse(",
334
- (0, gencommon_js_1.literalString)(value.toString()),
335
- ")",
336
- ];
337
352
  }
338
- function literalUint8Array(value) {
353
+ function elUint8Array(el, value) {
339
354
  if (value.length === 0) {
340
- return "new Uint8Array(0)";
355
+ el.push("new Uint8Array(0)");
356
+ return;
341
357
  }
358
+ el.push("new Uint8Array([");
342
359
  const strings = [];
343
360
  for (const n of value) {
344
361
  strings.push("0x" + n.toString(16).toUpperCase().padStart(2, "0"));
345
362
  }
346
- return `new Uint8Array([${strings.join(", ")}])`;
363
+ el.push(strings.join(", "));
364
+ el.push("])");
365
+ }
366
+ function elProtoInt64(el, literal, runtimeImports) {
367
+ switch (literal.longType) {
368
+ case protobuf_1.LongType.STRING:
369
+ el.push(escapeString(literal.value.toString()));
370
+ break;
371
+ case protobuf_1.LongType.BIGINT:
372
+ if (literal.value == protobuf_1.protoInt64.zero) {
373
+ // Loose comparison will match between 0n and 0.
374
+ el.push(runtimeImports.protoInt64, ".zero");
375
+ break;
376
+ }
377
+ switch (literal.type) {
378
+ case protobuf_1.ScalarType.UINT64:
379
+ case protobuf_1.ScalarType.FIXED64:
380
+ el.push(runtimeImports.protoInt64);
381
+ el.push(".uParse(");
382
+ el.push(escapeString(literal.value.toString()));
383
+ el.push(")");
384
+ break;
385
+ default:
386
+ el.push(runtimeImports.protoInt64);
387
+ el.push(".parse(");
388
+ el.push(escapeString(literal.value.toString()));
389
+ el.push(")");
390
+ break;
391
+ }
392
+ }
393
+ }
394
+ function escapeString(value) {
395
+ return ('"' +
396
+ value
397
+ .split("\\")
398
+ .join("\\\\")
399
+ .split('"')
400
+ .join('\\"')
401
+ .split("\r")
402
+ .join("\\r")
403
+ .split("\n")
404
+ .join("\\n") +
405
+ '"');
347
406
  }
@@ -1,4 +1,4 @@
1
- import { DescFile } from "@bufbuild/protobuf";
1
+ import type { DescFile } from "@bufbuild/protobuf";
2
2
  /**
3
3
  * A configuration for rewriting import paths, a feature mainly used for
4
4
  * remote code generation in the BSR npm registry, which makes it possible
@@ -1,5 +1,5 @@
1
- import { AnyDesc, DescExtension, DescFile } from "@bufbuild/protobuf";
2
- import { Printable } from "./generated-file.js";
1
+ import type { AnyDesc, DescExtension, DescFile } from "@bufbuild/protobuf";
2
+ import type { Printable } from "./generated-file.js";
3
3
  export { reifyWkt } from "./reify-wkt.js";
4
4
  export type { Target } from "./target.js";
5
5
  export type { Schema } from "./schema.js";
@@ -8,12 +8,8 @@ export type { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
8
8
  export type { ImportSymbol } from "./import-symbol.js";
9
9
  export { createImportSymbol } from "./import-symbol.js";
10
10
  export declare const localName: (desc: import("@bufbuild/protobuf").DescEnum | import("@bufbuild/protobuf").DescMessage | import("@bufbuild/protobuf").DescService | DescExtension | import("@bufbuild/protobuf").DescEnumValue | import("@bufbuild/protobuf").DescField | import("@bufbuild/protobuf").DescOneof | import("@bufbuild/protobuf").DescMethod) => string;
11
- export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, } from "./gencommon.js";
12
- export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
13
- /**
14
- * @deprecated Please use GeneratedFile.string() instead
15
- */
16
- export declare function literalString(value: string): string;
11
+ export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, literalString, } from "./legacy-gencommon.js";
12
+ export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./legacy-custom-options.js";
17
13
  /**
18
14
  * @deprecated Please use GeneratedFile.jsDoc() instead
19
15
  */
@@ -13,30 +13,23 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createJsDocBlock = exports.makeJsDoc = exports.literalString = exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.localName = exports.createImportSymbol = exports.reifyWkt = void 0;
16
+ exports.createJsDocBlock = exports.makeJsDoc = exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.literalString = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.localName = exports.createImportSymbol = exports.reifyWkt = void 0;
17
17
  const protobuf_1 = require("@bufbuild/protobuf");
18
18
  const jsdoc_js_1 = require("./jsdoc.js");
19
- const gencommon_js_1 = require("./gencommon.js");
20
19
  var reify_wkt_js_1 = require("./reify-wkt.js");
21
20
  Object.defineProperty(exports, "reifyWkt", { enumerable: true, get: function () { return reify_wkt_js_1.reifyWkt; } });
22
21
  var import_symbol_js_1 = require("./import-symbol.js");
23
22
  Object.defineProperty(exports, "createImportSymbol", { enumerable: true, get: function () { return import_symbol_js_1.createImportSymbol; } });
24
23
  exports.localName = protobuf_1.codegenInfo.localName;
25
- var gencommon_js_2 = require("./gencommon.js");
26
- Object.defineProperty(exports, "getFieldExplicitDefaultValue", { enumerable: true, get: function () { return gencommon_js_2.getFieldExplicitDefaultValue; } });
27
- Object.defineProperty(exports, "getFieldIntrinsicDefaultValue", { enumerable: true, get: function () { return gencommon_js_2.getFieldIntrinsicDefaultValue; } });
28
- Object.defineProperty(exports, "getFieldTyping", { enumerable: true, get: function () { return gencommon_js_2.getFieldTyping; } });
29
- var custom_options_js_1 = require("./custom-options.js");
30
- Object.defineProperty(exports, "findCustomScalarOption", { enumerable: true, get: function () { return custom_options_js_1.findCustomScalarOption; } });
31
- Object.defineProperty(exports, "findCustomMessageOption", { enumerable: true, get: function () { return custom_options_js_1.findCustomMessageOption; } });
32
- Object.defineProperty(exports, "findCustomEnumOption", { enumerable: true, get: function () { return custom_options_js_1.findCustomEnumOption; } });
33
- /**
34
- * @deprecated Please use GeneratedFile.string() instead
35
- */
36
- function literalString(value) {
37
- return (0, gencommon_js_1.literalString)(value);
38
- }
39
- exports.literalString = literalString;
24
+ var legacy_gencommon_js_1 = require("./legacy-gencommon.js");
25
+ Object.defineProperty(exports, "getFieldExplicitDefaultValue", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldExplicitDefaultValue; } });
26
+ Object.defineProperty(exports, "getFieldIntrinsicDefaultValue", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldIntrinsicDefaultValue; } });
27
+ Object.defineProperty(exports, "getFieldTyping", { enumerable: true, get: function () { return legacy_gencommon_js_1.getFieldTyping; } });
28
+ Object.defineProperty(exports, "literalString", { enumerable: true, get: function () { return legacy_gencommon_js_1.literalString; } });
29
+ var legacy_custom_options_js_1 = require("./legacy-custom-options.js");
30
+ Object.defineProperty(exports, "findCustomScalarOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomScalarOption; } });
31
+ Object.defineProperty(exports, "findCustomMessageOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomMessageOption; } });
32
+ Object.defineProperty(exports, "findCustomEnumOption", { enumerable: true, get: function () { return legacy_custom_options_js_1.findCustomEnumOption; } });
40
33
  /**
41
34
  * @deprecated Please use GeneratedFile.jsDoc() instead
42
35
  */
@@ -1,8 +1,14 @@
1
1
  import type { AnyDesc, DescFile } from "@bufbuild/protobuf";
2
2
  export type JSDocBlock = {
3
3
  readonly kind: "es_jsdoc";
4
+ /**
5
+ * @deprecated In a future release, we will make this property optional.
6
+ */
4
7
  text: string;
5
8
  indentation?: string;
9
+ /**
10
+ * @deprecated In a future release, we will remove this method.
11
+ */
6
12
  toString(): string;
7
13
  };
8
14
  export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
@@ -14,6 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.createJsDocBlock = void 0;
17
+ // TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
17
18
  function createJsDocBlock(textOrDesc, indentation) {
18
19
  const text = typeof textOrDesc == "string" ? textOrDesc : createTextForDesc(textOrDesc);
19
20
  return {
@@ -1,5 +1,5 @@
1
- import type { AnyDesc } from "@bufbuild/protobuf";
2
- import { Message, MessageType, ScalarType } from "@bufbuild/protobuf";
1
+ import type { AnyDesc, MessageType } from "@bufbuild/protobuf";
2
+ import { Message, ScalarType } from "@bufbuild/protobuf";
3
3
  /**
4
4
  * @deprecated Please use extensions instead.
5
5
  *
@@ -1,19 +1,24 @@
1
- import type { DescExtension } from "@bufbuild/protobuf";
2
- import { DescField, DescFile, LongType, ScalarType } from "@bufbuild/protobuf";
1
+ import type { DescExtension, DescField } from "@bufbuild/protobuf";
3
2
  import type { GeneratedFile, Printable } from "./generated-file.js";
4
3
  import type { ImportSymbol } from "./import-symbol.js";
5
- export declare function makeFilePreamble(file: DescFile, pluginName: string, pluginVersion: string, parameter: string, tsNoCheck: boolean): string;
6
4
  /**
7
- * Returns an expression for the TypeScript typing of a field,
8
- * and whether the property should be optional.
5
+ * @deprecated Please use GeneratedFile.string() instead
6
+ */
7
+ export declare function literalString(value: string): string;
8
+ /**
9
+ * @deprecated
9
10
  */
10
11
  export declare function getFieldTyping(field: DescField | DescExtension, file: GeneratedFile): {
11
12
  typing: Printable;
12
13
  optional: boolean;
13
14
  };
14
- export declare function scalarTypeScriptType(type: ScalarType, longType: LongType): Printable;
15
- export declare function literalString(value: string): string;
15
+ /**
16
+ * @deprecated
17
+ */
16
18
  export declare function getFieldExplicitDefaultValue(field: DescField | DescExtension, protoInt64Symbol: ImportSymbol): Printable | undefined;
19
+ /**
20
+ * @deprecated
21
+ */
17
22
  export declare function getFieldIntrinsicDefaultValue(field: DescField): {
18
23
  defaultValue: Printable | undefined;
19
24
  typingInferrable: boolean;
@@ -13,69 +13,28 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.literalString = exports.scalarTypeScriptType = exports.getFieldTyping = exports.makeFilePreamble = void 0;
16
+ exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.getFieldTyping = exports.literalString = void 0;
17
17
  const protobuf_1 = require("@bufbuild/protobuf");
18
- const { localName, getUnwrappedFieldType, scalarDefaultValue } = protobuf_1.codegenInfo;
19
- function makeFilePreamble(file, pluginName, pluginVersion, parameter, tsNoCheck) {
20
- const builder = [];
21
- const trimSuffix = (str, suffix) => str.endsWith(suffix) ? str.substring(0, str.length - suffix.length) : str;
22
- const writeLeadingComments = (comments) => {
23
- for (let comment of comments.leadingDetached) {
24
- comment = trimSuffix(comment, "\n");
25
- for (const line of comment.split("\n")) {
26
- builder.push(`//${line}\n`);
27
- }
28
- builder.push("\n");
29
- }
30
- if (comments.leading !== undefined) {
31
- const comment = trimSuffix(comments.leading, "\n");
32
- for (const line of comment.split("\n")) {
33
- builder.push(`//${line}\n`);
34
- }
35
- builder.push("\n");
36
- }
37
- };
38
- writeLeadingComments(file.getSyntaxComments());
39
- builder.push(`// @generated by ${pluginName} ${pluginVersion}`);
40
- if (parameter !== "") {
41
- builder.push(` with parameter "${parameter}"`);
42
- }
43
- builder.push("\n");
44
- builder.push(`// @generated from file ${file.name}.proto (`);
45
- if (file.proto.package !== undefined) {
46
- builder.push(`package ${file.proto.package}, `);
47
- }
48
- switch (file.edition) {
49
- case protobuf_1.Edition.EDITION_PROTO2:
50
- builder.push(`syntax proto2)\n`);
51
- break;
52
- case protobuf_1.Edition.EDITION_PROTO3:
53
- builder.push(`syntax proto3)\n`);
54
- break;
55
- default: {
56
- const editionString = protobuf_1.Edition[file.edition];
57
- if (typeof editionString == "string") {
58
- const e = editionString.replace("EDITION_", "").toLowerCase();
59
- builder.push(`edition ${e})\n`);
60
- }
61
- else {
62
- builder.push(`unknown edition\n`);
63
- }
64
- break;
65
- }
66
- }
67
- builder.push("/* eslint-disable */\n");
68
- if (tsNoCheck) {
69
- builder.push("// @ts-nocheck\n");
70
- }
71
- builder.push("\n");
72
- writeLeadingComments(file.getPackageComments());
73
- return trimSuffix(builder.join(""), "\n");
18
+ const { localName, getUnwrappedFieldType, scalarZeroValue } = protobuf_1.codegenInfo;
19
+ /**
20
+ * @deprecated Please use GeneratedFile.string() instead
21
+ */
22
+ function literalString(value) {
23
+ return ('"' +
24
+ value
25
+ .split("\\")
26
+ .join("\\\\")
27
+ .split('"')
28
+ .join('\\"')
29
+ .split("\r")
30
+ .join("\\r")
31
+ .split("\n")
32
+ .join("\\n") +
33
+ '"');
74
34
  }
75
- exports.makeFilePreamble = makeFilePreamble;
35
+ exports.literalString = literalString;
76
36
  /**
77
- * Returns an expression for the TypeScript typing of a field,
78
- * and whether the property should be optional.
37
+ * @deprecated
79
38
  */
80
39
  function getFieldTyping(field, file) {
81
40
  const typing = [];
@@ -138,42 +97,9 @@ function getFieldTyping(field, file) {
138
97
  return { typing, optional };
139
98
  }
140
99
  exports.getFieldTyping = getFieldTyping;
141
- function scalarTypeScriptType(type, longType) {
142
- switch (type) {
143
- case protobuf_1.ScalarType.STRING:
144
- return "string";
145
- case protobuf_1.ScalarType.BOOL:
146
- return "boolean";
147
- case protobuf_1.ScalarType.UINT64:
148
- case protobuf_1.ScalarType.SFIXED64:
149
- case protobuf_1.ScalarType.FIXED64:
150
- case protobuf_1.ScalarType.SINT64:
151
- case protobuf_1.ScalarType.INT64:
152
- if (longType === protobuf_1.LongType.STRING) {
153
- return "string";
154
- }
155
- return "bigint";
156
- case protobuf_1.ScalarType.BYTES:
157
- return "Uint8Array";
158
- default:
159
- return "number";
160
- }
161
- }
162
- exports.scalarTypeScriptType = scalarTypeScriptType;
163
- function literalString(value) {
164
- return ('"' +
165
- value
166
- .split("\\")
167
- .join("\\\\")
168
- .split('"')
169
- .join('\\"')
170
- .split("\r")
171
- .join("\\r")
172
- .split("\n")
173
- .join("\\n") +
174
- '"');
175
- }
176
- exports.literalString = literalString;
100
+ /**
101
+ * @deprecated
102
+ */
177
103
  function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
178
104
  switch (field.fieldKind) {
179
105
  case "enum": {
@@ -230,6 +156,9 @@ function getFieldExplicitDefaultValue(field, protoInt64Symbol) {
230
156
  return undefined;
231
157
  }
232
158
  exports.getFieldExplicitDefaultValue = getFieldExplicitDefaultValue;
159
+ /**
160
+ * @deprecated
161
+ */
233
162
  function getFieldIntrinsicDefaultValue(field) {
234
163
  if (field.repeated) {
235
164
  return {
@@ -265,8 +194,7 @@ function getFieldIntrinsicDefaultValue(field) {
265
194
  defaultValue = literalString("");
266
195
  }
267
196
  else {
268
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
269
- defaultValue = scalarDefaultValue(field.scalar, field.longType);
197
+ defaultValue = scalarZeroValue(field.scalar, field.longType);
270
198
  if (typeof defaultValue === "string") {
271
199
  defaultValue = literalString(defaultValue);
272
200
  }
@@ -283,3 +211,27 @@ function getFieldIntrinsicDefaultValue(field) {
283
211
  };
284
212
  }
285
213
  exports.getFieldIntrinsicDefaultValue = getFieldIntrinsicDefaultValue;
214
+ /**
215
+ * @deprecated
216
+ */
217
+ function scalarTypeScriptType(type, longType) {
218
+ switch (type) {
219
+ case protobuf_1.ScalarType.STRING:
220
+ return "string";
221
+ case protobuf_1.ScalarType.BOOL:
222
+ return "boolean";
223
+ case protobuf_1.ScalarType.UINT64:
224
+ case protobuf_1.ScalarType.SFIXED64:
225
+ case protobuf_1.ScalarType.FIXED64:
226
+ case protobuf_1.ScalarType.SINT64:
227
+ case protobuf_1.ScalarType.INT64:
228
+ if (longType === protobuf_1.LongType.STRING) {
229
+ return "string";
230
+ }
231
+ return "bigint";
232
+ case protobuf_1.ScalarType.BYTES:
233
+ return "Uint8Array";
234
+ default:
235
+ return "number";
236
+ }
237
+ }
@@ -0,0 +1,27 @@
1
+ import type { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
2
+ import { LongType, ScalarType } from "@bufbuild/protobuf";
3
+ export type LiteralProtoInt64 = {
4
+ readonly kind: "es_proto_int64";
5
+ type: ScalarType.INT64 | ScalarType.SINT64 | ScalarType.SFIXED64 | ScalarType.UINT64 | ScalarType.FIXED64;
6
+ longType: LongType;
7
+ value: bigint | string;
8
+ };
9
+ export type LiteralString = {
10
+ readonly kind: "es_string";
11
+ value: string;
12
+ };
13
+ export type RefDescMessage = {
14
+ readonly kind: "es_ref_message";
15
+ type: DescMessage;
16
+ typeOnly: boolean;
17
+ };
18
+ export type RefDescEnum = {
19
+ readonly kind: "es_ref_enum";
20
+ type: DescEnum;
21
+ typeOnly: boolean;
22
+ };
23
+ export type ExportDeclaration = {
24
+ readonly kind: "es_export_decl";
25
+ declaration: string;
26
+ name: string | DescMessage | DescEnum | DescExtension;
27
+ };