Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade lodash to version 4. #5

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 6 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
[![npm version](https://badge.fury.io/js/%40jitterbit%2Fnpdynamodb.svg)](https://badge.fury.io/js/%40jitterbit%2Fnpdynamodb) [![Actions Status](https://github.com/jitterbit/npdynamodb/workflows/Test/badge.svg)](https://github.com/jitterbit/npdynamodb/actions)

Forked from [noppoMan/npdynamodb](https://github.com/noppoMan/npdynamodb).
This fork intends primarily to maintain the migration capabilities of the original package. No testing, beyond the original
unit tests, is done on any area besides the migrator.

---

A Node.js Simple Query Builder and ORM for AWS DynamoDB.

## Motivation
When I visited [here ](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#query-property
) for the first time, I closed it in a moment.
When I visited [here](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#query-property) for the first time, I closed it in a moment.
Because it is too long and hard to see to understand.
So I decided to make client to handle DynamoDB more easier and it doesn't take waste of time to read documentation for it.

Expand All @@ -20,7 +23,7 @@ So I decided to make client to handle DynamoDB more easier and it doesn't take w

## Installation
```sh
npm install npdynamodb
npm install @jitterbit/npdynamodb
```

## Why is the Pure AWS-SDK in Node.js NOT good?
Expand Down Expand Up @@ -649,50 +652,6 @@ npdynamodb.plugin(function(Klass){
### Available Plugins
* [npdynamodb-typecast](https://github.com/noppoMan/npdynamodb-typecast) For casting hash and range key to actual attribution type

## Browser Support
Npdynamodb can be built using browserify or webpack, and pre-built or pre-built with uglified version can be found in the build directory.

### For Browserify or Webpack
```js
var AWS = require('aws-sdk');
var npdynamodb = require('npdynamodb/build/npdynamodb');

var dynamodb = new AWS.DynamoDB({
apiVersion: '2012-08-10',
accessKeyId: "here is key",
secretAccessKey: "here is secret key",
region: "ap-northeast-1",
sslEnabled: true,
});

var npd = npdynamodb.createClient(dynamodb);
npd().table('table_name').where('id', 1).then(function(data){
console.log(data);
});
```

### For HTML
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.1.39/aws-sdk.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/2.9.33/bluebird.min.js"></script>
<script src="../build/npdynamodb.min.js"></script>
<script>
var dynamodb = new AWS.DynamoDB({
apiVersion: '2012-08-10',
accessKeyId: "here is key",
secretAccessKey: "here is secret key",
region: "ap-northeast-1",
sslEnabled: true,
});

var npd = npdynamodb.createClient(dynamodb);
npd().table('table_name').where('id', 1).then(function(data){
console.log(data);
});
</script>
```

## Upgrading and Release Note
#### Upgrading 0.1x -> 0.2x

Expand Down
7 changes: 0 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

var _ = require('lodash');

// For Browser
if(typeof(window) === 'object') {
window.npdynamodb = exports;
window.DynamoDBDatatype = require('./node_modules/dynamodb-doc/lib/datatypes').DynamoDBDatatype;
window.DynamoDBFormatter = require('./node_modules/dynamodb-doc/lib/formatter').DynamoDBFormatter;
}

exports.version = require('./package.json').version;

exports.createClient = require('./lib/npdynamodb');
Expand Down
4 changes: 1 addition & 3 deletions lib/bin/npd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
'use strict';

var Liftoff = require('liftoff');
var Liftoff = require('liftoff');
var interpret = require('interpret');
var program = require('commander');
var fs = require('fs');
Expand All @@ -11,8 +11,6 @@ var argv = require('minimist')(process.argv.slice(2));
var chalk = require('chalk');
var _ = require('lodash');
var Migrator = require('../migrate/migrator');
var fs = require('fs');
var repl = require("repl");
var util = require('util');
var npdynamod = require('../../index');

Expand Down
3 changes: 1 addition & 2 deletions lib/dialects/2012-08-10/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var _ = require('lodash');
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var DOC = require("dynamodb-doc");

var utils = require('../../utils');
var api = require('./api');
Expand Down Expand Up @@ -198,7 +197,7 @@ _.each([
function addConditions(){
var args = _.toArray(arguments);
var col = args[1], op = args[2], val = args[3];
if(!_.contains(availableOperators, op)){
if(!_.includes(availableOperators, op)){
val = op;
op = '=';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/migrate/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ MigrateRunner.prototype.run = function(){
var version = dir.split('_')[0];
if (version == parseInt(version)
&& dir.indexOf(migration_suffix, dir.length - migration_suffix.length) !== -1){
if(!_.contains(versions, parseInt(version))) {
if(!_.includes(versions, parseInt(version))) {
return dir;
}
}
Expand Down Expand Up @@ -211,7 +211,7 @@ MigrateRunner.prototype.rollback = function(){
return data.version;
})).reverse();

var lastVersion = _.first(versions);
var lastVersion = _.head(versions);
if(!lastVersion) {
return Promise.resolve(null);
}
Expand Down
20 changes: 7 additions & 13 deletions lib/orm/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ Collection.prototype.at = function(index){
return this.indexAt(index);
};

_.each([
'pluck'
], function(name){
Collection.prototype[name] = function(){
var args = [this.toArray()].concat(_.map(arguments, function(arg){ return arg; }));
return _[name].apply(_, args);
};
});
Collection.prototype.pluck = function(){
var args = [this.toArray()].concat(_.map(arguments, function(arg){ return arg; }));
return _.map.apply(_, args);
};

_.each([
'each',
Expand All @@ -42,21 +38,19 @@ _.each([
'reduceRight',
'find',
'filter',
'where',
'findWhere',
'reject',
'every',
'some',
'invoke',
'invokeMap',
'sortBy',
'groupBy',
'indexBy',
'keyBy',
'countBy',
'shuffle',
'sample',
'size',
'partition',
'first',
'head',
'last',
'isEmpty'
], function(name){
Expand Down
31 changes: 12 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jitterbit/npdynamodb",
"version": "0.3.0",
"version": "0.3.1",
"description": "A Node.js Simple Query Builder and ORM for AWS DynamoDB.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -32,7 +32,8 @@
"url": "http://miketokyo.com"
},
{
"name": "Jitterbit"
"name": "Jitterbit",
"url": "https://jitterbit.com"
}
],
"license": "MIT",
Expand All @@ -42,28 +43,20 @@
"homepage": "https://github.com/jitterbit/npdynamodb#readme",
"dependencies": {
"bluebird": "^2.9.24",
"chalk": "^1.0.0",
"commander": "^2.7.1",
"chalk": "^1.1.3",
"commander": "^2.20.3",
"dynamodb-doc": "^1.0.0",
"glob": "^5.0.3",
"glob": "^5.0.15",
"interpret": "^0.5.2",
"json-loader": "0.5.2",
"liftoff": "^2.0.3",
"lodash": "^3.5.0",
"minimist": "^1.1.1",
"liftoff": "^2.5.0",
"lodash": "^4.17.15",
"minimist": "^1.2.5",
"readline": "0.0.7",
"uglify-js": "2.4.24",
"v8flags": "^2.0.3",
"webpack": "1.10.1"
"v8flags": "^2.1.1"
},
"devDependencies": {
"aws-sdk": "^2.1.18",
"chai": "^2.2.0",
"aws-sdk": "^2.643.0",
"chai": "^2.3.0",
"mocha": "^6.2.2"
},
"browser": {
"./lib/migrate/migrator.js": false,
"./lib/dialects/2012-08-10/schema.js": false,
"aws-sdk": false
}
}
15 changes: 0 additions & 15 deletions scripts/build.sh

This file was deleted.

54 changes: 0 additions & 54 deletions scripts/webpack.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/data/complex_table_seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var stabData = _.range(1, 11).map(function(i){
gsi_hash_key: "gkey1", //gsi
lsi_range_key: i, // lsi
bool: true,
binary: new Buffer([1,2,3,4]),
binary: Buffer.from([1,2,3,4]),
null: true,
stringSet: ["foo", "bar"],
numberSet: [1, 2],
binarySet: [new Buffer([1,2,3,4]), new Buffer([5,6,7,8])],
binarySet: [Buffer.from([1,2,3,4]), Buffer.from([5,6,7,8])],
document: {
number1: 1,
string1: "foo",
Expand Down
6 changes: 3 additions & 3 deletions test/orm_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('ORM', function(){
return chatCollection;
})
.then(function(chatCollection){
var chat = chatCollection.first();
var chat = chatCollection.head();
expect(chat.get("room_id")).to.equal('room1');
expect(chat.get("timestamp")).to.equal(1429291245);
return chatCollection;
Expand All @@ -115,7 +115,7 @@ describe('ORM', function(){
})
.then(function(chatCollection){
var chats = chatCollection.map(function(chat){
chat.set('timestamp', chat.get('timestamp') -1);
chat.set('timestamp', chat.get('timestamp') - 1);
return chat;
});
expect(chats[0].get("timestamp")).to.equal(1429291244);
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('ORM', function(){

it("Should each models in collection save changes", function(done){
Chat.where('room_id', 'room1').fetch().then(function(chats){
return chats.first().set('message', 'this is a updated message').save()
return chats.head().set('message', 'this is a updated message').save()
.then(function(chat){
return chat.reload();
});
Expand Down
2 changes: 1 addition & 1 deletion test/query_builder_read_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Promise = require('bluebird')
var Promise = require('bluebird');
var chai = require('chai');
var expect = chai.expect;
var _ = require('lodash');
Expand Down
Loading