Skip to content

Commit

Permalink
Release 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Gama committed Aug 29, 2016
1 parent 7661695 commit 710f8a6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# Changelog

## [1.2.0](https://github.com/seegno/bookshelf-json-columns/tree/HEAD)
## [1.2.1](https://github.com/seegno/bookshelf-json-columns/tree/HEAD)

[Full Changelog](https://github.com/seegno/bookshelf-json-columns/compare/1.2.0...1.2.1)

**Closed issues:**

- `array.includes` is undefined in non-ES2015 environments [\#28](https://github.com/seegno/bookshelf-json-columns/issues/28)

**Merged pull requests:**

- Update eslint version [\#30](https://github.com/seegno/bookshelf-json-columns/pull/30) ([ricardogama](https://github.com/ricardogama))
- Add babel-plugin-array-includes [\#29](https://github.com/seegno/bookshelf-json-columns/pull/29) ([ricardogama](https://github.com/ricardogama))

## [1.2.0](https://github.com/seegno/bookshelf-json-columns/tree/1.2.0) (2016-08-29)
[Full Changelog](https://github.com/seegno/bookshelf-json-columns/compare/1.1.1...1.2.0)

**Closed issues:**
Expand Down
51 changes: 33 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@

/**
* Stringify JSON columns.
*/

'use strict';

Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

var _stringify = require('babel-runtime/core-js/json/stringify');

var _stringify2 = _interopRequireDefault(_stringify);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Stringify JSON columns.
*/

function stringify(model, attributes, options) {
var _this = this;
Expand All @@ -21,7 +36,7 @@ function stringify(model, attributes, options) {

this.jsonColumns.forEach(function (column) {
if (_this.attributes[column]) {
_this.attributes[column] = JSON.stringify(_this.attributes[column]);
_this.attributes[column] = (0, _stringify2.default)(_this.attributes[column]);
}
});
}
Expand Down Expand Up @@ -49,7 +64,7 @@ function parse(model, response, options) {
* Export `bookshelf-json-columns` plugin.
*/

exports['default'] = function (Bookshelf) {
exports.default = function (Bookshelf) {
var Model = Bookshelf.Model.prototype;
var client = Bookshelf.knex.client.config.client;

Expand Down Expand Up @@ -80,14 +95,14 @@ exports['default'] = function (Bookshelf) {
}

// Handle arguments as Bookshelf.
var attributes = undefined;
var attributes = void 0;

if (key === null || typeof key === 'object') {
if (key === null || (typeof key === 'undefined' ? 'undefined' : (0, _typeof3.default)(key)) === 'object') {
attributes = key || {};
options = value ? _extends({}, value) : {};
options = value ? (0, _extends3.default)({}, value) : {};
} else {
(attributes = {})[key] = value;
options = options ? _extends({}, options) : {};
options = options ? (0, _extends3.default)({}, options) : {};
}

// Only handle arguments with `patch` option.
Expand All @@ -96,16 +111,16 @@ exports['default'] = function (Bookshelf) {
}

// Stringify JSON columns.
Object.keys(attributes).forEach(function (attribute) {
if (_this3.jsonColumns.includes(attribute)) {
attributes[attribute] = JSON.stringify(attributes[attribute]);
(0, _keys2.default)(attributes).forEach(function (attribute) {
if (_this3.jsonColumns.indexOf(attribute) !== -1) {
attributes[attribute] = (0, _stringify2.default)(attributes[attribute]);
}
});

return Model.save.call(this, attributes, options).then(function (model) {
// Parse JSON columns.
Object.keys(attributes).forEach(function (attribute) {
if (_this3.jsonColumns.includes(attribute)) {
(0, _keys2.default)(attributes).forEach(function (attribute) {
if (_this3.jsonColumns.indexOf(attribute) !== -1) {
model.attributes[attribute] = JSON.parse(model.attributes[attribute]);
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bookshelf-json-columns",
"version": "1.2.0",
"version": "1.2.1",
"description": "Parse JSON columns with Bookshelf.js",
"license": "MIT",
"author": {
Expand Down

0 comments on commit 710f8a6

Please sign in to comment.