diff --git a/package.json b/package.json index f20e31d40..c06a6f1b5 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "_moduleAliases": { "@spacebar/api": "dist/api", "@spacebar/cdn": "dist/cdn", + "@spacebar/extensions": "dist/extensions", "@spacebar/gateway": "dist/gateway", "@spacebar/util": "dist/util", "@spacebar/webrtc": "dist/webrtc", diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts index 305f81fcc..839ae6eeb 100644 --- a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts @@ -17,6 +17,7 @@ */ import { route } from "@spacebar/api"; +import { arrayRemove } from "@spacebar/extensions"; import { Channel, emitEvent, @@ -29,7 +30,6 @@ import { MessageReactionRemoveEmojiEvent, MessageReactionRemoveEvent, User, - arrayRemove, ReactionType, } from "@spacebar/util"; import { Request, Response, Router } from "express"; diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts index aea54b1d2..5a55c731e 100644 --- a/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts +++ b/src/api/routes/guilds/#guild_id/roles/#role_id/members.ts @@ -17,7 +17,8 @@ */ import { Router, Request, Response } from "express"; -import { DiscordApiErrors, Member, arrayPartition } from "@spacebar/util"; +import { arrayPartition } from "@spacebar/extensions"; +import { DiscordApiErrors, Member } from "@spacebar/util"; import { route } from "@spacebar/api"; const router = Router({ mergeParams: true }); diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts index acfe7f311..74c2d6d0f 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts @@ -17,10 +17,9 @@ */ import { fillMessageUrlEmbeds, randomString } from "@spacebar/api"; +import { mathLogBase, arrayDistributeSequentially } from "@spacebar/extensions"; import { Application, - arrayDistributeSequentially, - arrayPartition, Attachment, Channel, CloudAttachment, @@ -35,7 +34,6 @@ import { Guild, handleFile, HERE_MENTION, - mathLogBase, Member, Message, MessageCreateEvent, diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts index f242d6863..fa3d74f04 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts @@ -16,7 +16,8 @@ along with this program. If not, see . */ -import { arrayDistinctBy, arrayGroupBy, Config, EmbedCache, emitEvent, Message, MessageUpdateEvent, normalizeUrl, OrmUtils, sleep } from "@spacebar/util"; +import { sleep, arrayDistinctBy, arrayGroupBy } from "@spacebar/extensions"; +import { Config, EmbedCache, emitEvent, Message, MessageUpdateEvent, normalizeUrl, OrmUtils } from "@spacebar/util"; import { Embed, EmbedImage, EmbedType } from "@spacebar/schemas"; import * as cheerio from "cheerio"; import crypto from "node:crypto"; diff --git a/src/cdn/routes/avatars.ts b/src/cdn/routes/avatars.ts index bf2ab4371..6685ef7f7 100644 --- a/src/cdn/routes/avatars.ts +++ b/src/cdn/routes/avatars.ts @@ -16,12 +16,12 @@ along with this program. If not, see . */ +import crypto from "node:crypto"; import { Router, Response, Request } from "express"; +import { fileTypeFromBuffer } from "file-type"; import { Config } from "@spacebar/util"; import { storage } from "@spacebar/cdn"; -import { fileTypeFromBuffer } from "file-type"; import { HTTPError } from "lambert-server"; -import crypto from "node:crypto"; import { multer } from "../util/multer"; import { cache } from "../util/cache"; diff --git a/src/util/util/extensions/Array.ts b/src/extensions/Array.ts similarity index 100% rename from src/util/util/extensions/Array.ts rename to src/extensions/Array.ts diff --git a/src/util/util/extensions/Math.ts b/src/extensions/Math.ts similarity index 100% rename from src/util/util/extensions/Math.ts rename to src/extensions/Math.ts diff --git a/src/util/util/extensions/index.ts b/src/extensions/index.ts similarity index 100% rename from src/util/util/extensions/index.ts rename to src/extensions/index.ts diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 91fdcd887..74907f451 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -17,9 +17,9 @@ */ import { Capabilities, CLOSECODES, OPCODES, Payload, Send, setupListener, WebSocket } from "@spacebar/gateway"; +import { arrayGroupBy } from "@spacebar/extensions"; import { Application, - arrayGroupBy, Channel, checkToken, Config, diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts index 74b941ac6..0080e589c 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts @@ -16,7 +16,8 @@ along with this program. If not, see . */ -import { getDatabase, getPermission, listenEvent, Member, Role, Session, User, Presence, Channel, Permissions, arrayPartition, getMostRelevantSession } from "@spacebar/util"; +import { arrayPartition } from "@spacebar/extensions"; +import { getDatabase, getPermission, listenEvent, Member, Role, Session, User, Presence, Channel, Permissions, getMostRelevantSession } from "@spacebar/util"; import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send } from "@spacebar/gateway"; import murmur from "murmurhash-js/murmurhash3_gc"; import { check } from "./instanceOf"; diff --git a/src/gateway/util/Utils.ts b/src/gateway/util/Utils.ts index ebf7ae023..208806224 100644 --- a/src/gateway/util/Utils.ts +++ b/src/gateway/util/Utils.ts @@ -1,4 +1,23 @@ -import { Event, Session, sleep, TimeSpan, VoiceState } from "@spacebar/util"; +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2026 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import { sleep } from "@spacebar/extensions"; +import { Event, Session, TimeSpan, VoiceState } from "@spacebar/util"; import { WebSocket } from "./WebSocket"; import { OPCODES } from "./Constants"; import { Send } from "./Send"; diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index aea911eb5..0cea637e1 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -17,6 +17,7 @@ */ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm"; +import { arrayRemove } from "@spacebar/extensions"; import { Config, GuildWelcomeScreen, Snowflake, handleFile } from ".."; import { Ban } from "./Ban"; import { BaseClass } from "./BaseClass"; @@ -30,7 +31,6 @@ import { Template } from "./Template"; import { User } from "./User"; import { VoiceState } from "./VoiceState"; import { Webhook } from "./Webhook"; -import { arrayRemove } from "@spacebar/util"; // TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0} // TODO: guild_scheduled_events // TODO: stage_instances diff --git a/src/util/util/index.ts b/src/util/util/index.ts index f6de6a955..2c028e1d4 100644 --- a/src/util/util/index.ts +++ b/src/util/util/index.ts @@ -17,7 +17,6 @@ */ export * from "./ApiError"; -export * from "./extensions/Array"; export * from "./BitField"; //export * from "./Categories"; export * from "./cdn"; @@ -52,7 +51,6 @@ export * from "./Gifs"; export * from "./Application"; export * from "./NameValidation"; export * from "../../schemas/HelperTypes"; -export * from "./extensions"; export * from "./Random"; export * from "./Url"; export * from "./Version"; diff --git a/src/util/util/ipc/listener/RabbitMqSingleListener.ts b/src/util/util/ipc/listener/RabbitMqSingleListener.ts index 7e5867acc..d221cbb8c 100644 --- a/src/util/util/ipc/listener/RabbitMqSingleListener.ts +++ b/src/util/util/ipc/listener/RabbitMqSingleListener.ts @@ -18,12 +18,13 @@ import EventEmitter from "node:events"; import { randomUUID } from "node:crypto"; -import { BaseEventListener } from "./BaseEventListener"; -import { arraySum, EVENT, Event, EventOpts, sleep } from "@spacebar/util"; import amqp, { Channel, ChannelModel } from "amqplib"; -import { ProcessLifecycle } from "../../ProcessLifecycle"; -import { Monitoring } from "../../../monitoring/Monitoring"; import { Gauge } from "prom-client"; +import { sleep, arraySum } from "@spacebar/extensions"; +import { EVENT, Event, EventOpts } from "@spacebar/util"; +import { Monitoring } from "../../../monitoring/Monitoring"; +import { ProcessLifecycle } from "../../ProcessLifecycle"; +import { BaseEventListener } from "./BaseEventListener"; export class RabbitMqSingleListener extends BaseEventListener { static openListenersMetric: Gauge; diff --git a/src/util/util/ipc/listener/UnixSocketListener.ts b/src/util/util/ipc/listener/UnixSocketListener.ts index 50ffe2b09..cb9ea96b7 100644 --- a/src/util/util/ipc/listener/UnixSocketListener.ts +++ b/src/util/util/ipc/listener/UnixSocketListener.ts @@ -19,10 +19,11 @@ import EventEmitter from "node:events"; import fs from "node:fs"; import net, { Server } from "node:net"; -import { BaseEventListener } from "./BaseEventListener"; -import { arraySum, EVENT, Event, EventOpts } from "@spacebar/util"; -import { ProcessLifecycle } from "../../ProcessLifecycle"; import { Gauge } from "prom-client"; +import { arraySum } from "@spacebar/extensions"; +import { EVENT, Event, EventOpts } from "@spacebar/util"; +import { BaseEventListener } from "./BaseEventListener"; +import { ProcessLifecycle } from "../../ProcessLifecycle"; import { Monitoring } from "../../../monitoring/Monitoring"; export class UnixSocketListener extends BaseEventListener { diff --git a/src/util/util/ipc/writer/RabbitMqSingleWriter.ts b/src/util/util/ipc/writer/RabbitMqSingleWriter.ts index ad00aa2b5..96e820367 100644 --- a/src/util/util/ipc/writer/RabbitMqSingleWriter.ts +++ b/src/util/util/ipc/writer/RabbitMqSingleWriter.ts @@ -16,10 +16,11 @@ along with this program. If not, see . */ -import { BaseEventWriter } from "./BaseEventWriter"; import amqp, { Channel, ChannelModel } from "amqplib"; -import { Event, sleep } from "@spacebar/util"; +import { sleep } from "@spacebar/extensions"; +import { Event } from "@spacebar/util"; import { ProcessLifecycle } from "../../ProcessLifecycle"; +import { BaseEventWriter } from "./BaseEventWriter"; export class RabbitMqSingleWriter extends BaseEventWriter { private readonly host: string; diff --git a/tsconfig.json b/tsconfig.json index f7648dbb5..19e71deb6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,12 +32,21 @@ // "baseUrl": "./src/", //deprecated "paths": { //"*": ["./src/*"], + "@spacebar/api": ["./src/api"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/api*": ["./src/api*"], + "@spacebar/extensions": ["./src/extensions"], // Required for stable tsc, typescript-go doesn't need this + "@spacebar/extensions*": ["./src/extensions*"], + "@spacebar/gateway": ["./src/gateway"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/gateway*": ["./src/gateway*"], + "@spacebar/cdn": ["./src/cdn"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/cdn*": ["./src/cdn*"], + "@spacebar/util": ["./src/util"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/util*": ["./src/util*"], + "@spacebar/webrtc": ["./src/webrtc"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/webrtc*": ["./src/webrtc*"], + "@spacebar/schemas": ["./src/schemas"], // Required for stable tsc, typescript-go doesn't need this "@spacebar/schemas*": ["./src/schemas*"], + "lambert-server": ["./src/util/util/lambert-server"], // Required for stable tsc, typescript-go doesn't need this "lambert-server*": ["./src/util/util/lambert-server*"], } /* Specify a set of entries that re-map imports to additional lookup locations. */, "rootDir": "./src", // Required as of TypeScript 7