@kubb/plugin-faker 3.0.0-alpha.3 → 3.0.0-alpha.30

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.
Files changed (55) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-HTZ2R6MK.js +305 -0
  3. package/dist/chunk-HTZ2R6MK.js.map +1 -0
  4. package/dist/chunk-KBSFZ5OP.cjs +311 -0
  5. package/dist/chunk-KBSFZ5OP.cjs.map +1 -0
  6. package/dist/chunk-QFJUM25Z.js +113 -0
  7. package/dist/chunk-QFJUM25Z.js.map +1 -0
  8. package/dist/chunk-U6LOSTOE.cjs +115 -0
  9. package/dist/chunk-U6LOSTOE.cjs.map +1 -0
  10. package/dist/components.cjs +6 -565
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +15 -18
  13. package/dist/components.d.ts +15 -18
  14. package/dist/components.js +2 -570
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +13 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +8 -0
  19. package/dist/generators.d.ts +8 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +48 -504
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -125
  25. package/dist/index.d.ts +4 -125
  26. package/dist/index.js +31 -494
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DXoBXKVI.d.cts +112 -0
  29. package/dist/types-DXoBXKVI.d.ts +112 -0
  30. package/package.json +20 -16
  31. package/src/components/Faker.tsx +80 -0
  32. package/src/components/index.ts +1 -2
  33. package/src/generators/__snapshots__/createPet.ts +26 -0
  34. package/src/generators/__snapshots__/createPetSeed.ts +30 -0
  35. package/src/generators/__snapshots__/createPetUnknownTypeAny.ts +26 -0
  36. package/src/generators/__snapshots__/deletePet.ts +3 -0
  37. package/src/generators/__snapshots__/enumNames.ts +5 -0
  38. package/src/generators/__snapshots__/enumVarNames.ts +5 -0
  39. package/src/generators/__snapshots__/getPets.ts +29 -0
  40. package/src/generators/__snapshots__/pet.ts +8 -0
  41. package/src/generators/__snapshots__/petWithDateString.ts +8 -0
  42. package/src/generators/__snapshots__/petWithDayjs.ts +9 -0
  43. package/src/generators/__snapshots__/petWithMapper.ts +8 -0
  44. package/src/generators/__snapshots__/petWithRandExp.ts +9 -0
  45. package/src/generators/__snapshots__/pets.ts +8 -0
  46. package/src/generators/__snapshots__/showPetById.ts +29 -0
  47. package/src/generators/fakerGenerator.tsx +140 -0
  48. package/src/generators/index.ts +1 -0
  49. package/src/parser/index.ts +25 -14
  50. package/src/plugin.ts +19 -35
  51. package/src/types.ts +27 -48
  52. package/src/OperationGenerator.tsx +0 -31
  53. package/src/SchemaGenerator.tsx +0 -31
  54. package/src/components/OperationSchema.tsx +0 -84
  55. package/src/components/Schema.tsx +0 -146
package/dist/index.cjs CHANGED
@@ -1,521 +1,78 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/plugin.ts
2
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
3
- var _core = require('@kubb/core');
4
- var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
5
- var _utils = require('@kubb/core/utils');
6
- var _pluginoas = require('@kubb/plugin-oas');
7
- var _utils3 = require('@kubb/plugin-oas/utils');
8
- var _plugints = require('@kubb/plugin-ts');
1
+ 'use strict';
9
2
 
