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.
Files changed (128) hide show
  1. package/README.md +11 -0
  2. package/esm5/adaptive-render/AdaptiveRender.js +14 -0
  3. package/esm5/adaptive-render/DeviceDetectContext.js +62 -0
  4. package/esm5/adaptive-render/adaptive-render.type.js +1 -0
  5. package/esm5/adaptive-render/device.type.js +9 -0
  6. package/esm5/adaptive-render/index.js +4 -0
  7. package/esm5/adaptive-render/withAdaptiveRender.js +29 -0
  8. package/esm5/hooks/index.js +3 -0
  9. package/esm5/hooks/useDebounce.js +26 -0
  10. package/esm5/hooks/useQueryParams.js +20 -0
  11. package/esm5/hooks/useThrottle.js +18 -0
  12. package/esm5/http-api/httpApi.factory.js +143 -0
  13. package/esm5/http-api/httpHeader.factory.js +46 -0
  14. package/esm5/http-api/index.js +3 -0
  15. package/esm5/http-api/network.type.js +1 -0
  16. package/esm5/http-api/networkParser.js +73 -0
  17. package/esm5/index.js +11 -0
  18. package/esm5/proxies/cache.proxy.js +40 -0
  19. package/esm5/proxies/index.js +1 -0
  20. package/esm5/queries/buildMutationCreator.js +87 -0
  21. package/esm5/queries/buildQueryCreator.js +124 -0
  22. package/esm5/queries/index.js +2 -0
  23. package/esm5/queries/useMakeDeps.js +23 -0
  24. package/esm5/queries/utils/clearCacheByKeyword.js +50 -0
  25. package/esm5/queries/utils/createCacheKey.js +23 -0
  26. package/esm5/queries/utils/index.js +2 -0
  27. package/esm5/route-system/AsyncGuard.js +37 -0
  28. package/esm5/route-system/index.js +3 -0
  29. package/esm5/route-system/moduleRoute.model.js +1 -0
  30. package/esm5/route-system/renderRouteSystem.js +64 -0
  31. package/esm5/route-system/routeSystem.util.js +23 -0
  32. package/esm5/storage/CookieStorageAdapter.js +20 -0
  33. package/esm5/storage/ExpiableStorageAdapter.js +36 -0
  34. package/esm5/storage/MemorySimpleStorage.js +18 -0
  35. package/esm5/storage/SimpleStorageAdapter.js +18 -0
  36. package/esm5/storage/cookie.js +27 -0
  37. package/esm5/storage/index.js +4 -0
  38. package/esm5/storage/memoryStorage.js +35 -0
  39. package/esm5/storage/storage.factory.js +30 -0
  40. package/esm5/storage/storage.type.js +1 -0
  41. package/esm5/storage/token-provider.factory.js +23 -0
  42. package/esm5/types/component.type.js +1 -0
  43. package/esm5/types/index.js +2 -0
  44. package/esm5/types/marshalling.type.js +1 -0
  45. package/esm5/util/collection.js +17 -0
  46. package/esm5/util/envCheck.js +55 -0
  47. package/esm5/util/etc.js +12 -0
  48. package/esm5/util/filter.js +10 -0
  49. package/esm5/util/format.js +8 -0
  50. package/esm5/util/index.js +15 -0
  51. package/esm5/util/josa.js +57 -0
  52. package/esm5/util/json.js +19 -0
  53. package/esm5/util/libLoader.js +27 -0
  54. package/esm5/util/path.js +16 -0
  55. package/esm5/util/queryString.js +62 -0
  56. package/esm5/util/redux.js +6 -0
  57. package/esm5/util/template.js +65 -0
  58. package/esm5/util/typeCheck.js +33 -0
  59. package/esm5/validate/fn.js +66 -0
  60. package/esm5/validate/index.js +7 -0
  61. package/esm5/validate/mergeValidates.js +22 -0
  62. package/esm5/validate/validate.js +22 -0
  63. package/esm5/validate/validate.type.js +1 -0
  64. package/esm5/validate/validateSubUtils.js +67 -0
  65. package/libs/adaptive-render/AdaptiveRender.d.ts +25 -0
  66. package/libs/adaptive-render/DeviceDetectContext.d.ts +16 -0
  67. package/libs/adaptive-render/adaptive-render.type.d.ts +63 -0
  68. package/libs/adaptive-render/device.type.d.ts +14 -0
  69. package/libs/adaptive-render/index.d.ts +4 -0
  70. package/libs/adaptive-render/withAdaptiveRender.d.ts +35 -0
  71. package/libs/hooks/index.d.ts +3 -0
  72. package/libs/hooks/useDebounce.d.ts +29 -0
  73. package/libs/hooks/useQueryParams.d.ts +19 -0
  74. package/libs/hooks/useThrottle.d.ts +25 -0
  75. package/libs/http-api/httpApi.factory.d.ts +9 -0
  76. package/libs/http-api/httpHeader.factory.d.ts +15 -0
  77. package/libs/http-api/index.d.ts +3 -0
  78. package/libs/http-api/network.type.d.ts +109 -0
  79. package/libs/http-api/networkParser.d.ts +9 -0
  80. package/libs/index.d.ts +11 -0
  81. package/libs/proxies/cache.proxy.d.ts +11 -0
  82. package/libs/proxies/index.d.ts +1 -0
  83. package/libs/queries/buildMutationCreator.d.ts +37 -0
  84. package/libs/queries/buildQueryCreator.d.ts +115 -0
  85. package/libs/queries/index.d.ts +2 -0
  86. package/libs/queries/useMakeDeps.d.ts +1 -0
  87. package/libs/queries/utils/clearCacheByKeyword.d.ts +14 -0
  88. package/libs/queries/utils/createCacheKey.d.ts +1 -0
  89. package/libs/queries/utils/index.d.ts +2 -0
  90. package/libs/route-system/AsyncGuard.d.ts +8 -0
  91. package/libs/route-system/index.d.ts +3 -0
  92. package/libs/route-system/moduleRoute.model.d.ts +49 -0
  93. package/libs/route-system/renderRouteSystem.d.ts +5 -0
  94. package/libs/route-system/routeSystem.util.d.ts +4 -0
  95. package/libs/storage/CookieStorageAdapter.d.ts +11 -0
  96. package/libs/storage/ExpiableStorageAdapter.d.ts +11 -0
  97. package/libs/storage/MemorySimpleStorage.d.ts +10 -0
  98. package/libs/storage/SimpleStorageAdapter.d.ts +10 -0
  99. package/libs/storage/cookie.d.ts +2 -0
  100. package/libs/storage/index.d.ts +4 -0
  101. package/libs/storage/memoryStorage.d.ts +7 -0
  102. package/libs/storage/storage.factory.d.ts +31 -0
  103. package/libs/storage/storage.type.d.ts +96 -0
  104. package/libs/storage/token-provider.factory.d.ts +9 -0
  105. package/libs/types/component.type.d.ts +23 -0
  106. package/libs/types/index.d.ts +2 -0
  107. package/libs/types/marshalling.type.d.ts +5 -0
  108. package/libs/util/collection.d.ts +25 -0
  109. package/libs/util/envCheck.d.ts +56 -0
  110. package/libs/util/etc.d.ts +11 -0
  111. package/libs/util/filter.d.ts +2 -0
  112. package/libs/util/format.d.ts +6 -0
  113. package/libs/util/index.d.ts +15 -0
  114. package/libs/util/josa.d.ts +66 -0
  115. package/libs/util/json.d.ts +14 -0
  116. package/libs/util/libLoader.d.ts +1 -0
  117. package/libs/util/path.d.ts +20 -0
  118. package/libs/util/queryString.d.ts +35 -0
  119. package/libs/util/redux.d.ts +3 -0
  120. package/libs/util/template.d.ts +38 -0
  121. package/libs/util/typeCheck.d.ts +42 -0
  122. package/libs/validate/fn.d.ts +111 -0
  123. package/libs/validate/index.d.ts +58 -0
  124. package/libs/validate/mergeValidates.d.ts +21 -0
  125. package/libs/validate/validate.d.ts +2 -0
  126. package/libs/validate/validate.type.d.ts +84 -0
  127. package/libs/validate/validateSubUtils.d.ts +12 -0
  128. package/package.json +58 -0
