From 8c137a42a25de78ced8e1fdd4ab2b07557488477 Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 16 Mar 2026 23:45:23 +0100 Subject: [PATCH] Clean up schemas some more --- assets/openapi.json | Bin 963479 -> 949503 bytes assets/schemas.json | Bin 426405 -> 415904 bytes scripts/schema.js | 66 +++++++++++++++++- .../uncategorised/MessageCreateSchema.ts | 5 +- .../uncategorised/WebhookExecuteSchema.ts | 5 +- src/util/entities/Session.ts | 2 - 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index 13e0249ab1ea061462b21247648e7a47963babe2..0e1b4fa4f0ca2ec32f9532109b59b02a62c706ee 100644 GIT binary patch delta 958 zcma)4Ye*DP6lP}bnVB7TZKcw+O{0`AAh7Gbs<9t(Sjr@3BgFzA2xdzH~QC)1NYqXo$os@{F=YKu%oF< zSgH(^h+DCc6gR!976fNtLN4(y_yt<U z5YjO;Agv|$YUy1JmiI^@jJ+?N!=P0J>`50=P|sF8IPyc(D3mO15vYDfjLZ0c)})&z z_9zBFh#6citV?>Elt+fXxd=nqOhs=UOF;K-WoMv6aN>e~nN?b|VL029?ZG>jvfEt6jubBh+YqBGD9j$r_3u{dEVzf^{ zsyP#tv>~YGE9NH=EQ5SZ?gqfVw;E_pFQmmutM&)95xCy_zQz3V!>e}OrAx7$**$`j!$=v$j z!+n^!nSA$t-#OnoXO{0b!0pEPW$yP#ZhN~os3>YI7>lS%^vQ6)w{F8mczsfm!CQ(R zg}_sMzBZjzsU@yez+#n9sr6jNBWw9q@E<`nAm0?~pmu`yK(Y}(56gSd3s5^Jw1elC z)k5Oy@ffeo|JF&4E8I-pNpHSox4OMA(%sPp^OyK_5bqQkG`$JKvclzQiR$h4hx=+@ zFZ`s6Mfrbwz}i}^IZ_DkHQ^AfS2_D|&Jag(hWME_SV&4)UAuiPzDD`wupI4D`?@>i zP;WRG3(G-8jwrEkZ)Y$RmOIs6IT(utLtO{MN-X-UlK#lo6IS*#H~Y3$S2z8&T^)_} zcZcPJ;aIRE7z@fFRXG&yjY7(SO0*ti1-*^m0f7R%1{Qg7oxxodO#jShK=Q6w0ksvj zT+katkHH?q?ZPJTPx7wxdw-4)h0&d2F@0w#Pk-ffpaGy8R&cy4lz}swLY%md-R3Tl z=lH{Q|CgJdwUQIJd7dY)6$`$B|LWHMi<}>vUkPi{f|}AU3~>nb7C|=jX@o=tS8ixl zH?kwM3KAk;k`~l?%_>4*Cyn&cePwBReK~@SP-VwHraAF1a!@{#xmAm=EBmJ`fx4r( z9;TOg42wC^W=MX@xxneiBB+lc8yWPYt^&p+f(5XcjY^674r*V^9*pGb z=!%Uo&NHb(a8DsSd@_OafF_v>Mn|z*TR<4Hu8aB5(~8^R!xVDD#jj};-}?p~V63!3 zwAOPtBLYgQo0knE;wQg|K)@MC9%gN*MK%xmTE(s^3Ayki5wu(%`^v zXR^gLE4ecyULd*~kCd_pBeZS!Rb-4qgP6>2!=jZfju|2&4-g_%K3uU9V4CwY1iQRa z0n|iLsbP1R%8tt&oJdX{z%7U^7zA%{8%&2A(FF-E zW?5;Iz#}I)-i@DQt*B8dLGPyhfgve*>kxLX2&8<2b3-D4x6tVT!})QXV|K>Q4$%$z ztJp^LIR4SXmUvU;#JFT9zr2Yz=duUWl7;17gXPONx5f-pb(FOylWo(rRs5@eGd-N@RS{l6)L$ zE?X>_-D=4El~Ns1I#u%0CCitbJ*4(2vEKgbklF#~T-NU)S>`wb@d;}Q#GkOV4)0G{ T=(5sfqsvZL2HBs=9J~4_jrTf7 diff --git a/assets/schemas.json b/assets/schemas.json index 9b3dd7bea879443e68d2580a066f0d576ec5a935..1458afdb2e11b479f886abddec6d417c04d80557 100644 GIT binary patch delta 959 zcmZWoYeR#BZflopE8V(Cme7_F{d7r1WtY{DZD6J7p9;aHRJ1M*Dx<;@ zPW46?XFn7osAa}M$XXB-WwriTQJ_K>C@P5pA)?Ort=5nJz31{i=efM6_n@!mx;HgI z_E+K9QCNXj2dIiYNvOdVu1D0cIkk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ngso>u8B<(1 zke2|Gw*WVz($){6=>!N!L{XBmE2 z;}YPNYJy?34|3Qu0Z7v&0A`C?y*vo#5&@ycFV0Os11|n72>8PapK<@n`6UtAtzl>v z5)hm!^1MyyTB#o@4RrAg7}(q>1QLOlrz(5~9Pa1MZ0H>H@LC2oen%*YfYKPH2(M#3 zMI1;!VG*bYDuo?UC3w3X~Co+ z3iY&=#{@^unyJ**Wj9_DH%tpUxKF+Fki^Q?VJs0eZY3e new RegExp(r))]; const Excluded = [...exclusionList.manual, ...exclusionList.manualRe.map((r) => new RegExp(r)), ...exclusionList.auto.map((r) => r.value)]; const Included = [...exclusionList.include, ...exclusionList.includeRe.map((r) => new RegExp(r))]; @@ -167,6 +169,14 @@ async function main() { }); //.sort((a,b) => a.localeCompare(b)); + // remove node modules once and for all + console.log("Removing schemas from node modules..."); + schemas = schemas.filter((x) => !generator.getSymbols(x)[0].fullyQualifiedName.includes("/node_modules/")); + + // for (const s of schemas) { + // console.log(generator.getSymbols(s)[0].symbol); + // } + const elapsedList = stepSw.getElapsedAndReset(); process.stdout.write("Done in " + yellowBright(elapsedList.totalMilliseconds + "." + elapsedList.microseconds) + " ms\n"); console.log("Found", yellowBright(schemas.length), "schemas to process."); @@ -189,7 +199,7 @@ async function main() { const schemaSw = Stopwatch.startNew(); for (const name of schemas) { process.stdout.write(`Processing schema ${name}... `); - const part = TJS.generateSchema(program, name, settings, [], generator); + let part = TJS.generateSchema(program, name, settings, [], generator); if (!part) continue; if (definitions[name]) { @@ -200,6 +210,12 @@ async function main() { continue; } + // part = removeKeysMatchingRecursive(part, /^__@annotationsKey.*/, 128); + // part = removeArrayValuesMatchingRecursive(part, /^__@annotationsKey.*/, 128); + const _matchesRegex = (r) => (k, v, _) => (typeof k === "string" && k.match(r)) || (typeof v === "string" && v.match(r)); + part = await removeAllMatchingRecursive(part, _matchesRegex(/__@annotationsKey/)); + part = await removeAllMatchingRecursive(part, _matchesRegex(/ToGuildSource/)); + if (process.env.WRITE_SCHEMA_DIR === "true") writePromises.push(async () => await fsp.writeFile(path.join("schemas_orig", `${name}.json`), JSON.stringify(part, null, 4))); // testing: @@ -380,4 +396,50 @@ function columnizedObjectDiff(a, b, trackEqual = false) { return diffs; } +async function removeAllMatchingRecursive(o, selector, maxDepth = 32, path = "$") { + // process.stdout.write("S"); + // console.log("scan @", path, "with depth", maxDepth, typeof o, o); + // await printEnd(path, path.length); + if (!o) return o; + for (const [k, v] of Object.entries(o)) { + if (selector(k, v, o)) { + process.stdout.write(yellowBright("R(" + gray(k) + " @ " + cyan(path) + ") ")); + delete o[k]; + } else if (maxDepth > 0 && typeof o != "string") { + process.stdout.write(gray(">")); + o[k] = await removeAllMatchingRecursive(o[k], selector, maxDepth - 1, path + "." + k); + process.stdout.write(cyan("\b \b")); + } + } + + return o; +} + main().then(() => {}); + +// this is broken, figure this out someday - would be really neat to have +async function printEnd(str, len) { + const width = process.stdout.columns || 80; + const height = process.stdout.rows || 25; + + const storePos = "\x1b[s"; + const restPos = "\x1b[u"; + const eraseAfter = "\x1b[0K"; + const eraseLine = "\x1b[2K"; + const down1 = "\x1b[1E"; + const up1 = "\x1b[1F"; + const setCol = (col) => `\x1b[${col}G`; + const setTopPos = (col) => `\x1b[1;${col}H`; + const setBottomPos = (col) => `\x1b[${height};${col}H`; + + const startColumn = Math.max(1, width - len + 1); + + process.stdout.write(`\n\n\n${up1}${up1}${up1}`); + // process.stdout.write(`${storePos}${down1}${eraseAfter}${setTopPos(startColumn)}${str}${restPos}`);//${up1}`); + process.stdout.write(`${storePos}${setCol(startColumn)}${str}${restPos}`); + await sleep(12); +} + +async function sleep(delay) { + return new Promise((res, rej) => setTimeout(res, delay)); +} diff --git a/src/schemas/uncategorised/MessageCreateSchema.ts b/src/schemas/uncategorised/MessageCreateSchema.ts index b9c8119e0..f13132919 100644 --- a/src/schemas/uncategorised/MessageCreateSchema.ts +++ b/src/schemas/uncategorised/MessageCreateSchema.ts @@ -57,10 +57,7 @@ export interface MessageCreateSchema { } | null; payload_json?: string; file?: { filename: string }; - /** - TODO: we should create an interface for attachments - TODO: OpenWAAO<-->attachment-style metadata conversion - **/ + // TODO: we should create an interface for attachments attachments?: (MessageCreateAttachment | MessageCreateCloudAttachment)[]; sticker_ids?: string[] | null; // null check: fixes Discord-Go components?: ActionRowComponent[] | null; // null check: fixes Discord-Go diff --git a/src/schemas/uncategorised/WebhookExecuteSchema.ts b/src/schemas/uncategorised/WebhookExecuteSchema.ts index 2d0fdbd43..147a2d1a8 100644 --- a/src/schemas/uncategorised/WebhookExecuteSchema.ts +++ b/src/schemas/uncategorised/WebhookExecuteSchema.ts @@ -35,10 +35,7 @@ export interface WebhookExecuteSchema { components?: any[]; file?: { filename: string }; payload_json?: string; - /** - TODO: we should create an interface for attachments - TODO: OpenWAAO<-->attachment-style metadata conversion - **/ + // TODO: we should create an interface for attachments attachments?: MessageCreateAttachment[]; flags?: number; thread_name?: string; diff --git a/src/util/entities/Session.ts b/src/util/entities/Session.ts index e6ada0d94..a5cdeb77f 100644 --- a/src/util/entities/Session.ts +++ b/src/util/entities/Session.ts @@ -24,8 +24,6 @@ import { Activity, ClientStatus, GatewaySession, GatewaySessionClientInfo, Statu import { randomUpperString } from "@spacebar/api"; import { DateBuilder, IpDataClient, TimeSpan } from "../util"; -//TODO we need to remove all sessions on server start because if the server crashes without closing websockets it won't delete them - @Entity({ name: "sessions", })