@discomedia/utils 1.0.59 → 1.0.60

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.
Files changed (41) hide show
  1. package/README.md +0 -2
  2. package/dist/index.cjs +0 -1378
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +0 -1378
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/package.json +1 -1
  7. package/dist/test.js +0 -225
  8. package/dist/test.js.map +1 -1
  9. package/dist/types/index.d.ts +0 -82
  10. package/dist/types/index.d.ts.map +1 -1
  11. package/dist/types/misc-utils.d.ts +0 -6
  12. package/dist/types/misc-utils.d.ts.map +1 -1
  13. package/dist/types/types/index.d.ts +0 -2
  14. package/dist/types/types/index.d.ts.map +1 -1
  15. package/dist/types-frontend/index.d.ts +0 -82
  16. package/dist/types-frontend/index.d.ts.map +1 -1
  17. package/dist/types-frontend/misc-utils.d.ts +0 -6
  18. package/dist/types-frontend/misc-utils.d.ts.map +1 -1
  19. package/dist/types-frontend/types/index.d.ts +0 -2
  20. package/dist/types-frontend/types/index.d.ts.map +1 -1
  21. package/package.json +1 -1
  22. package/dist/types/polygon-indices.d.ts +0 -85
  23. package/dist/types/polygon-indices.d.ts.map +0 -1
  24. package/dist/types/polygon.d.ts +0 -126
  25. package/dist/types/polygon.d.ts.map +0 -1
  26. package/dist/types/technical-analysis.d.ts +0 -90
  27. package/dist/types/technical-analysis.d.ts.map +0 -1
  28. package/dist/types/types/polygon-indices-types.d.ts +0 -190
  29. package/dist/types/types/polygon-indices-types.d.ts.map +0 -1
  30. package/dist/types/types/polygon-types.d.ts +0 -204
  31. package/dist/types/types/polygon-types.d.ts.map +0 -1
  32. package/dist/types-frontend/polygon-indices.d.ts +0 -85
  33. package/dist/types-frontend/polygon-indices.d.ts.map +0 -1
  34. package/dist/types-frontend/polygon.d.ts +0 -126
  35. package/dist/types-frontend/polygon.d.ts.map +0 -1
  36. package/dist/types-frontend/technical-analysis.d.ts +0 -90
  37. package/dist/types-frontend/technical-analysis.d.ts.map +0 -1
  38. package/dist/types-frontend/types/polygon-indices-types.d.ts +0 -190
  39. package/dist/types-frontend/types/polygon-indices-types.d.ts.map +0 -1
  40. package/dist/types-frontend/types/polygon-types.d.ts +0 -204
  41. package/dist/types-frontend/types/polygon-types.d.ts.map +0 -1
package/dist/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.0.59",
6
+ "version": "1.0.60",
7
7
  "author": "Disco Media",
8
8
  "description": "Utility functions used in Disco Media apps",
9
9
  "always-build-npm": true,
