@kubb/plugin-oas 3.0.0-alpha.9 → 3.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +14 -5
  2. package/dist/OperationGenerator-Dko8Xtd7.d.cts +561 -0
  3. package/dist/OperationGenerator-Dko8Xtd7.d.ts +561 -0
  4. package/dist/{Schema-B1vcPGiK.d.ts → Schema-C2cbPYX1.d.cts} +1 -12
  5. package/dist/{Schema-DoSFh7Qd.d.cts → Schema-CbtIvprh.d.ts} +1 -12
  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-SZDO532A.js.map → chunk-QAFBZLJA.cjs.map} +1 -1
  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 -12
  31. package/dist/components.cjs.map +1 -1
  32. package/dist/components.d.cts +3 -6
  33. package/dist/components.d.ts +3 -6
  34. package/dist/components.js +3 -12
  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 -57
  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 -53
  47. package/dist/hooks.js.map +1 -1
  48. package/dist/index.cjs +142 -189
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +2 -5
  51. package/dist/index.d.ts +2 -5
  52. package/dist/index.js +82 -156
  53. package/dist/index.js.map +1 -1
  54. package/dist/utils.cjs +32 -45
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +4 -13
  57. package/dist/utils.d.ts +4 -13
  58. package/dist/utils.js +8 -44
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +20 -14
  61. package/src/OperationGenerator.ts +30 -39
  62. package/src/SchemaGenerator.ts +70 -11
  63. package/src/SchemaMapper.ts +24 -5
  64. package/src/components/Schema.tsx +1 -99
  65. package/src/generator.tsx +22 -18
  66. package/src/generators/index.ts +1 -0
  67. package/src/generators/jsonGenerator.ts +32 -0
  68. package/src/hooks/index.ts +2 -0
  69. package/src/hooks/useOperationManager.ts +56 -31
  70. package/src/hooks/useSchemaManager.ts +77 -0
  71. package/src/index.ts +2 -4
  72. package/src/plugin.ts +69 -56
  73. package/src/types.ts +29 -22
  74. package/src/utils/getParams.ts +1 -1
  75. package/src/utils/getSchemaFactory.ts +1 -1
  76. package/src/utils/index.ts +0 -1
  77. package/src/utils/parseFromConfig.ts +7 -7
  78. package/dist/OperationGenerator-By5WOmWB.d.ts +0 -165
  79. package/dist/OperationGenerator-Gd1X7wUz.d.cts +0 -165
  80. package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
  81. package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
  82. package/dist/chunk-75BIOXB7.cjs +0 -7
  83. package/dist/chunk-75BIOXB7.cjs.map +0 -1
  84. package/dist/chunk-IAUV3UKH.cjs +0 -3965
  85. package/dist/chunk-IAUV3UKH.cjs.map +0 -1
  86. package/dist/chunk-M347763D.js +0 -3965
  87. package/dist/chunk-M347763D.js.map +0 -1
  88. package/dist/chunk-N7EEVJA6.js +0 -35
  89. package/dist/chunk-N7EEVJA6.js.map +0 -1
  90. package/dist/chunk-NU4F7G47.cjs +0 -89
  91. package/dist/chunk-NU4F7G47.cjs.map +0 -1
  92. package/dist/chunk-O76YQFZB.cjs +0 -35
  93. package/dist/chunk-O76YQFZB.cjs.map +0 -1
  94. package/dist/chunk-SQ64ESS4.js +0 -7
  95. package/dist/chunk-SQ64ESS4.js.map +0 -1
  96. package/dist/chunk-SZDO532A.js +0 -89
  97. package/dist/types-CZTUCaE5.d.cts +0 -145
  98. package/dist/types-CZTUCaE5.d.ts +0 -145
  99. package/src/utils/refSorter.ts +0 -13
package/dist/hooks.cjs CHANGED
@@ -1,59 +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 _chunkIAUV3UKHcjs = require('./chunk-IAUV3UKH.cjs');
6
-
7
-
8
- var _chunkNU4F7G47cjs = require('./chunk-NU4F7G47.cjs');
9
-
10
- // src/hooks/index.ts
11
- _chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
12
-
13
- // src/hooks/useOas.ts
14
- _chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
15
- var _react = require('@kubb/react');
16
8
  function useOas() {
17
- const { oas } = _react.useContext.call(void 0, _chunkIAUV3UKHcjs.Oas.Context);
9
+ const { oas } = react.useContext(chunkZWHQ54JM_cjs.Oas.Context);
18
10
  if (!oas) {
19
11
  throw new Error("Oas is not defined");
20
12
  }
21
13
  return oas;
22
14
  }
23
-
24
- // src/hooks/useOperation.ts
25
- _chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
26
-
27
15
  function useOperation() {
28
- const { operation } = _react.useContext.call(void 0, _chunkIAUV3UKHcjs.Operation.Context);
16
+ const { operation } = react.useContext(chunkZWHQ54JM_cjs.Operation.Context);
29
17
  if (!operation) {
30
18
  throw new Error("Operation is not defined");
31
19
  }
32
20
  return operation;
33
21
  }
