@kubb/plugin-faker 5.0.0-beta.76 → 5.0.0-beta.79

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
@@ -58,7 +58,7 @@ function localeToFakerImport(locale) {
58
58
  * Determines if a schema node can be overridden during faker generation.
59
59
  */
60
60
  function canOverrideSchema(node) {
61
- return new Set([
61
+ return (/* @__PURE__ */ new Set([
62
62
  "array",
63
63
  "tuple",
64
64
  "object",
@@ -78,7 +78,7 @@ function canOverrideSchema(node) {
78
78
  "time",
79
79
  "datetime",
80
80
  "blob"
81
- ]).has(node.type);
81
+ ])).has(node.type);
82
82
  }
83
83
  /**
84
84
  * Resolves a parameter name based on its location (path, query, header, etc.) using the provided resolver.
@@ -92,7 +92,7 @@ function resolveParamNameByLocation(resolver, node, param) {
92
92
  }
93
93
  }
94
94
  function shouldInlineSingleResponseSchema(schema) {
95
- return new Set([
95
+ return (/* @__PURE__ */ new Set([
96
96
  "any",
97
97
  "unknown",
98
98
  "void",
@@ -113,7 +113,7 @@ function shouldInlineSingleResponseSchema(schema) {
113
113
  "blob",
114
114
  "enum",
115
115
  "union"
116
- ]).has(schema.type);
116
+ ])).has(schema.type);
117
117
  }
118
118
  /**
119
119
  * Builds a response schema as a union of all response statuses.
@@ -138,7 +138,7 @@ function buildResponseUnionSchema(node, resolver) {
138
138
  }))
139
139
  });
140
140
  }
141
- const SCALAR_TYPES$1 = new Set([
141
+ const SCALAR_TYPES$1 = /* @__PURE__ */ new Set([
142
142
  "string",
143
143
  "email",
144
144
  "url",
@@ -153,7 +153,7 @@ const SCALAR_TYPES$1 = new Set([
153
153
  "blob",
154
154
  "enum"
155
155
  ]);
156
- const ARRAY_TYPES$1 = new Set(["array"]);
156
+ const ARRAY_TYPES$1 = /* @__PURE__ */ new Set(["array"]);
157
157
  function toRelativeImportPath(from, to) {
158
158
  const relativePath = node_path.posix.relative(node_path.posix.dirname(from), to);
159
159
  return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
@@ -214,9 +214,9 @@ function resolveFakerTypeUsage(node, typeName, canOverride) {
214
214
  }
215
215
  //#endregion
216
216
  //#region src/components/Faker.tsx
217
- const OBJECT_TYPES = new Set(["object", "intersection"]);
218
- const ARRAY_TYPES = new Set(["array"]);
219
- const SCALAR_TYPES = new Set([
217
+ const OBJECT_TYPES = /* @__PURE__ */ new Set(["object", "intersection"]);
218
+ const ARRAY_TYPES = /* @__PURE__ */ new Set(["array"]);
219
+ const SCALAR_TYPES = /* @__PURE__ */ new Set([
220
220
  "string",
221
221
  "email",
222
222
  "url",
@@ -400,7 +400,7 @@ function rewriteAliasedImports(text, aliases) {
400
400
  * JavaScript and Java reserved words.
401
401
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
402
402
  */
403
- const reservedWords = new Set([
403
+ const reservedWords = /* @__PURE__ */ new Set([
404
404
  "abstract",
405
405
  "arguments",
406
406
  "boolean",
@@ -655,8 +655,8 @@ const fakerKeywordMapper = {
655
655
  return `faker.helpers.multiple(() => (${item}))`;
656
656
  },
657
657
  tuple: (items = []) => `[${items.join(", ")}]`,
658
- enum: (items = [], type = "any") => `faker.helpers.arrayElement<${type}>([${items.join(", ")}])`,
659
- union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
658
+ enum: (items = [], type) => `faker.helpers.arrayElement${type ? `<${type}>` : ""}([${items.join(", ")}])`,
659
+ union: (items = []) => `faker.helpers.arrayElement([${items.join(", ")}])`,
660
660
  datetime: () => "faker.date.anytime().toISOString()",
661
661
  date: (representation = "string", parser = "faker") => {
662
662
  if (representation === "string") {
@@ -756,9 +756,9 @@ const printerFaker = _kubb_core.ast.createPrinter((options) => {
756
756
  return fakerKeywordMapper.time(node.representation ?? "string", this.options.dateParser);
757
757
  },
758
758
  ref(node) {
759
- const refName = node.ref ? (0, _kubb_ast_utils.extractRefName)(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
759
+ const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? (0, _kubb_ast_utils.extractRefName)(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
760
760
  if (!refName) throw new Error("Name not defined for ref node");
761
- if (this.options.schemaName && refName === this.options.schemaName) return "undefined as any";
761
+ if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
762
762
  const resolvedName = node.ref ? this.options.resolver.resolveName(refName) : refName;
763
763
  if (!this.options.nestedInObject) return `${resolvedName}(data)`;
764
764
  return `${resolvedName}()`;
@@ -875,7 +875,8 @@ const fakerGenerator = (0, _kubb_core.defineGenerator)({
875
875
  regexGenerator,
876
876
  mapper,
877
877
  nodes: printer?.nodes,
878
- cyclicSchemas
878
+ cyclicSchemas,
879
+ nameMapping: adapter.options.nameMapping
879
880
  });
880
881
  const fakerText = printerInstance.print(node) ?? "undefined";
881
882
  const typeReference = resolveTypeReference({
@@ -1012,7 +1013,7 @@ const fakerGenerator = (0, _kubb_core.defineGenerator)({
1012
1013
  description: node.requestBody?.description ?? schema.description
1013
1014
  }));
1014
1015
  const responseName = resolver.resolveResponseName(node);
1015
- const localHelperNames = new Set([
1016
+ const localHelperNames = /* @__PURE__ */ new Set([
1016
1017
  ...paramEntries.map((entry) => entry.name),
1017
1018
  ...responseUnits.map((unit) => unit.name),
1018
1019
  ...dataUnits.map((unit) => unit.name),
@@ -1065,7 +1066,8 @@ const fakerGenerator = (0, _kubb_core.defineGenerator)({
1065
1066
  regexGenerator,
1066
1067
  mapper,
1067
1068
  nodes: printer?.nodes,
1068
- cyclicSchemas
1069
+ cyclicSchemas,
1070
+ nameMapping: adapter.options.nameMapping
1069
1071
  });
1070
1072
  const fakerText = printerInstance.print(schema) ?? "undefined";
1071
1073
  const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);