Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add more interfaces and types #2415

Merged
merged 19 commits into from Apr 14, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

refactor(core-database): add interfaces and types

  • Loading branch information...
faustbrian committed Apr 14, 2019
commit 3a7bde80af048f88a1da15dd6d0ec0874f415897
@@ -11,8 +11,7 @@ export const databaseServiceFactory = async (
walletManager: Database.IWalletManager,
connection: Database.IConnection,
): Promise<Database.IDatabaseService> => {
let databaseService: DatabaseService;
databaseService = new DatabaseService(
const databaseService: Database.IDatabaseService = new DatabaseService(
opts,
connection,
walletManager,
@@ -21,6 +20,8 @@ export const databaseServiceFactory = async (
new TransactionsBusinessRepository(() => databaseService),
new BlocksBusinessRepository(() => databaseService),
);

await databaseService.init();

return databaseService;
};

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,7 @@
import { Database } from "@arkecosystem/core-interfaces";
import { SearchParameterConverter } from "./utils/search-parameter-converter";

// @TODO: add database block interface
export class BlocksBusinessRepository implements Database.IBlocksBusinessRepository {
constructor(private databaseServiceProvider: () => Database.IDatabaseService) {}

@@ -6,18 +6,10 @@ import { sortEntries } from "./utils/sort-entries";

type CallbackFunctionVariadicVoidReturn = (...args: any[]) => void;

// @TODO: add return types
export class DelegatesBusinessRepository implements Database.IDelegatesBusinessRepository {
/**
* Create a new delegate repository instance.
* @param databaseServiceProvider
*/
public constructor(private databaseServiceProvider: () => Database.IDatabaseService) {}

/**
* Get all local delegates.
* @param {Object} params
* @return {Object}
*/
public getLocalDelegates(params: Database.IParameters = {}) {
// TODO: What's the diff between this and just calling 'allByUsername'
let delegates = this.databaseServiceProvider()
@@ -44,11 +36,6 @@ export class DelegatesBusinessRepository implements Database.IDelegatesBusinessR
return delegates;
}

/**
* Find all delegates.
* @param {Object} params
* @return {Object}
*/
public findAll(params: Database.IParameters = {}) {
this.applyOrder(params);

@@ -3,6 +3,7 @@ import { Database } from "@arkecosystem/core-interfaces";
import { Enums } from "@arkecosystem/crypto";
import { SearchParameterConverter } from "./utils/search-parameter-converter";

// @TODO: add database transaction interface
export class TransactionsBusinessRepository implements Database.ITransactionsBusinessRepository {
constructor(private databaseServiceProvider: () => Database.IDatabaseService) {}

@@ -3,26 +3,14 @@ import filterRows from "./utils/filter-rows";
import limitRows from "./utils/limit-rows";
import { sortEntries } from "./utils/sort-entries";

// @TODO: add return types
export class WalletsBusinessRepository implements Database.IWalletsBusinessRepository {
/**
* Create a new wallet repository instance.
* @param databaseServiceProvider
*/
public constructor(private databaseServiceProvider: () => Database.IDatabaseService) {}

/**
* Get all local wallets.
* @return {Array}
*/
public all() {
return this.databaseServiceProvider().walletManager.allByAddress();
}

/**
* Find all wallets.
* @param {{ orderBy?: string }} params
* @return {Object}
*/
public findAll(params: Database.IParameters = {}) {
this.applyOrder(params);

@@ -34,12 +22,6 @@ export class WalletsBusinessRepository implements Database.IWalletsBusinessRepos
};
}

/**
* Find all wallets for the given vote.
* @param {String} publicKey
* @param {Object} params
* @return {Object}
*/
public findAllByVote(publicKey: string, params: Database.IParameters = {}) {
this.applyOrder(params);

@@ -51,23 +33,14 @@ export class WalletsBusinessRepository implements Database.IWalletsBusinessRepos
};
}

/**
* Find a wallet by address, public key or username.
*/
public findById(id: string) {
return this.all().find(wallet => wallet.address === id || wallet.publicKey === id || wallet.username === id);
}

/**
* Count all wallets.
*/
public count() {
return this.all().length;
}

/**
* Find all wallets sorted by balance.
*/
public top(params: Database.IParameters = {}) {
this.applyOrder(params);

Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.