
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@simpli/meta-schema
Advanced tools
A data-structure library to describe more information about your model in a separated file
A data-structure library to describe more information about your model in a separated file
npm i @simpli/meta-schema
Meta-Schema helps you to organize meta information about the Model fields, can be used to declare how the field will be rendered.
import { Schema, FieldSet, FieldComponent } from '@simpli/meta-schema'
class MyModel {
title: string | null = null
description: string | null = null
}
class MySchema extends Schema {
// create a function to translate your field names,
// my translation only put it on uppercase
translateFrom = (fieldName: string) => fieldName.toUpperCase()
// declare the fieldSet
readonly fieldSet: FieldSet<MyModel> = {
// our first field is 'title', is a FieldComponent
title: (schema): FieldComponent => ({
// on "is" you may put the component class to render the fieldset
is: MyComponent,
// on "bind" you can put any prop
bind: {
label: this.translateFrom(schema.fieldName),
required: true,
validation: 'required',
},
// you can declare a `name` and use `on` for listeners
}),
// our second field is 'description', is a FieldData because it only answer a primitive value
description: schema => schema.model.description,
}
}
const subject = new MySchema()
subject.allFields // returns ['title', 'description']
subject.allHeaders // returns ['TITLE', 'DESCRIPTION']
subject.header // returns {title: 'TITLE', description: 'DESCRIPTION'}
const model = new MyModel()
model.title = 'my title'
model.description = 'my description'
const schemaBuilder = subject.build(model, 'title')
schemaBuilder.schema // returns subject
schemaBuilder.model // returns model
schemaBuilder.fieldName // returns 'title'
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) // false to use the fieldname as key
/* returns
[
{"description": "my description"},
{"description": "other description"},
{"description": null}
]
*/
subject.fieldDataList([m1, m2, m3], true) // true to use the translation as key
/* returns
[
{"DESCRIPTION": "my description"},
{"DESCRIPTION": "other description"},
{"DESCRIPTION": null}
]
*/
subject.fieldComponent(model, false)
/* returns
{
"title": {
is: MyComponent,
bind: {
label: 'TITLE',
required: true,
validation: 'required',
},
}
}
*/
subject.build(model, 'title').getData()
// returns null because it is not a FieldData
subject.build(model, 'description').getData() // returns 'my description'
subject.build(model, 'title').getComponent()
/* returns
{
is: MyComponent,
bind: {
label: 'TITLE',
required: true,
validation: 'required',
},
}
*/
subject.build(model, 'description').getComponent()
// returns null because it is not a FieldComponent
FAQs
A data-structure library to describe more information about your model in a separated file
The npm package @simpli/meta-schema receives a total of 13 weekly downloads. As such, @simpli/meta-schema popularity was classified as not popular.
We found that @simpli/meta-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.