Skip to main content

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>
}
Strict Type Checking

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 cannot object will be used

/index.ts
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);

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

namedescriptiontype
indexindex of current data object being created, utilize the index for fields requiring uniquenessnumber

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

namedescriptiontype
connectionKeyDataresolved data array for config key specified as the connection key, type will match the corresponding type of connection key dataX[]
indexindex of current data object being manipulatednumber
indexDatadata of current data object being createdT

handler - optional

function to be ran when execute is called

can be sync or async

type

type DataHandler<T extends object> = (data: T[]) => Promise<void> | void

function parameters

namedescriptiontype
dataresolved data array for config keyT[]
need to utilize a common connection/transaction between handlers?

utilize same pattern used by the Database Load Example