package/dist/test.js CHANGED
@@ -381,231 +381,6 @@ function getTradingDate(time) {
381
381
  return `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
382
382
  }
383
383
 
384
- /*
385
- How it works:
386
- `this.#head` is an instance of `Node` which keeps track of its current value and nests another instance of `Node` that keeps the value that comes after it. When a value is provided to `.enqueue()`, the code needs to iterate through `this.#head`, going deeper and deeper to find the last value. However, iterating through every single item is slow. This problem is solved by saving a reference to the last value as `this.#tail` so that it can reference it to add a new value.
387
- */
388
-
389
- class Node {
390
- value;
391
- next;
392
-
393
- constructor(value) {
394
- this.value = value;
395
- }
396
- }
397
-
398
- class Queue {
399
- #head;
400
- #tail;
401
- #size;
402
-
403
- constructor() {
404
- this.clear();
405
- }
406
-
407
- enqueue(value) {
408
- const node = new Node(value);
409
-
410
- if (this.#head) {
411
- this.#tail.next = node;
412
- this.#tail = node;
413
- } else {
414
- this.#head = node;
415
- this.#tail = node;
416
- }
417
-
418
- this.#size++;
419
- }
420
-
421
- dequeue() {
422
- const current = this.#head;
423
- if (!current) {
424
- return;
425
- }
426
-
427
- this.#head = this.#head.next;
428
- this.#size--;
429
- return current.value;
430
- }
431
-
432
- peek() {
433
- if (!this.#head) {
434
- return;
435
- }
436
-
437
- return this.#head.value;
438
-
439
- // TODO: Node.js 18.
440
- // return this.#head?.value;
441
- }
442
-
443
- clear() {
444
- this.#head = undefined;
445
- this.#tail = undefined;
446
- this.#size = 0;
447
- }
448
-
449
- get size() {
450
- return this.#size;
451
- }
452
-
453
- * [Symbol.iterator]() {
454
- let current = this.#head;
455
-
456
- while (current) {
457
- yield current.value;
458
- current = current.next;
459
- }
460
- }
461
-
462
- * drain() {
463
- while (this.#head) {
464
- yield this.dequeue();
465
- }
466
- }
467
- }
468
-
469
- function pLimit(concurrency) {
470
- let rejectOnClear = false;
471
-
472
- if (typeof concurrency === 'object') {
473
- ({concurrency, rejectOnClear = false} = concurrency);
474
- }
475
-
476
- validateConcurrency(concurrency);
477
-
478
- if (typeof rejectOnClear !== 'boolean') {
479
- throw new TypeError('Expected `rejectOnClear` to be a boolean');
480
- }
481
-
482
- const queue = new Queue();
483
- let activeCount = 0;
484
-
485
- const resumeNext = () => {
486
- // Process the next queued function if we're under the concurrency limit
487
- if (activeCount < concurrency && queue.size > 0) {
488
- activeCount++;
489
- queue.dequeue().run();
490
- }
491
- };
492
-
493
- const next = () => {
494
- activeCount--;
495
- resumeNext();
496
- };
497
-
498
- const run = async (function_, resolve, arguments_) => {
499
- // Execute the function and capture the result promise
500
- const result = (async () => function_(...arguments_))();
501
-
502
- // Resolve immediately with the promise (don't wait for completion)
503
- resolve(result);
504
-
505
- // Wait for the function to complete (success or failure)
506
- // We catch errors here to prevent unhandled rejections,
507
- // but the original promise rejection is preserved for the caller
508
- try {
509
- await result;
510
- } catch {}
511
-
512
- // Decrement active count and process next queued function
513
- next();
514
- };
515
-
516
- const enqueue = (function_, resolve, reject, arguments_) => {
517
- const queueItem = {reject};
518
-
519
- // Queue the internal resolve function instead of the run function
520
- // to preserve the asynchronous execution context.
521
- new Promise(internalResolve => { // eslint-disable-line promise/param-names
522
- queueItem.run = internalResolve;
523
- queue.enqueue(queueItem);
524
- }).then(run.bind(undefined, function_, resolve, arguments_)); // eslint-disable-line promise/prefer-await-to-then
525
-
526
- // Start processing immediately if we haven't reached the concurrency limit
527
- if (activeCount < concurrency) {
528
- resumeNext();
529
- }
530
- };
531
-
532
- const generator = (function_, ...arguments_) => new Promise((resolve, reject) => {
533
- enqueue(function_, resolve, reject, arguments_);
534
- });
535
-
536
- Object.defineProperties(generator, {
537
- activeCount: {
538
- get: () => activeCount,
539
- },
540
- pendingCount: {
541
- get: () => queue.size,
542
- },
543
- clearQueue: {
544
- value() {
545
- if (!rejectOnClear) {
546
- queue.clear();
547
- return;
548
- }
549
-
550
- const abortError = AbortSignal.abort().reason;
551
-
552
- while (queue.size > 0) {
553
- queue.dequeue().reject(abortError);
554
- }
555
- },
556
- },
557
- concurrency: {
558
- get: () => concurrency,
559
-
560
- set(newConcurrency) {
561
- validateConcurrency(newConcurrency);
562
- concurrency = newConcurrency;
563
-
564
- queueMicrotask(() => {
565
- // eslint-disable-next-line no-unmodified-loop-condition
566
- while (activeCount < concurrency && queue.size > 0) {
567
- resumeNext();
568
- }
569
- });
570
- },
571
- },
572
- map: {
573
- async value(iterable, function_) {
574
- const promises = Array.from(iterable, (value, index) => this(function_, value, index));
575
- return Promise.all(promises);
576
- },
577
- },
578
- });
579
-
580
- return generator;
581
- }
582
-
583
- function validateConcurrency(concurrency) {
584
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
585
- throw new TypeError('Expected `concurrency` to be a number from 1 and up');
586
- }
587
- }
588
-
589
- /**********************************************************************************
590
- * Polygon.io calls
591
- **********************************************************************************/
592
- // Constants from environment variables
593
- process.env.POLYGON_API_KEY;
594
- // Define concurrency limits per API
595
- const POLYGON_CONCURRENCY_LIMIT = 100;
596
- pLimit(POLYGON_CONCURRENCY_LIMIT);
597
-
598
- /**
599
- * Polygon Indices API Implementation
600
- *
601
- * This module provides functions to interact with the Polygon.io Indices API.
602
- */
603
- // Constants from environment variables
604
- const { ALPACA_INDICES_API_KEY } = process.env;
605
- // Define concurrency limits for API
606
- const POLYGON_INDICES_CONCURRENCY_LIMIT = 5;
607
- pLimit(POLYGON_INDICES_CONCURRENCY_LIMIT);
608
-
609
384
  function __classPrivateFieldSet(receiver, state, value, kind, f) {
610
385
  if (typeof state === "function" ? receiver !== state || true : !state.has(receiver))
611
386
  throw new TypeError("Cannot write private member to an object whose class did not declare it");