@graffiti-garden/wrapper-vue 0.6.2 → 0.6.3
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.
- package/dist/browser/plugin.mjs +211 -208
- package/dist/browser/plugin.mjs.map +1 -1
- package/dist/node/plugin.js +1 -1
- package/dist/node/plugin.js.map +1 -1
- package/dist/node/plugin.mjs +57 -54
- package/dist/node/plugin.mjs.map +1 -1
- package/dist/node/pollers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/pollers.ts +25 -12
package/dist/node/plugin.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var V=Object.defineProperty;var $=(t,e,
|
|
1
|
+
"use strict";var V=Object.defineProperty;var $=(t,e,s)=>e in t?V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var f=(t,e,s)=>$(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),M=require("@graffiti-garden/wrapper-synchronize"),w=Symbol(),R=Symbol();function p(){const t=r.inject(w);if(!t)throw new Error("No Graffiti instance provided, did you forget to install the plugin?");return t}function N(){return p()}function y(){const t=r.inject(R);if(!t)throw new Error("No Graffiti session provided, did you forget to install the plugin?");return t}class C{constructor(e){f(this,"poll",async e=>{let s;const o=this.getter;try{s=await o()}catch{this.getter===o&&e(null);return}this.getter===o&&e({object:s})});this.getter=e}clear(){}}class S{constructor(e){f(this,"iterator");f(this,"continue");f(this,"poll",async e=>{for(this.iterator||(this.continue?this.iterator=this.continue():this.iterator=this.streamFactory());this.iterator;){const s=this.iterator,o=await s.next();if(s===this.iterator){if(o.done){o.value&&(this.iterator=void 0,this.continue=o.value.continue);break}if(o.value.error){console.error(o.value.error);continue}e(o.value)}}});this.streamFactory=e}clear(){if(this.iterator){const e=this.iterator;this.iterator.return({continue:()=>e,cursor:""})}this.iterator=void 0,this.continue=void 0}}function P(t,e){return!e||t.object.lastModified>e.object.lastModified||t.object.lastModified===e.object.lastModified&&!t.tombstone&&!!e.tombstone}class L{constructor(){f(this,"entry",r.ref())}get result(){return r.computed(()=>{const e=this.entry.value;return e&&(e.tombstone?null:e.object)})}clear(){this.entry.value=void 0}onEntry(e){(!e||P(e,this.entry.value))&&(this.entry.value=e)}}class _{constructor(e){f(this,"results",r.ref([]));f(this,"resultsRaw",new Map);f(this,"batchFlattenTimer");this.graffiti=e}clear(){this.resultsRaw.clear(),this.results.value=[],clearTimeout(this.batchFlattenTimer),this.batchFlattenTimer=void 0}flattenResults(){this.results.value=Array.from(this.resultsRaw.values()).reduce((e,s)=>(s.tombstone||e.push(s.object),e),[])}onEntry(e){if(!e)return;const s=this.resultsRaw.get(e.object.url);P(e,s)&&(this.resultsRaw.set(e.object.url,e),this.batchFlattenTimer||(this.batchFlattenTimer=setTimeout(()=>{this.flattenResults(),this.batchFlattenTimer=void 0},0)))}}function b(t,e,s,o){let i;async function l(){i=s();for await(const a of i){if(a.error){console.error(a.error);continue}t.onEntry(a)}}const n=()=>e.poll(t.onEntry.bind(t)),c=r.ref(!1);return r.watch(o,async(a,u)=>{if(JSON.stringify(a)!==JSON.stringify(u)){i==null||i.return(null),t.clear(),e.clear(),l(),c.value=!0;try{await n()}finally{c.value=!1}}},{immediate:!0}),r.onScopeDispose(()=>i==null?void 0:i.return(null)),{poll:n,isPolling:c}}function E(t,e){return()=>{const s=r.toValue(e);return s===void 0?t==null?void 0:t.value:s}}function d(t){return t.map(e=>e())}function F(t,e,s){const o=p(),i=y(),l=()=>r.toValue(t),n=()=>r.toValue(e),c=E(i,s),a=[l,n,c],u=()=>o.synchronizeDiscover(...d(a)),h=()=>o.discover(...d(a)),g=new _(o),v=new S(h),{poll:m,isPolling:G}=b(g,v,u,a);return{results:g.results,poll:m,isPolling:G}}function j(t,e,s){const o=p(),i=y(),l=()=>r.toValue(t),n=()=>r.toValue(e),c=E(i,s),a=[l,n,c],u=()=>o.synchronizeGet(...d(a)),h=new L,g=()=>o.get(...d(a)),v=new C(g),{poll:m,isPolling:G}=b(h,v,u,a);return{result:h.result,poll:m,isPolling:G}}function O(t,e){const s=p(),l=[()=>r.toValue(t),()=>r.toValue(e)],n=()=>s.synchronizeRecoverOrphans(...d(l)),c=new _(s),a=()=>s.recoverOrphans(...d(l)),u=new S(a),{poll:h,isPolling:g}=b(c,u,n,l);return{results:c.results,poll:h,isPolling:g}}const z=r.defineComponent({__name:"Discover",props:{channels:{},schema:{},session:{}},setup(t){const e=t,{results:s,poll:o,isPolling:i}=F(r.toRef(e,"channels"),r.toRef(e,"schema"),r.toRef(e,"session"));return(l,n)=>r.renderSlot(l.$slots,"default",{results:r.unref(s),poll:r.unref(o),isPolling:r.unref(i)})}}),T=r.defineComponent({__name:"Get",props:{url:{},schema:{},session:{}},setup(t){const e=t,{result:s,poll:o,isPolling:i}=j(r.toRef(e,"url"),r.toRef(e,"schema"),r.toRef(e,"session"));return(l,n)=>r.renderSlot(l.$slots,"default",{result:r.unref(s),poll:r.unref(o),isPolling:r.unref(i)})}}),D=r.defineComponent({__name:"RecoverOrphans",props:{schema:{},session:{}},setup(t){const e=t,{results:s,poll:o,isPolling:i}=O(r.toRef(e,"schema"),r.toRef(e,"session"));return(l,n)=>r.renderSlot(l.$slots,"default",{results:r.unref(s),poll:r.unref(o),isPolling:r.unref(i)})}}),k={install(t,e){const s=e.graffiti,o=new M.GraffitiSynchronize(s),i=r.ref(void 0);o.sessionEvents.addEventListener("initialized",async l=>{const n=l.detail;if(n&&n.error&&console.error(n.error),n&&n.href){const c=t.config.globalProperties.$router;if(c){const a=c.options.history.base,u=new URL(n.href);u.pathname.startsWith(a)&&(u.pathname=u.pathname.slice(a.length)),await c.replace(u.pathname+u.search+u.hash)}}i.value||(i.value=null)}),o.sessionEvents.addEventListener("login",l=>{const n=l.detail;if(n.error){console.error("Error logging in:"),console.error(n.error);return}else i.value=n.session}),o.sessionEvents.addEventListener("logout",l=>{const n=l.detail;n.error?(console.error("Error logging out:"),console.error(n.error)):i.value=null}),t.provide(w,o),t.provide(R,i),t.component("GraffitiDiscover",z),t.component("GraffitiGet",T),t.component("GraffitiRecoverOrphans",D),t.config.globalProperties.$graffiti=o,t.config.globalProperties.$graffitiSession=i}},q=z,A=T,J=D;exports.GraffitiDiscover=q;exports.GraffitiGet=A;exports.GraffitiPlugin=k;exports.GraffitiRecoverOrphans=J;exports.useGraffiti=N;exports.useGraffitiDiscover=F;exports.useGraffitiGet=j;exports.useGraffitiRecoverOrphans=O;exports.useGraffitiSession=y;exports.useGraffitiSynchronize=p;
|
|
2
2
|
//# sourceMappingURL=plugin.js.map
|
package/dist/node/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/globals.ts","../../src/pollers.ts","../../src/reducers.ts","../../src/composables.ts","../../src/Discover.vue","../../src/Get.vue","../../src/RecoverOrphans.vue","../../src/plugin.ts"],"sourcesContent":["import { inject } from \"vue\";\nimport type { InjectionKey, Ref } from \"vue\";\nimport type { Graffiti, GraffitiSession } from \"@graffiti-garden/api\";\nimport type { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\nexport const graffitiInjectKey = Symbol() as InjectionKey<GraffitiSynchronize>;\nexport const graffitiSessionInjectKey = Symbol() as InjectionKey<\n 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 = inject(graffitiInjectKey);\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 = inject(graffitiSessionInjectKey);\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","import type {\n Graffiti,\n JSONSchema,\n GraffitiObject,\n GraffitiObjectStreamReturn,\n GraffitiObjectStreamContinueEntry,\n GraffitiObjectStream,\n GraffitiObjectStreamContinue,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Poller<Schema extends JSONSchema> {\n abstract poll(\n onEntry: (entry: GraffitiObjectStreamContinueEntry<Schema> | null) => 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 try {\n object = await this.getter();\n } catch (e) {\n onEntry(null);\n return;\n }\n onEntry({ object });\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 this.iterator = this.continue();\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 result = await this.iterator.next();\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,\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) {\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) {\n if (!entry) return;\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) {\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 const poll = () => poller.poll(reducer.onEntry.bind(reducer));\n\n const isPolling = 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 isPolling.value = true;\n try {\n await poll();\n } finally {\n isPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => synchronizeIterator?.return(null));\n\n return { poll, isPolling };\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): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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): {\n result: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\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 result: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiDiscover<Schema>(\n toRef(props, \"channels\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></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}>();\n\ndefineSlots<{\n default?(props: {\n result: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { result, poll, isPolling } = useGraffitiGet<Schema>(\n toRef(props, \"url\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :result=\"result\" :poll=\"poll\" :isPolling=\"isPolling\"></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}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiRecoverOrphans<Schema>(\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></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 { graffitiInjectKey, graffitiSessionInjectKey } 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 app.provide(graffitiInjectKey, graffiti);\n app.provide(graffitiSessionInjectKey, 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":["graffitiInjectKey","graffitiSessionInjectKey","useGraffitiSynchronize","graffiti","inject","useGraffiti","useGraffitiSession","session","GetPoller","getter","__publicField","onEntry","object","StreamPoller","streamFactory","result","iterator","isEntryNewer","entry","existing","SingletonReducer","ref","computed","value","ArrayReducer","acc","makeComposable","reducer","poller","synchronizeFactory","toWatch","synchronizeIterator","pollSynchronize","poll","isPolling","watch","newValue","oldValue","onScopeDispose","toSessionGetter","sessionInjected","sessionValue","toValue","callGetters","getters","fn","useGraffitiDiscover","channels","schema","channelsGetter","schemaGetter","sessionGetter","argGetters","useGraffitiGet","locationOrUri","locationOrUriGetter","useGraffitiRecoverOrphans","props","__props","results","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":"6TAKaA,EAAoB,OAAO,EAC3BC,EAA2B,OAAO,EASxC,SAASC,GAAyB,CACjC,MAAAC,EAAWC,SAAOJ,CAAiB,EACzC,GAAI,CAACG,EACH,MAAM,IAAI,MACR,sEACF,EAEK,OAAAA,CACT,CAeO,SAASE,GAAwB,CACtC,OAAOH,EAAuB,CAChC,CAkBO,SAASI,GAAqB,CAC7B,MAAAC,EAAUH,SAAOH,CAAwB,EAC/C,GAAI,CAACM,EACH,MAAM,IAAI,MACR,qEACF,EAEK,OAAAA,CACT,CC9CO,MAAMC,CAA+D,CAC1E,YAAqBC,EAA+C,CAEpEC,EAAA,YAA+B,MAAOC,GAAY,CAC5C,IAAAC,EACA,GAAA,CACOA,EAAA,MAAM,KAAK,OAAO,OACjB,CACVD,EAAQ,IAAI,EACZ,MAAA,CAEMA,EAAA,CAAE,OAAAC,EAAQ,CACpB,GAXqB,KAAA,OAAAH,CAAA,CAarB,OAAQ,CAAA,CACV,CAOO,MAAMI,CAAkE,CAI7E,YAAqBC,EAAmD,CAHxEJ,EAAA,iBACAA,EAAA,iBAgBAA,EAAA,YAA+B,MAAOC,GAAY,CAShD,IARK,KAAK,WACJ,KAAK,SACF,KAAA,SAAW,KAAK,SAAS,EAEzB,KAAA,SAAW,KAAK,cAAc,GAMhC,KAAK,UAFC,CAMX,MAAMI,EAAS,MAAM,KAAK,SAAS,KAAK,EAExC,GAAIA,EAAO,KAAM,CACXA,EAAO,QACT,KAAK,SAAW,OACX,KAAA,SAAWA,EAAO,MAAM,UAE/B,KAAA,CAGE,GAAAA,EAAO,MAAM,MAAO,CACd,QAAA,MAAMA,EAAO,MAAM,KAAK,EAChC,QAAA,CAGFJ,EAAQI,EAAO,KAAK,CAAA,CAExB,GA9CqB,KAAA,cAAAD,CAAA,CAErB,OAAQ,CACN,GAAI,KAAK,SAAU,CACjB,MAAME,EAAW,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AAUA,EAAO,KAAM,CAEnB,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,EACD/D,EAAS,cAAc,iBAAiB,QAAUgE,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,EACDjE,EAAS,cAAc,iBAAiB,SAAWgE,GAAQ,CACzD,MAAMC,EAAUD,EAA4B,OACxCC,EAAO,OACT,QAAQ,MAAM,oBAAoB,EAC1B,QAAA,MAAMA,EAAO,KAAK,GAE1BF,EAAgB,MAAQ,IAC1B,CACD,EAEGJ,EAAA,QAAQ9D,EAAmBG,CAAQ,EACnC2D,EAAA,QAAQ7D,EAA0BiE,CAAe,EAEjDJ,EAAA,UAAU,mBAAoBU,CAAQ,EACtCV,EAAA,UAAU,cAAeW,CAAG,EAC5BX,EAAA,UAAU,yBAA0BY,CAAc,EAClDZ,EAAA,OAAO,iBAAiB,UAAY3D,EACpC2D,EAAA,OAAO,iBAAiB,iBAAmBI,CAAA,CAEnD,EAiBaS,EAAmBH,EASnBI,EAAcH,EASdI,EAAyBH"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/globals.ts","../../src/pollers.ts","../../src/reducers.ts","../../src/composables.ts","../../src/Discover.vue","../../src/Get.vue","../../src/RecoverOrphans.vue","../../src/plugin.ts"],"sourcesContent":["import { inject } from \"vue\";\nimport type { InjectionKey, Ref } from \"vue\";\nimport type { Graffiti, GraffitiSession } from \"@graffiti-garden/api\";\nimport type { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\nexport const graffitiInjectKey = Symbol() as InjectionKey<GraffitiSynchronize>;\nexport const graffitiSessionInjectKey = Symbol() as InjectionKey<\n 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 = inject(graffitiInjectKey);\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 = inject(graffitiSessionInjectKey);\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","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: (entry: GraffitiObjectStreamContinueEntry<Schema> | null) => 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 this.iterator = this.continue();\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,\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) {\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) {\n if (!entry) return;\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) {\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 const poll = () => poller.poll(reducer.onEntry.bind(reducer));\n\n const isPolling = 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 isPolling.value = true;\n try {\n await poll();\n } finally {\n isPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => synchronizeIterator?.return(null));\n\n return { poll, isPolling };\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): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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): {\n result: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\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 result: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: 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, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: 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 poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\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}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiDiscover<Schema>(\n toRef(props, \"channels\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></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}>();\n\ndefineSlots<{\n default?(props: {\n result: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { result, poll, isPolling } = useGraffitiGet<Schema>(\n toRef(props, \"url\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :result=\"result\" :poll=\"poll\" :isPolling=\"isPolling\"></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}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiRecoverOrphans<Schema>(\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></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 { graffitiInjectKey, graffitiSessionInjectKey } 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 app.provide(graffitiInjectKey, graffiti);\n app.provide(graffitiSessionInjectKey, 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":["graffitiInjectKey","graffitiSessionInjectKey","useGraffitiSynchronize","graffiti","inject","useGraffiti","useGraffitiSession","session","GetPoller","getter","__publicField","onEntry","object","myGetter","StreamPoller","streamFactory","myIterator","result","iterator","isEntryNewer","entry","existing","SingletonReducer","ref","computed","value","ArrayReducer","acc","makeComposable","reducer","poller","synchronizeFactory","toWatch","synchronizeIterator","pollSynchronize","poll","isPolling","watch","newValue","oldValue","onScopeDispose","toSessionGetter","sessionInjected","sessionValue","toValue","callGetters","getters","fn","useGraffitiDiscover","channels","schema","channelsGetter","schemaGetter","sessionGetter","argGetters","useGraffitiGet","locationOrUri","locationOrUriGetter","useGraffitiRecoverOrphans","props","__props","results","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":"6TAKaA,EAAoB,OAAO,EAC3BC,EAA2B,OAAO,EASxC,SAASC,GAAyB,CACjC,MAAAC,EAAWC,SAAOJ,CAAiB,EACzC,GAAI,CAACG,EACH,MAAM,IAAI,MACR,sEACF,EAEK,OAAAA,CACT,CAeO,SAASE,GAAwB,CACtC,OAAOH,EAAuB,CAChC,CAkBO,SAASI,GAAqB,CAC7B,MAAAC,EAAUH,SAAOH,CAAwB,EAC/C,GAAI,CAACM,EACH,MAAM,IAAI,MAC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,EAAI,SAAWA,EAAI,OAASA,EAAI,IAAI,CAAA,CAC3D,CAIGL,EAAgB,QACnBA,EAAgB,MAAQ,KAC1B,CACD,EACDjE,EAAS,cAAc,iBAAiB,QAAUkE,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,EACDnE,EAAS,cAAc,iBAAiB,SAAWkE,GAAQ,CACzD,MAAMC,EAAUD,EAA4B,OACxCC,EAAO,OACT,QAAQ,MAAM,oBAAoB,EAC1B,QAAA,MAAMA,EAAO,KAAK,GAE1BF,EAAgB,MAAQ,IAC1B,CACD,EAEGJ,EAAA,QAAQhE,EAAmBG,CAAQ,EACnC6D,EAAA,QAAQ/D,EAA0BmE,CAAe,EAEjDJ,EAAA,UAAU,mBAAoBU,CAAQ,EACtCV,EAAA,UAAU,cAAeW,CAAG,EAC5BX,EAAA,UAAU,yBAA0BY,CAAc,EAClDZ,EAAA,OAAO,iBAAiB,UAAY7D,EACpC6D,EAAA,OAAO,iBAAiB,iBAAmBI,CAAA,CAEnD,EAiBaS,EAAmBH,EASnBI,EAAcH,EASdI,EAAyBH"}
|
package/dist/node/plugin.mjs
CHANGED
|
@@ -27,13 +27,14 @@ class U {
|
|
|
27
27
|
constructor(t) {
|
|
28
28
|
u(this, "poll", async (t) => {
|
|
29
29
|
let r;
|
|
30
|
+
const s = this.getter;
|
|
30
31
|
try {
|
|
31
|
-
r = await
|
|
32
|
+
r = await s();
|
|
32
33
|
} catch {
|
|
33
|
-
t(null);
|
|
34
|
+
this.getter === s && t(null);
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
|
-
t({ object: r });
|
|
37
|
+
this.getter === s && t({ object: r });
|
|
37
38
|
});
|
|
38
39
|
this.getter = t;
|
|
39
40
|
}
|
|
@@ -46,16 +47,18 @@ class O {
|
|
|
46
47
|
u(this, "continue");
|
|
47
48
|
u(this, "poll", async (t) => {
|
|
48
49
|
for (this.iterator || (this.continue ? this.iterator = this.continue() : this.iterator = this.streamFactory()); this.iterator; ) {
|
|
49
|
-
const r =
|
|
50
|
-
if (r.
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const r = this.iterator, s = await r.next();
|
|
51
|
+
if (r === this.iterator) {
|
|
52
|
+
if (s.done) {
|
|
53
|
+
s.value && (this.iterator = void 0, this.continue = s.value.continue);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (s.value.error) {
|
|
57
|
+
console.error(s.value.error);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
t(s.value);
|
|
53
61
|
}
|
|
54
|
-
if (r.value.error) {
|
|
55
|
-
console.error(r.value.error);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
t(r.value);
|
|
59
62
|
}
|
|
60
63
|
});
|
|
61
64
|
this.streamFactory = t;
|
|
@@ -112,11 +115,11 @@ class $ {
|
|
|
112
115
|
}, 0)));
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
function S(e, t, r,
|
|
116
|
-
let
|
|
118
|
+
function S(e, t, r, s) {
|
|
119
|
+
let o;
|
|
117
120
|
async function i() {
|
|
118
|
-
|
|
119
|
-
for await (const l of
|
|
121
|
+
o = r();
|
|
122
|
+
for await (const l of o) {
|
|
120
123
|
if (l.error) {
|
|
121
124
|
console.error(l.error);
|
|
122
125
|
continue;
|
|
@@ -124,14 +127,14 @@ function S(e, t, r, n) {
|
|
|
124
127
|
e.onEntry(l);
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
|
-
const
|
|
130
|
+
const n = () => t.poll(e.onEntry.bind(e)), c = v(!1);
|
|
128
131
|
return C(
|
|
129
|
-
|
|
132
|
+
s,
|
|
130
133
|
async (l, a) => {
|
|
131
134
|
if (JSON.stringify(l) !== JSON.stringify(a)) {
|
|
132
|
-
|
|
135
|
+
o == null || o.return(null), e.clear(), t.clear(), i(), c.value = !0;
|
|
133
136
|
try {
|
|
134
|
-
await
|
|
137
|
+
await n();
|
|
135
138
|
} finally {
|
|
136
139
|
c.value = !1;
|
|
137
140
|
}
|
|
@@ -140,7 +143,7 @@ function S(e, t, r, n) {
|
|
|
140
143
|
{
|
|
141
144
|
immediate: !0
|
|
142
145
|
}
|
|
143
|
-
), J(() =>
|
|
146
|
+
), J(() => o == null ? void 0 : o.return(null)), { poll: n, isPolling: c };
|
|
144
147
|
}
|
|
145
148
|
function z(e, t) {
|
|
146
149
|
return () => {
|
|
@@ -152,7 +155,7 @@ function d(e) {
|
|
|
152
155
|
return e.map((t) => t());
|
|
153
156
|
}
|
|
154
157
|
function B(e, t, r) {
|
|
155
|
-
const
|
|
158
|
+
const s = G(), o = j(), i = () => m(e), n = () => m(t), c = z(o, r), l = [i, n, c], a = () => s.synchronizeDiscover(...d(l)), g = () => s.discover(...d(l)), p = new $(s), y = new O(g), { poll: b, isPolling: w } = S(
|
|
156
159
|
p,
|
|
157
160
|
y,
|
|
158
161
|
a,
|
|
@@ -177,11 +180,11 @@ function B(e, t, r) {
|
|
|
177
180
|
};
|
|
178
181
|
}
|
|
179
182
|
function W(e, t, r) {
|
|
180
|
-
const
|
|
183
|
+
const s = G(), o = j(), i = () => m(e), n = () => m(t), c = z(o, r), l = [
|
|
181
184
|
i,
|
|
182
|
-
|
|
185
|
+
n,
|
|
183
186
|
c
|
|
184
|
-
], a = () =>
|
|
187
|
+
], a = () => s.synchronizeGet(...d(l)), g = new V(), p = () => s.get(...d(l)), y = new U(p), { poll: b, isPolling: w } = S(
|
|
185
188
|
g,
|
|
186
189
|
y,
|
|
187
190
|
a,
|
|
@@ -207,10 +210,10 @@ function W(e, t, r) {
|
|
|
207
210
|
};
|
|
208
211
|
}
|
|
209
212
|
function q(e, t) {
|
|
210
|
-
const r = G(), i = [() => m(e), () => m(t)],
|
|
213
|
+
const r = G(), i = [() => m(e), () => m(t)], n = () => r.synchronizeRecoverOrphans(...d(i)), c = new $(r), l = () => r.recoverOrphans(...d(i)), a = new O(l), { poll: g, isPolling: p } = S(
|
|
211
214
|
c,
|
|
212
215
|
a,
|
|
213
|
-
|
|
216
|
+
n,
|
|
214
217
|
i
|
|
215
218
|
);
|
|
216
219
|
return {
|
|
@@ -239,15 +242,15 @@ const D = /* @__PURE__ */ P({
|
|
|
239
242
|
session: {}
|
|
240
243
|
},
|
|
241
244
|
setup(e) {
|
|
242
|
-
const t = e, { results: r, poll:
|
|
245
|
+
const t = e, { results: r, poll: s, isPolling: o } = B(
|
|
243
246
|
h(t, "channels"),
|
|
244
247
|
h(t, "schema"),
|
|
245
248
|
h(t, "session")
|
|
246
249
|
);
|
|
247
|
-
return (i,
|
|
250
|
+
return (i, n) => R(i.$slots, "default", {
|
|
248
251
|
results: f(r),
|
|
249
|
-
poll: f(
|
|
250
|
-
isPolling: f(
|
|
252
|
+
poll: f(s),
|
|
253
|
+
isPolling: f(o)
|
|
251
254
|
});
|
|
252
255
|
}
|
|
253
256
|
}), M = /* @__PURE__ */ P({
|
|
@@ -258,15 +261,15 @@ const D = /* @__PURE__ */ P({
|
|
|
258
261
|
session: {}
|
|
259
262
|
},
|
|
260
263
|
setup(e) {
|
|
261
|
-
const t = e, { result: r, poll:
|
|
264
|
+
const t = e, { result: r, poll: s, isPolling: o } = W(
|
|
262
265
|
h(t, "url"),
|
|
263
266
|
h(t, "schema"),
|
|
264
267
|
h(t, "session")
|
|
265
268
|
);
|
|
266
|
-
return (i,
|
|
269
|
+
return (i, n) => R(i.$slots, "default", {
|
|
267
270
|
result: f(r),
|
|
268
|
-
poll: f(
|
|
269
|
-
isPolling: f(
|
|
271
|
+
poll: f(s),
|
|
272
|
+
isPolling: f(o)
|
|
270
273
|
});
|
|
271
274
|
}
|
|
272
275
|
}), N = /* @__PURE__ */ P({
|
|
@@ -276,40 +279,40 @@ const D = /* @__PURE__ */ P({
|
|
|
276
279
|
session: {}
|
|
277
280
|
},
|
|
278
281
|
setup(e) {
|
|
279
|
-
const t = e, { results: r, poll:
|
|
282
|
+
const t = e, { results: r, poll: s, isPolling: o } = q(
|
|
280
283
|
h(t, "schema"),
|
|
281
284
|
h(t, "session")
|
|
282
285
|
);
|
|
283
|
-
return (i,
|
|
286
|
+
return (i, n) => R(i.$slots, "default", {
|
|
284
287
|
results: f(r),
|
|
285
|
-
poll: f(
|
|
286
|
-
isPolling: f(
|
|
288
|
+
poll: f(s),
|
|
289
|
+
isPolling: f(o)
|
|
287
290
|
});
|
|
288
291
|
}
|
|
289
292
|
}), Y = {
|
|
290
293
|
install(e, t) {
|
|
291
|
-
const r = t.graffiti,
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
294
|
+
const r = t.graffiti, s = new K(r), o = v(void 0);
|
|
295
|
+
s.sessionEvents.addEventListener("initialized", async (i) => {
|
|
296
|
+
const n = i.detail;
|
|
297
|
+
if (n && n.error && console.error(n.error), n && n.href) {
|
|
295
298
|
const c = e.config.globalProperties.$router;
|
|
296
299
|
if (c) {
|
|
297
|
-
const l = c.options.history.base, a = new URL(
|
|
300
|
+
const l = c.options.history.base, a = new URL(n.href);
|
|
298
301
|
a.pathname.startsWith(l) && (a.pathname = a.pathname.slice(l.length)), await c.replace(a.pathname + a.search + a.hash);
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
|
-
|
|
302
|
-
}),
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
console.error("Error logging in:"), console.error(
|
|
304
|
+
o.value || (o.value = null);
|
|
305
|
+
}), s.sessionEvents.addEventListener("login", (i) => {
|
|
306
|
+
const n = i.detail;
|
|
307
|
+
if (n.error) {
|
|
308
|
+
console.error("Error logging in:"), console.error(n.error);
|
|
306
309
|
return;
|
|
307
310
|
} else
|
|
308
|
-
|
|
309
|
-
}),
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
}), e.provide(E,
|
|
311
|
+
o.value = n.session;
|
|
312
|
+
}), s.sessionEvents.addEventListener("logout", (i) => {
|
|
313
|
+
const n = i.detail;
|
|
314
|
+
n.error ? (console.error("Error logging out:"), console.error(n.error)) : o.value = null;
|
|
315
|
+
}), e.provide(E, s), e.provide(F, o), e.component("GraffitiDiscover", D), e.component("GraffitiGet", M), e.component("GraffitiRecoverOrphans", N), e.config.globalProperties.$graffiti = s, e.config.globalProperties.$graffitiSession = o;
|
|
313
316
|
}
|
|
314
317
|
}, Z = D, I = M, tt = N;
|
|
315
318
|
export {
|