@kubb/plugin-faker 5.0.0-beta.42 → 5.0.0-beta.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/{Faker-SBhWTdC7.d.ts → Faker-BA4l8DTe.d.ts} +2 -2
  2. package/dist/{Faker-DBPx_MVh.js → Faker-DUx7jvCo.js} +10 -55
  3. package/dist/Faker-DUx7jvCo.js.map +1 -0
  4. package/dist/{Faker-DRL0W5Lt.cjs → Faker-Ds2xP2-k.cjs} +11 -62
  5. package/dist/Faker-Ds2xP2-k.cjs.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +1 -1
  8. package/dist/components.js +1 -1
  9. package/dist/{fakerGenerator-Duc28_FK.d.ts → fakerGenerator-BNysC6rh.d.ts} +2 -2
  10. package/dist/{fakerGenerator-CVOr0Pwm.cjs → fakerGenerator-BeKRKYuy.cjs} +26 -60
  11. package/dist/fakerGenerator-BeKRKYuy.cjs.map +1 -0
  12. package/dist/{fakerGenerator-DNJ61yLj.js → fakerGenerator-D5Bcy5WY.js} +25 -59
  13. package/dist/fakerGenerator-D5Bcy5WY.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +47 -44
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +47 -44
  21. package/dist/index.js.map +1 -1
  22. package/dist/{printerFaker-DXS861Q0.d.ts → printerFaker-BzEB43Jz.d.ts} +11 -15
  23. package/package.json +8 -16
  24. package/dist/Faker-DBPx_MVh.js.map +0 -1
  25. package/dist/Faker-DRL0W5Lt.cjs.map +0 -1
  26. package/dist/fakerGenerator-CVOr0Pwm.cjs.map +0 -1
  27. package/dist/fakerGenerator-DNJ61yLj.js.map +0 -1
  28. package/extension.yaml +0 -819
  29. package/src/components/Faker.tsx +0 -139
  30. package/src/components/index.ts +0 -1
  31. package/src/generators/fakerGenerator.tsx +0 -311
  32. package/src/generators/index.ts +0 -1
  33. package/src/index.ts +0 -7
  34. package/src/plugin.ts +0 -92
  35. package/src/printers/printerFaker.ts +0 -405
  36. package/src/resolvers/resolverFaker.ts +0 -84
  37. package/src/types.ts +0 -185
  38. package/src/utils.ts +0 -257
