npdynamodb
Version:
A Node.js Simple Query Builder and ORM for AWS DynamoDB.
2 lines • 34.6 kB
JavaScript
!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<e.length;n++){var r=e[n],i=Object.keys(r)[0];e[n]=this.formatWireType(i,r[i])}return e;case"M":for(var o in e){var s=e[o],a=Object.keys(s)[0];e[o]=this.formatWireType(a,s[a])}return e;case"SS":return new this.createSet(e,"S");case"NS":return e=e.map(function(t){return Number(t)}),new this.createSet(e,"N");case"BS":return new this.createSet(e,"B");default:throw"Service returned unrecognized datatype "+t}}}var e=t.exports={};e.DynamoDBDatatype=r},function(t,n){t.exports=e},function(t,e,n){"use strict";function r(){function t(t){var e={};for(var n in t){var r=t[n];e[n]=y.formatDataType(r)}return e}function e(t){if(t.prototype&&"DynamoDBConditionObject"===t.prototype.instanceOf)t=[t];else{if(!Array.isArray(t))throw new Error(b);if(0===t.length)throw new Error(m);for(var e in t){var n=t[e];if(!n.prototype||"DynamoDBConditionObject"!==n.prototype.instanceOf)throw new Error(v)}}var r={};for(var e in t){var n=t[e];r[n.key]=n.format()}return r}function r(t){var e={};for(var n in t)if(t.hasOwnProperty(n)){var r={},i=t[n].Value,o=t[n].Action;r.Action=o,r.Value=y.formatDataType(i),e[n]=r}return e}function i(e){var n={};if(e.DeleteRequest){var r=e.DeleteRequest.Key;n.DeleteRequest={},n.DeleteRequest.Key=t(r)}else{var i=e.PutRequest.Item;n.PutRequest={},n.PutRequest.Item=t(i)}return n}function o(e){var n={};for(var r in e)if(e.hasOwnProperty(r)){n[r]={};var o=e[r];if(Array.isArray(o)){var s=[];for(var a in o)s.push(i(o[a]));n[r]=s}else if(o.AttributesToGet&&(n[r].AttributesToGet=o.AttributesToGet),o.ConsistentRead&&(n[r].ConsistentRead=o.ConsistentRead),o.ProjectionExpression&&(n[r].ProjectionExpression=o.ProjectionExpression),o.ExpressionAttributeNames&&(n[r].ExpressionAttributeNames=o.ExpressionAttributeNames),o.Keys){var u=[];for(var c in o.Keys){var f=o.Keys[c];u.push(t(f))}n[r].Keys=u}}return n}function s(t){var e={};for(var n in t){var r=Object.keys(t[n]),i=r[0],o=t[n][i];o=y.formatWireType(i,o),e[n]=o}return e}function a(t){for(var e in t)t[e]=s(t[e]);return t}function u(t){var e=t.ItemCollectionKey;return t.ItemCollectionKey=s(e),t}function c(t){for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];for(var r in n)n[r]=u(n[r])}return t}function f(t){var e=t.ItemCollectionKey;return t=e?u(t):c(t)}function p(t){for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];for(var r in n)n[r]=s(n[r])}return t}function l(t){for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];for(var r in n){var i=n[r];i.DeleteRequest?n[r].DeleteRequest.Key=s(i.DeleteRequest.Key):n[r].PutRequest.Item=s(i.PutRequest.Item)}}return t}function h(t){for(var e in t)if(t.hasOwnProperty(e)){var n=t[e],r=n.Keys;for(var i in r)n.Keys[i]=s(r[i])}return t}var d="undefined"==typeof window?n(3).DynamoDBDatatype:window.DynamoDBDatatype,y=new d,m="Need to pass in an array with 1 or more Condition Objects.",v="Only Condition objects are allowed as members of the array.",b="Need to pass in a valid Condition Object.",g={AttributeUpdates:r,ExclusiveStartKey:t,Expected:e,ExpressionAttributeValues:t,Item:t,Key:t,KeyConditions:e,RequestItems:o,ScanFilter:e,QueryFilter:e};this.formatOutput=function(t){var e={Attributes:s,Item:s,Items:a,ItemCollectionMetrics:f,LastEvaluatedKey:s,Responses:p,UnprocessedKeys:h,UnprocessedItems:l},n=t.data;if(n)for(var r in n)if(n.hasOwnProperty(r)){var i=e[r];i&&(t.data[r]=i(n[r]))}},this.formatInput=function(t){var e={},n=t.params;for(var r in n)if(n.hasOwnProperty(r)){var i=n[r],o=g[r];o&&(i=o(i)),e[r]=i}t.params=e}}var e=t.exports={};e.DynamoDBFormatter=r},function(t,e){t.exports={name:"npdynamodb",version:"0.2.11",description:"A Node.js Simple Query Builder and ORM for AWS DynamoDB.",main:"index.js",scripts:{test:"find ./test -name *_spec.js | xargs mocha --reporter spec -t 20000"},keywords:["dynamodb","aws","activerecord","orm","migration"],bin:{npd:"./lib/bin/npd"},repository:{type:"git",url:"https://github.com/noppoMan/npdynamodb.git"},author:"noppoMan <yuki@miketokyo.com> (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<arguments.length;n++)e.push(i(arguments[n]));return e.join(" ")}for(var n=1,r=arguments,o=r.length,s=String(t).replace(j,function(t){if("%%"===t)return"%";if(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=[];++f<e;)s[f].run();f=-1,e=u.length}s=null,c=!1,clearTimeout(t)}}function i(t,e){this.fun=t,this.array=e}function o(){}var s,a=t.exports={},u=[],c=!1,f=-1;a.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];u.push(new i(t,e)),1!==u.length||c||setTimeout(r,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},a.title="browser",a.browser=!0,a.env={},a.argv=[],a.version="",a.versions={},a.on=o,a.addListener=o,a.once=o,a.off=o,a.removeListener=o,a.removeAllListeners=o,a.emit=o,a.binding=function(t){throw new Error("process.binding is not supported")},a.cwd=function(){return"/"},a.chdir=function(t){throw new Error("process.chdir is not supported")},a.umask=function(){return 0}},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e,n){"use strict";var r=n(2),i=n(10);e.isEmpty=function(t){return null===t?!0:""===t?!0:r.isArray(t)&&0===t.length?!0:r.isObject(t)&&0===r.keys(t).length?!0:!1},e.newObject=function(t,e){var n={};return n[t]=e,n},e.toPascalCase=function(t){var e=t.replace(/_./g,function(t){return t.charAt(1).toUpperCase()});return e.charAt(0).toUpperCase()+e.slice(1)},e.collectionFlatten=function(t){var e={};return r.each(t,function(t){r.extend(e,t)}),e},e.PromiseWaterfall=function(t){return new i(function(e,n){function r(o){o&&"function"==typeof o.then?o.then(function(e){i.push(e),r(t.shift())})["catch"](n):o&&"function"!=typeof o.then?n(new TypeError("Function return value should be a promise.")):e(i)}var i=[];r(t.shift())})},e.lazyPromiseRunner=function(t){return{then:function(e){return t().then(e)}}},e.pairEach=function(t,e){var n={};return t.forEach(function(t,r){n[t]=e[r]}),n}},function(t,e,n){"use strict";function r(t){a.call(this),this.client=t.dynamodb,this.promisifidRawClient=t.promisifidRawClient,this.nextThen=void 0,this.params={},this.whereConditions=[],this.whereInConditions=[],this.filterConditions=[],this.conditions={},this.schema={}}function i(){var t=o.toArray(arguments),e=t[1],n=t[2],r=t[3];o.contains(p,n)||(r=n,n="="),this[t[0]+"Conditions"].push({key:e,values:[r].concat(Array.prototype.slice.call(t,4)),operator:n})}var o=n(2),s=n(12),a=n(11).EventEmitter,u=(n(18),n(16)),c=n(20),f={where:["BEGINS_WITH","BETWEEN"],filter:["BETWEEN","BEGINS_WITH","NOT_NULL","NULL","CONTAINS","NOT_CONTAINS","IN"]},p=c.availableOperators.concat(f.filter),l={};l.createTable=l.deleteTable=function(t){return{conditions:t.params}},l.deleteItem=l.getItem=l.updateItem=function(t){var e=u.collectionFlatten(o.map(t.whereConditions,function(t){return u.newObject(t.key,t.values[0])}));return{conditions:{Key:e}}},l.query=function(t){var e={};return e.KeyConditions=t.toDocClientConditon(t.whereConditions),o.isEmpty(t.filterConditions)||(e.QueryFilter=t.toDocClientConditon(t.filterConditions)),{conditions:e}},l.putItem=function(t){if(o.isArray(t.params)){var e=t.params.map(function(t){return{PutRequest:{Item:t}}}),n=t.conditions.TableName;return{beforeQuery:function(){this.nonTable()},nextThen:"batchWriteItem",conditions:{RequestItems:u.newObject(n,e)}}}return{conditions:{Item:t.params}}},l.batchGetItem=function(t){var e={};return e[t.conditions.TableName]={Keys:t.whereInConditions},["AttributesToGet","ConsistentRead","ProjectionExpression","ExpressionAttributeNames"].forEach(function(n){t.conditions[n]&&(e[t.conditions.TableName][n]=t.conditions[n],delete t.conditions[n])}),{beforeQuery:function(){this.nonTable()},conditions:{RequestItems:e}}},s.inherits(r,a),o.each(c.operations,function(t,e){o.each(t.input.members,function(t,e){r.prototype[o.camelCase(e)]=function(t){return this.conditions[e]=t,this}})}),o.each(c.transformFunctionMap,function(t,e){r.prototype[e]=function(e){this.nextThen=t,this.params=e}}),r.prototype.select=function(){this.attributesToGet(o.toArray(arguments))},r.prototype.table=function(t){this.tableName(t)},r.prototype.count=function(){this.conditions.Select="COUNT",this.nextThen="query"},r.prototype.offset=function(t){this.exclusiveStartKey(t)},r.prototype.whereIn=function(t,e){o.isArray(t)||(t=[t]),this.whereInConditions=this.whereInConditions.concat(e.map(function(e){if(o.isArray(e)||(e=[e]),e.length!==t.length)throw new Error("the length of key and value did not match.");return u.pairEach(t,e)})),this.nextThen="batchGetItem"},o.each(["filter","where"],function(t){r.prototype[t]=function(){return i.apply(this,[t].concat(o.toArray(arguments))),this},o.each(f[t],function(e){r.prototype[t+u.toPascalCase(e.toLowerCase())]=function(){var n=o.toArray(arguments),r=[t,n.shift(),e].concat(n);return i.apply(this,r),this}})}),r.prototype.toDocClientConditon=function(t){var e=this;return t.map(function(t){var n=[t.key,c.transformOperatorMap[t.operator]||t.operator].concat(t.values);return e.client.Condition.apply(null,n)})},r.prototype.set=function(t,e,n){return this.conditions.AttributeUpdates||(this.conditions.AttributeUpdates={}),this.conditions.AttributeUpdates[t]={Action:e,Value:n},this},r.prototype.asc=function(){this.scanIndexForward(!0)},r.prototype.desc=function(){this.scanIndexForward(!1)},r.prototype.nonTable=function(){this.conditions=o.omit(this.conditions,"TableName")},r.prototype.normalizationRawResponse=function(t){return t.Items?t.Items:t.Item?t.Item:t.Responses&&t.Responses[this.conditions.TableName]?t.Responses[this.conditions.TableName].reverse():void 0},r.prototype.buildQuery=function(){function t(t){return t?function(){var r=t(n);return r.beforeQuery||(r.beforeQuery=function(){}),r.nextThen||(r.nextThen=e),r}:void 0}var e=this.nextThen||"query",n=this;if(this.whereInConditions.length>0&&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)})}}])});