summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-17 09:56:51 +0100
committerRory& <root@rory.gay>2025-12-17 11:04:16 +0100
commit9bf4e59301bab7bb0d209fd51d4c43833238c3dc (patch)
tree18f0e74376397d87245bd27d5fc3ac0268c28d5f
parentUpdate workspace.xml after rebase (diff)
downloadserver-ts-9bf4e59301bab7bb0d209fd51d4c43833238c3dc.tar.xz
Fix extension cleanup stuff from Mathium05
-rw-r--r--src/util/config/envTypes/ConfigurationEnvConfiguration.ts6
-rw-r--r--src/util/config/envTypes/LogEnvConfiguration.ts6
-rw-r--r--src/util/config/envTypes/WebRtcEnvConfiguration.ts6
-rw-r--r--src/util/util/extensions/Array.ts53
4 files changed, 50 insertions, 21 deletions
diff --git a/src/util/config/envTypes/ConfigurationEnvConfiguration.ts b/src/util/config/envTypes/ConfigurationEnvConfiguration.ts

index 131d96ff..4f6918d9 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 <https://www.gnu.org/licenses/>. */ +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 { "<li>**`single`**: Ignore database config outright</li>" + "</ul>", }, - ].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 c4bbbfa6..ab97503c 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 <https://www.gnu.org/licenses/>. */ +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 07647da6..2bcc28bf 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 <https://www.gnu.org/licenses/>. */ +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 f17e8650..355296b1 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts
@@ -17,26 +17,49 @@ */ declare global { - interface Array<T> { - /** - * @deprecated never use, idk why but I can't get rid of this without errors - */ - remove(h: T): never; - } + interface Array<T> { + /** + * @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<T>(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<T>(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); + } +} + +export type Comparable = number | string | bigint | Date | { valueOf(): number | string | bigint }; + +export function arrayOrderBy<T>(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; + }); } -// register extensions +export function arrayOrderByDescending<T>(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