@aptre/protobuf-es-lite 0.2.9 → 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 (75) 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.d.ts +1 -0
  36. package/dist/index.js +12 -60
  37. package/dist/is-message.js +9 -16
  38. package/dist/json.js +72 -80
  39. package/dist/message.js +48 -55
  40. package/dist/names.js +12 -23
  41. package/dist/partial.js +13 -17
  42. package/dist/proto-base64.js +1 -4
  43. package/dist/proto-double.js +1 -4
  44. package/dist/proto-int64.js +9 -12
  45. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
  46. package/dist/protoc-gen-es-lite/typescript.js +27 -36
  47. package/dist/protoplugin/create-es-plugin.js +13 -17
  48. package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
  49. package/dist/protoplugin/ecmascript/generated-file.js +16 -20
  50. package/dist/protoplugin/ecmascript/import-path.js +13 -20
  51. package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
  52. package/dist/protoplugin/ecmascript/index.js +2 -7
  53. package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
  54. package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
  55. package/dist/protoplugin/ecmascript/parameter.js +10 -14
  56. package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
  57. package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
  58. package/dist/protoplugin/ecmascript/schema.js +16 -20
  59. package/dist/protoplugin/ecmascript/target.js +1 -2
  60. package/dist/protoplugin/ecmascript/transpile.js +15 -42
  61. package/dist/protoplugin/error.js +3 -9
  62. package/dist/protoplugin/index.js +2 -7
  63. package/dist/protoplugin/plugin.js +1 -2
  64. package/dist/protoplugin/run-node.js +6 -10
  65. package/dist/scalar.js +9 -15
  66. package/dist/service-type.js +4 -7
  67. package/dist/text-format.js +25 -30
  68. package/dist/type-registry.js +1 -2
  69. package/dist/unknown.js +7 -12
  70. package/dist/util.d.ts +1 -1
  71. package/dist/util.js +49 -55
  72. package/dist/varint.js +7 -17
  73. package/example/example.pb.ts +1 -1
  74. package/package.json +10 -7
  75. package/tsconfig.base.json +2 -2
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2024 Aperture Robotics, LLC.
3
2
  // Copyright 2021-2024 Buf Technologies, Inc.
4
3
  //
@@ -13,16 +12,14 @@
13
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
13
  // See the License for the specific language governing permissions and
15
14
  // limitations under the License.
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.codegenInfo = exports.packageName = void 0;
18
- const names_js_1 = require("./names.js");
19
- const field_wrapper_js_1 = require("./field-wrapper.js");
20
- const scalar_js_1 = require("./scalar.js");
21
- exports.packageName = "@aptre/protobuf-es-lite";
15
+ import { localName, safeIdentifier, safeObjectProperty } from "./names.js";
16
+ import { getUnwrappedFieldType } from "./field-wrapper.js";
17
+ import { scalarZeroValue } from "./scalar.js";
18
+ export const packageName = "@aptre/protobuf-es-lite";
22
19
  const symbolInfo = (typeOnly, privateImportPath) => ({
23
20
  typeOnly,
24
21
  privateImportPath,
25
- publicImportPath: exports.packageName,
22
+ publicImportPath: packageName,
26
23
  });
