Skip to content

feat: adding Persistance as plugin #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
"name": "@contentstack/delivery-sdk",
"version": "4.6.1",
"type": "module",
"description": "Contentstack Delivery SDK for TypeScript",
"homepage": "https://www.contentstack.com/",
"author": {
"name": "Contentstack",
"url": "https://www.contentstack.com/"
},
"repository": {
"type": "git",
"url": "https://github.com/contentstack/contentstack-typescript"
},
"license": "MIT",
"main": "./dist/legacy/index.cjs",
"module": "./dist/legacy/index.js",
Expand Down
10 changes: 9 additions & 1 deletion src/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// import { PersistanceStore } from '../persistance';

import { PersistanceStore } from '../persistance';
import { CacheOptions, Policy } from './types';

export async function handleRequest(
Expand All @@ -11,6 +10,15 @@ export async function handleRequest(
reject: any,
config: any
) {

try {
var PersistancePlugin = require('contentstack-persistance-typescript');
var PersistanceStore = PersistancePlugin.PersistanceStore;

} catch (e) {
throw new Error('Persistance store not provided. Please install contentstack-persistance-typescript package.');
}

const cacheStore = new PersistanceStore(cacheOptions);
switch (cacheOptions.policy) {
case Policy.NETWORK_ELSE_CACHE: {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ export function stack(config: StackConfig): StackClass {
const defaultAdapter = client.defaults.adapter;
client.defaults.adapter = (adapterConfig: any) => {
return new Promise(async (resolve, reject) => {
if (config.cacheOptions)
if (config.cacheOptions) {
await handleRequest(config.cacheOptions, config.apiKey, defaultAdapter, resolve, reject, adapterConfig);
}
else {
throw new Error('Persistance store not provided. Please provide persistance store plugin object.');
}
});
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @cspell/spellchecker */
import { HttpClientParams } from '@contentstack/core';
import { PersistanceStoreOptions, StorageType } from '../persistance';

// Internal Types
export type params = {
Expand Down Expand Up @@ -36,9 +35,9 @@ export interface StackConfig extends HttpClientParams {
port?: number;
debug?: boolean;
}
export interface CacheOptions extends PersistanceStoreOptions {
export interface CacheOptions {
policy: Policy;
storeType?: StorageType;
storeType?: any;
}

export enum Policy {
Expand Down
15 changes: 0 additions & 15 deletions src/persistance/config/persistance-storage-config.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/persistance/helper/utils.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/persistance/index.ts

This file was deleted.

123 changes: 0 additions & 123 deletions src/persistance/persistance-store.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/persistance/storages/index.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/persistance/storages/local-storage.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/persistance/storages/memory-storage.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/persistance/types/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/persistance/types/storage-type.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/persistance/types/storage.ts

This file was deleted.