Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import { mergeSchemas } from '@tanker/datastore-base';
import { expect } from '@tanker/test-utils';
import dataStoreConfig, { makePrefix, openDataStore } from './TestDataStore';
import KeyStore from '../Session/LocalUser/KeyStore';
import UserStore from '../Users/UserStore';
import TrustchainStore from '../Trustchain/TrustchainStore';
const schemas = mergeSchemas(
KeyStore.schemas,
UserStore.schemas,
TrustchainStore.schemas,
);
const baseConfig = { ...dataStoreConfig, schemas };
async function makeMemoryDataStore() {
const config = { ...baseConfig, dbName: `trustchain-${makePrefix()}` };
const dataStore = await openDataStore(config);
return { dataStore, config };
}
describe('TrustchainStore', () => {
const TABLE_METADATA = 'trustchain_metadata';
const LAST_BLOCK_INDEX_KEY = 'lastBlockIndex';
async open(userId: Uint8Array, userSecret: Uint8Array): Promise {
const { adapter, prefix, dbPath, url } = this._options;
const schemas = mergeSchemas(
GlobalSchema,
KeyStore.schemas,
ResourceStore.schemas,
GroupStore.schemas,
);
const dbName = `tanker_${prefix ? `${prefix}_` : ''}${utils.toSafeBase64(userId)}`;
// $FlowIKnow DataStore is a flow interface, which does not support static methods
this._datastore = await adapter().open({ dbName, dbPath, schemas, url });
this._schemas = schemas;
this._keyStore = await KeyStore.open(this._datastore, userSecret);
this._resourceStore = await ResourceStore.open(this._datastore, userSecret);
this._groupStore = await GroupStore.open(this._datastore, userSecret);
await this._checkVersion(userSecret);
async init(skipRootBlock?: bool) {
const schemas = mergeSchemas(
KeyStore.schemas,
UserStore.schemas,
TrustchainStore.schemas,
GroupStore.schemas,
UnverifiedStore.schemas,
);
this.trustchainKeyPair = tcrypto.makeSignKeyPair();
this.generator = await Generator.open(this.trustchainKeyPair);
this.dataStoreConfig = { ...dataStoreConfig, schemas, dbName: `trustchain-${makePrefix()}` };
const { trustchainId } = this.generator;
const userIdString = 'let try this for now';
export async function makeMemoryDataStore(): Promise> {
const schemas = mergeSchemas(UserStore.schemas);
const baseConfig = { ...dataStoreConfig, schemas };
const config = { ...baseConfig, dbName: `user-store-test-${makePrefix()}` };
return openDataStore(config);
}
export function makeMemoryDataStore(schemas: Array, dbName: string): Promise> {
const config = { adapter: PouchDBMemory, schemas: mergeSchemas(schemas), dbName: makePrefix() + dbName };
return openDataStore(config);
}
export async function makeMemoryDataStore(): Promise> {
const schemas = mergeSchemas(GroupStore.schemas);
const baseConfig = { ...dataStoreConfig, schemas };
const config = { ...baseConfig, dbName: `group-store-test-${makePrefix()}` };
return openDataStore(config);
}