Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

normalized-db/normalizer

Open more actions menu

Repository files navigation

@normalized-db/normalizer

Warning

This project has been deprecated in favor of @normalized-db/ndb.

Normalize JavaScript objects based on a simple schema (implemented with TypeScript).

Versioning

To ease versioning equal major and minor version numbers are used for all modules.

Installation

Install using NPM:

npm install --save @normalized-db/normalizer

Usage

Use the NormalizerBuilder to create a Normalizer. Use either schema(…) or schemaConfig(…) to apply a schema configuration. This is the only required parameter.

Due to references between objects the normalizer needs them to have keys, this is why you should define a UniqueKeyCallback which generates such keys. Note that these will also be used for persisting the normalized data by @normalized-db/data-store.

Using reverse references will generate a _refs-field on objects. E.g. normalizing an object like

const schema: ISchemaConfig = {
  _defaults: { key: 'id' },
  parentType: {
    targets: {
      foo: 'childType'
    }
  },
  childType: true
}

const parent: ParentType = { 
  id: 'parent',
  foo: { 
    id: 'child', 
    bar: 123
  }
}

would result in

const normalizedChild: ChildType = { 
  id: 'child', 
  bar: 123, 
  _refs: { 
    parentType: Set<string>(['parent'])
  }
}

Examples

A more detailed example for a ISchemaConfig and normalization input/output can be found in the core-module's README.

See the examples-project for detailed examples:

Morty Proxy This is a proxified and sanitized view of the page, visit original site.