@aptre/protobuf-es-lite 0.2.10 → 0.2.11

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 (73) hide show
  1. package/bin/protoc-gen-es-lite +2 -2
  2. package/dist/assert.js +4 -11
  3. package/dist/binary-encoding.js +30 -35
  4. package/dist/binary.js +84 -96
  5. package/dist/codegen-info.js +12 -15
  6. package/dist/create-descriptor-set.js +113 -117
  7. package/dist/descriptor-set.js +1 -2
  8. package/dist/enum.js +2 -7
  9. package/dist/feature-set.js +16 -20
  10. package/dist/field-wrapper.js +12 -17
  11. package/dist/field.js +18 -27
  12. package/dist/google/index.js +9 -41
  13. package/dist/google/protobuf/any.pb.d.ts +2 -2
  14. package/dist/google/protobuf/any.pb.js +3 -6
  15. package/dist/google/protobuf/api.pb.d.ts +2 -2
  16. package/dist/google/protobuf/api.pb.js +14 -17
  17. package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
  18. package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
  19. package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
  20. package/dist/google/protobuf/descriptor.pb.js +156 -160
  21. package/dist/google/protobuf/duration.pb.d.ts +2 -2
  22. package/dist/google/protobuf/duration.pb.js +3 -6
  23. package/dist/google/protobuf/empty.pb.d.ts +2 -2
  24. package/dist/google/protobuf/empty.pb.js +3 -6
  25. package/dist/google/protobuf/source_context.pb.d.ts +2 -2
  26. package/dist/google/protobuf/source_context.pb.js +3 -6
  27. package/dist/google/protobuf/struct.pb.d.ts +3 -3
  28. package/dist/google/protobuf/struct.pb.js +13 -16
  29. package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
  30. package/dist/google/protobuf/timestamp.pb.js +3 -6
  31. package/dist/google/protobuf/type.pb.d.ts +5 -5
  32. package/dist/google/protobuf/type.pb.js +31 -34
  33. package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
  34. package/dist/google/protobuf/wrappers.pb.js +11 -14
  35. package/dist/index.js +12 -60
  36. package/dist/is-message.js +9 -16
  37. package/dist/json.js +72 -80
  38. package/dist/message.js +48 -55
  39. package/dist/names.js +12 -23
  40. package/dist/partial.js +13 -17
  41. package/dist/proto-base64.js +1 -4
  42. package/dist/proto-double.js +1 -4
  43. package/dist/proto-int64.js +9 -12
  44. package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
  45. package/dist/protoc-gen-es-lite/typescript.js +27 -36
  46. package/dist/protoplugin/create-es-plugin.js +13 -17
  47. package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
  48. package/dist/protoplugin/ecmascript/generated-file.js +16 -20
  49. package/dist/protoplugin/ecmascript/import-path.js +13 -20
  50. package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
  51. package/dist/protoplugin/ecmascript/index.js +2 -7
  52. package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
  53. package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
  54. package/dist/protoplugin/ecmascript/parameter.js +10 -14
  55. package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
  56. package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
  57. package/dist/protoplugin/ecmascript/schema.js +16 -20
  58. package/dist/protoplugin/ecmascript/target.js +1 -2
  59. package/dist/protoplugin/ecmascript/transpile.js +15 -42
  60. package/dist/protoplugin/error.js +3 -9
  61. package/dist/protoplugin/index.js +2 -7
  62. package/dist/protoplugin/plugin.js +1 -2
  63. package/dist/protoplugin/run-node.js +6 -10
  64. package/dist/scalar.js +9 -15
  65. package/dist/service-type.js +4 -7
  66. package/dist/text-format.js +25 -30
  67. package/dist/type-registry.js +1 -2
  68. package/dist/unknown.js +7 -12
  69. package/dist/util.d.ts +1 -1
  70. package/dist/util.js +49 -55
  71. package/dist/varint.js +7 -17
  72. package/package.json +10 -7
  73. package/tsconfig.base.json +2 -2
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,37 +11,34 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.parseTextFormatScalarValue = exports.parseTextFormatEnumValue = void 0;
17
- const assert_js_1 = require("./assert.js");
18
- const proto_int64_js_1 = require("./proto-int64.js");
19
- const scalar_js_1 = require("./scalar.js");
20
- function parseTextFormatEnumValue(descEnum, value) {
14
+ import { assert } from "./assert.js";
15
+ import { protoInt64 } from "./proto-int64.js";
16
+ import { ScalarType } from "./scalar.js";
17
+ export function parseTextFormatEnumValue(descEnum, value) {
21
18
  const enumValue = descEnum.values.find((v) => v.name === value);
22
- (0, assert_js_1.assert)(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
19
+ assert(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
23
20
  return enumValue.number;
24
21
  }
25
- exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
26
- function parseTextFormatScalarValue(type, value) {
22
+ export function parseTextFormatScalarValue(type, value) {
27
23
  switch (type) {
28
- case scalar_js_1.ScalarType.STRING:
24
+ case ScalarType.STRING:
29
25
  return value;
30
- case scalar_js_1.ScalarType.BYTES: {
26
+ case ScalarType.BYTES: {
31
27
  const u = unescapeBytesDefaultValue(value);
32
28
  if (u === false) {
33
- throw new Error(`cannot parse ${scalar_js_1.ScalarType[type]} default value: ${value}`);
29
+ throw new Error(`cannot parse ${ScalarType[type]} default value: ${value}`);
34
30
  }
35
31
  return u;
36
32
  }
37
- case scalar_js_1.ScalarType.INT64:
38
- case scalar_js_1.ScalarType.SFIXED64:
39
- case scalar_js_1.ScalarType.SINT64:
40
- return proto_int64_js_1.protoInt64.parse(value);
41
- case scalar_js_1.ScalarType.UINT64:
42
- case scalar_js_1.ScalarType.FIXED64:
43
- return proto_int64_js_1.protoInt64.uParse(value);
44
- case scalar_js_1.ScalarType.DOUBLE:
45
- case scalar_js_1.ScalarType.FLOAT:
33
+ case ScalarType.INT64:
34
+ case ScalarType.SFIXED64:
35
+ case ScalarType.SINT64:
36
+ return protoInt64.parse(value);
37
+ case ScalarType.UINT64:
38
+ case ScalarType.FIXED64:
39
+ return protoInt64.uParse(value);
40
+ case ScalarType.DOUBLE:
41
+ case ScalarType.FLOAT:
46
42
  switch (value) {
47
43
  case "inf":
48
44
  return Number.POSITIVE_INFINITY;
@@ -53,17 +49,16 @@ function parseTextFormatScalarValue(type, value) {
53
49
  default:
54
50
  return parseFloat(value);
55
51
  }
56
- case scalar_js_1.ScalarType.BOOL:
52
+ case ScalarType.BOOL:
57
53
  return value === "true";
58
- case scalar_js_1.ScalarType.INT32:
59
- case scalar_js_1.ScalarType.UINT32:
60
- case scalar_js_1.ScalarType.SINT32:
61
- case scalar_js_1.ScalarType.FIXED32:
62
- case scalar_js_1.ScalarType.SFIXED32:
54
+ case ScalarType.INT32:
55
+ case ScalarType.UINT32:
56
+ case ScalarType.SINT32:
57
+ case ScalarType.FIXED32:
58
+ case ScalarType.SFIXED32:
63
59
  return parseInt(value, 10);
64
60
  }
65
61
  }
66
- exports.parseTextFormatScalarValue = parseTextFormatScalarValue;
67
62
  /**
68
63
  * Parses a text-encoded default value (proto2) of a BYTES field.
69
64
  */
@@ -170,7 +165,7 @@ function unescapeBytesDefaultValue(str) {
170
165
  if (t === false) {
171
166
  return false;
172
167
  }
173
- const tc = proto_int64_js_1.protoInt64.uEnc(s + t);
168
+ const tc = protoInt64.uEnc(s + t);
174
169
  const chunk = new Uint8Array(8);
175
170
  const view = new DataView(chunk.buffer);
176
171
  view.setInt32(0, tc.lo, true);
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2021-2024 Buf Technologies, Inc.
3
2
  //
4
3
  // Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,4 +11,4 @@
12
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
12
  // See the License for the specific language governing permissions and
14
13
  // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
14
+ export {};
package/dist/unknown.js CHANGED
@@ -1,21 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleUnknownField = exports.listUnknownFields = exports.unknownFieldsSymbol = void 0;
4
1
  // unknownFieldsSymbol is the symbol used for unknown fields.
5
- exports.unknownFieldsSymbol = Symbol("@aptre/protobuf-es-lite/unknown-fields");
6
- function listUnknownFields(message) {
7
- return message[exports.unknownFieldsSymbol] ?? [];
2
+ export const unknownFieldsSymbol = Symbol("@aptre/protobuf-es-lite/unknown-fields");
3
+ export function listUnknownFields(message) {
4
+ return message[unknownFieldsSymbol] ?? [];
8
5
  }
9
- exports.listUnknownFields = listUnknownFields;
10
6
  // handleUnknownField stores an unknown field.
11
- function handleUnknownField(message, no, wireType, data) {
7
+ export function handleUnknownField(message, no, wireType, data) {
12
8
  if (typeof message !== "object") {
13
9
  return;
14
10
  }
15
11
  const m = message;
16
- if (!Array.isArray(m[exports.unknownFieldsSymbol])) {
17
- m[exports.unknownFieldsSymbol] = [];
12
+ if (!Array.isArray(m[unknownFieldsSymbol])) {
13
+ m[unknownFieldsSymbol] = [];
18
14
  }
19
- m[exports.unknownFieldsSymbol].push({ no, wireType, data });
15
+ m[unknownFieldsSymbol].push({ no, wireType, data });
20
16
  }
21
- exports.handleUnknownField = handleUnknownField;
package/dist/util.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Printable } from "./protoplugin/ecmascript";
1
+ import type { Printable } from "./protoplugin/ecmascript/index.js";
2
2
  import { DescExtension, DescField } from "./descriptor-set.js";
3
3
  export declare function getFieldTypeInfo(field: DescField | DescExtension): {
4
4
  typing: Printable;
package/dist/util.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2024 Aperture Robotics, LLC.
3
2
  // Copyright 2021-2024 Buf Technologies, Inc.
4
3
  //
@@ -13,13 +12,11 @@
13
12
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
13
  // See the License for the specific language governing permissions and
15
14
  // limitations under the License.
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getFieldZeroValueExpression = exports.getFieldDefaultValueExpression = exports.getFieldTypeInfo = void 0;
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");
22
- function getFieldTypeInfo(field) {
15
+ import { FieldDescriptorProto_Label } from "./google/protobuf/descriptor.pb.js";
16
+ import { codegenInfo } from "./codegen-info.js";
17
+ import { LongType, ScalarType } from "./scalar.js";
18
+ import { localName } from "./names.js";
19
+ export function getFieldTypeInfo(field) {
23
20
  const typing = [];
24
21
  let typingInferrableFromZeroValue;
25
22
  let optional = false;
@@ -28,13 +25,13 @@ function getFieldTypeInfo(field) {
28
25
  typing.push(scalarTypeScriptType(field.scalar, field.longType));
29
26
  optional =
30
27
  field.optional ||
31
- field.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED;
28
+ field.proto.label === FieldDescriptorProto_Label.REQUIRED;
32
29
  typingInferrableFromZeroValue = true;
33
30
  break;
34
31
  case "message": {
35
- const baseType = codegen_info_js_1.codegenInfo.getUnwrappedFieldType(field);
32
+ const baseType = codegenInfo.getUnwrappedFieldType(field);
36
33
  if (baseType !== undefined) {
37
- typing.push(scalarTypeScriptType(baseType, scalar_js_1.LongType.BIGINT));
34
+ typing.push(scalarTypeScriptType(baseType, LongType.BIGINT));
38
35
  }
39
36
  else {
40
37
  typing.push({
@@ -55,17 +52,17 @@ function getFieldTypeInfo(field) {
55
52
  });
56
53
  optional =
57
54
  field.optional ||
58
- field.proto.label === descriptor_pb_js_1.FieldDescriptorProto_Label.REQUIRED;
55
+ field.proto.label === FieldDescriptorProto_Label.REQUIRED;
59
56
  typingInferrableFromZeroValue = true;
60
57
  break;
61
58
  case "map": {
62
59
  let keyType;
63
60
  switch (field.mapKey) {
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:
61
+ case ScalarType.INT32:
62
+ case ScalarType.FIXED32:
63
+ case ScalarType.UINT32:
64
+ case ScalarType.SFIXED32:
65
+ case ScalarType.SINT32:
69
66
  keyType = "number";
70
67
  break;
71
68
  default:
@@ -75,7 +72,7 @@ function getFieldTypeInfo(field) {
75
72
  let valueType;
76
73
  switch (field.mapValue.kind) {
77
74
  case "scalar":
78
- valueType = scalarTypeScriptType(field.mapValue.scalar, scalar_js_1.LongType.BIGINT);
75
+ valueType = scalarTypeScriptType(field.mapValue.scalar, LongType.BIGINT);
79
76
  break;
80
77
  case "message":
81
78
  valueType = {
@@ -105,12 +102,11 @@ function getFieldTypeInfo(field) {
105
102
  }
106
103
  return { typing, optional, typingInferrableFromZeroValue };
107
104
  }
108
- exports.getFieldTypeInfo = getFieldTypeInfo;
109
105
  /**
110
106
  * Return a printable expression for the default value of a field.
111
107
  * Only applicable for singular scalar and enum fields.
112
108
  */
113
- function getFieldDefaultValueExpression(field, enumAs = "enum_value_as_is") {
109
+ export function getFieldDefaultValueExpression(field, enumAs = "enum_value_as_is") {
114
110
  if (field.repeated) {
115
111
  return undefined;
116
112
  }
@@ -133,7 +129,6 @@ function getFieldDefaultValueExpression(field, enumAs = "enum_value_as_is") {
133
129
  return literalScalarValue(defaultValue, field);
134
130
  }
135
131
  }
136
- exports.getFieldDefaultValueExpression = getFieldDefaultValueExpression;
137
132
  /**
138
133
  * Return a printable expression for the zero value of a field.
139
134
  *
@@ -144,7 +139,7 @@ exports.getFieldDefaultValueExpression = getFieldDefaultValueExpression;
144
139
  * - an enums first value
145
140
  * - scalar zero value
146
141
  */
147
- function getFieldZeroValueExpression(field, enumAs = "enum_value_as_is") {
142
+ export function getFieldZeroValueExpression(field, enumAs = "enum_value_as_is") {
148
143
  if (field.repeated) {
149
144
  return "[]";
150
145
  }
@@ -163,47 +158,46 @@ function getFieldZeroValueExpression(field, enumAs = "enum_value_as_is") {
163
158
  return literalEnumValue(zeroValue, enumAs);
164
159
  }
165
160
  case "scalar": {
166
- const defaultValue = codegen_info_js_1.codegenInfo.scalarZeroValue(field.scalar, field.longType);
161
+ const defaultValue = codegenInfo.scalarZeroValue(field.scalar, field.longType);
167
162
  return literalScalarValue(defaultValue, field);
168
163
  }
169
164
  }
170
165
  }
171
- exports.getFieldZeroValueExpression = getFieldZeroValueExpression;
172
166
  function literalScalarValue(value, field) {
173
167
  switch (field.scalar) {
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:
168
+ case ScalarType.DOUBLE:
169
+ case ScalarType.FLOAT:
170
+ case ScalarType.INT32:
171
+ case ScalarType.FIXED32:
172
+ case ScalarType.UINT32:
173
+ case ScalarType.SFIXED32:
174
+ case ScalarType.SINT32:
181
175
  if (typeof value != "number") {
182
- throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
176
+ throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
183
177
  }
184
178
  return value;
185
- case scalar_js_1.ScalarType.BOOL:
179
+ case ScalarType.BOOL:
186
180
  if (typeof value != "boolean") {
187
- throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
181
+ throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
188
182
  }
189
183
  return value;
190
- case scalar_js_1.ScalarType.STRING:
184
+ case ScalarType.STRING:
191
185
  if (typeof value != "string") {
192
- throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
186
+ throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
193
187
  }
194
188
  return { kind: "es_string", value };
195
- case scalar_js_1.ScalarType.BYTES:
189
+ case ScalarType.BYTES:
196
190
  if (!(value instanceof Uint8Array)) {
197
- throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
191
+ throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
198
192
  }
199
193
  return value;
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:
194
+ case ScalarType.INT64:
195
+ case ScalarType.SINT64:
196
+ case ScalarType.SFIXED64:
197
+ case ScalarType.UINT64:
198
+ case ScalarType.FIXED64:
205
199
  if (typeof value != "bigint" && typeof value != "string") {
206
- throw new Error(`Unexpected value for ${scalar_js_1.ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
200
+ throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
207
201
  }
208
202
  return {
209
203
  kind: "es_proto_int64",
@@ -219,7 +213,7 @@ function literalEnumValue(value, enumAs) {
219
213
  return [
220
214
  { kind: "es_ref_enum", type: value.parent, typeOnly: false },
221
215
  ".",
222
- (0, names_js_1.localName)(value),
216
+ localName(value),
223
217
  ];
224
218
  case "enum_value_as_integer":
225
219
  return [
@@ -236,26 +230,26 @@ function literalEnumValue(value, enumAs) {
236
230
  " as ",
237
231
  { kind: "es_ref_enum", type: value.parent, typeOnly: true },
238
232
  ".",
239
- (0, names_js_1.localName)(value),
233
+ localName(value),
240
234
  ];
241
235
  }
242
236
  }
243
237
  function scalarTypeScriptType(type, longType) {
244
238
  switch (type) {
245
- case scalar_js_1.ScalarType.STRING:
239
+ case ScalarType.STRING:
246
240
  return "string";
247
- case scalar_js_1.ScalarType.BOOL:
241
+ case ScalarType.BOOL:
248
242
  return "boolean";
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) {
243
+ case ScalarType.UINT64:
244
+ case ScalarType.SFIXED64:
245
+ case ScalarType.FIXED64:
246
+ case ScalarType.SINT64:
247
+ case ScalarType.INT64:
248
+ if (longType === LongType.STRING) {
255
249
  return "string";
256
250
  }
257
251
  return "bigint";
258
- case scalar_js_1.ScalarType.BYTES:
252
+ case ScalarType.BYTES:
259
253
  return "Uint8Array";
260
254
  default:
261
255
  return "number";
package/dist/varint.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2008 Google Inc. All rights reserved.
3
2
  //
4
3
  // Redistribution and use in source and binary forms, with or without
@@ -31,8 +30,6 @@
31
30
  // of the input file used when generating it. This code is not
32
31
  // standalone and requires a support library to be linked with it. This
33
32
  // 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
33
  /* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
37
34
  /**
38
35
  * Read a 64 bit varint as two JS numbers.
@@ -45,7 +42,7 @@ exports.varint32read = exports.varint32write = exports.uInt64ToString = exports.
45
42
  *
46
43
  * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
47
44
  */
48
- function varint64read() {
45
+ export function varint64read() {
49
46
  let lowBits = 0;
50
47
  let highBits = 0;
51
48
  for (let shift = 0; shift < 28; shift += 7) {
@@ -75,7 +72,6 @@ function varint64read() {
75
72
  }
76
73
  throw new Error("invalid varint");
77
74
  }
78
- exports.varint64read = varint64read;
79
75
  /**
80
76
  * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
81
77
  *
@@ -83,7 +79,7 @@ exports.varint64read = varint64read;
83
79
  *
84
80
  * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
85
81
  */
86
- function varint64write(lo, hi, bytes) {
82
+ export function varint64write(lo, hi, bytes) {
87
83
  for (let i = 0; i < 28; i = i + 7) {
88
84
  const shift = lo >>> i;
89
85
  const hasNext = !(shift >>> 7 == 0 && hi == 0);
@@ -110,7 +106,6 @@ function varint64write(lo, hi, bytes) {
110
106
  }
111
107
  bytes.push((hi >>> 31) & 0x01);
112
108
  }
113
- exports.varint64write = varint64write;
114
109
  // constants for binary math
115
110
  const TWO_PWR_32_DBL = 0x100000000;
116
111
  /**
@@ -120,7 +115,7 @@ const TWO_PWR_32_DBL = 0x100000000;
120
115
  *
121
116
  * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
122
117
  */
123
- function int64FromString(dec) {
118
+ export function int64FromString(dec) {
124
119
  // Check for minus sign.
125
120
  const minus = dec[0] === "-";
126
121
  if (minus) {
@@ -149,7 +144,6 @@ function int64FromString(dec) {
149
144
  add1e6digit(-6);
150
145
  return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
151
146
  }
152
- exports.int64FromString = int64FromString;
153
147
  /**
154
148
  * Losslessly converts a 64-bit signed integer in 32:32 split representation
155
149
  * into a decimal string.
@@ -158,7 +152,7 @@ exports.int64FromString = int64FromString;
158
152
  *
159
153
  * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
160
154
  */
161
- function int64ToString(lo, hi) {
155
+ export function int64ToString(lo, hi) {
162
156
  let bits = newBits(lo, hi);
163
157
  // If we're treating the input as a signed value and the high bit is set, do
164
158
  // a manual two's complement conversion before the decimal conversion.
@@ -169,7 +163,6 @@ function int64ToString(lo, hi) {
169
163
  const result = uInt64ToString(bits.lo, bits.hi);
170
164
  return negative ? "-" + result : result;
171
165
  }
172
- exports.int64ToString = int64ToString;
173
166
  /**
174
167
  * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
175
168
  * into a decimal string.
@@ -178,7 +171,7 @@ exports.int64ToString = int64ToString;
178
171
  *
179
172
  * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
180
173
  */
181
- function uInt64ToString(lo, hi) {
174
+ export function uInt64ToString(lo, hi) {
182
175
  ({ lo, hi } = toUnsigned(lo, hi));
183
176
  // Skip the expensive conversion if the number is small enough to use the
184
177
  // built-in conversions.
@@ -224,7 +217,6 @@ function uInt64ToString(lo, hi) {
224
217
  decimalFrom1e7WithLeadingZeros(digitB) +
225
218
  decimalFrom1e7WithLeadingZeros(digitA));
226
219
  }
227
- exports.uInt64ToString = uInt64ToString;
228
220
  function toUnsigned(lo, hi) {
229
221
  return { lo: lo >>> 0, hi: hi >>> 0 };
230
222
  }
@@ -262,7 +254,7 @@ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
262
254
  *
263
255
  * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
264
256
  */
265
- function varint32write(value, bytes) {
257
+ export function varint32write(value, bytes) {
266
258
  if (value >= 0) {
267
259
  // write value as varint 32
268
260
  while (value > 0x7f) {
@@ -279,13 +271,12 @@ function varint32write(value, bytes) {
279
271
  bytes.push(1);
280
272
  }
281
273
  }
282
- exports.varint32write = varint32write;
283
274
  /**
284
275
  * Read an unsigned 32 bit varint.
285
276
  *
286
277
  * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L220
287
278
  */
288
- function varint32read() {
279
+ export function varint32read() {
289
280
  let b = this.buf[this.pos++];
290
281
  let result = b & 0x7f;
291
282
  if ((b & 0x80) == 0) {
@@ -321,4 +312,3 @@ function varint32read() {
321
312
  // Result can have 32 bits, convert it to unsigned
322
313
  return result >>> 0;
323
314
  }
324
- exports.varint32read = varint32read;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aptre/protobuf-es-lite",
3
3
  "description": "Lightweight Protobuf codegen for TypeScript and JavaScript.",
4
- "version": "0.2.10",
4
+ "version": "0.2.11",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "url": "git+ssh://git@github.com/aperturerobotics/protobuf-es-lite.git"
@@ -20,24 +20,27 @@
20
20
  "bin": {
21
21
  "protoc-gen-es-lite": "bin/protoc-gen-es-lite"
22
22
  },
23
- "main": "./dist/index.js",
24
- "types": "./dist/index.d.ts",
23
+ "type": "module",
25
24
  "exports": {
26
25
  ".": {
27
26
  "import": "./dist/index.js",
28
- "require": "./dist/index.js"
27
+ "require": "./dist/index.js",
28
+ "types": "./dist/index.d.ts"
29
29
  },
30
30
  "./protoplugin": {
31
31
  "import": "./dist/protoplugin/index.js",
32
- "require": "./dist/protoplugin/index.js"
32
+ "require": "./dist/protoplugin/index.js",
33
+ "types": "./dist/protoplugin/index.d.ts"
33
34
  },
34
35
  "./protoplugin/ecmascript": {
35
36
  "import": "./dist/protoplugin/ecmascript/index.js",
36
- "require": "./dist/protoplugin/ecmascript/index.js"
37
+ "require": "./dist/protoplugin/ecmascript/index.js",
38
+ "types": "./dist/protoplugin/ecmascript/index.d.ts"
37
39
  },
38
40
  "./google": {
39
41
  "import": "./dist/google/index.js",
40
- "require": "./dist/google/index.js"
42
+ "require": "./dist/google/index.js",
43
+ "types": "./dist/google/index.d.ts"
41
44
  }
42
45
  },
43
46
  "engines": {
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "node",
4
6
  "esModuleInterop": false,
5
7
  "forceConsistentCasingInFileNames": true,
6
8
  "strict": true,
@@ -15,8 +17,6 @@
15
17
  "noImplicitReturns": true,
16
18
  "noFallthroughCasesInSwitch": true,
17
19
  "noImplicitOverride": true,
18
- "moduleResolution": "Node16",
19
- "module": "Node16",
20
20
  "verbatimModuleSyntax": true,
21
21
  "skipLibCheck": false,
22
22
  "declaration": true