Skip to content

rune-langium / codegen/src/export

codegen/src/export ​

Generate TypeScript, Zod, JSON Schema, and form-preview metadata from parsed Rune DSL documents.

Remarks ​

Import this API from @rune-langium/codegen/export; the package root is empty. Inbound import and Rosetta rendering APIs use separate subpaths.

Use generate() when you need emitted files for a concrete target, and generatePreviewSchemas() when UI tooling needs structured field metadata and source maps for a selected data type. This package expects parsed Langium documents from @rune-langium/core.

Classes ​

ClassDescription
GeneratorErrorThrown when strict mode is enabled and any error diagnostic is produced. FR-022.
GenericModelEmitterParameterized WholeModelEmitter that wraps any NamespaceEmitter plus a LanguageProfile (019 spec §3.2). Collapses the "per-namespace then aggregate" pattern into one place so individual targets only need to ship a NamespaceEmitter + a Profile.
ProjectBindingUnavailable-

Interfaces ​

InterfaceDescription
AnnotationAttribute-
CodeListValue-
Condition-
EmittedProjectionProvenance recorded during emission, independent of an editor's node-ID format.
ExportDeclarationSelectionSerializable identity for a selected top-level Rune declaration.
ExportSelectionNamespace and declaration roots requested for an export.
FormPreviewSchema-
FunctionPreviewOutputThe declared result identity for a function preview schema.
GeneratedFuncMetadata for a single emitted Rune func (TypeScript target only). FR-028–FR-032 (function declarations, US6).
GeneratedProjection-
GeneratePreviewSchemaOptionsOptions for generatePreviewSchemas().
GeneratorDiagnosticA generator-time diagnostic (not a Langium validation diagnostic). FR-025 (diagnostics).
GeneratorOptionsOptions for a generation run. FR-001 (target selection), FR-022 (strict mode).
GeneratorOutputOne emitted output file from the generator. FR-001 (output structure).
LanguageProfileDeclarative target-level metadata for packaging (019 spec §3.2).
LibraryFuncParam-
NamespaceEmitter-
NamespaceEmitterConstructor-
NamespaceEmitterOptionsOptions passed to a NamespaceEmitter constructor.
NamespaceManifest-
NamespaceRegistry-
NativeFunctionShape-
NativeImplementation-
NativeImplementationBody-
NativeParameterShape-
PreviewSourceMapEntry-
ProjectCodeListBinding-
ProjectImplementationBinding-
ProjectionSubject-
PythonModule-
PythonProjectionContextLinked identities and semantic facts shared with the authoritative codegen utilities.
ResolvedExportSelection-
RuneAnnotationDecl-
RuneLibraryFunc-
RuneReport-
RuneRule-
RuneTypeAlias-
SelectedGenerationFiles and the dependency-closed receipt produced by a selected export.
SourceMapEntryOne source-map entry: maps an output line back to a source location. FR-024 (source maps).
TypeParam-
WholeModelEmitterEmitter contract for targets that consume the entire model as a single input (rather than one namespace at a time). Used by targets that need cross-namespace state — e.g. Excel produces one workbook for the whole model with cross-sheet hyperlinks, GraphQL SDL produces one schema file with the full type graph. SQL and Markdown are per-namespace targets (see TARGET_DESCRIPTORS) — Copilot review on PR #165 caught an earlier draft of this comment listing SQL as whole-model.
WholeModelEmitterConstructor-

Type Aliases ​

