@toxplanet/pegasus-sdk 1.2.3 → 1.2.5
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 +1 -1
- package/lib/chemicals.js +140 -102
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
environment: 'prod',
|
|
3
3
|
region: 'us-east-1',
|
|
4
|
-
awsAccountId: '
|
|
4
|
+
awsAccountId: '964963729446',
|
|
5
5
|
sourceService: 'pegasus-sdk',
|
|
6
6
|
secretArn: 'arn:aws:secretsmanager:us-east-1:964963729446:secret:rds!cluster-02ff6afa-c567-46ad-8b9e-55a19ad19f0d-neNrGF',
|
|
7
7
|
clusterArn: 'arn:aws:rds:us-east-1:964963729446:cluster:cr-chemicals-prod-v2',
|
package/lib/chemicals.js
CHANGED
|
@@ -896,13 +896,16 @@ class ChemicalsService {
|
|
|
896
896
|
index: async (params) => {
|
|
897
897
|
const chemical = params.body;
|
|
898
898
|
const result = await this.createChemical(chemical);
|
|
899
|
-
|
|
899
|
+
|
|
900
900
|
return {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
901
|
+
body: {
|
|
902
|
+
_index: params.index,
|
|
903
|
+
_id: result.chemicalId,
|
|
904
|
+
_version: 1,
|
|
905
|
+
result: 'created',
|
|
906
|
+
_source: result
|
|
907
|
+
},
|
|
908
|
+
statusCode: 200
|
|
906
909
|
};
|
|
907
910
|
},
|
|
908
911
|
|
|
@@ -958,7 +961,10 @@ class ChemicalsService {
|
|
|
958
961
|
|
|
959
962
|
if (cdiDocuments.length === 0) {
|
|
960
963
|
logInfo('pegasus-sdk', `[ChemicalsService.bulk] No CDI documents to index, returning empty no-op response`);
|
|
961
|
-
return {
|
|
964
|
+
return {
|
|
965
|
+
body: { took: 0, errors: false, items: [] },
|
|
966
|
+
statusCode: 200
|
|
967
|
+
};
|
|
962
968
|
}
|
|
963
969
|
|
|
964
970
|
logInfo('pegasus-sdk', `[ChemicalsService.bulk] Calling bulkIndexFielded with ${cdiDocuments.length} CDI documents`);
|
|
@@ -972,17 +978,20 @@ class ChemicalsService {
|
|
|
972
978
|
}
|
|
973
979
|
|
|
974
980
|
return {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
981
|
+
body: {
|
|
982
|
+
took: 1,
|
|
983
|
+
errors: result.errors.length > 0,
|
|
984
|
+
items: result.results.map((res, idx) => ({
|
|
985
|
+
index: {
|
|
986
|
+
_index: 'chemical_data_index',
|
|
987
|
+
_id: cdiDocuments[idx].source_id,
|
|
988
|
+
status: res.success ? 200 : 400,
|
|
989
|
+
result: res.success ? 'created' : 'error',
|
|
990
|
+
...(res.success ? {} : { error: { type: 'mapper_parsing_exception', reason: res.error } })
|
|
991
|
+
}
|
|
992
|
+
}))
|
|
993
|
+
},
|
|
994
|
+
statusCode: 200
|
|
986
995
|
};
|
|
987
996
|
} catch (error) {
|
|
988
997
|
logError('pegasus-sdk', 'ChemicalsService.bulk', 'Fatal error during bulk indexing', error);
|
|
@@ -992,46 +1001,61 @@ class ChemicalsService {
|
|
|
992
1001
|
|
|
993
1002
|
get: async (params) => {
|
|
994
1003
|
const result = await this.getChemicalBySourceId(params.id);
|
|
995
|
-
|
|
1004
|
+
|
|
996
1005
|
if (!result) {
|
|
997
1006
|
return {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1007
|
+
body: {
|
|
1008
|
+
_index: params.index,
|
|
1009
|
+
_id: params.id,
|
|
1010
|
+
found: false
|
|
1011
|
+
},
|
|
1012
|
+
statusCode: 200
|
|
1001
1013
|
};
|
|
1002
1014
|
}
|
|
1003
|
-
|
|
1015
|
+
|
|
1004
1016
|
return {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1017
|
+
body: {
|
|
1018
|
+
_index: params.index,
|
|
1019
|
+
_id: params.id,
|
|
1020
|
+
_version: 1,
|
|
1021
|
+
found: true,
|
|
1022
|
+
_source: result
|
|
1023
|
+
},
|
|
1024
|
+
statusCode: 200
|
|
1010
1025
|
};
|
|
1011
1026
|
},
|
|
1012
1027
|
|
|
1013
1028
|
update: async (params) => {
|
|
1014
1029
|
const result = await this.updateChemical(params.id, params.body);
|
|
1015
|
-
|
|
1030
|
+
|
|
1016
1031
|
return {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1032
|
+
body: {
|
|
1033
|
+
_index: params.index,
|
|
1034
|
+
_id: params.id,
|
|
1035
|
+
_version: 2,
|
|
1036
|
+
result: result ? 'updated' : 'noop',
|
|
1037
|
+
_source: result
|
|
1038
|
+
},
|
|
1039
|
+
statusCode: 200
|
|
1022
1040
|
};
|
|
1023
1041
|
},
|
|
1024
1042
|
|
|
1025
1043
|
delete: async (params) => {
|
|
1026
1044
|
if (params.index === 'synonym_lookup_index') {
|
|
1027
|
-
return {
|
|
1045
|
+
return {
|
|
1046
|
+
body: { _index: params.index, _id: params.id, result: 'not_found' },
|
|
1047
|
+
statusCode: 200
|
|
1048
|
+
};
|
|
1028
1049
|
}
|
|
1029
1050
|
const result = await this.deleteBySourceId(params.id);
|
|
1030
|
-
|
|
1051
|
+
|
|
1031
1052
|
return {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1053
|
+
body: {
|
|
1054
|
+
_index: params.index,
|
|
1055
|
+
_id: params.id,
|
|
1056
|
+
result: result ? 'deleted' : 'not_found'
|
|
1057
|
+
},
|
|
1058
|
+
statusCode: 200
|
|
1035
1059
|
};
|
|
1036
1060
|
},
|
|
1037
1061
|
|
|
@@ -1039,12 +1063,18 @@ class ChemicalsService {
|
|
|
1039
1063
|
const sourceId = params.body?.query?.term?.chemical_set_identifier
|
|
1040
1064
|
|| params.body?.query?.term?.source_id;
|
|
1041
1065
|
if (!sourceId) {
|
|
1042
|
-
return {
|
|
1066
|
+
return {
|
|
1067
|
+
body: { deleted: 0, failures: [] },
|
|
1068
|
+
statusCode: 200
|
|
1069
|
+
};
|
|
1043
1070
|
}
|
|
1044
1071
|
const result = await this.deleteBySourceId(sourceId);
|
|
1045
1072
|
return {
|
|
1046
|
-
|
|
1047
|
-
|
|
1073
|
+
body: {
|
|
1074
|
+
deleted: result ? 1 : 0,
|
|
1075
|
+
failures: []
|
|
1076
|
+
},
|
|
1077
|
+
statusCode: 200
|
|
1048
1078
|
};
|
|
1049
1079
|
},
|
|
1050
1080
|
|
|
@@ -1054,84 +1084,92 @@ class ChemicalsService {
|
|
|
1054
1084
|
|
|
1055
1085
|
if (params.index === 'synonym_lookup_index') {
|
|
1056
1086
|
const query = params.body?.query;
|
|
1057
|
-
searchTerm = query?.match?.chemical_name ||
|
|
1058
|
-
query?.term?.chemical_name ||
|
|
1087
|
+
searchTerm = query?.match?.chemical_name ||
|
|
1088
|
+
query?.term?.chemical_name ||
|
|
1059
1089
|
query?.query_string?.query || '';
|
|
1060
1090
|
const searchResults = await this.searchBySynonym(searchTerm, limit);
|
|
1061
|
-
|
|
1091
|
+
|
|
1062
1092
|
return {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
hits: {
|
|
1072
|
-
total: {
|
|
1073
|
-
value: searchResults.results.length,
|
|
1074
|
-
relation: 'eq'
|
|
1093
|
+
body: {
|
|
1094
|
+
took: 1,
|
|
1095
|
+
timed_out: false,
|
|
1096
|
+
_shards: {
|
|
1097
|
+
total: 1,
|
|
1098
|
+
successful: 1,
|
|
1099
|
+
skipped: 0,
|
|
1100
|
+
failed: 0
|
|
1075
1101
|
},
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1102
|
+
hits: {
|
|
1103
|
+
total: {
|
|
1104
|
+
value: searchResults.results.length,
|
|
1105
|
+
relation: 'eq'
|
|
1106
|
+
},
|
|
1107
|
+
max_score: searchResults.results[0]?.score || 0,
|
|
1108
|
+
hits: searchResults.results.map(result => ({
|
|
1109
|
+
_index: params.index,
|
|
1110
|
+
_id: result.id,
|
|
1111
|
+
_score: result.score,
|
|
1112
|
+
_source: {
|
|
1113
|
+
postgres_id: result.id,
|
|
1114
|
+
chemical_name: result.name,
|
|
1115
|
+
cas_numbers: result.cas,
|
|
1116
|
+
identifier_values: result.identifiers,
|
|
1117
|
+
synonyms: result.synonyms
|
|
1118
|
+
}
|
|
1119
|
+
}))
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
statusCode: 200
|
|
1090
1123
|
};
|
|
1091
1124
|
} else {
|
|
1092
1125
|
const query = params.body?.query;
|
|
1093
|
-
searchTerm = query?.match?.chemical_name ||
|
|
1094
|
-
query?.term?.chemical_name ||
|
|
1126
|
+
searchTerm = query?.match?.chemical_name ||
|
|
1127
|
+
query?.term?.chemical_name ||
|
|
1095
1128
|
query?.query_string?.query || '';
|
|
1096
1129
|
const searchResults = await this.searchByName(searchTerm, limit);
|
|
1097
|
-
|
|
1130
|
+
|
|
1098
1131
|
return {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
hits: {
|
|
1108
|
-
total: {
|
|
1109
|
-
value: searchResults.results.length,
|
|
1110
|
-
relation: 'eq'
|
|
1132
|
+
body: {
|
|
1133
|
+
took: 1,
|
|
1134
|
+
timed_out: false,
|
|
1135
|
+
_shards: {
|
|
1136
|
+
total: 1,
|
|
1137
|
+
successful: 1,
|
|
1138
|
+
skipped: 0,
|
|
1139
|
+
failed: 0
|
|
1111
1140
|
},
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1141
|
+
hits: {
|
|
1142
|
+
total: {
|
|
1143
|
+
value: searchResults.results.length,
|
|
1144
|
+
relation: 'eq'
|
|
1145
|
+
},
|
|
1146
|
+
max_score: searchResults.results[0]?.score || 0,
|
|
1147
|
+
hits: searchResults.results.map(result => ({
|
|
1148
|
+
_index: params.index,
|
|
1149
|
+
_id: result.id,
|
|
1150
|
+
_score: result.score,
|
|
1151
|
+
_source: {
|
|
1152
|
+
postgres_id: result.id,
|
|
1153
|
+
chemical_name: result.name,
|
|
1154
|
+
cas_numbers: result.cas,
|
|
1155
|
+
identifier_values: result.identifiers,
|
|
1156
|
+
synonyms: result.synonyms
|
|
1157
|
+
}
|
|
1158
|
+
}))
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
statusCode: 200
|
|
1126
1162
|
};
|
|
1127
1163
|
}
|
|
1128
1164
|
},
|
|
1129
1165
|
|
|
1130
1166
|
count: async (params) => {
|
|
1131
1167
|
if (params.index === 'synonym_lookup_index') {
|
|
1132
|
-
|
|
1168
|
+
const result = await this.getTotalSynonymCount();
|
|
1169
|
+
return { body: result, statusCode: 200 };
|
|
1133
1170
|
}
|
|
1134
|
-
|
|
1171
|
+
const result = await this.countAll();
|
|
1172
|
+
return { body: result, statusCode: 200 };
|
|
1135
1173
|
}
|
|
1136
1174
|
};
|
|
1137
1175
|
}
|
package/package.json
CHANGED