@flowerforce/flower-core 3.1.1 → 3.1.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,6 @@
1
1
  import { CoreUtilitiesFunctions } from './interfaces/CoreInterface';
2
2
  export declare const flattenRules: (ob: Record<string, any>) => Record<string, any>;
3
+ /**
4
+ * Defines a collection of utility functions for processing rules, nodes and graph-like structures
5
+ */
3
6
  export declare const CoreUtils: CoreUtilitiesFunctions;
@@ -1,2 +1,5 @@
1
1
  import { ReducersFunctions } from './interfaces/ReducerInterface';
2
+ /**
3
+ * These functions are Redux reducers used in a Flux architecture for managing state transitions and updates in a Flower application.
4
+ */
2
5
  export declare const FlowerCoreReducers: ReducersFunctions;
@@ -5,3 +5,5 @@ export { FlowerCoreStateSelectors as Selectors } from './FlowerCoreStateSelector
5
5
  export { CoreUtils } from './CoreUtils';
6
6
  export { MatchRules } from './RulesMatcher';
7
7
  export * from './interfaces';
8
+ declare const devtoolState: {};
9
+ export { devtoolState };
@@ -113,18 +113,105 @@ export type GenerateRulesName = (nextRules: RulesWithName[]) => {
113
113
  [X: string]: string;
114
114
  };
115
115
  export interface CoreUtilitiesFunctions {
116
+ /**
117
+ *
118
+ * Generates rule names from a set of rules.
119
+ * @param nextRules
120
+ *
121
+ * @returns
122
+ *
123
+ */
116
124
  generateRulesName: GenerateRulesName;
125
+ /**
126
+ * Recursively maps keys of an object using a callback function.
127
+ * @param obj
128
+ * @param cb
129
+ * @param isRecursive
130
+ *
131
+ * @returns
132
+ */
117
133
  mapKeysDeepLodash: MapKeysDeepLodash;
134
+ /**
135
+ * Generates a object of nodes from an array of nodes, using nodeId as keys
136
+ * @param nodes
137
+ * @returns
138
+ */
118
139
  generateNodes: GenerateNodes;
140
+ /**
141
+ * Converts nodes into an object with node IDs as keys and their respective rules as values.
142
+ * @param nodes
143
+ *
144
+ * @returns
145
+ */
119
146
  makeObjectRules: MakeObjectRules;
147
+ /**
148
+ * Checks if a node exists within a specific state.
149
+ * @param state
150
+ * @param name
151
+ * @param node
152
+ *
153
+ * @returns
154
+ */
120
155
  hasNode: HasNode;
156
+ /**
157
+ * Checks if a set of rules is empty.
158
+ * @param rules
159
+ *
160
+ * @returns
161
+ */
121
162
  isEmptyRules: IsEmptyRules;
163
+ /**
164
+ * Maps edges and sorts them moving empty rules to the bottom.
165
+ * @param nextNode
166
+ *
167
+ * @returns
168
+ */
122
169
  mapEdge: MapEdge;
170
+ /**
171
+ * Converts a rules object into an array of rule objects.
172
+ * @param rules
173
+ *
174
+ * @returns
175
+ */
123
176
  makeRules: MakeRules;
177
+ /**
178
+ * Generates nodes for a flower JSON structure, extracting rules and other properties.
179
+ * @param nodes
180
+ *
181
+ * @returns
182
+ */
124
183
  generateNodesForFlowerJson: GenerateNodesForFlowerJson;
184
+ /**
185
+ * Removes specified characters from the beginning of a string (default char -> '^').
186
+ * @param name
187
+ * @param char
188
+ *
189
+ * @returns
190
+ */
125
191
  cleanPath: CleanPath;
192
+ /**
193
+ * Creates a valid path from idValue
194
+ * @param idValue
195
+ *
196
+ * @returns
197
+ */
126
198
  getPath: GetPath;
199
+ /**
200
+ * Checks if two arrays are equal in length and have the same elements.
201
+ * @param arr
202
+ * @param arr2
203
+ *
204
+ * @returns
205
+ */
127
206
  allEqual: AllEqual;
207
+ /**
208
+ * Finds the first valid rule for a given value within a set of rules.
209
+ * @param nextRules
210
+ * @param value
211
+ * @param prefix
212
+ *
213
+ * @returns
214
+ */
128
215
  findValidRule: FindValidRule;
129
216
  }
