@graffiti-garden/wrapper-vue 0.6.4 → 0.6.5
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 +546 -461
- package/dist/browser/plugin.mjs.map +1 -1
- package/dist/node/Discover.vue.d.ts +5 -0
- package/dist/node/Discover.vue.d.ts.map +1 -1
- package/dist/node/Get.vue.d.ts +5 -0
- package/dist/node/Get.vue.d.ts.map +1 -1
- package/dist/node/RecoverOrphans.vue.d.ts +5 -0
- package/dist/node/RecoverOrphans.vue.d.ts.map +1 -1
- package/dist/node/composables.d.ts +9 -3
- package/dist/node/composables.d.ts.map +1 -1
- package/dist/node/plugin.d.ts +27 -0
- package/dist/node/plugin.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 +239 -154
- package/dist/node/plugin.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Discover.vue +17 -6
- package/src/Get.vue +17 -6
- package/src/RecoverOrphans.vue +16 -5
- package/src/composables.ts +116 -25
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 { 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","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) {\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","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","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":";;;;;AAKO,MAAMA,IAAoB,OAAO,GAC3BC,IAA2B,OAAO;AASxC,SAASC,IAAyB;AACjC,QAAAC,IAAWC,EAAOJ,CAAiB;AACzC,MAAI,CAACG;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;AAeO,SAASE,IAAwB;AACtC,SAAOH,EAAuB;AAChC;AAkBO,SAASI,IAAqB;AAC7B,QAAAC,IAAUH,EAAOH,CAAwB;AAC/C,MAAI,CAACM;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;AClEkX,IAA8PC,IAAE,MAAMC,UAAU,MAAK;AAAA,EAAC,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AMD,EAAO,QAAQE,EAAI,WAAWA,EAAI,SAASA,EAAI,IAAI;AAAA,QAAA;AAAA,MAC3D;AAIE,MAACL,EAAgB,UACnBA,EAAgB,QAAQ;AAAA,IAC1B,CACD,GACDrE,EAAS,cAAc,iBAAiB,SAAS,CAACsE,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,GACDvE,EAAS,cAAc,iBAAiB,UAAU,CAACsE,MAAQ;AACzD,YAAMC,IAAUD,EAA4B;AAC5C,MAAIC,EAAO,SACT,QAAQ,MAAM,oBAAoB,GAC1B,QAAA,MAAMA,EAAO,KAAK,KAE1BF,EAAgB,QAAQ;AAAA,IAC1B,CACD,GAEGJ,EAAA,QAAQpE,GAAmBG,CAAQ,GACnCiE,EAAA,QAAQnE,GAA0BuE,CAAe,GAEjDJ,EAAA,UAAU,oBAAoBU,CAAQ,GACtCV,EAAA,UAAU,eAAeW,CAAG,GAC5BX,EAAA,UAAU,0BAA0BY,CAAc,GAClDZ,EAAA,OAAO,iBAAiB,YAAYjE,GACpCiE,EAAA,OAAO,iBAAiB,mBAAmBI;AAAA,EAAA;AAEnD,GAiBaS,KAAmBH,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 { 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","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 const poll = async () => {\n if (isAlreadyPolling) return;\n isAlreadyPolling = true;\n try {\n await poller.poll(reducer.onEntry.bind(reducer));\n } finally {\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 isInitialPolling.value = true;\n try {\n await poll();\n } finally {\n isInitialPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => synchronizeIterator?.return(null));\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 results: Ref<GraffitiObject<Schema>[]>;\n objects: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\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 * @deprecated Use {@link objects} instead.\n */\n get results() {\n console.warn(\n \"The `results` property is deprecated. Use `objects` instead.\",\n );\n return this.objects;\n },\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 * @deprecated Use {@link isInitialPolling} instead.\n */\n get isPolling() {\n console.warn(\n \"The `isPolling` property is deprecated. Use `isInitialPolling` instead.\",\n );\n return this.isInitialPolling;\n },\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 result: Ref<GraffitiObject<Schema> | null | undefined>;\n object: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\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 * @deprecated Use {@link object} instead.\n */\n get result() {\n console.warn(\n \"The `result` property is deprecated. Use `object` instead.\",\n );\n return this.object;\n },\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 * @deprecated Use {@link isInitialPolling} instead.\n */\n get isPolling() {\n console.warn(\n \"The `isPolling` property is deprecated. Use `isInitialPolling` instead.\",\n );\n return this.isInitialPolling;\n },\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 results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\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 * @deprecated Use {@link objects} instead.\n */\n get results() {\n console.warn(\n \"The `result` property is deprecated. Use `object` instead.\",\n );\n return this.objects;\n },\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 * @deprecated Use {@link isInitialPolling} instead.\n */\n get isPolling() {\n console.warn(\n \"The `isPolling` property is deprecated. Use `isInitialPolling` instead.\",\n );\n return this.isInitialPolling;\n },\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 results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, results, poll, isPolling, isInitialPolling } =\n 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 :results=\"results\"\n :poll=\"poll\"\n :isPolling=\"isPolling\"\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 result: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isPolling: boolean;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { object, result, poll, isPolling, isInitialPolling } =\n 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 :result=\"result\"\n :poll=\"poll\"\n :isPolling=\"isPolling\"\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 results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n isInitialPolling: boolean;\n }): any;\n}>();\n\nconst { objects, results, poll, isPolling, isInitialPolling } =\n 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 :results=\"results\"\n :poll=\"poll\"\n :isPolling=\"isPolling\"\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 { 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","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","poll","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","results","isPolling","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":";;;;;AAKO,MAAMA,IAAoB,OAAO,GAC3BC,IAA2B,OAAO;AASxC,SAASC,IAAyB;AACjC,QAAAC,IAAWC,EAAOJ,CAAiB;AACzC,MAAI,CAACG;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;AAeO,SAASE,IAAwB;AACtC,SAAOH,EAAuB;AAChC;AAkBO,SAASI,IAAqB;AAC7B,QAAAC,IAAUH,EAAOH,CAAwB;AAC/C,MAAI,CAACM;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEK,SAAAA;AACT;AClEkX,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,IAAI;AAEd;AAAA,MAAA;AAEE,MAAA,KAAK,WAAWE,KACVF,EAAA,EAAE,QAAAC,GAAQ;AAAA,IAEtB;AAhBqB,SAAA,SAAAH;AAAA,EAAA;AAAA,EAkBrB,QAAQ;AAAA,EAAA;AACV;AAOO,MAAMK,EAA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AA,QAAQvE,GAA0B2E,CAAe,GAEjDJ,EAAA,UAAU,oBAAoBU,CAAQ,GACtCV,EAAA,UAAU,eAAeW,CAAG,GAC5BX,EAAA,UAAU,0BAA0BY,CAAc,GAClDZ,EAAA,OAAO,iBAAiB,YAAYrE,GACpCqE,EAAA,OAAO,iBAAiB,mBAAmBI;AAAA,EAAA;AAEnD,GAiBaS,KAAmBH,GASnBI,KAAcH,GASdI,KAAyBH;","x_google_ignoreList":[1]}
|
package/package.json
CHANGED
package/src/Discover.vue
CHANGED
|
@@ -11,23 +11,34 @@ const props = defineProps<{
|
|
|
11
11
|
channels: string[];
|
|
12
12
|
schema: Schema;
|
|
13
13
|
session?: GraffitiSession | null;
|
|
14
|
+
autopoll?: boolean;
|
|
14
15
|
}>();
|
|
15
16
|
|
|
16
17
|
defineSlots<{
|
|
17
18
|
default?(props: {
|
|
19
|
+
objects: GraffitiObject<Schema>[];
|
|
18
20
|
results: GraffitiObject<Schema>[];
|
|
19
21
|
poll: () => void;
|
|
20
22
|
isPolling: boolean;
|
|
23
|
+
isInitialPolling: boolean;
|
|
21
24
|
}): any;
|
|
22
25
|
}>();
|
|
23
26
|
|
|
24
|
-
const { results, poll, isPolling } =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
27
|
+
const { objects, results, poll, isPolling, isInitialPolling } =
|
|
28
|
+
useGraffitiDiscover<Schema>(
|
|
29
|
+
toRef(props, "channels"),
|
|
30
|
+
toRef(props, "schema"),
|
|
31
|
+
toRef(props, "session"),
|
|
32
|
+
toRef(props, "autopoll"),
|
|
33
|
+
);
|
|
29
34
|
</script>
|
|
30
35
|
|
|
31
36
|
<template>
|
|
32
|
-
<slot
|
|
37
|
+
<slot
|
|
38
|
+
:objects="objects"
|
|
39
|
+
:results="results"
|
|
40
|
+
:poll="poll"
|
|
41
|
+
:isPolling="isPolling"
|
|
42
|
+
:isInitialPolling="isInitialPolling"
|
|
43
|
+
></slot>
|
|
33
44
|
</template>
|
package/src/Get.vue
CHANGED
|
@@ -12,23 +12,34 @@ const props = defineProps<{
|
|
|
12
12
|
url: string | GraffitiObjectUrl;
|
|
13
13
|
schema: Schema;
|
|
14
14
|
session?: GraffitiSession | null;
|
|
15
|
+
autopoll?: boolean;
|
|
15
16
|
}>();
|
|
16
17
|
|
|
17
18
|
defineSlots<{
|
|
18
19
|
default?(props: {
|
|
20
|
+
object: GraffitiObject<Schema> | undefined | null;
|
|
19
21
|
result: GraffitiObject<Schema> | undefined | null;
|
|
20
22
|
poll: () => void;
|
|
21
23
|
isPolling: boolean;
|
|
24
|
+
isInitialPolling: boolean;
|
|
22
25
|
}): any;
|
|
23
26
|
}>();
|
|
24
27
|
|
|
25
|
-
const { result, poll, isPolling } =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
28
|
+
const { object, result, poll, isPolling, isInitialPolling } =
|
|
29
|
+
useGraffitiGet<Schema>(
|
|
30
|
+
toRef(props, "url"),
|
|
31
|
+
toRef(props, "schema"),
|
|
32
|
+
toRef(props, "session"),
|
|
33
|
+
toRef(props, "autopoll"),
|
|
34
|
+
);
|
|
30
35
|
</script>
|
|
31
36
|
|
|
32
37
|
<template>
|
|
33
|
-
<slot
|
|
38
|
+
<slot
|
|
39
|
+
:object="object"
|
|
40
|
+
:result="result"
|
|
41
|
+
:poll="poll"
|
|
42
|
+
:isPolling="isPolling"
|
|
43
|
+
:isInitialPolling="isInitialPolling"
|
|
44
|
+
></slot>
|
|
34
45
|
</template>
|
package/src/RecoverOrphans.vue
CHANGED
|
@@ -10,22 +10,33 @@ import { useGraffitiRecoverOrphans } from "./composables";
|
|
|
10
10
|
const props = defineProps<{
|
|
11
11
|
schema: Schema;
|
|
12
12
|
session: GraffitiSession;
|
|
13
|
+
autopoll?: boolean;
|
|
13
14
|
}>();
|
|
14
15
|
|
|
15
16
|
defineSlots<{
|
|
16
17
|
default?(props: {
|
|
18
|
+
objects: GraffitiObject<Schema>[];
|
|
17
19
|
results: GraffitiObject<Schema>[];
|
|
18
20
|
poll: () => void;
|
|
19
21
|
isPolling: boolean;
|
|
22
|
+
isInitialPolling: boolean;
|
|
20
23
|
}): any;
|
|
21
24
|
}>();
|
|
22
25
|
|
|
23
|
-
const { results, poll, isPolling } =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
)
|
|
26
|
+
const { objects, results, poll, isPolling, isInitialPolling } =
|
|
27
|
+
useGraffitiRecoverOrphans<Schema>(
|
|
28
|
+
toRef(props, "schema"),
|
|
29
|
+
toRef(props, "session"),
|
|
30
|
+
toRef(props, "autopoll"),
|
|
31
|
+
);
|
|
27
32
|
</script>
|
|
28
33
|
|
|
29
34
|
<template>
|
|
30
|
-
<slot
|
|
35
|
+
<slot
|
|
36
|
+
:objects="objects"
|
|
37
|
+
:results="results"
|
|
38
|
+
:poll="poll"
|
|
39
|
+
:isPolling="isPolling"
|
|
40
|
+
:isInitialPolling="isInitialPolling"
|
|
41
|
+
></slot>
|
|
31
42
|
</template>
|
package/src/composables.ts
CHANGED
|
@@ -18,6 +18,7 @@ function makeComposable<Schema extends JSONSchema>(
|
|
|
18
18
|
GraffitiObjectStreamContinueEntry<Schema>
|
|
19
19
|
>,
|
|
20
20
|
toWatch: readonly (() => any)[],
|
|
21
|
+
autopoll: MaybeRefOrGetter<boolean>,
|
|
21
22
|
) {
|
|
22
23
|
let synchronizeIterator:
|
|
23
24
|
| AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>
|
|
@@ -33,9 +34,21 @@ function makeComposable<Schema extends JSONSchema>(
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
let isAlreadyPolling = false;
|
|
38
|
+
const poll = async () => {
|
|
39
|
+
if (isAlreadyPolling) return;
|
|
40
|
+
isAlreadyPolling = true;
|
|
41
|
+
try {
|
|
42
|
+
await poller.poll(reducer.onEntry.bind(reducer));
|
|
43
|
+
} finally {
|
|
44
|
+
isAlreadyPolling = false;
|
|
45
|
+
if (toValue(autopoll)) {
|
|
46
|
+
poll();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
37
50
|
|
|
38
|
-
const
|
|
51
|
+
const isInitialPolling = ref(false);
|
|
39
52
|
watch(
|
|
40
53
|
toWatch,
|
|
41
54
|
async (newValue, oldValue) => {
|
|
@@ -50,11 +63,11 @@ function makeComposable<Schema extends JSONSchema>(
|
|
|
50
63
|
|
|
51
64
|
pollSynchronize();
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
isInitialPolling.value = true;
|
|
54
67
|
try {
|
|
55
68
|
await poll();
|
|
56
69
|
} finally {
|
|
57
|
-
|
|
70
|
+
isInitialPolling.value = false;
|
|
58
71
|
}
|
|
59
72
|
},
|
|
60
73
|
{
|
|
@@ -63,7 +76,7 @@ function makeComposable<Schema extends JSONSchema>(
|
|
|
63
76
|
);
|
|
64
77
|
onScopeDispose(() => synchronizeIterator?.return(null));
|
|
65
78
|
|
|
66
|
-
return { poll,
|
|
79
|
+
return { poll, isInitialPolling };
|
|
67
80
|
}
|
|
68
81
|
|
|
69
82
|
function toSessionGetter(
|
|
@@ -112,10 +125,13 @@ export function useGraffitiDiscover<Schema extends JSONSchema>(
|
|
|
112
125
|
* will be used. Otherwise, the provided value will be used.
|
|
113
126
|
*/
|
|
114
127
|
session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,
|
|
128
|
+
autopoll: MaybeRefOrGetter<boolean> = false,
|
|
115
129
|
): {
|
|
116
130
|
results: Ref<GraffitiObject<Schema>[]>;
|
|
131
|
+
objects: Ref<GraffitiObject<Schema>[]>;
|
|
117
132
|
poll: () => Promise<void>;
|
|
118
133
|
isPolling: Ref<boolean>;
|
|
134
|
+
isInitialPolling: Ref<boolean>;
|
|
119
135
|
} {
|
|
120
136
|
const graffiti = useGraffitiSynchronize();
|
|
121
137
|
const sessionInjected = useGraffitiSession();
|
|
@@ -132,29 +148,52 @@ export function useGraffitiDiscover<Schema extends JSONSchema>(
|
|
|
132
148
|
const reducer = new ArrayReducer<Schema>(graffiti);
|
|
133
149
|
const poller = new StreamPoller<Schema>(streamFactory);
|
|
134
150
|
|
|
135
|
-
const { poll,
|
|
151
|
+
const { poll, isInitialPolling } = makeComposable<Schema>(
|
|
136
152
|
reducer,
|
|
137
153
|
poller,
|
|
138
154
|
synchronizeFactory,
|
|
139
155
|
argGetters,
|
|
156
|
+
autopoll,
|
|
140
157
|
);
|
|
141
158
|
|
|
142
159
|
return {
|
|
143
160
|
/**
|
|
144
|
-
* A [
|
|
145
|
-
* an array of Graffiti objects.
|
|
161
|
+
* A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
|
|
162
|
+
* an array of Graffiti objects.
|
|
146
163
|
*/
|
|
147
|
-
|
|
164
|
+
objects: reducer.results,
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Use {@link objects} instead.
|
|
167
|
+
*/
|
|
168
|
+
get results() {
|
|
169
|
+
console.warn(
|
|
170
|
+
"The `results` property is deprecated. Use `objects` instead.",
|
|
171
|
+
);
|
|
172
|
+
return this.objects;
|
|
173
|
+
},
|
|
148
174
|
/**
|
|
149
175
|
* A method to poll for new results.
|
|
150
176
|
*/
|
|
151
177
|
poll,
|
|
152
178
|
/**
|
|
153
|
-
* A boolean [
|
|
154
|
-
* that indicates if the poll is currently running.
|
|
179
|
+
* A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
|
|
180
|
+
* that indicates if the *first* poll is currently running.
|
|
155
181
|
* Useful to show a loading spinner or disable a button.
|
|
182
|
+
*
|
|
183
|
+
* This also tracks new polls when the arguments have changed,
|
|
184
|
+
* but it does not track ongoing polls from either calling
|
|
185
|
+
* {@link poll} or using the `autopoll` argument.
|
|
156
186
|
*/
|
|
157
|
-
|
|
187
|
+
isInitialPolling,
|
|
188
|
+
/**
|
|
189
|
+
* @deprecated Use {@link isInitialPolling} instead.
|
|
190
|
+
*/
|
|
191
|
+
get isPolling() {
|
|
192
|
+
console.warn(
|
|
193
|
+
"The `isPolling` property is deprecated. Use `isInitialPolling` instead.",
|
|
194
|
+
);
|
|
195
|
+
return this.isInitialPolling;
|
|
196
|
+
},
|
|
158
197
|
};
|
|
159
198
|
}
|
|
160
199
|
|
|
@@ -182,10 +221,13 @@ export function useGraffitiGet<Schema extends JSONSchema>(
|
|
|
182
221
|
* will be used. Otherwise, the provided value will be used.
|
|
183
222
|
*/
|
|
184
223
|
session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,
|
|
224
|
+
autopoll: MaybeRefOrGetter<boolean> = false,
|
|
185
225
|
): {
|
|
186
226
|
result: Ref<GraffitiObject<Schema> | null | undefined>;
|
|
227
|
+
object: Ref<GraffitiObject<Schema> | null | undefined>;
|
|
187
228
|
poll: () => Promise<void>;
|
|
188
229
|
isPolling: Ref<boolean>;
|
|
230
|
+
isInitialPolling: Ref<boolean>;
|
|
189
231
|
} {
|
|
190
232
|
const graffiti = useGraffitiSynchronize();
|
|
191
233
|
const sessionInjected = useGraffitiSession();
|
|
@@ -206,30 +248,53 @@ export function useGraffitiGet<Schema extends JSONSchema>(
|
|
|
206
248
|
const getter = () => graffiti.get<Schema>(...callGetters(argGetters));
|
|
207
249
|
const poller = new GetPoller<Schema>(getter);
|
|
208
250
|
|
|
209
|
-
const { poll,
|
|
251
|
+
const { poll, isInitialPolling } = makeComposable<Schema>(
|
|
210
252
|
reducer,
|
|
211
253
|
poller,
|
|
212
254
|
synchronizeFactory,
|
|
213
255
|
argGetters,
|
|
256
|
+
autopoll,
|
|
214
257
|
);
|
|
215
258
|
|
|
216
259
|
return {
|
|
217
260
|
/**
|
|
218
|
-
* A [
|
|
261
|
+
* A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
|
|
219
262
|
* the retrieved Graffiti object, if it exists. If the object has been deleted,
|
|
220
263
|
* the result is `null`. If the object is still being fetched, the result is `undefined`.
|
|
221
264
|
*/
|
|
222
|
-
|
|
265
|
+
object: reducer.result,
|
|
266
|
+
/**
|
|
267
|
+
* @deprecated Use {@link object} instead.
|
|
268
|
+
*/
|
|
269
|
+
get result() {
|
|
270
|
+
console.warn(
|
|
271
|
+
"The `result` property is deprecated. Use `object` instead.",
|
|
272
|
+
);
|
|
273
|
+
return this.object;
|
|
274
|
+
},
|
|
223
275
|
/**
|
|
224
276
|
* A method to poll for new results.
|
|
225
277
|
*/
|
|
226
278
|
poll,
|
|
227
279
|
/**
|
|
228
|
-
* A boolean [
|
|
229
|
-
* that indicates if the poll is currently running.
|
|
280
|
+
* A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
|
|
281
|
+
* that indicates if the *first* poll is currently running.
|
|
230
282
|
* Useful to show a loading spinner or disable a button.
|
|
283
|
+
*
|
|
284
|
+
* This also tracks new polls when the arguments have changed,
|
|
285
|
+
* but it does not track ongoing polls from either calling
|
|
286
|
+
* {@link poll} or using the `autopoll` argument.
|
|
287
|
+
*/
|
|
288
|
+
isInitialPolling,
|
|
289
|
+
/**
|
|
290
|
+
* @deprecated Use {@link isInitialPolling} instead.
|
|
231
291
|
*/
|
|
232
|
-
isPolling
|
|
292
|
+
get isPolling() {
|
|
293
|
+
console.warn(
|
|
294
|
+
"The `isPolling` property is deprecated. Use `isInitialPolling` instead.",
|
|
295
|
+
);
|
|
296
|
+
return this.isInitialPolling;
|
|
297
|
+
},
|
|
233
298
|
};
|
|
234
299
|
}
|
|
235
300
|
|
|
@@ -251,10 +316,13 @@ export function useGraffitiGet<Schema extends JSONSchema>(
|
|
|
251
316
|
export function useGraffitiRecoverOrphans<Schema extends JSONSchema>(
|
|
252
317
|
schema: MaybeRefOrGetter<Schema>,
|
|
253
318
|
session: MaybeRefOrGetter<GraffitiSession>,
|
|
319
|
+
autopoll: MaybeRefOrGetter<boolean> = false,
|
|
254
320
|
): {
|
|
321
|
+
objects: Ref<GraffitiObject<Schema>[]>;
|
|
255
322
|
results: Ref<GraffitiObject<Schema>[]>;
|
|
256
323
|
poll: () => Promise<void>;
|
|
257
324
|
isPolling: Ref<boolean>;
|
|
325
|
+
isInitialPolling: Ref<boolean>;
|
|
258
326
|
} {
|
|
259
327
|
const graffiti = useGraffitiSynchronize();
|
|
260
328
|
|
|
@@ -270,28 +338,51 @@ export function useGraffitiRecoverOrphans<Schema extends JSONSchema>(
|
|
|
270
338
|
graffiti.recoverOrphans<Schema>(...callGetters(argGetters));
|
|
271
339
|
const poller = new StreamPoller<Schema>(streamFactory);
|
|
272
340
|
|
|
273
|
-
const { poll,
|
|
341
|
+
const { poll, isInitialPolling } = makeComposable<Schema>(
|
|
274
342
|
reducer,
|
|
275
343
|
poller,
|
|
276
344
|
synchronizeFactory,
|
|
277
345
|
argGetters,
|
|
346
|
+
autopoll,
|
|
278
347
|
);
|
|
279
348
|
|
|
280
349
|
return {
|
|
281
350
|
/**
|
|
282
|
-
* A [
|
|
283
|
-
* an array of Graffiti objects.
|
|
351
|
+
* A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
|
|
352
|
+
* an array of Graffiti objects.
|
|
353
|
+
*/
|
|
354
|
+
objects: reducer.results,
|
|
355
|
+
/**
|
|
356
|
+
* @deprecated Use {@link objects} instead.
|
|
284
357
|
*/
|
|
285
|
-
results
|
|
358
|
+
get results() {
|
|
359
|
+
console.warn(
|
|
360
|
+
"The `result` property is deprecated. Use `object` instead.",
|
|
361
|
+
);
|
|
362
|
+
return this.objects;
|
|
363
|
+
},
|
|
286
364
|
/**
|
|
287
365
|
* A method to poll for new results.
|
|
288
366
|
*/
|
|
289
367
|
poll,
|
|
290
368
|
/**
|
|
291
|
-
* A boolean [
|
|
292
|
-
* that indicates if the poll is currently running.
|
|
369
|
+
* A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
|
|
370
|
+
* that indicates if the *first* poll is currently running.
|
|
293
371
|
* Useful to show a loading spinner or disable a button.
|
|
372
|
+
*
|
|
373
|
+
* This also tracks new polls when the arguments have changed,
|
|
374
|
+
* but it does not track ongoing polls from either calling
|
|
375
|
+
* {@link poll} or using the `autopoll` argument.
|
|
294
376
|
*/
|
|
295
|
-
|
|
377
|
+
isInitialPolling,
|
|
378
|
+
/**
|
|
379
|
+
* @deprecated Use {@link isInitialPolling} instead.
|
|
380
|
+
*/
|
|
381
|
+
get isPolling() {
|
|
382
|
+
console.warn(
|
|
383
|
+
"The `isPolling` property is deprecated. Use `isInitialPolling` instead.",
|
|
384
|
+
);
|
|
385
|
+
return this.isInitialPolling;
|
|
386
|
+
},
|
|
296
387
|
};
|
|
297
388
|
}
|