@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
|
@@ -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,16 +11,14 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const service_type_js_1 = require("./service-type.js");
|
|
24
|
-
const text_format_js_1 = require("./text-format.js");
|
|
14
|
+
import { assert } from "./assert.js";
|
|
15
|
+
import { createFeatureResolver } from "./feature-set.js";
|
|
16
|
+
import { fieldJsonName } from "./field.js";
|
|
17
|
+
import { Edition, FeatureSet_RepeatedFieldEncoding, FieldDescriptorProto_Label, FieldDescriptorProto_Type, FieldOptions_JSType, FileDescriptorSet, MethodOptions_IdempotencyLevel, } from "./google/protobuf/descriptor.pb.js";
|
|
18
|
+
import { findEnumSharedPrefix } from "./names.js";
|
|
19
|
+
import { LongType, ScalarType } from "./scalar.js";
|
|
20
|
+
import { MethodIdempotency, MethodKind } from "./service-type.js";
|
|
21
|
+
import { parseTextFormatEnumValue, parseTextFormatScalarValue, } from "./text-format.js";
|
|
25
22
|
/**
|
|
26
23
|
* Create a DescriptorSet, a convenient interface for working with a set of
|
|
27
24
|
* google.protobuf.FileDescriptorProto.
|
|
@@ -30,7 +27,7 @@ const text_format_js_1 = require("./text-format.js");
|
|
|
30
27
|
* before any file that imports it. Protocol buffer compilers always produce
|
|
31
28
|
* files in topological order.
|
|
32
29
|
*/
|
|
33
|
-
function createDescriptorSet(input, options) {
|
|
30
|
+
export function createDescriptorSet(input, options) {
|
|
34
31
|
const cart = {
|
|
35
32
|
files: [],
|
|
36
33
|
enums: new Map(),
|
|
@@ -39,7 +36,7 @@ function createDescriptorSet(input, options) {
|
|
|
39
36
|
extensions: new Map(),
|
|
40
37
|
mapEntries: new Map(),
|
|
41
38
|
};
|
|
42
|
-
const fileDescriptors = input instanceof Uint8Array ?
|
|
39
|
+
const fileDescriptors = input instanceof Uint8Array ? FileDescriptorSet.fromBinary(input).file ?? []
|
|
43
40
|
: Array.isArray(input) ? input
|
|
44
41
|
: input.file ?? [];
|
|
45
42
|
const resolverByEdition = new Map();
|
|
@@ -47,19 +44,18 @@ function createDescriptorSet(input, options) {
|
|
|
47
44
|
const edition = proto.edition || parseFileSyntax(proto.syntax, proto.edition).edition;
|
|
48
45
|
let resolveFeatures = resolverByEdition.get(edition);
|
|
49
46
|
if (resolveFeatures === undefined) {
|
|
50
|
-
resolveFeatures =
|
|
47
|
+
resolveFeatures = createFeatureResolver(edition, options?.featureSetDefaults, options?.serializationOptions);
|
|
51
48
|
resolverByEdition.set(edition, resolveFeatures);
|
|
52
49
|
}
|
|
53
50
|
addFile(proto, cart, resolveFeatures);
|
|
54
51
|
}
|
|
55
52
|
return cart;
|
|
56
53
|
}
|
|
57
|
-
exports.createDescriptorSet = createDescriptorSet;
|
|
58
54
|
/**
|
|
59
55
|
* Create a descriptor for a file.
|
|
60
56
|
*/
|
|
61
57
|
function addFile(proto, cart, resolveFeatures) {
|
|
62
|
-
|
|
58
|
+
assert(proto.name, `invalid FileDescriptorProto: missing name`);
|
|
63
59
|
const file = {
|
|
64
60
|
kind: "file",
|
|
65
61
|
proto,
|
|
@@ -170,7 +166,7 @@ function addFields(message, cart, resolveFeatures) {
|
|
|
170
166
|
* parent type, if any.
|
|
171
167
|
*/
|
|
172
168
|
function addEnum(proto, file, parent, cart, resolveFeatures) {
|
|
173
|
-
|
|
169
|
+
assert(proto.name, `invalid EnumDescriptorProto: missing name`);
|
|
174
170
|
const desc = {
|
|
175
171
|
kind: "enum",
|
|
176
172
|
proto,
|
|
@@ -180,7 +176,7 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
|
|
|
180
176
|
name: proto.name,
|
|
181
177
|
typeName: makeTypeName(proto, parent, file),
|
|
182
178
|
values: [],
|
|
183
|
-
sharedPrefix:
|
|
179
|
+
sharedPrefix: findEnumSharedPrefix(proto.name, proto.value?.map((v) => v.name ?? "") ?? []),
|
|
184
180
|
toString() {
|
|
185
181
|
return `enum ${this.typeName}`;
|
|
186
182
|
},
|
|
@@ -203,8 +199,8 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
|
|
|
203
199
|
};
|
|
204
200
|
cart.enums.set(desc.typeName, desc);
|
|
205
201
|
proto.value?.forEach((proto) => {
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
assert(proto.name, `invalid EnumValueDescriptorProto: missing name`);
|
|
203
|
+
assert(proto.number !== undefined, `invalid EnumValueDescriptorProto: missing number`);
|
|
208
204
|
desc.values.push({
|
|
209
205
|
kind: "enum_value",
|
|
210
206
|
proto,
|
|
@@ -242,7 +238,7 @@ function addEnum(proto, file, parent, cart, resolveFeatures) {
|
|
|
242
238
|
* cart. Note that this does not create descriptors fields.
|
|
243
239
|
*/
|
|
244
240
|
function addMessage(proto, file, parent, cart, resolveFeatures) {
|
|
245
|
-
|
|
241
|
+
assert(proto.name, `invalid DescriptorProto: missing name`);
|
|
246
242
|
const desc = {
|
|
247
243
|
kind: "message",
|
|
248
244
|
proto,
|
|
@@ -296,7 +292,7 @@ function addMessage(proto, file, parent, cart, resolveFeatures) {
|
|
|
296
292
|
* cart.
|
|
297
293
|
*/
|
|
298
294
|
function addService(proto, file, cart, resolveFeatures) {
|
|
299
|
-
|
|
295
|
+
assert(proto.name, `invalid ServiceDescriptorProto: missing name`);
|
|
300
296
|
const desc = {
|
|
301
297
|
kind: "service",
|
|
302
298
|
proto,
|
|
@@ -329,39 +325,39 @@ function addService(proto, file, cart, resolveFeatures) {
|
|
|
329
325
|
* Create a descriptor for a method.
|
|
330
326
|
*/
|
|
331
327
|
function newMethod(proto, parent, cart, resolveFeatures) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
328
|
+
assert(proto.name, `invalid MethodDescriptorProto: missing name`);
|
|
329
|
+
assert(proto.inputType, `invalid MethodDescriptorProto: missing input_type`);
|
|
330
|
+
assert(proto.outputType, `invalid MethodDescriptorProto: missing output_type`);
|
|
335
331
|
let methodKind;
|
|
336
332
|
if (proto.clientStreaming === true && proto.serverStreaming === true) {
|
|
337
|
-
methodKind =
|
|
333
|
+
methodKind = MethodKind.BiDiStreaming;
|
|
338
334
|
}
|
|
339
335
|
else if (proto.clientStreaming === true) {
|
|
340
|
-
methodKind =
|
|
336
|
+
methodKind = MethodKind.ClientStreaming;
|
|
341
337
|
}
|
|
342
338
|
else if (proto.serverStreaming === true) {
|
|
343
|
-
methodKind =
|
|
339
|
+
methodKind = MethodKind.ServerStreaming;
|
|
344
340
|
}
|
|
345
341
|
else {
|
|
346
|
-
methodKind =
|
|
342
|
+
methodKind = MethodKind.Unary;
|
|
347
343
|
}
|
|
348
344
|
let idempotency;
|
|
349
345
|
switch (proto.options?.idempotencyLevel) {
|
|
350
|
-
case
|
|
351
|
-
idempotency =
|
|
346
|
+
case MethodOptions_IdempotencyLevel.IDEMPOTENT:
|
|
347
|
+
idempotency = MethodIdempotency.Idempotent;
|
|
352
348
|
break;
|
|
353
|
-
case
|
|
354
|
-
idempotency =
|
|
349
|
+
case MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS:
|
|
350
|
+
idempotency = MethodIdempotency.NoSideEffects;
|
|
355
351
|
break;
|
|
356
|
-
case
|
|
352
|
+
case MethodOptions_IdempotencyLevel.IDEMPOTENCY_UNKNOWN:
|
|
357
353
|
case undefined:
|
|
358
354
|
idempotency = undefined;
|
|
359
355
|
break;
|
|
360
356
|
}
|
|
361
357
|
const input = cart.messages.get(trimLeadingDot(proto.inputType));
|
|
362
358
|
const output = cart.messages.get(trimLeadingDot(proto.outputType));
|
|
363
|
-
|
|
364
|
-
|
|
359
|
+
assert(input, `invalid MethodDescriptorProto: input_type ${proto.inputType} not found`);
|
|
360
|
+
assert(output, `invalid MethodDescriptorProto: output_type ${proto.inputType} not found`);
|
|
365
361
|
const name = proto.name;
|
|
366
362
|
return {
|
|
367
363
|
kind: "rpc",
|
|
@@ -393,7 +389,7 @@ function newMethod(proto, parent, cart, resolveFeatures) {
|
|
|
393
389
|
* Create a descriptor for a oneof group.
|
|
394
390
|
*/
|
|
395
391
|
function newOneof(proto, parent, resolveFeatures) {
|
|
396
|
-
|
|
392
|
+
assert(proto.name, `invalid OneofDescriptorProto: missing name`);
|
|
397
393
|
return {
|
|
398
394
|
kind: "oneof",
|
|
399
395
|
proto,
|
|
@@ -421,9 +417,9 @@ function newOneof(proto, parent, resolveFeatures) {
|
|
|
421
417
|
* Create a descriptor for a field.
|
|
422
418
|
*/
|
|
423
419
|
function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
420
|
+
assert(proto.name, `invalid FieldDescriptorProto: missing name`);
|
|
421
|
+
assert(proto.number, `invalid FieldDescriptorProto: missing number`);
|
|
422
|
+
assert(proto.type, `invalid FieldDescriptorProto: missing type`);
|
|
427
423
|
const common = {
|
|
428
424
|
proto,
|
|
429
425
|
deprecated: proto.options?.deprecated ?? false,
|
|
@@ -434,7 +430,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
434
430
|
optional: isOptionalField(proto, file.syntax),
|
|
435
431
|
packedByDefault: isPackedFieldByDefault(proto, resolveFeatures),
|
|
436
432
|
packed: isPackedField(file, parent, proto, resolveFeatures),
|
|
437
|
-
jsonName: proto.jsonName ===
|
|
433
|
+
jsonName: proto.jsonName === fieldJsonName(proto.name) ? undefined : proto.jsonName,
|
|
438
434
|
scalar: undefined,
|
|
439
435
|
longType: undefined,
|
|
440
436
|
message: undefined,
|
|
@@ -458,14 +454,14 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
458
454
|
return resolveFeatures(parent.getFeatures(), proto.options?.features);
|
|
459
455
|
},
|
|
460
456
|
};
|
|
461
|
-
const repeated = proto.label ===
|
|
457
|
+
const repeated = proto.label === FieldDescriptorProto_Label.REPEATED;
|
|
462
458
|
switch (proto.type) {
|
|
463
|
-
case
|
|
464
|
-
case
|
|
465
|
-
|
|
459
|
+
case FieldDescriptorProto_Type.MESSAGE:
|
|
460
|
+
case FieldDescriptorProto_Type.GROUP: {
|
|
461
|
+
assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
|
|
466
462
|
const mapEntry = cart.mapEntries.get(trimLeadingDot(proto.typeName));
|
|
467
463
|
if (mapEntry !== undefined) {
|
|
468
|
-
|
|
464
|
+
assert(repeated, `invalid FieldDescriptorProto: expected map entry to be repeated`);
|
|
469
465
|
return {
|
|
470
466
|
...common,
|
|
471
467
|
kind: "field",
|
|
@@ -475,7 +471,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
475
471
|
};
|
|
476
472
|
}
|
|
477
473
|
const message = cart.messages.get(trimLeadingDot(proto.typeName));
|
|
478
|
-
|
|
474
|
+
assert(message !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
479
475
|
return {
|
|
480
476
|
...common,
|
|
481
477
|
kind: "field",
|
|
@@ -484,10 +480,10 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
484
480
|
message,
|
|
485
481
|
};
|
|
486
482
|
}
|
|
487
|
-
case
|
|
488
|
-
|
|
483
|
+
case FieldDescriptorProto_Type.ENUM: {
|
|
484
|
+
assert(proto.typeName, `invalid FieldDescriptorProto: missing type_name`);
|
|
489
485
|
const e = cart.enums.get(trimLeadingDot(proto.typeName));
|
|
490
|
-
|
|
486
|
+
assert(e !== undefined, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
|
|
491
487
|
return {
|
|
492
488
|
...common,
|
|
493
489
|
kind: "field",
|
|
@@ -499,7 +495,7 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
499
495
|
}
|
|
500
496
|
default: {
|
|
501
497
|
const scalar = fieldTypeToScalarType[proto.type];
|
|
502
|
-
|
|
498
|
+
assert(scalar, `invalid FieldDescriptorProto: unknown type ${proto.type}`);
|
|
503
499
|
return {
|
|
504
500
|
...common,
|
|
505
501
|
kind: "field",
|
|
@@ -507,9 +503,9 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
507
503
|
getDefaultValue,
|
|
508
504
|
repeated,
|
|
509
505
|
scalar,
|
|
510
|
-
longType: proto.options?.jstype ==
|
|
511
|
-
|
|
512
|
-
:
|
|
506
|
+
longType: proto.options?.jstype == FieldOptions_JSType.JS_STRING ?
|
|
507
|
+
LongType.STRING
|
|
508
|
+
: LongType.BIGINT,
|
|
513
509
|
};
|
|
514
510
|
}
|
|
515
511
|
}
|
|
@@ -518,11 +514,11 @@ function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
|
518
514
|
* Create a descriptor for an extension field.
|
|
519
515
|
*/
|
|
520
516
|
function newExtension(proto, file, parent, cart, resolveFeatures) {
|
|
521
|
-
|
|
517
|
+
assert(proto.extendee, `invalid FieldDescriptorProto: missing extendee`);
|
|
522
518
|
const field = newField(proto, file, null, // to safe us many lines of duplicated code, we trick the type system
|
|
523
519
|
undefined, cart, resolveFeatures);
|
|
524
520
|
const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
|
|
525
|
-
|
|
521
|
+
assert(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
|
|
526
522
|
return {
|
|
527
523
|
...field,
|
|
528
524
|
kind: "extension",
|
|
@@ -564,23 +560,23 @@ function parseFileSyntax(syntax, edition) {
|
|
|
564
560
|
case "":
|
|
565
561
|
case "proto2":
|
|
566
562
|
s = "proto2";
|
|
567
|
-
e =
|
|
563
|
+
e = Edition.EDITION_PROTO2;
|
|
568
564
|
break;
|
|
569
565
|
case "proto3":
|
|
570
566
|
s = "proto3";
|
|
571
|
-
e =
|
|
567
|
+
e = Edition.EDITION_PROTO3;
|
|
572
568
|
break;
|
|
573
569
|
case "editions":
|
|
574
570
|
s = "editions";
|
|
575
571
|
switch (edition) {
|
|
576
572
|
case undefined:
|
|
577
|
-
case
|
|
578
|
-
case
|
|
579
|
-
case
|
|
580
|
-
case
|
|
581
|
-
case
|
|
582
|
-
case
|
|
583
|
-
e =
|
|
573
|
+
case Edition.EDITION_1_TEST_ONLY:
|
|
574
|
+
case Edition.EDITION_2_TEST_ONLY:
|
|
575
|
+
case Edition.EDITION_99997_TEST_ONLY:
|
|
576
|
+
case Edition.EDITION_99998_TEST_ONLY:
|
|
577
|
+
case Edition.EDITION_99999_TEST_ONLY:
|
|
578
|
+
case Edition.EDITION_UNKNOWN:
|
|
579
|
+
e = Edition.EDITION_UNKNOWN;
|
|
584
580
|
break;
|
|
585
581
|
default:
|
|
586
582
|
e = edition;
|
|
@@ -590,7 +586,7 @@ function parseFileSyntax(syntax, edition) {
|
|
|
590
586
|
default:
|
|
591
587
|
throw new Error(`invalid FileDescriptorProto: unsupported syntax: ${syntax}`);
|
|
592
588
|
}
|
|
593
|
-
if (syntax === "editions" && edition ===
|
|
589
|
+
if (syntax === "editions" && edition === Edition.EDITION_UNKNOWN) {
|
|
594
590
|
throw new Error(`invalid FileDescriptorProto: syntax ${syntax} cannot have edition ${String(edition)}`);
|
|
595
591
|
}
|
|
596
592
|
return {
|
|
@@ -604,7 +600,7 @@ function parseFileSyntax(syntax, edition) {
|
|
|
604
600
|
function findFileDependencies(proto, cart) {
|
|
605
601
|
return (proto.dependency?.map((wantName) => {
|
|
606
602
|
const dep = cart.files.find((f) => f.proto.name === wantName);
|
|
607
|
-
|
|
603
|
+
assert(dep);
|
|
608
604
|
return dep;
|
|
609
605
|
}) ?? []);
|
|
610
606
|
}
|
|
@@ -625,7 +621,7 @@ function findFileDependencies(proto, cart) {
|
|
|
625
621
|
* - mypackage.MyMessage.extfield
|
|
626
622
|
*/
|
|
627
623
|
function makeTypeName(proto, parent, file) {
|
|
628
|
-
|
|
624
|
+
assert(proto.name, `invalid proto: missing name`);
|
|
629
625
|
let typeName;
|
|
630
626
|
if (parent) {
|
|
631
627
|
typeName = `${parent.typeName}.${proto.name}`;
|
|
@@ -645,17 +641,17 @@ function trimLeadingDot(typeName) {
|
|
|
645
641
|
return typeName.startsWith(".") ? typeName.substring(1) : typeName;
|
|
646
642
|
}
|
|
647
643
|
function getMapFieldTypes(mapEntry) {
|
|
648
|
-
|
|
649
|
-
|
|
644
|
+
assert(mapEntry.proto.options?.mapEntry, `invalid DescriptorProto: expected ${mapEntry.toString()} to be a map entry`);
|
|
645
|
+
assert(mapEntry.fields.length === 2, `invalid DescriptorProto: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
|
|
650
646
|
const keyField = mapEntry.fields.find((f) => f.proto.number === 1);
|
|
651
|
-
|
|
647
|
+
assert(keyField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing key field`);
|
|
652
648
|
const mapKey = keyField.scalar;
|
|
653
|
-
|
|
654
|
-
mapKey !==
|
|
655
|
-
mapKey !==
|
|
656
|
-
mapKey !==
|
|
649
|
+
assert(mapKey !== undefined &&
|
|
650
|
+
mapKey !== ScalarType.BYTES &&
|
|
651
|
+
mapKey !== ScalarType.FLOAT &&
|
|
652
|
+
mapKey !== ScalarType.DOUBLE, `invalid DescriptorProto: map entry ${mapEntry.toString()} has unexpected key type ${keyField.proto.type ?? -1}`);
|
|
657
653
|
const valueField = mapEntry.fields.find((f) => f.proto.number === 2);
|
|
658
|
-
|
|
654
|
+
assert(valueField, `invalid DescriptorProto: map entry ${mapEntry.toString()} is missing value field`);
|
|
659
655
|
switch (valueField.fieldKind) {
|
|
660
656
|
case "scalar":
|
|
661
657
|
return {
|
|
@@ -695,9 +691,9 @@ function findOneof(proto, allOneofs) {
|
|
|
695
691
|
return undefined;
|
|
696
692
|
}
|
|
697
693
|
let oneof;
|
|
698
|
-
if (proto.proto3Optional) {
|
|
694
|
+
if (!proto.proto3Optional) {
|
|
699
695
|
oneof = allOneofs[oneofIndex];
|
|
700
|
-
|
|
696
|
+
assert(oneof, `invalid FieldDescriptorProto: oneof #${oneofIndex} for field #${proto.number ?? -1} not found`);
|
|
701
697
|
}
|
|
702
698
|
return oneof;
|
|
703
699
|
}
|
|
@@ -709,7 +705,7 @@ function isOptionalField(proto, syntax) {
|
|
|
709
705
|
switch (syntax) {
|
|
710
706
|
case "proto2":
|
|
711
707
|
return (proto.oneofIndex === undefined &&
|
|
712
|
-
proto.label ===
|
|
708
|
+
proto.label === FieldDescriptorProto_Label.OPTIONAL);
|
|
713
709
|
case "proto3":
|
|
714
710
|
return proto.proto3Optional === true;
|
|
715
711
|
case "editions":
|
|
@@ -726,7 +722,7 @@ function isOptionalField(proto, syntax) {
|
|
|
726
722
|
*/
|
|
727
723
|
function isPackedFieldByDefault(proto, resolveFeatures) {
|
|
728
724
|
const { repeatedFieldEncoding } = resolveFeatures();
|
|
729
|
-
if (repeatedFieldEncoding !=
|
|
725
|
+
if (repeatedFieldEncoding != FeatureSet_RepeatedFieldEncoding.PACKED) {
|
|
730
726
|
return false;
|
|
731
727
|
}
|
|
732
728
|
// From the proto3 language guide:
|
|
@@ -735,10 +731,10 @@ function isPackedFieldByDefault(proto, resolveFeatures) {
|
|
|
735
731
|
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
736
732
|
// are not packed by default, which makes sense because they are length-delimited.
|
|
737
733
|
switch (proto.type) {
|
|
738
|
-
case
|
|
739
|
-
case
|
|
740
|
-
case
|
|
741
|
-
case
|
|
734
|
+
case FieldDescriptorProto_Type.STRING:
|
|
735
|
+
case FieldDescriptorProto_Type.BYTES:
|
|
736
|
+
case FieldDescriptorProto_Type.GROUP:
|
|
737
|
+
case FieldDescriptorProto_Type.MESSAGE:
|
|
742
738
|
return false;
|
|
743
739
|
default:
|
|
744
740
|
return true;
|
|
@@ -752,21 +748,21 @@ function isPackedFieldByDefault(proto, resolveFeatures) {
|
|
|
752
748
|
*/
|
|
753
749
|
function isPackedField(file, parent, proto, resolveFeatures) {
|
|
754
750
|
switch (proto.type) {
|
|
755
|
-
case
|
|
756
|
-
case
|
|
757
|
-
case
|
|
758
|
-
case
|
|
751
|
+
case FieldDescriptorProto_Type.STRING:
|
|
752
|
+
case FieldDescriptorProto_Type.BYTES:
|
|
753
|
+
case FieldDescriptorProto_Type.GROUP:
|
|
754
|
+
case FieldDescriptorProto_Type.MESSAGE:
|
|
759
755
|
// length-delimited types cannot be packed
|
|
760
756
|
return false;
|
|
761
757
|
default:
|
|
762
758
|
switch (file.edition) {
|
|
763
|
-
case
|
|
759
|
+
case Edition.EDITION_PROTO2:
|
|
764
760
|
return proto.options?.packed ?? false;
|
|
765
|
-
case
|
|
761
|
+
case Edition.EDITION_PROTO3:
|
|
766
762
|
return proto.options?.packed ?? true;
|
|
767
763
|
default: {
|
|
768
764
|
const { repeatedFieldEncoding } = resolveFeatures(parent?.getFeatures() ?? file.getFeatures(), proto.options?.features);
|
|
769
|
-
return (repeatedFieldEncoding ==
|
|
765
|
+
return (repeatedFieldEncoding == FeatureSet_RepeatedFieldEncoding.PACKED);
|
|
770
766
|
}
|
|
771
767
|
}
|
|
772
768
|
}
|
|
@@ -776,24 +772,24 @@ function isPackedField(file, parent, proto, resolveFeatures) {
|
|
|
776
772
|
* subset of field types declared by protobuf enum google.protobuf.FieldDescriptorProto.
|
|
777
773
|
*/
|
|
778
774
|
const fieldTypeToScalarType = {
|
|
779
|
-
[
|
|
780
|
-
[
|
|
781
|
-
[
|
|
782
|
-
[
|
|
783
|
-
[
|
|
784
|
-
[
|
|
785
|
-
[
|
|
786
|
-
[
|
|
787
|
-
[
|
|
788
|
-
[
|
|
789
|
-
[
|
|
790
|
-
[
|
|
791
|
-
[
|
|
792
|
-
[
|
|
793
|
-
[
|
|
794
|
-
[
|
|
795
|
-
[
|
|
796
|
-
[
|
|
775
|
+
[FieldDescriptorProto_Type.DOUBLE]: ScalarType.DOUBLE,
|
|
776
|
+
[FieldDescriptorProto_Type.FLOAT]: ScalarType.FLOAT,
|
|
777
|
+
[FieldDescriptorProto_Type.INT64]: ScalarType.INT64,
|
|
778
|
+
[FieldDescriptorProto_Type.UINT64]: ScalarType.UINT64,
|
|
779
|
+
[FieldDescriptorProto_Type.INT32]: ScalarType.INT32,
|
|
780
|
+
[FieldDescriptorProto_Type.FIXED64]: ScalarType.FIXED64,
|
|
781
|
+
[FieldDescriptorProto_Type.FIXED32]: ScalarType.FIXED32,
|
|
782
|
+
[FieldDescriptorProto_Type.BOOL]: ScalarType.BOOL,
|
|
783
|
+
[FieldDescriptorProto_Type.STRING]: ScalarType.STRING,
|
|
784
|
+
[FieldDescriptorProto_Type.GROUP]: undefined,
|
|
785
|
+
[FieldDescriptorProto_Type.MESSAGE]: undefined,
|
|
786
|
+
[FieldDescriptorProto_Type.BYTES]: ScalarType.BYTES,
|
|
787
|
+
[FieldDescriptorProto_Type.UINT32]: ScalarType.UINT32,
|
|
788
|
+
[FieldDescriptorProto_Type.ENUM]: undefined,
|
|
789
|
+
[FieldDescriptorProto_Type.SFIXED32]: ScalarType.SFIXED32,
|
|
790
|
+
[FieldDescriptorProto_Type.SFIXED64]: ScalarType.SFIXED64,
|
|
791
|
+
[FieldDescriptorProto_Type.SINT32]: ScalarType.SINT32,
|
|
792
|
+
[FieldDescriptorProto_Type.SINT64]: ScalarType.SINT64,
|
|
797
793
|
};
|
|
798
794
|
/**
|
|
799
795
|
* Find comments.
|
|
@@ -858,13 +854,13 @@ function declarationString() {
|
|
|
858
854
|
}
|
|
859
855
|
const file = this.kind === "extension" ? this.file : this.parent.file;
|
|
860
856
|
if (file.syntax == "proto2" &&
|
|
861
|
-
this.proto.label ===
|
|
857
|
+
this.proto.label === FieldDescriptorProto_Label.REQUIRED) {
|
|
862
858
|
parts.push("required");
|
|
863
859
|
}
|
|
864
860
|
let type;
|
|
865
861
|
switch (this.fieldKind) {
|
|
866
862
|
case "scalar":
|
|
867
|
-
type =
|
|
863
|
+
type = ScalarType[this.scalar].toLowerCase();
|
|
868
864
|
break;
|
|
869
865
|
case "enum":
|
|
870
866
|
type = this.enum.typeName;
|
|
@@ -873,11 +869,11 @@ function declarationString() {
|
|
|
873
869
|
type = this.message.typeName;
|
|
874
870
|
break;
|
|
875
871
|
case "map": {
|
|
876
|
-
const k =
|
|
872
|
+
const k = ScalarType[this.mapKey].toLowerCase();
|
|
877
873
|
let v;
|
|
878
874
|
switch (this.mapValue.kind) {
|
|
879
875
|
case "scalar":
|
|
880
|
-
v =
|
|
876
|
+
v = ScalarType[this.mapValue.scalar].toLowerCase();
|
|
881
877
|
break;
|
|
882
878
|
case "enum":
|
|
883
879
|
v = this.mapValue.enum.typeName;
|
|
@@ -897,8 +893,8 @@ function declarationString() {
|
|
|
897
893
|
}
|
|
898
894
|
let defaultValue = this.proto.defaultValue;
|
|
899
895
|
if (defaultValue !== undefined) {
|
|
900
|
-
if (this.proto.type ==
|
|
901
|
-
this.proto.type ==
|
|
896
|
+
if (this.proto.type == FieldDescriptorProto_Type.BYTES ||
|
|
897
|
+
this.proto.type == FieldDescriptorProto_Type.STRING) {
|
|
902
898
|
defaultValue = '"' + defaultValue.replace('"', '\\"') + '"';
|
|
903
899
|
}
|
|
904
900
|
options.push(`default = ${defaultValue}`);
|
|
@@ -907,7 +903,7 @@ function declarationString() {
|
|
|
907
903
|
options.push(`json_name = "${this.jsonName}"`);
|
|
908
904
|
}
|
|
909
905
|
if (this.proto.options?.jstype !== undefined) {
|
|
910
|
-
options.push(`jstype = ${
|
|
906
|
+
options.push(`jstype = ${FieldOptions_JSType[this.proto.options.jstype]}`);
|
|
911
907
|
}
|
|
912
908
|
if (this.proto.options?.deprecated === true) {
|
|
913
909
|
options.push(`deprecated = true`);
|
|
@@ -927,9 +923,9 @@ function getDefaultValue() {
|
|
|
927
923
|
}
|
|
928
924
|
switch (this.fieldKind) {
|
|
929
925
|
case "enum":
|
|
930
|
-
return
|
|
926
|
+
return parseTextFormatEnumValue(this.enum, d);
|
|
931
927
|
case "scalar":
|
|
932
|
-
return
|
|
928
|
+
return parseTextFormatScalarValue(this.scalar, d);
|
|
933
929
|
default:
|
|
934
930
|
return undefined;
|
|
935
931
|
}
|
package/dist/descriptor-set.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,4 +11,4 @@
|
|
|
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
|
-
|
|
14
|
+
export {};
|
package/dist/enum.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createEnumType = exports.normalizeEnumValue = void 0;
|
|
4
|
-
function normalizeEnumValue(value) {
|
|
1
|
+
export function normalizeEnumValue(value) {
|
|
5
2
|
if ("localName" in value) {
|
|
6
3
|
return value;
|
|
7
4
|
}
|
|
8
5
|
return { ...value, localName: value.name };
|
|
9
6
|
}
|
|
10
|
-
exports.normalizeEnumValue = normalizeEnumValue;
|
|
11
7
|
/**
|
|
12
8
|
* Create a new EnumType with the given values.
|
|
13
9
|
*/
|
|
14
|
-
function createEnumType(typeName, values,
|
|
10
|
+
export function createEnumType(typeName, values,
|
|
15
11
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
12
|
_opt) {
|
|
17
13
|
const names = Object.create(null);
|
|
@@ -38,4 +34,3 @@ _opt) {
|
|
|
38
34
|
},
|
|
39
35
|
};
|
|
40
36
|
}
|
|
41
|
-
exports.createEnumType = createEnumType;
|
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;
|