StackpressGitHub

API reference

Schema

Schema is the generated-schema helper used by transforms and schema-aware code. It stores enums, fieldsets, models, plugins, and props in map-like collections.

Import

import { Schema } from 'stackpress/schema';

Instantiation

Use Schema.make(config) when you are inside a generator and already have a raw SchemaConfig from Idea parsing. Use new Schema() only when building a schema object manually for tests or helper code.

const schema = Schema.make(props.schema);

for (const model of schema.models.values()) {
  console.log(model.name.singular);
}

This example is the normal transform pattern. props.schema is the raw generation payload, and Schema.make(...) rebuilds the class helpers used by Stackpress generators.

Properties

PropertyTypeDescription
enumsDataMap<string, EnumConfig>Enum declarations keyed by name.
fieldsetsDataMap<string, Fieldset>Fieldset declarations keyed by name.
modelsDataMap<string, Model>Model declarations keyed by name.
pluginsDataMap<string, PluginConfig>Idea plugin declarations keyed by module/path.
propsDataMap<string, PropConfig>Top-level idea props keyed by name.

Static Methods

Schema.make(config)

Creates a Schema instance from a raw SchemaConfig.

ParameterTypeDescription
configSchemaConfigParsed Idea schema payload.

Returns a Schema instance with helper collections populated.

const schema = Schema.make(props.schema);
const article = schema.models.get('Article');

This example creates a helper and reads one model by name. If the model does not exist, the map lookup returns no value.

Instance Methods

makeEnum(name, options)

Adds an enum declaration to schema.enums.

ParameterTypeDescription
namestringEnum name.
optionsEnumConfigEnum option config from Idea parsing.

Returns the enum config that was stored.

makeFieldset(name, attributes?, columns?)

Creates and stores a Fieldset.

ParameterTypeDescription
namestringFieldset name.
attributesAttributesTokenOptional fieldset attributes.
columnsColumnToken[]Optional fieldset columns.

Returns the created Fieldset.

makeModel(name, attributes?, columns?)

Creates and stores a Model.

ParameterTypeDescription
namestringModel name.
attributesAttributesTokenOptional model attributes.
columnsColumnToken[]Optional model columns.

Returns the created Model.

makePlugin(module, config)

Adds an Idea plugin declaration to schema.plugins.

ParameterTypeDescription
modulestringPlugin module or transform path.
configPluginConfigPlugin config object.

Returns the plugin config that was stored.

makeProp(name, value)

Adds a top-level prop to schema.props.

ParameterTypeDescription
namestringProp name.
valuePropConfigProp value.

Returns the prop value that was stored.