@bufbuild/protobuf 0.0.6 → 0.0.9
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/README.md +34 -4
- package/dist/cjs/binary-encoding.js +2 -2
- package/dist/cjs/codegen-info.js +60 -0
- package/dist/cjs/create-descriptor-set.js +952 -0
- package/dist/cjs/create-registry-from-desc.js +376 -0
- package/dist/cjs/create-registry.js +75 -0
- package/dist/cjs/descriptor-set.js +0 -458
- package/dist/cjs/google/protobuf/any_pb.js +4 -2
- package/dist/cjs/google/protobuf/duration_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +2 -2
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/{descriptor-registry.js → legacy-descriptor-registry.js} +35 -69
- package/dist/cjs/legacy-descriptor-set.js +453 -0
- package/dist/cjs/legacy-type-registry.js +104 -0
- package/dist/cjs/message.js +2 -1
- package/dist/cjs/private/binary-format-common.js +4 -3
- package/dist/cjs/private/binary-format-proto2.js +3 -6
- package/dist/cjs/private/binary-format-proto3.js +2 -5
- package/dist/cjs/private/enum.js +22 -31
- package/dist/cjs/private/field-wrapper.js +30 -1
- package/dist/cjs/private/field.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -5
- package/dist/cjs/private/message-type.js +2 -1
- package/dist/cjs/private/names.js +168 -29
- package/dist/cjs/proto-int64.js +1 -1
- package/dist/cjs/proto2.js +7 -9
- package/dist/cjs/proto3.js +10 -13
- package/dist/cjs/type-registry.js +0 -87
- package/dist/esm/binary-encoding.js +2 -2
- package/dist/esm/codegen-info.js +57 -0
- package/dist/esm/create-descriptor-set.js +947 -0
- package/dist/esm/create-registry-from-desc.js +371 -0
- package/dist/esm/create-registry.js +71 -0
- package/dist/esm/descriptor-set.js +1 -456
- package/dist/esm/google/protobuf/any_pb.js +4 -2
- package/dist/esm/google/protobuf/duration_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +2 -2
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/index.js +9 -3
- package/dist/esm/{descriptor-registry.js → legacy-descriptor-registry.js} +33 -67
- package/dist/esm/legacy-descriptor-set.js +449 -0
- package/dist/esm/legacy-type-registry.js +100 -0
- package/dist/esm/message.js +2 -1
- package/dist/esm/private/binary-format-common.js +4 -3
- package/dist/esm/private/binary-format-proto2.js +3 -6
- package/dist/esm/private/binary-format-proto3.js +2 -5
- package/dist/esm/private/enum.js +22 -31
- package/dist/esm/private/field-wrapper.js +28 -0
- package/dist/esm/private/field.js +2 -2
- package/dist/esm/private/json-format-common.js +6 -5
- package/dist/esm/private/message-type.js +2 -1
- package/dist/esm/private/names.js +163 -24
- package/dist/esm/proto-int64.js +1 -1
- package/dist/esm/proto2.js +8 -10
- package/dist/esm/proto3.js +11 -14
- package/dist/esm/type-registry.js +1 -85
- package/dist/types/codegen-info.d.ts +19 -0
- package/dist/types/create-descriptor-set.d.ts +16 -0
- package/dist/types/create-registry-from-desc.d.ts +49 -0
- package/dist/types/create-registry.d.ts +8 -0
- package/dist/types/descriptor-set.d.ts +554 -108
- package/dist/types/enum.d.ts +9 -5
- package/dist/types/index.d.ts +9 -3
- package/dist/types/{descriptor-registry.d.ts → legacy-descriptor-registry.d.ts} +8 -6
- package/dist/types/legacy-descriptor-set.d.ts +152 -0
- package/dist/types/legacy-type-registry.d.ts +44 -0
- package/dist/types/private/enum.d.ts +4 -8
- package/dist/types/private/field-wrapper.d.ts +7 -0
- package/dist/types/private/message-type.d.ts +1 -4
- package/dist/types/private/names.d.ts +26 -8
- package/dist/types/private/proto-runtime.d.ts +2 -2
- package/dist/types/private/util.d.ts +1 -6
- package/dist/types/type-registry.d.ts +0 -38
- package/package.json +4 -3
package/dist/esm/proto3.js
CHANGED
|
@@ -19,13 +19,11 @@ import { InternalFieldList } from "./private/field-list.js";
|
|
|
19
19
|
import { scalarDefaultValue } from "./private/scalars.js";
|
|
20
20
|
import { ScalarType } from "./field.js";
|
|
21
21
|
import { InternalOneofInfo } from "./private/field.js";
|
|
22
|
-
import {
|
|
22
|
+
import { localFieldName, fieldJsonName } from "./private/names.js";
|
|
23
23
|
/**
|
|
24
24
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
25
25
|
*/
|
|
26
|
-
export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), {
|
|
27
|
-
...makeUtilCommon(),
|
|
28
|
-
newFieldList(fields) {
|
|
26
|
+
export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), Object.assign(Object.assign({}, makeUtilCommon()), { newFieldList(fields) {
|
|
29
27
|
return new InternalFieldList(fields, normalizeFieldInfosProto3);
|
|
30
28
|
},
|
|
31
29
|
initFields(target) {
|
|
@@ -56,30 +54,29 @@ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBin
|
|
|
56
54
|
break;
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
57
|
+
} }));
|
|
61
58
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
62
59
|
function normalizeFieldInfosProto3(fieldInfos) {
|
|
60
|
+
var _a, _b, _c;
|
|
63
61
|
const r = [];
|
|
64
62
|
let o;
|
|
65
63
|
for (const field of typeof fieldInfos == "function"
|
|
66
64
|
? fieldInfos()
|
|
67
65
|
: fieldInfos) {
|
|
68
66
|
const f = field;
|
|
69
|
-
f.localName =
|
|
70
|
-
f.jsonName = field.jsonName
|
|
71
|
-
f.repeated = field.repeated
|
|
67
|
+
f.localName = localFieldName(field.name, field.oneof !== undefined);
|
|
68
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : fieldJsonName(field.name);
|
|
69
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
72
70
|
// From the proto3 language guide:
|
|
73
71
|
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
74
72
|
// This information is incomplete - according to the conformance tests, BOOL
|
|
75
73
|
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
76
74
|
// are not packed by default, which makes sense because they are length-delimited.
|
|
77
75
|
f.packed =
|
|
78
|
-
field.packed
|
|
79
|
-
(field.kind == "
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
field.T != ScalarType.STRING));
|
|
76
|
+
(_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
|
|
77
|
+
(field.kind == "scalar" &&
|
|
78
|
+
field.T != ScalarType.BYTES &&
|
|
79
|
+
field.T != ScalarType.STRING));
|
|
83
80
|
// We do not surface options at this time
|
|
84
81
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
85
82
|
if (field.oneof !== undefined) {
|
|
@@ -11,88 +11,4 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
* TypeRegistry is a simple registry for all message, enum, or service types.
|
|
16
|
-
*/
|
|
17
|
-
export class TypeRegistry {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.messages = {};
|
|
20
|
-
this.enums = {};
|
|
21
|
-
this.services = {};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Find a message type by its protobuf type name.
|
|
25
|
-
*/
|
|
26
|
-
findMessage(typeName) {
|
|
27
|
-
return this.messages[typeName];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Find an enum type by its protobuf type name.
|
|
31
|
-
*/
|
|
32
|
-
findEnum(typeName) {
|
|
33
|
-
return this.enums[typeName];
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Find a service type by its protobuf type name.
|
|
37
|
-
*/
|
|
38
|
-
findService(typeName) {
|
|
39
|
-
return this.services[typeName];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Create a new TypeRegistry from the given types.
|
|
43
|
-
*/
|
|
44
|
-
static from(...types) {
|
|
45
|
-
const registry = new TypeRegistry();
|
|
46
|
-
for (const type of types) {
|
|
47
|
-
registry.add(type);
|
|
48
|
-
}
|
|
49
|
-
return registry;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated use TypeRegistry.from()
|
|
53
|
-
*/
|
|
54
|
-
static fromIterable(types) {
|
|
55
|
-
return TypeRegistry.from(...types);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated use TypeRegistry.from()
|
|
59
|
-
*/
|
|
60
|
-
static fromTypes(...types) {
|
|
61
|
-
return TypeRegistry.from(...types);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Add a type to the registry. For messages, the types used in message
|
|
65
|
-
* fields are added recursively. For services, the message types used
|
|
66
|
-
* for requests and responses are added recursively.
|
|
67
|
-
*/
|
|
68
|
-
add(type) {
|
|
69
|
-
if ("fields" in type) {
|
|
70
|
-
if (!this.findMessage(type.typeName)) {
|
|
71
|
-
this.messages[type.typeName] = type;
|
|
72
|
-
for (const field of type.fields.list()) {
|
|
73
|
-
if (field.kind == "message") {
|
|
74
|
-
this.add(field.T);
|
|
75
|
-
}
|
|
76
|
-
else if (field.kind == "map" && field.V.kind == "message") {
|
|
77
|
-
this.add(field.V.T);
|
|
78
|
-
}
|
|
79
|
-
else if (field.kind == "enum") {
|
|
80
|
-
this.add(field.T);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else if ("methods" in type) {
|
|
86
|
-
if (!this.findService(type.typeName)) {
|
|
87
|
-
this.services[type.typeName] = type;
|
|
88
|
-
for (const method of Object.values(type.methods)) {
|
|
89
|
-
this.add(method.I);
|
|
90
|
-
this.add(method.O);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.enums[type.typeName] = type;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { localName } from "./private/names.js";
|
|
2
|
+
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
3
|
+
import { scalarDefaultValue } from "./private/scalars.js";
|
|
4
|
+
interface CodegenInfo {
|
|
5
|
+
readonly packageName: string;
|
|
6
|
+
readonly localName: typeof localName;
|
|
7
|
+
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
|
|
8
|
+
readonly getUnwrappedFieldType: typeof getUnwrappedFieldType;
|
|
9
|
+
readonly wktSourceFiles: readonly string[];
|
|
10
|
+
readonly scalarDefaultValue: typeof scalarDefaultValue;
|
|
11
|
+
}
|
|
12
|
+
declare type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency";
|
|
13
|
+
declare type RuntimeSymbolInfo = {
|
|
14
|
+
typeOnly: boolean;
|
|
15
|
+
publicImportPath: string;
|
|
16
|
+
privateImportPath: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const codegenInfo: CodegenInfo;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldDescriptorProto } from "./google/protobuf/descriptor_pb.js";
|
|
2
|
+
import { FileDescriptorProto, FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
3
|
+
import type { DescriptorSet } from "./descriptor-set.js";
|
|
4
|
+
/**
|
|
5
|
+
* Create a DescriptorSet, a convenient interface for working with a set of
|
|
6
|
+
* google.protobuf.FileDescriptorProto.
|
|
7
|
+
*
|
|
8
|
+
* Note that files must be given in topological order, so each file appears
|
|
9
|
+
* before any file that imports it. Protocol buffer compilers always produce
|
|
10
|
+
* files in topological order.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDescriptorSet(input: FileDescriptorProto[] | FileDescriptorSet | Uint8Array): DescriptorSet;
|
|
13
|
+
/**
|
|
14
|
+
* Get the default `packed` state of a repeated field.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isPackedFieldByDefault(proto: FieldDescriptorProto, syntax: "proto2" | "proto3"): boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { MessageType } from "./message-type.js";
|
|
2
|
+
import type { EnumType } from "./enum.js";
|
|
3
|
+
import type { IEnumTypeRegistry, IMessageTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
|
|
4
|
+
import type { ServiceType } from "./service-type.js";
|
|
5
|
+
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
6
|
+
import type { DescriptorSet } from "./descriptor-set.js";
|
|
7
|
+
/**
|
|
8
|
+
* Create a registry from a set of descriptors. The types returned by this
|
|
9
|
+
* registry behave exactly like types from generated code.
|
|
10
|
+
*
|
|
11
|
+
* This function accepts google.protobuf.FileDescriptorSet in serialized or
|
|
12
|
+
* deserialized form. Alternatively, it also accepts a DescriptorSet (see
|
|
13
|
+
* createDescriptorSet()).
|
|
14
|
+
*
|
|
15
|
+
* By default, all well-known types with a specialized JSON representation
|
|
16
|
+
* are replaced with their generated counterpart in this package.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createRegistryFromDescriptors(input: DescriptorSet | FileDescriptorSet | Uint8Array, replaceWkt?: boolean): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;
|
|
19
|
+
/**
|
|
20
|
+
* DescriptorRegistry is a type registry that dynamically creates types
|
|
21
|
+
* from a set of google.protobuf.FileDescriptorProto.
|
|
22
|
+
*
|
|
23
|
+
* By default, all well-known types with a specialized JSON representation
|
|
24
|
+
* are replaced with their generated counterpart in this package.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DescriptorRegistry implements IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry {
|
|
27
|
+
private readonly desc;
|
|
28
|
+
private readonly enums;
|
|
29
|
+
private readonly messages;
|
|
30
|
+
private readonly services;
|
|
31
|
+
constructor(descriptorSet: DescriptorSet, replaceWkt?: boolean);
|
|
32
|
+
/**
|
|
33
|
+
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
|
|
34
|
+
* or a FileDescriptorSet in binary format.
|
|
35
|
+
*/
|
|
36
|
+
static fromFileDescriptorSet(input: FileDescriptorSet | Uint8Array): DescriptorRegistry;
|
|
37
|
+
/**
|
|
38
|
+
* May raise an error on invalid descriptors.
|
|
39
|
+
*/
|
|
40
|
+
findEnum(typeName: string): EnumType | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* May raise an error on invalid descriptors.
|
|
43
|
+
*/
|
|
44
|
+
findMessage(typeName: string): MessageType | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* May raise an error on invalid descriptors.
|
|
47
|
+
*/
|
|
48
|
+
findService(typeName: string): ServiceType | undefined;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MessageType } from "./message-type.js";
|
|
2
|
+
import type { EnumType } from "./enum.js";
|
|
3
|
+
import type { ServiceType } from "./service-type.js";
|
|
4
|
+
import type { IMessageTypeRegistry, IEnumTypeRegistry, IServiceTypeRegistry } from "./type-registry.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a new registry from the given types. Note that
|
|
7
|
+
*/
|
|
8
|
+
export declare function createRegistry(...types: Array<MessageType | EnumType | ServiceType>): IMessageTypeRegistry & IEnumTypeRegistry & IServiceTypeRegistry;
|