# toModelEntry

FUNCTION in `@skmtc/core 0.63.4`

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

```ts
import { toModelEntry } from '@skmtc/core'

toModelEntry<EnrichmentType = undefined>(
  args: ToModelEntryArgs<EnrichmentType>
): ModelEntry<EnrichmentType>
```

- `EnrichmentType`: The enrichments that `toEnrichmentSchema` parses

## Parameters

- `args` (ToModelEntryArgs<EnrichmentType>, required): Configuration for the model entry
  - `id` (string, required): The generator's id: the `name` in its `deno.json`.
  - `projections` (readonly DeclaredProjection[]): 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.
  - `transform` ((args: TransformModelArgs) => void, required): Inserts the generator's projection for one variant of one model.
  - `toEnrichmentSchema` (() => v.GenericSchema<EnrichmentType>, required): The schema of the generator's enrichments. A generator with none gives `emptyEnrichmentSchema`.
  - `isSupported` ((args: IsSupportedModelArgs) => boolean): 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.
  - `supportsVariant` (() => boolean): Optional: whether this generator entry supports variants. Defaults to a function returning `false` when omitted.
  - `toPreviewModule` ((args: ToModelPreviewModuleArgs) => PreviewModule): Optional: the preview module of a model.
  - `toEnrichmentRequest` (<RequestedEnrichment extends EnrichmentType>(ref: RefParts) => EnrichmentRequest<RequestedEnrichment> | undefined): Optional: asks for a model's enrichments. See `EnrichmentRequest`.
  - `toEnrichmentDefaults` ((args: ToModelEnrichmentsArgs) => EnrichmentType | undefined): Optional: the enrichments a model starts with, derived from the document.

## Examples

A generator with no enrichments:

```ts
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

`ModelEntry<EnrichmentType>`

The entry, for the generator to export
