@kubb/plugin-faker 5.0.0-alpha.9 → 5.0.0-beta.10

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 (44) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +25 -7
  3. package/dist/Faker-BMgoFj8b.d.ts +27 -0
  4. package/dist/Faker-CWtonujy.js +334 -0
  5. package/dist/Faker-CWtonujy.js.map +1 -0
  6. package/dist/Faker-D39THFJ-.cjs +418 -0
  7. package/dist/Faker-D39THFJ-.cjs.map +1 -0
  8. package/dist/components.cjs +2 -2
  9. package/dist/components.d.ts +2 -31
  10. package/dist/components.js +1 -1
  11. package/dist/fakerGenerator-B-QnVz9o.d.ts +9 -0
  12. package/dist/fakerGenerator-B-XuVREg.cjs +570 -0
  13. package/dist/fakerGenerator-B-XuVREg.cjs.map +1 -0
  14. package/dist/fakerGenerator-DH6hN3yb.js +560 -0
  15. package/dist/fakerGenerator-DH6hN3yb.js.map +1 -0
  16. package/dist/generators.cjs +1 -1
  17. package/dist/generators.d.ts +2 -505
  18. package/dist/generators.js +1 -1
  19. package/dist/index.cjs +237 -84
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.ts +28 -4
  22. package/dist/index.js +229 -83
  23. package/dist/index.js.map +1 -1
  24. package/dist/printerFaker-W0pLunAj.d.ts +213 -0
  25. package/extension.yaml +357 -0
  26. package/package.json +48 -51
  27. package/src/components/Faker.tsx +124 -78
  28. package/src/generators/fakerGenerator.tsx +233 -134
  29. package/src/index.ts +7 -2
  30. package/src/plugin.ts +60 -121
  31. package/src/printers/printerFaker.ts +341 -0
  32. package/src/resolvers/resolverFaker.ts +85 -0
  33. package/src/types.ts +134 -81
  34. package/src/utils.ts +268 -0
  35. package/dist/components-BkBIov4R.js +0 -419
  36. package/dist/components-BkBIov4R.js.map +0 -1
  37. package/dist/components-IdP8GXXX.cjs +0 -461
  38. package/dist/components-IdP8GXXX.cjs.map +0 -1
  39. package/dist/fakerGenerator-CYUCNH3Q.cjs +0 -204
  40. package/dist/fakerGenerator-CYUCNH3Q.cjs.map +0 -1
  41. package/dist/fakerGenerator-M5oCrPmy.js +0 -200
  42. package/dist/fakerGenerator-M5oCrPmy.js.map +0 -1
  43. package/dist/types-r7BubMLO.d.ts +0 -132
  44. package/src/parser.ts +0 -453
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import { t as fakerGenerator } from "./fakerGenerator-M5oCrPmy.js";
2
+ import { n as printerFaker, t as fakerGenerator } from "./fakerGenerator-DH6hN3yb.js";
3
+ import { t as Faker } from "./Faker-CWtonujy.js";
3
4
  import path from "node:path";
4
- import { createPlugin, getBarrelFiles, getMode } from "@kubb/core";
5
- import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
5
+ import { PluginDriver, definePlugin, defineResolver } from "@kubb/core";
6
6
  import { pluginTsName } from "@kubb/plugin-ts";
7
+ import { createHash } from "node:crypto";
7
8
  //#region ../../internals/utils/src/casing.ts
8
9
  /**
9
10
  * Shared implementation for camelCase and PascalCase conversion.
@@ -23,9 +24,12 @@ function toCamelOrPascal(text, pascal) {
23
24
  * Splits `text` on `.` and applies `transformPart` to each segment.
24
25
  * The last segment receives `isLast = true`, all earlier segments receive `false`.
25
26
  * Segments are joined with `/` to form a file path.
27
+ *
28
+ * Only splits on dots followed by a letter so that version numbers
29
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
26
30
  */
