import type { AppEnvironmentId } from '../environments'; import type { INFRA_ADAPTER_CATALOG } from '../infra/constants'; import type { InfraDestroyRequest, InfraGeneratedArtifact, InfraLedger, InfraOutput, InfraOwnedResource, InfraPlanAction, InfraResourceStatus, InfraResult, } from './infraLifecycle'; import type { InfraAdapterId, InfraComputeProviderId, InfraComputeSelection, InfraEnvironmentSpec, InfraRuntimeProviderId, InfraRuntimeSelection, } from './infraManifest'; import type { InfraControlPlaneCredentialRef, InfraSecretReference } from './infraSecrets'; import type { InfraComputeTarget } from './infraTargets'; import type { InfraWorkloadSpec } from './infraWorkload'; /** Package exports must match this exact catalog entry; optional operations are advertised explicitly. */ export type InfraAdapterDescriptor

= { [K in P]: (typeof INFRA_ADAPTER_CATALOG)[K] & { readonly operations?: readonly ('suspend' | 'resume' | 'generate' | 'diagnostics')[]; }; }[P]; /** Trusted execution-only control-plane credential lookup, resolution and persistence. */ export interface InfraCredentialPort { /** Return a credential bundle when present; absence is not an error. */ findAsync( reference: InfraControlPlaneCredentialRef, ): Promise> | null>>; /** Resolve a required credential bundle; absence is an error. */ resolveAsync( reference: InfraControlPlaneCredentialRef, ): Promise>>>; /** Persist an opaque provider-owned credential bundle without exposing its schema to the host. */ persistAsync( reference: InfraControlPlaneCredentialRef, values: Readonly>, ): Promise>; } /** Trusted execution-only ports. Implementations must not serialize resolved credential values. */ export interface InfraExecutionContext { readonly projectId: string; readonly environment: AppEnvironmentId; readonly desired: InfraEnvironmentSpec; readonly previous?: InfraLedger; readonly signal?: AbortSignal; readonly credentials: InfraCredentialPort; readonly secrets: { resolveAsync(reference: InfraSecretReference): Promise>; }; } export interface InfraReconcileResult { readonly resources: readonly InfraOwnedResource[]; readonly outputs: readonly InfraOutput[]; } /** Current portable compute state resolved without creating, updating or deleting resources. */ export interface InfraComputeSnapshot extends InfraReconcileResult { readonly targets: readonly InfraComputeTarget[]; } export interface InfraComputeAdapter

{ readonly descriptor: InfraAdapterDescriptor

; /** Read-only prerequisites, config and control-plane credential validation. */ validateAsync( context: InfraExecutionContext, selection: InfraComputeSelection

, ): Promise>; /** Read-only discovery for planning and stateless runtime projection. Missing compute is empty. */ inspectAsync( context: InfraExecutionContext, selection: InfraComputeSelection

, ): Promise>; planAsync( context: InfraExecutionContext, selection: InfraComputeSelection

, ): Promise>; ensureAsync( context: InfraExecutionContext, selection: InfraComputeSelection

, ): Promise>; statusAsync(context: InfraExecutionContext): Promise>; destroyAsync( context: InfraExecutionContext, request: InfraDestroyRequest, ): Promise>; } export interface InfraRuntimeDesiredState< P extends InfraRuntimeProviderId = InfraRuntimeProviderId, > { readonly selection: InfraRuntimeSelection

; readonly targets: readonly InfraComputeTarget[]; readonly workloads: readonly InfraWorkloadSpec[]; /** Previously resolved outputs available to portable workload value references. */ readonly availableOutputs: readonly InfraOutput[]; } export interface InfraRuntimeAdapter

{ readonly descriptor: InfraAdapterDescriptor

; /** Read-only prerequisites and desired-state validation; no cluster creation. */ validateAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; planAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; ensureAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; statusAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; suspendAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; destroyAsync( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, request: InfraDestroyRequest, ): Promise>; generateAsync?( context: InfraExecutionContext, desired: InfraRuntimeDesiredState

, ): Promise>; } /** A service can own several capabilities but contributes one deduplicated platform instance. */ export interface InfraServiceAdapter { readonly descriptor: InfraAdapterDescriptor<'supabase' | 'cerbos' | 'r2' | 'supabase-vault'>; /** Read-only service config, bootstrap credentials and dependency validation. */ validateAsync(context: InfraExecutionContext): Promise>; planAsync(context: InfraExecutionContext): Promise>; /** Mutating pre-runtime preparation invoked only by an orchestrated `up` operation. */ prepareAsync?(context: InfraExecutionContext): Promise>; desiredWorkloadsAsync( context: InfraExecutionContext, ): Promise>; reconcileAsync( context: InfraExecutionContext, runtimeOutputs: readonly InfraOutput[], ): Promise>; statusAsync(context: InfraExecutionContext): Promise>; destroyAsync( context: InfraExecutionContext, request: InfraDestroyRequest, ): Promise>; suspendAsync?(context: InfraExecutionContext): Promise>; }