Models
toModelEntry
Creates the entry of a model generator: what the generator's mod.ts exports, and what the engine runs.
The engine calls transform for each model of the document that the generator supports and the settings do not leave out, once for each variant. transform inserts the generator's projection into its file.
Signature
import { toModelEntry } from '@skmtc/core'
toModelEntry<EnrichmentType = undefined>(
args: ToModelEntryArgs<EnrichmentType>
): ModelEntry<EnrichmentType>The enrichments that toEnrichmentSchema parses
Parameters
Configuration for the model entry
The generator's id: the name in its deno.json.
Every projection class this generator can insert: its own, and each one of another generator that it inserts. Core reads only their statics. See DeclaredProjection. Optional.
Inserts the generator's projection for one variant of one model.
The schema of the generator's enrichments. A generator with none gives emptyEnrichmentSchema.
Whether the generator supports a model. One that it does not is recorded as notSupported, and transform is not called for it. Resolve the schema here when the answer depends on it (context.resolveSchemaRefOnce(ref)). Defaults to supporting every model.
Optional: whether this generator entry supports variants. Defaults to a function returning false when omitted.
Optional: the preview module of a model.
Optional: asks for a model's enrichments. See EnrichmentRequest.
Optional: the enrichments a model starts with, derived from the document.
import { emptyEnrichmentSchema, toModelEntry, type EmptyEnrichments } from '@skmtc/core'
import { MyProjection } from './MyProjection.ts'
import denoJson from '../deno.json' with { type: 'json' }
export const myEntry = toModelEntry<EmptyEnrichments>({
id: denoJson.name,
projections: [MyProjection],
toEnrichmentSchema: () => emptyEnrichmentSchema,
transform({ context, ref, variant }) {
context.insertModel(MyProjection, ref, { variant })
}
})Returns
The entry, for the generator to export