diff --git a/build/npdynamodb.js b/build/npdynamodb.js index d3f8bed..b39e195 100644 --- a/build/npdynamodb.js +++ b/build/npdynamodb.js @@ -747,7 +747,7 @@ return /******/ (function(modules) { // webpackBootstrap module.exports = { "name": "npdynamodb", - "version": "0.2.9", + "version": "0.2.11", "description": "A Node.js Simple Query Builder and ORM for AWS DynamoDB.", "main": "index.js", "scripts": { @@ -925,9 +925,9 @@ return /******/ (function(modules) { // webpackBootstrap ], function(promiseInterface){ QueryBuilder.prototype[promiseInterface] = function(cb){ var self = this; - var gotResponse = false; var feature = self._feature; var callbacks = this._callbacks; + var timer; return Promise.all(callbacksPromisified.bind(self)(callbacks.beforeQuery)).then(function(){ var built = feature.buildQuery(); @@ -935,7 +935,10 @@ return /******/ (function(modules) { // webpackBootstrap return new Promise(function(resolve, reject){ var request = feature.client[built.method](built.params, function(err, data){ - gotResponse = true; + if(timer) { + clearTimeout(timer); + timer = null; + } if(err) { return reject(err); } @@ -944,11 +947,9 @@ return /******/ (function(modules) { // webpackBootstrap // Handle timeout if(self._options.timeout !== null) { - setTimeout(function(){ - if(!gotResponse) { - request.abort(); - reject(new Error("The connection has timed out.")); - } + timer = setTimeout(function(){ + request.abort(); + reject(new Error("The connection has timed out.")); }, self._options.timeout || 5000); } }); @@ -991,6 +992,7 @@ return /******/ (function(modules) { // webpackBootstrap 'filterContains', 'filterNotContains', 'limit', + 'offset', 'desc', 'asc', 'create', @@ -2288,6 +2290,10 @@ return /******/ (function(modules) { // webpackBootstrap this.nextThen = 'query'; }; + Feature.prototype.offset = function(exclusiveStartKey){ + this.exclusiveStartKey(exclusiveStartKey); + }; + Feature.prototype.whereIn = function(keys, values){ //items[this.conditions.TableName] = {}; if(!_.isArray(keys)) { diff --git a/build/npdynamodb.min.js b/build/npdynamodb.min.js index 834f24b..17a682d 100644 --- a/build/npdynamodb.min.js +++ b/build/npdynamodb.min.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("lodash"),require("aws-sdk"),require("bluebird")):"function"==typeof define&&define.amd?define(["lodash","aws-sdk","bluebird"],e):"object"==typeof exports?exports.npdynamodb=e(require("lodash"),require("aws-sdk"),require("bluebird")):t.npdynamodb=e(t._,t.AWS,t.Promise)}(this,function(t,e,n){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var r=n(2);"object"==typeof window&&(window.npdynamodb=e,window.DynamoDBDatatype=n(3).DynamoDBDatatype,window.DynamoDBFormatter=n(5).DynamoDBFormatter),e.version=n(6).version,e.createClient=n(7),e.define=n(27),e.Migrator=n(1);var i=n(8),o=n(29),s=n(28);[i,o,s].forEach(function(t){t.extend=function(e,n){r.extend(t.prototype,e||{}),r.extend(t,n||{})}}),e.plugin=function(t){if("function"!=typeof t)throw new Error("The plugin must be function.");t({QueryBuilder:i,Collection:o,Model:s})},e.Collection=n(29),e.Model=n(28)},function(t,e){},function(e,n){e.exports=t},function(t,e,n){"use strict";function r(){function t(t){var e=typeof t;return"number"===e||"string"===e||"boolean"===e||t instanceof Uint8Array&&c.util.isBrowser()||t instanceof c.util.Buffer||null===t}function e(t){return"SS"===t.datatype||"NS"===t.datatype||"BS"===t.datatype}function r(t){return Array.isArray(t)||"object"==typeof t}function i(t,e){return"NS"===t?e.map(function(t){return t.toString()}):e}function o(t){var e={},n={},r="M";Array.isArray(t)&&(n=[],r="L");for(var i in t)n[i]=this.formatDataType(t[i]);return e[r]=n,e}function s(t){if(null==t)return{NULL:!0};var e=typeof t;if("string"===e)return{S:t};if("number"===e)return{N:String(t)};if("boolean"===e)return{BOOL:t};if(t instanceof c.util.Buffer)return{B:t};if(t instanceof Uint8Array){if(c.util.isBrowser())return{B:t};throw new Error(f)}throw new Error(p)}function a(t){if("string"!=typeof t)throw new Error(d);if(c.util.isBrowser()){for(var e=t.length,n=new Uint8Array(new ArrayBuffer(e)),r=0;e>r;r++)n[r]=t.charCodeAt(r);return n}return c.util.Buffer(t)}function u(t){if(!(t instanceof c.util.Buffer||t instanceof Uint8Array))throw new Error(h);return c.util.isBrowser()?String.fromCharCode.apply(null,t):t.toString("utf-8").valueOf()}var c="undefined"==typeof window?n(4):window.AWS,f="Uint8Array can only be used for Binary in Browser.",p="Unrecognized Scalar Datatype to be formatted.",l="Unrecognized Datatype to be formatted.",h="Need to pass in Buffer or Uint8Array. ",d="Need to pass in string primitive to be converted to binary.";this.formatDataType=function(n){if(t(n))return s(n);if(e(n))return n.format();if(r(n))return o.call(this,n);throw new Error(l)},this.strToBin=function(t){return a.call(this,t)},this.binToStr=function(t){return u.call(this,t)},this.createSet=function(t,e){if("N"!==e&&"S"!==e&&"B"!==e)throw new Error(e+" is an invalid type for Set");var n=function(t,e){if(this.datatype=e+"S",this.contents={},this.add=function(t){if("SS"===this.datatype&&"string"==typeof t)this.contents[t]=t;else if("NS"===this.datatype&&"number"==typeof t)this.contents[t]=t;else if("BS"===this.datatype&&t instanceof c.util.Buffer)this.contents[u(t)]=t;else{if(!("BS"===this.datatype&&t instanceof Uint8Array))throw new Error("Inconsistent in this "+e+" Set");if(!c.util.isBrowser())throw new Error(f);this.contents[u(t)]=t}},this.contains=function(t){var e=t;return(t instanceof c.util.Buffer||t instanceof Uint8Array)&&(e=u(t)),void 0===this.contents[e]?!1:!0},this.remove=function(t){var e=t;(t instanceof c.util.Buffer||t instanceof Uint8Array)&&(e=u(t)),delete this.contents[e]},this.toArray=function(){var t=Object.keys(this.contents),e=[];for(var n in t){var r=t[n];this.contents.hasOwnProperty(r)&&e.push(this.contents[r])}return e},this.format=function(){var t=this.toArray(),e={};return e[this.datatype]=i(this.datatype,t),e},t)for(var n in t)this.add(t[n])};return new n(t,e)},this.formatWireType=function(t,e){switch(t){case"S":case"B":case"BOOL":return e;case"N":return Number(e);case"NULL":return null;case"L":for(var n=0;n (http://miketokyo.com)",license:"MIT",bugs:{url:"https://github.com/noppoMan/npdynamodb/issues"},homepage:"https://github.com/noppoMan/npdynamodb",dependencies:{bluebird:"^2.9.24",chalk:"^1.0.0",commander:"^2.7.1","dynamodb-doc":"^1.0.0",glob:"^5.0.3",interpret:"^0.5.2",liftoff:"^2.0.3",lodash:"^3.5.0",minimist:"^1.1.1",readline:"0.0.7",v8flags:"^2.0.3"},devDependencies:{"aws-sdk":"^2.1.18",chai:"^2.2.0"},browser:{"./lib/migrate/migrator.js":!1,"./lib/dialects/2012-08-10/schema.js":!1,"aws-sdk":!1}}},function(t,e,n){"use strict";function r(t,e){var n=new i(t,e);return n}var i=n(8),o=n(25),s=n(18),a={};t.exports=function(t,e){var i=t.config.apiVersion,u=n(26)("./"+i+"/api");a[i]||(a[i]=o(t,u.originalApis));var c={dynamodb:"function"==typeof t.Condition?t:new s.DynamoDB(t),promisifidRawClient:a[i]};return function(){return r(c,e)}}},function(t,e,n){"use strict";function r(t,e){u.call(this);var n=new f[t.dynamodb.config.apiVersion](t),r=e||{};r.initialize;this.apiVersion=n.client.config.apiVersion,this._feature=n,this._options=s.omit(r,"initialize"),this._initializer=r.initialize,this._callbacks={},"function"==typeof this._initializer&&this._initializer.bind(this)()}function i(t,e){return(t||[]).map(function(t){return t.bind(this)(e)}.bind(this))}var o=n(9),s=n(2),a=n(10),u=n(11).EventEmitter,c=n(12),f=(n(16),{"2012-08-10":n(17)});t.exports=r,c.inherits(r,u),o.forEach(function(t){r.prototype[t]=function(){return this._feature[t].apply(this._feature,s.toArray(arguments)),this}}),r.prototype.freshBuilder=function(){return new r({dynamodb:this._feature.client,promisifidRawClient:this._feature.promisifidRawClient},s.clone(s.extend(this._options,{initialize:this._initializer})))},r.prototype.tableName=function(){return this._feature.conditions.TableName},r.prototype.normalizationRawResponse=function(t){return this._feature.normalizationRawResponse(t)},r.prototype.feature=function(t){return t(this._feature),this},r.prototype.rawClient=function(t){return this._feature.promisifidRawClient},r.prototype.callbacks=function(t,e){return this._callbacks[t]||(this._callbacks[t]=[]),this._callbacks[t].push(e),this},s.each(["then"],function(t){r.prototype[t]=function(t){var e=this,n=!1,r=e._feature,o=this._callbacks;return a.all(i.bind(e)(o.beforeQuery)).then(function(){var t=r.buildQuery();return e.emit("beforeQuery",t.params),new a(function(i,o){var s=r.client[t.method](t.params,function(t,e){return n=!0,t?o(t):void i(e)});null!==e._options.timeout&&setTimeout(function(){n||(s.abort(),o(new Error("The connection has timed out.")))},e._options.timeout||5e3)})}).then(function(t){return a.all(i.bind(e)(o.afterQuery,t)).then(function(){return e.emit("afterQuery",t),t})}).then(function(n){return t.bind(e)(n)})}})},function(t,e){"use strict";t.exports=["select","table","count","all","where","first","whereIn","whereBetween","whereBeginsWith","filterBetween","filterBeginsWith","filter","filterIn","filterNull","filterNotNull","filterContains","filterNotContains","limit","desc","asc","create","update","set","delete","showTables","indexName","describe","createTable","deleteTable"]},function(t,e){t.exports=n},function(t,e){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(t){return"function"==typeof t}function i(t){return"number"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(t){return void 0===t}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!i(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,n,i,a,u,c;if(this._events||(this._events={}),"error"===t&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[t],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(i=arguments.length,a=new Array(i-1),u=1;i>u;u++)a[u-1]=arguments[u];n.apply(this,a)}else if(o(n)){for(i=arguments.length,a=new Array(i-1),u=1;i>u;u++)a[u-1]=arguments[u];for(c=n.slice(),i=c.length,u=0;i>u;u++)c[u].apply(this,a)}return!0},n.prototype.addListener=function(t,e){var i;if(!r(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,r(e.listener)?e.listener:e),this._events[t]?o(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,o(this._events[t])&&!this._events[t].warned){var i;i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[t].length>i&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,i,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,i=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(a=s;a-->0;)if(n[a]===e||n[a].listener&&n[a].listener===e){i=a;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?r(t._events[e])?1:t._events[e].length:0}},function(t,e,n){(function(t,r){function i(t,n){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),y(n)?r.showHidden=n:n&&e._extend(r,n),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),u(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function u(t,n,r){if(t.customInspect&&n&&A(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return g(i)||(i=u(t,i,r)),i}var o=c(t,n);if(o)return o;var s=Object.keys(n),y=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),T(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(n);if(0===s.length){if(A(n)){var m=n.name?": "+n.name:"";return t.stylize("[Function"+m+"]","special")}if(x(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(E(n))return t.stylize(Date.prototype.toString.call(n),"date");if(T(n))return f(n)}var v="",b=!1,w=["{","}"];if(d(n)&&(b=!0,w=["[","]"]),A(n)){var _=n.name?": "+n.name:"";v=" [Function"+_+"]"}if(x(n)&&(v=" "+RegExp.prototype.toString.call(n)),E(n)&&(v=" "+Date.prototype.toUTCString.call(n)),T(n)&&(v=" "+f(n)),0===s.length&&(!b||0==n.length))return w[0]+v+w[1];if(0>r)return x(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var D;return D=b?p(t,n,r,y,s):s.map(function(e){return l(t,n,r,y,e,b)}),t.seen.pop(),h(D,v,w)}function c(t,e){if(_(e))return t.stylize("undefined","undefined");if(g(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return b(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):m(e)?t.stylize("null","null"):void 0}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function p(t,e,n,r,i){for(var o=[],s=0,a=e.length;a>s;++s)N(e,String(s))?o.push(l(t,e,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(l(t,e,n,r,i,!0))}),o}function l(t,e,n,r,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},c.get?a=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(a=t.stylize("[Setter]","special")),N(r,i)||(s="["+i+"]"),a||(t.seen.indexOf(c.value)<0?(a=m(n)?u(t,c.value,null):u(t,c.value,n-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function h(t,e,n){var r=0,i=t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function d(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function m(t){return null===t}function v(t){return null==t}function b(t){return"number"==typeof t}function g(t){return"string"==typeof t}function w(t){return"symbol"==typeof t}function _(t){return void 0===t}function x(t){return D(t)&&"[object RegExp]"===S(t)}function D(t){return"object"==typeof t&&null!==t}function E(t){return D(t)&&"[object Date]"===S(t)}function T(t){return D(t)&&("[object Error]"===S(t)||t instanceof Error)}function A(t){return"function"==typeof t}function O(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function S(t){return Object.prototype.toString.call(t)}function B(t){return 10>t?"0"+t.toString(10):t.toString(10)}function C(){var t=new Date,e=[B(t.getHours()),B(t.getMinutes()),B(t.getSeconds())].join(":");return[t.getDate(),L[t.getMonth()],e].join(" ")}function N(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var j=/%[sdj%]/g;e.format=function(t){if(!g(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return t}}),a=r[n];o>n;a=r[++n])s+=m(a)||!D(a)?" "+a:" "+i(a);return s},e.deprecate=function(n,i){function o(){if(!s){if(r.throwDeprecation)throw new Error(i);r.traceDeprecation?console.trace(i):console.error(i),s=!0}return n.apply(this,arguments)}if(_(t.process))return function(){return e.deprecate(n,i).apply(this,arguments)};if(r.noDeprecation===!0)return n;var s=!1;return o};var I,k={};e.debuglog=function(t){if(_(I)&&(I=r.env.NODE_DEBUG||""),t=t.toUpperCase(),!k[t])if(new RegExp("\\b"+t+"\\b","i").test(I)){var n=r.pid;k[t]=function(){var r=e.format.apply(e,arguments);console.error("%s %d: %s",t,n,r)}}else k[t]=function(){};return k[t]},e.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=d,e.isBoolean=y,e.isNull=m,e.isNullOrUndefined=v,e.isNumber=b,e.isString=g,e.isSymbol=w,e.isUndefined=_,e.isRegExp=x,e.isObject=D,e.isDate=E,e.isError=T,e.isFunction=A,e.isPrimitive=O,e.isBuffer=n(14);var L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];e.log=function(){console.log("%s - %s",C(),e.format.apply(e,arguments))},e.inherits=n(15),e._extend=function(t,e){if(!e||!D(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}}).call(e,function(){return this}(),n(13))},function(t,e){function n(){c=!1,s.length?u=s.concat(u):f=-1,u.length&&r()}function r(){if(!c){var t=setTimeout(n);c=!0;for(var e=u.length;e;){for(s=u,u=[];++f1)for(var n=1;n0&&this.whereConditions.length>0)throw new Error("Can not specify the parameters of batchGetImte and Query operation at the same time");var r=t(l[e])||function(){return{beforeQuery:function(){},conditions:{},nextThen:e}},i=r();return i.beforeQuery.call(this),this.nextThen=i.nextThen,this.conditions=o.extend(this.conditions,i.conditions),{params:this.conditions,method:this.nextThen}},t.exports=r},function(t,e,n){"use strict";function r(t){var e="undefined"==typeof window,r=e?n(4):window.AWS,i=e?n(19).DynamoDBCondition:window.DynamoDBCondition,o=e?n(3).DynamoDBDatatype:window.DynamoDBDatatype,s=new o,a=e?n(5).DynamoDBFormatter:window.DynamoDBFormatter,u=new a,c=t||new r.DynamoDB,f=c.setupRequestListeners;return c.setupRequestListeners=function(t){f.call(this,t),t._events.validate.unshift(u.formatInput),t.on("extractData",u.formatOutput)},c.__proto__.Set=function(t,e){return s.createSet(t,e)},c.__proto__.Condition=function(t,e,n,r){return i(t,e,n,r)},c.__proto__.StrToBin=function(t){return s.strToBin(t)},c.__proto__.BinToStr=function(t){return s.binToStr(t)},c}var e=t.exports={};e.DynamoDB=r},function(t,e,n){"use strict";function r(t,e,r,i){var o="undefined"==typeof window?n(3).DynamoDBDatatype:window.DynamoDBDatatype,s=new o,a=function(t,e,n,r){this.key=t,this.operator=e,this.val1=n,this.val2=r,this.format=function(){var t={},e=[];return void 0!==this.val1&&e.push(s.formatDataType(this.val1)),void 0!==this.val2&&e.push(s.formatDataType(this.val2)),e.length>0&&(t.AttributeValueList=e),t.ComparisonOperator=this.operator,t}},u=new a(t,e,r,i);return u.prototype=Object.create(Object.prototype),u.prototype.instanceOf="DynamoDBConditionObject",u}var e=t.exports={};e.DynamoDBCondition=r},function(t,e,n){(function(e){function r(){if(this.AWS)return this.AWS.apiLoader.services.dynamodb["2012-08-10"].operations;var t="aws-sdk/apis/dynamodb-2012-08-10.min.json";try{return n(22)(t).operations}catch(r){var i=e.cwd()+"/node_modules/"+t;if(s.existsSync(i))return n(22)(i).operations;throw new TypeError("Module `aws-sdk` is required for npdynamodb")}}var i=n(2),o=n(16),s=n(21),a=r(this),u=[{origin:"createTable",transformed:"createTable"},{origin:"deleteTable",transformed:"deleteTable"},{origin:"deleteItem",transformed:"delete"},{origin:"describeTable",transformed:"describe"},{origin:"listTables",transformed:"showTables"},{origin:"putItem",transformed:"create"},{origin:"updateItem",transformed:"update"},{origin:"getItem",transformed:"first"},{origin:"query",transformed:"query"},{origin:"scan",transformed:"all"},{origin:"updateTable",transformed:"alterTable"},{origin:"waitFor",transformed:"waitFor"}],c={"=":"EQ","!=":"NE","<=":"LE","<":"LT",">=":"GE",">":"GT"};t.exports={operations:a,originalApis:i.keys(a).map(function(t){return i.camelCase(t)}).concat(["waitFor"]),transformFunctionMap:o.collectionFlatten(u.map(function(t){return o.newObject(t.transformed,t.origin)})),transformOperatorMap:c,availableOperators:i.keys(c)}}).call(e,n(13))},function(t,e){},function(t,e,n){function r(t){return n(i(t))}function i(t){return o[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var o={"./api":20,"./api.js":20,"./feature":17,"./feature.js":17,"./schema":23,"./schema.js":24};r.keys=function(){return Object.keys(o)},r.resolve=i,t.exports=r,r.id=22},function(t,e){},function(t,e){},function(t,e,n){"use strict";var r=n(10);t.exports=function(t,e){var n={};return e.forEach(function(e){n[e]=r.promisify(t[e],t)}),n}},function(t,e,n){function r(t){return n(i(t))}function i(t){return o[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var o={"./2012-08-10/api":20};r.keys=function(){return Object.keys(o)},r.resolve=i,t.exports=r,r.id=26},function(t,e,n){"use strict";var r=n(2),i=(n(12),n(16),n(7),n(28));t.exports=function(t,e,n){function o(n){this.tableName=t,r.extend(this,r.pick.apply(null,[e].concat(s))),this._attributes=n||{},this._builder=this.npdynamodb().table(t)}var s=["hashKey","rangeKey","npdynamodb"];return r.extend(o.prototype,r.clone(i.prototype)),r.each(r.omit.apply(null,[e].concat(s)),function(t,e){t.hasOwnProperty("bind")?o.prototype[e]=function(){return t.bind(this,r.toArray(arguments))}:o.prototype[e]=t}),r.each(["find","where","query","fetch","save"],function(t){o[t]=function(){var e=new o;return e[t].apply(e,r.toArray(arguments))}}),r.each(n,function(t,e){t.hasOwnProperty("bind")?o[e]=t.bind(o):o[e]=t}),o}},function(t,e,n){"use strict";function r(t,e){var n=this;return a(t,function(t){return n._refreshBuilder(),e(t)}).bind(this)}function i(){}var o=n(2),s=n(29),a=n(30);t.exports=i,i.prototype.where=function(){return this._builder.where.apply(this._builder,arguments),this},i.prototype.query=function(t){return"function"==typeof t?(t(this._builder),this):this._builder},i.prototype.find=function(t,e){var n=this,i=this._builder.where(this.hashKey,t);return e&&i.where(this.rangeKey,e),r.bind(this)(i.first(),function(t){return n._attributes=n._builder.normalizationRawResponse(t), -n})},i.prototype.reload=function(){return this.find(this.get(this.hashKey),this.get(this.rangeKey))},i.prototype.fetch=function(){var t=this;return r.bind(this)(this._builder,function(e){var n=t._builder.normalizationRawResponse(e),r=n.map(function(e){return new t.constructor(e)});return new s(r)})},i.prototype.save=function(t){var e=this;return"object"==typeof t&&o.extend(this._attributes,t),r.bind(this)(this._builder.create(this.attributes()),function(){return e})},i.prototype.destroy=function(t){var e=this,n=this._builder.where(this.hashKey,this.get(this.hashKey));return this.rangeKey&&n.where(this.rangeKey,this.get(this.rangeKey)),r.bind(this)(n["delete"](),function(){return e._attributes={},e})},i.prototype.set=function(t,e){return this._attributes[t]=e,this},i.prototype.unset=function(t){return this._attributes[t]&&delete this._attributes[t],this},i.prototype.extend=function(t){return o.extend(this._attributes,t),this},i.prototype.get=function(t){return this._attributes[t]},i.prototype.isEmpty=function(){return o.isEmpty(this._attributes)},i.prototype.attributes=function(){return this._attributes},i.prototype.toJson=function(){return JSON.stringify(this._attributes)},i.prototype._refreshBuilder=function(){this._builder=this.npdynamodb().table(this.tableName)},o.each(["each","map","includes","contains","keys","pick","values"],function(t){i.prototype[t]=function(){var e=[this._item].concat(o.map(arguments,function(t){return t}));return o[t].apply(o,e)}})},function(t,e,n){"use strict";function r(t){this._items=t}var i=n(2);t.exports=r,r.prototype.toArray=function(){return this._items.map(function(t){return t.attributes()})},r.prototype.toJSON=function(){return JSON.stringify(this.toArray())},r.prototype.indexAt=function(t){return this._items[t]},r.prototype.at=function(t){return this.indexAt(t)},i.each(["pluck"],function(t){r.prototype[t]=function(){var e=[this.toArray()].concat(i.map(arguments,function(t){return t}));return i[t].apply(i,e)}}),i.each(["each","map","reduce","reduceRight","find","filter","where","findWhere","reject","every","some","invoke","sortBy","groupBy","indexBy","countBy","shuffle","sample","size","partition","first","last","isEmpty"],function(t){r.prototype[t]=function(){var e=[this._items].concat(i.map(arguments,function(t){return t}));return i[t].apply(i,e)}})},function(t,e,n){"use strict";var r=n(10);t.exports=function(t,e){return new r(function(n,r){return t.then(function(t){return e||(e=function(t){return t}),n(e(t))})["catch"](r)})}}])}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("lodash"),require("aws-sdk"),require("bluebird")):"function"==typeof define&&define.amd?define(["lodash","aws-sdk","bluebird"],e):"object"==typeof exports?exports.npdynamodb=e(require("lodash"),require("aws-sdk"),require("bluebird")):t.npdynamodb=e(t._,t.AWS,t.Promise)}(this,function(t,e,n){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var r=n(2);"object"==typeof window&&(window.npdynamodb=e,window.DynamoDBDatatype=n(3).DynamoDBDatatype,window.DynamoDBFormatter=n(5).DynamoDBFormatter),e.version=n(6).version,e.createClient=n(7),e.define=n(27),e.Migrator=n(1);var i=n(8),o=n(29),s=n(28);[i,o,s].forEach(function(t){t.extend=function(e,n){r.extend(t.prototype,e||{}),r.extend(t,n||{})}}),e.plugin=function(t){if("function"!=typeof t)throw new Error("The plugin must be function.");t({QueryBuilder:i,Collection:o,Model:s})},e.Collection=n(29),e.Model=n(28)},function(t,e){},function(e,n){e.exports=t},function(t,e,n){"use strict";function r(){function t(t){var e=typeof t;return"number"===e||"string"===e||"boolean"===e||t instanceof Uint8Array&&c.util.isBrowser()||t instanceof c.util.Buffer||null===t}function e(t){return"SS"===t.datatype||"NS"===t.datatype||"BS"===t.datatype}function r(t){return Array.isArray(t)||"object"==typeof t}function i(t,e){return"NS"===t?e.map(function(t){return t.toString()}):e}function o(t){var e={},n={},r="M";Array.isArray(t)&&(n=[],r="L");for(var i in t)n[i]=this.formatDataType(t[i]);return e[r]=n,e}function s(t){if(null==t)return{NULL:!0};var e=typeof t;if("string"===e)return{S:t};if("number"===e)return{N:String(t)};if("boolean"===e)return{BOOL:t};if(t instanceof c.util.Buffer)return{B:t};if(t instanceof Uint8Array){if(c.util.isBrowser())return{B:t};throw new Error(f)}throw new Error(p)}function a(t){if("string"!=typeof t)throw new Error(d);if(c.util.isBrowser()){for(var e=t.length,n=new Uint8Array(new ArrayBuffer(e)),r=0;e>r;r++)n[r]=t.charCodeAt(r);return n}return c.util.Buffer(t)}function u(t){if(!(t instanceof c.util.Buffer||t instanceof Uint8Array))throw new Error(h);return c.util.isBrowser()?String.fromCharCode.apply(null,t):t.toString("utf-8").valueOf()}var c="undefined"==typeof window?n(4):window.AWS,f="Uint8Array can only be used for Binary in Browser.",p="Unrecognized Scalar Datatype to be formatted.",l="Unrecognized Datatype to be formatted.",h="Need to pass in Buffer or Uint8Array. ",d="Need to pass in string primitive to be converted to binary.";this.formatDataType=function(n){if(t(n))return s(n);if(e(n))return n.format();if(r(n))return o.call(this,n);throw new Error(l)},this.strToBin=function(t){return a.call(this,t)},this.binToStr=function(t){return u.call(this,t)},this.createSet=function(t,e){if("N"!==e&&"S"!==e&&"B"!==e)throw new Error(e+" is an invalid type for Set");var n=function(t,e){if(this.datatype=e+"S",this.contents={},this.add=function(t){if("SS"===this.datatype&&"string"==typeof t)this.contents[t]=t;else if("NS"===this.datatype&&"number"==typeof t)this.contents[t]=t;else if("BS"===this.datatype&&t instanceof c.util.Buffer)this.contents[u(t)]=t;else{if(!("BS"===this.datatype&&t instanceof Uint8Array))throw new Error("Inconsistent in this "+e+" Set");if(!c.util.isBrowser())throw new Error(f);this.contents[u(t)]=t}},this.contains=function(t){var e=t;return(t instanceof c.util.Buffer||t instanceof Uint8Array)&&(e=u(t)),void 0===this.contents[e]?!1:!0},this.remove=function(t){var e=t;(t instanceof c.util.Buffer||t instanceof Uint8Array)&&(e=u(t)),delete this.contents[e]},this.toArray=function(){var t=Object.keys(this.contents),e=[];for(var n in t){var r=t[n];this.contents.hasOwnProperty(r)&&e.push(this.contents[r])}return e},this.format=function(){var t=this.toArray(),e={};return e[this.datatype]=i(this.datatype,t),e},t)for(var n in t)this.add(t[n])};return new n(t,e)},this.formatWireType=function(t,e){switch(t){case"S":case"B":case"BOOL":return e;case"N":return Number(e);case"NULL":return null;case"L":for(var n=0;n (http://miketokyo.com)",license:"MIT",bugs:{url:"https://github.com/noppoMan/npdynamodb/issues"},homepage:"https://github.com/noppoMan/npdynamodb",dependencies:{bluebird:"^2.9.24",chalk:"^1.0.0",commander:"^2.7.1","dynamodb-doc":"^1.0.0",glob:"^5.0.3",interpret:"^0.5.2",liftoff:"^2.0.3",lodash:"^3.5.0",minimist:"^1.1.1",readline:"0.0.7",v8flags:"^2.0.3"},devDependencies:{"aws-sdk":"^2.1.18",chai:"^2.2.0"},browser:{"./lib/migrate/migrator.js":!1,"./lib/dialects/2012-08-10/schema.js":!1,"aws-sdk":!1}}},function(t,e,n){"use strict";function r(t,e){var n=new i(t,e);return n}var i=n(8),o=n(25),s=n(18),a={};t.exports=function(t,e){var i=t.config.apiVersion,u=n(26)("./"+i+"/api");a[i]||(a[i]=o(t,u.originalApis));var c={dynamodb:"function"==typeof t.Condition?t:new s.DynamoDB(t),promisifidRawClient:a[i]};return function(){return r(c,e)}}},function(t,e,n){"use strict";function r(t,e){u.call(this);var n=new f[t.dynamodb.config.apiVersion](t),r=e||{};r.initialize;this.apiVersion=n.client.config.apiVersion,this._feature=n,this._options=s.omit(r,"initialize"),this._initializer=r.initialize,this._callbacks={},"function"==typeof this._initializer&&this._initializer.bind(this)()}function i(t,e){return(t||[]).map(function(t){return t.bind(this)(e)}.bind(this))}var o=n(9),s=n(2),a=n(10),u=n(11).EventEmitter,c=n(12),f=(n(16),{"2012-08-10":n(17)});t.exports=r,c.inherits(r,u),o.forEach(function(t){r.prototype[t]=function(){return this._feature[t].apply(this._feature,s.toArray(arguments)),this}}),r.prototype.freshBuilder=function(){return new r({dynamodb:this._feature.client,promisifidRawClient:this._feature.promisifidRawClient},s.clone(s.extend(this._options,{initialize:this._initializer})))},r.prototype.tableName=function(){return this._feature.conditions.TableName},r.prototype.normalizationRawResponse=function(t){return this._feature.normalizationRawResponse(t)},r.prototype.feature=function(t){return t(this._feature),this},r.prototype.rawClient=function(t){return this._feature.promisifidRawClient},r.prototype.callbacks=function(t,e){return this._callbacks[t]||(this._callbacks[t]=[]),this._callbacks[t].push(e),this},s.each(["then"],function(t){r.prototype[t]=function(t){var e,n=this,r=n._feature,o=this._callbacks;return a.all(i.bind(n)(o.beforeQuery)).then(function(){var t=r.buildQuery();return n.emit("beforeQuery",t.params),new a(function(i,o){var s=r.client[t.method](t.params,function(t,n){return e&&(clearTimeout(e),e=null),t?o(t):void i(n)});null!==n._options.timeout&&(e=setTimeout(function(){s.abort(),o(new Error("The connection has timed out."))},n._options.timeout||5e3))})}).then(function(t){return a.all(i.bind(n)(o.afterQuery,t)).then(function(){return n.emit("afterQuery",t),t})}).then(function(e){return t.bind(n)(e)})}})},function(t,e){"use strict";t.exports=["select","table","count","all","where","first","whereIn","whereBetween","whereBeginsWith","filterBetween","filterBeginsWith","filter","filterIn","filterNull","filterNotNull","filterContains","filterNotContains","limit","offset","desc","asc","create","update","set","delete","showTables","indexName","describe","createTable","deleteTable"]},function(t,e){t.exports=n},function(t,e){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(t){return"function"==typeof t}function i(t){return"number"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(t){return void 0===t}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!i(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,n,i,a,u,c;if(this._events||(this._events={}),"error"===t&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[t],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(i=arguments.length,a=new Array(i-1),u=1;i>u;u++)a[u-1]=arguments[u];n.apply(this,a)}else if(o(n)){for(i=arguments.length,a=new Array(i-1),u=1;i>u;u++)a[u-1]=arguments[u];for(c=n.slice(),i=c.length,u=0;i>u;u++)c[u].apply(this,a)}return!0},n.prototype.addListener=function(t,e){var i;if(!r(e))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,r(e.listener)?e.listener:e),this._events[t]?o(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,o(this._events[t])&&!this._events[t].warned){var i;i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[t].length>i&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,i,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,i=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(a=s;a-->0;)if(n[a]===e||n[a].listener&&n[a].listener===e){i=a;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.listenerCount=function(t,e){var n;return n=t._events&&t._events[e]?r(t._events[e])?1:t._events[e].length:0}},function(t,e,n){(function(t,r){function i(t,n){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),y(n)?r.showHidden=n:n&&e._extend(r,n),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),u(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function u(t,n,r){if(t.customInspect&&n&&A(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return g(i)||(i=u(t,i,r)),i}var o=c(t,n);if(o)return o;var s=Object.keys(n),y=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),T(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(n);if(0===s.length){if(A(n)){var m=n.name?": "+n.name:"";return t.stylize("[Function"+m+"]","special")}if(x(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(E(n))return t.stylize(Date.prototype.toString.call(n),"date");if(T(n))return f(n)}var v="",b=!1,w=["{","}"];if(d(n)&&(b=!0,w=["[","]"]),A(n)){var _=n.name?": "+n.name:"";v=" [Function"+_+"]"}if(x(n)&&(v=" "+RegExp.prototype.toString.call(n)),E(n)&&(v=" "+Date.prototype.toUTCString.call(n)),T(n)&&(v=" "+f(n)),0===s.length&&(!b||0==n.length))return w[0]+v+w[1];if(0>r)return x(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var D;return D=b?p(t,n,r,y,s):s.map(function(e){return l(t,n,r,y,e,b)}),t.seen.pop(),h(D,v,w)}function c(t,e){if(_(e))return t.stylize("undefined","undefined");if(g(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return b(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):m(e)?t.stylize("null","null"):void 0}function f(t){return"["+Error.prototype.toString.call(t)+"]"}function p(t,e,n,r,i){for(var o=[],s=0,a=e.length;a>s;++s)N(e,String(s))?o.push(l(t,e,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(l(t,e,n,r,i,!0))}),o}function l(t,e,n,r,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},c.get?a=c.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):c.set&&(a=t.stylize("[Setter]","special")),N(r,i)||(s="["+i+"]"),a||(t.seen.indexOf(c.value)<0?(a=m(n)?u(t,c.value,null):u(t,c.value,n-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function h(t,e,n){var r=0,i=t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function d(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function m(t){return null===t}function v(t){return null==t}function b(t){return"number"==typeof t}function g(t){return"string"==typeof t}function w(t){return"symbol"==typeof t}function _(t){return void 0===t}function x(t){return D(t)&&"[object RegExp]"===S(t)}function D(t){return"object"==typeof t&&null!==t}function E(t){return D(t)&&"[object Date]"===S(t)}function T(t){return D(t)&&("[object Error]"===S(t)||t instanceof Error)}function A(t){return"function"==typeof t}function O(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function S(t){return Object.prototype.toString.call(t)}function B(t){return 10>t?"0"+t.toString(10):t.toString(10)}function C(){var t=new Date,e=[B(t.getHours()),B(t.getMinutes()),B(t.getSeconds())].join(":");return[t.getDate(),L[t.getMonth()],e].join(" ")}function N(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var j=/%[sdj%]/g;e.format=function(t){if(!g(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return t}}),a=r[n];o>n;a=r[++n])s+=m(a)||!D(a)?" "+a:" "+i(a);return s},e.deprecate=function(n,i){function o(){if(!s){if(r.throwDeprecation)throw new Error(i);r.traceDeprecation?console.trace(i):console.error(i),s=!0}return n.apply(this,arguments)}if(_(t.process))return function(){return e.deprecate(n,i).apply(this,arguments)};if(r.noDeprecation===!0)return n;var s=!1;return o};var I,k={};e.debuglog=function(t){if(_(I)&&(I=r.env.NODE_DEBUG||""),t=t.toUpperCase(),!k[t])if(new RegExp("\\b"+t+"\\b","i").test(I)){var n=r.pid;k[t]=function(){var r=e.format.apply(e,arguments);console.error("%s %d: %s",t,n,r)}}else k[t]=function(){};return k[t]},e.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=d,e.isBoolean=y,e.isNull=m,e.isNullOrUndefined=v,e.isNumber=b,e.isString=g,e.isSymbol=w,e.isUndefined=_,e.isRegExp=x,e.isObject=D,e.isDate=E,e.isError=T,e.isFunction=A,e.isPrimitive=O,e.isBuffer=n(14);var L=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];e.log=function(){console.log("%s - %s",C(),e.format.apply(e,arguments))},e.inherits=n(15),e._extend=function(t,e){if(!e||!D(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}}).call(e,function(){return this}(),n(13))},function(t,e){function n(){c=!1,s.length?u=s.concat(u):f=-1,u.length&&r()}function r(){if(!c){var t=setTimeout(n);c=!0;for(var e=u.length;e;){for(s=u,u=[];++f1)for(var n=1;n0&&this.whereConditions.length>0)throw new Error("Can not specify the parameters of batchGetImte and Query operation at the same time");var r=t(l[e])||function(){return{beforeQuery:function(){},conditions:{},nextThen:e}},i=r();return i.beforeQuery.call(this),this.nextThen=i.nextThen,this.conditions=o.extend(this.conditions,i.conditions),{params:this.conditions,method:this.nextThen}},t.exports=r},function(t,e,n){"use strict";function r(t){var e="undefined"==typeof window,r=e?n(4):window.AWS,i=e?n(19).DynamoDBCondition:window.DynamoDBCondition,o=e?n(3).DynamoDBDatatype:window.DynamoDBDatatype,s=new o,a=e?n(5).DynamoDBFormatter:window.DynamoDBFormatter,u=new a,c=t||new r.DynamoDB,f=c.setupRequestListeners;return c.setupRequestListeners=function(t){f.call(this,t),t._events.validate.unshift(u.formatInput),t.on("extractData",u.formatOutput)},c.__proto__.Set=function(t,e){return s.createSet(t,e)},c.__proto__.Condition=function(t,e,n,r){return i(t,e,n,r)},c.__proto__.StrToBin=function(t){return s.strToBin(t)},c.__proto__.BinToStr=function(t){return s.binToStr(t)},c}var e=t.exports={};e.DynamoDB=r},function(t,e,n){"use strict";function r(t,e,r,i){var o="undefined"==typeof window?n(3).DynamoDBDatatype:window.DynamoDBDatatype,s=new o,a=function(t,e,n,r){this.key=t,this.operator=e,this.val1=n,this.val2=r,this.format=function(){var t={},e=[];return void 0!==this.val1&&e.push(s.formatDataType(this.val1)),void 0!==this.val2&&e.push(s.formatDataType(this.val2)),e.length>0&&(t.AttributeValueList=e),t.ComparisonOperator=this.operator,t}},u=new a(t,e,r,i);return u.prototype=Object.create(Object.prototype),u.prototype.instanceOf="DynamoDBConditionObject",u}var e=t.exports={};e.DynamoDBCondition=r},function(t,e,n){(function(e){function r(){if(this.AWS)return this.AWS.apiLoader.services.dynamodb["2012-08-10"].operations;var t="aws-sdk/apis/dynamodb-2012-08-10.min.json";try{return n(22)(t).operations}catch(r){var i=e.cwd()+"/node_modules/"+t;if(s.existsSync(i))return n(22)(i).operations;throw new TypeError("Module `aws-sdk` is required for npdynamodb")}}var i=n(2),o=n(16),s=n(21),a=r(this),u=[{origin:"createTable",transformed:"createTable"},{origin:"deleteTable",transformed:"deleteTable"},{origin:"deleteItem",transformed:"delete"},{origin:"describeTable",transformed:"describe"},{origin:"listTables",transformed:"showTables"},{origin:"putItem",transformed:"create"},{origin:"updateItem",transformed:"update"},{origin:"getItem",transformed:"first"},{origin:"query",transformed:"query"},{origin:"scan",transformed:"all"},{origin:"updateTable",transformed:"alterTable"},{origin:"waitFor",transformed:"waitFor"}],c={"=":"EQ","!=":"NE","<=":"LE","<":"LT",">=":"GE",">":"GT"};t.exports={operations:a,originalApis:i.keys(a).map(function(t){return i.camelCase(t)}).concat(["waitFor"]),transformFunctionMap:o.collectionFlatten(u.map(function(t){return o.newObject(t.transformed,t.origin)})),transformOperatorMap:c,availableOperators:i.keys(c)}}).call(e,n(13))},function(t,e){},function(t,e,n){function r(t){return n(i(t))}function i(t){return o[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var o={"./api":20,"./api.js":20,"./feature":17,"./feature.js":17,"./schema":23,"./schema.js":24};r.keys=function(){return Object.keys(o)},r.resolve=i,t.exports=r,r.id=22},function(t,e){},function(t,e){},function(t,e,n){"use strict";var r=n(10);t.exports=function(t,e){var n={};return e.forEach(function(e){n[e]=r.promisify(t[e],t)}),n}},function(t,e,n){function r(t){return n(i(t))}function i(t){return o[t]||function(){throw new Error("Cannot find module '"+t+"'.")}()}var o={"./2012-08-10/api":20};r.keys=function(){return Object.keys(o)},r.resolve=i,t.exports=r,r.id=26},function(t,e,n){"use strict";var r=n(2),i=(n(12),n(16),n(7),n(28));t.exports=function(t,e,n){function o(n){this.tableName=t,r.extend(this,r.pick.apply(null,[e].concat(s))),this._attributes=n||{},this._builder=this.npdynamodb().table(t)}var s=["hashKey","rangeKey","npdynamodb"];return r.extend(o.prototype,r.clone(i.prototype)),r.each(r.omit.apply(null,[e].concat(s)),function(t,e){t.hasOwnProperty("bind")?o.prototype[e]=function(){return t.bind(this,r.toArray(arguments))}:o.prototype[e]=t}),r.each(["find","where","query","fetch","save"],function(t){o[t]=function(){var e=new o;return e[t].apply(e,r.toArray(arguments))}}),r.each(n,function(t,e){t.hasOwnProperty("bind")?o[e]=t.bind(o):o[e]=t}),o}},function(t,e,n){"use strict";function r(t,e){var n=this;return a(t,function(t){return n._refreshBuilder(),e(t)}).bind(this)}function i(){}var o=n(2),s=n(29),a=n(30);t.exports=i,i.prototype.where=function(){return this._builder.where.apply(this._builder,arguments),this},i.prototype.query=function(t){return"function"==typeof t?(t(this._builder),this):this._builder},i.prototype.find=function(t,e){var n=this,i=this._builder.where(this.hashKey,t);return e&&i.where(this.rangeKey,e), +r.bind(this)(i.first(),function(t){return n._attributes=n._builder.normalizationRawResponse(t),n})},i.prototype.reload=function(){return this.find(this.get(this.hashKey),this.get(this.rangeKey))},i.prototype.fetch=function(){var t=this;return r.bind(this)(this._builder,function(e){var n=t._builder.normalizationRawResponse(e),r=n.map(function(e){return new t.constructor(e)});return new s(r)})},i.prototype.save=function(t){var e=this;return"object"==typeof t&&o.extend(this._attributes,t),r.bind(this)(this._builder.create(this.attributes()),function(){return e})},i.prototype.destroy=function(t){var e=this,n=this._builder.where(this.hashKey,this.get(this.hashKey));return this.rangeKey&&n.where(this.rangeKey,this.get(this.rangeKey)),r.bind(this)(n["delete"](),function(){return e._attributes={},e})},i.prototype.set=function(t,e){return this._attributes[t]=e,this},i.prototype.unset=function(t){return this._attributes[t]&&delete this._attributes[t],this},i.prototype.extend=function(t){return o.extend(this._attributes,t),this},i.prototype.get=function(t){return this._attributes[t]},i.prototype.isEmpty=function(){return o.isEmpty(this._attributes)},i.prototype.attributes=function(){return this._attributes},i.prototype.toJson=function(){return JSON.stringify(this._attributes)},i.prototype._refreshBuilder=function(){this._builder=this.npdynamodb().table(this.tableName)},o.each(["each","map","includes","contains","keys","pick","values"],function(t){i.prototype[t]=function(){var e=[this._item].concat(o.map(arguments,function(t){return t}));return o[t].apply(o,e)}})},function(t,e,n){"use strict";function r(t){this._items=t}var i=n(2);t.exports=r,r.prototype.toArray=function(){return this._items.map(function(t){return t.attributes()})},r.prototype.toJSON=function(){return JSON.stringify(this.toArray())},r.prototype.indexAt=function(t){return this._items[t]},r.prototype.at=function(t){return this.indexAt(t)},i.each(["pluck"],function(t){r.prototype[t]=function(){var e=[this.toArray()].concat(i.map(arguments,function(t){return t}));return i[t].apply(i,e)}}),i.each(["each","map","reduce","reduceRight","find","filter","where","findWhere","reject","every","some","invoke","sortBy","groupBy","indexBy","countBy","shuffle","sample","size","partition","first","last","isEmpty"],function(t){r.prototype[t]=function(){var e=[this._items].concat(i.map(arguments,function(t){return t}));return i[t].apply(i,e)}})},function(t,e,n){"use strict";var r=n(10);t.exports=function(t,e){return new r(function(n,r){return t.then(function(t){return e||(e=function(t){return t}),n(e(t))})["catch"](r)})}}])}); \ No newline at end of file diff --git a/lib/query_builder.js b/lib/query_builder.js index 875ea28..7e8fbf3 100644 --- a/lib/query_builder.js +++ b/lib/query_builder.js @@ -85,9 +85,9 @@ _.each([ ], function(promiseInterface){ QueryBuilder.prototype[promiseInterface] = function(cb){ var self = this; - var gotResponse = false; var feature = self._feature; var callbacks = this._callbacks; + var timer; return Promise.all(callbacksPromisified.bind(self)(callbacks.beforeQuery)).then(function(){ var built = feature.buildQuery(); @@ -95,7 +95,10 @@ _.each([ return new Promise(function(resolve, reject){ var request = feature.client[built.method](built.params, function(err, data){ - gotResponse = true; + if(timer) { + clearTimeout(timer); + timer = null; + } if(err) { return reject(err); } @@ -104,11 +107,9 @@ _.each([ // Handle timeout if(self._options.timeout !== null) { - setTimeout(function(){ - if(!gotResponse) { - request.abort(); - reject(new Error("The connection has timed out.")); - } + timer = setTimeout(function(){ + request.abort(); + reject(new Error("The connection has timed out.")); }, self._options.timeout || 5000); } });