@kubb/plugin-ts 4.11.3 → 4.12.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/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{plugin-DDZUp8Ga.js → plugin-DEnfu1Si.js} +5 -6
- package/dist/{plugin-DDZUp8Ga.js.map → plugin-DEnfu1Si.js.map} +1 -1
- package/dist/{plugin-B1vz78vw.cjs → plugin-KCnzc1f5.cjs} +5 -6
- package/dist/{plugin-B1vz78vw.cjs.map → plugin-KCnzc1f5.cjs.map} +1 -1
- package/dist/{types-CaMNNWTx.d.ts → types-C7ABVeaM.d.cts} +217 -104
- package/dist/{types-B86eJVSW.d.cts → types-xVulrECR.d.ts} +217 -104
- package/package.json +8 -8
- package/src/generators/typeGenerator.tsx +1 -1
- package/src/plugin.ts +2 -3
package/dist/components.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Schema, n as PluginTs, o as OasTypes, s as SchemaObject } from "./types-
|
|
1
|
+
import { i as Schema, n as PluginTs, o as OasTypes, s as SchemaObject } from "./types-C7ABVeaM.cjs";
|
|
2
2
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
3
3
|
|
|
4
4
|
//#region src/components/OasType.d.ts
|
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Schema, n as PluginTs, o as OasTypes, s as SchemaObject } from "./types-
|
|
1
|
+
import { i as Schema, n as PluginTs, o as OasTypes, s as SchemaObject } from "./types-xVulrECR.js";
|
|
2
2
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
3
3
|
|
|
4
4
|
//#region src/components/OasType.d.ts
|
package/dist/generators.cjs
CHANGED
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -133,7 +133,7 @@ const typeGenerator = createReactGenerator({
|
|
|
133
133
|
const schemaGenerator = new SchemaGenerator(options, {
|
|
134
134
|
fabric: generator.context.fabric,
|
|
135
135
|
oas,
|
|
136
|
-
|
|
136
|
+
events: generator.context.events,
|
|
137
137
|
plugin,
|
|
138
138
|
pluginManager,
|
|
139
139
|
mode,
|
|
@@ -317,7 +317,7 @@ const pluginTs = definePlugin((options) => {
|
|
|
317
317
|
fabric: this.fabric,
|
|
318
318
|
oas,
|
|
319
319
|
pluginManager: this.pluginManager,
|
|
320
|
-
|
|
320
|
+
events: this.events,
|
|
321
321
|
plugin: this.plugin,
|
|
322
322
|
contentType,
|
|
323
323
|
include: void 0,
|
|
@@ -330,7 +330,7 @@ const pluginTs = definePlugin((options) => {
|
|
|
330
330
|
fabric: this.fabric,
|
|
331
331
|
oas,
|
|
332
332
|
pluginManager: this.pluginManager,
|
|
333
|
-
|
|
333
|
+
events: this.events,
|
|
334
334
|
plugin: this.plugin,
|
|
335
335
|
contentType,
|
|
336
336
|
exclude,
|
|
@@ -343,8 +343,7 @@ const pluginTs = definePlugin((options) => {
|
|
|
343
343
|
type: output.barrelType ?? "named",
|
|
344
344
|
root,
|
|
345
345
|
output,
|
|
346
|
-
meta: { pluginKey: this.plugin.key }
|
|
347
|
-
logger: this.logger
|
|
346
|
+
meta: { pluginKey: this.plugin.key }
|
|
348
347
|
});
|
|
349
348
|
await this.upsertFile(...barrelFiles);
|
|
350
349
|
}
|
|
@@ -353,4 +352,4 @@ const pluginTs = definePlugin((options) => {
|
|
|
353
352
|
|
|
354
353
|
//#endregion
|
|
355
354
|
export { oasGenerator as i, pluginTsName as n, typeGenerator as r, pluginTs as t };
|
|
356
|
-
//# sourceMappingURL=plugin-
|
|
355
|
+
//# sourceMappingURL=plugin-DEnfu1Si.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-DDZUp8Ga.js","names":["properties: Record<string, ts.TypeNode>","factory.createUnionDeclaration","factory.createTypeReferenceNode","factory.createIdentifier","factory.createTypeAliasDeclaration","factory.createTypeLiteralNode","factory.createPropertySignature","options","type","Type","options","groupName: Group['name']","transformers"],"sources":["../src/generators/oasGenerator.tsx","../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations({ plugin }) {\n const {\n options: { output },\n key: pluginKey,\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n logger: generator.context.logger,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAQA,MAAa,eAAe,qBAA+B;CACzD,MAAM;CACN,WAAW,EAAE,UAAU;EACrB,MAAM,EACJ,SAAS,EAAE,UACX,KAAK,cACH;EACJ,MAAM,gBAAgB,kBAAkB;EACxC,MAAM,MAAM,QAAQ;EAEpB,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAO,SAAS;GAAO;GAAW,CAAC;AAE9E,SACE,qBAAC;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;cAElC,oBAAC,KAAK;IAAO,MAAM,CAAC,QAAQ;IAAE,MAAK;IAAY;KAAa,EAE5D,oBAAC;IAAQ,MAAM;IAAO,UAAU;IAAO,KAAK,IAAI;KAAO;IAClD;;CAGZ,CAAC;;;;ACnBF,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMA,aAA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IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
1
|
+
{"version":3,"file":"plugin-DEnfu1Si.js","names":["properties: Record<string, ts.TypeNode>","factory.createUnionDeclaration","factory.createTypeReferenceNode","factory.createIdentifier","factory.createTypeAliasDeclaration","factory.createTypeLiteralNode","factory.createPropertySignature","options","type","Type","options","groupName: Group['name']","transformers"],"sources":["../src/generators/oasGenerator.tsx","../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations({ plugin }) {\n const {\n options: { output },\n key: pluginKey,\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n events: generator.context.events,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAQA,MAAa,eAAe,qBAA+B;CACzD,MAAM;CACN,WAAW,EAAE,UAAU;EACrB,MAAM,EACJ,SAAS,EAAE,UACX,KAAK,cACH;EACJ,MAAM,gBAAgB,kBAAkB;EACxC,MAAM,MAAM,QAAQ;EAEp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MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,eAAe,WAAW,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;AAElE,OAAI,KACF,QAAOE,gBAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,cAAc,MAbI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,WAAW,GAAG,YAAY;GAerC,MAAM,iBAAiB,MAbI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,WAAW,GAAG,eAAe;GAExC,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -135,7 +135,7 @@ const typeGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
135
135
|
const schemaGenerator = new __kubb_plugin_oas.SchemaGenerator(options, {
|
|
136
136
|
fabric: generator.context.fabric,
|
|
137
137
|
oas,
|
|
138
|
-
|
|
138
|
+
events: generator.context.events,
|
|
139
139
|
plugin,
|
|
140
140
|
pluginManager,
|
|
141
141
|
mode,
|
|
@@ -319,7 +319,7 @@ const pluginTs = (0, __kubb_core.definePlugin)((options) => {
|
|
|
319
319
|
fabric: this.fabric,
|
|
320
320
|
oas,
|
|
321
321
|
pluginManager: this.pluginManager,
|
|
322
|
-
|
|
322
|
+
events: this.events,
|
|
323
323
|
plugin: this.plugin,
|
|
324
324
|
contentType,
|
|
325
325
|
include: void 0,
|
|
@@ -332,7 +332,7 @@ const pluginTs = (0, __kubb_core.definePlugin)((options) => {
|
|
|
332
332
|
fabric: this.fabric,
|
|
333
333
|
oas,
|
|
334
334
|
pluginManager: this.pluginManager,
|
|
335
|
-
|
|
335
|
+
events: this.events,
|
|
336
336
|
plugin: this.plugin,
|
|
337
337
|
contentType,
|
|
338
338
|
exclude,
|
|
@@ -345,8 +345,7 @@ const pluginTs = (0, __kubb_core.definePlugin)((options) => {
|
|
|
345
345
|
type: output.barrelType ?? "named",
|
|
346
346
|
root,
|
|
347
347
|
output,
|
|
348
|
-
meta: { pluginKey: this.plugin.key }
|
|
349
|
-
logger: this.logger
|
|
348
|
+
meta: { pluginKey: this.plugin.key }
|
|
350
349
|
});
|
|
351
350
|
await this.upsertFile(...barrelFiles);
|
|
352
351
|
}
|
|
@@ -378,4 +377,4 @@ Object.defineProperty(exports, 'typeGenerator', {
|
|
|
378
377
|
return typeGenerator;
|
|
379
378
|
}
|
|
380
379
|
});
|
|
381
|
-
//# sourceMappingURL=plugin-
|
|
380
|
+
//# sourceMappingURL=plugin-KCnzc1f5.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-B1vz78vw.cjs","names":["File","OasType","properties: Record<string, ts.TypeNode>","transformers","SchemaGenerator","options","type","File","Type","schemaKeywords","pluginOasName","path","options","groupName: Group['name']","transformers","SchemaGenerator","OperationGenerator"],"sources":["../src/generators/oasGenerator.tsx","../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations({ plugin }) {\n const {\n options: { output },\n key: pluginKey,\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n logger: generator.context.logger,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAa,sEAA8C;CACzD,MAAM;CACN,WAAW,EAAE,UAAU;EACrB,MAAM,EACJ,SAAS,EAAE,UACX,KAAK,cACH;EACJ,MAAM,yDAAkC;EACxC,MAAM,2CAAc;EAEpB,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAO,SAAS;GAAO;GAAW,CAAC;AAE9E,SACE,0DAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;cAElC,yDAACA,yBAAK;IAAO,MAAM,CAAC,QAAQ;IAAE,MAAK;IAAY;KAAa,EAE5D,yDAACC;IAAQ,MAAM;IAAO,UAAU;IAAO,KAAK,IAAI;KAAO;IAClD;;CAGZ,CAAC;;;;ACnBF,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMC,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,wDAA6C,EACtD,OAAO,QAAQ,UAAU,KAAK,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AAEF,wFAAgE,WAAW,EAAE,OAAU;GACvF,EACH,CAAC;AAGJ,KAAI,QAAQ,SAAS;EACnB,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,QAAQ,QAAQ;GACtB,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AACF,aAAW,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3,"file":"plugin-KCnzc1f5.cjs","names":["File","OasType","properties: Record<string, ts.TypeNode>","transformers","SchemaGenerator","options","type","File","Type","schemaKeywords","pluginOasName","path","options","groupName: Group['name']","transformers","SchemaGenerator","OperationGenerator"],"sources":["../src/generators/oasGenerator.tsx","../src/generators/typeGenerator.tsx","../src/plugin.ts"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { OasType } from '../components'\nimport type { PluginTs } from '../types.ts'\n\nexport const oasGenerator = createReactGenerator<PluginTs>({\n name: 'oas',\n Operations({ plugin }) {\n const {\n options: { output },\n key: pluginKey,\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\n\n const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['Infer']} path=\"@kubb/oas\" isTypeOnly />\n\n <OasType name={'oas'} typeName={'Oas'} api={oas.api} />\n </File>\n )\n },\n})\n","import type { PluginManager } from '@kubb/core'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport transformers from '@kubb/core/transformers'\nimport { print } from '@kubb/fabric-core/parsers/typescript'\nimport { isKeyword, type OperationSchemas, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport type ts from 'typescript'\nimport { Type } from '../components'\nimport * as factory from '../factory.ts'\nimport { pluginTsName } from '../plugin.ts'\nimport type { PluginTs } from '../types'\n\nfunction printCombinedSchema({ name, schemas, pluginManager }: { name: string; schemas: OperationSchemas; pluginManager: PluginManager }): string {\n const properties: Record<string, ts.TypeNode> = {}\n\n if (schemas.response) {\n properties['response'] = factory.createUnionDeclaration({\n nodes: schemas.responses.map((res) => {\n const identifier = pluginManager.resolveName({\n name: res.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n if (schemas.request) {\n const identifier = pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['request'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.pathParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['pathParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.queryParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['queryParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.headerParams) {\n const identifier = pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n properties['headerParams'] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }\n\n if (schemas.errors) {\n properties['errors'] = factory.createUnionDeclaration({\n nodes: schemas.errors.map((error) => {\n const identifier = pluginManager.resolveName({\n name: error.name,\n pluginKey: [pluginTsName],\n type: 'function',\n })\n\n return factory.createTypeReferenceNode(factory.createIdentifier(identifier), undefined)\n }),\n })!\n }\n\n const namespaceNode = factory.createTypeAliasDeclaration({\n name,\n type: factory.createTypeLiteralNode(\n Object.keys(properties)\n .map((key) => {\n const type = properties[key]\n if (!type) {\n return undefined\n }\n\n return factory.createPropertySignature({\n name: transformers.pascalCase(key),\n type,\n })\n })\n .filter(Boolean),\n ),\n modifiers: [factory.modifiers.export],\n })\n\n return print(namespaceNode)\n}\n\nexport const typeGenerator = createReactGenerator<PluginTs>({\n name: 'typescript',\n Operation({ operation, generator, plugin }) {\n const {\n options,\n options: { mapper, enumType, syntaxType, optionalType },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const type = getName(operation, { type: 'function', pluginKey: [pluginTsName] })\n const combinedSchemaName = operation.method === 'get' ? `${type}Query` : `${type}Mutation`\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\n oas,\n events: generator.context.events,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const tree = schemaGenerator.parse({ schemaObject, name })\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const type = {\n name: schemaManager.getName(name, { type: 'type' }),\n typedName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(options.operationName || name, { group }),\n }\n\n return (\n <>\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[name, imp.name, imp.path, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={description}\n tree={tree}\n schema={schemaObject}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n keysToOmit={keysToOmit}\n syntaxType={syntaxType}\n />\n </>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {operationSchemas.map(mapOperationSchema)}\n\n <File.Source name={combinedSchemaName} isExportable isIndexable isTypeOnly>\n {printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager })}\n </File.Source>\n </File>\n )\n },\n Schema({ schema, plugin }) {\n const {\n options: { mapper, enumType, syntaxType, optionalType, output },\n } = plugin\n const mode = useMode()\n\n const oas = useOas()\n const pluginManager = usePluginManager()\n\n const { getName, getImports, getFile } = useSchemaManager()\n const imports = getImports(schema.tree)\n const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema)\n\n let typedName = getName(schema.name, { type: 'type' })\n\n if (enumType === 'asConst' && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) {\n typedName = typedName += 'Key' //Suffix for avoiding collisions (https://github.com/kubb-labs/kubb/issues/1873)\n }\n\n const type = {\n name: getName(schema.name, { type: 'function' }),\n typedName,\n file: getFile(schema.name),\n }\n\n return (\n <File\n baseName={type.file.baseName}\n path={type.file.path}\n meta={type.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {mode === 'split' &&\n imports.map((imp) => (\n <File.Import key={[schema.name, imp.path, imp.isTypeOnly].join('-')} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />\n ))}\n <Type\n name={type.name}\n typedName={type.typedName}\n description={schema.value.description}\n tree={schema.tree}\n schema={schema.value}\n mapper={mapper}\n enumType={enumType}\n optionalType={optionalType}\n syntaxType={syntaxType}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { oasGenerator, typeGenerator } from './generators'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = definePlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumSuffix = 'enum',\n dateType = 'string',\n unknownType = 'any',\n optionalType = 'questionToken',\n emptySchemaType = unknownType,\n syntaxType = 'type',\n transformers = {},\n oasType = false,\n mapper = {},\n generators = [typeGenerator, oasType === 'infer' ? oasGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n const usedEnumNames = {}\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n dateType,\n optionalType,\n oasType,\n enumType,\n enumSuffix,\n unknownType,\n emptySchemaType,\n syntaxType,\n group,\n override,\n mapper,\n usedEnumNames,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = pascalCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.upsertFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.upsertFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAQA,MAAa,sEAA8C;CACzD,MAAM;CACN,WAAW,EAAE,UAAU;EACrB,MAAM,EACJ,SAAS,EAAE,UACX,KAAK,cACH;EACJ,MAAM,yDAAkC;EACxC,MAAM,2CAAc;EAEpB,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAO,SAAS;GAAO;GAAW,CAAC;AAE9E,SACE,0DAACA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;cAElC,yDAACA,yBAAK;IAAO,MAAM,CAAC,QAAQ;IAAE,MAAK;IAAY;KAAa,EAE5D,yDAACC;IAAQ,MAAM;IAAO,UAAU;IAAO,KAAK,IAAI;KAAO;IAClD;;CAGZ,CAAC;;;;ACnBF,SAAS,oBAAoB,EAAE,MAAM,SAAS,iBAAoG;CAChJ,MAAMC,aAA0C,EAAE;AAElD,KAAI,QAAQ,SACV,YAAW,wDAA6C,EACtD,OAAO,QAAQ,UAAU,KAAK,QAAQ;EACpC,MAAM,aAAa,cAAc,YAAY;GAC3C,MAAM,IAAI;GACV,WAAW,CAAC,aAAa;GACzB,MAAM;GACP,CAAC;AAEF,wFAA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OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
2
|
-
import ts from "typescript";
|
|
3
1
|
import * as OasTypes from "oas/types";
|
|
4
2
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
5
3
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -7,8 +5,9 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
7
5
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
8
6
|
import BaseOas from "oas";
|
|
9
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
10
|
-
import {
|
|
8
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
11
9
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
10
|
+
import ts from "typescript";
|
|
12
11
|
|
|
13
12
|
//#region ../oas/src/types.d.ts
|
|
14
13
|
type contentType = 'application/json' | (string & {});
|
|
@@ -59,75 +58,229 @@ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
|
59
58
|
abstract build(...params: unknown[]): unknown;
|
|
60
59
|
}
|
|
61
60
|
//#endregion
|
|
62
|
-
//#region ../core/src/
|
|
63
|
-
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
64
|
-
#private;
|
|
65
|
-
constructor();
|
|
66
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
67
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
68
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
69
|
-
removeAll(): void;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region ../core/src/logger.d.ts
|
|
61
|
+
//#region ../core/src/Kubb.d.ts
|
|
73
62
|
type DebugEvent = {
|
|
74
63
|
date: Date;
|
|
75
64
|
logs: string[];
|
|
76
65
|
fileName?: string;
|
|
66
|
+
};
|
|
67
|
+
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
68
|
+
hookName: H;
|
|
69
|
+
plugins: Array<Plugin>;
|
|
70
|
+
};
|
|
71
|
+
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
72
|
+
hookName: H;
|
|
73
|
+
};
|
|
74
|
+
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
75
|
+
strategy: Strategy;
|
|
76
|
+
hookName: H;
|
|
77
|
+
plugin: Plugin;
|
|
78
|
+
parameters?: unknown[] | undefined;
|
|
79
|
+
output?: unknown;
|
|
80
|
+
};
|
|
81
|
+
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
82
|
+
duration: number;
|
|
83
|
+
strategy: Strategy;
|
|
84
|
+
hookName: H;
|
|
85
|
+
plugin: Plugin;
|
|
86
|
+
parameters?: unknown[] | undefined;
|
|
87
|
+
output?: unknown;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
91
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import type { AsyncEventEmitter } from '@kubb/core'
|
|
96
|
+
* import type { KubbEvents } from '@kubb/core'
|
|
97
|
+
*
|
|
98
|
+
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
99
|
+
*
|
|
100
|
+
* events.on('lifecycle:start', () => {
|
|
101
|
+
* console.log('Starting Kubb generation')
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* events.on('plugin:end', (plugin, duration) => {
|
|
105
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
interface KubbEvents {
|
|
77
110
|
/**
|
|
78
|
-
*
|
|
79
|
-
* - 'setup': Initial configuration and environment setup
|
|
80
|
-
* - 'plugin': Plugin installation and execution
|
|
81
|
-
* - 'hook': Plugin hook execution details
|
|
82
|
-
* - 'schema': Schema parsing and generation
|
|
83
|
-
* - 'file': File operations (read/write/generate)
|
|
84
|
-
* - 'error': Error details and stack traces
|
|
85
|
-
* - undefined: Generic logs (always inline)
|
|
111
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
86
112
|
*/
|
|
87
|
-
|
|
113
|
+
'lifecycle:start': [version: string];
|
|
88
114
|
/**
|
|
89
|
-
*
|
|
115
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
90
116
|
*/
|
|
91
|
-
|
|
117
|
+
'lifecycle:end': [];
|
|
92
118
|
/**
|
|
93
|
-
*
|
|
94
|
-
* - 'start': Start of plugin execution group
|
|
95
|
-
* - 'end': End of plugin execution group
|
|
119
|
+
* Emitted when configuration loading starts.
|
|
96
120
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
'config:start': [];
|
|
122
|
+
/**
|
|
123
|
+
* Emitted when configuration loading is complete.
|
|
124
|
+
*/
|
|
125
|
+
'config:end': [configs: Array<Config>];
|
|
126
|
+
/**
|
|
127
|
+
* Emitted when code generation phase starts.
|
|
128
|
+
*/
|
|
129
|
+
'generation:start': [config: Config];
|
|
130
|
+
/**
|
|
131
|
+
* Emitted when code generation phase completes.
|
|
132
|
+
*/
|
|
133
|
+
'generation:end': [Config: Config];
|
|
134
|
+
/**
|
|
135
|
+
* Emitted with a summary of the generation results.
|
|
136
|
+
* Contains summary lines, title, and success status.
|
|
137
|
+
*/
|
|
138
|
+
'generation:summary': [Config: Config, {
|
|
139
|
+
failedPlugins: Set<{
|
|
140
|
+
plugin: Plugin;
|
|
141
|
+
error: Error;
|
|
142
|
+
}>;
|
|
143
|
+
status: 'success' | 'failed';
|
|
144
|
+
hrStart: [number, number];
|
|
145
|
+
filesCreated: number;
|
|
146
|
+
pluginTimings?: Map<string, number>;
|
|
115
147
|
}];
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
150
|
+
*/
|
|
151
|
+
'format:start': [];
|
|
152
|
+
/**
|
|
153
|
+
* Emitted when code formatting completes.
|
|
154
|
+
*/
|
|
155
|
+
'format:end': [];
|
|
156
|
+
/**
|
|
157
|
+
* Emitted when linting starts.
|
|
158
|
+
*/
|
|
159
|
+
'lint:start': [];
|
|
160
|
+
/**
|
|
161
|
+
* Emitted when linting completes.
|
|
162
|
+
*/
|
|
163
|
+
'lint:end': [];
|
|
164
|
+
/**
|
|
165
|
+
* Emitted when plugin hooks execution starts.
|
|
166
|
+
*/
|
|
167
|
+
'hooks:start': [];
|
|
168
|
+
/**
|
|
169
|
+
* Emitted when plugin hooks execution completes.
|
|
170
|
+
*/
|
|
171
|
+
'hooks:end': [];
|
|
172
|
+
/**
|
|
173
|
+
* Emitted when a single hook execution starts.
|
|
174
|
+
*/
|
|
175
|
+
'hook:start': [command: string];
|
|
176
|
+
/**
|
|
177
|
+
* Emitted to execute a hook command (e.g., format or lint).
|
|
178
|
+
* The callback should be invoked when the command completes.
|
|
179
|
+
*/
|
|
180
|
+
'hook:execute': [{
|
|
181
|
+
command: string | URL;
|
|
182
|
+
args?: readonly string[];
|
|
183
|
+
}, cb: () => void];
|
|
184
|
+
/**
|
|
185
|
+
* Emitted when a single hook execution completes.
|
|
186
|
+
*/
|
|
187
|
+
'hook:end': [command: string];
|
|
188
|
+
/**
|
|
189
|
+
* Emitted when a new version of Kubb is available.
|
|
190
|
+
*/
|
|
191
|
+
'version:new': [currentVersion: string, latestVersion: string];
|
|
192
|
+
/**
|
|
193
|
+
* Informational message event.
|
|
194
|
+
*/
|
|
195
|
+
info: [message: string, info?: string];
|
|
196
|
+
/**
|
|
197
|
+
* Error event. Emitted when an error occurs during code generation.
|
|
198
|
+
*/
|
|
199
|
+
error: [error: Error, meta?: Record<string, unknown>];
|
|
200
|
+
/**
|
|
201
|
+
* Success message event.
|
|
202
|
+
*/
|
|
203
|
+
success: [message: string, info?: string];
|
|
204
|
+
/**
|
|
205
|
+
* Warning message event.
|
|
206
|
+
*/
|
|
207
|
+
warn: [message: string, info?: string];
|
|
208
|
+
/**
|
|
209
|
+
* Debug event for detailed logging.
|
|
210
|
+
* Contains timestamp, log messages, and optional filename.
|
|
211
|
+
*/
|
|
212
|
+
debug: [meta: DebugEvent];
|
|
213
|
+
/**
|
|
214
|
+
* Emitted when file processing starts.
|
|
215
|
+
* Contains the list of files to be processed.
|
|
216
|
+
*/
|
|
217
|
+
'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
|
|
218
|
+
/**
|
|
219
|
+
* Emitted for each file being processed, providing progress updates.
|
|
220
|
+
* Contains processed count, total count, percentage, and file details.
|
|
221
|
+
*/
|
|
222
|
+
'file:processing:update': [{
|
|
223
|
+
/** Number of files processed so far */
|
|
224
|
+
processed: number;
|
|
225
|
+
/** Total number of files to process */
|
|
226
|
+
total: number;
|
|
227
|
+
/** Processing percentage (0-100) */
|
|
228
|
+
percentage: number;
|
|
229
|
+
/** Optional source identifier */
|
|
230
|
+
source?: string;
|
|
231
|
+
/** The file being processed */
|
|
232
|
+
file: KubbFile.ResolvedFile;
|
|
233
|
+
/**
|
|
234
|
+
* Kubb configuration (not present in Fabric).
|
|
235
|
+
* Provides access to the current config during file processing.
|
|
236
|
+
*/
|
|
237
|
+
config: Config;
|
|
118
238
|
}];
|
|
119
|
-
};
|
|
120
|
-
type Logger = {
|
|
121
239
|
/**
|
|
122
|
-
*
|
|
240
|
+
* Emitted when file processing completes.
|
|
241
|
+
* Contains the list of processed files.
|
|
123
242
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
243
|
+
'files:processing:end': [files: KubbFile.ResolvedFile[]];
|
|
244
|
+
/**
|
|
245
|
+
* Emitted when a plugin starts executing.
|
|
246
|
+
*/
|
|
247
|
+
'plugin:start': [plugin: Plugin];
|
|
248
|
+
/**
|
|
249
|
+
* Emitted when a plugin completes execution.
|
|
250
|
+
*/
|
|
251
|
+
'plugin:end': [plugin: Plugin, duration: number];
|
|
252
|
+
/**
|
|
253
|
+
* Emitted when plugin hook progress tracking starts.
|
|
254
|
+
* Contains the hook name and list of plugins to execute.
|
|
255
|
+
*/
|
|
256
|
+
'plugins:hook:progress:start': [meta: ProgressStartMeta];
|
|
257
|
+
/**
|
|
258
|
+
* Emitted when plugin hook progress tracking ends.
|
|
259
|
+
* Contains the hook name that completed.
|
|
260
|
+
*/
|
|
261
|
+
'plugins:hook:progress:end': [meta: ProgressStopMeta];
|
|
262
|
+
/**
|
|
263
|
+
* Emitted when a plugin hook starts processing.
|
|
264
|
+
* Contains strategy, hook name, plugin, parameters, and output.
|
|
265
|
+
*/
|
|
266
|
+
'plugins:hook:processing:start': [meta: ExecutingMeta];
|
|
267
|
+
/**
|
|
268
|
+
* Emitted when a plugin hook completes processing.
|
|
269
|
+
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
270
|
+
*/
|
|
271
|
+
'plugins:hook:processing:end': [meta: ExecutedMeta];
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region ../core/src/utils/AsyncEventEmitter.d.ts
|
|
275
|
+
declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
276
|
+
#private;
|
|
277
|
+
constructor(maxListener?: number);
|
|
278
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
279
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
280
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
|
|
281
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
282
|
+
removeAll(): void;
|
|
283
|
+
}
|
|
131
284
|
//#endregion
|
|
132
285
|
//#region ../core/src/utils/types.d.ts
|
|
133
286
|
type PossiblePromise<T> = Promise<T> | T;
|
|
@@ -391,7 +544,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
391
544
|
* merging multiple sources into the same output file
|
|
392
545
|
*/
|
|
393
546
|
upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
394
|
-
|
|
547
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
395
548
|
mode: KubbFile.Mode;
|
|
396
549
|
/**
|
|
397
550
|
* Current plugin
|
|
@@ -437,35 +590,6 @@ type Group = {
|
|
|
437
590
|
//#region ../core/src/PluginManager.d.ts
|
|
438
591
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
439
592
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
440
|
-
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
441
|
-
strategy: Strategy;
|
|
442
|
-
hookName: H;
|
|
443
|
-
plugin: Plugin;
|
|
444
|
-
parameters?: unknown[] | undefined;
|
|
445
|
-
output?: unknown;
|
|
446
|
-
};
|
|
447
|
-
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
448
|
-
duration: number;
|
|
449
|
-
strategy: Strategy;
|
|
450
|
-
hookName: H;
|
|
451
|
-
plugin: Plugin;
|
|
452
|
-
parameters?: unknown[] | undefined;
|
|
453
|
-
output?: unknown;
|
|
454
|
-
};
|
|
455
|
-
type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
456
|
-
hookName: H;
|
|
457
|
-
duration: number;
|
|
458
|
-
strategy: Strategy;
|
|
459
|
-
parameters?: unknown[] | undefined;
|
|
460
|
-
plugin: Plugin;
|
|
461
|
-
};
|
|
462
|
-
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
463
|
-
hookName: H;
|
|
464
|
-
plugins: Array<Plugin>;
|
|
465
|
-
};
|
|
466
|
-
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
467
|
-
hookName: H;
|
|
468
|
-
};
|
|
469
593
|
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
470
594
|
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
471
595
|
result: Result;
|
|
@@ -473,19 +597,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
473
597
|
};
|
|
474
598
|
type Options$1 = {
|
|
475
599
|
fabric: Fabric;
|
|
476
|
-
|
|
600
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
477
601
|
/**
|
|
478
602
|
* @default Number.POSITIVE_INFINITY
|
|
479
603
|
*/
|
|
480
604
|
concurrency?: number;
|
|
481
605
|
};
|
|
482
|
-
type Events = {
|
|
483
|
-
progress_start: [meta: ProgressStartMeta];
|
|
484
|
-
progress_stop: [meta: ProgressStopMeta];
|
|
485
|
-
executing: [meta: ExecutingMeta];
|
|
486
|
-
executed: [meta: ExecutedMeta];
|
|
487
|
-
error: [error: Error, meta: ErrorMeta];
|
|
488
|
-
};
|
|
489
606
|
type GetFileProps<TOptions = object> = {
|
|
490
607
|
name: string;
|
|
491
608
|
mode?: KubbFile.Mode;
|
|
@@ -495,10 +612,10 @@ type GetFileProps<TOptions = object> = {
|
|
|
495
612
|
};
|
|
496
613
|
declare class PluginManager {
|
|
497
614
|
#private;
|
|
498
|
-
readonly events: EventEmitter<Events>;
|
|
499
615
|
readonly config: Config;
|
|
500
616
|
readonly options: Options$1;
|
|
501
617
|
constructor(config: Config, options: Options$1);
|
|
618
|
+
get events(): AsyncEventEmitter<KubbEvents>;
|
|
502
619
|
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
503
620
|
get plugins(): Array<Plugin>;
|
|
504
621
|
getFile<TOptions = object>({
|
|
@@ -512,10 +629,6 @@ declare class PluginManager {
|
|
|
512
629
|
}>;
|
|
513
630
|
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
514
631
|
resolveName: (params: ResolveNameParams) => string;
|
|
515
|
-
/**
|
|
516
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
517
|
-
*/
|
|
518
|
-
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
519
632
|
/**
|
|
520
633
|
* Run a specific hookName for plugin x.
|
|
521
634
|
*/
|
|
@@ -699,7 +812,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
699
812
|
override: Array<Override<TOptions>> | undefined;
|
|
700
813
|
contentType: contentType | undefined;
|
|
701
814
|
pluginManager: PluginManager;
|
|
702
|
-
|
|
815
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
703
816
|
/**
|
|
704
817
|
* Current plugin
|
|
705
818
|
*/
|
|
@@ -943,7 +1056,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
943
1056
|
fabric: Fabric;
|
|
944
1057
|
oas: Oas;
|
|
945
1058
|
pluginManager: PluginManager;
|
|
946
|
-
|
|
1059
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
947
1060
|
/**
|
|
948
1061
|
* Current plugin
|
|
949
1062
|
*/
|
|
@@ -1154,4 +1267,4 @@ type ResolvedOptions = {
|
|
|
1154
1267
|
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1155
1268
|
//#endregion
|
|
1156
1269
|
export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, OasTypes as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
|
|
1157
|
-
//# sourceMappingURL=types-
|
|
1270
|
+
//# sourceMappingURL=types-C7ABVeaM.d.cts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Fabric } from "@kubb/react-fabric";
|
|
2
|
+
import ts from "typescript";
|
|
1
3
|
import * as OasTypes from "oas/types";
|
|
2
4
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
3
5
|
import { Operation, Operation as Operation$1 } from "oas/operation";
|
|
@@ -5,10 +7,7 @@ import { OpenAPIV3 } from "openapi-types";
|
|
|
5
7
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
6
8
|
import BaseOas from "oas";
|
|
7
9
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
|
-
import { Fabric } from "@kubb/react-fabric";
|
|
9
|
-
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
10
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
|
-
import ts from "typescript";
|
|
12
11
|
|
|
13
12
|
//#region ../oas/src/types.d.ts
|
|
14
13
|
type contentType = 'application/json' | (string & {});
|
|
@@ -59,75 +58,229 @@ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
|
59
58
|
abstract build(...params: unknown[]): unknown;
|
|
60
59
|
}
|
|
61
60
|
//#endregion
|
|
62
|
-
//#region ../core/src/
|
|
63
|
-
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
64
|
-
#private;
|
|
65
|
-
constructor();
|
|
66
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
67
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
68
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
69
|
-
removeAll(): void;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region ../core/src/logger.d.ts
|
|
61
|
+
//#region ../core/src/Kubb.d.ts
|
|
73
62
|
type DebugEvent = {
|
|
74
63
|
date: Date;
|
|
75
64
|
logs: string[];
|
|
76
65
|
fileName?: string;
|
|
66
|
+
};
|
|
67
|
+
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
68
|
+
hookName: H;
|
|
69
|
+
plugins: Array<Plugin>;
|
|
70
|
+
};
|
|
71
|
+
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
72
|
+
hookName: H;
|
|
73
|
+
};
|
|
74
|
+
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
75
|
+
strategy: Strategy;
|
|
76
|
+
hookName: H;
|
|
77
|
+
plugin: Plugin;
|
|
78
|
+
parameters?: unknown[] | undefined;
|
|
79
|
+
output?: unknown;
|
|
80
|
+
};
|
|
81
|
+
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
82
|
+
duration: number;
|
|
83
|
+
strategy: Strategy;
|
|
84
|
+
hookName: H;
|
|
85
|
+
plugin: Plugin;
|
|
86
|
+
parameters?: unknown[] | undefined;
|
|
87
|
+
output?: unknown;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
91
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import type { AsyncEventEmitter } from '@kubb/core'
|
|
96
|
+
* import type { KubbEvents } from '@kubb/core'
|
|
97
|
+
*
|
|
98
|
+
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
99
|
+
*
|
|
100
|
+
* events.on('lifecycle:start', () => {
|
|
101
|
+
* console.log('Starting Kubb generation')
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* events.on('plugin:end', (plugin, duration) => {
|
|
105
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
106
|
+
* })
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
interface KubbEvents {
|
|
77
110
|
/**
|
|
78
|
-
*
|
|
79
|
-
* - 'setup': Initial configuration and environment setup
|
|
80
|
-
* - 'plugin': Plugin installation and execution
|
|
81
|
-
* - 'hook': Plugin hook execution details
|
|
82
|
-
* - 'schema': Schema parsing and generation
|
|
83
|
-
* - 'file': File operations (read/write/generate)
|
|
84
|
-
* - 'error': Error details and stack traces
|
|
85
|
-
* - undefined: Generic logs (always inline)
|
|
111
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
86
112
|
*/
|
|
87
|
-
|
|
113
|
+
'lifecycle:start': [version: string];
|
|
88
114
|
/**
|
|
89
|
-
*
|
|
115
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
90
116
|
*/
|
|
91
|
-
|
|
117
|
+
'lifecycle:end': [];
|
|
92
118
|
/**
|
|
93
|
-
*
|
|
94
|
-
* - 'start': Start of plugin execution group
|
|
95
|
-
* - 'end': End of plugin execution group
|
|
119
|
+
* Emitted when configuration loading starts.
|
|
96
120
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
'config:start': [];
|
|
122
|
+
/**
|
|
123
|
+
* Emitted when configuration loading is complete.
|
|
124
|
+
*/
|
|
125
|
+
'config:end': [configs: Array<Config>];
|
|
126
|
+
/**
|
|
127
|
+
* Emitted when code generation phase starts.
|
|
128
|
+
*/
|
|
129
|
+
'generation:start': [config: Config];
|
|
130
|
+
/**
|
|
131
|
+
* Emitted when code generation phase completes.
|
|
132
|
+
*/
|
|
133
|
+
'generation:end': [Config: Config];
|
|
134
|
+
/**
|
|
135
|
+
* Emitted with a summary of the generation results.
|
|
136
|
+
* Contains summary lines, title, and success status.
|
|
137
|
+
*/
|
|
138
|
+
'generation:summary': [Config: Config, {
|
|
139
|
+
failedPlugins: Set<{
|
|
140
|
+
plugin: Plugin;
|
|
141
|
+
error: Error;
|
|
142
|
+
}>;
|
|
143
|
+
status: 'success' | 'failed';
|
|
144
|
+
hrStart: [number, number];
|
|
145
|
+
filesCreated: number;
|
|
146
|
+
pluginTimings?: Map<string, number>;
|
|
115
147
|
}];
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
150
|
+
*/
|
|
151
|
+
'format:start': [];
|
|
152
|
+
/**
|
|
153
|
+
* Emitted when code formatting completes.
|
|
154
|
+
*/
|
|
155
|
+
'format:end': [];
|
|
156
|
+
/**
|
|
157
|
+
* Emitted when linting starts.
|
|
158
|
+
*/
|
|
159
|
+
'lint:start': [];
|
|
160
|
+
/**
|
|
161
|
+
* Emitted when linting completes.
|
|
162
|
+
*/
|
|
163
|
+
'lint:end': [];
|
|
164
|
+
/**
|
|
165
|
+
* Emitted when plugin hooks execution starts.
|
|
166
|
+
*/
|
|
167
|
+
'hooks:start': [];
|
|
168
|
+
/**
|
|
169
|
+
* Emitted when plugin hooks execution completes.
|
|
170
|
+
*/
|
|
171
|
+
'hooks:end': [];
|
|
172
|
+
/**
|
|
173
|
+
* Emitted when a single hook execution starts.
|
|
174
|
+
*/
|
|
175
|
+
'hook:start': [command: string];
|
|
176
|
+
/**
|
|
177
|
+
* Emitted to execute a hook command (e.g., format or lint).
|
|
178
|
+
* The callback should be invoked when the command completes.
|
|
179
|
+
*/
|
|
180
|
+
'hook:execute': [{
|
|
181
|
+
command: string | URL;
|
|
182
|
+
args?: readonly string[];
|
|
183
|
+
}, cb: () => void];
|
|
184
|
+
/**
|
|
185
|
+
* Emitted when a single hook execution completes.
|
|
186
|
+
*/
|
|
187
|
+
'hook:end': [command: string];
|
|
188
|
+
/**
|
|
189
|
+
* Emitted when a new version of Kubb is available.
|
|
190
|
+
*/
|
|
191
|
+
'version:new': [currentVersion: string, latestVersion: string];
|
|
192
|
+
/**
|
|
193
|
+
* Informational message event.
|
|
194
|
+
*/
|
|
195
|
+
info: [message: string, info?: string];
|
|
196
|
+
/**
|
|
197
|
+
* Error event. Emitted when an error occurs during code generation.
|
|
198
|
+
*/
|
|
199
|
+
error: [error: Error, meta?: Record<string, unknown>];
|
|
200
|
+
/**
|
|
201
|
+
* Success message event.
|
|
202
|
+
*/
|
|
203
|
+
success: [message: string, info?: string];
|
|
204
|
+
/**
|
|
205
|
+
* Warning message event.
|
|
206
|
+
*/
|
|
207
|
+
warn: [message: string, info?: string];
|
|
208
|
+
/**
|
|
209
|
+
* Debug event for detailed logging.
|
|
210
|
+
* Contains timestamp, log messages, and optional filename.
|
|
211
|
+
*/
|
|
212
|
+
debug: [meta: DebugEvent];
|
|
213
|
+
/**
|
|
214
|
+
* Emitted when file processing starts.
|
|
215
|
+
* Contains the list of files to be processed.
|
|
216
|
+
*/
|
|
217
|
+
'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
|
|
218
|
+
/**
|
|
219
|
+
* Emitted for each file being processed, providing progress updates.
|
|
220
|
+
* Contains processed count, total count, percentage, and file details.
|
|
221
|
+
*/
|
|
222
|
+
'file:processing:update': [{
|
|
223
|
+
/** Number of files processed so far */
|
|
224
|
+
processed: number;
|
|
225
|
+
/** Total number of files to process */
|
|
226
|
+
total: number;
|
|
227
|
+
/** Processing percentage (0-100) */
|
|
228
|
+
percentage: number;
|
|
229
|
+
/** Optional source identifier */
|
|
230
|
+
source?: string;
|
|
231
|
+
/** The file being processed */
|
|
232
|
+
file: KubbFile.ResolvedFile;
|
|
233
|
+
/**
|
|
234
|
+
* Kubb configuration (not present in Fabric).
|
|
235
|
+
* Provides access to the current config during file processing.
|
|
236
|
+
*/
|
|
237
|
+
config: Config;
|
|
118
238
|
}];
|
|
119
|
-
};
|
|
120
|
-
type Logger = {
|
|
121
239
|
/**
|
|
122
|
-
*
|
|
240
|
+
* Emitted when file processing completes.
|
|
241
|
+
* Contains the list of processed files.
|
|
123
242
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
243
|
+
'files:processing:end': [files: KubbFile.ResolvedFile[]];
|
|
244
|
+
/**
|
|
245
|
+
* Emitted when a plugin starts executing.
|
|
246
|
+
*/
|
|
247
|
+
'plugin:start': [plugin: Plugin];
|
|
248
|
+
/**
|
|
249
|
+
* Emitted when a plugin completes execution.
|
|
250
|
+
*/
|
|
251
|
+
'plugin:end': [plugin: Plugin, duration: number];
|
|
252
|
+
/**
|
|
253
|
+
* Emitted when plugin hook progress tracking starts.
|
|
254
|
+
* Contains the hook name and list of plugins to execute.
|
|
255
|
+
*/
|
|
256
|
+
'plugins:hook:progress:start': [meta: ProgressStartMeta];
|
|
257
|
+
/**
|
|
258
|
+
* Emitted when plugin hook progress tracking ends.
|
|
259
|
+
* Contains the hook name that completed.
|
|
260
|
+
*/
|
|
261
|
+
'plugins:hook:progress:end': [meta: ProgressStopMeta];
|
|
262
|
+
/**
|
|
263
|
+
* Emitted when a plugin hook starts processing.
|
|
264
|
+
* Contains strategy, hook name, plugin, parameters, and output.
|
|
265
|
+
*/
|
|
266
|
+
'plugins:hook:processing:start': [meta: ExecutingMeta];
|
|
267
|
+
/**
|
|
268
|
+
* Emitted when a plugin hook completes processing.
|
|
269
|
+
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
270
|
+
*/
|
|
271
|
+
'plugins:hook:processing:end': [meta: ExecutedMeta];
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region ../core/src/utils/AsyncEventEmitter.d.ts
|
|
275
|
+
declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
276
|
+
#private;
|
|
277
|
+
constructor(maxListener?: number);
|
|
278
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
279
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
280
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
|
|
281
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
282
|
+
removeAll(): void;
|
|
283
|
+
}
|
|
131
284
|
//#endregion
|
|
132
285
|
//#region ../core/src/utils/types.d.ts
|
|
133
286
|
type PossiblePromise<T> = Promise<T> | T;
|
|
@@ -391,7 +544,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
391
544
|
* merging multiple sources into the same output file
|
|
392
545
|
*/
|
|
393
546
|
upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
394
|
-
|
|
547
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
395
548
|
mode: KubbFile.Mode;
|
|
396
549
|
/**
|
|
397
550
|
* Current plugin
|
|
@@ -437,35 +590,6 @@ type Group = {
|
|
|
437
590
|
//#region ../core/src/PluginManager.d.ts
|
|
438
591
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
439
592
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
440
|
-
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
441
|
-
strategy: Strategy;
|
|
442
|
-
hookName: H;
|
|
443
|
-
plugin: Plugin;
|
|
444
|
-
parameters?: unknown[] | undefined;
|
|
445
|
-
output?: unknown;
|
|
446
|
-
};
|
|
447
|
-
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
448
|
-
duration: number;
|
|
449
|
-
strategy: Strategy;
|
|
450
|
-
hookName: H;
|
|
451
|
-
plugin: Plugin;
|
|
452
|
-
parameters?: unknown[] | undefined;
|
|
453
|
-
output?: unknown;
|
|
454
|
-
};
|
|
455
|
-
type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
456
|
-
hookName: H;
|
|
457
|
-
duration: number;
|
|
458
|
-
strategy: Strategy;
|
|
459
|
-
parameters?: unknown[] | undefined;
|
|
460
|
-
plugin: Plugin;
|
|
461
|
-
};
|
|
462
|
-
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
463
|
-
hookName: H;
|
|
464
|
-
plugins: Array<Plugin>;
|
|
465
|
-
};
|
|
466
|
-
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
467
|
-
hookName: H;
|
|
468
|
-
};
|
|
469
593
|
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
470
594
|
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
471
595
|
result: Result;
|
|
@@ -473,19 +597,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
473
597
|
};
|
|
474
598
|
type Options$1 = {
|
|
475
599
|
fabric: Fabric;
|
|
476
|
-
|
|
600
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
477
601
|
/**
|
|
478
602
|
* @default Number.POSITIVE_INFINITY
|
|
479
603
|
*/
|
|
480
604
|
concurrency?: number;
|
|
481
605
|
};
|
|
482
|
-
type Events = {
|
|
483
|
-
progress_start: [meta: ProgressStartMeta];
|
|
484
|
-
progress_stop: [meta: ProgressStopMeta];
|
|
485
|
-
executing: [meta: ExecutingMeta];
|
|
486
|
-
executed: [meta: ExecutedMeta];
|
|
487
|
-
error: [error: Error, meta: ErrorMeta];
|
|
488
|
-
};
|
|
489
606
|
type GetFileProps<TOptions = object> = {
|
|
490
607
|
name: string;
|
|
491
608
|
mode?: KubbFile.Mode;
|
|
@@ -495,10 +612,10 @@ type GetFileProps<TOptions = object> = {
|
|
|
495
612
|
};
|
|
496
613
|
declare class PluginManager {
|
|
497
614
|
#private;
|
|
498
|
-
readonly events: EventEmitter<Events>;
|
|
499
615
|
readonly config: Config;
|
|
500
616
|
readonly options: Options$1;
|
|
501
617
|
constructor(config: Config, options: Options$1);
|
|
618
|
+
get events(): AsyncEventEmitter<KubbEvents>;
|
|
502
619
|
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
503
620
|
get plugins(): Array<Plugin>;
|
|
504
621
|
getFile<TOptions = object>({
|
|
@@ -512,10 +629,6 @@ declare class PluginManager {
|
|
|
512
629
|
}>;
|
|
513
630
|
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
514
631
|
resolveName: (params: ResolveNameParams) => string;
|
|
515
|
-
/**
|
|
516
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
517
|
-
*/
|
|
518
|
-
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
519
632
|
/**
|
|
520
633
|
* Run a specific hookName for plugin x.
|
|
521
634
|
*/
|
|
@@ -699,7 +812,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
699
812
|
override: Array<Override<TOptions>> | undefined;
|
|
700
813
|
contentType: contentType | undefined;
|
|
701
814
|
pluginManager: PluginManager;
|
|
702
|
-
|
|
815
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
703
816
|
/**
|
|
704
817
|
* Current plugin
|
|
705
818
|
*/
|
|
@@ -943,7 +1056,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
943
1056
|
fabric: Fabric;
|
|
944
1057
|
oas: Oas;
|
|
945
1058
|
pluginManager: PluginManager;
|
|
946
|
-
|
|
1059
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
947
1060
|
/**
|
|
948
1061
|
* Current plugin
|
|
949
1062
|
*/
|
|
@@ -1154,4 +1267,4 @@ type ResolvedOptions = {
|
|
|
1154
1267
|
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1155
1268
|
//#endregion
|
|
1156
1269
|
export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, OasTypes as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
|
|
1157
|
-
//# sourceMappingURL=types-
|
|
1270
|
+
//# sourceMappingURL=types-xVulrECR.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.1",
|
|
4
4
|
"description": "TypeScript code generation plugin for Kubb, transforming OpenAPI schemas into TypeScript interfaces, types, and utility functions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -64,20 +64,20 @@
|
|
|
64
64
|
}
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@kubb/fabric-core": "0.
|
|
68
|
-
"@kubb/react-fabric": "0.
|
|
67
|
+
"@kubb/fabric-core": "0.7.0",
|
|
68
|
+
"@kubb/react-fabric": "0.7.0",
|
|
69
69
|
"natural-orderby": "^5.0.0",
|
|
70
70
|
"remeda": "^2.32.0",
|
|
71
71
|
"typescript": "5.9.3",
|
|
72
|
-
"@kubb/core": "4.
|
|
73
|
-
"@kubb/oas": "4.
|
|
74
|
-
"@kubb/plugin-oas": "4.
|
|
72
|
+
"@kubb/core": "4.12.1",
|
|
73
|
+
"@kubb/oas": "4.12.1",
|
|
74
|
+
"@kubb/plugin-oas": "4.12.1"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@kubb/plugin-oas": "4.
|
|
77
|
+
"@kubb/plugin-oas": "4.12.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@kubb/react-fabric": "0.
|
|
80
|
+
"@kubb/react-fabric": "0.7.0"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=20"
|
|
@@ -125,7 +125,7 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
125
125
|
const schemaGenerator = new SchemaGenerator(options, {
|
|
126
126
|
fabric: generator.context.fabric,
|
|
127
127
|
oas,
|
|
128
|
-
|
|
128
|
+
events: generator.context.events,
|
|
129
129
|
plugin,
|
|
130
130
|
pluginManager,
|
|
131
131
|
mode,
|
package/src/plugin.ts
CHANGED
|
@@ -101,7 +101,7 @@ export const pluginTs = definePlugin<PluginTs>((options) => {
|
|
|
101
101
|
fabric: this.fabric,
|
|
102
102
|
oas,
|
|
103
103
|
pluginManager: this.pluginManager,
|
|
104
|
-
|
|
104
|
+
events: this.events,
|
|
105
105
|
plugin: this.plugin,
|
|
106
106
|
contentType,
|
|
107
107
|
include: undefined,
|
|
@@ -117,7 +117,7 @@ export const pluginTs = definePlugin<PluginTs>((options) => {
|
|
|
117
117
|
fabric: this.fabric,
|
|
118
118
|
oas,
|
|
119
119
|
pluginManager: this.pluginManager,
|
|
120
|
-
|
|
120
|
+
events: this.events,
|
|
121
121
|
plugin: this.plugin,
|
|
122
122
|
contentType,
|
|
123
123
|
exclude,
|
|
@@ -136,7 +136,6 @@ export const pluginTs = definePlugin<PluginTs>((options) => {
|
|
|
136
136
|
meta: {
|
|
137
137
|
pluginKey: this.plugin.key,
|
|
138
138
|
},
|
|
139
|
-
logger: this.logger,
|
|
140
139
|
})
|
|
141
140
|
|
|
142
141
|
await this.upsertFile(...barrelFiles)
|