diff --git a/scripts/build.js b/scripts/build.js
deleted file mode 100644
index dfe7dfa1..00000000
--- a/scripts/build.js
+++ /dev/null
@@ -1,72 +0,0 @@
-const { execSync } = require("child_process");
-const path = require("path");
-const fs = require("fs");
-const { getSystemErrorMap } = require("util");
-const { argv } = require("process");
-
-var steps = 2, i = 0;
-if (argv.includes("clean")) steps++;
-if (argv.includes("copyonly")) steps--;
-const dirs = ["api", "util", "cdn", "gateway", "bundle"];
-const verbose = argv.includes("verbose") || argv.includes("v");
-
-var copyRecursiveSync = function(src, dest) {
- if(verbose) console.log(`cpsync: ${src} -> ${dest}`);
- var exists = fs.existsSync(src);
- if(!exists){
- console.log(src + " doesn't exist, not copying!");
- return;
- }
- var stats = exists && fs.statSync(src);
- var isDirectory = exists && stats.isDirectory();
- if (isDirectory) {
- fs.mkdirSync(dest, {recursive: true});
- fs.readdirSync(src).forEach(function(childItemName) {
- copyRecursiveSync(path.join(src, childItemName),
- path.join(dest, childItemName));
- });
- } else {
- fs.copyFileSync(src, dest);
- }
- };
-
-if (argv.includes("clean")) {
- console.log(`[${++i}/${steps}] Cleaning...`);
- dirs.forEach((a) => {
- var d = "../" + a + "/dist";
- if (fs.existsSync(d)) {
- fs.rmSync(d, { recursive: true });
- if (verbose) console.log(`Deleted ${d}!`);
- }
- });
-}
-
-console.log(`[${++i}/${steps}] Copying src files...`);
-copyRecursiveSync(path.join(__dirname, "..", "..", "api", "assets"), path.join(__dirname, "..", "dist", "api", "assets"));
-copyRecursiveSync(path.join(__dirname, "..", "..", "api", "client_test"), path.join(__dirname, "..", "dist", "api", "client_test"));
-copyRecursiveSync(path.join(__dirname, "..", "..", "api", "locales"), path.join(__dirname, "..", "dist", "api", "locales"));
-dirs.forEach((a) => {
- copyRecursiveSync("../" + a + "/src", "dist/" + a + "/src");
- if (verbose) console.log(`Copied ${"../" + a + "/dist"} -> ${"dist/" + a + "/src"}!`);
-});
-
-if (!argv.includes("copyonly")) {
- console.log(`[${++i}/${steps}] Compiling src files ...`);
-
- console.log(
- execSync(
- 'node "' +
- path.join(__dirname, "..", "node_modules", "typescript", "lib", "tsc.js") +
- '" -p "' +
- path.join(__dirname, "..") +
- '"',
- {
- cwd: path.join(__dirname, ".."),
- shell: true,
- env: process.env,
- encoding: "utf8"
- }
- )
- );
-}
-
diff --git a/scripts/droptables.sql b/scripts/droptables.sql
deleted file mode 100644
index 8a852048..00000000
--- a/scripts/droptables.sql
+++ /dev/null
@@ -1,31 +0,0 @@
-DROP TABLE applications;
-DROP TABLE attachments;
-DROP TABLE audit_logs;
-DROP TABLE bans;
-DROP TABLE connected_accounts;
-DROP TABLE emojis;
-DROP TABLE invites;
-DROP TABLE member_roles;
-DROP TABLE message_channel_mentions;
-DROP TABLE message_role_mentions;
-DROP TABLE message_stickers;
-DROP TABLE message_user_mentions;
-DROP TABLE messages;
-DROP TABLE rate_limits;
-DROP TABLE read_states;
-DROP TABLE recipients;
-DROP TABLE relationships;
-DROP TABLE roles;
-DROP TABLE sessions;
-DROP TABLE stickers;
-DROP TABLE team_members;
-DROP TABLE teams;
-DROP TABLE templates;
-DROP TABLE voice_states;
-DROP TABLE webhooks;
-DROP TABLE channels;
-DROP TABLE members;
-DROP TABLE guilds;
-DROP TABLE client_release;
--- DROP TABLE users;
--- DROP TABLE config;
\ No newline at end of file
diff --git a/scripts/generate_openapi.js b/scripts/generate_openapi.js
deleted file mode 100644
index c9de9fa6..00000000
--- a/scripts/generate_openapi.js
+++ /dev/null
@@ -1,137 +0,0 @@
-// https://mermade.github.io/openapi-gui/#
-// https://editor.swagger.io/
-const getRouteDescriptions = require("../jest/getRouteDescriptions");
-const path = require("path");
-const fs = require("fs");
-require("missing-native-js-functions");
-
-const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
-const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
-const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
-const specification = JSON.parse(fs.readFileSync(openapiPath, { encoding: "utf8" }));
-
-function combineSchemas(schemas) {
- var definitions = {};
-
- for (const name in schemas) {
- definitions = {
- ...definitions,
- ...schemas[name].definitions,
- [name]: { ...schemas[name], definitions: undefined, $schema: undefined }
- };
- }
-
- for (const key in definitions) {
- specification.components.schemas[key] = definitions[key];
- delete definitions[key].additionalProperties;
- delete definitions[key].$schema;
- const definition = definitions[key];
-
- if (typeof definition.properties === "object") {
- for (const property of Object.values(definition.properties)) {
- if (Array.isArray(property.type)) {
- if (property.type.includes("null")) {
- property.type = property.type.find((x) => x !== "null");
- property.nullable = true;
- }
- }
- }
- }
- }
-
- return definitions;
-}
-
-function getTag(key) {
- return key.match(/\/([\w-]+)/)[1];
-}
-
-function apiRoutes() {
- const routes = getRouteDescriptions();
-
- const tags = Array.from(routes.keys()).map((x) => getTag(x));
- specification.tags = [...specification.tags.map((x) => x.name), ...tags].unique().map((x) => ({ name: x }));
-
- routes.forEach((route, pathAndMethod) => {
- const [p, method] = pathAndMethod.split("|");
- const path = p.replace(/:(\w+)/g, "{$1}");
-
- let obj = specification.paths[path]?.[method] || {};
- if (!obj.description) {
- const permission = route.permission ? `##### Requires the \`\`${route.permission}\`\` permission\n` : "";
- const event = route.test?.event ? `##### Fires a \`\`${route.test?.event}\`\` event\n` : "";
- obj.description = permission + event;
- }
- if (route.body) {
- obj.requestBody = {
- required: true,
- content: {
- "application/json": {
- schema: { $ref: `#/components/schemas/${route.body}` }
- }
- }
- }.merge(obj.requestBody);
- }
- if (!obj.responses) {
- obj.responses = {
- default: {
- description: "not documented"
- }
- };
- }
- if (route.test?.response) {
- const status = route.test.response.status || 200;
- let schema = {
- allOf: [
- {
- $ref: `#/components/schemas/${route.test.response.body}`
- },
- {
- example: route.test.body
- }
- ]
- };
- if (!route.test.body) schema = schema.allOf[0];
-
- obj.responses = {
- [status]: {
- ...(route.test.response.body
- ? {
- description: obj.responses[status].description || "",
- content: {
- "application/json": {
- schema: schema
- }
- }
- }
- : {})
- }
- }.merge(obj.responses);
- delete obj.responses.default;
- }
- if (p.includes(":")) {
- obj.parameters = p.match(/:\w+/g)?.map((x) => ({
- name: x.replace(":", ""),
- in: "path",
- required: true,
- schema: { type: "string" },
- description: x.replace(":", "")
- }));
- }
- obj.tags = [...(obj.tags || []), getTag(p)].unique();
-
- specification.paths[path] = { ...specification.paths[path], [method]: obj };
- });
-}
-
-function main() {
- combineSchemas(schemas);
- apiRoutes();
-
- fs.writeFileSync(
- openapiPath,
- JSON.stringify(specification, null, 4).replaceAll("#/definitions", "#/components/schemas").replaceAll("bigint", "number")
- );
-}
-
-main();
diff --git a/scripts/generate_schema.js b/scripts/generate_schema.js
index b56c3fbc..01dd2146 100644
--- a/scripts/generate_schema.js
+++ b/scripts/generate_schema.js
@@ -48,14 +48,7 @@ function modify(obj) {
}
function main() {
- const files = [
- ...walk(path.join(__dirname, "..", "src", "routes")),
- ...walk(path.join(__dirname, "..", "..", "util", "src")),
- ];
- const program = TJS.getProgramFromFiles(
- files,
- compilerOptions
- );
+ const program = TJS.programFromConfig("tsconfig.json")
const generator = TJS.buildGenerator(program, settings);
if (!generator || !program) return;
diff --git a/scripts/install.js b/scripts/install.js
deleted file mode 100644
index db9dadbc..00000000
--- a/scripts/install.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const path = require("path");
-const fs = require("fs");
-const parts = ["api", "util", "cdn", "gateway"];
-
-const bundle = require("../package.json");
-
-for (const part of parts) {
- const { devDependencies, dependencies } = require(path.join(
- "..",
- "..",
- part,
- "package.json"
- ));
- bundle.devDependencies = { ...bundle.devDependencies, ...devDependencies };
- bundle.dependencies = { ...bundle.dependencies, ...dependencies };
- delete bundle.dependencies["@fosscord/util"];
-}
-
-fs.writeFileSync(
- path.join(__dirname, "..", "package.json"),
- JSON.stringify(bundle, null, "\t"),
- { encoding: "utf8" }
-);
diff --git a/scripts/migrate_db_engine.js b/scripts/migrate_db_engine.js
deleted file mode 100644
index 79e9d86f..00000000
--- a/scripts/migrate_db_engine.js
+++ /dev/null
@@ -1,109 +0,0 @@
-const { config } = require("dotenv");
-config();
-const { createConnection } = require("typeorm");
-const { initDatabase } = require("../../dist/util/Database");
-require("missing-native-js-functions");
-const {
- Application,
- Attachment,
- Ban,
- Channel,
- ConfigEntity,
- ConnectedAccount,
- Emoji,
- Guild,
- Invite,
- Member,
- Message,
- ReadState,
- Recipient,
- Relationship,
- Role,
- Sticker,
- Team,
- TeamMember,
- Template,
- User,
- VoiceState,
- Webhook,
-} = require("../../dist/entities/index");
-
-async function main() {
- if (!process.env.TO) throw new Error("TO database env connection string not set");
-
- // manually arrange them because of foreign keys
- const entities = [
- ConfigEntity,
- User,
- Guild,
- Channel,
- Invite,
- Role,
- Ban,
- Application,
- Emoji,
- ConnectedAccount,
- Member,
- ReadState,
- Recipient,
- Relationship,
- Sticker,
- Team,
- TeamMember,
- Template,
- VoiceState,
- Webhook,
- Message,
- Attachment,
- ];
-
- const oldDB = await initDatabase();
-
- const type = process.env.TO.includes("://") ? process.env.TO.split(":")[0]?.replace("+srv", "") : "sqlite";
- const isSqlite = type.includes("sqlite");
-
- // @ts-ignore
- const newDB = await createConnection({
- type,
- url: isSqlite ? undefined : process.env.TO,
- database: isSqlite ? process.env.TO : undefined,
- entities,
- name: "new",
- synchronize: true,
- });
- let i = 0;
-
- try {
- for (const entity of entities) {
- const entries = await oldDB.manager.find(entity);
-
- // @ts-ignore
- console.log("migrating " + entries.length + " " + entity.name + " ...");
-
- for (const entry of entries) {
- console.log(i++);
-
- try {
- await newDB.manager.insert(entity, entry);
- } catch (error) {
- try {
- if (!entry.id) throw new Error("object doesn't have a unique id: " + entry);
- await newDB.manager.update(entity, { id: entry.id }, entry);
- } catch (error) {
- console.error("couldn't migrate " + i + " " + entity.name, error);
- }
- }
- }
-
- // @ts-ignore
- console.log("migrated " + entries.length + " " + entity.name);
- }
- } catch (error) {
- console.error(error.message);
- }
-
- console.log("SUCCESS migrated all data");
- await newDB.close();
-}
-
-main().caught();
diff --git a/scripts/rights.js b/scripts/rights.js
index 289071f6..a4eb0b31 100644
--- a/scripts/rights.js
+++ b/scripts/rights.js
@@ -1,3 +1,4 @@
+require('module-alias/register');
const { Rights } = require("..");
const allRights = new Rights(1).bitfield;
|