@tradejs/cli 3.1.29-beta.290 → 3.1.29-beta.292

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,74 @@
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/researchMetricSnapshot.ts
21
+ var researchMetricSnapshot_exports = {};
22
+ __export(researchMetricSnapshot_exports, {
23
+ decodeResearchMetricSnapshot: () => decodeResearchMetricSnapshot,
24
+ encodeResearchMetricSnapshot: () => encodeResearchMetricSnapshot,
25
+ validatePermanentResearchMetrics: () => validatePermanentResearchMetrics
26
+ });
27
+ module.exports = __toCommonJS(researchMetricSnapshot_exports);
28
+ var import_node_crypto = require("crypto");
29
+ var import_node_zlib = require("zlib");
30
+ var MAX_BYTES = 256 * 1024 * 1024;
31
+ var hash = (bytes) => (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
32
+ var validatePermanentResearchMetrics = (value) => {
33
+ if (!value || typeof value !== "object") return;
34
+ for (const [key, child] of Object.entries(value)) {
35
+ if (["matchedPairs", "tradeRows", "allProjectedLeaves"].includes(key) && Array.isArray(child) && child.length)
36
+ throw new Error(`Temporary payload ${key} is not a permanent metric`);
37
+ if (key === "trades" && Array.isArray(child) && child.some(
38
+ (row) => row && typeof row === "object" && ("signalId" in row || "entryTimestamp" in row)
39
+ ))
40
+ throw new Error("Temporary trade records are not permanent metrics");
41
+ validatePermanentResearchMetrics(child);
42
+ }
43
+ };
44
+ var encodeResearchMetricSnapshot = (metrics) => {
45
+ validatePermanentResearchMetrics(metrics);
46
+ const bytes = Buffer.from(JSON.stringify(metrics));
47
+ if (bytes.length > MAX_BYTES)
48
+ throw new Error("Metric snapshot exceeds decoded size limit");
49
+ return {
50
+ schema: "tradejs-metric-snapshot/v1",
51
+ encoding: "gzip+base64",
52
+ decodedBytes: bytes.length,
53
+ sha256: hash(bytes),
54
+ payload: (0, import_node_zlib.gzipSync)(bytes, { level: 9 }).toString("base64")
55
+ };
56
+ };
57
+ var decodeResearchMetricSnapshot = (snapshot) => {
58
+ if (!snapshot || typeof snapshot !== "object" || !("schema" in snapshot) || snapshot.schema !== "tradejs-metric-snapshot/v1" || !("encoding" in snapshot) || snapshot.encoding !== "gzip+base64" || !("decodedBytes" in snapshot) || typeof snapshot.decodedBytes !== "number" || !Number.isSafeInteger(snapshot.decodedBytes) || snapshot.decodedBytes <= 0 || snapshot.decodedBytes > MAX_BYTES || !("sha256" in snapshot) || typeof snapshot.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(snapshot.sha256) || !("payload" in snapshot) || typeof snapshot.payload !== "string")
59
+ throw new Error("Invalid metric snapshot envelope");
60
+ const bytes = (0, import_node_zlib.gunzipSync)(Buffer.from(snapshot.payload, "base64"), {
61
+ maxOutputLength: snapshot.decodedBytes
62
+ });
63
+ if (bytes.length !== snapshot.decodedBytes || hash(bytes) !== snapshot.sha256)
64
+ throw new Error("Metric snapshot checksum or size mismatch");
65
+ const metrics = JSON.parse(bytes.toString("utf8"));
66
+ validatePermanentResearchMetrics(metrics);
67
+ return metrics;
68
+ };
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ decodeResearchMetricSnapshot,
72
+ encodeResearchMetricSnapshot,
73
+ validatePermanentResearchMetrics
74
+ });