import { valueForAssertion } from '../../constructs/api-assertion-codegen.js'; import { valueForDnsAssertion } from '../../constructs/dns-assertion-codegen.js'; import { valueForGrpcAssertion } from '../../constructs/grpc-assertion-codegen.js'; import { valueForIcmpAssertion } from '../../constructs/icmp-assertion-codegen.js'; import { valueForSslAssertion } from '../../constructs/ssl-assertion-codegen.js'; import { valueForTcpAssertion } from '../../constructs/tcp-monitor-codegen.js'; import { valueForTracerouteAssertion } from '../../constructs/traceroute-assertion-codegen.js'; import { valueForUrlAssertion } from '../../constructs/url-assertion-codegen.js'; import { Value } from '../../sourcegen/index.js'; import { type LiteralEdit, type SourceStyle } from './literal-edit.js'; import { type Node } from './source-file.js'; /** * Edits of the properties a construct spells with a helper expression rather * than a literal: `frequency: Frequency.EVERY_5M`, * `retryStrategy: RetryStrategyBuilder.fixedStrategy({ … })`, * `alertEscalationPolicy: AlertEscalationBuilder.runBasedEscalation(…)`, * `assertions: [AssertionBuilder.statusCode().equals(200)]`, and a date * the account reports as an ISO string: `startsAt: new Date('…')`. * * The expression is built by the same codegen `checkly import` uses for the * property, so the text written is the one an import would have generated; * only the rendering differs, following the file's quotes, indentation and * line ending the way `renderValue` does for literals (`sourcegen`'s own * printer fixes all three). The classes the expression references are * looked up under the names the file binds them to, and added to its * `checkly/constructs` import when it lacks them (`imports.ts`). * * An existing value is replaced only when it is a plain literal or an * expression on the same helper whose arguments are literals: a variable * inside `fixedStrategy({ maxRetries: retries })` is something the user * meant, and a rewrite must not throw it away. */ export type HelperKind = 'frequency' | 'retryStrategy' | 'alertEscalation' | 'assertions' | 'date'; /** The codegen for each assertion builder a monitor class spells its assertions with. */ declare const ASSERTION_CODEGENS: { AssertionBuilder: typeof valueForAssertion; UrlAssertionBuilder: typeof valueForUrlAssertion; TcpAssertionBuilder: typeof valueForTcpAssertion; DnsAssertionBuilder: typeof valueForDnsAssertion; GrpcAssertionBuilder: typeof valueForGrpcAssertion; SslAssertionBuilder: typeof valueForSslAssertion; IcmpAssertionBuilder: typeof valueForIcmpAssertion; TracerouteAssertionBuilder: typeof valueForTracerouteAssertion; }; export type AssertionBuilderName = keyof typeof ASSERTION_CODEGENS; /** The names of every assertion builder: each spells the same property, so a file may hold any of them. */ export declare const ASSERTION_BUILDERS: readonly string[]; interface HelperEditBase extends Omit { /** Sibling keys of the property that make the edit wrong (`doubleCheck` beside `retryStrategy`). */ unless?: string[]; /** * A plain value to write instead of the expression when the node being * replaced is itself a plain literal: a whole-minute `frequency` stays a * number in a file that spells it as one. The choice is made where the * node is known, in `apply-edits.ts`; the planner never sees the file. */ literalAlternative?: unknown; } /** * An edit of a helper-spelled property. The class the expression is built * on follows from the kind, except for assertions, where each monitor class * has its own builder. */ export type HelperEdit = HelperEditBase & ({ helper: 'frequency' | 'retryStrategy' | 'alertEscalation' | 'date'; builder?: undefined; } | { helper: 'assertions'; builder: AssertionBuilderName; }); export type SourceEdit = LiteralEdit | HelperEdit; export declare function isHelperEdit(edit: SourceEdit): edit is HelperEdit; /** The class the edit's expression is built on, as `checkly/constructs` exports it, or the global `Date`. */ export declare function helperClass(edit: HelperEdit): string; /** Whether the edit's class is a global every file binds, rather than one imported from `checkly/constructs`. */ export declare function isGlobalHelper(edit: HelperEdit): boolean; /** * The expression the codegen builds for the edit's value, and the classes * it references (those the codegen asked to import and the expression * names: a gRPC assertion the builder cannot spell comes back as a plain * object, which needs no import). The value is what the account holds, in * the import format `entry.before` carries. * * @throws WriteBackSkipped for a value the codegen cannot spell (an * assertion source or retry type this CLI does not know, a malformed row) * or one that means "unset", which is never written because nothing is * ever removed from the code. */ export declare function buildHelperValue(edit: HelperEdit, spelledOut?: readonly string[]): { value: Value; imports: string[]; }; /** * Whether `node` is an expression built on one of `locals` (the names the * file binds the helper class to): a member, call or `new` chain rooted at * such a name, with every argument a literal (see `isReplaceableByHelper`), * `undefined`, or such a chain. Replacing it loses nothing the user wrote * by hand. */ export declare function isHelperExpression(node: Node, locals: ReadonlySet): boolean; /** * Whether `node` can be replaced by a helper edit without losing anything * written by hand: a plain literal, `null` (the edit writes an expression, * not null, and the codegen spells an assertion it has no builder method * for as an object holding `regex: null`), a helper expression, or an * array or object built only of those. */ export declare function isReplaceableByHelper(node: Node, locals: ReadonlySet): boolean; export interface ExpressionLayout { /** The indentation of the line the expression starts on. */ column: string; /** Whether objects and lists inside stay on one line, as the replaced node did. */ inline: boolean; /** Whether a multi-line object or list ends its last member with a comma. */ trailingComma: boolean; /** The local name of each class the expression references, where the file binds it under another. */ locals: ReadonlyMap; } /** * The source text of a sourcegen expression in the file's style. Objects * keep the order the codegen gave them (its own sorter), so the text is * the one `checkly import` would print, reindented and requoted. * * @throws WriteBackSkipped for a value class the codegen never produces for * these properties and this renderer does not spell. */ export declare function renderExpression(value: Value, style: SourceStyle, layout: ExpressionLayout): string; /** * Whether a parsed node is the expression `value` renders to: the same * names, members, arguments and literals. The check the read-back of a * written file makes; it says nothing about what the expression means, * which the codegen's own tests cover. */ export declare function matchesValue(node: Node, value: Value, locals: ReadonlyMap): boolean; export {};