@bufbuild/protoplugin 1.6.0 → 1.7.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.
Files changed (57) hide show
  1. package/dist/cjs/create-es-plugin.d.ts +15 -0
  2. package/dist/cjs/create-es-plugin.js +11 -6
  3. package/dist/cjs/ecmascript/custom-options.d.ts +8 -0
  4. package/dist/cjs/ecmascript/custom-options.js +7 -1
  5. package/dist/cjs/ecmascript/export-declaration.d.ts +2 -2
  6. package/dist/cjs/ecmascript/export-declaration.js +1 -1
  7. package/dist/cjs/ecmascript/gencommon.d.ts +3 -2
  8. package/dist/cjs/ecmascript/gencommon.js +1 -1
  9. package/dist/cjs/ecmascript/generated-file.d.ts +7 -11
  10. package/dist/cjs/ecmascript/generated-file.js +5 -4
  11. package/dist/cjs/ecmascript/import-path.js +1 -1
  12. package/dist/cjs/ecmascript/import-symbol.js +1 -1
  13. package/dist/cjs/ecmascript/index.d.ts +1 -1
  14. package/dist/cjs/ecmascript/index.js +1 -1
  15. package/dist/cjs/ecmascript/jsdoc.d.ts +2 -2
  16. package/dist/cjs/ecmascript/jsdoc.js +4 -1
  17. package/dist/cjs/ecmascript/parameter.js +1 -1
  18. package/dist/cjs/ecmascript/reify-wkt.js +1 -1
  19. package/dist/cjs/ecmascript/runtime-imports.d.ts +1 -0
  20. package/dist/cjs/ecmascript/runtime-imports.js +2 -1
  21. package/dist/cjs/ecmascript/schema.d.ts +2 -1
  22. package/dist/cjs/ecmascript/schema.js +8 -9
  23. package/dist/cjs/ecmascript/target.js +1 -1
  24. package/dist/cjs/ecmascript/transpile.js +1 -1
  25. package/dist/cjs/error.js +1 -1
  26. package/dist/cjs/index.js +1 -1
  27. package/dist/cjs/plugin.js +1 -1
  28. package/dist/cjs/run-node.js +1 -1
  29. package/dist/esm/create-es-plugin.d.ts +15 -0
  30. package/dist/esm/create-es-plugin.js +11 -6
  31. package/dist/esm/ecmascript/custom-options.d.ts +8 -0
  32. package/dist/esm/ecmascript/custom-options.js +7 -1
  33. package/dist/esm/ecmascript/export-declaration.d.ts +2 -2
  34. package/dist/esm/ecmascript/export-declaration.js +1 -1
  35. package/dist/esm/ecmascript/gencommon.d.ts +3 -2
  36. package/dist/esm/ecmascript/gencommon.js +1 -1
  37. package/dist/esm/ecmascript/generated-file.d.ts +7 -11
  38. package/dist/esm/ecmascript/generated-file.js +6 -5
  39. package/dist/esm/ecmascript/import-path.js +1 -1
  40. package/dist/esm/ecmascript/import-symbol.js +1 -1
  41. package/dist/esm/ecmascript/index.d.ts +1 -1
  42. package/dist/esm/ecmascript/index.js +1 -1
  43. package/dist/esm/ecmascript/jsdoc.d.ts +2 -2
  44. package/dist/esm/ecmascript/jsdoc.js +4 -1
  45. package/dist/esm/ecmascript/parameter.js +1 -1
  46. package/dist/esm/ecmascript/reify-wkt.js +1 -1
  47. package/dist/esm/ecmascript/runtime-imports.d.ts +1 -0
  48. package/dist/esm/ecmascript/runtime-imports.js +2 -1
  49. package/dist/esm/ecmascript/schema.d.ts +2 -1
  50. package/dist/esm/ecmascript/schema.js +9 -10
  51. package/dist/esm/ecmascript/target.js +1 -1
  52. package/dist/esm/ecmascript/transpile.js +1 -1
  53. package/dist/esm/error.js +1 -1
  54. package/dist/esm/index.js +1 -1
  55. package/dist/esm/plugin.js +1 -1
  56. package/dist/esm/run-node.js +1 -1
  57. package/package.json +2 -2
@@ -1,6 +1,7 @@
1
1
  import { Schema } from "./ecmascript/schema.js";
2
2
  import type { FileInfo } from "./ecmascript/generated-file.js";
3
3
  import type { Plugin } from "./plugin.js";
