frappe-react-sdk 1.0.20 → 1.0.22
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.
|
@@ -2846,7 +2846,7 @@ const xo = Tr.exports.jsx, re = Zn(null), Lo = ({
|
|
|
2846
2846
|
db: a
|
|
2847
2847
|
} = ne(re);
|
|
2848
2848
|
return {
|
|
2849
|
-
...Ze(
|
|
2849
|
+
...Ze(t === void 0 ? a.getRequestURL(e, r) : t, () => a.getDoc(e, r), o)
|
|
2850
2850
|
};
|
|
2851
2851
|
}, Fo = (e) => {
|
|
2852
2852
|
var t, o, a;
|
|
@@ -2861,7 +2861,7 @@ const xo = Tr.exports.jsx, re = Zn(null), Lo = ({
|
|
|
2861
2861
|
db: a
|
|
2862
2862
|
} = ne(re);
|
|
2863
2863
|
return {
|
|
2864
|
-
...Ze(
|
|
2864
|
+
...Ze(t === void 0 ? `${a.getRequestURL(e)}?${Fo(r)}` : t, () => a.getDocList(e, r), o)
|
|
2865
2865
|
};
|
|
2866
2866
|
}, No = () => {
|
|
2867
2867
|
const {
|
|
@@ -2921,22 +2921,26 @@ const $o = (e, r, t = !1, o = !1, a, n) => {
|
|
|
2921
2921
|
db: c
|
|
2922
2922
|
} = ne(re);
|
|
2923
2923
|
return {
|
|
2924
|
-
...Ze(
|
|
2925
|
-
const f = Cr({
|
|
2924
|
+
...Ze(a === void 0 ? (() => {
|
|
2925
|
+
const f = Cr(t ? {
|
|
2926
2926
|
doctype: e,
|
|
2927
2927
|
filters: r != null ? r : [],
|
|
2928
2928
|
cache: t,
|
|
2929
2929
|
debug: o
|
|
2930
|
+
} : {
|
|
2931
|
+
doctype: e,
|
|
2932
|
+
filters: r != null ? r : [],
|
|
2933
|
+
debug: o
|
|
2930
2934
|
});
|
|
2931
2935
|
return `${i}/api/method/frappe.client.get_count?${f}`;
|
|
2932
|
-
})() :
|
|
2936
|
+
})() : a, () => c.getCount(e, r, t, o), n)
|
|
2933
2937
|
};
|
|
2934
2938
|
}, Do = (e, r, t, o) => {
|
|
2935
2939
|
const {
|
|
2936
2940
|
call: a
|
|
2937
2941
|
} = ne(re), n = Cr(r != null ? r : {}), i = `${e}?${n}`;
|
|
2938
2942
|
return {
|
|
2939
|
-
...Ze(t
|
|
2943
|
+
...Ze(t === void 0 ? i : t, () => a.get(e, r), o)
|
|
2940
2944
|
};
|
|
2941
2945
|
}, Vo = (e) => {
|
|
2942
2946
|
const {
|
|
@@ -41,4 +41,4 @@ Check the render method of \``+u+"`."}return""}}function Fo(u){{if(u!==void 0){v
|
|
|
41
41
|
|
|
42
42
|
Check your code at `+p+":"+m+"."}return""}}var yr={};function Do(u){{var p=_r();if(!p){var m=typeof u=="string"?u:u.displayName||u.name;m&&(p=`
|
|
43
43
|
|
|
44
|
-
Check the top-level render call using <`+m+">.")}return p}}function br(u,p){{if(!u._store||u._store.validated||u.key!=null)return;u._store.validated=!0;var m=Do(p);if(yr[m])return;yr[m]=!0;var E="";u&&u._owner&&u._owner!==nn.current&&(E=" It was passed a child from "+W(u._owner.type)+"."),ke(u),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',m,E),ke(null)}}function Sr(u,p){{if(typeof u!="object")return;if(ge(u))for(var m=0;m<u.length;m++){var E=u[m];an(E)&&br(E,p)}else if(an(u))u._store&&(u._store.validated=!0);else if(u){var O=T(u);if(typeof O=="function"&&O!==u.entries)for(var D=O.call(u),C;!(C=D.next()).done;)an(C.value)&&br(C.value,p)}}}function ko(u){{var p=u.type;if(p==null||typeof p=="string")return;var m;if(typeof p=="function")m=p.propTypes;else if(typeof p=="object"&&(p.$$typeof===d||p.$$typeof===l))m=p.propTypes;else return;if(m){var E=W(p);te(m,u.props,"prop",E,u)}else if(p.PropTypes!==void 0&&!rn){rn=!0;var O=W(p);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",O||"Unknown")}typeof p.getDefaultProps=="function"&&!p.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ao(u){{for(var p=Object.keys(u.props),m=0;m<p.length;m++){var E=p[m];if(E!=="children"&&E!=="key"){ke(u),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",E),ke(null);break}}u.ref!==null&&(ke(u),R("Invalid attribute `ref` supplied to `React.Fragment`."),ke(null))}}function Er(u,p,m,E,O,D){{var C=I(u);if(!C){var g="";(u===void 0||typeof u=="object"&&u!==null&&Object.keys(u).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Z=Fo(O);Z?g+=Z:g+=_r();var M;u===null?M="null":ge(u)?M="array":u!==void 0&&u.$$typeof===r?(M="<"+(W(u.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):M=typeof u,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",M,g)}var H=xo(u,p,m,O,D);if(H==null)return H;if(C){var re=p.children;if(re!==void 0)if(E)if(ge(re)){for(var Ae=0;Ae<re.length;Ae++)Sr(re[Ae],u);Object.freeze&&Object.freeze(re)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Sr(re,u)}return u===o?Ao(H):ko(H),H}}function Lo(u,p,m){return Er(u,p,m,!0)}function jo(u,p,m){return Er(u,p,m,!1)}var Po=jo,Uo=Lo;He.Fragment=o,He.jsx=Po,He.jsxs=Uo}()),He}(function(e){process.env.NODE_ENV==="production"?e.exports=to():e.exports=no()})(ir);const ro=ir.exports.jsx,ee=v.createContext(null),ao=({url:e="",children:r})=>{const t=v.useMemo(()=>{const o=new Oa.FrappeApp(e);return{url:e,app:o,auth:o.auth(),db:o.db(),call:o.call(),file:o.file()}},[e]);return ro(ee.Provider,{value:t,children:r})},oo=e=>{const{url:r,auth:t}=v.useContext(ee),{data:o,error:a,isValidating:n,mutate:s}=Me(`${r}/api/method/frappe.auth.get_logged_user`,()=>t.getLoggedInUser(),e),c=v.useCallback(async(i,f)=>t.loginWithUsernamePassword({username:i,password:f}).then(l=>{console.log(l),s()}),[]),d=v.useCallback(async()=>t.logout().then(()=>s(null)),[]);return{currentUser:o,isValidating:n,error:a,login:c,logout:d,updateCurrentUser:s}},so=(e,r,t,o)=>{const{db:a}=v.useContext(ee);return{...Me(
|
|
44
|
+
Check the top-level render call using <`+m+">.")}return p}}function br(u,p){{if(!u._store||u._store.validated||u.key!=null)return;u._store.validated=!0;var m=Do(p);if(yr[m])return;yr[m]=!0;var E="";u&&u._owner&&u._owner!==nn.current&&(E=" It was passed a child from "+W(u._owner.type)+"."),ke(u),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',m,E),ke(null)}}function Sr(u,p){{if(typeof u!="object")return;if(ge(u))for(var m=0;m<u.length;m++){var E=u[m];an(E)&&br(E,p)}else if(an(u))u._store&&(u._store.validated=!0);else if(u){var O=T(u);if(typeof O=="function"&&O!==u.entries)for(var D=O.call(u),C;!(C=D.next()).done;)an(C.value)&&br(C.value,p)}}}function ko(u){{var p=u.type;if(p==null||typeof p=="string")return;var m;if(typeof p=="function")m=p.propTypes;else if(typeof p=="object"&&(p.$$typeof===d||p.$$typeof===l))m=p.propTypes;else return;if(m){var E=W(p);te(m,u.props,"prop",E,u)}else if(p.PropTypes!==void 0&&!rn){rn=!0;var O=W(p);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",O||"Unknown")}typeof p.getDefaultProps=="function"&&!p.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ao(u){{for(var p=Object.keys(u.props),m=0;m<p.length;m++){var E=p[m];if(E!=="children"&&E!=="key"){ke(u),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",E),ke(null);break}}u.ref!==null&&(ke(u),R("Invalid attribute `ref` supplied to `React.Fragment`."),ke(null))}}function Er(u,p,m,E,O,D){{var C=I(u);if(!C){var g="";(u===void 0||typeof u=="object"&&u!==null&&Object.keys(u).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Z=Fo(O);Z?g+=Z:g+=_r();var M;u===null?M="null":ge(u)?M="array":u!==void 0&&u.$$typeof===r?(M="<"+(W(u.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):M=typeof u,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",M,g)}var H=xo(u,p,m,O,D);if(H==null)return H;if(C){var re=p.children;if(re!==void 0)if(E)if(ge(re)){for(var Ae=0;Ae<re.length;Ae++)Sr(re[Ae],u);Object.freeze&&Object.freeze(re)}else R("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Sr(re,u)}return u===o?Ao(H):ko(H),H}}function Lo(u,p,m){return Er(u,p,m,!0)}function jo(u,p,m){return Er(u,p,m,!1)}var Po=jo,Uo=Lo;He.Fragment=o,He.jsx=Po,He.jsxs=Uo}()),He}(function(e){process.env.NODE_ENV==="production"?e.exports=to():e.exports=no()})(ir);const ro=ir.exports.jsx,ee=v.createContext(null),ao=({url:e="",children:r})=>{const t=v.useMemo(()=>{const o=new Oa.FrappeApp(e);return{url:e,app:o,auth:o.auth(),db:o.db(),call:o.call(),file:o.file()}},[e]);return ro(ee.Provider,{value:t,children:r})},oo=e=>{const{url:r,auth:t}=v.useContext(ee),{data:o,error:a,isValidating:n,mutate:s}=Me(`${r}/api/method/frappe.auth.get_logged_user`,()=>t.getLoggedInUser(),e),c=v.useCallback(async(i,f)=>t.loginWithUsernamePassword({username:i,password:f}).then(l=>{console.log(l),s()}),[]),d=v.useCallback(async()=>t.logout().then(()=>s(null)),[]);return{currentUser:o,isValidating:n,error:a,login:c,logout:d,updateCurrentUser:s}},so=(e,r,t,o)=>{const{db:a}=v.useContext(ee);return{...Me(t===void 0?a.getRequestURL(e,r):t,()=>a.getDoc(e,r),o)}},lr=e=>{var t,o,a;let r="";if(e!=null&&e.fields&&(r+="fields="+JSON.stringify(e==null?void 0:e.fields)+"&"),e!=null&&e.filters&&(r+="filters="+JSON.stringify(e==null?void 0:e.filters)+"&"),e!=null&&e.orFilters&&(r+="or_filters="+JSON.stringify(e==null?void 0:e.orFilters)+"&"),e!=null&&e.limit_start&&(r+="limit_start="+JSON.stringify(e==null?void 0:e.limit_start)+"&"),e!=null&&e.limit&&(r+="limit="+JSON.stringify(e==null?void 0:e.limit)+"&"),e!=null&&e.orderBy){const n=`${(t=e.orderBy)==null?void 0:t.field} ${(a=(o=e.orderBy)==null?void 0:o.order)!=null?a:"asc"}`;r+="order_by="+n+"&"}return e!=null&&e.asDict&&(r+="as_dict="+e.asDict),r},io=(e,r,t,o)=>{const{db:a}=v.useContext(ee);return{...Me(t===void 0?`${a.getRequestURL(e)}?${lr(r)}`:t,()=>a.getDocList(e,r),o)}},uo=()=>{const{db:e}=v.useContext(ee),[r,t]=v.useState(!1),[o,a]=v.useState(null),[n,s]=v.useState(!1),c=v.useCallback(()=>{t(!1),a(null),s(!1)},[]);return{createDoc:v.useCallback(async(i,f)=>(a(null),s(!1),t(!0),e.createDoc(i,f).then(l=>(t(!1),s(!0),l)).catch(l=>{throw t(!1),s(!1),a(l),l})),[]),loading:r,error:o,isCompleted:n,reset:c}},co=()=>{const{db:e}=v.useContext(ee),[r,t]=v.useState(!1),[o,a]=v.useState(null),[n,s]=v.useState(!1),c=v.useCallback(()=>{t(!1),a(null),s(!1)},[]);return{updateDoc:v.useCallback(async(i,f,l)=>(a(null),s(!1),t(!0),e.updateDoc(i,f,l).then(y=>(t(!1),s(!0),y)).catch(y=>{throw t(!1),s(!1),a(y),y})),[]),loading:r,error:o,reset:c,isCompleted:n}},lo=()=>{const{db:e}=v.useContext(ee),[r,t]=v.useState(!1),[o,a]=v.useState(null),[n,s]=v.useState(!1),c=v.useCallback(()=>{t(!1),a(null),s(!1)},[]);return{deleteDoc:v.useCallback(async(i,f)=>(a(null),s(!1),t(!0),e.deleteDoc(i,f).then(l=>(t(!1),s(!0),l)).catch(l=>{throw t(!1),s(!1),a(l),l})),[]),loading:r,error:o,reset:c,isCompleted:n}};function fr(e){const r=[];for(let t in e)r.push(encodeURIComponent(t)+"="+encodeURIComponent(e[t]));return r.join("&")}const fo=(e,r,t=!1,o=!1,a,n)=>{const{url:s,db:c}=v.useContext(ee);return{...Me(a===void 0?(()=>{const f=fr(t?{doctype:e,filters:r!=null?r:[],cache:t,debug:o}:{doctype:e,filters:r!=null?r:[],debug:o});return`${s}/api/method/frappe.client.get_count?${f}`})():a,()=>c.getCount(e,r,t,o),n)}},dr=(e,r,t,o)=>{const{call:a}=v.useContext(ee),n=fr(r!=null?r:{}),s=`${e}?${n}`;return{...Me(t===void 0?s:t,()=>a.get(e,r),o)}},po=e=>{const{call:r}=v.useContext(ee),[t,o]=v.useState(null),[a,n]=v.useState(!1),[s,c]=v.useState(null),[d,i]=v.useState(!1),f=v.useCallback(()=>{o(null),n(!1),c(null),i(!1)},[]);return{call:v.useCallback(async y=>(c(null),i(!1),n(!0),o(null),r.post(e,y).then(h=>(o(h),n(!1),i(!0),h)).catch(h=>{throw n(!1),i(!1),c(h),h})),[]),result:t,loading:a,error:s,reset:f,isCompleted:d}},ho=e=>{const{call:r}=v.useContext(ee),[t,o]=v.useState(null),[a,n]=v.useState(!1),[s,c]=v.useState(null),[d,i]=v.useState(!1),f=v.useCallback(()=>{o(null),n(!1),c(null),i(!1)},[]);return{call:v.useCallback(async y=>(c(null),i(!1),n(!0),o(null),r.put(e,y).then(h=>(o(h),n(!1),i(!0),h)).catch(h=>{throw n(!1),i(!1),c(h),h})),[]),result:t,loading:a,error:s,reset:f,isCompleted:d}},vo=e=>{const{call:r}=v.useContext(ee),[t,o]=v.useState(null),[a,n]=v.useState(!1),[s,c]=v.useState(null),[d,i]=v.useState(!1),f=v.useCallback(()=>{o(null),n(!1),c(null),i(!1)},[]);return{call:v.useCallback(async y=>(c(null),i(!1),n(!0),o(null),r.delete(e,y).then(h=>(o(h),n(!1),i(!0),h)).catch(h=>{throw n(!1),i(!1),c(h),h})),[]),result:t,loading:a,error:s,reset:f,isCompleted:d}},mo=()=>{const{file:e}=v.useContext(ee),[r,t]=v.useState(0),[o,a]=v.useState(!1),[n,s]=v.useState(null),[c,d]=v.useState(!1),i=v.useCallback(async(l,y)=>(f(),a(!0),e.uploadFile(l,y,(h,S)=>t(Math.round(h/S*100))).then(h=>(d(!0),t(100),a(!1),h.data.message)).catch(h=>{throw console.error(h),s(h),a(!1),h})),[]),f=v.useCallback(()=>{t(0),a(!1),s(null),d(!1)},[]);return{upload:i,progress:r,loading:o,isCompleted:c,error:n,reset:f}},wo=(e,r,t=[],o=20,a=250)=>{const n=_o(r,a);return dr("frappe.desk.search.search_link",{doctype:e,page_length:o,txt:n,filters:JSON.stringify(t!=null?t:[])})},_o=(e,r)=>{const[t,o]=v.useState(e);return v.useEffect(()=>{const a=setTimeout(()=>{o(e)},r);return()=>{clearTimeout(a)}},[e,r]),t};N.FrappeContext=ee,N.FrappeProvider=ao,N.getDocListQueryString=lr,N.useFrappeAuth=oo,N.useFrappeCreateDoc=uo,N.useFrappeDeleteCall=vo,N.useFrappeDeleteDoc=lo,N.useFrappeFileUpload=mo,N.useFrappeGetCall=dr,N.useFrappeGetDoc=so,N.useFrappeGetDocCount=fo,N.useFrappeGetDocList=io,N.useFrappePostCall=po,N.useFrappePutCall=ho,N.useFrappeUpdateDoc=co,N.useSearch=wo,Object.defineProperties(N,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Error } from 'frappe-js-sdk/lib/frappe_app/types';
|
|
|
6
6
|
import { Filter, FrappeDoc, GetDocListArgs } from 'frappe-js-sdk/lib/db/types';
|
|
7
7
|
import { Key, SWRConfiguration, SWRResponse } from 'swr';
|
|
8
8
|
import { FileArgs } from 'frappe-js-sdk/lib/file/types';
|
|
9
|
-
export type { SWRConfiguration, SWRResponse };
|
|
9
|
+
export type { SWRConfiguration, SWRResponse, Key };
|
|
10
10
|
export type { FrappeDoc, GetDocListArgs, Filter, FileArgs, Error as FrappeError };
|
|
11
11
|
export interface FrappeConfig {
|
|
12
12
|
/** The URL of your Frappe server */
|
|
@@ -53,7 +53,7 @@ export declare const useFrappeAuth: (options?: Partial<import("swr/_internal").P
|
|
|
53
53
|
*
|
|
54
54
|
* @typeParam T - The type of the document
|
|
55
55
|
*/
|
|
56
|
-
export declare const useFrappeGetDoc: <T>(doctype: string, name?: string | undefined, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined
|
|
56
|
+
export declare const useFrappeGetDoc: <T>(doctype: string, name?: string | undefined, swrKey?: Key, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined) => SWRResponse<FrappeDoc<T>, Error>;
|
|
57
57
|
/**
|
|
58
58
|
* Function that returns a query string for all arguments passed to getDocList function
|
|
59
59
|
* @param args - The arguments to pass to the getDocList method
|
|
@@ -70,7 +70,7 @@ export declare const getDocListQueryString: (args?: GetDocListArgs | undefined)
|
|
|
70
70
|
*
|
|
71
71
|
* @typeParam T - The type definition of the document object
|
|
72
72
|
*/
|
|
73
|
-
export declare const useFrappeGetDocList: <T>(doctype: string, args?: GetDocListArgs | undefined, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined
|
|
73
|
+
export declare const useFrappeGetDocList: <T>(doctype: string, args?: GetDocListArgs | undefined, swrKey?: Key, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined) => SWRResponse<T[], Error>;
|
|
74
74
|
/**
|
|
75
75
|
* Hook to create a document in the database and maintain loading and error states
|
|
76
76
|
* @returns Object with the following properties: loading, error, isCompleted and createDoc and reset functions
|
|
@@ -133,7 +133,7 @@ export declare const useFrappeDeleteDoc: () => {
|
|
|
133
133
|
* @returns an object (SWRResponse) with the following properties: data (number), error, isValidating, and mutate
|
|
134
134
|
*
|
|
135
135
|
*/
|
|
136
|
-
export declare const useFrappeGetDocCount: (doctype: string, filters?: Filter[] | undefined, cache?: boolean, debug?: boolean, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined
|
|
136
|
+
export declare const useFrappeGetDocCount: (doctype: string, filters?: Filter[] | undefined, cache?: boolean, debug?: boolean, swrKey?: Key, options?: Partial<import("swr/_internal").PublicConfiguration<any, any, import("swr/_internal").BareFetcher<any>>> | undefined) => SWRResponse<number, Error>;
|
|
137
137
|
/**
|
|
138
138
|
* Hook to make a GET request to the server
|
|
139
139
|
*
|