@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,118 +1,117 @@
1
- import { int64fromString, int64toString } from "./google/varint.js";
1
+ import { int64fromString, int64toString } from "./private/goog-varint.js";
2
2
  function makeInt64Support() {
3
- const dv = new DataView(new ArrayBuffer(8));
4
- // note that Safari 14 implements BigInt, but not the DataView methods
5
- const ok =
6
- globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
7
- typeof dv.getBigInt64 === "function" &&
8
- typeof dv.getBigUint64 === "function" &&
9
- typeof dv.setBigInt64 === "function" &&
10
- typeof dv.setBigUint64 === "function";
11
- if (ok) {
12
- const MIN = BigInt("-9223372036854775808"),
13
- MAX = BigInt("9223372036854775807"),
14
- UMIN = BigInt("0"),
15
- UMAX = BigInt("18446744073709551615");
16
- return {
17
- zero: BigInt(0),
18
- supported: true,
19
- parse(value) {
20
- const bi = typeof value == "bigint" ? value : BigInt(value);
21
- if (bi > MAX || bi < MIN) {
22
- throw new Error(`int64 invalid: ${value}`);
23
- }
24
- return bi;
25
- },
26
- uParse(value) {
27
- const bi = typeof value == "bigint" ? value : BigInt(value);
28
- if (bi > UMAX || bi < UMIN) {
29
- throw new Error(`uint64 invalid: ${value}`);
30
- }
31
- return bi;
32
- },
33
- enc(value) {
34
- dv.setBigInt64(0, this.parse(value), true);
35
- return {
36
- lo: dv.getInt32(0, true),
37
- hi: dv.getInt32(4, true),
38
- };
39
- },
40
- uEnc(value) {
41
- dv.setBigInt64(0, this.uParse(value), true);
3
+ const dv = new DataView(new ArrayBuffer(8));
4
+ // note that Safari 14 implements BigInt, but not the DataView methods
5
+ const ok = globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
6
+ typeof dv.getBigInt64 === "function" &&
7
+ typeof dv.getBigUint64 === "function" &&
8
+ typeof dv.setBigInt64 === "function" &&
9
+ typeof dv.setBigUint64 === "function";
10
+ if (ok) {
11
+ const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
42
12
  return {
43
- lo: dv.getInt32(0, true),
44
- hi: dv.getInt32(4, true),
13
+ zero: BigInt(0),
14
+ supported: true,
15
+ parse(value) {
16
+ const bi = typeof value == "bigint" ? value : BigInt(value);
17
+ if (bi > MAX || bi < MIN) {
18
+ throw new Error(`int64 invalid: ${value}`);
19
+ }
20
+ return bi;
21
+ },
22
+ uParse(value) {
23
+ const bi = typeof value == "bigint" ? value : BigInt(value);
24
+ if (bi > UMAX || bi < UMIN) {
25
+ throw new Error(`uint64 invalid: ${value}`);
26
+ }
27
+ return bi;
28
+ },
29
+ enc(value) {
30
+ dv.setBigInt64(0, this.parse(value), true);
31
+ return {
32
+ lo: dv.getInt32(0, true),
33
+ hi: dv.getInt32(4, true),
34
+ };
35
+ },
36
+ uEnc(value) {
37
+ dv.setBigInt64(0, this.uParse(value), true);
38
+ return {
39
+ lo: dv.getInt32(0, true),
40
+ hi: dv.getInt32(4, true),
41
+ };
42
+ },
43
+ dec(lo, hi) {
44
+ dv.setInt32(0, lo, true);
45
+ dv.setInt32(4, hi, true);
46
+ return dv.getBigInt64(0, true);
47
+ },
48
+ uDec(lo, hi) {
49
+ dv.setInt32(0, lo, true);
50
+ dv.setInt32(4, hi, true);
51
+ return dv.getBigUint64(0, true);
52
+ },
45
53
  };
46
- },
47
- dec(lo, hi) {
48
- dv.setInt32(0, lo, true);
49
- dv.setInt32(4, hi, true);
50
- return dv.getBigInt64(0, true);
51
- },
52
- uDec(lo, hi) {
53
- dv.setInt32(0, lo, true);
54
- dv.setInt32(4, hi, true);
55
- return dv.getBigUint64(0, true);
56
- },
54
+ }
55
+ return {
56
+ zero: "0",
57
+ supported: false,
58
+ parse(value) {
59
+ if (!/^-?[0-9]+$/.test(value)) {
60
+ throw new Error(`int64 invalid: ${value}`);
61
+ }
62
+ return value;
63
+ },
64
+ uParse(value) {
65
+ if (!/^-?[0-9]+$/.test(value)) {
66
+ throw new Error(`uint64 invalid: ${value}`);
67
+ }
68
+ return value;
69
+ },
70
+ enc(value) {
71
+ if (typeof value == "string") {
72
+ if (!/^-?[0-9]+$/.test(value)) {
73
+ throw new Error(`int64 invalid: ${value}`);
74
+ }
75
+ }
76
+ else {
77
+ value = value.toString(10);
78
+ }
79
+ const [, lo, hi] = int64fromString(value);
80
+ return { lo, hi };
81
+ },
82
+ uEnc(value) {
83
+ if (typeof value == "string") {
84
+ if (!/^-?[0-9]+$/.test(value)) {
85
+ throw new Error(`uint64 invalid: ${value}`);
86
+ }
87
+ }
88
+ else {
89
+ value = value.toString(10);
90
+ }
91
+ const [minus, lo, hi] = int64fromString(value);
92
+ if (minus) {
93
+ throw new Error(`uint64 invalid: ${value}`);
94
+ }
95
+ return { lo, hi };
96
+ },
97
+ dec(lo, hi) {
98
+ const minus = (hi & 0x80000000) !== 0;
99
+ if (minus) {
100
+ // negate
101
+ hi = ~hi;
102
+ if (lo) {
103
+ lo = ~lo + 1;
104
+ }
105
+ else {
106
+ hi += 1;
107
+ }
108
+ return ("-" + int64toString(lo, hi));
109
+ }
110
+ return int64toString(lo, hi);
111
+ },
112
+ uDec(lo, hi) {
113
+ return int64toString(lo, hi);
114
+ },
57
115
  };
58
- }
59
- return {
60
- zero: "0",
61
- supported: false,
62
- parse(value) {
63
- if (!/^-?[0-9]+$/.test(value)) {
64
- throw new Error(`int64 invalid: ${value}`);
65
- }
66
- return value;
67
- },
68
- uParse(value) {
69
- if (!/^-?[0-9]+$/.test(value)) {
70
- throw new Error(`uint64 invalid: ${value}`);
71
- }
72
- return value;
73
- },
74
- enc(value) {
75
- if (typeof value == "string") {
76
- if (!/^-?[0-9]+$/.test(value)) {
77
- throw new Error(`int64 invalid: ${value}`);
78
- }
79
- } else {
80
- value = value.toString(10);
81
- }
82
- const [, lo, hi] = 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
- } else {
91
- value = value.toString(10);
92
- }
93
- const [minus, lo, hi] = int64fromString(value);
94
- if (minus) {
95
- throw new Error(`uint64 invalid: ${value}`);
96
- }
97
- return { lo, hi };
98
- },
99
- dec(lo, hi) {
100
- const minus = (hi & 0x80000000) !== 0;
101
- if (minus) {
102
- // negate
103
- hi = ~hi;
104
- if (lo) {
105
- lo = ~lo + 1;
106
- } else {
107
- hi += 1;
108
- }
109
- return "-" + int64toString(lo, hi);
110
- }
111
- return int64toString(lo, hi);
112
- },
113
- uDec(lo, hi) {
114
- return int64toString(lo, hi);
115
- },
116
- };
117
116
  }
