Comparing version 3.0.0-rc.4 to 3.0.0-rc.5
@@ -0,1 +1,15 @@ | ||
##### 3.0.0-rc.5 - 26 September 2016 | ||
###### Backwards compatible changes | ||
- Fixed some edge cases with Schemas related to anyOf, oneOf, allOf, and additionalProperties | ||
- #386 - Added intermediate `SimpleStore` class between `Container` and `DataStore`. | ||
- #393 - Added `Schema#pick` method | ||
###### Bug fixes | ||
- #374 - revert() after a save() does not work with Schema defined properties | ||
- #387 - Switch to passing only the current-change in 'changes' emit by @pik | ||
###### Other | ||
- #406 - refactor(test): splits tests into smaller ones by @stalniy | ||
##### 3.0.0-rc.4 - 03 August 2016 | ||
@@ -2,0 +16,0 @@ |
{ | ||
"name": "js-data", | ||
"description": "Robust, framework-agnostic in-memory data store.", | ||
"version": "3.0.0-rc.4", | ||
"version": "3.0.0-rc.5", | ||
"homepage": "http://www.js-data.io", | ||
@@ -71,17 +71,18 @@ "repository": { | ||
"devDependencies": { | ||
"babel-plugin-syntax-async-functions": "6.8.0", | ||
"babel-plugin-external-helpers": "^6.8.0", | ||
"babel-plugin-syntax-async-functions": "6.13.0", | ||
"babel-plugin-transform-es2015-modules-umd": "6.12.0", | ||
"babel-plugin-transform-regenerator": "6.11.4", | ||
"js-data-repo-tools": "0.5.5", | ||
"karma": "1.1.2", | ||
"babel-plugin-transform-regenerator": "6.14.0", | ||
"js-data-repo-tools": "0.5.7", | ||
"karma": "1.3.0", | ||
"karma-babel-preprocessor": "6.0.1", | ||
"karma-chai": "0.1.0", | ||
"karma-chrome-launcher": "1.0.1", | ||
"karma-mocha": "1.1.1", | ||
"karma-phantomjs-launcher": "1.0.1", | ||
"karma-chrome-launcher": "2.0.0", | ||
"karma-mocha": "1.2.0", | ||
"karma-phantomjs-launcher": "1.0.2", | ||
"karma-sauce-launcher": "1.0.0", | ||
"karma-sinon": "1.0.5", | ||
"phantomjs-prebuilt": "2.1.10", | ||
"uglify-js": "2.7.0" | ||
"phantomjs-prebuilt": "2.1.12", | ||
"uglify-js": "2.7.3" | ||
} | ||
} | ||
} |
<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 Status][b1]][b2] [![npm version][b3]][b4] [![npm downloads][b5]][b6] [![coverage][bcov]][lcov] | ||
# [js-data v3](http://www.js-data.io/) [![Slack][1]][2] [![NPM][3]][4] [![Downloads][5]][6] [![Coverage][7]][8] | ||
| __Browser tests__ | __Node.js tests__ | | ||
| ---------------------------------|----| | ||
| [![Sauce Test Status][b7]][b8] | [![Circle CI][b9]][b10] [![Circle CI][b11]][b10] [![Circle CI][b12]][b10] [![Circle CI][b13]][b10] [![Circle CI][b14]][b10] [![Circle CI][b15]][b10] | | ||
| [![Tests][9]][10] | [![Tests][11]][12] [![Tests][13]][12] [![Tests][14]][12] [![Tests][15]][12] [![Tests][16]][12] [![Tests][17]][12] | | ||
[b1]: http://slack.js-data.io/badge.svg | ||
[b2]: http://slack.js-data.io | ||
[b3]: https://img.shields.io/npm/v/js-data.svg?style=flat | ||
[b4]: https://www.npmjs.org/package/js-data | ||
[b5]: https://img.shields.io/npm/dm/js-data.svg?style=flat | ||
[b6]: https://www.npmjs.org/package/js-data | ||
[b7]: https://saucelabs.com/browser-matrix/jsdata.svg | ||
[b8]: https://saucelabs.com/u/jsdata | ||
[b9]: https://img.shields.io/circleci/project/js-data/js-data.svg | ||
[b10]: https://circleci.com/gh/js-data/js-data | ||
[b11]: https://img.shields.io/badge/Node.js-v6.x-brightgreen.svg | ||
[b12]: https://img.shields.io/badge/Node.js-v5.x-brightgreen.svg | ||
[b13]: https://img.shields.io/badge/Node.js-v4.x-brightgreen.svg | ||
[b14]: https://img.shields.io/badge/Node.js-v0.12.x-brightgreen.svg | ||
[b15]: https://img.shields.io/badge/Node.js-v0.10.x-brightgreen.svg | ||
[bcov]: https://img.shields.io/codecov/c/github/js-data/js-data/master.svg | ||
[lcov]: https://codecov.io/github/js-data/js-data | ||
[1]: http://slack.js-data.io/badge.svg | ||
[2]: http://slack.js-data.io | ||
[3]: https://img.shields.io/npm/v/js-data.svg?style=flat | ||
[4]: https://www.npmjs.org/package/js-data | ||
[5]: https://img.shields.io/npm/dm/js-data.svg?style=flat | ||
[6]: https://www.npmjs.org/package/js-data | ||
[7]: https://img.shields.io/codecov/c/github/js-data/js-data/master.svg | ||
[8]: https://codecov.io/github/js-data/js-data | ||
[9]: https://saucelabs.com/browser-matrix/jsdata.svg | ||
[10]: https://saucelabs.com/u/jsdata | ||
[11]: https://img.shields.io/circleci/project/js-data/js-data.svg | ||
[12]: https://circleci.com/gh/js-data/js-data | ||
[13]: https://img.shields.io/badge/Node.js-v6.x-brightgreen.svg | ||
[14]: https://img.shields.io/badge/Node.js-v5.x-brightgreen.svg | ||
[15]: https://img.shields.io/badge/Node.js-v4.x-brightgreen.svg | ||
[16]: https://img.shields.io/badge/Node.js-v0.12.x-brightgreen.svg | ||
[17]: https://img.shields.io/badge/Node.js-v0.10.x-brightgreen.svg | ||
@@ -43,21 +43,32 @@ __JSData v3 release candidate is stable. More features may be added before 3.0.0, | ||
To get started, visit the main website at __[http://js-data.io](http://www.js-data.io/v3.0/docs/home)__. | ||
### Just getting started? | ||
## Links | ||
Start with the [JSData Getting Started Tutorial][18] or checkout the [API Reference Documentation][19]. | ||
* [Quick start](http://www.js-data.io/v3.0/docs/home#quick-start) - Get started in 5 minutes | ||
* [Guides and Tutorials](http://www.js-data.io/v3.0/docs/installation) - Learn how to use JSData | ||
* [API Reference Docs](http://api.js-data.io) - Explore components, methods, options, etc. | ||
* [Community & Support](http://js-data.io/docs/community) - Find solutions and chat with the community | ||
* [General Contributing Guide](http://js-data.io/docs/contributing) - Give back and move the project forward | ||
* [Contributing to js-data core](https://github.com/js-data/js-data/blob/master/.github/CONTRIBUTING.md) | ||
### Need help? | ||
## License | ||
Please [post a question][20] on Stack Overflow. **This is the preferred method.** | ||
The MIT License (MIT) | ||
You can also chat with folks on the [Slack Channel][21]. If you end up getting | ||
your question answered, please still consider consider posting your question to | ||
Stack Overflow (then possibly answering it yourself). Thanks! | ||
Copyright (c) 2014-2016 js-data project authors | ||
### Want to contribute? | ||
* [LICENSE](https://github.com/js-data/js-data/blob/master/LICENSE) | ||
* [AUTHORS](https://github.com/js-data/js-data/blob/master/AUTHORS) | ||
* [CONTRIBUTORS](https://github.com/js-data/js-data/blob/master/CONTRIBUTORS) | ||
Awesome! You can get started over at the [Contributing guide][22]. | ||
And thank you! | ||
### License | ||
[The MIT License (MIT)][23] | ||
Copyright (c) 2014-2016 [js-data project authors][24] | ||
[18]: http://www.js-data.io/v3.0/docs/home | ||
[19]: http://api.js-data.io/ | ||
[20]: http://stackoverflow.com/questions/tagged/jsdata | ||
[21]: http://slack.js-data.io/ | ||
[22]: https://github.com/js-data/js-data/blob/master/.github/CONTRIBUTING.md | ||
[23]: https://github.com/js-data/js-data/blob/master/LICENSE | ||
[24]: https://github.com/js-data/js-data/blob/master/AUTHORS |
@@ -61,3 +61,3 @@ import utils from './utils' | ||
* // import {Collection, Record} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Collection, Record} = JSData | ||
@@ -106,3 +106,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Collection, Mapper} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Collection, Mapper} = JSData | ||
@@ -423,3 +423,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Collection} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Collection} = JSData | ||
@@ -889,3 +889,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Collection} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Collection} = JSData | ||
@@ -892,0 +892,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -35,3 +35,3 @@ import utils from './utils' | ||
* // Normally you would do: import {Component} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Component} = JSData | ||
@@ -74,3 +74,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Component} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Component} = JSData | ||
@@ -208,3 +208,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Collection, DataStore} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Collection, DataStore} = JSData | ||
@@ -211,0 +211,0 @@ * |
@@ -908,3 +908,3 @@ import utils from './utils' | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -961,3 +961,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container, Mapper} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -995,3 +995,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1031,3 +1031,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1068,3 +1068,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1114,3 +1114,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1232,3 +1232,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1264,3 +1264,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1330,3 +1330,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -1333,0 +1333,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -245,2 +245,18 @@ /** | ||
/** | ||
* JSData's {@link SimpleStore} class. Primarily for use in the browser. In | ||
* Node.js you probably want to use {@link Container} instead. | ||
* | ||
* @example | ||
* import {SimpleStore} from 'js-data' | ||
* const store = new SimpleStore() | ||
* | ||
* @name module:js-data.SimpleStore | ||
* @see SimpleStore | ||
* @since 3.0.0 | ||
* @tutorial ["http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore","Components of JSData: SimpleStore"] | ||
* @type {Constructor} | ||
*/ | ||
import SimpleStore from './SimpleStore' | ||
export * from './decorators' | ||
@@ -260,3 +276,4 @@ | ||
Settable, | ||
SimpleStore, | ||
utils | ||
} |
@@ -131,3 +131,3 @@ import utils from './utils' | ||
* // Normally you would do: import {LinkedCollection} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {LinkedCollection} = JSData | ||
@@ -134,0 +134,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -1052,3 +1052,3 @@ import utils from './utils' | ||
* // Normally you would do: import {Query} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Query} = JSData | ||
@@ -1055,0 +1055,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -22,2 +22,8 @@ import utils, { safeSetLink } from './utils' | ||
// Cache these strings | ||
const creatingPath = 'creating' | ||
const noValidatePath = 'noValidate' | ||
const keepChangeHistoryPath = 'keepChangeHistory' | ||
const previousPath = 'previous' | ||
/** | ||
@@ -35,3 +41,3 @@ * js-data's Record class. An instance of `Record` corresponds to an in-memory | ||
* // Normally you would do: import {Record} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Record} = JSData | ||
@@ -50,3 +56,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Mapper} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Mapper} = JSData | ||
@@ -65,3 +71,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -79,3 +85,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -99,3 +105,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -132,7 +138,8 @@ * console.log('Using JSData v' + JSData.version.full) | ||
const _set = this._set | ||
// TODO: Optimize these strings | ||
_set('creating', true) | ||
_set(creatingPath, true) | ||
if (opts.noValidate) { | ||
_set('noValidate', true) | ||
_set(noValidatePath, opts.noValidate === undefined ? true : opts.noValidate) | ||
} | ||
_set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory) | ||
// Set the idAttribute value first, if it exists. | ||
@@ -144,6 +151,8 @@ const mapper = this.constructor.mapper | ||
} | ||
utils.fillIn(this, props) | ||
_set('creating', false) | ||
_set('noValidate', false) | ||
_set('previous', utils.plainCopy(props)) | ||
_set(creatingPath, false) | ||
const validateOnSet = opts.validateOnSet === undefined ? (mapper ? mapper.validateOnSet : true) : opts.validateOnSet | ||
_set(noValidatePath, !validateOnSet) | ||
_set(previousPath, mapper ? mapper.toJSON(props) : utils.plainCopy(props)) | ||
} | ||
@@ -206,3 +215,3 @@ | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -237,3 +246,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -252,8 +261,9 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* @method Record#commit | ||
* @param {Object} [opts] Configuration options. Passed to {@link Record#toJSON}. | ||
* @since 3.0.0 | ||
*/ | ||
commit () { | ||
commit (opts) { | ||
this._set('changed') // unset | ||
this._set('history', []) // clear history | ||
this._set('previous', utils.plainCopy(this)) | ||
this._set('previous', this.toJSON(opts)) | ||
}, | ||
@@ -295,3 +305,3 @@ | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -320,3 +330,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -352,3 +362,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -378,3 +388,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -568,3 +578,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -602,3 +612,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -708,3 +718,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -753,3 +763,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -803,3 +813,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -833,3 +843,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Container} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Container} = JSData | ||
@@ -907,3 +917,3 @@ * console.log('Using JSData v' + JSData.version.full) | ||
* // Normally you would do: import {Record} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Record} = JSData | ||
@@ -910,0 +920,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -123,3 +123,3 @@ import utils from './utils' | ||
}) | ||
return allErrors.length ? undefined : allErrors | ||
return allErrors.length ? allErrors : undefined | ||
}, | ||
@@ -508,5 +508,2 @@ | ||
utils.forOwn(properties || {}, function (_schema, prop) { | ||
// if (value[prop] === undefined && _schema['default'] !== undefined) { | ||
// value[prop] = utils.copy(_schema['default']) | ||
// } | ||
opts.prop = prop | ||
@@ -531,3 +528,6 @@ errors = errors.concat(validate(value[prop], _schema, opts) || []) | ||
if (keys.length) { | ||
const origProp = opts.prop | ||
opts.prop = '' | ||
addError(`extra fields: ${keys.join(', ')}`, 'no extra fields', opts, errors) | ||
opts.prop = origProp | ||
} | ||
@@ -646,13 +646,8 @@ } else if (utils.isObject(additionalProperties)) { | ||
*/ | ||
const validateKeyword = function (op, value, schema, opts) { | ||
return schema[op] !== undefined && validationKeywords[op](value, schema, opts) | ||
} | ||
/** | ||
* @ignore | ||
*/ | ||
const runOps = function (ops, value, schema, opts) { | ||
let errors = [] | ||
ops.forEach(function (op) { | ||
errors = errors.concat(validateKeyword(op, value, schema, opts) || []) | ||
if (schema[op] !== undefined) { | ||
errors = errors.concat(validationKeywords[op](value, schema, opts) || []) | ||
} | ||
}) | ||
@@ -750,2 +745,4 @@ return errors.length ? errors : undefined | ||
const noValidatePath = 'noValidate' | ||
// boolean - Whether to preserve Change History for a Record | ||
const keepChangeHistoryPath = 'keepChangeHistory' | ||
// boolean - Whether to skip change notification for a Record's currently | ||
@@ -795,3 +792,2 @@ // changing property | ||
const _unset = this[unsetter] | ||
// Optionally check that the new value passes validation | ||
@@ -811,2 +807,4 @@ if (!_get(noValidatePath)) { | ||
if (track && !_get(creatingPath)) { | ||
// previous is versioned on database commit | ||
// props are versioned on set() | ||
const previous = _get(previousPath) | ||
@@ -863,8 +861,12 @@ const current = _get(keyPath) | ||
} | ||
const changes = this.changes() | ||
const changeRecord = utils.plainCopy(changes) | ||
changeRecord.timestamp = new Date().getTime() | ||
const changeHistory = _get(changeHistoryPath) || [] | ||
_set(changeHistoryPath, changeHistory) | ||
changeHistory.push(changeRecord) | ||
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) | ||
@@ -1015,3 +1017,3 @@ } | ||
* // Normally you would do: import {Schema} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Schema} = JSData | ||
@@ -1043,6 +1045,8 @@ * console.log('Using JSData v' + JSData.version.full) | ||
}) | ||
} | ||
if (this.type === 'array' && this.items && !(this.items instanceof Schema)) { | ||
} else if (this.type === 'array' && this.items && !(this.items instanceof Schema)) { | ||
this.items = new Schema(this.items) | ||
} | ||
if (this.extends && !(this.extends instanceof Schema)) { | ||
this.extends = new Schema(this.extends) | ||
} | ||
['allOf', 'anyOf', 'oneOf'].forEach((validationKeyword) => { | ||
@@ -1123,2 +1127,37 @@ if (this[validationKeyword]) { | ||
/** | ||
* Create a copy of the given value that contains only the properties defined | ||
* in this schema. | ||
* | ||
* @name Schema#pick | ||
* @method | ||
* @param {*} value The value to copy. | ||
* @returns {*} The copy. | ||
*/ | ||
pick (value) { | ||
if (this.type === 'object') { | ||
value || (value = {}) | ||
let copy = {} | ||
if (this.properties) { | ||
utils.forOwn(this.properties, (_definition, prop) => { | ||
copy[prop] = _definition.pick(value[prop]) | ||
}) | ||
} | ||
if (this.extends) { | ||
utils.fillIn(copy, this.extends.pick(value)) | ||
} | ||
return copy | ||
} else if (this.type === 'array') { | ||
value || (value = []) | ||
return value.map((item) => { | ||
const _copy = this.items ? this.items.pick(item) : {} | ||
if (this.extends) { | ||
utils.fillIn(_copy, this.extends.pick(item)) | ||
} | ||
return _copy | ||
}) | ||
} | ||
return utils.plainCopy(value) | ||
}, | ||
/** | ||
* Validate the provided value against this schema. | ||
@@ -1151,3 +1190,3 @@ * | ||
* // Normally you would do: import {Schema} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Schema} = JSData | ||
@@ -1154,0 +1193,0 @@ * console.log('Using JSData v' + JSData.version.full) |
@@ -66,3 +66,3 @@ import utils from './utils' | ||
* // Normally you would do: import {Settable} from 'js-data' | ||
* const JSData = require('js-data@3.0.0-beta.10') | ||
* const JSData = require('js-data@3.0.0-rc.4') | ||
* const {Settable} = JSData | ||
@@ -69,0 +69,0 @@ * console.log('Using JSData v' + JSData.version.full) |
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 too big to display
Sorry, the diff of this file is too big to display
2790359
36
40554
74
15