@toxplanet/pegasus-sdk 1.1.16 → 1.1.17

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.
Files changed (2) hide show
  1. package/lib/chemicals.js +33 -0
  2. package/package.json +1 -1
package/lib/chemicals.js CHANGED
@@ -101,6 +101,38 @@ class ChemicalsService {
101
101
  return { sql, parameters };
102
102
  }
103
103
 
104
+ _buildDebugSql(chemical) {
105
+ const esc = (s) => `'${String(s ?? '').replace(/'/g, "''")}'`;
106
+ const escJson = (v) => `'${JSON.stringify(v ?? {}).replace(/'/g, "''")}'`;
107
+ const escArr = (arr) => {
108
+ if (!Array.isArray(arr) || arr.length === 0) return `ARRAY[]::text[]`;
109
+ return `ARRAY[${arr.map(s => esc(s)).join(', ')}]`;
110
+ };
111
+ const escDate = (d) => esc(d instanceof Date ? d.toISOString() : (d ?? new Date().toISOString()));
112
+
113
+ return [
114
+ `INSERT INTO chemicals`,
115
+ ` (source_id, chemical_name, chemical_meta, chemical_identifiers, chemical_synonyms, chemical_categories, created_at, updated_at)`,
116
+ `VALUES (`,
117
+ ` ${esc(chemical.sourceId)},`,
118
+ ` ${esc(chemical.chemicalName)},`,
119
+ ` ${escJson(chemical.chemicalMeta)}::jsonb,`,
120
+ ` ${escJson(chemical.chemicalIdentifiers)}::jsonb,`,
121
+ ` ${escArr(chemical.chemicalSynonyms)},`,
122
+ ` ${escArr(chemical.chemicalCategories)},`,
123
+ ` ${escDate(chemical.createdAt)},`,
124
+ ` ${escDate(chemical.updatedAt)}`,
125
+ `)`,
126
+ `ON CONFLICT (source_id) DO UPDATE SET`,
127
+ ` chemical_name = ${esc(chemical.chemicalName)},`,
128
+ ` chemical_meta = ${escJson(chemical.chemicalMeta)}::jsonb,`,
129
+ ` chemical_identifiers = ${escJson(chemical.chemicalIdentifiers)}::jsonb,`,
130
+ ` chemical_synonyms = ${escArr(chemical.chemicalSynonyms)},`,
131
+ ` chemical_categories = ${escArr(chemical.chemicalCategories)},`,
132
+ ` updated_at = NOW();`
133
+ ].join('\n');
134
+ }
135
+
104
136
  async bulkIndexFielded(documents) {
105
137
  try {
106
138
  logInfo('pegasus-sdk', `[bulkIndexFielded] Starting bulk index with ${documents?.length || 0} documents`);
@@ -141,6 +173,7 @@ class ChemicalsService {
141
173
  };
142
174
 
143
175
  logInfo('pegasus-sdk', `[bulkIndexFielded] Prepared chemical object: sourceId=${chemical.sourceId}, chemicalName=${chemical.chemicalName}`);
176
+ logInfo('pegasus-sdk', `[bulkIndexFielded] DEBUG SQL for document ${i}:\n${this._buildDebugSql(chemical)}`);
144
177
 
145
178
  const isConnectionError = (err) =>
146
179
  err.message?.toLowerCase().includes('timeout') ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toxplanet/pegasus-sdk",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
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",