@vef-framework/core 1.0.97 → 1.0.99

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