@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
package/dist/cjs/index.js CHANGED
@@ -1,137 +1,39 @@
1
1
  "use strict";
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (
9
- !desc ||
10
- ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
- ) {
12
- desc = {
13
- enumerable: true,
14
- get: function () {
15
- return m[k];
16
- },
17
- };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }
21
- : function (o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- });
25
- var __exportStar =
26
- (this && this.__exportStar) ||
27
- function (m, exports) {
28
- for (var p in m)
29
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
- __createBinding(exports, m, p);
31
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
32
12
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.BinaryReader =
34
- exports.BinaryWriter =
35
- exports.WireType =
36
- exports.DescriptorSet =
37
- exports.DescriptorRegistry =
38
- exports.TypeRegistry =
39
- exports.MethodIdempotency =
40
- exports.MethodKind =
41
- exports.ScalarType =
42
- exports.Message =
43
- exports.protoInt64 =
44
- exports.proto2 =
45
- exports.proto3 =
46
- void 0;
13
+ exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.DescriptorSet = exports.DescriptorRegistry = exports.TypeRegistry = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
47
14
  var proto3_js_1 = require("./proto3.js");
48
- Object.defineProperty(exports, "proto3", {
49
- enumerable: true,
50
- get: function () {
51
- return proto3_js_1.proto3;
52
- },
53
- });
15
+ Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
54
16
  var proto2_js_1 = require("./proto2.js");
55
- Object.defineProperty(exports, "proto2", {
56
- enumerable: true,
57
- get: function () {
58
- return proto2_js_1.proto2;
59
- },
60
- });
17
+ Object.defineProperty(exports, "proto2", { enumerable: true, get: function () { return proto2_js_1.proto2; } });
61
18
  var proto_int64_js_1 = require("./proto-int64.js");
62
- Object.defineProperty(exports, "protoInt64", {
63
- enumerable: true,
64
- get: function () {
65
- return proto_int64_js_1.protoInt64;
66
- },
67
- });
19
+ Object.defineProperty(exports, "protoInt64", { enumerable: true, get: function () { return proto_int64_js_1.protoInt64; } });
68
20
  var message_js_1 = require("./message.js");
69
- Object.defineProperty(exports, "Message", {
70
- enumerable: true,
71
- get: function () {
72
- return message_js_1.Message;
73
- },
74
- });
21
+ Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_js_1.Message; } });
75
22
  var field_js_1 = require("./field.js");
76
- Object.defineProperty(exports, "ScalarType", {
77
- enumerable: true,
78
- get: function () {
79
- return field_js_1.ScalarType;
80
- },
81
- });
23
+ Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function () { return field_js_1.ScalarType; } });
82
24
  var service_type_js_1 = require("./service-type.js");
83
- Object.defineProperty(exports, "MethodKind", {
84
- enumerable: true,
85
- get: function () {
86
- return service_type_js_1.MethodKind;
87
- },
88
- });
89
- Object.defineProperty(exports, "MethodIdempotency", {
90
- enumerable: true,
91
- get: function () {
92
- return service_type_js_1.MethodIdempotency;
93
- },
94
- });
25
+ Object.defineProperty(exports, "MethodKind", { enumerable: true, get: function () { return service_type_js_1.MethodKind; } });
26
+ Object.defineProperty(exports, "MethodIdempotency", { enumerable: true, get: function () { return service_type_js_1.MethodIdempotency; } });
95
27
  var type_registry_js_1 = require("./type-registry.js");
96
- Object.defineProperty(exports, "TypeRegistry", {
97
- enumerable: true,
98
- get: function () {
99
- return type_registry_js_1.TypeRegistry;
100
- },
101
- });
28
+ Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_js_1.TypeRegistry; } });
102
29
  var descriptor_registry_js_1 = require("./descriptor-registry.js");
103
- Object.defineProperty(exports, "DescriptorRegistry", {
104
- enumerable: true,
105
- get: function () {
106
- return descriptor_registry_js_1.DescriptorRegistry;
107
- },
108
- });
30
+ Object.defineProperty(exports, "DescriptorRegistry", { enumerable: true, get: function () { return descriptor_registry_js_1.DescriptorRegistry; } });
109
31
  var descriptor_set_js_1 = require("./descriptor-set.js");
