@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,4 +1,17 @@
|
|
|
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.makeJsonFormatProto2 = void 0;
|
|
4
17
|
const field_wrapper_js_1 = require("./field-wrapper.js");
|
|
@@ -6,95 +19,84 @@ const assert_js_1 = require("./assert.js");
|
|
|
6
19
|
const json_format_common_js_1 = require("./json-format-common.js");
|
|
7
20
|
/* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
8
21
|
function makeJsonFormatProto2() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(0, assert_js_1.assert)(val !== undefined);
|
|
41
|
-
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
return options.emitDefaultValues || Object.keys(jsonObj).length > 0
|
|
46
|
-
? jsonObj
|
|
47
|
-
: undefined;
|
|
48
|
-
} else if (field.repeated) {
|
|
49
|
-
const jsonArr = [];
|
|
50
|
-
switch (field.kind) {
|
|
51
|
-
case "scalar":
|
|
52
|
-
for (let i = 0; i < value.length; i++) {
|
|
53
|
-
jsonArr.push(writeScalar(field.T, value[i], true));
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
case "enum":
|
|
57
|
-
for (let i = 0; i < value.length; i++) {
|
|
58
|
-
jsonArr.push(
|
|
59
|
-
writeEnum(field.T, value[i], true, options.enumAsInteger)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case "message":
|
|
64
|
-
for (let i = 0; i < value.length; i++) {
|
|
65
|
-
jsonArr.push(value[i].toJson(options));
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
return options.emitDefaultValues || jsonArr.length > 0
|
|
70
|
-
? jsonArr
|
|
71
|
-
: undefined;
|
|
72
|
-
} else {
|
|
73
|
-
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
74
|
-
// field is missing a value.
|
|
75
|
-
if (value === undefined) {
|
|
76
|
-
if (!field.oneof && !field.opt) {
|
|
77
|
-
throw `required field not set`;
|
|
22
|
+
return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
|
|
23
|
+
return function writeField(field, value, options) {
|
|
24
|
+
if (field.kind == "map") {
|
|
25
|
+
const jsonObj = {};
|
|
26
|
+
switch (field.V.kind) {
|
|
27
|
+
case "scalar":
|
|
28
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
29
|
+
const val = writeScalar(field.V.T, entryValue, true);
|
|
30
|
+
(0, assert_js_1.assert)(val !== undefined);
|
|
31
|
+
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "message":
|
|
35
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
36
|
+
// JSON standard allows only (double quoted) string as property key
|
|
37
|
+
jsonObj[entryKey.toString()] = entryValue.toJson(options);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case "enum":
|
|
41
|
+
const enumType = field.V.T;
|
|
42
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
43
|
+
(0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
|
|
44
|
+
const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
|
|
45
|
+
(0, assert_js_1.assert)(val !== undefined);
|
|
46
|
+
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return options.emitDefaultValues || Object.keys(jsonObj).length > 0
|
|
51
|
+
? jsonObj
|
|
52
|
+
: undefined;
|
|
78
53
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
54
|
+
else if (field.repeated) {
|
|
55
|
+
const jsonArr = [];
|
|
56
|
+
switch (field.kind) {
|
|
57
|
+
case "scalar":
|
|
58
|
+
for (let i = 0; i < value.length; i++) {
|
|
59
|
+
jsonArr.push(writeScalar(field.T, value[i], true));
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case "enum":
|
|
63
|
+
for (let i = 0; i < value.length; i++) {
|
|
64
|
+
jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case "message":
|
|
68
|
+
for (let i = 0; i < value.length; i++) {
|
|
69
|
+
jsonArr.push(value[i].toJson(options));
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return options.emitDefaultValues || jsonArr.length > 0
|
|
74
|
+
? jsonArr
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
79
|
+
// field is missing a value.
|
|
80
|
+
if (value === undefined) {
|
|
81
|
+
if (!field.oneof && !field.opt) {
|
|
82
|
+
throw `required field not set`;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
switch (field.kind) {
|
|
87
|
+
case "scalar":
|
|
88
|
+
// In contrast to proto3, we do not skip intrinsic default values.
|
|
89
|
+
// Explicit default values are not special cased either.
|
|
90
|
+
return writeScalar(field.T, value, true);
|
|
91
|
+
case "enum":
|
|
92
|
+
// In contrast to proto3, we do not skip intrinsic default values.
|
|
93
|
+
// Explicit default values are not special cased either.
|
|
94
|
+
return writeEnum(field.T, value, true, options.enumAsInteger);
|
|
95
|
+
case "message":
|
|
96
|
+
return (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
99
101
|
}
|
|
100
102
|
exports.makeJsonFormatProto2 = makeJsonFormatProto2;
|
|
@@ -1,4 +1,17 @@
|
|
|
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.makeJsonFormatProto3 = void 0;
|
|
4
17
|
const field_wrapper_js_1 = require("./field-wrapper.js");
|
|
@@ -6,98 +19,74 @@ const assert_js_1 = require("./assert.js");
|
|
|
6
19
|
const json_format_common_js_1 = require("./json-format-common.js");
|
|
7
20
|
/* eslint-disable no-case-declarations, @typescript-eslint/restrict-plus-operands,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
8
21
|
function makeJsonFormatProto3() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
case "scalar":
|
|
79
|
-
return writeScalar(
|
|
80
|
-
field.T,
|
|
81
|
-
value,
|
|
82
|
-
!!field.oneof || field.opt || options.emitDefaultValues
|
|
83
|
-
);
|
|
84
|
-
case "enum":
|
|
85
|
-
return writeEnum(
|
|
86
|
-
field.T,
|
|
87
|
-
value,
|
|
88
|
-
!!field.oneof || field.opt || options.emitDefaultValues,
|
|
89
|
-
options.enumAsInteger
|
|
90
|
-
);
|
|
91
|
-
case "message":
|
|
92
|
-
return value !== undefined
|
|
93
|
-
? (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(
|
|
94
|
-
options
|
|
95
|
-
)
|
|
96
|
-
: undefined;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
);
|
|
22
|
+
return (0, json_format_common_js_1.makeJsonFormatCommon)((writeEnum, writeScalar) => {
|
|
23
|
+
return function writeField(field, value, options) {
|
|
24
|
+
if (field.kind == "map") {
|
|
25
|
+
const jsonObj = {};
|
|
26
|
+
switch (field.V.kind) {
|
|
27
|
+
case "scalar":
|
|
28
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
29
|
+
const val = writeScalar(field.V.T, entryValue, true);
|
|
30
|
+
(0, assert_js_1.assert)(val !== undefined);
|
|
31
|
+
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "message":
|
|
35
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
36
|
+
// JSON standard allows only (double quoted) string as property key
|
|
37
|
+
jsonObj[entryKey.toString()] = entryValue.toJson(options);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
case "enum":
|
|
41
|
+
const enumType = field.V.T;
|
|
42
|
+
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
43
|
+
(0, assert_js_1.assert)(entryValue === undefined || typeof entryValue == "number");
|
|
44
|
+
const val = writeEnum(enumType, entryValue, true, options.enumAsInteger);
|
|
45
|
+
(0, assert_js_1.assert)(val !== undefined);
|
|
46
|
+
jsonObj[entryKey.toString()] = val; // JSON standard allows only (double quoted) string as property key
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
return options.emitDefaultValues || Object.keys(jsonObj).length > 0
|
|
51
|
+
? jsonObj
|
|
52
|
+
: undefined;
|
|
53
|
+
}
|
|
54
|
+
else if (field.repeated) {
|
|
55
|
+
const jsonArr = [];
|
|
56
|
+
switch (field.kind) {
|
|
57
|
+
case "scalar":
|
|
58
|
+
for (let i = 0; i < value.length; i++) {
|
|
59
|
+
jsonArr.push(writeScalar(field.T, value[i], true));
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case "enum":
|
|
63
|
+
for (let i = 0; i < value.length; i++) {
|
|
64
|
+
jsonArr.push(writeEnum(field.T, value[i], true, options.enumAsInteger));
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case "message":
|
|
68
|
+
for (let i = 0; i < value.length; i++) {
|
|
69
|
+
jsonArr.push((0, field_wrapper_js_1.wrapField)(field.T, value[i]).toJson(options));
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return options.emitDefaultValues || jsonArr.length > 0
|
|
74
|
+
? jsonArr
|
|
75
|
+
: undefined;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
switch (field.kind) {
|
|
79
|
+
case "scalar":
|
|
80
|
+
return writeScalar(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues);
|
|
81
|
+
case "enum":
|
|
82
|
+
return writeEnum(field.T, value, !!field.oneof || field.opt || options.emitDefaultValues, options.enumAsInteger);
|
|
83
|
+
case "message":
|
|
84
|
+
return value !== undefined
|
|
85
|
+
? (0, field_wrapper_js_1.wrapField)(field.T, value).toJson(options)
|
|
86
|
+
: undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
});
|
|
102
91
|
}
|
|
103
92
|
exports.makeJsonFormatProto3 = makeJsonFormatProto3;
|
|
@@ -1,4 +1,17 @@
|
|
|
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.makeMessageType = void 0;
|
|
4
17
|
const message_js_1 = require("../message.js");
|
|
@@ -6,32 +19,31 @@ const message_js_1 = require("../message.js");
|
|
|
6
19
|
* Create a new message type using the given runtime.
|
|
7
20
|
*/
|
|
8
21
|
function makeMessageType(runtime, typeName, fields, opt) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return type;
|
|
22
|
+
const localName = opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1);
|
|
23
|
+
const type = {
|
|
24
|
+
[localName]: function (data) {
|
|
25
|
+
runtime.util.initFields(this);
|
|
26
|
+
runtime.util.initPartial(data, this);
|
|
27
|
+
},
|
|
28
|
+
}[localName];
|
|
29
|
+
Object.setPrototypeOf(type.prototype, new message_js_1.Message());
|
|
30
|
+
Object.assign(type, {
|
|
31
|
+
runtime,
|
|
32
|
+
typeName,
|
|
33
|
+
fields: runtime.util.newFieldList(fields),
|
|
34
|
+
fromBinary(bytes, options) {
|
|
35
|
+
return new type().fromBinary(bytes, options);
|
|
36
|
+
},
|
|
37
|
+
fromJson(jsonValue, options) {
|
|
38
|
+
return new type().fromJson(jsonValue, options);
|
|
39
|
+
},
|
|
40
|
+
fromJsonString(jsonString, options) {
|
|
41
|
+
return new type().fromJsonString(jsonString, options);
|
|
42
|
+
},
|
|
43
|
+
equals(a, b) {
|
|
44
|
+
return runtime.util.equals(type, a, b);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return type;
|
|
36
48
|
}
|
|
37
49
|
exports.makeMessageType = makeMessageType;
|
|
@@ -1,79 +1,88 @@
|
|
|
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.makeMethodName =
|
|
4
|
-
exports.makeOneofName =
|
|
5
|
-
exports.makeFieldName =
|
|
6
|
-
exports.makeJsonName =
|
|
7
|
-
void 0;
|
|
16
|
+
exports.makeMethodName = exports.makeOneofName = exports.makeFieldName = exports.makeJsonName = void 0;
|
|
8
17
|
/**
|
|
9
18
|
* Returns the JSON name for a protobuf field, exactly like protoc does.
|
|
10
19
|
*/
|
|
11
20
|
function makeJsonName(protoName) {
|
|
12
|
-
|
|
21
|
+
return protoCamelCase(protoName);
|
|
13
22
|
}
|
|
14
23
|
exports.makeJsonName = makeJsonName;
|
|
15
24
|
/**
|
|
16
25
|
* Returns the local name of a field, exactly like protoc-gen-es does.
|
|
17
26
|
*/
|
|
18
27
|
function makeFieldName(protoName, inOneof) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const n = protoCamelCase(protoName);
|
|
29
|
+
if (inOneof) {
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
return rProp[n] ? n + escapeChar : n;
|
|
24
33
|
}
|
|
25
34
|
exports.makeFieldName = makeFieldName;
|
|
26
35
|
/**
|
|
27
36
|
* Returns the local name of a oneof group, exactly like protoc-gen-es does.
|
|
28
37
|
*/
|
|
29
38
|
function makeOneofName(protoName) {
|
|
30
|
-
|
|
39
|
+
return makeFieldName(protoName, false);
|
|
31
40
|
}
|
|
32
41
|
exports.makeOneofName = makeOneofName;
|
|
33
42
|
/**
|
|
34
43
|
* Returns the local name of a rpc, exactly like protoc-gen-es does.
|
|
35
44
|
*/
|
|
36
45
|
function makeMethodName(protoName) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
if (protoName.length == 0) {
|
|
47
|
+
return protoName;
|
|
48
|
+
}
|
|
49
|
+
return protoName[0].toLowerCase() + protoName.substring(1);
|
|
41
50
|
}
|
|
42
51
|
exports.makeMethodName = makeMethodName;
|
|
43
52
|
// Converts snake_case to protoCamelCase according to the convention
|
|
44
53
|
// used by protoc to convert a field name to a JSON name.
|
|
45
54
|
function protoCamelCase(snakeCase) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
let capNext = false;
|
|
56
|
+
const b = [];
|
|
57
|
+
for (let i = 0; i < snakeCase.length; i++) {
|
|
58
|
+
let c = snakeCase.charAt(i);
|
|
59
|
+
switch (c) {
|
|
60
|
+
case "_":
|
|
61
|
+
capNext = true;
|
|
62
|
+
break;
|
|
63
|
+
case "0":
|
|
64
|
+
case "1":
|
|
65
|
+
case "2":
|
|
66
|
+
case "3":
|
|
67
|
+
case "4":
|
|
68
|
+
case "5":
|
|
69
|
+
case "6":
|
|
70
|
+
case "7":
|
|
71
|
+
case "8":
|
|
72
|
+
case "9":
|
|
73
|
+
b.push(c);
|
|
74
|
+
capNext = false;
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
if (capNext) {
|
|
78
|
+
capNext = false;
|
|
79
|
+
c = c.toUpperCase();
|
|
80
|
+
}
|
|
81
|
+
b.push(c);
|
|
82
|
+
break;
|
|
71
83
|
}
|
|
72
|
-
b.push(c);
|
|
73
|
-
break;
|
|
74
84
|
}
|
|
75
|
-
|
|
76
|
-
return b.join("");
|
|
85
|
+
return b.join("");
|
|
77
86
|
}
|
|
78
87
|
// escapeChar must be appended to a reserved name.
|
|
79
88
|
// We choose '$' because it is invalid in proto identifiers.
|
|
@@ -81,21 +90,21 @@ const escapeChar = "$";
|
|
|
81
90
|
// Names that cannot be used for object properties.
|
|
82
91
|
// See buf_es/protoc-gen-es/internal/protoplugin/names.go
|
|
83
92
|
const rProp = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
// names reserved by JavaScript
|
|
94
|
+
constructor: true,
|
|
95
|
+
toString: true,
|
|
96
|
+
toJSON: true,
|
|
97
|
+
valueOf: true,
|
|
98
|
+
// names reserved by the runtime
|
|
99
|
+
getType: true,
|
|
100
|
+
clone: true,
|
|
101
|
+
equals: true,
|
|
102
|
+
fromBinary: true,
|
|
103
|
+
fromJson: true,
|
|
104
|
+
fromJsonString: true,
|
|
105
|
+
toBinary: true,
|
|
106
|
+
toJson: true,
|
|
107
|
+
toJsonString: true,
|
|
108
|
+
// names reserved by the runtime for the future
|
|
109
|
+
toObject: true,
|
|
101
110
|
};
|
|
@@ -1,2 +1,15 @@
|
|
|
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 });
|