@kubb/plugin-faker 5.0.0-beta.4 → 5.0.0-beta.56
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/README.md +39 -22
- package/dist/{Faker-CdyPfOPg.d.ts → Faker-A5UuxwJj.d.ts} +3 -3
- package/dist/{Faker-fcQEB9i5.js → Faker-CHh0JtBG.js} +41 -145
- package/dist/Faker-CHh0JtBG.js.map +1 -0
- package/dist/{Faker-BgleOzVN.cjs → Faker-CcGjn5ZM.cjs} +40 -174
- package/dist/Faker-CcGjn5ZM.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{fakerGenerator-D7daHCh6.js → fakerGenerator-DDNsdbH2.js} +237 -94
- package/dist/fakerGenerator-DDNsdbH2.js.map +1 -0
- package/dist/{fakerGenerator-VJEVzLjc.cjs → fakerGenerator-DrwGWYwv.cjs} +240 -97
- package/dist/fakerGenerator-DrwGWYwv.cjs.map +1 -0
- package/dist/fakerGenerator-KKVr-CA2.d.ts +14 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +240 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -15
- package/dist/index.js +241 -70
- package/dist/index.js.map +1 -1
- package/dist/{printerFaker-CJiwzoto.d.ts → printerFaker-CMCJT3FB.d.ts} +68 -35
- package/package.json +12 -22
- package/src/components/Faker.tsx +51 -65
- package/src/generators/fakerGenerator.tsx +108 -72
- package/src/plugin.ts +27 -23
- package/src/printers/printerFaker.ts +102 -40
- package/src/resolvers/resolverFaker.ts +31 -39
- package/src/types.ts +40 -31
- package/src/utils.ts +7 -106
- package/dist/Faker-BgleOzVN.cjs.map +0 -1
- package/dist/Faker-fcQEB9i5.js.map +0 -1
- package/dist/fakerGenerator-C3Ho3BaI.d.ts +0 -9
- package/dist/fakerGenerator-D7daHCh6.js.map +0 -1
- package/dist/fakerGenerator-VJEVzLjc.cjs.map +0 -1
- package/extension.yaml +0 -364
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PluginDriver","path","pluginTsName","fakerGenerator"],"sources":["../../../internals/utils/src/casing.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","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { defineResolver, PluginDriver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\nfunction isValidStrictIdentifier(name: string): boolean {\n try {\n new Function(`\"use strict\"; const ${name} = 1;`)\n } catch {\n return false\n }\n\n return true\n}\n\n/**\n * Naming convention resolver for Faker plugin.\n *\n * Provides default naming helpers using camelCase. Prefixes invalid identifiers with `_`.\n *\n * @example\n * `resolverFaker.default('list pets', 'function') // → 'listPets'`\n */\nexport const resolverFaker = defineResolver<PluginFaker>((ctx) => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type === 'file' || isValidStrictIdentifier(resolvedName)) {\n return resolvedName\n }\n\n return `_${resolvedName}`\n },\n resolveName(name, type) {\n return ctx.default(name, type)\n },\n resolvePathName(name, type) {\n return ctx.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' ? '' : ctx.resolveName(name, 'file')}${extname}` as `${string}.${string}`\n const filePath = ctx.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: ctx.pluginName },\n sources: [],\n imports: [],\n exports: [],\n }\n },\n resolveParamName(node, param) {\n return ctx.resolveName(`${node.operationId} ${param.in} ${param.name}`)\n },\n resolveDataName(node) {\n return ctx.resolveName(`${node.operationId} Data`)\n },\n resolveResponseStatusName(node, statusCode) {\n return ctx.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseName(node) {\n return ctx.resolveName(`${node.operationId} Response`)\n },\n resolvePathParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveQueryParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveHeaderParamsName(node, param) {\n return ctx.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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AAM,OAAO;AAClC,UAAO,IAAI,iBAAiB,MAAM,MAAM;;EAE1C,wBAAwB,MAAM,OAAO;AACnC,UAAO,IAAI,iBAAiB,MAAM,MAAM;;EAE3C;EACD;;;;;;ACjFF,MAAa,kBAAkB;;;;;;;;;AAU/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,QACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,EAAE,EACX,aAAa,SACb,YAAY,iBAAiB,EAAE,EAC/B,iBAAiB,SACjB,cACA,SACA,UAAU,cACV,aAAa,oBACX;CAEJ,MAAM,cAAc,QACf;EACC,GAAG;EACH,MAAM,MAAM,OACR,MAAM,QACL,QAA2B;AAC1B,OAAI,MAAM,SAAS,OACjB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAGjC,UAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD,KAAA;AAEJ,QAAO;EACL,MAAM;EACN;EACA,cAAc,CAACC,gBAAAA,aAAa;EAC5B,OAAO,EACL,oBAAoB,KAAK;AACvB,OAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;IAAc,GAAG,cAAc;AACrF,OAAI,gBACF,KAAI,eAAe,gBAAgB;AAErC,OAAI,aAAaC,uBAAAA,eAAe;AAChC,QAAK,MAAM,aAAa,eACtB,KAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path","pluginTsName","fakerGenerator"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/reserved.ts","../../../internals/shared/src/group.ts","../src/resolvers/resolverFaker.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\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 return 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 .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example From camelCase\n * `snakeCase('helloWorld') // 'hello_world'`\n *\n * @example From mixed separators\n * `snakeCase('Hello-World') // 'hello_world'`\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): 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 From camelCase\n * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import { posix } from 'node:path'\nimport { camelCase } from './casing.ts'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\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\n/**\n * Returns `name` when it's a syntactically valid JavaScript variable name,\n * otherwise prefixes it with `_` so the result is a valid identifier.\n *\n * Useful for sanitizing OpenAPI schema names or operation IDs that start with\n * a digit (e.g. `409`, `504AccountCancel`) before using them as exported\n * variable, type, or function names.\n *\n * @example\n * ```ts\n * ensureValidVarName('409') // '_409'\n * ensureValidVarName('504AccountCancel') // '_504AccountCancel'\n * ensureValidVarName('Pet') // 'Pet'\n * ensureValidVarName('class') // '_class'\n * ```\n */\nexport function ensureValidVarName(name: string): string {\n if (!name || isValidVarName(name)) {\n return name\n }\n return `_${name}`\n}\n","import { camelCase } from '@internals/utils'\nimport type { Group } from '@kubb/core'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase, ensureValidVarName, toFilePath } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-faker`. Decides the names and file\n * paths for every generated mock factory. Functions and files are prefixed\n * with `create` so `Pet` becomes `createPet`.\n *\n * @example Resolve a factory name\n * ```ts\n * import { resolverFaker } from '@kubb/plugin-faker'\n *\n * resolverFaker.default('list pets', 'function') // 'createListPets'\n * ```\n */\nexport const resolverFaker = defineResolver<PluginFaker>(() => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n if (type === 'file') return toFilePath(name, (part) => camelCase(part, { prefix: 'create' }))\n return ensureValidVarName(camelCase(name, { prefix: 'create' }))\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 resolvedName = context.output.mode === 'file' ? '' : this.resolveName(name, 'file')\n const inputBaseName = `${resolvedName}${extname}` as `${string}.${string}`\n const filePath = this.resolvePath(\n {\n baseName: inputBaseName,\n tag,\n path: groupPath,\n },\n context,\n )\n const baseName = path.basename(filePath) as `${string}.${string}`\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 { createGroupConfig } from '@internals/shared'\nimport { definePlugin } 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 for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\n/**\n * Generates one mock-data factory per OpenAPI schema using Faker.js. Call\n * `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,\n * and local development without a running backend.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginFaker } from '@kubb/plugin-faker'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginFaker({\n * output: { path: './mocks' },\n * seed: [100],\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrel: { type: 'named' } },\n seed,\n locale = 'en',\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 = createGroupConfig(group)\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":";;;;;;;;;;;;;;;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAAyB;CAC9D,OAAO,KACJ,KAAK,CAAC,CACN,QAAQ,qBAAqB,OAAO,CAAC,CACrC,QAA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,CAAC,GAC9B,iBAAiB,SACjB,cACA,SACA,UAAU,cACV,aAAa,oBACX;CAEJ,MAAM,cAAc,kBAAkB,KAAK;CAE3C,OAAO;EACL,MAAM;EACN;EACA,cAAc,CAACC,gBAAAA,YAAY;EAC3B,OAAO,EACL,oBAAoB,KAAK;GACvB,IAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;GACF,CAAC;GACD,IAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;GAAa,IAAI,aAAa;GACpF,IAAI,iBACF,IAAI,eAAe,eAAe;GAEpC,IAAI,aAAaC,uBAAAA,cAAc;GAC/B,KAAK,MAAM,aAAa,gBACtB,IAAI,aAAa,SAAS;EAE9B,EACF;CACF;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,52 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import { a as Options, i as printerFaker, n as PrinterFakerNodes, o as PluginFaker, r as PrinterFakerOptions, s as ResolverFaker, t as PrinterFakerFactory } from "./printerFaker-
|
|
3
|
-
import { t as Faker } from "./Faker-
|
|
4
|
-
import { t as fakerGenerator } from "./fakerGenerator-
|
|
5
|
-
import * as _$_kubb_core0 from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
+
import { a as Options, i as printerFaker, n as PrinterFakerNodes, o as PluginFaker, r as PrinterFakerOptions, s as ResolverFaker, t as PrinterFakerFactory } from "./printerFaker-CMCJT3FB.js";
|
|
3
|
+
import { t as Faker } from "./Faker-A5UuxwJj.js";
|
|
4
|
+
import { t as fakerGenerator } from "./fakerGenerator-KKVr-CA2.js";
|
|
6
5
|
|
|
7
6
|
//#region src/plugin.d.ts
|
|
8
7
|
/**
|
|
9
|
-
* Canonical plugin name for `@kubb/plugin-faker
|
|
8
|
+
* Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
|
|
9
|
+
* cross-plugin dependency references.
|
|
10
10
|
*/
|
|
11
11
|
declare const pluginFakerName = "plugin-faker";
|
|
12
12
|
/**
|
|
13
|
-
* Generates
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* Generates one mock-data factory per OpenAPI schema using Faker.js. Call
|
|
14
|
+
* `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
|
|
15
|
+
* and local development without a running backend.
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
|
-
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineConfig } from 'kubb'
|
|
20
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
21
|
+
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* input: { path: './petStore.yaml' },
|
|
25
|
+
* output: { path: './src/gen' },
|
|
26
|
+
* plugins: [
|
|
27
|
+
* pluginTs(),
|
|
28
|
+
* pluginFaker({
|
|
29
|
+
* output: { path: './mocks' },
|
|
30
|
+
* seed: [100],
|
|
31
|
+
* }),
|
|
32
|
+
* ],
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
19
35
|
*/
|
|
20
|
-
declare const pluginFaker: (options?: Options | undefined) =>
|
|
36
|
+
declare const pluginFaker: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginFaker>;
|
|
21
37
|
//#endregion
|
|
22
38
|
//#region src/resolvers/resolverFaker.d.ts
|
|
23
39
|
/**
|
|
24
|
-
*
|
|
40
|
+
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|
|
41
|
+
* paths for every generated mock factory. Functions and files are prefixed
|
|
42
|
+
* with `create` so `Pet` becomes `createPet`.
|
|
25
43
|
*
|
|
26
|
-
*
|
|
44
|
+
* @example Resolve a factory name
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { resolverFaker } from '@kubb/plugin-faker'
|
|
27
47
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
48
|
+
* resolverFaker.default('list pets', 'function') // 'createListPets'
|
|
49
|
+
* ```
|
|
30
50
|
*/
|
|
31
51
|
declare const resolverFaker: ResolverFaker;
|
|
32
52
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./chunk
|
|
2
|
-
import { t as Faker } from "./Faker-
|
|
3
|
-
import { n as printerFaker, t as fakerGenerator } from "./fakerGenerator-
|
|
4
|
-
import
|
|
5
|
-
import { PluginDriver, definePlugin, defineResolver } from "@kubb/core";
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
|
+
import { t as Faker } from "./Faker-CHh0JtBG.js";
|
|
3
|
+
import { n as printerFaker, t as fakerGenerator } from "./fakerGenerator-DDNsdbH2.js";
|
|
4
|
+
import { definePlugin, defineResolver } from "@kubb/core";
|
|
6
5
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
//#region ../../internals/utils/src/casing.ts
|
|
9
9
|
/**
|
|
@@ -16,79 +16,236 @@ import { createHash } from "node:crypto";
|
|
|
16
16
|
function toCamelOrPascal(text, pascal) {
|
|
17
17
|
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
18
18
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
19
|
-
|
|
20
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
19
|
+
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
21
20
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
26
|
-
* Segments are joined with `/` to form a file path.
|
|
23
|
+
* Converts `text` to camelCase.
|
|
27
24
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
25
|
+
* @example Word boundaries
|
|
26
|
+
* `camelCase('hello-world') // 'helloWorld'`
|
|
27
|
+
*
|
|
28
|
+
* @example With a prefix
|
|
29
|
+
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
30
30
|
*/
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
31
|
+
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
32
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
34
33
|
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../../internals/utils/src/fs.ts
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
38
|
+
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
39
|
+
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
38
40
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
42
|
+
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
43
|
+
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
44
|
+
* absolute path, letting generated files escape the configured output directory.
|
|
45
|
+
*
|
|
46
|
+
* @example Nested path from a dotted name
|
|
47
|
+
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
48
|
+
*
|
|
49
|
+
* @example PascalCase the final segment
|
|
50
|
+
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
51
|
+
*
|
|
52
|
+
* @example Suffix applied to the final segment only
|
|
53
|
+
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
42
54
|
*/
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
suffix
|
|
47
|
-
} : {}));
|
|
48
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
55
|
+
function toFilePath(name, caseLast = camelCase) {
|
|
56
|
+
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
57
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
49
58
|
}
|
|
50
59
|
//#endregion
|
|
51
|
-
//#region src/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
61
|
+
/**
|
|
62
|
+
* JavaScript and Java reserved words.
|
|
63
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
64
|
+
*/
|
|
65
|
+
const reservedWords = new Set([
|
|
66
|
+
"abstract",
|
|
67
|
+
"arguments",
|
|
68
|
+
"boolean",
|
|
69
|
+
"break",
|
|
70
|
+
"byte",
|
|
71
|
+
"case",
|
|
72
|
+
"catch",
|
|
73
|
+
"char",
|
|
74
|
+
"class",
|
|
75
|
+
"const",
|
|
76
|
+
"continue",
|
|
77
|
+
"debugger",
|
|
78
|
+
"default",
|
|
79
|
+
"delete",
|
|
80
|
+
"do",
|
|
81
|
+
"double",
|
|
82
|
+
"else",
|
|
83
|
+
"enum",
|
|
84
|
+
"eval",
|
|
85
|
+
"export",
|
|
86
|
+
"extends",
|
|
87
|
+
"false",
|
|
88
|
+
"final",
|
|
89
|
+
"finally",
|
|
90
|
+
"float",
|
|
91
|
+
"for",
|
|
92
|
+
"function",
|
|
93
|
+
"goto",
|
|
94
|
+
"if",
|
|
95
|
+
"implements",
|
|
96
|
+
"import",
|
|
97
|
+
"in",
|
|
98
|
+
"instanceof",
|
|
99
|
+
"int",
|
|
100
|
+
"interface",
|
|
101
|
+
"let",
|
|
102
|
+
"long",
|
|
103
|
+
"native",
|
|
104
|
+
"new",
|
|
105
|
+
"null",
|
|
106
|
+
"package",
|
|
107
|
+
"private",
|
|
108
|
+
"protected",
|
|
109
|
+
"public",
|
|
110
|
+
"return",
|
|
111
|
+
"short",
|
|
112
|
+
"static",
|
|
113
|
+
"super",
|
|
114
|
+
"switch",
|
|
115
|
+
"synchronized",
|
|
116
|
+
"this",
|
|
117
|
+
"throw",
|
|
118
|
+
"throws",
|
|
119
|
+
"transient",
|
|
120
|
+
"true",
|
|
121
|
+
"try",
|
|
122
|
+
"typeof",
|
|
123
|
+
"var",
|
|
124
|
+
"void",
|
|
125
|
+
"volatile",
|
|
126
|
+
"while",
|
|
127
|
+
"with",
|
|
128
|
+
"yield",
|
|
129
|
+
"Array",
|
|
130
|
+
"Date",
|
|
131
|
+
"hasOwnProperty",
|
|
132
|
+
"Infinity",
|
|
133
|
+
"isFinite",
|
|
134
|
+
"isNaN",
|
|
135
|
+
"isPrototypeOf",
|
|
136
|
+
"length",
|
|
137
|
+
"Math",
|
|
138
|
+
"name",
|
|
139
|
+
"NaN",
|
|
140
|
+
"Number",
|
|
141
|
+
"Object",
|
|
142
|
+
"prototype",
|
|
143
|
+
"String",
|
|
144
|
+
"toString",
|
|
145
|
+
"undefined",
|
|
146
|
+
"valueOf"
|
|
147
|
+
]);
|
|
148
|
+
/**
|
|
149
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* isValidVarName('status') // true
|
|
154
|
+
* isValidVarName('class') // false (reserved word)
|
|
155
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
function isValidVarName(name) {
|
|
159
|
+
if (!name || reservedWords.has(name)) return false;
|
|
160
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
59
161
|
}
|
|
60
162
|
/**
|
|
61
|
-
*
|
|
163
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
164
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
62
165
|
*
|
|
63
|
-
*
|
|
166
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
167
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
168
|
+
* variable, type, or function names.
|
|
64
169
|
*
|
|
65
170
|
* @example
|
|
66
|
-
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* ensureValidVarName('409') // '_409'
|
|
173
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
174
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
175
|
+
* ensureValidVarName('class') // '_class'
|
|
176
|
+
* ```
|
|
67
177
|
*/
|
|
68
|
-
|
|
178
|
+
function ensureValidVarName(name) {
|
|
179
|
+
if (!name || isValidVarName(name)) return name;
|
|
180
|
+
return `_${name}`;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region ../../internals/shared/src/group.ts
|
|
184
|
+
/**
|
|
185
|
+
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
186
|
+
* shared default naming so every plugin groups output consistently:
|
|
187
|
+
*
|
|
188
|
+
* - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).
|
|
189
|
+
* - other groups use the camelCased group (`pet store` → `petStore`).
|
|
190
|
+
*
|
|
191
|
+
* A user-provided `group.name` always wins over the default namer, so callers stay in
|
|
192
|
+
* control of their output folders. Returns `null` when grouping is disabled, matching the
|
|
193
|
+
* per-plugin convention.
|
|
194
|
+
*
|
|
195
|
+
* @param group - The user-supplied group option, or `undefined` to disable grouping.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* createGroupConfig(group) // shared across every plugin
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
function createGroupConfig(group) {
|
|
203
|
+
if (!group) return null;
|
|
204
|
+
const defaultName = (ctx) => {
|
|
205
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
206
|
+
return camelCase(ctx.group);
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
...group,
|
|
210
|
+
name: group.name ? group.name : defaultName
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/resolvers/resolverFaker.ts
|
|
215
|
+
/**
|
|
216
|
+
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|
|
217
|
+
* paths for every generated mock factory. Functions and files are prefixed
|
|
218
|
+
* with `create` so `Pet` becomes `createPet`.
|
|
219
|
+
*
|
|
220
|
+
* @example Resolve a factory name
|
|
221
|
+
* ```ts
|
|
222
|
+
* import { resolverFaker } from '@kubb/plugin-faker'
|
|
223
|
+
*
|
|
224
|
+
* resolverFaker.default('list pets', 'function') // 'createListPets'
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
const resolverFaker = defineResolver(() => {
|
|
69
228
|
return {
|
|
70
229
|
name: "default",
|
|
71
230
|
pluginName: "plugin-faker",
|
|
72
231
|
default(name, type) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return `_${resolvedName}`;
|
|
232
|
+
if (type === "file") return toFilePath(name, (part) => camelCase(part, { prefix: "create" }));
|
|
233
|
+
return ensureValidVarName(camelCase(name, { prefix: "create" }));
|
|
76
234
|
},
|
|
77
235
|
resolveName(name, type) {
|
|
78
|
-
return
|
|
236
|
+
return this.default(name, type);
|
|
79
237
|
},
|
|
80
238
|
resolvePathName(name, type) {
|
|
81
|
-
return
|
|
239
|
+
return this.default(name, type);
|
|
82
240
|
},
|
|
83
241
|
resolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
baseName,
|
|
88
|
-
pathMode,
|
|
242
|
+
const inputBaseName = `${context.output.mode === "file" ? "" : this.resolveName(name, "file")}${extname}`;
|
|
243
|
+
const filePath = this.resolvePath({
|
|
244
|
+
baseName: inputBaseName,
|
|
89
245
|
tag,
|
|
90
246
|
path: groupPath
|
|
91
247
|
}, context);
|
|
248
|
+
const baseName = path.basename(filePath);
|
|
92
249
|
return {
|
|
93
250
|
kind: "File",
|
|
94
251
|
id: createHash("sha256").update(filePath).digest("hex"),
|
|
@@ -96,61 +253,75 @@ const resolverFaker = defineResolver((ctx) => {
|
|
|
96
253
|
path: filePath,
|
|
97
254
|
baseName,
|
|
98
255
|
extname,
|
|
99
|
-
meta: { pluginName:
|
|
256
|
+
meta: { pluginName: this.pluginName },
|
|
100
257
|
sources: [],
|
|
101
258
|
imports: [],
|
|
102
259
|
exports: []
|
|
103
260
|
};
|
|
104
261
|
},
|
|
105
262
|
resolveParamName(node, param) {
|
|
106
|
-
return
|
|
263
|
+
return this.resolveName(`${node.operationId} ${param.in} ${param.name}`);
|
|
107
264
|
},
|
|
108
265
|
resolveDataName(node) {
|
|
109
|
-
return
|
|
266
|
+
return this.resolveName(`${node.operationId} Data`);
|
|
110
267
|
},
|
|
111
268
|
resolveResponseStatusName(node, statusCode) {
|
|
112
|
-
return
|
|
269
|
+
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
113
270
|
},
|
|
114
271
|
resolveResponseName(node) {
|
|
115
|
-
return
|
|
272
|
+
return this.resolveName(`${node.operationId} Response`);
|
|
273
|
+
},
|
|
274
|
+
resolveResponsesName(node) {
|
|
275
|
+
return this.resolveName(`${node.operationId} Responses`);
|
|
116
276
|
},
|
|
117
277
|
resolvePathParamsName(node, param) {
|
|
118
|
-
return
|
|
278
|
+
return this.resolveParamName(node, param);
|
|
119
279
|
},
|
|
120
280
|
resolveQueryParamsName(node, param) {
|
|
121
|
-
return
|
|
281
|
+
return this.resolveParamName(node, param);
|
|
122
282
|
},
|
|
123
283
|
resolveHeaderParamsName(node, param) {
|
|
124
|
-
return
|
|
284
|
+
return this.resolveParamName(node, param);
|
|
125
285
|
}
|
|
126
286
|
};
|
|
127
287
|
});
|
|
128
288
|
//#endregion
|
|
129
289
|
//#region src/plugin.ts
|
|
130
290
|
/**
|
|
131
|
-
* Canonical plugin name for `@kubb/plugin-faker
|
|
291
|
+
* Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
|
|
292
|
+
* cross-plugin dependency references.
|
|
132
293
|
*/
|
|
133
294
|
const pluginFakerName = "plugin-faker";
|
|
134
295
|
/**
|
|
135
|
-
* Generates
|
|
136
|
-
*
|
|
137
|
-
*
|
|
296
|
+
* Generates one mock-data factory per OpenAPI schema using Faker.js. Call
|
|
297
|
+
* `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
|
|
298
|
+
* and local development without a running backend.
|
|
138
299
|
*
|
|
139
300
|
* @example
|
|
140
|
-
*
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { defineConfig } from 'kubb'
|
|
303
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
304
|
+
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
305
|
+
*
|
|
306
|
+
* export default defineConfig({
|
|
307
|
+
* input: { path: './petStore.yaml' },
|
|
308
|
+
* output: { path: './src/gen' },
|
|
309
|
+
* plugins: [
|
|
310
|
+
* pluginTs(),
|
|
311
|
+
* pluginFaker({
|
|
312
|
+
* output: { path: './mocks' },
|
|
313
|
+
* seed: [100],
|
|
314
|
+
* }),
|
|
315
|
+
* ],
|
|
316
|
+
* })
|
|
317
|
+
* ```
|
|
141
318
|
*/
|
|
142
319
|
const pluginFaker = definePlugin((options) => {
|
|
143
320
|
const { output = {
|
|
144
321
|
path: "mocks",
|
|
145
|
-
|
|
146
|
-
}, seed, locale, group, exclude = [], include, override = [], mapper = {}, dateParser = "faker", generators: userGenerators = [], regexGenerator = "faker", paramsCasing, printer, resolver: userResolver, transformer: userTransformer } = options;
|
|
147
|
-
const groupConfig = group
|
|
148
|
-
...group,
|
|
149
|
-
name: group.name ? group.name : (ctx) => {
|
|
150
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
151
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
152
|
-
}
|
|
153
|
-
} : void 0;
|
|
322
|
+
barrel: { type: "named" }
|
|
323
|
+
}, seed, locale = "en", group, exclude = [], include, override = [], mapper = {}, dateParser = "faker", generators: userGenerators = [], regexGenerator = "faker", paramsCasing, printer, resolver: userResolver, transformer: userTransformer } = options;
|
|
324
|
+
const groupConfig = createGroupConfig(group);
|
|
154
325
|
return {
|
|
155
326
|
name: pluginFakerName,
|
|
156
327
|
options,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.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","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { defineResolver, PluginDriver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\nfunction isValidStrictIdentifier(name: string): boolean {\n try {\n new Function(`\"use strict\"; const ${name} = 1;`)\n } catch {\n return false\n }\n\n return true\n}\n\n/**\n * Naming convention resolver for Faker plugin.\n *\n * Provides default naming helpers using camelCase. Prefixes invalid identifiers with `_`.\n *\n * @example\n * `resolverFaker.default('list pets', 'function') // → 'listPets'`\n */\nexport const resolverFaker = defineResolver<PluginFaker>((ctx) => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type === 'file' || isValidStrictIdentifier(resolvedName)) {\n return resolvedName\n }\n\n return `_${resolvedName}`\n },\n resolveName(name, type) {\n return ctx.default(name, type)\n },\n resolvePathName(name, type) {\n return ctx.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' ? '' : ctx.resolveName(name, 'file')}${extname}` as `${string}.${string}`\n const filePath = ctx.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: ctx.pluginName },\n sources: [],\n imports: [],\n exports: [],\n }\n },\n resolveParamName(node, param) {\n return ctx.resolveName(`${node.operationId} ${param.in} ${param.name}`)\n },\n resolveDataName(node) {\n return ctx.resolveName(`${node.operationId} Data`)\n },\n resolveResponseStatusName(node, statusCode) {\n return ctx.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseName(node) {\n return ctx.resolveName(`${node.operationId} Response`)\n },\n resolvePathParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveQueryParamsName(node, param) {\n return ctx.resolveParamName(node, param)\n },\n resolveHeaderParamsName(node, param) {\n return ctx.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;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;;;;AAWjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,iBAAiB;AAC1C,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;AC9D9D,SAAS,wBAAwB,MAAuB;AACtD,KAAI;AACF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M;AACxB,UAAO,IAAI,YAAY,GAAG,KAAK,YAAY,WAAW;;EAExD,sBAAsB,MAAM,OAAO;AACjC,UAAO,IAAI,iBAAiB,MAAM,MAAM;;EAE1C,uBAAuB,MAAM,OAAO;AAClC,UAAO,IAAI,iBAAiB,MAAM,MAAM;;EAE1C,wBAAwB,MAAM,OAAO;AACnC,UAAO,IAAI,iBAAiB,MAAM,MAAM;;EAE3C;EACD;;;;;;ACjFF,MAAa,kBAAkB;;;;;;;;;AAU/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,QACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,SAAS,EAAE,EACX,aAAa,SACb,YAAY,iBAAiB,EAAE,EAC/B,iBAAiB,SACjB,cACA,SACA,UAAU,cACV,aAAa,oBACX;CAEJ,MAAM,cAAc,QACf;EACC,GAAG;EACH,MAAM,MAAM,OACR,MAAM,QACL,QAA2B;AAC1B,OAAI,MAAM,SAAS,OACjB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAGjC,UAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD,KAAA;AAEJ,QAAO;EACL,MAAM;EACN;EACA,cAAc,CAAC,aAAa;EAC5B,OAAO,EACL,oBAAoB,KAAK;AACvB,OAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,OAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;IAAc,GAAG,cAAc;AACrF,OAAI,gBACF,KAAI,eAAe,gBAAgB;AAErC,OAAI,aAAa,eAAe;AAChC,QAAK,MAAM,aAAa,eACtB,KAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/fs.ts","../../../internals/utils/src/reserved.ts","../../../internals/shared/src/group.ts","../src/resolvers/resolverFaker.ts","../src/plugin.ts"],"sourcesContent":["type Options = {\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 return 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 .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example From camelCase\n * `snakeCase('helloWorld') // 'hello_world'`\n *\n * @example From mixed separators\n * `snakeCase('Hello-World') // 'hello_world'`\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): 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 From camelCase\n * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import { posix } from 'node:path'\nimport { camelCase } from './casing.ts'\n\nfunction toSlash(p: string): string {\n if (p.startsWith('\\\\\\\\?\\\\')) return p\n return p.replaceAll('\\\\', '/')\n}\n\n/**\n * Returns the relative path from `rootDir` to `filePath`, always using forward slashes\n * and prefixed with `./` when not already traversing upward.\n *\n * @example\n * ```ts\n * getRelativePath('/src/components', '/src/components/Button.tsx') // './Button.tsx'\n * getRelativePath('/src/components', '/src/utils/helpers.ts') // '../utils/helpers.ts'\n * ```\n */\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = posix.relative(toSlash(rootDir), toSlash(filePath))\n\n return relativePath.startsWith('../') ? relativePath : `./${relativePath}`\n}\n\n/**\n * Builds a nested file path from a dotted name. Splits on dots that precede a letter\n * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases\n * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.\n *\n * Empty segments are dropped before joining. They arise when the name starts with a dot\n * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to\n * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an\n * absolute path, letting generated files escape the configured output directory.\n *\n * @example Nested path from a dotted name\n * `toFilePath('pet.petId') // 'pet/petId'`\n *\n * @example PascalCase the final segment\n * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`\n *\n * @example Suffix applied to the final segment only\n * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`\n */\nexport function toFilePath(name: string, caseLast: (part: string) => string = camelCase): string {\n const parts = name.split(/\\.(?=[a-zA-Z])/)\n return parts\n .map((part, i) => (i === parts.length - 1 ? caseLast(part) : camelCase(part)))\n .filter(Boolean)\n .join('/')\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\n/**\n * Returns `name` when it's a syntactically valid JavaScript variable name,\n * otherwise prefixes it with `_` so the result is a valid identifier.\n *\n * Useful for sanitizing OpenAPI schema names or operation IDs that start with\n * a digit (e.g. `409`, `504AccountCancel`) before using them as exported\n * variable, type, or function names.\n *\n * @example\n * ```ts\n * ensureValidVarName('409') // '_409'\n * ensureValidVarName('504AccountCancel') // '_504AccountCancel'\n * ensureValidVarName('Pet') // 'Pet'\n * ensureValidVarName('class') // '_class'\n * ```\n */\nexport function ensureValidVarName(name: string): string {\n if (!name || isValidVarName(name)) {\n return name\n }\n return `_${name}`\n}\n","import { camelCase } from '@internals/utils'\nimport type { Group } from '@kubb/core'\n\n/**\n * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the\n * shared default naming so every plugin groups output consistently:\n *\n * - `path` groups use the second path segment (`/pet/findByStatus` → `pet`).\n * - other groups use the camelCased group (`pet store` → `petStore`).\n *\n * A user-provided `group.name` always wins over the default namer, so callers stay in\n * control of their output folders. Returns `null` when grouping is disabled, matching the\n * per-plugin convention.\n *\n * @param group - The user-supplied group option, or `undefined` to disable grouping.\n *\n * @example\n * ```ts\n * createGroupConfig(group) // shared across every plugin\n * ```\n */\nexport function createGroupConfig(group: Group | undefined): Group | null {\n if (!group) {\n return null\n }\n\n const defaultName = (ctx: { group: string }): string => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n\n return camelCase(ctx.group)\n }\n\n return {\n ...group,\n name: group.name ? group.name : defaultName,\n } satisfies Group\n}\n","import { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase, ensureValidVarName, toFilePath } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginFaker } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-faker`. Decides the names and file\n * paths for every generated mock factory. Functions and files are prefixed\n * with `create` so `Pet` becomes `createPet`.\n *\n * @example Resolve a factory name\n * ```ts\n * import { resolverFaker } from '@kubb/plugin-faker'\n *\n * resolverFaker.default('list pets', 'function') // 'createListPets'\n * ```\n */\nexport const resolverFaker = defineResolver<PluginFaker>(() => {\n return {\n name: 'default',\n pluginName: 'plugin-faker',\n default(name, type) {\n if (type === 'file') return toFilePath(name, (part) => camelCase(part, { prefix: 'create' }))\n return ensureValidVarName(camelCase(name, { prefix: 'create' }))\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 resolvedName = context.output.mode === 'file' ? '' : this.resolveName(name, 'file')\n const inputBaseName = `${resolvedName}${extname}` as `${string}.${string}`\n const filePath = this.resolvePath(\n {\n baseName: inputBaseName,\n tag,\n path: groupPath,\n },\n context,\n )\n const baseName = path.basename(filePath) as `${string}.${string}`\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 { createGroupConfig } from '@internals/shared'\nimport { definePlugin } 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 for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\n/**\n * Generates one mock-data factory per OpenAPI schema using Faker.js. Call\n * `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,\n * and local development without a running backend.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginFaker } from '@kubb/plugin-faker'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginFaker({\n * output: { path: './mocks' },\n * seed: [100],\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrel: { type: 'named' } },\n seed,\n locale = 'en',\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 = createGroupConfig(group)\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":";;;;;;;;;;;;;;;AAkBA,SAAS,gBAAgB,MAAc,QAA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