Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dexie-relationships

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dexie-relationships - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

dist/index.d.ts

11

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.dexieRelationships = factory());
}(this, (function () { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('dexie')) :
typeof define === 'function' && define.amd ? define(['dexie'], factory) :
(global.dexieRelationships = factory(global.Dexie));
}(this, (function (Dexie) { 'use strict';
Dexie = 'default' in Dexie ? Dexie['default'] : Dexie;
var SchemaParser = function SchemaParser (schema) {

@@ -73,3 +75,2 @@ this.schema = schema;

var Relationships = function (db) {
var Dexie = db.constructor;
// Use Dexie.Promise to ensure transaction safety.

@@ -76,0 +77,0 @@ var Promise = Dexie.Promise;

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dexieRelationships=t()}(this,function(){"use strict";function e(t){return null!=t&&("string"==typeof t||"number"==typeof t||t instanceof Date||Array.isArray(t)&&t.every(e))}var t=function(e){this.schema=e};t.prototype.getForeignKeys=function(){var e=this,t={};return Object.keys(this.schema).forEach(function(n){var r=e.schema[n].split(",");t[n]=r.filter(function(e){return e.indexOf("->")!==-1}).map(function(e){var t=e.split("->").map(function(e){return e.trim()}),n=t[0],r=t[1];return{index:n,targetTable:r.split(".")[0],targetIndex:r.split(".")[1]}})}),t},t.prototype.getCleanedSchema=function(){var e=this,t={};return Object.keys(this.schema).forEach(function(n){var r=e.schema[n].split(",");t[n]=r.map(function(e){return e.split("->")[0].trim()}).join(",")}),t};var n=function(n){var r=n.constructor,o=r.Promise;n.Table.prototype.with=function(e){return this.toCollection().with(e)},n.Collection.prototype.with=function(t){var r=this,i=this._ctx.table.name,a=n._allTables,f={};Object.keys(t).forEach(function(e){var n=t[e],o=r._ctx.table.schema.idxByName[n];if(o&&o.hasOwnProperty("foreignKey")){var c=o;f[c.foreignKey.targetTable]={column:e,index:c.foreignKey.targetIndex,targetIndex:c.foreignKey.index,oneToOne:!0}}else{var s=n;if(!a.hasOwnProperty(s))throw new Error("Relationship table "+s+" doesn't exist.");if(!a[s].schema.hasOwnProperty("foreignKeys"))throw new Error("Relationship table "+s+" doesn't have foreign keys set.");var u=a[s].schema.foreignKeys.filter(function(e){return e.targetTable===i});u.length>0&&(f[s]={column:e,index:u[0].index,targetIndex:u[0].targetIndex})}});var c=Object.keys(f);return this.toArray().then(function(t){var n=c.map(function(n){var r=f[n],o=t.map(function(e){return e[r.targetIndex]}).filter(e);return a[n].where(r.index).anyOf(o)}),r=n.map(function(e){return e.toArray()});return o.all(r).then(function(e){c.forEach(function(n,r){var o=f[n],a=e[r],c=o.targetIndex,s=o.index,u=o.column,h={};t.forEach(function(e){h[e[c]]=e}),a.forEach(function(e){var t=e[s],r=h[t];if(!r)throw new Error("Could not lookup foreign key where "+n+"."+s+" == "+i+"."+u+". The content of the failing key was: "+JSON.stringify(t)+".");o.oneToOne||!r.hasOwnProperty(u)?Object.defineProperty(r,u,{value:o.oneToOne?e:[e],enumerable:!1,configurable:!0,writable:!0}):o.oneToOne||r[u].push(e)})})}).then(function(){return t})})},n.Version.prototype._parseStoresSpec=r.override(n.Version.prototype._parseStoresSpec,function(e){return function(n,r){var o=new t(n),i=o.getForeignKeys(),a=e.call(this,o.getCleanedSchema(),r);return Object.keys(r).forEach(function(e){i.hasOwnProperty(e)&&(r[e].foreignKeys=i[e],i[e].forEach(function(t){r[e].idxByName[t.index].foreignKey=t}))}),a}})};return n});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("dexie")):"function"==typeof define&&define.amd?define(["dexie"],t):e.dexieRelationships=t(e.Dexie)}(this,function(e){"use strict";function t(e){return null!=e&&("string"==typeof e||"number"==typeof e||e instanceof Date||Array.isArray(e)&&e.every(t))}e="default"in e?e["default"]:e;var n=function(e){this.schema=e};n.prototype.getForeignKeys=function(){var e=this,t={};return Object.keys(this.schema).forEach(function(n){var r=e.schema[n].split(",");t[n]=r.filter(function(e){return e.indexOf("->")!==-1}).map(function(e){var t=e.split("->").map(function(e){return e.trim()}),n=t[0],r=t[1];return{index:n,targetTable:r.split(".")[0],targetIndex:r.split(".")[1]}})}),t},n.prototype.getCleanedSchema=function(){var e=this,t={};return Object.keys(this.schema).forEach(function(n){var r=e.schema[n].split(",");t[n]=r.map(function(e){return e.split("->")[0].trim()}).join(",")}),t};var r=function(r){var o=e.Promise;r.Table.prototype["with"]=function(e){return this.toCollection()["with"](e)},r.Collection.prototype["with"]=function(e){var n=this,i=this._ctx.table.name,a=r._allTables,f={};Object.keys(e).forEach(function(t){var r=e[t],o=n._ctx.table.schema.idxByName[r];if(o&&o.hasOwnProperty("foreignKey")){var c=o;f[c.foreignKey.targetTable]={column:t,index:c.foreignKey.targetIndex,targetIndex:c.foreignKey.index,oneToOne:!0}}else{var s=r;if(!a.hasOwnProperty(s))throw new Error("Relationship table "+s+" doesn't exist.");if(!a[s].schema.hasOwnProperty("foreignKeys"))throw new Error("Relationship table "+s+" doesn't have foreign keys set.");var u=a[s].schema.foreignKeys.filter(function(e){return e.targetTable===i});u.length>0&&(f[s]={column:t,index:u[0].index,targetIndex:u[0].targetIndex})}});var c=Object.keys(f);return this.toArray().then(function(e){var n=c.map(function(n){var r=f[n],o=e.map(function(e){return e[r.targetIndex]}).filter(t);return a[n].where(r.index).anyOf(o)}),r=n.map(function(e){return e.toArray()});return o.all(r).then(function(t){c.forEach(function(n,r){var o=f[n],a=t[r],c=o.targetIndex,s=o.index,u=o.column,h={};e.forEach(function(e){h[e[c]]=e}),a.forEach(function(e){var t=e[s],r=h[t];if(!r)throw new Error("Could not lookup foreign key where "+n+"."+s+" == "+i+"."+u+". The content of the failing key was: "+JSON.stringify(t)+".");o.oneToOne||!r.hasOwnProperty(u)?Object.defineProperty(r,u,{value:o.oneToOne?e:[e],enumerable:!1,configurable:!0,writable:!0}):o.oneToOne||r[u].push(e)})})}).then(function(){return e})})},r.Version.prototype._parseStoresSpec=e.override(r.Version.prototype._parseStoresSpec,function(e){return function(t,r){var o=new n(t),i=o.getForeignKeys(),a=e.call(this,o.getCleanedSchema(),r);return Object.keys(r).forEach(function(e){i.hasOwnProperty(e)&&(r[e].foreignKeys=i[e],i[e].forEach(function(t){r[e].idxByName[t.index].foreignKey=t}))}),a}})};return r});
{
"name": "dexie-relationships",
"version": "1.2.1",
"version": "1.2.2",
"description": "Dexie relationship plugin",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"directories": {

@@ -10,3 +11,3 @@ "test": "tests"

"peerDependencies": {
"dexie": "^2.0.0-beta.3"
"dexie": "^2.0.0-beta.10"
},

@@ -13,0 +14,0 @@ "devDependencies": {

@@ -8,6 +8,7 @@ import buble from 'rollup-plugin-buble'

dest: 'dist/index.js',
external: ['dexie'],
globals: {
Dexie: 'Dexie',
dexie: 'Dexie',
},
plugins: [ buble() ]
};

@@ -10,6 +10,7 @@ import buble from 'rollup-plugin-buble'

dest: 'dist/index.min.js',
external: ['dexie'],
globals: {
Dexie: 'Dexie',
dexie: 'Dexie',
},
plugins: [ buble(), uglify({}, minify) ]
};

@@ -0,1 +1,2 @@

import Dexie from 'dexie'
import SchemaParser from './schema-parser'

@@ -5,3 +6,2 @@ import {isIndexableType} from './utils'

const Relationships = (db) => {
const Dexie = db.constructor
// Use Dexie.Promise to ensure transaction safety.

@@ -8,0 +8,0 @@ const Promise = Dexie.Promise

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(this,function(){"use strict";function t(){le=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,n=t.length;e<n;++e)fe[e]=t[e],ce[t.charCodeAt(e)]=e;ce["-".charCodeAt(0)]=62,ce["_".charCodeAt(0)]=63}function e(e){le||t();var n,r,o,i,u,a,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");u="="===e[s-2]?2:"="===e[s-1]?1:0,a=new he(3*s/4-u),o=u>0?s-4:s;var f=0;for(n=0,r=0;n<o;n+=4,r+=3)i=ce[e.charCodeAt(n)]<<18|ce[e.charCodeAt(n+1)]<<12|ce[e.charCodeAt(n+2)]<<6|ce[e.charCodeAt(n+3)],a[f++]=i>>16&255,a[f++]=i>>8&255,a[f++]=255&i;return 2===u?(i=ce[e.charCodeAt(n)]<<2|ce[e.charCodeAt(n+1)]>>4,a[f++]=255&i):1===u&&(i=ce[e.charCodeAt(n)]<<10|ce[e.charCodeAt(n+1)]<<4|ce[e.charCodeAt(n+2)]>>2,a[f++]=i>>8&255,a[f++]=255&i),a}function n(t){return fe[t>>18&63]+fe[t>>12&63]+fe[t>>6&63]+fe[63&t]}function r(t,e,r){for(var o,i=[],u=e;u<r;u+=3)o=(t[u]<<16)+(t[u+1]<<8)+t[u+2],i.push(n(o));return i.join("")}function o(e){le||t();for(var n,o=e.length,i=o%3,u="",a=[],s=16383,f=0,c=o-i;f<c;f+=s)a.push(r(e,f,f+s>c?c:f+s));return 1===i?(n=e[o-1],u+=fe[n>>2],u+=fe[n<<4&63],u+="=="):2===i&&(n=(e[o-2]<<8)+e[o-1],u+=fe[n>>10],u+=fe[n>>4&63],u+=fe[n<<2&63],u+="="),a.push(u),a.join("")}function i(t,e,n,r,o){var i,u,a=8*o-r-1,s=(1<<a)-1,f=s>>1,c=-7,h=n?o-1:0,l=n?-1:1,p=t[e+h];for(h+=l,i=p&(1<<-c)-1,p>>=-c,c+=a;c>0;i=256*i+t[e+h],h+=l,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=r;c>0;u=256*u+t[e+h],h+=l,c-=8);if(0===i)i=1-f;else{if(i===s)return u?NaN:(p?-1:1)*(1/0);u+=Math.pow(2,r),i-=f}return(p?-1:1)*u*Math.pow(2,i-r)}function u(t,e,n,r,o,i){var u,a,s,f=8*i-o-1,c=(1<<f)-1,h=c>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:i-1,g=r?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,u=c):(u=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-u))<1&&(u--,s*=2),e+=u+h>=1?l/s:l*Math.pow(2,1-h),e*s>=2&&(u++,s/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(e*s-1)*Math.pow(2,o),u+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,o),u=0));o>=8;t[n+p]=255&a,p+=g,a/=256,o-=8);for(u=u<<o|a,f+=o;f>0;t[n+p]=255&u,p+=g,u/=256,f-=8);t[n+p-g]|=128*d}function a(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return f.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=f.prototype):(null===t&&(t=new f(e)),t.length=e),t}function f(t,e,n){if(!(f.TYPED_ARRAY_SUPPORT||this instanceof f))return new f(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return p(this,t)}return c(this,t,e,n)}function c(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?y(t,e,n,r):"string"==typeof e?g(t,e,n):b(t,e)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function l(t,e,n,r){return h(e),e<=0?s(t,e):void 0!==n?"string"==typeof r?s(t,e).fill(n,r):s(t,e).fill(n):s(t,e)}function p(t,e){if(h(e),t=s(t,e<0?0:0|m(e)),!f.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function g(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!f.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|v(e,n);t=s(t,r);var o=t.write(e,n);return o!==r&&(t=t.slice(0,o)),t}function d(t,e){var n=e.length<0?0:0|m(e.length);t=s(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function y(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),f.TYPED_ARRAY_SUPPORT?(t=e,t.__proto__=f.prototype):t=d(t,e),t}function b(t,e){if(w(e)){var n=0|m(e.length);return t=s(t,n),0===t.length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||X(e.length)?s(t,0):d(t,e);if("Buffer"===e.type&&ge(e.data))return d(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function m(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function w(t){return!(null==t||!t._isBuffer)}function v(t,e){if(w(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return $(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return Z(t).length;default:if(r)return $(t).length;e=(""+e).toLowerCase(),r=!0}}function E(t,e,n){var r=this,o=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return j(r,e,n);case"utf8":case"utf-8":return U(r,e,n);case"ascii":return Y(r,e,n);case"latin1":case"binary":return D(r,e,n);case"base64":return I(r,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(r,e,n);default:if(o)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function A(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function R(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=f.from(e,r)),w(e))return 0===e.length?-1:S(t,e,n,r,o);if("number"==typeof e)return e&=255,f.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):S(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function S(t,e,n,r,o){function i(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}var u=1,a=t.length,s=e.length;if(void 0!==r&&(r=String(r).toLowerCase(),"ucs2"===r||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;u=2,a/=2,s/=2,n/=2}var f;if(o){var c=-1;for(f=n;f<a;f++)if(i(t,f)===i(e,c===-1?0:f-c)){if(c===-1&&(c=f),f-c+1===s)return c*u}else c!==-1&&(f-=f-c),c=-1}else for(n+s>a&&(n=a-s),f=n;f>=0;f--){for(var h=!0,l=0;l<s;l++)if(i(t,f+l)!==i(e,l)){h=!1;break}if(h)return f}return-1}function T(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r),r>o&&(r=o)):r=o;var i=e.length;if(i%2!==0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var u=0;u<r;++u){var a=parseInt(e.substr(2*u,2),16);if(isNaN(a))return u;t[n+u]=a}return u}function O(t,e,n,r){return Q($(e,t.length-n),t,n,r)}function P(t,e,n,r){return Q(G(e),t,n,r)}function _(t,e,n,r){return P(t,e,n,r)}function x(t,e,n,r){return Q(Z(e),t,n,r)}function B(t,e,n,r){return Q(W(e,t.length-n),t,n,r)}function I(t,e,n){return o(0===e&&n===t.length?t:t.slice(e,n))}function U(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i=t[o],u=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=n){var s,f,c,h;switch(a){case 1:i<128&&(u=i);break;case 2:s=t[o+1],128===(192&s)&&(h=(31&i)<<6|63&s,h>127&&(u=h));break;case 3:s=t[o+1],f=t[o+2],128===(192&s)&&128===(192&f)&&(h=(15&i)<<12|(63&s)<<6|63&f,h>2047&&(h<55296||h>57343)&&(u=h));break;case 4:s=t[o+1],f=t[o+2],c=t[o+3],128===(192&s)&&128===(192&f)&&128===(192&c)&&(h=(15&i)<<18|(63&s)<<12|(63&f)<<6|63&c,h>65535&&h<1114112&&(u=h))}}null===u?(u=65533,a=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),o+=a}return k(r)}function k(t){var e=t.length;if(e<=ye)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=ye));return n}function Y(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function D(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function j(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=e;i<n;++i)o+=J(t[i]);return o}function C(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function L(t,e,n){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function M(t,e,n,r,o,i){if(!w(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function z(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function N(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function q(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function F(t,e,n,r,o){return o||q(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),u(t,e,n,r,23,4),n+4}function K(t,e,n,r,o){return o||q(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),u(t,e,n,r,52,8),n+8}function V(t){if(t=H(t).replace(be,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function H(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function J(t){return t<16?"0"+t.toString(16):t.toString(16)}function $(t,e){e=e||1/0;for(var n,r=t.length,o=null,i=[],u=0;u<r;++u){if(n=t.charCodeAt(u),n>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(u+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function G(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}function W(t,e){for(var n,r,o,i=[],u=0;u<t.length&&!((e-=2)<0);++u)n=t.charCodeAt(u),r=n>>8,o=n%256,i.push(o),i.push(r);return i}function Z(t){return e(V(t))}function Q(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function X(t){return t!==t}function tt(t){return null!=t&&(!!t._isBuffer||et(t)||nt(t))}function et(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function nt(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&et(t.slice(0,0))}function rt(){throw new Error("setTimeout has not been defined")}function ot(){throw new Error("clearTimeout has not been defined")}function ut(t,e){this.fun=t,this.array=e}function at(t,e){var n={seen:[],stylize:ft};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),mt(e)?n.showHidden=e:e&&Bt(n,e),At(n.showHidden)&&(n.showHidden=!1),At(n.depth)&&(n.depth=2),At(n.colors)&&(n.colors=!1),At(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=st),ht(n,t,n.depth)}function st(t,e){var n=at.styles[e];return n?"["+at.colors[n][0]+"m"+t+"["+at.colors[n][1]+"m":t}function ft(t,e){return t}function ct(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function ht(t,e,n){if(t.customInspect&&e&&Pt(e.inspect)&&e.inspect!==at&&(!e.constructor||e.constructor.prototype!==e)){var r=e.inspect(n,t);return Et(r)||(r=ht(t,r,n)),r}var o=lt(t,e);if(o)return o;var i=Object.keys(e),u=ct(i);if(t.showHidden&&(i=Object.getOwnPropertyNames(e)),Ot(e)&&(i.indexOf("message")>=0||i.indexOf("description")>=0))return pt(e);if(0===i.length){if(Pt(e)){var a=e.name?": "+e.name:"";return t.stylize("[Function"+a+"]","special")}if(Rt(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(Tt(e))return t.stylize(Date.prototype.toString.call(e),"date");if(Ot(e))return pt(e)}var s="",f=!1,c=["{","}"];if(bt(e)&&(f=!0,c=["[","]"]),Pt(e)){var h=e.name?": "+e.name:"";s=" [Function"+h+"]"}if(Rt(e)&&(s=" "+RegExp.prototype.toString.call(e)),Tt(e)&&(s=" "+Date.prototype.toUTCString.call(e)),Ot(e)&&(s=" "+pt(e)),0===i.length&&(!f||0==e.length))return c[0]+s+c[1];if(n<0)return Rt(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var l;return l=f?gt(t,e,n,u,i):i.map(function(r){return dt(t,e,n,u,r,f)}),t.seen.pop(),yt(l,s,c)}function lt(t,e){if(At(e))return t.stylize("undefined","undefined");if(Et(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return vt(e)?t.stylize(""+e,"number"):mt(e)?t.stylize(""+e,"boolean"):wt(e)?t.stylize("null","null"):void 0}function pt(t){return"["+Error.prototype.toString.call(t)+"]"}function gt(t,e,n,r,o){for(var i=[],u=0,a=e.length;u<a;++u)It(e,String(u))?i.push(dt(t,e,n,r,String(u),!0)):i.push("");return o.forEach(function(o){o.match(/^\d+$/)||i.push(dt(t,e,n,r,o,!0))}),i}function dt(t,e,n,r,o,i){var u,a,s;if(s=Object.getOwnPropertyDescriptor(e,o)||{value:e[o]},s.get?a=s.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):s.set&&(a=t.stylize("[Setter]","special")),It(r,o)||(u="["+o+"]"),a||(t.seen.indexOf(s.value)<0?(a=wt(n)?ht(t,s.value,null):ht(t,s.value,n-1),a.indexOf("\n")>-1&&(a=i?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")),At(u)){if(i&&o.match(/^\d+$/))return a;u=JSON.stringify(""+o),u.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=t.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=t.stylize(u,"string"))}return u+": "+a}function yt(t,e,n){var r=0,o=t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return o>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function bt(t){return Array.isArray(t)}function mt(t){return"boolean"==typeof t}function wt(t){return null===t}function vt(t){return"number"==typeof t}function Et(t){return"string"==typeof t}function At(t){return void 0===t}function Rt(t){return St(t)&&"[object RegExp]"===xt(t)}function St(t){return"object"==typeof t&&null!==t}function Tt(t){return St(t)&&"[object Date]"===xt(t)}function Ot(t){return St(t)&&("[object Error]"===xt(t)||t instanceof Error)}function Pt(t){return"function"==typeof t}function _t(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function xt(t){return Object.prototype.toString.call(t)}function Bt(t,e){if(!e||!St(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}function It(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Ut(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0}function kt(){return"undefined"!=typeof Re?Re:Re=function(){return"foo"===function(){}.name}()}function Yt(t){return Object.prototype.toString.call(t)}function Dt(t){return!tt(t)&&("function"==typeof se.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}function jt(t,e){t||qt(t,!0,e,"==",Ft)}function Ct(t){if(Pt(t)){if(kt())return t.name;var e=t.toString(),n=e.match(Pe);return n&&n[1]}}function Lt(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=Nt(this),this.generatedMessage=!0);var e=t.stackStartFunction||qt;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var n=new Error;if(n.stack){var r=n.stack,o=Ct(e),i=r.indexOf("\n"+o);if(i>=0){var u=r.indexOf("\n",i+1);r=r.substring(u+1)}this.stack=r}}}function Mt(t,e){return"string"==typeof t?t.length<e?t:t.slice(0,e):t}function zt(t){if(kt()||!Pt(t))return at(t);var e=Ct(t),n=e?": "+e:"";return"[Function"+n+"]"}function Nt(t){return Mt(zt(t.actual),128)+" "+t.operator+" "+Mt(zt(t.expected),128)}function qt(t,e,n,r,o){throw new Lt({message:n,actual:t,expected:e,operator:r,stackStartFunction:o})}function Ft(t,e){t||qt(t,!0,e,"==",Ft)}function Kt(t,e,n){t!=e&&qt(t,e,n,"==",Kt)}function Vt(t,e,n){t==e&&qt(t,e,n,"!=",Vt)}function Ht(t,e,n){$t(t,e,!1)||qt(t,e,n,"deepEqual",Ht)}function Jt(t,e,n){$t(t,e,!0)||qt(t,e,n,"deepStrictEqual",Jt)}function $t(t,e,n,r){if(t===e)return!0;if(tt(t)&&tt(e))return 0===Ut(t,e);if(Tt(t)&&Tt(e))return t.getTime()===e.getTime();if(Rt(t)&&Rt(e))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(null!==t&&"object"==typeof t||null!==e&&"object"==typeof e){if(Dt(t)&&Dt(e)&&Yt(t)===Yt(e)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===Ut(new Uint8Array(t.buffer),new Uint8Array(e.buffer));if(tt(t)!==tt(e))return!1;r=r||{actual:[],expected:[]};var o=r.actual.indexOf(t);return o!==-1&&o===r.expected.indexOf(e)||(r.actual.push(t),r.expected.push(e),Wt(t,e,n,r))}return n?t===e:t==e}function Gt(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function Wt(t,e,n,r){if(null===t||void 0===t||null===e||void 0===e)return!1;if(_t(t)||_t(e))return t===e;if(n&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var o=Gt(t),i=Gt(e);if(o&&!i||!o&&i)return!1;if(o)return t=Oe.call(t),e=Oe.call(e),$t(t,e,n);var u,a,s=Te(t),f=Te(e);if(s.length!==f.length)return!1;for(s.sort(),f.sort(),a=s.length-1;a>=0;a--)if(s[a]!==f[a])return!1;for(a=s.length-1;a>=0;a--)if(u=s[a],!$t(t[u],e[u],n,r))return!1;return!0}function Zt(t,e,n){$t(t,e,!1)&&qt(t,e,n,"notDeepEqual",Zt)}function Qt(t,e,n){$t(t,e,!0)&&qt(t,e,n,"notDeepStrictEqual",Qt)}function Xt(t,e,n){t!==e&&qt(t,e,n,"===",Xt)}function te(t,e,n){t===e&&qt(t,e,n,"!==",te)}function ee(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&e.call({},t)===!0}function ne(t){var e;try{t()}catch(t){e=t}return e}function re(t,e,n,r){var o;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),o=ne(e),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!o&&qt(o,n,"Missing expected exception"+r);var i="string"==typeof r,u=!t&&Ot(o),a=!t&&o&&!n;if((u&&i&&ee(o,n)||a)&&qt(o,n,"Got unwanted exception"+r),t&&o&&n&&!ee(o,n)||!t&&o)throw o}function oe(t,e,n){re(!0,t,e,n)}function ie(t,e,n){re(!1,t,e,n)}function ue(t){if(t)throw t}function ae(t){return null!=t&&("string"==typeof t||"number"==typeof t||t instanceof Date||Array.isArray(t)&&t.every(ae))}var se="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},fe=[],ce=[],he="undefined"!=typeof Uint8Array?Uint8Array:Array,le=!1,pe={}.toString,ge=Array.isArray||function(t){return"[object Array]"==pe.call(t)},de=50;f.TYPED_ARRAY_SUPPORT=void 0===se.TYPED_ARRAY_SUPPORT||se.TYPED_ARRAY_SUPPORT,f.poolSize=8192,f._augment=function(t){return t.__proto__=f.prototype,t},f.from=function(t,e,n){return c(null,t,e,n)},f.TYPED_ARRAY_SUPPORT&&(f.prototype.__proto__=Uint8Array.prototype,f.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&f[Symbol.species]===f),f.alloc=function(t,e,n){return l(null,t,e,n)},f.allocUnsafe=function(t){return p(null,t)},f.allocUnsafeSlow=function(t){return p(null,t)},f.isBuffer=tt,f.compare=function(t,e){if(!w(t)||!w(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},f.isEncoding=function(t){switch(String(t).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}},f.concat=function(t,e){if(!ge(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=f.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var i=t[n];if(!w(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},f.byteLength=v,f.prototype._isBuffer=!0,f.prototype.swap16=function(){var t=this,e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var n=0;n<e;n+=2)A(t,n,n+1);return this},f.prototype.swap32=function(){var t=this,e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var n=0;n<e;n+=4)A(t,n,n+3),A(t,n+1,n+2);return this},f.prototype.swap64=function(){var t=this,e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var n=0;n<e;n+=8)A(t,n,n+7),A(t,n+1,n+6),A(t,n+2,n+5),A(t,n+3,n+4);return this},f.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?U(this,0,t):E.apply(this,arguments)},f.prototype.equals=function(t){if(!w(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){var t="",e=de;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},f.prototype.compare=function(t,e,n,r,o){if(!w(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;for(var i=o-r,u=n-e,a=Math.min(i,u),s=this.slice(r,o),f=t.slice(e,n),c=0;c<a;++c)if(s[c]!==f[c]){i=s[c],u=f[c];break}return i<u?-1:u<i?1:0},f.prototype.includes=function(t,e,n){return this.indexOf(t,e,n)!==-1},f.prototype.indexOf=function(t,e,n){return R(this,t,e,n,!0)},f.prototype.lastIndexOf=function(t,e,n){return R(this,t,e,n,!1)},f.prototype.write=function(t,e,n,r){var o=this;if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var u=!1;;)switch(r){case"hex":return T(o,t,e,n);case"utf8":case"utf-8":return O(o,t,e,n);case"ascii":return P(o,t,e,n);case"latin1":case"binary":return _(o,t,e,n);case"base64":return x(o,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(o,t,e,n);default:if(u)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),u=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ye=4096;f.prototype.slice=function(t,e){var n=this,r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),e<t&&(e=t);var o;if(f.TYPED_ARRAY_SUPPORT)o=this.subarray(t,e),o.__proto__=f.prototype;else{var i=e-t;o=new f(i,void 0);for(var u=0;u<i;++u)o[u]=n[u+t]}return o},f.prototype.readUIntLE=function(t,e,n){var r=this;t|=0,e|=0,n||L(t,e,this.length);for(var o=this[t],i=1,u=0;++u<e&&(i*=256);)o+=r[t+u]*i;return o},f.prototype.readUIntBE=function(t,e,n){var r=this;t|=0,e|=0,n||L(t,e,this.length);for(var o=this[t+--e],i=1;e>0&&(i*=256);)o+=r[t+--e]*i;return o},f.prototype.readUInt8=function(t,e){return e||L(t,1,this.length),this[t]},f.prototype.readUInt16LE=function(t,e){return e||L(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUInt16BE=function(t,e){return e||L(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUInt32LE=function(t,e){return e||L(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUInt32BE=function(t,e){return e||L(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readIntLE=function(t,e,n){var r=this;t|=0,e|=0,n||L(t,e,this.length);for(var o=this[t],i=1,u=0;++u<e&&(i*=256);)o+=r[t+u]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},f.prototype.readIntBE=function(t,e,n){var r=this;t|=0,e|=0,n||L(t,e,this.length);for(var o=e,i=1,u=this[t+--o];o>0&&(i*=256);)u+=r[t+--o]*i;return i*=128,u>=i&&(u-=Math.pow(2,8*e)),u},f.prototype.readInt8=function(t,e){return e||L(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},f.prototype.readInt16LE=function(t,e){e||L(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},f.prototype.readInt16BE=function(t,e){e||L(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},f.prototype.readInt32LE=function(t,e){return e||L(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return e||L(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readFloatLE=function(t,e){return e||L(t,4,this.length),i(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,e){return e||L(t,4,this.length),i(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,e){return e||L(t,8,this.length),i(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,e){return e||L(t,8,this.length),i(this,t,!1,52,8)},f.prototype.writeUIntLE=function(t,e,n,r){var o=this;if(t=+t,e|=0,n|=0,!r){var i=Math.pow(2,8*n)-1;M(this,t,e,n,i,0)}var u=1,a=0;for(this[e]=255&t;++a<n&&(u*=256);)o[e+a]=t/u&255;return e+n},f.prototype.writeUIntBE=function(t,e,n,r){var o=this;if(t=+t,e|=0,n|=0,!r){var i=Math.pow(2,8*n)-1;M(this,t,e,n,i,0)}var u=n-1,a=1;for(this[e+u]=255&t;--u>=0&&(a*=256);)o[e+u]=t/a&255;return e+n},f.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,1,255,0),f.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},f.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,!0),e+2},f.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,!1),e+2},f.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},f.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},f.prototype.writeIntLE=function(t,e,n,r){var o=this;if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);M(this,t,e,n,i-1,-i)}var u=0,a=1,s=0;for(this[e]=255&t;++u<n&&(a*=256);)t<0&&0===s&&0!==o[e+u-1]&&(s=1),o[e+u]=(t/a>>0)-s&255;return e+n},f.prototype.writeIntBE=function(t,e,n,r){var o=this;if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);M(this,t,e,n,i-1,-i)}var u=n-1,a=1,s=0;for(this[e+u]=255&t;--u>=0&&(a*=256);)t<0&&0===s&&0!==o[e+u+1]&&(s=1),o[e+u]=(t/a>>0)-s&255;return e+n},f.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,1,127,-128),f.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},f.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,!0),e+2},f.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,!1),e+2},f.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,4,2147483647,-2147483648),f.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},f.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||M(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),f.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},f.prototype.writeFloatLE=function(t,e,n){return F(this,t,e,!0,n)},f.prototype.writeFloatBE=function(t,e,n){return F(this,t,e,!1,n)},f.prototype.writeDoubleLE=function(t,e,n){return K(this,t,e,!0,n)},f.prototype.writeDoubleBE=function(t,e,n){return K(this,t,e,!1,n)},f.prototype.copy=function(t,e,n,r){var o=this;if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var i,u=r-n;if(this===t&&n<e&&e<r)for(i=u-1;i>=0;--i)t[i+e]=o[i+n];else if(u<1e3||!f.TYPED_ARRAY_SUPPORT)for(i=0;i<u;++i)t[i+e]=o[i+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+u),e);return u},f.prototype.fill=function(t,e,n,r){var o=this;if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!f.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var u;if("number"==typeof t)for(u=e;u<n;++u)o[u]=t;else{var a=w(t)?t:$(new f(t,r).toString()),s=a.length;for(u=0;u<n-e;++u)o[u+e]=a[u%s]}return this};var be=/[^+\/0-9A-Za-z-_]/g,me=rt,we=ot;"function"==typeof se.setTimeout&&(me=setTimeout),"function"==typeof se.clearTimeout&&(we=clearTimeout);ut.prototype.run=function(){this.fun.apply(null,this.array)};var ve,Ee=se.performance||{};Ee.now||Ee.mozNow||Ee.msNow||Ee.oNow||Ee.webkitNow||function(){return(new Date).getTime()},new Date;ve="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t};var Ae=ve;at.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]},at.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};var Re,Se=Object.prototype.hasOwnProperty,Te=Object.keys||function(t){var e=[];for(var n in t)Se.call(t,n)&&e.push(n);return e},Oe=Array.prototype.slice,Pe=/\s*function\s+([^\(\s]*)\s*/;jt.AssertionError=Lt,Ae(Lt,Error),jt.fail=qt,jt.ok=Ft,jt.equal=Kt,jt.notEqual=Vt,jt.deepEqual=Ht,jt.deepStrictEqual=Jt,jt.notDeepEqual=Zt,jt.notDeepStrictEqual=Qt,jt.strictEqual=Xt,jt.notStrictEqual=te,jt.throws=oe,jt.doesNotThrow=ie,jt.ifError=ue;var _e=function(t){this.schema=t};_e.prototype.getForeignKeys=function(){var t=this,e={};return Object.keys(this.schema).forEach(function(n){var r=t.schema[n].split(",");e[n]=r.filter(function(t){return t.indexOf("->")!==-1}).map(function(t){var e=t.split("->").map(function(t){return t.trim()}),n=e[0],r=e[1];return{index:n,targetTable:r.split(".")[0],targetIndex:r.split(".")[1]
}})}),e},_e.prototype.getCleanedSchema=function(){var t=this,e={};return Object.keys(this.schema).forEach(function(n){var r=t.schema[n].split(",");e[n]=r.map(function(t){return t.split("->")[0].trim()}).join(",")}),e};var xe=function(t){var e=t.constructor,n=e.Promise;t.Table.prototype.with=function(t){return this.toCollection().with(t)},t.Collection.prototype.with=function(e){var r=this,o=this._ctx.table.name,i=t._allTables,u={};Object.keys(e).forEach(function(t){var n=e[t],a=r._ctx.table.schema.idxByName[n];if(a&&a.hasOwnProperty("foreignKey")){var s=a;u[s.foreignKey.targetTable]={column:t,index:s.foreignKey.targetIndex,targetIndex:s.foreignKey.index,oneToOne:!0}}else{var f=n;if(!i.hasOwnProperty(f))throw new Error("Relationship table "+f+" doesn't exist.");if(!i[f].schema.hasOwnProperty("foreignKeys"))throw new Error("Relationship table "+f+" doesn't have foreign keys set.");var c=i[f].schema.foreignKeys.filter(function(t){return t.targetTable===o});c.length>0&&(u[f]={column:t,index:c[0].index,targetIndex:c[0].targetIndex})}});var a=Object.keys(u);return this.toArray().then(function(t){var e=a.map(function(e){var n=u[e],r=t.map(function(t){return t[n.targetIndex]}).filter(ae);return i[e].where(n.index).anyOf(r)}),r=e.map(function(t){return t.toArray()});return n.all(r).then(function(e){a.forEach(function(n,r){var i=u[n],a=e[r],s=i.targetIndex,f=i.index,c=i.column,h={};t.forEach(function(t){h[t[s]]=t}),a.forEach(function(t){var e=t[f],r=h[e];if(!r)throw new Error("Could not lookup foreign key where "+n+"."+f+" == "+o+"."+c+". The content of the failing key was: "+JSON.stringify(e)+".");i.oneToOne||!r.hasOwnProperty(c)?Object.defineProperty(r,c,{value:i.oneToOne?t:[t],enumerable:!1,configurable:!0,writable:!0}):i.oneToOne||r[c].push(t)})})}).then(function(){return t})})},t.Version.prototype._parseStoresSpec=e.override(t.Version.prototype._parseStoresSpec,function(t){return function(e,n){var r=new _e(e),o=r.getForeignKeys(),i=t.call(this,r.getCleanedSchema(),n);return Object.keys(n).forEach(function(t){o.hasOwnProperty(t)&&(n[t].foreignKeys=o[t],o[t].forEach(function(e){n[t].idxByName[e.index].foreignKey=e}))}),i}})};describe("simple",function(){var t=(Dexie.Promise,new Dexie("bands-simple",{addons:[xe]}));t.version(1).stores({genres:"\n id,\n name",bands:"\n id,\n name,\n genreId -> genres.id",albums:"\n id,\n name,\n bandId -> bands.id,\n year"}),beforeEach(function(){return t.delete().then(function(){return t.open()}).then(function(){return t.transaction("rw",t.bands,t.albums,t.genres,function(){t.genres.bulkAdd([{id:1,name:"Rock"},{id:2,name:"Schlager"}]),t.bands.bulkAdd([{id:1,name:"Beatles",genreId:1},{id:2,name:"Abba",genreId:2}]),t.albums.bulkAdd([{id:1,name:"Abbey Road",year:1969,bandId:1},{id:2,name:"Let It Be",year:1970,bandId:1},{id:3,name:"Super Trouper",bandId:2,year:1980},{id:4,name:"Waterloo",bandId:2,year:1974}])})})}),describe("many-to-one",function(){it("should be possible to retrieve an entity with a collection of referring entities attached to it",function(){return t.bands.where("name").equals("Beatles").with({albums:"albums"}).then(function(t){jt(1==t.length,"Should be one Beatles");var e=t[0];jt(!!e.albums,"Should have got the foreign albums collection"),jt(2===e.albums.length,"Should have 2 albums in this db"),jt("Abbey Road"===e.albums[0].name,"First albums should be 'Abbey Roead'"),jt("Let It Be"===e.albums[1].name,"Second album should be 'Let It Be'")})})}),describe("one-to-one",function(){it("should be possible to retrieve entity with a foreign key to expand that foreign key",function(){return t.albums.where("year").between(1970,1974,!0,!0).with({band:"bandId"}).then(function(t){jt(2===t.length,"Should retrieve two albums between 1970 to 1974");var e=t[0],n=t[1];jt("Let It Be"===e.name,"First album should be 'Let It Be'"),jt(!!e.band,"Should get the band resolved with the query"),jt("Beatles"===e.band.name,"The band should be Beatles"),jt("Waterloo"===n.name,"Second album should be 'Waterloo'"),jt(!!n.band,"Should get the band resolved with the query"),jt("Abba"===n.band.name,"The band should be Abba")})})}),describe("Multiple foreign keys of different kind",function(){it("Should be possible to retrieve entities with oneToOne as well as manyToOne relations",function(){return t.bands.where("name").equals("Beatles").with({albums:"albums",genre:"genreId"}).then(function(t){jt(1==t.length,"Should be one Beatles");var e=t[0];jt(!!e.albums,"Should have got the foreign albums collection"),jt(2===e.albums.length,"Should have 2 albums in this db"),jt("Abbey Road"===e.albums[0].name,"First albums should be 'Abbey Roead'"),jt("Let It Be"===e.albums[1].name,"Second album should be 'Let It Be'"),jt(!!e.genre,"Should have got the foreign genre entity"),jt("Rock"===e.genre.name,"The genre should be 'Rock' (even though that could be questionable)")})})}),describe("Navigation properties should be non-enumerable",function(){it("should be possible to put back an object to indexedDB after having retrieved it with navigation properties without storing the navigation properties redundantly",function(){return t.bands.where("name").equals("Abba").with({albums:"albums",genre:"genreId"}).then(function(e){jt(1===e.length,"Should be one Abba");var n=e[0];return jt(!!n.albums,"Abba should have its 'albums' foreign collection"),jt(!!n.genre,"Abba should have its 'genre' foreign property"),n.customProperty="Hello world",t.bands.put(n)}).then(function(){return t.bands.where("name").equals("Abba").first()}).then(function(t){jt(!t.albums,"Abba should not have the 'albums' foreign collection stored redundantly"),jt(!t.genre,"Abba should not have the 'genre' foreign property stored redundantly")})})}),describe("Sample from README",function(){it("should be possible to copy and paste the sample from README",function(){return t.bands.where("name").startsWithAnyOf("A","B").with({albums:"albums",genre:"genreId"}).then(function(t){t.forEach(function(t){console.log("Band Name: "+t.name),console.log("Genre: "+t.genre.name),console.log("Albums: "+JSON.stringify(t.albums,null,4))})}).then(function(){jt(!0,"Promise resolved and no exception occured")}).catch(function(t){jt(!1,"Something went wrong: "+(t.stack||t))})})})})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("dexie")):"function"==typeof define&&define.amd?define(["dexie"],e):e(t.Dexie)}(this,function(t){"use strict";function e(){le=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,r=t.length;e<r;++e)se[e]=t[e],ce[t.charCodeAt(e)]=e;ce["-".charCodeAt(0)]=62,ce["_".charCodeAt(0)]=63}function r(t){le||e();var r,n,o,i,u,a,f=t.length;if(f%4>0)throw new Error("Invalid string. Length must be a multiple of 4");u="="===t[f-2]?2:"="===t[f-1]?1:0,a=new he(3*f/4-u),o=u>0?f-4:f;var s=0;for(r=0,n=0;r<o;r+=4,n+=3)i=ce[t.charCodeAt(r)]<<18|ce[t.charCodeAt(r+1)]<<12|ce[t.charCodeAt(r+2)]<<6|ce[t.charCodeAt(r+3)],a[s++]=i>>16&255,a[s++]=i>>8&255,a[s++]=255&i;return 2===u?(i=ce[t.charCodeAt(r)]<<2|ce[t.charCodeAt(r+1)]>>4,a[s++]=255&i):1===u&&(i=ce[t.charCodeAt(r)]<<10|ce[t.charCodeAt(r+1)]<<4|ce[t.charCodeAt(r+2)]>>2,a[s++]=i>>8&255,a[s++]=255&i),a}function n(t){return se[t>>18&63]+se[t>>12&63]+se[t>>6&63]+se[63&t]}function o(t,e,r){for(var o,i=[],u=e;u<r;u+=3)o=(t[u]<<16)+(t[u+1]<<8)+t[u+2],i.push(n(o));return i.join("")}function i(t){le||e();for(var r,n=t.length,i=n%3,u="",a=[],f=16383,s=0,c=n-i;s<c;s+=f)a.push(o(t,s,s+f>c?c:s+f));return 1===i?(r=t[n-1],u+=se[r>>2],u+=se[r<<4&63],u+="=="):2===i&&(r=(t[n-2]<<8)+t[n-1],u+=se[r>>10],u+=se[r>>4&63],u+=se[r<<2&63],u+="="),a.push(u),a.join("")}function u(t,e,r,n,o){var i,u,a=8*o-n-1,f=(1<<a)-1,s=f>>1,c=-7,h=r?o-1:0,l=r?-1:1,p=t[e+h];for(h+=l,i=p&(1<<-c)-1,p>>=-c,c+=a;c>0;i=256*i+t[e+h],h+=l,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=n;c>0;u=256*u+t[e+h],h+=l,c-=8);if(0===i)i=1-s;else{if(i===f)return u?NaN:(p?-1:1)*(1/0);u+=Math.pow(2,n),i-=s}return(p?-1:1)*u*Math.pow(2,i-n)}function a(t,e,r,n,o,i){var u,a,f,s=8*i-o-1,c=(1<<s)-1,h=c>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,u=c):(u=Math.floor(Math.log(e)/Math.LN2),e*(f=Math.pow(2,-u))<1&&(u--,f*=2),e+=u+h>=1?l/f:l*Math.pow(2,1-h),e*f>=2&&(u++,f/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(e*f-1)*Math.pow(2,o),u+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,o),u=0));o>=8;t[r+p]=255&a,p+=g,a/=256,o-=8);for(u=u<<o|a,s+=o;s>0;t[r+p]=255&u,p+=g,u/=256,s-=8);t[r+p-g]|=128*d}function f(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(f()<e)throw new RangeError("Invalid typed array length");return c.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=c.prototype):(null===t&&(t=new c(e)),t.length=e),t}function c(t,e,r){if(!(c.TYPED_ARRAY_SUPPORT||this instanceof c))return new c(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return g(this,t)}return h(this,t,e,r)}function h(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?b(t,e,r,n):"string"==typeof e?d(t,e,r):m(t,e)}function l(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function p(t,e,r,n){return l(e),e<=0?s(t,e):void 0!==r?"string"==typeof n?s(t,e).fill(r,n):s(t,e).fill(r):s(t,e)}function g(t,e){if(l(e),t=s(t,e<0?0:0|w(e)),!c.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function d(t,e,r){if("string"==typeof r&&""!==r||(r="utf8"),!c.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|E(e,r);t=s(t,n);var o=t.write(e,r);return o!==n&&(t=t.slice(0,o)),t}function y(t,e){var r=e.length<0?0:0|w(e.length);t=s(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function b(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n),c.TYPED_ARRAY_SUPPORT?(t=e,t.__proto__=c.prototype):t=y(t,e),t}function m(t,e){if(v(e)){var r=0|w(e.length);return t=s(t,r),0===t.length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||tt(e.length)?s(t,0):y(t,e);if("Buffer"===e.type&&ge(e.data))return y(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function w(t){if(t>=f())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+f().toString(16)+" bytes");return 0|t}function v(t){return!(null==t||!t._isBuffer)}function E(t,e){if(v(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return G(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Q(t).length;default:if(n)return G(t).length;e=(""+e).toLowerCase(),n=!0}}function A(t,e,r){var n=this,o=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return C(n,e,r);case"utf8":case"utf-8":return k(n,e,r);case"ascii":return D(n,e,r);case"latin1":case"binary":return j(n,e,r);case"base64":return U(n,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(n,e,r);default:if(o)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function R(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function S(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=c.from(e,n)),v(e))return 0===e.length?-1:T(t,e,r,n,o);if("number"==typeof e)return e=255&e,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):T(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function T(t,e,r,n,o){function i(t,e){return 1===u?t[e]:t.readUInt16BE(e*u)}var u=1,a=t.length,f=e.length;if(void 0!==n&&(n=String(n).toLowerCase(),"ucs2"===n||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;u=2,a/=2,f/=2,r/=2}var s;if(o){var c=-1;for(s=r;s<a;s++)if(i(t,s)===i(e,c===-1?0:s-c)){if(c===-1&&(c=s),s-c+1===f)return c*u}else c!==-1&&(s-=s-c),c=-1}else for(r+f>a&&(r=a-f),s=r;s>=0;s--){for(var h=!0,l=0;l<f;l++)if(i(t,s+l)!==i(e,l)){h=!1;break}if(h)return s}return-1}function O(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n),n>o&&(n=o)):n=o;var i=e.length;if(i%2!==0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u<n;++u){var a=parseInt(e.substr(2*u,2),16);if(isNaN(a))return u;t[r+u]=a}return u}function P(t,e,r,n){return X(G(e,t.length-r),t,r,n)}function _(t,e,r,n){return X(W(e),t,r,n)}function x(t,e,r,n){return _(t,e,r,n)}function B(t,e,r,n){return X(Q(e),t,r,n)}function I(t,e,r,n){return X(Z(e,t.length-r),t,r,n)}function U(t,e,r){return i(0===e&&r===t.length?t:t.slice(e,r))}function k(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i=t[o],u=null,a=i>239?4:i>223?3:i>191?2:1;if(o+a<=r){var f,s,c,h;switch(a){case 1:i<128&&(u=i);break;case 2:f=t[o+1],128===(192&f)&&(h=(31&i)<<6|63&f,h>127&&(u=h));break;case 3:f=t[o+1],s=t[o+2],128===(192&f)&&128===(192&s)&&(h=(15&i)<<12|(63&f)<<6|63&s,h>2047&&(h<55296||h>57343)&&(u=h));break;case 4:f=t[o+1],s=t[o+2],c=t[o+3],128===(192&f)&&128===(192&s)&&128===(192&c)&&(h=(15&i)<<18|(63&f)<<12|(63&s)<<6|63&c,h>65535&&h<1114112&&(u=h))}}null===u?(u=65533,a=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),o+=a}return Y(n)}function Y(t){var e=t.length;if(e<=ye)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=ye));return r}function D(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function j(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function C(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=$(t[i]);return o}function L(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function M(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function z(t,e,r,n,o,i){if(!v(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function N(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function q(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function F(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function K(t,e,r,n,o){return o||F(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),a(t,e,r,n,23,4),r+4}function V(t,e,r,n,o){return o||F(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),a(t,e,r,n,52,8),r+8}function H(t){if(t=J(t).replace(be,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function J(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function $(t){return t<16?"0"+t.toString(16):t.toString(16)}function G(t,e){e=e||1/0;for(var r,n=t.length,o=null,i=[],u=0;u<n;++u){if(r=t.charCodeAt(u),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function W(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function Z(t,e){for(var r,n,o,i=[],u=0;u<t.length&&!((e-=2)<0);++u)r=t.charCodeAt(u),n=r>>8,o=r%256,i.push(o),i.push(n);return i}function Q(t){return r(H(t))}function X(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function tt(t){return t!==t}function et(t){return null!=t&&(!!t._isBuffer||rt(t)||nt(t))}function rt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function nt(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&rt(t.slice(0,0))}function ot(){throw new Error("setTimeout has not been defined")}function ut(){throw new Error("clearTimeout has not been defined")}function at(t,e){var r={seen:[],stylize:st};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),mt(e)?r.showHidden=e:e&&Bt(r,e),At(r.showHidden)&&(r.showHidden=!1),At(r.depth)&&(r.depth=2),At(r.colors)&&(r.colors=!1),At(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=ft),ht(r,t,r.depth)}function ft(t,e){var r=at.styles[e];return r?"["+at.colors[r][0]+"m"+t+"["+at.colors[r][1]+"m":t}function st(t,e){return t}function ct(t){var e={};return t.forEach(function(t,r){e[t]=!0}),e}function ht(t,e,r){if(t.customInspect&&e&&Pt(e.inspect)&&e.inspect!==at&&(!e.constructor||e.constructor.prototype!==e)){var n=e.inspect(r,t);return Et(n)||(n=ht(t,n,r)),n}var o=lt(t,e);if(o)return o;var i=Object.keys(e),u=ct(i);if(t.showHidden&&(i=Object.getOwnPropertyNames(e)),Ot(e)&&(i.indexOf("message")>=0||i.indexOf("description")>=0))return pt(e);if(0===i.length){if(Pt(e)){var a=e.name?": "+e.name:"";return t.stylize("[Function"+a+"]","special")}if(Rt(e))return t.stylize(RegExp.prototype.toString.call(e),"regexp");if(Tt(e))return t.stylize(Date.prototype.toString.call(e),"date");if(Ot(e))return pt(e)}var f="",s=!1,c=["{","}"];if(bt(e)&&(s=!0,c=["[","]"]),Pt(e)){var h=e.name?": "+e.name:"";f=" [Function"+h+"]"}if(Rt(e)&&(f=" "+RegExp.prototype.toString.call(e)),Tt(e)&&(f=" "+Date.prototype.toUTCString.call(e)),Ot(e)&&(f=" "+pt(e)),0===i.length&&(!s||0==e.length))return c[0]+f+c[1];if(r<0)return Rt(e)?t.stylize(RegExp.prototype.toString.call(e),"regexp"):t.stylize("[Object]","special");t.seen.push(e);var l;return l=s?gt(t,e,r,u,i):i.map(function(n){return dt(t,e,r,u,n,s)}),t.seen.pop(),yt(l,f,c)}function lt(t,e){if(At(e))return t.stylize("undefined","undefined");if(Et(e)){var r="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(r,"string")}return vt(e)?t.stylize(""+e,"number"):mt(e)?t.stylize(""+e,"boolean"):wt(e)?t.stylize("null","null"):void 0}function pt(t){return"["+Error.prototype.toString.call(t)+"]"}function gt(t,e,r,n,o){for(var i=[],u=0,a=e.length;u<a;++u)It(e,String(u))?i.push(dt(t,e,r,n,String(u),!0)):i.push("");return o.forEach(function(o){o.match(/^\d+$/)||i.push(dt(t,e,r,n,o,!0))}),i}function dt(t,e,r,n,o,i){var u,a,f;if(f=Object.getOwnPropertyDescriptor(e,o)||{value:e[o]},f.get?a=f.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):f.set&&(a=t.stylize("[Setter]","special")),It(n,o)||(u="["+o+"]"),a||(t.seen.indexOf(f.value)<0?(a=wt(r)?ht(t,f.value,null):ht(t,f.value,r-1),a.indexOf("\n")>-1&&(a=i?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")),At(u)){if(i&&o.match(/^\d+$/))return a;u=JSON.stringify(""+o),u.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=t.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=t.stylize(u,"string"))}return u+": "+a}function yt(t,e,r){var n=0,o=t.reduce(function(t,e){return n++,e.indexOf("\n")>=0&&n++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return o>60?r[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+r[1]:r[0]+e+" "+t.join(", ")+" "+r[1]}function bt(t){return Array.isArray(t)}function mt(t){return"boolean"==typeof t}function wt(t){return null===t}function vt(t){return"number"==typeof t}function Et(t){return"string"==typeof t}function At(t){return void 0===t}function Rt(t){return St(t)&&"[object RegExp]"===xt(t)}function St(t){return"object"==typeof t&&null!==t}function Tt(t){return St(t)&&"[object Date]"===xt(t)}function Ot(t){return St(t)&&("[object Error]"===xt(t)||t instanceof Error)}function Pt(t){return"function"==typeof t}function _t(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function xt(t){return Object.prototype.toString.call(t)}function Bt(t,e){if(!e||!St(e))return t;for(var r=Object.keys(e),n=r.length;n--;)t[r[n]]=e[r[n]];return t}function It(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Ut(t,e){if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0}function kt(){return"undefined"!=typeof Re?Re:Re=function(){return"foo"===function(){}.name}()}function Yt(t){return Object.prototype.toString.call(t)}function Dt(t){return!et(t)&&("function"==typeof fe.ArrayBuffer&&("function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):!!t&&(t instanceof DataView||!!(t.buffer&&t.buffer instanceof ArrayBuffer))))}function jt(t,e){t||qt(t,!0,e,"==",Ft)}function Ct(t){if(Pt(t)){if(kt())return t.name;var e=t.toString(),r=e.match(Pe);return r&&r[1]}}function Lt(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=Nt(this),this.generatedMessage=!0);var e=t.stackStartFunction||qt;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var r=new Error;if(r.stack){var n=r.stack,o=Ct(e),i=n.indexOf("\n"+o);if(i>=0){var u=n.indexOf("\n",i+1);n=n.substring(u+1)}this.stack=n}}}function Mt(t,e){return"string"==typeof t?t.length<e?t:t.slice(0,e):t}function zt(t){if(kt()||!Pt(t))return at(t);var e=Ct(t),r=e?": "+e:"";return"[Function"+r+"]"}function Nt(t){return Mt(zt(t.actual),128)+" "+t.operator+" "+Mt(zt(t.expected),128)}function qt(t,e,r,n,o){throw new Lt({message:r,actual:t,expected:e,operator:n,stackStartFunction:o})}function Ft(t,e){t||qt(t,!0,e,"==",Ft)}function Kt(t,e,r){t!=e&&qt(t,e,r,"==",Kt)}function Vt(t,e,r){t==e&&qt(t,e,r,"!=",Vt)}function Ht(t,e,r){$t(t,e,!1)||qt(t,e,r,"deepEqual",Ht)}function Jt(t,e,r){$t(t,e,!0)||qt(t,e,r,"deepStrictEqual",Jt)}function $t(t,e,r,n){if(t===e)return!0;if(et(t)&&et(e))return 0===Ut(t,e);if(Tt(t)&&Tt(e))return t.getTime()===e.getTime();if(Rt(t)&&Rt(e))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(null!==t&&"object"==typeof t||null!==e&&"object"==typeof e){if(Dt(t)&&Dt(e)&&Yt(t)===Yt(e)&&!(t instanceof Float32Array||t instanceof Float64Array))return 0===Ut(new Uint8Array(t.buffer),new Uint8Array(e.buffer));if(et(t)!==et(e))return!1;n=n||{actual:[],expected:[]};var o=n.actual.indexOf(t);return o!==-1&&o===n.expected.indexOf(e)||(n.actual.push(t),n.expected.push(e),Wt(t,e,r,n))}return r?t===e:t==e}function Gt(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function Wt(t,e,r,n){if(null===t||void 0===t||null===e||void 0===e)return!1;if(_t(t)||_t(e))return t===e;if(r&&Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;var o=Gt(t),i=Gt(e);if(o&&!i||!o&&i)return!1;if(o)return t=Oe.call(t),e=Oe.call(e),$t(t,e,r);var u,a,f=Te(t),s=Te(e);if(f.length!==s.length)return!1;for(f.sort(),s.sort(),a=f.length-1;a>=0;a--)if(f[a]!==s[a])return!1;for(a=f.length-1;a>=0;a--)if(u=f[a],!$t(t[u],e[u],r,n))return!1;return!0}function Zt(t,e,r){$t(t,e,!1)&&qt(t,e,r,"notDeepEqual",Zt)}function Qt(t,e,r){$t(t,e,!0)&&qt(t,e,r,"notDeepStrictEqual",Qt)}function Xt(t,e,r){t!==e&&qt(t,e,r,"===",Xt)}function te(t,e,r){t===e&&qt(t,e,r,"!==",te)}function ee(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(r){}return!Error.isPrototypeOf(e)&&e.call({},t)===!0}function re(t){var e;try{t()}catch(r){e=r}return e}function ne(t,e,r,n){var o;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(n=r,r=null),o=re(e),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),t&&!o&&qt(o,r,"Missing expected exception"+n);var i="string"==typeof n,u=!t&&Ot(o),a=!t&&o&&!r;if((u&&i&&ee(o,r)||a)&&qt(o,r,"Got unwanted exception"+n),t&&o&&r&&!ee(o,r)||!t&&o)throw o}function oe(t,e,r){ne(!0,t,e,r)}function ie(t,e,r){ne(!1,t,e,r)}function ue(t){if(t)throw t}function ae(t){return null!=t&&("string"==typeof t||"number"==typeof t||t instanceof Date||Array.isArray(t)&&t.every(ae))}t="default"in t?t["default"]:t;var fe="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},se=[],ce=[],he="undefined"!=typeof Uint8Array?Uint8Array:Array,le=!1,pe={}.toString,ge=Array.isArray||function(t){return"[object Array]"==pe.call(t)},de=50;c.TYPED_ARRAY_SUPPORT=void 0===fe.TYPED_ARRAY_SUPPORT||fe.TYPED_ARRAY_SUPPORT,c.poolSize=8192,c._augment=function(t){return t.__proto__=c.prototype,t},c.from=function(t,e,r){return h(null,t,e,r)},c.TYPED_ARRAY_SUPPORT&&(c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&c[Symbol.species]===c),c.alloc=function(t,e,r){return p(null,t,e,r)},c.allocUnsafe=function(t){return g(null,t)},c.allocUnsafeSlow=function(t){return g(null,t)},c.isBuffer=et,c.compare=function(t,e){if(!v(t)||!v(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},c.isEncoding=function(t){switch(String(t).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}},c.concat=function(t,e){if(!ge(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return c.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=c.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var i=t[r];if(!v(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o),o+=i.length}return n},c.byteLength=E,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var t=this,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)R(t,r,r+1);return this},c.prototype.swap32=function(){var t=this,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)R(t,r,r+3),R(t,r+1,r+2);return this},c.prototype.swap64=function(){var t=this,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)R(t,r,r+7),R(t,r+1,r+6),R(t,r+2,r+5),R(t,r+3,r+4);return this},c.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?k(this,0,t):A.apply(this,arguments)},c.prototype.equals=function(t){if(!v(t))throw new TypeError("Argument must be a Buffer");return this===t||0===c.compare(this,t)},c.prototype.inspect=function(){var t="",e=de;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},c.prototype.compare=function(t,e,r,n,o){if(!v(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,o>>>=0,this===t)return 0;for(var i=o-n,u=r-e,a=Math.min(i,u),f=this.slice(n,o),s=t.slice(e,r),c=0;c<a;++c)if(f[c]!==s[c]){i=f[c],u=s[c];break}return i<u?-1:u<i?1:0},c.prototype.includes=function(t,e,r){return this.indexOf(t,e,r)!==-1},c.prototype.indexOf=function(t,e,r){return S(this,t,e,r,!0)},c.prototype.lastIndexOf=function(t,e,r){return S(this,t,e,r,!1)},c.prototype.write=function(t,e,r,n){var o=this;if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e=0|e,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var u=!1;;)switch(n){case"hex":return O(o,t,e,r);case"utf8":case"utf-8":return P(o,t,e,r);case"ascii":return _(o,t,e,r);case"latin1":case"binary":return x(o,t,e,r);case"base64":return B(o,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(o,t,e,r);default:if(u)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),u=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var ye=4096;c.prototype.slice=function(t,e){var r=this,n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<t&&(e=t);var o;if(c.TYPED_ARRAY_SUPPORT)o=this.subarray(t,e),o.__proto__=c.prototype;else{var i=e-t;o=new c(i,(void 0));for(var u=0;u<i;++u)o[u]=r[u+t]}return o},c.prototype.readUIntLE=function(t,e,r){var n=this;t=0|t,e=0|e,r||M(t,e,this.length);for(var o=this[t],i=1,u=0;++u<e&&(i*=256);)o+=n[t+u]*i;return o},c.prototype.readUIntBE=function(t,e,r){var n=this;t=0|t,e=0|e,r||M(t,e,this.length);for(var o=this[t+--e],i=1;e>0&&(i*=256);)o+=n[t+--e]*i;return o},c.prototype.readUInt8=function(t,e){return e||M(t,1,this.length),this[t]},c.prototype.readUInt16LE=function(t,e){return e||M(t,2,this.length),this[t]|this[t+1]<<8},c.prototype.readUInt16BE=function(t,e){return e||M(t,2,this.length),this[t]<<8|this[t+1]},c.prototype.readUInt32LE=function(t,e){return e||M(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},c.prototype.readUInt32BE=function(t,e){return e||M(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},c.prototype.readIntLE=function(t,e,r){var n=this;t=0|t,e=0|e,r||M(t,e,this.length);for(var o=this[t],i=1,u=0;++u<e&&(i*=256);)o+=n[t+u]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},c.prototype.readIntBE=function(t,e,r){var n=this;t=0|t,e=0|e,r||M(t,e,this.length);for(var o=e,i=1,u=this[t+--o];o>0&&(i*=256);)u+=n[t+--o]*i;return i*=128,u>=i&&(u-=Math.pow(2,8*e)),u},c.prototype.readInt8=function(t,e){return e||M(t,1,this.length),128&this[t]?(255-this[t]+1)*-1:this[t]},c.prototype.readInt16LE=function(t,e){e||M(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(t,e){e||M(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(t,e){return e||M(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},c.prototype.readInt32BE=function(t,e){return e||M(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},c.prototype.readFloatLE=function(t,e){return e||M(t,4,this.length),u(this,t,!0,23,4)},c.prototype.readFloatBE=function(t,e){return e||M(t,4,this.length),u(this,t,!1,23,4)},c.prototype.readDoubleLE=function(t,e){return e||M(t,8,this.length),u(this,t,!0,52,8)},c.prototype.readDoubleBE=function(t,e){return e||M(t,8,this.length),u(this,t,!1,52,8)},c.prototype.writeUIntLE=function(t,e,r,n){var o=this;if(t=+t,e=0|e,r=0|r,!n){var i=Math.pow(2,8*r)-1;z(this,t,e,r,i,0)}var u=1,a=0;for(this[e]=255&t;++a<r&&(u*=256);)o[e+a]=t/u&255;return e+r},c.prototype.writeUIntBE=function(t,e,r,n){var o=this;if(t=+t,e=0|e,r=0|r,!n){var i=Math.pow(2,8*r)-1;z(this,t,e,r,i,0)}var u=r-1,a=1;for(this[e+u]=255&t;--u>=0&&(a*=256);)o[e+u]=t/a&255;return e+r},c.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,1,255,0),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},c.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},c.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},c.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):q(this,t,e,!0),e+4},c.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):q(this,t,e,!1),e+4},c.prototype.writeIntLE=function(t,e,r,n){var o=this;if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);z(this,t,e,r,i-1,-i)}var u=0,a=1,f=0;for(this[e]=255&t;++u<r&&(a*=256);)t<0&&0===f&&0!==o[e+u-1]&&(f=1),o[e+u]=(t/a>>0)-f&255;return e+r},c.prototype.writeIntBE=function(t,e,r,n){var o=this;if(t=+t,e=0|e,!n){var i=Math.pow(2,8*r-1);z(this,t,e,r,i-1,-i)}var u=r-1,a=1,f=0;for(this[e+u]=255&t;--u>=0&&(a*=256);)t<0&&0===f&&0!==o[e+u+1]&&(f=1),o[e+u]=(t/a>>0)-f&255;return e+r},c.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,1,127,-128),c.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},c.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):N(this,t,e,!0),e+2},c.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):N(this,t,e,!1),e+2},c.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):q(this,t,e,!0),e+4},c.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||z(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),c.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):q(this,t,e,!1),e+4},c.prototype.writeFloatLE=function(t,e,r){return K(this,t,e,!0,r)},c.prototype.writeFloatBE=function(t,e,r){return K(this,t,e,!1,r)},c.prototype.writeDoubleLE=function(t,e,r){return V(this,t,e,!0,r)},c.prototype.writeDoubleBE=function(t,e,r){return V(this,t,e,!1,r)},c.prototype.copy=function(t,e,r,n){var o=this;if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var i,u=n-r;if(this===t&&r<e&&e<n)for(i=u-1;i>=0;--i)t[i+e]=o[i+r];else if(u<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i<u;++i)t[i+e]=o[i+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+u),e);return u},c.prototype.fill=function(t,e,r,n){var o=this;if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t=255&t);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var u;if("number"==typeof t)for(u=e;u<r;++u)o[u]=t;else{var a=v(t)?t:G(new c(t,n).toString()),f=a.length;for(u=0;u<r-e;++u)o[u+e]=a[u%f]}return this};var be=/[^+\/0-9A-Za-z-_]/g,me=ot,we=ut;"function"==typeof fe.setTimeout&&(me=setTimeout),"function"==typeof fe.clearTimeout&&(we=clearTimeout);var ve,Ee=fe.performance||{};Ee.now||Ee.mozNow||Ee.msNow||Ee.oNow||Ee.webkitNow||function(){return(new Date).getTime()};ve="function"==typeof Object.create?function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t};var Ae=ve;at.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]},at.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};var Re,Se=Object.prototype.hasOwnProperty,Te=Object.keys||function(t){var e=[];for(var r in t)Se.call(t,r)&&e.push(r);return e},Oe=Array.prototype.slice,Pe=/\s*function\s+([^\(\s]*)\s*/;jt.AssertionError=Lt,Ae(Lt,Error),jt.fail=qt,jt.ok=Ft,jt.equal=Kt,jt.notEqual=Vt,jt.deepEqual=Ht,jt.deepStrictEqual=Jt,jt.notDeepEqual=Zt,jt.notDeepStrictEqual=Qt,jt.strictEqual=Xt,jt.notStrictEqual=te,jt["throws"]=oe,jt.doesNotThrow=ie,jt.ifError=ue;var _e=function(t){this.schema=t};_e.prototype.getForeignKeys=function(){var t=this,e={};return Object.keys(this.schema).forEach(function(r){var n=t.schema[r].split(",");e[r]=n.filter(function(t){return t.indexOf("->")!==-1}).map(function(t){var e=t.split("->").map(function(t){return t.trim()}),r=e[0],n=e[1];return{index:r,targetTable:n.split(".")[0],targetIndex:n.split(".")[1]
}})}),e},_e.prototype.getCleanedSchema=function(){var t=this,e={};return Object.keys(this.schema).forEach(function(r){var n=t.schema[r].split(",");e[r]=n.map(function(t){return t.split("->")[0].trim()}).join(",")}),e};var xe=function(e){var r=t.Promise;e.Table.prototype["with"]=function(t){return this.toCollection()["with"](t)},e.Collection.prototype["with"]=function(t){var n=this,o=this._ctx.table.name,i=e._allTables,u={};Object.keys(t).forEach(function(e){var r=t[e],a=n._ctx.table.schema.idxByName[r];if(a&&a.hasOwnProperty("foreignKey")){var f=a;u[f.foreignKey.targetTable]={column:e,index:f.foreignKey.targetIndex,targetIndex:f.foreignKey.index,oneToOne:!0}}else{var s=r;if(!i.hasOwnProperty(s))throw new Error("Relationship table "+s+" doesn't exist.");if(!i[s].schema.hasOwnProperty("foreignKeys"))throw new Error("Relationship table "+s+" doesn't have foreign keys set.");var c=i[s].schema.foreignKeys.filter(function(t){return t.targetTable===o});c.length>0&&(u[s]={column:e,index:c[0].index,targetIndex:c[0].targetIndex})}});var a=Object.keys(u);return this.toArray().then(function(t){var e=a.map(function(e){var r=u[e],n=t.map(function(t){return t[r.targetIndex]}).filter(ae);return i[e].where(r.index).anyOf(n)}),n=e.map(function(t){return t.toArray()});return r.all(n).then(function(e){a.forEach(function(r,n){var i=u[r],a=e[n],f=i.targetIndex,s=i.index,c=i.column,h={};t.forEach(function(t){h[t[f]]=t}),a.forEach(function(t){var e=t[s],n=h[e];if(!n)throw new Error("Could not lookup foreign key where "+r+"."+s+" == "+o+"."+c+". The content of the failing key was: "+JSON.stringify(e)+".");i.oneToOne||!n.hasOwnProperty(c)?Object.defineProperty(n,c,{value:i.oneToOne?t:[t],enumerable:!1,configurable:!0,writable:!0}):i.oneToOne||n[c].push(t)})})}).then(function(){return t})})},e.Version.prototype._parseStoresSpec=t.override(e.Version.prototype._parseStoresSpec,function(t){return function(e,r){var n=new _e(e),o=n.getForeignKeys(),i=t.call(this,n.getCleanedSchema(),r);return Object.keys(r).forEach(function(t){o.hasOwnProperty(t)&&(r[t].foreignKeys=o[t],o[t].forEach(function(e){r[t].idxByName[e.index].foreignKey=e}))}),i}})};describe("simple",function(){var t=(Dexie.Promise,new Dexie("bands-simple",{addons:[xe]}));t.version(1).stores({genres:"\n id,\n name",bands:"\n id,\n name,\n genreId -> genres.id",albums:"\n id,\n name,\n bandId -> bands.id,\n year"}),beforeEach(function(){return t["delete"]().then(function(){return t.open()}).then(function(){return t.transaction("rw",t.bands,t.albums,t.genres,function(){t.genres.bulkAdd([{id:1,name:"Rock"},{id:2,name:"Schlager"}]),t.bands.bulkAdd([{id:1,name:"Beatles",genreId:1},{id:2,name:"Abba",genreId:2}]),t.albums.bulkAdd([{id:1,name:"Abbey Road",year:1969,bandId:1},{id:2,name:"Let It Be",year:1970,bandId:1},{id:3,name:"Super Trouper",bandId:2,year:1980},{id:4,name:"Waterloo",bandId:2,year:1974}])})})}),describe("many-to-one",function(){it("should be possible to retrieve an entity with a collection of referring entities attached to it",function(){return t.bands.where("name").equals("Beatles")["with"]({albums:"albums"}).then(function(t){jt(1==t.length,"Should be one Beatles");var e=t[0];jt(!!e.albums,"Should have got the foreign albums collection"),jt(2===e.albums.length,"Should have 2 albums in this db"),jt("Abbey Road"===e.albums[0].name,"First albums should be 'Abbey Roead'"),jt("Let It Be"===e.albums[1].name,"Second album should be 'Let It Be'")})})}),describe("one-to-one",function(){it("should be possible to retrieve entity with a foreign key to expand that foreign key",function(){return t.albums.where("year").between(1970,1974,!0,!0)["with"]({band:"bandId"}).then(function(t){jt(2===t.length,"Should retrieve two albums between 1970 to 1974");var e=t[0],r=t[1];jt("Let It Be"===e.name,"First album should be 'Let It Be'"),jt(!!e.band,"Should get the band resolved with the query"),jt("Beatles"===e.band.name,"The band should be Beatles"),jt("Waterloo"===r.name,"Second album should be 'Waterloo'"),jt(!!r.band,"Should get the band resolved with the query"),jt("Abba"===r.band.name,"The band should be Abba")})})}),describe("Multiple foreign keys of different kind",function(){it("Should be possible to retrieve entities with oneToOne as well as manyToOne relations",function(){return t.bands.where("name").equals("Beatles")["with"]({albums:"albums",genre:"genreId"}).then(function(t){jt(1==t.length,"Should be one Beatles");var e=t[0];jt(!!e.albums,"Should have got the foreign albums collection"),jt(2===e.albums.length,"Should have 2 albums in this db"),jt("Abbey Road"===e.albums[0].name,"First albums should be 'Abbey Roead'"),jt("Let It Be"===e.albums[1].name,"Second album should be 'Let It Be'"),jt(!!e.genre,"Should have got the foreign genre entity"),jt("Rock"===e.genre.name,"The genre should be 'Rock' (even though that could be questionable)")})})}),describe("Navigation properties should be non-enumerable",function(){it("should be possible to put back an object to indexedDB after having retrieved it with navigation properties without storing the navigation properties redundantly",function(){return t.bands.where("name").equals("Abba")["with"]({albums:"albums",genre:"genreId"}).then(function(e){jt(1===e.length,"Should be one Abba");var r=e[0];return jt(!!r.albums,"Abba should have its 'albums' foreign collection"),jt(!!r.genre,"Abba should have its 'genre' foreign property"),r.customProperty="Hello world",t.bands.put(r)}).then(function(){return t.bands.where("name").equals("Abba").first()}).then(function(t){jt(!t.albums,"Abba should not have the 'albums' foreign collection stored redundantly"),jt(!t.genre,"Abba should not have the 'genre' foreign property stored redundantly")})})}),describe("Sample from README",function(){it("should be possible to copy and paste the sample from README",function(){return t.bands.where("name").startsWithAnyOf("A","B")["with"]({albums:"albums",genre:"genreId"}).then(function(t){t.forEach(function(t){console.log("Band Name: "+t.name),console.log("Genre: "+t.genre.name),console.log("Albums: "+JSON.stringify(t.albums,null,4))})}).then(function(){jt(!0,"Promise resolved and no exception occured")})["catch"](function(t){jt(!1,"Something went wrong: "+(t.stack||t))})})})})});

@@ -11,3 +11,5 @@ import buble from 'rollup-plugin-buble'

dest: 'bundle.js',
external: ['dexie'],
globals: {dexie: 'Dexie'},
plugins: [buble(), globals(), builtins(), uglify({}, minify)]
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc