6 Commits

Author SHA1 Message Date
677b07a176 1.0.15 2022-06-26 20:36:23 +02:00
0e11d0e760 fix(core): update 2022-06-26 20:36:22 +02:00
1f80df6ec2 1.0.14 2021-04-21 19:52:53 +00:00
05997ef1cf fix(core): update 2021-04-21 19:52:53 +00:00
dc5a93b3a2 1.0.13 2020-02-03 20:08:58 +00:00
51c1759961 fix(core): update 2020-02-03 20:08:57 +00:00
15 changed files with 10685 additions and 957 deletions

4
.gitignore vendored
View File

@@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@@ -3,14 +3,17 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
before_script:
- npm install -g @shipzone/npmci
# ==================== # ====================
# security stage # security stage
@@ -18,21 +21,37 @@ stages:
mirror: mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk - npmci command npm install --production --ignore-scripts
- npmci command npm install --ignore-scripts - npmci command npm config set registry https://registry.npmjs.org
- npmci command snyk test - npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
- notpriv allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ==================== # ====================
# test stage # test stage
@@ -41,37 +60,36 @@ snyk:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# metadata stage # metadata stage
@@ -79,34 +97,37 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- docker - lossless
- priv - docker
- priv
trigger: trigger:
stage: metadata stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:
@@ -114,5 +135,5 @@ pages:
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@@ -4,11 +4,12 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",
"gitrepo": "smartcache", "gitrepo": "smartcache",
"shortDescription": "cache things in smart ways", "description": "cache things in smart ways",
"npmPackagename": "@pushrocks/smartcache", "npmPackagename": "@pushrocks/smartcache",
"license": "MIT" "license": "MIT"
} }

11331
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,41 +1,47 @@
{ {
"name": "@pushrocks/smartcache", "name": "@pushrocks/smartcache",
"version": "1.0.12", "version": "1.0.15",
"private": false, "private": false,
"description": "cache things in smart ways", "description": "cache things in smart ways",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)" "build": "(tsbuild)",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.37",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^12.11.5", "@types/node": "^18.0.0",
"tslint": "^5.20.0", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smarterror": "^2.0.1", "@pushrocks/smarterror": "^2.0.1",
"@pushrocks/smarthash": "^2.0.6", "@pushrocks/smarthash": "^3.0.1",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smarttime": "^3.0.12" "@pushrocks/smarttime": "^3.0.45"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
} }

View File

