@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2

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 (138) hide show
  1. package/dist/cjs/binary-encoding.js +414 -409
  2. package/dist/cjs/binary-format.js +13 -0
  3. package/dist/cjs/descriptor-registry.js +420 -449
  4. package/dist/cjs/descriptor-set.js +429 -513
  5. package/dist/cjs/enum.js +13 -0
  6. package/dist/cjs/field-list.js +13 -0
  7. package/dist/cjs/field.js +43 -30
  8. package/dist/cjs/google/protobuf/any_pb.js +122 -140
  9. package/dist/cjs/google/protobuf/api_pb.js +177 -224
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
  11. package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
  12. package/dist/cjs/google/protobuf/duration_pb.js +72 -88
  13. package/dist/cjs/google/protobuf/empty_pb.js +17 -17
  14. package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
  15. package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
  16. package/dist/cjs/google/protobuf/struct_pb.js +144 -181
  17. package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
  18. package/dist/cjs/google/protobuf/type_pb.js +406 -462
  19. package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
  20. package/dist/cjs/google/varint.js +166 -171
  21. package/dist/cjs/index.js +41 -122
  22. package/dist/cjs/json-format.js +13 -0
  23. package/dist/cjs/message-type.js +13 -0
  24. package/dist/cjs/message.js +89 -85
  25. package/dist/cjs/private/assert.js +33 -26
  26. package/dist/cjs/private/base64.js +93 -79
  27. package/dist/cjs/private/binary-format-common.js +208 -208
  28. package/dist/cjs/private/binary-format-proto2.js +88 -109
  29. package/dist/cjs/private/binary-format-proto3.js +70 -90
  30. package/dist/cjs/private/enum.js +77 -44
  31. package/dist/cjs/private/field-list.js +64 -50
  32. package/dist/cjs/private/field-wrapper.js +21 -10
  33. package/dist/cjs/private/field.js +35 -25
  34. package/dist/cjs/private/json-format-common.js +427 -440
  35. package/dist/cjs/private/json-format-proto2.js +91 -89
  36. package/dist/cjs/private/json-format-proto3.js +82 -93
  37. package/dist/cjs/private/message-type.js +39 -27
  38. package/dist/cjs/private/names.js +71 -62
  39. package/dist/cjs/private/options-map.js +13 -0
  40. package/dist/cjs/private/proto-runtime.js +25 -16
  41. package/dist/cjs/private/scalars.js +113 -103
  42. package/dist/cjs/private/util-common.js +193 -210
  43. package/dist/cjs/private/util.js +13 -0
  44. package/dist/cjs/proto-int64.js +123 -111
  45. package/dist/cjs/proto2.js +63 -63
  46. package/dist/cjs/proto3.js +74 -74
  47. package/dist/cjs/service-type.js +27 -17
  48. package/dist/cjs/type-registry.js +46 -31
  49. package/dist/esm/binary-encoding.js +414 -414
  50. package/dist/esm/binary-format.js +13 -0
  51. package/dist/esm/descriptor-registry.js +422 -458
  52. package/dist/esm/descriptor-set.js +430 -478
  53. package/dist/esm/enum.js +13 -0
  54. package/dist/esm/field-list.js +13 -0
  55. package/dist/esm/field.js +42 -29
  56. package/dist/esm/google/protobuf/any_pb.js +122 -140
  57. package/dist/esm/google/protobuf/api_pb.js +177 -197
  58. package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
  59. package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
  60. package/dist/esm/google/protobuf/duration_pb.js +72 -88
  61. package/dist/esm/google/protobuf/empty_pb.js +17 -17
  62. package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
  63. package/dist/esm/google/protobuf/source_context_pb.js +25 -25
  64. package/dist/esm/google/protobuf/struct_pb.js +143 -180
  65. package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
  66. package/dist/esm/google/protobuf/type_pb.js +401 -421
  67. package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
  68. package/dist/esm/google/varint.js +165 -164
  69. package/dist/esm/index.js +14 -1
  70. package/dist/esm/json-format.js +13 -0
  71. package/dist/esm/message-type.js +13 -0
  72. package/dist/esm/message.js +89 -85
  73. package/dist/esm/private/assert.js +32 -21
  74. package/dist/esm/private/base64.js +92 -78
  75. package/dist/esm/private/binary-format-common.js +209 -207
  76. package/dist/esm/private/binary-format-proto2.js +89 -81
  77. package/dist/esm/private/binary-format-proto3.js +71 -67
  78. package/dist/esm/private/enum.js +75 -43
  79. package/dist/esm/private/field-list.js +64 -50
  80. package/dist/esm/private/field-wrapper.js +21 -10
  81. package/dist/esm/private/field.js +35 -22
  82. package/dist/esm/private/json-format-common.js +427 -435
  83. package/dist/esm/private/json-format-proto2.js +89 -81
  84. package/dist/esm/private/json-format-proto3.js +79 -80
  85. package/dist/esm/private/message-type.js +40 -28
  86. package/dist/esm/private/names.js +70 -57
  87. package/dist/esm/private/options-map.js +13 -0
  88. package/dist/esm/private/proto-runtime.js +26 -12
  89. package/dist/esm/private/scalars.js +112 -99
  90. package/dist/esm/private/util-common.js +193 -192
  91. package/dist/esm/private/util.js +13 -0
  92. package/dist/esm/proto-int64.js +123 -111
  93. package/dist/esm/proto2.js +63 -57
  94. package/dist/esm/proto3.js +74 -68
  95. package/dist/esm/service-type.js +25 -12
  96. package/dist/esm/type-registry.js +46 -31
  97. package/dist/types/binary-encoding.d.ts +398 -398
  98. package/dist/types/binary-format.d.ts +69 -91
  99. package/dist/types/descriptor-registry.d.ts +23 -29
  100. package/dist/types/descriptor-set.d.ts +107 -128
  101. package/dist/types/enum.d.ts +21 -21
  102. package/dist/types/field-list.d.ts +21 -21
  103. package/dist/types/field.d.ts +191 -231
  104. package/dist/types/google/protobuf/any_pb.d.ts +56 -77
  105. package/dist/types/google/protobuf/api_pb.d.ts +144 -187
  106. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
  107. package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
  108. package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
  109. package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
  110. package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
  111. package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
  112. package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
  113. package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
  114. package/dist/types/google/protobuf/type_pb.d.ts +355 -422
  115. package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
  116. package/dist/types/google/varint.d.ts +6 -13
  117. package/dist/types/index.d.ts +4 -27
  118. package/dist/types/json-format.d.ts +70 -89
  119. package/dist/types/message-type.d.ts +37 -45
  120. package/dist/types/message.d.ts +62 -87
  121. package/dist/types/private/assert.d.ts +1 -4
  122. package/dist/types/private/binary-format-common.d.ts +6 -32
  123. package/dist/types/private/enum.d.ts +13 -11
  124. package/dist/types/private/field-list.d.ts +14 -21
  125. package/dist/types/private/field-wrapper.d.ts +4 -10
  126. package/dist/types/private/field.d.ts +12 -12
  127. package/dist/types/private/json-format-common.d.ts +5 -27
  128. package/dist/types/private/message-type.d.ts +12 -7
  129. package/dist/types/private/names.d.ts +1 -4
  130. package/dist/types/private/options-map.d.ts +1 -1
  131. package/dist/types/private/proto-runtime.d.ts +34 -42
  132. package/dist/types/private/scalars.d.ts +5 -12
  133. package/dist/types/private/util-common.d.ts +1 -4
  134. package/dist/types/private/util.d.ts +29 -41
  135. package/dist/types/proto-int64.d.ts +42 -42
  136. package/dist/types/service-type.d.ts +36 -56
  137. package/dist/types/type-registry.d.ts +13 -15
  138. package/package.json +2 -3