10
- // src/OperationGenerator.tsx
3
+ var chunkU6LOSTOE_cjs = require('./chunk-U6LOSTOE.cjs');
4
+ require('./chunk-KBSFZ5OP.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ var utils = require('@kubb/core/utils');
9
+ var pluginOas = require('@kubb/plugin-oas');
10
+ var pluginTs = require('@kubb/plugin-ts');
11
11
 
12
- var _components = require('@kubb/plugin-oas/components');
13
- var _react = require('@kubb/react');
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
13
 
15
- // src/components/OperationSchema.tsx
14
+ var path__default = /*#__PURE__*/_interopDefault(path);
16
15
 
17
- var _hooks = require('@kubb/plugin-oas/hooks');
18
-
19
-
20
-
21
- // src/SchemaGenerator.tsx
22
-
23
-
24
-
25
-
26
- // src/components/Schema.tsx
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
- // src/parser/index.ts
35
-
36
-
37
- var fakerKeywordMapper = {
38
- any: () => "undefined",
39
- unknown: () => "unknown",
40
- number: (min, max) => {
41
- if (max !== void 0 && min !== void 0) {
42
- return `faker.number.float({ min: ${min}, max: ${max} })`;
43
- }
44
- if (min !== void 0) {
45
- return `faker.number.float({ min: ${min} })`;
46
- }
47
- if (max !== void 0) {
48
- return `faker.number.float({ max: ${max} })`;
49
- }
50
- return "faker.number.float()";
51
- },
52
- integer: (min, max) => {
53
- if (max !== void 0 && min !== void 0) {
54
- return `faker.number.int({ min: ${min}, max: ${max} })`;
55
- }
56
- if (min !== void 0) {
57
- return `faker.number.int({ min: ${min} })`;
58
- }
59
- if (max !== void 0) {
60
- return `faker.number.int({ max: ${max} })`;
61
- }
62
- return "faker.number.int()";
63
- },
64
- string: (min, max) => {
65
- if (max !== void 0 && min !== void 0) {
66
- return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
67
- }
68
- if (min !== void 0) {
69
- return `faker.string.alpha({ length: { min: ${min} } })`;
70
- }
71
- if (max !== void 0) {
72
- return `faker.string.alpha({ length: { max: ${max} } })`;
73
- }
74
- return "faker.string.alpha()";
75
- },
76
- boolean: () => "faker.datatype.boolean()",
77
- undefined: () => "undefined",
78
- null: () => "null",
79
- array: (items = []) => `faker.helpers.arrayElements([${items.join(", ")}]) as any`,
80
- tuple: (items = []) => `faker.helpers.arrayElements([${items.join(", ")}]) as any`,
81
- enum: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
82
- union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
83
- /**
84
- * ISO 8601
85
- */
86
- datetime: () => "faker.date.anytime().toISOString()",
87
- /**
88
- * Type `'date'` Date
89
- * Type `'string'` ISO date format (YYYY-MM-DD)
90
- * @default ISO date format (YYYY-MM-DD)
91
- */
92
- date: (type = "string", parser) => {
93
- if (type === "string") {
94
- if (parser) {
95
- return `${parser}(faker.date.anytime()).format("YYYY-MM-DD")`;
96
- }
97
- return "faker.date.anytime().toString()";
98
- }
99
- return "faker.date.anytime()";
100
- },
101
- /**
102
- * Type `'date'` Date
103
- * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
104
- * @default ISO time format (HH:mm:ss[.SSSSSS])
105
- */
106
- time: (type = "string", parser) => {
107
- if (type === "string") {
108
- if (parser) {
109
- return `${parser}(faker.date.anytime()).format("HH:mm:ss")`;
110
- }
111
- return "faker.date.anytime().toString()";
112
- }
113
- return "faker.date.anytime()";
114
- },
115
- uuid: () => "faker.string.uuid()",
116
- url: () => "faker.internet.url()",
117
- and: (items = []) => `Object.assign({}, ${items.join(", ")})`,
118
- object: () => "object",
119
- ref: () => "ref",
120
- matches: (value = "", regexGenerator = "faker") => {
121
- if (regexGenerator === "randexp") {
122
- return `${_transformers2.default.toRegExpString(value, "RandExp")}.gen()`;
123
- }
124
- return `faker.helpers.fromRegExp(${_transformers2.default.toRegExpString(value)})`;
125
- },
126
- email: () => "faker.internet.email()",
127
- firstName: () => "faker.person.firstName()",
128
- lastName: () => "faker.person.lastName()",
129
- password: () => "faker.internet.password()",
130
- phone: () => "faker.phone.number()",
131
- blob: () => "faker.image.imageUrl() as unknown as Blob",
132
- default: void 0,
133
- describe: void 0,
134
- const: (value) => _nullishCoalesce(value, () => ( "")),
135
- max: void 0,
136
- min: void 0,
137
- nullable: void 0,
138
- nullish: void 0,
139
- optional: void 0,
140
- readOnly: void 0,
141
- strict: void 0,
142
- deprecated: void 0,
143
- example: void 0,
144
- schema: void 0,
145
- catchall: void 0,
146
- name: void 0
147
- };
148
- function schemaKeywordsorter(a, b) {
149
- if (b.keyword === "null") {
150
- return -1;
151
- }
152
- return 0;
153
- }
154
- function joinItems(items) {
155
- switch (items.length) {
156
- case 0:
157
- return "undefined";
158
- case 1:
159
- return items[0];
160
- default:
161
- return fakerKeywordMapper.union(items);
162
- }
163
- }
164
- function parse(parent, current, options) {
165
- const value = fakerKeywordMapper[current.keyword];
166
- if (!value) {
167
- return void 0;
168
- }
169
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
170
- return fakerKeywordMapper.union(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
171
- }
172
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
173
- return fakerKeywordMapper.and(current.args.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
174
- }
175
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
176
- return fakerKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
177
- }
178
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
179
- return fakerKeywordMapper.enum(
180
- current.args.items.map((schema) => {
181
- if (schema.format === "number") {
182
- return schema.name;
183
- }
184
- return _transformers2.default.stringify(schema.name);
185
- })
186
- );
187
- }
188
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.ref)) {
189
- if (!_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.name])) {
190
- throw new Error(`Name not defined for keyword ${current.keyword}`);
191
- }
192
- if (options.withData) {
193
- return `${current.args.name}(data)`;
194
- }
195
- return `${current.args.name}()`;
196
- }
197
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
198
- const argsObject = Object.entries(_optionalChain([current, 'access', _3 => _3.args, 'optionalAccess', _4 => _4.properties]) || {}).filter((item) => {
199
- const schema = item[1];
200
- return schema && typeof schema.map === "function";
201
- }).map(([name, schemas]) => {
202
- const nameSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.name);
203
- const mappedName = _optionalChain([nameSchema, 'optionalAccess', _5 => _5.args]) || name;
204
- if (_optionalChain([options, 'access', _6 => _6.mapper, 'optionalAccess', _7 => _7[mappedName]])) {
205
- return `"${name}": ${_optionalChain([options, 'access', _8 => _8.mapper, 'optionalAccess', _9 => _9[mappedName]])}`;
206
- }
207
- return `"${name}": ${joinItems(
208
- schemas.sort(schemaKeywordsorter).map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean)
209
- )}`;
210
- }).join(",");
211
- return `{${argsObject}}`;
212
- }
213
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
214
- if (Array.isArray(current.args.items)) {
215
- return fakerKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, { ...options, withData: false })).filter(Boolean));
216
- }
217
- return parse(current, current.args.items, { ...options, withData: false });
218
- }
219
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
220
- if (current.args.format === "number" && current.args.name !== void 0) {
221
- return fakerKeywordMapper.const(_optionalChain([current, 'access', _10 => _10.args, 'access', _11 => _11.name, 'optionalAccess', _12 => _12.toString, 'call', _13 => _13()]));
222
- }
223
- return fakerKeywordMapper.const(_transformers2.default.stringify(current.args.value));
224
- }
225
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.matches) && current.args) {
226
- return fakerKeywordMapper.matches(current.args, options.regexGenerator);
227
- }
228
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.null) || _pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.undefined) || _pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.any)) {
229
- return value() || "";
230
- }
231
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.string)) {
232
- if (parent) {
233
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
234
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
235
- return fakerKeywordMapper.string(_optionalChain([minSchema, 'optionalAccess', _14 => _14.args]), _optionalChain([maxSchema, 'optionalAccess', _15 => _15.args]));
236
- }
237
- return fakerKeywordMapper.string();
238
- }
239
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.number)) {
240
- if (parent) {
241
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
242
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
243
- return fakerKeywordMapper.number(_optionalChain([minSchema, 'optionalAccess', _16 => _16.args]), _optionalChain([maxSchema, 'optionalAccess', _17 => _17.args]));
244
- }
245
- return fakerKeywordMapper.number();
246
- }
247
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.integer)) {
248
- if (parent) {
249
- const minSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.min);
250
- const maxSchema = _pluginoas.SchemaGenerator.find([parent], _pluginoas.schemaKeywords.max);
251
- return fakerKeywordMapper.integer(_optionalChain([minSchema, 'optionalAccess', _18 => _18.args]), _optionalChain([maxSchema, 'optionalAccess', _19 => _19.args]));
252
- }
253
- return fakerKeywordMapper.integer();
254
- }
255
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.datetime)) {
256
- return fakerKeywordMapper.datetime();
257
- }
258
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.date)) {
259
- return fakerKeywordMapper.date(current.args.type, options.dateParser);
260
- }
261
- if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.time)) {
262
- return fakerKeywordMapper.time(current.args.type, options.dateParser);
263
- }
264
- if (current.keyword in fakerKeywordMapper && "args" in current) {
265
- const value2 = fakerKeywordMapper[current.keyword];
266
- const options2 = JSON.stringify(current.args);
267
- return value2(options2);
268
- }
269
- if (current.keyword in fakerKeywordMapper) {
270
- return value();
271
- }
272
- return void 0;
273
- }
274
-
275
- // src/components/Schema.tsx
276
- var _jsxruntime = require('@kubb/react/jsx-runtime');
277
- function Schema(props) {
278
- const { withData, description } = props;
279
- const { tree, name } = _hooks.useSchema.call(void 0, );
280
- const {
281
- pluginManager,
282
- plugin: {
283
- options: { dateParser, regexGenerator, mapper, seed }
284
- }
285
- } = _react.useApp.call(void 0, );
286
- const resolvedName = pluginManager.resolveName({
287
- name,
288
- pluginKey: [pluginFakerName],
289
- type: "function"
290
- });
291
- const typeName = pluginManager.resolveName({
292
- name,
293
- pluginKey: [_plugints.pluginTsName],
294
- type: "type"
295
- });
296
- const fakerText = joinItems(
297
- tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, seed, regexGenerator, mapper, withData, dateParser })).filter(Boolean)
298
- );
299
- let fakerDefaultOverride = void 0;
300
- let fakerTextWithOverride = fakerText;
301
- if (withData && fakerText.startsWith("{")) {
302
- fakerDefaultOverride = "{}";
303
- fakerTextWithOverride = `{
304
- ...${fakerText},
305
- ...data
306
- }`;
307
- }
308
- if (withData && fakerText.startsWith("faker.helpers.arrayElements")) {
309
- fakerDefaultOverride = "[]";
310
- fakerTextWithOverride = `[
311
- ...${fakerText},
312
- ...data
313
- ]`;
314
- }
315
- const params = fakerDefaultOverride ? `data: NonNullable<Partial<${typeName}>> = ${fakerDefaultOverride}` : `data?: NonNullable<Partial<${typeName}>>`;
316
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
317
- /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
318
- _react.Function,
319
- {
320
- export: true,
321
- name: resolvedName,
322
- JSDoc: { comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean) },
323
- params: withData ? params : "",
324
- returnType: typeName ? `NonNullable<${typeName}>` : "",
325
- children: [
326
- seed ? `faker.seed(${JSON.stringify(seed)})` : "",
327
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
328
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function.Return, { children: fakerTextWithOverride })
329
- ]
330
- }
331
- ),
332
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {})
333
- ] });
334
- }
335
- Schema.File = function({}) {
336
- const { pluginManager } = _react.useApp.call(void 0, );
337
- const { tree, schema } = _hooks.useSchema.call(void 0, );
338
- const withData = tree.some(
339
- (schema2) => schema2.keyword === _pluginoas.schemaKeywords.array || schema2.keyword === _pluginoas.schemaKeywords.and || schema2.keyword === _pluginoas.schemaKeywords.object || schema2.keyword === _pluginoas.schemaKeywords.union || schema2.keyword === _pluginoas.schemaKeywords.tuple
340
- );
341
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
342
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.Imports, {}),
343
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _20 => _20.description]), withData }) })
344
- ] });
345
- };
346
- Schema.Imports = () => {
347
- const {
348
- pluginManager,
349
- plugin: {
350
- options: { extName, dateParser, regexGenerator }
351
- }
352
- } = _react.useApp.call(void 0, );
353
- const { path: root } = _react.useFile.call(void 0, );
354
- const { name, tree, schema } = _hooks.useSchema.call(void 0, );
355
- const typeName = pluginManager.resolveName({
356
- name,
357
- pluginKey: [_plugints.pluginTsName],
358
- type: "type"
359
- });
360
- const typeFileName = pluginManager.resolveName({
361
- name,
362
- pluginKey: [_plugints.pluginTsName],
363
- type: "file"
364
- });
365
- const typePath = pluginManager.resolvePath({
366
- baseName: typeFileName,
367
- pluginKey: [_plugints.pluginTsName]
368
- });
369
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
370
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
371
- regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
372
- dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: dateParser, name: dateParser }),
373
- typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { extName, isTypeOnly: true, root, path: typePath, name: [typeName] })
374
- ] });
375
- };
376
-
377
- // src/SchemaGenerator.tsx
378
-
379
- var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
380
- async schema(name, schema, options) {
381
- const { oas, pluginManager, plugin, mode, output } = this.context;
382
- const root = _react.createRoot.call(void 0, {
383
- logger: pluginManager.logger
384
- });
385
- const tree = this.parse({ schema, name });
386
- root.render(
387
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.File, {}) }) }) })
388
- );
389
- return root.files;
390
- }
391
- };
392
-
393
- // src/components/OperationSchema.tsx
394
-
395
- function OperationSchema({ description }) {
396
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { withData: false, description });
397
- }
398
- OperationSchema.File = function({}) {
399
- const { plugin, pluginManager, mode } = _react.useApp.call(void 0, );
400
- const oas = _hooks.useOas.call(void 0, );
401
- const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
402
- const operation = _hooks.useOperation.call(void 0, );
403
- const file = getFile(operation);
404
- const schemas = getSchemas(operation);
405
- const generator = new SchemaGenerator2(plugin.options, {
406
- oas,
407
- plugin,
408
- pluginManager,
409
- mode,
410
- override: plugin.options.override
411
- });
412
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
413
- const mapItem = ({ name, schema, description, ...options }, i) => {
414
- const typeName = pluginManager.resolveName({
415
- name,
416
- pluginKey: [_plugints.pluginTsName],
417
- type: "type"
418
- });
419
- const typeFileName = pluginManager.resolveName({
420
- name: options.operationName || name,
421
- pluginKey: [_plugints.pluginTsName],
422
- type: "file"
423
- });
424
- const typePath = pluginManager.resolvePath({
425
- baseName: typeFileName,
426
- pluginKey: [_plugints.pluginTsName],
427
- options: { tag: _optionalChain([options, 'access', _21 => _21.operation, 'optionalAccess', _22 => _22.getTags, 'call', _23 => _23(), 'access', _24 => _24[0], 'optionalAccess', _25 => _25.name]) }
428
- });
429
- const tree = generator.parse({ schema, name });
430
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
431
- typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { extName: plugin.options.extName, isTypeOnly: true, root: file.path, path: typePath, name: [typeName] }),
432
- plugin.options.dateParser && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { path: plugin.options.dateParser, name: plugin.options.dateParser }),
433
- mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { extName: plugin.options.extName }),
434
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description }) })
435
- ] }, i);
436
- };
437
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
438
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["faker"], path: "@faker-js/faker" }),
439
- plugin.options.regexGenerator === "randexp" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: "RandExp", path: "randexp" }),
440
- items.map(mapItem)
441
- ] }) });
442
- };
443
-
444
- // src/OperationGenerator.tsx
445
-
446
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
447
- async operation(operation, options) {
448
- const { oas, pluginManager, plugin, mode } = this.context;
449
- const root = _react.createRoot.call(void 0, {
450
- logger: pluginManager.logger
451
- });
452
- root.render(
453
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema.File, {}) }) }) })
454
- );
455
- return root.files;
456
- }
457
- };
458
-
459
- // src/plugin.ts
460
16
  var pluginFakerName = "plugin-faker";
