@arrai-innovations/reactive-helpers 20.0.0 → 20.1.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.
@@ -10,15 +10,16 @@ import { readonly } from "vue";
10
10
 
11
11
  /**
12
12
  * @typedef {object} PaginateInfo
13
- * @property {number} totalRecords - The total records.
14
- * @property {number} totalPages - The total pages.
15
- * @property {number} perPage - The per page.
13
+ * @property {number} [totalRecords] - The total records.
14
+ * @property {number} [totalPages] - The total pages.
15
+ * @property {number} [perPage] - The per page.
16
+ * @property {number} [page] - The page you are giving us results for.
16
17
  */
17
18
 
18
19
  /**
19
20
  * @typedef {(
20
21
  * newObjects:import('../use/listInstance.js').ListObject,
21
- * paginationInfo: PaginateInfo|undefined
22
+ * paginationInfo?: PaginateInfo,
22
23
  * )=>void} PageCallback
23
24
  */
24
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "20.0.0",
3
+ "version": "20.1.0",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -13,17 +13,21 @@ export type PaginateInfo = {
13
13
  /**
14
14
  * - The total records.
15
15
  */
16
- totalRecords: number;
16
+ totalRecords?: number;
17
17
  /**
18
18
  * - The total pages.
19
19
  */
20
- totalPages: number;
20
+ totalPages?: number;
21
21
  /**
22
22
  * - The per page.
23
23
  */
24
- perPage: number;
24
+ perPage?: number;
25
+ /**
26
+ * - The page you are giving us results for.
27
+ */
28
+ page?: number;
25
29
  };
26
- export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo: PaginateInfo | undefined) => void;
30
+ export type PageCallback = (newObjects: import("../use/listInstance.js").ListObject, paginationInfo?: PaginateInfo) => void;
27
31
  export type ListArgs = {
28
32
  /**
29
33
  * - The arguments to be passed to the crud handlers.
@@ -1 +1 @@
1
- {"version":3,"file":"listCrud.d.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- */
9
- /**
10
- * @typedef {object} PagedListInstanceState
11
- * @property {number} totalRecords - The total records.
12
- * @property {number} totalPages - The total pages.
13
- * @property {number} perPage - The per page.
14
- */
15
- /**
16
- * @typedef {object} PagedListInstance
17
- * @property {import('./listInstance.js').ListInstanceState & PagedListInstanceState} state - The state.
18
- */
19
1
  /**
20
2
  *
21
3
  * @param {PagedListListanceOptions & import('./listInstance.js').ListInstanceOptions} options - The options.
@@ -28,7 +10,7 @@ export type PagedListListanceOptions = {
28
10
  */
29
11
  keepOldPages: boolean;
30
12
  };
