@kubb/plugin-msw 5.0.0-alpha.9 → 5.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-CLQ77DVn.cjs +584 -0
  4. package/dist/components-CLQ77DVn.cjs.map +1 -0
  5. package/dist/components-vO0FIb2i.js +519 -0
  6. package/dist/components-vO0FIb2i.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +17 -21
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BPJCs1x1.js +176 -0
  11. package/dist/generators-BPJCs1x1.js.map +1 -0
  12. package/dist/generators-CrmMwWE4.cjs +186 -0
  13. package/dist/generators-CrmMwWE4.cjs.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +4 -500
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +54 -65
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +51 -65
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Dxu0KMQ4.d.ts +89 -0
  23. package/package.json +59 -57
  24. package/src/components/Handlers.tsx +3 -3
  25. package/src/components/Mock.tsx +36 -28
  26. package/src/components/MockWithFaker.tsx +36 -24
  27. package/src/components/Response.tsx +23 -17
  28. package/src/generators/handlersGenerator.tsx +18 -18
  29. package/src/generators/mswGenerator.tsx +49 -60
  30. package/src/index.ts +1 -1
  31. package/src/plugin.ts +48 -85
  32. package/src/resolvers/resolverMsw.ts +19 -0
  33. package/src/types.ts +45 -22
  34. package/src/utils.ts +109 -0
  35. package/dist/components-8XBwMbFa.cjs +0 -343
  36. package/dist/components-8XBwMbFa.cjs.map +0 -1
  37. package/dist/components-DgtTZkWX.js +0 -277
  38. package/dist/components-DgtTZkWX.js.map +0 -1
  39. package/dist/generators-CY1SNd5X.cjs +0 -171
  40. package/dist/generators-CY1SNd5X.cjs.map +0 -1
  41. package/dist/generators-CvyZTxOm.js +0 -161
  42. package/dist/generators-CvyZTxOm.js.map +0 -1
  43. package/dist/types-MdHRNpgi.d.ts +0 -68
