mokup 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.mjs +1 -0
- package/dist/vite.cjs +783 -0
- package/dist/vite.d.cts +10 -0
- package/dist/vite.d.mts +8 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.mjs +776 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ice breaker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# mokup
|
|
2
|
+
|
|
3
|
+
Mock utilities and a Vite plugin for local API mocking.
|
|
4
|
+
|
|
5
|
+
## Vite plugin
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import mokup from 'mokup/vite'
|
|
9
|
+
import { defineConfig } from 'vite'
|
|
10
|
+
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
plugins: [
|
|
13
|
+
mokup({
|
|
14
|
+
dir: 'mock',
|
|
15
|
+
prefix: '',
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Mock files
|
|
22
|
+
|
|
23
|
+
Filenames must include an HTTP method suffix (`.get`, `.post`, etc.).
|
|
24
|
+
|
|
25
|
+
`mock/user.get.json`
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"id": 1,
|
|
30
|
+
"name": "Ada"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`mock/auth.post.ts`
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export default {
|
|
38
|
+
response: ({ body }) => {
|
|
39
|
+
if (body && typeof body === 'object' && 'username' in body) {
|
|
40
|
+
return { ok: true }
|
|
41
|
+
}
|
|
42
|
+
return { ok: false }
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`mock/users/[id].get.ts`
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export default {
|
|
51
|
+
response: ({ params }) => ({ ok: true, id: params?.id }),
|
|
52
|
+
}
|
|
53
|
+
```
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
|
|
3
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
4
|
+
interface MockRequest {
|
|
5
|
+
url: string;
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
headers: IncomingMessage['headers'];
|
|
8
|
+
query: Record<string, string | string[]>;
|
|
9
|
+
body: unknown;
|
|
10
|
+
rawBody?: string;
|
|
11
|
+
params?: Record<string, string | string[]>;
|
|
12
|
+
}
|
|
13
|
+
interface MockContext {
|
|
14
|
+
delay: (ms: number) => Promise<void>;
|
|
15
|
+
json: (data: unknown) => unknown;
|
|
16
|
+
}
|
|
17
|
+
type MockResponseHandler = (req: MockRequest, res: ServerResponse, ctx: MockContext) => unknown | Promise<unknown>;
|
|
18
|
+
type MockResponse = unknown | MockResponseHandler;
|
|
19
|
+
interface MockRule {
|
|
20
|
+
url?: string;
|
|
21
|
+
method?: string;
|
|
22
|
+
response: MockResponse;
|
|
23
|
+
status?: number;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
delay?: number;
|
|
26
|
+
}
|
|
27
|
+
interface MokupViteOptions {
|
|
28
|
+
dir?: string | string[] | ((root: string) => string | string[]);
|
|
29
|
+
prefix?: string;
|
|
30
|
+
include?: RegExp | RegExp[];
|
|
31
|
+
exclude?: RegExp | RegExp[];
|
|
32
|
+
watch?: boolean;
|
|
33
|
+
log?: boolean;
|
|
34
|
+
playground?: boolean | {
|
|
35
|
+
path?: string;
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type { HttpMethod, MockContext, MockRequest, MockResponse, MockResponseHandler, MockRule, MokupViteOptions };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
|
|
3
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
4
|
+
interface MockRequest {
|
|
5
|
+
url: string;
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
headers: IncomingMessage['headers'];
|
|
8
|
+
query: Record<string, string | string[]>;
|
|
9
|
+
body: unknown;
|
|
10
|
+
rawBody?: string;
|
|
11
|
+
params?: Record<string, string | string[]>;
|
|
12
|
+
}
|
|
13
|
+
interface MockContext {
|
|
14
|
+
delay: (ms: number) => Promise<void>;
|
|
15
|
+
json: (data: unknown) => unknown;
|
|
16
|
+
}
|
|
17
|
+
type MockResponseHandler = (req: MockRequest, res: ServerResponse, ctx: MockContext) => unknown | Promise<unknown>;
|
|
18
|
+
type MockResponse = unknown | MockResponseHandler;
|
|
19
|
+
interface MockRule {
|
|
20
|
+
url?: string;
|
|
21
|
+
method?: string;
|
|
22
|
+
response: MockResponse;
|
|
23
|
+
status?: number;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
delay?: number;
|
|
26
|
+
}
|
|
27
|
+
interface MokupViteOptions {
|
|
28
|
+
dir?: string | string[] | ((root: string) => string | string[]);
|
|
29
|
+
prefix?: string;
|
|
30
|
+
include?: RegExp | RegExp[];
|
|
31
|
+
exclude?: RegExp | RegExp[];
|
|
32
|
+
watch?: boolean;
|
|
33
|
+
log?: boolean;
|
|
34
|
+
playground?: boolean | {
|
|
35
|
+
path?: string;
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type { HttpMethod, MockContext, MockRequest, MockResponse, MockResponseHandler, MockRule, MokupViteOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
|
|
3
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
4
|
+
interface MockRequest {
|
|
5
|
+
url: string;
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
headers: IncomingMessage['headers'];
|
|
8
|
+
query: Record<string, string | string[]>;
|
|
9
|
+
body: unknown;
|
|
10
|
+
rawBody?: string;
|
|
11
|
+
params?: Record<string, string | string[]>;
|
|
12
|
+
}
|
|
13
|
+
interface MockContext {
|
|
14
|
+
delay: (ms: number) => Promise<void>;
|
|
15
|
+
json: (data: unknown) => unknown;
|
|
16
|
+
}
|
|
17
|
+
type MockResponseHandler = (req: MockRequest, res: ServerResponse, ctx: MockContext) => unknown | Promise<unknown>;
|
|
18
|
+
type MockResponse = unknown | MockResponseHandler;
|
|
19
|
+
interface MockRule {
|
|
20
|
+
url?: string;
|
|
21
|
+
method?: string;
|
|
22
|
+
response: MockResponse;
|
|
23
|
+
status?: number;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
delay?: number;
|
|
26
|
+
}
|
|
27
|
+
interface MokupViteOptions {
|
|
28
|
+
dir?: string | string[] | ((root: string) => string | string[]);
|
|
29
|
+
prefix?: string;
|
|
30
|
+
include?: RegExp | RegExp[];
|
|
31
|
+
exclude?: RegExp | RegExp[];
|
|
32
|
+
watch?: boolean;
|
|
33
|
+
log?: boolean;
|
|
34
|
+
playground?: boolean | {
|
|
35
|
+
path?: string;
|
|
36
|
+
enabled?: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type { HttpMethod, MockContext, MockRequest, MockResponse, MockResponseHandler, MockRule, MokupViteOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|