Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-data

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-data - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

11

CHANGELOG.md

@@ -0,1 +1,12 @@

##### 3.0.1 - 18 August 2017
###### Backwards compatible changes
- Exposed the `makeDescriptor` method on the `Schema` class.
###### Bug fixes
- Fixes some missing definitions in `dist/js-data.d.ts`.
###### Other
- Upgraded dependencies.
##### 3.0.0 - 01 July 2017

@@ -2,0 +13,0 @@

3

dist/js-data.d.ts

@@ -361,2 +361,5 @@ export const version: {

apply(target: any, opts?: any): void
applyDefaults(target: any): void
makeDescriptor(prop: string, schema: Schema, opts?: any): any
pick(value: any): any
validate(value: any, opts?: any): SchemaValidationError[]

@@ -363,0 +366,0 @@ }

31

package.json
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "3.0.0",
"version": "3.0.1",
"homepage": "http://www.js-data.io",

@@ -21,4 +21,3 @@ "repository": {

"CONTRIBUTORS",
"typings.json",
"yarn.lock"
"typings.json"
],

@@ -64,3 +63,3 @@ "keywords": [

"devDependencies": {
"babel-core": "6.25.0",
"babel-core": "6.26.0",
"babel-eslint": "7.2.3",

@@ -70,9 +69,9 @@ "babel-plugin-external-helpers": "6.22.0",

"babel-plugin-transform-es2015-modules-umd": "6.24.1",
"babel-plugin-transform-regenerator": "6.24.1",
"babel-polyfill": "6.23.0",
"babel-plugin-transform-regenerator": "6.26.0",
"babel-polyfill": "6.26.0",
"babel-preset-es2015": "6.24.1",
"chai": "4.0.2",
"chai": "4.1.1",
"ink-docstrap": "git+https://github.com/js-data/docstrap.git#cfbe45fa313e1628c493076d5e15d2b855dfbf2c",
"js-data-repo-tools": "1.0.0",
"jsdoc": "3.4.3",
"jsdoc": "3.5.4",
"karma": "1.7.0",

@@ -86,11 +85,11 @@ "karma-babel-preprocessor": "6.0.1",

"karma-sinon": "1.0.5",
"mocha": "3.4.2",
"nyc": "11.0.3",
"phantomjs-prebuilt": "2.1.14",
"rollup": "0.43.0",
"rollup-plugin-babel": "2.7.1",
"sinon": "2.3.6",
"standard": "10.0.2",
"uglify-js": "3.0.22"
"mocha": "3.5.0",
"nyc": "11.1.0",
"phantomjs-prebuilt": "2.1.15",
"rollup": "0.47.6",
"rollup-plugin-babel": "3.0.2",
"sinon": "3.2.1",
"standard": "10.0.3",
"uglify-js": "3.0.27"
}
}
<img src="https://raw.githubusercontent.com/js-data/js-data/master/js-data.png" alt="js-data logo" title="js-data" align="right" width="96" height="96" />
# [js-data v3](http://www.js-data.io/) [![Slack][1]][2] [![NPM][3]][4] [![npm version](https://img.shields.io/badge/npm-v3.0.0--rc.8-yellow.svg?style=flat)](https://www.npmjs.org/package/js-data) [![Downloads][5]][6] [![Coverage][7]][8]
# [js-data v3](http://www.js-data.io/) [![Slack][1]][2] [![NPM][3]][4] [![Downloads][5]][6] [![Coverage][7]][8]

@@ -65,5 +65,5 @@ | __Browser tests__ | __Node.js tests__ |

Copyright (c) 2014-2016 [js-data project authors][24]
Copyright (c) 2014-2017 [js-data project authors][24]
[18]: http://www.js-data.io/v3.0/docs/home
[18]: http://www.js-data.io/docs/home
[19]: http://api.js-data.io/

@@ -70,0 +70,0 @@ [20]: http://stackoverflow.com/questions/tagged/jsdata

@@ -15,3 +15,3 @@ import utils from './utils'

* @name Schema.types
* @type {Object}
* @type {object}
*/