@@ -1,277 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { File, Function as Function$1, FunctionParams } from "@kubb/react-fabric";
3
- import { jsx } from "@kubb/react-fabric/jsx-runtime";
4
- //#region ../../internals/utils/src/casing.ts
5
- /**
6
- * Shared implementation for camelCase and PascalCase conversion.
7
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
8
- * and capitalizes each word according to `pascal`.
9
- *
10
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
11
- */
12
- function toCamelOrPascal(text, pascal) {
13
- 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) => {
14
- if (word.length > 1 && word === word.toUpperCase()) return word;
15
- if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
16
- return word.charAt(0).toUpperCase() + word.slice(1);
17
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
18
- }
19
- /**
20
- * Splits `text` on `.` and applies `transformPart` to each segment.
21
- * The last segment receives `isLast = true`, all earlier segments receive `false`.
22
- * Segments are joined with `/` to form a file path.
23
- */
24
- function applyToFileParts(text, transformPart) {
25
- const parts = text.split(".");
26
- return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
27
- }
28
- /**
29
- * Converts `text` to camelCase.
30
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
31
- *
32
- * @example
33
- * camelCase('hello-world') // 'helloWorld'
34
- * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
35
- */
36
- function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
37
- if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
38
- prefix,
39
- suffix
40
- } : {}));
41
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
42
- }
43
- //#endregion
44
- //#region ../../internals/utils/src/reserved.ts
45
- /**
46
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
47
- */
48
- function isValidVarName(name) {
49
- try {
50
- new Function(`var ${name}`);
51
- } catch {
52
- return false;
53
- }
54
- return true;
55
- }
56
- //#endregion
57
- //#region ../../internals/utils/src/urlPath.ts
58
- /**
59
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
60
- *
61
- * @example
62
- * const p = new URLPath('/pet/{petId}')
63
- * p.URL // '/pet/:petId'
64
- * p.template // '`/pet/${petId}`'
65
- */
66
- var URLPath = class {
67
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
68
- path;
69
- #options;
70
- constructor(path, options = {}) {
71
- this.path = path;
72
- this.#options = options;
73
- }
74
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
75
- get URL() {
76
- return this.toURLPath();
77
- }
78
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
79
- get isURL() {
80
- try {
81
- return !!new URL(this.path).href;
82
- } catch {
83
- return false;
84
- }
85
- }
86
- /**
87
- * Converts the OpenAPI path to a TypeScript template literal string.
88
- *
89
- * @example
90
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
91
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
92
- */
93
- get template() {
94
- return this.toTemplateString();
95
- }
96
- /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
97
- get object() {
98
- return this.toObject();
99
- }
100
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
101
- get params() {
102
- return this.getParams();
103
- }
104
- #transformParam(raw) {
105
- const param = isValidVarName(raw) ? raw : camelCase(raw);
106
- return this.#options.casing === "camelcase" ? camelCase(param) : param;
107
- }
108
- /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
109
- #eachParam(fn) {
110
- for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
111
- const raw = match[1];
112
- fn(raw, this.#transformParam(raw));
113
- }
114
- }
115
- toObject({ type = "path", replacer, stringify } = {}) {
116
- const object = {
117
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
118
- params: this.getParams()
119
- };
120
- if (stringify) {
121
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
122
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
123
- return `{ url: '${object.url}' }`;
124
- }
125
- return object;
126
- }
127
- /**
128
- * Converts the OpenAPI path to a TypeScript template literal string.
129
- * An optional `replacer` can transform each extracted parameter name before interpolation.
130
- *
131
- * @example
132
- * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
133
- */
134
- toTemplateString({ prefix = "", replacer } = {}) {
135
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
136
- if (i % 2 === 0) return part;
137
- const param = this.#transformParam(part);
138
- return `\${${replacer ? replacer(param) : param}}`;
139
- }).join("")}\``;
140
- }
141
- /**
142
- * Extracts all `{param}` segments from the path and returns them as a key-value map.
143
- * An optional `replacer` transforms each parameter name in both key and value positions.
144
- * Returns `undefined` when no path parameters are found.
145
- */
146
- getParams(replacer) {
147
- const params = {};
148
- this.#eachParam((_raw, param) => {
149
- const key = replacer ? replacer(param) : param;
150
- params[key] = key;
151
- });
152
- return Object.keys(params).length > 0 ? params : void 0;
153
- }
154
- /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
155
- toURLPath() {
156
- return this.path.replace(/\{([^}]+)\}/g, ":$1");
157
- }
158
- };
159
- //#endregion
160
- //#region src/components/Handlers.tsx
161
- function Handlers({ name, handlers }) {
162
- return /* @__PURE__ */ jsx(File.Source, {
163
- name,
164
- isIndexable: true,
165
- isExportable: true,
166
- children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const`
167
- });
168
- }
169
- //#endregion
170
- //#region src/components/Mock.tsx
171
- function Mock({ baseURL = "", name, typeName, operation }) {
172
- const method = operation.method;
173
- const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
174
- const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
175
- const responseObject = operation.getResponseByStatusCode(statusCode);
176
- const contentType = Object.keys(responseObject.content || {})?.[0];
177
- const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
178
- const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
179
- const dataType = contentType && responseObject?.content?.[contentType]?.schema !== void 0 ? typeName : "string | number | boolean | null | object";
180
- const params = FunctionParams.factory({ data: {
181
- type: `${dataType} | ((
182
- info: Parameters<Parameters<typeof http.${method}>[1]>[0],
183
- ) => Response | Promise<Response>)`,
184
- optional: true
185
- } });
186
- return /* @__PURE__ */ jsx(File.Source, {
187
- name,
188
- isIndexable: true,
189
- isExportable: true,
190
- children: /* @__PURE__ */ jsx(Function$1, {
191
- name,
192
- export: true,
193
- params: params.toConstructor(),
194
- children: `return http.${method}(\`${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}\`, function handler(info) {
195
- if(typeof data === 'function') return data(info)
196
-
197
- return new Response(JSON.stringify(data), {
198
- status: ${statusCode},
199
- ${headers.length ? ` headers: {
200
- ${headers.join(", \n")}
201
- },` : ""}
202
- })
203
- })`
204
- })
205
- });
206
- }
207
- //#endregion
208
- //#region src/components/MockWithFaker.tsx
209
- function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
210
- const method = operation.method;
211
- const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith("2"));
212
- const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
213
- const responseObject = operation.getResponseByStatusCode(statusCode);
214
- const contentType = Object.keys(responseObject.content || {})?.[0];
215
- const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
216
- const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
217
- const params = FunctionParams.factory({ data: {
218
- type: `${typeName} | ((
219
- info: Parameters<Parameters<typeof http.${method}>[1]>[0],
220
- ) => Response | Promise<Response>)`,
221
- optional: true
222
- } });
223
- return /* @__PURE__ */ jsx(File.Source, {
224
- name,
225
- isIndexable: true,
226
- isExportable: true,
227
- children: /* @__PURE__ */ jsx(Function$1, {
228
- name,
229
- export: true,
230
- params: params.toConstructor(),
231
- children: `return http.${method}('${baseURL}${url.replace(/([^/]):/g, "$1\\\\:")}', function handler(info) {
232
- if(typeof data === 'function') return data(info)
233
-
234
- return new Response(JSON.stringify(data || ${fakerName}(data)), {
235
- status: ${statusCode},
236
- ${headers.length ? ` headers: {
237
- ${headers.join(", \n")}
238
- },` : ""}
239
- })
240
- })`
241
- })
242
- });
243
- }
244
- //#endregion
245
- //#region src/components/Response.tsx
246
- function Response({ name, typeName, operation, statusCode }) {
247
- const responseObject = operation.getResponseByStatusCode(statusCode);
248
- const contentType = Object.keys(responseObject.content || {})?.[0];
249
- const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
250
- const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== void 0;
251
- const params = FunctionParams.factory({ data: {
252
- type: `${typeName}`,
253
- optional: !hasResponseSchema
254
- } });
255
- const responseName = `${name}Response${statusCode}`;
256
- return /* @__PURE__ */ jsx(File.Source, {
257
- name: responseName,
258
- isIndexable: true,
259
- isExportable: true,
260
- children: /* @__PURE__ */ jsx(Function$1, {
261
- name: responseName,
262
- export: true,
263
- params: params.toConstructor(),
264
- children: `
265
- return new Response(JSON.stringify(data), {
266
- status: ${statusCode},
267
- ${headers.length ? ` headers: {
268
- ${headers.join(", \n")}
269
- },` : ""}
270
- })`
271
- })
272
- });
273
- }
274
- //#endregion
275
- export { camelCase as a, Handlers as i, MockWithFaker as n, Mock as r, Response as t };
276
-
277
- //# sourceMappingURL=components-DgtTZkWX.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-DgtTZkWX.js","names":["#options","#transformParam","#eachParam","Function","Function","Function"],"sources":["../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/urlPath.ts","../src/components/Handlers.tsx","../src/components/Mock.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.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 = 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 * 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.has(word as 'valueOf') || (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 { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/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): FabricReactNode {\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 type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n operation: Operation\n}\n\nexport function Mock({ baseURL = '', name, typeName, operation }: Props): FabricReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<Response>)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}(\\`${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 { URLPath } from '@internals/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n operation: Operation\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): FabricReactNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<Response>)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${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 type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): FabricReactNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\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.toConstructor()}>\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":";;;;;;;;;;;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,g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C,KAAK,QAAN;EAAmB;EAAM,aAAA;EAAY,cAAA;YACnC,oBAACC,YAAD;GAAgB;GAAM,QAAA;GAAO,QAAQ,OAAO,eAAe;aACxD,eAAe,OAAO,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;iDAG/B,UAAU;gBAC3C,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;;GAGU,CAAA;EACC,CAAA;;;;AC3ClB,SAAgB,SAAS,EAAE,MAAM,UAAU,WAAW,cAAsC;CAC1F,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAAO,KAAK,eAAe,WAAW,EAAE,CAAC,GAAG;CAEhE,MAAM,UAAU,CAAC,cAAc,oBAAoB,YAAY,KAAK,KAAA,EAAU,CAAC,OAAO,QAAQ;CAE9F,MAAM,oBAAoB,eAAe,gBAAgB,UAAU,cAAc,WAAW,KAAA;CAE5F,MAAM,SAAS,eAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG;EACT,UAAU,CAAC;EACZ,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,oBAAC,KAAK,QAAN;EAAa,MAAM;EAAc,aAAA;EAAY,cAAA;YAC3C,oBAACC,YAAD;GAAU,MAAM;GAAc,QAAA;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;GAEU,CAAA;EACC,CAAA"}
@@ -1,171 +0,0 @@
1
- const require_components = require("./components-8XBwMbFa.cjs");
2
- let _kubb_plugin_faker = require("@kubb/plugin-faker");
3
- let _kubb_plugin_ts = require("@kubb/plugin-ts");
4
- let _kubb_core_hooks = require("@kubb/core/hooks");
5
- let _kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
6
- let _kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
7
- let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
8
- let _kubb_react_fabric = require("@kubb/react-fabric");
9
- let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
10
- //#region src/generators/handlersGenerator.tsx
11
- const handlersGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
12
- name: "plugin-msw",
13
- Operations({ operations, generator, plugin }) {
14
- const driver = (0, _kubb_core_hooks.usePluginDriver)();
15
- const oas = (0, _kubb_plugin_oas_hooks.useOas)();
16
- const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
17
- const file = driver.getFile({
18
- name: "handlers",
19
- extname: ".ts",
20
- pluginName: plugin.name
21
- });
22
- const imports = operations.map((operation) => {
23
- const operationFile = getFile(operation, { pluginName: plugin.name });
24
- const operationName = getName(operation, {
25
- pluginName: plugin.name,
26
- type: "function"
27
- });
28
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
29
- name: [operationName],
30
- root: file.path,
31
- path: operationFile.path
32
- }, operationFile.path);
33
- });
34
- const handlers = operations.map((operation) => `${getName(operation, {
35
- type: "function",
36
- pluginName: plugin.name
37
- })}()`);
38
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
39
- baseName: file.baseName,
40
- path: file.path,
41
- meta: file.meta,
42
- banner: (0, _kubb_plugin_oas_utils.getBanner)({
43
- oas,
44
- output: plugin.options.output,
45
- config: driver.config
46
- }),
47
- footer: (0, _kubb_plugin_oas_utils.getFooter)({
48
- oas,
49
- output: plugin.options.output
50
- }),
51
- children: [imports, /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Handlers, {
52
- name: "handlers",
53
- handlers
54
- })]
55
- });
56
- }
57
- });
58
- //#endregion
59
- //#region src/generators/mswGenerator.tsx
60
- const mswGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
61
- name: "msw",
62
- Operation({ operation, generator, plugin }) {
63
- const { options: { output, parser, baseURL } } = plugin;
64
- const driver = (0, _kubb_core_hooks.usePluginDriver)();
65
- const oas = (0, _kubb_plugin_oas_hooks.useOas)();
66
- const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
67
- const mock = {
68
- name: getName(operation, { type: "function" }),
69
- file: getFile(operation)
70
- };
71
- const faker = {
72
- file: getFile(operation, { pluginName: _kubb_plugin_faker.pluginFakerName }),
73
- schemas: getSchemas(operation, {
74
- pluginName: _kubb_plugin_faker.pluginFakerName,
75
- type: "function"
76
- })
77
- };
78
- const type = {
79
- file: getFile(operation, { pluginName: _kubb_plugin_ts.pluginTsName }),
80
- schemas: getSchemas(operation, {
81
- pluginName: _kubb_plugin_ts.pluginTsName,
82
- type: "type"
83
- })
84
- };
85
- const responseStatusCodes = operation.getResponseStatusCodes();
86
- const types = [];
87
- for (const code of responseStatusCodes) {
88
- if (code === "default") {
89
- types.push(["default", type.schemas.response.name]);
90
- continue;
91
- }
92
- if (code.startsWith("2")) {
93
- types.push([Number(code), type.schemas.response.name]);
94
- continue;
95
- }
96
- const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code));
97
- if (codeType) types.push([Number(code), codeType.name]);
98
- }
99
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
100
- baseName: mock.file.baseName,
101
- path: mock.file.path,
102
- meta: mock.file.meta,
103
- banner: (0, _kubb_plugin_oas_utils.getBanner)({
104
- oas,
105
- output,
106
- config: driver.config
107
- }),
108
- footer: (0, _kubb_plugin_oas_utils.getFooter)({
109
- oas,
110
- output
111
- }),
112
- children: [
113
- /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
114
- name: ["http"],
115
- path: "msw"
116
- }),
117
- /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
118
- name: ["ResponseResolver"],
119
- isTypeOnly: true,
120
- path: "msw"
121
- }),
122
- /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
123
- name: Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])])),
124
- path: type.file.path,
125
- root: mock.file.path,
126
- isTypeOnly: true
127
- }),
128
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
129
- name: [faker.schemas.response.name],
130
- root: mock.file.path,
131
- path: faker.file.path
132
- }),
133
- types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Response, {
134
- typeName,
135
- operation,
136
- name: mock.name,
137
- statusCode: code
138
- })),
139
- parser === "faker" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.MockWithFaker, {
140
- name: mock.name,
141
- typeName: type.schemas.response.name,
142
- fakerName: faker.schemas.response.name,
143
- operation,
144
- baseURL
145
- }),
146
- parser === "data" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Mock, {
147
- name: mock.name,
148
- typeName: type.schemas.response.name,
149
- fakerName: faker.schemas.response.name,
150
- operation,
151
- baseURL
152
- })
153
- ]
154
- });
155
- }
156
- });
157
- //#endregion
158
- Object.defineProperty(exports, "handlersGenerator", {
159
- enumerable: true,
160
- get: function() {
161
- return handlersGenerator;
162
- }
163
- });
164
- Object.defineProperty(exports, "mswGenerator", {
165
- enumerable: true,
166
- get: function() {
167
- return mswGenerator;
168
- }
169
- });
170
-
171
- //# sourceMappingURL=generators-CY1SNd5X.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-CY1SNd5X.cjs","names":["File","Handlers","pluginFakerName","pluginTsName","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginDriver } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = driver.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginDriver } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AAQA,MAAa,qBAAA,GAAA,4BAA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