From 5f46f559b727c05d3dd846c2fc7345933d5fbc5a Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:25:32 +1000 Subject: Remove import to class-validator, fix listening on port message in bundle --- package-lock.json | 37 ++++++++++++++++++ package.json | 4 +- scripts/generate_schema.js | 89 -------------------------------------------- scripts/schema.js | 89 ++++++++++++++++++++++++++++++++++++++++++++ src/bundle/Server.ts | 1 + src/util/entities/Message.ts | 1 - 6 files changed, 130 insertions(+), 91 deletions(-) delete mode 100644 scripts/generate_schema.js create mode 100644 scripts/schema.js diff --git a/package-lock.json b/package-lock.json index 5a18f12a..df9cfbff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { + "@yukikaze-bot/erlpack": "*", "ajv": "^8.6.2", "ajv-formats": "^2.1.1", "bcrypt": "^5.0.1", @@ -62,6 +63,7 @@ "@aws-sdk/client-s3": "^3.178.0", "@sentry/node": "^7.13.0", "@sentry/tracing": "^7.13.0", + "@yukikaze-bot/erlpack": "^1.0.1", "amqplib": "^0.10.3" } }, @@ -1909,6 +1911,23 @@ "@types/node": "*" } }, + "node_modules/@yukikaze-bot/erlpack": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@yukikaze-bot/erlpack/-/erlpack-1.0.1.tgz", + "integrity": "sha512-PCJ2lGCf8DsQtrE411PY+NTsolK48l4InNn1kcBo0iUllKZYGLqeqXEWGA/INrmwanKcoYkU4pBySqUFLQDEoA==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.5", + "node-addon-api": "^4.0.0" + } + }, + "node_modules/@yukikaze-bot/erlpack/node_modules/node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==", + "optional": true + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -7825,6 +7844,24 @@ "@types/node": "*" } }, + "@yukikaze-bot/erlpack": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@yukikaze-bot/erlpack/-/erlpack-1.0.1.tgz", + "integrity": "sha512-PCJ2lGCf8DsQtrE411PY+NTsolK48l4InNn1kcBo0iUllKZYGLqeqXEWGA/INrmwanKcoYkU4pBySqUFLQDEoA==", + "optional": true, + "requires": { + "@mapbox/node-pre-gyp": "^1.0.5", + "node-addon-api": "^4.0.0" + }, + "dependencies": { + "node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==", + "optional": true + } + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", diff --git a/package.json b/package.json index 650b8c0a..b3536b9e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "postinstall": "npx patch-package", "start": "node dist/bundle/start.js", "build": "tsc -p .", - "generate:rights": "node scripts/rights.js" + "generate:rights": "node scripts/rights.js", + "generate:schema": "node scripts/schema.js" }, "main": "dist/bundle/index.js", "types": "src/bundle/index.ts", @@ -76,6 +77,7 @@ "@aws-sdk/client-s3": "^3.178.0", "@sentry/node": "^7.13.0", "@sentry/tracing": "^7.13.0", + "@yukikaze-bot/erlpack": "^1.0.1", "amqplib": "^0.10.3" }, "_moduleAliases": { diff --git a/scripts/generate_schema.js b/scripts/generate_schema.js deleted file mode 100644 index 01dd2146..00000000 --- a/scripts/generate_schema.js +++ /dev/null @@ -1,89 +0,0 @@ -// https://mermade.github.io/openapi-gui/# -// https://editor.swagger.io/ -const path = require("path"); -const fs = require("fs"); -const TJS = require("typescript-json-schema"); -require("missing-native-js-functions"); -const schemaPath = path.join(__dirname, "..", "assets", "schemas.json"); - -const settings = { - required: true, - ignoreErrors: true, - excludePrivate: true, - defaultNumberType: "integer", - noExtraProps: true, - defaultProps: false -}; -const compilerOptions = { - strictNullChecks: true -}; -const Excluded = [ - "DefaultSchema", - "Schema", - "EntitySchema", - "ServerResponse", - "Http2ServerResponse", - "global.Express.Response", - "Response", - "e.Response", - "request.Response", - "supertest.Response", - - // TODO: Figure out how to exclude schemas from node_modules? - "SomeJSONSchema", - "UncheckedPartialSchema", - "PartialSchema", - "UncheckedPropertiesSchema", - "PropertiesSchema", - "AsyncSchema", - "AnySchema", -]; - -function modify(obj) { - for (var k in obj) { - if (typeof obj[k] === "object" && obj[k] !== null) { - modify(obj[k]); - } - } -} - -function main() { - const program = TJS.programFromConfig("tsconfig.json") - const generator = TJS.buildGenerator(program, settings); - if (!generator || !program) return; - - let schemas = generator.getUserSymbols().filter((x) => (x.endsWith("Schema") || x.endsWith("Response")) && !Excluded.includes(x)); - console.log(schemas); - - var definitions = {}; - - for (const name of schemas) { - const part = TJS.generateSchema(program, name, settings, [], generator); - if (!part) continue; - - definitions = { ...definitions, [name]: { ...part } }; - } - - modify(definitions); - - fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4)); -} - -main(); - -function walk(dir) { - var results = []; - var list = fs.readdirSync(dir); - list.forEach(function (file) { - file = dir + "/" + file; - var stat = fs.statSync(file); - if (stat && stat.isDirectory()) { - /* Recurse into a subdirectory */ - results = results.concat(walk(file)); - } else { - if (!file.endsWith(".ts")) return; - results.push(file); - } - }); - return results; -} diff --git a/scripts/schema.js b/scripts/schema.js new file mode 100644 index 00000000..01dd2146 --- /dev/null +++ b/scripts/schema.js @@ -0,0 +1,89 @@ +// https://mermade.github.io/openapi-gui/# +// https://editor.swagger.io/ +const path = require("path"); +const fs = require("fs"); +const TJS = require("typescript-json-schema"); +require("missing-native-js-functions"); +const schemaPath = path.join(__dirname, "..", "assets", "schemas.json"); + +const settings = { + required: true, + ignoreErrors: true, + excludePrivate: true, + defaultNumberType: "integer", + noExtraProps: true, + defaultProps: false +}; +const compilerOptions = { + strictNullChecks: true +}; +const Excluded = [ + "DefaultSchema", + "Schema", + "EntitySchema", + "ServerResponse", + "Http2ServerResponse", + "global.Express.Response", + "Response", + "e.Response", + "request.Response", + "supertest.Response", + + // TODO: Figure out how to exclude schemas from node_modules? + "SomeJSONSchema", + "UncheckedPartialSchema", + "PartialSchema", + "UncheckedPropertiesSchema", + "PropertiesSchema", + "AsyncSchema", + "AnySchema", +]; + +function modify(obj) { + for (var k in obj) { + if (typeof obj[k] === "object" && obj[k] !== null) { + modify(obj[k]); + } + } +} + +function main() { + const program = TJS.programFromConfig("tsconfig.json") + const generator = TJS.buildGenerator(program, settings); + if (!generator || !program) return; + + let schemas = generator.getUserSymbols().filter((x) => (x.endsWith("Schema") || x.endsWith("Response")) && !Excluded.includes(x)); + console.log(schemas); + + var definitions = {}; + + for (const name of schemas) { + const part = TJS.generateSchema(program, name, settings, [], generator); + if (!part) continue; + + definitions = { ...definitions, [name]: { ...part } }; + } + + modify(definitions); + + fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4)); +} + +main(); + +function walk(dir) { + var results = []; + var list = fs.readdirSync(dir); + list.forEach(function (file) { + file = dir + "/" + file; + var stat = fs.statSync(file); + if (stat && stat.isDirectory()) { + /* Recurse into a subdirectory */ + results = results.concat(walk(file)); + } else { + if (!file.endsWith(".ts")) return; + results.push(file); + } + }); + return results; +} diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts index da810d9b..c85daf40 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts @@ -110,6 +110,7 @@ async function main() { app.use(Sentry.Handlers.tracingHandler()); } + server.listen(port); await Promise.all([api.start(), cdn.start(), gateway.start()]); if (Config.get().sentry.enabled) { diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 3a3dd5e4..be790502 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -25,7 +25,6 @@ import { Sticker } from "./Sticker"; import { Attachment } from "./Attachment"; import { BannedWords } from "../util"; import { HTTPError } from "lambert-server"; -import { ValidatorConstraint } from "class-validator"; export enum MessageType { DEFAULT = 0, -- cgit 1.4.1