@@ -1,41 +1,52 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  /**
2
15
  * Assert that condition is truthy or throw error (with message)
3
16
  */
4
17
  export function assert(condition, msg) {
5
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
6
- if (!condition) {
7
- throw new Error(msg);
8
- }
18
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
19
+ if (!condition) {
20
+ throw new Error(msg);
21
+ }
9
22
  }
10
- const FLOAT32_MAX = 3.4028234663852886e38,
11
- FLOAT32_MIN = -3.4028234663852886e38,
12
- UINT32_MAX = 0xffffffff,
13
- INT32_MAX = 0x7fffffff,
14
- INT32_MIN = -0x80000000;
23
+ const FLOAT32_MAX = 3.4028234663852886e38, FLOAT32_MIN = -3.4028234663852886e38, UINT32_MAX = 0xffffffff, INT32_MAX = 0x7fffffff, INT32_MIN = -0x80000000;
15
24
  /**
16
25
  * Assert a valid signed protobuf 32-bit integer.
17
26
  */
18
27
  export function assertInt32(arg) {
19
- if (typeof arg !== "number") throw new Error("invalid int 32: " + typeof arg);
20
- if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
21
- throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
28
+ if (typeof arg !== "number")
29
+ throw new Error("invalid int 32: " + typeof arg);
30
+ if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
31
+ throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
22
32
  }
