@aptre/protobuf-es-lite 0.2.7 → 0.2.9

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 (121) hide show
  1. package/.ignore +1 -0
  2. package/README.md +23 -24
  3. package/bin/protoc-gen-es-lite +2 -2
  4. package/dist/binary-encoding.d.ts +420 -0
  5. package/dist/binary-encoding.js +437 -0
  6. package/dist/binary.d.ts +35 -2
  7. package/dist/binary.js +64 -65
  8. package/dist/codegen-info.d.ts +43 -0
  9. package/dist/codegen-info.js +72 -0
  10. package/dist/create-descriptor-set.d.ts +36 -0
  11. package/dist/create-descriptor-set.js +936 -0
  12. package/dist/descriptor-set.d.ts +672 -0
  13. package/dist/{editions.js → descriptor-set.js} +0 -11
  14. package/dist/enum.d.ts +35 -1
  15. package/dist/feature-set.d.ts +19 -0
  16. package/dist/feature-set.js +103 -0
  17. package/dist/field-wrapper.d.ts +7 -3
  18. package/dist/field-wrapper.js +30 -1
  19. package/dist/field.d.ts +8 -19
  20. package/dist/field.js +15 -117
  21. package/dist/google/index.d.ts +9 -0
  22. package/dist/google/index.js +41 -0
  23. package/dist/google/protobuf/any.pb.d.ts +139 -0
  24. package/dist/google/protobuf/any.pb.js +42 -0
  25. package/dist/google/protobuf/api.pb.d.ts +252 -0
  26. package/dist/google/protobuf/api.pb.js +70 -0
  27. package/dist/google/protobuf/compiler/plugin.pb.d.ts +240 -0
  28. package/dist/google/protobuf/compiler/plugin.pb.js +203 -0
  29. package/dist/google/protobuf/descriptor.pb.d.ts +2132 -0
  30. package/dist/google/protobuf/descriptor.pb.js +1080 -0
  31. package/dist/google/protobuf/duration.pb.d.ts +92 -0
  32. package/dist/google/protobuf/duration.pb.js +42 -0
  33. package/dist/google/protobuf/empty.pb.d.ts +18 -0
  34. package/dist/google/protobuf/empty.pb.js +39 -0
  35. package/dist/google/protobuf/source_context.pb.d.ts +21 -0
  36. package/dist/google/protobuf/source_context.pb.js +41 -0
  37. package/dist/google/protobuf/struct.pb.d.ts +121 -0
  38. package/dist/google/protobuf/struct.pb.js +83 -0
  39. package/dist/google/protobuf/timestamp.pb.d.ts +121 -0
  40. package/dist/google/protobuf/timestamp.pb.js +42 -0
  41. package/dist/google/protobuf/type.pb.d.ts +464 -0
  42. package/dist/google/protobuf/type.pb.js +338 -0
  43. package/dist/google/protobuf/wrappers.pb.d.ts +183 -0
  44. package/dist/google/protobuf/wrappers.pb.js +107 -0
  45. package/dist/index.d.ts +9 -3
  46. package/dist/index.js +41 -8
  47. package/dist/is-message.d.ts +10 -2
  48. package/dist/is-message.js +74 -3
  49. package/dist/json.d.ts +68 -1
  50. package/dist/json.js +57 -81
  51. package/dist/message.d.ts +30 -61
  52. package/dist/message.js +61 -20
  53. package/dist/names.d.ts +43 -0
  54. package/dist/names.js +276 -0
  55. package/dist/partial.js +14 -15
  56. package/dist/proto-base64.d.ts +18 -0
  57. package/dist/proto-base64.js +128 -0
  58. package/dist/proto-double.d.ts +5 -0
  59. package/dist/proto-double.js +29 -0
  60. package/dist/proto-int64.d.ts +95 -0
  61. package/dist/proto-int64.js +116 -0
  62. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.d.ts +1 -0
  63. package/dist/{protoc-gen-es-lite-plugin.js → protoc-gen-es-lite/protoc-gen-es-lite-plugin.js} +2 -2
  64. package/dist/{typescript.d.ts → protoc-gen-es-lite/typescript.d.ts} +3 -2
  65. package/dist/{typescript.js → protoc-gen-es-lite/typescript.js} +46 -34
  66. package/dist/protoplugin/create-es-plugin.d.ts +83 -0
  67. package/dist/protoplugin/create-es-plugin.js +119 -0
  68. package/dist/protoplugin/ecmascript/file-preamble.d.ts +2 -0
  69. package/dist/protoplugin/ecmascript/file-preamble.js +74 -0
  70. package/dist/protoplugin/ecmascript/generated-file.d.ts +116 -0
  71. package/dist/protoplugin/ecmascript/generated-file.js +407 -0
  72. package/dist/protoplugin/ecmascript/import-path.d.ts +65 -0
  73. package/dist/protoplugin/ecmascript/import-path.js +156 -0
  74. package/dist/protoplugin/ecmascript/import-symbol.d.ts +39 -0
  75. package/dist/protoplugin/ecmascript/import-symbol.js +37 -0
  76. package/dist/protoplugin/ecmascript/index.d.ts +7 -0
  77. package/dist/protoplugin/ecmascript/index.js +20 -0
  78. package/dist/protoplugin/ecmascript/jsdoc.d.ts +14 -0
  79. package/dist/protoplugin/ecmascript/jsdoc.js +93 -0
  80. package/dist/protoplugin/ecmascript/opaque-printables.d.ts +27 -0
  81. package/dist/protoplugin/ecmascript/opaque-printables.js +15 -0
  82. package/dist/protoplugin/ecmascript/parameter.d.ts +13 -0
  83. package/dist/protoplugin/ecmascript/parameter.js +161 -0
  84. package/dist/protoplugin/ecmascript/reify-wkt.d.ts +100 -0
  85. package/dist/protoplugin/ecmascript/reify-wkt.js +170 -0
  86. package/dist/protoplugin/ecmascript/runtime-imports.d.ts +6 -0
  87. package/dist/protoplugin/ecmascript/runtime-imports.js +28 -0
  88. package/dist/protoplugin/ecmascript/schema.d.ts +43 -0
  89. package/dist/protoplugin/ecmascript/schema.js +73 -0
  90. package/dist/protoplugin/ecmascript/target.d.ts +4 -0
  91. package/dist/protoplugin/ecmascript/target.js +15 -0
  92. package/dist/protoplugin/ecmascript/transpile.d.ts +2 -0
  93. package/dist/protoplugin/ecmascript/transpile.js +149 -0
  94. package/dist/protoplugin/error.d.ts +6 -0
  95. package/dist/protoplugin/error.js +43 -0
  96. package/dist/protoplugin/index.d.ts +8 -0
  97. package/dist/protoplugin/index.js +20 -0
  98. package/dist/protoplugin/plugin.d.ts +18 -0
  99. package/dist/protoplugin/plugin.js +15 -0
  100. package/dist/protoplugin/run-node.d.ts +12 -0
  101. package/dist/protoplugin/run-node.js +83 -0
  102. package/dist/scalar.d.ts +53 -1
  103. package/dist/scalar.js +87 -22
  104. package/dist/service-type.d.ts +95 -0
  105. package/dist/service-type.js +53 -0
  106. package/dist/text-format.d.ts +4 -0
  107. package/dist/text-format.js +189 -0
  108. package/dist/type-registry.d.ts +43 -0
  109. package/dist/type-registry.js +15 -0
  110. package/dist/unknown.d.ts +1 -1
  111. package/dist/util.d.ts +2 -2
  112. package/dist/util.js +46 -44
  113. package/dist/varint.d.ts +70 -0
  114. package/dist/varint.js +324 -0
  115. package/example/example.pb.ts +87 -0
  116. package/example/example.proto +1 -0
  117. package/example/tsconfig.json +8 -2
  118. package/package.json +19 -12
  119. package/tsconfig.json +4 -4
  120. package/dist/editions.d.ts +0 -6
  121. package/dist/protoc-gen-es-lite-plugin.d.ts +0 -1
