Skip to content

Commit

Permalink
Factory definition, use chancejs as a faker
Browse files Browse the repository at this point in the history
  • Loading branch information
nhat-phan committed Mar 23, 2018
1 parent f28c0fe commit 4dc93ab
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 151 deletions.
5 changes: 0 additions & 5 deletions dist/lib/facades/global/MongooseProvider.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions dist/lib/facades/global/MongooseProvider.js

This file was deleted.

4 changes: 4 additions & 0 deletions dist/lib/factory/interfaces/IFactory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { IFactoryBuilder } from './IFactoryBuilder';
export interface IFactory {
(className: string): IFactoryBuilder;
}
File renamed without changes.
10 changes: 10 additions & 0 deletions dist/lib/factory/interfaces/IFactoryBuilder.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface IFactoryBuilder {
times(amount: number): this;
states(states: string): this;
create<T = any>(): Promise<T>;
create<T = any>(attributes: Object): Promise<T>;
make<T = any>(): T;
make<T = any>(attributes: Object): T;
raw<T = any>(): T;
raw<T = any>(attributes: Object): T;
}
2 changes: 2 additions & 0 deletions dist/lib/factory/interfaces/IFactoryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
14 changes: 14 additions & 0 deletions dist/lib/factory/interfaces/IFactoryManager.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IFactoryBuilder } from './IFactoryBuilder';
export declare type FactoryDefinition<Faker> = (this: IFactoryManager<Faker>, faker: Faker) => Object;
export interface IFactoryManager<Faker> {
define(className: string, definition: FactoryDefinition<Faker>): this;
defineAs(className: string, name: string, definition: FactoryDefinition<Faker>): this;
state(className: string, state: string, definition: FactoryDefinition<Faker>): this;
of(className: string, name: string): IFactoryBuilder;
create<T = any>(className: string, attributes: Object): Promise<T>;
createAs<T = any>(className: string, name: string, attributes: Object): Promise<T>;
make<T = any>(className: string, attributes: Object): T;
makeAs<T = any>(className: string, name: string, attributes: Object): T;
raw<T = any>(className: string, attribute: Object, name: string): T;
rawOf<T = any>(className: string, name: string, attributes: Object): T;
}
2 changes: 2 additions & 0 deletions dist/lib/factory/interfaces/IFactoryManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
6 changes: 0 additions & 6 deletions dist/lib/query-builders/interfaces/IMongooseProvider.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/test/drivers/EloquentDriverProvider.test.d.ts

This file was deleted.

125 changes: 0 additions & 125 deletions dist/test/drivers/EloquentDriverProvider.test.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/factory/interfaces/IFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IFactoryBuilder } from './IFactoryBuilder'

export interface IFactory {
(className: string): IFactoryBuilder
}
14 changes: 14 additions & 0 deletions lib/factory/interfaces/IFactoryBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface IFactoryBuilder {
times(amount: number): this

states(states: string): this

create<T = any>(): Promise<T>
create<T = any>(attributes: Object): Promise<T>

make<T = any>(): T
make<T = any>(attributes: Object): T

raw<T = any>(): T
raw<T = any>(attributes: Object): T
}
21 changes: 21 additions & 0 deletions lib/factory/interfaces/IFactoryManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IFactoryBuilder } from './IFactoryBuilder'

export type FactoryDefinition<Faker> = (this: IFactoryManager<Faker>, faker: Faker) => Object

export interface IFactoryManager<Faker> {
define(className: string, definition: FactoryDefinition<Faker>): this
defineAs(className: string, name: string, definition: FactoryDefinition<Faker>): this

state(className: string, state: string, definition: FactoryDefinition<Faker>): this

of(className: string, name: string): IFactoryBuilder

create<T = any>(className: string, attributes: Object): Promise<T>
createAs<T = any>(className: string, name: string, attributes: Object): Promise<T>

make<T = any>(className: string, attributes: Object): T
makeAs<T = any>(className: string, name: string, attributes: Object): T

raw<T = any>(className: string, attribute: Object, name: string): T
rawOf<T = any>(className: string, name: string, attributes: Object): T
}
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "najs-eloquent",
"version": "0.2.17",
"version": "0.2.18",
"scripts": {
"build": "npm run build-ts && npm run tslint",
"build-ts": "tsc -d && ./script/copy-custom-definitions.js",
Expand Down Expand Up @@ -44,13 +44,15 @@
"najs-binding": "^1.4.0"
},
"dependencies": {
"chance": "^1.0.13",
"lodash": "^4.17.4",
"mongoose": "^5.0.11",
"mongoose-timestamps-moment": "^1.0.0",
"najs-facade": "^1.1.1",
"pluralize": "^7.0.0"
},
"devDependencies": {
"@types/chance": "^1.0.0",
"@types/jest": "^21.1.8",
"@types/lodash": "^4.14.91",
"@types/moment": "^2.13.0",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
dependencies:
"@types/node" "*"

"@types/chance@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/chance/-/chance-1.0.0.tgz#f9afc0fea03a24025dfd40396d62e9e152211c8e"

"@types/events@*":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.1.0.tgz#93b1be91f63c184450385272c47b6496fd028e02"
Expand Down Expand Up @@ -516,6 +520,10 @@ chalk@^2.0.1, chalk@^2.3.0:
escape-string-regexp "^1.0.5"
supports-color "^5.2.0"

chance@^1.0.13:
version "1.0.13"
resolved "https://registry.yarnpkg.com/chance/-/chance-1.0.13.tgz#666bec2db42b3084456a3e4f4c28a82db5ccb7e6"

chokidar@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
Expand Down

0 comments on commit 4dc93ab

Please sign in to comment.