vite-plugin-mock-dev-server 1.8.7 → 1.9.1
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/dist-CAA1v47s.js +204 -0
- package/dist/dist-DrfpZ4UT.cjs +323 -0
- package/dist/{helper-PQrLL5uH.cjs → helper-CCVedLL0.cjs} +10 -11
- package/dist/{helper-L9yYYkP2.js → helper-DhHU-YoO.js} +4 -3
- package/dist/{helper-Di4IZQHq.d.cts → helper-iVHsUTZ6.d.cts} +4 -45
- package/dist/{helper-6T1vILP_.d.ts → helper-r_bW1AY8.d.ts} +5 -46
- package/dist/helper.cjs +6 -5
- package/dist/helper.d.cts +2 -2
- package/dist/helper.d.ts +2 -2
- package/dist/helper.js +2 -1
- package/dist/index.cjs +50 -49
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +13 -10
- package/dist/{server-CAGUKvhH.d.cts → server-B5Ua2cmP.d.cts} +1 -7
- package/dist/{server-03xFMgug.cjs → server-BwOfV_62.cjs} +69 -62
- package/dist/{server-C258ATX8.js → server-C-u7jwot.js} +19 -10
- package/dist/{server-CXqFaG_J.d.ts → server-DgmHgcvl.d.ts} +2 -8
- package/dist/server.cjs +9 -8
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -1
- package/dist/{types-BdGI944Z.d.cts → types-BbbTJG0b.d.ts} +8 -11
- package/dist/{types-CxzZg47I.d.ts → types-DpbHkRjL.d.cts} +8 -11
- package/package.json +6 -6
- package/dist/chunk-BCwAaXi7.cjs +0 -31
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
//#region ../node_modules/.pnpm/@pengzhanbo+utils@2.1.0/node_modules/@pengzhanbo/utils/dist/index.mjs
|
|
2
|
+
function toString(s) {
|
|
3
|
+
return Object.prototype.toString.call(s);
|
|
4
|
+
}
|
|
5
|
+
function getTypeName(s) {
|
|
6
|
+
return s === null ? "null" : typeof s === "object" || typeof s === "function" ? toString(s).slice(8, -1).toLowerCase() : typeof s;
|
|
7
|
+
}
|
|
8
|
+
function isPrimitive(v) {
|
|
9
|
+
return v === null || typeof v !== "object" && typeof v !== "function";
|
|
10
|
+
}
|
|
11
|
+
function isBoolean(v) {
|
|
12
|
+
return typeof v === "boolean";
|
|
13
|
+
}
|
|
14
|
+
function isFunction(v) {
|
|
15
|
+
return typeof v === "function";
|
|
16
|
+
}
|
|
17
|
+
function isString(v) {
|
|
18
|
+
return typeof v === "string";
|
|
19
|
+
}
|
|
20
|
+
function isPlainObject(v) {
|
|
21
|
+
return getTypeName(v) === "object";
|
|
22
|
+
}
|
|
23
|
+
function isArray(v) {
|
|
24
|
+
return Array.isArray(v);
|
|
25
|
+
}
|
|
26
|
+
function isEmptyObject(v) {
|
|
27
|
+
if (!isPlainObject(v)) return false;
|
|
28
|
+
for (const _ in v) return false;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
function isTypedArray(v) {
|
|
32
|
+
return ArrayBuffer.isView(v) && !(v instanceof DataView);
|
|
33
|
+
}
|
|
34
|
+
function toArray(v) {
|
|
35
|
+
if (v === null || v === void 0) return [];
|
|
36
|
+
if (isArray(v)) return v;
|
|
37
|
+
return [v];
|
|
38
|
+
}
|
|
39
|
+
function uniq(v) {
|
|
40
|
+
return Array.from(new Set(v));
|
|
41
|
+
}
|
|
42
|
+
function sortBy(array, cb) {
|
|
43
|
+
if (array.length === 0) return [];
|
|
44
|
+
return array.sort((a, b) => {
|
|
45
|
+
const s1 = cb(a);
|
|
46
|
+
const s2 = cb(b);
|
|
47
|
+
return s1 > s2 ? 1 : s2 > s1 ? -1 : 0;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function hasOwn(obj, key) {
|
|
51
|
+
return obj === null ? false : Object.prototype.hasOwnProperty.call(obj, key);
|
|
52
|
+
}
|
|
53
|
+
function deepCloneImpl(valueToClone, objectToClone, stack = /* @__PURE__ */ new Map()) {
|
|
54
|
+
if (isPrimitive(valueToClone)) return valueToClone;
|
|
55
|
+
/* istanbul ignore if -- @preserve */
|
|
56
|
+
if (stack.has(valueToClone)) return stack.get(valueToClone);
|
|
57
|
+
if (Array.isArray(valueToClone)) {
|
|
58
|
+
const result = Array.from({ length: valueToClone.length });
|
|
59
|
+
stack.set(valueToClone, result);
|
|
60
|
+
for (let i = 0; i < valueToClone.length; i++) result[i] = deepCloneImpl(valueToClone[i], objectToClone, stack);
|
|
61
|
+
if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index;
|
|
62
|
+
if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
if (valueToClone instanceof Date) return new Date(valueToClone.getTime());
|
|
66
|
+
if (valueToClone instanceof RegExp) {
|
|
67
|
+
const result = new RegExp(valueToClone.source, valueToClone.flags);
|
|
68
|
+
result.lastIndex = valueToClone.lastIndex;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
if (valueToClone instanceof Map) {
|
|
72
|
+
const result = /* @__PURE__ */ new Map();
|
|
73
|
+
stack.set(valueToClone, result);
|
|
74
|
+
for (const [key, value] of valueToClone) result.set(key, deepCloneImpl(value, objectToClone, stack));
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
if (valueToClone instanceof Set) {
|
|
78
|
+
const result = /* @__PURE__ */ new Set();
|
|
79
|
+
stack.set(valueToClone, result);
|
|
80
|
+
for (const value of valueToClone) result.add(deepCloneImpl(value, objectToClone, stack));
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(valueToClone)) return valueToClone.subarray();
|
|
84
|
+
if (isTypedArray(valueToClone)) {
|
|
85
|
+
const result = new (Object.getPrototypeOf(valueToClone)).constructor(valueToClone.length);
|
|
86
|
+
stack.set(valueToClone, result);
|
|
87
|
+
for (let i = 0; i < valueToClone.length; i++) result[i] = deepCloneImpl(valueToClone[i], objectToClone, stack);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
if (valueToClone instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && valueToClone instanceof SharedArrayBuffer) return valueToClone.slice(0);
|
|
91
|
+
if (valueToClone instanceof DataView) {
|
|
92
|
+
const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
|
|
93
|
+
stack.set(valueToClone, result);
|
|
94
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
if (typeof File !== "undefined" && valueToClone instanceof File) {
|
|
98
|
+
const result = new File([valueToClone], valueToClone.name, { type: valueToClone.type });
|
|
99
|
+
stack.set(valueToClone, result);
|
|
100
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
if (valueToClone instanceof Blob) {
|
|
104
|
+
const result = new Blob([valueToClone], { type: valueToClone.type });
|
|
105
|
+
stack.set(valueToClone, result);
|
|
106
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
if (valueToClone instanceof Error) {
|
|
110
|
+
const result = new valueToClone.constructor(valueToClone.message, { cause: valueToClone.cause });
|
|
111
|
+
stack.set(valueToClone, result);
|
|
112
|
+
if (hasOwn(valueToClone, "name")) result.name = valueToClone.name;
|
|
113
|
+
result.stack = valueToClone.stack;
|
|
114
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
/* istanbul ignore if -- @preserve */
|
|
118
|
+
if (typeof valueToClone === "object" && valueToClone !== null) {
|
|
119
|
+
const result = Object.create(Object.getPrototypeOf(valueToClone));
|
|
120
|
+
stack.set(valueToClone, result);
|
|
121
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/* istanbul ignore next -- @preserve */
|
|
125
|
+
return valueToClone;
|
|
126
|
+
}
|
|
127
|
+
function copyProperties(target, source, objectToClone = target, stack) {
|
|
128
|
+
const keys = [...Object.keys(source), ...getSymbols(source)];
|
|
129
|
+
for (let i = 0; i < keys.length; i++) {
|
|
130
|
+
const key = keys[i];
|
|
131
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
132
|
+
if (descriptor == null || descriptor.writable) target[key] = deepCloneImpl(source[key], objectToClone, stack);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getSymbols(object) {
|
|
136
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
137
|
+
}
|
|
138
|
+
function deepClone(source) {
|
|
139
|
+
return deepCloneImpl(source, source, /* @__PURE__ */ new Map());
|
|
140
|
+
}
|
|
141
|
+
function deepEqual(v1, v2) {
|
|
142
|
+
const type1 = getTypeName(v1);
|
|
143
|
+
const type2 = getTypeName(v2);
|
|
144
|
+
if (type1 !== type2) return false;
|
|
145
|
+
if (type1 === "array") {
|
|
146
|
+
if (v1.length !== v2.length) return false;
|
|
147
|
+
return v1.every((item, index) => deepEqual(item, v2[index]));
|
|
148
|
+
}
|
|
149
|
+
if (type1 === "object") {
|
|
150
|
+
const keys1 = Object.keys(v1);
|
|
151
|
+
if (keys1.length !== Object.keys(v2).length) return false;
|
|
152
|
+
return keys1.every((key) => deepEqual(v1[key], v2[key]));
|
|
153
|
+
}
|
|
154
|
+
return Object.is(v1, v2);
|
|
155
|
+
}
|
|
156
|
+
function random(...args) {
|
|
157
|
+
let min, max, float;
|
|
158
|
+
if (args.length === 1) {
|
|
159
|
+
min = 0;
|
|
160
|
+
max = args[0];
|
|
161
|
+
float = false;
|
|
162
|
+
} else if (typeof args[1] === "number") {
|
|
163
|
+
min = args[0];
|
|
164
|
+
max = args[1];
|
|
165
|
+
float = !!args[2];
|
|
166
|
+
} else {
|
|
167
|
+
min = 0;
|
|
168
|
+
max = args[0];
|
|
169
|
+
float = !!args[1];
|
|
170
|
+
}
|
|
171
|
+
const num = Math.random() * (max - min) + min;
|
|
172
|
+
return float ? num : Math.floor(num);
|
|
173
|
+
}
|
|
174
|
+
async function sleep(ms, callback) {
|
|
175
|
+
return new Promise((resolve) => setTimeout(async () => {
|
|
176
|
+
await callback?.();
|
|
177
|
+
resolve();
|
|
178
|
+
}, ms));
|
|
179
|
+
}
|
|
180
|
+
function promiseParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
181
|
+
promises = Array.from(promises);
|
|
182
|
+
let current = 0;
|
|
183
|
+
const result = [];
|
|
184
|
+
let resolvedCount = 0;
|
|
185
|
+
const len = promises.length;
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
function next() {
|
|
188
|
+
const index = current++;
|
|
189
|
+
const promise = promises[index];
|
|
190
|
+
Promise.resolve(isFunction(promise) ? promise() : promise).then((res) => {
|
|
191
|
+
result[index] = res;
|
|
192
|
+
if (++resolvedCount === len) resolve(result);
|
|
193
|
+
if (current < len) next();
|
|
194
|
+
}).catch((reason) => reject(reason));
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < concurrency && i < len; i++) next();
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function timestamp() {
|
|
200
|
+
return +Date.now();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
export { deepClone, deepEqual, isArray, isBoolean, isEmptyObject, isFunction, isPlainObject, isString, promiseParallel, random, sleep, sortBy, timestamp, toArray, uniq };
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
//#region ../node_modules/.pnpm/@pengzhanbo+utils@2.1.0/node_modules/@pengzhanbo/utils/dist/index.mjs
|
|
26
|
+
function toString(s) {
|
|
27
|
+
return Object.prototype.toString.call(s);
|
|
28
|
+
}
|
|
29
|
+
function getTypeName(s) {
|
|
30
|
+
return s === null ? "null" : typeof s === "object" || typeof s === "function" ? toString(s).slice(8, -1).toLowerCase() : typeof s;
|
|
31
|
+
}
|
|
32
|
+
function isPrimitive(v) {
|
|
33
|
+
return v === null || typeof v !== "object" && typeof v !== "function";
|
|
34
|
+
}
|
|
35
|
+
function isBoolean(v) {
|
|
36
|
+
return typeof v === "boolean";
|
|
37
|
+
}
|
|
38
|
+
function isFunction(v) {
|
|
39
|
+
return typeof v === "function";
|
|
40
|
+
}
|
|
41
|
+
function isString(v) {
|
|
42
|
+
return typeof v === "string";
|
|
43
|
+
}
|
|
44
|
+
function isPlainObject(v) {
|
|
45
|
+
return getTypeName(v) === "object";
|
|
46
|
+
}
|
|
47
|
+
function isArray(v) {
|
|
48
|
+
return Array.isArray(v);
|
|
49
|
+
}
|
|
50
|
+
function isEmptyObject(v) {
|
|
51
|
+
if (!isPlainObject(v)) return false;
|
|
52
|
+
for (const _ in v) return false;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function isTypedArray(v) {
|
|
56
|
+
return ArrayBuffer.isView(v) && !(v instanceof DataView);
|
|
57
|
+
}
|
|
58
|
+
function toArray(v) {
|
|
59
|
+
if (v === null || v === void 0) return [];
|
|
60
|
+
if (isArray(v)) return v;
|
|
61
|
+
return [v];
|
|
62
|
+
}
|
|
63
|
+
function uniq(v) {
|
|
64
|
+
return Array.from(new Set(v));
|
|
65
|
+
}
|
|
66
|
+
function sortBy(array, cb) {
|
|
67
|
+
if (array.length === 0) return [];
|
|
68
|
+
return array.sort((a, b) => {
|
|
69
|
+
const s1 = cb(a);
|
|
70
|
+
const s2 = cb(b);
|
|
71
|
+
return s1 > s2 ? 1 : s2 > s1 ? -1 : 0;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function hasOwn(obj, key) {
|
|
75
|
+
return obj === null ? false : Object.prototype.hasOwnProperty.call(obj, key);
|
|
76
|
+
}
|
|
77
|
+
function deepCloneImpl(valueToClone, objectToClone, stack = /* @__PURE__ */ new Map()) {
|
|
78
|
+
if (isPrimitive(valueToClone)) return valueToClone;
|
|
79
|
+
/* istanbul ignore if -- @preserve */
|
|
80
|
+
if (stack.has(valueToClone)) return stack.get(valueToClone);
|
|
81
|
+
if (Array.isArray(valueToClone)) {
|
|
82
|
+
const result = Array.from({ length: valueToClone.length });
|
|
83
|
+
stack.set(valueToClone, result);
|
|
84
|
+
for (let i = 0; i < valueToClone.length; i++) result[i] = deepCloneImpl(valueToClone[i], objectToClone, stack);
|
|
85
|
+
if (Object.hasOwn(valueToClone, "index")) result.index = valueToClone.index;
|
|
86
|
+
if (Object.hasOwn(valueToClone, "input")) result.input = valueToClone.input;
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
if (valueToClone instanceof Date) return new Date(valueToClone.getTime());
|
|
90
|
+
if (valueToClone instanceof RegExp) {
|
|
91
|
+
const result = new RegExp(valueToClone.source, valueToClone.flags);
|
|
92
|
+
result.lastIndex = valueToClone.lastIndex;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
if (valueToClone instanceof Map) {
|
|
96
|
+
const result = /* @__PURE__ */ new Map();
|
|
97
|
+
stack.set(valueToClone, result);
|
|
98
|
+
for (const [key, value] of valueToClone) result.set(key, deepCloneImpl(value, objectToClone, stack));
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
if (valueToClone instanceof Set) {
|
|
102
|
+
const result = /* @__PURE__ */ new Set();
|
|
103
|
+
stack.set(valueToClone, result);
|
|
104
|
+
for (const value of valueToClone) result.add(deepCloneImpl(value, objectToClone, stack));
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(valueToClone)) return valueToClone.subarray();
|
|
108
|
+
if (isTypedArray(valueToClone)) {
|
|
109
|
+
const result = new (Object.getPrototypeOf(valueToClone)).constructor(valueToClone.length);
|
|
110
|
+
stack.set(valueToClone, result);
|
|
111
|
+
for (let i = 0; i < valueToClone.length; i++) result[i] = deepCloneImpl(valueToClone[i], objectToClone, stack);
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
if (valueToClone instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && valueToClone instanceof SharedArrayBuffer) return valueToClone.slice(0);
|
|
115
|
+
if (valueToClone instanceof DataView) {
|
|
116
|
+
const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
|
|
117
|
+
stack.set(valueToClone, result);
|
|
118
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
if (typeof File !== "undefined" && valueToClone instanceof File) {
|
|
122
|
+
const result = new File([valueToClone], valueToClone.name, { type: valueToClone.type });
|
|
123
|
+
stack.set(valueToClone, result);
|
|
124
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
if (valueToClone instanceof Blob) {
|
|
128
|
+
const result = new Blob([valueToClone], { type: valueToClone.type });
|
|
129
|
+
stack.set(valueToClone, result);
|
|
130
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
if (valueToClone instanceof Error) {
|
|
134
|
+
const result = new valueToClone.constructor(valueToClone.message, { cause: valueToClone.cause });
|
|
135
|
+
stack.set(valueToClone, result);
|
|
136
|
+
if (hasOwn(valueToClone, "name")) result.name = valueToClone.name;
|
|
137
|
+
result.stack = valueToClone.stack;
|
|
138
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
/* istanbul ignore if -- @preserve */
|
|
142
|
+
if (typeof valueToClone === "object" && valueToClone !== null) {
|
|
143
|
+
const result = Object.create(Object.getPrototypeOf(valueToClone));
|
|
144
|
+
stack.set(valueToClone, result);
|
|
145
|
+
copyProperties(result, valueToClone, objectToClone, stack);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
/* istanbul ignore next -- @preserve */
|
|
149
|
+
return valueToClone;
|
|
150
|
+
}
|
|
151
|
+
function copyProperties(target, source, objectToClone = target, stack) {
|
|
152
|
+
const keys = [...Object.keys(source), ...getSymbols(source)];
|
|
153
|
+
for (let i = 0; i < keys.length; i++) {
|
|
154
|
+
const key = keys[i];
|
|
155
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
156
|
+
if (descriptor == null || descriptor.writable) target[key] = deepCloneImpl(source[key], objectToClone, stack);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function getSymbols(object) {
|
|
160
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
161
|
+
}
|
|
162
|
+
function deepClone(source) {
|
|
163
|
+
return deepCloneImpl(source, source, /* @__PURE__ */ new Map());
|
|
164
|
+
}
|
|
165
|
+
function deepEqual(v1, v2) {
|
|
166
|
+
const type1 = getTypeName(v1);
|
|
167
|
+
const type2 = getTypeName(v2);
|
|
168
|
+
if (type1 !== type2) return false;
|
|
169
|
+
if (type1 === "array") {
|
|
170
|
+
if (v1.length !== v2.length) return false;
|
|
171
|
+
return v1.every((item, index) => deepEqual(item, v2[index]));
|
|
172
|
+
}
|
|
173
|
+
if (type1 === "object") {
|
|
174
|
+
const keys1 = Object.keys(v1);
|
|
175
|
+
if (keys1.length !== Object.keys(v2).length) return false;
|
|
176
|
+
return keys1.every((key) => deepEqual(v1[key], v2[key]));
|
|
177
|
+
}
|
|
178
|
+
return Object.is(v1, v2);
|
|
179
|
+
}
|
|
180
|
+
function random(...args) {
|
|
181
|
+
let min, max, float;
|
|
182
|
+
if (args.length === 1) {
|
|
183
|
+
min = 0;
|
|
184
|
+
max = args[0];
|
|
185
|
+
float = false;
|
|
186
|
+
} else if (typeof args[1] === "number") {
|
|
187
|
+
min = args[0];
|
|
188
|
+
max = args[1];
|
|
189
|
+
float = !!args[2];
|
|
190
|
+
} else {
|
|
191
|
+
min = 0;
|
|
192
|
+
max = args[0];
|
|
193
|
+
float = !!args[1];
|
|
194
|
+
}
|
|
195
|
+
const num = Math.random() * (max - min) + min;
|
|
196
|
+
return float ? num : Math.floor(num);
|
|
197
|
+
}
|
|
198
|
+
async function sleep(ms, callback) {
|
|
199
|
+
return new Promise((resolve) => setTimeout(async () => {
|
|
200
|
+
await callback?.();
|
|
201
|
+
resolve();
|
|
202
|
+
}, ms));
|
|
203
|
+
}
|
|
204
|
+
function promiseParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
205
|
+
promises = Array.from(promises);
|
|
206
|
+
let current = 0;
|
|
207
|
+
const result = [];
|
|
208
|
+
let resolvedCount = 0;
|
|
209
|
+
const len = promises.length;
|
|
210
|
+
return new Promise((resolve, reject) => {
|
|
211
|
+
function next() {
|
|
212
|
+
const index = current++;
|
|
213
|
+
const promise = promises[index];
|
|
214
|
+
Promise.resolve(isFunction(promise) ? promise() : promise).then((res) => {
|
|
215
|
+
result[index] = res;
|
|
216
|
+
if (++resolvedCount === len) resolve(result);
|
|
217
|
+
if (current < len) next();
|
|
218
|
+
}).catch((reason) => reject(reason));
|
|
219
|
+
}
|
|
220
|
+
for (let i = 0; i < concurrency && i < len; i++) next();
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function timestamp() {
|
|
224
|
+
return +Date.now();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//#endregion
|
|
228
|
+
Object.defineProperty(exports, '__toESM', {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function () {
|
|
231
|
+
return __toESM;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(exports, 'deepClone', {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function () {
|
|
237
|
+
return deepClone;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, 'deepEqual', {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function () {
|
|
243
|
+
return deepEqual;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(exports, 'isArray', {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function () {
|
|
249
|
+
return isArray;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
Object.defineProperty(exports, 'isBoolean', {
|
|
253
|
+
enumerable: true,
|
|
254
|
+
get: function () {
|
|
255
|
+
return isBoolean;
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(exports, 'isEmptyObject', {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function () {
|
|
261
|
+
return isEmptyObject;
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
Object.defineProperty(exports, 'isFunction', {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
get: function () {
|
|
267
|
+
return isFunction;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
Object.defineProperty(exports, 'isPlainObject', {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function () {
|
|
273
|
+
return isPlainObject;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(exports, 'isString', {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function () {
|
|
279
|
+
return isString;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, 'promiseParallel', {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function () {
|
|
285
|
+
return promiseParallel;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, 'random', {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function () {
|
|
291
|
+
return random;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
Object.defineProperty(exports, 'sleep', {
|
|
295
|
+
enumerable: true,
|
|
296
|
+
get: function () {
|
|
297
|
+
return sleep;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
Object.defineProperty(exports, 'sortBy', {
|
|
301
|
+
enumerable: true,
|
|
302
|
+
get: function () {
|
|
303
|
+
return sortBy;
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
Object.defineProperty(exports, 'timestamp', {
|
|
307
|
+
enumerable: true,
|
|
308
|
+
get: function () {
|
|
309
|
+
return timestamp;
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
Object.defineProperty(exports, 'toArray', {
|
|
313
|
+
enumerable: true,
|
|
314
|
+
get: function () {
|
|
315
|
+
return toArray;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
Object.defineProperty(exports, 'uniq', {
|
|
319
|
+
enumerable: true,
|
|
320
|
+
get: function () {
|
|
321
|
+
return uniq;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const __pengzhanbo_utils = require_chunk.__toESM(require("@pengzhanbo/utils"));
|
|
4
|
-
const node_stream = require_chunk.__toESM(require("node:stream"));
|
|
1
|
+
const require_dist = require('./dist-DrfpZ4UT.cjs');
|
|
2
|
+
const node_stream = require_dist.__toESM(require("node:stream"));
|
|
5
3
|
|
|
6
4
|
//#region src/core/defineMock.ts
|
|
7
5
|
function defineMock(config) {
|
|
@@ -25,7 +23,7 @@ function defineMock(config) {
|
|
|
25
23
|
*/
|
|
26
24
|
function createDefineMock(transformer) {
|
|
27
25
|
const define = (config) => {
|
|
28
|
-
if (
|
|
26
|
+
if (require_dist.isArray(config)) config = config.map((item) => transformer(item) || item);
|
|
29
27
|
else config = transformer(config) || config;
|
|
30
28
|
return config;
|
|
31
29
|
};
|
|
@@ -34,22 +32,23 @@ function createDefineMock(transformer) {
|
|
|
34
32
|
|
|
35
33
|
//#endregion
|
|
36
34
|
//#region src/core/defineMockData.ts
|
|
37
|
-
const mockDataCache = new Map();
|
|
38
|
-
const responseCache = new WeakMap();
|
|
35
|
+
const mockDataCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const responseCache = /* @__PURE__ */ new WeakMap();
|
|
39
37
|
const staleInterval = 70;
|
|
40
38
|
var CacheImpl = class {
|
|
39
|
+
value;
|
|
41
40
|
#initialValue;
|
|
42
41
|
#lastUpdate;
|
|
43
42
|
constructor(value) {
|
|
44
43
|
this.value = value;
|
|
45
|
-
this.#initialValue =
|
|
44
|
+
this.#initialValue = require_dist.deepClone(value);
|
|
46
45
|
this.#lastUpdate = Date.now();
|
|
47
46
|
}
|
|
48
47
|
hotUpdate(value) {
|
|
49
48
|
if (Date.now() - this.#lastUpdate < staleInterval) return;
|
|
50
|
-
if (!
|
|
49
|
+
if (!require_dist.deepEqual(value, this.#initialValue)) {
|
|
51
50
|
this.value = value;
|
|
52
|
-
this.#initialValue =
|
|
51
|
+
this.#initialValue = require_dist.deepClone(value);
|
|
53
52
|
this.#lastUpdate = Date.now();
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -60,7 +59,7 @@ function defineMockData(key, initialData) {
|
|
|
60
59
|
cache.hotUpdate(initialData);
|
|
61
60
|
if (responseCache.has(cache)) return responseCache.get(cache);
|
|
62
61
|
const res = [() => cache.value, (val) => {
|
|
63
|
-
if (
|
|
62
|
+
if (require_dist.isFunction(val)) val = val(cache.value) ?? cache.value;
|
|
64
63
|
cache.value = val;
|
|
65
64
|
}];
|
|
66
65
|
Object.defineProperty(res, "value", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepClone, deepEqual, isArray, isFunction } from "
|
|
1
|
+
import { deepClone, deepEqual, isArray, isFunction } from "./dist-CAA1v47s.js";
|
|
2
2
|
import { Transform } from "node:stream";
|
|
3
3
|
|
|
4
4
|
//#region src/core/defineMock.ts
|
|
@@ -32,10 +32,11 @@ function createDefineMock(transformer) {
|
|
|
32
32
|
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/core/defineMockData.ts
|
|
35
|
-
const mockDataCache = new Map();
|
|
36
|
-
const responseCache = new WeakMap();
|
|
35
|
+
const mockDataCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const responseCache = /* @__PURE__ */ new WeakMap();
|
|
37
37
|
const staleInterval = 70;
|
|
38
38
|
var CacheImpl = class {
|
|
39
|
+
value;
|
|
39
40
|
#initialValue;
|
|
40
41
|
#lastUpdate;
|
|
41
42
|
constructor(value) {
|
|
@@ -1,54 +1,16 @@
|
|
|
1
|
-
import { MockHttpItem, MockOptions, MockWebsocketItem } from "./types-
|
|
1
|
+
import { MockHttpItem, MockOptions, MockWebsocketItem } from "./types-DpbHkRjL.cjs";
|
|
2
2
|
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "node:http";
|
|
3
3
|
import { Transform } from "node:stream";
|
|
4
4
|
|
|
5
5
|
//#region src/core/defineMock.d.ts
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* mock config Type helper
|
|
8
9
|
*
|
|
9
10
|
* mock配置 类型帮助函数
|
|
10
11
|
* @param config see config docs:
|
|
11
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/
|
|
12
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config zh-CN DOC}
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* Mock Http Request
|
|
16
|
-
* ```ts
|
|
17
|
-
* export default defineMock({
|
|
18
|
-
* url: '/api/example',
|
|
19
|
-
* method: ['GET', 'POST'],
|
|
20
|
-
* body: { a: 1 },
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
* ```ts
|
|
24
|
-
* export default defineMock({
|
|
25
|
-
* url: '/api/example',
|
|
26
|
-
* method: 'GET',
|
|
27
|
-
* body: ({ query }) => ({ a: 1, b: query.b }),
|
|
28
|
-
* })
|
|
29
|
-
* ```
|
|
30
|
-
* @example
|
|
31
|
-
* Mock WebSocket
|
|
32
|
-
* ```ts
|
|
33
|
-
* export default defineMock({
|
|
34
|
-
* url: '/socket.io',
|
|
35
|
-
* ws: true,
|
|
36
|
-
* setup(wss) {
|
|
37
|
-
* wss.on('connection', (ws) => {
|
|
38
|
-
* ws.on('message', (rawData) => console.log(rawData))
|
|
39
|
-
* ws.send('data')
|
|
40
|
-
* })
|
|
41
|
-
* },
|
|
42
|
-
* })
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* mock config Type helper
|
|
47
|
-
*
|
|
48
|
-
* mock配置 类型帮助函数
|
|
49
|
-
* @param config see config docs:
|
|
50
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/en/guide/mock-config en-US DOC} |
|
|
51
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config zh-CN DOC}
|
|
12
|
+
* {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config en-US DOC} |
|
|
13
|
+
* {@link https://vite-plugin-mock-dev-server.netlify.app/zh/guide/mock-config zh-CN DOC}
|
|
52
14
|
*
|
|
53
15
|
* @example
|
|
54
16
|
* Mock Http Request
|
|
@@ -101,14 +63,12 @@ declare function defineMock(config: MockOptions): MockOptions;
|
|
|
101
63
|
* ```
|
|
102
64
|
*/
|
|
103
65
|
declare function createDefineMock(transformer: (mock: MockHttpItem | MockWebsocketItem) => MockHttpItem | MockWebsocketItem | void): typeof defineMock;
|
|
104
|
-
|
|
105
66
|
//#endregion
|
|
106
67
|
//#region src/core/defineMockData.d.ts
|
|
107
68
|
type MockData<T = any> = readonly [() => T, (val: T | ((val: T) => T | void)) => void] & {
|
|
108
69
|
value: T;
|
|
109
70
|
};
|
|
110
71
|
declare function defineMockData<T = any>(key: string, initialData: T): MockData<T>;
|
|
111
|
-
|
|
112
72
|
//#endregion
|
|
113
73
|
//#region src/core/sse.d.ts
|
|
114
74
|
interface SSEMessage {
|
|
@@ -146,6 +106,5 @@ declare class SSEStream extends Transform {
|
|
|
146
106
|
write(message: SSEMessage, cb?: (error: Error | null | undefined) => void): boolean;
|
|
147
107
|
}
|
|
148
108
|
declare function createSSEStream(req: IncomingMessage, res: ServerResponse): SSEStream;
|
|
149
|
-
|
|
150
109
|
//#endregion
|
|
151
110
|
export { HeaderStream, MockData, SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData };
|