@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/bin/protoc-gen-es-lite
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import {runNodeJs} from "../dist/protoplugin/index.js";
|
|
4
|
+
import {protocGenEsLite} from "../dist/protoc-gen-es-lite/protoc-gen-es-lite-plugin.js";
|
|
5
5
|
|
|
6
6
|
runNodeJs(protocGenEsLite);
|
package/dist/assert.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,43 +11,38 @@
|
|
|
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.assertFloat32 = exports.assertUInt32 = exports.assertInt32 = exports.assert = void 0;
|
|
17
14
|
/**
|
|
18
15
|
* Assert that condition is truthy or throw error (with message)
|
|
19
16
|
*/
|
|
20
|
-
function assert(condition, msg) {
|
|
17
|
+
export function assert(condition, msg) {
|
|
21
18
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
|
|
22
19
|
if (!condition) {
|
|
23
20
|
throw new Error(msg);
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
exports.assert = assert;
|
|
27
23
|
const FLOAT32_MAX = 3.4028234663852886e38, FLOAT32_MIN = -3.4028234663852886e38, UINT32_MAX = 0xffffffff, INT32_MAX = 0x7fffffff, INT32_MIN = -0x80000000;
|
|
28
24
|
/**
|
|
29
25
|
* Assert a valid signed protobuf 32-bit integer.
|
|
30
26
|
*/
|
|
31
|
-
function assertInt32(arg) {
|
|
27
|
+
export function assertInt32(arg) {
|
|
32
28
|
if (typeof arg !== "number")
|
|
33
29
|
throw new Error("invalid int 32: " + typeof arg);
|
|
34
30
|
if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
|
|
35
31
|
throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
36
32
|
}
|
|
37
|
-
exports.assertInt32 = assertInt32;
|
|
38
33
|
/**
|
|
39
34
|
* Assert a valid unsigned protobuf 32-bit integer.
|
|
40
35
|
*/
|
|
41
|
-
function assertUInt32(arg) {
|
|
36
|
+
export function assertUInt32(arg) {
|
|
42
37
|
if (typeof arg !== "number")
|
|
43
38
|
throw new Error("invalid uint 32: " + typeof arg);
|
|
44
39
|
if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
|
|
45
40
|
throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
46
41
|
}
|
|
47
|
-
exports.assertUInt32 = assertUInt32;
|
|
48
42
|
/**
|
|
49
43
|
* Assert a valid protobuf float value.
|
|
50
44
|
*/
|
|
51
|
-
function assertFloat32(arg) {
|
|
45
|
+
export function assertFloat32(arg) {
|
|
52
46
|
if (typeof arg !== "number")
|
|
53
47
|
throw new Error("invalid float 32: " + typeof arg);
|
|
54
48
|
if (!Number.isFinite(arg))
|
|
@@ -56,4 +50,3 @@ function assertFloat32(arg) {
|
|
|
56
50
|
if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
|
|
57
51
|
throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
58
52
|
}
|
|
59
|
-
exports.assertFloat32 = assertFloat32;
|
package/dist/binary-encoding.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,11 +11,9 @@
|
|
|
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
|
-
const assert_js_1 = require("./assert.js");
|
|
19
|
-
const proto_int64_js_1 = require("./proto-int64.js");
|
|
14
|
+
import { varint32read, varint32write, varint64read, varint64write, } from "./varint.js";
|
|
15
|
+
import { assertFloat32, assertInt32, assertUInt32 } from "./assert.js";
|
|
16
|
+
import { protoInt64 } from "./proto-int64.js";
|
|
20
17
|
/* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/restrict-plus-operands */
|
|
21
18
|
/**
|
|
22
19
|
* Protobuf binary format wire types.
|
|
@@ -26,7 +23,7 @@ const proto_int64_js_1 = require("./proto-int64.js");
|
|
|
26
23
|
*
|
|
27
24
|
* See https://developers.google.com/protocol-buffers/docs/encoding#structure
|
|
28
25
|
*/
|
|
29
|
-
var WireType;
|
|
26
|
+
export var WireType;
|
|
30
27
|
(function (WireType) {
|
|
31
28
|
/**
|
|
32
29
|
* Used for int32, int64, uint32, uint64, sint32, sint64, bool, enum
|
|
@@ -59,13 +56,34 @@ var WireType;
|
|
|
59
56
|
* Always 4 bytes with little-endian byte order.
|
|
60
57
|
*/
|
|
61
58
|
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
62
|
-
})(WireType || (
|
|
63
|
-
class BinaryWriter {
|
|
59
|
+
})(WireType || (WireType = {}));
|
|
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;
|
|
64
86
|
constructor(textEncoder) {
|
|
65
|
-
/**
|
|
66
|
-
* Previous fork states.
|
|
67
|
-
*/
|
|
68
|
-
this.stack = [];
|
|
69
87
|
this.textEncoder = textEncoder ?? new TextEncoder();
|
|
70
88
|
this.chunks = [];
|
|
71
89
|
this.buf = [];
|
|
@@ -141,7 +159,7 @@ class BinaryWriter {
|
|
|
141
159
|
* Write a `uint32` value, an unsigned 32 bit varint.
|
|
142
160
|
*/
|
|
143
161
|
uint32(value) {
|
|
144
|
-
|
|
162
|
+
assertUInt32(value);
|
|
145
163
|
// write value as varint 32, inlined for speed
|
|
146
164
|
while (value > 0x7f) {
|
|
147
165
|
this.buf.push((value & 0x7f) | 0x80);
|
|
@@ -154,8 +172,8 @@ class BinaryWriter {
|
|
|
154
172
|
* Write a `int32` value, a signed 32 bit varint.
|
|
155
173
|
*/
|
|
156
174
|
int32(value) {
|
|
157
|
-
|
|
158
|
-
|
|
175
|
+
assertInt32(value);
|
|
176
|
+
varint32write(value, this.buf);
|
|
159
177
|
return this;
|
|
160
178
|
}
|
|
161
179
|
/**
|
|
@@ -184,7 +202,7 @@ class BinaryWriter {
|
|
|
184
202
|
* Write a `float` value, 32-bit floating point number.
|
|
185
203
|
*/
|
|
186
204
|
float(value) {
|
|
187
|
-
|
|
205
|
+
assertFloat32(value);
|
|
188
206
|
let chunk = new Uint8Array(4);
|
|
189
207
|
new DataView(chunk.buffer).setFloat32(0, value, true);
|
|
190
208
|
return this.raw(chunk);
|
|
@@ -201,7 +219,7 @@ class BinaryWriter {
|
|
|
201
219
|
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
|
|
202
220
|
*/
|
|
203
221
|
fixed32(value) {
|
|
204
|
-
|
|
222
|
+
assertUInt32(value);
|
|
205
223
|
let chunk = new Uint8Array(4);
|
|
206
224
|
new DataView(chunk.buffer).setUint32(0, value, true);
|
|
207
225
|
return this.raw(chunk);
|
|
@@ -210,7 +228,7 @@ class BinaryWriter {
|
|
|
210
228
|
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
|
|
211
229
|
*/
|
|
212
230
|
sfixed32(value) {
|
|
213
|
-
|
|
231
|
+
assertInt32(value);
|
|
214
232
|
let chunk = new Uint8Array(4);
|
|
215
233
|
new DataView(chunk.buffer).setInt32(0, value, true);
|
|
216
234
|
return this.raw(chunk);
|
|
@@ -219,17 +237,17 @@ class BinaryWriter {
|
|
|
219
237
|
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
|
|
220
238
|
*/
|
|
221
239
|
sint32(value) {
|
|
222
|
-
|
|
240
|
+
assertInt32(value);
|
|
223
241
|
// zigzag encode
|
|
224
242
|
value = ((value << 1) ^ (value >> 31)) >>> 0;
|
|
225
|
-
|
|
243
|
+
varint32write(value, this.buf);
|
|
226
244
|
return this;
|
|
227
245
|
}
|
|
228
246
|
/**
|
|
229
247
|
* Write a `fixed64` value, a signed, fixed-length 64-bit integer.
|
|
230
248
|
*/
|
|
231
249
|
sfixed64(value) {
|
|
232
|
-
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc =
|
|
250
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.enc(value);
|
|
233
251
|
view.setInt32(0, tc.lo, true);
|
|
234
252
|
view.setInt32(4, tc.hi, true);
|
|
235
253
|
return this.raw(chunk);
|
|
@@ -238,7 +256,7 @@ class BinaryWriter {
|
|
|
238
256
|
* Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
|
|
239
257
|
*/
|
|
240
258
|
fixed64(value) {
|
|
241
|
-
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc =
|
|
259
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.uEnc(value);
|
|
242
260
|
view.setInt32(0, tc.lo, true);
|
|
243
261
|
view.setInt32(4, tc.hi, true);
|
|
244
262
|
return this.raw(chunk);
|
|
@@ -247,37 +265,42 @@ class BinaryWriter {
|
|
|
247
265
|
* Write a `int64` value, a signed 64-bit varint.
|
|
248
266
|
*/
|
|
249
267
|
int64(value) {
|
|
250
|
-
let tc =
|
|
251
|
-
|
|
268
|
+
let tc = protoInt64.enc(value);
|
|
269
|
+
varint64write(tc.lo, tc.hi, this.buf);
|
|
252
270
|
return this;
|
|
253
271
|
}
|
|
254
272
|
/**
|
|
255
273
|
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
|
|
256
274
|
*/
|
|
257
275
|
sint64(value) {
|
|
258
|
-
let tc =
|
|
276
|
+
let tc = protoInt64.enc(value),
|
|
259
277
|
// zigzag encode
|
|
260
278
|
sign = tc.hi >> 31, lo = (tc.lo << 1) ^ sign, hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
|
|
261
|
-
|
|
279
|
+
varint64write(lo, hi, this.buf);
|
|
262
280
|
return this;
|
|
263
281
|
}
|
|
264
282
|
/**
|
|
265
283
|
* Write a `uint64` value, an unsigned 64-bit varint.
|
|
266
284
|
*/
|
|
267
285
|
uint64(value) {
|
|
268
|
-
let tc =
|
|
269
|
-
|
|
286
|
+
let tc = protoInt64.uEnc(value);
|
|
287
|
+
varint64write(tc.lo, tc.hi, this.buf);
|
|
270
288
|
return this;
|
|
271
289
|
}
|
|
272
290
|
}
|
|
273
|
-
|
|
274
|
-
|
|
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;
|
|
275
303
|
constructor(buf, textDecoder) {
|
|
276
|
-
this.varint64 = varint_js_1.varint64read; // dirty cast for `this`
|
|
277
|
-
/**
|
|
278
|
-
* Read a `uint32` field, an unsigned 32 bit varint.
|
|
279
|
-
*/
|
|
280
|
-
this.uint32 = varint_js_1.varint32read; // dirty cast for `this` and access to protected `buf`
|
|
281
304
|
this.buf = buf;
|
|
282
305
|
this.len = buf.length;
|
|
283
306
|
this.pos = 0;
|
|
@@ -331,6 +354,7 @@ class BinaryReader {
|
|
|
331
354
|
this.assertBounds();
|
|
332
355
|
return this.buf.subarray(start, this.pos);
|
|
333
356
|
}
|
|
357
|
+
varint64 = varint64read; // dirty cast for `this`
|
|
334
358
|
/**
|
|
335
359
|
* Throws error if position in byte array is out of range.
|
|
336
360
|
*/
|
|
@@ -338,6 +362,10 @@ class BinaryReader {
|
|
|
338
362
|
if (this.pos > this.len)
|
|
339
363
|
throw new RangeError("premature EOF");
|
|
340
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`
|
|
341
369
|
/**
|
|
342
370
|
* Read a `int32` field, a signed 32 bit varint.
|
|
343
371
|
*/
|
|
@@ -356,13 +384,13 @@ class BinaryReader {
|
|
|
356
384
|
* Read a `int64` field, a signed 64-bit varint.
|
|
357
385
|
*/
|
|
358
386
|
int64() {
|
|
359
|
-
return
|
|
387
|
+
return protoInt64.dec(...this.varint64());
|
|
360
388
|
}
|
|
361
389
|
/**
|
|
362
390
|
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
363
391
|
*/
|
|
364
392
|
uint64() {
|
|
365
|
-
return
|
|
393
|
+
return protoInt64.uDec(...this.varint64());
|
|
366
394
|
}
|
|
367
395
|
/**
|
|
368
396
|
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
@@ -373,7 +401,7 @@ class BinaryReader {
|
|
|
373
401
|
let s = -(lo & 1);
|
|
374
402
|
lo = ((lo >>> 1) | ((hi & 1) << 31)) ^ s;
|
|
375
403
|
hi = (hi >>> 1) ^ s;
|
|
376
|
-
return
|
|
404
|
+
return protoInt64.dec(lo, hi);
|
|
377
405
|
}
|
|
378
406
|
/**
|
|
379
407
|
* Read a `bool` field, a variant.
|
|
@@ -398,13 +426,13 @@ class BinaryReader {
|
|
|
398
426
|
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
399
427
|
*/
|
|
400
428
|
fixed64() {
|
|
401
|
-
return
|
|
429
|
+
return protoInt64.uDec(this.sfixed32(), this.sfixed32());
|
|
402
430
|
}
|
|
403
431
|
/**
|
|
404
432
|
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
405
433
|
*/
|
|
406
434
|
sfixed64() {
|
|
407
|
-
return
|
|
435
|
+
return protoInt64.dec(this.sfixed32(), this.sfixed32());
|
|
408
436
|
}
|
|
409
437
|
/**
|
|
410
438
|
* Read a `float` field, 32-bit floating point number.
|
|
@@ -434,4 +462,3 @@ class BinaryReader {
|
|
|
434
462
|
return this.textDecoder.decode(this.bytes());
|
|
435
463
|
}
|
|
436
464
|
}
|
|
437
|
-
exports.BinaryReader = BinaryReader;
|