@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.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 (127) hide show
  1. package/README.md +21 -1
  2. package/dist/cjs/binary-encoding.js +402 -410
  3. package/dist/cjs/descriptor-registry.js +407 -449
  4. package/dist/cjs/descriptor-set.js +416 -513
  5. package/dist/cjs/field.js +30 -30
  6. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  7. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  8. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  9. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  10. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  11. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  12. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  13. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  14. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  15. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  16. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  17. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  18. package/dist/cjs/index.js +24 -122
  19. package/dist/cjs/message.js +81 -89
  20. package/dist/cjs/private/assert.js +20 -26
  21. package/dist/cjs/private/base64.js +79 -78
  22. package/dist/cjs/private/binary-format-common.js +195 -208
  23. package/dist/cjs/private/binary-format-proto2.js +75 -109
  24. package/dist/cjs/private/binary-format-proto3.js +57 -90
  25. package/dist/cjs/private/enum.js +38 -43
  26. package/dist/cjs/private/field-list.js +51 -50
  27. package/dist/cjs/private/field-wrapper.js +8 -10
  28. package/dist/cjs/private/field.js +22 -25
  29. package/dist/cjs/private/goog-varint.js +275 -0
  30. package/dist/cjs/private/json-format-common.js +414 -440
  31. package/dist/cjs/private/json-format-proto2.js +78 -89
  32. package/dist/cjs/private/json-format-proto3.js +69 -93
  33. package/dist/cjs/private/message-type.js +26 -27
  34. package/dist/cjs/private/names.js +58 -62
  35. package/dist/cjs/private/proto-runtime.js +11 -16
  36. package/dist/cjs/private/scalars.js +100 -103
  37. package/dist/cjs/private/util-common.js +180 -210
  38. package/dist/cjs/proto-int64.js +111 -112
  39. package/dist/cjs/proto2.js +50 -63
  40. package/dist/cjs/proto3.js +61 -74
  41. package/dist/cjs/service-type.js +14 -17
  42. package/dist/cjs/type-registry.js +33 -31
  43. package/dist/esm/binary-encoding.js +401 -414
  44. package/dist/esm/descriptor-registry.js +409 -458
  45. package/dist/esm/descriptor-set.js +417 -478
  46. package/dist/esm/field.js +29 -29
  47. package/dist/esm/google/protobuf/any_pb.js +122 -140
  48. package/dist/esm/google/protobuf/api_pb.js +177 -197
  49. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  50. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  51. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  52. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  53. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  54. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  55. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  56. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  57. package/dist/esm/google/protobuf/type_pb.js +401 -421
  58. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  59. package/dist/esm/index.js +1 -1
  60. package/dist/esm/message.js +81 -89
  61. package/dist/esm/private/assert.js +19 -21
  62. package/dist/esm/private/base64.js +79 -78
  63. package/dist/esm/private/binary-format-common.js +196 -207
  64. package/dist/esm/private/binary-format-proto2.js +76 -81
  65. package/dist/esm/private/binary-format-proto3.js +58 -67
  66. package/dist/esm/private/enum.js +38 -43
  67. package/dist/esm/private/field-list.js +51 -50
  68. package/dist/esm/private/field-wrapper.js +8 -10
  69. package/dist/esm/private/field.js +22 -22
  70. package/dist/esm/private/goog-varint.js +266 -0
  71. package/dist/esm/private/json-format-common.js +414 -435
  72. package/dist/esm/private/json-format-proto2.js +76 -81
  73. package/dist/esm/private/json-format-proto3.js +66 -80
  74. package/dist/esm/private/message-type.js +27 -28
  75. package/dist/esm/private/names.js +57 -57
  76. package/dist/esm/private/proto-runtime.js +11 -11
  77. package/dist/esm/private/scalars.js +99 -99
  78. package/dist/esm/private/util-common.js +180 -192
  79. package/dist/esm/proto-int64.js +111 -112
  80. package/dist/esm/proto2.js +50 -57
  81. package/dist/esm/proto3.js +61 -68
  82. package/dist/esm/service-type.js +12 -12
  83. package/dist/esm/type-registry.js +33 -31
  84. package/dist/types/binary-encoding.d.ts +398 -398
  85. package/dist/types/binary-format.d.ts +69 -91
  86. package/dist/types/descriptor-registry.d.ts +23 -29
  87. package/dist/types/descriptor-set.d.ts +107 -128
  88. package/dist/types/enum.d.ts +21 -21
  89. package/dist/types/field-list.d.ts +21 -21
  90. package/dist/types/field.d.ts +191 -231
  91. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  92. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  93. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  94. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  95. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  96. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  97. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  98. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  99. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  100. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  101. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  102. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  103. package/dist/types/index.d.ts +4 -27
  104. package/dist/types/json-format.d.ts +70 -89
  105. package/dist/types/message-type.d.ts +38 -46
  106. package/dist/types/message.d.ts +73 -99
  107. package/dist/types/private/assert.d.ts +1 -4
  108. package/dist/types/private/binary-format-common.d.ts +6 -32
  109. package/dist/types/private/enum.d.ts +4 -11
  110. package/dist/types/private/field-list.d.ts +14 -21
  111. package/dist/types/private/field-wrapper.d.ts +5 -11
  112. package/dist/types/private/field.d.ts +12 -12
  113. package/dist/types/{google/varint.d.ts → private/goog-varint.d.ts} +6 -13
  114. package/dist/types/private/json-format-common.d.ts +5 -27
  115. package/dist/types/private/message-type.d.ts +3 -8
  116. package/dist/types/private/names.d.ts +1 -4
  117. package/dist/types/private/options-map.d.ts +1 -1
  118. package/dist/types/private/proto-runtime.d.ts +29 -42
  119. package/dist/types/private/scalars.d.ts +5 -12
  120. package/dist/types/private/util-common.d.ts +1 -4
  121. package/dist/types/private/util.d.ts +29 -41
  122. package/dist/types/proto-int64.d.ts +42 -42
  123. package/dist/types/service-type.d.ts +37 -57
  124. package/dist/types/type-registry.d.ts +13 -15
  125. package/package.json +2 -2
  126. package/dist/cjs/google/varint.js +0 -280
  127. package/dist/esm/google/varint.js +0 -265
