fix(build): migrate project tooling and filesystem integration to current smartfs-based stack

This commit is contained in:
2026-04-07 20:13:18 +00:00
parent 6af4f6b9c0
commit 3ac4676cc6
13 changed files with 3282 additions and 3581 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/levelcache',
version: '3.2.0',
version: '3.2.1',
description: 'A versatile caching solution offering multi-level storage utilizing memory, disk, and Amazon S3 for efficient data management and backup.'
}

View File

@@ -38,43 +38,48 @@ export class CacheDiskManager extends AbstractCache {
);
}
if (this.status === 'active') {
plugins.smartfile.fs.ensureDirSync(this.fsPath);
await plugins.fs.directory(this.fsPath).recursive().create();
}
this.readyDeferred.resolve();
}
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.fs
.file(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)))
.encoding('utf8')
.read()) as string;
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.fs
.file(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)))
.write(cacheEntryArg.foldToJson());
}
public async checkKeyPresence(keyArg: string): Promise<boolean> {
return plugins.smartfile.fs.isFile(
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
);
return plugins.fs
.file(plugins.path.join(this.fsPath, encodeURIComponent(keyArg)))
.exists();
}
public async deleteCacheEntryByKey(keyArg: string) {
await plugins.smartfile.fs.remove(
const cacheFile = plugins.fs.file(
plugins.path.join(this.fsPath, encodeURIComponent(keyArg)),
);
if (await cacheFile.exists()) {
await cacheFile.delete();
}
}
public async cleanOutdated() {}
public async cleanAll() {
if (this.status === 'active') {
if (plugins.smartfile.fs.isDirectory(this.fsPath)) {
await plugins.smartfile.fs.ensureEmptyDir(this.fsPath);
const dir = plugins.fs.directory(this.fsPath);
if (await dir.exists()) {
await plugins.fs.directory(this.fsPath).recursive().delete();
await plugins.fs.directory(this.fsPath).recursive().create();
}
}
}

View File

@@ -19,19 +19,19 @@ export class CacheEntry
}
@plugins.smartjson.foldDec()
public key: string;
accessor key: string;
@plugins.smartjson.foldDec()
public ttl: number;
accessor ttl: number;
@plugins.smartjson.foldDec()
public createdAt: number;
accessor createdAt: number;
@plugins.smartjson.foldDec()
public typeInfo: string;
accessor typeInfo: string;
@plugins.smartjson.foldDec()
contents: Buffer;
accessor contents: Buffer;
public toStorageJsonString(): string {
return this.foldToJson();

View File

@@ -15,7 +15,7 @@ export interface ILevelCacheConstructorOptions {
maxDiskStorageInMB?: number;
maxS3StorageInMB?: number;
diskStoragePath?: string;
s3Config?: plugins.tsclass.storage.IS3Descriptor;
s3Config?: plugins.tsclass.storage.IStorageDescriptor;
s3BucketName?: string;
forceLevel?: 'memory' | 'disk' | 's3';
expirationInMs?: number;

View File

@@ -6,28 +6,23 @@ export { path };
// @push.rocks scope
import * as lik from '@push.rocks/lik';
import * as smartbucket from '@push.rocks/smartbucket';
import * as smartcache from '@push.rocks/smartcache';
import * as smartfile from '@push.rocks/smartfile';
import * as smartfs from '@push.rocks/smartfs';
import * as smartjson from '@push.rocks/smartjson';
import * as smartpath from '@push.rocks/smartpath';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartstring from '@push.rocks/smartstring';
import * as smartunique from '@push.rocks/smartunique';
import * as taskbuffer from '@push.rocks/taskbuffer';
export {
lik,
smartbucket,
smartcache,
smartfile,
smartfs,
smartjson,
smartpath,
smartpromise,
smartstring,
smartunique,
taskbuffer,
};
// shared smartfs instance backed by the node provider
export const fs = new smartfs.SmartFs(new smartfs.SmartFsProviderNode());
// @tsclass scope
import * as tsclass from '@tsclass/tsclass';