Initial commit

This commit is contained in:
Wroclaw 2023-05-11 06:03:22 +02:00
commit 1e63e008af
48 changed files with 12715 additions and 0 deletions

View file

@ -0,0 +1,20 @@
type queryType = {
type: "before" | "after" | "around",
id: string
} | {
type: null
};
/**
* Before, around, after pagination wrapper
*/
export default class baaPagination<T> {
readonly table: string;
readonly key: string;
constructor(table: string, key: string) {
this.table = table;
this.key = key;
}
}

11
server/utils/database.ts Normal file
View file

@ -0,0 +1,11 @@
import mysql from "mysql2/promise";
export const database = await mysql.createConnection({
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_SCHEMA,
});
export type data<T> = [T[], mysql.FieldPacket[]];

3
server/utils/isString.ts Normal file
View file

@ -0,0 +1,3 @@
export function isString(value: unknown): value is string {
return typeof value === "string";
}

View file

@ -0,0 +1 @@
export * from "../../utils/cookieSettings";

43
server/utils/snowflake.ts Normal file
View file

@ -0,0 +1,43 @@
export default class Snowflake {
static current_increment = 0n;
public static increment() {
this.current_increment = BigInt.asUintN(12, this.current_increment + 1n);
return this.current_increment;
}
state = 0n;
public set_timestamp(value: number | bigint) {
value = BigInt.asUintN(64 - 22, BigInt(value));
const state = BigInt.asUintN(22, this.state);
this.state = state + (value << 22n);
}
public set_machineid(value: number | bigint) {
value = BigInt.asUintN(12 - 17, BigInt(value));
const state = BigInt.asUintN(17, this.state) + (this.state >> 22n) << 22n;
this.state = state + (value << 12n);
}
public set_processid(value: number | bigint) {
value = BigInt.asUintN(17 - 12, BigInt(value));
const state = BigInt.asUintN(12, this.state) + (this.state >> 17n) << 17n;
this.state = state + (value << 12n);
}
public set_increment(value: number | bigint) {
value = BigInt.asUintN(12 - 0, BigInt(value));
const state = (this.state >> 12n) << 12n;
this.state = state + (value << 0n);
}
constructor() {
this.set_timestamp(Date.now());
this.set_processid(1);
this.set_increment(Snowflake.increment());
}
public toString() {
return this.state.toString();
}
}