AI Integration

MockData

Realistic sample values for a type, committed next to it.

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}>;
  };
}
OptionApplies toWhat it does
poolstrings, numbers, booleans, bigints, …draw the value from this list
min / maxnumbers, datesbound the generated range
rt$itemsarraysthe element node (a MockData node for T[number])
rt$lengtharraysfixed length, or a [min, max] range
rt$optionalobjectschance (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 } }
Without 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.

Use MockData<T> in tests and seed scripts, and import createMockDataFn from @mionjs/run-types/mocking, so your app bundle ships no mock pools.
Copyright © 2026