@kubb/plugin-oas 0.0.0-canary-20240804130641 → 0.0.0-canary-20241104172400

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 (103) hide show
  1. package/README.md +14 -5
  2. package/dist/OperationGenerator-Bw6sj3Eb.d.cts +560 -0
  3. package/dist/OperationGenerator-Bw6sj3Eb.d.ts +560 -0
  4. package/dist/{Schema-D41ItX9C.d.ts → Schema-4FwWfdim.d.cts} +2 -13
  5. package/dist/{Schema-FGI5VPqc.d.cts → Schema-BlGtSgNB.d.ts} +2 -13
  6. package/dist/chunk-2TGWPVZN.cjs +92 -0
  7. package/dist/chunk-2TGWPVZN.cjs.map +1 -0
  8. package/dist/chunk-A3ROGKLW.cjs +752 -0
  9. package/dist/chunk-A3ROGKLW.cjs.map +1 -0
  10. package/dist/chunk-ABOQ73FL.cjs +36 -0
  11. package/dist/chunk-ABOQ73FL.cjs.map +1 -0
  12. package/dist/chunk-BG77DP54.js +30 -0
  13. package/dist/chunk-BG77DP54.js.map +1 -0
  14. package/dist/chunk-GF26SDHQ.js +28 -0
  15. package/dist/chunk-GF26SDHQ.js.map +1 -0
  16. package/dist/chunk-JA75IPYU.js +744 -0
  17. package/dist/chunk-JA75IPYU.js.map +1 -0
  18. package/dist/chunk-PADR76WZ.cjs +4 -0
  19. package/dist/chunk-PADR76WZ.cjs.map +1 -0
  20. package/dist/chunk-QAFBZLJA.cjs +48 -0
  21. package/dist/chunk-QAFBZLJA.cjs.map +1 -0
  22. package/dist/chunk-R47XMJ32.js +3 -0
  23. package/dist/chunk-R47XMJ32.js.map +1 -0
  24. package/dist/chunk-TNWNNVQW.js +88 -0
  25. package/dist/chunk-TNWNNVQW.js.map +1 -0
  26. package/dist/chunk-XNCEFOE6.js +45 -0
  27. package/dist/chunk-XNCEFOE6.js.map +1 -0
  28. package/dist/chunk-ZWHQ54JM.cjs +32 -0
  29. package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
  30. package/dist/components.cjs +20 -17
  31. package/dist/components.cjs.map +1 -1
  32. package/dist/components.d.cts +12 -9
  33. package/dist/components.d.ts +12 -9
  34. package/dist/components.js +3 -17
  35. package/dist/components.js.map +1 -1
  36. package/dist/generators.cjs +14 -0
  37. package/dist/generators.cjs.map +1 -0
  38. package/dist/generators.d.cts +9 -0
  39. package/dist/generators.d.ts +9 -0
  40. package/dist/generators.js +5 -0
  41. package/dist/generators.js.map +1 -0
  42. package/dist/hooks.cjs +90 -58
  43. package/dist/hooks.cjs.map +1 -1
  44. package/dist/hooks.d.cts +37 -10
  45. package/dist/hooks.d.ts +37 -10
  46. package/dist/hooks.js +79 -54
  47. package/dist/hooks.js.map +1 -1
  48. package/dist/index.cjs +277 -270
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +6 -78
  51. package/dist/index.d.ts +6 -78
  52. package/dist/index.js +235 -255
  53. package/dist/index.js.map +1 -1
  54. package/dist/utils.cjs +32 -87
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +8 -43
  57. package/dist/utils.d.ts +8 -43
  58. package/dist/utils.js +8 -86
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +21 -15
  61. package/src/OperationGenerator.ts +91 -64
  62. package/src/SchemaGenerator.ts +102 -22
  63. package/src/SchemaMapper.ts +24 -5
  64. package/src/components/Oas.tsx +9 -3
  65. package/src/components/Operation.tsx +1 -1
  66. package/src/components/Schema.tsx +2 -99
  67. package/src/generator.tsx +129 -0
  68. package/src/generators/index.ts +1 -0
  69. package/src/generators/jsonGenerator.ts +32 -0
  70. package/src/hooks/index.ts +2 -0
  71. package/src/hooks/useOperationManager.ts +56 -30
  72. package/src/hooks/useSchemaManager.ts +77 -0
  73. package/src/index.ts +5 -13
  74. package/src/plugin.ts +73 -69
  75. package/src/types.ts +29 -27
  76. package/src/utils/getParams.ts +2 -2
  77. package/src/utils/getSchemaFactory.ts +1 -1
  78. package/src/utils/index.ts +2 -2
  79. package/src/utils/parseFromConfig.ts +7 -7
  80. package/dist/OperationGenerator-BV6QRtkW.d.cts +0 -60
  81. package/dist/OperationGenerator-DO5tNGuT.d.ts +0 -60
  82. package/dist/SchemaMapper-CsBQ6eEx.d.cts +0 -248
  83. package/dist/SchemaMapper-CsBQ6eEx.d.ts +0 -248
  84. package/dist/chunk-CCPZYOTX.cjs +0 -695
  85. package/dist/chunk-CCPZYOTX.cjs.map +0 -1
  86. package/dist/chunk-CO7DS2KL.cjs +0 -35
  87. package/dist/chunk-CO7DS2KL.cjs.map +0 -1
  88. package/dist/chunk-EK7UO5ZW.js +0 -35
  89. package/dist/chunk-EK7UO5ZW.js.map +0 -1
  90. package/dist/chunk-KI3GNEKH.js +0 -3265
  91. package/dist/chunk-KI3GNEKH.js.map +0 -1
  92. package/dist/chunk-LRJFQCDO.js +0 -101
  93. package/dist/chunk-LRJFQCDO.js.map +0 -1
  94. package/dist/chunk-PFN2GSIC.cjs +0 -101
  95. package/dist/chunk-PFN2GSIC.cjs.map +0 -1
  96. package/dist/chunk-TL7TBM2U.cjs +0 -3265
  97. package/dist/chunk-TL7TBM2U.cjs.map +0 -1
  98. package/dist/chunk-UZLE6NIY.js +0 -695
  99. package/dist/chunk-UZLE6NIY.js.map +0 -1
  100. package/dist/types-Db0qp8u-.d.cts +0 -148
  101. package/dist/types-Db0qp8u-.d.ts +0 -148
  102. package/src/utils/getGroupedByTagFiles.ts +0 -82
  103. package/src/utils/refSorter.ts +0 -13
