@aptre/protobuf-es-lite 0.2.10 → 0.2.11

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 (73) hide show
  1. package/bin/protoc-gen-es-lite +2 -2
  2. package/dist/assert.js +4 -11
  3. package/dist/binary-encoding.js +30 -35
  4. package/dist/binary.js +84 -96
  5. package/dist/codegen-info.js +12 -15
  6. package/dist/create-descriptor-set.js +113 -117
  7. package/dist/descriptor-set.js +1 -2
  8. package/dist/enum.js +2 -7
  9. package/dist/feature-set.js +16 -20
  10. package/dist/field-wrapper.js +12 -17
  11. package/dist/field.js +18 -27
  12. package/dist/google/index.js +9 -41
  13. package/dist/google/protobuf/any.pb.d.ts +2 -2
  14. package/dist/google/protobuf/any.pb.js +3 -6
  15. package/dist/google/protobuf/api.pb.d.ts +2 -2
  16. package/dist/google/protobuf/api.pb.js +14 -17
  17. package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
  18. package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
  19. package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
  20. package/dist/google/protobuf/descriptor.pb.js +156 -160
  21. package/dist/google/protobuf/duration.pb.d.ts +2 -2
  22. package/dist/google/protobuf/duration.pb.js +3 -6
  23. package/dist/google/protobuf/empty.pb.d.ts +2 -2
  24. package/dist/google/protobuf/empty.pb.js +3 -6
  25. package/dist/google/protobuf/source_context.pb.d.ts +2 -2
  26. package/dist/google/protobuf/source_context.pb.js +3 -6
  27. package/dist/google/protobuf/struct.pb.d.ts +3 -3
  28. package/dist/google/protobuf/struct.pb.js +13 -16
  29. package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
  30. package/dist/google/protobuf/timestamp.pb.js +3 -6
  31. package/dist/google/protobuf/type.pb.d.ts +5 -5
  32. package/dist/google/protobuf/type.pb.js +31 -34
  33. package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
  34. package/dist/google/protobuf/wrappers.pb.js +11 -14
  35. package/dist/index.js +12 -60
  36. package/dist/is-message.js +9 -16
  37. package/dist/json.js +72 -80
  38. package/dist/message.js +48 -55
  39. package/dist/names.js +12 -23
  40. package/dist/partial.js +13 -17
  41. package/dist/proto-base64.js +1 -4
  42. package/dist/proto-double.js +1 -4
  43. package/dist/proto-int64.js +9 -12
  44. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
  45. package/dist/protoc-gen-es-lite/typescript.js +27 -36
  46. package/dist/protoplugin/create-es-plugin.js +13 -17
  47. package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
  48. package/dist/protoplugin/ecmascript/generated-file.js +16 -20
  49. package/dist/protoplugin/ecmascript/import-path.js +13 -20
  50. package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
  51. package/dist/protoplugin/ecmascript/index.js +2 -7
  52. package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
  53. package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
  54. package/dist/protoplugin/ecmascript/parameter.js +10 -14
  55. package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
  56. package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
  57. package/dist/protoplugin/ecmascript/schema.js +16 -20
  58. package/dist/protoplugin/ecmascript/target.js +1 -2
  59. package/dist/protoplugin/ecmascript/transpile.js +15 -42
  60. package/dist/protoplugin/error.js +3 -9
  61. package/dist/protoplugin/index.js +2 -7
  62. package/dist/protoplugin/plugin.js +1 -2
  63. package/dist/protoplugin/run-node.js +6 -10
  64. package/dist/scalar.js +9 -15
  65. package/dist/service-type.js +4 -7
  66. package/dist/text-format.js +25 -30
  67. package/dist/type-registry.js +1 -2
  68. package/dist/unknown.js +7 -12
  69. package/dist/util.d.ts +1 -1
  70. package/dist/util.js +49 -55
  71. package/dist/varint.js +7 -17
  72. package/package.json +10 -7
  73. package/tsconfig.base.json +2 -2
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,9 +11,7 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.reifyWkt = void 0;
17
- const scalar_js_1 = require("../../scalar.js");
14
+ import { ScalarType } from "../../scalar.js";
18
15
  /**
19
16
  * Reifies a given DescMessage into a more concrete object representing its
20
17
  * respective well-known type. The returned object will contain properties
@@ -26,15 +23,15 @@ const scalar_js_1 = require("../../scalar.js");
26
23
  * Returns undefined if the WKT cannot be completely constructed via the
27
24
  * DescMessage.
28
25
  */
