@graffiti-garden/wrapper-vue 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,61 +1,81 @@
1
- var L = Object.defineProperty;
2
- var k = (e, t, r) => t in e ? L(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var u = (e, t, r) => k(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { inject as _, ref as v, computed as A, watch as C, onScopeDispose as J, toValue as m, defineComponent as P, toRef as h, renderSlot as R, unref as f } from "vue";
5
- import { GraffitiSynchronize as K } from "@graffiti-garden/wrapper-synchronize";
6
- const E = Symbol(), F = Symbol();
1
+ var k = Object.defineProperty;
2
+ var A = (e, t, r) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var u = (e, t, r) => A(e, typeof t != "symbol" ? t + "" : t, r);
4
+ import { inject as E, ref as v, computed as C, watch as J, onScopeDispose as K, toValue as m, defineComponent as P, toRef as h, renderSlot as R, unref as f } from "vue";
5
+ import { GraffitiSynchronize as U } from "@graffiti-garden/wrapper-synchronize";
6
+ const F = Symbol(), _ = Symbol();
7
7
  function G() {
8
- const e = _(E);
8
+ const e = E(F);
9
9
  if (!e)
10
10
  throw new Error(
11
11
  "No Graffiti instance provided, did you forget to install the plugin?"
12
12
  );
13
13
  return e;
14
14
  }
15
- function X() {
15
+ function Z() {
16
16
  return G();
17
17
  }
18
18
  function j() {
19
- const e = _(F);
19
+ const e = E(_);
20
20
  if (!e)
21
21
  throw new Error(
22
22
  "No Graffiti session provided, did you forget to install the plugin?"
23
23
  );
24
24
  return e;
25
25
  }
26
- class U {
26
+ var V = class O extends Error {
27
+ constructor(t) {
28
+ super(t), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, O.prototype);
29
+ }
30
+ };
31
+ class x {
27
32
  constructor(t) {
28
33
  u(this, "poll", async (t) => {
29
34
  let r;
35
+ const s = this.getter;
30
36
  try {
31
- r = await this.getter();
37
+ r = await s();
32
38
  } catch {
33
- t(null);
39
+ this.getter === s && t(null);
34
40
  return;
35
41
  }
36
- t({ object: r });
42
+ this.getter === s && t({ object: r });
37
43
  });
38
44
  this.getter = t;
39
45
  }
40
46
  clear() {
41
47
  }
42
48
  }
43
- class O {
49
+ class T {
44
50
  constructor(t) {
45
51
  u(this, "iterator");
46
52
  u(this, "continue");
47
53
  u(this, "poll", async (t) => {
48
- for (this.iterator || (this.continue ? this.iterator = this.continue() : this.iterator = this.streamFactory()); this.iterator; ) {
49
- const r = await this.iterator.next();
50
- if (r.done) {
51
- r.value && (this.iterator = void 0, this.continue = r.value.continue);
52
- break;
53
- }
54
- if (r.value.error) {
55
- console.error(r.value.error);
56
- continue;
54
+ if (!this.iterator)
55
+ if (this.continue)
56
+ try {
57
+ this.iterator = this.continue();
58
+ } catch (r) {
59
+ if (r instanceof V)
60
+ t("clear"), this.iterator = this.streamFactory();
61
+ else
62
+ throw r;
63
+ }
64
+ else
65
+ this.iterator = this.streamFactory();
66
+ for (; this.iterator; ) {
67
+ const r = this.iterator, s = await r.next();
68
+ if (r === this.iterator) {
69
+ if (s.done) {
70
+ s.value && (this.iterator = void 0, this.continue = s.value.continue);
71
+ break;
72
+ }
73
+ if (s.value.error) {
74
+ console.error(s.value.error);
75
+ continue;
76
+ }
77
+ t(s.value);
57
78
  }
58
- t(r.value);
59
79
  }
60
80
  });
61
81
  this.streamFactory = t;
@@ -71,15 +91,15 @@ class O {
71
91
  this.iterator = void 0, this.continue = void 0;
72
92
  }
73
93
  }
74
- function T(e, t) {
94
+ function $(e, t) {
75
95
  return !t || e.object.lastModified > t.object.lastModified || e.object.lastModified === t.object.lastModified && !e.tombstone && !!t.tombstone;
76
96
  }
77
- class V {
97
+ class B {
78
98
  constructor() {
79
99
  u(this, "entry", v());
80
100
  }
81
101
  get result() {
82
- return A(() => {
102
+ return C(() => {
83
103
  const t = this.entry.value;
84
104
  return t && (t.tombstone ? null : t.object);
85
105
  });
@@ -88,10 +108,14 @@ class V {
88
108
  this.entry.value = void 0;
89
109
  }
90
110
  onEntry(t) {
91
- (!t || T(t, this.entry.value)) && (this.entry.value = t);
111
+ if (t === "clear") {
112
+ this.clear();
113
+ return;
114
+ }
115
+ (!t || $(t, this.entry.value)) && (this.entry.value = t);
92
116
  }
93
117
  }
94
- class $ {
118
+ class z {
95
119
  constructor(t) {
96
120
  u(this, "results", v([]));
97
121
  u(this, "resultsRaw", /* @__PURE__ */ new Map());
@@ -106,17 +130,21 @@ class $ {
106
130
  }
107
131
  onEntry(t) {
108
132
  if (!t) return;
133
+ if (t === "clear") {
134
+ this.clear();
135
+ return;
136
+ }
109
137
  const r = this.resultsRaw.get(t.object.url);
110
- T(t, r) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
138
+ $(t, r) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
111
139
  this.flattenResults(), this.batchFlattenTimer = void 0;
112
140
  }, 0)));
113
141
  }
114
142
  }
115
- function S(e, t, r, n) {
116
- let s;
117
- async function i() {
118
- s = r();
119
- for await (const l of s) {
143
+ function S(e, t, r, s) {
144
+ let o;
145
+ async function n() {
146
+ o = r();
147
+ for await (const l of o) {
120
148
  if (l.error) {
121
149
  console.error(l.error);
122
150
  continue;
@@ -124,14 +152,14 @@ function S(e, t, r, n) {
124
152
  e.onEntry(l);
125
153
  }
126
154
  }
127
- const o = () => t.poll(e.onEntry.bind(e)), c = v(!1);
128
- return C(
129
- n,
155
+ const i = () => t.poll(e.onEntry.bind(e)), c = v(!1);
156
+ return J(
157
+ s,
130
158
  async (l, a) => {
131
159
  if (JSON.stringify(l) !== JSON.stringify(a)) {
132
- s == null || s.return(null), e.clear(), t.clear(), i(), c.value = !0;
160
+ o == null || o.return(null), e.clear(), t.clear(), n(), c.value = !0;
133
161
  try {
134
- await o();
162
+ await i();
135
163
  } finally {
136
164
  c.value = !1;
137
165
  }
@@ -140,9 +168,9 @@ function S(e, t, r, n) {
140
168
  {
141
169
  immediate: !0
142
170
  }
143
- ), J(() => s == null ? void 0 : s.return(null)), { poll: o, isPolling: c };
171
+ ), K(() => o == null ? void 0 : o.return(null)), { poll: i, isPolling: c };
144
172
  }
145
- function z(e, t) {
173
+ function D(e, t) {
146
174
  return () => {
147
175
  const r = m(t);
148
176
  return r === void 0 ? e == null ? void 0 : e.value : r;
@@ -151,9 +179,9 @@ function z(e, t) {
151
179
  function d(e) {
152
180
  return e.map((t) => t());
153
181
  }
154
- function B(e, t, r) {
155
- const n = G(), s = j(), i = () => m(e), o = () => m(t), c = z(s, r), l = [i, o, c], a = () => n.synchronizeDiscover(...d(l)), g = () => n.discover(...d(l)), p = new $(n), y = new O(g), { poll: b, isPolling: w } = S(
156
- p,
182
+ function W(e, t, r) {
183
+ const s = G(), o = j(), n = () => m(e), i = () => m(t), c = D(o, r), l = [n, i, c], a = () => s.synchronizeDiscover(...d(l)), p = () => s.discover(...d(l)), g = new z(s), y = new T(p), { poll: b, isPolling: w } = S(
184
+ g,
157
185
  y,
158
186
  a,
159
187
  l
@@ -163,7 +191,7 @@ function B(e, t, r) {
163
191
  * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
164
192
  * an array of Graffiti objects. All tombstoned objects have been filtered out.
165
193
  */
166
- results: p.results,
194
+ results: g.results,
167
195
  /**
168
196
  * A method to poll for new results.
169
197
  */
@@ -176,13 +204,13 @@ function B(e, t, r) {
176
204
  isPolling: w
177
205
  };
178
206
  }
179
- function W(e, t, r) {
180
- const n = G(), s = j(), i = () => m(e), o = () => m(t), c = z(s, r), l = [
207
+ function q(e, t, r) {
208
+ const s = G(), o = j(), n = () => m(e), i = () => m(t), c = D(o, r), l = [
209
+ n,
181
210
  i,
182
- o,
183
211
  c
184
- ], a = () => n.synchronizeGet(...d(l)), g = new V(), p = () => n.get(...d(l)), y = new U(p), { poll: b, isPolling: w } = S(
185
- g,
212
+ ], a = () => s.synchronizeGet(...d(l)), p = new B(), g = () => s.get(...d(l)), y = new x(g), { poll: b, isPolling: w } = S(
213
+ p,
186
214
  y,
187
215
  a,
188
216
  l
@@ -193,7 +221,7 @@ function W(e, t, r) {
193
221
  * the retrieved Graffiti object, if it exists. If the object has been deleted,
194
222
  * the result is `null`. If the object is still being fetched, the result is `undefined`.
195
223
  */
196
- result: g.result,
224
+ result: p.result,
197
225
  /**
198
226
  * A method to poll for new results.
199
227
  */
@@ -206,12 +234,12 @@ function W(e, t, r) {
206
234
  isPolling: w
207
235
  };
208
236
  }
209
- function q(e, t) {
210
- const r = G(), i = [() => m(e), () => m(t)], o = () => r.synchronizeRecoverOrphans(...d(i)), c = new $(r), l = () => r.recoverOrphans(...d(i)), a = new O(l), { poll: g, isPolling: p } = S(
237
+ function H(e, t) {
238
+ const r = G(), n = [() => m(e), () => m(t)], i = () => r.synchronizeRecoverOrphans(...d(n)), c = new z(r), l = () => r.recoverOrphans(...d(n)), a = new T(l), { poll: p, isPolling: g } = S(
211
239
  c,
212
240
  a,
213
- o,
214
- i
241
+ i,
242
+ n
215
243
  );
216
244
  return {
217
245
  /**
@@ -222,16 +250,16 @@ function q(e, t) {
222
250
  /**
223
251
  * A method to poll for new results.
224
252
  */
225
- poll: g,
253
+ poll: p,
226
254
  /**
227
255
  * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
228
256
  * that indicates if the poll is currently running.
229
257
  * Useful to show a loading spinner or disable a button.
230
258
  */
231
- isPolling: p
259
+ isPolling: g
232
260
  };
233
261
  }
234
- const D = /* @__PURE__ */ P({
262
+ const N = /* @__PURE__ */ P({
235
263
  __name: "Discover",
236
264
  props: {
237
265
  channels: {},
@@ -239,15 +267,15 @@ const D = /* @__PURE__ */ P({
239
267
  session: {}
240
268
  },
241
269
  setup(e) {
242
- const t = e, { results: r, poll: n, isPolling: s } = B(
270
+ const t = e, { results: r, poll: s, isPolling: o } = W(
243
271
  h(t, "channels"),
244
272
  h(t, "schema"),
245
273
  h(t, "session")
246
274
  );
247
- return (i, o) => R(i.$slots, "default", {
275
+ return (n, i) => R(n.$slots, "default", {
248
276
  results: f(r),
249
- poll: f(n),
250
- isPolling: f(s)
277
+ poll: f(s),
278
+ isPolling: f(o)
251
279
  });
252
280
  }
253
281
  }), M = /* @__PURE__ */ P({
@@ -258,69 +286,69 @@ const D = /* @__PURE__ */ P({
258
286
  session: {}
259
287
  },
260
288
  setup(e) {
261
- const t = e, { result: r, poll: n, isPolling: s } = W(
289
+ const t = e, { result: r, poll: s, isPolling: o } = q(
262
290
  h(t, "url"),
263
291
  h(t, "schema"),
264
292
  h(t, "session")
265
293
  );
266
- return (i, o) => R(i.$slots, "default", {
294
+ return (n, i) => R(n.$slots, "default", {
267
295
  result: f(r),
268
- poll: f(n),
269
- isPolling: f(s)
296
+ poll: f(s),
297
+ isPolling: f(o)
270
298
  });
271
299
  }
272
- }), N = /* @__PURE__ */ P({
300
+ }), L = /* @__PURE__ */ P({
273
301
  __name: "RecoverOrphans",
274
302
  props: {
275
303
  schema: {},
276
304
  session: {}
277
305
  },
278
306
  setup(e) {
279
- const t = e, { results: r, poll: n, isPolling: s } = q(
307
+ const t = e, { results: r, poll: s, isPolling: o } = H(
280
308
  h(t, "schema"),
281
309
  h(t, "session")
282
310
  );
283
- return (i, o) => R(i.$slots, "default", {
311
+ return (n, i) => R(n.$slots, "default", {
284
312
  results: f(r),
285
- poll: f(n),
286
- isPolling: f(s)
313
+ poll: f(s),
314
+ isPolling: f(o)
287
315
  });
288
316
  }
289
- }), Y = {
317
+ }), I = {
290
318
  install(e, t) {
291
- const r = t.graffiti, n = new K(r), s = v(void 0);
292
- n.sessionEvents.addEventListener("initialized", async (i) => {
293
- const o = i.detail;
294
- if (o && o.error && console.error(o.error), o && o.href) {
319
+ const r = t.graffiti, s = new U(r), o = v(void 0);
320
+ s.sessionEvents.addEventListener("initialized", async (n) => {
321
+ const i = n.detail;
322
+ if (i && i.error && console.error(i.error), i && i.href) {
295
323
  const c = e.config.globalProperties.$router;
296
324
  if (c) {
297
- const l = c.options.history.base, a = new URL(o.href);
325
+ const l = c.options.history.base, a = new URL(i.href);
298
326
  a.pathname.startsWith(l) && (a.pathname = a.pathname.slice(l.length)), await c.replace(a.pathname + a.search + a.hash);
299
327
  }
300
328
  }
301
- s.value || (s.value = null);
302
- }), n.sessionEvents.addEventListener("login", (i) => {
303
- const o = i.detail;
304
- if (o.error) {
305
- console.error("Error logging in:"), console.error(o.error);
329
+ o.value || (o.value = null);
330
+ }), s.sessionEvents.addEventListener("login", (n) => {
331
+ const i = n.detail;
332
+ if (i.error) {
333
+ console.error("Error logging in:"), console.error(i.error);
306
334
  return;
307
335
  } else
308
- s.value = o.session;
309
- }), n.sessionEvents.addEventListener("logout", (i) => {
310
- const o = i.detail;
311
- o.error ? (console.error("Error logging out:"), console.error(o.error)) : s.value = null;
312
- }), e.provide(E, n), e.provide(F, s), e.component("GraffitiDiscover", D), e.component("GraffitiGet", M), e.component("GraffitiRecoverOrphans", N), e.config.globalProperties.$graffiti = n, e.config.globalProperties.$graffitiSession = s;
336
+ o.value = i.session;
337
+ }), s.sessionEvents.addEventListener("logout", (n) => {
338
+ const i = n.detail;
339
+ i.error ? (console.error("Error logging out:"), console.error(i.error)) : o.value = null;
340
+ }), e.provide(F, s), e.provide(_, o), e.component("GraffitiDiscover", N), e.component("GraffitiGet", M), e.component("GraffitiRecoverOrphans", L), e.config.globalProperties.$graffiti = s, e.config.globalProperties.$graffitiSession = o;
313
341
  }
314
- }, Z = D, I = M, tt = N;
342
+ }, tt = N, et = M, rt = L;
315
343
  export {
316
- Z as GraffitiDiscover,
317
- I as GraffitiGet,
318
- Y as GraffitiPlugin,
319
- tt as GraffitiRecoverOrphans,
320
- X as useGraffiti,
321
- B as useGraffitiDiscover,
322
- W as useGraffitiGet,
323
- q as useGraffitiRecoverOrphans,
344
+ tt as GraffitiDiscover,
345
+ et as GraffitiGet,
346
+ I as GraffitiPlugin,
347
+ rt as GraffitiRecoverOrphans,
348
+ Z as useGraffiti,
349
+ W as useGraffitiDiscover,
350
+ q as useGraffitiGet,
351
+ H as useGraffitiRecoverOrphans,
324
352
  j as useGraffitiSession,
325
353
  G as useGraffitiSynchronize
326
354
  };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","sources":["../../src/globals.ts","../../src/pollers.ts","../../src/reducers.ts","../../src/composables.ts","../../src/Discover.vue","../../src/Get.vue","../../src/RecoverOrphans.vue","../../src/plugin.ts"],"sourcesContent":["import { inject } from \"vue\";\nimport type { InjectionKey, Ref } from \"vue\";\nimport type { Graffiti, GraffitiSession } from \"@graffiti-garden/api\";\nimport type { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\nexport const graffitiInjectKey = Symbol() as InjectionKey<GraffitiSynchronize>;\nexport const graffitiSessionInjectKey = Symbol() as InjectionKey<\n Ref<GraffitiSession | undefined | null>\n>;\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * that has been wrapped by the {@link GraffitiPlugin} with the [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSynchronize() {\n const graffiti = inject(graffitiInjectKey);\n if (!graffiti) {\n throw new Error(\n \"No Graffiti instance provided, did you forget to install the plugin?\",\n );\n }\n return graffiti;\n}\n\n/**\n * Returns the global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffiti | $graffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n *\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffiti(): Graffiti {\n return useGraffitiSynchronize();\n}\n\n/**\n * Returns a global reactive [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In Vue templates and the [options API](https://vuejs.org/guide/introduction.html#options-api)\n * use the global variable {@link ComponentCustomProperties.$graffitiSession | $graffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n * @throws If the {@link GraffitiPlugin} is not installed\n */\nexport function useGraffitiSession() {\n const session = inject(graffitiSessionInjectKey);\n if (!session) {\n throw new Error(\n \"No Graffiti session provided, did you forget to install the plugin?\",\n );\n }\n return session;\n}\n","import type {\n Graffiti,\n JSONSchema,\n GraffitiObject,\n GraffitiObjectStreamReturn,\n GraffitiObjectStreamContinueEntry,\n GraffitiObjectStream,\n GraffitiObjectStreamContinue,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Poller<Schema extends JSONSchema> {\n abstract poll(\n onEntry: (entry: GraffitiObjectStreamContinueEntry<Schema> | null) => void,\n ): Promise<void>;\n abstract clear(): void;\n}\n\n/**\n * Polls for a single object and calls onValue with the result.\n */\nexport class GetPoller<Schema extends JSONSchema> implements Poller<Schema> {\n constructor(readonly getter: () => Promise<GraffitiObject<Schema>>) {}\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n let object: GraffitiObject<Schema>;\n try {\n object = await this.getter();\n } catch (e) {\n onEntry(null);\n return;\n }\n onEntry({ object });\n };\n\n clear() {}\n}\n\n/**\n * Polls for multiple objects and calls `onObject` with the result.\n * If `poll` is called multiple times, it doesn't poll the results\n * entirely from scratch, but instead only polls the new results.\n */\nexport class StreamPoller<Schema extends JSONSchema> implements Poller<Schema> {\n iterator: GraffitiObjectStreamContinue<Schema> | undefined;\n continue: (() => GraffitiObjectStreamContinue<Schema>) | undefined;\n\n constructor(readonly streamFactory: () => GraffitiObjectStream<Schema>) {}\n\n clear() {\n if (this.iterator) {\n const iterator = this.iterator;\n this.iterator.return({\n continue: () => iterator,\n cursor: \"\",\n });\n }\n this.iterator = undefined;\n this.continue = undefined;\n }\n\n poll: Poller<Schema>[\"poll\"] = async (onEntry) => {\n if (!this.iterator) {\n if (this.continue) {\n this.iterator = this.continue();\n } else {\n this.iterator = this.streamFactory();\n }\n }\n\n while (true) {\n // Check if the iterator has been cancelled.\n if (!this.iterator) {\n break;\n }\n\n const result = await this.iterator.next();\n\n if (result.done) {\n if (result.value) {\n this.iterator = undefined;\n this.continue = result.value.continue;\n }\n break;\n }\n\n if (result.value.error) {\n console.error(result.value.error);\n continue;\n }\n\n onEntry(result.value);\n }\n };\n}\n","import { computed, ref } from \"vue\";\nimport type { Ref } from \"vue\";\nimport type {\n GraffitiObject,\n Graffiti,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\n\nexport abstract class Reducer<Schema extends JSONSchema> {\n abstract clear(): void;\n abstract onEntry(\n entry: GraffitiObjectStreamContinueEntry<Schema> | null,\n ): void;\n}\n\nfunction isEntryNewer<Schema extends JSONSchema>(\n entry: GraffitiObjectStreamContinueEntry<Schema>,\n existing: GraffitiObjectStreamContinueEntry<Schema> | null | undefined,\n): boolean {\n return (\n !existing ||\n entry.object.lastModified > existing.object.lastModified ||\n (entry.object.lastModified === existing.object.lastModified &&\n !entry.tombstone &&\n !!existing.tombstone)\n );\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one as the `result` property (a Vue ref).\n * Before any objects have been received, the result\n * is `undefined`. If the object has been deleted,\n * the result is `null`.\n */\nexport class SingletonReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly entry: Ref<\n GraffitiObjectStreamContinueEntry<Schema> | null | undefined\n > = ref();\n\n get result(): Ref<GraffitiObject<Schema> | null | undefined> {\n return computed(() => {\n const value = this.entry.value;\n if (!value) return value;\n if (value.tombstone) return null;\n return value.object;\n });\n }\n\n clear() {\n this.entry.value = undefined;\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null) {\n if (!entry || isEntryNewer<Schema>(entry, this.entry.value)) {\n this.entry.value = entry;\n }\n }\n}\n\n/**\n * Retrieves multiple Graffiti objects and retains\n * the most recent one per URI as the `results` property (a Vue ref).\n * If multiple objects are received concurrently,\n * they are processed in batches every `REFRESH_RATE` milliseconds\n * to avoid freezing the interface.\n */\nexport class ArrayReducer<Schema extends JSONSchema>\n implements Reducer<Schema>\n{\n readonly results: Ref<GraffitiObject<Schema>[]> = ref([]);\n readonly resultsRaw: Map<string, GraffitiObjectStreamContinueEntry<Schema>> =\n new Map();\n batchFlattenTimer: ReturnType<typeof setTimeout> | undefined;\n\n constructor(readonly graffiti: Graffiti) {}\n\n clear() {\n this.resultsRaw.clear();\n this.results.value = [];\n clearTimeout(this.batchFlattenTimer);\n this.batchFlattenTimer = undefined;\n }\n\n flattenResults() {\n this.results.value = Array.from(this.resultsRaw.values()).reduce<\n GraffitiObject<Schema>[]\n >((acc, entry) => {\n if (!entry.tombstone) {\n acc.push(entry.object);\n }\n return acc;\n }, []);\n }\n\n onEntry(entry: GraffitiObjectStreamContinueEntry<Schema> | null) {\n if (!entry) return;\n const existing = this.resultsRaw.get(entry.object.url);\n if (!isEntryNewer<Schema>(entry, existing)) return;\n this.resultsRaw.set(entry.object.url, entry);\n\n // Don't flatten the results all at once,\n // because we may get a lot of results\n // and we don't want the interface to\n // freeze up\n if (!this.batchFlattenTimer) {\n this.batchFlattenTimer = setTimeout(() => {\n this.flattenResults();\n this.batchFlattenTimer = undefined;\n }, 0);\n }\n }\n}\n","import { onScopeDispose, ref, toValue, watch } from \"vue\";\nimport type { Ref, MaybeRefOrGetter } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiSynchronize, useGraffitiSession } from \"./globals\";\nimport { GetPoller, Poller, StreamPoller } from \"./pollers\";\nimport { ArrayReducer, Reducer, SingletonReducer } from \"./reducers\";\n\nfunction makeComposable<Schema extends JSONSchema>(\n reducer: Reducer<Schema>,\n poller: Poller<Schema>,\n synchronizeFactory: () => AsyncGenerator<\n GraffitiObjectStreamContinueEntry<Schema>\n >,\n toWatch: readonly (() => any)[],\n) {\n let synchronizeIterator:\n | AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>\n | undefined;\n async function pollSynchronize() {\n synchronizeIterator = synchronizeFactory();\n for await (const result of synchronizeIterator) {\n if (result.error) {\n console.error(result.error);\n continue;\n }\n reducer.onEntry(result);\n }\n }\n\n const poll = () => poller.poll(reducer.onEntry.bind(reducer));\n\n const isPolling = ref(false);\n watch(\n toWatch,\n async (newValue, oldValue) => {\n // Catch unnecessary updates\n if (JSON.stringify(newValue) === JSON.stringify(oldValue)) {\n return;\n }\n\n synchronizeIterator?.return(null);\n reducer.clear();\n poller.clear();\n\n pollSynchronize();\n\n isPolling.value = true;\n try {\n await poll();\n } finally {\n isPolling.value = false;\n }\n },\n {\n immediate: true,\n },\n );\n onScopeDispose(() => synchronizeIterator?.return(null));\n\n return { poll, isPolling };\n}\n\nfunction toSessionGetter(\n sessionInjected: ReturnType<typeof useGraffitiSession>,\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n) {\n return () => {\n const sessionValue = toValue(session);\n if (sessionValue === undefined) {\n return sessionInjected?.value;\n } else {\n return sessionValue;\n }\n };\n}\n\nfunction callGetters<T extends readonly (() => any)[]>(\n getters: T,\n): {\n [K in keyof T]: ReturnType<T[K]>;\n} {\n return getters.map((fn) => fn()) as any;\n}\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiDiscover}.\n *\n * The arguments of this composable as the same as Graffiti.discover,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiDiscover<Schema extends JSONSchema>(\n channels: MaybeRefOrGetter<string[]>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const channelsGetter = () => toValue(channels);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [channelsGetter, schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeDiscover(...callGetters(argGetters));\n const streamFactory = () => graffiti.discover(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\n };\n}\n\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiGet}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiGet<Schema extends JSONSchema>(\n locationOrUri: MaybeRefOrGetter<GraffitiObjectUrl | string>,\n schema: MaybeRefOrGetter<Schema>,\n /**\n * If the session is `undefined`, the global session,\n * {@link ComponentCustomProperties.$graffitiSession | $graffitiSession},\n * will be used. Otherwise, the provided value will be used.\n */\n session?: MaybeRefOrGetter<GraffitiSession | undefined | null>,\n): {\n result: Ref<GraffitiObject<Schema> | null | undefined>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n const sessionInjected = useGraffitiSession();\n\n const locationOrUriGetter = () => toValue(locationOrUri);\n const schemaGetter = () => toValue(schema);\n const sessionGetter = toSessionGetter(sessionInjected, session);\n const argGetters = [\n locationOrUriGetter,\n schemaGetter,\n sessionGetter,\n ] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeGet(...callGetters(argGetters));\n\n const reducer = new SingletonReducer<Schema>();\n const getter = () => graffiti.get<Schema>(...callGetters(argGetters));\n const poller = new GetPoller<Schema>(getter);\n\n const { poll, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * the retrieved Graffiti object, if it exists. If the object has been deleted,\n * the result is `null`. If the object is still being fetched, the result is `undefined`.\n */\n result: reducer.result,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\n };\n}\n\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [composable](https://vuejs.org/guide/reusability/composables.html)\n * for use in the Vue [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * Its corresponding renderless component is {@link GraffitiRecoverOrphans}.\n *\n * The arguments of this composable as the same as Graffiti.get,\n * only they can also be [Refs](https://vuejs.org/api/reactivity-core.html#ref)\n * or [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description).\n * As they change the output will automatically update.\n * Reactivity only triggers when the root array or object changes,\n * not when the elements or properties change.\n * If you need deep reactivity, wrap your argument in a getter.\n */\nexport function useGraffitiRecoverOrphans<Schema extends JSONSchema>(\n schema: MaybeRefOrGetter<Schema>,\n session: MaybeRefOrGetter<GraffitiSession>,\n): {\n results: Ref<GraffitiObject<Schema>[]>;\n poll: () => Promise<void>;\n isPolling: Ref<boolean>;\n} {\n const graffiti = useGraffitiSynchronize();\n\n const schemaGetter = () => toValue(schema);\n const sessionGetter = () => toValue(session);\n const argGetters = [schemaGetter, sessionGetter] as const;\n\n const synchronizeFactory = () =>\n graffiti.synchronizeRecoverOrphans(...callGetters(argGetters));\n\n const reducer = new ArrayReducer<Schema>(graffiti);\n const streamFactory = () =>\n graffiti.recoverOrphans<Schema>(...callGetters(argGetters));\n const poller = new StreamPoller<Schema>(streamFactory);\n\n const { poll, isPolling } = makeComposable<Schema>(\n reducer,\n poller,\n synchronizeFactory,\n argGetters,\n );\n\n return {\n /**\n * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains\n * an array of Graffiti objects. All tombstoned objects have been filtered out.\n */\n results: reducer.results,\n /**\n * A method to poll for new results.\n */\n poll,\n /**\n * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)\n * that indicates if the poll is currently running.\n * Useful to show a loading spinner or disable a button.\n */\n isPolling,\n };\n}\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiDiscover } from \"./composables\";\n\nconst props = defineProps<{\n channels: string[];\n schema: Schema;\n session?: GraffitiSession | null;\n}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiDiscover<Schema>(\n toRef(props, \"channels\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiObjectUrl,\n GraffitiObject,\n GraffitiSession,\n JSONSchema,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiGet } from \"./composables\";\n\nconst props = defineProps<{\n url: string | GraffitiObjectUrl;\n schema: Schema;\n session?: GraffitiSession | null;\n}>();\n\ndefineSlots<{\n default?(props: {\n result: GraffitiObject<Schema> | undefined | null;\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { result, poll, isPolling } = useGraffitiGet<Schema>(\n toRef(props, \"url\"),\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :result=\"result\" :poll=\"poll\" :isPolling=\"isPolling\"></slot>\n</template>\n","<script setup lang=\"ts\" generic=\"Schema extends JSONSchema\">\nimport { toRef } from \"vue\";\nimport type {\n GraffitiSession,\n JSONSchema,\n GraffitiObject,\n} from \"@graffiti-garden/api\";\nimport { useGraffitiRecoverOrphans } from \"./composables\";\n\nconst props = defineProps<{\n schema: Schema;\n session: GraffitiSession;\n}>();\n\ndefineSlots<{\n default?(props: {\n results: GraffitiObject<Schema>[];\n poll: () => void;\n isPolling: boolean;\n }): any;\n}>();\n\nconst { results, poll, isPolling } = useGraffitiRecoverOrphans<Schema>(\n toRef(props, \"schema\"),\n toRef(props, \"session\"),\n);\n</script>\n\n<template>\n <slot :results=\"results\" :poll=\"poll\" :isPolling=\"isPolling\"></slot>\n</template>\n","import type { App, Plugin, Ref } from \"vue\";\nimport { ref } from \"vue\";\nimport Discover from \"./Discover.vue\";\nimport Get from \"./Get.vue\";\nimport RecoverOrphans from \"./RecoverOrphans.vue\";\nimport type {\n Graffiti,\n GraffitiSession,\n GraffitiLoginEvent,\n GraffitiLogoutEvent,\n GraffitiSessionInitializedEvent,\n} from \"@graffiti-garden/api\";\nimport { graffitiInjectKey, graffitiSessionInjectKey } from \"./globals\";\nimport type { Router } from \"vue-router\";\nimport { GraffitiSynchronize } from \"@graffiti-garden/wrapper-synchronize\";\n\ndeclare module \"vue\" {\n export interface ComponentCustomProperties {\n /**\n * Global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance.\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffiti} instead.\n *\n * This is the same Graffiti registered with the {@link GraffitiPlugin}\n * via {@link GraffitiPluginOptions.graffiti}, only it has been wrapped\n * with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html).\n * Be sure to use the wrapped instance to enable reactivity.\n */\n $graffiti: Graffiti;\n /**\n * Global reactive [GraffitiSession](https://api.graffiti.garden/classes/GraffitiSession.html) instance\n * as a [Vue ref](https://vuejs.org/api/reactivity-core.html#ref).\n *\n * In the [composition API](https://vuejs.org/guide/introduction.html#composition-api)\n * use {@link useGraffitiSession} instead.\n *\n * While the application is loading and restoring any previous sessions,\n * the value will be `undefined`. If the user is not logged in,\n * the value will be `null`.\n *\n * This only keeps track of one session. If your app needs\n * to support multiple login sessions, you'll need to manage them\n * yourself using [`Graffiti.sessionEvents`](https://api.graffiti.garden/classes/Graffiti.html#sessionevents).\n */\n $graffitiSession: Ref<GraffitiSession | undefined | null>;\n }\n\n export interface GlobalComponents {\n GraffitiDiscover: typeof Discover;\n GraffitiGet: typeof Get;\n GraffitiRecoverOrphans: typeof RecoverOrphans;\n }\n}\nexport type { ComponentCustomProperties } from \"vue\";\n\n/**\n * Options for the {@link GraffitiPlugin}.\n */\nexport interface GraffitiPluginOptions {\n /**\n * An instance of the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * for the Vue.js plugin to use.\n * This instance, wrapped with [GraffitiSynchronize](https://sync.graffiti.garden/classes/GraffitiSynchronize.html),\n * will be exposed in Vue templates as {@link ComponentCustomProperties.$graffiti | $graffiti}\n * and in setup functions as {@link useGraffiti}.\n * You must interact with Graffiti through these wrapped instances\n * to enable reactivity.\n *\n * You'll likely want to use the [federated implementation](https://github.com/graffiti-garden/implementation-federated).\n * However, you could also use the [local implementation](https://github.com/graffiti-garden/implementation-local)\n * for testing. Other implementations may be available in the future.\n */\n graffiti: Graffiti;\n}\n\n/**\n * A [Vue.js](https://vuejs.org/) plugin that wraps around\n * the [Graffiti API](https://api.graffiti.garden/classes/Graffiti.html)\n * to provide [reactive](https://en.wikipedia.org/wiki/Reactive_programming) versions\n * of various Graffiti API methods.\n *\n * These reactive methods are available as both\n * [renderless components](https://vuejs.org/guide/components/slots#renderless-components),\n * which make it possible to create a whole Graffiti app in an HTML template,\n * and [composables](https://vuejs.org/guide/reusability/composables.html),\n * which can be used in the programmatic [composition API](https://vuejs.org/guide/introduction.html#composition-api).\n *\n * | [API](https://api.graffiti.garden/classes/Graffiti.html) method | [Composable](https://vuejs.org/guide/reusability/composables.html) | [Component](https://vuejs.org/guide/components/slots#renderless-components) |\n * | --- | --- | --- |\n * | [discover](https://api.graffiti.garden/classes/Graffiti.html#discover) | {@link useGraffitiDiscover} | {@link GraffitiDiscover} |\n * | [get](https://api.graffiti.garden/classes/Graffiti.html#get) | {@link useGraffitiGet} | {@link GraffitiGet} |\n * | [recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans) | {@link useGraffitiRecoverOrphans} | {@link GraffitiRecoverOrphans} |\n *\n * The plugin also exposes a global [Graffiti](https://api.graffiti.garden/classes/Graffiti.html) instance\n * and keeps track of the global [GraffitiSession](https://api.graffiti.garden/interfaces/GraffitiSession.html)\n * state as a reactive variable.\n * They are available in templates as global variables or in setup functions as\n * composable functions.\n *\n * | Global variabale | [Composable](https://vuejs.org/guide/reusability/composables.html) |\n * | --- | --- |\n * | {@link ComponentCustomProperties.$graffiti | $graffiti } | {@link useGraffiti} |\n * | {@link ComponentCustomProperties.$graffitiSession | $graffitiSession } | {@link useGraffitiSession} |\n *\n * [See the README for installation instructions](/).\n *\n * You can [try out live examples](/examples/), but basic usage looks like this:\n *\n * ```ts\n * import { createApp } from \"vue\";\n * import { GraffitiPlugin } from \"@graffiti-garden/vue\";\n * import { GraffitiLocal } from \"@graffiti-garden/implementation-local\";\n * import App from \"./App.vue\";\n *\n * createApp(App)\n * .use(GraffitiPlugin, {\n * graffiti: new GraffitiLocal(),\n * })\n * ```\n *\n * ```vue\n * <!-- App.vue -->\n * <template>\n * <button\n * v-if=\"$graffitiSession.value\"\n * @click=\"$graffiti.put({\n * value: { content: 'Hello, world!' },\n * channels: [ 'my-channel' ]\n * }, $graffitiSession.value)\"\n * >\n * Say Hello\n * </button>\n * <button v-else @click=\"$graffiti.login()\">\n * Log In to Say Hello\n * </button>\n *\n * <GraffitiDiscover\n * v-slot=\"{ results }\"\n * :channels=\"[ 'my-channel' ]\"\n * :schema=\"{\n * properties: {\n * value: {\n * required: ['content'],\n * properties: {\n * content: { type: 'string' }\n * }\n * }\n * }\n * }\"\n * >\n * <ul>\n * <li\n * v-for=\"result in results\"\n * :key=\"$graffiti.objectToUri(result)\"\n * >\n * {{ result.value.content }}\n * </li>\n * </ul>\n * </GraffitiDiscover>\n * </template>\n * ```\n */\nexport const GraffitiPlugin: Plugin<GraffitiPluginOptions> = {\n install(app: App, options: GraffitiPluginOptions) {\n const graffitiBase = options.graffiti;\n const graffiti = new GraffitiSynchronize(graffitiBase);\n\n const graffitiSession = ref<GraffitiSession | undefined | null>(undefined);\n graffiti.sessionEvents.addEventListener(\"initialized\", async (evt) => {\n const detail = (evt as GraffitiSessionInitializedEvent).detail;\n\n if (detail && detail.error) {\n console.error(detail.error);\n }\n\n if (detail && detail.href) {\n // If we're using Vue Router, redirect to the URL after login\n const router = app.config.globalProperties.$router as\n | Router\n | undefined;\n if (router) {\n const base = router.options.history.base;\n const url = new URL(detail.href);\n if (url.pathname.startsWith(base)) {\n url.pathname = url.pathname.slice(base.length);\n }\n await router.replace(url.pathname + url.search + url.hash);\n }\n }\n\n // Set the session to \"null\" if the user is not logged in\n if (!graffitiSession.value) {\n graffitiSession.value = null;\n }\n });\n graffiti.sessionEvents.addEventListener(\"login\", (evt) => {\n const detail = (evt as GraffitiLoginEvent).detail;\n if (detail.error) {\n console.error(\"Error logging in:\");\n console.error(detail.error);\n return;\n } else {\n graffitiSession.value = detail.session;\n }\n });\n graffiti.sessionEvents.addEventListener(\"logout\", (evt) => {\n const detail = (evt as GraffitiLogoutEvent).detail;\n if (detail.error) {\n console.error(\"Error logging out:\");\n console.error(detail.error);\n } else {\n graffitiSession.value = null;\n }\n });\n\n app.provide(graffitiInjectKey, graffiti);\n app.provide(graffitiSessionInjectKey, graffitiSession);\n\n app.component(\"GraffitiDiscover\", Discover);\n app.component(\"GraffitiGet\", Get);\n app.component(\"GraffitiRecoverOrphans\", RecoverOrphans);\n app.config.globalProperties.$graffiti = graffiti;\n app.config.globalProperties.$graffitiSession = graffitiSession;\n },\n};\n\nexport * from \"./composables\";\nexport {\n useGraffiti,\n useGraffitiSynchronize,\n useGraffitiSession,\n} from \"./globals\";\n\n/**\n * The [Graffiti.discover](https://api.graffiti.garden/classes/Graffiti.html#discover)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiDiscover}.\n */\nexport const GraffitiDiscover = Discover;\n/**\n * The [Graffiti.get](https://api.graffiti.garden/classes/Graffiti.html#get)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiGet}.\n */\nexport const GraffitiGet = Get;\n/**\n * The [Graffiti.recoverOrphans](https://api.graffiti.garden/classes/Graffiti.html#recoverorphans)\n * method as a reactive [renderless component](https://vuejs.org/guide/components/slots#renderless-components)\n * for use in Vue templates.\n *\n * Its props and slots are identical to the arguments and return values of\n * the composable {@link useGraffitiRecoverOrphans}.\n */\nexport const GraffitiRecoverOrphans = RecoverOrphans;\n"],"names":["graffitiInjectKey","graffitiSessionInjectKey","useGraffitiSynchronize","graffiti","inject","useGraffiti","useGraffitiSession","session","GetPoller","getter","__publicField","onEntry","object","StreamPoller","streamFactory","result","iterator","isEntryNewer","entry","existing","SingletonReducer","ref","computed","value","ArrayReducer","acc","makeComposable","reducer","poller","synchronizeFactory","toWatch","synchronizeIterator","pollSynchronize","poll","isPolling","watch","newValue","oldValue","onScopeDispose","toSessionGetter","sessionInjected","sessionValue","toValue","callGetters","getters","fn","useGraffitiDiscover","channels","schema","channelsGetter","schemaGetter","sessionGetter","argGetters","useGraffitiGet","locationOrUri","locationOrUriGetter","useGraffitiRecoverOrphans","props","__props","results","toRef","GraffitiPlugin","app","options","graffitiBase","GraffitiSynchronize","graffitiSession","evt","detail","router","base","url","Discover","Get","RecoverOrphans","GraffitiDiscover","GraffitiGet","GraffitiRecoverOrphans"],"mappings":";;;;;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,SA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AAAF,EAAgB,QAAQE,EAAO;AAAA,IACjC,CACD,GACDjE,EAAS,cAAc,iBAAiB,UAAU,CAACgE,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,QAAQ9D,GAAmBG,CAAQ,GACnC2D,EAAA,QAAQ7D,GAA0BiE,CAAe,GAEjDJ,EAAA,UAAU,oBAAoBU,CAAQ,GACtCV,EAAA,UAAU,eAAeW,CAAG,GAC5BX,EAAA,UAAU,0BAA0BY,CAAc,GAClDZ,EAAA,OAAO,iBAAiB,YAAY3D,GACpC2D,EAAA,OAAO,iBAAiB,mBAAmBI;AAAA,EAAA;AAEnD,GAiBaS,IAAmBH,GASnBI,IAAcH,GASdI,KAAyBH;"}
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,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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,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,6 +1,6 @@
1
1
  import { JSONSchema, GraffitiObject, GraffitiObjectStreamContinueEntry, GraffitiObjectStream, GraffitiObjectStreamContinue } from '@graffiti-garden/api';
2
2
  export declare abstract class Poller<Schema extends JSONSchema> {
3
- abstract poll(onEntry: (entry: GraffitiObjectStreamContinueEntry<Schema> | null) => void): Promise<void>;
3
+ abstract poll(onEntry: (entry: GraffitiObjectStreamContinueEntry<Schema> | null | "clear") => void): Promise<void>;
4
4
  abstract clear(): void;
5
5
  }
6
6
  /**