@graffiti-garden/wrapper-vue 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"composables.d.ts","sourceRoot":"","sources":["../../src/composables.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AACjD,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,UAAU,EAEX,MAAM,sBAAsB,CAAC;AA8G9B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,UAAU,EAC3D,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EAAE,CAAC,EACpC,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC;AAChC;;;;GAIG;AACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC,EAC9D,QAAQ,GAAE,gBAAgB,CAAC,OAAO,CAAS,GAC1C;IACD,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAChC,CA6CA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,UAAU,EACtD,aAAa,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAC3D,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC;AAChC;;;;GAIG;AACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC,EAC9D,QAAQ,GAAE,gBAAgB,CAAC,OAAO,CAAS,GAC1C;IACD,MAAM,EAAE,GAAG,CAAC,cAAc,CAAC,MAAM,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CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAChC,CA6CA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,UAAU,EACtD,aAAa,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,MAAM,CAAC,EAC3D,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC;AAChC;;;;GAIG;AACH,OAAO,CAAC,EAAE,gBAAgB,CAAC,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC,EAC9D,QAAQ,GAAE,gBAAgB,CAAC,OAAO,CAAS,GAC1C;IACD,MAAM,EAAE,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACvD,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAChC,CAkDA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,SAAS,UAAU,EACjE,MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAChC,OAAO,EAAE,gBAAgB,CAAC,eAAe,CAAC,EAC1C,QAAQ,GAAE,gBAAgB,CAAC,OAAO,CAAS,GAC1C;IACD,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACvC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,gBAAgB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CAChC,CA4CA"}
@@ -1,2 +1,2 @@
1
- "use strict";var $=Object.defineProperty;var I=(e,t,o)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var p=(e,t,o)=>I(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),M=require("@graffiti-garden/wrapper-synchronize"),G={};function v(){const e=G.graffitiSynchronize;if(!e)throw new Error("No Graffiti instance provided, did you forget to install the plugin?");return e}function N(){return v()}function w(){const e=G.graffitiSession;if(!e)throw new Error("No Graffiti session provided, did you forget to install the plugin?");return e}var B=class S extends Error{constructor(t){super(t),this.name="GraffitiErrorNotFound",Object.setPrototypeOf(this,S.prototype)}};class C{constructor(t){p(this,"poll",async t=>{let o;const s=this.getter;try{o=await s()}catch{this.getter===s&&t(null);return}this.getter===s&&t({object:o})});this.getter=t}clear(){}}class P{constructor(t){p(this,"iterator");p(this,"continue");p(this,"poll",async t=>{if(!this.iterator)if(this.continue)try{this.iterator=this.continue()}catch(o){if(o instanceof B)t("clear"),this.iterator=this.streamFactory();else throw o}else this.iterator=this.streamFactory();for(;this.iterator;){const o=this.iterator,s=await o.next();if(o===this.iterator){if(s.done){s.value&&(this.iterator=void 0,this.continue=s.value.continue);break}if(s.value.error){console.error(s.value.error);continue}t(s.value)}}});this.streamFactory=t}clear(){if(this.iterator){const t=this.iterator;this.iterator.return({continue:()=>t,cursor:""})}this.iterator=void 0,this.continue=void 0}}function j(e,t){return!t||e.object.lastModified>t.object.lastModified||e.object.lastModified===t.object.lastModified&&!e.tombstone&&!!t.tombstone}class L{constructor(){p(this,"entry",r.ref())}get result(){return r.computed(()=>{const t=this.entry.value;return t&&(t.tombstone?null:t.object)})}clear(){this.entry.value=void 0}onEntry(t){if(t==="clear"){this.clear();return}(!t||j(t,this.entry.value))&&(this.entry.value=t)}}class E{constructor(t){p(this,"results",r.ref([]));p(this,"resultsRaw",new Map);p(this,"batchFlattenTimer");this.graffiti=t}clear(){this.resultsRaw.clear(),this.results.value=[],clearTimeout(this.batchFlattenTimer),this.batchFlattenTimer=void 0}flattenResults(){this.results.value=Array.from(this.resultsRaw.values()).reduce((t,o)=>(o.tombstone||t.push(o.object),t),[])}onEntry(t){if(!t)return;if(t==="clear"){this.clear();return}const o=this.resultsRaw.get(t.object.url);j(t,o)&&(this.resultsRaw.set(t.object.url,t),this.batchFlattenTimer||(this.batchFlattenTimer=setTimeout(()=>{this.flattenResults(),this.batchFlattenTimer=void 0},0)))}}function R(e,t,o,s,a){let n;async function i(){n=o();for await(const f of n){if(f.error){console.error(f.error);continue}e.onEntry(f)}}let u=!1,c;const l=async()=>{if(u||!c)return;const f=c;u=!0;try{await f()}finally{if(f!==c)return;u=!1,r.toValue(a)&&l()}},h=r.ref(!1);return r.watch(s,async(f,g)=>{if(JSON.stringify(f)===JSON.stringify(g))return;n==null||n.return(null),e.clear(),t.clear(),i(),c=()=>t.poll(e.onEntry.bind(e));const m=c;u=!1,h.value=!0;try{await l()}finally{if(m!==c)return;h.value=!1}},{immediate:!0}),r.onScopeDispose(()=>{n==null||n.return(null),e.clear(),t.clear(),c=void 0}),{poll:l,isInitialPolling:h}}function F(e,t){return()=>{const o=r.toValue(t);return o===void 0?e==null?void 0:e.value:o}}function d(e){return e.map(t=>t())}function O(e,t,o,s=!1){const a=v(),n=w(),i=()=>r.toValue(e),u=()=>r.toValue(t),c=F(n,o),l=[i,u,c],h=()=>a.synchronizeDiscover(...d(l)),f=()=>a.discover(...d(l)),g=new E(a),m=new P(f),{poll:y,isInitialPolling:b}=R(g,m,h,l,s);return{objects:g.results,poll:y,isInitialPolling:b}}function _(e,t,o,s=!1){const a=v(),n=w(),i=()=>r.toValue(e),u=()=>r.toValue(t),c=F(n,o),l=[i,u,c],h=()=>a.synchronizeGet(...d(l)),f=new L,g=()=>a.get(...d(l)),m=new C(g),{poll:y,isInitialPolling:b}=R(f,m,h,l,s);return{object:f.result,poll:y,isInitialPolling:b}}function z(e,t,o=!1){const s=v(),i=[()=>r.toValue(e),()=>r.toValue(t)],u=()=>s.synchronizeRecoverOrphans(...d(i)),c=new E(s),l=()=>s.recoverOrphans(...d(i)),h=new P(l),{poll:f,isInitialPolling:g}=R(c,h,u,i,o);return{objects:c.results,poll:f,isInitialPolling:g}}const T=r.defineComponent({__name:"Discover",props:{channels:{},schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{objects:o,poll:s,isInitialPolling:a}=O(r.toRef(t,"channels"),r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,i)=>r.renderSlot(n.$slots,"default",{objects:r.unref(o),poll:r.unref(s),isInitialPolling:r.unref(a)})}}),V=r.defineComponent({__name:"Get",props:{url:{},schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{object:o,poll:s,isInitialPolling:a}=_(r.toRef(t,"url"),r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,i)=>r.renderSlot(n.$slots,"default",{object:r.unref(o),poll:r.unref(s),isInitialPolling:r.unref(a)})}}),D=r.defineComponent({__name:"RecoverOrphans",props:{schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{objects:o,poll:s,isInitialPolling:a}=z(r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,i)=>r.renderSlot(n.$slots,"default",{objects:r.unref(o),poll:r.unref(s),isInitialPolling:r.unref(a)})}}),k={install(e,t){const o=t.graffiti,s=new M.GraffitiSynchronize(o),a=r.ref(void 0);s.sessionEvents.addEventListener("initialized",async n=>{const i=n.detail;if(i&&i.error&&console.error(i.error),i&&i.href){const u=e.config.globalProperties.$router;if(u){const c=u.options.history.base,l=new URL(i.href);l.pathname.startsWith(c)&&(l.pathname=l.pathname.slice(c.length)),await u.replace(l.pathname+l.search+l.hash)}}a.value||(a.value=null)}),s.sessionEvents.addEventListener("login",n=>{const i=n.detail;if(i.error){console.error("Error logging in:"),console.error(i.error);return}else a.value=i.session}),s.sessionEvents.addEventListener("logout",n=>{const i=n.detail;i.error?(console.error("Error logging out:"),console.error(i.error)):a.value=null}),G.graffitiSynchronize=s,G.graffitiSession=a,e.component("GraffitiDiscover",T),e.component("GraffitiGet",V),e.component("GraffitiRecoverOrphans",D),e.config.globalProperties.$graffiti=s,e.config.globalProperties.$graffitiSession=a}},A=T,q=V,J=D;exports.GraffitiDiscover=A;exports.GraffitiGet=q;exports.GraffitiPlugin=k;exports.GraffitiRecoverOrphans=J;exports.useGraffiti=N;exports.useGraffitiDiscover=O;exports.useGraffitiGet=_;exports.useGraffitiRecoverOrphans=z;exports.useGraffitiSession=w;exports.useGraffitiSynchronize=v;
1
+ "use strict";var $=Object.defineProperty;var I=(e,t,o)=>t in e?$(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;var g=(e,t,o)=>I(e,typeof t!="symbol"?t+"":t,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),M=require("@graffiti-garden/wrapper-synchronize"),G={};function v(){const e=G.graffitiSynchronize;if(!e)throw new Error("No Graffiti instance provided, did you forget to install the plugin?");return e}function N(){return v()}function w(){const e=G.graffitiSession;if(!e)throw new Error("No Graffiti session provided, did you forget to install the plugin?");return e}var B=class P extends Error{constructor(t){super(t),this.name="GraffitiErrorNotFound",Object.setPrototypeOf(this,P.prototype)}};class C{constructor(t){g(this,"poll",async t=>{let o;const i=this.getter;try{o=await i()}catch{this.getter===i&&t(null);return}this.getter===i&&t({object:o})});this.getter=t}clear(){}}class S{constructor(t){g(this,"iterator");g(this,"continue");g(this,"poll",async t=>{if(!this.iterator)if(this.continue)try{this.iterator=this.continue()}catch(o){if(o instanceof B)t("clear"),this.iterator=this.streamFactory();else throw o}else this.iterator=this.streamFactory();for(;this.iterator;){const o=this.iterator,i=await o.next();if(o===this.iterator){if(i.done){this.iterator=void 0,i.value&&(this.continue=i.value.continue);break}if(i.value.error){console.error(i.value.error);continue}t(i.value)}}});this.streamFactory=t}clear(){if(this.iterator){const t=this.iterator;this.iterator.return({continue:()=>t,cursor:""})}this.iterator=void 0,this.continue=void 0}}function j(e,t){return!t||e.object.lastModified>t.object.lastModified||e.object.lastModified===t.object.lastModified&&!e.tombstone&&!!t.tombstone}class L{constructor(){g(this,"entry",r.ref())}get result(){return r.computed(()=>{const t=this.entry.value;return t&&(t.tombstone?null:t.object)})}clear(){this.entry.value=void 0}onEntry(t){if(t==="clear"){this.clear();return}(!t||j(t,this.entry.value))&&(this.entry.value=t)}}class E{constructor(t){g(this,"results",r.ref([]));g(this,"resultsRaw",new Map);g(this,"batchFlattenTimer");this.graffiti=t}clear(){this.resultsRaw.clear(),this.results.value=[],clearTimeout(this.batchFlattenTimer),this.batchFlattenTimer=void 0}flattenResults(){this.results.value=Array.from(this.resultsRaw.values()).reduce((t,o)=>(o.tombstone||t.push(o.object),t),[])}onEntry(t){if(!t)return;if(t==="clear"){this.clear();return}const o=this.resultsRaw.get(t.object.url);j(t,o)&&(this.resultsRaw.set(t.object.url,t),this.batchFlattenTimer||(this.batchFlattenTimer=setTimeout(()=>{this.flattenResults(),this.batchFlattenTimer=void 0},0)))}}function R(e,t,o,i,a){let n;async function s(){n=o();for await(const f of n){if(f.error){console.error(f.error);continue}e.onEntry(f)}}let u=!1,c;const l=async()=>{if(u||!c)return;const f=c;u=!0;try{await f()}catch{await new Promise(m=>setTimeout(m,2e3))}finally{if(f!==c)return;u=!1,r.toValue(a)&&l()}},h=r.ref(!1);return r.watch(i,async(f,p)=>{if(JSON.stringify(f)===JSON.stringify(p))return;n==null||n.return(null),e.clear(),t.clear(),s(),c=()=>t.poll(e.onEntry.bind(e));const m=c;u=!1,h.value=!0;try{await l()}finally{if(m!==c)return;h.value=!1}},{immediate:!0}),r.onScopeDispose(()=>{n==null||n.return(null),e.clear(),t.clear(),c=void 0}),{poll:l,isInitialPolling:h}}function F(e,t){return()=>{const o=r.toValue(t);return o===void 0?e==null?void 0:e.value:o}}function d(e){return e.map(t=>t())}function O(e,t,o,i=!1){const a=v(),n=w(),s=()=>r.toValue(e),u=()=>r.toValue(t),c=F(n,o),l=[s,u,c],h=()=>a.synchronizeDiscover(...d(l)),f=()=>a.discover(...d(l)),p=new E(a),m=new S(f),{poll:y,isInitialPolling:b}=R(p,m,h,l,i);return{objects:p.results,poll:y,isInitialPolling:b}}function _(e,t,o,i=!1){const a=v(),n=w(),s=()=>r.toValue(e),u=()=>r.toValue(t),c=F(n,o),l=[s,u,c],h=()=>a.synchronizeGet(...d(l)),f=new L,p=()=>a.get(...d(l)),m=new C(p),{poll:y,isInitialPolling:b}=R(f,m,h,l,i);return{object:f.result,poll:y,isInitialPolling:b}}function z(e,t,o=!1){const i=v(),s=[()=>r.toValue(e),()=>r.toValue(t)],u=()=>i.synchronizeRecoverOrphans(...d(s)),c=new E(i),l=()=>i.recoverOrphans(...d(s)),h=new S(l),{poll:f,isInitialPolling:p}=R(c,h,u,s,o);return{objects:c.results,poll:f,isInitialPolling:p}}const T=r.defineComponent({__name:"Discover",props:{channels:{},schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{objects:o,poll:i,isInitialPolling:a}=O(r.toRef(t,"channels"),r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,s)=>r.renderSlot(n.$slots,"default",{objects:r.unref(o),poll:r.unref(i),isInitialPolling:r.unref(a)})}}),V=r.defineComponent({__name:"Get",props:{url:{},schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{object:o,poll:i,isInitialPolling:a}=_(r.toRef(t,"url"),r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,s)=>r.renderSlot(n.$slots,"default",{object:r.unref(o),poll:r.unref(i),isInitialPolling:r.unref(a)})}}),D=r.defineComponent({__name:"RecoverOrphans",props:{schema:{},session:{},autopoll:{type:Boolean}},setup(e){const t=e,{objects:o,poll:i,isInitialPolling:a}=z(r.toRef(t,"schema"),r.toRef(t,"session"),r.toRef(t,"autopoll"));return(n,s)=>r.renderSlot(n.$slots,"default",{objects:r.unref(o),poll:r.unref(i),isInitialPolling:r.unref(a)})}}),k={install(e,t){const o=t.graffiti,i=new M.GraffitiSynchronize(o),a=r.ref(void 0);i.sessionEvents.addEventListener("initialized",async n=>{const s=n.detail;if(s&&s.error&&console.error(s.error),s&&s.href){const u=e.config.globalProperties.$router;if(u){const c=u.options.history.base,l=new URL(s.href);l.pathname.startsWith(c)&&(l.pathname=l.pathname.slice(c.length)),await u.replace(l.pathname+l.search+l.hash)}}a.value||(a.value=null)}),i.sessionEvents.addEventListener("login",n=>{const s=n.detail;if(s.error){console.error("Error logging in:"),console.error(s.error);return}else a.value=s.session}),i.sessionEvents.addEventListener("logout",n=>{const s=n.detail;s.error?(console.error("Error logging out:"),console.error(s.error)):a.value=null}),G.graffitiSynchronize=i,G.graffitiSession=a,e.component("GraffitiDiscover",T),e.component("GraffitiGet",V),e.component("GraffitiRecoverOrphans",D),e.config.globalProperties.$graffiti=i,e.config.globalProperties.$graffitiSession=a}},A=T,q=V,J=D;exports.GraffitiDiscover=A;exports.GraffitiGet=q;exports.GraffitiPlugin=k;exports.GraffitiRecoverOrphans=J;exports.useGraffiti=N;exports.useGraffitiDiscover=O;exports.useGraffitiGet=_;exports.useGraffitiRecoverOrphans=z;exports.useGraffitiSession=w;exports.useGraffitiSynchronize=v;
2
2
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../src/globals.ts","../../node_modules/@graffiti-garden/api/dist/index.mjs","../../src/pollers.ts","../../src/reducers.ts","../../src/composables.ts","../../src/Discover.vue","../../src/Get.vue","../../src/RecoverOrphans.vue","../../src/plugin.ts"],"sourcesContent":["import type { Ref } from \"vue\";\nimport type { Graffiti, GraffitiSession } from \"@graffiti-garden/api\";\nimport type { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\nexport const globals: {\n graffitiSynchronize?: GraffitiSynchronize;\n graffitiSession?: Ref<GraffitiSession | undefined | null>;\n} = {};\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * that has been wrapped by the {@link GraffitiPlugin} with the [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSynchronize() {\n const graffiti = globals.graffitiSynchronize;\n if (!graffiti) {\n throw new Error(\n \"No Graffiti instance provided, did you forget to install the plugin?\",\n );\n }\n return graffiti;\n}\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffiti | $graffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n *\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffiti(): Graffiti {\n return useGraffitiSynchronize();\n}\n\n/**\n * Returns a global reactive [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffitiSession | $graffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSession() {\n const session = globals.graffitiSession;\n if (!session) {\n throw new Error(\n \"No Graffiti session provided, did you forget to install the plugin?\",\n );\n }\n return session;\n}\n","var r=class{};var p={type:\"object\",properties:{value:{type:\"object\"},channels:{type:\"array\",items:{type:\"string\"}},allowed:{type:\"array\",items:{type:\"string\"},nullable:!0},url:{type:\"string\"},actor:{type:\"string\"},lastModified:{type:\"number\"}},additionalProperties:!1,required:[\"value\",\"channels\",\"actor\",\"url\",\"lastModified\"]},O={...p,required:[\"value\",\"channels\"]};var a=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorUnauthorized\",Object.setPrototypeOf(this,t.prototype)}},i=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorForbidden\",Object.setPrototypeOf(this,t.prototype)}},s=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorNotFound\",Object.setPrototypeOf(this,t.prototype)}},o=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorInvalidSchema\",Object.setPrototypeOf(this,t.prototype)}},n=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorSchemaMismatch\",Object.setPrototypeOf(this,t.prototype)}},c=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorPatchTestFailed\",Object.setPrototypeOf(this,t.prototype)}},f=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorPatchError\",Object.setPrototypeOf(this,t.prototype)}},m=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorInvalidUrl\",Object.setPrototypeOf(this,t.prototype)}},S=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorUnrecognizedUriScheme\",Object.setPrototypeOf(this,t.prototype)}};export{r as Graffiti,i as GraffitiErrorForbidden,o as GraffitiErrorInvalidSchema,m as GraffitiErrorInvalidUrl,s as GraffitiErrorNotFound,f as GraffitiErrorPatchError,c as GraffitiErrorPatchTestFailed,n as GraffitiErrorSchemaMismatch,a as GraffitiErrorUnauthorized,S as GraffitiErrorUnrecognizedUrlScheme,p as GraffitiObjectJSONSchema,O as GraffitiPutObjectJSONSchema};\n//# sourceMappingURL=index.mjs.map\n","import {\n type Graffiti,\n type JSONSchema,\n type GraffitiObject,\n type GraffitiObjectStreamReturn,\n type GraffitiObjectStreamContinueEntry,\n type GraffitiObjectStream,\n type GraffitiObjectStreamContinue,\n GraffitiErrorNotFound,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Poller<Schema extends JSONSchema> {\n abstract poll(\n onEntry: (\n entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\",\n ) => void,\n ): Promise<void>;\n abstract clear(): void;\n}\n\n/**\n * Polls for a single object and calls onValue with the result.\n */\nexport class GetPoller<Schema extends JSONSchema> implements Poller<Schema> {\n constructor(readonly getter: () => Promise<GraffitiObject<Schema>>) {}\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n let object: GraffitiObject<Schema>;\n const myGetter = this.getter;\n try {\n object = await myGetter();\n } catch (e) {\n if (this.getter === myGetter) {\n onEntry(null);\n }\n return;\n }\n if (this.getter === myGetter) {\n onEntry({ object });\n }\n };\n\n clear() {}\n}\n\n/**\n * Polls for multiple objects and calls `onObject` with the result.\n * If `poll` is called multiple times, it doesn't poll the results\n * entirely from scratch, but instead only polls the new results.\n */\nexport class StreamPoller<Schema extends JSONSchema> implements Poller<Schema> {\n iterator: GraffitiObjectStreamContinue<Schema> | undefined;\n continue: (() => GraffitiObjectStreamContinue<Schema>) | undefined;\n\n constructor(readonly streamFactory: () => GraffitiObjectStream<Schema>) {}\n\n clear() {\n if (this.iterator) {\n const iterator = this.iterator;\n this.iterator.return({\n continue: () => iterator,\n cursor: \"\",\n });\n }\n this.iterator = undefined;\n this.continue = undefined;\n }\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n if (!this.iterator) {\n if (this.continue) {\n try {\n this.iterator = this.continue();\n } catch (e) {\n // The cursor has expired, we need to start from scratch.\n if (e instanceof GraffitiErrorNotFound) {\n onEntry(\"clear\");\n this.iterator = this.streamFactory();\n } else {\n throw e;\n }\n }\n } else {\n this.iterator = this.streamFactory();\n }\n }\n\n while (true) {\n // Check if the iterator has been cancelled.\n if (!this.iterator) {\n break;\n }\n\n const myIterator: GraffitiObjectStreamContinue<Schema> = this.iterator;\n\n const result = await myIterator.next();\n\n // Check again if it was cancelled.\n if (myIterator !== this.iterator) {\n continue;\n }\n\n if (result.done) {\n if (result.value) {\n this.iterator = undefined;\n this.continue = result.value.continue;\n }\n break;\n }\n\n if (result.value.error) {\n console.error(result.value.error);\n continue;\n }\n\n onEntry(result.value);\n }\n };\n}\n","import { computed, ref } from \"vue\";\nimport type { Ref } from \"vue\";\nimport type {\n GraffitiObject,\n Graffiti,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Reducer<Schema extends JSONSchema> {\n abstract clear(): void;\n abstract onEntry(\n entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\",\n ): void;\n}\n\nfunction isEntryNewer<Schema extends JSONSchema>(\n entry: GraffitiObjectStreamContinueEntry<Schema>,\n existing: GraffitiObjectStreamContinueEntry<Schema> | null | undefined,\n): boolean {\n return (\n !existing ||\n entry.object.lastModified > existing.object.lastModified ||\n (entry.object.lastModified === existing.object.lastModified &&\n !entry.tombstone &&\n !!existing.tombstone)\n );\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one as the `result` property (a Vue ref).\n * Before any objects have been received, the result\n * is `undefined`. If the object has been deleted,\n * the result is `null`.\n */\nexport class SingletonReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly entry: Ref<\n GraffitiObjectStreamContinueEntry<Schema> | null | undefined\n > = ref();\n\n get result(): Ref<GraffitiObject<Schema> | null | undefined> {\n return computed(() => {\n const value = this.entry.value;\n if (!value) return value;\n if (value.tombstone) return null;\n return value.object;\n });\n }\n\n clear() {\n this.entry.value = undefined;\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\") {\n if (entry === \"clear\") {\n this.clear();\n return;\n }\n if (!entry || isEntryNewer<Schema>(entry, this.entry.value)) {\n this.entry.value = entry;\n }\n }\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one per URI as the `results` property (a Vue ref).\n * If multiple objects are received concurrently,\n * they are processed in batches every `REFRESH_RATE` milliseconds\n * to avoid freezing the interface.\n */\nexport class ArrayReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly results: Ref<GraffitiObject<Schema>[]> = ref([]);\n readonly resultsRaw: Map<string, GraffitiObjectStreamContinueEntry<Schema>> =\n new Map();\n batchFlattenTimer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(readonly graffiti: Graffiti) {}\n\n clear() {\n this.resultsRaw.clear();\n this.results.value = [];\n clearTimeout(this.batchFlattenTimer);\n this.batchFlattenTimer = undefined;\n }\n\n flattenResults() {\n this.results.value = Array.from(this.resultsRaw.values()).reduce<\n GraffitiObject<Schema>[]\n >((acc, entry) => {\n if (!entry.tombstone) {\n acc.push(entry.object);\n }\n return acc;\n }, []);\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\") {\n if (!entry) return;\n if (entry === \"clear\") {\n this.clear();\n return;\n }\n const existing = this.resultsRaw.get(entry.object.url);\n if (!isEntryNewer<Schema>(entry, existing)) return;\n this.resultsRaw.set(entry.object.url, entry);\n\n // Don't flatten the results all at once,\n // because we may get a lot of results\n // and we don't want the interface to\n // freeze up\n if (!this.batchFlattenTimer) {\n this.batchFlattenTimer = setTimeout(() => {\n this.flattenResults();\n this.batchFlattenTimer = undefined;\n }, 0);\n }\n }\n}\n","import { onScopeDispose, ref, toValue, watch } from \"vue\";\nimport type { Ref, MaybeRefOrGetter } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiSynchronize, useGraffitiSession } from \"./globals\";\nimport { GetPoller, Poller, StreamPoller } from \"./pollers\";\nimport { ArrayReducer, Reducer, SingletonReducer } from \"./reducers\";\n\nfunction makeComposable<Schema extends JSONSchema>(\n reducer: Reducer<Schema>,\n poller: Poller<Schema>,\n synchronizeFactory: () => AsyncGenerator<\n GraffitiObjectStreamContinueEntry<Schema>\n >,\n toWatch: readonly (() => any)[],\n autopoll: MaybeRefOrGetter<boolean>,\n) {\n let synchronizeIterator:\n | AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>\n | undefined;\n async function pollSynchronize() {\n synchronizeIterator = synchronizeFactory();\n for await (const result of synchronizeIterator) {\n if (result.error) {\n console.error(result.error);\n continue;\n }\n reducer.onEntry(result);\n }\n }\n\n let isAlreadyPolling = false;\n let innerPoll: (() => Promise<void>) | undefined;\n const poll = async () => {\n if (isAlreadyPolling) return;\n if (!innerPoll) return;\n const myPoll = innerPoll;\n isAlreadyPolling = true;\n try {\n await myPoll();\n } finally {\n if (myPoll !== innerPoll) return;\n isAlreadyPolling = false;\n if (toValue(autopoll)) {\n poll();\n }\n }\n };\n\n const isInitialPolling = ref(false);\n watch(\n toWatch,\n async (newValue, oldValue) => {\n // Catch unnecessary updates\n if (JSON.stringify(newValue) === JSON.stringify(oldValue)) {\n return;\n }\n\n synchronizeIterator?.return(null);\n reducer.clear();\n poller.clear();\n\n pollSynchronize();\n\n innerPoll = () => poller.poll(reducer.onEntry.bind(reducer));\n const myPoll = innerPoll;\n\n isAlreadyPolling = false;\n\n isInitialPolling.value = true;\n try {\n await poll();\n } finally {\n if (myPoll !== innerPoll) return;\n isInitialPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => {\n synchronizeIterator?.return(null);\n reducer.clear();\n poller.clear();\n innerPoll = undefined;\n });\n\n return { poll, isInitialPolling };\n}\n\nfunction toSessionGetter(\n sessionInjected: ReturnType<typeof useGraffitiSession>,\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n) {\n return () => {\n const sessionValue = toValue(session);\n if (sessionValue === undefined) {\n return sessionInjected?.value;\n } else {\n return sessionValue;\n }\n };\n}\n\nfunction callGetters<T extends readonly (() => any)[]>(\n getters: T,\n): {\n [K in keyof T]: ReturnType<T[K]>;\n} {\n return getters.map((fn) => fn()) as any;\n}\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiDiscover}.\n *\n * The arguments of this composable as the same as Graffiti.discover,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiDiscover<Schema extends JSONSchema>(\n channels: MaybeRefOrGetter<string[]>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n objects: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const channelsGetter = () => toValue(channels);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [channelsGetter, schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeDiscover(...callGetters(argGetters));\n const streamFactory = () => graffiti.discover(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects.\n */\n objects: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiGet}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiGet<Schema extends JSONSchema>(\n locationOrUri: MaybeRefOrGetter<GraffitiObjectUrl | string>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n object: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const locationOrUriGetter = () => toValue(locationOrUri);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [\n locationOrUriGetter,\n schemaGetter,\n sessionGetter,\n ] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeGet(...callGetters(argGetters));\n\n const reducer = new SingletonReducer<Schema>();\n const getter = () => graffiti.get<Schema>(...callGetters(argGetters));\n const poller = new GetPoller<Schema>(getter);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * the retrieved Graffiti object, if it exists. If the object has been deleted,\n * the result is `null`. If the object is still being fetched, the result is `undefined`.\n */\n object: reducer.result,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiRecoverOrphans}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiRecoverOrphans<Schema extends JSONSchema>(\n schema: MaybeRefOrGetter<Schema>,\n session: MaybeRefOrGetter<GraffitiSession>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n objects: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n\n const schemaGetter = () => toValue(schema);\n const sessionGetter = () => toValue(session);\n const argGetters = [schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeRecoverOrphans(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const streamFactory = () =>\n graffiti.recoverOrphans<Schema>(...callGetters(argGetters));\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects.\n */\n objects: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiDiscover } from \"./composables\";\n\nconst props = defineProps<{\n channels: string[];\n schema: Schema;\n session?: GraffitiSession | null;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n objects: GraffitiObject<Schema>[];\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, poll, isInitialPolling } = useGraffitiDiscover<Schema>(\n toRef(props, \"channels\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :objects=\"objects\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiGet } from \"./composables\";\n\nconst props = defineProps<{\n url: string | GraffitiObjectUrl;\n schema: Schema;\n session?: GraffitiSession | null;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n object: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { object, poll, isInitialPolling } = useGraffitiGet<Schema>(\n toRef(props, \"url\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :object=\"object\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiRecoverOrphans } from \"./composables\";\n\nconst props = defineProps<{\n schema: Schema;\n session: GraffitiSession;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n objects: GraffitiObject<Schema>[];\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, poll, isInitialPolling } = useGraffitiRecoverOrphans<Schema>(\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :objects=\"objects\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","import type { App, Plugin, Ref } from \"vue\";\nimport { ref } from \"vue\";\nimport Discover from \"./Discover.vue\";\nimport Get from \"./Get.vue\";\nimport RecoverOrphans from \"./RecoverOrphans.vue\";\nimport type {\n Graffiti,\n GraffitiSession,\n GraffitiLoginEvent,\n GraffitiLogoutEvent,\n GraffitiSessionInitializedEvent,\n} from \"@graffiti-garden/api\";\nimport { globals } from \"./globals\";\nimport type { Router } from \"vue-router\";\nimport { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\ndeclare module \"vue\" {\n export interface ComponentCustomProperties {\n /**\n * Global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n */\n $graffiti: Graffiti;\n /**\n * Global reactive [GraffitiSession](https://api.graffiti.garden/classes/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n */\n $graffitiSession: Ref<GraffitiSession | undefined | null>;\n }\n\n export interface GlobalComponents {\n GraffitiDiscover: typeof Discover;\n GraffitiGet: typeof Get;\n GraffitiRecoverOrphans: typeof RecoverOrphans;\n }\n}\nexport type { ComponentCustomProperties } from \"vue\";\n\n/**\n * Options for the {@link GraffitiPlugin}.\n */\nexport interface GraffitiPluginOptions {\n /**\n * An instance of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * for the Vue.js plugin to use.\n * This instance, wrapped with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html),\n * will be exposed in Vue templates as {@link ComponentCustomProperties.$graffiti | $graffiti}\n * and in setup functions as {@link useGraffiti}.\n * You must interact with Graffiti through these wrapped instances\n * to enable reactivity.\n *\n * You'll likely want to use the [federated implementation](https://github.com/graffiti-garden/implementation-federated).\n * However, you could also use the [local implementation](https://github.com/graffiti-garden/implementation-local)\n * for testing. Other implementations may be available in the future.\n */\n graffiti: Graffiti;\n}\n\n/**\n * A [Vue.js](https://vuejs.org/) plugin that wraps around\n * the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * to provide [reactive](https://en.wikipedia.org/wiki/Reactive_programming) versions\n * of various Graffiti API methods.\n *\n * These reactive methods are available as both\n * [renderless components](https://vuejs.org/guide/components/slots#renderless-components),\n * which make it possible to create a whole Graffiti app in an HTML template,\n * and [composables](https://vuejs.org/guide/reusability/composables.html),\n * which can be used in the programmatic [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * | [API](https://api.graffiti.garden/classes/Graffiti.html) method | [Composable](https://vuejs.org/guide/reusability/composables.html) | [Component](https://vuejs.org/guide/components/slots#renderless-components) |\n * | --- | --- | --- |\n * | [discover](https://api.graffiti.garden/classes/Graffiti.html#discover) | {@link useGraffitiDiscover} | {@link GraffitiDiscover} |\n * | [get](https://api.graffiti.garden/classes/Graffiti.html#get) | {@link useGraffitiGet} | {@link GraffitiGet} |\n * | [recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans) | {@link useGraffitiRecoverOrphans} | {@link GraffitiRecoverOrphans} |\n *\n * The plugin also exposes a global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * and keeps track of the global [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html)\n * state as a reactive variable.\n * They are available in templates as global variables or in setup functions as\n * composable functions.\n *\n * | Global variabale | [Composable](https://vuejs.org/guide/reusability/composables.html) |\n * | --- | --- |\n * | {@link ComponentCustomProperties.$graffiti | $graffiti } | {@link useGraffiti} |\n * | {@link ComponentCustomProperties.$graffitiSession | $graffitiSession } | {@link useGraffitiSession} |\n *\n * [See the README for installation instructions](/).\n *\n * You can [try out live examples](/examples/), but basic usage looks like this:\n *\n * ```ts\n * import { createApp } from \"vue\";\n * import { GraffitiPlugin } from \"@graffiti-garden/vue\";\n * import { GraffitiLocal } from \"@graffiti-garden/implementation-local\";\n * import App from \"./App.vue\";\n *\n * createApp(App)\n * .use(GraffitiPlugin, {\n * graffiti: new GraffitiLocal(),\n * })\n * ```\n *\n * ```vue\n * <!-- App.vue -->\n * <template>\n * <button\n * v-if=\"$graffitiSession.value\"\n * @click=\"$graffiti.put({\n * value: { content: 'Hello, world!' },\n * channels: [ 'my-channel' ]\n * }, $graffitiSession.value)\"\n * >\n * Say Hello\n * </button>\n * <button v-else @click=\"$graffiti.login()\">\n * Log In to Say Hello\n * </button>\n *\n * <GraffitiDiscover\n * v-slot=\"{ results }\"\n * :channels=\"[ 'my-channel' ]\"\n * :schema=\"{\n * properties: {\n * value: {\n * required: ['content'],\n * properties: {\n * content: { type: 'string' }\n * }\n * }\n * }\n * }\"\n * >\n * <ul>\n * <li\n * v-for=\"result in results\"\n * :key=\"$graffiti.objectToUri(result)\"\n * >\n * {{ result.value.content }}\n * </li>\n * </ul>\n * </GraffitiDiscover>\n * </template>\n * ```\n */\nexport const GraffitiPlugin: Plugin<GraffitiPluginOptions> = {\n install(app: App, options: GraffitiPluginOptions) {\n const graffitiBase = options.graffiti;\n const graffiti = new GraffitiSynchronize(graffitiBase);\n\n const graffitiSession = ref<GraffitiSession | undefined | null>(undefined);\n graffiti.sessionEvents.addEventListener(\"initialized\", async (evt) => {\n const detail = (evt as GraffitiSessionInitializedEvent).detail;\n\n if (detail && detail.error) {\n console.error(detail.error);\n }\n\n if (detail && detail.href) {\n // If we're using Vue Router, redirect to the URL after login\n const router = app.config.globalProperties.$router as\n | Router\n | undefined;\n if (router) {\n const base = router.options.history.base;\n const url = new URL(detail.href);\n if (url.pathname.startsWith(base)) {\n url.pathname = url.pathname.slice(base.length);\n }\n await router.replace(url.pathname + url.search + url.hash);\n }\n }\n\n // Set the session to \"null\" if the user is not logged in\n if (!graffitiSession.value) {\n graffitiSession.value = null;\n }\n });\n graffiti.sessionEvents.addEventListener(\"login\", (evt) => {\n const detail = (evt as GraffitiLoginEvent).detail;\n if (detail.error) {\n console.error(\"Error logging in:\");\n console.error(detail.error);\n return;\n } else {\n graffitiSession.value = detail.session;\n }\n });\n graffiti.sessionEvents.addEventListener(\"logout\", (evt) => {\n const detail = (evt as GraffitiLogoutEvent).detail;\n if (detail.error) {\n console.error(\"Error logging out:\");\n console.error(detail.error);\n } else {\n graffitiSession.value = null;\n }\n });\n\n globals.graffitiSynchronize = graffiti;\n globals.graffitiSession = graffitiSession;\n\n app.component(\"GraffitiDiscover\", Discover);\n app.component(\"GraffitiGet\", Get);\n app.component(\"GraffitiRecoverOrphans\", RecoverOrphans);\n app.config.globalProperties.$graffiti = graffiti;\n app.config.globalProperties.$graffitiSession = graffitiSession;\n },\n};\n\nexport * from \"./composables\";\nexport {\n useGraffiti,\n useGraffitiSynchronize,\n useGraffitiSession,\n} from \"./globals\";\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiDiscover}.\n */\nexport const GraffitiDiscover = Discover;\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiGet}.\n */\nexport const GraffitiGet = Get;\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiRecoverOrphans}.\n */\nexport const GraffitiRecoverOrphans = RecoverOrphans;\n"],"names":["globals","useGraffitiSynchronize","graffiti","useGraffiti","useGraffitiSession","session","s","t","e","GetPoller","getter","__publicField","onEntry","object","myGetter","StreamPoller","streamFactory","GraffitiErrorNotFound","myIterator","result","iterator","isEntryNewer","entry","existing","SingletonReducer","ref","computed","value","ArrayReducer","acc","makeComposable","reducer","poller","synchronizeFactory","toWatch","autopoll","synchronizeIterator","pollSynchronize","isAlreadyPolling","innerPoll","poll","myPoll","toValue","isInitialPolling","watch","newValue","oldValue","onScopeDispose","toSessionGetter","sessionInjected","sessionValue","callGetters","getters","fn","useGraffitiDiscover","channels","schema","channelsGetter","schemaGetter","sessionGetter","argGetters","useGraffitiGet","locationOrUri","locationOrUriGetter","useGraffitiRecoverOrphans","props","__props","objects","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":"6TAIaA,EAGT,CAAC,EAOE,SAASC,GAAyB,CACvC,MAAMC,EAAWF,EAAQ,oBACzB,GAAI,CAACE,EACH,MAAM,IAAI,MACR,sEACF,EAEK,OAAAA,CACT,CAeO,SAASC,GAAwB,CACtC,OAAOF,EAAuB,CAChC,CAkBO,SAASG,GAAqB,CACnC,MAAMC,EAAUL,EAAQ,gBACxB,GAAI,CAACK,EACH,MAAM,IAAI,MACR,qEACF,EAEK,OAAAA,CACT,CCjEkX,IAA8PC,EAAE,MAAMC,UAAU,KAAK,CAAC,YAAYC,EAAE,CAAC,MAAMA,CAAC,EAAE,KAAK,KAAK,wBAAwB,OAAO,eAAe,KAAKD,EAAE,SAAS,CAAC,CAAC,ECuBnuB,MAAME,CAA+D,CAC1E,YAAqBC,EAA+C,CAEpEC,EAAA,YAA+B,MAAOC,GAAY,CAC5C,IAAAC,EACJ,MAAMC,EAAW,KAAK,OAClB,GAAA,CACFD,EAAS,MAAMC,EAAS,OACd,CACN,KAAK,SAAWA,GAClBF,EAAQ,IAAI,EAEd,MAAA,CAEE,KAAK,SAAWE,GACVF,EAAA,CAAE,OAAAC,EAAQ,CAEtB,GAhBqB,KAAA,OAAAH,CAAA,CAkBrB,OAAQ,CAAA,CACV,CAOO,MAAMK,CAAkE,CAI7E,YAAqBC,EAAmD,CAHxEL,EAAA,iBACAA,EAAA,iBAgBAA,EAAA,YAA+B,MAAOC,GAAY,CAC5C,GAAA,CAAC,KAAK,SACR,GAAI,KAAK,SACH,GAAA,CACG,KAAA,SAAW,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nB,MAAAC,EAASP,EAAI,OAAO,iBAAiB,QAG3C,GAAIO,EAAQ,CACJ,MAAAC,EAAOD,EAAO,QAAQ,QAAQ,KAC9BE,EAAM,IAAI,IAAIH,EAAO,IAAI,EAC3BG,EAAI,SAAS,WAAWD,CAAI,IAC9BC,EAAI,SAAWA,EAAI,SAAS,MAAMD,EAAK,MAAM,GAE/C,MAAMD,EAAO,QAAQE,EAAI,SAAWA,EAAI,OAASA,EAAI,IAAI,CAAA,CAC3D,CAIGL,EAAgB,QACnBA,EAAgB,MAAQ,KAC1B,CACD,EACDxE,EAAS,cAAc,iBAAiB,QAAUyE,GAAQ,CACxD,MAAMC,EAAUD,EAA2B,OAC3C,GAAIC,EAAO,MAAO,CAChB,QAAQ,MAAM,mBAAmB,EACzB,QAAA,MAAMA,EAAO,KAAK,EAC1B,MAAA,MAEAF,EAAgB,MAAQE,EAAO,OACjC,CACD,EACD1E,EAAS,cAAc,iBAAiB,SAAWyE,GAAQ,CACzD,MAAMC,EAAUD,EAA4B,OACxCC,EAAO,OACT,QAAQ,MAAM,oBAAoB,EAC1B,QAAA,MAAMA,EAAO,KAAK,GAE1BF,EAAgB,MAAQ,IAC1B,CACD,EAED1E,EAAQ,oBAAsBE,EAC9BF,EAAQ,gBAAkB0E,EAEtBJ,EAAA,UAAU,mBAAoBU,CAAQ,EACtCV,EAAA,UAAU,cAAeW,CAAG,EAC5BX,EAAA,UAAU,yBAA0BY,CAAc,EAClDZ,EAAA,OAAO,iBAAiB,UAAYpE,EACpCoE,EAAA,OAAO,iBAAiB,iBAAmBI,CAAA,CAEnD,EAiBaS,EAAmBH,EASnBI,EAAcH,EASdI,EAAyBH","x_google_ignoreList":[1]}
1
+ {"version":3,"file":"plugin.js","sources":["../../src/globals.ts","../../node_modules/@graffiti-garden/api/dist/index.mjs","../../src/pollers.ts","../../src/reducers.ts","../../src/composables.ts","../../src/Discover.vue","../../src/Get.vue","../../src/RecoverOrphans.vue","../../src/plugin.ts"],"sourcesContent":["import type { Ref } from \"vue\";\nimport type { Graffiti, GraffitiSession } from \"@graffiti-garden/api\";\nimport type { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\nexport const globals: {\n graffitiSynchronize?: GraffitiSynchronize;\n graffitiSession?: Ref<GraffitiSession | undefined | null>;\n} = {};\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * that has been wrapped by the {@link GraffitiPlugin} with the [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSynchronize() {\n const graffiti = globals.graffitiSynchronize;\n if (!graffiti) {\n throw new Error(\n \"No Graffiti instance provided, did you forget to install the plugin?\",\n );\n }\n return graffiti;\n}\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffiti | $graffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n *\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffiti(): Graffiti {\n return useGraffitiSynchronize();\n}\n\n/**\n * Returns a global reactive [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffitiSession | $graffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSession() {\n const session = globals.graffitiSession;\n if (!session) {\n throw new Error(\n \"No Graffiti session provided, did you forget to install the plugin?\",\n );\n }\n return session;\n}\n","var r=class{};var p={type:\"object\",properties:{value:{type:\"object\"},channels:{type:\"array\",items:{type:\"string\"}},allowed:{type:\"array\",items:{type:\"string\"},nullable:!0},url:{type:\"string\"},actor:{type:\"string\"},lastModified:{type:\"number\"}},additionalProperties:!1,required:[\"value\",\"channels\",\"actor\",\"url\",\"lastModified\"]},O={...p,required:[\"value\",\"channels\"]};var a=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorUnauthorized\",Object.setPrototypeOf(this,t.prototype)}},i=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorForbidden\",Object.setPrototypeOf(this,t.prototype)}},s=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorNotFound\",Object.setPrototypeOf(this,t.prototype)}},o=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorInvalidSchema\",Object.setPrototypeOf(this,t.prototype)}},n=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorSchemaMismatch\",Object.setPrototypeOf(this,t.prototype)}},c=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorPatchTestFailed\",Object.setPrototypeOf(this,t.prototype)}},f=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorPatchError\",Object.setPrototypeOf(this,t.prototype)}},m=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorInvalidUrl\",Object.setPrototypeOf(this,t.prototype)}},S=class t extends Error{constructor(e){super(e),this.name=\"GraffitiErrorUnrecognizedUriScheme\",Object.setPrototypeOf(this,t.prototype)}};export{r as Graffiti,i as GraffitiErrorForbidden,o as GraffitiErrorInvalidSchema,m as GraffitiErrorInvalidUrl,s as GraffitiErrorNotFound,f as GraffitiErrorPatchError,c as GraffitiErrorPatchTestFailed,n as GraffitiErrorSchemaMismatch,a as GraffitiErrorUnauthorized,S as GraffitiErrorUnrecognizedUrlScheme,p as GraffitiObjectJSONSchema,O as GraffitiPutObjectJSONSchema};\n//# sourceMappingURL=index.mjs.map\n","import {\n type Graffiti,\n type JSONSchema,\n type GraffitiObject,\n type GraffitiObjectStreamReturn,\n type GraffitiObjectStreamContinueEntry,\n type GraffitiObjectStream,\n type GraffitiObjectStreamContinue,\n GraffitiErrorNotFound,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Poller<Schema extends JSONSchema> {\n abstract poll(\n onEntry: (\n entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\",\n ) => void,\n ): Promise<void>;\n abstract clear(): void;\n}\n\n/**\n * Polls for a single object and calls onValue with the result.\n */\nexport class GetPoller<Schema extends JSONSchema> implements Poller<Schema> {\n constructor(readonly getter: () => Promise<GraffitiObject<Schema>>) {}\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n let object: GraffitiObject<Schema>;\n const myGetter = this.getter;\n try {\n object = await myGetter();\n } catch (e) {\n if (this.getter === myGetter) {\n onEntry(null);\n }\n return;\n }\n if (this.getter === myGetter) {\n onEntry({ object });\n }\n };\n\n clear() {}\n}\n\n/**\n * Polls for multiple objects and calls `onObject` with the result.\n * If `poll` is called multiple times, it doesn't poll the results\n * entirely from scratch, but instead only polls the new results.\n */\nexport class StreamPoller<Schema extends JSONSchema> implements Poller<Schema> {\n iterator: GraffitiObjectStreamContinue<Schema> | undefined;\n continue: (() => GraffitiObjectStreamContinue<Schema>) | undefined;\n\n constructor(readonly streamFactory: () => GraffitiObjectStream<Schema>) {}\n\n clear() {\n if (this.iterator) {\n const iterator = this.iterator;\n this.iterator.return({\n continue: () => iterator,\n cursor: \"\",\n });\n }\n this.iterator = undefined;\n this.continue = undefined;\n }\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n if (!this.iterator) {\n if (this.continue) {\n try {\n this.iterator = this.continue();\n } catch (e) {\n // The cursor has expired, we need to start from scratch.\n if (e instanceof GraffitiErrorNotFound) {\n onEntry(\"clear\");\n this.iterator = this.streamFactory();\n } else {\n throw e;\n }\n }\n } else {\n this.iterator = this.streamFactory();\n }\n }\n\n while (true) {\n // Check if the iterator has been cancelled.\n if (!this.iterator) {\n break;\n }\n\n const myIterator: GraffitiObjectStreamContinue<Schema> = this.iterator;\n\n const result = await myIterator.next();\n\n // Check again if it was cancelled.\n if (myIterator !== this.iterator) {\n continue;\n }\n\n if (result.done) {\n this.iterator = undefined;\n if (result.value) {\n this.continue = result.value.continue;\n }\n break;\n }\n\n if (result.value.error) {\n console.error(result.value.error);\n continue;\n }\n\n onEntry(result.value);\n }\n };\n}\n","import { computed, ref } from \"vue\";\nimport type { Ref } from \"vue\";\nimport type {\n GraffitiObject,\n Graffiti,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Reducer<Schema extends JSONSchema> {\n abstract clear(): void;\n abstract onEntry(\n entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\",\n ): void;\n}\n\nfunction isEntryNewer<Schema extends JSONSchema>(\n entry: GraffitiObjectStreamContinueEntry<Schema>,\n existing: GraffitiObjectStreamContinueEntry<Schema> | null | undefined,\n): boolean {\n return (\n !existing ||\n entry.object.lastModified > existing.object.lastModified ||\n (entry.object.lastModified === existing.object.lastModified &&\n !entry.tombstone &&\n !!existing.tombstone)\n );\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one as the `result` property (a Vue ref).\n * Before any objects have been received, the result\n * is `undefined`. If the object has been deleted,\n * the result is `null`.\n */\nexport class SingletonReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly entry: Ref<\n GraffitiObjectStreamContinueEntry<Schema> | null | undefined\n > = ref();\n\n get result(): Ref<GraffitiObject<Schema> | null | undefined> {\n return computed(() => {\n const value = this.entry.value;\n if (!value) return value;\n if (value.tombstone) return null;\n return value.object;\n });\n }\n\n clear() {\n this.entry.value = undefined;\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\") {\n if (entry === \"clear\") {\n this.clear();\n return;\n }\n if (!entry || isEntryNewer<Schema>(entry, this.entry.value)) {\n this.entry.value = entry;\n }\n }\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one per URI as the `results` property (a Vue ref).\n * If multiple objects are received concurrently,\n * they are processed in batches every `REFRESH_RATE` milliseconds\n * to avoid freezing the interface.\n */\nexport class ArrayReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly results: Ref<GraffitiObject<Schema>[]> = ref([]);\n readonly resultsRaw: Map<string, GraffitiObjectStreamContinueEntry<Schema>> =\n new Map();\n batchFlattenTimer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(readonly graffiti: Graffiti) {}\n\n clear() {\n this.resultsRaw.clear();\n this.results.value = [];\n clearTimeout(this.batchFlattenTimer);\n this.batchFlattenTimer = undefined;\n }\n\n flattenResults() {\n this.results.value = Array.from(this.resultsRaw.values()).reduce<\n GraffitiObject<Schema>[]\n >((acc, entry) => {\n if (!entry.tombstone) {\n acc.push(entry.object);\n }\n return acc;\n }, []);\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null | \"clear\") {\n if (!entry) return;\n if (entry === \"clear\") {\n this.clear();\n return;\n }\n const existing = this.resultsRaw.get(entry.object.url);\n if (!isEntryNewer<Schema>(entry, existing)) return;\n this.resultsRaw.set(entry.object.url, entry);\n\n // Don't flatten the results all at once,\n // because we may get a lot of results\n // and we don't want the interface to\n // freeze up\n if (!this.batchFlattenTimer) {\n this.batchFlattenTimer = setTimeout(() => {\n this.flattenResults();\n this.batchFlattenTimer = undefined;\n }, 0);\n }\n }\n}\n","import { onScopeDispose, ref, toValue, watch } from \"vue\";\nimport type { Ref, MaybeRefOrGetter } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiSynchronize, useGraffitiSession } from \"./globals\";\nimport { GetPoller, Poller, StreamPoller } from \"./pollers\";\nimport { ArrayReducer, Reducer, SingletonReducer } from \"./reducers\";\n\nfunction makeComposable<Schema extends JSONSchema>(\n reducer: Reducer<Schema>,\n poller: Poller<Schema>,\n synchronizeFactory: () => AsyncGenerator<\n GraffitiObjectStreamContinueEntry<Schema>\n >,\n toWatch: readonly (() => any)[],\n autopoll: MaybeRefOrGetter<boolean>,\n) {\n let synchronizeIterator:\n | AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>\n | undefined;\n async function pollSynchronize() {\n synchronizeIterator = synchronizeFactory();\n for await (const result of synchronizeIterator) {\n if (result.error) {\n console.error(result.error);\n continue;\n }\n reducer.onEntry(result);\n }\n }\n\n let isAlreadyPolling = false;\n let innerPoll: (() => Promise<void>) | undefined;\n const poll = async () => {\n if (isAlreadyPolling) return;\n if (!innerPoll) return;\n const myPoll = innerPoll;\n isAlreadyPolling = true;\n try {\n await myPoll();\n } catch (e) {\n // If there is an error, wait a little bit so as not to\n // cause an infinite loop\n await new Promise((r) => setTimeout(r, 2000));\n } finally {\n if (myPoll !== innerPoll) return;\n isAlreadyPolling = false;\n if (toValue(autopoll)) {\n poll();\n }\n }\n };\n\n const isInitialPolling = ref(false);\n watch(\n toWatch,\n async (newValue, oldValue) => {\n // Catch unnecessary updates\n if (JSON.stringify(newValue) === JSON.stringify(oldValue)) {\n return;\n }\n\n synchronizeIterator?.return(null);\n reducer.clear();\n poller.clear();\n\n pollSynchronize();\n\n innerPoll = () => poller.poll(reducer.onEntry.bind(reducer));\n const myPoll = innerPoll;\n\n isAlreadyPolling = false;\n\n isInitialPolling.value = true;\n try {\n await poll();\n } finally {\n if (myPoll !== innerPoll) return;\n isInitialPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => {\n synchronizeIterator?.return(null);\n reducer.clear();\n poller.clear();\n innerPoll = undefined;\n });\n\n return { poll, isInitialPolling };\n}\n\nfunction toSessionGetter(\n sessionInjected: ReturnType<typeof useGraffitiSession>,\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n) {\n return () => {\n const sessionValue = toValue(session);\n if (sessionValue === undefined) {\n return sessionInjected?.value;\n } else {\n return sessionValue;\n }\n };\n}\n\nfunction callGetters<T extends readonly (() => any)[]>(\n getters: T,\n): {\n [K in keyof T]: ReturnType<T[K]>;\n} {\n return getters.map((fn) => fn()) as any;\n}\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiDiscover}.\n *\n * The arguments of this composable as the same as Graffiti.discover,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiDiscover<Schema extends JSONSchema>(\n channels: MaybeRefOrGetter<string[]>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n objects: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const channelsGetter = () => toValue(channels);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [channelsGetter, schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeDiscover(...callGetters(argGetters));\n const streamFactory = () => graffiti.discover(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects.\n */\n objects: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiGet}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiGet<Schema extends JSONSchema>(\n locationOrUri: MaybeRefOrGetter<GraffitiObjectUrl | string>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n object: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const locationOrUriGetter = () => toValue(locationOrUri);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [\n locationOrUriGetter,\n schemaGetter,\n sessionGetter,\n ] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeGet(...callGetters(argGetters));\n\n const reducer = new SingletonReducer<Schema>();\n const getter = () => graffiti.get<Schema>(...callGetters(argGetters));\n const poller = new GetPoller<Schema>(getter);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * the retrieved Graffiti object, if it exists. If the object has been deleted,\n * the result is `null`. If the object is still being fetched, the result is `undefined`.\n */\n object: reducer.result,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiRecoverOrphans}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiRecoverOrphans<Schema extends JSONSchema>(\n schema: MaybeRefOrGetter<Schema>,\n session: MaybeRefOrGetter<GraffitiSession>,\n autopoll: MaybeRefOrGetter<boolean> = false,\n): {\n objects: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isInitialPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n\n const schemaGetter = () => toValue(schema);\n const sessionGetter = () => toValue(session);\n const argGetters = [schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeRecoverOrphans(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const streamFactory = () =>\n graffiti.recoverOrphans<Schema>(...callGetters(argGetters));\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isInitialPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n autopoll,\n );\n\n return {\n /**\n * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects.\n */\n objects: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the *first* poll is currently running.\n * Useful to show a loading spinner or disable a button.\n *\n * This also tracks new polls when the arguments have changed,\n * but it does not track ongoing polls from either calling\n * {@link poll} or using the `autopoll` argument.\n */\n isInitialPolling,\n };\n}\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiDiscover } from \"./composables\";\n\nconst props = defineProps<{\n channels: string[];\n schema: Schema;\n session?: GraffitiSession | null;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n objects: GraffitiObject<Schema>[];\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, poll, isInitialPolling } = useGraffitiDiscover<Schema>(\n toRef(props, \"channels\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :objects=\"objects\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiGet } from \"./composables\";\n\nconst props = defineProps<{\n url: string | GraffitiObjectUrl;\n schema: Schema;\n session?: GraffitiSession | null;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n object: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { object, poll, isInitialPolling } = useGraffitiGet<Schema>(\n toRef(props, \"url\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :object=\"object\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiRecoverOrphans } from \"./composables\";\n\nconst props = defineProps<{\n schema: Schema;\n session: GraffitiSession;\n autopoll?: boolean;\n}>();\n\ndefineSlots<{\n default?(props: {\n objects: GraffitiObject<Schema>[];\n poll: () => void;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, poll, isInitialPolling } = useGraffitiRecoverOrphans<Schema>(\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n toRef(props, \"autopoll\"),\n);\n</script>\n\n<template>\n <slot\n :objects=\"objects\"\n :poll=\"poll\"\n :isInitialPolling=\"isInitialPolling\"\n ></slot>\n</template>\n","import type { App, Plugin, Ref } from \"vue\";\nimport { ref } from \"vue\";\nimport Discover from \"./Discover.vue\";\nimport Get from \"./Get.vue\";\nimport RecoverOrphans from \"./RecoverOrphans.vue\";\nimport type {\n Graffiti,\n GraffitiSession,\n GraffitiLoginEvent,\n GraffitiLogoutEvent,\n GraffitiSessionInitializedEvent,\n} from \"@graffiti-garden/api\";\nimport { globals } from \"./globals\";\nimport type { Router } from \"vue-router\";\nimport { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\ndeclare module \"vue\" {\n export interface ComponentCustomProperties {\n /**\n * Global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n */\n $graffiti: Graffiti;\n /**\n * Global reactive [GraffitiSession](https://api.graffiti.garden/classes/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n */\n $graffitiSession: Ref<GraffitiSession | undefined | null>;\n }\n\n export interface GlobalComponents {\n GraffitiDiscover: typeof Discover;\n GraffitiGet: typeof Get;\n GraffitiRecoverOrphans: typeof RecoverOrphans;\n }\n}\nexport type { ComponentCustomProperties } from \"vue\";\n\n/**\n * Options for the {@link GraffitiPlugin}.\n */\nexport interface GraffitiPluginOptions {\n /**\n * An instance of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * for the Vue.js plugin to use.\n * This instance, wrapped with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html),\n * will be exposed in Vue templates as {@link ComponentCustomProperties.$graffiti | $graffiti}\n * and in setup functions as {@link useGraffiti}.\n * You must interact with Graffiti through these wrapped instances\n * to enable reactivity.\n *\n * You'll likely want to use the [federated implementation](https://github.com/graffiti-garden/implementation-federated).\n * However, you could also use the [local implementation](https://github.com/graffiti-garden/implementation-local)\n * for testing. Other implementations may be available in the future.\n */\n graffiti: Graffiti;\n}\n\n/**\n * A [Vue.js](https://vuejs.org/) plugin that wraps around\n * the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * to provide [reactive](https://en.wikipedia.org/wiki/Reactive_programming) versions\n * of various Graffiti API methods.\n *\n * These reactive methods are available as both\n * [renderless components](https://vuejs.org/guide/components/slots#renderless-components),\n * which make it possible to create a whole Graffiti app in an HTML template,\n * and [composables](https://vuejs.org/guide/reusability/composables.html),\n * which can be used in the programmatic [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * | [API](https://api.graffiti.garden/classes/Graffiti.html) method | [Composable](https://vuejs.org/guide/reusability/composables.html) | [Component](https://vuejs.org/guide/components/slots#renderless-components) |\n * | --- | --- | --- |\n * | [discover](https://api.graffiti.garden/classes/Graffiti.html#discover) | {@link useGraffitiDiscover} | {@link GraffitiDiscover} |\n * | [get](https://api.graffiti.garden/classes/Graffiti.html#get) | {@link useGraffitiGet} | {@link GraffitiGet} |\n * | [recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans) | {@link useGraffitiRecoverOrphans} | {@link GraffitiRecoverOrphans} |\n *\n * The plugin also exposes a global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * and keeps track of the global [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html)\n * state as a reactive variable.\n * They are available in templates as global variables or in setup functions as\n * composable functions.\n *\n * | Global variabale | [Composable](https://vuejs.org/guide/reusability/composables.html) |\n * | --- | --- |\n * | {@link ComponentCustomProperties.$graffiti | $graffiti } | {@link useGraffiti} |\n * | {@link ComponentCustomProperties.$graffitiSession | $graffitiSession } | {@link useGraffitiSession} |\n *\n * [See the README for installation instructions](/).\n *\n * You can [try out live examples](/examples/), but basic usage looks like this:\n *\n * ```ts\n * import { createApp } from \"vue\";\n * import { GraffitiPlugin } from \"@graffiti-garden/vue\";\n * import { GraffitiLocal } from \"@graffiti-garden/implementation-local\";\n * import App from \"./App.vue\";\n *\n * createApp(App)\n * .use(GraffitiPlugin, {\n * graffiti: new GraffitiLocal(),\n * })\n * ```\n *\n * ```vue\n * <!-- App.vue -->\n * <template>\n * <button\n * v-if=\"$graffitiSession.value\"\n * @click=\"$graffiti.put({\n * value: { content: 'Hello, world!' },\n * channels: [ 'my-channel' ]\n * }, $graffitiSession.value)\"\n * >\n * Say Hello\n * </button>\n * <button v-else @click=\"$graffiti.login()\">\n * Log In to Say Hello\n * </button>\n *\n * <GraffitiDiscover\n * v-slot=\"{ results }\"\n * :channels=\"[ 'my-channel' ]\"\n * :schema=\"{\n * properties: {\n * value: {\n * required: ['content'],\n * properties: {\n * content: { type: 'string' }\n * }\n * }\n * }\n * }\"\n * >\n * <ul>\n * <li\n * v-for=\"result in results\"\n * :key=\"$graffiti.objectToUri(result)\"\n * >\n * {{ result.value.content }}\n * </li>\n * </ul>\n * </GraffitiDiscover>\n * </template>\n * ```\n */\nexport const GraffitiPlugin: Plugin<GraffitiPluginOptions> = {\n install(app: App, options: GraffitiPluginOptions) {\n const graffitiBase = options.graffiti;\n const graffiti = new GraffitiSynchronize(graffitiBase);\n\n const graffitiSession = ref<GraffitiSession | undefined | null>(undefined);\n graffiti.sessionEvents.addEventListener(\"initialized\", async (evt) => {\n const detail = (evt as GraffitiSessionInitializedEvent).detail;\n\n if (detail && detail.error) {\n console.error(detail.error);\n }\n\n if (detail && detail.href) {\n // If we're using Vue Router, redirect to the URL after login\n const router = app.config.globalProperties.$router as\n | Router\n | undefined;\n if (router) {\n const base = router.options.history.base;\n const url = new URL(detail.href);\n if (url.pathname.startsWith(base)) {\n url.pathname = url.pathname.slice(base.length);\n }\n await router.replace(url.pathname + url.search + url.hash);\n }\n }\n\n // Set the session to \"null\" if the user is not logged in\n if (!graffitiSession.value) {\n graffitiSession.value = null;\n }\n });\n graffiti.sessionEvents.addEventListener(\"login\", (evt) => {\n const detail = (evt as GraffitiLoginEvent).detail;\n if (detail.error) {\n console.error(\"Error logging in:\");\n console.error(detail.error);\n return;\n } else {\n graffitiSession.value = detail.session;\n }\n });\n graffiti.sessionEvents.addEventListener(\"logout\", (evt) => {\n const detail = (evt as GraffitiLogoutEvent).detail;\n if (detail.error) {\n console.error(\"Error logging out:\");\n console.error(detail.error);\n } else {\n graffitiSession.value = null;\n }\n });\n\n globals.graffitiSynchronize = graffiti;\n globals.graffitiSession = graffitiSession;\n\n app.component(\"GraffitiDiscover\", Discover);\n app.component(\"GraffitiGet\", Get);\n app.component(\"GraffitiRecoverOrphans\", RecoverOrphans);\n app.config.globalProperties.$graffiti = graffiti;\n app.config.globalProperties.$graffitiSession = graffitiSession;\n },\n};\n\nexport * from \"./composables\";\nexport {\n useGraffiti,\n useGraffitiSynchronize,\n useGraffitiSession,\n} from \"./globals\";\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiDiscover}.\n */\nexport const GraffitiDiscover = Discover;\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiGet}.\n */\nexport const GraffitiGet = Get;\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiRecoverOrphans}.\n */\nexport const GraffitiRecoverOrphans = RecoverOrphans;\n"],"names":["globals","useGraffitiSynchronize","graffiti","useGraffiti","useGraffitiSession","session","s","t","e","GetPoller","getter","__publicField","onEntry","object","myGetter","StreamPoller","streamFactory","GraffitiErrorNotFound","myIterator","result","iterator","isEntryNewer","entry","existing","SingletonReducer","ref","computed","value","ArrayReducer","acc","makeComposable","reducer","poller","synchronizeFactory","toWatch","autopoll","synchronizeIterator","pollSynchronize","isAlreadyPolling","innerPoll","poll","myPoll","r","toValue","isInitialPolling","watch","newValue","oldValue","onScopeDispose","toSessionGetter","sessionInjected","sessionValue","callGetters","getters","fn","useGraffitiDiscover","channels","schema","channelsGetter","schemaGetter","sessionGetter","argGetters","useGraffitiGet","locationOrUri","locationOrUriGetter","useGraffitiRecoverOrphans","props","__props","objects","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":"6TAIaA,EAGT,CAAC,EAOE,SAASC,GAAyB,CACvC,MAAMC,EAAWF,EAAQ,oBACzB,GAAI,CAACE,EACH,MAAM,IAAI,MACR,sEACF,EAEK,OAAAA,CACT,CAeO,SAASC,GAAwB,CACtC,OAAOF,EAAuB,CAChC,CAkBO,SAASG,GAAqB,CACnC,MAAMC,EAAUL,EAAQ,gBACxB,GAAI,CAACK,EACH,MAAM,IAAI,MACR,qEACF,EAEK,OAAAA,CACT,CCjEkX,IAA8PC,EAAE,MAAMC,UAAU,KAAK,CAAC,YAAYC,EAAE,CAAC,MAAMA,CAAC,EAAE,KAAK,KAAK,wBAAwB,OAAO,eAAe,KAAKD,EAAE,SAAS,CAAC,CAAC,EC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B,EAC1B,QAAA,MAAMA,EAAO,KAAK,GAE1BF,EAAgB,MAAQ,IAC1B,CACD,EAED3E,EAAQ,oBAAsBE,EAC9BF,EAAQ,gBAAkB2E,EAEtBJ,EAAA,UAAU,mBAAoBU,CAAQ,EACtCV,EAAA,UAAU,cAAeW,CAAG,EAC5BX,EAAA,UAAU,yBAA0BY,CAAc,EAClDZ,EAAA,OAAO,iBAAiB,UAAYrE,EACpCqE,EAAA,OAAO,iBAAiB,iBAAmBI,CAAA,CAEnD,EAiBaS,EAAmBH,EASnBI,EAAcH,EASdI,EAAyBH","x_google_ignoreList":[1]}
@@ -1,6 +1,6 @@
1
1
  var M = Object.defineProperty;
2
2
  var B = (e, t, r) => t in e ? M(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var p = (e, t, r) => B(e, typeof t != "symbol" ? t + "" : t, r);
3
+ var m = (e, t, r) => B(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { ref as G, computed as L, watch as k, onScopeDispose as A, toValue as d, defineComponent as S, toRef as u, renderSlot as R, unref as g } from "vue";
5
5
  import { GraffitiSynchronize as C } from "@graffiti-garden/wrapper-synchronize";
6
6
  const b = {};
@@ -30,7 +30,7 @@ var J = class _ extends Error {
30
30
  };
31
31
  class U {
32
32
  constructor(t) {
33
- p(this, "poll", async (t) => {
33
+ m(this, "poll", async (t) => {
34
34
  let r;
35
35
  const o = this.getter;
36
36
  try {
@@ -48,9 +48,9 @@ class U {
48
48
  }
49
49
  class O {
50
50
  constructor(t) {
51
- p(this, "iterator");
52
- p(this, "continue");
53
- p(this, "poll", async (t) => {
51
+ m(this, "iterator");
52
+ m(this, "continue");
53
+ m(this, "poll", async (t) => {
54
54
  if (!this.iterator)
55
55
  if (this.continue)
56
56
  try {
@@ -67,7 +67,7 @@ class O {
67
67
  const r = this.iterator, o = await r.next();
68
68
  if (r === this.iterator) {
69
69
  if (o.done) {
70
- o.value && (this.iterator = void 0, this.continue = o.value.continue);
70
+ this.iterator = void 0, o.value && (this.continue = o.value.continue);
71
71
  break;
72
72
  }
73
73
  if (o.value.error) {
@@ -96,7 +96,7 @@ function z(e, t) {
96
96
  }
97
97
  class V {
98
98
  constructor() {
99
- p(this, "entry", G());
99
+ m(this, "entry", G());
100
100
  }
101
101
  get result() {
102
102
  return L(() => {
@@ -117,9 +117,9 @@ class V {
117
117
  }
118
118
  class T {
119
119
  constructor(t) {
120
- p(this, "results", G([]));
121
- p(this, "resultsRaw", /* @__PURE__ */ new Map());
122
- p(this, "batchFlattenTimer");
120
+ m(this, "results", G([]));
121
+ m(this, "resultsRaw", /* @__PURE__ */ new Map());
122
+ m(this, "batchFlattenTimer");
123
123
  this.graffiti = t;
124
124
  }
125
125
  clear() {
@@ -152,30 +152,32 @@ function E(e, t, r, o, n) {
152
152
  e.onEntry(c);
153
153
  }
154
154
  }
155
- let f = !1, a;
156
- const l = async () => {
157
- if (f || !a) return;
158
- const c = a;
155
+ let f = !1, l;
156
+ const a = async () => {
157
+ if (f || !l) return;
158
+ const c = l;
159
159
  f = !0;
160
160
  try {
161
161
  await c();
162
+ } catch {
163
+ await new Promise((v) => setTimeout(v, 2e3));
162
164
  } finally {
163
- if (c !== a) return;
164
- f = !1, d(n) && l();
165
+ if (c !== l) return;
166
+ f = !1, d(n) && a();
165
167
  }
166
168
  }, h = G(!1);
167
169
  return k(
168
170
  o,
169
- async (c, m) => {
170
- if (JSON.stringify(c) === JSON.stringify(m))
171
+ async (c, p) => {
172
+ if (JSON.stringify(c) === JSON.stringify(p))
171
173
  return;
172
- i == null || i.return(null), e.clear(), t.clear(), s(), a = () => t.poll(e.onEntry.bind(e));
173
- const y = a;
174
+ i == null || i.return(null), e.clear(), t.clear(), s(), l = () => t.poll(e.onEntry.bind(e));
175
+ const v = l;
174
176
  f = !1, h.value = !0;
175
177
  try {
176
- await l();
178
+ await a();
177
179
  } finally {
178
- if (y !== a) return;
180
+ if (v !== l) return;
179
181
  h.value = !1;
180
182
  }
181
183
  },
@@ -183,8 +185,8 @@ function E(e, t, r, o, n) {
183
185
  immediate: !0
184
186
  }
185
187
  ), A(() => {
186
- i == null || i.return(null), e.clear(), t.clear(), a = void 0;
187
- }), { poll: l, isInitialPolling: h };
188
+ i == null || i.return(null), e.clear(), t.clear(), l = void 0;
189
+ }), { poll: a, isInitialPolling: h };
188
190
  }
189
191
  function $(e, t) {
190
192
  return () => {
@@ -192,15 +194,15 @@ function $(e, t) {
192
194
  return r === void 0 ? e == null ? void 0 : e.value : r;
193
195
  };
194
196
  }
195
- function v(e) {
197
+ function y(e) {
196
198
  return e.map((t) => t());
197
199
  }
198
200
  function x(e, t, r, o = !1) {
199
- const n = w(), i = F(), s = () => d(e), f = () => d(t), a = $(i, r), l = [s, f, a], h = () => n.synchronizeDiscover(...v(l)), c = () => n.discover(...v(l)), m = new T(n), y = new O(c), { poll: P, isInitialPolling: j } = E(
200
- m,
201
- y,
201
+ const n = w(), i = F(), s = () => d(e), f = () => d(t), l = $(i, r), a = [s, f, l], h = () => n.synchronizeDiscover(...y(a)), c = () => n.discover(...y(a)), p = new T(n), v = new O(c), { poll: P, isInitialPolling: j } = E(
202
+ p,
203
+ v,
202
204
  h,
203
- l,
205
+ a,
204
206
  o
205
207
  );
206
208
  return {
@@ -208,7 +210,7 @@ function x(e, t, r, o = !1) {
208
210
  * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
209
211
  * an array of Graffiti objects.
210
212
  */
211
- objects: m.results,
213
+ objects: p.results,
212
214
  /**
213
215
  * A method to poll for new results.
214
216
  */
@@ -226,15 +228,15 @@ function x(e, t, r, o = !1) {
226
228
  };
227
229
  }
228
230
  function W(e, t, r, o = !1) {
229
- const n = w(), i = F(), s = () => d(e), f = () => d(t), a = $(i, r), l = [
231
+ const n = w(), i = F(), s = () => d(e), f = () => d(t), l = $(i, r), a = [
230
232
  s,
231
233
  f,
232
- a
233
- ], h = () => n.synchronizeGet(...v(l)), c = new V(), m = () => n.get(...v(l)), y = new U(m), { poll: P, isInitialPolling: j } = E(
234
+ l
235
+ ], h = () => n.synchronizeGet(...y(a)), c = new V(), p = () => n.get(...y(a)), v = new U(p), { poll: P, isInitialPolling: j } = E(
234
236
  c,
235
- y,
237
+ v,
236
238
  h,
237
- l,
239
+ a,
238
240
  o
239
241
  );
240
242
  return {
@@ -261,8 +263,8 @@ function W(e, t, r, o = !1) {
261
263
  };
262
264
  }
263
265
  function q(e, t, r = !1) {
264
- const o = w(), s = [() => d(e), () => d(t)], f = () => o.synchronizeRecoverOrphans(...v(s)), a = new T(o), l = () => o.recoverOrphans(...v(s)), h = new O(l), { poll: c, isInitialPolling: m } = E(
265
- a,
266
+ const o = w(), s = [() => d(e), () => d(t)], f = () => o.synchronizeRecoverOrphans(...y(s)), l = new T(o), a = () => o.recoverOrphans(...y(s)), h = new O(a), { poll: c, isInitialPolling: p } = E(
267
+ l,
266
268
  h,
267
269
  f,
268
270
  s,
@@ -273,7 +275,7 @@ function q(e, t, r = !1) {
273
275
  * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
274
276
  * an array of Graffiti objects.
275
277
  */
276
- objects: a.results,
278
+ objects: l.results,
277
279
  /**
278
280
  * A method to poll for new results.
279
281
  */
@@ -287,7 +289,7 @@ function q(e, t, r = !1) {
287
289
  * but it does not track ongoing polls from either calling
288
290
  * {@link poll} or using the `autopoll` argument.
289
291
  */
290
- isInitialPolling: m
292
+ isInitialPolling: p
291
293
  };
292
294
  }
293
295
  const D = /* @__PURE__ */ S({
@@ -359,8 +361,8 @@ const D = /* @__PURE__ */ S({
359
361
  if (s && s.error && console.error(s.error), s && s.href) {
360
362
  const f = e.config.globalProperties.$router;
361
363
  if (f) {
362
- const a = f.options.history.base, l = new URL(s.href);
363
- l.pathname.startsWith(a) && (l.pathname = l.pathname.slice(a.length)), await f.replace(l.pathname + l.search + l.hash);
364
+ const l = f.options.history.base, a = new URL(s.href);
365
+ a.pathname.startsWith(l) && (a.pathname = a.pathname.slice(l.length)), await f.replace(a.pathname + a.search + a.hash);
364
366
  }
365
367
  }
366
368
  n.value || (n.value = null);