4
+ import type { FeatureSetDefaults } from "@bufbuild/protobuf";
4
5
  interface PluginInit {
5
6
  /**
6
7
  * Name of this code generator plugin.
@@ -15,6 +16,20 @@ interface PluginInit {
15
16
  * options.
16
17
  */
17
18
  parseOption?: (key: string, value: string) => void;
19
+ /**
20
+ * Whether the plugin supports editions.
21
+ */
22
+ supportsEditions?: boolean;
23
+ /**
24
+ * By default, plugins support all editions supported by createDescriptorSet()
25
+ * from @bufbuild/protobuf, if supportsEditions is enabled.
26
+ *
27
+ * This option can be used to limit support for specific editions, by providing
28
+ * your own google.protobuf.FeatureSetDefaults generated by protoc with the
29
+ * flags --experimental_edition_defaults_out, --experimental_edition_defaults_minimum,
30
+ * and --experimental_edition_defaults_maximum.
31
+ */
32
+ featureSetDefaults?: FeatureSetDefaults;
18
33
  /**
19
34
  * A function which will generate TypeScript files based on proto input.
20
35
  * This function will be invoked by the plugin framework when the plugin runs.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -30,9 +30,9 @@ function createEcmaScriptPlugin(init) {
30
30
  name: init.name,
31
31
  version: init.version,
32
32
  run(req) {
33
- var _a;
33
+ var _a, _b;
34
34
  const parameter = (0, parameter_js_1.parseParameter)(req.parameter, init.parseOption);
35
- const schema = (0, schema_js_1.createSchema)(req, parameter, init.name, init.version);
35
+ const schema = (0, schema_js_1.createSchema)(req, parameter, init.name, init.version, init.featureSetDefaults);
36
36
  const targetTs = schema.targets.includes("ts");
37
37
  const targetJs = schema.targets.includes("js");
38
38
  const targetDts = schema.targets.includes("dts");
@@ -96,14 +96,19 @@ function createEcmaScriptPlugin(init) {
96
96
  const transpiledFiles = transpileFn(tsFiles, transpileJs, transpileDts, parameter.jsImportStyle);
97
97
  files.push(...transpiledFiles);
98
98
  }
99
- return toResponse(files);
99
+ return toResponse(files, (_b = init.supportsEditions) !== null && _b !== void 0 ? _b : false);
100
100
  },
101
101
  };
102
102
  }
103
103
  exports.createEcmaScriptPlugin = createEcmaScriptPlugin;
104
- function toResponse(files) {
104
+ function toResponse(files, supportsEditions) {
105
+ let supportedFeatures = protobuf_1.CodeGeneratorResponse_Feature.PROTO3_OPTIONAL;
106
+ if (supportsEditions) {
107
+ supportedFeatures =
108
+ supportedFeatures | protobuf_1.CodeGeneratorResponse_Feature.SUPPORTS_EDITIONS;
109
+ }
105
110
  return new protobuf_1.CodeGeneratorResponse({
106
- supportedFeatures: protobuf_1.protoInt64.parse(protobuf_1.CodeGeneratorResponse_Feature.PROTO3_OPTIONAL),
111
+ supportedFeatures: protobuf_1.protoInt64.parse(supportedFeatures),
107
112
  file: files.map((f) => {
108
113
  if (f.preamble !== undefined) {
109
114
  f.content = f.preamble + "\n" + f.content;
@@ -1,12 +1,16 @@
1
1
  import type { AnyDesc } from "@bufbuild/protobuf";
2
2
  import { Message, MessageType, ScalarType } from "@bufbuild/protobuf";
3
3
  /**
4
+ * @deprecated Please use extensions instead.
5
+ *
4
6
  * Returns the value of a custom option with a scalar type.
5
7
  *
6
8
  * If no option is found, returns undefined.
7
9
  */
8
10
  export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, extensionNumber: number, scalarType: T): ScalarValue<T> | undefined;
9
11
  /**
12
+ * @deprecated Please use extensions instead.
13
+ *
10
14
  * Returns the value of a custom message option for the given descriptor and
11
15
  * extension number.
12
16
  * The msgType param is then used to deserialize the message for returning to
@@ -19,6 +23,8 @@ export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDe
19
23
  */
20
24
  export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, extensionNumber: number, msgType: MessageType<T>): T | undefined;
21
25
  /**
26
+ * @deprecated Please use extensions instead.
27
+ *
22
28
  * Returns the value of a custom enum option for the given descriptor and
23
29
  * extension number.
24
30
  *
@@ -26,6 +32,8 @@ export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyD
26
32
  */
27
33
  export declare function findCustomEnumOption(desc: AnyDesc, extensionNumber: number): number | undefined;
28
34
  /**
35
+ * @deprecated Please use extensions instead.
36
+ *
29
37
  * ScalarValue is a conditional type that pairs a ScalarType value with its concrete type.
30
38
  */
31
39
  type ScalarValue<T> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? bigint | string : T extends ScalarType.SINT64 ? bigint | string : T extends ScalarType.SFIXED64 ? bigint | string : T extends ScalarType.UINT64 ? bigint | string : T extends ScalarType.FIXED64 ? bigint | string : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = void 0;
17
17
  const protobuf_1 = require("@bufbuild/protobuf");
