release: v0.2.2 AriaEngine OPFS 自研存储后端 — 零依赖纯文件系统
CI / test (18.x) (push) Successful in 10m0s
CI / test (20.x) (push) Successful in 9m56s
CI / test (22.x) (push) Successful in 9m56s
CI / test (24.x) (push) Successful in 9m52s

This commit is contained in:
thzxx
2026-07-27 21:08:57 +08:00
parent eab58adc37
commit fef4db44ca
18 changed files with 450 additions and 73 deletions
+88 -2
View File
@@ -2776,6 +2776,89 @@ class MemoryBackend {
}
}
class OPFSBackend {
constructor() {
this.root = null;
this.dbDir = null;
this.dbName = '';
}
async open(name) {
this.dbName = name;
this.root = await navigator.storage.getDirectory();
this.dbDir = await this.root.getDirectoryHandle(name, { create: true });
}
async close() {
this.dbDir = null;
this.root = null;
}
isOpen() {
return this.dbDir !== null;
}
async read(key) {
if (!this.dbDir)
return null;
try {
const fh = await this.dbDir.getFileHandle(key);
const file = await fh.getFile();
return await file.arrayBuffer();
}
catch {
return null;
}
}
async write(key, data) {
if (!this.dbDir)
return;
const fh = await this.dbDir.getFileHandle(key, { create: true });
const writable = await fh.createWritable();
await writable.write(data);
await writable.close();
}
async delete(key) {
if (!this.dbDir)
return;
try {
await this.dbDir.removeEntry(key);
}
catch {
// 文件不存在则忽略
}
}
async listKeys() {
if (!this.dbDir)
return [];
const keys = [];
// FileSystemDirectoryHandle.entries() 返回 AsyncIterable,使用 any 绕过 dts 生成限制
const dir = this.dbDir;
for await (const [name] of dir.entries()) {
keys.push(name);
}
return keys;
}
async exists(key) {
if (!this.dbDir)
return false;
try {
await this.dbDir.getFileHandle(key);
return true;
}
catch {
return false;
}
}
async clear() {
if (!this.dbDir)
return;
const dir = this.dbDir;
for await (const [name] of dir.entries()) {
try {
await this.dbDir.removeEntry(name);
}
catch { /* ignore */ }
}
}
}
/**
* AriaEngine — 自研页面式存储引擎主类
* @module engine/aria/index
@@ -2813,7 +2896,10 @@ class AriaEngine {
return;
this.dbName = dbName;
// 1. 存储后端
if (this.config.storageBackend === 'indexeddb') {
if (this.config.storageBackend === 'opfs') {
this.backend = new OPFSBackend();
}
else if (this.config.storageBackend === 'indexeddb') {
this.backend = new IndexedDBBackend();
}
else {
@@ -5815,5 +5901,5 @@ if (typeof window !== 'undefined') {
// 别名
const MeSqlark = MetonaSqlark;
export { AriaEngine, HybridEngine, IndexedDBEngine, MeSqlark, MemoryEngine, MetonaSqlark, OPFSEngine, Table, VERSION, api, create, api as default, parse, tokenize };
export { AriaEngine, HybridEngine, IndexedDBEngine, MeSqlark, MemoryEngine, MetonaSqlark, OPFSBackend, OPFSEngine, Table, VERSION, api, create, api as default, parse, tokenize };
//# sourceMappingURL=metona-sqlark.esm.js.map