@gaddario98/react-core 2.1.5 → 2.1.6
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/README.md +630 -4
- package/dist/pages/index.d.ts +527 -682
- package/dist/pages/index.js +234 -253
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/index.mjs +234 -253
- package/dist/pages/index.mjs.map +1 -1
- package/dist/queries/index.d.ts +25 -4
- package/dist/queries/index.js +211 -216
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +211 -216
- package/dist/queries/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/queries/index.d.ts
CHANGED
|
@@ -223,15 +223,30 @@ type GetApiValuesFunction<Q extends QueriesArray> = {
|
|
|
223
223
|
(type: 'query' | 'mutation', key: string, defaultValue?: unknown): unknown;
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
-
type
|
|
227
|
-
type
|
|
226
|
+
type SetStateAction<S> = S | ((prevState: S) => S);
|
|
227
|
+
type QueryStoreEntry<Q extends QueriesArray = QueriesArray> = QueryResult<Q[number]["response"]>;
|
|
228
|
+
type MutationStoreEntry<Q extends QueriesArray = QueriesArray> = UseMutationResult<Q[number]["response"], Error, Q[number]["props"], unknown>;
|
|
228
229
|
declare const DEFAULT_QUERY_ENTRY: QueryStoreEntry;
|
|
229
230
|
declare const DEFAULT_MUTATION_ENTRY: MutationStoreEntry;
|
|
231
|
+
/**
|
|
232
|
+
* Global atom storing all query results with localStorage persistence.
|
|
233
|
+
* Used when `persistQueries` is `true` (default).
|
|
234
|
+
*/
|
|
235
|
+
declare const queriesAtomWithStorage: jotai.WritableAtom<Record<string, QueryStoreEntry<QueriesArray>>, [Record<string, QueryStoreEntry<QueriesArray>> | typeof jotai_utils.RESET | ((prev: Record<string, QueryStoreEntry<QueriesArray>>) => Record<string, QueryStoreEntry<QueriesArray>> | typeof jotai_utils.RESET)], void>;
|
|
236
|
+
/**
|
|
237
|
+
* Global atom storing all query results in memory only (no persistence).
|
|
238
|
+
* Used when `persistQueries` is `false`.
|
|
239
|
+
*/
|
|
240
|
+
declare const queriesAtomBase: jotai.PrimitiveAtom<Record<string, QueryStoreEntry<QueriesArray>>> & {
|
|
241
|
+
init: Record<string, QueryStoreEntry<QueriesArray>>;
|
|
242
|
+
};
|
|
230
243
|
/**
|
|
231
244
|
* Global atom storing all query results.
|
|
245
|
+
* Delegates to `queriesAtomWithStorage` or `queriesAtomBase` based on
|
|
246
|
+
* the `persistQueries` flag in `ApiConfig` (defaults to `true`).
|
|
232
247
|
* Key format: "scopeId:queryKey"
|
|
233
248
|
*/
|
|
234
|
-
declare const queriesAtom: jotai.WritableAtom<Record<string, QueryStoreEntry<QueriesArray>>, [
|
|
249
|
+
declare const queriesAtom: jotai.WritableAtom<Record<string, QueryStoreEntry<QueriesArray>>, [update: SetStateAction<Record<string, QueryStoreEntry<QueriesArray>>>], void>;
|
|
235
250
|
/**
|
|
236
251
|
* Global atom storing all mutation results.
|
|
237
252
|
* Key format: "scopeId:mutationKey"
|
|
@@ -286,6 +301,12 @@ interface ApiConfig {
|
|
|
286
301
|
};
|
|
287
302
|
encryption?: EncryptionConfig;
|
|
288
303
|
showNotification?: (notification: ApiNotificationMessage) => void;
|
|
304
|
+
/**
|
|
305
|
+
* Whether to persist query results to storage (e.g. localStorage).
|
|
306
|
+
* Defaults to `true` for backward compatibility.
|
|
307
|
+
* Set to `false` to use an in-memory atom without any storage persistence.
|
|
308
|
+
*/
|
|
309
|
+
persistQueries?: boolean;
|
|
289
310
|
}
|
|
290
311
|
declare const apiConfigAtom: _gaddario98_react_state.PrimitiveAtom<ApiConfig>;
|
|
291
312
|
declare const useApiConfigValue: () => ApiConfig;
|
|
@@ -368,5 +389,5 @@ declare const decryptData: (encryptedData: string, secretKey: string) => Promise
|
|
|
368
389
|
declare const apiRequest: <TProps, TResponse, TConverter = TProps>({ method, url, body, headers, converter, }: ApiRequestFnProps<TProps, TConverter>) => Promise<TResponse>;
|
|
369
390
|
declare const fetchRequest: <TProps, TResponse>(url: string, headers?: AxiosRequestConfig["headers"]) => Promise<TResponse>;
|
|
370
391
|
|
|
371
|
-
export { DEFAULT_MUTATION_ENTRY, DEFAULT_QUERY_ENTRY, QueriesProvider, ab2str, algorithm, apiConfigAtom, apiRequest, createMutationSelector, createQuerySelector, createScopeMutationsAtom, createScopeQueriesAtom, decryptData, encryptData, fetchRequest, getCompositeKey, importKey, mutationsAtom, queriesAtom, str2ab, useApi, useApiConfigReset, useApiConfigState, useApiConfigValue, useApiValues, useInvalidateQueries, useJotaiMutations, useJotaiQueries, useMultipleMutation, useMultipleQuery, useMultipleWebSocket, useMutateApi, useQueryApi, useWebSocket };
|
|
392
|
+
export { DEFAULT_MUTATION_ENTRY, DEFAULT_QUERY_ENTRY, QueriesProvider, ab2str, algorithm, apiConfigAtom, apiRequest, createMutationSelector, createQuerySelector, createScopeMutationsAtom, createScopeQueriesAtom, decryptData, encryptData, fetchRequest, getCompositeKey, importKey, mutationsAtom, queriesAtom, queriesAtomBase, queriesAtomWithStorage, str2ab, useApi, useApiConfigReset, useApiConfigState, useApiConfigValue, useApiValues, useInvalidateQueries, useJotaiMutations, useJotaiQueries, useMultipleMutation, useMultipleQuery, useMultipleWebSocket, useMutateApi, useQueryApi, useWebSocket };
|
|
372
393
|
export type { AllMutation, ApiConfig, ApiConverter, ApiMethod, ApiNotificationMessage, ApiRequestFnProps, ContextValue, CustomMutation, CustomMutationOptions, CustomQueryOptions, EncryptionConfig, Endpoint, ExtractMutation, ExtractMutationByKey, ExtractQuery, ExtractQueryByKey, ExtractQueryResponse, ExtractWebSocket, GetApiValuesFunction, MultipleQueryResponse, MultipleWebSocketResponse, MutationActionInternal, MutationConfig, MutationItem, MutationStateInternal, MutationStoreEntry, QueriesArray, QueriesProps, QueryAtIndex, QueryConfig, QueryConfigArray, QueryDefinition, QueryItem, QueryProps, QueryResult, QueryStoreEntry, SingleQueryConfig, UseApiOptions, WebSocketDefinition, WebSocketResult, WebSocketsArray };
|
package/dist/queries/index.js
CHANGED
|
@@ -1,4 +1,111 @@
|
|
|
1
|
-
'use strict';var jotai=require('jotai'),utils=require('jotai/utils'),index_ts=require('../state/index.js'),reactQuery=require('@tanstack/react-query'),axios=require('axios'),React=require('react'),compilerRuntime=require('react/compiler-runtime'),equal=require('fast-deep-equal'),jsxRuntime=require('react/jsx-runtime');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var React__namespace=/*#__PURE__*/_interopNamespaceDefault(React)
|
|
1
|
+
'use strict';var jotai=require('jotai'),utils=require('jotai/utils'),index_ts=require('../state/index.js'),reactQuery=require('@tanstack/react-query'),axios=require('axios'),React=require('react'),compilerRuntime=require('react/compiler-runtime'),equal=require('fast-deep-equal'),jsxRuntime=require('react/jsx-runtime');function _interopNamespaceDefault(e){var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var React__namespace=/*#__PURE__*/_interopNamespaceDefault(React);const apiClient = axios.create({
|
|
2
|
+
timeout: 30000,
|
|
3
|
+
headers: {
|
|
4
|
+
"Content-Type": "application/json"
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
apiClient.interceptors.response.use(response => response, error => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
if (error.response) {
|
|
10
|
+
throw new Error(((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.message) || ((_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) || `Error ${error.response.status}`);
|
|
11
|
+
} else if (error.request) {
|
|
12
|
+
throw new Error("No response from server - request timeout or network issue");
|
|
13
|
+
} else {
|
|
14
|
+
throw new Error("Request configuration error");
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const apiRequest = async ({
|
|
18
|
+
method,
|
|
19
|
+
url,
|
|
20
|
+
body,
|
|
21
|
+
headers,
|
|
22
|
+
converter
|
|
23
|
+
}) => {
|
|
24
|
+
try {
|
|
25
|
+
const isPrimitive = typeof body === "string" || typeof body === "number" || typeof body === "boolean";
|
|
26
|
+
let finalUrl = url;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
let finalBody = body;
|
|
29
|
+
// 1. Primitive Body Handling (Append to URL)
|
|
30
|
+
if (isPrimitive && body) {
|
|
31
|
+
if (method !== "POST") {
|
|
32
|
+
finalUrl = `${url}/${body}`;
|
|
33
|
+
finalBody = undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// 2. Object Body Handling (Path Param Replacement)
|
|
37
|
+
if (!isPrimitive && typeof body === "object" && body !== null) {
|
|
38
|
+
// Look for :param in string
|
|
39
|
+
// e.g. /users/:uid/availability
|
|
40
|
+
const pathParams = finalUrl.match(/:[a-zA-Z0-9_]+/g);
|
|
41
|
+
if (pathParams) {
|
|
42
|
+
// Create shallow copy to avoid mutating original
|
|
43
|
+
finalBody = Object.assign({}, body);
|
|
44
|
+
pathParams.forEach(param => {
|
|
45
|
+
if (finalBody) {
|
|
46
|
+
const key = param.substring(1); // remove :
|
|
47
|
+
if (key in finalBody) {
|
|
48
|
+
finalUrl = finalUrl.replace(param, String(finalBody[key]));
|
|
49
|
+
// Optional: remove from body if it was used in path?
|
|
50
|
+
// Usually yes for simple IDs, maybe not for others.
|
|
51
|
+
// Let's remove to keep body clean.
|
|
52
|
+
delete finalBody[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const data = converter && finalBody ? converter(finalBody) : finalBody;
|
|
59
|
+
const response = await apiClient({
|
|
60
|
+
url: finalUrl,
|
|
61
|
+
method,
|
|
62
|
+
data,
|
|
63
|
+
headers
|
|
64
|
+
});
|
|
65
|
+
if (response.status >= 200 && response.status < 300) {
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error("API Request Error:", error);
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
throw new Error("Unknown error occurred");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const fetchRequest = async (url, headers) => {
|
|
78
|
+
return apiRequest({
|
|
79
|
+
url,
|
|
80
|
+
method: "GET",
|
|
81
|
+
headers
|
|
82
|
+
});
|
|
83
|
+
};const _endpoints = {
|
|
84
|
+
custom: '',
|
|
85
|
+
api: 'http://localhost:3000' // import.meta.env.VITE_API_URL ||
|
|
86
|
+
};
|
|
87
|
+
const defaultQueryClient = new reactQuery.QueryClient({
|
|
88
|
+
defaultOptions: {
|
|
89
|
+
queries: {
|
|
90
|
+
retry: 2
|
|
91
|
+
// staleTime: 2 * 60 * 1000,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
const {
|
|
96
|
+
atom: apiConfigAtom,
|
|
97
|
+
useValue: useApiConfigValue,
|
|
98
|
+
useState: useApiConfigState,
|
|
99
|
+
useReset: useApiConfigReset
|
|
100
|
+
} = index_ts.atomStateGenerator({
|
|
101
|
+
key: 'apiConfig',
|
|
102
|
+
defaultValue: {
|
|
103
|
+
endpoints: _endpoints,
|
|
104
|
+
requestFn: apiRequest,
|
|
105
|
+
queryClient: defaultQueryClient
|
|
106
|
+
},
|
|
107
|
+
persist: false
|
|
108
|
+
});// ============================================================================
|
|
2
109
|
// Default Values
|
|
3
110
|
// ============================================================================
|
|
4
111
|
const DEFAULT_QUERY_ENTRY = Object.freeze({
|
|
@@ -13,12 +120,12 @@ const DEFAULT_QUERY_ENTRY = Object.freeze({
|
|
|
13
120
|
error: null,
|
|
14
121
|
dataUpdatedAt: 0,
|
|
15
122
|
errorUpdatedAt: 0,
|
|
16
|
-
fetchStatus:
|
|
123
|
+
fetchStatus: "idle",
|
|
17
124
|
refetch: () => Promise.resolve()
|
|
18
125
|
});
|
|
19
126
|
const DEFAULT_MUTATION_ENTRY = Object.freeze({
|
|
20
127
|
data: undefined,
|
|
21
|
-
status:
|
|
128
|
+
status: "idle",
|
|
22
129
|
error: null,
|
|
23
130
|
variables: undefined,
|
|
24
131
|
submittedAt: 0,
|
|
@@ -37,12 +144,38 @@ const DEFAULT_MUTATION_ENTRY = Object.freeze({
|
|
|
37
144
|
// ============================================================================
|
|
38
145
|
// Global Atoms (single atom for all queries, single atom for all mutations)
|
|
39
146
|
// ============================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Global atom storing all query results with localStorage persistence.
|
|
149
|
+
* Used when `persistQueries` is `true` (default).
|
|
150
|
+
*/
|
|
151
|
+
const queriesAtomWithStorage = utils.atomWithStorage("queries-atom", {}, utils.createJSONStorage(() => index_ts.storage), {
|
|
152
|
+
getOnInit: true
|
|
153
|
+
});
|
|
154
|
+
/**
|
|
155
|
+
* Global atom storing all query results in memory only (no persistence).
|
|
156
|
+
* Used when `persistQueries` is `false`.
|
|
157
|
+
*/
|
|
158
|
+
const queriesAtomBase = jotai.atom({});
|
|
40
159
|
/**
|
|
41
160
|
* Global atom storing all query results.
|
|
161
|
+
* Delegates to `queriesAtomWithStorage` or `queriesAtomBase` based on
|
|
162
|
+
* the `persistQueries` flag in `ApiConfig` (defaults to `true`).
|
|
42
163
|
* Key format: "scopeId:queryKey"
|
|
43
164
|
*/
|
|
44
|
-
const queriesAtom =
|
|
45
|
-
|
|
165
|
+
const queriesAtom = jotai.atom(get => {
|
|
166
|
+
const {
|
|
167
|
+
persistQueries = true
|
|
168
|
+
} = get(apiConfigAtom);
|
|
169
|
+
return persistQueries ? get(queriesAtomWithStorage) : get(queriesAtomBase);
|
|
170
|
+
}, (get, set, update) => {
|
|
171
|
+
const {
|
|
172
|
+
persistQueries = true
|
|
173
|
+
} = get(apiConfigAtom);
|
|
174
|
+
if (persistQueries) {
|
|
175
|
+
set(queriesAtomWithStorage, update);
|
|
176
|
+
} else {
|
|
177
|
+
set(queriesAtomBase, update);
|
|
178
|
+
}
|
|
46
179
|
});
|
|
47
180
|
/**
|
|
48
181
|
* Global atom storing all mutation results.
|
|
@@ -132,132 +265,7 @@ const createMutationSelector = (scopeId, mutationKey) => {
|
|
|
132
265
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
133
266
|
return entry !== null && entry !== void 0 ? entry : DEFAULT_MUTATION_ENTRY;
|
|
134
267
|
}, (a, b) => a === b || a.data === b.data && a.isPending === b.isPending && a.error === b.error);
|
|
135
|
-
}
|
|
136
|
-
timeout: 30000,
|
|
137
|
-
headers: {
|
|
138
|
-
'Content-Type': 'application/json'
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
apiClient.interceptors.response.use(response => response, error => {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
if (error.response) {
|
|
144
|
-
throw new Error(((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.message) || ((_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) || `Error ${error.response.status}`);
|
|
145
|
-
} else if (error.request) {
|
|
146
|
-
throw new Error('No response from server - request timeout or network issue');
|
|
147
|
-
} else {
|
|
148
|
-
throw new Error('Request configuration error');
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
const apiRequest = async ({
|
|
152
|
-
method,
|
|
153
|
-
url,
|
|
154
|
-
body,
|
|
155
|
-
headers,
|
|
156
|
-
converter
|
|
157
|
-
}) => {
|
|
158
|
-
try {
|
|
159
|
-
const isPrimitive = typeof body === 'string' || typeof body === 'number' || typeof body === 'boolean';
|
|
160
|
-
let finalUrl = url;
|
|
161
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
-
let finalBody = body;
|
|
163
|
-
// 1. Primitive Body Handling (Append to URL)
|
|
164
|
-
if (isPrimitive && body) {
|
|
165
|
-
if (method !== 'POST') {
|
|
166
|
-
finalUrl = `${url}/${body}`;
|
|
167
|
-
finalBody = undefined;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// 2. Object Body Handling (Path Param Replacement)
|
|
171
|
-
if (!isPrimitive && typeof body === 'object' && body !== null) {
|
|
172
|
-
// Look for :param in string
|
|
173
|
-
// e.g. /users/:uid/availability
|
|
174
|
-
const pathParams = finalUrl.match(/:[a-zA-Z0-9_]+/g);
|
|
175
|
-
if (pathParams) {
|
|
176
|
-
// Create shallow copy to avoid mutating original
|
|
177
|
-
finalBody = Object.assign({}, body);
|
|
178
|
-
pathParams.forEach(param => {
|
|
179
|
-
if (finalBody) {
|
|
180
|
-
const key = param.substring(1); // remove :
|
|
181
|
-
if (key in finalBody) {
|
|
182
|
-
finalUrl = finalUrl.replace(param, String(finalBody[key]));
|
|
183
|
-
// Optional: remove from body if it was used in path?
|
|
184
|
-
// Usually yes for simple IDs, maybe not for others.
|
|
185
|
-
// Let's remove to keep body clean.
|
|
186
|
-
delete finalBody[key];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
// Also handle case where we append ID to end if URL ends with / and we have 'id' or 'uid' in body?
|
|
192
|
-
// No, explicit :param or explicit append logic is safer.
|
|
193
|
-
// But we have logic for 'updateUser' where we just set endpoint ['api', 'users'] and method PUT.
|
|
194
|
-
// We expect /users/123.
|
|
195
|
-
// If body is { uid: 123, ...data }, we want /users/123.
|
|
196
|
-
// If no :param is found, and method is PUT/DELETE/PATCH, and body has 'id' or 'uid', should we append?
|
|
197
|
-
// User asked to eliminate customRequest.
|
|
198
|
-
// Let's add: "If method is PUT/DELETE/PATCH, and no :param replacement happened, and body has (id|uid), append it."
|
|
199
|
-
const hasId = 'id' in finalBody || 'uid' in finalBody;
|
|
200
|
-
if ((method === 'PUT' || method === 'DELETE' || method === 'PATCH') && hasId && !pathParams) {
|
|
201
|
-
const id = finalBody.id || finalBody.uid;
|
|
202
|
-
if (id) {
|
|
203
|
-
finalUrl = `${finalUrl}/${id}`;
|
|
204
|
-
// We generally DON'T remove ID from body in this implicit case as it might be needed for validation
|
|
205
|
-
// But for cleaner API calls we might want to.
|
|
206
|
-
// Let's keep it safe: Don't remove ID here.
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
const data = converter && finalBody ? converter(finalBody) : finalBody;
|
|
211
|
-
const response = await apiClient({
|
|
212
|
-
url: finalUrl,
|
|
213
|
-
method,
|
|
214
|
-
data,
|
|
215
|
-
headers
|
|
216
|
-
});
|
|
217
|
-
if (response.status >= 200 && response.status < 300) {
|
|
218
|
-
return response.data;
|
|
219
|
-
}
|
|
220
|
-
throw new Error(`Request failed with status ${response.status}`);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error('API Request Error:', error);
|
|
223
|
-
if (error instanceof Error) {
|
|
224
|
-
throw error;
|
|
225
|
-
}
|
|
226
|
-
throw new Error('Unknown error occurred');
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
const fetchRequest = async (url, headers) => {
|
|
230
|
-
return apiRequest({
|
|
231
|
-
url,
|
|
232
|
-
method: 'GET',
|
|
233
|
-
headers
|
|
234
|
-
});
|
|
235
|
-
};const _endpoints = {
|
|
236
|
-
custom: '',
|
|
237
|
-
api: 'http://localhost:3000' // import.meta.env.VITE_API_URL ||
|
|
238
|
-
};
|
|
239
|
-
const defaultQueryClient = new reactQuery.QueryClient({
|
|
240
|
-
defaultOptions: {
|
|
241
|
-
queries: {
|
|
242
|
-
retry: 2
|
|
243
|
-
// staleTime: 2 * 60 * 1000,
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
const {
|
|
248
|
-
atom: apiConfigAtom,
|
|
249
|
-
useValue: useApiConfigValue,
|
|
250
|
-
useState: useApiConfigState,
|
|
251
|
-
useReset: useApiConfigReset
|
|
252
|
-
} = index_ts.atomStateGenerator({
|
|
253
|
-
key: 'apiConfig',
|
|
254
|
-
defaultValue: {
|
|
255
|
-
endpoints: _endpoints,
|
|
256
|
-
requestFn: apiRequest,
|
|
257
|
-
queryClient: defaultQueryClient
|
|
258
|
-
},
|
|
259
|
-
persist: false
|
|
260
|
-
});/******************************************************************************
|
|
268
|
+
};/******************************************************************************
|
|
261
269
|
Copyright (c) Microsoft Corporation.
|
|
262
270
|
|
|
263
271
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -508,7 +516,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
508
516
|
}, [result.data, result.status, result.error, result.variables, result.submittedAt, result.isIdle, result.isPending, result.isSuccess, result.isError, setMutationsAtom, compositeKey]);
|
|
509
517
|
return result;
|
|
510
518
|
};const useMultipleQuery = t0 => {
|
|
511
|
-
const $ = compilerRuntime.c(
|
|
519
|
+
const $ = compilerRuntime.c(27);
|
|
512
520
|
let t1;
|
|
513
521
|
if ($[0] !== t0) {
|
|
514
522
|
t1 = t0 === undefined ? [] : t0;
|
|
@@ -576,55 +584,27 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
576
584
|
}
|
|
577
585
|
const generateQueryFn = t4;
|
|
578
586
|
let t5;
|
|
579
|
-
let t6;
|
|
580
587
|
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
|
|
581
|
-
t5 = {
|
|
582
|
-
|
|
588
|
+
t5 = {
|
|
589
|
+
data: {},
|
|
590
|
+
results: {}
|
|
591
|
+
};
|
|
583
592
|
$[10] = t5;
|
|
584
|
-
$[11] = t6;
|
|
585
593
|
} else {
|
|
586
594
|
t5 = $[10];
|
|
587
|
-
t6 = $[11];
|
|
588
|
-
}
|
|
589
|
-
let t7;
|
|
590
|
-
if ($[12] !== settings) {
|
|
591
|
-
t7 = {
|
|
592
|
-
settings,
|
|
593
|
-
data: t5,
|
|
594
|
-
results: t6
|
|
595
|
-
};
|
|
596
|
-
$[12] = settings;
|
|
597
|
-
$[13] = t7;
|
|
598
|
-
} else {
|
|
599
|
-
t7 = $[13];
|
|
600
|
-
}
|
|
601
|
-
const ref = React.useRef(t7);
|
|
602
|
-
let t8;
|
|
603
|
-
let t9;
|
|
604
|
-
if ($[14] !== settings) {
|
|
605
|
-
t8 = () => {
|
|
606
|
-
ref.current.settings = settings;
|
|
607
|
-
};
|
|
608
|
-
t9 = [settings];
|
|
609
|
-
$[14] = settings;
|
|
610
|
-
$[15] = t8;
|
|
611
|
-
$[16] = t9;
|
|
612
|
-
} else {
|
|
613
|
-
t8 = $[15];
|
|
614
|
-
t9 = $[16];
|
|
615
595
|
}
|
|
616
|
-
React.
|
|
617
|
-
let
|
|
618
|
-
if ($[
|
|
619
|
-
let
|
|
620
|
-
if ($[
|
|
621
|
-
|
|
596
|
+
const ref = React.useRef(t5);
|
|
597
|
+
let t6;
|
|
598
|
+
if ($[11] !== generateQueryFn || $[12] !== isLogged || $[13] !== settings) {
|
|
599
|
+
let t7;
|
|
600
|
+
if ($[15] !== generateQueryFn || $[16] !== isLogged) {
|
|
601
|
+
t7 = setting => {
|
|
622
602
|
const {
|
|
623
603
|
queryKey,
|
|
624
|
-
enabled:
|
|
604
|
+
enabled: t8,
|
|
625
605
|
disableAuthControl
|
|
626
606
|
} = setting;
|
|
627
|
-
const enabled =
|
|
607
|
+
const enabled = t8 === undefined ? true : t8;
|
|
628
608
|
const rest = __rest(setting, ["queryKey", "enabled", "disableAuthControl"]);
|
|
629
609
|
return Object.assign({
|
|
630
610
|
queryKey,
|
|
@@ -632,25 +612,28 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
632
612
|
enabled: !!enabled && (disableAuthControl || !!isLogged)
|
|
633
613
|
}, rest);
|
|
634
614
|
};
|
|
635
|
-
$[
|
|
636
|
-
$[
|
|
637
|
-
$[
|
|
615
|
+
$[15] = generateQueryFn;
|
|
616
|
+
$[16] = isLogged;
|
|
617
|
+
$[17] = t7;
|
|
638
618
|
} else {
|
|
639
|
-
|
|
619
|
+
t7 = $[17];
|
|
640
620
|
}
|
|
641
|
-
|
|
642
|
-
$[
|
|
643
|
-
$[
|
|
644
|
-
$[
|
|
645
|
-
$[
|
|
621
|
+
t6 = settings.map(t7);
|
|
622
|
+
$[11] = generateQueryFn;
|
|
623
|
+
$[12] = isLogged;
|
|
624
|
+
$[13] = settings;
|
|
625
|
+
$[14] = t6;
|
|
646
626
|
} else {
|
|
647
|
-
|
|
627
|
+
t6 = $[14];
|
|
648
628
|
}
|
|
649
|
-
const queries =
|
|
650
|
-
let
|
|
651
|
-
if ($[
|
|
652
|
-
|
|
653
|
-
const setting_0 =
|
|
629
|
+
const queries = t6;
|
|
630
|
+
let t7;
|
|
631
|
+
if ($[18] !== settings) {
|
|
632
|
+
t7 = results => results.reduce((prev, result, index) => {
|
|
633
|
+
const setting_0 = settings[index];
|
|
634
|
+
if (!setting_0) {
|
|
635
|
+
return prev;
|
|
636
|
+
}
|
|
654
637
|
const keyToMap = setting_0.keyToMap;
|
|
655
638
|
Object.assign(prev, {
|
|
656
639
|
[keyToMap]: {
|
|
@@ -665,28 +648,30 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
665
648
|
});
|
|
666
649
|
return prev;
|
|
667
650
|
}, {});
|
|
668
|
-
$[
|
|
651
|
+
$[18] = settings;
|
|
652
|
+
$[19] = t7;
|
|
669
653
|
} else {
|
|
670
|
-
|
|
654
|
+
t7 = $[19];
|
|
671
655
|
}
|
|
672
|
-
const combine =
|
|
673
|
-
let
|
|
674
|
-
if ($[
|
|
675
|
-
|
|
656
|
+
const combine = t7;
|
|
657
|
+
let t8;
|
|
658
|
+
if ($[20] !== combine || $[21] !== queries) {
|
|
659
|
+
t8 = {
|
|
676
660
|
queries,
|
|
677
661
|
combine
|
|
678
662
|
};
|
|
679
|
-
$[
|
|
680
|
-
$[
|
|
663
|
+
$[20] = combine;
|
|
664
|
+
$[21] = queries;
|
|
665
|
+
$[22] = t8;
|
|
681
666
|
} else {
|
|
682
|
-
|
|
667
|
+
t8 = $[22];
|
|
683
668
|
}
|
|
684
|
-
const result_0 = reactQuery.useQueries(
|
|
685
|
-
let
|
|
686
|
-
let
|
|
687
|
-
if ($[
|
|
688
|
-
|
|
689
|
-
|
|
669
|
+
const result_0 = reactQuery.useQueries(t8, queryClient);
|
|
670
|
+
let t10;
|
|
671
|
+
let t9;
|
|
672
|
+
if ($[23] !== result_0 || $[24] !== settings) {
|
|
673
|
+
t9 = () => {
|
|
674
|
+
settings.forEach(setting_1 => {
|
|
690
675
|
const {
|
|
691
676
|
keyToMap: keyToMap_0,
|
|
692
677
|
onDataChanged,
|
|
@@ -696,6 +681,9 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
696
681
|
return;
|
|
697
682
|
}
|
|
698
683
|
const currentResult = result_0[keyToMap_0];
|
|
684
|
+
if (!currentResult) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
699
687
|
const prevResult = ref.current.results[keyToMap_0];
|
|
700
688
|
if (onStateChange) {
|
|
701
689
|
if (!prevResult || prevResult.data !== currentResult.data || prevResult.isLoading !== currentResult.isLoading || prevResult.isLoadingMapped !== currentResult.isLoadingMapped || prevResult.isFetching !== currentResult.isFetching || prevResult.isPending !== currentResult.isPending || prevResult.error !== currentResult.error) {
|
|
@@ -713,15 +701,16 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
713
701
|
}
|
|
714
702
|
});
|
|
715
703
|
};
|
|
716
|
-
|
|
717
|
-
$[
|
|
718
|
-
$[
|
|
719
|
-
$[
|
|
704
|
+
t10 = [result_0, settings];
|
|
705
|
+
$[23] = result_0;
|
|
706
|
+
$[24] = settings;
|
|
707
|
+
$[25] = t10;
|
|
708
|
+
$[26] = t9;
|
|
720
709
|
} else {
|
|
721
|
-
|
|
722
|
-
|
|
710
|
+
t10 = $[25];
|
|
711
|
+
t9 = $[26];
|
|
723
712
|
}
|
|
724
|
-
React.useEffect(
|
|
713
|
+
React.useEffect(t9, t10);
|
|
725
714
|
return result_0;
|
|
726
715
|
};/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
727
716
|
const defaultState = DEFAULT_MUTATION_ENTRY;
|
|
@@ -1020,11 +1009,11 @@ const useMultipleMutation = configs => {
|
|
|
1020
1009
|
}, [stableConfigs, lastMessages, statuses, createSendMessage]);
|
|
1021
1010
|
return result;
|
|
1022
1011
|
};function useApi(configs, optionsOrId) {
|
|
1023
|
-
const options = typeof optionsOrId ===
|
|
1012
|
+
const options = typeof optionsOrId === "string" ? {
|
|
1024
1013
|
scopeId: optionsOrId
|
|
1025
1014
|
} : optionsOrId !== null && optionsOrId !== void 0 ? optionsOrId : {};
|
|
1026
1015
|
const {
|
|
1027
|
-
scopeId =
|
|
1016
|
+
scopeId = "default",
|
|
1028
1017
|
persistToAtoms = true
|
|
1029
1018
|
} = options;
|
|
1030
1019
|
// Global atom setters
|
|
@@ -1046,9 +1035,14 @@ const useMultipleMutation = configs => {
|
|
|
1046
1035
|
}, [setMutationsAtom, scopeId]);
|
|
1047
1036
|
// Enhanced query configs with atom persistence
|
|
1048
1037
|
const enhancedQueryConfigs = React.useMemo(() => {
|
|
1049
|
-
const items = configs.filter(q => q.type ===
|
|
1038
|
+
const items = configs.filter(q => q.type === "query");
|
|
1050
1039
|
return items.map(item => {
|
|
1051
1040
|
if (!item.queryConfig) return null;
|
|
1041
|
+
const hasValidQueryKey = Array.isArray(item.queryConfig.queryKey) && item.queryConfig.queryKey.length > 0;
|
|
1042
|
+
const hasValidEndpoint = Array.isArray(item.queryConfig.endpoint) && item.queryConfig.endpoint.length > 0;
|
|
1043
|
+
if (!hasValidQueryKey || !hasValidEndpoint) {
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1052
1046
|
const key = item.key;
|
|
1053
1047
|
const originalOnStateChange = item.queryConfig.onStateChange;
|
|
1054
1048
|
return Object.assign(Object.assign({}, item.queryConfig), {
|
|
@@ -1068,7 +1062,7 @@ const useMultipleMutation = configs => {
|
|
|
1068
1062
|
JSON.stringify(configs), persistToAtoms, updateQueryAtom]);
|
|
1069
1063
|
// Enhanced mutation configs with atom persistence
|
|
1070
1064
|
const enhancedMutationItems = React.useMemo(() => {
|
|
1071
|
-
const items = configs.filter(q => q.type ===
|
|
1065
|
+
const items = configs.filter(q => q.type === "mutation" && !!q.mutationConfig);
|
|
1072
1066
|
return items.map(item => {
|
|
1073
1067
|
const key = item.key;
|
|
1074
1068
|
const originalOnStateChange = item.mutationConfig.onStateChange;
|
|
@@ -1085,7 +1079,7 @@ const useMultipleMutation = configs => {
|
|
|
1085
1079
|
});
|
|
1086
1080
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1087
1081
|
}, [JSON.stringify(configs), persistToAtoms, updateMutationAtom]);
|
|
1088
|
-
const webSocketItems = React.useMemo(() => configs.filter(q => q.type ===
|
|
1082
|
+
const webSocketItems = React.useMemo(() => configs.filter(q => q.type === "websocket"),
|
|
1089
1083
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1090
1084
|
[JSON.stringify(configs)]);
|
|
1091
1085
|
// Execute hooks
|
|
@@ -1110,7 +1104,8 @@ const useMultipleMutation = configs => {
|
|
|
1110
1104
|
}, [allQuery, allMutation, queryKeys, mutationKeys]);
|
|
1111
1105
|
const refreshQueries = React.useCallback(() => {
|
|
1112
1106
|
ref.current.queryKeys.forEach(k => {
|
|
1113
|
-
|
|
1107
|
+
var _a;
|
|
1108
|
+
(_a = ref.current.allQuery[k]) === null || _a === void 0 ? void 0 : _a.refetch();
|
|
1114
1109
|
});
|
|
1115
1110
|
}, []);
|
|
1116
1111
|
return {
|
|
@@ -1729,4 +1724,4 @@ const decryptData = async (encryptedData, secretKey) => {
|
|
|
1729
1724
|
console.error('Decryption failed:', error);
|
|
1730
1725
|
throw new Error('Decryption failed');
|
|
1731
1726
|
}
|
|
1732
|
-
};exports.DEFAULT_MUTATION_ENTRY=DEFAULT_MUTATION_ENTRY;exports.DEFAULT_QUERY_ENTRY=DEFAULT_QUERY_ENTRY;exports.QueriesProvider=QueriesProvider;exports.ab2str=ab2str;exports.algorithm=algorithm;exports.apiConfigAtom=apiConfigAtom;exports.apiRequest=apiRequest;exports.createMutationSelector=createMutationSelector;exports.createQuerySelector=createQuerySelector;exports.createScopeMutationsAtom=createScopeMutationsAtom;exports.createScopeQueriesAtom=createScopeQueriesAtom;exports.decryptData=decryptData;exports.encryptData=encryptData;exports.fetchRequest=fetchRequest;exports.getCompositeKey=getCompositeKey;exports.importKey=importKey;exports.mutationsAtom=mutationsAtom;exports.queriesAtom=queriesAtom;exports.str2ab=str2ab;exports.useApi=useApi;exports.useApiConfigReset=useApiConfigReset;exports.useApiConfigState=useApiConfigState;exports.useApiConfigValue=useApiConfigValue;exports.useApiValues=useApiValues;exports.useInvalidateQueries=useInvalidateQueries;exports.useJotaiMutations=useJotaiMutations;exports.useJotaiQueries=useJotaiQueries;exports.useMultipleMutation=useMultipleMutation;exports.useMultipleQuery=useMultipleQuery;exports.useMultipleWebSocket=useMultipleWebSocket;exports.useMutateApi=useMutateApi;exports.useQueryApi=useQueryApi;exports.useWebSocket=useWebSocket;//# sourceMappingURL=index.js.map
|
|
1727
|
+
};exports.DEFAULT_MUTATION_ENTRY=DEFAULT_MUTATION_ENTRY;exports.DEFAULT_QUERY_ENTRY=DEFAULT_QUERY_ENTRY;exports.QueriesProvider=QueriesProvider;exports.ab2str=ab2str;exports.algorithm=algorithm;exports.apiConfigAtom=apiConfigAtom;exports.apiRequest=apiRequest;exports.createMutationSelector=createMutationSelector;exports.createQuerySelector=createQuerySelector;exports.createScopeMutationsAtom=createScopeMutationsAtom;exports.createScopeQueriesAtom=createScopeQueriesAtom;exports.decryptData=decryptData;exports.encryptData=encryptData;exports.fetchRequest=fetchRequest;exports.getCompositeKey=getCompositeKey;exports.importKey=importKey;exports.mutationsAtom=mutationsAtom;exports.queriesAtom=queriesAtom;exports.queriesAtomBase=queriesAtomBase;exports.queriesAtomWithStorage=queriesAtomWithStorage;exports.str2ab=str2ab;exports.useApi=useApi;exports.useApiConfigReset=useApiConfigReset;exports.useApiConfigState=useApiConfigState;exports.useApiConfigValue=useApiConfigValue;exports.useApiValues=useApiValues;exports.useInvalidateQueries=useInvalidateQueries;exports.useJotaiMutations=useJotaiMutations;exports.useJotaiQueries=useJotaiQueries;exports.useMultipleMutation=useMultipleMutation;exports.useMultipleQuery=useMultipleQuery;exports.useMultipleWebSocket=useMultipleWebSocket;exports.useMutateApi=useMutateApi;exports.useQueryApi=useQueryApi;exports.useWebSocket=useWebSocket;//# sourceMappingURL=index.js.map
|