Skip to content

Commit fcea584

Browse files
namestydOrgJellijellegerbrandyorenyodfat
authored
Client 2 0 dev (#467)
* [WIP] Modelling separate schemes, proposals and other entities * [WIP] Proposal does not depend on Plugin type * [WIP] Generic Scheme progress * More progess and corrections on GenericScheme * use migration-experimental * read updates * docs updated * test fix * Scheme and Proposal search, and type specific itemMaps implemented * [WIP] Better and dynamic use of fragments * init * State implemented for GenericScheme and name fixes * Various fixes + Vote and Stake added * Turned proposal fields into EntityRefs * Logger and Tag added * [WIP] Detemplatized ProposalPlugin and added Queue and DAO * Reward, Reputation and Settings added * [WIP] All remaining entities added * [WIP] Organizing classes: fields, constructor, static, read, write * review comments * test addresses + begin version fixes * all tests almost passing * ItemMap base abstraction and SchemeRegistrar added * ContributionReward and UGenericScheme + small refactor * tests passing * remove comment * revert doc updates * package-lock updates * Competition suggestion and vote added. All schemes except competition * test-env 4.0.2 * wait for subgraph * sleep longer? * sleep * sleep longer :/ * wait script * remove test logging * fix * fix error message * handle startup log * executable shell script * new scaffolding * linter fix * Competition added * TS and Linter fixes. New folder replaced old src * Renamed scheme to plugin everywhere except queries, results and names * Dynamic querying of proposals and plugin fragment fixes * General cleanup * fix compiler errors * Minor fixes * Eliminated boilerplate constructors and itemMap wrappers * Arc getABI function signature changed. Handler for all params missing * Templatized plugin and proposal with states. Eliminated UGS * Extra constructors deleted and linter fix * Added missing proposal methods, templatized create proposal, tests prog * [WIP] progress on test updates * Plugin calculateID method. Dao createProposal mehtod simplified * Proposal is now created in dao.createProposal * Typedefs for anyProposal, anyPlugin and anyProposalPlugin * change name and version * simplifying imports * Simplified imports * [WIP] Progress on tests and fixes * sleep 120 * Tests migrated (untested) * Minor fix on fetchState for plugins * Export for reputationFromToken Scheme * import changes * Merge fixes * merge fixes (no universal schemes + scheme params) * experimental merge fix * ProposalName fix * rollup working * static baseFragment getter * Static getters instead of fields * Access modifiers explicit * ProposalPlugins and Plugin both implemented in DAO. Query still missing * Query gets passed down to ItemMap for better error message with query * wait-for-subgraph.sh * trying to debug * test w/ dorgtech images * postgres logs * Fixed dependencies issue. Arc tests working * daostack docker images * dorgtech images * remove logging * fix * remove non-existent proposal types * itemMaps now return states instead of entities * change query * Wrappers for search itemMappers and fetchAll is new default * Competition Plugin no longer extends CRExt. Progress on tests * fix test * Votes now part of proposal state and query. Progress on tests * Competition fixes. Test progress * update docker images + regen docs * update graph-node * version bump * IArcOptions * remove web3Provider unused property * better typing * custom signer * version bump * web3 client + provider getters * Progress on tests. Mapped 'SchemeRegistrar' type to its proposal type * rebranding to arc.js (#449) * rebranding to arc.js * update docs * Unknown Plugin created. 25 tests to go * FetchAll condition eliminated. FetchState throws if found null * testing * lint fixes * getDefaultAddress(): string * cache.spec.ts working * token no contract fix * proposal.spec.ts passing * Proposal-stake tests fixed * proposal-execute.spec.ts working * queue.spec.ts working * dao fix * proposal-claim-reward.spec.ts working * SchemeRegistrar test fixes * init * Plugin base itemMap. ReputationFromToken now a plugin * Package json fix * Proposal competition test fixes * fix test * competition update * No more console.log. Replaced for logger * Linter fixes * IProposalType param removed. Proposal test bug fix * bump package version; add rc.13 support (#452) * bump package version; add rc.13 support * use latest version numbers for tests * Optional plugin param in createProposal options * Merge fixes * Member createdAt field added and tested * competition fix * linter fixes * fix dao.createProposal test * fix error * add competition suggestions back into the cache * linter fix * removing parallel cache manip tests * fix * skipping cache manip tests * export IEntityState * Doc, demojs and tsconfig updates * NoImplicit any flag enabled * Operation minor test fix * grammar updates + test cov * Removed unnecessary semicolons, appended 'Plugin' to all plugin classes * Queried ID passed to ItemMaps instead of query, for better error msgs * Arc client options interface * Dev docs, fragment cleanup and renaming 'scheme' to 'plugin' * Linter fixes * [WIP] PluginManager and tests * [WIP] PluginManager Add Test working * All tests working. Replaced plugin not being removed * Replace test still failing * Minor fix for plugin options parameter. Already fixed in main branch * test fix * Remove SchemeRegistrarEdit * update package-lock.json * linter fixes * use @daostack/test-env-experimental * Merge fixes for schemefactory * Linter fixes * dao.proposal and dao.plugin shorthands added * Single plugin and proposal search shorthands * dao.proposal(...) fix * Plugin and Proposal static create, with tests * version bump Co-authored-by: dOrgJelli <[email protected]> Co-authored-by: Jordan Ellis <[email protected]> Co-authored-by: Jelle Gerbrandy <[email protected]> Co-authored-by: orenyodfat <[email protected]>
1 parent 26bc0df commit fcea584

17 files changed

+937
-97
lines changed

package-lock.json

Lines changed: 49 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc.js",
3-
"version": "2.0.0-experimental.7",
3+
"version": "2.0.0-experimental.8",
44
"description": "",
55
"keywords": [],
66
"main": "dist/lib/index.js",
@@ -73,7 +73,7 @@
7373
},
7474
"devDependencies": {
7575
"@daostack/migration-experimental": "0.1.1-rc.16-v0",
76-
"@daostack/test-env-experimental": "4.0.5",
76+
"@daostack/test-env-experimental": "4.0.6",
7777
"@types/graphql": "^14.2.2",
7878
"@types/isomorphic-fetch": "^0.0.34",
7979
"@types/jest": "^24.0.15",

src/arc.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'ethers/dist/shims'
55
import { BigNumber } from 'ethers/utils'
66
import gql from 'graphql-tag'
77
import { Observable, Observer, of } from 'rxjs'
8+
import { first } from 'rxjs/operators'
89
import {
910
Address,
1011
AnyPlugin,
@@ -29,8 +30,6 @@ import {
2930
Logger,
3031
Operation,
3132
Plugin,
32-
PluginName,
33-
Plugins,
3433
Proposal,
3534
Reward,
3635
sendTransaction,
@@ -216,10 +215,6 @@ export class Arc extends GraphNodeObserver {
216215
return Tag.search(this, options, apolloQueryOptions)
217216
}
218217

219-
public plugin(id: string, name: PluginName): AnyPlugin {
220-
return new Plugins[name](this, id)
221-
}
222-
223218
public plugins(
224219
options: IPluginQueryOptions = {},
225220
apolloQueryOptions: IApolloQueryOptions = {}
@@ -234,6 +229,24 @@ export class Arc extends GraphNodeObserver {
234229
return Proposal.search(this, options, apolloQueryOptions)
235230
}
236231

232+
public async plugin(options: IPluginQueryOptions, unique?: boolean): Promise<AnyPlugin> {
233+
const plugins = await this.plugins(options).pipe(first()).toPromise()
234+
if (plugins.length !== 1 && unique) {
235+
throw Error('Could not find a unique plugin satisfying these options')
236+
} else {
237+
return plugins[0]
238+
}
239+
}
240+
241+
public async proposal(options: IPluginQueryOptions, unique?: boolean): Promise<AnyProposal> {
242+
const proposals = await this.proposals(options).pipe(first()).toPromise()
243+
if (proposals.length !== 1 && unique) {
244+
throw Error('Could not find a unique proposal satisfying these options')
245+
} else {
246+
return proposals[0]
247+
}
248+
}
249+
237250
public events(
238251
options: IEventQueryOptions = {},
239252
apolloQueryOptions: IApolloQueryOptions = {}

src/dao.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,41 @@ export class DAO extends Entity<IDAOState> {
203203
}
204204

205205
public async plugin(options: IPluginQueryOptions): Promise<AnyPlugin> {
206-
const plugins = await this.plugins(options).pipe(first()).toPromise()
206+
207+
const opts = {
208+
...options,
209+
where: {
210+
...options.where,
211+
dao: this.id
212+
}
213+
}
214+
215+
const plugins = await this.plugins(opts).pipe(first()).toPromise()
207216
if (plugins.length === 1) {
208217
return plugins[0]
209218
} else {
210219
throw Error('Could not find a unique plugin satisfying these options')
211220
}
212221
}
213222

223+
public async proposal(options: IProposalQueryOptions): Promise<AnyProposal> {
224+
225+
const opts = {
226+
...options,
227+
where: {
228+
...options.where,
229+
dao: this.id
230+
}
231+
}
232+
233+
const proposals = await this.proposals(opts).pipe(first()).toPromise()
234+
if (proposals.length === 1) {
235+
return proposals[0]
236+
} else {
237+
throw Error('Could not find a unique proposal satisfying these options')
238+
}
239+
}
240+
214241
public async proposalPlugin(options: IPluginQueryOptions): Promise<AnyProposalPlugin> {
215242
const plugins = await this.proposalPlugins(options).pipe(first()).toPromise()
216243
if (plugins.length === 1) {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export * from './plugins/genericPlugin'
1111
export * from './plugins/schemeRegistrar'
1212
export * from './plugins/reputationFromToken'
1313
export * from './plugins/unknownPlugin'
14+
export * from './plugins/pluginManager'
15+
export * from './plugins/unknownProposal'
1416
export * from './plugins/utils'
1517
export * from './utils'
1618
export * from './arc'

src/plugins/plugin.ts

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -99,48 +99,41 @@ export abstract class Plugin<TPluginState extends IPluginState> extends Entity<T
9999
${Plugin.baseFragment}
100100
`
101101

102-
const itemMap = (arc: Arc, item: any, queriedId?: string): AnyPlugin | null => {
103-
if (!options.where) {
104-
options.where = {}
105-
}
106-
107-
if (!Object.keys(Plugins).includes(item.name)) {
108-
Logger.debug(
109-
`Plugin name '${item.name}' not supported. Instantiating it as Unknown Plugin.`
110-
)
111-
112-
const state = Plugins.Unknown.itemMap(arc, item, queriedId)
113-
if (!state) {
114-
return null
115-
}
102+
return context.getObservableList(
103+
context,
104+
query,
105+
Plugin.deduceTypeAndCreate,
106+
options.where?.id,
107+
apolloQueryOptions
108+
) as Observable<
109+
Array<Plugin<TPluginState>>
110+
>
111+
}
116112

117-
return new Plugins.Unknown(arc, state)
118-
} else {
119-
if (item.name === 'ContributionRewardExt') {
120-
// Determine what type of plugin this is
121-
const rewarder = item.contributionRewardExtParams.rewarder
122-
123-
try {
124-
if (arc.getContractInfo(rewarder).name === 'Competition') {
125-
item.name = 'Competition'
126-
}
127-
} catch (err) {
128-
// Continue as usual, creating a ContributionRewardExt class
129-
}
113+
public static async create(context: Arc, id: string): Promise<AnyPlugin> {
114+
const query = gql`query SchemeStateById
115+
{
116+
controllerScheme (id: "${id}") {
117+
...PluginFields
130118
}
119+
}
120+
${Plugin.baseFragment}
121+
`
122+
const observable = context.getObservableObject(
123+
context,
124+
query,
125+
Plugin.deduceTypeAndCreate,
126+
id,
127+
{}
128+
) as Observable<AnyPlugin | null>
131129

132-
const state: IPluginState = Plugins[item.name].itemMap(arc, item, queriedId)
133-
if (!state) {
134-
return null
135-
}
130+
const result = await observable.pipe(first()).toPromise()
136131

137-
return new Plugins[item.name](arc, state)
138-
}
132+
if (!result) {
133+
throw new Error(`Plugin with id '${id}' does not exist or is not indexed`)
139134
}
140135

141-
return context.getObservableList(context, query, itemMap, options.where?.id, apolloQueryOptions) as Observable<
142-
Array<Plugin<TPluginState>>
143-
>
136+
return result
144137
}
145138

146139
public static calculateId(opts: {
@@ -190,6 +183,41 @@ export abstract class Plugin<TPluginState extends IPluginState> extends Entity<T
190183
}
191184
private static baseFragmentField: DocumentNode | undefined
192185

186+
private static deduceTypeAndCreate(context: Arc, item: any, queriedId?: string): AnyPlugin | null {
187+
if (!Object.keys(Plugins).includes(item.name)) {
188+
Logger.debug(
189+
`Plugin name '${item.name}' not supported. Instantiating it as Unknown Plugin.`
190+
)
191+
192+
const state = Plugins.Unknown.itemMap(context, item, queriedId)
193+
if (!state) {
194+
return null
195+
}
196+
197+
return new Plugins.Unknown(context, state)
198+
} else {
199+
if (item.name === 'ContributionRewardExt') {
200+
// Determine what type of plugin this is
201+
const rewarder = item.contributionRewardExtParams.rewarder
202+
203+
try {
204+
if (context.getContractInfo(rewarder).name === 'Competition') {
205+
item.name = 'Competition'
206+
}
207+
} catch (err) {
208+
// Continue as usual, creating a ContributionRewardExt class
209+
}
210+
}
211+
212+
const state: IPluginState = Plugins[item.name].itemMap(context, item, queriedId)
213+
if (!state) {
214+
return null
215+
}
216+
217+
return new Plugins[item.name](context, state)
218+
}
219+
}
220+
193221
// @ts-ignore
194222
public 'constructor': typeof Plugin
195223

src/plugins/pluginManager/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './plugin'
2+
export * from './proposal'

0 commit comments

Comments
 (0)