@kubb/plugin-faker 4.5.1 → 4.5.2

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.
@@ -1,4 +1,4 @@
1
- import { i as Schema, n as PluginFaker } from "./types-NHbH6Svj.cjs";
1
+ import { i as Schema, n as PluginFaker } from "./types-BKduR7YF.cjs";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
4
  //#region src/components/Faker.d.ts
@@ -1,4 +1,4 @@
1
- import { i as Schema, n as PluginFaker } from "./types-CEWRTyrN.js";
1
+ import { i as Schema, n as PluginFaker } from "./types-BEAw2_Gh.js";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
4
  //#region src/components/Faker.d.ts
@@ -1,4 +1,4 @@
1
- import { n as PluginFaker, r as ReactGenerator } from "./types-NHbH6Svj.cjs";
1
+ import { n as PluginFaker, r as ReactGenerator } from "./types-BKduR7YF.cjs";
2
2
 
3
3
  //#region src/generators/fakerGenerator.d.ts
4
4
  declare const fakerGenerator: ReactGenerator<PluginFaker>;
@@ -1,4 +1,4 @@
1
- import { n as PluginFaker, r as ReactGenerator } from "./types-CEWRTyrN.js";
1
+ import { n as PluginFaker, r as ReactGenerator } from "./types-BEAw2_Gh.js";
2
2
 
3
3
  //#region src/generators/fakerGenerator.d.ts
4
4
  declare const fakerGenerator: ReactGenerator<PluginFaker>;
package/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@ __kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
13
13
 
14
14
  //#region src/plugin.ts
15
15
  const pluginFakerName = "plugin-faker";
16
- const pluginFaker = (0, __kubb_core.createPlugin)((options) => {
16
+ const pluginFaker = (0, __kubb_core.definePlugin)((options) => {
17
17
  const { output = {
18
18
  path: "mocks",
19
19
  barrelType: "named"
@@ -31,7 +31,8 @@ const pluginFaker = (0, __kubb_core.createPlugin)((options) => {
31
31
  mapper,
32
32
  override,
33
33
  regexGenerator,
34
- group
34
+ group,
35
+ usedEnumNames: {}
35
36
  },
36
37
  pre: [__kubb_plugin_oas.pluginOasName, __kubb_plugin_ts.pluginTsName],
37
38
  resolvePath(baseName, pathMode, options$1) {
@@ -59,11 +60,10 @@ const pluginFaker = (0, __kubb_core.createPlugin)((options) => {
59
60
  if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
60
61
  return resolvedName;
61
62
  },
62
- async buildStart() {
63
- const [swaggerPlugin] = __kubb_core.PluginManager.getDependedPlugins(this.plugins, [__kubb_plugin_oas.pluginOasName]);
64
- const oas = await swaggerPlugin.context.getOas();
63
+ async install() {
65
64
  const root = node_path.default.resolve(this.config.root, this.config.output.path);
66
65
  const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
66
+ const oas = await this.getOas();
67
67
  const schemaFiles = await new __kubb_plugin_oas.SchemaGenerator(this.plugin.options, {
68
68
  fabric: this.fabric,
69
69
  oas,
@@ -88,7 +88,7 @@ const pluginFaker = (0, __kubb_core.createPlugin)((options) => {
88
88
  mode
89
89
  }).build(...generators);
90
90
  await this.addFile(...operationFiles);
91
- const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fileManager.files, {
91
+ const barrelFiles = await (0, __kubb_core.getBarrelFiles)(this.fabric.files, {
92
92
  type: output.barrelType ?? "named",
93
93
  root,
94
94
  output,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["fakerGenerator","pluginOasName","pluginTsName","path","options","groupName: Group['name']","PluginManager","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\n },\n pre: [pluginOasName, pluginTsName],\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 = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fileManager.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.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,kBAAkB;AAE/B,MAAa,6CAAyC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,SAAS,EAAE,EACX,cAAc,OACd,kBAAkB,aAClB,WAAW,UACX,aAAa,SACb,aAAa,CAACA,sCAAe,CAAC,OAAO,QAAQ,EAC7C,iBAAiB,SACjB,gBACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,KAAK,CAACC,iCAAeC,8BAAa;EAClC,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1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Q,GAAG,eAAe;GAErC,MAAM,cAAc,sCAAqB,KAAK,YAAY,OAAO;IAC/D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["fakerGenerator","pluginOasName","pluginTsName","path","options","groupName: Group['name']","SchemaGenerator","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\n usedEnumNames: {},\n },\n pre: [pluginOasName, pluginTsName],\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 = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\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 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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...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.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;AAQA,MAAa,kBAAkB;AAE/B,MAAa,6CAAyC,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,SAAS,EAAE,EACX,cAAc,OACd,kBAAkB,aAClB,WAAW,UACX,aAAa,S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,IAAIG,kCAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,QAAQ,GAAG,YAAY;GAclC,MAAM,iBAAiB,MAZI,IAAIC,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UserPluginWithLifeCycle, n as PluginFaker, t as Options } from "./types-NHbH6Svj.cjs";
1
+ import { a as UserPluginWithLifeCycle, n as PluginFaker, t as Options } from "./types-BKduR7YF.cjs";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginFakerName = "plugin-faker";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as UserPluginWithLifeCycle, n as PluginFaker, t as Options } from "./types-CEWRTyrN.js";
1
+ import { a as UserPluginWithLifeCycle, n as PluginFaker, t as Options } from "./types-BEAw2_Gh.js";
2
2
 
3
3
  //#region src/plugin.d.ts
4
4
  declare const pluginFakerName = "plugin-faker";
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import "./components-B6wjVu4Y.js";
2
2
  import { t as fakerGenerator } from "./fakerGenerator-CfTiMdtr.js";
3
3
  import path from "node:path";
4
- import { PluginManager, createPlugin, getBarrelFiles, getMode } from "@kubb/core";
4
+ import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
5
5
  import { camelCase } from "@kubb/core/transformers";
6
6
  import { OperationGenerator, SchemaGenerator, pluginOasName } from "@kubb/plugin-oas";
7
7
  import { pluginTsName } from "@kubb/plugin-ts";
8
8
 
9
9
  //#region src/plugin.ts
10
10
  const pluginFakerName = "plugin-faker";
11
- const pluginFaker = createPlugin((options) => {
11
+ const pluginFaker = definePlugin((options) => {
12
12
  const { output = {
13
13
  path: "mocks",
14
14
  barrelType: "named"
@@ -26,7 +26,8 @@ const pluginFaker = createPlugin((options) => {
26
26
  mapper,
27
27
  override,
28
28
  regexGenerator,
29
- group
29
+ group,
30
+ usedEnumNames: {}
30
31
  },
31
32
  pre: [pluginOasName, pluginTsName],
32
33
  resolvePath(baseName, pathMode, options$1) {
@@ -54,11 +55,10 @@ const pluginFaker = createPlugin((options) => {
54
55
  if (type) return transformers$1?.name?.(resolvedName, type) || resolvedName;
55
56
  return resolvedName;
56
57
  },
57
- async buildStart() {
58
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
59
- const oas = await swaggerPlugin.context.getOas();
58
+ async install() {
60
59
  const root = path.resolve(this.config.root, this.config.output.path);
61
60
  const mode = getMode(path.resolve(root, output.path));
61
+ const oas = await this.getOas();
62
62
  const schemaFiles = await new SchemaGenerator(this.plugin.options, {
63
63
  fabric: this.fabric,
64
64
  oas,
@@ -83,7 +83,7 @@ const pluginFaker = createPlugin((options) => {
83
83
  mode
84
84
  }).build(...generators);
85
85
  await this.addFile(...operationFiles);
86
- const barrelFiles = await getBarrelFiles(this.fileManager.files, {
86
+ const barrelFiles = await getBarrelFiles(this.fabric.files, {
87
87
  type: output.barrelType ?? "named",
88
88
  root,
89
89
  output,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["options","groupName: Group['name']","transformers"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = createPlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\n },\n pre: [pluginOasName, pluginTsName],\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 = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...operationFiles)\n\n const barrelFiles = await getBarrelFiles(this.fileManager.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.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AASA,MAAa,kBAAkB;AAE/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,MACA,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,+BAAe,EAAE,EACjB,SAAS,EAAE,EACX,cAAc,OACd,kBAAkB,aAClB,WAAW,UACX,aAAa,SACb,aAAa,CAAC,eAAe,CAAC,OAAO,QAAQ,EAC7C,iBAAiB,SACjB,gBACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,KAAK,CAAC,eAAe,aAAa;EAClC,YAAY,UAAU,UAAU,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AEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,QAAQ,GAAG,YAAY;GAclC,MAAM,iBAAiB,MAZI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,MAAM,cAAc,MAAM,eAAe,KAAK,YAAY,OAAO;IAC/D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
1
+ {"version":3,"file":"index.js","names":["options","groupName: Group['name']","transformers"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { fakerGenerator } from './generators/fakerGenerator.tsx'\nimport type { PluginFaker } from './types.ts'\n\nexport const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']\n\nexport const pluginFaker = definePlugin<PluginFaker>((options) => {\n const {\n output = { path: 'mocks', barrelType: 'named' },\n seed,\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n mapper = {},\n unknownType = 'any',\n emptySchemaType = unknownType,\n dateType = 'string',\n dateParser = 'faker',\n generators = [fakerGenerator].filter(Boolean),\n regexGenerator = 'faker',\n contentType,\n } = options\n\n return {\n name: pluginFakerName,\n options: {\n output,\n transformers,\n seed,\n dateType,\n unknownType,\n emptySchemaType,\n dateParser,\n mapper,\n override,\n regexGenerator,\n group,\n usedEnumNames: {},\n },\n pre: [pluginOasName, pluginTsName],\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 = camelCase(name, {\n prefix: type ? 'create' : undefined,\n isFile: type === 'file',\n })\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 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.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\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.addFile(...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.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAQA,MAAa,kBAAkB;AA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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;GAc/B,MAAM,cAAc,MAZI,IAAI,gBAAgB,KAAK,OAAO,SAAS;IAC/D,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA,SAAS;IACT;IACA;IACA,QAAQ,OAAO;IAChB,CAAC,CAEwC,MAAM,GAAG,WAAW;AAC9D,SAAM,KAAK,QAAQ,GAAG,YAAY;GAclC,MAAM,iBAAiB,MAZI,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAE8C,MAAM,GAAG,WAAW;AACpE,SAAM,KAAK,QAAQ,GAAG,eAAe;GAErC,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,QAAQ,GAAG,YAAY;;EAErC;EACD"}
@@ -1,4 +1,4 @@
1
- import { Fabric, FileManager } from "@kubb/react-fabric";
1
+ import { Fabric } from "@kubb/react-fabric";
2
2
  import { KubbFile } from "@kubb/fabric-core/types";
3
3
  import { ConsolaInstance, LogLevel } from "consola";
4
4
  import * as OasTypes from "oas/types";
@@ -75,6 +75,21 @@ type Logger = {
75
75
  type PossiblePromise<T> = Promise<T> | T;
76
76
  //#endregion
77
77
  //#region ../core/src/types.d.ts
78
+ declare global {
79
+ namespace Kubb {
80
+ interface PluginContext {}
81
+ }
82
+ }
83
+ /**
84
+ * Config used in `kubb.config.ts`
85
+ *
86
+ * @example
87
+ * import { defineConfig } from '@kubb/core'
88
+ * export default defineConfig({
89
+ * ...
90
+ * })
91
+ */
92
+
78
93
  type InputPath = {
79
94
  /**
80
95
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -229,11 +244,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
229
244
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
230
245
  */
231
246
  post?: Array<string>;
232
- } & (TOptions['context'] extends never ? {
233
- context?: never;
234
- } : {
235
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
236
- });
247
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
248
+ };
237
249
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
238
250
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
239
251
  /**
@@ -259,25 +271,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
259
271
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
260
272
  */
261
273
  options: TOptions['resolvedOptions'];
262
- } & (TOptions['context'] extends never ? {
263
- context?: never;
264
- } : {
265
- context: TOptions['context'];
266
- });
274
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
275
+ /**
276
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
277
+ */
278
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
279
+ };
267
280
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
268
281
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
269
282
  /**
270
283
  * Start of the lifecycle of a plugin.
271
284
  * @type hookParallel
272
285
  */
273
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
286
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
274
287
  /**
275
288
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
276
289
  * Options can als be included.
277
290
  * @type hookFirst
278
291
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
279
292
  */
280
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
293
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
281
294
  /**
282
295
  * Resolve to a name based on a string.
283
296
  * Useful when converting to PascalCase or camelCase.
@@ -285,11 +298,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
285
298
  * @example ('pet') => 'Pet'
286
299
  */
287
300
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
288
- /**
289
- * End of the plugin lifecycle.
290
- * @type hookParallel
291
- */
292
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
293
301
  };
294
302
  type PluginLifecycleHooks = keyof PluginLifecycle;
295
303
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -316,24 +324,15 @@ type ResolveNameParams = {
316
324
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
317
325
  fabric: Fabric;
318
326
  config: Config;
319
- /**
320
- * @deprecated
321
- */
322
- fileManager: FileManager;
323
327
  pluginManager: PluginManager;
324
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
325
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
326
- resolveName: (params: ResolveNameParams) => string;
328
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
327
329
  logger: Logger;
328
- /**
329
- * All plugins
330
- */
331
- plugins: Plugin[];
330
+ mode: KubbFile.Mode;
332
331
  /**
333
332
  * Current plugin
334
333
  */
335
334
  plugin: Plugin<TOptions>;
336
- };
335
+ } & Kubb.PluginContext;
337
336
  /**
338
337
  * Specify the export location for the files and define the behavior of the output
339
338
  */
@@ -408,13 +407,14 @@ type GetFileProps<TOptions = object> = {
408
407
  };
409
408
  declare class PluginManager {
410
409
  #private;
411
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
412
410
  readonly events: EventEmitter<Events>;
413
411
  readonly config: Config;
414
412
  readonly executed: Array<Executer>;
415
413
  readonly logger: Logger;
416
414
  readonly options: Options$3;
417
415
  constructor(config: Config, options: Options$3);
416
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
417
+ get plugins(): Array<Plugin>;
418
418
  getFile<TOptions = object>({
419
419
  name,
420
420
  mode,
@@ -424,7 +424,7 @@ declare class PluginManager {
424
424
  }: GetFileProps<TOptions>): KubbFile.File<{
425
425
  pluginKey: Plugin['key'];
426
426
  }>;
427
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
427
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
428
428
  resolveName: (params: ResolveNameParams) => string;
429
429
  /**
430
430
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -512,11 +512,9 @@ declare class PluginManager {
512
512
  }): Promise<void>;
513
513
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
514
514
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
515
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
516
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
517
515
  }
518
516
  //#endregion
519
- //#region ../core/src/FileManager.d.ts
517
+ //#region ../core/src/utils/getBarrelFiles.d.ts
520
518
  type FileMetaBase = {
521
519
  pluginKey?: Plugin['key'];
522
520
  };
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
669
667
  /**
670
668
  * Full qualified path.
671
669
  */
672
- path: KubbFile.OptionalPath;
670
+ path: KubbFile.Path;
673
671
  /**
674
672
  * When true `File.Import` will be used.
675
673
  * When false a reference will be used inside the current file.
@@ -774,6 +772,15 @@ type Schema = {
774
772
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
775
773
  //#endregion
776
774
  //#region ../plugin-oas/src/types.d.ts
775
+ type Context$2 = {
776
+ getOas(): Promise<Oas>;
777
+ getBaseURL(): Promise<string | undefined>;
778
+ };
779
+ declare global {
780
+ namespace Kubb {
781
+ interface PluginContext extends Context$2 {}
782
+ }
783
+ }
777
784
  type ResolvePathOptions = {
778
785
  pluginKey?: Plugin['key'];
779
786
  group?: {
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
794
801
  type Ref = {
795
802
  propertyName: string;
796
803
  originalName: string;
797
- path: KubbFile.OptionalPath;
804
+ path: KubbFile.Path;
798
805
  pluginKey?: Plugin['key'];
799
806
  };
800
807
  type Refs = Record<string, Ref>;
@@ -1095,4 +1102,4 @@ type ResolvedOptions = {
1095
1102
  type PluginFaker = PluginFactoryOptions<'plugin-faker', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1096
1103
  //#endregion
1097
1104
  export { UserPluginWithLifeCycle as a, Schema as i, PluginFaker as n, ReactGenerator as r, Options$1 as t };
1098
- //# sourceMappingURL=types-CEWRTyrN.d.ts.map
1105
+ //# sourceMappingURL=types-BEAw2_Gh.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { KubbFile } from "@kubb/fabric-core/types";
2
- import { Fabric, FileManager } from "@kubb/react-fabric";
2
+ import { Fabric } from "@kubb/react-fabric";
3
3
  import { ConsolaInstance, LogLevel } from "consola";
4
4
  import * as OasTypes from "oas/types";
5
5
  import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
@@ -75,6 +75,21 @@ type Logger = {
75
75
  type PossiblePromise<T> = Promise<T> | T;
76
76
  //#endregion
77
77
  //#region ../core/src/types.d.ts
78
+ declare global {
79
+ namespace Kubb {
80
+ interface PluginContext {}
81
+ }
82
+ }
83
+ /**
84
+ * Config used in `kubb.config.ts`
85
+ *
86
+ * @example
87
+ * import { defineConfig } from '@kubb/core'
88
+ * export default defineConfig({
89
+ * ...
90
+ * })
91
+ */
92
+
78
93
  type InputPath = {
79
94
  /**
80
95
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -229,11 +244,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
229
244
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
230
245
  */
231
246
  post?: Array<string>;
232
- } & (TOptions['context'] extends never ? {
233
- context?: never;
234
- } : {
235
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
236
- });
247
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
248
+ };
237
249
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
238
250
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
239
251
  /**
@@ -259,25 +271,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
259
271
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
260
272
  */
261
273
  options: TOptions['resolvedOptions'];
262
- } & (TOptions['context'] extends never ? {
263
- context?: never;
264
- } : {
265
- context: TOptions['context'];
266
- });
274
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
275
+ /**
276
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
277
+ */
278
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
279
+ };
267
280
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
268
281
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
269
282
  /**
270
283
  * Start of the lifecycle of a plugin.
271
284
  * @type hookParallel
272
285
  */
273
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
286
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
274
287
  /**
275
288
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
276
289
  * Options can als be included.
277
290
  * @type hookFirst
278
291
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
279
292
  */
280
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
293
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
281
294
  /**
282
295
  * Resolve to a name based on a string.
283
296
  * Useful when converting to PascalCase or camelCase.
@@ -285,11 +298,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
285
298
  * @example ('pet') => 'Pet'
286
299
  */
287
300
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
288
- /**
289
- * End of the plugin lifecycle.
290
- * @type hookParallel
291
- */
292
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
293
301
  };
294
302
  type PluginLifecycleHooks = keyof PluginLifecycle;
295
303
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -316,24 +324,15 @@ type ResolveNameParams = {
316
324
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
317
325
  fabric: Fabric;
318
326
  config: Config;
319
- /**
320
- * @deprecated
321
- */
322
- fileManager: FileManager;
323
327
  pluginManager: PluginManager;
324
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
325
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
326
- resolveName: (params: ResolveNameParams) => string;
328
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
327
329
  logger: Logger;
328
- /**
329
- * All plugins
330
- */
331
- plugins: Plugin[];
330
+ mode: KubbFile.Mode;
332
331
  /**
333
332
  * Current plugin
334
333
  */
335
334
  plugin: Plugin<TOptions>;
336
- };
335
+ } & Kubb.PluginContext;
337
336
  /**
338
337
  * Specify the export location for the files and define the behavior of the output
339
338
  */
@@ -408,13 +407,14 @@ type GetFileProps<TOptions = object> = {
408
407
  };
409
408
  declare class PluginManager {
410
409
  #private;
411
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
412
410
  readonly events: EventEmitter<Events>;
413
411
  readonly config: Config;
414
412
  readonly executed: Array<Executer>;
415
413
  readonly logger: Logger;
416
414
  readonly options: Options$3;
417
415
  constructor(config: Config, options: Options$3);
416
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
417
+ get plugins(): Array<Plugin>;
418
418
  getFile<TOptions = object>({
419
419
  name,
420
420
  mode,
@@ -424,7 +424,7 @@ declare class PluginManager {
424
424
  }: GetFileProps<TOptions>): KubbFile.File<{
425
425
  pluginKey: Plugin['key'];
426
426
  }>;
427
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
427
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
428
428
  resolveName: (params: ResolveNameParams) => string;
429
429
  /**
430
430
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -512,11 +512,9 @@ declare class PluginManager {
512
512
  }): Promise<void>;
513
513
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
514
514
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
515
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
516
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
517
515
  }
518
516
  //#endregion
519
- //#region ../core/src/FileManager.d.ts
517
+ //#region ../core/src/utils/getBarrelFiles.d.ts
520
518
  type FileMetaBase = {
521
519
  pluginKey?: Plugin['key'];
522
520
  };
@@ -669,7 +667,7 @@ type SchemaKeywordMapper = {
669
667
  /**
670
668
  * Full qualified path.
671
669
  */
672
- path: KubbFile.OptionalPath;
670
+ path: KubbFile.Path;
673
671
  /**
674
672
  * When true `File.Import` will be used.
675
673
  * When false a reference will be used inside the current file.
@@ -774,6 +772,15 @@ type Schema = {
774
772
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
775
773
  //#endregion
776
774
  //#region ../plugin-oas/src/types.d.ts
775
+ type Context$2 = {
776
+ getOas(): Promise<Oas>;
777
+ getBaseURL(): Promise<string | undefined>;
778
+ };
779
+ declare global {
780
+ namespace Kubb {
781
+ interface PluginContext extends Context$2 {}
782
+ }
783
+ }
777
784
  type ResolvePathOptions = {
778
785
  pluginKey?: Plugin['key'];
779
786
  group?: {
@@ -794,7 +801,7 @@ type ResolvePathOptions = {
794
801
  type Ref = {
795
802
  propertyName: string;
796
803
  originalName: string;
797
- path: KubbFile.OptionalPath;
804
+ path: KubbFile.Path;
798
805
  pluginKey?: Plugin['key'];
799
806
  };
800
807
  type Refs = Record<string, Ref>;
@@ -1095,4 +1102,4 @@ type ResolvedOptions = {
1095
1102
  type PluginFaker = PluginFactoryOptions<'plugin-faker', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1096
1103
  //#endregion
1097
1104
  export { UserPluginWithLifeCycle as a, Schema as i, PluginFaker as n, ReactGenerator as r, Options$1 as t };
1098
- //# sourceMappingURL=types-NHbH6Svj.d.cts.map
1105
+ //# sourceMappingURL=types-BKduR7YF.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-faker",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
4
4
  "description": "Faker.js data generator plugin for Kubb, creating realistic mock data from OpenAPI specifications for development and testing.",
5
5
  "keywords": [
6
6
  "faker",
@@ -68,17 +68,17 @@
68
68
  }
69
69
  ],
70
70
  "dependencies": {
71
- "@kubb/react-fabric": "0.2.14",
72
- "@kubb/core": "4.5.1",
73
- "@kubb/oas": "4.5.1",
74
- "@kubb/plugin-oas": "4.5.1",
75
- "@kubb/plugin-ts": "4.5.1"
71
+ "@kubb/react-fabric": "0.2.19",
72
+ "@kubb/oas": "4.5.2",
73
+ "@kubb/plugin-oas": "4.5.2",
74
+ "@kubb/plugin-ts": "4.5.2",
75
+ "@kubb/core": "4.5.2"
76
76
  },
77
77
  "devDependencies": {
78
- "@kubb/plugin-oas": "4.5.1"
78
+ "@kubb/plugin-oas": "4.5.2"
79
79
  },
80
80
  "peerDependencies": {
81
- "@kubb/react-fabric": "0.2.14"
81
+ "@kubb/react-fabric": "0.2.19"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=20"
package/src/plugin.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import path from 'node:path'
2
- import { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'
2
+ import { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
3
3
  import { camelCase } from '@kubb/core/transformers'
4
- import type { PluginOas } from '@kubb/plugin-oas'
5
4
  import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
6
5
  import { pluginTsName } from '@kubb/plugin-ts'
7
6
  import { fakerGenerator } from './generators/fakerGenerator.tsx'
@@ -9,7 +8,7 @@ import type { PluginFaker } from './types.ts'
9
8
 
10
9
  export const pluginFakerName = 'plugin-faker' satisfies PluginFaker['name']
11
10
 
12
- export const pluginFaker = createPlugin<PluginFaker>((options) => {
11
+ export const pluginFaker = definePlugin<PluginFaker>((options) => {
13
12
  const {
14
13
  output = { path: 'mocks', barrelType: 'named' },
15
14
  seed,
@@ -42,6 +41,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
42
41
  override,
43
42
  regexGenerator,
44
43
  group,
44
+ usedEnumNames: {},
45
45
  },
46
46
  pre: [pluginOasName, pluginTsName],
47
47
  resolvePath(baseName, pathMode, options) {
@@ -90,12 +90,10 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
90
90
 
91
91
  return resolvedName
92
92
  },
93
- async buildStart() {
94
- const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])
95
-
96
- const oas = await swaggerPlugin.context.getOas()
93
+ async install() {
97
94
  const root = path.resolve(this.config.root, this.config.output.path)
98
95
  const mode = getMode(path.resolve(root, output.path))
96
+ const oas = await this.getOas()
99
97
 
100
98
  const schemaGenerator = new SchemaGenerator(this.plugin.options, {
101
99
  fabric: this.fabric,
@@ -127,7 +125,7 @@ export const pluginFaker = createPlugin<PluginFaker>((options) => {
127
125
  const operationFiles = await operationGenerator.build(...generators)
128
126
  await this.addFile(...operationFiles)
129
127
 
130
- const barrelFiles = await getBarrelFiles(this.fileManager.files, {
128
+ const barrelFiles = await getBarrelFiles(this.fabric.files, {
131
129
  type: output.barrelType ?? 'named',
132
130
  root,
133
131
  output,