clay-normalizer
Normalizer for clay-collection
Last updated 7 months ago by realglobe .
Apache-2.0 · Repository · Bugs · Original npm · Tarball
$ cnpm install clay-normalizer 
SYNC missed versions from official npm registry.

clay-normalizer

Build Status npm Version JS Standard

Normalizer for clay-collection

Installation

$ npm install clay-normalizer --save

Usage

'use strict'

const { clayEntity } = require('clay-entity')
const { normalize, denormalize } = require('clay-normalizer')

{
  let org01 = clayEntity({ id: 1, name: 'org01', $$as: 'Org' })
  let user01 = clayEntity({ id: 1, name: 'user01', org: org01, $$as: 'User' })
  let user02 = clayEntity({ id: 2, name: 'user02', org: org01, $$as: 'User' })

  let { pointers, pointed, relations } = normalize([ user01, user02 ])

  console.log(pointers) // -> [ 'User#1', 'User#2' ]
  console.log(pointed) // -> { User: { '1': { /* ... */ }, '2': { /* ... */ } }, Org: { '1': { /* ... */ } } }
  console.log(relations) // -> { 'User#1': { org: 'Org#1' }, 'User#2': { org: 'Org#1' } }

  let users = denormalize({ pointers, pointed, relations })
  console.log(users) // -> [ { /* ... */ }, { /* ... */ } ]
}

Functions

Available functions

Signature Description
denormalize(normalized, options) -> ClayEntity[] Restore from normalized
normalize(collection, options) -> ClayNormalized Normalize clay entities

License

This software is released under the Apache-2.0 License.

Links

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (5)
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |