@adaskothebeast/react-redux-toolkit-hierarchical-date-hook 4.0.1 → 6.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.
package/index.esm.js CHANGED
@@ -1,9 +1,12 @@
1
- import 'core-js/modules/es.array.iterator.js';
2
- import 'core-js/modules/es.object.assign.js';
3
- import 'core-js/modules/web.dom-exception.constructor.js';
4
- import 'core-js/modules/web.dom-exception.stack.js';
5
- import 'core-js/modules/web.dom-exception.to-string-tag.js';
6
- import 'core-js/modules/web.structured-clone.js';
1
+ function _extends() {
2
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
3
+ for (var e = 1; e < arguments.length; e++) {
4
+ var t = arguments[e];
5
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
6
+ }
7
+ return n;
8
+ }, _extends.apply(null, arguments);
9
+ }
7
10
 
8
11
  /**
9
12
  * This custom hook transforms the string date fields based on matching regex to Date objects
@@ -21,16 +24,25 @@ import 'core-js/modules/web.structured-clone.js';
21
24
  * import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
22
25
  * import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
23
26
  * import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
27
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
28
+ *
29
+ * const MyComponent: React.FC = () => {
30
+ * const useQueryResult = useGetUserQuery(userId);
31
+ * const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(
32
+ * useQueryResult,
33
+ * hierarchicalConvertToDate
34
+ * );
24
35
  *
25
- * const MyComponent: React.FC = () => {
26
- * // Call your generated hook here
27
- * const useQueryResult = useQueryFunction(arg, options);
36
+ * if (adjustedResult.isLoading) {
37
+ * return <div>Loading...</div>;
38
+ * }
28
39
  *
29
- * // Pass the result to the custom hook
30
- * const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, hierarchicalConvertToDate);
40
+ * if (adjustedResult.error) {
41
+ * return <div>Error: {adjustedResult.error}</div>;
42
+ * }
31
43
  *
32
- * // Rest of your component...
33
- * }
44
+ * return <div>User's name is {adjustedResult.data?.name}</div>;
45
+ * };
34
46
  * ```
35
47
  *
36
48
  * @param useQueryResult The result of a Redux Toolkit query hook
@@ -38,18 +50,14 @@ import 'core-js/modules/web.structured-clone.js';
38
50
  * @returns The original query result with its data field transformed, if it exists
39
51
  */
40
52
  function useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, convertFunc) {
41
- const result = useQueryResult;
42
- // Transform 'data' field if it exists
43
- if (result.data) {
44
- // Deep clone the data to avoid mutating the state directly
45
- const clonedData = structuredClone(result.data);
53
+ if (useQueryResult.data) {
54
+ const clonedData = structuredClone(useQueryResult.data);
46
55
  convertFunc(clonedData);
47
- return Object.assign(Object.assign({}, result), {
56
+ return _extends({}, useQueryResult, {
48
57
  data: clonedData
49
- }); // Type assertion via 'unknown'
58
+ });
50
59
  }
51
- // If there's no 'data', return the result as is
52
- return result;
60
+ return useQueryResult;
53
61
  }
54
62
 
55
63
  export { useAdjustUseQueryHookResultWithHierarchicalDateConverter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaskothebeast/react-redux-toolkit-hierarchical-date-hook",
3
- "version": "4.0.1",
3
+ "version": "6.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Adam Pluciński <adaskothebeast@gmail.com> (https://github.com/adaskothebeast)",
6
6
  "repository": {
@@ -12,11 +12,11 @@
12
12
  },
13
13
  "homepage": "https://github.com/AdaskoTheBeAsT/date-interceptors",
14
14
  "peerDependencies": {
15
- "@reduxjs/toolkit": "^2.2.5",
16
15
  "jest-environment-jsdom": "*"
17
16
  },
18
17
  "sideEffects": false,
19
18
  "module": "./index.esm.js",
20
19
  "type": "module",
21
- "main": "./index.esm.js"
20
+ "main": "./index.esm.js",
21
+ "types": "./index.d.ts"
22
22
  }
@@ -1,5 +1,12 @@
1
- import { UseQueryHookResult } from '@reduxjs/toolkit/dist/query/react/buildHooks';
2
- import { BaseQueryFn, QueryDefinition, TypedUseQueryStateResult } from '@reduxjs/toolkit/query/react';
1
+ interface CustomQueryResult<ResultType> {
2
+ data?: ResultType;
3
+ error?: Error;
4
+ isLoading: boolean;
5
+ isFetching: boolean;
6
+ isSuccess: boolean;
7
+ isError: boolean;
8
+ refetch: () => void;
9
+ }
3
10
  /**
4
11
  * This custom hook transforms the string date fields based on matching regex to Date objects
5
12
  * of a Redux Toolkit query result using the HierarchicalConverter.
@@ -16,20 +23,30 @@ import { BaseQueryFn, QueryDefinition, TypedUseQueryStateResult } from '@reduxjs
16
23
  * import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
17
24
  * import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
18
25
  * import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
26
+ * import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
19
27
  *
20
- * const MyComponent: React.FC = () => {
21
- * // Call your generated hook here
22
- * const useQueryResult = useQueryFunction(arg, options);
28
+ * const MyComponent: React.FC = () => {
29
+ * const useQueryResult = useGetUserQuery(userId);
30
+ * const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(
31
+ * useQueryResult,
32
+ * hierarchicalConvertToDate
33
+ * );
23
34
  *
24
- * // Pass the result to the custom hook
25
- * const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, hierarchicalConvertToDate);
35
+ * if (adjustedResult.isLoading) {
36
+ * return <div>Loading...</div>;
37
+ * }
26
38
  *
27
- * // Rest of your component...
28
- * }
39
+ * if (adjustedResult.error) {
40
+ * return <div>Error: {adjustedResult.error}</div>;
41
+ * }
42
+ *
43
+ * return <div>User's name is {adjustedResult.data?.name}</div>;
44
+ * };
29
45
  * ```
30
46
  *
31
47
  * @param useQueryResult The result of a Redux Toolkit query hook
32
48
  * @param convertFunc The function that performs the conversion in place
33
49
  * @returns The original query result with its data field transformed, if it exists
34
50
  */
35
- export declare function useAdjustUseQueryHookResultWithHierarchicalDateConverter<ResultType, QueryArg, BaseQuery extends BaseQueryFn = BaseQueryFn, ReducerPath extends string = string, R extends TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery> = TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery>>(useQueryResult: UseQueryHookResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, ReducerPath>, R>, convertFunc: (obj: object) => void): UseQueryHookResult<QueryDefinition<QueryArg, BaseQuery, string, ResultType, ReducerPath>, R>;
51
+ export declare function useAdjustUseQueryHookResultWithHierarchicalDateConverter<ResultType>(useQueryResult: CustomQueryResult<ResultType>, convertFunc: (obj: object) => void): CustomQueryResult<ResultType>;
52
+ export {};
File without changes