"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),b=new WeakMap,q=(...e)=>{var r;const o=e[0],t=(r=l.getCurrentInstance())==null?void 0:r.proxy;if(t==null)throw new Error("injectLocal must be called in setup");return b.has(t)&&o in b.get(t)?b.get(t)[o]:l.inject(...e)};function w(e){return typeof e=="function"?e():l.unref(e)}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const F=()=>{};function _(e,r=!1,o="Timeout"){return new Promise((t,s)=>{setTimeout(r?()=>s(o):t,e)})}function x(e,r=!1){function o(n,{flush:u="sync",deep:c=!1,timeout:d,throwOnTimeout:T}={}){let m=null;const v=[new Promise(p=>{m=l.watch(e,h=>{n(h)!==r&&(m==null||m(),p(h))},{flush:u,deep:c,immediate:!0})})];return d!=null&&v.push(_(d,T).then(()=>w(e)).finally(()=>m==null?void 0:m())),Promise.race(v)}function t(n,u){if(!l.isRef(n))return o(h=>h===n,u);const{flush:c="sync",deep:d=!1,timeout:T,throwOnTimeout:m}=u??{};let f=null;const p=[new Promise(h=>{f=l.watch([e,n],([a,g])=>{r!==(a===g)&&(f==null||f(),h(a))},{flush:c,deep:d,immediate:!0})})];return T!=null&&p.push(_(T,m).then(()=>w(e)).finally(()=>(f==null||f(),w(e)))),Promise.race(p)}function s(n){return o(u=>!!u,n)}function i(n){return t(null,n)}function D(n){return t(void 0,n)}function C(n){return o(Number.isNaN,n)}function S(n,u){return o(c=>{const d=Array.from(c);return d.includes(n)||d.includes(w(n))},u)}function P(n){return y(1,n)}function y(n=1,u){let c=-1;return o(()=>(c+=1,c>=n),u)}return Array.isArray(w(e))?{toMatch:o,toContains:S,changed:P,changedTimes:y,get not(){return x(e,!r)}}:{toMatch:o,toBe:t,toBeTruthy:s,toBeNull:i,toBeNaN:C,toBeUndefined:D,changed:P,changedTimes:y,get not(){return x(e,!r)}}}function B(e){return x(e)}const N=Symbol("RESOURCE_CONTEXT"),U=()=>q(N,{name:""}),M={create:()=>Promise.resolve({data:null}),deleteOne:()=>Promise.resolve({data:null}),getList:()=>Promise.resolve({data:Array.from({length:30}).map((e,r)=>({name:r,id:r})),total:20}),getMany:()=>Promise.resolve({data:[]}),getManyReference:()=>Promise.resolve({data:[],total:0}),getOne:()=>Promise.resolve({data:null}),update:()=>Promise.resolve({data:null})},j=Symbol("DATA_PROVIDER_CONTEXT"),E=()=>q(j,M);function R(e){const{initialData:r,shallow:o,onSuccess:t=F,onError:s=F,immediate:i,resetOnExecute:D=!1,queryFn:C,queryKey:S}=e,P=(o?l.shallowRef:l.ref)(r),y=l.ref(!1),n=l.ref(!1),u=l.ref(!1),c=l.shallowRef(),d=a=>{n.value=a,y.value=!a},T=()=>{D&&(P.value=r)},m=()=>new Promise((a,g)=>{B(y).toBe(!0).then(()=>c.value?g(c.value):a(h))}),f={then:(...a)=>m().then(...a),catch:(...a)=>m().catch(...a)};let v=0;const p=a=>{if(c.value=void 0,n.value)return f;if(C===void 0)return y.value=!0,f;T(),d(!0),v+=1;const g=v;return C(a).then(O=>{const A=O;P.value=A,t(A)}).catch(O=>{c.value=O,s(O)}).finally(()=>{var O;(O=e.onFinish)==null||O.call(e),g===v&&d(!1)}),f};i&&p();const h={data:P,error:c,isFinished:y,isLoading:n,isAborted:u,isCanceled:u,execute:p};return{...h,...f}}const k=(e,r=!1)=>{const{create:o}=E(),t=R({immediate:r,queryFn:i=>o(e,i)}),s=t.execute;return{...t,sendCreate:s}},L=(e,r=!1)=>{const{deleteOne:o}=E(),t=R({immediate:r,queryFn:i=>o(e,i)}),s=t.execute;return{...t,sendDelete:s}},X=(e,r=!1)=>{const{getOne:o}=E(),t=R({immediate:r,queryFn:i=>o(e,i)}),s=t.execute;return{...t,getOneData:s}},G=(e,r=!1)=>{const{update:o}=E(),t=R({immediate:r,queryFn:i=>o(e,i)}),s=t.execute;return{...t,sendUpdate:s}},I=()=>{const{name:e}=U(),r=G(e),o=L(e),t=k(e),s=X(e);return{update:r,deleteOne:o,create:t,getOne:s}};exports.useCurd=I;
//# sourceMappingURL=useCurd.js.map
