@kubb/plugin-faker 5.0.0-beta.81 → 5.0.0-beta.84

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.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { buildObject, containsCircularRef, extractRefName, jsStringEscape, mapSchemaItems, mapSchemaMembers, objectKey, stringify, toRegExpString } from "@kubb/ast/utils";
2
+ import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
3
3
  import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
4
- import { File, Function, jsxRenderer } from "@kubb/renderer-jsx";
4
+ import { File, Function, jsxRenderer } from "kubb/jsx";
5
5
  import path, { posix } from "node:path";
6
- import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
7
- import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
+ import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
8
7
  import { createHash } from "node:crypto";
9
8
  //#region src/utils.ts
10
9
  /**
@@ -236,17 +235,17 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
236
235
  children: /* @__PURE__ */ jsxs(Function, {
237
236
  export: true,
238
237
  name,
239
- JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
238
+ JSDoc: { comments: description ? [`@description ${ast.jsStringEscape(description)}`] : [] },
240
239
  params: canOverride ? paramsSignature : void 0,
241
240
  returnType: returnType ?? void 0,
242
241
  children: [seed ? /* @__PURE__ */ jsxs(Fragment, { children: [`faker.seed(${JSON.stringify(seed)})`, /* @__PURE__ */ jsx("br", {})] }) : void 0, `return ${returnExpression}`]
243
242
  })
244
243
  });
245
244
  }
246
- const functionSignature = `${description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : ""}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
245
+ const functionSignature = `${description ? `/**\n * @description ${ast.jsStringEscape(description)}\n */\n ` : ""}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
247
246
  const seedCode = seed ? `faker.seed(${JSON.stringify(seed)})\n ` : "";
248
247
  const { cyclicSchemas, schemaName } = printer.options;
249
- const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => containsCircularRef(p.schema, {
248
+ const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => ast.containsCircularRef(p.schema, {
250
249
  circularSchemas: cyclicSchemas,
251
250
  excludeName: schemaName
252
251
  })) ? `{
@@ -656,7 +655,7 @@ const fakerKeywordMapper = {
656
655
  return `{...${items.join(", ...")}}`;
657
656
  },
658
657
  matches: (value = "", regexGenerator = "faker") => {
659
- if (regexGenerator === "randexp") return `${toRegExpString(value, "RandExp")}.gen()`;
658
+ if (regexGenerator === "randexp") return `${ast.toRegExpString(value, "RandExp")}.gen()`;
660
659
  return `faker.helpers.fromRegExp("${value}")`;
661
660
  },
662
661
  email: () => "faker.internet.email()",
@@ -667,7 +666,7 @@ function getEnumValues(node) {
667
666
  return node.enumValues ?? [];
668
667
  }
669
668
  function parseEnumValue(value) {
670
- if (typeof value === "string") return stringify(value);
669
+ if (typeof value === "string") return ast.stringify(value);
671
670
  return value;
672
671
  }
673
672
  /**
@@ -732,7 +731,7 @@ const printerFaker = ast.createPrinter((options) => {
732
731
  return fakerKeywordMapper.time(node.representation ?? "string", this.options.dateParser);
733
732
  },
734
733
  ref(node) {
735
- const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? extractRefName(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
734
+ const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? ast.extractRefName(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
736
735
  if (!refName) throw new Error("Name not defined for ref node");
737
736
  if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
738
737
  const resolvedName = node.ref ? this.options.resolver.resolveName(refName) : refName;
@@ -745,7 +744,7 @@ const printerFaker = ast.createPrinter((options) => {
745
744
  union(node) {
746
745
  const { discriminatorPropertyName } = node;
747
746
  const baseTypeName = this.options.typeName;
748
- const items = mapSchemaMembers(node, (member) => {
747
+ const items = ast.mapSchemaMembers(node, (member) => {
749
748
  const value = discriminatorPropertyName ? getDiscriminatorValue(member, discriminatorPropertyName) : void 0;
750
749
  if (baseTypeName && value !== void 0) return printNested(member, {
751
750
  typeName: `Extract<NonNullable<${baseTypeName}>, { ${JSON.stringify(discriminatorPropertyName)}: ${parseEnumValue(value)} }>`,
@@ -760,11 +759,11 @@ const printerFaker = ast.createPrinter((options) => {
760
759
  return fakerKeywordMapper.union(items);
761
760
  },
762
761
  intersection(node) {
763
- const items = mapSchemaMembers(node, (member) => printNested(member, { nestedInObject: true })).map(({ output }) => output).filter((item) => Boolean(item) && item !== "undefined");
762
+ const items = ast.mapSchemaMembers(node, (member) => printNested(member, { nestedInObject: true })).map(({ output }) => output).filter((item) => Boolean(item) && item !== "undefined");
764
763
  return fakerKeywordMapper.and(items);
765
764
  },
766
765
  array(node) {
767
- const items = mapSchemaItems(node, (member) => printNested(member, {
766
+ const items = ast.mapSchemaItems(node, (member) => printNested(member, {
768
767
  typeName: this.options.typeName ? `NonNullable<${this.options.typeName}>[number]` : void 0,
769
768
  nestedInObject: true
770
769
  })).map(({ output }) => output).filter((item) => Boolean(item));
@@ -779,17 +778,18 @@ const printerFaker = ast.createPrinter((options) => {
779
778
  },
780
779
  object(node) {
781
780
  const cyclicSchemas = this.options.cyclicSchemas;
782
- return buildObject((node.properties ?? []).map((property) => {
781
+ const entries = (node.properties ?? []).map((property) => {
783
782
  const value = printNested(property.schema, {
784
783
  typeName: this.options.typeName ? indexedTypeName(this.options.typeName, property.name, this.options.nestedInUnion) : void 0,
785
784
  nestedInObject: true
786
785
  }) ?? "undefined";
787
- if (cyclicSchemas && containsCircularRef(property.schema, {
786
+ if (cyclicSchemas && ast.containsCircularRef(property.schema, {
788
787
  circularSchemas: cyclicSchemas,
789
788
  excludeName: this.options.schemaName
790
- })) return `get ${objectKey(property.name)}() { const _value = ${value}; Object.defineProperty(this, ${JSON.stringify(property.name)}, { value: _value, configurable: true, writable: true, enumerable: true }); return _value }`;
791
- return `${objectKey(property.name)}: ${value}`;
792
- }));
789
+ })) return `get ${ast.objectKey(property.name)}() { const _value = ${value}; Object.defineProperty(this, ${JSON.stringify(property.name)}, { value: _value, configurable: true, writable: true, enumerable: true }); return _value }`;
790
+ return `${ast.objectKey(property.name)}: ${value}`;
791
+ });
792
+ return ast.buildObject(entries);
793
793
  },
794
794
  ...options.nodes
795
795
  },
@@ -1237,7 +1237,7 @@ const pluginFakerName = "plugin-faker";
1237
1237
  *
1238
1238
  * @example
1239
1239
  * ```ts
1240
- * import { defineConfig } from 'kubb'
1240
+ * import { defineConfig } from 'kubb/config'
1241
1241
  * import { pluginTs } from '@kubb/plugin-ts'
1242
1242
  * import { pluginFaker } from '@kubb/plugin-faker'
1243
1243
  *