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
| Class | Description |
|---|---|
| GeneratorError | Thrown when strict mode is enabled and any error diagnostic is produced. FR-022. |
| GenericModelEmitter | Parameterized 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
| Interface | Description |
|---|---|
| AnnotationAttribute | - |
| CodeListValue | - |
| Condition | - |
| EmittedProjection | Provenance recorded during emission, independent of an editor's node-ID format. |
| ExportDeclarationSelection | Serializable identity for a selected top-level Rune declaration. |
| ExportSelection | Namespace and declaration roots requested for an export. |
| FormPreviewSchema | - |
| FunctionPreviewOutput | The declared result identity for a function preview schema. |
| GeneratedFunc | Metadata for a single emitted Rune func (TypeScript target only). FR-028–FR-032 (function declarations, US6). |
| GeneratedProjection | - |
| GeneratePreviewSchemaOptions | Options for generatePreviewSchemas(). |
| GeneratorDiagnostic | A generator-time diagnostic (not a Langium validation diagnostic). FR-025 (diagnostics). |
| GeneratorOptions | Options for a generation run. FR-001 (target selection), FR-022 (strict mode). |
| GeneratorOutput | One emitted output file from the generator. FR-001 (output structure). |
| LanguageProfile | Declarative target-level metadata for packaging (019 spec §3.2). |
| LibraryFuncParam | - |
| NamespaceEmitter | - |
| NamespaceEmitterConstructor | - |
| NamespaceEmitterOptions | Options passed to a NamespaceEmitter constructor. |
| NamespaceManifest | - |
| NamespaceRegistry | - |
| NativeFunctionShape | - |
| NativeImplementation | - |
| NativeImplementationBody | - |
| NativeParameterShape | - |
| PreviewSourceMapEntry | - |
| ProjectCodeListBinding | - |
| ProjectImplementationBinding | - |
| ProjectionSubject | - |
| PythonModule | - |
| PythonProjectionContext | Linked identities and semantic facts shared with the authoritative codegen utilities. |
| ResolvedExportSelection | - |
| RuneAnnotationDecl | - |
| RuneLibraryFunc | - |
| RuneReport | - |
| RuneRule | - |
| RuneTypeAlias | - |
| SelectedGeneration | Files and the dependency-closed receipt produced by a selected export. |
| SourceMapEntry | One source-map entry: maps an output line back to a source location. FR-024 (source maps). |
| TypeParam | - |
| WholeModelEmitter | Emitter 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 Alias | Description |
|---|---|
| ExcelOptions | - |
| ExcelSheetToggles | Which sheets to emit. Resolves the per-sheet defaults when absent. |
| FormPreviewKind | - |
| ImplementationLanguage | - |
| JsonSchemaOptions | - |
| MarkdownOptions | - |
| NativeImplementationResolution | - |
| PreviewField | - |
| PreviewFieldKind | - |
| ProjectBindingRegistry | - |
| SqlOptions | - |
| Target | Supported 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) |
| TargetDescriptor | Static 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
| Variable | Description |
|---|---|
| ExcelOptionsSchema | - |
| IMPLEMENTED_TARGETS | The targets runGenerate can actually produce output for in this build. |
| NATIVE_IMPLEMENTATIONS | - |
| RUNTIME_HELPER_JS_SOURCE | Annotation-free counterpart used by the Studio execution worker. |
| TARGET_DESCRIPTORS | Registry 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
| Function | Description |
|---|---|
| adaptPreviewData | Normalize canonical object values using the active linked declarations. |
| applyProjectPreviewBindings | Transform every finite definition too, so deferred object expansion uses the same choices. |
| bindGeneratedProjectModule | Attach a prepared registry to a newly loaded generated module; no global registry crosses projects. |
| collectDeclarationDependencies | Direct declaration dependencies through the authoritative effective-reference port. |
| createProjectBindingRegistry | Prepared data and installed callbacks only; this module never reads configuration or loads code. |
| createPythonProjectionContext | - |
| declarationKey | Stable, kind-aware identity for a selected top-level declaration. |
| describeNativeFunction | - |
| emitStandaloneZodSchema | Emit 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). |
| expandPreviewField | Resolve one deferred object body without expanding its nested references. |
| generate | Generate code from one or more parsed Langium documents. |
| generatePreviewSchemas | Generate structured form-preview schemas from one or more parsed Langium documents. |
| generatePythonModule | Standalone browser-safe Python source plus source-addressed display fragments. |
| generateSelected | Generate 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 | - |
| getTargetRelativePath | Convert a dot-separated Rune namespace to the emitted relative file path for a target. |
| isWholeModelEmitter | Runtime 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. |
| metadataPreviewField | Edit a metadata payload's value path while retaining its adjacent keys, scheme and references. |
| nativeFunctionShape | Exact linked signature, shared by catalog guards and the upstream coverage inventory. |
| normalizePreviewInputs | Adapt plain form values to the generated function's metadata-bearing input contract. |
| previewTypeSymbol | Canonical presentation identity shared by schema generation, resource bindings and layout consumers. |
| projectBindingHeader | - |
| projectBindingNames | Names cannot collide with authored Rune identifiers and remain unique in single-file bundles. |
| projectCodeListForAlias | One adapter guard shared by the graph and all resource-aware generators. |
| projectPythonCondition | - |
| projectPythonExpression | Forward generation is independent of the deliberately narrower inverse Python lens. |
| projectPythonFunction | Complete implementation; the inverse Python lens retains its narrower expression contract. |
| projectRuneJsonData | Project canonical Choice slots and concrete Data types before Rune wire metadata encoding. |
| renderCodeListEnum | Use the same canonical enum builder and Rune renderer as schema imports. |
| resolveEffectiveProjectTargetId | Resolve a kind-qualified authored target through core's linked project identity. |
| resolveExcelSheets | Resolve 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. |
| resolveExportSelection | Resolve selected roots and return shallow document views without mutating the linked workspace. |
| resolveNativeImplementation | Authored Rune bodies win. Match identity, annotation and signature before selecting a target body. |
| selectPythonProjection | - |
| selectTypeScriptProjection | Select recorded output; display availability is independent of inverse-lens coverage. |
| unknownExportSelectionDiagnostics | Shared diagnostic details for stale declaration or namespace export roots. |
| validateProjectPreviewBindings | Resource constraints supplement the generated Rune validator; missing data is an availability error. |
| validateTargetOptions | - |