@ztimson/momentum 0.44.0 → 0.45.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/index.mjs CHANGED
@@ -740,94 +740,165 @@ L.MemoryStorage = At;
740
740
  };
741
741
  Object.defineProperty(r, "__esModule", { value: true }), e(S, r), e(L, r);
742
742
  })(xt);
743
- function combinePathedEvents(...paths) {
744
- let hitNone = false;
745
- const combined = paths.map((p2) => typeof p2 == "string" ? parsePathedEvent(p2) : p2).toSorted((p1, p2) => {
746
- const l1 = p1.fullPath.length, l2 = p2.fullPath.length;
747
- return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
748
- }).reduce((acc, p2) => {
749
- if (p2.none) hitNone = true;
750
- if (!acc) return p2;
751
- if (hitNone) return acc;
752
- if (p2.all) acc.all = true;
753
- if (p2.all || p2.create) acc.create = true;
754
- if (p2.all || p2.read) acc.read = true;
755
- if (p2.all || p2.update) acc.update = true;
756
- if (p2.all || p2.delete) acc.delete = true;
757
- if (p2.all || p2.execute) acc.execute = true;
758
- acc.methods = [...acc.methods, ...p2.methods];
759
- return acc;
760
- }, null);
761
- if (combined.all) combined.methods = ["*"];
762
- if (combined.none) combined.methods = ["n"];
763
- combined.methods = new B(combined.methods);
764
- combined.full = pathedEvent(combined.fullPath, ...combined.methods);
765
- return combined;
766
- }
767
- function hasPath(target, ...anyPath) {
768
- const parsedRequired = anyPath.map(parsePathedEvent);
769
- const parsedTarget = ft(target).map(parsePathedEvent);
770
- return !!parsedRequired.find((r) => {
771
- if (r.all) return true;
772
- const filtered = parsedTarget.filter((p2) => r.fullPath.startsWith(p2.fullPath));
773
- if (!filtered.length) return false;
774
- const combined = combinePathedEvents(...filtered);
775
- return !combined.none && (combined.all || new B(combined.methods).intersection(new B(r.methods)).length);
776
- });
777
- }
778
- function hasPathFatal(target, ...paths) {
779
- if (!hasPath(target, ...paths)) throw new Error(`Missing permission: ${paths.join(", ")}`);
743
+ function PE(str, ...args) {
744
+ const combined = [];
745
+ for (let i = 0; i < str.length || i < args.length; i++) {
746
+ if (str[i]) combined.push(str[i]);
747
+ if (args[i]) combined.push(args[i]);
748
+ }
749
+ return new PathEvent(combined.join(""));
780
750
  }
781
- function pathedEvent(path, ...methods) {
782
- var _a;
783
- let p2 = ft(path).map((p22) => p22 == null ? void 0 : p22.toString()).filter((p22) => !!p22).map((p22) => p22 == null ? void 0 : p22.replaceAll(/(^\/|\/$)/g, "")).join("/");
784
- if (methods.length) p2 += `:${methods.join("")}`;
785
- return (_a = p2 == null ? void 0 : p2.replaceAll("//", "/")) == null ? void 0 : _a.trim();
751
+ function PES(str, ...args) {
752
+ let combined = [];
753
+ for (let i = 0; i < str.length || i < args.length; i++) {
754
+ if (str[i]) combined.push(str[i]);
755
+ if (args[i]) combined.push(args[i]);
756
+ }
757
+ const [paths, methods] = combined.join("").split(":");
758
+ return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
786
759
  }
787
- function parsePathedEvent(path) {
788
- var _a;
789
- if (typeof path == "object") return path;
790
- let [p2, scope, method] = path.split(":");
791
- if (!method) method = scope || "*";
792
- if (p2 == "*" || !p2 && method == "*") {
793
- p2 = "";
794
- method = "*";
795
- }
796
- let temp = p2.split("/").filter((p22) => !!p22);
797
- return {
798
- full: path,
799
- module: ((_a = temp.splice(0, 1)[0]) == null ? void 0 : _a.toLowerCase()) || "",
800
- fullPath: p2,
801
- path: temp.join("/"),
802
- methods: method.split(""),
803
- all: method == null ? void 0 : method.includes("*"),
804
- none: method == null ? void 0 : method.includes("n"),
805
- create: !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("c"))),
806
- read: !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("r"))),
807
- update: !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("u"))),
808
- delete: !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("d"))),
809
- execute: !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("x")))
810
- };
760
+ class PathEvent {
761
+ constructor(pathedEvent) {
762
+ /** First directory in path */
763
+ __publicField(this, "module");
764
+ /** Entire path, including the module & name */
765
+ __publicField(this, "fullPath");
766
+ /** Path including the name, excluding the module */
767
+ __publicField(this, "path");
768
+ /** Last sagment of path */
769
+ __publicField(this, "name");
770
+ /** List of methods */
771
+ __publicField(this, "methods");
772
+ /** All/Wildcard specified */
773
+ __publicField(this, "all");
774
+ /** None specified */
775
+ __publicField(this, "none");
776
+ /** Create method specified */
777
+ __publicField(this, "create");
778
+ /** Read method specified */
779
+ __publicField(this, "read");
780
+ /** Update method specified */
781
+ __publicField(this, "update");
782
+ /** Delete method specified */
783
+ __publicField(this, "delete");
784
+ var _a;
785
+ if (typeof pathedEvent == "object") return Object.assign(this, pathedEvent);
786
+ let [p2, scope, method] = pathedEvent.split(":");
787
+ if (!method) method = scope || "*";
788
+ if (p2 == "*" || !p2 && method == "*") {
789
+ p2 = "";
790
+ method = "*";
791
+ }
792
+ let temp = p2.split("/").filter((p22) => !!p22);
793
+ this.module = ((_a = temp.splice(0, 1)[0]) == null ? void 0 : _a.toLowerCase()) || "";
794
+ this.fullPath = p2;
795
+ this.path = temp.join("/");
796
+ this.name = temp.pop() || "";
797
+ this.methods = method.split("");
798
+ this.all = method == null ? void 0 : method.includes("*");
799
+ this.none = method == null ? void 0 : method.includes("n");
800
+ this.create = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("c")));
801
+ this.read = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("r")));
802
+ this.update = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("u")));
803
+ this.delete = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("d")));
804
+ }
805
+ /**
806
+ * Combine multiple pathed events into one parsed object. Longest path takes precedent, but all subsequent methods are
807
+ * combined until a "none" is reached
808
+ *
809
+ * @param {string | PathEvent} paths PathedEvents as strings or pre-parsed
810
+ * @return {PathEvent} Final combined permission
811
+ */
812
+ static combine(paths) {
813
+ let hitNone = false;
814
+ const combined = paths.map((p2) => new PathEvent(p2)).toSorted((p1, p2) => {
815
+ const l1 = p1.fullPath.length, l2 = p2.fullPath.length;
816
+ return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
817
+ }).reduce((acc, p2) => {
818
+ if (p2.none) hitNone = true;
819
+ if (!acc) return p2;
820
+ if (hitNone) return acc;
821
+ if (p2.all) acc.all = true;
822
+ if (p2.all || p2.create) acc.create = true;
823
+ if (p2.all || p2.read) acc.read = true;
824
+ if (p2.all || p2.update) acc.update = true;
825
+ if (p2.all || p2.delete) acc.delete = true;
826
+ acc.methods = [...acc.methods, ...p2.methods];
827
+ return acc;
828
+ }, null);
829
+ if (combined.all) combined.methods = ["*"];
830
+ if (combined.none) combined.methods = ["n"];
831
+ combined.methods = new B(combined.methods);
832
+ combined.raw = PES`${combined.fullPath}:${combined.methods}`;
833
+ return combined;
834
+ }
835
+ /**
836
+ * Squash 2 sets of paths & return true if any overlap is found
837
+ *
838
+ * @param {string | PathEvent | (string | PathEvent)[]} target Array of PathedEvents as strings or pre-parsed
839
+ * @param has
840
+ * @return {boolean} Whether there is any overlap
841
+ */
842
+ static has(target, ...has) {
843
+ const parsedRequired = ft(has).map((pe) => new PathEvent(pe));
844
+ const parsedTarget = ft(target).map((pe) => new PathEvent(pe));
845
+ return !!parsedRequired.find((r) => {
846
+ if (!r.fullPath && r.all) return true;
847
+ const filtered = parsedTarget.filter((p2) => r.fullPath.startsWith(p2.fullPath));
848
+ if (!filtered.length) return false;
849
+ const combined = PathEvent.combine(filtered);
850
+ return !combined.none && (combined.all || new B(combined.methods).intersection(new B(r.methods)).length);
851
+ });
852
+ }
853
+ /**
854
+ * Same as `has` but raises an error if there is no overlap
855
+ *
856
+ * @param {string | string[]} target Array of PathedEvents as strings or pre-parsed
857
+ * @param has
858
+ */
859
+ static hasFatal(target, ...has) {
860
+ if (!PathEvent.has(target, ...has)) throw new Error(`Missing permission: ${ft(has).join(", ")}`);
861
+ }
862
+ /**
863
+ * Create pathed event string from its components
864
+ *
865
+ * @param {string | string[]} path Event path
866
+ * @param {Method} methods Event method
867
+ * @return {string} String representation of PathedEvent
868
+ */
869
+ static toString(path, methods) {
870
+ let p2 = ft(path).filter((p22) => p22 != null).join("/");
871
+ if (methods == null ? void 0 : methods.length) p2 += `:${ft(methods).map((m) => m.toLowerCase()).join("")}`;
872
+ return p2 == null ? void 0 : p2.trim().replaceAll(/\/{2,}/g, "/").replaceAll(/(^\/|\/$)/g, "");
873
+ }
874
+ /**
875
+ * Create pathed event string from its components
876
+ *
877
+ * @return {string} String representation of PathedEvent
878
+ */
879
+ toString() {
880
+ return PathEvent.toString(this.fullPath, this.methods);
881
+ }
811
882
  }
