@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/cjs/proto3.js
CHANGED
|
@@ -26,9 +26,7 @@ const names_js_1 = require("./private/names.js");
|
|
|
26
26
|
/**
|
|
27
27
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
28
28
|
*/
|
|
29
|
-
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_format_proto3_js_1.makeJsonFormatProto3)(), (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(), {
|
|
30
|
-
...(0, util_common_js_1.makeUtilCommon)(),
|
|
31
|
-
newFieldList(fields) {
|
|
29
|
+
exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_format_proto3_js_1.makeJsonFormatProto3)(), (0, binary_format_proto3_js_1.makeBinaryFormatProto3)(), Object.assign(Object.assign({}, (0, util_common_js_1.makeUtilCommon)()), { newFieldList(fields) {
|
|
32
30
|
return new field_list_js_1.InternalFieldList(fields, normalizeFieldInfosProto3);
|
|
33
31
|
},
|
|
34
32
|
initFields(target) {
|
|
@@ -59,30 +57,29 @@ exports.proto3 = (0, proto_runtime_js_1.makeProtoRuntime)("proto3", (0, json_for
|
|
|
59
57
|
break;
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
}
|
|
63
|
-
});
|
|
60
|
+
} }));
|
|
64
61
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
65
62
|
function normalizeFieldInfosProto3(fieldInfos) {
|
|
63
|
+
var _a, _b, _c;
|
|
66
64
|
const r = [];
|
|
67
65
|
let o;
|
|
68
66
|
for (const field of typeof fieldInfos == "function"
|
|
69
67
|
? fieldInfos()
|
|
70
68
|
: fieldInfos) {
|
|
71
69
|
const f = field;
|
|
72
|
-
f.localName = (0, names_js_1.
|
|
73
|
-
f.jsonName = field.jsonName
|
|
74
|
-
f.repeated = field.repeated
|
|
70
|
+
f.localName = (0, names_js_1.localFieldName)(field.name, field.oneof !== undefined);
|
|
71
|
+
f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : (0, names_js_1.fieldJsonName)(field.name);
|
|
72
|
+
f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
|
|
75
73
|
// From the proto3 language guide:
|
|
76
74
|
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
77
75
|
// This information is incomplete - according to the conformance tests, BOOL
|
|
78
76
|
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
79
77
|
// are not packed by default, which makes sense because they are length-delimited.
|
|
80
78
|
f.packed =
|
|
81
|
-
field.packed
|
|
82
|
-
(field.kind == "
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
field.T != field_js_1.ScalarType.STRING));
|
|
79
|
+
(_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
|
|
80
|
+
(field.kind == "scalar" &&
|
|
81
|
+
field.T != field_js_1.ScalarType.BYTES &&
|
|
82
|
+
field.T != field_js_1.ScalarType.STRING));
|
|
86
83
|
// We do not surface options at this time
|
|
87
84
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
88
85
|
if (field.oneof !== undefined) {
|
|
@@ -13,90 +13,3 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.TypeRegistry = void 0;
|
|
17
|
-
/**
|
|
18
|
-
* TypeRegistry is a simple registry for all message, enum, or service types.
|
|
19
|
-
*/
|
|
20
|
-
class TypeRegistry {
|
|
21
|
-
constructor() {
|
|
22
|
-
this.messages = {};
|
|
23
|
-
this.enums = {};
|
|
24
|
-
this.services = {};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Find a message type by its protobuf type name.
|
|
28
|
-
*/
|
|
29
|
-
findMessage(typeName) {
|
|
30
|
-
return this.messages[typeName];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Find an enum type by its protobuf type name.
|
|
34
|
-
*/
|
|
35
|
-
findEnum(typeName) {
|
|
36
|
-
return this.enums[typeName];
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Find a service type by its protobuf type name.
|
|
40
|
-
*/
|
|
41
|
-
findService(typeName) {
|
|
42
|
-
return this.services[typeName];
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a new TypeRegistry from the given types.
|
|
46
|
-
*/
|
|
47
|
-
static from(...types) {
|
|
48
|
-
const registry = new TypeRegistry();
|
|
49
|
-
for (const type of types) {
|
|
50
|
-
registry.add(type);
|
|
51
|
-
}
|
|
52
|
-
return registry;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated use TypeRegistry.from()
|
|
56
|
-
*/
|
|
57
|
-
static fromIterable(types) {
|
|
58
|
-
return TypeRegistry.from(...types);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated use TypeRegistry.from()
|
|
62
|
-
*/
|
|
63
|
-
static fromTypes(...types) {
|
|
64
|
-
return TypeRegistry.from(...types);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Add a type to the registry. For messages, the types used in message
|
|
68
|
-
* fields are added recursively. For services, the message types used
|
|
69
|
-
* for requests and responses are added recursively.
|
|
70
|
-
*/
|
|
71
|
-
add(type) {
|
|
72
|
-
if ("fields" in type) {
|
|
73
|
-
if (!this.findMessage(type.typeName)) {
|
|
74
|
-
this.messages[type.typeName] = type;
|
|
75
|
-
for (const field of type.fields.list()) {
|
|
76
|
-
if (field.kind == "message") {
|
|
77
|
-
this.add(field.T);
|
|
78
|
-
}
|
|
79
|
-
else if (field.kind == "map" && field.V.kind == "message") {
|
|
80
|
-
this.add(field.V.T);
|
|
81
|
-
}
|
|
82
|
-
else if (field.kind == "enum") {
|
|
83
|
-
this.add(field.T);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else if ("methods" in type) {
|
|
89
|
-
if (!this.findService(type.typeName)) {
|
|
90
|
-
this.services[type.typeName] = type;
|
|
91
|
-
for (const method of Object.values(type.methods)) {
|
|
92
|
-
this.add(method.I);
|
|
93
|
-
this.add(method.O);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.enums[type.typeName] = type;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.TypeRegistry = TypeRegistry;
|
|
@@ -64,7 +64,7 @@ export class BinaryWriter {
|
|
|
64
64
|
* Previous fork states.
|
|
65
65
|
*/
|
|
66
66
|
this.stack = [];
|
|
67
|
-
this.textEncoder = textEncoder
|
|
67
|
+
this.textEncoder = textEncoder !== null && textEncoder !== void 0 ? textEncoder : new TextEncoder();
|
|
68
68
|
this.chunks = [];
|
|
69
69
|
this.buf = [];
|
|
70
70
|
}
|
|
@@ -279,7 +279,7 @@ export class BinaryReader {
|
|
|
279
279
|
this.len = buf.length;
|
|
280
280
|
this.pos = 0;
|
|
281
281
|
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
282
|
-
this.textDecoder = textDecoder
|
|
282
|
+
this.textDecoder = textDecoder !== null && textDecoder !== void 0 ? textDecoder : new TextDecoder();
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
285
|
* Reads a tag - field number and wire type.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { localName } from "./private/names.js";
|
|
15
|
+
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
|
|
16
|
+
import { scalarDefaultValue } from "./private/scalars.js";
|
|
17
|
+
const packageName = "@bufbuild/protobuf";
|
|
18
|
+
export const codegenInfo = {
|
|
19
|
+
packageName,
|
|
20
|
+
localName,
|
|
21
|
+
getUnwrappedFieldType,
|
|
22
|
+
scalarDefaultValue,
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
symbols: {
|
|
25
|
+
proto2: { typeOnly: false, privateImportPath: "./proto2.js", publicImportPath: packageName },
|
|
26
|
+
proto3: { typeOnly: false, privateImportPath: "./proto3.js", publicImportPath: packageName },
|
|
27
|
+
Message: { typeOnly: false, privateImportPath: "./message.js", publicImportPath: packageName },
|
|
28
|
+
PartialMessage: { typeOnly: true, privateImportPath: "./message.js", publicImportPath: packageName },
|
|
29
|
+
PlainMessage: { typeOnly: true, privateImportPath: "./message.js", publicImportPath: packageName },
|
|
30
|
+
FieldList: { typeOnly: true, privateImportPath: "./field-list.js", publicImportPath: packageName },
|
|
31
|
+
MessageType: { typeOnly: true, privateImportPath: "./message-type.js", publicImportPath: packageName },
|
|
32
|
+
BinaryReadOptions: { typeOnly: true, privateImportPath: "./binary-format.js", publicImportPath: packageName },
|
|
33
|
+
BinaryWriteOptions: { typeOnly: true, privateImportPath: "./binary-format.js", publicImportPath: packageName },
|
|
34
|
+
JsonReadOptions: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
35
|
+
JsonWriteOptions: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
36
|
+
JsonValue: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
37
|
+
JsonObject: { typeOnly: true, privateImportPath: "./json-format.js", publicImportPath: packageName },
|
|
38
|
+
protoInt64: { typeOnly: false, privateImportPath: "./proto-int64.js", publicImportPath: packageName },
|
|
39
|
+
ScalarType: { typeOnly: false, privateImportPath: "./field.js", publicImportPath: packageName },
|
|
40
|
+
MethodKind: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
41
|
+
MethodIdempotency: { typeOnly: false, privateImportPath: "./service-type.js", publicImportPath: packageName },
|
|
42
|
+
},
|
|
43
|
+
wktSourceFiles: [
|
|
44
|
+
"google/protobuf/compiler/plugin.proto",
|
|
45
|
+
"google/protobuf/any.proto",
|
|
46
|
+
"google/protobuf/api.proto",
|
|
47
|
+
"google/protobuf/descriptor.proto",
|
|
48
|
+
"google/protobuf/duration.proto",
|
|
49
|
+
"google/protobuf/empty.proto",
|
|
50
|
+
"google/protobuf/field_mask.proto",
|
|
51
|
+
"google/protobuf/source_context.proto",
|
|
52
|
+
"google/protobuf/struct.proto",
|
|
53
|
+
"google/protobuf/timestamp.proto",
|
|
54
|
+
"google/protobuf/type.proto",
|
|
55
|
+
"google/protobuf/wrappers.proto",
|
|
56
|
+
],
|
|
57
|
+
};
|