Typegen types

Types for source type generation and the typegen:field plugin hook.

Types used by generateSourceTypes() / writeSourceTypes() and the typegen:field hook.

import type {
  TypegenFieldContext,
  GenerateSourceTypesOptions,
  WriteSourceTypesOptions,
} from 'comark-content'

TypegenFieldContext

Payload for the typegen:field hook. Plugins mutate type in place and register imports through imports.

interface TypegenFieldContext {
  source: string
  path: string[]
  schema: JsonSchema
  layer: 'data' | 'row'
  type: string
  imports: TypegenImportCollector
}
FieldDescription
sourceSource name being rendered.
pathField path inside the schema (e.g. ['items', 'answer']).
schemaJSON Schema node for this field.
layer'data' for get() shapes; 'row' for flattened query columns.
typeMutable TS type string — starts as the default from JSON Schema.
importsCall imports.add('comark', 'MarkdownDocument') to emit extra import type lines.

See markdown-fields for a complete example.

GenerateSourceTypesOptions

Options passed to generateSourceTypes(content, options?).

OptionTypeDefaultDescription
moduleNamestring'comark-content'Module specifier augmented in the generated declare module block.
pathsbooleantrueEmit a ContentPaths map (path → data type). Pass false on very large sites.

WriteSourceTypesOptions

Extends GenerateSourceTypesOptions with output location options for writeSourceTypes(content, options?).

OptionTypeDefaultDescription
outDirstring'.'Directory for the generated file.
fileNamestring'comark-content.d.ts'File name inside outDir.
outFilestringExplicit path; overrides outDir / fileName.