@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2
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 +414 -409
- package/dist/cjs/binary-format.js +13 -0
- package/dist/cjs/descriptor-registry.js +420 -449
- package/dist/cjs/descriptor-set.js +429 -513
- package/dist/cjs/enum.js +13 -0
- package/dist/cjs/field-list.js +13 -0
- package/dist/cjs/field.js +43 -30
- package/dist/cjs/google/protobuf/any_pb.js +122 -140
- package/dist/cjs/google/protobuf/api_pb.js +177 -224
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
- package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
- package/dist/cjs/google/protobuf/duration_pb.js +72 -88
- package/dist/cjs/google/protobuf/empty_pb.js +17 -17
- package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
- package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
- package/dist/cjs/google/protobuf/struct_pb.js +144 -181
- package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
- package/dist/cjs/google/protobuf/type_pb.js +406 -462
- package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
- package/dist/cjs/google/varint.js +166 -171
- package/dist/cjs/index.js +41 -122
- package/dist/cjs/json-format.js +13 -0
- package/dist/cjs/message-type.js +13 -0
- package/dist/cjs/message.js +89 -85
- package/dist/cjs/private/assert.js +33 -26
- package/dist/cjs/private/base64.js +93 -79
- package/dist/cjs/private/binary-format-common.js +208 -208
- package/dist/cjs/private/binary-format-proto2.js +88 -109
- package/dist/cjs/private/binary-format-proto3.js +70 -90
- package/dist/cjs/private/enum.js +77 -44
- package/dist/cjs/private/field-list.js +64 -50
- package/dist/cjs/private/field-wrapper.js +21 -10
- package/dist/cjs/private/field.js +35 -25
- package/dist/cjs/private/json-format-common.js +427 -440
- package/dist/cjs/private/json-format-proto2.js +91 -89
- package/dist/cjs/private/json-format-proto3.js +82 -93
- package/dist/cjs/private/message-type.js +39 -27
- package/dist/cjs/private/names.js +71 -62
- package/dist/cjs/private/options-map.js +13 -0
- package/dist/cjs/private/proto-runtime.js +25 -16
- package/dist/cjs/private/scalars.js +113 -103
- package/dist/cjs/private/util-common.js +193 -210
- package/dist/cjs/private/util.js +13 -0
- package/dist/cjs/proto-int64.js +123 -111
- package/dist/cjs/proto2.js +63 -63
- package/dist/cjs/proto3.js +74 -74
- package/dist/cjs/service-type.js +27 -17
- package/dist/cjs/type-registry.js +46 -31
- package/dist/esm/binary-encoding.js +414 -414
- package/dist/esm/binary-format.js +13 -0
- package/dist/esm/descriptor-registry.js +422 -458
- package/dist/esm/descriptor-set.js +430 -478
- package/dist/esm/enum.js +13 -0
- package/dist/esm/field-list.js +13 -0
- package/dist/esm/field.js +42 -29
- package/dist/esm/google/protobuf/any_pb.js +122 -140
- package/dist/esm/google/protobuf/api_pb.js +177 -197
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
- package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
- package/dist/esm/google/protobuf/duration_pb.js +72 -88
- package/dist/esm/google/protobuf/empty_pb.js +17 -17
- package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
- package/dist/esm/google/protobuf/source_context_pb.js +25 -25
- package/dist/esm/google/protobuf/struct_pb.js +143 -180
- package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
- package/dist/esm/google/protobuf/type_pb.js +401 -421
- package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
- package/dist/esm/google/varint.js +165 -164
- package/dist/esm/index.js +14 -1
- package/dist/esm/json-format.js +13 -0
- package/dist/esm/message-type.js +13 -0
- package/dist/esm/message.js +89 -85
- package/dist/esm/private/assert.js +32 -21
- package/dist/esm/private/base64.js +92 -78
- package/dist/esm/private/binary-format-common.js +209 -207
- package/dist/esm/private/binary-format-proto2.js +89 -81
- package/dist/esm/private/binary-format-proto3.js +71 -67
- package/dist/esm/private/enum.js +75 -43
- package/dist/esm/private/field-list.js +64 -50
- package/dist/esm/private/field-wrapper.js +21 -10
- package/dist/esm/private/field.js +35 -22
- package/dist/esm/private/json-format-common.js +427 -435
- package/dist/esm/private/json-format-proto2.js +89 -81
- package/dist/esm/private/json-format-proto3.js +79 -80
- package/dist/esm/private/message-type.js +40 -28
- package/dist/esm/private/names.js +70 -57
- package/dist/esm/private/options-map.js +13 -0
- package/dist/esm/private/proto-runtime.js +26 -12
- package/dist/esm/private/scalars.js +112 -99
- package/dist/esm/private/util-common.js +193 -192
- package/dist/esm/private/util.js +13 -0
- package/dist/esm/proto-int64.js +123 -111
- package/dist/esm/proto2.js +63 -57
- package/dist/esm/proto3.js +74 -68
- package/dist/esm/service-type.js +25 -12
- package/dist/esm/type-registry.js +46 -31
- package/dist/types/binary-encoding.d.ts +398 -398
- package/dist/types/binary-format.d.ts +69 -91
- package/dist/types/descriptor-registry.d.ts +23 -29
- package/dist/types/descriptor-set.d.ts +107 -128
- package/dist/types/enum.d.ts +21 -21
- package/dist/types/field-list.d.ts +21 -21
- package/dist/types/field.d.ts +191 -231
- package/dist/types/google/protobuf/any_pb.d.ts +56 -77
- package/dist/types/google/protobuf/api_pb.d.ts +144 -187
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
- package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
- package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
- package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
- package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
- package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
- package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
- package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
- package/dist/types/google/protobuf/type_pb.d.ts +355 -422
- package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
- package/dist/types/google/varint.d.ts +6 -13
- package/dist/types/index.d.ts +4 -27
- package/dist/types/json-format.d.ts +70 -89
- package/dist/types/message-type.d.ts +37 -45
- package/dist/types/message.d.ts +62 -87
- package/dist/types/private/assert.d.ts +1 -4
- package/dist/types/private/binary-format-common.d.ts +6 -32
- package/dist/types/private/enum.d.ts +13 -11
- package/dist/types/private/field-list.d.ts +14 -21
- package/dist/types/private/field-wrapper.d.ts +4 -10
- package/dist/types/private/field.d.ts +12 -12
- package/dist/types/private/json-format-common.d.ts +5 -27
- package/dist/types/private/message-type.d.ts +12 -7
- package/dist/types/private/names.d.ts +1 -4
- package/dist/types/private/options-map.d.ts +1 -1
- package/dist/types/private/proto-runtime.d.ts +34 -42
- package/dist/types/private/scalars.d.ts +5 -12
- package/dist/types/private/util-common.d.ts +1 -4
- package/dist/types/private/util.d.ts +29 -41
- package/dist/types/proto-int64.d.ts +42 -42
- package/dist/types/service-type.d.ts +36 -56
- package/dist/types/type-registry.d.ts +13 -15
- package/package.json +2 -3
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.makeProtoRuntime = void 0;
|
|
4
17
|
const enum_js_1 = require("./enum.js");
|
|
5
18
|
const message_type_js_1 = require("./message-type.js");
|
|
6
19
|
function makeProtoRuntime(syntax, json, bin, util) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
makeEnumType: enum_js_1.makeEnumType,
|
|
21
|
-
getEnumType: enum_js_1.getEnumType,
|
|
22
|
-
};
|
|
20
|
+
return {
|
|
21
|
+
syntax,
|
|
22
|
+
json,
|
|
23
|
+
bin,
|
|
24
|
+
util,
|
|
25
|
+
makeMessageType(typeName, fields, opt) {
|
|
26
|
+
return (0, message_type_js_1.makeMessageType)(this, typeName, fields, opt);
|
|
27
|
+
},
|
|
28
|
+
makeEnum: enum_js_1.makeEnum,
|
|
29
|
+
makeEnumType: enum_js_1.makeEnumType,
|
|
30
|
+
getEnumType: enum_js_1.getEnumType,
|
|
31
|
+
};
|
|
23
32
|
}
|
|
24
33
|
exports.makeProtoRuntime = makeProtoRuntime;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
3
|
+
//
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// you may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
//
|
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scalarTypeInfo =
|
|
4
|
-
exports.scalarDefaultValue =
|
|
5
|
-
exports.scalarEquals =
|
|
6
|
-
void 0;
|
|
16
|
+
exports.scalarTypeInfo = exports.scalarDefaultValue = exports.scalarEquals = void 0;
|
|
7
17
|
const field_js_1 = require("../field.js");
|
|
8
18
|
const binary_encoding_js_1 = require("../binary-encoding.js");
|
|
9
19
|
const proto_int64_js_1 = require("../proto-int64.js");
|
|
@@ -12,39 +22,39 @@ const proto_int64_js_1 = require("../proto-int64.js");
|
|
|
12
22
|
* Returns true if both scalar values are equal.
|
|
13
23
|
*/
|
|
14
24
|
function scalarEquals(type, a, b) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
// Special case BYTES - we need to compare each byte individually
|
|
20
|
-
if (type == field_js_1.ScalarType.BYTES) {
|
|
21
|
-
if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
|
|
22
|
-
return false;
|
|
25
|
+
if (a === b) {
|
|
26
|
+
// This correctly matches equal values except BYTES and (possibly) 64-bit integers.
|
|
27
|
+
return true;
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
// Special case BYTES - we need to compare each byte individually
|
|
30
|
+
if (type == field_js_1.ScalarType.BYTES) {
|
|
31
|
+
if (!(a instanceof Uint8Array) || !(b instanceof Uint8Array)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (a.length !== b.length) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < a.length; i++) {
|
|
38
|
+
if (a[i] !== b[i]) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
26
43
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
// Special case 64-bit integers - we support number, string and bigint representation.
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
46
|
+
switch (type) {
|
|
47
|
+
case field_js_1.ScalarType.UINT64:
|
|
48
|
+
case field_js_1.ScalarType.FIXED64:
|
|
49
|
+
case field_js_1.ScalarType.INT64:
|
|
50
|
+
case field_js_1.ScalarType.SFIXED64:
|
|
51
|
+
case field_js_1.ScalarType.SINT64:
|
|
52
|
+
// Loose comparison will match between 0n, 0 and "0".
|
|
53
|
+
return a == b;
|
|
31
54
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
36
|
-
switch (type) {
|
|
37
|
-
case field_js_1.ScalarType.UINT64:
|
|
38
|
-
case field_js_1.ScalarType.FIXED64:
|
|
39
|
-
case field_js_1.ScalarType.INT64:
|
|
40
|
-
case field_js_1.ScalarType.SFIXED64:
|
|
41
|
-
case field_js_1.ScalarType.SINT64:
|
|
42
|
-
// Loose comparison will match between 0n, 0 and "0".
|
|
43
|
-
return a == b;
|
|
44
|
-
}
|
|
45
|
-
// Anything that hasn't been caught by strict comparison or special cased
|
|
46
|
-
// BYTES and 64-bit integers is not equal.
|
|
47
|
-
return false;
|
|
55
|
+
// Anything that hasn't been caught by strict comparison or special cased
|
|
56
|
+
// BYTES and 64-bit integers is not equal.
|
|
57
|
+
return false;
|
|
48
58
|
}
|
|
49
59
|
exports.scalarEquals = scalarEquals;
|
|
50
60
|
/**
|
|
@@ -52,27 +62,27 @@ exports.scalarEquals = scalarEquals;
|
|
|
52
62
|
* proto3 semantics.
|
|
53
63
|
*/
|
|
54
64
|
function scalarDefaultValue(type) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
switch (type) {
|
|
66
|
+
case field_js_1.ScalarType.BOOL:
|
|
67
|
+
return false;
|
|
68
|
+
case field_js_1.ScalarType.UINT64:
|
|
69
|
+
case field_js_1.ScalarType.FIXED64:
|
|
70
|
+
case field_js_1.ScalarType.INT64:
|
|
71
|
+
case field_js_1.ScalarType.SFIXED64:
|
|
72
|
+
case field_js_1.ScalarType.SINT64:
|
|
73
|
+
return proto_int64_js_1.protoInt64.zero;
|
|
74
|
+
case field_js_1.ScalarType.DOUBLE:
|
|
75
|
+
case field_js_1.ScalarType.FLOAT:
|
|
76
|
+
return 0.0;
|
|
77
|
+
case field_js_1.ScalarType.BYTES:
|
|
78
|
+
return new Uint8Array(0);
|
|
79
|
+
case field_js_1.ScalarType.STRING:
|
|
80
|
+
return "";
|
|
81
|
+
default:
|
|
82
|
+
// Handles INT32, UINT32, SINT32, FIXED32, SFIXED32.
|
|
83
|
+
// We do not use individual cases to save a few bytes code size.
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
exports.scalarDefaultValue = scalarDefaultValue;
|
|
78
88
|
/**
|
|
@@ -86,53 +96,53 @@ exports.scalarDefaultValue = scalarDefaultValue;
|
|
|
86
96
|
* If argument `value` is omitted, [2] is always false.
|
|
87
97
|
*/
|
|
88
98
|
function scalarTypeInfo(type, value) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
99
|
+
const isUndefined = value === undefined;
|
|
100
|
+
let wireType = binary_encoding_js_1.WireType.Varint;
|
|
101
|
+
let isIntrinsicDefault = value === 0;
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- INT32, UINT32, SINT32 are covered by the defaults
|
|
103
|
+
switch (type) {
|
|
104
|
+
case field_js_1.ScalarType.STRING:
|
|
105
|
+
isIntrinsicDefault = isUndefined || !value.length;
|
|
106
|
+
wireType = binary_encoding_js_1.WireType.LengthDelimited;
|
|
107
|
+
break;
|
|
108
|
+
case field_js_1.ScalarType.BOOL:
|
|
109
|
+
isIntrinsicDefault = value === false;
|
|
110
|
+
break;
|
|
111
|
+
case field_js_1.ScalarType.DOUBLE:
|
|
112
|
+
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
113
|
+
break;
|
|
114
|
+
case field_js_1.ScalarType.FLOAT:
|
|
115
|
+
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
116
|
+
break;
|
|
117
|
+
case field_js_1.ScalarType.INT64:
|
|
118
|
+
isIntrinsicDefault = isUndefined || value == 0;
|
|
119
|
+
break;
|
|
120
|
+
case field_js_1.ScalarType.UINT64:
|
|
121
|
+
isIntrinsicDefault = isUndefined || value == 0;
|
|
122
|
+
break;
|
|
123
|
+
case field_js_1.ScalarType.FIXED64:
|
|
124
|
+
isIntrinsicDefault = isUndefined || value == 0;
|
|
125
|
+
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
126
|
+
break;
|
|
127
|
+
case field_js_1.ScalarType.BYTES:
|
|
128
|
+
isIntrinsicDefault = isUndefined || !value.byteLength;
|
|
129
|
+
wireType = binary_encoding_js_1.WireType.LengthDelimited;
|
|
130
|
+
break;
|
|
131
|
+
case field_js_1.ScalarType.FIXED32:
|
|
132
|
+
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
133
|
+
break;
|
|
134
|
+
case field_js_1.ScalarType.SFIXED32:
|
|
135
|
+
wireType = binary_encoding_js_1.WireType.Bit32;
|
|
136
|
+
break;
|
|
137
|
+
case field_js_1.ScalarType.SFIXED64:
|
|
138
|
+
isIntrinsicDefault = isUndefined || value == 0;
|
|
139
|
+
wireType = binary_encoding_js_1.WireType.Bit64;
|
|
140
|
+
break;
|
|
141
|
+
case field_js_1.ScalarType.SINT64:
|
|
142
|
+
isIntrinsicDefault = isUndefined || value == 0;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
const method = field_js_1.ScalarType[type].toLowerCase();
|
|
146
|
+
return [wireType, method, isUndefined || isIntrinsicDefault];
|
|
137
147
|
}
|
|
138
148
|
exports.scalarTypeInfo = scalarTypeInfo;
|