import { n as Plugin, s as Middleware } from "./plugin-DYhXH7JX.mjs"; import { c as TypedEntry, d as PartSchemaOf, f as ValuesOf, m as ServiceInput, o as SpecificationOptions, s as StoredAttributesOf, u as CustomResultOf } from "./define-DwE2AZUZ.mjs"; /** The scope an action is about, as the platform sends it, with its id and its slug as text. */ interface Scope extends Record { id: string; slug: string; } /** The deployment an action is about. */ interface Deployment { id: string; } /** What a scope's action handler gets as its input: the service's, its parameters typed `Parameters` and the scope's attributes `Attributes`, with the scope and, when the action is about one, the deployment. */ interface ScopeInput, Attributes = Record> extends ServiceInput { scope: Scope; deployment?: Deployment; } /** What a scope's deployment action handler gets as its input: the scope's, with the deployment its payload names, required. */ interface DeploymentInput, Attributes = Record> extends ScopeInput { deployment: Deployment; } /** * What a scope's telemetry action handler gets as its input: the scope's * without what a telemetry payload does not carry (its action, whether the * platform manages it, a trace to continue), its parameters and its * service's attributes untyped (its arguments arrive with it). Every scope's * input is one, so a handler of it answers any scope action. */ type TelemetryInput = Omit; /** * A scope's actions as the platform defines them (contract/kinds/scope.json). * A well-known action is the platform's: its type, whether it is retried and * the parameters it is sent come from the table, and one the table answers * with the lifecycle declares the scope's attributes as its results, since the * platform copies into the scope's attributes only the result keys an * action's results schema declares. Its title names its run on the trace, * never what is published. A telemetry action, any key under a telemetry * prefix, is the platform's too, with no definition of its own: it is * published as any custom action is (contract/kinds/service.json `action`). */ /** The actions the platform sends a scope today, by the key each is bound to (`[ScopeActions.CREATE_SCOPE]: …`): the contract's well-known actions, then its telemetry ones. */ declare const ScopeActions: { readonly CREATE_SCOPE: "create-scope"; readonly DELETE_SCOPE: "delete-scope"; readonly UPDATE_SCOPE: "update-scope"; readonly START_INITIAL: "start-initial"; readonly START_BLUE_GREEN: "start-blue-green"; readonly SWITCH_TRAFFIC: "switch-traffic"; readonly FINALIZE_DEPLOYMENT: "finalize-deployment"; readonly FINALIZE_BLUE_GREEN: "finalize-blue-green"; readonly ROLLBACK_DEPLOYMENT: "rollback-deployment"; readonly DELETE_DEPLOYMENT: "delete-deployment"; readonly DIAGNOSE_SCOPE: "diagnose-scope"; readonly DIAGNOSE_DEPLOYMENT: "diagnose-deployment"; readonly KILL_INSTANCES: "kill-instances"; readonly SET_DESIRED_INSTANCE_COUNT: "set-desired-instance-count"; readonly PAUSE_AUTOSCALING: "pause-autoscaling"; readonly RESUME_AUTOSCALING: "resume-autoscaling"; readonly RESTART_PODS: "restart-pods"; readonly LOG_READ: "log:read"; readonly METRIC_LIST: "metric:list"; readonly METRIC_DATA: "metric:data"; readonly INSTANCE_DATA: "instance:data"; }; /** The contract's telemetry prefixes (`telemetry.prefixes`), as the type of a key reads them; the contract stays what the code matches a key by (`isTelemetry`). */ type TelemetryPrefix = "log:" | "metric:" | "parameter:" | "instance:"; /** A telemetry action's key: any under a telemetry prefix. */ type TelemetryKey = `${TelemetryPrefix}${string}`; /** A well-known action's key, as the type of a key reads it: each of `ScopeActions` but the telemetry ones, the contract's `actions`. */ type WellKnownKey = Exclude<(typeof ScopeActions)[keyof typeof ScopeActions], TelemetryKey>; /** A text parameter's schema, as the table writes one. */ type TextSchema = { type: "string"; }; /** A number parameter's schema, as the table writes one. */ type NumberSchema = { type: "number"; }; /** A parameters schema as the table writes one: an object, the names it requires, its properties. */ type ParametersSchema = { type: "object"; required: Required; properties: Properties; }; /** The parameters schema of an action about a scope. */ type ScopeSchema = ParametersSchema<["scope_id"], { scope_id: TextSchema; }>; /** The parameters schema of an action about a scope's deployment. */ type DeploymentSchema = ParametersSchema<["scope_id", "deployment_id"], { scope_id: TextSchema; deployment_id: TextSchema; }>; /** * The parameters schema the platform sends each well-known action, as the * table gives it (`actions..parameters.schema`), as the type of a key * reads it: a literal mirror, since a JSON import widens its text, held equal * to the table by `test/kinds/scope/table.test.ts`. None for an action the * table sends none; the runtime reads the table. */ interface WellKnownParametersSchemas { "create-scope": ScopeSchema; "delete-scope": ScopeSchema; "update-scope": ScopeSchema; "start-initial": DeploymentSchema; "start-blue-green": DeploymentSchema; "switch-traffic": ParametersSchema<["scope_id", "deployment_id", "desired_traffic"], { scope_id: TextSchema; deployment_id: TextSchema; desired_traffic: NumberSchema; }>; "finalize-deployment": DeploymentSchema; "finalize-blue-green": DeploymentSchema; "rollback-deployment": DeploymentSchema; "delete-deployment": DeploymentSchema; "diagnose-scope": ScopeSchema; "diagnose-deployment": DeploymentSchema; "kill-instances": ParametersSchema<["scope_id", "instance_id", "deployment_id"], { scope_id: TextSchema; instance_id: TextSchema; deployment_id: TextSchema; }>; "set-desired-instance-count": ParametersSchema<["desired_instances"], { desired_instances: NumberSchema; }>; "pause-autoscaling": undefined; "resume-autoscaling": undefined; "restart-pods": undefined; } /** A deployment action's key: a well-known action whose parameters require a deployment (`requiresDeployment`), as the type of a key reads it. */ type DeploymentKey = { [Key in WellKnownKey]: WellKnownParametersSchemas[Key] extends { required: readonly (infer Name)[]; } ? ("deployment_id" extends Name ? Key : never) : never; }[WellKnownKey]; /** The parameters the scope's action `Key` gets, its own specification `Declared`: a well-known action's its table row's, a custom one's its `parameters` schema's. */ type ScopeParametersOf = Key extends WellKnownKey ? ValuesOf : ValuesOf>; /** What the scope's action `Key` returns, the scope's body `Body`: a well-known action, which the table answers with the lifecycle, `Partial` of the scope's attributes; a telemetry one what its payload's output schema says, `unknown`; a custom one its `results` schema's values. */ type ScopeResultOf = Key extends WellKnownKey ? StoredAttributesOf : Key extends TelemetryKey ? unknown : CustomResultOf; /** What the scope's action `Key` that is no deployment action gets as its input, the scope's body `Body`: its parameters and the scope's attributes. */ interface ScopeActionInputOf extends ScopeInput, StoredAttributesOf> {} /** What the scope's deployment action `Key` gets as its input, the scope's body `Body`: its parameters, the scope's attributes and the deployment, required. */ interface DeploymentActionInputOf extends DeploymentInput, StoredAttributesOf> {} /** What the scope's action `Key` gets as its input: a telemetry key the telemetry input, a deployment action's the deployment required, any other the scope's. */ type ScopeHandlerInputOf = Key extends TelemetryKey ? TelemetryInput : Key extends DeploymentKey ? DeploymentActionInputOf : ScopeActionInputOf; /** A scope's actions, by key, each typed by what its key gets (`ScopeHandlerInputOf`) and returns (`ScopeResultOf`), its own specification `Specs[Key]`. */ type ScopeEntries = { [Key in keyof Specs]: TypedEntry, ScopeResultOf, Specs[Key]>; }; /** * The actions a definition declares when TypeScript infers none of their * keys: every entry is a handler that reads its input, which TypeScript * types only once their keys are fixed. They are the well-known ones and any * telemetry one, each optional. */ type DefaultScopeSpecs = Partial> & { [key: TelemetryKey]: undefined; }; /** What a scope's middleware is handed: the input of any of its actions but the telemetry ones, its parameters untyped, which the route builds again right before the handler. */ type ScopeMiddlewareInput = ScopeInput, StoredAttributesOf>; /** What a scope is defined by: its body `Body`, each action's specification `Specs[key]`. */ interface ScopeDefinition, Specs = Record> extends SpecificationOptions> { /** The service_specification body, as the API takes it; named by the package's slug. */ specification: Body; /** The asset type the scope deploys (`docker-image`, `lambda`, `bundle`, …): its `asset_type` attribute's default; the contract's unless given. */ assetType?: string; /** The scope type the scope provides, its scope_type body as the API takes it (its `name` the package's and its `description` the name unless given); none without it. */ scopeType?: Record; /** What it answers, by key: its well-known actions (`ScopeActions`), its telemetry ones, and its custom ones, each with its specification. A deployment action's handler gets the deployment, required; any other well-known action's, the scope's input; a telemetry key's, the telemetry input, with no action; a custom key's, the scope's, its parameters and results its own schemas'. */ actions: ScopeEntries; /** Around each handler of its actions but the telemetry ones, after the kind's own middleware: it is handed the scope's action's input, its parameters untyped. Never on a telemetry action, whose payload carries no attributes. On a deployment action, the deployment is checked again after it, right before the handler: one it passes on without it fails the action, MISSING_DEPLOYMENT. */ use?: Middleware>[]; } /** * A scope of its package: its specification, its actions and its scope type * published, a route per action, then its last route. A definition with a * problem is refused, naming every one at once: the specification's (its * body and its attributes, its default actions, its asset type, its scope * type, its actions), then the definition's own. */ declare function defineScope, const Specs extends Record = DefaultScopeSpecs>(definition: ScopeDefinition): Plugin; export { type DeploymentActionInputOf, type DeploymentInput, type ScopeActionInputOf, ScopeActions, type ScopeDefinition, type ScopeInput, type ScopeResultOf, type TelemetryInput, defineScope }; //# sourceMappingURL=scope.d.mts.map