31
- export type PagedListInstanceState = {
13
+ export type PaginatedRawState = {
32
14
  /**
33
15
  * - The total records.
34
16
  */
@@ -41,11 +23,37 @@ export type PagedListInstanceState = {
41
23
  * - The per page.
42
24
  */
43
25
  perPage: number;
26
+ /**
27
+ * - The page to ids map.
28
+ */
29
+ pageToIds: Map<number, string[]>;
30
+ };
31
+ export type PaginatedState = import("vue").UnwrapNestedRefs<PaginatedRawState>;
32
+ export type PagedListInstanceStateExtension = {
33
+ /**
34
+ * - The total records.
35
+ */
36
+ totalRecords: import("vue").Ref<number>;
37
+ /**
38
+ * - The total pages.
39
+ */
40
+ totalPages: import("vue").Ref<number>;
41
+ /**
42
+ * - The per page.
43
+ */
44
+ perPage: import("vue").Ref<number>;
45
+ /**
46
+ * - The page to ids map.
47
+ */
48
+ pageToIds: import("vue").Ref<Map<number, string[]>>;
44
49
  };
45
- export type PagedListInstance = {
50
+ export type PagedListInstanceState = typeof reactive;
51
+ export type PagedListRawInstance = {
46
52
  /**
47
53
  * - The state.
48
54
  */
49
- state: import("./listInstance.js").ListInstanceState & PagedListInstanceState;
55
+ state: PagedListInstanceState;
50
56
  };
57
+ export type PagedListInstance = import("./listInstance.js").ListInstance & PagedListRawInstance;
58
+ import { reactive } from "vue";
51
59
  //# sourceMappingURL=paginatedListInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paginatedListInstance.d.ts","sourceRoot":"","sources":["../../use/paginatedListInstance.js"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AAEH;;;;;GAKG;AAEH;;;GAGG;AAEH;;;;GAIG;AACH,+EAHW,wBAAwB,GAAG,OAAO,mBAAmB,EAAE,mBAAmB,GACxE,iBAAiB,CA+C7B;;;;;kBAjEa,OAAO;;;;;;kBAKP,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM;;;;;;WAKN,OAAO,mBAAmB,EAAE,iBAAiB,GAAG,sBAAsB"}
1
+ {"version":3,"file":"paginatedListInstance.d.ts","sourceRoot":"","sources":["../../use/paginatedListInstance.js"],"names":[],"mappings":"AA2DA;;;;GAIG;AACH,+EAHW,wBAAwB,GAAG,OAAO,mBAAmB,EAAE,mBAAmB,GACxE,iBAAiB,CA6D7B;;;;;kBAjHa,OAAO;;;;;;kBAKP,MAAM;;;;gBACN,MAAM;;;;aACN,MAAM;;;;eACN,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;;6BAItB,OAAO,KAAK,EAAE,gBAAgB,CAAC,iBAAiB,CAAC;;;;;kBAKhD,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;gBACzB,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;aACzB,OAAO,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC;;;;eACzB,OAAO,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;;;;;;;WAYxC,sBAAsB;;gCAIvB,OAAO,mBAAmB,EAAE,YAAY,GAAG,oBAAoB;yBA7C3C,KAAK"}
@@ -1,2 +1,2 @@
1
- export function refIfReactive<T, K extends keyof T>(source: (T & object) | undefined | null, property: K, defaultValue?: T[K]): import("vue").Ref<T[K]> | T[K] | undefined;
1
+ export function refIfReactive<T, K extends keyof T>(source: (T & object) | undefined | null, property: K, defaultValue?: T[K]): import("vue").ComputedRef<T[K]> | import("vue").Ref<T[K]>;
2
2
  //# sourceMappingURL=refIfReactive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refIfReactive.d.ts","sourceRoot":"","sources":["../../utils/refIfReactive.js"],"names":[],"mappings":"AAYO,8BAPM,CAAC,EACS,CAAC,SAAX,MAAO,CAAE,UACX,CAAA,CAAC,GAAG,MAAM,IAAG,SAAS,GAAG,IAAI,YAC7B,CAAC,iBACD,CAAC,CAAC,CAAC,CAAC,GACF,OAAO,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAOtD"}
1
+ {"version":3,"file":"refIfReactive.d.ts","sourceRoot":"","sources":["../../utils/refIfReactive.js"],"names":[],"mappings":"AAYO,8BAPM,CAAC,EACS,CAAC,SAAX,MAAO,CAAE,UACX,CAAA,CAAC,GAAG,MAAM,IAAG,SAAS,GAAG,IAAI,YAC7B,CAAC,iBACD,CAAC,CAAC,CAAC,CAAC,GACF,OAAO,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAOrE"}
@@ -3,7 +3,7 @@ import { assignReactiveObject } from "../utils/assignReactiveObject.js";
3
3
  import { getFakePk } from "../utils/getFakePk.js";
4
4
  import { useLoadingError } from "./loadingError.js";
5
5
  import inspect from "browser-util-inspect";
6
- import { computed, effectScope, nextTick, reactive, readonly, ref, shallowReactive, toRef, unref, watch } from "vue";
6
+ import { computed, effectScope, nextTick, reactive, readonly, ref, toRef, unref, watch } from "vue";
7
7
  import { CancellablePromise, wrapMaybeCancellable } from "../utils/cancellablePromise.js";
8
8
  import { refIfReactive } from "../utils/refIfReactive.js";
9
9
 
@@ -265,12 +265,12 @@ export function useListInstance({ props, handlers = {}, keepOldPages }) {
265
265
 
266
266
  // ### touching the _objectsMap or _objectsProxy directly will not trigger reactivity ###
267
267
  const state = reactive({
268
- crud: shallowReactive({
269
- args: reactive({}),
268
+ crud: {
269
+ args: {},
270
270
  list: defaultListCrud.list,
271
271
  bulkDelete: defaultListCrud.bulkDelete,
272
272
  executeAction: defaultListCrud.executeAction,
273
- }),
273
+ },
274
274
  pkKey: refIfReactive(props, "pkKey"),
275
275
  params: refIfReactive(props, "params", {}),
276
276
  /** @type {{[key: string]: ListObject}} */
@@ -1,7 +1,7 @@
1
1
  import { defaultObjectCrud, getObjectCrud } from "../config/objectCrud.js";
2
2
  import { assignReactiveObject } from "../utils/assignReactiveObject.js";
3
3
  import { useLoadingError } from "./loadingError.js";
4
- import { reactive, readonly, ref, shallowReactive } from "vue";
4
+ import { reactive, readonly, ref } from "vue";
5
5
  import { wrapMaybeCancellable } from "../utils/cancellablePromise.js";
6
6
  import { refIfReactive } from "../utils/refIfReactive.js";
7
7
 
@@ -212,19 +212,18 @@ export function useObjectInstance({ props, handlers = {} }) {
212
212
  const state = reactive(
213
213
  /** @type {ObjectInstanceRawState} */
214
214
  {
215
- crud: shallowReactive(
215
+ crud:
216
216
  /** @type {ObjectInstanceRawStateCrud} */
217
217
  {
218
- args: reactive({}),
218
+ args: {},
219
219
  create: defaultObjectCrud.create,
220
220
  retrieve: defaultObjectCrud.retrieve,
221
221
  update: defaultObjectCrud.update,
222
222
  delete: defaultObjectCrud.delete,
223
223
  patch: defaultObjectCrud.patch,
224
224
  subscribe: defaultObjectCrud.subscribe,
225
- }
226
- ),
227
- object: reactive({}),
225
+ },
226
+ object: {},
228
227
  pk: refIfReactive(props, "pk", null),
229
228
  pkKey: refIfReactive(props, "pkKey"),
230
229
  params: refIfReactive(props, "params", {}),
@@ -1,4 +1,5 @@
1
1
  import { useListInstance } from "./listInstance.js";
2
+ import { reactive, toRefs } from "vue";
2
3
 
3
4
  /**
4
5
  * @module use/paginatedListInstance.js
@@ -11,65 +12,113 @@ import { useListInstance } from "./listInstance.js";
11
12
  */
12
13
 
13
14
  /**
14
- * @typedef {object} PagedListInstanceState
15
+ * @typedef {object} PaginatedRawState
15
16
  * @property {number} totalRecords - The total records.
16
17
  * @property {number} totalPages - The total pages.
17
18
  * @property {number} perPage - The per page.
19
+ * @property {Map<number, string[]>} pageToIds - The page to ids map.
18
20
  */
19
21
 
20
22
  /**
21
- * @typedef {object} PagedListInstance
22
- * @property {import('./listInstance.js').ListInstanceState & PagedListInstanceState} state - The state.
23
+ * @typedef {import('vue').UnwrapNestedRefs<PaginatedRawState>} PaginatedState
23
24
  */
24
25
 
26
+ /**
27
+ * @typedef {object} PagedListInstanceStateExtension
28
+ * @property {import('vue').Ref<number>} totalRecords - The total records.
29
+ * @property {import('vue').Ref<number>} totalPages - The total pages.
30
+ * @property {import('vue').Ref<number>} perPage - The per page.
31
+ * @property {import('vue').Ref<Map<number, string[]>>} pageToIds - The page to ids map.
32
+ */
33
+
34
+ /**
35
+ * @typedef {import('vue').reactive<(
36
+ * import('./listInstance.js').ListInstanceRawState &
37
+ * PagedListInstanceStateExtension
38
+ * )>} PagedListInstanceState
39
+ */
40
+
41
+ /**
42
+ * @typedef {object} PagedListRawInstance
43
+ * @property {PagedListInstanceState} state - The state.
44
+ */
45
+
46
+ /**
47
+ * @typedef {import('./listInstance.js').ListInstance & PagedListRawInstance} PagedListInstance
48
+ */
49
+
50
+ /**
51
+ * @param {import('./listInstance.js').ListInstance} listInstance - The list instance.
52
+ * @param {PaginatedState} paginatedState - The paginated state.
53
+ * @returns {PagedListInstance} - The paged list instance.
54
+ */
55
+ function makePagedListInstance(listInstance, paginatedState) {
56
+ Object.assign(listInstance.state, toRefs(paginatedState));
57
+ return /** @type {PagedListInstance} */ (listInstance);
58
+ }
59
+
25
60
  /**
26
61
  *
27
62
  * @param {PagedListListanceOptions & import('./listInstance.js').ListInstanceOptions} options - The options.
28
63
  * @returns {PagedListInstance} - The paged list instance.
29
64
  */
30
65
  export function usePagedListInstance({ keepOldPages, ...useListInstanceArgs }) {
31
- const listInstance = /** @type {PagedListInstance & import('./listInstance.js').ListInstance} */ (
32
- /** @type {unknown} */ (useListInstance({ keepOldPages, ...useListInstanceArgs }))
33
- );
66
+ /** @type {PaginatedState} */
67
+ const paginatedState = reactive({
68
+ totalRecords: 0,
69
+ totalPages: 0,
70
+ perPage: 0,
71
+ pageToIds: new Map(),
72
+ });
34
73
 
35
- listInstance.state.totalRecords = 0;
36
- listInstance.state.totalPages = 0;
37
- listInstance.state.perPage = 0;
74
+ const paginatedListInstance = makePagedListInstance(
75
+ useListInstance({ keepOldPages, ...useListInstanceArgs }),
76
+ paginatedState
77
+ );
38
78
 
39
- const superClearList = listInstance.clearList;
40
- listInstance.clearList = () => {
79
+ const superClearList = paginatedListInstance.clearList;
80
+ paginatedListInstance.clearList = () => {
41
81
  superClearList();
42
- listInstance.state.totalRecords = 0;
43
- listInstance.state.totalPages = 0;
44
- listInstance.state.perPage = 0;
82
+ paginatedState.totalRecords = 0;
83
+ paginatedState.totalPages = 0;
84
+ paginatedState.perPage = 0;
45
85
  };
46
86
  if (keepOldPages === undefined) {
47
87
  throw new Error("keepOldPages is required");
48
88
  }
49
89
 
50
- listInstance.pageCallback = (newObjects, { totalRecords, totalPages, perPage }) => {
90
+ paginatedListInstance.pageCallback = (
91
+ /** @type {import('./listInstance.js').ListObject[]} */ newObjects,
92
+ /** @type {import('../config/listCrud.js').PaginateInfo} */ { page, totalRecords, totalPages, perPage }
93
+ ) => {
51
94
  // with keepOldPages, you are responsible for clearing the list as needed
52
95
  if (!keepOldPages) {
53
96
  // display one page at a time, clear the list
54
- listInstance.clearList();
97
+ paginatedListInstance.clearList();
55
98
  }
56
99
  newObjects.forEach((newObject) => {
57
- if (newObject[listInstance.state.pkKey] in listInstance.state.objects) {
58
- listInstance.updateListObject(newObject);
100
+ if (newObject[paginatedListInstance.state.pkKey] in paginatedListInstance.state.objects) {
101
+ paginatedListInstance.updateListObject(newObject);
59
102
  } else {
60
- listInstance.addListObject(newObject);
103
+ paginatedListInstance.addListObject(newObject);
61
104
  }
62
105
  });
106
+ if (keepOldPages && page !== undefined) {
107
+ const pageIds = newObjects.map((obj) => obj[paginatedListInstance.state.pkKey] + "");
108
+ // webstorm being crazy
109
+ // noinspection JSUnresolvedReference
110
+ paginatedState.pageToIds.set(page, pageIds);
111
+ }
63
112
  if (totalRecords !== undefined) {
64
- listInstance.state.totalRecords = totalRecords;
113
+ paginatedState.totalRecords = totalRecords;
65
114
  }
66
115
  if (totalPages !== undefined) {
67
- listInstance.state.totalPages = totalPages;
116
+ paginatedState.totalPages = totalPages;
68
117
  }
69
118
  if (perPage !== undefined) {
70
- listInstance.state.perPage = perPage;
119
+ paginatedState.perPage = perPage;
71
120
  }
72
121
  };
73
122
 
74
- return listInstance;
123
+ return paginatedListInstance;
75
124
  }
@@ -1,4 +1,4 @@
1
- import { isReactive, toRef, unref } from "vue";
1
+ import { computed, isReactive, toRef, unref } from "vue";
2
2
 
3
3
  /**
4
4
  * Returns a ref to a property if the source is reactive, otherwise returns the unrefed value.
@@ -8,11 +8,11 @@ import { isReactive, toRef, unref } from "vue";
8
8
  * @param {T & object | undefined | null} source - The source object.
9
9
  * @param {K} property - The property to access.
10
10
  * @param {T[K]} [defaultValue] - The default value to use if source or property is missing.
11
- * @returns {import('vue').Ref<T[K]> | T[K] | undefined} The ref to the property if the source is reactive, otherwise the unrefed value.
11
+ * @returns {import('vue').ComputedRef<T[K]> | import('vue').Ref<T[K]>} The ref to the property if the source is reactive, otherwise the unrefed value.
12
12
  */
13
13
  export const refIfReactive = (source, property, defaultValue) => {
14
14
  if (source && isReactive(source)) {
15
15
  return toRef(source, property);
16
16
  }
17
- return unref(source?.[property]) ?? defaultValue;
17
+ return computed(() => unref(source?.[property]) ?? defaultValue);
18
18
  };