@ztimson/momentum 0.15.1 → 0.15.2

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/momentum.mjs CHANGED
@@ -1,6 +1,6 @@
1
- var pt = Object.defineProperty;
2
- var dt = (i, e, t) => e in i ? pt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var a = (i, e, t) => (dt(i, typeof e != "symbol" ? e + "" : e, t), t);
1
+ var dt = Object.defineProperty;
2
+ var pt = (i, e, t) => e in i ? dt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var a = (i, e, t) => (pt(i, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  var ft = Object.defineProperty, mt = (i, e, t) => e in i ? ft(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (mt(i, typeof e != "symbol" ? e + "" : e, t), t);
5
5
  function Et(i, e = !1) {
6
6
  if (i == null)
@@ -17,7 +17,7 @@ function yt(i, e) {
17
17
  const t = document.createElement("a");
18
18
  t.href = i, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
19
19
  }
20
- class p {
20
+ class d {
21
21
  constructor() {
22
22
  h(this, "listeners", {});
23
23
  }
@@ -58,8 +58,8 @@ class p {
58
58
  });
59
59
  }
60
60
  }
61
- h(p, "listeners", {});
62
- const C = class b {
61
+ h(d, "listeners", {});
62
+ const B = class b {
63
63
  constructor(e = {}) {
64
64
  h(this, "interceptors", {}), h(this, "headers", {}), this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => b.addInterceptor(t));
65
65
  }
@@ -99,8 +99,8 @@ const C = class b {
99
99
  });
100
100
  }
101
101
  };
102
- h(C, "interceptors", {}), h(C, "headers", {});
103
- let Z = C;
102
+ h(B, "interceptors", {}), h(B, "headers", {});
103
+ let Z = B;
104
104
  Z.addInterceptor((i, e) => {
105
105
  if (i.status == 200)
106
106
  return e();
@@ -204,7 +204,7 @@ const O = {
204
204
  WHITE: "\x1B[97m"
205
205
  };
206
206
  var L = /* @__PURE__ */ ((i) => (i[i.ERROR = 0] = "ERROR", i[i.WARN = 1] = "WARN", i[i.INFO = 2] = "INFO", i[i.LOG = 3] = "LOG", i[i.DEBUG = 4] = "DEBUG", i))(L || {});
207
- const gt = class m extends p {
207
+ const gt = class m extends d {
208
208
  constructor(e) {
209
209
  super(), this.namespace = e;
210
210
  }
@@ -269,11 +269,11 @@ class bt extends Promise {
269
269
  return this.listeners.push(e), this;
270
270
  }
271
271
  }
272
- class d extends Z {
272
+ class p extends Z {
273
273
  constructor(t = location.origin, r = {}) {
274
274
  r.url = t;
275
275
  super(r);
276
- a(this, "emitter", new p());
276
+ a(this, "emitter", new d());
277
277
  a(this, "_token", null);
278
278
  a(this, "emit", this.emitter.emit.bind(this.emitter));
279
279
  a(this, "off", this.emitter.off.bind(this.emitter));
@@ -530,7 +530,7 @@ var ht = function(i) {
530
530
  }
531
531
  }, e;
532
532
  }(P), wt = Function.prototype.bind;
533
- function B(i, e) {
533
+ function C(i, e) {
534
534
  return wt.call(i, e);
535
535
  }
536
536
  var St = function() {
@@ -579,9 +579,9 @@ var St = function() {
579
579
  n && at.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
580
580
  return n.unsubscribe();
581
581
  }, o = {
582
- next: t.next && B(t.next, u),
583
- error: t.error && B(t.error, u),
584
- complete: t.complete && B(t.complete, u)
582
+ next: t.next && C(t.next, u),
583
+ error: t.error && C(t.error, u),
584
+ complete: t.complete && C(t.complete, u)
585
585
  }) : o = t;
586
586
  }
587
587
  return n.destination = new St(o), n;
@@ -809,12 +809,12 @@ var Rt = nt(function(i) {
809
809
  i.prototype.next.call(this, this._value = t);
810
810
  }, e;
811
811
  }(lt), Dt = /* @__PURE__ */ ((i) => (i[i.DISABLED = 0] = "DISABLED", i[i.CRON = 1] = "CRON", i[i.EVENT = 2] = "EVENT", i[i.GET = 3] = "GET", i[i.POST = 4] = "POST", i[i.PATCH = 5] = "PATCH", i[i.PUT = 6] = "PUT", i[i.DELETE = 7] = "DELETE", i))(Dt || {});
812
- class Pt extends p {
812
+ class Pt extends d {
813
813
  constructor(t) {
814
814
  super();
815
815
  a(this, "api");
816
816
  a(this, "$cache", new I([]));
817
- this.api = typeof t == "string" ? new d(t) : t;
817
+ this.api = typeof t == "string" ? new p(t) : t;
818
818
  }
819
819
  get cache() {
820
820
  return this.$cache.value;
@@ -849,14 +849,14 @@ class Pt extends p {
849
849
  }).then((r) => (r && (this.cache = this.cache.filter((s) => s._id != r._id).concat([r])), this.emit("UPDATE", r), r));
850
850
  }
851
851
  }
852
- class It extends p {
852
+ class It extends d {
853
853
  constructor(t, r) {
854
854
  var s;
855
855
  super();
856
856
  a(this, "api");
857
857
  a(this, "storageKey");
858
858
  a(this, "$user", new I(void 0));
859
- if (this.opts = r, this.api = typeof t == "string" ? new d(t) : t, (s = this.opts) != null && s.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (n) => {
859
+ if (this.opts = r, this.api = typeof t == "string" ? new p(t) : t, (s = this.opts) != null && s.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (n) => {
860
860
  var o;
861
861
  (o = this.opts) != null && o.persist && (n ? localStorage.setItem(this.storageKey, n) : localStorage.removeItem(this.storageKey)), n ? this.whoAmI(n, !0) : this.user = null;
862
862
  }), r != null && r.persist) {
@@ -927,11 +927,11 @@ class It extends p {
927
927
  return r && (this.api.token = t, this.user = (s == null ? void 0 : s.user) || null, s && this.emit("LOGIN", s.user)), s;
928
928
  }
929
929
  }
930
- class qt extends p {
930
+ class qt extends d {
931
931
  constructor(t) {
932
932
  super();
933
933
  a(this, "api");
934
- this.api = typeof t == "string" ? new d(t) : t;
934
+ this.api = typeof t == "string" ? new p(t) : t;
935
935
  }
936
936
  delete(t, r) {
937
937
  return this.api.request({
@@ -960,22 +960,22 @@ class qt extends p {
960
960
  }).then((n) => (this.emit("SET", t, r), n));
961
961
  }
962
962
  }
963
- class Ut extends p {
963
+ class Ut extends d {
964
964
  constructor(t) {
965
965
  super();
966
966
  a(this, "api");
967
- this.api = typeof t == "string" ? new d(t) : t;
967
+ this.api = typeof t == "string" ? new p(t) : t;
968
968
  }
969
969
  send(t) {
970
- let r = "/api/email/send";
970
+ let r = "/api/email";
971
971
  return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((s) => (this.emit("SENT", t), s));
972
972
  }
973
973
  }
974
- class Bt extends p {
974
+ class Ct extends d {
975
975
  constructor(t) {
976
976
  super();
977
977
  a(this, "api");
978
- this.api = typeof t == "string" ? new d(t) : t;
978
+ this.api = typeof t == "string" ? new p(t) : t;
979
979
  }
980
980
  create(t) {
981
981
  return this.api.request({
@@ -1004,10 +1004,10 @@ class Bt extends p {
1004
1004
  }).then(() => this.emit("DELETE", t));
1005
1005
  }
1006
1006
  }
1007
- class Ct {
1007
+ class Bt {
1008
1008
  constructor(e, t) {
1009
1009
  a(this, "api");
1010
- this.api = typeof e == "string" ? new d(e) : e, t != null && t != "NONE" && (window.addEventListener("error", (r) => this.error(r.error.stack)), window.addEventListener("unhandledrejection", async (r) => this.error(r.reason.stack)));
1010
+ this.api = typeof e == "string" ? new p(e) : e, t != null && t != "NONE" && (window.addEventListener("error", (r) => this.error(r.error.stack)), window.addEventListener("unhandledrejection", async (r) => this.error(r.reason.stack)));
1011
1011
  }
1012
1012
  buildLog(e, t) {
1013
1013
  return {
@@ -1015,8 +1015,10 @@ class Ct {
1015
1015
  level: e,
1016
1016
  log: t,
1017
1017
  ctx: {
1018
- url: location.href,
1019
- res: [window.innerWidth, window.innerHeight]
1018
+ cores: navigator.hardwareConcurrency,
1019
+ mem: navigator == null ? void 0 : navigator.deviceMemory,
1020
+ res: [window.innerWidth, window.innerHeight],
1021
+ url: location.href
1020
1022
  }
1021
1023
  };
1022
1024
  }
@@ -1061,7 +1063,7 @@ const D = class D {
1061
1063
  a(this, "url");
1062
1064
  a(this, "connection");
1063
1065
  a(this, "open", !1);
1064
- this.api = typeof e == "string" ? new d(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1066
+ this.api = typeof e == "string" ? new p(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1065
1067
  }
1066
1068
  close() {
1067
1069
  console.debug("Disconnected from Momentum"), this.open = !1, this.connection.close();
@@ -1089,11 +1091,11 @@ const D = class D {
1089
1091
  };
1090
1092
  a(D, "timeout", 1e4);
1091
1093
  let M = D;
1092
- class jt extends p {
1094
+ class jt extends d {
1093
1095
  constructor(t) {
1094
1096
  super();
1095
1097
  a(this, "api");
1096
- this.api = typeof t == "string" ? new d(t) : t;
1098
+ this.api = typeof t == "string" ? new p(t) : t;
1097
1099
  }
1098
1100
  delete(t) {
1099
1101
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
@@ -1148,13 +1150,13 @@ class jt extends p {
1148
1150
  return (Array.isArray(t) ? t : [t]).forEach((u) => n.append("file", u)), this.api.request({ url: o, body: n }).then((u) => (this.emit("UPLOAD", u), u));
1149
1151
  }
1150
1152
  }
1151
- class kt extends p {
1153
+ class kt extends d {
1152
1154
  constructor(t) {
1153
1155
  super();
1154
1156
  a(this, "api");
1155
1157
  a(this, "listed", !1);
1156
1158
  a(this, "$cache", new I([]));
1157
- this.api = typeof t == "string" ? new d(t) : t;
1159
+ this.api = typeof t == "string" ? new p(t) : t;
1158
1160
  }
1159
1161
  get cache() {
1160
1162
  return this.$cache.value;
@@ -1189,12 +1191,12 @@ class kt extends p {
1189
1191
  }).then((r) => (r && (this.cache = this.cache.filter((s) => s.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1190
1192
  }
1191
1193
  }
1192
- class Gt extends p {
1194
+ class Gt extends d {
1193
1195
  constructor(t) {
1194
1196
  super();
1195
1197
  a(this, "api");
1196
1198
  a(this, "$cache", new I({}));
1197
- this.api = typeof t == "string" ? new d(t) : t;
1199
+ this.api = typeof t == "string" ? new p(t) : t;
1198
1200
  }
1199
1201
  get cache() {
1200
1202
  return this.$cache.value;
@@ -1217,11 +1219,11 @@ class Gt extends p {
1217
1219
  return this.api.request({ url: `/api/settings/${t.key}`, body: t }).then((r) => (r && (this.cache = { ...this.cache, [r.key]: r.value }), this.emit("UPDATE", r), r));
1218
1220
  }
1219
1221
  }
1220
- class Nt extends p {
1222
+ class Nt extends d {
1221
1223
  constructor(t) {
1222
1224
  super();
1223
1225
  a(this, "api");
1224
- this.api = typeof t == "string" ? new d(t) : t;
1226
+ this.api = typeof t == "string" ? new p(t) : t;
1225
1227
  }
1226
1228
  delete(t) {
1227
1229
  return this.api.request({ url: `/api/static/${t}`, method: "DELETE" }).then(() => {
@@ -1237,7 +1239,7 @@ class Nt extends p {
1237
1239
  return (Array.isArray(t) ? t : [t]).forEach((n) => s.append("file", n)), this.api.request({ url: "/api/static" + r, body: s }).then((n) => (this.emit("UPLOAD", n), n));
1238
1240
  }
1239
1241
  }
1240
- class Wt extends p {
1242
+ class Wt extends d {
1241
1243
  constructor(t, r) {
1242
1244
  super();
1243
1245
  a(this, "api");
@@ -1252,10 +1254,10 @@ class Wt extends p {
1252
1254
  a(this, "static");
1253
1255
  a(this, "storage");
1254
1256
  a(this, "users");
1255
- this.api = new d(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1257
+ this.api = new p(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1256
1258
  persist: (r == null ? void 0 : r.persist) ?? !0,
1257
1259
  loginUi: r == null ? void 0 : r.loginUi
1258
- }), this.data = new qt(this.api), this.email = new Ut(this.api), this.groups = new Bt(this.api), this.logger = new Ct(this.api, r == null ? void 0 : r.logLevel), this.settings = new Gt(this.api), this.static = new Nt(this.api), this.storage = new jt(this.api), this.users = new kt(this.api), r != null && r.socket && (this.socket = new M(this.api)), this.api.on("*", (s, ...n) => this.emit(`API::${s}`, ...n)), this.actions.on("*", (s, ...n) => this.emit(`ACTIONS::${s}`, ...n)), this.auth.on("*", (s, ...n) => this.emit(`AUTH::${s}`, ...n)), this.data.on("*", (s, ...n) => this.emit(`DATA::${s}`, ...n)), this.email.on("*", (s, ...n) => this.emit(`EMAIL::${s}`, ...n)), this.groups.on("*", (s, ...n) => this.emit(`GROUPS::${s}`, ...n)), this.settings.on("*", (s, ...n) => this.emit(`SETTINGS::${s}`, ...n)), this.static.on("*", (s, ...n) => this.emit(`STATIC::${s}`, ...n)), this.storage.on("*", (s, ...n) => this.emit(`STORAGE::${s}`, ...n)), this.users.on("*", (s, ...n) => this.emit(`USERS::${s}`, ...n)), this.users.on("*", (s, ...n) => {
1260
+ }), this.data = new qt(this.api), this.email = new Ut(this.api), this.groups = new Ct(this.api), this.logger = new Bt(this.api, r == null ? void 0 : r.logLevel), this.settings = new Gt(this.api), this.static = new Nt(this.api), this.storage = new jt(this.api), this.users = new kt(this.api), r != null && r.socket && (this.socket = new M(this.api)), this.api.on("*", (s, ...n) => this.emit(`API::${s}`, ...n)), this.actions.on("*", (s, ...n) => this.emit(`ACTIONS::${s}`, ...n)), this.auth.on("*", (s, ...n) => this.emit(`AUTH::${s}`, ...n)), this.data.on("*", (s, ...n) => this.emit(`DATA::${s}`, ...n)), this.email.on("*", (s, ...n) => this.emit(`EMAIL::${s}`, ...n)), this.groups.on("*", (s, ...n) => this.emit(`GROUPS::${s}`, ...n)), this.settings.on("*", (s, ...n) => this.emit(`SETTINGS::${s}`, ...n)), this.static.on("*", (s, ...n) => this.emit(`STATIC::${s}`, ...n)), this.storage.on("*", (s, ...n) => this.emit(`STORAGE::${s}`, ...n)), this.users.on("*", (s, ...n) => this.emit(`USERS::${s}`, ...n)), this.users.on("*", (s, ...n) => {
1259
1261
  var o;
1260
1262
  if (Array.isArray(n[0])) {
1261
1263
  const u = n[0].find((c) => {
@@ -1271,12 +1273,12 @@ class Wt extends p {
1271
1273
  export {
1272
1274
  Dt as ActionType,
1273
1275
  Pt as Actions,
1274
- d as Api,
1276
+ p as Api,
1275
1277
  It as Auth,
1276
1278
  qt as Data,
1277
1279
  Ut as Email,
1278
- Bt as Groups,
1279
- Ct as Logger,
1280
+ Ct as Groups,
1281
+ Bt as Logger,
1280
1282
  Wt as Momentum,
1281
1283
  Gt as Settings,
1282
1284
  M as Socket,