open-index/open-npm huggingface dataset:
npm package: @superseed/core
Description: This is package contains core Classes and helpers for defining custom MockGenerators nad DataSources.
Latest version: 2.1.3

# superseed core 

This is package contains core Classes and helpers for defining custom MockGenerators nad DataSources.

# Core classes
## MockGenerator
The base Mock generator class to extend when  defining custom generators.
 
### Creating a custom mock generator

A mock generator must extend the MockGenerator and implement the generate() method. This method generate multiple mocks based on the cound. The 
*Example:*

```js
const {MockGenerator} = require('@supoerseed/core');
 class CustomGenerator extends MockGenerator {
  generateMock(db, staticFields = {}) {
   // generate some mock data
  }
}
const myGenerator = new CustomGenerator();
```

A simpler way is
```js
const myGenerator = new MockGenerator({
  generateMock(db, staticFields = {}) {
    // generate some mock data
  }
});
```

For more examples see [@superseed/mongoose](https://www.npmjs.com/package/@superseed/mongoose) and [@superseed/mocker-data-generator](https://www.npmjs.com/package/@superseed/mocker-data-generator) 

## DataSource
The Mock generator class to extend when defining custom data sources.

### Creating a custom data source
*Example:*

```js
class CustomSource extends DataSource {
    createSeeds(seeds){
       // save seed somewhere
    }
    
    deleteSeeds() {
      // delete seed created earlier 
    }
}
const myCustomSource = new CustomSource();
```

A simplified way 

```js
const myCustomSource = new DataSource({
  createSeeds(seeds) {
    // save seed somewhere
  },
  deleteSeeds() {
    // delete seed created earlier 
  }
});
```

For more examples see [@superseed/mongodb](https://www.npmjs.com/package/@superseed/mongodb) and [@superseed/restapi](https://www.npmjs.com/package/@superseed/restapi) 


# Core generators

- hasMany
- hasOne
npm package: @superseed/mocker-data-generator
Description: A super-seed module that allows support for MockGenerators using [mocker-data-generator](https://www.npmjs.com/package/mocker-data-generator) schema
Latest version: 2.0.4

# superseed mocker-data-generator

A super-seed module that allows support for MockGenerators using [mocker-data-generator](https://www.npmjs.com/package/mocker-data-generator) schema

# Install

```bash
npm install @superseed/mocker-data-generator
```

# Usage

_Example:_

```js
const {Seeder, SeedJob} = require('@super-seed/superseed');
const MockSchema = require('@superseed/mocker-data-generator');

class CustomSeeded extends BasedataSource {
    createSeeds(seeds) {
        // save seed somewhere
    }
}

// sample from mocker-data-generator
const person = {
    firstName: {
        faker: 'name.firstName'
    },
    lastName: {
        faker: 'name.lastName'
    },
    country: {
        faker: 'address.country'
    },
    createdAt: {
        faker: 'date.past'
    },
};

const cat = {
    name: {
        chance: 'word'
    },
    ownerId: {
        hasOne: 'users',
        get: '_id'
    }
};

const peopleSeeder = new SeedJob(
    'users',
    new MockSchema(user),
    new CustomSeeded()
);

const catSeeder = new SeedJob('cats', new MockSchema(cat), new CustomSeeded());

const seeder = new Seeder();
seeder.addJob(peopleSeeder, 1).addJob(catSeeder, 2);
seeder.seed().then(data => {
    console.log(data);
});
```
npm package: @superseed/mongodb
Description: REST API data source for super-seed
Latest version: 1.1.0

# super-seed-mongodb
REST API data source for super-seed

# Install
```bash
npm install @superseed/mongodb
```

## Usage example

The Mongo DB data source allow storage of seeds to MongoDB

*Example:*

```js
const {Seeder, SeedJob} = require('@superseed/superseed');
const MongoDBSource = require('@superseed/mongodb');
const {BaseMockGenerator} = require('@superseed/core');

class MyGenerator extends BaseMockGenerator {
  generateMock(db, staticFields) {
    return {
     name: 'test'
    }
  }
}

const mongodbSource = new MongoDBSource({
      url: 'mongodb://localhost:27017',
      dbName: 'test-seeds',
      options: {
        auth: {
          user: 'user',
          password: 'password'
        }
      }
});

const peopleSeeder = new SeedJob('users', new MyGenerator(), mongodbSource.collection('users'));

const seeder = new Seeder();
seeder.addJob(peopleSeeder, 1);
const data = await seeder.seed();    
```
npm package: @superseed/restapi
Description: REST API data source for [superseed](https://www.npmjs.com/package/@superseed/superseed)
Latest version: 1.1.5

# @superseed/restapi
REST API data source for [superseed](https://www.npmjs.com/package/@superseed/superseed)

# Install
```bash
npm i @superseed/restapi
```

## Usage example
```js

const {Seeder, SeedJob} = require('@superseed/superseed');
const APISource = require('@superseed/restapi');
const {BaseMockGenerator} = require('@superseed/core');

const myService = new APISource({
  baseURL: 'http://localhost:1234/api/v1',
  responseHandler
});

const myEntity = myService.defineEntity({
  basePath: '/entities',
  name: 'Entity'
});

class MyGenerator extends BaseMockGenerator {
  generate(db, count) {
    return [...Array(count).keys()].map(() => ({
      name: 'test'
    }));
  }
}
const peopleSeeder = new SeedJob('users', new MyGenerator(), myEntity);

const seeder = new Seeder();
seeder.addJob(peopleSeeder, 1);
const data = await seeder.seed();

```