@bufbuild/protobuf 1.6.0 → 1.7.0
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/cjs/binary-encoding.js +2 -3
- package/dist/cjs/binary-format.d.ts +17 -0
- package/dist/cjs/binary-format.js +1 -1
- package/dist/cjs/codegen-info.d.ts +4 -4
- package/dist/cjs/codegen-info.js +2 -1
- package/dist/cjs/create-descriptor-set.d.ts +1 -1
- package/dist/cjs/create-descriptor-set.js +56 -50
- package/dist/cjs/create-registry-from-desc.d.ts +2 -2
- package/dist/cjs/create-registry-from-desc.js +53 -9
- package/dist/cjs/create-registry.d.ts +3 -2
- package/dist/cjs/create-registry.js +56 -37
- package/dist/cjs/descriptor-set.js +1 -1
- package/dist/cjs/enum.js +1 -1
- package/dist/cjs/extension-accessor.d.ts +35 -0
- package/dist/cjs/extension-accessor.js +108 -0
- package/dist/cjs/extension.d.ts +24 -0
- package/dist/cjs/extension.js +15 -0
- package/dist/cjs/field-list.js +1 -1
- package/dist/cjs/field.js +1 -1
- package/dist/cjs/google/protobuf/any_pb.js +1 -1
- package/dist/cjs/google/protobuf/api_pb.js +1 -1
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/duration_pb.js +1 -1
- package/dist/cjs/google/protobuf/empty_pb.js +1 -1
- package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
- package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +2 -2
- package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +2 -2
- package/dist/cjs/google/protobuf/wrappers_pb.js +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/json-format.d.ts +5 -5
- package/dist/cjs/json-format.js +1 -1
- package/dist/cjs/message-type.js +1 -1
- package/dist/cjs/message.js +1 -1
- package/dist/cjs/private/assert.js +1 -1
- package/dist/cjs/private/binary-format-common.d.ts +2 -3
- package/dist/cjs/private/binary-format-common.js +80 -78
- package/dist/cjs/private/binary-format-proto2.js +59 -64
- package/dist/cjs/private/binary-format-proto3.js +44 -40
- package/dist/cjs/private/enum.js +1 -1
- package/dist/cjs/private/extensions.d.ts +34 -0
- package/dist/cjs/private/extensions.js +86 -0
- package/dist/cjs/private/feature-set.d.ts +3 -3
- package/dist/cjs/private/feature-set.js +27 -32
- package/dist/cjs/private/field-list.js +1 -1
- package/dist/cjs/private/field-wrapper.d.ts +2 -2
- package/dist/cjs/private/field-wrapper.js +1 -1
- package/dist/cjs/private/field.js +1 -1
- package/dist/cjs/private/json-format-common.js +202 -156
- package/dist/cjs/private/json-format-proto2.js +2 -1
- package/dist/cjs/private/json-format-proto3.js +7 -5
- package/dist/cjs/private/message-type.js +1 -1
- package/dist/cjs/private/names.d.ts +2 -2
- package/dist/cjs/private/names.js +3 -2
- package/dist/cjs/private/options-map.js +1 -1
- package/dist/cjs/private/proto-runtime.d.ts +6 -0
- package/dist/cjs/private/proto-runtime.js +5 -1
- package/dist/cjs/private/reify-wkt.js +1 -1
- package/dist/cjs/private/scalars.js +1 -1
- package/dist/cjs/private/text-format.js +1 -1
- package/dist/cjs/private/util-common.js +1 -1
- package/dist/cjs/private/util.js +1 -1
- package/dist/cjs/proto-base64.js +1 -1
- package/dist/cjs/proto-delimited.js +1 -1
- package/dist/cjs/proto-double.js +1 -1
- package/dist/cjs/proto-int64.js +1 -1
- package/dist/cjs/proto2.js +1 -1
- package/dist/cjs/proto3.js +1 -1
- package/dist/cjs/service-type.js +1 -1
- package/dist/cjs/to-plain-message.js +1 -1
- package/dist/cjs/type-registry.d.ts +14 -0
- package/dist/cjs/type-registry.js +1 -1
- package/dist/esm/binary-encoding.js +2 -3
- package/dist/esm/binary-format.d.ts +17 -0
- package/dist/esm/binary-format.js +1 -1
- package/dist/esm/codegen-info.d.ts +4 -4
- package/dist/esm/codegen-info.js +2 -1
- package/dist/esm/create-descriptor-set.d.ts +1 -1
- package/dist/esm/create-descriptor-set.js +56 -50
- package/dist/esm/create-registry-from-desc.d.ts +2 -2
- package/dist/esm/create-registry-from-desc.js +53 -9
- package/dist/esm/create-registry.d.ts +3 -2
- package/dist/esm/create-registry.js +56 -37
- package/dist/esm/descriptor-set.js +1 -1
- package/dist/esm/enum.js +1 -1
- package/dist/esm/extension-accessor.d.ts +35 -0
- package/dist/esm/extension-accessor.js +101 -0
- package/dist/esm/extension.d.ts +24 -0
- package/dist/esm/extension.js +14 -0
- package/dist/esm/field-list.js +1 -1
- package/dist/esm/field.js +1 -1
- package/dist/esm/google/protobuf/any_pb.js +1 -1
- package/dist/esm/google/protobuf/api_pb.js +1 -1
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/duration_pb.js +1 -1
- package/dist/esm/google/protobuf/empty_pb.js +1 -1
- package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
- package/dist/esm/google/protobuf/source_context_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +2 -2
- package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +2 -2
- package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/json-format.d.ts +5 -5
- package/dist/esm/json-format.js +1 -1
- package/dist/esm/message-type.js +1 -1
- package/dist/esm/message.js +1 -1
- package/dist/esm/private/assert.js +1 -1
- package/dist/esm/private/binary-format-common.d.ts +2 -3
- package/dist/esm/private/binary-format-common.js +80 -77
- package/dist/esm/private/binary-format-proto2.js +59 -64
- package/dist/esm/private/binary-format-proto3.js +44 -40
- package/dist/esm/private/enum.js +1 -1
- package/dist/esm/private/extensions.d.ts +34 -0
- package/dist/esm/private/extensions.js +81 -0
- package/dist/esm/private/feature-set.d.ts +3 -3
- package/dist/esm/private/feature-set.js +27 -32
- package/dist/esm/private/field-list.js +1 -1
- package/dist/esm/private/field-wrapper.d.ts +2 -2
- package/dist/esm/private/field-wrapper.js +1 -1
- package/dist/esm/private/field.js +1 -1
- package/dist/esm/private/json-format-common.js +202 -156
- package/dist/esm/private/json-format-proto2.js +2 -1
- package/dist/esm/private/json-format-proto3.js +7 -5
- package/dist/esm/private/message-type.js +1 -1
- package/dist/esm/private/names.d.ts +2 -2
- package/dist/esm/private/names.js +3 -2
- package/dist/esm/private/options-map.js +1 -1
- package/dist/esm/private/proto-runtime.d.ts +6 -0
- package/dist/esm/private/proto-runtime.js +5 -1
- package/dist/esm/private/reify-wkt.js +1 -1
- package/dist/esm/private/scalars.js +1 -1
- package/dist/esm/private/text-format.js +1 -1
- package/dist/esm/private/util-common.js +1 -1
- package/dist/esm/private/util.js +1 -1
- package/dist/esm/proto-base64.js +1 -1
- package/dist/esm/proto-delimited.js +1 -1
- package/dist/esm/proto-double.js +1 -1
- package/dist/esm/proto-int64.js +1 -1
- package/dist/esm/proto2.js +1 -1
- package/dist/esm/proto3.js +1 -1
- package/dist/esm/service-type.js +1 -1
- package/dist/esm/to-plain-message.js +1 -1
- package/dist/esm/type-registry.d.ts +14 -0
- package/dist/esm/type-registry.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -30,7 +30,8 @@ function localName(desc) {
|
|
|
30
30
|
return localOneofName(desc.name);
|
|
31
31
|
case "enum":
|
|
32
32
|
case "message":
|
|
33
|
-
case "service":
|
|
33
|
+
case "service":
|
|
34
|
+
case "extension": {
|
|
34
35
|
const pkg = desc.file.proto.package;
|
|
35
36
|
const offset = pkg === undefined ? 0 : pkg.length + 1;
|
|
36
37
|
const name = desc.typeName.substring(offset).replace(/\./g, "_");
|
|
@@ -7,6 +7,8 @@ import type { MessageType } from "../message-type.js";
|
|
|
7
7
|
import type { FieldListSource } from "./field-list.js";
|
|
8
8
|
import type { EnumObject } from "./enum.js";
|
|
9
9
|
import type { Util } from "./util.js";
|
|
10
|
+
import type { Extension } from "../extension.js";
|
|
11
|
+
import type { ExtensionFieldSource } from "./extensions.js";
|
|
10
12
|
/**
|
|
11
13
|
* A facade that provides serialization and other internal functionality.
|
|
12
14
|
*/
|
|
@@ -43,5 +45,9 @@ export interface ProtoRuntime {
|
|
|
43
45
|
* enum, or an enum constructed with makeEnum(), it raises an error.
|
|
44
46
|
*/
|
|
45
47
|
getEnumType(enumObject: EnumObject): EnumType;
|
|
48
|
+
/**
|
|
49
|
+
* Create an extension at runtime, without generating code.
|
|
50
|
+
*/
|
|
51
|
+
makeExtension<E extends Message<E> = AnyMessage, V = unknown>(typeName: string, extendee: MessageType<E>, field: ExtensionFieldSource): Extension<E, V>;
|
|
46
52
|
}
|
|
47
53
|
export declare function makeProtoRuntime(syntax: string, json: JsonFormat, bin: BinaryFormat, util: Util): ProtoRuntime;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2021-
|
|
2
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
3
3
|
//
|
|
4
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
exports.makeProtoRuntime = void 0;
|
|
17
17
|
const enum_js_1 = require("./enum.js");
|
|
18
18
|
const message_type_js_1 = require("./message-type.js");
|
|
19
|
+
const extensions_js_1 = require("./extensions.js");
|
|
19
20
|
function makeProtoRuntime(syntax, json, bin, util) {
|
|
20
21
|
return {
|
|
21
22
|
syntax,
|
|
@@ -28,6 +29,9 @@ function makeProtoRuntime(syntax, json, bin, util) {
|
|
|
28
29
|
makeEnum: enum_js_1.makeEnum,
|
|
29
30
|
makeEnumType: enum_js_1.makeEnumType,
|
|
30
31
|
getEnumType: enum_js_1.getEnumType,
|
|
32
|
+
makeExtension(typeName, extendee, field) {
|
|
33
|
+
return (0, extensions_js_1.makeExtension)(this, typeName, extendee, field);
|
|
34
|
+
},
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
37
|
exports.makeProtoRuntime = makeProtoRuntime;
|
package/dist/cjs/private/util.js
CHANGED
package/dist/cjs/proto-base64.js
CHANGED
package/dist/cjs/proto-double.js
CHANGED
package/dist/cjs/proto-int64.js
CHANGED
package/dist/cjs/proto2.js
CHANGED
package/dist/cjs/proto3.js
CHANGED
package/dist/cjs/service-type.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { MessageType } from "./message-type.js";
|
|
2
2
|
import type { EnumType } from "./enum.js";
|
|
3
3
|
import type { ServiceType } from "./service-type.js";
|
|
4
|
+
import type { Extension } from "./extension.js";
|
|
4
5
|
/**
|
|
5
6
|
* IMessageTypeRegistry provides look-up for message types.
|
|
6
7
|
*
|
|
@@ -41,3 +42,16 @@ export interface IServiceTypeRegistry {
|
|
|
41
42
|
*/
|
|
42
43
|
findService(typeName: string): ServiceType | undefined;
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* IExtensionRegistry provides look-up for extensions.
|
|
47
|
+
*/
|
|
48
|
+
export interface IExtensionRegistry {
|
|
49
|
+
/**
|
|
50
|
+
* Find an extension by the extendee type name and the extension number.
|
|
51
|
+
*/
|
|
52
|
+
findExtensionFor(extendee: string, no: number): Extension | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Find an extension type by its protobuf type name.
|
|
55
|
+
*/
|
|
56
|
+
findExtension(typeName: string): Extension | undefined;
|
|
57
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -315,8 +315,7 @@ export class BinaryReader {
|
|
|
315
315
|
this.pos += len;
|
|
316
316
|
break;
|
|
317
317
|
case WireType.StartGroup:
|
|
318
|
-
//
|
|
319
|
-
// But we must still be able to parse and treat as unknown.
|
|
318
|
+
// TODO check for matching field numbers in StartGroup / EndGroup tags
|
|
320
319
|
let t;
|
|
321
320
|
while ((t = this.tag()[1]) !== WireType.EndGroup) {
|
|
322
321
|
this.skip(t);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Message } from "./message.js";
|
|
2
2
|
import type { IBinaryReader, IBinaryWriter, WireType } from "./binary-encoding.js";
|
|
3
|
+
import type { FieldInfo } from "./field.js";
|
|
3
4
|
/**
|
|
4
5
|
* BinaryFormat is the contract for serializing messages to and from binary
|
|
5
6
|
* data. Implementations may be specific to a proto syntax, and can be
|
|
@@ -27,10 +28,26 @@ export interface BinaryFormat {
|
|
|
27
28
|
* delimitedMessageEncoding is optional for backwards compatibility.
|
|
28
29
|
*/
|
|
29
30
|
readMessage(message: Message, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void;
|
|
31
|
+
/**
|
|
32
|
+
* Parse a field from binary data, and store it in the given target.
|
|
33
|
+
*
|
|
34
|
+
* The target must be an initialized message object, with oneof groups,
|
|
35
|
+
* repeated fields and maps already present.
|
|
36
|
+
*/
|
|
37
|
+
readField(target: Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
38
|
+
reader: IBinaryReader, field: FieldInfo, wireType: WireType, options: BinaryReadOptions): void;
|
|
30
39
|
/**
|
|
31
40
|
* Serialize a message to binary data.
|
|
32
41
|
*/
|
|
33
42
|
writeMessage(message: Message, writer: IBinaryWriter, options: BinaryWriteOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Serialize a field value to binary data.
|
|
45
|
+
*
|
|
46
|
+
* The value must be an array for repeated fields, a record object for map
|
|
47
|
+
* fields. Only selected oneof fields should be passed to this method.
|
|
48
|
+
*/
|
|
49
|
+
writeField(field: FieldInfo, value: any, // eslint-disable-line @typescript-eslint/no-explicit-any -- `any` is the best choice for dynamic access
|
|
50
|
+
writer: IBinaryWriter, options: BinaryWriteOptions): void;
|
|
34
51
|
/**
|
|
35
52
|
* Retrieve the unknown fields for the given message.
|
|
36
53
|
*
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { reifyWkt } from "./private/reify-wkt.js";
|
|
2
|
-
import type { DescEnum, DescEnumValue, DescField, DescMessage, DescMethod, DescOneof, DescService } from "./descriptor-set";
|
|
2
|
+
import type { DescEnum, DescEnumValue, DescField, DescExtension, DescMessage, DescMethod, DescOneof, DescService } from "./descriptor-set";
|
|
3
3
|
import { LongType, ScalarType } from "./field.js";
|
|
4
4
|
interface CodegenInfo {
|
|
5
5
|
/**
|
|
6
6
|
* Name of the runtime library NPM package.
|
|
7
7
|
*/
|
|
8
8
|
readonly packageName: string;
|
|
9
|
-
readonly localName: (desc: DescEnum | DescEnumValue | DescMessage | DescOneof | DescField | DescService | DescMethod) => string;
|
|
9
|
+
readonly localName: (desc: DescEnum | DescEnumValue | DescMessage | DescExtension | DescOneof | DescField | DescService | DescMethod) => string;
|
|
10
10
|
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
|
|
11
|
-
readonly getUnwrappedFieldType: (field: DescField) => ScalarType | undefined;
|
|
11
|
+
readonly getUnwrappedFieldType: (field: DescField | DescExtension) => ScalarType | undefined;
|
|
12
12
|
readonly wktSourceFiles: readonly string[];
|
|
13
13
|
readonly scalarDefaultValue: (type: ScalarType, longType: LongType) => any;
|
|
14
14
|
/**
|
|
@@ -18,7 +18,7 @@ interface CodegenInfo {
|
|
|
18
18
|
readonly safeIdentifier: (name: string) => string;
|
|
19
19
|
readonly safeObjectProperty: (name: string) => string;
|
|
20
20
|
}
|
|
21
|
-
type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoDouble" | "protoInt64" | "ScalarType" | "LongType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
|
|
21
|
+
type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "Extension" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoDouble" | "protoInt64" | "ScalarType" | "LongType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
|
|
22
22
|
type RuntimeSymbolInfo = {
|
|
23
23
|
typeOnly: boolean;
|
|
24
24
|
publicImportPath: string;
|
package/dist/esm/codegen-info.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -34,6 +34,7 @@ export const codegenInfo = {
|
|
|
34
34
|
PlainMessage: { typeOnly: true, privateImportPath: "./message.js", publicImportPath: packageName },
|
|
35
35
|
FieldList: { typeOnly: true, privateImportPath: "./field-list.js", publicImportPath: packageName },
|
|
36
36
|
MessageType: { typeOnly: true, privateImportPath: "./message-type.js", publicImportPath: packageName },
|
|
37
|
+
Extension: { typeOnly: true, privateImportPath: "./extension.js", publicImportPath: packageName },
|
|
37
38
|
BinaryReadOptions: { typeOnly: true, privateImportPath: "./binary-format.js", publicImportPath: packageName },
|
|
38
39
|
BinaryWriteOptions: { typeOnly: true, privateImportPath: "./binary-format.js", publicImportPath: packageName },
|
|
39
40
|
JsonReadOptions: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
@@ -20,7 +20,7 @@ interface CreateDescriptorSetOptions {
|
|
|
20
20
|
*
|
|
21
21
|
* To create a DescriptorSet that provides your language-specific features,
|
|
22
22
|
* you have to provide a google.protobuf.FeatureSetDefaults message in this
|
|
23
|
-
* option.
|
|
23
|
+
* option. It can also specify the minimum and maximum supported edition.
|
|
24
24
|
*
|
|
25
25
|
* The defaults can be generated with `protoc` - see the flag
|
|
26
26
|
* `--experimental_edition_defaults_out`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2021-
|
|
1
|
+
// Copyright 2021-2024 Buf Technologies, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -27,27 +27,35 @@ import { createFeatureResolver, featureSetDefaults, } from "./private/feature-se
|
|
|
27
27
|
* files in topological order.
|
|
28
28
|
*/
|
|
29
29
|
export function createDescriptorSet(input, options) {
|
|
30
|
-
var _a;
|
|
31
30
|
const cart = {
|
|
32
31
|
enums: new Map(),
|
|
33
32
|
messages: new Map(),
|
|
34
33
|
services: new Map(),
|
|
35
34
|
extensions: new Map(),
|
|
36
35
|
mapEntries: new Map(),
|
|
37
|
-
resolveFeatures: createFeatureResolver((_a = options === null || options === void 0 ? void 0 : options.featureSetDefaults) !== null && _a !== void 0 ? _a : featureSetDefaults),
|
|
38
36
|
};
|
|
39
37
|
const fileDescriptors = input instanceof FileDescriptorSet
|
|
40
38
|
? input.file
|
|
41
39
|
: input instanceof Uint8Array
|
|
42
40
|
? FileDescriptorSet.fromBinary(input).file
|
|
43
41
|
: input;
|
|
44
|
-
const
|
|
42
|
+
const resolverByEdition = new Map();
|
|
43
|
+
const files = fileDescriptors.map((proto) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const edition = (_a = proto.edition) !== null && _a !== void 0 ? _a : parseFileSyntax(proto.syntax, proto.edition).edition;
|
|
46
|
+
let resolveFeatures = resolverByEdition.get(edition);
|
|
47
|
+
if (resolveFeatures === undefined) {
|
|
48
|
+
resolveFeatures = createFeatureResolver((_b = options === null || options === void 0 ? void 0 : options.featureSetDefaults) !== null && _b !== void 0 ? _b : featureSetDefaults, edition);
|
|
49
|
+
resolverByEdition.set(edition, resolveFeatures);
|
|
50
|
+
}
|
|
51
|
+
return newFile(proto, cart, resolveFeatures);
|
|
52
|
+
});
|
|
45
53
|
return Object.assign({ files }, cart);
|
|
46
54
|
}
|
|
47
55
|
/**
|
|
48
56
|
* Create a descriptor for a file.
|
|
49
57
|
*/
|
|
50
|
-
function newFile(proto, cart) {
|
|
58
|
+
function newFile(proto, cart, resolveFeatures) {
|
|
51
59
|
var _a, _b;
|
|
52
60
|
assert(proto.name, `invalid FileDescriptorProto: missing name`);
|
|
53
61
|
const file = Object.assign(Object.assign({ kind: "file", proto, deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false }, parseFileSyntax(proto.syntax, proto.edition)), { name: proto.name.replace(/\.proto/, ""), enums: [], messages: [], extensions: [], services: [], toString() {
|
|
@@ -66,25 +74,25 @@ function newFile(proto, cart) {
|
|
|
66
74
|
},
|
|
67
75
|
getFeatures() {
|
|
68
76
|
var _a;
|
|
69
|
-
return
|
|
77
|
+
return resolveFeatures((_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
70
78
|
} });
|
|
71
79
|
cart.mapEntries.clear(); // map entries are local to the file, we can safely discard
|
|
72
80
|
for (const enumProto of proto.enumType) {
|
|
73
|
-
addEnum(enumProto, file, undefined, cart);
|
|
81
|
+
addEnum(enumProto, file, undefined, cart, resolveFeatures);
|
|
74
82
|
}
|
|
75
83
|
for (const messageProto of proto.messageType) {
|
|
76
|
-
addMessage(messageProto, file, undefined, cart);
|
|
84
|
+
addMessage(messageProto, file, undefined, cart, resolveFeatures);
|
|
77
85
|
}
|
|
78
86
|
for (const serviceProto of proto.service) {
|
|
79
|
-
addService(serviceProto, file, cart);
|
|
87
|
+
addService(serviceProto, file, cart, resolveFeatures);
|
|
80
88
|
}
|
|
81
|
-
addExtensions(file, cart);
|
|
89
|
+
addExtensions(file, cart, resolveFeatures);
|
|
82
90
|
for (const mapEntry of cart.mapEntries.values()) {
|
|
83
|
-
addFields(mapEntry, cart);
|
|
91
|
+
addFields(mapEntry, cart, resolveFeatures);
|
|
84
92
|
}
|
|
85
93
|
for (const message of file.messages) {
|
|
86
|
-
addFields(message, cart);
|
|
87
|
-
addExtensions(message, cart);
|
|
94
|
+
addFields(message, cart, resolveFeatures);
|
|
95
|
+
addExtensions(message, cart, resolveFeatures);
|
|
88
96
|
}
|
|
89
97
|
cart.mapEntries.clear(); // map entries are local to the file, we can safely discard
|
|
90
98
|
return file;
|
|
@@ -94,23 +102,23 @@ function newFile(proto, cart) {
|
|
|
94
102
|
* and to our cart.
|
|
95
103
|
* Recurses into nested types.
|
|
96
104
|
*/
|
|
97
|
-
function addExtensions(desc, cart) {
|
|
105
|
+
function addExtensions(desc, cart, resolveFeatures) {
|
|
98
106
|
switch (desc.kind) {
|
|
99
107
|
case "file":
|
|
100
108
|
for (const proto of desc.proto.extension) {
|
|
101
|
-
const ext = newExtension(proto, desc, undefined, cart);
|
|
109
|
+
const ext = newExtension(proto, desc, undefined, cart, resolveFeatures);
|
|
102
110
|
desc.extensions.push(ext);
|
|
103
111
|
cart.extensions.set(ext.typeName, ext);
|
|
104
112
|
}
|
|
105
113
|
break;
|
|
106
114
|
case "message":
|
|
107
115
|
for (const proto of desc.proto.extension) {
|
|
108
|
-
const ext = newExtension(proto, desc.file, desc, cart);
|
|
116
|
+
const ext = newExtension(proto, desc.file, desc, cart, resolveFeatures);
|
|
109
117
|
desc.nestedExtensions.push(ext);
|
|
110
118
|
cart.extensions.set(ext.typeName, ext);
|
|
111
119
|
}
|
|
112
120
|
for (const message of desc.nestedMessages) {
|
|
113
|
-
addExtensions(message, cart);
|
|
121
|
+
addExtensions(message, cart, resolveFeatures);
|
|
114
122
|
}
|
|
115
123
|
break;
|
|
116
124
|
}
|
|
@@ -119,12 +127,12 @@ function addExtensions(desc, cart) {
|
|
|
119
127
|
* Create descriptors for fields and oneof groups, and add them to the message.
|
|
120
128
|
* Recurses into nested types.
|
|
121
129
|
*/
|
|
122
|
-
function addFields(message, cart) {
|
|
123
|
-
const allOneofs = message.proto.oneofDecl.map((proto) => newOneof(proto, message,
|
|
130
|
+
function addFields(message, cart, resolveFeatures) {
|
|
131
|
+
const allOneofs = message.proto.oneofDecl.map((proto) => newOneof(proto, message, resolveFeatures));
|
|
124
132
|
const oneofsSeen = new Set();
|
|
125
133
|
for (const proto of message.proto.field) {
|
|
126
134
|
const oneof = findOneof(proto, allOneofs);
|
|
127
|
-
const field = newField(proto, message.file, message, oneof, cart);
|
|
135
|
+
const field = newField(proto, message.file, message, oneof, cart, resolveFeatures);
|
|
128
136
|
message.fields.push(field);
|
|
129
137
|
if (oneof === undefined) {
|
|
130
138
|
message.members.push(field);
|
|
@@ -141,14 +149,14 @@ function addFields(message, cart) {
|
|
|
141
149
|
message.oneofs.push(oneof);
|
|
142
150
|
}
|
|
143
151
|
for (const child of message.nestedMessages) {
|
|
144
|
-
addFields(child, cart);
|
|
152
|
+
addFields(child, cart, resolveFeatures);
|
|
145
153
|
}
|
|
146
154
|
}
|
|
147
155
|
/**
|
|
148
156
|
* Create a descriptor for an enumeration, and add it our cart and to the
|
|
149
157
|
* parent type, if any.
|
|
150
158
|
*/
|
|
151
|
-
function addEnum(proto, file, parent, cart) {
|
|
159
|
+
function addEnum(proto, file, parent, cart, resolveFeatures) {
|
|
152
160
|
var _a, _b, _c;
|
|
153
161
|
assert(proto.name, `invalid EnumDescriptorProto: missing name`);
|
|
154
162
|
const desc = {
|
|
@@ -178,9 +186,8 @@ function addEnum(proto, file, parent, cart) {
|
|
|
178
186
|
return findComments(file.proto.sourceCodeInfo, path);
|
|
179
187
|
},
|
|
180
188
|
getFeatures() {
|
|
181
|
-
var _a, _b
|
|
182
|
-
|
|
183
|
-
return cart.resolveFeatures(this.file.edition, parentFeatures, (_c = this.proto.options) === null || _c === void 0 ? void 0 : _c.features);
|
|
189
|
+
var _a, _b;
|
|
190
|
+
return resolveFeatures((_a = parent === null || parent === void 0 ? void 0 : parent.getFeatures()) !== null && _a !== void 0 ? _a : file.getFeatures(), (_b = proto.options) === null || _b === void 0 ? void 0 : _b.features);
|
|
184
191
|
},
|
|
185
192
|
};
|
|
186
193
|
cart.enums.set(desc.typeName, desc);
|
|
@@ -216,7 +223,7 @@ function addEnum(proto, file, parent, cart) {
|
|
|
216
223
|
},
|
|
217
224
|
getFeatures() {
|
|
218
225
|
var _a;
|
|
219
|
-
return
|
|
226
|
+
return resolveFeatures(desc.getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
220
227
|
},
|
|
221
228
|
});
|
|
222
229
|
});
|
|
@@ -226,7 +233,7 @@ function addEnum(proto, file, parent, cart) {
|
|
|
226
233
|
* Create a descriptor for a message, including nested types, and add it to our
|
|
227
234
|
* cart. Note that this does not create descriptors fields.
|
|
228
235
|
*/
|
|
229
|
-
function addMessage(proto, file, parent, cart) {
|
|
236
|
+
function addMessage(proto, file, parent, cart, resolveFeatures) {
|
|
230
237
|
var _a, _b, _c, _d;
|
|
231
238
|
assert(proto.name, `invalid DescriptorProto: missing name`);
|
|
232
239
|
const desc = {
|
|
@@ -260,9 +267,8 @@ function addMessage(proto, file, parent, cart) {
|
|
|
260
267
|
return findComments(file.proto.sourceCodeInfo, path);
|
|
261
268
|
},
|
|
262
269
|
getFeatures() {
|
|
263
|
-
var _a, _b
|
|
264
|
-
|
|
265
|
-
return cart.resolveFeatures(this.file.edition, parentFeatures, (_c = this.proto.options) === null || _c === void 0 ? void 0 : _c.features);
|
|
270
|
+
var _a, _b;
|
|
271
|
+
return resolveFeatures((_a = parent === null || parent === void 0 ? void 0 : parent.getFeatures()) !== null && _a !== void 0 ? _a : file.getFeatures(), (_b = proto.options) === null || _b === void 0 ? void 0 : _b.features);
|
|
266
272
|
},
|
|
267
273
|
};
|
|
268
274
|
if (((_c = proto.options) === null || _c === void 0 ? void 0 : _c.mapEntry) === true) {
|
|
@@ -273,17 +279,17 @@ function addMessage(proto, file, parent, cart) {
|
|
|
273
279
|
cart.messages.set(desc.typeName, desc);
|
|
274
280
|
}
|
|
275
281
|
for (const enumProto of proto.enumType) {
|
|
276
|
-
addEnum(enumProto, file, desc, cart);
|
|
282
|
+
addEnum(enumProto, file, desc, cart, resolveFeatures);
|
|
277
283
|
}
|
|
278
284
|
for (const messageProto of proto.nestedType) {
|
|
279
|
-
addMessage(messageProto, file, desc, cart);
|
|
285
|
+
addMessage(messageProto, file, desc, cart, resolveFeatures);
|
|
280
286
|
}
|
|
281
287
|
}
|
|
282
288
|
/**
|
|
283
289
|
* Create a descriptor for a service, including methods, and add it to our
|
|
284
290
|
* cart.
|
|
285
291
|
*/
|
|
286
|
-
function addService(proto, file, cart) {
|
|
292
|
+
function addService(proto, file, cart, resolveFeatures) {
|
|
287
293
|
var _a, _b;
|
|
288
294
|
assert(proto.name, `invalid ServiceDescriptorProto: missing name`);
|
|
289
295
|
const desc = {
|
|
@@ -306,19 +312,19 @@ function addService(proto, file, cart) {
|
|
|
306
312
|
},
|
|
307
313
|
getFeatures() {
|
|
308
314
|
var _a;
|
|
309
|
-
return
|
|
315
|
+
return resolveFeatures(file.getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
310
316
|
},
|
|
311
317
|
};
|
|
312
318
|
file.services.push(desc);
|
|
313
319
|
cart.services.set(desc.typeName, desc);
|
|
314
320
|
for (const methodProto of proto.method) {
|
|
315
|
-
desc.methods.push(newMethod(methodProto, desc, cart));
|
|
321
|
+
desc.methods.push(newMethod(methodProto, desc, cart, resolveFeatures));
|
|
316
322
|
}
|
|
317
323
|
}
|
|
318
324
|
/**
|
|
319
325
|
* Create a descriptor for a method.
|
|
320
326
|
*/
|
|
321
|
-
function newMethod(proto, parent, cart) {
|
|
327
|
+
function newMethod(proto, parent, cart, resolveFeatures) {
|
|
322
328
|
var _a, _b, _c;
|
|
323
329
|
assert(proto.name, `invalid MethodDescriptorProto: missing name`);
|
|
324
330
|
assert(proto.inputType, `invalid MethodDescriptorProto: missing input_type`);
|
|
@@ -377,14 +383,14 @@ function newMethod(proto, parent, cart) {
|
|
|
377
383
|
},
|
|
378
384
|
getFeatures() {
|
|
379
385
|
var _a;
|
|
380
|
-
return
|
|
386
|
+
return resolveFeatures(parent.getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
381
387
|
},
|
|
382
388
|
};
|
|
383
389
|
}
|
|
384
390
|
/**
|
|
385
391
|
* Create a descriptor for a oneof group.
|
|
386
392
|
*/
|
|
387
|
-
function newOneof(proto, parent,
|
|
393
|
+
function newOneof(proto, parent, resolveFeatures) {
|
|
388
394
|
assert(proto.name, `invalid OneofDescriptorProto: missing name`);
|
|
389
395
|
return {
|
|
390
396
|
kind: "oneof",
|
|
@@ -406,14 +412,14 @@ function newOneof(proto, parent, cart) {
|
|
|
406
412
|
},
|
|
407
413
|
getFeatures() {
|
|
408
414
|
var _a;
|
|
409
|
-
return
|
|
415
|
+
return resolveFeatures(parent.getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
410
416
|
},
|
|
411
417
|
};
|
|
412
418
|
}
|
|
413
419
|
/**
|
|
414
420
|
* Create a descriptor for a field.
|
|
415
421
|
*/
|
|
416
|
-
function newField(proto, file, parent, oneof, cart) {
|
|
422
|
+
function newField(proto, file, parent, oneof, cart, resolveFeatures) {
|
|
417
423
|
var _a, _b, _c;
|
|
418
424
|
assert(proto.name, `invalid FieldDescriptorProto: missing name`);
|
|
419
425
|
assert(proto.number, `invalid FieldDescriptorProto: missing number`);
|
|
@@ -426,8 +432,8 @@ function newField(proto, file, parent, oneof, cart) {
|
|
|
426
432
|
parent,
|
|
427
433
|
oneof,
|
|
428
434
|
optional: isOptionalField(proto, file.syntax),
|
|
429
|
-
packedByDefault: isPackedFieldByDefault(
|
|
430
|
-
packed: isPackedField(file, parent, proto,
|
|
435
|
+
packedByDefault: isPackedFieldByDefault(proto, resolveFeatures),
|
|
436
|
+
packed: isPackedField(file, parent, proto, resolveFeatures),
|
|
431
437
|
jsonName: proto.jsonName === fieldJsonName(proto.name) ? undefined : proto.jsonName,
|
|
432
438
|
scalar: undefined,
|
|
433
439
|
longType: undefined,
|
|
@@ -450,7 +456,7 @@ function newField(proto, file, parent, oneof, cart) {
|
|
|
450
456
|
},
|
|
451
457
|
getFeatures() {
|
|
452
458
|
var _a;
|
|
453
|
-
return
|
|
459
|
+
return resolveFeatures(parent.getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
454
460
|
},
|
|
455
461
|
};
|
|
456
462
|
const repeated = proto.label === FieldDescriptorProto_Label.REPEATED;
|
|
@@ -489,10 +495,10 @@ function newField(proto, file, parent, oneof, cart) {
|
|
|
489
495
|
/**
|
|
490
496
|
* Create a descriptor for an extension field.
|
|
491
497
|
*/
|
|
492
|
-
function newExtension(proto, file, parent, cart) {
|
|
498
|
+
function newExtension(proto, file, parent, cart, resolveFeatures) {
|
|
493
499
|
assert(proto.extendee, `invalid FieldDescriptorProto: missing extendee`);
|
|
494
500
|
const field = newField(proto, file, null, // to safe us many lines of duplicated code, we trick the type system
|
|
495
|
-
undefined, cart);
|
|
501
|
+
undefined, cart, resolveFeatures);
|
|
496
502
|
const extendee = cart.messages.get(trimLeadingDot(proto.extendee));
|
|
497
503
|
assert(extendee, `invalid FieldDescriptorProto: extendee ${proto.extendee} not found`);
|
|
498
504
|
return Object.assign(Object.assign({}, field), { kind: "extension", typeName: makeTypeName(proto, parent, file), parent,
|
|
@@ -517,8 +523,8 @@ function newExtension(proto, file, parent, cart) {
|
|
|
517
523
|
return findComments(file.proto.sourceCodeInfo, path);
|
|
518
524
|
},
|
|
519
525
|
getFeatures() {
|
|
520
|
-
var _a
|
|
521
|
-
return
|
|
526
|
+
var _a;
|
|
527
|
+
return resolveFeatures((parent !== null && parent !== void 0 ? parent : file).getFeatures(), (_a = proto.options) === null || _a === void 0 ? void 0 : _a.features);
|
|
522
528
|
} });
|
|
523
529
|
}
|
|
524
530
|
/**
|
|
@@ -674,8 +680,8 @@ function isOptionalField(proto, syntax) {
|
|
|
674
680
|
* are unpacked by default. With editions, the default is whatever the edition
|
|
675
681
|
* specifies as a default. In edition 2023, fields are packed by default.
|
|
676
682
|
*/
|
|
677
|
-
function isPackedFieldByDefault(
|
|
678
|
-
const { repeatedFieldEncoding } = resolveFeatures(
|
|
683
|
+
function isPackedFieldByDefault(proto, resolveFeatures) {
|
|
684
|
+
const { repeatedFieldEncoding } = resolveFeatures();
|
|
679
685
|
if (repeatedFieldEncoding != FeatureSet_RepeatedFieldEncoding.PACKED) {
|
|
680
686
|
return false;
|
|
681
687
|
}
|
|
@@ -716,7 +722,7 @@ function isPackedField(file, parent, proto, resolveFeatures) {
|
|
|
716
722
|
case Edition.EDITION_PROTO3:
|
|
717
723
|
return (_d = (_c = proto.options) === null || _c === void 0 ? void 0 : _c.packed) !== null && _d !== void 0 ? _d : true;
|
|
718
724
|
default: {
|
|
719
|
-
const { repeatedFieldEncoding } = resolveFeatures(
|
|
725
|
+
const { repeatedFieldEncoding } = resolveFeatures((_e = parent === null || parent === void 0 ? void 0 : parent.getFeatures()) !== null && _e !== void 0 ? _e : file.getFeatures(), (_f = proto.options) === null || _f === void 0 ? void 0 : _f.features);
|
|
720
726
|
return (repeatedFieldEncoding == FeatureSet_RepeatedFieldEncoding.PACKED);
|
|
721
727
|
}
|
|
722
728
|
}
|