Skip to content

Commit facc0a4

Browse files
committed
feat: adding Persistance as plugin
1 parent fc3e5f1 commit facc0a4

File tree

14 files changed

+26
-242
lines changed

14 files changed

+26
-242
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.6.1",
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// import { PersistanceStore } from '../persistance';
22

3-
import { PersistanceStore } from '../persistance';
43
import { CacheOptions, Policy } from './types';
54

65
export async function handleRequest(
@@ -11,6 +10,15 @@ export async function handleRequest(
1110
reject: any,
1211
config: any
1312
) {
13+
14+
try {
15+
var PersistancePlugin = require('contentstack-persistance-typescript');
16+
var PersistanceStore = PersistancePlugin.PersistanceStore;
17+
18+
} catch (e) {
19+
throw new Error('Persistance store not provided. Please install contentstack-persistance-typescript package.');
20+
}
21+
1422
const cacheStore = new PersistanceStore(cacheOptions);
1523
switch (cacheOptions.policy) {
1624
case Policy.NETWORK_ELSE_CACHE: {

src/lib/contentstack.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ export function stack(config: StackConfig): StackClass {
9797
const defaultAdapter = client.defaults.adapter;
9898
client.defaults.adapter = (adapterConfig: any) => {
9999
return new Promise(async (resolve, reject) => {
100-
if (config.cacheOptions)
100+
if (config.cacheOptions) {
101101
await handleRequest(config.cacheOptions, config.apiKey, defaultAdapter, resolve, reject, adapterConfig);
102+
}
103+
else {
104+
throw new Error('Persistance store not provided. Please provide persistance store plugin object.');
105+
}
102106
});
103107
};
104108
}

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+
storeType?: 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)