@kubb/plugin-faker 5.0.0-beta.3 → 5.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -5
- package/dist/{Faker-CdyPfOPg.d.ts → Faker-BaLJxPyl.d.ts} +2 -2
- package/dist/{Faker-fcQEB9i5.js → Faker-CXZVQQ7e.js} +36 -99
- package/dist/Faker-CXZVQQ7e.js.map +1 -0
- package/dist/{Faker-BgleOzVN.cjs → Faker-CkJccVKI.cjs} +35 -122
- package/dist/Faker-CkJccVKI.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-BvMBDgwp.js} +126 -32
- package/dist/fakerGenerator-BvMBDgwp.js.map +1 -0
- package/dist/fakerGenerator-DSvAJTq3.d.ts +15 -0
- package/dist/{fakerGenerator-VJEVzLjc.cjs → fakerGenerator-DhNV9xBw.cjs} +127 -33
- package/dist/fakerGenerator-DhNV9xBw.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +177 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -12
- package/dist/index.js +178 -37
- package/dist/index.js.map +1 -1
- package/dist/{printerFaker-CJiwzoto.d.ts → printerFaker-Bhwq62d1.d.ts} +63 -26
- package/extension.yaml +817 -0
- package/package.json +8 -13
- package/src/components/Faker.tsx +44 -63
- package/src/generators/fakerGenerator.tsx +35 -35
- package/src/plugin.ts +23 -6
- package/src/printers/printerFaker.ts +80 -16
- package/src/resolvers/resolverFaker.ts +29 -37
- package/src/types.ts +36 -23
- package/src/utils.ts +6 -105
- 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/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
2
|
+
import { n as printerFaker, t as fakerGenerator } from "./fakerGenerator-BvMBDgwp.js";
|
|
3
|
+
import { t as Faker } from "./Faker-CXZVQQ7e.js";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { KubbDriver, definePlugin, defineResolver } from "@kubb/core";
|
|
6
6
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
//#region ../../internals/utils/src/casing.ts
|
|
@@ -48,42 +48,163 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
48
48
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
|
-
//#region src/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|
|
59
152
|
}
|
|
60
153
|
/**
|
|
61
|
-
*
|
|
154
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
155
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
62
156
|
*
|
|
63
|
-
*
|
|
157
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
158
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
159
|
+
* variable, type, or function names.
|
|
64
160
|
*
|
|
65
161
|
* @example
|
|
66
|
-
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* ensureValidVarName('409') // '_409'
|
|
164
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
165
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
166
|
+
* ensureValidVarName('class') // '_class'
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
function ensureValidVarName(name) {
|
|
170
|
+
if (!name || isValidVarName(name)) return name;
|
|
171
|
+
return `_${name}`;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/resolvers/resolverFaker.ts
|
|
175
|
+
/**
|
|
176
|
+
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|
|
177
|
+
* paths for every generated mock factory. Functions and files are prefixed
|
|
178
|
+
* with `create` so `Pet` becomes `createPet`.
|
|
179
|
+
*
|
|
180
|
+
* @example Resolve a factory name
|
|
181
|
+
* ```ts
|
|
182
|
+
* import { resolverFaker } from '@kubb/plugin-faker'
|
|
183
|
+
*
|
|
184
|
+
* resolverFaker.default('list pets', 'function') // 'createListPets'
|
|
185
|
+
* ```
|
|
67
186
|
*/
|
|
68
|
-
const resolverFaker = defineResolver((
|
|
187
|
+
const resolverFaker = defineResolver(() => {
|
|
69
188
|
return {
|
|
70
189
|
name: "default",
|
|
71
190
|
pluginName: "plugin-faker",
|
|
72
191
|
default(name, type) {
|
|
73
|
-
const resolvedName = camelCase(name, {
|
|
74
|
-
|
|
75
|
-
|
|
192
|
+
const resolvedName = camelCase(name, {
|
|
193
|
+
isFile: type === "file",
|
|
194
|
+
prefix: "create"
|
|
195
|
+
});
|
|
196
|
+
return type === "file" ? resolvedName : ensureValidVarName(resolvedName);
|
|
76
197
|
},
|
|
77
198
|
resolveName(name, type) {
|
|
78
|
-
return
|
|
199
|
+
return this.default(name, type);
|
|
79
200
|
},
|
|
80
201
|
resolvePathName(name, type) {
|
|
81
|
-
return
|
|
202
|
+
return this.default(name, type);
|
|
82
203
|
},
|
|
83
204
|
resolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
84
|
-
const pathMode =
|
|
85
|
-
const baseName = `${pathMode === "single" ? "" :
|
|
86
|
-
const filePath =
|
|
205
|
+
const pathMode = KubbDriver.getMode(path.resolve(context.root, context.output.path));
|
|
206
|
+
const baseName = `${pathMode === "single" ? "" : this.resolveName(name, "file")}${extname}`;
|
|
207
|
+
const filePath = this.resolvePath({
|
|
87
208
|
baseName,
|
|
88
209
|
pathMode,
|
|
89
210
|
tag,
|
|
@@ -96,48 +217,68 @@ const resolverFaker = defineResolver((ctx) => {
|
|
|
96
217
|
path: filePath,
|
|
97
218
|
baseName,
|
|
98
219
|
extname,
|
|
99
|
-
meta: { pluginName:
|
|
220
|
+
meta: { pluginName: this.pluginName },
|
|
100
221
|
sources: [],
|
|
101
222
|
imports: [],
|
|
102
223
|
exports: []
|
|
103
224
|
};
|
|
104
225
|
},
|
|
105
226
|
resolveParamName(node, param) {
|
|
106
|
-
return
|
|
227
|
+
return this.resolveName(`${node.operationId} ${param.in} ${param.name}`);
|
|
107
228
|
},
|
|
108
229
|
resolveDataName(node) {
|
|
109
|
-
return
|
|
230
|
+
return this.resolveName(`${node.operationId} Data`);
|
|
110
231
|
},
|
|
111
232
|
resolveResponseStatusName(node, statusCode) {
|
|
112
|
-
return
|
|
233
|
+
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
113
234
|
},
|
|
114
235
|
resolveResponseName(node) {
|
|
115
|
-
return
|
|
236
|
+
return this.resolveName(`${node.operationId} Response`);
|
|
237
|
+
},
|
|
238
|
+
resolveResponsesName(node) {
|
|
239
|
+
return this.resolveName(`${node.operationId} Responses`);
|
|
116
240
|
},
|
|
117
241
|
resolvePathParamsName(node, param) {
|
|
118
|
-
return
|
|
242
|
+
return this.resolveParamName(node, param);
|
|
119
243
|
},
|
|
120
244
|
resolveQueryParamsName(node, param) {
|
|
121
|
-
return
|
|
245
|
+
return this.resolveParamName(node, param);
|
|
122
246
|
},
|
|
123
247
|
resolveHeaderParamsName(node, param) {
|
|
124
|
-
return
|
|
248
|
+
return this.resolveParamName(node, param);
|
|
125
249
|
}
|
|
126
250
|
};
|
|
127
251
|
});
|
|
128
252
|
//#endregion
|
|
129
253
|
//#region src/plugin.ts
|
|
130
254
|
/**
|
|
131
|
-
* Canonical plugin name for `@kubb/plugin-faker
|
|
255
|
+
* Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
|
|
256
|
+
* cross-plugin dependency references.
|
|
132
257
|
*/
|
|
133
258
|
const pluginFakerName = "plugin-faker";
|
|
134
259
|
/**
|
|
135
|
-
* Generates
|
|
136
|
-
*
|
|
137
|
-
*
|
|
260
|
+
* Generates one mock-data factory per OpenAPI schema using Faker.js. Call
|
|
261
|
+
* `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
|
|
262
|
+
* and local development without a running backend.
|
|
138
263
|
*
|
|
139
264
|
* @example
|
|
140
|
-
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { defineConfig } from 'kubb'
|
|
267
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
268
|
+
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
269
|
+
*
|
|
270
|
+
* export default defineConfig({
|
|
271
|
+
* input: { path: './petStore.yaml' },
|
|
272
|
+
* output: { path: './src/gen' },
|
|
273
|
+
* plugins: [
|
|
274
|
+
* pluginTs(),
|
|
275
|
+
* pluginFaker({
|
|
276
|
+
* output: { path: './mocks' },
|
|
277
|
+
* seed: [100],
|
|
278
|
+
* }),
|
|
279
|
+
* ],
|
|
280
|
+
* })
|
|
281
|
+
* ```
|
|
141
282
|
*/
|
|
142
283
|
const pluginFaker = definePlugin((options) => {
|
|
143
284
|
const { output = {
|
|
@@ -150,7 +291,7 @@ const pluginFaker = definePlugin((options) => {
|
|
|
150
291
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
151
292
|
return `${camelCase(ctx.group)}Controller`;
|
|
152
293
|
}
|
|
153
|
-
} :
|
|
294
|
+
} : null;
|
|
154
295
|
return {
|
|
155
296
|
name: pluginFakerName,
|
|
156
297
|
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,KA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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/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\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 { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { camelCase, ensureValidVarName } from '@internals/utils'\nimport { defineResolver, KubbDriver } 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 const resolvedName = camelCase(name, { isFile: type === 'file', prefix: 'create' })\n return type === 'file' ? resolvedName : ensureValidVarName(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 = KubbDriver.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 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', 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 : null\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,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;EAEhB,IADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,EACjD,OAAO;EACrB,IAAI,MAAM,KAAK,CAAC,QAAQ,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;EAC3E,OAAO,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;CAC1C,OAAO,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;CAClG,IAAI,QACF,OAAO,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;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;GAC1B,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;GAGjC,OAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD;CAEJ,OAAO;EACL,MAAM;EACN;EACA,cAAc,CAAC,aAAa;EAC5B,OAAO,EACL,oBAAoB,KAAK;GACvB,IAAI,WAAW;IACb;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;GACF,IAAI,YAAY,eAAe;IAAE,GAAG;IAAe,GAAG;IAAc,GAAG,cAAc;GACrF,IAAI,iBACF,IAAI,eAAe,gBAAgB;GAErC,IAAI,aAAa,eAAe;GAChC,KAAK,MAAM,aAAa,gBACtB,IAAI,aAAa,UAAU;KAGhC;EACF;EACD"}
|
|
@@ -41,6 +41,13 @@ type ResolverFaker = Resolver & ast.OperationParamsResolver & {
|
|
|
41
41
|
* `resolver.resolveResponseName(node) // -> 'listPetsResponse'`
|
|
42
42
|
*/
|
|
43
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;
|
|
44
51
|
/**
|
|
45
52
|
* Resolves the faker function name for path parameters.
|
|
46
53
|
*
|
|
@@ -65,80 +72,86 @@ type ResolverFaker = Resolver & ast.OperationParamsResolver & {
|
|
|
65
72
|
};
|
|
66
73
|
type Options = {
|
|
67
74
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
75
|
+
* Where the generated mock factories are written and how they are exported.
|
|
76
|
+
*
|
|
77
|
+
* @default { path: 'mocks', barrel: { type: 'named' } }
|
|
70
78
|
*/
|
|
71
79
|
output?: Output;
|
|
72
80
|
/**
|
|
73
|
-
*
|
|
81
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
74
82
|
*/
|
|
75
83
|
group?: Group;
|
|
76
84
|
/**
|
|
77
|
-
*
|
|
85
|
+
* Skip operations matching at least one entry in the list.
|
|
78
86
|
*/
|
|
79
87
|
exclude?: Array<Exclude>;
|
|
80
88
|
/**
|
|
81
|
-
*
|
|
89
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
82
90
|
*/
|
|
83
91
|
include?: Array<Include>;
|
|
84
92
|
/**
|
|
85
|
-
*
|
|
93
|
+
* Apply a different options object to operations matching a pattern.
|
|
86
94
|
*/
|
|
87
95
|
override?: Array<Override<ResolvedOptions>>;
|
|
88
96
|
/**
|
|
89
|
-
*
|
|
97
|
+
* Library used to format string-represented date, time, and datetime fields.
|
|
98
|
+
* Any library exporting a default function works; Kubb adds the import for you.
|
|
90
99
|
*
|
|
91
100
|
* @default 'faker'
|
|
92
101
|
*/
|
|
93
102
|
dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {});
|
|
94
103
|
/**
|
|
95
|
-
*
|
|
104
|
+
* Library used to generate strings that satisfy a regex `pattern` keyword.
|
|
105
|
+
* - `'faker'` uses `faker.helpers.fromRegExp`. No extra dependency.
|
|
106
|
+
* - `'randexp'` uses the `randexp` package. Supports a wider regex grammar.
|
|
96
107
|
*
|
|
97
108
|
* @default 'faker'
|
|
98
109
|
*/
|
|
99
110
|
regexGenerator?: 'faker' | 'randexp';
|
|
100
111
|
/**
|
|
101
|
-
*
|
|
112
|
+
* Map a schema name to a custom Faker expression. Use this when the schema name
|
|
113
|
+
* does not give Faker enough context (`'email'`, `'avatarUrl'`, `'phoneNumber'`).
|
|
102
114
|
*/
|
|
103
115
|
mapper?: Record<string, string>;
|
|
104
116
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* and phone numbers reflect the target region.
|
|
117
|
+
* Faker locale code. Switches the named import to `fakerXX` from `@faker-js/faker`
|
|
118
|
+
* so names, addresses, and phone numbers reflect the target region.
|
|
108
119
|
*
|
|
109
120
|
* @default 'en'
|
|
110
|
-
*
|
|
111
121
|
* @example German
|
|
112
122
|
* `locale: 'de'`
|
|
113
|
-
*
|
|
114
123
|
* @example Austrian German
|
|
115
124
|
* `locale: 'de_AT'`
|
|
116
|
-
*
|
|
117
125
|
* @see https://fakerjs.dev/api/localization.html
|
|
118
126
|
*/
|
|
119
127
|
locale?: string;
|
|
120
128
|
/**
|
|
121
|
-
*
|
|
129
|
+
* Value passed to `faker.seed(...)`. Set this for deterministic mock output,
|
|
130
|
+
* which is useful for snapshot tests.
|
|
122
131
|
*/
|
|
123
|
-
seed?: number | number
|
|
132
|
+
seed?: number | Array<number>;
|
|
124
133
|
/**
|
|
125
|
-
*
|
|
134
|
+
* Rename properties inside path/query/header mocks. Body mocks are unaffected.
|
|
135
|
+
*
|
|
136
|
+
* @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
|
|
126
137
|
*/
|
|
127
138
|
paramsCasing?: 'camelcase';
|
|
128
139
|
/**
|
|
129
|
-
*
|
|
140
|
+
* Custom generators that run alongside the built-in Faker generators.
|
|
130
141
|
*/
|
|
131
142
|
generators?: Array<Generator<PluginFaker>>;
|
|
132
143
|
/**
|
|
133
|
-
* Override naming
|
|
144
|
+
* Override the naming of generated factory helpers. Common use: append `Mock` or
|
|
145
|
+
* `Factory` so helpers do not clash with imported types.
|
|
134
146
|
*/
|
|
135
147
|
resolver?: Partial<ResolverFaker> & ThisType<ResolverFaker>;
|
|
136
148
|
/**
|
|
137
|
-
* AST visitor to
|
|
149
|
+
* AST visitor applied to schema and operation nodes before printing.
|
|
138
150
|
*/
|
|
139
151
|
transformer?: ast.Visitor;
|
|
140
152
|
/**
|
|
141
|
-
*
|
|
153
|
+
* Replace the Faker handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
154
|
+
* Each handler returns the Faker expression as a string.
|
|
142
155
|
*/
|
|
143
156
|
printer?: {
|
|
144
157
|
nodes?: PrinterFakerNodes;
|
|
@@ -146,7 +159,7 @@ type Options = {
|
|
|
146
159
|
};
|
|
147
160
|
type ResolvedOptions = {
|
|
148
161
|
output: Output;
|
|
149
|
-
group: Group |
|
|
162
|
+
group: Group | null;
|
|
150
163
|
exclude: NonNullable<Options['exclude']>;
|
|
151
164
|
include: Options['include'];
|
|
152
165
|
override: NonNullable<Options['override']>;
|
|
@@ -169,11 +182,29 @@ declare global {
|
|
|
169
182
|
//#endregion
|
|
170
183
|
//#region src/printers/printerFaker.d.ts
|
|
171
184
|
/**
|
|
172
|
-
* Partial
|
|
185
|
+
* Partial map of node-type overrides for the Faker printer. Each key is a
|
|
186
|
+
* `SchemaType` (`'string'`, `'date'`, ...) and each handler returns the
|
|
187
|
+
* Faker expression for that schema as a string. Use `this.transform` to
|
|
188
|
+
* recurse into nested schema nodes and `this.options` to read printer options.
|
|
189
|
+
*
|
|
190
|
+
* @example Override the integer handler
|
|
191
|
+
* ```ts
|
|
192
|
+
* pluginFaker({
|
|
193
|
+
* printer: {
|
|
194
|
+
* nodes: {
|
|
195
|
+
* integer() {
|
|
196
|
+
* return 'faker.number.float()'
|
|
197
|
+
* },
|
|
198
|
+
* },
|
|
199
|
+
* },
|
|
200
|
+
* })
|
|
201
|
+
* ```
|
|
173
202
|
*/
|
|
174
203
|
type PrinterFakerNodes = ast.PrinterPartial<string, PrinterFakerOptions>;
|
|
175
204
|
/**
|
|
176
|
-
*
|
|
205
|
+
* Options passed to the Faker printer at instantiation: the parser library
|
|
206
|
+
* for date strings, the regex generator, the user-supplied schema-name
|
|
207
|
+
* mapper, and the resolver used to compute identifiers.
|
|
177
208
|
*/
|
|
178
209
|
type PrinterFakerOptions = {
|
|
179
210
|
dateParser?: PluginFaker['resolvedOptions']['dateParser'];
|
|
@@ -183,6 +214,12 @@ type PrinterFakerOptions = {
|
|
|
183
214
|
typeName?: string;
|
|
184
215
|
schemaName?: string;
|
|
185
216
|
nestedInObject?: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Set while printing the members of a union (`oneOf`). Object properties then index their
|
|
219
|
+
* type as `(NonNullable<T> & Record<K, unknown>)[K]` instead of `NonNullable<T>[K]`, so a key
|
|
220
|
+
* carried by only some branches stays valid (a plain index would be a TS2339).
|
|
221
|
+
*/
|
|
222
|
+
nestedInUnion?: boolean;
|
|
186
223
|
nodes?: PrinterFakerNodes;
|
|
187
224
|
/**
|
|
188
225
|
* Names of schemas that participate in a circular dependency chain.
|
|
@@ -203,4 +240,4 @@ type PrinterFakerFactory = ast.PrinterFactoryOptions<'faker', PrinterFakerOption
|
|
|
203
240
|
declare const printerFaker: (options: PrinterFakerOptions) => ast.Printer<PrinterFakerFactory>;
|
|
204
241
|
//#endregion
|
|
205
242
|
export { Options as a, printerFaker as i, PrinterFakerNodes as n, PluginFaker as o, PrinterFakerOptions as r, ResolverFaker as s, PrinterFakerFactory as t };
|
|
206
|
-
//# sourceMappingURL=printerFaker-
|
|
243
|
+
//# sourceMappingURL=printerFaker-Bhwq62d1.d.ts.map
|