Skip to content

Commit

Permalink
Merge branch 'release/v0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Jul 12, 2016
2 parents 5b96e3e + d0a96f9 commit 493e45e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ This library is in in active development, please report any issue you might find
- [Installation](#installation)
- [Getting started](#getting-started)
- [Aliases](#aliases)
- [runInTransaction alias](#runintransaction-alias)
- [Schema](#schema)
- [Creation](#creation)
- [Properties types](#properties-types)
Expand Down Expand Up @@ -113,8 +112,6 @@ After a successfull connection, gstore has 2 aliases set up
- `gstore.ds` The gcloud datastore instance
- `gstore.runInTransaction`. Alias of the same gcloud method

#### runInTransaction alias

## Schema
### Creation
```
Expand Down Expand Up @@ -189,7 +186,8 @@ This setting can be overridden by passing a *readAll* setting set to **true** in
- **inline** settings of list(), query() and findAround()

#### write
If you want to protect certain properties to be written by a user, you can set their *write* option to **false**. You can then call [sanitize()](#modelSanitize) on a Model passing the user data and those properties will be removed. Example: `var data = BlogPostModel.sanitize(req.body);`
If you want to protect certain properties to be written by a user, you can set their *write* option to **false**. You can then call [sanitize()](#modelSanitize) on a Model passing the user data and those properties will be removed.
Example: `var data = BlogPostModel.sanitize(req.body);`


```
Expand Down
2 changes: 1 addition & 1 deletion lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
let path;
if (id) {
if (is.string(id)) {
id = /^\d+$/.test(id) ? parseInt(id, 10) : id;
id = isFinite(id) ? parseInt(id, 10) : id;
} else if (!is.number(id)) {
throw new Error('id must be a string or a number');
}
Expand Down
12 changes: 8 additions & 4 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
let multiple = is.array(id);

cb = args.pop();
id = is.array(id) || isNaN(parseInt(id)) ? id : parseInt(id);
id = parseId(id);
ancestors = args.length > 1 ? args[1] : undefined;
namespace = args.length > 2 ? args[2] : undefined;
transaction = args.length > 3 ? args[3] : undefined;
Expand Down Expand Up @@ -102,7 +102,7 @@
let args = arrayArguments(arguments);

cb = args.pop();
id = isNaN(parseInt(id)) ? id : parseInt(id);
id = parseId(id);
ancestors = args.length > 2 ? args[2] : undefined;
namespace = args.length > 3 ? args[3] : undefined;
transaction = args.length > 4 ? args[4] : undefined;
Expand Down Expand Up @@ -279,7 +279,7 @@
let multiple = is.array(id);

cb = args.pop();
id = is.array(id) || isNaN(parseInt(id)) ? id : parseInt(id);
id = parseId(id);
ancestors = args.length > 1 ? args[1]: undefined;
namespace = args.length > 2 ? args[2]: undefined;
transaction = args.length > 3 ? args[3]: undefined;
Expand Down Expand Up @@ -567,7 +567,7 @@
let path = [_this.entityKind];

if (typeof id !== 'undefined' && id !== null) {
id = isNaN(parseInt(id, 10)) ? id : parseInt(id, 10);
id = parseId(id);
path.push(id);
}

Expand Down Expand Up @@ -884,6 +884,10 @@
return a;
}

function parseId(id) {
return isFinite(id) ? parseInt(id, 10) : id;
}

function initQuery(self, namespace, transaction) {
if (transaction && transaction.constructor.name !== 'Transaction') {
throw Error('Transaction needs to be a gcloud Transaction');
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gstore-node",
"version": "0.5.0",
"version": "0.5.1",
"description": "gstore-node is a Google Datastore Entity Models tools",
"main": "index.js",
"scripts": {
Expand All @@ -12,8 +12,7 @@
"node": ">=4.0"
},
"keywords": [
"Google Datastore",
"Node JS"
"google datastore", "gcloud node", "google app engine", "node.js"
],
"repository": {
"type": "git",
Expand Down
19 changes: 19 additions & 0 deletions test/model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ describe('Model', function() {
expect(ds.get.getCall(0).args[0].id).equal(123);
});

it('not converting string with mix of number and non number', () => {
ModelInstance.get('123:456', () => {});

expect(ds.get.getCall(0).args[0].name).equal('123:456');
});

it('passing an ancestor path array', () => {
let ancestors = ['Parent', 'keyname'];

Expand Down Expand Up @@ -442,6 +448,12 @@ describe('Model', function() {
expect(transaction.get.getCall(0).args[0].path[1]).equal(123);
});

it('not converting string id with mix of number and alpha chars', () => {
ModelInstance.update('123:456', () => {});

expect(transaction.get.getCall(0).args[0].name).equal('123:456');
});

it('should rollback if error while getting entity', function(done) {
transaction.get.restore();

Expand Down Expand Up @@ -625,6 +637,13 @@ describe('Model', function() {
});
});

it('not converting string id with mix of number and alpha chars', (done) => {
ModelInstance.delete('123:456', () => {
expect(ds.delete.getCall(0).args[0].name).equal('123:456');
done();
});
});

it('should allow array of ids', (done) => {
ModelInstance.delete([22, 69], (err, response) => {
expect(is.array(ds.delete.getCall(0).args[0])).be.true;
Expand Down

0 comments on commit 493e45e

Please sign in to comment.