joint-normalizer
v0.0.7
Published
Normalization logic for Joint Kit payloads
Downloads
42
Readme
Joint Normalizer
Normalization logic for common HTTP response payloads.
Currently supports JSON API Spec only.
Table of Contents
Introduction
[TBC]
How to Use
Install
$ yarn add joint-normalizer
API
Constructor
Constructor Options
| Name | Required? | Description |
| ----------------- | --------- | ----------- |
| debugInit | No | Set to true
to log debug messages during instantiation. Defaults to false
. |
| debugToModel | No | Set to true
to log debug messages during Model object hydration. Defaults to false
. |
| debug | No | Set to true
to log debug messages during instance utilization. Defaults to false
. |
| payloadSpec | No | The output specification of the Joint payload. Defaults to 'json-api'
. |
| fieldForModelType | No | The property name in the payload that identifies the name of the Model type. Defaults to 'type'
. |
| toFieldFormat | No | The target format (case) for normalized fields. Supported formats: 'snake'
, 'kebab'
, 'camel'
. Defaults to 'snake'
. |
| fromFieldFormat | No | The source format (case) of the payload's fields. This declaration is not necessary for functional correctness, but will merely suppress unnecessary transformations (and loops) when the source and target match. Supported formats: 'snake'
, 'kebab'
, 'camel'
. Defaults to 'snake'
. |
| relationNameMap | No | [TBC]
| models | No | The Model object definitions (shapes) that the normalizer will build and return (if instructed). Provide the model definitions as an Object. |
Instance
Instance Properties
| Name | Type | Description |
| ----------- | ------- | ----------- |
| ... | ... | [TBC - List all properties from constructor options] |
| Model | Function | The Model factory that is constructed with the models
provided at instantiation. If a payload type is handled by the normalizer, and a valid Model definition cannot be determined, the normalizer will simply return the generic normalized shape. |
Instance Functions
All functions are synchronous.
| Name | Parameters | Returns | Description |
| ---------------- | ---------- | ------- | ----------- |
| normalizePayload | payload
- the payload to normalize. asModel
- whether or not to return a Model object. | The normalized payload (generic object -or- Model object) | Perform the normalization of a provided Joint payload. |
Errors
[TBC]
For Developers
Dev Lint
The plugin uses ESLint for source code linting. The linting will run automatically on git commit
.
$ yarn lint
You can run with flag
--fix
, or shortcut command flint, to trigger auto fixing (e.g.yarn flint
).
Dev Test
The plugin uses Mocha for the testing framework, and Chai for its assertions.
$ yarn test
To build the plugin before running the test, you can use:
$ yarn build-test
Dev Build
The plugin is automatically built on yarn publish
. But, you can manually build the plugin using:
$ yarn build