vite-plugin-ai-mock-generator 1.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/dist/index.js ADDED
@@ -0,0 +1,663 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
9
+ var path__default = /*#__PURE__*/_interopDefault(path);
10
+
11
+ // src/storage.ts
12
+ var MockStorage = class {
13
+ constructor(options = {}) {
14
+ this.storageDir = options.dir || "mock-data";
15
+ this.persist = options.persist !== false;
16
+ this.cache = /* @__PURE__ */ new Map();
17
+ if (this.persist && !fs__default.default.existsSync(this.storageDir)) {
18
+ fs__default.default.mkdirSync(this.storageDir, { recursive: true });
19
+ }
20
+ this.load();
21
+ }
22
+ /**
23
+ * 生成存储 key
24
+ */
25
+ getKey(endpoint, method) {
26
+ return `${method}:${endpoint}`;
27
+ }
28
+ /**
29
+ * 生成文件名
30
+ */
31
+ getFileName(endpoint, method) {
32
+ const sanitized = endpoint.replace(/^\//, "").replace(/\//g, "_").replace(/:/g, "_");
33
+ return `${method}_${sanitized}.json`;
34
+ }
35
+ /**
36
+ * 获取数据
37
+ */
38
+ get(endpoint, method = "GET") {
39
+ const key = this.getKey(endpoint, method);
40
+ const store = this.cache.get(key);
41
+ return store?.data;
42
+ }
43
+ /**
44
+ * 设置数据
45
+ */
46
+ set(endpoint, method, data, metadata) {
47
+ const key = this.getKey(endpoint, method);
48
+ const store = {
49
+ endpoint,
50
+ method,
51
+ data,
52
+ metadata: {
53
+ count: Array.isArray(data) ? data.length : 1,
54
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
55
+ version: "1.0.0",
56
+ type: typeof data,
57
+ ...metadata
58
+ }
59
+ };
60
+ this.cache.set(key, store);
61
+ if (this.persist) {
62
+ this.save(endpoint, method, store);
63
+ }
64
+ }
65
+ /**
66
+ * 删除数据
67
+ */
68
+ delete(endpoint, method = "GET") {
69
+ const key = this.getKey(endpoint, method);
70
+ this.cache.delete(key);
71
+ if (this.persist) {
72
+ const fileName = this.getFileName(endpoint, method);
73
+ const filePath = path__default.default.join(this.storageDir, fileName);
74
+ if (fs__default.default.existsSync(filePath)) {
75
+ fs__default.default.unlinkSync(filePath);
76
+ }
77
+ }
78
+ }
79
+ /**
80
+ * 清空所有数据
81
+ */
82
+ clear() {
83
+ this.cache.clear();
84
+ if (this.persist && fs__default.default.existsSync(this.storageDir)) {
85
+ const files = fs__default.default.readdirSync(this.storageDir);
86
+ for (const file of files) {
87
+ fs__default.default.unlinkSync(path__default.default.join(this.storageDir, file));
88
+ }
89
+ }
90
+ }
91
+ /**
92
+ * 获取所有端点
93
+ */
94
+ getAll() {
95
+ return Array.from(this.cache.values());
96
+ }
97
+ /**
98
+ * 保存到文件
99
+ */
100
+ save(endpoint, method, store) {
101
+ const fileName = this.getFileName(endpoint, method);
102
+ const filePath = path__default.default.join(this.storageDir, fileName);
103
+ fs__default.default.writeFileSync(filePath, JSON.stringify(store, null, 2), "utf-8");
104
+ }
105
+ /**
106
+ * 从文件加载
107
+ */
108
+ load() {
109
+ if (!this.persist || !fs__default.default.existsSync(this.storageDir)) {
110
+ return;
111
+ }
112
+ const files = fs__default.default.readdirSync(this.storageDir);
113
+ for (const file of files) {
114
+ if (!file.endsWith(".json")) continue;
115
+ try {
116
+ const filePath = path__default.default.join(this.storageDir, file);
117
+ const content = fs__default.default.readFileSync(filePath, "utf-8");
118
+ const store = JSON.parse(content);
119
+ const key = this.getKey(store.endpoint, store.method);
120
+ this.cache.set(key, store);
121
+ } catch (error) {
122
+ console.warn(`Failed to load mock data from ${file}:`, error);
123
+ }
124
+ }
125
+ }
126
+ /**
127
+ * 导出所有数据
128
+ */
129
+ export(outputPath) {
130
+ const allData = this.getAll();
131
+ fs__default.default.writeFileSync(outputPath, JSON.stringify(allData, null, 2), "utf-8");
132
+ }
133
+ /**
134
+ * 导入数据
135
+ */
136
+ import(inputPath) {
137
+ const content = fs__default.default.readFileSync(inputPath, "utf-8");
138
+ const allData = JSON.parse(content);
139
+ for (const store of allData) {
140
+ const key = this.getKey(store.endpoint, store.method);
141
+ this.cache.set(key, store);
142
+ if (this.persist) {
143
+ this.save(store.endpoint, store.method, store);
144
+ }
145
+ }
146
+ }
147
+ };
148
+
149
+ // src/generator.ts
150
+ var MockDataGenerator = class {
151
+ constructor(options) {
152
+ this.apiKey = options.apiKey;
153
+ this.apiUrl = options.apiUrl;
154
+ this.model = options.model;
155
+ }
156
+ /**
157
+ * 生成 Mock 数据
158
+ */
159
+ async generate(context) {
160
+ const { type, count, locale, quality } = context;
161
+ const prompt = this.buildPrompt(type, count, locale, quality);
162
+ const response = await this.callAI(prompt);
163
+ return this.parseResponse(response, type.isArray);
164
+ }
165
+ /**
166
+ * 构建 AI Prompt
167
+ */
168
+ buildPrompt(type, count, locale, quality) {
169
+ const properties = type.properties.map((p) => this.formatProperty(p)).join("\n");
170
+ return `
171
+ \u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 Mock \u6570\u636E\u751F\u6210\u5668\u3002\u8BF7\u6839\u636E\u4EE5\u4E0B\u7C7B\u578B\u5B9A\u4E49\u751F\u6210\u771F\u5B9E\u3001\u5408\u7406\u7684\u6D4B\u8BD5\u6570\u636E\u3002
172
+
173
+ \u7C7B\u578B\u540D\u79F0: ${type.name}
174
+ \u6570\u636E\u8BED\u8A00: ${locale === "zh-CN" ? "\u4E2D\u6587" : "\u82F1\u6587"}
175
+ \u6570\u636E\u6570\u91CF: ${count}
176
+ \u8D28\u91CF\u8981\u6C42: ${quality === "high" ? "\u9AD8\u8D28\u91CF\uFF08\u771F\u5B9E\u4E1A\u52A1\u6570\u636E\uFF09" : quality === "fast" ? "\u5FEB\u901F\u751F\u6210" : "\u5E73\u8861\u8D28\u91CF\u548C\u901F\u5EA6"}
177
+
178
+ \u7C7B\u578B\u5B9A\u4E49:
179
+ ${properties}
180
+
181
+ \u8981\u6C42:
182
+ 1. \u751F\u6210 ${count} \u6761\u6570\u636E
183
+ 2. \u6570\u636E\u8981\u7B26\u5408\u4E1A\u52A1\u903B\u8F91\u548C\u771F\u5B9E\u573A\u666F
184
+ 3. \u5B57\u6BB5\u503C\u8981\u5408\u7406\uFF08\u5982\u4EF7\u683C\u4E0D\u80FD\u4E3A\u8D1F\u6570\uFF0C\u5E74\u9F84\u5728\u5408\u7406\u8303\u56F4\uFF09
185
+ 4. \u65E5\u671F\u683C\u5F0F\u4F7F\u7528 ISO 8601
186
+ 5. \u8FD4\u56DE JSON \u6570\u7EC4\u683C\u5F0F\uFF0C\u4E0D\u8981\u5305\u542B\u4EFB\u4F55\u5176\u4ED6\u6587\u5B57
187
+ 6. \u7406\u89E3\u5B57\u6BB5\u8BED\u4E49\uFF0C\u751F\u6210\u771F\u5B9E\u6570\u636E\uFF08\u5982 userName \u751F\u6210\u771F\u5B9E\u59D3\u540D\uFF09
188
+
189
+ \u793A\u4F8B\u683C\u5F0F:
190
+ [
191
+ {
192
+ "id": 1,
193
+ "name": "\u5F20\u4E09",
194
+ ...
195
+ }
196
+ ]
197
+
198
+ \u8BF7\u751F\u6210\u6570\u636E:
199
+ `.trim();
200
+ }
201
+ /**
202
+ * 格式化属性
203
+ */
204
+ formatProperty(prop) {
205
+ let line = `- ${prop.name}: ${prop.type}`;
206
+ if (prop.comment) {
207
+ line += ` // ${prop.comment}`;
208
+ }
209
+ if (prop.constraints) {
210
+ const constraints = [];
211
+ if (prop.constraints.min !== void 0) {
212
+ constraints.push(`min: ${prop.constraints.min}`);
213
+ }
214
+ if (prop.constraints.max !== void 0) {
215
+ constraints.push(`max: ${prop.constraints.max}`);
216
+ }
217
+ if (prop.constraints.unique) {
218
+ constraints.push("unique");
219
+ }
220
+ if (prop.constraints.enum) {
221
+ constraints.push(`enum: [${prop.constraints.enum.join(", ")}]`);
222
+ }
223
+ if (constraints.length > 0) {
224
+ line += ` (${constraints.join(", ")})`;
225
+ }
226
+ }
227
+ return line;
228
+ }
229
+ /**
230
+ * 调用 AI API
231
+ */
232
+ async callAI(prompt) {
233
+ try {
234
+ const response = await fetch(`${this.apiUrl}/chat/completions`, {
235
+ method: "POST",
236
+ headers: {
237
+ "Content-Type": "application/json",
238
+ Authorization: `Bearer ${this.apiKey}`
239
+ },
240
+ body: JSON.stringify({
241
+ model: this.model,
242
+ messages: [
243
+ {
244
+ role: "user",
245
+ content: prompt
246
+ }
247
+ ],
248
+ temperature: 0.7
249
+ })
250
+ });
251
+ if (!response.ok) {
252
+ throw new Error(`AI API error: ${response.statusText}`);
253
+ }
254
+ const data = await response.json();
255
+ return data.choices[0].message.content;
256
+ } catch (error) {
257
+ console.error("Failed to call AI API:", error);
258
+ throw error;
259
+ }
260
+ }
261
+ /**
262
+ * 解析 AI 响应
263
+ */
264
+ parseResponse(response, isArray = true) {
265
+ try {
266
+ let cleanedResponse = response.trim();
267
+ cleanedResponse = cleanedResponse.replace(/^```json\s*/i, "");
268
+ cleanedResponse = cleanedResponse.replace(/^```\s*/, "");
269
+ cleanedResponse = cleanedResponse.replace(/\s*```$/, "");
270
+ const jsonMatch = cleanedResponse.match(/(\[[\s\S]*\]|\{[\s\S]*\})/);
271
+ if (!jsonMatch) {
272
+ throw new Error("No JSON array or object found in response");
273
+ }
274
+ const data = JSON.parse(jsonMatch[0]);
275
+ return isArray ? data : data[0];
276
+ } catch (error) {
277
+ console.error("Failed to parse AI response:", error);
278
+ console.error("Response:", response);
279
+ throw error;
280
+ }
281
+ }
282
+ /**
283
+ * 生成基础数据(不使用 AI)
284
+ */
285
+ generateBasic(type, count) {
286
+ const data = [];
287
+ for (let i = 0; i < count; i++) {
288
+ const item = {};
289
+ for (const prop of type.properties) {
290
+ item[prop.name] = this.generateBasicValue(prop, i);
291
+ }
292
+ data.push(item);
293
+ }
294
+ return data;
295
+ }
296
+ /**
297
+ * 生成基础值
298
+ */
299
+ generateBasicValue(prop, index) {
300
+ const { type, constraints } = prop;
301
+ if (constraints?.enum) {
302
+ return constraints.enum[index % constraints.enum.length];
303
+ }
304
+ switch (type) {
305
+ case "number":
306
+ const min = constraints?.min ?? 0;
307
+ const max = constraints?.max ?? 100;
308
+ return Math.floor(Math.random() * (max - min + 1)) + min;
309
+ case "string":
310
+ return `${prop.name}_${index + 1}`;
311
+ case "boolean":
312
+ return Math.random() > 0.5;
313
+ case "Date":
314
+ return (/* @__PURE__ */ new Date()).toISOString();
315
+ default:
316
+ return null;
317
+ }
318
+ }
319
+ };
320
+
321
+ // src/utils.ts
322
+ function delay(ms) {
323
+ const delayTime = Array.isArray(ms) ? Math.random() * (ms[1] - ms[0]) + ms[0] : ms;
324
+ return new Promise((resolve) => setTimeout(resolve, delayTime));
325
+ }
326
+ function matchPathParams(pattern, path2) {
327
+ const patternParts = pattern.split("/");
328
+ const pathParts = path2.split("/");
329
+ if (patternParts.length !== pathParts.length) {
330
+ return null;
331
+ }
332
+ const params = {};
333
+ for (let i = 0; i < patternParts.length; i++) {
334
+ const patternPart = patternParts[i];
335
+ const pathPart = pathParts[i];
336
+ if (patternPart.startsWith(":")) {
337
+ const paramName = patternPart.slice(1);
338
+ params[paramName] = pathPart;
339
+ } else if (patternPart !== pathPart) {
340
+ return null;
341
+ }
342
+ }
343
+ return params;
344
+ }
345
+ function parseQueryParams(url) {
346
+ const queryString = url.split("?")[1];
347
+ if (!queryString) return {};
348
+ const params = {};
349
+ const pairs = queryString.split("&");
350
+ for (const pair of pairs) {
351
+ const [key, value] = pair.split("=");
352
+ params[decodeURIComponent(key)] = decodeURIComponent(value || "");
353
+ }
354
+ return params;
355
+ }
356
+ function applyFilters(data, filters) {
357
+ if (!filters || Object.keys(filters).length === 0) {
358
+ return data;
359
+ }
360
+ return data.filter((item) => {
361
+ for (const [key, value] of Object.entries(filters)) {
362
+ if (item[key] !== value) {
363
+ return false;
364
+ }
365
+ }
366
+ return true;
367
+ });
368
+ }
369
+ function applySorting(data, sort) {
370
+ if (!sort) return data;
371
+ const sortConfig = typeof sort === "string" ? { field: sort, order: "asc" } : sort;
372
+ return [...data].sort((a, b) => {
373
+ const aValue = a[sortConfig.field];
374
+ const bValue = b[sortConfig.field];
375
+ if (aValue < bValue) return sortConfig.order === "asc" ? -1 : 1;
376
+ if (aValue > bValue) return sortConfig.order === "asc" ? 1 : -1;
377
+ return 0;
378
+ });
379
+ }
380
+ function applyPagination(data, page = 1, pageSize = 20) {
381
+ const total = data.length;
382
+ const totalPages = Math.ceil(total / pageSize);
383
+ const start = (page - 1) * pageSize;
384
+ const end = start + pageSize;
385
+ return {
386
+ data: data.slice(start, end),
387
+ pagination: {
388
+ page,
389
+ pageSize,
390
+ total,
391
+ totalPages
392
+ }
393
+ };
394
+ }
395
+ function formatResponse(data, success = true, message) {
396
+ return {
397
+ code: success ? 200 : 500,
398
+ data,
399
+ message: message || (success ? "Success" : "Error")
400
+ };
401
+ }
402
+
403
+ // src/server.ts
404
+ var MockServer = class {
405
+ constructor(storage, options) {
406
+ this.storage = storage;
407
+ this.endpoints = options.endpoints || [];
408
+ this.options = options;
409
+ }
410
+ /**
411
+ * 配置服务器中间件
412
+ */
413
+ configureServer(server) {
414
+ server.middlewares.use(async (req, res, next) => {
415
+ const url = req.url || "";
416
+ const method = req.method;
417
+ const endpoint = this.matchEndpoint(url, method);
418
+ if (!endpoint) {
419
+ return next();
420
+ }
421
+ try {
422
+ const params = this.parseRequest(req, url);
423
+ const data = await this.getMockData(endpoint, params);
424
+ if (this.options.server?.delay) {
425
+ await delay(this.options.server.delay);
426
+ }
427
+ res.setHeader("Content-Type", "application/json");
428
+ if (this.options.server?.cors) {
429
+ res.setHeader("Access-Control-Allow-Origin", "*");
430
+ res.setHeader("Access-Control-Allow-Methods", "*");
431
+ res.setHeader("Access-Control-Allow-Headers", "*");
432
+ }
433
+ res.statusCode = 200;
434
+ res.end(JSON.stringify(data));
435
+ if (this.options.output?.logs) {
436
+ console.log(`[Mock] ${method} ${url} \u2192 ${data ? "OK" : "Empty"}`);
437
+ }
438
+ } catch (error) {
439
+ console.error(`[Mock] Error handling ${method} ${url}:`, error);
440
+ res.statusCode = 500;
441
+ res.end(
442
+ JSON.stringify({
443
+ code: 500,
444
+ message: error.message
445
+ })
446
+ );
447
+ }
448
+ });
449
+ console.log("\n\u{1F3AD} Mock \u670D\u52A1\u5668\u5DF2\u542F\u52A8");
450
+ console.log(`\u{1F4CD} \u5DF2\u6CE8\u518C ${this.endpoints.length} \u4E2A\u7AEF\u70B9
451
+ `);
452
+ }
453
+ /**
454
+ * 匹配端点
455
+ */
456
+ matchEndpoint(url, method) {
457
+ const path2 = url.split("?")[0];
458
+ const prefix = this.options.server?.prefix || "";
459
+ const cleanPath = prefix ? path2.replace(new RegExp(`^${prefix}`), "") : path2;
460
+ for (const endpoint of this.endpoints) {
461
+ if (endpoint.enabled === false) continue;
462
+ if (endpoint.method !== method) continue;
463
+ if (endpoint.path === cleanPath) {
464
+ return endpoint;
465
+ }
466
+ if (matchPathParams(endpoint.path, cleanPath)) {
467
+ return endpoint;
468
+ }
469
+ }
470
+ return null;
471
+ }
472
+ /**
473
+ * 解析请求
474
+ */
475
+ parseRequest(req, url) {
476
+ const query = parseQueryParams(url);
477
+ const path2 = url.split("?")[0];
478
+ const endpoint = this.matchEndpoint(path2, req.method);
479
+ const pathParams = endpoint ? matchPathParams(endpoint.path, path2.split("?")[0]) : null;
480
+ return {
481
+ query,
482
+ params: pathParams || {},
483
+ body: req.body,
484
+ headers: req.headers
485
+ };
486
+ }
487
+ /**
488
+ * 获取 Mock 数据
489
+ */
490
+ async getMockData(endpoint, params) {
491
+ let data = this.storage.get(endpoint.path, endpoint.method);
492
+ if (!data) {
493
+ console.warn(
494
+ `[Mock] No data found for ${endpoint.method} ${endpoint.path}`
495
+ );
496
+ return formatResponse([], false, "No mock data available");
497
+ }
498
+ if (Array.isArray(data)) {
499
+ if (params.query.filter) {
500
+ data = applyFilters(data, JSON.parse(params.query.filter));
501
+ }
502
+ if (params.query.sort) {
503
+ data = applySorting(data, params.query.sort);
504
+ }
505
+ if (params.query.page || params.query.pageSize) {
506
+ const page = parseInt(params.query.page) || 1;
507
+ const pageSize = parseInt(params.query.pageSize) || 20;
508
+ const result = applyPagination(data, page, pageSize);
509
+ return formatResponse({
510
+ list: result.data,
511
+ pagination: result.pagination
512
+ });
513
+ }
514
+ }
515
+ if (endpoint.custom) {
516
+ data = await endpoint.custom(data, params);
517
+ }
518
+ return formatResponse(data);
519
+ }
520
+ /**
521
+ * 添加端点
522
+ */
523
+ addEndpoint(endpoint) {
524
+ this.endpoints.push(endpoint);
525
+ }
526
+ /**
527
+ * 移除端点
528
+ */
529
+ removeEndpoint(path2, method) {
530
+ this.endpoints = this.endpoints.filter(
531
+ (e) => !(e.path === path2 && e.method === method)
532
+ );
533
+ }
534
+ /**
535
+ * 获取所有端点
536
+ */
537
+ getEndpoints() {
538
+ return this.endpoints;
539
+ }
540
+ };
541
+
542
+ // src/index.ts
543
+ function vitePluginAIMockGenerator(options = {}) {
544
+ const {
545
+ apiKey = process.env.OPENAI_API_KEY || "",
546
+ apiUrl = process.env.OPENAI_API_URL || "https://api.openai.com/v1",
547
+ model = process.env.OPENAI_MODEL || "gpt-4",
548
+ enabled = true,
549
+ autoGenerate = false,
550
+ generation = {
551
+ locale: "zh-CN",
552
+ count: 20,
553
+ quality: "balanced"
554
+ },
555
+ storage: storageOptions = {
556
+ dir: "mock-data",
557
+ persist: true,
558
+ cache: true
559
+ },
560
+ output = {
561
+ console: true,
562
+ logs: false
563
+ }
564
+ } = options;
565
+ if (!enabled) {
566
+ return {
567
+ name: "vite-plugin-ai-mock-generator"
568
+ };
569
+ }
570
+ const storage = new MockStorage(storageOptions);
571
+ const generator = new MockDataGenerator({ apiKey, apiUrl, model });
572
+ const server = new MockServer(storage, options);
573
+ return {
574
+ name: "vite-plugin-ai-mock-generator",
575
+ enforce: "pre",
576
+ configResolved(config) {
577
+ if (output.console) {
578
+ console.log("\n\u{1F916} AI Mock Generator \u5DF2\u542F\u52A8");
579
+ console.log(`\u{1F4C2} \u5B58\u50A8\u76EE\u5F55: ${storageOptions.dir}`);
580
+ console.log(`\u{1F30D} \u6570\u636E\u8BED\u8A00: ${generation.locale}`);
581
+ console.log(`\u{1F4CA} \u9ED8\u8BA4\u6570\u91CF: ${generation.count}`);
582
+ console.log(`\u{1F511} API Key: ${apiKey ? "\u5DF2\u914D\u7F6E" : "\u672A\u914D\u7F6E"}`);
583
+ console.log(
584
+ `\u{1F4CD} \u7AEF\u70B9\u6570\u91CF: ${options.endpoints?.length || 0}`
585
+ );
586
+ }
587
+ },
588
+ async buildStart() {
589
+ if (autoGenerate && options.endpoints) {
590
+ if (output.console) {
591
+ console.log("\n\u{1F504} \u5F00\u59CB\u81EA\u52A8\u751F\u6210 Mock \u6570\u636E...\n");
592
+ }
593
+ for (const endpoint of options.endpoints) {
594
+ const existingData = storage.get(endpoint.path, endpoint.method);
595
+ if (existingData) {
596
+ if (output.console) {
597
+ console.log(
598
+ `\u23ED\uFE0F \u8DF3\u8FC7 ${endpoint.method} ${endpoint.path} (\u5DF2\u6709\u6570\u636E)`
599
+ );
600
+ }
601
+ continue;
602
+ }
603
+ try {
604
+ if (output.console) {
605
+ console.log(`\u{1F3B2} \u751F\u6210 ${endpoint.method} ${endpoint.path}...`);
606
+ }
607
+ const typeDefinition = parseTypeDefinition(endpoint.response);
608
+ const count = endpoint.count || generation.count || 20;
609
+ let data;
610
+ if (generation.quality === "fast") {
611
+ data = generator.generateBasic(typeDefinition, count);
612
+ } else {
613
+ data = await generator.generate({
614
+ type: typeDefinition,
615
+ count,
616
+ locale: generation.locale || "zh-CN",
617
+ quality: generation.quality || "balanced"
618
+ });
619
+ }
620
+ storage.set(endpoint.path, endpoint.method, data, {
621
+ type: endpoint.response
622
+ });
623
+ if (output.console) {
624
+ console.log(
625
+ `\u2705 \u5DF2\u751F\u6210 ${count} \u6761\u6570\u636E: ${endpoint.method} ${endpoint.path}`
626
+ );
627
+ }
628
+ } catch (error) {
629
+ console.error(
630
+ `\u274C \u751F\u6210\u5931\u8D25 ${endpoint.method} ${endpoint.path}:`,
631
+ error.message
632
+ );
633
+ }
634
+ }
635
+ if (output.console) {
636
+ console.log("\n\u2728 Mock \u6570\u636E\u751F\u6210\u5B8C\u6210\n");
637
+ }
638
+ }
639
+ },
640
+ configureServer(viteServer) {
641
+ server.configureServer(viteServer);
642
+ }
643
+ };
644
+ }
645
+ function parseTypeDefinition(typeStr) {
646
+ if (typeof typeStr === "object") {
647
+ return typeStr;
648
+ }
649
+ const isArray = typeStr.endsWith("[]");
650
+ const typeName = isArray ? typeStr.slice(0, -2) : typeStr;
651
+ return {
652
+ name: typeName,
653
+ properties: [],
654
+ isArray
655
+ };
656
+ }
657
+
658
+ exports.MockDataGenerator = MockDataGenerator;
659
+ exports.MockServer = MockServer;
660
+ exports.MockStorage = MockStorage;
661
+ exports.vitePluginAIMockGenerator = vitePluginAIMockGenerator;
662
+ //# sourceMappingURL=index.js.map
663
+ //# sourceMappingURL=index.js.map