110
- Object.defineProperty(exports, "DescriptorSet", {
111
- enumerable: true,
112
- get: function () {
113
- return descriptor_set_js_1.DescriptorSet;
114
- },
115
- });
32
+ Object.defineProperty(exports, "DescriptorSet", { enumerable: true, get: function () { return descriptor_set_js_1.DescriptorSet; } });
116
33
  var binary_encoding_js_1 = require("./binary-encoding.js");
117
- Object.defineProperty(exports, "WireType", {
118
- enumerable: true,
119
- get: function () {
120
- return binary_encoding_js_1.WireType;
121
- },
122
- });
123
- Object.defineProperty(exports, "BinaryWriter", {
124
- enumerable: true,
125
- get: function () {
126
- return binary_encoding_js_1.BinaryWriter;
127
- },
128
- });
129
- Object.defineProperty(exports, "BinaryReader", {
130
- enumerable: true,
131
- get: function () {
132
- return binary_encoding_js_1.BinaryReader;
133
- },
134
- });
34
+ Object.defineProperty(exports, "WireType", { enumerable: true, get: function () { return binary_encoding_js_1.WireType; } });
35
+ Object.defineProperty(exports, "BinaryWriter", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryWriter; } });
36
+ Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return binary_encoding_js_1.BinaryReader; } });
135
37
  var json_format_js_1 = require("./json-format.js");
136
38
  // ideally, we would export these types with sub-path exports:
137
39
  __exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);
@@ -2,97 +2,89 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Message = void 0;
4
4
  /**
5
- * Message is the base class of every message, generated, or created at
6
- * runtime.
5
+ * Every message - generated or created at runtime - is an instance of this
6
+ * class.
7
7
  *
8
- * It is _not_ safe to extend this class. If you want to create a message at
9
- * run time, use proto3.makeMessageType().
8
+ * It is unsafe to extend this class. If you want to create a message at run
9
+ * time, use proto3.makeMessageType().
10
10
  */
