Partial

In case when operating with object deltas you can specify field flag isPartial to true it will means that any field specified in the model can be absent and it should NOT be considered as corruption.

  • null will considered as valid value inside iterables.

  • All child objects fields inside class model will be also considered as partial. No matter of nesting level, even inside iterables.

  • symbol fields will NOT be initialized.

  • If field is not present in origin it will be also deleted from converted object.

class Note {
   public text: string;
   public date: number;
}

const NOTE_META = new ObjectMeta({
   builder: Note,
   fields: {
      date: new NumberField(),
      text: new StringField()
   }
});

class User {
   public name: string;
   public age: number;
   public city: string;
   public notes: Note[];
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      age: new NumberField(),
      name: new StringField(),
      city: new StringField(),
      notes: new ObjectArrayField({ meta: NOTE_META }),
   }
});

const users = [
   {
      name: `Vasya`
   },
   {
      age: 12
   },
   {
      city: `Odessa`,
      notes: [
         { text: `AAA` },
         { date: 1 },
      ]
   },
   {
      notes: [
         null,
         { text: `BBB` },
         null,
         { date: 2 },
      ]
   },
];

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

JTC.log.asString(result.tree) //?

console.log(result.isCorrupted);    // false
console.log(result.converted.all);

Last updated

Was this helpful?