Meta-Schema
A data-structure library to describe more information about your model in a separated file
Install
npm i @simpli/meta-schema
About
Meta-Schema helps you to organize meta information about the Model fields, can be used to declare how the field will be rendered.
Usage
Import
import { Schema, FieldSet, FieldComponent } from '@simpli/meta-schema'
Create your schema
class MyModel {
title: string | null = null
description: string | null = null
}
class MySchema extends Schema {
translateFrom = (fieldName: string) => fieldName.toUpperCase()
readonly fieldSet: FieldSet<MyModel> = {
title: (schema): FieldComponent => ({
is: MyComponent,
bind: {
label: this.translateFrom(schema.fieldName),
required: true,
validation: 'required',
},
}),
description: schema => schema.model.description,
}
}
Schema basic methods
const subject = new MySchema()
subject.allFields
subject.allHeaders
subject.header
const model = new MyModel()
model.title = 'my title'
model.description = 'my description'
const schemaBuilder = subject.build(model, 'title')
schemaBuilder.schema
schemaBuilder.model
schemaBuilder.fieldName
const m1 = new MyModel()
m1.title = 'my title'
m1.description = 'my description'
const m2 = new MyModel()
m2.title = 'other title'
m2.description = 'other description'
const m3 = new MyModel()
m3.title = 'with null description'
m3.description = null
subject.fieldDataList([m1, m2, m3], false)
subject.fieldDataList([m1, m2, m3], true)
subject.fieldComponent(model, false)
subject.build(model, 'title').getData()
subject.build(model, 'description').getData()
subject.build(model, 'title').getComponent()
subject.build(model, 'description').getComponent()