@naturalcycles/js-lib
Advanced tools
Comparing version 4.6.0 to 4.7.0
@@ -0,1 +1,8 @@ | ||
# [4.7.0](https://github.com/NaturalCycles/js-lib/compare/v4.6.0...v4.7.0) (2019-04-26) | ||
### Features | ||
* [@memo](https://github.com/memo)Promise decorator ([8f81f14](https://github.com/NaturalCycles/js-lib/commit/8f81f14)) | ||
# [4.6.0](https://github.com/NaturalCycles/js-lib/compare/v4.5.1...v4.6.0) (2019-04-10) | ||
@@ -2,0 +9,0 @@ |
@@ -12,3 +12,2 @@ // Based on: | ||
*/ | ||
/* tslint:disable:no-invalid-this */ | ||
import { jsonMemoSerializer, MapMemoCache } from './memo.util'; | ||
@@ -44,2 +43,3 @@ /** | ||
descriptor.value = function (...args) { | ||
const ctx = this; | ||
const cacheKey = jsonMemoSerializer(args); | ||
@@ -49,3 +49,3 @@ if (cache.has(cacheKey)) { | ||
} | ||
const res = originalFn.apply(this, args); | ||
const res = originalFn.apply(ctx, args); | ||
cache.set(cacheKey, res); | ||
@@ -56,3 +56,3 @@ // console.log('miss', cacheKey) | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`); | ||
console.log(`memo.dropCache (method=${String(key)})`); | ||
cache.clear(); | ||
@@ -59,0 +59,0 @@ }; |
@@ -38,2 +38,3 @@ // Based on: | ||
descriptor.value = function (...args) { | ||
const ctx = this; | ||
const cacheKey = opts.serializer(args); | ||
@@ -43,3 +44,3 @@ if (cache.has(cacheKey)) { | ||
} | ||
const res = originalFn.apply(this, args); | ||
const res = originalFn.apply(ctx, args); | ||
cache.set(cacheKey, res); | ||
@@ -49,3 +50,3 @@ return res; | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`); | ||
console.log(`memo.dropCache (method=${String(key)})`); | ||
cache.clear(); | ||
@@ -52,0 +53,0 @@ }; |
import { memo } from './decorators/memo.decorator'; | ||
import { memoCache } from './decorators/memoCache.decorator'; | ||
import { memoPromise } from './decorators/memoPromise.decorator'; | ||
import { AppError } from './error/app.error'; | ||
@@ -12,3 +13,3 @@ import { anyToErrorMessage, anyToErrorObject, appErrorToErrorObject, appErrorToHttpError, errorObjectToAppError, errorObjectToHttpError, errorToErrorObject, } from './error/error.util'; | ||
import { silentConsole } from './util/test.util'; | ||
export { memo, memoCache, AppError, HttpError, silentConsole, randomInt, loadScript, capitalizeFirstLetter, lowercaseFirstLetter, removeWhitespace, pick, filterFalsyValues, filterEmptyStringValues, filterUndefinedValues, filterValues, transformValues, objectNullValuesToUndefined, deepEquals, deepCopy, isObject, isEmptyObject, mergeDeep, deepTrim, sortObjectDeep, unsetValue, mask, arrayToHash, classToPlain, getKeyByValue, invertObject, invertMap, by, deepFreeze, anyToErrorMessage, anyToErrorObject, errorToErrorObject, errorObjectToAppError, errorObjectToHttpError, appErrorToErrorObject, appErrorToHttpError, arrayRange, dedupeArray, flatArray, }; | ||
export { memo, memoCache, memoPromise, AppError, HttpError, silentConsole, randomInt, loadScript, capitalizeFirstLetter, lowercaseFirstLetter, removeWhitespace, pick, filterFalsyValues, filterEmptyStringValues, filterUndefinedValues, filterValues, transformValues, objectNullValuesToUndefined, deepEquals, deepCopy, isObject, isEmptyObject, mergeDeep, deepTrim, sortObjectDeep, unsetValue, mask, arrayToHash, classToPlain, getKeyByValue, invertObject, invertMap, by, deepFreeze, anyToErrorMessage, anyToErrorObject, errorToErrorObject, errorObjectToAppError, errorObjectToHttpError, appErrorToErrorObject, appErrorToHttpError, arrayRange, dedupeArray, flatArray, }; | ||
//# sourceMappingURL=index.js.map |
@@ -9,2 +9,2 @@ /** | ||
*/ | ||
export declare const memo: () => (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export declare const memo: () => MethodDecorator; |
@@ -14,3 +14,2 @@ "use strict"; | ||
*/ | ||
/* tslint:disable:no-invalid-this */ | ||
const memo_util_1 = require("./memo.util"); | ||
@@ -46,2 +45,3 @@ /** | ||
descriptor.value = function (...args) { | ||
const ctx = this; | ||
const cacheKey = memo_util_1.jsonMemoSerializer(args); | ||
@@ -51,3 +51,3 @@ if (cache.has(cacheKey)) { | ||
} | ||
const res = originalFn.apply(this, args); | ||
const res = originalFn.apply(ctx, args); | ||
cache.set(cacheKey, res); | ||
@@ -58,3 +58,3 @@ // console.log('miss', cacheKey) | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`); | ||
console.log(`memo.dropCache (method=${String(key)})`); | ||
cache.clear(); | ||
@@ -61,0 +61,0 @@ }; |
@@ -7,2 +7,2 @@ import { MemoSerializer } from './memo.util'; | ||
} | ||
export declare const memoCache: (opts?: MemoCacheOpts) => (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export declare const memoCache: (opts?: MemoCacheOpts) => MethodDecorator; |
@@ -43,2 +43,3 @@ "use strict"; | ||
descriptor.value = function (...args) { | ||
const ctx = this; | ||
const cacheKey = opts.serializer(args); | ||
@@ -48,3 +49,3 @@ if (cache.has(cacheKey)) { | ||
} | ||
const res = originalFn.apply(this, args); | ||
const res = originalFn.apply(ctx, args); | ||
cache.set(cacheKey, res); | ||
@@ -54,3 +55,3 @@ return res; | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`); | ||
console.log(`memo.dropCache (method=${String(key)})`); | ||
cache.clear(); | ||
@@ -57,0 +58,0 @@ }; |
import { memo } from './decorators/memo.decorator'; | ||
import { memoCache } from './decorators/memoCache.decorator'; | ||
import { memoPromise } from './decorators/memoPromise.decorator'; | ||
import { AppError } from './error/app.error'; | ||
@@ -14,2 +15,2 @@ import { Admin401ErrorData, Admin403ErrorData, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse } from './error/error.model'; | ||
import { silentConsole } from './util/test.util'; | ||
export { memo, memoCache, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, AppError, HttpError, Admin401ErrorData, Admin403ErrorData, silentConsole, randomInt, loadScript, StringMap, PromiseMap, ClassType, DeepReadonly, capitalizeFirstLetter, lowercaseFirstLetter, removeWhitespace, pick, filterFalsyValues, filterEmptyStringValues, filterUndefinedValues, filterValues, transformValues, objectNullValuesToUndefined, deepEquals, deepCopy, isObject, isEmptyObject, mergeDeep, deepTrim, sortObjectDeep, unsetValue, mask, arrayToHash, classToPlain, getKeyByValue, invertObject, invertMap, by, deepFreeze, anyToErrorMessage, anyToErrorObject, errorToErrorObject, errorObjectToAppError, errorObjectToHttpError, appErrorToErrorObject, appErrorToHttpError, arrayRange, dedupeArray, flatArray, }; | ||
export { memo, memoCache, memoPromise, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, AppError, HttpError, Admin401ErrorData, Admin403ErrorData, silentConsole, randomInt, loadScript, StringMap, PromiseMap, ClassType, DeepReadonly, capitalizeFirstLetter, lowercaseFirstLetter, removeWhitespace, pick, filterFalsyValues, filterEmptyStringValues, filterUndefinedValues, filterValues, transformValues, objectNullValuesToUndefined, deepEquals, deepCopy, isObject, isEmptyObject, mergeDeep, deepTrim, sortObjectDeep, unsetValue, mask, arrayToHash, classToPlain, getKeyByValue, invertObject, invertMap, by, deepFreeze, anyToErrorMessage, anyToErrorObject, errorToErrorObject, errorObjectToAppError, errorObjectToHttpError, appErrorToErrorObject, appErrorToHttpError, arrayRange, dedupeArray, flatArray, }; |
@@ -7,2 +7,4 @@ "use strict"; | ||
exports.memoCache = memoCache_decorator_1.memoCache; | ||
const memoPromise_decorator_1 = require("./decorators/memoPromise.decorator"); | ||
exports.memoPromise = memoPromise_decorator_1.memoPromise; | ||
const app_error_1 = require("./error/app.error"); | ||
@@ -9,0 +11,0 @@ exports.AppError = app_error_1.AppError; |
{ | ||
"name": "@naturalcycles/js-lib", | ||
"version": "4.6.0", | ||
"version": "4.7.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "build": "del ./dist && tsc", |
@@ -14,4 +14,2 @@ // Based on: | ||
/* tslint:disable:no-invalid-this */ | ||
import { jsonMemoSerializer, MapMemoCache, MemoCache } from './memo.util' | ||
@@ -27,7 +25,3 @@ | ||
*/ | ||
export const memo = () => ( | ||
target: any, | ||
key: string, | ||
descriptor: PropertyDescriptor, | ||
): PropertyDescriptor => { | ||
export const memo = (): MethodDecorator => (target, key, descriptor) => { | ||
if (typeof descriptor.value !== 'function') { | ||
@@ -55,3 +49,4 @@ throw new Error('Memoization can be applied only to methods') | ||
descriptor.value = function (...args: any[]): any { | ||
descriptor.value = function (this: any, ...args: any[]): any { | ||
const ctx = this | ||
const cacheKey = jsonMemoSerializer(args) | ||
@@ -63,3 +58,3 @@ | ||
const res: any = originalFn.apply(this, args) | ||
const res: any = originalFn.apply(ctx, args) | ||
@@ -70,6 +65,5 @@ cache.set(cacheKey, res) | ||
return res | ||
} | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`) | ||
} as any | ||
;(descriptor.value as any).dropCache = () => { | ||
console.log(`memo.dropCache (method=${String(key)})`) | ||
cache.clear() | ||
@@ -76,0 +70,0 @@ } |
@@ -39,7 +39,7 @@ // Based on: | ||
export const memoCache = (opts: MemoCacheOpts = {}) => ( | ||
target: any, | ||
key: string, | ||
descriptor: PropertyDescriptor, | ||
): PropertyDescriptor => { | ||
export const memoCache = (opts: MemoCacheOpts = {}): MethodDecorator => ( | ||
target, | ||
key, | ||
descriptor, | ||
) => { | ||
if (typeof descriptor.value !== 'function') { | ||
@@ -59,3 +59,4 @@ throw new Error('Memoization can be applied only to methods') | ||
descriptor.value = function (...args: any[]): any { | ||
descriptor.value = function (this: any, ...args: any[]): any { | ||
const ctx = this | ||
const cacheKey = opts.serializer!(args) | ||
@@ -67,3 +68,3 @@ | ||
const res: any = originalFn.apply(this, args) | ||
const res: any = originalFn.apply(ctx, args) | ||
@@ -73,6 +74,5 @@ cache.set(cacheKey, res) | ||
return res | ||
} | ||
descriptor.value.dropCache = () => { | ||
console.log(`memo.dropCache (method=${key})`) | ||
} as any | ||
;(descriptor.value as any).dropCache = () => { | ||
console.log(`memo.dropCache (method=${String(key)})`) | ||
cache.clear() | ||
@@ -79,0 +79,0 @@ } |
import { memo } from './decorators/memo.decorator' | ||
import { memoCache } from './decorators/memoCache.decorator' | ||
import { memoPromise } from './decorators/memoPromise.decorator' | ||
import { AppError } from './error/app.error' | ||
@@ -57,2 +58,3 @@ import { | ||
memoCache, | ||
memoPromise, | ||
ErrorData, | ||
@@ -59,0 +61,0 @@ ErrorObject, |
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
134073
99
2508