Entity / Operators

Test a primitive operator's claims

A claim states a property you expect each implementation to keep. For example, a commutative operator gives the same result when you swap its two inputs. Use Operation.define from @doeixd/metakit/operation to declare claims beside the argument and result schemas. Use checkOperation from @doeixd/metakit/conformance to test an implementation against those claims.

ts
import { Schema } from 'effect'
import { checkOperation } from '@doeixd/metakit/conformance'
import * as Operation from '@doeixd/metakit/operation'

const either = Operation.define({
  id: 'acme.either',
  version: 1,
  args: [Schema.Boolean, Schema.Boolean],
  returns: Schema.Boolean,
  nulls: 'strict',
  claims: { commutative: true },
})
const memory = Operation.implementations(
  'memory',
  Operation.implement(either, (left, right) => left || right),
)
const report = checkOperation(either, memory)

report.ok is true for this implementation. Read report.failures to see why a check failed, including the arguments and results when a call breaks a claim. The checks combine fixed cases with seeded samples. Pass SQL runners in the sql option to compare the recorded calls that returned a value or null in memory.

If you declare an operator using Expr.operator, use claims to declare its algebraic properties. Check its Entity implementations against each other with Conformance.operator from foldkit-entity/conformance.

Publishing what a server runs

Operators.describe(op) and Operators.describeTable(table) emit metadata with the ID, version, input and output schemas, null and collation rules, and declared claims. OperatorDescription decodes a description from another service.

Versions form part of the operator's identity: a table providing acme.slug (v1) refuses a query calling acme.slug@2 with acme.slug@2 (this table has acme.slug) so client/server deploy skew surfaces immediately.