@@ -0,0 +1,9 @@
1
+ import { o as Generator, P as PluginOas } from './OperationGenerator-Bw6sj3Eb.js';
2
+ import '@kubb/core';
3
+ import '@kubb/fs/types';
4
+ import '@kubb/oas';
5
+ import '@kubb/react/types';
6
+
7
+ declare const jsonGenerator: Generator<PluginOas>;
8
+
9
+ export { jsonGenerator };
@@ -0,0 +1,5 @@
1
+ export { jsonGenerator } from './chunk-TNWNNVQW.js';
2
+ import './chunk-R47XMJ32.js';
3
+ import './chunk-GF26SDHQ.js';
4
+ //# sourceMappingURL=generators.js.map
5
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
package/dist/hooks.cjs CHANGED
@@ -1,60 +1,51 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ 'use strict';
2
2
 
3
+ var chunkA3ROGKLW_cjs = require('./chunk-A3ROGKLW.cjs');
4
+ require('./chunk-QAFBZLJA.cjs');
5
+ var chunkZWHQ54JM_cjs = require('./chunk-ZWHQ54JM.cjs');
6
+ var react = require('@kubb/react');
3
7
 
4
-
5
- var _chunkTL7TBM2Ucjs = require('./chunk-TL7TBM2U.cjs');
6
- require('./chunk-CCPZYOTX.cjs');
7
-
8
-
9
- var _chunkPFN2GSICcjs = require('./chunk-PFN2GSIC.cjs');
10
-
11
- // src/hooks/index.ts
12
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
13
-
14
- // src/hooks/useOas.ts
15
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
16
- var _react = require('@kubb/react');
17
8
  function useOas() {
18
- const { oas } = _react.useContext.call(void 0, _chunkTL7TBM2Ucjs.Oas.Context);
9
+ const { oas } = react.useContext(chunkZWHQ54JM_cjs.Oas.Context);
19
10
  if (!oas) {
20
11
  throw new Error("Oas is not defined");
21
12
  }
22
13
  return oas;
23
14
  }
24
-
25
- // src/hooks/useOperation.ts
26
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
27
-
28
15
  function useOperation() {
29
- const { operation } = _react.useContext.call(void 0, _chunkTL7TBM2Ucjs.Operation.Context);
16
+ const { operation } = react.useContext(chunkZWHQ54JM_cjs.Operation.Context);
30
17
  if (!operation) {
31
18
  throw new Error("Operation is not defined");
32
19
  }
33
20
  return operation;
34
21
  }
