@vef-framework/core 1.0.62 → 1.0.64

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