bulltrackers-module 1.0.738 → 1.0.740
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/functions/computation-system-v2/core-api.js +88 -0
- package/functions/computation-system-v2/docs/admin.md +44 -18
- package/functions/computation-system-v2/docs/plans.md +588 -0
- package/functions/computation-system-v2/framework/core/Manifest.js +25 -1
- package/functions/computation-system-v2/framework/data/DataFetcher.js +34 -2
- package/functions/computation-system-v2/framework/data/SchemaRegistry.js +31 -7
- package/functions/computation-system-v2/framework/execution/Orchestrator.js +36 -21
- package/functions/computation-system-v2/framework/execution/RemoteTaskRunner.js +74 -13
- package/functions/computation-system-v2/handlers/adminTest.js +1 -2
- package/functions/computation-system-v2/index.js +4 -176
- package/package.json +1 -1
|
@@ -1,184 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Computation System v2 Entry Point
|
|
3
|
-
*
|
|
4
|
-
* const { execute, analyze, runComputation } = require('./computation-system-v2');
|
|
5
|
-
* * // Analyze what can run
|
|
6
|
-
* const report = await analyze({ date: '2026-01-24' });
|
|
7
|
-
* * // Execute computations (Monolith/Scheduler mode)
|
|
8
|
-
* const result = await execute({ date: '2026-01-24' });
|
|
9
|
-
* * // Run single computation (Worker mode)
|
|
10
|
-
* const task = await runComputation({
|
|
11
|
-
* date: '2026-01-24',
|
|
12
|
-
* computation: 'UserPortfolioSummary'
|
|
13
|
-
* });
|
|
3
|
+
* Exports both the Core API and the Cloud Function Handlers.
|
|
14
4
|
*/
|
|
15
5
|
|
|
16
|
-
const
|
|
17
|
-
const config = require('./config/bulltrackers.config');
|
|
18
|
-
const { ManifestBuilder } = require('./framework/core/Manifest');
|
|
19
|
-
const { Computation } = require('./framework/core/Computation');
|
|
20
|
-
|
|
21
|
-
// Add computations to config
|
|
22
|
-
// These are loaded from computation-system-v2/computations folder
|
|
23
|
-
config.computations = [
|
|
24
|
-
require('./computations/UserPortfolioSummary'),
|
|
25
|
-
require('./computations/PopularInvestorProfileMetrics'),
|
|
26
|
-
require('./computations/PopularInvestorRiskAssessment'),
|
|
27
|
-
require('./computations/PopularInvestorRiskMetrics'),
|
|
28
|
-
// Add more computations here as they're migrated
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
// Singleton orchestrator instance
|
|
32
|
-
let orchestrator = null;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get or create the orchestrator instance.
|
|
36
|
-
* @param {Object} [customConfig] - Override default config
|
|
37
|
-
* @param {Object} [logger] - Custom logger
|
|
38
|
-
* @returns {Promise<Orchestrator>}
|
|
39
|
-
*/
|
|
40
|
-
async function getOrchestrator(customConfig = null, logger = null) {
|
|
41
|
-
if (!orchestrator || customConfig) {
|
|
42
|
-
const cfg = customConfig || config;
|
|
43
|
-
orchestrator = new Orchestrator(cfg, logger);
|
|
44
|
-
// Note: Orchestrator initializes lazily on first execute/analyze call,
|
|
45
|
-
// but we can force it here if needed.
|
|
46
|
-
}
|
|
47
|
-
return orchestrator;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Analyze what can run for a given date.
|
|
52
|
-
* @param {Object} options
|
|
53
|
-
* @param {string} options.date - Target date (YYYY-MM-DD)
|
|
54
|
-
* @param {Object} [options.config] - Override config
|
|
55
|
-
* @param {Object} [options.logger] - Custom logger
|
|
56
|
-
* @returns {Promise<Object>} Analysis report
|
|
57
|
-
*/
|
|
58
|
-
async function analyze(options) {
|
|
59
|
-
const { date, config: customConfig = null, logger = null } = options;
|
|
60
|
-
const orch = await getOrchestrator(customConfig, logger);
|
|
61
|
-
return orch.analyze({ date });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Execute computations for a given date.
|
|
66
|
-
* (Used by Scheduler or Monolithic runs)
|
|
67
|
-
*/
|
|
68
|
-
async function execute(options) {
|
|
69
|
-
const {
|
|
70
|
-
date,
|
|
71
|
-
pass = null,
|
|
72
|
-
computation = null,
|
|
73
|
-
dryRun = false,
|
|
74
|
-
entities = null,
|
|
75
|
-
config: customConfig = null,
|
|
76
|
-
logger = null
|
|
77
|
-
} = options;
|
|
78
|
-
|
|
79
|
-
const orch = await getOrchestrator(customConfig, logger);
|
|
80
|
-
return orch.execute({ date, pass, computation, dryRun, entities });
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* WORKER ENTRY POINT: Run a single computation.
|
|
85
|
-
* (Used by Cloud Functions / Dispatcher)
|
|
86
|
-
*
|
|
87
|
-
* @param {Object} options
|
|
88
|
-
* @param {string} options.date - Target date (YYYY-MM-DD)
|
|
89
|
-
* @param {string} options.computation - Computation name
|
|
90
|
-
* @param {string[]} [options.entityIds] - Specific entities to run (null = all)
|
|
91
|
-
* @param {boolean} [options.dryRun] - If true, don't persist results
|
|
92
|
-
* @param {boolean} [options.force] - If true, bypass up-to-date checks
|
|
93
|
-
* @param {boolean} [options.useWorkerPool] - Override worker pool setting (undefined = use config)
|
|
94
|
-
* @param {Object} [options.config] - Override config
|
|
95
|
-
* @param {Object} [options.logger] - Custom logger
|
|
96
|
-
*/
|
|
97
|
-
async function runComputation(options) {
|
|
98
|
-
const {
|
|
99
|
-
date,
|
|
100
|
-
computation,
|
|
101
|
-
entityIds = null,
|
|
102
|
-
dryRun = false,
|
|
103
|
-
force = false,
|
|
104
|
-
useWorkerPool, // Runtime override for worker pool
|
|
105
|
-
config: customConfig = null,
|
|
106
|
-
logger = null
|
|
107
|
-
} = options;
|
|
108
|
-
|
|
109
|
-
const orch = await getOrchestrator(customConfig, logger);
|
|
110
|
-
|
|
111
|
-
// 1. Ensure manifest is built
|
|
112
|
-
if (!orch.manifest) await orch.initialize();
|
|
113
|
-
|
|
114
|
-
// 2. Find the specific entry
|
|
115
|
-
// We normalize to handle case-insensitivity
|
|
116
|
-
const normalizedName = computation.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
117
|
-
const entry = orch.manifest.find(c => c.name === normalizedName);
|
|
118
|
-
|
|
119
|
-
if (!entry) {
|
|
120
|
-
throw new Error(`Computation not found: ${computation}`);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 3. Delegate to Orchestrator's runSingle
|
|
124
|
-
// This handles dependencies, data fetching, middleware, etc.
|
|
125
|
-
return orch.runSingle(entry, date, {
|
|
126
|
-
entityIds,
|
|
127
|
-
dryRun,
|
|
128
|
-
force,
|
|
129
|
-
useWorkerPool // Pass override to Orchestrator
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Get the manifest (list of all computations with metadata).
|
|
135
|
-
*/
|
|
136
|
-
async function getManifest(options = {}) {
|
|
137
|
-
const { config: customConfig = null, logger = null } = options;
|
|
138
|
-
const orch = await getOrchestrator(customConfig, logger);
|
|
139
|
-
if (!orch.manifest) await orch.initialize();
|
|
140
|
-
return orch.manifest;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Warm the schema cache for all tables.
|
|
145
|
-
*/
|
|
146
|
-
async function warmCache(options = {}) {
|
|
147
|
-
const { config: customConfig = null, logger = null } = options;
|
|
148
|
-
const orch = await getOrchestrator(customConfig, logger);
|
|
149
|
-
const allTables = Object.keys(orch.config.tables);
|
|
150
|
-
return orch.schemaRegistry.warmCache(allTables);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Reset the singleton (useful for testing).
|
|
155
|
-
*/
|
|
156
|
-
function reset() {
|
|
157
|
-
orchestrator = null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Import handlers for Cloud Functions
|
|
6
|
+
const coreApi = require('./core-api');
|
|
161
7
|
const handlers = require('./handlers');
|
|
162
8
|
|
|
163
9
|
module.exports = {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
execute,
|
|
167
|
-
ManifestBuilder,
|
|
168
|
-
Computation,
|
|
169
|
-
|
|
170
|
-
runComputation, // <--- New Method
|
|
171
|
-
getManifest,
|
|
172
|
-
warmCache,
|
|
173
|
-
reset,
|
|
174
|
-
|
|
175
|
-
// For advanced usage
|
|
176
|
-
getOrchestrator,
|
|
177
|
-
config,
|
|
178
|
-
|
|
179
|
-
// Cloud Function handlers
|
|
180
|
-
...handlers,
|
|
181
|
-
|
|
182
|
-
// Re-export framework components
|
|
183
|
-
...require('./framework')
|
|
10
|
+
...coreApi,
|
|
11
|
+
...handlers
|
|
184
12
|
};
|