130
217
  export {};
@@ -6,58 +6,170 @@ export type ActionWithPayload<T> = {
6
6
  };
7
7
  type ReducerFunctionSign<T extends object, R> = (state: Record<string, Flower<T>>, action: ActionWithPayload<R>) => Record<string, Flower<T>> | void;
8
8
  export type ActionsTypes = 'historyAdd' | 'historyPrevToNode' | 'setFormTouched' | 'forceAddHistory' | 'historyPop' | 'restoreHistory' | 'replaceNode' | 'initializeFromNode' | 'forceResetHistory' | 'destroy' | 'initNodes' | 'setCurrentNode' | 'formAddErrors' | 'formRemoveErrors' | 'addData' | 'addDataByPath' | 'replaceData' | 'unsetData' | 'setFormIsValidating' | 'node' | 'prevToNode' | 'next' | 'prev' | 'reset';
9
+ /**
10
+ * These functions are Redux reducers used in a Flux architecture for managing state transitions and updates in a Flower application.
11
+ */
9
12
  export type ReducersFunctions<T extends Record<string, any> = Record<string, Flower<Record<string, any>>>> = {
13
+ /**
14
+ * @param state
15
+ * @param action
16
+ *
17
+ * Adds a node to the history of a specific flow if the node exists.
18
+ *
19
+ * @returns state
20
+ */
10
21
  historyAdd: ReducerFunctionSign<T, {
11
22
  name: string;
12
23
  node: string;
13
24
  }>;
25
+ /**
26
+ * @param state
27
+ * @param action
28
+ *
29
+ * Navigates to a specific node in the history of a flow.
30
+ *
31
+ * @returns state
32
+ */
14
33
  historyPrevToNode: ReducerFunctionSign<T, {
15
34
  name: string;
16
35
  node: string;
17
36
  } | string>;
37
+ /**
38
+ * @param state
39
+ * @param action
40
+ *
41
+ * Sets the "touched" state of a form node in a flow.
42
+ *
43
+ * @returns state
44
+ */
18
45
  setFormTouched: ReducerFunctionSign<T, {
19
46
  flowName: string;
20
47
  currentNode: string;
21
48
  } | string>;
49
+ /**
50
+ * @param state
51
+ * @param action
52
+ *
53
+ * Adds multiple nodes to the history of a flow, starting from a specified index.
54
+ *
55
+ * @returns state
56
+ */
22
57
  forceAddHistory: ReducerFunctionSign<T, {
23
58
  history: string[];
24
59
  name?: string;
25
60
  flowName?: string;
26
61
  }>;
62
+ /**
63
+ * @param state
64
+ * @param action
65
+ *
66
+ * Removes the current node from the history of a flow.
67
+ *
68
+ * @returns state
69
+ */
27
70
  historyPop: ReducerFunctionSign<T, {
28
71
  name: string;
29
72
  }>;
73
+ /**
74
+ * @param state
75
+ * @param action
76
+ *
77
+ * Restores the history of a flow to its initial state.
78
+ *
79
+ * @returns state
80
+ */
30
81
  restoreHistory: ReducerFunctionSign<T, {
31
82
  name: string;
32
83
  }>;
84
+ /**
85
+ * @param state
86
+ * @param action
87
+ *
88
+ * Replaces the current node in a flow with a specified node.
89
+ *
90
+ * @returns state
91
+ */
33
92
  replaceNode: ReducerFunctionSign<T, {
34
93
  node: string;
35
94
  name?: string;
36
95
  flowName?: string;
37
96
  }>;
97
+ /**
98
+ * @param state
99
+ * @param action
100
+ *
101
+ * Initializes a flow from a specific node.
102
+ *
103
+ * @returns state
104
+ */
38
105
  initializeFromNode: ReducerFunctionSign<T, {
39
106
  node: string;
40
107
  name?: string;
41
108
  flowName?: string;
42
109
  }>;
110
+ /**
111
+ * @param state
112
+ * @param action
113
+ *
114
+ * Resets the history of a flow forcefully.
115
+ *
116
+ * @returns state
117
+ */
43
118
  forceResetHistory: ReducerFunctionSign<T, {
44
119
  name?: string;
45
120
  flowName?: string;
46
121
  }>;
122
+ /**
123
+ * @param state
124
+ * @param action
125
+ *
126
+ * Destroys a flow by removing it from the state.
127
+ *
128
+ * @returns state
129
+ */
47
130
  destroy: ReducerFunctionSign<T, {
48
131
  name: string;
49
132
  }>;
133
+ /**
134
+ * @param state
135
+ * @param action
136
+ *
137
+ * Initializes the nodes of a flow, setting its initial state and generating necessary data structures.
138
+ *
139
+ * @returns state
140
+ */
50
141
  initNodes: ReducerFunctionSign<T, {
51
142
  name: string;
52
143
  startId: string;
53
144
  persist: boolean;
54
145
  nodes: Node[];
55
146
  initialData: any;
147
+ initialState: {
148
+ startId?: string;
149
+ current?: string;
150
+ history?: string[];
151
+ };
56
152
  }>;
153
+ /**
154
+ * @param state
155
+ * @param action
156
+ *
157
+ * Sets the current node of a flow to a specified node.
158
+ *
159
+ * @returns state
160
+ */
57
161
  setCurrentNode: ReducerFunctionSign<T, {
58
162
  name: string;
59
163
  node: string;
60
164
  }>;
165
+ /**
166
+ * @param state
167
+ * @param action
168
+ *
169
+ * Adds errors to a form node in a flow.
170
+ *
171
+ * @returns state
172
+ */
61
173
  formAddErrors: ReducerFunctionSign<T, {
62
174
  name: string;
63
175
  currentNode: string;
@@ -66,33 +178,89 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
66
178
  [x: string]: string[];
67
179
  } | string[];
68
180
  }>;
