Skip to content

Commit 225def5

Browse files
authored
V2: JSON Types (#866)
1 parent cf183a1 commit 225def5

38 files changed

+3910
-194
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2021-2024 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+
15+
syntax = "proto3";
16+
package spec;
17+
18+
import "google/protobuf/any.proto";
19+
import "google/protobuf/duration.proto";
20+
import "google/protobuf/empty.proto";
21+
import "google/protobuf/field_mask.proto";
22+
import "google/protobuf/struct.proto";
23+
import "google/protobuf/timestamp.proto";
24+
import "google/protobuf/wrappers.proto";
25+
26+
message JsonTypesMessage {
27+
bool bool_field = 1;
28+
double double_field = 2;
29+
bytes bytes_field = 3;
30+
int64 int64_field = 4;
31+
JsonTypeEnum enum_field = 5;
32+
JsonTypesMessage message_field = 6;
33+
google.protobuf.Any any_field = 7;
34+
google.protobuf.Duration duration_field = 8;
35+
google.protobuf.Empty empty_field = 9;
36+
google.protobuf.FieldMask field_mask_field = 10;
37+
google.protobuf.Struct struct_field = 11;
38+
google.protobuf.Value value_field = 12;
39+
google.protobuf.ListValue list_value_field = 13;
40+
google.protobuf.NullValue null_value_field = 14;
41+
google.protobuf.Timestamp timestamp_field = 15;
42+
google.protobuf.DoubleValue wrapped_double_field = 16;
43+
google.protobuf.FloatValue wrapped_float_field = 17;
44+
google.protobuf.Int64Value wrapped_int64_field = 18;
45+
google.protobuf.UInt64Value wrapped_uint64_field = 19;
46+
google.protobuf.Int32Value wrapped_int32_field = 20;
47+
google.protobuf.UInt32Value wrapped_uint32_field = 21;
48+
google.protobuf.BoolValue wrapped_bool_field = 22;
49+
google.protobuf.StringValue wrapped_string_field = 23;
50+
google.protobuf.BytesValue wrapped_bytes_field = 24;
51+
repeated JsonTypeEnum repeated_enum_field = 25;
52+
map<bool, JsonTypeEnum> map_bool_enum_field = 26;
53+
}
54+
55+
enum JsonTypeEnum {
56+
JSON_TYPE_ENUM_UNSPECIFIED = 0;
57+
JSON_TYPE_ENUM_YES = 1;
58+
JSON_TYPE_ENUM_NO = 2;
59+
}

packages/protobuf-test/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"build": "../../node_modules/typescript/bin/tsc --project tsconfig.json --outDir ./dist --declaration",
77
"postbuild": "cp src/perf-payload.* dist && cp -r src/gen/js* dist/gen",
88
"pregenerate": "rm -rf src/gen/*/*",
9-
"generate": "npm run generate:ts && npm run generate:js",
9+
"generate": "npm run generate:ts && npm run generate:js && npm run generate:ts,json_types && npm run generate:js,json_types",
1010
"generate:ts": "protoc --es_out=src/gen/ts --es_opt=ts_nocheck=false,target=ts,import_extension=.js --proto_path=. $(buf ls-files extra) --proto_path=$(upstream-include test) $(upstream-files test) google/protobuf/type.proto",
1111
"generate:js": "protoc --es_out=src/gen/js --es_opt=ts_nocheck=false,target=js+dts,import_extension=.js --proto_path=. $(buf ls-files extra) --proto_path=$(upstream-include test) $(upstream-files test) google/protobuf/type.proto",
12+
"generate:ts,json_types": "protoc --es_out=src/gen/ts,json_types --es_opt=ts_nocheck=false,target=ts,import_extension=.js,json_types=true --proto_path=. extra/json_types.proto",
13+
"generate:js,json_types": "protoc --es_out=src/gen/js,json_types --es_opt=ts_nocheck=false,target=js+dts,import_extension=.js,json_types=true --proto_path=. extra/json_types.proto",
1214
"postgenerate": "license-header src/gen",
1315
"perf": "tsx src/perf.ts benchmark '.*'",
1416
"profile": "dexnode dist/esm/perf.js run 'fromBinary perf-payload.bin' 10000",

0 commit comments

Comments
 (0)