This commit is contained in:
2023-08-05 16:03:31 +00:00
parent 92a67315f3
commit 743ab3e1aa
16 changed files with 138 additions and 49 deletions
+1
View File
@@ -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",
+72 -2
View File
@@ -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)
+23 -4
View File
@@ -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<Uint8Array>[] = [];
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 {};
+1 -1
View File
@@ -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;
+8 -9
View File
@@ -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<Uint8Array> {
@@ -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;
}
+19 -19
View File
@@ -5,30 +5,30 @@ export class RandUtil {
}
public nextFloat1(): number {
public nextFloat1(): Promise<number> {
return this.rng.nextFloat1();
}
public nextRange(min: number, max: number): number {
public async nextRange(min: number, max: number): Promise<number> {
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<number> {
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<number> {
return this.rng.nextInt(max);
}
public nextBit(): boolean {
const view = new DataView(this.rng.nextBits(1) as ArrayBufferLike);
public async nextBit(): Promise<boolean> {
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<boolean> {
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<T>(srcArray: T[]): T[] {
public async shuffle<T>(srcArray: T[]): Promise<T[]> {
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<T>(items: T[] | Record<string | number, T> | Set<T>): T {
public async choice<T>(items: T[] | Record<string | number, T> | Set<T>): Promise<T> {
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, number>): string | number {
public async choiceUsingWeight(items: Record<string | number, number>): Promise<string | number> {
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<T>(items: [T, number][]): T {
public async choiceUsingWeightPair<T>(items: [T, number][]): Promise<T> {
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) {
+1 -1
View File
@@ -1,4 +1,4 @@
import { combineObject } from "./combineObject";
import { combineObject } from "./combineObject.js";
export function combineArray<K extends string, V>(array: V[][], columnList: K[]): Record<K, V>[] {
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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) {
+2 -2
View File
@@ -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, ""));
+2 -2
View File
@@ -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));
+1 -1
View File
@@ -1,4 +1,4 @@
import { mb_strwidth } from ".//mb_strwidth";
import { mb_strwidth } from ".//mb_strwidth.js";
/**
* mb_strimwidth
+1 -1
View File
@@ -1,5 +1,5 @@
import type { ValuesOf } from "./defs";
import type { ValuesOf } from "./defs.js";
import { zip } from "lodash-es";
export function merge2DArrToObjectArr<T extends Record<string, unknown>>(column: (keyof T)[], list: ValuesOf<T>[][]): T[]{
+2 -2
View File
@@ -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<T>(result: Nullable<T>): T {
if (result === null || result === undefined) {
+2 -2
View File
@@ -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<T>(result: Nullable<unknown>): T {
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Nullable } from ".//Nullable";
import type { Nullable } from ".//Nullable.js";
type ErrType<T> = { new(msg?: string): T }