@@ -100,3 +100,3 @@ const types = {

* @name Schema.validationKeywords
* @type {Object}
* @type {object}
*/

@@ -116,4 +116,4 @@ const validationKeywords = {

* @param {*} value Value to be validated.
* @param {Object} schema Schema containing the `allOf` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `allOf` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -141,4 +141,4 @@ */

* @param {*} value Value to be validated.
* @param {Object} schema Schema containing the `anyOf` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `anyOf` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -166,4 +166,4 @@ */

* @param {*} value TODO
* @param {Object} schema TODO
* @param {Object} opts TODO
* @param {object} schema TODO
* @param {object} opts TODO
*/

@@ -182,4 +182,4 @@ dependencies (value, schema, opts) {

* @param {*} value Value to validate
* @param {Object} schema Schema containing the `enum` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `enum` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -201,4 +201,4 @@ */

* @param {*} value Array to be validated.
* @param {Object} schema Schema containing the items keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the items keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -233,4 +233,4 @@ */

* @param {*} value Number to validate against the keyword.
* @param {Object} schema Schema containing the `maximum` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `maximum` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -260,4 +260,4 @@ */

* @param {*} value Array to be validated.
* @param {Object} schema Schema containing the `maxItems` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `maxItems` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -279,4 +279,4 @@ */

* @param {*} value String to be validated.
* @param {Object} schema Schema containing the `maxLength` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `maxLength` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -296,4 +296,4 @@ */

* @param {*} value Object to be validated.
* @param {Object} schema Schema containing the `maxProperties` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `maxProperties` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -319,4 +319,4 @@ */

* @param {*} value Number to validate against the keyword.
* @param {Object} schema Schema containing the `minimum` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `minimum` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -346,4 +346,4 @@ */

* @param {*} value Array to be validated.
* @param {Object} schema Schema containing the `minItems` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `minItems` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -365,4 +365,4 @@ */

* @param {*} value String to be validated.
* @param {Object} schema Schema containing the `minLength` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `minLength` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -382,4 +382,4 @@ */

* @param {*} value Object to be validated.
* @param {Object} schema Schema containing the `minProperties` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `minProperties` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -405,4 +405,4 @@ */

* @param {*} value Number to be validated.
* @param {Object} schema Schema containing the `multipleOf` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `multipleOf` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -427,4 +427,4 @@ */

* @param {*} value to be checked.
* @param {Object} schema Schema containing the not keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the not keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -447,4 +447,4 @@ */

* @param {*} value to be checked.
* @param {Object} schema Schema containing the `oneOf` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `oneOf` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -478,4 +478,4 @@ */

* @param {*} value String to be validated.
* @param {Object} schema Schema containing the `pattern` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `pattern` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -500,4 +500,4 @@ */

* @param {*} value Object to be validated.
* @param {Object} schema Schema containing the `properties` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `properties` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -568,4 +568,4 @@ */

* @param {*} value Object to be validated.
* @param {Object} schema Schema containing the `required` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `required` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -597,4 +597,4 @@ */

* @param {*} value Value to be validated.
* @param {Object} schema Schema containing the `type` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `type` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -638,4 +638,4 @@ */

* @param {*} value Array to be validated.
* @param {Object} schema Schema containing the `uniqueItems` keyword.
* @param {Object} [opts] Configuration options.
* @param {object} schema Schema containing the `uniqueItems` keyword.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -755,4 +755,4 @@ */

* @param {*} value Value to be validated.
* @param {Object} schema Valid Schema according to the http://json-schema.org/ v4 specification.
* @param {Object} [opts] Configuration options.
* @param {object} schema Valid Schema according to the http://json-schema.org/ v4 specification.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -832,142 +832,6 @@ */

/**
* Assemble a property descriptor which will be added to the prototype of
* {@link Mapper#recordClass}. This method is called when
* {@link Mapper#applySchema} is set to `true`.
*
* @ignore
*/
const makeDescriptor = function (prop, schema, opts) {
const descriptor = {
// Better to allow configurability, but at the user's own risk
configurable: true,
// These properties are enumerable by default, but regardless of their
// enumerability, they won't be "own" properties of individual records
enumerable: schema.enumerable === undefined ? true : !!schema.enumerable
}
// Cache a few strings for optimal performance
const keyPath = `props.${prop}`
const previousPath = `previous.${prop}`
const getter = opts.getter
const setter = opts.setter
const unsetter = opts.unsetter
const track = utils.isBoolean(opts.track) ? opts.track : schema.track
descriptor.get = function () {
return this._get(keyPath)
}
if (utils.isFunction(schema.get)) {
const originalGet = descriptor.get
descriptor.get = function () {
return schema.get.call(this, originalGet)
}
}
descriptor.set = function (value) {
// These are accessed a lot
const _get = this[getter]
const _set = this[setter]
const _unset = this[unsetter]
// Optionally check that the new value passes validation
if (!_get(noValidatePath)) {
const errors = schema.validate(value, { path: [prop] })
if (errors) {
// Immediately throw an error, preventing the record from getting into
// an invalid state
const error = new Error(validationFailureMsg)
error.errors = errors
throw error
}
}
// TODO: Make it so tracking can be turned on for all properties instead of
// only per-property
if (track && !_get(creatingPath)) {
// previous is versioned on database commit
// props are versioned on set()
const previous = _get(previousPath)
const current = _get(keyPath)
let changing = _get(changingPath)
let changed = _get(changedPath)
if (!changing) {
// Track properties that are changing in the current event loop
changed = []
}
// Add changing properties to this array once at most
const index = changed.indexOf(prop)
if (current !== value && index === -1) {
changed.push(prop)
}
if (previous === value) {
if (index >= 0) {
changed.splice(index, 1)
}
}
// No changes in current event loop
if (!changed.length) {
changing = false
_unset(changingPath)
_unset(changedPath)
// Cancel pending change event
if (_get(eventIdPath)) {
clearTimeout(_get(eventIdPath))
_unset(eventIdPath)
}
}
// Changes detected in current event loop
if (!changing && changed.length) {
_set(changedPath, changed)
_set(changingPath, true)
// Saving the timeout id allows us to batch all changes in the same
// event loop into a single "change"
// TODO: Optimize
_set(eventIdPath, setTimeout(() => {
// Previous event loop where changes were gathered has ended, so
// notify any listeners of those changes and prepare for any new
// changes
_unset(changedPath)
_unset(eventIdPath)
_unset(changingPath)
// TODO: Optimize
if (!_get(silentPath)) {
let i
for (i = 0; i < changed.length; i++) {
this.emit('change:' + changed[i], this, utils.get(this, changed[i]))
}
const changes = utils.diffObjects({ [prop]: value }, { [prop]: current })
if (_get(keepChangeHistoryPath)) {
const changeRecord = utils.plainCopy(changes)
changeRecord.timestamp = new Date().getTime()
let changeHistory = _get(changeHistoryPath)
!changeHistory && _set(changeHistoryPath, (changeHistory = []))
changeHistory.push(changeRecord)
}
this.emit('change', this, changes)
}
_unset(silentPath)
}, 0))
}
}
_set(keyPath, value)
return value
}
if (utils.isFunction(schema.set)) {
const originalSet = descriptor.set
descriptor.set = function (value) {
return schema.set.call(this, value, originalSet)
}
}
return descriptor
}
/**
* A map of validation functions grouped by type.
*
* @name Schema.typeGroupValidators
* @type {Object}
* @type {object}
*/

@@ -986,3 +850,3 @@ const typeGroupValidators = {

* @param {*} value Array to be validated.
* @param {Object} schema Schema containing at least one array keyword.
* @param {object} schema Schema containing at least one array keyword.
* @param {Object} [opts] Configuration options.

@@ -1108,3 +972,3 @@ * @returns {(array|undefined)} Array of errors or `undefined` if valid.

* @extends Component
* @param {Object} definition Schema definition according to json-schema.org
* @param {object} definition Schema definition according to json-schema.org
*/

@@ -1150,3 +1014,3 @@ function Schema (definition) {

* @method
* @param {Object} target The prototype to which to apply this schema.
* @param {object} target The prototype to which to apply this schema.
*/

@@ -1160,7 +1024,7 @@ apply (target, opts) {

const properties = this.properties || {}
utils.forOwn(properties, function (schema, prop) {
utils.forOwn(properties, (schema, prop) => {
Object.defineProperty(
target,
prop,
makeDescriptor(prop, schema, opts)
this.makeDescriptor(prop, schema, opts)
)

@@ -1175,3 +1039,3 @@ })

* @method
* @param {Object} target The target to which to apply values for missing values.
* @param {object} target The target to which to apply values for missing values.
*/

@@ -1207,2 +1071,146 @@ applyDefaults (target) {

/**
* Assemble a property descriptor for tracking and validating changes to
* a property according to the given schema. This method is called when
* {@link Mapper#applySchema} is set to `true`.
*
* @name Schema#makeDescriptor
* @method
* @param {string} prop The property name.
* @param {(Schema|object)} schema The schema for the property.
* @param {object} [opts] Optional configuration.
* @param {function} [opts.getter] Custom getter function.
* @param {function} [opts.setter] Custom setter function.
* @param {function} [opts.track] Whether to track changes.
* @returns {object} A property descriptor for the given schema.
*/
makeDescriptor (prop, schema, opts) {
const descriptor = {
// Better to allow configurability, but at the user's own risk
configurable: true,
// These properties are enumerable by default, but regardless of their
// enumerability, they won't be "own" properties of individual records
enumerable: schema.enumerable === undefined ? true : !!schema.enumerable
}
// Cache a few strings for optimal performance
const keyPath = `props.${prop}`
const previousPath = `previous.${prop}`
const getter = opts.getter
const setter = opts.setter
const unsetter = opts.unsetter
const track = utils.isBoolean(opts.track) ? opts.track : schema.track
descriptor.get = function () {
return this._get(keyPath)
}
if (utils.isFunction(schema.get)) {
const originalGet = descriptor.get
descriptor.get = function () {
return schema.get.call(this, originalGet)
}
}
descriptor.set = function (value) {
// These are accessed a lot
const _get = this[getter]
const _set = this[setter]
const _unset = this[unsetter]
// Optionally check that the new value passes validation
if (!_get(noValidatePath)) {
const errors = schema.validate(value, { path: [prop] })
if (errors) {
// Immediately throw an error, preventing the record from getting into
// an invalid state
const error = new Error(validationFailureMsg)
error.errors = errors
throw error
}
}
// TODO: Make it so tracking can be turned on for all properties instead of
// only per-property
if (track && !_get(creatingPath)) {
// previous is versioned on database commit
// props are versioned on set()
const previous = _get(previousPath)
const current = _get(keyPath)
let changing = _get(changingPath)
let changed = _get(changedPath)
if (!changing) {
// Track properties that are changing in the current event loop
changed = []
}
// Add changing properties to this array once at most
const index = changed.indexOf(prop)
if (current !== value && index === -1) {
changed.push(prop)
}
if (previous === value) {
if (index >= 0) {
changed.splice(index, 1)
}
}
// No changes in current event loop
if (!changed.length) {
changing = false
_unset(changingPath)
_unset(changedPath)
// Cancel pending change event
if (_get(eventIdPath)) {
clearTimeout(_get(eventIdPath))
_unset(eventIdPath)
}
}
// Changes detected in current event loop
if (!changing && changed.length) {
_set(changedPath, changed)
_set(changingPath, true)
// Saving the timeout id allows us to batch all changes in the same
// event loop into a single "change"
// TODO: Optimize
_set(eventIdPath, setTimeout(() => {
// Previous event loop where changes were gathered has ended, so
// notify any listeners of those changes and prepare for any new
// changes
_unset(changedPath)
_unset(eventIdPath)
_unset(changingPath)
// TODO: Optimize
if (!_get(silentPath)) {
let i
for (i = 0; i < changed.length; i++) {
this.emit('change:' + changed[i], this, utils.get(this, changed[i]))
}
const changes = utils.diffObjects({ [prop]: value }, { [prop]: current })
if (_get(keepChangeHistoryPath)) {
const changeRecord = utils.plainCopy(changes)
changeRecord.timestamp = new Date().getTime()
let changeHistory = _get(changeHistoryPath)
!changeHistory && _set(changeHistoryPath, (changeHistory = []))
changeHistory.push(changeRecord)
}
this.emit('change', this, changes)
}
_unset(silentPath)
}, 0))
}
}
_set(keyPath, value)
return value
}
if (utils.isFunction(schema.set)) {
const originalSet = descriptor.set
descriptor.set = function (value) {
return schema.set.call(this, value, originalSet)
}
}
return descriptor
},
/**
* Create a copy of the given value that contains only the properties defined

@@ -1258,3 +1266,3 @@ * in this schema.

* @param {*} value Value to validate.
* @param {Object} [opts] Configuration options.
* @param {object} [opts] Configuration options.
* @returns {(array|undefined)} Array of errors or `undefined` if valid.

@@ -1321,9 +1329,9 @@ */

* @method Schema.extend
* @param {Object} [props={}] Properties to add to the prototype of the
* @param {object} [props={}] Properties to add to the prototype of the
* subclass.
* @param {Object} [props.constructor] Provide a custom constructor function
* @param {object} [props.constructor] Provide a custom constructor function
* to be used as the subclass itself.
* @param {Object} [classProps={}] Static properties to add to the subclass.
* @param {object} [classProps={}] Static properties to add to the subclass.
* @returns {Constructor} Subclass of this Schema class.
* @since 3.0.0
*/

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc