@kubb/plugin-msw 5.0.0-alpha.9 → 5.0.0-beta.10
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/LICENSE +17 -10
- package/README.md +26 -7
- package/dist/components-BYvgvrY7.cjs +569 -0
- package/dist/components-BYvgvrY7.cjs.map +1 -0
- package/dist/components-Cm17DMTE.js +510 -0
- package/dist/components-Cm17DMTE.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +17 -21
- package/dist/components.js +1 -1
- package/dist/generators-D9gvdP7Z.js +177 -0
- package/dist/generators-D9gvdP7Z.js.map +1 -0
- package/dist/generators-rZ99WaWQ.cjs +187 -0
- package/dist/generators-rZ99WaWQ.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -500
- package/dist/generators.js +1 -1
- package/dist/index.cjs +62 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +59 -65
- package/dist/index.js.map +1 -1
- package/dist/types-ItsHsMvC.d.ts +94 -0
- package/extension.yaml +233 -0
- package/package.json +57 -58
- package/src/components/Handlers.tsx +3 -3
- package/src/components/Mock.tsx +37 -28
- package/src/components/MockWithFaker.tsx +37 -24
- package/src/components/Response.tsx +23 -17
- package/src/generators/handlersGenerator.tsx +19 -19
- package/src/generators/mswGenerator.tsx +50 -60
- package/src/index.ts +1 -1
- package/src/plugin.ts +47 -86
- package/src/resolvers/resolverMsw.ts +28 -0
- package/src/types.ts +55 -27
- package/src/utils.ts +58 -0
- package/dist/components-8XBwMbFa.cjs +0 -343
- package/dist/components-8XBwMbFa.cjs.map +0 -1
- package/dist/components-DgtTZkWX.js +0 -277
- package/dist/components-DgtTZkWX.js.map +0 -1
- package/dist/generators-CY1SNd5X.cjs +0 -171
- package/dist/generators-CY1SNd5X.cjs.map +0 -1
- package/dist/generators-CvyZTxOm.js +0 -161
- package/dist/generators-CvyZTxOm.js.map +0 -1
- package/dist/types-MdHRNpgi.d.ts +0 -68
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components-BYvgvrY7.cjs","names":["#options","#transformParam","#eachParam","File","declarationPrinter","ast","File","Function","declarationPrinter","ast","File","Function","ast","File","Function"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/components/Handlers.tsx","../../../internals/shared/src/operation.ts","../src/utils.ts","../src/components/Mock.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["type Options = {\n /**\n * When `true`, dot-separated segments are split on `.` and joined with `/` after casing.\n */\n isFile?: boolean\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n *\n * Only splits on dots followed by a letter so that version numbers\n * embedded in operationIds (e.g. `v2025.0`) are kept intact.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split(/\\.(?=[a-zA-Z])/)\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","import { camelCase } from './casing.ts'\nimport { isValidVarName } from './reserved.ts'\n\nexport type URLObject = {\n /**\n * The resolved URL string (Express-style or template literal, depending on context).\n */\n url: string\n /**\n * Extracted path parameters as a key-value map, or `undefined` when the path has none.\n */\n params?: Record<string, string>\n}\n\ntype ObjectOptions = {\n /**\n * Controls whether the `url` is rendered as an Express path or a template literal.\n * @default 'path'\n */\n type?: 'path' | 'template'\n /**\n * Optional transform applied to each extracted parameter name.\n */\n replacer?: (pathParam: string) => string\n /**\n * When `true`, the result is serialized to a string expression instead of a plain object.\n */\n stringify?: boolean\n}\n\n/**\n * Supported identifier casing strategies for path parameters.\n */\ntype PathCasing = 'camelcase'\n\ntype Options = {\n /**\n * Casing strategy applied to path parameter names.\n * @default undefined (original identifier preserved)\n */\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 /**\n * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.\n */\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 *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').URL // '/pet/:petId'\n * ```\n */\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 *\n * @example\n * ```ts\n * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true\n * new URLPath('/pet/{petId}').isURL // false\n * ```\n */\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 *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').object\n * // { url: '/pet/:petId', params: { petId: 'petId' } }\n * ```\n */\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 *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').params // { petId: 'petId' }\n * new URLPath('/pet').params // undefined\n * ```\n */\n get params(): Record<string, string> | undefined {\n return this.toParamsObject()\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 /**\n * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.\n */\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.toParamsObject(),\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 * @example\n * ```ts\n * new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()\n * // { petId: 'petId', tagId: 'tagId' }\n * ```\n */\n toParamsObject(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.\n *\n * @example\n * ```ts\n * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'\n * ```\n */\n toURLPath(): string {\n return this.path.replace(/\\{([^}]+)\\}/g, ':$1')\n }\n}\n","import { File } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx/types'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): KubbReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { URLPath } from '@internals/utils'\nimport { ast } from '@kubb/core'\n\nexport type ContentTypeInfo = {\n contentTypes: string[]\n isMultipleContentTypes: boolean\n contentTypeUnion: string\n defaultContentType: string\n hasFormData: boolean\n}\n\nexport type RequestConfigResolver = {\n resolveDataName(node: ast.OperationNode): string\n}\n\nexport type ResponseStatusNameResolver = {\n resolveResponseStatusName(node: ast.OperationNode, statusCode: ast.StatusCode): string\n}\n\nexport type ResponseNameResolver = ResponseStatusNameResolver & {\n resolveResponseName(node: ast.OperationNode): string\n}\n\nexport type OperationTypeNameResolver = RequestConfigResolver &\n ResponseNameResolver & {\n resolvePathParamsName(node: ast.OperationNode, param: ast.ParameterNode): string\n resolveQueryParamsName(node: ast.OperationNode, param: ast.ParameterNode): string\n resolveHeaderParamsName(node: ast.OperationNode, param: ast.ParameterNode): string\n }\n\nexport type OperationCommentLink = 'pathTemplate' | 'urlPath' | false | ((node: ast.OperationNode) => string | undefined)\n\nexport type BuildOperationCommentsOptions = {\n link?: OperationCommentLink\n linkPosition?: 'beforeDeprecated' | 'afterDeprecated'\n splitLines?: boolean\n}\n\ntype ResponseLike = {\n statusCode: ast.StatusCode | number | string\n}\n\nexport type OperationParameterGroups = Record<ast.ParameterNode['in'], Array<ast.ParameterNode>>\n\nexport type ResolveOperationTypeNameOptions = {\n paramsCasing?: 'camelcase'\n responseStatusNames?: boolean | 'error'\n exclude?: ReadonlyArray<string | undefined>\n order?: 'params-first' | 'body-response-first'\n}\n\nfunction getOperationLink(node: ast.OperationNode, link: OperationCommentLink): string | undefined {\n if (!link) {\n return undefined\n }\n\n if (typeof link === 'function') {\n return link(node)\n }\n\n if (link === 'urlPath') {\n return node.path ? `{@link ${new URLPath(node.path).URL}}` : undefined\n }\n\n return `{@link ${node.path.replaceAll('{', ':').replaceAll('}', '')}}`\n}\n\nexport function getContentTypeInfo(node: ast.OperationNode): ContentTypeInfo {\n const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? []\n const isMultipleContentTypes = contentTypes.length > 1\n\n return {\n contentTypes,\n isMultipleContentTypes,\n contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(' | ') : '',\n defaultContentType: contentTypes[0] ?? 'application/json',\n hasFormData: contentTypes.some((ct) => ct === 'multipart/form-data'),\n }\n}\n\nexport function buildRequestConfigType(node: ast.OperationNode, resolver: RequestConfigResolver): string {\n const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined\n const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node)\n const configType = requestName ? `Partial<RequestConfig<${requestName}>>` : 'Partial<RequestConfig>'\n const configProps = ['client?: Client', isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : undefined].filter(Boolean).join('; ')\n\n return `${configType} & { ${configProps} }`\n}\n\nexport function buildOperationComments(node: ast.OperationNode, options: BuildOperationCommentsOptions = {}): Array<string> {\n const { link = 'pathTemplate', linkPosition = 'afterDeprecated', splitLines = false } = options\n const linkComment = getOperationLink(node, link)\n const comments =\n linkPosition === 'beforeDeprecated'\n ? [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, linkComment, node.deprecated && '@deprecated']\n : [node.description && `@description ${node.description}`, node.summary && `@summary ${node.summary}`, node.deprecated && '@deprecated', linkComment]\n\n const filteredComments = comments.filter((comment): comment is string => Boolean(comment))\n\n if (!splitLines) {\n return filteredComments\n }\n\n return filteredComments.flatMap((text) => text.split(/\\r?\\n/).map((line) => line.trim())).filter((comment): comment is string => Boolean(comment))\n}\n\nexport function getOperationParameters(node: ast.OperationNode, options: { paramsCasing?: 'camelcase' } = {}): OperationParameterGroups {\n const params = ast.caseParams(node.parameters, options.paramsCasing)\n\n return {\n path: params.filter((param) => param.in === 'path'),\n query: params.filter((param) => param.in === 'query'),\n header: params.filter((param) => param.in === 'header'),\n cookie: params.filter((param) => param.in === 'cookie'),\n }\n}\n\nexport function getStatusCodeNumber(statusCode: ast.StatusCode | number | string): number | undefined {\n const code = Number(statusCode)\n\n return Number.isNaN(code) ? undefined : code\n}\n\nexport function isSuccessStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== undefined && code >= 200 && code < 300\n}\n\nexport function isErrorStatusCode(statusCode: ast.StatusCode | number | string): boolean {\n const code = getStatusCodeNumber(statusCode)\n\n return code !== undefined && code >= 400\n}\n\nexport function getSuccessResponses<TResponse extends ResponseLike>(responses: ReadonlyArray<TResponse>): Array<TResponse> {\n return responses.filter((response) => isSuccessStatusCode(response.statusCode))\n}\n\nexport function getOperationSuccessResponses(node: ast.OperationNode): Array<ast.ResponseNode> {\n return getSuccessResponses(node.responses)\n}\n\nexport function getPrimarySuccessResponse(node: ast.OperationNode): ast.ResponseNode | undefined {\n return getOperationSuccessResponses(node)[0]\n}\n\nexport function resolveErrorNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses\n .filter((response) => isErrorStatusCode(response.statusCode))\n .map((response) => resolver.resolveResponseStatusName(node, response.statusCode))\n}\n\nexport function resolveStatusCodeNames(node: ast.OperationNode, resolver: ResponseStatusNameResolver): string[] {\n return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode))\n}\n\nexport function resolveOperationTypeNames(\n node: ast.OperationNode,\n resolver: OperationTypeNameResolver,\n options: ResolveOperationTypeNameOptions = {},\n): string[] {\n const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing })\n const responseStatusNames =\n options.responseStatusNames === 'error'\n ? resolveErrorNames(node, resolver)\n : options.responseStatusNames === false\n ? []\n : resolveStatusCodeNames(node, resolver)\n const exclude = new Set(options.exclude ?? [])\n const paramNames = [\n ...path.map((param) => resolver.resolvePathParamsName(node, param)),\n ...query.map((param) => resolver.resolveQueryParamsName(node, param)),\n ...header.map((param) => resolver.resolveHeaderParamsName(node, param)),\n ]\n const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined, resolver.resolveResponseName(node)]\n const names =\n options.order === 'body-response-first'\n ? [...bodyAndResponseNames, ...paramNames, ...responseStatusNames]\n : [...paramNames, ...bodyAndResponseNames, ...responseStatusNames]\n\n return names.filter((name): name is string => Boolean(name) && !exclude.has(name))\n}\n\nexport function resolveResponseTypes(node: ast.OperationNode, resolver: ResponseNameResolver): Array<[statusCode: number | 'default', typeName: string]> {\n const types: Array<[number | 'default', string]> = []\n\n for (const response of node.responses) {\n if (response.statusCode === 'default') {\n types.push(['default', resolver.resolveResponseName(node)])\n continue\n }\n\n const code = getStatusCodeNumber(response.statusCode)\n if (code === undefined) {\n continue\n }\n\n types.push([code, isSuccessStatusCode(code) ? resolver.resolveResponseName(node) : resolver.resolveResponseStatusName(node, response.statusCode)])\n }\n\n return types\n}\n\nexport function findSuccessStatusCode(responses: Array<{ statusCode: ast.StatusCode | number | string }>): ast.StatusCode | undefined {\n for (const response of responses) {\n if (isSuccessStatusCode(response.statusCode)) {\n return response.statusCode as ast.StatusCode\n }\n }\n\n return undefined\n}\n","import type { ast } from '@kubb/core'\nimport type { ResolverFaker } from '@kubb/plugin-faker'\nimport type { PluginMsw } from './types.ts'\n\n/**\n * Gets the content type from a response, defaulting to 'application/json' if a schema exists.\n */\nexport function getContentType(response: ast.ResponseNode | undefined): string | undefined {\n return getResponseContentType(response) ?? (hasResponseSchema(response) ? 'application/json' : undefined)\n}\n\n/**\n * Determines if a response has a schema that is not void or any.\n */\nexport function hasResponseSchema(response: ast.ResponseNode | undefined): boolean {\n return !!getResponseContentType(response) || (!!response?.schema && response.schema.type !== 'void' && response.schema.type !== 'any')\n}\n\nfunction getResponseContentType(response: ast.ResponseNode | undefined): string | undefined {\n const contentType = response as unknown as { mediaType?: string | null; contentType?: string | null } | undefined\n const value = contentType?.mediaType ?? contentType?.contentType\n return typeof value === 'string' && value.length > 0 ? value : undefined\n}\n\n/**\n * Converts an HTTP method to its lowercase MSW equivalent (e.g., 'POST' → 'post').\n */\nexport function getMswMethod(node: ast.OperationNode): string {\n return node.method.toLowerCase()\n}\n\n/**\n * Converts an OpenAPI-style path to an Express/MSW-style path by replacing `{param}` with `:param`.\n */\nexport function getMswUrl(node: ast.OperationNode): string {\n return node.path.replaceAll('{', ':').replaceAll('}', '')\n}\n\n/**\n * Resolves faker metadata for an MSW operation, including response name and file path.\n */\nexport function resolveFakerMeta(\n node: ast.OperationNode,\n options: {\n root: string\n fakerResolver: ResolverFaker\n fakerOutput: PluginMsw['resolvedOptions']['output']\n fakerGroup: PluginMsw['resolvedOptions']['group']\n },\n): { name: string; file: { path: string } } {\n const { root, fakerResolver, fakerOutput, fakerGroup } = options\n const tag = node.tags[0] ?? 'default'\n\n return {\n name: fakerResolver.resolveResponseName(node),\n file: fakerResolver.resolveFile({ name: node.operationId, extname: '.ts', tag, path: node.path }, { root, output: fakerOutput, group: fakerGroup }),\n }\n}\n","import { getPrimarySuccessResponse } from '@internals/shared'\nimport { URLPath } from '@internals/utils'\nimport { ast } from '@kubb/core'\nimport { functionPrinter } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx/types'\nimport { getContentType, getMswMethod, getMswUrl, hasResponseSchema } from '../utils.ts'\n\ntype Props = {\n name: string\n typeName: string\n requestTypeName?: string\n baseURL: string | undefined\n node: ast.OperationNode\n}\n\nconst declarationPrinter = functionPrinter({ mode: 'declaration' })\n\nexport function Mock({ baseURL = '', name, typeName, requestTypeName, node }: Props): KubbReactNode {\n const method = getMswMethod(node)\n const successResponse = getPrimarySuccessResponse(node)\n const statusCode = successResponse ? Number(successResponse.statusCode) : 200\n const contentType = getContentType(successResponse)\n const url = new URLPath(getMswUrl(node)).toURLPath()\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n const responseHasSchema = hasResponseSchema(successResponse)\n const dataType = responseHasSchema ? typeName : 'string | number | boolean | null | object'\n\n const callbackType = requestTypeName\n ? `HttpResponseResolver<Record<string, string>, ${requestTypeName}, any>`\n : `((info: Parameters<Parameters<typeof http.${method}>[1]>[0]) => Response | Promise<Response>)`\n\n const params = declarationPrinter.print(\n ast.createFunctionParameters({\n params: [\n ast.createFunctionParameter({\n name: 'data',\n type: ast.createParamsType({\n variant: 'reference',\n name: `${dataType} | ${callbackType}`,\n }),\n optional: true,\n }),\n ],\n }),\n )\n\n const httpCall = requestTypeName ? `http.${method}<Record<string, string>, ${requestTypeName}, any>` : `http.${method}`\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params ?? ''}>\n {`return ${httpCall}(\\`${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}\\`, function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { getPrimarySuccessResponse } from '@internals/shared'\nimport { URLPath } from '@internals/utils'\nimport { ast } from '@kubb/core'\nimport { functionPrinter } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx/types'\nimport { getContentType, getMswMethod, getMswUrl } from '../utils.ts'\n\ntype Props = {\n name: string\n typeName: string\n requestTypeName?: string\n fakerName: string\n baseURL: string | undefined\n node: ast.OperationNode\n}\n\nconst declarationPrinter = functionPrinter({ mode: 'declaration' })\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, requestTypeName, node }: Props): KubbReactNode {\n const method = getMswMethod(node)\n const successResponse = getPrimarySuccessResponse(node)\n const statusCode = successResponse ? Number(successResponse.statusCode) : 200\n const contentType = getContentType(successResponse)\n const url = new URLPath(getMswUrl(node)).toURLPath()\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const callbackType = requestTypeName\n ? `HttpResponseResolver<Record<string, string>, ${requestTypeName}, any>`\n : `((info: Parameters<Parameters<typeof http.${method}>[1]>[0]) => Response | Promise<Response>)`\n\n const params = declarationPrinter.print(\n ast.createFunctionParameters({\n params: [\n ast.createFunctionParameter({\n name: 'data',\n type: ast.createParamsType({\n variant: 'reference',\n name: `${typeName} | ${callbackType}`,\n }),\n optional: true,\n }),\n ],\n }),\n )\n\n const httpCall = requestTypeName ? `http.${method}<Record<string, string>, ${requestTypeName}, any>` : `http.${method}`\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params ?? ''}>\n {`return ${httpCall}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { ast } from '@kubb/core'\nimport { functionPrinter } from '@kubb/plugin-ts'\nimport { File, Function } from '@kubb/renderer-jsx'\nimport type { KubbReactNode } from '@kubb/renderer-jsx/types'\nimport { getContentType, hasResponseSchema } from '../utils.ts'\n\ntype Props = {\n typeName: string\n name: string\n response: ast.ResponseNode\n key?: string | number | null\n}\n\nconst declarationPrinter = functionPrinter({ mode: 'declaration' })\n\nexport function Response({ name, typeName, response }: Props): KubbReactNode {\n const statusCode = Number(response.statusCode)\n const contentType = getContentType(response)\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const params = declarationPrinter.print(\n ast.createFunctionParameters({\n params: [\n ast.createFunctionParameter({\n name: 'data',\n type: ast.createParamsType({ variant: 'reference', name: typeName }),\n optional: !hasResponseSchema(response),\n }),\n ],\n }),\n )\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params ?? ''}>\n {`\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsBA,SAAS,gBAAgB,MAAc,QAAyB;CAS9D,OARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAEH,CAAC,MAAM,gBAAgB,CAAC,OAAO,QAE3C,CACT,KAAK,MAAM,MAAM;EAEhB,IADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,EACjD,OAAO;EACrB,IAAI,MAAM,KAAK,CAAC,QAAQ,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;EAC3E,OAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;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AO,QAAQ;CAE9F,MAAM,SAAS,mBAAmB,MAChCC,WAAAA,IAAI,yBAAyB,EAC3B,QAAQ,CACNA,WAAAA,IAAI,wBAAwB;EAC1B,MAAM;EACN,MAAMA,WAAAA,IAAI,iBAAiB;GAAE,SAAS;GAAa,MAAM;GAAU,CAAC;EACpE,UAAU,CAAC,kBAAkB,SAAS;EACvC,CAAC,CACH,EACF,CAAC,CACH;CAED,MAAM,eAAe,GAAG,KAAK,UAAU;CAEvC,OACE,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,KAAK,QAAN;EAAa,MAAM;EAAc,aAAA;EAAY,cAAA;YAC3C,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,UAAD;GAAU,MAAM;GAAc,QAAA;GAAO,QAAQ,UAAU;aACpD;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;GAEU,CAAA;EACC,CAAA"}
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { ast } from "@kubb/core";
|
|
3
|
+
import { functionPrinter } from "@kubb/plugin-ts";
|
|
4
|
+
import { File, Function } from "@kubb/renderer-jsx";
|
|
5
|
+
import { jsx } from "@kubb/renderer-jsx/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
|
+
* Only splits on dots followed by a letter so that version numbers
|
|
27
|
+
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
28
|
+
*/
|
|
29
|
+
function applyToFileParts(text, transformPart) {
|
|
30
|
+
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
31
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts `text` to camelCase.
|
|
35
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
39
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
40
|
+
*/
|
|
41
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
42
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
43
|
+
prefix,
|
|
44
|
+
suffix
|
|
45
|
+
} : {}));
|
|
46
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
50
|
+
/**
|
|
51
|
+
* JavaScript and Java reserved words.
|
|
52
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
53
|
+
*/
|
|
54
|
+
const reservedWords = new Set([
|
|
55
|
+
"abstract",
|
|
56
|
+
"arguments",
|
|
57
|
+
"boolean",
|
|
58
|
+
"break",
|
|
59
|
+
"byte",
|
|
60
|
+
"case",
|
|
61
|
+
"catch",
|
|
62
|
+
"char",
|
|
63
|
+
"class",
|
|
64
|
+
"const",
|
|
65
|
+
"continue",
|
|
66
|
+
"debugger",
|
|
67
|
+
"default",
|
|
68
|
+
"delete",
|
|
69
|
+
"do",
|
|
70
|
+
"double",
|
|
71
|
+
"else",
|
|
72
|
+
"enum",
|
|
73
|
+
"eval",
|
|
74
|
+
"export",
|
|
75
|
+
"extends",
|
|
76
|
+
"false",
|
|
77
|
+
"final",
|
|
78
|
+
"finally",
|
|
79
|
+
"float",
|
|
80
|
+
"for",
|
|
81
|
+
"function",
|
|
82
|
+
"goto",
|
|
83
|
+
"if",
|
|
84
|
+
"implements",
|
|
85
|
+
"import",
|
|
86
|
+
"in",
|
|
87
|
+
"instanceof",
|
|
88
|
+
"int",
|
|
89
|
+
"interface",
|
|
90
|
+
"let",
|
|
91
|
+
"long",
|
|
92
|
+
"native",
|
|
93
|
+
"new",
|
|
94
|
+
"null",
|
|
95
|
+
"package",
|
|
96
|
+
"private",
|
|
97
|
+
"protected",
|
|
98
|
+
"public",
|
|
99
|
+
"return",
|
|
100
|
+
"short",
|
|
101
|
+
"static",
|
|
102
|
+
"super",
|
|
103
|
+
"switch",
|
|
104
|
+
"synchronized",
|
|
105
|
+
"this",
|
|
106
|
+
"throw",
|
|
107
|
+
"throws",
|
|
108
|
+
"transient",
|
|
109
|
+
"true",
|
|
110
|
+
"try",
|
|
111
|
+
"typeof",
|
|
112
|
+
"var",
|
|
113
|
+
"void",
|
|
114
|
+
"volatile",
|
|
115
|
+
"while",
|
|
116
|
+
"with",
|
|
117
|
+
"yield",
|
|
118
|
+
"Array",
|
|
119
|
+
"Date",
|
|
120
|
+
"hasOwnProperty",
|
|
121
|
+
"Infinity",
|
|
122
|
+
"isFinite",
|
|
123
|
+
"isNaN",
|
|
124
|
+
"isPrototypeOf",
|
|
125
|
+
"length",
|
|
126
|
+
"Math",
|
|
127
|
+
"name",
|
|
128
|
+
"NaN",
|
|
129
|
+
"Number",
|
|
130
|
+
"Object",
|
|
131
|
+
"prototype",
|
|
132
|
+
"String",
|
|
133
|
+
"toString",
|
|
134
|
+
"undefined",
|
|
135
|
+
"valueOf"
|
|
136
|
+
]);
|
|
137
|
+
/**
|
|
138
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* isValidVarName('status') // true
|
|
143
|
+
* isValidVarName('class') // false (reserved word)
|
|
144
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
function isValidVarName(name) {
|
|
148
|
+
if (!name || reservedWords.has(name)) return false;
|
|
149
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region ../../internals/utils/src/urlPath.ts
|
|
153
|
+
/**
|
|
154
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* const p = new URLPath('/pet/{petId}')
|
|
158
|
+
* p.URL // '/pet/:petId'
|
|
159
|
+
* p.template // '`/pet/${petId}`'
|
|
160
|
+
*/
|
|
161
|
+
var URLPath = class {
|
|
162
|
+
/**
|
|
163
|
+
* The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
|
|
164
|
+
*/
|
|
165
|
+
path;
|
|
166
|
+
#options;
|
|
167
|
+
constructor(path, options = {}) {
|
|
168
|
+
this.path = path;
|
|
169
|
+
this.#options = options;
|
|
170
|
+
}
|
|
171
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* new URLPath('/pet/{petId}').URL // '/pet/:petId'
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
get URL() {
|
|
179
|
+
return this.toURLPath();
|
|
180
|
+
}
|
|
181
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
|
|
186
|
+
* new URLPath('/pet/{petId}').isURL // false
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
get isURL() {
|
|
190
|
+
try {
|
|
191
|
+
return !!new URL(this.path).href;
|
|
192
|
+
} catch {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
201
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
202
|
+
*/
|
|
203
|
+
get template() {
|
|
204
|
+
return this.toTemplateString();
|
|
205
|
+
}
|
|
206
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* new URLPath('/pet/{petId}').object
|
|
211
|
+
* // { url: '/pet/:petId', params: { petId: 'petId' } }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
get object() {
|
|
215
|
+
return this.toObject();
|
|
216
|
+
}
|
|
217
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* new URLPath('/pet/{petId}').params // { petId: 'petId' }
|
|
222
|
+
* new URLPath('/pet').params // undefined
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
get params() {
|
|
226
|
+
return this.toParamsObject();
|
|
227
|
+
}
|
|
228
|
+
#transformParam(raw) {
|
|
229
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
230
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
|
|
234
|
+
*/
|
|
235
|
+
#eachParam(fn) {
|
|
236
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
237
|
+
const raw = match[1];
|
|
238
|
+
fn(raw, this.#transformParam(raw));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
242
|
+
const object = {
|
|
243
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
244
|
+
params: this.toParamsObject()
|
|
245
|
+
};
|
|
246
|
+
if (stringify) {
|
|
247
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
248
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
249
|
+
return `{ url: '${object.url}' }`;
|
|
250
|
+
}
|
|
251
|
+
return object;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
255
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
259
|
+
*/
|
|
260
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
261
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
262
|
+
if (i % 2 === 0) return part;
|
|
263
|
+
const param = this.#transformParam(part);
|
|
264
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
265
|
+
}).join("")}\``;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
269
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
270
|
+
* Returns `undefined` when no path parameters are found.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
|
|
275
|
+
* // { petId: 'petId', tagId: 'tagId' }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
toParamsObject(replacer) {
|
|
279
|
+
const params = {};
|
|
280
|
+
this.#eachParam((_raw, param) => {
|
|
281
|
+
const key = replacer ? replacer(param) : param;
|
|
282
|
+
params[key] = key;
|
|
283
|
+
});
|
|
284
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
285
|
+
}
|
|
286
|
+
/** Converts the OpenAPI path to Express-style colon syntax.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
toURLPath() {
|
|
294
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/components/Handlers.tsx
|
|
299
|
+
function Handlers({ name, handlers }) {
|
|
300
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
301
|
+
name,
|
|
302
|
+
isIndexable: true,
|
|
303
|
+
isExportable: true,
|
|
304
|
+
children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region ../../internals/shared/src/operation.ts
|
|
309
|
+
function getStatusCodeNumber(statusCode) {
|
|
310
|
+
const code = Number(statusCode);
|
|
311
|
+
return Number.isNaN(code) ? void 0 : code;
|
|
312
|
+
}
|
|
313
|
+
function isSuccessStatusCode(statusCode) {
|
|
314
|
+
const code = getStatusCodeNumber(statusCode);
|
|
315
|
+
return code !== void 0 && code >= 200 && code < 300;
|
|
316
|
+
}
|
|
317
|
+
function getSuccessResponses(responses) {
|
|
318
|
+
return responses.filter((response) => isSuccessStatusCode(response.statusCode));
|
|
319
|
+
}
|
|
320
|
+
function getOperationSuccessResponses(node) {
|
|
321
|
+
return getSuccessResponses(node.responses);
|
|
322
|
+
}
|
|
323
|
+
function getPrimarySuccessResponse(node) {
|
|
324
|
+
return getOperationSuccessResponses(node)[0];
|
|
325
|
+
}
|
|
326
|
+
function resolveResponseTypes(node, resolver) {
|
|
327
|
+
const types = [];
|
|
328
|
+
for (const response of node.responses) {
|
|
329
|
+
if (response.statusCode === "default") {
|
|
330
|
+
types.push(["default", resolver.resolveResponseName(node)]);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const code = getStatusCodeNumber(response.statusCode);
|
|
334
|
+
if (code === void 0) continue;
|
|
335
|
+
types.push([code, isSuccessStatusCode(code) ? resolver.resolveResponseName(node) : resolver.resolveResponseStatusName(node, response.statusCode)]);
|
|
336
|
+
}
|
|
337
|
+
return types;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/utils.ts
|
|
341
|
+
/**
|
|
342
|
+
* Gets the content type from a response, defaulting to 'application/json' if a schema exists.
|
|
343
|
+
*/
|
|
344
|
+
function getContentType(response) {
|
|
345
|
+
return getResponseContentType(response) ?? (hasResponseSchema(response) ? "application/json" : void 0);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Determines if a response has a schema that is not void or any.
|
|
349
|
+
*/
|
|
350
|
+
function hasResponseSchema(response) {
|
|
351
|
+
return !!getResponseContentType(response) || !!response?.schema && response.schema.type !== "void" && response.schema.type !== "any";
|
|
352
|
+
}
|
|
353
|
+
function getResponseContentType(response) {
|
|
354
|
+
const contentType = response;
|
|
355
|
+
const value = contentType?.mediaType ?? contentType?.contentType;
|
|
356
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Converts an HTTP method to its lowercase MSW equivalent (e.g., 'POST' → 'post').
|
|
360
|
+
*/
|
|
361
|
+
function getMswMethod(node) {
|
|
362
|
+
return node.method.toLowerCase();
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Converts an OpenAPI-style path to an Express/MSW-style path by replacing `{param}` with `:param`.
|
|
366
|
+
*/
|
|
367
|
+
function getMswUrl(node) {
|
|
368
|
+
return node.path.replaceAll("{", ":").replaceAll("}", "");
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Resolves faker metadata for an MSW operation, including response name and file path.
|
|
372
|
+
*/
|
|
373
|
+
function resolveFakerMeta(node, options) {
|
|
374
|
+
const { root, fakerResolver, fakerOutput, fakerGroup } = options;
|
|
375
|
+
const tag = node.tags[0] ?? "default";
|
|
376
|
+
return {
|
|
377
|
+
name: fakerResolver.resolveResponseName(node),
|
|
378
|
+
file: fakerResolver.resolveFile({
|
|
379
|
+
name: node.operationId,
|
|
380
|
+
extname: ".ts",
|
|
381
|
+
tag,
|
|
382
|
+
path: node.path
|
|
383
|
+
}, {
|
|
384
|
+
root,
|
|
385
|
+
output: fakerOutput,
|
|
386
|
+
group: fakerGroup
|
|
387
|
+
})
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/components/Mock.tsx
|
|
392
|
+
const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
393
|
+
function Mock({ baseURL = "", name, typeName, requestTypeName, node }) {
|
|
394
|
+
const method = getMswMethod(node);
|
|
395
|
+
const successResponse = getPrimarySuccessResponse(node);
|
|
396
|
+
const statusCode = successResponse ? Number(successResponse.statusCode) : 200;
|
|
397
|
+
const contentType = getContentType(successResponse);
|
|
398
|
+
const url = new URLPath(getMswUrl(node)).toURLPath();
|
|
399
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
400
|
+
const dataType = hasResponseSchema(successResponse) ? typeName : "string | number | boolean | null | object";
|
|
401
|
+
const callbackType = requestTypeName ? `HttpResponseResolver<Record<string, string>, ${requestTypeName}, any>` : `((info: Parameters<Parameters<typeof http.${method}>[1]>[0]) => Response | Promise<Response>)`;
|
|
402
|
+
const params = declarationPrinter$2.print(ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
403
|
+
name: "data",
|
|
404
|
+
type: ast.createParamsType({
|
|
405
|
+
variant: "reference",
|
|
406
|
+
name: `${dataType} | ${callbackType}`
|
|
407
|
+
}),
|
|
408
|
+
optional: true
|
|
409
|
+
})] }));
|
|
410
|
+
const httpCall = requestTypeName ? `http.${method}<Record<string, string>, ${requestTypeName}, any>` : `http.${method}`;
|
|
411
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
412
|
+
name,
|
|
413
|
+
isIndexable: true,
|
|
414
|
+
isExportable: true,
|
|
415
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
416
|
+
name,
|
|
417
|
+
export: true,
|
|
418
|
+
params: params ?? "",
|
|
419
|
+
children: `return ${httpCall}(\`${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}\`, function handler(info) {
|
|
420
|
+
if(typeof data === 'function') return data(info)
|
|
421
|
+
|
|
422
|
+
return new Response(JSON.stringify(data), {
|
|
423
|
+
status: ${statusCode},
|
|
424
|
+
${headers.length ? ` headers: {
|
|
425
|
+
${headers.join(", \n")}
|
|
426
|
+
},` : ""}
|
|
427
|
+
})
|
|
428
|
+
})`
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
//#endregion
|
|
433
|
+
//#region src/components/MockWithFaker.tsx
|
|
434
|
+
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
435
|
+
function MockWithFaker({ baseURL = "", name, fakerName, typeName, requestTypeName, node }) {
|
|
436
|
+
const method = getMswMethod(node);
|
|
437
|
+
const successResponse = getPrimarySuccessResponse(node);
|
|
438
|
+
const statusCode = successResponse ? Number(successResponse.statusCode) : 200;
|
|
439
|
+
const contentType = getContentType(successResponse);
|
|
440
|
+
const url = new URLPath(getMswUrl(node)).toURLPath();
|
|
441
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
442
|
+
const callbackType = requestTypeName ? `HttpResponseResolver<Record<string, string>, ${requestTypeName}, any>` : `((info: Parameters<Parameters<typeof http.${method}>[1]>[0]) => Response | Promise<Response>)`;
|
|
443
|
+
const params = declarationPrinter$1.print(ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
444
|
+
name: "data",
|
|
445
|
+
type: ast.createParamsType({
|
|
446
|
+
variant: "reference",
|
|
447
|
+
name: `${typeName} | ${callbackType}`
|
|
448
|
+
}),
|
|
449
|
+
optional: true
|
|
450
|
+
})] }));
|
|
451
|
+
const httpCall = requestTypeName ? `http.${method}<Record<string, string>, ${requestTypeName}, any>` : `http.${method}`;
|
|
452
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
453
|
+
name,
|
|
454
|
+
isIndexable: true,
|
|
455
|
+
isExportable: true,
|
|
456
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
457
|
+
name,
|
|
458
|
+
export: true,
|
|
459
|
+
params: params ?? "",
|
|
460
|
+
children: `return ${httpCall}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
|
|
461
|
+
if(typeof data === 'function') return data(info)
|
|
462
|
+
|
|
463
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
464
|
+
status: ${statusCode},
|
|
465
|
+
${headers.length ? ` headers: {
|
|
466
|
+
${headers.join(", \n")}
|
|
467
|
+
},` : ""}
|
|
468
|
+
})
|
|
469
|
+
})`
|
|
470
|
+
})
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/components/Response.tsx
|
|
475
|
+
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
476
|
+
function Response({ name, typeName, response }) {
|
|
477
|
+
const statusCode = Number(response.statusCode);
|
|
478
|
+
const contentType = getContentType(response);
|
|
479
|
+
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
480
|
+
const params = declarationPrinter.print(ast.createFunctionParameters({ params: [ast.createFunctionParameter({
|
|
481
|
+
name: "data",
|
|
482
|
+
type: ast.createParamsType({
|
|
483
|
+
variant: "reference",
|
|
484
|
+
name: typeName
|
|
485
|
+
}),
|
|
486
|
+
optional: !hasResponseSchema(response)
|
|
487
|
+
})] }));
|
|
488
|
+
const responseName = `${name}Response${statusCode}`;
|
|
489
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
490
|
+
name: responseName,
|
|
491
|
+
isIndexable: true,
|
|
492
|
+
isExportable: true,
|
|
493
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
494
|
+
name: responseName,
|
|
495
|
+
export: true,
|
|
496
|
+
params: params ?? "",
|
|
497
|
+
children: `
|
|
498
|
+
return new Response(JSON.stringify(data), {
|
|
499
|
+
status: ${statusCode},
|
|
500
|
+
${headers.length ? ` headers: {
|
|
501
|
+
${headers.join(", \n")}
|
|
502
|
+
},` : ""}
|
|
503
|
+
})`
|
|
504
|
+
})
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
508
|
+
export { getOperationSuccessResponses as a, camelCase as c, resolveFakerMeta as i, MockWithFaker as n, resolveResponseTypes as o, Mock as r, Handlers as s, Response as t };
|
|
509
|
+
|
|
510
|
+
//# sourceMappingURL=components-Cm17DMTE.js.map
|