Module: js-data-express

Registered as js-data-express in NPM.

Details
Source
index.js, line 361
Examples

npm i --save js-data-express@rc js-data@rc

import { Router } from 'js-data-express';
const adapter = new Router();

var Router = require('js-data-express').Router;
var adapter = new Router();

Classes

Router

Members


<static> Router

Router class.

Details
Type Source See
Constructor index.js, line 345
  • Router
Examples

import { Router } from 'js-data-express';
const adapter = new Router();

var Router = require('js-data-express').Router;
var adapter = new Router();

<static> version

Details of the current version of the js-data-express module.

Details
Type Source
Object index.js, line 321
Properties:
Name Type Description
version.full String

The full semver value.

version.major Number

The major version number.

version.minor Number

The minor version number.

version.patch Number

The patch version number.

version.alpha String | Boolean

The alpha version value, otherwise false if the current version is not alpha.

version.beta String | Boolean

The beta version value, otherwise false if the current version is not beta.

Examples

import { version } from 'js-data-express';
console.log(version.full);

var version = require('js-data-express').version;
console.log(version.full);

Methods


<static> mount(app, store, config)

Convenience method that mounts queryParser and a store.

Method parameters:
Name Type Argument Description
app *
store Object

Instance of Mapper, Container, SimpleStore, or DataStore.

config Config | String <optional>

Configuration options.

Details
Source
index.js, line 284
Examples

import express from 'express';
import { mount, queryParser, Router } from 'js-data-express';
import { Container } from 'js-data';

const app = express();
const store = new Container();
const UserMapper = store.defineMapper('user');
const CommentMapper = store.defineMapper('comment');
mount(app, store);

mount(app, store, '/api');

Type Definitions


ActionHandler(component, req)

Custom defined method that retrieves data/results for an endpoint

Method parameters:
Name Type Description
component Object

Instance of Mapper, Container, SimpleStore, or DataStore.

req Object

HTTP(S) Request Object

Return value:
Type Description
Promise

Promise that resolves with the result.

Details
Type Source
Function index.js, line 64
Example

(component, req) => {
   return new Promise((resolve, reject) => {
     // ..some logic
     return resolve(results)
    })
}

Config

Configuration options for endpoints, actions, & request/response

Details
Type Source
Object index.js, line 192
Properties:
Name Type Argument Description
getEndpoint Endpoint <optional>

Define endpoints with custom method

create CreateConfig <optional>

create action configs

createMany CreateManyConfig <optional>

createMany action configs

destroy DestroyConfig <optional>

destroy action configs

destroyAll DestroyAllConfig <optional>

destroyAll action configs

find FindConfig <optional>

find action configs

findAll FindAllConfig <optional>

findAll action configs

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results

update UpdateConfig <optional>

update action configs

updateAll UpdateAllConfig <optional>

updateAll action configs

updateMany UpdateManyConfig <optional>

updateMany action configs


CreateConfig

create action configs

Details
Type Source
Object index.js, line 94
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


CreateManyConfig

createMany action configs

Details
Type Source
Object index.js, line 104
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


DestroyAllConfig

destroyAll action configs

Details
Type Source
Object index.js, line 124
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


DestroyConfig

destroy action configs

Details
Type Source
Object index.js, line 114
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


Endpoint(mapper)

Define endpoint path with custom logic

Method parameters:
Name Type Description
mapper Object

Component Mapper object

Details
Type Source
Function index.js, line 184

FindAllConfig

findAll action configs

Details
Type Source
Object index.js, line 144
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


FindConfig

find action configs

Details
Type Source
Object index.js, line 134
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


RequestHandler(req, res, next)

A middleware method invoked on all requests

Method parameters:
Name Type Description
req Object

HTTP(S) Request Object

res Object

HTTP(S) Response Object

next Function

Express next() callback to continue the chain

Details
Type Source
Function index.js, line 44

ResponseHandler(req, res, next)

A method that handles all responses

Method parameters:
Name Type Description
req Object

HTTP(S) Request Object

res Object

HTTP(S) Response Object

next Function

Express next() callback to continue the chain

Details
Type Source
Function index.js, line 54

Serializer(component, result, opts)

Method parameters:
Name Type Description
component Object

Instance of Mapper, Container, SimpleStore, or DataStore.

result Object

The result of the endpoint's ActionHandler.

opts Object

Configuration options.

Return value:
Type Description
Object | Array | undefined

The serialized result.

Details
Type Source
Function index.js, line 84

UpdateAllConfig

UpdateAllConfig action configs

Details
Type Source
Object index.js, line 164
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


UpdateConfig

update action configs

Details
Type Source
Object index.js, line 154
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results


UpdateManyConfig

updateMany action configs

Details
Type Source
Object index.js, line 174
Properties:
Name Type Argument Description
action ActionHandler <optional>

Custom action to retrieve data results

statusCode Number <optional>

The status code to return with the response

toJSON Serializer | Boolean <optional>

Define custom toJSON method for response results