@kubb/plugin-zod 4.4.0 → 4.5.0

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 (54) hide show
  1. package/dist/{components-DUJ6Xkpc.js → components-BtBB23cQ.js} +85 -75
  2. package/dist/components-BtBB23cQ.js.map +1 -0
  3. package/dist/{components-BiOh-7_I.cjs → components-DIUzzW4k.cjs} +82 -72
  4. package/dist/components-DIUzzW4k.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +4 -3
  7. package/dist/components.d.ts +4 -3
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-CwEOtNXG.js → generators-9upbJt-4.js} +116 -122
  10. package/dist/generators-9upbJt-4.js.map +1 -0
  11. package/dist/{generators-B2hD7k6l.cjs → generators-T3e_E7Uy.cjs} +115 -120
  12. package/dist/generators-T3e_E7Uy.cjs.map +1 -0
  13. package/dist/generators.cjs +2 -2
  14. package/dist/generators.d.cts +4 -4
  15. package/dist/generators.d.ts +4 -4
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +12 -2
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +11 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-CENqfJvI.d.cts → types-CQSK_Scm.d.cts} +145 -265
  24. package/dist/{types-DRKJPaUn.d.ts → types-DcQBOr_-.d.ts} +145 -265
  25. package/package.json +18 -20
  26. package/src/components/Zod.tsx +7 -13
  27. package/src/generators/__snapshots__/createPet.ts +2 -2
  28. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +2 -2
  29. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput.ts +7 -9
  30. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput_entire_.ts +7 -10
  31. package/src/generators/__snapshots__/createPet_wrapOutput.ts +7 -9
  32. package/src/generators/__snapshots__/discriminator.ts +20 -28
  33. package/src/generators/__snapshots__/getPets.ts +3 -3
  34. package/src/generators/__snapshots__/getPets_wrapOutput.ts +8 -10
  35. package/src/generators/__snapshots__/petArray.ts +1 -5
  36. package/src/generators/__snapshots__/queryAllDefaulted.ts +1 -1
  37. package/src/generators/__snapshots__/queryAllDefaulted_wrapOutput.ts +2 -2
  38. package/src/generators/__snapshots__/showPetById.ts +3 -3
  39. package/src/generators/__snapshots__/showPetById_wrapOutput.ts +8 -10
  40. package/src/generators/index.ts +1 -1
  41. package/src/generators/operationsGenerator.tsx +5 -5
  42. package/src/generators/zodGenerator.tsx +24 -21
  43. package/src/parser.ts +37 -36
  44. package/src/plugin.ts +15 -0
  45. package/dist/components-BiOh-7_I.cjs.map +0 -1
  46. package/dist/components-DUJ6Xkpc.js.map +0 -1
  47. package/dist/generators-B2hD7k6l.cjs.map +0 -1
  48. package/dist/generators-CwEOtNXG.js.map +0 -1
  49. package/dist/utils.cjs +0 -0
  50. package/dist/utils.d.cts +0 -28
  51. package/dist/utils.d.ts +0 -28
  52. package/dist/utils.js +0 -1
  53. package/src/utils/index.ts +0 -1
  54. /package/{src/utils → templates}/ToZod.ts +0 -0
@@ -1,28 +1,88 @@
1
- import { n as Operations, t as Zod } from "./components-DUJ6Xkpc.js";
2
- import { SchemaGenerator, createReactGenerator, schemaKeywords } from "@kubb/plugin-oas";
1
+ import { n as Operations, t as Zod } from "./components-BtBB23cQ.js";
2
+ import path from "node:path";
3
+ import { SchemaGenerator, schemaKeywords } from "@kubb/plugin-oas";
3
4
  import { pluginTsName } from "@kubb/plugin-ts";
4
- import { useMode, usePlugin, usePluginManager } from "@kubb/core/hooks";
5
- import { Oas } from "@kubb/plugin-oas/components";
5
+ import { useMode, usePluginManager } from "@kubb/core/hooks";
6
+ import { createReactGenerator } from "@kubb/plugin-oas/generators";
6
7
  import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
7
8
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
8
- import { File } from "@kubb/react-fabric";
9
+ import { File, Fragment } from "@kubb/react-fabric";
9
10
  import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
10
11
 
12
+ //#region src/generators/operationsGenerator.tsx
13
+ const operationsGenerator = createReactGenerator({
14
+ name: "operations",
15
+ Operations({ operations, generator, plugin }) {
16
+ const { key: pluginKey, options: { output, importPath } } = plugin;
17
+ const pluginManager = usePluginManager();
18
+ const oas = useOas();
19
+ const { getFile, groupSchemasByName } = useOperationManager(generator);
20
+ const name = "operations";
21
+ const file = pluginManager.getFile({
22
+ name,
23
+ extname: ".ts",
24
+ pluginKey
25
+ });
26
+ const transformedOperations = operations.map((operation) => ({
27
+ operation,
28
+ data: groupSchemasByName(operation, { type: "function" })
29
+ }));
30
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
31
+ const names = [
32
+ data.request,
33
+ ...Object.values(data.responses),
34
+ ...Object.values(data.parameters)
35
+ ].filter(Boolean);
36
+ return /* @__PURE__ */ jsx(File.Import, {
37
+ name: names,
38
+ root: file.path,
39
+ path: getFile(operation).path
40
+ }, key);
41
+ }).filter(Boolean);
42
+ return /* @__PURE__ */ jsxs(File, {
43
+ baseName: file.baseName,
44
+ path: file.path,
45
+ meta: file.meta,
46
+ banner: getBanner({
47
+ oas,
48
+ output,
49
+ config: pluginManager.config
50
+ }),
51
+ footer: getFooter({
52
+ oas,
53
+ output
54
+ }),
55
+ children: [
56
+ /* @__PURE__ */ jsx(File.Import, {
57
+ isTypeOnly: true,
58
+ name: ["z"],
59
+ path: importPath
60
+ }),
61
+ imports,
62
+ /* @__PURE__ */ jsx(Operations, {
63
+ name,
64
+ operations: transformedOperations
65
+ })
66
+ ]
67
+ });
68
+ }
69
+ });
70
+
71
+ //#endregion
11
72
  //#region src/generators/zodGenerator.tsx
12
73
  const zodGenerator = createReactGenerator({
13
74
  name: "zod",
14
- Operation({ operation, options, instance }) {
15
- const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
16
- const plugin = usePlugin();
75
+ Operation({ config, operation, generator, plugin }) {
76
+ const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version } } = plugin;
17
77
  const mode = useMode();
18
78
  const pluginManager = usePluginManager();
19
79
  const oas = useOas();
20
- const { getSchemas, getFile, getGroup } = useOperationManager();
80
+ const { getSchemas, getFile, getGroup } = useOperationManager(generator);
21
81
  const schemaManager = useSchemaManager();
22
82
  const file = getFile(operation);
23
83
  const schemas = getSchemas(operation);
24
84
  const schemaGenerator = new SchemaGenerator(options, {
25
- fabric: instance.context.fabric,
85
+ fabric: generator.context.fabric,
26
86
  oas,
27
87
  plugin,
28
88
  pluginManager,
@@ -37,7 +97,7 @@ const zodGenerator = createReactGenerator({
37
97
  schemas.request,
38
98
  schemas.response
39
99
  ].flat().filter(Boolean);
40
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
100
+ const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
41
101
  const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
42
102
  const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
43
103
  const optional = !required && !someDefaults && name.includes("Params");
@@ -67,47 +127,42 @@ const zodGenerator = createReactGenerator({
67
127
  group
68
128
  })
69
129
  };
70
- return /* @__PURE__ */ jsxs(Oas.Schema, {
71
- name,
72
- schemaObject,
73
- tree,
74
- children: [
75
- typed && /* @__PURE__ */ jsx(File.Import, {
76
- isTypeOnly: true,
77
- root: file.path,
78
- path: type.file.path,
79
- name: [type.name]
80
- }),
81
- typed && plugin.options.version === "3" && /* @__PURE__ */ jsx(File.Import, {
82
- isTypeOnly: true,
83
- path: "@kubb/plugin-zod/utils",
84
- name: ["ToZod"]
85
- }),
86
- imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
87
- root: file.path,
88
- path: imp.path,
89
- name: imp.name
90
- }, [
91
- imp.path,
92
- imp.name,
93
- imp.isTypeOnly
94
- ].join("-"))),
95
- /* @__PURE__ */ jsx(Zod, {
96
- name: zod.name,
97
- typeName: typed ? type.name : void 0,
98
- inferTypeName: inferred ? zod.inferTypeName : void 0,
99
- description,
100
- tree,
101
- rawSchema: schemaObject,
102
- mapper,
103
- coercion,
104
- keysToOmit,
105
- wrapOutput,
106
- version: plugin.options.version,
107
- emptySchemaType: plugin.options.emptySchemaType
108
- })
109
- ]
110
- }, i);
130
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
131
+ typed && /* @__PURE__ */ jsx(File.Import, {
132
+ isTypeOnly: true,
133
+ root: file.path,
134
+ path: type.file.path,
135
+ name: [type.name]
136
+ }),
137
+ typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
138
+ name: ["ToZod"],
139
+ root: file.path,
140
+ path: path.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
141
+ }),
142
+ imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
143
+ root: file.path,
144
+ path: imp.path,
145
+ name: imp.name
146
+ }, [
147
+ imp.path,
148
+ imp.name,
149
+ imp.isTypeOnly
150
+ ].join("-"))),
151
+ /* @__PURE__ */ jsx(Zod, {
152
+ name: zod.name,
153
+ typeName: typed ? type.name : void 0,
154
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
155
+ description,
156
+ tree,
157
+ schema: schemaObject,
158
+ mapper,
159
+ coercion,
160
+ keysToOmit,
161
+ wrapOutput,
162
+ version: plugin.options.version,
163
+ emptySchemaType: plugin.options.emptySchemaType
164
+ })
165
+ ] });
111
166
  };
112
167
  return /* @__PURE__ */ jsxs(File, {
113
168
  baseName: file.baseName,
@@ -128,10 +183,9 @@ const zodGenerator = createReactGenerator({
128
183
  }), operationSchemas.map(mapOperationSchema)]
129
184
  });
130
185
  },
131
- Schema({ schema, options }) {
132
- const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
186
+ Schema({ config, schema, plugin }) {
133
187
  const { getName, getFile, getImports } = useSchemaManager();
134
- const { options: { output, emptySchemaType } } = usePlugin();
188
+ const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version } } = plugin;
135
189
  const pluginManager = usePluginManager();
136
190
  const oas = useOas();
137
191
  const imports = getImports(schema.tree);
@@ -171,10 +225,10 @@ const zodGenerator = createReactGenerator({
171
225
  path: type.file.path,
172
226
  name: [type.name]
173
227
  }),
174
- typed && /* @__PURE__ */ jsx(File.Import, {
175
- isTypeOnly: true,
176
- path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
177
- name: ["ToZod"]
228
+ typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
229
+ name: ["ToZod"],
230
+ root: zod.file.path,
231
+ path: path.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
178
232
  }),
179
233
  imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
180
234
  root: zod.file.path,
@@ -191,7 +245,7 @@ const zodGenerator = createReactGenerator({
191
245
  inferTypeName: inferred ? zod.inferTypeName : void 0,
192
246
  description: schema.value.description,
193
247
  tree: schema.tree,
194
- rawSchema: schema.value,
248
+ schema: schema.value,
195
249
  mapper,
196
250
  coercion,
197
251
  wrapOutput,
@@ -204,65 +258,5 @@ const zodGenerator = createReactGenerator({
204
258
  });
205
259
 
206
260
  //#endregion
207
- //#region src/generators/operationsGenerator.tsx
208
- const operationsGenerator = createReactGenerator({
209
- name: "operations",
210
- Operations({ operations }) {
211
- const { key: pluginKey, options: { output, importPath } } = usePlugin();
212
- const pluginManager = usePluginManager();
213
- const oas = useOas();
214
- const { getFile, groupSchemasByName } = useOperationManager();
215
- const name = "operations";
216
- const file = pluginManager.getFile({
217
- name,
218
- extname: ".ts",
219
- pluginKey
220
- });
221
- const transformedOperations = operations.map((operation) => ({
222
- operation,
223
- data: groupSchemasByName(operation, { type: "function" })
224
- }));
225
- const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
226
- const names = [
227
- data.request,
228
- ...Object.values(data.responses),
229
- ...Object.values(data.parameters)
230
- ].filter(Boolean);
231
- return /* @__PURE__ */ jsx(File.Import, {
232
- name: names,
233
- root: file.path,
234
- path: getFile(operation).path
235
- }, key);
236
- }).filter(Boolean);
237
- return /* @__PURE__ */ jsxs(File, {
238
- baseName: file.baseName,
239
- path: file.path,
240
- meta: file.meta,
241
- banner: getBanner({
242
- oas,
243
- output,
244
- config: pluginManager.config
245
- }),
246
- footer: getFooter({
247
- oas,
248
- output
249
- }),
250
- children: [
251
- /* @__PURE__ */ jsx(File.Import, {
252
- isTypeOnly: true,
253
- name: ["z"],
254
- path: importPath
255
- }),
256
- imports,
257
- /* @__PURE__ */ jsx(Operations, {
258
- name,
259
- operations: transformedOperations
260
- })
261
- ]
262
- });
263
- }
264
- });
265
-
266
- //#endregion
267
- export { zodGenerator as n, operationsGenerator as t };
268
- //# sourceMappingURL=generators-CwEOtNXG.js.map
261
+ export { operationsGenerator as n, zodGenerator as t };
262
+ //# sourceMappingURL=generators-9upbJt-4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-9upbJt-4.js","names":["options"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } 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 { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Fragment>\n )\n }\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: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,UAAU;EAEtE,MAAM,OAAO;EACb,M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1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;MACjB;;IACG;;CAGZ,CAAC"}
@@ -1,12 +1,14 @@
1
- const require_components = require('./components-BiOh-7_I.cjs');
1
+ const require_components = require('./components-DIUzzW4k.cjs');
2
+ let node_path = require("node:path");
3
+ node_path = require_components.__toESM(node_path);
2
4
  let __kubb_plugin_oas = require("@kubb/plugin-oas");