35
-
36
- // src/hooks/useOperationManager.ts
37
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
38
-
39
22
  function useOperationManager() {
40
- const { plugin, pluginManager } = _react.useApp.call(void 0, );
41
- const { generator } = _react.useContext.call(void 0, _chunkTL7TBM2Ucjs.Oas.Context);
42
- if (!generator) {
43
- throw new Error(`'generator' is not defined`);
44
- }
45
- const getName = (operation, { pluginKey = plugin.key, type }) => {
23
+ const { plugin, pluginManager } = react.useApp();
24
+ const { generator } = react.useContext(chunkZWHQ54JM_cjs.Oas.Context);
25
+ const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
46
26
  return pluginManager.resolveName({
47
- name: operation.getOperationId(),
27
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
48
28
  pluginKey,
49
29
  type
50
30
  });
51
31
  };
52
- const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
53
- const tag = _optionalChain([operation, 'access', _ => _.getTags, 'call', _2 => _2(), 'access', _3 => _3.at, 'call', _4 => _4(0), 'optionalAccess', _5 => _5.name]);
54
- const name = getName(operation, { type: "file", pluginKey });
32
+ const getSchemas = (operation, params) => {
33
+ if (!generator) {
34
+ throw new Error(`'generator' is not defined`);
35
+ }
36
+ return generator.getSchemas(operation, {
37
+ resolveName: (name) => pluginManager.resolveName({
38
+ name,
39
+ pluginKey: params?.pluginKey,
40
+ type: params?.type
41
+ })
42
+ });
43
+ };
44
+ const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = ".ts" } = {}) => {
45
+ const name = getName(operation, { type: "file", pluginKey, prefix, suffix });
55
46
  const file = pluginManager.getFile({
56
47
  name,
57
- extName,
48
+ extname,
58
49
  pluginKey,
59
50
  options: { type: "file", pluginKey, tag }
60
51
  });
@@ -69,6 +60,9 @@ function useOperationManager() {
69
60
  };
70
61
  };
71
62
  const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
63
+ if (!generator) {
64
+ throw new Error(`'generator' is not defined`);
65
+ }
72
66
  const schemas = generator.getSchemas(operation);
