import type { Resource, ResourceType } from '../../constructs/construct-codegen.js'; import { type Context } from '../../constructs/internal/codegen/index.js'; import type { Project } from '../../constructs/project.js'; import type { DiffChange, DiffEntry, DiffMaskedMarker, DiffRedaction, ResourceSync } from '../../rest/projects.js'; import type { Program } from '../../sourcegen/index.js'; /** * Shapes the local side of a deploy preview like an import resource — the * payload `checkly import` receives per resource and the construct codegens * read — so it can be rendered by the same codegen as the deployed side and * the two diffed as text. * * The deployed side needs no shaping: a preview's `before` (`detail: 'full'`) * IS the import format, straight from the API. The local side is the payload * this CLI synthesized for the deploy, which differs from the import format in * exactly the ways `toImportResource` bridges: it has no `id`; it references * other resources by logical id (`{ ref }`) where the import format carries * physical ids; its relations are separate subscription and assignment * resources, which the codegen folds onto the parent by registering them; it * keeps a check's intent constraints in the author's order where the stored * form groups them; and it carries a few keys only a deploy reads. * * Nothing here canonicalizes nulls, defaults or ordering beyond that. The * local payload is well-formed by construction, and the deployed side comes * from the same function the import plan uses, which the codegen was written * for. A payload that cannot be shaped throws `UnshapeableError`; the * renderer catches it and lists the changes instead. */ /** Physical ids keyed by `${type}:${logicalId}`. */ export type PhysicalIds = ReadonlyMap; export declare function idKey(type: string, logicalId: string): string; /** * The segments of an RFC 6901 pointer, unescaped; the root pointer has none. * * @throws UnshapeableError for a string that is not a pointer, rather than * matching it against nothing. */ export declare function pointerSegments(pointer: string): string[]; /** A payload this module cannot turn into an import resource; the message says why. */ export declare class UnshapeableError extends Error { } /** * Every resource's physical id, for the rendering: the preview's entries * carry the id of everything that exists (including a resource the code only * references, whose `fromId` construct sends it), and a resource being created * gets a synthetic one so the codegen has something to key its registrations * on. Every local resource has an entry afterwards; this is the one place an * id is minted. */ export declare function physicalIdsFromPlan(diff: readonly DiffEntry[], local: readonly ResourceSync[]): PhysicalIds; /** * Keys of a deployed row that neither side renders: a setup or teardown * snippet reference. The codegen resolves one through snippet files an * import registers and a preview has not, a deploy clears it either way, and * it is a bookkeeping column the plan never reports — so left in `before`, * `fillUnchangedFromBefore` would copy it onto the local side. */ export declare const UNRENDERED_KEYS: readonly ["setupSnippetId", "tearDownSnippetId"]; /** * Fills into the shaped local payload every property the deployed row holds * that the payload leaves out and the plan does not report as changed. Those * are the defaults the deploy's validation fills into an absent property * (`activated: true`, a check type's response-time limits, an empty header * list), which the row then always carries and the codegen prints: the plan * compared the validated payload against the row, so a property absent here * and unreported there is one the deploy leaves as it is. Taking it from * `before` makes the two renderings agree on it without this CLI keeping a * copy of any default — and cannot hide a change, since a value copied to * both sides prints alike on both. * * A key is left alone when a reported change path is it, lies under it, or * lies above it; an explicit `null` is a value, not an absence; and only * object keys are filled, never the elements of a list. */ export declare function fillUnchangedFromBefore(local: Record, before: Record, changes: readonly DiffChange[]): void; /** * The local payload of one resource, as an import resource: `id` set, every * reference a physical id, deploy-only keys dropped, the intent's constraints * grouped as stored. No canonicalization of nulls, defaults or * ordering: the payload has none, and the defaults the deploy would fill * are taken from the deployed row by `fillUnchangedFromBefore`. * * @throws UnshapeableError for a payload the codegen could not render. */ export declare function toImportResource(type: ResourceType, logicalId: string, payload: unknown, ids: PhysicalIds): Resource; /** * The relation rows a parent's `before` carries — every live subscription * and assignment, the way the import format spells them — as the resources * whose `prepare()` registers them on the codegen context. */ export declare function relationResourcesFromBefore(type: string, before: Record): Resource[]; export interface AfterRelationsInput { ids: PhysicalIds; /** Every resource of the local deploy payload. */ local: readonly ResourceSync[]; /** The parent's own preview entry: its type, logical id and `before`. */ entry: DiffEntry; /** The whole preview, for the relation entries folded into this parent. */ diff: readonly DiffEntry[]; pruneRelations: boolean; } /** * The relation resources the local side renders with: the project's own * subscription and assignment constructs for this parent, plus every deployed * relation the deploy will leave in place. A deployed row is left out when the * code removed it (a DELETE or DETACH relation entry folded into this parent * names its row id), when `--prune-unmanaged-relations` will delete it (a pruned entry * names it too), or when a local construct already stands for the same target. * What remains is unmanaged: the deploy keeps it, so both sides show it. * * @throws UnshapeableError when one of the parent's own relations cannot be shaped. */ export declare function relationResourcesForAfter(input: AfterRelationsInput): Resource[]; /** What a redacted value renders as, on both sides: never an empty string, which could pass for a value. */ export declare const MASK = "********"; /** * A payload with the API's redaction rules applied — the type's whole table, * whatever the deployed row held — so a credential is masked on both sides * (the deployed side arrives blanked and is masked the same way, since a * blank could pass for a value) and never a phantom change, nor printed. A * rule that matches nothing is simply ignored. No table at all is refused: * an API that reports a `before` without one predates the rules, and the one * direction this module must never take is printing a credential. * * @throws UnshapeableError when the API reported no rule table. */ export declare function blankRedacted(payload: T, redactions: readonly DiffRedaction[] | undefined): T; export declare function isMaskedMarker(value: unknown): value is DiffMaskedMarker; /** Whether a reported value holds a marker anywhere inside it. */ export declare const carriesMarker: (value: unknown) => boolean; /** The value at `segments` inside `root`, or undefined where the path does not resolve. */ export declare function nodeAt(root: unknown, segments: readonly string[]): unknown; /** * Write `text` over the masked value of every element the report marks * `changed`, in the payload's list at `path`. A reported element is matched * to the payload's by `key` when that key is unique in both, else by index * when the key at that index is the same and the lists are equal in length, * else not at all — the deployed row's list can be ordered differently from * the report, so an index alone is never trusted, and a name is never * wrong. A scalar marker names its own path. Returns whether any mark was * placed. */ export declare function markChanged(payload: unknown, path: string, reported: unknown, text: string): boolean; /** The types another construct refers to by variable. */ export declare const REFERENCEABLE_TYPES: (keyof import("../../constructs/project.js").Resources)[]; /** * Re-register the construct a codegen has just prepared under the name it * has in the user's code (`names`, keyed by `idKey`), or else its logical * id, in the construct file the codegen chose. A codegen names the variable * it exports after the resource's content (an alert channel after its * address, a group after its name), so a change to that content would show * as a renamed variable beside the change itself; the code's name and the * logical id are the same on both sides. The codegen's own name is given up * first, so the new one can be the same (a group declared as `websiteGroup` * and named "Website Group") without a counter to tell the two apart. A type * whose codegen registers no variable is left alone. */ export declare function registerUnderCodeName(context: Context, resource: Resource, names?: ReadonlyMap): void; /** * Register every referenceable construct of the local project on a fresh * context, under its physical id, so a rendered reference comes out as a * variable rather than as `fromId(...)`: the one the construct has in the * user's code (`names`, keyed by `idKey`), or else one derived from its name. Both * sides of a comparison register the same set in the same order, which is * what makes their identifiers agree. The constructs the code names go * first, so a name derived for another construct that happens to be the * same is the one that gets a counter. One support file for all of them, so * the context's per-file identifier namespace tells two constructs with the * same name apart (`group`, `group2`); a support file, not a construct file, * because `renderConstruct` counts the construct files a render adds. */ export declare function registerProject(context: Context, program: Program, project: Project, ids: PhysicalIds, names?: ReadonlyMap): void;