Skip to content

Commit bbc5c49

Browse files
authored
Merge pull request #181 from contentstack/feat/DX-2274
Persistance code changes
2 parents cfcbe19 + e6145d5 commit bbc5c49

File tree

17 files changed

+28
-638
lines changed

17 files changed

+28
-638
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
"name": "@contentstack/delivery-sdk",
33
"version": "4.7.0",
44
"type": "module",
5+
"description": "Contentstack Delivery SDK for TypeScript",
6+
"homepage": "https://www.contentstack.com/",
7+
"author": {
8+
"name": "Contentstack",
9+
"url": "https://www.contentstack.com/"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/contentstack/contentstack-typescript"
14+
},
515
"license": "MIT",
616
"main": "./dist/legacy/index.cjs",
717
"module": "./dist/legacy/index.js",

src/lib/cache.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

src/lib/contentstack.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { httpClient, retryRequestHandler, retryResponseErrorHandler, retryResponseHandler } from '@contentstack/core';
22
import { AxiosRequestHeaders } from 'axios';
3-
import { handleRequest } from './cache';
43
import { Stack as StackClass } from './stack';
54
import { Policy, StackConfig } from './types';
65
import * as Utility from './utils';
@@ -95,11 +94,25 @@ export function stack(config: StackConfig): StackClass {
9594
if (config.logHandler) client.defaults.logHandler = config.logHandler;
9695

9796
if (config.cacheOptions && config.cacheOptions.policy !== Policy.IGNORE_CACHE) {
97+
if (!config.cacheOptions.persistanceStore) {
98+
throw new Error('Persistance store not provided. Please provide persistance store plugin object.');
99+
}
98100
const defaultAdapter = client.defaults.adapter;
99101
client.defaults.adapter = (adapterConfig: any) => {
100102
return new Promise(async (resolve, reject) => {
101-
if (config.cacheOptions)
102-
await handleRequest(config.cacheOptions, config.apiKey, defaultAdapter, resolve, reject, adapterConfig);
103+
if (config.cacheOptions && config.cacheOptions.persistanceStore) {
104+
await config.cacheOptions.persistanceStore.handleRequest(
105+
config.cacheOptions.policy,
106+
config.apiKey,
107+
defaultAdapter,
108+
resolve,
109+
reject,
110+
adapterConfig
111+
);
112+
}
113+
else {
114+
throw new Error('Persistance store not provided. Please provide persistance store plugin object.');
115+
}
103116
});
104117
};
105118
}

src/lib/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @cspell/spellchecker */
22
import { HttpClientParams } from '@contentstack/core';
3-
import { PersistanceStoreOptions, StorageType } from '../persistance';
43

54
// Internal Types
65
export type params = {
@@ -36,9 +35,9 @@ export interface StackConfig extends HttpClientParams {
3635
port?: number;
3736
debug?: boolean;
3837
}
39-
export interface CacheOptions extends PersistanceStoreOptions {
38+
export interface CacheOptions {
4039
policy: Policy;
41-
storeType?: StorageType;
40+
persistanceStore?: any;
4241
}
4342

4443
export enum Policy {

src/persistance/config/persistance-storage-config.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/persistance/helper/utils.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/persistance/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/persistance/persistance-store.ts

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/persistance/storages/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/persistance/storages/local-storage.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)