@aida/injector-faked-model

Aida faked model injector

Usage no npm install needed!

<script type="module">
  import aidaInjectorFakedModel from 'https://cdn.skypack.dev/@aida/injector-faked-model';
</script>

README

Injector - Faked Model

Introduction

The Faked Model injector generates an array of fake data for each of the specified models.

Dependencies

The Faked Model injector has no dependencies.

Use Cases

The main use case for this injector is to generate a larger amount of fake data that can later be used to insert into development databases or for other similar uses.

Example


//This is what will be generated by fakedModel. Check the supported options for more details on the generated data.
const fakedModels = {
  "User": [
    {
      "id": "27bd418b-05e0-4e40-9fb2-54a9ff7de038",
      "address": {
        "city": "Nara",
        "street": "914 Al Spring Suite 191"
      }
    }
  ],
  "Product": [
    {
      "name": "Shampoo",
      "weight": "300grams"
    }
  ]
}

//...
// In some script, insert the fake data to MongoDB
Object.keys(fakedModels).forEach(modelName => {
  db[modelName.toLowerCase()].insertMany(fakedModels[modelName]);
});

API

options

  • exclude: An array of model names for which data should not be generated. If a include is provided, it only uses the include models, ignoring the exclude ones.
  • include: An array of model names for which data should be generated. If provided, it will only include the models in the include. If neither exclude nor include is provided, it generates data for all models.
  • itemsPerModel: The number of fake objects (items) to be generated per model. Defaults to 1.
  • modelType: The model type for which the data should be generated. Defaults to 'core'.
  • seed: An integer to serve as the seed for the random data generation. Defaults to 12.