package/src/utils.ts DELETED
@@ -1,257 +0,0 @@
1
- import { posix } from 'node:path'
2
- import { ast } from '@kubb/core'
3
- import type { ResolverFaker } from './types.ts'
4
-
5
- /**
6
- * Returns the `@faker-js/faker` named export for a locale code.
7
- *
8
- * Without a locale, returns `'faker'` for the default English instance.
9
- * With a locale, the language code is converted to upper case and joined with any region suffix.
10
- *
11
- * @example Default
12
- * `localeToFakerImport() // 'faker'`
13
- *
14
- * @example Simple locale
15
- * `localeToFakerImport('de') // 'fakerDE'`
16
- *
17
- * @example Compound locale
18
- * `localeToFakerImport('de_AT') // 'fakerDE_AT'`
19
- */
20
- export function localeToFakerImport(locale?: string): string {
21
- if (!locale) {
22
- return 'faker'
23
- }
24
-
25
- const parts = locale.split('_')
26
- parts[0] = parts[0]!.toUpperCase()
27
- return `faker${parts.join('_')}`
28
- }
29
-
30
- /**
31
- * Determines if a schema node can be overridden during faker generation.
32
- */
33
- export function canOverrideSchema(node: ast.SchemaNode): boolean {
34
- return new Set<ast.SchemaNode['type']>([
35
- 'array',
36
- 'tuple',
37
- 'object',
38
- 'intersection',
39
- 'union',
40
- 'enum',
41
- 'ref',
42
- 'string',
43
- 'email',
44
- 'url',
45
- 'uuid',
46
- 'number',
47
- 'integer',
48
- 'bigint',
49
- 'boolean',
50
- 'date',
51
- 'time',
52
- 'datetime',
53
- 'blob',
54
- ]).has(node.type)
55
- }
56
-
57
- /**
58
- * Resolves a parameter name based on its location (path, query, header, etc.) using the provided resolver.
59
- */
60
- export function resolveParamNameByLocation(
61
- resolver: Pick<ResolverFaker, 'resolvePathParamsName' | 'resolveQueryParamsName' | 'resolveHeaderParamsName' | 'resolveParamName'>,
62
- node: ast.OperationNode,
63
- param: ast.ParameterNode,
64
- ): string {
65
- switch (param.in) {
66
- case 'path':
67
- return resolver.resolvePathParamsName(node, param)
68
- case 'query':
69
- return resolver.resolveQueryParamsName(node, param)
70
- case 'header':
71
- return resolver.resolveHeaderParamsName(node, param)
72
- default:
73
- return resolver.resolveParamName(node, param)
74
- }
75
- }
76
-
77
- function shouldInlineSingleResponseSchema(schema: ast.SchemaNode): boolean {
78
- return new Set<ast.SchemaNode['type']>([
79
- 'any',
80
- 'unknown',
81
- 'void',
82
- 'null',
83
- 'array',
84
- 'tuple',
85
- 'string',
86
- 'email',
87
- 'url',
88
- 'uuid',
89
- 'number',
90
- 'integer',
91
- 'bigint',
92
- 'boolean',
93
- 'date',
94
- 'time',
95
- 'datetime',
96
- 'blob',
97
- 'enum',
98
- 'union',
99
- ]).has(schema.type)
100
- }
101
-
102
- /**
103
- * Builds a response schema as a union of all response statuses.
104
- * Returns null if no responses are provided, or embeds single simple responses inline.
105
- */
106
- export function buildResponseUnionSchema(node: ast.OperationNode, resolver: ResolverFaker): ast.SchemaNode | null {
107
- const responses = node.responses.filter((response) => response.content?.[0]?.schema)
108
-
109
- if (!responses.length) {
110
- return null
111
- }
112
-
113
- if (responses.length === 1) {
114
- const schema = responses[0]!.content?.[0]?.schema
115
- if (schema && shouldInlineSingleResponseSchema(schema)) {
116
- return schema
117
- }
118
-
119
- return ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, responses[0]!.statusCode) })
120
- }
121
-
122
- return ast.createSchema({
123
- type: 'union',
124
- members: responses.map((response) => ast.createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, response.statusCode) })),
125
- })
126
- }
127
-
128
- const SCALAR_TYPES = new Set<ast.SchemaNode['type']>([
129
- 'string',
130
- 'email',
131
- 'url',
132
- 'uuid',
133
- 'number',
134
- 'integer',
135
- 'bigint',
136
- 'boolean',
137
- 'date',
138
- 'time',
139
- 'datetime',
140
- 'blob',
141
- 'enum',
142
- ])
143
- const ARRAY_TYPES = new Set<ast.SchemaNode['type']>(['array'])
144
-
145
- function toRelativeImportPath(from: string, to: string): string {
146
- const relativePath = posix.relative(posix.dirname(from), to)
147
- return relativePath.startsWith('../') ? relativePath : `./${relativePath}`
148
- }
149
-
150
- /**
151
- * Resolves a type reference, determining if it needs an import statement or inline type reference.
152
- * Takes into account whether the type can be overridden and the file paths.
153
- */
154
- export function resolveTypeReference({
155
- node,
156
- canOverride,
157
- name,
158
- typeName,
159
- filePath,
160
- typeFilePath,
161
- }: {
162
- node: ast.SchemaNode
163
- canOverride: boolean
164
- name: string
165
- typeName: string
166
- filePath: string
167
- typeFilePath: string
168
- }): { importPath?: string; typeName: string } {
169
- const { usesTypeName } = resolveFakerTypeUsage(node, typeName, canOverride)
170
-
171
- if (!usesTypeName) {
172
- return { typeName }
173
- }
174
-
175
- if (name === typeName) {
176
- return {
177
- typeName: `import('${toRelativeImportPath(filePath, typeFilePath)}').${typeName}`,
178
- }
179
- }
180
-
181
- return {
182
- importPath: typeFilePath,
183
- typeName,
184
- }
185
- }
186
-
187
- /**
188
- * Maps a schema node type to its corresponding scalar type representation.
189
- * Returns the type name for enums or the base type (string, number, etc.) for primitives.
190
- */
191
- export function getScalarType(node: ast.SchemaNode, typeName: string): string {
192
- switch (node.type) {
193
- case 'string':
194
- case 'email':
195
- case 'url':
196
- case 'uuid':
197
- return 'string'
198
- case 'number':
199
- case 'integer':
200
- return 'number'
201
- case 'bigint':
202
- return 'bigint'
203
- case 'boolean':
204
- return 'boolean'
205
- case 'date':
206
- case 'time':
207
- return node.representation === 'date' ? 'Date' : 'string'
208
- case 'datetime':
209
- return 'string'
210
- case 'blob':
211
- return 'Blob'
212
- case 'enum':
213
- return typeName
214
- default:
215
- return typeName
216
- }
217
- }
218
-
219
- /**
220
- * Resolves faker type usage information for a schema.
221
- * Determines the data type, return type, and whether it uses the type name.
222
- */
223
- export function resolveFakerTypeUsage(
224
- node: ast.SchemaNode,
225
- typeName: string,
226
- canOverride: boolean,
227
- ): {
228
- dataType: string
229
- returnType: string | null
230
- usesTypeName: boolean
231
- } {
232
- const isArray = ARRAY_TYPES.has(node.type)
233
- const isTuple = node.type === 'tuple'
234
- const isScalar = SCALAR_TYPES.has(node.type)
235
-
236
- let dataType = `Partial<${typeName}>`
237
-
238
- if (isArray || isTuple || node.type === 'union' || node.type === 'enum') {
239
- dataType = typeName
240
- }
241
-
242
- if (isScalar) {
243
- dataType = getScalarType(node, typeName)
244
- }
245
-
246
- let returnType = canOverride ? typeName : null
247
-
248
- if (isScalar) {
249
- returnType = getScalarType(node, typeName)
250
- }
251
-
252
- return {
253
- dataType,
254
- returnType,
255
- usesTypeName: dataType.includes(typeName) || Boolean(returnType?.includes(typeName)),
256
- }
257
- }