@kubb/plugin-cypress 4.33.0 → 4.33.2
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/components-BK_6GU4v.js +257 -0
- package/dist/components-BK_6GU4v.js.map +1 -0
- package/dist/components-Drg_gLu2.cjs +305 -0
- package/dist/components-Drg_gLu2.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-XAzL9FKJ.js → generators-D5YFtyyC.js} +2 -2
- package/dist/{generators-XAzL9FKJ.js.map → generators-D5YFtyyC.js.map} +1 -1
- package/dist/{generators-C5Cvq5RO.cjs → generators-DDI2uD9N.cjs} +2 -2
- package/dist/{generators-C5Cvq5RO.cjs.map → generators-DDI2uD9N.cjs.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +42 -6
- package/dist/generators.js +1 -1
- package/dist/index.cjs +4 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
- package/src/components/Request.tsx +1 -1
- package/src/plugin.ts +1 -1
- package/dist/components-CXqedeum.js +0 -102
- package/dist/components-CXqedeum.js.map +0 -1
- package/dist/components-DIv7fdTx.cjs +0 -144
- package/dist/components-DIv7fdTx.cjs.map +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,OA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SAAgB,QAAQ,EAAE,UAAU,IAAI,MAAM,gBAAgB,aAAa,KAAK,QAAQ,YAAY,cAAc,kBAA0C;CAC1J,MAAM,OAAO,IAAI,QAAQ,KAAK,EAAE,QAAQ,cAAc,CAAC;CAEvD,MAAM,SAAS,UAAU;EAAE;EAAY;EAAc;EAAgB;EAAa,CAAC;CAEnF,MAAM,aACJ,mBAAmB,SAAS,qBAAqB,YAAY,SAAS,KAAK,KAAK,sCAAsC,YAAY,SAAS,KAAK;CAGlJ,MAAM,cAAc,KAAK,iBAAiB,EAAE,QAAQ,SAAS,CAAC;CAG9D,MAAM,iBAA2B,CAAC,YAAY,OAAO,IAAI,QAAQ,cAAc;AAG/E,KAAI,YAAY,aAAa,KAC3B,gBAAe,KAAK,aAAa;AAInC,KAAI,YAAY,cAAc,KAC5B,gBAAe,KAAK,UAAU;AAIhC,KAAI,YAAY,SAAS,KACvB,gBAAe,KAAK,aAAa;AAInC,gBAAe,KAAK,aAAa;AAEjC,QACE,oBAAC,KAAK,QAAN;EAAmB;EAAM,aAAA;EAAY,cAAA;YACnC,oBAACG,YAAD;GAAgB;GAAM,QAAA;GAAO,QAAQ,OAAO,eAAe;GAAc;aACtE,mBAAmB,SAChB,qBAAqB,YAAY,SAAS,KAAK;IACvD,eAAe,KAAK,QAAQ,CAAC;8BAErB,qBAAqB,YAAY,SAAS,KAAK;IACvD,eAAe,KAAK,QAAQ,CAAC;;GAEhB,CAAA;EACC,CAAA;;AAIlB,QAAQ,YAAY"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
28
|
+
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
29
|
+
let _kubb_oas = require("@kubb/oas");
|
|
30
|
+
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
31
|
+
//#region ../../internals/utils/src/casing.ts
|
|
32
|
+
/**
|
|
33
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
34
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
35
|
+
* and capitalizes each word according to `pascal`.
|
|
36
|
+
*
|
|
37
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
38
|
+
*/
|
|
39
|
+
function toCamelOrPascal(text, pascal) {
|
|
40
|
+
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) => {
|
|
41
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
42
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
43
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
44
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
48
|
+
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
49
|
+
* Segments are joined with `/` to form a file path.
|
|
50
|
+
*/
|
|
51
|
+
function applyToFileParts(text, transformPart) {
|
|
52
|
+
const parts = text.split(".");
|
|
53
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Converts `text` to camelCase.
|
|
57
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
61
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
62
|
+
*/
|
|
63
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
64
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
65
|
+
prefix,
|
|
66
|
+
suffix
|
|
67
|
+
} : {}));
|
|
68
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
72
|
+
/**
|
|
73
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
74
|
+
*/
|
|
75
|
+
function isValidVarName(name) {
|
|
76
|
+
try {
|
|
77
|
+
new Function(`var ${name}`);
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region ../../internals/utils/src/urlPath.ts
|
|
85
|
+
/**
|
|
86
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* const p = new URLPath('/pet/{petId}')
|
|
90
|
+
* p.URL // '/pet/:petId'
|
|
91
|
+
* p.template // '`/pet/${petId}`'
|
|
92
|
+
*/
|
|
93
|
+
var URLPath = class {
|
|
94
|
+
/** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
|
|
95
|
+
path;
|
|
96
|
+
#options;
|
|
97
|
+
constructor(path, options = {}) {
|
|
98
|
+
this.path = path;
|
|
99
|
+
this.#options = options;
|
|
100
|
+
}
|
|
101
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
102
|
+
get URL() {
|
|
103
|
+
return this.toURLPath();
|
|
104
|
+
}
|
|
105
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
|
|
106
|
+
get isURL() {
|
|
107
|
+
try {
|
|
108
|
+
return !!new URL(this.path).href;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
118
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
119
|
+
*/
|
|
120
|
+
get template() {
|
|
121
|
+
return this.toTemplateString();
|
|
122
|
+
}
|
|
123
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
|
|
124
|
+
get object() {
|
|
125
|
+
return this.toObject();
|
|
126
|
+
}
|
|
127
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
|
|
128
|
+
get params() {
|
|
129
|
+
return this.getParams();
|
|
130
|
+
}
|
|
131
|
+
#transformParam(raw) {
|
|
132
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
133
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
134
|
+
}
|
|
135
|
+
/** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
|
|
136
|
+
#eachParam(fn) {
|
|
137
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
138
|
+
const raw = match[1];
|
|
139
|
+
fn(raw, this.#transformParam(raw));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
143
|
+
const object = {
|
|
144
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
145
|
+
params: this.getParams()
|
|
146
|
+
};
|
|
147
|
+
if (stringify) {
|
|
148
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
149
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
150
|
+
return `{ url: '${object.url}' }`;
|
|
151
|
+
}
|
|
152
|
+
return object;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
156
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
160
|
+
*/
|
|
161
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
162
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
163
|
+
if (i % 2 === 0) return part;
|
|
164
|
+
const param = this.#transformParam(part);
|
|
165
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
166
|
+
}).join("")}\``;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
170
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
171
|
+
* Returns `undefined` when no path parameters are found.
|
|
172
|
+
*/
|
|
173
|
+
getParams(replacer) {
|
|
174
|
+
const params = {};
|
|
175
|
+
this.#eachParam((_raw, param) => {
|
|
176
|
+
const key = replacer ? replacer(param) : param;
|
|
177
|
+
params[key] = key;
|
|
178
|
+
});
|
|
179
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
180
|
+
}
|
|
181
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
182
|
+
toURLPath() {
|
|
183
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/components/Request.tsx
|
|
188
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
189
|
+
if (paramsType === "object") {
|
|
190
|
+
const pathParams = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
191
|
+
typed: true,
|
|
192
|
+
casing: paramsCasing
|
|
193
|
+
});
|
|
194
|
+
return _kubb_react_fabric.FunctionParams.factory({
|
|
195
|
+
data: {
|
|
196
|
+
mode: "object",
|
|
197
|
+
children: {
|
|
198
|
+
...pathParams,
|
|
199
|
+
data: typeSchemas.request?.name ? {
|
|
200
|
+
type: typeSchemas.request?.name,
|
|
201
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
202
|
+
} : void 0,
|
|
203
|
+
params: typeSchemas.queryParams?.name ? {
|
|
204
|
+
type: typeSchemas.queryParams?.name,
|
|
205
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
206
|
+
} : void 0,
|
|
207
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
208
|
+
type: typeSchemas.headerParams?.name,
|
|
209
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
210
|
+
} : void 0
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
options: {
|
|
214
|
+
type: "Partial<Cypress.RequestOptions>",
|
|
215
|
+
default: "{}"
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return _kubb_react_fabric.FunctionParams.factory({
|
|
220
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
221
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
222
|
+
children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
223
|
+
typed: true,
|
|
224
|
+
casing: paramsCasing
|
|
225
|
+
}),
|
|
226
|
+
default: (0, _kubb_oas.isAllOptional)(typeSchemas.pathParams?.schema) ? "{}" : void 0
|
|
227
|
+
} : void 0,
|
|
228
|
+
data: typeSchemas.request?.name ? {
|
|
229
|
+
type: typeSchemas.request?.name,
|
|
230
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
231
|
+
} : void 0,
|
|
232
|
+
params: typeSchemas.queryParams?.name ? {
|
|
233
|
+
type: typeSchemas.queryParams?.name,
|
|
234
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
235
|
+
} : void 0,
|
|
236
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
237
|
+
type: typeSchemas.headerParams?.name,
|
|
238
|
+
optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
239
|
+
} : void 0,
|
|
240
|
+
options: {
|
|
241
|
+
type: "Partial<Cypress.RequestOptions>",
|
|
242
|
+
default: "{}"
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }) {
|
|
247
|
+
const path = new URLPath(url, { casing: paramsCasing });
|
|
248
|
+
const params = getParams({
|
|
249
|
+
paramsType,
|
|
250
|
+
paramsCasing,
|
|
251
|
+
pathParamsType,
|
|
252
|
+
typeSchemas
|
|
253
|
+
});
|
|
254
|
+
const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
|
|
255
|
+
const urlTemplate = path.toTemplateString({ prefix: baseURL });
|
|
256
|
+
const requestOptions = [`method: '${method}'`, `url: ${urlTemplate}`];
|
|
257
|
+
if (typeSchemas.queryParams?.name) requestOptions.push("qs: params");
|
|
258
|
+
if (typeSchemas.headerParams?.name) requestOptions.push("headers");
|
|
259
|
+
if (typeSchemas.request?.name) requestOptions.push("body: data");
|
|
260
|
+
requestOptions.push("...options");
|
|
261
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
262
|
+
name,
|
|
263
|
+
isIndexable: true,
|
|
264
|
+
isExportable: true,
|
|
265
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
|
|
266
|
+
name,
|
|
267
|
+
export: true,
|
|
268
|
+
params: params.toConstructor(),
|
|
269
|
+
returnType,
|
|
270
|
+
children: dataReturnType === "data" ? `return cy.request<${typeSchemas.response.name}>({
|
|
271
|
+
${requestOptions.join(",\n ")}
|
|
272
|
+
}).then((res) => res.body)` : `return cy.request<${typeSchemas.response.name}>({
|
|
273
|
+
${requestOptions.join(",\n ")}
|
|
274
|
+
})`
|
|
275
|
+
})
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
Request.getParams = getParams;
|
|
279
|
+
//#endregion
|
|
280
|
+
Object.defineProperty(exports, "Request", {
|
|
281
|
+
enumerable: true,
|
|
282
|
+
get: function() {
|
|
283
|
+
return Request;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
Object.defineProperty(exports, "__name", {
|
|
287
|
+
enumerable: true,
|
|
288
|
+
get: function() {
|
|
289
|
+
return __name;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
Object.defineProperty(exports, "__toESM", {
|
|
293
|
+
enumerable: true,
|
|
294
|
+
get: function() {
|
|
295
|
+
return __toESM;
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
Object.defineProperty(exports, "camelCase", {
|
|
299
|
+
enumerable: true,
|
|
300
|
+
get: function() {
|
|
301
|
+
return camelCase;
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
//# sourceMappingURL=components-Drg_gLu2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-Drg_gLu2.cjs","names":["#options","#transformParam","#eachParam","FunctionParams","File","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,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;AC4C9D,SAAgB,eAAe,MAAuB;AACpD,KAAI;AACF,MAAI,SAAS,OAAO,OAAO;SACrB;AACN,SAAO;;AA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