import { CaseFormat, GeneratedFile, IdentifierValue } from '../../../sourcegen/index.js'; import { ProgramFile } from '../../../sourcegen/program.js'; import type { ConstructExport } from '../../session.js'; import type { CheckConfigDefaults } from '../../../services/checkly-config-loader.js'; import type { FriendResourceSync } from '../../../rest/projects.js'; export declare class MissingContextVariableMappingError extends Error { } export declare abstract class VariableLocator { id: IdentifierValue; filePath: string; constructor(id: IdentifierValue, filePath: string); } export declare class GeneratedVariableLocator extends VariableLocator { file: GeneratedFile; constructor(id: IdentifierValue, file: GeneratedFile); } export declare class FriendVariableLocator extends VariableLocator { } export interface FilenameOptions { tags?: string[]; isolate?: boolean; unique?: boolean; contentKey?: string; case?: CaseFormat; } export declare class FilePath { fullPath: string; constructor(fullPath: string); get extless(): string; } /** * The name a registered construct's variable gets: a resource name to derive * an identifier from, or an identifier to use as it is, such as the name the * construct already has in the user's code. */ export type VariableName = string | { identifier: string; }; /** * What a masked value prints as: never an empty string, which could pass for * a value. Only a string the preview itself wrote (`ContextOptions.maskedValues`) * is ever printed back for a secret; a value that merely looks masked is not. */ export declare const MASKED_VALUE = "********"; export interface ContextOptions { /** * Set by the deploy preview's renderer, never by an import: the exact * strings the preview wrote over masked values. A `secret: true` variable * then prints such a value as a string literal beside `secret: true`, * instead of a generated `secret()` reference, so the two sides of a * preview can differ where the secret moved. Any other value prints as the * plain mask, never as itself. */ maskedValues?: ReadonlySet; /** * Set when the code being rendered already exists (a deploy preview, the * write-back), never by an import: the properties that code spells out, * as dotted paths from the construct's options (`muted`, * `request.skipSSL`, `retryStrategy.maxRetries`, and for a list element * with a literal key, `headers[Authorization].locked`, the key taken as * it is). A codegen writes * such a property even when its value is the default it would otherwise * leave out, so that a property the author wrote down does not vanish * from a rendering, or read as added or removed in a diff, because its * value happens to be the default. */ spelledOut?: ReadonlySet; /** * The `checks` defaults of the project the generated code will live in, * which a generated check falls back to for a property it leaves out (see * `projectDefaultsFor` in `check-codegen.ts`). `{}` stands for a project * that sets none, where an omitted property means the backend default. * * Absent, the project is unknown, so a codegen cannot tell which omissions * are safe: every check property a project default could fill in is then * written out even at its default value, and an empty relation or variable * list is written as `[]`. */ projectDefaults?: ProjectDefaults; /** * The names of resources a generated construct refers to by ID because the * code being generated does not declare them, keyed by resource type and * then by physical ID (as a string). A `fromId()` reference to a named * resource carries the name in a trailing comment, so that a reader can * tell what the ID stands for. */ referencedNames?: ReferencedNames; } /** * The project-level check defaults of a `checkly.config`: the shared `checks` * section and the sections for browser and multi-step checks. */ export interface ProjectDefaults { checks?: CheckConfigDefaults; browserChecks?: CheckConfigDefaults; multiStepChecks?: CheckConfigDefaults; } /** * The resource types a generated construct can refer to with `fromId()`: the * same types an import plan can name as friends. */ export type ReferencedResourceType = FriendResourceSync['type']; export type ReferencedNames = Partial>>>; /** * The child keys under a prefix among dotted paths: `retryStrategy` picks * `maxRetries` out of `retryStrategy.maxRetries`. A bracketed element key * (`headers[x.trace].locked`) is opaque: the dots inside it do not separate * segments, so `request` has the child `headers[x.trace]`. */ export declare function pathsUnder(paths: ReadonlySet, prefix: string): string[]; export declare class Context { #private; readonly maskedValues: ReadonlySet | undefined; /** See `ContextOptions.projectDefaults`; `undefined` when the project is unknown. */ readonly projectDefaults: ProjectDefaults | undefined; constructor(options?: ContextOptions); /** The name of a resource referenced by ID, if known (see `ContextOptions.referencedNames`). */ referencedName(type: ReferencedResourceType, physicalId: string | number): string | undefined; /** Whether the code being rendered spells out the property at `path` (see `ContextOptions.spelledOut`). */ spelledOut(path: string): boolean; /** The spelled-out properties directly under `prefix`, for a codegen that takes a list rather than a context. */ spelledOutUnder(prefix: string): string[]; /** * Whether a value is one of the stand-ins the preview wrote over a secret. * Such a value is unknown to the codegen: it is never parsed for a * credential inside it and never held against an import-safety rule. * Where a codegen would derive a prop from the real value, it prints the * stand-in as that prop instead, so the preview shows the mask, and its * change note, in the prop's place. Under an import no value is ever * masked. */ isMasked(value: unknown): boolean; filePath(parent: string, hint: string, options?: FilenameOptions): FilePath; importVariable(locator: GeneratedVariableLocator, file: GeneratedFile): IdentifierValue; importFriendVariable(locator: FriendVariableLocator, file: GeneratedFile): IdentifierValue; /** * Give up the identifier reserved for a registered variable, for a caller * about to register the same construct again under another name: the new * name is then free to be the one the old registration held. */ releaseVariable(locator: GeneratedVariableLocator): void; registerCheckGroup(physicalId: number, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupCheckGroup(physicalId: number): GeneratedVariableLocator; registerFriendCheckGroup(physicalId: number, friend: ConstructExport): FriendVariableLocator; lookupFriendCheckGroup(physicalId: number): FriendVariableLocator; registerAlertChannel(physicalId: number, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupAlertChannel(physicalId: number): GeneratedVariableLocator; registerFriendAlertChannel(physicalId: number, friend: ConstructExport): FriendVariableLocator; lookupFriendAlertChannel(physicalId: number): FriendVariableLocator; registerPrivateLocation(physicalId: string, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupPrivateLocation(physicalId: string): GeneratedVariableLocator; registerFriendPrivateLocation(physicalId: string, friend: ConstructExport): FriendVariableLocator; lookupFriendPrivateLocation(physicalId: string): FriendVariableLocator; registerPrivateLocationGroupAssignment(privateLocationPhysicalId: string, groupPhysicalId: number): void; lookupCheckGroupPrivateLocations(groupPhysicalId: number): string[]; registerPrivateLocationCheckAssignment(privateLocationPhysicalId: string, checkPhysicalId: string): void; lookupCheckPrivateLocations(checkPhysicalId: string): string[]; registerAlertChannelCheckSubscription(alertChannelPhysicalId: number, checkPhysicalId: string): void; lookupCheckAlertChannels(checkPhysicalId: string): number[]; registerAlertChannelGroupSubscription(alertChannelPhysicalId: number, groupPhysicalId: number): void; lookupCheckGroupAlertChannels(groupPhysicalId: number): number[]; registerStatusPageService(physicalId: string, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupStatusPageService(physicalId: string): GeneratedVariableLocator; registerFriendStatusPageService(physicalId: string, friend: ConstructExport): FriendVariableLocator; lookupFriendStatusPageService(physicalId: string): FriendVariableLocator; registerStatusPage(physicalId: string, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupStatusPage(physicalId: string): GeneratedVariableLocator; registerFriendStatusPage(physicalId: string, friend: ConstructExport): FriendVariableLocator; lookupFriendStatusPage(physicalId: string): FriendVariableLocator; registerStatusPageComponent(physicalId: string, name: VariableName, file: GeneratedFile): GeneratedVariableLocator; lookupStatusPageComponent(physicalId: string): GeneratedVariableLocator; registerFriendStatusPageComponent(physicalId: string, friend: ConstructExport): FriendVariableLocator; lookupFriendStatusPageComponent(physicalId: string): FriendVariableLocator; registerKnownSecret(name: string): boolean; registerAuxiliarySnippetFile(physicalId: number, snippetFile: ProgramFile): void; /** * The snippet file a script names by ID. Recorded as used by the generated * code (`usedAuxiliarySnippetFiles`). * * @throws Error if the snippet, or a snippet it reaches, was refused * (`registerRefusedSnippet`). */ lookupAuxiliarySnippetFile(physicalId: number): ProgramFile | undefined; /** * The snippet files a check's script requires through `./snippets/`. * Recorded as used by the generated code (`usedAuxiliarySnippetFiles`). * * @throws Error if the script, or a snippet it reaches, requires a refused * snippet (`registerRefusedSnippet`). */ findScriptSnippetFiles(content: string): ProgramFile[]; /** * The snippet files `content` requires, without recording them as used: * through `./snippets/` only, or with `sameFolder` also as a sibling * (`./other-snippet`), which is how a snippet that is itself required may * require another. */ snippetFilesRequiredBy(content: string, options?: { sameFolder?: boolean; }): ProgramFile[]; /** * Remembers a snippet the codegen cannot convert, instead of failing every * resource for it: only a resource that names it by ID, or whose script * reaches it through requires, fails, with `cause` as the reason. * * @param name The snippet's name, by which a script requires it (see * `snippetFilename`); absent if it has none. */ registerRefusedSnippet(physicalId: number, name: string | undefined, cause: Error): void; /** * The path of a snippet's file: `snippets/`, the name kept as it is * when it is one the backend allows in a file name (`isSafeSnippetFilename`), * else in kebab-case. Snippets with the same name but different IDs get * numbered paths. */ snippetFilePath(physicalId: number, name: string): FilePath; /** * The file name, without an extension, that a snippet's file is named * after (see `snippetFilePath`), by which a script requires it. */ snippetFilename(name: string): string; /** Every registered snippet file. */ get auxiliarySnippetFiles(): ProgramFile[]; /** * The snippet files the generated code itself uses: those a script names * by ID or requires, not counting what the snippets require in turn. */ get usedAuxiliarySnippetFiles(): ReadonlySet; }