118
117
  export const protoInt64 = makeInt64Support();
@@ -8,70 +8,63 @@ import { makeJsonFormatProto2 } from "./private/json-format-proto2.js";
8
8
  /**
9
9
  * Provides functionality for messages defined with the proto2 syntax.
10
10
  */
11
- export const proto2 = makeProtoRuntime(
12
- "proto2",
13
- makeJsonFormatProto2(),
14
- makeBinaryFormatProto2(),
15
- {
11
+ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), {
16
12
  ...makeUtilCommon(),
17
13
  newFieldList(fields) {
18
- return new InternalFieldList(fields, normalizeFieldInfosProto2);
14
+ return new InternalFieldList(fields, normalizeFieldInfosProto2);
19
15
  },
20
16
  initFields(target) {
21
- for (const member of target.getType().fields.byMember()) {
22
- const name = member.localName,
23
- t = target;
24
- if (member.repeated) {
25
- t[name] = [];
26
- continue;
17
+ for (const member of target.getType().fields.byMember()) {
18
+ const name = member.localName, t = target;
19
+ if (member.repeated) {
20
+ t[name] = [];
21
+ continue;
22
+ }
23
+ switch (member.kind) {
24
+ case "oneof":
25
+ t[name] = { case: undefined };
26
+ break;
27
+ case "map":
28
+ t[name] = {};
29
+ break;
30
+ case "scalar":
31
+ case "enum":
32
+ case "message":
33
+ // In contrast to proto3, enum and scalar fields have no intrinsic default value,
34
+ // only an optional explicit default value.
35
+ // Unlike proto3 intrinsic default values, proto2 explicit default values are not
36
+ // set on construction, because they are not omitted on the wire. If we did set
37
+ // default values on construction, a deserialize-serialize round-trip would add
38
+ // fields to a message.
39
+ break;
40
+ }
27
41
  }
28
- switch (member.kind) {
29
- case "oneof":
30
- t[name] = { case: undefined };
31
- break;
32
- case "map":
33
- t[name] = {};
34
- break;
35
- case "scalar":
36
- case "enum":
37
- case "message":
38
- // In contrast to proto3, enum and scalar fields have no intrinsic default value,
39
- // only an optional explicit default value.
40
- // Unlike proto3 intrinsic default values, proto2 explicit default values are not
41
- // set on construction, because they are not omitted on the wire. If we did set
42
- // default values on construction, a deserialize-serialize round-trip would add
43
- // fields to a message.
44
- break;
45
- }
46
- }
47
42
  },
48
- }
49
- );
43
+ });
50
44
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
51
45
  function normalizeFieldInfosProto2(fieldInfos) {
52
- const r = [];
53
- let o;
54
- for (const field of typeof fieldInfos == "function"
55
- ? fieldInfos()
56
- : fieldInfos) {
57
- const f = field;
58
- f.localName = makeFieldName(field.name, field.oneof !== undefined);
59
- f.jsonName = field.jsonName ?? makeJsonName(field.name);
60
- f.repeated = field.repeated ?? false;
61
- // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
62
- f.packed = field.packed ?? false;
63
- // We do not surface options at this time
64
- // f.options = field.options ?? emptyReadonlyObject;
65
- if (field.oneof !== undefined) {
66
- const ooname =
67
- typeof field.oneof == "string" ? field.oneof : field.oneof.name;
68
- if (!o || o.name != ooname) {
69
- o = new InternalOneofInfo(ooname);
70
- }
71
- f.oneof = o;
72
- o.addField(f);
46
+ const r = [];
47
+ let o;
48
+ for (const field of typeof fieldInfos == "function"
49
+ ? fieldInfos()
50
+ : fieldInfos) {
51
+ const f = field;
52
+ f.localName = makeFieldName(field.name, field.oneof !== undefined);
53
+ f.jsonName = field.jsonName ?? makeJsonName(field.name);
54
+ f.repeated = field.repeated ?? false;
55
+ // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
56
+ f.packed = field.packed ?? false;
57
+ // We do not surface options at this time
58
+ // f.options = field.options ?? emptyReadonlyObject;
59
+ if (field.oneof !== undefined) {
60
+ const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
61
+ if (!o || o.name != ooname) {
62
+ o = new InternalOneofInfo(ooname);
63
+ }
64
+ f.oneof = o;
65
+ o.addField(f);
66
+ }
67
+ r.push(f);
73
68
  }
74
- r.push(f);
75
- }
76
- return r;
69
+ return r;
77
70
  }
@@ -10,81 +10,74 @@ import { makeFieldName, makeJsonName } from "./private/names.js";
10
10
  /**
11
11
  * Provides functionality for messages defined with the proto3 syntax.
12
12
  */
13
- export const proto3 = makeProtoRuntime(
14
- "proto3",
15
- makeJsonFormatProto3(),
16
- makeBinaryFormatProto3(),
17
- {
13
+ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), {
18
14
  ...makeUtilCommon(),
19
15
  newFieldList(fields) {
20
- return new InternalFieldList(fields, normalizeFieldInfosProto3);
16
+ return new InternalFieldList(fields, normalizeFieldInfosProto3);
21
17
  },
22
18
  initFields(target) {
23
- for (const member of target.getType().fields.byMember()) {
24
- if (member.opt) {
25
- continue;
19
+ for (const member of target.getType().fields.byMember()) {
20
+ if (member.opt) {
21
+ continue;
22
+ }
23
+ const name = member.localName, t = target;
24
+ if (member.repeated) {
25
+ t[name] = [];
26
+ continue;
27
+ }
28
+ switch (member.kind) {
29
+ case "oneof":
30
+ t[name] = { case: undefined };
31
+ break;
32
+ case "enum":
33
+ t[name] = 0;
34
+ break;
35
+ case "map":
36
+ t[name] = {};
37
+ break;
38
+ case "scalar":
39
+ t[name] = scalarDefaultValue(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
40
+ break;
41
+ case "message":
42
+ // message fields are always optional in proto3
43
+ break;
44
+ }
26
45
  }
27
- const name = member.localName,
28
- t = target;
29
- if (member.repeated) {
30
- t[name] = [];
31
- continue;
32
- }
33
- switch (member.kind) {
34
- case "oneof":
35
- t[name] = { case: undefined };
36
- break;
37
- case "enum":
38
- t[name] = 0;
39
- break;
40
- case "map":
41
- t[name] = {};
42
- break;
43
- case "scalar":
44
- t[name] = scalarDefaultValue(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
45
- break;
46
- case "message":
47
- // message fields are always optional in proto3
48
- break;
49
- }
50
- }
51
46
  },
52
- }
53
- );
47
+ });
54
48
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
55
49
  function normalizeFieldInfosProto3(fieldInfos) {
56
- const r = [];
57
- let o;
58
- for (const field of typeof fieldInfos == "function"
59
- ? fieldInfos()
60
- : fieldInfos) {
61
- const f = field;
62
- f.localName = makeFieldName(field.name, field.oneof !== undefined);
63
- f.jsonName = field.jsonName ?? makeJsonName(field.name);
64
- f.repeated = field.repeated ?? false;
65
- // From the proto3 language guide:
66
- // > In proto3, repeated fields of scalar numeric types are packed by default.
67
- // This information is incomplete - according to the conformance tests, BOOL
68
- // and ENUM are packed by default as well. This means only STRING and BYTES
69
- // are not packed by default, which makes sense because they are length-delimited.
70
- f.packed =
71
- field.packed ??
72
- (field.kind == "enum" ||
73
- (field.kind == "scalar" &&
74
- field.T != ScalarType.BYTES &&
75
- field.T != ScalarType.STRING));
76
- // We do not surface options at this time
77
- // f.options = field.options ?? emptyReadonlyObject;
78
- if (field.oneof !== undefined) {
79
- const ooname =
80
- typeof field.oneof == "string" ? field.oneof : field.oneof.name;
81
- if (!o || o.name != ooname) {
82
- o = new InternalOneofInfo(ooname);
83
- }
84
- f.oneof = o;
85
- o.addField(f);
50
+ const r = [];
51
+ let o;
52
+ for (const field of typeof fieldInfos == "function"
53
+ ? fieldInfos()
54
+ : fieldInfos) {
55
+ const f = field;
56
+ f.localName = makeFieldName(field.name, field.oneof !== undefined);
57
+ f.jsonName = field.jsonName ?? makeJsonName(field.name);
58
+ f.repeated = field.repeated ?? false;
59
+ // From the proto3 language guide:
60
+ // > In proto3, repeated fields of scalar numeric types are packed by default.
61
+ // This information is incomplete - according to the conformance tests, BOOL
62
+ // and ENUM are packed by default as well. This means only STRING and BYTES
63
+ // are not packed by default, which makes sense because they are length-delimited.
64
+ f.packed =
65
+ field.packed ??
66
+ (field.kind == "enum" ||
67
+ (field.kind == "scalar" &&
68
+ field.T != ScalarType.BYTES &&
69
+ field.T != ScalarType.STRING));
70
+ // We do not surface options at this time
71
+ // f.options = field.options ?? emptyReadonlyObject;
72
+ if (field.oneof !== undefined) {
73
+ const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
74
+ if (!o || o.name != ooname) {
75
+ o = new InternalOneofInfo(ooname);
76
+ }
77
+ f.oneof = o;
78
+ o.addField(f);
79
+ }
80
+ r.push(f);
86
81
  }
87
- r.push(f);
88
- }
89
- return r;
82
+ return r;
90
83
  }
@@ -9,10 +9,10 @@
9
9
  */
10
10
  export var MethodKind;
11
11
  (function (MethodKind) {
12
- MethodKind[(MethodKind["Unary"] = 0)] = "Unary";
13
- MethodKind[(MethodKind["ServerStreaming"] = 1)] = "ServerStreaming";
14
- MethodKind[(MethodKind["ClientStreaming"] = 2)] = "ClientStreaming";
15
- MethodKind[(MethodKind["BiDiStreaming"] = 3)] = "BiDiStreaming";
12
+ MethodKind[MethodKind["Unary"] = 0] = "Unary";
13
+ MethodKind[MethodKind["ServerStreaming"] = 1] = "ServerStreaming";
14
+ MethodKind[MethodKind["ClientStreaming"] = 2] = "ClientStreaming";
15
+ MethodKind[MethodKind["BiDiStreaming"] = 3] = "BiDiStreaming";
16
16
  })(MethodKind || (MethodKind = {}));
17
17
  /**
18
18
  * Is this method side-effect-free (or safe in HTTP parlance), or just
@@ -26,12 +26,12 @@ export var MethodKind;
26
26
  */
27
27
  export var MethodIdempotency;
28
28
  (function (MethodIdempotency) {
29
- /**
30
- * Idempotent, no side effects.
31
- */
32
- MethodIdempotency[(MethodIdempotency["NoSideEffects"] = 1)] = "NoSideEffects";
33
- /**
34
- * Idempotent, but may have side effects.
35
- */
36
- MethodIdempotency[(MethodIdempotency["Idempotent"] = 2)] = "Idempotent";
29
+ /**
30
+ * Idempotent, no side effects.
31
+ */
32
+ MethodIdempotency[MethodIdempotency["NoSideEffects"] = 1] = "NoSideEffects";
33
+ /**
34
+ * Idempotent, but may have side effects.
35
+ */
36
+ MethodIdempotency[MethodIdempotency["Idempotent"] = 2] = "Idempotent";
37
37
  })(MethodIdempotency || (MethodIdempotency = {}));
@@ -2,37 +2,39 @@
2
2
  * TypeRegistry is a basic type registry
3
3
  */
4
4
  export class TypeRegistry {
5
- constructor() {
6
- this.messages = {};
7
- this.enums = {};
8
- this.services = {};
9
- }
10
- findMessage(typeName) {
11
- return this.messages[typeName];
12
- }
13
- findEnum(typeName) {
14
- return this.enums[typeName];
15
- }
16
- findService(typeName) {
17
- return this.services[typeName];
18
- }
19
- add(type) {
20
- if ("fields" in type) {
21
- this.messages[type.typeName] = type;
22
- } else if ("methods" in type) {
23
- this.services[type.typeName] = type;
24
- } else {
25
- this.enums[type.typeName] = type;
5
+ constructor() {
6
+ this.messages = {};
7
+ this.enums = {};
8
+ this.services = {};
26
9
  }
27
- }
28
- static fromIterable(types) {
29
- const r = new TypeRegistry();
30
- for (const t of types) {
31
- r.add(t);
10
+ findMessage(typeName) {
11
+ return this.messages[typeName];
12
+ }
13
+ findEnum(typeName) {
14
+ return this.enums[typeName];
15
+ }
16
+ findService(typeName) {
17
+ return this.services[typeName];
18
+ }
19
+ add(type) {
20
+ if ("fields" in type) {
21
+ this.messages[type.typeName] = type;
22
+ }
23
+ else if ("methods" in type) {
24
+ this.services[type.typeName] = type;
25
+ }
26
+ else {
27
+ this.enums[type.typeName] = type;
28
+ }
29
+ }
30
+ static fromIterable(types) {
31
+ const r = new TypeRegistry();
32
+ for (const t of types) {
33
+ r.add(t);
34
+ }
35
+ return r;
36
+ }
37
+ static fromTypes(...types) {
38
+ return TypeRegistry.fromIterable(types);
32
39
  }
33
- return r;
34
- }
35
- static fromTypes(...types) {
36
- return TypeRegistry.fromIterable(types);
37
- }
38
40
  }