Comparing version 2.0.0 to 3.0.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"1f69ce26-c132-4a14-89d8-62da4e2ceb78":{"parent":null,"children":["408ddc6f-ebd4-4d81-9cb9-186ce1d46604"]},"408ddc6f-ebd4-4d81-9cb9-186ce1d46604":{"parent":"1f69ce26-c132-4a14-89d8-62da4e2ceb78","children":["66076800-65c8-4b21-a293-49734af4296f"]},"66076800-65c8-4b21-a293-49734af4296f":{"parent":"408ddc6f-ebd4-4d81-9cb9-186ce1d46604","children":[]}},"files":{"/Users/scommisso/Projects/datastar/lib/index.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/model.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/schema.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/index.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/index.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/create.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statement.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/find.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/remove.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/table.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/partial-statements/with.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/alter.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/statements/update.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-builder/compound-statement.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/statement-collection.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/attributes.js":["66076800-65c8-4b21-a293-49734af4296f"],"/Users/scommisso/Projects/datastar/lib/await-wrap.js":["66076800-65c8-4b21-a293-49734af4296f"]},"externalIds":{}} | ||
{"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":{}} |
@@ -28,4 +28,9 @@ | ||
Attributes.prototype.get = function (name) { | ||
if (this.schema._aliases[name]) name = this.schema._aliases[name]; | ||
return this.schema.valueToNull(this.data[snakeCase(name)]); | ||
var key = this.schema.entityKeyToColumnName(name); | ||
var value = this.data[key]; | ||
if (this.schema.requiresNullConversion(key)) { | ||
return this.schema.valueToNull(value, true); | ||
} | ||
if (this.schema.isKey(key)) { return value; } | ||
return this.schema.nullToValue(this.schema.fieldMeta(key), value); | ||
}; | ||
@@ -32,0 +37,0 @@ |
@@ -95,3 +95,2 @@ | ||
}; | ||
this._columns = this.meta = schema.toCql(); | ||
@@ -293,2 +292,11 @@ this._aliases = schema.aliases() || {}; | ||
// | ||
// Transform an entity key to the proper key that cassandra expects (snake_case, unalias) | ||
// | ||
Schema.prototype.entityKeyToColumnName = function (key) { | ||
var mappedKey = snakeCase(key); | ||
var alias = this._aliases[mappedKey]; | ||
return alias || mappedKey; | ||
}; | ||
// | ||
// Transform an entity, an object of conditions or an array of fields to have the proper | ||
@@ -309,9 +317,4 @@ // keys that cassandra expects (snake_case, unalias) | ||
// | ||
var mappedKey = snakeCase(key); | ||
var alias = this._aliases[mappedKey]; | ||
if (alias) { | ||
acc[alias] = entity[key]; | ||
} else { | ||
acc[mappedKey] = entity[key]; | ||
} | ||
var mappedKey = this.entityKeyToColumnName(key); | ||
acc[mappedKey] = entity[key]; | ||
@@ -421,3 +424,3 @@ return acc; | ||
Schema.prototype.isKey = function (key) { | ||
return this._keysLookup[key]; | ||
return !!this._keysLookup[key]; | ||
}; | ||
@@ -691,3 +694,7 @@ | ||
var key = keys[i]; | ||
entity[key] = this.valueToNull(entity[key]); | ||
if (this.requiresNullConversion(key)) { | ||
entity[key] = this.valueToNull(entity[key], true); | ||
} else if (!this.isKey(key)) { | ||
entity[key] = this.nullToValue(this.fieldMeta(key), entity[key]); | ||
} | ||
} | ||
@@ -698,6 +705,17 @@ | ||
Schema.prototype.requiresNullConversion = function (columnName) { | ||
if (!this.meta[columnName]) { | ||
columnName = this.entityKeyToColumnName(columnName); | ||
} | ||
var metaData = this.fieldMeta(columnName); | ||
var isKey = this.isKey(columnName); | ||
if (isKey) { return false; } | ||
if (!metaData || typeof metaData.nullConversion !== 'boolean') { return true; } | ||
return metaData.nullConversion; | ||
}; | ||
// | ||
// Detect our `null-like` values and return null if applicable | ||
// | ||
Schema.prototype.valueToNull = function (value) { | ||
Schema.prototype.valueToNull = function (value, skipNameCheck) { | ||
if (value === '\x00') { | ||
@@ -717,3 +735,3 @@ return null; | ||
for (let i = 0; i < value.length; i++) { | ||
value[i] = this.valueToNull(value[i]); | ||
value[i] = this.valueToNull(value[i], true); | ||
} | ||
@@ -727,3 +745,5 @@ | ||
for (let i = 0; i < keys.length; i++) { | ||
value[keys[i]] = this.valueToNull(value[keys[i]]); | ||
if (skipNameCheck || !this._keysLookup[keys[i]]) { | ||
value[keys[i]] = this.valueToNull(value[keys[i]], true); | ||
} | ||
} | ||
@@ -730,0 +750,0 @@ |
{ | ||
"name": "datastar", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Now witness the power of this FULLY ARMED AND OPERATIONAL DATASTAR!", | ||
@@ -9,3 +9,3 @@ "main": "lib", | ||
"clone": "^1.0.4", | ||
"joi-of-cql": "^1.0.2", | ||
"joi-of-cql": "^2.0.1", | ||
"list-stream": "^1.0.0", | ||
@@ -15,3 +15,3 @@ "lodash.pick": "^4.0.1", | ||
"one-time": "0.0.4", | ||
"priam": "^3.0.0", | ||
"priam": "^3.1.0", | ||
"read-only-stream": "^2.0.0", | ||
@@ -18,0 +18,0 @@ "through2": "^2.0.0", |
@@ -1004,2 +1004,6 @@ # datastar | ||
Fields that are defined as either `partitionKey()` or `clusteringKey()` will not | ||
be converted to/from `null`. In addition, to exclude a field from this `null` | ||
handling, define the field with `meta({ nullConversion: false })`. | ||
2. Casing, as mentioned briefly in the warning at the top of the readme, we assume | ||
@@ -1006,0 +1010,0 @@ `camelCase` as the casing convention when interacting with datastar and the |
@@ -67,5 +67,9 @@ | ||
foo_id: cql.uuid(), | ||
secondary_id: cql.uuid(), | ||
non_nullable_id: cql.uuid().meta({ nullConversion: false }), | ||
nullable_id: cql.uuid(), | ||
something: cql.text() | ||
}).partitionKey('foo_id') | ||
.clusteringKey('secondary_id') | ||
}; | ||
@@ -752,2 +752,3 @@ /* jshint camelcase: false */ | ||
describe('foo', () => { | ||
const zeros = '00000000-0000-0000-0000-000000000000'; | ||
const one = uuid.v4(); | ||
@@ -761,2 +762,3 @@ const two = uuid.v4(); | ||
const eight = uuid.v4(); | ||
const nine = uuid.v4(); | ||
@@ -792,3 +794,3 @@ let Foo; | ||
Foo.create({ fooId: one }, err => { | ||
Foo.create({ fooId: one, secondaryId: one, nullableId: two }, err => { | ||
assume(err).is.falsey(); | ||
@@ -798,19 +800,23 @@ next(); | ||
Foo.create({ fooId: two }, err => { | ||
Foo.create({ fooId: two, secondaryId: one, nullableId: two }, err => { | ||
assume(err).is.falsey(); | ||
next(); | ||
}); | ||
}); | ||
it('should create a record in the database that will properly expire with given ttl', done => { | ||
Foo.create({ entity: { fooId: three }, ttl: 3 }, err => { | ||
Foo.create({ entity: { | ||
fooId: three, | ||
secondaryId: zeros, | ||
nullableId: zeros | ||
}, ttl: 3 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: three }, (error, res) => { | ||
Foo.findOne({ fooId: three, secondaryId: zeros }, (error, res) => { | ||
assume(error).is.falsey(); | ||
assume(res); | ||
assume(res.fooId).equals(three); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: three }, (er, result) => { | ||
Foo.findOne({ fooId: three, secondaryId: zeros }, (er, result) => { | ||
assume(er).is.falsey(); | ||
@@ -826,6 +832,6 @@ assume(result).is.falsey(); | ||
it('should create a record in the database that will expire but still be found before it reaches given ttl', done => { | ||
Foo.create({ entity: { fooId: four }, ttl: 7 }, err => { | ||
Foo.create({ entity: { fooId: four, secondaryId: one }, ttl: 7 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: four }, (err, res) => { | ||
Foo.findOne({ fooId: four, secondaryId: one }, (err, res) => { | ||
assume(err).is.falsey(); | ||
@@ -836,3 +842,3 @@ assume(res); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: four }, (err, result) => { | ||
Foo.findOne({ fooId: four, secondaryId: one }, (err, result) => { | ||
assume(err).is.falsey(); | ||
@@ -849,7 +855,7 @@ assume(result); | ||
it('should update a record in the database that will expire with given ttl', done => { | ||
Foo.update({ entity: { fooId: five, something: 'foo' }, ttl: 2 }, err => { | ||
Foo.update({ entity: { fooId: five, secondaryId: one, something: 'foo' }, ttl: 2 }, err => { | ||
assume(err).is.falsey(); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: five }, (er, res) => { | ||
Foo.findOne({ fooId: five, secondaryId: one }, (er, res) => { | ||
assume(er).is.falsey(); | ||
@@ -864,6 +870,6 @@ assume(res).is.falsey(); | ||
it('should update a record in the database that can be found before it reaches ttl', done => { | ||
Foo.update({ entity: { fooId: six, something: 'foo' }, ttl: 5 }, err => { | ||
Foo.update({ entity: { fooId: six, secondaryId: one, something: 'foo' }, ttl: 5 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: six }, (error, result) => { | ||
Foo.findOne({ fooId: six, secondaryId: one }, (error, result) => { | ||
assume(error).is.falsey(); | ||
@@ -874,3 +880,3 @@ assume(result); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: six }, (er, res) => { | ||
Foo.findOne({ fooId: six, secondaryId: one }, (er, res) => { | ||
assume(er).is.falsey(); | ||
@@ -887,6 +893,6 @@ assume(res); | ||
it('should update a record in the database with an updated reset ttl and can be found before it reaches the updated ttl', done => { | ||
Foo.update({ entity: { fooId: seven, something: 'boo' }, ttl: 3 }, err => { | ||
Foo.update({ entity: { fooId: seven, secondaryId: one, something: 'boo' }, ttl: 3 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: seven }, (error, result) => { | ||
Foo.findOne({ fooId: seven, secondaryId: one }, (error, result) => { | ||
assume(error).is.falsey(); | ||
@@ -896,7 +902,7 @@ assume(result); | ||
Foo.update({ entity: { fooId: seven, something: 'foo' }, ttl: 10 }, error => { | ||
Foo.update({ entity: { fooId: seven, secondaryId: one, something: 'foo' }, ttl: 10 }, error => { | ||
assume(error).is.falsey(); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: seven }, (er, res) => { | ||
Foo.findOne({ fooId: seven, secondaryId: one }, (er, res) => { | ||
assume(er).is.falsey(); | ||
@@ -914,6 +920,6 @@ assume(res); | ||
it('should update a record in the database with an updated reset ttl and expire after it reaches the updated ttl', done => { | ||
Foo.update({ entity: { fooId: eight, something: 'boo' }, ttl: 2 }, err => { | ||
Foo.update({ entity: { fooId: eight, secondaryId: one, something: 'boo' }, ttl: 2 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: eight }, (error, result) => { | ||
Foo.findOne({ fooId: eight, secondaryId: one }, (error, result) => { | ||
assume(error).is.falsey(); | ||
@@ -923,7 +929,7 @@ assume(result); | ||
Foo.update({ entity: { fooId: eight, something: 'foo' }, ttl: 3 }, error => { | ||
Foo.update({ entity: { fooId: eight, secondaryId: one, something: 'foo' }, ttl: 3 }, error => { | ||
assume(error).is.falsey(); | ||
setTimeout(() => { | ||
Foo.findOne({ fooId: eight }, (er, res) => { | ||
Foo.findOne({ fooId: eight, secondaryId: one }, (er, res) => { | ||
assume(er).is.falsey(); | ||
@@ -939,2 +945,29 @@ assume(res).is.falsey(); | ||
it('handles nullable fields properly', done => { | ||
Foo.create({ entity: { | ||
fooId: nine, | ||
secondaryId: zeros, | ||
nullableId: zeros | ||
}, ttl: 1 }, err => { | ||
assume(err).is.falsey(); | ||
Foo.findOne({ fooId: nine, secondaryId: zeros }, (error, res) => { | ||
assume(error).is.falsey(); | ||
assume(res); | ||
assume(res.fooId).equals(nine); | ||
assume(res.secondaryId).equals(zeros); | ||
assume(res.nonNullableId).equals(zeros); | ||
assume(res.nullableId).equals(null); | ||
const resAsJson = res.toJSON(); | ||
assume(resAsJson.fooId).equals(nine); | ||
assume(resAsJson.secondaryId).equals(zeros); | ||
assume(resAsJson.nonNullableId).equals(zeros); | ||
assume(resAsJson.nullableId).equals(null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('should run a find query with a limit of 1 and return 1 record', done => { | ||
@@ -950,3 +983,3 @@ Foo.findAll({ conditions: {}, limit: 1 }, (err, recs) => { | ||
const next = assume.wait(2, 2, done); | ||
Foo.remove({ fooId: one }, err => { | ||
Foo.remove({ fooId: one, secondaryId: one }, err => { | ||
assume(err).is.falsey(); | ||
@@ -956,3 +989,3 @@ next(); | ||
Foo.remove({ fooId: two }, err => { | ||
Foo.remove({ fooId: two, secondaryId: one }, err => { | ||
assume(err).is.falsey(); | ||
@@ -959,0 +992,0 @@ next(); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
461355
5345
1079
0
+ Added@hapi/address@2.1.4(transitive)
+ Added@hapi/bourne@1.3.2(transitive)
+ Added@hapi/hoek@8.5.1(transitive)
+ Added@hapi/joi@15.1.1(transitive)
+ Added@hapi/topo@3.1.6(transitive)
+ Addedjoi-of-cql@2.0.6(transitive)
+ Addeduuid@3.4.0(transitive)
- Removedhoek@4.3.1(transitive)
- Removedisemail@2.2.1(transitive)
- Removedjoi@8.4.2(transitive)
- Removedjoi-of-cql@1.0.2(transitive)
- Removedmoment@2.30.1(transitive)
- Removedtopo@2.1.1(transitive)
Updatedjoi-of-cql@^2.0.1
Updatedpriam@^3.1.0