diff --git a/dist/bundle-core.js b/dist/bundle-core.js index b2ae714..fca72ee 100644 --- a/dist/bundle-core.js +++ b/dist/bundle-core.js @@ -11,7 +11,7 @@ exports.init=function(e,o){require("pull-stream");const r=require("events");if(S const push=require("push-stream"),hash=require("ssb-keys/util").hash,validate=require("ssb-validate"),keys=require("ssb-keys"),path=require("path"),Log=require("./log"),FullScanIndexes=require("./indexes/full-scan"),Partial=require("./indexes/partial"),JITDb=require("jitdb"),FeedSyncer=require("./feed-syncer");function getId(e){return"%"+hash(JSON.stringify(e,null,2))}exports.init=function(e,t){const n=Log(e,t),a=JITDb(n,path.join(e,"indexes")),s=FullScanIndexes(n,e),r=s.contacts,i=Partial(e),o=FeedSyncer(i,r);function l(e,t){s.getDataFromKey(e,(e,n)=>{n?t(null,n.value):t(e)})}function u(e,t){var a=getId(e);s.getDataFromKey(a,(s,r)=>{if(r)t(null,r.value);else{if("string"==typeof e.content){const t=keys.unbox(e.content,SSB.net.config.keys.private);if(t){const n=e.content;e.content=t,e.meta={private:"true",original:{content:n}}}}n.add(a,e,t)}})}function d(e,t){s.keyToSeq(e,(e,a)=>e?t(e):null==a?t(new Error("seq is null!")):void n.del(a,t))}const c=null;return{get:l,getSync:function(e,t){if(s.seq.value===n.since.value)l(e,t);else var a=s.seq(()=>{s.seq.value===n.since.value&&(a(),l(e,t))})},add:u,del:d,deleteFeed:function(e,t){SSB.db.jitdb.onReady(()=>{SSB.db.jitdb.query({type:"EQUAL",data:{seek:SSB.db.jitdb.seekAuthor,value:e,indexType:"author"}},(n,a)=>{push(push.values(a),push.asyncMap((e,t)=>{d(e.key,t)}),push.collect(n=>{n||(delete SSB.state.feeds[e],s.removeFeedFromLatest(e)),t(n)}))})})},validateAndAdd:function(e,t){const n=e.author in SSB.state.feeds;try{if(SSB.state=n?validate.append(SSB.state,c,e):validate.appendOOO(SSB.state,c,e),SSB.state.error)return t(SSB.state.error);u(e,t)}catch(e){return t(e)}},validateAndAddOOO:function(e,t){try{if(validate.initial(),validate.appendOOO(SSB.state,c,e),SSB.state.error)return t(SSB.state.error);u(e,t)}catch(e){return t(e)}},getStatus:function(){const e=i.getSync(),t=r.getGraphForFeedSync(SSB.net.id);let a=0,o=0,l=0,u=0,d=0,c=0;return t.following.forEach(t=>{e[t]&&e[t].full&&(d+=1),c+=1}),t.extended.forEach(t=>{e[t]&&e[t].syncedProfile&&(a+=1),e[t]&&e[t].syncedContacts&&(o+=1),e[t]&&e[t].syncedMessages&&(l+=1),u+=1}),{log:n.since.value,indexes:s.seq.value,partial:{totalPartial:u,profilesSynced:a,contactsSynced:o,messagesSynced:l,totalFull:c,fullSynced:d}}},getAllLatest:s.getAllLatest,getDataFromAuthorSequence:s.getDataFromAuthorSequence,contacts:r,profiles:s.profiles,getMessagesByRoot:s.getMessagesByRoot,getMessagesByMention:s.getMessagesByMention,getMessagesByVoteLink:s.getMessagesByVoteLink,jitdb:a,onDrain:n.onDrain,getLatest:s.getLatest,clearIndexes:function(){s.remove(()=>{})},partial:i,feedSyncer:o}}; },{"./feed-syncer":5,"./indexes/full-scan":6,"./indexes/partial":7,"./log":8,"jitdb":205,"path":265,"push-stream":399,"ssb-keys":503,"ssb-keys/util":511,"ssb-validate":518}],5:[function(require,module,exports){ -module.exports=function(e,t){const n=require("pull-stream"),a=require("pull-paramap");function l(t,a,l,s,i){s[t]&&s[t][a]?i(null,t):n(l(),n.asyncMap(SSB.db.validateAndAddOOO),n.collect((n,l)=>{if(n)return console.error(n.message),i(n);SSB.state.queue=[];var s={};s[a]=!0,e.updateState(t,s,e=>{i(e,t)})}))}var s=!1;return{syncFeeds:function i(o,c){s=!0,console.log("syncing feeds"),e.get((d,r)=>{t.getGraphForFeed(SSB.net.id,(d,p)=>{console.time("full feeds"),n(n.values(p.following),n.asyncMap((t,a)=>{r[t]&&r[t].full?a():n(o.partialReplication.getFeed({id:t,seq:0,keys:!1}),n.asyncMap(SSB.db.validateAndAdd),n.collect(n=>{if(n)throw n;SSB.state.queue=[],e.updateState(t,{full:!0},a)}))}),n.collect(()=>{console.timeEnd("full feeds"),console.time("partial feeds"),t.getGraphForFeed(SSB.net.id,(e,d)=>{n(n.values(d.extended),a((e,t)=>{l(e,"syncedMessages",()=>o.partialReplication.getFeedReverse({id:e,keys:!1,limit:25}),r,t)},5),a((e,t)=>{l(e,"syncedProfile",()=>o.partialReplication.getMessagesOfType({id:e,type:"about"}),r,t)},5),a((e,t)=>{l(e,"syncedContacts",()=>o.partialReplication.getMessagesOfType({id:e,type:"contact"}),r,t)},5),n.collect(()=>{console.timeEnd("partial feeds"),t.getGraphForFeed(SSB.net.id,(e,t)=>{JSON.stringify(d)===JSON.stringify(t)?(s=!1,c&&c(o)):i(o,c)})}))})}))})})},syncing:s,inSync:function(){const n=e.getSync(),a=t.getGraphForFeedSync(SSB.net.id);let l=0,s=0,i=0,o=0,c=0,d=0;return a.following.forEach(e=>{n[e]&&n[e].full&&(c+=1),d+=1}),a.extended.forEach(e=>{n[e]&&n[e].syncedProfile&&(s+=1),n[e]&&n[e].syncedContacts&&(i+=1),n[e]&&n[e].syncedMessages&&(o+=1),l+=1}),(0!==l||0!==d)&&(l==o&&l==i&&l==s&&d==c)}}}; +module.exports=function(e,t){const n=require("pull-stream"),a=require("pull-paramap");function s(t,a,s,l,i){l[t]&&l[t][a]?i(null,t):n(s(),n.asyncMap(SSB.db.validateAndAddOOO),n.collect((n,s)=>{if(n)return console.error(n.message),i(n);SSB.state.queue=[];var l={};l[a]=!0,e.updateState(t,l,e=>{i(e,t)})}))}var l=!1;return{syncFeeds:function i(d,o){l=!0,console.log("syncing feeds"),e.get((c,r)=>{t.getGraphForFeed(SSB.net.id,(c,p)=>{console.time("full feeds"),n(n.values(p.following),n.asyncMap((t,a)=>{r[t]&&r[t].full?a():(delete SSB.state.feeds[t],n(d.partialReplication.getFeed({id:t,seq:0,keys:!1}),n.asyncMap(SSB.db.validateAndAdd),n.collect(n=>{if(n)throw n;SSB.state.queue=[],e.updateState(t,{full:!0},a)})))}),n.collect(()=>{console.timeEnd("full feeds"),console.time("partial feeds"),t.getGraphForFeed(SSB.net.id,(e,c)=>{n(n.values(c.extended),a((e,t)=>{s(e,"syncedMessages",()=>d.partialReplication.getFeedReverse({id:e,keys:!1,limit:25}),r,t)},5),a((e,t)=>{s(e,"syncedProfile",()=>d.partialReplication.getMessagesOfType({id:e,type:"about"}),r,t)},5),a((e,t)=>{s(e,"syncedContacts",()=>d.partialReplication.getMessagesOfType({id:e,type:"contact"}),r,t)},5),n.collect(()=>{console.timeEnd("partial feeds"),t.getGraphForFeed(SSB.net.id,(e,t)=>{JSON.stringify(c)===JSON.stringify(t)?(l=!1,o&&o(d)):i(d,o)})}))})}))})})},syncing:l,inSync:function(){const n=e.getSync(),a=t.getGraphForFeedSync(SSB.net.id);let s=0,l=0,i=0,d=0,o=0,c=0;return a.following.forEach(e=>{n[e]&&n[e].full&&(o+=1),c+=1}),a.extended.forEach(e=>{n[e]&&n[e].syncedProfile&&(l+=1),n[e]&&n[e].syncedContacts&&(i+=1),n[e]&&n[e].syncedMessages&&(d+=1),s+=1}),(0!==s||0!==c)&&(s==d&&s==i&&s==l&&c==o)}}}; },{"pull-paramap":346,"pull-stream":353}],6:[function(require,module,exports){ (function (Buffer){ @@ -2731,7 +2731,7 @@ var pull=require("pull-stream"),GQ=require("gossip-query"),hash=require("ssb-key const pull=require("pull-stream"),pullCont=require("pull-cont");var Obv=require("obv");const{originalData:originalData}=require("./msg-utils");exports.manifest={createHistoryStream:"source"},exports.permissions={anonymous:{allow:["createHistoryStream"],deny:null}},exports.init=function(e,t){return e.createHistoryStream=function(e){const t=e.sequence||e.seq||0,l=e.limit||1e10,u=!1!==e.keys,n=!1!==e.values,r={type:"EQUAL",data:{seek:SSB.db.jitdb.seekAuthor,value:e.id,indexType:"author",indexAll:!0}};function a(e){let t=originalData(e);return!u&&n?t.value:u&&!n?t.key:t}return pull(pullCont(function(u){const n=SSB.db.partial.getSync();t&&n[e.id]&&!0===n[e.id].full?SSB.db.jitdb.query(r,t-1,l,!0,(e,t)=>{u(e,pull.values(t.map(e=>a(e))))}):t?SSB.db.jitdb.query(r,(e,n)=>{if(e)return u(e);pull(pull.values(n),pull.filter(e=>e.value.sequence>=t),pull.take(l),pull.collect((e,t)=>{u(null,pull.values(t.map(e=>a(e))))}))}):SSB.db.jitdb.query(r,(e,t)=>{u(e,pull.values(t.map(e=>a(e))))})}))},e.post=Obv(),e.add=function(e,t){SSB.db.validateAndAdd(e,t)},e.getAtSequence=function(e,t){SSB.db.getDataFromAuthorSequence("string"==typeof e?e.split(":"):e,function(e,l){e?t(e):t(null,originalData(l))})},{}}; },{"./msg-utils":9,"obv":252,"pull-cont":298,"pull-stream":353}],583:[function(require,module,exports){ -const pull=require("pull-stream"),pullCont=require("pull-cont"),sort=require("ssb-sort"),{originalValue:originalValue,originalData:originalData}=require("./msg-utils");exports.manifest={getFeed:"source",getFeedReverse:"source",getTangle:"async",getMessagesOfType:"source"},exports.permissions={anonymous:{allow:Object.keys(exports.manifest)}},exports.name="partial-replication",exports.init=function(e,t){return{getFeed:function(t){return pull(e.createHistoryStream(t))},getFeedReverse:function(t){return pull(pullCont(function(r){SSB.db.getLatest(t.id,(a,i)=>{if(a)throw a;var u=i?i.sequence-(t.limit-1):0;u<0&&(u=0),t.seq=u,r(null,e.createHistoryStream(t))})}))},getTangle:function(e,t){if(!e)return t("msg not found:"+e);SSB.db.get(e,(r,a)=>r?t(r):a.meta&&"true"===a.meta.private?t(null,[]):void SSB.db.getMessagesByRoot(e,(e,r)=>{if(e)return t(e);r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private),t(null,[originalValue(a),...sort(r).map(e=>originalValue(e.value))])}))},getMessagesOfType:function(e){if(!e.id)throw new Error("id is required!");if(!e.type)throw new Error("type is required!");const t=e.sequence||e.seq||0,r=e.limit||1e10,a={type:"AND",data:[{type:"EQUAL",data:{seek:SSB.db.jitdb.seekAuthor,value:e.id,indexType:"author",indexAll:!0}},{type:"EQUAL",data:{seek:SSB.db.jitdb.seekType,value:e.type,indexType:"type"}}]};return pull(pullCont(function(e){t?SSB.db.jitdb.query(a,t-1,r,!0,(t,r)=>{r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private).map(e=>e.value),e(t,pull.values(r))}):SSB.db.jitdb.query(a,(t,r)=>{r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private).map(e=>e.value),e(t,pull.values(r))})}))}}}; +const pull=require("pull-stream"),pullCont=require("pull-cont"),sort=require("ssb-sort"),{originalValue:originalValue,originalData:originalData}=require("./msg-utils");exports.manifest={getFeed:"source",getFeedReverse:"source",getTangle:"async",getMessagesOfType:"source"},exports.permissions={anonymous:{allow:Object.keys(exports.manifest)}},exports.name="partial-replication",exports.init=function(e,t){return{getFeed:function(t){return pull(e.createHistoryStream(t))},getFeedReverse:function(t){return pull(pullCont(function(r){SSB.db.getLatest(t.id,(a,l)=>{if(a)return console.error("Got error on feed reverse",a),r(null,pull.empty());var u=l?l.sequence-(t.limit-1):0;u<0&&(u=0),t.seq=u,r(null,e.createHistoryStream(t))})}))},getTangle:function(e,t){if(!e)return t("msg not found:"+e);SSB.db.get(e,(r,a)=>r?t(r):a.meta&&"true"===a.meta.private?t(null,[]):void SSB.db.getMessagesByRoot(e,(e,r)=>{if(e)return t(e);r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private),t(null,[originalValue(a),...sort(r).map(e=>originalValue(e.value))])}))},getMessagesOfType:function(e){if(!e.id)throw new Error("id is required!");if(!e.type)throw new Error("type is required!");const t=e.sequence||e.seq||0,r=e.limit||1e10,a={type:"AND",data:[{type:"EQUAL",data:{seek:SSB.db.jitdb.seekAuthor,value:e.id,indexType:"author",indexAll:!0}},{type:"EQUAL",data:{seek:SSB.db.jitdb.seekType,value:e.type,indexType:"type"}}]};return pull(pullCont(function(e){t?SSB.db.jitdb.query(a,t-1,r,!0,(t,r)=>{r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private).map(e=>e.value),e(t,pull.values(r))}):SSB.db.jitdb.query(a,(t,r)=>{r=r.filter(e=>!e.value.meta||"true"!==e.value.meta.private).map(e=>e.value),e(t,pull.values(r))})}))}}}; },{"./msg-utils":9,"pull-cont":298,"pull-stream":353,"ssb-sort":517}],584:[function(require,module,exports){ module.exports=function(n,u){var e,l,i=[],t=!1;function c(){if(!t)return;const c=i.length;if(!(c>0&&t&&null!=u)||u.value===n.since.value){for(var o=0;o{!t||null!=u&&u.value!==n.since.value?i.push(c):c(e,l)})}}}; diff --git a/package.json b/package.json index cc3501a..7a15e7c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ssb-browser-core", "description": "", - "version": "5.1.0", + "version": "5.1.1", "homepage": "https://github.com/arj03/ssb-browser-core", "repository": { "type": "git",