@ztimson/momentum 0.39.2 → 0.40.0

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.
package/dist/data.d.ts CHANGED
@@ -17,7 +17,7 @@ export type DataEvents = TypedEvents & {
17
17
  create: (collection: string, document: any) => any;
18
18
  read: (collection: string, documents: any | any[]) => any;
19
19
  update: (collection: string, document: any) => any;
20
- delete: (collection: string, document: string) => any;
20
+ delete: (collection: string, document: number) => any;
21
21
  raw: (collection: string, query: RawQuery, response: any) => any;
22
22
  };
23
23
  export declare class Data extends TypedEmitter<DataEvents> {
@@ -25,9 +25,9 @@ export declare class Data extends TypedEmitter<DataEvents> {
25
25
  constructor(api: Api | string);
26
26
  create<T>(collection: string, document: Document<T>): Promise<Document<T>>;
27
27
  read<T extends Meta>(collection: string): Promise<T[]>;
28
- read<T extends Meta>(collection: string, document: string): Promise<T>;
28
+ read<T extends Meta>(collection: string, id: number): Promise<T>;
29
29
  update<T>(collection: string, document: Document<T>, append?: boolean): Promise<Document<T>>;
30
- delete(collection: string, document: string): Promise<void>;
30
+ delete(collection: string, id: number): Promise<void>;
31
31
  raw<T>(collection: string, query: RawQuery): Promise<Document<T>>;
32
32
  }
33
33
  //# sourceMappingURL=data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../src/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAE9D,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;AAEnC,MAAM,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,G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AM,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;CAMjE"}
package/dist/index.cjs CHANGED
@@ -5,10 +5,10 @@
5
5
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
6
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
7
 
8
- var et = Object.defineProperty;
9
- var nt = (n, t, e) => t in n ? et(n, t, { enumerable: true, configurable: true, writable: true, value: e }) : n[t] = e;
10
- var i = (n, t, e) => (nt(n, typeof t != "symbol" ? t + "" : t, e), e);
11
- function rt(n, t = false) {
8
+ var nt = Object.defineProperty;
9
+ var rt = (n, t, e) => t in n ? nt(n, t, { enumerable: true, configurable: true, writable: true, value: e }) : n[t] = e;
10
+ var i = (n, t, e) => (rt(n, typeof t != "symbol" ? t + "" : t, e), e);
11
+ function ot(n, t = false) {
12
12
  if (n == null)
13
13
  throw new Error("Cannot clean a NULL value");
14
14
  return Array.isArray(n) ? n = n.filter((e) => e != null) : Object.entries(n).forEach(([e, r]) => {
@@ -26,6 +26,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
26
26
  return n;
27
27
  }
28
28
  }
29
+ function ut(n) {
30
+ return Array.isArray(n) ? n : [n];
31
+ }
29
32
  class m extends Promise {
30
33
  constructor(e) {
31
34
  super((r, o) => e(
@@ -63,14 +66,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
63
66
  return this.from(super.finally(e));
64
67
  }
65
68
  }
66
- function at(n, t) {
67
- const e = document.createElement("a");
68
- e.href = n, e.download = t, document.body.appendChild(e), e.click(), document.body.removeChild(e);
69
- }
70
69
  function Tt(n, t) {
70
+ n instanceof Blob || (n = new Blob(ut(n)));
71
71
  const e = URL.createObjectURL(n);
72
72
  at(e, t), URL.revokeObjectURL(e);
73
73
  }
74
+ function at(n, t) {
75
+ const e = document.createElement("a");
76
+ e.href = n, e.download = t || n.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
77
+ }
74
78
  function It(n = {}) {
75
79
  return new Promise((t) => {
76
80
  const e = document.createElement("input");
@@ -79,13 +83,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
79
83
  }, document.body.appendChild(e), e.click();
80
84
  });
81
85
  }
82
- function $t(n) {
86
+ function Dt(n) {
83
87
  return new m((t, e, r) => {
84
88
  const o = new XMLHttpRequest(), s = new FormData();
85
89
  n.files.forEach((c) => s.append("file", c)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (c) => c.lengthComputable ? r(c.loaded / c.total) : null), o.addEventListener("loadend", () => t(U(o.responseText))), o.addEventListener("error", () => e(U(o.responseText))), o.addEventListener("timeout", () => e({ error: "Request timed out" })), o.open("POST", n.url), Object.entries(n.headers || {}).forEach(([c, y]) => o.setRequestHeader(c, y)), o.send(s);
86
90
  });
87
91
  }
88
- class F {
92
+ class v {
89
93
  constructor() {
90
94
  i(this, "listeners", {});
91
95
  }
@@ -126,7 +130,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
126
130
  });
127
131
  }
128
132
  }
129
- i(F, "listeners", {});
133
+ i(v, "listeners", {});
130
134
  class p extends Error {
131
135
  constructor(e, r) {
132
136
  super(e);
@@ -155,7 +159,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
155
159
  }
156
160
  }
157
161
  i(p, "code", 500);
158
- class v extends p {
162
+ class Y extends p {
159
163
  constructor(t = "Bad Request") {
160
164
  super(t);
161
165
  }
@@ -163,8 +167,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
163
167
  return t.constructor.code == this.code;
164
168
  }
165
169
  }
166
- i(v, "code", 400);
167
- class Y extends p {
170
+ i(Y, "code", 400);
171
+ class H extends p {
168
172
  constructor(t = "Unauthorized") {
169
173
  super(t);
170
174
  }
@@ -172,8 +176,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
172
176
  return t.constructor.code == this.code;
173
177
  }
174
178
  }
175
- i(Y, "code", 401);
176
- class H extends p {
179
+ i(H, "code", 401);
180
+ class W extends p {
177
181
  constructor(t = "Payment Required") {
178
182
  super(t);
179
183
  }
@@ -181,8 +185,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
181
185
  return t.constructor.code == this.code;
182
186
  }
183
187
  }
184
- i(H, "code", 402);
185
- class W extends p {
188
+ i(W, "code", 402);
189
+ class z extends p {
186
190
  constructor(t = "Forbidden") {
187
191
  super(t);
188
192
  }
@@ -190,8 +194,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
190
194
  return t.constructor.code == this.code;
191
195
  }
192
196
  }
193
- i(W, "code", 403);
194
- class z extends p {
197
+ i(z, "code", 403);
198
+ class J extends p {
195
199
  constructor(t = "Not Found") {
196
200
  super(t);
197
201
  }
@@ -199,8 +203,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
199
203
  return t.constructor.code == this.code;
200
204
  }
201
205
  }
202
- i(z, "code", 404);
203
- class J extends p {
206
+ i(J, "code", 404);
207
+ class K extends p {
204
208
  constructor(t = "Method Not Allowed") {
205
209
  super(t);
206
210
  }
@@ -208,8 +212,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
208
212
  return t.constructor.code == this.code;
209
213
  }
210
214
  }
211
- i(J, "code", 405);
212
- class K extends p {
215
+ i(K, "code", 405);
216
+ class Z extends p {
213
217
  constructor(t = "Not Acceptable") {
214
218
  super(t);
215
219
  }
@@ -217,8 +221,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
217
221
  return t.constructor.code == this.code;
218
222
  }
219
223
  }
220
- i(K, "code", 406);
221
- class Z extends p {
224
+ i(Z, "code", 406);
225
+ class V extends p {
222
226
  constructor(t = "Internal Server Error") {
223
227
  super(t);
224
228
  }
@@ -226,8 +230,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
226
230
  return t.constructor.code == this.code;
227
231
  }
228
232
  }
229
- i(Z, "code", 500);
230
- class V extends p {
233
+ i(V, "code", 500);
234
+ class X extends p {
231
235
  constructor(t = "Not Implemented") {
232
236
  super(t);
233
237
  }
@@ -235,8 +239,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
235
239
  return t.constructor.code == this.code;
236
240
  }
237
241
  }
238
- i(V, "code", 501);
239
- class X extends p {
242
+ i(X, "code", 501);
243
+ class Q extends p {
240
244
  constructor(t = "Bad Gateway") {
241
245
  super(t);
242
246
  }
@@ -244,8 +248,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
244
248
  return t.constructor.code == this.code;
245
249
  }
246
250
  }
247
- i(X, "code", 502);
248
- class Q extends p {
251
+ i(Q, "code", 502);
252
+ class _ extends p {
249
253
  constructor(t = "Service Unavailable") {
250
254
  super(t);
251
255
  }
@@ -253,8 +257,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
253
257
  return t.constructor.code == this.code;
254
258
  }
255
259
  }
256
- i(Q, "code", 503);
257
- class _ extends p {
260
+ i(_, "code", 503);
261
+ class tt extends p {
258
262
  constructor(t = "Gateway Timeout") {
259
263
  super(t);
260
264
  }
@@ -262,7 +266,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
262
266
  return t.constructor.code == this.code;
263
267
  }
264
268
  }
265
- i(_, "code", 504);
269
+ i(tt, "code", 504);
266
270
  const w = class w2 {
267
271
  constructor(t = {}) {
268
272
  i(this, "interceptors", {});
@@ -291,7 +295,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
291
295
  const s = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((c) => ({ key: c, value: t.query[c] }));
292
296
  e += (e.includes("?") ? "&" : "?") + s.map((c) => `${c.key}=${c.value}`).join("&");
293
297
  }
294
- const r = rt({
298
+ const r = ot({
295
299
  "Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
296
300
  ...w2.headers,
297
301
  ...this.headers,
@@ -302,36 +306,36 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
302
306
  headers: r,
303
307
  method: t.method || (t.body ? "POST" : "GET"),
304
308
  body: t.body
305
- }).then(async (a) => {
306
- var M, j;
307
- for (let u of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
308
- await new Promise((O) => u(a, () => O()));
309
- const R = a.headers.get("Content-Length"), N = R ? parseInt(R, 10) : 0;
310
- let k = 0;
311
- const T = (M = a.body) == null ? void 0 : M.getReader(), tt = new ReadableStream({
312
- start(u) {
309
+ }).then(async (u) => {
310
+ var j, k;
311
+ for (let a of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
312
+ await new Promise((O) => a(u, () => O()));
313
+ const R = u.headers.get("Content-Length"), C = R ? parseInt(R, 10) : 0;
314
+ let D = 0;
315
+ const N = (j = u.body) == null ? void 0 : j.getReader(), et = new ReadableStream({
316
+ start(a) {
313
317
  function O() {
314
- T == null || T.read().then((x) => {
315
- if (x.done)
316
- return u.close();
317
- k += x.value.byteLength, y(k / N), u.enqueue(x.value), O();
318
- }).catch((x) => u.error(x));
318
+ N == null || N.read().then((B) => {
319
+ if (B.done)
320
+ return a.close();
321
+ D += B.value.byteLength, y(D / C), a.enqueue(B.value), O();
322
+ }).catch((B) => a.error(B));
319
323
  }
320
324
  O();
321
325
  }
322
326
  });
323
- if (a.data = new Response(tt), t.decode == null || t.decode) {
324
- const u = (j = a.headers.get("Content-Type")) == null ? void 0 : j.toLowerCase();
325
- u != null && u.includes("form") ? a.data = await a.data.formData() : u != null && u.includes("json") ? a.data = await a.data.json() : u != null && u.includes("text") ? a.data = await a.data.text() : u != null && u.includes("application") && (a.data = await a.data.blob());
327
+ if (u.data = new Response(et), t.decode == null || t.decode) {
328
+ const a = (k = u.headers.get("Content-Type")) == null ? void 0 : k.toLowerCase();
329
+ a != null && a.includes("form") ? u.data = await u.data.formData() : a != null && a.includes("json") ? u.data = await u.data.json() : a != null && a.includes("text") ? u.data = await u.data.text() : a != null && a.includes("application") && (u.data = await u.data.blob());
326
330
  }
327
- a.ok ? s(a) : c(a);
331
+ u.ok ? s(u) : c(u);
328
332
  });
329
333
  });
330
334
  }
331
335
  };
332
336
  i(w, "interceptors", {}), i(w, "headers", {});
333
337
  let q = w;
334
- const B = {
338
+ const S = {
335
339
  CLEAR: "\x1B[0m",
336
340
  BRIGHT: "\x1B[1m",
337
341
  DIM: "\x1B[2m",
@@ -339,7 +343,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
339
343
  BLINK: "\x1B[5m",
340
344
  REVERSE: "\x1B[7m",
341
345
  HIDDEN: "\x1B[8m"
342
- }, L = {
346
+ }, $ = {
343
347
  BLACK: "\x1B[30m",
344
348
  RED: "\x1B[31m",
345
349
  GREEN: "\x1B[32m",
@@ -357,8 +361,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
357
361
  LIGHT_CYAN: "\x1B[96m",
358
362
  WHITE: "\x1B[97m"
359
363
  };
360
- var ut = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(ut || {});
361
- const g = class g2 extends F {
364
+ var lt = /* @__PURE__ */ ((n) => (n[n.ERROR = 0] = "ERROR", n[n.WARN = 1] = "WARN", n[n.INFO = 2] = "INFO", n[n.LOG = 3] = "LOG", n[n.DEBUG = 4] = "DEBUG", n))(lt || {});
365
+ const g = class g2 extends v {
362
366
  constructor(t) {
363
367
  super(), this.namespace = t;
364
368
  }
@@ -377,31 +381,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
377
381
  if (g2.LOG_LEVEL < 4)
378
382
  return;
379
383
  const e = this.format(...t);
380
- g2.emit(4, e), console.debug(L.LIGHT_GREY + e + B.CLEAR);
384
+ g2.emit(4, e), console.debug($.LIGHT_GREY + e + S.CLEAR);
381
385
  }
382
386
  log(...t) {
383
387
  if (g2.LOG_LEVEL < 3)
384
388
  return;
385
389
  const e = this.format(...t);
386
- g2.emit(3, e), console.log(B.CLEAR + e);
390
+ g2.emit(3, e), console.log(S.CLEAR + e);
387
391
  }
388
392
  info(...t) {
389
393
  if (g2.LOG_LEVEL < 2)
390
394
  return;
391
395
  const e = this.format(...t);
392
- g2.emit(2, e), console.info(L.BLUE + e + B.CLEAR);
396
+ g2.emit(2, e), console.info($.BLUE + e + S.CLEAR);
393
397
  }
394
398
  warn(...t) {
395
399
  if (g2.LOG_LEVEL < 1)
396
400
  return;
397
401
  const e = this.format(...t);
398
- g2.emit(1, e), console.warn(L.YELLOW + e + B.CLEAR);
402
+ g2.emit(1, e), console.warn($.YELLOW + e + S.CLEAR);
399
403
  }
400
404
  error(...t) {
401
405
  if (g2.LOG_LEVEL < 0)
402
406
  return;
403
407
  const e = this.format(...t);
404
- g2.emit(0, e), console.error(L.RED + e + B.CLEAR);
408
+ g2.emit(0, e), console.error($.RED + e + S.CLEAR);
405
409
  }
406
410
  };
407
411
  i(g, "LOG_LEVEL", 4);
@@ -409,7 +413,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
409
413
  constructor(url = location.origin, opts = {}) {
410
414
  opts.url = url;
411
415
  super(opts);
412
- __publicField(this, "emitter", new F());
416
+ __publicField(this, "emitter", new v());
413
417
  __publicField(this, "_token", null);
414
418
  __publicField(this, "emit", this.emitter.emit.bind(this.emitter));
415
419
  __publicField(this, "off", this.emitter.off.bind(this.emitter));
@@ -1162,7 +1166,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1162
1166
  ActionType2[ActionType2["PUT"] = 6] = "PUT";
1163
1167
  return ActionType2;
1164
1168
  })(ActionType || {});
1165
- class Actions extends F {
1169
+ class Actions extends v {
1166
1170
  constructor(api) {
1167
1171
  super();
1168
1172
  __publicField(this, "api");
@@ -1222,7 +1226,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1222
1226
  });
1223
1227
  }
1224
1228
  }
1225
- class Ai extends F {
1229
+ class Ai extends v {
1226
1230
  constructor(api) {
1227
1231
  super();
1228
1232
  __publicField(this, "api");
@@ -1241,7 +1245,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1241
1245
  return this.api.request({ url: "/api/ai", method: "DELETE" });
1242
1246
  }
1243
1247
  }
1244
- class Analytics extends F {
1248
+ class Analytics extends v {
1245
1249
  constructor(api) {
1246
1250
  super();
1247
1251
  __publicField(this, "api");
@@ -1266,13 +1270,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1266
1270
  return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
1267
1271
  }
1268
1272
  setup(username, method = "app", totp) {
1269
- return this.api.request({ url: `/api/auth/totp/${username}`, body: rt({
1273
+ return this.api.request({ url: `/api/auth/totp/${username}`, body: ot({
1270
1274
  method,
1271
1275
  totp
1272
1276
  }) });
1273
1277
  }
1274
1278
  }
1275
- class Auth extends F {
1279
+ class Auth extends v {
1276
1280
  constructor(api, opts = {}) {
1277
1281
  super();
1278
1282
  __publicField(this, "api");
@@ -1412,7 +1416,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1412
1416
  });
1413
1417
  }
1414
1418
  }
1415
- class Data extends F {
1419
+ class Data extends v {
1416
1420
  constructor(api) {
1417
1421
  super();
1418
1422
  __publicField(this, "api");
@@ -1421,21 +1425,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1421
1425
  create(collection, document2) {
1422
1426
  return this.api.request({
1423
1427
  url: `/api/data/${collection}`,
1424
- method: "POST"
1428
+ method: "POST",
1429
+ body: document2
1425
1430
  }).then((resp) => {
1426
1431
  this.emit("create", collection, resp);
1427
1432
  return resp;
1428
1433
  });
1429
1434
  }
1430
- read(collection, document2) {
1431
- return this.api.request({ url: `/api/data/${collection}${document2 ? `/${document2}` : ""}` }).then((resp) => {
1435
+ read(collection, id) {
1436
+ return this.api.request({ url: `/api/data/${collection}${id ? `/${id}` : ""}` }).then((resp) => {
1432
1437
  this.emit("read", collection, resp);
1433
1438
  return resp;
1434
1439
  });
1435
1440
  }
1436
1441
  update(collection, document2, append = true) {
1442
+ if (!document2._id) return this.create(collection, document2);
1437
1443
  return this.api.request({
1438
- url: `/api/data/${collection}`,
1444
+ url: `/api/data/${collection}/${document2._id}`,
1439
1445
  method: append ? "PATCH" : "PUT",
1440
1446
  body: document2
1441
1447
  }).then((resp) => {
@@ -1443,11 +1449,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1443
1449
  return resp;
1444
1450
  });
1445
1451
  }
1446
- delete(collection, document2) {
1452
+ delete(collection, id) {
1447
1453
  return this.api.request({
1448
- url: `/api/data/${collection}/${document2}`,
1454
+ url: `/api/data/${collection}/${id}`,
1449
1455
  method: "DELETE"
1450
- }).then(() => this.emit("delete", collection, document2));
1456
+ }).then(() => this.emit("delete", collection, id));
1451
1457
  }
1452
1458
  raw(collection, query) {
1453
1459
  return this.api.request({ url: `/api/data/${collection}`, body: query }).then((resp) => {
@@ -1456,7 +1462,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1456
1462
  });
1457
1463
  }
1458
1464
  }
1459
- class Email extends F {
1465
+ class Email extends v {
1460
1466
  constructor(api) {
1461
1467
  super();
1462
1468
  __publicField(this, "api");
@@ -1471,7 +1477,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1471
1477
  });
1472
1478
  }
1473
1479
  }
1474
- class Groups extends F {
1480
+ class Groups extends v {
1475
1481
  constructor(api) {
1476
1482
  super();
1477
1483
  __publicField(this, "api");
@@ -1564,32 +1570,32 @@ ${log}`;
1564
1570
  return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ""}` }).then((resp) => resp);
1565
1571
  }
1566
1572
  debug(...logs) {
1567
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(ut.DEBUG, logs) }).then(() => {
1573
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.DEBUG, logs) }).then(() => {
1568
1574
  }).catch(() => {
1569
1575
  });
1570
1576
  }
1571
1577
  log(...logs) {
1572
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(ut.LOG, logs) }).then(() => {
1578
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.LOG, logs) }).then(() => {
1573
1579
  }).catch(() => {
1574
1580
  });
1575
1581
  }
1576
1582
  info(...logs) {
1577
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(ut.INFO, logs) }).then(() => {
1583
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.INFO, logs) }).then(() => {
1578
1584
  }).catch(() => {
1579
1585
  });
1580
1586
  }
1581
1587
  warn(...logs) {
1582
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(ut.WARN, logs) }).then(() => {
1588
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.WARN, logs) }).then(() => {
1583
1589
  }).catch(() => {
1584
1590
  });
1585
1591
  }
1586
1592
  error(...logs) {
1587
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(ut.ERROR, logs) }).then(() => {
1593
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.ERROR, logs) }).then(() => {
1588
1594
  }).catch(() => {
1589
1595
  });
1590
1596
  }
1591
1597
  }
1592
- class Payments extends F {
1598
+ class Payments extends v {
1593
1599
  constructor(api, secret) {
1594
1600
  super();
1595
1601
  __publicField(this, "api");
@@ -1630,7 +1636,7 @@ ${log}`;
1630
1636
  return history;
1631
1637
  }
1632
1638
  }
1633
- class Pdf extends F {
1639
+ class Pdf extends v {
1634
1640
  constructor(api) {
1635
1641
  super();
1636
1642
  __publicField(this, "api");
@@ -1703,7 +1709,7 @@ ${log}`;
1703
1709
  };
1704
1710
  __publicField(_Socket, "timeout", 1e4);
1705
1711
  let Socket = _Socket;
1706
- class Storage extends F {
1712
+ class Storage extends v {
1707
1713
  constructor(api) {
1708
1714
  super();
1709
1715
  __publicField(this, "api");
@@ -1766,9 +1772,9 @@ ${log}`;
1766
1772
  if (!files) files = await It(typeof opts == "object" ? opts : void 0);
1767
1773
  if (!files || Array.isArray(files) && !files.length) return [];
1768
1774
  const path = this.api.path("/api/storage/", typeof opts == "string" ? opts : opts.path || "");
1769
- return $t({
1775
+ return Dt({
1770
1776
  url: `${this.api.url}${path}`,
1771
- files: Array.isArray(files) ? files : [files],
1777
+ files: ut(files),
1772
1778
  headers: this.api.headers
1773
1779
  }).onProgress((p2) => {
1774
1780
  prog(p2);
@@ -1784,7 +1790,7 @@ ${log}`;
1784
1790
  this.settings = settings;
1785
1791
  }
1786
1792
  async inject(reload = false) {
1787
- if (!Object.keys(this.settings.cache).length || reload) await this.settings.list();
1793
+ if (!Object.keys(this.settings.cache).length || reload) await this.settings.all();
1788
1794
  if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
1789
1795
  const meta = document.createElement("meta");
1790
1796
  meta.name = "mobile-web-app-capable";
@@ -1983,7 +1989,7 @@ ${log}`;
1983
1989
  }, 1e3);
1984
1990
  }
1985
1991
  }
1986
- class Users extends F {
1992
+ class Users extends v {
1987
1993
  constructor(api) {
1988
1994
  super();
1989
1995
  __publicField(this, "api");
@@ -2006,7 +2012,7 @@ ${log}`;
2006
2012
  this.emit("delete", username);
2007
2013
  });
2008
2014
  }
2009
- list(reload = false) {
2015
+ all(reload = false) {
2010
2016
  if (!reload && this.listed) return Promise.resolve(this.cache);
2011
2017
  return this.api.request({ url: `/api/users` }).then((resp) => {
2012
2018
  resp == null ? void 0 : resp.map((r) => {
@@ -2043,12 +2049,12 @@ ${log}`;
2043
2049
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2044
2050
  this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
2045
2051
  }
2046
- this.emit(user._id ? "update" : "create", resp);
2052
+ this.emit(resp._id ? "update" : "create", resp);
2047
2053
  return resp;
2048
2054
  });
2049
2055
  }
2050
2056
  uploadImage(username, file) {
2051
- return $t({
2057
+ return Dt({
2052
2058
  url: this.api.url + `/api/users/${username}/image`,
2053
2059
  files: [file],
2054
2060
  headers: this.api.headers
@@ -2058,7 +2064,7 @@ ${log}`;
2058
2064
  });
2059
2065
  }
2060
2066
  }
2061
- class Settings extends F {
2067
+ class Settings extends v {
2062
2068
  constructor(api) {
2063
2069
  super();
2064
2070
  __publicField(this, "api");
@@ -2071,7 +2077,7 @@ ${log}`;
2071
2077
  set cache(val) {
2072
2078
  this.$cache.next(val);
2073
2079
  }
2074
- list(detailed = false) {
2080
+ all(detailed = false) {
2075
2081
  return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
2076
2082
  this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
2077
2083
  this.emit("list", resp || []);
@@ -2100,7 +2106,7 @@ ${log}`;
2100
2106
  });
2101
2107
  }
2102
2108
  }
2103
- class Static extends F {
2109
+ class Static extends v {
2104
2110
  constructor(api) {
2105
2111
  super();
2106
2112
  __publicField(this, "api");
@@ -2113,9 +2119,9 @@ ${log}`;
2113
2119
  }
2114
2120
  upload(files, path = "/") {
2115
2121
  return new m(async (res, rej, prog) => {
2116
- return $t({
2122
+ return Dt({
2117
2123
  url: this.api.url + ("/api/static/" + path).replaceAll("//", "/"),
2118
- files: Array.isArray(files) ? files : [files],
2124
+ files: ut(files),
2119
2125
  headers: this.api.headers
2120
2126
  }).onProgress((p2) => {
2121
2127
  prog(p2);
@@ -2126,7 +2132,7 @@ ${log}`;
2126
2132
  });
2127
2133
  }
2128
2134
  }
2129
- class Momentum extends F {
2135
+ class Momentum extends v {
2130
2136
  constructor(url, opts) {
2131
2137
  super();
2132
2138
  __publicField(this, "api");
@@ -2179,16 +2185,11 @@ ${log}`;
2179
2185
  this.storage.on("*", (event, ...args) => this.emit(`Storage:${event}`, ...args));
2180
2186
  this.users.on("*", (event, ...args) => this.emit(`Users:${event}`, ...args));
2181
2187
  this.users.on("*", (event, ...args) => {
2182
- var _a;
2183
- if (Array.isArray(args[0])) {
2184
- const u = args[0].find((u2) => {
2185
- var _a2;
2186
- return u2._id == ((_a2 = this.auth.user) == null ? void 0 : _a2._id);
2187
- });
2188
- if (u) this.auth.user = u;
2189
- } else if (args[0]._id == ((_a = this.auth.user) == null ? void 0 : _a._id)) {
2190
- this.auth.user = args[0];
2191
- }
2188
+ const u = ut(args[0]).find((u2) => {
2189
+ var _a;
2190
+ return (u2 == null ? void 0 : u2._id) == ((_a = this.auth.user) == null ? void 0 : _a._id);
2191
+ });
2192
+ if (u) this.auth.user = u;
2192
2193
  });
2193
2194
  }
2194
2195
  }