@toxplanet/pegasus-sdk 1.1.9 → 1.1.11

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/lib/chemicals.js CHANGED
@@ -1,4 +1,4 @@
1
- const { logError } = require('@toxplanet/tphelper/logging');
1
+ const { logError, logInfo } = require('@toxplanet/tphelper/logging');
2
2
  const { getDrizzle, schema } = require('./db');
3
3
  const { eq, sql, and, inArray, arrayContains } = require('drizzle-orm');
4
4
 
@@ -46,6 +46,13 @@ class ChemicalsService {
46
46
  logInfo('pegasus-sdk', `[bulkIndexFielded] Processing document ${i}: source_id=${doc.source_id}, chemical_name=${doc.chemical_name}`);
47
47
 
48
48
  try {
49
+ const parseDate = (dateValue) => {
50
+ if (!dateValue) return new Date();
51
+ if (dateValue instanceof Date) return dateValue;
52
+ if (typeof dateValue === 'string') return new Date(dateValue);
53
+ return new Date();
54
+ };
55
+
49
56
  const chemical = {
50
57
  sourceId: doc.source_id || doc._id,
51
58
  chemicalName: doc.chemical_name || doc.name,
@@ -53,8 +60,8 @@ class ChemicalsService {
53
60
  chemicalIdentifiers: doc.chemical_identifiers || {},
54
61
  chemicalSynonyms: doc.chemical_synonyms || [],
55
62
  chemicalCategories: doc.chemical_categories || [],
56
- createdAt: doc.created_at || new Date(),
57
- updatedAt: doc.updated_at || new Date(),
63
+ createdAt: parseDate(doc.created_at),
64
+ updatedAt: parseDate(doc.updated_at),
58
65
  ...(doc.imported_at && { importedAt: doc.imported_at }),
59
66
  ...(doc.chemical_id && { chemicalId: doc.chemical_id })
60
67
  };
@@ -658,7 +665,6 @@ class ChemicalsService {
658
665
  },
659
666
 
660
667
  bulk: async (params) => {
661
- const { logInfo, logError } = require('@toxplanet/tphelper/logging');
662
668
  const operations = params.body || params.operations;
663
669
 
664
670
  logInfo('pegasus-sdk', `[ChemicalsService.bulk] Starting bulk operation with ${operations?.length || 0} total operations`);
@@ -691,8 +697,8 @@ class ChemicalsService {
691
697
  chemical_identifiers: doc.chemical_identifiers || {},
692
698
  chemical_synonyms: doc.chemical_synonyms || [],
693
699
  chemical_categories: doc.chemical_categories || [],
694
- created_at: doc.chemical_created_at,
695
- updated_at: doc.chemical_updated_at
700
+ created_at: doc.chemical_created_at ? (typeof doc.chemical_created_at === 'string' ? new Date(doc.chemical_created_at) : doc.chemical_created_at) : new Date(),
701
+ updated_at: doc.chemical_updated_at ? (typeof doc.chemical_updated_at === 'string' ? new Date(doc.chemical_updated_at) : doc.chemical_updated_at) : new Date()
696
702
  };
697
703
  cdiDocuments.push(cdiDoc);
698
704
  logInfo('pegasus-sdk', `[ChemicalsService.bulk] Extracted CDI doc: ${JSON.stringify({ source_id: cdiDoc.source_id, chemical_name: cdiDoc.chemical_name })}`);
@@ -1,3 +1,5 @@
1
+ const { logInfo, logError } = require('@toxplanet/tphelper/logging');
2
+
1
3
  class ElasticsearchService {
2
4
  constructor(connection) {
3
5
  this.connection = connection;
@@ -64,7 +66,6 @@ class ElasticsearchService {
64
66
  }
65
67
 
66
68
  async bulk(params) {
67
- const { logInfo, logError } = require('@toxplanet/tphelper/logging');
68
69
  const operations = params.body || params.operations;
69
70
 
70
71
  logInfo('pegasus-sdk', `[ElasticsearchService.bulk] Starting bulk routing with ${operations?.length || 0} operations`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toxplanet/pegasus-sdk",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "SDK for migrating chemical data to Pegasus PostgreSQL + OpenSearch architecture with Elasticsearch client compatibility",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",