@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.js CHANGED
@@ -576,8 +576,9 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
576
576
  })();
577
577
  const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);
578
578
  if (!useGenericOverride) {
579
+ const dataParamName = /\bdata\b/.test(fakerTextWithOverride) ? "data" : "_data";
579
580
  const params = createFunctionParameters({ params: [createFunctionParameter({
580
- name: /\bdata\b/.test(fakerTextWithOverride) ? "data" : "_data",
581
+ name: dataParamName,
581
582
  type: dataType,
582
583
  optional: true
583
584
  })] });
@@ -678,7 +679,7 @@ function operationFileEntry(node, name, extname = ".ts") {
678
679
  */
679
680
  function resolveDependencyOperationFile(options) {
680
681
  const { cache, node, resolver, root, output, group } = options;
681
- return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
682
+ return cache.ensureItem(`${resolver.pluginName}:operationFile`, () => resolver.file({
682
683
  ...operationFileEntry(node, node.operationId),
683
684
  root,
684
685
  output,
@@ -882,6 +883,18 @@ function mapSchemaItems(node, transform) {
882
883
  }
883
884
  //#endregion
884
885
  //#region src/printers/printerFaker.ts
886
+ /**
887
+ * Formats that put a whole number inside a `type: 'string'` schema, the way ProtoJSON encodes
888
+ * 64-bit integers, so the mock has to be digits rather than letters.
889
+ *
890
+ * @see https://protobuf.dev/programming-guides/json/#int64-strings
891
+ */
892
+ const integerFormats = /* @__PURE__ */ new Set([
893
+ "int32",
894
+ "int64",
895
+ "uint64"
896
+ ]);
897
+ const maxInt32 = 2147483647;
885
898
  const fakerKeywordMapper = {
886
899
  any: () => "undefined",
887
900
  unknown: () => "undefined",
@@ -899,6 +912,10 @@ const fakerKeywordMapper = {
899
912
  return "faker.number.int()";
900
913
  },
901
914
  bigint: () => "faker.number.bigInt()",
915
+ integerString: (format) => {
916
+ if (format === "int32") return `faker.number.int({ max: ${maxInt32} }).toString()`;
917
+ return "faker.number.bigInt().toString()";
918
+ },
902
919
  string: (min, max) => {
903
920
  if (max !== void 0 && min !== void 0) return `faker.string.alpha({ length: { min: ${min}, max: ${max} } })`;
904
921
  if (max !== void 0) return `faker.string.alpha({ length: ${max} })`;
@@ -998,6 +1015,7 @@ const printerFaker = ast.createPrinter((options) => {
998
1015
  null: () => fakerKeywordMapper.null(),
999
1016
  string(node) {
1000
1017
  if (node.pattern) return fakerKeywordMapper.matches(node.pattern, this.options.regexGenerator);
1018
+ if (node.format && integerFormats.has(node.format)) return fakerKeywordMapper.integerString(node.format);
1001
1019
  return fakerKeywordMapper.string(node.min, node.max);
1002
1020
  },
1003
1021
  email: () => fakerKeywordMapper.email(),