@bufbuild/protobuf 0.0.1 → 0.0.2-alpha.3
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 +1 -21
- package/dist/cjs/binary-encoding.js +21 -8
- package/dist/cjs/binary-format.js +13 -0
- package/dist/cjs/descriptor-registry.js +13 -0
- package/dist/cjs/descriptor-set.js +13 -0
- package/dist/cjs/enum.js +13 -0
- package/dist/cjs/field-list.js +13 -0
- package/dist/cjs/field.js +13 -0
- package/dist/cjs/google/protobuf/any_pb.js +13 -33
- package/dist/cjs/google/protobuf/api_pb.js +10 -30
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +10 -45
- package/dist/cjs/google/protobuf/descriptor_pb.js +13 -39
- package/dist/cjs/google/protobuf/duration_pb.js +10 -30
- package/dist/cjs/google/protobuf/empty_pb.js +10 -30
- package/dist/cjs/google/protobuf/field_mask_pb.js +10 -30
- package/dist/cjs/google/protobuf/source_context_pb.js +10 -30
- package/dist/cjs/google/protobuf/struct_pb.js +10 -30
- package/dist/cjs/google/protobuf/timestamp_pb.js +10 -30
- package/dist/cjs/google/protobuf/type_pb.js +10 -30
- package/dist/cjs/google/protobuf/wrappers_pb.js +10 -39
- package/dist/cjs/{private/goog-varint.js → google/varint.js} +0 -0
- package/dist/cjs/index.js +21 -2
- package/dist/cjs/json-format.js +13 -0
- package/dist/cjs/message-type.js +13 -0
- package/dist/cjs/message.js +18 -6
- package/dist/cjs/private/assert.js +13 -0
- package/dist/cjs/private/binary-format-common.js +13 -0
- package/dist/cjs/private/binary-format-proto2.js +13 -0
- package/dist/cjs/private/binary-format-proto3.js +13 -0
- package/dist/cjs/private/enum.js +39 -1
- package/dist/cjs/private/field-list.js +13 -0
- package/dist/cjs/private/field-wrapper.js +13 -0
- package/dist/cjs/private/field.js +13 -0
- package/dist/cjs/private/json-format-common.js +16 -3
- package/dist/cjs/private/json-format-proto2.js +13 -0
- package/dist/cjs/private/json-format-proto3.js +13 -0
- package/dist/cjs/private/message-type.js +13 -0
- package/dist/cjs/private/names.js +13 -0
- package/dist/cjs/private/options-map.js +13 -0
- package/dist/cjs/private/proto-runtime.js +14 -0
- package/dist/cjs/private/scalars.js +13 -0
- package/dist/cjs/private/util-common.js +16 -3
- package/dist/cjs/private/util.js +13 -0
- package/dist/cjs/proto-base64.js +138 -0
- package/dist/cjs/proto-int64.js +19 -6
- package/dist/cjs/proto2.js +13 -0
- package/dist/cjs/proto3.js +13 -0
- package/dist/cjs/service-type.js +13 -0
- package/dist/cjs/type-registry.js +13 -0
- package/dist/esm/binary-encoding.js +14 -1
- package/dist/esm/binary-format.js +13 -0
- package/dist/esm/descriptor-registry.js +13 -0
- package/dist/esm/descriptor-set.js +13 -0
- package/dist/esm/enum.js +13 -0
- package/dist/esm/field-list.js +13 -0
- package/dist/esm/field.js +13 -0
- package/dist/esm/google/protobuf/any_pb.js +13 -33
- package/dist/esm/google/protobuf/api_pb.js +10 -30
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +10 -45
- package/dist/esm/google/protobuf/descriptor_pb.js +13 -39
- package/dist/esm/google/protobuf/duration_pb.js +10 -30
- package/dist/esm/google/protobuf/empty_pb.js +10 -30
- package/dist/esm/google/protobuf/field_mask_pb.js +10 -30
- package/dist/esm/google/protobuf/source_context_pb.js +10 -30
- package/dist/esm/google/protobuf/struct_pb.js +10 -30
- package/dist/esm/google/protobuf/timestamp_pb.js +10 -30
- package/dist/esm/google/protobuf/type_pb.js +10 -30
- package/dist/esm/google/protobuf/wrappers_pb.js +10 -39
- package/dist/esm/{private/goog-varint.js → google/varint.js} +0 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/json-format.js +13 -0
- package/dist/esm/message-type.js +13 -0
- package/dist/esm/message.js +18 -6
- package/dist/esm/private/assert.js +13 -0
- package/dist/esm/private/binary-format-common.js +13 -0
- package/dist/esm/private/binary-format-proto2.js +13 -0
- package/dist/esm/private/binary-format-proto3.js +13 -0
- package/dist/esm/private/enum.js +37 -0
- package/dist/esm/private/field-list.js +13 -0
- package/dist/esm/private/field-wrapper.js +13 -0
- package/dist/esm/private/field.js +13 -0
- package/dist/esm/private/json-format-common.js +16 -3
- package/dist/esm/private/json-format-proto2.js +13 -0
- package/dist/esm/private/json-format-proto3.js +13 -0
- package/dist/esm/private/message-type.js +13 -0
- package/dist/esm/private/names.js +13 -0
- package/dist/esm/private/options-map.js +13 -0
- package/dist/esm/private/proto-runtime.js +15 -1
- package/dist/esm/private/scalars.js +13 -0
- package/dist/esm/private/util-common.js +16 -3
- package/dist/esm/private/util.js +13 -0
- package/dist/esm/proto-base64.js +135 -0
- package/dist/esm/proto-int64.js +14 -1
- package/dist/esm/proto2.js +13 -0
- package/dist/esm/proto3.js +13 -0
- package/dist/esm/service-type.js +13 -0
- package/dist/esm/type-registry.js +13 -0
- package/dist/types/google/protobuf/any_pb.d.ts +3 -3
- package/dist/types/google/protobuf/descriptor_pb.d.ts +16 -3
- package/dist/types/{private/goog-varint.d.ts → google/varint.d.ts} +0 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/json-format.d.ts +1 -1
- package/dist/types/message-type.d.ts +4 -3
- package/dist/types/message.d.ts +16 -15
- package/dist/types/private/enum.d.ts +9 -0
- package/dist/types/private/field-wrapper.d.ts +3 -3
- package/dist/types/private/message-type.d.ts +12 -2
- package/dist/types/private/proto-runtime.d.ts +18 -13
- package/dist/types/private/util.d.ts +4 -4
- package/dist/types/proto-base64.d.ts +26 -0
- package/dist/types/service-type.d.ts +7 -7
- package/package.json +3 -4
- package/dist/cjs/private/base64.js +0 -119
- package/dist/esm/private/base64.js +0 -114
- package/dist/types/private/base64.d.ts +0 -18
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
|
|
15
|
+
// lookup table from base64 character to byte
|
|
16
|
+
let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
17
|
+
// lookup table from base64 character *code* to byte because lookup by number is fast
|
|
18
|
+
let decTable = [];
|
|
19
|
+
for (let i = 0; i < encTable.length; i++)
|
|
20
|
+
decTable[encTable[i].charCodeAt(0)] = i;
|
|
21
|
+
// support base64url variants
|
|
22
|
+
decTable["-".charCodeAt(0)] = encTable.indexOf("+");
|
|
23
|
+
decTable["_".charCodeAt(0)] = encTable.indexOf("/");
|
|
24
|
+
export const protoBase64 = {
|
|
25
|
+
/**
|
|
26
|
+
* Decodes a base64 string to a byte array.
|
|
27
|
+
*
|
|
28
|
+
* - ignores white-space, including line breaks and tabs
|
|
29
|
+
* - allows inner padding (can decode concatenated base64 strings)
|
|
30
|
+
* - does not require padding
|
|
31
|
+
* - understands base64url encoding:
|
|
32
|
+
* "-" instead of "+",
|
|
33
|
+
* "_" instead of "/",
|
|
34
|
+
* no padding
|
|
35
|
+
*/
|
|
36
|
+
dec(base64Str) {
|
|
37
|
+
// estimate byte size, not accounting for inner padding and whitespace
|
|
38
|
+
let es = (base64Str.length * 3) / 4;
|
|
39
|
+
// if (es % 3 !== 0)
|
|
40
|
+
// throw new Error("invalid base64 string");
|
|
41
|
+
if (base64Str[base64Str.length - 2] == "=")
|
|
42
|
+
es -= 2;
|
|
43
|
+
else if (base64Str[base64Str.length - 1] == "=")
|
|
44
|
+
es -= 1;
|
|
45
|
+
let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
|
|
46
|
+
groupPos = 0, // position in base64 group
|
|
47
|
+
b, // current byte
|
|
48
|
+
p = 0; // previous byte
|
|
49
|
+
for (let i = 0; i < base64Str.length; i++) {
|
|
50
|
+
b = decTable[base64Str.charCodeAt(i)];
|
|
51
|
+
if (b === undefined) {
|
|
52
|
+
switch (base64Str[i]) {
|
|
53
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
54
|
+
case "=":
|
|
55
|
+
groupPos = 0; // reset state when padding found
|
|
56
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
57
|
+
case "\n":
|
|
58
|
+
case "\r":
|
|
59
|
+
case "\t":
|
|
60
|
+
case " ":
|
|
61
|
+
continue; // skip white-space, and padding
|
|
62
|
+
default:
|
|
63
|
+
throw Error("invalid base64 string.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
switch (groupPos) {
|
|
67
|
+
case 0:
|
|
68
|
+
p = b;
|
|
69
|
+
groupPos = 1;
|
|
70
|
+
break;
|
|
71
|
+
case 1:
|
|
72
|
+
bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
|
|
73
|
+
p = b;
|
|
74
|
+
groupPos = 2;
|
|
75
|
+
break;
|
|
76
|
+
case 2:
|
|
77
|
+
bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
|
|
78
|
+
p = b;
|
|
79
|
+
groupPos = 3;
|
|
80
|
+
break;
|
|
81
|
+
case 3:
|
|
82
|
+
bytes[bytePos++] = ((p & 3) << 6) | b;
|
|
83
|
+
groupPos = 0;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (groupPos == 1)
|
|
88
|
+
throw Error("invalid base64 string.");
|
|
89
|
+
return bytes.subarray(0, bytePos);
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Decodes a base64 string to a byte array.
|
|
93
|
+
*
|
|
94
|
+
* - ignores white-space, including line breaks and tabs
|
|
95
|
+
* - allows inner padding (can decode concatenated base64 strings)
|
|
96
|
+
* - does not require padding
|
|
97
|
+
* - understands base64url encoding:
|
|
98
|
+
* "-" instead of "+",
|
|
99
|
+
* "_" instead of "/",
|
|
100
|
+
* no padding
|
|
101
|
+
*/
|
|
102
|
+
enc(bytes) {
|
|
103
|
+
let base64 = "", groupPos = 0, // position in base64 group
|
|
104
|
+
b, // current byte
|
|
105
|
+
p = 0; // carry over from previous byte
|
|
106
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
107
|
+
b = bytes[i];
|
|
108
|
+
switch (groupPos) {
|
|
109
|
+
case 0:
|
|
110
|
+
base64 += encTable[b >> 2];
|
|
111
|
+
p = (b & 3) << 4;
|
|
112
|
+
groupPos = 1;
|
|
113
|
+
break;
|
|
114
|
+
case 1:
|
|
115
|
+
base64 += encTable[p | (b >> 4)];
|
|
116
|
+
p = (b & 15) << 2;
|
|
117
|
+
groupPos = 2;
|
|
118
|
+
break;
|
|
119
|
+
case 2:
|
|
120
|
+
base64 += encTable[p | (b >> 6)];
|
|
121
|
+
base64 += encTable[b & 63];
|
|
122
|
+
groupPos = 0;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// padding required?
|
|
127
|
+
if (groupPos) {
|
|
128
|
+
base64 += encTable[p];
|
|
129
|
+
base64 += "=";
|
|
130
|
+
if (groupPos == 1)
|
|
131
|
+
base64 += "=";
|
|
132
|
+
}
|
|
133
|
+
return base64;
|
|
134
|
+
},
|
|
135
|
+
};
|
package/dist/esm/proto-int64.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
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 { int64fromString, int64toString } from "./google/varint.js";
|
|
2
15
|
function makeInt64Support() {
|
|
3
16
|
const dv = new DataView(new ArrayBuffer(8));
|
|
4
17
|
// note that Safari 14 implements BigInt, but not the DataView methods
|
package/dist/esm/proto2.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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.
|
|
1
14
|
import { makeProtoRuntime } from "./private/proto-runtime.js";
|
|
2
15
|
import { makeBinaryFormatProto2 } from "./private/binary-format-proto2.js";
|
|
3
16
|
import { makeUtilCommon } from "./private/util-common.js";
|
package/dist/esm/proto3.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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.
|
|
1
14
|
import { makeProtoRuntime } from "./private/proto-runtime.js";
|
|
2
15
|
import { makeBinaryFormatProto3 } from "./private/binary-format-proto3.js";
|
|
3
16
|
import { makeJsonFormatProto3 } from "./private/json-format-proto3.js";
|
package/dist/esm/service-type.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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.
|
|
1
14
|
/**
|
|
2
15
|
* MethodKind represents the four method types that can be declared in
|
|
3
16
|
* protobuf with the `stream` keyword:
|
|
@@ -1,3 +1,16 @@
|
|
|
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.
|
|
1
14
|
/**
|
|
2
15
|
* TypeRegistry is a basic type registry
|
|
3
16
|
*/
|
|
@@ -26,7 +26,7 @@ import { Message } from "../../index.js";
|
|
|
26
26
|
* foo = any.unpack(Foo.class);
|
|
27
27
|
* }
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* Example 3: Pack and unpack a message in Python.
|
|
30
30
|
*
|
|
31
31
|
* foo = Foo(...)
|
|
32
32
|
* any = Any()
|
|
@@ -36,7 +36,7 @@ import { Message } from "../../index.js";
|
|
|
36
36
|
* any.Unpack(foo)
|
|
37
37
|
* ...
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* Example 4: Pack and unpack a message in Go
|
|
40
40
|
*
|
|
41
41
|
* foo := &pb.Foo{...}
|
|
42
42
|
* any, err := anypb.New(foo)
|
|
@@ -57,7 +57,7 @@ import { Message } from "../../index.js";
|
|
|
57
57
|
*
|
|
58
58
|
*
|
|
59
59
|
* JSON
|
|
60
|
-
*
|
|
60
|
+
*
|
|
61
61
|
* The JSON representation of an `Any` value uses the regular
|
|
62
62
|
* representation of the deserialized, embedded message, with an
|
|
63
63
|
* additional field `@type` which contains the type URL. Example:
|
|
@@ -286,7 +286,6 @@ export declare class FieldDescriptorProto extends Message<FieldDescriptorProto>
|
|
|
286
286
|
* For booleans, "true" or "false".
|
|
287
287
|
* For strings, contains the default text contents (not escaped in any way).
|
|
288
288
|
* For bytes, contains the C escaped value. All bytes >= 128 are escaped.
|
|
289
|
-
* TODO(kenton): Base-64 encode?
|
|
290
289
|
*
|
|
291
290
|
* @generated from field: optional string default_value = 7;
|
|
292
291
|
*/
|
|
@@ -1020,9 +1019,23 @@ export declare class FieldOptions extends Message<FieldOptions> {
|
|
|
1020
1019
|
* check its required fields, regardless of whether or not the message has
|
|
1021
1020
|
* been parsed.
|
|
1022
1021
|
*
|
|
1022
|
+
* As of 2021, lazy does no correctness checks on the byte stream during
|
|
1023
|
+
* parsing. This may lead to crashes if and when an invalid byte stream is
|
|
1024
|
+
* finally parsed upon access.
|
|
1025
|
+
*
|
|
1026
|
+
* TODO(b/211906113): Enable validation on lazy fields.
|
|
1027
|
+
*
|
|
1023
1028
|
* @generated from field: optional bool lazy = 5 [default = false];
|
|
1024
1029
|
*/
|
|
1025
1030
|
lazy?: boolean;
|
|
1031
|
+
/**
|
|
1032
|
+
* unverified_lazy does no correctness checks on the byte stream. This should
|
|
1033
|
+
* only be used where lazy with verification is prohibitive for performance
|
|
1034
|
+
* reasons.
|
|
1035
|
+
*
|
|
1036
|
+
* @generated from field: optional bool unverified_lazy = 15 [default = false];
|
|
1037
|
+
*/
|
|
1038
|
+
unverifiedLazy?: boolean;
|
|
1026
1039
|
/**
|
|
1027
1040
|
* Is this field deprecated?
|
|
1028
1041
|
* Depending on the target platform, this can emit Deprecated annotations
|
|
@@ -1413,8 +1426,8 @@ export declare class SourceCodeInfo_Location extends Message<SourceCodeInfo_Loca
|
|
|
1413
1426
|
* location.
|
|
1414
1427
|
*
|
|
1415
1428
|
* Each element is a field number or an index. They form a path from
|
|
1416
|
-
* the root FileDescriptorProto to the place where the definition.
|
|
1417
|
-
* example, this path:
|
|
1429
|
+
* the root FileDescriptorProto to the place where the definition occurs.
|
|
1430
|
+
* For example, this path:
|
|
1418
1431
|
* [ 4, 3, 2, 7, 1 ]
|
|
1419
1432
|
* refers to:
|
|
1420
1433
|
* file.message_type(3) // 4, 3
|
|
File without changes
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { proto3 } from "./proto3.js";
|
|
2
2
|
export { proto2 } from "./proto2.js";
|
|
3
3
|
export { protoInt64 } from "./proto-int64.js";
|
|
4
|
-
export {
|
|
4
|
+
export { protoBase64 } from "./proto-base64.js";
|
|
5
|
+
export { Message, AnyMessage, PartialMessage, PlainMessage, } from "./message.js";
|
|
5
6
|
export type { FieldInfo } from "./field.js";
|
|
6
7
|
export type { FieldList } from "./field-list.js";
|
|
7
8
|
export { ScalarType } from "./field.js";
|
|
@@ -19,7 +19,7 @@ export interface JsonFormat {
|
|
|
19
19
|
/**
|
|
20
20
|
* Parse a message from JSON.
|
|
21
21
|
*/
|
|
22
|
-
readMessage<T extends Message
|
|
22
|
+
readMessage<T extends Message<T>>(type: MessageType<T>, jsonValue: JsonValue, options: JsonReadOptions, message?: T): T;
|
|
23
23
|
/**
|
|
24
24
|
* Serialize a message to JSON.
|
|
25
25
|
*/
|
|
@@ -2,7 +2,7 @@ import type { FieldList } from "./field-list.js";
|
|
|
2
2
|
import type { ProtoRuntime } from "./private/proto-runtime.js";
|
|
3
3
|
import type { JsonReadOptions, JsonValue } from "./json-format.js";
|
|
4
4
|
import type { BinaryReadOptions } from "./binary-format.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { AnyMessage, Message, PartialMessage, PlainMessage } from "./message.js";
|
|
6
6
|
import type { FieldWrapper } from "./private/field-wrapper.js";
|
|
7
7
|
/**
|
|
8
8
|
* MessageType represents a protobuf message. It provides:
|
|
@@ -10,7 +10,7 @@ import type { FieldWrapper } from "./private/field-wrapper.js";
|
|
|
10
10
|
* - metadata for reflection-based operations
|
|
11
11
|
* - common functionality like serialization
|
|
12
12
|
*/
|
|
13
|
-
export interface MessageType<T extends Message =
|
|
13
|
+
export interface MessageType<T extends Message<T> = AnyMessage> {
|
|
14
14
|
/**
|
|
15
15
|
* Create a new instance of this type.
|
|
16
16
|
*/
|
|
@@ -45,6 +45,7 @@ export interface MessageType<T extends Message = DynamicMessage> {
|
|
|
45
45
|
fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): T;
|
|
46
46
|
/**
|
|
47
47
|
* Returns true if the given arguments have equal field values, recursively.
|
|
48
|
+
* Will also return true if both messages are `undefined` or `null`.
|
|
48
49
|
*/
|
|
49
|
-
equals(a: T | PlainMessage<T> | undefined, b: T | PlainMessage<T> | undefined): boolean;
|
|
50
|
+
equals(a: T | PlainMessage<T> | undefined | null, b: T | PlainMessage<T> | undefined | null): boolean;
|
|
50
51
|
}
|
package/dist/types/message.d.ts
CHANGED
|
@@ -2,17 +2,25 @@ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
|
|
|
2
2
|
import type { JsonReadOptions, JsonValue, JsonWriteOptions, JsonWriteStringOptions } from "./json-format.js";
|
|
3
3
|
import type { MessageType } from "./message-type.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* AnyMessage is an interface implemented by all messages. If you need to
|
|
6
|
+
* handle messages of unknown type, this interface provides a convenient
|
|
7
|
+
* index signature to access fields with message["fieldname"].
|
|
8
|
+
*/
|
|
9
|
+
export interface AnyMessage extends Message<AnyMessage> {
|
|
10
|
+
[k: string]: any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Message is the base class of every message, generated, or created at
|
|
14
|
+
* runtime.
|
|
7
15
|
*
|
|
8
|
-
* It is
|
|
9
|
-
* time, use proto3.makeMessageType().
|
|
16
|
+
* It is _not_ safe to extend this class. If you want to create a message at
|
|
17
|
+
* run time, use proto3.makeMessageType().
|
|
10
18
|
*/
|
|
11
|
-
export declare class Message<T extends Message =
|
|
19
|
+
export declare class Message<T extends Message<T> = AnyMessage> {
|
|
12
20
|
/**
|
|
13
21
|
* Compare with a message of the same type.
|
|
14
22
|
*/
|
|
15
|
-
equals(other: T | PlainMessage<T> | undefined): boolean;
|
|
23
|
+
equals(other: T | PlainMessage<T> | undefined | null): boolean;
|
|
16
24
|
/**
|
|
17
25
|
* Create a deep copy.
|
|
18
26
|
*/
|
|
@@ -73,13 +81,13 @@ export declare type PlainMessage<T extends Message> = {
|
|
|
73
81
|
export declare type PartialMessage<T extends Message> = {
|
|
74
82
|
[P in keyof T as T[P] extends Function ? never : P]?: PartialField<T[P]>;
|
|
75
83
|
};
|
|
76
|
-
declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends OneofSelectedMessage<infer C, infer V> ? {
|
|
84
|
+
declare type PartialField<F> = F extends (Date | Uint8Array | bigint | boolean | string | number) ? F : F extends Array<infer U> ? Array<PartialField<U>> : F extends ReadonlyArray<infer U> ? ReadonlyArray<PartialField<U>> : F extends Message ? PartialMessage<F> : F extends OneofSelectedMessage<infer C, infer V> ? {
|
|
77
85
|
case: C;
|
|
78
86
|
value: PartialMessage<V>;
|
|
79
87
|
} : F extends {
|
|
80
88
|
case: string | undefined;
|
|
81
89
|
value?: unknown;
|
|
82
|
-
} ? F : F extends
|
|
90
|
+
} ? F : F extends {
|
|
83
91
|
[key: string | number]: Message<infer U>;
|
|
84
92
|
} ? {
|
|
85
93
|
[key: string | number]: PartialMessage<U>;
|
|
@@ -88,11 +96,4 @@ declare type OneofSelectedMessage<K extends string, M extends Message> = {
|
|
|
88
96
|
case: K;
|
|
89
97
|
value: M;
|
|
90
98
|
};
|
|
91
|
-
/**
|
|
92
|
-
* DynamicMessage exposes the fields of the message with an index signature,
|
|
93
|
-
* which means that fields can be accessed with message["fieldname"].
|
|
94
|
-
*/
|
|
95
|
-
export declare type DynamicMessage = Message & {
|
|
96
|
-
[k: string]: any;
|
|
97
|
-
};
|
|
98
99
|
export {};
|
|
@@ -20,3 +20,12 @@ export declare function setEnumType(enumObject: EnumObject, typeName: string, va
|
|
|
20
20
|
* Create a new EnumType with the given values.
|
|
21
21
|
*/
|
|
22
22
|
export declare function makeEnumType(typeName: string, values: EnumValueInfo[]): EnumType;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new enum object with the given values.
|
|
25
|
+
*/
|
|
26
|
+
export declare function makeEnum(typeName: string, values: EnumValueInfo[], opt?: {
|
|
27
|
+
/**
|
|
28
|
+
* MY_ENUM_ for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`, or blank string
|
|
29
|
+
*/
|
|
30
|
+
sharedPrefix?: string;
|
|
31
|
+
}): EnumObject;
|
|
@@ -7,15 +7,15 @@ import type { MessageType } from "../message-type.js";
|
|
|
7
7
|
* Note that this feature exists for google/protobuf/{wrappers,struct}.proto
|
|
8
8
|
* and cannot be used to arbitrarily modify types in generated code.
|
|
9
9
|
*/
|
|
10
|
-
export interface FieldWrapper<T extends Message = any, U = any> {
|
|
10
|
+
export interface FieldWrapper<T extends Message<T> = any, U = any> {
|
|
11
11
|
wrapField(value: U): T;
|
|
12
12
|
unwrapField(value: T): U;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Wrap field values whose message type has a wrapper.
|
|
16
16
|
*/
|
|
17
|
-
export declare function wrapField<T extends Message
|
|
17
|
+
export declare function wrapField<T extends Message<T>>(type: MessageType<T>, value: any): T;
|
|
18
18
|
/**
|
|
19
19
|
* Unwrap field values whose message type has a wrapper.
|
|
20
20
|
*/
|
|
21
|
-
export declare function unwrapField<T extends Message
|
|
21
|
+
export declare function unwrapField<T extends Message<T>>(type: MessageType<T>, value: T): any;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyMessage, Message } from "../message.js";
|
|
2
2
|
import type { FieldListSource } from "./field-list.js";
|
|
3
3
|
import type { MessageType } from "../message-type.js";
|
|
4
4
|
import type { ProtoRuntime } from "./proto-runtime.js";
|
|
5
5
|
/**
|
|
6
6
|
* Create a new message type using the given runtime.
|
|
7
7
|
*/
|
|
8
|
-
export declare function makeMessageType<T extends Message =
|
|
8
|
+
export declare function makeMessageType<T extends Message<T> = AnyMessage>(runtime: ProtoRuntime, typeName: string, fields: FieldListSource, opt?: {
|
|
9
|
+
/**
|
|
10
|
+
* localName is the "name" property of the constructed function.
|
|
11
|
+
* It is useful in stack traces, debuggers and test frameworks,
|
|
12
|
+
* but has no other implications.
|
|
13
|
+
*
|
|
14
|
+
* This property is optional because by default, the last part
|
|
15
|
+
* from the given typeName is used. Since this does not take
|
|
16
|
+
* reserved words into account, we provide this property so that
|
|
17
|
+
* an escaped name can be given.
|
|
18
|
+
*/
|
|
9
19
|
localName?: string;
|
|
10
20
|
}): MessageType<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { JsonFormat
|
|
1
|
+
import type { JsonFormat } from "../json-format.js";
|
|
2
2
|
import type { BinaryFormat } from "../binary-format.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AnyMessage } from "../message.js";
|
|
4
4
|
import type { Message } from "../message.js";
|
|
5
5
|
import type { EnumType, EnumValueInfo } from "../enum.js";
|
|
6
6
|
import type { MessageType } from "../message-type.js";
|
|
@@ -18,24 +18,29 @@ export interface ProtoRuntime {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a message type at runtime, without generating code.
|
|
20
20
|
*/
|
|
21
|
-
makeMessageType<T extends Message =
|
|
21
|
+
makeMessageType<T extends Message<T> = AnyMessage>(typeName: string, fields: FieldListSource, opt?: {
|
|
22
22
|
localName?: string;
|
|
23
|
-
options?: {
|
|
24
|
-
readonly [extensionName: string]: JsonValue;
|
|
25
|
-
};
|
|
26
23
|
}): MessageType<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Create an enum object at runtime, without generating code.
|
|
26
|
+
*
|
|
27
|
+
* The object conforms to TypeScript enums, and comes with
|
|
28
|
+
* mapping from name to value, and from value to name.
|
|
29
|
+
*
|
|
30
|
+
* The type name and other reflection information is accessible
|
|
31
|
+
* via getEnumType().
|
|
32
|
+
*/
|
|
33
|
+
makeEnum(typeName: string, values: EnumValueInfo[], opt?: {}): EnumObject;
|
|
27
34
|
/**
|
|
28
35
|
* Create an enum type at runtime, without generating code.
|
|
36
|
+
* Note that this only creates the reflection information, not an
|
|
37
|
+
* actual enum object.
|
|
29
38
|
*/
|
|
30
|
-
makeEnumType(typeName: string, values: EnumValueInfo[], opt?: {
|
|
31
|
-
options?: {
|
|
32
|
-
readonly [extensionName: string]: JsonValue;
|
|
33
|
-
};
|
|
34
|
-
}): EnumType;
|
|
39
|
+
makeEnumType(typeName: string, values: EnumValueInfo[], opt?: {}): EnumType;
|
|
35
40
|
/**
|
|
36
|
-
* Get reflection information from
|
|
41
|
+
* Get reflection information - the EnumType - from an enum object.
|
|
37
42
|
* If this function is called on something other than a generated
|
|
38
|
-
* enum, it raises an error.
|
|
43
|
+
* enum, or an enum constructed with makeEnum(), it raises an error.
|
|
39
44
|
*/
|
|
40
45
|
getEnumType(enumObject: EnumObject): EnumType;
|
|
41
46
|
}
|
|
@@ -30,14 +30,14 @@ export interface Util {
|
|
|
30
30
|
/**
|
|
31
31
|
* Set specified field values on the target message, recursively.
|
|
32
32
|
*/
|
|
33
|
-
initPartial<T extends Message
|
|
33
|
+
initPartial<T extends Message<T>>(source: PartialMessage<T> | undefined, target: T): void;
|
|
34
34
|
/**
|
|
35
35
|
* Compares two messages of the same type recursively.
|
|
36
|
-
* Will also return true if both messages are `undefined`.
|
|
36
|
+
* Will also return true if both messages are `undefined` or `null`.
|
|
37
37
|
*/
|
|
38
|
-
equals<T extends Message
|
|
38
|
+
equals<T extends Message<T>>(type: MessageType, a: T | PlainMessage<T> | undefined | null, b: T | PlainMessage<T> | undefined | null): boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Create a deep copy.
|
|
41
41
|
*/
|
|
42
|
-
clone<T extends Message
|
|
42
|
+
clone<T extends Message<T>>(message: T): T;
|
|
43
43
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const protoBase64: {
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a base64 string to a byte array.
|
|
4
|
+
*
|
|
5
|
+
* - ignores white-space, including line breaks and tabs
|
|
6
|
+
* - allows inner padding (can decode concatenated base64 strings)
|
|
7
|
+
* - does not require padding
|
|
8
|
+
* - understands base64url encoding:
|
|
9
|
+
* "-" instead of "+",
|
|
10
|
+
* "_" instead of "/",
|
|
11
|
+
* no padding
|
|
12
|
+
*/
|
|
13
|
+
readonly dec: (base64Str: string) => Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Decodes a base64 string to a byte array.
|
|
16
|
+
*
|
|
17
|
+
* - ignores white-space, including line breaks and tabs
|
|
18
|
+
* - allows inner padding (can decode concatenated base64 strings)
|
|
19
|
+
* - does not require padding
|
|
20
|
+
* - understands base64url encoding:
|
|
21
|
+
* "-" instead of "+",
|
|
22
|
+
* "_" instead of "/",
|
|
23
|
+
* no padding
|
|
24
|
+
*/
|
|
25
|
+
readonly enc: (bytes: Uint8Array) => string;
|
|
26
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyMessage, Message } from "./message.js";
|
|
2
2
|
import type { MessageType } from "./message-type.js";
|
|
3
3
|
/**
|
|
4
4
|
* ServiceType represents a protobuf services. It provides metadata for
|
|
@@ -29,32 +29,32 @@ export interface ServiceType {
|
|
|
29
29
|
* - "idempotency": User-provided indication whether the method will cause
|
|
30
30
|
* the same effect every time it is called.
|
|
31
31
|
*/
|
|
32
|
-
export declare type MethodInfo<I extends Message =
|
|
32
|
+
export declare type MethodInfo<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage> = MethodInfoUnary<I, O> | MethodInfoServerStreaming<I, O> | MethodInfoClientStreaming<I, O> | MethodInfoBiDiStreaming<I, O>;
|
|
33
33
|
/**
|
|
34
34
|
* A unary method: rpc (Input) returns (Output)
|
|
35
35
|
*/
|
|
36
|
-
export interface MethodInfoUnary<I extends Message
|
|
36
|
+
export interface MethodInfoUnary<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
|
|
37
37
|
readonly kind: MethodKind.Unary;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* A server streaming method: rpc (Input) returns (stream Output)
|
|
41
41
|
*/
|
|
42
|
-
export interface MethodInfoServerStreaming<I extends Message
|
|
42
|
+
export interface MethodInfoServerStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
|
|
43
43
|
readonly kind: MethodKind.ServerStreaming;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* A client streaming method: rpc (stream Input) returns (Output)
|
|
47
47
|
*/
|
|
48
|
-
export interface MethodInfoClientStreaming<I extends Message
|
|
48
|
+
export interface MethodInfoClientStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
|
|
49
49
|
readonly kind: MethodKind.ClientStreaming;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* A method that streams bi-directionally: rpc (stream Input) returns (stream Output)
|
|
53
53
|
*/
|
|
54
|
-
export interface MethodInfoBiDiStreaming<I extends Message
|
|
54
|
+
export interface MethodInfoBiDiStreaming<I extends Message<I>, O extends Message<O>> extends miShared<I, O> {
|
|
55
55
|
readonly kind: MethodKind.BiDiStreaming;
|
|
56
56
|
}
|
|
57
|
-
interface miShared<I extends Message =
|
|
57
|
+
interface miShared<I extends Message<I> = AnyMessage, O extends Message<O> = AnyMessage> {
|
|
58
58
|
readonly name: string;
|
|
59
59
|
readonly I: MessageType<I>;
|
|
60
60
|
readonly O: MessageType<O>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha.3",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "A complete implementation of protocol buffers in TypeScript, suitable for web browsers and Node.js.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/bufbuild/
|
|
8
|
+
"url": "https://github.com/bufbuild/protobuf-es.git",
|
|
9
9
|
"directory": "packages/protobuf"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
-
"main": "./dist/cjs/index.js",
|
|
19
18
|
"types": "./dist/types/index.d.ts",
|
|
20
19
|
"exports": {
|
|
21
20
|
"import": "./dist/esm/index.js",
|
|
@@ -23,7 +22,7 @@
|
|
|
23
22
|
"default": "./dist/esm/index.js"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"typescript": "^4.
|
|
25
|
+
"typescript": "^4.6.3"
|
|
27
26
|
},
|
|
28
27
|
"files": [
|
|
29
28
|
"dist/**/"
|