0.1.1 • Published 1 year ago

idea-spec v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

💡 Idea Spec

Maps made for idea plugins.

Install

$ npm i idea-spec

Usage

In your plugin you can populate the maps like the following.

import type { PluginWithCLIProps } from '@ossph/idea';
import { Model, Fieldset, Enum } from 'idea-spec';

export default function transform({ config, schema, cli }: PluginWithCLIProps) {
  //populate model cache
  for (const name in schema.model) {
    Model.add(schema.model[name]);
  }
  //populate fieldset cache
  for (const name in schema.type) {
    Fieldset.add(schema.type[name]);
  }
  //populate enum cach
  for (const name in schema.enum) {
    Enum.add(name, schema.enum[name]);
  }

  //.. your plugin logic
}

Then, you can make new constructs like the following.

const model = new Model('profile');
const fieldset = new Fieldset('address');
const roles = Enum.get('roles');

Enum

The following methods are available for enums.

Enum.add(name: string, options: Record<string, Data>)

Adds a schema to the static enum cache.

Enum.has(name: string)

Returns true if the name is in the enum cache.

Enum.get(name: string)

Returns the enum options from the enum cache given the name.

Fieldset

Fieldsets have the following properties.

NameTypeDescription
assertionsColumn[]the columns with assertions
attributesobjectthe fieldset attributes
camelobjectcamel cased fieldset name
columnsColumn[]all the columns
enumsColumn[]all columns that are enums
fieldsColumn[]all columns that are fields
fieldsetsColumn[]all columns that are fieldsets
iconstringfieldset icon
labelstring[]fieldset label
listsColumn[]all columns that are lists
lowerstringlowercase fieldset name
namestringfieldset name
pluralstringplural label
singularstringsingular label
titlestringtitle label
viewsColumn[]all columns that are views

The following methods are available for fieldsets.

Fieldset.add(name: string, options: Record<string, Data>)

Adds a schema to the static fieldset cache.

Fieldset.has(name: string)

Returns true if the name is in the fieldset cache.

Fieldset.get(name: string)

Returns the fieldset options from the fieldset cache given the name.

const fieldset = new Fieldset('address');
fieldset.column('city');

Returns the column information given the column name.

Model

Models have the following properties

NameTypeDescription
activeColumnnullthe active column
assertionsColumn[]the columns with assertions
attributesobjectthe model attributes
camelobjectcamel cased model name
columnsColumn[]all the columns
createdColumnnullthe created column
enumsColumn[]all columns that are enums
fieldsColumn[]all columns that are fields
fieldsetsColumn[]all columns that are fieldsets
filterablesColumn[]all columns that are filterable
idsColumn[]all columns that are @id's
indexableColumn[]all columns that are indexable
iconstringmodel icon
labelstring[]model label
listsColumn[]all columns that are lists
lowerstringlowercase model name
namestringmodel name
pluralstringplural label
relatedColumn[]all columns that are related
relationsColumn[]all columns that are relations
restorablebooleantrue if model is restorable
searchableColumn[]all columns that are searchable
sortablesColumn[]all columns that are sortable
spanablesColumn[]all columns that are spanable
singularstringsingular label
titlestringtitle label
uniquesColumn[]all columns that are @unique
updatedColumnnullthe udpated column
viewsColumn[]all columns that are views

The following methods are available for models.

Model.add(name: string, options: Record<string, Data>)

Adds a schema to the static model cache.

Model.has(name: string)

Returns true if the name is in the model cache.

Model.get(name: string)

Returns the model options from the models cache given the name.

const model = new Model('user');
model.column('name');

Returns the column information given the column name.

Column

Columns have the following properties

NameTypeDescription
activebooleantrue if this column is an @active column
assertionsobject[]the column assertions
attributesobjectthe column attributes
configobjectthe column config
defaultscalarthe column @default value
enumobjectnullenum if type is an enum
fieldobjectthe column field (defaults to none)
fieldsetFieldsetnullfieldset if type is a fieldset
filterablebooleantrue if column is @filterable
generatedbooleantrue if column is @generated
idbooleantrue if column is an @id
indexablebooleantrue if column is @filterable, @searchable, or @sortable
labelstringthe column @label
listobjectthe column list format (defaults to none)
modelModelnullmodel if type is a model
multiplebooleantrue if the column accepts @multiple values
nameobjectthe column name
relatedobjectnullthe related column, if any
relationobjectnullthe column @relation, if any
requiredbooleantrue if the column is @required or @is.required
searchablebooleantrue if column is @searchable
sortablebooleantrue if column is @sortable
spanablebooleantrue if column is @spanable
typestringthe column type
uniquebooleantrue if column is @unique
viewobjectthe column @view format (defaults to none)
0.1.1

1 year ago

0.1.0

1 year ago