Skip to content
GitHubXDiscord

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 { createCheck } from '@triggery/core';
function createCheck<C extends Record<string, unknown>>(
  conditions: C,
): CheckCtx<C>;
ParamTypeDescription
conditionsRecord<string, unknown>Snapshot map of condition values. Pass the same shape the runtime gives to handlers.

A CheckCtx object:

MethodSignatureResult
is(key, predicate)(key, value => boolean) => booleantrue when the condition exists (non-null) and the predicate returns truthy.
all(map)({ key: predicate, … }) => booleanEvery listed condition must exist and pass its predicate.
any(map)({ key: predicate, … }) => booleanAt least one listed condition must exist and pass its predicate.

You normally use ctx.check instead of constructing your own:

import { createTriggerfunction 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).
@example```ts const messageTrigger = createTrigger<{ events: { 'new-message': { author: string; text: string } }; conditions: { user: { id: string }; settings: { sound: boolean } }; actions: { showToast: { title: string }; playSound: void }; }>({ id: 'message-received', events: ['new-message'], required: ['user', 'settings'], handler({ event, conditions, actions, check }) { if (!conditions.user || !conditions.settings) return; // V1: manual narrowing if (check.is('settings', (s) => s.sound)) actions.playSound?.(); actions.showToast?.({ title: event.payload.author }); }, }); ```
} 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).
@example```ts const messageTrigger = createTrigger<{ events: { 'new-message': { author: string; text: string } }; conditions: { user: { id: string }; settings: { sound: boolean } }; actions: { showToast: { title: string }; playSound: void }; }>({ id: 'message-received', events: ['new-message'], required: ['user', 'settings'], handler({ event, conditions, actions, check }) { if (!conditions.user || !conditions.settings) return; // V1: manual narrowing if (check.is('settings', (s) => s.sound)) actions.playSound?.(); actions.showToast?.({ title: event.payload.author }); }, }); ```
<{
events
events: {
    ping: void;
}
: { pingping: void: void };
conditions
conditions: {
    user: {
        active: boolean;
    } | null;
    tenant: string | null;
}
: { user
user: {
    active: boolean;
} | null
: { activeactive: boolean: boolean } | null; tenanttenant: string | null: string | null };
}>({ idid: string: 'demo', eventsevents: 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;
}
.activeactive: boolean, tenanttenant: (t: string) => boolean: tt: string => tt: string.lengthString.length: number
Returns the length of a String object.
> 0 })) {
consolevar console: Console.logConsole.log(...data: any[]): void
The **`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 { createCheckfunction 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
: { activeactive: boolean: true, namename: string: 'Alice' } as { activeactive: boolean: boolean; namename: string: string } | null,
tenanttenant: 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;
}
.activeactive: 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;
}
.activeactive: boolean, tenanttenant: (t: string) => boolean: tt: string => tt: string.lengthString.length: number
Returns 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;
}
.activeactive: boolean }); // false
import { createCheckfunction 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 { activeactive: 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;
}
.activeactive: boolean); // false