danibram / mocker-data-generator

A simplified way to generate masive mock data based on a schema, you can use the awesome fake/random data generators like (FakerJs, ChanceJs, CasualJs and RandExpJs)
https://danibram.github.io/mocker-data-generator/
MIT License
426 stars 45 forks source link

Would it be useful if I added a seed option? #104

Closed suspiciousfellow closed 4 years ago

suspiciousfellow commented 4 years ago

casual, faker, etc have seed options. There's not a documented way of doing that with this module. Is there one and if not if I added it and submitted a PR would you be likely to accept it?

danibram commented 4 years ago

Yes, sorry, i didnt have time to improve the library to be 100% modular, but if you want to add a generator, basically you can start reading the src/lib/Generator.ts there are the generators implemented, my next idea will be move the generators in separated files, but right now are there...

marshallswain commented 4 years ago

@danibram. Thanks for this awesome module!

I'm interested in adding a simple seed method to the Mocker class, here: https://github.com/danibram/mocker-data-generator/blob/master/src/lib/Mocker.ts#L17

I would specifically like to be able to seed the internal database by using this api:

mocker().seed(name, arrayOfData)

The seed method would accept a name and an array of data, like this:

seed(name: string, data: []): Mocker {
  this.DB[name] = data
  return this
}

More complete example of usage:

const mocker = require('mocker-data-generator').default

const assets = require('./assets.json')
const users = require('./services/users/users.fixtures')

mocker()
  .seed('assets', assets) // seeding data to be referenced by other schemas
  .schema('users', users, 10)
  .build()
  .then(data => {
    debugger
  }, error => {
    debugger
  })

Do you foresee any issues with this API? Would you be willing to merge a pull request if I submit one?

danibram commented 4 years ago

Hi! Thanks for your comments! Yes, I have to admit that I misunderstood the issue at first, now its clear, and running in v2.8.0, sorry @suspiciousfellow You can test here Thanks! For the next one, PR always welcome, but today I was faster 😂

danibram commented 4 years ago

I think now we can close that issue

marshallswain commented 4 years ago

So awesome! Thank you!

Spown commented 2 years ago

so... does seed suppose to do what it typically does in procedural generation or is it something else here? because right now it just adds the seed object as the first item in the collection and everything else is random on a runtime basis. also its not mentioned in the docs even once.