Skip to content

Commit f451e09

Browse files
authored
Merge pull request #279 from kcl-lang/feat-new-kcl-type-spec
feat: new kcl type API spec
2 parents 41ea18e + a5fbd9e commit f451e09

File tree

6 files changed

+611
-5253
lines changed

6 files changed

+611
-5253
lines changed

cpp/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,30 @@ mod ffi {
660660
pub examples: Vec<HashMapExampleValue>,
661661
/// Base schema if applicable.
662662
pub base_schema: OptionalKclType,
663+
/// Function type if the KclType is a function.
664+
pub function: OptionalFunctionType,
665+
/// Optional schema index signature
666+
pub index_signature: OptionalIndexSignature,
667+
}
668+
669+
#[derive(Debug, Default)]
670+
pub struct FunctionType {
671+
pub params: Vec<Parameter>,
672+
pub return_ty: OptionalKclType,
673+
}
674+
675+
#[derive(Debug, Default)]
676+
pub struct Parameter {
677+
pub name: String,
678+
pub ty: OptionalKclType,
679+
}
680+
681+
#[derive(Debug, Default)]
682+
pub struct IndexSignature {
683+
pub key_name: String,
684+
pub key: OptionalKclType,
685+
pub val: OptionalKclType,
686+
pub any_other: bool,
663687
}
664688

665689
#[derive(Debug, Default)]
@@ -674,6 +698,18 @@ mod ffi {
674698
value: String,
675699
}
676700

701+
#[derive(Debug, Default)]
702+
struct OptionalFunctionType {
703+
has_value: bool,
704+
value: FunctionType,
705+
}
706+
707+
#[derive(Debug, Default)]
708+
struct OptionalIndexSignature {
709+
has_value: bool,
710+
value: IndexSignature,
711+
}
712+
677713
#[derive(Debug, Default)]
678714
/// Message representing a decorator in KCL.
679715
pub struct Decorator {
@@ -1340,6 +1376,8 @@ impl KclType {
13401376
pkg_path: r.pkg_path.clone(),
13411377
line: r.line,
13421378
item: OptionalKclType::new_from_box(&r.item),
1379+
// TODO: function and index_signature fields
1380+
..Default::default()
13431381
}
13441382
}
13451383
}

nodejs/index.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,26 @@ export interface KclType {
328328
description: string
329329
/** A map object to hold examples, the key is the example name. */
330330
examples: Record<string, Example>
331+
/** Base schema if applicable. */
332+
baseSchema: KclType
333+
/** Function type if the KclType is a function. */
334+
function: FunctionType
335+
/** Optional schema index signature */
336+
indexSignature?: IndexSignature
337+
}
338+
export interface FunctionType {
339+
params: Array<Parameter>
340+
returnTy: KclType
341+
}
342+
export interface Parameter {
343+
name: string
344+
ty: KclType
345+
}
346+
export interface IndexSignature {
347+
keyName?: string
348+
key: KclType
349+
val: KclType
350+
anyOther: boolean
331351
}
332352
/** Message representing a decorator in KCL. */
333353
export interface Decorator {

nodejs/src/spec.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,32 @@ pub struct KclType {
700700
pub description: String,
701701
/// A map object to hold examples, the key is the example name.
702702
pub examples: HashMap<String, Example>,
703+
/// Base schema if applicable.
704+
pub base_schema: Reference<KclType>,
705+
/// Function type if the KclType is a function.
706+
pub function: FunctionType,
707+
/// Optional schema index signature
708+
pub index_signature: Option<IndexSignature>,
709+
}
710+
711+
#[napi(object)]
712+
pub struct FunctionType {
713+
pub params: Vec<Parameter>,
714+
pub return_ty: Reference<KclType>,
715+
}
716+
717+
#[napi(object)]
718+
pub struct Parameter {
719+
pub name: String,
720+
pub ty: Reference<KclType>,
721+
}
722+
723+
#[napi(object)]
724+
pub struct IndexSignature {
725+
pub key_name: Option<String>,
726+
pub key: Reference<KclType>,
727+
pub val: Reference<KclType>,
728+
pub any_other: bool,
703729
}
704730

705731
/// Message representing a decorator in KCL.

swift/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ DerivedData/
1010
/KclLib/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
1111
/KclLib/.swiftpm/config/registries.json
1212
/KclLib/Sources/CKclLib/lib
13+
Cargo.lock

0 commit comments

Comments
 (0)