@ventlio/tanstack-query 0.2.69 → 0.2.70
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/dist/index.mjs +5 -6
- package/dist/index.mjs.map +1 -1
- package/dist/model/model.interface.d.ts +2 -2
- package/dist/model/useQueryModel.js +5 -6
- package/dist/model/useQueryModel.js.map +1 -1
- package/package.json +1 -1
- package/src/model/model.interface.ts +2 -2
- package/src/model/useQueryModel.ts +9 -10
package/dist/index.mjs
CHANGED
|
@@ -104,7 +104,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
104
104
|
const { getQueryKey } = useKeyTrackerModel(keyTracker);
|
|
105
105
|
const queryKey = getQueryKey();
|
|
106
106
|
const add = (data, position, path) => {
|
|
107
|
-
let records = findAll(path) ?? [];
|
|
107
|
+
let records = (findAll(path) ?? []);
|
|
108
108
|
if (!position || position === 'end') {
|
|
109
109
|
records = [...records, data];
|
|
110
110
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -132,7 +132,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
132
132
|
return result(data, path, []);
|
|
133
133
|
};
|
|
134
134
|
const findMany = (selector, path) => {
|
|
135
|
-
const data = findAll(path) ?? [];
|
|
135
|
+
const data = (findAll(path) ?? []);
|
|
136
136
|
return data.filter(selector);
|
|
137
137
|
};
|
|
138
138
|
const find = (id, path) => {
|
|
@@ -140,7 +140,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
140
140
|
if (!modelConfig?.idColumn) {
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
143
|
-
const data = findAll(path) ?? [];
|
|
143
|
+
const data = (findAll(path) ?? []);
|
|
144
144
|
return data.find((record) => record[modelConfig.idColumn] === id);
|
|
145
145
|
};
|
|
146
146
|
const get = (path) => {
|
|
@@ -154,7 +154,6 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
154
154
|
if (path) {
|
|
155
155
|
const data = get();
|
|
156
156
|
newData = lodashSet(data, path, newData);
|
|
157
|
-
return queryClient.setQueryData(queryKey, newData);
|
|
158
157
|
}
|
|
159
158
|
return queryClient.setQueryData(queryKey, newData);
|
|
160
159
|
};
|
|
@@ -164,7 +163,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
164
163
|
return modelConfig;
|
|
165
164
|
};
|
|
166
165
|
const update = (id, data, path) => {
|
|
167
|
-
const oldData = findAll(path) ?? [];
|
|
166
|
+
const oldData = (findAll(path) ?? []);
|
|
168
167
|
const modelConfig = getModelConfig();
|
|
169
168
|
if (!modelConfig?.idColumn) {
|
|
170
169
|
return undefined;
|
|
@@ -189,7 +188,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
189
188
|
return updatedRecord;
|
|
190
189
|
};
|
|
191
190
|
const remove = (id, path) => {
|
|
192
|
-
const oldData = findAll(path) ?? [];
|
|
191
|
+
const oldData = (findAll(path) ?? []);
|
|
193
192
|
const modelConfig = getModelConfig();
|
|
194
193
|
if (!modelConfig?.idColumn) {
|
|
195
194
|
return false;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export interface QueryModelBuilder<T> {
|
|
2
2
|
add: (data: T, position?: QueryModelAddPosition, path?: string) => T | undefined;
|
|
3
|
-
findAll: (path?: string) => T[] | undefined;
|
|
3
|
+
findAll: (path?: string) => T[] | T | undefined;
|
|
4
4
|
findMany: (selector: (record: T) => boolean, path?: string) => T[];
|
|
5
5
|
find: (id: number | string, path?: string) => T | undefined;
|
|
6
6
|
update: (id: number | string, data: Partial<T>, path?: string) => T | undefined;
|
|
7
7
|
remove: (id: number, path?: string) => boolean;
|
|
8
8
|
get: (path?: string) => T | undefined;
|
|
9
|
-
set: (data: Partial<
|
|
9
|
+
set: <DataType>(data: Partial<DataType>, path?: string) => DataType | undefined;
|
|
10
10
|
}
|
|
11
11
|
export type QueryModelAddPosition = 'start' | 'end';
|
|
@@ -8,7 +8,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
8
8
|
const { getQueryKey } = useKeyTrackerModel(keyTracker);
|
|
9
9
|
const queryKey = getQueryKey();
|
|
10
10
|
const add = (data, position, path) => {
|
|
11
|
-
let records = findAll(path) ?? [];
|
|
11
|
+
let records = (findAll(path) ?? []);
|
|
12
12
|
if (!position || position === 'end') {
|
|
13
13
|
records = [...records, data];
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -36,7 +36,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
36
36
|
return result(data, path, []);
|
|
37
37
|
};
|
|
38
38
|
const findMany = (selector, path) => {
|
|
39
|
-
const data = findAll(path) ?? [];
|
|
39
|
+
const data = (findAll(path) ?? []);
|
|
40
40
|
return data.filter(selector);
|
|
41
41
|
};
|
|
42
42
|
const find = (id, path) => {
|
|
@@ -44,7 +44,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
44
44
|
if (!modelConfig?.idColumn) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
|
-
const data = findAll(path) ?? [];
|
|
47
|
+
const data = (findAll(path) ?? []);
|
|
48
48
|
return data.find((record) => record[modelConfig.idColumn] === id);
|
|
49
49
|
};
|
|
50
50
|
const get = (path) => {
|
|
@@ -58,7 +58,6 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
58
58
|
if (path) {
|
|
59
59
|
const data = get();
|
|
60
60
|
newData = lodashSet(data, path, newData);
|
|
61
|
-
return queryClient.setQueryData(queryKey, newData);
|
|
62
61
|
}
|
|
63
62
|
return queryClient.setQueryData(queryKey, newData);
|
|
64
63
|
};
|
|
@@ -68,7 +67,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
68
67
|
return modelConfig;
|
|
69
68
|
};
|
|
70
69
|
const update = (id, data, path) => {
|
|
71
|
-
const oldData = findAll(path) ?? [];
|
|
70
|
+
const oldData = (findAll(path) ?? []);
|
|
72
71
|
const modelConfig = getModelConfig();
|
|
73
72
|
if (!modelConfig?.idColumn) {
|
|
74
73
|
return undefined;
|
|
@@ -93,7 +92,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
93
92
|
return updatedRecord;
|
|
94
93
|
};
|
|
95
94
|
const remove = (id, path) => {
|
|
96
|
-
const oldData = findAll(path) ?? [];
|
|
95
|
+
const oldData = (findAll(path) ?? []);
|
|
97
96
|
const modelConfig = getModelConfig();
|
|
98
97
|
if (!modelConfig?.idColumn) {
|
|
99
98
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQueryModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export interface QueryModelBuilder<T> {
|
|
2
2
|
add: (data: T, position?: QueryModelAddPosition, path?: string) => T | undefined;
|
|
3
|
-
findAll: (path?: string) => T[] | undefined;
|
|
3
|
+
findAll: (path?: string) => T[] | T | undefined;
|
|
4
4
|
findMany: (selector: (record: T) => boolean, path?: string) => T[];
|
|
5
5
|
find: (id: number | string, path?: string) => T | undefined;
|
|
6
6
|
update: (id: number | string, data: Partial<T>, path?: string) => T | undefined;
|
|
7
7
|
remove: (id: number, path?: string) => boolean;
|
|
8
8
|
get: (path?: string) => T | undefined;
|
|
9
|
-
set: (data: Partial<
|
|
9
|
+
set: <DataType>(data: Partial<DataType>, path?: string) => DataType | undefined;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type QueryModelAddPosition = 'start' | 'end';
|
|
@@ -11,7 +11,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
11
11
|
const queryKey = getQueryKey() as any[];
|
|
12
12
|
|
|
13
13
|
const add = (data: T, position?: QueryModelAddPosition, path?: string): T | undefined => {
|
|
14
|
-
let records = findAll(path) ?? [];
|
|
14
|
+
let records = (findAll(path) ?? []) as T[];
|
|
15
15
|
|
|
16
16
|
if (!position || position === 'end') {
|
|
17
17
|
records = [...records, data];
|
|
@@ -30,7 +30,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
30
30
|
return data;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const findAll = (path?: string): T[] | undefined => {
|
|
33
|
+
const findAll = (path?: string): T[] | T | undefined => {
|
|
34
34
|
const data = queryClient.getQueryData(queryKey, { exact });
|
|
35
35
|
|
|
36
36
|
if (!data) {
|
|
@@ -45,7 +45,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const findMany = (selector: (record: T) => boolean, path?: string): T[] => {
|
|
48
|
-
const data = findAll(path) ?? [];
|
|
48
|
+
const data = (findAll(path) ?? []) as T[];
|
|
49
49
|
return data.filter(selector);
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
55
55
|
if (!modelConfig?.idColumn) {
|
|
56
56
|
return undefined;
|
|
57
57
|
}
|
|
58
|
-
const data = findAll(path) ?? [];
|
|
58
|
+
const data = (findAll(path) ?? []) as T[];
|
|
59
59
|
|
|
60
60
|
return data.find((record) => (record as Record<string, any>)[modelConfig.idColumn] === id);
|
|
61
61
|
};
|
|
@@ -68,14 +68,13 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
68
68
|
return data as T;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
const set = (newData:
|
|
71
|
+
const set = <DataType>(newData: Partial<DataType>, path?: string): DataType | undefined => {
|
|
72
72
|
if (path) {
|
|
73
73
|
const data = get() as any;
|
|
74
74
|
newData = lodashSet(data, path, newData);
|
|
75
|
-
|
|
76
|
-
return queryClient.setQueryData(queryKey, newData) as T;
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
|
|
77
|
+
return queryClient.setQueryData(queryKey, newData) as DataType;
|
|
79
78
|
};
|
|
80
79
|
|
|
81
80
|
const getModelConfig = () => {
|
|
@@ -86,7 +85,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
86
85
|
};
|
|
87
86
|
|
|
88
87
|
const update = (id: string | number, data: Partial<T>, path?: string): T | undefined => {
|
|
89
|
-
const oldData = findAll(path) ?? [];
|
|
88
|
+
const oldData = (findAll(path) ?? []) as T[];
|
|
90
89
|
const modelConfig = getModelConfig();
|
|
91
90
|
|
|
92
91
|
if (!modelConfig?.idColumn) {
|
|
@@ -115,7 +114,7 @@ export const useQueryModel = <T>(keyTracker: string, exact: boolean = true): Que
|
|
|
115
114
|
};
|
|
116
115
|
|
|
117
116
|
const remove = (id: number | string, path?: string): boolean => {
|
|
118
|
-
const oldData = findAll(path) ?? [];
|
|
117
|
+
const oldData = (findAll(path) ?? []) as T[];
|
|
119
118
|
const modelConfig = getModelConfig();
|
|
120
119
|
|
|
121
120
|
if (!modelConfig?.idColumn) {
|