fix(core): update

This commit is contained in:
Philipp Kunz 2021-04-23 18:41:30 +00:00
parent d18f4b6928
commit 17b59fd222
14 changed files with 79 additions and 46 deletions

4
.gitignore vendored
View File

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

View File

@ -19,22 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
auditProductionDependencies:
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
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- 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:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -84,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

View File

@ -35,11 +35,15 @@
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}
}

View File

@ -8,13 +8,20 @@ a cache that uses memory/disk/s3 as backup
* [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/)
## Status for master
[![pipeline status](https://gitlab.com/pushrocks/levelcache/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/levelcache/commits/master)
[![coverage report](https://gitlab.com/pushrocks/levelcache/badges/master/coverage.svg)](https://gitlab.com/pushrocks/levelcache/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/levelcache.svg)](https://www.npmjs.com/package/@pushrocks/levelcache)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/levelcache/badge.svg)](https://snyk.io/test/npm/@pushrocks/levelcache)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/levelcache/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/levelcache/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/levelcache)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/levelcache)](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/levelcache)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/levelcache)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/levelcache)](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

View File

@ -6,17 +6,20 @@ let testLevelCache: levelcache.LevelCache;
tap.test('should create a new levelcache instance', async () => {
testLevelCache = new levelcache.LevelCache({
cacheId: 'myCache'
cacheId: 'myCache',
});
expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache);
});
tap.test('should cache a value', async () => {
await testLevelCache.storeCacheEntryByKey('mykey', new CacheEntry({
contents: Buffer.from('heythere'),
ttl: 10000,
typeInfo: 'string'
}));
await testLevelCache.storeCacheEntryByKey(
'mykey',
new CacheEntry({
contents: Buffer.from('heythere'),
ttl: 10000,
typeInfo: 'string',
})
);
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
console.log(result);
});

View File

@ -1,3 +1,2 @@
export * from './levelcache.classes.levelcache';
export * from './levelcache.classes.cacheentry';

View File

@ -1,9 +1,9 @@
import { CacheEntry } from "./levelcache.classes.cacheentry";
import { CacheEntry } from './levelcache.classes.cacheentry';
export abstract class AbstractCache {
public abstract ready: Promise<void>;
public abstract status: 'active' | 'inactive';
// Blobs
/**
* store a Blob
@ -22,4 +22,4 @@ export abstract class AbstractCache {
* cleans the cache
*/
public abstract clean(): Promise<void>;
}
}

View File

@ -10,9 +10,9 @@ import { CacheEntry } from './levelcache.classes.cacheentry';
export class CacheDiskManager extends AbstractCache {
private levelCacheRef: LevelCache;
private readyDeferred = plugins.smartpromise.defer<void>();
public ready = this.readyDeferred.promise;
public status: 'active' | 'inactive';
public status: 'active' | 'inactive';
public fsPath: string;
public maxCacheSizeInMb: number;
@ -24,7 +24,10 @@ export class CacheDiskManager extends AbstractCache {
public async init() {
if (this.levelCacheRef.options.diskStoragePath) {
this.fsPath = plugins.path.join(this.levelCacheRef.options.diskStoragePath, this.levelCacheRef.options.cacheId);
this.fsPath = plugins.path.join(
this.levelCacheRef.options.diskStoragePath,
this.levelCacheRef.options.cacheId
);
} else {
this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId);
}
@ -35,12 +38,17 @@ export class CacheDiskManager extends AbstractCache {
}
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
const fileString = await plugins.smartfile.fs.toStringSync(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
const fileString = await plugins.smartfile.fs.toStringSync(
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
);
return CacheEntry.fromStorageJsonString(fileString);
}
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
await plugins.smartfile.memory.toFs(cacheEntryArg.foldToJson(), plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
await plugins.smartfile.memory.toFs(
cacheEntryArg.foldToJson(),
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
);
}
public async checkKeyPresence(keyArg): Promise<boolean> {

View File

@ -7,7 +7,7 @@ export class CacheMemoryManager extends AbstractCache {
private levelCacheRef: LevelCache;
private fastMap = new plugins.lik.FastMap<CacheEntry>();
private readyDeferred = plugins.smartpromise.defer<void>();
public ready = this.readyDeferred.promise;
public status: 'active' | 'inactive';
@ -41,5 +41,4 @@ export class CacheMemoryManager extends AbstractCache {
public async clean() {
this.fastMap.clean();
}
}

View File

@ -48,7 +48,10 @@ export class CacheS3Manager extends AbstractCache {
}
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
await this.s3CacheDir.fastStore(encodeURIComponent(keyArg), cacheEntryArg.toStorageJsonString());
await this.s3CacheDir.fastStore(
encodeURIComponent(keyArg),
cacheEntryArg.toStorageJsonString()
);
}
public async checkKeyPresence(keyArg: string): Promise<boolean> {

View File

@ -10,7 +10,9 @@ export interface ICacheEntryConstructorOptions {
/**
* a CacheEntry
*/
export class CacheEntry extends plugins.smartjson.Smartjson implements ICacheEntryConstructorOptions {
export class CacheEntry
extends plugins.smartjson.Smartjson
implements ICacheEntryConstructorOptions {
public static fromStorageJsonString(storageJsonString: string) {
return new CacheEntry(plugins.smartjson.parse(storageJsonString));
}
@ -23,7 +25,7 @@ export class CacheEntry extends plugins.smartjson.Smartjson implements ICacheEnt
@plugins.smartjson.foldDec()
public typeInfo: string;
@plugins.smartjson.foldDec()
contents: Buffer;

View File

@ -46,7 +46,7 @@ export class CacheRouter {
if (!returnCache && this.levelCacheRef.options.persistentCache) {
const checkCache = (cacheArg: AbstractCache) => {
const resultPromise = cacheArg.checkKeyPresence(keyArg);
resultPromise.then(hasKeyArg => {
resultPromise.then((hasKeyArg) => {
if (hasKeyArg) {
done.resolve(cacheArg);
}
@ -56,7 +56,7 @@ export class CacheRouter {
Promise.all([
checkCache(this.levelCacheRef.cacheMemoryManager),
checkCache(this.levelCacheRef.cacheDiskManager),
checkCache(this.levelCacheRef.cacheMemoryManager)
checkCache(this.levelCacheRef.cacheMemoryManager),
]).then(() => {
done.resolve(returnCache);
});

View File

@ -79,12 +79,11 @@ export class LevelCache extends AbstractCache {
}
}
public async checkKeyPresence(keyArg: string): Promise<boolean> {
return plugins.smartpromise.getFirstTrueOrFalse([
this.cacheMemoryManager.checkKeyPresence(keyArg),
this.cacheDiskManager.checkKeyPresence(keyArg),
this.cacheS3Manager.checkKeyPresence(keyArg)
this.cacheS3Manager.checkKeyPresence(keyArg),
]);
}