@aptre/protobuf-es-lite 0.2.11 → 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/dist/binary-encoding.js +41 -9
- package/dist/binary.js +6 -12
- package/dist/codegen-info.d.ts +0 -1
- package/dist/codegen-info.js +0 -1
- package/dist/create-descriptor-set.js +1 -1
- package/dist/feature-set.d.ts +1 -1
- package/dist/feature-set.js +3 -3
- package/dist/field.js +17 -7
- package/dist/google/protobuf/api.pb.js +45 -7
- package/dist/google/protobuf/descriptor.pb.js +720 -108
- package/dist/google/protobuf/struct.pb.js +19 -3
- package/dist/google/protobuf/type.pb.js +48 -7
- package/dist/json.d.ts +0 -9
- package/dist/json.js +0 -22
- package/dist/message.d.ts +3 -3
- package/dist/message.js +2 -2
- package/dist/partial.js +7 -12
- package/dist/protoplugin/create-es-plugin.js +3 -3
- package/dist/protoplugin/error.js +1 -1
- package/example/example.pb.ts +24 -18
- package/package.json +1 -1
- package/tsconfig.base.json +3 -3
- package/dist/type-registry.d.ts +0 -43
- package/dist/type-registry.js +0 -14
package/dist/binary-encoding.js
CHANGED
|
@@ -58,11 +58,32 @@ export var WireType;
|
|
|
58
58
|
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
59
59
|
})(WireType || (WireType = {}));
|
|
60
60
|
export class BinaryWriter {
|
|
61
|
+
/**
|
|
62
|
+
* We cannot allocate a buffer for the entire output
|
|
63
|
+
* because we don't know it's size.
|
|
64
|
+
*
|
|
65
|
+
* So we collect smaller chunks of known size and
|
|
66
|
+
* concat them later.
|
|
67
|
+
*
|
|
68
|
+
* Use `raw()` to push data to this array. It will flush
|
|
69
|
+
* `buf` first.
|
|
70
|
+
*/
|
|
71
|
+
chunks;
|
|
72
|
+
/**
|
|
73
|
+
* A growing buffer for byte values. If you don't know
|
|
74
|
+
* the size of the data you are writing, push to this
|
|
75
|
+
* array.
|
|
76
|
+
*/
|
|
77
|
+
buf;
|
|
78
|
+
/**
|
|
79
|
+
* Previous fork states.
|
|
80
|
+
*/
|
|
81
|
+
stack = [];
|
|
82
|
+
/**
|
|
83
|
+
* Text encoder instance to convert UTF-8 to bytes.
|
|
84
|
+
*/
|
|
85
|
+
textEncoder;
|
|
61
86
|
constructor(textEncoder) {
|
|
62
|
-
/**
|
|
63
|
-
* Previous fork states.
|
|
64
|
-
*/
|
|
65
|
-
this.stack = [];
|
|
66
87
|
this.textEncoder = textEncoder ?? new TextEncoder();
|
|
67
88
|
this.chunks = [];
|
|
68
89
|
this.buf = [];
|
|
@@ -268,12 +289,18 @@ export class BinaryWriter {
|
|
|
268
289
|
}
|
|
269
290
|
}
|
|
270
291
|
export class BinaryReader {
|
|
292
|
+
/**
|
|
293
|
+
* Current position.
|
|
294
|
+
*/
|
|
295
|
+
pos;
|
|
296
|
+
/**
|
|
297
|
+
* Number of bytes available in this reader.
|
|
298
|
+
*/
|
|
299
|
+
len;
|
|
300
|
+
buf;
|
|
301
|
+
view;
|
|
302
|
+
textDecoder;
|
|
271
303
|
constructor(buf, textDecoder) {
|
|
272
|
-
this.varint64 = varint64read; // dirty cast for `this`
|
|
273
|
-
/**
|
|
274
|
-
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
275
|
-
*/
|
|
276
|
-
this.uint32 = varint32read; // dirty cast for `this` and access to protected `buf`
|
|
277
304
|
this.buf = buf;
|
|
278
305
|
this.len = buf.length;
|
|
279
306
|
this.pos = 0;
|
|
@@ -327,6 +354,7 @@ export class BinaryReader {
|
|
|
327
354
|
this.assertBounds();
|
|
328
355
|
return this.buf.subarray(start, this.pos);
|
|
329
356
|
}
|
|
357
|
+
varint64 = varint64read; // dirty cast for `this`
|
|
330
358
|
/**
|
|
331
359
|
* Throws error if position in byte array is out of range.
|
|
332
360
|
*/
|
|
@@ -334,6 +362,10 @@ export class BinaryReader {
|
|
|
334
362
|
if (this.pos > this.len)
|
|
335
363
|
throw new RangeError("premature EOF");
|
|
336
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
367
|
+
*/
|
|
368
|
+
uint32 = varint32read; // dirty cast for `this` and access to protected `buf`
|
|
337
369
|
/**
|
|
338
370
|
* Read a `int32` field, a signed 32 bit varint.
|
|
339
371
|
*/
|
package/dist/binary.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isFieldSet, resolveMessageType, } from "./field.js";
|
|
2
|
-
import { isCompleteMessage } from "./is-message.js";
|
|
3
2
|
import { handleUnknownField, unknownFieldsSymbol } from "./unknown.js";
|
|
4
3
|
import { wrapField } from "./field-wrapper.js";
|
|
5
4
|
import { LongType, ScalarType, scalarZeroValue, } from "./scalar.js";
|
|
@@ -59,17 +58,12 @@ reader, field, wireType, options) {
|
|
|
59
58
|
if (!Array.isArray(tgtArr)) {
|
|
60
59
|
tgtArr = target[localName] = [];
|
|
61
60
|
}
|
|
62
|
-
tgtArr.push(readMessageField(reader,
|
|
61
|
+
tgtArr.push(readMessageField(reader, {}, messageType.fields, options, field));
|
|
63
62
|
}
|
|
64
63
|
else {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
else {
|
|
69
|
-
target[localName] = readMessageField(reader, messageType.create(), messageType.fields, options, field);
|
|
70
|
-
if (messageType.fieldWrapper && !field.oneof && !field.repeated) {
|
|
71
|
-
target[localName] = messageType.fieldWrapper.unwrapField(target[localName]);
|
|
72
|
-
}
|
|
64
|
+
target[localName] = readMessageField(reader, {}, messageType.fields, options, field);
|
|
65
|
+
if (messageType.fieldWrapper && !field.oneof && !field.repeated) {
|
|
66
|
+
target[localName] = messageType.fieldWrapper.unwrapField(target[localName]);
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
69
|
break;
|
|
@@ -103,7 +97,7 @@ export function readMapEntry(field, reader, options) {
|
|
|
103
97
|
break;
|
|
104
98
|
case "message":
|
|
105
99
|
const messageType = resolveMessageType(field.V.T);
|
|
106
|
-
val = readMessageField(reader,
|
|
100
|
+
val = readMessageField(reader, {}, messageType.fields, options, undefined);
|
|
107
101
|
break;
|
|
108
102
|
}
|
|
109
103
|
break;
|
|
@@ -125,7 +119,7 @@ export function readMapEntry(field, reader, options) {
|
|
|
125
119
|
val = field.V.T.values[0].no;
|
|
126
120
|
break;
|
|
127
121
|
case "message":
|
|
128
|
-
val =
|
|
122
|
+
val = {};
|
|
129
123
|
break;
|
|
130
124
|
}
|
|
131
125
|
}
|
package/dist/codegen-info.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export declare const codegenInfo: {
|
|
|
32
32
|
readonly LongType: RuntimeSymbolInfo;
|
|
33
33
|
readonly MethodKind: RuntimeSymbolInfo;
|
|
34
34
|
readonly MethodIdempotency: RuntimeSymbolInfo;
|
|
35
|
-
readonly IMessageTypeRegistry: RuntimeSymbolInfo;
|
|
36
35
|
readonly createEnumType: RuntimeSymbolInfo;
|
|
37
36
|
readonly createMessageType: RuntimeSymbolInfo;
|
|
38
37
|
};
|
package/dist/codegen-info.js
CHANGED
|
@@ -39,7 +39,6 @@ const symbols = {
|
|
|
39
39
|
LongType: symbolInfo(false, "./scalar.js"),
|
|
40
40
|
MethodKind: symbolInfo(false, "./service-type.js"),
|
|
41
41
|
MethodIdempotency: symbolInfo(false, "./service-type.js"),
|
|
42
|
-
IMessageTypeRegistry: symbolInfo(true, "./type-registry.js"),
|
|
43
42
|
createEnumType: symbolInfo(false, "./enum.js"),
|
|
44
43
|
createMessageType: symbolInfo(false, "./message.js"),
|
|
45
44
|
};
|
|
@@ -691,7 +691,7 @@ function findOneof(proto, allOneofs) {
|
|
|
691
691
|
return undefined;
|
|
692
692
|
}
|
|
693
693
|
let oneof;
|
|
694
|
-
if (proto.proto3Optional) {
|
|
694
|
+
if (!proto.proto3Optional) {
|
|
695
695
|
oneof = allOneofs[oneofIndex];
|
|
696
696
|
assert(oneof, `invalid FieldDescriptorProto: oneof #${oneofIndex} for field #${proto.number ?? -1} not found`);
|
|
697
697
|
}
|
package/dist/feature-set.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export type MergedFeatureSet = FeatureSet & Required<FeatureSet>;
|
|
|
14
14
|
export type FeatureResolverFn = (a?: FeatureSet, b?: FeatureSet) => MergedFeatureSet;
|
|
15
15
|
/**
|
|
16
16
|
* Create an edition feature resolver with the given feature set defaults, or
|
|
17
|
-
* the feature set defaults supported by @
|
|
17
|
+
* the feature set defaults supported by @aptre/protobuf-es-lite.
|
|
18
18
|
*/
|
|
19
19
|
export declare function createFeatureResolver(edition: Edition, compiledFeatureSetDefaults?: FeatureSetDefaults, serializationOptions?: Partial<BinaryReadOptions & BinaryWriteOptions>): FeatureResolverFn;
|
package/dist/feature-set.js
CHANGED
|
@@ -15,14 +15,14 @@ import { Edition, FeatureSet, FeatureSetDefaults, } from "./google/protobuf/desc
|
|
|
15
15
|
import { protoBase64 } from "./proto-base64.js";
|
|
16
16
|
import { applyPartialMessage } from "./partial.js";
|
|
17
17
|
/**
|
|
18
|
-
* Return the edition feature defaults supported by @
|
|
18
|
+
* Return the edition feature defaults supported by @aptre/protobuf-es-lite.
|
|
19
19
|
*/
|
|
20
20
|
function getFeatureSetDefaults(options) {
|
|
21
21
|
return FeatureSetDefaults.fromBinary(protoBase64.dec("ChESDAgBEAIYAiADKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH"), options);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Create an edition feature resolver with the given feature set defaults, or
|
|
25
|
-
* the feature set defaults supported by @
|
|
25
|
+
* the feature set defaults supported by @aptre/protobuf-es-lite.
|
|
26
26
|
*/
|
|
27
27
|
export function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
|
|
28
28
|
const fds = FeatureSetDefaults.create(compiledFeatureSetDefaults ?? getFeatureSetDefaults(serializationOptions));
|
|
@@ -48,7 +48,7 @@ export function createFeatureResolver(edition, compiledFeatureSetDefaults, seria
|
|
|
48
48
|
}
|
|
49
49
|
highestMatch = {
|
|
50
50
|
e,
|
|
51
|
-
f: c.features ??
|
|
51
|
+
f: c.features ?? {},
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
if (highestMatch === undefined) {
|
package/dist/field.js
CHANGED
|
@@ -5,6 +5,13 @@ import { localFieldName, localOneofName, protoCamelCase } from "./names.js";
|
|
|
5
5
|
* Provides convenient access to field information of a message type.
|
|
6
6
|
*/
|
|
7
7
|
export class FieldList {
|
|
8
|
+
_fields;
|
|
9
|
+
_normalizer;
|
|
10
|
+
all;
|
|
11
|
+
numbersAsc;
|
|
12
|
+
jsonNames;
|
|
13
|
+
numbers;
|
|
14
|
+
members;
|
|
8
15
|
constructor(fields, normalizer) {
|
|
9
16
|
this._fields = fields;
|
|
10
17
|
this._normalizer = normalizer;
|
|
@@ -125,14 +132,17 @@ export function resolveMessageType(t) {
|
|
|
125
132
|
}
|
|
126
133
|
// InternarlOneofInfo implements OneofInfo.
|
|
127
134
|
export class InternalOneofInfo {
|
|
135
|
+
kind = "oneof";
|
|
136
|
+
name;
|
|
137
|
+
localName;
|
|
138
|
+
repeated = false;
|
|
139
|
+
packed = false;
|
|
140
|
+
opt = false;
|
|
141
|
+
req = false;
|
|
142
|
+
default = undefined;
|
|
143
|
+
fields = [];
|
|
144
|
+
_lookup;
|
|
128
145
|
constructor(name) {
|
|
129
|
-
this.kind = "oneof";
|
|
130
|
-
this.repeated = false;
|
|
131
|
-
this.packed = false;
|
|
132
|
-
this.opt = false;
|
|
133
|
-
this.req = false;
|
|
134
|
-
this.default = undefined;
|
|
135
|
-
this.fields = [];
|
|
136
146
|
this.name = name;
|
|
137
147
|
this.localName = localOneofName(name);
|
|
138
148
|
}
|
|
@@ -35,11 +35,37 @@ export const Method = createMessageType({
|
|
|
35
35
|
typeName: "google.protobuf.Method",
|
|
36
36
|
fields: [
|
|
37
37
|
{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
38
|
-
{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
{
|
|
39
|
+
no: 2,
|
|
40
|
+
name: "request_type_url",
|
|
41
|
+
kind: "scalar",
|
|
42
|
+
T: 9 /* ScalarType.STRING */,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
no: 3,
|
|
46
|
+
name: "request_streaming",
|
|
47
|
+
kind: "scalar",
|
|
48
|
+
T: 8 /* ScalarType.BOOL */,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
no: 4,
|
|
52
|
+
name: "response_type_url",
|
|
53
|
+
kind: "scalar",
|
|
54
|
+
T: 9 /* ScalarType.STRING */,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
no: 5,
|
|
58
|
+
name: "response_streaming",
|
|
59
|
+
kind: "scalar",
|
|
60
|
+
T: 8 /* ScalarType.BOOL */,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
no: 6,
|
|
64
|
+
name: "options",
|
|
65
|
+
kind: "message",
|
|
66
|
+
T: () => Option,
|
|
67
|
+
repeated: true,
|
|
68
|
+
},
|
|
43
69
|
{ no: 7, name: "syntax", kind: "enum", T: Syntax_Enum },
|
|
44
70
|
],
|
|
45
71
|
packedByDefault: true,
|
|
@@ -56,8 +82,20 @@ export const Api = createMessageType({
|
|
|
56
82
|
typeName: "google.protobuf.Api",
|
|
57
83
|
fields: [
|
|
58
84
|
{ no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
59
|
-
{
|
|
60
|
-
|
|
85
|
+
{
|
|
86
|
+
no: 2,
|
|
87
|
+
name: "methods",
|
|
88
|
+
kind: "message",
|
|
89
|
+
T: () => Method,
|
|
90
|
+
repeated: true,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
no: 3,
|
|
94
|
+
name: "options",
|
|
95
|
+
kind: "message",
|
|
96
|
+
T: () => Option,
|
|
97
|
+
repeated: true,
|
|
98
|
+
},
|
|
61
99
|
{ no: 4, name: "version", kind: "scalar", T: 9 /* ScalarType.STRING */ },
|
|
62
100
|
{ no: 5, name: "source_context", kind: "message", T: () => SourceContext },
|
|
63
101
|
{ no: 6, name: "mixins", kind: "message", T: () => Mixin, repeated: true },
|