Function: defineContract()

August 8, 2026 ยท View on GitHub

@plures/praxis


@plures/praxis / index / defineContract

Function: defineContract()

defineContract(options): Contract

Defined in: packages/praxis-core/src/decision-ledger/types.ts:146

Define a contract for a rule or constraint.

Parameters

options

DefineContractOptions

Contract definition options including ruleId, behavior, examples, and invariants

Returns

Contract

A fully constructed Contract with a generated timestamp and default version

Example

const loginContract = defineContract({
  ruleId: 'auth.login',
  behavior: 'Process login events and create user session facts',
  examples: [
    {
      given: 'User provides valid credentials',
      when: 'LOGIN event is received',
      then: 'UserSessionCreated fact is emitted'
    }
  ],
  invariants: ['Session must have unique ID']
});