27
31
  function applyToFileParts(text, transformPart) {
28
- const parts = text.split(".");
32
+ const parts = text.split(/\.(?=[a-zA-Z])/);
29
33
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
30
34
  }
31
35
  /**
@@ -44,98 +48,240 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
44
48
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
45
49
  }
46
50
  //#endregion
51
+ //#region ../../internals/utils/src/reserved.ts
52
+ /**
53
+ * JavaScript and Java reserved words.
54
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
55
+ */
56
+ const reservedWords = new Set([
57
+ "abstract",
58
+ "arguments",
59
+ "boolean",
60
+ "break",
61
+ "byte",
62
+ "case",
63
+ "catch",
64
+ "char",
65
+ "class",
66
+ "const",
67
+ "continue",
68
+ "debugger",
69
+ "default",
70
+ "delete",
71
+ "do",
72
+ "double",
73
+ "else",
74
+ "enum",
75
+ "eval",
76
+ "export",
77
+ "extends",
78
+ "false",
79
+ "final",
80
+ "finally",
81
+ "float",
82
+ "for",
83
+ "function",
84
+ "goto",
85
+ "if",
86
+ "implements",
87
+ "import",
88
+ "in",
89
+ "instanceof",
90
+ "int",
91
+ "interface",
92
+ "let",
93
+ "long",
94
+ "native",
95
+ "new",
96
+ "null",
97
+ "package",
98
+ "private",
99
+ "protected",
100
+ "public",
101
+ "return",
102
+ "short",
103
+ "static",
104
+ "super",
105
+ "switch",
106
+ "synchronized",
107
+ "this",
108
+ "throw",
109
+ "throws",
110
+ "transient",
111
+ "true",
112
+ "try",
113
+ "typeof",
114
+ "var",
115
+ "void",
116
+ "volatile",
117
+ "while",
118
+ "with",
119
+ "yield",
120
+ "Array",
121
+ "Date",
122
+ "hasOwnProperty",
123
+ "Infinity",
124
+ "isFinite",
125
+ "isNaN",
126
+ "isPrototypeOf",
127
+ "length",
128
+ "Math",
129
+ "name",
130
+ "NaN",
131
+ "Number",
132
+ "Object",
133
+ "prototype",
134
+ "String",
135
+ "toString",
136
+ "undefined",
137
+ "valueOf"
138
+ ]);
139
+ /**
140
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * isValidVarName('status') // true
145
+ * isValidVarName('class') // false (reserved word)
146
+ * isValidVarName('42foo') // false (starts with digit)
147
+ * ```
148
+ */
149
+ function isValidVarName(name) {
150
+ if (!name || reservedWords.has(name)) return false;
151
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
152
+ }
153
+ //#endregion
154
+ //#region src/resolvers/resolverFaker.ts
155
+ /**
156
+ * Naming convention resolver for Faker plugin.
157
+ *
158
+ * Provides default naming helpers using camelCase with a `create` prefix for factory functions and files.
159
+ *
160
+ * @example
161
+ * `resolverFaker.default('list pets', 'function') // → 'createListPets'`
162
+ */
163
+ const resolverFaker = defineResolver(() => {
164
+ return {
165
+ name: "default",
166
+ pluginName: "plugin-faker",
167
+ default(name, type) {
168
+ const resolvedName = camelCase(name, {
169
+ isFile: type === "file",
170
+ prefix: "create"
171
+ });
172
+ if (type === "file" || isValidVarName(resolvedName)) return resolvedName;
173
+ return `_${resolvedName}`;
174
+ },
175
+ resolveName(name, type) {
176
+ return this.default(name, type);
177
+ },
178
+ resolvePathName(name, type) {
179
+ return this.default(name, type);
180
+ },
181
+ resolveFile({ name, extname, tag, path: groupPath }, context) {
182
+ const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path));
183
+ const baseName = `${pathMode === "single" ? "" : this.resolveName(name, "file")}${extname}`;
184
+ const filePath = this.resolvePath({
185
+ baseName,
186
+ pathMode,
187
+ tag,
188
+ path: groupPath
189
+ }, context);
190
+ return {
191
+ kind: "File",
192
+ id: createHash("sha256").update(filePath).digest("hex"),
193
+ name: path.basename(filePath, extname),
194
+ path: filePath,
195
+ baseName,
196
+ extname,
197
+ meta: { pluginName: this.pluginName },
198
+ sources: [],
199
+ imports: [],
200
+ exports: []
201
+ };
202
+ },
203
+ resolveParamName(node, param) {
204
+ return this.resolveName(`${node.operationId} ${param.in} ${param.name}`);
205
+ },
206
+ resolveDataName(node) {
207
+ return this.resolveName(`${node.operationId} Data`);
208
+ },
209
+ resolveResponseStatusName(node, statusCode) {
210
+ return this.resolveName(`${node.operationId} Status ${statusCode}`);
211
+ },
212
+ resolveResponseName(node) {
213
+ return this.resolveName(`${node.operationId} Response`);
214
+ },
215
+ resolveResponsesName(node) {
216
+ return this.resolveName(`${node.operationId} Responses`);
217
+ },
218
+ resolvePathParamsName(node, param) {
219
+ return this.resolveParamName(node, param);
220
+ },
221
+ resolveQueryParamsName(node, param) {
222
+ return this.resolveParamName(node, param);
223
+ },
224
+ resolveHeaderParamsName(node, param) {
225
+ return this.resolveParamName(node, param);
226
+ }
227
+ };
228
+ });
229
+ //#endregion
47
230
  //#region src/plugin.ts
