Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: JSON Types #866

Merged
merged 17 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/protobuf-test/extra/json_types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2021-2024 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";
package spec;

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";

message JsonTypesMessage {
bool bool_field = 1;
double double_field = 2;
bytes bytes_field = 3;
int64 int64_field = 4;
JsonTypeEnum enum_field = 5;
JsonTypesMessage message_field = 6;
google.protobuf.Any any_field = 7;
google.protobuf.Duration duration_field = 8;
google.protobuf.Empty empty_field = 9;
google.protobuf.FieldMask field_mask_field = 10;
google.protobuf.Struct struct_field = 11;
google.protobuf.Value value_field = 12;
google.protobuf.ListValue list_value_field = 13;
google.protobuf.NullValue null_value_field = 14;
google.protobuf.Timestamp timestamp_field = 15;
google.protobuf.DoubleValue wrapped_double_field = 16;
google.protobuf.FloatValue wrapped_float_field = 17;
google.protobuf.Int64Value wrapped_int64_field = 18;
google.protobuf.UInt64Value wrapped_uint64_field = 19;
google.protobuf.Int32Value wrapped_int32_field = 20;
google.protobuf.UInt32Value wrapped_uint32_field = 21;
google.protobuf.BoolValue wrapped_bool_field = 22;
google.protobuf.StringValue wrapped_string_field = 23;
google.protobuf.BytesValue wrapped_bytes_field = 24;
repeated JsonTypeEnum repeated_enum_field = 25;
map<bool, JsonTypeEnum> map_bool_enum_field = 26;
}

enum JsonTypeEnum {
JSON_TYPE_ENUM_UNSPECIFIED = 0;
JSON_TYPE_ENUM_YES = 1;
JSON_TYPE_ENUM_NO = 2;
}
4 changes: 3 additions & 1 deletion packages/protobuf-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"build": "../../node_modules/typescript/bin/tsc --project tsconfig.json --outDir ./dist --declaration",
"postbuild": "cp src/perf-payload.* dist && cp -r src/gen/js* dist/gen",
"pregenerate": "rm -rf src/gen/*/*",
"generate": "npm run generate:ts && npm run generate:js",
"generate": "npm run generate:ts && npm run generate:js && npm run generate:ts,json_types && npm run generate:js,json_types",
"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",
"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",
"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",
"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",
"postgenerate": "license-header src/gen",
"perf": "tsx src/perf.ts benchmark '.*'",
"profile": "dexnode dist/esm/perf.js run 'fromBinary perf-payload.bin' 10000",
Expand Down
Loading