Type AliasDescription
ExcelOptions-
ExcelSheetTogglesWhich sheets to emit. Resolves the per-sheet defaults when absent.
FormPreviewKind-
ImplementationLanguage-
JsonSchemaOptions-
MarkdownOptions-
NativeImplementationResolution-
PreviewField-
PreviewFieldKind-
ProjectBindingRegistry-
SqlOptions-
TargetSupported generator targets. - zod — FR-002–FR-014 (US1, per-namespace) - json-schema — FR-019 (per-namespace) - typescript — FR-020 (per-namespace; includes func emission) - sql — 018 Phase 2 (per-namespace DDL emitter) - markdown — 018 Phase 2 (per-namespace docs emitter) - excel — 018 Phase 1 (whole-model binary emitter, .xlsx) - graphql — 018 Phase 3 (whole-model SDL emitter) - openapi — 021 Phase 2b (per-namespace; OAS 3.1, composes the JSON Schema emitter's own output + adds constraint keywords, funcs→operations, optional CRUD paths) - xsd — 021 Phase 3 (per-namespace; W3C XML Schema documents, a from-scratch emitter symmetric to the inbound XSD reader — no func/operation emission, XSD has no RPC verb model)
TargetDescriptorStatic descriptor for a generator target. Single source of truth used by UI surfaces (the studio targets table — 018 Task 0.7) to render labels + decide between Preview / Download affordances. The runtime contract mirrors which emitter interface the target implements (NamespaceEmitter vs WholeModelEmitter — see Task 0.2).
TemporalWireFormat-
TypescriptOptions-
ZodOptions-

Variables ​

VariableDescription
ExcelOptionsSchema-
IMPLEMENTED_TARGETSThe targets runGenerate can actually produce output for in this build.
NATIVE_IMPLEMENTATIONS-
RUNTIME_HELPER_JS_SOURCEAnnotation-free counterpart used by the Studio execution worker.
TARGET_DESCRIPTORSRegistry of all generator targets. The studio reads this to render the targets table; runGenerate reads it to pick the dispatch path. Keep in sync with the Target union — TS exhaustiveness check on Record<Target, ...> enforces this at compile time.
TARGET_OPTIONS_SCHEMAS-

Functions ​

FunctionDescription
adaptPreviewDataNormalize canonical object values using the active linked declarations.
applyProjectPreviewBindingsTransform every finite definition too, so deferred object expansion uses the same choices.
bindGeneratedProjectModuleAttach a prepared registry to a newly loaded generated module; no global registry crosses projects.
collectDeclarationDependenciesDirect declaration dependencies through the authoritative effective-reference port.
createProjectBindingRegistryPrepared data and installed callbacks only; this module never reads configuration or loads code.
createPythonProjectionContext-
declarationKeyStable, kind-aware identity for a selected top-level declaration.
describeNativeFunction-
emitStandaloneZodSchemaEmit one target type's real Zod schema as a self-contained script — the target's transitive closure (Task 2) assembled into a single synthetic NamespaceWalkResult and rendered through the real, unmodified emitNamespace() (zod target), never a hand-rolled approximation of it (per the repo's DRY precept).
expandPreviewFieldResolve one deferred object body without expanding its nested references.
generateGenerate code from one or more parsed Langium documents.
generatePreviewSchemasGenerate structured form-preview schemas from one or more parsed Langium documents.
generatePythonModuleStandalone browser-safe Python source plus source-addressed display fragments.
generateSelectedGenerate a declaration-scoped export and return the exact selection receipt used by generation. This lets callers present or archive the dependency closure without resolving the source workspace a second time.
getGeneratorCapabilities-
getTargetLayouts-
getTargetRelativePathConvert a dot-separated Rune namespace to the emitted relative file path for a target.
isWholeModelEmitterRuntime discriminator between the two emitter contracts. Distinguishes by prototype shape: NamespaceEmitter exposes a finalize() method (plus the per-element emitData / emitEnumeration / etc. hooks); WholeModelEmitter exposes only a single async emit() method.
metadataPreviewFieldEdit a metadata payload's value path while retaining its adjacent keys, scheme and references.
nativeFunctionShapeExact linked signature, shared by catalog guards and the upstream coverage inventory.
normalizePreviewInputsAdapt plain form values to the generated function's metadata-bearing input contract.
previewTypeSymbolCanonical presentation identity shared by schema generation, resource bindings and layout consumers.
projectBindingHeader-
projectBindingNamesNames cannot collide with authored Rune identifiers and remain unique in single-file bundles.
projectCodeListForAliasOne adapter guard shared by the graph and all resource-aware generators.
projectPythonCondition-
projectPythonExpressionForward generation is independent of the deliberately narrower inverse Python lens.
projectPythonFunctionComplete implementation; the inverse Python lens retains its narrower expression contract.
projectRuneJsonDataProject canonical Choice slots and concrete Data types before Rune wire metadata encoding.
renderCodeListEnumUse the same canonical enum builder and Rune renderer as schema imports.
resolveEffectiveProjectTargetIdResolve a kind-qualified authored target through core's linked project identity.
resolveExcelSheetsResolve the effective sheet toggles from a partial/absent options block, applying the schema defaults. Used by the emitter so a missing excel option or a partial sheets object still produces a complete workbook.
resolveExportSelectionResolve selected roots and return shallow document views without mutating the linked workspace.
resolveNativeImplementationAuthored Rune bodies win. Match identity, annotation and signature before selecting a target body.
selectPythonProjection-
selectTypeScriptProjectionSelect recorded output; display availability is independent of inverse-lens coverage.
unknownExportSelectionDiagnosticsShared diagnostic details for stale declaration or namespace export roots.
validateProjectPreviewBindingsResource constraints supplement the generated Rune validator; missing data is an availability error.
validateTargetOptions-

Core packages released under MIT. Studio app released under FSL-1.1-ALv2.