34
-
35
- // src/hooks/useOperationManager.ts
36
- _chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
37
-
38
22
  function useOperationManager() {
39
- const { plugin, pluginManager } = _react.useApp.call(void 0, );
40
- const { generator } = _react.useContext.call(void 0, _chunkIAUV3UKHcjs.Oas.Context);
41
- if (!generator) {
42
- throw new Error(`'generator' is not defined`);
43
- }
44
- 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 }) => {
45
26
  return pluginManager.resolveName({
46
- name: operation.getOperationId(),
27
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
47
28
  pluginKey,
48
29
  type
49
30
  });
50
31
  };
51
- const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
52
- const tag = _optionalChain([operation, 'access', _ => _.getTags, 'call', _2 => _2(), 'access', _3 => _3.at, 'call', _4 => _4(0), 'optionalAccess', _5 => _5.name]);
53
- 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 });
54
46
  const file = pluginManager.getFile({
55
47
  name,
56
- extName,
48
+ extname,
57
49
  pluginKey,
58
50
  options: { type: "file", pluginKey, tag }
59
51
  });
@@ -68,6 +60,9 @@ function useOperationManager() {
68
60
  };
69
61
  };
70
62
  const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
63
+ if (!generator) {
64
+ throw new Error(`'generator' is not defined`);
65
+ }
71
66
  const schemas = generator.getSchemas(operation);
72
67
  const errors = (schemas.errors || []).reduce(
73
68
  (prev, acc) => {
@@ -84,23 +79,23 @@ function useOperationManager() {
84
79
  {}
85
80
  );
86
81
  return {
87
- request: _optionalChain([schemas, 'access', _6 => _6.request, 'optionalAccess', _7 => _7.name]) ? pluginManager.resolveName({
82
+ request: schemas.request?.name ? pluginManager.resolveName({
88
83
  name: schemas.request.name,
89
84
  pluginKey,
90
85
  type
91
86
  }) : void 0,
92
87
  parameters: {
93
- path: _optionalChain([schemas, 'access', _8 => _8.pathParams, 'optionalAccess', _9 => _9.name]) ? pluginManager.resolveName({
88
+ path: schemas.pathParams?.name ? pluginManager.resolveName({
94
89
  name: schemas.pathParams.name,
95
90
  pluginKey,
96
91
  type
97
92
  }) : void 0,
98
- query: _optionalChain([schemas, 'access', _10 => _10.queryParams, 'optionalAccess', _11 => _11.name]) ? pluginManager.resolveName({
93
+ query: schemas.queryParams?.name ? pluginManager.resolveName({
99
94
  name: schemas.queryParams.name,
100
95
  pluginKey,
101
96
  type
102
97
  }) : void 0,
103
- header: _optionalChain([schemas, 'access', _12 => _12.headerParams, 'optionalAccess', _13 => _13.name]) ? pluginManager.resolveName({
98
+ header: schemas.headerParams?.name ? pluginManager.resolveName({
104
99
  name: schemas.headerParams.name,
105
100
  pluginKey,
106
101
  type
@@ -125,23 +120,12 @@ function useOperationManager() {
125
120
  return {
126
121
  getName,
127
122
  getFile,
128
- getSchemas: (operation, params, forStatusCode) => generator.getSchemas(operation, {
129
- forStatusCode,
130
- resolveName: (name) => pluginManager.resolveName({
131
- name,
132
- pluginKey: _optionalChain([params, 'optionalAccess', _14 => _14.pluginKey]),
133
- type: _optionalChain([params, 'optionalAccess', _15 => _15.type])
134
- })
135
- }),
123
+ getSchemas,
136
124
  groupSchemasByName
137
125
  };
138
126
  }
139
-
140
- // src/hooks/useOperations.ts
141
- _chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
142
-
143
127
  function useOperations({ method, path } = {}) {
144
- const { operations } = _react.useContext.call(void 0, _chunkIAUV3UKHcjs.Oas.Context);
128
+ const { operations } = react.useContext(chunkZWHQ54JM_cjs.Oas.Context);
145
129
  if (!operations) {
146
130
  throw new Error("Operations is not defined");
147
131
  }
@@ -154,11 +138,60 @@ function useOperations({ method, path } = {}) {
154
138
  }
155
139
  return items;
156
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
+ }
157
189
 
158
-
159
-
160
-
161
-
162
-
163
- exports.useOas = useOas; exports.useOperation = useOperation; exports.useOperationManager = useOperationManager; exports.useOperations = useOperations; exports.useSchema = _chunkIAUV3UKHcjs.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
164
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;AACE;AACF,wDAA6B;AAC7B;AACA;ACTA,8CAA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,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;ALqHA;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 //TODO replace with group\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,CA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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 { e as OperationSchemas } from './types-CZTUCaE5.cjs';
5
- import { a as SchemaContextProps } from './Schema-DoSFh7Qd.cjs';
6
- import '@kubb/oas/parser';
7
- import 'react';
4
+ import { Mode } from '@kubb/fs/types';
5
+ import { w as OperationSchemas, f as Schema } from './OperationGenerator-Dko8Xtd7.cjs';
6
+ import { a as SchemaContextProps } from './Schema-C2cbPYX1.cjs';
8
7
  import '@kubb/react/types';
9
- import './SchemaMapper-sGcY1xL5.cjs';
8
+ import 'react';
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 { e as OperationSchemas } from './types-CZTUCaE5.js';
5
- import { a as SchemaContextProps } from './Schema-B1vcPGiK.js';
6
- import '@kubb/oas/parser';
7
- import 'react';
4
+ import { Mode } from '@kubb/fs/types';
5
+ import { w as OperationSchemas, f as Schema } from './OperationGenerator-Dko8Xtd7.js';
6
+ import { a as SchemaContextProps } from './Schema-CbtIvprh.js';
8
7
  import '@kubb/react/types';
9
- import './SchemaMapper-sGcY1xL5.js';
8
+ import 'react';
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,18 +1,8 @@
1
- import {
2
- Oas,
3
- Operation,
4
- useSchema
5
- } from "./chunk-M347763D.js";
6
- import {
7
- init_esm_shims
8
- } from "./chunk-SZDO532A.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';
9
5
 
10
- // src/hooks/index.ts
11
- init_esm_shims();
12
-
13
- // src/hooks/useOas.ts
14
- init_esm_shims();
15
- import { useContext } from "@kubb/react";
16
6
  function useOas() {
17
7
  const { oas } = useContext(Oas.Context);
18
8
  if (!oas) {
@@ -20,40 +10,40 @@ function useOas() {
20
10
  }
21
11
  return oas;
22
12
  }
23
-
24
- // src/hooks/useOperation.ts
25
- init_esm_shims();
26
- import { useContext as useContext2 } from "@kubb/react";
27
13
  function useOperation() {
28
- const { operation } = useContext2(Operation.Context);
14
+ const { operation } = useContext(Operation.Context);
29
15
  if (!operation) {
30
16
  throw new Error("Operation is not defined");
31
17
  }
32
18
  return operation;
33
19
  }
34
-
35
- // src/hooks/useOperationManager.ts
36
- init_esm_shims();
37
- import { useApp, useContext as useContext3 } from "@kubb/react";
38
20
  function useOperationManager() {
39
21
  const { plugin, pluginManager } = useApp();
40
- const { generator } = useContext3(Oas.Context);
41
- if (!generator) {
42
- throw new Error(`'generator' is not defined`);
43
- }
44
- const getName = (operation, { pluginKey = plugin.key, type }) => {
22
+ const { generator } = useContext(Oas.Context);
23
+ const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
45
24
  return pluginManager.resolveName({
46
- name: operation.getOperationId(),
25
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
47
26
  pluginKey,
48
27
  type
49
28
  });
50
29
  };
51
- const getFile = (operation, { pluginKey = plugin.key, extName = ".ts" } = {}) => {
52
- const tag = operation.getTags().at(0)?.name;
53
- 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 });
54
44
  const file = pluginManager.getFile({
55
45
  name,
56
- extName,
46
+ extname,
57
47
  pluginKey,
58
48
  options: { type: "file", pluginKey, tag }
59
49
  });
@@ -68,6 +58,9 @@ function useOperationManager() {
68
58
  };
69
59
  };
70
60
  const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
61
+ if (!generator) {
62
+ throw new Error(`'generator' is not defined`);
63
+ }
71
64
  const schemas = generator.getSchemas(operation);
72
65
  const errors = (schemas.errors || []).reduce(
73
66
  (prev, acc) => {
@@ -125,23 +118,12 @@ function useOperationManager() {
125
118
  return {
126
119
  getName,
127
120
  getFile,
128
- getSchemas: (operation, params, forStatusCode) => generator.getSchemas(operation, {
129
- forStatusCode,
130
- resolveName: (name) => pluginManager.resolveName({
131
- name,
132
- pluginKey: params?.pluginKey,
133
- type: params?.type
134
- })
135
- }),
121
+ getSchemas,
136
122
  groupSchemasByName
137
123
  };
138
124
  }
139
-
140
- // src/hooks/useOperations.ts
141
- init_esm_shims();
142
- import { useContext as useContext4 } from "@kubb/react";
143
125
  function useOperations({ method, path } = {}) {
144
- const { operations } = useContext4(Oas.Context);
126
+ const { operations } = useContext(Oas.Context);
145
127
  if (!operations) {
146
128
  throw new Error("Operations is not defined");
147
129
  }
@@ -154,11 +136,55 @@ function useOperations({ method, path } = {}) {
154
136
  }
155
137
  return items;
156
138
  }
157
- export {
158
- useOas,
159
- useOperation,
160
- useOperationManager,
161
- useOperations,
162
- useSchema
163
- };
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
164
190
  //# sourceMappingURL=hooks.js.map