UNPKG

67.3 kBJavaScriptView Raw
1/*!
2 * Fortune.js
3 * Version 5.5.13
4 * MIT License
5 * http://fortune.js.org
6 */
7!function i(s,u,a){function f(r,e){if(!u[r]){if(!s[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(c)return c(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var o=u[r]={exports:{}};s[r][0].call(o.exports,function(e){return f(s[r][1][e]||e)},o,o.exports,i,s,u,a)}return u[r].exports}for(var c="function"==typeof require&&require,e=0;e<a.length;e++)f(a[e]);return f}({1:[function(p,e,h){(function(e){"use strict";var t=p("../../common/deep_equal"),T=p("../../common/message"),O=p("../../common/array/find"),r=p("../../common/generate_id"),_=p("../../common/errors").BadRequestError,n=p("../../common/keys"),I=n.primary,B=n.type,P=n.isArray,o=[[Date,function(e,r){return e.getTime()===r.getTime()}],[e,function(e,r){return e.equals(r)}],[Object,function(e,r){return t(e,r)}]],U=[[Number,function(e,r){return e-r}],[String,function(e,r){return e===r?0:r<e?1:-1}],[Boolean,function(e,r){return e===r?0:e?1:-1}],[Date,function(e,r){return e.getTime()-r.getTime()}],[e,e.compare],[Object,function(){return 0}]];function i(e,r,t){var n;return null===t?null===r:e?e.compare?0===e.compare(r,t):(n=O(o,x(e)))?n[1](r,t):r===t:r===t}function s(t,e){return function(r){return t[P]?O(e,function(e){return i(t[B],r,e)}):i(t[B],r,e)}}function R(e,r,t){var n;for(n in r)switch(n){case"and":if(!u(e,r[n],t))return!1;break;case"or":if(!a(e,r[n],t))return!1;break;case"not":if(R(e,r[n],t))return!1;break;case"range":if(!l(e,r[n],t))return!1;break;case"match":if(!f(e,r[n],t))return!1;break;case"exists":if(!c(e,r[n],t))return!1}return!0}function u(e,r,t){var n;for(n=0;n<r.length;n++)if(!R(e,r[n],t))return!1;return!0}function a(e,r,t){var n;for(n=0;n<r.length;n++)if(R(e,r[n],t))return!0;return!1}function f(e,r,t){var n,o;for(n in r)if(o=r[n],Array.isArray(o)||(o=[o]),void 0===O(o,s(e[n],t[n])))return!1;return!0}function c(e,r,t){var n,o,i;for(n in r)if(o=t[n],i=e[n][P],r[n]){if(!o)return!1;if(i&&!o.length)return!1}else{if(o&&!i)return!1;if(i&&o.length)return!1}return!0}function l(e,r,t){var n,o,i,s,u,a,f={};for(n in r)if(i=(o=e[n])[B],s=o[P],i||s){if(u=r[n],null==(a=t[n]))return!1;if(s&&(a=a?a.length:0),f[n]||(f[n]=s?O(U,x(Number))[1]:i.compare||O(U,x(i))[1]),null!==u[0]&&f[n](a,u[0])<0)return!1;if(null!==u[1]&&f[n](u[1],a)<0)return!1}return!0}function x(t){return function(e){var r=t===e[0]||t.name===e[0].name;if(!r)try{r=e[0]===t.prototype.constructor}catch(e){}return r}}h.generateId=r,h.applyOptions=function(e,r,t,n){var o,i,s,u,a,f,c,l,p,h,d,y,m,g,v,w,b,E,A,k;if(t||(t={}),n||(n={}),f=n.language,t)for(c=r,r=[],l=0,p=c.length;l<p;l++)i=c[l],R(e,t,i)&&r.push(i);if(o=r.length,"fields"in t){if(u=!O(Object.keys(t.fields),function(e){return!t.fields[e]}),a=!O(Object.keys(t.fields),function(e){return t.fields[e]}),!u&&!a)throw new _(T("FieldsFormat",f));for(l=0,p=r.length;l<p;l++)for(s in i=r[l])s!==I&&(u&&!t.fields.hasOwnProperty(s)||a&&t.fields.hasOwnProperty(s))&&delete i[s]}return"sort"in t&&(r=r.sort((h=e,d=t.sort,function(e,r){for(y in d){if(g=e[y],v=r[y],w=d[y],b=h[y],E=b[P],A=b[B],null===g)return 1;if(null===v)return-1;if(k=0,E)k=g.length-v.length;else if(A){if(!(m=A.compare||O(U,x(A))[1]))throw new Error('Missing "compare" function.');k=m(g,v)}if(0!==k)return w?k:-k}return 0}))),("limit"in t||"offset"in t)&&(r=r.slice(t.offset,t.limit?(t.offset||0)+t.limit:r.length)),r.count=o,r}}).call(this,p("buffer").Buffer)},{"../../common/array/find":8,"../../common/deep_equal":19,"../../common/errors":20,"../../common/generate_id":22,"../../common/keys":24,"../../common/message":25,buffer:47}],2:[function(e,r,t){"use strict";var l=e("../common").generateId;t.inputRecord=function(e,r){var t,n,o,i=this.recordTypes,s=this.keys.primary,u=this.keys.isArray,a=i[e],f=Object.getOwnPropertyNames(a),c={};c[s]=s in r?r[s]:l();for(t=0,n=f.length;t<n;t++)o=f[t],r.hasOwnProperty(o)?c[o]=r[o]:c[o]=a[o][u]?[]:null;return c},t.outputRecord=function(e,r){var t,n,o,i,s,u=this.recordTypes,a=this.keys.primary,f=this.keys.isArray,c=this.keys.denormalizedInverse,l=u[e],p=Object.getOwnPropertyNames(l),h={};for(h[a]=r[a],t=0,n=p.length;t<n;t++)o=p[t],s=(i=r.hasOwnProperty(o))?r[o]:l[o][f]?[]:null,l[o][c]?Object.defineProperty(h,o,{configurable:!0,writable:!0,value:s}):i&&(h[o]=s);return h}},{"../common":1}],3:[function(e,r,t){"use strict";var p=e("../../../common/apply_update"),m=e("../../../common/array/map"),g=e("../../../common/promise"),n=e("../common"),d=n.applyOptions,o=e("./helpers"),v=o.inputRecord,w=o.outputRecord;r.exports=function(h){function e(e){h.call(this,e),this.options||(this.options={}),"recordsPerType"in this.options||(this.options.recordsPerType=1e3)}return(e.prototype=new h).connect=function(){var e,r=g.Promise,t=this.recordTypes;for(e in this.db={},t)this.db[e]={};return r.resolve()},e.prototype.disconnect=function(){var e=g.Promise;return delete this.db,e.resolve()},e.prototype.find=function(e,r,t,n){var o,i,s,u,a=g.Promise,f=this,c=f.recordTypes[e],l=f.db[e],p=[];if(r&&!r.length)return h.prototype.find.call(f);if(r)for(o=0,i=r.length;o<i;o++)s=r[o],l.hasOwnProperty(s)&&(u=l[s],delete l[s],l[s]=u,p.push(w.call(f,e,u)));else for(s in l)p.push(w.call(f,e,l[s]));return a.resolve(d(c,p,t,n))},e.prototype.create=function(r,e,t){var n,o,i,s,u,a,f=g.Promise,c=this,l=c.message,p=c.options.recordsPerType,h=c.keys.primary,d=c.errors.ConflictError,y=c.db[r];for(t||(t={}),a=t.language,n=0,o=(e=m(e,function(e){return v.call(c,r,e)})).length;n<o;n++)if(s=(i=e[n])[h],y.hasOwnProperty(s))return f.reject(new d(l("RecordExists",a,{id:s})));for(n=0,o=e.length;n<o;n++)y[(i=e[n])[h]]=i;if(p&&(u=Object.keys(y)).length>p)for(n=0,o=(u=u.slice(0,u.length-p)).length;n<o;n++)delete y[u[n]];return f.resolve(m(e,function(e){return w.call(c,r,e)}))},e.prototype.update=function(e,r){var t,n,o,i,s,u=g.Promise,a=this,f=a.keys.primary,c=a.db[e],l=0;if(!r.length)return h.prototype.update.call(a);for(t=0,n=r.length;t<n;t++)(s=c[i=(o=r[t])[f]])&&(l++,s=w.call(a,e,s),p(s,o),delete c[i],c[i]=v.call(a,e,s));return u.resolve(l)},e.prototype.delete=function(e,r){var t,n,o,i=g.Promise,s=this.db[e],u=0;if(r&&!r.length)return h.prototype.delete.call(this);if(r)for(t=0,n=r.length;t<n;t++)s[o=r[t]]&&(delete s[o],u++);else for(o in s)delete s[o],u++;return i.resolve(u)},e.common=n,e.features={logicalOperators:!0},e}},{"../../../common/apply_update":6,"../../../common/array/map":10,"../../../common/promise":28,"../common":1,"./helpers":2}],4:[function(e,r,t){"use strict";var n=e("../common/assign"),o=e("../common/promise"),i=e("./adapters/memory");function s(e){n(this,e)}s.prototype.constructor=function(){},delete s.prototype.constructor,s.prototype.connect=function(){return o.Promise.resolve()},s.prototype.disconnect=function(){return o.Promise.resolve()},s.prototype.create=function(){return o.Promise.resolve([])},s.prototype.find=function(){var e=o.Promise,r=[];return r.count=0,e.resolve(r)},s.prototype.update=function(){return o.Promise.resolve(0)},s.prototype.delete=function(){return o.Promise.resolve(0)},s.prototype.beginTransaction=function(){return o.Promise.resolve(this)},s.prototype.endTransaction=function(){return o.Promise.resolve()},s.prototype.applyOperators=function(e){return e},s.DefaultAdapter=i(s),s.features={},r.exports=s},{"../common/assign":14,"../common/promise":28,"./adapters/memory":3}],5:[function(e,r,t){"use strict";var n=e("./"),o=e("../common"),i=e("../common/errors"),s=e("../common/keys"),u=e("../common/promise");r.exports=function(e){var r,t;if("function"!=typeof(t=Array.isArray(e.adapter)?e.adapter:[e.adapter])[0])throw new TypeError("The adapter must be a function.");if(r=n.prototype.isPrototypeOf(t[0].prototype)?t[0]:t[0](n),!n.prototype.isPrototypeOf(r.prototype))throw new TypeError("The adapter must inherit the Adapter class.");return new r({options:t[1]||{},recordTypes:e.recordTypes,features:r.features,common:o,errors:i,keys:s,message:e.message,Promise:u.Promise})}},{"../common":23,"../common/errors":20,"../common/keys":24,"../common/promise":28,"./":4}],6:[function(e,r,t){"use strict";var n=e("./array/pull");r.exports=function(e,r){var t;for(t in r.replace)e[t]=r.replace[t];for(t in r.push)e[t]=e[t]?e[t].concat(r.push[t]):[].concat(r.push[t]);for(t in r.pull)e[t]=e[t]?n(e[t],r.pull[t]):[]}},{"./array/pull":11}],7:[function(e,r,t){"use strict";r.exports=function(e,r){var t,n,o=[],i=0;for(t=0,n=e.length;t<n;t++)r(e[t],t,e)&&(o[i++]=e[t]);return o}},{}],8:[function(e,r,t){"use strict";r.exports=function(e,r){var t,n,o;for(t=0,n=e.length;t<n;t++)if(r(o=e[t]))return o}},{}],9:[function(e,r,t){"use strict";r.exports=function(e,r){var t,n;for(t=0,n=e.length;t<n;t++)if(e[t]===r)return!0;return!1}},{}],10:[function(e,r,t){"use strict";r.exports=function(e,r){var t,n,o=[],i=0;for(t=0,n=e.length;t<n;t++)o[i++]=r(e[t],t,e);return o}},{}],11:[function(e,r,t){"use strict";r.exports=function(e,r){var t,n,o,i={},s=[];if(Array.isArray(r))for(n=0,o=r.length;n<o;n++)i[r[n]]=!0;else i[r]=!0;for(n=e.length;n--;)t=e[n],i.hasOwnProperty(t)||s.unshift(t);return s}},{}],12:[function(e,r,t){"use strict";r.exports=function(e,r,t){var n,o,i=t;for(n=0,o=e.length;n<o;n++)i=r(i,e[n],n,e);return i}},{}],13:[function(e,r,t){"use strict";r.exports=function(e){var r,t,n,o={},i=[];for(r=0,t=e.length;r<t;r++)n=e[r],o.hasOwnProperty(n)||(i.push(n),o[n]=!0);return i}},{}],14:[function(e,r,t){"use strict";r.exports=function(e){var r,t,n,o;for(r=1,t=arguments.length;r<t;r++)if(null!=(o=arguments[r]))for(n in o)e[n]=o[n];return e}},{}],15:[function(e,r,t){"use strict";r.exports=function(e){var r=Number.parseFloat(e);return 0<=e-r+1?r:e}},{}],16:[function(r,s,e){(function(t){"use strict";var e=r("./errors"),n=r("./message"),a=r("./cast_to_number"),o=e.BadRequestError,i=t.from||function(e,r){return new t(e,r)},f=[[Number,function(e){return parseFloat(e)}],[Date,function(e,r){if("string"==typeof e&&(e=Date.parse(e),Number.isNaN(e)))throw new o(n("DateISO8601",r.language));if(e=new Date(e),Number.isNaN(e.getTime()))throw new o(n("DateInvalid",r.language));return e}],[t,function(e,r){var t=r&&r.bufferEncoding?r.bufferEncoding:"base64";if("string"!=typeof e)throw new o(n("BufferEncoding",r.language,{bufferEncoding:t}));return i(e,t)}],[Boolean,function(e){return"string"==typeof e?/^(?:true|1|yes|t|y)$/i.test(e):Boolean(e)}],[Object,function(e,r){if("string"==typeof e)return JSON.parse(e);if("object"==typeof e)return e;throw new o(n("JSONParse",r.language))}],[String,function(e){return""+e}]];s.exports=function(e,r,t){var n,o,i,s,u;if(""===e)return null;if(!r)return a(e);for(n=0,o=f.length;n<o;n++){if(!(s=(i=f[n])[0]===r||i[0].name===r.name))try{s=i[0]===r.prototype.constructor}catch(e){}if(s){u=i[1];break}}return u&&null!==e?u(e,t):e}}).call(this,r("buffer").Buffer)},{"./cast_to_number":15,"./errors":20,"./message":25,buffer:47}],17:[function(e,r,t){"use strict";r.exports=function e(r){var t,n,o,i;if(Array.isArray(r))i=!0;else if(null==r||Object.getPrototypeOf(r)!==Object.prototype)return r;for(n in t=i?[]:{},r)o=r[n],t[n]=null!=o&&Object.getPrototypeOf(o)===Object.prototype||Array.isArray(o)?e(o):o;return t}},{}],18:[function(e,r,t){"use strict";var n,o,i,s="function"==typeof Symbol,u=["denormalizedInverse","updateRecord","linkedHash"];for(t.primary="id",t.type="type",t.link="link",t.inverse="inverse",t.isArray="isArray",n=0,o=u.length;n<o;n++)t[i=u[n]]=s?Symbol(i):"__"+i+"__";t.change="change",t.sync="sync",t.connect="connect",t.disconnect="disconnect",t.failure="failure",t.find="find",t.create="create",t.update="update",t.delete="delete"},{}],19:[function(e,r,t){(function(a){"use strict";r.exports=function e(r,t){var n,o,i,s=0,u=0;if(r===t)return!0;if(!r||!t)return!1;if(r.prototype!==t.prototype)return!1;for(n in r)if(s++,o=r[n],i=t[n],"object"!=typeof o){if(a.isBuffer(o)){if(!a.isBuffer(i)||!o.equals(i))return!1}else if(o&&"function"==typeof o.getTime){if(!i||"function"!=typeof i.getTime||o.getTime()!==i.getTime())return!1}else if(o!==i)return!1}else if("object"!=typeof i||!e(o,i))return!1;for(n in t)u++;return s===u}}).call(this,{isBuffer:e("../../node_modules/is-buffer/index.js")})},{"../../node_modules/is-buffer/index.js":51}],20:[function(e,r,t){"use strict";var n=e("./response_classes");t.BadRequestError=n.BadRequestError,t.UnauthorizedError=n.UnauthorizedError,t.ForbiddenError=n.ForbiddenError,t.NotFoundError=n.NotFoundError,t.MethodError=n.MethodError,t.NotAcceptableError=n.NotAcceptableError,t.ConflictError=n.ConflictError,t.UnsupportedError=n.UnsupportedError,t.UnprocessableError=n.UnprocessableError,t.nativeErrors=n.nativeErrors},{"./response_classes":29}],21:[function(e,r,t){"use strict";var n=e("./constants");t.change=n.change,t.sync=n.sync,t.connect=n.connect,t.disconnect=n.disconnect,t.failure=n.failure},{"./constants":18}],22:[function(e,r,t){"use strict";var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",o=n.length;r.exports=function(){var e,r=[];for(e=0;e<15;e++)r.push(n.charAt(Math.floor(Math.random()*o)));return r.join("")}},{}],23:[function(e,r,t){"use strict";r.exports={constants:e("./constants"),keys:e("./keys"),events:e("./events"),methods:e("./methods"),assign:e("./assign"),castToNumber:e("./cast_to_number"),castValue:e("./cast_value"),clone:e("./clone"),deepEqual:e("./deep_equal"),generateId:e("./generate_id"),applyUpdate:e("./apply_update"),message:e("./message"),responses:e("./response_classes"),errors:e("./errors"),successes:e("./success"),filter:e("./array/filter"),find:e("./array/find"),includes:e("./array/includes"),map:e("./array/map"),pull:e("./array/pull"),reduce:e("./array/reduce"),unique:e("./array/unique")}},{"./apply_update":6,"./array/filter":7,"./array/find":8,"./array/includes":9,"./array/map":10,"./array/pull":11,"./array/reduce":12,"./array/unique":13,"./assign":14,"./cast_to_number":15,"./cast_value":16,"./clone":17,"./constants":18,"./deep_equal":19,"./errors":20,"./events":21,"./generate_id":22,"./keys":24,"./message":25,"./methods":27,"./response_classes":29,"./success":30}],24:[function(e,r,t){"use strict";var n=e("./constants");t.primary=n.primary,t.type=n.type,t.link=n.link,t.isArray=n.isArray,t.inverse=n.inverse,t.denormalizedInverse=n.denormalizedInverse},{"./constants":18}],25:[function(e,r,t){"use strict";var n,o={en:e("./messages/en")};for(n in o)a[n]=o[n];function a(e,r,t){var n,o,i,s="GenericError",u=this||a;if(u.hasOwnProperty(r)||((i=r&&r.match(/.+?(?=-)/))&&(i=i[0]),r=u.hasOwnProperty(i)?i:u.defaultLanguage),"string"==typeof(n=u[r].hasOwnProperty(e)?u[r][e]:u[r][s]||u.en[s]))for(o in t)n=n.replace("{"+o+"}",t[o]);return"function"==typeof n&&(n=n(t)),n}r.exports=a,Object.defineProperty(a,"defaultLanguage",{value:"en",writable:!0})},{"./messages/en":26}],26:[function(e,r,t){r.exports={GenericError:function(e){return"An internal error occurred."},MalformedRequest:function(e){return"The request was malformed."},InvalidBody:function(e){return"The request body is invalid."},SerializerNotFound:function(e){return'The serializer for "'+e.id+'" does not exist.'},InputOnly:function(e){return"Input only."},InvalidID:function(e){return"An ID is invalid."},DateISO8601:function(e){return"Date string must be an ISO 8601 formatted string."},DateInvalid:function(e){return"Date value is invalid."},BufferEncoding:function(e){return"Buffer value must be a "+e.bufferEncoding+"-encoded string."},JSONParse:function(e){return"Could not parse value as JSON."},MissingPayload:function(e){return"Payload is missing."},SpecifiedIDs:function(e){return"IDs should not be specified."},InvalidURL:function(e){return"Invalid URL."},RelatedRecordNotFound:function(e){return'A related record for the field "'+e.field+'" was not found.'},CreateRecordsInvalid:function(e){return"There are no valid records to be created."},CreateRecordsFail:function(e){return"Records could not be created."},CreateRecordMissingID:function(e){return"An ID on a created record is missing."},DeleteRecordsMissingID:function(e){return"IDs are required for deleting records."},DeleteRecordsInvalid:function(e){return"A record to be deleted could not be found."},DeleteRecordsFail:function(e){return"Not all records specified could be deleted."},UnspecifiedType:function(e){return"The type is unspecified."},InvalidType:function(e){return'The requested type "'+e.type+'" is not a valid type.'},InvalidLink:function(e){return'The field "'+e.field+'" does not define a link.'},InvalidMethod:function(e){return'The method "'+e.method+'" is unrecognized.'},CollisionToOne:function(e){return'Multiple records can not have the same to-one link value on the field "'+e.field+'".'},CollisionDuplicate:function(e){return'Duplicate ID "'+e.id+'" in the field "'+e.field+'".'},UpdateRecordMissing:function(e){return"A record to be updated could not be found."},UpdateRecordsInvalid:function(e){return"There are no valid updates."},UpdateRecordMissingID:function(e){return"An ID on an update is missing."},EnforceArrayType:function(e){return'The value of "'+e.key+'" is invalid, it must be an array with values of type "'+e.type+'".'},EnforceArray:function(e){return'The value of "'+e.key+'" is invalid, it must be an array.'},EnforceSameID:function(e){return'An ID of "'+e.key+'" is invalid, it cannot be the same ID of the record.'},EnforceSingular:function(e){return'The value of "'+e.key+'" can not be an array, it must be a singular value.'},EnforceValue:function(e){return'The value of "'+e.key+'" is invalid, it must be a "'+e.type+'".'},EnforceValueArray:function(e){return'A value in the array of "'+e.key+'" is invalid, it must be a "'+e.type+'".'},FieldsFormat:function(e){return"Fields format is invalid. It may either be inclusive or exclusive, but not both."},RecordExists:function(e){return'A record with ID "'+e.id+'" already exists.'}}},{}],27:[function(e,r,t){"use strict";var n=e("./constants");t.find=n.find,t.create=n.create,t.update=n.update,t.delete=n.delete},{"./constants":18}],28:[function(e,r,t){"use strict";t.Promise=Promise},{}],29:[function(e,r,t){"use strict";var n=e("error-class"),o=e("./assign");t.OK=function(e){o(this,e)},t.Created=function(e){o(this,e)},t.Empty=function(e){o(this,e)},t.BadRequestError=n("BadRequestError"),t.UnauthorizedError=n("UnauthorizedError"),t.ForbiddenError=n("ForbiddenError"),t.NotFoundError=n("NotFoundError"),t.MethodError=n("MethodError"),t.NotAcceptableError=n("NotAcceptableError"),t.ConflictError=n("ConflictError"),t.UnsupportedError=n("UnsupportedError"),t.UnprocessableError=n("UnprocessableError"),t.nativeErrors=[Error,TypeError,ReferenceError,RangeError,SyntaxError,EvalError,URIError]},{"./assign":14,"error-class":48}],30:[function(e,r,t){"use strict";var n=e("./response_classes");t.OK=n.OK,t.Created=n.Created,t.Empty=n.Empty},{"./response_classes":29}],31:[function(e,r,t){"use strict";window.fortune=e("./")},{"./":32}],32:[function(e,r,t){"use strict";var n=e("event-lite"),h=e("./adapter/adapters/memory"),d=e("./adapter/singleton"),y=e("./record_type/validate"),o=e("./record_type/ensure_types"),i=e("./common/promise"),s=e("./request"),m=s.middlewares,g=e("./adapter"),v=e("./common"),u=v.assign,w=v.methods,a=v.events;function f(e,r){if(!(this instanceof f))return new f(e,r);this.constructor(e,r)}function b(r,t){return function(e){return t.call(r,e)}}(f.prototype=new n).constructor=function(e,r){var t,n,o,i,s,u,a,f,c=this,l={},p=v.message;for(n in void 0===e&&(e={}),void 0===r&&(r={}),"adapter"in r||(r.adapter=[h(g)]),"settings"in r||(r.settings={}),"hooks"in r||(r.hooks={}),"enforceLinks"in r.settings||(r.settings.enforceLinks=!0),i={},w){for(a=0,f=(o=[m[n],m.include,m.end]).length;a<f;a++)o[a]=b(c,o[a]);i[w[n]]=o}for(s in u=r.hooks){if(!e.hasOwnProperty(s))throw new Error('Attempted to define hook on "'+s+'" type which does not exist.');if(!Array.isArray(u[s]))throw new TypeError('Hook value for "'+s+'" type must be an array.')}for(s in e){if(s in l)throw new Error('Can not define type name "'+s+'" which is in Object.prototype.');y(e[s]),u.hasOwnProperty(s)||(u[s]=[])}t=new d({adapter:r.adapter,recordTypes:e,hooks:u,message:p}),c.options=r,c.hooks=u,c.recordTypes=e,c.adapter=t,Object.defineProperties(c,{connectionStatus:{value:0,writable:!0},message:{value:p},flows:{value:i}})},f.prototype.request=function(t){var n=this,e=n.connectionStatus,r=i.Promise;return 0===e?n.connect().then(function(){return s.call(n,t)}):1===e?new r(function(e,r){n.once(a.failure,function(){r(new Error("Connection failed."))}),n.once(a.connect,function(){e(s.call(n,t))})}):s.call(n,t)},f.prototype.find=function(e,r,t,n,o){var i={method:w.find,type:e};return r&&(i.ids=Array.isArray(r)?r:[r]),t&&(i.options=t),n&&(i.include=n),o&&(i.meta=o),this.request(i)},f.prototype.create=function(e,r,t,n){var o={method:w.create,type:e,payload:Array.isArray(r)?r:[r]};return t&&(o.include=t),n&&(o.meta=n),this.request(o)},f.prototype.update=function(e,r,t,n){var o={method:w.update,type:e,payload:Array.isArray(r)?r:[r]};return t&&(o.include=t),n&&(o.meta=n),this.request(o)},f.prototype.delete=function(e,r,t,n){var o={method:w.delete,type:e};return r&&(o.ids=Array.isArray(r)?r:[r]),t&&(o.include=t),n&&(o.meta=n),this.request(o)},f.prototype.connect=function(){var t=this,e=i.Promise;return 1===t.connectionStatus?e.reject(new Error("Connection is in progress.")):2===t.connectionStatus?e.reject(new Error("Connection is already done.")):(t.connectionStatus=1,new e(function(e,r){Object.defineProperty(t,"denormalizedFields",{value:o(t.recordTypes),writable:!0,configurable:!0}),t.adapter.connect().then(function(){return t.connectionStatus=2,t.emit(a.connect),e(t)},function(e){return t.connectionStatus=0,t.emit(a.failure),r(e)})}))},f.prototype.disconnect=function(){var t=this,e=i.Promise;return 2!==t.connectionStatus?e.reject(new Error("Instance has not been connected.")):(t.connectionStatus=1,new e(function(e,r){return t.adapter.disconnect().then(function(){return t.connectionStatus=0,t.emit(a.disconnect),e(t)},function(e){return t.connectionStatus=2,t.emit(a.failure),r(e)})}))},f.prototype.common=v,u(f,{Adapter:g,adapters:{memory:h(g)},errors:v.errors,message:v.message,methods:w,events:a}),Object.defineProperty(f,"Promise",{enumerable:!0,get:function(){return i.Promise},set:function(e){i.Promise=e}}),r.exports=f},{"./adapter":4,"./adapter/adapters/memory":3,"./adapter/singleton":5,"./common":23,"./common/promise":28,"./record_type/ensure_types":34,"./record_type/validate":35,"./request":42,"event-lite":49}],33:[function(t,n,e){(function(r){"use strict";var c=t("../common/message"),l=t("../common/array/find"),p=t("../common/errors").BadRequestError,e=t("../common/keys"),h=e.primary,d=e.type,y=e.link,m=e.isArray,u=[[String,function(e){return"string"==typeof e}],[Number,function(e){return"number"==typeof e}],[Boolean,function(e){return"boolean"==typeof e}],[Date,function(e){return e&&"function"==typeof e.getTime&&!Number.isNaN(e.getTime())}],[Object,function(e){return null!==e&&"object"==typeof e}],[r,function(e){return r.isBuffer(e)}]];function g(e,r,t,n){var o,i=n.language,s=e[d];if(null!==t&&!(o=(o=l(u,function(e){return e[0]===s}))?o[1]:s)(t))throw new p(c(e[m]?"EnforceValueArray":"EnforceValue",i,{key:r,type:s.displayName||s.name}))}function v(r){return function(e){return r===e}}n.exports=function(e,r,t,n){var o,i,s,u,a,f;for(s in n||(n={}),f=n.language,r)if(a=t[s])if(u=r[s],a[d])if(a[m]){if(!Array.isArray(u))throw new p(c("EnforceArrayType",f,{key:s,type:a[d].name}));for(o=0,i=u.length;o<i;o++)g(a,s,u[o],n)}else g(a,s,u,n);else if(a[y]){if(a[m]){if(!Array.isArray(u))throw new p(c("EnforceArray",f,{key:s}));if(e===a[y]&&l(u,v(r[h])))throw new p(c("EnforceSameID",f,{key:s}));continue}if(Array.isArray(u))throw new p(c("EnforceSingular",f,{key:s}));if(e===a[y]&&r[h]===u)throw new p(c("EnforceSameID",f,{key:s}))}else;else s!==h&&delete r[s];return r}}).call(this,t("buffer").Buffer)},{"../common/array/find":8,"../common/errors":20,"../common/keys":24,"../common/message":25,buffer:47}],34:[function(e,r,t){"use strict";var n=e("../common/keys"),a=n.link,f=n.inverse,c=n.isArray,l=n.denormalizedInverse;r.exports=function(e){var r,t,n,o,i,s,u={};for(r in e)for(t in e[r])if(n=e[r][t],a in n){if(!e.hasOwnProperty(n[a]))throw new Error('The value for "'+a+'" on "'+t+'" in type "'+r+'" is invalid, the record type does not exist.');if(o=e[n[a]],f in n){if(!o.hasOwnProperty(n[f]))throw new Error('The value for "'+f+'" on "'+t+'" in type "'+r+'" is invalid, the field does not exist.');if(o[n[f]][f]!==t)throw new Error('The value for "'+f+'" on "'+t+'" in type "'+r+'" is invalid, the inversely related field must define its inverse as "'+t+'".');if(o[n[f]][a]!==r)throw new Error('The value for "'+a+'" on "'+t+'" in type "'+r+'" is invalid, the inversely related field must define its link as "'+r+'".')}else u[i="__"+r+"_"+t+"_inverse"]=!0,Object.defineProperty(n,f,{value:i}),(s={})[a]=r,s[f]=t,s[c]=!0,s[l]=!0,Object.defineProperty(o,i,{value:s})}return u}},{"../common/keys":24}],35:[function(h,d,e){(function(e){"use strict";var n=h("../common/array/find"),r=h("../common/array/map"),t=h("../common/keys"),o=t.primary,i=t.type,s=t.link,u=t.inverse,a=t.isArray,f={},c=[String,Number,Boolean,Date,Object,e],l=r(c,function(e){return e.name.toLowerCase()});function p(e,r){var t=e[r]=function(e){var r;if("string"==typeof e)r={link:e};else if("function"==typeof e)r={type:e};else{if(!Array.isArray(e))return e;r={},e[1]?r.inverse=e[1]:r.isArray=!0,"string"==typeof(e=Array.isArray(e[0])?(r.isArray=!0,e[0][0]):e[0])?r.link=e:"function"==typeof e&&(r.type=e)}return r}(e[r]);if("object"!=typeof t)throw new TypeError('The definition of "'+r+'" must be an object.');if(r===o)throw new Error('Can not define primary key "'+o+'".');if(r in f)throw new Error('Can not define field name "'+r+'" which is in Object.prototype.');if(!t[i]&&!t[s])throw new Error('The definition of "'+r+'" must contain either the "'+i+'" or "'+s+'" property.');if(t[i]&&t[s])throw new Error('Can not define both "'+i+'" and "'+s+'" on "'+r+'".');if(t[i]){if("string"==typeof t[i]&&(t[i]=c[l.indexOf(t[i].toLowerCase())]),"function"!=typeof t[i])throw new Error('The "'+i+'" on "'+r+'" must be a function.');if(!n(c,function(e){var r=e===t[i]||e.name===t[i].name;if(!r)try{r=Object.create(t[i])instanceof e}catch(e){r=!0}return r}))throw new Error('The "'+i+'" on "'+r+'" must be or inherit from a valid native type.');if(t[u])throw new Error('The field "'+u+'" may not be defined on "'+r+'".')}if(t[s]){if("string"!=typeof t[s])throw new TypeError('The "'+s+'" on "'+r+'" must be a string.');if(t[u]&&"string"!=typeof t[u])throw new TypeError('The "'+u+'" on "'+r+'" must be a string.')}if(t[a]&&"boolean"!=typeof t[a])throw new TypeError('The key "'+a+'" on "'+r+'" must be a boolean.')}d.exports=function(e){var r;if("object"!=typeof e)throw new TypeError("Type definition must be an object.");for(r in e)p(e,r);return e}}).call(this,h("buffer").Buffer)},{"../common/array/find":8,"../common/array/map":10,"../common/keys":24,buffer:47}],36:[function(e,r,t){"use strict";var l=e("../common/message"),u=e("../common/promise"),p=e("../common/array/unique"),h=e("../common/array/map"),d=e("../common/array/includes"),y=e("../common/errors").BadRequestError,n=e("../common/keys"),m=n.primary,g=n.link,v=n.isArray,w=n.inverse;r.exports=function(n,o,i,s,a){var f=u.Promise,c=this.options.settings.enforceLinks;return f.all(h(s,function(s){var u=Array.isArray(o[s])?o[s]:o.hasOwnProperty(s)&&null!==o[s]?[o[s]]:[],e=i[s][g],r=i[s][w],t={fields:{}};return t.fields[r]=!0,new f(function(o,i){return u.length?n.find(e,u,t,a).then(function(e){var r,t,n;if(c)for(r=p(h(e,function(e){return e[m]})),t=0,n=u.length;t<n;t++)if(!d(r,u[t]))return i(new y(l("RelatedRecordNotFound",a.language,{field:s})));return o(e)}):o()})})).then(function(e){var r,t,n,o={};for(t=0,n=e.length;t<n;t++)(r=e[t])&&(o[s[t]]=i[s[t]][v]?r:r[0]);return o})}},{"../common/array/includes":9,"../common/array/map":10,"../common/array/unique":13,"../common/errors":20,"../common/keys":24,"../common/message":25,"../common/promise":28}],37:[function(e,r,t){"use strict";var s=e("./validate_records"),u=e("./check_links"),a=e("../record_type/enforce"),j=e("../common/message"),f=e("../common/promise"),S=e("../common/array/map"),q=e("../common/errors").BadRequestError,n=e("./update_helpers"),c=n.scrubDenormalizedUpdates,C=n.getUpdate,D=n.addId,N=n.removeId,o=e("../common/constants"),l=o.change,p=o.create,h=o.update,M=o.primary,L=o.link,F=o.inverse,z=o.isArray,d=o.denormalizedInverse;r.exports=function(E){var A,k,T,O,o,_,I,B=f.Promise,t=this,n=t.denormalizedFields,P=t.recordTypes,i=t.hooks,U={},R=[],x=[];return B.resolve(E.request.payload).then(function(e){var r,t,n;if(!(k=e)||!k.length)throw new q(j("CreateRecordsInvalid",I));for(n in T=E.request.type,O=E.request.meta,A=E.transaction,I=O.language,o=i[T],_=P[T])if(L in _[n]&&R.push(n),d in _[n])for(r=0,t=k.length;r<t;r++)delete k[r][n];return"function"==typeof o[0]?B.all(S(k,function(e){return o[0](E,e)})):k}).then(function(e){return B.all(S(e,function(r,e){return r&&"object"==typeof r?k[e]=r:r=k[e],a(T,r,_,O),u.call(t,A,r,_,R,O).then(function(e){return x.push(e),r})}))}).then(function(){return s.call(t,k,_,R,O),A.create(T,k,O)}).then(function(e){var r,t,n,o,i,s,u,a,f,c,l,p,h,d,y,m,g,v,w,b={};if(!e.length)throw new q(j("CreateRecordsFail",I));for(k=e,Object.defineProperty(E.response,"records",{configurable:!0,value:k}),p=0,h=k.length;p<h;p++){if(r=k[p],i=x[p],!(M in r))throw new Error(j("CreateRecordMissingID",I));for(d=0,y=R.length;d<y;d++)if(t=R[d],n=_[t][F],r.hasOwnProperty(t)&&n){for(s=_[t][L],u=P[s][n][z],a=(o=_[t][z])?r[t]:[r[t]],U[s]||(U[s]=[]),b[s]||(b[s]={}),m=0,g=a.length;m<g;m++)null!==(f=a[m])&&D(r[M],C(s,f,U,b),n,u),o||!i[t]||null===i[t][n]||u||i[t][n]===r[M]||N(f,C(T,i[t][n],U,b),t,u);if(o&&i[t]&&!u)for(v=0,w=(l=Array.isArray(i[t])?i[t]:[i[t]]).length;v<w;v++)(c=l[v])[n]!==r[M]&&N(c[M],C(T,c[n],U,b),t,o)}}return B.all(S(Object.keys(U),function(e){return U[e].length?A.update(e,U[e],O):null}))}).then(function(){var e,r={};for(e in r[p]={},r[p][T]=k,U)c(U[e],n),U[e].length&&(h in r||(r[h]={}),r[h][e]=U[e]);return t.emit(l,r),E})}},{"../common/array/map":10,"../common/constants":18,"../common/errors":20,"../common/message":25,"../common/promise":28,"../record_type/enforce":33,"./check_links":36,"./update_helpers":44,"./validate_records":45}],38:[function(e,r,t){"use strict";var O=e("../common/message"),a=e("../common/promise"),_=e("../common/array/map"),f=e("../common/errors").NotFoundError,n=e("./update_helpers"),c=n.scrubDenormalizedUpdates,I=n.getUpdate,B=n.removeId,o=e("../common/constants"),l=o.change,p=o.delete,h=o.update,P=o.primary,U=o.link,R=o.inverse,x=o.isArray;r.exports=function(t){var y,e,m,g=a.Promise,n=this,o=n.denormalizedFields,r=t.request,i=r.type,v=r.ids,w=r.meta,b=w.language,E=n.recordTypes,s=n.hooks,A={},k=E[i],u=s[i],T=[];for(e in y=t.transaction,k)U in k[e]&&T.push(e);if(!v||!v.length)throw new f(O("DeleteRecordsMissingID",b));return y.find(i,v,null,w).then(function(e){if((m=e).length<v.length)throw new f(O("DeleteRecordsInvalid",b));return Object.defineProperty(t.response,"records",{configurable:!0,value:m}),"function"==typeof u[0]?g.all(_(m,function(e){return u[0](t,e)})):m}).then(function(){return y.delete(i,v,w)}).then(function(e){var r,t,n,o,i,s,u,a,f,c,l,p,h,d={};if(e<v.length)throw new Error(O("DeleteRecordsFail",b));for(r=0,t=m.length;r<t;r++)for(u=m[r],n=0,o=T.length;n<o;n++)if(a=T[n],c=k[a][R],u.hasOwnProperty(a)&&c)for(l=k[a][U],p=E[l][c][x],h=Array.isArray(u[a])?u[a]:[u[a]],A[l]||(A[l]=[]),d[l]||(d[l]={}),i=0,s=h.length;i<s;i++)null!==(f=h[i])&&B(u[P],I(l,f,A,d),c,p);return g.all(_(Object.keys(A),function(e){return A[e].length?y.update(e,A[e],w):null}))}).then(function(){var e,r={};for(e in r[p]={},r[p][i]=v,A)c(A[e],o),A[e].length&&(h in r||(r[h]={}),r[h][e]=A[e]);return n.emit(l,r),t})}},{"../common/array/map":10,"../common/constants":18,"../common/errors":20,"../common/message":25,"../common/promise":28,"./update_helpers":44}],39:[function(e,r,t){"use strict";var c=e("../common/array/map"),i=e("../common/promise");r.exports=function(n){var o=i.Promise,s=this.hooks,u=n.request,e=n.response,r=u.type,t=s[r],a=e.records,f=e.include;return(a?o.all(c(a,function(e){return o.resolve("function"==typeof t[1]?t[1](n,e):e)})).then(function(e){var i,r,t;for(r=0,t=e.length;r<t;r++)e[r]&&(a[r]=e[r]);if(f)return i=Object.keys(f),o.all(c(i,function(r){return u.includeType=r,o.all(c(f[r],function(e){return o.resolve("function"==typeof s[r][1]?s[r][1](n,e):e)}))})).then(function(e){var r,t,n,o;for(delete u.includeType,r=0,t=e.length;r<t;r++)for(n=0,o=e[r].length;n<o;n++)e[r][n]&&(f[i[r]][n]=e[r][n])})}):o.resolve()).then(function(){return delete e.records,delete e.include,n.response.payload={records:a},f&&(n.response.payload.include=f),a&&"count"in a&&(n.response.payload.count=a.count),n})}},{"../common/array/map":10,"../common/promise":28}],40:[function(e,r,t){"use strict";r.exports=function(r){var e=r.transaction,t=r.request,n=t.type,o=t.ids,i=t.options,s=t.meta;return n?e.find(n,o,i,s).then(function(e){return Object.defineProperty(r.response,"records",{configurable:!0,value:e}),r}):r}},{}],41:[function(e,r,t){"use strict";var f=e("../common/promise"),c=e("../common/array/map"),l=e("../common/array/find"),b=e("../common/array/reduce"),E=e("../common/message"),A=e("../common/errors").BadRequestError,n=e("../common/keys"),k=n.primary,T=n.link;function O(r){return function(e){return e[k]===r}}r.exports=function(t){var e,r,n,p=f.Promise,o=t.request,h=o.type,i=o.ids||[],s=o.include,d=o.meta,y=d.language,u=t.response,m=t.transaction,g=u.records,v=this.recordTypes,w=!0,a={};if(!h||!s||!g)return t;for(a[h]={},e=0,r=i.length;e<r;e++)a[h][i[e]]=!0;if(!i.length)for(e=0,r=g.length;e<r;e++)n=g[e][k],a[h][n]||(a[h][n]=!0);return s.length&&!Array.isArray(s[0])&&(s=[s]),p.all(c(s,function(l){return new p(function(r,t){var u,n,o,i,e,s,a,f=h,c=[];for(Array.isArray(l)&&(Array.isArray(l[1])||"object"!=typeof l[1])||(l=[l]),e=0,s=l.length;e<s;e++)Array.isArray(l[e])&&(c[e]=l[e][1],l[e]=l[e][0]);for(e=0,s=g.length;e<s;e++)if(!(l[0]in g[e])){w=!1;break}if(w)a=p.resolve(g);else{for((o={fields:{}}).fields[l[0]]=!0,n=[],e=0,s=g.length;e<s;e++)n.push(g[e][k]);a=m.find(h,n,o,d)}return a.then(function(e){return b(l,function(e,s,r){return e.then(function(e){if(i=v[f][s],!f||!i)return[];if(!(T in i))throw new A(E("InvalidLink",y,{field:s}));return u={},f=i[T],n=b(e,function(e,r){var t,n,o,i=Array.isArray(r[s])?r[s]:[r[s]];for(t=0,n=i.length;t<n;t++)(o=i[t])&&!u[o]&&(u[o]=!0,e.push(o));return e},[]),r in c?o=c[r]:r<l.length-1?(o={fields:{}}).fields[l[r+1]]=!0:o=null,n.length?m.find(f,n,o,d):[]})},p.resolve(e))}).then(function(e){return r({type:f,ids:n,records:e})},function(e){return t(e)})})})).then(function(e){var r=b(e,function(e,r){var t,n,o,i;if(!r.ids.length)return e;for(e[r.type]||(e[r.type]=[]),a[r.type]||(a[r.type]={}),t=0,n=r.ids.length;t<n;t++)o=r.ids[t],a[r.type][o]||(i=l(r.records,O(o)))&&(a[r.type][o]=!0,e[r.type].push(i));return e[r.type].length||delete e[r.type],e},{});return Object.keys(r).length&&Object.defineProperty(t.response,"include",{configurable:!0,value:r}),t})}},{"../common/array/find":8,"../common/array/map":10,"../common/array/reduce":12,"../common/errors":20,"../common/keys":24,"../common/message":25,"../common/promise":28}],42:[function(e,r,t){"use strict";var n=e("../common/promise"),o=e("../common/assign"),h=e("../common/array/unique"),d=e("../common/message"),i=e("../common/response_classes"),y=i.BadRequestError,m=i.NotFoundError,g=i.MethodError,v=i.OK,w=i.Empty,b=i.Created,s=e("../common/methods"),E=s.find,A=s.create;function u(i){var e,s=n.Promise,u=this.flows,a=this.recordTypes,f=this.adapter,c=(o((e={request:{method:E,type:null,ids:null,options:{},include:[],meta:{},payload:null},response:{meta:{},payload:null}}).request,i),e),l=c.request.method,p="transaction"in i;return s.resolve(c).then(function(e){var r,t=e.request.type,n=e.request.ids,o=e.request.meta.language;if(n&&(e.request.ids=h(n)),null===t)throw(r=new y(d("UnspecifiedType",o))).isTypeUnspecified=!0,r;if(!a.hasOwnProperty(t))throw new m(d("InvalidType",o,{type:t}));if(!(l in u))throw new g(d("InvalidMethod",o,{method:l}));return p?s.resolve(i.transaction):f.beginTransaction()}).then(function(e){var r,t,n,o;for(c.transaction=e,r=s.resolve(c),n=0,o=(t=u[l]).length;n<o;n++)r=r.then(t[n]);return r}).then(function(t){return p?s.resolve():t.transaction.endTransaction().then(function(){var e=t.request.method,r=t.response;return r.payload?e===A?new b(r):new v(r):new w(r)})}).catch(function(e){return"transaction"in c&&!p?c.transaction.endTransaction(e).then(r,r):r();function r(){throw o(e,c.response)}})}u.middlewares={create:e("./create"),delete:e("./delete"),update:e("./update"),find:e("./find"),include:e("./include"),end:e("./end")},r.exports=u},{"../common/array/unique":13,"../common/assign":14,"../common/message":25,"../common/methods":27,"../common/promise":28,"../common/response_classes":29,"./create":37,"./delete":38,"./end":39,"./find":40,"./include":41,"./update":43}],43:[function(e,r,t){"use strict";var p=e("../common/deep_equal"),n=e("../common/promise"),h=e("../common/assign"),d=e("../common/clone"),o=e("./validate_records"),y=e("./check_links"),m=e("../record_type/enforce"),g=e("../common/message"),v=e("../common/apply_update"),i=e("./update_helpers"),w=i.scrubDenormalizedUpdates,U=i.getUpdate,R=i.addId,x=i.removeId,s=e("../common/errors"),b=s.NotFoundError,j=s.BadRequestError,S=e("../common/array/find"),q=e("../common/array/includes"),C=e("../common/array/map"),u=e("../common/constants"),D=u.change,N=u.update,M=u.primary,L=u.link,F=u.inverse,z=u.isArray,V=u.denormalizedInverse,J=u.updateRecord,K=u.linkedHash;function Y(e,r){var t;for(t in e.replace)r.hasOwnProperty(t)||delete e.replace[t];for(t in e.pull)r.hasOwnProperty(t)||delete e.pull[t];for(t in e.push)r.hasOwnProperty(t)||delete e.push[t]}r.exports=function(s){var E,u,A,a,k,T,f,O=n.Promise,c=this,t=c.denormalizedFields,l=c.adapter,_=c.recordTypes,i=c.hooks,I={},B=[],P=[];return O.resolve(s.request.payload).then(function(e){var r,t,n,o;for(o in function(e,r){var t,n,o=r.language;if(!e||!e.length)throw new j(g("UpdateRecordsInvalid",o));for(t=0,n=e.length;t<n;t++)if(!e[t][M])throw new j(g("UpdateRecordMissingID",o))}(u=e,s.request.meta),k=s.request.type,T=s.request.meta,E=s.transaction,f=T.language,A=_[k],a=i[k],A)if(L in A[o]&&P.push(o),V in A[o])for(r=0,t=u.length;r<t;r++)(n=u[r]).replace&&delete n.replace[o],n.pull&&delete n.pull[o],n.push&&delete n.push[o];return E.find(k,C(u,function(e){return e[M]}),null,T)}).then(function(e){if(e.length<u.length)throw new b(g("UpdateRecordMissing",f));return O.all(C(e,function(r){var t,n,o="function"==typeof a[0],i=r[M];if(!(t=S(u,function(e){return e[M]===i})))throw new b(g("UpdateRecordMissing",f));return o&&(n=d(t)),O.resolve(o?a[0](s,r,t):t).then(function(e){if(e&&"object"==typeof e&&(t=e),o&&(p(t,n)||(s.response.meta.updateModified=!0),t[M]!==i))throw new j(g("InvalidID",f));return B.push(t),Object.defineProperty(t,J,{value:r}),r=h({},r),v(r,t),t.operate&&(r=l.applyOperators(r,t.operate)),m(k,r,A,T),y.call(c,E,r,A,P,T).then(function(e){return Object.defineProperty(t,K,{value:e}),r})})}))}).then(function(e){var r,t;for(o.call(c,e,A,P,T),Object.defineProperty(s.response,"records",{configurable:!0,value:e}),r=0,t=B.length;r<t;r++)Y(B[r],A);return E.update(k,B,T)}).then(function(){var e,r,t,n,o,i,s,u,a,f,c,l,p,h,d,y,m,g,v,w,b={};for(d=0,y=B.length;d<y;d++)for(p=B[d],m=0,g=P.length;m<g;m++)if(h=P[m],e=A[h][F]){if(r=A[h][z],t=A[h][L],n=_[t][e][z],I[t]||(I[t]=[]),b[t]||(b[t]={}),i=p[J],o=p[K],p.replace&&p.replace.hasOwnProperty(h)){if(f=p.replace[h],!Array.isArray(f)){if(f===i[h])continue;null!==f&&R(p[M],U(t,f,I,b),e,n),o[h]&&null!==o[h][e]&&!n&&o[h][e]!==p[M]&&x(f,U(k,o[h][e],I,b),h,n),null!==i[h]&&i[h]!==p[h]&&i[h]!==f&&x(p[M],U(t,i[h],I,b),e,n);continue}for(a=f,v=0,w=i[h].length;v<w;v++)if(f=i[h][v],!q(a,f)){if("pull"in p||(p.pull={}),p.pull.hasOwnProperty(h)){if(Array.isArray(p.pull[h])){p.pull[h].push(f);continue}p.pull[h]=[p.pull[h],f];continue}p.pull[h]=[f]}for(v=0,w=a.length;v<w;v++)if(f=a[v],!q(i[h],f)){if("push"in p||(p.push={}),p.push.hasOwnProperty(h)){if(Array.isArray(p.push[h])){p.push[h].push(f);continue}p.push[h]=[p.push[h],f];continue}p.push[h]=[f]}delete p.replace[h]}if(p.pull&&p.pull[h])for(v=0,w=(l=Array.isArray(p.pull[h])?p.pull[h]:[p.pull[h]]).length;v<w;v++)null!==(f=l[v])&&x(p[M],U(t,f,I,b),e,n);if(p.push&&p.push[h])for(v=0,w=(c=Array.isArray(p.push[h])?p.push[h]:[p.push[h]]).length;v<w;v++)null!==(f=c[v])&&R(p[M],U(t,f,I,b),e,n);if(o[h]&&!n)for(v=0,w=(u=Array.isArray(o[h])?o[h]:[o[h]]).length;v<w;v++)(s=u[v])[e]!==p[M]&&x(s[M],U(k,s[e],I,b),h,r)}return O.all(C(Object.keys(I),function(e){return I[e].length?E.update(e,I[e],T):null}))}).then(function(){var e,r={};for(e in r[N]={},r[N][k]=B,I)w(I[e],t),I[e].length&&(e!==k?r[N][e]=I[e]:r[N][k]=r[N][k].concat(I[k]));return c.emit(D,r),s})}},{"../common/apply_update":6,"../common/array/find":8,"../common/array/includes":9,"../common/array/map":10,"../common/assign":14,"../common/clone":17,"../common/constants":18,"../common/deep_equal":19,"../common/errors":20,"../common/message":25,"../common/promise":28,"../record_type/enforce":33,"./check_links":36,"./update_helpers":44,"./validate_records":45}],44:[function(e,r,t){"use strict";var i=e("../common/array/find"),s=e("../common/keys").primary;t.getUpdate=function(e,r,t,n){var o;return n[e]&&n[e][r]?i(t[e],function(e){return e[s]===r}):(o={id:r},t[e]||(t[e]=[]),t[e].push(o),n[e]={},n[e][r]=!0,o)},t.addId=function(e,r,t,n){if(n)return r.push||(r.push={}),r.push[t]||(r.push[t]=[]),void r.push[t].push(e);r.replace||(r.replace={}),r.replace[t]=e},t.removeId=function(e,r,t,n){if(n)return r.pull||(r.pull={}),r.pull[t]||(r.pull[t]=[]),void r.pull[t].push(e);r.replace||(r.replace={}),r.replace[t]=null},t.scrubDenormalizedUpdates=function(e,r){var t,n,o,i;for(t=e.length;t--;){for(o in n=e[t])if(o!==s){for(i in n[o])i in r&&delete n[o][i];Object.keys(n[o]).length||delete n[o]}1===Object.keys(n).length&&e.splice(t,1)}}},{"../common/array/find":8,"../common/keys":24}],45:[function(e,r,t){"use strict";var k=e("../common/message"),T=e("../common/errors").ConflictError,n=e("../common/keys"),O=n.link,_=n.isArray,I=n.inverse;r.exports=function(e,r,t,n){var o,i,s,u,a,f,c,l,p,h,d,y,m,g,v,w,b=this.recordTypes,E=n.language,A={};for(o=0,i=t.length;o<i;o++){if(m=r[l=t[o]][O],g=r[l][I],v=r[l][_],w=b[m][g][_],v)for(s=0,u=e.length;s<u;s++)if(p=e[s],Array.isArray(p[l]))for(y={},a=0,f=(d=p[l]).length;a<f;a++){if(h=d[a],y.hasOwnProperty(h))throw new T(k("CollisionDuplicate",E,{id:h,field:l}));y[h]=!0}if(!w)for(A[l]={},s=0,u=e.length;s<u;s++)for(c=(p=e[s])[l],a=0,f=(d=Array.isArray(c)?c:c?[c]:[]).length;a<f;a++){if(h=d[a],A[l].hasOwnProperty(h))throw new T(k("CollisionToOne",E,{field:l}));A[l][h]=!0}}}},{"../common/errors":20,"../common/keys":24,"../common/message":25}],46:[function(e,r,t){"use strict";t.byteLength=function(e){var r=h(e),t=r[0],n=r[1];return 3*(t+n)/4-n},t.toByteArray=function(e){for(var r,t=h(e),n=t[0],o=t[1],i=new p((f=n,c=o,3*(f+c)/4-c)),s=0,u=0<o?n-4:n,a=0;a<u;a+=4)r=l[e.charCodeAt(a)]<<18|l[e.charCodeAt(a+1)]<<12|l[e.charCodeAt(a+2)]<<6|l[e.charCodeAt(a+3)],i[s++]=r>>16&255,i[s++]=r>>8&255,i[s++]=255&r;var f,c;2===o&&(r=l[e.charCodeAt(a)]<<2|l[e.charCodeAt(a+1)]>>4,i[s++]=255&r);1===o&&(r=l[e.charCodeAt(a)]<<10|l[e.charCodeAt(a+1)]<<4|l[e.charCodeAt(a+2)]>>2,i[s++]=r>>8&255,i[s++]=255&r);return i},t.fromByteArray=function(e){for(var r,t=e.length,n=t%3,o=[],i=0,s=t-n;i<s;i+=16383)o.push(a(e,i,s<i+16383?s:i+16383));1===n?(r=e[t-1],o.push(u[r>>2]+u[r<<4&63]+"==")):2===n&&(r=(e[t-2]<<8)+e[t-1],o.push(u[r>>10]+u[r>>4&63]+u[r<<2&63]+"="));return o.join("")};for(var u=[],l=[],p="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,i=n.length;o<i;++o)u[o]=n[o],l[n.charCodeAt(o)]=o;function h(e){var r=e.length;if(0<r%4)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");return-1===t&&(t=r),[t,t===r?0:4-t%4]}function a(e,r,t){for(var n,o,i=[],s=r;s<t;s+=3)n=(e[s]<<16&16711680)+(e[s+1]<<8&65280)+(255&e[s+2]),i.push(u[(o=n)>>18&63]+u[o>>12&63]+u[o>>6&63]+u[63&o]);return i.join("")}l["-".charCodeAt(0)]=62,l["_".charCodeAt(0)]=63},{}],47:[function(e,r,t){"use strict";var n=e("base64-js"),i=e("ieee754");t.Buffer=l,t.SlowBuffer=function(e){+e!=e&&(e=0);return l.alloc(+e)},t.INSPECT_MAX_BYTES=50;var o=2147483647;function s(e){if(o<e)throw new RangeError('The value "'+e+'" is invalid for option "size"');var r=new Uint8Array(e);return r.__proto__=l.prototype,r}function l(e,r,t){if("number"!=typeof e)return u(e,r,t);if("string"==typeof r)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}function u(e,r,t){if("string"==typeof e)return function(e,r){"string"==typeof r&&""!==r||(r="utf8");if(!l.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var t=0|h(e,r),n=s(t),o=n.write(e,r);o!==t&&(n=n.slice(0,o));return n}(e,r);if(ArrayBuffer.isView(e))return c(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(C(e,ArrayBuffer)||e&&C(e.buffer,ArrayBuffer))return function(e,r,t){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(t||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===r&&void 0===t?new Uint8Array(e):void 0===t?new Uint8Array(e,r):new Uint8Array(e,r,t);return n.__proto__=l.prototype,n}(e,r,t);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return l.from(n,r,t);var o=function(e){if(l.isBuffer(e)){var r=0|p(e.length),t=s(r);return 0===t.length||e.copy(t,0,0,r),t}if(void 0!==e.length)return"number"!=typeof e.length||D(e.length)?s(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return l.from(e[Symbol.toPrimitive]("string"),r,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return a(e),s(e<0?0:0|p(e))}function c(e){for(var r=e.length<0?0:0|p(e.length),t=s(r),n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(e){if(o<=e)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|e}function h(e,r){if(l.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||C(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var t=e.length,n=2<arguments.length&&!0===arguments[2];if(!n&&0===t)return 0;for(var o=!1;;)switch(r){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return j(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*t;case"hex":return t>>>1;case"base64":return S(e).length;default:if(o)return n?-1:j(e).length;r=(""+r).toLowerCase(),o=!0}}function d(e,r,t){var n=e[r];e[r]=e[t],e[t]=n}function y(e,r,t,n,o){if(0===e.length)return-1;if("string"==typeof t?(n=t,t=0):2147483647<t?t=2147483647:t<-2147483648&&(t=-2147483648),D(t=+t)&&(t=o?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(o)return-1;t=e.length-1}else if(t<0){if(!o)return-1;t=0}if("string"==typeof r&&(r=l.from(r,n)),l.isBuffer(r))return 0===r.length?-1:m(e,r,t,n,o);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,r,t):Uint8Array.prototype.lastIndexOf.call(e,r,t):m(e,[r],t,n,o);throw new TypeError("val must be string, number or Buffer")}function m(e,r,t,n,o){var i,s=1,u=e.length,a=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||r.length<2)return-1;u/=s=2,a/=2,t/=2}function f(e,r){return 1===s?e[r]:e.readUInt16BE(r*s)}if(o){var c=-1;for(i=t;i<u;i++)if(f(e,i)===f(r,-1===c?0:i-c)){if(-1===c&&(c=i),i-c+1===a)return c*s}else-1!==c&&(i-=i-c),c=-1}else for(u<t+a&&(t=u-a),i=t;0<=i;i--){for(var l=!0,p=0;p<a;p++)if(f(e,i+p)!==f(r,p)){l=!1;break}if(l)return i}return-1}function g(e,r,t,n){t=Number(t)||0;var o=e.length-t;n?o<(n=Number(n))&&(n=o):n=o;var i=r.length;i/2<n&&(n=i/2);for(var s=0;s<n;++s){var u=parseInt(r.substr(2*s,2),16);if(D(u))return s;e[t+s]=u}return s}function v(e,r,t,n){return q(function(e){for(var r=[],t=0;t<e.length;++t)r.push(255&e.charCodeAt(t));return r}(r),e,t,n)}function w(e,r,t){return 0===r&&t===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(r,t))}function b(e,r,t){t=Math.min(e.length,t);for(var n=[],o=r;o<t;){var i,s,u,a,f=e[o],c=null,l=239<f?4:223<f?3:191<f?2:1;if(o+l<=t)switch(l){case 1:f<128&&(c=f);break;case 2:128==(192&(i=e[o+1]))&&127<(a=(31&f)<<6|63&i)&&(c=a);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&2047<(a=(15&f)<<12|(63&i)<<6|63&s)&&(a<55296||57343<a)&&(c=a);break;case 4:i=e[o+1],s=e[o+2],u=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&u)&&65535<(a=(15&f)<<18|(63&i)<<12|(63&s)<<6|63&u)&&a<1114112&&(c=a)}null===c?(c=65533,l=1):65535<c&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=l}return function(e){var r=e.length;if(r<=E)return String.fromCharCode.apply(String,e);var t="",n=0;for(;n<r;)t+=String.fromCharCode.apply(String,e.slice(n,n+=E));return t}(n)}t.kMaxLength=o,(l.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}())||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(l.prototype,"parent",{enumerable:!0,get:function(){if(l.isBuffer(this))return this.buffer}}),Object.defineProperty(l.prototype,"offset",{enumerable:!0,get:function(){if(l.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&l[Symbol.species]===l&&Object.defineProperty(l,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),l.poolSize=8192,l.from=function(e,r,t){return u(e,r,t)},l.prototype.__proto__=Uint8Array.prototype,l.__proto__=Uint8Array,l.alloc=function(e,r,t){return o=r,i=t,a(n=e),n<=0?s(n):void 0!==o?"string"==typeof i?s(n).fill(o,i):s(n).fill(o):s(n);var n,o,i},l.allocUnsafe=function(e){return f(e)},l.allocUnsafeSlow=function(e){return f(e)},l.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==l.prototype},l.compare=function(e,r){if(C(e,Uint8Array)&&(e=l.from(e,e.offset,e.byteLength)),C(r,Uint8Array)&&(r=l.from(r,r.offset,r.byteLength)),!l.isBuffer(e)||!l.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var t=e.length,n=r.length,o=0,i=Math.min(t,n);o<i;++o)if(e[o]!==r[o]){t=e[o],n=r[o];break}return t<n?-1:n<t?1:0},l.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},l.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return l.alloc(0);var t;if(void 0===r)for(t=r=0;t<e.length;++t)r+=e[t].length;var n=l.allocUnsafe(r),o=0;for(t=0;t<e.length;++t){var i=e[t];if(C(i,Uint8Array)&&(i=l.from(i)),!l.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},l.byteLength=h,l.prototype._isBuffer=!0,l.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<e;r+=2)d(this,r,r+1);return this},l.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<e;r+=4)d(this,r,r+3),d(this,r+1,r+2);return this},l.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<e;r+=8)d(this,r,r+7),d(this,r+1,r+6),d(this,r+2,r+5),d(this,r+3,r+4);return this},l.prototype.toLocaleString=l.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?b(this,0,e):function(e,r,t){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===t||t>this.length)&&(t=this.length),t<=0)return"";if((t>>>=0)<=(r>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,r,t);case"utf8":case"utf-8":return b(this,r,t);case"ascii":return A(this,r,t);case"latin1":case"binary":return k(this,r,t);case"base64":return w(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,r,t);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},l.prototype.equals=function(e){if(!l.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===l.compare(this,e)},l.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},l.prototype.compare=function(e,r,t,n,o){if(C(e,Uint8Array)&&(e=l.from(e,e.offset,e.byteLength)),!l.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===r&&(r=0),void 0===t&&(t=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||t>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(o<=n&&t<=r)return 0;if(o<=n)return-1;if(t<=r)return 1;if(this===e)return 0;for(var i=(o>>>=0)-(n>>>=0),s=(t>>>=0)-(r>>>=0),u=Math.min(i,s),a=this.slice(n,o),f=e.slice(r,t),c=0;c<u;++c)if(a[c]!==f[c]){i=a[c],s=f[c];break}return i<s?-1:s<i?1:0},l.prototype.includes=function(e,r,t){return-1!==this.indexOf(e,r,t)},l.prototype.indexOf=function(e,r,t){return y(this,e,r,t,!0)},l.prototype.lastIndexOf=function(e,r,t){return y(this,e,r,t,!1)},l.prototype.write=function(e,r,t,n){if(void 0===r)n="utf8",t=this.length,r=0;else if(void 0===t&&"string"==typeof r)n=r,t=this.length,r=0;else{if(!isFinite(r))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");r>>>=0,isFinite(t)?(t>>>=0,void 0===n&&(n="utf8")):(n=t,t=void 0)}var o=this.length-r;if((void 0===t||o<t)&&(t=o),0<e.length&&(t<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i,s,u,a,f,c,l,p,h,d=!1;;)switch(n){case"hex":return g(this,e,r,t);case"utf8":case"utf-8":return p=r,h=t,q(j(e,(l=this).length-p),l,p,h);case"ascii":return v(this,e,r,t);case"latin1":case"binary":return v(this,e,r,t);case"base64":return a=this,f=r,c=t,q(S(e),a,f,c);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s=r,u=t,q(function(e,r){for(var t,n,o,i=[],s=0;s<e.length&&!((r-=2)<0);++s)t=e.charCodeAt(s),n=t>>8,o=t%256,i.push(o),i.push(n);return i}(e,(i=this).length-s),i,s,u);default:if(d)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),d=!0}},l.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var E=4096;function A(e,r,t){var n="";t=Math.min(e.length,t);for(var o=r;o<t;++o)n+=String.fromCharCode(127&e[o]);return n}function k(e,r,t){var n="";t=Math.min(e.length,t);for(var o=r;o<t;++o)n+=String.fromCharCode(e[o]);return n}function T(e,r,t){var n=e.length;(!r||r<0)&&(r=0),(!t||t<0||n<t)&&(t=n);for(var o="",i=r;i<t;++i)o+=x(e[i]);return o}function O(e,r,t){for(var n=e.slice(r,t),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function _(e,r,t){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(t<e+r)throw new RangeError("Trying to access beyond buffer length")}function I(e,r,t,n,o,i){if(!l.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(o<r||r<i)throw new RangeError('"value" argument is out of bounds');if(t+n>e.length)throw new RangeError("Index out of range")}function B(e,r,t,n,o,i){if(t+n>e.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function P(e,r,t,n,o){return r=+r,t>>>=0,o||B(e,0,t,4),i.write(e,r,t,n,23,4),t+4}function U(e,r,t,n,o){return r=+r,t>>>=0,o||B(e,0,t,8),i.write(e,r,t,n,52,8),t+8}l.prototype.slice=function(e,r){var t=this.length;(e=~~e)<0?(e+=t)<0&&(e=0):t<e&&(e=t),(r=void 0===r?t:~~r)<0?(r+=t)<0&&(r=0):t<r&&(r=t),r<e&&(r=e);var n=this.subarray(e,r);return n.__proto__=l.prototype,n},l.prototype.readUIntLE=function(e,r,t){e>>>=0,r>>>=0,t||_(e,r,this.length);for(var n=this[e],o=1,i=0;++i<r&&(o*=256);)n+=this[e+i]*o;return n},l.prototype.readUIntBE=function(e,r,t){e>>>=0,r>>>=0,t||_(e,r,this.length);for(var n=this[e+--r],o=1;0<r&&(o*=256);)n+=this[e+--r]*o;return n},l.prototype.readUInt8=function(e,r){return e>>>=0,r||_(e,1,this.length),this[e]},l.prototype.readUInt16LE=function(e,r){return e>>>=0,r||_(e,2,this.length),this[e]|this[e+1]<<8},l.prototype.readUInt16BE=function(e,r){return e>>>=0,r||_(e,2,this.length),this[e]<<8|this[e+1]},l.prototype.readUInt32LE=function(e,r){return e>>>=0,r||_(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},l.prototype.readUInt32BE=function(e,r){return e>>>=0,r||_(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},l.prototype.readIntLE=function(e,r,t){e>>>=0,r>>>=0,t||_(e,r,this.length);for(var n=this[e],o=1,i=0;++i<r&&(o*=256);)n+=this[e+i]*o;return(o*=128)<=n&&(n-=Math.pow(2,8*r)),n},l.prototype.readIntBE=function(e,r,t){e>>>=0,r>>>=0,t||_(e,r,this.length);for(var n=r,o=1,i=this[e+--n];0<n&&(o*=256);)i+=this[e+--n]*o;return(o*=128)<=i&&(i-=Math.pow(2,8*r)),i},l.prototype.readInt8=function(e,r){return e>>>=0,r||_(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},l.prototype.readInt16LE=function(e,r){e>>>=0,r||_(e,2,this.length);var t=this[e]|this[e+1]<<8;return 32768&t?4294901760|t:t},l.prototype.readInt16BE=function(e,r){e>>>=0,r||_(e,2,this.length);var t=this[e+1]|this[e]<<8;return 32768&t?4294901760|t:t},l.prototype.readInt32LE=function(e,r){return e>>>=0,r||_(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},l.prototype.readInt32BE=function(e,r){return e>>>=0,r||_(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},l.prototype.readFloatLE=function(e,r){return e>>>=0,r||_(e,4,this.length),i.read(this,e,!0,23,4)},l.prototype.readFloatBE=function(e,r){return e>>>=0,r||_(e,4,this.length),i.read(this,e,!1,23,4)},l.prototype.readDoubleLE=function(e,r){return e>>>=0,r||_(e,8,this.length),i.read(this,e,!0,52,8)},l.prototype.readDoubleBE=function(e,r){return e>>>=0,r||_(e,8,this.length),i.read(this,e,!1,52,8)},l.prototype.writeUIntLE=function(e,r,t,n){(e=+e,r>>>=0,t>>>=0,n)||I(this,e,r,t,Math.pow(2,8*t)-1,0);var o=1,i=0;for(this[r]=255&e;++i<t&&(o*=256);)this[r+i]=e/o&255;return r+t},l.prototype.writeUIntBE=function(e,r,t,n){(e=+e,r>>>=0,t>>>=0,n)||I(this,e,r,t,Math.pow(2,8*t)-1,0);var o=t-1,i=1;for(this[r+o]=255&e;0<=--o&&(i*=256);)this[r+o]=e/i&255;return r+t},l.prototype.writeUInt8=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,1,255,0),this[r]=255&e,r+1},l.prototype.writeUInt16LE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,2,65535,0),this[r]=255&e,this[r+1]=e>>>8,r+2},l.prototype.writeUInt16BE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=255&e,r+2},l.prototype.writeUInt32LE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=255&e,r+4},l.prototype.writeUInt32BE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=255&e,r+4},l.prototype.writeIntLE=function(e,r,t,n){if(e=+e,r>>>=0,!n){var o=Math.pow(2,8*t-1);I(this,e,r,t,o-1,-o)}var i=0,s=1,u=0;for(this[r]=255&e;++i<t&&(s*=256);)e<0&&0===u&&0!==this[r+i-1]&&(u=1),this[r+i]=(e/s>>0)-u&255;return r+t},l.prototype.writeIntBE=function(e,r,t,n){if(e=+e,r>>>=0,!n){var o=Math.pow(2,8*t-1);I(this,e,r,t,o-1,-o)}var i=t-1,s=1,u=0;for(this[r+i]=255&e;0<=--i&&(s*=256);)e<0&&0===u&&0!==this[r+i+1]&&(u=1),this[r+i]=(e/s>>0)-u&255;return r+t},l.prototype.writeInt8=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=255&e,r+1},l.prototype.writeInt16LE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,2,32767,-32768),this[r]=255&e,this[r+1]=e>>>8,r+2},l.prototype.writeInt16BE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=255&e,r+2},l.prototype.writeInt32LE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,4,2147483647,-2147483648),this[r]=255&e,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4},l.prototype.writeInt32BE=function(e,r,t){return e=+e,r>>>=0,t||I(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=255&e,r+4},l.prototype.writeFloatLE=function(e,r,t){return P(this,e,r,!0,t)},l.prototype.writeFloatBE=function(e,r,t){return P(this,e,r,!1,t)},l.prototype.writeDoubleLE=function(e,r,t){return U(this,e,r,!0,t)},l.prototype.writeDoubleBE=function(e,r,t){return U(this,e,r,!1,t)},l.prototype.copy=function(e,r,t,n){if(!l.isBuffer(e))throw new TypeError("argument should be a Buffer");if(t||(t=0),n||0===n||(n=this.length),r>=e.length&&(r=e.length),r||(r=0),0<n&&n<t&&(n=t),n===t)return 0;if(0===e.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(t<0||t>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-r<n-t&&(n=e.length-r+t);var o=n-t;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(r,t,n);else if(this===e&&t<r&&r<n)for(var i=o-1;0<=i;--i)e[i+r]=this[i+t];else Uint8Array.prototype.set.call(e,this.subarray(t,n),r);return o},l.prototype.fill=function(e,r,t,n){if("string"==typeof e){if("string"==typeof r?(n=r,r=0,t=this.length):"string"==typeof t&&(n=t,t=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!l.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){var o=e.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(e=o)}}else"number"==typeof e&&(e&=255);if(r<0||this.length<r||this.length<t)throw new RangeError("Out of range index");if(t<=r)return this;var i;if(r>>>=0,t=void 0===t?this.length:t>>>0,e||(e=0),"number"==typeof e)for(i=r;i<t;++i)this[i]=e;else{var s=l.isBuffer(e)?e:l.from(e,n),u=s.length;if(0===u)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<t-r;++i)this[i+r]=s[i%u]}return this};var R=/[^+/0-9A-Za-z-_]/g;function x(e){return e<16?"0"+e.toString(16):e.toString(16)}function j(e,r){var t;r=r||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if(55295<(t=e.charCodeAt(s))&&t<57344){if(!o){if(56319<t){-1<(r-=3)&&i.push(239,191,189);continue}if(s+1===n){-1<(r-=3)&&i.push(239,191,189);continue}o=t;continue}if(t<56320){-1<(r-=3)&&i.push(239,191,189),o=t;continue}t=65536+(o-55296<<10|t-56320)}else o&&-1<(r-=3)&&i.push(239,191,189);if(o=null,t<128){if((r-=1)<0)break;i.push(t)}else if(t<2048){if((r-=2)<0)break;i.push(t>>6|192,63&t|128)}else if(t<65536){if((r-=3)<0)break;i.push(t>>12|224,t>>6&63|128,63&t|128)}else{if(!(t<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(t>>18|240,t>>12&63|128,t>>6&63|128,63&t|128)}}return i}function S(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,r,t,n){for(var o=0;o<n&&!(o+t>=r.length||o>=e.length);++o)r[o+t]=e[o];return o}function C(e,r){return e instanceof r||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===r.name}function D(e){return e!=e}},{"base64-js":46,ieee754:50}],48:[function(e,r,t){"use strict";var n="captureStackTrace"in Error;function o(e){return{value:e,writable:!0,configurable:!0}}r.exports=function(e){var r;if(!e||"string"!=typeof e)throw new TypeError('Argument "name" must be a non-empty string.');return(r=function e(){if(!(this instanceof e))return new(e.bind.apply(e,Array.prototype.concat.apply([null],arguments)));(function(e){n?Error.captureStackTrace(this,this.constructor):Object.defineProperty(this,"stack",o(Error(e).stack)),Object.defineProperty(this,"message",o(void 0!==e?""+e:""))}).apply(this,arguments)}).prototype=Object.create(Error.prototype,{constructor:o(r),name:o(e)}),r}},{}],49:[function(e,n,r){!function(e){void 0!==n&&(n.exports=e);var o="listeners",t={on:function(e,r){return s(this,e).push(r),this},once:function(e,r){var t=this;return n.originalListener=r,s(t,e).push(n),t;function n(){i.call(t,e,n),r.apply(this,arguments)}},off:i,emit:function(e,r){var t=this,n=s(t,e,!0);if(!n)return!1;var o=arguments.length;if(1===o)n.forEach(function(e){e.call(t)});else if(2===o)n.forEach(function(e){e.call(t,r)});else{var i=Array.prototype.slice.call(arguments,1);n.forEach(function(e){e.apply(t,i)})}return!!n.length}};function r(e){for(var r in t)e[r]=t[r];return e}function i(e,r){var t,n=this;if(arguments.length){if(r){if(t=s(n,e,!0)){if(!(t=t.filter(function(e){return e!==r&&e.originalListener!==r})).length)return i.call(n,e);n[o][e]=t}}else if((t=n[o])&&(delete t[e],!Object.keys(t).length))return i.call(n)}else delete n[o];return n}function s(e,r,t){if(!t||e[o]){var n=e[o]||(e[o]={});return n[r]||(n[r]=[])}}r(e.prototype),e.mixin=r}(function e(){if(!(this instanceof e))return new e})},{}],50:[function(e,r,t){t.read=function(e,r,t,n,o){var i,s,u=8*o-n-1,a=(1<<u)-1,f=a>>1,c=-7,l=t?o-1:0,p=t?-1:1,h=e[r+l];for(l+=p,i=h&(1<<-c)-1,h>>=-c,c+=u;0<c;i=256*i+e[r+l],l+=p,c-=8);for(s=i&(1<<-c)-1,i>>=-c,c+=n;0<c;s=256*s+e[r+l],l+=p,c-=8);if(0===i)i=1-f;else{if(i===a)return s?NaN:1/0*(h?-1:1);s+=Math.pow(2,n),i-=f}return(h?-1:1)*s*Math.pow(2,i-n)},t.write=function(e,r,t,n,o,i){var s,u,a,f=8*i-o-1,c=(1<<f)-1,l=c>>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,d=n?1:-1,y=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(u=isNaN(r)?1:0,s=c):(s=Math.floor(Math.log(r)/Math.LN2),r*(a=Math.pow(2,-s))<1&&(s--,a*=2),2<=(r+=1<=s+l?p/a:p*Math.pow(2,1-l))*a&&(s++,a/=2),c<=s+l?(u=0,s=c):1<=s+l?(u=(r*a-1)*Math.pow(2,o),s+=l):(u=r*Math.pow(2,l-1)*Math.pow(2,o),s=0));8<=o;e[t+h]=255&u,h+=d,u/=256,o-=8);for(s=s<<o|u,f+=o;0<f;e[t+h]=255&s,h+=d,s/=256,f-=8);e[t+h-d]|=128*y}},{}],51:[function(e,r,t){function n(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}r.exports=function(e){return null!=e&&(n(e)||"function"==typeof(r=e).readFloatLE&&"function"==typeof r.slice&&n(r.slice(0,0))||!!e._isBuffer);var r}},{}]},{},[31]);