@kubb/plugin-faker 5.0.0-beta.77 → 5.0.0-beta.80

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
@@ -32,7 +32,7 @@ function localeToFakerImport(locale) {
32
32
  * Determines if a schema node can be overridden during faker generation.
33
33
  */
34
34
  function canOverrideSchema(node) {
35
- return new Set([
35
+ return (/* @__PURE__ */ new Set([
36
36
  "array",
37
37
  "tuple",
38
38
  "object",
@@ -52,7 +52,7 @@ function canOverrideSchema(node) {
52
52
  "time",
53
53
  "datetime",
54
54
  "blob"
55
- ]).has(node.type);
55
+ ])).has(node.type);
56
56
  }
57
57
  /**
58
58
  * Resolves a parameter name based on its location (path, query, header, etc.) using the provided resolver.
@@ -66,7 +66,7 @@ function resolveParamNameByLocation(resolver, node, param) {
66
66
  }
67
67
  }
68
68
  function shouldInlineSingleResponseSchema(schema) {
69
- return new Set([
69
+ return (/* @__PURE__ */ new Set([
70
70
  "any",
71
71
  "unknown",
72
72
  "void",
@@ -87,7 +87,7 @@ function shouldInlineSingleResponseSchema(schema) {
87
87
  "blob",
88
88
  "enum",
89
89
  "union"
90
- ]).has(schema.type);
90
+ ])).has(schema.type);
91
91
  }
92
92
  /**
93
93
  * Builds a response schema as a union of all response statuses.
@@ -112,7 +112,7 @@ function buildResponseUnionSchema(node, resolver) {
112
112
  }))
113
113
  });
114
114
  }
115
- const SCALAR_TYPES$1 = new Set([
115
+ const SCALAR_TYPES$1 = /* @__PURE__ */ new Set([
116
116
  "string",
117
117
  "email",
118
118
  "url",
@@ -127,7 +127,7 @@ const SCALAR_TYPES$1 = new Set([
127
127
  "blob",
128
128
  "enum"
129
129
  ]);
130
- const ARRAY_TYPES$1 = new Set(["array"]);
130
+ const ARRAY_TYPES$1 = /* @__PURE__ */ new Set(["array"]);
131
131
  function toRelativeImportPath(from, to) {
132
132
  const relativePath = posix.relative(posix.dirname(from), to);
133
133
  return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
@@ -188,9 +188,9 @@ function resolveFakerTypeUsage(node, typeName, canOverride) {
188
188
  }
189
189
  //#endregion
190
190
  //#region src/components/Faker.tsx
191
- const OBJECT_TYPES = new Set(["object", "intersection"]);
192
- const ARRAY_TYPES = new Set(["array"]);
193
- const SCALAR_TYPES = new Set([
191
+ const OBJECT_TYPES = /* @__PURE__ */ new Set(["object", "intersection"]);
192
+ const ARRAY_TYPES = /* @__PURE__ */ new Set(["array"]);
193
+ const SCALAR_TYPES = /* @__PURE__ */ new Set([
194
194
  "string",
195
195
  "email",
196
196
  "url",
@@ -374,7 +374,7 @@ function rewriteAliasedImports(text, aliases) {
374
374
  * JavaScript and Java reserved words.
375
375
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
376
376
  */
377
- const reservedWords = new Set([
377
+ const reservedWords = /* @__PURE__ */ new Set([
378
378
  "abstract",
379
379
  "arguments",
380
380
  "boolean",
@@ -629,8 +629,8 @@ const fakerKeywordMapper = {
629
629
  return `faker.helpers.multiple(() => (${item}))`;
630
630
  },
631
631
  tuple: (items = []) => `[${items.join(", ")}]`,
632
- enum: (items = [], type = "any") => `faker.helpers.arrayElement<${type}>([${items.join(", ")}])`,
633
- union: (items = []) => `faker.helpers.arrayElement<any>([${items.join(", ")}])`,
632
+ enum: (items = [], type) => `faker.helpers.arrayElement${type ? `<${type}>` : ""}([${items.join(", ")}])`,
633
+ union: (items = []) => `faker.helpers.arrayElement([${items.join(", ")}])`,
634
634
  datetime: () => "faker.date.anytime().toISOString()",
635
635
  date: (representation = "string", parser = "faker") => {
636
636
  if (representation === "string") {
@@ -730,9 +730,9 @@ const printerFaker = ast.createPrinter((options) => {
730
730
  return fakerKeywordMapper.time(node.representation ?? "string", this.options.dateParser);
731
731
  },
732
732
  ref(node) {
733
- const refName = node.ref ? extractRefName(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
733
+ const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? extractRefName(node.ref) ?? node.name ?? node.schema?.name : node.name ?? node.schema?.name;
734
734
  if (!refName) throw new Error("Name not defined for ref node");
735
- if (this.options.schemaName && refName === this.options.schemaName) return "undefined as any";
735
+ if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
736
736
  const resolvedName = node.ref ? this.options.resolver.resolveName(refName) : refName;
737
737
  if (!this.options.nestedInObject) return `${resolvedName}(data)`;
738
738
  return `${resolvedName}()`;
@@ -849,7 +849,8 @@ const fakerGenerator = defineGenerator({
849
849
  regexGenerator,
850
850
  mapper,
851
851
  nodes: printer?.nodes,
852
- cyclicSchemas
852
+ cyclicSchemas,
853
+ nameMapping: adapter.options.nameMapping
853
854
  });
854
855
  const fakerText = printerInstance.print(node) ?? "undefined";
855
856
  const typeReference = resolveTypeReference({
@@ -986,7 +987,7 @@ const fakerGenerator = defineGenerator({
986
987
  description: node.requestBody?.description ?? schema.description
987
988
  }));
988
989
  const responseName = resolver.resolveResponseName(node);
989
- const localHelperNames = new Set([
990
+ const localHelperNames = /* @__PURE__ */ new Set([
990
991
  ...paramEntries.map((entry) => entry.name),
991
992
  ...responseUnits.map((unit) => unit.name),
992
993
  ...dataUnits.map((unit) => unit.name),
@@ -1039,7 +1040,8 @@ const fakerGenerator = defineGenerator({
1039
1040
  regexGenerator,
1040
1041
  mapper,
1041
1042
  nodes: printer?.nodes,
1042
- cyclicSchemas
1043
+ cyclicSchemas,
1044
+ nameMapping: adapter.options.nameMapping
1043
1045
  });
1044
1046
  const fakerText = printerInstance.print(schema) ?? "undefined";
1045
1047
  const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);