@kubb/plugin-cypress 5.0.0-alpha.3 → 5.0.0-alpha.31

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/src/types.ts CHANGED
@@ -1,20 +1,77 @@
1
- import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
1
+ import type { Visitor } from '@kubb/ast/types'
2
+ import type {
3
+ CompatibilityPreset,
4
+ Exclude,
5
+ Generator,
6
+ Group,
7
+ Include,
8
+ Output,
9
+ Override,
10
+ PluginFactoryOptions,
11
+ ResolvePathOptions,
12
+ Resolver,
13
+ UserGroup,
14
+ } from '@kubb/core'
2
15
 
3
- import type { contentType, Oas } from '@kubb/oas'
4
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
- import type { Generator } from '@kubb/plugin-oas/generators'
16
+ /**
17
+ * The concrete resolver type for `@kubb/plugin-cypress`.
18
+ * Extends the base `Resolver` with a `resolveName` helper for operation function names.
19
+ */
20
+ export type ResolverCypress = Resolver & {
21
+ /**
22
+ * Resolves the function name for a given raw operation name.
23
+ * @example
24
+ * resolver.resolveName('show pet by id') // -> 'showPetById'
25
+ */
26
+ resolveName(this: ResolverCypress, name: string): string
27
+ }
28
+
29
+ /**
30
+ * Discriminated union that ties `pathParamsType` to the `paramsType` values where it is meaningful.
31
+ *
32
+ * - `paramsType: 'object'` — all parameters (including path params) are merged into a single
33
+ * destructured object. `pathParamsType` is never reached in this code path and has no effect.
34
+ * - `paramsType?: 'inline'` (or omitted) — each parameter group is a separate function argument.
35
+ * `pathParamsType` controls whether the path-param group itself is destructured (`'object'`)
36
+ * or spread as individual arguments (`'inline'`).
37
+ */
38
+ type ParamsTypeOptions =
39
+ | {
40
+ /**
41
+ * All parameters — path, query, headers, and body — are merged into a single
42
+ * destructured object argument.
43
+ * - 'object' returns the params and pathParams as an object.
44
+ * @default 'inline'
45
+ */
46
+ paramsType: 'object'
47
+ /**
48
+ * `pathParamsType` has no effect when `paramsType` is `'object'`.
49
+ * Path params are already inside the single destructured object.
50
+ */
51
+ pathParamsType?: never
52
+ }
53
+ | {
54
+ /**
55
+ * Each parameter group is emitted as a separate function argument.
56
+ * - 'inline' returns the params as comma separated params.
57
+ * @default 'inline'
58
+ */
59
+ paramsType?: 'inline'
60
+ /**
61
+ * Controls how path parameters are arranged within the inline argument list.
62
+ * - 'object' groups path params into a destructured object: `{ petId }: PathParams`.
63
+ * - 'inline' emits each path param as its own argument: `petId: string`.
64
+ * @default 'inline'
65
+ */
66
+ pathParamsType?: 'object' | 'inline'
67
+ }
6
68
 
