@schmock/faker 1.12.0 → 2.0.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/field-name-matcher.d.ts.map +1 -1
- package/dist/field-name-matcher.js +9 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/jsf-config.d.ts +8 -5
- package/dist/jsf-config.d.ts.map +1 -1
- package/dist/jsf-config.js +19 -42
- package/dist/schema-enhancement.js +4 -0
- package/dist/test-utils.d.ts +5 -5
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/test-utils.js +25 -13
- package/package.json +4 -4
- package/src/advanced-features.test.ts +72 -71
- package/src/data-quality.test.ts +38 -38
- package/src/error-handling.test.ts +54 -56
- package/src/field-mappings.test.ts +74 -63
- package/src/field-name-matcher.ts +12 -2
- package/src/index.test.ts +145 -135
- package/src/index.ts +8 -6
- package/src/integration.test.ts +30 -28
- package/src/jsf-config.ts +21 -37
- package/src/performance.test.ts +45 -43
- package/src/plugin-integration.test.ts +46 -46
- package/src/real-world.test.ts +22 -22
- package/src/schema-enhancement.ts +5 -0
- package/src/steps/deterministic-seeds.steps.ts +24 -21
- package/src/steps/faker-plugin.steps.ts +190 -142
- package/src/test-utils.ts +38 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-name-matcher.d.ts","sourceRoot":"","sources":["../src/field-name-matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAsC5E;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,YAAY,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,EACnB,QAAQ,GAAE,YAAY,EAAuB,GAC5C,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"field-name-matcher.d.ts","sourceRoot":"","sources":["../src/field-name-matcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAsC5E;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,YAAY,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,EACnB,QAAQ,GAAE,YAAY,EAAuB,GAC5C,WAAW,GAAG,SAAS,CAuFzB"}
|
|
@@ -84,8 +84,11 @@ export function findBestMapping(fieldName, schema, mappings = ALL_FIELD_MAPPINGS
|
|
|
84
84
|
score: 1.0,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
// Skip if schema already has pattern, enum, or
|
|
88
|
-
if (schemaAny.pattern ||
|
|
87
|
+
// Skip if schema already has pattern, enum, faker, or $ref constraint
|
|
88
|
+
if (schemaAny.pattern ||
|
|
89
|
+
schemaAny.enum ||
|
|
90
|
+
schemaAny.faker ||
|
|
91
|
+
schemaAny.$ref) {
|
|
89
92
|
return undefined;
|
|
90
93
|
}
|
|
91
94
|
// Skip numeric faker mapping when schema already constrains the range
|
|
@@ -101,6 +104,10 @@ export function findBestMapping(fieldName, schema, mappings = ALL_FIELD_MAPPINGS
|
|
|
101
104
|
(mapping.schemaType === "number" || mapping.schemaType === "integer")) {
|
|
102
105
|
continue;
|
|
103
106
|
}
|
|
107
|
+
// Skip faker mappings for object/array schemas — they generate primitive values
|
|
108
|
+
if (schemaType === "object" || schemaType === "array") {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
104
111
|
// Check schema type constraint
|
|
105
112
|
if (mapping.schemaType && schemaType && mapping.schemaType !== schemaType) {
|
|
106
113
|
const isNumeric = (mapping.schemaType === "number" && schemaType === "integer") ||
|
package/dist/index.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export interface FakerPluginOptions {
|
|
|
15
15
|
seed?: number;
|
|
16
16
|
}
|
|
17
17
|
export declare function fakerPlugin(options: FakerPluginOptions): Schmock.Plugin;
|
|
18
|
-
export declare function generateFromSchema(options: SchemaGenerationContext): any
|
|
18
|
+
export declare function generateFromSchema(options: SchemaGenerationContext): Promise<any>;
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO/C,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CA+CvE;AAED,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO/C,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CA+CvE;AAED,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,GAAG,CAAC,CA8Cd"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ResourceLimitError as o,SchemaGenerationError as LQ,SchemaValidationError as i}from"@schmock/core";var J=1e4,b=10,G=3,w=3,M=100,E=0.05;import{base as n,en as m,Faker as r}from"@faker-js/faker";import C from"json-schema-faker";function L(Q){let $=new r({locale:[m,n]});if(Q!==void 0)$.seed(Q);return $}var f=!1,k;function h(Q){let $=Q|0;return()=>{$=$+1831565813|0;let B=$;return B=Math.imul(B^B>>>15,B|1),B^=B+Math.imul(B^B>>>7,B|61),((B^B>>>14)>>>0)/4294967296}}function v(Q){if(!f||Q!==k)k=Q,C.extend("faker",()=>L(Q)),C.option({requiredOnly:!1,alwaysFakeOptionals:!0,useDefaultValue:!0,ignoreMissingRefs:!0,failOnInvalidTypes:!1,failOnInvalidFormat:!1}),f=!0;if(Q!==void 0)C.option({random:h(Q)}),C.extend("faker",()=>L(Q));else C.option({random:Math.random});return C}var g=new Set(["__proto__","constructor","prototype"]);function u(Q,$,B=Math.random){if($!==void 0){if($<0)return 0;return $}if(Q.minItems!==void 0&&Q.maxItems!==void 0)return Math.floor(B()*(Q.maxItems-Q.minItems+1))+Q.minItems;if(Q.minItems!==void 0)return Math.max(Q.minItems,G);if(Q.maxItems!==void 0)return Math.min(Q.maxItems,G);return G}function P(Q,$,B,Z,K){if(!$)return Q;let X=structuredClone(Q);for(let[q,z]of Object.entries($)){if(g.has(q))continue;if(q.includes("."))c(X,q,z,{params:B,state:Z,query:K});else if(typeof z==="object"&&z!==null&&!Array.isArray(z))if(X[q]&&typeof X[q]==="object")X[q]=P(X[q],z,B,Z,K);else X[q]=P({},z,B,Z,K);else if(typeof z==="string"&&z.includes("{{"))X[q]=S(z,{params:B,state:Z,query:K});else X[q]=z}return X}function c(Q,$,B,Z){let K=$.split("."),X=Q;for(let z=0;z<K.length-1;z++){let W=K[z];if(g.has(W))return;if(!(W in X)||typeof X[W]!=="object"||X[W]===null)X[W]={};X=X[W]}let q=K[K.length-1];if(g.has(q))return;if(typeof B==="string"&&B.includes("{{"))X[q]=S(B,Z);else X[q]=B}function S(Q,$){let B=Q.match(/^\{\{\s*([^}]+)\s*\}\}$/);if(B){let X=B[1].trim().split("."),q=$;for(let z of X)if(q&&typeof q==="object")q=q[z];else return Q;return q!==void 0?q:Q}return Q.replace(/\{\{\s*([^}]+)\s*\}\}/g,(K,X)=>{let q=X.trim().split("."),z=$;for(let W of q)if(z&&typeof z==="object")z=z[W];else return K;return z!==void 0?String(z):K})}var s=[{keywords:["email"],fakerMethod:"internet.email",schemaType:"string",minScore:0.6,format:"email"},{keywords:["username","user_name","login","handle"],fakerMethod:"internet.username",schemaType:"string",minScore:0.6},{keywords:["password","passwd","secret"],fakerMethod:"internet.password",schemaType:"string",minScore:0.6},{keywords:["token","api_key","apikey","access_token","refresh_token"],fakerMethod:"string.alphanumeric",schemaType:"string",minScore:0.8}],t=[{keywords:["first_name","firstname","given_name","forename"],fakerMethod:"person.firstName",schemaType:"string",minScore:0.6},{keywords:["last_name","lastname","surname","family_name"],fakerMethod:"person.lastName",schemaType:"string",minScore:0.6},{keywords:["full_name","fullname","display_name","displayname","full_name"],fakerMethod:"person.fullName",schemaType:"string",minScore:0.6},{keywords:["name"],fakerMethod:"person.fullName",schemaType:"string",minScore:0.6},{keywords:["middle_name","middlename"],fakerMethod:"person.middleName",schemaType:"string",minScore:0.8},{keywords:["prefix","honorific","salutation"],fakerMethod:"person.prefix",schemaType:"string",minScore:0.8},{keywords:["suffix"],fakerMethod:"person.suffix",schemaType:"string",minScore:0.9},{keywords:["gender","sex"],fakerMethod:"person.sex",schemaType:"string",minScore:0.8},{keywords:["bio","biography"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.8},{keywords:["job_title","jobtitle","position","occupation","job","role"],fakerMethod:"person.jobTitle",schemaType:"string",minScore:0.6},{keywords:["job_area","department","division","team"],fakerMethod:"person.jobArea",schemaType:"string",minScore:0.8},{keywords:["zodiac","zodiac_sign"],fakerMethod:"person.zodiacSign",schemaType:"string",minScore:0.9}],a=[{keywords:["phone","mobile","cell","tel","telephone","cellphone","fax"],fakerMethod:"phone.number",schemaType:"string",minScore:0.6},{keywords:["imei"],fakerMethod:"phone.imei",schemaType:"string",minScore:0.9}],e=[{keywords:["street","street_address"],fakerMethod:"location.streetAddress",schemaType:"string",minScore:0.6},{keywords:["address","mailing_address","postal_address"],fakerMethod:"location.streetAddress",schemaType:"string",minScore:0.6},{keywords:["city","town"],fakerMethod:"location.city",schemaType:"string",minScore:0.6},{keywords:["state","province","region"],fakerMethod:"location.state",schemaType:"string",minScore:0.8},{keywords:["country"],fakerMethod:"location.country",schemaType:"string",minScore:0.8},{keywords:["country_code","countrycode"],fakerMethod:"location.countryCode",schemaType:"string",minScore:0.8},{keywords:["county"],fakerMethod:"location.county",schemaType:"string",minScore:0.9},{keywords:["continent"],fakerMethod:"location.continent",schemaType:"string",minScore:0.9},{keywords:["zip","zipcode","zip_code","postal","postal_code"],fakerMethod:"location.zipCode",schemaType:"string",minScore:0.6},{keywords:["latitude","lat"],fakerMethod:"location.latitude",schemaType:"number",minScore:0.6},{keywords:["longitude","lng","lon","long"],fakerMethod:"location.longitude",schemaType:"number",minScore:0.6},{keywords:["timezone","time_zone","tz"],fakerMethod:"location.timeZone",schemaType:"string",minScore:0.8},{keywords:["building_number"],fakerMethod:"location.buildingNumber",schemaType:"string",minScore:0.9}],QQ=[{keywords:["url","website","link","href","homepage","webpage"],fakerMethod:"internet.url",schemaType:"string",minScore:0.6},{keywords:["avatar","photo_url","profile_image","image_url","picture","thumbnail","icon"],fakerMethod:"image.avatar",schemaType:"string",minScore:0.6},{keywords:["domain","hostname","domain_name"],fakerMethod:"internet.domainName",schemaType:"string",minScore:0.8},{keywords:["ip","ip_address","ipaddress","ipv4"],fakerMethod:"internet.ipv4",schemaType:"string",minScore:0.8},{keywords:["ipv6"],fakerMethod:"internet.ipv6",schemaType:"string",minScore:0.9},{keywords:["mac","mac_address"],fakerMethod:"internet.mac",schemaType:"string",minScore:0.9},{keywords:["user_agent","useragent"],fakerMethod:"internet.userAgent",schemaType:"string",minScore:0.9},{keywords:["port"],fakerMethod:"internet.port",schemaType:"number",minScore:0.9},{keywords:["protocol"],fakerMethod:"internet.protocol",schemaType:"string",minScore:0.9}],$Q=[{keywords:["uuid","guid"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.6},{keywords:["sku"],fakerMethod:"string.alphanumeric",schemaType:"string",minScore:0.9},{keywords:["slug"],fakerMethod:"lorem.slug",schemaType:"string",minScore:0.8},{keywords:["isbn"],fakerMethod:"commerce.isbn",schemaType:"string",minScore:0.9},{keywords:["vin"],fakerMethod:"vehicle.vin",schemaType:"string",minScore:0.9},{keywords:["iban"],fakerMethod:"finance.iban",schemaType:"string",minScore:0.9},{keywords:["bic","swift"],fakerMethod:"finance.bic",schemaType:"string",minScore:0.9},{keywords:["ssn","social_security"],fakerMethod:"string.numeric",schemaType:"string",minScore:0.9}],BQ=[{keywords:["description","desc","summary","overview","about","excerpt"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.6},{keywords:["content","body","text","message"],fakerMethod:"lorem.paragraphs",schemaType:"string",minScore:0.6},{keywords:["title","heading","subject","headline"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.6},{keywords:["tag","label","category","keyword"],fakerMethod:"lorem.word",schemaType:"string",minScore:0.8},{keywords:["comment","note","remark","feedback","review"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.8},{keywords:["sentence"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.9},{keywords:["paragraph"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.9},{keywords:["word"],fakerMethod:"lorem.word",schemaType:"string",minScore:0.9}],ZQ=[{keywords:["company","organization","org","employer","brand"],fakerMethod:"company.name",schemaType:"string",minScore:0.6},{keywords:["product","product_name","item_name"],fakerMethod:"commerce.productName",schemaType:"string",minScore:0.8},{keywords:["price","amount","cost","fee","salary","wage","total","subtotal","balance","revenue","income"],fakerMethod:"commerce.price",minScore:0.6},{keywords:["currency","currency_code"],fakerMethod:"finance.currencyCode",schemaType:"string",minScore:0.8},{keywords:["currency_name"],fakerMethod:"finance.currencyName",schemaType:"string",minScore:0.8},{keywords:["currency_symbol"],fakerMethod:"finance.currencySymbol",schemaType:"string",minScore:0.8},{keywords:["account_number","account_no"],fakerMethod:"finance.accountNumber",schemaType:"string",minScore:0.8},{keywords:["credit_card","card_number"],fakerMethod:"finance.creditCardNumber",schemaType:"string",minScore:0.8},{keywords:["cvv"],fakerMethod:"finance.creditCardCVV",schemaType:"string",minScore:0.9},{keywords:["transaction_type"],fakerMethod:"finance.transactionType",schemaType:"string",minScore:0.9}],KQ=[{keywords:["created_at","createdat","creation_date","date_created","createddate"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["updated_at","updatedat","modified_at","modifiedat","date_updated","last_modified","date_modified"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["deleted_at","deletedat"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["published_at","publishedat","publish_date"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["expires_at","expiresat","expiration","expiry"],fakerMethod:"date.future",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["birthday","date_of_birth","dob","birthdate","born"],fakerMethod:"date.birthdate",schemaType:"string",minScore:0.8},{keywords:["start_date","begin_date"],fakerMethod:"date.past",schemaType:"string",minScore:0.8},{keywords:["end_date","due_date","deadline"],fakerMethod:"date.future",schemaType:"string",minScore:0.8},{keywords:["timestamp","ts"],fakerMethod:"date.recent",schemaType:"string",minScore:0.8}],XQ=[{keywords:["color","colour"],fakerMethod:"color.human",schemaType:"string",minScore:0.8},{keywords:["hex_color","hexcolor"],fakerMethod:"color.rgb",schemaType:"string",minScore:0.9}],zQ=[{keywords:["age"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:18,max:80}},{keywords:["rating","score","stars"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:5}},{keywords:["count","quantity","qty"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:100}},{keywords:["percentage","percent"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:0,max:100}},{keywords:["weight"],fakerMethod:"number.float",schemaType:"number",minScore:0.8,fakerArgs:{min:0.1,max:200}},{keywords:["height"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:100,max:220}},{keywords:["width","length","depth"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:1000}},{keywords:["priority","order","rank","level"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:10}},{keywords:["version"],fakerMethod:"system.semver",schemaType:"string",minScore:0.8}],WQ=[{keywords:["is_active","isactive","active","enabled","is_enabled"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.9},{keywords:["is_deleted","isdeleted","deleted"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.05},{keywords:["is_archived","isarchived","archived"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.1},{keywords:["is_verified","isverified","verified","confirmed","is_confirmed"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.8},{keywords:["is_admin","isadmin","admin"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.1},{keywords:["is_public","ispublic","public","visible","is_visible"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.7},{keywords:["is_read","isread","read","seen","is_seen"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.6},{keywords:["is_default","isdefault"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.1},{keywords:["is_required","isrequired","required","mandatory"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.5},{keywords:["is_featured","isfeatured","featured","promoted"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.15},{keywords:["available","in_stock"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.85}],qQ=[{keywords:["filename","file_name"],fakerMethod:"system.fileName",schemaType:"string",minScore:0.8},{keywords:["file_type","filetype","mime_type","mimetype","content_type"],fakerMethod:"system.mimeType",schemaType:"string",minScore:0.8},{keywords:["file_ext","extension"],fakerMethod:"system.fileExt",schemaType:"string",minScore:0.9},{keywords:["file_path","filepath","path"],fakerMethod:"system.filePath",schemaType:"string",minScore:0.9},{keywords:["cron","cron_expression"],fakerMethod:"system.cron",schemaType:"string",minScore:0.9},{keywords:["semver"],fakerMethod:"system.semver",schemaType:"string",minScore:0.9}],UQ=[{keywords:["aircraft_type","airplane","aircraft"],fakerMethod:"airline.aircraftType",schemaType:"string",minScore:0.9},{keywords:["flight_number","flight"],fakerMethod:"airline.flightNumber",schemaType:"string",minScore:0.9},{keywords:["record_locator","booking_ref","pnr"],fakerMethod:"airline.recordLocator",schemaType:"string",minScore:0.9},{keywords:["seat","seat_number"],fakerMethod:"airline.seat",schemaType:"string",minScore:0.9}],VQ=[{keywords:["animal","animal_type","species"],fakerMethod:"animal.type",schemaType:"string",minScore:0.9},{keywords:["pet_name"],fakerMethod:"animal.petName",schemaType:"string",minScore:0.9},{keywords:["breed"],fakerMethod:"animal.dog",schemaType:"string",minScore:0.9},{keywords:["bird"],fakerMethod:"animal.bird",schemaType:"string",minScore:0.9},{keywords:["fish"],fakerMethod:"animal.fish",schemaType:"string",minScore:0.9},{keywords:["horse"],fakerMethod:"animal.horse",schemaType:"string",minScore:0.9},{keywords:["insect"],fakerMethod:"animal.insect",schemaType:"string",minScore:0.9}],YQ=[{keywords:["book_title"],fakerMethod:"book.title",schemaType:"string",minScore:0.9},{keywords:["author","book_author","writer"],fakerMethod:"book.author",schemaType:"string",minScore:0.9},{keywords:["genre","book_genre"],fakerMethod:"book.genre",schemaType:"string",minScore:0.9},{keywords:["publisher","publishing_house"],fakerMethod:"book.publisher",schemaType:"string",minScore:0.9},{keywords:["book_series","series_name"],fakerMethod:"book.series",schemaType:"string",minScore:0.9}],FQ=[{keywords:["dish","meal","recipe_name"],fakerMethod:"food.dish",schemaType:"string",minScore:0.9},{keywords:["ingredient"],fakerMethod:"food.ingredient",schemaType:"string",minScore:0.9},{keywords:["spice"],fakerMethod:"food.spice",schemaType:"string",minScore:0.9},{keywords:["fruit"],fakerMethod:"food.fruit",schemaType:"string",minScore:0.9},{keywords:["vegetable"],fakerMethod:"food.vegetable",schemaType:"string",minScore:0.9},{keywords:["meat"],fakerMethod:"food.meat",schemaType:"string",minScore:0.9},{keywords:["food_description"],fakerMethod:"food.description",schemaType:"string",minScore:0.9},{keywords:["ethnic_category","cuisine"],fakerMethod:"food.ethnicCategory",schemaType:"string",minScore:0.9}],HQ=[{keywords:["song","song_name","track","track_name"],fakerMethod:"music.songName",schemaType:"string",minScore:0.9},{keywords:["album","album_name"],fakerMethod:"music.album",schemaType:"string",minScore:0.9},{keywords:["artist","musician","band"],fakerMethod:"music.artist",schemaType:"string",minScore:0.9},{keywords:["music_genre"],fakerMethod:"music.genre",schemaType:"string",minScore:0.9}],GQ=[],JQ=[{keywords:["vehicle","vehicle_name"],fakerMethod:"vehicle.vehicle",schemaType:"string",minScore:0.9},{keywords:["vehicle_type"],fakerMethod:"vehicle.type",schemaType:"string",minScore:0.9},{keywords:["vehicle_manufacturer","car_make"],fakerMethod:"vehicle.manufacturer",schemaType:"string",minScore:0.9},{keywords:["vehicle_model","car_model"],fakerMethod:"vehicle.model",schemaType:"string",minScore:0.9},{keywords:["fuel","fuel_type"],fakerMethod:"vehicle.fuel",schemaType:"string",minScore:0.9},{keywords:["bicycle"],fakerMethod:"vehicle.bicycle",schemaType:"string",minScore:0.9},{keywords:["vehicle_color","car_color"],fakerMethod:"vehicle.color",schemaType:"string",minScore:0.9}],wQ=[{keywords:["branch","branch_name","git_branch"],fakerMethod:"git.branch",schemaType:"string",minScore:0.9},{keywords:["commit_sha","commit_hash","sha"],fakerMethod:"git.commitSha",schemaType:"string",minScore:0.9},{keywords:["commit_message"],fakerMethod:"git.commitMessage",schemaType:"string",minScore:0.9}],CQ=[{keywords:["db_column","column_name"],fakerMethod:"database.column",schemaType:"string",minScore:0.9},{keywords:["db_type","column_type"],fakerMethod:"database.type",schemaType:"string",minScore:0.9},{keywords:["db_engine","database_engine"],fakerMethod:"database.engine",schemaType:"string",minScore:0.9},{keywords:["collation"],fakerMethod:"database.collation",schemaType:"string",minScore:0.9},{keywords:["mongodb_id","object_id"],fakerMethod:"database.mongodbObjectId",schemaType:"string",minScore:0.9}],jQ=[{keywords:["abbreviation","tech_abbreviation"],fakerMethod:"hacker.abbreviation",schemaType:"string",minScore:0.9},{keywords:["hacker_phrase","tech_phrase"],fakerMethod:"hacker.phrase",schemaType:"string",minScore:0.9}],IQ=[{keywords:["adjective"],fakerMethod:"word.adjective",schemaType:"string",minScore:0.8},{keywords:["adverb"],fakerMethod:"word.adverb",schemaType:"string",minScore:0.8},{keywords:["noun"],fakerMethod:"word.noun",schemaType:"string",minScore:0.8},{keywords:["verb"],fakerMethod:"word.verb",schemaType:"string",minScore:0.8}],l=[...s,...t,...a,...e,...QQ,...$Q,...BQ,...ZQ,...KQ,...XQ,...zQ,...WQ,...qQ,...UQ,...VQ,...YQ,...FQ,...HQ,...GQ,...JQ,...wQ,...CQ,...jQ,...IQ];function d(Q){let $=Q.split(/[_-]/),B=[];for(let Z of $){if(!Z)continue;let K=Z.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z0-9])([A-Z])/g,"$1_$2").split("_");for(let X of K)if(X)B.push(X.toLowerCase())}return B}function MQ(Q,$){let B=Q.join(""),Z=0;for(let K of $){let X=d(K),q=X.join("");if(B===q)return 1;if(X.length>0&&X.every((z)=>Q.includes(z))){let W=X.length/Q.length>0.5?0.9:0.65;Z=Math.max(Z,W)}if(X.length>0&&X.length<=Q.length){if(Q.slice(-X.length).every((W,U)=>W===X[U]))Z=Math.max(Z,0.8)}if(q.length>=3&&B.includes(q))Z=Math.max(Z,0.7)}return Z}function p(Q,$,B=l){let Z=$,K=typeof $.type==="string"?$.type:void 0;if(K==="string"&&$.format==="uuid")return{mapping:{keywords:["uuid"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.5},score:1};if(Z.pattern||Z.enum||Z.faker)return;let X=$.minimum!==void 0||$.maximum!==void 0||$.exclusiveMinimum!==void 0||$.exclusiveMaximum!==void 0,q=d(Q),z;for(let W of B){if(X&&(W.schemaType==="number"||W.schemaType==="integer"))continue;if(W.schemaType&&K&&W.schemaType!==K){if(!(W.schemaType==="number"&&K==="integer"||W.schemaType==="integer"&&K==="number"))continue}let U=MQ(q,W.keywords);if(U>=W.minScore&&(!z||U>z.score))z={mapping:W,score:U}}if(K==="string"){if(q[q.length-1]==="id"&&q.length>1){if(!z||z.score<0.8)z={mapping:{keywords:["id"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.5},score:0.8}}}return z}import{ResourceLimitError as x,SchemaValidationError as Y}from"@schmock/core";var R;function V(Q){return typeof Q==="object"&&Q!==null&&!Array.isArray(Q)}function j(Q,$="$"){if(!Q||typeof Q!=="object")throw new Y($,"Schema must be a valid JSON Schema object");if(Object.keys(Q).length===0)throw new Y($,"Schema cannot be empty");let B=["object","array","string","number","integer","boolean","null"];if(Q.type&&typeof Q.type==="string"&&!B.includes(Q.type))throw new Y($,`Invalid schema type: "${Q.type}"`,"Supported types are: object, array, string, number, integer, boolean, null");if(Q.type==="object"&&Q.properties){if(typeof Q.properties!=="object"||Array.isArray(Q.properties))throw new Y(`${$}.properties`,"Properties must be an object mapping property names to schemas",'Use { "propertyName": { "type": "string" } } format');for(let[K,X]of Object.entries(Q.properties))if(typeof X==="object"&&X!==null){let q="faker"in X?String(X.faker):void 0;if(q)try{A(q)}catch(z){if(z instanceof Y){let W=z.context,U="Invalid faker method",H;if(W&&typeof W==="object"){if("issue"in W&&typeof W.issue==="string")U=W.issue;if("suggestion"in W&&typeof W.suggestion==="string")H=W.suggestion}throw new Y(`${$}.properties.${K}.faker`,U,H)}if(z instanceof Error)throw z;throw Error(String(z))}j(X,`${$}.properties.${K}`)}}if(Q.type==="array"){if(Q.items===null||Q.items===void 0)throw new Y(`${$}.items`,"Array schema must have valid items definition","Define items as a schema object or array of schemas");if(Array.isArray(Q.items)){if(Q.items.length===0)throw new Y(`${$}.items`,"Array items cannot be empty array","Provide at least one item schema");Q.items.forEach((K,X)=>{if(typeof K==="object"&&K!==null)j(K,`${$}.items[${X}]`)})}else if(typeof Q.items==="object"&&Q.items!==null)j(Q.items,`${$}.items`)}if(N(Q))throw new Y($,"Schema contains circular references which are not supported");let Z=D(Q);if(Z>b)throw new x("schema_nesting_depth",b,Z);if(Z>=w)PQ(Q,$);if(O(Q,$),Q.$ref==="#")throw new Y($,"Self-referencing schemas are not supported")}function N(Q,$=new Set){if($.has(Q))return!0;if(Q.$ref==="#")return!0;if($.add(Q),Q.type==="object"&&Q.properties){for(let B of Object.values(Q.properties))if(V(B)){if(N(B,$))return!0}}if(Q.type==="array"&&Q.items){let B=Array.isArray(Q.items)?Q.items:[Q.items];for(let Z of B)if(V(Z)){if(N(Z,$))return!0}}return $.delete(Q),!1}function D(Q,$=0){if($>b)return $;let B=$;if(Q.type==="object"&&Q.properties){for(let Z of Object.values(Q.properties))if(V(Z))B=Math.max(B,D(Z,$+1))}if(Q.type==="array"&&Q.items){let Z=Array.isArray(Q.items)?Q.items:[Q.items];for(let K of Z)if(V(K))B=Math.max(B,D(K,$+1))}return B}function PQ(Q,$){function B(Z,K){let X=Z.type;if(Array.isArray(X)?X.includes("array"):X==="array"){let z=Z.maxItems||G;if(K>=w&&z>=M)throw new x("deep_nesting_memory_risk",w*M,K*z);if(Z.items){let W=Array.isArray(Z.items)?Z.items:[Z.items];for(let U of W)if(V(U))B(U,K+1)}return}if(X==="object"&&Z.properties){for(let z of Object.values(Z.properties))if(V(z))B(z,K+1)}}B(Q,0)}function O(Q,$){if(Q.type==="array"){if(Q.maxItems&&Q.maxItems>J)throw new x("array_max_items",J,Q.maxItems);let B=D(Q),Z=Q.maxItems||Q.minItems||G;if(B>w&&Z>M)throw new x("memory_estimation",w*M,B*Z)}if(Q.type==="object"&&Q.properties){for(let[B,Z]of Object.entries(Q.properties))if(V(Z))O(Z,`${$}.properties.${B}`)}if(Q.type==="array"&&Q.items){if(Array.isArray(Q.items))Q.items.forEach((B,Z)=>{if(V(B))O(B,`${$}.items[${Z}]`)});else if(V(Q.items))O(Q.items,`${$}.items`)}}function A(Q){let $=Q.split(".");if($.length<2)throw new Y("$.faker",`Invalid faker method format: "${Q}"`,"Use format like 'person.firstName' or 'internet.email'");if(!R)R=L();let Z=R;for(let K of $)if(Z&&typeof Z==="object"&&K in Z)Z=Z[K];else throw new Y("$.faker",`Invalid faker method: "${Q}"`,"Check faker.js documentation for valid methods");if(typeof Z!=="function")throw new Y("$.faker",`Invalid faker method: "${Q}" is not a function`,"Check faker.js documentation for valid methods")}function F(Q){if(!Q||typeof Q!=="object")return Q;let $={...Q};if($.properties){$.properties={...$.properties};for(let[B,Z]of Object.entries($.properties))if(V(Z))$.properties[B]=bQ(B,Z)}for(let B of["allOf","anyOf","oneOf"]){let Z=$[B];if(Array.isArray(Z))$[B]=Z.map((K)=>V(K)?F(K):K)}if($.items){if(Array.isArray($.items))$.items=$.items.map((B)=>V(B)?F(B):B);else if(V($.items))$.items=F($.items)}if($.additionalProperties&&typeof $.additionalProperties==="object"&&!Array.isArray($.additionalProperties))$.additionalProperties=F($.additionalProperties);return $}function bQ(Q,$){let B={...$};if(B.faker)return A(B.faker),B;let Z=B.allOf||B.anyOf||B.oneOf;if(B.properties||Z||B.items){let X=F(B);Object.assign(B,X)}if(Z)return B;let K=p(Q,B);if(K){if(B.faker=K.mapping.fakerMethod,K.mapping.format)B.format=K.mapping.format;if(K.mapping.trueProbability!==void 0)B.schmockTrueProbability=K.mapping.trueProbability}return B}function hQ(Q){return j(Q.schema),{name:"faker",version:"1.0.1",process($,B){if(B!==void 0&&B!==null)return{context:$,response:B};try{let Z=OQ({schema:Q.schema,count:Q.count,overrides:Q.overrides,params:$.params,state:$.routeState,query:$.query,seed:Q.seed});return{context:$,response:Z}}catch(Z){if(Z instanceof i||Z instanceof o)throw Z;throw new LQ($.path,Z instanceof Error?Z:Error(String(Z)),Q.schema)}}}}function OQ(Q){let{schema:$,count:B,overrides:Z,params:K,state:X,query:q,seed:z}=Q;j($);let W;if($.type==="array"&&$.items){let U=u($,B);if(U>J)throw new o("array_size",J,U);let H=Array.isArray($.items)?$.items[0]:$.items;if(!H||typeof H==="boolean")throw new i("$.items","Array schema must have valid items definition");let T=F(H);W=[];for(let y=0;y<U;y++){let I=v(z).generate(T);I=_(I,T),I=P(I,Z,K,X,q),W.push(I)}}else{let U=F($);W=v(z).generate(U),W=_(W,U),W=P(W,Z,K,X,q)}return W}function _(Q,$){if(Q===null||Q===void 0||!$||typeof $!=="object")return Q;let B=$;if(B.schmockNullable===!0){if(Math.random()<E)return null}if($.type==="boolean"&&typeof B.schmockTrueProbability==="number")return Math.random()<B.schmockTrueProbability;if(typeof Q==="object"&&!Array.isArray(Q)&&$.properties){for(let[Z,K]of Object.entries($.properties))if(Z in Q&&V(K))Q[Z]=_(Q[Z],K)}if(Array.isArray(Q)&&$.items&&V($.items))for(let Z=0;Z<Q.length;Z++)Q[Z]=_(Q[Z],$.items);return Q}export{OQ as generateFromSchema,hQ as fakerPlugin};
|
|
1
|
+
import{ResourceLimitError as l,SchemaGenerationError as PQ,SchemaValidationError as d}from"@schmock/core";var G=1e4,M=10,C=3,H=3,I=100,T=0.05;import{base as p,en as o,Faker as i}from"@faker-js/faker";import{generate as n}from"json-schema-faker";function D(Q){let $=new i({locale:[o,p]});if(Q!==void 0)$.seed(Q);return $}async function _(Q,$){let B=$??Math.floor(Math.random()*2147483647);return n(Q,{seed:B,optionalsProbability:1,alwaysFakeOptionals:!0,useDefaultValue:!0,ignoreMissingRefs:!0,failOnInvalidTypes:!1,failOnInvalidFormat:!1,extensions:{faker:D($)}})}var v=new Set(["__proto__","constructor","prototype"]);function y(Q,$,B=Math.random){if($!==void 0){if($<0)return 0;return $}if(Q.minItems!==void 0&&Q.maxItems!==void 0)return Math.floor(B()*(Q.maxItems-Q.minItems+1))+Q.minItems;if(Q.minItems!==void 0)return Math.max(Q.minItems,C);if(Q.maxItems!==void 0)return Math.min(Q.maxItems,C);return C}function P(Q,$,B,Z,K){if(!$)return Q;let X=structuredClone(Q);for(let[W,z]of Object.entries($)){if(v.has(W))continue;if(W.includes("."))m(X,W,z,{params:B,state:Z,query:K});else if(typeof z==="object"&&z!==null&&!Array.isArray(z))if(X[W]&&typeof X[W]==="object")X[W]=P(X[W],z,B,Z,K);else X[W]=P({},z,B,Z,K);else if(typeof z==="string"&&z.includes("{{"))X[W]=E(z,{params:B,state:Z,query:K});else X[W]=z}return X}function m(Q,$,B,Z){let K=$.split("."),X=Q;for(let z=0;z<K.length-1;z++){let q=K[z];if(v.has(q))return;if(!(q in X)||typeof X[q]!=="object"||X[q]===null)X[q]={};X=X[q]}let W=K[K.length-1];if(v.has(W))return;if(typeof B==="string"&&B.includes("{{"))X[W]=E(B,Z);else X[W]=B}function E(Q,$){let B=Q.match(/^\{\{\s*([^}]+)\s*\}\}$/);if(B){let X=B[1].trim().split("."),W=$;for(let z of X)if(W&&typeof W==="object")W=W[z];else return Q;return W!==void 0?W:Q}return Q.replace(/\{\{\s*([^}]+)\s*\}\}/g,(K,X)=>{let W=X.trim().split("."),z=$;for(let q of W)if(z&&typeof z==="object")z=z[q];else return K;return z!==void 0?String(z):K})}var r=[{keywords:["email"],fakerMethod:"internet.email",schemaType:"string",minScore:0.6,format:"email"},{keywords:["username","user_name","login","handle"],fakerMethod:"internet.username",schemaType:"string",minScore:0.6},{keywords:["password","passwd","secret"],fakerMethod:"internet.password",schemaType:"string",minScore:0.6},{keywords:["token","api_key","apikey","access_token","refresh_token"],fakerMethod:"string.alphanumeric",schemaType:"string",minScore:0.8}],h=[{keywords:["first_name","firstname","given_name","forename"],fakerMethod:"person.firstName",schemaType:"string",minScore:0.6},{keywords:["last_name","lastname","surname","family_name"],fakerMethod:"person.lastName",schemaType:"string",minScore:0.6},{keywords:["full_name","fullname","display_name","displayname","full_name"],fakerMethod:"person.fullName",schemaType:"string",minScore:0.6},{keywords:["name"],fakerMethod:"person.fullName",schemaType:"string",minScore:0.6},{keywords:["middle_name","middlename"],fakerMethod:"person.middleName",schemaType:"string",minScore:0.8},{keywords:["prefix","honorific","salutation"],fakerMethod:"person.prefix",schemaType:"string",minScore:0.8},{keywords:["suffix"],fakerMethod:"person.suffix",schemaType:"string",minScore:0.9},{keywords:["gender","sex"],fakerMethod:"person.sex",schemaType:"string",minScore:0.8},{keywords:["bio","biography"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.8},{keywords:["job_title","jobtitle","position","occupation","job","role"],fakerMethod:"person.jobTitle",schemaType:"string",minScore:0.6},{keywords:["job_area","department","division","team"],fakerMethod:"person.jobArea",schemaType:"string",minScore:0.8},{keywords:["zodiac","zodiac_sign"],fakerMethod:"person.zodiacSign",schemaType:"string",minScore:0.9}],c=[{keywords:["phone","mobile","cell","tel","telephone","cellphone","fax"],fakerMethod:"phone.number",schemaType:"string",minScore:0.6},{keywords:["imei"],fakerMethod:"phone.imei",schemaType:"string",minScore:0.9}],s=[{keywords:["street","street_address"],fakerMethod:"location.streetAddress",schemaType:"string",minScore:0.6},{keywords:["address","mailing_address","postal_address"],fakerMethod:"location.streetAddress",schemaType:"string",minScore:0.6},{keywords:["city","town"],fakerMethod:"location.city",schemaType:"string",minScore:0.6},{keywords:["state","province","region"],fakerMethod:"location.state",schemaType:"string",minScore:0.8},{keywords:["country"],fakerMethod:"location.country",schemaType:"string",minScore:0.8},{keywords:["country_code","countrycode"],fakerMethod:"location.countryCode",schemaType:"string",minScore:0.8},{keywords:["county"],fakerMethod:"location.county",schemaType:"string",minScore:0.9},{keywords:["continent"],fakerMethod:"location.continent",schemaType:"string",minScore:0.9},{keywords:["zip","zipcode","zip_code","postal","postal_code"],fakerMethod:"location.zipCode",schemaType:"string",minScore:0.6},{keywords:["latitude","lat"],fakerMethod:"location.latitude",schemaType:"number",minScore:0.6},{keywords:["longitude","lng","lon","long"],fakerMethod:"location.longitude",schemaType:"number",minScore:0.6},{keywords:["timezone","time_zone","tz"],fakerMethod:"location.timeZone",schemaType:"string",minScore:0.8},{keywords:["building_number"],fakerMethod:"location.buildingNumber",schemaType:"string",minScore:0.9}],t=[{keywords:["url","website","link","href","homepage","webpage"],fakerMethod:"internet.url",schemaType:"string",minScore:0.6},{keywords:["avatar","photo_url","profile_image","image_url","picture","thumbnail","icon"],fakerMethod:"image.avatar",schemaType:"string",minScore:0.6},{keywords:["domain","hostname","domain_name"],fakerMethod:"internet.domainName",schemaType:"string",minScore:0.8},{keywords:["ip","ip_address","ipaddress","ipv4"],fakerMethod:"internet.ipv4",schemaType:"string",minScore:0.8},{keywords:["ipv6"],fakerMethod:"internet.ipv6",schemaType:"string",minScore:0.9},{keywords:["mac","mac_address"],fakerMethod:"internet.mac",schemaType:"string",minScore:0.9},{keywords:["user_agent","useragent"],fakerMethod:"internet.userAgent",schemaType:"string",minScore:0.9},{keywords:["port"],fakerMethod:"internet.port",schemaType:"number",minScore:0.9},{keywords:["protocol"],fakerMethod:"internet.protocol",schemaType:"string",minScore:0.9}],a=[{keywords:["uuid","guid"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.6},{keywords:["sku"],fakerMethod:"string.alphanumeric",schemaType:"string",minScore:0.9},{keywords:["slug"],fakerMethod:"lorem.slug",schemaType:"string",minScore:0.8},{keywords:["isbn"],fakerMethod:"commerce.isbn",schemaType:"string",minScore:0.9},{keywords:["vin"],fakerMethod:"vehicle.vin",schemaType:"string",minScore:0.9},{keywords:["iban"],fakerMethod:"finance.iban",schemaType:"string",minScore:0.9},{keywords:["bic","swift"],fakerMethod:"finance.bic",schemaType:"string",minScore:0.9},{keywords:["ssn","social_security"],fakerMethod:"string.numeric",schemaType:"string",minScore:0.9}],e=[{keywords:["description","desc","summary","overview","about","excerpt"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.6},{keywords:["content","body","text","message"],fakerMethod:"lorem.paragraphs",schemaType:"string",minScore:0.6},{keywords:["title","heading","subject","headline"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.6},{keywords:["tag","label","category","keyword"],fakerMethod:"lorem.word",schemaType:"string",minScore:0.8},{keywords:["comment","note","remark","feedback","review"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.8},{keywords:["sentence"],fakerMethod:"lorem.sentence",schemaType:"string",minScore:0.9},{keywords:["paragraph"],fakerMethod:"lorem.paragraph",schemaType:"string",minScore:0.9},{keywords:["word"],fakerMethod:"lorem.word",schemaType:"string",minScore:0.9}],QQ=[{keywords:["company","organization","org","employer","brand"],fakerMethod:"company.name",schemaType:"string",minScore:0.6},{keywords:["product","product_name","item_name"],fakerMethod:"commerce.productName",schemaType:"string",minScore:0.8},{keywords:["price","amount","cost","fee","salary","wage","total","subtotal","balance","revenue","income"],fakerMethod:"commerce.price",minScore:0.6},{keywords:["currency","currency_code"],fakerMethod:"finance.currencyCode",schemaType:"string",minScore:0.8},{keywords:["currency_name"],fakerMethod:"finance.currencyName",schemaType:"string",minScore:0.8},{keywords:["currency_symbol"],fakerMethod:"finance.currencySymbol",schemaType:"string",minScore:0.8},{keywords:["account_number","account_no"],fakerMethod:"finance.accountNumber",schemaType:"string",minScore:0.8},{keywords:["credit_card","card_number"],fakerMethod:"finance.creditCardNumber",schemaType:"string",minScore:0.8},{keywords:["cvv"],fakerMethod:"finance.creditCardCVV",schemaType:"string",minScore:0.9},{keywords:["transaction_type"],fakerMethod:"finance.transactionType",schemaType:"string",minScore:0.9}],$Q=[{keywords:["created_at","createdat","creation_date","date_created","createddate"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["updated_at","updatedat","modified_at","modifiedat","date_updated","last_modified","date_modified"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["deleted_at","deletedat"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["published_at","publishedat","publish_date"],fakerMethod:"date.recent",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["expires_at","expiresat","expiration","expiry"],fakerMethod:"date.future",schemaType:"string",minScore:0.6,format:"date-time"},{keywords:["birthday","date_of_birth","dob","birthdate","born"],fakerMethod:"date.birthdate",schemaType:"string",minScore:0.8},{keywords:["start_date","begin_date"],fakerMethod:"date.past",schemaType:"string",minScore:0.8},{keywords:["end_date","due_date","deadline"],fakerMethod:"date.future",schemaType:"string",minScore:0.8},{keywords:["timestamp","ts"],fakerMethod:"date.recent",schemaType:"string",minScore:0.8}],BQ=[{keywords:["color","colour"],fakerMethod:"color.human",schemaType:"string",minScore:0.8},{keywords:["hex_color","hexcolor"],fakerMethod:"color.rgb",schemaType:"string",minScore:0.9}],ZQ=[{keywords:["age"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:18,max:80}},{keywords:["rating","score","stars"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:5}},{keywords:["count","quantity","qty"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:100}},{keywords:["percentage","percent"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:0,max:100}},{keywords:["weight"],fakerMethod:"number.float",schemaType:"number",minScore:0.8,fakerArgs:{min:0.1,max:200}},{keywords:["height"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:100,max:220}},{keywords:["width","length","depth"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:1000}},{keywords:["priority","order","rank","level"],fakerMethod:"number.int",schemaType:"number",minScore:0.8,fakerArgs:{min:1,max:10}},{keywords:["version"],fakerMethod:"system.semver",schemaType:"string",minScore:0.8}],KQ=[{keywords:["is_active","isactive","active","enabled","is_enabled"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.9},{keywords:["is_deleted","isdeleted","deleted"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.05},{keywords:["is_archived","isarchived","archived"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.1},{keywords:["is_verified","isverified","verified","confirmed","is_confirmed"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.8},{keywords:["is_admin","isadmin","admin"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.1},{keywords:["is_public","ispublic","public","visible","is_visible"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.7},{keywords:["is_read","isread","read","seen","is_seen"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.6},{keywords:["is_default","isdefault"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.1},{keywords:["is_required","isrequired","required","mandatory"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.6,trueProbability:0.5},{keywords:["is_featured","isfeatured","featured","promoted"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.15},{keywords:["available","in_stock"],fakerMethod:"datatype.boolean",schemaType:"boolean",minScore:0.8,trueProbability:0.85}],XQ=[{keywords:["filename","file_name"],fakerMethod:"system.fileName",schemaType:"string",minScore:0.8},{keywords:["file_type","filetype","mime_type","mimetype","content_type"],fakerMethod:"system.mimeType",schemaType:"string",minScore:0.8},{keywords:["file_ext","extension"],fakerMethod:"system.fileExt",schemaType:"string",minScore:0.9},{keywords:["file_path","filepath","path"],fakerMethod:"system.filePath",schemaType:"string",minScore:0.9},{keywords:["cron","cron_expression"],fakerMethod:"system.cron",schemaType:"string",minScore:0.9},{keywords:["semver"],fakerMethod:"system.semver",schemaType:"string",minScore:0.9}],zQ=[{keywords:["aircraft_type","airplane","aircraft"],fakerMethod:"airline.aircraftType",schemaType:"string",minScore:0.9},{keywords:["flight_number","flight"],fakerMethod:"airline.flightNumber",schemaType:"string",minScore:0.9},{keywords:["record_locator","booking_ref","pnr"],fakerMethod:"airline.recordLocator",schemaType:"string",minScore:0.9},{keywords:["seat","seat_number"],fakerMethod:"airline.seat",schemaType:"string",minScore:0.9}],qQ=[{keywords:["animal","animal_type","species"],fakerMethod:"animal.type",schemaType:"string",minScore:0.9},{keywords:["pet_name"],fakerMethod:"animal.petName",schemaType:"string",minScore:0.9},{keywords:["breed"],fakerMethod:"animal.dog",schemaType:"string",minScore:0.9},{keywords:["bird"],fakerMethod:"animal.bird",schemaType:"string",minScore:0.9},{keywords:["fish"],fakerMethod:"animal.fish",schemaType:"string",minScore:0.9},{keywords:["horse"],fakerMethod:"animal.horse",schemaType:"string",minScore:0.9},{keywords:["insect"],fakerMethod:"animal.insect",schemaType:"string",minScore:0.9}],WQ=[{keywords:["book_title"],fakerMethod:"book.title",schemaType:"string",minScore:0.9},{keywords:["author","book_author","writer"],fakerMethod:"book.author",schemaType:"string",minScore:0.9},{keywords:["genre","book_genre"],fakerMethod:"book.genre",schemaType:"string",minScore:0.9},{keywords:["publisher","publishing_house"],fakerMethod:"book.publisher",schemaType:"string",minScore:0.9},{keywords:["book_series","series_name"],fakerMethod:"book.series",schemaType:"string",minScore:0.9}],UQ=[{keywords:["dish","meal","recipe_name"],fakerMethod:"food.dish",schemaType:"string",minScore:0.9},{keywords:["ingredient"],fakerMethod:"food.ingredient",schemaType:"string",minScore:0.9},{keywords:["spice"],fakerMethod:"food.spice",schemaType:"string",minScore:0.9},{keywords:["fruit"],fakerMethod:"food.fruit",schemaType:"string",minScore:0.9},{keywords:["vegetable"],fakerMethod:"food.vegetable",schemaType:"string",minScore:0.9},{keywords:["meat"],fakerMethod:"food.meat",schemaType:"string",minScore:0.9},{keywords:["food_description"],fakerMethod:"food.description",schemaType:"string",minScore:0.9},{keywords:["ethnic_category","cuisine"],fakerMethod:"food.ethnicCategory",schemaType:"string",minScore:0.9}],VQ=[{keywords:["song","song_name","track","track_name"],fakerMethod:"music.songName",schemaType:"string",minScore:0.9},{keywords:["album","album_name"],fakerMethod:"music.album",schemaType:"string",minScore:0.9},{keywords:["artist","musician","band"],fakerMethod:"music.artist",schemaType:"string",minScore:0.9},{keywords:["music_genre"],fakerMethod:"music.genre",schemaType:"string",minScore:0.9}],YQ=[],jQ=[{keywords:["vehicle","vehicle_name"],fakerMethod:"vehicle.vehicle",schemaType:"string",minScore:0.9},{keywords:["vehicle_type"],fakerMethod:"vehicle.type",schemaType:"string",minScore:0.9},{keywords:["vehicle_manufacturer","car_make"],fakerMethod:"vehicle.manufacturer",schemaType:"string",minScore:0.9},{keywords:["vehicle_model","car_model"],fakerMethod:"vehicle.model",schemaType:"string",minScore:0.9},{keywords:["fuel","fuel_type"],fakerMethod:"vehicle.fuel",schemaType:"string",minScore:0.9},{keywords:["bicycle"],fakerMethod:"vehicle.bicycle",schemaType:"string",minScore:0.9},{keywords:["vehicle_color","car_color"],fakerMethod:"vehicle.color",schemaType:"string",minScore:0.9}],FQ=[{keywords:["branch","branch_name","git_branch"],fakerMethod:"git.branch",schemaType:"string",minScore:0.9},{keywords:["commit_sha","commit_hash","sha"],fakerMethod:"git.commitSha",schemaType:"string",minScore:0.9},{keywords:["commit_message"],fakerMethod:"git.commitMessage",schemaType:"string",minScore:0.9}],CQ=[{keywords:["db_column","column_name"],fakerMethod:"database.column",schemaType:"string",minScore:0.9},{keywords:["db_type","column_type"],fakerMethod:"database.type",schemaType:"string",minScore:0.9},{keywords:["db_engine","database_engine"],fakerMethod:"database.engine",schemaType:"string",minScore:0.9},{keywords:["collation"],fakerMethod:"database.collation",schemaType:"string",minScore:0.9},{keywords:["mongodb_id","object_id"],fakerMethod:"database.mongodbObjectId",schemaType:"string",minScore:0.9}],GQ=[{keywords:["abbreviation","tech_abbreviation"],fakerMethod:"hacker.abbreviation",schemaType:"string",minScore:0.9},{keywords:["hacker_phrase","tech_phrase"],fakerMethod:"hacker.phrase",schemaType:"string",minScore:0.9}],HQ=[{keywords:["adjective"],fakerMethod:"word.adjective",schemaType:"string",minScore:0.8},{keywords:["adverb"],fakerMethod:"word.adverb",schemaType:"string",minScore:0.8},{keywords:["noun"],fakerMethod:"word.noun",schemaType:"string",minScore:0.8},{keywords:["verb"],fakerMethod:"word.verb",schemaType:"string",minScore:0.8}],k=[...r,...h,...c,...s,...t,...a,...e,...QQ,...$Q,...BQ,...ZQ,...KQ,...XQ,...zQ,...qQ,...WQ,...UQ,...VQ,...YQ,...jQ,...FQ,...CQ,...GQ,...HQ];function u(Q){let $=Q.split(/[_-]/),B=[];for(let Z of $){if(!Z)continue;let K=Z.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z0-9])([A-Z])/g,"$1_$2").split("_");for(let X of K)if(X)B.push(X.toLowerCase())}return B}function wQ(Q,$){let B=Q.join(""),Z=0;for(let K of $){let X=u(K),W=X.join("");if(B===W)return 1;if(X.length>0&&X.every((z)=>Q.includes(z))){let q=X.length/Q.length>0.5?0.9:0.65;Z=Math.max(Z,q)}if(X.length>0&&X.length<=Q.length){if(Q.slice(-X.length).every((q,U)=>q===X[U]))Z=Math.max(Z,0.8)}if(W.length>=3&&B.includes(W))Z=Math.max(Z,0.7)}return Z}function S(Q,$,B=k){let Z=$,K=typeof $.type==="string"?$.type:void 0;if(K==="string"&&$.format==="uuid")return{mapping:{keywords:["uuid"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.5},score:1};if(Z.pattern||Z.enum||Z.faker||Z.$ref)return;let X=$.minimum!==void 0||$.maximum!==void 0||$.exclusiveMinimum!==void 0||$.exclusiveMaximum!==void 0,W=u(Q),z;for(let q of B){if(X&&(q.schemaType==="number"||q.schemaType==="integer"))continue;if(K==="object"||K==="array")continue;if(q.schemaType&&K&&q.schemaType!==K){if(!(q.schemaType==="number"&&K==="integer"||q.schemaType==="integer"&&K==="number"))continue}let U=wQ(W,q.keywords);if(U>=q.minScore&&(!z||U>z.score))z={mapping:q,score:U}}if(K==="string"){if(W[W.length-1]==="id"&&W.length>1){if(!z||z.score<0.8)z={mapping:{keywords:["id"],fakerMethod:"string.uuid",schemaType:"string",minScore:0.5},score:0.8}}}return z}import{ResourceLimitError as L,SchemaValidationError as Y}from"@schmock/core";var g;function V(Q){return typeof Q==="object"&&Q!==null&&!Array.isArray(Q)}function w(Q,$="$"){if(!Q||typeof Q!=="object")throw new Y($,"Schema must be a valid JSON Schema object");if(Object.keys(Q).length===0)throw new Y($,"Schema cannot be empty");let B=["object","array","string","number","integer","boolean","null"];if(Q.type&&typeof Q.type==="string"&&!B.includes(Q.type))throw new Y($,`Invalid schema type: "${Q.type}"`,"Supported types are: object, array, string, number, integer, boolean, null");if(Q.type==="object"&&Q.properties){if(typeof Q.properties!=="object"||Array.isArray(Q.properties))throw new Y(`${$}.properties`,"Properties must be an object mapping property names to schemas",'Use { "propertyName": { "type": "string" } } format');for(let[K,X]of Object.entries(Q.properties))if(typeof X==="object"&&X!==null){let W="faker"in X?String(X.faker):void 0;if(W)try{N(W)}catch(z){if(z instanceof Y){let q=z.context,U="Invalid faker method",F;if(q&&typeof q==="object"){if("issue"in q&&typeof q.issue==="string")U=q.issue;if("suggestion"in q&&typeof q.suggestion==="string")F=q.suggestion}throw new Y(`${$}.properties.${K}.faker`,U,F)}if(z instanceof Error)throw z;throw Error(String(z))}w(X,`${$}.properties.${K}`)}}if(Q.type==="array"){if(Q.items===null||Q.items===void 0)throw new Y(`${$}.items`,"Array schema must have valid items definition","Define items as a schema object or array of schemas");if(Array.isArray(Q.items)){if(Q.items.length===0)throw new Y(`${$}.items`,"Array items cannot be empty array","Provide at least one item schema");Q.items.forEach((K,X)=>{if(typeof K==="object"&&K!==null)w(K,`${$}.items[${X}]`)})}else if(typeof Q.items==="object"&&Q.items!==null)w(Q.items,`${$}.items`)}if(R(Q))throw new Y($,"Schema contains circular references which are not supported");let Z=O(Q);if(Z>M)throw new L("schema_nesting_depth",M,Z);if(Z>=H)JQ(Q,$);if(b(Q,$),Q.$ref==="#")throw new Y($,"Self-referencing schemas are not supported")}function R(Q,$=new Set){if($.has(Q))return!0;if(Q.$ref==="#")return!0;if($.add(Q),Q.type==="object"&&Q.properties){for(let B of Object.values(Q.properties))if(V(B)){if(R(B,$))return!0}}if(Q.type==="array"&&Q.items){let B=Array.isArray(Q.items)?Q.items:[Q.items];for(let Z of B)if(V(Z)){if(R(Z,$))return!0}}return $.delete(Q),!1}function O(Q,$=0){if($>M)return $;let B=$;if(Q.type==="object"&&Q.properties){for(let Z of Object.values(Q.properties))if(V(Z))B=Math.max(B,O(Z,$+1))}if(Q.type==="array"&&Q.items){let Z=Array.isArray(Q.items)?Q.items:[Q.items];for(let K of Z)if(V(K))B=Math.max(B,O(K,$+1))}return B}function JQ(Q,$){function B(Z,K){let X=Z.type;if(Array.isArray(X)?X.includes("array"):X==="array"){let z=Z.maxItems||C;if(K>=H&&z>=I)throw new L("deep_nesting_memory_risk",H*I,K*z);if(Z.items){let q=Array.isArray(Z.items)?Z.items:[Z.items];for(let U of q)if(V(U))B(U,K+1)}return}if(X==="object"&&Z.properties){for(let z of Object.values(Z.properties))if(V(z))B(z,K+1)}}B(Q,0)}function b(Q,$){if(Q.type==="array"){if(Q.maxItems&&Q.maxItems>G)throw new L("array_max_items",G,Q.maxItems);let B=O(Q),Z=Q.maxItems||Q.minItems||C;if(B>H&&Z>I)throw new L("memory_estimation",H*I,B*Z)}if(Q.type==="object"&&Q.properties){for(let[B,Z]of Object.entries(Q.properties))if(V(Z))b(Z,`${$}.properties.${B}`)}if(Q.type==="array"&&Q.items){if(Array.isArray(Q.items))Q.items.forEach((B,Z)=>{if(V(B))b(B,`${$}.items[${Z}]`)});else if(V(Q.items))b(Q.items,`${$}.items`)}}function N(Q){let $=Q.split(".");if($.length<2)throw new Y("$.faker",`Invalid faker method format: "${Q}"`,"Use format like 'person.firstName' or 'internet.email'");if(!g)g=D();let Z=g;for(let K of $)if(Z&&typeof Z==="object"&&K in Z)Z=Z[K];else throw new Y("$.faker",`Invalid faker method: "${Q}"`,"Check faker.js documentation for valid methods");if(typeof Z!=="function")throw new Y("$.faker",`Invalid faker method: "${Q}" is not a function`,"Check faker.js documentation for valid methods")}function j(Q){if(!Q||typeof Q!=="object")return Q;let $={...Q};if($.properties){$.properties={...$.properties};for(let[B,Z]of Object.entries($.properties))if(V(Z))$.properties[B]=IQ(B,Z)}for(let B of["allOf","anyOf","oneOf"]){let Z=$[B];if(Array.isArray(Z))$[B]=Z.map((K)=>V(K)?j(K):K)}if($.items){if(Array.isArray($.items))$.items=$.items.map((B)=>V(B)?j(B):B);else if(V($.items))$.items=j($.items)}if($.additionalProperties&&typeof $.additionalProperties==="object"&&!Array.isArray($.additionalProperties))$.additionalProperties=j($.additionalProperties);return $}function IQ(Q,$){let B={...$};if(B.faker)return N(B.faker),B;let Z=B.allOf||B.anyOf||B.oneOf;if(B.properties||Z||B.items){let X=j(B);Object.assign(B,X)}if(Z)return B;if(B.const!==void 0||B.enum)return B;let K=S(Q,B);if(K){if(B.faker=K.mapping.fakerMethod,K.mapping.format)B.format=K.mapping.format;if(K.mapping.trueProbability!==void 0)B.schmockTrueProbability=K.mapping.trueProbability}return B}function nQ(Q){return w(Q.schema),{name:"faker",version:"1.0.1",async process($,B){if(B!==void 0&&B!==null)return{context:$,response:B};try{let Z=await MQ({schema:Q.schema,count:Q.count,overrides:Q.overrides,params:$.params,state:$.routeState,query:$.query,seed:Q.seed});return{context:$,response:Z}}catch(Z){if(Z instanceof d||Z instanceof l)throw Z;throw new PQ($.path,Z instanceof Error?Z:Error(String(Z)),Q.schema)}}}}async function MQ(Q){let{schema:$,count:B,overrides:Z,params:K,state:X,query:W,seed:z}=Q;w($);let q;if($.type==="array"&&$.items){let U=y($,B);if(U>G)throw new l("array_size",G,U);let F=Array.isArray($.items)?$.items[0]:$.items;if(!F||typeof F==="boolean")throw new d("$.items","Array schema must have valid items definition");let f=j(F);q=[];for(let A=0;A<U;A++){let J=await _(f,z);J=x(J,f),J=P(J,Z,K,X,W),q.push(J)}}else{let U=j($);q=await _(U,z),q=x(q,U),q=P(q,Z,K,X,W)}return q}function x(Q,$){if(Q===null||Q===void 0||!$||typeof $!=="object")return Q;let B=$;if(B.schmockNullable===!0){if(Math.random()<T)return null}if($.type==="boolean"&&typeof B.schmockTrueProbability==="number")return Math.random()<B.schmockTrueProbability;if(typeof Q==="object"&&!Array.isArray(Q)&&$.properties){for(let[Z,K]of Object.entries($.properties))if(Z in Q&&V(K))Q[Z]=x(Q[Z],K)}if(Array.isArray(Q)&&$.items&&V($.items))for(let Z=0;Z<Q.length;Z++)Q[Z]=x(Q[Z],$.items);return Q}export{MQ as generateFromSchema,nQ as fakerPlugin};
|
package/dist/jsf-config.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Faker } from "@faker-js/faker";
|
|
2
|
-
import
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
3
|
/**
|
|
4
|
-
* Create isolated faker instance to avoid race conditions
|
|
5
|
-
* Each generation gets its own faker instance to ensure thread-safety
|
|
6
|
-
* @returns Fresh Faker instance with English locale
|
|
4
|
+
* Create isolated faker instance to avoid race conditions.
|
|
5
|
+
* Each generation gets its own faker instance to ensure thread-safety.
|
|
7
6
|
*/
|
|
8
7
|
export declare function createFakerInstance(seed?: number): Faker;
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Generate data from a JSON schema using json-schema-faker 0.6.0 async API.
|
|
10
|
+
* Stateless — each call is self-contained with its own faker instance and options.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateWithJsf(schema: JSONSchema7, seed?: number): Promise<unknown>;
|
|
10
13
|
//# sourceMappingURL=jsf-config.d.ts.map
|
package/dist/jsf-config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsf-config.d.ts","sourceRoot":"","sources":["../src/jsf-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"jsf-config.d.ts","sourceRoot":"","sources":["../src/jsf-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,CAAC,EAAE,MAAM,SAMhD;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,WAAW,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC,CAkBlB"}
|
package/dist/jsf-config.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { base, en, Faker } from "@faker-js/faker";
|
|
2
|
-
import
|
|
2
|
+
import { generate } from "json-schema-faker";
|
|
3
3
|
/**
|
|
4
|
-
* Create isolated faker instance to avoid race conditions
|
|
5
|
-
* Each generation gets its own faker instance to ensure thread-safety
|
|
6
|
-
* @returns Fresh Faker instance with English locale
|
|
4
|
+
* Create isolated faker instance to avoid race conditions.
|
|
5
|
+
* Each generation gets its own faker instance to ensure thread-safety.
|
|
7
6
|
*/
|
|
8
7
|
export function createFakerInstance(seed) {
|
|
9
8
|
const faker = new Faker({ locale: [en, base] });
|
|
@@ -12,44 +11,22 @@ export function createFakerInstance(seed) {
|
|
|
12
11
|
}
|
|
13
12
|
return faker;
|
|
14
13
|
}
|
|
15
|
-
let jsfConfigured = false;
|
|
16
|
-
let currentSeed;
|
|
17
14
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Generate data from a JSON schema using json-schema-faker 0.6.0 async API.
|
|
16
|
+
* Stateless — each call is self-contained with its own faker instance and options.
|
|
20
17
|
*/
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
jsf.extend("faker", () => createFakerInstance(seed));
|
|
36
|
-
jsf.option({
|
|
37
|
-
requiredOnly: false,
|
|
38
|
-
alwaysFakeOptionals: true,
|
|
39
|
-
useDefaultValue: true,
|
|
40
|
-
ignoreMissingRefs: true,
|
|
41
|
-
failOnInvalidTypes: false,
|
|
42
|
-
failOnInvalidFormat: false,
|
|
43
|
-
});
|
|
44
|
-
jsfConfigured = true;
|
|
45
|
-
}
|
|
46
|
-
// Always reset PRNG for deterministic output per call
|
|
47
|
-
if (seed !== undefined) {
|
|
48
|
-
jsf.option({ random: createSeededRandom(seed) });
|
|
49
|
-
jsf.extend("faker", () => createFakerInstance(seed));
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
jsf.option({ random: Math.random });
|
|
53
|
-
}
|
|
54
|
-
return jsf;
|
|
18
|
+
export async function generateWithJsf(schema, seed) {
|
|
19
|
+
// When no seed is specified, generate a random seed to ensure different
|
|
20
|
+
// results on each call. JSF 0.6.0 treats seed=undefined as deterministic.
|
|
21
|
+
const effectiveSeed = seed ?? Math.floor(Math.random() * 2147483647);
|
|
22
|
+
return generate(schema, {
|
|
23
|
+
seed: effectiveSeed,
|
|
24
|
+
optionalsProbability: 1.0,
|
|
25
|
+
alwaysFakeOptionals: true,
|
|
26
|
+
useDefaultValue: true,
|
|
27
|
+
ignoreMissingRefs: true,
|
|
28
|
+
failOnInvalidTypes: false,
|
|
29
|
+
failOnInvalidFormat: false,
|
|
30
|
+
extensions: { faker: createFakerInstance(seed) },
|
|
31
|
+
});
|
|
55
32
|
}
|
|
@@ -55,6 +55,10 @@ function enhanceFieldSchema(fieldName, fieldSchema) {
|
|
|
55
55
|
if (hasComposition) {
|
|
56
56
|
return enhanced;
|
|
57
57
|
}
|
|
58
|
+
// Don't apply smart mapping when const or enum is defined — these have fixed values
|
|
59
|
+
if (enhanced.const !== undefined || enhanced.enum) {
|
|
60
|
+
return enhanced;
|
|
61
|
+
}
|
|
58
62
|
// Apply smart field name mapping via the scoring matcher
|
|
59
63
|
const match = findBestMapping(fieldName, enhanced);
|
|
60
64
|
if (match) {
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -41,17 +41,17 @@ export declare const performance: {
|
|
|
41
41
|
}>;
|
|
42
42
|
};
|
|
43
43
|
export declare const generate: {
|
|
44
|
-
samples: <T>(schema: JSONSchema7, count?: number, options?: any) => T[]
|
|
45
|
-
withSeed: (schema: JSONSchema7, _seed?: number) => any
|
|
44
|
+
samples: <T>(schema: JSONSchema7, count?: number, options?: any) => Promise<T[]>;
|
|
45
|
+
withSeed: (schema: JSONSchema7, _seed?: number) => Promise<any>;
|
|
46
46
|
};
|
|
47
47
|
export declare const stats: {
|
|
48
48
|
distribution: (samples: any[]) => Map<any, number>;
|
|
49
49
|
entropy: (samples: any[]) => number;
|
|
50
50
|
};
|
|
51
51
|
export declare const schemaTests: {
|
|
52
|
-
expectValid: (schema: JSONSchema7) => void
|
|
53
|
-
expectInvalid: (schema: any, errorMessage?: string | RegExp) => void
|
|
54
|
-
expectSchemaError: (schema: any, path: string, issue?: string) => void
|
|
52
|
+
expectValid: (schema: JSONSchema7) => Promise<void>;
|
|
53
|
+
expectInvalid: (schema: any, errorMessage?: string | RegExp) => Promise<void>;
|
|
54
|
+
expectSchemaError: (schema: any, path: string, issue?: string) => Promise<void>;
|
|
55
55
|
};
|
|
56
56
|
export {};
|
|
57
57
|
//# sourceMappingURL=test-utils.d.ts.map
|
package/dist/test-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,UAAU,WAAY,SAAQ,WAAW;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,OAAO;;sBAEJ,WAAW;sBAIX,WAAW;8BAIF,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAQ,WAAW;uBAM1D,WAAW,gBACJ;YAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,KACrD,WAAW;;sBAOE,WAAW,CAAC,MAAM,CAAC,eAAe,MAAM,KAAG,WAAW;;sBAO7D,MAAM,eACD,WAAW,KACtB,WAAW;sBAWL,MAAM,mBACG,WAAW,KAC1B,WAAW;;;oBASJ,WAAW;2BAYJ,WAAW;;CAkB/B,CAAC;AAGF,eAAO,MAAM,UAAU;+BAGR,MAAM,cACN,WAAW,CAAC,MAAM,CAAC,KAC7B,OAAO,CAAC,OAAO,CAAC;+
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,UAAU,WAAY,SAAQ,WAAW;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,OAAO;;sBAEJ,WAAW;sBAIX,WAAW;8BAIF,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,KAAQ,WAAW;uBAM1D,WAAW,gBACJ;YAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,KACrD,WAAW;;sBAOE,WAAW,CAAC,MAAM,CAAC,eAAe,MAAM,KAAG,WAAW;;sBAO7D,MAAM,eACD,WAAW,KACtB,WAAW;sBAWL,MAAM,mBACG,WAAW,KAC1B,WAAW;;;oBASJ,WAAW;2BAYJ,WAAW;;CAkB/B,CAAC;AAGF,eAAO,MAAM,UAAU;+BAGR,MAAM,cACN,WAAW,CAAC,MAAM,CAAC,KAC7B,OAAO,CAAC,OAAO,CAAC;+BAqCQ,GAAG,EAAE,KAAG,MAAM;wBAMrB,GAAG,EAAE,aAAa,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,KAAG,OAAO;uCAM7D,MAAM,EAAE,YACP,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,KACjE,OAAO;CAgDX,CAAC;AAGF,eAAO,MAAM,WAAW;cACN,CAAC,MACX,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KACvB,OAAO,CAAC;QAAE,MAAM,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;wBAOvB,MAAM,IAAI,KAAG,MAAM;uBAW9B,MAAM,MACT,MAAM,GAAG,0BAEZ,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAgBvD,CAAC;AAGF,eAAO,MAAM,QAAQ;cACH,CAAC,UACP,WAAW,4BAET,GAAG,KACZ,OAAO,CAAC,CAAC,EAAE,CAAC;uBAQU,WAAW,UAAU,MAAM,KAAG,OAAO,CAAC,GAAG,CAAC;CAKpE,CAAC;AAGF,eAAO,MAAM,KAAK;4BACQ,GAAG,EAAE,KAAG,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC;uBAS7B,GAAG,EAAE,KAAG,MAAM;CAclC,CAAC;AAGF,eAAO,MAAM,WAAW;0BACM,WAAW,KAAG,OAAO,CAAC,IAAI,CAAC;4BAK7C,GAAG,iBACI,MAAM,GAAG,MAAM,KAC7B,OAAO,CAAC,IAAI,CAAC;gCAWN,GAAG,QACL,MAAM,UACJ,MAAM,KACb,OAAO,CAAC,IAAI,CAAC;CAejB,CAAC"}
|
package/dist/test-utils.js
CHANGED
|
@@ -87,8 +87,16 @@ export const validators = {
|
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
// Generate multiple samples to check for patterns
|
|
90
|
-
const mappedSamples =
|
|
91
|
-
|
|
90
|
+
const mappedSamples = [];
|
|
91
|
+
for (let i = 0; i < 10; i++) {
|
|
92
|
+
const result = await generateFromSchema({ schema: mappedSchema });
|
|
93
|
+
mappedSamples.push(result[fieldName]);
|
|
94
|
+
}
|
|
95
|
+
const unmappedSamples = [];
|
|
96
|
+
for (let i = 0; i < 10; i++) {
|
|
97
|
+
const result = await generateFromSchema({ schema: unmappedSchema });
|
|
98
|
+
unmappedSamples.push(result.unmappedRandomField12345);
|
|
99
|
+
}
|
|
92
100
|
// If field is mapped to a specific faker method, it should have different characteristics
|
|
93
101
|
// than the generic unmapped field
|
|
94
102
|
return (analyzeDataCharacteristics(mappedSamples) !==
|
|
@@ -164,13 +172,17 @@ export const performance = {
|
|
|
164
172
|
};
|
|
165
173
|
// Test Data Generators
|
|
166
174
|
export const generate = {
|
|
167
|
-
samples: (schema, count = 10, options) => {
|
|
168
|
-
|
|
175
|
+
samples: async (schema, count = 10, options) => {
|
|
176
|
+
const results = [];
|
|
177
|
+
for (let i = 0; i < count; i++) {
|
|
178
|
+
results.push(await generateFromSchema({ schema, ...options }));
|
|
179
|
+
}
|
|
180
|
+
return results;
|
|
169
181
|
},
|
|
170
|
-
withSeed: (schema, _seed) => {
|
|
182
|
+
withSeed: async (schema, _seed) => {
|
|
171
183
|
// Note: faker.js doesn't support seeding in the same way,
|
|
172
184
|
// but we can at least ensure consistent test behavior
|
|
173
|
-
return generateFromSchema({ schema });
|
|
185
|
+
return await generateFromSchema({ schema });
|
|
174
186
|
},
|
|
175
187
|
};
|
|
176
188
|
// Statistical Analysis
|
|
@@ -198,20 +210,20 @@ export const stats = {
|
|
|
198
210
|
};
|
|
199
211
|
// Schema Validation Test Helpers
|
|
200
212
|
export const schemaTests = {
|
|
201
|
-
expectValid: (schema) => {
|
|
202
|
-
expect(
|
|
213
|
+
expectValid: async (schema) => {
|
|
214
|
+
await expect(generateFromSchema({ schema })).resolves.not.toThrow();
|
|
203
215
|
},
|
|
204
|
-
expectInvalid: (schema, errorMessage) => {
|
|
216
|
+
expectInvalid: async (schema, errorMessage) => {
|
|
205
217
|
if (errorMessage) {
|
|
206
|
-
expect(
|
|
218
|
+
await expect(generateFromSchema({ schema })).rejects.toThrow(errorMessage);
|
|
207
219
|
}
|
|
208
220
|
else {
|
|
209
|
-
expect(
|
|
221
|
+
await expect(generateFromSchema({ schema })).rejects.toThrow();
|
|
210
222
|
}
|
|
211
223
|
},
|
|
212
|
-
expectSchemaError: (schema, path, issue) => {
|
|
224
|
+
expectSchemaError: async (schema, path, issue) => {
|
|
213
225
|
try {
|
|
214
|
-
generateFromSchema({ schema });
|
|
226
|
+
await generateFromSchema({ schema });
|
|
215
227
|
throw new Error("Expected schema validation to fail");
|
|
216
228
|
}
|
|
217
229
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schmock/faker",
|
|
3
3
|
"description": "Faker-powered automatic data generation for Schmock",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@faker-js/faker": "^10.4.0",
|
|
34
|
-
"json-schema-faker": "^0.
|
|
34
|
+
"json-schema-faker": "^0.6.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@schmock/core": "^
|
|
37
|
+
"@schmock/core": "^2.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@amiceli/vitest-cucumber": "^6.3.0",
|
|
41
41
|
"@types/json-schema": "^7.0.15",
|
|
42
42
|
"@types/node": "^25.5.0",
|
|
43
|
-
"vitest": "^4.1.
|
|
43
|
+
"vitest": "^4.1.2"
|
|
44
44
|
}
|
|
45
45
|
}
|