Module: js-data

Registered as js-data in NPM and Bower.

Also available from CDN.JS and JSDelivr.

Details
Source
index.js, line 1
Examples

npm i --save js-data@beta

bower i --save js-data@3.0.0-beta.1

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-data/3.0.0-beta.1/js-data.min.js"></script>

<script src="https://cdn.jsdelivr.net/js-data/3.0.0-beta.1/js-data.min.js"></script>

<script src="/path/to/js-data.min.js"></script>
<script>
  console.log(JSData.version.full); // "3.0.0-beta.1"
</script>

var JSData = require('js-data');

import * as JSData from 'js-data';

define('myApp', ['js-data'], function (JSData) { ... })

Members


<static> Collection

JSData's Collection class.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 65
Example
import {Collection} from 'js-data'
const collection = new Collection()

<static> Component

JSData's Component class. Most components in JSData extend this class.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 80
Example
import {Component} from 'js-data'
// Make a custom component.
const MyComponent = Component.extend({
  myMethod (someArg) { ... }
})

<static> Container

JSData's Container class. Defines and manages Mappers. Used in Node.js and in the browser, though in the browser you may want to use DataStore instead.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 98
Example
import {Container} from 'js-data'
const store = new Container()

<static> DataStore

JSData's DataStore class. Primarily for use in the browser. In Node.js you probably want to use Container instead.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 115
Example
import {DataStore} from 'js-data'
const store = new DataStore()

<static> Index

JSData's Index class, based on mindex.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 131
  • Index

<static> LinkedCollection

JSData's LinkedCollection class. Used by the DataStore component. If you need to create a collection manually, you should probably use the Collection class.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 141

<static> Mapper

JSData's Mapper class. The core of the ORM.

Examples

import {Mapper} from 'js-data'
const UserMapper = new Mapper({ name: 'user' })

<static> Query

JSData's Query class. Used by the Collection component.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 176

<static> Record

JSData's Record class.

Details
Type Since Source Tutorials See
Constructor 3.0.0 index.js, line 186
Example
import {Container} from 'js-data'
const store = new Container()
store.defineMapper('user')
const user = store.createRecord('user')

<static> Schema

JSData's Schema class. Implements http://json-schema.org/draft-04.

Example
import {Container, Schema} from 'js-data'
const userSchema = new Schema({
  properties: {
    id: { type: 'string' },
    name: { type: 'string' }
  }
})
const store = new Container()
store.defineMapper('user', {
  schema: userSchema
})

<static> Settable

JSData's Settable class.

Details
Type Since Source See
Constructor 3.0.0 index.js, line 229
Example
import {Settable} from 'js-data'
const obj = new Settable()
obj.set('secret', 'value')
console.log(JSON.stringify(obj)) // {}

<static> utils

JSData's utility methods.

Details
Type Since Source See
Object 3.0.0 index.js, line 50
Properties:
Name Type Description
Promise Function

See utils.Promise.

Example
import {utils} from 'js-data'
console.log(utils.isString('foo')) // true

<static> version

Describes the version of this JSData object.

Details
Type Since Source
Object 2.0.0 index.js, line 29
Properties:
Name Type Description
full String

The full semver value.

major Number

The major version number.

minor Number

The minor version number.

patch Number

The patch version number.

alpha String | Boolean

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

beta String | Boolean

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

Example
console.log(JSData.version.full) // "3.0.0-beta.1"

Methods


<static> belongsTo(related, opts)

BelongsTo relation decorator. You probably won't use this directly.

Method parameters:
Name Type Description
related Mapper

The relation the target belongs to.

opts Object

Configuration options.

Properties
Name Type Description
foreignKey String

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 4

<static> hasMany(related, opts)

HasMany relation decorator. You probably won't use this directly.

Method parameters:
Name Type Description
related Mapper

The relation of which the target has many.

opts Object

Configuration options.

Properties
Name Type Argument Description
foreignKey String <optional>

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 24

<static> hasOne(related, opts)

HasOne relation decorator. You probably won't use this directly.

Method parameters:
Name Type Description
related Mapper

The relation of which the target has one.

opts Object

Configuration options.

Properties
Name Type Argument Description
foreignKey String <optional>

The field that holds the primary key of the related record.

localField String

The field that holds a reference to the related record object.

Return value:
Type Description
Function

Invocation function, which accepts the target as the only parameter.

Details
Source
decorators.js, line 44