3
5
  __kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
4
6
  let __kubb_plugin_ts = require("@kubb/plugin-ts");
5
7
  __kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
6
8
  let __kubb_core_hooks = require("@kubb/core/hooks");
7
9
  __kubb_core_hooks = require_components.__toESM(__kubb_core_hooks);
8
- let __kubb_plugin_oas_components = require("@kubb/plugin-oas/components");
9
- __kubb_plugin_oas_components = require_components.__toESM(__kubb_plugin_oas_components);
10
+ let __kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
11
+ __kubb_plugin_oas_generators = require_components.__toESM(__kubb_plugin_oas_generators);
10
12
  let __kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
11
13
  __kubb_plugin_oas_hooks = require_components.__toESM(__kubb_plugin_oas_hooks);
12
14
  let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
@@ -16,21 +18,80 @@ __kubb_react_fabric = require_components.__toESM(__kubb_react_fabric);
16
18
  let __kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
17
19
  __kubb_react_fabric_jsx_runtime = require_components.__toESM(__kubb_react_fabric_jsx_runtime);
18
20
 
21
+ //#region src/generators/operationsGenerator.tsx
22
+ const operationsGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
23
+ name: "operations",
24
+ Operations({ operations, generator, plugin }) {
25
+ const { key: pluginKey, options: { output, importPath } } = plugin;
26
+ const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
27
+ const oas = (0, __kubb_plugin_oas_hooks.useOas)();
28
+ const { getFile, groupSchemasByName } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
29
+ const name = "operations";
30
+ const file = pluginManager.getFile({
31
+ name,
32
+ extname: ".ts",
33
+ pluginKey
34
+ });
35
+ const transformedOperations = operations.map((operation) => ({
36
+ operation,
37
+ data: groupSchemasByName(operation, { type: "function" })
38
+ }));
39
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
40
+ const names = [
41
+ data.request,
42
+ ...Object.values(data.responses),
43
+ ...Object.values(data.parameters)
44
+ ].filter(Boolean);
45
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
46
+ name: names,
47
+ root: file.path,
48
+ path: getFile(operation).path
49
+ }, key);
50
+ }).filter(Boolean);
51
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
52
+ baseName: file.baseName,
53
+ path: file.path,
54
+ meta: file.meta,
55
+ banner: (0, __kubb_plugin_oas_utils.getBanner)({
56
+ oas,
57
+ output,
58
+ config: pluginManager.config
59
+ }),
60
+ footer: (0, __kubb_plugin_oas_utils.getFooter)({
61
+ oas,
62
+ output
63
+ }),
64
+ children: [
65
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
66
+ isTypeOnly: true,
67
+ name: ["z"],
68
+ path: importPath
69
+ }),
70
+ imports,
71
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Operations, {
72
+ name,
73
+ operations: transformedOperations
74
+ })
75
+ ]
76
+ });
77
+ }
78
+ });
79
+
80
+ //#endregion
19
81
  //#region src/generators/zodGenerator.tsx
