@ocap/indexdb-fs 1.28.8 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/esm/db.d.mts +26 -0
- package/esm/db.mjs +33 -0
- package/esm/main.d.mts +2 -0
- package/esm/main.mjs +7 -0
- package/esm/package.mjs +6 -0
- package/esm/table/base.d.mts +18 -0
- package/esm/table/base.mjs +68 -0
- package/esm/table/transaction.d.mts +9 -0
- package/esm/table/transaction.mjs +13 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/db.cjs +35 -0
- package/lib/db.d.cts +26 -0
- package/lib/main.cjs +8 -0
- package/lib/main.d.cts +2 -0
- package/lib/package.cjs +18 -0
- package/lib/table/base.cjs +74 -0
- package/lib/table/base.d.cts +18 -0
- package/lib/table/transaction.cjs +15 -0
- package/lib/table/transaction.d.cts +9 -0
- package/package.json +39 -11
- package/lib/db.js +0 -35
- package/lib/main.js +0 -3
- package/lib/table/base.js +0 -76
- package/lib/table/transaction.js +0 -10
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# [**@ocap/indexdb-fs**](https://github.com/arcblock/blockchain)
|
|
2
2
|
|
|
3
|
-
[](https://github.com/prettier/prettier)
|
|
4
3
|
|
|
5
4
|
> OCAP indexdb adapter that stores data on disk through lokijs
|
|
6
5
|
|
|
@@ -15,7 +14,7 @@ bun install @ocap/indexdb-fs
|
|
|
15
14
|
## Usage
|
|
16
15
|
|
|
17
16
|
```js
|
|
18
|
-
const FsIndexDB = require('@ocap/indexdb-fs');
|
|
17
|
+
const FsIndexDB = require('@ocap/indexdb-fs').default;
|
|
19
18
|
|
|
20
19
|
const indexdb = new FsIndexDB(os.tmpdir());
|
|
21
20
|
```
|
package/esm/db.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LocalBaseIndexDB } from "@ocap/indexdb-memory";
|
|
2
|
+
import { md5 } from "@ocap/util/lib/md5";
|
|
3
|
+
import { IIndexDB, IIndexTable, IndexTableTypeMap } from "@ocap/types";
|
|
4
|
+
|
|
5
|
+
//#region src/db.d.ts
|
|
6
|
+
declare class FsIndexDB extends LocalBaseIndexDB implements IIndexDB {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
md5: typeof md5;
|
|
10
|
+
tx: IIndexTable<IndexTableTypeMap['tx']>;
|
|
11
|
+
account: IIndexTable<IndexTableTypeMap['account']>;
|
|
12
|
+
asset: IIndexTable<IndexTableTypeMap['asset']>;
|
|
13
|
+
token: IIndexTable<IndexTableTypeMap['token']>;
|
|
14
|
+
factory: IIndexTable<IndexTableTypeMap['factory']>;
|
|
15
|
+
stake: IIndexTable<IndexTableTypeMap['stake']>;
|
|
16
|
+
delegation: IIndexTable<IndexTableTypeMap['delegation']>;
|
|
17
|
+
rollup: IIndexTable<IndexTableTypeMap['rollup']>;
|
|
18
|
+
rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
|
|
19
|
+
rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
|
|
20
|
+
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
21
|
+
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
22
|
+
balance: IIndexTable<unknown>;
|
|
23
|
+
constructor(dataDir: string);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { FsIndexDB as default };
|
package/esm/db.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { name, version } from "./package.mjs";
|
|
2
|
+
import base_default from "./table/base.mjs";
|
|
3
|
+
import transaction_default from "./table/transaction.mjs";
|
|
4
|
+
import { LocalBaseIndexDB } from "@ocap/indexdb-memory";
|
|
5
|
+
import { md5 } from "@ocap/util/lib/md5";
|
|
6
|
+
|
|
7
|
+
//#region src/db.ts
|
|
8
|
+
var FsIndexDB = class extends LocalBaseIndexDB {
|
|
9
|
+
constructor(dataDir) {
|
|
10
|
+
super();
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.version = version;
|
|
13
|
+
this.md5 = md5;
|
|
14
|
+
this.account = new base_default("account", dataDir, "address");
|
|
15
|
+
this.asset = new base_default("asset", dataDir, "address");
|
|
16
|
+
this.factory = new base_default("factory", dataDir, "address");
|
|
17
|
+
this.delegation = new base_default("delegation", dataDir, "address");
|
|
18
|
+
this.tx = new transaction_default("tx", dataDir, "hash");
|
|
19
|
+
this.token = new base_default("token", dataDir, "address");
|
|
20
|
+
this.stake = new base_default("stake", dataDir, "address");
|
|
21
|
+
this.rollup = new base_default("rollup", dataDir, "address");
|
|
22
|
+
this.rollupBlock = new base_default("rollupBlock", dataDir, "hash");
|
|
23
|
+
this.rollupValidator = new base_default("rollupValidator", dataDir, "address");
|
|
24
|
+
this.tokenDistribution = new base_default("tokenDistribution", dataDir, "tokenAddress");
|
|
25
|
+
this.balance = new base_default("balance", dataDir, ["address", "tokenAddress"]);
|
|
26
|
+
this.tokenFactory = new base_default("tokenFactory", dataDir, "address");
|
|
27
|
+
this.attachReadyListeners();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var db_default = FsIndexDB;
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { db_default as default };
|
package/esm/main.d.mts
ADDED
package/esm/main.mjs
ADDED
package/esm/package.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseIndex } from "@ocap/indexdb";
|
|
2
|
+
import Lokijs from "lokijs";
|
|
3
|
+
import { IIndexTable } from "@ocap/types";
|
|
4
|
+
|
|
5
|
+
//#region src/table/base.d.ts
|
|
6
|
+
type UniqIndex = string | string[];
|
|
7
|
+
declare class FsIndex<T = unknown> extends BaseIndex<T> implements IIndexTable<T> {
|
|
8
|
+
collection: Lokijs.Collection<T & Record<string, unknown>> | null;
|
|
9
|
+
db: Lokijs;
|
|
10
|
+
constructor(name: string, dataDir: string, uniqIndex: UniqIndex);
|
|
11
|
+
count(...args: Parameters<Lokijs.Collection['count']>): number;
|
|
12
|
+
_insert(row: Record<string, unknown>): T & Record<string, unknown>;
|
|
13
|
+
_get(key: string | Record<string, unknown>): (T & Record<string, unknown>) | null;
|
|
14
|
+
_update(key: string | Record<string, unknown>, updates: Record<string, unknown>): T & Record<string, unknown>;
|
|
15
|
+
_reset(): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FsIndex as default };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { name } from "../package.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { BaseIndex } from "@ocap/indexdb";
|
|
4
|
+
import Debug from "debug";
|
|
5
|
+
import Lokijs from "lokijs";
|
|
6
|
+
import FsAdapter from "lokijs/src/loki-fs-structured-adapter.js";
|
|
7
|
+
|
|
8
|
+
//#region src/table/base.ts
|
|
9
|
+
const debug = Debug(name);
|
|
10
|
+
var FsIndex = class FsIndex extends BaseIndex {
|
|
11
|
+
constructor(name$1, dataDir, uniqIndex) {
|
|
12
|
+
super(name$1, uniqIndex);
|
|
13
|
+
this.collection = null;
|
|
14
|
+
const adapter = new FsAdapter();
|
|
15
|
+
const db = new Lokijs(path.join(dataDir, `${name$1}.db`), {
|
|
16
|
+
adapter,
|
|
17
|
+
autoload: true,
|
|
18
|
+
autosave: true,
|
|
19
|
+
autosaveInterval: 1e3,
|
|
20
|
+
autoloadCallback: () => {
|
|
21
|
+
this.collection = db.getCollection(name$1);
|
|
22
|
+
if (this.collection === null) this.collection = db.addCollection(name$1, {
|
|
23
|
+
unique: [this.primaryKey],
|
|
24
|
+
clone: true
|
|
25
|
+
});
|
|
26
|
+
this.markReady();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
this.db = db;
|
|
30
|
+
}
|
|
31
|
+
count(...args) {
|
|
32
|
+
return this.collection.count(...args);
|
|
33
|
+
}
|
|
34
|
+
_insert(row) {
|
|
35
|
+
const id = this.generatePrimaryKey(row);
|
|
36
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
|
37
|
+
if (doc) return doc;
|
|
38
|
+
debug(`insert ${this.name}`, row);
|
|
39
|
+
return this.collection.insert({
|
|
40
|
+
[this.primaryKey]: id,
|
|
41
|
+
...row
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
_get(key) {
|
|
45
|
+
const id = this.generatePrimaryKey(key);
|
|
46
|
+
return key ? this.collection.by(this.primaryKey, id) ?? null : null;
|
|
47
|
+
}
|
|
48
|
+
_update(key, updates) {
|
|
49
|
+
const id = this.generatePrimaryKey(key);
|
|
50
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
|
51
|
+
if (!doc) throw new Error(`${this.name} does not exists: ${key}`);
|
|
52
|
+
debug(`update ${this.name}`, {
|
|
53
|
+
id,
|
|
54
|
+
key,
|
|
55
|
+
updates
|
|
56
|
+
});
|
|
57
|
+
Object.assign(doc, updates);
|
|
58
|
+
this.collection.update(doc);
|
|
59
|
+
return doc;
|
|
60
|
+
}
|
|
61
|
+
_reset() {
|
|
62
|
+
this.collection.removeWhere({});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var base_default = FsIndex;
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { base_default as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import FsIndex from "./base.mjs";
|
|
2
|
+
import { TIndexedTransaction } from "@ocap/types";
|
|
3
|
+
|
|
4
|
+
//#region src/table/transaction.d.ts
|
|
5
|
+
declare class Transaction extends FsIndex<TIndexedTransaction> {
|
|
6
|
+
_insert(row: Record<string, unknown>): TIndexedTransaction & Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Transaction as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import base_default from "./base.mjs";
|
|
2
|
+
import { formatTxBeforeInsert } from "@ocap/indexdb";
|
|
3
|
+
|
|
4
|
+
//#region src/table/transaction.ts
|
|
5
|
+
var Transaction = class extends base_default {
|
|
6
|
+
_insert(row) {
|
|
7
|
+
return super._insert(formatTxBeforeInsert(row));
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var transaction_default = Transaction;
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { transaction_default as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/lib/db.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_package = require('./package.cjs');
|
|
4
|
+
const require_table_base = require('./table/base.cjs');
|
|
5
|
+
const require_table_transaction = require('./table/transaction.cjs');
|
|
6
|
+
let _ocap_indexdb_memory = require("@ocap/indexdb-memory");
|
|
7
|
+
let _ocap_util_lib_md5 = require("@ocap/util/lib/md5");
|
|
8
|
+
|
|
9
|
+
//#region src/db.ts
|
|
10
|
+
var FsIndexDB = class extends _ocap_indexdb_memory.LocalBaseIndexDB {
|
|
11
|
+
constructor(dataDir) {
|
|
12
|
+
super();
|
|
13
|
+
this.name = require_package.name;
|
|
14
|
+
this.version = require_package.version;
|
|
15
|
+
this.md5 = _ocap_util_lib_md5.md5;
|
|
16
|
+
this.account = new require_table_base.default("account", dataDir, "address");
|
|
17
|
+
this.asset = new require_table_base.default("asset", dataDir, "address");
|
|
18
|
+
this.factory = new require_table_base.default("factory", dataDir, "address");
|
|
19
|
+
this.delegation = new require_table_base.default("delegation", dataDir, "address");
|
|
20
|
+
this.tx = new require_table_transaction.default("tx", dataDir, "hash");
|
|
21
|
+
this.token = new require_table_base.default("token", dataDir, "address");
|
|
22
|
+
this.stake = new require_table_base.default("stake", dataDir, "address");
|
|
23
|
+
this.rollup = new require_table_base.default("rollup", dataDir, "address");
|
|
24
|
+
this.rollupBlock = new require_table_base.default("rollupBlock", dataDir, "hash");
|
|
25
|
+
this.rollupValidator = new require_table_base.default("rollupValidator", dataDir, "address");
|
|
26
|
+
this.tokenDistribution = new require_table_base.default("tokenDistribution", dataDir, "tokenAddress");
|
|
27
|
+
this.balance = new require_table_base.default("balance", dataDir, ["address", "tokenAddress"]);
|
|
28
|
+
this.tokenFactory = new require_table_base.default("tokenFactory", dataDir, "address");
|
|
29
|
+
this.attachReadyListeners();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var db_default = FsIndexDB;
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.default = db_default;
|
package/lib/db.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LocalBaseIndexDB } from "@ocap/indexdb-memory";
|
|
2
|
+
import { IIndexDB, IIndexTable, IndexTableTypeMap } from "@ocap/types";
|
|
3
|
+
import { md5 } from "@ocap/util/lib/md5";
|
|
4
|
+
|
|
5
|
+
//#region src/db.d.ts
|
|
6
|
+
declare class FsIndexDB extends LocalBaseIndexDB implements IIndexDB {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
md5: typeof md5;
|
|
10
|
+
tx: IIndexTable<IndexTableTypeMap['tx']>;
|
|
11
|
+
account: IIndexTable<IndexTableTypeMap['account']>;
|
|
12
|
+
asset: IIndexTable<IndexTableTypeMap['asset']>;
|
|
13
|
+
token: IIndexTable<IndexTableTypeMap['token']>;
|
|
14
|
+
factory: IIndexTable<IndexTableTypeMap['factory']>;
|
|
15
|
+
stake: IIndexTable<IndexTableTypeMap['stake']>;
|
|
16
|
+
delegation: IIndexTable<IndexTableTypeMap['delegation']>;
|
|
17
|
+
rollup: IIndexTable<IndexTableTypeMap['rollup']>;
|
|
18
|
+
rollupBlock: IIndexTable<IndexTableTypeMap['rollupBlock']>;
|
|
19
|
+
rollupValidator: IIndexTable<IndexTableTypeMap['rollupValidator']>;
|
|
20
|
+
tokenDistribution: IIndexTable<IndexTableTypeMap['tokenDistribution']>;
|
|
21
|
+
tokenFactory: IIndexTable<IndexTableTypeMap['tokenFactory']>;
|
|
22
|
+
balance: IIndexTable<unknown>;
|
|
23
|
+
constructor(dataDir: string);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { FsIndexDB as default };
|
package/lib/main.cjs
ADDED
package/lib/main.d.cts
ADDED
package/lib/package.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region package.json
|
|
3
|
+
var name = "@ocap/indexdb-fs";
|
|
4
|
+
var version = "1.20.2";
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
Object.defineProperty(exports, 'name', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return name;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, 'version', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return version;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_package = require('../package.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
6
|
+
let _ocap_indexdb = require("@ocap/indexdb");
|
|
7
|
+
let debug = require("debug");
|
|
8
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
9
|
+
let lokijs = require("lokijs");
|
|
10
|
+
lokijs = require_rolldown_runtime.__toESM(lokijs);
|
|
11
|
+
let lokijs_src_loki_fs_structured_adapter = require("lokijs/src/loki-fs-structured-adapter");
|
|
12
|
+
lokijs_src_loki_fs_structured_adapter = require_rolldown_runtime.__toESM(lokijs_src_loki_fs_structured_adapter);
|
|
13
|
+
|
|
14
|
+
//#region src/table/base.ts
|
|
15
|
+
const debug$1 = (0, debug.default)(require_package.name);
|
|
16
|
+
var FsIndex = class FsIndex extends _ocap_indexdb.BaseIndex {
|
|
17
|
+
constructor(name$1, dataDir, uniqIndex) {
|
|
18
|
+
super(name$1, uniqIndex);
|
|
19
|
+
this.collection = null;
|
|
20
|
+
const adapter = new lokijs_src_loki_fs_structured_adapter.default();
|
|
21
|
+
const db = new lokijs.default(node_path.default.join(dataDir, `${name$1}.db`), {
|
|
22
|
+
adapter,
|
|
23
|
+
autoload: true,
|
|
24
|
+
autosave: true,
|
|
25
|
+
autosaveInterval: 1e3,
|
|
26
|
+
autoloadCallback: () => {
|
|
27
|
+
this.collection = db.getCollection(name$1);
|
|
28
|
+
if (this.collection === null) this.collection = db.addCollection(name$1, {
|
|
29
|
+
unique: [this.primaryKey],
|
|
30
|
+
clone: true
|
|
31
|
+
});
|
|
32
|
+
this.markReady();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.db = db;
|
|
36
|
+
}
|
|
37
|
+
count(...args) {
|
|
38
|
+
return this.collection.count(...args);
|
|
39
|
+
}
|
|
40
|
+
_insert(row) {
|
|
41
|
+
const id = this.generatePrimaryKey(row);
|
|
42
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
|
43
|
+
if (doc) return doc;
|
|
44
|
+
debug$1(`insert ${this.name}`, row);
|
|
45
|
+
return this.collection.insert({
|
|
46
|
+
[this.primaryKey]: id,
|
|
47
|
+
...row
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
_get(key) {
|
|
51
|
+
const id = this.generatePrimaryKey(key);
|
|
52
|
+
return key ? this.collection.by(this.primaryKey, id) ?? null : null;
|
|
53
|
+
}
|
|
54
|
+
_update(key, updates) {
|
|
55
|
+
const id = this.generatePrimaryKey(key);
|
|
56
|
+
const doc = FsIndex.prototype._get.call(this, id);
|
|
57
|
+
if (!doc) throw new Error(`${this.name} does not exists: ${key}`);
|
|
58
|
+
debug$1(`update ${this.name}`, {
|
|
59
|
+
id,
|
|
60
|
+
key,
|
|
61
|
+
updates
|
|
62
|
+
});
|
|
63
|
+
Object.assign(doc, updates);
|
|
64
|
+
this.collection.update(doc);
|
|
65
|
+
return doc;
|
|
66
|
+
}
|
|
67
|
+
_reset() {
|
|
68
|
+
this.collection.removeWhere({});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var base_default = FsIndex;
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.default = base_default;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IIndexTable } from "@ocap/types";
|
|
2
|
+
import { BaseIndex } from "@ocap/indexdb";
|
|
3
|
+
import Lokijs from "lokijs";
|
|
4
|
+
|
|
5
|
+
//#region src/table/base.d.ts
|
|
6
|
+
type UniqIndex = string | string[];
|
|
7
|
+
declare class FsIndex<T = unknown> extends BaseIndex<T> implements IIndexTable<T> {
|
|
8
|
+
collection: Lokijs.Collection<T & Record<string, unknown>> | null;
|
|
9
|
+
db: Lokijs;
|
|
10
|
+
constructor(name: string, dataDir: string, uniqIndex: UniqIndex);
|
|
11
|
+
count(...args: Parameters<Lokijs.Collection['count']>): number;
|
|
12
|
+
_insert(row: Record<string, unknown>): T & Record<string, unknown>;
|
|
13
|
+
_get(key: string | Record<string, unknown>): (T & Record<string, unknown>) | null;
|
|
14
|
+
_update(key: string | Record<string, unknown>, updates: Record<string, unknown>): T & Record<string, unknown>;
|
|
15
|
+
_reset(): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FsIndex as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_table_base = require('./base.cjs');
|
|
4
|
+
let _ocap_indexdb = require("@ocap/indexdb");
|
|
5
|
+
|
|
6
|
+
//#region src/table/transaction.ts
|
|
7
|
+
var Transaction = class extends require_table_base.default {
|
|
8
|
+
_insert(row) {
|
|
9
|
+
return super._insert((0, _ocap_indexdb.formatTxBeforeInsert)(row));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var transaction_default = Transaction;
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.default = transaction_default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import FsIndex from "./base.cjs";
|
|
2
|
+
import { TIndexedTransaction } from "@ocap/types";
|
|
3
|
+
|
|
4
|
+
//#region src/table/transaction.d.ts
|
|
5
|
+
declare class Transaction extends FsIndex<TIndexedTransaction> {
|
|
6
|
+
_insert(row: Record<string, unknown>): TIndexedTransaction & Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Transaction as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/indexdb-fs",
|
|
3
3
|
"description": "OCAP indexdb adapter that uses file system as backend",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.29.0",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
7
|
"bugs": {
|
|
7
8
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -13,9 +14,6 @@
|
|
|
13
14
|
"contributors": [
|
|
14
15
|
"wangshijun <shijun@arcblock.io> (https://www.arcblock.io)"
|
|
15
16
|
],
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@ocap/indexdb-test": "1.28.8"
|
|
18
|
-
},
|
|
19
17
|
"homepage": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/fs",
|
|
20
18
|
"keywords": [
|
|
21
19
|
"ocap",
|
|
@@ -23,15 +21,37 @@
|
|
|
23
21
|
"fs"
|
|
24
22
|
],
|
|
25
23
|
"license": "Apache-2.0",
|
|
26
|
-
"main": "./lib/main.
|
|
24
|
+
"main": "./lib/main.cjs",
|
|
25
|
+
"module": "./esm/main.mjs",
|
|
26
|
+
"types": "./esm/main.d.mts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./esm/main.d.mts",
|
|
30
|
+
"import": "./esm/main.mjs",
|
|
31
|
+
"default": "./lib/main.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./lib/*.js": {
|
|
34
|
+
"types": "./esm/*.d.mts",
|
|
35
|
+
"import": "./esm/*.mjs",
|
|
36
|
+
"default": "./lib/*.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./lib/*": {
|
|
39
|
+
"types": "./esm/*.d.mts",
|
|
40
|
+
"import": "./esm/*.mjs",
|
|
41
|
+
"default": "./lib/*.cjs"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
27
44
|
"files": [
|
|
28
|
-
"lib"
|
|
45
|
+
"lib",
|
|
46
|
+
"esm"
|
|
29
47
|
],
|
|
30
48
|
"repository": {
|
|
31
49
|
"type": "git",
|
|
32
50
|
"url": "https://github.com/ArcBlock/blockchain/tree/master/indexdb/fs"
|
|
33
51
|
},
|
|
34
52
|
"scripts": {
|
|
53
|
+
"build": "tsdown",
|
|
54
|
+
"prebuild": "rm -rf lib esm",
|
|
35
55
|
"lint": "biome check",
|
|
36
56
|
"lint:fix": "biome check --write",
|
|
37
57
|
"test": "bun test",
|
|
@@ -39,11 +59,19 @@
|
|
|
39
59
|
},
|
|
40
60
|
"gitHead": "87990c8b5e215107fc587c1ced0d6b3e2cd2483e",
|
|
41
61
|
"dependencies": {
|
|
42
|
-
"@ocap/indexdb": "1.
|
|
43
|
-
"@ocap/indexdb-memory": "1.
|
|
44
|
-
"@ocap/
|
|
45
|
-
"
|
|
46
|
-
"
|
|
62
|
+
"@ocap/indexdb": "1.29.0",
|
|
63
|
+
"@ocap/indexdb-memory": "1.29.0",
|
|
64
|
+
"@ocap/types": "1.29.0",
|
|
65
|
+
"@ocap/util": "1.29.0",
|
|
66
|
+
"debug": "^4.4.3",
|
|
67
|
+
"lodash": "^4.17.23",
|
|
47
68
|
"lokijs": "^1.5.12"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@ocap/indexdb-test": "1.29.0",
|
|
72
|
+
"@types/debug": "^4.1.12",
|
|
73
|
+
"@types/lodash": "^4.17.10",
|
|
74
|
+
"@types/node": "^22.7.5",
|
|
75
|
+
"tsdown": "^0.18.4"
|
|
48
76
|
}
|
|
49
77
|
}
|
package/lib/db.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const BaseIndexDB = require('@ocap/indexdb-memory/lib/db/base');
|
|
2
|
-
const { md5 } = require('@ocap/util/lib/md5');
|
|
3
|
-
|
|
4
|
-
const Table = require('./table/base');
|
|
5
|
-
const Transaction = require('./table/transaction');
|
|
6
|
-
const { name, version } = require('../package.json');
|
|
7
|
-
|
|
8
|
-
class FsIndexDB extends BaseIndexDB {
|
|
9
|
-
constructor(dataDir) {
|
|
10
|
-
super();
|
|
11
|
-
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.version = version;
|
|
14
|
-
|
|
15
|
-
this.md5 = md5;
|
|
16
|
-
|
|
17
|
-
this.account = new Table('account', dataDir, 'address');
|
|
18
|
-
this.asset = new Table('asset', dataDir, 'address');
|
|
19
|
-
this.factory = new Table('factory', dataDir, 'address');
|
|
20
|
-
this.delegation = new Table('delegation', dataDir, 'address');
|
|
21
|
-
this.tx = new Transaction('tx', dataDir, 'hash');
|
|
22
|
-
this.token = new Table('token', dataDir, 'address');
|
|
23
|
-
this.stake = new Table('stake', dataDir, 'address');
|
|
24
|
-
this.rollup = new Table('rollup', dataDir, 'address');
|
|
25
|
-
this.rollupBlock = new Table('rollupBlock', dataDir, 'hash');
|
|
26
|
-
this.rollupValidator = new Table('rollupValidator', dataDir, 'address');
|
|
27
|
-
this.tokenDistribution = new Table('tokenDistribution', dataDir, 'tokenAddress');
|
|
28
|
-
this.balance = new Table('balance', dataDir, ['address', 'tokenAddress']);
|
|
29
|
-
this.tokenFactory = new Table('tokenFactory', dataDir, 'address');
|
|
30
|
-
|
|
31
|
-
this.attachReadyListeners();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = FsIndexDB;
|
package/lib/main.js
DELETED
package/lib/table/base.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const path = require('node:path');
|
|
2
|
-
const { BaseIndex } = require('@ocap/indexdb');
|
|
3
|
-
const Lokijs = require('lokijs');
|
|
4
|
-
const FsAdapter = require('lokijs/src/loki-fs-structured-adapter');
|
|
5
|
-
|
|
6
|
-
const debug = require('debug')(require('../../package.json').name);
|
|
7
|
-
|
|
8
|
-
class FsIndex extends BaseIndex {
|
|
9
|
-
constructor(name, dataDir, uniqIndex) {
|
|
10
|
-
super(name, uniqIndex);
|
|
11
|
-
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.uniqIndex = uniqIndex;
|
|
14
|
-
this.collection = null;
|
|
15
|
-
|
|
16
|
-
const adapter = new FsAdapter();
|
|
17
|
-
const db = new Lokijs(path.join(dataDir, `${name}.db`), {
|
|
18
|
-
adapter,
|
|
19
|
-
autoload: true,
|
|
20
|
-
autosave: true,
|
|
21
|
-
autosaveInterval: 1000,
|
|
22
|
-
autoloadCallback: () => {
|
|
23
|
-
this.collection = db.getCollection(name);
|
|
24
|
-
|
|
25
|
-
if (this.collection === null) {
|
|
26
|
-
this.collection = db.addCollection(name, { unique: [this.primaryKey], clone: true });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.markReady();
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
this.db = db;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
count(...args) {
|
|
36
|
-
return this.collection.count(...args);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_insert(row) {
|
|
40
|
-
const id = this.generatePrimaryKey(row);
|
|
41
|
-
// Don't call this._get here cause _get may be overwritten
|
|
42
|
-
const doc = FsIndex.prototype._get.call(this, id);
|
|
43
|
-
if (doc) {
|
|
44
|
-
return doc;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
debug(`insert ${this.name}`, row);
|
|
48
|
-
return this.collection.insert({ [this.primaryKey]: id, ...row });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_get(key) {
|
|
52
|
-
const id = this.generatePrimaryKey(key);
|
|
53
|
-
return key ? this.collection.by(this.primaryKey, id) : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
_update(key, updates) {
|
|
57
|
-
const id = this.generatePrimaryKey(key);
|
|
58
|
-
// Don't call this._get here cause _get may be overwritten
|
|
59
|
-
const doc = FsIndex.prototype._get.call(this, id);
|
|
60
|
-
if (!doc) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
debug(`update ${this.name}`, { id, key, updates });
|
|
65
|
-
|
|
66
|
-
Object.assign(doc, updates);
|
|
67
|
-
this.collection.update(doc);
|
|
68
|
-
return doc;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
_reset() {
|
|
72
|
-
this.collection.removeWhere({});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = FsIndex;
|
package/lib/table/transaction.js
DELETED