Class: Schema

Schema


new Schema(definition)

js-data's Schema class.

import {Schema} from 'js-data'
Method parameters:
Name Type Description
definition Object

Schema definition according to json-schema.org

Details
Source
Schema.js, line 860

Extends

This class extends the Component class.

Members


<static> typeGroupValidators

TODO

Details
Type Source
Object Schema.js, line 766

<static> types

TODO

Details
Type Source
Object Schema.js, line 6

<static> validationKeywords

TODO

Details
Type Source
Object Schema.js, line 91

_listeners

Event listeners attached to this Component. Do not modify. Use Component#on and Component#off instead.

Details
Type Since Source
Object 3.0.0 Component.js, line 7
Inherited From:

Methods


<static> validate(value, schema, opts)

TODO

Method parameters:
Name Type Argument Description
value *

TODO

schema Object <optional>

TODO

opts Object <optional>

Configuration options.

Details
Source
Schema.js, line 584

dbg(args)

Log the provided values at the "debug" level.

Method parameters:
Name Type Argument Description
args * <optional>
<repeatable>

Values to log.

Details
Since Source
3.0.0 Component.js, line 32
Inherited From:

emit(event, args)

Trigger an event on this Component.

Method parameters:
Name Type Argument Description
event String

Name of event to emit.

args * <optional>
<repeatable>

Arguments to pass to any listeners.

Details
Since Source
3.0.0 Component.js, line 98
Inherited From:
Examples
collection.on('foo', (msg) => {
  console.log(msg) // "bar"
})
collection.emit('foo', 'bar')
store.on('foo', (msg, val1, val2) => {
  console.log(msg, val1, val2) // "bar" "beep" "boop"
})
store.emit('foo', 'bar', 'beep', 'boop')

log(level, args)

Log the provided values. By default sends values to console[level].

Method parameters:
Name Type Argument Description
level String

Log level

args * <optional>
<repeatable>

Values to log.

Details
Since Source
3.0.0 Component.js, line 39
Inherited From:

off(event, listener)

Remove an event listener from this Component. If no listener is provided, then all listeners for the specified event will be removed. If no event is specified then all listeners for all events will be removed.

Method parameters:
Name Type Argument Description
event String <optional>

Name of event to unsubsribe to.

listener Function <optional>

Listener to remove.

Details
Since Source
3.0.0 Component.js, line 79
Inherited From:
Examples

Remove a listener to a single event

collection.off('add', handler)

Remove all listeners to a single event

record.off('change')

Remove all listeners to all events

store.off()

on(event, listener, ctx)

Register a new event listener on this Component.

Method parameters:
Name Type Argument Description
event String

Name of event to subsribe to.

listener Function

Listener function to handle the event.

ctx * <optional>

Optional content in which to invoke the listener.

Details
Since Source
3.0.0 Component.js, line 49
Inherited From:
Examples

Listen for all "afterCreate" events in a DataStore

store.on('afterCreate', (mapperName, props, opts, result) => {
  console.log(mapperName) // "post"
  console.log(props.id) // undefined
  console.log(result.id) // 1234
})
store.create('post', { title: 'Modeling your data' }).then((post) => {
  console.log(post.id) // 1234
})

Listen for the "add" event on a collection

collection.on('add', (records) => {
  console.log(records) // [...]
})

Listen for "change" events on a record

post.on('change', (record, changes) => {
  console.log(changes) // { changed: { title: 'Modeling your data' } }
})
post.title = 'Modeling your data'

validate(value, opts)

Validate the provided value against this schema.

Method parameters:
Name Type Argument Description
value *

Value to validate.

opts Object <optional>

Configuration options.

Return value:
Type Description
Array | undefined

Array of errors or undefined if valid.

Details
Source
Schema.js, line 912

validate(target)

This adds ES5 getters/setters to the target based on the "properties" in this Schema, which makes possible change tracking and validation on property assignment.

Method parameters:
Name Type Description
target Object

The prototype to which to apply this schema.

Details
Source
Schema.js, line 888