@intelligo.ai/object-to-schema
Advanced tools
Comparing version 2.0.3 to 2.0.4
{ | ||
"person": { | ||
"name": { "mname": "MNAME" }, | ||
"dateOfBirth": "10/14/88", | ||
"dateOfBirth": "1/1/66", | ||
"dateOfDeath": "10/14/2026", | ||
"positions": { | ||
@@ -9,2 +10,3 @@ "pastPositions": ["a", "b", "c", "d"], | ||
}, | ||
"nicknames": ["john, johnny, john-boy, bigJ", "bbj", "mj"], | ||
"addes": [{ "street": "s1", "house": "h1" }, { "street": "s2", "house": "h2" }], | ||
@@ -11,0 +13,0 @@ "addesB": [ |
@@ -14,3 +14,5 @@ { | ||
"path": "dob", | ||
"predefinedTransformations": ["toDate"] | ||
"predefinedTransformations": [ | ||
"toDate" | ||
] | ||
} | ||
@@ -32,10 +34,35 @@ }, | ||
"path": "jobs.lastPositions", | ||
"predefinedTransformations": ["titleCase"] | ||
"predefinedTransformations": [ | ||
{ | ||
"transformation": "titleCase" | ||
}, | ||
{ | ||
"transformation": "arrayToString", | ||
"transformationArgs": ", " | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"source": "person.nicknames", | ||
"target": { | ||
"path": "names.nicknames", | ||
"predefinedTransformations": [ | ||
{ | ||
"transformation": "stringToArray", | ||
"transformationArgs": ", " | ||
}, | ||
{ | ||
"transformation": "titleCase" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"source": "person.positions.currentPosition", | ||
"target": { | ||
"path": "jobs.currentPosition", | ||
"predefinedTransformations": ["titleCase"] | ||
"predefinedTransformations": [ | ||
"titleCase" | ||
] | ||
} | ||
@@ -65,3 +92,5 @@ }, | ||
"path": "addresses[].streetAddress", | ||
"predefinedTransformations": ["titleCase"] | ||
"predefinedTransformations": [ | ||
"titleCase" | ||
] | ||
} | ||
@@ -86,4 +115,28 @@ }, | ||
} | ||
}, | ||
{ | ||
"source": "person.dateOfBirth", | ||
"target": { | ||
"path": "d.Dates[]" | ||
} | ||
}, | ||
{ | ||
"source": "person.dateOfDeath", | ||
"target": { | ||
"path": "d.Dates[]" | ||
} | ||
}, | ||
{ | ||
"source": "person.dateOfBirth", | ||
"target": { | ||
"path": "dates[].dob" | ||
} | ||
}, | ||
{ | ||
"source": "person.dateOfDeath", | ||
"target": { | ||
"path": "dates[].dod" | ||
} | ||
} | ||
] | ||
} |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -12,3 +28,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var _b; | ||
var key = _a[0], value = _a[1]; | ||
var _c = __read(_a, 2), key = _c[0], value = _c[1]; | ||
return ramda_1.default.mergeDeepLeft(example, (_b = {}, _b[key] = cases(value), _b)); | ||
@@ -15,0 +31,0 @@ }, {}); |
@@ -9,2 +9,460 @@ "use strict"; | ||
exports.extractExampleFromSchema = exampleRecordExtractor_1.extractExampleFromSchema; | ||
var aa = { | ||
"evictionId": 1836030810467466240.0, | ||
"bridge": null, | ||
"defendantNames": [ | ||
{ | ||
"isBusiness": false, | ||
"tahoeId": "G-575692654799887454", | ||
"ssn": "099-66-2500", | ||
"prefix": "", | ||
"firstName": "MATTHEW", | ||
"middleName": "", | ||
"lastName": "ROSENBLUM", | ||
"suffix": "", | ||
"gender": "M", | ||
"nameHash": 5682392457680976900.0, | ||
"addressHashOpt9": 3396533295236144100.0, | ||
"fullName": "MATTHEW ROSENBLUM", | ||
"address": { | ||
"addressType": "Defendant Address", | ||
"addressHashOpt9": 3396533295236144100.0, | ||
"houseNumber": "36", | ||
"streetDirection": "E", | ||
"streetName": "64th", | ||
"streetType": "ST", | ||
"streetPostDirection": "", | ||
"unitType": "", | ||
"unitNumber": "", | ||
"city": "New York", | ||
"county": "", | ||
"state": "NY", | ||
"zipCode": "10065", | ||
"zip4": "7371", | ||
"longitude": "", | ||
"latitude": "", | ||
"fipsCode": "", | ||
"verificationCodes": [ | ||
"AC01", | ||
"AE09", | ||
"AS02" | ||
], | ||
"fullAddress": "36 E 64th ST; New York, NY 10065-7371" | ||
}, | ||
"partyType": "Defendant" | ||
}, | ||
{ | ||
"isBusiness": false, | ||
"tahoeId": "G-575692654799887454", | ||
"ssn": "099-66-2500", | ||
"prefix": "", | ||
"firstName": "MATTHEW", | ||
"middleName": "", | ||
"lastName": "ROSENBLUM", | ||
"suffix": "", | ||
"gender": "M3", | ||
"nameHash": 5682392457680976900.0, | ||
"addressHashOpt9": 3396533295236144100.0, | ||
"fullName": "MATTHEW ROSENBLUM3", | ||
"address": { | ||
"addressType": "Defendant Address", | ||
"addressHashOpt9": 3396533295236144100.0, | ||
"houseNumber": "36", | ||
"streetDirection": "E", | ||
"streetName": "64th", | ||
"streetType": "ST", | ||
"streetPostDirection": "", | ||
"unitType": "", | ||
"unitNumber": "", | ||
"city": "New York", | ||
"county": "", | ||
"state": "NY", | ||
"zipCode": "10065", | ||
"zip4": "7371", | ||
"longitude": "", | ||
"latitude": "", | ||
"fipsCode": "", | ||
"verificationCodes": [ | ||
"AC01", | ||
"AE09", | ||
"AS02" | ||
], | ||
"fullAddress": "36 E 64th ST; New York, NY 10065-7371" | ||
}, | ||
"partyType": "Defendant" | ||
} | ||
], | ||
"plaintiffNames": [ | ||
{ | ||
"isOwner": true, | ||
"tahoeId": null, | ||
"ssn": null, | ||
"prefix": "", | ||
"firstName": "", | ||
"middleName": "", | ||
"lastName": "OKADA DENKI SAN LTD", | ||
"suffix": "", | ||
"gender": "N", | ||
"nameHash": 1020963256723863680.0, | ||
"fullName": "OKADA DENKI SAN LTD", | ||
"partyType": "Defendant" | ||
} | ||
], | ||
"addresses": [ | ||
{ | ||
"addressType": "Court Address", | ||
"addressHashOpt9": -5893356457424657400.0, | ||
"houseNumber": "111", | ||
"streetDirection": "", | ||
"streetName": "Centre", | ||
"streetType": "ST", | ||
"streetPostDirection": "", | ||
"unitType": "Rm", | ||
"unitNumber": "118", | ||
"city": "New York", | ||
"county": "New York", | ||
"state": "NY", | ||
"zipCode": "10013", | ||
"zip4": "4390", | ||
"longitude": "", | ||
"latitude": "", | ||
"fipsCode": "", | ||
"verificationCodes": [ | ||
"AC03", | ||
"AE08", | ||
"AS02" | ||
], | ||
"fullAddress": "111 Centre ST, Rm 118; New York, NY 10013-4390" | ||
}, | ||
{ | ||
"addressType": "Defendant Address", | ||
"addressHashOpt9": 3396533295236144100.0, | ||
"houseNumber": "36", | ||
"streetDirection": "E", | ||
"streetName": "64th", | ||
"streetType": "ST", | ||
"streetPostDirection": "", | ||
"unitType": "", | ||
"unitNumber": "", | ||
"city": "New York", | ||
"county": "", | ||
"state": "NY", | ||
"zipCode": "10065", | ||
"zip4": "7371", | ||
"longitude": "", | ||
"latitude": "", | ||
"fipsCode": "", | ||
"verificationCodes": [ | ||
"AC01", | ||
"AE09", | ||
"AS02" | ||
], | ||
"fullAddress": "36 E 64th ST; New York, NY 10065-7371" | ||
} | ||
], | ||
"courts": [ | ||
{ | ||
"type": "court", | ||
"addressHashOpt9": -5893356457424657400.0, | ||
"courtId": "NYNEWL1", | ||
"courtName": "Civil Court of the City of New York", | ||
"courtPhoneOne": "6463865700", | ||
"courtPhoneOneExtension": null, | ||
"courtPhoneTwo": "6463865730", | ||
"fax": "2123748053", | ||
"courtUrl": "http://www.courts.state.ny.us/courts/1jd/index.shtml", | ||
"address": { | ||
"addressType": "Court Address", | ||
"addressHashOpt9": -5893356457424657400.0, | ||
"houseNumber": "111", | ||
"streetDirection": "", | ||
"streetName": "Centre", | ||
"streetType": "ST", | ||
"streetPostDirection": "", | ||
"unitType": "Rm", | ||
"unitNumber": "118", | ||
"city": "New York", | ||
"county": "New York", | ||
"state": "NY", | ||
"zipCode": "10013", | ||
"zip4": "4390", | ||
"longitude": "", | ||
"latitude": "", | ||
"fipsCode": "", | ||
"verificationCodes": [ | ||
"AC03", | ||
"AE08", | ||
"AS02" | ||
], | ||
"fullAddress": "111 Centre ST, Rm 118; New York, NY 10013-4390" | ||
} | ||
} | ||
], | ||
"evictionDetails": [ | ||
{ | ||
"courtId": "NYNEWL1", | ||
"caseNumber": "20050071276", | ||
"fileDate": "20050516", | ||
"liabilityAmount": "000045000", | ||
"reportDate": "20060824", | ||
"fileType": "BN", | ||
"state": "NY", | ||
"unlawfulDetainer": "Y", | ||
"assetsInDollar": "000000000", | ||
"updateDate": "" | ||
} | ||
] | ||
}; | ||
var a = mapper_1.mapObject(aa, [ | ||
{ | ||
"source": "defendantNames[].ssn", | ||
"target": { | ||
"path": "party[].identificationCard.number", | ||
"predefinedTransformations": [], | ||
}, | ||
}, | ||
{ | ||
"source": "defendantNames[].default", | ||
"target": { | ||
"path": "party[].identificationCard.type", | ||
"defaultValue": "SSN", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].firstName", | ||
"target": { | ||
"path": "party[].name.firstName", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].lastName", | ||
"target": { | ||
"path": "party[].name.lastName", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].gender", | ||
"target": { | ||
"path": "party[].sex", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].fullName", | ||
"target": { | ||
"path": "party[].name.full", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].partyType", | ||
"target": { | ||
"path": "party[].type", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.houseNumber", | ||
"target": { | ||
"path": "party[].address.poBox", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.streetName", | ||
"target": { | ||
"path": "party[].address.street1", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.streetType", | ||
"target": { | ||
"path": "party[].address.street2", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.unitNumber", | ||
"target": { | ||
"path": "party[].address.apartment", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.city", | ||
"target": { | ||
"path": "party[].address.city", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.state", | ||
"target": { | ||
"path": "party[].address.state", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.zipCode", | ||
"target": { | ||
"path": "party[].address.zip", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.zip4", | ||
"target": { | ||
"path": "party[].address.zipExtension", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.fullAddress", | ||
"target": { | ||
"path": "party[].address.full", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.longitude", | ||
"target": { | ||
"path": "party[].address.longtitude", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "defendantNames[].address.latitude", | ||
"target": { | ||
"path": "party[].address.latitude", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "xplaintiffNames[].firstName", | ||
"target": { | ||
"path": "party[].name.firstName", | ||
"predefinedTransformations": [], | ||
} | ||
}, | ||
{ | ||
"source": "xplaintiffNames[].lastName", | ||
"target": { | ||
"path": "party[].name.lastName", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "xplaintiffNames[].gender", | ||
"target": { | ||
"path": "party[].sex", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "xplaintiffNames[].fullName", | ||
"target": { | ||
"path": "party[].name.full", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "xplaintiffNames[].partyType", | ||
"target": { | ||
"path": "party[].type", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "courts.0.courtName", | ||
"target": { | ||
"path": "courtName", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "courts.0.courtName", | ||
"target": { | ||
"path": "legalSource.name", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "courts.0.courtUrl", | ||
"target": { | ||
"path": "legalSource.link", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "courts.0.address.county", | ||
"target": { | ||
"path": "legalSource.county", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "courts.0.address.state", | ||
"target": { | ||
"path": "legalSource.state", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "evictionDetails.0.caseNumber", | ||
"target": { | ||
"path": "caseNum", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "evictionDetails.0.fileDate", | ||
"target": { | ||
"path": "filingDate", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "evictionDetails.0.liabilityAmount", | ||
"target": { | ||
"path": "lawsuitAmount", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "evictionDetails.0.reportDate", | ||
"target": { | ||
"path": "legalSource.publicationDate", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "default", | ||
"target": { | ||
"path": "caseCategory", | ||
"defaultValue": "UNLAWFUL_DETAINER", | ||
"predefinedTransformations": [] | ||
} | ||
}, | ||
{ | ||
"source": "default", | ||
"target": { | ||
"path": "caseType", | ||
"defaultValue": "CIVIL", | ||
"predefinedTransformations": [] | ||
}, | ||
}, | ||
{ | ||
"source": "default", | ||
"target": { | ||
"path": "courtType", | ||
"defaultValue": "COUNTY", | ||
"predefinedTransformations": [] | ||
}, | ||
} | ||
]); | ||
console.log(JSON.stringify(a, null, 2)); | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,18 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -24,2 +40,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var transform_1 = require("./utils/transform"); | ||
var predefinedTransformations_1 = require("./utils/predefinedTransformations"); | ||
function mapObject(originalObj, transformations) { | ||
@@ -37,3 +54,3 @@ if (!transformations || transformations.length == 0) { | ||
var extractionTree = buildTree(transformations); | ||
var _a = ramda_1.default.partition(isTargetValue(), Object.entries(extractionTree)), treeEntries = _a[0], treeLeafs = _a[1]; | ||
var _a = __read(ramda_1.default.partition(isTargetValue(), Object.entries(extractionTree)), 2), treeEntries = _a[0], treeLeafs = _a[1]; | ||
treatLeafsMutation(originalObj, treeLeafs, targetObject); | ||
@@ -45,4 +62,7 @@ treatTreeMutation(originalObj, treeEntries, transformations, targetObject); | ||
treeEntries.forEach(function (_a) { | ||
var source = _a[0], _ = _a[1]; | ||
var _b = __read(_a, 2), source = _b[0], _ = _b[1]; | ||
var arrayValuesToSet = object_path_1.default.get(originalObj, source); | ||
if (!arrayValuesToSet) { | ||
return; | ||
} | ||
var nextTargets = getSubTransformations(transformations, source); | ||
@@ -57,25 +77,15 @@ nextTargets.forEach(function (_a) { | ||
} | ||
var toLowerCase = transform_1.applyToOneOrMany(function (str) { return str.toLowerCase(); }); | ||
var toUpperCase = transform_1.applyToOneOrMany(function (str) { return str.toUpperCase(); }); | ||
var titleCase = transform_1.applyToOneOrMany(function (str) { return str | ||
.split(/\s/) | ||
.map(function (word) { return "" + word[0].toUpperCase() + word.slice(1); }) | ||
.join(' '); }); | ||
var toDate = transform_1.applyToOneOrMany(function (str) { return new Date(str); }); | ||
var strategies = { | ||
predefinedTransformations: { | ||
toUpperCase: function (str) { return toUpperCase(str); }, | ||
toLowerCase: function (str) { return toLowerCase(str); }, | ||
titleCase: function (str) { return titleCase(str); }, | ||
toDate: function (str) { return toDate(str); }, | ||
} | ||
}; | ||
function chooseHighestPriorityTransform(originalObj) { | ||
function chooseHighestPriorityTransforms(originalObj) { | ||
return function withObject(transforms) { | ||
if (transforms.every(function (transform) { return transform.target.path.includes('[]'); })) { | ||
return transforms; | ||
} | ||
var transformGenerator = transform_1.generateTransform(transforms); | ||
var transform = transformGenerator.next(); | ||
while (!transform.done && !object_path_1.default.has(originalObj, stringUtil_1.unUnidotify(transform.value.source)) && !transform.value.target.defaultValue) { | ||
while (!transform.done | ||
&& !object_path_1.default.has(originalObj, stringUtil_1.unUnidotify(transform.value.source)) | ||
&& !transform.value.target.defaultValue) { | ||
transform = transformGenerator.next(); | ||
} | ||
return transform.done ? null : transform.value; | ||
return transform.done ? [] : [transform.value]; | ||
}; | ||
@@ -88,3 +98,3 @@ } | ||
.map(function (_a) { | ||
var path = _a[0], transforms = _a[1]; | ||
var _b = __read(_a, 2), path = _b[0], transforms = _b[1]; | ||
return [path, transforms.map(function (transform) { return transform.target; })]; | ||
@@ -99,15 +109,15 @@ }); | ||
.map(function (_a) { | ||
var path = _a[0], transforms = _a[1]; | ||
var _b = __read(_a, 2), path = _b[0], transforms = _b[1]; | ||
return [ | ||
path, | ||
chooseHighestPriorityTransform(originalObj)(transform_1.sortTransformsByPriority(transforms)) | ||
chooseHighestPriorityTransforms(originalObj)(transform_1.sortTransformsByPriority(transforms)) | ||
]; | ||
}) | ||
.filter(function (_a) { | ||
var _ = _a[0], transforms = _a[1]; | ||
return transforms != null; | ||
var _b = __read(_a, 2), _ = _b[0], transforms = _b[1]; | ||
return transforms.length; | ||
}) | ||
.map(function (_a) { | ||
var _ = _a[0], transform = _a[1]; | ||
return transform; | ||
.flatMap(function (_a) { | ||
var _b = __read(_a, 2), _ = _b[0], transforms = _b[1]; | ||
return transforms.map(generalUtil_1.identity); | ||
}); | ||
@@ -120,4 +130,5 @@ var priorityTreeLeafs = transformsToTreeLeafs(highestPriorityTransforms); | ||
priorityTreeLeafs.forEach(function (_a) { | ||
var source = _a[0], mappingsArray = _a[1]; | ||
var _b = __read(_a, 2), source = _b[0], mappingsArray = _b[1]; | ||
mappingsArray.forEach(function (target) { | ||
var _a; | ||
var valueToSet = object_path_1.default.get(originalObj, stringUtil_1.unUnidotify(source)) || target.defaultValue || null; | ||
@@ -127,8 +138,15 @@ if (target.predefinedTransformations) { | ||
.predefinedTransformations | ||
.reduce(function (finalValue, transformationName) { | ||
return (strategies.predefinedTransformations[transformationName] || generalUtil_1.identity)(finalValue); | ||
.reduceRight(function (finalValue, predefinedTransformation) { | ||
var _a, _b, _c, _d; | ||
var transformationName = (_a = predefinedTransformation) === null || _a === void 0 ? void 0 : _a.transformation; | ||
var transformationArgs = (_c = (_b = predefinedTransformation) === null || _b === void 0 ? void 0 : _b.transformationArgs, (_c !== null && _c !== void 0 ? _c : undefined)); | ||
return (_d = predefinedTransformations_1.strategies.predefinedTransformations[transformationName], (_d !== null && _d !== void 0 ? _d : generalUtil_1.identity))(finalValue, transformationArgs); | ||
}, valueToSet); | ||
} | ||
if (target.path.includes('[]')) { | ||
object_path_1.default.push(targetObject, target.path.split('[]')[0], valueToSet); | ||
var splitTargetByArray = target.path.split('[]'); | ||
var valueToPush = ramda_1.default.isEmpty(splitTargetByArray[1]) | ||
? valueToSet | ||
: (_a = {}, _a[splitTargetByArray[1].slice(1)] = valueToSet, _a); | ||
object_path_1.default.push(targetObject, splitTargetByArray[0], valueToPush); | ||
} | ||
@@ -161,3 +179,3 @@ else { | ||
.map(function (_a) { | ||
var superTarget = _a[0], value = _a[1]; | ||
var _b = __read(_a, 2), superTarget = _b[0], value = _b[1]; | ||
return ({ | ||
@@ -171,3 +189,3 @@ superTarget: superTarget, | ||
return function (_a) { | ||
var _ = _a[0], value = _a[1]; | ||
var _b = __read(_a, 2), _ = _b[0], value = _b[1]; | ||
return !Array.isArray(value); | ||
@@ -182,3 +200,3 @@ }; | ||
var _b; | ||
var key = _a[0], value = _a[1]; | ||
var _c = __read(_a, 2), key = _c[0], value = _c[1]; | ||
return (__assign(__assign({}, acc), (_b = {}, | ||
@@ -196,3 +214,3 @@ _b[key] = buildTree(value.map(function (transform) { return ({ | ||
function groupExtractionsByPath(transformations) { | ||
var _a = ramda_1.default.partition(function (transform) { return transform.source.includes('[]'); }, transformations), furtherProcessing = _a[0], noProcessing = _a[1]; | ||
var _a = __read(ramda_1.default.partition(function (transform) { return transform.source.includes('[]'); }, transformations), 2), furtherProcessing = _a[0], noProcessing = _a[1]; | ||
return { | ||
@@ -199,0 +217,0 @@ group: groupBySourcePrefix()(furtherProcessing), |
@@ -71,3 +71,3 @@ "use strict"; | ||
else { | ||
var type = generalUtil_1.resolveType(nestedValue); | ||
var type = generalUtil_1.resolveType(nestedValue[0]); | ||
return [ | ||
@@ -74,0 +74,0 @@ JSON.stringify({ |
import { Transform, SomeObj, TreeLeaf } from './types'; | ||
export declare function generateTransform(transforms: Transform[]): Iterator<Transform>; | ||
export declare function applyToOneOrMany<P, A>(fn: (oneOrMany: P) => A): (oneOrMany: P | P[]) => A | A[]; | ||
export declare function applyToOneOrMany<P, A>(fn: (oneOrMany: P, args?: string | string[]) => A): (oneOrMany: P | P[], args?: string | string[] | undefined) => A | A[]; | ||
export declare function assignSchema(schema: SomeObj, key: string, value: any): SomeObj & { | ||
@@ -5,0 +5,0 @@ [x: string]: any; |
@@ -29,2 +29,29 @@ "use strict"; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -37,19 +64,32 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
function generateTransform(transforms) { | ||
var _i, transforms_1, transform; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var transforms_1, transforms_1_1, transform, e_1_1; | ||
var e_1, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_i = 0, transforms_1 = transforms; | ||
_a.label = 1; | ||
_b.trys.push([0, 5, 6, 7]); | ||
transforms_1 = __values(transforms), transforms_1_1 = transforms_1.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < transforms_1.length)) return [3, 4]; | ||
transform = transforms_1[_i]; | ||
if (!!transforms_1_1.done) return [3, 4]; | ||
transform = transforms_1_1.value; | ||
return [4, transform]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
_b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
_i++; | ||
transforms_1_1 = transforms_1.next(); | ||
return [3, 1]; | ||
case 4: return [2]; | ||
case 4: return [3, 7]; | ||
case 5: | ||
e_1_1 = _b.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3, 7]; | ||
case 6: | ||
try { | ||
if (transforms_1_1 && !transforms_1_1.done && (_a = transforms_1.return)) _a.call(transforms_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
return [7]; | ||
case 7: return [2]; | ||
} | ||
@@ -60,6 +100,6 @@ }); | ||
function applyToOneOrMany(fn) { | ||
return function withFunction(oneOrMany) { | ||
return function withFunction(oneOrMany, args) { | ||
return Array.isArray(oneOrMany) | ||
? oneOrMany.map(fn) | ||
: fn(oneOrMany); | ||
? oneOrMany.flatMap(function (one) { return fn(one, args); }) | ||
: fn(oneOrMany, args); | ||
}; | ||
@@ -75,3 +115,3 @@ } | ||
var transforms = treeLeafs.flatMap(function (_a) { | ||
var path = _a[0], targets = _a[1]; | ||
var _b = __read(_a, 2), path = _b[0], targets = _b[1]; | ||
return targets.map(function (target) { return ({ source: path, target: target }); }); | ||
@@ -78,0 +118,0 @@ }); |
@@ -7,3 +7,6 @@ declare type SomeObj = { | ||
}; | ||
declare type PredefinedTransformation = 'toUpperCase' | 'toLowerCase' | 'titleCase' | 'toDate'; | ||
interface PredefinedTransformation { | ||
transformationArgs?: any; | ||
transformation: 'toUpperCase' | 'toLowerCase' | 'titleCase' | 'toDate' | 'stringToArray' | 'arrayToString' | 'fromTracerDate'; | ||
} | ||
declare type TreeLeaf = [string, Transform['target'][]]; | ||
@@ -10,0 +13,0 @@ declare type Transform = { |
{ | ||
"name": "@intelligo.ai/object-to-schema", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
361368
60
7078
0