Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bootstrap): Implement async bootstrapping and mock store
- Loading branch information
Showing
13 changed files
with
120 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
VERBOSITY=silly | ||
API_BASE=/api |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './store'; | ||
export * from './mock.store'; |
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,37 @@ | ||
import { identifier, ModelStatic, Model } from '../models/model'; | ||
import { Collection } from '../models/collection'; | ||
import { Store, Query } from './store'; | ||
import {Chance} from 'chance'; | ||
import * as _ from 'lodash'; | ||
|
||
export type ChanceInstance = Chance.Chance; | ||
|
||
export abstract class MockStore<T extends Model> extends Store<T> { | ||
|
||
protected chanceInstance: ChanceInstance; | ||
|
||
constructor(modelStatic: ModelStatic<T>) { | ||
super(modelStatic); | ||
} | ||
|
||
protected chance(seed?: any): ChanceInstance { | ||
if (!this.chanceInstance || !!seed) { | ||
this.chanceInstance = new Chance(seed); | ||
} | ||
return this.chanceInstance; | ||
} | ||
|
||
protected abstract getMock(id?:identifier):T; | ||
|
||
public findOne(id: identifier): Promise<T> { | ||
return Promise.resolve(this.getMock(id)); | ||
} | ||
|
||
public findMany(query?:any): Promise<Collection<T>> { | ||
|
||
const models = _.times(10, () => this.getMock()); | ||
|
||
return Promise.resolve(new Collection(models)); | ||
} | ||
|
||
} |
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,6 +1,6 @@ | ||
export function maxLength(length: number): PropertyDecorator { | ||
return (target: any, propertyKey: string) => { | ||
let type = Reflect.getMetadata("design:type", target, propertyKey); | ||
console.log(length, type); | ||
// console.log(length, type); | ||
}; | ||
} |
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