ApiCoreFunctions
Function: contract()
function contract<C>(
schema,
that,
why
): Contract;Defined in: packages/core/src/records/contract-builder.ts:582
One condition of a contract, built in TypeScript: body is typed from
schema (a collection definition, a validator, or JSON Schema), and the
result is the { that, else } a definition's contract.check holds.
const famous = contract(Fame, ({ body, versions, link }) =>
versions(body.reactions)
.where((r) => r.collection.eq('app.reaction').and(r.link('on').eq(link('on'))))
.map((r) => r.author)
.distinct()
.count()
.gte(5),
'Needs five different people',
);Throws when what it builds is not a condition the library would define.
Type Parameters
| Type Parameter |
|---|
C extends object |
Parameters
| Parameter | Type |
|---|---|
schema | C |
that | (scope) => BoolLike |
why | string |