@nylas/react 1.1.0-canary.5 → 1.1.0-canary.7

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.
Files changed (96) hide show
  1. package/dist/{elements-dc5b338e-e87f79b6.js → elements-dc5b338e-6078b875.js} +1 -1
  2. package/dist/{elements-dc5b338e-29ef67ec.cjs → elements-dc5b338e-96e197ca.cjs} +1 -1
  3. package/dist/{focus-visible-e8093c16-61d506d2.cjs → focus-visible-e8093c16-018ffd63.cjs} +1 -1
  4. package/dist/{focus-visible-e8093c16-e7357f74.js → focus-visible-e8093c16-ab01d60a.js} +1 -1
  5. package/dist/{index-f9ba9aa8.js → index-1fd24ccf.js} +1039 -1428
  6. package/dist/index-823fdc6f.cjs +36 -0
  7. package/dist/react.cjs +1 -1
  8. package/dist/react.js +52 -52
  9. package/package.json +3 -3
  10. package/dist/add-circle-icon_22.entry-9f634efd.js +0 -1731
  11. package/dist/add-circle-icon_22.entry-e7ec6c34.cjs +0 -1
  12. package/dist/archive-icon_7.entry-24bac466.js +0 -75
  13. package/dist/archive-icon_7.entry-6649ed76.cjs +0 -1
  14. package/dist/arrow-icon.entry-1fffd526.cjs +0 -1
  15. package/dist/arrow-icon.entry-82e59ce4.js +0 -15
  16. package/dist/bold-icon_3.entry-5a01fecf.cjs +0 -1
  17. package/dist/bold-icon_3.entry-72e585da.js +0 -35
  18. package/dist/calendar-cancel-icon.entry-0b52bdc9.cjs +0 -1
  19. package/dist/calendar-cancel-icon.entry-247b530c.js +0 -15
  20. package/dist/calendar-check-icon_2.entry-d7bb76c7.cjs +0 -1
  21. package/dist/calendar-check-icon_2.entry-dbb2df49.js +0 -25
  22. package/dist/calendar-icon.entry-911773c4.cjs +0 -1
  23. package/dist/calendar-icon.entry-d64cb3d3.js +0 -15
  24. package/dist/chevron-icon_3.entry-b72f4cdb.cjs +0 -1
  25. package/dist/chevron-icon_3.entry-db9f8217.js +0 -117
  26. package/dist/close-icon.entry-9d141bb4.js +0 -15
  27. package/dist/close-icon.entry-da590fa2.cjs +0 -1
  28. package/dist/constants-6ee60d6d-09ee73d9.cjs +0 -15
  29. package/dist/constants-6ee60d6d-d5928e79.js +0 -3740
  30. package/dist/document-refresh-icon.entry-5e8cc2f0.cjs +0 -1
  31. package/dist/document-refresh-icon.entry-ee9632d7.js +0 -15
  32. package/dist/forward-icon_6.entry-cac8473a.cjs +0 -3
  33. package/dist/forward-icon_6.entry-f054ad9d.js +0 -953
  34. package/dist/globe-icon.entry-2fde6ac4.js +0 -15
  35. package/dist/globe-icon.entry-bc484551.cjs +0 -1
  36. package/dist/google-logo-icon_4.entry-a9848399.cjs +0 -1
  37. package/dist/google-logo-icon_4.entry-dca87e45.js +0 -349
  38. package/dist/index-22f7e49c.cjs +0 -37
  39. package/dist/index.es-f57e612a-1d17c676.js +0 -3137
  40. package/dist/index.es-f57e612a-95ca3e17.cjs +0 -7
  41. package/dist/info-icon_2.entry-dbf3931a.js +0 -34
  42. package/dist/info-icon_2.entry-e67844eb.cjs +0 -1
  43. package/dist/loading-icon.entry-4566cba8.cjs +0 -1
  44. package/dist/loading-icon.entry-ae4c2d7e.js +0 -15
  45. package/dist/mailbox-store-47fc8a1a-2365f20f.js +0 -380
  46. package/dist/mailbox-store-47fc8a1a-cd3516a7.cjs +0 -1
  47. package/dist/nylas-additional-participants.entry-7c568149.cjs +0 -1
  48. package/dist/nylas-additional-participants.entry-e8426256.js +0 -81
  49. package/dist/nylas-booked-event-card_10.entry-6a664889.cjs +0 -1
  50. package/dist/nylas-booked-event-card_10.entry-ef767733.js +0 -782
  51. package/dist/nylas-form-card.entry-d8506b1f.js +0 -54
  52. package/dist/nylas-form-card.entry-e44169b6.cjs +0 -1
  53. package/dist/nylas-if-state.entry-044c49d2.cjs +0 -1
  54. package/dist/nylas-if-state.entry-98a336df.js +0 -94
  55. package/dist/nylas-list-folders.entry-509f9be4.cjs +0 -1
  56. package/dist/nylas-list-folders.entry-55ce3403.js +0 -120
  57. package/dist/nylas-list-threads.entry-1f57382a.js +0 -70
  58. package/dist/nylas-list-threads.entry-c36e2cf3.cjs +0 -1
  59. package/dist/nylas-login.entry-66f542b8.cjs +0 -1
  60. package/dist/nylas-login.entry-76358c2f.js +0 -73
  61. package/dist/nylas-mailbox-pagination.entry-5562257a.js +0 -101
  62. package/dist/nylas-mailbox-pagination.entry-89b0dd99.cjs +0 -1
  63. package/dist/nylas-mailbox-toolbar-button.entry-573e0429.cjs +0 -1
  64. package/dist/nylas-mailbox-toolbar-button.entry-6b1b5b15.js +0 -82
  65. package/dist/nylas-mailbox.entry-97c503f2.js +0 -134
  66. package/dist/nylas-mailbox.entry-e21a2f50.cjs +0 -1
  67. package/dist/nylas-provider.entry-07e1e26a.js +0 -145
  68. package/dist/nylas-provider.entry-61899957.cjs +0 -1
  69. package/dist/nylas-scheduler-editor.entry-60fe38ce.cjs +0 -7
  70. package/dist/nylas-scheduler-editor.entry-e326c9de.js +0 -2275
  71. package/dist/nylas-scheduling.entry-be0cc090.js +0 -235
  72. package/dist/nylas-scheduling.entry-d88289db.cjs +0 -1
  73. package/dist/nylas-threads-refresh.entry-8201f8dd.js +0 -74
  74. package/dist/nylas-threads-refresh.entry-c71ee775.cjs +0 -1
  75. package/dist/nylas-threads-search.entry-912a90a4.cjs +0 -1
  76. package/dist/nylas-threads-search.entry-fc477e01.js +0 -69
  77. package/dist/nylas-view-thread.entry-af418ddb.cjs +0 -1
  78. package/dist/nylas-view-thread.entry-d2953ea8.js +0 -203
  79. package/dist/people-icon.entry-4b598fde.js +0 -15
  80. package/dist/people-icon.entry-73cfa6f5.cjs +0 -1
  81. package/dist/play-icon_2.entry-1a487abb.cjs +0 -1
  82. package/dist/play-icon_2.entry-d1c2f823.js +0 -25
  83. package/dist/refresh-icon.entry-42d543d0.cjs +0 -1
  84. package/dist/refresh-icon.entry-6aedfce6.js +0 -15
  85. package/dist/register-component-cf5c8420-d3fb6bf9.cjs +0 -1
  86. package/dist/register-component-cf5c8420-dc1bc0a4.js +0 -109
  87. package/dist/scheduler-config-store-6222c0ed-000f1a4f.js +0 -18
  88. package/dist/scheduler-config-store-6222c0ed-758621fb.cjs +0 -1
  89. package/dist/scheduler-store-39d37291-4e8e9ff9.js +0 -293
  90. package/dist/scheduler-store-39d37291-b66c052c.cjs +0 -1
  91. package/dist/time-period-selector.entry-f1e27a00.js +0 -76
  92. package/dist/time-period-selector.entry-fb3d0178.cjs +0 -1
  93. package/dist/translate-icon.entry-0d44b6cb.cjs +0 -1
  94. package/dist/translate-icon.entry-3db947f5.js +0 -15
  95. package/dist/warning-icon.entry-a20657e4.cjs +0 -1
  96. package/dist/warning-icon.entry-a8ea0fe0.js +0 -15
