Metakit / Domain types and row aggregates

Model domain types and row aggregates

Using plain number for money, Date for calendar dates, and plain strings for ordered statuses lets subtle bugs compile: adding USD to EUR, shifting a due date across a timezone boundary, or sorting "pro" after "free" alphabetically.

@doeixd/metakit/domain, a subpath of the @doeixd/metakit package (pnpm add @doeixd/metakit effect), gives you branded integer-backed Effect Schemas, Money, Decimal, CalendarDay and OrderedEnum, whose operations are exact integer arithmetic in JavaScript, in SQL and in the Z3 solver. @doeixd/metakit/aggregates adds row summaries (sum, count, min, max, every, any) that update by adding or removing one row's contribution (a delta) instead of adding every row again, and @doeixd/metakit/aggregates/sql compiles them to SQL.

The code blocks continue one file: Schema, Expr, Num and the first block's imports stay in scope. Expr.refine attaches a rule to a Schema as data, Expr.in builds an expression over named inputs, and Expr.eval runs one in memory.