The complete public API of @lakeql/config, generated from the package's TypeScript source.
You use three functions most: defineConfig authors the config file, loadConfig loads and validates it, and createLakeQLRuntime composes the runtime that owns your data sources. The remaining exports are the config and runtime types, the AdapterRegistry, the RuntimeLifecycleManager, and the error classes thrown during loading and runtime construction.
Instance-local adapter-factory registry.
Accepts an explicit list of AdapterFactory instances at construction and provides deterministic, immutable lookup by adapter name. Each registry instance owns its own private state; concurrent runtimes never share mutable registration data.
The registry stores and returns the exact factory references supplied by the caller. It does not clone, wrap, initialize, or validate adapter-owned configuration.
Constructor
Constructs a registry from an explicit list of adapter factories.
Duplicate adapter names are rejected before any lookup can occur. The input array is defensively copied so that later mutations by the caller cannot alter the registrations.
| Name | Type |
|---|---|
| factoriesRequired | readonly AdapterFactory[] |
Adapter factories to register. Each factory’s
| |
Properties
| Name | Type |
|---|---|
| #factoriesRequired | Map<AdapterName, AdapterFactory> |
O(1) factory lookup by adapter name. | |
| #namesRequired | readonly AdapterName[] |
Registration-order name list. | |
Methods
Returns the factory registered under the given adapter name, or undefined if no factory is registered for that name.
Parameters
| Name | Type |
|---|---|
| adapterNameRequired | AdapterName |
The adapter name to look up. | |
Returns
AdapterFactory | undefinedThe registered factory, or undefined.
Returns the factory registered under the given adapter name.
This is the standard runtime-composition path: callers that expect the adapter to be present use this method and handle the structured error at a higher level.
Parameters
| Name | Type |
|---|---|
| adapterNameRequired | AdapterName |
The adapter name to look up. | |
Returns
AdapterFactoryThe registered factory. *
Returns a fresh readonly snapshot of all registered adapter names in registration order.
Mutating the returned array does not affect the registry’s internal state.
Returns
readonly AdapterName[]A new array of adapter names in the order they were registered.
Auth configuration block for the unified config.
Groups the config-level auth concerns: the global impersonation fallback and the technical-user permission rules. Request authentication (tokenResolver) and identity resolution (identityResolver) are API-server concerns configured on defineApiConfig (ApiRuntimeConfig), not here, because they run per HTTP request; permissions are declarative data and belong with the rest of the project configuration.
Properties
| Name | Type |
|---|---|
| impersonationResolver? | ImpersonationResolver |
Global fallback impersonation resolver, applied across every data source. This is the source-independent counterpart to a per-source dataSources.<source>.impersonationResolver. Resolution is two-level: for a given data source the per-source resolver takes precedence, and this global resolver is used only when that source defines none. When neither exists, the request runs with no impersonation (system user / the source’s configured service credentials). Use the per-source field to override impersonation for a specific source, and this field to apply one resolver to all sources that do not. | |
| permissions? | Permission[] |
Permission rules for technical users, defining which data sources and tables each may read and write. Declared here in defineConfig and read by the application wiring, which forwards them to the API server (defineApiConfig) where the authorization checks consume them. | |
Maps a JWT payload to a ResolvedIdentity. Can be sync or async to support custom identity providers.
Definition
(
token: JWTPayload
) => ResolvedIdentity | Promise<ResolvedIdentity>Resolves impersonation credentials for a given user and adapter context.
Definition
(context: {
currentUser: JWTPayload
isServicePrincipal: boolean
dataSource: string
adapter: string
}) => Promise<{
requestAuth?: { type: string; token: string } | undefined
options?: Record<string, unknown>
} | null>Auth and permission types for the unified LakeQL configuration.
These types are owned by @lakeql/config because they are consumed by both the API and CLI layers. They are transport-neutral — the config package does not interpret JWT, HTTP, or GraphQL details.
JWT-like payload. A plain record from a decoded token.
Definition
Record<string, unknown>Permission rule for a technical user, defining which dataSources/tables they can read and write.
Properties
| Name | Type | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| nameRequired | string | ||||||||||
Username to match against currentUser.userName. | |||||||||||
| useSystemUserRequired | boolean | ||||||||||
Whether this user’s queries run via a system user (no impersonation). | |||||||||||
| permissionsRequired | Object | ||||||||||
Read and write access rules. | |||||||||||
| |||||||||||
Permission rule entry defining catalog, schema, and table access.
Properties
| Name | Type |
|---|---|
| catalog? | string |
Optional catalog filter. If omitted, matches any catalog. | |
| schemaRequired | string |
Schema to match, or ”*“ for all schemas. | |
| tablesRequired | string[] |
Tables to match, or [”*”] for all tables in the schema. | |
Resolved identity information from a JWT token.
Properties
| Name | Type |
|---|---|
| userNameRequired | string |
The resolved user name from the token. | |
| isServicePrincipalRequired | boolean |
Whether this request originates from a Service Principal (technical user). | |
| userToken? | string |
The raw user token (for OBO flows). | |
Resolves the current user from an incoming request. Returns the JWT payload or null/undefined when unauthenticated.
Definition
(
req: Request
) => Promise<JWTPayload | null | undefined> | JWTPayload | null | undefinedComposes a LakeQLRuntime from loaded configuration, explicit adapter factories, and an auth resolver.
Construction is sequential: each configured data-source definition is resolved through the registry and its factory methods are called in order (createDataSource, createReadStrategy, optionally createWriteStrategy). The function resolves only after every configured source has been fully composed.
An empty dataSources map produces a valid empty runtime.
If composition fails after one or more data sources have been created, all previously created data sources are closed before the error propagates. Cleanup failures are attached as secondary diagnostics and never replace the primary error.
Parameters
| Name | Type |
|---|---|
| optionsRequired | CreateLakeQLRuntimeOptions |
Configuration, adapter factories, and auth resolver. | |
Returns
Promise<LakeQLRuntime>A composed runtime owning all created instances. *
Validates and normalizes a typed LakeQL configuration.
Accepts an explicit adapter list, a data-source map, and optional application-level config (auth, sourcePath). Validates registrations and individual data-source configurations, merges defaults/overrides, and returns a TypedLakeQLConfig with identity-preserved adapters and a normalized dataSources map.
This is the single point of truth (SPOT) for LakeQL configuration. Both the API and CLI consume the same config object.
This function is pure and stateless — it does not read project files, create runtime instances, or accumulate module-level state.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
TAdapters | readonly AdapterDefinition<string, any, any, any>[] | — |
Parameters
| Name | Type | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| configRequired | Object | ||||||||||||||||||
| |||||||||||||||||||
Returns
TypedLakeQLConfig<TAdapters>Manages a single active LakeQL runtime with safe reload semantics.
During reload, a new runtime is created first. The old runtime is only closed after the new one resolves successfully. If creation fails, the old runtime remains active and the construction error propagates to the caller.
If the old runtime’s close() rejects after a successful swap, the new runtime remains active and the close error propagates.
Constructor
| Name | Type |
|---|---|
| initialRuntimeRequired | LakeQLRuntime |
The first active runtime instance. | |
Properties
| Name | Type |
|---|---|
| #runtimeRequired | LakeQLRuntime |
Methods
Reloads the runtime with new configuration.
Creates a new runtime before closing the old one. If creation fails, the old runtime remains active and the error propagates. If the old runtime’s close() rejects after a successful swap, the new runtime is still exposed as active and the close error propagates to the caller.
Parameters
| Name | Type |
|---|---|
| optionsRequired | CreateLakeQLRuntimeOptions |
New configuration for the replacement runtime. | |
Returns
Promise<LakeQLRuntime>The new active runtime. *
Thrown during configuration validation when an adapter definition’s adapterName does not strictly equal its factory.adapterName.
Exposes both names for programmatic handling and includes them in the error message for diagnostics.
Constructor
| Name | Type |
|---|---|
| definitionNameRequired | AdapterName |
The adapterName from the adapter definition. | |
| factoryNameRequired | AdapterName |
The adapterName from the adapter’s factory. | |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| definitionNameRequired | AdapterName |
The adapter name declared on the definition object. | |
| factoryNameRequired | AdapterName |
The adapter name reported by the factory. | |
Thrown during defineConfig() processing when a named data source fails validation, merge, adapter resolution, or opaque-value detection.
Carries the affected source name, the optional adapter name, and the original cause for programmatic handling and diagnostics. The cause value is preserved unchanged — non-Error values (strings, null, undefined, numbers, symbols) are never normalized or coerced.
Constructor
| Name | Type |
|---|---|
| messageRequired | string |
A human-readable description of the configuration failure. | |
| sourceNameRequired | string |
The data-source name that triggered the failure. | |
| adapterNameRequired | string | undefined |
The adapter name for the failing source, or
| |
| causeRequired | unknown |
The original thrown value. Preserved as-is without
| |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| sourceNameRequired | string |
The configured data-source name that triggered the failure. | |
| adapterNameRequired | string | undefined |
The adapter name associated with the failing data source, or undefined when the adapter could not be resolved (e.g. unknown adapter reference). | |
| causeRequired | unknown |
The original thrown value that caused this configuration failure. | |
Thrown during registry construction when two or more adapter factories share the same adapter name.
Exposes the conflicting name for programmatic handling and includes it in the error message for diagnostics.
Constructor
| Name | Type |
|---|---|
| adapterNameRequired | AdapterName |
The conflicting adapter name detected during
| |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| adapterNameRequired | AdapterName |
The adapter name that was registered more than once. | |
Thrown during runtime composition when a factory method (createDataSource, createReadStrategy, or createWriteStrategy) fails for a configured data-source definition.
Exposes the source name, adapter name, and original error for programmatic handling and diagnostics.
Constructor
| Name | Type |
|---|---|
| sourceNameRequired | string |
The configured data-source name that triggered the
| |
| adapterNameRequired | AdapterName |
The adapter name whose factory method threw. | |
| causeRequired | unknown |
The original error thrown by the factory method. | |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| sourceNameRequired | string |
The configured data-source name that failed during composition. | |
| adapterNameRequired | AdapterName |
The adapter name associated with the failing factory. | |
| causeRequired | unknown |
The original error thrown by the factory method. | |
Thrown by getOrThrow() when the requested adapter name is not present in the registry.
Exposes the requested name and a snapshot of all registered adapter names for programmatic handling and diagnostics.
Constructor
| Name | Type |
|---|---|
| adapterNameRequired | AdapterName |
The adapter name that was not found in the registry. | |
| registeredAdapterNamesRequired | readonly AdapterName[] |
All adapter names currently registered,
| |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| adapterNameRequired | AdapterName |
The adapter name that was requested but not found. | |
| registeredAdapterNamesRequired | readonly AdapterName[] |
Immutable snapshot of registered adapter names at the time of the error. | |
Thrown by runtime accessors (getDataSource, getReadStrategy, getWriteStrategy) when the requested source name is not present in the runtime’s configured data sources.
Exposes the requested name and a frozen snapshot of all configured source names for programmatic handling and diagnostics.
Constructor
| Name | Type |
|---|---|
| sourceNameRequired | string |
The source name that was not found in the runtime. | |
| configuredSourceNamesRequired | readonly string[] |
All source names configured in the
| |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| sourceNameRequired | string |
The data-source name that was requested but not found. | |
| configuredSourceNamesRequired | readonly string[] |
Immutable snapshot of configured data-source names at the time of the error. Subsequent mutations to the runtime’s internal collection do not affect this field. | |
Thrown by getWriteStrategy() when the requested data source exists in the runtime but was configured without a writeConfig field.
Exposes the source name for programmatic handling and includes it in the error message for diagnostics.
Constructor
| Name | Type |
|---|---|
| sourceNameRequired | string |
The configured source name whose definition does
| |
Properties
| Name | Type |
|---|---|
| nameRequired | unknown |
| sourceNameRequired | string |
The configured data-source name that has no write strategy. | |
Resolves, validates, and normalizes a LakeQL project configuration file.
Uses c12 to locate a lakeql.config.{ts,mts,js,mjs} file within the specified working directory. The resolved module’s default export is validated and normalized into a LoadedLakeQLProject containing serializable data-source definitions and non-serializable adapter factories.
This function is stateless: it maintains no module-level config state and each call returns an independent result.
Parameters
| Name | Type |
|---|---|
| options? | LoadConfigOptions |
Resolution options containing the working directory. {} | |
Returns
Promise<LoadedLakeQLProject>A normalized project config with separate config and adapters fields. *
Options accepted by loadConfig().
Properties
| Name | Type |
|---|---|
| cwd? | string |
Working directory in which to search for the project config file. | |
Typed adapter definition that combines an adapter’s public name, factory reference, registration options, validation, and optional custom merge logic.
Adapter packages expose definitions implementing this interface to register with defineConfig(). The definition provides the type information necessary for TypeScript inference of data-source configuration without requiring global module augmentation.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
TName | string | — |
TDataSourceConfig | — | — |
TRegistrationOptions | — | unknown |
TWriteConfig | — | never |
Properties
| Name | Type |
|---|---|
| adapterNameRequired | TName |
Unique adapter name matching factory.adapterName. | |
| factoryRequired | AdapterFactory |
The AdapterFactory reference for downstream runtime composition. | |
| registrationOptions? | TRegistrationOptions |
Optional adapter-level default options applied to all data sources using this adapter. | |
| mergeDataSourceConfig? | ( registrationOptions: TRegistrationOptions | undefined, sourceConfig: DataSourceConfigInput<TDataSourceConfig, TRegistrationOptions> ) => MergedDataSourceConfig<TDataSourceConfig> |
Optional custom merge function that owns the entire merge for a data source. Called synchronously before validateDataSourceConfig(). When declared, the default shallow-merge path is skipped entirely. | |
Input shape passed to an adapter’s mergeDataSourceConfig() function.
Contains the data-source connection value, optional write configuration, and optional overrides scoped to the adapter’s registration options.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
TConnection | — | — |
TRegistrationOptions | — | unknown |
The adapter’s registration-level options type. | ||
Properties
| Name | Type |
|---|---|
| connectionRequired | TConnection |
The data-source connection value before merge processing. | |
| writeConfig? | unknown |
Optional adapter-owned write configuration passed through unchanged. | |
| overrides? | OverridesFor<TRegistrationOptions> |
Optional overrides scoped to registration-level option fields. Typed via | |
Typed input shape for a single data source within defineConfig().
Uses distributive conditional inference over the adapter tuple to narrow adapter, connection, and overrides based on the selected adapter. This is the INPUT shape accepted by the dataSources map; the normalized output shape (NormalizedDataSourceEntry) omits overrides.
Definition
TAdapter extends AdapterDefinition<
infer TName,
infer TConnection,
infer TOptions,
infer TWriteConfig
>
? {
/** The adapter name selecting which registered adapter handles this data source. */
adapter: TName
/** The adapter-specific connection configuration value. */
connection: TConnection
/** Optional adapter-owned write configuration, typed per adapter. */
writeConfig?: TWriteConfig
/**
* Optional overrides scoped to the adapter's registration-level option
* fields.
*
* Typed via {@link OverridesFor}: an adapter with real registration
* options accepts `Partial<TOptions>`, while an adapter that declares
* no options (`TOptions` is `unknown`, `never`, or an empty object)
* collapses this field to `never` so assigning an arbitrary object is a
* type error rather than a silent no-op.
*/
overrides?: OverridesFor<TOptions>
/** Optional per-data-source impersonation resolver, taking precedence over the global one. */
impersonationResolver?: ImpersonationResolver
/**
* Optional prefix prepended to every generated GraphQL name for this
* source, case-normalized per target context at generation time. Used
* to disambiguate sources that expose same-named tables. Unset leaves
* generated names unchanged.
*/
namePrefix?: string
/** Optional page size used when a request omits `perPage`. Must be a positive integer. */
defaultPerPage?: number
/** Optional upper bound a request's `perPage` may not exceed. Must be a positive integer. */
maxRecordsPerPage?: number
}
: neverConstrains the dataSources map so that each entry’s adapter field is limited to the union of registered adapter names, and config fields are narrowed to the corresponding adapter’s types.
Result returned by an adapter’s mergeDataSourceConfig() function.
Contains the merged connection value and optional write configuration. The connection is subsequently passed to validateDataSourceConfig().
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
TConnection | — | — |
The adapter-owned connection configuration type. | ||
Properties
| Name | Type |
|---|---|
| connectionRequired | TConnection |
The merged connection value ready for validation. | |
| writeConfig? | unknown |
Optional adapter-owned write configuration after merge processing. | |
Normalized output shape for a single data source after merge processing.
Unlike the input DataSourceEntry, this type omits overrides (consumed during merge) and marks all fields readonly. It is used inside TypedLakeQLConfig as the value type of the normalized dataSources map.
Definition
TAdapter extends AdapterDefinition<
infer TName,
infer TConnection,
infer _TOptions,
infer TWriteConfig
>
? {
/** The adapter name that processed this data source. */
readonly adapter: TName
/** The merged connection value after defaults/overrides processing. */
readonly connection: TConnection
/** Optional adapter-owned write configuration, typed per adapter. */
readonly writeConfig?: TWriteConfig
/** Optional per-data-source impersonation resolver, taking precedence over the global one. */
readonly impersonationResolver?: ImpersonationResolver
/** Optional prefix prepended to every generated GraphQL name for this source. */
readonly namePrefix?: string
/** The resolved per-data-source paging limits. */
readonly paging: ResolvedPaging
}
: neverReadonly record mapping data-source names to their normalized entries.
This is the OUTPUT type used in TypedLakeQLConfig.dataSources, distinct from the input DataSourcesFor type which carries overrides.
Definition
Readonly<Record<string, NormalizedDataSourceEntry<TAdapters[number]>>>Resolved per-data-source paging limits produced by resolvePaging.
Extends ReadStrategyPaging so resolved values flow to the adapter factory’s createReadStrategy paging argument with compile-time assignability and no cast. The named interface is retained (rather than a type alias) so it reads as a distinct, documented config-layer type.
The return type of defineConfig().
Contains the identity-preserved adapter definitions, a normalized readonly data-sources map, and the unified application-level config fields (auth, sourcePath) shared by API and CLI.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
TAdapters | readonly AdapterDefinition<string, any, any, any>[] | — |
The readonly tuple of registered AdapterDefinition objects. | ||
Properties
| Name | Type | ||||||
|---|---|---|---|---|---|---|---|
| adaptersRequired | TAdapters | ||||||
The registered adapter definitions, identity-preserved in registration order. | |||||||
| dataSourcesRequired | NormalizedDataSourcesFor<TAdapters> | ||||||
Normalized data-source map with merged connections and no overrides. | |||||||
| sourcePathRequired | string | ||||||
Base path for code generation (schemas, config-registry, etc.). The CLI resolves a relative value against the command invocation directory (INIT_CWD when run via a package-manager script, otherwise the current working directory). "." | |||||||
| auth? | AuthConfig | ||||||
Auth configuration grouping the global impersonation fallback and technical-user permission rules. Used by the API layer at runtime. | |||||||
| paging? | Object | ||||||
Config-level paging defaults applied to every data source that does not supply its own per-source override. Each field must be a positive integer. | |||||||
| |||||||
Options accepted by createLakeQLRuntime() to compose a runtime from loaded configuration, explicit adapter factories, and an auth resolver.
Properties
| Name | Type |
|---|---|
| configRequired | LoadedLakeQLConfig |
Loaded configuration containing named data-source definitions. | |
| adaptersRequired | readonly AdapterFactory[] |
Adapter factories used to construct data sources and strategies. | |
| resolveAuthRequired | ResolveAuth |
Auth resolution function injected into read strategies. Called during request processing to resolve credentials from the request context for a given data-source name. | |
A composed LakeQL runtime that owns data-source instances, read strategies, and write strategies created during composition.
Accessors return the exact instances created for each configured source name. The runtime is responsible for closing its owned data sources through LakeQLRuntime.close.
Properties
| Name | Type |
|---|---|
| getDataSourceRequired | (name: string) => DataSource |
Returns the data-source instance for the given configured name. | |
| getReadStrategyRequired | (name: string) => DataSourceReadStrategy |
Returns the read-strategy instance for the given configured name. | |
| getWriteStrategyRequired | (name: string) => DataSourceWriteStrategy |
Returns the write-strategy instance for the given configured name. | |
| closeRequired | () => Promise<void> |
Releases all resources held by this runtime. Invokes close() on every owned data-source instance exactly once. Subsequent calls return the same promise without closing data sources again. | |
Normalized configuration containing named data-source definitions and application-level settings.
Returned as part of a LoadedLakeQLProject from loadConfig(). The config is serializable data-source metadata; non-serializable runtime objects live in connection and writeConfig opaque fields.
Properties
| Name | Type | ||||||
|---|---|---|---|---|---|---|---|
| dataSourcesRequired | Readonly<Record<string, RuntimeDataSourceDefinition>> | ||||||
Named source definitions available to one runtime instance. | |||||||
| sourcePathRequired | string | ||||||
Base path for code generation (schemas, config-registry, etc.). "." | |||||||
| auth? | AuthConfig | ||||||
Auth configuration grouping the global impersonation fallback and technical-user permission rules. Passed through from defineConfig() without interpretation. | |||||||
| paging? | Object | ||||||
Config-level paging defaults applied to data sources that do not supply their own per-source override. | |||||||
| |||||||
Complete project-level result returned by loadConfig().
Separates the serializable data-source definitions from the non-serializable adapter factory list exported by the project config module.
Properties
| Name | Type |
|---|---|
| configRequired | LoadedLakeQLConfig |
Normalized data-source definitions. | |
| adaptersRequired | readonly AdapterFactory[] |
Adapter factories exported by the project config module. | |
A single data-source entry within a loaded configuration.
Each definition identifies the adapter that owns it and carries opaque connection and write configuration values that are passed through to the adapter factory without interpretation.
Properties
| Name | Type |
|---|---|
| adapterRequired | AdapterName |
Open name of the factory that owns this definition. | |
| connectionRequired | unknown |
Adapter-owned connection configuration passed only to createDataSource(). | |
| writeConfig? | unknown |
Optional adapter-owned write configuration passed only to createWriteStrategy(). | |
| impersonationResolver? | ImpersonationResolver |
Optional per-data-source impersonation resolver. Takes precedence over the global auth.impersonationResolver when resolving request-scoped credentials for this source. Passed through as an opaque runtime object; never cloned or serialized. | |
| namePrefix? | string |
Optional prefix prepended to every generated GraphQL name for this source. Case-normalized per target context at generation time (type names in PascalCase, query/mutation names in lowerCamelCase). Used to disambiguate sources that expose same-named tables. Unset leaves generated names unchanged. | |
| pagingRequired | ResolvedPaging |
The resolved per-data-source paging limits passed to the read strategy. | |