181
+ /**
182
+ * @param state
183
+ * @param action
184
+ *
185
+ * Removes errors from a form node in a flow.
186
+ *
187
+ * @returns state
188
+ */
69
189
  formRemoveErrors: ReducerFunctionSign<T, {
70
190
  name: string;
71
191
  currentNode: string;
72
192
  id: string;
73
193
  }>;
194
+ /**
195
+ * @param state
196
+ * @param action
197
+ *
198
+ * Adds data to a flow.
199
+ *
200
+ * @returns state
201
+ */
74
202
  addData: ReducerFunctionSign<T, {
75
203
  flowName: string;
76
204
  value: T;
77
205
  }>;
206
+ /**
207
+ * @param state
208
+ * @param action
209
+ *
210
+ * Adds data to a flow at a specific path.
211
+ *
212
+ * @returns state
213
+ */
78
214
  addDataByPath: ReducerFunctionSign<T, {
79
215
  id: string[];
80
216
  flowName: string;
81
217
  value: T | string;
82
218
  }>;
219
+ /**
220
+ * @param state
221
+ * @param action
222
+ *
223
+ * Replaces the data of a flow with new data.
224
+ *
225
+ * @returns state
226
+ */
83
227
  replaceData: ReducerFunctionSign<T, {
84
228
  flowName: string;
85
229
  value: T;
86
230
  }>;
231
+ /**
232
+ * @param state
233
+ * @param action
234
+ *
235
+ * Unsets data from a flow at a specific path.
236
+ *
237
+ * @returns state
238
+ */
87
239
  unsetData: ReducerFunctionSign<T, {
88
240
  id: string[] | string;
89
241
  flowName: string;
90
242
  }>;
243
+ /**
244
+ * @param state
245
+ * @param action
246
+ *
247
+ * Sets the "isValidating" state of a form node in a flow.
248
+ *
249
+ * @returns state
250
+ */
91
251
  setFormIsValidating: ReducerFunctionSign<T, {
92
252
  name: string;
93
253
  currentNode: string;
94
254
  isValidating?: boolean;
95
255
  }>;
