@graffiti-garden/wrapper-vue 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,40 +1,45 @@
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();
7
- function G() {
8
- const e = _(E);
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
+ 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() {
16
- return G();
15
+ function Z() {
16
+ return b();
17
17
  }
18
- function j() {
19
- const e = _(F);
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
- class U {
26
+ var K = class _ extends Error {
27
27
  constructor(t) {
28
- u(this, "poll", async (t) => {
29
- let r;
30
- const s = this.getter;
28
+ super(t), this.name = "GraffitiErrorNotFound", Object.setPrototypeOf(this, _.prototype);
29
+ }
30
+ };
31
+ class V {
32
+ constructor(t) {
33
+ p(this, "poll", async (t) => {
34
+ let s;
35
+ const r = this.getter;
31
36
  try {
32
- r = await s();
37
+ s = await r();
33
38
  } catch {
34
- this.getter === s && t(null);
39
+ this.getter === r && t(null);
35
40
  return;
36
41
  }
37
- this.getter === s && t({ object: r });
42
+ this.getter === r && t({ object: s });
38
43
  });
39
44
  this.getter = t;
40
45
  }
@@ -43,21 +48,33 @@ class U {
43
48
  }
44
49
  class O {
45
50
  constructor(t) {
46
- u(this, "iterator");
47
- u(this, "continue");
48
- u(this, "poll", async (t) => {
49
- for (this.iterator || (this.continue ? this.iterator = this.continue() : this.iterator = this.streamFactory()); this.iterator; ) {
50
- const r = this.iterator, s = await r.next();
51
- if (r === this.iterator) {
52
- if (s.done) {
53
- s.value && (this.iterator = void 0, this.continue = s.value.continue);
51
+ p(this, "iterator");
52
+ p(this, "continue");
53
+ p(this, "poll", async (t) => {
54
+ if (!this.iterator)
55
+ if (this.continue)
56
+ try {
57
+ this.iterator = this.continue();
58
+ } catch (s) {
59
+ if (s instanceof K)
60
+ t("clear"), this.iterator = this.streamFactory();
61
+ else
62
+ throw s;
63
+ }
64
+ else
65
+ this.iterator = this.streamFactory();
66
+ for (; this.iterator; ) {
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);
54
71
  break;
55
72
  }
56
- if (s.value.error) {
57
- console.error(s.value.error);
73
+ if (r.value.error) {
74
+ console.error(r.value.error);
58
75
  continue;
59
76
  }
60
- t(s.value);
77
+ t(r.value);
61
78
  }
62
79
  }
63
80
  });
@@ -74,15 +91,15 @@ class O {
74
91
  this.iterator = void 0, this.continue = void 0;
75
92
  }
76
93
  }
77
- function T(e, t) {
94
+ function U(e, t) {
78
95
  return !t || e.object.lastModified > t.object.lastModified || e.object.lastModified === t.object.lastModified && !e.tombstone && !!t.tombstone;
79
96
  }
80
- class V {
97
+ class x {
81
98
  constructor() {
82
- u(this, "entry", v());
99
+ p(this, "entry", y());
83
100
  }
84
101
  get result() {
85
- return A(() => {
102
+ return k(() => {
86
103
  const t = this.entry.value;
87
104
  return t && (t.tombstone ? null : t.object);
88
105
  });
@@ -91,240 +108,333 @@ class V {
91
108
  this.entry.value = void 0;
92
109
  }
93
110
  onEntry(t) {
94
- (!t || T(t, this.entry.value)) && (this.entry.value = t);
111
+ if (t === "clear") {
112
+ this.clear();
113
+ return;
114
+ }
115
+ (!t || U(t, this.entry.value)) && (this.entry.value = t);
95
116
  }
96
117
  }
97
118
  class $ {
98
119
  constructor(t) {
99
- u(this, "results", v([]));
100
- u(this, "resultsRaw", /* @__PURE__ */ new Map());
101
- u(this, "batchFlattenTimer");
120
+ p(this, "results", y([]));
121
+ p(this, "resultsRaw", /* @__PURE__ */ new Map());
122
+ p(this, "batchFlattenTimer");
102
123
  this.graffiti = t;
103
124
  }
104
125
  clear() {
105
126
  this.resultsRaw.clear(), this.results.value = [], clearTimeout(this.batchFlattenTimer), this.batchFlattenTimer = void 0;
106
127
  }
107
128
  flattenResults() {
108
- 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), []);
109
130
  }
110
131
  onEntry(t) {
111
132
  if (!t) return;
112
- const r = this.resultsRaw.get(t.object.url);
113
- T(t, r) && (this.resultsRaw.set(t.object.url, t), this.batchFlattenTimer || (this.batchFlattenTimer = setTimeout(() => {
133
+ if (t === "clear") {
134
+ this.clear();
135
+ return;
136
+ }
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(() => {
114
139
  this.flattenResults(), this.batchFlattenTimer = void 0;
115
140
  }, 0)));
116
141
  }
117
142
  }
118
- function S(e, t, r, s) {
119
- let o;
120
- async function i() {
121
- o = r();
122
- for await (const l of o) {
123
- if (l.error) {
124
- 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);
125
150
  continue;
126
151
  }
127
- e.onEntry(l);
152
+ e.onEntry(f);
128
153
  }
129
154
  }
130
- const n = () => t.poll(e.onEntry.bind(e)), c = v(!1);
131
- return C(
132
- s,
133
- async (l, a) => {
134
- if (JSON.stringify(l) !== JSON.stringify(a)) {
135
- o == null || o.return(null), e.clear(), t.clear(), i(), 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;
136
171
  try {
137
- await n();
172
+ await c();
138
173
  } finally {
139
- c.value = !1;
174
+ l.value = !1;
140
175
  }
141
176
  }
142
177
  },
143
178
  {
144
179
  immediate: !0
145
180
  }
146
- ), J(() => o == null ? void 0 : o.return(null)), { poll: n, isPolling: c };
181
+ ), C(() => i == null ? void 0 : i.return(null)), { poll: c, isInitialPolling: l };
147
182
  }
148
183
  function z(e, t) {
149
184
  return () => {
150
- const r = m(t);
151
- 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;
152
187
  };
153
188
  }
154
- function d(e) {
189
+ function v(e) {
155
190
  return e.map((t) => t());
156
191
  }
157
- function B(e, t, r) {
158
- const s = G(), o = j(), i = () => m(e), n = () => m(t), c = z(o, r), l = [i, n, c], a = () => s.synchronizeDiscover(...d(l)), g = () => s.discover(...d(l)), p = new $(s), y = new O(g), { poll: b, isPolling: w } = S(
159
- p,
160
- y,
161
- a,
162
- 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
163
199
  );
164
200
  return {
165
201
  /**
166
- * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
167
- * 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.
168
204
  */
169
- results: p.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
+ },
170
214
  /**
171
215
  * A method to poll for new results.
172
216
  */
173
- poll: b,
217
+ poll: P,
174
218
  /**
175
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
176
- * 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.
177
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.
226
+ */
227
+ isInitialPolling: w,
228
+ /**
229
+ * @deprecated Use {@link isInitialPolling} instead.
178
230
  */
179
- isPolling: w
231
+ get isPolling() {
232
+ return console.warn(
233
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
234
+ ), this.isInitialPolling;
235
+ }
180
236
  };
181
237
  }
182
- function W(e, t, r) {
183
- const s = G(), o = j(), i = () => m(e), n = () => m(t), c = z(o, r), l = [
184
- i,
185
- n,
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,
241
+ a,
186
242
  c
187
- ], a = () => s.synchronizeGet(...d(l)), g = new V(), p = () => s.get(...d(l)), y = new U(p), { poll: b, isPolling: w } = S(
243
+ ], f = () => n.synchronizeGet(...v(l)), g = new x(), m = () => n.get(...v(l)), G = new V(m), { poll: P, isInitialPolling: w } = S(
188
244
  g,
189
- y,
190
- a,
191
- l
245
+ G,
246
+ f,
247
+ l,
248
+ r
192
249
  );
193
250
  return {
194
251
  /**
195
- * 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
196
253
  * the retrieved Graffiti object, if it exists. If the object has been deleted,
197
254
  * the result is `null`. If the object is still being fetched, the result is `undefined`.
198
255
  */
199
- result: g.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
+ },
200
265
  /**
201
266
  * A method to poll for new results.
202
267
  */
203
- poll: b,
268
+ poll: P,
204
269
  /**
205
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
206
- * 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.
207
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.
208
281
  */
209
- isPolling: w
282
+ get isPolling() {
283
+ return console.warn(
284
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
285
+ ), this.isInitialPolling;
286
+ }
210
287
  };
211
288
  }
212
- function q(e, t) {
213
- const r = G(), i = [() => m(e), () => m(t)], n = () => r.synchronizeRecoverOrphans(...d(i)), c = new $(r), l = () => r.recoverOrphans(...d(i)), a = new O(l), { poll: g, isPolling: p } = S(
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(
214
291
  c,
292
+ f,
215
293
  a,
216
- n,
217
- i
294
+ o,
295
+ s
218
296
  );
219
297
  return {
220
298
  /**
221
- * A [Ref](https://vuejs.org/api/reactivity-core.html#ref) that contains
222
- * 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.
223
305
  */
224
- results: c.results,
306
+ get results() {
307
+ return console.warn(
308
+ "The `result` property is deprecated. Use `object` instead."
309
+ ), this.objects;
310
+ },
225
311
  /**
226
312
  * A method to poll for new results.
227
313
  */
228
314
  poll: g,
229
315
  /**
230
- * A boolean [Ref](https://vuejs.org/api/reactivity-core.html#ref)
231
- * 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.
232
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.
323
+ */
324
+ isInitialPolling: m,
325
+ /**
326
+ * @deprecated Use {@link isInitialPolling} instead.
233
327
  */
234
- isPolling: p
328
+ get isPolling() {
329
+ return console.warn(
330
+ "The `isPolling` property is deprecated. Use `isInitialPolling` instead."
331
+ ), this.isInitialPolling;
332
+ }
235
333
  };
236
334
  }
237
- const D = /* @__PURE__ */ P({
335
+ const D = /* @__PURE__ */ j({
238
336
  __name: "Discover",
239
337
  props: {
240
338
  channels: {},
241
339
  schema: {},
242
- session: {}
340
+ session: {},
341
+ autopoll: { type: Boolean }
243
342
  },
244
343
  setup(e) {
245
- const t = e, { results: r, poll: s, isPolling: o } = B(
344
+ const t = e, { objects: s, results: r, poll: n, isPolling: i, isInitialPolling: o } = W(
246
345
  h(t, "channels"),
247
346
  h(t, "schema"),
248
- h(t, "session")
347
+ h(t, "session"),
348
+ h(t, "autopoll")
249
349
  );
250
- return (i, n) => R(i.$slots, "default", {
251
- results: f(r),
252
- poll: f(s),
253
- 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)
254
356
  });
255
357
  }
256
- }), M = /* @__PURE__ */ P({
358
+ }), N = /* @__PURE__ */ j({
257
359
  __name: "Get",
258
360
  props: {
259
361
  url: {},
260
362
  schema: {},
261
- session: {}
363
+ session: {},
364
+ autopoll: { type: Boolean }
262
365
  },
263
366
  setup(e) {
264
- const t = e, { result: r, poll: s, isPolling: o } = W(
367
+ const t = e, { object: s, result: r, poll: n, isPolling: i, isInitialPolling: o } = q(
265
368
  h(t, "url"),
266
369
  h(t, "schema"),
267
- h(t, "session")
370
+ h(t, "session"),
371
+ h(t, "autopoll")
268
372
  );
269
- return (i, n) => R(i.$slots, "default", {
270
- result: f(r),
271
- poll: f(s),
272
- 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)
273
379
  });
274
380
  }
275
- }), N = /* @__PURE__ */ P({
381
+ }), M = /* @__PURE__ */ j({
276
382
  __name: "RecoverOrphans",
277
383
  props: {
278
384
  schema: {},
279
- session: {}
385
+ session: {},
386
+ autopoll: { type: Boolean }
280
387
  },
281
388
  setup(e) {
282
- const t = e, { results: r, poll: s, isPolling: o } = q(
389
+ const t = e, { objects: s, results: r, poll: n, isPolling: i, isInitialPolling: o } = H(
283
390
  h(t, "schema"),
284
- h(t, "session")
391
+ h(t, "session"),
392
+ h(t, "autopoll")
285
393
  );
286
- return (i, n) => R(i.$slots, "default", {
287
- results: f(r),
288
- poll: f(s),
289
- 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)
290
400
  });
291
401
  }
292
- }), Y = {
402
+ }), tt = {
293
403
  install(e, t) {
294
- const r = t.graffiti, s = new K(r), o = v(void 0);
295
- s.sessionEvents.addEventListener("initialized", async (i) => {
296
- const n = i.detail;
297
- if (n && n.error && console.error(n.error), n && n.href) {
298
- const c = e.config.globalProperties.$router;
299
- if (c) {
300
- const l = c.options.history.base, a = new URL(n.href);
301
- 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);
302
412
  }
303
413
  }
304
- o.value || (o.value = null);
305
- }), s.sessionEvents.addEventListener("login", (i) => {
306
- const n = i.detail;
307
- if (n.error) {
308
- console.error("Error logging in:"), console.error(n.error);
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);
309
419
  return;
310
420
  } else
311
- o.value = n.session;
312
- }), s.sessionEvents.addEventListener("logout", (i) => {
313
- const n = i.detail;
314
- n.error ? (console.error("Error logging out:"), console.error(n.error)) : o.value = null;
315
- }), e.provide(E, s), e.provide(F, o), e.component("GraffitiDiscover", D), e.component("GraffitiGet", M), e.component("GraffitiRecoverOrphans", N), e.config.globalProperties.$graffiti = s, e.config.globalProperties.$graffitiSession = o;
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;
316
426
  }
317
- }, Z = D, I = M, tt = N;
427
+ }, et = D, st = N, rt = M;
318
428
  export {
319
- Z as GraffitiDiscover,
320
- I as GraffitiGet,
321
- Y as GraffitiPlugin,
322
- tt as GraffitiRecoverOrphans,
323
- X as useGraffiti,
324
- B as useGraffitiDiscover,
325
- W as useGraffitiGet,
326
- q as useGraffitiRecoverOrphans,
327
- j as useGraffitiSession,
328
- G as useGraffitiSynchronize
429
+ et as GraffitiDiscover,
430
+ st as GraffitiGet,
431
+ tt as GraffitiPlugin,
432
+ rt as GraffitiRecoverOrphans,
433
+ Z as useGraffiti,
434
+ W as useGraffitiDiscover,
435
+ q as useGraffitiGet,
436
+ H as useGraffitiRecoverOrphans,
437
+ T as useGraffitiSession,
438
+ b as useGraffitiSynchronize
329
439
  };
330
440
  //# sourceMappingURL=plugin.mjs.map