-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Batterii/nb/definition-hierarchy
Implement Definition Hierarchy, individual adapter methods
- Loading branch information
Showing
20 changed files
with
447 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import {Evaluator} from "../evaluator"; | ||
|
||
export interface Adapter { | ||
build<T>(Model: any): T; | ||
build<T>(Model: any, evaluator?: Evaluator): T|Promise<T>; | ||
save<T>(instance: T, Model?: any): Promise<T>; | ||
destroy(instance: Record<string, any>, Model?: any): Promise<void>; | ||
relate(instance: any, name: string, other: any, Model?: any): Promise<Record<string, any>>; | ||
set(instance: Record<string, any>, key: string, value: any): Promise<Record<string, any>>; | ||
destroy<T>(instance: T, Model?: any): Promise<void>; | ||
relate<T>(instance: T, name: string, other: any, Model?: any): T|Promise<T>; | ||
set<T>(instance: T, key: string, value: any): T|Promise<T>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {Definition} from "./definition"; | ||
import {FixtureRiveter} from "./fixture-riveter"; | ||
|
||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
export class DefinitionHierarchy { | ||
fixtureRiveter: FixtureRiveter; | ||
fixtureName: string; | ||
|
||
constructor(fixtureRiveter: FixtureRiveter, fixtureName: string) { | ||
this.fixtureRiveter = fixtureRiveter; | ||
this.fixtureName = fixtureName; | ||
} | ||
|
||
static setAdapterMethods(definition: Definition<any>): void { | ||
const toBuild = definition.toBuild(); | ||
if (toBuild) { | ||
this.prototype.build = toBuild; | ||
} | ||
|
||
const toSave = definition.toSave(); | ||
if (toSave) { | ||
this.prototype.save = toSave; | ||
} | ||
|
||
const toDestroy = definition.toDestroy(); | ||
if (toDestroy) { | ||
this.prototype.destroy = toDestroy; | ||
} | ||
|
||
const toRelate = definition.toRelate(); | ||
if (toRelate) { | ||
this.prototype.relate = toRelate; | ||
} | ||
|
||
const toSet = definition.toSet(); | ||
if (toSet) { | ||
this.prototype.set = toSet; | ||
} | ||
} | ||
|
||
build(Model: any): any { | ||
return this.fixtureRiveter.getAdapter(this.fixtureName).build(Model); | ||
} | ||
|
||
async save(instance: any, Model?: any): Promise<any> { | ||
return this.fixtureRiveter.getAdapter(this.fixtureName).save(instance, Model); | ||
} | ||
|
||
async destroy(instance: any, Model?: any): Promise<void> { | ||
return this.fixtureRiveter.getAdapter(this.fixtureName).destroy(instance, Model); | ||
} | ||
|
||
async relate(instance: any, name: string, other: any, Model?: any): Promise<any> { | ||
return this.fixtureRiveter | ||
.getAdapter(this.fixtureName) | ||
.relate(instance, name, other, Model); | ||
} | ||
|
||
async set(instance: any, key: string, value: any): Promise<any> { | ||
return this.fixtureRiveter.getAdapter(this.fixtureName).set(instance, key, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.