27
24
  const symbols = {
28
25
  Message: symbolInfo(false, "./message.js"),
@@ -47,13 +44,13 @@ const symbols = {
47
44
  createMessageType: symbolInfo(false, "./message.js"),
48
45
  };
49
46
  // prettier-ignore
50
- exports.codegenInfo = {
51
- packageName: exports.packageName,
52
- localName: names_js_1.localName,
53
- getUnwrappedFieldType: field_wrapper_js_1.getUnwrappedFieldType,
54
- scalarZeroValue: scalar_js_1.scalarZeroValue,
55
- safeIdentifier: names_js_1.safeIdentifier,
56
- safeObjectProperty: names_js_1.safeObjectProperty,
47
+ export const codegenInfo = {
48
+ packageName,
49
+ localName,
50
+ getUnwrappedFieldType,
51
+ scalarZeroValue,
52
+ safeIdentifier,
53
+ safeObjectProperty,
57
54
  symbols,
58
55
  wktSourceFiles: [
59
56
  "google/protobuf/compiler/plugin.proto",
@@ -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,16 +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.createDescriptorSet = void 0;
17
- const assert_js_1 = require("./assert.js");
18
- const feature_set_js_1 = require("./feature-set.js");
19
- const field_js_1 = require("./field.js");
20
- const descriptor_pb_js_1 = require("./google/protobuf/descriptor.pb.js");
21
- const names_js_1 = require("./names.js");
22
- const scalar_js_1 = require("./scalar.js");
23
- const service_type_js_1 = require("./service-type.js");
24
- const text_format_js_1 = require("./text-format.js");
14
+ import { assert } from "./assert.js";
15
+ import { createFeatureResolver } from "./feature-set.js";
16
+ import { fieldJsonName } from "./field.js";
17
+ import { Edition, FeatureSet_RepeatedFieldEncoding, FieldDescriptorProto_Label, FieldDescriptorProto_Type, FieldOptions_JSType, FileDescriptorSet, MethodOptions_IdempotencyLevel, } from "./google/protobuf/descriptor.pb.js";
18
+ import { findEnumSharedPrefix } from "./names.js";
19
+ import { LongType, ScalarType } from "./scalar.js";
20
+ import { MethodIdempotency, MethodKind } from "./service-type.js";
21
+ import { parseTextFormatEnumValue, parseTextFormatScalarValue, } from "./text-format.js";
25
22
  /**
26
23
  * Create a DescriptorSet, a convenient interface for working with a set of
27
24
  * google.protobuf.FileDescriptorProto.
@@ -30,7 +27,7 @@ const text_format_js_1 = require("./text-format.js");
30
27
  * before any file that imports it. Protocol buffer compilers always produce
31
28
  * files in topological order.
32
29
  */
33
- function createDescriptorSet(input, options) {
30
+ export function createDescriptorSet(input, options) {
34
31
  const cart = {
35
32
  files: [],
36
33
  enums: new Map(),
@@ -39,7 +36,7 @@ function createDescriptorSet(input, options) {
39
36
  extensions: new Map(),
40
37
  mapEntries: new Map(),
41
38
  };
42
- const fileDescriptors = input instanceof Uint8Array ? descriptor_pb_js_1.FileDescriptorSet.fromBinary(input).file ?? []
39
+ const fileDescriptors = input instanceof Uint8Array ? FileDescriptorSet.fromBinary(input).file ?? []
43
40
  : Array.isArray(input) ? input
44
41
  : input.file ?? [];
45
42
  const resolverByEdition = new Map();
@@ -47,19 +44,18 @@ function createDescriptorSet(input, options) {
47
44
  const edition = proto.edition || parseFileSyntax(proto.syntax, proto.edition).edition;
48
45
  let resolveFeatures = resolverByEdition.get(edition);
49
46
  if (resolveFeatures === undefined) {
50
- resolveFeatures = (0, feature_set_js_1.createFeatureResolver)(edition, options?.featureSetDefaults, options?.serializationOptions);
47
+ resolveFeatures = createFeatureResolver(edition, options?.featureSetDefaults, options?.serializationOptions);
51
48
  resolverByEdition.set(edition, resolveFeatures);
52
49
  }
53
50
  addFile(proto, cart, resolveFeatures);
54
51
  }
55
52
  return cart;
56
53
  }
57
- exports.createDescriptorSet = createDescriptorSet;
58
54
  /**
59
55
  * Create a descriptor for a file.
60
56
  */
61
57
  function addFile(proto, cart, resolveFeatures) {
62
- (0, assert_js_1.assert)(proto.name, `invalid FileDescriptorProto: missing name`);
58
+ assert(proto.name, `invalid FileDescriptorProto: missing name`);
63
59
  const file = {
64
60
  kind: "file",
65
61
  proto,
@@ -170,7 +166,7 @@ function addFields(message, cart, resolveFeatures) {
170
166
  * parent type, if any.
171
167
  */
172
168
  function addEnum(proto, file, parent, cart, resolveFeatures) {
173
- (0, assert_js_1.assert)(proto.name, `invalid EnumDescriptorProto: missing name`);
169
+ assert(proto.name, `invalid EnumDescriptorProto: missing name`);
174
170
  const desc = {
175
171
  kind: "enum",
176
172
  proto,
@@ -180,7 +176,7 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
180
176
  name: proto.name,
181
177
  typeName: makeTypeName(proto, parent, file),
182
178
  values: [],
183
- sharedPrefix: (0, names_js_1.findEnumSharedPrefix)(proto.name, proto.value?.map((v) => v.name ?? "") ?? []),
179
+ sharedPrefix: findEnumSharedPrefix(proto.name, proto.value?.map((v) => v.name ?? "") ?? []),
184
180
  toString() {
185
181
  return `enum ${this.typeName}`;
186
182
  },
@@ -203,8 +199,8 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
203
199
  };
204
200
  cart.enums.set(desc.typeName, desc);
205
201
  proto.value?.forEach((proto) => {
206
- (0, assert_js_1.assert)(proto.name, `invalid EnumValueDescriptorProto: missing name`);
207
- (0, assert_js_1.assert)(proto.number !== undefined, `invalid EnumValueDescriptorProto: missing number`);
202
+ assert(proto.name, `invalid EnumValueDescriptorProto: missing name`);
203
+ assert(proto.number !== undefined, `invalid EnumValueDescriptorProto: missing number`);
208
204
  desc.values.push({
209
205
  kind: "enum_value",
210
206
  proto,
@@ -242,7 +238,7 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
242
238
  * cart. Note that this does not create descriptors fields.
243
239
  */
244
240
  function addMessage(proto, file, parent, cart, resolveFeatures) {
245
- (0, assert_js_1.assert)(proto.name, `invalid DescriptorProto: missing name`);
241
+ assert(proto.name, `invalid DescriptorProto: missing name`);
246
242
  const desc = {
247
243
  kind: "message",
248
244
  proto,
@@ -296,7 +292,7 @@ function addMessage(proto, file, parent, cart, resolveFeatures) {
296
292
  * cart.
297
293
  */
298
294
  function addService(proto, file, cart, resolveFeatures) {
299
- (0, assert_js_1.assert)(proto.name, `invalid ServiceDescriptorProto: missing name`);
295
+ assert(proto.name, `invalid ServiceDescriptorProto: missing name`);
300
296
  const desc = {
301
297
  kind: "service",
302
298
  proto,
@@ -329,39 +325,39 @@ function addService(proto, file, cart, resolveFeatures) {
329
325
  * Create a descriptor for a method.
330
326
  */
331
327
  function newMethod(proto, parent, cart, resolveFeatures) {
332
- (0, assert_js_1.assert)(proto.name, `invalid MethodDescriptorProto: missing name`);
333
- (0, assert_js_1.assert)(proto.inputType, `invalid MethodDescriptorProto: missing input_type`);
334
- (0, assert_js_1.assert)(proto.outputType, `invalid MethodDescriptorProto: missing output_type`);
328
+ assert(proto.name, `invalid MethodDescriptorProto: missing name`);
329
+ assert(proto.inputType, `invalid MethodDescriptorProto: missing input_type`);
330
+ assert(proto.outputType, `invalid MethodDescriptorProto: missing output_type`);
335
331
  let methodKind;
336
332
  if (proto.clientStreaming === true && proto.serverStreaming === true) {
337
- methodKind = service_type_js_1.MethodKind.BiDiStreaming;
333
+ methodKind = MethodKind.BiDiStreaming;
338
334
  }
339
335
  else if (proto.clientStreaming === true) {
340
- methodKind = service_type_js_1.MethodKind.ClientStreaming;
336
+ methodKind = MethodKind.ClientStreaming;
341
337
  }
342
338
  else if (proto.serverStreaming === true) {
343
- methodKind = service_type_js_1.MethodKind.ServerStreaming;
339
+ methodKind = MethodKind.ServerStreaming;
344
340
  }
345
341
  else {
346
- methodKind = service_type_js_1.MethodKind.Unary;
342
+ methodKind = MethodKind.Unary;
347
343
  }
348
344
  let idempotency;
349
345
  switch (proto.options?.idempotencyLevel) {
350
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENT:
351
- idempotency = service_type_js_1.MethodIdempotency.Idempotent;
346
+ case MethodOptions_IdempotencyLevel.IDEMPOTENT:
347
+ idempotency = MethodIdempotency.Idempotent;
352
348
  break;
353
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
354
- idempotency = service_type_js_1.MethodIdempotency.NoSideEffects;
349
+ case MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
350
+ idempotency = MethodIdempotency.NoSideEffects;
355
351
  break;
356
- case descriptor_pb_js_1.MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
352
+ case MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
357
353
  case undefined:
358
354
  idempotency = undefined;
359
355
  break;
360
356
  }
361
357
  const input = cart.messages.get(trimLeadingDot(proto.inputType));
362
358
  const output = cart.messages.get(trimLeadingDot(proto.outputType));
363
- (0, assert_js_1.assert)(input, `invalid MethodDescriptorProto: input_type ${proto.inputType} not found`);
364
- (0, assert_js_1.assert)(output, `invalid MethodDescriptorProto: output_type ${proto.inputType} not found`);
359
+ assert(input, `invalid MethodDescriptorProto: input_type ${proto.inputType} not found`);
360
+ assert(output, `invalid MethodDescriptorProto: output_type ${proto.inputType} not found`);
365
361
  const name = proto.name;
366
362
  return {
367
363
  kind: "rpc",
@@ -393,7 +389,7 @@ function newMethod(proto, parent, cart, resolveFeatures) {
393
389
  * Create a descriptor for a oneof group.
394
390
  */
395
391
  function newOneof(proto, parent, resolveFeatures) {
396
- (0, assert_js_1.assert)(proto.name, `invalid OneofDescriptorProto: missing name`);
392
+ assert(proto.name, `invalid OneofDescriptorProto: missing name`);
397
393
  return {
398
394
  kind: "oneof",
399
395
  proto,
@@ -421,9 +417,9 @@ function newOneof(proto, parent, resolveFeatures) {
421
417
  * Create a descriptor for a field.
422
418
  */
423
419
  function newField(proto, file, parent, oneof, cart, resolveFeatures) {
424
- (0, assert_js_1.assert)(proto.name, `invalid FieldDescriptorProto: missing name`);
425
- (0, assert_js_1.assert)(proto.number, `invalid FieldDescriptorProto: missing number`);
426
- (0, assert_js_1.assert)(proto.type, `invalid FieldDescriptorProto: missing type`);
420
+ assert(proto.name, `invalid FieldDescriptorProto: missing name`);
421
+ assert(proto.number, `invalid FieldDescriptorProto: missing number`);
422
+ assert(proto.type, `invalid FieldDescriptorProto: missing type`);
427
423
  const common = {
428
424
  proto,
429
425
  deprecated: proto.options?.deprecated ?? false,
@@ -434,7 +430,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
434
430
  optional: isOptionalField(proto, file.syntax),
435
431
  packedByDefault: isPackedFieldByDefault(proto, resolveFeatures),
436
432
  packed: isPackedField(file, parent, proto, resolveFeatures),
437
- jsonName: proto.jsonName === (0, field_js_1.fieldJsonName)(proto.name) ? undefined : proto.jsonName,
433
+ jsonName: proto.jsonName === fieldJsonName(proto.name) ? undefined : proto.jsonName,
438
434
  scalar: undefined,
439
435
  longType: undefined,
440
436
  message: undefined,
@@ -458,14 +454,14 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
458
454
  return resolveFeatures(parent.getFeatures(), proto.options?.features);
459
455
  },
460
456
  };
461
- const repeated = proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REPEATED;
457
+ const repeated = proto.label === FieldDescriptorProto_Label.REPEATED;
462
458
  switch (proto.type) {
463
- case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
464
- case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP: {
465
- (0, assert_js_1.assert)(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
459
+ case FieldDescriptorProto_Type.MESSAGE:
460
+ case FieldDescriptorProto_Type.GROUP: {
461
+ assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
466
462
  const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
467
463
  if (mapEntry !== undefined) {
468
- (0, assert_js_1.assert)(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
464
+ assert(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
469
465
  return {
470
466
  ...common,
471
467
  kind: "field",
@@ -475,7 +471,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
475
471
  };
476
472
  }
477
473
  const message = cart.messages.get(trimLeadingDot(proto.typeName));
478
- (0, assert_js_1.assert)(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
474
+ assert(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
479
475
  return {
480
476
  ...common,
481
477
  kind: "field",
@@ -484,10 +480,10 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
484
480
  message,
485
481
  };
486
482
  }
487
- case descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM: {
488
- (0, assert_js_1.assert)(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
483
+ case FieldDescriptorProto_Type.ENUM: {
484
+ assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
489
485
  const e = cart.enums.get(trimLeadingDot(proto.typeName));
490
- (0, assert_js_1.assert)(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
486
+ assert(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
491
487
  return {
492
488
  ...common,
493
489
  kind: "field",
@@ -499,7 +495,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
499
495
  }
500
496
  default: {
501
497
  const scalar = fieldTypeToScalarType[proto.type];
502
- (0, assert_js_1.assert)(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
498
+ assert(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
503
499
  return {
504
500
  ...common,
505
501
  kind: "field",
@@ -507,9 +503,9 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
507
503
  getDefaultValue,
508
504
  repeated,
509
505
  scalar,
510
- longType: proto.options?.jstype == descriptor_pb_js_1.FieldOptions_JSType.JS_STRING ?
511
- scalar_js_1.LongType.STRING
512
- : scalar_js_1.LongType.BIGINT,
506
+ longType: proto.options?.jstype == FieldOptions_JSType.JS_STRING ?
507
+ LongType.STRING
508
+ : LongType.BIGINT,
513
509
  };
514
510
  }
515
511
  }
@@ -518,11 +514,11 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
518
514
  * Create a descriptor for an extension field.
519
515
  */
520
516
  function newExtension(proto, file, parent, cart, resolveFeatures) {
521
- (0, assert_js_1.assert)(proto.extendee, `invalid FieldDescriptorProto: missing extendee`);
517
+ assert(proto.extendee, `invalid FieldDescriptorProto: missing extendee`);
522
518
  const field = newField(proto, file, null, // to safe us many lines of duplicated code, we trick the type system
523
519
  undefined, cart, resolveFeatures);
524
520
  const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
525
- (0, assert_js_1.assert)(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
521
+ assert(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
526
522
  return {
527
523
  ...field,
528
524
  kind: "extension",
@@ -564,23 +560,23 @@ function parseFileSyntax(syntax, edition) {
564
560
  case "":
565
561
  case "proto2":
566
562
  s = "proto2";
567
- e = descriptor_pb_js_1.Edition.EDITION_PROTO2;
563
+ e = Edition.EDITION_PROTO2;
568
564
  break;
569
565
  case "proto3":
570
566
  s = "proto3";
571
- e = descriptor_pb_js_1.Edition.EDITION_PROTO3;
567
+ e = Edition.EDITION_PROTO3;
572
568
  break;
573
569
  case "editions":
574
570
  s = "editions";
575
571
  switch (edition) {
576
572
  case undefined:
577
- case descriptor_pb_js_1.Edition.EDITION_1_TEST_ONLY:
578
- case descriptor_pb_js_1.Edition.EDITION_2_TEST_ONLY:
579
- case descriptor_pb_js_1.Edition.EDITION_99997_TEST_ONLY:
580
- case descriptor_pb_js_1.Edition.EDITION_99998_TEST_ONLY:
581
- case descriptor_pb_js_1.Edition.EDITION_99999_TEST_ONLY:
582
- case descriptor_pb_js_1.Edition.EDITION_UNKNOWN:
583
- e = descriptor_pb_js_1.Edition.EDITION_UNKNOWN;
573
+ case Edition.EDITION_1_TEST_ONLY:
574
+ case Edition.EDITION_2_TEST_ONLY:
575
+ case Edition.EDITION_99997_TEST_ONLY:
576
+ case Edition.EDITION_99998_TEST_ONLY:
577
+ case Edition.EDITION_99999_TEST_ONLY:
578
+ case Edition.EDITION_UNKNOWN:
579
+ e = Edition.EDITION_UNKNOWN;
584
580
  break;
585
581
  default:
586
582
  e = edition;
@@ -590,7 +586,7 @@ function parseFileSyntax(syntax, edition) {
590
586
  default:
591
587
  throw new Error(`invalid FileDescriptorProto: unsupported syntax: ${syntax}`);
592
588
  }
593
- if (syntax === "editions" && edition === descriptor_pb_js_1.Edition.EDITION_UNKNOWN) {
589
+ if (syntax === "editions" && edition === Edition.EDITION_UNKNOWN) {
594
590
  throw new Error(`invalid FileDescriptorProto: syntax ${syntax} cannot have edition ${String(edition)}`);
595
591
  }
596
592
  return {
@@ -604,7 +600,7 @@ function parseFileSyntax(syntax, edition) {
604
600
  function findFileDependencies(proto, cart) {
605
601
  return (proto.dependency?.map((wantName) => {
606
602
  const dep = cart.files.find((f) => f.proto.name === wantName);
607
- (0, assert_js_1.assert)(dep);
603
+ assert(dep);
608
604
  return dep;
609
605
  }) ?? []);
610
606
  }
@@ -625,7 +621,7 @@ function findFileDependencies(proto, cart) {
625
621
  * - mypackage.MyMessage.extfield
626
622
  */
627
623
  function makeTypeName(proto, parent, file) {
628
- (0, assert_js_1.assert)(proto.name, `invalid proto: missing name`);
624
+ assert(proto.name, `invalid proto: missing name`);
629
625
  let typeName;
630
626
  if (parent) {
631
627
  typeName = `${parent.typeName}.${proto.name}`;
@@ -645,17 +641,17 @@ function trimLeadingDot(typeName) {
645
641
  return typeName.startsWith(".") ? typeName.substring(1) : typeName;
646
642
  }
647
643
  function getMapFieldTypes(mapEntry) {
648
- (0, assert_js_1.assert)(mapEntry.proto.options?.mapEntry, `invalid DescriptorProto: expected ${mapEntry.toString()} to be a map entry`);
649
- (0, assert_js_1.assert)(mapEntry.fields.length === 2, `invalid DescriptorProto: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
644
+ assert(mapEntry.proto.options?.mapEntry, `invalid DescriptorProto: expected ${mapEntry.toString()} to be a map entry`);
645
+ assert(mapEntry.fields.length === 2, `invalid DescriptorProto: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
650
646
  const keyField = mapEntry.fields.find((f) => f.proto.number === 1);
651
- (0, assert_js_1.assert)(keyField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field`);
647
+ assert(keyField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field`);
652
648
  const mapKey = keyField.scalar;
653
- (0, assert_js_1.assert)(mapKey !== undefined &&
654
- mapKey !== scalar_js_1.ScalarType.BYTES &&
655
- mapKey !== scalar_js_1.ScalarType.FLOAT &&
656
- mapKey !== scalar_js_1.ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${keyField.proto.type ?? -1}`);
649
+ assert(mapKey !== undefined &&
650
+ mapKey !== ScalarType.BYTES &&
651
+ mapKey !== ScalarType.FLOAT &&
652
+ mapKey !== ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${keyField.proto.type ?? -1}`);
657
653
  const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
658
- (0, assert_js_1.assert)(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
654
+ assert(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
659
655
  switch (valueField.fieldKind) {
660
656
  case "scalar":
661
657
  return {
@@ -697,7 +693,7 @@ function findOneof(proto, allOneofs) {
697
693
  let oneof;
698
694
  if (proto.proto3Optional) {
699
695
  oneof = allOneofs[oneofIndex];
700
- (0, assert_js_1.assert)(oneof, `invalid FieldDescriptorProto: oneof #${oneofIndex} for field #${proto.number ?? -1} not found`);
696
+ assert(oneof, `invalid FieldDescriptorProto: oneof #${oneofIndex} for field #${proto.number ?? -1} not found`);
701
697
  }
702
698
  return oneof;
703
699
  }
@@ -709,7 +705,7 @@ function isOptionalField(proto, syntax) {
709
705
  switch (syntax) {
710
706
  case "proto2":
711
707
  return (proto.oneofIndex === undefined &&
712
- proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.OPTIONAL);
708
+ proto.label === FieldDescriptorProto_Label.OPTIONAL);
713
709
  case "proto3":
714
710
  return proto.proto3Optional === true;
715
711
  case "editions":
@@ -726,7 +722,7 @@ function isOptionalField(proto, syntax) {
726
722
  */
727
723
  function isPackedFieldByDefault(proto, resolveFeatures) {
728
724
  const { repeatedFieldEncoding } = resolveFeatures();
729
- if (repeatedFieldEncoding != descriptor_pb_js_1.FeatureSet_RepeatedFieldEncoding.PACKED) {
725
+ if (repeatedFieldEncoding != FeatureSet_RepeatedFieldEncoding.PACKED) {
730
726
  return false;
731
727
  }
732
728
  // From the proto3 language guide:
@@ -735,10 +731,10 @@ function isPackedFieldByDefault(proto, resolveFeatures) {
735
731
  // and ENUM are packed by default as well. This means only STRING and BYTES
736
732
  // are not packed by default, which makes sense because they are length-delimited.
737
733
  switch (proto.type) {
738
- case descriptor_pb_js_1.FieldDescriptorProto_Type.STRING:
739
- case descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES:
740
- case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP:
741
- case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
734
+ case FieldDescriptorProto_Type.STRING:
735
+ case FieldDescriptorProto_Type.BYTES:
736
+ case FieldDescriptorProto_Type.GROUP:
737
+ case FieldDescriptorProto_Type.MESSAGE:
742
738
  return false;
743
739
  default:
744
740
  return true;
@@ -752,21 +748,21 @@ function isPackedFieldByDefault(proto, resolveFeatures) {
752
748
  */
753
749
  function isPackedField(file, parent, proto, resolveFeatures) {
754
750
  switch (proto.type) {
755
- case descriptor_pb_js_1.FieldDescriptorProto_Type.STRING:
756
- case descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES:
757
- case descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP:
758
- case descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE:
751
+ case FieldDescriptorProto_Type.STRING:
752
+ case FieldDescriptorProto_Type.BYTES:
753
+ case FieldDescriptorProto_Type.GROUP:
754
+ case FieldDescriptorProto_Type.MESSAGE:
759
755
  // length-delimited types cannot be packed
760
756
  return false;
761
757
  default:
762
758
  switch (file.edition) {
763
- case descriptor_pb_js_1.Edition.EDITION_PROTO2:
759
+ case Edition.EDITION_PROTO2:
764
760
  return proto.options?.packed ?? false;
765
- case descriptor_pb_js_1.Edition.EDITION_PROTO3:
761
+ case Edition.EDITION_PROTO3:
766
762
  return proto.options?.packed ?? true;
767
763
  default: {
768
764
  const { repeatedFieldEncoding } = resolveFeatures(parent?.getFeatures() ?? file.getFeatures(), proto.options?.features);
769
- return (repeatedFieldEncoding == descriptor_pb_js_1.FeatureSet_RepeatedFieldEncoding.PACKED);
765
+ return (repeatedFieldEncoding == FeatureSet_RepeatedFieldEncoding.PACKED);
770
766
  }
771
767
  }
772
768
  }
@@ -776,24 +772,24 @@ function isPackedField(file, parent, proto, resolveFeatures) {
776
772
  * subset of field types declared by protobuf enum google.protobuf.FieldDescriptorProto.
777
773
  */
778
774
  const fieldTypeToScalarType = {
779
- [descriptor_pb_js_1.FieldDescriptorProto_Type.DOUBLE]: scalar_js_1.ScalarType.DOUBLE,
780
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FLOAT]: scalar_js_1.ScalarType.FLOAT,
781
- [descriptor_pb_js_1.FieldDescriptorProto_Type.INT64]: scalar_js_1.ScalarType.INT64,
782
- [descriptor_pb_js_1.FieldDescriptorProto_Type.UINT64]: scalar_js_1.ScalarType.UINT64,
783
- [descriptor_pb_js_1.FieldDescriptorProto_Type.INT32]: scalar_js_1.ScalarType.INT32,
784
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED64]: scalar_js_1.ScalarType.FIXED64,
785
- [descriptor_pb_js_1.FieldDescriptorProto_Type.FIXED32]: scalar_js_1.ScalarType.FIXED32,
786
- [descriptor_pb_js_1.FieldDescriptorProto_Type.BOOL]: scalar_js_1.ScalarType.BOOL,
787
- [descriptor_pb_js_1.FieldDescriptorProto_Type.STRING]: scalar_js_1.ScalarType.STRING,
788
- [descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP]: undefined,
789
- [descriptor_pb_js_1.FieldDescriptorProto_Type.MESSAGE]: undefined,
790
- [descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES]: scalar_js_1.ScalarType.BYTES,
791
- [descriptor_pb_js_1.FieldDescriptorProto_Type.UINT32]: scalar_js_1.ScalarType.UINT32,
792
- [descriptor_pb_js_1.FieldDescriptorProto_Type.ENUM]: undefined,
793
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED32]: scalar_js_1.ScalarType.SFIXED32,
794
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SFIXED64]: scalar_js_1.ScalarType.SFIXED64,
795
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SINT32]: scalar_js_1.ScalarType.SINT32,
796
- [descriptor_pb_js_1.FieldDescriptorProto_Type.SINT64]: scalar_js_1.ScalarType.SINT64,
775
+ [FieldDescriptorProto_Type.DOUBLE]: ScalarType.DOUBLE,
776
+ [FieldDescriptorProto_Type.FLOAT]: ScalarType.FLOAT,
777
+ [FieldDescriptorProto_Type.INT64]: ScalarType.INT64,
778
+ [FieldDescriptorProto_Type.UINT64]: ScalarType.UINT64,
779
+ [FieldDescriptorProto_Type.INT32]: ScalarType.INT32,
780
+ [FieldDescriptorProto_Type.FIXED64]: ScalarType.FIXED64,
781
+ [FieldDescriptorProto_Type.FIXED32]: ScalarType.FIXED32,
782
+ [FieldDescriptorProto_Type.BOOL]: ScalarType.BOOL,
783
+ [FieldDescriptorProto_Type.STRING]: ScalarType.STRING,
784
+ [FieldDescriptorProto_Type.GROUP]: undefined,
785
+ [FieldDescriptorProto_Type.MESSAGE]: undefined,
786
+ [FieldDescriptorProto_Type.BYTES]: ScalarType.BYTES,
787
+ [FieldDescriptorProto_Type.UINT32]: ScalarType.UINT32,
788
+ [FieldDescriptorProto_Type.ENUM]: undefined,
789
+ [FieldDescriptorProto_Type.SFIXED32]: ScalarType.SFIXED32,
790
+ [FieldDescriptorProto_Type.SFIXED64]: ScalarType.SFIXED64,
791
+ [FieldDescriptorProto_Type.SINT32]: ScalarType.SINT32,
792
+ [FieldDescriptorProto_Type.SINT64]: ScalarType.SINT64,
797
793
  };
798
794
  /**
799
795
  * Find comments.
@@ -858,13 +854,13 @@ function declarationString() {
858
854
  }
859
855
  const file = this.kind === "extension" ? this.file : this.parent.file;
860
856
  if (file.syntax == "proto2" &&
861
- this.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED) {
857
+ this.proto.label === FieldDescriptorProto_Label.REQUIRED) {
862
858
  parts.push("required");
863
859
  }
864
860
  let type;
865
861
  switch (this.fieldKind) {
866
862
  case "scalar":
867
- type = scalar_js_1.ScalarType[this.scalar].toLowerCase();
863
+ type = ScalarType[this.scalar].toLowerCase();
868
864
  break;
869
865
  case "enum":
870
866
  type = this.enum.typeName;
@@ -873,11 +869,11 @@ function declarationString() {
873
869
  type = this.message.typeName;
874
870
  break;
875
871
  case "map": {
876
- const k = scalar_js_1.ScalarType[this.mapKey].toLowerCase();
872
+ const k = ScalarType[this.mapKey].toLowerCase();
877
873
  let v;
878
874
  switch (this.mapValue.kind) {
879
875
  case "scalar":
880
- v = scalar_js_1.ScalarType[this.mapValue.scalar].toLowerCase();
876
+ v = ScalarType[this.mapValue.scalar].toLowerCase();
881
877
  break;
882
878
  case "enum":
883
879
  v = this.mapValue.enum.typeName;
@@ -897,8 +893,8 @@ function declarationString() {
897
893
  }
898
894
  let defaultValue = this.proto.defaultValue;
899
895
  if (defaultValue !== undefined) {
900
- if (this.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.BYTES ||
901
- this.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.STRING) {
896
+ if (this.proto.type == FieldDescriptorProto_Type.BYTES ||
897
+ this.proto.type == FieldDescriptorProto_Type.STRING) {
902
898
  defaultValue = '"' + defaultValue.replace('"', '\\"') + '"';
903
899
  }
904
900
  options.push(`default = ${defaultValue}`);
@@ -907,7 +903,7 @@ function declarationString() {
907
903
  options.push(`json_name = "${this.jsonName}"`);
908
904
  }
909
905
  if (this.proto.options?.jstype !== undefined) {
910
- options.push(`jstype = ${descriptor_pb_js_1.FieldOptions_JSType[this.proto.options.jstype]}`);
906
+ options.push(`jstype = ${FieldOptions_JSType[this.proto.options.jstype]}`);
911
907
  }
912
908
  if (this.proto.options?.deprecated === true) {
913
909
  options.push(`deprecated = true`);
@@ -927,9 +923,9 @@ function getDefaultValue() {
927
923
  }
928
924
  switch (this.fieldKind) {
929
925
  case "enum":
930
- return (0, text_format_js_1.parseTextFormatEnumValue)(this.enum, d);
926
+ return parseTextFormatEnumValue(this.enum, d);
931
927
  case "scalar":
932
- return (0, text_format_js_1.parseTextFormatScalarValue)(this.scalar, d);
928
+ return parseTextFormatScalarValue(this.scalar, d);
933
929
  default:
934
930
  return undefined;
935
931
  }
@@ -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 {};
package/dist/enum.js CHANGED
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEnumType = exports.normalizeEnumValue = void 0;
4
- function normalizeEnumValue(value) {
1
+ export function normalizeEnumValue(value) {
5
2
  if ("localName" in value) {
6
3
  return value;
7
4
  }
8
5
  return { ...value, localName: value.name };
9
6
  }
10
- exports.normalizeEnumValue = normalizeEnumValue;
11
7
  /**
12
8
  * Create a new EnumType with the given values.
13
9
  */
14
- function createEnumType(typeName, values,
10
+ export function createEnumType(typeName, values,
15
11
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
12
  _opt) {
17
13
  const names = Object.create(null);
@@ -38,4 +34,3 @@ _opt) {
38
34
  },
39
35
  };
40
36
  }
41
- exports.createEnumType = createEnumType;