monorepo 버전 준비

## @strpc
기존 RPC를 package화

### @strpc/express
express의 middleware + router 결함

## @sammo
게임 전체
- server, client
- gateway_server, gateway_client
This commit is contained in:
2023-09-23 16:29:18 +00:00
parent 734e0cb7bf
commit e59f9a9659
197 changed files with 15458 additions and 3 deletions
+11
View File
@@ -0,0 +1,11 @@
import { combineObject } from "./combineObject.js";
export function combineArray<K extends string, V>(array: V[][], columnList: K[]): Record<K, V>[] {
const result: Record<K, V>[] = [];
for (const key of array.keys()) {
const item = array[key];
result[key] = combineObject(item, columnList);
}
return result;
}
@@ -0,0 +1,8 @@
export function combineObject<K extends string, V>(item: V[], columnList: K[]): Record<K, V> {
const newItem: Record<string, V> = {};
for (const columnIdx in columnList) {
const columnName = columnList[columnIdx];
newItem[columnName] = item[columnIdx];
}
return newItem;
}
@@ -0,0 +1,28 @@
import type { BytesLike, BufferSource } from "../types.js";
export function convertBytesLikeToUint8Array(data: string, encodeUTF8: boolean): Uint8Array;
export function convertBytesLikeToUint8Array(data: BufferSource | string): Uint8Array;
export function convertBytesLikeToUint8Array(data: BytesLike, encodeUTF8 = true): Uint8Array {
if (data instanceof Uint8Array) {
return data;
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
if (data instanceof SharedArrayBuffer) {
return new Uint8Array(data);
}
if (data instanceof Uint8Array) {
return data;
}
if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (typeof (data) === 'string') {
if(encodeUTF8){
return (new TextEncoder()).encode(data);
}
return new Uint8Array(data.split('').map(s=>s.codePointAt(0) as number));
}
throw new Error(`Unknown data type ${typeof (data)}`);
}
@@ -0,0 +1,9 @@
import type { IDItem } from "../types.js";
export function convertIDArray<T>(array: Iterable<T>): IDItem<T>[] {
const result: IDItem<T>[] = [];
for (const id of array) {
result.push({ id });
}
return result;
}
@@ -0,0 +1,10 @@
export function convertIterableToMap<T extends object, K extends keyof T, V extends T[K] & (string | number | symbol)>(
values: Iterable<T>,
key: K
): Map<V, T> {
const result = new Map<V, T>();
for (const obj of values) {
result.set(obj[key] as V, obj);
}
return result;
}
@@ -0,0 +1,7 @@
type Entries<T> = {
[K in keyof T]: [K, T[K]];
}[keyof T][];
export function entriesWithType<T extends object>(value: T): Entries<T>{
return Object.entries(value) as unknown as Entries<T>;
}
+5
View File
@@ -0,0 +1,5 @@
export * from "./combineObject.js";
export * from "./combineArray.js";
export * from "./convertBytesLikeToUint8Array.js";
export * from "./convertIDArray.js";
export * from "./convertIterableToMap.js"
@@ -0,0 +1,20 @@
import type { ValuesOf } from "../types.js";
import { zip } from "lodash-es";
export function merge2DArrToObjectArr<T extends Record<string, unknown>>(column: (keyof T)[], list: ValuesOf<T>[][]): T[]{
const result: T[] = [];
for(const rawItem of list){
const item: Record<string, unknown> = {};
if(column.length != rawItem.length){
throw `column과 item의 길이가 같지 않습니다: ${column.length} != ${list.length}, ${JSON.stringify(item)}`;
}
for(const [key, value] of zip(column, rawItem)){
item[key as string] = value;
}
result.push(item as T);
}
return result;
}
+35
View File
@@ -0,0 +1,35 @@
import { isString } from "lodash-es";
interface NameValuePair {
name: string,
value: string
}
export function mergeKVArray(array : NameValuePair[]):Record<string, string|string[]>{
const result:Record<string, string|string[]> = {};
for(const {name, value} of array){
if(!isString(name)){
throw new TypeError(`${name} is not string`);
}
if(!isString(value)){
throw new TypeError(`${value} is not string`);
}
if(name === '' || name === '[]'){
continue;
}
if(name.length > 2 && name.slice(-2) == '[]'){
const keyHead = name.slice(0, -2);
if(!(keyHead in result)){
result[keyHead] = [value];
}
else{
(result[keyHead] as string[]).push(value);
}
continue;
}
result[name] = value;
}
return result;
}