type Awaitable = Value | PromiseLike; type ScopeKind = "terminal" | "storeWriter" | "state"; export type CanonicalMutationResource = Readonly<{ key: string; value: Value; }>; type ScopeResources = Readonly>; export type CanonicalMutationResources = Readonly & Partial>; export type CanonicalStateMutationResources = Readonly; declare const mutationScopeBrand: unique symbol; type MutationScope = Readonly<{ [mutationScopeBrand]: Kind; }>; export type CanonicalMutationScopes = Readonly<{ terminal: MutationScope<"terminal">; storeWriter: MutationScope<"storeWriter">; state?: MutationScope<"state">; }>; export type CanonicalStateMutationScopes = CanonicalMutationScopes & Readonly<{ state: MutationScope<"state">; }>; export type CanonicalMutationLockPorts = Readonly<{ resources: CanonicalMutationResources; acquireTerminal: () => Awaitable<() => void>; afterTerminalAcquired?: () => Awaitable; withStoreWriter: (operation: () => Promise) => Promise; acquireState?: () => Awaitable<() => void>; }>; export declare function canonicalMutationResource(key: string, value: Value): Readonly<{ key: string; value: Value; }>; type ScopesFor = Pick; export declare function capabilityGatedRepositoryOperation(required: Required, bound: Bound, operation: (resource: Resource, ...args: Args) => Result): (scopes: ScopesFor, resources: Pick, ...args: Args) => Result; export declare function capabilityGatedRepositoryPairOperation(required: Required, bound: readonly [First, Second], operation: (first: FirstResource, second: SecondResource, ...args: Args) => Result): (scopes: ScopesFor, resources: Pick, ...args: Args) => Result; type ScopesForPorts = Ports extends { acquireState: () => unknown; } ? CanonicalStateMutationScopes : CanonicalMutationScopes; type ResourcesForPorts = Ports extends { acquireState: () => unknown; } ? ScopeResources : CanonicalMutationResources; /** Acquire terminal -> writer -> optional state and release in reverse. */ export declare function withCanonicalMutationLocks(ports: Ports, operation: (scopes: ScopesForPorts, resources: ResourcesForPorts) => Promise): Promise; /** Add one state scope to the currently active terminal + writer transaction. */ export declare function withCanonicalStateMutationLock(scopes: CanonicalMutationScopes, resources: CanonicalMutationResources, state: Readonly<{ resource: CanonicalMutationResource; acquire: () => Awaitable<() => void>; }>, operation: (scopes: CanonicalStateMutationScopes, resources: CanonicalStateMutationResources) => Promise): Promise; export {};