256
+ /**
257
+ * @param state
258
+ * @param action
259
+ *
260
+ * Handles node transitions in a flow, updating history and form states accordingly.
261
+ *
262
+ * @returns state
263
+ */
96
264
  node: ReducerFunctionSign<T, {
97
265
  name: string;
98
266
  flowName?: string;
@@ -100,25 +268,65 @@ export type ReducersFunctions<T extends Record<string, any> = Record<string, Flo
100
268
  node?: string;
101
269
  history: string[];
102
270
  }>;
271
+ /**
272
+ * @param state
273
+ * @param action
274
+ *
275
+ * Navigates to a specific node in the history of a flow.
276
+ *
277
+ * @returns state
278
+ */
103
279
  prevToNode: ReducerFunctionSign<T, {
104
280
  name?: string;
105
281
  flowName?: string;
106
282
  node: string;
107
283
  }>;
284
+ /**
285
+ * @param state
286
+ * @param action
287
+ *
288
+ * Moves to the next node in a flow based on validation rules and current state.
289
+ *
290
+ * @returns state
291
+ */
108
292
  next: ReducerFunctionSign<T, {
109
293
  name?: string;
110
294
  flowName?: string;
111
295
  data: T;
112
296
  route?: string;
113
297
  }>;
298
+ /**
299
+ * @param state
300
+ * @param action
301
+ *
302
+ * Moves to the previous node in a flow.
303
+ *
304
+ * @returns state
305
+ */
114
306
  prev: ReducerFunctionSign<T, {
115
307
  name?: string;
116
308
  flowName?: string;
117
309
  }>;
310
+ /**
311
+ * @param state
312
+ * @param action
313
+ *
314
+ * Return back to the first node and resets history.
315
+ *
316
+ * @returns state
317
+ */
118
318
  restart: ReducerFunctionSign<T, {
119
319
  name?: string;
120
320
  flowName?: string;
121
321
  }>;
