Comparing version 2.1.1 to 2.2.0
@@ -1,1 +0,1 @@ | ||
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.each=exports.getKeysOfItems=exports.getValuesOfItems=exports.purgeManyByCondition=exports.getManyByCondition=exports.getAmountOfItems=exports.getMany=exports.purgeMany=exports.destroy=exports.prune=exports.has=exports.purge=exports.view=exports.update=exports.get=exports.set=exports.Cachu=void 0;var instance_1=require("./instance");Object.defineProperty(exports,"Cachu",{enumerable:!0,get:function(){return instance_1.Cachu}});var global_1=__importDefault(require("./global"));exports.default=global_1.default;var global_2=require("./global");Object.defineProperty(exports,"set",{enumerable:!0,get:function(){return global_2.set}}),Object.defineProperty(exports,"get",{enumerable:!0,get:function(){return global_2.get}}),Object.defineProperty(exports,"update",{enumerable:!0,get:function(){return global_2.update}}),Object.defineProperty(exports,"view",{enumerable:!0,get:function(){return global_2.view}}),Object.defineProperty(exports,"purge",{enumerable:!0,get:function(){return global_2.purge}}),Object.defineProperty(exports,"has",{enumerable:!0,get:function(){return global_2.has}}),Object.defineProperty(exports,"prune",{enumerable:!0,get:function(){return global_2.prune}}),Object.defineProperty(exports,"destroy",{enumerable:!0,get:function(){return global_2.destroy}}),Object.defineProperty(exports,"purgeMany",{enumerable:!0,get:function(){return global_2.purgeMany}}),Object.defineProperty(exports,"getMany",{enumerable:!0,get:function(){return global_2.getMany}}),Object.defineProperty(exports,"getAmountOfItems",{enumerable:!0,get:function(){return global_2.getAmountOfItems}}),Object.defineProperty(exports,"getManyByCondition",{enumerable:!0,get:function(){return global_2.getManyByCondition}}),Object.defineProperty(exports,"purgeManyByCondition",{enumerable:!0,get:function(){return global_2.purgeManyByCondition}}),Object.defineProperty(exports,"getValuesOfItems",{enumerable:!0,get:function(){return global_2.getValuesOfItems}}),Object.defineProperty(exports,"getKeysOfItems",{enumerable:!0,get:function(){return global_2.getKeysOfItems}}),Object.defineProperty(exports,"each",{enumerable:!0,get:function(){return global_2.each}}); | ||
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,e,r){return new(e||(e=Promise))((function(i,o){function u(t){try{a(r.next(t))}catch(t){o(t)}}function s(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,s)}a((r=r.apply(t,n||[])).next())}))},__generator=this&&this.__generator||function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!((i=(i=u.trys).length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(t,u)}catch(t){o=[6,t],r=0}finally{e=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;var Cachu=function(t){var n,e,r=this;this.set=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){return-1!==this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:(this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*r.maxAge.valueOf()})),this.store.length===this.maxAmount&&(e=this.store.reduce((function(t,n){return t[2]<n[2]?t:n})),this.store.splice(this.store.findIndex((function(t){return t[0]===e[0]})),1)),this.store.push([t,n,Date.now()]),[2,!0])}))}))},this.get=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*e.maxAge.valueOf()})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.view=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*e.maxAge.valueOf()||n[0]===t})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.update=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e;return __generator(this,(function(r){return-1===(e=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store[e]=[t,n,Date.now()],[2,!0])}))}))},this.has=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return-1===this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:[2,!0]}))}))},this.purge=function(t){return __awaiter(r,void 0,void 0,(function(){var n;return __generator(this,(function(e){return-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store.splice(n,1),[2,!0])}))}))},this.prune=function(){return __awaiter(r,void 0,void 0,(function(){var t=this;return __generator(this,(function(n){return this.store.length>0&&(this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*t.maxAge.valueOf()}))),[2,!0]}))}))},this.destroy=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return this.store=[],[2,!0]}))}))},this.purgeMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r;return __generator(this,(function(i){switch(i.label){case 0:n=0,e=t,i.label=1;case 1:return n<e.length?(r=e[n],[4,this.purge(r)]):[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2,!0]}}))}))},this.getMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r,i,o;return __generator(this,(function(u){switch(u.label){case 0:n=[],e=0,r=t,u.label=1;case 1:return e<r.length?(i=r[e],[4,this.get(i)]):[3,4];case 2:null===(o=u.sent())&&void 0===o||n.push(o),u.label=3;case 3:return e++,[3,1];case 4:return[2,n]}}))}))},this.purgeManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return this.store=this.store.filter((function(n){return!t(n)})),[2,!0]}))}))},this.getManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return[2,this.store.filter((function(n){return t(n)}))]}))}))},this.getAmountOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.store.length]}))}))},this.getValuesOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[1]}))]}))}))},this.getKeysOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[0]}))]}))}))},this.each=function(t){return __awaiter(r,void 0,void 0,(function(){var n=this;return __generator(this,(function(e){return this.store.forEach((function(e){return __awaiter(n,void 0,void 0,(function(){return __generator(this,(function(n){switch(n.label){case 0:return[4,t(e)];case 1:return n.sent(),[2]}}))}))})),[2,!0]}))}))},t||(t={}),this.maxAmount=null!==(n=t.maxAmount)&&void 0!==n?n:1/0,this.maxAge=null!==(e=t.maxAge)&&void 0!==e?e:1/0,this.store=[]};exports.Cachu=Cachu; |
{ | ||
"name": "cachu", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Simple, minimalistic key-value cache.", | ||
@@ -9,7 +9,7 @@ "main": "build/index.js", | ||
"build": "tsc", | ||
"build:dev": "tsc -w", | ||
"build:watch": "tsc -w", | ||
"minify": "node minify.mjs", | ||
"release:patch": "npm run minify && npm version patch && npm publish", | ||
"release:minor": "npm run minify && npm version minor && npm publish", | ||
"release:major": "npm run minify && npm version major && npm publish", | ||
"push:patch": "npm run minify && npm version patch && npm publish", | ||
"push:minor": "npm run minify && npm version minor && npm publish", | ||
"push:major": "npm run minify && npm version major && npm publish", | ||
"test": "node dev/instance.mjs" | ||
@@ -44,5 +44,5 @@ }, | ||
"engines": { | ||
"node": ">=16.13.0", | ||
"npm": ">=8.1.0" | ||
"node": ">=16.0.0", | ||
"npm": ">=8.0.0" | ||
} | ||
} |
@@ -11,3 +11,3 @@ # cachu | ||
🤫 All the upcoming features are listed [over here](https://github.com/azurystudios/cachu/projects/1). | ||
Upcoming features are listed [over here](https://github.com/azurystudios/cachu/projects/1). | ||
@@ -23,5 +23,6 @@ ## Installation | ||
yarn add cachu | ||
pnpm add cachu | ||
``` | ||
### Class Instance | ||
### Create New Instance | ||
@@ -38,27 +39,9 @@ Recommended if you need multiple caches. | ||
(async () => { | ||
const demo = async () => { | ||
await cache.set(123, 'hello world') | ||
console.log(await cache.get(123)) | ||
})() | ||
} | ||
demo() | ||
``` | ||
### Global Instance | ||
Recommended if you need only one cache or want to configure cachu globally. | ||
```js | ||
import cachu, { set, get } from 'cachu' | ||
// configure cachu globally (optional) | ||
cachu({ | ||
maxAmount: 10, // cache can contain up to 10 items | ||
maxAge: 60 // delete items after a minute | ||
}) | ||
(async () => { | ||
await set(123, 'hello world') | ||
console.log(await get(123)) | ||
})() | ||
``` | ||
## API | ||
@@ -65,0 +48,0 @@ |
@@ -1,4 +0,27 @@ | ||
export { Cachu } from './instance'; | ||
import global from './global'; | ||
export default global; | ||
export { set, get, update, view, purge, has, prune, destroy, purgeMany, getMany, getAmountOfItems, getManyByCondition, purgeManyByCondition, getValuesOfItems, getKeysOfItems, each } from './global'; | ||
interface Config { | ||
maxAge?: number | undefined; | ||
maxAmount?: number | undefined; | ||
} | ||
export declare class Cachu { | ||
private maxAmount; | ||
private maxAge; | ||
private store; | ||
constructor(config?: Config); | ||
set: (key: {}, value: {}) => Promise<boolean>; | ||
get: (key: {}) => Promise<any>; | ||
view: (key: {}) => Promise<any>; | ||
update: (key: {}, value: {}) => Promise<boolean>; | ||
has: (key: {}) => Promise<boolean>; | ||
purge: (key: {}) => Promise<boolean>; | ||
prune: () => Promise<boolean>; | ||
destroy: () => Promise<boolean>; | ||
purgeMany: (keys: Array<any>) => Promise<boolean>; | ||
getMany: (keys: Array<any>) => Promise<any[]>; | ||
purgeManyByCondition: (condition: Function) => Promise<boolean>; | ||
getManyByCondition: (condition: Function) => Promise<any[]>; | ||
getAmountOfItems: () => Promise<number>; | ||
getValuesOfItems: () => Promise<any[] | undefined>; | ||
getKeysOfItems: () => Promise<any[] | undefined>; | ||
each: (action: Function) => Promise<boolean>; | ||
} | ||
export {}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
0
0
22107
5
27
69
1