diff --git a/package.json b/package.json index ba6b0de..0eec6ec 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "express-session": "^1.17.3", "ky": "^0.33.3", "lodash-es": "^4.17.21", + "mysql2": "^3.6.0", "pinia": "^2.1.4", "reflect-metadata": "^0.1.13", "tslib": "^2.6.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1351606..53c207d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -47,6 +47,9 @@ dependencies: lodash-es: specifier: ^4.17.21 version: 4.17.21 + mysql2: + specifier: ^3.6.0 + version: 3.6.0 pinia: specifier: ^2.1.4 version: 2.1.4(typescript@5.1.6)(vue@3.3.4) @@ -58,7 +61,7 @@ dependencies: version: 2.6.1 typeorm: specifier: ^0.3.17 - version: 0.3.17(ts-node@10.9.1) + version: 0.3.17(mysql2@3.6.0)(ts-node@10.9.1) vue: specifier: ^3.3.4 version: 3.3.4 @@ -1451,6 +1454,11 @@ packages: object-keys: 1.1.1 dev: true + /denque@2.1.0: + resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} + engines: {node: '>=0.10'} + dev: false + /depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -1989,6 +1997,12 @@ packages: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} dev: true + /generate-function@2.3.1: + resolution: {integrity: sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==} + dependencies: + is-property: 1.0.2 + dev: false + /get-caller-file@2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} @@ -2171,6 +2185,13 @@ packages: safer-buffer: 2.1.2 dev: false + /iconv-lite@0.6.3: + resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} + engines: {node: '>=0.10.0'} + dependencies: + safer-buffer: 2.1.2 + dev: false + /ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} dev: false @@ -2329,6 +2350,10 @@ packages: engines: {node: '>=8'} dev: true + /is-property@1.0.2: + resolution: {integrity: sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==} + dev: false + /is-regex@1.1.4: resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==} engines: {node: '>= 0.4'} @@ -2460,6 +2485,10 @@ packages: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} dev: true + /long@5.2.3: + resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + dev: false + /lru-cache@6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} engines: {node: '>=10'} @@ -2467,6 +2496,16 @@ packages: yallist: 4.0.0 dev: true + /lru-cache@7.18.3: + resolution: {integrity: sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==} + engines: {node: '>=12'} + dev: false + + /lru-cache@8.0.5: + resolution: {integrity: sha512-MhWWlVnuab1RG5/zMRRcVGXZLCXrZTgfwMikgzCegsPnG62yDQo5JnqKkrK4jO5iKqDAZGItAqN5CtKBCBWRUA==} + engines: {node: '>=16.14'} + dev: false + /magic-string@0.30.2: resolution: {integrity: sha512-lNZdu7pewtq/ZvWUp9Wpf/x7WzMTsR26TWV03BRZrXFsv+BI6dy8RAiKgm1uM/kyR0rCfUcqvOlXKG66KhIGug==} engines: {node: '>=12'} @@ -2580,6 +2619,20 @@ packages: resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==} dev: true + /mysql2@3.6.0: + resolution: {integrity: sha512-EWUGAhv6SphezurlfI2Fpt0uJEWLmirrtQR7SkbTHFC+4/mJBrPiSzHESHKAWKG7ALVD6xaG/NBjjd1DGJGQQQ==} + engines: {node: '>= 8.0'} + dependencies: + denque: 2.1.0 + generate-function: 2.3.1 + iconv-lite: 0.6.3 + long: 5.2.3 + lru-cache: 8.0.5 + named-placeholders: 1.1.3 + seq-queue: 0.0.5 + sqlstring: 2.3.3 + dev: false + /mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} dependencies: @@ -2588,6 +2641,13 @@ packages: thenify-all: 1.6.0 dev: false + /named-placeholders@1.1.3: + resolution: {integrity: sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==} + engines: {node: '>=12.0.0'} + dependencies: + lru-cache: 7.18.3 + dev: false + /nanoid@3.3.6: resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} @@ -3121,6 +3181,10 @@ packages: - supports-color dev: false + /seq-queue@0.0.5: + resolution: {integrity: sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==} + dev: false + /serve-static@1.15.0: resolution: {integrity: sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==} engines: {node: '>= 0.8.0'} @@ -3226,6 +3290,11 @@ packages: resolution: {integrity: sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==} dev: true + /sqlstring@2.3.3: + resolution: {integrity: sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==} + engines: {node: '>= 0.6'} + dev: false + /statuses@2.0.1: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} @@ -3487,7 +3556,7 @@ packages: is-typed-array: 1.1.12 dev: true - /typeorm@0.3.17(ts-node@10.9.1): + /typeorm@0.3.17(mysql2@3.6.0)(ts-node@10.9.1): resolution: {integrity: sha512-UDjUEwIQalO9tWw9O2A4GU+sT3oyoUXheHJy4ft+RFdnRdQctdQ34L9SqE2p7LdwzafHx1maxT+bqXON+Qnmig==} engines: {node: '>= 12.9.0'} hasBin: true @@ -3555,6 +3624,7 @@ packages: dotenv: 16.3.1 glob: 8.1.0 mkdirp: 2.1.6 + mysql2: 3.6.0 reflect-metadata: 0.1.13 sha.js: 2.4.11 ts-node: 10.9.1(@types/node@18.17.0)(typescript@5.1.6) diff --git a/server/index.ts b/server/index.ts index b904887..e782055 100644 --- a/server/index.ts +++ b/server/index.ts @@ -3,13 +3,15 @@ import 'reflect-metadata'; import { BasicQueryDTO } from './api/index.js'; import { validate } from 'class-validator'; import express, { type Request, type Response } from "express" -import { AppDataSource } from "./data_source" -import dotenv from "dotenv"; +import { AppDataSource } from "./data_source.js" import session from "express-session"; import path from 'node:path'; +import { LiteHashDRBG } from './util/LiteHashDRBG.js'; +import { simpleSerialize } from './util/simpleSerialize.js'; export async function test() { console.log("Hello World!"); + console.log(process.env.GAME_DB_HOST); const dto = new BasicQueryDTO(); dto.command = 'None'; @@ -18,6 +20,23 @@ export async function test() { const result = await validate(dto); console.log(result); //must be integer가 나타나야함 + + const rawRng = new LiteHashDRBG(simpleSerialize( + 'haha', + 'hoho' + )); + + const arr: Promise[] = []; + let j = 0; + for(let i = 0; i < 100; i += 1){ + arr.push(rawRng.nextBits(32).then((v) => { + console.log(`${j}: ${i}`); + j += 1; + return v; + })); + } + + await Promise.all(arr); } @@ -28,8 +47,8 @@ const ownConfig = { port: Number(process.env.SERVER_PORT), } +/* AppDataSource.initialize().then(async () => { - // create express app const app = express() app.use(session({ @@ -47,5 +66,5 @@ AppDataSource.initialize().then(async () => { console.log(`Express server has started on port ${ownConfig.port}`) }).catch(error => console.log(error)) - +*/ export default {}; \ No newline at end of file diff --git a/server/util/JosaUtil.ts b/server/util/JosaUtil.ts index a707ef6..2f61674 100644 --- a/server/util/JosaUtil.ts +++ b/server/util/JosaUtil.ts @@ -1,4 +1,4 @@ -import { unwrap_err } from "./unwrap_err"; +import { unwrap_err } from "./unwrap_err.js"; // https://github.com/coxcore/postposition 의 php 버전을 다시 typescript로 재 작성 const KO_START_CODE = 44032; diff --git a/server/util/LiteHashDRBG.ts b/server/util/LiteHashDRBG.ts index 6303736..d5b4f82 100644 --- a/server/util/LiteHashDRBG.ts +++ b/server/util/LiteHashDRBG.ts @@ -1,11 +1,10 @@ -import type { RNG } from "./RNG"; +import type { RNG } from "./RNG.js"; -import { sha512 } from './sha2'; +import { sha512 } from './sha2.js'; -import { convertBytesLikeToUint8Array } from "./convertBytesLikeToUint8Array"; -import type { BytesLike } from "./BytesLike"; -import { unwrap } from "./unwrap"; -import { delay } from "./delay"; +import { convertBytesLikeToUint8Array } from "./convertBytesLikeToUint8Array.js"; +import type { BytesLike } from "./BytesLike.js"; +import { delay } from "./delay.js"; const maxRngSupportBit = 53; const maxInt = 0x1f_ffff_ffff_ffff; // NOTE: b 0, 10000110011, 11...11 @@ -194,10 +193,10 @@ export class LiteHashDRBG implements RNG { await delay(0); const nextBlock = await waiter; - if (nextBlockWait instanceof Promise) { + if (nextBlockWait) { nextBlockWait(); } - return unwrap(nextBlock); + return nextBlock!; } public async nextBits(bits: number, baseBytes?: number): Promise { @@ -207,7 +206,7 @@ export class LiteHashDRBG implements RNG { const bytes = (bits + 7) >> 3; const headBits = bits & 0x7; - const result = this.nextBytes(bytes, baseBytes); + const result = await this.nextBytes(bytes, baseBytes); if (headBits === 0) { return result; } diff --git a/server/util/RandUtil.ts b/server/util/RandUtil.ts index d627d4a..f662114 100644 --- a/server/util/RandUtil.ts +++ b/server/util/RandUtil.ts @@ -5,30 +5,30 @@ export class RandUtil { } - public nextFloat1(): number { + public nextFloat1(): Promise { return this.rng.nextFloat1(); } - public nextRange(min: number, max: number): number { + public async nextRange(min: number, max: number): Promise { const range = max - min; - return this.nextFloat1() * (range) + min; + return await this.nextFloat1() * (range) + min; } - public nextRangeInt(min: number, max: number): number { + public async nextRangeInt(min: number, max: number): Promise { const range = max - min; - return this.rng.nextInt(range) + min; + return await this.rng.nextInt(range) + min; } - public nextInt(max?: number): number { + public nextInt(max?: number): Promise { return this.rng.nextInt(max); } - public nextBit(): boolean { - const view = new DataView(this.rng.nextBits(1) as ArrayBufferLike); + public async nextBit(): Promise { + const view = new DataView(await this.rng.nextBits(1) as ArrayBufferLike); return view.getUint8(0) != 0; } - public nextBool(prob = 0.5): boolean { + public async nextBool(prob = 0.5): Promise { if (prob >= 1) { return true; } @@ -38,10 +38,10 @@ export class RandUtil { if (prob <= 0){ return false; } - return this.nextFloat1() < prob; + return await this.nextFloat1() < prob; } - public shuffle(srcArray: T[]): T[] { + public async shuffle(srcArray: T[]): Promise { const cnt = srcArray.length; if(cnt === 0){ return []; @@ -52,7 +52,7 @@ export class RandUtil { const result: T[] = Array.from(srcArray); for (let srcIdx = 0; srcIdx < cnt; srcIdx += 1) { - const destIdx = this.rng.nextInt(cnt - srcIdx - 1) + srcIdx; + const destIdx = await this.rng.nextInt(cnt - srcIdx - 1) + srcIdx; if(srcIdx === destIdx){ continue; } @@ -64,12 +64,12 @@ export class RandUtil { //Object는 integer key에 예외가 있어 shuffleAssoc은 없음 - public choice(items: T[] | Record | Set): T { + public async choice(items: T[] | Record | Set): Promise { if (items instanceof Array) { if(items.length === 0){ throw new Error('Empty items'); } - const idx = this.rng.nextInt(items.length - 1); + const idx = await this.rng.nextInt(items.length - 1); return items[idx]; } @@ -77,10 +77,10 @@ export class RandUtil { return this.choice(Array.from(items.values())); } - return items[this.choice(Array.from(Object.keys(items)))]; + return items[await this.choice(Array.from(Object.keys(items)))]; } - public choiceUsingWeight(items: Record): string | number { + public async choiceUsingWeight(items: Record): Promise { if(Object.keys(items).length === 0){ throw new Error('Empty items'); } @@ -92,7 +92,7 @@ export class RandUtil { sum += value; } - let rd = this.nextFloat1() * sum; + let rd = await this.nextFloat1() * sum; for (const [item, value] of Object.entries(items)) { if (value <= 0) { @@ -111,7 +111,7 @@ export class RandUtil { throw new Error('Unreacheable'); } - public choiceUsingWeightPair(items: [T, number][]): T { + public async choiceUsingWeightPair(items: [T, number][]): Promise { if(items.length === 0){ throw new Error('Empty items'); } @@ -123,7 +123,7 @@ export class RandUtil { sum += value; } - let rd = this.nextFloat1() * sum; + let rd = await this.nextFloat1() * sum; for (const [item, value] of items) { if (value <= 0) { diff --git a/server/util/combineArray.ts b/server/util/combineArray.ts index 7400bea..9facda0 100644 --- a/server/util/combineArray.ts +++ b/server/util/combineArray.ts @@ -1,4 +1,4 @@ -import { combineObject } from "./combineObject"; +import { combineObject } from "./combineObject.js"; export function combineArray(array: V[][], columnList: K[]): Record[] { diff --git a/server/util/convertBytesLikeToArrayBuffer.ts b/server/util/convertBytesLikeToArrayBuffer.ts index e98688c..edf76a3 100644 --- a/server/util/convertBytesLikeToArrayBuffer.ts +++ b/server/util/convertBytesLikeToArrayBuffer.ts @@ -1,4 +1,4 @@ -import type { BytesLike } from "./BytesLike"; +import type { BytesLike } from "./BytesLike.js"; export function convertBytesLikeToArrayBuffer(data: BytesLike, encodeUTF8 = true): ArrayBuffer{ if (data instanceof ArrayBuffer) { diff --git a/server/util/convertBytesLikeToUint8Array.ts b/server/util/convertBytesLikeToUint8Array.ts index 269175c..45769f8 100644 --- a/server/util/convertBytesLikeToUint8Array.ts +++ b/server/util/convertBytesLikeToUint8Array.ts @@ -1,4 +1,4 @@ -import type { BytesLike } from "./BytesLike"; +import type { BytesLike } from "./BytesLike.js"; export function convertBytesLikeToUint8Array(data: BytesLike, encodeUTF8 = true): Uint8Array { if (data instanceof Uint8Array) { diff --git a/server/util/convertSearch초성.ts b/server/util/convertSearch초성.ts index 6fdc545..13ff32a 100644 --- a/server/util/convertSearch초성.ts +++ b/server/util/convertSearch초성.ts @@ -1,5 +1,5 @@ -import { automata초성All } from "./automata초성"; -import { filter초성withAlphabet } from "./filter초성withAlphabet"; +import { automata초성All } from "./automata초성.js"; +import { filter초성withAlphabet } from "./filter초성withAlphabet.js"; export function convertSearch초성(text: string): string[]{ const [filteredTextH, filteredTextA] = filter초성withAlphabet(text.replace(/\s+/g, "")); diff --git a/server/util/isBrightColor.ts b/server/util/isBrightColor.ts index 6ecfe59..acfbbea 100644 --- a/server/util/isBrightColor.ts +++ b/server/util/isBrightColor.ts @@ -1,5 +1,5 @@ -import { unwrap } from ".//unwrap"; -import { hexToRgb } from ".//hexToRgb"; +import { unwrap } from ".//unwrap.js"; +import { hexToRgb } from "./hexToRgb.js"; export function isBrightColor(color: string): boolean { const cv = unwrap(hexToRgb(color)); diff --git a/server/util/mb_strimwidth.ts b/server/util/mb_strimwidth.ts index 39d621c..f096c5e 100644 --- a/server/util/mb_strimwidth.ts +++ b/server/util/mb_strimwidth.ts @@ -1,4 +1,4 @@ -import { mb_strwidth } from ".//mb_strwidth"; +import { mb_strwidth } from ".//mb_strwidth.js"; /** * mb_strimwidth diff --git a/server/util/merge2DArrToObjectArr.ts b/server/util/merge2DArrToObjectArr.ts index 15340d4..eb77aea 100644 --- a/server/util/merge2DArrToObjectArr.ts +++ b/server/util/merge2DArrToObjectArr.ts @@ -1,5 +1,5 @@ -import type { ValuesOf } from "./defs"; +import type { ValuesOf } from "./defs.js"; import { zip } from "lodash-es"; export function merge2DArrToObjectArr>(column: (keyof T)[], list: ValuesOf[][]): T[]{ diff --git a/server/util/unwrap.ts b/server/util/unwrap.ts index c795977..cac7a63 100644 --- a/server/util/unwrap.ts +++ b/server/util/unwrap.ts @@ -1,5 +1,5 @@ -import type { Nullable } from './Nullable'; -import { NotNullExpected } from "./NotNullExpected"; +import type { Nullable } from './Nullable.js'; +import { NotNullExpected } from "./NotNullExpected.js"; export function unwrap(result: Nullable): T { if (result === null || result === undefined) { diff --git a/server/util/unwrap_any.ts b/server/util/unwrap_any.ts index 04158f7..683e614 100644 --- a/server/util/unwrap_any.ts +++ b/server/util/unwrap_any.ts @@ -1,5 +1,5 @@ -import type { Nullable } from ".//Nullable"; -import { NotNullExpected } from ".//NotNullExpected"; +import type { Nullable } from ".//Nullable.js"; +import { NotNullExpected } from ".//NotNullExpected.js"; export function unwrap_any(result: Nullable): T { diff --git a/server/util/unwrap_err.ts b/server/util/unwrap_err.ts index dcf63b3..7e0fe0e 100644 --- a/server/util/unwrap_err.ts +++ b/server/util/unwrap_err.ts @@ -1,4 +1,4 @@ -import type { Nullable } from ".//Nullable"; +import type { Nullable } from ".//Nullable.js"; type ErrType = { new(msg?: string): T }