fix
This commit is contained in:
+23
-4
@@ -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,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;
|
||||
|
||||
@@ -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
@@ -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,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,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,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) {
|
||||
|
||||
@@ -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, ""));
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
import { mb_strwidth } from ".//mb_strwidth";
|
||||
import { mb_strwidth } from ".//mb_strwidth.js";
|
||||
|
||||
/**
|
||||
* mb_strimwidth
|
||||
|
||||
@@ -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[]{
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
import type { Nullable } from ".//Nullable";
|
||||
import type { Nullable } from ".//Nullable.js";
|
||||
|
||||
type ErrType<T> = { new(msg?: string): T }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user