createCheck
Stable · since 0.1.0
Builds the check helper that handlers receive via ctx.check. The runtime wires this for you on every run — createCheck is exported only for the rare cases where you need the same predicate DSL outside the handler context (custom middleware, condition-based testing, devtools panels).
is, all and any accept predicates over NonNullable<C[K]>. When a condition value is undefined or null, the predicate is never called and the result is false for that key.
Import
Section titled “Import”import { createCheck } from '@triggery/core';
Signature
Section titled “Signature”function createCheck<C extends Record<string, unknown>>(
conditions: C,
): CheckCtx<C>;Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
conditions | Record<string, unknown> | Snapshot map of condition values. Pass the same shape the runtime gives to handlers. |
Returns
Section titled “Returns”A CheckCtx object:
| Method | Signature | Result |
|---|---|---|
is(key, predicate) | (key, value => boolean) => boolean | true when the condition exists (non-null) and the predicate returns truthy. |
all(map) | ({ key: predicate, … }) => boolean | Every listed condition must exist and pass its predicate. |
any(map) | ({ key: predicate, … }) => boolean | At least one listed condition must exist and pass its predicate. |
Examples
Section titled “Examples”Inside a handler (the common case)
Section titled “Inside a handler (the common case)”You normally use ctx.check instead of constructing your own:
import { createTrigger function createTrigger<S extends TriggerSchema>(config: CreateTriggerConfig<S>, runtime?: Runtime): Trigger<S>Create a trigger and register it in a runtime (the default runtime if none is passed). } from '@triggery/core';
createTrigger createTrigger<{
events: {
ping: void;
};
conditions: {
user: {
active: boolean;
} | null;
tenant: string | null;
};
}>(config: CreateTriggerConfig<{
events: {
ping: void;
};
conditions: {
user: {
active: boolean;
} | null;
tenant: string | null;
};
}>, runtime?: Runtime): Trigger<{
events: {
ping: void;
};
conditions: {
user: {
active: boolean;
} | null;
tenant: string | null;
};
}>
Create a trigger and register it in a runtime (the default runtime if none is passed). <{
events events: {
ping: void;
}
: { ping ping: void : void };
conditions conditions: {
user: {
active: boolean;
} | null;
tenant: string | null;
}
: { user user: {
active: boolean;
} | null
: { active active: boolean : boolean } | null; tenant tenant: string | null : string | null };
}>({
id id: string : 'demo',
events events: readonly "ping"[] : ['ping'],
handler handler: TriggerHandler<{
events: {
ping: void;
};
conditions: {
user: {
active: boolean;
} | null;
tenant: string | null;
};
}, never>
({ check check: CheckCtx<{
user: {
active: boolean;
} | null;
tenant: string | null;
}>
}) {
if (check check: CheckCtx<{
user: {
active: boolean;
} | null;
tenant: string | null;
}>
.all all<{
user: (u: {
active: boolean;
}) => boolean;
tenant: (t: string) => boolean;
}>(map: {
user: (u: {
active: boolean;
}) => boolean;
tenant: (t: string) => boolean;
}): boolean
({ user user: (u: {
active: boolean;
}) => boolean
: u u: {
active: boolean;
}
=> u u: {
active: boolean;
}
.active active: boolean , tenant tenant: (t: string) => boolean : t t: string => t t: string .length String.length: numberReturns the length of a String object. > 0 })) {
console var console: Console .log Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) ('go');
}
},
});Standalone (advanced — outside a handler)
Section titled “Standalone (advanced — outside a handler)”import { createCheck function createCheck<C extends Record<string, unknown>>(conditions: C): CheckCtx<C>Builds the `check` helper bound to a specific conditions snapshot.
`is`, `all` and `any` accept predicates over `NonNullable<C[K]>`: if a condition is
absent (`undefined` or `null`), the predicate is not invoked and the result is `false`
for that key. } from '@triggery/core';
const check const check: CheckCtx<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>
= createCheck createCheck<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>(conditions: {
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}): CheckCtx<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>
Builds the `check` helper bound to a specific conditions snapshot.
`is`, `all` and `any` accept predicates over `NonNullable<C[K]>`: if a condition is
absent (`undefined` or `null`), the predicate is not invoked and the result is `false`
for that key. ({
user user: {
active: boolean;
name: string;
} | null
: { active active: boolean : true, name name: string : 'Alice' } as { active active: boolean : boolean; name name: string : string } | null,
tenant tenant: string | null : 'acme-corp' as string | null,
});
check const check: CheckCtx<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>
.is is<"user">(key: "user", predicate: (value: {
active: boolean;
name: string;
}) => boolean): boolean
('user', u u: {
active: boolean;
name: string;
}
=> u u: {
active: boolean;
name: string;
}
.active active: boolean ); // true
check const check: CheckCtx<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>
.all all<{
user: (u: {
active: boolean;
name: string;
}) => boolean;
tenant: (t: string) => boolean;
}>(map: {
user: (u: {
active: boolean;
name: string;
}) => boolean;
tenant: (t: string) => boolean;
}): boolean
({ user user: (u: {
active: boolean;
name: string;
}) => boolean
: u u: {
active: boolean;
name: string;
}
=> u u: {
active: boolean;
name: string;
}
.active active: boolean , tenant tenant: (t: string) => boolean : t t: string => t t: string .length String.length: numberReturns the length of a String object. > 0 }); // true
check const check: CheckCtx<{
user: {
active: boolean;
name: string;
} | null;
tenant: string | null;
}>
.any any<{
user: (u: {
active: boolean;
name: string;
}) => boolean;
}>(map: {
user: (u: {
active: boolean;
name: string;
}) => boolean;
}): boolean
({ user user: (u: {
active: boolean;
name: string;
}) => boolean
: u u: {
active: boolean;
name: string;
}
=> !u u: {
active: boolean;
name: string;
}
.active active: boolean }); // falseNull safety
Section titled “Null safety”import { createCheck function createCheck<C extends Record<string, unknown>>(conditions: C): CheckCtx<C>Builds the `check` helper bound to a specific conditions snapshot.
`is`, `all` and `any` accept predicates over `NonNullable<C[K]>`: if a condition is
absent (`undefined` or `null`), the predicate is not invoked and the result is `false`
for that key. } from '@triggery/core';
const check const check: CheckCtx<{
user: {
active: boolean;
} | null;
}>
= createCheck createCheck<{
user: {
active: boolean;
} | null;
}>(conditions: {
user: {
active: boolean;
} | null;
}): CheckCtx<{
user: {
active: boolean;
} | null;
}>
Builds the `check` helper bound to a specific conditions snapshot.
`is`, `all` and `any` accept predicates over `NonNullable<C[K]>`: if a condition is
absent (`undefined` or `null`), the predicate is not invoked and the result is `false`
for that key. ({ user user: {
active: boolean;
} | null
: null as { active active: boolean : boolean } | null });
// Predicate is never invoked when the value is null — no NPE risk.
check const check: CheckCtx<{
user: {
active: boolean;
} | null;
}>
.is is<"user">(key: "user", predicate: (value: {
active: boolean;
}) => boolean): boolean
('user', u u: {
active: boolean;
}
=> u u: {
active: boolean;
}
.active active: boolean ); // falseRelated
Section titled “Related” createTrigger The handler receives a `check` instance automatically.
TriggerCtx Full handler context type, including `check`.
Conditions guide When to read conditions directly vs through `check`.
Required limitation Why `check` exists at all — V1 narrowing notes.