Skip to content

Persistance code changes #181

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

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
82 changes: 0 additions & 82 deletions src/lib/cache.ts

This file was deleted.

19 changes: 16 additions & 3 deletions src/lib/contentstack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { httpClient, retryRequestHandler, retryResponseErrorHandler, retryResponseHandler } from '@contentstack/core';
import { AxiosRequestHeaders } from 'axios';
import { handleRequest } from './cache';
import { Stack as StackClass } from './stack';
import { Policy, StackConfig } from './types';
import * as Utility from './utils';
Expand Down Expand Up @@ -94,11 +93,25 @@ export function stack(config: StackConfig): StackClass {
if (config.logHandler) client.defaults.logHandler = config.logHandler;

if (config.cacheOptions && config.cacheOptions.policy !== Policy.IGNORE_CACHE) {
if (!config.cacheOptions.persistanceStore) {
throw new Error('Persistance store not provided. Please provide persistance store plugin object.');
}
const defaultAdapter = client.defaults.adapter;
client.defaults.adapter = (adapterConfig: any) => {
return new Promise(async (resolve, reject) => {
if (config.cacheOptions)
await handleRequest(config.cacheOptions, config.apiKey, defaultAdapter, resolve, reject, adapterConfig);
if (config.cacheOptions && config.cacheOptions.persistanceStore) {
await config.cacheOptions.persistanceStore.handleRequest(
config.cacheOptions.policy,
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;
persistanceStore?: 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.

Loading