73
67
  const errors = (schemas.errors || []).reduce(
74
68
  (prev, acc) => {
@@ -85,23 +79,23 @@ function useOperationManager() {
85
79
  {}
86
80
  );
87
81
  return {
88
- request: _optionalChain([schemas, 'access', _6 => _6.request, 'optionalAccess', _7 => _7.name]) ? pluginManager.resolveName({
82
+ request: schemas.request?.name ? pluginManager.resolveName({
89
83
  name: schemas.request.name,
90
84
  pluginKey,
91
85
  type
92
86
  }) : void 0,
93
87
  parameters: {
94
- path: _optionalChain([schemas, 'access', _8 => _8.pathParams, 'optionalAccess', _9 => _9.name]) ? pluginManager.resolveName({
88
+ path: schemas.pathParams?.name ? pluginManager.resolveName({
95
89
  name: schemas.pathParams.name,
96
90
  pluginKey,
97
91
  type
98
92
  }) : void 0,
99
- query: _optionalChain([schemas, 'access', _10 => _10.queryParams, 'optionalAccess', _11 => _11.name]) ? pluginManager.resolveName({
93
+ query: schemas.queryParams?.name ? pluginManager.resolveName({
100
94
  name: schemas.queryParams.name,
101
95
  pluginKey,
102
96
  type
103
97
  }) : void 0,
104
- header: _optionalChain([schemas, 'access', _12 => _12.headerParams, 'optionalAccess', _13 => _13.name]) ? pluginManager.resolveName({
98
+ header: schemas.headerParams?.name ? pluginManager.resolveName({
105
99
  name: schemas.headerParams.name,
106
100
  pluginKey,
107
101
  type
@@ -126,23 +120,12 @@ function useOperationManager() {
126
120
  return {
127
121
  getName,
128
122
  getFile,
129
- getSchemas: (operation, params, forStatusCode) => generator.getSchemas(operation, {
130
- forStatusCode,
131
- resolveName: (name) => pluginManager.resolveName({
132
- name,
133
- pluginKey: _optionalChain([params, 'optionalAccess', _14 => _14.pluginKey]),
134
- type: _optionalChain([params, 'optionalAccess', _15 => _15.type])
135
- })
136
- }),
123
+ getSchemas,
137
124
  groupSchemasByName
138
125
  };
139
126
  }
140
-
141
- // src/hooks/useOperations.ts
142
- _chunkPFN2GSICcjs.init_cjs_shims.call(void 0, );
143
-
144
127
  function useOperations({ method, path } = {}) {
145
- const { operations } = _react.useContext.call(void 0, _chunkTL7TBM2Ucjs.Oas.Context);
128
+ const { operations } = react.useContext(chunkZWHQ54JM_cjs.Oas.Context);
146
129
  if (!operations) {
147
130
  throw new Error("Operations is not defined");
148
131
  }
@@ -155,11 +138,60 @@ function useOperations({ method, path } = {}) {
155
138
  }
156
139
  return items;
157
140
  }
141
+ function useSchema() {
142
+ const props = react.useContext(chunkZWHQ54JM_cjs.Schema.Context);
143
+ return props;
144
+ }
145
+ function useSchemaManager() {
146
+ const { mode, plugin, pluginManager, fileManager } = react.useApp();
147
+ const getName = (name, { pluginKey = plugin.key, type }) => {
148
+ return pluginManager.resolveName({
149
+ name,
150
+ pluginKey,
151
+ type
152
+ });
153
+ };
154
+ const getFile = (name, { mode: mode2 = "split", pluginKey = plugin.key, extname = ".ts", tag } = {}) => {
155
+ const resolvedName = mode2 === "single" ? "" : getName(name, { type: "file", pluginKey });
156
+ const file = pluginManager.getFile({
157
+ name: resolvedName,
158
+ extname,
159
+ pluginKey,
160
+ options: { type: "file", pluginKey, tag }
161
+ });
162
+ return {
163
+ ...file,
164
+ meta: {
165
+ ...file.meta,
166
+ name: resolvedName,
167
+ pluginKey
168
+ }
169
+ };
170
+ };
171
+ const getImports = (tree) => {
172
+ const refs = chunkA3ROGKLW_cjs.SchemaGenerator.deepSearch(tree, chunkA3ROGKLW_cjs.schemaKeywords.ref);
173
+ return refs?.map((item, i) => {
174
+ if (!item.args.path || !item.args.isImportable) {
175
+ return void 0;
176
+ }
177
+ return {
178
+ name: [item.args.name],
179
+ path: item.args.path
180
+ };
181
+ }).filter(Boolean);
182
+ };
183
+ return {
184
+ getName,
185
+ getFile,
186
+ getImports
187
+ };
188
+ }
158
189
 
159
-
160
-
161
-
162
-
163
-
164
- exports.useOas = useOas; exports.useOperation = useOperation; exports.useOperationManager = useOperationManager; exports.useOperations = useOperations; exports.useSchema = _chunkTL7TBM2Ucjs.useSchema;
190
+ exports.useOas = useOas;
191
+ exports.useOperation = useOperation;
192
+ exports.useOperationManager = useOperationManager;
193
+ exports.useOperations = useOperations;
194
+ exports.useSchema = useSchema;
195
+ exports.useSchemaManager = useSchemaManager;
196
+ //# sourceMappingURL=hooks.cjs.map
165
197
  //# sourceMappingURL=hooks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-oas/dist/hooks.cjs","../src/hooks/index.ts","../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts"],"names":["useContext"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACVA,8CAAA,CAAA;ADYA;AACA;AEbA,8CAAA,CAAA;AAAA,oCAA2B;AAMpB,SAAS,MAAA,CAAA,EAAkB;AAChC,EAAA,MAAM,EAAE,IAAI,EAAA,EAAI,+BAAA,qBAAW,CAAI,OAAO,CAAA;AAEtC,EAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,IAAA,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAAA,EACtC;AAEA,EAAA,OAAO,GAAA;AACT;AFSA;AACA;AGxBA,8CAAA,CAAA;AAAA;AASO,SAAS,YAAA,CAAA,EAA8B;AAC5C,EAAA,MAAM,EAAE,UAAU,EAAA,EAAIA,+BAAAA,2BAAW,CAAU,OAAO,CAAA;AAElD,EAAA,GAAA,CAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,0BAA0B,CAAA;AAAA,EAC5C;AAEA,EAAA,OAAO,SAAA;AACT;AHiBA;AACA;AInCA,8CAAA,CAAA;AAAA;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nB,IAAA,kBAAM,MAAA,+BAAQ;AAAA,MAChB,CAAC;AAAA,IACL,CAAC,CAAA;AAAA,IACH;AAAA,EACF,CAAA;AACF;AJvBA;AACA;AK5IA,8CAAA,CAAA;AAAA;AAsBO,SAAS,aAAA,CAAc,EAAE,MAAA,EAAQ,KAAK,EAAA,EAAwB,CAAC,CAAA,EAAgB;AACpF,EAAA,MAAM,EAAE,WAAW,EAAA,EAAIA,+BAAAA,qBAAW,CAAI,OAAO,CAAA;AAE7C,EAAA,GAAA,CAAI,CAAC,UAAA,EAAY;AACf,IAAA,MAAM,IAAI,KAAA,CAAM,2BAA2B,CAAA;AAAA,EAC7C;AACA,EAAA,IAAI,MAAA,EAAQ,UAAA;AAEZ,EAAA,GAAA,CAAI,IAAA,EAAM;AACR,IAAA,MAAA,EAAQ,KAAA,CAAM,MAAA,CAAO,CAAC,IAAA,EAAA,GAAS,IAAA,CAAK,KAAA,IAAS,IAAI,CAAA;AAAA,EACnD;AAEA,EAAA,GAAA,CAAI,MAAA,EAAQ;AACV,IAAA,MAAA,EAAQ,KAAA,CAAM,MAAA,CAAO,CAAC,IAAA,EAAA,GAAS,IAAA,CAAK,OAAA,IAAW,MAAM,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,KAAA;AACT;ALsHA;AACE;AACA;AACA;AACA;AACA;AACF,wMAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-oas/dist/hooks.cjs","sourcesContent":[null,"export { useOas } from './useOas.ts'\nexport { useOperation } from './useOperation.ts'\nexport { useOperationManager } from './useOperationManager.ts'\nexport { useOperations } from './useOperations.ts'\nexport { useSchema } from './useSchema.ts'\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\ntype SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (operation: OperationType, params?: { pluginKey?: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta>\n groupSchemasByName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => SchemaNames\n getSchemas: (\n operation: Operation,\n params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] },\n forStatusCode?: string | number,\n ) => OperationSchemas\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: operation.getOperationId(),\n pluginKey,\n type,\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {\n // needed for the `output.group`\n const tag = operation.getTags().at(0)?.name\n const name = getName(operation, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name,\n extName,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n tag,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n [schemas.response.statusCode || 'default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas: (operation, params, forStatusCode) =>\n generator.getSchemas(operation, {\n forStatusCode,\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n }),\n groupSchemasByName,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"names":["useContext","Oas","Operation","useApp","Schema","mode","SchemaGenerator","schemaKeywords"],"mappings":";;;;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAAA,gBAAA,CAAWC,sBAAI,OAAO,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcD,GAAAA,gBAAAA,CAAWE,4BAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAG5C,EAAO,OAAA,SAAA;AACT;AC0CO,SAAS,mBAAiD,GAAA;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAc,EAAA,GAAIC,YAAO,EAAA;AACzC,EAAA,MAAM,EAAE,SAAA,EAAcH,GAAAA,gBAAAA,CAAWC,sBAAI,OAAO,CAAA;AAE5C,EAAA,MAAM,OAAgD,GAAA,CAAC,SAAW,EAAA,EAAE,MAAS,GAAA,EAAA,EAAI,MAAS,GAAA,EAAA,EAAI,SAAY,GAAA,MAAA,CAAO,GA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AAA,YAAA;AAAA,QACN;AAAA;AACF,KACF;AAAA,GACF;AAEA,EAAM,MAAA,UAAA,GAAmD,CAAC,IAAS,KAAA;AACjE,IAAA,MAAM,IAAO,GAAAC,iCAAA,CAAgB,UAAW,CAAA,IAAA,EAAMC,iCAAe,GAAG,CAAA;AAEhE,IAAA,OAAO,IACH,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,CAAM,KAAA;AACjB,MAAA,IAAI,CAAC,IAAK,CAAA,IAAA,CAAK,QAAQ,CAAC,IAAA,CAAK,KAAK,YAAc,EAAA;AAC9C,QAAO,OAAA,KAAA,CAAA;AAAA;AAGT,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA;AAAA,OAClB;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,GACnB;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"hooks.cjs","sourcesContent":["import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n tag?: string\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n //TODO replace tag with group\n const getFile: UseOperationManagerResult['getFile'] = (\n operation,\n { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = '.ts' } = {},\n ) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n tag,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n [schemas.response.statusCode || 'default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import { useApp } from '@kubb/react'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Mode } from '@kubb/fs/types'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (name: string, params?: { pluginKey?: Plugin['key']; mode?: Mode; extname?: KubbFile.Extname; tag?: string }) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const { mode, plugin, pluginManager, fileManager } = useApp()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n //TODO replace tag with group\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', tag } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item, i) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"]}
package/dist/hooks.d.cts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
2
  import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
- import { f as OperationSchemas } from './types-Db0qp8u-.cjs';
5
- import { a as SchemaContextProps } from './Schema-FGI5VPqc.cjs';
6
- import '@kubb/oas/parser';
4
+ import { Mode } from '@kubb/fs/types';
5
+ import { w as OperationSchemas, f as Schema } from './OperationGenerator-Bw6sj3Eb.cjs';
6
+ import { a as SchemaContextProps } from './Schema-4FwWfdim.cjs';
7
+ import '@kubb/react/types';
7
8
  import 'react';
8
- import '@kubb/react';
9
- import './SchemaMapper-CsBQ6eEx.cjs';
10
9
 
11
10
  declare function useOas(): Oas;
12
11
 
@@ -15,7 +14,7 @@ declare function useOas(): Oas;
15
14
  */
16
15
  declare function useOperation(): Operation;
17
16
 
18
- type FileMeta = FileMetaBase & {
17
+ type FileMeta$1 = FileMetaBase & {
19
18
  pluginKey: Plugin['key'];
20
19
  name: string;
21
20
  tag?: string;
@@ -34,13 +33,18 @@ type SchemaNames = {
34
33
  };
35
34
  type UseOperationManagerResult = {
36
35
  getName: (operation: Operation, params: {
36
+ prefix?: string;
37
+ suffix?: string;
37
38
  pluginKey?: Plugin['key'];
38
39
  type: ResolveNameParams['type'];
39
40
  }) => string;
40
41
  getFile: (operation: Operation, params?: {
42
+ prefix?: string;
43
+ suffix?: string;
41
44
  pluginKey?: Plugin['key'];
42
- extName?: KubbFile.Extname;
43
- }) => KubbFile.File<FileMeta>;
45
+ extname?: KubbFile.Extname;
46
+ tag?: string;
47
+ }) => KubbFile.File<FileMeta$1>;
44
48
  groupSchemasByName: (operation: Operation, params: {
45
49
  pluginKey?: Plugin['key'];
46
50
  type: ResolveNameParams['type'];
@@ -48,7 +52,7 @@ type UseOperationManagerResult = {
48
52
  getSchemas: (operation: Operation, params?: {
49
53
  pluginKey?: Plugin['key'];
50
54
  type?: ResolveNameParams['type'];
51
- }, forStatusCode?: string | number) => OperationSchemas;
55
+ }) => OperationSchemas;
52
56
  };
53
57
  /**
54
58
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
@@ -78,4 +82,27 @@ type UseSchemaResult = SchemaContextProps;
78
82
  */
79
83
  declare function useSchema(): UseSchemaResult;
80
84
 
81
- export { useOas, useOperation, useOperationManager, useOperations, useSchema };
85
+ type FileMeta = FileMetaBase & {
86
+ pluginKey: Plugin['key'];
87
+ name: string;
88
+ tag?: string;
89
+ };
90
+ type UseSchemaManagerResult = {
91
+ getName: (name: string, params: {
92
+ pluginKey?: Plugin['key'];
93
+ type: ResolveNameParams['type'];
94
+ }) => string;
95
+ getFile: (name: string, params?: {
96
+ pluginKey?: Plugin['key'];
97
+ mode?: Mode;
98
+ extname?: KubbFile.Extname;
99
+ tag?: string;
100
+ }) => KubbFile.File<FileMeta>;
101
+ getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
102
+ };
103
+ /**
104
+ * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
105
+ */
106
+ declare function useSchemaManager(): UseSchemaManagerResult;
107
+
108
+ export { type SchemaNames, useOas, useOperation, useOperationManager, useOperations, useSchema, useSchemaManager };
package/dist/hooks.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { Oas, Operation, HttpMethod } from '@kubb/oas';
2
2
  import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
3
3
  import * as KubbFile from '@kubb/fs/types';
4
- import { f as OperationSchemas } from './types-Db0qp8u-.js';
5
- import { a as SchemaContextProps } from './Schema-D41ItX9C.js';
6
- import '@kubb/oas/parser';
4
+ import { Mode } from '@kubb/fs/types';
5
+ import { w as OperationSchemas, f as Schema } from './OperationGenerator-Bw6sj3Eb.js';
6
+ import { a as SchemaContextProps } from './Schema-BlGtSgNB.js';
7
+ import '@kubb/react/types';
7
8
  import 'react';
8
- import '@kubb/react';
9
- import './SchemaMapper-CsBQ6eEx.js';
10
9
 
11
10
  declare function useOas(): Oas;
12
11
 
@@ -15,7 +14,7 @@ declare function useOas(): Oas;
15
14
  */
16
15
  declare function useOperation(): Operation;
17
16
 
18
- type FileMeta = FileMetaBase & {
17
+ type FileMeta$1 = FileMetaBase & {
19
18
  pluginKey: Plugin['key'];
20
19
  name: string;
21
20
  tag?: string;
@@ -34,13 +33,18 @@ type SchemaNames = {
34
33
  };
35
34
  type UseOperationManagerResult = {
36
35
  getName: (operation: Operation, params: {
36
+ prefix?: string;
37
+ suffix?: string;
37
38
  pluginKey?: Plugin['key'];
38
39
  type: ResolveNameParams['type'];
39
40
  }) => string;
40
41
  getFile: (operation: Operation, params?: {
42
+ prefix?: string;
43
+ suffix?: string;
41
44
  pluginKey?: Plugin['key'];
42
- extName?: KubbFile.Extname;
43
- }) => KubbFile.File<FileMeta>;
45
+ extname?: KubbFile.Extname;
46
+ tag?: string;
47
+ }) => KubbFile.File<FileMeta$1>;
44
48
  groupSchemasByName: (operation: Operation, params: {
45
49
  pluginKey?: Plugin['key'];
46
50
  type: ResolveNameParams['type'];
@@ -48,7 +52,7 @@ type UseOperationManagerResult = {
48
52
  getSchemas: (operation: Operation, params?: {
49
53
  pluginKey?: Plugin['key'];
50
54
  type?: ResolveNameParams['type'];
51
- }, forStatusCode?: string | number) => OperationSchemas;
55
+ }) => OperationSchemas;
52
56
  };
53
57
  /**
54
58
  * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
@@ -78,4 +82,27 @@ type UseSchemaResult = SchemaContextProps;
78
82
  */
79
83
  declare function useSchema(): UseSchemaResult;
80
84
 
81
- export { useOas, useOperation, useOperationManager, useOperations, useSchema };
85
+ type FileMeta = FileMetaBase & {
86
+ pluginKey: Plugin['key'];
87
+ name: string;
88
+ tag?: string;
89
+ };
90
+ type UseSchemaManagerResult = {
91
+ getName: (name: string, params: {
92
+ pluginKey?: Plugin['key'];
93
+ type: ResolveNameParams['type'];
94
+ }) => string;
95
+ getFile: (name: string, params?: {
96
+ pluginKey?: Plugin['key'];
97
+ mode?: Mode;
98
+ extname?: KubbFile.Extname;
99
+ tag?: string;
100
+ }) => KubbFile.File<FileMeta>;
101
+ getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
102
+ };
103
+ /**
104
+ * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
105
+ */
106
+ declare function useSchemaManager(): UseSchemaManagerResult;
107
+
108
+ export { type SchemaNames, useOas, useOperation, useOperationManager, useOperations, useSchema, useSchemaManager };
package/dist/hooks.js CHANGED
@@ -1,19 +1,8 @@
1
- import {
2
- Oas,
3
- Operation,
4
- useSchema
5
- } from "./chunk-KI3GNEKH.js";
6
- import "./chunk-UZLE6NIY.js";
7
- import {
8
- init_esm_shims
9
- } from "./chunk-LRJFQCDO.js";
1
+ import { SchemaGenerator, schemaKeywords } from './chunk-JA75IPYU.js';
2
+ import './chunk-XNCEFOE6.js';
3
+ import { Oas, Operation, Schema } from './chunk-GF26SDHQ.js';
4
+ import { useContext, useApp } from '@kubb/react';
10
5
 
11
- // src/hooks/index.ts
12
- init_esm_shims();
13
-
14
- // src/hooks/useOas.ts
15
- init_esm_shims();
16
- import { useContext } from "@kubb/react";
17
6
  function useOas() {
18
7
  const { oas } = useContext(Oas.Context);
19
8
  if (!oas) {
@@ -21,40 +10,40 @@ function useOas() {
21
10
  }
22
11
  return oas;
23
12
  }
24
-
25
- // src/hooks/useOperation.ts
26
- init_esm_shims();
27
- import { useContext as useContext2 } from "@kubb/react";
28
13
  function useOperation() {
29
- const { operation } = useContext2(Operation.Context);
14
+ const { operation } = useContext(Operation.Context);
30
15
  if (!operation) {
31
16
  throw new Error("Operation is not defined");
32
17
  }
33
18
  return operation;
34
19
  }
35
-
36
- // src/hooks/useOperationManager.ts
37
- init_esm_shims();
38
- import { useApp, useContext as useContext3 } from "@kubb/react";
39
20
  function useOperationManager() {
40
21
  const { plugin, pluginManager } = useApp();
41
- const { generator } = useContext3(Oas.Context);
42
- if (!generator) {
43
- throw new Error(`'generator' is not defined`);
44
- }
45
- const getName = (operation, { pluginKey = plugin.key, type }) => {
22
+ const { generator } = useContext(Oas.Context);
23
+ const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
46
24
  return pluginManager.resolveName({
47
- name: operation.getOperationId(),
25
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
48
26
  pluginKey,
49
27
  type
50
28
  });
51
29
  };
52
- const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
53
- const tag = operation.getTags().at(0)?.name;
54
- const name = getName(operation, { type: "file", pluginKey });
30
+ const getSchemas = (operation, params) => {
31
+ if (!generator) {
32
+ throw new Error(`'generator' is not defined`);
33
+ }
34
+ return generator.getSchemas(operation, {
35
+ resolveName: (name) => pluginManager.resolveName({
36
+ name,
37
+ pluginKey: params?.pluginKey,
38
+ type: params?.type
39
+ })
40
+ });
41
+ };
42
+ const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = ".ts" } = {}) => {
43
+ const name = getName(operation, { type: "file", pluginKey, prefix, suffix });
55
44
  const file = pluginManager.getFile({
56
45
  name,
57
- extName,
46
+ extname,
58
47
  pluginKey,
59
48
  options: { type: "file", pluginKey, tag }
60
49
  });
@@ -69,6 +58,9 @@ function useOperationManager() {
69
58
  };
70
59
  };
71
60
  const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
61
+ if (!generator) {
62
+ throw new Error(`'generator' is not defined`);
63
+ }
72
64
  const schemas = generator.getSchemas(operation);
73
65
  const errors = (schemas.errors || []).reduce(
74
66
  (prev, acc) => {
@@ -126,23 +118,12 @@ function useOperationManager() {
126
118
  return {
127
119
  getName,
128
120
  getFile,
129
- getSchemas: (operation, params, forStatusCode) => generator.getSchemas(operation, {
130
- forStatusCode,
131
- resolveName: (name) => pluginManager.resolveName({
132
- name,
133
- pluginKey: params?.pluginKey,
134
- type: params?.type
135
- })
136
- }),
121
+ getSchemas,
137
122
  groupSchemasByName
138
123
  };
139
124
  }
140
-
141
- // src/hooks/useOperations.ts
142
- init_esm_shims();
143
- import { useContext as useContext4 } from "@kubb/react";
144
125
  function useOperations({ method, path } = {}) {
145
- const { operations } = useContext4(Oas.Context);
126
+ const { operations } = useContext(Oas.Context);
146
127
  if (!operations) {
147
128
  throw new Error("Operations is not defined");
148
129
  }
@@ -155,11 +136,55 @@ function useOperations({ method, path } = {}) {
155
136
  }
156
137
  return items;
157
138
  }
158
- export {
159
- useOas,
160
- useOperation,
161
- useOperationManager,
162
- useOperations,
163
- useSchema
164
- };
139
+ function useSchema() {
140
+ const props = useContext(Schema.Context);
141
+ return props;
142
+ }
143
+ function useSchemaManager() {
144
+ const { mode, plugin, pluginManager, fileManager } = useApp();
145
+ const getName = (name, { pluginKey = plugin.key, type }) => {
146
+ return pluginManager.resolveName({
147
+ name,
148
+ pluginKey,
149
+ type
150
+ });
151
+ };
152
+ const getFile = (name, { mode: mode2 = "split", pluginKey = plugin.key, extname = ".ts", tag } = {}) => {
153
+ const resolvedName = mode2 === "single" ? "" : getName(name, { type: "file", pluginKey });
154
+ const file = pluginManager.getFile({
155
+ name: resolvedName,
156
+ extname,
157
+ pluginKey,
158
+ options: { type: "file", pluginKey, tag }
159
+ });
160
+ return {
161
+ ...file,
162
+ meta: {
163
+ ...file.meta,
164
+ name: resolvedName,
165
+ pluginKey
166
+ }
167
+ };
168
+ };
169
+ const getImports = (tree) => {
170
+ const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
171
+ return refs?.map((item, i) => {
172
+ if (!item.args.path || !item.args.isImportable) {
173
+ return void 0;
174
+ }
175
+ return {
176
+ name: [item.args.name],
177
+ path: item.args.path
178
+ };
179
+ }).filter(Boolean);
180
+ };
181
+ return {
182
+ getName,
183
+ getFile,
184
+ getImports
185
+ };
186
+ }
187
+
188
+ export { useOas, useOperation, useOperationManager, useOperations, useSchema, useSchemaManager };
189
+ //# sourceMappingURL=hooks.js.map
165
190
  //# sourceMappingURL=hooks.js.map