Result

JTC.convert call will return result as an object which contains converted / origin data and information about conversion process.

class User {
   public id: number;
   public name: string;
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      id: new NumberField(),
      name: new StringField(),
   }
});

const users = [
   { id: 1, name: `Vasya` },
   { id: `2`, name: 132 },
   null,
   { id: 3, name: `Petya` },
   { id: `3`, name: `Masha` },
];

const result = JTC.convert({
   id: `Users`,
   meta: new ObjectArrayMeta({ meta: USER_META }),
   values: users,
});


console.log(result);

// Array of all converted objects
console.log(result.converted.all);
// Array of converted objects, where all fields passed validation
console.log(result.converted.valid);
// Array of converted objects, where one or more fields failed to validation
console.log(result.converted.corrupted);
// Boolean that will be 'true' if validation failed for one or more fields
console.log(result.isCorrupted);
// Info about convertation, which can be used to build log with "JTC.log.asString"  and "JTC.logToConsole"
console.log(result.tree);
// Array of initial values, same as provided in "values"
console.log(result.origin.all);
// Array of initial values, where one or more field validation failed
console.log(result.origin.corrupted);
// Array of initial values, which didn't match any expected meta
console.log(result.origin.excluded);

Last updated

Was this helpful?