@@ -1,3137 +0,0 @@
1
- import { d as T, u as nr, k as hn } from "./index-f9ba9aa8.js";
2
- class rr {
3
- constructor(e, n, r = !0, s) {
4
- this.automaticComponentRegistration = !0, this.registeredComponents = {}, this.propStateRegistrations = /* @__PURE__ */ new Map(), this.eventListenerRegistrations = /* @__PURE__ */ new Map(), this.host = e, this.stores = n, this.automaticComponentRegistration = r, this.eventOverrides = s, T(`[${this.hostTagName}] Initializing (abstract) provider.`, { eventOverrides: s }), this.registerComponent = this.registerComponent.bind(this), this.getStore = this.getStore.bind(this), Object.keys(this.stores).forEach((i) => {
5
- this.propStateRegistrations.set(i, /* @__PURE__ */ new Map());
6
- });
7
- }
8
- async componentWillLoad(e) {
9
- T(`[${this.hostTagName}] Will load`), this.setupStoreListeners(), this.nylasConnector = e;
10
- const n = Array.from(this.host.querySelectorAll("*")).filter((r) => r.tagName.toLowerCase().startsWith("nylas-"));
11
- T(`[${this.hostTagName}] Found ${n.length} child component(s).`, { childComponents: n }), n.forEach((r) => {
12
- const s = r;
13
- if (!s) {
14
- T(`[~${this.hostTagName}] Component ${s.tagName} does not have a name. Skipping.`);
15
- return;
16
- }
17
- if (!s.registerNylasComponent) {
18
- T(`[~${this.hostTagName}] Component ${s.tagName} is not a component that can be registered. Skipping.`, { component: s });
19
- return;
20
- }
21
- const i = {
22
- element: s,
23
- name: s.tagName.toLowerCase(),
24
- getStoresToProp: s.getStoresToProp,
25
- storeToProps: s.storeToProps,
26
- stateToProps: s.stateToProps,
27
- authToProp: s.authToProp,
28
- eventToProps: s.eventToProps,
29
- connectorToProp: s.connectorToProp,
30
- localPropsToProp: s.localPropsToProp
31
- };
32
- this.registerComponent(i);
33
- });
34
- }
35
- async componentDidLoad() {
36
- T(`[${this.hostTagName}] Did load`);
37
- }
38
- async componentDisconnected() {
39
- Object.values(this.stores).forEach((e) => {
40
- e.dispose();
41
- });
42
- }
43
- async registerComponentHandler(e) {
44
- if (e.stopPropagation(), !this.automaticComponentRegistration) {
45
- T(`[${this.hostTagName}] Automatic component registration disabled. Skipping registration of ${e.detail.name}.`);
46
- return;
47
- }
48
- this.registerComponent(e.detail);
49
- }
50
- async unregisterComponentHandler(e) {
51
- if (e.stopPropagation(), !this.automaticComponentRegistration) {
52
- T(`[${this.hostTagName}] Automatic component registration disabled. Skipping unregistration of ${e.detail.name}.`);
53
- return;
54
- }
55
- this.unregisterComponent(e.detail);
56
- }
57
- registerComponent(e) {
58
- T(`[${this.hostTagName}] Registering component ${e.name}.`);
59
- const n = e.element.dataset.nylasId;
60
- if (n && this.registeredComponents[n]) {
61
- T(`[${this.hostTagName}] Component ${e.name} already registered. Skipping.`);
62
- return;
63
- }
64
- const { stateToProps: r, getStoresToProp: s, eventToProps: i, storeToProps: o, connectorToProp: u, localPropsToProp: a, element: c } = e;
65
- c.dataset.nylasId = nr(), this.registeredComponents[c.dataset.nylasId] = e;
66
- const d = this.eventOverrides;
67
- i == null || i.forEach((l, h) => {
68
- var y;
69
- const f = this.nylasConnector, m = async (g) => {
70
- T(`[${this.hostTagName}] Handling "${e.name}" prop "${String(h)}" event.`, { event: g }), h in d && (T(`[${this.hostTagName}] Found event override for "${String(h)}" event. Calling override.`), await d[h](g, f)), g.defaultPrevented || await l(g, f);
71
- }, p = e.element.dataset.nylasId;
72
- p && !this.eventListenerRegistrations.has(p) && this.eventListenerRegistrations.set(p, []), p && ((y = this.eventListenerRegistrations.get(p)) == null || y.push([c, h, m])), T(`[${this.hostTagName}] Setting "${e.name}" event "${String(h)}" to automcially call NylasConnector method.`);
73
- const v = hn(h.toString());
74
- T(`[${this.hostTagName}] Adding event listener for "${v}" on "${c.tagName}"`), c.addEventListener(v, m);
75
- }), r == null || r.forEach((l, h) => {
76
- var y, g, b, k;
77
- const [f, m] = h.split("."), v = this.getStore(f).state[m];
78
- if (!c.dataset.nylasId) {
79
- T(`[${this.hostTagName}] Component "${e.name}" not registered. Skipping.`, { component: e });
80
- return;
81
- }
82
- this.propStateRegistrations.has(f) || this.propStateRegistrations.set(f, /* @__PURE__ */ new Map()), (y = this.propStateRegistrations.get(f)) != null && y.has(m) ? (k = (b = this.propStateRegistrations.get(f)) == null ? void 0 : b.get(m)) == null || k.push({
83
- elementId: c.dataset.nylasId,
84
- propKey: l
85
- }) : (g = this.propStateRegistrations.get(f)) == null || g.set(m, [
86
- {
87
- elementId: c.dataset.nylasId,
88
- propKey: l
89
- }
90
- ]), c[l.toString()] = v, T(`[${this.hostTagName}] Setting "${e.name}" prop "${l.toString()}" to "${h}" value.`, { stateValue: v });
91
- }), a == null || a.forEach((l, h) => {
92
- const f = this.host[h];
93
- c[l.toString()] = f, T(`[${this.hostTagName}] Setting "${e.name}" prop "${l.toString()}" to the value of "${h}" value.`, { value: h, mappedPropValue: f });
94
- }), s && (c[s == null ? void 0 : s.toString()] = this.getStore, T(`[${this.hostTagName}] Setting "${e.name}" prop "${s.toString()}" to "getStore" method.`)), o == null || o.forEach((l, h) => {
95
- const f = this.getStore(h);
96
- c[l.toString()] = f, T(`[${this.hostTagName}] Setting "${e.name}" prop "${l.toString()}" to "${h}" store.`, { store: f });
97
- }), u && (c[u == null ? void 0 : u.toString()] = this.nylasConnector, T(`[${this.hostTagName}] Setting "${e.name}" prop "${u.toString()}" to "nylasConnector" value.`, { connectorToProp: u })), T(`[${this.hostTagName}] Component ${e.name} registered.`);
98
- }
99
- unregisterComponent(e) {
100
- T(`[${this.hostTagName}] Unregistering component ${e.name}.`);
101
- const n = e.element.dataset.nylasId;
102
- if (!n) {
103
- T(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);
104
- return;
105
- }
106
- if (this.registeredComponents[n]) {
107
- T(`[${this.hostTagName}] Component ${e.name} not registered. Skipping.`);
108
- return;
109
- }
110
- this.propStateRegistrations.forEach((s, i) => {
111
- s.forEach((o, u) => {
112
- var d, l;
113
- const a = (d = this.propStateRegistrations.get(i)) == null ? void 0 : d.get(u), c = a == null ? void 0 : a.filter((h) => h.elementId !== n);
114
- c && ((l = this.propStateRegistrations.get(i)) == null || l.set(u, c));
115
- });
116
- });
117
- const r = this.eventListenerRegistrations.get(n);
118
- r == null || r.forEach(([s, i, o]) => {
119
- const u = hn(i.toString());
120
- T(`[${this.hostTagName}] Removing event listener for "${u}" on "${s.tagName}"`), s.removeEventListener(u, o);
121
- }), delete this.registeredComponents[n];
122
- }
123
- getStore(e) {
124
- const n = this.stores[e];
125
- if (!n)
126
- throw new Error(`[${this.hostTagName}] Store "${e.toString()}" not found.`);
127
- return n;
128
- }
129
- async setupStoreListeners() {
130
- const e = this;
131
- Object.entries(this.stores).forEach(([n, r]) => {
132
- T(`[${e.hostTagName}] Listening for changes in "${n}" store.`), r.use({
133
- set(s, i, o) {
134
- var c;
135
- if (T(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" changed`, { newValue: i, oldValue: o }), i === o) {
136
- T(`[${e.hostTagName}] Store "${n}" state "${s.toString()}" unchanged. Skipping.`);
137
- return;
138
- }
139
- const u = e.registeredComponents;
140
- if (!u) {
141
- T(`[${e.hostTagName}] No registered components found. Skipping.`);
142
- return;
143
- }
144
- const a = ((c = e.propStateRegistrations.get(n)) == null ? void 0 : c.get(s.toString())) || [];
145
- T(`[${e.hostTagName}] Found ${a.length} prop(s) registered for "${s.toString()}" store.`, {
146
- props: a,
147
- propStateRegistrations: e.propStateRegistrations
148
- }), a.forEach(({ elementId: d, propKey: l }) => {
149
- const h = u[d];
150
- if (!h) {
151
- T(`[${e.hostTagName}] Component "${d}" not found. Skipping.`, { component: h });
152
- return;
153
- }
154
- const m = e.getStore(n).state[s];
155
- h.element[l.toString()] = m, T(`[${e.hostTagName}] Setting "${h.name}" prop "${l.toString()}" to "${s.toString()}" value.`, { stateValue: m });
156
- });
157
- }
158
- });
159
- });
160
- }
161
- get hostTagName() {
162
- var e, n;
163
- return ((n = (e = this.host) == null ? void 0 : e.tagName) == null ? void 0 : n.toLowerCase()) ?? "nylas-provider";
164
- }
165
- }
166
- class ns extends rr {
167
- }
168
- const sr = typeof global < "u" ? global : typeof self < "u" ? self : typeof window < "u" ? window : {};
169
- var ir = Object.defineProperty, or = (t, e, n) => e in t ? ir(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, ut = (t, e, n) => (or(t, typeof e != "symbol" ? e + "" : e, n), n), ar = /* @__PURE__ */ ((t) => (t.Error = "error", t.Warning = "warning", t.Info = "info", t.Success = "success", t))(ar || {});
170
- const rs = (t) => "error" in t;
171
- class ss extends Error {
172
- constructor(e) {
173
- super(e == null ? void 0 : e.message), ut(this, "apiError"), this.name = "NylasAPIError", this.stack = new Error().stack, this.apiError = e;
174
- }
175
- }
176
- async function dn(t) {
177
- const e = new TextEncoder().encode(t), n = await crypto.subtle.digest("SHA-256", e), r = Array.from(new Uint8Array(n)).map((s) => s.toString(16).padStart(2, "0")).join("");
178
- return btoa(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
179
- }
180
- const K = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : sr, $ = Object.keys, M = Array.isArray;
181
- function U(t, e) {
182
- return typeof e != "object" || $(e).forEach(function(n) {
183
- t[n] = e[n];
184
- }), t;
185
- }
186
- typeof Promise > "u" || K.Promise || (K.Promise = Promise);
187
- const Be = Object.getPrototypeOf, ur = {}.hasOwnProperty;
188
- function z(t, e) {
189
- return ur.call(t, e);
190
- }
191
- function Pe(t, e) {
192
- typeof e == "function" && (e = e(Be(t))), (typeof Reflect > "u" ? $ : Reflect.ownKeys)(e).forEach((n) => {
193
- ee(t, n, e[n]);
194
- });
195
- }
196
- const Pn = Object.defineProperty;
197
- function ee(t, e, n, r) {
198
- Pn(t, e, U(n && z(n, "get") && typeof n.get == "function" ? { get: n.get, set: n.set, configurable: !0 } : { value: n, configurable: !0, writable: !0 }, r));
199
- }
200
- function ke(t) {
201
- return { from: function(e) {
202
- return t.prototype = Object.create(e.prototype), ee(t.prototype, "constructor", t), { extend: Pe.bind(null, t.prototype) };
203
- } };
204
- }
205
- const lr = Object.getOwnPropertyDescriptor;
206
- function Jt(t, e) {
207
- let n;
208
- return lr(t, e) || (n = Be(t)) && Jt(n, e);
209
- }
210
- const cr = [].slice;
211
- function lt(t, e, n) {
212
- return cr.call(t, e, n);
213
- }
214
- function En(t, e) {
215
- return e(t);
216
- }
217
- function Ie(t) {
218
- if (!t)
219
- throw new Error("Assertion Failed");
220
- }
221
- function Cn(t) {
222
- K.setImmediate ? setImmediate(t) : setTimeout(t, 0);
223
- }
224
- function Tn(t, e) {
225
- return t.reduce((n, r, s) => {
226
- var i = e(r, s);
227
- return i && (n[i[0]] = i[1]), n;
228
- }, {});
229
- }
230
- function te(t, e) {
231
- if (z(t, e))
232
- return t[e];
233
- if (!e)
234
- return t;
235
- if (typeof e != "string") {
236
- for (var n = [], r = 0, s = e.length; r < s; ++r) {
237
- var i = te(t, e[r]);
238
- n.push(i);
239
- }
240
- return n;
241
- }
242
- var o = e.indexOf(".");
243
- if (o !== -1) {
244
- var u = t[e.substr(0, o)];
245
- return u === void 0 ? void 0 : te(u, e.substr(o + 1));
246
- }
247
- }
248
- function H(t, e, n) {
249
- if (t && e !== void 0 && (!("isFrozen" in Object) || !Object.isFrozen(t)))
250
- if (typeof e != "string" && "length" in e) {
251
- Ie(typeof n != "string" && "length" in n);
252
- for (var r = 0, s = e.length; r < s; ++r)
253
- H(t, e[r], n[r]);
254
- } else {
255
- var i = e.indexOf(".");
256
- if (i !== -1) {
257
- var o = e.substr(0, i), u = e.substr(i + 1);
258
- if (u === "")
259
- n === void 0 ? M(t) && !isNaN(parseInt(o)) ? t.splice(o, 1) : delete t[o] : t[o] = n;
260
- else {
261
- var a = t[o];
262
- a && z(t, o) || (a = t[o] = {}), H(a, u, n);
263
- }
264
- } else
265
- n === void 0 ? M(t) && !isNaN(parseInt(e)) ? t.splice(e, 1) : delete t[e] : t[e] = n;
266
- }
267
- }
268
- function An(t) {
269
- var e = {};
270
- for (var n in t)
271
- z(t, n) && (e[n] = t[n]);
272
- return e;
273
- }
274
- const hr = [].concat;
275
- function On(t) {
276
- return hr.apply([], t);
277
- }
278
- const In = "Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(On([8, 16, 32, 64].map((t) => ["Int", "Uint", "Float"].map((e) => e + t + "Array")))).filter((t) => K[t]), dr = In.map((t) => K[t]);
279
- Tn(In, (t) => [t, !0]);
280
- let se = null;
281
- function We(t) {
282
- se = typeof WeakMap < "u" && /* @__PURE__ */ new WeakMap();
283
- const e = Ct(t);
284
- return se = null, e;
285
- }
286
- function Ct(t) {
287
- if (!t || typeof t != "object")
288
- return t;
289
- let e = se && se.get(t);
290
- if (e)
291
- return e;
292
- if (M(t)) {
293
- e = [], se && se.set(t, e);
294
- for (var n = 0, r = t.length; n < r; ++n)
295
- e.push(Ct(t[n]));
296
- } else if (dr.indexOf(t.constructor) >= 0)
297
- e = t;
298
- else {
299
- const i = Be(t);
300
- for (var s in e = i === Object.prototype ? {} : Object.create(i), se && se.set(t, e), t)
301
- z(t, s) && (e[s] = Ct(t[s]));
302
- }
303
- return e;
304
- }
305
- const { toString: fr } = {};
306
- function Tt(t) {
307
- return fr.call(t).slice(8, -1);
308
- }
309
- const At = typeof Symbol < "u" ? Symbol.iterator : "@@iterator", pr = typeof At == "symbol" ? function(t) {
310
- var e;
311
- return t != null && (e = t[At]) && e.apply(t);
312
- } : function() {
313
- return null;
314
- }, _e = {};
315
- function J(t) {
316
- var e, n, r, s;
317
- if (arguments.length === 1) {
318
- if (M(t))
319
- return t.slice();
320
- if (this === _e && typeof t == "string")
321
- return [t];
322
- if (s = pr(t)) {
323
- for (n = []; !(r = s.next()).done; )
324
- n.push(r.value);
325
- return n;
326
- }
327
- if (t == null)
328
- return [t];
329
- if (typeof (e = t.length) == "number") {
330
- for (n = new Array(e); e--; )
331
- n[e] = t[e];
332
- return n;
333
- }
334
- return [t];
335
- }
336
- for (e = arguments.length, n = new Array(e); e--; )
337
- n[e] = arguments[e];
338
- return n;
339
- }
340
- const Zt = typeof Symbol < "u" ? (t) => t[Symbol.toStringTag] === "AsyncFunction" : () => !1;
341
- var G = typeof location < "u" && /^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);
342
- function Kn(t, e) {
343
- G = t, jn = e;
344
- }
345
- var jn = () => !0;
346
- const mr = !new Error("").stack;
347
- function Ee() {
348
- if (mr)
349
- try {
350
- throw new Error();
351
- } catch (t) {
352
- return t;
353
- }
354
- return new Error();
355
- }
356
- function Ot(t, e) {
357
- var n = t.stack;
358
- return n ? (e = e || 0, n.indexOf(t.name) === 0 && (e += (t.name + t.message).split(`
359
- `).length), n.split(`
360
- `).slice(e).filter(jn).map((r) => `
361
- ` + r).join("")) : "";
362
- }
363
- var Rn = ["Unknown", "Constraint", "Data", "TransactionInactive", "ReadOnly", "Version", "NotFound", "InvalidState", "InvalidAccess", "Abort", "Timeout", "QuotaExceeded", "Syntax", "DataClone"], en = ["Modify", "Bulk", "OpenFailed", "VersionChange", "Schema", "Upgrade", "InvalidTable", "MissingAPI", "NoSuchDatabase", "InvalidArgument", "SubTransaction", "Unsupported", "Internal", "DatabaseClosed", "PrematureCommit", "ForeignAwait"].concat(Rn), gr = { VersionChanged: "Database version changed by other database connection", DatabaseClosed: "Database has been closed", Abort: "Transaction aborted", TransactionInactive: "Transaction has already completed or failed", MissingAPI: "IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb" };
364
- function xe(t, e) {
365
- this._e = Ee(), this.name = t, this.message = e;
366
- }
367
- function Nn(t, e) {
368
- return t + ". Errors: " + Object.keys(e).map((n) => e[n].toString()).filter((n, r, s) => s.indexOf(n) === r).join(`
369
- `);
370
- }
371
- function ct(t, e, n, r) {
372
- this._e = Ee(), this.failures = e, this.failedKeys = r, this.successCount = n, this.message = Nn(t, e);
373
- }
374
- function je(t, e) {
375
- this._e = Ee(), this.name = "BulkError", this.failures = Object.keys(e).map((n) => e[n]), this.failuresByPos = e, this.message = Nn(t, e);
376
- }
377
- ke(xe).from(Error).extend({ stack: { get: function() {
378
- return this._stack || (this._stack = this.name + ": " + this.message + Ot(this._e, 2));
379
- } }, toString: function() {
380
- return this.name + ": " + this.message;
381
- } }), ke(ct).from(xe), ke(je).from(xe);
382
- var tn = en.reduce((t, e) => (t[e] = e + "Error", t), {});
383
- const yr = xe;
384
- var C = en.reduce((t, e) => {
385
- var n = e + "Error";
386
- function r(s, i) {
387
- this._e = Ee(), this.name = n, s ? typeof s == "string" ? (this.message = `${s}${i ? `
388
- ` + i : ""}`, this.inner = i || null) : typeof s == "object" && (this.message = `${s.name} ${s.message}`, this.inner = s) : (this.message = gr[e] || n, this.inner = null);
389
- }
390
- return ke(r).from(yr), t[e] = r, t;
391
- }, {});
392
- C.Syntax = SyntaxError, C.Type = TypeError, C.Range = RangeError;
393
- var fn = Rn.reduce((t, e) => (t[e + "Error"] = C[e], t), {}), tt = en.reduce((t, e) => (["Syntax", "Type", "Range"].indexOf(e) === -1 && (t[e + "Error"] = C[e]), t), {});
394
- function I() {
395
- }
396
- function Fe(t) {
397
- return t;
398
- }
399
- function vr(t, e) {
400
- return t == null || t === Fe ? e : function(n) {
401
- return e(t(n));
402
- };
403
- }
404
- function me(t, e) {
405
- return function() {
406
- t.apply(this, arguments), e.apply(this, arguments);
407
- };
408
- }
409
- function br(t, e) {
410
- return t === I ? e : function() {
411
- var n = t.apply(this, arguments);
412
- n !== void 0 && (arguments[0] = n);
413
- var r = this.onsuccess, s = this.onerror;
414
- this.onsuccess = null, this.onerror = null;
415
- var i = e.apply(this, arguments);
416
- return r && (this.onsuccess = this.onsuccess ? me(r, this.onsuccess) : r), s && (this.onerror = this.onerror ? me(s, this.onerror) : s), i !== void 0 ? i : n;
417
- };
418
- }
419
- function wr(t, e) {
420
- return t === I ? e : function() {
421
- t.apply(this, arguments);
422
- var n = this.onsuccess, r = this.onerror;
423
- this.onsuccess = this.onerror = null, e.apply(this, arguments), n && (this.onsuccess = this.onsuccess ? me(n, this.onsuccess) : n), r && (this.onerror = this.onerror ? me(r, this.onerror) : r);
424
- };
425
- }
426
- function _r(t, e) {
427
- return t === I ? e : function(n) {
428
- var r = t.apply(this, arguments);
429
- U(n, r);
430
- var s = this.onsuccess, i = this.onerror;
431
- this.onsuccess = null, this.onerror = null;
432
- var o = e.apply(this, arguments);
433
- return s && (this.onsuccess = this.onsuccess ? me(s, this.onsuccess) : s), i && (this.onerror = this.onerror ? me(i, this.onerror) : i), r === void 0 ? o === void 0 ? void 0 : o : U(r, o);
434
- };
435
- }
436
- function kr(t, e) {
437
- return t === I ? e : function() {
438
- return e.apply(this, arguments) !== !1 && t.apply(this, arguments);
439
- };
440
- }
441
- function nn(t, e) {
442
- return t === I ? e : function() {
443
- var n = t.apply(this, arguments);
444
- if (n && typeof n.then == "function") {
445
- for (var r = this, s = arguments.length, i = new Array(s); s--; )
446
- i[s] = arguments[s];
447
- return n.then(function() {
448
- return e.apply(r, i);
449
- });
450
- }
451
- return e.apply(this, arguments);
452
- };
453
- }
454
- tt.ModifyError = ct, tt.DexieError = xe, tt.BulkError = je;
455
- var Me = {};
456
- const $n = 100, [It, ht, Kt] = typeof Promise > "u" ? [] : (() => {
457
- let t = Promise.resolve();
458
- if (typeof crypto > "u" || !crypto.subtle)
459
- return [t, Be(t), t];
460
- const e = crypto.subtle.digest("SHA-512", new Uint8Array([0]));
461
- return [e, Be(e), t];
462
- })(), Dn = ht && ht.then, nt = It && It.constructor, rn = !!Kt;
463
- var jt = !1, xr = Kt ? () => {
464
- Kt.then(Ye);
465
- } : K.setImmediate ? setImmediate.bind(null, Ye) : K.MutationObserver ? () => {
466
- var t = document.createElement("div");
467
- new MutationObserver(() => {
468
- Ye(), t = null;
469
- }).observe(t, { attributes: !0 }), t.setAttribute("i", "1");
470
- } : () => {
471
- setTimeout(Ye, 0);
472
- }, Re = function(t, e) {
473
- Ke.push([t, e]), dt && (xr(), dt = !1);
474
- }, Rt = !0, dt = !0, de = [], rt = [], Nt = null, $t = Fe, Se = { id: "global", global: !0, ref: 0, unhandleds: [], onunhandled: gn, pgp: !1, env: {}, finalize: function() {
475
- this.unhandleds.forEach((t) => {
476
- try {
477
- gn(t[0], t[1]);
478
- } catch {
479
- }
480
- });
481
- } }, E = Se, Ke = [], fe = 0, st = [];
482
- function S(t) {
483
- if (typeof this != "object")
484
- throw new TypeError("Promises must be constructed via new");
485
- this._listeners = [], this.onuncatched = I, this._lib = !1;
486
- var e = this._PSD = E;
487
- if (G && (this._stackHolder = Ee(), this._prev = null, this._numPrev = 0), typeof t != "function") {
488
- if (t !== Me)
489
- throw new TypeError("Not a function");
490
- return this._state = arguments[1], this._value = arguments[2], void (this._state === !1 && Bt(this, this._value));
491
- }
492
- this._state = null, this._value = null, ++e.ref, Fn(this, t);
493
- }
494
- const Dt = { get: function() {
495
- var t = E, e = ft;
496
- function n(r, s) {
497
- var i = !t.global && (t !== E || e !== ft);
498
- const o = i && !ne();
499
- var u = new S((a, c) => {
500
- sn(this, new Bn(pt(r, t, i, o), pt(s, t, i, o), a, c, t));
501
- });
502
- return G && Ln(u, this), u;
503
- }
504
- return n.prototype = Me, n;
505
- }, set: function(t) {
506
- ee(this, "then", t && t.prototype === Me ? Dt : { get: function() {
507
- return t;
508
- }, set: Dt.set });
509
- } };
510
- function Bn(t, e, n, r, s) {
511
- this.onFulfilled = typeof t == "function" ? t : null, this.onRejected = typeof e == "function" ? e : null, this.resolve = n, this.reject = r, this.psd = s;
512
- }
513
- function Fn(t, e) {
514
- try {
515
- e((n) => {
516
- if (t._state === null) {
517
- if (n === t)
518
- throw new TypeError("A promise cannot be resolved with itself.");
519
- var r = t._lib && ze();
520
- n && typeof n.then == "function" ? Fn(t, (s, i) => {
521
- n instanceof S ? n._then(s, i) : n.then(s, i);
522
- }) : (t._state = !0, t._value = n, Mn(t)), r && He();
523
- }
524
- }, Bt.bind(null, t));
525
- } catch (n) {
526
- Bt(t, n);
527
- }
528
- }
529
- function Bt(t, e) {
530
- if (rt.push(e), t._state === null) {
531
- var n = t._lib && ze();
532
- e = $t(e), t._state = !1, t._value = e, G && e !== null && typeof e == "object" && !e._promise && function(r, s, i) {
533
- try {
534
- r.apply(null, i);
535
- } catch (o) {
536
- s && s(o);
537
- }
538
- }(() => {
539
- var r = Jt(e, "stack");
540
- e._promise = t, ee(e, "stack", { get: () => jt ? r && (r.get ? r.get.apply(e) : r.value) : t.stack });
541
- }), function(r) {
542
- de.some((s) => s._value === r._value) || de.push(r);
543
- }(t), Mn(t), n && He();
544
- }
545
- }
546
- function Mn(t) {
547
- var e = t._listeners;
548
- t._listeners = [];
549
- for (var n = 0, r = e.length; n < r; ++n)
550
- sn(t, e[n]);
551
- var s = t._PSD;
552
- --s.ref || s.finalize(), fe === 0 && (++fe, Re(() => {
553
- --fe == 0 && on();
554
- }, []));
555
- }
556
- function sn(t, e) {
557
- if (t._state !== null) {
558
- var n = t._state ? e.onFulfilled : e.onRejected;
559
- if (n === null)
560
- return (t._state ? e.resolve : e.reject)(t._value);
561
- ++e.psd.ref, ++fe, Re(Sr, [n, t, e]);
562
- } else
563
- t._listeners.push(e);
564
- }
565
- function Sr(t, e, n) {
566
- try {
567
- Nt = e;
568
- var r, s = e._value;
569
- e._state ? r = t(s) : (rt.length && (rt = []), r = t(s), rt.indexOf(s) === -1 && function(i) {
570
- for (var o = de.length; o; )
571
- if (de[--o]._value === i._value)
572
- return void de.splice(o, 1);
573
- }(e)), n.resolve(r);
574
- } catch (i) {
575
- n.reject(i);
576
- } finally {
577
- Nt = null, --fe == 0 && on(), --n.psd.ref || n.psd.finalize();
578
- }
579
- }
580
- function qn(t, e, n) {
581
- if (e.length === n)
582
- return e;
583
- var r = "";
584
- if (t._state === !1) {
585
- var s, i, o = t._value;
586
- o != null ? (s = o.name || "Error", i = o.message || o, r = Ot(o, 0)) : (s = o, i = ""), e.push(s + (i ? ": " + i : "") + r);
587
- }
588
- return G && ((r = Ot(t._stackHolder, 2)) && e.indexOf(r) === -1 && e.push(r), t._prev && qn(t._prev, e, n)), e;
589
- }
590
- function Ln(t, e) {
591
- var n = e ? e._numPrev + 1 : 0;
592
- n < 100 && (t._prev = e, t._numPrev = n);
593
- }
594
- function Ye() {
595
- ze() && He();
596
- }
597
- function ze() {
598
- var t = Rt;
599
- return Rt = !1, dt = !1, t;
600
- }
601
- function He() {
602
- var t, e, n;
603
- do
604
- for (; Ke.length > 0; )
605
- for (t = Ke, Ke = [], n = t.length, e = 0; e < n; ++e) {
606
- var r = t[e];
607
- r[0].apply(null, r[1]);
608
- }
609
- while (Ke.length > 0);
610
- Rt = !0, dt = !0;
611
- }
612
- function on() {
613
- var t = de;
614
- de = [], t.forEach((r) => {
615
- r._PSD.onunhandled.call(null, r._value, r);
616
- });
617
- for (var e = st.slice(0), n = e.length; n; )
618
- e[--n]();
619
- }
620
- function Ge(t) {
621
- return new S(Me, !1, t);
622
- }
623
- function j(t, e) {
624
- var n = E;
625
- return function() {
626
- var r = ze(), s = E;
627
- try {
628
- return ae(n, !0), t.apply(this, arguments);
629
- } catch (i) {
630
- e && e(i);
631
- } finally {
632
- ae(s, !1), r && He();
633
- }
634
- };
635
- }
636
- Pe(S.prototype, { then: Dt, _then: function(t, e) {
637
- sn(this, new Bn(null, null, t, e, E));
638
- }, catch: function(t) {
639
- if (arguments.length === 1)
640
- return this.then(null, t);
641
- var e = arguments[0], n = arguments[1];
642
- return typeof e == "function" ? this.then(null, (r) => r instanceof e ? n(r) : Ge(r)) : this.then(null, (r) => r && r.name === e ? n(r) : Ge(r));
643
- }, finally: function(t) {
644
- return this.then((e) => (t(), e), (e) => (t(), Ge(e)));
645
- }, stack: { get: function() {
646
- if (this._stack)
647
- return this._stack;
648
- try {
649
- jt = !0;
650
- var t = qn(this, [], 20).join(`
651
- From previous: `);
652
- return this._state !== null && (this._stack = t), t;
653
- } finally {
654
- jt = !1;
655
- }
656
- } }, timeout: function(t, e) {
657
- return t < 1 / 0 ? new S((n, r) => {
658
- var s = setTimeout(() => r(new C.Timeout(e)), t);
659
- this.then(n, r).finally(clearTimeout.bind(null, s));
660
- }) : this;
661
- } }), typeof Symbol < "u" && Symbol.toStringTag && ee(S.prototype, Symbol.toStringTag, "Dexie.Promise"), Se.env = Un(), Pe(S, { all: function() {
662
- var t = J.apply(null, arguments).map(Xe);
663
- return new S(function(e, n) {
664
- t.length === 0 && e([]);
665
- var r = t.length;
666
- t.forEach((s, i) => S.resolve(s).then((o) => {
667
- t[i] = o, --r || e(t);
668
- }, n));
669
- });
670
- }, resolve: (t) => {
671
- if (t instanceof S)
672
- return t;
673
- if (t && typeof t.then == "function")
674
- return new S((n, r) => {
675
- t.then(n, r);
676
- });
677
- var e = new S(Me, !0, t);
678
- return Ln(e, Nt), e;
679
- }, reject: Ge, race: function() {
680
- var t = J.apply(null, arguments).map(Xe);
681
- return new S((e, n) => {
682
- t.map((r) => S.resolve(r).then(e, n));
683
- });
684
- }, PSD: { get: () => E, set: (t) => E = t }, totalEchoes: { get: () => ft }, newPSD: oe, usePSD: Te, scheduler: { get: () => Re, set: (t) => {
685
- Re = t;
686
- } }, rejectionMapper: { get: () => $t, set: (t) => {
687
- $t = t;
688
- } }, follow: (t, e) => new S((n, r) => oe((s, i) => {
689
- var o = E;
690
- o.unhandleds = [], o.onunhandled = i, o.finalize = me(function() {
691
- (function(u) {
692
- function a() {
693
- u(), st.splice(st.indexOf(a), 1);
694
- }
695
- st.push(a), ++fe, Re(() => {
696
- --fe == 0 && on();
697
- }, []);
698
- })(() => {
699
- this.unhandleds.length === 0 ? s() : i(this.unhandleds[0]);
700
- });
701
- }, o.finalize), t();
702
- }, e, n, r)) }), nt && (nt.allSettled && ee(S, "allSettled", function() {
703
- const t = J.apply(null, arguments).map(Xe);
704
- return new S((e) => {
705
- t.length === 0 && e([]);
706
- let n = t.length;
707
- const r = new Array(n);
708
- t.forEach((s, i) => S.resolve(s).then((o) => r[i] = { status: "fulfilled", value: o }, (o) => r[i] = { status: "rejected", reason: o }).then(() => --n || e(r)));
709
- });
710
- }), nt.any && typeof AggregateError < "u" && ee(S, "any", function() {
711
- const t = J.apply(null, arguments).map(Xe);
712
- return new S((e, n) => {
713
- t.length === 0 && n(new AggregateError([]));
714
- let r = t.length;
715
- const s = new Array(r);
716
- t.forEach((i, o) => S.resolve(i).then((u) => e(u), (u) => {
717
- s[o] = u, --r || n(new AggregateError(s));
718
- }));
719
- });
720
- }));
721
- const F = { awaits: 0, echoes: 0, id: 0 };
722
- var Pr = 0, it = [], wt = 0, ft = 0, Er = 0;
723
- function oe(t, e, n, r) {
724
- var s = E, i = Object.create(s);
725
- i.parent = s, i.ref = 0, i.global = !1, i.id = ++Er;
726
- var o = Se.env;
727
- i.env = rn ? { Promise: S, PromiseProp: { value: S, configurable: !0, writable: !0 }, all: S.all, race: S.race, allSettled: S.allSettled, any: S.any, resolve: S.resolve, reject: S.reject, nthen: pn(o.nthen, i), gthen: pn(o.gthen, i) } : {}, e && U(i, e), ++s.ref, i.finalize = function() {
728
- --this.parent.ref || this.parent.finalize();
729
- };
730
- var u = Te(i, t, n, r);
731
- return i.ref === 0 && i.finalize(), u;
732
- }
733
- function Ce() {
734
- return F.id || (F.id = ++Pr), ++F.awaits, F.echoes += $n, F.id;
735
- }
736
- function ne() {
737
- return !!F.awaits && (--F.awaits == 0 && (F.id = 0), F.echoes = F.awaits * $n, !0);
738
- }
739
- function Xe(t) {
740
- return F.echoes && t && t.constructor === nt ? (Ce(), t.then((e) => (ne(), e), (e) => (ne(), D(e)))) : t;
741
- }
742
- function Cr(t) {
743
- ++ft, F.echoes && --F.echoes != 0 || (F.echoes = F.id = 0), it.push(E), ae(t, !0);
744
- }
745
- function Tr() {
746
- var t = it[it.length - 1];
747
- it.pop(), ae(t, !1);
748
- }
749
- function ae(t, e) {
750
- var n = E;
751
- if ((e ? !F.echoes || wt++ && t === E : !wt || --wt && t === E) || Vn(e ? Cr.bind(null, t) : Tr), t !== E && (E = t, n === Se && (Se.env = Un()), rn)) {
752
- var r = Se.env.Promise, s = t.env;
753
- ht.then = s.nthen, r.prototype.then = s.gthen, (n.global || t.global) && (Object.defineProperty(K, "Promise", s.PromiseProp), r.all = s.all, r.race = s.race, r.resolve = s.resolve, r.reject = s.reject, s.allSettled && (r.allSettled = s.allSettled), s.any && (r.any = s.any));
754
- }
755
- }
756
- function Un() {
757
- var t = K.Promise;
758
- return rn ? { Promise: t, PromiseProp: Object.getOwnPropertyDescriptor(K, "Promise"), all: t.all, race: t.race, allSettled: t.allSettled, any: t.any, resolve: t.resolve, reject: t.reject, nthen: ht.then, gthen: t.prototype.then } : {};
759
- }
760
- function Te(t, e, n, r, s) {
761
- var i = E;
762
- try {
763
- return ae(t, !0), e(n, r, s);
764
- } finally {
765
- ae(i, !1);
766
- }
767
- }
768
- function Vn(t) {
769
- Dn.call(It, t);
770
- }
771
- function pt(t, e, n, r) {
772
- return typeof t != "function" ? t : function() {
773
- var s = E;
774
- n && Ce(), ae(e, !0);
775
- try {
776
- return t.apply(this, arguments);
777
- } finally {
778
- ae(s, !1), r && Vn(ne);
779
- }
780
- };
781
- }
782
- function pn(t, e) {
783
- return function(n, r) {
784
- return t.call(this, pt(n, e), pt(r, e));
785
- };
786
- }
787
- ("" + Dn).indexOf("[native code]") === -1 && (Ce = ne = I);
788
- const mn = "unhandledrejection";
789
- function gn(t, e) {
790
- var n;
791
- try {
792
- n = e.onuncatched(t);
793
- } catch {
794
- }
795
- if (n !== !1)
796
- try {
797
- var r, s = { promise: e, reason: t };
798
- if (K.document && document.createEvent ? ((r = document.createEvent("Event")).initEvent(mn, !0, !0), U(r, s)) : K.CustomEvent && U(r = new CustomEvent(mn, { detail: s }), s), r && K.dispatchEvent && (dispatchEvent(r), !K.PromiseRejectionEvent && K.onunhandledrejection))
799
- try {
800
- K.onunhandledrejection(r);
801
- } catch {
802
- }
803
- G && r && !r.defaultPrevented && console.warn(`Unhandled rejection: ${t.stack || t}`);
804
- } catch {
805
- }
806
- }
807
- var D = S.reject;
808
- function Ft(t, e, n, r) {
809
- if (t.idbdb && (t._state.openComplete || E.letThrough || t._vip)) {
810
- var s = t._createTransaction(e, n, t._dbSchema);
811
- try {
812
- s.create(), t._state.PR1398_maxLoop = 3;
813
- } catch (i) {
814
- return i.name === tn.InvalidState && t.isOpen() && --t._state.PR1398_maxLoop > 0 ? (console.warn("Dexie: Need to reopen db"), t._close(), t.open().then(() => Ft(t, e, n, r))) : D(i);
815
- }
816
- return s._promise(e, (i, o) => oe(() => (E.trans = s, r(i, o, s)))).then((i) => s._completion.then(() => i));
817
- }
818
- if (t._state.openComplete)
819
- return D(new C.DatabaseClosed(t._state.dbOpenError));
820
- if (!t._state.isBeingOpened) {
821
- if (!t._options.autoOpen)
822
- return D(new C.DatabaseClosed());
823
- t.open().catch(I);
824
- }
825
- return t._state.dbReadyPromise.then(() => Ft(t, e, n, r));
826
- }
827
- const yn = "3.2.4", he = String.fromCharCode(65535), Mt = -1 / 0, X = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.", Wn = "String expected.", Ne = [], yt = typeof navigator < "u" && /(MSIE|Trident|Edge)/.test(navigator.userAgent), Ar = yt, Or = yt, zn = (t) => !/(dexie\.js|dexie\.min\.js)/.test(t), vt = "__dbnames", _t = "readonly", kt = "readwrite";
828
- function ge(t, e) {
829
- return t ? e ? function() {
830
- return t.apply(this, arguments) && e.apply(this, arguments);
831
- } : t : e;
832
- }
833
- const Hn = { type: 3, lower: -1 / 0, lowerOpen: !1, upper: [[]], upperOpen: !1 };
834
- function Qe(t) {
835
- return typeof t != "string" || /\./.test(t) ? (e) => e : (e) => (e[t] === void 0 && t in e && delete (e = We(e))[t], e);
836
- }
837
- class Ir {
838
- _trans(e, n, r) {
839
- const s = this._tx || E.trans, i = this.name;
840
- function o(a, c, d) {
841
- if (!d.schema[i])
842
- throw new C.NotFound("Table " + i + " not part of transaction");
843
- return n(d.idbtrans, d);
844
- }
845
- const u = ze();
846
- try {
847
- return s && s.db === this.db ? s === E.trans ? s._promise(e, o, r) : oe(() => s._promise(e, o, r), { trans: s, transless: E.transless || E }) : Ft(this.db, e, [this.name], o);
848
- } finally {
849
- u && He();
850
- }
851
- }
852
- get(e, n) {
853
- return e && e.constructor === Object ? this.where(e).first(n) : this._trans("readonly", (r) => this.core.get({ trans: r, key: e }).then((s) => this.hook.reading.fire(s))).then(n);
854
- }
855
- where(e) {
856
- if (typeof e == "string")
857
- return new this.db.WhereClause(this, e);
858
- if (M(e))
859
- return new this.db.WhereClause(this, `[${e.join("+")}]`);
860
- const n = $(e);
861
- if (n.length === 1)
862
- return this.where(n[0]).equals(e[n[0]]);
863
- const r = this.schema.indexes.concat(this.schema.primKey).filter((c) => c.compound && n.every((d) => c.keyPath.indexOf(d) >= 0) && c.keyPath.every((d) => n.indexOf(d) >= 0))[0];
864
- if (r && this.db._maxKey !== he)
865
- return this.where(r.name).equals(r.keyPath.map((c) => e[c]));
866
- !r && G && console.warn(`The query ${JSON.stringify(e)} on ${this.name} would benefit of a compound index [${n.join("+")}]`);
867
- const { idxByName: s } = this.schema, i = this.db._deps.indexedDB;
868
- function o(c, d) {
869
- try {
870
- return i.cmp(c, d) === 0;
871
- } catch {
872
- return !1;
873
- }
874
- }
875
- const [u, a] = n.reduce(([c, d], l) => {
876
- const h = s[l], f = e[l];
877
- return [c || h, c || !h ? ge(d, h && h.multi ? (m) => {
878
- const p = te(m, l);
879
- return M(p) && p.some((v) => o(f, v));
880
- } : (m) => o(f, te(m, l))) : d];
881
- }, [null, null]);
882
- return u ? this.where(u.name).equals(e[u.keyPath]).filter(a) : r ? this.filter(a) : this.where(n).equals("");
883
- }
884
- filter(e) {
885
- return this.toCollection().and(e);
886
- }
887
- count(e) {
888
- return this.toCollection().count(e);
889
- }
890
- offset(e) {
891
- return this.toCollection().offset(e);
892
- }
893
- limit(e) {
894
- return this.toCollection().limit(e);
895
- }
896
- each(e) {
897
- return this.toCollection().each(e);
898
- }
899
- toArray(e) {
900
- return this.toCollection().toArray(e);
901
- }
902
- toCollection() {
903
- return new this.db.Collection(new this.db.WhereClause(this));
904
- }
905
- orderBy(e) {
906
- return new this.db.Collection(new this.db.WhereClause(this, M(e) ? `[${e.join("+")}]` : e));
907
- }
908
- reverse() {
909
- return this.toCollection().reverse();
910
- }
911
- mapToClass(e) {
912
- this.schema.mappedClass = e;
913
- const n = (r) => {
914
- if (!r)
915
- return r;
916
- const s = Object.create(e.prototype);
917
- for (var i in r)
918
- if (z(r, i))
919
- try {
920
- s[i] = r[i];
921
- } catch {
922
- }
923
- return s;
924
- };
925
- return this.schema.readHook && this.hook.reading.unsubscribe(this.schema.readHook), this.schema.readHook = n, this.hook("reading", n), e;
926
- }
927
- defineClass() {
928
- return this.mapToClass(function(e) {
929
- U(this, e);
930
- });
931
- }
932
- add(e, n) {
933
- const { auto: r, keyPath: s } = this.schema.primKey;
934
- let i = e;
935
- return s && r && (i = Qe(s)(e)), this._trans("readwrite", (o) => this.core.mutate({ trans: o, type: "add", keys: n != null ? [n] : null, values: [i] })).then((o) => o.numFailures ? S.reject(o.failures[0]) : o.lastResult).then((o) => {
936
- if (s)
937
- try {
938
- H(e, s, o);
939
- } catch {
940
- }
941
- return o;
942
- });
943
- }
944
- update(e, n) {
945
- if (typeof e != "object" || M(e))
946
- return this.where(":id").equals(e).modify(n);
947
- {
948
- const r = te(e, this.schema.primKey.keyPath);
949
- if (r === void 0)
950
- return D(new C.InvalidArgument("Given object does not contain its primary key"));
951
- try {
952
- typeof n != "function" ? $(n).forEach((s) => {
953
- H(e, s, n[s]);
954
- }) : n(e, { value: e, primKey: r });
955
- } catch {
956
- }
957
- return this.where(":id").equals(r).modify(n);
958
- }
959
- }
960
- put(e, n) {
961
- const { auto: r, keyPath: s } = this.schema.primKey;
962
- let i = e;
963
- return s && r && (i = Qe(s)(e)), this._trans("readwrite", (o) => this.core.mutate({ trans: o, type: "put", values: [i], keys: n != null ? [n] : null })).then((o) => o.numFailures ? S.reject(o.failures[0]) : o.lastResult).then((o) => {
964
- if (s)
965
- try {
966
- H(e, s, o);
967
- } catch {
968
- }
969
- return o;
970
- });
971
- }
972
- delete(e) {
973
- return this._trans("readwrite", (n) => this.core.mutate({ trans: n, type: "delete", keys: [e] })).then((n) => n.numFailures ? S.reject(n.failures[0]) : void 0);
974
- }
975
- clear() {
976
- return this._trans("readwrite", (e) => this.core.mutate({ trans: e, type: "deleteRange", range: Hn })).then((e) => e.numFailures ? S.reject(e.failures[0]) : void 0);
977
- }
978
- bulkGet(e) {
979
- return this._trans("readonly", (n) => this.core.getMany({ keys: e, trans: n }).then((r) => r.map((s) => this.hook.reading.fire(s))));
980
- }
981
- bulkAdd(e, n, r) {
982
- const s = Array.isArray(n) ? n : void 0, i = (r = r || (s ? void 0 : n)) ? r.allKeys : void 0;
983
- return this._trans("readwrite", (o) => {
984
- const { auto: u, keyPath: a } = this.schema.primKey;
985
- if (a && s)
986
- throw new C.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");
987
- if (s && s.length !== e.length)
988
- throw new C.InvalidArgument("Arguments objects and keys must have the same length");
989
- const c = e.length;
990
- let d = a && u ? e.map(Qe(a)) : e;
991
- return this.core.mutate({ trans: o, type: "add", keys: s, values: d, wantResults: i }).then(({ numFailures: l, results: h, lastResult: f, failures: m }) => {
992
- if (l === 0)
993
- return i ? h : f;
994
- throw new je(`${this.name}.bulkAdd(): ${l} of ${c} operations failed`, m);
995
- });
996
- });
997
- }
998
- bulkPut(e, n, r) {
999
- const s = Array.isArray(n) ? n : void 0, i = (r = r || (s ? void 0 : n)) ? r.allKeys : void 0;
1000
- return this._trans("readwrite", (o) => {
1001
- const { auto: u, keyPath: a } = this.schema.primKey;
1002
- if (a && s)
1003
- throw new C.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");
1004
- if (s && s.length !== e.length)
1005
- throw new C.InvalidArgument("Arguments objects and keys must have the same length");
1006
- const c = e.length;
1007
- let d = a && u ? e.map(Qe(a)) : e;
1008
- return this.core.mutate({ trans: o, type: "put", keys: s, values: d, wantResults: i }).then(({ numFailures: l, results: h, lastResult: f, failures: m }) => {
1009
- if (l === 0)
1010
- return i ? h : f;
1011
- throw new je(`${this.name}.bulkPut(): ${l} of ${c} operations failed`, m);
1012
- });
1013
- });
1014
- }
1015
- bulkDelete(e) {
1016
- const n = e.length;
1017
- return this._trans("readwrite", (r) => this.core.mutate({ trans: r, type: "delete", keys: e })).then(({ numFailures: r, lastResult: s, failures: i }) => {
1018
- if (r === 0)
1019
- return s;
1020
- throw new je(`${this.name}.bulkDelete(): ${r} of ${n} operations failed`, i);
1021
- });
1022
- }
1023
- }
1024
- function $e(t) {
1025
- var e = {}, n = function(o, u) {
1026
- if (u) {
1027
- for (var a = arguments.length, c = new Array(a - 1); --a; )
1028
- c[a - 1] = arguments[a];
1029
- return e[o].subscribe.apply(null, c), t;
1030
- }
1031
- if (typeof o == "string")
1032
- return e[o];
1033
- };
1034
- n.addEventType = i;
1035
- for (var r = 1, s = arguments.length; r < s; ++r)
1036
- i(arguments[r]);
1037
- return n;
1038
- function i(o, u, a) {
1039
- if (typeof o != "object") {
1040
- var c;
1041
- u || (u = kr), a || (a = I);
1042
- var d = { subscribers: [], fire: a, subscribe: function(l) {
1043
- d.subscribers.indexOf(l) === -1 && (d.subscribers.push(l), d.fire = u(d.fire, l));
1044
- }, unsubscribe: function(l) {
1045
- d.subscribers = d.subscribers.filter(function(h) {
1046
- return h !== l;
1047
- }), d.fire = d.subscribers.reduce(u, a);
1048
- } };
1049
- return e[o] = n[o] = d, d;
1050
- }
1051
- $(c = o).forEach(function(l) {
1052
- var h = c[l];
1053
- if (M(h))
1054
- i(l, c[l][0], c[l][1]);
1055
- else {
1056
- if (h !== "asap")
1057
- throw new C.InvalidArgument("Invalid event config");
1058
- var f = i(l, Fe, function() {
1059
- for (var m = arguments.length, p = new Array(m); m--; )
1060
- p[m] = arguments[m];
1061
- f.subscribers.forEach(function(v) {
1062
- Cn(function() {
1063
- v.apply(null, p);
1064
- });
1065
- });
1066
- });
1067
- }
1068
- });
1069
- }
1070
- }
1071
- function Oe(t, e) {
1072
- return ke(e).from({ prototype: t }), e;
1073
- }
1074
- function be(t, e) {
1075
- return !(t.filter || t.algorithm || t.or) && (e ? t.justLimit : !t.replayFilter);
1076
- }
1077
- function xt(t, e) {
1078
- t.filter = ge(t.filter, e);
1079
- }
1080
- function St(t, e, n) {
1081
- var r = t.replayFilter;
1082
- t.replayFilter = r ? () => ge(r(), e()) : e, t.justLimit = n && !r;
1083
- }
1084
- function ot(t, e) {
1085
- if (t.isPrimKey)
1086
- return e.primaryKey;
1087
- const n = e.getIndexByKeyPath(t.index);
1088
- if (!n)
1089
- throw new C.Schema("KeyPath " + t.index + " on object store " + e.name + " is not indexed");
1090
- return n;
1091
- }
1092
- function vn(t, e, n) {
1093
- const r = ot(t, e.schema);
1094
- return e.openCursor({ trans: n, values: !t.keysOnly, reverse: t.dir === "prev", unique: !!t.unique, query: { index: r, range: t.range } });
1095
- }
1096
- function Je(t, e, n, r) {
1097
- const s = t.replayFilter ? ge(t.filter, t.replayFilter()) : t.filter;
1098
- if (t.or) {
1099
- const i = {}, o = (u, a, c) => {
1100
- if (!s || s(a, c, (h) => a.stop(h), (h) => a.fail(h))) {
1101
- var d = a.primaryKey, l = "" + d;
1102
- l === "[object ArrayBuffer]" && (l = "" + new Uint8Array(d)), z(i, l) || (i[l] = !0, e(u, a, c));
1103
- }
1104
- };
1105
- return Promise.all([t.or._iterate(o, n), bn(vn(t, r, n), t.algorithm, o, !t.keysOnly && t.valueMapper)]);
1106
- }
1107
- return bn(vn(t, r, n), ge(t.algorithm, s), e, !t.keysOnly && t.valueMapper);
1108
- }
1109
- function bn(t, e, n, r) {
1110
- var s = j(r ? (i, o, u) => n(r(i), o, u) : n);
1111
- return t.then((i) => {
1112
- if (i)
1113
- return i.start(() => {
1114
- var o = () => i.continue();
1115
- e && !e(i, (u) => o = u, (u) => {
1116
- i.stop(u), o = I;
1117
- }, (u) => {
1118
- i.fail(u), o = I;
1119
- }) || s(i.value, i, (u) => o = u), o();
1120
- });
1121
- });
1122
- }
1123
- function L(t, e) {
1124
- try {
1125
- const n = wn(t), r = wn(e);
1126
- if (n !== r)
1127
- return n === "Array" ? 1 : r === "Array" ? -1 : n === "binary" ? 1 : r === "binary" ? -1 : n === "string" ? 1 : r === "string" ? -1 : n === "Date" ? 1 : r !== "Date" ? NaN : -1;
1128
- switch (n) {
1129
- case "number":
1130
- case "Date":
1131
- case "string":
1132
- return t > e ? 1 : t < e ? -1 : 0;
1133
- case "binary":
1134
- return function(s, i) {
1135
- const o = s.length, u = i.length, a = o < u ? o : u;
1136
- for (let c = 0; c < a; ++c)
1137
- if (s[c] !== i[c])
1138
- return s[c] < i[c] ? -1 : 1;
1139
- return o === u ? 0 : o < u ? -1 : 1;
1140
- }(_n(t), _n(e));
1141
- case "Array":
1142
- return function(s, i) {
1143
- const o = s.length, u = i.length, a = o < u ? o : u;
1144
- for (let c = 0; c < a; ++c) {
1145
- const d = L(s[c], i[c]);
1146
- if (d !== 0)
1147
- return d;
1148
- }
1149
- return o === u ? 0 : o < u ? -1 : 1;
1150
- }(t, e);
1151
- }
1152
- } catch {
1153
- }
1154
- return NaN;
1155
- }
1156
- function wn(t) {
1157
- const e = typeof t;
1158
- if (e !== "object")
1159
- return e;
1160
- if (ArrayBuffer.isView(t))
1161
- return "binary";
1162
- const n = Tt(t);
1163
- return n === "ArrayBuffer" ? "binary" : n;
1164
- }
1165
- function _n(t) {
1166
- return t instanceof Uint8Array ? t : ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : new Uint8Array(t);
1167
- }
1168
- class Kr {
1169
- _read(e, n) {
1170
- var r = this._ctx;
1171
- return r.error ? r.table._trans(null, D.bind(null, r.error)) : r.table._trans("readonly", e).then(n);
1172
- }
1173
- _write(e) {
1174
- var n = this._ctx;
1175
- return n.error ? n.table._trans(null, D.bind(null, n.error)) : n.table._trans("readwrite", e, "locked");
1176
- }
1177
- _addAlgorithm(e) {
1178
- var n = this._ctx;
1179
- n.algorithm = ge(n.algorithm, e);
1180
- }
1181
- _iterate(e, n) {
1182
- return Je(this._ctx, e, n, this._ctx.table.core);
1183
- }
1184
- clone(e) {
1185
- var n = Object.create(this.constructor.prototype), r = Object.create(this._ctx);
1186
- return e && U(r, e), n._ctx = r, n;
1187
- }
1188
- raw() {
1189
- return this._ctx.valueMapper = null, this;
1190
- }
1191
- each(e) {
1192
- var n = this._ctx;
1193
- return this._read((r) => Je(n, e, r, n.table.core));
1194
- }
1195
- count(e) {
1196
- return this._read((n) => {
1197
- const r = this._ctx, s = r.table.core;
1198
- if (be(r, !0))
1199
- return s.count({ trans: n, query: { index: ot(r, s.schema), range: r.range } }).then((o) => Math.min(o, r.limit));
1200
- var i = 0;
1201
- return Je(r, () => (++i, !1), n, s).then(() => i);
1202
- }).then(e);
1203
- }
1204
- sortBy(e, n) {
1205
- const r = e.split(".").reverse(), s = r[0], i = r.length - 1;
1206
- function o(c, d) {
1207
- return d ? o(c[r[d]], d - 1) : c[s];
1208
- }
1209
- var u = this._ctx.dir === "next" ? 1 : -1;
1210
- function a(c, d) {
1211
- var l = o(c, i), h = o(d, i);
1212
- return l < h ? -u : l > h ? u : 0;
1213
- }
1214
- return this.toArray(function(c) {
1215
- return c.sort(a);
1216
- }).then(n);
1217
- }
1218
- toArray(e) {
1219
- return this._read((n) => {
1220
- var r = this._ctx;
1221
- if (r.dir === "next" && be(r, !0) && r.limit > 0) {
1222
- const { valueMapper: s } = r, i = ot(r, r.table.core.schema);
1223
- return r.table.core.query({ trans: n, limit: r.limit, values: !0, query: { index: i, range: r.range } }).then(({ result: o }) => s ? o.map(s) : o);
1224
- }
1225
- {
1226
- const s = [];
1227
- return Je(r, (i) => s.push(i), n, r.table.core).then(() => s);
1228
- }
1229
- }, e);
1230
- }
1231
- offset(e) {
1232
- var n = this._ctx;
1233
- return e <= 0 || (n.offset += e, be(n) ? St(n, () => {
1234
- var r = e;
1235
- return (s, i) => r === 0 || (r === 1 ? (--r, !1) : (i(() => {
1236
- s.advance(r), r = 0;
1237
- }), !1));
1238
- }) : St(n, () => {
1239
- var r = e;
1240
- return () => --r < 0;
1241
- })), this;
1242
- }
1243
- limit(e) {
1244
- return this._ctx.limit = Math.min(this._ctx.limit, e), St(this._ctx, () => {
1245
- var n = e;
1246
- return function(r, s, i) {
1247
- return --n <= 0 && s(i), n >= 0;
1248
- };
1249
- }, !0), this;
1250
- }
1251
- until(e, n) {
1252
- return xt(this._ctx, function(r, s, i) {
1253
- return !e(r.value) || (s(i), n);
1254
- }), this;
1255
- }
1256
- first(e) {
1257
- return this.limit(1).toArray(function(n) {
1258
- return n[0];
1259
- }).then(e);
1260
- }
1261
- last(e) {
1262
- return this.reverse().first(e);
1263
- }
1264
- filter(e) {
1265
- var n, r;
1266
- return xt(this._ctx, function(s) {
1267
- return e(s.value);
1268
- }), n = this._ctx, r = e, n.isMatch = ge(n.isMatch, r), this;
1269
- }
1270
- and(e) {
1271
- return this.filter(e);
1272
- }
1273
- or(e) {
1274
- return new this.db.WhereClause(this._ctx.table, e, this);
1275
- }
1276
- reverse() {
1277
- return this._ctx.dir = this._ctx.dir === "prev" ? "next" : "prev", this._ondirectionchange && this._ondirectionchange(this._ctx.dir), this;
1278
- }
1279
- desc() {
1280
- return this.reverse();
1281
- }
1282
- eachKey(e) {
1283
- var n = this._ctx;
1284
- return n.keysOnly = !n.isMatch, this.each(function(r, s) {
1285
- e(s.key, s);
1286
- });
1287
- }
1288
- eachUniqueKey(e) {
1289
- return this._ctx.unique = "unique", this.eachKey(e);
1290
- }
1291
- eachPrimaryKey(e) {
1292
- var n = this._ctx;
1293
- return n.keysOnly = !n.isMatch, this.each(function(r, s) {
1294
- e(s.primaryKey, s);
1295
- });
1296
- }
1297
- keys(e) {
1298
- var n = this._ctx;
1299
- n.keysOnly = !n.isMatch;
1300
- var r = [];
1301
- return this.each(function(s, i) {
1302
- r.push(i.key);
1303
- }).then(function() {
1304
- return r;
1305
- }).then(e);
1306
- }
1307
- primaryKeys(e) {
1308
- var n = this._ctx;
1309
- if (n.dir === "next" && be(n, !0) && n.limit > 0)
1310
- return this._read((s) => {
1311
- var i = ot(n, n.table.core.schema);
1312
- return n.table.core.query({ trans: s, values: !1, limit: n.limit, query: { index: i, range: n.range } });
1313
- }).then(({ result: s }) => s).then(e);
1314
- n.keysOnly = !n.isMatch;
1315
- var r = [];
1316
- return this.each(function(s, i) {
1317
- r.push(i.primaryKey);
1318
- }).then(function() {
1319
- return r;
1320
- }).then(e);
1321
- }
1322
- uniqueKeys(e) {
1323
- return this._ctx.unique = "unique", this.keys(e);
1324
- }
1325
- firstKey(e) {
1326
- return this.limit(1).keys(function(n) {
1327
- return n[0];
1328
- }).then(e);
1329
- }
1330
- lastKey(e) {
1331
- return this.reverse().firstKey(e);
1332
- }
1333
- distinct() {
1334
- var e = this._ctx, n = e.index && e.table.schema.idxByName[e.index];
1335
- if (!n || !n.multi)
1336
- return this;
1337
- var r = {};
1338
- return xt(this._ctx, function(s) {
1339
- var i = s.primaryKey.toString(), o = z(r, i);
1340
- return r[i] = !0, !o;
1341
- }), this;
1342
- }
1343
- modify(e) {
1344
- var n = this._ctx;
1345
- return this._write((r) => {
1346
- var s;
1347
- if (typeof e == "function")
1348
- s = e;
1349
- else {
1350
- var i = $(e), o = i.length;
1351
- s = function(p) {
1352
- for (var v = !1, y = 0; y < o; ++y) {
1353
- var g = i[y], b = e[g];
1354
- te(p, g) !== b && (H(p, g, b), v = !0);
1355
- }
1356
- return v;
1357
- };
1358
- }
1359
- const u = n.table.core, { outbound: a, extractKey: c } = u.schema.primaryKey, d = this.db._options.modifyChunkSize || 200, l = [];
1360
- let h = 0;
1361
- const f = [], m = (p, v) => {
1362
- const { failures: y, numFailures: g } = v;
1363
- h += p - g;
1364
- for (let b of $(y))
1365
- l.push(y[b]);
1366
- };
1367
- return this.clone().primaryKeys().then((p) => {
1368
- const v = (y) => {
1369
- const g = Math.min(d, p.length - y);
1370
- return u.getMany({ trans: r, keys: p.slice(y, y + g), cache: "immutable" }).then((b) => {
1371
- const k = [], P = [], x = a ? [] : null, w = [];
1372
- for (let _ = 0; _ < g; ++_) {
1373
- const R = b[_], O = { value: We(R), primKey: p[y + _] };
1374
- s.call(O, O.value, O) !== !1 && (O.value == null ? w.push(p[y + _]) : a || L(c(R), c(O.value)) === 0 ? (P.push(O.value), a && x.push(p[y + _])) : (w.push(p[y + _]), k.push(O.value)));
1375
- }
1376
- const A = be(n) && n.limit === 1 / 0 && (typeof e != "function" || e === Pt) && { index: n.index, range: n.range };
1377
- return Promise.resolve(k.length > 0 && u.mutate({ trans: r, type: "add", values: k }).then((_) => {
1378
- for (let R in _.failures)
1379
- w.splice(parseInt(R), 1);
1380
- m(k.length, _);
1381
- })).then(() => (P.length > 0 || A && typeof e == "object") && u.mutate({ trans: r, type: "put", keys: x, values: P, criteria: A, changeSpec: typeof e != "function" && e }).then((_) => m(P.length, _))).then(() => (w.length > 0 || A && e === Pt) && u.mutate({ trans: r, type: "delete", keys: w, criteria: A }).then((_) => m(w.length, _))).then(() => p.length > y + g && v(y + d));
1382
- });
1383
- };
1384
- return v(0).then(() => {
1385
- if (l.length > 0)
1386
- throw new ct("Error modifying one or more objects", l, h, f);
1387
- return p.length;
1388
- });
1389
- });
1390
- });
1391
- }
1392
- delete() {
1393
- var e = this._ctx, n = e.range;
1394
- return be(e) && (e.isPrimKey && !Or || n.type === 3) ? this._write((r) => {
1395
- const { primaryKey: s } = e.table.core.schema, i = n;
1396
- return e.table.core.count({ trans: r, query: { index: s, range: i } }).then((o) => e.table.core.mutate({ trans: r, type: "deleteRange", range: i }).then(({ failures: u, lastResult: a, results: c, numFailures: d }) => {
1397
- if (d)
1398
- throw new ct("Could not delete some values", Object.keys(u).map((l) => u[l]), o - d);
1399
- return o - d;
1400
- }));
1401
- }) : this.modify(Pt);
1402
- }
1403
- }
1404
- const Pt = (t, e) => e.value = null;
1405
- function jr(t, e) {
1406
- return t < e ? -1 : t === e ? 0 : 1;
1407
- }
1408
- function Rr(t, e) {
1409
- return t > e ? -1 : t === e ? 0 : 1;
1410
- }
1411
- function W(t, e, n) {
1412
- var r = t instanceof Gn ? new t.Collection(t) : t;
1413
- return r._ctx.error = n ? new n(e) : new TypeError(e), r;
1414
- }
1415
- function we(t) {
1416
- return new t.Collection(t, () => Yn("")).limit(0);
1417
- }
1418
- function Nr(t, e, n, r, s, i) {
1419
- for (var o = Math.min(t.length, r.length), u = -1, a = 0; a < o; ++a) {
1420
- var c = e[a];
1421
- if (c !== r[a])
1422
- return s(t[a], n[a]) < 0 ? t.substr(0, a) + n[a] + n.substr(a + 1) : s(t[a], r[a]) < 0 ? t.substr(0, a) + r[a] + n.substr(a + 1) : u >= 0 ? t.substr(0, u) + e[u] + n.substr(u + 1) : null;
1423
- s(t[a], c) < 0 && (u = a);
1424
- }
1425
- return o < r.length && i === "next" ? t + n.substr(t.length) : o < t.length && i === "prev" ? t.substr(0, n.length) : u < 0 ? null : t.substr(0, u) + r[u] + n.substr(u + 1);
1426
- }
1427
- function Ze(t, e, n, r) {
1428
- var s, i, o, u, a, c, d, l = n.length;
1429
- if (!n.every((p) => typeof p == "string"))
1430
- return W(t, Wn);
1431
- function h(p) {
1432
- s = function(y) {
1433
- return y === "next" ? (g) => g.toUpperCase() : (g) => g.toLowerCase();
1434
- }(p), i = function(y) {
1435
- return y === "next" ? (g) => g.toLowerCase() : (g) => g.toUpperCase();
1436
- }(p), o = p === "next" ? jr : Rr;
1437
- var v = n.map(function(y) {
1438
- return { lower: i(y), upper: s(y) };
1439
- }).sort(function(y, g) {
1440
- return o(y.lower, g.lower);
1441
- });
1442
- u = v.map(function(y) {
1443
- return y.upper;
1444
- }), a = v.map(function(y) {
1445
- return y.lower;
1446
- }), c = p, d = p === "next" ? "" : r;
1447
- }
1448
- h("next");
1449
- var f = new t.Collection(t, () => re(u[0], a[l - 1] + r));
1450
- f._ondirectionchange = function(p) {
1451
- h(p);
1452
- };
1453
- var m = 0;
1454
- return f._addAlgorithm(function(p, v, y) {
1455
- var g = p.key;
1456
- if (typeof g != "string")
1457
- return !1;
1458
- var b = i(g);
1459
- if (e(b, a, m))
1460
- return !0;
1461
- for (var k = null, P = m; P < l; ++P) {
1462
- var x = Nr(g, b, u[P], a[P], o, c);
1463
- x === null && k === null ? m = P + 1 : (k === null || o(k, x) > 0) && (k = x);
1464
- }
1465
- return v(k !== null ? function() {
1466
- p.continue(k + d);
1467
- } : y), !1;
1468
- }), f;
1469
- }
1470
- function re(t, e, n, r) {
1471
- return { type: 2, lower: t, upper: e, lowerOpen: n, upperOpen: r };
1472
- }
1473
- function Yn(t) {
1474
- return { type: 1, lower: t, upper: t };
1475
- }
1476
- class Gn {
1477
- get Collection() {
1478
- return this._ctx.table.db.Collection;
1479
- }
1480
- between(e, n, r, s) {
1481
- r = r !== !1, s = s === !0;
1482
- try {
1483
- return this._cmp(e, n) > 0 || this._cmp(e, n) === 0 && (r || s) && (!r || !s) ? we(this) : new this.Collection(this, () => re(e, n, !r, !s));
1484
- } catch {
1485
- return W(this, X);
1486
- }
1487
- }
1488
- equals(e) {
1489
- return e == null ? W(this, X) : new this.Collection(this, () => Yn(e));
1490
- }
1491
- above(e) {
1492
- return e == null ? W(this, X) : new this.Collection(this, () => re(e, void 0, !0));
1493
- }
1494
- aboveOrEqual(e) {
1495
- return e == null ? W(this, X) : new this.Collection(this, () => re(e, void 0, !1));
1496
- }
1497
- below(e) {
1498
- return e == null ? W(this, X) : new this.Collection(this, () => re(void 0, e, !1, !0));
1499
- }
1500
- belowOrEqual(e) {
1501
- return e == null ? W(this, X) : new this.Collection(this, () => re(void 0, e));
1502
- }
1503
- startsWith(e) {
1504
- return typeof e != "string" ? W(this, Wn) : this.between(e, e + he, !0, !0);
1505
- }
1506
- startsWithIgnoreCase(e) {
1507
- return e === "" ? this.startsWith(e) : Ze(this, (n, r) => n.indexOf(r[0]) === 0, [e], he);
1508
- }
1509
- equalsIgnoreCase(e) {
1510
- return Ze(this, (n, r) => n === r[0], [e], "");
1511
- }
1512
- anyOfIgnoreCase() {
1513
- var e = J.apply(_e, arguments);
1514
- return e.length === 0 ? we(this) : Ze(this, (n, r) => r.indexOf(n) !== -1, e, "");
1515
- }
1516
- startsWithAnyOfIgnoreCase() {
1517
- var e = J.apply(_e, arguments);
1518
- return e.length === 0 ? we(this) : Ze(this, (n, r) => r.some((s) => n.indexOf(s) === 0), e, he);
1519
- }
1520
- anyOf() {
1521
- const e = J.apply(_e, arguments);
1522
- let n = this._cmp;
1523
- try {
1524
- e.sort(n);
1525
- } catch {
1526
- return W(this, X);
1527
- }
1528
- if (e.length === 0)
1529
- return we(this);
1530
- const r = new this.Collection(this, () => re(e[0], e[e.length - 1]));
1531
- r._ondirectionchange = (i) => {
1532
- n = i === "next" ? this._ascending : this._descending, e.sort(n);
1533
- };
1534
- let s = 0;
1535
- return r._addAlgorithm((i, o, u) => {
1536
- const a = i.key;
1537
- for (; n(a, e[s]) > 0; )
1538
- if (++s, s === e.length)
1539
- return o(u), !1;
1540
- return n(a, e[s]) === 0 || (o(() => {
1541
- i.continue(e[s]);
1542
- }), !1);
1543
- }), r;
1544
- }
1545
- notEqual(e) {
1546
- return this.inAnyRange([[Mt, e], [e, this.db._maxKey]], { includeLowers: !1, includeUppers: !1 });
1547
- }
1548
- noneOf() {
1549
- const e = J.apply(_e, arguments);
1550
- if (e.length === 0)
1551
- return new this.Collection(this);
1552
- try {
1553
- e.sort(this._ascending);
1554
- } catch {
1555
- return W(this, X);
1556
- }
1557
- const n = e.reduce((r, s) => r ? r.concat([[r[r.length - 1][1], s]]) : [[Mt, s]], null);
1558
- return n.push([e[e.length - 1], this.db._maxKey]), this.inAnyRange(n, { includeLowers: !1, includeUppers: !1 });
1559
- }
1560
- inAnyRange(e, n) {
1561
- const r = this._cmp, s = this._ascending, i = this._descending, o = this._min, u = this._max;
1562
- if (e.length === 0)
1563
- return we(this);
1564
- if (!e.every((g) => g[0] !== void 0 && g[1] !== void 0 && s(g[0], g[1]) <= 0))
1565
- return W(this, "First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower", C.InvalidArgument);
1566
- const a = !n || n.includeLowers !== !1, c = n && n.includeUppers === !0;
1567
- let d, l = s;
1568
- function h(g, b) {
1569
- return l(g[0], b[0]);
1570
- }
1571
- try {
1572
- d = e.reduce(function(g, b) {
1573
- let k = 0, P = g.length;
1574
- for (; k < P; ++k) {
1575
- const x = g[k];
1576
- if (r(b[0], x[1]) < 0 && r(b[1], x[0]) > 0) {
1577
- x[0] = o(x[0], b[0]), x[1] = u(x[1], b[1]);
1578
- break;
1579
- }
1580
- }
1581
- return k === P && g.push(b), g;
1582
- }, []), d.sort(h);
1583
- } catch {
1584
- return W(this, X);
1585
- }
1586
- let f = 0;
1587
- const m = c ? (g) => s(g, d[f][1]) > 0 : (g) => s(g, d[f][1]) >= 0, p = a ? (g) => i(g, d[f][0]) > 0 : (g) => i(g, d[f][0]) >= 0;
1588
- let v = m;
1589
- const y = new this.Collection(this, () => re(d[0][0], d[d.length - 1][1], !a, !c));
1590
- return y._ondirectionchange = (g) => {
1591
- g === "next" ? (v = m, l = s) : (v = p, l = i), d.sort(h);
1592
- }, y._addAlgorithm((g, b, k) => {
1593
- for (var P = g.key; v(P); )
1594
- if (++f, f === d.length)
1595
- return b(k), !1;
1596
- return !!function(x) {
1597
- return !m(x) && !p(x);
1598
- }(P) || (this._cmp(P, d[f][1]) === 0 || this._cmp(P, d[f][0]) === 0 || b(() => {
1599
- l === s ? g.continue(d[f][0]) : g.continue(d[f][1]);
1600
- }), !1);
1601
- }), y;
1602
- }
1603
- startsWithAnyOf() {
1604
- const e = J.apply(_e, arguments);
1605
- return e.every((n) => typeof n == "string") ? e.length === 0 ? we(this) : this.inAnyRange(e.map((n) => [n, n + he])) : W(this, "startsWithAnyOf() only works with strings");
1606
- }
1607
- }
1608
- function Y(t) {
1609
- return j(function(e) {
1610
- return qe(e), t(e.target.error), !1;
1611
- });
1612
- }
1613
- function qe(t) {
1614
- t.stopPropagation && t.stopPropagation(), t.preventDefault && t.preventDefault();
1615
- }
1616
- const Le = "storagemutated", ie = "x-storagemutated-1", ue = $e(null, Le);
1617
- class $r {
1618
- _lock() {
1619
- return Ie(!E.global), ++this._reculock, this._reculock !== 1 || E.global || (E.lockOwnerFor = this), this;
1620
- }
1621
- _unlock() {
1622
- if (Ie(!E.global), --this._reculock == 0)
1623
- for (E.global || (E.lockOwnerFor = null); this._blockedFuncs.length > 0 && !this._locked(); ) {
1624
- var e = this._blockedFuncs.shift();
1625
- try {
1626
- Te(e[1], e[0]);
1627
- } catch {
1628
- }
1629
- }
1630
- return this;
1631
- }
1632
- _locked() {
1633
- return this._reculock && E.lockOwnerFor !== this;
1634
- }
1635
- create(e) {
1636
- if (!this.mode)
1637
- return this;
1638
- const n = this.db.idbdb, r = this.db._state.dbOpenError;
1639
- if (Ie(!this.idbtrans), !e && !n)
1640
- switch (r && r.name) {
1641
- case "DatabaseClosedError":
1642
- throw new C.DatabaseClosed(r);
1643
- case "MissingAPIError":
1644
- throw new C.MissingAPI(r.message, r);
1645
- default:
1646
- throw new C.OpenFailed(r);
1647
- }
1648
- if (!this.active)
1649
- throw new C.TransactionInactive();
1650
- return Ie(this._completion._state === null), (e = this.idbtrans = e || (this.db.core ? this.db.core.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability }) : n.transaction(this.storeNames, this.mode, { durability: this.chromeTransactionDurability }))).onerror = j((s) => {
1651
- qe(s), this._reject(e.error);
1652
- }), e.onabort = j((s) => {
1653
- qe(s), this.active && this._reject(new C.Abort(e.error)), this.active = !1, this.on("abort").fire(s);
1654
- }), e.oncomplete = j(() => {
1655
- this.active = !1, this._resolve(), "mutatedParts" in e && ue.storagemutated.fire(e.mutatedParts);
1656
- }), this;
1657
- }
1658
- _promise(e, n, r) {
1659
- if (e === "readwrite" && this.mode !== "readwrite")
1660
- return D(new C.ReadOnly("Transaction is readonly"));
1661
- if (!this.active)
1662
- return D(new C.TransactionInactive());
1663
- if (this._locked())
1664
- return new S((i, o) => {
1665
- this._blockedFuncs.push([() => {
1666
- this._promise(e, n, r).then(i, o);
1667
- }, E]);
1668
- });
1669
- if (r)
1670
- return oe(() => {
1671
- var i = new S((o, u) => {
1672
- this._lock();
1673
- const a = n(o, u, this);
1674
- a && a.then && a.then(o, u);
1675
- });
1676
- return i.finally(() => this._unlock()), i._lib = !0, i;
1677
- });
1678
- var s = new S((i, o) => {
1679
- var u = n(i, o, this);
1680
- u && u.then && u.then(i, o);
1681
- });
1682
- return s._lib = !0, s;
1683
- }
1684
- _root() {
1685
- return this.parent ? this.parent._root() : this;
1686
- }
1687
- waitFor(e) {
1688
- var n = this._root();
1689
- const r = S.resolve(e);
1690
- if (n._waitingFor)
1691
- n._waitingFor = n._waitingFor.then(() => r);
1692
- else {
1693
- n._waitingFor = r, n._waitingQueue = [];
1694
- var s = n.idbtrans.objectStore(n.storeNames[0]);
1695
- (function o() {
1696
- for (++n._spinCount; n._waitingQueue.length; )
1697
- n._waitingQueue.shift()();
1698
- n._waitingFor && (s.get(-1 / 0).onsuccess = o);
1699
- })();
1700
- }
1701
- var i = n._waitingFor;
1702
- return new S((o, u) => {
1703
- r.then((a) => n._waitingQueue.push(j(o.bind(null, a))), (a) => n._waitingQueue.push(j(u.bind(null, a)))).finally(() => {
1704
- n._waitingFor === i && (n._waitingFor = null);
1705
- });
1706
- });
1707
- }
1708
- abort() {
1709
- this.active && (this.active = !1, this.idbtrans && this.idbtrans.abort(), this._reject(new C.Abort()));
1710
- }
1711
- table(e) {
1712
- const n = this._memoizedTables || (this._memoizedTables = {});
1713
- if (z(n, e))
1714
- return n[e];
1715
- const r = this.schema[e];
1716
- if (!r)
1717
- throw new C.NotFound("Table " + e + " not part of transaction");
1718
- const s = new this.db.Table(e, r, this);
1719
- return s.core = this.db.core.table(e), n[e] = s, s;
1720
- }
1721
- }
1722
- function qt(t, e, n, r, s, i, o) {
1723
- return { name: t, keyPath: e, unique: n, multi: r, auto: s, compound: i, src: (n && !o ? "&" : "") + (r ? "*" : "") + (s ? "++" : "") + Xn(e) };
1724
- }
1725
- function Xn(t) {
1726
- return typeof t == "string" ? t : t ? "[" + [].join.call(t, "+") + "]" : "";
1727
- }
1728
- function Qn(t, e, n) {
1729
- return { name: t, primKey: e, indexes: n, mappedClass: null, idxByName: Tn(n, (r) => [r.name, r]) };
1730
- }
1731
- let Ue = (t) => {
1732
- try {
1733
- return t.only([[]]), Ue = () => [[]], [[]];
1734
- } catch {
1735
- return Ue = () => he, he;
1736
- }
1737
- };
1738
- function Lt(t) {
1739
- return t == null ? () => {
1740
- } : typeof t == "string" ? function(e) {
1741
- return e.split(".").length === 1 ? (n) => n[e] : (n) => te(n, e);
1742
- }(t) : (e) => te(e, t);
1743
- }
1744
- function kn(t) {
1745
- return [].slice.call(t);
1746
- }
1747
- let Dr = 0;
1748
- function De(t) {
1749
- return t == null ? ":id" : typeof t == "string" ? t : `[${t.join("+")}]`;
1750
- }
1751
- function Br(t, e, n) {
1752
- function r(a) {
1753
- if (a.type === 3)
1754
- return null;
1755
- if (a.type === 4)
1756
- throw new Error("Cannot convert never type to IDBKeyRange");
1757
- const { lower: c, upper: d, lowerOpen: l, upperOpen: h } = a;
1758
- return c === void 0 ? d === void 0 ? null : e.upperBound(d, !!h) : d === void 0 ? e.lowerBound(c, !!l) : e.bound(c, d, !!l, !!h);
1759
- }
1760
- const { schema: s, hasGetAll: i } = function(a, c) {
1761
- const d = kn(a.objectStoreNames);
1762
- return { schema: { name: a.name, tables: d.map((l) => c.objectStore(l)).map((l) => {
1763
- const { keyPath: h, autoIncrement: f } = l, m = M(h), p = h == null, v = {}, y = { name: l.name, primaryKey: { name: null, isPrimaryKey: !0, outbound: p, compound: m, keyPath: h, autoIncrement: f, unique: !0, extractKey: Lt(h) }, indexes: kn(l.indexNames).map((g) => l.index(g)).map((g) => {
1764
- const { name: b, unique: k, multiEntry: P, keyPath: x } = g, w = { name: b, compound: M(x), keyPath: x, unique: k, multiEntry: P, extractKey: Lt(x) };
1765
- return v[De(x)] = w, w;
1766
- }), getIndexByKeyPath: (g) => v[De(g)] };
1767
- return v[":id"] = y.primaryKey, h != null && (v[De(h)] = y.primaryKey), y;
1768
- }) }, hasGetAll: d.length > 0 && "getAll" in c.objectStore(d[0]) && !(typeof navigator < "u" && /Safari/.test(navigator.userAgent) && !/(Chrome\/|Edge\/)/.test(navigator.userAgent) && [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604) };
1769
- }(t, n), o = s.tables.map((a) => function(c) {
1770
- const d = c.name;
1771
- return { name: d, schema: c, mutate: function({ trans: l, type: h, keys: f, values: m, range: p }) {
1772
- return new Promise((v, y) => {
1773
- v = j(v);
1774
- const g = l.objectStore(d), b = g.keyPath == null, k = h === "put" || h === "add";
1775
- if (!k && h !== "delete" && h !== "deleteRange")
1776
- throw new Error("Invalid operation type: " + h);
1777
- const { length: P } = f || m || { length: 1 };
1778
- if (f && m && f.length !== m.length)
1779
- throw new Error("Given keys array must have same length as given values array.");
1780
- if (P === 0)
1781
- return v({ numFailures: 0, failures: {}, results: [], lastResult: void 0 });
1782
- let x;
1783
- const w = [], A = [];
1784
- let _ = 0;
1785
- const R = (q) => {
1786
- ++_, qe(q);
1787
- };
1788
- if (h === "deleteRange") {
1789
- if (p.type === 4)
1790
- return v({ numFailures: _, failures: A, results: [], lastResult: void 0 });
1791
- p.type === 3 ? w.push(x = g.clear()) : w.push(x = g.delete(r(p)));
1792
- } else {
1793
- const [q, B] = k ? b ? [m, f] : [m, null] : [f, null];
1794
- if (k)
1795
- for (let N = 0; N < P; ++N)
1796
- w.push(x = B && B[N] !== void 0 ? g[h](q[N], B[N]) : g[h](q[N])), x.onerror = R;
1797
- else
1798
- for (let N = 0; N < P; ++N)
1799
- w.push(x = g[h](q[N])), x.onerror = R;
1800
- }
1801
- const O = (q) => {
1802
- const B = q.target.result;
1803
- w.forEach((N, ye) => N.error != null && (A[ye] = N.error)), v({ numFailures: _, failures: A, results: h === "delete" ? f : w.map((N) => N.result), lastResult: B });
1804
- };
1805
- x.onerror = (q) => {
1806
- R(q), O(q);
1807
- }, x.onsuccess = O;
1808
- });
1809
- }, getMany: ({ trans: l, keys: h }) => new Promise((f, m) => {
1810
- f = j(f);
1811
- const p = l.objectStore(d), v = h.length, y = new Array(v);
1812
- let g, b = 0, k = 0;
1813
- const P = (w) => {
1814
- const A = w.target;
1815
- y[A._pos] = A.result, ++k === b && f(y);
1816
- }, x = Y(m);
1817
- for (let w = 0; w < v; ++w)
1818
- h[w] != null && (g = p.get(h[w]), g._pos = w, g.onsuccess = P, g.onerror = x, ++b);
1819
- b === 0 && f(y);
1820
- }), get: ({ trans: l, key: h }) => new Promise((f, m) => {
1821
- f = j(f);
1822
- const p = l.objectStore(d).get(h);
1823
- p.onsuccess = (v) => f(v.target.result), p.onerror = Y(m);
1824
- }), query: function(l) {
1825
- return (h) => new Promise((f, m) => {
1826
- f = j(f);
1827
- const { trans: p, values: v, limit: y, query: g } = h, b = y === 1 / 0 ? void 0 : y, { index: k, range: P } = g, x = p.objectStore(d), w = k.isPrimaryKey ? x : x.index(k.name), A = r(P);
1828
- if (y === 0)
1829
- return f({ result: [] });
1830
- if (l) {
1831
- const _ = v ? w.getAll(A, b) : w.getAllKeys(A, b);
1832
- _.onsuccess = (R) => f({ result: R.target.result }), _.onerror = Y(m);
1833
- } else {
1834
- let _ = 0;
1835
- const R = v || !("openKeyCursor" in w) ? w.openCursor(A) : w.openKeyCursor(A), O = [];
1836
- R.onsuccess = (q) => {
1837
- const B = R.result;
1838
- return B ? (O.push(v ? B.value : B.primaryKey), ++_ === y ? f({ result: O }) : void B.continue()) : f({ result: O });
1839
- }, R.onerror = Y(m);
1840
- }
1841
- });
1842
- }(i), openCursor: function({ trans: l, values: h, query: f, reverse: m, unique: p }) {
1843
- return new Promise((v, y) => {
1844
- v = j(v);
1845
- const { index: g, range: b } = f, k = l.objectStore(d), P = g.isPrimaryKey ? k : k.index(g.name), x = m ? p ? "prevunique" : "prev" : p ? "nextunique" : "next", w = h || !("openKeyCursor" in P) ? P.openCursor(r(b), x) : P.openKeyCursor(r(b), x);
1846
- w.onerror = Y(y), w.onsuccess = j((A) => {
1847
- const _ = w.result;
1848
- if (!_)
1849
- return void v(null);
1850
- _.___id = ++Dr, _.done = !1;
1851
- const R = _.continue.bind(_);
1852
- let O = _.continuePrimaryKey;
1853
- O && (O = O.bind(_));
1854
- const q = _.advance.bind(_), B = () => {
1855
- throw new Error("Cursor not stopped");
1856
- };
1857
- _.trans = l, _.stop = _.continue = _.continuePrimaryKey = _.advance = () => {
1858
- throw new Error("Cursor not started");
1859
- }, _.fail = j(y), _.next = function() {
1860
- let N = 1;
1861
- return this.start(() => N-- ? this.continue() : this.stop()).then(() => this);
1862
- }, _.start = (N) => {
1863
- const ye = new Promise((V, le) => {
1864
- V = j(V), w.onerror = Y(le), _.fail = le, _.stop = (Ae) => {
1865
- _.stop = _.continue = _.continuePrimaryKey = _.advance = B, V(Ae);
1866
- };
1867
- }), ve = () => {
1868
- if (w.result)
1869
- try {
1870
- N();
1871
- } catch (V) {
1872
- _.fail(V);
1873
- }
1874
- else
1875
- _.done = !0, _.start = () => {
1876
- throw new Error("Cursor behind last entry");
1877
- }, _.stop();
1878
- };
1879
- return w.onsuccess = j((V) => {
1880
- w.onsuccess = ve, ve();
1881
- }), _.continue = R, _.continuePrimaryKey = O, _.advance = q, ve(), ye;
1882
- }, v(_);
1883
- }, y);
1884
- });
1885
- }, count({ query: l, trans: h }) {
1886
- const { index: f, range: m } = l;
1887
- return new Promise((p, v) => {
1888
- const y = h.objectStore(d), g = f.isPrimaryKey ? y : y.index(f.name), b = r(m), k = b ? g.count(b) : g.count();
1889
- k.onsuccess = j((P) => p(P.target.result)), k.onerror = Y(v);
1890
- });
1891
- } };
1892
- }(a)), u = {};
1893
- return o.forEach((a) => u[a.name] = a), { stack: "dbcore", transaction: t.transaction.bind(t), table(a) {
1894
- if (!u[a])
1895
- throw new Error(`Table '${a}' not found`);
1896
- return u[a];
1897
- }, MIN_KEY: -1 / 0, MAX_KEY: Ue(e), schema: s };
1898
- }
1899
- function Ut({ _novip: t }, e) {
1900
- const n = e.db, r = function(s, i, { IDBKeyRange: o, indexedDB: u }, a) {
1901
- return { dbcore: function(c, d) {
1902
- return d.reduce((l, { create: h }) => ({ ...l, ...h(l) }), c);
1903
- }(Br(i, o, a), s.dbcore) };
1904
- }(t._middlewares, n, t._deps, e);
1905
- t.core = r.dbcore, t.tables.forEach((s) => {
1906
- const i = s.name;
1907
- t.core.schema.tables.some((o) => o.name === i) && (s.core = t.core.table(i), t[i] instanceof t.Table && (t[i].core = s.core));
1908
- });
1909
- }
1910
- function mt({ _novip: t }, e, n, r) {
1911
- n.forEach((s) => {
1912
- const i = r[s];
1913
- e.forEach((o) => {
1914
- const u = Jt(o, s);
1915
- (!u || "value" in u && u.value === void 0) && (o === t.Transaction.prototype || o instanceof t.Transaction ? ee(o, s, { get() {
1916
- return this.table(s);
1917
- }, set(a) {
1918
- Pn(this, s, { value: a, writable: !0, configurable: !0, enumerable: !0 });
1919
- } }) : o[s] = new t.Table(s, i));
1920
- });
1921
- });
1922
- }
1923
- function Vt({ _novip: t }, e) {
1924
- e.forEach((n) => {
1925
- for (let r in n)
1926
- n[r] instanceof t.Table && delete n[r];
1927
- });
1928
- }
1929
- function Fr(t, e) {
1930
- return t._cfg.version - e._cfg.version;
1931
- }
1932
- function Mr(t, e, n, r) {
1933
- const s = t._dbSchema, i = t._createTransaction("readwrite", t._storeNames, s);
1934
- i.create(n), i._completion.catch(r);
1935
- const o = i._reject.bind(i), u = E.transless || E;
1936
- oe(() => {
1937
- E.trans = i, E.transless = u, e === 0 ? ($(s).forEach((a) => {
1938
- Et(n, a, s[a].primKey, s[a].indexes);
1939
- }), Ut(t, n), S.follow(() => t.on.populate.fire(i)).catch(o)) : function({ _novip: a }, c, d, l) {
1940
- const h = [], f = a._versions;
1941
- let m = a._dbSchema = zt(a, a.idbdb, l), p = !1;
1942
- const v = f.filter((g) => g._cfg.version >= c);
1943
- function y() {
1944
- return h.length ? S.resolve(h.shift()(d.idbtrans)).then(y) : S.resolve();
1945
- }
1946
- return v.forEach((g) => {
1947
- h.push(() => {
1948
- const b = m, k = g._cfg.dbschema;
1949
- Ht(a, b, l), Ht(a, k, l), m = a._dbSchema = k;
1950
- const P = Jn(b, k);
1951
- P.add.forEach((w) => {
1952
- Et(l, w[0], w[1].primKey, w[1].indexes);
1953
- }), P.change.forEach((w) => {
1954
- if (w.recreate)
1955
- throw new C.Upgrade("Not yet support for changing primary key");
1956
- {
1957
- const A = l.objectStore(w.name);
1958
- w.add.forEach((_) => Wt(A, _)), w.change.forEach((_) => {
1959
- A.deleteIndex(_.name), Wt(A, _);
1960
- }), w.del.forEach((_) => A.deleteIndex(_));
1961
- }
1962
- });
1963
- const x = g._cfg.contentUpgrade;
1964
- if (x && g._cfg.version > c) {
1965
- Ut(a, l), d._memoizedTables = {}, p = !0;
1966
- let w = An(k);
1967
- P.del.forEach((O) => {
1968
- w[O] = b[O];
1969
- }), Vt(a, [a.Transaction.prototype]), mt(a, [a.Transaction.prototype], $(w), w), d.schema = w;
1970
- const A = Zt(x);
1971
- let _;
1972
- A && Ce();
1973
- const R = S.follow(() => {
1974
- if (_ = x(d), _ && A) {
1975
- var O = ne.bind(null, null);
1976
- _.then(O, O);
1977
- }
1978
- });
1979
- return _ && typeof _.then == "function" ? S.resolve(_) : R.then(() => _);
1980
- }
1981
- }), h.push((b) => {
1982
- (!p || !Ar) && function(k, P) {
1983
- [].slice.call(P.db.objectStoreNames).forEach((x) => k[x] == null && P.db.deleteObjectStore(x));
1984
- }(g._cfg.dbschema, b), Vt(a, [a.Transaction.prototype]), mt(a, [a.Transaction.prototype], a._storeNames, a._dbSchema), d.schema = a._dbSchema;
1985
- });
1986
- }), y().then(() => {
1987
- var g, b;
1988
- b = l, $(g = m).forEach((k) => {
1989
- b.db.objectStoreNames.contains(k) || Et(b, k, g[k].primKey, g[k].indexes);
1990
- });
1991
- });
1992
- }(t, e, i, n).catch(o);
1993
- });
1994
- }
1995
- function Jn(t, e) {
1996
- const n = { del: [], add: [], change: [] };
1997
- let r;
1998
- for (r in t)
1999
- e[r] || n.del.push(r);
2000
- for (r in e) {
2001
- const s = t[r], i = e[r];
2002
- if (s) {
2003
- const o = { name: r, def: i, recreate: !1, del: [], add: [], change: [] };
2004
- if ("" + (s.primKey.keyPath || "") != "" + (i.primKey.keyPath || "") || s.primKey.auto !== i.primKey.auto && !yt)
2005
- o.recreate = !0, n.change.push(o);
2006
- else {
2007
- const u = s.idxByName, a = i.idxByName;
2008
- let c;
2009
- for (c in u)
2010
- a[c] || o.del.push(c);
2011
- for (c in a) {
2012
- const d = u[c], l = a[c];
2013
- d ? d.src !== l.src && o.change.push(l) : o.add.push(l);
2014
- }
2015
- (o.del.length > 0 || o.add.length > 0 || o.change.length > 0) && n.change.push(o);
2016
- }
2017
- } else
2018
- n.add.push([r, i]);
2019
- }
2020
- return n;
2021
- }
2022
- function Et(t, e, n, r) {
2023
- const s = t.db.createObjectStore(e, n.keyPath ? { keyPath: n.keyPath, autoIncrement: n.auto } : { autoIncrement: n.auto });
2024
- return r.forEach((i) => Wt(s, i)), s;
2025
- }
2026
- function Wt(t, e) {
2027
- t.createIndex(e.name, e.keyPath, { unique: e.unique, multiEntry: e.multi });
2028
- }
2029
- function zt(t, e, n) {
2030
- const r = {};
2031
- return lt(e.objectStoreNames, 0).forEach((s) => {
2032
- const i = n.objectStore(s);
2033
- let o = i.keyPath;
2034
- const u = qt(Xn(o), o || "", !1, !1, !!i.autoIncrement, o && typeof o != "string", !0), a = [];
2035
- for (let d = 0; d < i.indexNames.length; ++d) {
2036
- const l = i.index(i.indexNames[d]);
2037
- o = l.keyPath;
2038
- var c = qt(l.name, o, !!l.unique, !!l.multiEntry, !1, o && typeof o != "string", !1);
2039
- a.push(c);
2040
- }
2041
- r[s] = Qn(s, u, a);
2042
- }), r;
2043
- }
2044
- function Ht({ _novip: t }, e, n) {
2045
- const r = n.db.objectStoreNames;
2046
- for (let s = 0; s < r.length; ++s) {
2047
- const i = r[s], o = n.objectStore(i);
2048
- t._hasGetAll = "getAll" in o;
2049
- for (let u = 0; u < o.indexNames.length; ++u) {
2050
- const a = o.indexNames[u], c = o.index(a).keyPath, d = typeof c == "string" ? c : "[" + lt(c).join("+") + "]";
2051
- if (e[i]) {
2052
- const l = e[i].idxByName[d];
2053
- l && (l.name = a, delete e[i].idxByName[d], e[i].idxByName[a] = l);
2054
- }
2055
- }
2056
- }
2057
- typeof navigator < "u" && /Safari/.test(navigator.userAgent) && !/(Chrome\/|Edge\/)/.test(navigator.userAgent) && K.WorkerGlobalScope && K instanceof K.WorkerGlobalScope && [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604 && (t._hasGetAll = !1);
2058
- }
2059
- class qr {
2060
- _parseStoresSpec(e, n) {
2061
- $(e).forEach((r) => {
2062
- if (e[r] !== null) {
2063
- var s = e[r].split(",").map((o, u) => {
2064
- const a = (o = o.trim()).replace(/([&*]|\+\+)/g, ""), c = /^\[/.test(a) ? a.match(/^\[(.*)\]$/)[1].split("+") : a;
2065
- return qt(a, c || null, /\&/.test(o), /\*/.test(o), /\+\+/.test(o), M(c), u === 0);
2066
- }), i = s.shift();
2067
- if (i.multi)
2068
- throw new C.Schema("Primary key cannot be multi-valued");
2069
- s.forEach((o) => {
2070
- if (o.auto)
2071
- throw new C.Schema("Only primary key can be marked as autoIncrement (++)");
2072
- if (!o.keyPath)
2073
- throw new C.Schema("Index must have a name and cannot be an empty string");
2074
- }), n[r] = Qn(r, i, s);
2075
- }
2076
- });
2077
- }
2078
- stores(e) {
2079
- const n = this.db;
2080
- this._cfg.storesSource = this._cfg.storesSource ? U(this._cfg.storesSource, e) : e;
2081
- const r = n._versions, s = {};
2082
- let i = {};
2083
- return r.forEach((o) => {
2084
- U(s, o._cfg.storesSource), i = o._cfg.dbschema = {}, o._parseStoresSpec(s, i);
2085
- }), n._dbSchema = i, Vt(n, [n._allTables, n, n.Transaction.prototype]), mt(n, [n._allTables, n, n.Transaction.prototype, this._cfg.tables], $(i), i), n._storeNames = $(i), this;
2086
- }
2087
- upgrade(e) {
2088
- return this._cfg.contentUpgrade = nn(this._cfg.contentUpgrade || I, e), this;
2089
- }
2090
- }
2091
- function an(t, e) {
2092
- let n = t._dbNamesDB;
2093
- return n || (n = t._dbNamesDB = new pe(vt, { addons: [], indexedDB: t, IDBKeyRange: e }), n.version(1).stores({ dbnames: "name" })), n.table("dbnames");
2094
- }
2095
- function un(t) {
2096
- return t && typeof t.databases == "function";
2097
- }
2098
- function Yt(t) {
2099
- return oe(function() {
2100
- return E.letThrough = !0, t();
2101
- });
2102
- }
2103
- function Lr() {
2104
- var t;
2105
- return !navigator.userAgentData && /Safari\//.test(navigator.userAgent) && !/Chrom(e|ium)\//.test(navigator.userAgent) && indexedDB.databases ? new Promise(function(e) {
2106
- var n = function() {
2107
- return indexedDB.databases().finally(e);
2108
- };
2109
- t = setInterval(n, 100), n();
2110
- }).finally(function() {
2111
- return clearInterval(t);
2112
- }) : Promise.resolve();
2113
- }
2114
- function Ur(t) {
2115
- const e = t._state, { indexedDB: n } = t._deps;
2116
- if (e.isBeingOpened || t.idbdb)
2117
- return e.dbReadyPromise.then(() => e.dbOpenError ? D(e.dbOpenError) : t);
2118
- G && (e.openCanceller._stackHolder = Ee()), e.isBeingOpened = !0, e.dbOpenError = null, e.openComplete = !1;
2119
- const r = e.openCanceller;
2120
- function s() {
2121
- if (e.openCanceller !== r)
2122
- throw new C.DatabaseClosed("db.open() was cancelled");
2123
- }
2124
- let i = e.dbReadyResolve, o = null, u = !1;
2125
- return S.race([r, (typeof navigator > "u" ? S.resolve() : Lr()).then(() => new S((a, c) => {
2126
- if (s(), !n)
2127
- throw new C.MissingAPI();
2128
- const d = t.name, l = e.autoSchema ? n.open(d) : n.open(d, Math.round(10 * t.verno));
2129
- if (!l)
2130
- throw new C.MissingAPI();
2131
- l.onerror = Y(c), l.onblocked = j(t._fireOnBlocked), l.onupgradeneeded = j((h) => {
2132
- if (o = l.transaction, e.autoSchema && !t._options.allowEmptyDB) {
2133
- l.onerror = qe, o.abort(), l.result.close();
2134
- const m = n.deleteDatabase(d);
2135
- m.onsuccess = m.onerror = j(() => {
2136
- c(new C.NoSuchDatabase(`Database ${d} doesnt exist`));
2137
- });
2138
- } else {
2139
- o.onerror = Y(c);
2140
- var f = h.oldVersion > Math.pow(2, 62) ? 0 : h.oldVersion;
2141
- u = f < 1, t._novip.idbdb = l.result, Mr(t, f / 10, o, c);
2142
- }
2143
- }, c), l.onsuccess = j(() => {
2144
- o = null;
2145
- const h = t._novip.idbdb = l.result, f = lt(h.objectStoreNames);
2146
- if (f.length > 0)
2147
- try {
2148
- const p = h.transaction((m = f).length === 1 ? m[0] : m, "readonly");
2149
- e.autoSchema ? function({ _novip: v }, y, g) {
2150
- v.verno = y.version / 10;
2151
- const b = v._dbSchema = zt(0, y, g);
2152
- v._storeNames = lt(y.objectStoreNames, 0), mt(v, [v._allTables], $(b), b);
2153
- }(t, h, p) : (Ht(t, t._dbSchema, p), function(v, y) {
2154
- const g = Jn(zt(0, v.idbdb, y), v._dbSchema);
2155
- return !(g.add.length || g.change.some((b) => b.add.length || b.change.length));
2156
- }(t, p) || console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.")), Ut(t, p);
2157
- } catch {
2158
- }
2159
- var m;
2160
- Ne.push(t), h.onversionchange = j((p) => {
2161
- e.vcFired = !0, t.on("versionchange").fire(p);
2162
- }), h.onclose = j((p) => {
2163
- t.on("close").fire(p);
2164
- }), u && function({ indexedDB: p, IDBKeyRange: v }, y) {
2165
- !un(p) && y !== vt && an(p, v).put({ name: y }).catch(I);
2166
- }(t._deps, d), a();
2167
- }, c);
2168
- }))]).then(() => (s(), e.onReadyBeingFired = [], S.resolve(Yt(() => t.on.ready.fire(t.vip))).then(function a() {
2169
- if (e.onReadyBeingFired.length > 0) {
2170
- let c = e.onReadyBeingFired.reduce(nn, I);
2171
- return e.onReadyBeingFired = [], S.resolve(Yt(() => c(t.vip))).then(a);
2172
- }
2173
- }))).finally(() => {
2174
- e.onReadyBeingFired = null, e.isBeingOpened = !1;
2175
- }).then(() => t).catch((a) => {
2176
- e.dbOpenError = a;
2177
- try {
2178
- o && o.abort();
2179
- } catch {
2180
- }
2181
- return r === e.openCanceller && t._close(), D(a);
2182
- }).finally(() => {
2183
- e.openComplete = !0, i();
2184
- });
2185
- }
2186
- function Gt(t) {
2187
- var e = (i) => t.next(i), n = s(e), r = s((i) => t.throw(i));
2188
- function s(i) {
2189
- return (o) => {
2190
- var u = i(o), a = u.value;
2191
- return u.done ? a : a && typeof a.then == "function" ? a.then(n, r) : M(a) ? Promise.all(a).then(n, r) : n(a);
2192
- };
2193
- }
2194
- return s(e)();
2195
- }
2196
- function Vr(t, e, n) {
2197
- var r = arguments.length;
2198
- if (r < 2)
2199
- throw new C.InvalidArgument("Too few arguments");
2200
- for (var s = new Array(r - 1); --r; )
2201
- s[r - 1] = arguments[r];
2202
- return n = s.pop(), [t, On(s), n];
2203
- }
2204
- function Zn(t, e, n, r, s) {
2205
- return S.resolve().then(() => {
2206
- const i = E.transless || E, o = t._createTransaction(e, n, t._dbSchema, r), u = { trans: o, transless: i };
2207
- if (r)
2208
- o.idbtrans = r.idbtrans;
2209
- else
2210
- try {
2211
- o.create(), t._state.PR1398_maxLoop = 3;
2212
- } catch (l) {
2213
- return l.name === tn.InvalidState && t.isOpen() && --t._state.PR1398_maxLoop > 0 ? (console.warn("Dexie: Need to reopen db"), t._close(), t.open().then(() => Zn(t, e, n, null, s))) : D(l);
2214
- }
2215
- const a = Zt(s);
2216
- let c;
2217
- a && Ce();
2218
- const d = S.follow(() => {
2219
- if (c = s.call(o, o), c)
2220
- if (a) {
2221
- var l = ne.bind(null, null);
2222
- c.then(l, l);
2223
- } else
2224
- typeof c.next == "function" && typeof c.throw == "function" && (c = Gt(c));
2225
- }, u);
2226
- return (c && typeof c.then == "function" ? S.resolve(c).then((l) => o.active ? l : D(new C.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))) : d.then(() => c)).then((l) => (r && o._resolve(), o._completion.then(() => l))).catch((l) => (o._reject(l), D(l)));
2227
- });
2228
- }
2229
- function et(t, e, n) {
2230
- const r = M(t) ? t.slice() : [t];
2231
- for (let s = 0; s < n; ++s)
2232
- r.push(e);
2233
- return r;
2234
- }
2235
- const Wr = { stack: "dbcore", name: "VirtualIndexMiddleware", level: 1, create: function(t) {
2236
- return { ...t, table(e) {
2237
- const n = t.table(e), { schema: r } = n, s = {}, i = [];
2238
- function o(c, d, l) {
2239
- const h = De(c), f = s[h] = s[h] || [], m = c == null ? 0 : typeof c == "string" ? 1 : c.length, p = d > 0, v = { ...l, isVirtual: p, keyTail: d, keyLength: m, extractKey: Lt(c), unique: !p && l.unique };
2240
- return f.push(v), v.isPrimaryKey || i.push(v), m > 1 && o(m === 2 ? c[0] : c.slice(0, m - 1), d + 1, l), f.sort((y, g) => y.keyTail - g.keyTail), v;
2241
- }
2242
- const u = o(r.primaryKey.keyPath, 0, r.primaryKey);
2243
- s[":id"] = [u];
2244
- for (const c of r.indexes)
2245
- o(c.keyPath, 0, c);
2246
- function a(c) {
2247
- const d = c.query.index;
2248
- return d.isVirtual ? { ...c, query: { index: d, range: (l = c.query.range, h = d.keyTail, { type: l.type === 1 ? 2 : l.type, lower: et(l.lower, l.lowerOpen ? t.MAX_KEY : t.MIN_KEY, h), lowerOpen: !0, upper: et(l.upper, l.upperOpen ? t.MIN_KEY : t.MAX_KEY, h), upperOpen: !0 }) } } : c;
2249
- var l, h;
2250
- }
2251
- return { ...n, schema: { ...r, primaryKey: u, indexes: i, getIndexByKeyPath: function(c) {
2252
- const d = s[De(c)];
2253
- return d && d[0];
2254
- } }, count: (c) => n.count(a(c)), query: (c) => n.query(a(c)), openCursor(c) {
2255
- const { keyTail: d, isVirtual: l, keyLength: h } = c.query.index;
2256
- return l ? n.openCursor(a(c)).then((f) => f && function(m) {
2257
- return Object.create(m, { continue: { value: function(p) {
2258
- p != null ? m.continue(et(p, c.reverse ? t.MAX_KEY : t.MIN_KEY, d)) : c.unique ? m.continue(m.key.slice(0, h).concat(c.reverse ? t.MIN_KEY : t.MAX_KEY, d)) : m.continue();
2259
- } }, continuePrimaryKey: { value(p, v) {
2260
- m.continuePrimaryKey(et(p, t.MAX_KEY, d), v);
2261
- } }, primaryKey: { get: () => m.primaryKey }, key: { get() {
2262
- const p = m.key;
2263
- return h === 1 ? p[0] : p.slice(0, h);
2264
- } }, value: { get: () => m.value } });
2265
- }(f)) : n.openCursor(c);
2266
- } };
2267
- } };
2268
- } };
2269
- function ln(t, e, n, r) {
2270
- return n = n || {}, r = r || "", $(t).forEach((s) => {
2271
- if (z(e, s)) {
2272
- var i = t[s], o = e[s];
2273
- if (typeof i == "object" && typeof o == "object" && i && o) {
2274
- const u = Tt(i);
2275
- u !== Tt(o) ? n[r + s] = e[s] : u === "Object" ? ln(i, o, n, r + s + ".") : i !== o && (n[r + s] = e[s]);
2276
- } else
2277
- i !== o && (n[r + s] = e[s]);
2278
- } else
2279
- n[r + s] = void 0;
2280
- }), $(e).forEach((s) => {
2281
- z(t, s) || (n[r + s] = e[s]);
2282
- }), n;
2283
- }
2284
- const zr = { stack: "dbcore", name: "HooksMiddleware", level: 2, create: (t) => ({ ...t, table(e) {
2285
- const n = t.table(e), { primaryKey: r } = n.schema;
2286
- return { ...n, mutate(s) {
2287
- const i = E.trans, { deleting: o, creating: u, updating: a } = i.table(e).hook;
2288
- switch (s.type) {
2289
- case "add":
2290
- if (u.fire === I)
2291
- break;
2292
- return i._promise("readwrite", () => c(s), !0);
2293
- case "put":
2294
- if (u.fire === I && a.fire === I)
2295
- break;
2296
- return i._promise("readwrite", () => c(s), !0);
2297
- case "delete":
2298
- if (o.fire === I)
2299
- break;
2300
- return i._promise("readwrite", () => c(s), !0);
2301
- case "deleteRange":
2302
- if (o.fire === I)
2303
- break;
2304
- return i._promise("readwrite", () => function(l) {
2305
- return d(l.trans, l.range, 1e4);
2306
- }(s), !0);
2307
- }
2308
- return n.mutate(s);
2309
- function c(l) {
2310
- const h = E.trans, f = l.keys || function(m, p) {
2311
- return p.type === "delete" ? p.keys : p.keys || p.values.map(m.extractKey);
2312
- }(r, l);
2313
- if (!f)
2314
- throw new Error("Keys missing");
2315
- return (l = l.type === "add" || l.type === "put" ? { ...l, keys: f } : { ...l }).type !== "delete" && (l.values = [...l.values]), l.keys && (l.keys = [...l.keys]), function(m, p, v) {
2316
- return p.type === "add" ? Promise.resolve([]) : m.getMany({ trans: p.trans, keys: v, cache: "immutable" });
2317
- }(n, l, f).then((m) => {
2318
- const p = f.map((v, y) => {
2319
- const g = m[y], b = { onerror: null, onsuccess: null };
2320
- if (l.type === "delete")
2321
- o.fire.call(b, v, g, h);
2322
- else if (l.type === "add" || g === void 0) {
2323
- const k = u.fire.call(b, v, l.values[y], h);
2324
- v == null && k != null && (v = k, l.keys[y] = v, r.outbound || H(l.values[y], r.keyPath, v));
2325
- } else {
2326
- const k = ln(g, l.values[y]), P = a.fire.call(b, k, v, g, h);
2327
- if (P) {
2328
- const x = l.values[y];
2329
- Object.keys(P).forEach((w) => {
2330
- z(x, w) ? x[w] = P[w] : H(x, w, P[w]);
2331
- });
2332
- }
2333
- }
2334
- return b;
2335
- });
2336
- return n.mutate(l).then(({ failures: v, results: y, numFailures: g, lastResult: b }) => {
2337
- for (let k = 0; k < f.length; ++k) {
2338
- const P = y ? y[k] : f[k], x = p[k];
2339
- P == null ? x.onerror && x.onerror(v[k]) : x.onsuccess && x.onsuccess(l.type === "put" && m[k] ? l.values[k] : P);
2340
- }
2341
- return { failures: v, results: y, numFailures: g, lastResult: b };
2342
- }).catch((v) => (p.forEach((y) => y.onerror && y.onerror(v)), Promise.reject(v)));
2343
- });
2344
- }
2345
- function d(l, h, f) {
2346
- return n.query({ trans: l, values: !1, query: { index: r, range: h }, limit: f }).then(({ result: m }) => c({ type: "delete", keys: m, trans: l }).then((p) => p.numFailures > 0 ? Promise.reject(p.failures[0]) : m.length < f ? { failures: [], numFailures: 0, lastResult: void 0 } : d(l, { ...h, lower: m[m.length - 1], lowerOpen: !0 }, f)));
2347
- }
2348
- } };
2349
- } }) };
2350
- function er(t, e, n) {
2351
- try {
2352
- if (!e || e.keys.length < t.length)
2353
- return null;
2354
- const r = [];
2355
- for (let s = 0, i = 0; s < e.keys.length && i < t.length; ++s)
2356
- L(e.keys[s], t[i]) === 0 && (r.push(n ? We(e.values[s]) : e.values[s]), ++i);
2357
- return r.length === t.length ? r : null;
2358
- } catch {
2359
- return null;
2360
- }
2361
- }
2362
- const Hr = { stack: "dbcore", level: -1, create: (t) => ({ table: (e) => {
2363
- const n = t.table(e);
2364
- return { ...n, getMany: (r) => {
2365
- if (!r.cache)
2366
- return n.getMany(r);
2367
- const s = er(r.keys, r.trans._cache, r.cache === "clone");
2368
- return s ? S.resolve(s) : n.getMany(r).then((i) => (r.trans._cache = { keys: r.keys, values: r.cache === "clone" ? We(i) : i }, i));
2369
- }, mutate: (r) => (r.type !== "add" && (r.trans._cache = null), n.mutate(r)) };
2370
- } }) };
2371
- function cn(t) {
2372
- return !("from" in t);
2373
- }
2374
- const Q = function(t, e) {
2375
- if (!this) {
2376
- const n = new Q();
2377
- return t && "d" in t && U(n, t), n;
2378
- }
2379
- U(this, arguments.length ? { d: 1, from: t, to: arguments.length > 1 ? e : t } : { d: 0 });
2380
- };
2381
- function Ve(t, e, n) {
2382
- const r = L(e, n);
2383
- if (isNaN(r))
2384
- return;
2385
- if (r > 0)
2386
- throw RangeError();
2387
- if (cn(t))
2388
- return U(t, { from: e, to: n, d: 1 });
2389
- const s = t.l, i = t.r;
2390
- if (L(n, t.from) < 0)
2391
- return s ? Ve(s, e, n) : t.l = { from: e, to: n, d: 1, l: null, r: null }, xn(t);
2392
- if (L(e, t.to) > 0)
2393
- return i ? Ve(i, e, n) : t.r = { from: e, to: n, d: 1, l: null, r: null }, xn(t);
2394
- L(e, t.from) < 0 && (t.from = e, t.l = null, t.d = i ? i.d + 1 : 1), L(n, t.to) > 0 && (t.to = n, t.r = null, t.d = t.l ? t.l.d + 1 : 1);
2395
- const o = !t.r;
2396
- s && !t.l && gt(t, s), i && o && gt(t, i);
2397
- }
2398
- function gt(t, e) {
2399
- cn(e) || function n(r, { from: s, to: i, l: o, r: u }) {
2400
- Ve(r, s, i), o && n(r, o), u && n(r, u);
2401
- }(t, e);
2402
- }
2403
- function Yr(t, e) {
2404
- const n = Xt(e);
2405
- let r = n.next();
2406
- if (r.done)
2407
- return !1;
2408
- let s = r.value;
2409
- const i = Xt(t);
2410
- let o = i.next(s.from), u = o.value;
2411
- for (; !r.done && !o.done; ) {
2412
- if (L(u.from, s.to) <= 0 && L(u.to, s.from) >= 0)
2413
- return !0;
2414
- L(s.from, u.from) < 0 ? s = (r = n.next(u.from)).value : u = (o = i.next(s.from)).value;
2415
- }
2416
- return !1;
2417
- }
2418
- function Xt(t) {
2419
- let e = cn(t) ? null : { s: 0, n: t };
2420
- return { next(n) {
2421
- const r = arguments.length > 0;
2422
- for (; e; )
2423
- switch (e.s) {
2424
- case 0:
2425
- if (e.s = 1, r)
2426
- for (; e.n.l && L(n, e.n.from) < 0; )
2427
- e = { up: e, n: e.n.l, s: 1 };
2428
- else
2429
- for (; e.n.l; )
2430
- e = { up: e, n: e.n.l, s: 1 };
2431
- case 1:
2432
- if (e.s = 2, !r || L(n, e.n.to) <= 0)
2433
- return { value: e.n, done: !1 };
2434
- case 2:
2435
- if (e.n.r) {
2436
- e.s = 3, e = { up: e, n: e.n.r, s: 0 };
2437
- continue;
2438
- }
2439
- case 3:
2440
- e = e.up;
2441
- }
2442
- return { done: !0 };
2443
- } };
2444
- }
2445
- function xn(t) {
2446
- var e, n;
2447
- const r = (((e = t.r) === null || e === void 0 ? void 0 : e.d) || 0) - (((n = t.l) === null || n === void 0 ? void 0 : n.d) || 0), s = r > 1 ? "r" : r < -1 ? "l" : "";
2448
- if (s) {
2449
- const i = s === "r" ? "l" : "r", o = { ...t }, u = t[s];
2450
- t.from = u.from, t.to = u.to, t[s] = u[s], o[s] = u[i], t[i] = o, o.d = Sn(o);
2451
- }
2452
- t.d = Sn(t);
2453
- }
2454
- function Sn({ r: t, l: e }) {
2455
- return (t ? e ? Math.max(t.d, e.d) : t.d : e ? e.d : 0) + 1;
2456
- }
2457
- Pe(Q.prototype, { add(t) {
2458
- return gt(this, t), this;
2459
- }, addKey(t) {
2460
- return Ve(this, t, t), this;
2461
- }, addKeys(t) {
2462
- return t.forEach((e) => Ve(this, e, e)), this;
2463
- }, [At]() {
2464
- return Xt(this);
2465
- } });
2466
- const Gr = { stack: "dbcore", level: 0, create: (t) => {
2467
- const e = t.schema.name, n = new Q(t.MIN_KEY, t.MAX_KEY);
2468
- return { ...t, table: (r) => {
2469
- const s = t.table(r), { schema: i } = s, { primaryKey: o } = i, { extractKey: u, outbound: a } = o, c = { ...s, mutate: (h) => {
2470
- const f = h.trans, m = f.mutatedParts || (f.mutatedParts = {}), p = (x) => {
2471
- const w = `idb://${e}/${r}/${x}`;
2472
- return m[w] || (m[w] = new Q());
2473
- }, v = p(""), y = p(":dels"), { type: g } = h;
2474
- let [b, k] = h.type === "deleteRange" ? [h.range] : h.type === "delete" ? [h.keys] : h.values.length < 50 ? [[], h.values] : [];
2475
- const P = h.trans._cache;
2476
- return s.mutate(h).then((x) => {
2477
- if (M(b)) {
2478
- g !== "delete" && (b = x.results), v.addKeys(b);
2479
- const w = er(b, P);
2480
- w || g === "add" || y.addKeys(b), (w || k) && function(A, _, R, O) {
2481
- function q(B) {
2482
- const N = A(B.name || "");
2483
- function ye(V) {
2484
- return V != null ? B.extractKey(V) : null;
2485
- }
2486
- const ve = (V) => B.multiEntry && M(V) ? V.forEach((le) => N.addKey(le)) : N.addKey(V);
2487
- (R || O).forEach((V, le) => {
2488
- const Ae = R && ye(R[le]), bt = O && ye(O[le]);
2489
- L(Ae, bt) !== 0 && (Ae != null && ve(Ae), bt != null && ve(bt));
2490
- });
2491
- }
2492
- _.indexes.forEach(q);
2493
- }(p, i, w, k);
2494
- } else if (b) {
2495
- const w = { from: b.lower, to: b.upper };
2496
- y.add(w), v.add(w);
2497
- } else
2498
- v.add(n), y.add(n), i.indexes.forEach((w) => p(w.name).add(n));
2499
- return x;
2500
- });
2501
- } }, d = ({ query: { index: h, range: f } }) => {
2502
- var m, p;
2503
- return [h, new Q((m = f.lower) !== null && m !== void 0 ? m : t.MIN_KEY, (p = f.upper) !== null && p !== void 0 ? p : t.MAX_KEY)];
2504
- }, l = { get: (h) => [o, new Q(h.key)], getMany: (h) => [o, new Q().addKeys(h.keys)], count: d, query: d, openCursor: d };
2505
- return $(l).forEach((h) => {
2506
- c[h] = function(f) {
2507
- const { subscr: m } = E;
2508
- if (m) {
2509
- const p = (k) => {
2510
- const P = `idb://${e}/${r}/${k}`;
2511
- return m[P] || (m[P] = new Q());
2512
- }, v = p(""), y = p(":dels"), [g, b] = l[h](f);
2513
- if (p(g.name || "").add(b), !g.isPrimaryKey) {
2514
- if (h !== "count") {
2515
- const k = h === "query" && a && f.values && s.query({ ...f, values: !1 });
2516
- return s[h].apply(this, arguments).then((P) => {
2517
- if (h === "query") {
2518
- if (a && f.values)
2519
- return k.then(({ result: w }) => (v.addKeys(w), P));
2520
- const x = f.values ? P.result.map(u) : P.result;
2521
- f.values ? v.addKeys(x) : y.addKeys(x);
2522
- } else if (h === "openCursor") {
2523
- const x = P, w = f.values;
2524
- return x && Object.create(x, { key: { get: () => (y.addKey(x.primaryKey), x.key) }, primaryKey: { get() {
2525
- const A = x.primaryKey;
2526
- return y.addKey(A), A;
2527
- } }, value: { get: () => (w && v.addKey(x.primaryKey), x.value) } });
2528
- }
2529
- return P;
2530
- });
2531
- }
2532
- y.add(n);
2533
- }
2534
- }
2535
- return s[h].apply(this, arguments);
2536
- };
2537
- }), c;
2538
- } };
2539
- } };
2540
- class pe {
2541
- constructor(e, n) {
2542
- this._middlewares = {}, this.verno = 0;
2543
- const r = pe.dependencies;
2544
- this._options = n = { addons: pe.addons, autoOpen: !0, indexedDB: r.indexedDB, IDBKeyRange: r.IDBKeyRange, ...n }, this._deps = { indexedDB: n.indexedDB, IDBKeyRange: n.IDBKeyRange };
2545
- const { addons: s } = n;
2546
- this._dbSchema = {}, this._versions = [], this._storeNames = [], this._allTables = {}, this.idbdb = null, this._novip = this;
2547
- const i = { dbOpenError: null, isBeingOpened: !1, onReadyBeingFired: null, openComplete: !1, dbReadyResolve: I, dbReadyPromise: null, cancelOpen: I, openCanceller: null, autoSchema: !0, PR1398_maxLoop: 3 };
2548
- var o;
2549
- i.dbReadyPromise = new S((u) => {
2550
- i.dbReadyResolve = u;
2551
- }), i.openCanceller = new S((u, a) => {
2552
- i.cancelOpen = a;
2553
- }), this._state = i, this.name = e, this.on = $e(this, "populate", "blocked", "versionchange", "close", { ready: [nn, I] }), this.on.ready.subscribe = En(this.on.ready.subscribe, (u) => (a, c) => {
2554
- pe.vip(() => {
2555
- const d = this._state;
2556
- if (d.openComplete)
2557
- d.dbOpenError || S.resolve().then(a), c && u(a);
2558
- else if (d.onReadyBeingFired)
2559
- d.onReadyBeingFired.push(a), c && u(a);
2560
- else {
2561
- u(a);
2562
- const l = this;
2563
- c || u(function h() {
2564
- l.on.ready.unsubscribe(a), l.on.ready.unsubscribe(h);
2565
- });
2566
- }
2567
- });
2568
- }), this.Collection = (o = this, Oe(Kr.prototype, function(u, a) {
2569
- this.db = o;
2570
- let c = Hn, d = null;
2571
- if (a)
2572
- try {
2573
- c = a();
2574
- } catch (m) {
2575
- d = m;
2576
- }
2577
- const l = u._ctx, h = l.table, f = h.hook.reading.fire;
2578
- this._ctx = { table: h, index: l.index, isPrimKey: !l.index || h.schema.primKey.keyPath && l.index === h.schema.primKey.name, range: c, keysOnly: !1, dir: "next", unique: "", algorithm: null, filter: null, replayFilter: null, justLimit: !0, isMatch: null, offset: 0, limit: 1 / 0, error: d, or: l.or, valueMapper: f !== Fe ? f : null };
2579
- })), this.Table = function(u) {
2580
- return Oe(Ir.prototype, function(a, c, d) {
2581
- this.db = u, this._tx = d, this.name = a, this.schema = c, this.hook = u._allTables[a] ? u._allTables[a].hook : $e(null, { creating: [br, I], reading: [vr, Fe], updating: [_r, I], deleting: [wr, I] });
2582
- });
2583
- }(this), this.Transaction = function(u) {
2584
- return Oe($r.prototype, function(a, c, d, l, h) {
2585
- this.db = u, this.mode = a, this.storeNames = c, this.schema = d, this.chromeTransactionDurability = l, this.idbtrans = null, this.on = $e(this, "complete", "error", "abort"), this.parent = h || null, this.active = !0, this._reculock = 0, this._blockedFuncs = [], this._resolve = null, this._reject = null, this._waitingFor = null, this._waitingQueue = null, this._spinCount = 0, this._completion = new S((f, m) => {
2586
- this._resolve = f, this._reject = m;
2587
- }), this._completion.then(() => {
2588
- this.active = !1, this.on.complete.fire();
2589
- }, (f) => {
2590
- var m = this.active;
2591
- return this.active = !1, this.on.error.fire(f), this.parent ? this.parent._reject(f) : m && this.idbtrans && this.idbtrans.abort(), D(f);
2592
- });
2593
- });
2594
- }(this), this.Version = function(u) {
2595
- return Oe(qr.prototype, function(a) {
2596
- this.db = u, this._cfg = { version: a, storesSource: null, dbschema: {}, tables: {}, contentUpgrade: null };
2597
- });
2598
- }(this), this.WhereClause = function(u) {
2599
- return Oe(Gn.prototype, function(a, c, d) {
2600
- this.db = u, this._ctx = { table: a, index: c === ":id" ? null : c, or: d };
2601
- const l = u._deps.indexedDB;
2602
- if (!l)
2603
- throw new C.MissingAPI();
2604
- this._cmp = this._ascending = l.cmp.bind(l), this._descending = (h, f) => l.cmp(f, h), this._max = (h, f) => l.cmp(h, f) > 0 ? h : f, this._min = (h, f) => l.cmp(h, f) < 0 ? h : f, this._IDBKeyRange = u._deps.IDBKeyRange;
2605
- });
2606
- }(this), this.on("versionchange", (u) => {
2607
- u.newVersion > 0 ? console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`) : console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`), this.close();
2608
- }), this.on("blocked", (u) => {
2609
- !u.newVersion || u.newVersion < u.oldVersion ? console.warn(`Dexie.delete('${this.name}') was blocked`) : console.warn(`Upgrade '${this.name}' blocked by other connection holding version ${u.oldVersion / 10}`);
2610
- }), this._maxKey = Ue(n.IDBKeyRange), this._createTransaction = (u, a, c, d) => new this.Transaction(u, a, c, this._options.chromeTransactionDurability, d), this._fireOnBlocked = (u) => {
2611
- this.on("blocked").fire(u), Ne.filter((a) => a.name === this.name && a !== this && !a._state.vcFired).map((a) => a.on("versionchange").fire(u));
2612
- }, this.use(Wr), this.use(zr), this.use(Gr), this.use(Hr), this.vip = Object.create(this, { _vip: { value: !0 } }), s.forEach((u) => u(this));
2613
- }
2614
- version(e) {
2615
- if (isNaN(e) || e < 0.1)
2616
- throw new C.Type("Given version is not a positive number");
2617
- if (e = Math.round(10 * e) / 10, this.idbdb || this._state.isBeingOpened)
2618
- throw new C.Schema("Cannot add version when database is open");
2619
- this.verno = Math.max(this.verno, e);
2620
- const n = this._versions;
2621
- var r = n.filter((s) => s._cfg.version === e)[0];
2622
- return r || (r = new this.Version(e), n.push(r), n.sort(Fr), r.stores({}), this._state.autoSchema = !1, r);
2623
- }
2624
- _whenReady(e) {
2625
- return this.idbdb && (this._state.openComplete || E.letThrough || this._vip) ? e() : new S((n, r) => {
2626
- if (this._state.openComplete)
2627
- return r(new C.DatabaseClosed(this._state.dbOpenError));
2628
- if (!this._state.isBeingOpened) {
2629
- if (!this._options.autoOpen)
2630
- return void r(new C.DatabaseClosed());
2631
- this.open().catch(I);
2632
- }
2633
- this._state.dbReadyPromise.then(n, r);
2634
- }).then(e);
2635
- }
2636
- use({ stack: e, create: n, level: r, name: s }) {
2637
- s && this.unuse({ stack: e, name: s });
2638
- const i = this._middlewares[e] || (this._middlewares[e] = []);
2639
- return i.push({ stack: e, create: n, level: r ?? 10, name: s }), i.sort((o, u) => o.level - u.level), this;
2640
- }
2641
- unuse({ stack: e, name: n, create: r }) {
2642
- return e && this._middlewares[e] && (this._middlewares[e] = this._middlewares[e].filter((s) => r ? s.create !== r : !!n && s.name !== n)), this;
2643
- }
2644
- open() {
2645
- return Ur(this);
2646
- }
2647
- _close() {
2648
- const e = this._state, n = Ne.indexOf(this);
2649
- if (n >= 0 && Ne.splice(n, 1), this.idbdb) {
2650
- try {
2651
- this.idbdb.close();
2652
- } catch {
2653
- }
2654
- this._novip.idbdb = null;
2655
- }
2656
- e.dbReadyPromise = new S((r) => {
2657
- e.dbReadyResolve = r;
2658
- }), e.openCanceller = new S((r, s) => {
2659
- e.cancelOpen = s;
2660
- });
2661
- }
2662
- close() {
2663
- this._close();
2664
- const e = this._state;
2665
- this._options.autoOpen = !1, e.dbOpenError = new C.DatabaseClosed(), e.isBeingOpened && e.cancelOpen(e.dbOpenError);
2666
- }
2667
- delete() {
2668
- const e = arguments.length > 0, n = this._state;
2669
- return new S((r, s) => {
2670
- const i = () => {
2671
- this.close();
2672
- var o = this._deps.indexedDB.deleteDatabase(this.name);
2673
- o.onsuccess = j(() => {
2674
- (function({ indexedDB: u, IDBKeyRange: a }, c) {
2675
- !un(u) && c !== vt && an(u, a).delete(c).catch(I);
2676
- })(this._deps, this.name), r();
2677
- }), o.onerror = Y(s), o.onblocked = this._fireOnBlocked;
2678
- };
2679
- if (e)
2680
- throw new C.InvalidArgument("Arguments not allowed in db.delete()");
2681
- n.isBeingOpened ? n.dbReadyPromise.then(i) : i();
2682
- });
2683
- }
2684
- backendDB() {
2685
- return this.idbdb;
2686
- }
2687
- isOpen() {
2688
- return this.idbdb !== null;
2689
- }
2690
- hasBeenClosed() {
2691
- const e = this._state.dbOpenError;
2692
- return e && e.name === "DatabaseClosed";
2693
- }
2694
- hasFailed() {
2695
- return this._state.dbOpenError !== null;
2696
- }
2697
- dynamicallyOpened() {
2698
- return this._state.autoSchema;
2699
- }
2700
- get tables() {
2701
- return $(this._allTables).map((e) => this._allTables[e]);
2702
- }
2703
- transaction() {
2704
- const e = Vr.apply(this, arguments);
2705
- return this._transaction.apply(this, e);
2706
- }
2707
- _transaction(e, n, r) {
2708
- let s = E.trans;
2709
- s && s.db === this && e.indexOf("!") === -1 || (s = null);
2710
- const i = e.indexOf("?") !== -1;
2711
- let o, u;
2712
- e = e.replace("!", "").replace("?", "");
2713
- try {
2714
- if (u = n.map((c) => {
2715
- var d = c instanceof this.Table ? c.name : c;
2716
- if (typeof d != "string")
2717
- throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");
2718
- return d;
2719
- }), e == "r" || e === _t)
2720
- o = _t;
2721
- else {
2722
- if (e != "rw" && e != kt)
2723
- throw new C.InvalidArgument("Invalid transaction mode: " + e);
2724
- o = kt;
2725
- }
2726
- if (s) {
2727
- if (s.mode === _t && o === kt) {
2728
- if (!i)
2729
- throw new C.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");
2730
- s = null;
2731
- }
2732
- s && u.forEach((c) => {
2733
- if (s && s.storeNames.indexOf(c) === -1) {
2734
- if (!i)
2735
- throw new C.SubTransaction("Table " + c + " not included in parent transaction.");
2736
- s = null;
2737
- }
2738
- }), i && s && !s.active && (s = null);
2739
- }
2740
- } catch (c) {
2741
- return s ? s._promise(null, (d, l) => {
2742
- l(c);
2743
- }) : D(c);
2744
- }
2745
- const a = Zn.bind(null, this, o, u, s, r);
2746
- return s ? s._promise(o, a, "lock") : E.trans ? Te(E.transless, () => this._whenReady(a)) : this._whenReady(a);
2747
- }
2748
- table(e) {
2749
- if (!z(this._allTables, e))
2750
- throw new C.InvalidTable(`Table ${e} does not exist`);
2751
- return this._allTables[e];
2752
- }
2753
- }
2754
- const Xr = typeof Symbol < "u" && "observable" in Symbol ? Symbol.observable : "@@observable";
2755
- class Qr {
2756
- constructor(e) {
2757
- this._subscribe = e;
2758
- }
2759
- subscribe(e, n, r) {
2760
- return this._subscribe(e && typeof e != "function" ? e : { next: e, error: n, complete: r });
2761
- }
2762
- [Xr]() {
2763
- return this;
2764
- }
2765
- }
2766
- function tr(t, e) {
2767
- return $(e).forEach((n) => {
2768
- gt(t[n] || (t[n] = new Q()), e[n]);
2769
- }), t;
2770
- }
2771
- function Jr(t) {
2772
- let e, n = !1;
2773
- const r = new Qr((s) => {
2774
- const i = Zt(t);
2775
- let o = !1, u = {}, a = {};
2776
- const c = { get closed() {
2777
- return o;
2778
- }, unsubscribe: () => {
2779
- o = !0, ue.storagemutated.unsubscribe(f);
2780
- } };
2781
- s.start && s.start(c);
2782
- let d = !1, l = !1;
2783
- function h() {
2784
- return $(a).some((p) => u[p] && Yr(u[p], a[p]));
2785
- }
2786
- const f = (p) => {
2787
- tr(u, p), h() && m();
2788
- }, m = () => {
2789
- if (d || o)
2790
- return;
2791
- u = {};
2792
- const p = {}, v = function(y) {
2793
- i && Ce();
2794
- const g = () => oe(t, { subscr: y, trans: null }), b = E.trans ? Te(E.transless, g) : g();
2795
- return i && b.then(ne, ne), b;
2796
- }(p);
2797
- l || (ue(Le, f), l = !0), d = !0, Promise.resolve(v).then((y) => {
2798
- n = !0, e = y, d = !1, o || (h() ? m() : (u = {}, a = p, s.next && s.next(y)));
2799
- }, (y) => {
2800
- d = !1, n = !1, s.error && s.error(y), c.unsubscribe();
2801
- });
2802
- };
2803
- return m(), c;
2804
- });
2805
- return r.hasValue = () => n, r.getValue = () => e, r;
2806
- }
2807
- let Qt;
2808
- try {
2809
- Qt = { indexedDB: K.indexedDB || K.mozIndexedDB || K.webkitIndexedDB || K.msIndexedDB, IDBKeyRange: K.IDBKeyRange || K.webkitIDBKeyRange };
2810
- } catch {
2811
- Qt = { indexedDB: null, IDBKeyRange: null };
2812
- }
2813
- const ce = pe;
2814
- function at(t) {
2815
- let e = Z;
2816
- try {
2817
- Z = !0, ue.storagemutated.fire(t);
2818
- } finally {
2819
- Z = e;
2820
- }
2821
- }
2822
- Pe(ce, { ...tt, delete: (t) => new ce(t, { addons: [] }).delete(), exists: (t) => new ce(t, { addons: [] }).open().then((e) => (e.close(), !0)).catch("NoSuchDatabaseError", () => !1), getDatabaseNames(t) {
2823
- try {
2824
- return function({ indexedDB: e, IDBKeyRange: n }) {
2825
- return un(e) ? Promise.resolve(e.databases()).then((r) => r.map((s) => s.name).filter((s) => s !== vt)) : an(e, n).toCollection().primaryKeys();
2826
- }(ce.dependencies).then(t);
2827
- } catch {
2828
- return D(new C.MissingAPI());
2829
- }
2830
- }, defineClass: () => function(t) {
2831
- U(this, t);
2832
- }, ignoreTransaction: (t) => E.trans ? Te(E.transless, t) : t(), vip: Yt, async: function(t) {
2833
- return function() {
2834
- try {
2835
- var e = Gt(t.apply(this, arguments));
2836
- return e && typeof e.then == "function" ? e : S.resolve(e);
2837
- } catch (n) {
2838
- return D(n);
2839
- }
2840
- };
2841
- }, spawn: function(t, e, n) {
2842
- try {
2843
- var r = Gt(t.apply(n, e || []));
2844
- return r && typeof r.then == "function" ? r : S.resolve(r);
2845
- } catch (s) {
2846
- return D(s);
2847
- }
2848
- }, currentTransaction: { get: () => E.trans || null }, waitFor: function(t, e) {
2849
- const n = S.resolve(typeof t == "function" ? ce.ignoreTransaction(t) : t).timeout(e || 6e4);
2850
- return E.trans ? E.trans.waitFor(n) : n;
2851
- }, Promise: S, debug: { get: () => G, set: (t) => {
2852
- Kn(t, t === "dexie" ? () => !0 : zn);
2853
- } }, derive: ke, extend: U, props: Pe, override: En, Events: $e, on: ue, liveQuery: Jr, extendObservabilitySet: tr, getByKeyPath: te, setByKeyPath: H, delByKeyPath: function(t, e) {
2854
- typeof e == "string" ? H(t, e, void 0) : "length" in e && [].map.call(e, function(n) {
2855
- H(t, n, void 0);
2856
- });
2857
- }, shallowClone: An, deepClone: We, getObjectDiff: ln, cmp: L, asap: Cn, minKey: Mt, addons: [], connections: Ne, errnames: tn, dependencies: Qt, semVer: yn, version: yn.split(".").map((t) => parseInt(t)).reduce((t, e, n) => t + e / Math.pow(10, 2 * n)) }), ce.maxKey = Ue(ce.dependencies.IDBKeyRange), typeof dispatchEvent < "u" && typeof addEventListener < "u" && (ue(Le, (t) => {
2858
- if (!Z) {
2859
- let e;
2860
- yt ? (e = document.createEvent("CustomEvent"), e.initCustomEvent(ie, !0, !0, t)) : e = new CustomEvent(ie, { detail: t }), Z = !0, dispatchEvent(e), Z = !1;
2861
- }
2862
- }), addEventListener(ie, ({ detail: t }) => {
2863
- Z || at(t);
2864
- }));
2865
- let Z = !1;
2866
- if (typeof BroadcastChannel < "u") {
2867
- const t = new BroadcastChannel(ie);
2868
- typeof t.unref == "function" && t.unref(), ue(Le, (e) => {
2869
- Z || t.postMessage(e);
2870
- }), t.onmessage = (e) => {
2871
- e.data && at(e.data);
2872
- };
2873
- } else if (typeof self < "u" && typeof navigator < "u") {
2874
- ue(Le, (e) => {
2875
- try {
2876
- Z || (typeof localStorage < "u" && localStorage.setItem(ie, JSON.stringify({ trig: Math.random(), changedParts: e })), typeof self.clients == "object" && [...self.clients.matchAll({ includeUncontrolled: !0 })].forEach((n) => n.postMessage({ type: ie, changedParts: e })));
2877
- } catch {
2878
- }
2879
- }), typeof addEventListener < "u" && addEventListener("storage", (e) => {
2880
- if (e.key === ie) {
2881
- const n = JSON.parse(e.newValue);
2882
- n && at(n.changedParts);
2883
- }
2884
- });
2885
- const t = self.document && navigator.serviceWorker;
2886
- t && t.addEventListener("message", function({ data: e }) {
2887
- e && e.type === ie && at(e.changedParts);
2888
- });
2889
- }
2890
- S.rejectionMapper = function(t, e) {
2891
- if (!t || t instanceof xe || t instanceof TypeError || t instanceof SyntaxError || !t.name || !fn[t.name])
2892
- return t;
2893
- var n = new fn[t.name](e || t.message, t);
2894
- return "stack" in t && ee(n, "stack", { get: function() {
2895
- return this.inner.stack;
2896
- } }), n;
2897
- }, Kn(G, zn);
2898
- class Zr extends pe {
2899
- constructor() {
2900
- super("NylasAuthDatabase"), ut(this, "grant"), ut(this, "pkce"), this.version(1).stores({
2901
- grant: "++id,token",
2902
- pkce: "++id,codeVerifier"
2903
- }), this.grant = this.table("grant"), this.pkce = this.table("pkce");
2904
- }
2905
- }
2906
- class es {
2907
- constructor() {
2908
- ut(this, "theDB"), this.theDB = new Zr();
2909
- }
2910
- async setCodeVerifier(e) {
2911
- await this.theDB.pkce.put({ id: 1, codeVerifier: e }, 1);
2912
- }
2913
- async getCodeVerifier() {
2914
- const [e] = await this.theDB.pkce.toArray();
2915
- return e ? e.codeVerifier : null;
2916
- }
2917
- async getTokenInfo() {
2918
- const e = await this.theDB.grant.get(1);
2919
- return e ? e.token : null;
2920
- }
2921
- async setTokenInfo(e) {
2922
- await this.theDB.grant.put({ id: 1, token: e }, 1);
2923
- }
2924
- async reset() {
2925
- await this.theDB.grant.clear();
2926
- }
2927
- }
2928
- function is(t) {
2929
- const e = "NylasAuth";
2930
- if (!t)
2931
- throw new Error("NylasAuth requires a config object");
2932
- let n = null;
2933
- if (t.storageType === "indexeddb" && (n = new es()), !n)
2934
- throw new Error("NylasAuth requires a storage object");
2935
- const r = [
2936
- {
2937
- type: "read-only",
2938
- value: "https://www.googleapis.com/auth/gmail.readonly"
2939
- },
2940
- {
2941
- type: "modify",
2942
- value: "https://www.googleapis.com/auth/gmail.modify"
2943
- },
2944
- {
2945
- type: "compose",
2946
- value: "https://www.googleapis.com/auth/gmail.compose"
2947
- },
2948
- {
2949
- type: "insert",
2950
- value: "https://www.googleapis.com/auth/gmail.insert"
2951
- },
2952
- {
2953
- type: "labels",
2954
- value: "https://www.googleapis.com/auth/gmail.labels"
2955
- },
2956
- {
2957
- type: "metadata",
2958
- value: "https://www.googleapis.com/auth/gmail.metadata"
2959
- },
2960
- {
2961
- type: "settings.basic",
2962
- value: "https://www.googleapis.com/auth/gmail.settings.basic"
2963
- },
2964
- {
2965
- type: "settings.sharing",
2966
- value: "https://www.googleapis.com/auth/gmail.settings.sharing"
2967
- }
2968
- ], s = [
2969
- {
2970
- type: "read-only",
2971
- value: "https://outlook.office.com/mail.read"
2972
- },
2973
- {
2974
- type: "modify",
2975
- value: "https://outlook.office.com/mail.readwrite"
2976
- },
2977
- {
2978
- type: "send",
2979
- value: "https://outlook.office.com/mail.send"
2980
- },
2981
- {
2982
- type: "offline",
2983
- value: "offline_access"
2984
- }
2985
- ];
2986
- async function i(o, u, a, c = !0, d, l) {
2987
- const h = await (n == null ? void 0 : n.getTokenInfo()), f = new URL(o, d ?? t.apiUri), m = new Headers();
2988
- m.append("Accept", "application/json"), m.append("Content-Type", "application/json"), m.append("User-Agent", e), h && m.append("Authorization", `Bearer ${h.access_token}`);
2989
- const p = await fetch(f.toString(), {
2990
- method: u || "GET",
2991
- headers: m,
2992
- mode: "cors",
2993
- referrer: location.origin,
2994
- body: a ? JSON.stringify(a) : void 0,
2995
- ...l || {}
2996
- });
2997
- return c ? await p.json() : p.body;
2998
- }
2999
- return {
3000
- config: t,
3001
- /**
3002
- * This method will make a request to the Nylas API to exchange an authorization code for an access token.
3003
- * @param scopes The scopes that were used to generate the authorization code
3004
- * @param email The email that was used to generate the authorization code
3005
- * @param provider The provider that was used to generate the authorization code
3006
- * @returns A promise that resolves to a URL string that can be used to redirect the user to the Nylas API to complete the authorization flow
3007
- */
3008
- async getHostedAuthRedirectURL(o = t.defaultScopes, u, a) {
3009
- const c = await dn(Math.random().toString()), d = await dn(c);
3010
- await (n == null ? void 0 : n.setCodeVerifier(c));
3011
- const l = new URL(`${t.apiUri}/v3/connect/auth`);
3012
- return l.searchParams.set("client_id", t.clientId), l.searchParams.set("response_type", "code"), l.searchParams.set("scope", o.join(" ")), l.searchParams.set("redirect_uri", t.redirectURI), l.searchParams.set("access_type", "offline"), l.searchParams.set("code_challenge", d), l.searchParams.set("code_challenge_method", "S256"), l.searchParams.set("options", "rotate_refresh_token"), a && l.searchParams.set("provider", a), u && l.searchParams.set("login_hint", u), l.toString();
3013
- },
3014
- /**
3015
- * This method will make a request to the Nylas API to exchange an authorization code for an access token.
3016
- * @param path A path to the Nylas API, e.g. `/v3/grants/methreads`
3017
- * @param method GET, POST, PUT, DELETE, etc.
3018
- * @param body A JSON object to send as the body of the request
3019
- * @param domain The domain to use for the request, e.g. `api.us.nylas.com`
3020
- * @param parseJSON Whether to parse the response as JSON or return the raw response (default: true)
3021
- * @returns
3022
- */
3023
- nylasAPIRequest: i,
3024
- /**
3025
- * This method will make a request to the Nylas API to exchange an authorization code for an access token.
3026
- * @param code The authorization code that was returned from the Nylas API
3027
- * @returns A promise that resolves to a TokenExchangeResponse object
3028
- */
3029
- async exchangeAuthCodeForTokenInfo(o) {
3030
- if (!o)
3031
- return null;
3032
- const u = await (n == null ? void 0 : n.getCodeVerifier()), a = await this.nylasAPIRequest("/v3/connect/token", "POST", {
3033
- code: o,
3034
- client_id: t.clientId,
3035
- grant_type: "authorization_code",
3036
- redirect_uri: t.redirectURI,
3037
- code_verifier: u
3038
- });
3039
- return "error" in a || await (n == null ? void 0 : n.setTokenInfo(a)), a;
3040
- },
3041
- /**
3042
- * This method will make a `application/octet-stream` request to the Nylas API to download a file.
3043
- */
3044
- async nylasDownloadFileRequest(o, u = "GET", a) {
3045
- const c = await (n == null ? void 0 : n.getTokenInfo()), d = new URL(o, t.apiUri), l = new Headers();
3046
- return l.append("Accept", "application/json"), l.append("Content-Type", "application/octet-stream"), l.append("User-Agent", e), c && l.append("Authorization", `Bearer ${c.access_token}`), (await fetch(d.toString(), {
3047
- method: u,
3048
- headers: l,
3049
- mode: "cors",
3050
- referrer: location.origin,
3051
- body: a ? JSON.stringify(a) : void 0
3052
- })).blob();
3053
- },
3054
- /**
3055
- * This methid will clear the access token from the storage object
3056
- */
3057
- async logout() {
3058
- const o = await (n == null ? void 0 : n.getTokenInfo());
3059
- o && await this.nylasAPIRequest(`/v3/connect/revoke?token=${o.access_token}`, "POST"), await (n == null ? void 0 : n.reset());
3060
- },
3061
- /**
3062
- * This method will make a request to the Nylas API to exchange an authorization code for an access token.
3063
- * @returns A promise that resolves to a boolean indicating whether the user is authenticated
3064
- */
3065
- async isAuthenticated() {
3066
- return !!await (n == null ? void 0 : n.getTokenInfo());
3067
- },
3068
- /**
3069
- * This method will return information about the current access token.
3070
- * @returns A promise with the token info
3071
- */
3072
- async getTokenInfo() {
3073
- const o = await (n == null ? void 0 : n.getTokenInfo());
3074
- if (!o)
3075
- return null;
3076
- const { access_token: u, ...a } = o;
3077
- return a;
3078
- },
3079
- /**
3080
- * This method will make a request to the Nylas API to validate if the current access token is valid.
3081
- * @returns A promise that resolves to a boolean indicating whether the current access token is valid
3082
- */
3083
- async isAccessTokenValid() {
3084
- const o = await (n == null ? void 0 : n.getTokenInfo());
3085
- return o ? "data" in await this.nylasAPIRequest(`/v3/connect/tokeninfo?id_token=${o.id_token}`, "GET") : !1;
3086
- },
3087
- /**
3088
- * This method will make a request to the Nylas API to refresh the current access token.
3089
- * @returns A promise that resolves to a TokenExchangeResponse object
3090
- */
3091
- async refreshAccessToken() {
3092
- const o = await (n == null ? void 0 : n.getTokenInfo());
3093
- if (!o)
3094
- return null;
3095
- const u = await this.nylasAPIRequest("/v3/connect/token", "POST", {
3096
- client_id: t.clientId,
3097
- grant_type: "refresh_token",
3098
- refresh_token: o.refresh_token
3099
- });
3100
- return "error" in u || await (n == null ? void 0 : n.setTokenInfo(u)), u;
3101
- },
3102
- /**
3103
- * This method will return true if the current access token has the given scope
3104
- * based on the type of scope (e.g. 'read-only', 'modify', 'compose', 'insert', 'labels', 'metadata', 'settings.basic', or 'settings.sharing')
3105
- * @param type Either 'read-only', 'modify', 'compose', 'insert', 'labels', 'metadata', 'settings.basic', or 'settings.sharing'
3106
- */
3107
- async hasScopeByType(o = "email", u) {
3108
- const a = await (n == null ? void 0 : n.getTokenInfo());
3109
- if (!a)
3110
- return !1;
3111
- const c = a.scope.toLowerCase().split(" ");
3112
- let d = [];
3113
- const l = Array.isArray(u) ? u : [u];
3114
- return o === "email" && (d = [...s, ...r].filter((h) => l.includes(h.type))), d.every((h) => c.includes(h.value));
3115
- },
3116
- /**
3117
- * A helper method to check if the current access token has a given scope.
3118
- * @param scope The scope(s) to check for in the current access token (e.g. https://www.googleapis.com/auth/gmail.modify)
3119
- * @returns boolean indicating whether the current access token has the given scope
3120
- */
3121
- async hasScope(o) {
3122
- const u = await (n == null ? void 0 : n.getTokenInfo());
3123
- if (!u)
3124
- return !1;
3125
- const a = u.scope.toLowerCase().split(" ");
3126
- return (Array.isArray(o) ? o : [o]).some((c) => a.includes(c.toLowerCase()));
3127
- }
3128
- };
3129
- }
3130
- export {
3131
- ns as N,
3132
- rs as X,
3133
- ss as Z,
3134
- is as e,
3135
- sr as g,
3136
- ar as n
3137
- };