23
33
  /**
24
34
  * Assert a valid unsigned protobuf 32-bit integer.
25
35
  */
26
36
  export function assertUInt32(arg) {
27
- if (typeof arg !== "number")
28
- throw new Error("invalid uint 32: " + typeof arg);
29
- if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
30
- throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
37
+ if (typeof arg !== "number")
38
+ throw new Error("invalid uint 32: " + typeof arg);
39
+ if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
40
+ throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
31
41
  }
32
42
  /**
33
43
  * Assert a valid protobuf float value.
34
44
  */
35
45
  export function assertFloat32(arg) {
36
- if (typeof arg !== "number")
37
- throw new Error("invalid float 32: " + typeof arg);
38
- if (!Number.isFinite(arg)) return;
39
- if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
40
- throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
46
+ if (typeof arg !== "number")
47
+ throw new Error("invalid float 32: " + typeof arg);
48
+ if (!Number.isFinite(arg))
49
+ return;
50
+ if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
51
+ throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
41
52
  }
@@ -1,11 +1,23 @@
1
+ // Copyright 2021-2022 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
2
15
  // lookup table from base64 character to byte
3
- let encTable =
4
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
16
+ let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
5
17
  // lookup table from base64 character *code* to byte because lookup by number is fast
6
18
  let decTable = [];
7
19
  for (let i = 0; i < encTable.length; i++)
8
- decTable[encTable[i].charCodeAt(0)] = i;
20
+ decTable[encTable[i].charCodeAt(0)] = i;
9
21
  // support base64url variants
10
22
  decTable["-".charCodeAt(0)] = encTable.indexOf("+");
11
23
  decTable["_".charCodeAt(0)] = encTable.indexOf("/");
@@ -21,57 +33,59 @@ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
21
33
  * no padding
22
34
  */