18
18
  /**
19
+ * @deprecated Please use extensions instead.
20
+ *
19
21
  * Returns the value of a custom option with a scalar type.
20
22
  *
21
23
  * If no option is found, returns undefined.
@@ -63,6 +65,8 @@ function findCustomScalarOption(desc, extensionNumber, scalarType) {
63
65
  }
64
66
  exports.findCustomScalarOption = findCustomScalarOption;
65
67
  /**
68
+ * @deprecated Please use extensions instead.
69
+ *
66
70
  * Returns the value of a custom message option for the given descriptor and
67
71
  * extension number.
68
72
  * The msgType param is then used to deserialize the message for returning to
@@ -89,6 +93,8 @@ function findCustomMessageOption(desc, extensionNumber, msgType) {
89
93
  }
90
94
  exports.findCustomMessageOption = findCustomMessageOption;
91
95
  /**
96
+ * @deprecated Please use extensions instead.
97
+ *
92
98
  * Returns the value of a custom enum option for the given descriptor and
93
99
  * extension number.
94
100
  *
@@ -1,7 +1,7 @@
1
- import { DescEnum, DescMessage } from "@bufbuild/protobuf";
1
+ import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
2
2
  export type ExportDeclaration = {
3
3
  readonly kind: "es_export_decl";
4
4
  declaration: string;
5
- name: string | DescMessage | DescEnum;
5
+ name: string | DescMessage | DescEnum | DescExtension;
6
6
  };
7
7
  export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,3 +1,4 @@
1
+ import type { DescExtension } from "@bufbuild/protobuf";
1
2
  import { DescField, DescFile, LongType, ScalarType } from "@bufbuild/protobuf";
2
3
  import type { GeneratedFile, Printable } from "./generated-file.js";
3
4
  import type { ImportSymbol } from "./import-symbol.js";
@@ -6,13 +7,13 @@ export declare function makeFilePreamble(file: DescFile, pluginName: string, plu
6
7
  * Returns an expression for the TypeScript typing of a field,
7
8
  * and whether the property should be optional.
8
9
  */
9
- export declare function getFieldTyping(field: DescField, file: GeneratedFile): {
10
+ export declare function getFieldTyping(field: DescField | DescExtension, file: GeneratedFile): {
10
11
  typing: Printable;
11
12
  optional: boolean;
12
13
  };
13
14
  export declare function scalarTypeScriptType(type: ScalarType, longType: LongType): Printable;
14
15
  export declare function literalString(value: string): string;
15
- export declare function getFieldExplicitDefaultValue(field: DescField, protoInt64Symbol: ImportSymbol): Printable | undefined;
16
+ export declare function getFieldExplicitDefaultValue(field: DescField | DescExtension, protoInt64Symbol: ImportSymbol): Printable | undefined;
16
17
  export declare function getFieldIntrinsicDefaultValue(field: DescField): {
17
18
  defaultValue: Printable | undefined;
18
19
  typingInferrable: boolean;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -6,7 +6,7 @@ import type { JSDocBlock } from "./jsdoc.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 | Printable[];
9
+ export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | DescMessage | DescEnum | DescExtension | Printable[];
10
10
  /**
11
11
  * FileInfo represents an intermediate type using for transpiling TypeScript internally.
12
12
  */
@@ -67,7 +67,7 @@ export interface GeneratedFile {
67
67
  * descriptor. The comment block will contain the original comments from the
68
68
  * protobuf source, and annotations such as `@generated from message MyMessage`.
69
69
  */
70
- jsDoc(desc: Exclude<AnyDesc, DescFile | DescExtension>, indentation?: string): JSDocBlock;
70
+ jsDoc(desc: Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
71
71
  /**
72
72
  * Create a printable export statement. For example:
73
73
  *
@@ -84,11 +84,11 @@ export interface GeneratedFile {
84
84
  * statement. If the plugin option `js_import_style=legacy_commonjs` is set,
85
85
  * exports will automatically be generated for CommonJS.
86
86
  */
87
- exportDecl(declaration: string, name: string | DescMessage | DescEnum): Printable;
87
+ exportDecl(declaration: string, name: string | DescMessage | DescEnum | DescExtension): Printable;
88
88
  /**
89
89
  * Import a message or enumeration generated by protoc-gen-es.
90
90
  */
91
- import(type: DescMessage | DescEnum): ImportSymbol;
91
+ import(type: DescMessage | DescEnum | DescExtension): ImportSymbol;
92
92
  /**
93
93
  * Import any symbol from a file or package.
94
94
  *
@@ -109,12 +109,8 @@ export interface GeneratedFile {
109
109
  export interface GeneratedFileController extends GeneratedFile {
110
110
  getFileInfo(): FileInfo;
111
111
  }
112
- type CreateTypeImportFn = (desc: DescMessage | DescEnum) => ImportSymbol;
112
+ type CreateTypeImportFn = (desc: DescMessage | DescEnum | DescExtension) => ImportSymbol;
113
113
  type RewriteImportPathFn = (path: string) => string;
114
- export declare function createGeneratedFile(name: string, importPath: string, jsImportStyle: "module" | "legacy_commonjs", rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, preambleSettings: {
115
- pluginName: string;
116
- pluginVersion: string;
117
- pluginParameter: string;
118
- tsNocheck: boolean;
119
- }): GeneratedFileController;
114
+ type CreatePreambleFn = (descFile: DescFile) => string;
115
+ export declare function createGeneratedFile(name: string, importPath: string, jsImportStyle: "module" | "legacy_commonjs", rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, createPreamble: CreatePreambleFn): GeneratedFileController;
120
116
  export {};
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@ const gencommon_js_1 = require("./gencommon.js");
19
19
  const import_path_js_1 = require("./import-path.js");
20
20
  const export_declaration_js_1 = require("./export-declaration.js");
21
21
  const jsdoc_js_1 = require("./jsdoc.js");
22
- function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, preambleSettings) {
22
+ function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
23
23
  let preamble;
24
24
  const el = [];
25
25
  return {
26
26
  preamble(file) {
27
- preamble = (0, gencommon_js_1.makeFilePreamble)(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.pluginParameter, preambleSettings.tsNocheck);
27
+ preamble = createPreamble(file);
28
28
  },
29
29
  print(printableOrFragments, ...rest) {
30
30
  let printables;
@@ -183,6 +183,7 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
183
183
  });
184
184
  break;
185
185
  case "message":
186
+ case "extension":
186
187
  case "enum":
187
188
  el.push(createTypeImport(p));
188
189
  break;
@@ -322,7 +323,7 @@ function literalBigint(value, runtimeImports) {
322
323
  }
323
324
  return [
324
325
  runtimeImports.protoInt64,
325
- ".parse(",
326
+ value > 0 ? ".uParse(" : ".parse(",
326
327
  (0, gencommon_js_1.literalString)(value.toString()),
327
328
  ")",
328
329
  ];
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -7,7 +7,7 @@ export type { RuntimeImports } from "./runtime-imports.js";
7
7
  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
- export declare const localName: (desc: import("@bufbuild/protobuf").DescEnum | import("@bufbuild/protobuf").DescMessage | import("@bufbuild/protobuf").DescService | import("@bufbuild/protobuf").DescEnumValue | import("@bufbuild/protobuf").DescField | import("@bufbuild/protobuf").DescOneof | import("@bufbuild/protobuf").DescMethod) => string;
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
11
  export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, } from "./gencommon.js";
12
12
  export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
13
13
  /**
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,8 +1,8 @@
1
- import type { AnyDesc, DescExtension, DescFile } from "@bufbuild/protobuf";
1
+ import type { AnyDesc, DescFile } from "@bufbuild/protobuf";
2
2
  export type JSDocBlock = {
3
3
  readonly kind: "es_jsdoc";
4
4
  text: string;
5
5
  indentation?: string;
6
6
  toString(): string;
7
7
  };
8
- export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile | DescExtension>, indentation?: string): JSDocBlock;
8
+ export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -69,6 +69,9 @@ function createTextForDesc(desc) {
69
69
  case "field":
70
70
  text += `@generated from field: ${desc.declarationString()};`;
71
71
  break;
72
+ case "extension":
73
+ text += `@generated from extension: ${desc.declarationString()};`;
74
+ break;
72
75
  default:
73
76
  text += `@generated from ${desc.toString()}`;
74
77
  break;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -7,6 +7,7 @@ export interface RuntimeImports {
7
7
  PlainMessage: ImportSymbol;
8
8
  FieldList: ImportSymbol;
9
9
  MessageType: ImportSymbol;
10
+ Extension: ImportSymbol;
10
11
  BinaryReadOptions: ImportSymbol;
11
12
  BinaryWriteOptions: ImportSymbol;
12
13
  JsonReadOptions: ImportSymbol;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ function createRuntimeImports(bootstrapWkt) {
26
26
  PlainMessage: infoToSymbol("PlainMessage", bootstrapWkt),
27
27
  FieldList: infoToSymbol("FieldList", bootstrapWkt),
28
28
  MessageType: infoToSymbol("MessageType", bootstrapWkt),
29
+ Extension: infoToSymbol("Extension", bootstrapWkt),
29
30
  BinaryReadOptions: infoToSymbol("BinaryReadOptions", bootstrapWkt),
30
31
  BinaryWriteOptions: infoToSymbol("BinaryWriteOptions", bootstrapWkt),
31
32
  JsonReadOptions: infoToSymbol("JsonReadOptions", bootstrapWkt),
@@ -1,4 +1,5 @@
1
1
  import type { CodeGeneratorRequest, DescFile } from "@bufbuild/protobuf";
2
+ import { FeatureSetDefaults } from "@bufbuild/protobuf";
2
3
  import type { FileInfo, GeneratedFile } from "./generated-file.js";
3
4
  import { RuntimeImports } from "./runtime-imports.js";
4
5
  import type { Target } from "./target.js";
@@ -37,5 +38,5 @@ interface SchemaController extends Schema {
37
38
  getFileInfo: () => FileInfo[];
38
39
  prepareGenerate(target: Target): void;
39
40
  }
40
- export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string): SchemaController;
41
+ export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string, featureSetDefaults: FeatureSetDefaults | undefined): SchemaController;
41
42
  export {};
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -19,8 +19,11 @@ const generated_file_js_1 = require("./generated-file.js");
19
19
  const runtime_imports_js_1 = require("./runtime-imports.js");
20
20
  const import_symbol_js_1 = require("./import-symbol.js");
21
21
  const import_path_js_1 = require("./import-path.js");
22
- function createSchema(request, parameter, pluginName, pluginVersion) {
23
- const descriptorSet = (0, protobuf_1.createDescriptorSet)(request.protoFile);
22
+ const gencommon_1 = require("./gencommon");
23
+ function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
24
+ const descriptorSet = (0, protobuf_1.createDescriptorSet)(request.protoFile, {
25
+ featureSetDefaults,
26
+ });
24
27
  const filesToGenerate = findFilesToGenerate(descriptorSet, request);
25
28
  const runtime = (0, runtime_imports_js_1.createRuntimeImports)(parameter.bootstrapWkt);
26
29
  const createTypeImport = (desc) => {
@@ -28,6 +31,7 @@ function createSchema(request, parameter, pluginName, pluginVersion) {
28
31
  const from = (0, import_path_js_1.makeImportPath)(desc.file, parameter.bootstrapWkt, filesToGenerate);
29
32
  return (0, import_symbol_js_1.createImportSymbol)(name, from);
30
33
  };
34
+ const createPreamble = (descFile) => (0, gencommon_1.makeFilePreamble)(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
31
35
  let target;
32
36
  const generatedFiles = [];
33
37
  return {
@@ -41,12 +45,7 @@ function createSchema(request, parameter, pluginName, pluginVersion) {
41
45
  throw new Error("prepareGenerate() must be called before generateFile()");
42
46
  }
43
47
  const genFile = (0, generated_file_js_1.createGeneratedFile)(name, (0, import_path_js_1.deriveImportPath)(name), target === "js" ? parameter.jsImportStyle : "module", // ts and dts always use import/export, only js may use commonjs
44
- (importPath) => (0, import_path_js_1.rewriteImportPath)(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, {
45
- pluginName,
46
- pluginVersion,
47
- pluginParameter: parameter.sanitizedParameter,
48
- tsNocheck: parameter.tsNocheck,
49
- });
48
+ (importPath) => (0, import_path_js_1.rewriteImportPath)(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, createPreamble);
50
49
  generatedFiles.push(genFile);
51
50
  return genFile;
52
51
  },
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
package/dist/cjs/error.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,6 +1,7 @@
1
1
  import { Schema } from "./ecmascript/schema.js";
2
2
  import type { FileInfo } from "./ecmascript/generated-file.js";
3
3
  import type { Plugin } from "./plugin.js";
4
+ import type { FeatureSetDefaults } from "@bufbuild/protobuf";
4
5
  interface PluginInit {
5
6
  /**
6
7
  * Name of this code generator plugin.
@@ -15,6 +16,20 @@ interface PluginInit {
15
16
  * options.
16
17
  */
17
18
  parseOption?: (key: string, value: string) => void;
19
+ /**
20
+ * Whether the plugin supports editions.
21
+ */
22
+ supportsEditions?: boolean;
23
+ /**
24
+ * By default, plugins support all editions supported by createDescriptorSet()
25
+ * from @bufbuild/protobuf, if supportsEditions is enabled.
26
+ *
27
+ * This option can be used to limit support for specific editions, by providing
28
+ * your own google.protobuf.FeatureSetDefaults generated by protoc with the
29
+ * flags --experimental_edition_defaults_out, --experimental_edition_defaults_minimum,
30
+ * and --experimental_edition_defaults_maximum.
31
+ */
32
+ featureSetDefaults?: FeatureSetDefaults;
18
33
  /**
19
34
  * A function which will generate TypeScript files based on proto input.
20
35
  * This function will be invoked by the plugin framework when the plugin runs.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -27,9 +27,9 @@ export function createEcmaScriptPlugin(init) {
27
27
  name: init.name,
28
28
  version: init.version,
29
29
  run(req) {
30
- var _a;
30
+ var _a, _b;
31
31
  const parameter = parseParameter(req.parameter, init.parseOption);
32
- const schema = createSchema(req, parameter, init.name, init.version);
32
+ const schema = createSchema(req, parameter, init.name, init.version, init.featureSetDefaults);
33
33
  const targetTs = schema.targets.includes("ts");
34
34
  const targetJs = schema.targets.includes("js");
35
35
  const targetDts = schema.targets.includes("dts");
@@ -93,13 +93,18 @@ export function createEcmaScriptPlugin(init) {
93
93
  const transpiledFiles = transpileFn(tsFiles, transpileJs, transpileDts, parameter.jsImportStyle);
94
94
  files.push(...transpiledFiles);
95
95
  }
96
- return toResponse(files);
96
+ return toResponse(files, (_b = init.supportsEditions) !== null && _b !== void 0 ? _b : false);
97
97
  },
98
98
  };
99
99
  }
100
- function toResponse(files) {
100
+ function toResponse(files, supportsEditions) {
101
+ let supportedFeatures = CodeGeneratorResponse_Feature.PROTO3_OPTIONAL;
102
+ if (supportsEditions) {
103
+ supportedFeatures =
104
+ supportedFeatures | CodeGeneratorResponse_Feature.SUPPORTS_EDITIONS;
105
+ }
101
106
  return new CodeGeneratorResponse({
102
- supportedFeatures: protoInt64.parse(CodeGeneratorResponse_Feature.PROTO3_OPTIONAL),
107
+ supportedFeatures: protoInt64.parse(supportedFeatures),
103
108
  file: files.map((f) => {
104
109
  if (f.preamble !== undefined) {
105
110
  f.content = f.preamble + "\n" + f.content;
@@ -1,12 +1,16 @@
1
1
  import type { AnyDesc } from "@bufbuild/protobuf";
2
2
  import { Message, MessageType, ScalarType } from "@bufbuild/protobuf";
3
3
  /**
4
+ * @deprecated Please use extensions instead.
5
+ *
4
6
  * Returns the value of a custom option with a scalar type.
5
7
  *
6
8
  * If no option is found, returns undefined.
7
9
  */
8
10
  export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDesc, extensionNumber: number, scalarType: T): ScalarValue<T> | undefined;
9
11
  /**
12
+ * @deprecated Please use extensions instead.
13
+ *
10
14
  * Returns the value of a custom message option for the given descriptor and
11
15
  * extension number.
12
16
  * The msgType param is then used to deserialize the message for returning to
@@ -19,6 +23,8 @@ export declare function findCustomScalarOption<T extends ScalarType>(desc: AnyDe
19
23
  */
20
24
  export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyDesc, extensionNumber: number, msgType: MessageType<T>): T | undefined;
21
25
  /**
26
+ * @deprecated Please use extensions instead.
27
+ *
22
28
  * Returns the value of a custom enum option for the given descriptor and
23
29
  * extension number.
24
30
  *
@@ -26,6 +32,8 @@ export declare function findCustomMessageOption<T extends Message<T>>(desc: AnyD
26
32
  */
27
33
  export declare function findCustomEnumOption(desc: AnyDesc, extensionNumber: number): number | undefined;
28
34
  /**
35
+ * @deprecated Please use extensions instead.
36
+ *
29
37
  * ScalarValue is a conditional type that pairs a ScalarType value with its concrete type.
30
38
  */
31
39
  type ScalarValue<T> = T extends ScalarType.STRING ? string : T extends ScalarType.INT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.UINT32 ? number : T extends ScalarType.SINT32 ? number : T extends ScalarType.FIXED32 ? number : T extends ScalarType.SFIXED32 ? number : T extends ScalarType.FLOAT ? number : T extends ScalarType.DOUBLE ? number : T extends ScalarType.INT64 ? bigint | string : T extends ScalarType.SINT64 ? bigint | string : T extends ScalarType.SFIXED64 ? bigint | string : T extends ScalarType.UINT64 ? bigint | string : T extends ScalarType.FIXED64 ? bigint | string : T extends ScalarType.BOOL ? boolean : T extends ScalarType.BYTES ? Uint8Array : never;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -13,6 +13,8 @@
13
13
  // limitations under the License.
14
14
  import { proto3, BinaryReader, ScalarType, } from "@bufbuild/protobuf";
15
15
  /**
16
+ * @deprecated Please use extensions instead.
17
+ *
16
18
  * Returns the value of a custom option with a scalar type.
17
19
  *
18
20
  * If no option is found, returns undefined.
@@ -59,6 +61,8 @@ export function findCustomScalarOption(desc, extensionNumber, scalarType) {
59
61
  return undefined;
60
62
  }
61
63
  /**
64
+ * @deprecated Please use extensions instead.
65
+ *
62
66
  * Returns the value of a custom message option for the given descriptor and
63
67
  * extension number.
64
68
  * The msgType param is then used to deserialize the message for returning to
@@ -84,6 +88,8 @@ export function findCustomMessageOption(desc, extensionNumber, msgType) {
84
88
  return undefined;
85
89
  }
86
90
  /**
91
+ * @deprecated Please use extensions instead.
92
+ *
87
93
  * Returns the value of a custom enum option for the given descriptor and
88
94
  * extension number.
89
95
  *
@@ -1,7 +1,7 @@
1
- import { DescEnum, DescMessage } from "@bufbuild/protobuf";
1
+ import { DescEnum, DescExtension, DescMessage } from "@bufbuild/protobuf";
2
2
  export type ExportDeclaration = {
3
3
  readonly kind: "es_export_decl";
4
4
  declaration: string;
5
- name: string | DescMessage | DescEnum;
5
+ name: string | DescMessage | DescEnum | DescExtension;
6
6
  };
7
7
  export declare function createExportDeclaration(declaration: string, name: ExportDeclaration["name"]): ExportDeclaration;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,3 +1,4 @@
1
+ import type { DescExtension } from "@bufbuild/protobuf";
1
2
  import { DescField, DescFile, LongType, ScalarType } from "@bufbuild/protobuf";
2
3
  import type { GeneratedFile, Printable } from "./generated-file.js";
3
4
  import type { ImportSymbol } from "./import-symbol.js";
@@ -6,13 +7,13 @@ export declare function makeFilePreamble(file: DescFile, pluginName: string, plu
6
7
  * Returns an expression for the TypeScript typing of a field,
7
8
  * and whether the property should be optional.
8
9
  */
9
- export declare function getFieldTyping(field: DescField, file: GeneratedFile): {
10
+ export declare function getFieldTyping(field: DescField | DescExtension, file: GeneratedFile): {
10
11
  typing: Printable;
11
12
  optional: boolean;
12
13
  };
13
14
  export declare function scalarTypeScriptType(type: ScalarType, longType: LongType): Printable;
14
15
  export declare function literalString(value: string): string;
15
- export declare function getFieldExplicitDefaultValue(field: DescField, protoInt64Symbol: ImportSymbol): Printable | undefined;
16
+ export declare function getFieldExplicitDefaultValue(field: DescField | DescExtension, protoInt64Symbol: ImportSymbol): Printable | undefined;
16
17
  export declare function getFieldIntrinsicDefaultValue(field: DescField): {
17
18
  defaultValue: Printable | undefined;
18
19
  typingInferrable: boolean;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -6,7 +6,7 @@ import type { JSDocBlock } from "./jsdoc.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 | Printable[];
9
+ export type Printable = string | number | boolean | bigint | Uint8Array | ImportSymbol | ExportDeclaration | JSDocBlock | DescMessage | DescEnum | DescExtension | Printable[];
10
10
  /**
11
11
  * FileInfo represents an intermediate type using for transpiling TypeScript internally.
12
12
  */
@@ -67,7 +67,7 @@ export interface GeneratedFile {
67
67
  * descriptor. The comment block will contain the original comments from the
68
68
  * protobuf source, and annotations such as `@generated from message MyMessage`.
69
69
  */
70
- jsDoc(desc: Exclude<AnyDesc, DescFile | DescExtension>, indentation?: string): JSDocBlock;
70
+ jsDoc(desc: Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
71
71
  /**
72
72
  * Create a printable export statement. For example:
73
73
  *
@@ -84,11 +84,11 @@ export interface GeneratedFile {
84
84
  * statement. If the plugin option `js_import_style=legacy_commonjs` is set,
85
85
  * exports will automatically be generated for CommonJS.
86
86
  */
87
- exportDecl(declaration: string, name: string | DescMessage | DescEnum): Printable;
87
+ exportDecl(declaration: string, name: string | DescMessage | DescEnum | DescExtension): Printable;
88
88
  /**
89
89
  * Import a message or enumeration generated by protoc-gen-es.
90
90
  */
91
- import(type: DescMessage | DescEnum): ImportSymbol;
91
+ import(type: DescMessage | DescEnum | DescExtension): ImportSymbol;
92
92
  /**
93
93
  * Import any symbol from a file or package.
94
94
  *
@@ -109,12 +109,8 @@ export interface GeneratedFile {
109
109
  export interface GeneratedFileController extends GeneratedFile {
110
110
  getFileInfo(): FileInfo;
111
111
  }
112
- type CreateTypeImportFn = (desc: DescMessage | DescEnum) => ImportSymbol;
112
+ type CreateTypeImportFn = (desc: DescMessage | DescEnum | DescExtension) => ImportSymbol;
113
113
  type RewriteImportPathFn = (path: string) => string;
114
- export declare function createGeneratedFile(name: string, importPath: string, jsImportStyle: "module" | "legacy_commonjs", rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, preambleSettings: {
115
- pluginName: string;
116
- pluginVersion: string;
117
- pluginParameter: string;
118
- tsNocheck: boolean;
119
- }): GeneratedFileController;
114
+ type CreatePreambleFn = (descFile: DescFile) => string;
115
+ export declare function createGeneratedFile(name: string, importPath: string, jsImportStyle: "module" | "legacy_commonjs", rewriteImportPath: RewriteImportPathFn, createTypeImport: CreateTypeImportFn, runtimeImports: RuntimeImports, createPreamble: CreatePreambleFn): GeneratedFileController;
120
116
  export {};
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -12,16 +12,16 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { createImportSymbol } from "./import-symbol.js";
15
- import { literalString, makeFilePreamble } from "./gencommon.js";
15
+ import { literalString } from "./gencommon.js";
16
16
  import { makeImportPathRelative } from "./import-path.js";
17
17
  import { createExportDeclaration } from "./export-declaration.js";
18
18
  import { createJsDocBlock } from "./jsdoc.js";
19
- export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, preambleSettings) {
19
+ export function createGeneratedFile(name, importPath, jsImportStyle, rewriteImportPath, createTypeImport, runtimeImports, createPreamble) {
20
20
  let preamble;
21
21
  const el = [];
22
22
  return {
23
23
  preamble(file) {
24
- preamble = makeFilePreamble(file, preambleSettings.pluginName, preambleSettings.pluginVersion, preambleSettings.pluginParameter, preambleSettings.tsNocheck);
24
+ preamble = createPreamble(file);
25
25
  },
26
26
  print(printableOrFragments, ...rest) {
27
27
  let printables;
@@ -179,6 +179,7 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
179
179
  });
180
180
  break;
181
181
  case "message":
182
+ case "extension":
182
183
  case "enum":
183
184
  el.push(createTypeImport(p));
184
185
  break;
@@ -318,7 +319,7 @@ function literalBigint(value, runtimeImports) {
318
319
  }
319
320
  return [
320
321
  runtimeImports.protoInt64,
321
- ".parse(",
322
+ value > 0 ? ".uParse(" : ".parse(",
322
323
  literalString(value.toString()),
323
324
  ")",
324
325
  ];
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -7,7 +7,7 @@ export type { RuntimeImports } from "./runtime-imports.js";
7
7
  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
- export declare const localName: (desc: import("@bufbuild/protobuf").DescEnum | import("@bufbuild/protobuf").DescMessage | import("@bufbuild/protobuf").DescService | import("@bufbuild/protobuf").DescEnumValue | import("@bufbuild/protobuf").DescField | import("@bufbuild/protobuf").DescOneof | import("@bufbuild/protobuf").DescMethod) => string;
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
11
  export { getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, } from "./gencommon.js";
12
12
  export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
13
13
  /**
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,8 +1,8 @@
1
- import type { AnyDesc, DescExtension, DescFile } from "@bufbuild/protobuf";
1
+ import type { AnyDesc, DescFile } from "@bufbuild/protobuf";
2
2
  export type JSDocBlock = {
3
3
  readonly kind: "es_jsdoc";
4
4
  text: string;
5
5
  indentation?: string;
6
6
  toString(): string;
7
7
  };
8
- export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile | DescExtension>, indentation?: string): JSDocBlock;
8
+ export declare function createJsDocBlock(textOrDesc: string | Exclude<AnyDesc, DescFile>, indentation?: string): JSDocBlock;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -65,6 +65,9 @@ function createTextForDesc(desc) {
65
65
  case "field":
66
66
  text += `@generated from field: ${desc.declarationString()};`;
67
67
  break;
68
+ case "extension":
69
+ text += `@generated from extension: ${desc.declarationString()};`;
70
+ break;
68
71
  default:
69
72
  text += `@generated from ${desc.toString()}`;
70
73
  break;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -7,6 +7,7 @@ export interface RuntimeImports {
7
7
  PlainMessage: ImportSymbol;
8
8
  FieldList: ImportSymbol;
9
9
  MessageType: ImportSymbol;
10
+ Extension: ImportSymbol;
10
11
  BinaryReadOptions: ImportSymbol;
11
12
  BinaryWriteOptions: ImportSymbol;
12
13
  JsonReadOptions: ImportSymbol;
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ export function createRuntimeImports(bootstrapWkt) {
23
23
  PlainMessage: infoToSymbol("PlainMessage", bootstrapWkt),
24
24
  FieldList: infoToSymbol("FieldList", bootstrapWkt),
25
25
  MessageType: infoToSymbol("MessageType", bootstrapWkt),
26
+ Extension: infoToSymbol("Extension", bootstrapWkt),
26
27
  BinaryReadOptions: infoToSymbol("BinaryReadOptions", bootstrapWkt),
27
28
  BinaryWriteOptions: infoToSymbol("BinaryWriteOptions", bootstrapWkt),
28
29
  JsonReadOptions: infoToSymbol("JsonReadOptions", bootstrapWkt),
@@ -1,4 +1,5 @@
1
1
  import type { CodeGeneratorRequest, DescFile } from "@bufbuild/protobuf";
2
+ import { FeatureSetDefaults } from "@bufbuild/protobuf";
2
3
  import type { FileInfo, GeneratedFile } from "./generated-file.js";
3
4
  import { RuntimeImports } from "./runtime-imports.js";
4
5
  import type { Target } from "./target.js";
@@ -37,5 +38,5 @@ interface SchemaController extends Schema {
37
38
  getFileInfo: () => FileInfo[];
38
39
  prepareGenerate(target: Target): void;
39
40
  }
40
- export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string): SchemaController;
41
+ export declare function createSchema(request: CodeGeneratorRequest, parameter: ParsedParameter, pluginName: string, pluginVersion: string, featureSetDefaults: FeatureSetDefaults | undefined): SchemaController;
41
42
  export {};
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -11,13 +11,16 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- import { codegenInfo, createDescriptorSet } from "@bufbuild/protobuf";
14
+ import { codegenInfo, createDescriptorSet, } from "@bufbuild/protobuf";
15
15
  import { createGeneratedFile } from "./generated-file.js";
16
16
  import { createRuntimeImports } from "./runtime-imports.js";
17
17
  import { createImportSymbol } from "./import-symbol.js";
18
18
  import { deriveImportPath, makeImportPath, rewriteImportPath, } from "./import-path.js";
19
- export function createSchema(request, parameter, pluginName, pluginVersion) {
20
- const descriptorSet = createDescriptorSet(request.protoFile);
19
+ import { makeFilePreamble } from "./gencommon";
20
+ export function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
21
+ const descriptorSet = createDescriptorSet(request.protoFile, {
22
+ featureSetDefaults,
23
+ });
21
24
  const filesToGenerate = findFilesToGenerate(descriptorSet, request);
22
25
  const runtime = createRuntimeImports(parameter.bootstrapWkt);
23
26
  const createTypeImport = (desc) => {
@@ -25,6 +28,7 @@ export function createSchema(request, parameter, pluginName, pluginVersion) {
25
28
  const from = makeImportPath(desc.file, parameter.bootstrapWkt, filesToGenerate);
26
29
  return createImportSymbol(name, from);
27
30
  };
31
+ const createPreamble = (descFile) => makeFilePreamble(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
28
32
  let target;
29
33
  const generatedFiles = [];
30
34
  return {
@@ -38,12 +42,7 @@ export function createSchema(request, parameter, pluginName, pluginVersion) {
38
42
  throw new Error("prepareGenerate() must be called before generateFile()");
39
43
  }
40
44
  const genFile = createGeneratedFile(name, deriveImportPath(name), target === "js" ? parameter.jsImportStyle : "module", // ts and dts always use import/export, only js may use commonjs
41
- (importPath) => rewriteImportPath(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, {
42
- pluginName,
43
- pluginVersion,
44
- pluginParameter: parameter.sanitizedParameter,
45
- tsNocheck: parameter.tsNocheck,
46
- });
45
+ (importPath) => rewriteImportPath(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, createPreamble);
47
46
  generatedFiles.push(genFile);
48
47
  return genFile;
49
48
  },
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/dist/esm/error.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- // Copyright 2021-2023 Buf Technologies, Inc.
1
+ // Copyright 2021-2024 Buf Technologies, Inc.
2
2
  //
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "Helps to create your own Protocol Buffers code generators.",
6
6
  "repository": {
@@ -47,7 +47,7 @@
47
47
  }
48
48
  },
49
49
  "dependencies": {
50
- "@bufbuild/protobuf": "1.6.0",
50
+ "@bufbuild/protobuf": "1.7.1",
51
51
  "@typescript/vfs": "^1.4.0",
52
52
  "typescript": "4.5.2"
53
53
  },