@@ -1,121 +1,120 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.protoInt64 = void 0;
4
- const varint_js_1 = require("./google/varint.js");
4
+ const goog_varint_js_1 = require("./private/goog-varint.js");
5
5
  function makeInt64Support() {
6
- const dv = new DataView(new ArrayBuffer(8));
7
- // note that Safari 14 implements BigInt, but not the DataView methods
8
- const ok =
9
- globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
10
- typeof dv.getBigInt64 === "function" &&
11
- typeof dv.getBigUint64 === "function" &&
12
- typeof dv.setBigInt64 === "function" &&
13
- typeof dv.setBigUint64 === "function";
14
- if (ok) {
15
- const MIN = BigInt("-9223372036854775808"),
16
- MAX = BigInt("9223372036854775807"),
17
- UMIN = BigInt("0"),
18
- UMAX = BigInt("18446744073709551615");
19
- return {
20
- zero: BigInt(0),
21
- supported: true,
22
- parse(value) {
23
- const bi = typeof value == "bigint" ? value : BigInt(value);
24
- if (bi > MAX || bi < MIN) {
25
- throw new Error(`int64 invalid: ${value}`);
26
- }
27
- return bi;
28
- },
29
- uParse(value) {
30
- const bi = typeof value == "bigint" ? value : BigInt(value);
31
- if (bi > UMAX || bi < UMIN) {
32
- throw new Error(`uint64 invalid: ${value}`);
33
- }
34
- return bi;
35
- },
36
- enc(value) {
37
- dv.setBigInt64(0, this.parse(value), true);
38
- return {
39
- lo: dv.getInt32(0, true),
40
- hi: dv.getInt32(4, true),
41
- };
42
- },
43
- uEnc(value) {
44
- dv.setBigInt64(0, this.uParse(value), true);
6
+ const dv = new DataView(new ArrayBuffer(8));
7
+ // note that Safari 14 implements BigInt, but not the DataView methods
8
+ const ok = globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
9
+ typeof dv.getBigInt64 === "function" &&
10
+ typeof dv.getBigUint64 === "function" &&
11
+ typeof dv.setBigInt64 === "function" &&
12
+ typeof dv.setBigUint64 === "function";
13
+ if (ok) {
14
+ const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
45
15
  return {
46
- lo: dv.getInt32(0, true),
47
- hi: dv.getInt32(4, true),
16
+ zero: BigInt(0),
17
+ supported: true,
18
+ parse(value) {
19
+ const bi = typeof value == "bigint" ? value : BigInt(value);
20
+ if (bi > MAX || bi < MIN) {
21
+ throw new Error(`int64 invalid: ${value}`);
22
+ }
23
+ return bi;
24
+ },
25
+ uParse(value) {
26
+ const bi = typeof value == "bigint" ? value : BigInt(value);
27
+ if (bi > UMAX || bi < UMIN) {
28
+ throw new Error(`uint64 invalid: ${value}`);
29
+ }
30
+ return bi;
31
+ },
32
+ enc(value) {
33
+ dv.setBigInt64(0, this.parse(value), true);
34
+ return {
35
+ lo: dv.getInt32(0, true),
36
+ hi: dv.getInt32(4, true),
37
+ };
38
+ },
39
+ uEnc(value) {
40
+ dv.setBigInt64(0, this.uParse(value), true);
41
+ return {
42
+ lo: dv.getInt32(0, true),
43
+ hi: dv.getInt32(4, true),
44
+ };
45
+ },
46
+ dec(lo, hi) {
47
+ dv.setInt32(0, lo, true);
48
+ dv.setInt32(4, hi, true);
49
+ return dv.getBigInt64(0, true);
50
+ },
51
+ uDec(lo, hi) {
52
+ dv.setInt32(0, lo, true);
53
+ dv.setInt32(4, hi, true);
54
+ return dv.getBigUint64(0, true);
55
+ },
48
56
  };
49
- },
50
- dec(lo, hi) {
51
- dv.setInt32(0, lo, true);
52
- dv.setInt32(4, hi, true);
53
- return dv.getBigInt64(0, true);
54
- },
55
- uDec(lo, hi) {
56
- dv.setInt32(0, lo, true);
57
- dv.setInt32(4, hi, true);
58
- return dv.getBigUint64(0, true);
59
- },
57
+ }
58
+ return {
59
+ zero: "0",
60
+ supported: false,
61
+ parse(value) {
62
+ if (!/^-?[0-9]+$/.test(value)) {
63
+ throw new Error(`int64 invalid: ${value}`);
64
+ }
65
+ return value;
66
+ },
67
+ uParse(value) {
68
+ if (!/^-?[0-9]+$/.test(value)) {
69
+ throw new Error(`uint64 invalid: ${value}`);
70
+ }
71
+ return value;
72
+ },
73
+ enc(value) {
74
+ if (typeof value == "string") {
75
+ if (!/^-?[0-9]+$/.test(value)) {
76
+ throw new Error(`int64 invalid: ${value}`);
77
+ }
78
+ }
79
+ else {
80
+ value = value.toString(10);
81
+ }
82
+ const [, lo, hi] = (0, goog_varint_js_1.int64fromString)(value);
83
+ return { lo, hi };
84
+ },
85
+ uEnc(value) {
86
+ if (typeof value == "string") {
87
+ if (!/^-?[0-9]+$/.test(value)) {
88
+ throw new Error(`uint64 invalid: ${value}`);
89
+ }
90
+ }
91
+ else {
92
+ value = value.toString(10);
93
+ }
94
+ const [minus, lo, hi] = (0, goog_varint_js_1.int64fromString)(value);
95
+ if (minus) {
96
+ throw new Error(`uint64 invalid: ${value}`);
97
+ }
98
+ return { lo, hi };
99
+ },
100
+ dec(lo, hi) {
101
+ const minus = (hi & 0x80000000) !== 0;
102
+ if (minus) {
103
+ // negate
104
+ hi = ~hi;
105
+ if (lo) {
106
+ lo = ~lo + 1;
107
+ }
108
+ else {
109
+ hi += 1;
110
+ }
111
+ return ("-" + (0, goog_varint_js_1.int64toString)(lo, hi));
112
+ }
113
+ return (0, goog_varint_js_1.int64toString)(lo, hi);
114
+ },
115
+ uDec(lo, hi) {
116
+ return (0, goog_varint_js_1.int64toString)(lo, hi);
117
+ },
60
118
  };
61
- }
62
- return {
63
- zero: "0",
64
- supported: false,
65
- parse(value) {
66
- if (!/^-?[0-9]+$/.test(value)) {
67
- throw new Error(`int64 invalid: ${value}`);
68
- }
69
- return value;
70
- },
71
- uParse(value) {
72
- if (!/^-?[0-9]+$/.test(value)) {
73
- throw new Error(`uint64 invalid: ${value}`);
74
- }
75
- return value;
76
- },
77
- enc(value) {
78
- if (typeof value == "string") {
79
- if (!/^-?[0-9]+$/.test(value)) {
80
- throw new Error(`int64 invalid: ${value}`);
81
- }
82
- } else {
83
- value = value.toString(10);
84
- }
85
- const [, lo, hi] = (0, varint_js_1.int64fromString)(value);
86
- return { lo, hi };
87
- },
88
- uEnc(value) {
89
- if (typeof value == "string") {
90
- if (!/^-?[0-9]+$/.test(value)) {
91
- throw new Error(`uint64 invalid: ${value}`);
92
- }
93
- } else {
94
- value = value.toString(10);
95
- }
96
- const [minus, lo, hi] = (0, varint_js_1.int64fromString)(value);
97
- if (minus) {
98
- throw new Error(`uint64 invalid: ${value}`);
99
- }
100
- return { lo, hi };
101
- },
102
- dec(lo, hi) {
103
- const minus = (hi & 0x80000000) !== 0;
104
- if (minus) {
105
- // negate
106
- hi = ~hi;
107
- if (lo) {
108
- lo = ~lo + 1;
109
- } else {
110
- hi += 1;
111
- }
112
- return "-" + (0, varint_js_1.int64toString)(lo, hi);
113
- }
114
- return (0, varint_js_1.int64toString)(lo, hi);
115
- },
116
- uDec(lo, hi) {
117
- return (0, varint_js_1.int64toString)(lo, hi);
118
- },
119
- };
120
119
  }
121
120
  exports.protoInt64 = makeInt64Support();
@@ -11,76 +11,63 @@ const json_format_proto2_js_1 = require("./private/json-format-proto2.js");
11
11
  /**
12
12
  * Provides functionality for messages defined with the proto2 syntax.
13
13
  */
14
- exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)(
15
- "proto2",
16
- (0, json_format_proto2_js_1.makeJsonFormatProto2)(),
17
- (0, binary_format_proto2_js_1.makeBinaryFormatProto2)(),
18
- {
14
+ exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (0, json_format_proto2_js_1.makeJsonFormatProto2)(), (0, binary_format_proto2_js_1.makeBinaryFormatProto2)(), {
19
15
  ...(0, util_common_js_1.makeUtilCommon)(),
20
16
  newFieldList(fields) {
21
- return new field_list_js_1.InternalFieldList(
22
- fields,
23
- normalizeFieldInfosProto2
24
- );
17
+ return new field_list_js_1.InternalFieldList(fields, normalizeFieldInfosProto2);
25
18
  },
26
19
  initFields(target) {
27
- for (const member of target.getType().fields.byMember()) {
28
- const name = member.localName,
29
- t = target;
30
- if (member.repeated) {
31
- t[name] = [];
32
- continue;
20
+ for (const member of target.getType().fields.byMember()) {
21
+ const name = member.localName, t = target;
22
+ if (member.repeated) {
23
+ t[name] = [];
24
+ continue;
25
+ }
26
+ switch (member.kind) {
27
+ case "oneof":
28
+ t[name] = { case: undefined };
29
+ break;
30
+ case "map":
31
+ t[name] = {};
32
+ break;
33
+ case "scalar":
34
+ case "enum":
35
+ case "message":
36
+ // In contrast to proto3, enum and scalar fields have no intrinsic default value,
37
+ // only an optional explicit default value.
38
+ // Unlike proto3 intrinsic default values, proto2 explicit default values are not
39
+ // set on construction, because they are not omitted on the wire. If we did set
40
+ // default values on construction, a deserialize-serialize round-trip would add
41
+ // fields to a message.
42
+ break;
43
+ }
33
44
  }
34
- switch (member.kind) {
35
- case "oneof":
36
- t[name] = { case: undefined };
37
- break;
38
- case "map":
39
- t[name] = {};
40
- break;
41
- case "scalar":
42
- case "enum":
43
- case "message":
44
- // In contrast to proto3, enum and scalar fields have no intrinsic default value,
45
- // only an optional explicit default value.
46
- // Unlike proto3 intrinsic default values, proto2 explicit default values are not
47
- // set on construction, because they are not omitted on the wire. If we did set
48
- // default values on construction, a deserialize-serialize round-trip would add
49
- // fields to a message.
50
- break;
51
- }
52
- }
53
45
  },
54
- }
55
- );
46
+ });
56
47
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
57
48
  function normalizeFieldInfosProto2(fieldInfos) {
58
- const r = [];
59
- let o;
60
- for (const field of typeof fieldInfos == "function"
61
- ? fieldInfos()
62
- : fieldInfos) {
63
- const f = field;
64
- f.localName = (0, names_js_1.makeFieldName)(
65
- field.name,
66
- field.oneof !== undefined
67
- );
68
- f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
69
- f.repeated = field.repeated ?? false;
70
- // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
71
- f.packed = field.packed ?? false;
72
- // We do not surface options at this time
73
- // f.options = field.options ?? emptyReadonlyObject;
74
- if (field.oneof !== undefined) {
75
- const ooname =
76
- typeof field.oneof == "string" ? field.oneof : field.oneof.name;
77
- if (!o || o.name != ooname) {
78
- o = new field_js_1.InternalOneofInfo(ooname);
79
- }
80
- f.oneof = o;
81
- o.addField(f);
49
+ const r = [];
50
+ let o;
51
+ for (const field of typeof fieldInfos == "function"
52
+ ? fieldInfos()
53
+ : fieldInfos) {
54
+ const f = field;
55
+ f.localName = (0, names_js_1.makeFieldName)(field.name, field.oneof !== undefined);
56
+ f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
57
+ f.repeated = field.repeated ?? false;
58
+ // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
59
+ f.packed = field.packed ?? false;
60
+ // We do not surface options at this time
61
+ // f.options = field.options ?? emptyReadonlyObject;
62
+ if (field.oneof !== undefined) {
63
+ const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
64
+ if (!o || o.name != ooname) {
65
+ o = new field_js_1.InternalOneofInfo(ooname);
66
+ }
67
+ f.oneof = o;
68
+ o.addField(f);
69
+ }
70
+ r.push(f);
82
71
  }
83
- r.push(f);
84
- }
85
- return r;
72
+ return r;
86
73
  }
@@ -13,87 +13,74 @@ const names_js_1 = require("./private/names.js");
13
13
  /**
14
14
  * Provides functionality for messages defined with the proto3 syntax.
15
15
  */
16
- exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)(
17
- "proto3",
18
- (0, json_format_proto3_js_1.makeJsonFormatProto3)(),
19
- (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(),
20
- {
16
+ exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_format_proto3_js_1.makeJsonFormatProto3)(), (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(), {
21
17
  ...(0, util_common_js_1.makeUtilCommon)(),
22
18
  newFieldList(fields) {
23
- return new field_list_js_1.InternalFieldList(
24
- fields,
25
- normalizeFieldInfosProto3
26
- );
19
+ return new field_list_js_1.InternalFieldList(fields, normalizeFieldInfosProto3);
27
20
  },
28
21
  initFields(target) {
29
- for (const member of target.getType().fields.byMember()) {
30
- if (member.opt) {
31
- continue;
22
+ for (const member of target.getType().fields.byMember()) {
23
+ if (member.opt) {
24
+ continue;
25
+ }
26
+ const name = member.localName, t = target;
27
+ if (member.repeated) {
28
+ t[name] = [];
29
+ continue;
30
+ }
31
+ switch (member.kind) {
32
+ case "oneof":
33
+ t[name] = { case: undefined };
34
+ break;
35
+ case "enum":
36
+ t[name] = 0;
37
+ break;
38
+ case "map":
39
+ t[name] = {};
40
+ break;
41
+ case "scalar":
42
+ t[name] = (0, scalars_js_1.scalarDefaultValue)(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
43
+ break;
44
+ case "message":
45
+ // message fields are always optional in proto3
46
+ break;
47
+ }
32
48
  }
33
- const name = member.localName,
34
- t = target;
35
- if (member.repeated) {
36
- t[name] = [];
37
- continue;
38
- }
39
- switch (member.kind) {
40
- case "oneof":
41
- t[name] = { case: undefined };
42
- break;
43
- case "enum":
44
- t[name] = 0;
45
- break;
46
- case "map":
47
- t[name] = {};
48
- break;
49
- case "scalar":
50
- t[name] = (0, scalars_js_1.scalarDefaultValue)(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
51
- break;
52
- case "message":
53
- // message fields are always optional in proto3
54
- break;
55
- }
56
- }
57
49
  },
58
- }
59
- );
50
+ });
60
51
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
61
52
  function normalizeFieldInfosProto3(fieldInfos) {
62
- const r = [];
63
- let o;
64
- for (const field of typeof fieldInfos == "function"
65
- ? fieldInfos()
66
- : fieldInfos) {
67
- const f = field;
68
- f.localName = (0, names_js_1.makeFieldName)(
69
- field.name,
70
- field.oneof !== undefined
71
- );
72
- f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
73
- f.repeated = field.repeated ?? false;
74
- // From the proto3 language guide:
75
- // > In proto3, repeated fields of scalar numeric types are packed by default.
76
- // This information is incomplete - according to the conformance tests, BOOL
77
- // and ENUM are packed by default as well. This means only STRING and BYTES
78
- // are not packed by default, which makes sense because they are length-delimited.
79
- f.packed =
80
- field.packed ??
81
- (field.kind == "enum" ||
82
- (field.kind == "scalar" &&
83
- field.T != field_js_1.ScalarType.BYTES &&
84
- field.T != field_js_1.ScalarType.STRING));
85
- // We do not surface options at this time
86
- // f.options = field.options ?? emptyReadonlyObject;
87
- if (field.oneof !== undefined) {
88
- const ooname =
89
- typeof field.oneof == "string" ? field.oneof : field.oneof.name;
90
- if (!o || o.name != ooname) {
91
- o = new field_js_2.InternalOneofInfo(ooname);
92
- }
93
- f.oneof = o;
94
- o.addField(f);
53
+ const r = [];
54
+ let o;
55
+ for (const field of typeof fieldInfos == "function"
56
+ ? fieldInfos()
57
+ : fieldInfos) {
58
+ const f = field;
59
+ f.localName = (0, names_js_1.makeFieldName)(field.name, field.oneof !== undefined);
60
+ f.jsonName = field.jsonName ?? (0, names_js_1.makeJsonName)(field.name);
61
+ f.repeated = field.repeated ?? false;
62
+ // From the proto3 language guide:
63
+ // > In proto3, repeated fields of scalar numeric types are packed by default.
64
+ // This information is incomplete - according to the conformance tests, BOOL
65
+ // and ENUM are packed by default as well. This means only STRING and BYTES
66
+ // are not packed by default, which makes sense because they are length-delimited.
67
+ f.packed =
68
+ field.packed ??
69
+ (field.kind == "enum" ||
70
+ (field.kind == "scalar" &&
71
+ field.T != field_js_1.ScalarType.BYTES &&
72
+ field.T != field_js_1.ScalarType.STRING));
73
+ // We do not surface options at this time
74
+ // f.options = field.options ?? emptyReadonlyObject;
75
+ if (field.oneof !== undefined) {
76
+ const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
77
+ if (!o || o.name != ooname) {
78
+ o = new field_js_2.InternalOneofInfo(ooname);
79
+ }
80
+ f.oneof = o;
81
+ o.addField(f);
82
+ }
83
+ r.push(f);
95
84
  }
96
- r.push(f);
97
- }
98
- return r;
85
+ return r;
99
86
  }
@@ -12,11 +12,11 @@ exports.MethodIdempotency = exports.MethodKind = void 0;
12
12
  */
13
13
  var MethodKind;
14
14
  (function (MethodKind) {
15
- MethodKind[(MethodKind["Unary"] = 0)] = "Unary";
16
- MethodKind[(MethodKind["ServerStreaming"] = 1)] = "ServerStreaming";
17
- MethodKind[(MethodKind["ClientStreaming"] = 2)] = "ClientStreaming";
18
- MethodKind[(MethodKind["BiDiStreaming"] = 3)] = "BiDiStreaming";
19
- })((MethodKind = exports.MethodKind || (exports.MethodKind = {})));
15
+ MethodKind[MethodKind["Unary"] = 0] = "Unary";
16
+ MethodKind[MethodKind["ServerStreaming"] = 1] = "ServerStreaming";
17
+ MethodKind[MethodKind["ClientStreaming"] = 2] = "ClientStreaming";
18
+ MethodKind[MethodKind["BiDiStreaming"] = 3] = "BiDiStreaming";
19
+ })(MethodKind = exports.MethodKind || (exports.MethodKind = {}));
20
20
  /**
21
21
  * Is this method side-effect-free (or safe in HTTP parlance), or just
22
22
  * idempotent, or neither? HTTP based RPC implementation may choose GET verb
@@ -29,15 +29,12 @@ var MethodKind;
29
29
  */
30
30
  var MethodIdempotency;
31
31
  (function (MethodIdempotency) {
32
- /**
33
- * Idempotent, no side effects.
34
- */
35
- MethodIdempotency[(MethodIdempotency["NoSideEffects"] = 1)] = "NoSideEffects";
36
- /**
37
- * Idempotent, but may have side effects.
38
- */
39
- MethodIdempotency[(MethodIdempotency["Idempotent"] = 2)] = "Idempotent";
40
- })(
41
- (MethodIdempotency =
42
- exports.MethodIdempotency || (exports.MethodIdempotency = {}))
43
- );
32
+ /**
33
+ * Idempotent, no side effects.
34
+ */
35
+ MethodIdempotency[MethodIdempotency["NoSideEffects"] = 1] = "NoSideEffects";
36
+ /**
37
+ * Idempotent, but may have side effects.
38
+ */
39
+ MethodIdempotency[MethodIdempotency["Idempotent"] = 2] = "Idempotent";
40
+ })(MethodIdempotency = exports.MethodIdempotency || (exports.MethodIdempotency = {}));
@@ -5,38 +5,40 @@ exports.TypeRegistry = void 0;
5
5
  * TypeRegistry is a basic type registry