7
69
  export type Options = {
8
70
  /**
9
- * Specify the export location for the files and define the behavior of the output
71
+ * Specify the export location for the files and define the behavior of the output.
10
72
  * @default { path: 'cypress', barrelType: 'named' }
11
73
  */
12
- output?: Output<Oas>
13
- /**
14
- * Define which contentType should be used.
15
- * By default, the first JSON valid mediaType is used
16
- */
17
- contentType?: contentType
74
+ output?: Output
18
75
  /**
19
76
  * Return type when calling cy.request.
20
77
  * - 'data' returns ResponseConfig[data].
@@ -23,29 +80,18 @@ export type Options = {
23
80
  */
24
81
  dataReturnType?: 'data' | 'full'
25
82
  /**
26
- * How to style your params, by default no casing is applied
27
- * - 'camelcase' uses camelcase for the params names
83
+ * How to style your params, by default no casing is applied.
84
+ * - 'camelcase' uses camelCase for the params names.
28
85
  */
29
86
  paramsCasing?: 'camelcase'
30
87
  /**
31
- * How to pass your params.
32
- * - 'object' returns the params and pathParams as an object.
33
- * - 'inline' returns the params as comma separated params.
34
- * @default 'inline'
35
- */
36
- paramsType?: 'object' | 'inline'
37
- /**
38
- * How to pass your pathParams.
39
- * - 'object' returns the pathParams as an object.
40
- * - 'inline' returns the pathParams as comma separated params.
41
- * @default 'inline'
88
+ * Base URL prepended to every generated request URL.
42
89
  */
43
- pathParamsType?: 'object' | 'inline'
44
90
  baseURL?: string
45
91
  /**
46
92
  * Group the Cypress requests based on the provided name.
47
93
  */
48
- group?: Group
94
+ group?: UserGroup
49
95
  /**
50
96
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
51
97
  */
@@ -58,26 +104,47 @@ export type Options = {
58
104
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
59
105
  */
60
106
  override?: Array<Override<ResolvedOptions>>
61
- transformers?: {
62
- /**
63
- * Customize the names based on the type that is provided by the plugin.
64
- */
65
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
66
- }
67
107
  /**
68
- * Define some generators next to the Cypress generators.
108
+ * Apply a compatibility naming preset.
109
+ * @default 'default'
110
+ */
111
+ compatibilityPreset?: CompatibilityPreset
112
+ /**
113
+ * A single resolver whose methods override the default resolver's naming conventions.
114
+ * When a method returns `null` or `undefined`, the default resolver's result is used instead.
115
+ */
116
+ resolver?: Partial<ResolverCypress> & ThisType<ResolverCypress>
117
+ /**
118
+ * A single AST visitor applied before printing.
119
+ * When a visitor method returns `null` or `undefined`, the preset transformer's result is used instead.
120
+ */
121
+ transformer?: Visitor
122
+ /**
123
+ * Define some generators next to the default generators.
69
124
  */
70
125
  generators?: Array<Generator<PluginCypress>>
71
- }
126
+ } & ParamsTypeOptions
72
127
 
73
128
  type ResolvedOptions = {
74
- output: Output<Oas>
75
- group: Options['group']
129
+ output: Output
130
+ exclude: Array<Exclude>
131
+ include: Array<Include> | undefined
132
+ override: Array<Override<ResolvedOptions>>
133
+ group: Group | undefined
76
134
  baseURL: Options['baseURL'] | undefined
77
135
  dataReturnType: NonNullable<Options['dataReturnType']>
78
- pathParamsType: NonNullable<Options['pathParamsType']>
136
+ pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>
79
137
  paramsType: NonNullable<Options['paramsType']>
80
138
  paramsCasing: Options['paramsCasing']
139
+ resolver: ResolverCypress
81
140
  }
82
141
 
83
- export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>
142
+ export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions, ResolverCypress>
143
+
144
+ declare global {
145
+ namespace Kubb {
146
+ interface PluginRegistry {
147
+ 'plugin-cypress': PluginCypress
148
+ }
149
+ }
150
+ }
@@ -1,257 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { getPathParams } from "@kubb/plugin-oas/utils";
3
- import { File, Function as Function$1, FunctionParams } from "@kubb/react-fabric";
4
- import { isAllOptional, isOptional } from "@kubb/oas";
5
- import { jsx } from "@kubb/react-fabric/jsx-runtime";
6
- //#region ../../internals/utils/src/casing.ts
7
- /**
8
- * Shared implementation for camelCase and PascalCase conversion.
9
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
10
- * and capitalizes each word according to `pascal`.
11
- *
12
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
13
- */
14
- function toCamelOrPascal(text, pascal) {
15
- 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) => {
16
- if (word.length > 1 && word === word.toUpperCase()) return word;
17
- if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
18
- return word.charAt(0).toUpperCase() + word.slice(1);
19
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
20
- }
21
- /**
22
- * Splits `text` on `.` and applies `transformPart` to each segment.
23
- * The last segment receives `isLast = true`, all earlier segments receive `false`.
24
- * Segments are joined with `/` to form a file path.
25
- */
26
- function applyToFileParts(text, transformPart) {
27
- const parts = text.split(".");
28
- return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
29
- }
30
- /**
31
- * Converts `text` to camelCase.
32
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
33
- *
34
- * @example
35
- * camelCase('hello-world') // 'helloWorld'
36
- * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
37
- */
38
- function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
39
- if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
40
- prefix,
41
- suffix
42
- } : {}));
43
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
44
- }
45
- //#endregion
46
- //#region ../../internals/utils/src/reserved.ts
47
- /**
48
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
49
- */
50
- function isValidVarName(name) {
51
- try {
52
- new Function(`var ${name}`);
53
- } catch {
54
- return false;
55
- }
56
- return true;
57
- }
58
- //#endregion
59
- //#region ../../internals/utils/src/urlPath.ts
60
- /**
61
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
62
- *
63
- * @example
64
- * const p = new URLPath('/pet/{petId}')
65
- * p.URL // '/pet/:petId'
66
- * p.template // '`/pet/${petId}`'
67
- */
68
- var URLPath = class {
69
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
70
- path;
71
- #options;
72
- constructor(path, options = {}) {
73
- this.path = path;
74
- this.#options = options;
75
- }
76
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
77
- get URL() {
78
- return this.toURLPath();
79
- }
80
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
81
- get isURL() {
82
- try {
83
- return !!new URL(this.path).href;
84
- } catch {
85
- return false;
86
- }
87
- }
88
- /**
89
- * Converts the OpenAPI path to a TypeScript template literal string.
90
- *
91
- * @example
92
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
93
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
94
- */
95
- get template() {
96
- return this.toTemplateString();
97
- }
98
- /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
99
- get object() {
100
- return this.toObject();
101
- }
102
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
103
- get params() {
104
- return this.getParams();
105
- }
106
- #transformParam(raw) {
107
- const param = isValidVarName(raw) ? raw : camelCase(raw);
108
- return this.#options.casing === "camelcase" ? camelCase(param) : param;
109
- }
110
- /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
111
- #eachParam(fn) {
112
- for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
113
- const raw = match[1];
114
- fn(raw, this.#transformParam(raw));
115
- }
116
- }
117
- toObject({ type = "path", replacer, stringify } = {}) {
118
- const object = {
119
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
120
- params: this.getParams()
121
- };
122
- if (stringify) {
123
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
124
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
125
- return `{ url: '${object.url}' }`;
126
- }
127
- return object;
128
- }
129
- /**
130
- * Converts the OpenAPI path to a TypeScript template literal string.
131
- * An optional `replacer` can transform each extracted parameter name before interpolation.
132
- *
133
- * @example
134
- * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
135
- */
136
- toTemplateString({ prefix = "", replacer } = {}) {
137
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
138
- if (i % 2 === 0) return part;
139
- const param = this.#transformParam(part);
140
- return `\${${replacer ? replacer(param) : param}}`;
141
- }).join("")}\``;
142
- }
143
- /**
144
- * Extracts all `{param}` segments from the path and returns them as a key-value map.
145
- * An optional `replacer` transforms each parameter name in both key and value positions.
146
- * Returns `undefined` when no path parameters are found.
147
- */
148
- getParams(replacer) {
149
- const params = {};
150
- this.#eachParam((_raw, param) => {
151
- const key = replacer ? replacer(param) : param;
152
- params[key] = key;
153
- });
154
- return Object.keys(params).length > 0 ? params : void 0;
155
- }
156
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
157
- toURLPath() {
158
- return this.path.replace(/\{([^}]+)\}/g, ":$1");
159
- }
160
- };
161
- //#endregion
162
- //#region src/components/Request.tsx
163
- function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
164
- if (paramsType === "object") {
165
- const pathParams = getPathParams(typeSchemas.pathParams, {
166
- typed: true,
167
- casing: paramsCasing
168
- });
169
- return FunctionParams.factory({
170
- data: {
171
- mode: "object",
172
- children: {
173
- ...pathParams,
174
- data: typeSchemas.request?.name ? {
175
- type: typeSchemas.request?.name,
176
- optional: isOptional(typeSchemas.request?.schema)
177
- } : void 0,
178
- params: typeSchemas.queryParams?.name ? {
179
- type: typeSchemas.queryParams?.name,
180
- optional: isOptional(typeSchemas.queryParams?.schema)
181
- } : void 0,
182
- headers: typeSchemas.headerParams?.name ? {
183
- type: typeSchemas.headerParams?.name,
184
- optional: isOptional(typeSchemas.headerParams?.schema)
185
- } : void 0
186
- }
187
- },
188
- options: {
189
- type: "Partial<Cypress.RequestOptions>",
190
- default: "{}"
191
- }
192
- });
193
- }
194
- return FunctionParams.factory({
195
- pathParams: typeSchemas.pathParams?.name ? {
196
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
197
- children: getPathParams(typeSchemas.pathParams, {
198
- typed: true,
199
- casing: paramsCasing
200
- }),
201
- default: isAllOptional(typeSchemas.pathParams?.schema) ? "{}" : void 0
202
- } : void 0,
203
- data: typeSchemas.request?.name ? {
204
- type: typeSchemas.request?.name,
205
- optional: isOptional(typeSchemas.request?.schema)
206
- } : void 0,
207
- params: typeSchemas.queryParams?.name ? {
208
- type: typeSchemas.queryParams?.name,
209
- optional: isOptional(typeSchemas.queryParams?.schema)
210
- } : void 0,
211
- headers: typeSchemas.headerParams?.name ? {
212
- type: typeSchemas.headerParams?.name,
213
- optional: isOptional(typeSchemas.headerParams?.schema)
214
- } : void 0,
215
- options: {
216
- type: "Partial<Cypress.RequestOptions>",
217
- default: "{}"
218
- }
219
- });
220
- }
221
- function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }) {
222
- const path = new URLPath(url, { casing: paramsCasing });
223
- const params = getParams({
224
- paramsType,
225
- paramsCasing,
226
- pathParamsType,
227
- typeSchemas
228
- });
229
- const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
230
- const urlTemplate = path.toTemplateString({ prefix: baseURL });
231
- const requestOptions = [`method: '${method}'`, `url: ${urlTemplate}`];
232
- if (typeSchemas.queryParams?.name) requestOptions.push("qs: params");
233
- if (typeSchemas.headerParams?.name) requestOptions.push("headers");
234
- if (typeSchemas.request?.name) requestOptions.push("body: data");
235
- requestOptions.push("...options");
236
- return /* @__PURE__ */ jsx(File.Source, {
237
- name,
238
- isIndexable: true,
239
- isExportable: true,
240
- children: /* @__PURE__ */ jsx(Function$1, {
241
- name,
242
- export: true,
243
- params: params.toConstructor(),
244
- returnType,
245
- children: dataReturnType === "data" ? `return cy.request<${typeSchemas.response.name}>({
246
- ${requestOptions.join(",\n ")}
247
- }).then((res) => res.body)` : `return cy.request<${typeSchemas.response.name}>({
248
- ${requestOptions.join(",\n ")}
249
- })`
250
- })
251
- });
252
- }
253
- Request.getParams = getParams;
254
- //#endregion
255
- export { camelCase as n, Request as t };
256
-
257
- //# sourceMappingURL=components-BK_6GU4v.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-BK_6GU4v.js","names":["#options","#transformParam","#eachParam","Function"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/components/Request.tsx"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = [\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]\n\n/**\n * Prefixes a word with `_` when it is a reserved JavaScript/Java identifier\n * or starts with a digit.\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.includes(word) || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n */\nexport function isValidVarName(name: string): boolean {\n try {\n new Function(`var ${name}`)\n } catch {\n return false\n }\n return true\n}\n","import { camelCase } from './casing.ts'\nimport { isValidVarName } from './reserved.ts'\n\nexport type URLObject = {\n /** The resolved URL string (Express-style or template literal, depending on context). */\n url: string\n /** Extracted path parameters as a key-value map, or `undefined` when the path has none. */\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n /** Controls whether the `url` is rendered as an Express path or a template literal. Defaults to `'path'`. */\n type?: 'path' | 'template'\n /** Optional transform applied to each extracted parameter name. */\n replacer?: (pathParam: string) => string\n /** When `true`, the result is serialized to a string expression instead of a plain object. */\n stringify?: boolean\n}\n\n/** Supported identifier casing strategies for path parameters. */\ntype PathCasing = 'camelcase'\n\ntype Options = {\n /** Casing strategy applied to path parameter names. Defaults to the original identifier. */\n casing?: PathCasing\n}\n\n/**\n * Parses and transforms an OpenAPI/Swagger path string into various URL formats.\n *\n * @example\n * const p = new URLPath('/pet/{petId}')\n * p.URL // '/pet/:petId'\n * p.template // '`/pet/${petId}`'\n */\nexport class URLPath {\n /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */\n path: string\n\n #options: Options\n\n constructor(path: string, options: Options = {}) {\n this.path = path\n this.#options = options\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */\n get URL(): string {\n return this.toURLPath()\n }\n\n /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */\n get isURL(): boolean {\n try {\n return !!new URL(this.path).href\n } catch {\n return false\n }\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n *\n * @example\n * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'\n * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'\n */\n get template(): string {\n return this.toTemplateString()\n }\n\n /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */\n get object(): URLObject | string {\n return this.toObject()\n }\n\n /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */\n get params(): Record<string, string> | undefined {\n return this.getParams()\n }\n\n #transformParam(raw: string): string {\n const param = isValidVarName(raw) ? raw : camelCase(raw)\n return this.#options.casing === 'camelcase' ? camelCase(param) : param\n }\n\n /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */\n #eachParam(fn: (raw: string, param: string) => void): void {\n for (const match of this.path.matchAll(/\\{([^}]+)\\}/g)) {\n const raw = match[1]!\n fn(raw, this.#transformParam(raw))\n }\n }\n\n toObject({ type = 'path', replacer, stringify }: ObjectOptions = {}): URLObject | string {\n const object = {\n url: type === 'path' ? this.toURLPath() : this.toTemplateString({ replacer }),\n params: this.getParams(),\n }\n\n if (stringify) {\n if (type === 'template') {\n return JSON.stringify(object).replaceAll(\"'\", '').replaceAll(`\"`, '')\n }\n\n if (object.params) {\n return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll(\"'\", '').replaceAll(`\"`, '')} }`\n }\n\n return `{ url: '${object.url}' }`\n }\n\n return object\n }\n\n /**\n * Converts the OpenAPI path to a TypeScript template literal string.\n * An optional `replacer` can transform each extracted parameter name before interpolation.\n *\n * @example\n * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'\n */\n toTemplateString({ prefix = '', replacer }: { prefix?: string; replacer?: (pathParam: string) => string } = {}): string {\n const parts = this.path.split(/\\{([^}]+)\\}/)\n const result = parts\n .map((part, i) => {\n if (i % 2 === 0) return part\n const param = this.#transformParam(part)\n return `\\${${replacer ? replacer(param) : param}}`\n })\n .join('')\n\n return `\\`${prefix}${result}\\``\n }\n\n /**\n * Extracts all `{param}` segments from the path and returns them as a key-value map.\n * An optional `replacer` transforms each parameter name in both key and value positions.\n * Returns `undefined` when no path parameters are found.\n */\n getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined {\n const params: Record<string, string> = {}\n\n this.#eachParam((_raw, param) => {\n const key = replacer ? replacer(param) : param\n params[key] = key\n })\n\n return Object.keys(params).length > 0 ? params : undefined\n }\n\n /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */\n toURLPath(): string {\n return this.path.replace(/\\{([^}]+)\\}/g, ':$1')\n }\n}\n","import { URLPath } from '@internals/utils'\nimport { type HttpMethod, isAllOptional, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { PluginCypress } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeSchemas: OperationSchemas\n url: string\n baseURL: string | undefined\n dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']\n paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']\n paramsType: PluginCypress['resolvedOptions']['paramsType']\n pathParamsType: PluginCypress['resolvedOptions']['pathParamsType']\n method: HttpMethod\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']\n paramsType: PluginCypress['resolvedOptions']['paramsType']\n pathParamsType: PluginCypress['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })\n\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...pathParams,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n options: {\n type: 'Partial<Cypress.RequestOptions>',\n default: '{}',\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: 'Partial<Cypress.RequestOptions>',\n default: '{}',\n },\n })\n}\n\nexport function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }: Props): FabricReactNode {\n const path = new URLPath(url, { casing: paramsCasing })\n\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n\n const returnType =\n dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`\n\n // Build the URL template string - this will convert /pets/:petId to /pets/${petId}\n const urlTemplate = path.toTemplateString({ prefix: baseURL })\n\n // Build request options object\n const requestOptions: string[] = [`method: '${method}'`, `url: ${urlTemplate}`]\n\n // Add query params if they exist\n if (typeSchemas.queryParams?.name) {\n requestOptions.push('qs: params')\n }\n\n // Add headers if they exist\n if (typeSchemas.headerParams?.name) {\n requestOptions.push('headers')\n }\n\n // Add body if request schema exists\n if (typeSchemas.request?.name) {\n requestOptions.push('body: data')\n }\n\n // Spread additional Cypress options\n requestOptions.push('...options')\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()} returnType={returnType}>\n {dataReturnType === 'data'\n ? `return cy.request<${typeSchemas.response.name}>({\n ${requestOptions.join(',\\n ')}\n}).then((res) => res.body)`\n : `return cy.request<${typeSchemas.response.name}>({\n ${requestOptions.join(',\\n ')}\n})`}\n </Function>\n </File.Source>\n )\n}\n\nRequest.getParams = getParams\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,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;;;;;;;AAQjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAA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