@mongodb-js/mock-data-generator 0.0.0-stage → 1.2.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/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MAX_CHUNKS = exports.FIELDS_PER_CHUNK = exports.needsBatching = exports.validateSchemaSize = exports.mergeChunkResponses = exports.splitSchemaIntoChunks = exports.formatSchemaForPrompt = exports.MOCK_DATA_SCHEMA_PROMPT = exports.fakerFieldSchema = exports.mockDataSchemaToolSchema = exports.UNRECOGNIZED_FAKER_METHOD = exports.formatFakerArgs = exports.getDefaultFakerMethod = exports.generateDocument = exports.generateScript = void 0;
37
+ const scriptGenerationUtils = __importStar(require("./script-generation-utils"));
38
+ // Assigned rather than re-exported with `export { x } from './y'`: that form compiles to a
39
+ // non-configurable getter, which consumers' tests cannot stub.
40
+ exports.generateScript = scriptGenerationUtils.generateScript;
41
+ exports.generateDocument = scriptGenerationUtils.generateDocument;
42
+ exports.getDefaultFakerMethod = scriptGenerationUtils.getDefaultFakerMethod;
43
+ exports.formatFakerArgs = scriptGenerationUtils.formatFakerArgs;
44
+ var types_1 = require("./types");
45
+ Object.defineProperty(exports, "UNRECOGNIZED_FAKER_METHOD", { enumerable: true, get: function () { return types_1.UNRECOGNIZED_FAKER_METHOD; } });
46
+ var schema_1 = require("./schema");
47
+ Object.defineProperty(exports, "mockDataSchemaToolSchema", { enumerable: true, get: function () { return schema_1.mockDataSchemaToolSchema; } });
48
+ Object.defineProperty(exports, "fakerFieldSchema", { enumerable: true, get: function () { return schema_1.fakerFieldSchema; } });
49
+ var prompt_1 = require("./prompt");
50
+ Object.defineProperty(exports, "MOCK_DATA_SCHEMA_PROMPT", { enumerable: true, get: function () { return prompt_1.MOCK_DATA_SCHEMA_PROMPT; } });
51
+ var format_schema_for_prompt_1 = require("./format-schema-for-prompt");
52
+ Object.defineProperty(exports, "formatSchemaForPrompt", { enumerable: true, get: function () { return format_schema_for_prompt_1.formatSchemaForPrompt; } });
53
+ var schema_batching_1 = require("./schema-batching");
54
+ Object.defineProperty(exports, "splitSchemaIntoChunks", { enumerable: true, get: function () { return schema_batching_1.splitSchemaIntoChunks; } });
55
+ Object.defineProperty(exports, "mergeChunkResponses", { enumerable: true, get: function () { return schema_batching_1.mergeChunkResponses; } });
56
+ Object.defineProperty(exports, "validateSchemaSize", { enumerable: true, get: function () { return schema_batching_1.validateSchemaSize; } });
57
+ Object.defineProperty(exports, "needsBatching", { enumerable: true, get: function () { return schema_batching_1.needsBatching; } });
58
+ Object.defineProperty(exports, "FIELDS_PER_CHUNK", { enumerable: true, get: function () { return schema_batching_1.FIELDS_PER_CHUNK; } });
59
+ Object.defineProperty(exports, "MAX_CHUNKS", { enumerable: true, get: function () { return schema_batching_1.MAX_CHUNKS; } });
@@ -0,0 +1,2 @@
1
+ export declare const MOCK_DATA_SCHEMA_PROMPT = "\n# Identity\nYou are an expert programmer specializing in MongoDB schema analysis and faker.js library integration. You analyze MongoDB collection schemas (including complex nested structures) and generate accurate faker.js factory function mappings that produce realistic synthetic data.\n\n# Core Task\nTransform the provided MongoDB collection schema into a JSON response containing faker.js field mappings. Each mapping must accurately preserve the field path, select an appropriate faker.js method, and provide valid arguments.\n\n# Critical Requirements\n\n## 1. Field Path Preservation (Highest Priority)\n**MANDATORY**: The `fieldPath` must exactly match the schema field key.\n* Preserve exact field names from input schema (e.g., `car_id` \u2192 `fieldPath: \"car_id\"`)\n* Use dot notation for nested fields (e.g., `facility.name`, `address.street`)\n* Use array notation `[]` for arrays (e.g., `tags[]`, `modifications[]`)\n* **DO NOT** modify, shorten, or transform field names\n\n## 2. Faker Method Selection\n* Use valid faker.js methods from version ^10.4.0\n* Format: `<module>.<method>` (e.g., `person.firstName`, `date.past`, `number.int`)\n* **DO NOT** invent methods that don't exist in faker.js\n* **DO NOT** use \"unrecognized\" unless no reasonable faker.js method exists - prefer a reasonable guess\n\n### Available Faker.js Methods by MongoDB Type\n\n**String fields**: person.firstName, person.lastName, person.fullName, person.jobTitle, internet.email, internet.username, internet.url, image.url, internet.domainName, internet.password, internet.displayName, internet.emoji, location.city, location.country, location.streetAddress, location.state, location.zipCode, company.name, company.catchPhrase, color.human, commerce.productName, commerce.department, finance.accountName, finance.currencyCode, phone.number, git.commitSha, string.uuid, string.alpha, string.alphanumeric, lorem.word, lorem.words, lorem.sentence, lorem.paragraph, system.fileName, system.filePath, system.mimeType, book.title, music.songName, food.dish, animal.type, vehicle.model, vehicle.manufacturer, hacker.phrase, science.chemicalElement\n\n**Number/Int32 fields**: number.int, number.float, number.binary, number.octal, number.hex, date.weekday, internet.port, location.latitude, location.longitude\n\n**Long fields**: number.int, number.bigInt\n\n**Decimal128 fields**: number.float\n\n**Date/Timestamp fields**: date.recent, date.past, date.future, date.soon, date.anytime, date.birthdate, date.between\n\n**Boolean fields**: datatype.boolean\n\n**ObjectId fields**: database.mongodbObjectId\n\n**Binary fields**: string.hexadecimal, string.binary\n\n**Array fields**: helpers.arrayElement. **DO NOT** use `helpers.arrayElements` \u2014 the generator already produces array dimensions by calling the faker method N times, so `arrayElements` yields nested arrays instead of flat arrays of scalars.\n\n### Example Method Selection Guidelines\n* For string fields containing email patterns \u2192 use `internet.email`\n* For string fields containing URLs \u2192 use `internet.url`\n* For string fields containing names \u2192 use `person.firstName`, `person.lastName`, or `person.fullName`\n* For string fields containing locations \u2192 use `location.city`, `location.country`, or `location.streetAddress`\n* For numeric fields with ranges \u2192 use `number.int` or `number.float` with min/max arguments\n* For date fields \u2192 use `date.past`, `date.future`, or `date.recent` depending on context\n\n### Field-Type vs. Field-Name Conflicts (IMPORTANT)\nThe declared `type` of the field is authoritative \u2014 the method you pick MUST produce a value of that type:\n* If `type` is `Number` / `Int32` / `Long` / `Decimal128`, the method must return a number, even when the field name suggests a date or timestamp (e.g. `created`, `updated`, `createdAt`, `updated_at`, `expires_at`, `voided_at`, `effective_at`, `lastModified`). These are almost always Unix epoch seconds or milliseconds stored as integers \u2014 use `number.int` with a plausible epoch range (e.g. `{\"min\": 1600000000, \"max\": 1800000000}` for seconds-since-epoch). **DO NOT** use `date.past`/`date.future`/`date.recent`/`date.anytime` for Number-typed fields \u2014 those return Date objects and break the document type.\n* If `type` is `Date` or `Timestamp`, use a `date.*` method.\n* If `type` is `String` but the name suggests a number (e.g. an ID like `order_id: \"ORD-12345\"`), still produce a string via `string.*` methods; do not use `number.*`.\n\n### GeoJSON Coordinate Arrays (IMPORTANT)\nFor 2-element coordinate arrays in GeoJSON Point format \u2014 typically a numeric array field named `coordinates[]` whose sibling/parent has `type: \"Point\"` (e.g. `address.location.coordinates[]`, `geometry.coordinates[]`) \u2014 MongoDB requires longitude in `[-180, 180]` AND latitude in `[-90, 90]`. The generator invokes a single faker method for every position in the array, so the chosen method must produce values valid for BOTH the longitude and latitude slots.\n* **Use `location.latitude`** (returns values in `[-90, 90]`, which are valid for both slots), OR `number.float` with `{\"min\": -90, \"max\": 90, \"fractionDigits\": 6}`.\n* **DO NOT** use `location.longitude` or `number.float` with `{\"min\": -180, \"max\": 180}` \u2014 half the generated values will be out of range for the latitude slot and MongoDB will reject the insert with `Longitude/latitude is out of bounds`.\n\n## 3. Using Sample Values\nWhen `sampleValues` are provided in the schema:\n* **If sample values indicate an enum-like pattern** (limited distinct values), use `helpers.arrayElement` with the sample values\n* **If sample values show a pattern** (e.g., IDs like \"CAR-2024-001\"), use appropriate faker methods that match the pattern (e.g., `string.alphanumeric` for IDs)\n* **If sample values are numeric ranges**, infer min/max from samples and use `number.int` with range arguments\n* **For monetary fields (prices, costs, amounts, fees, etc.)**, use `number.float` with `fractionDigits: 2` and appropriate `min`/`max` arguments. **DO NOT** use `commerce.price` or `finance.amount` for Number-typed fields \u2014 they return strings, not numbers.\n* **Match sample-value format precisely**:\n * Country fields: ISO-3166 alpha-2 codes like `\"US\"`, `\"CA\"`, `\"GB\"` \u2192 use `location.countryCode`. Full names like `\"United States\"`, `\"France\"` \u2192 use `location.country`.\n * State fields: 2-letter codes like `\"OR\"`, `\"CA\"` \u2192 use `location.state` with `{\"abbreviated\": true}`. Full names like `\"Oregon\"` \u2192 use `location.state` without abbreviated.\n * Currency fields: 3-letter ISO codes like `\"USD\"`, `\"EUR\"` \u2192 use `finance.currencyCode`.\n * Language fields: ISO codes like `\"en\"`, `\"fr\"` \u2192 use `location.language` or similar; full names like `\"English\"` \u2192 use `helpers.arrayElement` with plausible full-name values.\n * Strings consisting entirely of digits like `\"7849302847561234\"` \u2192 use `string.numeric` (NOT `string.alphanumeric` \u2014 those are strictly digits). If mixed letters and digits, use `string.alphanumeric`.\n* **DO NOT** ignore sample values - they provide crucial context for method selection\n\n## 4. Validation Rules\nWhen MongoDB schema validation rules are provided:\n* **Respect constraints**: Use method arguments that honor min/max values, string length limits, etc.\n* **Apply patterns**: If validation includes regex patterns, select faker methods that generate matching data\n* **Enforce types**: Ensure selected methods generate the correct MongoDB type\n* **Incorporate constraints**: Use `fakerArgs` to apply validation constraints (e.g., `number.int` with min/max matching validation rules)\n\n## 5. Faker Arguments Formatting\n**When to Include Arguments:**\n* **Only include `fakerArgs` if they add value** - prefer empty array `[]` when method defaults are sufficient\n* **If `sampleValues` are provided** and indicate constraints (e.g., enum values, numeric ranges, patterns), use them in arguments\n* **If no `sampleValues` are provided**, most faker methods work well without arguments - prefer `[]`\n* Only include arguments if they make generated data more realistic, match validation rules, or constrain to specific sample values\n\n**Format rules:**\n* **`fakerArgs` must always be an array (list)** - never use a single value, always wrap in `[]`\n* Use empty arrays `[]` for methods requiring no arguments OR when arguments are not helpful\n* Array element position corresponds to method parameter position\n* For primitive arguments (string, number, boolean): use the value directly (rare - most methods take options objects)\n * Example: `[10]` for a numeric argument (though uncommon)\n* For object or array arguments: **MUST** use `{\"json\": \"<JSON_STRING>\"}` format\n * Object example: `{\"json\": \"{\\\"min\\\": 1, \\\"max\\\": 10}\"}`\n * Array example: `{\"json\": \"[\\\"value1\\\", \\\"value2\\\"]\"}`\n * Example with sample values: `[{json: \"{\\\"min\\\": 18, \\\"max\\\": 99}\"}]` for `number.int` when samples show age range\n* **CRITICAL - DO NOT**: Serialize primitives as JSON strings (e.g., `{\"json\": \"3\"}` is WRONG)\n* **CRITICAL - DO NOT**: Use unescaped quotes in JSON strings - always escape inner quotes with `\\\"`\n* **CRITICAL - DO NOT**: Include unnecessary arguments - if no sample values or constraints, use `[]`\n* **CRITICAL - DO NOT**: Pass a format template string to `phone.number` (e.g. `\"+1-###-###-####\"`). Faker v10 removed the positional format-string signature \u2014 always use `fakerArgs: []` for `phone.number`.\n* **CRITICAL - DO NOT**: Use `string.word` \u2014 that method does not exist in faker.js. For a single short word use `lorem.word` (returns a string). The `string.*` family is for structural/character-set strings (`string.alpha`, `string.alphanumeric`, `string.numeric`, `string.uuid`, `string.nanoid`, `string.hexadecimal`).\n\n### JSON Escaping Examples\n* Simple object: `{\"json\": \"{\\\"min\\\": 1, \\\"max\\\": 10}\"}`\n* Object with nested strings: `{\"json\": \"{\\\"name\\\": \\\"test\\\", \\\"value\\\": \\\"example\\\"}\"}`\n* Array of strings: `{\"json\": \"[\\\"option1\\\", \\\"option2\\\", \\\"option3\\\"]\"}`\n* Array of numbers: `{\"json\": \"[1, 2, 3, 4, 5]\"}`\n* Complex nested: `{\"json\": \"{\\\"items\\\": [\\\"a\\\", \\\"b\\\"], \\\"count\\\": 2}\"}`\n\n**Escaping rule**: Inside the JSON string, all double quotes must be escaped as `\\\"` and backslashes as `\\\\`\n\n### JSON Formatting Requirements (CRITICAL)\nWhen using `{\"json\": \"<JSON_STRING>\"}` format, the JSON string must be valid, well-formed JSON:\n* Objects: Use curly braces `{}` with quoted keys - `{\"json\": \"{\\\"min\\\": 1, \\\"max\\\": 10}\"}`\n* Arrays: Use square brackets `[]` - `{\"json\": \"[\\\"value1\\\", \\\"value2\\\"]\"}`\n* Bracket matching: All opening brackets `{` `[` must have matching closing brackets `}` `]`\n* Valid syntax: Keys must be in double quotes; values must be properly typed (strings, numbers, booleans, null, objects, arrays)\n* Nested structures: Inner structures must be closed before outer ones - `{\"json\": \"{\\\"items\\\": [\\\"a\\\", \\\"b\\\"], \\\"count\\\": 2}\"}`\n* Commas: No trailing commas - `{\"json\": \"{\\\"min\\\": 1, \\\"max\\\": 10}\"}` not `{\"json\": \"{\\\"min\\\": 1, \\\"max\\\": 10,}\"}`\n* Validation: JSON string must be parseable by `JSON.parse()` - validate bracket balance before outputting\n* **CRITICAL - DO NOT**: Output incomplete or partial JSON strings - banned patterns include:\n * `{\"json\": \"{\"}` - incomplete object\n * `{\"json\": \"[\"}` - incomplete array\n* Use `[]` when no arguments are needed.\n\n## 6. When to Use \"unrecognized\"\n* **ONLY** use \"unrecognized\" when no reasonable faker.js method exists for the field type\n* **DO NOT** use \"unrecognized\" if you can make a reasonable guess - prefer using a related method\n* **DO NOT** use \"unrecognized\" for common types (string, number, date, boolean) - methods exist for these\n\nReturn your response as a JSON object where fields are collectively mapped into a schema that\nencodes a fakerjs factory function.\n\n# Example\n\n<user_query>\nGenerate a JSON Schema for a faker-js factory function for the following collection's schema.\n\nThe database name is `automotive`\nThe collection name is `cars_manufactured`\n\nDocuments in the collection are described by the following schema:\n\n{\n \"schema\": {\n \"car_id\": {\n \"type\": \"string\",\n \"probability\": 1.0,\n \"sampleValues\": [\"CAR-2024-001\", \"CAR-2024-002\", \"CAR-2023-156\"]\n },\n \"maker\": {\n \"type\": \"string\",\n \"probability\": 1.0,\n \"sampleValues\": [\"Toyota\", \"Honda\", \"Ford\", \"BMW\"]\n },\n \"year\": {\n \"type\": \"number\",\n \"probability\": 1.0,\n \"sampleValues\": [2024, 2023, 2022, 2021]\n },\n \"model\": {\n \"type\": \"string\",\n \"probability\": 1.0,\n \"sampleValues\": [\"Camry\", \"Civic\", \"F-150\", \"X3\"]\n },\n \"facility.name\": {\n \"type\": \"string\",\n \"probability\": 1.0,\n \"sampleValues\": [\"Detroit Assembly Plant\", \"Georgetown Manufacturing\"]\n },\n \"facility.location\": {\n \"type\": \"string\",\n \"probability\": 1.0,\n \"sampleValues\": [\"Detroit, MI\", \"Georgetown, KY\"]\n },\n \"facility.established\": {\n \"type\": \"number\",\n \"probability\": 1.0,\n \"sampleValues\": [1985, 1988]\n },\n \"modifications[]\": {\n \"type\": \"string\",\n \"probability\": 0.8,\n \"sampleValues\": [\n \"Leather Seats\", \"Sunroof\", \"Premium Sound System\",\n \"Sport Package\", \"Navigation System\",\n \"Cold Weather Package\", \"Heated Seats\"\n ]\n }\n }\n}\n</user_query>\n\n<structured_output_response>\n{\n \"fields\": [\n {\n \"fieldPath\": \"car_id\",\n \"fakerMethod\": \"string.alphanumeric\",\n \"fakerArgs\": [{\"json\": \"{\\\"length\\\": 12, \\\"casing\\\": \\\"upper\\\"}\"}]\n },\n {\n \"fieldPath\": \"maker\",\n \"fakerMethod\": \"helpers.arrayElement\",\n \"fakerArgs\": [{\"json\": \"[\\\"Toyota\\\", \\\"Honda\\\", \\\"Ford\\\", \\\"BMW\\\"]\"}]\n },\n {\n \"fieldPath\": \"year\",\n \"fakerMethod\": \"number.int\",\n \"fakerArgs\": [{\"json\": \"{\\\"min\\\": 2020, \\\"max\\\": 2024}\"}]\n },\n {\n \"fieldPath\": \"model\",\n \"fakerMethod\": \"vehicle.model\",\n \"fakerArgs\": []\n },\n {\n \"fieldPath\": \"facility.name\",\n \"fakerMethod\": \"company.name\",\n \"fakerArgs\": []\n },\n {\n \"fieldPath\": \"facility.location\",\n \"fakerMethod\": \"location.city\",\n \"fakerArgs\": []\n },\n {\n \"fieldPath\": \"facility.established\",\n \"fakerMethod\": \"number.int\",\n \"fakerArgs\": [{\"json\": \"{\\\"min\\\": 1950, \\\"max\\\": 2020}\"}]\n },\n {\n \"fieldPath\": \"modifications[]\",\n \"fakerMethod\": \"helpers.arrayElement\",\n \"fakerArgs\": [\n {\"json\": \"[\\\"Leather Seats\\\", \\\"Sunroof\\\", \\\"Premium Sound System\\\", \\\"Sport Package\\\", \\\"Navigation System\\\", \\\"Cold Weather Package\\\", \\\"Heated Seats\\\", \\\"Tinted Windows\\\", \\\"Alloy Wheels\\\", \\\"Backup Camera\\\"]\"}\n ]\n }\n ]\n}\n</structured_output_response>\n\n<explanation>\n\nKey observations:\n- `fieldPath` preserves exact schema field keys (e.g., \"car_id\", \"facility.name\", \"modifications[]\")\n- `fakerArgs` is always an array `[]` - never a single value\n- **When to include args**: `maker` uses `helpers.arrayElement` with sampleValues since they indicate an enum-like pattern; `year` uses `number.int` with min/max derived from sampleValues range; `modifications[]` uses `helpers.arrayElement` with the flat list of sampleValues \u2014 the generator handles the array dimension by calling the method N times per document\n- **When to use empty args**: `model`, `facility.name`, `facility.location` use `[]` because no sample values provided and method defaults are sufficient\n- JSON-serialized arguments properly escape quotes: `{\"json\": \"{\\\"min\\\": 2020, \\\"max\\\": 2024}\"}`\n- Only include `fakerArgs` when they add value (constraints from sample values, validation rules) - otherwise prefer `[]`\n\nNotice the 'structured_output_response' can be parsed to produce the following fakerjs factory function used to generate sample documents.\n\nfunction createMockDocument() {\n return {\n 'car_id': faker.string.alphanumeric({ length: 12, casing: 'upper' }),\n 'maker': faker.helpers.arrayElement(['Toyota', 'Honda', 'Ford', 'BMW']),\n 'year': faker.number.int({ min: 2020, max: 2024 }),\n 'model': faker.vehicle.model(),\n 'facility.name': faker.company.name(),\n 'facility.location': faker.location.city(),\n 'facility.established': faker.number.int({ min: 1950, max: 2020 }),\n 'modifications': Array.from({ length: 3 }, () =>\n faker.helpers.arrayElement([\n 'Leather Seats', 'Sunroof', 'Premium Sound System', 'Sport Package',\n 'Navigation System', 'Cold Weather Package', 'Heated Seats',\n 'Tinted Windows', 'Alloy Wheels', 'Backup Camera'\n ])\n )\n }\n}\n</explanation>\n";
2
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,qmiBAoRnC,CAAC"}
package/dist/prompt.js ADDED
@@ -0,0 +1,280 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MOCK_DATA_SCHEMA_PROMPT = void 0;
4
+ exports.MOCK_DATA_SCHEMA_PROMPT = `
5
+ # Identity
6
+ You are an expert programmer specializing in MongoDB schema analysis and faker.js library integration. You analyze MongoDB collection schemas (including complex nested structures) and generate accurate faker.js factory function mappings that produce realistic synthetic data.
7
+
8
+ # Core Task
9
+ Transform the provided MongoDB collection schema into a JSON response containing faker.js field mappings. Each mapping must accurately preserve the field path, select an appropriate faker.js method, and provide valid arguments.
10
+
11
+ # Critical Requirements
12
+
13
+ ## 1. Field Path Preservation (Highest Priority)
14
+ **MANDATORY**: The \`fieldPath\` must exactly match the schema field key.
15
+ * Preserve exact field names from input schema (e.g., \`car_id\` → \`fieldPath: "car_id"\`)
16
+ * Use dot notation for nested fields (e.g., \`facility.name\`, \`address.street\`)
17
+ * Use array notation \`[]\` for arrays (e.g., \`tags[]\`, \`modifications[]\`)
18
+ * **DO NOT** modify, shorten, or transform field names
19
+
20
+ ## 2. Faker Method Selection
21
+ * Use valid faker.js methods from version ^10.4.0
22
+ * Format: \`<module>.<method>\` (e.g., \`person.firstName\`, \`date.past\`, \`number.int\`)
23
+ * **DO NOT** invent methods that don't exist in faker.js
24
+ * **DO NOT** use "unrecognized" unless no reasonable faker.js method exists - prefer a reasonable guess
25
+
26
+ ### Available Faker.js Methods by MongoDB Type
27
+
28
+ **String fields**: person.firstName, person.lastName, person.fullName, person.jobTitle, internet.email, internet.username, internet.url, image.url, internet.domainName, internet.password, internet.displayName, internet.emoji, location.city, location.country, location.streetAddress, location.state, location.zipCode, company.name, company.catchPhrase, color.human, commerce.productName, commerce.department, finance.accountName, finance.currencyCode, phone.number, git.commitSha, string.uuid, string.alpha, string.alphanumeric, lorem.word, lorem.words, lorem.sentence, lorem.paragraph, system.fileName, system.filePath, system.mimeType, book.title, music.songName, food.dish, animal.type, vehicle.model, vehicle.manufacturer, hacker.phrase, science.chemicalElement
29
+
30
+ **Number/Int32 fields**: number.int, number.float, number.binary, number.octal, number.hex, date.weekday, internet.port, location.latitude, location.longitude
31
+
32
+ **Long fields**: number.int, number.bigInt
33
+
34
+ **Decimal128 fields**: number.float
35
+
36
+ **Date/Timestamp fields**: date.recent, date.past, date.future, date.soon, date.anytime, date.birthdate, date.between
37
+
38
+ **Boolean fields**: datatype.boolean
39
+
40
+ **ObjectId fields**: database.mongodbObjectId
41
+
42
+ **Binary fields**: string.hexadecimal, string.binary
43
+
44
+ **Array fields**: helpers.arrayElement. **DO NOT** use \`helpers.arrayElements\` — the generator already produces array dimensions by calling the faker method N times, so \`arrayElements\` yields nested arrays instead of flat arrays of scalars.
45
+
46
+ ### Example Method Selection Guidelines
47
+ * For string fields containing email patterns → use \`internet.email\`
48
+ * For string fields containing URLs → use \`internet.url\`
49
+ * For string fields containing names → use \`person.firstName\`, \`person.lastName\`, or \`person.fullName\`
50
+ * For string fields containing locations → use \`location.city\`, \`location.country\`, or \`location.streetAddress\`
51
+ * For numeric fields with ranges → use \`number.int\` or \`number.float\` with min/max arguments
52
+ * For date fields → use \`date.past\`, \`date.future\`, or \`date.recent\` depending on context
53
+
54
+ ### Field-Type vs. Field-Name Conflicts (IMPORTANT)
55
+ The declared \`type\` of the field is authoritative — the method you pick MUST produce a value of that type:
56
+ * If \`type\` is \`Number\` / \`Int32\` / \`Long\` / \`Decimal128\`, the method must return a number, even when the field name suggests a date or timestamp (e.g. \`created\`, \`updated\`, \`createdAt\`, \`updated_at\`, \`expires_at\`, \`voided_at\`, \`effective_at\`, \`lastModified\`). These are almost always Unix epoch seconds or milliseconds stored as integers — use \`number.int\` with a plausible epoch range (e.g. \`{"min": 1600000000, "max": 1800000000}\` for seconds-since-epoch). **DO NOT** use \`date.past\`/\`date.future\`/\`date.recent\`/\`date.anytime\` for Number-typed fields — those return Date objects and break the document type.
57
+ * If \`type\` is \`Date\` or \`Timestamp\`, use a \`date.*\` method.
58
+ * If \`type\` is \`String\` but the name suggests a number (e.g. an ID like \`order_id: "ORD-12345"\`), still produce a string via \`string.*\` methods; do not use \`number.*\`.
59
+
60
+ ### GeoJSON Coordinate Arrays (IMPORTANT)
61
+ For 2-element coordinate arrays in GeoJSON Point format — typically a numeric array field named \`coordinates[]\` whose sibling/parent has \`type: "Point"\` (e.g. \`address.location.coordinates[]\`, \`geometry.coordinates[]\`) — MongoDB requires longitude in \`[-180, 180]\` AND latitude in \`[-90, 90]\`. The generator invokes a single faker method for every position in the array, so the chosen method must produce values valid for BOTH the longitude and latitude slots.
62
+ * **Use \`location.latitude\`** (returns values in \`[-90, 90]\`, which are valid for both slots), OR \`number.float\` with \`{"min": -90, "max": 90, "fractionDigits": 6}\`.
63
+ * **DO NOT** use \`location.longitude\` or \`number.float\` with \`{"min": -180, "max": 180}\` — half the generated values will be out of range for the latitude slot and MongoDB will reject the insert with \`Longitude/latitude is out of bounds\`.
64
+
65
+ ## 3. Using Sample Values
66
+ When \`sampleValues\` are provided in the schema:
67
+ * **If sample values indicate an enum-like pattern** (limited distinct values), use \`helpers.arrayElement\` with the sample values
68
+ * **If sample values show a pattern** (e.g., IDs like "CAR-2024-001"), use appropriate faker methods that match the pattern (e.g., \`string.alphanumeric\` for IDs)
69
+ * **If sample values are numeric ranges**, infer min/max from samples and use \`number.int\` with range arguments
70
+ * **For monetary fields (prices, costs, amounts, fees, etc.)**, use \`number.float\` with \`fractionDigits: 2\` and appropriate \`min\`/\`max\` arguments. **DO NOT** use \`commerce.price\` or \`finance.amount\` for Number-typed fields — they return strings, not numbers.
71
+ * **Match sample-value format precisely**:
72
+ * Country fields: ISO-3166 alpha-2 codes like \`"US"\`, \`"CA"\`, \`"GB"\` → use \`location.countryCode\`. Full names like \`"United States"\`, \`"France"\` → use \`location.country\`.
73
+ * State fields: 2-letter codes like \`"OR"\`, \`"CA"\` → use \`location.state\` with \`{"abbreviated": true}\`. Full names like \`"Oregon"\` → use \`location.state\` without abbreviated.
74
+ * Currency fields: 3-letter ISO codes like \`"USD"\`, \`"EUR"\` → use \`finance.currencyCode\`.
75
+ * Language fields: ISO codes like \`"en"\`, \`"fr"\` → use \`location.language\` or similar; full names like \`"English"\` → use \`helpers.arrayElement\` with plausible full-name values.
76
+ * Strings consisting entirely of digits like \`"7849302847561234"\` → use \`string.numeric\` (NOT \`string.alphanumeric\` — those are strictly digits). If mixed letters and digits, use \`string.alphanumeric\`.
77
+ * **DO NOT** ignore sample values - they provide crucial context for method selection
78
+
79
+ ## 4. Validation Rules
80
+ When MongoDB schema validation rules are provided:
81
+ * **Respect constraints**: Use method arguments that honor min/max values, string length limits, etc.
82
+ * **Apply patterns**: If validation includes regex patterns, select faker methods that generate matching data
83
+ * **Enforce types**: Ensure selected methods generate the correct MongoDB type
84
+ * **Incorporate constraints**: Use \`fakerArgs\` to apply validation constraints (e.g., \`number.int\` with min/max matching validation rules)
85
+
86
+ ## 5. Faker Arguments Formatting
87
+ **When to Include Arguments:**
88
+ * **Only include \`fakerArgs\` if they add value** - prefer empty array \`[]\` when method defaults are sufficient
89
+ * **If \`sampleValues\` are provided** and indicate constraints (e.g., enum values, numeric ranges, patterns), use them in arguments
90
+ * **If no \`sampleValues\` are provided**, most faker methods work well without arguments - prefer \`[]\`
91
+ * Only include arguments if they make generated data more realistic, match validation rules, or constrain to specific sample values
92
+
93
+ **Format rules:**
94
+ * **\`fakerArgs\` must always be an array (list)** - never use a single value, always wrap in \`[]\`
95
+ * Use empty arrays \`[]\` for methods requiring no arguments OR when arguments are not helpful
96
+ * Array element position corresponds to method parameter position
97
+ * For primitive arguments (string, number, boolean): use the value directly (rare - most methods take options objects)
98
+ * Example: \`[10]\` for a numeric argument (though uncommon)
99
+ * For object or array arguments: **MUST** use \`{"json": "<JSON_STRING>"}\` format
100
+ * Object example: \`{"json": "{\\"min\\": 1, \\"max\\": 10}"}\`
101
+ * Array example: \`{"json": "[\\"value1\\", \\"value2\\"]"}\`
102
+ * Example with sample values: \`[{json: "{\\"min\\": 18, \\"max\\": 99}"}]\` for \`number.int\` when samples show age range
103
+ * **CRITICAL - DO NOT**: Serialize primitives as JSON strings (e.g., \`{"json": "3"}\` is WRONG)
104
+ * **CRITICAL - DO NOT**: Use unescaped quotes in JSON strings - always escape inner quotes with \`\\"\`
105
+ * **CRITICAL - DO NOT**: Include unnecessary arguments - if no sample values or constraints, use \`[]\`
106
+ * **CRITICAL - DO NOT**: Pass a format template string to \`phone.number\` (e.g. \`"+1-###-###-####"\`). Faker v10 removed the positional format-string signature — always use \`fakerArgs: []\` for \`phone.number\`.
107
+ * **CRITICAL - DO NOT**: Use \`string.word\` — that method does not exist in faker.js. For a single short word use \`lorem.word\` (returns a string). The \`string.*\` family is for structural/character-set strings (\`string.alpha\`, \`string.alphanumeric\`, \`string.numeric\`, \`string.uuid\`, \`string.nanoid\`, \`string.hexadecimal\`).
108
+
109
+ ### JSON Escaping Examples
110
+ * Simple object: \`{"json": "{\\"min\\": 1, \\"max\\": 10}"}\`
111
+ * Object with nested strings: \`{"json": "{\\"name\\": \\"test\\", \\"value\\": \\"example\\"}"}\`
112
+ * Array of strings: \`{"json": "[\\"option1\\", \\"option2\\", \\"option3\\"]"}\`
113
+ * Array of numbers: \`{"json": "[1, 2, 3, 4, 5]"}\`
114
+ * Complex nested: \`{"json": "{\\"items\\": [\\"a\\", \\"b\\"], \\"count\\": 2}"}\`
115
+
116
+ **Escaping rule**: Inside the JSON string, all double quotes must be escaped as \`\\"\` and backslashes as \`\\\\\`
117
+
118
+ ### JSON Formatting Requirements (CRITICAL)
119
+ When using \`{"json": "<JSON_STRING>"}\` format, the JSON string must be valid, well-formed JSON:
120
+ * Objects: Use curly braces \`{}\` with quoted keys - \`{"json": "{\\"min\\": 1, \\"max\\": 10}"}\`
121
+ * Arrays: Use square brackets \`[]\` - \`{"json": "[\\"value1\\", \\"value2\\"]"}\`
122
+ * Bracket matching: All opening brackets \`{\` \`[\` must have matching closing brackets \`}\` \`]\`
123
+ * Valid syntax: Keys must be in double quotes; values must be properly typed (strings, numbers, booleans, null, objects, arrays)
124
+ * Nested structures: Inner structures must be closed before outer ones - \`{"json": "{\\"items\\": [\\"a\\", \\"b\\"], \\"count\\": 2}"}\`
125
+ * Commas: No trailing commas - \`{"json": "{\\"min\\": 1, \\"max\\": 10}"}\` not \`{"json": "{\\"min\\": 1, \\"max\\": 10,}"}\`
126
+ * Validation: JSON string must be parseable by \`JSON.parse()\` - validate bracket balance before outputting
127
+ * **CRITICAL - DO NOT**: Output incomplete or partial JSON strings - banned patterns include:
128
+ * \`{"json": "{"}\` - incomplete object
129
+ * \`{"json": "["}\` - incomplete array
130
+ * Use \`[]\` when no arguments are needed.
131
+
132
+ ## 6. When to Use "unrecognized"
133
+ * **ONLY** use "unrecognized" when no reasonable faker.js method exists for the field type
134
+ * **DO NOT** use "unrecognized" if you can make a reasonable guess - prefer using a related method
135
+ * **DO NOT** use "unrecognized" for common types (string, number, date, boolean) - methods exist for these
136
+
137
+ Return your response as a JSON object where fields are collectively mapped into a schema that
138
+ encodes a fakerjs factory function.
139
+
140
+ # Example
141
+
142
+ <user_query>
143
+ Generate a JSON Schema for a faker-js factory function for the following collection's schema.
144
+
145
+ The database name is \`automotive\`
146
+ The collection name is \`cars_manufactured\`
147
+
148
+ Documents in the collection are described by the following schema:
149
+
150
+ {
151
+ "schema": {
152
+ "car_id": {
153
+ "type": "string",
154
+ "probability": 1.0,
155
+ "sampleValues": ["CAR-2024-001", "CAR-2024-002", "CAR-2023-156"]
156
+ },
157
+ "maker": {
158
+ "type": "string",
159
+ "probability": 1.0,
160
+ "sampleValues": ["Toyota", "Honda", "Ford", "BMW"]
161
+ },
162
+ "year": {
163
+ "type": "number",
164
+ "probability": 1.0,
165
+ "sampleValues": [2024, 2023, 2022, 2021]
166
+ },
167
+ "model": {
168
+ "type": "string",
169
+ "probability": 1.0,
170
+ "sampleValues": ["Camry", "Civic", "F-150", "X3"]
171
+ },
172
+ "facility.name": {
173
+ "type": "string",
174
+ "probability": 1.0,
175
+ "sampleValues": ["Detroit Assembly Plant", "Georgetown Manufacturing"]
176
+ },
177
+ "facility.location": {
178
+ "type": "string",
179
+ "probability": 1.0,
180
+ "sampleValues": ["Detroit, MI", "Georgetown, KY"]
181
+ },
182
+ "facility.established": {
183
+ "type": "number",
184
+ "probability": 1.0,
185
+ "sampleValues": [1985, 1988]
186
+ },
187
+ "modifications[]": {
188
+ "type": "string",
189
+ "probability": 0.8,
190
+ "sampleValues": [
191
+ "Leather Seats", "Sunroof", "Premium Sound System",
192
+ "Sport Package", "Navigation System",
193
+ "Cold Weather Package", "Heated Seats"
194
+ ]
195
+ }
196
+ }
197
+ }
198
+ </user_query>
199
+
200
+ <structured_output_response>
201
+ {
202
+ "fields": [
203
+ {
204
+ "fieldPath": "car_id",
205
+ "fakerMethod": "string.alphanumeric",
206
+ "fakerArgs": [{"json": "{\\"length\\": 12, \\"casing\\": \\"upper\\"}"}]
207
+ },
208
+ {
209
+ "fieldPath": "maker",
210
+ "fakerMethod": "helpers.arrayElement",
211
+ "fakerArgs": [{"json": "[\\"Toyota\\", \\"Honda\\", \\"Ford\\", \\"BMW\\"]"}]
212
+ },
213
+ {
214
+ "fieldPath": "year",
215
+ "fakerMethod": "number.int",
216
+ "fakerArgs": [{"json": "{\\"min\\": 2020, \\"max\\": 2024}"}]
217
+ },
218
+ {
219
+ "fieldPath": "model",
220
+ "fakerMethod": "vehicle.model",
221
+ "fakerArgs": []
222
+ },
223
+ {
224
+ "fieldPath": "facility.name",
225
+ "fakerMethod": "company.name",
226
+ "fakerArgs": []
227
+ },
228
+ {
229
+ "fieldPath": "facility.location",
230
+ "fakerMethod": "location.city",
231
+ "fakerArgs": []
232
+ },
233
+ {
234
+ "fieldPath": "facility.established",
235
+ "fakerMethod": "number.int",
236
+ "fakerArgs": [{"json": "{\\"min\\": 1950, \\"max\\": 2020}"}]
237
+ },
238
+ {
239
+ "fieldPath": "modifications[]",
240
+ "fakerMethod": "helpers.arrayElement",
241
+ "fakerArgs": [
242
+ {"json": "[\\"Leather Seats\\", \\"Sunroof\\", \\"Premium Sound System\\", \\"Sport Package\\", \\"Navigation System\\", \\"Cold Weather Package\\", \\"Heated Seats\\", \\"Tinted Windows\\", \\"Alloy Wheels\\", \\"Backup Camera\\"]"}
243
+ ]
244
+ }
245
+ ]
246
+ }
247
+ </structured_output_response>
248
+
249
+ <explanation>
250
+
251
+ Key observations:
252
+ - \`fieldPath\` preserves exact schema field keys (e.g., "car_id", "facility.name", "modifications[]")
253
+ - \`fakerArgs\` is always an array \`[]\` - never a single value
254
+ - **When to include args**: \`maker\` uses \`helpers.arrayElement\` with sampleValues since they indicate an enum-like pattern; \`year\` uses \`number.int\` with min/max derived from sampleValues range; \`modifications[]\` uses \`helpers.arrayElement\` with the flat list of sampleValues — the generator handles the array dimension by calling the method N times per document
255
+ - **When to use empty args**: \`model\`, \`facility.name\`, \`facility.location\` use \`[]\` because no sample values provided and method defaults are sufficient
256
+ - JSON-serialized arguments properly escape quotes: \`{"json": "{\\"min\\": 2020, \\"max\\": 2024}"}\`
257
+ - Only include \`fakerArgs\` when they add value (constraints from sample values, validation rules) - otherwise prefer \`[]\`
258
+
259
+ Notice the 'structured_output_response' can be parsed to produce the following fakerjs factory function used to generate sample documents.
260
+
261
+ function createMockDocument() {
262
+ return {
263
+ 'car_id': faker.string.alphanumeric({ length: 12, casing: 'upper' }),
264
+ 'maker': faker.helpers.arrayElement(['Toyota', 'Honda', 'Ford', 'BMW']),
265
+ 'year': faker.number.int({ min: 2020, max: 2024 }),
266
+ 'model': faker.vehicle.model(),
267
+ 'facility.name': faker.company.name(),
268
+ 'facility.location': faker.location.city(),
269
+ 'facility.established': faker.number.int({ min: 1950, max: 2020 }),
270
+ 'modifications': Array.from({ length: 3 }, () =>
271
+ faker.helpers.arrayElement([
272
+ 'Leather Seats', 'Sunroof', 'Premium Sound System', 'Sport Package',
273
+ 'Navigation System', 'Cold Weather Package', 'Heated Seats',
274
+ 'Tinted Windows', 'Alloy Wheels', 'Backup Camera'
275
+ ])
276
+ )
277
+ }
278
+ }
279
+ </explanation>
280
+ `;
@@ -0,0 +1,21 @@
1
+ import type { MockDataSchemaToolOutput, RawSchema } from './schema';
2
+ export declare const FIELDS_PER_CHUNK = 30;
3
+ export declare const MAX_CHUNKS = 15;
4
+ /**
5
+ * Splits a schema into smaller chunks for processing.
6
+ */
7
+ export declare function splitSchemaIntoChunks(rawSchema: RawSchema, fieldsPerChunk?: number): RawSchema[];
8
+ /**
9
+ * Merges multiple chunk responses into a single response.
10
+ */
11
+ export declare function mergeChunkResponses(chunkResponses: MockDataSchemaToolOutput[]): MockDataSchemaToolOutput;
12
+ /**
13
+ * Validates schema size is within processing limits.
14
+ * Throws if schema exceeds maximum supported fields.
15
+ */
16
+ export declare function validateSchemaSize(rawSchema: RawSchema): void;
17
+ /**
18
+ * Determines if schema needs to be processed in chunks.
19
+ */
20
+ export declare function needsBatching(rawSchema: RawSchema): boolean;
21
+ //# sourceMappingURL=schema-batching.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-batching.d.ts","sourceRoot":"","sources":["../src/schema-batching.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGpE,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,EACpB,cAAc,GAAE,MAAyB,GACxC,SAAS,EAAE,CAIb;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,wBAAwB,EAAE,GACzC,wBAAwB,CAM1B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAS7D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAE3D"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MAX_CHUNKS = exports.FIELDS_PER_CHUNK = void 0;
7
+ exports.splitSchemaIntoChunks = splitSchemaIntoChunks;
8
+ exports.mergeChunkResponses = mergeChunkResponses;
9
+ exports.validateSchemaSize = validateSchemaSize;
10
+ exports.needsBatching = needsBatching;
11
+ const chunk_1 = __importDefault(require("lodash/chunk"));
12
+ // Based on token output limits; provides safe buffer.
13
+ exports.FIELDS_PER_CHUNK = 30;
14
+ exports.MAX_CHUNKS = 15;
15
+ /**
16
+ * Splits a schema into smaller chunks for processing.
17
+ */
18
+ function splitSchemaIntoChunks(rawSchema, fieldsPerChunk = exports.FIELDS_PER_CHUNK) {
19
+ return (0, chunk_1.default)(Object.entries(rawSchema), fieldsPerChunk).map((entries) => Object.fromEntries(entries));
20
+ }
21
+ /**
22
+ * Merges multiple chunk responses into a single response.
23
+ */
24
+ function mergeChunkResponses(chunkResponses) {
25
+ if (chunkResponses.length === 0) {
26
+ return { fields: [] };
27
+ }
28
+ return { fields: chunkResponses.flatMap((response) => response.fields) };
29
+ }
30
+ /**
31
+ * Validates schema size is within processing limits.
32
+ * Throws if schema exceeds maximum supported fields.
33
+ */
34
+ function validateSchemaSize(rawSchema) {
35
+ const fieldCount = Object.keys(rawSchema).length;
36
+ const maxFields = exports.FIELDS_PER_CHUNK * exports.MAX_CHUNKS;
37
+ if (fieldCount > maxFields) {
38
+ throw new Error(`Schema too large: ${fieldCount} fields exceeds maximum of ${maxFields} fields`);
39
+ }
40
+ }
41
+ /**
42
+ * Determines if schema needs to be processed in chunks.
43
+ */
44
+ function needsBatching(rawSchema) {
45
+ return Object.keys(rawSchema).length > exports.FIELDS_PER_CHUNK;
46
+ }
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const fakerFieldSchema: z.ZodObject<{
3
+ fieldPath: z.ZodString;
4
+ fakerMethod: z.ZodString;
5
+ fakerArgs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
6
+ json: z.ZodString;
7
+ }, z.core.$strip>, z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
8
+ }, z.core.$strip>;
9
+ export declare const mockDataSchemaToolSchema: z.ZodObject<{
10
+ fields: z.ZodArray<z.ZodObject<{
11
+ fieldPath: z.ZodString;
12
+ fakerMethod: z.ZodString;
13
+ fakerArgs: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
14
+ json: z.ZodString;
15
+ }, z.core.$strip>, z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
16
+ }, z.core.$strip>>;
17
+ }, z.core.$strip>;
18
+ export type MockDataSchemaToolOutput = z.infer<typeof mockDataSchemaToolSchema>;
19
+ export interface MockDataSchemaRawField {
20
+ type: string;
21
+ sampleValues?: unknown[];
22
+ }
23
+ export type RawSchema = Record<string, MockDataSchemaRawField>;
24
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,gBAAgB;;;;;;iBAgB3B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;iBAInC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEhF,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockDataSchemaToolSchema = exports.fakerFieldSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const fakerArgItemSchema = zod_1.z.union([
6
+ zod_1.z.object({ json: zod_1.z.string() }),
7
+ zod_1.z.string(),
8
+ zod_1.z.number(),
9
+ zod_1.z.boolean(),
10
+ ]);
11
+ exports.fakerFieldSchema = zod_1.z.object({
12
+ fieldPath: zod_1.z
13
+ .string()
14
+ .describe('Dot-notation path to the field (e.g., "facility.name", "modifications[]")'),
15
+ fakerMethod: zod_1.z
16
+ .string()
17
+ .describe('Faker.js method (e.g., "person.firstName", "helpers.arrayElement")'),
18
+ fakerArgs: zod_1.z
19
+ .array(fakerArgItemSchema)
20
+ .describe('Array of arguments for the faker method. Use empty [] when defaults are sufficient. Use {"json": "..."} format for object/array arguments.'),
21
+ });
22
+ exports.mockDataSchemaToolSchema = zod_1.z.object({
23
+ fields: zod_1.z
24
+ .array(exports.fakerFieldSchema)
25
+ .describe('Array of field-to-faker mappings'),
26
+ });
@@ -0,0 +1,42 @@
1
+ import type { ArrayLengthMap, FakerArg, FakerFieldMapping, MongoDBFieldType, ScriptOptions } from './types';
2
+ export type ScriptResult = {
3
+ script: string;
4
+ success: true;
5
+ } | {
6
+ error: string;
7
+ success: false;
8
+ };
9
+ /**
10
+ * Entry point method: Generate the final script
11
+ */
12
+ export declare function generateScript(schema: Record<string, FakerFieldMapping>, options: ScriptOptions): ScriptResult;
13
+ /**
14
+ * Gets default faker method for unrecognized fields based on MongoDB type
15
+ */
16
+ export declare function getDefaultFakerMethod(mongoType: MongoDBFieldType): string;
17
+ /**
18
+ * Converts array of faker arguments to comma separated string for function calls.
19
+ *
20
+ * Serializes various argument types into valid JavaScript syntax:
21
+ * - Strings: Uses JSON.stringify() to handle quotes, newlines, and special characters
22
+ * - Numbers: Validates finite numbers and converts to string representation
23
+ * - Booleans: Converts to 'true' or 'false' literals
24
+ * - Objects with 'json' property: Parses and re-stringifies JSON for validation
25
+ *
26
+ * @param fakerArgs - Array of arguments to convert to JavaScript code
27
+ * @returns Comma-separated string of JavaScript arguments, or empty string if no args
28
+ * @throws Error if arguments contain invalid values (non-finite numbers, malformed JSON)
29
+ *
30
+ * @example
31
+ * formatFakerArgs(['male', 25, true]) // Returns: '"male", 25, true'
32
+ * formatFakerArgs([{json: '{"min": 1}'}]) // Returns: '{"min": 1}'
33
+ */
34
+ export declare function formatFakerArgs(fakerArgs: FakerArg[]): string;
35
+ type Document = Record<string, unknown>;
36
+ /**
37
+ * Generates documents for the PreviewScreen component.
38
+ * Executes faker methods to create actual document objects.
39
+ */
40
+ export declare function generateDocument(fakerSchema: Record<string, FakerFieldMapping>, arrayLengthMap?: ArrayLengthMap): Document;
41
+ export {};
42
+ //# sourceMappingURL=script-generation-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-generation-utils.d.ts","sourceRoot":"","sources":["../src/script-generation-utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,cAAc,EACd,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACd,MAAM,SAAS,CAAC;AAIjB,MAAM,MAAM,YAAY,GACtB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;AAcxE;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACzC,OAAO,EAAE,aAAa,GACrB,YAAY,CAgFd;AAmXD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,CAyDzE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,MAAM,CA4B7D;AAED,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExC;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAC9C,cAAc,GAAE,cAAmB,GAClC,QAAQ,CAGV"}