/**
 * Central invariants registry — SSoT for system-wide invariants surfaced via
 * the SaGa T10326 SG-SUBSTRATE-RECONCILIATION programme (Epic T10327
 * E-INVARIANT-REGISTRY-SSOT, Task T10335 R1).
 *
 * Every registered invariant carries the metadata needed to:
 * 1. Reference its source ADR (e.g. `ADR-073` §1.2 for I1-I8).
 * 2. Locate the runtime guard that enforces it (when one exists).
 * 3. Bind the CI lint rule that protects it (when one exists).
 * 4. Cross-reference test files that exercise it.
 * 5. Render documentation via the downstream R8 auto-render pipeline.
 *
 * Downstream consumers:
 * - R2 (T10336, SHIPPED): registers ADR-070 ORC-001..ORC-014 codes into
 *   this same registry via `./adr-070-orchestration.ts`.
 * - R4 (T10338): CI gate validates that every `severity:'error'` entry has
 *   a non-null `runtimeGate` AND a matching error-code in `errors.ts`.
 * - R5 (T10339): refactor `packages/core/src/release/invariants/registry.ts`
 *   to consume the central registry instead of carrying its own list.
 * - R6 (T10340): `cleo doctor --audit-invariants` walks the registry to
 *   produce a per-invariant audit report.
 * - R8 (T10342): auto-render docs page from the registry.
 *
 * @epic T10327 — E-INVARIANT-REGISTRY-SSOT
 * @saga T10326 — SG-SUBSTRATE-RECONCILIATION
 * @task T10335 — R1: registry + ADR-073 I1-I8
 * @see ADR-073-above-epic-naming.md §1.2
 */
import { ADR_056_INVARIANTS } from './adr-056-release.js';
import { ADR_070_INVARIANTS } from './adr-070-orchestration.js';
import { ADR_073_INVARIANTS } from './adr-073-saga.js';
// Re-exported so consumers can import either the per-ADR list or the merged
// registry from one place.
export { ADR_056_INVARIANTS } from './adr-056-release.js';
export { ADR_070_INVARIANTS } from './adr-070-orchestration.js';
export { ADR_073_INVARIANTS } from './adr-073-saga.js';
/**
 * Compute the canonical registry key for an invariant.
 *
 * @internal
 */
function buildKey(invariant) {
    return `${invariant.adr}.${invariant.code}`;
}
/**
 * Build the merged registry record from all per-ADR invariant modules.
 *
 * Future ADR modules (ADR-070 ORC codes via R2 T10336, etc.) append to
 * the spread list below. Each module exports a `readonly RegisteredInvariant[]`
 * — this index assembles them into a keyed record at module load time.
 *
 * @internal
 */
function buildRegistry() {
    const entries = [
        ...ADR_073_INVARIANTS,
        ...ADR_056_INVARIANTS,
        ...ADR_070_INVARIANTS,
    ];
    const record = {};
    for (const entry of entries) {
        const key = buildKey(entry);
        if (record[key] !== undefined) {
            throw new Error(`Duplicate invariant key registered: ${key}`);
        }
        record[key] = entry;
    }
    return Object.freeze(record);
}
/**
 * Central invariants registry — keyed by `${adr}.${code}`.
 *
 * Treat as read-only at runtime. Mutating this record is a contract
 * violation; downstream consumers (R5 release-registry refactor, R6
 * doctor audit, R8 docs renderer) assume immutability.
 *
 * @example
 * ```ts
 * import { INVARIANTS_REGISTRY } from '@cleocode/contracts';
 * const i3 = INVARIANTS_REGISTRY['ADR-073.I3'];
 * if (i3?.runtimeGate) {
 *   console.log(`Guard: ${i3.runtimeGate.functionName}`);
 * }
 * ```
 */
export const INVARIANTS_REGISTRY = buildRegistry();
/**
 * Look up a single invariant by its `${adr}.${code}` key.
 *
 * @example
 * ```ts
 * const i3 = getInvariant('ADR-073.I3');
 * // → RegisteredInvariant for ADR-073 invariant I3
 * ```
 */
export function getInvariant(adrCode) {
    return INVARIANTS_REGISTRY[adrCode];
}
/**
 * Return every invariant registered against a given ADR, in declaration order.
 *
 * @example
 * ```ts
 * const adr073 = getInvariantsByAdr('ADR-073');
 * // → array of I1..I8 entries
 * ```
 */
export function getInvariantsByAdr(adr) {
    const result = [];
    for (const key of Object.keys(INVARIANTS_REGISTRY)) {
        const entry = INVARIANTS_REGISTRY[key];
        if (entry !== undefined && entry.adr === adr) {
            result.push(entry);
        }
    }
    return result;
}
//# sourceMappingURL=index.js.map