API
[mocq]
configuration syntax
MocQ
[mocq]
configuration for an individual data object type
/** data object configuration syntax */
type MocQ<T extends object> = {
generator: DataGenerator<T>
count: number
connections?: {
[connectionKey: string]: DataConnection<T>
}
handler?: DataHandler<T>
}
when working with TypeScript it's best practice to utilize the MocQ
type to explicitly type your data object configurations
without an explicit type
[mocq]
will attempt to infer the key data object type, if it cannotobject
will be used
- Explicit Type (recommended)
- Type Assertion
import { mocq, MocQ } from 'mocq';
import { User, Node } from './types';
type customMocqConfig: {
users: MocQ<User>
nodes: MocQ<Node>
};
const config: customMocqConfig = {
/* ... */
};
const { generate, execute } = mocq(config);
import { mocq, MocQ } from 'mocq';
import { User, Node } from './types';
const config = {
users: {
/* ... */
} as MocQ<User>,
nodes: {
/* ... */
} as MocQ<Node>,
};
const { generate, execute } = mocq(config);
generator - required
generic synchronous function that returns a single instance of a data object
type
type DataGenerator<T extends object> = (index: number) => T
function parameters
name | description | type |
---|---|---|
index | index of current data object being created, utilize the index for fields requiring uniqueness | number |
count - required
number of desired data objects
allowed values
number > 0
connections - optional
key-value pairs allowing for the ability to hook into the generated data of configuration by key and augment data per instance of current data type
types
{
[connectionKey: string]: DataConnection<T>
}
connectionKey
must be present in top level config
type DataConnection<T extends object> = (connectionKeyData: X[], index: number, indexData: T) => Partial<T>
generic synchronous function that returns a partial of a data object to be spread onto generated data
see data resolution for more info
function parameters
name | description | type |
---|---|---|
connectionKeyData | resolved data array for config key specified as the connection key, type will match the corresponding type of connection key data | X[] |
index | index of current data object being manipulated | number |
indexData | data of current data object being created | T |
handler - optional
function to be ran when execute
is called
can be
sync
orasync
type
type DataHandler<T extends object> = (data: T[]) => Promise<void> | void
function parameters
name | description | type |
---|---|---|
data | resolved data array for config key | T[] |
utilize same pattern used by the Database Load Example