package/dist/util.js CHANGED
@@ -15,8 +15,10 @@
15
15
  // limitations under the License.
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.getFieldZeroValueExpression = exports.getFieldDefaultValueExpression = exports.getFieldTypeInfo = void 0;
18
- const protobuf_1 = require("@bufbuild/protobuf");
19
- const ecmascript_1 = require("@bufbuild/protoplugin/ecmascript");
18
+ const descriptor_pb_js_1 = require("./google/protobuf/descriptor.pb.js");
19
+ const codegen_info_js_1 = require("./codegen-info.js");
20
+ const scalar_js_1 = require("./scalar.js");
21
+ const names_js_1 = require("./names.js");
20
22
  function getFieldTypeInfo(field) {
21
23
  const typing = [];
22
24
  let typingInferrableFromZeroValue;
@@ -26,13 +28,13 @@ function getFieldTypeInfo(field) {
26
28
  typing.push(scalarTypeScriptType(field.scalar, field.longType));
27
29
  optional =
28
30
  field.optional ||
29
- field.proto.label === protobuf_1.FieldDescriptorProto_Label.REQUIRED;
31
+ field.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED;
30
32
  typingInferrableFromZeroValue = true;
31
33
  break;
32
34
  case "message": {
33
- const baseType = protobuf_1.codegenInfo.getUnwrappedFieldType(field);
35
+ const baseType = codegen_info_js_1.codegenInfo.getUnwrappedFieldType(field);
34
36
  if (baseType !== undefined) {
35
- typing.push(scalarTypeScriptType(baseType, protobuf_1.LongType.BIGINT));
37
+ typing.push(scalarTypeScriptType(baseType, scalar_js_1.LongType.BIGINT));
36
38
  }
37
39
  else {
38
40
  typing.push({
@@ -53,17 +55,17 @@ function getFieldTypeInfo(field) {
53
55
  });
54
56
  optional =
55
57
  field.optional ||
56
- field.proto.label === protobuf_1.FieldDescriptorProto_Label.REQUIRED;
58
+ field.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED;
57
59
  typingInferrableFromZeroValue = true;
58
60
  break;
59
61
  case "map": {
60
62
  let keyType;
61
63
  switch (field.mapKey) {
62
- case protobuf_1.ScalarType.INT32:
63
- case protobuf_1.ScalarType.FIXED32:
64
- case protobuf_1.ScalarType.UINT32:
65
- case protobuf_1.ScalarType.SFIXED32:
66
- case protobuf_1.ScalarType.SINT32:
64
+ case scalar_js_1.ScalarType.INT32:
65
+ case scalar_js_1.ScalarType.FIXED32:
66
+ case scalar_js_1.ScalarType.UINT32:
67
+ case scalar_js_1.ScalarType.SFIXED32:
68
+ case scalar_js_1.ScalarType.SINT32:
67
69
  keyType = "number";
68
70
  break;
69
71
  default:
@@ -73,7 +75,7 @@ function getFieldTypeInfo(field) {
73
75
  let valueType;
74
76
  switch (field.mapValue.kind) {
75
77
  case "scalar":
76
- valueType = scalarTypeScriptType(field.mapValue.scalar, protobuf_1.LongType.BIGINT);
78
+ valueType = scalarTypeScriptType(field.mapValue.scalar, scalar_js_1.LongType.BIGINT);
77
79
  break;
78
80
  case "message":
79
81
  valueType = {
@@ -161,7 +163,7 @@ function getFieldZeroValueExpression(field, enumAs = "enum_value_as_is") {
161
163
  return literalEnumValue(zeroValue, enumAs);
162
164
  }
163
165
  case "scalar": {
164
- const defaultValue = protobuf_1.codegenInfo.scalarZeroValue(field.scalar, field.longType);
166
+ const defaultValue = codegen_info_js_1.codegenInfo.scalarZeroValue(field.scalar, field.longType);
165
167
  return literalScalarValue(defaultValue, field);
166
168
  }
167
169
  }
@@ -169,39 +171,39 @@ function getFieldZeroValueExpression(field, enumAs = "enum_value_as_is") {
169
171
  exports.getFieldZeroValueExpression = getFieldZeroValueExpression;
170
172
  function literalScalarValue(value, field) {
171
173
  switch (field.scalar) {
172
- case protobuf_1.ScalarType.DOUBLE:
173
- case protobuf_1.ScalarType.FLOAT:
174
- case protobuf_1.ScalarType.INT32:
175
- case protobuf_1.ScalarType.FIXED32:
176
- case protobuf_1.ScalarType.UINT32:
177
- case protobuf_1.ScalarType.SFIXED32:
178
- case protobuf_1.ScalarType.SINT32:
174
+ case scalar_js_1.ScalarType.DOUBLE:
175
+ case scalar_js_1.ScalarType.FLOAT:
176
+ case scalar_js_1.ScalarType.INT32:
177
+ case scalar_js_1.ScalarType.FIXED32:
178
+ case scalar_js_1.ScalarType.UINT32:
179
+ case scalar_js_1.ScalarType.SFIXED32:
180
+ case scalar_js_1.ScalarType.SINT32:
179
181
  if (typeof value != "number") {
180
- throw new Error(`Unexpected value for ${protobuf_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
182
+ throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
181
183
  }
182
184
  return value;
183
- case protobuf_1.ScalarType.BOOL:
185
+ case scalar_js_1.ScalarType.BOOL:
184
186
  if (typeof value != "boolean") {
185
- throw new Error(`Unexpected value for ${protobuf_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
187
+ throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
186
188
  }
187
189
  return value;
188
- case protobuf_1.ScalarType.STRING:
190
+ case scalar_js_1.ScalarType.STRING:
189
191
  if (typeof value != "string") {
190
- throw new Error(`Unexpected value for ${protobuf_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
192
+ throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
191
193
  }
192
194
  return { kind: "es_string", value };
193
- case protobuf_1.ScalarType.BYTES:
195
+ case scalar_js_1.ScalarType.BYTES:
194
196
  if (!(value instanceof Uint8Array)) {
195
- throw new Error(`Unexpected value for ${protobuf_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
197
+ throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
196
198
  }
197
199
  return value;
198
- case protobuf_1.ScalarType.INT64:
199
- case protobuf_1.ScalarType.SINT64:
200
- case protobuf_1.ScalarType.SFIXED64:
201
- case protobuf_1.ScalarType.UINT64:
202
- case protobuf_1.ScalarType.FIXED64:
200
+ case scalar_js_1.ScalarType.INT64:
201
+ case scalar_js_1.ScalarType.SINT64:
202
+ case scalar_js_1.ScalarType.SFIXED64:
203
+ case scalar_js_1.ScalarType.UINT64:
204
+ case scalar_js_1.ScalarType.FIXED64:
203
205
  if (typeof value != "bigint" && typeof value != "string") {
204
- throw new Error(`Unexpected value for ${protobuf_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
206
+ throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
205
207
  }
206
208
  return {
207
209
  kind: "es_proto_int64",
@@ -217,7 +219,7 @@ function literalEnumValue(value, enumAs) {
217
219
  return [
218
220
  { kind: "es_ref_enum", type: value.parent, typeOnly: false },
219
221
  ".",
220
- (0, ecmascript_1.localName)(value),
222
+ (0, names_js_1.localName)(value),
221
223
  ];
222
224
  case "enum_value_as_integer":
223
225
  return [
@@ -234,26 +236,26 @@ function literalEnumValue(value, enumAs) {
234
236
  " as ",
235
237
  { kind: "es_ref_enum", type: value.parent, typeOnly: true },
236
238
  ".",
237
- (0, ecmascript_1.localName)(value),
239
+ (0, names_js_1.localName)(value),
238
240
  ];
239
241
  }
240
242
  }
241
243
  function scalarTypeScriptType(type, longType) {
242
244
  switch (type) {
243
- case protobuf_1.ScalarType.STRING:
245
+ case scalar_js_1.ScalarType.STRING:
244
246
  return "string";
245
- case protobuf_1.ScalarType.BOOL:
247
+ case scalar_js_1.ScalarType.BOOL:
246
248
  return "boolean";
247
- case protobuf_1.ScalarType.UINT64:
248
- case protobuf_1.ScalarType.SFIXED64:
249
- case protobuf_1.ScalarType.FIXED64:
250
- case protobuf_1.ScalarType.SINT64:
251
- case protobuf_1.ScalarType.INT64:
252
- if (longType === protobuf_1.LongType.STRING) {
249
+ case scalar_js_1.ScalarType.UINT64:
250
+ case scalar_js_1.ScalarType.SFIXED64:
251
+ case scalar_js_1.ScalarType.FIXED64:
252
+ case scalar_js_1.ScalarType.SINT64:
253
+ case scalar_js_1.ScalarType.INT64:
254
+ if (longType === scalar_js_1.LongType.STRING) {
253
255
  return "string";
254
256
  }
255
257
  return "bigint";
256
- case protobuf_1.ScalarType.BYTES:
258
+ case scalar_js_1.ScalarType.BYTES:
257
259
  return "Uint8Array";
258
260
  default:
259
261
  return "number";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Read a 64 bit varint as two JS numbers.
3
+ *
4
+ * Returns tuple:
5
+ * [0]: low bits
6
+ * [1]: high bits
7
+ *
8
+ * Copyright 2008 Google Inc. All rights reserved.
9
+ *
10
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
11
+ */
12
+ export declare function varint64read(this: ReaderLike): [number, number];
13
+ /**
14
+ * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
15
+ *
16
+ * Copyright 2008 Google Inc. All rights reserved.
17
+ *
18
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
19
+ */
20
+ export declare function varint64write(lo: number, hi: number, bytes: number[]): void;
21
+ /**
22
+ * Parse decimal string of 64 bit integer value as two JS numbers.
23
+ *
24
+ * Copyright 2008 Google Inc. All rights reserved.
25
+ *
26
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
27
+ */
28
+ export declare function int64FromString(dec: string): {
29
+ lo: number;
30
+ hi: number;
31
+ };
32
+ /**
33
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
34
+ * into a decimal string.
35
+ *
36
+ * Copyright 2008 Google Inc. All rights reserved.
37
+ *
38
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
39
+ */
40
+ export declare function int64ToString(lo: number, hi: number): string;
41
+ /**
42
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
43
+ * into a decimal string.
44
+ *
45
+ * Copyright 2008 Google Inc. All rights reserved.
46
+ *
47
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
48
+ */
49
+ export declare function uInt64ToString(lo: number, hi: number): string;
50
+ /**
51
+ * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
52
+ *
53
+ * Copyright 2008 Google Inc. All rights reserved.
54
+ *
55
+ * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
56
+ */
57
+ export declare function varint32write(value: number, bytes: number[]): void;
58
+ /**
59
+ * Read an unsigned 32 bit varint.
60
+ *
61
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
62
+ */
63
+ export declare function varint32read(this: ReaderLike): number;
64
+ type ReaderLike = {
65
+ buf: Uint8Array;
66
+ pos: number;
67
+ len: number;
68
+ assertBounds(): void;
69
+ };
70
+ export {};
package/dist/varint.js ADDED
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ //
30
+ // Code generated by the Protocol Buffer compiler is owned by the owner
31
+ // of the input file used when generating it. This code is not
32
+ // standalone and requires a support library to be linked with it. This
33
+ // support library is itself covered by the above license.
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.varint32read = exports.varint32write = exports.uInt64ToString = exports.int64ToString = exports.int64FromString = exports.varint64write = exports.varint64read = void 0;
36
+ /* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
37
+ /**
38
+ * Read a 64 bit varint as two JS numbers.
39
+ *
40
+ * Returns tuple:
41
+ * [0]: low bits
42
+ * [1]: high bits
43
+ *
44
+ * Copyright 2008 Google Inc. All rights reserved.
45
+ *
46
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
47
+ */
48
+ function varint64read() {
49
+ let lowBits = 0;
50
+ let highBits = 0;
51
+ for (let shift = 0; shift < 28; shift += 7) {
52
+ let b = this.buf[this.pos++];
53
+ lowBits |= (b & 0x7f) << shift;
54
+ if ((b & 0x80) == 0) {
55
+ this.assertBounds();
56
+ return [lowBits, highBits];
57
+ }
58
+ }
59
+ let middleByte = this.buf[this.pos++];
60
+ // last four bits of the first 32 bit number
61
+ lowBits |= (middleByte & 0x0f) << 28;
62
+ // 3 upper bits are part of the next 32 bit number
63
+ highBits = (middleByte & 0x70) >> 4;
64
+ if ((middleByte & 0x80) == 0) {
65
+ this.assertBounds();
66
+ return [lowBits, highBits];
67
+ }
68
+ for (let shift = 3; shift <= 31; shift += 7) {
69
+ let b = this.buf[this.pos++];
70
+ highBits |= (b & 0x7f) << shift;
71
+ if ((b & 0x80) == 0) {
72
+ this.assertBounds();
73
+ return [lowBits, highBits];
74
+ }
75
+ }
76
+ throw new Error("invalid varint");
77
+ }
78
+ exports.varint64read = varint64read;
79
+ /**
80
+ * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
81
+ *
82
+ * Copyright 2008 Google Inc. All rights reserved.
83
+ *
84
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
85
+ */
86
+ function varint64write(lo, hi, bytes) {
87
+ for (let i = 0; i < 28; i = i + 7) {
88
+ const shift = lo >>> i;
89
+ const hasNext = !(shift >>> 7 == 0 && hi == 0);
90
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
91
+ bytes.push(byte);
92
+ if (!hasNext) {
93
+ return;
94
+ }
95
+ }
96
+ const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4);
97
+ const hasMoreBits = !(hi >> 3 == 0);
98
+ bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff);
99
+ if (!hasMoreBits) {
100
+ return;
101
+ }
102
+ for (let i = 3; i < 31; i = i + 7) {
103
+ const shift = hi >>> i;
104
+ const hasNext = !(shift >>> 7 == 0);
105
+ const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
106
+ bytes.push(byte);
107
+ if (!hasNext) {
108
+ return;
109
+ }
110
+ }
111
+ bytes.push((hi >>> 31) & 0x01);
112
+ }
113
+ exports.varint64write = varint64write;
114
+ // constants for binary math
115
+ const TWO_PWR_32_DBL = 0x100000000;
116
+ /**
117
+ * Parse decimal string of 64 bit integer value as two JS numbers.
118
+ *
119
+ * Copyright 2008 Google Inc. All rights reserved.
120
+ *
121
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
122
+ */
123
+ function int64FromString(dec) {
124
+ // Check for minus sign.
125
+ const minus = dec[0] === "-";
126
+ if (minus) {
127
+ dec = dec.slice(1);
128
+ }
129
+ // Work 6 decimal digits at a time, acting like we're converting base 1e6
130
+ // digits to binary. This is safe to do with floating point math because
131
+ // Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
132
+ const base = 1e6;
133
+ let lowBits = 0;
134
+ let highBits = 0;
135
+ function add1e6digit(begin, end) {
136
+ // Note: Number('') is 0.
137
+ const digit1e6 = Number(dec.slice(begin, end));
138
+ highBits *= base;
139
+ lowBits = lowBits * base + digit1e6;
140
+ // Carry bits from lowBits to
141
+ if (lowBits >= TWO_PWR_32_DBL) {
142
+ highBits = highBits + ((lowBits / TWO_PWR_32_DBL) | 0);
143
+ lowBits = lowBits % TWO_PWR_32_DBL;
144
+ }
145
+ }
146
+ add1e6digit(-24, -18);
147
+ add1e6digit(-18, -12);
148
+ add1e6digit(-12, -6);
149
+ add1e6digit(-6);
150
+ return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
151
+ }
152
+ exports.int64FromString = int64FromString;
153
+ /**
154
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
155
+ * into a decimal string.
156
+ *
157
+ * Copyright 2008 Google Inc. All rights reserved.
158
+ *
159
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
160
+ */
161
+ function int64ToString(lo, hi) {
162
+ let bits = newBits(lo, hi);
163
+ // If we're treating the input as a signed value and the high bit is set, do
164
+ // a manual two's complement conversion before the decimal conversion.
165
+ const negative = bits.hi & 0x80000000;
166
+ if (negative) {
167
+ bits = negate(bits.lo, bits.hi);
168
+ }
169
+ const result = uInt64ToString(bits.lo, bits.hi);
170
+ return negative ? "-" + result : result;
171
+ }
172
+ exports.int64ToString = int64ToString;
173
+ /**
174
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
175
+ * into a decimal string.
176
+ *
177
+ * Copyright 2008 Google Inc. All rights reserved.
178
+ *
179
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
180
+ */
181
+ function uInt64ToString(lo, hi) {
182
+ ({ lo, hi } = toUnsigned(lo, hi));
183
+ // Skip the expensive conversion if the number is small enough to use the
184
+ // built-in conversions.
185
+ // Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
186
+ // highBits <= 0x1FFFFF can be safely expressed with a double and retain
187
+ // integer precision.
188
+ // Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
189
+ if (hi <= 0x1fffff) {
190
+ return String(TWO_PWR_32_DBL * hi + lo);
191
+ }
192
+ // What this code is doing is essentially converting the input number from
193
+ // base-2 to base-1e7, which allows us to represent the 64-bit range with
194
+ // only 3 (very large) digits. Those digits are then trivial to convert to
195
+ // a base-10 string.
196
+ // The magic numbers used here are -
197
+ // 2^24 = 16777216 = (1,6777216) in base-1e7.
198
+ // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
199
+ // Split 32:32 representation into 16:24:24 representation so our
200
+ // intermediate digits don't overflow.
201
+ const low = lo & 0xffffff;
202
+ const mid = ((lo >>> 24) | (hi << 8)) & 0xffffff;
203
+ const high = (hi >> 16) & 0xffff;
204
+ // Assemble our three base-1e7 digits, ignoring carries. The maximum
205
+ // value in a digit at this step is representable as a 48-bit integer, which
206
+ // can be stored in a 64-bit floating point number.
207
+ let digitA = low + mid * 6777216 + high * 6710656;
208
+ let digitB = mid + high * 8147497;
209
+ let digitC = high * 2;
210
+ // Apply carries from A to B and from B to C.
211
+ const base = 10000000;
212
+ if (digitA >= base) {
213
+ digitB += Math.floor(digitA / base);
214
+ digitA %= base;
215
+ }
216
+ if (digitB >= base) {
217
+ digitC += Math.floor(digitB / base);
218
+ digitB %= base;
219
+ }
220
+ // If digitC is 0, then we should have returned in the trivial code path
221
+ // at the top for non-safe integers. Given this, we can assume both digitB
222
+ // and digitA need leading zeros.
223
+ return (digitC.toString() +
224
+ decimalFrom1e7WithLeadingZeros(digitB) +
225
+ decimalFrom1e7WithLeadingZeros(digitA));
226
+ }
227
+ exports.uInt64ToString = uInt64ToString;
228
+ function toUnsigned(lo, hi) {
229
+ return { lo: lo >>> 0, hi: hi >>> 0 };
230
+ }
231
+ function newBits(lo, hi) {
232
+ return { lo: lo | 0, hi: hi | 0 };
233
+ }
234
+ /**
235
+ * Returns two's compliment negation of input.
236
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
237
+ */
238
+ function negate(lowBits, highBits) {
239
+ highBits = ~highBits;
240
+ if (lowBits) {
241
+ lowBits = ~lowBits + 1;
242
+ }
243
+ else {
244
+ // If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
245
+ // adding 1 to that, results in 0x100000000, which leaves
246
+ // the low bits 0x0 and simply adds one to the high bits.
247
+ highBits += 1;
248
+ }
249
+ return newBits(lowBits, highBits);
250
+ }
251
+ /**
252
+ * Returns decimal representation of digit1e7 with leading zeros.
253
+ */
254
+ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
255
+ const partial = String(digit1e7);
256
+ return "0000000".slice(partial.length) + partial;
257
+ };
258
+ /**
259
+ * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
260
+ *
261
+ * Copyright 2008 Google Inc. All rights reserved.
262
+ *
263
+ * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
264
+ */
265
+ function varint32write(value, bytes) {
266
+ if (value >= 0) {
267
+ // write value as varint 32
268
+ while (value > 0x7f) {
269
+ bytes.push((value & 0x7f) | 0x80);
270
+ value = value >>> 7;
271
+ }
272
+ bytes.push(value);
273
+ }
274
+ else {
275
+ for (let i = 0; i < 9; i++) {
276
+ bytes.push((value & 127) | 128);
277
+ value = value >> 7;
278
+ }
279
+ bytes.push(1);
280
+ }
281
+ }
282
+ exports.varint32write = varint32write;
283
+ /**
284
+ * Read an unsigned 32 bit varint.
285
+ *
286
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
287
+ */
288
+ function varint32read() {
289
+ let b = this.buf[this.pos++];
290
+ let result = b & 0x7f;
291
+ if ((b & 0x80) == 0) {
292
+ this.assertBounds();
293
+ return result;
294
+ }
295
+ b = this.buf[this.pos++];
296
+ result |= (b & 0x7f) << 7;
297
+ if ((b & 0x80) == 0) {
298
+ this.assertBounds();
299
+ return result;
300
+ }
301
+ b = this.buf[this.pos++];
302
+ result |= (b & 0x7f) << 14;
303
+ if ((b & 0x80) == 0) {
304
+ this.assertBounds();
305
+ return result;
306
+ }
307
+ b = this.buf[this.pos++];
308
+ result |= (b & 0x7f) << 21;
309
+ if ((b & 0x80) == 0) {
310
+ this.assertBounds();
311
+ return result;
312
+ }
313
+ // Extract only last 4 bits
314
+ b = this.buf[this.pos++];
315
+ result |= (b & 0x0f) << 28;
316
+ for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++)
317
+ b = this.buf[this.pos++];
318
+ if ((b & 0x80) != 0)
319
+ throw new Error("invalid varint");
320
+ this.assertBounds();
321
+ // Result can have 32 bits, convert it to unsigned
322
+ return result >>> 0;
323
+ }
324
+ exports.varint32read = varint32read;
@@ -0,0 +1,87 @@
1
+ //
2
+
3
+ // @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
4
+ // @generated from file example/example.proto (package example, syntax proto3)
5
+ /* eslint-disable */
6
+
7
+ //
8
+
9
+ import type { MessageType, PartialFieldInfo } from "@aptre/protobuf-es-lite";
10
+ import { createEnumType, createMessageType, Message, Timestamp } from "../src/";
11
+
12
+ export const protobufPackage = "example";
13
+
14
+ /**
15
+ * ExampleEnum is an example enumeration.
16
+ *
17
+ *
18
+ * @generated from enum example.ExampleEnum
19
+ */
20
+ export enum ExampleEnum {
21
+ /**
22
+ * @generated from enum value: UNKNOWN = 0;
23
+ */
24
+ UNKNOWN = 0,
25
+
26
+ /**
27
+ * @generated from enum value: FIRST = 1;
28
+ */
29
+ FIRST = 1,
30
+
31
+ /**
32
+ * @generated from enum value: SECOND = 2;
33
+ */
34
+ SECOND = 2,
35
+ }
36
+
37
+ // ExampleEnum_Enum is the enum type for ExampleEnum.
38
+ export const ExampleEnum_Enum = createEnumType("example.ExampleEnum", [
39
+ { no: 0, name: "UNKNOWN" },
40
+ { no: 1, name: "FIRST" },
41
+ { no: 2, name: "SECOND" },
42
+ ]);
43
+
44
+ /**
45
+ * EchoMsg is the message body for Echo.
46
+ *
47
+ *
48
+ * @generated from message example.EchoMsg
49
+ */
50
+ export type EchoMsg = Message<{
51
+ /**
52
+ * @generated from field: string body = 1 [packed = false, default = "", jstype = JS_NORMAL];
53
+ */
54
+ body?: string;
55
+ /**
56
+ * @generated from field: google.protobuf.Timestamp ts = 2 [packed = false, default = , jstype = JS_NORMAL];
57
+ */
58
+ ts?: Timestamp;
59
+ /**
60
+ * @generated from field: example.ExampleEnum example_enum = 3 [packed = false, default = , jstype = JS_NORMAL];
61
+ */
62
+ exampleEnum?: ExampleEnum;
63
+ /**
64
+ * @generated from field: string example_string = 4 [packed = false, default = "", jstype = JS_NORMAL];
65
+ */
66
+ exampleString?: string;
67
+ /**
68
+ * @generated from field: repeated google.protobuf.Timestamp timestamps = 5 [packed = false, default = , jstype = JS_NORMAL];
69
+ */
70
+ timestamps?: Timestamp[];
71
+
72
+ }>;
73
+
74
+ export const EchoMsg: MessageType<EchoMsg> = createMessageType(
75
+ {
76
+ typeName: "example.EchoMsg",
77
+ fields: [
78
+ { no: 1, name: "body", kind: "scalar", T: 9 /* ScalarType.STRING */ },
79
+ { no: 2, name: "ts", kind: "message", T: () => Timestamp },
80
+ { no: 3, name: "example_enum", kind: "enum", T: ExampleEnum_Enum },
81
+ { no: 4, name: "example_string", kind: "scalar", T: 9 /* ScalarType.STRING */ },
82
+ { no: 5, name: "timestamps", kind: "message", T: () => Timestamp, repeated: true },
83
+ ] as readonly PartialFieldInfo[],
84
+ packedByDefault: true,
85
+ },
86
+ );
87
+
@@ -30,4 +30,5 @@ message EchoMsg {
30
30
  ExampleEnum example_enum = 3;
31
31
  string example_string = 4;
32
32
  }
33
+ repeated google.protobuf.Timestamp timestamps = 5;
33
34
  }
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "extends": "../tsconfig.json",
3
- "files": ["example_pb.ts"],
3
+ "files": ["example.pb.ts"],
4
4
  "compilerOptions": {
5
- "paths": {"@aptre/protobuf-es-lite": ["../", "../dist"]}
5
+ "paths": {
6
+ "@aptre/protobuf-es-lite": [
7
+ "../",
8
+ "../dist"
9
+ ],
10
+ "@aptre/protobuf-es-lite/google": ["../src/google", "../dist/google"],
11
+ }
6
12
  }
7
13
  }