Skip to content

Commit

Permalink
ConnectorInterface is now IOrganizationConnector
Browse files Browse the repository at this point in the history
It also now contains the name and network properties.
  • Loading branch information
bpierre committed Jul 14, 2020
1 parent b9cfe5f commit 6456de9
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 68 deletions.
16 changes: 11 additions & 5 deletions packages/connect-core/src/connections/ConnectorJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import { AppFilters } from '@aragon/connect-types'
import { AppFilters, Network } from '@aragon/connect-types'
import IOrganizationConnector from './IOrganizationConnector'
import { App, Repo, Role } from '..'
import Permission from '../entities/Permission'
import { ConnectorInterface } from './ConnectorInterface'

export type ConnectorJsonConfig = { permissions: Permission[] }
export type ConnectorJsonConfig = {
permissions: Permission[]
network: Network
}

class ConnectorJson implements ConnectorInterface {
class ConnectorJson implements IOrganizationConnector {
#permissions: Permission[]
readonly name = 'json'
readonly network: Network

constructor({ permissions }: ConnectorJsonConfig) {
constructor({ permissions, network }: ConnectorJsonConfig) {
this.#permissions = permissions
this.network = network
}

async permissionsForOrg(): Promise<Permission[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { AppFilters, Network } from '@aragon/connect-types'
import App from '../entities/App'
import Permission from '../entities/Permission'
import Repo from '../entities/Repo'
import Role from '../entities/Role'
import { AppFilters } from '@aragon/connect-types'

export interface ConnectorInterface {
export default interface IOrganizationConnector {
readonly name: string
readonly network: Network
appByAddress(appAddress: string): Promise<App>
appForOrg(orgAddress: string, filters?: AppFilters): Promise<App>
appsForOrg(orgAddress: string, filters?: AppFilters): Promise<App[]>
chainId?: number
chainId?: string
connect?: () => Promise<void>
onAppsForOrg(
orgAddress: string,
filters: AppFilters,
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-core/src/entities/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AppIntent,
} from '../types'
import { resolveManifest, resolveArtifact } from '../utils/metadata'
import { ConnectorInterface } from '../connections/ConnectorInterface'
import IOrganizationConnector from '../connections/IOrganizationConnector'

// TODO:
// [ ] (ipfs) contentUrl String The HTTP URL of the app content. Uses the IPFS HTTP provider. E.g. http://gateway.ipfs.io/ipfs/QmdLEDDfi…/ (ContentUri passing through the resolver)
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class App extends CoreEntity {
constructor(
data: AppData,
metadata: Metadata,
connector: ConnectorInterface
connector: IOrganizationConnector
) {
super(connector)

Expand All @@ -71,7 +71,7 @@ export default class App extends CoreEntity {

static async create(
data: AppData,
connector: ConnectorInterface
connector: IOrganizationConnector
): Promise<App> {
const artifact = await resolveArtifact(data)
const manifest = await resolveManifest(data)
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-core/src/entities/CoreEntity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConnectorInterface } from '../connections/ConnectorInterface'
import IOrganizationConnector from '../connections/IOrganizationConnector'

export default class CoreEntity {
protected _connector: ConnectorInterface
protected _connector: IOrganizationConnector

constructor(connector: ConnectorInterface) {
constructor(connector: IOrganizationConnector) {
this._connector = connector
}
}
6 changes: 3 additions & 3 deletions packages/connect-core/src/entities/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import App from './App'
import TransactionIntent from '../transactions/TransactionIntent'
import Permission from './Permission'
import { XDAI_WSS_ENDPOINT } from '../params'
import { ConnectorInterface } from '../connections/ConnectorInterface'
import IOrganizationConnector from '../connections/IOrganizationConnector'
import { toArrayEntry } from '../utils/misc'

// TODO
Expand Down Expand Up @@ -54,11 +54,11 @@ export default class Organization {
#provider: ethers.providers.Provider
#connected: boolean

private _connector: ConnectorInterface
private _connector: IOrganizationConnector

constructor(
location: string,
connector: ConnectorInterface,
connector: IOrganizationConnector,
provider: any,
network: Network
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-core/src/entities/Permission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CoreEntity from './CoreEntity'
import App from './App'
import Role from './Role'
import { ConnectorInterface } from '../connections/ConnectorInterface'
import IOrganizationConnector from '../connections/IOrganizationConnector'

export interface ParamData {
argumentId: number
Expand All @@ -24,7 +24,7 @@ export default class Permission extends CoreEntity implements PermissionData {
readonly params!: ParamData[]
readonly roleHash!: string

constructor(data: PermissionData, connector: ConnectorInterface) {
constructor(data: PermissionData, connector: IOrganizationConnector) {
super(connector)

this.allowed = data.allowed
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-core/src/entities/Repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Metadata,
AragonArtifactRole,
} from '../types'
import IOrganizationConnector from '../connections/IOrganizationConnector'
import { resolveMetadata, resolveManifest } from '../utils/metadata'
import { ConnectorInterface } from '../connections/ConnectorInterface'

export interface RepoData {
address: string
Expand All @@ -29,7 +29,7 @@ export default class Repo extends CoreEntity {
constructor(
data: RepoData,
metadata: Metadata,
connector: ConnectorInterface
connector: IOrganizationConnector
) {
super(connector)

Expand All @@ -44,7 +44,7 @@ export default class Repo extends CoreEntity {

static async create(
data: RepoData,
connector: ConnectorInterface
connector: IOrganizationConnector
): Promise<Repo> {
const artifact = await resolveMetadata(
'artifact.json',
Expand Down
6 changes: 3 additions & 3 deletions packages/connect-core/src/entities/Role.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import CoreEntity from './CoreEntity'
import Permission, { PermissionData } from './Permission'
import IOrganizationConnector from '../connections/IOrganizationConnector'
import { AragonArtifact, Metadata } from '../types'
import { resolveArtifact } from '../utils/metadata'
import { ConnectorInterface } from '../connections/ConnectorInterface'

export interface RoleData {
appAddress: string
Expand All @@ -27,7 +27,7 @@ export default class Role extends CoreEntity {
constructor(
data: RoleData,
metadata: Metadata,
connector: ConnectorInterface
connector: IOrganizationConnector
) {
super(connector)

Expand All @@ -48,7 +48,7 @@ export default class Role extends CoreEntity {

static async create(
data: RoleData,
connector: ConnectorInterface
connector: IOrganizationConnector
): Promise<Role> {
const artifact = await resolveArtifact(data)

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { ConnectorInterface } from './connections/ConnectorInterface'
export { default as IOrganizationConnector } from './connections/IOrganizationConnector'
export {
default as ConnectorJson,
ConnectorJsonConfig,
Expand Down
1 change: 1 addition & 0 deletions packages/connect-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ethers } from 'ethers'
import IOrganizationConnector from './connections/IOrganizationConnector'

export type Metadata = (AragonArtifact | AragonManifest)[]

Expand Down
16 changes: 12 additions & 4 deletions packages/connect-ethereum/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import { Network } from '@aragon/connect-types'
import { AppFilters } from '@aragon/connect-types'
import {
ConnectorInterface,
IOrganizationConnector,
Permission,
App,
Repo,
Role,
} from '@aragon/connect-core'

export type ConnectorEthereumConfig = object
export type ConnectorEthereumConfig = {
network: Network
}

class ConnectorEthereum implements IOrganizationConnector {
readonly name = 'ethereum'
readonly network: Network

class ConnectorEthereum implements ConnectorInterface {
constructor(config: ConnectorEthereumConfig = {}) {}
constructor(config: ConnectorEthereumConfig) {
this.network = config.network
}

async permissionsForOrg(): Promise<Permission[]> {
return new Promise(resolve => {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-thegraph/src/__test__/apps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('when connecting to the mainnet subgraph', () => {
let connector: ConnectorTheGraph

beforeAll(() => {
connector = new ConnectorTheGraph(MAINNET_NETWORK)
connector = new ConnectorTheGraph({ network: MAINNET_NETWORK })
})

function isValidApp(): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-thegraph/src/__test__/permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('when connecting to the mainnet subgraph', () => {
let connector: ConnectorTheGraph

beforeAll(() => {
connector = new ConnectorTheGraph(MAINNET_NETWORK)
connector = new ConnectorTheGraph({ network: MAINNET_NETWORK })
})

describe('when querying for the permissions of an org', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-thegraph/src/__test__/repos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('when connecting to the mainnet subgraph', () => {
let connector: ConnectorTheGraph

beforeAll(() => {
connector = new ConnectorTheGraph(MAINNET_NETWORK)
connector = new ConnectorTheGraph({ network: MAINNET_NETWORK })
})

describe('when querying the repository of an app', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-thegraph/src/__test__/roles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('when connecting to the mainnet subgraph', () => {
let connector: ConnectorTheGraph

beforeAll(() => {
connector = new ConnectorTheGraph(MAINNET_NETWORK)
connector = new ConnectorTheGraph({ network: MAINNET_NETWORK })
})

describe('when querying the roles associated with an app', () => {
Expand Down
47 changes: 26 additions & 21 deletions packages/connect-thegraph/src/connector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
App,
ConnectorInterface,
IOrganizationConnector,
Permission,
Repo,
Role,
Expand All @@ -17,8 +17,9 @@ import {
} from './parsers'

export type ConnectorTheGraphConfig = {
verbose?: boolean
network: Network
orgSubgraphUrl?: string
verbose?: boolean
}

function getOrgSubgraphUrl(network: Network): string | null {
Expand Down Expand Up @@ -50,31 +51,35 @@ function appFiltersToQueryFilter(appFilters: AppFilters) {
return queryFilter
}

export default class ConnectorTheGraph extends GraphQLWrapper
implements ConnectorInterface {
constructor(
network: Network,
{ verbose = false, orgSubgraphUrl }: ConnectorTheGraphConfig = {}
) {
const _orgSubgraphUrl = orgSubgraphUrl || getOrgSubgraphUrl(network)
if (!_orgSubgraphUrl) {
export default class ConnectorTheGraph implements IOrganizationConnector {
#gql: GraphQLWrapper
readonly name = 'thegraph'
readonly network: Network

constructor(config: ConnectorTheGraphConfig) {
const orgSubgraphUrl =
config.orgSubgraphUrl || getOrgSubgraphUrl(config.network)

if (!orgSubgraphUrl) {
throw new Error(
`The chainId ${network.chainId} is not supported by the TheGraph connector.`
`The chainId ${config.network.chainId} is not supported by the TheGraph connector.`
)
}
super(_orgSubgraphUrl, verbose)

this.#gql = new GraphQLWrapper(orgSubgraphUrl, config.verbose)
this.network = config.network
}

async rolesForAddress(appAddress: string): Promise<Role[]> {
return this.performQueryWithParser(
return this.#gql.performQueryWithParser(
queries.ROLE_BY_APP_ADDRESS('query'),
{ appAddress: appAddress.toLowerCase() },
parseRoles
)
}

async permissionsForOrg(orgAddress: string): Promise<Permission[]> {
return this.performQueryWithParser(
return this.#gql.performQueryWithParser(
queries.ORGANIZATION_PERMISSIONS('query'),
{ orgAddress: orgAddress.toLowerCase() },
parsePermissions
Expand All @@ -85,7 +90,7 @@ export default class ConnectorTheGraph extends GraphQLWrapper
orgAddress: string,
callback: Function
): { unsubscribe: Function } {
return this.subscribeToQueryWithParser(
return this.#gql.subscribeToQueryWithParser(
queries.ORGANIZATION_PERMISSIONS('subscription'),
{ orgAddress: orgAddress.toLowerCase() },
callback,
Expand All @@ -94,15 +99,15 @@ export default class ConnectorTheGraph extends GraphQLWrapper
}

async appByAddress(appAddress: string): Promise<App> {
return this.performQueryWithParser(
return this.#gql.performQueryWithParser(
queries.APP_BY_ADDRESS('query'),
{ appAddress: appAddress.toLowerCase() },
parseApp
)
}

async appForOrg(orgAddress: string, filters: AppFilters): Promise<App> {
const apps = await this.performQueryWithParser<App[]>(
const apps = await this.#gql.performQueryWithParser<App[]>(
queries.ORGANIZATION_APPS('query'),
{
appFilter: appFiltersToQueryFilter(filters),
Expand All @@ -115,7 +120,7 @@ export default class ConnectorTheGraph extends GraphQLWrapper
}

async appsForOrg(orgAddress: string, filters: AppFilters): Promise<App[]> {
return this.performQueryWithParser<App[]>(
return this.#gql.performQueryWithParser<App[]>(
queries.ORGANIZATION_APPS('query'),
{
appFilter: appFiltersToQueryFilter(filters),
Expand All @@ -130,7 +135,7 @@ export default class ConnectorTheGraph extends GraphQLWrapper
filters: AppFilters,
callback: Function
): { unsubscribe: Function } {
return this.subscribeToQueryWithParser(
return this.#gql.subscribeToQueryWithParser(
queries.ORGANIZATION_APPS('subscription'),
{
appFilter: appFiltersToQueryFilter(filters),
Expand All @@ -147,7 +152,7 @@ export default class ConnectorTheGraph extends GraphQLWrapper
filters: AppFilters,
callback: Function
): { unsubscribe: Function } {
return this.subscribeToQueryWithParser(
return this.#gql.subscribeToQueryWithParser(
queries.ORGANIZATION_APPS('subscription'),
{
appFilter: appFiltersToQueryFilter(filters),
Expand All @@ -159,7 +164,7 @@ export default class ConnectorTheGraph extends GraphQLWrapper
}

async repoForApp(appAddress: string): Promise<Repo> {
return this.performQueryWithParser(
return this.#gql.performQueryWithParser(
queries.REPO_BY_APP_ADDRESS('query'),
{ appAddress: appAddress.toLowerCase() },
parseRepo
Expand Down
Loading

0 comments on commit 6456de9

Please sign in to comment.