@ztimson/momentum 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,7 +58,7 @@ class p {
58
58
  });
59
59
  }
60
60
  }
61
- h(p, "listeners", {});
61
+ h(d, "listeners", {});
62
62
  const C = 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));
@@ -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));
@@ -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
970
  let r = "/api/email/send";
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 Bt 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({
@@ -1007,7 +1007,7 @@ class Bt extends p {
1007
1007
  class Ct {
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 {
@@ -1061,7 +1061,7 @@ const D = class D {
1061
1061
  a(this, "url");
1062
1062
  a(this, "connection");
1063
1063
  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();
1064
+ 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
1065
  }
1066
1066
  close() {
1067
1067
  console.debug("Disconnected from Momentum"), this.open = !1, this.connection.close();
@@ -1089,11 +1089,11 @@ const D = class D {
1089
1089
  };
1090
1090
  a(D, "timeout", 1e4);
1091
1091
  let M = D;
1092
- class jt extends p {
1092
+ class jt extends d {
1093
1093
  constructor(t) {
1094
1094
  super();
1095
1095
  a(this, "api");
1096
- this.api = typeof t == "string" ? new d(t) : t;
1096
+ this.api = typeof t == "string" ? new p(t) : t;
1097
1097
  }
1098
1098
  delete(t) {
1099
1099
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
@@ -1126,7 +1126,7 @@ class jt extends p {
1126
1126
  if (F.done) {
1127
1127
  o(1);
1128
1128
  const S = new Blob(T), q = r.downloadName || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(S);
1129
- yt(Y, q.includes(".") ? q : q + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, S), s(S);
1129
+ yt(Y, r.downloadAs || q.includes(".") ? q : q + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, S), s(S);
1130
1130
  } else {
1131
1131
  const S = F.value;
1132
1132
  T.push(S), g += S.length, o(g / w), E.read().then(_);
@@ -1148,13 +1148,13 @@ class jt extends p {
1148
1148
  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
1149
  }
1150
1150
  }
1151
- class kt extends p {
1151
+ class kt extends d {
1152
1152
  constructor(t) {
1153
1153
  super();
1154
1154
  a(this, "api");
1155
1155
  a(this, "listed", !1);
1156
1156
  a(this, "$cache", new I([]));
1157
- this.api = typeof t == "string" ? new d(t) : t;
1157
+ this.api = typeof t == "string" ? new p(t) : t;
1158
1158
  }
1159
1159
  get cache() {
1160
1160
  return this.$cache.value;
@@ -1189,12 +1189,12 @@ class kt extends p {
1189
1189
  }).then((r) => (r && (this.cache = this.cache.filter((s) => s.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1190
1190
  }
1191
1191
  }
1192
- class Gt extends p {
1192
+ class Gt extends d {
1193
1193
  constructor(t) {
1194
1194
  super();
1195
1195
  a(this, "api");
1196
1196
  a(this, "$cache", new I({}));
1197
- this.api = typeof t == "string" ? new d(t) : t;
1197
+ this.api = typeof t == "string" ? new p(t) : t;
1198
1198
  }
1199
1199
  get cache() {
1200
1200
  return this.$cache.value;
@@ -1217,11 +1217,11 @@ class Gt extends p {
1217
1217
  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
1218
  }
1219
1219
  }
1220
- class Nt extends p {
1220
+ class Nt extends d {
1221
1221
  constructor(t) {
1222
1222
  super();
1223
1223
  a(this, "api");
1224
- this.api = typeof t == "string" ? new d(t) : t;
1224
+ this.api = typeof t == "string" ? new p(t) : t;
1225
1225
  }
1226
1226
  delete(t) {
1227
1227
  return this.api.request({ url: `/api/static/${t}`, method: "DELETE" }).then(() => {
@@ -1237,7 +1237,7 @@ class Nt extends p {
1237
1237
  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
1238
  }
1239
1239
  }
1240
- class Wt extends p {
1240
+ class Wt extends d {
1241
1241
  constructor(t, r) {
1242
1242
  super();
1243
1243
  a(this, "api");
@@ -1252,7 +1252,7 @@ class Wt extends p {
1252
1252
  a(this, "static");
1253
1253
  a(this, "storage");
1254
1254
  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, {
1255
+ this.api = new p(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1256
1256
  persist: (r == null ? void 0 : r.persist) ?? !0,
1257
1257
  loginUi: r == null ? void 0 : r.loginUi
1258
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) => {
@@ -1271,7 +1271,7 @@ class Wt extends p {
1271
1271
  export {
1272
1272
  Dt as ActionType,
1273
1273
  Pt as Actions,
1274
- d as Api,
1274
+ p as Api,
1275
1275
  It as Auth,
1276
1276
  qt as Data,
1277
1277
  Ut as Email,