import * as spec from '@jsii/spec'; import { Worker } from 'worker_threads'; /** * Version of the on-disk runtime index format. * * Bump this whenever the manifest, index, or defs layout written by * {@link buildIndex} changes in a way that an older reader could not understand * (or an older writer would produce incorrectly). The version is encoded both * in the file *names* and in a `version` field *inside* the manifest: * * - The names (`.jsii.runtime.v{VERSION}.json`, ...) let a single cache entry * shared by multiple jsii runtimes of different versions at the same time keep * each version's own files side-by-side without clobbering. A runtime simply * never reads a manifest whose name encodes a version other than its own. * - The `version` field is an integrity check that a file's contents match what * its name claims. * * The format is a private, best-effort, on-disk cache owned exclusively by this * package. It is not part of the published `.jsii` assembly specification and * carries no backwards-compatibility guarantee. */ export declare const RUNTIME_INDEX_VERSION = 1; /** Data handed to the index-builder worker via {@link Worker} `workerData`. */ export interface IndexBuilderWorkerData { readonly packageDir: string; readonly supportedFeatures: spec.JsiiFeature[]; } /** * Accessor for the types of a loaded assembly. * * There are two implementations: {@link EagerTypes}, backed by the fully parsed * `types` map of an assembly, and {@link LazyTypes}, which parses each type * definition on first access from a pre-built index. Both expose the same * surface so the kernel does not care which one it is holding. */ export interface AssemblyTypes { /** The total number of types declared by the assembly. */ readonly count: number; /** Iterates the fully-qualified names of all declared types. */ fqns(): Iterable; /** * Iterates `[fqn, kind]` for every declared type, by row, without requiring a * name lookup. Preferred over `fqns()` + `kindOf()` when visiting every type. */ entries(): Iterable; /** * Returns the {@link spec.TypeKind} of a type without materializing its full * definition, or `undefined` if the FQN is unknown. */ kindOf(fqn: string): spec.TypeKind | undefined; /** * Returns the full definition of a type, or `undefined` if the FQN is * unknown. Callers must not mutate the returned object. */ get(fqn: string): spec.Type | undefined; } /** * Assembly metadata as returned by {@link loadRuntimeAssembly}. * * Narrower than {@link spec.Assembly}: `types` are accessed through * {@link AssemblyTypes} instead, and `readme`/`submodules` are compile-time * only data not available at runtime. Omitting them here means TypeScript * will flag any accidental access at compile time. */ export type AssemblyMetadata = Omit; export interface LoadedAssembly { /** The assembly metadata (without `types`, `readme`, or `submodules`). */ readonly metadata: AssemblyMetadata; /** Accessor for the assembly's types. */ readonly types: AssemblyTypes; } /** * Loads an assembly from a package directory. * * When the directory is a stable package-cache entry (`cached`) and assembly * validation is not requested, a compact "runtime index" is used so that only * the types actually accessed during execution are parsed, a large saving for * big assemblies (e.g. aws-cdk-lib), of which a typical run touches a tiny * fraction. * * The index is built on first use, whether the package was just extracted into * the cache or had been cached by an earlier run that predates this feature, * and is transparently rebuilt when {@link RUNTIME_INDEX_VERSION} changes. * Building and using the index is strictly best-effort: any failure falls back * to a full, eager load, so correctness never depends on the cache. */ export declare function loadRuntimeAssembly(packageDir: string, options: { readonly cached: boolean; readonly validate: boolean; readonly supportedFeatures: spec.JsiiFeature[]; /** Optional sink for best-effort diagnostics from the index-builder worker. */ readonly debug?: (...args: any[]) => void; }): LoadedAssembly; /** * Builds the runtime index for a cached package by (re-)reading its assembly. * * This is the unit of work performed on the index-builder worker thread; it is * intentionally self-contained (takes only a `packageDir`) so it can run with * no shared state. Errors propagate to the caller. */ export declare function buildRuntimeIndex(packageDir: string, supportedFeatures: spec.JsiiFeature[]): void; /** * Starts a worker thread that builds the runtime index for a cached package and * returns immediately, without awaiting it. * * The worker is intentionally not `unref`'d: it keeps the host process alive * until the index has been written, then exits on its own. This way even a * short-lived process (which has already returned its results to the host) * finishes building the index rather than abandoning it half-written. The * worker shares no kernel state; it is handed only the `packageDir` and * re-reads the assembly itself. Building the index is best-effort: any failure * is reported to `debug` (when provided) and the next load retries. * * Returns the {@link Worker}, or `undefined` if it could not be started. */ export declare function buildIndexInWorker(packageDir: string, supportedFeatures: spec.JsiiFeature[], debug?: (...args: any[]) => void): Worker | undefined; //# sourceMappingURL=runtime-index.d.ts.map