@arrai-innovations/reactive-helpers 14.1.0 → 15.0.0

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.
@@ -14,6 +14,7 @@ const defaultCrud = {
14
14
  list: undefined,
15
15
  bulkDelete: undefined,
16
16
  subscribe: undefined,
17
+ executeAction: undefined,
17
18
  };
18
19
 
19
20
  /**
@@ -76,10 +77,15 @@ const defaultCrud = {
76
77
  * @typedef {(SubscribeFnArgs)=>void} SubscribeFn
77
78
  */
78
79
 
80
+ /**
81
+ * @typedef {(ExecuteActionFnArgs)=>void} ExecuteActionFn
82
+ */
83
+
79
84
  /**
80
85
  * @typedef {object} ListCrudFunctions
81
86
  * @property {ListFn} [list] - The list function to get a list of items.
82
87
  * @property {BulkDeleteFn} [bulkDelete] - The delete function to bulk delete a list of items.
88
+ * @property {ExecuteActionFn} [executeAction] - The function to execute a certain action on a list of items.
83
89
  * @property {SubscribeFn} [subscribe] - The subscribe function to get a subscription to a list of items.
84
90
  */
85
91
 
@@ -95,10 +101,11 @@ const defaultCrud = {
95
101
  * @throws {Error} - If unknown keys are passed.
96
102
  * @returns {void}
97
103
  */
98
- export const setListCrud = ({ list, bulkDelete, subscribe, args = {}, ...rest }) => {
104
+ export const setListCrud = ({ list, bulkDelete, subscribe, executeAction, args = {}, ...rest }) => {
99
105
  defaultCrud.list = list;
100
106
  defaultCrud.subscribe = subscribe;
101
107
  defaultCrud.bulkDelete = bulkDelete;
108
+ defaultCrud.executeAction = executeAction;
102
109
  Object.assign(defaultCrud.args, cloneDeep(args));
103
110
  if (Object.keys(rest).length) {
104
111
  throw new Error(`Unknown key(s) passed to setListCrud: ${Object.keys(rest).join(", ")}`);
@@ -54,6 +54,12 @@ The default arguments for the crud functions.
54
54
 
55
55
  The delete function to bulk delete a list of items.
56
56
 
57
+ ##### executeAction
58
+
59
+ > **executeAction**: [`ExecuteActionFn`](listCrud.md#executeactionfn)
60
+
61
+ The function to execute a certain action on a list of items.
62
+
57
63
  ##### list
58
64
 
59
65
  > **list**: [`ListFn`](listCrud.md#listfn)
@@ -187,6 +193,22 @@ The method to call when new data is received.
187
193
 
188
194
  ***
189
195
 
196
+ ### ExecuteActionFn()
197
+
198
+ > **ExecuteActionFn**\<\>: (`ExecuteActionFnArgs`) => `void`
199
+
200
+ #### Type Parameters
201
+
202
+ #### Parameters
203
+
204
+ • **ExecuteActionFnArgs**: `any`
205
+
206
+ #### Returns
207
+
208
+ `void`
209
+
210
+ ***
211
+
190
212
  ### ListFn()
191
213
 
192
214
  > **ListFn**\<\>: (`ListFnArgs`) => `void`
@@ -275,6 +297,10 @@ The default arguments for the crud functions.
275
297
 
276
298
  The delete function to bulk delete a list of items.
277
299
 
300
+ • **reactiveCrud.executeAction**: [`ExecuteActionFn`](listCrud.md#executeactionfn)
301
+
302
+ The function to execute a certain action on a list of items.
303
+
278
304
  • **reactiveCrud.list**: [`ListFn`](listCrud.md#listfn)
279
305
 
280
306
  The list function to get a list of items.
package/docs/use/list.md CHANGED
@@ -6,6 +6,56 @@
6
6
 
7
7
  # use/list
8
8
 
9
+ ## Classes
10
+
11
+ ### ListError
12
+
13
+ Custom error class for use list errors.
14
+
15
+ #### Extends
16
+
17
+ - `Error`
18
+
19
+ #### Constructors
20
+
21
+ ##### new ListError()
22
+
23
+ > **new ListError**(`message`, `code`): [`ListError`](list.md#listerror)
24
+
25
+ Creates a new ListError.
26
+
27
+ ###### Parameters
28
+
29
+ • **message**: `string`
30
+
31
+ The error message.
32
+
33
+ • **code**: `string`
34
+
35
+ The error code.
36
+
37
+ ###### Returns
38
+
39
+ [`ListError`](list.md#listerror)
40
+
41
+ ###### Overrides
42
+
43
+ `Error.constructor`
44
+
45
+ #### Properties
46
+
47
+ ##### code
48
+
49
+ > **code**: `string`
50
+
51
+ ##### name
52
+
53
+ > **name**: `string`
54
+
55
+ ###### Inherited from
56
+
57
+ `Error.name`
58
+
9
59
  ## Interfaces
10
60
 
11
61
  ### ListManagerProperties
@@ -280,6 +330,10 @@ The options for the list./.
280
330
  ```vue
281
331
  ```
282
332
 
333
+ #### Throws
334
+
335
+ - If required options are not provided.
336
+
283
337
  ***
284
338
 
285
339
  ### useLists()
@@ -77,6 +77,16 @@ Adds an object to the list.
77
77
 
78
78
  `void`
79
79
 
80
+ ##### bulkDelete()
81
+
82
+ > **bulkDelete**: () => `Promise`\<`void`\>
83
+
84
+ Initiates a bulk delete operation on all objects in the list.
85
+
86
+ ###### Returns
87
+
88
+ `Promise`\<`void`\>
89
+
80
90
  ##### clearList()
81
91
 
82
92
  > **clearList**: () => `void`
@@ -115,6 +125,16 @@ Deletes an object from the list by pk.
115
125
 
116
126
  `void`
117
127
 
128
+ ##### executeAction()
129
+
130
+ > **executeAction**: () => `Promise`\<`void`\>
131
+
132
+ Initiates an action on all objects in the list.
133
+
134
+ ###### Returns
135
+
136
+ `Promise`\<`void`\>
137
+
118
138
  ##### getFakePk()
119
139
 
120
140
  > **getFakePk**: () => `string`
@@ -182,6 +202,13 @@ Default implementation are used as set by `setListCrud`.
182
202
  Provide the implementation for the bulkDelete
183
203
  function.
184
204
 
205
+ ###### executeAction
206
+
207
+ > **executeAction**: [`ExecuteActionFn`](../config/listCrud.md#executeactionfn)
208
+
209
+ Provide the implementation for the executeAction
210
+ function.
211
+
185
212
  ###### list
186
213
 
187
214
  > **list**: [`ListFn`](../config/listCrud.md#listfn)
@@ -493,7 +520,7 @@ watch(toRef(props, "someListFilter"), (newValue, oldValue) => {
493
520
 
494
521
  #### Throws
495
522
 
496
- If the props are missing.
523
+ If the props or keepOldPages are missing.
497
524
 
498
525
  ***
499
526
 
@@ -362,7 +362,9 @@ const listSubscription = useListSubscription({ props: listSubscriptionProps });
362
362
 
363
363
  #### Throws
364
364
 
365
- - If both listInstance and props are passed, or if neither are passed.
365
+ - If both listInstance and props are passed, or if neither are
366
+ passed. Also thrown if clearListOnListIntentTriggered is not passed or if neither listInstance
367
+ nor keepOldPages are passed.
366
368
 
367
369
  ***
368
370
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "14.1.0",
3
+ "version": "15.0.0",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,7 +30,9 @@ describe("config/listCrud.js", () => {
30
30
  */
31
31
  const retrievedCrud = reactive({});
32
32
  expect(() => getListCrud(retrievedCrud)).not.toThrow();
33
- expect(new Set(Object.keys(retrievedCrud))).toEqual(new Set(["list", "bulkDelete", "subscribe", "args"]));
33
+ expect(new Set(Object.keys(retrievedCrud))).toEqual(
34
+ new Set(["list", "bulkDelete", "executeAction", "subscribe", "args"])
35
+ );
34
36
  expect(retrievedCrud.args).not.toBe(crud.args);
35
37
  expect(retrievedCrud.args).toEqual(crud.args);
36
38
  expect(retrievedCrud.list).toBe(crud.list);
@@ -15,8 +15,8 @@ describe("use/listCalculated", () => {
15
15
  AwaitNot = watchesModule.AwaitNot;
16
16
  });
17
17
  it("should return a list of calculated items", async () => {
18
- const mainListInstance = useListInstance({ props: { pkKey: "id" } });
19
- const calculatedListInstance = useListInstance({ props: { pkKey: "id" } });
18
+ const mainListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
19
+ const calculatedListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
20
20
  mainListInstance.addListObject({
21
21
  id: "1",
22
22
  name: "main",
@@ -77,8 +77,8 @@ describe("use/listCalculated", () => {
77
77
  });
78
78
  });
79
79
  it("should allow calculated objects to return results based on related objects", async () => {
80
- const mainListInstance = useListInstance({ props: { pkKey: "id" } });
81
- const relatedListInstance = useListInstance({ props: { pkKey: "id" } });
80
+ const mainListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
81
+ const relatedListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
82
82
  mainListInstance.addListObject({
83
83
  id: "1",
84
84
  name: "main",
@@ -19,7 +19,7 @@ describe("use/listFilter", () => {
19
19
  });
20
20
 
21
21
  it("should match an allowed filter function", async () => {
22
- const list = useListInstance({ props: { pkKey: "id" } });
22
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
23
23
  const filter = useListFilter({
24
24
  parentState: list.state,
25
25
  allowedFilter: (object) => object.id === 1 || object.id === 3,
@@ -65,7 +65,7 @@ describe("use/listFilter", () => {
65
65
  });
66
66
  });
67
67
  it("should match an excluded filter function", async () => {
68
- const list = useListInstance({ props: { pkKey: "id" } });
68
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
69
69
  const filter = useListFilter({
70
70
  parentState: list.state,
71
71
  excludedFilter: (object) => object.id == 2 || object.id == 4,
@@ -111,7 +111,7 @@ describe("use/listFilter", () => {
111
111
  });
112
112
  });
113
113
  it("no args: returns objects unfiltered", async () => {
114
- const listInstance = useListInstance({ props: { pkKey: "id" } });
114
+ const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
115
115
  const listItems = [
116
116
  { id: 4, name: "four", has_things: true },
117
117
  { id: 2, name: "two", has_things: true },
@@ -135,7 +135,7 @@ describe("use/listFilter", () => {
135
135
  vi.resetAllMocks();
136
136
  const orderByRules = [{ key: "name", desc: true, localeCompare: false }];
137
137
  const sortThrottleWait = 0;
138
- const listInstance = useListInstance({ props: { pkKey: "id" } });
138
+ const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
139
139
  const listItems = [
140
140
  { id: 4, name: "four", has_things: true },
141
141
  { id: 2, name: "two", has_things: true },
@@ -177,6 +177,7 @@ describe("use/listFilter", () => {
177
177
  fields,
178
178
  },
179
179
  },
180
+ keepOldPages: false,
180
181
  });
181
182
  const listInstanceB = useListInstance({
182
183
  props: {
@@ -186,6 +187,7 @@ describe("use/listFilter", () => {
186
187
  fields,
187
188
  },
188
189
  },
190
+ keepOldPages: false,
189
191
  });
190
192
  const excludedFilter = (object) => object.id === 1 || object.name === "three";
191
193
  const allowedFilter = (object) => object.id === 2 || object.name === "four";
@@ -223,7 +225,7 @@ describe("use/listFilter", () => {
223
225
  });
224
226
  describe("useListFilters updates index when", () => {
225
227
  it("parentInstance.objects is updated", async () => {
226
- const list = useListInstance({ props: { pkKey: "id" } });
228
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
227
229
  const filter = useListFilter({
228
230
  parentState: list.state,
229
231
  allowedFilter: (object) => !!object.allowed?.every((e) => e),
@@ -264,8 +266,8 @@ describe("use/listFilter", () => {
264
266
  });
265
267
  });
266
268
  it("parentInstance.relatedObjects is updated", async () => {
267
- const list = useListInstance({ props: { pkKey: "id" } });
268
- const relatedList = useListInstance({ props: { pkKey: "id" } });
269
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
270
+ const relatedList = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
269
271
  const related = useListRelated({
270
272
  parentState: list.state,
271
273
  relatedObjectsRules: {
@@ -320,7 +322,7 @@ describe("use/listFilter", () => {
320
322
  });
321
323
  });
322
324
  it("parentInstance.calculatedObjects is updated", async () => {
323
- const list = useListInstance({ props: { pkKey: "id" } });
325
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
324
326
  const calculated = useListCalculated({
325
327
  parentState: list.state,
326
328
  calculatedObjectsRules: reactive({
@@ -364,7 +366,7 @@ describe("use/listFilter", () => {
364
366
  });
365
367
  });
366
368
  it("you can use nested useListFilters", async () => {
367
- const list = useListInstance({ props: { pkKey: "id" } });
369
+ const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
368
370
 
369
371
  function filter1AllowedFilter(object) {
370
372
  return object.has_things && object.has_stuff;