@vef-framework/core 1.0.122 → 1.0.124

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