@aptre/protobuf-es-lite 0.2.11 → 0.2.13

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.
@@ -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, messageType.create(), messageType.fields, options, field));
61
+ tgtArr.push(readMessageField(reader, {}, messageType.fields, options, field));
63
62
  }
64
63
  else {
65
- if (isCompleteMessage(target[localName], messageType.fields.list())) {
66
- readMessageField(reader, target[localName], messageType.fields, options, field);
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, messageType.create(), messageType.fields, options, undefined);
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 = resolveMessageType(field.V.T).create();
122
+ val = {};
129
123
  break;
130
124
  }
131
125
  }
@@ -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
  };
@@ -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
  }
@@ -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 @bufbuild/protobuf.
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;
@@ -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 @bufbuild/protobuf.
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 @bufbuild/protobuf.
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 ?? FeatureSet.create(),
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
  }
@@ -89,7 +89,6 @@ export declare const protobufPackage = "google.protobuf";
89
89
  * }
90
90
  *
91
91
  *
92
- *
93
92
  * @generated from message google.protobuf.Any
94
93
  */
95
94
  export type Any = Message<{
@@ -124,15 +123,13 @@ export type Any = Message<{
124
123
  * used with implementation specific semantics.
125
124
  *
126
125
  *
127
- *
128
- * @generated from field: string type_url = 1 [packed = false, default = "", jstype = JS_NORMAL];
126
+ * @generated from field: string type_url = 1;
129
127
  */
130
128
  typeUrl?: string;
131
129
  /**
132
130
  * Must be a valid serialized protocol buffer of the above specified type.
133
131
  *
134
- *
135
- * @generated from field: bytes value = 2 [packed = false, default = "", jstype = JS_NORMAL];
132
+ * @generated from field: bytes value = 2;
136
133
  */
137
134
  value?: Uint8Array;
138
135
  }>;
@@ -7,57 +7,49 @@ export declare const protobufPackage = "google.protobuf";
7
7
  /**
8
8
  * Method represents a method of an API interface.
9
9
  *
10
- *
11
10
  * @generated from message google.protobuf.Method
12
11
  */
13
12
  export type Method = Message<{
14
13
  /**
15
14
  * The simple name of this method.
16
15
  *
17
- *
18
- * @generated from field: string name = 1 [packed = false, default = "", jstype = JS_NORMAL];
16
+ * @generated from field: string name = 1;
19
17
  */
20
18
  name?: string;
21
19
  /**
22
20
  * A URL of the input message type.
23
21
  *
24
- *
25
- * @generated from field: string request_type_url = 2 [packed = false, default = "", jstype = JS_NORMAL];
22
+ * @generated from field: string request_type_url = 2;
26
23
  */
27
24
  requestTypeUrl?: string;
28
25
  /**
29
26
  * If true, the request is streamed.
30
27
  *
31
- *
32
- * @generated from field: bool request_streaming = 3 [packed = false, default = , jstype = JS_NORMAL];
28
+ * @generated from field: bool request_streaming = 3;
33
29
  */
34
30
  requestStreaming?: boolean;
35
31
  /**
36
32
  * The URL of the output message type.
37
33
  *
38
- *
39
- * @generated from field: string response_type_url = 4 [packed = false, default = "", jstype = JS_NORMAL];
34
+ * @generated from field: string response_type_url = 4;
40
35
  */
41
36
  responseTypeUrl?: string;
42
37
  /**
43
38
  * If true, the response is streamed.
44
39
  *
45
- *
46
- * @generated from field: bool response_streaming = 5 [packed = false, default = , jstype = JS_NORMAL];
40
+ * @generated from field: bool response_streaming = 5;
47
41
  */
48
42
  responseStreaming?: boolean;
49
43
  /**
50
44
  * Any metadata attached to the method.
51
45
  *
52
- *
53
- * @generated from field: repeated google.protobuf.Option options = 6 [packed = false, default = , jstype = JS_NORMAL];
46
+ * @generated from field: repeated google.protobuf.Option options = 6;
54
47
  */
55
48
  options?: Option[];
56
49
  /**
57
50
  * The source syntax of this method.
58
51
  *
59
- *
60
- * @generated from field: google.protobuf.Syntax syntax = 7 [packed = false, default = , jstype = JS_NORMAL];
52
+ * @generated from field: google.protobuf.Syntax syntax = 7;
61
53
  */
62
54
  syntax?: Syntax;
63
55
  }>;
@@ -142,23 +134,20 @@ export declare const Method: MessageType<Method>;
142
134
  * ...
143
135
  * }
144
136
  *
145
- *
146
137
  * @generated from message google.protobuf.Mixin
147
138
  */
148
139
  export type Mixin = Message<{
149
140
  /**
150
141
  * The fully qualified name of the interface which is included.
151
142
  *
152
- *
153
- * @generated from field: string name = 1 [packed = false, default = "", jstype = JS_NORMAL];
143
+ * @generated from field: string name = 1;
154
144
  */
155
145
  name?: string;
156
146
  /**
157
147
  * If non-empty specifies a path under which inherited HTTP paths
158
148
  * are rooted.
159
149
  *
160
- *
161
- * @generated from field: string root = 2 [packed = false, default = "", jstype = JS_NORMAL];
150
+ * @generated from field: string root = 2;
162
151
  */
163
152
  root?: string;
164
153
  }>;
@@ -174,7 +163,6 @@ export declare const Mixin: MessageType<Mixin>;
174
163
  * this message itself. See https://cloud.google.com/apis/design/glossary for
175
164
  * detailed terminology.
176
165
  *
177
- *
178
166
  * @generated from message google.protobuf.Api
179
167
  */
180
168
  export type Api = Message<{
@@ -182,22 +170,19 @@ export type Api = Message<{
182
170
  * The fully qualified name of this interface, including package name
183
171
  * followed by the interface's simple name.
184
172
  *
185
- *
186
- * @generated from field: string name = 1 [packed = false, default = "", jstype = JS_NORMAL];
173
+ * @generated from field: string name = 1;
187
174
  */
188
175
  name?: string;
189
176
  /**
190
177
  * The methods of this interface, in unspecified order.
191
178
  *
192
- *
193
- * @generated from field: repeated google.protobuf.Method methods = 2 [packed = false, default = , jstype = JS_NORMAL];
179
+ * @generated from field: repeated google.protobuf.Method methods = 2;
194
180
  */
195
181
  methods?: Method[];
196
182
  /**
197
183
  * Any metadata attached to the interface.
198
184
  *
199
- *
200
- * @generated from field: repeated google.protobuf.Option options = 3 [packed = false, default = , jstype = JS_NORMAL];
185
+ * @generated from field: repeated google.protobuf.Option options = 3;
201
186
  */
202
187
  options?: Option[];
203
188
  /**
@@ -222,30 +207,26 @@ export type Api = Message<{
222
207
  * experimental, non-GA interfaces.
223
208
  *
224
209
  *
225
- *
226
- * @generated from field: string version = 4 [packed = false, default = "", jstype = JS_NORMAL];
210
+ * @generated from field: string version = 4;
227
211
  */
228
212
  version?: string;
229
213
  /**
230
214
  * Source context for the protocol buffer service represented by this
231
215
  * message.
232
216
  *
233
- *
234
- * @generated from field: google.protobuf.SourceContext source_context = 5 [packed = false, default = , jstype = JS_NORMAL];
217
+ * @generated from field: google.protobuf.SourceContext source_context = 5;
235
218
  */
236
219
  sourceContext?: SourceContext;
237
220
  /**
238
221
  * Included interfaces. See [Mixin][].
239
222
  *
240
- *
241
- * @generated from field: repeated google.protobuf.Mixin mixins = 6 [packed = false, default = , jstype = JS_NORMAL];
223
+ * @generated from field: repeated google.protobuf.Mixin mixins = 6;
242
224
  */
243
225
  mixins?: Mixin[];
244
226
  /**
245
227
  * The source syntax of the service.
246
228
  *
247
- *
248
- * @generated from field: google.protobuf.Syntax syntax = 7 [packed = false, default = , jstype = JS_NORMAL];
229
+ * @generated from field: google.protobuf.Syntax syntax = 7;
249
230
  */
250
231
  syntax?: Syntax;
251
232
  }>;