@ventlio/tanstack-query 0.2.63-beta.5.2 → 0.2.63-beta.6.2

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,3 @@
1
1
  import type { QueryClient } from '@tanstack/react-query';
2
- import type { BootstrapQueryRequest } from '../types';
3
- export declare const bootstrapQueryRequest: (queryClient: QueryClient, options?: BootstrapQueryRequest) => void;
2
+ import type { BootstrapConfig } from '../types';
3
+ export declare const bootstrapQueryRequest: (queryClient: QueryClient, options?: BootstrapConfig) => void;
@@ -4,7 +4,7 @@ const bootstrapQueryRequest = (queryClient, options) => {
4
4
  staleTime: Infinity,
5
5
  cacheTime: Infinity,
6
6
  });
7
- // set default query confg
7
+ // set default query config
8
8
  queryClient.setQueryData(['config'], {
9
9
  headers: {
10
10
  Authorization: ``,
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { useQueryHeaders } from './config/useQueryHeaders.js';
5
5
  export { useReactNativeEnv } from './config/useReactNativeEnv.js';
6
6
  export { scrollToTop } from './helpers/scrollToTop.js';
7
7
  export { getDateInFuture } from './helpers/timeFuncs.js';
8
+ export { QueryModel } from './model/Model.js';
8
9
  export { useKeyTrackerModel } from './model/useKeyTrackerModel.js';
9
10
  export { useQueryModel } from './model/useQueryModel.js';
10
11
  export { useRefetchQuery } from './model/useRefetchQuery.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
2
+ import result from 'lodash.result';
3
+ import set from 'lodash.set';
2
4
  import { useState, useMemo, useEffect, startTransition } from 'react';
3
5
  import axios from 'axios';
4
6
 
@@ -8,7 +10,7 @@ const bootstrapQueryRequest = (queryClient, options) => {
8
10
  staleTime: Infinity,
9
11
  cacheTime: Infinity,
10
12
  });
11
- // set default query confg
13
+ // set default query config
12
14
  queryClient.setQueryData(['config'], {
13
15
  headers: {
14
16
  Authorization: ``,
@@ -81,6 +83,94 @@ const useQueryHeaders = () => {
81
83
  return { setQueryHeaders, getHeaders };
82
84
  };
83
85
 
86
+ class QueryModel {
87
+ queryKey;
88
+ queryClient;
89
+ exact;
90
+ constructor(queryKey, queryClient, exact = true) {
91
+ this.queryKey = queryKey;
92
+ this.queryClient = queryClient;
93
+ this.exact = exact;
94
+ }
95
+ findAll(path) {
96
+ const data = this.queryClient.getQueryData(this.queryKey, { exact: this.exact });
97
+ if (!data) {
98
+ return [];
99
+ }
100
+ if (!path) {
101
+ return Array.isArray(data) ? data : [data];
102
+ }
103
+ return result(data, path, []);
104
+ }
105
+ findMany(selector, path) {
106
+ const data = this.findAll(path) ?? [];
107
+ return data.filter(selector);
108
+ }
109
+ find(id, path) {
110
+ const modelConfig = this.getModelConfig();
111
+ if (!modelConfig?.idColumn) {
112
+ return undefined;
113
+ }
114
+ const data = this.findAll(path) ?? [];
115
+ return data.find((record) => record[modelConfig.idColumn] === id);
116
+ }
117
+ update(id, data, path) {
118
+ const oldData = this.findAll(path) ?? [];
119
+ const modelConfig = this.getModelConfig();
120
+ if (!modelConfig?.idColumn) {
121
+ return undefined;
122
+ }
123
+ const idColumn = modelConfig.idColumn;
124
+ let updatedRecord = undefined;
125
+ const newData = oldData.map((record) => {
126
+ let dataRecord = record;
127
+ if (dataRecord[idColumn] === id) {
128
+ dataRecord = { ...dataRecord, ...data };
129
+ updatedRecord = dataRecord;
130
+ }
131
+ return dataRecord;
132
+ });
133
+ if (!path) {
134
+ this.queryClient.setQueryData(this.queryKey, newData);
135
+ }
136
+ else {
137
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
138
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
139
+ }
140
+ return updatedRecord;
141
+ }
142
+ delete(id, path) {
143
+ const oldData = this.findAll(path) ?? [];
144
+ const modelConfig = this.getModelConfig();
145
+ if (!modelConfig?.idColumn) {
146
+ return false;
147
+ }
148
+ const idColumn = modelConfig.idColumn;
149
+ let updated = false;
150
+ const newData = oldData.filter((record) => {
151
+ const dataRecord = record;
152
+ if (dataRecord[idColumn] === id) {
153
+ updated = true;
154
+ return false;
155
+ }
156
+ return true;
157
+ });
158
+ if (!path) {
159
+ this.queryClient.setQueryData(this.queryKey, newData);
160
+ }
161
+ else {
162
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
163
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
164
+ }
165
+ return updated;
166
+ }
167
+ getModelConfig() {
168
+ const { options } = this.queryClient.getQueryData(['config']) ?? {};
169
+ const { modelConfig } = options ?? {};
170
+ return modelConfig;
171
+ }
172
+ }
173
+
84
174
  const useKeyTrackerModel = (keyTracker) => {
85
175
  const queryClient = useQueryClient();
86
176
  const getQueryKey = (innerKeyTracker) => {
@@ -97,9 +187,11 @@ const useKeyTrackerModel = (keyTracker) => {
97
187
  return { refetchQuery, getQueryKey };
98
188
  };
99
189
 
100
- const useQueryModel = (queryKey, filters) => {
190
+ const useQueryModel = (keyTracker) => {
101
191
  const queryClient = useQueryClient();
102
- return queryClient.getQueryData(queryKey, filters);
192
+ const { getQueryKey } = useKeyTrackerModel(keyTracker);
193
+ const queryKey = getQueryKey();
194
+ return new QueryModel(queryKey, queryClient);
103
195
  };
104
196
 
105
197
  const useRefetchQuery = async (queryKey) => {
@@ -499,5 +591,5 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
499
591
  return { post, ...mutation };
500
592
  };
501
593
 
502
- export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useReactNativeEnv, useRefetchQuery };
594
+ export { ContentType, HttpMethod, QueryModel, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useReactNativeEnv, useRefetchQuery };
503
595
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,14 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import type { QueryModelBuilder } from './model.interface';
3
+ export declare class QueryModel<T> implements QueryModelBuilder<T> {
4
+ private readonly queryKey;
5
+ private readonly queryClient;
6
+ private readonly exact;
7
+ constructor(queryKey: any[], queryClient: QueryClient, exact?: boolean);
8
+ findAll(path?: string): T[] | undefined;
9
+ findMany(selector: (record: T) => boolean, path?: string): T[];
10
+ find(id: string | number, path?: string): T | undefined;
11
+ update(id: string | number, data: Partial<T>, path?: string): T | undefined;
12
+ delete(id: number | string, path?: string): boolean;
13
+ private getModelConfig;
14
+ }
@@ -0,0 +1,93 @@
1
+ import result from 'lodash.result';
2
+ import set from 'lodash.set';
3
+
4
+ class QueryModel {
5
+ queryKey;
6
+ queryClient;
7
+ exact;
8
+ constructor(queryKey, queryClient, exact = true) {
9
+ this.queryKey = queryKey;
10
+ this.queryClient = queryClient;
11
+ this.exact = exact;
12
+ }
13
+ findAll(path) {
14
+ const data = this.queryClient.getQueryData(this.queryKey, { exact: this.exact });
15
+ if (!data) {
16
+ return [];
17
+ }
18
+ if (!path) {
19
+ return Array.isArray(data) ? data : [data];
20
+ }
21
+ return result(data, path, []);
22
+ }
23
+ findMany(selector, path) {
24
+ const data = this.findAll(path) ?? [];
25
+ return data.filter(selector);
26
+ }
27
+ find(id, path) {
28
+ const modelConfig = this.getModelConfig();
29
+ if (!modelConfig?.idColumn) {
30
+ return undefined;
31
+ }
32
+ const data = this.findAll(path) ?? [];
33
+ return data.find((record) => record[modelConfig.idColumn] === id);
34
+ }
35
+ update(id, data, path) {
36
+ const oldData = this.findAll(path) ?? [];
37
+ const modelConfig = this.getModelConfig();
38
+ if (!modelConfig?.idColumn) {
39
+ return undefined;
40
+ }
41
+ const idColumn = modelConfig.idColumn;
42
+ let updatedRecord = undefined;
43
+ const newData = oldData.map((record) => {
44
+ let dataRecord = record;
45
+ if (dataRecord[idColumn] === id) {
46
+ dataRecord = { ...dataRecord, ...data };
47
+ updatedRecord = dataRecord;
48
+ }
49
+ return dataRecord;
50
+ });
51
+ if (!path) {
52
+ this.queryClient.setQueryData(this.queryKey, newData);
53
+ }
54
+ else {
55
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
56
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
57
+ }
58
+ return updatedRecord;
59
+ }
60
+ delete(id, path) {
61
+ const oldData = this.findAll(path) ?? [];
62
+ const modelConfig = this.getModelConfig();
63
+ if (!modelConfig?.idColumn) {
64
+ return false;
65
+ }
66
+ const idColumn = modelConfig.idColumn;
67
+ let updated = false;
68
+ const newData = oldData.filter((record) => {
69
+ const dataRecord = record;
70
+ if (dataRecord[idColumn] === id) {
71
+ updated = true;
72
+ return false;
73
+ }
74
+ return true;
75
+ });
76
+ if (!path) {
77
+ this.queryClient.setQueryData(this.queryKey, newData);
78
+ }
79
+ else {
80
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
81
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
82
+ }
83
+ return updated;
84
+ }
85
+ getModelConfig() {
86
+ const { options } = this.queryClient.getQueryData(['config']) ?? {};
87
+ const { modelConfig } = options ?? {};
88
+ return modelConfig;
89
+ }
90
+ }
91
+
92
+ export { QueryModel };
93
+ //# sourceMappingURL=Model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Model.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,5 @@
1
+ export * from './Model';
2
+ export * from './model.interface';
1
3
  export * from './useKeyTrackerModel';
2
4
  export * from './useQueryModel';
3
5
  export * from './useRefetchQuery';
@@ -0,0 +1,7 @@
1
+ export interface QueryModelBuilder<T> {
2
+ findAll: (path?: string) => T[] | undefined;
3
+ findMany: (selector: (record: T) => boolean, path?: string) => T[];
4
+ find: (id: number | string, path?: string) => T | undefined;
5
+ update: (id: number | string, data: Partial<T>, path?: string) => T | undefined;
6
+ delete: (id: number, path?: string) => boolean;
7
+ }
@@ -1,2 +1,2 @@
1
- import type { QueryFilters } from '@tanstack/react-query';
2
- export declare const useQueryModel: (queryKey: any[], filters?: QueryFilters | undefined) => unknown;
1
+ import { QueryModel } from './Model';
2
+ export declare const useQueryModel: <T>(keyTracker: string) => QueryModel<T>;
@@ -1,8 +1,12 @@
1
1
  import { useQueryClient } from '@tanstack/react-query';
2
+ import { QueryModel } from './Model.js';
3
+ import { useKeyTrackerModel } from './useKeyTrackerModel.js';
2
4
 
3
- const useQueryModel = (queryKey, filters) => {
5
+ const useQueryModel = (keyTracker) => {
4
6
  const queryClient = useQueryClient();
5
- return queryClient.getQueryData(queryKey, filters);
7
+ const { getQueryKey } = useKeyTrackerModel(keyTracker);
8
+ const queryKey = getQueryKey();
9
+ return new QueryModel(queryKey, queryClient);
6
10
  };
7
11
 
8
12
  export { useQueryModel };
@@ -1 +1 @@
1
- {"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -1,15 +1,19 @@
1
1
  import type { RawAxiosRequestHeaders } from 'axios';
2
- export interface BootstrapQueryRequest {
2
+ export interface BootstrapConfig {
3
3
  environments?: {
4
4
  appBaseUrl: string;
5
5
  appTimeout: number;
6
6
  };
7
7
  context?: ContextType;
8
+ modelConfig?: BootstrapModelConfig;
9
+ }
10
+ export interface BootstrapModelConfig {
11
+ idColumn: string;
8
12
  }
9
13
  export type ContextType = 'app' | 'web' | 'electronjs';
10
14
  export interface TanstackQueryConfig {
11
15
  headers: RawAxiosRequestHeaders;
12
- options?: BootstrapQueryRequest;
16
+ options?: BootstrapConfig;
13
17
  }
14
18
  export interface IUseQueryHeaders {
15
19
  getHeaders: () => TanstackQueryConfig['headers'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ventlio/tanstack-query",
3
- "version": "0.2.63-beta.5.2",
3
+ "version": "0.2.63-beta.6.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "contributors": [
@@ -51,6 +51,8 @@
51
51
  "@testing-library/react-hooks": "^8.0.1",
52
52
  "@types/axios": "^0.14.0",
53
53
  "@types/jest": "^29.5.1",
54
+ "@types/lodash.result": "^4.5.7",
55
+ "@types/lodash.set": "^4.3.7",
54
56
  "@types/node": "*",
55
57
  "@types/react": "^18.2.0",
56
58
  "@types/react-dom": "^18.2.0",
@@ -82,5 +84,9 @@
82
84
  "files": [
83
85
  "dist/**/*",
84
86
  "src"
85
- ]
87
+ ],
88
+ "dependencies": {
89
+ "lodash.result": "^4.5.2",
90
+ "lodash.set": "^4.3.2"
91
+ }
86
92
  }
@@ -1,14 +1,14 @@
1
1
  import type { QueryClient } from '@tanstack/react-query';
2
- import type { BootstrapQueryRequest, TanstackQueryConfig } from '../types';
2
+ import type { BootstrapConfig, TanstackQueryConfig } from '../types';
3
3
 
4
- export const bootstrapQueryRequest = (queryClient: QueryClient, options?: BootstrapQueryRequest): void => {
4
+ export const bootstrapQueryRequest = (queryClient: QueryClient, options?: BootstrapConfig): void => {
5
5
  // make query config doesn't expire
6
6
  queryClient.setQueryDefaults(['config'], {
7
7
  staleTime: Infinity,
8
8
  cacheTime: Infinity,
9
9
  });
10
10
 
11
- // set default query confg
11
+ // set default query config
12
12
  queryClient.setQueryData<TanstackQueryConfig>(['config'], {
13
13
  headers: {
14
14
  Authorization: ``,
@@ -0,0 +1,107 @@
1
+ import type { QueryClient } from '@tanstack/react-query';
2
+ import result from 'lodash.result';
3
+ import set from 'lodash.set';
4
+ import type { TanstackQueryConfig } from '../types';
5
+ import type { QueryModelBuilder } from './model.interface';
6
+
7
+ export class QueryModel<T> implements QueryModelBuilder<T> {
8
+ constructor(
9
+ private readonly queryKey: any[],
10
+ private readonly queryClient: QueryClient,
11
+ private readonly exact: boolean = true
12
+ ) {}
13
+
14
+ public findAll(path?: string): T[] | undefined {
15
+ const data = this.queryClient.getQueryData(this.queryKey, { exact: this.exact });
16
+
17
+ if (!data) {
18
+ return [];
19
+ }
20
+
21
+ if (!path) {
22
+ return Array.isArray(data) ? data : [data];
23
+ }
24
+
25
+ return result<T[]>(data, path, []);
26
+ }
27
+
28
+ public findMany(selector: (record: T) => boolean, path?: string): T[] {
29
+ const data = this.findAll(path) ?? [];
30
+ return data.filter(selector);
31
+ }
32
+
33
+ find(id: string | number, path?: string): T | undefined {
34
+ const modelConfig = this.getModelConfig();
35
+
36
+ if (!modelConfig?.idColumn) {
37
+ return undefined;
38
+ }
39
+ const data = this.findAll(path) ?? [];
40
+
41
+ return data.find((record) => (record as Record<string, any>)[modelConfig.idColumn] === id);
42
+ }
43
+
44
+ update(id: string | number, data: Partial<T>, path?: string): T | undefined {
45
+ const oldData = this.findAll(path) ?? [];
46
+ const modelConfig = this.getModelConfig();
47
+
48
+ if (!modelConfig?.idColumn) {
49
+ return undefined;
50
+ }
51
+ const idColumn = modelConfig.idColumn;
52
+
53
+ let updatedRecord: T | undefined = undefined;
54
+ const newData = oldData.map((record) => {
55
+ let dataRecord = record as Record<string, any>;
56
+
57
+ if (dataRecord[idColumn] === id) {
58
+ dataRecord = { ...dataRecord, ...data };
59
+ updatedRecord = dataRecord as T;
60
+ }
61
+
62
+ return dataRecord;
63
+ });
64
+
65
+ if (!path) {
66
+ this.queryClient.setQueryData(this.queryKey, newData);
67
+ } else {
68
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
69
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
70
+ }
71
+ return updatedRecord;
72
+ }
73
+
74
+ delete(id: number | string, path?: string): boolean {
75
+ const oldData = this.findAll(path) ?? [];
76
+ const modelConfig = this.getModelConfig();
77
+
78
+ if (!modelConfig?.idColumn) {
79
+ return false;
80
+ }
81
+ const idColumn = modelConfig.idColumn;
82
+ let updated = false;
83
+ const newData = oldData.filter((record) => {
84
+ const dataRecord = record as Record<string, any>;
85
+ if (dataRecord[idColumn] === id) {
86
+ updated = true;
87
+ return false;
88
+ }
89
+ return true;
90
+ });
91
+
92
+ if (!path) {
93
+ this.queryClient.setQueryData(this.queryKey, newData);
94
+ } else {
95
+ const queryData = this.queryClient.getQueryData(this.queryKey, { exact: this.exact }) ?? {};
96
+ this.queryClient.setQueryData(this.queryKey, set(queryData, path, newData));
97
+ }
98
+ return updated;
99
+ }
100
+
101
+ private getModelConfig() {
102
+ const { options } = this.queryClient.getQueryData<TanstackQueryConfig>(['config']) ?? {};
103
+ const { modelConfig } = options ?? {};
104
+
105
+ return modelConfig;
106
+ }
107
+ }
@@ -1,3 +1,5 @@
1
+ export * from './Model';
2
+ export * from './model.interface';
1
3
  export * from './useKeyTrackerModel';
2
4
  export * from './useQueryModel';
3
5
  export * from './useRefetchQuery';
@@ -0,0 +1,7 @@
1
+ export interface QueryModelBuilder<T> {
2
+ findAll: (path?: string) => T[] | undefined;
3
+ findMany: (selector: (record: T) => boolean, path?: string) => T[];
4
+ find: (id: number | string, path?: string) => T | undefined;
5
+ update: (id: number | string, data: Partial<T>, path?: string) => T | undefined;
6
+ delete: (id: number, path?: string) => boolean;
7
+ }
@@ -1,8 +1,10 @@
1
- import type { QueryFilters } from '@tanstack/react-query';
2
1
  import { useQueryClient } from '@tanstack/react-query';
2
+ import { QueryModel } from './Model';
3
+ import { useKeyTrackerModel } from './useKeyTrackerModel';
3
4
 
4
- export const useQueryModel = (queryKey: any[], filters?: QueryFilters | undefined) => {
5
+ export const useQueryModel = <T>(keyTracker: string): QueryModel<T> => {
5
6
  const queryClient = useQueryClient();
6
-
7
- return queryClient.getQueryData(queryKey, filters);
7
+ const { getQueryKey } = useKeyTrackerModel(keyTracker);
8
+ const queryKey = getQueryKey() as any[];
9
+ return new QueryModel<T>(queryKey, queryClient);
8
10
  };
@@ -1,16 +1,22 @@
1
1
  import type { RawAxiosRequestHeaders } from 'axios';
2
2
 
3
- export interface BootstrapQueryRequest {
3
+ export interface BootstrapConfig {
4
4
  environments?: {
5
5
  appBaseUrl: string;
6
6
  appTimeout: number;
7
7
  };
8
8
  context?: ContextType;
9
+ modelConfig?: BootstrapModelConfig;
9
10
  }
11
+
12
+ export interface BootstrapModelConfig {
13
+ idColumn: string;
14
+ }
15
+
10
16
  export type ContextType = 'app' | 'web' | 'electronjs';
11
17
  export interface TanstackQueryConfig {
12
18
  headers: RawAxiosRequestHeaders;
13
- options?: BootstrapQueryRequest;
19
+ options?: BootstrapConfig;
14
20
  }
15
21
 
16
22
  export interface IUseQueryHeaders {