Fix extension cleanup stuff from Mathium05

This commit is contained in:
Rory&
2025-12-17 09:56:51 +01:00
parent 91221248d5
commit 9bf4e59301
4 changed files with 50 additions and 21 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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);
}
}
// register extensions
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;
});
}
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;
});
}