@kubb/plugin-faker 5.0.0-beta.10 → 5.0.0-beta.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,32 +1,293 @@
1
- import { t as __name } from "./chunk--u3MIqq1.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-W0pLunAj.js";
3
- import { t as Faker } from "./Faker-BMgoFj8b.js";
4
- import { t as fakerGenerator } from "./fakerGenerator-B-QnVz9o.js";
5
- import * as _$_kubb_core0 from "@kubb/core";
6
-
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
3
+ import { KubbReactNode } from "kubb/jsx";
4
+ //#region src/types.d.ts
5
+ /**
6
+ * Resolver for Faker that provides naming methods for mock functions.
7
+ *
8
+ * The top-level `name` and `file` apply the plugin's `create` prefix. Composite
9
+ * operation naming is grouped into the `param` and `response` namespaces.
10
+ */
11
+ type ResolverFaker = Resolver & {
12
+ /**
13
+ * Naming for operation parameters, keyed by their location.
14
+ */
15
+ param: {
16
+ /**
17
+ * Resolves the faker function name for an individual parameter.
18
+ *
19
+ * @example Individual parameter name
20
+ * `resolver.param.name(node, param) // -> 'showPetByIdPathPetId'`
21
+ */
22
+ name(node: ast.OperationNode, param: ast.ParameterNode): string;
23
+ /**
24
+ * Resolves the faker function name for an operation's grouped path parameters.
25
+ *
26
+ * @example Grouped path parameters name
27
+ * `resolver.param.path(node, param) // -> 'createShowPetByIdPath'`
28
+ */
29
+ path(node: ast.OperationNode, param: ast.ParameterNode): string;
30
+ /**
31
+ * Resolves the faker function name for an operation's grouped query parameters.
32
+ *
33
+ * @example Grouped query parameters name
34
+ * `resolver.param.query(node, param) // -> 'createListPetsQuery'`
35
+ */
36
+ query(node: ast.OperationNode, param: ast.ParameterNode): string;
37
+ /**
38
+ * Resolves the faker function name for an operation's grouped header parameters.
39
+ *
40
+ * @example Grouped header parameters name
41
+ * `resolver.param.headers(node, param) // -> 'createDeletePetHeaders'`
42
+ */
43
+ headers(node: ast.OperationNode, param: ast.ParameterNode): string;
44
+ };
45
+ /**
46
+ * Naming for operation request bodies and responses.
47
+ */
48
+ response: {
49
+ /**
50
+ * Resolves the faker function name for a response by status code.
51
+ *
52
+ * @example Response status name
53
+ * `resolver.response.status(node, 200) // -> 'listPetsStatus200'`
54
+ */
55
+ status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
56
+ /**
57
+ * Resolves the faker function name for a request body.
58
+ *
59
+ * @example Request body name
60
+ * `resolver.response.body(node) // -> 'createPetsBody'`
61
+ */
62
+ body(node: ast.OperationNode): string;
63
+ /**
64
+ * Resolves the faker function name for the response union.
65
+ *
66
+ * @example Response union name
67
+ * `resolver.response.response(node) // -> 'listPetsResponse'`
68
+ */
69
+ response(node: ast.OperationNode): string;
70
+ /**
71
+ * Resolves the faker function name for the response collection.
72
+ *
73
+ * @example Responses collection name
74
+ * `resolver.response.responses(node) // -> 'listPetsResponses'`
75
+ */
76
+ responses(node: ast.OperationNode): string;
77
+ };
78
+ };
79
+ /**
80
+ * Where the generated mock factories are written and how they are exported, plus the optional
81
+ * `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
82
+ *
83
+ * @default { path: 'mocks', barrel: { type: 'named' } }
84
+ */
85
+ type Options = OutputOptions & {
86
+ /**
87
+ * Skip operations matching at least one entry in the list.
88
+ */
89
+ exclude?: Array<Exclude>;
90
+ /**
91
+ * Restrict generation to operations matching at least one entry in the list.
92
+ */
93
+ include?: Array<Include>;
94
+ /**
95
+ * Apply a different options object to operations matching a pattern.
96
+ */
97
+ override?: Array<Override<ResolvedOptions>>;
98
+ /**
99
+ * Library used to format string-represented date, time, and datetime fields.
100
+ * Any library exporting a default function works; Kubb adds the import for you.
101
+ *
102
+ * @default 'faker'
103
+ */
104
+ dateParser?: 'faker' | 'dayjs' | 'moment' | (string & {});
105
+ /**
106
+ * Library used to generate strings that satisfy a regex `pattern` keyword.
107
+ * - `'faker'` uses `faker.helpers.fromRegExp`. No extra dependency.
108
+ * - `'randexp'` uses the `randexp` package. Supports a wider regex grammar.
109
+ *
110
+ * @default 'faker'
111
+ */
112
+ regexGenerator?: 'faker' | 'randexp';
113
+ /**
114
+ * Faker locale code. Switches the named import to `fakerXX` from `@faker-js/faker`
115
+ * so names, addresses, and phone numbers reflect the target region.
116
+ *
117
+ * @default 'en'
118
+ * @example German
119
+ * `locale: 'de'`
120
+ * @example Austrian German
121
+ * `locale: 'de_AT'`
122
+ * @see https://fakerjs.dev/api/localization.html
123
+ */
124
+ locale?: string;
125
+ /**
126
+ * Value passed to `faker.seed(...)`. Set this for deterministic mock output,
127
+ * which is useful for snapshot tests.
128
+ */
129
+ seed?: number | Array<number>;
130
+ /**
131
+ * Override the naming of generated factory helpers. Common use: append `Mock` or
132
+ * `Factory` so helpers do not clash with imported types.
133
+ */
134
+ resolver?: ResolverPatch<ResolverFaker>;
135
+ /**
136
+ * Macros applied to schema and operation nodes before printing.
137
+ */
138
+ macros?: Array<ast.Macro>;
139
+ /**
140
+ * Replace the Faker handler for a specific schema type (`'integer'`, `'date'`, ...).
141
+ * Each handler returns the Faker expression as a string.
142
+ */
143
+ printer?: {
144
+ nodes?: PrinterFakerNodes;
145
+ };
146
+ };
147
+ type ResolvedOptions = {
148
+ output: Output;
149
+ group: Group | null;
150
+ exclude: NonNullable<Options['exclude']>;
151
+ include: Options['include'];
152
+ override: NonNullable<Options['override']>;
153
+ dateParser: NonNullable<Options['dateParser']>;
154
+ regexGenerator: NonNullable<Options['regexGenerator']>;
155
+ seed: NonNullable<Options['seed']> | undefined;
156
+ locale: Options['locale'];
157
+ printer: Options['printer'];
158
+ };
159
+ type PluginFaker = PluginFactoryOptions<'plugin-faker', Options, ResolvedOptions, ResolverFaker>;
160
+ declare global {
161
+ namespace Kubb {
162
+ interface PluginRegistry {
163
+ 'plugin-faker': PluginFaker;
164
+ }
165
+ }
166
+ }
167
+ //#endregion
168
+ //#region src/printers/printerFaker.d.ts
169
+ /**
170
+ * Partial map of node-type overrides for the Faker printer. Each key is a
171
+ * `SchemaType` (`'string'`, `'date'`, ...) and each handler returns the
172
+ * Faker expression for that schema as a string. Use `this.transform` to
173
+ * recurse into nested schema nodes and `this.options` to read printer options.
174
+ *
175
+ * @example Override the integer handler
176
+ * ```ts
177
+ * pluginFaker({
178
+ * printer: {
179
+ * nodes: {
180
+ * integer() {
181
+ * return 'faker.number.float()'
182
+ * },
183
+ * },
184
+ * },
185
+ * })
186
+ * ```
187
+ */
188
+ type PrinterFakerNodes = ast.PrinterPartial<string, PrinterFakerOptions>;
189
+ /**
190
+ * Options passed to the Faker printer at instantiation: the parser library
191
+ * for date strings, the regex generator, and the resolver used to compute
192
+ * identifiers.
193
+ */
194
+ type PrinterFakerOptions = {
195
+ dateParser?: PluginFaker['resolvedOptions']['dateParser'];
196
+ regexGenerator?: PluginFaker['resolvedOptions']['regexGenerator'];
197
+ resolver: ResolverFaker;
198
+ typeName?: string;
199
+ schemaName?: string;
200
+ nestedInObject?: boolean;
201
+ /**
202
+ * Set while printing the members of a union (`oneOf`). Object properties then index their
203
+ * type as `(NonNullable<T> & Record<K, unknown>)[K]` instead of `NonNullable<T>[K]`, so a key
204
+ * carried by only some branches stays valid (a plain index would be a TS2339).
205
+ */
206
+ nestedInUnion?: boolean;
207
+ nodes?: PrinterFakerNodes;
208
+ /**
209
+ * Names of schemas that participate in a circular dependency chain.
210
+ * Properties whose schema transitively references one of these are emitted
211
+ * as lazy getters so that user overrides via the `data` parameter prevent
212
+ * the recursive faker call from ever executing (avoiding stack overflow).
213
+ */
214
+ cyclicSchemas?: ReadonlySet<string>;
215
+ };
216
+ /**
217
+ * Factory options for the Faker printer, defining input/output types and configuration.
218
+ */
219
+ type PrinterFakerFactory = ast.PrinterFactoryOptions<'faker', PrinterFakerOptions, string, string>;
220
+ /**
221
+ * Creates a Faker printer that generates mock data generation code from schema nodes.
222
+ * Handles circular references gracefully by emitting memoizing getters for cyclic properties.
223
+ */
224
+ declare const printerFaker: (options: PrinterFakerOptions) => ast.Printer<PrinterFakerFactory>;
225
+ //#endregion
226
+ //#region src/components/Faker.d.ts
227
+ type Props = {
228
+ name: string;
229
+ typeName: string;
230
+ node: ast.SchemaNode;
231
+ printer: ast.Printer<PrinterFakerFactory>;
232
+ seed?: PluginFaker['options']['seed'];
233
+ description?: string;
234
+ canOverride: boolean;
235
+ };
236
+ declare function Faker({ node, description, name, typeName, printer, seed, canOverride }: Props): KubbReactNode;
237
+ //#endregion
238
+ //#region src/generators/fakerGenerator.d.ts
239
+ /**
240
+ * Built-in generator for `@kubb/plugin-faker`. Emits one `createX` factory
241
+ * per schema in the spec plus per-operation request/response factories. Each
242
+ * factory returns a value matching the corresponding TypeScript type from
243
+ * `@kubb/plugin-ts`.
244
+ */
245
+ declare const fakerGenerator: import("kubb/kit").Generator<PluginFaker, unknown>;
246
+ //#endregion
7
247
  //#region src/plugin.d.ts