20
- const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
82
+ const zodGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
21
83
  name: "zod",
22
- Operation({ operation, options, instance }) {
23
- const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
24
- const plugin = (0, __kubb_core_hooks.usePlugin)();
84
+ Operation({ config, operation, generator, plugin }) {
85
+ const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version } } = plugin;
25
86
  const mode = (0, __kubb_core_hooks.useMode)();
26
87
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
27
88
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
28
- const { getSchemas, getFile, getGroup } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
89
+ const { getSchemas, getFile, getGroup } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
29
90
  const schemaManager = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
30
91
  const file = getFile(operation);
31
92
  const schemas = getSchemas(operation);
32
93
  const schemaGenerator = new __kubb_plugin_oas.SchemaGenerator(options, {
33
- fabric: instance.context.fabric,
94
+ fabric: generator.context.fabric,
34
95
  oas,
35
96
  plugin,
36
97
  pluginManager,
@@ -45,7 +106,7 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
45
106
  schemas.request,
46
107
  schemas.response
47
108
  ].flat().filter(Boolean);
48
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
109
+ const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
49
110
  const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
50
111
  const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
51
112
  const optional = !required && !someDefaults && name.includes("Params");
@@ -75,47 +136,42 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
75
136
  group
76
137
  })
77
138
  };
78
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_plugin_oas_components.Oas.Schema, {
79
- name,
80
- schemaObject,
81
- tree,
82
- children: [
83
- typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
84
- isTypeOnly: true,
85
- root: file.path,
86
- path: type.file.path,
87
- name: [type.name]
88
- }),
89
- typed && plugin.options.version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
90
- isTypeOnly: true,
91
- path: "@kubb/plugin-zod/utils",
92
- name: ["ToZod"]
93
- }),
94
- imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
95
- root: file.path,
96
- path: imp.path,
97
- name: imp.name
98
- }, [
99
- imp.path,
100
- imp.name,
101
- imp.isTypeOnly
102
- ].join("-"))),
103
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Zod, {
104
- name: zod.name,
105
- typeName: typed ? type.name : void 0,
106
- inferTypeName: inferred ? zod.inferTypeName : void 0,
107
- description,
108
- tree,
109
- rawSchema: schemaObject,
110
- mapper,
111
- coercion,
112
- keysToOmit,
113
- wrapOutput,
114
- version: plugin.options.version,
115
- emptySchemaType: plugin.options.emptySchemaType
116
- })
117
- ]
118
- }, i);
139
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.Fragment, { children: [
140
+ typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
141
+ isTypeOnly: true,
142
+ root: file.path,
143
+ path: type.file.path,
144
+ name: [type.name]
145
+ }),
146
+ typed && version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
147
+ name: ["ToZod"],
148
+ root: file.path,
149
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
150
+ }),
151
+ imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
152
+ root: file.path,
153
+ path: imp.path,
154
+ name: imp.name
155
+ }, [
156
+ imp.path,
157
+ imp.name,
158
+ imp.isTypeOnly
159
+ ].join("-"))),
160
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Zod, {
161
+ name: zod.name,
162
+ typeName: typed ? type.name : void 0,
163
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
164
+ description,
165
+ tree,
166
+ schema: schemaObject,
167
+ mapper,
168
+ coercion,
169
+ keysToOmit,
170
+ wrapOutput,
171
+ version: plugin.options.version,
172
+ emptySchemaType: plugin.options.emptySchemaType
173
+ })
174
+ ] });
119
175
  };