@@ -0,0 +1,124 @@
1
+ import { __awaiter, __generator, __spreadArray } from "tslib";
2
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
3
+ import { createStorage } from '../storage';
4
+ import { useMakeDeps } from './useMakeDeps';
5
+ import { clearCacheByKeyword, createCacheKey } from './utils';
6
+ function defConverter(args) {
7
+ return args;
8
+ }
9
+ export function buildQueryCreator(store) {
10
+ var keyDic = {};
11
+ return function createRepositoryQuery(_a) {
12
+ var _this = this;
13
+ var key = _a.key, subKeysFromParams = _a.subKeysFromParams, _b = _a.cache, cacheType = _b === void 0 ? 'session' : _b, _c = _a.expired, expired = _c === void 0 ? 0 : _c, _d = _a.lazy, lazy = _d === void 0 ? false : _d, _e = _a.defaultLoading, defaultLoading = _e === void 0 ? false : _e, fetcher = _a.fetcher, defaultData = _a.defaultData, _f = _a.parameterConverter, parameterConverter = _f === void 0 ? defConverter : _f, _g = _a.resultConverter, resultConverter = _g === void 0 ? defConverter : _g;
14
+ if (key) {
15
+ if (keyDic[key]) {
16
+ console.warn("Query hooks key \"".concat(key, "\" already exists. Please change the key"));
17
+ }
18
+ keyDic[key] = true;
19
+ }
20
+ var resultHooks = function (requestParams) {
21
+ var refFetching = useRef(false);
22
+ var _a = useState(defaultData), data = _a[0], setData = _a[1];
23
+ var _b = useState(undefined), error = _b[0], setError = _b[1];
24
+ var _c = useState(defaultLoading), loading = _c[0], setLoading = _c[1];
25
+ var deps = useMakeDeps(requestParams, subKeysFromParams);
26
+ var loader = useCallback(function (params) { return __awaiter(_this, void 0, void 0, function () {
27
+ var sto, cachedValue, prm;
28
+ return __generator(this, function (_a) {
29
+ switch (_a.label) {
30
+ case 0:
31
+ if (refFetching.current) {
32
+ return [2];
33
+ }
34
+ sto = key && cacheType !== false
35
+ ? createStorage(cacheType, createCacheKey(key, params, subKeysFromParams), expired)
36
+ : null;
37
+ setError(undefined);
38
+ if (sto) {
39
+ cachedValue = sto.get();
40
+ if (cachedValue) {
41
+ if (key) {
42
+ store.dispatch({
43
+ type: "QueryHooks/".concat(key, "/cached"),
44
+ params: params,
45
+ payload: cachedValue,
46
+ });
47
+ }
48
+ setData(cachedValue);
49
+ setLoading(false);
50
+ return [2];
51
+ }
52
+ }
53
+ refFetching.current = true;
54
+ if (key) {
55
+ store.dispatch({
56
+ type: "QueryHooks/".concat(key, "/pending"),
57
+ params: params,
58
+ });
59
+ }
60
+ setLoading(true);
61
+ prm = fetcher(parameterConverter(params, store.getState));
62
+ return [4, prm
63
+ .then(function (res) {
64
+ var convertedData = resultConverter(res, store.getState, params);
65
+ if (key) {
66
+ store.dispatch({
67
+ type: "QueryHooks/".concat(key, "/fulfilled"),
68
+ params: params,
69
+ payload: convertedData,
70
+ });
71
+ }
72
+ if (sto) {
73
+ sto.set(convertedData);
74
+ }
75
+ setData(convertedData);
76
+ setLoading(false);
77
+ refFetching.current = false;
78
+ })
79
+ .catch(function (err) {
80
+ if (key) {
81
+ store.dispatch({
82
+ type: "QueryHooks/".concat(key, "/rejected"),
83
+ params: params,
84
+ payload: err,
85
+ });
86
+ }
87
+ setError(err);
88
+ setLoading(false);
89
+ refFetching.current = false;
90
+ })];
91
+ case 1:
92
+ _a.sent();
93
+ return [2];
94
+ }
95
+ });
96
+ }); }, []);
97
+ var clear = useCallback(function (removeCache) {
98
+ if (removeCache === void 0) { removeCache = true; }
99
+ setData(defaultData);
100
+ if (!removeCache ||
101
+ !key ||
102
+ cacheType === false ||
103
+ cacheType === 'cookie') {
104
+ return;
105
+ }
106
+ clearCacheByKeyword(cacheType, key);
107
+ }, [setData]);
108
+ useLayoutEffect(function () {
109
+ if (lazy) {
110
+ return;
111
+ }
112
+ loader(requestParams);
113
+ }, __spreadArray(__spreadArray([], deps, true), [lazy], false));
114
+ return {
115
+ data: data,
116
+ error: error,
117
+ loading: loading,
118
+ load: loader,
119
+ clear: clear,
120
+ };
121
+ };
122
+ return resultHooks;
123
+ };
124
+ }
@@ -0,0 +1,2 @@
1
+ export * from './buildMutationCreator';
2
+ export * from './buildQueryCreator';
@@ -0,0 +1,23 @@
1
+ import { useMemo } from 'react';
2
+ import { isObject } from '../util';
3
+ export function useMakeDeps(args, keys) {
4
+ var subKeys = useMemo(function () {
5
+ if (keys) {
6
+ return keys;
7
+ }
8
+ if (!args) {
9
+ return [];
10
+ }
11
+ return Object.keys(args);
12
+ }, [keys]);
13
+ var deps = useMemo(function () {
14
+ if (isObject(args)) {
15
+ return subKeys.map(function (subKey) { return args[subKey]; });
16
+ }
17
+ if (Array.isArray(args)) {
18
+ return args;
19
+ }
20
+ return [args];
21
+ }, [args]);
22
+ return deps;
23
+ }
@@ -0,0 +1,50 @@
1
+ import { memoryStorage } from '../../storage';
2
+ function getStorage(type) {
3
+ if (type === 'session') {
4
+ return sessionStorage;
5
+ }
6
+ if (type === 'local') {
7
+ return localStorage;
8
+ }
9
+ return memoryStorage;
10
+ }
11
+ var findRelatedKeyCurried = function (key) { return function (keyword) {
12
+ return key.indexOf(keyword) >= 0;
13
+ }; };
14
+ function findAllRelatedKeyFromStorage(sto, keyword) {
15
+ var key = null;
16
+ var keyList = [];
17
+ var len = sto.length;
18
+ if (len === 0) {
19
+ return keyList;
20
+ }
21
+ if (Array.isArray(keyword)) {
22
+ for (var keyIdx = 0; keyIdx < len; keyIdx++) {
23
+ key = sto.key(keyIdx);
24
+ if (key && keyword.find(findRelatedKeyCurried(key))) {
25
+ keyList.push(key);
26
+ }
27
+ }
28
+ }
29
+ else {
30
+ for (var keyIdx = 0; keyIdx < len; keyIdx++) {
31
+ key = sto.key(keyIdx);
32
+ if (key && key.indexOf(keyword) >= 0) {
33
+ keyList.push(key);
34
+ }
35
+ }
36
+ }
37
+ return keyList;
38
+ }
39
+ export function clearCacheByKeyword(type, keyword, storageGetter) {
40
+ if (storageGetter === void 0) { storageGetter = getStorage; }
41
+ var sto = storageGetter(type);
42
+ var keyList = findAllRelatedKeyFromStorage(sto, keyword);
43
+ if (keyList.length === 0) {
44
+ return 0;
45
+ }
46
+ for (var index = 0; index < keyList.length; index++) {
47
+ sto.removeItem(keyList[index]);
48
+ }
49
+ return keyList.length;
50
+ }
@@ -0,0 +1,23 @@
1
+ import { isNumber, isObject, isString } from '../../util';
2
+ export function createCacheKey(key, params, subKeys) {
3
+ if (isObject(params)) {
4
+ var appendedValues = void 0;
5
+ if (subKeys) {
6
+ appendedValues = subKeys.reduce(function (acc, currKey) {
7
+ acc.push(createCacheKey(currKey, params[currKey]));
8
+ return acc;
9
+ }, [key]);
10
+ }
11
+ else {
12
+ appendedValues = Object.entries(params).reduce(function (acc, item) {
13
+ acc.push(createCacheKey(item[0], item[1]));
14
+ return acc;
15
+ }, [key]);
16
+ }
17
+ return appendedValues.join('-');
18
+ }
19
+ if (params && (isString(params) || isNumber(params))) {
20
+ return "".concat(key, "-").concat(params);
21
+ }
22
+ return key;
23
+ }
@@ -0,0 +1,2 @@
1
+ export * from './clearCacheByKeyword';
2
+ export * from './createCacheKey';
@@ -0,0 +1,37 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { useHistory } from 'react-router';
3
+ import { noop } from '../util';
4
+ export var AsyncGuard = function (_a) {
5
+ var _b = _a.redirect, redirect = _b === void 0 ? '/' : _b, FailComp = _a.failComponent, guard = _a.guard, children = _a.children;
6
+ var history = useHistory();
7
+ var _c = useState(guard ? null : true), end = _c[0], setEnd = _c[1];
8
+ useEffect(function () {
9
+ if (end || !guard) {
10
+ return noop;
11
+ }
12
+ var handleAsync = function (res) {
13
+ if (res) {
14
+ setEnd(true);
15
+ return;
16
+ }
17
+ if (FailComp) {
18
+ setEnd(false);
19
+ }
20
+ else {
21
+ history.replace(redirect);
22
+ }
23
+ };
24
+ Promise.resolve(0)
25
+ .then(guard)
26
+ .then(handleAsync)
27
+ .catch(function () { return handleAsync(false); });
28
+ return noop;
29
+ }, [end, FailComp, history, redirect, guard]);
30
+ if (end === false && FailComp) {
31
+ return React.createElement(FailComp, null);
32
+ }
33
+ if (!end) {
34
+ return null;
35
+ }
36
+ return React.createElement(React.Fragment, null, children);
37
+ };
@@ -0,0 +1,3 @@
1
+ export * from './renderRouteSystem';
2
+ export * from './moduleRoute.model';
3
+ export * from './routeSystem.util';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ import { __spreadArray } from "tslib";
2
+ import React, { Suspense } from 'react';
3
+ import { Redirect, Route, Switch } from 'react-router-dom';
4
+ import { AsyncGuard } from './AsyncGuard';
5
+ function toPromiseList(guardList) {
6
+ return guardList.map(function (fn) {
7
+ var ret = fn();
8
+ if (ret instanceof Promise) {
9
+ return ret;
10
+ }
11
+ return Promise.resolve(ret);
12
+ });
13
+ }
14
+ function renderSubRoute(route, notFound, guardList) {
15
+ if (guardList === void 0) { guardList = []; }
16
+ var Comp = route.component;
17
+ var Wrap = route.wrap || React.Fragment;
18
+ if (route.guard) {
19
+ guardList.push(route.guard);
20
+ if (route.child) {
21
+ return (React.createElement(Wrap, null, renderRouteSystem(route.child, true, notFound, __spreadArray([], guardList, true))));
22
+ }
23
+ var guardResults = function () {
24
+ return Promise.all(toPromiseList(guardList)).then(function (items) {
25
+ return items.every(Boolean);
26
+ });
27
+ };
28
+ return (React.createElement(Wrap, null,
29
+ React.createElement(Suspense, { fallback: React.createElement(React.Fragment, null) },
30
+ React.createElement(AsyncGuard, { guard: guardResults, redirect: route.redirect, failComponent: route.failComponent }, Comp && React.createElement(Comp, null)))));
31
+ }
32
+ if (route.redirect) {
33
+ return React.createElement(Redirect, { to: route.redirect });
34
+ }
35
+ if (route.child) {
36
+ return (React.createElement(Wrap, null, renderRouteSystem(route.child, true, notFound, __spreadArray([], guardList, true))));
37
+ }
38
+ if (guardList.length > 0) {
39
+ var guardResults = function () {
40
+ return Promise.all(toPromiseList(guardList)).then(function (items) {
41
+ return items.every(Boolean);
42
+ });
43
+ };
44
+ return (React.createElement(Wrap, null,
45
+ React.createElement(Suspense, { fallback: React.createElement(React.Fragment, null) },
46
+ React.createElement(AsyncGuard, { guard: guardResults, redirect: route.redirect, failComponent: route.failComponent }, Comp && React.createElement(Comp, null)))));
47
+ }
48
+ return (React.createElement(Wrap, null,
49
+ React.createElement(Suspense, { fallback: React.createElement(React.Fragment, null) }, Comp && React.createElement(Comp, null))));
50
+ }
51
+ export var renderRouteSystem = function (routes, withSwitch, notFound, guardList) {
52
+ if (guardList === void 0) { guardList = []; }
53
+ var NotFound = notFound;
54
+ if (withSwitch) {
55
+ return (React.createElement(Switch, null,
56
+ routes.map(function (route) { return (React.createElement(Route, { key: route.path, path: route.path, exact: route.exact }, renderSubRoute(route, notFound, __spreadArray([], guardList, true)))); }),
57
+ NotFound && React.createElement(NotFound, null)));
58
+ }
59
+ var renders = routes.map(function (route) { return (React.createElement(Route, { key: route.path, path: route.path, exact: route.exact }, renderSubRoute(route, notFound, __spreadArray([], guardList, true)))); });
60
+ if (NotFound) {
61
+ renders.push(React.createElement(NotFound, { key: "%%not-found%%" }));
62
+ }
63
+ return renders;
64
+ };
@@ -0,0 +1,23 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ export function createGuardDispatch(store) {
3
+ return function guardDispatch(effectResult) {
4
+ return __awaiter(this, void 0, void 0, function () {
5
+ var dispatch, action;
6
+ return __generator(this, function (_a) {
7
+ switch (_a.label) {
8
+ case 0:
9
+ dispatch = store.dispatch;
10
+ return [4, dispatch(effectResult)];
11
+ case 1:
12
+ action = _a.sent();
13
+ return [2, action.meta.requestStatus === 'fulfilled'];
14
+ }
15
+ });
16
+ });
17
+ };
18
+ }
19
+ export function createGuardSelector(store) {
20
+ return function guardSelector(selector) {
21
+ return selector(store.getState());
22
+ };
23
+ }
@@ -0,0 +1,20 @@
1
+ import { marshalJson, unmarshalJson } from '../util';
2
+ var CookieStorageAdapter = (function () {
3
+ function CookieStorageAdapter(cookie, key, expiredTime) {
4
+ if (expiredTime === void 0) { expiredTime = 0; }
5
+ this.cookie = cookie;
6
+ this.key = key;
7
+ this.expiredTime = expiredTime;
8
+ }
9
+ CookieStorageAdapter.prototype.get = function () {
10
+ return unmarshalJson(this.cookie.get(this.key));
11
+ };
12
+ CookieStorageAdapter.prototype.set = function (value) {
13
+ this.cookie.set(this.key, marshalJson(value), this.expiredTime);
14
+ };
15
+ CookieStorageAdapter.prototype.remove = function () {
16
+ this.cookie.remove(this.key);
17
+ };
18
+ return CookieStorageAdapter;
19
+ }());
20
+ export { CookieStorageAdapter };
@@ -0,0 +1,36 @@
1
+ var ExpiableStorageAdapter = (function () {
2
+ function ExpiableStorageAdapter(storage, expiredTime) {
3
+ if (expiredTime === void 0) { expiredTime = 0; }
4
+ this.storage = storage;
5
+ this.expiredTime = expiredTime;
6
+ }
7
+ Object.defineProperty(ExpiableStorageAdapter.prototype, "key", {
8
+ get: function () {
9
+ return this.storage.key;
10
+ },
11
+ enumerable: false,
12
+ configurable: true
13
+ });
14
+ ExpiableStorageAdapter.prototype.get = function () {
15
+ var mData = this.storage.get();
16
+ if (!mData) {
17
+ return null;
18
+ }
19
+ if (mData.expiredTime <= 0 || mData.expiredTime > Date.now()) {
20
+ return mData.data;
21
+ }
22
+ this.storage.remove();
23
+ return null;
24
+ };
25
+ ExpiableStorageAdapter.prototype.set = function (value) {
26
+ this.storage.set({
27
+ data: value,
28
+ expiredTime: this.expiredTime > 0 ? Date.now() + this.expiredTime * 1000 : 0,
29
+ });
30
+ };
31
+ ExpiableStorageAdapter.prototype.remove = function () {
32
+ this.storage.remove();
33
+ };
34
+ return ExpiableStorageAdapter;
35
+ }());
36
+ export { ExpiableStorageAdapter };
@@ -0,0 +1,18 @@
1
+ import { memoryStorage } from './memoryStorage';
2
+ var MemorySimpleStorage = (function () {
3
+ function MemorySimpleStorage(key) {
4
+ this.key = key;
5
+ this.storage = memoryStorage;
6
+ }
7
+ MemorySimpleStorage.prototype.get = function () {
8
+ return (this.storage.getItem(this.key) || null);
9
+ };
10
+ MemorySimpleStorage.prototype.set = function (value) {
11
+ this.storage.setItem(this.key, value);
12
+ };
13
+ MemorySimpleStorage.prototype.remove = function () {
14
+ this.storage.removeItem(this.key);
15
+ };
16
+ return MemorySimpleStorage;
17
+ }());
18
+ export { MemorySimpleStorage };
@@ -0,0 +1,18 @@
1
+ import { marshalJson, unmarshalJson } from '../util';
2
+ var SimpleStorageAdapter = (function () {
3
+ function SimpleStorageAdapter(key, storage) {
4
+ this.key = key;
5
+ this.storage = storage;
6
+ }
7
+ SimpleStorageAdapter.prototype.get = function () {
8
+ return unmarshalJson(this.storage.getItem(this.key));
9
+ };
10
+ SimpleStorageAdapter.prototype.set = function (value) {
11
+ this.storage.setItem(this.key, marshalJson(value));
12
+ };
13
+ SimpleStorageAdapter.prototype.remove = function () {
14
+ this.storage.removeItem(this.key);
15
+ };
16
+ return SimpleStorageAdapter;
17
+ }());
18
+ export { SimpleStorageAdapter };
@@ -0,0 +1,27 @@
1
+ export var cookie = {
2
+ set: function (key, value, expireDays) {
3
+ if (expireDays === void 0) { expireDays = 1; }
4
+ var d = new Date();
5
+ d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
6
+ var expires = 'expires=' + d.toUTCString();
7
+ document.cookie = key + '=' + value + ';' + expires + ';path=/';
8
+ },
9
+ get: function (key) {
10
+ var name = key + '=';
11
+ var decodedCookie = decodeURIComponent(document.cookie);
12
+ var ca = decodedCookie.split(';');
13
+ for (var i = 0; i < ca.length; i++) {
14
+ var c = ca[i];
15
+ while (c.charAt(0) == ' ') {
16
+ c = c.substring(1);
17
+ }
18
+ if (c.indexOf(name) == 0) {
19
+ return c.substring(name.length, c.length);
20
+ }
21
+ }
22
+ return '';
23
+ },
24
+ remove: function (key) {
25
+ document.cookie = key + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;';
26
+ },
27
+ };
@@ -0,0 +1,4 @@
1
+ export * from './storage.factory';
2
+ export * from './token-provider.factory';
3
+ export * from './storage.type';
4
+ export * from './memoryStorage';
@@ -0,0 +1,35 @@
1
+ var MemoryStorageImpl = (function () {
2
+ function MemoryStorageImpl() {
3
+ this.cacheMap = new Map();
4
+ this.keys = [];
5
+ }
6
+ Object.defineProperty(MemoryStorageImpl.prototype, "length", {
7
+ get: function () {
8
+ return this.cacheMap.size;
9
+ },
10
+ enumerable: false,
11
+ configurable: true
12
+ });
13
+ MemoryStorageImpl.prototype.clear = function () {
14
+ this.cacheMap.clear();
15
+ this.keys = [];
16
+ };
17
+ MemoryStorageImpl.prototype.getItem = function (key) {
18
+ return this.cacheMap.get(key);
19
+ };
20
+ MemoryStorageImpl.prototype.key = function (index) {
21
+ return this.keys[index] || null;
22
+ };
23
+ MemoryStorageImpl.prototype.removeItem = function (key) {
24
+ this.cacheMap.delete(key);
25
+ this.keys = this.keys.filter(function (item) { return item !== key; });
26
+ };
27
+ MemoryStorageImpl.prototype.setItem = function (key, value) {
28
+ if (this.cacheMap.has(key) === false) {
29
+ this.keys.push(key);
30
+ }
31
+ this.cacheMap.set(key, value);
32
+ };
33
+ return MemoryStorageImpl;
34
+ }());
35
+ export var memoryStorage = new MemoryStorageImpl();
@@ -0,0 +1,30 @@
1
+ import { CookieStorageAdapter } from './CookieStorageAdapter';
2
+ import { ExpiableStorageAdapter } from './ExpiableStorageAdapter';
3
+ import { MemorySimpleStorage } from './MemorySimpleStorage';
4
+ import { SimpleStorageAdapter } from './SimpleStorageAdapter';
5
+ import { cookie } from './cookie';
6
+ import { isServer, isStorageAvailable } from '../util/envCheck';
7
+ export var createStorage = function (type, key, expiredTime) {
8
+ if (type === void 0) { type = 'session'; }
9
+ if (key === void 0) { key = '_'; }
10
+ if (expiredTime === void 0) { expiredTime = 0; }
11
+ var ret;
12
+ if (type !== 'cookie' && expiredTime > 0) {
13
+ return new ExpiableStorageAdapter(createStorage(type, key), expiredTime);
14
+ }
15
+ if (isServer() || !isStorageAvailable() || type === 'memory') {
16
+ ret = new MemorySimpleStorage(key);
17
+ }
18
+ else if (type === 'cookie') {
19
+ ret = new CookieStorageAdapter(cookie, key, expiredTime);
20
+ }
21
+ else {
22
+ try {
23
+ ret = new SimpleStorageAdapter(key, type === 'local' ? localStorage : sessionStorage);
24
+ }
25
+ catch (error) {
26
+ ret = new MemorySimpleStorage(key);
27
+ }
28
+ }
29
+ return ret;
30
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { createStorage } from './storage.factory';
2
+ var StorageTokenProvider = (function () {
3
+ function StorageTokenProvider(storage) {
4
+ this.storage = storage;
5
+ this._token = '';
6
+ this._token = this.storage.get() || '';
7
+ }
8
+ StorageTokenProvider.prototype.get = function () {
9
+ return this.storage.get() || '';
10
+ };
11
+ StorageTokenProvider.prototype.set = function (token) {
12
+ this._token = token;
13
+ this.storage.set(token);
14
+ };
15
+ StorageTokenProvider.prototype.clear = function () {
16
+ this._token = '';
17
+ this.storage.remove();
18
+ };
19
+ return StorageTokenProvider;
20
+ }());
21
+ export function createTokenProvider(type, key, expiredTime) {
22
+ return new StorageTokenProvider(createStorage(type, key, expiredTime));
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './component.type';
2
+ export * from './marshalling.type';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { __spreadArray } from "tslib";
2
+ export function reorder(list, startIndex, endIndex) {
3
+ var result = __spreadArray([], list, true);
4
+ var removed = result.splice(startIndex, 1)[0];
5
+ result.splice(endIndex, 0, removed);
6
+ return result;
7
+ }
8
+ export function update(list, index, item) {
9
+ var copied = __spreadArray([], list, true);
10
+ copied[index] = item;
11
+ return copied;
12
+ }
13
+ export function remove(list, index) {
14
+ var copied = __spreadArray([], list, true);
15
+ copied.splice(index, 1);
16
+ return copied;
17
+ }