23
35
  export function base64decode(base64Str) {
24
- // estimate byte size, not accounting for inner padding and whitespace
25
- let es = (base64Str.length * 3) / 4;
26
- // if (es % 3 !== 0)
27
- // throw new Error("invalid base64 string");
28
- if (base64Str[base64Str.length - 2] == "=") es -= 2;
29
- else if (base64Str[base64Str.length - 1] == "=") es -= 1;
30
- let bytes = new Uint8Array(es),
31
- bytePos = 0, // position in byte array
36
+ // estimate byte size, not accounting for inner padding and whitespace
37
+ let es = (base64Str.length * 3) / 4;
38
+ // if (es % 3 !== 0)
39
+ // throw new Error("invalid base64 string");
40
+ if (base64Str[base64Str.length - 2] == "=")
41
+ es -= 2;
42
+ else if (base64Str[base64Str.length - 1] == "=")
43
+ es -= 1;
44
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
32
45
  groupPos = 0, // position in base64 group
33
46
  b, // current byte
34
47
  p = 0; // previous byte
35
- for (let i = 0; i < base64Str.length; i++) {
36
- b = decTable[base64Str.charCodeAt(i)];
37
- if (b === undefined) {
38
- switch (base64Str[i]) {
39
- // @ts-ignore TS7029: Fallthrough case in switch
40
- case "=":
41
- groupPos = 0; // reset state when padding found
42
- // @ts-ignore TS7029: Fallthrough case in switch
43
- case "\n":
44
- case "\r":
45
- case "\t":
46
- case " ":
47
- continue; // skip white-space, and padding
48
- default:
49
- throw Error("invalid base64 string.");
50
- }
48
+ for (let i = 0; i < base64Str.length; i++) {
49
+ b = decTable[base64Str.charCodeAt(i)];
50
+ if (b === undefined) {
51
+ switch (base64Str[i]) {
52
+ // @ts-ignore TS7029: Fallthrough case in switch
53
+ case "=":
54
+ groupPos = 0; // reset state when padding found
55
+ // @ts-ignore TS7029: Fallthrough case in switch
56
+ case "\n":
57
+ case "\r":
58
+ case "\t":
59
+ case " ":
60
+ continue; // skip white-space, and padding
61
+ default:
62
+ throw Error("invalid base64 string.");
63
+ }
64
+ }
65
+ switch (groupPos) {
66
+ case 0:
67
+ p = b;
68
+ groupPos = 1;
69
+ break;
70
+ case 1:
71
+ bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
72
+ p = b;
73
+ groupPos = 2;
74
+ break;
75
+ case 2:
76
+ bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
77
+ p = b;
78
+ groupPos = 3;
79
+ break;
80
+ case 3:
81
+ bytes[bytePos++] = ((p & 3) << 6) | b;
82
+ groupPos = 0;
83
+ break;
84
+ }
51
85
  }
52
- switch (groupPos) {
53
- case 0:
54
- p = b;
55
- groupPos = 1;
56
- break;
57
- case 1:
58
- bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
59
- p = b;
60
- groupPos = 2;
61
- break;
62
- case 2:
63
- bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
64
- p = b;
65
- groupPos = 3;
66
- break;
67
- case 3:
68
- bytes[bytePos++] = ((p & 3) << 6) | b;
69
- groupPos = 0;
70
- break;
71
- }
72
- }
73
- if (groupPos == 1) throw Error("invalid base64 string.");
74
- return bytes.subarray(0, bytePos);
86
+ if (groupPos == 1)
87
+ throw Error("invalid base64 string.");
88
+ return bytes.subarray(0, bytePos);
75
89
  }
76
90
  /**
77
91
  * Encodes a byte array to a base64 string.
@@ -79,35 +93,35 @@ export function base64decode(base64Str) {
79
93
  * Does not insert newlines.
80
94
  */
81
95
  export function base64encode(bytes) {
82
- let base64 = "",
83
- groupPos = 0, // position in base64 group
96
+ let base64 = "", groupPos = 0, // position in base64 group
84
97
  b, // current byte
85
98
  p = 0; // carry over from previous byte
86
- for (let i = 0; i < bytes.length; i++) {
87
- b = bytes[i];
88
- switch (groupPos) {
89
- case 0:
90
- base64 += encTable[b >> 2];
91
- p = (b & 3) << 4;
92
- groupPos = 1;
93
- break;
94
- case 1:
95
- base64 += encTable[p | (b >> 4)];
96
- p = (b & 15) << 2;
97
- groupPos = 2;
98
- break;
99
- case 2:
100
- base64 += encTable[p | (b >> 6)];
101
- base64 += encTable[b & 63];
102
- groupPos = 0;
103
- break;
99
+ for (let i = 0; i < bytes.length; i++) {
100
+ b = bytes[i];
101
+ switch (groupPos) {
102
+ case 0:
103
+ base64 += encTable[b >> 2];
104
+ p = (b & 3) << 4;
105
+ groupPos = 1;
106
+ break;
107
+ case 1:
108
+ base64 += encTable[p | (b >> 4)];
109
+ p = (b & 15) << 2;
110
+ groupPos = 2;
111
+ break;
112
+ case 2:
113
+ base64 += encTable[p | (b >> 6)];
114
+ base64 += encTable[b & 63];
115
+ groupPos = 0;
116
+ break;
117
+ }
118
+ }
119
+ // padding required?
120
+ if (groupPos) {
121
+ base64 += encTable[p];
122
+ base64 += "=";
123
+ if (groupPos == 1)
124
+ base64 += "=";
104
125
  }
105
- }
106
- // padding required?
107
- if (groupPos) {
108
- base64 += encTable[p];
109
- base64 += "=";
110
- if (groupPos == 1) base64 += "=";
111
- }
112
- return base64;
126
+ return base64;
113
127
  }