120
176
  return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
121
177
  baseName: file.baseName,
@@ -136,10 +192,9 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
136
192
  }), operationSchemas.map(mapOperationSchema)]
137
193
  });
138
194
  },
139
- Schema({ schema, options }) {
140
- const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
195
+ Schema({ config, schema, plugin }) {
141
196
  const { getName, getFile, getImports } = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
142
- const { options: { output, emptySchemaType } } = (0, __kubb_core_hooks.usePlugin)();
197
+ const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version } } = plugin;
143
198
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
144
199
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
145
200
  const imports = getImports(schema.tree);
@@ -179,10 +234,10 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
179
234
  path: type.file.path,
180
235
  name: [type.name]
181
236
  }),
182
- typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
183
- isTypeOnly: true,
184
- path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
185
- name: ["ToZod"]
237
+ typed && version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
238
+ name: ["ToZod"],
239
+ root: zod.file.path,
240
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
186
241
  }),
187
242
  imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
188
243
  root: zod.file.path,
@@ -199,7 +254,7 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
199
254
  inferTypeName: inferred ? zod.inferTypeName : void 0,
200
255
  description: schema.value.description,
201
256
  tree: schema.tree,
202
- rawSchema: schema.value,
257
+ schema: schema.value,
203
258
  mapper,
204
259
  coercion,
205
260
  wrapOutput,
@@ -211,66 +266,6 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
211
266
  }
212
267
  });
213
268
 
214
- //#endregion
215
- //#region src/generators/operationsGenerator.tsx
216
- const operationsGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
217
- name: "operations",
218
- Operations({ operations }) {
219
- const { key: pluginKey, options: { output, importPath } } = (0, __kubb_core_hooks.usePlugin)();
220
- const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
221
- const oas = (0, __kubb_plugin_oas_hooks.useOas)();
222
- const { getFile, groupSchemasByName } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
223
- const name = "operations";
224
- const file = pluginManager.getFile({
225
- name,
226
- extname: ".ts",
227
- pluginKey
228
- });
229
- const transformedOperations = operations.map((operation) => ({
230
- operation,
231
- data: groupSchemasByName(operation, { type: "function" })
232
- }));
233
- const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
234
- const names = [
235
- data.request,
236
- ...Object.values(data.responses),
237
- ...Object.values(data.parameters)
238
- ].filter(Boolean);
239
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
240
- name: names,
241
- root: file.path,
242
- path: getFile(operation).path
243
- }, key);
244
- }).filter(Boolean);
245
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
246
- baseName: file.baseName,
247
- path: file.path,
248
- meta: file.meta,
249
- banner: (0, __kubb_plugin_oas_utils.getBanner)({
250
- oas,
251
- output,
252
- config: pluginManager.config
253
- }),
254
- footer: (0, __kubb_plugin_oas_utils.getFooter)({
255
- oas,
256
- output
257
- }),
258
- children: [
259
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
260
- isTypeOnly: true,
261
- name: ["z"],
262
- path: importPath
263
- }),
264
- imports,
265
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Operations, {
266
- name,
267
- operations: transformedOperations
268
- })
269
- ]
270
- });
271
- }
272
- });
273
-
274
269
  //#endregion
275
270
  Object.defineProperty(exports, 'operationsGenerator', {
276
271
  enumerable: true,
@@ -284,4 +279,4 @@ Object.defineProperty(exports, 'zodGenerator', {
284
279
  return zodGenerator;
285
280
  }
286
281
  });
287
- //# sourceMappingURL=generators-B2hD7k6l.cjs.map
282
+ //# sourceMappingURL=generators-T3e_E7Uy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-T3e_E7Uy.cjs","names":["File","Operations","SchemaGenerator","options","schemaKeywords","pluginTsName","Fragment","File","path","Zod"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } 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 { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Fragment>\n )\n }\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: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,MAAa,6EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WAC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