42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
|
|
import type { RouteContract } from '../types.js'
|
||
|
|
/**
|
||
|
|
* Plugin Contract Types
|
||
|
|
* Types for plugin contract system and composed contracts.
|
||
|
|
*/
|
||
|
|
export interface PluginContractSpec {
|
||
|
|
/** Route path prefix pattern. Supports wildcards: '/api/**' matches '/api/users' */
|
||
|
|
readonly appliesTo: string
|
||
|
|
/** Contracts organized by hook phase */
|
||
|
|
readonly hooks: {
|
||
|
|
readonly [phase: string]: {
|
||
|
|
/** Preconditions that must hold before this phase executes */
|
||
|
|
readonly requires?: readonly string[]
|
||
|
|
/** Postconditions that must hold after this phase executes */
|
||
|
|
readonly ensures?: readonly string[]
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/** Plugin metadata for diagnostics */
|
||
|
|
readonly meta?: {
|
||
|
|
readonly name?: string
|
||
|
|
readonly version?: string
|
||
|
|
readonly description?: string
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Lazy extension references — Apophis extensions this plugin needs.
|
||
|
|
* Extensions are resolved at test time from the extension registry.
|
||
|
|
* If a required extension is missing, the plugin's contracts are skipped with a warning.
|
||
|
|
*/
|
||
|
|
readonly extensions?: ReadonlyArray<{
|
||
|
|
readonly name: string
|
||
|
|
readonly required?: boolean
|
||
|
|
}>
|
||
|
|
}
|
||
|
|
export interface ComposedContract {
|
||
|
|
readonly route: RouteContract
|
||
|
|
phases: {
|
||
|
|
[phase: string]: {
|
||
|
|
requires: Array<{ formula: string; source: 'route' | `plugin:${string}` }>
|
||
|
|
ensures: Array<{ formula: string; source: 'route' | `plugin:${string}` }>
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|