Skip to content

Commit eb6ee5c

Browse files
committed
feat: release interface-forge 2.7.0
1 parent f08dc24 commit eb6ee5c

18 files changed

Lines changed: 1158 additions & 125 deletions

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable user-facing changes to this project are documented here.
44

5+
## [2.7.0] - 2026-05-28
6+
7+
### Added
8+
9+
- Added `interface-forge/json-schema` with `JsonSchemaFactory` for optional AJV-backed JSON Schema data generation and validation.
10+
- Added JSON Schema support for object, primitive, array, nested object, `enum`, `const`, common string/number/array constraints, selected formats, and shallow local `$defs`/`definitions` references.
11+
- Added `factory.sequence.increment()`, `factory.sequence.template()`, and `factory.sequence.date()` helpers for stateful sequence values in factory schemas.
12+
- Added `IncrementSequenceGenerator`, `TemplateSequenceGenerator`, and `DateSequenceGenerator` exports for direct generator usage.
13+
14+
### Documentation
15+
16+
- Added JSON Schema integration documentation and installation guidance.
17+
- Updated generator documentation to cover `factory.sequence` and direct generator usage.
18+
519
## [2.6.7] - 2026-05-28
620

721
### Fixed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
</div>
1212

13-
A TypeScript library for creating strongly typed mock data factories. Built on [Faker.js](https://fakerjs.dev/) with advanced composition patterns, database persistence, fixture caching, and optional [Zod](https://zod.dev/) schema integration.
13+
A TypeScript library for creating strongly typed mock data factories. Built on [Faker.js](https://fakerjs.dev/) with advanced composition patterns, database persistence, fixture caching, and optional [Zod](https://zod.dev/) and JSON Schema integration.
1414

1515
## Support This Project
1616

@@ -27,7 +27,7 @@ Your support helps maintain and improve this library for the community! 🚀
2727
- **🔄 Advanced Composition**: Build complex object relationships with `compose()` and `extend()`
2828
- **🗄️ Database Integration**: Built-in persistence with Mongoose, Prisma, TypeORM adapters
2929
- **📁 Fixture Caching**: Cache generated data for consistent test scenarios
30-
- **📐 Zod Integration**: Generate data directly from schemas with validation
30+
- **📐 Schema Integration**: Generate data directly from Zod or JSON Schema with validation
3131
- **🔗 Hooks & Transforms**: Pre/post-build data transformation and validation
3232
- **🎲 Deterministic**: Seed generators for reproducible test data
3333

@@ -47,6 +47,9 @@ pnpm add --save-dev interface-forge
4747

4848
# For Zod integration (optional)
4949
npm install zod
50+
51+
# For JSON Schema integration (optional)
52+
npm install ajv ajv-formats
5053
```
5154

5255
## Quick Start
@@ -97,6 +100,24 @@ const userFactory = new ZodFactory(userSchema);
97100
const user = userFactory.build(); // Automatically validates against schema
98101
```
99102

103+
### JSON Schema Integration
104+
105+
```typescript
106+
import { JsonSchemaFactory } from 'interface-forge/json-schema';
107+
108+
const userSchema = {
109+
type: 'object',
110+
required: ['id', 'email'],
111+
properties: {
112+
id: { type: 'string', format: 'uuid' },
113+
email: { type: 'string', format: 'email' },
114+
},
115+
} as const;
116+
117+
const userFactory = new JsonSchemaFactory(userSchema);
118+
const user = userFactory.build(); // Automatically validates with AJV
119+
```
120+
100121
### Database Persistence
101122

102123
```typescript
@@ -147,6 +168,9 @@ const enhancedUserFactory = userFactory.compose<EnhancedUser>({
147168

148169
- `CycleGenerator` - Predictable value cycling
149170
- `SampleGenerator` - Random sampling without repeats
171+
- `factory.sequence.increment()` - Incrementing numeric sequences
172+
- `factory.sequence.template()` - Template-based string sequences
173+
- `factory.sequence.date()` - Date/time sequences
150174

151175
## Documentation
152176

@@ -155,6 +179,7 @@ const enhancedUserFactory = userFactory.compose<EnhancedUser>({
155179
- [Getting Started](https://goldziher.github.io/interface-forge/docs/getting-started/installation)
156180
- [Core Concepts](https://goldziher.github.io/interface-forge/docs/core/factory-basics)
157181
- [Zod Integration](https://goldziher.github.io/interface-forge/docs/schema/zod-integration)
182+
- [JSON Schema Integration](https://goldziher.github.io/interface-forge/docs/schema/json-schema-integration)
158183
- [Advanced Features](https://goldziher.github.io/interface-forge/docs/advanced/persistence)
159184
- [API Reference](https://goldziher.github.io/interface-forge/docs/api)
160185

docs/docs/api.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ const user = factory.build();
5555
- `withTypeHandler(typeName, handler)` - Add custom type handler
5656
- `withTypeHandlers(handlers)` - Add multiple type handlers
5757

58+
### JsonSchemaFactory
59+
60+
Generate data from JSON Schema and validate it with AJV.
61+
62+
```typescript
63+
import { JsonSchemaFactory } from 'interface-forge/json-schema';
64+
65+
const factory = new JsonSchemaFactory(userSchema);
66+
const user = factory.build();
67+
```
68+
69+
**Methods:**
70+
71+
- `build(overrides?)` - Generate and validate one object
72+
- `batch(count, overrides?)` - Generate and validate multiple objects
73+
- `buildAsync(overrides?)` - Async generation
74+
- `batchAsync(count, overrides?)` - Async batch generation
75+
5876
### Utility Classes
5977

6078
**Ref\<T>** - Lazy references
@@ -75,6 +93,15 @@ const gen = new CycleGenerator(['a', 'b', 'c']);
7593
const gen = new SampleGenerator(['x', 'y', 'z']);
7694
```
7795

96+
**factory.sequence** - Stateful sequence helpers
97+
98+
```typescript
99+
const userFactory = new Factory<User>((faker) => ({
100+
id: faker.sequence.increment({ start: 1 }),
101+
slug: faker.sequence.template('user-{0000}'),
102+
}));
103+
```
104+
78105
## Type Definitions
79106

80107
```typescript

docs/docs/core/generators.md

Lines changed: 61 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,162 +4,123 @@ sidebar_position: 3
44

55
# Utility Generators
66

7-
Control data patterns with specialized generators.
7+
Control repeated data patterns with generators.
8+
9+
## Factory Sequence Helpers
10+
11+
Use `factory.sequence` inside factory definitions for stateful values that advance across builds and batches:
12+
13+
```typescript
14+
import { Factory } from 'interface-forge';
15+
16+
const userFactory = new Factory<User>((faker) => ({
17+
id: faker.sequence.increment({ start: 1000 }),
18+
slug: faker.sequence.template('user-{0000}'),
19+
createdAt: faker.sequence.date({
20+
start: '2026-01-01T00:00:00.000Z',
21+
unit: 'day',
22+
}),
23+
email: faker.internet.email(),
24+
}));
25+
26+
const users = userFactory.batch(3);
27+
// ids: 1000, 1001, 1002
28+
// slugs: user-0001, user-0002, user-0003
29+
```
30+
31+
Each helper call site has independent state. Create a new factory when you need to reset the sequence.
832

933
## CycleGenerator
1034

1135
Cycle through predefined values sequentially:
1236

1337
```typescript
14-
import { CycleGenerator } from 'interface-forge';
38+
import { CycleGenerator, Factory } from 'interface-forge';
1539

16-
const statusGenerator = new CycleGenerator(['pending', 'active', 'failed']);
40+
const statusGenerator = new CycleGenerator(['pending', 'active', 'failed']).generate();
1741

1842
const taskFactory = new Factory<Task>((faker) => ({
1943
id: faker.string.uuid(),
20-
status: statusGenerator.next(), // Cycles: pending → active → failed → pending
44+
status: statusGenerator,
2145
title: faker.lorem.sentence(),
2246
}));
2347

2448
const tasks = taskFactory.batch(6);
25-
// Statuses: pending, active, failed, pending, active, failed
49+
// statuses: pending, active, failed, pending, active, failed
2650
```
2751

2852
## SampleGenerator
2953

30-
Random selection without consecutive duplicates:
54+
Randomly sample values without consecutive duplicates:
3155

3256
```typescript
33-
import { SampleGenerator } from 'interface-forge';
57+
import { Factory, SampleGenerator } from 'interface-forge';
3458

35-
const roleGenerator = new SampleGenerator(['user', 'admin', 'guest']);
59+
const roleGenerator = new SampleGenerator(['user', 'admin', 'guest']).generate();
3660

3761
const userFactory = new Factory<User>((faker) => ({
3862
id: faker.string.uuid(),
39-
role: roleGenerator.next(), // Random, but no consecutive duplicates
63+
role: roleGenerator,
4064
name: faker.person.fullName(),
4165
}));
4266
```
4367

68+
## Specialized Sequence Classes
69+
70+
The factory helpers are the ergonomic path for factory definitions. The underlying classes are also exported when you need to manage generator instances yourself:
71+
72+
```typescript
73+
import {
74+
DateSequenceGenerator,
75+
IncrementSequenceGenerator,
76+
TemplateSequenceGenerator,
77+
} from 'interface-forge';
78+
79+
const ids = new IncrementSequenceGenerator({ start: 1, step: 2 }).generate();
80+
const slugs = new TemplateSequenceGenerator('order-{0000}').generate();
81+
const dates = new DateSequenceGenerator({
82+
start: '2026-01-01T00:00:00.000Z',
83+
unit: 'hour',
84+
}).generate();
85+
```
86+
4487
## Practical Patterns
4588

4689
### Sequential IDs
4790

4891
```typescript
49-
const idGenerator = new CycleGenerator([1, 2, 3, 4, 5]);
50-
5192
const orderFactory = new Factory<Order>((faker) => ({
52-
id: idGenerator.next(),
93+
id: faker.sequence.increment({ start: 1 }),
5394
total: faker.number.float({ min: 10, max: 1000 }),
5495
}));
5596
```
5697

57-
### Weighted Distribution
58-
59-
```typescript
60-
// 50% basic, 30% premium, 20% enterprise
61-
const typeGenerator = new SampleGenerator([
62-
'basic',
63-
'basic',
64-
'basic',
65-
'basic',
66-
'basic',
67-
'premium',
68-
'premium',
69-
'premium',
70-
'enterprise',
71-
'enterprise',
72-
]);
73-
```
74-
7598
### State Transitions
7699

77100
```typescript
78-
const stateGenerator = new CycleGenerator([
101+
const statusGenerator = new CycleGenerator([
79102
'draft',
80103
'pending_review',
81104
'approved',
82105
'published',
83-
]);
106+
]).generate();
84107

85108
const articleFactory = new Factory<Article>((faker) => ({
86109
title: faker.lorem.sentence(),
87-
status: stateGenerator.next(),
110+
status: statusGenerator,
88111
}));
89112
```
90113

91114
### Time Slots
92115

93116
```typescript
94-
const timeSlots = ['09:00', '10:00', '11:00', '14:00', '15:00'];
95-
const timeGenerator = new CycleGenerator(timeSlots);
96-
97117
const appointmentFactory = new Factory<Appointment>((faker) => ({
98118
patientName: faker.person.fullName(),
99-
time: timeGenerator.next(),
119+
startsAt: faker.sequence.date({
120+
start: '2026-01-01T09:00:00.000Z',
121+
step: 30,
122+
unit: 'minute',
123+
}),
100124
duration: 30,
101125
}));
102126
```
103-
104-
## Advanced Usage
105-
106-
### Combining Generators
107-
108-
```typescript
109-
const priorityGen = new CycleGenerator(['low', 'medium', 'high']);
110-
const categoryGen = new SampleGenerator(['bug', 'feature', 'enhancement']);
111-
112-
const ticketFactory = new Factory<Ticket>((faker) => ({
113-
id: faker.string.uuid(),
114-
priority: priorityGen.next(),
115-
category: categoryGen.next(),
116-
}));
117-
```
118-
119-
### A/B Testing Data
120-
121-
```typescript
122-
const variantGen = new CycleGenerator(['A', 'B']);
123-
124-
const experimentFactory = new Factory<Experiment>((faker) => ({
125-
userId: faker.string.uuid(),
126-
variant: variantGen.next(), // Equal A/B distribution
127-
conversionRate: faker.number.float({ min: 0, max: 1 }),
128-
}));
129-
```
130-
131-
### Load Testing
132-
133-
```typescript
134-
const endpointGen = new CycleGenerator([
135-
'/api/users',
136-
'/api/products',
137-
'/api/orders',
138-
]);
139-
140-
const requestFactory = new Factory<Request>((faker) => ({
141-
endpoint: endpointGen.next(),
142-
method: faker.helpers.arrayElement(['GET', 'POST', 'PUT']),
143-
responseTime: faker.number.int({ min: 50, max: 2000 }),
144-
}));
145-
```
146-
147-
## Factory Integration
148-
149-
Use generators with factory methods:
150-
151-
```typescript
152-
const userFactory = new Factory<User>(factoryFn);
153-
154-
// iterate() - Use with CycleGenerator
155-
const iteratedFactory = userFactory.iterate(statusGenerator);
156-
157-
// sample() - Use with SampleGenerator
158-
const sampledFactory = userFactory.sample(
159-
[{ role: 'admin' }, { role: 'user' }],
160-
(template, faker) => ({
161-
...userFactory.build(),
162-
role: template.role,
163-
}),
164-
);
165-
```

docs/docs/getting-started/basic-usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ const eventFactory = new Factory<Event>((faker) => {
140140

141141
- [Factory Composition](../core/composition) - Combine factories
142142
- [Utility Generators](../core/generators) - Control data patterns
143-
- [Zod Integration](../schema/zod-integration) - Schema-based generation
143+
- [Zod Integration](../schema/zod-integration) - Zod-based generation
144+
- [JSON Schema Integration](../schema/json-schema-integration) - JSON Schema-based generation

docs/docs/getting-started/installation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ If you want to use the Zod integration, you will also need to install `zod`:
2525
```bash
2626
pnpm add zod
2727
```
28+
29+
## Optional JSON Schema Integration
30+
31+
If you want to use the JSON Schema integration, install the AJV peer dependencies:
32+
33+
```bash
34+
pnpm add ajv ajv-formats
35+
```

docs/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Interface Forge is a TypeScript library for creating strongly typed mock data fa
1313
- **Type-Safe Factories**: Create factories that are fully type-safe, ensuring that your test data always matches your interfaces.
1414
- **Faker.js Integration**: Leverages the full power of Faker.js for generating realistic data.
1515
- **Advanced Composition**: Easily compose factories to create complex data structures.
16-
- **Zod Schema Integration**: Generate mock data directly from your Zod schemas.
16+
- **Schema Integration**: Generate mock data directly from Zod or JSON Schema.
1717
- **Extensible**: Customize and extend the library to fit your specific needs.
1818

1919
## Support This Project

0 commit comments

Comments
 (0)