-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtypes.js
186 lines (182 loc) · 7.2 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//@ts-check
/**
* @typedef {Boolean} True the `true` boolean value
*/
/**
* @typedef {Array<MachineOutput> | null} FSM_Outputs
*/
/**
* @typedef {Object} FSM_Internal_State
* @property {String} cs control state
* @property {HistoryState} hs history state
* @property {ExtendedState} es extended state
*/
/**
* @callback Stateful_FSM
* @param {*} input
* @returns {FSM_Outputs|Error}
*/
/**
* @callback Pure_FSM
* @param {*} input
* @param {FSM_Internal_State} fsm_state
* @returns {{outputs: FSM_Outputs|Error, fsmState: FSM_Internal_State}}
*/
/**
* @typedef {Object} FSM_Def
* @property {FSM_States} states Object whose every key is a control state admitted by the
* specified state machine. The value associated to that key is unused in the present version of the library. The
* hierarchy of the states correspond to property nesting in the `states` object
* @property {Array<EventLabel>} events A list of event monikers the machine is configured to react to
* @property {Array<Transition>} transitions An array of transitions the machine is allowed to take
* @property {*} initialExtendedState The initial value for the machine's extended state
* @property {function(ExtendedState, ExtendedStateUpdate) : ExtendedState} updateState function
* which update the extended state of the state machine
*/
/**
* @typedef {Object.<ControlState, *>} FSM_States
*/
/**
* @typedef {InconditionalTransition | ConditionalTransition} Transition
*/
/**
* @typedef {{from: ControlState, to: ControlState|HistoryState, event?: EventLabel, action: ActionFactory}} InconditionalTransition
* Inconditional_Transition encodes transition with no guards attached. Every time the specified event occurs, and
* the machine is in the specified state, it will transition to the target control state, and invoke the action
* returned by the action factory
*/
/**
* @typedef {{from: ControlState, event?: EventLabel, guards: Array<Condition>}} ConditionalTransition Transition for the
* specified state is contingent to some guards being passed. Those guards are defined as an array.
*/
/**
* @typedef {{predicate: FSM_Predicate, to: ControlState|HistoryState, action: ActionFactory}} Condition On satisfying the
* specified predicate, the received event data will trigger the transition to the specified target control state
* and invoke the action created by the specified action factory, leading to an update of the internal state of the
* extended state machine and possibly an output to the state machine client.
*/
/**
* @typedef {function(ExtendedState, EventData, FSM_Settings) : Actions} ActionFactory
*/
/**
* @typedef {{updates: ExtendedStateUpdate, outputs: Array<MachineOutput>}} Actions The actions
* to be performed by the state machine in response to a transition. `updates` represents the state update for
* the variables of the extended state machine. `output` represents the output of the state machine passed to the
* API caller.
*/
/** @typedef {function (ExtendedState, EventData) : Boolean} FSM_Predicate */
/**
* @typedef {Object} Debug_Settings
* @property {*} checkContracts opaque type. Just use the fsmContracts that is exported by Kingly.
* @property {Console} console object with the same properties as console in a browser environment.
* Can be used to fake or stub the console for logging purposes or outside browser environments.
*
* */
/** @typedef {Object} DevTool_Settings
* @property {*} tracer opaque type. Just use the tracer provided by the Courtesan extension.
* */
/** @typedef {Object|{}} FSM_Settings
* @property {Debug_Settings} [debug]
* @property {DevTool_Settings} [devTool]
* @property {String} [displayName]
* Miscellaneous settings including how to update the machine's state and debug
* configuration
* */
/**
* @typedef {Object.<EventLabel, EventData>} LabelledEvent extended state for a given state machine
*/
/**
* @typedef {Object} FsmTraceData
* @property {ControlState} controlState
* @property {{EventLabel, EventData}} eventLabel
* @property {ControlState} targetControlState
* @property {FSM_Predicate} predicate
* @property {ExtendedStateUpdate} updates
* @property {ExtendedState} extendedState
* @property {ActionFactory} actionFactory
* @property {Number} guardIndex
* @property {Number} transitionIndex
*/
/**
* @typedef {function(HistoryType, ControlState): HistoryState} HistoryStateFactory
*/
/**
* @typedef {Object.<HistoryType, HistoryDict>} HistoryState history object containing deeep and shallow history states
* for all relevant control states
*/
/**
* @typedef {Object.<ControlState, ControlState>} HistoryDict Maps a compound control state to its history state
*/
/**
* @typedef {"deep" | "shallow"} HistoryType
*/
/** @typedef {String} ControlState Name of the control state */
/** @typedef {String} EventLabel */
/**
* @typedef {*} EventData
*/
/**
* @typedef {*} ExtendedState extended state for a given state machine
*/
/**
* @typedef {*} ExtendedStateUpdate
*/
/** @typedef {null} NO_OUTPUT
/** @typedef {* | NO_OUTPUT} MachineOutput well it is preferrable that that be an object instead of a primitive */
// Contract types
/**
* @typedef {Object} ContractsDef
* @property {String} description name for the series of contracts
* @property {function(FSM_Def):Object} injected a function of the machine definition which returns an object to be
* injected to the contracts predicates
* @property {Array<ContractDef>} contracts array of contract definitions
*/
/**
* @typedef {Object} ContractDef
* @property {String} name name for the contract
* @property {Boolean} shouldThrow whether the contract should thrown an exception or alternatively return one
* @property {function(FSM_Def, *):ContractCheck} predicate array of contract definitions
*/
/**
* @typedef {Object} ContractCheck
* @property {Boolean} isFulfilled whether the contract is fulfilled
* @property {{message:String, info:*}} blame information about the cause for the contract failure. The
* `message` property is destined to the developer (for instnce can be printed in the console). Info aims
* at providing additional data helping to track the error cause
* @property {function(FSM_Def, *):ContractCheck} predicate array of contract definitions
*/
// Component types
/**
* @typedef {String} CommandName
*/
/**
* @typedef {function(SubjectEmitter, CommandParams, EffectHandlers, Element, Subject): *} CommandHandler
* A command handler performs effect, possibly relying on effects implementation included in the effect handlers
* parameter. A command handler also receives parameters for its execution and two subjects, one for receiving
* events, another one for emitting them (currently unused). Lastly, a command handler may
* receive an Element which is generally used for rendering purposes
*/
/**
* @typedef {*} Operation
*/
/**
* @typedef {*} CommandParams
*//**
* @typedef {*} EffectHandlers
*/
/**
* @typedef {function(*):*} SubjectEmitter
*/
/**
* @typedef {Object} AnonymousObserver
* @property {SubjectEmitter} next
* @property {function(*):*} [error]
* @property {function(*):*} [complete]
*/
/**
* @typedef {Object} Subject
* @property {function(AnonymousObserver):*} subscribe
* @property {function(*):*} next
* @property {function(*):*} [error]
* @property {function(*):*} [complete]
*/