11
11
  class Message {
12
- /**
13
- * Compare with a message of the same type.
14
- */
15
- equals(other) {
16
- return this.getType().runtime.util.equals(this.getType(), this, other);
17
- }
18
- /**
19
- * Create a deep copy.
20
- */
21
- clone() {
22
- // return this.getType().runtime.util.clone(this);
23
- return this.getType().runtime.util.clone(this);
24
- }
25
- /**
26
- * Parse from binary data, merging fields.
27
- *
28
- * Repeated fields are appended. Map entries are added, overwriting
29
- * existing keys.
30
- *
31
- * If a message field is already present, it will be merged with the
32
- * new data.
33
- */
34
- fromBinary(bytes, options) {
35
- const type = this.getType(),
36
- format = type.runtime.bin,
37
- opt = format.makeReadOptions(options);
38
- format.readMessage(this, opt.readerFactory(bytes), bytes.byteLength, opt);
39
- return this;
40
- }
41
- /**
42
- * Parse a message from a JSON value.
43
- */
44
- fromJson(jsonValue, options) {
45
- const type = this.getType(),
46
- format = type.runtime.json,
47
- opt = format.makeReadOptions(options);
48
- format.readMessage(type, jsonValue, opt, this);
49
- return this;
50
- }
51
- /**
52
- * Parse a message from a JSON string.
53
- */
54
- fromJsonString(jsonString, options) {
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
56
- return this.fromJson(JSON.parse(jsonString), options);
57
- }
58
- /**
59
- * Serialize the message to binary data.
60
- */
61
- toBinary(options) {
62
- const type = this.getType(),
63
- bin = type.runtime.bin,
64
- opt = bin.makeWriteOptions(options),
65
- writer = opt.writerFactory();
66
- bin.writeMessage(this, writer, opt);
67
- return writer.finish();
68
- }
69
- /**
70
- * Serialize the message to a JSON value, a JavaScript value that can be
71
- * passed to JSON.stringify().
72
- */
73
- toJson(options) {
74
- const type = this.getType(),
75
- json = type.runtime.json,
76
- opt = json.makeWriteOptions(options);
77
- return json.writeMessage(this, opt);
78
- }
79
- /**
80
- * Serialize the message to a JSON string.
81
- */
82
- toJsonString(options) {
83
- const value = this.toJson(options);
84
- return JSON.stringify(value, null, options?.prettySpaces ?? 0);
85
- }
86
- /**
87
- * Retrieve the MessageType of this message - a singleton that represents
88
- * the protobuf message declaration and provides metadata for reflection-
89
- * based operations.
90
- */
91
- getType() {
92
- // Any class that extends Message _must_ provide a complete static
93
- // implementation of MessageType.
94
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
95
- return Object.getPrototypeOf(this).constructor;
96
- }
12
+ // TODO find better name to prevent field name conflicts?
13
+ /**
14
+ * Compare with a message of the same type.
15
+ */
16
+ equals(other) {
17
+ return this.getType().runtime.util.equals(this.getType(), this, other);
18
+ }
19
+ // TODO find better name to prevent field name conflicts?
20
+ /**
21
+ * Create a deep copy.
22
+ */
23
+ clone() {
24
+ return this.getType().runtime.util.clone(this);
25
+ }
26
+ /**
27
+ * Parse from binary data, merging fields.
28
+ *
29
+ * Repeated fields are appended. Map entries are added, overwriting
30
+ * existing keys.
31
+ *
32
+ * If a message field is already present, it will be merged with the
33
+ * new data.
34
+ */
35
+ fromBinary(bytes, options) {
36
+ const type = this.getType(), format = type.runtime.bin, opt = format.makeReadOptions(options);
37
+ format.readMessage(this, opt.readerFactory(bytes), bytes.byteLength, opt);
38
+ return this;
39
+ }
40
+ /**
41
+ * Parse a message from a JSON value.
42
+ */
43
+ fromJson(jsonValue, options) {
44
+ const type = this.getType(), format = type.runtime.json, opt = format.makeReadOptions(options);
45
+ format.readMessage(type, jsonValue, opt, this);
46
+ return this;
47
+ }
48
+ /**
49
+ * Parse a message from a JSON string.
50
+ */
51
+ fromJsonString(jsonString, options) {
52
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- assigning to JsonValue is safe here
53
+ return this.fromJson(JSON.parse(jsonString), options);
54
+ }
55
+ /**
56
+ * Serialize the message to binary data.
57
+ */
58
+ toBinary(options) {
59
+ const type = this.getType(), bin = type.runtime.bin, opt = bin.makeWriteOptions(options), writer = opt.writerFactory();
60
+ bin.writeMessage(this, writer, opt);
61
+ return writer.finish();
62
+ }
63
+ /**
64
+ * Serialize the message to a JSON value, a JavaScript value that can be
65
+ * passed to JSON.stringify().
66
+ */
67
+ toJson(options) {
68
+ const type = this.getType(), json = type.runtime.json, opt = json.makeWriteOptions(options);
69
+ return json.writeMessage(this, opt);
70
+ }
71
+ /**
72
+ * Serialize the message to a JSON string.
73
+ */
74
+ toJsonString(options) {
75
+ const value = this.toJson(options);
76
+ return JSON.stringify(value, null, options?.prettySpaces ?? 0);
77
+ }
78
+ /**
79
+ * Retrieve the MessageType of this message - a singleton that represents
80
+ * the protobuf message declaration and provides metadata for reflection-
81
+ * based operations.
82
+ */
83
+ getType() {
84
+ // Any class that extends Message _must_ provide a complete static
85
+ // implementation of MessageType.
86
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
87
+ return Object.getPrototypeOf(this).constructor;
88
+ }
97
89
  }
98
90
  exports.Message = Message;
@@ -1,52 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertFloat32 =
4
- exports.assertUInt32 =
5
- exports.assertInt32 =
6
- exports.assert =
7
- void 0;
3
+ exports.assertFloat32 = exports.assertUInt32 = exports.assertInt32 = exports.assert = void 0;
8
4
  /**
9
5
  * Assert that condition is truthy or throw error (with message)
10
6
  */
11
7
  function assert(condition, msg) {
12
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
13
- if (!condition) {
14
- throw new Error(msg);
15
- }
8
+ // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
9
+ if (!condition) {
10
+ throw new Error(msg);
11
+ }
16
12
  }
17
13
  exports.assert = assert;
