@adaptic/utils 0.0.902 → 0.0.904
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/dist/index.cjs +108 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +97 -45
- package/dist/index.mjs.map +1 -1
- package/dist/test.js +56 -12
- package/dist/test.js.map +1 -1
- package/dist/types/alpaca/legacy/positions.d.ts.map +1 -1
- package/dist/types/display-manager.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/polygon.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { clearLine, cursorTo } from 'readline';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
1
|
import { format, sub, set, add, startOfDay, endOfDay, isBefore } from 'date-fns';
|
|
5
2
|
import { formatInTimeZone, toZonedTime, fromZonedTime } from 'date-fns-tz';
|
|
6
3
|
import require$$0$3, { EventEmitter } from 'events';
|
|
@@ -491,6 +488,33 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
491
488
|
const chalk = createChalk();
|
|
492
489
|
createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
493
490
|
|
|
491
|
+
// Detect whether we are running in a Node.js environment with a real stdout.
|
|
492
|
+
// In browsers (or environments without process.stdout) all terminal / fs
|
|
493
|
+
// operations become no-ops so the library can be safely imported client-side.
|
|
494
|
+
const isNode = typeof process !== "undefined" &&
|
|
495
|
+
typeof process.stdout !== "undefined" &&
|
|
496
|
+
typeof process.stdout.write === "function";
|
|
497
|
+
// Lazy-load Node-only dependencies so bundlers can tree-shake / stub them.
|
|
498
|
+
// chalk is kept as a static import (ESM-only in v5) — Rollup handles it.
|
|
499
|
+
// readline, fs, and path are loaded at runtime only in Node.
|
|
500
|
+
let clearLine;
|
|
501
|
+
let cursorTo;
|
|
502
|
+
let fs;
|
|
503
|
+
let path;
|
|
504
|
+
if (isNode) {
|
|
505
|
+
try {
|
|
506
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
507
|
+
const readline = require("readline");
|
|
508
|
+
clearLine = readline.clearLine;
|
|
509
|
+
cursorTo = readline.cursorTo;
|
|
510
|
+
fs = require("fs");
|
|
511
|
+
path = require("path");
|
|
512
|
+
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
513
|
+
}
|
|
514
|
+
catch {
|
|
515
|
+
// Silently degrade — all operations will be no-ops.
|
|
516
|
+
}
|
|
517
|
+
}
|
|
494
518
|
class DisplayManager {
|
|
495
519
|
static instance;
|
|
496
520
|
promptText = "";
|
|
@@ -508,9 +532,19 @@ class DisplayManager {
|
|
|
508
532
|
* Logs a message while preserving the prompt at the bottom
|
|
509
533
|
*/
|
|
510
534
|
log(message, options) {
|
|
535
|
+
if (!isNode) {
|
|
536
|
+
// In browser environments, fall back to console
|
|
537
|
+
const level = options?.type === "error"
|
|
538
|
+
? "error"
|
|
539
|
+
: options?.type === "warn"
|
|
540
|
+
? "warn"
|
|
541
|
+
: "log";
|
|
542
|
+
console[level](message);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
511
545
|
// Clear the current prompt line
|
|
512
|
-
clearLine(process.stdout, 0);
|
|
513
|
-
cursorTo(process.stdout, 0);
|
|
546
|
+
clearLine?.(process.stdout, 0);
|
|
547
|
+
cursorTo?.(process.stdout, 0);
|
|
514
548
|
// Format the timestamp
|
|
515
549
|
const date = new Date();
|
|
516
550
|
const timestamp = date.toLocaleString("en-US", {
|
|
@@ -521,11 +555,13 @@ class DisplayManager {
|
|
|
521
555
|
// Build the log message
|
|
522
556
|
let logMessage = `[${timestamp}]${options?.source ? ` [${options.source}] ` : ""}${account ? ` [${account}] ` : ""}${symbol ? ` [${symbol}] ` : ""}${message}`;
|
|
523
557
|
// Add color based on type
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
558
|
+
if (chalk) {
|
|
559
|
+
if (options?.type === "error") {
|
|
560
|
+
logMessage = chalk.red(logMessage);
|
|
561
|
+
}
|
|
562
|
+
else if (options?.type === "warn") {
|
|
563
|
+
logMessage = chalk.yellow(logMessage);
|
|
564
|
+
}
|
|
529
565
|
}
|
|
530
566
|
// Write the log message
|
|
531
567
|
process.stdout.write(logMessage + "\n");
|
|
@@ -545,6 +581,8 @@ class DisplayManager {
|
|
|
545
581
|
* Writes a log entry to a symbol-specific log file
|
|
546
582
|
*/
|
|
547
583
|
writeSymbolLog(symbol, date, logMessage, options) {
|
|
584
|
+
if (!fs || !path)
|
|
585
|
+
return;
|
|
548
586
|
try {
|
|
549
587
|
// Create logs directory if it doesn't exist
|
|
550
588
|
if (!fs.existsSync("logs")) {
|
|
@@ -571,6 +609,8 @@ class DisplayManager {
|
|
|
571
609
|
* Writes a log entry to a generic log file when no symbol is provided
|
|
572
610
|
*/
|
|
573
611
|
writeGenericLog(date, logMessage, options) {
|
|
612
|
+
if (!fs || !path)
|
|
613
|
+
return;
|
|
574
614
|
try {
|
|
575
615
|
// Create logs directory if it doesn't exist
|
|
576
616
|
if (!fs.existsSync("logs")) {
|
|
@@ -595,11 +635,15 @@ class DisplayManager {
|
|
|
595
635
|
}
|
|
596
636
|
}
|
|
597
637
|
writePrompt() {
|
|
638
|
+
if (!isNode)
|
|
639
|
+
return;
|
|
598
640
|
process.stdout.write(this.promptText);
|
|
599
641
|
}
|
|
600
642
|
clearPrompt() {
|
|
601
|
-
|
|
602
|
-
|
|
643
|
+
if (!isNode)
|
|
644
|
+
return;
|
|
645
|
+
clearLine?.(process.stdout, 0);
|
|
646
|
+
cursorTo?.(process.stdout, 0);
|
|
603
647
|
}
|
|
604
648
|
restorePrompt() {
|
|
605
649
|
this.writePrompt();
|