Comparing version 3.0.0 to 3.0.1
@@ -1,1 +0,1 @@ | ||
{"processes":{"3ee8ba7f-1fe6-49ee-a788-5a6f8f1ada4d":{"parent":"be9ce8d1-3ad6-4eec-8bb1-5ed0f06b505e","children":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"]},"be9ce8d1-3ad6-4eec-8bb1-5ed0f06b505e":{"parent":null,"children":["3ee8ba7f-1fe6-49ee-a788-5a6f8f1ada4d"]},"c5094c7d-674d-441c-9ee5-a4ee4259c7f1":{"parent":"3ee8ba7f-1fe6-49ee-a788-5a6f8f1ada4d","children":[]}},"files":{"/Users/scommisso/Projects/datastar/lib/index.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/model.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/schema.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/index.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/index.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/create.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statement.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/find.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/remove.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/table.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/partial-statements/with.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/alter.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/update.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-builder/compound-statement.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/statement-collection.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/attributes.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"],"/Users/scommisso/Projects/datastar/lib/await-wrap.js":["c5094c7d-674d-441c-9ee5-a4ee4259c7f1"]},"externalIds":{}} | ||
{"processes":{"147bb809-59a0-45a5-ab5b-18e7057da5b1":{"parent":"d90be867-ead0-4d00-aff0-f10a8396e41a","children":["e060164e-eefe-4552-9713-fdb470e49706"]},"d90be867-ead0-4d00-aff0-f10a8396e41a":{"parent":null,"children":["147bb809-59a0-45a5-ab5b-18e7057da5b1"]},"e060164e-eefe-4552-9713-fdb470e49706":{"parent":"147bb809-59a0-45a5-ab5b-18e7057da5b1","children":[]}},"files":{"/Users/scommisso/Projects/datastar/lib/index.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/model.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/schema.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/index.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/index.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/create.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statement.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/find.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/remove.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/table.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/partial-statements/with.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/alter.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/update.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-builder/compound-statement.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/statement-collection.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/attributes.js":["e060164e-eefe-4552-9713-fdb470e49706"],"/Users/scommisso/Projects/datastar/lib/await-wrap.js":["e060164e-eefe-4552-9713-fdb470e49706"]},"externalIds":{}} |
@@ -31,3 +31,3 @@ | ||
if (this.schema.requiresNullConversion(key)) { | ||
return this.schema.valueToNull(value, true); | ||
return this.schema.valueToNull(value); | ||
} | ||
@@ -34,0 +34,0 @@ if (this.schema.isKey(key)) { return value; } |
@@ -691,3 +691,3 @@ | ||
if (this.requiresNullConversion(key)) { | ||
entity[key] = this.valueToNull(entity[key], true); | ||
entity[key] = this.valueToNull(entity[key]); | ||
} else if (!this.isKey(key)) { | ||
@@ -715,38 +715,6 @@ entity[key] = this.nullToValue(this.fieldMeta(key), entity[key]); | ||
// | ||
Schema.prototype.valueToNull = function (value, skipNameCheck) { | ||
if (value === '\x00') { | ||
return null; | ||
} | ||
if (value === '00000000-0000-0000-0000-000000000000') { | ||
return null; | ||
} | ||
var type = this.type(value); | ||
if (type === 'date' && value.getTime() === 0) { | ||
return null; | ||
} | ||
if (type === 'array') { | ||
for (let i = 0; i < value.length; i++) { | ||
value[i] = this.valueToNull(value[i], true); | ||
} | ||
return value; | ||
} | ||
if (type === 'object') { | ||
var keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i++) { | ||
if (skipNameCheck || !this._keysLookup[keys[i]]) { | ||
value[keys[i]] = this.valueToNull(value[keys[i]], true); | ||
} | ||
} | ||
return value; | ||
} | ||
return value; | ||
Schema.prototype.valueToNull = function (value) { | ||
return valueToNullImpl(value, this.type.bind(this), new WeakSet()); | ||
}; | ||
// | ||
@@ -1152,1 +1120,56 @@ // Assess if we have sufficient conditions during our pre-remove check from | ||
} | ||
// | ||
// Detect our `null-like` values and return null if applicable. | ||
// Implements recursion for `valueToNull` prototype function. | ||
// | ||
function valueToNullImpl(value, getType, visited) { | ||
if (value === '\x00') { | ||
return null; | ||
} | ||
if (value === '00000000-0000-0000-0000-000000000000') { | ||
return null; | ||
} | ||
var type = getType(value); | ||
if (type === 'date' && value.getTime() === 0) { | ||
return null; | ||
} | ||
if (value === null || typeof value === 'undefined') { | ||
return value; | ||
} | ||
if (isObject(value)) { | ||
// Prevent cyclic structures from being re-evaluated | ||
if (visited.has(value)) { | ||
return value; | ||
} | ||
visited.add(value); | ||
if (type === 'array') { | ||
for (let i = 0; i < value.length; i++) { | ||
var arrValue = value[i]; | ||
if (!isObject(arrValue) || !visited.has(arrValue)) { | ||
value[i] = valueToNullImpl(arrValue, getType, visited); | ||
} | ||
} | ||
} else if (type === 'object') { | ||
var keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i++) { | ||
var keyValue = value[keys[i]]; | ||
if (!isObject(keyValue) || !visited.has(keyValue)) { | ||
value[keys[i]] = valueToNullImpl(keyValue, getType, visited); | ||
} | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null; | ||
} |
{ | ||
"name": "datastar", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Now witness the power of this FULLY ARMED AND OPERATIONAL DATASTAR!", | ||
@@ -33,2 +33,3 @@ "main": "lib", | ||
"istanbul": "^0.4.1", | ||
"lodash.clonedeep": "^4.5.0", | ||
"mocha": "^5.2.0", | ||
@@ -35,0 +36,0 @@ "mocha-istanbul": "^0.2.0", |
const assume = require('assume'), | ||
entity = require('../fixtures/dog'), | ||
dogFixture = require('../fixtures/dog'), | ||
schemas = require('../fixtures/schemas'), | ||
mocks = require('../mocks'), | ||
helpers = require('../helpers'); | ||
helpers = require('../helpers'), | ||
cloneDeep = require('lodash.clonedeep'); | ||
@@ -11,10 +12,14 @@ assume.use(require('assume-sinon')); | ||
describe('Model instance (unit)', () => { | ||
let dog; | ||
const datastar = helpers.connectDatastar({ mock: true }, mocks.datastar()); | ||
const Dog = datastar.define('dog', { | ||
schema: schemas.dog | ||
let dog, Dog, datastar, entity; | ||
beforeEach(() => { | ||
datastar = helpers.connectDatastar({ mock: true }, mocks.datastar()); | ||
Dog = datastar.define('dog', { | ||
schema: schemas.dog | ||
}); | ||
entity = cloneDeep(dogFixture); | ||
dog = Dog.toInstance(entity); | ||
}); | ||
it('should "transform" data into an instance of the defined model', () => { | ||
dog = Dog.toInstance(entity); | ||
assume(dog).is.instanceof(Dog); | ||
@@ -47,3 +52,10 @@ }); | ||
}); | ||
it('should handle de-nulling cyclic objects', () => { | ||
dog.owner.puppies = [dog]; // inject cyclic reference | ||
// See https://github.com/godaddy/datastar/pull/27 | ||
// Previously, this would cause recursive loop (Max call stack size exceeded error) | ||
assume(dog.owner).exists(); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
464239
5376
15