fix(core): update
This commit is contained in:
		
							
								
								
									
										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 | ||||||
| @@ -19,22 +19,35 @@ 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 | ||||||
|  |  | ||||||
|  | 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 +62,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 +73,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,6 +93,8 @@ 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 tslint typescript | ||||||
|     - npmci npm prepare |     - npmci npm prepare | ||||||
|   | |||||||
							
								
								
									
										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"] | ||||||
|               } |               } | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|   | |||||||
| @@ -35,11 +35,15 @@ | |||||||
|     "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" | ||||||
|   ] |   ] | ||||||
| } | } | ||||||
							
								
								
									
										21
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								readme.md
									
									
									
									
									
								
							| @@ -8,13 +8,20 @@ a cache that uses memory/disk/s3 as backup | |||||||
| * [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/) | * [docs (typedoc)](https://pushrocks.gitlab.io/levelcache/) | ||||||
|  |  | ||||||
| ## Status for master | ## Status for master | ||||||
| [](https://gitlab.com/pushrocks/levelcache/commits/master) |  | ||||||
| [](https://gitlab.com/pushrocks/levelcache/commits/master) | Status Category | Status Badge | ||||||
| [](https://www.npmjs.com/package/@pushrocks/levelcache) | -- | -- | ||||||
| [](https://snyk.io/test/npm/@pushrocks/levelcache) | 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 | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										15
									
								
								test/test.ts
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								test/test.ts
									
									
									
									
									
								
							| @@ -6,17 +6,20 @@ let testLevelCache: levelcache.LevelCache; | |||||||
|  |  | ||||||
| tap.test('should create a new levelcache instance', async () => { | tap.test('should create a new levelcache instance', async () => { | ||||||
|   testLevelCache = new levelcache.LevelCache({ |   testLevelCache = new levelcache.LevelCache({ | ||||||
|     cacheId: 'myCache' |     cacheId: 'myCache', | ||||||
|   }); |   }); | ||||||
|   expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache); |   expect(testLevelCache).to.be.instanceOf(levelcache.LevelCache); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| tap.test('should cache a value', async () => { | tap.test('should cache a value', async () => { | ||||||
|   await testLevelCache.storeCacheEntryByKey('mykey', new CacheEntry({ |   await testLevelCache.storeCacheEntryByKey( | ||||||
|     contents: Buffer.from('heythere'), |     'mykey', | ||||||
|     ttl: 10000, |     new CacheEntry({ | ||||||
|     typeInfo: 'string' |       contents: Buffer.from('heythere'), | ||||||
|   })); |       ttl: 10000, | ||||||
|  |       typeInfo: 'string', | ||||||
|  |     }) | ||||||
|  |   ); | ||||||
|   const result = await testLevelCache.retrieveCacheEntryByKey('mykey'); |   const result = await testLevelCache.retrieveCacheEntryByKey('mykey'); | ||||||
|   console.log(result); |   console.log(result); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -1,3 +1,2 @@ | |||||||
| export * from './levelcache.classes.levelcache'; | export * from './levelcache.classes.levelcache'; | ||||||
| export * from './levelcache.classes.cacheentry'; | export * from './levelcache.classes.cacheentry'; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import { CacheEntry } from "./levelcache.classes.cacheentry"; | import { CacheEntry } from './levelcache.classes.cacheentry'; | ||||||
|  |  | ||||||
| export abstract class AbstractCache { | export abstract class AbstractCache { | ||||||
|   public abstract ready: Promise<void>; |   public abstract ready: Promise<void>; | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ export class CacheDiskManager extends AbstractCache { | |||||||
|   private readyDeferred = plugins.smartpromise.defer<void>(); |   private readyDeferred = plugins.smartpromise.defer<void>(); | ||||||
|  |  | ||||||
|   public ready = this.readyDeferred.promise; |   public ready = this.readyDeferred.promise; | ||||||
|   public status: 'active' | 'inactive'; |   public status: 'active' | 'inactive'; | ||||||
|   public fsPath: string; |   public fsPath: string; | ||||||
|   public maxCacheSizeInMb: number; |   public maxCacheSizeInMb: number; | ||||||
|  |  | ||||||
| @@ -24,7 +24,10 @@ export class CacheDiskManager extends AbstractCache { | |||||||
|  |  | ||||||
|   public async init() { |   public async init() { | ||||||
|     if (this.levelCacheRef.options.diskStoragePath) { |     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 { |     } else { | ||||||
|       this.fsPath = plugins.path.join(paths.nogitDir, this.levelCacheRef.options.cacheId); |       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> { |   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); |     return CacheEntry.fromStorageJsonString(fileString); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) { |   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> { |   public async checkKeyPresence(keyArg): Promise<boolean> { | ||||||
|   | |||||||
| @@ -41,5 +41,4 @@ export class CacheMemoryManager extends AbstractCache { | |||||||
|   public async clean() { |   public async clean() { | ||||||
|     this.fastMap.clean(); |     this.fastMap.clean(); | ||||||
|   } |   } | ||||||
|    |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -48,7 +48,10 @@ export class CacheS3Manager extends AbstractCache { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) { |   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> { |   public async checkKeyPresence(keyArg: string): Promise<boolean> { | ||||||
|   | |||||||
| @@ -10,7 +10,9 @@ export interface ICacheEntryConstructorOptions { | |||||||
| /** | /** | ||||||
|  * a CacheEntry |  * 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) { |   public static fromStorageJsonString(storageJsonString: string) { | ||||||
|     return new CacheEntry(plugins.smartjson.parse(storageJsonString)); |     return new CacheEntry(plugins.smartjson.parse(storageJsonString)); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ export class CacheRouter { | |||||||
|     if (!returnCache && this.levelCacheRef.options.persistentCache) { |     if (!returnCache && this.levelCacheRef.options.persistentCache) { | ||||||
|       const checkCache = (cacheArg: AbstractCache) => { |       const checkCache = (cacheArg: AbstractCache) => { | ||||||
|         const resultPromise = cacheArg.checkKeyPresence(keyArg); |         const resultPromise = cacheArg.checkKeyPresence(keyArg); | ||||||
|         resultPromise.then(hasKeyArg => { |         resultPromise.then((hasKeyArg) => { | ||||||
|           if (hasKeyArg) { |           if (hasKeyArg) { | ||||||
|             done.resolve(cacheArg); |             done.resolve(cacheArg); | ||||||
|           } |           } | ||||||
| @@ -56,7 +56,7 @@ export class CacheRouter { | |||||||
|       Promise.all([ |       Promise.all([ | ||||||
|         checkCache(this.levelCacheRef.cacheMemoryManager), |         checkCache(this.levelCacheRef.cacheMemoryManager), | ||||||
|         checkCache(this.levelCacheRef.cacheDiskManager), |         checkCache(this.levelCacheRef.cacheDiskManager), | ||||||
|         checkCache(this.levelCacheRef.cacheMemoryManager) |         checkCache(this.levelCacheRef.cacheMemoryManager), | ||||||
|       ]).then(() => { |       ]).then(() => { | ||||||
|         done.resolve(returnCache); |         done.resolve(returnCache); | ||||||
|       }); |       }); | ||||||
|   | |||||||
| @@ -79,12 +79,11 @@ export class LevelCache extends AbstractCache { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   public async checkKeyPresence(keyArg: string): Promise<boolean> { |   public async checkKeyPresence(keyArg: string): Promise<boolean> { | ||||||
|     return plugins.smartpromise.getFirstTrueOrFalse([ |     return plugins.smartpromise.getFirstTrueOrFalse([ | ||||||
|       this.cacheMemoryManager.checkKeyPresence(keyArg), |       this.cacheMemoryManager.checkKeyPresence(keyArg), | ||||||
|       this.cacheDiskManager.checkKeyPresence(keyArg), |       this.cacheDiskManager.checkKeyPresence(keyArg), | ||||||
|       this.cacheS3Manager.checkKeyPresence(keyArg) |       this.cacheS3Manager.checkKeyPresence(keyArg), | ||||||
|     ]); |     ]); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user