socket-function 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/callHTTPHandler.ts +1 -1
- package/src/misc.ts +9 -5
package/package.json
CHANGED
package/src/callHTTPHandler.ts
CHANGED
|
@@ -210,7 +210,7 @@ export async function httpCallHandler(request: http.IncomingMessage, response: h
|
|
|
210
210
|
|
|
211
211
|
} catch (e: any) {
|
|
212
212
|
console.log(`HTTP error (${request.method}) ${e.stack}`);
|
|
213
|
-
response.writeHead(500, String(e.message));
|
|
213
|
+
response.writeHead(500, String(e.message).replace(/[^\x20-\x7E]/g, ""));
|
|
214
214
|
} finally {
|
|
215
215
|
response.end();
|
|
216
216
|
}
|
package/src/misc.ts
CHANGED
|
@@ -295,12 +295,12 @@ export function sort<T>(arr: T[], sortKey: (obj: T) => unknown) {
|
|
|
295
295
|
|
|
296
296
|
export class QueueLimited<T> {
|
|
297
297
|
private items: T[] = [];
|
|
298
|
-
private
|
|
298
|
+
private nextIndex = 0;
|
|
299
299
|
constructor(private readonly maxCount: number) { }
|
|
300
300
|
|
|
301
301
|
public push(item: T): void {
|
|
302
|
-
this.
|
|
303
|
-
this.
|
|
302
|
+
this.items[this.nextIndex] = item;
|
|
303
|
+
this.nextIndex = (this.nextIndex + 1) % this.maxCount;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
public getAllUnordered(): T[] {
|
|
@@ -308,11 +308,15 @@ export class QueueLimited<T> {
|
|
|
308
308
|
}
|
|
309
309
|
public reset(): void {
|
|
310
310
|
this.items = [];
|
|
311
|
-
this.
|
|
311
|
+
this.nextIndex = 0;
|
|
312
|
+
}
|
|
313
|
+
public clear(): void {
|
|
314
|
+
this.reset();
|
|
312
315
|
}
|
|
313
316
|
public getOldest(): T | undefined {
|
|
314
317
|
if (this.items.length === 0) return undefined;
|
|
315
|
-
let index = this.
|
|
318
|
+
let index = this.nextIndex - 1;
|
|
319
|
+
|
|
316
320
|
if (index === -1) {
|
|
317
321
|
index += this.maxCount;
|
|
318
322
|
}
|