@ramiyohay/schema-faker 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -79,4 +79,13 @@ const user = generate(UserSchema, {
79
79
  });
80
80
 
81
81
  console.log(user);
82
+ ```
83
+
84
+ ### Strict mode
85
+
86
+ By default, unsupported Zod types are ignored.
87
+ Enable strict mode to throw an error instead:
88
+
89
+ ```ts
90
+ generate(schema, { strict: true });
82
91
  ```
@@ -1,4 +1,5 @@
1
1
  import { Random } from "./random";
2
2
  export type Context = {
3
3
  random: Random;
4
+ strict: boolean;
4
5
  };
package/dist/generate.js CHANGED
@@ -7,6 +7,7 @@ const deepMerge_1 = require("./core/deepMerge");
7
7
  function generate(schema, options = {}) {
8
8
  const ctx = {
9
9
  random: new random_1.Random(options.seed),
10
+ strict: options.strict || false,
10
11
  };
11
12
  // Function to generate a single value
12
13
  const makeOne = () => {
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type GenerateOptions = {
2
2
  seed?: number;
3
3
  count?: number;
4
+ strict?: boolean;
4
5
  overrides?: Record<string, any>;
5
6
  };
@@ -57,6 +57,9 @@ function parseZodSchema(schema, ctx) {
57
57
  case "ZodDate": // Date type
58
58
  return (0, date_1.generateDate)(schema, ctx);
59
59
  default:
60
- return null;
60
+ if (ctx.strict) {
61
+ throw new Error(`Unsupported Zod type: ${schema._def.typeName}`);
62
+ }
63
+ return undefined;
61
64
  }
62
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramiyohay/schema-faker",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Generate fake data from Zod schemas in a deterministic way",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",