diff --git a/src/util/config/envTypes/ConfigurationEnvConfiguration.ts b/src/util/config/envTypes/ConfigurationEnvConfiguration.ts
index 131d96ff7..4f6918d9c 100644
--- a/src/util/config/envTypes/ConfigurationEnvConfiguration.ts
+++ b/src/util/config/envTypes/ConfigurationEnvConfiguration.ts
@@ -16,9 +16,11 @@
along with this program. If not, see .
*/
+import { arrayOrderBy } from "@spacebar/util";
+
export class ConfigurationEnvConfiguration {
static get schema() {
- return [
+ return arrayOrderBy([
{ key: "CONFIG_PATH", type: "string", description: "Path to a JSON file containing configuration data" },
{ key: "CONFIG_WRITEBACK", type: "boolean", description: "Whether to write back configuration changes to the specified JSON file" },
{
@@ -32,7 +34,7 @@ export class ConfigurationEnvConfiguration {
"
**`single`**: Ignore database config outright" +
"",
},
- ].orderBy((e) => e.key);
+ ], (e) => e.key);
}
get enabled(): boolean {
diff --git a/src/util/config/envTypes/LogEnvConfiguration.ts b/src/util/config/envTypes/LogEnvConfiguration.ts
index c4bbbfa6c..ab97503cc 100644
--- a/src/util/config/envTypes/LogEnvConfiguration.ts
+++ b/src/util/config/envTypes/LogEnvConfiguration.ts
@@ -16,6 +16,8 @@
along with this program. If not, see .
*/
+import { arrayOrderBy } from "@spacebar/util";
+
interface GatewayLoggingConfigValue {
enabled: boolean;
logTraces: boolean;
@@ -28,7 +30,7 @@ interface GatewayLoggingConfigValue {
export class LogEnvConfiguration {
static get schema() {
- return [
+ return arrayOrderBy([
{ key: "LOG_CDN_SIGNATURES", type: "boolean", description: "Log CDN attachment signature checks - very noisy!" },
{ key: "LOG_DATABASE_QUERIES", type: "boolean", description: "Enable logging of database queries." },
{ key: "LOG_GATEWAY_EVENTS", type: "boolean", description: "Comma-separated list of flags. Any of: `TRACES`, `USER_ID`, `SESSION_ID`, `PAYLOAD`, `HTTP`, `HTTP_MESSAGES`." },
@@ -44,7 +46,7 @@ export class LogEnvConfiguration {
{ key: "LOG_AUTHENTICATION", type: "boolean", description: "Log authentication debug messages - very noisy!" },
{ key: "LOG_VALIDATION_ERRORS", type: "boolean", description: "Enable logging of validation errors." },
{ key: "LOG_IMPORT_ERRORS", type: "boolean", description: "Enable logging of import errors." },
- ].orderBy((e) => e.key);
+ ], (e) => e.key);
}
get gatewayLogging(): GatewayLoggingConfigValue {
diff --git a/src/util/config/envTypes/WebRtcEnvConfiguration.ts b/src/util/config/envTypes/WebRtcEnvConfiguration.ts
index 07647da60..2bcc28bf8 100644
--- a/src/util/config/envTypes/WebRtcEnvConfiguration.ts
+++ b/src/util/config/envTypes/WebRtcEnvConfiguration.ts
@@ -16,14 +16,16 @@
along with this program. If not, see .
*/
+import { arrayOrderBy } from "@spacebar/util";
+
export class WebRtcEnvConfiguration {
static get schema() {
- return [
+ return arrayOrderBy([
{ key: "WRTC_PUBLIC_IP", type: "string", description: "Public IP of the server running the media server" },
{ key: "WRTC_PORT_MIN", type: "number", description: "Minimum port for WebRTC media server" },
{ key: "WRTC_PORT_MAX", type: "number", description: "Maximum port for WebRTC media server" },
{ key: "WRTC_LIBRARY", type: "string", description: "WebRTC library to use. One of `@spacebarchat/medooze-webrtc` (voice+video) or `@spacebarchat/mediasoup-webrtc` (voice only)" },
- ].orderBy((e) => e.key);
+ ], (e) => e.key);
}
get publicIp(): string {
diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts
index f17e8650d..355296b14 100644
--- a/src/util/util/extensions/Array.ts
+++ b/src/util/util/extensions/Array.ts
@@ -17,26 +17,49 @@
*/
declare global {
- interface Array {
- /**
- * @deprecated never use, idk why but I can't get rid of this without errors
- */
- remove(h: T): never;
- }
+ interface Array {
+ /**
+ * @deprecated never use, idk why but I can't get rid of this without errors
+ */
+ remove(h: T): never;
+ }
}
/* https://stackoverflow.com/a/50636286 */
export function arrayPartition(array: T[], filter: (elem: T) => boolean): [T[], T[]] {
- const pass: T[] = [],
- fail: T[] = [];
- array.forEach((e) => (filter(e) ? pass : fail).push(e));
- return [pass, fail];
+ const pass: T[] = [],
+ fail: T[] = [];
+ array.forEach((e) => (filter(e) ? pass : fail).push(e));
+ return [pass, fail];
}
+
export function arrayRemove(array: T[], item: T): void {
- const index = array.indexOf(item);
- if (index > -1) {
- array.splice(index, 1);
- }
+ const index = array.indexOf(item);
+ if (index > -1) {
+ array.splice(index, 1);
+ }
}
-// register extensions
+export type Comparable = number | string | bigint | Date | { valueOf(): number | string | bigint };
+
+export function arrayOrderBy(array: T[], keySelector: (elem: T) => Comparable): T[] {
+ return array.slice().sort((a, b) => {
+ const keyA = keySelector(a);
+ const keyB = keySelector(b);
+
+ if (keyA < keyB) return -1;
+ if (keyA > keyB) return 1;
+ return 0;
+ });
+}
+
+export function arrayOrderByDescending(array: T[], keySelector: (elem: T) => Comparable): T[] {
+ return array.slice().sort((a, b) => {
+ const keyA = keySelector(a);
+ const keyB = keySelector(b);
+
+ if (keyA > keyB) return -1;
+ if (keyA < keyB) return 1;
+ return 0;
+ });
+}
\ No newline at end of file