Skip to content

Commit 5f3279b

Browse files
authored
Merge pull request #259 from siberiacancode/#255
#255 into main 👽 add introducing and references
2 parents afe6b8f + a73dedc commit 5f3279b

14 files changed

Lines changed: 1084 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Introducing
3+
description: Introduction to mock-config-server
4+
---
5+
6+
<img src='/mock-config/configSchemaLight.svg' className='dark:hidden' />
7+
<img src='/mock-config/configSchemaDark.svg' className='hidden dark:block' />
8+
9+
The global mock configuration is represented as an array in which the first element is either `settings` or a `component`, and all subsequent elements are components.
10+
11+
## Settings
12+
13+
`Settings` define global parameters for the mock server. They enable you to configure features such as CORS, logging, artificial delays, and other operational options that apply to the entire server.
14+
15+
Settings are optional and can be placed as the first element in your configuration array. For detailed information, refer to the [Settings](./settings) section.
16+
17+
## Components
18+
19+
`Components` are modular units that organize and group related mock requests. They allow you to:
20+
21+
- Scope requests under a common base URL
22+
- Apply shared interceptors to all requests within the component
23+
- Group related endpoints together for better organization
24+
25+
Each component contains a `configs` array, which holds the actual request definitions. These configs are where you define how individual API endpoints should be mocked.
26+
27+
For detailed type information, refer to the [MockServerComponent](./references/MockServerComponent) reference.
28+
29+
## Configs
30+
31+
`Configs` are the fundamental concept in the mock server. Each config defines how to handle a single API endpoint.
32+
33+
Configs are easy to fill and maintain. They allow you to emulate various application behaviors by specifying matching criteria:
34+
35+
- For **REST requests**: `headers`, `cookies`, `query`, `params`, or `body`
36+
- For **GraphQL requests**: `headers`, `cookies`, `query`, or `variables`
37+
38+
Using these matching criteria, you can define different responses for different request conditions, making it easy to simulate various server behaviors and edge cases.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pages": ["introducing.mdx", "references"]
3+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: CORS
3+
---
4+
5+
import { TypeTable } from 'fumadocs-ui/components/type-table';
6+
7+
## Cors
8+
9+
<TypeTable
10+
type={{
11+
allowedHeaders: {
12+
description: 'List of allowed headers for CORS',
13+
type: 'string[]',
14+
default: '*'
15+
},
16+
credentials: {
17+
description: 'Whether to allow sending credentials (cookies, auth headers)',
18+
type: 'boolean',
19+
default: true
20+
},
21+
exposedHeaders: {
22+
description: 'Headers exposed to the browser',
23+
type: 'string[]',
24+
default: '*'
25+
},
26+
maxAge: {
27+
description: 'How long (in seconds) the results of a preflight request can be cached',
28+
type: 'number',
29+
default: 3600
30+
},
31+
methods: {
32+
description: 'Allowed HTTP methods (uppercased)',
33+
type: 'Uppercase<RestMethod>[]',
34+
typeDescriptionLink: './Rest#RestMethod',
35+
default: '"GET,OPTIONS,PUT,PATCH,POST,DELETE"'
36+
},
37+
origin: {
38+
description:
39+
'Allowed origin(s) — string, RegExp, array of strings/RegExps, or a function returning them',
40+
type: (
41+
<span>
42+
((request: Request) {'=>'}{' '}
43+
<a className='underline' href='#CorsOrigin'>
44+
CorsOrigin
45+
</a>{' '}
46+
| Promise{'<'}
47+
<a className='underline' href='#CorsOrigin'>
48+
CorsOrigin
49+
</a>
50+
{'>'}) |{' '}
51+
<a className='underline' href='#CorsOrigin'>
52+
CorsOrigin
53+
</a>
54+
</span>
55+
),
56+
required: true
57+
}
58+
}}
59+
/>
60+
61+
<a id='CorsOrigin'></a>
62+
## CorsOrigin
63+
64+
```typescript
65+
string | (string | RegExp)[] | RegExp
66+
```
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: Database
3+
---
4+
5+
import { TypeTable } from 'fumadocs-ui/components/type-table';
6+
7+
## DatabaseConfig
8+
9+
<TypeTable
10+
type={{
11+
data: {
12+
description: 'Initial data for the database',
13+
type: '`${string}.json` | Record<string, unknown>',
14+
required: true
15+
},
16+
routes: {
17+
description: 'Optional route mapping or JSON file path for database operations',
18+
type: '`${string}.json` | Record<`/${string}`, `/${string}`>'
19+
}
20+
}}
21+
/>
22+
23+
<a id='Orm'></a>
24+
## ORM
25+
26+
The ORM type is determined by the structure of your database. If a database is an array where each element has an `id` property, it uses `NestedOrm`. Otherwise, it uses `ShallowOrm`.
27+
28+
## ShallowOrm{'<'}Item{'>'}
29+
30+
Used for non-array database fields or arrays without `id` properties.
31+
32+
<TypeTable
33+
type={{
34+
get: {
35+
description: 'Get the current value',
36+
type: '() => Item',
37+
required: true
38+
},
39+
update: {
40+
description: 'Update the value',
41+
type: '(data: Item) => void',
42+
required: true
43+
}
44+
}}
45+
/>
46+
47+
## NestedOrm{'<'}Item{'>'}
48+
49+
Used for array database fields where each element has an `id` property. Provides full CRUD operations.
50+
51+
<TypeTable
52+
type={{
53+
count: {
54+
description: 'Get the number of items in the collection',
55+
type: '() => number',
56+
required: true
57+
},
58+
create: {
59+
description: 'Create a new item (id will be auto-generated)',
60+
type: '(item: Omit<Item, "id">) => Item',
61+
required: true
62+
},
63+
createMany: {
64+
description: 'Create multiple items at once',
65+
type: '(items: Omit<Item, "id">[]) => void',
66+
required: true
67+
},
68+
delete: {
69+
description: 'Delete an item by id',
70+
type: '(id: StorageIndex) => void',
71+
required: true
72+
},
73+
deleteMany: {
74+
description: 'Delete multiple items by their ids',
75+
type: '(ids: StorageIndex[]) => void',
76+
required: true
77+
},
78+
exists: {
79+
description: 'Check if an item exists matching the filters',
80+
type: '(filters: Partial<Item>) => boolean',
81+
required: true
82+
},
83+
findById: {
84+
description: 'Find an item by its id',
85+
type: '(id: StorageIndex) => Item | undefined',
86+
required: true
87+
},
88+
findFirst: {
89+
description: 'Find the first item matching the filters',
90+
type: '(filters?: Partial<Item>) => Item | undefined',
91+
required: true
92+
},
93+
findMany: {
94+
description: 'Find all items matching the filters',
95+
type: '(filters?: Partial<Item>) => Item[]',
96+
required: true
97+
},
98+
update: {
99+
description: 'Update an item by its id',
100+
type: '(id: StorageIndex, item: Partial<Omit<Item, "id">>) => void',
101+
required: true
102+
},
103+
updateMany: {
104+
description: 'Update multiple items by their ids',
105+
type: '(ids: StorageIndex[], item: Partial<Omit<Item, "id">>) => number',
106+
required: true
107+
}
108+
}}
109+
/>
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
title: GraphQL
3+
---
4+
5+
import { TypeTable } from 'fumadocs-ui/components/type-table';
6+
7+
## GraphqlConfig
8+
9+
<TypeTable
10+
type={{
11+
baseUrl: {
12+
description: 'The base URL',
13+
type: '`/${string}`'
14+
},
15+
configs: {
16+
description: 'Array of GraphQL request configurations',
17+
type: 'GraphQLRequestConfig[]',
18+
typeDescriptionLink: '#GraphQLRequestConfig',
19+
required: true
20+
},
21+
interceptors: {
22+
description: 'Optional interceptors applied to GraphQL handlers',
23+
type: "Interceptors<'graphql'>",
24+
typeDescriptionLink: './Interceptors'
25+
}
26+
}}
27+
/>
28+
29+
<a id='GraphQLRequestConfig'></a>
30+
## GraphQLRequestConfig
31+
32+
<TypeTable
33+
type={{
34+
operationType: {
35+
description: 'Operation type (query or mutation)',
36+
type: 'GraphQLOperationType',
37+
typeDescriptionLink: '#GraphQLOperationType',
38+
required: true
39+
},
40+
operationName: {
41+
description: 'Operation name (string or RegExp) used to match requests',
42+
type: 'GraphQLOperationName',
43+
typeDescriptionLink: '#GraphQLOperationName'
44+
},
45+
query: {
46+
description: 'GraphQL query string to match against incoming requests',
47+
type: 'string'
48+
},
49+
routes: {
50+
description: 'One or more route responses or queues for this operation',
51+
type: 'GraphQLRouteConfig[]',
52+
typeDescriptionLink: '#GraphQLRouteConfig',
53+
required: true
54+
},
55+
interceptors: {
56+
description: 'Optional interceptors for this specific GraphQL config',
57+
type: "Interceptors<'graphql'>",
58+
typeDescriptionLink: './Interceptors'
59+
}
60+
}}
61+
/>
62+
63+
<a id='GraphQLRouteConfig'></a>
64+
## GraphQLRouteConfig
65+
66+
There are 2 ways to specify a GraphQL route:
67+
68+
You can pass a `queue` field with an array of timed responses (for polling/queues):
69+
70+
<TypeTable
71+
type={{
72+
settings: {
73+
description: 'Optional response settings (delay, polling, status)',
74+
type: 'GraphQLSettings & { polling: true }',
75+
typeDescriptionLink: '#GraphQLSettings'
76+
},
77+
queue: {
78+
description: 'Sequence of timed responses (for polling/queues)',
79+
type: 'Array<{ time?: number; data: GraphqlDataResponse }>',
80+
required: true
81+
},
82+
entities: {
83+
description: 'Optional request entities mapping (cookies, headers, query, variables)',
84+
type: 'GraphQLEntitiesByEntityName',
85+
typeDescriptionLink: '#GraphQLEntitiesByEntityName'
86+
},
87+
interceptors: {
88+
description: 'Optional interceptors applied to GraphQL routes',
89+
type: "Interceptors<'graphql'>",
90+
typeDescriptionLink: './Interceptors'
91+
}
92+
}}
93+
/>
94+
95+
Or you can specify a single response with the `data` field:
96+
97+
<TypeTable
98+
type={{
99+
settings: {
100+
description: 'Optional response settings (delay, polling, status)',
101+
type: 'GraphQLSettings & { polling?: false }',
102+
typeDescriptionLink: '#GraphQLSettings'
103+
},
104+
data: {
105+
description: 'Static or dynamic response data (function or value)',
106+
type: 'GraphqlDataResponse',
107+
typeDescriptionLink: '#GraphqlDataResponse',
108+
required: true
109+
},
110+
entities: {
111+
description: 'Optional request entities mapping (cookies, headers, query, variables)',
112+
type: 'GraphQLEntitiesByEntityName',
113+
typeDescriptionLink: '#GraphQLEntitiesByEntityName'
114+
},
115+
interceptors: {
116+
description: 'Optional interceptors applied to GraphQL routes',
117+
type: "Interceptors<'graphql'>",
118+
typeDescriptionLink: './Interceptors'
119+
}
120+
}}
121+
/>
122+
123+
<a id='GraphqlDataResponse'></a>
124+
## GraphqlDataResponse
125+
126+
<TypeTable
127+
type={{
128+
GraphqlDataResponse: {
129+
description: 'Either a static Data value or a function producing Data (sync or async)',
130+
type: 'Data | (request: Request, entities: GraphQLEntitiesByEntityName) => Data | Promise<Data>'
131+
}
132+
}}
133+
/>
134+
135+
<a id='GraphQLSettings'></a>
136+
## GraphQLSettings
137+
138+
<TypeTable
139+
type={{
140+
delay: {
141+
description: 'Optional artificial delay (ms) applied to this response',
142+
type: 'number'
143+
},
144+
polling: {
145+
description: 'Whether this route is polling (returns queued responses)',
146+
type: 'boolean'
147+
},
148+
status: {
149+
description: 'Optional HTTP status code for the response',
150+
type: 'number'
151+
}
152+
}}
153+
/>
154+
155+
<a id='GraphQLOperationType'></a>
156+
## GraphQLOperationType
157+
158+
Operation types supported by GraphQL configs
159+
160+
```typescript
161+
type GraphQLOperationType = 'mutation' | 'query';
162+
```
163+
164+
<a id='GraphQLOperationName'></a>
165+
## GraphQLOperationName
166+
167+
Operation name
168+
169+
```typescript
170+
type GraphQLOperationName = string | RegExp;
171+
```
172+
173+
<a id='GraphQLEntitiesByEntityName'></a>
174+
## GraphQLEntitiesByEntityName
175+
176+
```typescript
177+
Record<'cookies' | 'headers' | 'query' | 'variables', GraphQLEntity>;
178+
```

0 commit comments

Comments
 (0)