@@ -8,16 +8,31 @@ cache things in smart ways
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcache/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartcache/)
## Status for master ## Status for master
[![build status](https://gitlab.com/pushrocks/smartcache/badges/master/build.svg)](https://gitlab.com/pushrocks/smartcache/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartcache/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartcache/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartcache.svg)](https://www.npmjs.com/package/@pushrocks/smartcache) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartcache/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartcache) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartcache/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartcache/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartcache)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartcache)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartcache)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartcache)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartcache)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)

View File

@@ -1,51 +1,54 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as smartcache from '../ts/index'; import * as smartcache from '../ts/index.js';
import * as smartdelay from '@pushrocks/smartdelay';
let smartcacheInstance: smartcache.SmartCache; let smartcacheInstance: smartcache.SmartCache;
tap.test('should create a valid instance of SmartCache', async () => { tap.test('should create a valid instance of SmartCache', async () => {
smartcacheInstance = new smartcache.SmartCache(); smartcacheInstance = new smartcache.SmartCache();
expect(smartcacheInstance).to.be.instanceof(smartcache.SmartCache); expect(smartcacheInstance).toBeInstanceOf(smartcache.SmartCache);
}); });
tap.test('try to get async responses', async () => { tap.test('try to get async responses', async (toolsArg) => {
let response1Counter = 0;
const getResponse = async () => { const getResponse = async () => {
const response = await smartcacheInstance const response = await smartcacheInstance
.cacheReturn(async () => { .cacheReturn(async () => {
console.log('function ran'); console.log('function 1 ran');
response1Counter++;
return 'hello'; return 'hello';
}, 1000) }, 1000)
.catch(err => { .catch((err) => {
console.log(err); console.log(err);
}); });
console.log('response is:'); console.log('response is:');
console.log(response); console.log(response);
}; };
let response2Counter = 0;
const getResponse2 = async () => { const getResponse2 = async () => {
const response = await smartcacheInstance const response = await smartcacheInstance
.cacheReturn(async () => { .cacheReturn(async () => {
console.log('function 2 ran'); console.log('function 2 ran');
return 'hello'; response2Counter++;
return 'hello there!';
}, 1000) }, 1000)
.catch(err => { .catch((err) => {
console.log(err); console.log(err);
}); });
console.log('response is:'); console.log('response is:');
console.log(response); console.log(response);
}; };
getResponse(); await getResponse();
getResponse(); await getResponse();
getResponse2(); await getResponse2();
getResponse2(); await getResponse2();
await smartdelay.delayFor(1000).then(async () => { await toolsArg.delayFor(500);
await getResponse(); await getResponse();
// getResponse2(); await toolsArg.delayFor(2000);
}); await getResponse2();
}); });
tap.start({ tap.start({
throwOnError: true throwOnError: true,
}); });

8
ts/00_commitinfo_data.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartcache',
version: '1.0.15',
description: 'cache things in smart ways'
}

View File

@@ -1 +1 @@
export * from './smartcache.classes.smartcache'; export * from './smartcache.classes.smartcache.js';

View File

@@ -1,4 +1,4 @@
import * as plugins from './smartcache.plugins'; import * as plugins from './smartcache.plugins.js';
import { SmartError } from '@pushrocks/smarterror'; import { SmartError } from '@pushrocks/smarterror';
export interface ICacheMap { export interface ICacheMap {
@@ -12,7 +12,7 @@ export interface ICacheMap {
export class CacheManager { export class CacheManager {
private _cacheMap: ICacheMap = {}; private _cacheMap: ICacheMap = {};
cacheExists(identifierArg): boolean { cacheExists(identifierArg: string): boolean {
if (this._cacheMap[identifierArg]) { if (this._cacheMap[identifierArg]) {
return true; return true;
} }
@@ -36,7 +36,7 @@ export class CacheManager {
this._cacheMap[identifierArg] = { this._cacheMap[identifierArg] = {
timer: new plugins.smarttime.Timer(validForArg), timer: new plugins.smarttime.Timer(validForArg),
cachedDeferred: new plugins.smartpromise.Deferred(), cachedDeferred: new plugins.smartpromise.Deferred(),
cachedObject: null cachedObject: null,
}; };
this._cacheMap[identifierArg].timer.start(); this._cacheMap[identifierArg].timer.start();
this._cacheMap[identifierArg].timer.completed.then(() => { this._cacheMap[identifierArg].timer.completed.then(() => {

View File

@@ -1,12 +1,14 @@
import * as plugins from './smartcache.plugins'; import * as plugins from './smartcache.plugins.js';
import { CacheManager } from './smartcache.classes.cachemanager'; import { CacheManager } from './smartcache.classes.cachemanager.js';
export class SmartCache { export class SmartCache {
private _cacheManager = new CacheManager(); private _cacheManager = new CacheManager();
async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) { async cacheReturn(asyncCachedFuncArg: () => Promise<any>, cacheDuration: number = 5000) {
let callStack: string = new plugins.smarterror.SmartError('').cleanFullStack; const callStack: string = new plugins.smarterror.SmartError(
let callHash = plugins.smarthash.sha256FromStringSync(callStack); 'Cache Creation Point'
).cleanFullStack.split('\n')[2];
const callHash = plugins.smarthash.sha256FromStringSync(callStack);
// console.log(callHash); // console.log(callHash);
if ( if (
@@ -17,7 +19,7 @@ export class SmartCache {
return this._cacheManager.getCache(callHash).cachedObject; return this._cacheManager.getCache(callHash).cachedObject;
} else { } else {
this._cacheManager.announceCache(callHash, cacheDuration); this._cacheManager.announceCache(callHash, cacheDuration);
let newCachedObject = await asyncCachedFuncArg(); const newCachedObject = await asyncCachedFuncArg();
this._cacheManager.setCache(callHash, newCachedObject, cacheDuration); this._cacheManager.setCache(callHash, newCachedObject, cacheDuration);
return newCachedObject; return newCachedObject;
} }

9
tsconfig.json Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}

View File

@@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}