@toxplanet/pegasus-sdk 1.1.24 → 1.2.0
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/config/environment.prod.js +2 -2
- package/lib/chemicals.js +52 -8
- package/package.json +47 -47
|
@@ -3,12 +3,12 @@ module.exports = {
|
|
|
3
3
|
region: 'us-east-1',
|
|
4
4
|
awsAccountId: '147997144422',
|
|
5
5
|
sourceService: 'pegasus-sdk',
|
|
6
|
-
secretArn: 'arn:aws:secretsmanager:us-east-1:
|
|
6
|
+
secretArn: 'arn:aws:secretsmanager:us-east-1:964963729446:secret:rds!cluster-bd301b0f-93b7-4dcb-a4fa-ebf753fd1c00-atsPOm',
|
|
7
7
|
clusterArn: 'arn:aws:rds:us-east-1:147997144422:cluster:cr-chemicals-prod',
|
|
8
8
|
database: {
|
|
9
9
|
name: 'chemicals'
|
|
10
10
|
},
|
|
11
|
-
openSearchEndpoint: 'https://
|
|
11
|
+
openSearchEndpoint: 'https://aq6ftqi0hawm42795fci.us-east-1.aoss-fips.amazonaws.com',
|
|
12
12
|
openSearchIndex: 'chemicals',
|
|
13
13
|
indexRoutes: {
|
|
14
14
|
chemicals: ['chemicals*'],
|
package/lib/chemicals.js
CHANGED
|
@@ -39,6 +39,42 @@ function parsePostgresArray(str) {
|
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function transformChemicalMeta(meta) {
|
|
43
|
+
if (!meta || typeof meta !== 'object') return [];
|
|
44
|
+
if (Array.isArray(meta)) {
|
|
45
|
+
// If it's already in new format, return as-is
|
|
46
|
+
if (meta.length > 0 && meta[0].key !== undefined) {
|
|
47
|
+
return meta;
|
|
48
|
+
}
|
|
49
|
+
// Transform from old format { meta_key, meta_value_text, meta_value_type, ... } to new format { key, value, [unit] }
|
|
50
|
+
return meta.map(item => {
|
|
51
|
+
const transformed = {
|
|
52
|
+
key: item.meta_key || item.key,
|
|
53
|
+
value: item.meta_value_text || item.value || []
|
|
54
|
+
};
|
|
55
|
+
if (item.unit) transformed.unit = item.unit;
|
|
56
|
+
return transformed;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function transformChemicalIdentifiers(identifiers) {
|
|
63
|
+
if (!identifiers || typeof identifiers !== 'object') return [];
|
|
64
|
+
if (Array.isArray(identifiers)) {
|
|
65
|
+
// If it's already in new format, return as-is
|
|
66
|
+
if (identifiers.length > 0 && identifiers[0].type !== undefined) {
|
|
67
|
+
return identifiers;
|
|
68
|
+
}
|
|
69
|
+
// Transform from old format { identifier_key, identifier_value, ... } to new format { type, value }
|
|
70
|
+
return identifiers.map(item => ({
|
|
71
|
+
type: item.identifier_key || item.type,
|
|
72
|
+
value: Array.isArray(item.identifier_value) ? item.identifier_value[0] : (item.value || item.identifier_value)
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
class ChemicalsService {
|
|
43
79
|
constructor(connection) {
|
|
44
80
|
this.connection = connection;
|
|
@@ -64,8 +100,8 @@ class ChemicalsService {
|
|
|
64
100
|
chemicalId: row.chemical_id,
|
|
65
101
|
sourceId: row.source_id,
|
|
66
102
|
chemicalName: row.chemical_name,
|
|
67
|
-
chemicalMeta: row.chemical_meta ? JSON.parse(row.chemical_meta) : null,
|
|
68
|
-
chemicalIdentifiers: row.chemical_identifiers ? JSON.parse(row.chemical_identifiers) : null,
|
|
103
|
+
chemicalMeta: row.chemical_meta ? (Array.isArray(row.chemical_meta) ? row.chemical_meta : JSON.parse(row.chemical_meta)) : null,
|
|
104
|
+
chemicalIdentifiers: row.chemical_identifiers ? (Array.isArray(row.chemical_identifiers) ? row.chemical_identifiers : JSON.parse(row.chemical_identifiers)) : null,
|
|
69
105
|
chemicalSynonyms: this._parsePostgresArray(row.chemical_synonyms),
|
|
70
106
|
chemicalCategories: this._parsePostgresArray(row.chemical_categories),
|
|
71
107
|
createdAt: row.created_at,
|
|
@@ -132,11 +168,14 @@ class ChemicalsService {
|
|
|
132
168
|
'RETURNING chemical_id, source_id'
|
|
133
169
|
].join('\n');
|
|
134
170
|
|
|
171
|
+
const transformedMeta = transformChemicalMeta(chemical.chemicalMeta);
|
|
172
|
+
const transformedIdentifiers = transformChemicalIdentifiers(chemical.chemicalIdentifiers);
|
|
173
|
+
|
|
135
174
|
const parameters = [
|
|
136
175
|
{ name: 'source_id', value: { stringValue: chemical.sourceId } },
|
|
137
176
|
{ name: 'chemical_name', value: { stringValue: chemical.chemicalName } },
|
|
138
|
-
{ name: 'chemical_meta', value: { stringValue: JSON.stringify(
|
|
139
|
-
{ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(
|
|
177
|
+
{ name: 'chemical_meta', value: { stringValue: JSON.stringify(transformedMeta) }, typeHint: 'JSON' },
|
|
178
|
+
{ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(transformedIdentifiers) }, typeHint: 'JSON' },
|
|
140
179
|
{ name: 'chemical_synonyms', value: { stringValue: this._toPostgresArray(chemical.chemicalSynonyms ?? []) } },
|
|
141
180
|
{ name: 'chemical_categories', value: { stringValue: this._toPostgresArray(chemical.chemicalCategories ?? []) } },
|
|
142
181
|
{ name: 'created_at', value: { stringValue: this._serializeDate(chemical.createdAt) } },
|
|
@@ -326,13 +365,16 @@ class ChemicalsService {
|
|
|
326
365
|
try {
|
|
327
366
|
await this.connection.ensureConnected();
|
|
328
367
|
|
|
368
|
+
const transformedMeta = transformChemicalMeta(chemical.chemical_meta);
|
|
369
|
+
const transformedIdentifiers = transformChemicalIdentifiers(chemical.chemical_identifiers);
|
|
370
|
+
|
|
329
371
|
const columns = ['source_id', 'chemical_name', 'chemical_meta', 'chemical_identifiers', 'chemical_synonyms', 'chemical_categories', 'created_at', 'updated_at'];
|
|
330
372
|
const values = [':source_id', ':chemical_name', ':chemical_meta::jsonb', ':chemical_identifiers::jsonb', ':chemical_synonyms::text[]', ':chemical_categories::text[]', ':created_at::timestamp', ':updated_at::timestamp'];
|
|
331
373
|
const params = [
|
|
332
374
|
{ name: 'source_id', value: { stringValue: chemical.source_id } },
|
|
333
375
|
{ name: 'chemical_name', value: { stringValue: chemical.chemical_name } },
|
|
334
|
-
{ name: 'chemical_meta', value: { stringValue: JSON.stringify(
|
|
335
|
-
{ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(
|
|
376
|
+
{ name: 'chemical_meta', value: { stringValue: JSON.stringify(transformedMeta) }, typeHint: 'JSON' },
|
|
377
|
+
{ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(transformedIdentifiers) }, typeHint: 'JSON' },
|
|
336
378
|
{ name: 'chemical_synonyms', value: { stringValue: this._toPostgresArray(chemical.chemical_synonyms || []) } },
|
|
337
379
|
{ name: 'chemical_categories', value: { stringValue: this._toPostgresArray(chemical.chemical_categories || []) } },
|
|
338
380
|
{ name: 'created_at', value: { stringValue: this._serializeDate(chemical.created_at || new Date()) } },
|
|
@@ -372,12 +414,14 @@ class ChemicalsService {
|
|
|
372
414
|
params.push({ name: 'chemical_name', value: { stringValue: updates.chemical_name } });
|
|
373
415
|
}
|
|
374
416
|
if (updates.chemical_meta) {
|
|
417
|
+
const transformedMeta = transformChemicalMeta(updates.chemical_meta);
|
|
375
418
|
setClauses.push('chemical_meta = :chemical_meta::jsonb');
|
|
376
|
-
params.push({ name: 'chemical_meta', value: { stringValue: JSON.stringify(
|
|
419
|
+
params.push({ name: 'chemical_meta', value: { stringValue: JSON.stringify(transformedMeta) }, typeHint: 'JSON' });
|
|
377
420
|
}
|
|
378
421
|
if (updates.chemical_identifiers) {
|
|
422
|
+
const transformedIdentifiers = transformChemicalIdentifiers(updates.chemical_identifiers);
|
|
379
423
|
setClauses.push('chemical_identifiers = :chemical_identifiers::jsonb');
|
|
380
|
-
params.push({ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(
|
|
424
|
+
params.push({ name: 'chemical_identifiers', value: { stringValue: JSON.stringify(transformedIdentifiers) }, typeHint: 'JSON' });
|
|
381
425
|
}
|
|
382
426
|
if (updates.chemical_synonyms) {
|
|
383
427
|
setClauses.push('chemical_synonyms = :chemical_synonyms::text[]');
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@toxplanet/pegasus-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "SDK for migrating chemical data to Pegasus PostgreSQL + OpenSearch architecture with Elasticsearch client compatibility",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "vitest run",
|
|
9
|
-
"test:watch": "vitest",
|
|
10
|
-
"test:ui": "vitest --ui"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"elasticsearch",
|
|
14
|
-
"opensearch",
|
|
15
|
-
"postgresql",
|
|
16
|
-
"aws",
|
|
17
|
-
"chemicals",
|
|
18
|
-
"database",
|
|
19
|
-
"search",
|
|
20
|
-
"sdk",
|
|
21
|
-
"pegasus",
|
|
22
|
-
"migration"
|
|
23
|
-
],
|
|
24
|
-
"author": "Chemical Research Development Team",
|
|
25
|
-
"license": "MIT",
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@toxplanet/tphelper": "1.2.8",
|
|
28
|
-
"@opensearch-project/opensearch": "^2.5.0",
|
|
29
|
-
"@aws-sdk/client-rds-data": "^3.490.0",
|
|
30
|
-
"@aws-sdk/client-sqs": "^3.490.0",
|
|
31
|
-
"@aws-sdk/credential-providers": "^3.490.0"
|
|
32
|
-
},
|
|
33
|
-
"engines": {
|
|
34
|
-
"node": ">=18.0.0"
|
|
35
|
-
},
|
|
36
|
-
"files": [
|
|
37
|
-
"index.js",
|
|
38
|
-
"lib/",
|
|
39
|
-
"config/",
|
|
40
|
-
"README.md",
|
|
41
|
-
"ELASTICSEARCH_CLIENT.md",
|
|
42
|
-
"LICENSE"
|
|
43
|
-
],
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"vitest": "^1.2.0"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@toxplanet/pegasus-sdk",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "SDK for migrating chemical data to Pegasus PostgreSQL + OpenSearch architecture with Elasticsearch client compatibility",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "vitest run",
|
|
9
|
+
"test:watch": "vitest",
|
|
10
|
+
"test:ui": "vitest --ui"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"elasticsearch",
|
|
14
|
+
"opensearch",
|
|
15
|
+
"postgresql",
|
|
16
|
+
"aws",
|
|
17
|
+
"chemicals",
|
|
18
|
+
"database",
|
|
19
|
+
"search",
|
|
20
|
+
"sdk",
|
|
21
|
+
"pegasus",
|
|
22
|
+
"migration"
|
|
23
|
+
],
|
|
24
|
+
"author": "Chemical Research Development Team",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@toxplanet/tphelper": "1.2.8",
|
|
28
|
+
"@opensearch-project/opensearch": "^2.5.0",
|
|
29
|
+
"@aws-sdk/client-rds-data": "^3.490.0",
|
|
30
|
+
"@aws-sdk/client-sqs": "^3.490.0",
|
|
31
|
+
"@aws-sdk/credential-providers": "^3.490.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.0.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"lib/",
|
|
39
|
+
"config/",
|
|
40
|
+
"README.md",
|
|
41
|
+
"ELASTICSEARCH_CLIENT.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"vitest": "^1.2.0"
|
|
46
|
+
}
|
|
47
|
+
}
|