From cb616957d927107363312a8969eee0ffc4aaa4dd Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Mon, 20 Feb 2017 17:53:28 +0100 Subject: [PATCH 1/3] Add missing export (as mentioned in issue #7) --- dist/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dist/index.d.ts b/dist/index.d.ts index e95e0ad..3c5cece 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -13,3 +13,7 @@ declare module 'dexie' { } } } + +declare var dexieRelationships: (db: Dexie) => void; + +export default dexieRelationships; From 71772912b1936490600595dc4aa6aaf1dbcf7948 Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Fri, 24 Feb 2017 11:27:21 +0100 Subject: [PATCH 2/3] Version-bump for npm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3f169d0..0a1d963 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dexie-relationships", - "version": "1.2.2", + "version": "1.2.3", "description": "Dexie relationship plugin", "main": "dist/index.js", "typings": "dist/index.d.ts", From 847b91ee0a3bb1f6c7f15834e91262bfdaf2b16c Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Fri, 24 Feb 2017 11:37:04 +0100 Subject: [PATCH 3/3] built and tested --- dist/index.min.js | 2 +- test/browser/bundle.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/index.min.js b/dist/index.min.js index f1fe9c0..259811f 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!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}); +!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}); diff --git a/test/browser/bundle.js b/test/browser/bundle.js index 1175aa9..0cb1dd7 100644 --- a/test/browser/bundle.js +++ b/test/browser/bundle.js @@ -1,2 +1,2 @@ -!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;e0)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>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;uc?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<>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<>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<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()=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;sa&&(r=a-f),s=r;s>=0;s--){for(var h=!0,l=0;lo&&(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;u239?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;nn)&&(r=n);for(var o="",i=e;ir)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||et.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>>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>>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;u55295&&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>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=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-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=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=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);o0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(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;ci)&&(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),e0&&(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=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=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>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=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=0;--i)t[i+e]=o[i+r];else if(u<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var u;if("number"==typeof t)for(u=e;u")!==-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))})})})})}); +!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;e0)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>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;uc?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<>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<>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<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()=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,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;sa&&(r=a-f),s=r;s>=0;s--){for(var h=!0,l=0;lo&&(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;u239?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;nn)&&(r=n);for(var o="",i=e;ir)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||et.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>>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>>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;u55295&&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>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=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-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=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=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(t){}return!Error.isPrototypeOf(e)&&e.call({},t)===!0}function re(t){var e;try{t()}catch(t){e=t}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);o0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(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;ci)&&(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),e0&&(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,e|=0,r||M(t,e,this.length);for(var o=this[t],i=1,u=0;++u=i&&(o-=Math.pow(2,8*e)),o},c.prototype.readIntBE=function(t,e,r){var n=this;t|=0,e|=0,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,r|=0,!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=0&&(a*=256);)o[e+u]=t/a&255;return e+r},c.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,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,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,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,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,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,!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>0)-f&255;return e+r},c.prototype.writeIntBE=function(t,e,r,n){var o=this;if(t=+t,e|=0,!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,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,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,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,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,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=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=0;--i)t[i+e]=o[i+r];else if(u<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var u;if("number"==typeof t)for(u=e;u")!==-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))})})})})});