18
- const FLOAT32_MAX = 3.4028234663852886e38,
19
- FLOAT32_MIN = -3.4028234663852886e38,
20
- UINT32_MAX = 0xffffffff,
21
- INT32_MAX = 0x7fffffff,
22
- INT32_MIN = -0x80000000;
14
+ const FLOAT32_MAX = 3.4028234663852886e38, FLOAT32_MIN = -3.4028234663852886e38, UINT32_MAX = 0xffffffff, INT32_MAX = 0x7fffffff, INT32_MIN = -0x80000000;
23
15
  /**
24
16
  * Assert a valid signed protobuf 32-bit integer.
25
17
  */
26
18
  function assertInt32(arg) {
27
- if (typeof arg !== "number") throw new Error("invalid int 32: " + typeof arg);
28
- if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
29
- throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
19
+ if (typeof arg !== "number")
20
+ throw new Error("invalid int 32: " + typeof arg);
21
+ if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
22
+ throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
30
23
  }
31
24
  exports.assertInt32 = assertInt32;
32
25
  /**
33
26
  * Assert a valid unsigned protobuf 32-bit integer.
34
27
  */
35
28
  function assertUInt32(arg) {
36
- if (typeof arg !== "number")
37
- throw new Error("invalid uint 32: " + typeof arg);
38
- if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
39
- throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
29
+ if (typeof arg !== "number")
30
+ throw new Error("invalid uint 32: " + typeof arg);
31
+ if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
32
+ throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
40
33
  }
41
34
  exports.assertUInt32 = assertUInt32;
42
35
  /**
43
36
  * Assert a valid protobuf float value.
44
37
  */
45
38
  function assertFloat32(arg) {
46
- if (typeof arg !== "number")
47
- throw new Error("invalid float 32: " + typeof arg);
48
- if (!Number.isFinite(arg)) return;
49
- if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
50
- throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
39
+ if (typeof arg !== "number")
40
+ throw new Error("invalid float 32: " + typeof arg);
41
+ if (!Number.isFinite(arg))
42
+ return;
43
+ if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
44
+ throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
51
45
  }
52
46
  exports.assertFloat32 = assertFloat32;
@@ -3,12 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.base64encode = exports.base64decode = void 0;
5
5
  // lookup table from base64 character to byte
6
- let encTable =
7
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
6
+ let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
8
7
  // lookup table from base64 character *code* to byte because lookup by number is fast
9
8
  let decTable = [];
10
9
  for (let i = 0; i < encTable.length; i++)
11
- decTable[encTable[i].charCodeAt(0)] = i;
10
+ decTable[encTable[i].charCodeAt(0)] = i;
12
11
  // support base64url variants
13
12
  decTable["-".charCodeAt(0)] = encTable.indexOf("+");
14
13
  decTable["_".charCodeAt(0)] = encTable.indexOf("/");
@@ -24,57 +23,59 @@ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
24
23
  * no padding
25
24
  */
26
25
  function base64decode(base64Str) {
27
- // estimate byte size, not accounting for inner padding and whitespace
28
- let es = (base64Str.length * 3) / 4;
29
- // if (es % 3 !== 0)
30
- // throw new Error("invalid base64 string");
31
- if (base64Str[base64Str.length - 2] == "=") es -= 2;
32
- else if (base64Str[base64Str.length - 1] == "=") es -= 1;
33
- let bytes = new Uint8Array(es),
34
- bytePos = 0, // position in byte array
26
+ // estimate byte size, not accounting for inner padding and whitespace
27
+ let es = (base64Str.length * 3) / 4;
28
+ // if (es % 3 !== 0)
29
+ // throw new Error("invalid base64 string");
30
+ if (base64Str[base64Str.length - 2] == "=")
31
+ es -= 2;
32
+ else if (base64Str[base64Str.length - 1] == "=")
33
+ es -= 1;
34
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
35
35
  groupPos = 0, // position in base64 group
36
36
  b, // current byte
37
37
  p = 0; // previous byte
38
- for (let i = 0; i < base64Str.length; i++) {
39
- b = decTable[base64Str.charCodeAt(i)];
40
- if (b === undefined) {
41
- switch (base64Str[i]) {
42
- // @ts-ignore TS7029: Fallthrough case in switch
43
- case "=":
44
- groupPos = 0; // reset state when padding found
45
- // @ts-ignore TS7029: Fallthrough case in switch
46
- case "\n":
47
- case "\r":
48
- case "\t":
49
- case " ":
50
- continue; // skip white-space, and padding
51
- default:
52
- throw Error("invalid base64 string.");
53
- }
38
+ for (let i = 0; i < base64Str.length; i++) {
39
+ b = decTable[base64Str.charCodeAt(i)];
40
+ if (b === undefined) {
41
+ switch (base64Str[i]) {
42
+ // @ts-ignore TS7029: Fallthrough case in switch
43
+ case "=":
44
+ groupPos = 0; // reset state when padding found
45
+ // @ts-ignore TS7029: Fallthrough case in switch
46
+ case "\n":
47
+ case "\r":
48
+ case "\t":
49
+ case " ":
50
+ continue; // skip white-space, and padding
51
+ default:
52
+ throw Error("invalid base64 string.");
53
+ }
54
+ }
55
+ switch (groupPos) {
56
+ case 0:
57
+ p = b;
58
+ groupPos = 1;
59
+ break;
60
+ case 1:
61
+ bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
62
+ p = b;
63
+ groupPos = 2;
64
+ break;
65
+ case 2:
66
+ bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
67
+ p = b;
68
+ groupPos = 3;
69
+ break;
70
+ case 3:
71
+ bytes[bytePos++] = ((p & 3) << 6) | b;
72
+ groupPos = 0;
73
+ break;
74
+ }
54
75
  }
55
- switch (groupPos) {
56
- case 0:
57
- p = b;
58
- groupPos = 1;
59
- break;
60
- case 1:
61
- bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
62
- p = b;
63
- groupPos = 2;
64
- break;
65
- case 2:
66
- bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
67
- p = b;
68
- groupPos = 3;
69
- break;
70
- case 3:
71
- bytes[bytePos++] = ((p & 3) << 6) | b;
72
- groupPos = 0;
73
- break;
74
- }
75
- }
76
- if (groupPos == 1) throw Error("invalid base64 string.");
77
- return bytes.subarray(0, bytePos);
76
+ if (groupPos == 1)
77
+ throw Error("invalid base64 string.");
78
+ return bytes.subarray(0, bytePos);
78
79
  }
79
80
  exports.base64decode = base64decode;
80
81
  /**
@@ -83,36 +84,36 @@ exports.base64decode = base64decode;
83
84
  * Does not insert newlines.
84
85
  */
85
86
  function base64encode(bytes) {
86
- let base64 = "",
87
- groupPos = 0, // position in base64 group
87
+ let base64 = "", groupPos = 0, // position in base64 group
88
88
  b, // current byte
89
89
  p = 0; // carry over from previous byte
90
- for (let i = 0; i < bytes.length; i++) {
91
- b = bytes[i];
92
- switch (groupPos) {
93
- case 0:
94
- base64 += encTable[b >> 2];
95
- p = (b & 3) << 4;
96
- groupPos = 1;
97
- break;
98
- case 1:
99
- base64 += encTable[p | (b >> 4)];
100
- p = (b & 15) << 2;
101
- groupPos = 2;
102
- break;
103
- case 2:
104
- base64 += encTable[p | (b >> 6)];
105
- base64 += encTable[b & 63];
106
- groupPos = 0;
107
- break;
90
+ for (let i = 0; i < bytes.length; i++) {
91
+ b = bytes[i];
92
+ switch (groupPos) {
93
+ case 0:
94
+ base64 += encTable[b >> 2];
95
+ p = (b & 3) << 4;
96
+ groupPos = 1;
97
+ break;
98
+ case 1:
99
+ base64 += encTable[p | (b >> 4)];
100
+ p = (b & 15) << 2;
101
+ groupPos = 2;
102
+ break;
103
+ case 2:
104
+ base64 += encTable[p | (b >> 6)];
105
+ base64 += encTable[b & 63];
106
+ groupPos = 0;
107
+ break;
108
+ }
109
+ }
110
+ // padding required?
111
+ if (groupPos) {
112
+ base64 += encTable[p];
113
+ base64 += "=";
114
+ if (groupPos == 1)
115
+ base64 += "=";
108
116
  }
109
- }
110
- // padding required?
111
- if (groupPos) {
112
- base64 += encTable[p];
113
- base64 += "=";
114
- if (groupPos == 1) base64 += "=";
115
- }
116
- return base64;
117
+ return base64;
117
118
  }
118
119
  exports.base64encode = base64encode;