import { Program } from '../sourcegen/index.js'; import { ConstructCodegen } from '../constructs/construct-codegen.js'; import { Context, type ProjectDefaults, type ReferencedNames } from '../constructs/internal/codegen/index.js'; import type { ConstructExport } from '../constructs/session.js'; import type { AuxiliaryResourceSync, FriendResourceSync } from '../rest/projects.js'; /** A resource to generate a construct for, as an import plan carries it. */ export interface GenerateResource { type: string; logicalId: string; physicalId?: string | number; payload: any; } /** * The resources to generate code for, in the shape of an import plan's * `changes`: the resources themselves and the account data they refer to * (`auxiliary`, such as the snippets a check's scripts use). */ export interface GenerateChanges { resources: R[]; auxiliary?: AuxiliaryResourceSync[]; } /** * The changes of an import plan, which also lists the resources the project * already declares (`friends`), for the generated code to import from the * project's own files. */ export interface ImportChanges extends GenerateChanges { friends?: FriendResourceSync[]; } export interface GenerateOptions { /** * The check defaults of the project the code is generated for. Absent, the * project is unknown and every check property a project default could * change is written out, even at its default value (see * `ContextOptions.projectDefaults`). Pass `{}` for a project without * defaults. */ projectDefaults?: ProjectDefaults; /** * Names of the resources the generated code refers to by ID, keyed by * resource type and physical ID. Each such `fromId()` reference carries the * name in a trailing comment. */ referencedNames?: ReferencedNames; } /** A resource the codegen could not generate, and why. */ export interface GenerateFailure { resource: R; cause: Error; } export interface GeneratedConstructFile { /** Relative to the root of the generated code, with `/` separators. */ path: string; content: string; } export interface GenerateResult { files: GeneratedConstructFile[]; failures: GenerateFailure[]; } export interface GenerateIntoProgramOptions extends GenerateOptions { /** * The construct the project exports for a friend resource, looked up by * the friend's type and logical ID. Without it, every friend is reported * as not requested. */ friendExport?: (type: FriendResourceSync['type'], logicalId: string) => ConstructExport | undefined; /** * The context to generate against, for a caller that reads it afterwards. * Without it, one is created from `projectDefaults` and `referencedNames`, * which are then the only options it takes. */ context?: Context; /** * Whether a snippet the codegen cannot convert fails only the resources * that use it (`Context.registerRefusedSnippet`), instead of the whole * generation. */ deferRefusedSnippets?: boolean; } /** * Generates the constructs for `changes` into `program`, which the caller * then writes or renders. A resource that fails to generate is returned as a * failure, and the files of the other resources are still generated; a * friend or auxiliary resource that cannot be processed throws instead, * since every resource could depend on it. * * The program must be new: generated files accumulate in it. */ export declare function generateIntoProgram(changes: ImportChanges, program: Program, codegen: ConstructCodegen, options?: GenerateIntoProgramOptions): GenerateFailure[]; /** * Generates `checkly/constructs` code for `changes` in memory: TypeScript * construct files (`*.check.ts`), the spec files of browser and multi-step * checks (`*.spec.ts`), and their support files (scripts, snippets). Nothing * is read from or written to disk, and the result depends on the arguments * alone. * * A resource that cannot be generated is listed in `failures` with the * reason, and the files of the other resources are still returned, without * anything the failed resource would have contributed. The * reason is an `UnsupportedResourceTypeError` for a resource type no codegen * covers, an `ImportSafetyViolation` or `UnsupportedScriptError` for a * resource whose content cannot be converted, or a plain `Error` otherwise * (a Playwright check suite, whose code bundle cannot be unpacked as * source, among them). An error raised while a construct expression is * being built reaches `failures` wrapped in a plain `Error` that adds where * it happened, so look for these classes along the `cause` chain. * * `auxiliary` may hold every snippet of the account: only the snippets the * generated code uses are returned, with those they require in turn. A * snippet the codegen cannot convert fails only a resource that uses it, * with the reason (such as an `UnsupportedScriptError`) on the `cause` * chain. * * Friends (resources an import plan says the project already declares) are * not accepted, since there is no project to import them from: a `friends` * field is ignored, and a reference to any resource outside `changes` * renders as `fromId()`, with its name from `referencedNames` when given. * * @experimental See the `checkly/codegen` entry: intended for Checkly's own * services, and not covered by semver guarantees until stated otherwise. * * @throws Error if an auxiliary resource is of a type other than `snippet`. */ export declare function generateConstructFiles(changes: GenerateChanges, options?: GenerateOptions): GenerateResult;