f9db43a2e9
* Add key * Add: a second index uuid, push changes to sync controller * Add: sync.js * Add: tokenManager * Change: log entire body for http error * Add: token flow * Fix: minor * Fix: move cleanup to stop function * Add: syncNow * Update dependencies * Fix: handle 401 error * Add: handle 401 error * Fix: then -> catch * Add: sync options to options page * Update db-to-cloud * Change: make prefs.set return a promise * Add: disble selector if connected * Add: update selector state * Fix: return promise in prefs.set * Fix: manage complex state * Fix: handle prefs change * Change: manage sync status in background * Add: show current status in the UI * Add: schedule a faster sync when db changed * Update dependencies * Add: include progress in sync status * Add: more detail status * Show status text only * Bump dependencies * Change: show loaded and total * Fix: syncTarget is undefined * Add: google and onedrive * Fix: token is not reused * Bump dependencies * Don't use minified version since it is hard to debug * Fix: expire time is incorrect * Change: switch google to code flow * Bump dependencies * Change: only modify pref if the initialization success? * Don't stop the sync if the first sync is not triggered by the user * Add: implement refresh token * Change: switch microsoft to code flow * Add: subtract expire with a latency * Add: microsoft client secret * Add: display error message * Fix: fromPref is not used * Change: try to revoke the token when log out * Add: revoke dropbox token * Fix: Google only generates one refresh token for one user by default * Bump dependencies, fix onedrive list issue * Fix: arguments sent to sync.put is wrong * Fix: don't schedule a sync on db changed if not connected * Bump dependencies. Fix issue of switching drives * Bump db-to-cloud, fix switching drive issue * Fix: only auth user on 401 error, don't display login window without user interaction * Fix: don't call revoke() if token is undefined * Add: login button to generate the access token interactively * Fix: make addMissingProperties a local * Fix: store missing props in an object * Fix: sync.getStatus should be sync * LATENCY -> NETWORK_LATENCY * Fix: cache the token forever if there is no expire time e.g. dropbox * Add some comments * Fix: i18n * Fix: i18n sync status * fixup! Fix: i18n sync status * Fix: 'sync to cloud' is displayed twice
3 lines
20 KiB
JavaScript
3 lines
20 KiB
JavaScript
var dbToCloud=function(t){"use strict";function e(t,e,n,o,r,i,c){try{var a=t[i](c),l=a.value}catch(t){return void n(t)}a.done?e(l):Promise.resolve(l).then(o,r)}function n(t){return function(){var n=this,o=arguments;return new Promise((function(r,i){var c=t.apply(n,o);function a(t){e(c,r,i,a,l,"next",t)}function l(t){e(c,r,i,a,l,"throw",t)}a(void 0)}))}}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,o)}return n}function i(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(n,!0).forEach((function(e){o(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(n).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function c(t,e){if(null==t)return{};var n,o,r=function(t,e){if(null==t)return{};var n,o,r={},i=Object.keys(t);for(o=0;o<i.length;o++)n=i[o],e.indexOf(n)>=0||(r[n]=t[n]);return r}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)n=i[o],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}function a(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var n=[],o=!0,r=!1,i=void 0;try{for(var c,a=t[Symbol.iterator]();!(o=(c=a.next()).done)&&(n.push(c.value),!e||n.length!==e);o=!0);}catch(t){r=!0,i=t}finally{try{o||null==a.return||a.return()}finally{if(r)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function l({maxActiveReader:t=1/0}={}){let e,n,o=0;const r={read:t=>i(t,!1),write:t=>i(t,!0),length:0};return r;function i(i,a){const l=function({fn:t,block:e=!1,prev:n,next:o,q:r=c(),q2:i=(t.length?c():null)}){return{fn:t,block:e,prev:n,next:o,q:r,q2:i}}({fn:i,block:a});return n?(n.next=l,l.prev=n,n=l,e||(e=n)):e=n=l,r.length++,function i(){const c=e;if(!c||c.block&&c.prev||c.prev&&c.prev.block||o>=t)return;c.block||o++;e=c.next;let a;try{a=c.fn(c.q2&&c.q2.resolve)}catch(t){return c.q.reject(t),void l()}c.q2&&c.q2.promise.then(s);if(a&&a.then){const t=a.then(c.q.resolve,c.q.reject);c.q2||t.then(l)}else if(c.q.resolve(a),!c.q2)return void l();i();function l(){s()}function s(t){c.prev&&(c.prev.next=c.next),c.next&&(c.next.prev=c.prev),n===c&&(n=c.prev),c.block||o--,r.length--,t&&t(),i()}}(),l.q.promise}function c(){const t={};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t}}function s(t){let e,n=0;return()=>(n&&clearTimeout(n),n=setTimeout(o),e||(e=function(){const t={};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t}()),e.promise);function o(){Promise.resolve(t()).then(e.resolve,e.reject),n=0,e=null}}const u={};function p(t){return String.fromCharCode(parseInt(t.slice(1),16))}function f(t){return"%".concat("00".concat(t.charCodeAt(0).toString(16)).slice(-2))}Object.defineProperty(u,"__esModule",{value:!0}),u.encode=function(t){return btoa(encodeURIComponent(t).replace(/%[0-9A-F]{2}/g,p))},u.decode=function(t){return decodeURIComponent(Array.from(atob(t),f).join(""))};class d extends Error{constructor(t,e,n=e&&e.status){super(t),this.code=n,this.origin=e,Error.captureStackTrace&&Error.captureStackTrace(this,d)}}function h(t){return new Promise(e=>setTimeout(e,t))}function y({fetch:t,cooldown:e=0,getAccessToken:o}){const r=l();return t=>r.write(function(){var o=n((function*(n){try{return yield function(t){return a.apply(this,arguments)}(t)}finally{e&&t.method&&"GET"!==t.method?setTimeout(n,e):n()}}));return function(t){return o.apply(this,arguments)}}());function a(){return(a=n((function*(e){let n=e.path,r=e.contentType,a=e.headers,l=e.format,s=c(e,["path","contentType","headers","format"]);const u={Authorization:"Bearer ".concat(yield o())};for(r&&(u["Content-Type"]=r),Object.assign(u,a);;){const e=yield t(n,i({headers:u},s));if(!e.ok){const t=e.headers.get("Retry-After");if(t){const e=Number(t);if(e){yield h(1e3*e);continue}}const n=yield e.text();throw new d("failed to fetch [".concat(e.status,"]: ").concat(n),e)}if(l)return yield e[l]();const o=e.headers.get("Content-Type");return/application\/json/.test(o)?yield e.json():yield e.text()}}))).apply(this,arguments)}}var g=Object.freeze({fsDrive:()=>{},github:function({userAgent:t="db-to-cloud",owner:e,repo:o,getAccessToken:r,fetch:i=("undefined"!=typeof self?self:global).fetch}){const c=y({fetch:i,getAccessToken:r,cooldown:1e3}),a=new Map;return{name:"github",get:p,put:d,post:function(t,e){return d(t,e,!1)},delete:function(t){return g.apply(this,arguments)},list:function(t){return s.apply(this,arguments)},shaCache:a};function l(e){return e.headers||(e.headers={}),e.headers["User-Agent"]||(e.headers["User-Agent"]=t),e.headers.Accept||(e.headers.Accept="application/vnd.github.v3+json"),e.path="https://api.github.com".concat(e.path),c(e)}function s(){return(s=n((function*(t){const n=yield l({path:"/repos/".concat(e,"/").concat(o,"/contents/").concat(t)}),r=[];var i=!0,c=!1,s=void 0;try{for(var u,p=n[Symbol.iterator]();!(i=(u=p.next()).done);i=!0){const t=u.value;r.push(t.name),a.set(t.path,t.sha)}}catch(t){c=!0,s=t}finally{try{i||null==p.return||p.return()}finally{if(c)throw s}}return r}))).apply(this,arguments)}function p(t){return f.apply(this,arguments)}function f(){return(f=n((function*(t){const n=yield l({path:"/repos/".concat(e,"/").concat(o,"/contents/").concat(t)});return a.set(n.path,n.sha),u.decode(n.content)}))).apply(this,arguments)}function d(t,e){return h.apply(this,arguments)}function h(){return(h=n((function*(t,n,r=!0){const i={message:"",content:u.encode(n)};r&&a.has(t)&&(i.sha=a.get(t));const c={method:"PUT",path:"/repos/".concat(e,"/").concat(o,"/contents/").concat(t),contentType:"application/json",body:JSON.stringify(i)};let s,f=!1;for(;!s;){try{s=yield l(c)}catch(e){if(422!==e.code||!e.message.includes('\\"sha\\" wasn\'t supplied'))throw e;if(!r||f)throw e.code="EEXIST",e;yield p(t)}f=!0}a.set(t,s.content.sha)}))).apply(this,arguments)}function g(){return(g=n((function*(t){try{let n=a.get(t);n||(yield p(t),n=a.get(t)),yield l({method:"DELETE",path:"/repos/".concat(e,"/").concat(o,"/contents/").concat(t),body:JSON.stringify({message:"",sha:n})})}catch(t){if(404===t.code)return;throw t}}))).apply(this,arguments)}},dropbox:function({getAccessToken:t,fetch:e=("undefined"!=typeof self?self:global).fetch}){const o=y({fetch:e,getAccessToken:t});return{name:"dropbox",get:function(t){return s.apply(this,arguments)},put:u,post:function(t,e){return f.apply(this,arguments)},delete:function(t){return d.apply(this,arguments)},list:function(t){return a.apply(this,arguments)}};function r(t){let e=t.path,n=t.body,r=c(t,["path","body"]);return o(i({method:"POST",path:"https://api.dropboxapi.com/2/".concat(e),contentType:"application/json",body:JSON.stringify(n)},r))}function a(){return(a=n((function*(t){const e=[];let n=yield r({path:"files/list_folder",body:{path:"/".concat(t)}});var o=!0,i=!1,c=void 0;try{for(var a,l=n.entries[Symbol.iterator]();!(o=(a=l.next()).done);o=!0){const t=a.value;e.push(t.name)}}catch(t){i=!0,c=t}finally{try{o||null==l.return||l.return()}finally{if(i)throw c}}if(!n.has_more)return e;for(;n.has_more;){n=yield r({path:"files/list_folder/continue",body:{cursor:n.cursor}});var s=!0,u=!1,p=void 0;try{for(var f,d=n.entries[Symbol.iterator]();!(s=(f=d.next()).done);s=!0){const t=f.value;e.push(t.name)}}catch(t){u=!0,p=t}finally{try{s||null==d.return||d.return()}finally{if(u)throw p}}}return e}))).apply(this,arguments)}function l(t){const e=new URLSearchParams;return e.set("arg",JSON.stringify(t)),e.toString()}function s(){return(s=n((function*(t){const e={path:"/".concat(t)};try{return yield o({path:"https://content.dropboxapi.com/2/files/download?".concat(l(e)),format:"text"})}catch(t){throw 409===t.code&&t.message.includes("not_found")&&(t.code="ENOENT"),t}}))).apply(this,arguments)}function u(t,e){return p.apply(this,arguments)}function p(){return(p=n((function*(t,e,n="overwrite"){const r={path:"/".concat(t),mode:n,autorename:!1};yield o({path:"https://content.dropboxapi.com/2/files/upload?".concat(l(r)),method:"POST",contentType:"application/octet-stream",body:e})}))).apply(this,arguments)}function f(){return(f=n((function*(t,e){try{return yield u(t,e,"add")}catch(t){throw 409===t.code&&t.message.includes("conflict")&&(t.code="EEXIST"),t}}))).apply(this,arguments)}function d(){return(d=n((function*(t){try{yield r({path:"files/delete_v2",body:{path:"/".concat(t)}})}catch(t){if(409===t.code&&t.message.includes("not_found"))return;throw t}}))).apply(this,arguments)}},onedrive:function({getAccessToken:t,fetch:e=("undefined"!=typeof self?self:global).fetch}){const o=y({fetch:e,getAccessToken:t});return{name:"onedrive",get:function(t){return a.apply(this,arguments)},put:function(t,e){return l.apply(this,arguments)},post:function(t,e){return s.apply(this,arguments)},delete:function(t){return u.apply(this,arguments)},list:function(t){return c.apply(this,arguments)}};function r(t){return i.apply(this,arguments)}function i(){return(i=n((function*(t){return t.path="https://graph.microsoft.com/v1.0/me/drive/special/approot".concat(t.path),yield o(t)}))).apply(this,arguments)}function c(){return(c=n((function*(t){t&&(t=":/".concat(t,":"));let e=yield r({path:"".concat(t,"/children?select=name")}),n=e.value.map(t=>t.name);for(;e["@odata.nextLink"];)e=yield o({path:e["@odata.nextLink"]}),n=n.concat(e.value.map(t=>t.name));return n}))).apply(this,arguments)}function a(){return(a=n((function*(t){return yield r({path:":/".concat(t,":/content"),format:"text"})}))).apply(this,arguments)}function l(){return(l=n((function*(t,e){yield r({method:"PUT",path:":/".concat(t,":/content"),headers:{"Content-Type":"text/plain"},body:e})}))).apply(this,arguments)}function s(){return(s=n((function*(t,e){try{yield r({method:"PUT",path:":/".concat(t,":/content?@microsoft.graph.conflictBehavior=fail"),headers:{"Content-Type":"text/plain"},body:e})}catch(t){throw 409===t.code&&t.message.includes("nameAlreadyExists")&&(t.code="EEXIST"),t}}))).apply(this,arguments)}function u(){return(u=n((function*(t){try{yield r({method:"DELETE",path:":/".concat(t,":")})}catch(t){if(404===t.code)return;throw t}}))).apply(this,arguments)}},google:function({getAccessToken:t,fetch:e=("undefined"!=typeof self?self:global).fetch,FormData:o=("undefined"!=typeof self?self:global).FormData,Blob:r=("undefined"!=typeof self?self:global).Blob}){const i=y({fetch:e,getAccessToken:t}),c=new Map;let a;return{name:"google",get:function(t){return T.apply(this,arguments)},put:function(t,e){return j.apply(this,arguments)},post:k,delete:function(t){return x.apply(this,arguments)},list:function(t){return b.apply(this,arguments)},init:function(){return w.apply(this,arguments)},acquireLock:function(t){return u.apply(this,arguments)},releaseLock:function(){return p.apply(this,arguments)},fileMetaCache:c};function l(t,e){return s.apply(this,arguments)}function s(){return(s=n((function*(t,e){yield i({method:"DELETE",path:"https://www.googleapis.com/drive/v3/files/".concat(t,"/revisions/").concat(e)})}))).apply(this,arguments)}function u(){return(u=n((function*(t){const e=c.get("lock.json"),n=(yield h(e.id,JSON.stringify({expire:Date.now()+60*t*1e3}))).headRevisionId,o=yield i({path:"https://www.googleapis.com/drive/v3/files/".concat(e.id,"/revisions?fields=revisions(id)")});for(let t=1;t<o.revisions.length;t++){const r=o.revisions[t].id;if(r===n)return void(a=n);if(JSON.parse(yield i({path:"https://www.googleapis.com/drive/v3/files/".concat(e.id,"/revisions/").concat(r,"?alt=media")})).expire>Date.now())throw yield l(e.id,n),new d("failed to acquire lock",null,"EEXIST");yield l(e.id,r)}throw new Error("cannot find lock revision")}))).apply(this,arguments)}function p(){return(p=n((function*(){const t=c.get("lock.json");yield l(t.id,a),a=null}))).apply(this,arguments)}function f(){return(f=n((function*(t,e){t="https://www.googleapis.com/drive/v3/files?spaces=appDataFolder&fields=nextPageToken,files(id,name,headRevisionId)"+(t?"&"+t:"");let n=yield i({path:t});for(e(n);n.nextPageToken;)e(n=yield i({path:"".concat(t,"&pageToken=").concat(n.nextPageToken)}))}))).apply(this,arguments)}function h(t,e){return g.apply(this,arguments)}function g(){return(g=n((function*(t,e){return yield i({method:"PATCH",path:"https://www.googleapis.com/upload/drive/v3/files/".concat(t,"?uploadType=media&fields=headRevisionId"),headers:{"Content-Type":"text/plain"},body:e})}))).apply(this,arguments)}function v(t){return m.apply(this,arguments)}function m(){return(m=n((function*(t){t&&(t="q=".concat(encodeURIComponent(t))),yield function(t,e){return f.apply(this,arguments)}(t,t=>{var e=!0,n=!1,o=void 0;try{for(var r,i=t.files[Symbol.iterator]();!(e=(r=i.next()).done);e=!0){const t=r.value;c.set(t.name,t)}}catch(t){n=!0,o=t}finally{try{e||null==i.return||i.return()}finally{if(n)throw o}}})}))).apply(this,arguments)}function w(){return(w=n((function*(){yield v(),c.has("lock.json")||(yield k("lock.json","{}")),c.has("meta.json")||(yield k("meta.json","{}"))}))).apply(this,arguments)}function b(){return(b=n((function*(t){return[...c.values()].filter(e=>e.name.startsWith(t+"/")).map(t=>t.name.split("/")[1])}))).apply(this,arguments)}function T(){return(T=n((function*(t){let e=c.get(t);if(!(e||(yield v("name = '".concat(t,"'")),e=c.get(t))))throw new d("metaCache doesn't contain ".concat(t),null,"ENOENT");try{return yield i({path:"https://www.googleapis.com/drive/v3/files/".concat(e.id,"?alt=media")})}catch(t){throw 404===t.code&&(t.code="ENOENT"),t}}))).apply(this,arguments)}function j(){return(j=n((function*(t,e){if(!c.has(t))return yield k(t,e);const n=c.get(t),o=yield h(n.id,e);n.headRevisionId=o.headRevisionId}))).apply(this,arguments)}function k(t,e){return O.apply(this,arguments)}function O(){return(O=n((function*(t,e){const n=new o,a={name:t,parents:["appDataFolder"]};n.append("metadata",new r([JSON.stringify(a)],{type:"application/json; charset=UTF-8"})),n.append("media",new r([e],{type:"text/plain"}));const l=yield i({method:"POST",path:"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&fields=id,name,headRevisionId",body:n});c.set(l.name,l)}))).apply(this,arguments)}function x(){return(x=n((function*(t){const e=c.get(t);if(e)try{yield i({method:"DELETE",path:"https://www.googleapis.com/drive/v3/files/".concat(e.id)})}catch(t){if(404===t.code)return;throw t}}))).apply(this,arguments)}}});return t.dbToCloud=function({onGet:t,onPut:e,onDelete:o,onFirstSync:r,onWarn:i=console.error,onProgress:c,compareRevision:u,getState:p,setState:f,lockExpire:d=60}){let h,y,g;const v=new Map,m=s(()=>f(h,y)),w=new Map,b=l();return{use:function(t){h=function(t){const e=Object.create(t);return e.get=function(){var e=n((function*(e){return JSON.parse(yield t.get(e))}));return function(t){return e.apply(this,arguments)}}(),e.put=function(){var e=n((function*(e,n){return yield t.put(e,JSON.stringify(n))}));return function(t,n){return e.apply(this,arguments)}}(),e.post=function(){var e=n((function*(e,n){return yield t.post(e,JSON.stringify(n))}));return function(t,n){return e.apply(this,arguments)}}(),e.acquireLock||(e.acquireLock=function(t){return o.apply(this,arguments)},e.releaseLock=function(){return r.apply(this,arguments)}),e.getMeta||(e.getMeta=function(){return i.apply(this,arguments)},e.putMeta=function(t){return c.apply(this,arguments)}),e.peekChanges||(e.peekChanges=function(t){return a.apply(this,arguments)}),e;function o(){return(o=n((function*(t){try{yield this.post("lock.json",{expire:Date.now()+60*t*1e3})}catch(t){if("EEXIST"===t.code){const t=yield this.get("lock.json");Date.now()>t.expire&&(yield this.delete("lock.json"))}throw t}}))).apply(this,arguments)}function r(){return(r=n((function*(){yield this.delete("lock.json")}))).apply(this,arguments)}function i(){return(i=n((function*(){try{return yield this.get("meta.json")}catch(t){if("ENOENT"===t.code||404===t.code)return{};throw t}}))).apply(this,arguments)}function c(){return(c=n((function*(t){yield this.put("meta.json",t)}))).apply(this,arguments)}function a(){return(a=n((function*(t){return(yield this.getMeta()).lastChange!==t.lastChange}))).apply(this,arguments)}}(t)},start:function(){return b.write(n((function*(){if(!y||!y.enabled){if(!h)throw new Error("cloud drive is undefined");h.init&&(yield h.init()),(y=(yield p(h))||{}).enabled=!0,y.queue||(y.queue=[]),null==y.lastChange&&(yield r()),yield O()}})))},stop:function(){return b.write(n((function*(){y&&y.enabled&&(y=g=null,v.clear(),w.clear(),h.uninit&&(yield h.uninit()),yield m())})))},put:function(t,e){if(!y||!y.enabled)return;y.queue.push({_id:t,_rev:e,action:"put"}),m()},delete:function(t,e){if(!y||!y.enabled)return;y.queue.push({_id:t,_rev:e,action:"delete"}),m()},syncNow:function(t){return b.write(n((function*(){if(!y||!y.enabled)throw new Error("Cannot sync now, the sync is not enabled");yield O(t)})))},drive:()=>h,isInit:()=>Boolean(y&&y.enabled)};function T(){return(T=n((function*(){if(!(g=yield h.getMeta()).lastChange||g.lastChange===y.lastChange)return;let t=[];if(y.lastChange){const e=Math.floor((g.lastChange-1)/100);let n=Math.floor(y.lastChange/100);for(;n<=e;){const e=yield h.get("changes/".concat(n,".json"));v.set(n,e),t=t.concat(e),n++}t=t.slice(y.lastChange%100)}else t=(yield h.list("docs")).map(t=>({action:"put",_id:t.slice(0,-5)}));const n=new Map;var r=!0,l=!1,s=void 0;try{for(var u,p=t[Symbol.iterator]();!(r=(u=p.next()).done);r=!0){const t=u.value;n.set(t._id,t)}}catch(t){l=!0,s=t}finally{try{r||null==p.return||p.return()}finally{if(l)throw s}}let f=0;var d=!0,b=!1,T=void 0;try{for(var j,k=n[Symbol.iterator]();!(d=(j=k.next()).done);d=!0){const t=a(j.value,2),r=t[0],l=t[1];let s,u;if(c&&c({phase:"pull",total:n.size,loaded:f,change:l}),"delete"===l.action)yield o(r,l._rev);else if("put"===l.action){try{var O=yield h.get("docs/".concat(r,".json"));s=O.doc,u=O._rev}catch(t){if("ENOENT"===t.code||404===t.code){i("Cannot find ".concat(r,". Is it deleted without updating the history?")),f++;continue}throw t}yield e(s)}const p=l._rev||u;p&&w.set(r,p),f++}}catch(t){b=!0,T=t}finally{try{d||null==k.return||k.return()}finally{if(b)throw T}}y.lastChange=g.lastChange,yield m()}))).apply(this,arguments)}function j(){return(j=n((function*(){if(!y.queue.length)return;const e=y.queue.slice(),n=new Map;var o=!0,r=!1,i=void 0;try{for(var a,l=e[Symbol.iterator]();!(o=(a=l.next()).done);o=!0){const t=a.value;n.set(t._id,t)}}catch(t){r=!0,i=t}finally{try{o||null==l.return||l.return()}finally{if(r)throw i}}const s=[];var p=!0,f=!1,d=void 0;try{for(var b,T=n.values()[Symbol.iterator]();!(p=(b=T.next()).done);p=!0){const t=b.value,e=w.get(t._id);void 0!==e&&u(t._rev,e)<=0||s.push(t)}}catch(t){f=!0,d=t}finally{try{p||null==T.return||T.return()}finally{if(f)throw d}}let j,k,O=0;for(var x=0,E=s;x<E.length;x++){const e=E[x];if(c&&c({phase:"push",loaded:O,total:s.length,change:e}),"delete"===e.action)yield h.delete("docs/".concat(e._id,".json"));else if("put"===e.action){const n=yield t(e._id,e._rev);yield h.put("docs/".concat(e._id,".json"),{doc:n,_rev:e._rev})}w.set(e._id,e._rev),O++}if(g.lastChange){k=Math.floor(g.lastChange/100);const t=g.lastChange%100;j=(j=t?v.get(k)||(yield h.get("changes/".concat(k,".json"))):[]).slice(0,t).concat(s)}else k=0,j=s;for(let t=0;100*t<j.length;t++){const e=j.slice(100*t,100*(t+1));yield h.put("changes/".concat(k+t,".json"),e),v.set(k+t,e)}g.lastChange=(g.lastChange||0)+s.length,yield h.putMeta(g),y.queue=y.queue.slice(e.length),y.lastChange=g.lastChange,yield m()}))).apply(this,arguments)}function k(){return(k=n((function*(){yield h.acquireLock(d);try{yield function(){return T.apply(this,arguments)}(),yield function(){return j.apply(this,arguments)}()}finally{yield h.releaseLock()}}))).apply(this,arguments)}function O(){return x.apply(this,arguments)}function x(){return(x=n((function*(t=!0){c&&c({phase:"start"});try{if(!y.queue.length&&t&&g){if(!(yield h.peekChanges(g)))return}yield function(){return k.apply(this,arguments)}()}finally{c&&c({phase:"end"})}}))).apply(this,arguments)}},t.drive=g,t}({});
|
|
//# sourceMappingURL=db-to-cloud.min.js.map
|