231
+ /**
232
+ * Canonical plugin name for `@kubb/plugin-faker`, used in driver lookups and warnings.
233
+ */
48
234
  const pluginFakerName = "plugin-faker";
49
- const pluginFaker = createPlugin((options) => {
235
+ /**
236
+ * Generates Faker mock data factories from OpenAPI/AST specification.
237
+ *
238
+ * Creates randomized test data and mock helpers from schema definitions.
239
+ *
240
+ * @example
241
+ * `import pluginFaker from '@kubb/plugin-faker'; export default defineConfig({ plugins: [pluginFaker({ output: { path: 'mocks' } })], })`
242
+ */
243
+ const pluginFaker = definePlugin((options) => {
50
244
  const { output = {
51
245
  path: "mocks",
52
246
  barrelType: "named"
53
- }, seed, group, exclude = [], include, override = [], transformers = {}, mapper = {}, unknownType = "any", emptySchemaType = unknownType, dateType = "string", integerType = "number", dateParser = "faker", generators = [fakerGenerator].filter(Boolean), regexGenerator = "faker", paramsCasing, contentType } = options;
247
+ }, seed, locale, group, exclude = [], include, override = [], mapper = {}, dateParser = "faker", generators: userGenerators = [], regexGenerator = "faker", paramsCasing, printer, resolver: userResolver, transformer: userTransformer } = options;
248
+ const groupConfig = group ? {
249
+ ...group,
250
+ name: group.name ? group.name : (ctx) => {
251
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
252
+ return `${camelCase(ctx.group)}Controller`;
253
+ }
254
+ } : void 0;
54
255
  return {
55
256
  name: pluginFakerName,
56
- options: {
57
- output,
58
- transformers,
59
- seed,
60
- dateType,
61
- integerType,
62
- unknownType,
63
- emptySchemaType,
64
- dateParser,
65
- mapper,
66
- override,
67
- regexGenerator,
68
- paramsCasing,
69
- group,
70
- usedEnumNames: {}
71
- },
72
- pre: [pluginOasName, pluginTsName],
73
- resolvePath(baseName, pathMode, options) {
74
- const root = path.resolve(this.config.root, this.config.output.path);
75
- if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
76
- /**
77
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
78
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
79
- */
80
- return path.resolve(root, output.path);
81
- if (group && (options?.group?.path || options?.group?.tag)) {
82
- const groupName = group?.name ? group.name : (ctx) => {
83
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
84
- return `${camelCase(ctx.group)}Controller`;
85
- };
86
- return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
87
- }
88
- return path.resolve(root, output.path, baseName);
89
- },
90
- resolveName(name, type) {
91
- const resolvedName = camelCase(name, {
92
- prefix: type ? "create" : void 0,
93
- isFile: type === "file"
94
- });
95
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
96
- return resolvedName;
97
- },
98
- async install() {
99
- const root = path.resolve(this.config.root, this.config.output.path);
100
- const mode = getMode(path.resolve(root, output.path));
101
- const oas = await this.getOas();
102
- const schemaFiles = await new SchemaGenerator(this.plugin.options, {
103
- fabric: this.fabric,
104
- oas,
105
- driver: this.driver,
106
- events: this.events,
107
- plugin: this.plugin,
108
- contentType,
109
- include: void 0,
110
- override,
111
- mode,
112
- output: output.path
113
- }).build(...generators);
114
- await this.upsertFile(...schemaFiles);
115
- const operationFiles = await new OperationGenerator(this.plugin.options, {
116
- fabric: this.fabric,
117
- oas,
118
- driver: this.driver,
119
- events: this.events,
120
- plugin: this.plugin,
121
- contentType,
257
+ options,
258
+ dependencies: [pluginTsName],
259
+ hooks: { "kubb:plugin:setup"(ctx) {
260
+ ctx.setOptions({
261
+ output,
262
+ seed,
263
+ locale,
122
264
  exclude,
123
265
  include,
124
266
  override,
125
- mode
126
- }).build(...generators);
127
- await this.upsertFile(...operationFiles);
128
- const barrelFiles = await getBarrelFiles(this.fabric.files, {
129
- type: output.barrelType ?? "named",
130
- root,
131
- output,
132
- meta: { pluginName: this.plugin.name }
267
+ group: groupConfig,
268
+ mapper,
269
+ dateParser,
270
+ regexGenerator,
271
+ paramsCasing,
272
+ printer
133
273
  });
134
- await this.upsertFile(...barrelFiles);
135
- }
274
+ ctx.setResolver(userResolver ? {
275
+ ...resolverFaker,
276
+ ...userResolver
277
+ } : resolverFaker);
278
+ if (userTransformer) ctx.setTransformer(userTransformer);
279
+ ctx.addGenerator(fakerGenerator);
280
+ for (const generator of userGenerators) ctx.addGenerator(generator);
281
+ } }
136
282
  };
137
283
  });
138
284
  //#endregion
139
- export { pluginFaker, pluginFakerName };
285
+ export { Faker, pluginFaker as default, pluginFaker, fakerGenerator, pluginFakerName, printerFaker, resolverFaker };
140
286
 
141
287
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n integerType = 'number',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n paramsCasing,\n contentType,\n } = options\n\n // @deprecated Will be removed in v5 when collisionDetection defaults to true\n const usedEnumNames = {}\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n integerType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n paramsCasing,\n group,\n usedEnumNames,\n },\n pre: [pluginOasName, pluginTsName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CA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QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../src/resolvers/resolverFaker.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase, isValidVarName } from '@internals/utils'\nimport { defineResolver, PluginDriver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\n/**\n * Naming convention resolver for Faker plugin.\n *\n * Provides default naming helpers using camelCase with a `create` prefix for factory functions and files.\n *\n * @example\n * `resolverFaker.default('list pets', 'function') // → 'createListPets'`\n */\nexport const resolverFaker = defineResolver<PluginFaker>(() => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file', prefix: 'create' })\n\n if (type === 'file' || isValidVarName(resolvedName)) {\n return resolvedName\n }\n\n return `_${resolvedName}`\n },\n resolveName(name, type) {\n return this.default(name, type)\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveFile({ name, extname, tag, path: groupPath }, context) {\n const pathMode = PluginDriver.getMode(path.resolve(context.root, context.output.path))\n const baseName = `${pathMode === 'single' ? '' : this.resolveName(name, 'file')}${extname}` as `${string}.${string}`\n const filePath = this.resolvePath(\n {\n baseName,\n pathMode,\n tag,\n path: groupPath,\n },\n context,\n )\n\n return {\n kind: 'File',\n id: createHash('sha256').update(filePath).digest('hex'),\n name: path.basename(filePath, extname),\n path: filePath,\n baseName,\n extname,\n meta: { pluginName: this.pluginName },\n sources: [],\n imports: [],\n exports: [],\n }\n },\n resolveParamName(node, param) {\n return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)\n },\n resolveDataName(node) {\n return this.resolveName(`${node.operationId} Data`)\n },\n resolveResponseStatusName(node, statusCode) {\n return this.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseName(node) {\n return this.resolveName(`${node.operationId} Response`)\n },\n resolveResponsesName(node) {\n return this.resolveName(`${node.operationId} Responses`)\n },\n resolvePathParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n resolveQueryParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n resolveHeaderParamsName(node, param) {\n return this.resolveParamName(node, param)\n },\n }\n})\n","import { camelCase } from '@internals/utils'\nimport { definePlugin, type Group } from '@kubb/core'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport { resolverFaker } from './resolvers/resolverFaker.ts'\nimport type { PluginFaker } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-faker`, used in driver lookups and warnings.\n */\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\n/**\n * Generates Faker mock data factories from OpenAPI/AST specification.\n *\n * Creates randomized test data and mock helpers from schema definitions.\n *\n * @example\n * `import pluginFaker from '@kubb/plugin-faker'; export default defineConfig({ plugins: [pluginFaker({ output: { path: 'mocks' } })], })`\n */\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n locale,\n group,\n exclude = [],\n include,\n override = [],\n mapper = {},\n dateParser = 'faker',\n generators: userGenerators = [],\n regexGenerator = 'faker',\n paramsCasing,\n printer,\n resolver: userResolver,\n transformer: userTransformer,\n } = options\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : undefined\n\n return {\n name: pluginFakerName,\n options,\n dependencies: [pluginTsName],\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n seed,\n locale,\n exclude,\n include,\n override,\n group: groupConfig,\n mapper,\n dateParser,\n regexGenerator,\n paramsCasing,\n printer,\n })\n ctx.setResolver(userResolver ? { ...resolverFaker, ...userResolver } : resolverFaker)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n ctx.addGenerator(fakerGenerator)\n for (const generator of userGenerators) {\n ctx.addGenerator(generator)\n }\n },\n },\n }\n})\n\nexport default pluginFaker\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;CAS9D,OARmB,KAChB,MAAM,CACN,Q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,iBACF,IAAI,eAAe,gBAAgB;GAErC,IAAI,aAAa,eAAe;GAChC,KAAK,MAAM,aAAa,gBACtB,IAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
@@ -0,0 +1,213 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.js";
2
+ import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * Resolver for Faker that provides naming methods for mock functions.
7
+ */
8
+ type ResolverFaker = Resolver & ast.OperationParamsResolver & {
9
+ /**
10
+ * Resolves the faker function name for a schema.
11
+ *
12
+ * @example Resolving faker function names
13
+ * `resolver.resolveName('show pet by id') // -> 'showPetById'`
14
+ */
15
+ resolveName(this: ResolverFaker, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
16
+ /**
17
+ * Resolves the output file name for a faker module.
18
+ *
19
+ * @example Resolving faker file names
20
+ * `resolver.resolvePathName('show pet by id', 'file') // -> 'showPetById'`
21
+ */
22
+ resolvePathName(this: ResolverFaker, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
23
+ /**
24
+ * Resolves the faker function name for a request body.
25
+ *
26
+ * @example Resolving data function names
27
+ * `resolver.resolveDataName(node) // -> 'createPetsData'`
28
+ */
29
+ resolveDataName(this: ResolverFaker, node: ast.OperationNode): string;
30
+ /**
31
+ * Resolves the faker function name for a response by status code.
32
+ *
33
+ * @example Response status names
34
+ * `resolver.resolveResponseStatusName(node, 200) // -> 'listPetsStatus200'`
35
+ */
36
+ resolveResponseStatusName(this: ResolverFaker, node: ast.OperationNode, statusCode: ast.StatusCode): string;
37
+ /**
38
+ * Resolves the faker function name for the response union.
39
+ *
40
+ * @example Response union names
41
+ * `resolver.resolveResponseName(node) // -> 'listPetsResponse'`
42
+ */
43
+ resolveResponseName(this: ResolverFaker, node: ast.OperationNode): string;
44
+ /**
45
+ * Resolves the faker function name for the response collection.
46
+ *
47
+ * @example Responses collection names
48
+ * `resolver.resolveResponsesName(node) // -> 'listPetsResponses'`
49
+ */
50
+ resolveResponsesName(this: ResolverFaker, node: ast.OperationNode): string;
51
+ /**
52
+ * Resolves the faker function name for path parameters.
53
+ *
54
+ * @example Path parameters names
55
+ * `resolver.resolvePathParamsName(node, param) // -> 'showPetByIdPathPetId'`
56
+ */
57
+ resolvePathParamsName(this: ResolverFaker, node: ast.OperationNode, param: ast.ParameterNode): string;
58
+ /**
59
+ * Resolves the faker function name for query parameters.
60
+ *
61
+ * @example Query parameters names
62
+ * `resolver.resolveQueryParamsName(node, param) // -> 'listPetsQueryLimit'`
63
+ */
64
+ resolveQueryParamsName(this: ResolverFaker, node: ast.OperationNode, param: ast.ParameterNode): string;
65
+ /**
66
+ * Resolves the faker function name for header parameters.
67
+ *
68
+ * @example Header parameters names
69
+ * `resolver.resolveHeaderParamsName(node, param) // -> 'deletePetHeaderApiKey'`
70
+ */
71
+ resolveHeaderParamsName(this: ResolverFaker, node: ast.OperationNode, param: ast.ParameterNode): string;
72
+ };
73
+ type Options = {
74
+ /**
75
+ * Specify the export location for the files and define the behavior of the output.
76
+ * @default { path: 'mocks', barrelType: 'named' }
77
+ */
78
+ output?: Output;
79
+ /**
80
+ * Group the Faker mocks based on the provided name.
81
+ */
82
+ group?: Group;
83
+ /**
84
+ * Tags, operations, or paths to exclude from generation.
85
+ */
86
+ exclude?: Array<Exclude>;
87
+ /**
88
+ * Tags, operations, or paths to include in generation.
89
+ */
90
+ include?: Array<Include>;
91
+ /**
92
+ * Override options for specific tags, operations, or paths.
93
+ */
94
+ override?: Array<Override<ResolvedOptions>>;
95
+ /**
96
+ * Parser to use when formatting date/time values as strings.
97
+ *
98
+ * @default 'faker'
99
+ */
100
+ dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {});
101
+ /**
102
+ * Generator to use for RegExp patterns.
103
+ *
104
+ * @default 'faker'
105
+ */
106
+ regexGenerator?: 'faker' | 'randexp';
107
+ /**
108
+ * Provide per-property faker expressions keyed by property name.
109
+ */
110
+ mapper?: Record<string, string>;
111
+ /**
112
+ * Locale for generating mock data.
113
+ * Imports the matching localized `@faker-js/faker` instance so names, addresses,
114
+ * and phone numbers reflect the target region.
115
+ *
116
+ * @default 'en'
117
+ *
118
+ * @example German
119
+ * `locale: 'de'`
120
+ *
121
+ * @example Austrian German
122
+ * `locale: 'de_AT'`
123
+ *
124
+ * @see https://fakerjs.dev/api/localization.html
125
+ */
126
+ locale?: string;
127
+ /**
128
+ * Seed faker for deterministic output.
129
+ */
130
+ seed?: number | number[];
131
+ /**
132
+ * Apply casing to parameter names to match your configuration.
133
+ */
134
+ paramsCasing?: 'camelcase';
135
+ /**
136
+ * Additional generators alongside the default generators.
137
+ */
138
+ generators?: Array<Generator<PluginFaker>>;
139
+ /**
140
+ * Override naming conventions for function names and types.
141
+ */
142
+ resolver?: Partial<ResolverFaker> & ThisType<ResolverFaker>;
143
+ /**
144
+ * AST visitor to transform generated nodes.
145
+ */
146
+ transformer?: ast.Visitor;
147
+ /**
148
+ * Override individual faker printer node handlers.
149
+ */
150
+ printer?: {
151
+ nodes?: PrinterFakerNodes;
152
+ };
153
+ };
154
+ type ResolvedOptions = {
155
+ output: Output;
156
+ group: Group | undefined;
157
+ exclude: NonNullable<Options['exclude']>;
158
+ include: Options['include'];
159
+ override: NonNullable<Options['override']>;
160
+ dateParser: NonNullable<Options['dateParser']>;
161
+ regexGenerator: NonNullable<Options['regexGenerator']>;
162
+ mapper: NonNullable<Options['mapper']>;
163
+ seed: NonNullable<Options['seed']> | undefined;
164
+ locale: Options['locale'];
165
+ paramsCasing: Options['paramsCasing'];
166
+ printer: Options['printer'];
167
+ };
168
+ type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, ResolverFaker>;
169
+ declare global {
170
+ namespace Kubb {
171
+ interface PluginRegistry {
172
+ 'plugin-faker': PluginFaker;
173
+ }
174
+ }
175
+ }
176
+ //#endregion
177
+ //#region src/printers/printerFaker.d.ts
178
+ /**
179
+ * Partial printer nodes for Faker generation, mapping schema types to output strings.
180
+ */
181
+ type PrinterFakerNodes = ast.PrinterPartial<string, PrinterFakerOptions>;
182
+ /**
183
+ * Configuration options for the Faker printer, including resolvers, mappers, and cyclic schema tracking.
184
+ */
185
+ type PrinterFakerOptions = {
186
+ dateParser?: PluginFaker['resolvedOptions']['dateParser'];
187
+ regexGenerator?: PluginFaker['resolvedOptions']['regexGenerator'];
188
+ mapper?: PluginFaker['resolvedOptions']['mapper'];
189
+ resolver: ResolverFaker;
190
+ typeName?: string;
191
+ schemaName?: string;
192
+ nestedInObject?: boolean;
193
+ nodes?: PrinterFakerNodes;
194
+ /**
195
+ * Names of schemas that participate in a circular dependency chain.
196
+ * Properties whose schema transitively references one of these are emitted
197
+ * as lazy getters so that user overrides via the `data` parameter prevent
198
+ * the recursive faker call from ever executing (avoiding stack overflow).
199
+ */
200
+ cyclicSchemas?: ReadonlySet<string>;
201
+ };
202
+ /**
203
+ * Factory options for the Faker printer, defining input/output types and configuration.
204
+ */
205
+ type PrinterFakerFactory = ast.PrinterFactoryOptions<'faker', PrinterFakerOptions, string, string>;
206
+ /**
207
+ * Creates a Faker printer that generates mock data generation code from schema nodes.
208
+ * Handles circular references gracefully by emitting memoizing getters for cyclic properties.
209
+ */
210
+ declare const printerFaker: (options: PrinterFakerOptions) => ast.Printer<PrinterFakerFactory>;
211
+ //#endregion
212
+ export { Options as a, printerFaker as i, PrinterFakerNodes as n, PluginFaker as o, PrinterFakerOptions as r, ResolverFaker as s, PrinterFakerFactory as t };
213
+ //# sourceMappingURL=printerFaker-W0pLunAj.d.ts.map