@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.
- package/dist/browser/plugin.mjs +3 -1
- package/dist/browser/plugin.mjs.map +1 -1
- package/dist/node/composables.d.ts.map +1 -1
- package/dist/node/plugin.js +1 -1
- package/dist/node/plugin.js.map +1 -1
- package/dist/node/plugin.mjs +43 -41
- package/dist/node/plugin.mjs.map +1 -1
- package/package.json +1 -1
- package/src/composables.ts +4 -0
- package/src/pollers.ts +1 -1
package/dist/node/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","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","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AgB,QAAQ;AAAA,IAC1B,CACD,GACDxE,EAAS,cAAc,iBAAiB,SAAS,CAACyE,MAAQ;AACxD,YAAMC,IAAUD,EAA2B;AAC3C,UAAIC,EAAO,OAAO;AAChB,gBAAQ,MAAM,mBAAmB,GACzB,QAAA,MAAMA,EAAO,KAAK;AAC1B;AAAA,MAAA;AAEA,QAAAF,EAAgB,QAAQE,EAAO;AAAA,IACjC,CACD,GACD1E,EAAS,cAAc,iBAAiB,UAAU,CAACyE,MAAQ;AACzD,YAAMC,IAAUD,EAA4B;AAC5C,MAAIC,EAAO,SACT,QAAQ,MAAM,oBAAoB,GAC1B,QAAA,MAAMA,EAAO,KAAK,KAE1BF,EAAgB,QAAQ;AAAA,IAC1B,CACD,GAED1E,EAAQ,sBAAsBE,GAC9BF,EAAQ,kBAAkB0E,GAEtBJ,EAAA,UAAU,oBAAoBU,CAAQ,GACtCV,EAAA,UAAU,eAAeW,CAAG,GAC5BX,EAAA,UAAU,0BAA0BY,CAAc,GAClDZ,EAAA,OAAO,iBAAiB,YAAYpE,GACpCoE,EAAA,OAAO,iBAAiB,mBAAmBI;AAAA,EAAA;AAEnD,GAiBaS,IAAmBH,GASnBI,KAAcH,GASdI,KAAyBH;","x_google_ignoreList":[1]}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","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":";;;;;AAIO,MAAMA,IAGT,CAAC;AAOE,SAASC,IAAyB;AACvC,QAAMC,IAAWF,EAAQ;AACzB,MAAI,CAACE;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;AAeO,SAASC,IAAwB;AACtC,SAAOF,EAAuB;AAChC;AAkBO,SAASG,IAAqB;AACnC,QAAMC,IAAUL,EAAQ;AACxB,MAAI,CAACK;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;ACjEkX,IAA8PC,IAAE,MAAMC,UAAU,MAAK;AAAA,EAAC,YAAYC,GAAE;AAAC,UAAMA,CAAC,GAAE,KAAK,OAAK,yBAAwB,OAAO,eAAe,MAAKD,EAAE,SAAS;AAAA,EAAC;AAAC;ACuBnuB,MAAME,EAA+D;AAAA,EAC1E,YAAqBC,GAA+C;AAEpE,IAAAC,EAAA,cAA+B,OAAOC,MAAY;AAC5C,UAAAC;AACJ,YAAMC,IAAW,KAAK;AAClB,UAAA;AACF,QAAAD,IAAS,MAAMC,EAAS;AAAA,cACd;AACN,QAAA,KAAK,WAAWA,KAClBF,EAAQ,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GAiBaS,IAAmBH,GASnBI,KAAcH,GASdI,KAAyBH;","x_google_ignoreList":[1]}
|
package/package.json
CHANGED
package/src/composables.ts
CHANGED
|
@@ -43,6 +43,10 @@ function makeComposable<Schema extends JSONSchema>(
|
|
|
43
43
|
isAlreadyPolling = true;
|
|
44
44
|
try {
|
|
45
45
|
await myPoll();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
// If there is an error, wait a little bit so as not to
|
|
48
|
+
// cause an infinite loop
|
|
49
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
46
50
|
} finally {
|
|
47
51
|
if (myPoll !== innerPoll) return;
|
|
48
52
|
isAlreadyPolling = false;
|
package/src/pollers.ts
CHANGED
|
@@ -101,8 +101,8 @@ export class StreamPoller<Schema extends JSONSchema> implements Poller<Schema> {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if (result.done) {
|
|
104
|
+
this.iterator = undefined;
|
|
104
105
|
if (result.value) {
|
|
105
|
-
this.iterator = undefined;
|
|
106
106
|
this.continue = result.value.continue;
|
|
107
107
|
}
|
|
108
108
|
break;
|