29
- function reifyWkt(message) {
26
+ export function reifyWkt(message) {
30
27
  switch (message.typeName) {
31
28
  case "google.protobuf.Any": {
32
29
  const typeUrl = message.fields.find((f) => f.number == 1 &&
33
30
  f.fieldKind == "scalar" &&
34
- f.scalar === scalar_js_1.ScalarType.STRING);
31
+ f.scalar === ScalarType.STRING);
35
32
  const value = message.fields.find((f) => f.number == 2 &&
36
33
  f.fieldKind == "scalar" &&
37
- f.scalar === scalar_js_1.ScalarType.BYTES);
34
+ f.scalar === ScalarType.BYTES);
38
35
  if (typeUrl && value) {
39
36
  return {
40
37
  typeName: message.typeName,
@@ -47,10 +44,10 @@ function reifyWkt(message) {
47
44
  case "google.protobuf.Timestamp": {
48
45
  const seconds = message.fields.find((f) => f.number == 1 &&
49
46
  f.fieldKind == "scalar" &&
50
- f.scalar === scalar_js_1.ScalarType.INT64);
47
+ f.scalar === ScalarType.INT64);
51
48
  const nanos = message.fields.find((f) => f.number == 2 &&
52
49
  f.fieldKind == "scalar" &&
53
- f.scalar === scalar_js_1.ScalarType.INT32);
50
+ f.scalar === ScalarType.INT32);
54
51
  if (seconds && nanos) {
55
52
  return {
56
53
  typeName: message.typeName,
@@ -63,10 +60,10 @@ function reifyWkt(message) {
63
60
  case "google.protobuf.Duration": {
64
61
  const seconds = message.fields.find((f) => f.number == 1 &&
65
62
  f.fieldKind == "scalar" &&
66
- f.scalar === scalar_js_1.ScalarType.INT64);
63
+ f.scalar === ScalarType.INT64);
67
64
  const nanos = message.fields.find((f) => f.number == 2 &&
68
65
  f.fieldKind == "scalar" &&
69
- f.scalar === scalar_js_1.ScalarType.INT32);
66
+ f.scalar === ScalarType.INT32);
70
67
  if (seconds && nanos) {
71
68
  return {
72
69
  typeName: message.typeName,
@@ -94,15 +91,15 @@ function reifyWkt(message) {
94
91
  }
95
92
  const numberValue = message.fields.find((f) => f.number == 2 &&
96
93
  f.fieldKind == "scalar" &&
97
- f.scalar === scalar_js_1.ScalarType.DOUBLE &&
94
+ f.scalar === ScalarType.DOUBLE &&
98
95
  f.oneof === kind);
99
96
  const stringValue = message.fields.find((f) => f.number == 3 &&
100
97
  f.fieldKind == "scalar" &&
101
- f.scalar === scalar_js_1.ScalarType.STRING &&
98
+ f.scalar === ScalarType.STRING &&
102
99
  f.oneof === kind);
103
100
  const boolValue = message.fields.find((f) => f.number == 4 &&
104
101
  f.fieldKind == "scalar" &&
105
- f.scalar === scalar_js_1.ScalarType.BOOL &&
102
+ f.scalar === ScalarType.BOOL &&
106
103
  f.oneof === kind);
107
104
  const structValue = message.fields.find((f) => f.number == 5 && f.oneof === kind);
108
105
  if (structValue?.fieldKind !== "message" ||
@@ -139,7 +136,7 @@ function reifyWkt(message) {
139
136
  case "google.protobuf.FieldMask": {
140
137
  const paths = message.fields.find((f) => f.number == 1 &&
141
138
  f.fieldKind == "scalar" &&
142
- f.scalar === scalar_js_1.ScalarType.STRING &&
139
+ f.scalar === ScalarType.STRING &&
143
140
  f.repeated);
144
141
  if (paths) {
145
142
  return { typeName: message.typeName, paths };
@@ -167,4 +164,3 @@ function reifyWkt(message) {
167
164
  }
168
165
  return undefined;
169
166
  }
170
- exports.reifyWkt = reifyWkt;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,17 +11,14 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createRuntimeImports = void 0;
17
- const import_symbol_js_1 = require("./import-symbol.js");
18
- const codegen_info_js_1 = require("../../codegen-info.js");
19
- function createRuntimeImports(bootstrapWkt) {
14
+ import { createImportSymbol } from "./import-symbol.js";
15
+ import { codegenInfo } from "../../codegen-info.js";
16
+ export function createRuntimeImports(bootstrapWkt) {
20
17
  const imports = {};
21
- for (const [name, info] of Object.entries(codegen_info_js_1.codegenInfo.symbols)) {
22
- const symbol = (0, import_symbol_js_1.createImportSymbol)(name, bootstrapWkt ? info.privateImportPath : info.publicImportPath);
18
+ for (const [name, info] of Object.entries(codegenInfo.symbols)) {
19
+ const symbol = createImportSymbol(name, bootstrapWkt ? info.privateImportPath : info.publicImportPath);
23
20
  imports[name] =
24
21
  info.typeOnly ? symbol.toTypeOnly() : symbol;
25
22
  }
26
23
  return imports;
27
24
  }
28
- exports.createRuntimeImports = createRuntimeImports;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,30 +11,28 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createSchema = void 0;
17
- const generated_file_js_1 = require("./generated-file.js");
18
- const runtime_imports_js_1 = require("./runtime-imports.js");
19
- const import_symbol_js_1 = require("./import-symbol.js");
20
- const import_path_js_1 = require("./import-path.js");
21
- const file_preamble_js_1 = require("./file-preamble.js");
22
- const create_descriptor_set_js_1 = require("../../create-descriptor-set.js");
23
- const codegen_info_js_1 = require("../../codegen-info.js");
24
- function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
14
+ import { createGeneratedFile } from "./generated-file.js";
15
+ import { createRuntimeImports } from "./runtime-imports.js";
16
+ import { createImportSymbol } from "./import-symbol.js";
17
+ import { deriveImportPath, makeImportPath, rewriteImportPath, } from "./import-path.js";
18
+ import { makeFilePreamble } from "./file-preamble.js";
19
+ import { createDescriptorSet } from "../../create-descriptor-set.js";
20
+ import { codegenInfo } from "../../codegen-info.js";
21
+ export function createSchema(request, parameter, pluginName, pluginVersion, featureSetDefaults) {
25
22
  if (!request.protoFile) {
26
23
  throw new Error("no protoFile passed to createSchema");
27
24
  }
28
- const descriptorSet = (0, create_descriptor_set_js_1.createDescriptorSet)(request.protoFile, {
25
+ const descriptorSet = createDescriptorSet(request.protoFile, {
29
26
  featureSetDefaults,
30
27
  });
31
28
  const filesToGenerate = findFilesToGenerate(descriptorSet, request);
32
- const runtime = (0, runtime_imports_js_1.createRuntimeImports)(parameter.bootstrapWkt);
29
+ const runtime = createRuntimeImports(parameter.bootstrapWkt);
33
30
  const createTypeImport = (desc) => {
34
- const name = codegen_info_js_1.codegenInfo.localName(desc);
35
- const from = (0, import_path_js_1.makeImportPath)(desc.file, parameter.bootstrapWkt, filesToGenerate);
36
- return (0, import_symbol_js_1.createImportSymbol)(name, from);
31
+ const name = codegenInfo.localName(desc);
32
+ const from = makeImportPath(desc.file, parameter.bootstrapWkt, filesToGenerate);
33
+ return createImportSymbol(name, from);
37
34
  };
38
- const createPreamble = (descFile) => (0, file_preamble_js_1.makeFilePreamble)(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
35
+ const createPreamble = (descFile) => makeFilePreamble(descFile, pluginName, pluginVersion, parameter.sanitizedParameter, parameter.tsNocheck);
39
36
  let target;
40
37
  const generatedFiles = [];
41
38
  return {
@@ -48,8 +45,8 @@ function createSchema(request, parameter, pluginName, pluginVersion, featureSetD
48
45
  if (target === undefined) {
49
46
  throw new Error("prepareGenerate() must be called before generateFile()");
50
47
  }
51
- 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
52
- (importPath) => (0, import_path_js_1.rewriteImportPath)(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, createPreamble);
48
+ const genFile = createGeneratedFile(name, deriveImportPath(name), target === "js" ? parameter.jsImportStyle : "module", // ts and dts always use import/export, only js may use commonjs
49
+ (importPath) => rewriteImportPath(importPath, parameter.rewriteImports, parameter.importExtension), createTypeImport, runtime, createPreamble);
53
50
  generatedFiles.push(genFile);
54
51
  return genFile;
55
52
  },
@@ -63,7 +60,6 @@ function createSchema(request, parameter, pluginName, pluginVersion, featureSetD
63
60
  },
64
61
  };
65
62
  }
66
- exports.createSchema = createSchema;
67
63
  function findFilesToGenerate(descriptorSet, request) {
68
64
  const missing = request.fileToGenerate?.filter((fileToGenerate) => descriptorSet.files.every((file) => fileToGenerate !== file.name + ".proto")) ?? [];
69
65
  if (missing.length) {
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,4 +11,4 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
14
+ export {};
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,55 +11,30 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- var desc = Object.getOwnPropertyDescriptor(m, k);
18
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
- desc = { enumerable: true, get: function() { return m[k]; } };
20
- }
21
- Object.defineProperty(o, k2, desc);
22
- }) : (function(o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- }));
26
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
- Object.defineProperty(o, "default", { enumerable: true, value: v });
28
- }) : function(o, v) {
29
- o["default"] = v;
30
- });
31
- var __importStar = (this && this.__importStar) || function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.transpile = void 0;
40
- const typescript_1 = __importStar(require("typescript"));
41
- const vfs_1 = require("@typescript/vfs");
14
+ import ts from "typescript";
15
+ import { createDefaultMapFromNodeModules, createSystem, createVirtualCompilerHost, } from "@typescript/vfs";
42
16
  /* eslint-disable import/no-named-as-default-member */
43
17
  // The default options used to auto-transpile if needed.
44
18
  const defaultOptions = {
45
19
  // Type checking
46
20
  strict: false,
47
21
  // modules
48
- module: typescript_1.default.ModuleKind.ES2020,
49
- moduleResolution: typescript_1.default.ModuleResolutionKind.Node16,
22
+ module: ts.ModuleKind.ES2020,
23
+ moduleResolution: ts.ModuleResolutionKind.Node16,
50
24
  noResolve: true,
51
25
  resolveJsonModule: false,
52
26
  // emit
53
27
  emitBOM: false,
54
- importsNotUsedAsValues: typescript_1.default.ImportsNotUsedAsValues.Preserve,
55
- newLine: typescript_1.default.NewLineKind.LineFeed,
28
+ importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Preserve,
29
+ newLine: ts.NewLineKind.LineFeed,
56
30
  preserveValueImports: false,
57
31
  // JavaScript Support
58
32
  allowJs: true,
59
33
  checkJs: false,
60
34
  // Language and Environment
61
35
  lib: [],
62
- moduleDetection: typescript_1.ModuleDetectionKind.Force,
63
- target: typescript_1.default.ScriptTarget.ES2020,
36
+ moduleDetection: ts.ModuleDetectionKind.Force,
37
+ target: ts.ScriptTarget.ES2020,
64
38
  // Completeness
65
39
  skipLibCheck: true,
66
40
  skipDefaultLibCheck: false,
@@ -88,34 +62,34 @@ const defaultOptions = {
88
62
  * npm does not support that yet.
89
63
  */
90
64
  function createTranspiler(options, files) {
91
- const fsMap = (0, vfs_1.createDefaultMapFromNodeModules)({
65
+ const fsMap = createDefaultMapFromNodeModules({
92
66
  target: options.target,
93
67
  });
94
68
  files.forEach((file) => {
95
69
  fsMap.set(file.name, file.content);
96
70
  });
97
- const system = (0, vfs_1.createSystem)(fsMap);
98
- const host = (0, vfs_1.createVirtualCompilerHost)(system, options, typescript_1.default);
99
- return typescript_1.default.createProgram({
71
+ const system = createSystem(fsMap);
72
+ const host = createVirtualCompilerHost(system, options, ts);
73
+ return ts.createProgram({
100
74
  rootNames: [...fsMap.keys()],
101
75
  options,
102
76
  host: host.compilerHost,
103
77
  });
104
78
  }
105
- function transpile(files, transpileJs, transpileDts, jsImportStyle) {
79
+ export function transpile(files, transpileJs, transpileDts, jsImportStyle) {
106
80
  const options = {
107
81
  ...defaultOptions,
108
82
  declaration: transpileDts,
109
83
  emitDeclarationOnly: transpileDts && !transpileJs,
110
84
  };
111
85
  if (jsImportStyle == "legacy_commonjs") {
112
- options.module = typescript_1.default.ModuleKind.CommonJS;
86
+ options.module = ts.ModuleKind.CommonJS;
113
87
  }
114
88
  // Create the transpiler (a ts.Program object)
115
89
  const program = createTranspiler(options, files);
116
90
  const results = [];
117
91
  let err;
118
- const result = program.emit(undefined, (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
92
+ const result = program.emit(undefined, (fileName, data, _writeByteOrderMark, _onError, sourceFiles) => {
119
93
  // We have to go through some hoops here because the header we add to each
120
94
  // file is not part of the AST. So we find the TypeScript file we
121
95
  // generated for each emitted file and add the header to each output ourselves.
@@ -146,4 +120,3 @@ function transpile(files, transpileJs, transpileDts, jsImportStyle) {
146
120
  }
147
121
  return results;
148
122
  }
149
- exports.transpile = transpile;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,9 +11,7 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.isPluginOptionError = exports.reasonToString = exports.PluginOptionError = void 0;
17
- class PluginOptionError extends Error {
14
+ export class PluginOptionError extends Error {
18
15
  constructor(option, reason) {
19
16
  const detail = reason !== undefined ? reasonToString(reason) : "";
20
17
  super(detail.length > 0 ?
@@ -23,8 +20,7 @@ class PluginOptionError extends Error {
23
20
  this.name = "PluginOptionError";
24
21
  }
25
22
  }
26
- exports.PluginOptionError = PluginOptionError;
27
- function reasonToString(reason) {
23
+ export function reasonToString(reason) {
28
24
  if (reason instanceof Error) {
29
25
  return reason.message;
30
26
  }
@@ -33,11 +29,9 @@ function reasonToString(reason) {
33
29
  }
34
30
  return String(reason);
35
31
  }
36
- exports.reasonToString = reasonToString;
37
- function isPluginOptionError(arg) {
32
+ export function isPluginOptionError(arg) {
38
33
  if (!(arg instanceof Error)) {
39
34
  return false;
40
35
  }
41
36
  return arg.name === "PluginOptionError";
42
37
  }
43
- exports.isPluginOptionError = isPluginOptionError;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,9 +11,5 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createEcmaScriptPlugin = exports.runNodeJs = void 0;
17
- var run_node_js_1 = require("./run-node.js");
18
- Object.defineProperty(exports, "runNodeJs", { enumerable: true, get: function () { return run_node_js_1.runNodeJs; } });
19
- var create_es_plugin_js_1 = require("./create-es-plugin.js");
20
- Object.defineProperty(exports, "createEcmaScriptPlugin", { enumerable: true, get: function () { return create_es_plugin_js_1.createEcmaScriptPlugin; } });
14
+ export { runNodeJs } from "./run-node.js";
15
+ export { createEcmaScriptPlugin } from "./create-es-plugin.js";
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,4 +11,4 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
14
+ export {};
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,10 +11,8 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.runNodeJs = void 0;
17
- const error_js_1 = require("./error.js");
18
- const plugin_pb_js_1 = require("../google/protobuf/compiler/plugin.pb.js");
14
+ import { isPluginOptionError, reasonToString } from "./error.js";
15
+ import { CodeGeneratorRequest, CodeGeneratorResponse, } from "../google/protobuf/compiler/plugin.pb.js";
19
16
  /**
20
17
  * Run a plugin with Node.js.
21
18
  *
@@ -26,7 +23,7 @@ const plugin_pb_js_1 = require("../google/protobuf/compiler/plugin.pb.js");
26
23
  * runNodeJs(myPlugin);
27
24
  * ```
28
25
  */
29
- function runNodeJs(plugin) {
26
+ export function runNodeJs(plugin) {
30
27
  const args = process.argv.slice(2);
31
28
  if ((args.length === 1 && args[0] === "-v") || args[0] === "--version") {
32
29
  process.stdout.write(`${plugin.name} ${plugin.version}\n`);
@@ -38,19 +35,18 @@ function runNodeJs(plugin) {
38
35
  }
39
36
  readBytes(process.stdin)
40
37
  .then((data) => {
41
- const req = plugin_pb_js_1.CodeGeneratorRequest.fromBinary(data);
38
+ const req = CodeGeneratorRequest.fromBinary(data);
42
39
  const res = plugin.run(req);
43
- return writeBytes(process.stdout, plugin_pb_js_1.CodeGeneratorResponse.toBinary(res));
40
+ return writeBytes(process.stdout, CodeGeneratorResponse.toBinary(res));
44
41
  })
45
42
  .then(() => process.exit(0))
46
43
  .catch((reason) => {
47
- const message = (0, error_js_1.isPluginOptionError)(reason) ? reason.message : (0, error_js_1.reasonToString)(reason);
44
+ const message = isPluginOptionError(reason) ? reason.message : reasonToString(reason);
48
45
  process.stderr.write(`${plugin.name}: ${message}\n`);
49
46
  process.exit(1);
50
47
  return;
51
48
  });
52
49
  }
53
- exports.runNodeJs = runNodeJs;
54
50
  /**
55
51
  * Read a stream to the end.
56
52
  */
package/dist/scalar.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,15 +11,13 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.isScalarZeroValue = exports.scalarZeroValue = exports.scalarEquals = exports.LongType = exports.ScalarType = void 0;
17
- const proto_int64_js_1 = require("./proto-int64.js");
14
+ import { protoInt64 } from "./proto-int64.js";
18
15
  /**
19
16
  * Scalar value types. This is a subset of field types declared by protobuf
20
17
  * enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
21
18
  * are omitted, but the numerical values are identical.
22
19
  */
23
- var ScalarType;
20
+ export var ScalarType;
24
21
  (function (ScalarType) {
25
22
  // 0 is reserved for errors.
26
23
  // Order is weird for historical reasons.
@@ -51,7 +48,7 @@ var ScalarType;
51
48
  ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
52
49
  ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
53
50
  ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
54
- })(ScalarType || (exports.ScalarType = ScalarType = {}));
51
+ })(ScalarType || (ScalarType = {}));
55
52
  /**
56
53
  * JavaScript representation of fields with 64 bit integral types (int64, uint64,
57
54
  * sint64, fixed64, sfixed64).
@@ -67,7 +64,7 @@ var ScalarType;
67
64
  * uint64 field_b = 2 [jstype = JS_STRING]; // String
68
65
  * ```
69
66
  */
70
- var LongType;
67
+ export var LongType;
71
68
  (function (LongType) {
72
69
  /**
73
70
  * Use JavaScript BigInt.
@@ -79,11 +76,11 @@ var LongType;
79
76
  * Field option `[jstype = JS_STRING]`.
80
77
  */
81
78
  LongType[LongType["STRING"] = 1] = "STRING";
82
- })(LongType || (exports.LongType = LongType = {}));
79
+ })(LongType || (LongType = {}));
83
80
  /**
84
81
  * Returns true if both scalar values are equal.
85
82
  */
86
- function scalarEquals(type, a, b) {
83
+ export function scalarEquals(type, a, b) {
87
84
  if (a === b) {
88
85
  // This correctly matches equal values except BYTES and (possibly) 64-bit integers.
89
86
  return true;
@@ -118,11 +115,10 @@ function scalarEquals(type, a, b) {
118
115
  // BYTES and 64-bit integers is not equal.
119
116
  return false;
120
117
  }
121
- exports.scalarEquals = scalarEquals;
122
118
  /**
123
119
  * Returns the zero value for the given scalar type.
124
120
  */
125
- function scalarZeroValue(type, longType) {
121
+ export function scalarZeroValue(type, longType) {
126
122
  switch (type) {
127
123
  case ScalarType.BOOL:
128
124
  return false;
@@ -132,7 +128,7 @@ function scalarZeroValue(type, longType) {
132
128
  case ScalarType.SFIXED64:
133
129
  case ScalarType.SINT64:
134
130
  // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison -- acceptable since it's covered by tests
135
- return (longType == 0 ? proto_int64_js_1.protoInt64.zero : "0");
131
+ return (longType == 0 ? protoInt64.zero : "0");
136
132
  case ScalarType.DOUBLE:
137
133
  case ScalarType.FLOAT:
138
134
  return 0.0;
@@ -146,7 +142,6 @@ function scalarZeroValue(type, longType) {
146
142
  return 0;
147
143
  }
148
144
  }
149
- exports.scalarZeroValue = scalarZeroValue;
150
145
  /**
151
146
  * Returns true for a zero-value. For example, an integer has the zero-value `0`,
152
147
  * a boolean is `false`, a string is `""`, and bytes is an empty Uint8Array.
@@ -154,7 +149,7 @@ exports.scalarZeroValue = scalarZeroValue;
154
149
  * In proto3, zero-values are not written to the wire, unless the field is
155
150
  * optional or repeated.
156
151
  */
157
- function isScalarZeroValue(type, value) {
152
+ export function isScalarZeroValue(type, value) {
158
153
  switch (type) {
159
154
  case ScalarType.BOOL:
160
155
  return value === false;
@@ -166,4 +161,3 @@ function isScalarZeroValue(type, value) {
166
161
  return value == 0; // Loose comparison matches 0n, 0 and "0"
167
162
  }
168
163
  }
169
- exports.isScalarZeroValue = isScalarZeroValue;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,8 +11,6 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.MethodIdempotency = exports.MethodKind = void 0;
17
14
  /**
18
15
  * MethodKind represents the four method types that can be declared in
19
16
  * protobuf with the `stream` keyword:
@@ -23,13 +20,13 @@ exports.MethodIdempotency = exports.MethodKind = void 0;
23
20
  * 3. ClientStreaming: rpc (stream Input) returns (Output)
24
21
  * 4. BiDiStreaming: rpc (stream Input) returns (stream Output)
25
22
  */
26
- var MethodKind;
23
+ export var MethodKind;
27
24
  (function (MethodKind) {
28
25
  MethodKind[MethodKind["Unary"] = 0] = "Unary";
29
26
  MethodKind[MethodKind["ServerStreaming"] = 1] = "ServerStreaming";
30
27
  MethodKind[MethodKind["ClientStreaming"] = 2] = "ClientStreaming";
31
28
  MethodKind[MethodKind["BiDiStreaming"] = 3] = "BiDiStreaming";
32
- })(MethodKind || (exports.MethodKind = MethodKind = {}));
29
+ })(MethodKind || (MethodKind = {}));
33
30
  /**
34
31
  * Is this method side-effect-free (or safe in HTTP parlance), or just
35
32
  * idempotent, or neither? HTTP based RPC implementation may choose GET verb
@@ -40,7 +37,7 @@ var MethodKind;
40
37
  * defined in the well-known type google/protobuf/descriptor.proto, but
41
38
  * drops UNKNOWN.
42
39
  */
43
- var MethodIdempotency;
40
+ export var MethodIdempotency;
44
41
  (function (MethodIdempotency) {
45
42
  /**
46
43
  * Idempotent, no side effects.
@@ -50,4 +47,4 @@ var MethodIdempotency;
50
47
  * Idempotent, but may have side effects.
51
48
  */
52
49
  MethodIdempotency[MethodIdempotency["Idempotent"] = 2] = "Idempotent";
53
- })(MethodIdempotency || (exports.MethodIdempotency = MethodIdempotency = {}));
50
+ })(MethodIdempotency || (MethodIdempotency = {}));