From 5e8285ebf7a2d6336f8ffe9c45ea7b68d07f4afd Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 20 Sep 2024 18:57:26 +0100 Subject: [PATCH] funkyarray in package and in project??? --- server/index.ts | 2 +- server/objects/FunkyArray.ts | 77 ------------------------------------ server/objects/Session.ts | 2 +- 3 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 server/objects/FunkyArray.ts diff --git a/server/index.ts b/server/index.ts index f3af797..591081b 100644 --- a/server/index.ts +++ b/server/index.ts @@ -27,7 +27,7 @@ import FastifyFormBody from "@fastify/formbody"; import FastifyCookie from "@fastify/cookie"; import FastifyView from "@fastify/view"; import EJS from "ejs"; -import FunkyArray from "./objects/FunkyArray"; +import FunkyArray from "funky-array"; import RemoteUser from "./objects/RemoteUser"; import { MessageType } from "./enums/MessageType"; import Database from "./objects/Database"; diff --git a/server/objects/FunkyArray.ts b/server/objects/FunkyArray.ts deleted file mode 100644 index f906aaf..0000000 --- a/server/objects/FunkyArray.ts +++ /dev/null @@ -1,77 +0,0 @@ -export default class FunkyArray { - private items:Map = new Map(); - private itemKeys:Array = new Array(); - - private _getKeys() : Array { - const keyArray = new Array(); - let result:IteratorResult; - const iterator = this.items.keys(); - while (!(result = iterator.next()).done) { - keyArray.push(result.value); - } - return keyArray; - } - - public set(key:T, item:TT, regenerate:boolean = true) : TT { - this.items.set(key, item); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return item; - } - - public remove(key:T, regenerate:boolean = true) { - const success = this.items.delete(key); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return success; - } - - public removeFirst(regenerate:boolean = true) { - const success = this.items.delete(this.items.keys().next().value); - if (regenerate) { - this.itemKeys = this._getKeys(); - } - return success; - } - - public first() : TT { - return this.items.values().next().value; - } - - public get length() : number { - return this.items.size; - } - - public get(key:T) : TT | undefined { - return this.items.get(key); - } - - public has(key:T) : boolean { - return this.itemKeys.includes(key); - } - - public get keys() : Array { - return this.itemKeys; - } - - public forEach(callback: (value:TT) => void) { - return new Promise(async (resolve, reject) => { - if (this.items.size === 0) { - return resolve(true); - } - - try { - const iterator = this.items.values(); - let result:IteratorResult; - while (!(result = iterator.next()).done) { - await callback(result.value); - } - resolve(true); - } catch (e) { - reject(e); - } - }); - } -} \ No newline at end of file diff --git a/server/objects/Session.ts b/server/objects/Session.ts index 371135c..b292c6d 100644 --- a/server/objects/Session.ts +++ b/server/objects/Session.ts @@ -2,7 +2,7 @@ import Config from "./Config"; import FastifyCookie from "@fastify/cookie"; import FunkyArray from "funky-array"; import SessionUser from "./SessionUser"; -import { FastifyReply, FastifyRequest } from "fastify"; +import { FastifyReply } from "fastify"; import User from "../entities/User"; import { randomBytes } from "crypto"; import Gauge from "simple-prom/lib/objects/Gauge";