bulltrackers-module 1.0.668 → 1.0.670

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.
@@ -77,7 +77,6 @@ async function sendAuthenticatedCallback(callbackUrl, payload, logger, directFet
77
77
  }
78
78
  }
79
79
 
80
- // ... [SHARED UTILS and SHARED ASYNC HELPERS remain exactly the same] ...
81
80
 
82
81
  function getMillis(field) {
83
82
  if (!field) return 0;
@@ -176,13 +176,9 @@ async function commitResults(stateObj, dStr, passName, config, deps, skipStatusW
176
176
  _pageCount: pageCountValue,
177
177
  _lastUpdated: new Date().toISOString(),
178
178
  _expireAt: expireAt,
179
- _completed: isFinalFlush || (isInitialWrite ? false : undefined) // Initialize false if initial, set true if final
179
+ _completed: isFinalFlush ? true : false // Always a boolean: true when final flush, false otherwise
180
180
  };
181
181
 
182
- // Adjust logic to correctly set _completed only on final flush
183
- if (isFinalFlush) headerData._completed = true;
184
- else if (isInitialWrite) headerData._completed = false;
185
-
186
182
  await mainDocRef.set(headerData, { merge: !isInitialWrite });
187
183
 
188
184
  runMetrics.io.writes += 1;
@@ -38,7 +38,18 @@ async function tryLoadFromGCS(config, dateString, snapshotName, logger) {
38
38
  if (exists) {
39
39
  logger.log('INFO', `[DataLoader] ⚡️ GCS HIT: ${snapshotName} for ${dateString}`);
40
40
  const [content] = await file.download();
41
- return JSON.parse(zlib.gunzipSync(content).toString());
41
+
42
+ // FIX: GCS client auto-decompresses if Content-Encoding is gzip.
43
+ // We try gunzip first; if it fails with header check, it's likely already JSON.
44
+ try {
45
+ return JSON.parse(zlib.gunzipSync(content).toString());
46
+ } catch (zipError) {
47
+ if (zipError.message && zipError.message.includes('incorrect header check')) {
48
+ // Content was already decompressed by the client
49
+ return JSON.parse(content.toString());
50
+ }
51
+ throw zipError;
52
+ }
42
53
  }
43
54
  } catch (e) {
44
55
  logger.log('WARN', `[DataLoader] GCS Check Failed (${snapshotName}): ${e.message}`);
@@ -434,7 +445,19 @@ async function* streamPortfolioData(config, deps, dateString, providedRefs = nul
434
445
  if (exists) {
435
446
  logger.log('INFO', `[DataLoader] ⚡️ STREAMING: Hydrating Portfolios from GCS Snapshot`);
436
447
  const [content] = await file.download();
437
- const fullData = JSON.parse(zlib.gunzipSync(content).toString());
448
+
449
+ // FIX: Handle Double Decompression
450
+ let fullData;
451
+ try {
452
+ fullData = JSON.parse(zlib.gunzipSync(content).toString());
453
+ } catch (zipError) {
454
+ if (zipError.message && zipError.message.includes('incorrect header check')) {
455
+ fullData = JSON.parse(content.toString());
456
+ } else {
457
+ throw zipError;
458
+ }
459
+ }
460
+
438
461
  yield fullData; // Yield all in one chunk as it fits in memory
439
462
  return;
440
463
  }
@@ -473,7 +496,7 @@ async function* streamHistoryData(config, deps, dateString, providedRefs = null,
473
496
  if (exists) {
474
497
  logger.log('INFO', `[DataLoader] ⚡️ STREAMING: Hydrating History from GCS (JSONL)`);
475
498
 
476
- const fileStream = file.createReadStream().pipe(zlib.createGunzip());
499
+ const fileStream = file.createReadStream();
477
500
  const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity });
478
501
 
479
502
  let currentBatch = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.668",
3
+ "version": "1.0.670",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [