@kubb/plugin-faker 5.0.0-beta.104 → 5.0.0-beta.109

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
@@ -580,8 +580,9 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
580
580
  })();
581
581
  const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);
582
582
  if (!useGenericOverride) {
583
+ const dataParamName = /\bdata\b/.test(fakerTextWithOverride) ? "data" : "_data";
583
584
  const params = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
584
- name: /\bdata\b/.test(fakerTextWithOverride) ? "data" : "_data",
585
+ name: dataParamName,
585
586
  type: dataType,
586
587
  optional: true
587
588
  })] });
@@ -682,7 +683,7 @@ function operationFileEntry(node, name, extname = ".ts") {
682
683
  */
683
684
  function resolveDependencyOperationFile(options) {
684
685
  const { cache, node, resolver, root, output, group } = options;
685
- return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
686
+ return cache.ensureItem(`${resolver.pluginName}:operationFile`, () => resolver.file({
686
687
  ...operationFileEntry(node, node.operationId),
687
688
  root,
688
689
  output,
@@ -886,6 +887,18 @@ function mapSchemaItems(node, transform) {
886
887
  }
887
888
  //#endregion
888
889
  //#region src/printers/printerFaker.ts
890
+ /**
891
+ * Formats that put a whole number inside a `type: 'string'` schema, the way ProtoJSON encodes
892
+ * 64-bit integers, so the mock has to be digits rather than letters.
893
+ *
894
+ * @see https://protobuf.dev/programming-guides/json/#int64-strings
895
+ */
896
+ const integerFormats = /* @__PURE__ */ new Set([
897
+ "int32",
898
+ "int64",
899
+ "uint64"
900
+ ]);
901
+ const maxInt32 = 2147483647;
889
902
  const fakerKeywordMapper = {
890
903
  any: () => "undefined",
891
904
  unknown: () => "undefined",
@@ -903,6 +916,10 @@ const fakerKeywordMapper = {
903
916
  return "faker.number.int()";
904
917
  },
905
918
  bigint: () => "faker.number.bigInt()",
919
+ integerString: (format) => {
920
+ if (format === "int32") return `faker.number.int({ max: ${maxInt32} }).toString()`;
921
+ return "faker.number.bigInt().toString()";
922
+ },
906
923
  string: (min, max) => {
907
924
  if (max !== void 0 && min !== void 0) return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
908
925
  if (max !== void 0) return `faker.string.alpha({ length: ${max} })`;
@@ -1002,6 +1019,7 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
1002
1019
  null: () => fakerKeywordMapper.null(),
1003
1020
  string(node) {
1004
1021
  if (node.pattern) return fakerKeywordMapper.matches(node.pattern, this.options.regexGenerator);
1022
+ if (node.format && integerFormats.has(node.format)) return fakerKeywordMapper.integerString(node.format);
1005
1023
  return fakerKeywordMapper.string(node.min, node.max);
1006
1024
  },
1007
1025
  email: () => fakerKeywordMapper.email(),