Comparing version 3.0.1 to 3.0.3
@@ -0,1 +1,15 @@ | ||
## [3.0.3](https://github.com/TinkoffCreditSystems/cachalot/compare/v3.0.2...v3.0.3) (2020-06-24) | ||
### Bug Fixes | ||
* less lodash in project ([#31](https://github.com/TinkoffCreditSystems/cachalot/issues/31)) ([5b4d99d](https://github.com/TinkoffCreditSystems/cachalot/commit/5b4d99d)) | ||
## [3.0.2](https://github.com/TinkoffCreditSystems/cachalot/compare/v3.0.1...v3.0.2) (2020-06-24) | ||
### Bug Fixes | ||
* Executor cannot return `undefined`. The only valid result for emptiness is `null`. ([ed8a701](https://github.com/TinkoffCreditSystems/cachalot/commit/ed8a701)) | ||
## [3.0.1](https://github.com/TinkoffCreditSystems/cachalot/compare/v3.0.0...v3.0.1) (2020-05-08) | ||
@@ -2,0 +16,0 @@ |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MemcachedStorageAdapter = exports.DEFAULT_LOCK_EXPIRES = void 0; | ||
const ConnectionStatus_1 = require("../ConnectionStatus"); | ||
@@ -8,0 +9,0 @@ const custom_error_1 = __importDefault(require("../errors/custom-error")); |
"use strict"; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = __importStar(require("lodash")); | ||
exports.RedisStorageAdapter = exports.DEFAULT_LOCK_EXPIRES = exports.DEFAULT_OPERATION_TIMEOUT = void 0; | ||
const ConnectionStatus_1 = require("../ConnectionStatus"); | ||
@@ -39,3 +32,3 @@ const with_timeout_1 = require("../with-timeout"); | ||
this.redisInstance.on("end", () => this.setConnectionStatus(ConnectionStatus_1.ConnectionStatus.DISCONNECTED)); | ||
this.withTimeout = lodash_1.partial(with_timeout_1.withTimeout, lodash_1.default, this.options.operationTimeout); | ||
this.withTimeout = (promise) => with_timeout_1.withTimeout(promise, this.options.operationTimeout); | ||
} | ||
@@ -42,0 +35,0 @@ /** |
import { ConnectionStatus } from "../ConnectionStatus"; | ||
import { StorageAdapter, StorageAdapterOptions } from "../StorageAdapter"; | ||
import { StorageAdapter } from "../StorageAdapter"; | ||
declare class TestStorageAdapter implements StorageAdapter { | ||
options: StorageAdapterOptions; | ||
testInterface: any; | ||
internalStorage: Record<string, string>; | ||
isConnected: boolean; | ||
internalStorage: any; | ||
constructor(testInstance: any, isConnected?: boolean); | ||
constructor(storage?: Record<string, string>, isConnected?: boolean); | ||
checkConnection(): void; | ||
@@ -18,5 +16,6 @@ getConnectionStatus(): ConnectionStatus; | ||
isLockExists(key: string): Promise<boolean>; | ||
mset(values: Map<string, any>): Promise<void>; | ||
mset(values: Map<string, string>): Promise<void>; | ||
mget(keys: string[]): Promise<(string | null)[]>; | ||
setOptions(): void; | ||
} | ||
export default TestStorageAdapter; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const ConnectionStatus_1 = require("../ConnectionStatus"); | ||
class TestStorageAdapter { | ||
constructor(testInstance, isConnected = true) { | ||
this.testInterface = testInstance; | ||
this.testInterface.internalStorage = {}; | ||
constructor(storage = {}, isConnected = true) { | ||
this.internalStorage = storage; | ||
this.isConnected = isConnected; | ||
@@ -24,3 +22,3 @@ } | ||
this.checkConnection(); | ||
this.testInterface.internalStorage[key] = value; | ||
this.internalStorage[key] = value; | ||
return true; | ||
@@ -30,8 +28,8 @@ } | ||
this.checkConnection(); | ||
return this.testInterface.internalStorage[key]; | ||
return this.internalStorage[key]; | ||
} | ||
async del(key) { | ||
this.checkConnection(); | ||
if (this.testInterface.internalStorage[key]) { | ||
delete this.testInterface.internalStorage[key]; | ||
if (this.internalStorage[key]) { | ||
delete this.internalStorage[key]; | ||
return true; | ||
@@ -51,3 +49,3 @@ } | ||
this.checkConnection(); | ||
return !!this.testInterface.internalStorage[`${key}_lock`]; | ||
return !!this.internalStorage[`${key}_lock`]; | ||
} | ||
@@ -57,3 +55,3 @@ async mset(values) { | ||
values.forEach((value, key) => { | ||
this.testInterface.internalStorage[key] = value; | ||
this.internalStorage[key] = value; | ||
}); | ||
@@ -63,6 +61,9 @@ } | ||
this.checkConnection(); | ||
return keys.map(key => this.testInterface.internalStorage[key] || null); | ||
return keys.map(key => this.internalStorage[key] || null); | ||
} | ||
setOptions() { | ||
return undefined; | ||
} | ||
} | ||
exports.default = TestStorageAdapter; | ||
//# sourceMappingURL=TestStorageAdapter.js.map |
@@ -25,4 +25,4 @@ import { Executor } from "./Executor"; | ||
}; | ||
export declare const isCustomStorageOptions: (options: object) => options is CacheWithCustomStorageOptions; | ||
export declare const isBaseStorageOptions: (options: object) => options is CacheWithBaseStorageOptions; | ||
export declare const isCustomStorageOptions: (options: unknown) => options is CacheWithCustomStorageOptions; | ||
export declare const isBaseStorageOptions: (options: unknown) => options is CacheWithBaseStorageOptions; | ||
export interface ManagerSelectorOptions { | ||
@@ -29,0 +29,0 @@ manager?: string; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EXPIRES_IN = exports.isBaseStorageOptions = exports.isCustomStorageOptions = void 0; | ||
const defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep")); | ||
@@ -41,3 +42,3 @@ const ConnectionStatus_1 = require("./ConnectionStatus"); | ||
} | ||
if (exports.isBaseStorageOptions(options)) { | ||
else if (exports.isBaseStorageOptions(options)) { | ||
this.storage = new BaseStorage_1.BaseStorage({ | ||
@@ -50,3 +51,3 @@ adapter: options.adapter, | ||
} | ||
if (!this.storage) { | ||
else { | ||
throw new Error("Either custom storage or storage adapter must be passed in options."); | ||
@@ -53,0 +54,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConnectionStatus = void 0; | ||
var ConnectionStatus; | ||
@@ -4,0 +5,0 @@ (function (ConnectionStatus) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -8,0 +20,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ERRORS = void 0; | ||
exports.ERRORS = { | ||
@@ -4,0 +5,0 @@ ParseError: "ParseError", |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.executorReturnsUndefinedError = exports.isOperationTimeoutError = exports.operationTimeoutError = exports.waitForResultError = exports.requestMaximumTimeoutExceededError = exports.parseError = void 0; | ||
const custom_error_1 = __importDefault(require("./custom-error")); | ||
@@ -8,0 +9,0 @@ const constants_1 = require("./constants"); |
@@ -9,3 +9,5 @@ import { ReadWriteOptions } from "./storage/Storage"; | ||
} | ||
declare type NonUndefined<T> = T extends undefined ? never : T; | ||
export declare function runExecutor<R>(executor: Executor<R>): Promise<R>; | ||
export declare type Executor<R> = (...args: unknown[]) => Promise<R> | R; | ||
export declare type Executor<R> = (...args: unknown[]) => Promise<NonUndefined<R>> | NonUndefined<R>; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.runExecutor = void 0; | ||
const errors_1 = require("./errors/errors"); | ||
@@ -4,0 +5,0 @@ async function runExecutor(executor) { |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,4 +16,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WriteThroughManager = exports.RefreshAheadManager = exports.ReadThroughManager = exports.MemcachedStorageAdapter = exports.RedisStorageAdapter = exports.Record = void 0; | ||
const Record_1 = require("./storage/Record"); | ||
exports.Record = Record_1.Record; | ||
Object.defineProperty(exports, "Record", { enumerable: true, get: function () { return Record_1.Record; } }); | ||
const Cache_1 = __importDefault(require("./Cache")); | ||
@@ -23,4 +31,4 @@ const RedisStorageAdapter_1 = __importDefault(require("./adapters/RedisStorageAdapter")); | ||
exports.RefreshAheadManager = RefreshAheadManager_1.default; | ||
__export(require("./errors/constants")); | ||
__exportStar(require("./errors/constants"), exports); | ||
exports.default = Cache_1.default; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RunExecutorLockedKeyRetrieveStrategy = void 0; | ||
const Executor_1 = require("../Executor"); | ||
@@ -4,0 +5,0 @@ /** |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -13,2 +25,3 @@ }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WaitForResultLockedKeyRetrieveStrategy = exports.DEFAULT_REQUEST_TIMEOUT = exports.DEFAULT_MAXIMUM_TIMEOUT = void 0; | ||
const errors = __importStar(require("../errors/errors")); | ||
@@ -15,0 +28,0 @@ const deserialize_1 = __importDefault(require("../deserialize")); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LockedKeyRetrieveStrategyTypes = void 0; | ||
var LockedKeyRetrieveStrategyTypes; | ||
@@ -4,0 +5,0 @@ (function (LockedKeyRetrieveStrategyTypes) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseManager = void 0; | ||
const LockedKeyRetrieveStrategy_1 = require("../LockedKeyRetrieveStrategy"); | ||
@@ -4,0 +5,0 @@ const WaitForResultLockedKeyRetrieveStrategy_1 = require("../locked-key-retrieve-strategies/WaitForResultLockedKeyRetrieveStrategy"); |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_REFRESH_AHEAD_FACTOR = void 0; | ||
const BaseManager_1 = require("./BaseManager"); | ||
@@ -8,0 +9,0 @@ const Executor_1 = require("../Executor"); |
@@ -26,3 +26,3 @@ import { ConnectionStatus } from "../ConnectionStatus"; | ||
*/ | ||
export declare type CommandFn = (...args: unknown[]) => unknown; | ||
export declare type CommandFn = (...args: any[]) => unknown; | ||
/** | ||
@@ -29,0 +29,0 @@ * BaseStorage is the default Storage implementation for Manager. |
@@ -6,5 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseStorage = exports.TAGS_VERSIONS_ALIAS = void 0; | ||
const crypto_1 = require("crypto"); | ||
const isFunction_1 = __importDefault(require("lodash/isFunction")); | ||
const uniq_1 = __importDefault(require("lodash/uniq")); | ||
const ConnectionStatus_1 = require("../ConnectionStatus"); | ||
@@ -16,2 +15,5 @@ const deserialize_1 = __importDefault(require("../deserialize")); | ||
exports.TAGS_VERSIONS_ALIAS = "cache-tags-versions"; | ||
function uniq(arr) { | ||
return [...new Set(arr)]; | ||
} | ||
/** | ||
@@ -25,2 +27,3 @@ * BaseStorage is the default Storage implementation for Manager. | ||
constructor(options) { | ||
var _a, _b; | ||
/** | ||
@@ -34,6 +37,5 @@ * An offline commands queue. | ||
this.hashKeys = options.hashKeys || false; | ||
if (isFunction_1.default(this.adapter.setOptions)) { | ||
this.adapter.setOptions(options); | ||
} | ||
(_b = (_a = this.adapter).setOptions) === null || _b === void 0 ? void 0 : _b.call(_a, options); | ||
this.adapter.onConnect(async () => this.executeCommandsFromQueue()); | ||
this.setTagVersions = this.setTagVersions.bind(this); | ||
} | ||
@@ -112,14 +114,15 @@ /** | ||
async set(key, value, options = {}) { | ||
var _a, _b; | ||
let tags = []; | ||
if (isFunction_1.default(options.tags)) { | ||
tags = options.tags(); | ||
if (Array.isArray(options.tags)) { | ||
tags = options.tags; | ||
} | ||
else if (options.tags !== undefined) { | ||
tags = options.tags; | ||
tags = options.tags(); | ||
} | ||
const dynamicTags = isFunction_1.default(options.getTags) ? options.getTags(value) : []; | ||
const dynamicTags = (_b = (_a = options.getTags) === null || _a === void 0 ? void 0 : _a.call(options, value)) !== null && _b !== void 0 ? _b : []; | ||
if (!Array.isArray(dynamicTags)) { | ||
throw new TypeError(`getTags should return an array of strings, got ${typeof dynamicTags}`); | ||
} | ||
const record = new Record_1.Record(key, value, uniq_1.default(tags.concat(dynamicTags)).map(this.createTag), options); | ||
const record = new Record_1.Record(key, value, uniq(tags.concat(dynamicTags)).map(this.createTag), options); | ||
await this.adapter.set(this.createKey(key), JSON.stringify({ ...record, value: JSON.stringify(record.value) }), record.expiresIn); | ||
@@ -126,0 +129,0 @@ return record; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Record = void 0; | ||
class Record { | ||
@@ -4,0 +5,0 @@ constructor(key, value, tags, options = {}) { |
@@ -1,2 +0,4 @@ | ||
declare const _default: (time: number) => Promise<number>; | ||
/// <reference types="node" /> | ||
import Timer = NodeJS.Timer; | ||
declare const _default: (time: number) => Promise<Timer>; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withTimeout = void 0; | ||
const errors_1 = require("./errors/errors"); | ||
@@ -4,0 +5,0 @@ exports.withTimeout = async (promise, timeout) => { |
{ | ||
"name": "cachalot", | ||
"version": "3.0.1", | ||
"version": "3.0.3", | ||
"description": "Cache manager for nodejs with support different cache strategies", | ||
@@ -32,9 +32,8 @@ "keywords": [ | ||
"lint": "prettier -c tests/**/*.ts src/*.ts src/**/*.ts && eslint src tests --ext .ts --max-warnings 0", | ||
"check": "npm run lint && npm run test:unit", | ||
"test": "npm run test:unit", | ||
"test:unit": "jest --coverage --verbose --passWithNoTests", | ||
"test:ci": "npm run test:unit -- --coverageReporters=text-lcov | coveralls", | ||
"test:ci": "npm run test:unit -- --coverageReporters=lcovonly", | ||
"test:integration": "jest --config tests/jest.config.js --forceExit --detectOpenHandles --verbose", | ||
"test:unit:watch": "jest --watch", | ||
"prepublishOnly": "npm run check && npm run build", | ||
"prepublishOnly": "npm run build", | ||
"semantic-release": "semantic-release" | ||
@@ -48,23 +47,22 @@ }, | ||
"@semantic-release/git": "^7.0.16", | ||
"@types/ioredis": "^4.14.9", | ||
"@types/jest": "^25.1.4", | ||
"@types/lodash": "^4.14.149", | ||
"@types/ioredis": "^4.16.7", | ||
"@types/jest": "^25.2.3", | ||
"@types/lodash": "^4.14.157", | ||
"@types/memcached": "^2.2.6", | ||
"@types/node": "^8", | ||
"@types/uuid": "^7.0.0", | ||
"@typescript-eslint/eslint-plugin": "^2.23.0", | ||
"@typescript-eslint/parser": "^2.23.0", | ||
"coveralls": "^3.0.4", | ||
"cz-conventional-changelog": "^3.1.0", | ||
"@types/node": "^8.10.61", | ||
"@types/uuid": "^8.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"coveralls": "^3.1.0", | ||
"cz-conventional-changelog": "^3.2.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"ioredis": "^4.16.0", | ||
"jest": "^25.1.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"ioredis": "^4.17.3", | ||
"jest": "^25.5.4", | ||
"memcached": "^2.2.2", | ||
"prettier": "1.19.1", | ||
"prettier": "^1.19.1", | ||
"semantic-release": "^15.13.24", | ||
"ts-jest": "^25.2.1", | ||
"typedoc": "^0.16.11", | ||
"typescript": "^3.8.3", | ||
"uuid": "^7.0.2" | ||
"ts-jest": "^25.5.1", | ||
"typescript": "^3.9.5", | ||
"uuid": "^8.2.0" | ||
}, | ||
@@ -71,0 +69,0 @@ "config": { |
# Cachalot | ||
[![Build status](https://img.shields.io/travis/TinkoffCreditSystems/cachalot/master.svg?style=flat-square)](https://travis-ci.org/TinkoffCreditSystems/cachalot) | ||
[![Build status](https://img.shields.io/github/workflow/status/TinkoffCreditSystems/cachalot/CI?style=flat-square)](https://github.com/TinkoffCreditSystems/cachalot/actions?query=branch%3Amaster+workflow%3ACI) | ||
[![Coveralls github](https://img.shields.io/coveralls/github/TinkoffCreditSystems/cachalot.svg?style=flat-square)](https://coveralls.io/github/TinkoffCreditSystems/cachalot) | ||
@@ -5,0 +5,0 @@ [![Written in typescript](https://img.shields.io/badge/written_in-typescript-blue.svg?style=flat-square)](https://www.typescriptlang.org/) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138983
22
1987