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

feat: impl schema query API. #471

Merged
merged 1 commit into from
Mar 27, 2023
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
10 changes: 10 additions & 0 deletions internal/spec/gpyrpc/gpyrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ service KclvmService {
rpc EvalCode(EvalCode_Args) returns(EvalCode_Result);
rpc ResolveCode(ResolveCode_Args) returns(ResolveCode_Result);
rpc GetSchemaType(GetSchemaType_Args) returns(GetSchemaType_Result);
rpc GetSchemaTypeMapping(GetSchemaTypeMapping_Args) returns(GetSchemaTypeMapping_Result);
rpc ValidateCode(ValidateCode_Args) returns(ValidateCode_Result);
rpc SpliceCode(SpliceCode_Args) returns(SpliceCode_Result);

Expand Down Expand Up @@ -247,6 +248,15 @@ message GetSchemaType_Result {
repeated KclType schema_type_list = 1;
}

message GetSchemaTypeMapping_Args {
string file = 1;
string code = 2;
string schema_name = 3; // emtry is all
}
message GetSchemaTypeMapping_Result {
map<string, KclType> schema_type_mapping = 1;
}

message ValidateCode_Args {
string data = 1;
string code = 2;
Expand Down
19 changes: 5 additions & 14 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions kclvm/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ serde_yaml = "0.9.2"
protobuf-json-mapping = "3.1.0"
compiler_base_session = {path = "../../compiler_base/session"}
serde = { version = "1", features = ["derive"] }
anyhow = "1.0"
indexmap = "1.0"

kclvm-runner = {path = "../runner"}
kclvm-error = {path = "../error"}
kclvm-parser = {path = "../parser"}
kclvm-sema = {path = "../sema"}
kclvm-ast = {path = "../ast"}
kclvm-ast-pretty = {path = "../ast_pretty"}
kclvm-runtime = {path = "../runtime"}
kclvm-tools = {path = "../tools" }
kclvm-query = {path = "../query"}
Expand Down
18 changes: 8 additions & 10 deletions kclvm/capi/src/api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn test_c_api_call_exec_program() {
let serv = kclvm_service_new(0);
let input_path = Path::new(TEST_DATA_PATH).join("exec-program.json");
let input = fs::read_to_string(&input_path)
.expect(format!("Something went wrong reading {}", input_path.display()).as_str());
.unwrap_or_else(|_| panic!("Something went wrong reading {}", input_path.display()));
let args = unsafe {
CString::from_vec_unchecked(
parse_message_from_json::<ExecProgram_Args>(&input)
Expand All @@ -28,13 +28,12 @@ fn test_c_api_call_exec_program() {

let result = parse_message_from_protobuf::<ExecProgram_Result>(result.to_bytes()).unwrap();
let except_result_path = Path::new(TEST_DATA_PATH).join("exec-program.response.json");
let except_result_json = fs::read_to_string(&except_result_path).expect(
format!(
let except_result_json = fs::read_to_string(&except_result_path).unwrap_or_else(|_| {
panic!(
"Something went wrong reading {}",
except_result_path.display()
)
.as_str(),
);
});
let except_result = parse_message_from_json::<ExecProgram_Result>(&except_result_json).unwrap();
assert_eq!(result.json_result, except_result.json_result);
assert_eq!(result.yaml_result, except_result.yaml_result);
Expand All @@ -48,7 +47,7 @@ fn test_c_api_call_override_file() {
let serv = kclvm_service_new(0);
let input_path = Path::new(TEST_DATA_PATH).join("override-file.json");
let input = fs::read_to_string(&input_path)
.expect(format!("Something went wrong reading {}", input_path.display()).as_str());
.unwrap_or_else(|_| panic!("Something went wrong reading {}", input_path.display()));
let args = unsafe {
CString::from_vec_unchecked(
parse_message_from_json::<OverrideFile_Args>(&input)
Expand All @@ -63,13 +62,12 @@ fn test_c_api_call_override_file() {

let result = parse_message_from_protobuf::<OverrideFile_Result>(result.to_bytes()).unwrap();
let except_result_path = Path::new(TEST_DATA_PATH).join("override-file.response.json");
let except_result_json = fs::read_to_string(&except_result_path).expect(
format!(
let except_result_json = fs::read_to_string(&except_result_path).unwrap_or_else(|_| {
panic!(
"Something went wrong reading {}",
except_result_path.display()
)
.as_str(),
);
});
let except_result =
parse_message_from_json::<OverrideFile_Result>(&except_result_json).unwrap();
assert_eq!(result.result, except_result.result);
Expand Down
Loading