Corruption

In case when values provided in JTC.convert don't match expected shape they can be processed in few ways:

circle-info

If any corruption was detected during conversion, log will be shown in the console depending on environment

Object

If during object conversion some field will be of unexpected type it will NOT be saved in corresponding class instance, it will be replaced by default instance value

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

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

const users = [
   {
      id: 1,
      name: `Vasya`,
      age: 43,
   },
   {
      id: `2`,
      name: `Petya`,
      age: 54,
   },
   {
      id: 3,
      name: true,
      age: `Masha`,
   },
];

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

console.log(result.converted.all);
console.log(result.converted.corrupted);
console.log(result.converted.valid);

/*
1 -> id -> 2 | Expected number, but got string
2 -> age -> Masha | Expected number, but got string
2 -> name -> true | Expected string, but got boolean
*/
console.log(JTC.log.asString(result.tree));

Iterable (Array, Map)

If during iterable conversion value of unexpected type will be faced it will be excluded from corresponding result iterable.

circle-info

In case when iterable entry is of "object" type, but all of its fields corrupted, such entry will also be excluded from iterable

Last updated