6
6
  */
7
7
  class TypeRegistry {
8
- constructor() {
9
- this.messages = {};
10
- this.enums = {};
11
- this.services = {};
12
- }
13
- findMessage(typeName) {
14
- return this.messages[typeName];
15
- }
16
- findEnum(typeName) {
17
- return this.enums[typeName];
18
- }
19
- findService(typeName) {
20
- return this.services[typeName];
21
- }
22
- add(type) {
23
- if ("fields" in type) {
24
- this.messages[type.typeName] = type;
25
- } else if ("methods" in type) {
26
- this.services[type.typeName] = type;
27
- } else {
28
- this.enums[type.typeName] = type;
8
+ constructor() {
9
+ this.messages = {};
10
+ this.enums = {};
11
+ this.services = {};
29
12
  }
30
- }
31
- static fromIterable(types) {
32
- const r = new TypeRegistry();
33
- for (const t of types) {
34
- r.add(t);
13
+ findMessage(typeName) {
14
+ return this.messages[typeName];
15
+ }
16
+ findEnum(typeName) {
17
+ return this.enums[typeName];
18
+ }
19
+ findService(typeName) {
20
+ return this.services[typeName];
21
+ }
22
+ add(type) {
23
+ if ("fields" in type) {
24
+ this.messages[type.typeName] = type;
25
+ }
26
+ else if ("methods" in type) {
27
+ this.services[type.typeName] = type;
28
+ }
29
+ else {
30
+ this.enums[type.typeName] = type;
31
+ }
32
+ }
33
+ static fromIterable(types) {
34
+ const r = new TypeRegistry();
35
+ for (const t of types) {
36
+ r.add(t);
37
+ }
38
+ return r;
39
+ }
40
+ static fromTypes(...types) {
41
+ return TypeRegistry.fromIterable(types);
35
42
  }
36
- return r;
37
- }
38
- static fromTypes(...types) {
39
- return TypeRegistry.fromIterable(types);
40
- }
41
43
  }
42
44
  exports.TypeRegistry = TypeRegistry;