@tradejs/cli 1.0.6 → 1.0.9

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.
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/timeWindow.ts
21
+ var timeWindow_exports = {};
22
+ __export(timeWindow_exports, {
23
+ resolveTimeWindow: () => resolveTimeWindow
24
+ });
25
+ module.exports = __toCommonJS(timeWindow_exports);
26
+ var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
27
+ var toEpochMs = (value) => {
28
+ if (value == null || value === "") {
29
+ return null;
30
+ }
31
+ const parsed = Number(value);
32
+ if (!Number.isFinite(parsed) || parsed <= 0) {
33
+ return null;
34
+ }
35
+ return parsed < 1e12 ? Math.trunc(parsed * 1e3) : Math.trunc(parsed);
36
+ };
37
+ var toPositiveNumber = (value) => {
38
+ if (value == null || value === "") {
39
+ return null;
40
+ }
41
+ const parsed = Number(value);
42
+ if (!Number.isFinite(parsed) || parsed <= 0) {
43
+ return null;
44
+ }
45
+ return parsed;
46
+ };
47
+ var resolveTimeWindow = ({
48
+ days,
49
+ startTime,
50
+ endTime,
51
+ nowMs = Date.now(),
52
+ defaultStartMs,
53
+ defaultEndMs
54
+ }) => {
55
+ const explicitStart = toEpochMs(startTime);
56
+ const explicitEnd = toEpochMs(endTime);
57
+ if (explicitStart != null || explicitEnd != null) {
58
+ const resolvedEnd2 = explicitEnd ?? defaultEndMs ?? nowMs;
59
+ const resolvedStart = explicitStart ?? defaultStartMs;
60
+ if (resolvedStart >= resolvedEnd2) {
61
+ throw new Error(
62
+ `Invalid time window: startTime (${resolvedStart}) must be less than endTime (${resolvedEnd2})`
63
+ );
64
+ }
65
+ return {
66
+ start: resolvedStart,
67
+ end: resolvedEnd2,
68
+ source: "explicit"
69
+ };
70
+ }
71
+ const resolvedDays = toPositiveNumber(days);
72
+ if (resolvedDays != null) {
73
+ const resolvedEnd2 = defaultEndMs ?? nowMs;
74
+ const resolvedStart = resolvedEnd2 - resolvedDays * ONE_DAY_MS;
75
+ if (resolvedStart >= resolvedEnd2) {
76
+ throw new Error(
77
+ `Invalid time window: computed start (${resolvedStart}) must be less than end (${resolvedEnd2})`
78
+ );
79
+ }
80
+ return {
81
+ start: Math.trunc(resolvedStart),
82
+ end: Math.trunc(resolvedEnd2),
83
+ source: "days"
84
+ };
85
+ }
86
+ const resolvedEnd = defaultEndMs ?? nowMs;
87
+ if (defaultStartMs >= resolvedEnd) {
88
+ throw new Error(
89
+ `Invalid default time window: start (${defaultStartMs}) must be less than end (${resolvedEnd})`
90
+ );
91
+ }
92
+ return {
93
+ start: Math.trunc(defaultStartMs),
94
+ end: Math.trunc(resolvedEnd),
95
+ source: "default"
96
+ };
97
+ };
98
+ // Annotate the CommonJS export names for ESM import in node:
99
+ 0 && (module.exports = {
100
+ resolveTimeWindow
101
+ });