Skip to content

Commit cc57c5a

Browse files
committed
chore: update list varibale API arguments and return values
Signed-off-by: peefy <[email protected]>
1 parent 7057481 commit cc57c5a

File tree

5 files changed

+133
-83
lines changed

5 files changed

+133
-83
lines changed

nodejs/__test__/list_variables.spec.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import test from 'ava'
33
import { listVariables, ListVariablesArgs } from '../index.js'
44

55
test('listVariables', (t) => {
6-
const result = listVariables(ListVariablesArgs('__test__/test_data/schema.k', []))
7-
t.is(result.variables['app'].value, 'AppConfig {replicas: 2}')
6+
const result = listVariables(ListVariablesArgs(['__test__/test_data/schema.k'], []))
7+
t.is(result.variables['app'][0].value, 'AppConfig {replicas: 2}')
88
})

nodejs/index.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,20 @@ export interface LintPathResult {
152152
export interface OverrideFileResult {
153153
result: boolean
154154
}
155+
export interface ListVariablesOptions {
156+
mergeProgram: boolean
157+
}
155158
export interface ListVariablesResult {
156-
variables: Record<string, Variable>
159+
variables: Record<string, Array<Variable>>
157160
unsupportedCodes: Array<string>
158161
parseErrors: Array<Error>
159162
}
160163
export interface Variable {
161164
value: string
165+
typeName: string
166+
opSym: string
167+
listItems: Array<Variable>
168+
dictEntires: Record<string, Variable>
162169
}
163170
export interface GetSchemaTypeResult {
164171
schemaTypeList: Array<KclType>
@@ -320,7 +327,7 @@ export class ExecProgramArgs {
320327
constructor(paths: Array<string>, workDir?: string | undefined | null)
321328
}
322329
export class ListVariablesArgs {
323-
constructor(file: string, specs: Array<string>)
330+
constructor(files: Array<string>, specs: Array<string>, opts?: ListVariablesOptions | undefined | null)
324331
}
325332
export class OverrideFileArgs {
326333
constructor(file: string, specs: Array<string>, importPaths: Array<string>)

nodejs/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,18 @@ pub struct ListVariablesArgs(kclvm_api::ListVariablesArgs);
8383
#[napi]
8484
impl ListVariablesArgs {
8585
#[napi(constructor)]
86-
pub fn new(files: Vec<String>, specs: Vec<String>) -> Result<Self> {
87-
Ok(Self(kclvm_api::ListVariablesArgs { files, specs }))
86+
pub fn new(
87+
files: Vec<String>,
88+
specs: Vec<String>,
89+
opts: Option<ListVariablesOptions>,
90+
) -> Result<Self> {
91+
Ok(Self(kclvm_api::ListVariablesArgs {
92+
files,
93+
specs,
94+
options: opts.map(|o| kclvm_api::ListVariablesOptions {
95+
merge_program: o.merge_program,
96+
}),
97+
}))
8898
}
8999
}
90100

nodejs/src/spec.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,47 @@ impl OverrideFileResult {
337337
}
338338
}
339339

340+
#[napi(object)]
341+
pub struct ListVariablesOptions {
342+
pub merge_program: bool,
343+
}
344+
340345
#[napi(object)]
341346
pub struct ListVariablesResult {
342-
pub variables: HashMap<String, Variable>,
347+
pub variables: HashMap<String, Vec<Variable>>,
343348
pub unsupported_codes: Vec<String>,
344349
pub parse_errors: Vec<Error>,
345350
}
346351

347352
#[napi(object)]
353+
#[derive(Default, Debug)]
348354
pub struct Variable {
349355
pub value: String,
356+
pub type_name: String,
357+
pub op_sym: String,
358+
pub list_items: Vec<Variable>,
359+
pub dict_entires: HashMap<String, Variable>,
360+
}
361+
362+
impl Variable {
363+
pub fn new(v: &kclvm_api::Variable) -> Self {
364+
Self {
365+
value: v.value.to_string(),
366+
type_name: v.type_name.to_string(),
367+
op_sym: v.op_sym.to_string(),
368+
list_items: v.list_items.iter().map(|v| Variable::new(v)).collect(),
369+
dict_entires: v
370+
.dict_entries
371+
.iter()
372+
.map(|e| {
373+
(
374+
e.key.to_string(),
375+
Variable::new(&e.value.clone().unwrap_or_default()),
376+
)
377+
})
378+
.collect(),
379+
}
380+
}
350381
}
351382

352383
impl ListVariablesResult {
@@ -358,9 +389,7 @@ impl ListVariablesResult {
358389
.map(|(k, v)| {
359390
(
360391
k.to_string(),
361-
Variable {
362-
value: v.value.to_string(),
363-
},
392+
v.variables.iter().map(|v| Variable::new(v)).collect(),
364393
)
365394
})
366395
.collect(),

python/kcl_lib/api/spec_pb2.py

Lines changed: 77 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)