@aptre/protobuf-es-lite 0.2.7 → 0.2.8

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 +3 -3
  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 +8 -3
  46. package/dist/index.js +38 -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/partial.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyPartialMessage = void 0;
4
- const protobuf_1 = require("@bufbuild/protobuf");
4
+ const field_js_1 = require("./field.js");
5
5
  const is_message_js_1 = require("./is-message.js");
6
+ const scalar_js_1 = require("./scalar.js");
6
7
  // applyPartialMessage applies a partial message to a message.
7
8
  function applyPartialMessage(source, target, fields) {
8
9
  if (source === undefined) {
@@ -23,16 +24,14 @@ function applyPartialMessage(source, target, fields) {
23
24
  const sourceField = member.findField(sk);
24
25
  let val = s[localName].value;
25
26
  if (sourceField?.kind == "message") {
26
- const messageType = typeof sourceField.T === "function"
27
- ? sourceField.T()
28
- : sourceField.T;
27
+ const messageType = (0, field_js_1.resolveMessageType)(sourceField.T);
29
28
  if (!(0, is_message_js_1.isCompleteMessage)(val, messageType.fields.list())) {
30
29
  val = messageType.create(val);
31
30
  }
32
31
  }
33
32
  else if (sourceField &&
34
33
  sourceField.kind === "scalar" &&
35
- sourceField.T === protobuf_1.ScalarType.BYTES) {
34
+ sourceField.T === scalar_js_1.ScalarType.BYTES) {
36
35
  val = toU8Arr(val);
37
36
  }
38
37
  t[localName] = { case: sk, value: val };
@@ -40,10 +39,11 @@ function applyPartialMessage(source, target, fields) {
40
39
  case "scalar":
41
40
  case "enum":
42
41
  let copy = s[localName];
43
- if (member.T === protobuf_1.ScalarType.BYTES) {
44
- copy = member.repeated
45
- ? copy.map(toU8Arr)
46
- : toU8Arr(copy);
42
+ if (member.T === scalar_js_1.ScalarType.BYTES) {
43
+ copy =
44
+ member.repeated ?
45
+ copy.map(toU8Arr)
46
+ : toU8Arr(copy);
47
47
  }
48
48
  t[localName] = copy;
49
49
  break;
@@ -51,7 +51,7 @@ function applyPartialMessage(source, target, fields) {
51
51
  switch (member.V.kind) {
52
52
  case "scalar":
53
53
  case "enum":
54
- if (member.V.T === protobuf_1.ScalarType.BYTES) {
54
+ if (member.V.T === scalar_js_1.ScalarType.BYTES) {
55
55
  for (const [k, v] of Object.entries(s[localName])) {
56
56
  t[localName][k] = toU8Arr(v);
57
57
  }
@@ -61,7 +61,7 @@ function applyPartialMessage(source, target, fields) {
61
61
  }
62
62
  break;
63
63
  case "message":
64
- const messageType = typeof member.V.T === "function" ? member.V.T() : member.V.T;
64
+ const messageType = (0, field_js_1.resolveMessageType)(member.V.T);
65
65
  for (const k of Object.keys(s[localName])) {
66
66
  let val = s[localName][k];
67
67
  if (!messageType.fieldWrapper) {
@@ -75,7 +75,7 @@ function applyPartialMessage(source, target, fields) {
75
75
  }
76
76
  break;
77
77
  case "message":
78
- const mt = typeof member.T === "function" ? member.T() : member.T;
78
+ const mt = (0, field_js_1.resolveMessageType)(member.T);
79
79
  if (member.repeated) {
80
80
  t[localName] = s[localName].map((val) => (0, is_message_js_1.isCompleteMessage)(val, mt.fields.list()) ? val : mt.create(val));
81
81
  }
@@ -93,9 +93,8 @@ function applyPartialMessage(source, target, fields) {
93
93
  }
94
94
  else {
95
95
  const messageType = mt;
96
- t[localName] = (0, is_message_js_1.isCompleteMessage)(val, messageType.fields.list())
97
- ? val
98
- : messageType.create(val);
96
+ t[localName] =
97
+ (0, is_message_js_1.isCompleteMessage)(val, messageType.fields.list()) ? val : (messageType.create(val));
99
98
  }
100
99
  }
101
100
  break;
@@ -0,0 +1,18 @@
1
+ export declare const protoBase64: {
2
+ /**
3
+ * Decodes a base64 string to a byte array.
4
+ *
5
+ * - ignores white-space, including line breaks and tabs
6
+ * - allows inner padding (can decode concatenated base64 strings)
7
+ * - does not require padding
8
+ * - understands base64url encoding:
9
+ * "-" instead of "+",
10
+ * "_" instead of "/",
11
+ * no padding
12
+ */
13
+ readonly dec: (base64Str: string) => Uint8Array;
14
+ /**
15
+ * Encode a byte array to a base64 string.
16
+ */
17
+ readonly enc: (bytes: Uint8Array) => string;
18
+ };
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.protoBase64 = void 0;
17
+ /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
18
+ // lookup table from base64 character to byte
19
+ let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
20
+ // lookup table from base64 character *code* to byte because lookup by number is fast
21
+ let decTable = [];
22
+ for (let i = 0; i < encTable.length; i++)
23
+ decTable[encTable[i].charCodeAt(0)] = i;
24
+ // support base64url variants
25
+ decTable["-".charCodeAt(0)] = encTable.indexOf("+");
26
+ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
27
+ exports.protoBase64 = {
28
+ /**
29
+ * Decodes a base64 string to a byte array.
30
+ *
31
+ * - ignores white-space, including line breaks and tabs
32
+ * - allows inner padding (can decode concatenated base64 strings)
33
+ * - does not require padding
34
+ * - understands base64url encoding:
35
+ * "-" instead of "+",
36
+ * "_" instead of "/",
37
+ * no padding
38
+ */
39
+ dec(base64Str) {
40
+ // estimate byte size, not accounting for inner padding and whitespace
41
+ let es = (base64Str.length * 3) / 4;
42
+ if (base64Str[base64Str.length - 2] == "=")
43
+ es -= 2;
44
+ else if (base64Str[base64Str.length - 1] == "=")
45
+ es -= 1;
46
+ let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
47
+ groupPos = 0, // position in base64 group
48
+ b, // current byte
49
+ p = 0; // previous byte
50
+ for (let i = 0; i < base64Str.length; i++) {
51
+ b = decTable[base64Str.charCodeAt(i)];
52
+ if (b === undefined) {
53
+ switch (base64Str[i]) {
54
+ // @ts-ignore TS7029: Fallthrough case in switch
55
+ case "=":
56
+ groupPos = 0; // reset state when padding found
57
+ // @ts-ignore TS7029: Fallthrough case in switch
58
+ case "\n":
59
+ case "\r":
60
+ case "\t":
61
+ case " ":
62
+ continue; // skip white-space, and padding
63
+ default:
64
+ throw Error("invalid base64 string.");
65
+ }
66
+ }
67
+ switch (groupPos) {
68
+ case 0:
69
+ p = b;
70
+ groupPos = 1;
71
+ break;
72
+ case 1:
73
+ bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
74
+ p = b;
75
+ groupPos = 2;
76
+ break;
77
+ case 2:
78
+ bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
79
+ p = b;
80
+ groupPos = 3;
81
+ break;
82
+ case 3:
83
+ bytes[bytePos++] = ((p & 3) << 6) | b;
84
+ groupPos = 0;
85
+ break;
86
+ }
87
+ }
88
+ if (groupPos == 1)
89
+ throw Error("invalid base64 string.");
90
+ return bytes.subarray(0, bytePos);
91
+ },
92
+ /**
93
+ * Encode a byte array to a base64 string.
94
+ */
95
+ enc(bytes) {
96
+ let base64 = "", groupPos = 0, // position in base64 group
97
+ b, // current byte
98
+ p = 0; // carry over from previous byte
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
+ // add output padding
120
+ if (groupPos) {
121
+ base64 += encTable[p];
122
+ base64 += "=";
123
+ if (groupPos == 1)
124
+ base64 += "=";
125
+ }
126
+ return base64;
127
+ },
128
+ };
@@ -0,0 +1,5 @@
1
+ export declare const protoDouble: {
2
+ readonly NaN: number;
3
+ readonly POSITIVE_INFINITY: number;
4
+ readonly NEGATIVE_INFINITY: number;
5
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.protoDouble = void 0;
17
+ // Export global Number constants. This is done so that we can safely use
18
+ // these global constants when generating code and be assured we're using
19
+ // the correct values. We cannot rely on globalThis since we support ES2017
20
+ // and globalThis was introduced in ES2020. We also don't want to explicitly
21
+ // generate code using, for example, Number.NaN, since this could clash with
22
+ // a message name of Number. Instead we can export them here since this will
23
+ // be in a different scope as the generated code and we are guaranteed to use
24
+ // the intended global values.
25
+ exports.protoDouble = {
26
+ NaN: Number.NaN,
27
+ POSITIVE_INFINITY: Number.POSITIVE_INFINITY,
28
+ NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY,
29
+ };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * We use the `bigint` primitive to represent 64-bit integral types. If bigint
3
+ * is unavailable, we fall back to a string representation, which means that
4
+ * all values typed as `bigint` will actually be strings.
5
+ *
6
+ * If your code is intended to run in an environment where bigint may be
7
+ * unavailable, it must handle both the bigint and the string representation.
8
+ * For presenting values, this is straight-forward with implicit or explicit
9
+ * conversion to string:
10
+ *
11
+ * ```ts
12
+ * let el = document.createElement("span");
13
+ * el.innerText = message.int64Field; // assuming a protobuf int64 field
14
+ *
15
+ * console.log(`int64: ${message.int64Field}`);
16
+ *
17
+ * let str: string = message.int64Field.toString();
18
+ * ```
19
+ *
20
+ * If you need to manipulate 64-bit integral values and are sure the values
21
+ * can be safely represented as an IEEE-754 double precision number, you can
22
+ * convert to a JavaScript Number:
23
+ *
24
+ * ```ts
25
+ * console.log(message.int64Field.toString())
26
+ * let num = Number(message.int64Field);
27
+ * num = num + 1;
28
+ * message.int64Field = protoInt64.parse(num);
29
+ * ```
30
+ *
31
+ * If you need to manipulate 64-bit integral values that are outside the
32
+ * range of safe representation as a JavaScript Number, we recommend you
33
+ * use a third party library, for example the npm package "long":
34
+ *
35
+ * ```ts
36
+ * // convert the field value to a Long
37
+ * const bits = protoInt64.enc(message.int64Field);
38
+ * const longValue = Long.fromBits(bits.lo, bits.hi);
39
+ *
40
+ * // perform arithmetic
41
+ * const longResult = longValue.subtract(1);
42
+ *
43
+ * // set the result in the field
44
+ * message.int64Field = protoInt64.dec(longResult.low, longResult.high);
45
+ *
46
+ * // Assuming int64Field contains 9223372036854775807:
47
+ * console.log(message.int64Field); // 9223372036854775806
48
+ * ```
49
+ */
50
+ interface Int64Support {
51
+ /**
52
+ * 0n if bigint is available, "0" if unavailable.
53
+ */
54
+ readonly zero: bigint;
55
+ /**
56
+ * Is bigint available?
57
+ */
58
+ readonly supported: boolean;
59
+ /**
60
+ * Parse a signed 64-bit integer.
61
+ * Returns a bigint if available, a string otherwise.
62
+ */
63
+ parse(value: string | number | bigint): bigint;
64
+ /**
65
+ * Parse an unsigned 64-bit integer.
66
+ * Returns a bigint if available, a string otherwise.
67
+ */
68
+ uParse(value: string | number | bigint): bigint;
69
+ /**
70
+ * Convert a signed 64-bit integral value to a two's complement.
71
+ */
72
+ enc(value: string | number | bigint): {
73
+ lo: number;
74
+ hi: number;
75
+ };
76
+ /**
77
+ * Convert an unsigned 64-bit integral value to a two's complement.
78
+ */
79
+ uEnc(value: string | number | bigint): {
80
+ lo: number;
81
+ hi: number;
82
+ };
83
+ /**
84
+ * Convert a two's complement to a signed 64-bit integral value.
85
+ * Returns a bigint if available, a string otherwise.
86
+ */
87
+ dec(lo: number, hi: number): bigint;
88
+ /**
89
+ * Convert a two's complement to an unsigned 64-bit integral value.
90
+ * Returns a bigint if available, a string otherwise.
91
+ */
92
+ uDec(lo: number, hi: number): bigint;
93
+ }
94
+ export declare const protoInt64: Int64Support;
95
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.protoInt64 = void 0;
17
+ const assert_js_1 = require("./assert.js");
18
+ const varint_js_1 = require("./varint.js");
19
+ function makeInt64Support() {
20
+ const dv = new DataView(new ArrayBuffer(8));
21
+ // note that Safari 14 implements BigInt, but not the DataView methods
22
+ const ok = typeof BigInt === "function" &&
23
+ typeof dv.getBigInt64 === "function" &&
24
+ typeof dv.getBigUint64 === "function" &&
25
+ typeof dv.setBigInt64 === "function" &&
26
+ typeof dv.setBigUint64 === "function" &&
27
+ (typeof process != "object" ||
28
+ typeof process.env != "object" ||
29
+ process.env.BUF_BIGINT_DISABLE !== "1");
30
+ if (ok) {
31
+ const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
32
+ return {
33
+ zero: BigInt(0),
34
+ supported: true,
35
+ parse(value) {
36
+ const bi = typeof value == "bigint" ? value : BigInt(value);
37
+ if (bi > MAX || bi < MIN) {
38
+ throw new Error(`int64 invalid: ${value}`);
39
+ }
40
+ return bi;
41
+ },
42
+ uParse(value) {
43
+ const bi = typeof value == "bigint" ? value : BigInt(value);
44
+ if (bi > UMAX || bi < UMIN) {
45
+ throw new Error(`uint64 invalid: ${value}`);
46
+ }
47
+ return bi;
48
+ },
49
+ enc(value) {
50
+ dv.setBigInt64(0, this.parse(value), true);
51
+ return {
52
+ lo: dv.getInt32(0, true),
53
+ hi: dv.getInt32(4, true),
54
+ };
55
+ },
56
+ uEnc(value) {
57
+ dv.setBigInt64(0, this.uParse(value), true);
58
+ return {
59
+ lo: dv.getInt32(0, true),
60
+ hi: dv.getInt32(4, true),
61
+ };
62
+ },
63
+ dec(lo, hi) {
64
+ dv.setInt32(0, lo, true);
65
+ dv.setInt32(4, hi, true);
66
+ return dv.getBigInt64(0, true);
67
+ },
68
+ uDec(lo, hi) {
69
+ dv.setInt32(0, lo, true);
70
+ dv.setInt32(4, hi, true);
71
+ return dv.getBigUint64(0, true);
72
+ },
73
+ };
74
+ }
75
+ const assertInt64String = (value) => (0, assert_js_1.assert)(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
76
+ const assertUInt64String = (value) => (0, assert_js_1.assert)(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
77
+ return {
78
+ zero: "0",
79
+ supported: false,
80
+ parse(value) {
81
+ if (typeof value != "string") {
82
+ value = value.toString();
83
+ }
84
+ assertInt64String(value);
85
+ return value;
86
+ },
87
+ uParse(value) {
88
+ if (typeof value != "string") {
89
+ value = value.toString();
90
+ }
91
+ assertUInt64String(value);
92
+ return value;
93
+ },
94
+ enc(value) {
95
+ if (typeof value != "string") {
96
+ value = value.toString();
97
+ }
98
+ assertInt64String(value);
99
+ return (0, varint_js_1.int64FromString)(value);
100
+ },
101
+ uEnc(value) {
102
+ if (typeof value != "string") {
103
+ value = value.toString();
104
+ }
105
+ assertUInt64String(value);
106
+ return (0, varint_js_1.int64FromString)(value);
107
+ },
108
+ dec(lo, hi) {
109
+ return (0, varint_js_1.int64ToString)(lo, hi);
110
+ },
111
+ uDec(lo, hi) {
112
+ return (0, varint_js_1.uInt64ToString)(lo, hi);
113
+ },
114
+ };
115
+ }
116
+ exports.protoInt64 = makeInt64Support();
@@ -0,0 +1 @@
1
+ export declare const protocGenEsLite: import("../protoplugin/plugin.js").Plugin;
@@ -15,10 +15,10 @@
15
15
  // limitations under the License.
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.protocGenEsLite = void 0;
18
- const protoplugin_1 = require("@bufbuild/protoplugin");
18
+ const index_js_1 = require("../protoplugin/index.js");
19
19
  const typescript_js_1 = require("./typescript.js");
20
20
  // import { version } from "../package.json";
21
- exports.protocGenEsLite = (0, protoplugin_1.createEcmaScriptPlugin)({
21
+ exports.protocGenEsLite = (0, index_js_1.createEcmaScriptPlugin)({
22
22
  name: "protoc-gen-es-lite",
23
23
  version: `unknown`,
24
24
  generateTs: typescript_js_1.generateTs,
@@ -1,6 +1,7 @@
1
- import type { DescEnum, DescExtension, DescField, DescFile, DescMessage } from "@bufbuild/protobuf";
2
- import type { GeneratedFile, ImportSymbol, Printable, Schema } from "@bufbuild/protoplugin/ecmascript";
1
+ import type { GeneratedFile, ImportSymbol, Printable, Schema } from "../protoplugin/ecmascript/index.js";
2
+ import { DescEnum, DescExtension, DescField, DescFile, DescMessage } from "../descriptor-set.js";
3
3
  export declare function generateTs(schema: Schema): void;
4
+ export declare function checkSupportedSyntax(file: DescFile): void;
4
5
  export declare function makeImportPath(file: DescFile): string;
5
6
  export declare function generateFieldInfo(f: GeneratedFile, field: DescField | DescExtension): void;
6
7
  export declare const createTypeImport: (desc: DescMessage | DescEnum | DescExtension) => ImportSymbol;