@kubb/plugin-oas 3.0.0-alpha.9 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/OperationGenerator-BgQeGRzk.d.cts +550 -0
- package/dist/OperationGenerator-BgQeGRzk.d.ts +550 -0
- package/dist/{Schema-B1vcPGiK.d.ts → Schema-1iM2I0dK.d.ts} +1 -12
- package/dist/{Schema-DoSFh7Qd.d.cts → Schema-5o-c5UOy.d.cts} +1 -12
- package/dist/chunk-ABOQ73FL.cjs +36 -0
- package/dist/chunk-ABOQ73FL.cjs.map +1 -0
- package/dist/chunk-BG77DP54.js +30 -0
- package/dist/chunk-BG77DP54.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-QAFBZLJA.cjs +48 -0
- package/dist/chunk-QAFBZLJA.cjs.map +1 -0
- package/dist/chunk-QT6ZFRNJ.cjs +752 -0
- package/dist/chunk-QT6ZFRNJ.cjs.map +1 -0
- package/dist/chunk-QWO5NQGQ.js +88 -0
- package/dist/chunk-QWO5NQGQ.js.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/chunk-SR63CBLH.cjs +92 -0
- package/dist/chunk-SR63CBLH.cjs.map +1 -0
- package/dist/chunk-V2JO6RHI.js +744 -0
- package/dist/chunk-V2JO6RHI.js.map +1 -0
- package/dist/chunk-XNCEFOE6.js +45 -0
- package/dist/chunk-XNCEFOE6.js.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +3 -6
- package/dist/components.d.ts +3 -6
- package/dist/components.js +3 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +102 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +41 -10
- package/dist/hooks.d.ts +41 -10
- package/dist/hooks.js +91 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +134 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +68 -146
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -45
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -13
- package/dist/utils.d.ts +4 -13
- package/dist/utils.js +8 -44
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +11 -23
- package/src/SchemaGenerator.ts +68 -9
- package/src/SchemaMapper.ts +6 -4
- package/src/components/Schema.tsx +1 -99
- package/src/generator.tsx +22 -18
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +77 -30
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/plugin.ts +69 -56
- package/src/types.ts +24 -18
- package/src/utils/getParams.ts +1 -1
- package/src/utils/getSchemaFactory.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/parseFromConfig.ts +7 -7
- package/dist/OperationGenerator-By5WOmWB.d.ts +0 -165
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +0 -165
- package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
- package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
- package/dist/chunk-75BIOXB7.cjs +0 -7
- package/dist/chunk-75BIOXB7.cjs.map +0 -1
- package/dist/chunk-IAUV3UKH.cjs +0 -3965
- package/dist/chunk-IAUV3UKH.cjs.map +0 -1
- package/dist/chunk-M347763D.js +0 -3965
- package/dist/chunk-M347763D.js.map +0 -1
- package/dist/chunk-N7EEVJA6.js +0 -35
- package/dist/chunk-N7EEVJA6.js.map +0 -1
- package/dist/chunk-NU4F7G47.cjs +0 -89
- package/dist/chunk-NU4F7G47.cjs.map +0 -1
- package/dist/chunk-O76YQFZB.cjs +0 -35
- package/dist/chunk-O76YQFZB.cjs.map +0 -1
- package/dist/chunk-SQ64ESS4.js +0 -7
- package/dist/chunk-SQ64ESS4.js.map +0 -1
- package/dist/chunk-SZDO532A.js +0 -89
- package/dist/chunk-SZDO532A.js.map +0 -1
- package/dist/types-CZTUCaE5.d.cts +0 -145
- package/dist/types-CZTUCaE5.d.ts +0 -145
- package/src/utils/refSorter.ts +0 -13
package/dist/hooks.cjs.map
CHANGED
|
@@ -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,8CAAA,CAAA;ADWA;AACA;AEZA,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;AFQA;AACA;AGvBA,8CAAA,CAAA;AAAA;AASO,SAAS,YAAA,CAAA,EAA8B;AAC5C,EAAA,MAAM,EAAE,UAAU,EAAA,EAAIA,+BAAA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9B,SAAA,CAAU,UAAA,CAAW,SAAA,EAAW;AAAA,MAC9B,aAAA;AAAA,MACA,WAAA,EAAa,CAAC,IAAA,EAAA,GACZ,aAAA,CAAc,WAAA,CAAY;AAAA,QACxB,IAAA;AAAA,QACA,SAAA,kBAAW,MAAA,+BAAQ,WAAA;AAAA,QACnB,IAAA,kBAAM,MAAA,+BAAQ;AAAA,MAChB,CAAC;AAAA,IACL,CAAC,CAAA;AAAA,IACH;AAAA,EACF,CAAA;AACF;AJzBA;AACA;AK3IA,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;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,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA,CAAA;AAAA,GACtC;AAEA,EAAO,OAAA,GAAA,CAAA;AACT,CAAA;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcD,GAAAA,gBAAAA,CAAWE,4BAAU,OAAO,CAAA,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA,CAAA;AAAA,GAC5C;AAEA,EAAO,OAAA,SAAA,CAAA;AACT,CAAA;ACkDO,SAAS,mBAAiD,GAAA;A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QACN,SAAA;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACF,CAAA;AAEA,EAAM,MAAA,UAAA,GAAmD,CAAC,IAAS,KAAA;AACjE,IAAA,MAAM,IAAO,GAAAC,iCAAA,CAAgB,UAAW,CAAA,IAAA,EAAMC,iCAAe,GAAG,CAAA,CAAA;AAEhE,IAAA,OAAO,IACH,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,CAAM,KAAA;AACjB,MAAI,IAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAM,EAAA;AACnB,QAAO,OAAA,KAAA,CAAA,CAAA;AAAA,OACT;AAEA,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA,IAAA;AAAA,OAClB,CAAA;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAAA,GACnB,CAAA;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,GACF,CAAA;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 getSchemaName: (\n operation: Operation,\n key: keyof Omit<OperationSchemas, 'errors' | 'statusCodes'>,\n params?: {\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 const getSchemaName: UseOperationManagerResult['getSchemaName'] = (operation, key, { pluginKey = plugin.key, type } = {}) => {\n const schemas = getSchemas(operation)\n\n if (!schemas[key]?.name) {\n throw new Error(`SchemaName not found for ${operation.getOperationId()}`)\n }\n\n return pluginManager.resolveName({\n name: schemas[key]?.name,\n pluginKey,\n type,\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 getSchemaName,\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) {\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 {
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import 'react';
|
|
4
|
+
import { Mode } from '@kubb/fs/types';
|
|
5
|
+
import { w as OperationSchemas, g as Schema } from './OperationGenerator-BgQeGRzk.cjs';
|
|
6
|
+
import { a as SchemaContextProps } from './Schema-5o-c5UOy.cjs';
|
|
8
7
|
import '@kubb/react/types';
|
|
9
|
-
import '
|
|
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,22 @@ 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;
|
|
41
|
+
getSchemaName: (operation: Operation, key: keyof Omit<OperationSchemas, 'errors' | 'statusCodes'>, params?: {
|
|
42
|
+
pluginKey?: Plugin['key'];
|
|
43
|
+
type?: ResolveNameParams['type'];
|
|
44
|
+
}) => string;
|
|
40
45
|
getFile: (operation: Operation, params?: {
|
|
46
|
+
prefix?: string;
|
|
47
|
+
suffix?: string;
|
|
41
48
|
pluginKey?: Plugin['key'];
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
extname?: KubbFile.Extname;
|
|
50
|
+
tag?: string;
|
|
51
|
+
}) => KubbFile.File<FileMeta$1>;
|
|
44
52
|
groupSchemasByName: (operation: Operation, params: {
|
|
45
53
|
pluginKey?: Plugin['key'];
|
|
46
54
|
type: ResolveNameParams['type'];
|
|
@@ -48,7 +56,7 @@ type UseOperationManagerResult = {
|
|
|
48
56
|
getSchemas: (operation: Operation, params?: {
|
|
49
57
|
pluginKey?: Plugin['key'];
|
|
50
58
|
type?: ResolveNameParams['type'];
|
|
51
|
-
}
|
|
59
|
+
}) => OperationSchemas;
|
|
52
60
|
};
|
|
53
61
|
/**
|
|
54
62
|
* `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
|
|
@@ -78,4 +86,27 @@ type UseSchemaResult = SchemaContextProps;
|
|
|
78
86
|
*/
|
|
79
87
|
declare function useSchema(): UseSchemaResult;
|
|
80
88
|
|
|
81
|
-
|
|
89
|
+
type FileMeta = FileMetaBase & {
|
|
90
|
+
pluginKey: Plugin['key'];
|
|
91
|
+
name: string;
|
|
92
|
+
tag?: string;
|
|
93
|
+
};
|
|
94
|
+
type UseSchemaManagerResult = {
|
|
95
|
+
getName: (name: string, params: {
|
|
96
|
+
pluginKey?: Plugin['key'];
|
|
97
|
+
type: ResolveNameParams['type'];
|
|
98
|
+
}) => string;
|
|
99
|
+
getFile: (name: string, params?: {
|
|
100
|
+
pluginKey?: Plugin['key'];
|
|
101
|
+
mode?: Mode;
|
|
102
|
+
extname?: KubbFile.Extname;
|
|
103
|
+
tag?: string;
|
|
104
|
+
}) => KubbFile.File<FileMeta>;
|
|
105
|
+
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
|
|
109
|
+
*/
|
|
110
|
+
declare function useSchemaManager(): UseSchemaManagerResult;
|
|
111
|
+
|
|
112
|
+
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 {
|
|
5
|
-
import {
|
|
6
|
-
import '
|
|
7
|
-
import 'react';
|
|
4
|
+
import { Mode } from '@kubb/fs/types';
|
|
5
|
+
import { w as OperationSchemas, g as Schema } from './OperationGenerator-BgQeGRzk.js';
|
|
6
|
+
import { a as SchemaContextProps } from './Schema-1iM2I0dK.js';
|
|
8
7
|
import '@kubb/react/types';
|
|
9
|
-
import '
|
|
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,22 @@ 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;
|
|
41
|
+
getSchemaName: (operation: Operation, key: keyof Omit<OperationSchemas, 'errors' | 'statusCodes'>, params?: {
|
|
42
|
+
pluginKey?: Plugin['key'];
|
|
43
|
+
type?: ResolveNameParams['type'];
|
|
44
|
+
}) => string;
|
|
40
45
|
getFile: (operation: Operation, params?: {
|
|
46
|
+
prefix?: string;
|
|
47
|
+
suffix?: string;
|
|
41
48
|
pluginKey?: Plugin['key'];
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
extname?: KubbFile.Extname;
|
|
50
|
+
tag?: string;
|
|
51
|
+
}) => KubbFile.File<FileMeta$1>;
|
|
44
52
|
groupSchemasByName: (operation: Operation, params: {
|
|
45
53
|
pluginKey?: Plugin['key'];
|
|
46
54
|
type: ResolveNameParams['type'];
|
|
@@ -48,7 +56,7 @@ type UseOperationManagerResult = {
|
|
|
48
56
|
getSchemas: (operation: Operation, params?: {
|
|
49
57
|
pluginKey?: Plugin['key'];
|
|
50
58
|
type?: ResolveNameParams['type'];
|
|
51
|
-
}
|
|
59
|
+
}) => OperationSchemas;
|
|
52
60
|
};
|
|
53
61
|
/**
|
|
54
62
|
* `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
|
|
@@ -78,4 +86,27 @@ type UseSchemaResult = SchemaContextProps;
|
|
|
78
86
|
*/
|
|
79
87
|
declare function useSchema(): UseSchemaResult;
|
|
80
88
|
|
|
81
|
-
|
|
89
|
+
type FileMeta = FileMetaBase & {
|
|
90
|
+
pluginKey: Plugin['key'];
|
|
91
|
+
name: string;
|
|
92
|
+
tag?: string;
|
|
93
|
+
};
|
|
94
|
+
type UseSchemaManagerResult = {
|
|
95
|
+
getName: (name: string, params: {
|
|
96
|
+
pluginKey?: Plugin['key'];
|
|
97
|
+
type: ResolveNameParams['type'];
|
|
98
|
+
}) => string;
|
|
99
|
+
getFile: (name: string, params?: {
|
|
100
|
+
pluginKey?: Plugin['key'];
|
|
101
|
+
mode?: Mode;
|
|
102
|
+
extname?: KubbFile.Extname;
|
|
103
|
+
tag?: string;
|
|
104
|
+
}) => KubbFile.File<FileMeta>;
|
|
105
|
+
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
|
|
109
|
+
*/
|
|
110
|
+
declare function useSchemaManager(): UseSchemaManagerResult;
|
|
111
|
+
|
|
112
|
+
export { type SchemaNames, useOas, useOperation, useOperationManager, useOperations, useSchema, useSchemaManager };
|
package/dist/hooks.js
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./chunk-M347763D.js";
|
|
6
|
-
import {
|
|
7
|
-
init_esm_shims
|
|
8
|
-
} from "./chunk-SZDO532A.js";
|
|
1
|
+
import { SchemaGenerator, schemaKeywords } from './chunk-V2JO6RHI.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,51 @@ 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 } =
|
|
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 } =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
const { generator } = useContext(Oas.Context);
|
|
23
|
+
const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
|
|
24
|
+
return pluginManager.resolveName({
|
|
25
|
+
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
26
|
+
pluginKey,
|
|
27
|
+
type
|
|
28
|
+
});
|
|
29
|
+
};
|
|
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 getSchemaName = (operation, key, { pluginKey = plugin.key, type } = {}) => {
|
|
43
|
+
const schemas = getSchemas(operation);
|
|
44
|
+
if (!schemas[key]?.name) {
|
|
45
|
+
throw new Error(`SchemaName not found for ${operation.getOperationId()}`);
|
|
46
|
+
}
|
|
45
47
|
return pluginManager.resolveName({
|
|
46
|
-
name:
|
|
48
|
+
name: schemas[key]?.name,
|
|
47
49
|
pluginKey,
|
|
48
50
|
type
|
|
49
51
|
});
|
|
50
52
|
};
|
|
51
|
-
const getFile = (operation, { pluginKey = plugin.key,
|
|
52
|
-
const
|
|
53
|
-
const name = getName(operation, { type: "file", pluginKey });
|
|
53
|
+
const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = ".ts" } = {}) => {
|
|
54
|
+
const name = getName(operation, { type: "file", pluginKey, prefix, suffix });
|
|
54
55
|
const file = pluginManager.getFile({
|
|
55
56
|
name,
|
|
56
|
-
|
|
57
|
+
extname,
|
|
57
58
|
pluginKey,
|
|
58
59
|
options: { type: "file", pluginKey, tag }
|
|
59
60
|
});
|
|
@@ -68,6 +69,9 @@ function useOperationManager() {
|
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
71
|
const groupSchemasByName = (operation, { pluginKey = plugin.key, type }) => {
|
|
72
|
+
if (!generator) {
|
|
73
|
+
throw new Error(`'generator' is not defined`);
|
|
74
|
+
}
|
|
71
75
|
const schemas = generator.getSchemas(operation);
|
|
72
76
|
const errors = (schemas.errors || []).reduce(
|
|
73
77
|
(prev, acc) => {
|
|
@@ -125,23 +129,13 @@ function useOperationManager() {
|
|
|
125
129
|
return {
|
|
126
130
|
getName,
|
|
127
131
|
getFile,
|
|
128
|
-
getSchemas
|
|
129
|
-
|
|
130
|
-
resolveName: (name) => pluginManager.resolveName({
|
|
131
|
-
name,
|
|
132
|
-
pluginKey: params?.pluginKey,
|
|
133
|
-
type: params?.type
|
|
134
|
-
})
|
|
135
|
-
}),
|
|
132
|
+
getSchemas,
|
|
133
|
+
getSchemaName,
|
|
136
134
|
groupSchemasByName
|
|
137
135
|
};
|
|
138
136
|
}
|
|
139
|
-
|
|
140
|
-
// src/hooks/useOperations.ts
|
|
141
|
-
init_esm_shims();
|
|
142
|
-
import { useContext as useContext4 } from "@kubb/react";
|
|
143
137
|
function useOperations({ method, path } = {}) {
|
|
144
|
-
const { operations } =
|
|
138
|
+
const { operations } = useContext(Oas.Context);
|
|
145
139
|
if (!operations) {
|
|
146
140
|
throw new Error("Operations is not defined");
|
|
147
141
|
}
|
|
@@ -154,11 +148,55 @@ function useOperations({ method, path } = {}) {
|
|
|
154
148
|
}
|
|
155
149
|
return items;
|
|
156
150
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
151
|
+
function useSchema() {
|
|
152
|
+
const props = useContext(Schema.Context);
|
|
153
|
+
return props;
|
|
154
|
+
}
|
|
155
|
+
function useSchemaManager() {
|
|
156
|
+
const { mode, plugin, pluginManager, fileManager } = useApp();
|
|
157
|
+
const getName = (name, { pluginKey = plugin.key, type }) => {
|
|
158
|
+
return pluginManager.resolveName({
|
|
159
|
+
name,
|
|
160
|
+
pluginKey,
|
|
161
|
+
type
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const getFile = (name, { mode: mode2 = "split", pluginKey = plugin.key, extname = ".ts", tag } = {}) => {
|
|
165
|
+
const resolvedName = mode2 === "single" ? "" : getName(name, { type: "file", pluginKey });
|
|
166
|
+
const file = pluginManager.getFile({
|
|
167
|
+
name: resolvedName,
|
|
168
|
+
extname,
|
|
169
|
+
pluginKey,
|
|
170
|
+
options: { type: "file", pluginKey, tag }
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
...file,
|
|
174
|
+
meta: {
|
|
175
|
+
...file.meta,
|
|
176
|
+
name: resolvedName,
|
|
177
|
+
pluginKey
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
const getImports = (tree) => {
|
|
182
|
+
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
|
|
183
|
+
return refs?.map((item, i) => {
|
|
184
|
+
if (!item.args.path) {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
name: [item.args.name],
|
|
189
|
+
path: item.args.path
|
|
190
|
+
};
|
|
191
|
+
}).filter(Boolean);
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
getName,
|
|
195
|
+
getFile,
|
|
196
|
+
getImports
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { useOas, useOperation, useOperationManager, useOperations, useSchema, useSchemaManager };
|
|
201
|
+
//# sourceMappingURL=hooks.js.map
|
|
164
202
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/index.ts","../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,kBAAkB;AAMpB,SAAS,SAAkB;AAChC,QAAM,EAAE,IAAI,IAAI,WAAW,IAAI,OAAO;AAEtC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAEA,SAAO;AACT;;;ACdA;AAAA,SAAS,cAAAA,mBAAkB;AASpB,SAAS,eAA8B;AAC5C,QAAM,EAAE,UAAU,IAAIC,YAAW,UAAU,OAAO;AAElD,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AACT;;;ACjBA;AAAA,SAAS,QAAQ,cAAAC,mBAAkB;AAwC5B,SAAS,sBAAiD;AAC/D,QAAM,EAAE,QAAQ,cAAc,IAAI,OAAO;AACzC,QAAM,EAAE,UAAU,IAAIC,YAAW,IAAI,OAAO;AAE5C,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,KAAK,MAAM;AACrG,WAAO,cAAc,YAAY;AAAA,MAC/B,MAAM,UAAU,eAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC,MAAM;AAErH,UAAM,MAAM,UAAU,QAAQ,EAAE,GAAG,CAAC,GAAG;AAEvC,UAAM,OAAO,QAAQ,WAAW,EAAE,MAAM,QAAQ,UAAU,CAAC;AAE3D,UAAM,OAAO,cAAc,QAAQ;AAAA,MACjC;AAAA,MACA;AAAA,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AM,QAAQ,SAAS;AAAA,UACvB;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACD,CAAC,SAAS,GAAG,cAAc,YAAY;AAAA,UACrC,MAAM,QAAQ,SAAS;AAAA,UACvB;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACD,GAAG;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,YAAY,CAAC,WAAW,QAAQ,kBAC9B,UAAU,WAAW,WAAW;AAAA,MAC9B;AAAA,MACA,aAAa,CAAC,SACZ,cAAc,YAAY;AAAA,QACxB;AAAA,QACA,WAAW,QAAQ;AAAA,QACnB,MAAM,QAAQ;AAAA,MAChB,CAAC;AAAA,IACL,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;ACnKA;AAAA,SAAS,cAAAC,mBAAkB;AAsBpB,SAAS,cAAc,EAAE,QAAQ,KAAK,IAAwB,CAAC,GAAgB;AACpF,QAAM,EAAE,WAAW,IAAIC,YAAW,IAAI,OAAO;AAE7C,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AACA,MAAI,QAAQ;AAEZ,MAAI,MAAM;AACR,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,EACnD;AAEA,MAAI,QAAQ;AACV,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACvD;AAEA,SAAO;AACT;","names":["useContext","useContext","useContext","useContext","useContext","useContext"]}
|
|
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","useApp","mode"],"mappings":";;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,UAAA,CAAW,IAAI,OAAO,CAAA,C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Q,MAAM,EAAE,IAAA,EAAM,MAAQ,EAAA,SAAA,EAAW,CAAA,CAAA;AAEvF,IAAM,MAAA,IAAA,GAAO,cAAc,OAAQ,CAAA;AAAA,MACjC,IAAM,EAAA,YAAA;AAAA,MACN,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAS,EAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,WAAW,GAAI,EAAA;AAAA,KACzC,CAAA,CAAA;AAED,IAAO,OAAA;AAAA,MACL,GAAG,IAAA;AAAA,MACH,IAAM,EAAA;AAAA,QACJ,GAAG,IAAK,CAAA,IAAA;AAAA,QACR,IAAM,EAAA,YAAA;AAAA,QACN,SAAA;AAAA,OACF;AAAA,KACF,CAAA;AAAA,GACF,CAAA;AAEA,EAAM,MAAA,UAAA,GAAmD,CAAC,IAAS,KAAA;AACjE,IAAA,MAAM,IAAO,GAAA,eAAA,CAAgB,UAAW,CAAA,IAAA,EAAM,eAAe,GAAG,CAAA,CAAA;AAEhE,IAAA,OAAO,IACH,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,CAAM,KAAA;AACjB,MAAI,IAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAM,EAAA;AACnB,QAAO,OAAA,KAAA,CAAA,CAAA;AAAA,OACT;AAEA,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA,IAAA;AAAA,OAClB,CAAA;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAAA,GACnB,CAAA;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA;AAAA,GACF,CAAA;AACF","file":"hooks.js","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 getSchemaName: (\n operation: Operation,\n key: keyof Omit<OperationSchemas, 'errors' | 'statusCodes'>,\n params?: {\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 const getSchemaName: UseOperationManagerResult['getSchemaName'] = (operation, key, { pluginKey = plugin.key, type } = {}) => {\n const schemas = getSchemas(operation)\n\n if (!schemas[key]?.name) {\n throw new Error(`SchemaName not found for ${operation.getOperationId()}`)\n }\n\n return pluginManager.resolveName({\n name: schemas[key]?.name,\n pluginKey,\n type,\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 getSchemaName,\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) {\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"]}
|