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

jsonapi-store-relationaldb

Package Overview
Dependencies
Maintainers
6
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-store-relationaldb - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

test/proxy.js

4

CHANGELOG.md

@@ -0,1 +1,5 @@

- 2017-12-12 - v5.0.0
- 2017-12-12 - Support latest version of `jsonapi-server` with store managed id support.
- 2017-12-12 - Revert column type for `string` properties back to `string` from `text`.
- 2017-12-12 - Remove support for Node.js 4.
- 2017-10-09 - v4.0.0

@@ -2,0 +6,0 @@ - 2017-10-09 - Optimised Sequelize UUID column type for ids.

85

lib/modelGenerators/default.js

@@ -1,11 +0,11 @@

var DataTypes = require('sequelize').DataTypes
const DataTypes = require('sequelize').DataTypes
exports.joiSchemaToSequelizeModel = function (resourceName, joiSchema) {
var model = {
id: {
module.exports = class {
constructor (resourceName, joiSchema) {
this.id = {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
type: {
}
this.type = {
type: DataTypes.VIRTUAL, // We do not actually save this to DB, but API needs this

@@ -18,7 +18,7 @@ set: function (val) {

}
},
meta: {
}
this.meta = {
type: DataTypes.STRING,
get: function () {
var data = this.getDataValue('meta')
const data = this.getDataValue('meta')
if (!data) return undefined

@@ -31,27 +31,52 @@ return JSON.parse(data)

}
}
Object.keys(joiSchema).forEach(function (attributeName) {
var attribute = joiSchema[attributeName]
if (attribute._type === 'string') model[attributeName] = { type: DataTypes.TEXT, allowNull: true }
if (attribute._type === 'date') model[attributeName] = { type: DataTypes.DATE, allowNull: true }
if (attribute._type === 'number') model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true }
if (attribute._type === 'boolean') model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true }
if (attribute._type === 'array') {
// Serialize array to ';'-separated string for most SQL dbs.
model[attributeName] = {
type: DataTypes.STRING,
allowNull: true,
get: function () {
var data = this.getDataValue(attributeName)
return data ? data.split(';') : []
},
set: function (val) {
this.setDataValue(attributeName, val.join(';'))
for (let attributeName of Object.keys(joiSchema)) {
const attribute = joiSchema[attributeName]
if (attribute._type === 'string') {
this[attributeName] = {
type: DataTypes.STRING,
allowNull: true
}
}
if (attribute._type === 'date') {
this[attributeName] = {
type: DataTypes.DATE,
allowNull: true
}
}
if (attribute._type === 'number') {
this[attributeName] = {
type: DataTypes.NUMERIC,
allowNull: true
}
}
if (attribute._type === 'boolean') {
this[attributeName] = {
type: DataTypes.BOOLEAN,
allowNull: true
}
}
if (attribute._type === 'array') {
// Serialize array to ';'-separated string for most SQL dbs.
this[attributeName] = {
type: DataTypes.STRING,
allowNull: true,
get: function () {
const data = this.getDataValue(attributeName)
return data ? data.split(';') : []
},
set: function (val) {
this.setDataValue(attributeName, val.join(';'))
}
}
}
if (attributeName === 'id') {
delete this[attributeName].allowNull
Object.assign(this[attributeName], {
type: DataTypes.STRING(128),
primaryKey: true
})
}
}
})
return model
}
}

@@ -1,23 +0,11 @@

var DataTypes = require('sequelize').DataTypes
const DataTypes = require('sequelize').DataTypes
const Default = require('./default')
exports.joiSchemaToSequelizeModel = function (resourceName, joiSchema) {
var model = {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
type: {
type: DataTypes.VIRTUAL, // We do not actually save this to DB, but API needs this
set: function (val) {
this.setDataValue('type', val)
},
get: function () {
return resourceName
}
},
meta: {
module.exports = class extends Default {
constructor (resourceName, joiSchema) {
super(resourceName, joiSchema)
this.meta = {
type: DataTypes.JSONB,
get: function () {
var data = this.getDataValue('meta')
const data = this.getDataValue('meta')
if (!data) return undefined

@@ -30,33 +18,49 @@ return data

}
}
Object.keys(joiSchema).forEach(function (attributeName) {
var attribute = joiSchema[attributeName]
if (attribute._type === 'string') model[attributeName] = { type: DataTypes.TEXT, allowNull: true }
if (attribute._type === 'date') model[attributeName] = { type: DataTypes.DATE, allowNull: true }
if (attribute._type === 'number') {
if (typeof attribute._flags.precision !== 'undefined') {
model[attributeName] = { type: DataTypes.NUMERIC(32, attribute._flags.precision), allowNull: true }
} else {
model[attributeName] = { type: DataTypes.NUMERIC, allowNull: true }
for (let attributeName of Object.keys(joiSchema)) {
const attribute = joiSchema[attributeName]
if (attribute._type === 'number') {
if (typeof attribute._flags.precision !== 'undefined') {
this[attributeName] = {
type: DataTypes.NUMERIC(32, attribute._flags.precision),
allowNull: true
}
} else {
this[attributeName] = {
type: DataTypes.NUMERIC,
allowNull: true
}
}
}
}
if (attribute._type === 'boolean') model[attributeName] = { type: DataTypes.BOOLEAN, allowNull: true }
if (attribute._type === 'array') {
// PostgreSQL has proper array support, so lets use that
switch (attribute._inner.items[0]._type) {
case 'string': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.STRING), allowNull: true}; break
case 'number': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.NUMERIC), allowNull: true}; break
case 'boolean': model[attributeName] = {type: DataTypes.ARRAY(DataTypes.BOOLEAN), allowNull: true}; break
if (attribute._type === 'array') {
// PostgreSQL has proper array support, so lets use that
switch (attribute._inner.items[0]._type) {
case 'string':
this[attributeName] = {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true
}
break
case 'number':
this[attributeName] = {
type: DataTypes.ARRAY(DataTypes.NUMERIC),
allowNull: true
}
break
case 'boolean':
this[attributeName] = {
type: DataTypes.ARRAY(DataTypes.BOOLEAN),
allowNull: true
}
break
}
this[attributeName].get = function () {
return this.getDataValue(attributeName) || []
}
this[attributeName].set = function (val) {
this.setDataValue(attributeName, val || [])
}
}
model[attributeName].get = function () {
return this.getDataValue(attributeName) || []
}
model[attributeName].set = function (val) {
this.setDataValue(attributeName, val || [])
}
}
})
return model
}
}

@@ -13,4 +13,4 @@ 'use strict'

var modelGenerators = {
postgres: require('./modelGenerators/postgres'),
default: require('./modelGenerators/default')
Postgres: require('./modelGenerators/postgres'),
Default: require('./modelGenerators/default')
}

@@ -144,10 +144,7 @@

case 'postgres':
modelAttributes = modelGenerators.postgres.joiSchemaToSequelizeModel(
self.resourceConfig.resource,
localAttributes)
modelAttributes = new modelGenerators.Postgres(self.resourceConfig.resource, localAttributes)
break
default:
modelAttributes = modelGenerators.default.joiSchemaToSequelizeModel(
self.resourceConfig.resource,
localAttributes)
modelAttributes = new modelGenerators.Default(self.resourceConfig.resource, localAttributes)
break
}

@@ -154,0 +151,0 @@

{
"name": "jsonapi-store-relationaldb",
"version": "4.0.0",
"version": "5.0.0",
"description": "Relational data store for jsonapi-server.",

@@ -22,11 +22,11 @@ "keywords": [

"engines": {
"node": ">=4.5"
"node": ">=6"
},
"dependencies": {
"async": "2.5.0",
"async": "2.6.0",
"debug": "3.1.0",
"joi": "11.3.4",
"joi": "12.0.0",
"lodash": "4.17.4",
"semver": "5.4.1",
"sequelize": "4.13.8"
"sequelize": "4.28.0"
},

@@ -36,10 +36,10 @@ "devDependencies": {

"coveralls": "3.0.0",
"eslint": "4.8.0",
"eslint": "4.13.1",
"eslint-config-standard": "10.2.1",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-node": "5.2.0",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-node": "5.2.1",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-standard": "3.0.1",
"jsonapi-server": "3.2.1",
"jsonapi-server": "4.1.2",
"lokka": "1.7.0",

@@ -50,4 +50,4 @@ "lokka-transport-http": "1.6.1",

"mocha-performance": "0.1.1",
"mysql2": "1.4.2",
"pg": "7.3.0",
"mysql2": "1.5.1",
"pg": "7.4.0",
"pg-hstore": "2.3.2",

@@ -54,0 +54,0 @@ "plato": "1.7.0",

@@ -7,5 +7,6 @@ [![Coverage Status](https://coveralls.io/repos/holidayextras/jsonapi-store-relationaldb/badge.svg?branch=master&service=github)](https://coveralls.io/github/holidayextras/jsonapi-store-relationaldb?branch=master)

# jsonapi-store-relationaldb
#### :warning: PLEASE NOTE: Version 4.x releases erroneously created columns for `string` properties as Sequelize `text` type. The behaviour in version 5.x has reverted back to creating columns with the Sequelize `string` type, which is the more adequate type and was the behaviour in versions 3.x and older. The `text` columns created by version 4.x will need to be manually migrated to `string` columns.
`jsonapi-store-relationaldb` is a relational database backed data store for [`jsonapi-server`](https://github.com/holidayextras/jsonapi-server).

@@ -12,0 +13,0 @@

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