@kubb/plugin-faker 5.1.0 → 5.1.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/index.cjs CHANGED
@@ -613,33 +613,35 @@ function Faker({ node, description, name, typeName, printer, canOverride, typeMo
613
613
  })
614
614
  });
615
615
  }
616
- const jsdoc = description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : "";
617
- const functionSignature = typeMode === "schema" ? `${jsdoc}export function ${name}(data?: Partial<${typeName}>): ${typeName}` : `${jsdoc}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
618
616
  const returnType = typeMode === "schema" ? typeName : "Omit<typeof defaultFakeData, keyof NoInfer<TData>> & NoInfer<TData>";
619
617
  const { cyclicSchemas, schemaName } = printer.options;
620
618
  const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => (0, kubb_kit.containsCircularRef)(p.schema, {
621
619
  circularSchemas: cyclicSchemas,
622
620
  excludeName: schemaName
623
- })) ? `{
624
- const defaultFakeData = ${fakerText}
625
- if (data) {
626
- for (const [key, value] of Object.entries(data)) {
627
- Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
628
- }
621
+ })) ? `const defaultFakeData = ${fakerText}
622
+ if (data) {
623
+ for (const [key, value] of Object.entries(data)) {
624
+ Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
629
625
  }
630
- return defaultFakeData as ${returnType}
631
- }` : `{
632
- const defaultFakeData = ${fakerText}
633
- return {
634
- ...defaultFakeData,
635
- ...(data || {}),
636
- } as ${returnType}
637
- }`;
638
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File.Source, {
626
+ }
627
+ return defaultFakeData as ${returnType}` : `const defaultFakeData = ${fakerText}
628
+ return {
629
+ ...defaultFakeData,
630
+ ...(data || {}),
631
+ } as ${returnType}`;
632
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
639
633
  name,
640
634
  isExportable: true,
641
635
  isIndexable: true,
642
- children: [functionSignature, functionBody]
636
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
637
+ export: true,
638
+ name,
639
+ JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
640
+ generics: typeMode === "schema" ? void 0 : `TData extends Partial<${typeName}> = object`,
641
+ params: typeMode === "schema" ? `data?: Partial<${typeName}>` : "data?: TData",
642
+ returnType: typeMode === "schema" ? typeName : void 0,
643
+ children: functionBody
644
+ })
643
645
  });
644
646
  }
645
647
  //#endregion
@@ -1153,8 +1155,8 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1153
1155
  schema(node, ctx) {
1154
1156
  const { config, resolver, root } = ctx;
1155
1157
  const { output, group, dateParser, regexGenerator, seed, locale, printer, typeMode } = ctx.options;
1156
- const pluginTs = ctx.driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1157
- if (!node.name || !pluginTs) return;
1158
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1159
+ if (!node.name) return;
1158
1160
  const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
1159
1161
  const schemaName = node.name;
1160
1162
  const isEnumSchema = !!kubb_kit.ast.narrowSchema(node, kubb_kit.ast.schemaTypes.enum);
@@ -1275,8 +1277,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1275
1277
  operation(node, ctx) {
1276
1278
  const { config, resolver, root } = ctx;
1277
1279
  const { output, group, dateParser, regexGenerator, seed, locale, printer, typeMode } = ctx.options;
1278
- const pluginTs = ctx.driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1279
- if (!pluginTs) return;
1280
+ const pluginTs = ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1280
1281
  const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
1281
1282
  const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
1282
1283
  const paramGroups = [
@@ -1560,6 +1561,7 @@ const pluginFaker = (0, kubb_kit.definePlugin)((options) => {
1560
1561
  options,
1561
1562
  dependencies: [_kubb_plugin_ts.pluginTsName],
1562
1563
  hooks: { "kubb:plugin:setup"(ctx) {
1564
+ ctx.requirePlugin(_kubb_plugin_ts.pluginTsName);
1563
1565
  ctx.setOptions({
1564
1566
  output,
1565
1567
  seed,