From 17b59fd2224accbc0391fb4a6bfbbfb149a62ba7 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 23 Apr 2021 18:41:30 +0000 Subject: [PATCH] fix(core): update --- .gitignore | 4 +-- .gitlab-ci.yml | 29 ++++++++++++++------ .vscode/settings.json | 2 +- package.json | 8 ++++-- readme.md | 21 +++++++++----- test/test.ts | 15 ++++++---- ts/index.ts | 1 - ts/levelcache.abstract.classes.cache.ts | 6 ++-- ts/levelcache.classes.cache.diskmanager.ts | 18 ++++++++---- ts/levelcache.classes.cache.memorymanager.ts | 3 +- ts/levelcache.classes.cache.s3manager.ts | 5 +++- ts/levelcache.classes.cacheentry.ts | 6 ++-- ts/levelcache.classes.cacherouter.ts | 4 +-- ts/levelcache.classes.levelcache.ts | 3 +- 14 files changed, 79 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index 91c0db0..ef13c79 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,6 @@ node_modules/ # builds dist/ -dist_web/ -dist_serve/ -dist_ts_web/ +dist_*/ # custom \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a95dfb6..9a4467e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 01d2b8d..3648eaa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,7 @@ "properties": { "projectType": { "type": "string", - "enum": ["website", "element", "service", "npm"] + "enum": ["website", "element", "service", "npm", "wcc"] } } } diff --git a/package.json b/package.json index 26c24be..30754ad 100644 --- a/package.json +++ b/package.json @@ -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" ] -} +} \ No newline at end of file diff --git a/readme.md b/readme.md index ad711fc..7f79b33 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/test/test.ts b/test/test.ts index e768e5b..aa39b91 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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); }); diff --git a/ts/index.ts b/ts/index.ts index 2f1acf2..ae319ca 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,2 @@ export * from './levelcache.classes.levelcache'; export * from './levelcache.classes.cacheentry'; - diff --git a/ts/levelcache.abstract.classes.cache.ts b/ts/levelcache.abstract.classes.cache.ts index 32a02f7..3e5389d 100644 --- a/ts/levelcache.abstract.classes.cache.ts +++ b/ts/levelcache.abstract.classes.cache.ts @@ -1,9 +1,9 @@ -import { CacheEntry } from "./levelcache.classes.cacheentry"; +import { CacheEntry } from './levelcache.classes.cacheentry'; export abstract class AbstractCache { public abstract ready: Promise; public abstract status: 'active' | 'inactive'; - + // Blobs /** * store a Blob @@ -22,4 +22,4 @@ export abstract class AbstractCache { * cleans the cache */ public abstract clean(): Promise; -} \ No newline at end of file +} diff --git a/ts/levelcache.classes.cache.diskmanager.ts b/ts/levelcache.classes.cache.diskmanager.ts index d619fa3..c7314d3 100644 --- a/ts/levelcache.classes.cache.diskmanager.ts +++ b/ts/levelcache.classes.cache.diskmanager.ts @@ -10,9 +10,9 @@ import { CacheEntry } from './levelcache.classes.cacheentry'; export class CacheDiskManager extends AbstractCache { private levelCacheRef: LevelCache; private readyDeferred = plugins.smartpromise.defer(); - + 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 { - 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 { diff --git a/ts/levelcache.classes.cache.memorymanager.ts b/ts/levelcache.classes.cache.memorymanager.ts index d993040..ffe29a1 100644 --- a/ts/levelcache.classes.cache.memorymanager.ts +++ b/ts/levelcache.classes.cache.memorymanager.ts @@ -7,7 +7,7 @@ export class CacheMemoryManager extends AbstractCache { private levelCacheRef: LevelCache; private fastMap = new plugins.lik.FastMap(); private readyDeferred = plugins.smartpromise.defer(); - + public ready = this.readyDeferred.promise; public status: 'active' | 'inactive'; @@ -41,5 +41,4 @@ export class CacheMemoryManager extends AbstractCache { public async clean() { this.fastMap.clean(); } - } diff --git a/ts/levelcache.classes.cache.s3manager.ts b/ts/levelcache.classes.cache.s3manager.ts index 2b2a707..486ddc7 100644 --- a/ts/levelcache.classes.cache.s3manager.ts +++ b/ts/levelcache.classes.cache.s3manager.ts @@ -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 { diff --git a/ts/levelcache.classes.cacheentry.ts b/ts/levelcache.classes.cacheentry.ts index c872023..b974a4f 100644 --- a/ts/levelcache.classes.cacheentry.ts +++ b/ts/levelcache.classes.cacheentry.ts @@ -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; diff --git a/ts/levelcache.classes.cacherouter.ts b/ts/levelcache.classes.cacherouter.ts index 0d943a7..1f19fbd 100644 --- a/ts/levelcache.classes.cacherouter.ts +++ b/ts/levelcache.classes.cacherouter.ts @@ -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); }); diff --git a/ts/levelcache.classes.levelcache.ts b/ts/levelcache.classes.levelcache.ts index 4e40e87..dae91ce 100644 --- a/ts/levelcache.classes.levelcache.ts +++ b/ts/levelcache.classes.levelcache.ts @@ -79,12 +79,11 @@ export class LevelCache extends AbstractCache { } } - public async checkKeyPresence(keyArg: string): Promise { return plugins.smartpromise.getFirstTrueOrFalse([ this.cacheMemoryManager.checkKeyPresence(keyArg), this.cacheDiskManager.checkKeyPresence(keyArg), - this.cacheS3Manager.checkKeyPresence(keyArg) + this.cacheS3Manager.checkKeyPresence(keyArg), ]); }