deploy: ebd4cc0010
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
function createBrowserLocalStorageCache(options) {
|
||||
const namespaceKey = `algoliasearch-client-js-${options.key}`;
|
||||
// eslint-disable-next-line functional/no-let
|
||||
let storage;
|
||||
const getStorage = () => {
|
||||
if (storage === undefined) {
|
||||
storage = options.localStorage || window.localStorage;
|
||||
}
|
||||
return storage;
|
||||
};
|
||||
const getNamespace = () => {
|
||||
return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
|
||||
};
|
||||
const setNamespace = (namespace) => {
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
};
|
||||
const removeOutdatedCacheItems = () => {
|
||||
const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
|
||||
const namespace = getNamespace();
|
||||
const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
|
||||
return cacheItem.timestamp !== undefined;
|
||||
}));
|
||||
setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
|
||||
if (!timeToLive)
|
||||
return;
|
||||
const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
|
||||
const currentTimestamp = new Date().getTime();
|
||||
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
|
||||
return !isExpired;
|
||||
}));
|
||||
setNamespace(filteredNamespaceWithoutExpiredItems);
|
||||
};
|
||||
return {
|
||||
get(key, defaultValue, events = {
|
||||
miss: () => Promise.resolve(),
|
||||
}) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
removeOutdatedCacheItems();
|
||||
const keyAsString = JSON.stringify(key);
|
||||
return getNamespace()[keyAsString];
|
||||
})
|
||||
.then(value => {
|
||||
return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
|
||||
})
|
||||
.then(([value, exists]) => {
|
||||
return Promise.all([value, exists || events.miss(value)]);
|
||||
})
|
||||
.then(([value]) => value);
|
||||
},
|
||||
set(key, value) {
|
||||
return Promise.resolve().then(() => {
|
||||
const namespace = getNamespace();
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
namespace[JSON.stringify(key)] = {
|
||||
timestamp: new Date().getTime(),
|
||||
value,
|
||||
};
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
return value;
|
||||
});
|
||||
},
|
||||
delete(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
const namespace = getNamespace();
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
delete namespace[JSON.stringify(key)];
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
return Promise.resolve().then(() => {
|
||||
getStorage().removeItem(namespaceKey);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
exports.createBrowserLocalStorageCache = createBrowserLocalStorageCache;
|
||||
31
node_modules/@algolia/cache-browser-local-storage/dist/cache-browser-local-storage.d.ts
generated
vendored
31
node_modules/@algolia/cache-browser-local-storage/dist/cache-browser-local-storage.d.ts
generated
vendored
@@ -1,31 +0,0 @@
|
||||
import { Cache } from '@algolia/cache-common';
|
||||
|
||||
export declare type BrowserLocalStorageCacheItem = {
|
||||
/**
|
||||
* The cache item creation timestamp.
|
||||
*/
|
||||
readonly timestamp: number;
|
||||
/**
|
||||
* The cache item value
|
||||
*/
|
||||
readonly value: any;
|
||||
};
|
||||
|
||||
export declare type BrowserLocalStorageOptions = {
|
||||
/**
|
||||
* The cache key.
|
||||
*/
|
||||
readonly key: string;
|
||||
/**
|
||||
* The time to live for each cached item in seconds.
|
||||
*/
|
||||
readonly timeToLive?: number;
|
||||
/**
|
||||
* The native local storage implementation.
|
||||
*/
|
||||
readonly localStorage?: Storage;
|
||||
};
|
||||
|
||||
export declare function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache;
|
||||
|
||||
export { }
|
||||
@@ -1,79 +0,0 @@
|
||||
function createBrowserLocalStorageCache(options) {
|
||||
const namespaceKey = `algoliasearch-client-js-${options.key}`;
|
||||
// eslint-disable-next-line functional/no-let
|
||||
let storage;
|
||||
const getStorage = () => {
|
||||
if (storage === undefined) {
|
||||
storage = options.localStorage || window.localStorage;
|
||||
}
|
||||
return storage;
|
||||
};
|
||||
const getNamespace = () => {
|
||||
return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
|
||||
};
|
||||
const setNamespace = (namespace) => {
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
};
|
||||
const removeOutdatedCacheItems = () => {
|
||||
const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
|
||||
const namespace = getNamespace();
|
||||
const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
|
||||
return cacheItem.timestamp !== undefined;
|
||||
}));
|
||||
setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
|
||||
if (!timeToLive)
|
||||
return;
|
||||
const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
|
||||
const currentTimestamp = new Date().getTime();
|
||||
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
|
||||
return !isExpired;
|
||||
}));
|
||||
setNamespace(filteredNamespaceWithoutExpiredItems);
|
||||
};
|
||||
return {
|
||||
get(key, defaultValue, events = {
|
||||
miss: () => Promise.resolve(),
|
||||
}) {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
removeOutdatedCacheItems();
|
||||
const keyAsString = JSON.stringify(key);
|
||||
return getNamespace()[keyAsString];
|
||||
})
|
||||
.then(value => {
|
||||
return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
|
||||
})
|
||||
.then(([value, exists]) => {
|
||||
return Promise.all([value, exists || events.miss(value)]);
|
||||
})
|
||||
.then(([value]) => value);
|
||||
},
|
||||
set(key, value) {
|
||||
return Promise.resolve().then(() => {
|
||||
const namespace = getNamespace();
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
namespace[JSON.stringify(key)] = {
|
||||
timestamp: new Date().getTime(),
|
||||
value,
|
||||
};
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
return value;
|
||||
});
|
||||
},
|
||||
delete(key) {
|
||||
return Promise.resolve().then(() => {
|
||||
const namespace = getNamespace();
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
delete namespace[JSON.stringify(key)];
|
||||
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
||||
});
|
||||
},
|
||||
clear() {
|
||||
return Promise.resolve().then(() => {
|
||||
getStorage().removeItem(namespaceKey);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export { createBrowserLocalStorageCache };
|
||||
2
node_modules/@algolia/cache-browser-local-storage/index.js
generated
vendored
2
node_modules/@algolia/cache-browser-local-storage/index.js
generated
vendored
@@ -1,2 +0,0 @@
|
||||
// eslint-disable-next-line functional/immutable-data, import/no-commonjs
|
||||
module.exports = require('./dist/cache-browser-local-storage.cjs.js');
|
||||
22
node_modules/@algolia/cache-browser-local-storage/package.json
generated
vendored
22
node_modules/@algolia/cache-browser-local-storage/package.json
generated
vendored
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "@algolia/cache-browser-local-storage",
|
||||
"version": "4.20.0",
|
||||
"private": false,
|
||||
"description": "Promise-based cache library for browser using local storage.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/algolia/algoliasearch-client-javascript.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"sideEffects": false,
|
||||
"main": "index.js",
|
||||
"module": "dist/cache-browser-local-storage.esm.js",
|
||||
"types": "dist/cache-browser-local-storage.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"@algolia/cache-common": "4.20.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user