jordy 0.12.0
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.
- package/README.md +11 -0
- package/esm5/adaptive-render/AdaptiveRender.js +14 -0
- package/esm5/adaptive-render/DeviceDetectContext.js +62 -0
- package/esm5/adaptive-render/adaptive-render.type.js +1 -0
- package/esm5/adaptive-render/device.type.js +9 -0
- package/esm5/adaptive-render/index.js +4 -0
- package/esm5/adaptive-render/withAdaptiveRender.js +29 -0
- package/esm5/hooks/index.js +3 -0
- package/esm5/hooks/useDebounce.js +26 -0
- package/esm5/hooks/useQueryParams.js +20 -0
- package/esm5/hooks/useThrottle.js +18 -0
- package/esm5/http-api/httpApi.factory.js +143 -0
- package/esm5/http-api/httpHeader.factory.js +46 -0
- package/esm5/http-api/index.js +3 -0
- package/esm5/http-api/network.type.js +1 -0
- package/esm5/http-api/networkParser.js +73 -0
- package/esm5/index.js +11 -0
- package/esm5/proxies/cache.proxy.js +40 -0
- package/esm5/proxies/index.js +1 -0
- package/esm5/queries/buildMutationCreator.js +87 -0
- package/esm5/queries/buildQueryCreator.js +124 -0
- package/esm5/queries/index.js +2 -0
- package/esm5/queries/useMakeDeps.js +23 -0
- package/esm5/queries/utils/clearCacheByKeyword.js +50 -0
- package/esm5/queries/utils/createCacheKey.js +23 -0
- package/esm5/queries/utils/index.js +2 -0
- package/esm5/route-system/AsyncGuard.js +37 -0
- package/esm5/route-system/index.js +3 -0
- package/esm5/route-system/moduleRoute.model.js +1 -0
- package/esm5/route-system/renderRouteSystem.js +64 -0
- package/esm5/route-system/routeSystem.util.js +23 -0
- package/esm5/storage/CookieStorageAdapter.js +20 -0
- package/esm5/storage/ExpiableStorageAdapter.js +36 -0
- package/esm5/storage/MemorySimpleStorage.js +18 -0
- package/esm5/storage/SimpleStorageAdapter.js +18 -0
- package/esm5/storage/cookie.js +27 -0
- package/esm5/storage/index.js +4 -0
- package/esm5/storage/memoryStorage.js +35 -0
- package/esm5/storage/storage.factory.js +30 -0
- package/esm5/storage/storage.type.js +1 -0
- package/esm5/storage/token-provider.factory.js +23 -0
- package/esm5/types/component.type.js +1 -0
- package/esm5/types/index.js +2 -0
- package/esm5/types/marshalling.type.js +1 -0
- package/esm5/util/collection.js +17 -0
- package/esm5/util/envCheck.js +55 -0
- package/esm5/util/etc.js +12 -0
- package/esm5/util/filter.js +10 -0
- package/esm5/util/format.js +8 -0
- package/esm5/util/index.js +15 -0
- package/esm5/util/josa.js +57 -0
- package/esm5/util/json.js +19 -0
- package/esm5/util/libLoader.js +27 -0
- package/esm5/util/path.js +16 -0
- package/esm5/util/queryString.js +62 -0
- package/esm5/util/redux.js +6 -0
- package/esm5/util/template.js +65 -0
- package/esm5/util/typeCheck.js +33 -0
- package/esm5/validate/fn.js +66 -0
- package/esm5/validate/index.js +7 -0
- package/esm5/validate/mergeValidates.js +22 -0
- package/esm5/validate/validate.js +22 -0
- package/esm5/validate/validate.type.js +1 -0
- package/esm5/validate/validateSubUtils.js +67 -0
- package/libs/adaptive-render/AdaptiveRender.d.ts +25 -0
- package/libs/adaptive-render/DeviceDetectContext.d.ts +16 -0
- package/libs/adaptive-render/adaptive-render.type.d.ts +63 -0
- package/libs/adaptive-render/device.type.d.ts +14 -0
- package/libs/adaptive-render/index.d.ts +4 -0
- package/libs/adaptive-render/withAdaptiveRender.d.ts +35 -0
- package/libs/hooks/index.d.ts +3 -0
- package/libs/hooks/useDebounce.d.ts +29 -0
- package/libs/hooks/useQueryParams.d.ts +19 -0
- package/libs/hooks/useThrottle.d.ts +25 -0
- package/libs/http-api/httpApi.factory.d.ts +9 -0
- package/libs/http-api/httpHeader.factory.d.ts +15 -0
- package/libs/http-api/index.d.ts +3 -0
- package/libs/http-api/network.type.d.ts +109 -0
- package/libs/http-api/networkParser.d.ts +9 -0
- package/libs/index.d.ts +11 -0
- package/libs/proxies/cache.proxy.d.ts +11 -0
- package/libs/proxies/index.d.ts +1 -0
- package/libs/queries/buildMutationCreator.d.ts +37 -0
- package/libs/queries/buildQueryCreator.d.ts +115 -0
- package/libs/queries/index.d.ts +2 -0
- package/libs/queries/useMakeDeps.d.ts +1 -0
- package/libs/queries/utils/clearCacheByKeyword.d.ts +14 -0
- package/libs/queries/utils/createCacheKey.d.ts +1 -0
- package/libs/queries/utils/index.d.ts +2 -0
- package/libs/route-system/AsyncGuard.d.ts +8 -0
- package/libs/route-system/index.d.ts +3 -0
- package/libs/route-system/moduleRoute.model.d.ts +49 -0
- package/libs/route-system/renderRouteSystem.d.ts +5 -0
- package/libs/route-system/routeSystem.util.d.ts +4 -0
- package/libs/storage/CookieStorageAdapter.d.ts +11 -0
- package/libs/storage/ExpiableStorageAdapter.d.ts +11 -0
- package/libs/storage/MemorySimpleStorage.d.ts +10 -0
- package/libs/storage/SimpleStorageAdapter.d.ts +10 -0
- package/libs/storage/cookie.d.ts +2 -0
- package/libs/storage/index.d.ts +4 -0
- package/libs/storage/memoryStorage.d.ts +7 -0
- package/libs/storage/storage.factory.d.ts +31 -0
- package/libs/storage/storage.type.d.ts +96 -0
- package/libs/storage/token-provider.factory.d.ts +9 -0
- package/libs/types/component.type.d.ts +23 -0
- package/libs/types/index.d.ts +2 -0
- package/libs/types/marshalling.type.d.ts +5 -0
- package/libs/util/collection.d.ts +25 -0
- package/libs/util/envCheck.d.ts +56 -0
- package/libs/util/etc.d.ts +11 -0
- package/libs/util/filter.d.ts +2 -0
- package/libs/util/format.d.ts +6 -0
- package/libs/util/index.d.ts +15 -0
- package/libs/util/josa.d.ts +66 -0
- package/libs/util/json.d.ts +14 -0
- package/libs/util/libLoader.d.ts +1 -0
- package/libs/util/path.d.ts +20 -0
- package/libs/util/queryString.d.ts +35 -0
- package/libs/util/redux.d.ts +3 -0
- package/libs/util/template.d.ts +38 -0
- package/libs/util/typeCheck.d.ts +42 -0
- package/libs/validate/fn.d.ts +111 -0
- package/libs/validate/index.d.ts +58 -0
- package/libs/validate/mergeValidates.d.ts +21 -0
- package/libs/validate/validate.d.ts +2 -0
- package/libs/validate/validate.type.d.ts +84 -0
- package/libs/validate/validateSubUtils.d.ts +12 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIsMobile, useIsTablet } from './DeviceDetectContext';
|
|
3
|
+
export var AdaptiveRender = function (_a) {
|
|
4
|
+
var mobile = _a.mobile, notTablet = _a.notTablet, children = _a.children;
|
|
5
|
+
var isMobile = useIsMobile();
|
|
6
|
+
var isTablet = useIsTablet();
|
|
7
|
+
if (notTablet && isTablet) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if ((mobile && isMobile) || (!mobile && !isMobile)) {
|
|
11
|
+
return React.createElement(React.Fragment, null, children);
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
2
|
+
import { isMobile as isMobileCheck, isNativeApp as isNativeAppCheck, isServer, isTablet as isTabletCheck, } from '../util/envCheck';
|
|
3
|
+
import { DeviceSizeEnum } from './device.type';
|
|
4
|
+
function getIsMobile() {
|
|
5
|
+
if (isServer()) {
|
|
6
|
+
try {
|
|
7
|
+
return isMobileCheck();
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return isMobileCheck() || window.innerWidth < DeviceSizeEnum.TABLET;
|
|
14
|
+
}
|
|
15
|
+
function getIsTablet() {
|
|
16
|
+
if (isServer()) {
|
|
17
|
+
try {
|
|
18
|
+
return isTabletCheck();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return (isTabletCheck() ||
|
|
25
|
+
(window.innerWidth >= DeviceSizeEnum.TABLET &&
|
|
26
|
+
window.innerWidth <= DeviceSizeEnum.DESKTOP_SM - 1));
|
|
27
|
+
}
|
|
28
|
+
export var DeviceDetectContext = createContext([
|
|
29
|
+
getIsMobile(),
|
|
30
|
+
getIsTablet(),
|
|
31
|
+
isNativeAppCheck(),
|
|
32
|
+
]);
|
|
33
|
+
var DeviceDetectContextProvider = DeviceDetectContext.Provider;
|
|
34
|
+
export var DeviceDetectProvider = function (_a) {
|
|
35
|
+
var children = _a.children;
|
|
36
|
+
var _b = useState(getIsMobile()), isMobile = _b[0], setIsMobile = _b[1];
|
|
37
|
+
var _c = useState(getIsTablet()), isTablet = _c[0], setIsTablet = _c[1];
|
|
38
|
+
var isNative = useMemo(isNativeAppCheck, []);
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
if (isServer() || !window || typeof window.matchMedia !== 'function') {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
var mqMobile = window.matchMedia("screen and (max-width: ".concat(DeviceSizeEnum.TABLET - 1, "px)"));
|
|
44
|
+
var mqTablet = window.matchMedia("screen and (min-width: ".concat(DeviceSizeEnum.TABLET, "px) and (max-width: ").concat(DeviceSizeEnum.DESKTOP_SM - 1, "px)"));
|
|
45
|
+
var handleResizeForMobile = function (e) {
|
|
46
|
+
setIsMobile(e.matches);
|
|
47
|
+
};
|
|
48
|
+
var handleResizeForTablet = function (e) {
|
|
49
|
+
setIsTablet(e.matches);
|
|
50
|
+
};
|
|
51
|
+
mqMobile.addEventListener('change', handleResizeForMobile);
|
|
52
|
+
mqTablet.addEventListener('change', handleResizeForTablet);
|
|
53
|
+
return function () {
|
|
54
|
+
mqMobile.removeEventListener('change', handleResizeForMobile);
|
|
55
|
+
mqTablet.removeEventListener('change', handleResizeForTablet);
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
58
|
+
return (React.createElement(DeviceDetectContextProvider, { value: [isMobile, isTablet, isNative] }, children));
|
|
59
|
+
};
|
|
60
|
+
export var useIsMobile = function () { return useContext(DeviceDetectContext)[0]; };
|
|
61
|
+
export var useIsTablet = function () { return useContext(DeviceDetectContext)[1]; };
|
|
62
|
+
export var useIsNative = function () { return useContext(DeviceDetectContext)[2]; };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export var DeviceSizeEnum;
|
|
2
|
+
(function (DeviceSizeEnum) {
|
|
3
|
+
DeviceSizeEnum[DeviceSizeEnum["MOBILE_SM"] = 320] = "MOBILE_SM";
|
|
4
|
+
DeviceSizeEnum[DeviceSizeEnum["MOBILE"] = 481] = "MOBILE";
|
|
5
|
+
DeviceSizeEnum[DeviceSizeEnum["TABLET_SM"] = 768] = "TABLET_SM";
|
|
6
|
+
DeviceSizeEnum[DeviceSizeEnum["TABLET"] = 961] = "TABLET";
|
|
7
|
+
DeviceSizeEnum[DeviceSizeEnum["DESKTOP_SM"] = 1025] = "DESKTOP_SM";
|
|
8
|
+
DeviceSizeEnum[DeviceSizeEnum["DESKTOP"] = 1120] = "DESKTOP";
|
|
9
|
+
})(DeviceSizeEnum || (DeviceSizeEnum = {}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useIsMobile, useIsTablet, useIsNative } from './DeviceDetectContext';
|
|
4
|
+
export function withAdaptiveRender(settings) {
|
|
5
|
+
var FnComp = function (props) {
|
|
6
|
+
var isMobile = useIsMobile();
|
|
7
|
+
var isTablet = useIsTablet();
|
|
8
|
+
var isNative = useIsNative();
|
|
9
|
+
var DesktopComp = settings.desktop, TabletComp = settings.tablet, MobileComp = settings.mobile, NativeAppComp = settings.native;
|
|
10
|
+
var Comp;
|
|
11
|
+
if (isNative && NativeAppComp) {
|
|
12
|
+
Comp = NativeAppComp;
|
|
13
|
+
}
|
|
14
|
+
else if (isMobile && MobileComp) {
|
|
15
|
+
Comp = MobileComp;
|
|
16
|
+
}
|
|
17
|
+
else if (isTablet && TabletComp) {
|
|
18
|
+
Comp = TabletComp;
|
|
19
|
+
}
|
|
20
|
+
else if (!isMobile && !isTablet && DesktopComp) {
|
|
21
|
+
Comp = DesktopComp;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return React.createElement(Comp, __assign({}, props));
|
|
27
|
+
};
|
|
28
|
+
return FnComp;
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
export function useDebounce(fn, time, deps) {
|
|
4
|
+
if (time === void 0) { time = 300; }
|
|
5
|
+
if (deps === void 0) { deps = []; }
|
|
6
|
+
var timerRef = useRef(0);
|
|
7
|
+
var memoizeFn = useCallback(fn, deps);
|
|
8
|
+
useEffect(function () { return function () { return clearTimeout(timerRef.current); }; }, [memoizeFn]);
|
|
9
|
+
var callback = useMemo(function () {
|
|
10
|
+
var result = (function (args) {
|
|
11
|
+
if (timerRef.current) {
|
|
12
|
+
clearTimeout(timerRef.current);
|
|
13
|
+
}
|
|
14
|
+
timerRef.current = setTimeout(function () {
|
|
15
|
+
memoizeFn(args);
|
|
16
|
+
}, time);
|
|
17
|
+
});
|
|
18
|
+
result.stop = function () {
|
|
19
|
+
if (timerRef.current) {
|
|
20
|
+
clearTimeout(timerRef.current);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return result;
|
|
24
|
+
}, [memoizeFn]);
|
|
25
|
+
return callback;
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { useCallback, useMemo } from 'react';
|
|
3
|
+
import { useLocation, useParams } from 'react-router-dom';
|
|
4
|
+
import { qs } from '../util/queryString';
|
|
5
|
+
var defSelector = function (params) {
|
|
6
|
+
return params;
|
|
7
|
+
};
|
|
8
|
+
export function useQueryParams(selector) {
|
|
9
|
+
if (selector === void 0) { selector = defSelector; }
|
|
10
|
+
var selConverter = useCallback(selector, []);
|
|
11
|
+
var location = useLocation();
|
|
12
|
+
var params = useParams();
|
|
13
|
+
var searchString = location.search;
|
|
14
|
+
var result = useMemo(function () {
|
|
15
|
+
var query = qs.parse(searchString);
|
|
16
|
+
var innerResult = __assign(__assign({}, query), params);
|
|
17
|
+
return selConverter(innerResult);
|
|
18
|
+
}, [searchString, params, selConverter]);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
export function useThrottle(fn, time, deps) {
|
|
3
|
+
if (time === void 0) { time = 300; }
|
|
4
|
+
if (deps === void 0) { deps = []; }
|
|
5
|
+
var timerRef = useRef(0);
|
|
6
|
+
var memoizeFn = useCallback(fn, deps);
|
|
7
|
+
useEffect(function () { return function () { return clearTimeout(timerRef.current); }; }, [memoizeFn]);
|
|
8
|
+
var callback = useCallback(function (args) {
|
|
9
|
+
if (timerRef.current) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
timerRef.current = setTimeout(function () {
|
|
13
|
+
timerRef.current = 0;
|
|
14
|
+
}, time);
|
|
15
|
+
memoizeFn(args);
|
|
16
|
+
}, [memoizeFn]);
|
|
17
|
+
return callback;
|
|
18
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getFileName, qs } from '../util';
|
|
3
|
+
import { axiosCreateHeader, axiosResponseToData, axiosUploadCommon as uploadCommon, convertToFormData, throwNewErrorForLib, } from './networkParser';
|
|
4
|
+
export var createHttpApi = function (baseUrl, parserVisitor, headerProvider, withCredentials, paramsSerializer) {
|
|
5
|
+
if (headerProvider === void 0) { headerProvider = function () { return ({}); }; }
|
|
6
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
7
|
+
if (paramsSerializer === void 0) { paramsSerializer = qs.serialize; }
|
|
8
|
+
var fnUploadCommon = uploadCommon(baseUrl, parserVisitor, headerProvider, withCredentials);
|
|
9
|
+
var fnCatchCommon = throwNewErrorForLib(parserVisitor);
|
|
10
|
+
var fnExceptCommon = parserVisitor.throwOther;
|
|
11
|
+
return {
|
|
12
|
+
delete: function (url, params, timeout) {
|
|
13
|
+
try {
|
|
14
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
15
|
+
return axios
|
|
16
|
+
.delete("".concat(baseUrl).concat(url), {
|
|
17
|
+
headers: headers,
|
|
18
|
+
params: params,
|
|
19
|
+
withCredentials: withCredentials,
|
|
20
|
+
timeout: timeout,
|
|
21
|
+
paramsSerializer: paramsSerializer,
|
|
22
|
+
})
|
|
23
|
+
.then(axiosResponseToData)
|
|
24
|
+
.catch(fnCatchCommon);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
get: function (url, params, timeout) {
|
|
31
|
+
try {
|
|
32
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
33
|
+
return axios
|
|
34
|
+
.get("".concat(baseUrl).concat(url), {
|
|
35
|
+
headers: headers,
|
|
36
|
+
params: params,
|
|
37
|
+
withCredentials: withCredentials,
|
|
38
|
+
timeout: timeout,
|
|
39
|
+
paramsSerializer: paramsSerializer,
|
|
40
|
+
})
|
|
41
|
+
.then(axiosResponseToData)
|
|
42
|
+
.catch(fnCatchCommon);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
getFile: function (url, params, filename) {
|
|
49
|
+
try {
|
|
50
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
51
|
+
return axios
|
|
52
|
+
.get(baseUrl + url, {
|
|
53
|
+
headers: headers,
|
|
54
|
+
params: params,
|
|
55
|
+
responseType: 'blob',
|
|
56
|
+
withCredentials: withCredentials,
|
|
57
|
+
paramsSerializer: paramsSerializer,
|
|
58
|
+
})
|
|
59
|
+
.then(axiosResponseToData)
|
|
60
|
+
.then(function (blob) { return new File([blob], filename || getFileName(url)); })
|
|
61
|
+
.catch(fnCatchCommon);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
getBlob: function (url, params) {
|
|
68
|
+
try {
|
|
69
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
70
|
+
return axios
|
|
71
|
+
.get(baseUrl + url, {
|
|
72
|
+
headers: headers,
|
|
73
|
+
params: params,
|
|
74
|
+
responseType: 'blob',
|
|
75
|
+
withCredentials: withCredentials,
|
|
76
|
+
paramsSerializer: paramsSerializer,
|
|
77
|
+
})
|
|
78
|
+
.then(axiosResponseToData)
|
|
79
|
+
.catch(fnCatchCommon);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
post: function (url, data, timeout) {
|
|
86
|
+
if (data === void 0) { data = null; }
|
|
87
|
+
try {
|
|
88
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
89
|
+
return axios
|
|
90
|
+
.post(baseUrl + url, data, {
|
|
91
|
+
headers: headers,
|
|
92
|
+
withCredentials: withCredentials,
|
|
93
|
+
timeout: timeout,
|
|
94
|
+
})
|
|
95
|
+
.then(axiosResponseToData)
|
|
96
|
+
.catch(fnCatchCommon);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
postUpload: function (url, data, progCallback, timeout) {
|
|
103
|
+
return fnUploadCommon('post', url, convertToFormData(data), progCallback, timeout);
|
|
104
|
+
},
|
|
105
|
+
put: function (url, data, timeout) {
|
|
106
|
+
if (data === void 0) { data = null; }
|
|
107
|
+
try {
|
|
108
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
109
|
+
return axios
|
|
110
|
+
.put(baseUrl + url, data, {
|
|
111
|
+
headers: headers,
|
|
112
|
+
withCredentials: withCredentials,
|
|
113
|
+
timeout: timeout,
|
|
114
|
+
})
|
|
115
|
+
.then(axiosResponseToData)
|
|
116
|
+
.catch(fnCatchCommon);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
putUpload: function (url, data, progCallback, timeout) {
|
|
123
|
+
return fnUploadCommon('put', url, convertToFormData(data), progCallback, timeout);
|
|
124
|
+
},
|
|
125
|
+
patch: function (url, data, timeout) {
|
|
126
|
+
if (data === void 0) { data = null; }
|
|
127
|
+
try {
|
|
128
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
129
|
+
return axios
|
|
130
|
+
.patch(baseUrl + url, data, {
|
|
131
|
+
headers: headers,
|
|
132
|
+
withCredentials: withCredentials,
|
|
133
|
+
timeout: timeout,
|
|
134
|
+
})
|
|
135
|
+
.then(axiosResponseToData)
|
|
136
|
+
.catch(fnCatchCommon);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return Promise.reject(error).catch(fnExceptCommon);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isServer } from '../util/envCheck';
|
|
2
|
+
var acceptContentType = function (headerData) {
|
|
3
|
+
headerData.Accept = 'application/json';
|
|
4
|
+
return headerData;
|
|
5
|
+
};
|
|
6
|
+
var contentTypeFormPost = function (headerData) {
|
|
7
|
+
headerData['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
8
|
+
return headerData;
|
|
9
|
+
};
|
|
10
|
+
var contentTypeFormMultipart = function (headerData) {
|
|
11
|
+
headerData['Content-Type'] = 'multipart/form-data';
|
|
12
|
+
return headerData;
|
|
13
|
+
};
|
|
14
|
+
var contentTypeJson = function (headerData) {
|
|
15
|
+
headerData['Content-Type'] = 'application/json; charset=utf-8';
|
|
16
|
+
return headerData;
|
|
17
|
+
};
|
|
18
|
+
var bearerToken = function (headerData, token) {
|
|
19
|
+
if (token) {
|
|
20
|
+
headerData.Authorization = "Bearer ".concat(token);
|
|
21
|
+
}
|
|
22
|
+
return headerData;
|
|
23
|
+
};
|
|
24
|
+
export var headerPipe = {
|
|
25
|
+
acceptContentType: acceptContentType,
|
|
26
|
+
contentTypeFormPost: contentTypeFormPost,
|
|
27
|
+
contentTypeFormMultipart: contentTypeFormMultipart,
|
|
28
|
+
contentTypeJson: contentTypeJson,
|
|
29
|
+
bearerToken: bearerToken,
|
|
30
|
+
};
|
|
31
|
+
export var createHttpHeaderProvider = function (tokenProvider) {
|
|
32
|
+
return function () {
|
|
33
|
+
var pipes = [];
|
|
34
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
35
|
+
pipes[_i] = arguments[_i];
|
|
36
|
+
}
|
|
37
|
+
var token = '';
|
|
38
|
+
if (tokenProvider) {
|
|
39
|
+
token = tokenProvider.get();
|
|
40
|
+
if (!token && !isServer()) {
|
|
41
|
+
throw new Error('로그인 상태가 만료 되었습니다.\n다시 로그인 하여 주시기 바랍니다.');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return pipes.reduce(function (prev, fn) { return fn(prev, token); }, {});
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
export var axiosResponseToData = function (axiosRes) {
|
|
3
|
+
return axiosRes.data;
|
|
4
|
+
};
|
|
5
|
+
export function axiosCreateHeader(headerProvider) {
|
|
6
|
+
return {
|
|
7
|
+
common: headerProvider(),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export var throwNewErrorForLib = function (parserVisitor) {
|
|
11
|
+
return function (anyError) {
|
|
12
|
+
var newError = parserVisitor.parse(anyError);
|
|
13
|
+
return parserVisitor.interrupt(newError).then(function () {
|
|
14
|
+
throw newError;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export var axiosUploadCommon = function (baseUrl, parserVisitor, headerProvider, withCredentials) {
|
|
19
|
+
if (withCredentials === void 0) { withCredentials = true; }
|
|
20
|
+
return function (method, url, data, progCallback, timeout) {
|
|
21
|
+
try {
|
|
22
|
+
var headers = axiosCreateHeader(headerProvider);
|
|
23
|
+
var fnCatchCommon = throwNewErrorForLib(parserVisitor);
|
|
24
|
+
return axios(baseUrl + url, {
|
|
25
|
+
data: data,
|
|
26
|
+
headers: headers,
|
|
27
|
+
method: method,
|
|
28
|
+
onUploadProgress: function (_a) {
|
|
29
|
+
var loaded = _a.loaded, total = _a.total;
|
|
30
|
+
var args = {
|
|
31
|
+
completed: loaded >= total,
|
|
32
|
+
loaded: loaded,
|
|
33
|
+
progress: Math.floor((loaded * 1000) / total) / 10,
|
|
34
|
+
total: total,
|
|
35
|
+
};
|
|
36
|
+
if (progCallback) {
|
|
37
|
+
progCallback(args);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
withCredentials: withCredentials,
|
|
41
|
+
timeout: timeout,
|
|
42
|
+
})
|
|
43
|
+
.then(axiosResponseToData)
|
|
44
|
+
.catch(fnCatchCommon);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return Promise.reject(error);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export function convertToFormData(data) {
|
|
52
|
+
var formData = new FormData();
|
|
53
|
+
var keys = Object.keys(data);
|
|
54
|
+
var key = '';
|
|
55
|
+
for (var i = 0; i < keys.length; i++) {
|
|
56
|
+
key = keys[i];
|
|
57
|
+
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
var value = data[key];
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
var len = value.length;
|
|
63
|
+
for (var idx = 0; idx < len; idx++) {
|
|
64
|
+
var file = value[idx];
|
|
65
|
+
formData.append(key, file, file.name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
formData.set(key, value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return formData;
|
|
73
|
+
}
|
package/esm5/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DeviceDetectProvider, withAdaptiveRender } from './adaptive-render';
|
|
2
|
+
import { createHttpApi, createHttpHeaderProvider, headerPipe, } from './http-api';
|
|
3
|
+
import { cache } from './proxies';
|
|
4
|
+
import { createGuardDispatch, createGuardSelector, renderRouteSystem, } from './route-system';
|
|
5
|
+
import validate, { mergeValidates, } from './validate';
|
|
6
|
+
export * from './queries';
|
|
7
|
+
export * from './storage';
|
|
8
|
+
export * from './hooks';
|
|
9
|
+
export * from './util';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export { DeviceDetectProvider, withAdaptiveRender, createHttpApi, headerPipe, createHttpHeaderProvider, cache, renderRouteSystem, createGuardDispatch, createGuardSelector, validate, mergeValidates, };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __spreadArray } from "tslib";
|
|
2
|
+
import { createStorage } from '../storage';
|
|
3
|
+
import { isServer } from '../util/envCheck';
|
|
4
|
+
var FORCE_NOT_CACHE = false;
|
|
5
|
+
function createKey(url, params) {
|
|
6
|
+
if (params) {
|
|
7
|
+
return "".concat(url, "-").concat(JSON.stringify(params));
|
|
8
|
+
}
|
|
9
|
+
return url;
|
|
10
|
+
}
|
|
11
|
+
export function cache(type, expiredTime) {
|
|
12
|
+
if (expiredTime === void 0) { expiredTime = 0; }
|
|
13
|
+
if (isServer() || FORCE_NOT_CACHE) {
|
|
14
|
+
return function (baseApi) {
|
|
15
|
+
return baseApi.get;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var cacheProxy = function (fn) {
|
|
19
|
+
return function (url, params) {
|
|
20
|
+
var storage = createStorage(type, createKey(url, params), expiredTime);
|
|
21
|
+
var value = storage.get();
|
|
22
|
+
if (value) {
|
|
23
|
+
return Promise.resolve(value);
|
|
24
|
+
}
|
|
25
|
+
return fn(url, params).then(function (data) {
|
|
26
|
+
storage.set(data);
|
|
27
|
+
return data;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
return function (baseApi) {
|
|
32
|
+
return cacheProxy(function () {
|
|
33
|
+
var args = [];
|
|
34
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
35
|
+
args[_i] = arguments[_i];
|
|
36
|
+
}
|
|
37
|
+
return baseApi.get.apply(baseApi, __spreadArray([], args, true));
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cache.proxy';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
function defineConverter(args) {
|
|
4
|
+
return args;
|
|
5
|
+
}
|
|
6
|
+
export function buildMutationCreator(store) {
|
|
7
|
+
var keyDic = {};
|
|
8
|
+
return function createRepositoryMutation(_a) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
var key = _a.key, mutator = _a.mutator, _b = _a.parameterConverter, parameterConverter = _b === void 0 ? defineConverter : _b, _c = _a.resultConverter, resultConverter = _c === void 0 ? defineConverter : _c;
|
|
11
|
+
if (key) {
|
|
12
|
+
if (keyDic[key]) {
|
|
13
|
+
console.warn("Mutation hooks key \"".concat(key, "\" already exists. Please change the key."));
|
|
14
|
+
}
|
|
15
|
+
keyDic[key] = true;
|
|
16
|
+
}
|
|
17
|
+
var resultHooks = function () {
|
|
18
|
+
var refFetching = useRef(false);
|
|
19
|
+
var _a = useState(null), data = _a[0], setData = _a[1];
|
|
20
|
+
var _b = useState(undefined), error = _b[0], setError = _b[1];
|
|
21
|
+
var _c = useState(false), loading = _c[0], setLoading = _c[1];
|
|
22
|
+
var mutate = useCallback(function (params, throwable) {
|
|
23
|
+
if (throwable === void 0) { throwable = false; }
|
|
24
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
25
|
+
var prm;
|
|
26
|
+
return __generator(this, function (_a) {
|
|
27
|
+
switch (_a.label) {
|
|
28
|
+
case 0:
|
|
29
|
+
if (refFetching.current) {
|
|
30
|
+
if (throwable) {
|
|
31
|
+
throw new Error('이미 수행 중입니다.');
|
|
32
|
+
}
|
|
33
|
+
return [2, false];
|
|
34
|
+
}
|
|
35
|
+
setError(undefined);
|
|
36
|
+
setLoading(true);
|
|
37
|
+
refFetching.current = true;
|
|
38
|
+
if (key) {
|
|
39
|
+
store.dispatch({ type: "MutationHooks/".concat(key, "/pending"), params: params });
|
|
40
|
+
}
|
|
41
|
+
prm = mutator(parameterConverter(params, store.getState));
|
|
42
|
+
return [4, prm
|
|
43
|
+
.then(function (res) {
|
|
44
|
+
var convertedData = resultConverter(res, store.getState);
|
|
45
|
+
if (key) {
|
|
46
|
+
store.dispatch({
|
|
47
|
+
type: "MutationHooks/".concat(key, "/fulfilled"),
|
|
48
|
+
params: params,
|
|
49
|
+
payload: convertedData,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
setData(convertedData);
|
|
53
|
+
setLoading(false);
|
|
54
|
+
refFetching.current = false;
|
|
55
|
+
return true;
|
|
56
|
+
})
|
|
57
|
+
.catch(function (err) {
|
|
58
|
+
if (key) {
|
|
59
|
+
store.dispatch({
|
|
60
|
+
type: "MutationHooks/".concat(key, "/rejected"),
|
|
61
|
+
params: params,
|
|
62
|
+
payload: err,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
setError(err);
|
|
66
|
+
setLoading(false);
|
|
67
|
+
refFetching.current = false;
|
|
68
|
+
if (throwable) {
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
})];
|
|
73
|
+
case 1: return [2, _a.sent()];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}, []);
|
|
78
|
+
return {
|
|
79
|
+
data: data,
|
|
80
|
+
error: error,
|
|
81
|
+
loading: loading,
|
|
82
|
+
mutate: mutate,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
return resultHooks;
|
|
86
|
+
};
|
|
87
|
+
}
|