@aptre/protobuf-es-lite 0.2.10 → 0.2.12
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.
- package/bin/protoc-gen-es-lite +2 -2
- package/dist/assert.js +4 -11
- package/dist/binary-encoding.js +69 -42
- package/dist/binary.js +87 -105
- package/dist/codegen-info.d.ts +0 -1
- package/dist/codegen-info.js +12 -16
- package/dist/create-descriptor-set.js +114 -118
- package/dist/descriptor-set.js +1 -2
- package/dist/enum.js +2 -7
- package/dist/feature-set.d.ts +1 -1
- package/dist/feature-set.js +18 -22
- package/dist/field-wrapper.js +12 -17
- package/dist/field.js +35 -34
- package/dist/google/index.js +9 -41
- package/dist/google/protobuf/any.pb.d.ts +2 -2
- package/dist/google/protobuf/any.pb.js +3 -6
- package/dist/google/protobuf/api.pb.d.ts +2 -2
- package/dist/google/protobuf/api.pb.js +56 -21
- package/dist/google/protobuf/compiler/plugin.pb.d.ts +2 -2
- package/dist/google/protobuf/compiler/plugin.pb.js +15 -18
- package/dist/google/protobuf/descriptor.pb.d.ts +19 -19
- package/dist/google/protobuf/descriptor.pb.js +831 -223
- package/dist/google/protobuf/duration.pb.d.ts +2 -2
- package/dist/google/protobuf/duration.pb.js +3 -6
- package/dist/google/protobuf/empty.pb.d.ts +2 -2
- package/dist/google/protobuf/empty.pb.js +3 -6
- package/dist/google/protobuf/source_context.pb.d.ts +2 -2
- package/dist/google/protobuf/source_context.pb.js +3 -6
- package/dist/google/protobuf/struct.pb.d.ts +3 -3
- package/dist/google/protobuf/struct.pb.js +31 -18
- package/dist/google/protobuf/timestamp.pb.d.ts +2 -2
- package/dist/google/protobuf/timestamp.pb.js +3 -6
- package/dist/google/protobuf/type.pb.d.ts +5 -5
- package/dist/google/protobuf/type.pb.js +74 -36
- package/dist/google/protobuf/wrappers.pb.d.ts +2 -2
- package/dist/google/protobuf/wrappers.pb.js +11 -14
- package/dist/index.js +12 -60
- package/dist/is-message.js +9 -16
- package/dist/json.d.ts +0 -9
- package/dist/json.js +72 -102
- package/dist/message.d.ts +3 -3
- package/dist/message.js +50 -57
- package/dist/names.js +12 -23
- package/dist/partial.js +15 -24
- package/dist/proto-base64.js +1 -4
- package/dist/proto-double.js +1 -4
- package/dist/proto-int64.js +9 -12
- package/dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js +4 -7
- package/dist/protoc-gen-es-lite/typescript.js +27 -36
- package/dist/protoplugin/create-es-plugin.js +14 -18
- package/dist/protoplugin/ecmascript/file-preamble.js +5 -9
- package/dist/protoplugin/ecmascript/generated-file.js +16 -20
- package/dist/protoplugin/ecmascript/import-path.js +13 -20
- package/dist/protoplugin/ecmascript/import-symbol.js +1 -5
- package/dist/protoplugin/ecmascript/index.js +2 -7
- package/dist/protoplugin/ecmascript/jsdoc.js +1 -5
- package/dist/protoplugin/ecmascript/opaque-printables.js +1 -2
- package/dist/protoplugin/ecmascript/parameter.js +10 -14
- package/dist/protoplugin/ecmascript/reify-wkt.js +12 -16
- package/dist/protoplugin/ecmascript/runtime-imports.js +5 -9
- package/dist/protoplugin/ecmascript/schema.js +16 -20
- package/dist/protoplugin/ecmascript/target.js +1 -2
- package/dist/protoplugin/ecmascript/transpile.js +15 -42
- package/dist/protoplugin/error.js +4 -10
- package/dist/protoplugin/index.js +2 -7
- package/dist/protoplugin/plugin.js +1 -2
- package/dist/protoplugin/run-node.js +6 -10
- package/dist/scalar.js +9 -15
- package/dist/service-type.js +4 -7
- package/dist/text-format.js +25 -30
- package/dist/unknown.js +7 -12
- package/dist/util.d.ts +1 -1
- package/dist/util.js +49 -55
- package/dist/varint.js +7 -17
- package/example/example.pb.ts +24 -18
- package/package.json +10 -7
- package/tsconfig.base.json +3 -3
- package/dist/type-registry.d.ts +0 -43
- package/dist/type-registry.js +0 -15
package/dist/text-format.js
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
19
|
+
assert(enumValue, `cannot parse ${descEnum.name} default value: ${value}`);
|
|
23
20
|
return enumValue.number;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
function parseTextFormatScalarValue(type, value) {
|
|
22
|
+
export function parseTextFormatScalarValue(type, value) {
|
|
27
23
|
switch (type) {
|
|
28
|
-
case
|
|
24
|
+
case ScalarType.STRING:
|
|
29
25
|
return value;
|
|
30
|
-
case
|
|
26
|
+
case ScalarType.BYTES: {
|
|
31
27
|
const u = unescapeBytesDefaultValue(value);
|
|
32
28
|
if (u === false) {
|
|
33
|
-
throw new Error(`cannot parse ${
|
|
29
|
+
throw new Error(`cannot parse ${ScalarType[type]} default value: ${value}`);
|
|
34
30
|
}
|
|
35
31
|
return u;
|
|
36
32
|
}
|
|
37
|
-
case
|
|
38
|
-
case
|
|
39
|
-
case
|
|
40
|
-
return
|
|
41
|
-
case
|
|
42
|
-
case
|
|
43
|
-
return
|
|
44
|
-
case
|
|
45
|
-
case
|
|
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
|
|
52
|
+
case ScalarType.BOOL:
|
|
57
53
|
return value === "true";
|
|
58
|
-
case
|
|
59
|
-
case
|
|
60
|
-
case
|
|
61
|
-
case
|
|
62
|
-
case
|
|
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 =
|
|
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);
|
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
|
-
|
|
6
|
-
function listUnknownFields(message) {
|
|
7
|
-
return message[
|
|
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[
|
|
17
|
-
m[
|
|
12
|
+
if (!Array.isArray(m[unknownFieldsSymbol])) {
|
|
13
|
+
m[unknownFieldsSymbol] = [];
|
|
18
14
|
}
|
|
19
|
-
m[
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 ===
|
|
28
|
+
field.proto.label === FieldDescriptorProto_Label.REQUIRED;
|
|
32
29
|
typingInferrableFromZeroValue = true;
|
|
33
30
|
break;
|
|
34
31
|
case "message": {
|
|
35
|
-
const baseType =
|
|
32
|
+
const baseType = codegenInfo.getUnwrappedFieldType(field);
|
|
36
33
|
if (baseType !== undefined) {
|
|
37
|
-
typing.push(scalarTypeScriptType(baseType,
|
|
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 ===
|
|
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
|
|
65
|
-
case
|
|
66
|
-
case
|
|
67
|
-
case
|
|
68
|
-
case
|
|
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,
|
|
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 =
|
|
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
|
|
175
|
-
case
|
|
176
|
-
case
|
|
177
|
-
case
|
|
178
|
-
case
|
|
179
|
-
case
|
|
180
|
-
case
|
|
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 ${
|
|
176
|
+
throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
|
|
183
177
|
}
|
|
184
178
|
return value;
|
|
185
|
-
case
|
|
179
|
+
case ScalarType.BOOL:
|
|
186
180
|
if (typeof value != "boolean") {
|
|
187
|
-
throw new Error(`Unexpected value for ${
|
|
181
|
+
throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
|
|
188
182
|
}
|
|
189
183
|
return value;
|
|
190
|
-
case
|
|
184
|
+
case ScalarType.STRING:
|
|
191
185
|
if (typeof value != "string") {
|
|
192
|
-
throw new Error(`Unexpected value for ${
|
|
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
|
|
189
|
+
case ScalarType.BYTES:
|
|
196
190
|
if (!(value instanceof Uint8Array)) {
|
|
197
|
-
throw new Error(`Unexpected value for ${
|
|
191
|
+
throw new Error(`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`);
|
|
198
192
|
}
|
|
199
193
|
return value;
|
|
200
|
-
case
|
|
201
|
-
case
|
|
202
|
-
case
|
|
203
|
-
case
|
|
204
|
-
case
|
|
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 ${
|
|
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
|
-
|
|
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
|
-
|
|
233
|
+
localName(value),
|
|
240
234
|
];
|
|
241
235
|
}
|
|
242
236
|
}
|
|
243
237
|
function scalarTypeScriptType(type, longType) {
|
|
244
238
|
switch (type) {
|
|
245
|
-
case
|
|
239
|
+
case ScalarType.STRING:
|
|
246
240
|
return "string";
|
|
247
|
-
case
|
|
241
|
+
case ScalarType.BOOL:
|
|
248
242
|
return "boolean";
|
|
249
|
-
case
|
|
250
|
-
case
|
|
251
|
-
case
|
|
252
|
-
case
|
|
253
|
-
case
|
|
254
|
-
if (longType ===
|
|
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
|
|
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/example/example.pb.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
1
|
// @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
|
|
4
2
|
// @generated from file example/example.proto (package example, syntax proto3)
|
|
5
3
|
/* eslint-disable */
|
|
6
4
|
|
|
7
|
-
//
|
|
8
|
-
|
|
9
5
|
import type { MessageType, PartialFieldInfo } from "@aptre/protobuf-es-lite";
|
|
10
6
|
import { createEnumType, createMessageType, Message, Timestamp } from "@aptre/protobuf-es-lite";
|
|
11
7
|
|
|
@@ -14,7 +10,6 @@ export const protobufPackage = "example";
|
|
|
14
10
|
/**
|
|
15
11
|
* ExampleEnum is an example enumeration.
|
|
16
12
|
*
|
|
17
|
-
*
|
|
18
13
|
* @generated from enum example.ExampleEnum
|
|
19
14
|
*/
|
|
20
15
|
export enum ExampleEnum {
|
|
@@ -44,30 +39,41 @@ export const ExampleEnum_Enum = createEnumType("example.ExampleEnum", [
|
|
|
44
39
|
/**
|
|
45
40
|
* EchoMsg is the message body for Echo.
|
|
46
41
|
*
|
|
47
|
-
*
|
|
48
42
|
* @generated from message example.EchoMsg
|
|
49
43
|
*/
|
|
50
44
|
export type EchoMsg = Message<{
|
|
51
45
|
/**
|
|
52
|
-
* @generated from field: string body = 1
|
|
46
|
+
* @generated from field: string body = 1;
|
|
53
47
|
*/
|
|
54
48
|
body?: string;
|
|
55
49
|
/**
|
|
56
|
-
* @generated from field: google.protobuf.Timestamp ts = 2
|
|
50
|
+
* @generated from field: google.protobuf.Timestamp ts = 2;
|
|
57
51
|
*/
|
|
58
52
|
ts?: Timestamp;
|
|
59
53
|
/**
|
|
60
|
-
* @generated from field:
|
|
54
|
+
* @generated from field: repeated google.protobuf.Timestamp timestamps = 5;
|
|
61
55
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* @generated from field: string example_string = 4 [packed = false, default = "", jstype = JS_NORMAL];
|
|
65
|
-
*/
|
|
66
|
-
exampleString?: string;
|
|
56
|
+
timestamps?: Timestamp[];
|
|
57
|
+
|
|
67
58
|
/**
|
|
68
|
-
* @generated from
|
|
59
|
+
* @generated from oneof example.EchoMsg.demo
|
|
69
60
|
*/
|
|
70
|
-
|
|
61
|
+
demo?: {
|
|
62
|
+
value?: undefined,
|
|
63
|
+
case: undefined
|
|
64
|
+
} | {
|
|
65
|
+
/**
|
|
66
|
+
* @generated from field: example.ExampleEnum example_enum = 3;
|
|
67
|
+
*/
|
|
68
|
+
value: ExampleEnum;
|
|
69
|
+
case: "exampleEnum";
|
|
70
|
+
} | {
|
|
71
|
+
/**
|
|
72
|
+
* @generated from field: string example_string = 4;
|
|
73
|
+
*/
|
|
74
|
+
value: string;
|
|
75
|
+
case: "exampleString";
|
|
76
|
+
};
|
|
71
77
|
|
|
72
78
|
}>;
|
|
73
79
|
|
|
@@ -77,8 +83,8 @@ export const EchoMsg: MessageType<EchoMsg> = createMessageType(
|
|
|
77
83
|
fields: [
|
|
78
84
|
{ no: 1, name: "body", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
79
85
|
{ 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
|
|
86
|
+
{ no: 3, name: "example_enum", kind: "enum", T: ExampleEnum_Enum, oneof: "demo" },
|
|
87
|
+
{ no: 4, name: "example_string", kind: "scalar", T: 9 /* ScalarType.STRING */, oneof: "demo" },
|
|
82
88
|
{ no: 5, name: "timestamps", kind: "message", T: () => Timestamp, repeated: true },
|
|
83
89
|
] as readonly PartialFieldInfo[],
|
|
84
90
|
packedByDefault: true,
|
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.
|
|
4
|
+
"version": "0.2.12",
|
|
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
|
-
"
|
|
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": {
|
package/tsconfig.base.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "Node16",
|
|
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
|
package/dist/type-registry.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { AnyMessage, Message, MessageType } from "./message.js";
|
|
2
|
-
import type { EnumType } from "./enum.js";
|
|
3
|
-
import type { ServiceType } from "./service-type.js";
|
|
4
|
-
/**
|
|
5
|
-
* IMessageTypeRegistry provides look-up for message types.
|
|
6
|
-
*
|
|
7
|
-
* You can conveniently create a registry using the createRegistry()
|
|
8
|
-
* function:
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { createRegistry } from "@bufbuild/protobuf";
|
|
12
|
-
* import { MyMessage, MyOtherMessage } from "./gen/my_message.pb.js";
|
|
13
|
-
*
|
|
14
|
-
* const reg: IMessageTypeRegistry = createRegistry(
|
|
15
|
-
* MyMessage,
|
|
16
|
-
* MyOtherMessage,
|
|
17
|
-
* );
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export interface IMessageTypeRegistry {
|
|
21
|
-
/**
|
|
22
|
-
* Find a message type by its protobuf type name.
|
|
23
|
-
*/
|
|
24
|
-
findMessage<T extends Message<T> = AnyMessage>(typeName: string): MessageType<T> | undefined;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* IEnumTypeRegistry provides look-up for enum types.
|
|
28
|
-
*/
|
|
29
|
-
export interface IEnumTypeRegistry {
|
|
30
|
-
/**
|
|
31
|
-
* Find an enum type by its protobuf type name.
|
|
32
|
-
*/
|
|
33
|
-
findEnum(typeName: string): EnumType | undefined;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* IServiceTypeRegistry provides look-up for service types.
|
|
37
|
-
*/
|
|
38
|
-
export interface IServiceTypeRegistry {
|
|
39
|
-
/**
|
|
40
|
-
* Find a service type by its protobuf type name.
|
|
41
|
-
*/
|
|
42
|
-
findService(typeName: string): ServiceType | undefined;
|
|
43
|
-
}
|