UNPKG

2.5 kBTypeScriptView Raw
1import { SdmContext } from "../context/SdmContext";
2import { Goals } from "../goal/Goals";
3import { PushListenerInvocation } from "../listener/PushListener";
4import { GoalSettingStructure } from "../mapping/GoalSetter";
5import { Mapping } from "../mapping/Mapping";
6import { Predicated } from "../mapping/PredicateMapping";
7import { GoalComponent } from "./GoalComponent";
8export interface GoalContribution<F> extends Mapping<F, GoalComponent>, Predicated<F> {
9}
10/**
11 * Add state to an invocation. Only available in memory.
12 * @param S type of the fact to add.
13 */
14export interface StatefulInvocation<S> extends SdmContext {
15 facts?: S;
16}
17export declare type DefaultFacts = Record<string, any>;
18/**
19 * Within evaluation of push rules we can manage state on a push.
20 * This interface allows state. This state will not be persisted.
21 */
22export interface StatefulPushListenerInvocation<S = DefaultFacts> extends PushListenerInvocation, StatefulInvocation<S> {
23}
24/**
25 * Enrich the invocation, attaching some facts.
26 * The returned object will be merged with any facts already on the invocation.
27 * @param {(f: (StatefulInvocation<FACT>)) => Promise<FACT>} compute additional facts.
28 * @return {GoalContribution<F>}
29 */
30export declare function attachFacts<FACT, F extends SdmContext = PushListenerInvocation>(compute: (f: F) => Promise<FACT>): GoalContribution<F>;
31/**
32 * Contribute goals based on a series of contribution rules.
33 *
34 * Instead of stopping at the first match, each push will get _all_ the goals it qualifies for.
35 *
36 * Duplicates will be removed.
37 *
38 * @param contributor first contributor
39 * @param {GoalContribution<F>} contributors
40 * @return a mapping to goals
41 */
42export declare function goalContributors<F extends SdmContext = StatefulPushListenerInvocation<any>>(contributor: GoalContribution<F>, ...contributors: Array<GoalContribution<F>>): Mapping<F, Goals>;
43/**
44 * Enrich the given push mapping with our own contributions
45 * @param {Mapping<F extends SdmContext, Goals>} mapping
46 * @param {GoalContribution<F extends SdmContext>} contributor
47 * @param {GoalContribution<F extends SdmContext>} contributors
48 * @return {Mapping<F extends SdmContext, Goals>}
49 */
50export declare function enrichGoalSetters<F extends SdmContext = StatefulPushListenerInvocation<any>>(mapping: GoalContribution<F>, contributor: GoalContribution<F>, ...contributors: Array<GoalContribution<F>>): Mapping<F, Goals> & GoalSettingStructure<F, Goals>;
51//# sourceMappingURL=goalContribution.d.ts.map
\No newline at end of file