MockData
Experimental The enrichment workflow works today; the generated file shape and the commands may still change between minor versions.
MockData<T> gives a type realistic sample values: pools of names and emails, ranges for numbers and dates, and hints for arrays and optional fields. It feeds the createMockDataFn<T>() generator. Like FriendlyText<T>, you commit it next to your type and the compiler checks it against that type on every build.
MockData Shape
The map mirrors your type, with the options each field's kind allows.
import type * as TF from '@mionjs/run-types/formats';
// src/models/user.ts
export interface User {
name: TF.String<{minLength: 2; maxLength: 60}>;
age: TF.Number<{min: 0; max: 120}>;
isActive: boolean;
tags: string[];
profile: {
email: TF.Email;
score: TF.Number<{min: 0; max: 100}>;
};
}
import type {MockData} from '@mionjs/run-types';
import type {User} from './user';
// @todo: generated skeleton — fill in real data, then delete this line
export const mockUser: MockData<User> = {
name: {pool: []},
age: {pool: []},
isActive: {pool: []},
tags: {rt$items: {pool: []}, rt$length: [1, 3]},
profile: {
email: {pool: []},
score: {pool: []},
},
};
import type {MockData} from '@mionjs/run-types';
import type {User} from './user';
export const mockUser: MockData<User> = {
name: {pool: ['Alice Martin', 'Liang Wei', 'Fatima Noor' /* …50+ */]},
age: {pool: [], min: 18, max: 95}, // empty pool: draw from the range instead
isActive: {pool: [true, true, false]},
tags: {rt$items: {pool: ['urgent', 'beta', 'vip']}, rt$length: [1, 4]},
profile: {
email: {pool: ['[email protected]', '[email protected]' /* … */]},
score: {pool: [], min: 0, max: 100},
},
};
| Option | Applies to | What it does |
|---|---|---|
pool | strings, numbers, booleans, bigints, … | draw the value from this list |
min / max | numbers, dates | bound the generated range |
rt$items | arrays | the element node (a MockData node for T[number]) |
rt$length | arrays | fixed length, or a [min, max] range |
rt$optional | objects | chance (0 to 1) that an optional member is present |
Generating Data from the Map
Pass the map to the generator through the data option.
import {createMockDataFn} from '@mionjs/run-types/mocking';
import type {User} from './user';
import {mockUser} from './mock-user';
const newUser = createMockDataFn<User>(undefined, {data: mockUser});
newUser();
// → { name: 'Liang Wei', age: 41, isActive: true,
// tags: ['beta', 'vip'],
// profile: { email: '[email protected]', score: 73 } }
data, the generator works as usual. The MockData<T> type and the createMockDataFn({ data }) integration ship today.Checking Sample Values at Build Time
Planned The compiler checks every pool value and range against its field at build time, not when your tests run. A bad value fails the build, and a min above max is reported too.
export const mockUser: MockData<User> = {
profile: {
email: { pool: ['[email protected]', 'not-an-email'] }, // error: 'not-an-email' isn't a valid email
score: { min: 0, max: 150 }, // error: 150 is above the field's max of 100
},
};
Format-Aware Defaults
Without a pool, the generator still follows type formats: an email field gets a real-looking address, a uuidv4 field a real-looking UUID. Use MockData<T> when you want believable values instead: real names in name, your own domains in email, realistic ranges in age. Any field you leave out falls back to the format-aware generator.
MockData<T> in tests and seed scripts, and import createMockDataFn from @mionjs/run-types/mocking, so your app bundle ships no mock pools.