@graffiti-garden/wrapper-vue 0.6.4 → 0.6.6

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,10 +1,10 @@
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
- function G() {
1
+ var B = Object.defineProperty;
2
+ var L = (e, t, s) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
+ var p = (e, t, s) => L(e, typeof t != "symbol" ? t + "" : t, s);
4
+ import { inject as E, ref as y, computed as k, watch as A, onScopeDispose as C, toValue as d, defineComponent as j, toRef as h, renderSlot as R, unref as u } from "vue";
5
+ import { GraffitiSynchronize as J } from "@graffiti-garden/wrapper-synchronize";
6
+ const F = Symbol(), I = Symbol();
7
+ function b() {
8
8
  const e = E(F);
9
9
  if (!e)
10
10
  throw new Error(
@@ -13,68 +13,68 @@ function G() {
13
13
  return e;
14
14
  }
15
15
  function Z() {
16
- return G();
16
+ return b();
17
17
  }
18
- function j() {
19
- const e = E(_);
18
+ function T() {
19
+ const e = E(I);
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
- var V = class O extends Error {
26
+ var K = class _ extends Error {
27
27
  constructor(t) {
28
- super(t), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, O.prototype);
28
+ super(t), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, _.prototype);
29
29
  }
30
30
  };
31
- class x {
31
+ class V {
32
32
  constructor(t) {
33
- u(this, "poll", async (t) => {
34
- let r;
35
- const s = this.getter;
33
+ p(this, "poll", async (t) => {
34
+ let s;
35
+ const r = this.getter;
36
36
  try {
37
- r = await s();
37
+ s = await r();
38
38
  } catch {
39
- this.getter === s && t(null);
39
+ this.getter === r && t(null);
40
40
  return;
41
41
  }
42
- this.getter === s && t({ object: r });
42
+ this.getter === r && t({ object: s });
43
43
  });
44
44
  this.getter = t;
45
45
  }
46
46
  clear() {
47
47
  }
48
48
  }
49
- class T {
49
+ class O {
50
50
  constructor(t) {
51
- u(this, "iterator");
52
- u(this, "continue");
53
- u(this, "poll", async (t) => {
51
+ p(this, "iterator");
52
+ p(this, "continue");
53
+ p(this, "poll", async (t) => {
54
54
  if (!this.iterator)
55
55
  if (this.continue)
56
56
  try {
57
57
  this.iterator = this.continue();
58
- } catch (r) {
59
- if (r instanceof V)
58
+ } catch (s) {
59
+ if (s instanceof K)
60
60
  t("clear"), this.iterator = this.streamFactory();
61
61
  else
62
- throw r;
62
+ throw s;
63
63
  }
64
64
  else
65
65
  this.iterator = this.streamFactory();
66
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);
67
+ const s = this.iterator, r = await s.next();
68
+ if (s === this.iterator) {
69
+ if (r.done) {
70
+ r.value && (this.iterator = void 0, this.continue = r.value.continue);
71
71
  break;
72
72
  }
73
- if (s.value.error) {
74
- console.error(s.value.error);
73
+ if (r.value.error) {
74
+ console.error(r.value.error);
75
75
  continue;
76
76
  }
77
- t(s.value);
77
+ t(r.value);
78
78
  }
79
79
  }
80
80
  });
@@ -91,15 +91,15 @@ class T {
91
91
  this.iterator = void 0, this.continue = void 0;
92
92
  }
93
93
  }
94
- function $(e, t) {
94
+ function U(e, t) {
95
95
  return !t || e.object.lastModified > t.object.lastModified || e.object.lastModified === t.object.lastModified && !e.tombstone && !!t.tombstone;
96
96
  }
97
- class B {
97
+ class x {
98
98
  constructor() {
99
- u(this, "entry", v());
99
+ p(this, "entry", y());
100
100
  }
101
101
  get result() {
102
- return C(() => {
102
+ return k(() => {
103
103
  const t = this.entry.value;
104
104
  return t && (t.tombstone ? null : t.object);
105
105
  });
@@ -112,21 +112,21 @@ class B {
112
112
  this.clear();
113
113
  return;
114
114
  }
115
- (!t || $(t, this.entry.value)) && (this.entry.value = t);
115
+ (!t || U(t, this.entry.value)) && (this.entry.value = t);
116
116
  }
117
117
  }
118
- class z {
118
+ class $ {
119
119
  constructor(t) {
120
- u(this, "results", v([]));
121
- u(this, "resultsRaw", /* @__PURE__ */ new Map());
122
- u(this, "batchFlattenTimer");
120
+ p(this, "results", y([]));
121
+ p(this, "resultsRaw", /* @__PURE__ */ new Map());
122
+ p(this, "batchFlattenTimer");
123
123
  this.graffiti = t;
124
124
  }
125
125
  clear() {
126
126
  this.resultsRaw.clear(), this.results.value = [], clearTimeout(this.batchFlattenTimer), this.batchFlattenTimer = void 0;
127
127
  }
128
128
  flattenResults() {
129
- this.results.value = Array.from(this.resultsRaw.values()).reduce((t, r) => (r.tombstone || t.push(r.object), t), []);
129
+ this.results.value = Array.from(this.resultsRaw.values()).reduce((t, s) => (s.tombstone || t.push(s.object), t), []);
130
130
  }
131
131
  onEntry(t) {
132
132
  if (!t) return;
@@ -134,222 +134,307 @@ class z {
134
134
  this.clear();
135
135
  return;
136
136
  }
137
- const r = this.resultsRaw.get(t.object.url);
138
- $(t, r) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
137
+ const s = this.resultsRaw.get(t.object.url);
138
+ U(t, s) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
139
139
  this.flattenResults(), this.batchFlattenTimer = void 0;
140
140
  }, 0)));
141
141
  }
142
142
  }
143
- function S(e, t, r, s) {
144
- let o;
145
- async function n() {
146
- o = r();
147
- for await (const l of o) {
148
- if (l.error) {
149
- console.error(l.error);
143
+ function S(e, t, s, r, n) {
144
+ let i;
145
+ async function o() {
146
+ i = s();
147
+ for await (const f of i) {
148
+ if (f.error) {
149
+ console.error(f.error);
150
150
  continue;
151
151
  }
152
- e.onEntry(l);
152
+ e.onEntry(f);
153
153
  }
154
154
  }
155
- const i = () => t.poll(e.onEntry.bind(e)), c = v(!1);
156
- return J(
157
- s,
158
- async (l, a) => {
159
- if (JSON.stringify(l) !== JSON.stringify(a)) {
160
- o == null || o.return(null), e.clear(), t.clear(), n(), c.value = !0;
155
+ let a = !1;
156
+ const c = async () => {
157
+ if (!a) {
158
+ a = !0;
159
+ try {
160
+ await t.poll(e.onEntry.bind(e));
161
+ } finally {
162
+ a = !1, d(n) && c();
163
+ }
164
+ }
165
+ }, l = y(!1);
166
+ return A(
167
+ r,
168
+ async (f, g) => {
169
+ if (JSON.stringify(f) !== JSON.stringify(g)) {
170
+ i == null || i.return(null), e.clear(), t.clear(), o(), l.value = !0;
161
171
  try {
162
- await i();
172
+ await c();
163
173
  } finally {
164
- c.value = !1;
174
+ l.value = !1;
165
175
  }
166
176
  }
167
177
  },
168
178
  {
169
179
  immediate: !0
170
180
  }
171
- ), K(() => o == null ? void 0 : o.return(null)), { poll: i, isPolling: c };
181
+ ), C(() => i == null ? void 0 : i.return(null)), { poll: c, isInitialPolling: l };
172
182
  }
173
- function D(e, t) {
183
+ function z(e, t) {
174
184
  return () => {
175
- const r = m(t);
176
- return r === void 0 ? e == null ? void 0 : e.value : r;
185
+ const s = d(t);
186
+ return s === void 0 ? e == null ? void 0 : e.value : s;
177
187
  };
178
188
  }
179
- function d(e) {
189
+ function v(e) {
180
190
  return e.map((t) => t());
181
191
  }
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,
185
- y,
186
- a,
187
- l
192
+ function W(e, t, s, r = !1) {
193
+ const n = b(), i = T(), o = () => d(e), a = () => d(t), c = z(i, s), l = [o, a, c], f = () => n.synchronizeDiscover(...v(l)), g = () => n.discover(...v(l)), m = new $(n), G = new O(g), { poll: P, isInitialPolling: w } = S(
194
+ m,
195
+ G,
196
+ f,
197
+ l,
198
+ r
188
199
  );
189
200
  return {
190
201
  /**
191
- * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
192
- * an array of Graffiti objects. All tombstoned objects have been filtered out.
202
+ * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
203
+ * an array of Graffiti objects.
193
204
  */
194
- results: g.results,
205
+ objects: m.results,
206
+ /**
207
+ * @deprecated Use {@link objects} instead.
208
+ */
209
+ get results() {
210
+ return console.warn(
211
+ "The `results` property is deprecated. Use `objects` instead."
212
+ ), this.objects;
213
+ },
195
214
  /**
196
215
  * A method to poll for new results.
197
216
  */
198
- poll: b,
217
+ poll: P,
199
218
  /**
200
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
201
- * that indicates if the poll is currently running.
219
+ * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
220
+ * that indicates if the *first* poll is currently running.
202
221
  * Useful to show a loading spinner or disable a button.
222
+ *
223
+ * This also tracks new polls when the arguments have changed,
224
+ * but it does not track ongoing polls from either calling
225
+ * {@link poll} or using the `autopoll` argument.
203
226
  */
204
- isPolling: w
227
+ isInitialPolling: w,
228
+ /**
229
+ * @deprecated Use {@link isInitialPolling} instead.
230
+ */
231
+ get isPolling() {
232
+ return console.warn(
233
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
234
+ ), this.isInitialPolling;
235
+ }
205
236
  };
206
237
  }
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,
210
- i,
211
- c
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,
214
- y,
238
+ function q(e, t, s, r = !1) {
239
+ const n = b(), i = T(), o = () => d(e), a = () => d(t), c = z(i, s), l = [
240
+ o,
215
241
  a,
216
- l
242
+ c
243
+ ], f = () => n.synchronizeGet(...v(l)), g = new x(), m = () => n.get(...v(l)), G = new V(m), { poll: P, isInitialPolling: w } = S(
244
+ g,
245
+ G,
246
+ f,
247
+ l,
248
+ r
217
249
  );
218
250
  return {
219
251
  /**
220
- * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
252
+ * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
221
253
  * the retrieved Graffiti object, if it exists. If the object has been deleted,
222
254
  * the result is `null`. If the object is still being fetched, the result is `undefined`.
223
255
  */
224
- result: p.result,
256
+ object: g.result,
257
+ /**
258
+ * @deprecated Use {@link object} instead.
259
+ */
260
+ get result() {
261
+ return console.warn(
262
+ "The `result` property is deprecated. Use `object` instead."
263
+ ), this.object;
264
+ },
225
265
  /**
226
266
  * A method to poll for new results.
227
267
  */
228
- poll: b,
268
+ poll: P,
229
269
  /**
230
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
231
- * that indicates if the poll is currently running.
270
+ * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
271
+ * that indicates if the *first* poll is currently running.
232
272
  * Useful to show a loading spinner or disable a button.
273
+ *
274
+ * This also tracks new polls when the arguments have changed,
275
+ * but it does not track ongoing polls from either calling
276
+ * {@link poll} or using the `autopoll` argument.
277
+ */
278
+ isInitialPolling: w,
279
+ /**
280
+ * @deprecated Use {@link isInitialPolling} instead.
233
281
  */
234
- isPolling: w
282
+ get isPolling() {
283
+ return console.warn(
284
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
285
+ ), this.isInitialPolling;
286
+ }
235
287
  };
236
288
  }
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(
289
+ function H(e, t, s = !1) {
290
+ const r = b(), o = [() => d(e), () => d(t)], a = () => r.synchronizeRecoverOrphans(...v(o)), c = new $(r), l = () => r.recoverOrphans(...v(o)), f = new O(l), { poll: g, isInitialPolling: m } = S(
239
291
  c,
292
+ f,
240
293
  a,
241
- i,
242
- n
294
+ o,
295
+ s
243
296
  );
244
297
  return {
245
298
  /**
246
- * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
247
- * an array of Graffiti objects. All tombstoned objects have been filtered out.
299
+ * A [ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
300
+ * an array of Graffiti objects.
301
+ */
302
+ objects: c.results,
303
+ /**
304
+ * @deprecated Use {@link objects} instead.
248
305
  */
249
- results: c.results,
306
+ get results() {
307
+ return console.warn(
308
+ "The `result` property is deprecated. Use `object` instead."
309
+ ), this.objects;
310
+ },
250
311
  /**
251
312
  * A method to poll for new results.
252
313
  */
253
- poll: p,
314
+ poll: g,
254
315
  /**
255
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
256
- * that indicates if the poll is currently running.
316
+ * A boolean [ref](https://vuejs.org/api/reactivity-core.html#ref)
317
+ * that indicates if the *first* poll is currently running.
257
318
  * Useful to show a loading spinner or disable a button.
319
+ *
320
+ * This also tracks new polls when the arguments have changed,
321
+ * but it does not track ongoing polls from either calling
322
+ * {@link poll} or using the `autopoll` argument.
258
323
  */
259
- isPolling: g
324
+ isInitialPolling: m,
325
+ /**
326
+ * @deprecated Use {@link isInitialPolling} instead.
327
+ */
328
+ get isPolling() {
329
+ return console.warn(
330
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
331
+ ), this.isInitialPolling;
332
+ }
260
333
  };
261
334
  }
262
- const N = /* @__PURE__ */ P({
335
+ const D = /* @__PURE__ */ j({
263
336
  __name: "Discover",
264
337
  props: {
265
338
  channels: {},
266
339
  schema: {},
267
- session: {}
340
+ session: {},
341
+ autopoll: { type: Boolean }
268
342
  },
269
343
  setup(e) {
270
- const t = e, { results: r, poll: s, isPolling: o } = W(
344
+ const t = e, { objects: s, results: r, poll: n, isPolling: i, isInitialPolling: o } = W(
271
345
  h(t, "channels"),
272
346
  h(t, "schema"),
273
- h(t, "session")
347
+ h(t, "session"),
348
+ h(t, "autopoll")
274
349
  );
275
- return (n, i) => R(n.$slots, "default", {
276
- results: f(r),
277
- poll: f(s),
278
- isPolling: f(o)
350
+ return (a, c) => R(a.$slots, "default", {
351
+ objects: u(s),
352
+ results: u(r),
353
+ poll: u(n),
354
+ isPolling: u(i),
355
+ isInitialPolling: u(o)
279
356
  });
280
357
  }
281
- }), M = /* @__PURE__ */ P({
358
+ }), N = /* @__PURE__ */ j({
282
359
  __name: "Get",
283
360
  props: {
284
361
  url: {},
285
362
  schema: {},
286
- session: {}
363
+ session: {},
364
+ autopoll: { type: Boolean }
287
365
  },
288
366
  setup(e) {
289
- const t = e, { result: r, poll: s, isPolling: o } = q(
367
+ const t = e, { object: s, result: r, poll: n, isPolling: i, isInitialPolling: o } = q(
290
368
  h(t, "url"),
291
369
  h(t, "schema"),
292
- h(t, "session")
370
+ h(t, "session"),
371
+ h(t, "autopoll")
293
372
  );
294
- return (n, i) => R(n.$slots, "default", {
295
- result: f(r),
296
- poll: f(s),
297
- isPolling: f(o)
373
+ return (a, c) => R(a.$slots, "default", {
374
+ object: u(s),
375
+ result: u(r),
376
+ poll: u(n),
377
+ isPolling: u(i),
378
+ isInitialPolling: u(o)
298
379
  });
299
380
  }
300
- }), L = /* @__PURE__ */ P({
381
+ }), M = /* @__PURE__ */ j({
301
382
  __name: "RecoverOrphans",
302
383
  props: {
303
384
  schema: {},
304
- session: {}
385
+ session: {},
386
+ autopoll: { type: Boolean }
305
387
  },
306
388
  setup(e) {
307
- const t = e, { results: r, poll: s, isPolling: o } = H(
389
+ const t = e, { objects: s, results: r, poll: n, isPolling: i, isInitialPolling: o } = H(
308
390
  h(t, "schema"),
309
- h(t, "session")
391
+ h(t, "session"),
392
+ h(t, "autopoll")
310
393
  );
311
- return (n, i) => R(n.$slots, "default", {
312
- results: f(r),
313
- poll: f(s),
314
- isPolling: f(o)
394
+ return (a, c) => R(a.$slots, "default", {
395
+ objects: u(s),
396
+ results: u(r),
397
+ poll: u(n),
398
+ isPolling: u(i),
399
+ isInitialPolling: u(o)
315
400
  });
316
401
  }
317
- }), I = {
402
+ }), tt = {
318
403
  install(e, t) {
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) {
323
- const c = e.config.globalProperties.$router;
324
- if (c) {
325
- const l = c.options.history.base, a = new URL(i.href);
326
- a.pathname.startsWith(l) && (a.pathname = a.pathname.slice(l.length)), await c.replace(a.pathname + a.search + a.hash);
404
+ const s = t.graffiti, r = new J(s), n = y(void 0);
405
+ r.sessionEvents.addEventListener("initialized", async (i) => {
406
+ const o = i.detail;
407
+ if (o && o.error && console.error(o.error), o && o.href) {
408
+ const a = e.config.globalProperties.$router;
409
+ if (a) {
410
+ const c = a.options.history.base, l = new URL(o.href);
411
+ l.pathname.startsWith(c) && (l.pathname = l.pathname.slice(c.length)), await a.replace(l.pathname + l.search + l.hash);
327
412
  }
328
413
  }
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);
414
+ n.value || (n.value = null);
415
+ }), r.sessionEvents.addEventListener("login", (i) => {
416
+ const o = i.detail;
417
+ if (o.error) {
418
+ console.error("Error logging in:"), console.error(o.error);
334
419
  return;
335
420
  } else
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;
421
+ n.value = o.session;
422
+ }), r.sessionEvents.addEventListener("logout", (i) => {
423
+ const o = i.detail;
424
+ o.error ? (console.error("Error logging out:"), console.error(o.error)) : n.value = null;
425
+ }), e.provide(F, r), e.provide(I, n), e.component("GraffitiDiscover", D), e.component("GraffitiGet", N), e.component("GraffitiRecoverOrphans", M), e.config.globalProperties.$graffiti = r, e.config.globalProperties.$graffitiSession = n;
341
426
  }
342
- }, tt = N, et = M, rt = L;
427
+ }, et = D, st = N, rt = M;
343
428
  export {
344
- tt as GraffitiDiscover,
345
- et as GraffitiGet,
346
- I as GraffitiPlugin,
429
+ et as GraffitiDiscover,
430
+ st as GraffitiGet,
431
+ tt as GraffitiPlugin,
347
432
  rt as GraffitiRecoverOrphans,
348
433
  Z as useGraffiti,
349
434
  W as useGraffitiDiscover,
350
435
  q as useGraffitiGet,
351
436
  H as useGraffitiRecoverOrphans,
352
- j as useGraffitiSession,
353
- G as useGraffitiSynchronize
437
+ T as useGraffitiSession,
438
+ b as useGraffitiSynchronize
354
439
  };
355
440
  //# sourceMappingURL=plugin.mjs.map