8
248
  /**
9
- * Canonical plugin name for `@kubb/plugin-faker`, used in driver lookups and warnings.
249
+ * Canonical plugin name for `@kubb/plugin-faker`. Used for driver lookups and
250
+ * cross-plugin dependency references.
10
251
  */
11
252
  declare const pluginFakerName = "plugin-faker";
12
253
  /**
13
- * Generates Faker mock data factories from OpenAPI/AST specification.
14
- *
15
- * Creates randomized test data and mock helpers from schema definitions.
254
+ * Generates one mock-data factory per OpenAPI schema using Faker.js. Call
255
+ * `createPet()` to get a realistic `Pet` object. Useful for tests, Storybook,
256
+ * and local development without a running backend.
16
257
  *
17
258
  * @example
18
- * `import pluginFaker from '@kubb/plugin-faker'; export default defineConfig({ plugins: [pluginFaker({ output: { path: 'mocks' } })], })`
259
+ * ```ts
260
+ * import { defineConfig } from 'kubb/config'
261
+ * import { pluginTs } from '@kubb/plugin-ts'
262
+ * import { pluginFaker } from '@kubb/plugin-faker'
263
+ *
264
+ * export default defineConfig({
265
+ * input: './petStore.yaml',
266
+ * output: { path: './src/gen' },
267
+ * plugins: [
268
+ * pluginTs(),
269
+ * pluginFaker({
270
+ * output: { path: './mocks' },
271
+ * seed: [100],
272
+ * }),
273
+ * ],
274
+ * })
275
+ * ```
19
276
  */
20
- declare const pluginFaker: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginFaker>;
277
+ declare const pluginFaker: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginFaker>;
21
278
  //#endregion
22
279
  //#region src/resolvers/resolverFaker.d.ts
23
280
  /**
24
- * Naming convention resolver for Faker plugin.
281
+ * Default resolver used by `@kubb/plugin-faker`. Decides the names and file
282
+ * paths for every generated mock factory. Functions and files are prefixed
283
+ * with `create` so `Pet` becomes `createPet`.
25
284
  *
26
- * Provides default naming helpers using camelCase with a `create` prefix for factory functions and files.
285
+ * @example Resolve a factory name
286
+ * ```ts
287
+ * import { resolverFaker } from '@kubb/plugin-faker'
27
288
  *
28
- * @example
29
- * `resolverFaker.default('list pets', 'function') // → 'createListPets'`
289
+ * resolverFaker.name('list pets') // 'createListPets'
290
+ * ```
30
291
  */
31
292
  declare const resolverFaker: ResolverFaker;
32
293
  //#endregion