Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
b6c4ef568a | |||
c7682e4cc5 | |||
677b07a176 | |||
0e11d0e760 | |||
1f80df6ec2 | |||
05997ef1cf |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@@ -19,22 +22,36 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --production --ignore-scripts
|
||||||
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
auditDevDependencies:
|
||||||
|
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 --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@@ -49,9 +66,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@@ -62,9 +77,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@@ -84,11 +97,12 @@ 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:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@@ -108,11 +122,10 @@ trigger:
|
|||||||
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
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
"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"
|
||||||
}
|
}
|
||||||
|
1635
package-lock.json
generated
1635
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@@ -1,41 +1,45 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcache",
|
"name": "@pushrocks/smartcache",
|
||||||
"version": "1.0.13",
|
"version": "1.0.16",
|
||||||
"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.2.0",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^13.7.0",
|
"@types/node": "^18.0.0"
|
||||||
"tslint": "^6.0.0",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.6",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smarterror": "^2.0.1",
|
"@pushrocks/smarterror": "^2.0.1",
|
||||||
"@pushrocks/smarthash": "^2.1.6",
|
"@pushrocks/smarthash": "^3.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smarttime": "^3.0.12"
|
"@pushrocks/smarttime": "^4.0.1"
|
||||||
},
|
},
|
||||||
"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"
|
||||||
}
|
}
|
||||||
|
4314
pnpm-lock.yaml
generated
Normal file
4314
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
readme.md
24
readme.md
@@ -8,16 +8,26 @@ 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
|
||||||
[](https://gitlab.com/pushrocks/smartcache/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartcache/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartcache)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartcache)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](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
|
## Contribution
|
||||||
|
|
||||||
|
25
test/test.ts
25
test/test.ts
@@ -1,35 +1,38 @@
|
|||||||
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 1 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');
|
||||||
|
response2Counter++;
|
||||||
return 'hello there!';
|
return 'hello there!';
|
||||||
}, 1000)
|
}, 1000)
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
console.log('response is:');
|
console.log('response is:');
|
||||||
@@ -40,12 +43,12 @@ tap.test('try to get async responses', async () => {
|
|||||||
await getResponse();
|
await getResponse();
|
||||||
await getResponse2();
|
await getResponse2();
|
||||||
await getResponse2();
|
await getResponse2();
|
||||||
await smartdelay.delayFor(2000).then(async () => {
|
await toolsArg.delayFor(500);
|
||||||
await getResponse();
|
await getResponse();
|
||||||
await getResponse2();
|
await toolsArg.delayFor(2000);
|
||||||
});
|
await getResponse2();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start({
|
tap.start({
|
||||||
throwOnError: true
|
throwOnError: true,
|
||||||
});
|
});
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartcache',
|
||||||
|
version: '1.0.16',
|
||||||
|
description: 'cache things in smart ways'
|
||||||
|
}
|
@@ -1 +1 @@
|
|||||||
export * from './smartcache.classes.smartcache';
|
export * from './smartcache.classes.smartcache.js';
|
||||||
|
@@ -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(() => {
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
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) {
|
||||||
const callStack: string = new plugins.smarterror.SmartError('Cache Creation Point').cleanFullStack.split('\n')[2];
|
const callStack: string = new plugins.smarterror.SmartError(
|
||||||
|
'Cache Creation Point'
|
||||||
|
).cleanFullStack.split('\n')[2];
|
||||||
const callHash = plugins.smarthash.sha256FromStringSync(callStack);
|
const callHash = plugins.smarthash.sha256FromStringSync(callStack);
|
||||||
|
|
||||||
// console.log(callHash);
|
// console.log(callHash);
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@@ -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"
|
|
||||||
}
|
|
Reference in New Issue
Block a user