322
+ /**
323
+ * @param state
324
+ * @param action
325
+ *
326
+ * Returns back to the first node, resets history and clean all previous data from flow.
327
+ *
328
+ * @returns state
329
+ */
122
330
  reset: ReducerFunctionSign<T, {
123
331
  name?: string;
124
332
  flowName?: string;
@@ -1,6 +1,10 @@
1
1
  import { RulesObject } from './CoreInterface';
2
2
  import { Flower, Form, INode } from './Store';
3
3
  export interface ISelectors {
4
+ /**
5
+ * @param state
6
+ * @returns
7
+ */
4
8
  selectGlobal<T extends Record<string, any>>(state: {
5
9
  flower: {
6
10
  [x: string]: Flower<T>;
@@ -8,31 +12,97 @@ export interface ISelectors {
8
12
  }): {
9
13
  [x: string]: Flower<T>;
10
14
  };
15
+ /**
16
+ * @param name
17
+ * @returns
18
+ */
11
19
  selectFlower<T extends Record<string, any>>(name: string): (state: {
12
20
  [x: string]: Flower<T>;
13
21
  }) => Flower<T>;
22
+ /**
23
+ * @param id
24
+ * @returns
25
+ */
14
26
  selectFlowerFormNode<T extends Record<string, any>>(id: string): (state: Flower<T>) => Form<T>;
27
+ /**
28
+ * @param flower
29
+ * @returns
30
+ */
15
31
  selectFlowerHistory<T extends Record<string, any>>(flower: Flower<T>): Array<string>;
32
+ /**
33
+ * @param flower
34
+ * @returns
35
+ */
16
36
  makeSelectNodesIds<T extends Record<string, any>>(flower: Flower<T>): Flower<T>['nodes'];
37
+ /**
38
+ * @param flower
39
+ * @returns
40
+ */
17
41
  makeSelectStartNodeId<T extends Record<string, any>>(flower: Flower<T>): string;
42
+ /**
43
+ * @param flower
44
+ * @param startNodeId
45
+ * @returns
46
+ */
18
47
  makeSelectCurrentNodeId<T extends Record<string, any>>(flower: Flower<T>, startNodeId: Flower<T>['startId']): string;
48
+ /**
49
+ * @param nodes
50
+ * @param history
51
+ * @param current
52
+ * @returns
53
+ */
19
54
  makeSelectPrevNodeRetain<T extends Record<string, any>>(nodes: Flower<T>['nodes'], history: Flower<T>['history'], current: Flower<T>['current']): boolean | string | undefined;
55
+ /**
56
+ * @param nodes
57
+ * @param current
58
+ * @returns
59
+ */
20
60
  makeSelectCurrentNodeDisabled<T extends Record<string, any>>(nodes: {
21
61
  [x: string]: Partial<INode>;
22
62
  }, current: Flower<T>['current']): boolean;
63
+ /**
64
+ * @param form
65
+ * @returns
66
+ */
23
67
  makeSelectNodeErrors<T extends Record<string, any>>(form: Form<T> | undefined): {
24
68
  touched: boolean;
25
69
  errors: any;
26
70
  isValid: boolean;
27
71
  isValidating?: boolean;
28
72
  };
73
+ /**
74
+ * @param flower
75
+ * @returns
76
+ */
29
77
  getDataByFlow<T extends Record<string, any>>(flower: Flower<T>): T;
78
+ /**
79
+ * @param id
80
+ * @returns
81
+ */
30
82
  getDataFromState<T extends Record<string, any>>(id: string | string[]): (data: T) => Partial<T>;
83
+ /**
84
+ * @param form
85
+ * @returns
86
+ */
31
87
  makeSelectNodeFormTouched<T extends Record<string, any>>(form: Form<T>): boolean | undefined;
88
+ /**
89
+ * @param name
90
+ * @param id
91
+ * @param validate
92
+ * @returns
93
+ */
32
94
  makeSelectFieldError<T extends Record<string, any>>(name: string, id: string, validate: {
33
95
  rules?: RulesObject<any>;
34
96
  message?: string;
35
97
  }[] | null): (data?: T) => Array<string>;
98
+ /**
99
+ * @param id
100
+ * @param rules
101
+ * @param keys
102
+ * @param flowName
103
+ * @param value
104
+ * @returns
105
+ */
36
106
  selectorRulesDisabled<T extends Record<string, any>>(id: string, rules: any, keys: string[] | null, flowName: string, value: any): (data: T | undefined, form: {
37
107
  touched: boolean;
38
108
  errors: any;
@@ -1,8 +1,45 @@
1
1
  export interface CoreStateUtils {
2
+ /**
3
+ * @param state
4
+ *
5
+ * Extracts data from all flows in the state object.
6
+ * It iterates through each flow and retrieves its data property.
7
+ */
2
8
  getAllData<T extends object>(state: T | undefined): Record<string, any> | undefined;
9
+ /**
10
+ *
11
+ * @param name
12
+ * @param id
13
+ *
14
+ * Selects the form node with a specific ID from a given flow.
15
+ * It returns a selector function that accepts the state as an argument and retrieves the form node
16
+ */
3
17
  selectFlowerFormNode<T extends object>(name: string, id: string): (state: T) => Record<string, any>;
18
+ /**
19
+ *
20
+ * @param name
21
+ *
22
+ * Creates a selector function that selects the next rules for the current node in a given flow.
23
+ * It retrieves the next rules from the state
24
+ */
4
25
  makeSelectCurrentNodeId<T extends object>(name: string): (state: T) => string;
26
+ /**
27
+ *
28
+ * @param name
29
+ *
30
+ * Creates a selector function that selects the ID of the current node in a given flow.
31
+ * It first retrieves the sub-state of the specified flow, then checks if there's a current node ID;
32
+ * if not, it falls back to the start ID.
33
+ */
5
34
  makeSelectCurrentNextRules<T extends object>(name: string): (state: T) => any;
35
+ /**
36
+ *
37
+ * @param name
38
+ * @param currentNodeId
39
+ *
40
+ * Creates a selector function that selects error-related information for a specific node in a given flow.
41
+ * It retrieves the form node using selectFlowerFormNode, then extracts information about touched state, errors, validation status, and validity.
42
+ */
6
43
  makeSelectNodeErrors<T extends object>(name: string, currentNodeId: string): (state: T) => {
7
44
  touched: boolean;
8
45
  errors: any;