vite-plugin-mock-dev-server 1.8.4 → 1.8.6

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/dist/helper.d.cts CHANGED
@@ -1,123 +1,3 @@
1
- import { a as MockHttpItem, d as MockWebsocketItem, b as MockOptions } from './types-BYspd62h.cjs';
2
- export { c as MockRequest } from './types-BYspd62h.cjs';
3
- import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
4
- import { Transform } from 'node:stream';
5
- import 'co-body';
6
- import 'cookies';
7
- import 'cors';
8
- import 'formidable';
9
- import 'node:buffer';
10
- import 'vite';
11
- import 'ws';
12
-
13
- /**
14
- * mock config Type helper
15
- *
16
- * mock配置 类型帮助函数
17
- * @param config see config docs:
18
- * {@link https://vite-plugin-mock-dev-server.netlify.app/en/guide/mock-config en-US DOC} |
19
- * {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config zh-CN DOC}
20
- *
21
- * @example
22
- * Mock Http Request
23
- * ```ts
24
- * export default defineMock({
25
- * url: '/api/example',
26
- * method: ['GET', 'POST'],
27
- * body: { a: 1 },
28
- * })
29
- * ```
30
- * ```ts
31
- * export default defineMock({
32
- * url: '/api/example',
33
- * method: 'GET',
34
- * body: ({ query }) => ({ a: 1, b: query.b }),
35
- * })
36
- * ```
37
- * @example
38
- * Mock WebSocket
39
- * ```ts
40
- * export default defineMock({
41
- * url: '/socket.io',
42
- * ws: true,
43
- * setup(wss) {
44
- * wss.on('connection', (ws) => {
45
- * ws.on('message', (rawData) => console.log(rawData))
46
- * ws.send('data')
47
- * })
48
- * },
49
- * })
50
- * ```
51
- */
52
- declare function defineMock(config: MockHttpItem): MockHttpItem;
53
- declare function defineMock(config: MockWebsocketItem): MockWebsocketItem;
54
- declare function defineMock(config: MockOptions): MockOptions;
55
- /**
56
- * Return a custom defineMock function to support preprocessing of mock config.
57
- *
58
- * 返回一个自定义的 defineMock 函数,用于支持对 mock config 的预处理。
59
- * @param transformer preprocessing function
60
- * @example
61
- * ```ts
62
- * const definePostMock = createDefineMock((mock) => {
63
- * mock.url = '/api/post/' + mock.url
64
- * })
65
- * export default definePostMock({
66
- * url: 'list',
67
- * body: [{ title: '1' }, { title: '2' }],
68
- * })
69
- * ```
70
- */
71
- declare function createDefineMock(transformer: (mock: MockHttpItem | MockWebsocketItem) => MockHttpItem | MockWebsocketItem | void): typeof defineMock;
72
-
73
- type MockData<T = any> = readonly [
74
- /**
75
- * getter
76
- */
77
- () => T,
78
- /**
79
- * setter
80
- */
81
- (val: T | ((val: T) => T | void)) => void
82
- ] & {
83
- value: T;
84
- };
85
- declare function defineMockData<T = any>(key: string, initialData: T): MockData<T>;
86
-
87
- interface SSEMessage {
88
- data?: string | object;
89
- comment?: string;
90
- event?: string;
91
- id?: string;
92
- retry?: number;
93
- }
94
- interface WriteHeaders {
95
- writeHead?: (statusCode: number, headers?: OutgoingHttpHeaders) => WriteHeaders;
96
- flushHeaders?: () => void;
97
- }
98
- type HeaderStream = NodeJS.WritableStream & WriteHeaders;
99
- /**
100
- * Transforms "messages" to W3C event stream content.
101
- * See https://html.spec.whatwg.org/multipage/server-sent-events.html
102
- * A message is an object with one or more of the following properties:
103
- * - data (String or object, which gets turned into JSON)
104
- * - event
105
- * - id
106
- * - retry
107
- * - comment
108
- *
109
- * If constructed with a HTTP Request, it will optimise the socket for streaming.
110
- * If this stream is piped to an HTTP Response, it will set appropriate headers.
111
- */
112
- declare class SSEStream extends Transform {
113
- constructor(req: IncomingMessage);
114
- pipe<T extends HeaderStream>(destination: T, options?: {
115
- end?: boolean;
116
- }): T;
117
- _transform(message: SSEMessage, encoding: string, callback: (error?: (Error | null), data?: any) => void): void;
118
- write(message: SSEMessage, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
119
- write(message: SSEMessage, cb?: (error: Error | null | undefined) => void): boolean;
120
- }
121
- declare function createSSEStream(req: IncomingMessage, res: ServerResponse): SSEStream;
122
-
123
- export { type HeaderStream, type MockData, MockHttpItem, MockOptions, MockWebsocketItem, type SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData };
1
+ import { MockHttpItem, MockOptions, MockRequest, MockWebsocketItem } from "./types-BdGI944Z.cjs";
2
+ import { HeaderStream, MockData, SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData } from "./helper-Di4IZQHq.cjs";
3
+ export { HeaderStream, MockData, MockHttpItem, MockOptions, MockRequest, MockWebsocketItem, SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData };
package/dist/helper.d.ts CHANGED
@@ -1,123 +1,3 @@
1
- import { a as MockHttpItem, d as MockWebsocketItem, b as MockOptions } from './types-BYspd62h.js';
2
- export { c as MockRequest } from './types-BYspd62h.js';
3
- import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
4
- import { Transform } from 'node:stream';
5
- import 'co-body';
6
- import 'cookies';
7
- import 'cors';
8
- import 'formidable';
9
- import 'node:buffer';
10
- import 'vite';
11
- import 'ws';
12
-
13
- /**
14
- * mock config Type helper
15
- *
16
- * mock配置 类型帮助函数
17
- * @param config see config docs:
18
- * {@link https://vite-plugin-mock-dev-server.netlify.app/en/guide/mock-config en-US DOC} |
19
- * {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config zh-CN DOC}
20
- *
21
- * @example
22
- * Mock Http Request
23
- * ```ts
24
- * export default defineMock({
25
- * url: '/api/example',
26
- * method: ['GET', 'POST'],
27
- * body: { a: 1 },
28
- * })
29
- * ```
30
- * ```ts
31
- * export default defineMock({
32
- * url: '/api/example',
33
- * method: 'GET',
34
- * body: ({ query }) => ({ a: 1, b: query.b }),
35
- * })
36
- * ```
37
- * @example
38
- * Mock WebSocket
39
- * ```ts
40
- * export default defineMock({
41
- * url: '/socket.io',
42
- * ws: true,
43
- * setup(wss) {
44
- * wss.on('connection', (ws) => {
45
- * ws.on('message', (rawData) => console.log(rawData))
46
- * ws.send('data')
47
- * })
48
- * },
49
- * })
50
- * ```
51
- */
52
- declare function defineMock(config: MockHttpItem): MockHttpItem;
53
- declare function defineMock(config: MockWebsocketItem): MockWebsocketItem;
54
- declare function defineMock(config: MockOptions): MockOptions;
55
- /**
56
- * Return a custom defineMock function to support preprocessing of mock config.
57
- *
58
- * 返回一个自定义的 defineMock 函数,用于支持对 mock config 的预处理。
59
- * @param transformer preprocessing function
60
- * @example
61
- * ```ts
62
- * const definePostMock = createDefineMock((mock) => {
63
- * mock.url = '/api/post/' + mock.url
64
- * })
65
- * export default definePostMock({
66
- * url: 'list',
67
- * body: [{ title: '1' }, { title: '2' }],
68
- * })
69
- * ```
70
- */
71
- declare function createDefineMock(transformer: (mock: MockHttpItem | MockWebsocketItem) => MockHttpItem | MockWebsocketItem | void): typeof defineMock;
72
-
73
- type MockData<T = any> = readonly [
74
- /**
75
- * getter
76
- */
77
- () => T,
78
- /**
79
- * setter
80
- */
81
- (val: T | ((val: T) => T | void)) => void
82
- ] & {
83
- value: T;
84
- };
85
- declare function defineMockData<T = any>(key: string, initialData: T): MockData<T>;
86
-
87
- interface SSEMessage {
88
- data?: string | object;
89
- comment?: string;
90
- event?: string;
91
- id?: string;
92
- retry?: number;
93
- }
94
- interface WriteHeaders {
95
- writeHead?: (statusCode: number, headers?: OutgoingHttpHeaders) => WriteHeaders;
96
- flushHeaders?: () => void;
97
- }
98
- type HeaderStream = NodeJS.WritableStream & WriteHeaders;
99
- /**
100
- * Transforms "messages" to W3C event stream content.
101
- * See https://html.spec.whatwg.org/multipage/server-sent-events.html
102
- * A message is an object with one or more of the following properties:
103
- * - data (String or object, which gets turned into JSON)
104
- * - event
105
- * - id
106
- * - retry
107
- * - comment
108
- *
109
- * If constructed with a HTTP Request, it will optimise the socket for streaming.
110
- * If this stream is piped to an HTTP Response, it will set appropriate headers.
111
- */
112
- declare class SSEStream extends Transform {
113
- constructor(req: IncomingMessage);
114
- pipe<T extends HeaderStream>(destination: T, options?: {
115
- end?: boolean;
116
- }): T;
117
- _transform(message: SSEMessage, encoding: string, callback: (error?: (Error | null), data?: any) => void): void;
118
- write(message: SSEMessage, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
119
- write(message: SSEMessage, cb?: (error: Error | null | undefined) => void): boolean;
120
- }
121
- declare function createSSEStream(req: IncomingMessage, res: ServerResponse): SSEStream;
122
-
123
- export { type HeaderStream, type MockData, MockHttpItem, MockOptions, MockWebsocketItem, type SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData };
1
+ import { MockHttpItem, MockOptions, MockRequest, MockWebsocketItem } from "./types-CxzZg47I.js";
2
+ import { HeaderStream, MockData, SSEMessage, createDefineMock$1 as createDefineMock, createSSEStream$1 as createSSEStream, defineMock$1 as defineMock, defineMockData$1 as defineMockData } from "./helper-6T1vILP_.js";
3
+ export { HeaderStream, MockData, MockHttpItem, MockOptions, MockRequest, MockWebsocketItem, SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData };
package/dist/helper.js CHANGED
@@ -1,12 +1,3 @@
1
- import {
2
- createDefineMock,
3
- createSSEStream,
4
- defineMock,
5
- defineMockData
6
- } from "./chunk-4RQVTS77.js";
7
- export {
8
- createDefineMock,
9
- createSSEStream,
10
- defineMock,
11
- defineMockData
12
- };
1
+ import { createDefineMock, createSSEStream, defineMock, defineMockData } from "./helper-L9yYYkP2.js";
2
+
3
+ export { createDefineMock, createSSEStream, defineMock, defineMockData };