socket-function 0.42.0 → 0.44.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.42.0",
3
+ "version": "0.44.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
package/src/misc.ts CHANGED
@@ -293,6 +293,25 @@ export function sort<T>(arr: T[], sortKey: (obj: T) => unknown) {
293
293
  return arr;
294
294
  }
295
295
 
296
+ export class QueueLimited<T> {
297
+ private items: T[] = [];
298
+ private index = 0;
299
+ constructor(private readonly maxCount: number) { }
300
+
301
+ public push(item: T) {
302
+ this.index = (this.index + 1) % this.maxCount;
303
+ this.items[this.index] = item;
304
+ }
305
+
306
+ public getAllUnordered() {
307
+ return this.items;
308
+ }
309
+ public reset() {
310
+ this.items = [];
311
+ this.index = 0;
312
+ }
313
+ }
314
+
296
315
  export function binarySearchBasic<T, V>(array: T[], getVal: (val: T) => V, searchValue: V): number {
297
316
  return binarySearchIndex(array.length, i => compare(getVal(array[i]), searchValue));
298
317
  }
@@ -142,7 +142,9 @@ export async function startSocketServer(
142
142
  throw new Error(`Invalid cross domain request, ${JSON.stringify(host)} !== ${JSON.stringify(origin)} (also not in config.allowedHostnames ${JSON.stringify(config.allowHostnames)})`);
143
143
  }
144
144
  } catch (e) {
145
- console.error(e);
145
+ // NOTE: Just log, because invalid requests are guaranteed to happen, and
146
+ // there's no point wasting time looking at them.
147
+ console.log(e);
146
148
  return;
147
149
  }
148
150
  }