bulltrackers-module 1.0.253 → 1.0.254
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Checks availability of root data via the Root Data Index.
|
|
3
|
-
* REFACTORED: Now
|
|
3
|
+
* REFACTORED: Now supports granular 'userType' checks (Speculator vs Normal).
|
|
4
4
|
*/
|
|
5
5
|
const { normalizeName } = require('../utils/utils');
|
|
6
6
|
|
|
@@ -10,11 +10,34 @@ const INDEX_COLLECTION = process.env.ROOT_DATA_AVAILABILITY_COLLECTION || 'syste
|
|
|
10
10
|
function checkRootDependencies(calcManifest, rootDataStatus) {
|
|
11
11
|
const missing = [];
|
|
12
12
|
if (!calcManifest.rootDataDependencies) return { canRun: true, missing };
|
|
13
|
+
|
|
14
|
+
const userType = calcManifest.userType || 'all';
|
|
15
|
+
|
|
13
16
|
for (const dep of calcManifest.rootDataDependencies) {
|
|
14
|
-
if (dep === 'portfolio'
|
|
17
|
+
if (dep === 'portfolio') {
|
|
18
|
+
if (userType === 'speculator') {
|
|
19
|
+
if (!rootDataStatus.speculatorPortfolio) missing.push('speculatorPortfolio');
|
|
20
|
+
} else if (userType === 'normal') {
|
|
21
|
+
if (!rootDataStatus.normalPortfolio) missing.push('normalPortfolio');
|
|
22
|
+
} else {
|
|
23
|
+
// 'all', 'aggregate', or 'n/a' -> Check if ANY portfolio data exists
|
|
24
|
+
// This satisfies the "either/or" requirement for generic calculations
|
|
25
|
+
if (!rootDataStatus.hasPortfolio) missing.push('portfolio');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (dep === 'history') {
|
|
29
|
+
if (userType === 'speculator') {
|
|
30
|
+
if (!rootDataStatus.speculatorHistory) missing.push('speculatorHistory');
|
|
31
|
+
} else if (userType === 'normal') {
|
|
32
|
+
if (!rootDataStatus.normalHistory) missing.push('normalHistory');
|
|
33
|
+
} else {
|
|
34
|
+
// 'all', 'aggregate', or 'n/a' -> Check if ANY history data exists
|
|
35
|
+
if (!rootDataStatus.hasHistory) missing.push('history');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// These data types are global and do not have user subtypes
|
|
15
39
|
else if (dep === 'insights' && !rootDataStatus.hasInsights) missing.push('insights');
|
|
16
40
|
else if (dep === 'social' && !rootDataStatus.hasSocial) missing.push('social');
|
|
17
|
-
else if (dep === 'history' && !rootDataStatus.hasHistory) missing.push('history');
|
|
18
41
|
else if (dep === 'price' && !rootDataStatus.hasPrices) missing.push('price');
|
|
19
42
|
}
|
|
20
43
|
return { canRun: missing.length === 0, missing };
|
|
@@ -49,27 +72,33 @@ function getViableCalculations(candidates, fullManifest, rootDataStatus, dailySt
|
|
|
49
72
|
|
|
50
73
|
/**
|
|
51
74
|
* Checks data availability by reading the centralized index.
|
|
52
|
-
*
|
|
75
|
+
* Extracts granular details to support Speculator-specific checks.
|
|
53
76
|
*/
|
|
54
77
|
async function checkRootDataAvailability(dateStr, config, dependencies, earliestDates) {
|
|
55
78
|
const { logger, db } = dependencies;
|
|
56
79
|
|
|
57
80
|
try {
|
|
58
81
|
// 1. Try reading the Index
|
|
59
|
-
const indexDoc =
|
|
82
|
+
const indexDoc = db.collection(INDEX_COLLECTION).doc(dateStr).get();
|
|
60
83
|
|
|
61
84
|
if (indexDoc.exists) {
|
|
62
85
|
const data = indexDoc.data();
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
// have logic to fetch refs if providedRefs is null (which they are here).
|
|
86
|
+
const details = data.details || {}; // Extract granular details if present
|
|
87
|
+
|
|
66
88
|
return {
|
|
67
89
|
status: {
|
|
90
|
+
// Global flags (Aggregate - true if EITHER exists)
|
|
68
91
|
hasPortfolio: !!data.hasPortfolio,
|
|
69
92
|
hasHistory: !!data.hasHistory,
|
|
70
93
|
hasSocial: !!data.hasSocial,
|
|
71
94
|
hasInsights: !!data.hasInsights,
|
|
72
|
-
hasPrices: !!data.hasPrices
|
|
95
|
+
hasPrices: !!data.hasPrices,
|
|
96
|
+
|
|
97
|
+
// Granular flags (Specific)
|
|
98
|
+
speculatorPortfolio: !!details.speculatorPortfolio,
|
|
99
|
+
normalPortfolio: !!details.normalPortfolio,
|
|
100
|
+
speculatorHistory: !!details.speculatorHistory,
|
|
101
|
+
normalHistory: !!details.normalHistory
|
|
73
102
|
},
|
|
74
103
|
portfolioRefs: null,
|
|
75
104
|
historyRefs: null,
|
|
@@ -79,10 +108,12 @@ async function checkRootDataAvailability(dateStr, config, dependencies, earliest
|
|
|
79
108
|
};
|
|
80
109
|
} else {
|
|
81
110
|
// Index missing: implies data hasn't been indexed yet or doesn't exist.
|
|
82
|
-
// For safety in this strict model, we assume MISSING.
|
|
83
111
|
logger.log('WARN', `[Availability] Index not found for ${dateStr}. Assuming NO data.`);
|
|
84
112
|
return {
|
|
85
|
-
status: {
|
|
113
|
+
status: {
|
|
114
|
+
hasPortfolio: false, hasHistory: false, hasSocial: false, hasInsights: false, hasPrices: false,
|
|
115
|
+
speculatorPortfolio: false, normalPortfolio: false, speculatorHistory: false, normalHistory: false
|
|
116
|
+
}
|
|
86
117
|
};
|
|
87
118
|
}
|
|
88
119
|
|