test-ic-wallet-middleware-common
Version:
Ic middleware wallet common objects
42 lines (41 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseRxDbContext = void 0;
const errors_1 = require("../errors");
const rxdb_1 = require("rxdb");
class BaseRxDbContext {
rxStorage;
constructor(rxStorage) {
this.rxStorage = rxStorage;
}
_db;
get db() {
if (this._db) {
return this._db;
}
throw new errors_1.DbContextError("db.not.initialized", "DB is not initialized");
}
set db(rxDb) {
this._db = rxDb;
}
async init() {
this._db = await (0, rxdb_1.createRxDatabase)({
name: this.getDbName(),
storage: this.rxStorage,
ignoreDuplicate: false,
eventReduce: true,
hashFunction: (input) => {
let hash = 0x811c9dc5; // FNV offset basis
for (let i = 0; i < input.length; i++) {
hash ^= input.charCodeAt(i);
hash *= 0x01000193; // FNV prime
hash >>>= 0; // Convert to unsigned 32-bit integer
}
return Promise.resolve((hash >>> 0).toString());
},
cleanupPolicy: {},
});
await this._db.addCollections(this.getSchema());
}
}
exports.BaseRxDbContext = BaseRxDbContext;