1.4.7 • Published 4 years ago

schema-exchanger v1.4.7

Weekly downloads
86
License
SEE LICENSE IN LI...
Repository
-
Last release
4 years ago

schema-exchanger

The lib for moving some data scheme to another data scheme

example

class LocalPet extends Exchanger {
  static get schema() {
    return {
      name: { key: "name" }
    }
  }
}

class OtherPet extends Exchanger {
  static get schema() {
    return {
      name: { key: "nickname" }
    }
  }
}

class LocalSchema extends Exchanger {
  static get schema() {
    return {
      id: { key: "id" },
      user: { key: "user", type: LocalUser },
      pets: { key: "pets", type: [LocalPet] }
    }
  }
}

class OtherSchema extends Exchanger {
  static get schema() {
    return {
      id: { key: "uuid" },
      user: { key: "userData", type: OtherUser },
      pets: { key: "childs", type: [OtherPet] }
    }
  }
}

const SomeData = {
  id: 123,
  user: { id: 123, name: "name" },
  pets: [{ name: "Sparky" }]
}

const localObj = LocalSchema.fromJson(LocalData)
const otherObj = OtherSchema.fromExchanger(localObj)

otherObj.toJSON()

/* 
expected output object
{
  uuid: 123,
  userData: {
    uuid: 123,
    title: "name"
  },
  childs: [
    {
      nickname: "Sparky"
    }
  ]
} 
*/
1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago