@ramiyohay/schema-faker 0.4.0 → 0.5.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 +1 -0
- package/dist/generators/record.d.ts +2 -0
- package/dist/generators/record.js +16 -0
- package/dist/zod/parseZod.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateRecord = generateRecord;
|
|
4
|
+
const parseZod_1 = require("../zod/parseZod");
|
|
5
|
+
function generateRecord(schema, ctx) {
|
|
6
|
+
const result = {};
|
|
7
|
+
const keySchema = schema._def.keyType;
|
|
8
|
+
const valueSchema = schema._def.valueType;
|
|
9
|
+
const count = ctx.random.int(1, 5); // Generate between 1 and 5 entries
|
|
10
|
+
for (let i = 0; i < count; i++) {
|
|
11
|
+
const key = (0, parseZod_1.parseZodSchema)(keySchema, ctx);
|
|
12
|
+
const value = (0, parseZod_1.parseZodSchema)(valueSchema, ctx);
|
|
13
|
+
result[String(key)] = value;
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
package/dist/zod/parseZod.js
CHANGED
|
@@ -7,6 +7,7 @@ const boolean_1 = require("../generators/boolean");
|
|
|
7
7
|
const array_1 = require("../generators/array");
|
|
8
8
|
const enum_1 = require("../generators/enum");
|
|
9
9
|
const date_1 = require("../generators/date");
|
|
10
|
+
const record_1 = require("../generators/record");
|
|
10
11
|
function parseZodSchema(schema, ctx) {
|
|
11
12
|
switch (schema._def.typeName) {
|
|
12
13
|
case "ZodString": // String type
|
|
@@ -46,7 +47,10 @@ function parseZodSchema(schema, ctx) {
|
|
|
46
47
|
const index = ctx.random.int(0, options.length - 1);
|
|
47
48
|
return parseZodSchema(options[index], ctx);
|
|
48
49
|
}
|
|
49
|
-
case "
|
|
50
|
+
case "ZodRecord": // Record type
|
|
51
|
+
return (0, record_1.generateRecord)(schema, ctx);
|
|
52
|
+
case "ZodTuple": {
|
|
53
|
+
// Tuple type , create array with fixed length and types
|
|
50
54
|
const items = schema._def.items;
|
|
51
55
|
return items.map((itemSchema) => parseZodSchema(itemSchema, ctx));
|
|
52
56
|
}
|