fix(core): Update CI workflows and dependencies; apply small bugfixes and formatting improvements
This commit is contained in:
@@ -6,8 +6,8 @@ on:
|
|||||||
- '**'
|
- '**'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
- name: Install pnpm and npmci
|
- name: Install pnpm and npmci
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
|
|
||||||
- name: Run npm prepare
|
- name: Run npm prepare
|
||||||
run: npmci npm prepare
|
run: npmci npm prepare
|
||||||
|
@@ -6,8 +6,8 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Audit production dependencies
|
- name: Audit production dependencies
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Test stable
|
- name: Test stable
|
||||||
@@ -82,7 +82,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
@@ -104,7 +104,7 @@ jobs:
|
|||||||
- name: Prepare
|
- name: Prepare
|
||||||
run: |
|
run: |
|
||||||
pnpm install -g pnpm
|
pnpm install -g pnpm
|
||||||
pnpm install -g @shipzone/npmci
|
pnpm install -g @ship.zone/npmci
|
||||||
npmci npm prepare
|
npmci npm prepare
|
||||||
|
|
||||||
- name: Code quality
|
- name: Code quality
|
||||||
|
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,7 +3,6 @@
|
|||||||
# artifacts
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
|
||||||
|
|
||||||
# installs
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
@@ -17,4 +16,8 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
dist_*/
|
dist_*/
|
||||||
|
|
||||||
# custom
|
# AI
|
||||||
|
.claude/
|
||||||
|
.serena/
|
||||||
|
|
||||||
|
#------# custom
|
27
changelog.md
27
changelog.md
@@ -1,12 +1,27 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-08-28 - 3.1.2 - fix(core)
|
||||||
|
Update CI workflows and dependencies; apply small bugfixes and formatting improvements
|
||||||
|
|
||||||
|
- Update Gitea workflow image URL and computed repo URL to internal registry and simplified repo path
|
||||||
|
- Switch npmci install target from @shipzone/npmci to @ship.zone/npmci in CI scripts
|
||||||
|
- Bump devDependencies and dependencies to newer versions (tsbuild, tstest, tapbundle, lik, smartbucket, smartfile, smartpath, smartpromise, taskbuffer, tsclass, etc.)
|
||||||
|
- Add package metadata: homepage anchor, packageManager, bugs URL and pnpm overrides block
|
||||||
|
- Fix TypeScript formatting and signatures (consistent trailing commas, multiline parameter lists, path join argument formatting)
|
||||||
|
- Fix file system and S3 manager calls to ensure consistent path handling and argument formatting (improved encoding/consistency in disk and S3 managers)
|
||||||
|
- Correct test file syntax (object commas) to avoid runtime/parse issues
|
||||||
|
- Update .gitignore to add AI tool folders and reorganize custom section
|
||||||
|
- Add pnpm-workspace.yaml with onlyBuiltDependencies entry
|
||||||
|
|
||||||
## 2024-11-26 - 3.1.1 - fix(core)
|
## 2024-11-26 - 3.1.1 - fix(core)
|
||||||
|
|
||||||
Fix S3 cache manager methods for better path encoding consistency
|
Fix S3 cache manager methods for better path encoding consistency
|
||||||
|
|
||||||
- Corrected path parameter usage in S3 manager methods to ensure encoding and consistency.
|
- Corrected path parameter usage in S3 manager methods to ensure encoding and consistency.
|
||||||
- Updated package.json Git dependencies for scoped packages.
|
- Updated package.json Git dependencies for scoped packages.
|
||||||
|
|
||||||
## 2024-11-24 - 3.1.0 - feat(core)
|
## 2024-11-24 - 3.1.0 - feat(core)
|
||||||
|
|
||||||
Enhanced caching solution with optional configurations and improved documentation.
|
Enhanced caching solution with optional configurations and improved documentation.
|
||||||
|
|
||||||
- Improved package description and keywords for better discoverability.
|
- Improved package description and keywords for better discoverability.
|
||||||
@@ -15,6 +30,7 @@ Enhanced caching solution with optional configurations and improved documentatio
|
|||||||
- Enhanced README with detailed usage instructions and examples.
|
- Enhanced README with detailed usage instructions and examples.
|
||||||
|
|
||||||
## 2024-05-29 to 2024-02-14 - 3.0.8
|
## 2024-05-29 to 2024-02-14 - 3.0.8
|
||||||
|
|
||||||
Minor configuration updates and documentation changes.
|
Minor configuration updates and documentation changes.
|
||||||
|
|
||||||
- Updated project description.
|
- Updated project description.
|
||||||
@@ -22,54 +38,65 @@ Minor configuration updates and documentation changes.
|
|||||||
- Adjustments to npmextra.json regarding githost.
|
- Adjustments to npmextra.json regarding githost.
|
||||||
|
|
||||||
## 2024-02-14 - 3.0.7
|
## 2024-02-14 - 3.0.7
|
||||||
|
|
||||||
Core enhancements and bug fixes.
|
Core enhancements and bug fixes.
|
||||||
|
|
||||||
- Fixed updates in the core module to improve stability.
|
- Fixed updates in the core module to improve stability.
|
||||||
|
|
||||||
## 2024-02-14 - 3.0.6
|
## 2024-02-14 - 3.0.6
|
||||||
|
|
||||||
Core maintenance and updates.
|
Core maintenance and updates.
|
||||||
|
|
||||||
- Implemented minor fixes in the core module.
|
- Implemented minor fixes in the core module.
|
||||||
|
|
||||||
## 2023-07-21 - 3.0.5
|
## 2023-07-21 - 3.0.5
|
||||||
|
|
||||||
Addressed core module adjustments.
|
Addressed core module adjustments.
|
||||||
|
|
||||||
- Patched core module to rectify issues.
|
- Patched core module to rectify issues.
|
||||||
|
|
||||||
## 2023-07-20 - 3.0.4
|
## 2023-07-20 - 3.0.4
|
||||||
|
|
||||||
Further improvements to core functionality.
|
Further improvements to core functionality.
|
||||||
|
|
||||||
- Additional fixes applied to the core component.
|
- Additional fixes applied to the core component.
|
||||||
|
|
||||||
## 2023-07-11 to 2023-07-10 - 3.0.3
|
## 2023-07-11 to 2023-07-10 - 3.0.3
|
||||||
|
|
||||||
Organizational and structural changes.
|
Organizational and structural changes.
|
||||||
|
|
||||||
- Transitioned to a new organizational scheme.
|
- Transitioned to a new organizational scheme.
|
||||||
|
|
||||||
## 2023-01-09 - 3.0.2
|
## 2023-01-09 - 3.0.2
|
||||||
|
|
||||||
Core module corrections.
|
Core module corrections.
|
||||||
|
|
||||||
- Resolved various issues within the core module.
|
- Resolved various issues within the core module.
|
||||||
|
|
||||||
## 2022-06-09 - 3.0.1
|
## 2022-06-09 - 3.0.1
|
||||||
|
|
||||||
Continuous enhancements in core functionality.
|
Continuous enhancements in core functionality.
|
||||||
|
|
||||||
- Continued bug fixes for core module efficiency.
|
- Continued bug fixes for core module efficiency.
|
||||||
|
|
||||||
## 2022-04-04 to 2022-04-02 - 3.0.0
|
## 2022-04-04 to 2022-04-02 - 3.0.0
|
||||||
|
|
||||||
Major release with significant updates.
|
Major release with significant updates.
|
||||||
|
|
||||||
## 2022-03-22 - 2.0.0
|
## 2022-03-22 - 2.0.0
|
||||||
|
|
||||||
Significant breaking changes in core tech stack.
|
Significant breaking changes in core tech stack.
|
||||||
|
|
||||||
- BREAKING CHANGE: Transitioned core module to ECMAScript Modules (ESM).
|
- BREAKING CHANGE: Transitioned core module to ECMAScript Modules (ESM).
|
||||||
|
|
||||||
## 2021-05-10 - 1.0.9
|
## 2021-05-10 - 1.0.9
|
||||||
|
|
||||||
Caching improvements and optimization.
|
Caching improvements and optimization.
|
||||||
|
|
||||||
- Enhanced caching by properly respecting TTL across all cache levels.
|
- Enhanced caching by properly respecting TTL across all cache levels.
|
||||||
|
|
||||||
## 2020-02-15 to 2020-02-05 - 1.0.6 to 1.0.1
|
## 2020-02-15 to 2020-02-05 - 1.0.6 to 1.0.1
|
||||||
|
|
||||||
Initial series of core module fixes and updates.
|
Initial series of core module fixes and updates.
|
||||||
|
|
||||||
- Persistent efforts to stabilize and improve core functionalities.
|
- Persistent efforts to stabilize and improve core functionalities.
|
||||||
|
35
package.json
35
package.json
@@ -15,26 +15,26 @@
|
|||||||
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
|
"localPublish": "gitzone commit && pnpm run build && pnpm publish && pnpm publish --access public --registry=\"https://registry.npmjs.org\""
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.6.7",
|
||||||
"@git.zone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@git.zone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^2.3.5",
|
||||||
"@push.rocks/tapbundle": "^5.5.3",
|
"@push.rocks/tapbundle": "^6.0.3",
|
||||||
"@types/node": "^22.9.3"
|
"@types/node": "^24.3.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/lik": "^6.1.0",
|
"@push.rocks/lik": "^6.2.2",
|
||||||
"@push.rocks/smartbucket": "^3.3.3",
|
"@push.rocks/smartbucket": "^3.3.10",
|
||||||
"@push.rocks/smartcache": "^1.0.13",
|
"@push.rocks/smartcache": "^1.0.17",
|
||||||
"@push.rocks/smartenv": "^5.0.12",
|
"@push.rocks/smartenv": "^5.0.13",
|
||||||
"@push.rocks/smartexit": "^1.0.23",
|
"@push.rocks/smartexit": "^1.0.23",
|
||||||
"@push.rocks/smartfile": "^11.0.21",
|
"@push.rocks/smartfile": "^11.2.7",
|
||||||
"@push.rocks/smartjson": "^5.0.20",
|
"@push.rocks/smartjson": "^5.0.20",
|
||||||
"@push.rocks/smartpath": "^5.0.18",
|
"@push.rocks/smartpath": "^6.0.0",
|
||||||
"@push.rocks/smartpromise": "^4.0.4",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@push.rocks/smartstring": "^4.0.15",
|
"@push.rocks/smartstring": "^4.0.15",
|
||||||
"@push.rocks/smartunique": "^3.0.9",
|
"@push.rocks/smartunique": "^3.0.9",
|
||||||
"@push.rocks/taskbuffer": "^3.1.7",
|
"@push.rocks/taskbuffer": "^3.1.10",
|
||||||
"@tsclass/tsclass": "^4.1.2"
|
"@tsclass/tsclass": "^9.2.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@@ -65,9 +65,16 @@
|
|||||||
"Node.js",
|
"Node.js",
|
||||||
"TypeScript"
|
"TypeScript"
|
||||||
],
|
],
|
||||||
"homepage": "https://code.foss.global/push.rocks/levelcache",
|
"homepage": "https://code.foss.global/push.rocks/levelcache#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/levelcache.git"
|
"url": "https://code.foss.global/push.rocks/levelcache.git"
|
||||||
|
},
|
||||||
|
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://code.foss.global/push.rocks/levelcache/issues"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"overrides": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6848
pnpm-lock.yaml
generated
6848
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
4
pnpm-workspace.yaml
Normal file
4
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
onlyBuiltDependencies:
|
||||||
|
- esbuild
|
||||||
|
- mongodb-memory-server
|
||||||
|
- puppeteer
|
@@ -1,13 +1,17 @@
|
|||||||
# @push.rocks/levelcache
|
# @push.rocks/levelcache
|
||||||
|
|
||||||
A cache that utilizes memory, disk, and S3 for data storage and backup.
|
A cache that utilizes memory, disk, and S3 for data storage and backup.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To install `@push.rocks/levelcache`, you can use npm or yarn:
|
To install `@push.rocks/levelcache`, you can use npm or yarn:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @push.rocks/levelcache --save
|
npm install @push.rocks/levelcache --save
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add @push.rocks/levelcache
|
yarn add @push.rocks/levelcache
|
||||||
```
|
```
|
||||||
@@ -43,7 +47,7 @@ const myCache = new LevelCache({
|
|||||||
s3Config: {
|
s3Config: {
|
||||||
accessKeyId: 'yourAccessKeyId', // AWS S3 access key
|
accessKeyId: 'yourAccessKeyId', // AWS S3 access key
|
||||||
secretAccessKey: 'yourSecretAccessKey', // Corresponding secret key
|
secretAccessKey: 'yourSecretAccessKey', // Corresponding secret key
|
||||||
region: 'us-west-2' // AWS region, e.g., 'us-west-2'
|
region: 'us-west-2', // AWS region, e.g., 'us-west-2'
|
||||||
},
|
},
|
||||||
s3BucketName: 'myBucketName', // Designated name for S3 bucket
|
s3BucketName: 'myBucketName', // Designated name for S3 bucket
|
||||||
immutableCache: false, // Whether stored cache entries should remain unaltered
|
immutableCache: false, // Whether stored cache entries should remain unaltered
|
||||||
|
@@ -18,7 +18,7 @@ tap.test('should cache a value', async () => {
|
|||||||
contents: Buffer.from('heythere'),
|
contents: Buffer.from('heythere'),
|
||||||
ttl: 10000,
|
ttl: 10000,
|
||||||
typeInfo: 'string',
|
typeInfo: 'string',
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
expect(result.contents.toString()).toEqual('heythere');
|
expect(result.contents.toString()).toEqual('heythere');
|
||||||
@@ -31,7 +31,7 @@ tap.test('should respect ttl', async (tools) => {
|
|||||||
contents: Buffer.from('heythere'),
|
contents: Buffer.from('heythere'),
|
||||||
ttl: 1000,
|
ttl: 1000,
|
||||||
typeInfo: 'string',
|
typeInfo: 'string',
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
const result = await testLevelCache.retrieveCacheEntryByKey('mykey');
|
||||||
expect(result.contents.toString()).toEqual('heythere');
|
expect(result.contents.toString()).toEqual('heythere');
|
||||||
|
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/levelcache',
|
name: '@push.rocks/levelcache',
|
||||||
version: '3.1.1',
|
version: '3.1.2',
|
||||||
description: 'A versatile caching solution offering multi-level storage utilizing memory, disk, and Amazon S3 for efficient data management and backup.'
|
description: 'A versatile caching solution offering multi-level storage utilizing memory, disk, and Amazon S3 for efficient data management and backup.'
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,10 @@ export abstract class AbstractCache {
|
|||||||
/**
|
/**
|
||||||
* store a Blob
|
* store a Blob
|
||||||
*/
|
*/
|
||||||
public abstract storeCacheEntryByKey(keyArg: string, valueArg: CacheEntry): Promise<void>;
|
public abstract storeCacheEntryByKey(
|
||||||
|
keyArg: string,
|
||||||
|
valueArg: CacheEntry,
|
||||||
|
): Promise<void>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* retrieve cache entry
|
* retrieve cache entry
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
import * as plugins from './levelcache.plugins.js';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
import * as paths from './levelcache.paths.js';
|
import * as paths from './levelcache.paths.js';
|
||||||
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
import {
|
||||||
|
type ILevelCacheConstructorOptions,
|
||||||
|
LevelCache,
|
||||||
|
} from './levelcache.classes.levelcache.js';
|
||||||
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,10 +29,13 @@ export class CacheDiskManager extends AbstractCache {
|
|||||||
if (this.levelCacheRef.options.diskStoragePath) {
|
if (this.levelCacheRef.options.diskStoragePath) {
|
||||||
this.fsPath = plugins.path.join(
|
this.fsPath = plugins.path.join(
|
||||||
this.levelCacheRef.options.diskStoragePath,
|
this.levelCacheRef.options.diskStoragePath,
|
||||||
this.levelCacheRef.options.cacheId
|
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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (this.status === 'active') {
|
if (this.status === 'active') {
|
||||||
plugins.smartfile.fs.ensureDirSync(this.fsPath);
|
plugins.smartfile.fs.ensureDirSync(this.fsPath);
|
||||||
@@ -39,7 +45,7 @@ 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(
|
const fileString = await plugins.smartfile.fs.toStringSync(
|
||||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||||
);
|
);
|
||||||
return CacheEntry.fromStorageJsonString(fileString);
|
return CacheEntry.fromStorageJsonString(fileString);
|
||||||
}
|
}
|
||||||
@@ -47,16 +53,20 @@ export class CacheDiskManager extends AbstractCache {
|
|||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
await plugins.smartfile.memory.toFs(
|
await plugins.smartfile.memory.toFs(
|
||||||
cacheEntryArg.foldToJson(),
|
cacheEntryArg.foldToJson(),
|
||||||
plugins.path.join(this.fsPath, encodeURIComponent(keyArg))
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
public async checkKeyPresence(keyArg: string): Promise<boolean> {
|
||||||
return plugins.smartfile.fs.isFile(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
return plugins.smartfile.fs.isFile(
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteCacheEntryByKey(keyArg: string) {
|
public async deleteCacheEntryByKey(keyArg: string) {
|
||||||
await plugins.smartfile.fs.remove(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)));
|
await plugins.smartfile.fs.remove(
|
||||||
|
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async cleanOutdated() {}
|
public async cleanOutdated() {}
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
import * as plugins from './levelcache.plugins.js';
|
import * as plugins from './levelcache.plugins.js';
|
||||||
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
import { AbstractCache } from './levelcache.abstract.classes.cache.js';
|
||||||
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
import { CacheEntry } from './levelcache.classes.cacheentry.js';
|
||||||
import { type ILevelCacheConstructorOptions, LevelCache } from './levelcache.classes.levelcache.js';
|
import {
|
||||||
|
type ILevelCacheConstructorOptions,
|
||||||
|
LevelCache,
|
||||||
|
} from './levelcache.classes.levelcache.js';
|
||||||
|
|
||||||
export class CacheMemoryManager extends AbstractCache {
|
export class CacheMemoryManager extends AbstractCache {
|
||||||
private levelCacheRef: LevelCache;
|
private levelCacheRef: LevelCache;
|
||||||
@@ -22,7 +25,10 @@ export class CacheMemoryManager extends AbstractCache {
|
|||||||
this.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
public async storeCacheEntryByKey(
|
||||||
|
keyArg: string,
|
||||||
|
cacheEntryArg: CacheEntry,
|
||||||
|
): Promise<void> {
|
||||||
this.fastMap.addToMap(keyArg, cacheEntryArg, { force: true });
|
this.fastMap.addToMap(keyArg, cacheEntryArg, { force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,15 +24,21 @@ export class CacheS3Manager extends AbstractCache {
|
|||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
if (this.levelCacheRef.options.s3Config) {
|
if (this.levelCacheRef.options.s3Config) {
|
||||||
this.smartbucket = new plugins.smartbucket.SmartBucket(this.levelCacheRef.options.s3Config);
|
this.smartbucket = new plugins.smartbucket.SmartBucket(
|
||||||
|
this.levelCacheRef.options.s3Config,
|
||||||
|
);
|
||||||
this.s3CacheBucket = await this.smartbucket.getBucketByName('');
|
this.s3CacheBucket = await this.smartbucket.getBucketByName('');
|
||||||
this.s3CacheDir = await (
|
this.s3CacheDir = await (
|
||||||
await this.s3CacheBucket.getBaseDirectory()
|
await this.s3CacheBucket.getBaseDirectory()
|
||||||
).getSubDirectoryByName(this.levelCacheRef.options.cacheId);
|
).getSubDirectoryByName(this.levelCacheRef.options.cacheId);
|
||||||
if (this.levelCacheRef.options.maxS3StorageInMB) {
|
if (this.levelCacheRef.options.maxS3StorageInMB) {
|
||||||
console.log(`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`);
|
console.log(
|
||||||
|
`cache level S3 activated with ${this.levelCacheRef.options.maxS3StorageInMB}`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(`s3 cache started without limit. Automatically applying timebox of 1 month`);
|
console.log(
|
||||||
|
`s3 cache started without limit. Automatically applying timebox of 1 month`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.status = 'active';
|
this.status = 'active';
|
||||||
} else {
|
} else {
|
||||||
@@ -42,9 +48,11 @@ export class CacheS3Manager extends AbstractCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
const jsonFileString = (await this.s3CacheDir.fastGet({
|
const jsonFileString = (
|
||||||
|
await this.s3CacheDir.fastGet({
|
||||||
path: encodeURIComponent(keyArg),
|
path: encodeURIComponent(keyArg),
|
||||||
})).toString();
|
})
|
||||||
|
).toString();
|
||||||
const cacheEntry = CacheEntry.fromStorageJsonString(jsonFileString);
|
const cacheEntry = CacheEntry.fromStorageJsonString(jsonFileString);
|
||||||
return cacheEntry;
|
return cacheEntry;
|
||||||
}
|
}
|
||||||
@@ -52,7 +60,7 @@ export class CacheS3Manager extends AbstractCache {
|
|||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry) {
|
||||||
await this.s3CacheDir.fastPut({
|
await this.s3CacheDir.fastPut({
|
||||||
path: encodeURIComponent(keyArg),
|
path: encodeURIComponent(keyArg),
|
||||||
contents: cacheEntryArg.toStorageJsonString()
|
contents: cacheEntryArg.toStorageJsonString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,12 +14,18 @@ export class CacheRouter {
|
|||||||
/**
|
/**
|
||||||
* gets the relevant cache to perform a store action on
|
* gets the relevant cache to perform a store action on
|
||||||
*/
|
*/
|
||||||
async getCacheForStoreAction(keyArg: string, cacheEntry: CacheEntry): Promise<AbstractCache> {
|
async getCacheForStoreAction(
|
||||||
|
keyArg: string,
|
||||||
|
cacheEntry: CacheEntry,
|
||||||
|
): Promise<AbstractCache> {
|
||||||
let returnCache: AbstractCache;
|
let returnCache: AbstractCache;
|
||||||
const mbToBytesMultiplier = 1000 * 1000;
|
const mbToBytesMultiplier = 1000 * 1000;
|
||||||
const maxMemoryBytes = this.levelCacheRef.options.maxMemoryStorageInMB * mbToBytesMultiplier;
|
const maxMemoryBytes =
|
||||||
const maxDiskBytes = this.levelCacheRef.options.maxDiskStorageInMB * mbToBytesMultiplier;
|
this.levelCacheRef.options.maxMemoryStorageInMB * mbToBytesMultiplier;
|
||||||
const maxS3Bytes = this.levelCacheRef.options.maxS3StorageInMB * mbToBytesMultiplier;
|
const maxDiskBytes =
|
||||||
|
this.levelCacheRef.options.maxDiskStorageInMB * mbToBytesMultiplier;
|
||||||
|
const maxS3Bytes =
|
||||||
|
this.levelCacheRef.options.maxS3StorageInMB * mbToBytesMultiplier;
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case cacheEntry.contents.byteLength <= maxMemoryBytes &&
|
case cacheEntry.contents.byteLength <= maxMemoryBytes &&
|
||||||
|
@@ -64,9 +64,15 @@ export class LevelCache extends AbstractCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// store things
|
// store things
|
||||||
public async storeCacheEntryByKey(keyArg: string, cacheEntryArg: CacheEntry): Promise<void> {
|
public async storeCacheEntryByKey(
|
||||||
|
keyArg: string,
|
||||||
|
cacheEntryArg: CacheEntry,
|
||||||
|
): Promise<void> {
|
||||||
cacheEntryArg.key = keyArg;
|
cacheEntryArg.key = keyArg;
|
||||||
const targetCache = await this.cacheRouter.getCacheForStoreAction(keyArg, cacheEntryArg);
|
const targetCache = await this.cacheRouter.getCacheForStoreAction(
|
||||||
|
keyArg,
|
||||||
|
cacheEntryArg,
|
||||||
|
);
|
||||||
cacheEntryArg.createdAt = Date.now();
|
cacheEntryArg.createdAt = Date.now();
|
||||||
await targetCache.storeCacheEntryByKey(keyArg, cacheEntryArg);
|
await targetCache.storeCacheEntryByKey(keyArg, cacheEntryArg);
|
||||||
}
|
}
|
||||||
@@ -76,7 +82,8 @@ export class LevelCache extends AbstractCache {
|
|||||||
* retrieve cache entry
|
* retrieve cache entry
|
||||||
*/
|
*/
|
||||||
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
public async retrieveCacheEntryByKey(keyArg: string): Promise<CacheEntry> {
|
||||||
const targetCache = await this.cacheRouter.getCacheForRetrieveAction(keyArg);
|
const targetCache =
|
||||||
|
await this.cacheRouter.getCacheForRetrieveAction(keyArg);
|
||||||
if (targetCache) {
|
if (targetCache) {
|
||||||
const cacheEntry = await targetCache.retrieveCacheEntryByKey(keyArg);
|
const cacheEntry = await targetCache.retrieveCacheEntryByKey(keyArg);
|
||||||
if (cacheEntry.createdAt + cacheEntry.ttl < Date.now()) {
|
if (cacheEntry.createdAt + cacheEntry.ttl < Date.now()) {
|
||||||
|
@@ -2,6 +2,6 @@ import * as plugins from './levelcache.plugins.js';
|
|||||||
|
|
||||||
export const packageDir = plugins.path.join(
|
export const packageDir = plugins.path.join(
|
||||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
'../'
|
'../',
|
||||||
);
|
);
|
||||||
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
export const nogitDir = plugins.path.join(packageDir, '.nogit/');
|
||||||
|
@@ -31,6 +31,4 @@ export {
|
|||||||
// @tsclass scope
|
// @tsclass scope
|
||||||
import * as tsclass from '@tsclass/tsclass';
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
export {
|
export { tsclass };
|
||||||
tsclass,
|
|
||||||
};
|
|
||||||
|
@@ -6,9 +6,9 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {}
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["dist_*/**/*.d.ts"]
|
||||||
"dist_*/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user