461
- var pluginFaker = _core.createPlugin.call(void 0, (options) => {
17
+ var pluginFaker = core.createPlugin((options) => {
462
18
  const {
463
- output = { path: "mocks" },
19
+ output = { path: "mocks", barrelType: "named" },
464
20
  seed,
465
21
  group,
466
22
  exclude = [],
467
23
  include,
468
24
  override = [],
469
- transformers: transformers3 = {},
25
+ transformers: transformers$1 = {},
470
26
  mapper = {},
471
- dateType = "string",
472
27
  unknownType = "any",
473
- dateParser,
28
+ dateType = "string",
29
+ dateParser = "faker",
30
+ generators = [chunkU6LOSTOE_cjs.fakerGenerator].filter(Boolean),
474
31
  regexGenerator = "faker"
475
32
  } = options;
476
- const template = _optionalChain([group, 'optionalAccess', _26 => _26.output]) ? group.output : `${output.path}/{{tag}}Controller`;
33
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
477
34
  return {
478
35
  name: pluginFakerName,
479
36
  options: {
480
- extName: output.extName,
481
- transformers: transformers3,
482
- dateType,
37
+ output,
38
+ transformers: transformers$1,
483
39
  seed,
40
+ dateType,
484
41
  unknownType,
485
42
  dateParser,
486
43
  mapper,
487
44
  override,
488
45
  regexGenerator
489
46
  },
490
- pre: [_pluginoas.pluginOasName, _plugints.pluginTsName],
47
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName],
491
48
  resolvePath(baseName, pathMode, options2) {
492
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
493
- const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
49
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
50
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
494
51
  if (mode === "single") {
495
- return _path2.default.resolve(root, output.path);
52
+ return path__default.default.resolve(root, output.path);
496
53
  }
497
- if (_optionalChain([options2, 'optionalAccess', _27 => _27.tag]) && _optionalChain([group, 'optionalAccess', _28 => _28.type]) === "tag") {
498
- const tag = _transformers.camelCase.call(void 0, options2.tag);
499
- return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
54
+ if (options2?.tag && group?.type === "tag") {
55
+ const tag = transformers.camelCase(options2.tag);
56
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
500
57
  }
501
- return _path2.default.resolve(root, output.path, baseName);
58
+ return path__default.default.resolve(root, output.path, baseName);
502
59
  },
503
60
  resolveName(name, type) {
504
- const resolvedName = _transformers.camelCase.call(void 0, name, {
61
+ const resolvedName = transformers.camelCase(name, {
505
62
  prefix: type ? "create" : void 0,
506
63
  isFile: type === "file"
507
64
  });
508
65
  if (type) {
509
- return _optionalChain([transformers3, 'optionalAccess', _29 => _29.name, 'optionalCall', _30 => _30(resolvedName, type)]) || resolvedName;
66
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
510
67
  }
511
68
  return resolvedName;
512
69
  },
513
70
  async buildStart() {
514
- const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
71
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
515
72
  const oas = await swaggerPlugin.context.getOas();
516
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
517
- const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
518
- const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
73
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
74
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
75
+ const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
519
76
  oas,
520
77
  pluginManager: this.pluginManager,
521
78
  plugin: this.plugin,
@@ -525,9 +82,9 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
525
82
  mode,
526
83
  output: output.path
527
84
  });
528
- const schemaFiles = await schemaGenerator.build();
85
+ const schemaFiles = await schemaGenerator.build(...generators);
529
86
  await this.addFile(...schemaFiles);
530
- const operationGenerator = new OperationGenerator(this.plugin.options, {
87
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
531
88
  oas,
532
89
  pluginManager: this.pluginManager,
533
90
  plugin: this.plugin,
@@ -537,37 +94,24 @@ var pluginFaker = _core.createPlugin.call(void 0, (options) => {
537
94
  override,
538
95
  mode
539
96
  });
540
- const operationFiles = await operationGenerator.build();
97
+ const operationFiles = await operationGenerator.build(...generators);
541
98
  await this.addFile(...operationFiles);
542
- },
543
- async buildEnd() {
544
- if (this.config.output.write === false) {
545
- return;
546
- }
547
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
548
- if (_optionalChain([group, 'optionalAccess', _31 => _31.type]) === "tag") {
549
- const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
550
- logger: this.logger,
551
- files: this.fileManager.files,
552
- plugin: this.plugin,
553
- template,
554
- exportAs: group.exportAs || "{{tag}}Mocks",
555
- root,
556
- output
557
- });
558
- await this.addFile(...rootFiles);
559
- }
560
- await this.fileManager.addIndexes({
99
+ const barrelFiles = await this.fileManager.getBarrelFiles({
100
+ type: output.barrelType ?? "named",
561
101
  root,
562
102
  output,
563
- meta: { pluginKey: this.plugin.key },
103
+ files: this.fileManager.files,
104
+ meta: {
105
+ pluginKey: this.plugin.key
106
+ },
564
107
  logger: this.logger
565
108
  });
109
+ await this.addFile(...barrelFiles);
566
110
  }
567
111
  };
568
112
  });
569
113
 
570
-
571
-
572
- exports.pluginFaker = pluginFaker; exports.pluginFakerName = pluginFakerName;
114
+ exports.pluginFaker = pluginFaker;
115
+ exports.pluginFakerName = pluginFakerName;
116
+ //# sourceMappingURL=index.cjs.map
573
117
  //# sourceMappingURL=index.cjs.map