jordy 0.19.0 → 0.20.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/esm5/cache/cache.js +27 -0
- package/esm5/cache/cache.type.js +1 -0
- package/esm5/cache/clearAllCachesExceptBy.js +37 -0
- package/esm5/{queries/utils → cache}/clearCacheByKeyword.js +1 -1
- package/esm5/{queries/utils → cache}/createCacheKey.js +1 -1
- package/esm5/cache/index.js +5 -0
- package/esm5/hooks/index.js +2 -1
- package/esm5/{queries → hooks}/useMakeDeps.js +0 -0
- package/esm5/index.js +2 -2
- package/esm5/queries/buildQueryCreator.js +2 -2
- package/esm5/storage/index.js +2 -2
- package/libs/cache/cache.d.ts +27 -0
- package/libs/cache/cache.type.d.ts +26 -0
- package/libs/cache/clearAllCachesExceptBy.d.ts +23 -0
- package/libs/{queries/utils → cache}/clearCacheByKeyword.d.ts +5 -3
- package/libs/cache/createCacheKey.d.ts +11 -0
- package/libs/cache/index.d.ts +5 -0
- package/libs/hooks/index.d.ts +2 -1
- package/libs/{queries → hooks}/useMakeDeps.d.ts +0 -0
- package/libs/index.d.ts +2 -2
- package/libs/storage/index.d.ts +2 -2
- package/package.json +1 -1
- package/esm5/proxies/cache.proxy.js +0 -40
- package/esm5/proxies/index.js +0 -1
- package/esm5/queries/utils/index.js +0 -2
- package/libs/proxies/cache.proxy.d.ts +0 -11
- package/libs/proxies/index.d.ts +0 -1
- package/libs/queries/utils/createCacheKey.d.ts +0 -1
- package/libs/queries/utils/index.d.ts +0 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { createStorage } from '../storage/createStorage.factory';
|
|
3
|
+
import { createCacheKey } from './createCacheKey';
|
|
4
|
+
export function cache(_a) {
|
|
5
|
+
var key = _a.key, _b = _a.type, type = _b === void 0 ? 'session' : _b, expired = _a.expired, fetcher = _a.fetcher;
|
|
6
|
+
var resultFetcher = function fetcherProxy(params) {
|
|
7
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
8
|
+
var sto, cachedData, newResult;
|
|
9
|
+
return __generator(this, function (_a) {
|
|
10
|
+
switch (_a.label) {
|
|
11
|
+
case 0:
|
|
12
|
+
sto = createStorage(type, createCacheKey(key, params), expired);
|
|
13
|
+
cachedData = sto.get();
|
|
14
|
+
if (cachedData) {
|
|
15
|
+
return [2, cachedData];
|
|
16
|
+
}
|
|
17
|
+
return [4, fetcher(params)];
|
|
18
|
+
case 1:
|
|
19
|
+
newResult = _a.sent();
|
|
20
|
+
sto.set(newResult);
|
|
21
|
+
return [2, newResult];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return resultFetcher;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { memoryStorage } from '../storage/memoryStorage';
|
|
2
|
+
var findRelatedKeyCurried = function (key) { return function (keyword) {
|
|
3
|
+
return key.indexOf(keyword) >= 0;
|
|
4
|
+
}; };
|
|
5
|
+
function findAllKeysExcepts(sto, keywords) {
|
|
6
|
+
var key = null;
|
|
7
|
+
var keyList = [];
|
|
8
|
+
var len = sto.length;
|
|
9
|
+
for (var keyIdx = 0; keyIdx < len; keyIdx++) {
|
|
10
|
+
key = sto.key(keyIdx);
|
|
11
|
+
if (key && !keywords.find(findRelatedKeyCurried(key))) {
|
|
12
|
+
keyList.push(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return keyList;
|
|
16
|
+
}
|
|
17
|
+
function getStorage(type) {
|
|
18
|
+
if (type === 'session') {
|
|
19
|
+
return sessionStorage;
|
|
20
|
+
}
|
|
21
|
+
if (type === 'local') {
|
|
22
|
+
return localStorage;
|
|
23
|
+
}
|
|
24
|
+
return memoryStorage;
|
|
25
|
+
}
|
|
26
|
+
export function clearAllCachesExceptBy(type, keywords, storageGetter) {
|
|
27
|
+
if (storageGetter === void 0) { storageGetter = getStorage; }
|
|
28
|
+
var sto = storageGetter(type);
|
|
29
|
+
var keyList = findAllKeysExcepts(sto, keywords);
|
|
30
|
+
if (keyList.length === 0) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
for (var index = 0; index < keyList.length; index++) {
|
|
34
|
+
sto.removeItem(keyList[index]);
|
|
35
|
+
}
|
|
36
|
+
return keyList.length;
|
|
37
|
+
}
|
package/esm5/hooks/index.js
CHANGED
|
File without changes
|
package/esm5/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative, } from './adaptive-render';
|
|
2
|
-
import { cache } from './proxies';
|
|
3
2
|
import { useRouteSystem } from './route-system';
|
|
3
|
+
export * from './cache';
|
|
4
4
|
export * from './http-api';
|
|
5
5
|
export * from './hooks';
|
|
6
6
|
export * from './queries';
|
|
@@ -9,4 +9,4 @@ export * from './types';
|
|
|
9
9
|
export * from './util';
|
|
10
10
|
export * from './jwt';
|
|
11
11
|
export * from './validate';
|
|
12
|
-
export { DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative,
|
|
12
|
+
export { DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative, useRouteSystem, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
2
|
+
import { createCacheKey, clearCacheByKeyword } from '../cache';
|
|
2
3
|
import { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
3
4
|
import { createStorage } from '../storage';
|
|
4
|
-
import { useMakeDeps } from '
|
|
5
|
-
import { clearCacheByKeyword, createCacheKey } from './utils';
|
|
5
|
+
import { useMakeDeps } from '../hooks/useMakeDeps';
|
|
6
6
|
function defConverter(args) {
|
|
7
7
|
return args;
|
|
8
8
|
}
|
package/esm5/storage/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export * from './MemorySimpleStorage';
|
|
|
4
4
|
export * from './SimpleStorageAdapter';
|
|
5
5
|
export * from './StorageTokenProvider';
|
|
6
6
|
export * from './cookie';
|
|
7
|
-
export * from './memoryStorage';
|
|
8
7
|
export * from './createStorage.factory';
|
|
9
|
-
export * from './storage.type';
|
|
10
8
|
export * from './createTokenProvider.factory';
|
|
9
|
+
export * from './memoryStorage';
|
|
10
|
+
export * from './storage.type';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CacheConfigDto } from './cache.type';
|
|
2
|
+
/**
|
|
3
|
+
* 데이터를 가져오는 비동기 함수에 대해 그 결과값을 일정시간동안 캐싱하는 비동기 함수를 만든다.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```
|
|
7
|
+
* // 선언
|
|
8
|
+
* const cachedFetchJordyDashboard = cache({
|
|
9
|
+
* key: 'jordy_dashboard',
|
|
10
|
+
* type: 'memory',
|
|
11
|
+
* expired: 60 * 3,
|
|
12
|
+
* fetcher: repo.jordy.fetchDashboard,
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // 사용
|
|
16
|
+
* async function main() {
|
|
17
|
+
* const params = { date: Date.now(), page: 1 };
|
|
18
|
+
* const result = await cachedFetchJordyDashboard(params);
|
|
19
|
+
*
|
|
20
|
+
* console.log(result);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param {CacheConfigDto} config 캐시 설정
|
|
25
|
+
* @returns 캐시 기능이 적용된 비동기 함수
|
|
26
|
+
*/
|
|
27
|
+
export declare function cache<R, P = void>({ key, type, expired, fetcher, }: CacheConfigDto<R, P>): (params: P) => Promise<R>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StorageType } from 'packages/storage/storage.type';
|
|
2
|
+
export declare type LargeStorageType = Exclude<StorageType, 'cookie'>;
|
|
3
|
+
export interface CacheConfigDto<R, P> {
|
|
4
|
+
/**
|
|
5
|
+
* 캐시 고유키
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
/**
|
|
9
|
+
* 캐시 종류 선택.
|
|
10
|
+
*
|
|
11
|
+
* @default 'session'
|
|
12
|
+
*/
|
|
13
|
+
type?: LargeStorageType;
|
|
14
|
+
/**
|
|
15
|
+
* 캐시 유효기간 설정. (seconds)
|
|
16
|
+
*
|
|
17
|
+
* 0 혹은 설정하지 않으면 기한이 없다.
|
|
18
|
+
*
|
|
19
|
+
* @default 0
|
|
20
|
+
*/
|
|
21
|
+
expired?: number;
|
|
22
|
+
/**
|
|
23
|
+
* 데이터 가져오기를 실제 수행 할 함수.
|
|
24
|
+
*/
|
|
25
|
+
fetcher: (params: P) => Promise<R>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StorageKeyManager } from '../storage/storage.type';
|
|
2
|
+
import { LargeStorageType } from './cache.type';
|
|
3
|
+
declare function getStorage(type: LargeStorageType): StorageKeyManager;
|
|
4
|
+
/**
|
|
5
|
+
* 제시된 키워드가 포함되지 않은 캐시들을 모두 제거한다.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* clearAllCachesExceptBy(
|
|
10
|
+
* 'local', // 로컬 스토리지 대상 예시
|
|
11
|
+
* ['jordy', 'theson', 'lookpin'], // 삭제 시 제외할 키워드들
|
|
12
|
+
* );
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param type 지울 대상. local or session or memory
|
|
16
|
+
* @param keywords 제외할 키워드
|
|
17
|
+
* @param storageGetter 대상이되는 스토리지 함수. 테스트 용도가 아니면 별도로 지정하지 않음.
|
|
18
|
+
* @returns 지워진 모든 캐시 개수
|
|
19
|
+
*
|
|
20
|
+
* @see clearCacheByKeyword - 지정된 키워드들에 한해서만 캐시를 지움.
|
|
21
|
+
*/
|
|
22
|
+
export declare function clearAllCachesExceptBy(type: LargeStorageType, keywords: string[], storageGetter?: typeof getStorage): number;
|
|
23
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StorageKeyManager
|
|
2
|
-
|
|
1
|
+
import { StorageKeyManager } from '../storage/storage.type';
|
|
2
|
+
import { LargeStorageType } from './cache.type';
|
|
3
3
|
declare function getStorage(type: LargeStorageType): StorageKeyManager;
|
|
4
4
|
/**
|
|
5
5
|
* 캐시를 제거한다.
|
|
@@ -8,7 +8,9 @@ declare function getStorage(type: LargeStorageType): StorageKeyManager;
|
|
|
8
8
|
*
|
|
9
9
|
* @param type 캐시 타입 (쿠키 제외)
|
|
10
10
|
* @param keyword 삭제 대상이 되는 키워드
|
|
11
|
-
* @returns
|
|
11
|
+
* @returns 지워진 캐시 개수
|
|
12
|
+
*
|
|
13
|
+
* @see clearAllCachesExceptBy - 지정된 키워드 외의 모든 캐시를 지움.
|
|
12
14
|
*/
|
|
13
15
|
export declare function clearCacheByKeyword(type: LargeStorageType, keyword: string | string[], storageGetter?: typeof getStorage): number;
|
|
14
16
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 키와 파라미터를 조합하여 키값을 만든다.
|
|
3
|
+
*
|
|
4
|
+
* 이 함수는 각종 캐시 제어 기능에 쓰인다.
|
|
5
|
+
*
|
|
6
|
+
* @param key 기반이 되는 키값
|
|
7
|
+
* @param params 조합될 1차 파라미터값. 객체일 경우 그 키와 값을 직렬화 하여 사용, 아닐경우 그 값 자체로 사용.
|
|
8
|
+
* @param subKeys params 에서 사용될 키를 지정한다. 미 지정 시 params 의 모든 키를 대상으로 키값을 만든다.
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCacheKey<P>(key: string, params?: P, subKeys?: Array<keyof P>): string;
|
package/libs/hooks/index.d.ts
CHANGED
|
File without changes
|
package/libs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative } from './adaptive-render';
|
|
2
|
-
import { cache } from './proxies';
|
|
3
2
|
import { ModuleRouteModel, useRouteSystem } from './route-system';
|
|
3
|
+
export * from './cache';
|
|
4
4
|
export * from './http-api';
|
|
5
5
|
export * from './hooks';
|
|
6
6
|
export * from './queries';
|
|
@@ -9,4 +9,4 @@ export * from './types';
|
|
|
9
9
|
export * from './util';
|
|
10
10
|
export * from './jwt';
|
|
11
11
|
export * from './validate';
|
|
12
|
-
export { ModuleRouteModel, DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative,
|
|
12
|
+
export { ModuleRouteModel, DeviceDetectProvider, withAdaptiveRender, useIsMobile, useIsTablet, useIsNative, useRouteSystem, };
|
package/libs/storage/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './MemorySimpleStorage';
|
|
|
4
4
|
export * from './SimpleStorageAdapter';
|
|
5
5
|
export * from './StorageTokenProvider';
|
|
6
6
|
export * from './cookie';
|
|
7
|
-
export * from './memoryStorage';
|
|
8
7
|
export * from './createStorage.factory';
|
|
9
|
-
export * from './storage.type';
|
|
10
8
|
export * from './createTokenProvider.factory';
|
|
9
|
+
export * from './memoryStorage';
|
|
10
|
+
export * from './storage.type';
|
package/package.json
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { __read, __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([], __read(args), false));
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
}
|
package/esm5/proxies/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './cache.proxy';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { HttpApi } from '../http-api';
|
|
2
|
-
declare type CacheProxy = (baseApi: HttpApi) => <T extends string | string[] | Record<string, any>, P = void | Record<string, any>>(url: string, params?: P) => Promise<T>;
|
|
3
|
-
declare type CacheType = 'local' | 'session' | 'memory';
|
|
4
|
-
/**
|
|
5
|
-
* 스토리지를 이용한 API 캐시를 적용한다.
|
|
6
|
-
*
|
|
7
|
-
* @param type local, session, memory 셋 중 하나. 기본 local.
|
|
8
|
-
* @param expiredTime 캐시가 만료되는 시간(seconds). 0 이하면 무제한. 기본 0.
|
|
9
|
-
*/
|
|
10
|
-
export declare function cache(type?: CacheType, expiredTime?: number): CacheProxy;
|
|
11
|
-
export {};
|
package/libs/proxies/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './cache.proxy';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createCacheKey<P>(key: string, params?: P, subKeys?: Array<keyof P>): string;
|