@vef-framework/core 1.0.128 → 1.0.130
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/cjs/api/api-client.cjs +1 -546
- package/cjs/api/api-context.cjs +1 -97
- package/cjs/api/index.cjs +1 -16
- package/cjs/api/query-client.cjs +1 -32
- package/cjs/api/request-client.cjs +1 -252
- package/cjs/auth/auth-context.cjs +1 -38
- package/cjs/auth/index.cjs +1 -8
- package/cjs/expr/compiler.cjs +1 -301
- package/cjs/expr/helpers.cjs +1 -92
- package/cjs/index.cjs +1 -23
- package/cjs/middleware/dispatcher.cjs +1 -32
- package/esm/api/api-client.js +1 -543
- package/esm/api/api-context.js +1 -94
- package/esm/api/index.js +1 -5
- package/esm/api/query-client.js +1 -30
- package/esm/api/request-client.js +1 -249
- package/esm/auth/auth-context.js +1 -35
- package/esm/auth/index.js +1 -3
- package/esm/expr/compiler.js +1 -299
- package/esm/expr/helpers.js +1 -86
- package/esm/index.js +1 -9
- package/esm/middleware/dispatcher.js +1 -28
- package/package.json +2 -2
package/cjs/api/api-client.cjs
CHANGED
|
@@ -1,547 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var reactQuery = require('@tanstack/react-query');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
var queryClient = require('./query-client.cjs');
|
|
7
|
-
var requestClient = require('./request-client.cjs');
|
|
8
|
-
|
|
9
|
-
"use strict";
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __typeError = (msg) => {
|
|
12
|
-
throw TypeError(msg);
|
|
13
|
-
};
|
|
14
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
16
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
17
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
18
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
20
|
-
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
21
|
-
var _queryClient, _requestClient, _requestMethods, _currentSignal, _ApiClient_instances, selectData_fn, wrapRefetchFn_fn, createQueryResult_fn, createApi_fn;
|
|
22
|
-
class ApiClient {
|
|
23
|
-
/**
|
|
24
|
-
* Create an API client.
|
|
25
|
-
*
|
|
26
|
-
* @param options - The options of the API client.
|
|
27
|
-
*/
|
|
28
|
-
constructor(options) {
|
|
29
|
-
this.options = options;
|
|
30
|
-
__privateAdd(this, _ApiClient_instances);
|
|
31
|
-
/**
|
|
32
|
-
* The useApiQuery hook.
|
|
33
|
-
* These hook functions are doing this because React's Hooks cannot be used in class methods,
|
|
34
|
-
* and this approach can bypass the check.
|
|
35
|
-
*/
|
|
36
|
-
__publicField(this, "useApiQuery");
|
|
37
|
-
/**
|
|
38
|
-
* The useSuspenseApiQuery hook.
|
|
39
|
-
*/
|
|
40
|
-
__publicField(this, "useSuspenseApiQuery");
|
|
41
|
-
/**
|
|
42
|
-
* The useApiMutation hook.
|
|
43
|
-
* These hook functions are doing this because React's Hooks cannot be used in class methods,
|
|
44
|
-
* and this approach can bypass the check.
|
|
45
|
-
*/
|
|
46
|
-
__publicField(this, "useApiMutation");
|
|
47
|
-
/**
|
|
48
|
-
* The useIsFetching hook.
|
|
49
|
-
*/
|
|
50
|
-
__publicField(this, "useIsFetching");
|
|
51
|
-
/**
|
|
52
|
-
* The useIsMutating hook.
|
|
53
|
-
*/
|
|
54
|
-
__publicField(this, "useIsMutating");
|
|
55
|
-
/**
|
|
56
|
-
* THe QueryClientProvider component.
|
|
57
|
-
*/
|
|
58
|
-
__publicField(this, "QueryClientProvider");
|
|
59
|
-
/**
|
|
60
|
-
* The query client.
|
|
61
|
-
*/
|
|
62
|
-
__privateAdd(this, _queryClient);
|
|
63
|
-
/**
|
|
64
|
-
* The request client.
|
|
65
|
-
*/
|
|
66
|
-
__privateAdd(this, _requestClient);
|
|
67
|
-
/**
|
|
68
|
-
* The request methods.
|
|
69
|
-
*/
|
|
70
|
-
__privateAdd(this, _requestMethods);
|
|
71
|
-
/**
|
|
72
|
-
* The current signal.
|
|
73
|
-
*/
|
|
74
|
-
__privateAdd(this, _currentSignal);
|
|
75
|
-
__privateSet(this, _queryClient, queryClient.createQueryClient(options));
|
|
76
|
-
__privateSet(this, _requestClient, requestClient.createRequestClient(options));
|
|
77
|
-
__privateSet(this, _requestMethods, {
|
|
78
|
-
get: async (url, options2) => {
|
|
79
|
-
const signal = __privateGet(this, _currentSignal);
|
|
80
|
-
__privateSet(this, _currentSignal, void 0);
|
|
81
|
-
return await __privateGet(this, _requestClient).get(url, {
|
|
82
|
-
...options2,
|
|
83
|
-
signal
|
|
84
|
-
});
|
|
85
|
-
},
|
|
86
|
-
post: async (url, data, options2) => {
|
|
87
|
-
const signal = __privateGet(this, _currentSignal);
|
|
88
|
-
__privateSet(this, _currentSignal, void 0);
|
|
89
|
-
return await __privateGet(this, _requestClient).post(url, data, {
|
|
90
|
-
...options2,
|
|
91
|
-
signal
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
put: async (url, data, options2) => {
|
|
95
|
-
const signal = __privateGet(this, _currentSignal);
|
|
96
|
-
__privateSet(this, _currentSignal, void 0);
|
|
97
|
-
return await __privateGet(this, _requestClient).put(url, data, {
|
|
98
|
-
...options2,
|
|
99
|
-
signal
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
delete: async (url, options2) => {
|
|
103
|
-
const signal = __privateGet(this, _currentSignal);
|
|
104
|
-
__privateSet(this, _currentSignal, void 0);
|
|
105
|
-
return await __privateGet(this, _requestClient).delete(url, {
|
|
106
|
-
...options2,
|
|
107
|
-
signal
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const that = this;
|
|
112
|
-
this.useApiQuery = function useApiQuery(queryFn, args, options2) {
|
|
113
|
-
var _a;
|
|
114
|
-
const {
|
|
115
|
-
keepPreviousData,
|
|
116
|
-
placeholderData,
|
|
117
|
-
initialData,
|
|
118
|
-
...restOptions
|
|
119
|
-
} = options2 ?? {};
|
|
120
|
-
const result = reactQuery.useQuery({
|
|
121
|
-
queryKey: [queryFn.key, args],
|
|
122
|
-
queryFn: ({ signal }) => queryFn(args, { signal }),
|
|
123
|
-
select: __privateMethod(that, _ApiClient_instances, selectData_fn),
|
|
124
|
-
placeholderData: placeholderData ?? keepPreviousData === true ? reactQuery.keepPreviousData : void 0,
|
|
125
|
-
initialData: initialData ? {
|
|
126
|
-
code: 0,
|
|
127
|
-
message: "ok",
|
|
128
|
-
data: initialData
|
|
129
|
-
} : void 0,
|
|
130
|
-
...restOptions
|
|
131
|
-
});
|
|
132
|
-
return __privateMethod(_a = that, _ApiClient_instances, createQueryResult_fn).call(_a, result);
|
|
133
|
-
};
|
|
134
|
-
this.useSuspenseApiQuery = function useSuspenseApiQuery(queryFn, args, options2) {
|
|
135
|
-
const {
|
|
136
|
-
keepPreviousData,
|
|
137
|
-
initialData,
|
|
138
|
-
...restOptions
|
|
139
|
-
} = options2 ?? {};
|
|
140
|
-
const { data, refetch } = reactQuery.useSuspenseQuery({
|
|
141
|
-
queryKey: [queryFn.key, args],
|
|
142
|
-
queryFn: ({ signal }) => queryFn(args, { signal }),
|
|
143
|
-
select: __privateMethod(that, _ApiClient_instances, selectData_fn),
|
|
144
|
-
initialData: initialData ? {
|
|
145
|
-
code: 0,
|
|
146
|
-
message: "ok",
|
|
147
|
-
data: initialData
|
|
148
|
-
} : void 0,
|
|
149
|
-
...restOptions
|
|
150
|
-
});
|
|
151
|
-
return {
|
|
152
|
-
data,
|
|
153
|
-
refetch: __privateMethod(this, _ApiClient_instances, wrapRefetchFn_fn).call(this, refetch)
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
this.useApiMutation = function useApiMutation(mutationFn) {
|
|
157
|
-
const {
|
|
158
|
-
isPending,
|
|
159
|
-
isIdle,
|
|
160
|
-
isError,
|
|
161
|
-
isSuccess,
|
|
162
|
-
error,
|
|
163
|
-
data,
|
|
164
|
-
mutateAsync
|
|
165
|
-
} = reactQuery.useMutation({
|
|
166
|
-
mutationKey: [mutationFn.key],
|
|
167
|
-
mutationFn: (args) => mutationFn(args)
|
|
168
|
-
});
|
|
169
|
-
const mutate = async (args) => await mutateAsync(args);
|
|
170
|
-
return {
|
|
171
|
-
mutate,
|
|
172
|
-
isPending,
|
|
173
|
-
isIdle,
|
|
174
|
-
isError,
|
|
175
|
-
isSuccess,
|
|
176
|
-
message: data?.message,
|
|
177
|
-
error: error ?? void 0,
|
|
178
|
-
data: data?.data
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
this.useIsFetching = function useIsFetching(apiKey, args) {
|
|
182
|
-
const count = reactQuery.useIsFetching({
|
|
183
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
184
|
-
type: "active",
|
|
185
|
-
exact: false
|
|
186
|
-
});
|
|
187
|
-
return count > 0;
|
|
188
|
-
};
|
|
189
|
-
this.useIsMutating = function useIsMutating(apiKey) {
|
|
190
|
-
const count = reactQuery.useIsMutating({
|
|
191
|
-
mutationKey: [apiKey],
|
|
192
|
-
exact: false
|
|
193
|
-
});
|
|
194
|
-
return count > 0;
|
|
195
|
-
};
|
|
196
|
-
this.QueryClientProvider = function QueryClientProvider({ children }) {
|
|
197
|
-
return react.createElement(
|
|
198
|
-
reactQuery.QueryClientProvider,
|
|
199
|
-
{
|
|
200
|
-
client: __privateGet(that, _queryClient)
|
|
201
|
-
},
|
|
202
|
-
children
|
|
203
|
-
);
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Fetch the API query.
|
|
208
|
-
*
|
|
209
|
-
* @param queryFn - The API function.
|
|
210
|
-
* @param args - The arguments of the API.
|
|
211
|
-
* @param options - The options of the API.
|
|
212
|
-
* @returns The API query.
|
|
213
|
-
*/
|
|
214
|
-
async fetchApiQuery(queryFn, args, options) {
|
|
215
|
-
const { initialData, ...restOptions } = options ?? {};
|
|
216
|
-
const result = await __privateGet(this, _queryClient).fetchQuery({
|
|
217
|
-
queryKey: [queryFn.key, args],
|
|
218
|
-
queryFn: ({ signal }) => queryFn(args, { signal }),
|
|
219
|
-
initialData: initialData ? {
|
|
220
|
-
code: 0,
|
|
221
|
-
message: "ok",
|
|
222
|
-
data: initialData
|
|
223
|
-
} : void 0,
|
|
224
|
-
...restOptions
|
|
225
|
-
});
|
|
226
|
-
return result.data;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Create a query API.
|
|
230
|
-
*
|
|
231
|
-
* @param key - The key of the API.
|
|
232
|
-
* @param factory - The factory of the API function.
|
|
233
|
-
* @returns The query API.
|
|
234
|
-
*/
|
|
235
|
-
createQueryApi(key, factory) {
|
|
236
|
-
const apiFn = __privateMethod(this, _ApiClient_instances, createApi_fn).call(this, key, factory);
|
|
237
|
-
apiFn.useQuery = this.useApiQuery.bind(this, apiFn);
|
|
238
|
-
apiFn.useSuspenseQuery = this.useSuspenseApiQuery.bind(this, apiFn);
|
|
239
|
-
apiFn.fetchQuery = this.fetchApiQuery.bind(this, apiFn);
|
|
240
|
-
apiFn.getQueryData = this.getApiQueryData.bind(this, key);
|
|
241
|
-
apiFn.getQueriesData = this.getApiQueriesData.bind(this, key);
|
|
242
|
-
apiFn.setQueryData = (data, args) => this.setApiQueryData(data, key, args);
|
|
243
|
-
apiFn.ensureQueryData = this.ensureApiQueryData.bind(this, apiFn);
|
|
244
|
-
apiFn.removeQueries = this.removeApiQueries.bind(this, key);
|
|
245
|
-
apiFn.invalidateQueries = this.invalidateApiQueries.bind(this, key);
|
|
246
|
-
apiFn.resetQueries = this.resetApiQueries.bind(this, key);
|
|
247
|
-
apiFn.refetchQueries = this.refetchApiQueries.bind(this, key);
|
|
248
|
-
apiFn.cancelQueries = this.cancelApiQueries.bind(this, key);
|
|
249
|
-
apiFn.isFetching = this.isFetching.bind(this, key);
|
|
250
|
-
apiFn.useIsFetching = this.useIsFetching.bind(void 0, key);
|
|
251
|
-
return Object.freeze(apiFn);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Create a mutation API.
|
|
255
|
-
*
|
|
256
|
-
* @param key - The key of the API.
|
|
257
|
-
* @param factory - The factory of the API function.
|
|
258
|
-
* @param relatedQueries - The related queries.
|
|
259
|
-
* @returns The mutation API.
|
|
260
|
-
*/
|
|
261
|
-
createMutationApi(key, factory, relatedQueries = []) {
|
|
262
|
-
const apiFn = __privateMethod(this, _ApiClient_instances, createApi_fn).call(this, key, factory);
|
|
263
|
-
apiFn.relatedQueries = Object.freeze(relatedQueries);
|
|
264
|
-
apiFn.useMutation = this.useApiMutation.bind(this, apiFn);
|
|
265
|
-
apiFn.refetchRelatedQueries = function refetchRelatedQueries() {
|
|
266
|
-
return Promise.all(
|
|
267
|
-
relatedQueries.map((query) => query.refetchQueries())
|
|
268
|
-
);
|
|
269
|
-
};
|
|
270
|
-
apiFn.invalidateRelatedQueries = function invalidateRelatedQueries() {
|
|
271
|
-
return Promise.all(
|
|
272
|
-
relatedQueries.map((query) => query.invalidateQueries())
|
|
273
|
-
);
|
|
274
|
-
};
|
|
275
|
-
apiFn.isMutating = this.isMutating.bind(this, key);
|
|
276
|
-
apiFn.useIsMutating = this.useIsMutating.bind(void 0, key);
|
|
277
|
-
return Object.freeze(apiFn);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Get the API query data.
|
|
281
|
-
*
|
|
282
|
-
* @param apiKey - The key of the API.
|
|
283
|
-
* @param args - The arguments of the API.
|
|
284
|
-
* @returns The API query data.
|
|
285
|
-
*/
|
|
286
|
-
getApiQueryData(apiKey, args) {
|
|
287
|
-
return __privateGet(this, _queryClient).getQueryData(
|
|
288
|
-
arguments.length > 1 ? [apiKey, args] : [apiKey]
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get the API queries data.
|
|
293
|
-
*
|
|
294
|
-
* @param apiKey - The key of the API.
|
|
295
|
-
* @param args - The arguments of the API.
|
|
296
|
-
* @returns The API queries data.
|
|
297
|
-
*/
|
|
298
|
-
getApiQueriesData(apiKey, args) {
|
|
299
|
-
return __privateGet(this, _queryClient).getQueriesData({
|
|
300
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
301
|
-
type: "active",
|
|
302
|
-
exact: false
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Set the API query data.
|
|
307
|
-
*
|
|
308
|
-
* @param data - The data.
|
|
309
|
-
* @param apiKey - The key of the API.
|
|
310
|
-
* @param args - The arguments of the API.
|
|
311
|
-
*/
|
|
312
|
-
setApiQueryData(data, apiKey, args) {
|
|
313
|
-
__privateGet(this, _queryClient).setQueryData(
|
|
314
|
-
arguments.length > 2 ? [apiKey, args] : [apiKey],
|
|
315
|
-
data
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Ensure the API query data.
|
|
320
|
-
*
|
|
321
|
-
* @param queryFn - The API function.
|
|
322
|
-
* @param args - The arguments of the API.
|
|
323
|
-
* @param options - The options of the API.
|
|
324
|
-
* @returns The API query data.
|
|
325
|
-
*/
|
|
326
|
-
async ensureApiQueryData(queryFn, args, options) {
|
|
327
|
-
const { initialData, ...restOptions } = options ?? {};
|
|
328
|
-
const result = await __privateGet(this, _queryClient).ensureQueryData({
|
|
329
|
-
queryKey: [queryFn.key, args],
|
|
330
|
-
queryFn: ({ signal }) => queryFn(args, { signal }),
|
|
331
|
-
initialData: initialData ? {
|
|
332
|
-
code: 0,
|
|
333
|
-
message: "ok",
|
|
334
|
-
data: initialData
|
|
335
|
-
} : void 0,
|
|
336
|
-
...restOptions,
|
|
337
|
-
revalidateIfStale: true
|
|
338
|
-
});
|
|
339
|
-
return result.data;
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Remove the API queries.
|
|
343
|
-
*
|
|
344
|
-
* @param apiKey - The key of the API.
|
|
345
|
-
* @param args - The arguments of the API.
|
|
346
|
-
*/
|
|
347
|
-
removeApiQueries(apiKey, args) {
|
|
348
|
-
__privateGet(this, _queryClient).removeQueries({
|
|
349
|
-
type: "all",
|
|
350
|
-
exact: false,
|
|
351
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey]
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Invalidate the API queries.
|
|
356
|
-
*
|
|
357
|
-
* @param apiKey - The key of the API.
|
|
358
|
-
* @param args - The arguments of the API.
|
|
359
|
-
*/
|
|
360
|
-
invalidateApiQueries(apiKey, args) {
|
|
361
|
-
return __privateGet(this, _queryClient).invalidateQueries(
|
|
362
|
-
{
|
|
363
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
364
|
-
type: "all",
|
|
365
|
-
exact: false,
|
|
366
|
-
stale: false,
|
|
367
|
-
refetchType: "active"
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
throwOnError: false,
|
|
371
|
-
cancelRefetch: false
|
|
372
|
-
}
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Reset the API queries.
|
|
377
|
-
*
|
|
378
|
-
* @param apiKey - The key of the API.
|
|
379
|
-
* @param args - The arguments of the API.
|
|
380
|
-
*/
|
|
381
|
-
resetApiQueries(apiKey, args) {
|
|
382
|
-
return __privateGet(this, _queryClient).resetQueries(
|
|
383
|
-
{
|
|
384
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
385
|
-
type: "active",
|
|
386
|
-
exact: false
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
cancelRefetch: true,
|
|
390
|
-
throwOnError: false
|
|
391
|
-
}
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Refetch the API queries.
|
|
396
|
-
*
|
|
397
|
-
* @param apiKey - The key of the API.
|
|
398
|
-
* @param args - The arguments of the API.
|
|
399
|
-
*/
|
|
400
|
-
refetchApiQueries(apiKey, args) {
|
|
401
|
-
return __privateGet(this, _queryClient).refetchQueries(
|
|
402
|
-
{
|
|
403
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
404
|
-
type: "active",
|
|
405
|
-
exact: false
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
throwOnError: false,
|
|
409
|
-
cancelRefetch: false
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Cancel the API queries.
|
|
415
|
-
*
|
|
416
|
-
* @param apiKey - The key of the API.
|
|
417
|
-
* @param args - The arguments of the API.
|
|
418
|
-
*/
|
|
419
|
-
cancelApiQueries(apiKey, args) {
|
|
420
|
-
return __privateGet(this, _queryClient).cancelQueries(
|
|
421
|
-
{
|
|
422
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
423
|
-
type: "active",
|
|
424
|
-
exact: false
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
revert: true,
|
|
428
|
-
silent: true
|
|
429
|
-
}
|
|
430
|
-
);
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Check if the API query/queries is fetching.
|
|
434
|
-
*
|
|
435
|
-
* @param apiKey - The key of the API.
|
|
436
|
-
* @param args - The arguments of the API.
|
|
437
|
-
* @returns Whether the API query is fetching.
|
|
438
|
-
*/
|
|
439
|
-
isFetching(apiKey, args) {
|
|
440
|
-
return __privateGet(this, _queryClient).isFetching({
|
|
441
|
-
queryKey: arguments.length > 1 ? [apiKey, args] : [apiKey],
|
|
442
|
-
type: "active",
|
|
443
|
-
exact: false
|
|
444
|
-
}) > 0;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Check if the API mutation is mutating.
|
|
448
|
-
*
|
|
449
|
-
* @param apiKey - The key of the API.
|
|
450
|
-
* @returns Whether the API mutation is mutating.
|
|
451
|
-
*/
|
|
452
|
-
isMutating(apiKey) {
|
|
453
|
-
return __privateGet(this, _queryClient).isMutating({
|
|
454
|
-
mutationKey: [apiKey],
|
|
455
|
-
exact: false
|
|
456
|
-
}) > 0;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
_queryClient = new WeakMap();
|
|
460
|
-
_requestClient = new WeakMap();
|
|
461
|
-
_requestMethods = new WeakMap();
|
|
462
|
-
_currentSignal = new WeakMap();
|
|
463
|
-
_ApiClient_instances = new WeakSet();
|
|
464
|
-
/**
|
|
465
|
-
* Select the data.
|
|
466
|
-
*
|
|
467
|
-
* @param data - The data.
|
|
468
|
-
* @returns The data.
|
|
469
|
-
*/
|
|
470
|
-
selectData_fn = function(data) {
|
|
471
|
-
return data.data;
|
|
472
|
-
};
|
|
473
|
-
/**
|
|
474
|
-
* Wrap the refetch function.
|
|
475
|
-
*
|
|
476
|
-
* @param refetch - The refetch function.
|
|
477
|
-
* @returns The refetch result.
|
|
478
|
-
*/
|
|
479
|
-
wrapRefetchFn_fn = function(refetch) {
|
|
480
|
-
return async (options) => {
|
|
481
|
-
const result = await refetch(options);
|
|
482
|
-
return {
|
|
483
|
-
isSuccess: result.isSuccess,
|
|
484
|
-
isError: result.isError,
|
|
485
|
-
error: result.error,
|
|
486
|
-
data: result.data
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
};
|
|
490
|
-
/**
|
|
491
|
-
* Create a query result.
|
|
492
|
-
*
|
|
493
|
-
* @returns The query result.
|
|
494
|
-
*/
|
|
495
|
-
createQueryResult_fn = function({
|
|
496
|
-
isPending,
|
|
497
|
-
isFetching,
|
|
498
|
-
isLoading,
|
|
499
|
-
isRefetching,
|
|
500
|
-
isSuccess,
|
|
501
|
-
isPlaceholderData,
|
|
502
|
-
isError,
|
|
503
|
-
isLoadingError,
|
|
504
|
-
isRefetchError,
|
|
505
|
-
isStale,
|
|
506
|
-
error,
|
|
507
|
-
data,
|
|
508
|
-
refetch
|
|
509
|
-
}) {
|
|
510
|
-
return {
|
|
511
|
-
isPending,
|
|
512
|
-
isSuccess,
|
|
513
|
-
isError,
|
|
514
|
-
isLoadingError,
|
|
515
|
-
isRefetchError,
|
|
516
|
-
isLoading,
|
|
517
|
-
isFetching,
|
|
518
|
-
isRefetching,
|
|
519
|
-
isPlaceholderData,
|
|
520
|
-
isStale,
|
|
521
|
-
error: error ?? void 0,
|
|
522
|
-
data,
|
|
523
|
-
refetch: __privateMethod(this, _ApiClient_instances, wrapRefetchFn_fn).call(this, refetch)
|
|
524
|
-
};
|
|
525
|
-
};
|
|
526
|
-
/**
|
|
527
|
-
* Create an API.
|
|
528
|
-
*
|
|
529
|
-
* @param key - The key of the API.
|
|
530
|
-
* @param factory - The factory of the API function.
|
|
531
|
-
* @returns The API.
|
|
532
|
-
*/
|
|
533
|
-
createApi_fn = function(key, factory) {
|
|
534
|
-
const fn = factory(__privateGet(this, _requestMethods));
|
|
535
|
-
const apiFn = async (args, apiOptions) => {
|
|
536
|
-
__privateSet(this, _currentSignal, apiOptions?.signal);
|
|
537
|
-
return await fn(args);
|
|
538
|
-
};
|
|
539
|
-
apiFn.key = key;
|
|
540
|
-
return apiFn;
|
|
541
|
-
};
|
|
542
|
-
function createApiClient(options) {
|
|
543
|
-
return Object.freeze(new ApiClient(options));
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
exports.ApiClient = ApiClient;
|
|
547
|
-
exports.createApiClient = createApiClient;
|
|
2
|
+
"use strict";var v=require("@tanstack/react-query"),K=require("react"),C=require("./query-client.cjs"),I=require("./request-client.cjs"),R=Object.defineProperty,P=a=>{throw TypeError(a)},x=(a,e,i)=>e in a?R(a,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[e]=i,A=(a,e,i)=>x(a,typeof e!="symbol"?e+"":e,i),w=(a,e,i)=>e.has(a)||P("Cannot "+i),n=(a,e,i)=>(w(a,e,"read from private field"),i?i.call(a):e.get(a)),D=(a,e,i)=>e.has(a)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(a):e.set(a,i),g=(a,e,i,t)=>(w(a,e,"write to private field"),t?t.call(a,i):e.set(a,i),i),f=(a,e,i)=>(w(a,e,"access private method"),i),u,m,b,h,y,k,M,S,F;class E{constructor(e){this.options=e,D(this,y),A(this,"useApiQuery"),A(this,"useSuspenseApiQuery"),A(this,"useApiMutation"),A(this,"useIsFetching"),A(this,"useIsMutating"),A(this,"QueryClientProvider"),D(this,u),D(this,m),D(this,b),D(this,h),g(this,u,C.createQueryClient(e)),g(this,m,I.createRequestClient(e)),g(this,b,{get:async(t,s)=>{const r=n(this,h);return g(this,h,void 0),await n(this,m).get(t,{...s,signal:r})},post:async(t,s,r)=>{const c=n(this,h);return g(this,h,void 0),await n(this,m).post(t,s,{...r,signal:c})},put:async(t,s,r)=>{const c=n(this,h);return g(this,h,void 0),await n(this,m).put(t,s,{...r,signal:c})},delete:async(t,s)=>{const r=n(this,h);return g(this,h,void 0),await n(this,m).delete(t,{...s,signal:r})}});const i=this;this.useApiQuery=function(t,s,r){var c;const{keepPreviousData:d,placeholderData:p,initialData:o,...Q}=r??{},l=v.useQuery({queryKey:[t.key,s],queryFn:({signal:q})=>t(s,{signal:q}),select:f(i,y,k),placeholderData:p??d===!0?v.keepPreviousData:void 0,initialData:o?{code:0,message:"ok",data:o}:void 0,...Q});return f(c=i,y,S).call(c,l)},this.useSuspenseApiQuery=function(t,s,r){const{keepPreviousData:c,initialData:d,...p}=r??{},{data:o,refetch:Q}=v.useSuspenseQuery({queryKey:[t.key,s],queryFn:({signal:l})=>t(s,{signal:l}),select:f(i,y,k),initialData:d?{code:0,message:"ok",data:d}:void 0,...p});return{data:o,refetch:f(this,y,M).call(this,Q)}},this.useApiMutation=function(t){const{isPending:s,isIdle:r,isError:c,isSuccess:d,error:p,data:o,mutateAsync:Q}=v.useMutation({mutationKey:[t.key],mutationFn:l=>t(l)});return{mutate:async l=>await Q(l),isPending:s,isIdle:r,isError:c,isSuccess:d,message:o?.message,error:p??void 0,data:o?.data}},this.useIsFetching=function(t,s){return v.useIsFetching({queryKey:arguments.length>1?[t,s]:[t],type:"active",exact:!1})>0},this.useIsMutating=function(t){return v.useIsMutating({mutationKey:[t],exact:!1})>0},this.QueryClientProvider=function({children:t}){return K.createElement(v.QueryClientProvider,{client:n(i,u)},t)}}async fetchApiQuery(e,i,t){const{initialData:s,...r}=t??{};return(await n(this,u).fetchQuery({queryKey:[e.key,i],queryFn:({signal:c})=>e(i,{signal:c}),initialData:s?{code:0,message:"ok",data:s}:void 0,...r})).data}createQueryApi(e,i){const t=f(this,y,F).call(this,e,i);return t.useQuery=this.useApiQuery.bind(this,t),t.useSuspenseQuery=this.useSuspenseApiQuery.bind(this,t),t.fetchQuery=this.fetchApiQuery.bind(this,t),t.getQueryData=this.getApiQueryData.bind(this,e),t.getQueriesData=this.getApiQueriesData.bind(this,e),t.setQueryData=(s,r)=>this.setApiQueryData(s,e,r),t.ensureQueryData=this.ensureApiQueryData.bind(this,t),t.removeQueries=this.removeApiQueries.bind(this,e),t.invalidateQueries=this.invalidateApiQueries.bind(this,e),t.resetQueries=this.resetApiQueries.bind(this,e),t.refetchQueries=this.refetchApiQueries.bind(this,e),t.cancelQueries=this.cancelApiQueries.bind(this,e),t.isFetching=this.isFetching.bind(this,e),t.useIsFetching=this.useIsFetching.bind(void 0,e),Object.freeze(t)}createMutationApi(e,i,t=[]){const s=f(this,y,F).call(this,e,i);return s.relatedQueries=Object.freeze(t),s.useMutation=this.useApiMutation.bind(this,s),s.refetchRelatedQueries=function(){return Promise.all(t.map(r=>r.refetchQueries()))},s.invalidateRelatedQueries=function(){return Promise.all(t.map(r=>r.invalidateQueries()))},s.isMutating=this.isMutating.bind(this,e),s.useIsMutating=this.useIsMutating.bind(void 0,e),Object.freeze(s)}getApiQueryData(e,i){return n(this,u).getQueryData(arguments.length>1?[e,i]:[e])}getApiQueriesData(e,i){return n(this,u).getQueriesData({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1})}setApiQueryData(e,i,t){n(this,u).setQueryData(arguments.length>2?[i,t]:[i],e)}async ensureApiQueryData(e,i,t){const{initialData:s,...r}=t??{};return(await n(this,u).ensureQueryData({queryKey:[e.key,i],queryFn:({signal:c})=>e(i,{signal:c}),initialData:s?{code:0,message:"ok",data:s}:void 0,...r,revalidateIfStale:!0})).data}removeApiQueries(e,i){n(this,u).removeQueries({type:"all",exact:!1,queryKey:arguments.length>1?[e,i]:[e]})}invalidateApiQueries(e,i){return n(this,u).invalidateQueries({queryKey:arguments.length>1?[e,i]:[e],type:"all",exact:!1,stale:!1,refetchType:"active"},{throwOnError:!1,cancelRefetch:!1})}resetApiQueries(e,i){return n(this,u).resetQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{cancelRefetch:!0,throwOnError:!1})}refetchApiQueries(e,i){return n(this,u).refetchQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{throwOnError:!1,cancelRefetch:!1})}cancelApiQueries(e,i){return n(this,u).cancelQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{revert:!0,silent:!0})}isFetching(e,i){return n(this,u).isFetching({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1})>0}isMutating(e){return n(this,u).isMutating({mutationKey:[e],exact:!1})>0}}u=new WeakMap,m=new WeakMap,b=new WeakMap,h=new WeakMap,y=new WeakSet,k=function(a){return a.data},M=function(a){return async e=>{const i=await a(e);return{isSuccess:i.isSuccess,isError:i.isError,error:i.error,data:i.data}}},S=function({isPending:a,isFetching:e,isLoading:i,isRefetching:t,isSuccess:s,isPlaceholderData:r,isError:c,isLoadingError:d,isRefetchError:p,isStale:o,error:Q,data:l,refetch:q}){return{isPending:a,isSuccess:s,isError:c,isLoadingError:d,isRefetchError:p,isLoading:i,isFetching:e,isRefetching:t,isPlaceholderData:r,isStale:o,error:Q??void 0,data:l,refetch:f(this,y,M).call(this,q)}},F=function(a,e){const i=e(n(this,b)),t=async(s,r)=>(g(this,h,r?.signal),await i(s));return t.key=a,t};function O(a){return Object.freeze(new E(a))}exports.ApiClient=E,exports.createApiClient=O;
|
package/cjs/api/api-context.cjs
CHANGED
|
@@ -1,98 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
const Context = react.createContext(null);
|
|
9
|
-
const ApiContextProvider = ({
|
|
10
|
-
client,
|
|
11
|
-
dataDictionaryApi,
|
|
12
|
-
loginApi,
|
|
13
|
-
logoutApi,
|
|
14
|
-
fetchAuthenticatedUserApi,
|
|
15
|
-
children
|
|
16
|
-
}) => {
|
|
17
|
-
const apiContext = react.useMemo(() => {
|
|
18
|
-
const stubQueryApi = client.createQueryApi(
|
|
19
|
-
"_vefStubQueryApi",
|
|
20
|
-
() => (stubData) => Promise.resolve({
|
|
21
|
-
code: 0,
|
|
22
|
-
message: "ok",
|
|
23
|
-
data: stubData
|
|
24
|
-
})
|
|
25
|
-
);
|
|
26
|
-
const asyncFnQueryApi = client.createQueryApi(
|
|
27
|
-
"_vefAsyncFnQueryApi",
|
|
28
|
-
() => async ({ args, fn }) => ({
|
|
29
|
-
code: 0,
|
|
30
|
-
message: "ok",
|
|
31
|
-
data: await fn(...args)
|
|
32
|
-
})
|
|
33
|
-
);
|
|
34
|
-
const stubMutationApi = client.createMutationApi(
|
|
35
|
-
"_vefStubMutationApi",
|
|
36
|
-
() => (stubData) => Promise.resolve({
|
|
37
|
-
code: 0,
|
|
38
|
-
message: "ok",
|
|
39
|
-
data: stubData
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
const asyncFnMutationApi = client.createMutationApi(
|
|
43
|
-
"_vefAsyncFnMutationApi",
|
|
44
|
-
() => async ({ args, fn }) => ({
|
|
45
|
-
code: 0,
|
|
46
|
-
message: "ok",
|
|
47
|
-
data: await fn(...args)
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
return Object.freeze({
|
|
51
|
-
useApiQuery: client.useApiQuery,
|
|
52
|
-
useSuspenseApiQuery: client.useSuspenseApiQuery,
|
|
53
|
-
useApiMutation: client.useApiMutation,
|
|
54
|
-
useIsFetching: client.useIsFetching,
|
|
55
|
-
useIsMutating: client.useIsMutating,
|
|
56
|
-
fetchApiQuery: client.fetchApiQuery.bind(client),
|
|
57
|
-
createQueryApi: client.createQueryApi.bind(client),
|
|
58
|
-
createMutationApi: client.createMutationApi.bind(client),
|
|
59
|
-
getApiQueryData: client.getApiQueryData.bind(client),
|
|
60
|
-
getApiQueriesData: client.getApiQueriesData.bind(client),
|
|
61
|
-
setApiQueryData: client.setApiQueryData.bind(client),
|
|
62
|
-
ensureApiQueryData: client.ensureApiQueryData.bind(client),
|
|
63
|
-
removeApiQueries: client.removeApiQueries.bind(client),
|
|
64
|
-
invalidateApiQueries: client.invalidateApiQueries.bind(client),
|
|
65
|
-
resetApiQueries: client.resetApiQueries.bind(client),
|
|
66
|
-
refetchApiQueries: client.refetchApiQueries.bind(client),
|
|
67
|
-
cancelApiQueries: client.cancelApiQueries.bind(client),
|
|
68
|
-
isFetching: client.isFetching.bind(client),
|
|
69
|
-
isMutating: client.isMutating.bind(client),
|
|
70
|
-
stubQueryApi,
|
|
71
|
-
asyncFnQueryApi,
|
|
72
|
-
stubMutationApi,
|
|
73
|
-
asyncFnMutationApi,
|
|
74
|
-
dataDictionaryApi,
|
|
75
|
-
loginApi,
|
|
76
|
-
logoutApi,
|
|
77
|
-
fetchAuthenticatedUserApi
|
|
78
|
-
});
|
|
79
|
-
}, [client, dataDictionaryApi, loginApi, logoutApi, fetchAuthenticatedUserApi]);
|
|
80
|
-
return react.createElement(
|
|
81
|
-
Context.Provider,
|
|
82
|
-
{ value: apiContext },
|
|
83
|
-
react.createElement(client.QueryClientProvider, {}, children)
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
function useApiContext() {
|
|
87
|
-
const context = react.useContext(Context);
|
|
88
|
-
if (context === null) {
|
|
89
|
-
throw new shared.VefError(
|
|
90
|
-
-1,
|
|
91
|
-
"Api context not found: Please ensure useApiContext is called within an ApiContextProvider"
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return context;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.ApiContextProvider = ApiContextProvider;
|
|
98
|
-
exports.useApiContext = useApiContext;
|
|
2
|
+
"use strict";var l=require("@vef-framework/shared"),t=require("react");const A=t.createContext(null),g=({client:e,dataDictionaryApi:n,loginApi:u,logoutApi:a,fetchAuthenticatedUserApi:s,children:p})=>{const o=t.useMemo(()=>{const c=e.createQueryApi("_vefStubQueryApi",()=>i=>Promise.resolve({code:0,message:"ok",data:i})),d=e.createQueryApi("_vefAsyncFnQueryApi",()=>async({args:i,fn:r})=>({code:0,message:"ok",data:await r(...i)})),Q=e.createMutationApi("_vefStubMutationApi",()=>i=>Promise.resolve({code:0,message:"ok",data:i})),y=e.createMutationApi("_vefAsyncFnMutationApi",()=>async({args:i,fn:r})=>({code:0,message:"ok",data:await r(...i)}));return Object.freeze({useApiQuery:e.useApiQuery,useSuspenseApiQuery:e.useSuspenseApiQuery,useApiMutation:e.useApiMutation,useIsFetching:e.useIsFetching,useIsMutating:e.useIsMutating,fetchApiQuery:e.fetchApiQuery.bind(e),createQueryApi:e.createQueryApi.bind(e),createMutationApi:e.createMutationApi.bind(e),getApiQueryData:e.getApiQueryData.bind(e),getApiQueriesData:e.getApiQueriesData.bind(e),setApiQueryData:e.setApiQueryData.bind(e),ensureApiQueryData:e.ensureApiQueryData.bind(e),removeApiQueries:e.removeApiQueries.bind(e),invalidateApiQueries:e.invalidateApiQueries.bind(e),resetApiQueries:e.resetApiQueries.bind(e),refetchApiQueries:e.refetchApiQueries.bind(e),cancelApiQueries:e.cancelApiQueries.bind(e),isFetching:e.isFetching.bind(e),isMutating:e.isMutating.bind(e),stubQueryApi:c,asyncFnQueryApi:d,stubMutationApi:Q,asyncFnMutationApi:y,dataDictionaryApi:n,loginApi:u,logoutApi:a,fetchAuthenticatedUserApi:s})},[e,n,u,a,s]);return t.createElement(A.Provider,{value:o},t.createElement(e.QueryClientProvider,{},p))};function b(){const e=t.useContext(A);if(e===null)throw new l.VefError(-1,"Api context not found: Please ensure useApiContext is called within an ApiContextProvider");return e}exports.ApiContextProvider=g,exports.useApiContext=b;
|
package/cjs/api/index.cjs
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var apiClient = require('./api-client.cjs');
|
|
5
|
-
var apiContext = require('./api-context.cjs');
|
|
6
|
-
var reactQuery = require('@tanstack/react-query');
|
|
7
|
-
|
|
8
|
-
"use strict";
|
|
9
|
-
|
|
10
|
-
exports.ApiClient = apiClient.ApiClient;
|
|
11
|
-
exports.createApiClient = apiClient.createApiClient;
|
|
12
|
-
exports.ApiContextProvider = apiContext.ApiContextProvider;
|
|
13
|
-
exports.useApiContext = apiContext.useApiContext;
|
|
14
|
-
Object.defineProperty(exports, "useQueryErrorResetBoundary", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return reactQuery.useQueryErrorResetBoundary; }
|
|
17
|
-
});
|
|
2
|
+
"use strict";var e=require("./api-client.cjs"),r=require("./api-context.cjs"),t=require("@tanstack/react-query");exports.ApiClient=e.ApiClient,exports.createApiClient=e.createApiClient,exports.ApiContextProvider=r.ApiContextProvider,exports.useApiContext=r.useApiContext,Object.defineProperty(exports,"useQueryErrorResetBoundary",{enumerable:!0,get:function(){return t.useQueryErrorResetBoundary}});
|