Skip to main content

alef_core/config/
languages.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::PathBuf;
4
5use super::extras::Language;
6
7/// Configuration for a single capsule type entry in `PythonConfig::capsule_types`.
8///
9/// Supports two TOML forms via `#[serde(untagged)]`:
10///
11/// - String: `Language = "tree_sitter.Language"` → capsule round-trip via `into_raw()`
12/// - Struct: `Parser = { python_type = "tree_sitter.Parser", construct_from = "Language" }` → Python-side construction
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(untagged)]
15pub enum CapsuleTypeConfig {
16    /// Capsule round-trip: the Rust type exposes `into_raw()` returning a raw pointer.
17    /// The generated code calls `PyCapsule_New(value.into_raw(), capsule_name, None)` on return,
18    /// and `PyCapsule_GetPointer` + `from_raw()` on input.
19    ///
20    /// Value is the fully-qualified Python capsule name (e.g. `"tree_sitter.Language"`).
21    Capsule(String),
22    /// Python-side construction: the type does not have a direct `into_raw()`.
23    /// Instead, the generated code constructs the Python type by calling a Python factory
24    /// (e.g. `tree_sitter.Parser(language)`) where `language` is a bound capsule argument.
25    ConstructFrom {
26        /// The fully-qualified Python type to import and call (e.g. `"tree_sitter.Parser"`).
27        python_type: String,
28        /// The capsule-type argument name to pass to the Python constructor.
29        /// Must be one of the other capsule-type entries (e.g. `"Language"`).
30        construct_from: String,
31    },
32}
33
34impl CapsuleTypeConfig {
35    /// Returns the Python type string (dotted path) for this config entry.
36    pub fn python_type(&self) -> &str {
37        match self {
38            Self::Capsule(name) => name,
39            Self::ConstructFrom { python_type, .. } => python_type,
40        }
41    }
42
43    /// Returns the `construct_from` dependency type name, if this is a `ConstructFrom` entry.
44    pub fn construct_from(&self) -> Option<&str> {
45        match self {
46            Self::ConstructFrom { construct_from, .. } => Some(construct_from.as_str()),
47            Self::Capsule(_) => None,
48        }
49    }
50
51    /// Returns true when this entry represents a raw capsule round-trip (not Python-side construction).
52    pub fn is_capsule_roundtrip(&self) -> bool {
53        matches!(self, Self::Capsule(_))
54    }
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PythonConfig {
59    pub module_name: Option<String>,
60    pub async_runtime: Option<String>,
61    pub stubs: Option<StubsConfig>,
62    /// PyPI package name (e.g. `"html-to-markdown"`). Used as the `[project] name` in
63    /// `pyproject.toml` and to derive the `python-packages` list for maturin.
64    /// Defaults to the crate name.
65    #[serde(default)]
66    pub pip_name: Option<String>,
67    /// Per-language feature override. When set, these features are used instead of
68    /// `[crate] features` for this language's binding crate.
69    #[serde(default)]
70    pub features: Option<Vec<String>>,
71    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
72    /// When set, this takes priority over the IR type-level serde_rename_all.
73    #[serde(default)]
74    pub serde_rename_all: Option<String>,
75    /// Map of type name -> capsule config for PyCapsule pass-through.
76    /// Types listed here are emitted as PyCapsule_New / PyCapsule_GetPointer instead of
77    /// opaque `#[pyclass]` wrappers. Use `CapsuleTypeConfig::Capsule` for raw capsule
78    /// round-trips and `CapsuleTypeConfig::ConstructFrom` for Python-side construction.
79    #[serde(default)]
80    pub capsule_types: HashMap<String, CapsuleTypeConfig>,
81    /// When true, wrap blocking function bodies in py.allow_threads() to release the GIL.
82    // TODO: Wire into gen_bindings.rs to emit py.allow_threads(|| { ... }) for non-async functions.
83    #[serde(default)]
84    pub release_gil: bool,
85    /// Functions to exclude from Python binding generation.
86    #[serde(default)]
87    pub exclude_functions: Vec<String>,
88    /// Types to exclude from Python binding generation.
89    #[serde(default)]
90    pub exclude_types: Vec<String>,
91    /// Additional Cargo dependencies for this language's binding crate only.
92    #[serde(default)]
93    pub extra_dependencies: HashMap<String, toml::Value>,
94    /// Override the scaffold output directory for this language's Cargo.toml and package files.
95    #[serde(default)]
96    pub scaffold_output: Option<PathBuf>,
97    /// Per-field name remapping for this language. Key is `TypeName.field_name` (e.g.
98    /// `"LayoutDetection.class"`), value is the desired binding field name. Applied after
99    /// automatic keyword escaping, so an explicit entry takes priority.
100    #[serde(default)]
101    pub rename_fields: HashMap<String, String>,
102    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
103    /// commands across all pipelines (lint, test, build, etc.).
104    /// E.g., `run_wrapper = "uv run --no-sync"` turns `ruff format packages/python` into
105    /// `uv run --no-sync ruff format packages/python`.
106    #[serde(default)]
107    pub run_wrapper: Option<String>,
108    /// Extra paths to append to default lint commands (format, check, typecheck).
109    /// Space-separated paths are appended to the command.
110    #[serde(default)]
111    pub extra_lint_paths: Vec<String>,
112    /// Additional `from <module> import <symbol>` lines to emit in the generated `__init__.py`.
113    /// Key is the relative or absolute Python module path (e.g. `"._supported_languages"`),
114    /// value is the list of symbols to import. The symbols are also added to `__all__`.
115    ///
116    /// Use this to re-export hand-written sibling modules (e.g. generated by a project's own
117    /// build script) without alef's cleanup culling them. The hand-written file must NOT contain
118    /// the substrings `"DO NOT EDIT"`, `"auto-generated by alef"`, or `"AUTO-GENERATED by alef"`
119    /// in its first 5 lines, or alef's cleanup pipeline will treat it as a stale alef artifact.
120    #[serde(default)]
121    pub extra_init_imports: std::collections::BTreeMap<String, Vec<String>>,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct StubsConfig {
126    pub output: PathBuf,
127}
128
129/// Configuration for a single capsule type entry in `NodeConfig::capsule_types`.
130///
131/// When set, the named Rust type is NOT emitted as a `#[napi]` opaque wrapper.
132/// Instead, functions returning this type produce a `JsObject` carrying the raw
133/// pointer in a configurable `Napi::External<T>` property — the layout consumed
134/// by the `tree-sitter` npm package's `Parser.setLanguage()`.
135///
136/// TOML form:
137/// ```toml
138/// [crates.node.capsule_types.Language]
139/// type = "Language"
140/// from_module = "tree-sitter"
141/// property_name = "language"
142/// type_tag = { lower = "0x8AF2E5212AD58ABF", upper = "0xD5006CAD83ABBA16" }
143/// ```
144#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
145pub struct NodeCapsuleTypeConfig {
146    /// User-facing class name in the ecosystem library (e.g. `"Language"`).
147    /// Emitted as the return-type annotation in the generated `index.d.ts`.
148    #[serde(rename = "type")]
149    pub type_name: String,
150    /// npm package to import the type from (e.g. `"tree-sitter"`).
151    /// Emitted as the `from` clause in the generated `import type` line.
152    pub from_module: String,
153    /// Codegen strategy. Currently only `"external_pointer"` is supported.
154    /// Defaults to `"external_pointer"`.
155    #[serde(default = "default_node_capsule_construct")]
156    pub construct: String,
157    /// JS property name to set on the returned object. `node-tree-sitter`
158    /// reads `value["language"]`; other consumers may use different names.
159    /// Defaults to `"__parser"` for back-compat with existing configs.
160    #[serde(default = "default_node_capsule_property_name")]
161    pub property_name: String,
162    /// Optional N-API type tag to apply via `napi_type_tag_object`. Required
163    /// when the consumer library (e.g. `node-tree-sitter`) calls
164    /// `napi_check_object_type_tag` to validate the External before using it.
165    #[serde(default)]
166    pub type_tag: Option<NapiTypeTagConfig>,
167}
168
169/// An N-API `napi_type_tag` value, expressed as two 64-bit hex strings.
170#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
171pub struct NapiTypeTagConfig {
172    /// Lower 64 bits of the tag, hex (e.g. `"0x8AF2E5212AD58ABF"`).
173    pub lower: String,
174    /// Upper 64 bits of the tag, hex (e.g. `"0xD5006CAD83ABBA16"`).
175    pub upper: String,
176}
177
178fn default_node_capsule_construct() -> String {
179    "external_pointer".to_string()
180}
181
182fn default_node_capsule_property_name() -> String {
183    "__parser".to_string()
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct NodeConfig {
188    pub package_name: Option<String>,
189    /// Per-language feature override. When set, these features are used instead of
190    /// `[crate] features` for this language's binding crate.
191    #[serde(default)]
192    pub features: Option<Vec<String>>,
193    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
194    /// When set, this takes priority over the IR type-level serde_rename_all.
195    #[serde(default)]
196    pub serde_rename_all: Option<String>,
197    /// Prefix for generated type names (e.g. "Js" produces `JsConversionOptions`).
198    /// Defaults to `"Js"`.
199    #[serde(default)]
200    pub type_prefix: Option<String>,
201    /// Map of Rust type name -> capsule config for raw-pointer passthrough.
202    /// Types listed here skip the default `#[napi]` opaque-wrapper emission;
203    /// functions returning them produce a `JsObject` with a `__parser`
204    /// `Napi::External<T>` property instead. See [`NodeCapsuleTypeConfig`].
205    #[serde(default)]
206    pub capsule_types: HashMap<String, NodeCapsuleTypeConfig>,
207    /// Functions to exclude from Node binding generation.
208    #[serde(default)]
209    pub exclude_functions: Vec<String>,
210    /// Types to exclude from Node binding generation.
211    #[serde(default)]
212    pub exclude_types: Vec<String>,
213    /// Additional Cargo dependencies for this language's binding crate only.
214    #[serde(default)]
215    pub extra_dependencies: HashMap<String, toml::Value>,
216    /// Override the scaffold output directory for this language's Cargo.toml and package files.
217    #[serde(default)]
218    pub scaffold_output: Option<PathBuf>,
219    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
220    /// desired binding field name. Applied after automatic keyword escaping.
221    #[serde(default)]
222    pub rename_fields: HashMap<String, String>,
223    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
224    /// commands across all pipelines (lint, test, build, etc.).
225    #[serde(default)]
226    pub run_wrapper: Option<String>,
227    /// Extra paths to append to default lint commands (format, check, typecheck).
228    #[serde(default)]
229    pub extra_lint_paths: Vec<String>,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize)]
233pub struct RubyConfig {
234    pub gem_name: Option<String>,
235    pub stubs: Option<StubsConfig>,
236    /// Per-language feature override. When set, these features are used instead of
237    /// `[crate] features` for this language's binding crate.
238    #[serde(default)]
239    pub features: Option<Vec<String>>,
240    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
241    /// When set, this takes priority over the IR type-level serde_rename_all.
242    #[serde(default)]
243    pub serde_rename_all: Option<String>,
244    /// Functions to exclude from Ruby binding generation.
245    #[serde(default)]
246    pub exclude_functions: Vec<String>,
247    /// Types to exclude from Ruby binding generation.
248    #[serde(default)]
249    pub exclude_types: Vec<String>,
250    /// Additional Cargo dependencies for this language's binding crate only.
251    #[serde(default)]
252    pub extra_dependencies: HashMap<String, toml::Value>,
253    /// Override the scaffold output directory for this language's Cargo.toml and package files.
254    #[serde(default)]
255    pub scaffold_output: Option<PathBuf>,
256    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
257    /// desired binding field name. Applied after automatic keyword escaping.
258    #[serde(default)]
259    pub rename_fields: HashMap<String, String>,
260    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
261    /// commands across all pipelines (lint, test, build, etc.).
262    #[serde(default)]
263    pub run_wrapper: Option<String>,
264    /// Extra paths to append to default lint commands (format, check, typecheck).
265    #[serde(default)]
266    pub extra_lint_paths: Vec<String>,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct PhpConfig {
271    pub extension_name: Option<String>,
272    /// Cargo crate name for the PHP binding (e.g. `"ts-pack-core-php"`).
273    /// Used to derive the shared library filename in the e2e test runner.
274    /// When absent, the lib name is derived from `extension_name` by appending `_php`.
275    #[serde(default)]
276    pub cargo_crate_name: Option<String>,
277    /// Override the PHP namespace used for class registration and PSR-4 autoloading.
278    ///
279    /// When set, this value is used verbatim as the PHP namespace (e.g. `"HtmlToMarkdown"`).
280    /// When absent, the namespace is derived from `extension_name` by splitting on `_` and
281    /// converting each segment to PascalCase (e.g. `html_to_markdown` → `Html\To\Markdown`).
282    #[serde(default)]
283    pub namespace: Option<String>,
284    /// Feature gate for ext-php-rs (default: "extension-module").
285    /// All generated code is wrapped in `#[cfg(feature = "...")]`.
286    #[serde(default)]
287    pub feature_gate: Option<String>,
288    /// Output directory for generated PHP facade / stubs (e.g., `packages/php/src/`).
289    #[serde(default)]
290    pub stubs: Option<StubsConfig>,
291    #[serde(default)]
292    pub features: Option<Vec<String>>,
293    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
294    /// When set, this takes priority over the IR type-level serde_rename_all.
295    #[serde(default)]
296    pub serde_rename_all: Option<String>,
297    /// Functions to exclude from PHP binding generation.
298    #[serde(default)]
299    pub exclude_functions: Vec<String>,
300    /// Types to exclude from PHP binding generation.
301    #[serde(default)]
302    pub exclude_types: Vec<String>,
303    /// Additional Cargo dependencies for this language's binding crate only.
304    #[serde(default)]
305    pub extra_dependencies: HashMap<String, toml::Value>,
306    /// Override the scaffold output directory for this language's Cargo.toml and package files.
307    #[serde(default)]
308    pub scaffold_output: Option<PathBuf>,
309    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
310    /// desired binding field name. Applied after automatic keyword escaping.
311    #[serde(default)]
312    pub rename_fields: HashMap<String, String>,
313    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
314    /// commands across all pipelines (lint, test, build, etc.).
315    #[serde(default)]
316    pub run_wrapper: Option<String>,
317    /// Extra paths to append to default lint commands (format, check, typecheck).
318    #[serde(default)]
319    pub extra_lint_paths: Vec<String>,
320}
321
322#[derive(Debug, Clone, Serialize, Deserialize)]
323pub struct ElixirConfig {
324    pub app_name: Option<String>,
325    #[serde(default)]
326    pub features: Option<Vec<String>>,
327    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
328    /// When set, this takes priority over the IR type-level serde_rename_all.
329    #[serde(default)]
330    pub serde_rename_all: Option<String>,
331    /// Functions to exclude from Elixir NIF generation.
332    #[serde(default)]
333    pub exclude_functions: Vec<String>,
334    /// Types to exclude from Elixir NIF generation.
335    #[serde(default)]
336    pub exclude_types: Vec<String>,
337    /// Additional Cargo dependencies for this language's binding crate only.
338    #[serde(default)]
339    pub extra_dependencies: HashMap<String, toml::Value>,
340    /// Override the scaffold output directory for this language's Cargo.toml and package files.
341    #[serde(default)]
342    pub scaffold_output: Option<PathBuf>,
343    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
344    /// desired binding field name. Applied after automatic keyword escaping.
345    #[serde(default)]
346    pub rename_fields: HashMap<String, String>,
347    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
348    /// commands across all pipelines (lint, test, build, etc.).
349    #[serde(default)]
350    pub run_wrapper: Option<String>,
351    /// Extra paths to append to default lint commands (format, check, typecheck).
352    #[serde(default)]
353    pub extra_lint_paths: Vec<String>,
354    /// Functions that should be scheduled on the dirty CPU scheduler.
355    /// HTML parsing and other CPU-intensive NIFs should be listed here to avoid
356    /// blocking BEAM scheduler threads.
357    #[serde(default)]
358    pub cpu_bound_functions: Vec<String>,
359}
360
361#[derive(Debug, Clone, Serialize, Deserialize)]
362pub struct WasmConfig {
363    #[serde(default)]
364    pub exclude_functions: Vec<String>,
365    #[serde(default)]
366    pub exclude_types: Vec<String>,
367    #[serde(default)]
368    pub type_overrides: HashMap<String, String>,
369    #[serde(default)]
370    pub features: Option<Vec<String>>,
371    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
372    /// When set, this takes priority over the IR type-level serde_rename_all.
373    #[serde(default)]
374    pub serde_rename_all: Option<String>,
375    /// Prefix for generated type names (e.g. "Wasm" produces `WasmConversionOptions`).
376    /// Defaults to `"Wasm"`.
377    #[serde(default)]
378    pub type_prefix: Option<String>,
379    /// Functions to exclude from the public TypeScript re-export (index.ts) while still
380    /// generating the Rust binding. Use this when a custom module provides a wrapper.
381    #[serde(default)]
382    pub exclude_reexports: Vec<String>,
383    /// Wide-character C functions to shim for WASM external scanner interop.
384    #[serde(default)]
385    pub env_shims: Vec<String>,
386    /// Additional Cargo dependencies for the WASM binding crate only.
387    #[serde(default)]
388    pub extra_dependencies: HashMap<String, toml::Value>,
389    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
390    /// desired binding field name. Applied after automatic keyword escaping.
391    #[serde(default)]
392    pub rename_fields: HashMap<String, String>,
393    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
394    /// commands across all pipelines (lint, test, build, etc.).
395    #[serde(default)]
396    pub run_wrapper: Option<String>,
397    /// Extra paths to append to default lint commands (format, check, typecheck).
398    #[serde(default)]
399    pub extra_lint_paths: Vec<String>,
400    /// Override the core Cargo dependency name and path for the WASM binding crate.
401    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
402    /// `../<override>`) instead of the umbrella `[crate.name]`. Use this to point
403    /// the WASM binding at a wasm-safe sub-crate while other languages keep the
404    /// facade. Defaults to unset.
405    #[serde(default)]
406    pub core_crate_override: Option<String>,
407    /// Keys to subtract from the merged `extra_dependencies` set for this
408    /// language only. Useful when `[crate.extra_dependencies]` lists sibling
409    /// crates that the WASM target cannot link.
410    #[serde(default)]
411    pub exclude_extra_dependencies: Vec<String>,
412    /// Hand-written Rust modules to declare in the generated lib.rs with `pub mod <name>;`
413    /// and re-export with `pub use <name>::*;`. Separate from `[custom_modules].wasm` which
414    /// only adds TypeScript `export *` re-exports. Use this for Rust-side dispatch/glue modules.
415    #[serde(default)]
416    pub custom_rust_modules: Vec<String>,
417    /// Per-type field exclusions for the generated From impls and binding struct.
418    /// Key is the type name (e.g. "ServerConfig"), value is a list of field names to skip.
419    /// Use when source fields are gated behind `#[cfg(not(target_arch = "wasm32"))]` and
420    /// therefore don't exist in the wasm32 compilation environment.
421    #[serde(default)]
422    pub exclude_fields: HashMap<String, Vec<String>>,
423    /// Source crate names whose types are re-exported by the `core_crate_override`
424    /// crate. References to `<original_crate>::TypeName` in generated code are
425    /// rewritten to `<override_crate>::TypeName`. Only meaningful when
426    /// `core_crate_override` is set.
427    /// Example: with `core_crate_override = "mylib-http"`, setting
428    /// `source_crate_remaps = ["mylib-core", "mylib"]` rewrites
429    /// `mylib_core::Method` and `mylib::Method` references to
430    /// `mylib_http::Method` (assumes `mylib-http` re-exports them via
431    /// `pub use mylib_core::*`).
432    #[serde(default)]
433    pub source_crate_remaps: Vec<String>,
434}
435
436#[derive(Debug, Clone, Serialize, Deserialize)]
437pub struct FfiConfig {
438    pub prefix: Option<String>,
439    #[serde(default = "default_error_style")]
440    pub error_style: String,
441    pub header_name: Option<String>,
442    /// Native library name for Go cgo/Java Panama/C# P/Invoke (e.g., "ts_pack_ffi").
443    /// Defaults to `{prefix}_ffi`.
444    #[serde(default)]
445    pub lib_name: Option<String>,
446    /// If true, generate visitor/callback FFI support.
447    #[serde(default)]
448    pub visitor_callbacks: bool,
449    #[serde(default)]
450    pub features: Option<Vec<String>>,
451    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
452    /// When set, this takes priority over the IR type-level serde_rename_all.
453    #[serde(default)]
454    pub serde_rename_all: Option<String>,
455    /// Functions to exclude from FFI binding generation.
456    #[serde(default)]
457    pub exclude_functions: Vec<String>,
458    /// Types to exclude from FFI binding generation.
459    #[serde(default)]
460    pub exclude_types: Vec<String>,
461    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
462    /// desired binding field name. Applied after automatic keyword escaping.
463    #[serde(default)]
464    pub rename_fields: HashMap<String, String>,
465    /// Rust expression used to construct an error value of this crate's
466    /// `error_type` from a runtime `String` message inside generated FFI
467    /// trait-bridge plugin shims (`plugin_impl_initialize`, `plugin_impl_shutdown`).
468    ///
469    /// The expression has access to a local variable `msg: String` containing
470    /// the underlying error message and is interpolated verbatim. Example
471    /// values:
472    ///
473    /// ```toml
474    /// # downstream whose error type has a struct variant with two fields:
475    /// plugin_error_constructor = """
476    /// kreuzberg::KreuzbergError::Plugin { message: msg, plugin_name: String::new() }
477    /// """
478    ///
479    /// # downstream whose error type implements `From<String>`:
480    /// plugin_error_constructor = "MyError::from(msg)"
481    /// ```
482    ///
483    /// Defaults to `None`. When unset, the plugin shim still emits — backends
484    /// fall back to a `format!("{}: {}", prefix, msg)`-style construction via
485    /// the configured `error_constructor`. Downstreams that don't expose
486    /// trait-bridged plugins can ignore this knob entirely.
487    #[serde(default)]
488    pub plugin_error_constructor: Option<String>,
489}
490
491fn default_error_style() -> String {
492    "last_error".to_string()
493}
494
495#[derive(Debug, Clone, Serialize, Deserialize)]
496pub struct GoConfig {
497    pub module: Option<String>,
498    /// Override the Go package name (default: derived from module path)
499    pub package_name: Option<String>,
500    #[serde(default)]
501    pub features: Option<Vec<String>>,
502    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
503    /// When set, this takes priority over the IR type-level serde_rename_all.
504    #[serde(default)]
505    pub serde_rename_all: Option<String>,
506    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
507    /// desired binding field name. Applied after automatic keyword escaping.
508    #[serde(default)]
509    pub rename_fields: HashMap<String, String>,
510    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
511    /// commands across all pipelines (lint, test, build, etc.).
512    #[serde(default)]
513    pub run_wrapper: Option<String>,
514    /// Extra paths to append to default lint commands (format, check, typecheck).
515    #[serde(default)]
516    pub extra_lint_paths: Vec<String>,
517}
518
519#[derive(Debug, Clone, Serialize, Deserialize)]
520pub struct JavaConfig {
521    pub package: Option<String>,
522    /// Override the Maven `<groupId>` emitted by alef-scaffold and alef-e2e. When unset,
523    /// `java_group_id()` falls back to the Java `package` value. Set this when the
524    /// published Maven coords differ from the Java package path (e.g. group
525    /// `dev.kreuzberg`, package `dev.kreuzberg.htmltomarkdown`).
526    #[serde(default)]
527    pub group_id: Option<String>,
528    /// Override the Maven `<artifactId>` emitted by alef-scaffold and alef-e2e. When
529    /// unset, defaults to the crate name (the `[[crates]] name = "..."`). Set this when
530    /// the published artifactId differs from the source crate name (e.g. crate
531    /// `html-to-markdown-rs` published as `html-to-markdown`).
532    #[serde(default)]
533    pub artifact_id: Option<String>,
534    #[serde(default = "default_java_ffi_style")]
535    pub ffi_style: String,
536    #[serde(default)]
537    pub features: Option<Vec<String>>,
538    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
539    /// When set, this takes priority over the IR type-level serde_rename_all.
540    #[serde(default)]
541    pub serde_rename_all: Option<String>,
542    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
543    /// desired binding field name. Applied after automatic keyword escaping.
544    #[serde(default)]
545    pub rename_fields: HashMap<String, String>,
546    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
547    /// commands across all pipelines (lint, test, build, etc.).
548    #[serde(default)]
549    pub run_wrapper: Option<String>,
550    /// Extra paths to append to default lint commands (format, check, typecheck).
551    /// Ignored when project_file is set.
552    #[serde(default)]
553    pub extra_lint_paths: Vec<String>,
554    /// Project file for Maven/Gradle (e.g., "pom.xml", "build.gradle"). When set, default
555    /// lint/build/test commands target this file instead of the output directory.
556    #[serde(default)]
557    pub project_file: Option<String>,
558}
559
560fn default_java_ffi_style() -> String {
561    "panama".to_string()
562}
563
564/// Target platform for Kotlin code generation.
565///
566/// - `"jvm"` (default): emits source consuming the Java/Panama FFM facade.
567/// - `"native"`: emits Kotlin/Native source consuming the cbindgen C FFI library.
568/// - `"multiplatform"`: reserved for the KMP stage (Phase 3 follow-up).
569#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
570#[serde(rename_all = "lowercase")]
571pub enum KotlinTarget {
572    #[default]
573    Jvm,
574    Native,
575    // Multiplatform — Phase 3 KMP stage; placeholder so the enum is forward-compatible.
576    Multiplatform,
577}
578
579#[derive(Debug, Clone, Serialize, Deserialize)]
580pub struct KotlinConfig {
581    pub package: Option<String>,
582    #[serde(default)]
583    pub features: Option<Vec<String>>,
584    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
585    /// When set, this takes priority over the IR type-level serde_rename_all.
586    #[serde(default)]
587    pub serde_rename_all: Option<String>,
588    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
589    /// desired binding field name. Applied after automatic keyword escaping.
590    #[serde(default)]
591    pub rename_fields: HashMap<String, String>,
592    /// Functions to exclude from Kotlin binding generation.
593    #[serde(default)]
594    pub exclude_functions: Vec<String>,
595    /// Types to exclude from Kotlin binding generation.
596    #[serde(default)]
597    pub exclude_types: Vec<String>,
598    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
599    /// commands across all pipelines (lint, test, build, etc.).
600    #[serde(default)]
601    pub run_wrapper: Option<String>,
602    /// Extra paths to append to default lint commands (format, check, typecheck).
603    #[serde(default)]
604    pub extra_lint_paths: Vec<String>,
605    /// Target platform for Kotlin output. `"jvm"` (default) emits source consuming
606    /// the Java/Panama FFM facade; `"native"` emits Kotlin/Native source consuming
607    /// the cbindgen C FFI library. `"multiplatform"` is reserved for the KMP stage.
608    #[serde(default)]
609    pub target: KotlinTarget,
610    /// Emission mode controlling which Kotlin project layout is generated.
611    ///
612    /// Accepted values:
613    /// - `"jvm"` (default) — standard JVM-only project under `packages/kotlin/`
614    /// - `"kmp"` — Kotlin Multiplatform project under `packages/kotlin-mpp/`
615    /// - `"android"` — Android library project under `packages/kotlin-android/`
616    ///
617    /// When `None`, defaults to `"jvm"`.
618    #[serde(default)]
619    pub mode: Option<String>,
620}
621
622/// Dart bridging style: FRB (default) or raw `dart:ffi`.
623#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
624#[serde(rename_all = "lowercase")]
625pub enum DartStyle {
626    /// flutter_rust_bridge — emits a Rust crate plus Dart wrappers using
627    /// FRB-generated bridge symbols. Default.
628    #[default]
629    Frb,
630    /// Raw `dart:ffi` over the cbindgen C ABI — emits Dart-only source that
631    /// loads the shared library at runtime. Cheaper to ship; loses FRB's
632    /// async ergonomics and freezed-style data classes.
633    Ffi,
634}
635
636#[derive(Debug, Clone, Serialize, Deserialize)]
637pub struct GleamConfig {
638    pub app_name: Option<String>,
639    /// Erlang atom name for @external(erlang, "<nif>", ...) lookups (e.g., "my_app_nif").
640    /// Defaults to the app_name.
641    #[serde(default)]
642    pub nif_module: Option<String>,
643    #[serde(default)]
644    pub features: Option<Vec<String>>,
645    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
646    /// When set, this takes priority over the IR type-level serde_rename_all.
647    #[serde(default)]
648    pub serde_rename_all: Option<String>,
649    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
650    /// desired binding field name. Applied after automatic keyword escaping.
651    #[serde(default)]
652    pub rename_fields: HashMap<String, String>,
653    /// Functions to exclude from Gleam binding generation.
654    #[serde(default)]
655    pub exclude_functions: Vec<String>,
656    /// Types to exclude from Gleam binding generation.
657    #[serde(default)]
658    pub exclude_types: Vec<String>,
659    /// Prefix wrapper for default tool invocations.
660    #[serde(default)]
661    pub run_wrapper: Option<String>,
662    /// Extra paths to append to default lint commands.
663    #[serde(default)]
664    pub extra_lint_paths: Vec<String>,
665    /// Per-`element_type` Gleam record-constructor recipes used by the e2e
666    /// generator when emitting `json_object` arg literals. Each entry maps a
667    /// fixture-side `element_type` string (e.g. `"BatchFileItem"`) to a
668    /// structured constructor description that the codegen interpolates per
669    /// JSON-array item. Without an entry the codegen falls back to the
670    /// `json_object_wrapper` (or a plain `json_to_gleam`).
671    ///
672    /// Example:
673    ///
674    /// ```toml
675    /// [[crates.gleam.element_constructors]]
676    /// element_type = "BatchFileItem"
677    /// constructor = "kreuzberg.BatchFileItem"
678    /// [[crates.gleam.element_constructors.fields]]
679    /// gleam_field = "path"
680    /// kind = "file_path"
681    /// json_field = "path"
682    /// [[crates.gleam.element_constructors.fields]]
683    /// gleam_field = "config"
684    /// kind = "literal"
685    /// value = "option.None"
686    /// ```
687    #[serde(default)]
688    pub element_constructors: Vec<GleamElementConstructor>,
689    /// Optional Gleam expression template used to wrap `json_object` arg
690    /// values when no `element_type` recipe matches. The placeholder
691    /// `{json}` is replaced with a Gleam string literal containing the JSON
692    /// form of the arg value, allowing the downstream's Gleam binding to do
693    /// its own parsing.
694    ///
695    /// Example:
696    ///
697    /// ```toml
698    /// [crates.gleam]
699    /// json_object_wrapper = "kreuzberg.config_from_json_string({json})"
700    /// ```
701    ///
702    /// When `None`, the codegen emits `{json}` verbatim (a plain Gleam
703    /// string), matching the iter15 default.
704    #[serde(default)]
705    pub json_object_wrapper: Option<String>,
706}
707
708/// One per-`element_type` Gleam record-constructor recipe. Keyed by the
709/// fixture-side `element_type` string and consumed by the e2e Gleam codegen
710/// when building `json_object` arg literals.
711#[derive(Debug, Clone, Serialize, Deserialize)]
712pub struct GleamElementConstructor {
713    /// Fixture-side `element_type` value this recipe applies to (e.g.
714    /// `"BatchFileItem"`).
715    pub element_type: String,
716    /// Fully-qualified Gleam constructor identifier (e.g.
717    /// `"kreuzberg.BatchFileItem"`). Emitted verbatim before the `(...)` field
718    /// list.
719    pub constructor: String,
720    /// Ordered list of fields to emit inside the constructor's `(...)` block,
721    /// in argument-position order. Each field describes how its value is
722    /// derived from the per-item JSON object.
723    pub fields: Vec<GleamElementField>,
724}
725
726/// One field inside a [`GleamElementConstructor`]'s argument list.
727///
728/// `kind` selects the source/encoding strategy:
729/// * `"file_path"` — read `json_field` from the JSON object as a string,
730///   prefix with the configured `test_documents_dir` when the value does not
731///   start with `/`, and emit as a Gleam string literal.
732/// * `"byte_array"` — read `json_field` from the JSON object as a JSON
733///   `Array(Number)` and emit as a Gleam BitArray literal `<<n1, n2, …>>`.
734/// * `"string"` — read `json_field` as a string, emit as a Gleam string
735///   literal; falls back to `default` (or empty) if missing.
736/// * `"literal"` — emit `value` verbatim (no JSON lookup). Use for
737///   constant fields like `config: option.None`.
738#[derive(Debug, Clone, Serialize, Deserialize)]
739pub struct GleamElementField {
740    /// Gleam record field name (e.g. `"path"`, `"config"`).
741    pub gleam_field: String,
742    /// Source/encoding strategy. See struct doc.
743    pub kind: String,
744    /// JSON object key to read, when `kind` is one of the JSON-driven
745    /// strategies. Required for `"file_path"`, `"byte_array"`, `"string"`;
746    /// ignored for `"literal"`.
747    #[serde(default)]
748    pub json_field: Option<String>,
749    /// Default Gleam expression when `json_field` is missing/null. Only
750    /// honoured by the `"string"` strategy today.
751    #[serde(default)]
752    pub default: Option<String>,
753    /// Verbatim Gleam expression to emit when `kind = "literal"`.
754    #[serde(default)]
755    pub value: Option<String>,
756}
757
758#[derive(Debug, Clone, Default, Serialize, Deserialize)]
759pub struct DartConfig {
760    /// Dart pub.dev package name (e.g. `"my_package"`). Used as the `name` in
761    /// `pubspec.yaml`. Defaults to a snake_case derivation of the crate name.
762    #[serde(default)]
763    pub pubspec_name: Option<String>,
764    /// Dart library name (the `library` declaration). Defaults to the pubspec name.
765    #[serde(default)]
766    pub lib_name: Option<String>,
767    /// Dart package name override (e.g. for pub.dev scoped packages).
768    #[serde(default)]
769    pub package_name: Option<String>,
770    /// Bridging style. `"frb"` (default) uses flutter_rust_bridge; `"ffi"` emits
771    /// raw `dart:ffi` source over the cbindgen C library.
772    #[serde(default)]
773    pub style: DartStyle,
774    /// flutter_rust_bridge version to pin in generated pubspec.yaml.
775    /// Defaults to `template_versions::cargo::FLUTTER_RUST_BRIDGE` when unset.
776    #[serde(default)]
777    pub frb_version: Option<String>,
778    /// Cargo features to enable on the binding crate.
779    #[serde(default)]
780    pub features: Option<Vec<String>>,
781    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
782    #[serde(default)]
783    pub serde_rename_all: Option<String>,
784    /// Per-field name remapping. Key is `TypeName.field_name`, value is the
785    /// desired binding field name. Applied after automatic keyword escaping.
786    #[serde(default)]
787    pub rename_fields: HashMap<String, String>,
788    /// Functions to exclude from Dart binding generation.
789    #[serde(default)]
790    pub exclude_functions: Vec<String>,
791    /// Types to exclude from Dart binding generation.
792    #[serde(default)]
793    pub exclude_types: Vec<String>,
794    /// Prefix wrapper for default tool invocations.
795    #[serde(default)]
796    pub run_wrapper: Option<String>,
797    /// Extra paths to append to default lint commands.
798    #[serde(default)]
799    pub extra_lint_paths: Vec<String>,
800    /// Override the core Cargo dependency name and path for the Dart binding crate.
801    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
802    /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
803    /// Defaults to unset.
804    #[serde(default)]
805    pub core_crate_override: Option<String>,
806    /// Keys to subtract from the merged `extra_dependencies` set for this
807    /// language only.
808    #[serde(default)]
809    pub exclude_extra_dependencies: Vec<String>,
810    /// Method names whose Rust bridge body should be emitted as `unimplemented!()`.
811    ///
812    /// Use this when a function's FFI signature (e.g. nested tuples containing
813    /// `Vec<u8>`) cannot be represented across the FRB bridge at all. Consumers must
814    /// list the method names explicitly — this field has no built-in defaults so the
815    /// knob is library-agnostic.
816    ///
817    /// Example (`alef.toml`):
818    /// ```toml
819    /// [crates.dart]
820    /// stub_methods = ["batch_extract_bytes", "batch_extract_bytes_sync"]
821    /// ```
822    #[serde(default)]
823    pub stub_methods: Vec<String>,
824    /// Per-target Cargo dependency overrides for the binding crate.
825    ///
826    /// When set, the emitted `Cargo.toml` wraps the base core dependency in a
827    /// `[target.'cfg(not(<cfg>))'.dependencies]` section and adds a matching
828    /// `[target.'cfg(<cfg>)'.dependencies]` block using `override_features`
829    /// (and `default_features = false` when `override_default_features = false`).
830    /// Required when the binding has to swap the feature set on a specific
831    /// target triple, e.g. Android x86_64 dropping ORT-dependent features.
832    ///
833    /// Example (`alef.toml`):
834    /// ```toml
835    /// [[crates.dart.target_dep_overrides]]
836    /// cfg = "all(target_os = \"android\", target_arch = \"x86_64\")"
837    /// features = ["android-target"]
838    /// default_features = false
839    /// ```
840    #[serde(default)]
841    pub target_dep_overrides: Vec<DartTargetDepOverride>,
842}
843
844#[derive(Debug, Clone, Serialize, Deserialize)]
845pub struct DartTargetDepOverride {
846    /// Cargo `cfg(...)` predicate (without the `cfg(...)` wrapper). Example:
847    /// `all(target_os = "android", target_arch = "x86_64")`.
848    pub cfg: String,
849    /// Features to enable on the core dependency for this target.
850    #[serde(default)]
851    pub features: Vec<String>,
852    /// When false (default), emit `default-features = false` for this target.
853    /// When true, allow the core dep's default features through.
854    #[serde(default)]
855    pub default_features: bool,
856}
857
858#[derive(Debug, Clone, Default, Serialize, Deserialize)]
859pub struct SwiftConfig {
860    /// Swift module name (e.g. `"MyLibrary"`). Defaults to PascalCase of the crate name.
861    #[serde(default)]
862    pub module_name: Option<String>,
863    /// Swift package name. Defaults to the module name.
864    #[serde(default)]
865    pub package_name: Option<String>,
866    /// swift-bridge version. Defaults to `template_versions::cargo::SWIFT_BRIDGE` when unset.
867    #[serde(default)]
868    pub swift_bridge_version: Option<String>,
869    /// Minimum macOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_MACOS` when unset.
870    #[serde(default)]
871    pub min_macos_version: Option<String>,
872    /// Minimum iOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_IOS` when unset.
873    #[serde(default)]
874    pub min_ios_version: Option<String>,
875    /// Cargo features to enable on the binding crate.
876    #[serde(default)]
877    pub features: Option<Vec<String>>,
878    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
879    #[serde(default)]
880    pub serde_rename_all: Option<String>,
881    /// Per-field name remapping. Key is `TypeName.field_name`, value is the
882    /// desired binding field name. Applied after automatic keyword escaping.
883    #[serde(default)]
884    pub rename_fields: HashMap<String, String>,
885    /// Functions to exclude from Swift binding generation.
886    #[serde(default)]
887    pub exclude_functions: Vec<String>,
888    /// Types to exclude from Swift binding generation.
889    #[serde(default)]
890    pub exclude_types: Vec<String>,
891    /// Fields to exclude from Swift binding generation.
892    /// Format: `"TypeName.field_name"`.
893    #[serde(default)]
894    pub exclude_fields: Vec<String>,
895    /// Prefix wrapper for default tool invocations.
896    #[serde(default)]
897    pub run_wrapper: Option<String>,
898    /// Extra paths to append to default lint commands.
899    #[serde(default)]
900    pub extra_lint_paths: Vec<String>,
901    /// Override the core Cargo dependency name and path for the Swift binding crate.
902    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
903    /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
904    /// Defaults to unset.
905    #[serde(default)]
906    pub core_crate_override: Option<String>,
907    /// Keys to subtract from the merged `extra_dependencies` set for this
908    /// language only.
909    #[serde(default)]
910    pub exclude_extra_dependencies: Vec<String>,
911    /// Override the auto-generated `create_<type>(api_key, base_url)` constructor
912    /// body for opaque client types that expose methods. When set, the swift backend
913    /// emits this snippet verbatim as the function body (no implicit `Ok(...)`).
914    ///
915    /// Use this when the source crate's constructor signature differs from the
916    /// default `Type::new(api_key, base_url)` shape — e.g. liter-llm uses
917    /// `DefaultClient::new(ClientConfig, Option<&str>)` and needs to build a
918    /// `ClientConfig` from the bridge inputs first.
919    ///
920    /// The snippet is parameterised by `{type_name}` (the wrapper newtype name)
921    /// and runs in a function body with `api_key: String` and `base_url: Option<String>`
922    /// already in scope. It must return `Result<{type_name}, String>`.
923    #[serde(default)]
924    pub client_constructor_body: HashMap<String, String>,
925}
926
927#[derive(Debug, Clone, Serialize, Deserialize)]
928pub struct ZigConfig {
929    pub module_name: Option<String>,
930    #[serde(default)]
931    pub features: Option<Vec<String>>,
932    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
933    /// When set, this takes priority over the IR type-level serde_rename_all.
934    #[serde(default)]
935    pub serde_rename_all: Option<String>,
936    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
937    /// desired binding field name. Applied after automatic keyword escaping.
938    #[serde(default)]
939    pub rename_fields: HashMap<String, String>,
940    /// Functions to exclude from Zig binding generation.
941    #[serde(default)]
942    pub exclude_functions: Vec<String>,
943    /// Types to exclude from Zig binding generation.
944    #[serde(default)]
945    pub exclude_types: Vec<String>,
946    /// Prefix wrapper for default tool invocations.
947    #[serde(default)]
948    pub run_wrapper: Option<String>,
949    /// Extra paths to append to default lint commands.
950    #[serde(default)]
951    pub extra_lint_paths: Vec<String>,
952}
953
954#[derive(Debug, Clone, Serialize, Deserialize)]
955pub struct CSharpConfig {
956    pub namespace: Option<String>,
957    /// NuGet `<PackageId>` to publish under. When unset, falls back to `namespace`.
958    /// Use this when the published artifact id must differ from the C# `RootNamespace` —
959    /// e.g. when the unprefixed name is owned by a third party on nuget.org and
960    /// you publish under a vendor-prefixed id like `KreuzbergDev.<Lib>`.
961    #[serde(default)]
962    pub package_id: Option<String>,
963    pub target_framework: Option<String>,
964    #[serde(default)]
965    pub features: Option<Vec<String>>,
966    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
967    /// When set, this takes priority over the IR type-level serde_rename_all.
968    #[serde(default)]
969    pub serde_rename_all: Option<String>,
970    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
971    /// desired binding field name. Applied after automatic keyword escaping.
972    #[serde(default)]
973    pub rename_fields: HashMap<String, String>,
974    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
975    /// commands across all pipelines (lint, test, build, etc.).
976    #[serde(default)]
977    pub run_wrapper: Option<String>,
978    /// Extra paths to append to default lint commands (format, check, typecheck).
979    /// Ignored when project_file is set.
980    #[serde(default)]
981    pub extra_lint_paths: Vec<String>,
982    /// Project file for C# (e.g., "MyProject.csproj", "MySolution.sln"). When set, default
983    /// lint/build/test commands target this file instead of the output directory.
984    #[serde(default)]
985    pub project_file: Option<String>,
986    /// Functions to exclude from C# binding generation (e.g., functions not present in the
987    /// C FFI layer). Excluded functions are omitted from both NativeMethods.cs and the
988    /// wrapper class.
989    #[serde(default)]
990    pub exclude_functions: Vec<String>,
991}
992
993#[derive(Debug, Clone, Serialize, Deserialize)]
994pub struct RConfig {
995    pub package_name: Option<String>,
996    #[serde(default)]
997    pub features: Option<Vec<String>>,
998    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
999    /// When set, this takes priority over the IR type-level serde_rename_all.
1000    #[serde(default)]
1001    pub serde_rename_all: Option<String>,
1002    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1003    /// desired binding field name. Applied after automatic keyword escaping.
1004    #[serde(default)]
1005    pub rename_fields: HashMap<String, String>,
1006    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
1007    /// commands across all pipelines (lint, test, build, etc.).
1008    #[serde(default)]
1009    pub run_wrapper: Option<String>,
1010    /// Extra paths to append to default lint commands (format, check, typecheck).
1011    #[serde(default)]
1012    pub extra_lint_paths: Vec<String>,
1013}
1014
1015/// Custom modules that alef should declare (mod X;) but not generate.
1016/// These are hand-written modules imported by the generated lib.rs.
1017#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1018pub struct CustomModulesConfig {
1019    #[serde(default)]
1020    pub python: Vec<String>,
1021    #[serde(default)]
1022    pub node: Vec<String>,
1023    #[serde(default)]
1024    pub ruby: Vec<String>,
1025    #[serde(default)]
1026    pub php: Vec<String>,
1027    #[serde(default)]
1028    pub elixir: Vec<String>,
1029    #[serde(default)]
1030    pub wasm: Vec<String>,
1031    #[serde(default)]
1032    pub ffi: Vec<String>,
1033    #[serde(default)]
1034    pub go: Vec<String>,
1035    #[serde(default)]
1036    pub java: Vec<String>,
1037    #[serde(default)]
1038    pub csharp: Vec<String>,
1039    #[serde(default)]
1040    pub r: Vec<String>,
1041}
1042
1043impl CustomModulesConfig {
1044    pub fn for_language(&self, lang: Language) -> &[String] {
1045        match lang {
1046            Language::Python => &self.python,
1047            Language::Node => &self.node,
1048            Language::Ruby => &self.ruby,
1049            Language::Php => &self.php,
1050            Language::Elixir => &self.elixir,
1051            Language::Wasm => &self.wasm,
1052            Language::Ffi => &self.ffi,
1053            Language::Go => &self.go,
1054            Language::Java => &self.java,
1055            Language::Csharp => &self.csharp,
1056            Language::R => &self.r,
1057            Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
1058            Language::Kotlin | Language::Swift | Language::Dart | Language::Gleam | Language::Zig | Language::C => &[],
1059        }
1060    }
1061}
1062
1063/// Custom classes/functions from hand-written modules to register in module init.
1064#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1065pub struct CustomRegistration {
1066    #[serde(default)]
1067    pub classes: Vec<String>,
1068    #[serde(default)]
1069    pub functions: Vec<String>,
1070    #[serde(default)]
1071    pub init_calls: Vec<String>,
1072}
1073
1074/// Per-language custom registrations.
1075#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1076pub struct CustomRegistrationsConfig {
1077    #[serde(default)]
1078    pub python: Option<CustomRegistration>,
1079    #[serde(default)]
1080    pub node: Option<CustomRegistration>,
1081    #[serde(default)]
1082    pub ruby: Option<CustomRegistration>,
1083    #[serde(default)]
1084    pub php: Option<CustomRegistration>,
1085    #[serde(default)]
1086    pub elixir: Option<CustomRegistration>,
1087    #[serde(default)]
1088    pub wasm: Option<CustomRegistration>,
1089}
1090
1091impl CustomRegistrationsConfig {
1092    pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
1093        match lang {
1094            Language::Python => self.python.as_ref(),
1095            Language::Node => self.node.as_ref(),
1096            Language::Ruby => self.ruby.as_ref(),
1097            Language::Php => self.php.as_ref(),
1098            Language::Elixir => self.elixir.as_ref(),
1099            Language::Wasm => self.wasm.as_ref(),
1100            _ => None,
1101        }
1102    }
1103}