@graffiti-garden/wrapper-vue 0.6.6 → 0.7.1

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