@duxweb/dvha-core 1.0.30 → 1.0.31
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("axios"),f=require("lodash-es");function b(e){return Object.values(e).some(l=>l instanceof File?!0:Array.isArray(l)?l.some(a=>a instanceof File):l&&typeof l=="object"?b(l):!1)}function C(e){const l=new FormData,a=(d,r="")=>{Object.entries(d).forEach(([t,c])=>{const i=r?`${r}[${t}]`:t;c instanceof File?l.append(i,c):Array.isArray(c)?c.forEach((s,k)=>{s instanceof File?l.append(`${i}[${k}]`,s):s!=null&&l.append(`${i}[${k}]`,String(s))}):c&&typeof c=="object"?a(c,i):c!=null&&l.append(i,String(c))})};return a(e),l}function m(e){const l=(a,d)=>{const r=`${f.trim(e.apiUrl,"/")}${d?`/${f.trim(d,"/")}`:""}`;return a?`${r}/${f.trim(a||"","/")}`:r};return{apiUrl:l,getList:(a,d,r)=>{const t={};return a.pagination&&typeof a.pagination=="object"&&(t.page=a.pagination.page,t.pageSize=a.pagination.pageSize),n.get(l(a.path,d?.config.apiBasePath)||"",{params:{...t,...a.filters,...a.sorters},headers:{Authorization:r?.token},...a.meta}).then(c=>e.successCallback?e.successCallback(c):h(c)).catch(c=>{throw e.errorCallback?e.errorCallback(c):u(c)})},create:(a,d,r)=>{let t=a.data;return a.data&&typeof a.data=="object"&&!Array.isArray(a.data)&&!(a.data instanceof FormData)&&b(a.data)&&(t=C(a.data)),n.post(l(a.path,d?.config.apiBasePath)||"",t,{headers:{Authorization:r?.token},...a.meta}).then(c=>e.successCallback?e.successCallback(c):h(c)).catch(c=>{throw e.errorCallback?e.errorCallback(c):u(c)})},update:(a,d,r)=>{let t=a.data;return a.data&&typeof a.data=="object"&&!Array.isArray(a.data)&&!(a.data instanceof FormData)&&b(a.data)&&(t=C(a.data)),n.put(l(a.id?`${a.path}/${a.id}`:a.path,d?.config.apiBasePath)||"",t,{headers:{Authorization:r?.token},...a.meta}).then(c=>e.successCallback?e.successCallback(c):h(c)).catch(c=>{throw e.errorCallback?e.errorCallback(c):u(c)})},deleteOne:(a,d,r)=>n.delete(l(a.id?`${a.path}/${a.id}`:a.path,d?.config.apiBasePath)||"",{headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),getOne:(a,d,r)=>n.get(l(a.id?`${a.path}/${a.id}`:a.path,d?.config.apiBasePath)||"",{headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),getMany:(a,d,r)=>n.get(l(a.path,d?.config.apiBasePath)||"",{params:{ids:a.ids},headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),createMany:(a,d,r)=>n.post(l(a.path,d?.config.apiBasePath)||"",a.data,{headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),updateMany:(a,d,r)=>n.put(l(a.path,d?.config.apiBasePath)||"",{ids:a.ids,data:a.data},{headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),deleteMany:(a,d,r)=>n.delete(l(a.path,d?.config.apiBasePath)||"",{params:{ids:a.ids},headers:{Authorization:r?.token},...a.meta}).then(t=>e.successCallback?e.successCallback(t):h(t)).catch(t=>{throw e.errorCallback?e.errorCallback(t):u(t)}),custom:(a,d,r)=>{let t={...a.query};return a.sorters&&typeof a.sorters=="object"&&(t={...t,...a.sorters}),a.filters&&typeof a.filters=="object"&&(t={...t,...a.filters}),n.request({url:l(a.path,d?.config.apiBasePath)||"",method:a.method||"GET",data:a.payload,params:t,signal:a.signal,headers:{Authorization:r?.token,...a.headers},onUploadProgress:c=>{const i=Math.round(c.loaded*100/(c.total||1));a.onUploadProgress?.({loaded:c.loaded,total:c.total,percent:i})},onDownloadProgress:c=>{const i=Math.round(c.loaded*100/(c.total||1));a.onDownloadProgress?.({loaded:c.loaded,total:c.total,percent:i})},...a.meta}).then(c=>e.successCallback?e.successCallback(c):h(c)).catch(c=>{throw e.errorCallback?e.errorCallback(c):u(c)})},getTotal:a=>e.getTotal?e.getTotal(a):a.meta?.total||0}}function h(e){return{message:e.data?.message,data:e.data?.data,meta:e.data?.meta,raw:e.data}}function u(e){return{message:e.response?.data?.message||e?.message,data:e.response?.data?.data,meta:e.response?.data?.meta,status:e.response?.data?.code||e.response?.status||500,raw:e.response?.data}}exports.simpleDataProvider=m;
|
|
@@ -1,162 +1,182 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { trim as
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import n from "axios";
|
|
2
|
+
import { trim as s } from "lodash-es";
|
|
3
|
+
function b(e) {
|
|
4
|
+
return Object.values(e).some((l) => l instanceof File ? !0 : Array.isArray(l) ? l.some((a) => a instanceof File) : l && typeof l == "object" ? b(l) : !1);
|
|
5
|
+
}
|
|
6
|
+
function C(e) {
|
|
7
|
+
const l = new FormData(), a = (d, r = "") => {
|
|
8
|
+
Object.entries(d).forEach(([t, c]) => {
|
|
9
|
+
const f = r ? `${r}[${t}]` : t;
|
|
10
|
+
c instanceof File ? l.append(f, c) : Array.isArray(c) ? c.forEach((i, k) => {
|
|
11
|
+
i instanceof File ? l.append(`${f}[${k}]`, i) : i != null && l.append(`${f}[${k}]`, String(i));
|
|
12
|
+
}) : c && typeof c == "object" ? a(c, f) : c != null && l.append(f, String(c));
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
return a(e), l;
|
|
16
|
+
}
|
|
17
|
+
function y(e) {
|
|
18
|
+
const l = (a, d) => {
|
|
19
|
+
const r = `${s(e.apiUrl, "/")}${d ? `/${s(d, "/")}` : ""}`;
|
|
20
|
+
return a ? `${r}/${s(a || "", "/")}` : r;
|
|
7
21
|
};
|
|
8
22
|
return {
|
|
9
|
-
apiUrl:
|
|
10
|
-
getList: (a,
|
|
11
|
-
const
|
|
12
|
-
return a.pagination && typeof a.pagination == "object" && (
|
|
23
|
+
apiUrl: l,
|
|
24
|
+
getList: (a, d, r) => {
|
|
25
|
+
const t = {};
|
|
26
|
+
return a.pagination && typeof a.pagination == "object" && (t.page = a.pagination.page, t.pageSize = a.pagination.pageSize), n.get(l(a.path, d?.config.apiBasePath) || "", {
|
|
13
27
|
params: {
|
|
14
|
-
...
|
|
28
|
+
...t,
|
|
15
29
|
...a.filters,
|
|
16
30
|
...a.sorters
|
|
17
31
|
},
|
|
18
32
|
headers: {
|
|
19
|
-
Authorization:
|
|
33
|
+
Authorization: r?.token
|
|
20
34
|
},
|
|
21
35
|
...a.meta
|
|
22
|
-
}).then((
|
|
23
|
-
throw
|
|
36
|
+
}).then((c) => e.successCallback ? e.successCallback(c) : h(c)).catch((c) => {
|
|
37
|
+
throw e.errorCallback ? e.errorCallback(c) : u(c);
|
|
24
38
|
});
|
|
25
39
|
},
|
|
26
|
-
create: (a,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
create: (a, d, r) => {
|
|
41
|
+
let t = a.data;
|
|
42
|
+
return a.data && typeof a.data == "object" && !Array.isArray(a.data) && !(a.data instanceof FormData) && b(a.data) && (t = C(a.data)), n.post(l(a.path, d?.config.apiBasePath) || "", t, {
|
|
43
|
+
headers: {
|
|
44
|
+
Authorization: r?.token
|
|
45
|
+
},
|
|
46
|
+
...a.meta
|
|
47
|
+
}).then((c) => e.successCallback ? e.successCallback(c) : h(c)).catch((c) => {
|
|
48
|
+
throw e.errorCallback ? e.errorCallback(c) : u(c);
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
update: (a, d, r) => {
|
|
52
|
+
let t = a.data;
|
|
53
|
+
return a.data && typeof a.data == "object" && !Array.isArray(a.data) && !(a.data instanceof FormData) && b(a.data) && (t = C(a.data)), n.put(l(a.id ? `${a.path}/${a.id}` : a.path, d?.config.apiBasePath) || "", t, {
|
|
54
|
+
headers: {
|
|
55
|
+
Authorization: r?.token
|
|
56
|
+
},
|
|
57
|
+
...a.meta
|
|
58
|
+
}).then((c) => e.successCallback ? e.successCallback(c) : h(c)).catch((c) => {
|
|
59
|
+
throw e.errorCallback ? e.errorCallback(c) : u(c);
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
deleteOne: (a, d, r) => n.delete(l(a.id ? `${a.path}/${a.id}` : a.path, d?.config.apiBasePath) || "", {
|
|
43
63
|
headers: {
|
|
44
|
-
Authorization:
|
|
64
|
+
Authorization: r?.token
|
|
45
65
|
},
|
|
46
66
|
...a.meta
|
|
47
|
-
}).then((
|
|
48
|
-
throw
|
|
67
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
68
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
49
69
|
}),
|
|
50
|
-
getOne: (a,
|
|
70
|
+
getOne: (a, d, r) => n.get(l(a.id ? `${a.path}/${a.id}` : a.path, d?.config.apiBasePath) || "", {
|
|
51
71
|
headers: {
|
|
52
|
-
Authorization:
|
|
72
|
+
Authorization: r?.token
|
|
53
73
|
},
|
|
54
74
|
...a.meta
|
|
55
|
-
}).then((
|
|
56
|
-
throw
|
|
75
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
76
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
57
77
|
}),
|
|
58
|
-
getMany: (a,
|
|
78
|
+
getMany: (a, d, r) => n.get(l(a.path, d?.config.apiBasePath) || "", {
|
|
59
79
|
params: {
|
|
60
80
|
ids: a.ids
|
|
61
81
|
},
|
|
62
82
|
headers: {
|
|
63
|
-
Authorization:
|
|
83
|
+
Authorization: r?.token
|
|
64
84
|
},
|
|
65
85
|
...a.meta
|
|
66
|
-
}).then((
|
|
67
|
-
throw
|
|
86
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
87
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
68
88
|
}),
|
|
69
|
-
createMany: (a,
|
|
89
|
+
createMany: (a, d, r) => n.post(l(a.path, d?.config.apiBasePath) || "", a.data, {
|
|
70
90
|
headers: {
|
|
71
|
-
Authorization:
|
|
91
|
+
Authorization: r?.token
|
|
72
92
|
},
|
|
73
93
|
...a.meta
|
|
74
|
-
}).then((
|
|
75
|
-
throw
|
|
94
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
95
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
76
96
|
}),
|
|
77
|
-
updateMany: (a,
|
|
97
|
+
updateMany: (a, d, r) => n.put(l(a.path, d?.config.apiBasePath) || "", {
|
|
78
98
|
ids: a.ids,
|
|
79
99
|
data: a.data
|
|
80
100
|
}, {
|
|
81
101
|
headers: {
|
|
82
|
-
Authorization:
|
|
102
|
+
Authorization: r?.token
|
|
83
103
|
},
|
|
84
104
|
...a.meta
|
|
85
|
-
}).then((
|
|
86
|
-
throw
|
|
105
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
106
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
87
107
|
}),
|
|
88
|
-
deleteMany: (a,
|
|
108
|
+
deleteMany: (a, d, r) => n.delete(l(a.path, d?.config.apiBasePath) || "", {
|
|
89
109
|
params: {
|
|
90
110
|
ids: a.ids
|
|
91
111
|
},
|
|
92
112
|
headers: {
|
|
93
|
-
Authorization:
|
|
113
|
+
Authorization: r?.token
|
|
94
114
|
},
|
|
95
115
|
...a.meta
|
|
96
|
-
}).then((
|
|
97
|
-
throw
|
|
116
|
+
}).then((t) => e.successCallback ? e.successCallback(t) : h(t)).catch((t) => {
|
|
117
|
+
throw e.errorCallback ? e.errorCallback(t) : u(t);
|
|
98
118
|
}),
|
|
99
|
-
custom: (a,
|
|
100
|
-
let
|
|
119
|
+
custom: (a, d, r) => {
|
|
120
|
+
let t = {
|
|
101
121
|
...a.query
|
|
102
122
|
};
|
|
103
|
-
return a.sorters && typeof a.sorters == "object" && (
|
|
104
|
-
...
|
|
123
|
+
return a.sorters && typeof a.sorters == "object" && (t = {
|
|
124
|
+
...t,
|
|
105
125
|
...a.sorters
|
|
106
|
-
}), a.filters && typeof a.filters == "object" && (
|
|
107
|
-
...
|
|
126
|
+
}), a.filters && typeof a.filters == "object" && (t = {
|
|
127
|
+
...t,
|
|
108
128
|
...a.filters
|
|
109
|
-
}),
|
|
110
|
-
url:
|
|
129
|
+
}), n.request({
|
|
130
|
+
url: l(a.path, d?.config.apiBasePath) || "",
|
|
111
131
|
method: a.method || "GET",
|
|
112
132
|
data: a.payload,
|
|
113
|
-
params:
|
|
133
|
+
params: t,
|
|
114
134
|
signal: a.signal,
|
|
115
135
|
headers: {
|
|
116
|
-
Authorization:
|
|
136
|
+
Authorization: r?.token,
|
|
117
137
|
...a.headers
|
|
118
138
|
},
|
|
119
|
-
onUploadProgress: (
|
|
120
|
-
const
|
|
139
|
+
onUploadProgress: (c) => {
|
|
140
|
+
const f = Math.round(c.loaded * 100 / (c.total || 1));
|
|
121
141
|
a.onUploadProgress?.({
|
|
122
|
-
loaded:
|
|
123
|
-
total:
|
|
124
|
-
percent:
|
|
142
|
+
loaded: c.loaded,
|
|
143
|
+
total: c.total,
|
|
144
|
+
percent: f
|
|
125
145
|
});
|
|
126
146
|
},
|
|
127
|
-
onDownloadProgress: (
|
|
128
|
-
const
|
|
147
|
+
onDownloadProgress: (c) => {
|
|
148
|
+
const f = Math.round(c.loaded * 100 / (c.total || 1));
|
|
129
149
|
a.onDownloadProgress?.({
|
|
130
|
-
loaded:
|
|
131
|
-
total:
|
|
132
|
-
percent:
|
|
150
|
+
loaded: c.loaded,
|
|
151
|
+
total: c.total,
|
|
152
|
+
percent: f
|
|
133
153
|
});
|
|
134
154
|
},
|
|
135
155
|
...a.meta
|
|
136
|
-
}).then((
|
|
137
|
-
throw
|
|
156
|
+
}).then((c) => e.successCallback ? e.successCallback(c) : h(c)).catch((c) => {
|
|
157
|
+
throw e.errorCallback ? e.errorCallback(c) : u(c);
|
|
138
158
|
});
|
|
139
159
|
},
|
|
140
|
-
getTotal: (a) =>
|
|
160
|
+
getTotal: (a) => e.getTotal ? e.getTotal(a) : a.meta?.total || 0
|
|
141
161
|
};
|
|
142
162
|
}
|
|
143
|
-
function
|
|
163
|
+
function h(e) {
|
|
144
164
|
return {
|
|
145
|
-
message:
|
|
146
|
-
data:
|
|
147
|
-
meta:
|
|
148
|
-
raw:
|
|
165
|
+
message: e.data?.message,
|
|
166
|
+
data: e.data?.data,
|
|
167
|
+
meta: e.data?.meta,
|
|
168
|
+
raw: e.data
|
|
149
169
|
};
|
|
150
170
|
}
|
|
151
|
-
function
|
|
171
|
+
function u(e) {
|
|
152
172
|
return {
|
|
153
|
-
message:
|
|
154
|
-
data:
|
|
155
|
-
meta:
|
|
156
|
-
status:
|
|
157
|
-
raw:
|
|
173
|
+
message: e.response?.data?.message || e?.message,
|
|
174
|
+
data: e.response?.data?.data,
|
|
175
|
+
meta: e.response?.data?.meta,
|
|
176
|
+
status: e.response?.data?.code || e.response?.status || 500,
|
|
177
|
+
raw: e.response?.data
|
|
158
178
|
};
|
|
159
179
|
}
|
|
160
180
|
export {
|
|
161
|
-
|
|
181
|
+
y as simpleDataProvider
|
|
162
182
|
};
|