sudoblockio / tackle

Tackle is a programmable configuration language for building modular utilities, code generators, and CLIs with schema validation baked in.
Apache License 2.0
52 stars 2 forks source link

Support complex types / composition #161

Open robcxyz opened 1 year ago

robcxyz commented 1 year ago

Would be good if a declarative hook field was able to be typed like another hook would be. This would allow nesting of typed structures as is common in many schema oriented operations.

Examples

Foo<-:
  input_str: str

Bar<-:
  foo: 
    type: Foo

p->: {{Bar(foo=Foo(input_str='fooo'))}}

Expected output

p:
 foo:
   input_str: fooo
Embedded

Bar<-:
  foo: 
    type: Foo

  Foo<-:
    input_str: str

bar: 
  foo: 
    input_str: fooo

p->: {{Bar(**bar)}}

Expected output

p:
 foo:
   input_str: fooo

Complex Types

Base<-:
  field: str 

S<-:
  field1:
    type: Base
  field2:
    type: list[Base]
  field3:
    type: dict[str,Base]
  field4:
    type: optional[Base]
  field5:
    type: union[Base, str]
  field6:
    type: optional[Base]
  field7:
    type: optional[Base]
  field8:
    type: optional[Base]
  field9:
    type: optional[Base]
  field10:
    type: optional[Base]

Enum

Schema<-:
  with_type:
    type: string
    enum:
      - red
      - green
      - blue

  without_type:
    enum:
      - red
      - green
      - blue

  with_default:
    type: string
    default: red
    enum:
      - red
      - green
      - blue

  # Type can be inferred 
  with_default_without_type:
    default: red
    enum:
      - red
      - green
      - blue
S<-: 
  field: 
    enum: 
      - red
      - green
S<-: 
  field: 
    enum: 
      red: 1
      green: 2 

Implementation