812
883
  class PathedEventEmitter {
813
884
  constructor() {
814
885
  __publicField(this, "listeners", []);
815
886
  }
816
887
  emit(event, ...args) {
817
- const parsed = parsePathedEvent(event);
818
- this.listeners.filter((l) => hasPath(l[0], event)).forEach((l) => l[1](parsed, ...args));
888
+ const parsed = new PathEvent(event);
889
+ this.listeners.filter((l) => PathEvent.has(l[0], event)).forEach((l) => l[1](parsed, ...args));
819
890
  }
820
891
  off(listener) {
821
892
  this.listeners = this.listeners.filter((l) => l[1] != listener);
822
893
  }
823
894
  on(event, listener) {
824
- ft(event).forEach((e) => this.listeners.push([parsePathedEvent(e), listener]));
895
+ ft(event).forEach((e) => this.listeners.push([new PathEvent(e), listener]));
825
896
  return () => this.off(listener);
826
897
  }
827
898
  once(event, listener) {
828
899
  return new Promise((res) => {
829
900
  const unsubscribe = this.on(event, (event2, ...args) => {
830
- res(args);
901
+ res(args.length < 2 ? args[0] : args);
831
902
  if (listener) listener(event2, ...args);
832
903
  unsubscribe();
833
904
  });
@@ -859,11 +930,11 @@ class Api extends F {
859
930
  if (token == this._token) return;
860
931
  this._token = token;
861
932
  this.headers["Authorization"] = token ? `Bearer ${token}` : null;
862
- this.emit(pathedEvent("api/token", "u"), token);
933
+ this.emit(PES`api/token:${token ? "u" : "d"}`, token);
863
934
  }
864
935
  healthcheck() {
865
936
  return this.request({ url: "/api/healthcheck" }).then((resp) => {
866
- this.emit(pathedEvent("api/healthcheck", "r"), resp);
937
+ this.emit(PES`api/healthcheck:r`, resp);
867
938
  return resp;
868
939
  });
869
940
  }
@@ -871,15 +942,15 @@ class Api extends F {
871
942
  const key = Lt(options);
872
943
  const method = options.method == "GET" ? "r" : options.method == "POST" ? "c" : options.method == "DELETE" ? "d" : "u";
873
944
  if (this.pending[key] != null) return this.pending[key];
874
- this.pending[key] = super.request(options).then((resp) => {
875
- this.emit(pathedEvent("api/response", method), resp, options);
876
- return resp.data;
945
+ this.pending[key] = super.request(options).then((response) => {
946
+ this.emit(PES`api/response:${method}`, { request: options, response });
947
+ return response.data;
877
948
  }).catch((err) => {
878
949
  const e = (err == null ? void 0 : err.data) || err;
879
- this.emit(pathedEvent("api/error", method), e, options);
950
+ this.emit(PES`api/error:${method}`, { request: options, error: e });
880
951
  throw e;
881
952
  }).finally(() => delete this.pending[key]);
882
- this.emit(pathedEvent("api/request", method), this.pending[key], options);
953
+ this.emit(PES`api/request:${method}`, { request: options, response: this.pending[key] });
883
954
  return this.pending[key];
884
955
  }
885
956
  }
@@ -902,15 +973,15 @@ class Actions extends PathedEventEmitter {
902
973
  }
903
974
  delete(id) {
904
975
  if (!id) throw new Error("Cannot delete action, missing ID");
905
- return this.api.request({ url: `/api/` + pathedEvent(["actions", id]), method: "DELETE" }).then(() => {
976
+ return this.api.request({ url: `/api/` + PES`actions/${id}`, method: "DELETE" }).then(() => {
906
977
  this.cache.delete(id);
907
- this.emit(pathedEvent(["actions", id], "d"), id);
978
+ this.emit(PES`actions/${id}:d`, id);
908
979
  });
909
980
  }
910
981
  all() {
911
- return this.api.request({ url: `/api/actions` }).then((resp) => {
982
+ return this.api.request({ url: `/api/` + PES`actions` }).then((resp) => {
912
983
  this.cache.addAll(resp);
913
- this.emit(pathedEvent("actions", "r"), resp || []);
984
+ this.emit(PES`actions:r`, resp || []);
914
985
  return resp;
915
986
  });
916
987
  }
@@ -918,35 +989,29 @@ class Actions extends PathedEventEmitter {
918
989
  if (!id) throw new Error("Cannot read action, missing ID");
919
990
  const cached = this.cache.get(id);
920
991
  if (!reload && cached) return Promise.resolve(cached);
921
- return this.api.request({ url: `/api/` + pathedEvent(["actions", id]) }).then((action) => {
992
+ return this.api.request({ url: `/api/` + PES`actions/${id}` }).then((action) => {
922
993
  if (action) this.cache.add(action);
923
- this.emit(pathedEvent(["actions", id], "r"), action);
994
+ this.emit(PES`actions/${id}:r`, action);
924
995
  return action;
925
996
  });
926
997
  }
927
998
  run(path, opts = {}) {
928
999
  if (!path) throw new Error("Cannot run action, missing path");
929
- return this.api.request({ url: `/api/` + pathedEvent(["actions/run", path]), ...opts }).then((resp) => {
930
- this.emit(pathedEvent(["actions/run", path], "x"), resp);
931
- return resp;
932
- });
1000
+ return this.api.request({ url: `/api/` + PES`actions/run/${path}`, ...opts });
933
1001
  }
934
1002
  runById(action, opts = {}) {
935
1003
  const id = typeof action == "string" ? action : action == null ? void 0 : action._id;
936
1004
  if (!id) throw new Error("Cannot run action, missing ID");
937
- return this.api.request({ url: "/api/" + pathedEvent(["actions/run-by-id", id]), method: "POST", ...opts }).then((resp) => {
938
- this.emit(pathedEvent(["actions/run-by-id", id], "x"), resp);
939
- return resp;
940
- });
1005
+ return this.api.request({ url: "/api/" + PES`actions/run-by-id/${id}`, method: "POST", ...opts });
941
1006
  }
942
1007
  update(action) {
943
1008
  return this.api.request({
944
- url: `/api/` + pathedEvent(["actions", action._id]),
1009
+ url: `/api/` + PES`actions/${action._id}`,
945
1010
  method: "POST",
946
1011
  body: action
947
1012
  }).then((action2) => {
948
1013
  if (action2) this.cache.add(action2);
949
- this.emit(pathedEvent(["actions", action2._id], "u"), action2);
1014
+ this.emit(PES`actions/${action2._id}:u`, action2);
950
1015
  return action2;
951
1016
  });
952
1017
  }
@@ -959,16 +1024,16 @@ class Ai extends PathedEventEmitter {
959
1024
  }
960
1025
  ask(question, context) {
961
1026
  if (!question) throw new Error("Cannot ask AI, missing question");
962
- return this.api.request({ url: `/api/ai`, method: "POST", body: {
1027
+ return this.api.request({ url: `/api/` + PES`ai`, method: "POST", body: {
963
1028
  question,
964
1029
  context
965
- } }).then((resp) => {
966
- this.emit(pathedEvent("ai", "c"), question, context, resp);
967
- return resp;
1030
+ } }).then((response) => {
1031
+ this.emit(PES`ai:c`, { question, context, response });
1032
+ return response;
968
1033
  });
969
1034
  }
970
1035
  clear() {
971
- return this.api.request({ url: "/api/ai", method: "DELETE" }).then(() => this.emit(pathedEvent("ai", "d")));
1036
+ return this.api.request({ url: "/api/" + PES`ai`, method: "DELETE" }).then(() => this.emit(PES`ai:d`, this.api.token));
972
1037
  }
973
1038
  }
974
1039
  class Analytics extends PathedEventEmitter {
@@ -979,8 +1044,8 @@ class Analytics extends PathedEventEmitter {
979
1044
  }
980
1045
  ipTrace(ip) {
981
1046
  if (!ip) throw new Error("Cannot trace, missing IP");
982
- return this.api.request({ url: `/api/analytics/trace?ip=${ip}` }).then((resp) => {
983
- this.emit(pathedEvent("analytics/trace", "r"), ip, resp);
1047
+ return this.api.request({ url: `/api/` + PES`analytics/trace/${ip}` }).then((resp) => {
1048
+ this.emit(PES`analytics/trace/${ip}:r`, resp);
984
1049
  return resp;
985
1050
  });
986
1051
  }
@@ -1026,11 +1091,12 @@ class Auth extends PathedEventEmitter {
1026
1091
  "/api/auth/totp"
1027
1092
  ];
1028
1093
  if (resp.status == 401 && !blacklist.find((url) => resp.url.includes(url)))
1029
- this.emit(pathedEvent("auth/session-expired", "d"));
1094
+ this.emit(PES`auth/session-expired:d`, this.api.token);
1030
1095
  next();
1031
1096
  });
1032
1097
  this.api.on("api/token", (event, token) => {
1033
1098
  var _a;
1099
+ console.log("loading user...");
1034
1100
  if ((_a = this.opts) == null ? void 0 : _a.persist) {
1035
1101
  if (token) localStorage.setItem(this.storageKey, token);
1036
1102
  else localStorage.removeItem(this.storageKey);
@@ -1053,15 +1119,12 @@ class Auth extends PathedEventEmitter {
1053
1119
  set user(user) {
1054
1120
  if (!A(this.user, user)) {
1055
1121
  this._user = user ? user : null;
1056
- this.emit(pathedEvent("auth/user", "u"), this._user);
1122
+ this.emit(PES`auth/user:u`, this._user);
1057
1123
  }
1058
1124
  }
1059
1125
  knownHost(host = location.origin) {
1060
1126
  if (host.startsWith("/")) return Promise.resolve();
1061
- return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` }).then(() => this.emit(pathedEvent("auth/known-host", "r"), host, true)).catch((err) => {
1062
- this.emit(pathedEvent("auth/known-host", "r"), host, false);
1063
- throw err;
1064
- });
1127
+ return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` });
1065
1128
  }
1066
1129
  login(username, password, totp) {
1067
1130
  if (!username || !password) throw new Error("Cannot login, missing username or password");
@@ -1077,7 +1140,7 @@ class Auth extends PathedEventEmitter {
1077
1140
  }).then(async (resp) => {
1078
1141
  this.api.token = (resp == null ? void 0 : resp.token) || null;
1079
1142
  const user = await this.once("auth/user");
1080
- this.emit(pathedEvent(["auth/login", username], "x"), user);
1143
+ this.emit(PES`auth/login/${username}:u`, user);
1081
1144
  return user;
1082
1145
  });
1083
1146
  }
@@ -1098,16 +1161,16 @@ class Auth extends PathedEventEmitter {
1098
1161
  });
1099
1162
  }
1100
1163
  logout() {
1164
+ this.emit(PES`auth/logout:d`, this.user);
1101
1165
  this.api.token = null;
1102
1166
  this.user = null;
1103
- this.emit(pathedEvent("auth/logout", "d"));
1104
1167
  }
1105
1168
  async register(u) {
1106
1169
  var _a;
1107
1170
  if (!u.username || !u.password) throw new Error("Cannot register user, missing username or password");
1108
1171
  const user = await this.api.request({ url: "/api/auth/register", body: { ...u } });
1109
1172
  if ((_a = user == null ? void 0 : user.image) == null ? void 0 : _a.startsWith("/")) user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
1110
- this.emit(pathedEvent("auth/register", "c"), user);
1173
+ this.emit(PES`auth/register:c`, user);
1111
1174
  return user;
1112
1175
  }
1113
1176
  reset(emailOrPass, token) {
@@ -1120,7 +1183,7 @@ class Auth extends PathedEventEmitter {
1120
1183
  password: token ? emailOrPass : void 0
1121
1184
  }
1122
1185
  }).then(() => {
1123
- this.emit(pathedEvent("auth/reset", token ? "u" : "c"), token || emailOrPass);
1186
+ this.emit(PES`auth/reset:${token ? "u" : "c"}`, token || emailOrPass);
1124
1187
  });
1125
1188
  }
1126
1189
  async session(token, set = false) {
@@ -1129,12 +1192,12 @@ class Auth extends PathedEventEmitter {
1129
1192
  url: "/api/auth/session",
1130
1193
  headers: token ? { "Authorization": `Bearer ${token}` } : void 0
1131
1194
  });
1132
- this.emit(pathedEvent("auth/session", "r"), session);
1195
+ this.emit(PES`auth/session:r`, session);
1133
1196
  if (set) {
1134
1197
  this.api.token = token;
1135
1198
  if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
1136
1199
  this.user = (session == null ? void 0 : session.user) || null;
1137
- if (session) this.emit(pathedEvent("auth/login", "c"), session.user);
1200
+ if (session) this.emit(PES`auth/login:c`, session.user);
1138
1201
  }
1139
1202
  return session;
1140
1203
  }
@@ -1144,7 +1207,7 @@ class Auth extends PathedEventEmitter {
1144
1207
  url: "/api/auth/password",
1145
1208
  body: { username, password, oldPassword }
1146
1209
  }).then((resp) => {
1147
- this.emit(pathedEvent("auth/reset", "u"), resp == null ? void 0 : resp.token);
1210
+ this.emit(PES`auth/reset:u`, resp == null ? void 0 : resp.token);
1148
1211
  if (resp == null ? void 0 : resp.token) this.api.token = resp.token;
1149
1212
  });
1150
1213
  }
@@ -1250,7 +1313,7 @@ class Client extends PathedEventEmitter {
1250
1313
  if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
1251
1314
  }, 500);
1252
1315
  }
1253
- this.emit(pathedEvent("client/inject", "c"));
1316
+ this.emit(PES`client/inject:c`, this.platform);
1254
1317
  }
1255
1318
  pwaPrompt(platform) {
1256
1319
  const url = this.settings.api.url;
@@ -1367,13 +1430,13 @@ class Client extends PathedEventEmitter {
1367
1430
  setTimeout(() => {
1368
1431
  prompt.remove();
1369
1432
  backdrop.remove();
1370
- this.emit(pathedEvent("client/pwa", "d"), platform);
1433
+ this.emit(PES`client/pwa:d`, platform);
1371
1434
  }, 500);
1372
1435
  };
1373
1436
  prompt.append(close);
1374
1437
  backdrop.append(prompt);
1375
1438
  document.body.append(backdrop);
1376
- this.emit(pathedEvent("client/pwa", "c"), platform);
1439
+ this.emit(PES`client/pwa:c`, platform);
1377
1440
  }
1378
1441
  }
1379
1442
  class Data extends PathedEventEmitter {
@@ -1385,18 +1448,18 @@ class Data extends PathedEventEmitter {
1385
1448
  create(collection, document2) {
1386
1449
  if (!collection || !document2) throw new Error("Cannot create document, missing collection or document");
1387
1450
  return this.api.request({
1388
- url: `/api/` + pathedEvent(["data", collection]),
1451
+ url: `/api/` + PES`data/${collection}`,
1389
1452
  method: "POST",
1390
1453
  body: document2
1391
1454
  }).then((resp) => {
1392
- this.emit(pathedEvent(["data", collection], "c"), collection, resp);
1455
+ this.emit(PES`data/${collection}:c`, resp);
1393
1456
  return resp;
1394
1457
  });
1395
1458
  }
1396
1459
  read(collection, id) {
1397
1460
  if (!collection) throw new Error("Cannot read documents, missing collection");
1398
- return this.api.request({ url: `/api/` + pathedEvent(["data", collection, id]) }).then((resp) => {
1399
- this.emit(pathedEvent(["data", collection, id], "r"), collection, resp);
1461
+ return this.api.request({ url: `/api/` + PES`data/${collection}/${id}` }).then((resp) => {
1462
+ this.emit(PES`data/${collection}/${id}:r`, collection, resp);
1400
1463
  return resp;
1401
1464
  });
1402
1465
  }
@@ -1404,43 +1467,43 @@ class Data extends PathedEventEmitter {
1404
1467
  if (!collection || !document2) throw new Error("Cannot update document, missing collection or document");
1405
1468
  if (!document2._id) return this.create(collection, document2);
1406
1469
  return this.api.request({
1407
- url: `/api/` + pathedEvent(["data", collection, document2._id]),
1470
+ url: `/api/` + PES`data/${collection}/${document2._id}`,
1408
1471
  method: append ? "PATCH" : "PUT",
1409
1472
  body: document2
1410
1473
  }).then((resp) => {
1411
- this.emit(pathedEvent(["data", collection, document2._id], "u"), collection, resp);
1474
+ this.emit(PES`data/${collection}/${document2._id}:u`, resp);
1412
1475
  return resp;
1413
1476
  });
1414
1477
  }
1415
1478
  delete(collection, id) {
1416
1479
  if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
1417
1480
  return this.api.request({
1418
- url: `/api/` + pathedEvent(["data", collection, id]),
1481
+ url: `/api/` + PES`data/${collection}/${id}`,
1419
1482
  method: "DELETE"
1420
- }).then(() => this.emit(pathedEvent(["data", collection, id], "d"), collection, id));
1483
+ }).then(() => this.emit(PES`data/${collection}/${id}:d`, id));
1421
1484
  }
1422
1485
  raw(collection, query) {
1423
1486
  if (!collection || !query) throw new Error("Cannot execute raw query, missing collection or query");
1424
1487
  const mode = query.operand.startsWith("find") ? "r" : query.operand == "insert" ? "c" : query.operand.startsWith("delete") ? "d" : "u";
1425
- return this.api.request({ url: `/api/` + pathedEvent(["data/raw", collection]) + "?raw", body: query }).then((resp) => {
1426
- this.emit(pathedEvent(["data", collection], mode), collection, query, resp);
1488
+ return this.api.request({ url: `/api/` + PES`data/${collection}` + "?raw", body: query }).then((resp) => {
1489
+ this.emit(PES`data/${collection}:${mode}`, resp);
1427
1490
  return resp;
1428
1491
  });
1429
1492
  }
1430
1493
  deleteSchema(path) {
1431
1494
  if (!path) throw new Error("Cannot delete schema, missing collection path");
1432
- return this.api.request({ url: `/api/` + pathedEvent(["schema", path]), method: "DELETE" }).then(() => this.emit(pathedEvent(["schema", path], "d"), path));
1495
+ return this.api.request({ url: `/api/` + PES`schema/${path}`, method: "DELETE" }).then(() => this.emit(PES`schema/${path}:d`, path));
1433
1496
  }
1434
1497
  getSchema(pathOrTree) {
1435
- return this.api.request({ url: "/api/" + pathedEvent(["schema", typeof pathOrTree == "string" ? pathOrTree : ""]) + (pathOrTree === true ? `?tree=${pathOrTree}` : "") }).then((resp) => {
1436
- this.emit(pathedEvent(["schema", typeof pathOrTree == "string" ? pathOrTree : ""], "r"), resp);
1498
+ return this.api.request({ url: "/api/" + PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}` + (pathOrTree === true ? `?tree=${pathOrTree}` : "") }).then((resp) => {
1499
+ this.emit(PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}:r`, resp);
1437
1500
  return resp;
1438
1501
  });
1439
1502
  }
1440
1503
  setSchema(schema) {
1441
1504
  if (!schema.path) throw new Error("Cannot update schema, missing collection path");
1442
- return this.api.request({ url: "/api/" + pathedEvent(["schema", schema.path]), body: schema }).then((resp) => {
1443
- this.emit(pathedEvent(["schema", schema.path], schema._id ? "u" : "c"), resp);
1505
+ return this.api.request({ url: "/api/" + PES`schema/${schema.path}`, body: schema }).then((resp) => {
1506
+ this.emit(PES`schema/${schema.path}:${schema._id ? "u" : "c"}`, resp);
1444
1507
  return resp;
1445
1508
  });
1446
1509
  }
@@ -1454,10 +1517,10 @@ class Email extends PathedEventEmitter {
1454
1517
  send(email) {
1455
1518
  var _a;
1456
1519
  if (!email.to && !email.bcc || !email.body) throw new Error("Cannot send email, missing address or body");
1457
- return this.api.request({ url: "/api/" + pathedEvent(["email", (_a = email.body) == null ? void 0 : _a.template]), body: email }).then((resp) => {
1520
+ return this.api.request({ url: "/api/" + PES`email/${(_a = email.body) == null ? void 0 : _a.template}`, body: email }).then((response) => {
1458
1521
  var _a2;
1459
- this.emit(pathedEvent(["email", (_a2 = email.body) == null ? void 0 : _a2.template], "c"), email, resp);
1460
- return resp;
1522
+ this.emit(PES`email/${(_a2 = email.body) == null ? void 0 : _a2.template}:c`, { email, response });
1523
+ return response;
1461
1524
  });
1462
1525
  }
1463
1526
  }
@@ -1465,49 +1528,59 @@ class Groups extends PathedEventEmitter {
1465
1528
  constructor(api) {
1466
1529
  super();
1467
1530
  __publicField(this, "api");
1531
+ __publicField(this, "cache", new Dt("name"));
1468
1532
  this.api = typeof api == "string" ? new Api(api) : api;
1469
1533
  }
1470
- all() {
1471
- return this.api.request({ url: `/api/groups` }).then((resp) => {
1472
- this.emit(pathedEvent("groups", "r"), resp || []);
1534
+ async all(reload) {
1535
+ if (!reload && this.cache.complete) return this.cache.all();
1536
+ return this.api.request({ url: `/api/` + PES`groups` }).then((resp) => {
1537
+ this.cache.addAll(resp);
1538
+ this.emit(PES`groups:r`, resp || []);
1473
1539
  return resp;
1474
1540
  });
1475
1541
  }
1476
1542
  create(group) {
1477
1543
  if (!group.name) throw new Error("Cannot create group, missing name");
1478
1544
  return this.api.request({
1479
- url: `/api/groups/${group.name}`,
1545
+ url: `/api/` + PES`groups/${group.name}`,
1480
1546
  method: "POST",
1481
1547
  body: group
1482
1548
  }).then((resp) => {
1483
- this.emit(pathedEvent(["groups", group.name], "c"), resp);
1549
+ this.cache.add(resp);
1550
+ this.emit(PES`groups/${group.name}:c`, resp);
1484
1551
  return resp;
1485
1552
  });
1486
1553
  }
1487
- read(name) {
1554
+ async read(name, reload) {
1488
1555
  if (!name) throw new Error("Cannot read group, missing name");
1489
- return this.api.request({ url: `/api/` + pathedEvent(["groups", name]) }).then((resp) => {
1490
- this.emit(pathedEvent(["groups", name], "r"), resp);
1556
+ if (!reload && this.cache.get(name)) return this.cache.get(name);
1557
+ return this.api.request({ url: `/api/` + PES`groups/${name}` }).then((resp) => {
1558
+ this.cache.add(resp);
1559
+ this.emit(PES`groups/${name}:r`, resp);
1491
1560
  return resp;
1492
1561
  });
1493
1562
  }
1494
1563
  update(group) {
1495
1564
  if (!group.name) throw new Error("Cannot update group, missing name");
1496
1565
  return this.api.request({
1497
- url: `/api/` + pathedEvent(["groups", group.name]),
1566
+ url: `/api/` + PES`groups/${group.name}`,
1498
1567
  method: "PATCH",
1499
1568
  body: group
1500
1569
  }).then((resp) => {
1501
- this.emit(pathedEvent(["groups", group.name], "u"), resp);
1570
+ this.cache.add(resp);
1571
+ this.emit(PES`groups/${group.name}:u`, resp);
1502
1572
  return resp;
1503
1573
  });
1504
1574
  }
1505
1575
  delete(name) {
1506
1576
  if (!name) throw new Error("Cannot delete group, missing name");
1507
1577
  return this.api.request({
1508
- url: `/api/` + pathedEvent(["groups", name]),
1578
+ url: `/api/` + PES`groups/${name}`,
1509
1579
  method: "DELETE"
1510
- }).then(() => this.emit(pathedEvent(["groups", name], "d")));
1580
+ }).then(() => {
1581
+ this.cache.delete(name);
1582
+ this.emit(PES`groups/${name}:d`);
1583
+ });
1511
1584
  }
1512
1585
  }
1513
1586
  class Logger extends PathedEventEmitter {
@@ -1546,11 +1619,11 @@ ${log}`;
1546
1619
  };
1547
1620
  }
1548
1621
  createLog(log, namespace = this.namespace) {
1549
- return this.api.request({ url: `/api/` + pathedEvent(["logs", namespace]), body: log }).then(() => this.emit(pathedEvent(["logs", namespace], "c"), log)).catch(() => {
1622
+ return this.api.request({ url: `/api/` + PES`logs/${namespace}`, body: log }).then(() => this.emit(PES`logs/${namespace}:c`, log)).catch(() => {
1550
1623
  });
1551
1624
  }
1552
1625
  clearLogs(namespace = this.namespace) {
1553
- return this.api.request({ url: `/api/` + pathedEvent(["logs", namespace]), method: "DELETE" }).then(() => this.emit(pathedEvent(["logs", namespace], "d")));
1626
+ return this.api.request({ url: `/api/` + PES`logs/${namespace}`, method: "DELETE" }).then(() => this.emit(PES`logs/${namespace}:d`));
1554
1627
  }
1555
1628
  clearServerLogs() {
1556
1629
  return this.clearLogs("server");
@@ -1558,8 +1631,8 @@ ${log}`;
1558
1631
  getLogs(length, page, namespace = this.namespace) {
1559
1632
  if (!namespace) throw new Error("Cannot get logs, missing namespace");
1560
1633
  const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v) => !!v).join("&");
1561
- return this.api.request({ url: `/api/` + pathedEvent(["logs", namespace]) + (query ? `?${query}` : "") }).then((logs) => {
1562
- this.emit(pathedEvent(["logs", namespace], "r"), logs);
1634
+ return this.api.request({ url: `/api/` + PES`logs/${namespace}` + (query ? `?${query}` : "") }).then((logs) => {
1635
+ this.emit(PES`logs/${namespace}:r`, logs);
1563
1636
  return logs;
1564
1637
  });
1565
1638
  }
@@ -1605,7 +1678,7 @@ class Payments extends PathedEventEmitter {
1605
1678
  amount,
1606
1679
  custom
1607
1680
  } });
1608
- this.emit(pathedEvent("payments", "c"), amount, custom, request.data.clientSecret);
1681
+ this.emit(PES`payments:c`, request.data.clientSecret);
1609
1682
  return request.data.clientSecret;
1610
1683
  }
1611
1684
  async createForm(element, amount, custom) {
@@ -1619,8 +1692,8 @@ class Payments extends PathedEventEmitter {
1619
1692
  });
1620
1693
  }
1621
1694
  async history(username) {
1622
- const history = await this.api.request({ url: `/api/` + pathedEvent("payments", username) });
1623
- this.emit(pathedEvent(["payments", username], "r"), username, history);
1695
+ const history = await this.api.request({ url: `/api/` + PES`payments/${username}` });
1696
+ this.emit(PES`payments/${username}:r`, history);
1624
1697
  return history;
1625
1698
  }
1626
1699
  }
@@ -1631,7 +1704,7 @@ class Pdf extends PathedEventEmitter {
1631
1704
  this.api = typeof api == "string" ? new Api(api) : api;
1632
1705
  }
1633
1706
  createPdf(body, options) {
1634
- return this.api.request({ url: `/api/pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
1707
+ return this.api.request({ url: `/api/` + PES`pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
1635
1708
  const blob = await resp.blob();
1636
1709
  if (options == null ? void 0 : options.download) {
1637
1710
  let filename = (options == null ? void 0 : options.filename) || qt();
@@ -1640,7 +1713,7 @@ class Pdf extends PathedEventEmitter {
1640
1713
  dt(url, filename);
1641
1714
  URL.revokeObjectURL(url);
1642
1715
  }
1643
- this.emit(pathedEvent("pdf", "c"), body, options, blob);
1716
+ this.emit(PES`pdf:c`, blob);
1644
1717
  return blob;
1645
1718
  });
1646
1719
  }
@@ -1712,54 +1785,54 @@ class Storage extends PathedEventEmitter {
1712
1785
  }
1713
1786
  copy(source, destination) {
1714
1787
  if (!source || !destination) throw new Error("Cannot copy file or folder, missing source or destination");
1715
- return this.api.request({ url: "/api/" + pathedEvent(["storage", destination]), body: { from: source } }).then((resp) => {
1716
- this.emit(pathedEvent(["storage", destination], "c"), source, destination, resp);
1717
- return resp;
1788
+ return this.api.request({ url: "/api/" + PES`storage/${destination}`, body: { from: source } }).then((response) => {
1789
+ this.emit(PES`storage/${destination}:c`, response);
1790
+ return response;
1718
1791
  });
1719
1792
  }
1720
1793
  delete(path) {
1721
1794
  if (!path) throw new Error("Cannot delete file or folder, missing path");
1722
- return this.api.request({ url: "/api/" + pathedEvent(["storage", path]), method: "DELETE" }).then(() => {
1723
- this.emit(pathedEvent(["storage", path], "d"), path);
1795
+ return this.api.request({ url: "/api/" + PES`storage/${path}`, method: "DELETE" }).then(() => {
1796
+ this.emit(PES`storage/${path}:d`, path);
1724
1797
  });
1725
1798
  }
1726
1799
  download(path, opts = {}) {
1727
1800
  if (!path) throw new Error("Cannot download file, missing path");
1728
- return this.api.request({ ...opts, url: "/api/" + pathedEvent(["storage", path]), decode: false }).then(async (response) => {
1801
+ return this.api.request({ ...opts, url: "/api/" + PES`storage/${path}`, decode: false }).then(async (response) => {
1729
1802
  const blob = await response.blob();
1730
1803
  const name = opts.downloadAs || path.split("/").pop();
1731
- this.emit(pathedEvent(["storage", path], "r"), path, blob);
1804
+ this.emit(PES`storage/${path}:r`, blob);
1732
1805
  Gt(blob, name);
1733
1806
  return response;
1734
1807
  });
1735
1808
  }
1736
1809
  list(path) {
1737
1810
  if (!path) path = "/";
1738
- return this.api.request({ url: "/api/" + pathedEvent(["storage", path]) + "?list" }).then((resp) => {
1739
- this.emit(pathedEvent(["storage", path], "r"), path, resp);
1811
+ return this.api.request({ url: "/api/" + PES`storage/${path}` + "?list" }).then((resp) => {
1812
+ this.emit(PES`storage/${path}:r`, resp);
1740
1813
  return resp;
1741
1814
  });
1742
1815
  }
1743
1816
  open(path, target = "_blank") {
1744
1817
  if (!path) throw new Error("Cannot download file, missing path");
1745
- const link = `${this.api.url}/api/${pathedEvent(["storage", path])}${this.api.token ? `?token=${this.api.token}` : ""}`;
1818
+ const link = `${this.api.url}/api/` + PES`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
1746
1819
  if (!target) return link;
1747
- this.emit(pathedEvent(["storage", path], "r"), path);
1820
+ this.emit(PES`storage/${path}:r`, path);
1748
1821
  return window.open(link, target);
1749
1822
  }
1750
1823
  mkdir(path) {
1751
1824
  if (!path) throw new Error("Cannot make directory, missing path");
1752
- return this.api.request({ url: "/api/" + pathedEvent(["storage", path]), body: { directory: true } }).then((resp) => {
1753
- this.emit(pathedEvent(["storage", path], "c"), path, resp);
1825
+ return this.api.request({ url: "/api/" + PES`storage/${path}`, body: { directory: true } }).then((resp) => {
1826
+ this.emit(PES`storage/${path}:c`, resp);
1754
1827
  return resp;
1755
1828
  });
1756
1829
  }
1757
1830
  move(source, destination) {
1758
1831
  if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
1759
1832
  if (source == destination) return this.list(destination);
1760
- return this.api.request({ url: "/api/" + pathedEvent(["storage", source]), method: "PATCH", body: { move: destination } }).then((resp) => {
1761
- this.emit(pathedEvent(["storage", source], "u"), source, destination, resp);
1762
- return resp;
1833
+ return this.api.request({ url: "/api/" + PES`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
1834
+ this.emit(PES`storage/${source}:u`, response);
1835
+ return response;
1763
1836
  });
1764
1837
  }
1765
1838
  upload(files, opts) {
@@ -1768,13 +1841,13 @@ class Storage extends PathedEventEmitter {
1768
1841
  if (!files || Array.isArray(files) && !files.length) return [];
1769
1842
  const path = (opts && typeof opts == "object" ? opts == null ? void 0 : opts.path : opts) || "/";
1770
1843
  return Ft({
1771
- url: `${this.api.url}/api/${pathedEvent(["storage", path])}`,
1844
+ url: `${this.api.url}/api/` + PES`storage/${path}`,
1772
1845
  files: ft(files),
1773
1846
  headers: this.api.headers
1774
1847
  }).onProgress((p2) => {
1775
1848
  prog(p2);
1776
1849
  }).then((resp) => {
1777
- this.emit(pathedEvent(["storage", path], "c"), resp);
1850
+ this.emit(PES`storage/${path}:c`, resp);
1778
1851
  res(resp);
1779
1852
  }).catch((err) => rej(err));
1780
1853
  });
@@ -1787,44 +1860,44 @@ class Users extends PathedEventEmitter {
1787
1860
  __publicField(this, "cache", new Dt("username"));
1788
1861
  this.api = typeof api == "string" ? new Api(api) : api;
1789
1862
  }
1790
- delete(username) {
1791
- if (!username) throw new Error("Cannot delete user, missing username");
1792
- return this.api.request({
1793
- url: "/api/" + pathedEvent(["users", username]),
1794
- method: "DELETE"
1795
- }).then(() => {
1796
- this.cache.delete(username);
1797
- this.emit(pathedEvent(["users", username], "d"), username);
1798
- });
1799
- }
1800
- async all(reload = false) {
1863
+ async all(reload) {
1801
1864
  if (!reload && this.cache.complete) return this.cache.all();
1802
- return this.api.request({ url: "/api/" + pathedEvent("users") }).then((resp) => {
1865
+ return this.api.request({ url: "/api/" + PES`users` }).then((resp) => {
1803
1866
  resp == null ? void 0 : resp.forEach((r) => {
1804
1867
  r.image = this.api.url + r.image + `?token=${this.api.token}`;
1805
1868
  return r;
1806
1869
  });
1807
1870
  this.cache.addAll(resp);
1808
- this.emit(pathedEvent("users", "r"), resp || []);
1871
+ this.emit(PES`users:r`, resp || []);
1809
1872
  return resp;
1810
1873
  });
1811
1874
  }
1812
- async read(username, reload = false) {
1875
+ delete(username) {
1876
+ if (!username) throw new Error("Cannot delete user, missing username");
1877
+ return this.api.request({
1878
+ url: "/api/" + PES`users/${username}`,
1879
+ method: "DELETE"
1880
+ }).then(() => {
1881
+ this.cache.delete(username);
1882
+ this.emit(PES`users/${username}:d`, username);
1883
+ });
1884
+ }
1885
+ async read(username, reload) {
1813
1886
  if (!username) throw new Error("Cannot read user, missing username");
1814
1887
  if (!reload && this.cache.get(username)) return this.cache.get(username);
1815
- return this.api.request({ url: "/api/" + pathedEvent(["users", username]) }).then((resp) => {
1888
+ return this.api.request({ url: "/api/" + PES`users/${username}` }).then((resp) => {
1816
1889
  if (resp) {
1817
1890
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1818
1891
  this.cache.add(resp);
1819
1892
  }
1820
- this.emit(pathedEvent(["users", username], "r"), resp);
1893
+ this.emit(PES`users/${username}:r`, resp);
1821
1894
  return resp;
1822
1895
  });
1823
1896
  }
1824
1897
  update(user) {
1825
1898
  if (!user.username) throw new Error("Cannot update user, missing username");
1826
1899
  return this.api.request({
1827
- url: `/api/` + pathedEvent(["users", user.username]),
1900
+ url: `/api/` + PES`users/${user.username}`,
1828
1901
  method: "PATCH",
1829
1902
  body: user
1830
1903
  }).then((resp) => {
@@ -1832,19 +1905,16 @@ class Users extends PathedEventEmitter {
1832
1905
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1833
1906
  this.cache.add(resp);
1834
1907
  }
1835
- this.emit(pathedEvent(["users", user.username], resp._id ? "u" : "c"), resp);
1908
+ this.emit(PES`users/${user.username}:${resp._id ? "u" : "c"}`, resp);
1836
1909
  return resp;
1837
1910
  });
1838
1911
  }
1839
1912
  uploadImage(username, file) {
1840
1913
  if (!username || !file) throw new Error("Cannot update user image, missing username or file");
1841
1914
  return Ft({
1842
- url: this.api.url + `/api/` + pathedEvent(["users", username, "image"]),
1915
+ url: this.api.url + `/api/` + PES`users/${username}/image`,
1843
1916
  files: [file],
1844
1917
  headers: this.api.headers
1845
- }).then((resp) => {
1846
- this.emit(pathedEvent(["users", username, "image"], "u"), username, file);
1847
- return resp;
1848
1918
  });
1849
1919
  }
1850
1920
  }
@@ -1857,33 +1927,33 @@ class Settings extends PathedEventEmitter {
1857
1927
  }
1858
1928
  async all(detailed = false, reload) {
1859
1929
  if (!reload && !detailed && this.cache.complete) return this.cache;
1860
- return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
1930
+ return this.api.request({ url: `/api/` + PES`settings` + (detailed ? "?detailed" : "") }).then((resp) => {
1861
1931
  if (resp) Object.keys(resp).forEach((key) => this.cache.set(key, detailed ? resp[key].value : resp[key]));
1862
- this.emit(pathedEvent("settings", "r"), resp || []);
1932
+ this.emit(PES`settings:r`, resp || []);
1863
1933
  return resp;
1864
1934
  });
1865
1935
  }
1866
1936
  delete(key) {
1867
1937
  if (!key) throw new Error("Cannot delete setting, missing key");
1868
- return this.api.request({ url: `/api/` + pathedEvent(["settings", key]), method: "DELETE" }).then(() => {
1938
+ return this.api.request({ url: `/api/` + PES`settings/${key}`, method: "DELETE" }).then(() => {
1869
1939
  this.cache.delete(key);
1870
- this.emit(pathedEvent(["settings", key], "d"), key);
1940
+ this.emit(PES`settings/${key}:d`, key);
1871
1941
  });
1872
1942
  }
1873
1943
  read(key, reload = false) {
1874
1944
  if (!key) throw new Error("Cannot read setting, missing key");
1875
1945
  if (!reload && this.cache.get(key)) return this.cache.get(key);
1876
- return this.api.request({ url: `/api/` + pathedEvent(["settings", key]) }).then((variable) => {
1946
+ return this.api.request({ url: `/api/` + PES`settings/${key}` }).then((variable) => {
1877
1947
  if (variable) this.cache.set(variable.key, variable.value);
1878
- this.emit(pathedEvent(["settings", key], "r"), variable);
1948
+ this.emit(PES`settings/${key}:r`, variable);
1879
1949
  return variable;
1880
1950
  });
1881
1951
  }
1882
1952
  update(variable) {
1883
1953
  if (!variable.key) throw new Error("Cannot update setting, missing key");
1884
- return this.api.request({ url: `/api/` + pathedEvent(["settings", variable.key]), body: variable }).then((variable2) => {
1954
+ return this.api.request({ url: `/api/` + PES`settings/${variable.key}`, body: variable }).then((variable2) => {
1885
1955
  if (variable2) this.cache.set(variable2.key, variable2.value);
1886
- this.emit(`/api/` + pathedEvent(["settings", variable2.key], variable2._id ? "u" : "c"), variable2);
1956
+ this.emit(`/api/` + PES`settings/${variable2.key}:${variable2._id ? "u" : "c"}`, variable2);
1887
1957
  return variable2;
1888
1958
  });
1889
1959
  }
@@ -1896,21 +1966,21 @@ class Static extends PathedEventEmitter {
1896
1966
  }
1897
1967
  delete(path) {
1898
1968
  if (!path) throw new Error("Cannot delete static asset, missing path");
1899
- return this.api.request({ url: `/api/` + pathedEvent(["static", path]), method: "DELETE" }).then(() => {
1900
- this.emit(pathedEvent(["static", path], "d"), path);
1969
+ return this.api.request({ url: `/api/` + PES`static/${path}`, method: "DELETE" }).then(() => {
1970
+ this.emit(PES`static/${path}:d`, path);
1901
1971
  });
1902
1972
  }
1903
1973
  upload(files, path = "/") {
1904
1974
  if (!files) throw new Error("Cannot upload static assets, missing file");
1905
1975
  return new E(async (res, rej, prog) => {
1906
1976
  return Ft({
1907
- url: this.api.url + "/api/" + pathedEvent(["static", path]),
1977
+ url: this.api.url + "/api/" + PES`static/${path}`,
1908
1978
  files: ft(files),
1909
1979
  headers: this.api.headers
1910
1980
  }).onProgress((p2) => {
1911
1981
  prog(p2);
1912
1982
  }).then((resp) => {
1913
- this.emit(pathedEvent(["static", path], "c"), resp);
1983
+ this.emit(PES`static/${path}:c`, resp);
1914
1984
  res(resp);
1915
1985
  }).catch((err) => rej(err));
1916
1986
  });
@@ -1974,7 +2044,8 @@ class Momentum extends PathedEventEmitter {
1974
2044
  this.relayEvents(this.users);
1975
2045
  this.users.on(`*`, () => {
1976
2046
  if (!this.auth.user) return;
1977
- this.auth.user = this.users.cache.get(this.auth.user.username);
2047
+ const cached = this.users.cache.get(this.auth.user.username);
2048
+ if (cached) this.auth.user = cached;
1978
2049
  });
1979
2050
  }
1980
2051
  }
@@ -1991,6 +2062,9 @@ export {
1991
2062
  Groups,
1992
2063
  Logger,
1993
2064
  Momentum,
2065
+ PE,
2066
+ PES,
2067
+ PathEvent,
1994
2068
  PathedEventEmitter,
1995
2069
  Payments,
1996
2070
  Pdf,
@@ -1999,10 +2073,5 @@ export {
1999
2073
  Static,
2000
2074
  Storage,
2001
2075
  Totp,
2002
- Users,
2003
- combinePathedEvents,
2004
- hasPath,
2005
- hasPathFatal,
2006
- parsePathedEvent,
2007
- pathedEvent
2076
+ Users
2008
2077
  };