@toxplanet/pegasus-sdk 1.0.1 → 1.1.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/lib/sync.js CHANGED
@@ -1,41 +1,43 @@
1
- class SyncService {
2
- constructor(connection) {}
3
-
4
- async syncBatch(batchSize) {}
5
-
6
- async syncAll() {}
7
-
8
- async syncContinuous(intervalMs) {}
9
-
10
- async stopContinuousSync() {}
11
-
12
- async getPendingCount() {}
13
-
14
- async getOldestPending() {}
15
-
16
- async getSyncLag() {}
17
-
18
- async getFailedEntries(minRetryCount) {}
19
-
20
- async retryFailed(outboxId) {}
21
-
22
- async retryAllFailed() {}
23
-
24
- async markAsProcessed(outboxId) {}
25
-
26
- async deleteProcessedOlderThan(days) {}
27
-
28
- async cleanupOutbox(daysToKeep) {}
29
-
30
- async getSyncStats(timeWindowMinutes) {}
31
-
32
- async getSyncThroughput() {}
33
-
34
- async verifySync(chemicalId) {}
35
-
36
- async forceResync(chemicalId) {}
37
-
38
- async getOutboxHealth() {}
39
- }
40
-
41
- module.exports = SyncService;
1
+ class SyncService {
2
+ constructor(connection) {
3
+ this.connection = connection;
4
+ }
5
+
6
+ async syncBatch(batchSize) {}
7
+
8
+ async syncAll() {}
9
+
10
+ async syncContinuous(intervalMs) {}
11
+
12
+ async stopContinuousSync() {}
13
+
14
+ async getPendingCount() {}
15
+
16
+ async getOldestPending() {}
17
+
18
+ async getSyncLag() {}
19
+
20
+ async getFailedEntries(minRetryCount) {}
21
+
22
+ async retryFailed(outboxId) {}
23
+
24
+ async retryAllFailed() {}
25
+
26
+ async markAsProcessed(outboxId) {}
27
+
28
+ async deleteProcessedOlderThan(days) {}
29
+
30
+ async cleanupOutbox(daysToKeep) {}
31
+
32
+ async getSyncStats(timeWindowMinutes) {}
33
+
34
+ async getSyncThroughput() {}
35
+
36
+ async verifySync(chemicalId) {}
37
+
38
+ async forceResync(chemicalId) {}
39
+
40
+ async getOutboxHealth() {}
41
+ }
42
+
43
+ module.exports = SyncService;
package/lib/utils.js CHANGED
@@ -1,47 +1,49 @@
1
- class UtilsService {
2
- constructor(connection) {}
3
-
4
- async executeBatch(operations, batchSize, concurrency) {}
5
-
6
- async withTransaction(callback) {}
7
-
8
- async withRetry(operation, maxRetries, backoffMs) {}
9
-
10
- validateChemical(chemical) {}
11
-
12
- validateDocument(document) {}
13
-
14
- validateIdentifier(identifier) {}
15
-
16
- validateCAS(casNumber) {}
17
-
18
- transformForOpenSearch(chemical) {}
19
-
20
- transformFromElasticsearch(esDocument) {}
21
-
22
- transformFromDynamoDB(dynamoItem) {}
23
-
24
- buildOpenSearchQuery(searchTerm, searchType) {}
25
-
26
- buildPostgresFilter(filters) {}
27
-
28
- parseChemicalIdentifiers(identifiers) {}
29
-
30
- parseSynonyms(synonyms) {}
31
-
32
- extractCASFromText(text) {}
33
-
34
- sanitizeSearchTerm(term) {}
35
-
36
- generateSourceId(chemical) {}
37
-
38
- calculateChecksum(data) {}
39
-
40
- formatError(error) {}
41
-
42
- logOperation(operation, duration, metadata) {}
43
-
44
- getTimestamp() {}
45
- }
46
-
47
- module.exports = UtilsService;
1
+ class UtilsService {
2
+ constructor(connection) {
3
+ this.connection = connection;
4
+ }
5
+
6
+ async executeBatch(operations, batchSize, concurrency) {}
7
+
8
+ async withTransaction(callback) {}
9
+
10
+ async withRetry(operation, maxRetries, backoffMs) {}
11
+
12
+ validateChemical(chemical) {}
13
+
14
+ validateDocument(document) {}
15
+
16
+ validateIdentifier(identifier) {}
17
+
18
+ validateCAS(casNumber) {}
19
+
20
+ transformForOpenSearch(chemical) {}
21
+
22
+ transformFromElasticsearch(esDocument) {}
23
+
24
+ transformFromDynamoDB(dynamoItem) {}
25
+
26
+ buildOpenSearchQuery(searchTerm, searchType) {}
27
+
28
+ buildPostgresFilter(filters) {}
29
+
30
+ parseChemicalIdentifiers(identifiers) {}
31
+
32
+ parseSynonyms(synonyms) {}
33
+
34
+ extractCASFromText(text) {}
35
+
36
+ sanitizeSearchTerm(term) {}
37
+
38
+ generateSourceId(chemical) {}
39
+
40
+ calculateChecksum(data) {}
41
+
42
+ formatError(error) {}
43
+
44
+ logOperation(operation, duration, metadata) {}
45
+
46
+ getTimestamp() {}
47
+ }
48
+
49
+ module.exports = UtilsService;
package/package.json CHANGED
@@ -1,25 +1,48 @@
1
- {
2
- "name": "@toxplanet/pegasus-sdk",
3
- "version": "1.0.1",
4
- "description": "SDK for migrating chemical data to Pegasus PostgreSQL + OpenSearch architecture",
5
- "main": "index.js",
6
- "scripts": {
7
- "test:search": "node tests/search.js",
8
- "test:chemicals": "node tests/chemicals.js"
9
- },
10
- "keywords": [
11
- ],
12
- "author": "Chemical Research Development Team",
13
- "license": "MIT",
14
- "dependencies": {
15
- "@toxplanet/tphelper": "1.2.8",
16
- "pg": "^8.11.3",
17
- "drizzle-orm": "^0.30.0",
18
- "@opensearch-project/opensearch": "^2.5.0",
19
- "@aws-sdk/client-secrets-manager": "^3.490.0",
20
- "@aws-sdk/credential-providers": "^3.490.0"
21
- },
22
- "engines": {
23
- "node": ">=18.0.0"
24
- }
25
- }
1
+ {
2
+ "name": "@toxplanet/pegasus-sdk",
3
+ "version": "1.1.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
+ "pg": "^8.11.3",
29
+ "drizzle-orm": "^0.30.0",
30
+ "@opensearch-project/opensearch": "^2.5.0",
31
+ "@aws-sdk/client-secrets-manager": "^3.490.0",
32
+ "@aws-sdk/credential-providers": "^3.490.0"
33
+ },
34
+ "engines": {
35
+ "node": ">=18.0.0"
36
+ },
37
+ "files": [
38
+ "index.js",
39
+ "lib/",
40
+ "config/",
41
+ "README.md",
42
+ "ELASTICSEARCH_CLIENT.md",
43
+ "LICENSE"
44
+ ],
45
+ "devDependencies": {
46
+ "vitest": "^1.2.0"
47
+ }
48
+ }
package/env.example DELETED
@@ -1,21 +0,0 @@
1
- NODE_ENV=development
2
-
3
- # Pegasus SDK Configuration Overrides
4
- PEGASUS_SDK_DB_SECRET_ARN=arn:aws:secretsmanager:us-east-1:292931567094:secret:rds!cluster-b851c3ce-58cc-41cd-aeae-05cc7f5e031a-ZYSjiI
5
- PEGASUS_SDK_OPENSEARCH_ENDPOINT=https://war8lk73nzswquk8dcz1.us-east-1.aoss.amazonaws.com
6
- PEGASUS_SDK_AWS_REGION=us-east-1
7
-
8
- # Database Configuration
9
- PEGASUS_SDK_DATABASE_HOST=cr-chemicals.cluster-cz0iqdg8irhb.us-east-1.rds.amazonaws.com
10
- PEGASUS_SDK_DATABASE_NAME=chemicals
11
-
12
- # OpenSearch Configuration
13
- PEGASUS_SDK_OPENSEARCH_INDEX=chemicals
14
-
15
- # PostgreSQL Connection Pool Settings (optional)
16
- PEGASUS_SDK_MAX_CONNECTIONS=2
17
- PEGASUS_SDK_MIN_CONNECTIONS=0
18
- PEGASUS_SDK_IDLE_TIMEOUT=30000
19
- PEGASUS_SDK_CONNECTION_TIMEOUT=5000
20
- PEGASUS_SDK_STATEMENT_TIMEOUT=30000
21
- PEGASUS_SDK_QUERY_TIMEOUT=30000
package/index.d.ts DELETED
@@ -1,252 +0,0 @@
1
- export interface PostgresConfig {
2
- maxConnections?: number;
3
- minConnections?: number;
4
- idleTimeoutMillis?: number;
5
- connectionTimeoutMillis?: number;
6
- statementTimeout?: number;
7
- queryTimeout?: number;
8
- }
9
-
10
- export interface DatabaseConfig {
11
- host?: string;
12
- name?: string;
13
- }
14
-
15
- export interface PegasusConfig {
16
- environment?: string;
17
- region?: string;
18
- secretName?: string;
19
- openSearchEndpoint?: string;
20
- openSearchIndex?: string;
21
- database?: DatabaseConfig;
22
- postgres?: PostgresConfig;
23
- }
24
-
25
- export interface Chemical {
26
- chemical_id?: string;
27
- source_id: string;
28
- chemical_name: string;
29
- chemical_identifiers: Identifier[];
30
- chemical_synonyms: string[];
31
- chemical_categories: string[];
32
- chemical_meta: Record<string, any>;
33
- created_at?: Date;
34
- updated_at?: Date;
35
- }
36
-
37
- export interface Identifier {
38
- type: string;
39
- value: string;
40
- }
41
-
42
- export interface Document {
43
- document_id?: string;
44
- document_path: string;
45
- processed_at?: Date;
46
- cas_count?: number;
47
- }
48
-
49
- export interface OutboxEntry {
50
- outbox_id: number;
51
- chemical_id: string;
52
- operation: 'INSERT' | 'UPDATE' | 'DELETE';
53
- created_at: Date;
54
- processed_at?: Date;
55
- retry_count: number;
56
- last_error?: string;
57
- }
58
-
59
- export interface ConnectionStatus {
60
- postgres: {
61
- connected: boolean;
62
- timestamp?: Date;
63
- version?: string;
64
- poolSize?: number;
65
- idleConnections?: number;
66
- waitingRequests?: number;
67
- error?: string;
68
- };
69
- opensearch: {
70
- connected: boolean;
71
- version?: string;
72
- cluster?: string;
73
- error?: string;
74
- } | null;
75
- environment: string;
76
- region: string;
77
- }
78
-
79
- export declare class PegasusConnection {
80
- constructor(config?: PegasusConfig);
81
- getSecret(): Promise<any>;
82
- connect(): Promise<void>;
83
- disconnect(): Promise<void>;
84
- getPostgresClient(): any;
85
- getOpenSearchClient(): any;
86
- getOpenSearchIndex(): string;
87
- testConnection(): Promise<ConnectionStatus>;
88
- query(sql: string, params?: any[]): Promise<any>;
89
- getClient(): Promise<any>;
90
- transaction(callback: (client: any) => Promise<any>): Promise<any>;
91
- }
92
-
93
- export declare class ChemicalsService {
94
- constructor(connection: PegasusConnection);
95
- bulkIndexFielded(documents: any[]): Promise<void>;
96
- bulkIndexFulltext(documents: any[]): Promise<void>;
97
- bulkIndexSubstances(substances: any[]): Promise<void>;
98
- createChemical(chemical: Chemical): Promise<Chemical>;
99
- updateChemical(chemicalId: string, updates: Partial<Chemical>): Promise<Chemical>;
100
- deleteChemical(chemicalId: string): Promise<void>;
101
- deleteBySourceId(sourceId: string): Promise<void>;
102
- deleteCollection(collectionName: string): Promise<number>;
103
- updateCollectionProperty(collectionName: string, propertyPath: string, newValue: any): Promise<number>;
104
- bulkUpdateProperty(filter: any, propertyPath: string, newValue: any): Promise<number>;
105
- getChemicalById(chemicalId: string): Promise<Chemical>;
106
- getChemicalBySourceId(sourceId: string): Promise<Chemical>;
107
- getChemicalsByCAS(casNumber: string): Promise<Chemical[]>;
108
- getChemicalsByIdentifier(identifierType: string, identifierValue: string): Promise<Chemical[]>;
109
- countAll(): Promise<number>;
110
- countByCollection(collectionName: string): Promise<number>;
111
- countByIdentifier(identifierValue: string): Promise<number>;
112
- countByCAS(casNumber: string): Promise<number>;
113
- getTotalSynonymCount(): Promise<number>;
114
- getSynonymCount(synonymTerm: string): Promise<number>;
115
- convertIdentifier(fromIdentifier: string, toIdentifierType: string): Promise<any>;
116
- convertIdentifiersBatch(fromIdentifiers: string[], toIdentifierType: string): Promise<any[]>;
117
- searchByName(searchTerm: string, limit?: number): Promise<SearchResults>;
118
- searchBySynonym(synonymTerm: string, limit?: number): Promise<SearchResults>;
119
- findChemicalsWithoutDocuments(collectionName: string, searchTerm: string, pageSize: number): Promise<Chemical[]>;
120
- countChemicalsWithoutDocuments(collectionName: string): Promise<number>;
121
- }
122
-
123
- export declare class DocumentsService {
124
- constructor(connection: PegasusConnection);
125
- createDocument(documentPath: string, casNumbers: string[]): Promise<Document>;
126
- bulkCreateDocuments(documents: any[]): Promise<void>;
127
- updateDocument(documentId: string, updates: Partial<Document>): Promise<Document>;
128
- deleteDocument(documentId: string): Promise<void>;
129
- deleteDocumentByPath(documentPath: string): Promise<void>;
130
- getDocumentById(documentId: string): Promise<Document>;
131
- getDocumentByPath(documentPath: string): Promise<Document>;
132
- getDocumentsByCAS(casNumber: string): Promise<Document[]>;
133
- getCASByDocument(documentId: string): Promise<string[]>;
134
- getCASByDocumentPath(documentPath: string): Promise<string[]>;
135
- addCASToDocument(documentId: string, casNumber: string): Promise<void>;
136
- addCASToDocumentBatch(documentId: string, casNumbers: string[]): Promise<void>;
137
- removeCASFromDocument(documentId: string, casNumber: string): Promise<void>;
138
- findDocumentsWithMultipleCAS(casNumbers: string[], requireAll: boolean): Promise<Document[]>;
139
- countDocuments(): Promise<number>;
140
- countDocumentsByCAS(casNumber: string): Promise<number>;
141
- countUniqueCAS(): Promise<number>;
142
- getTopCASByDocumentCount(limit: number): Promise<any[]>;
143
- extractTextFromPDF(pdfBuffer: Buffer): Promise<string>;
144
- extractCASFromText(text: string): Promise<string[]>;
145
- processDocument(documentPath: string, documentData: any): Promise<Document>;
146
- }
147
-
148
- export interface SearchOptions {
149
- limit?: number;
150
- casExact?: number;
151
- casPrefix?: number;
152
- nameExact?: number;
153
- namePrefix?: number;
154
- identifierExact?: number;
155
- identifierPrefix?: number;
156
- synonymExact?: number;
157
- synonymPrefix?: number;
158
- }
159
-
160
- export interface ChemicalSearchResult {
161
- id: number;
162
- name: string;
163
- cas: string[];
164
- identifiers: string[];
165
- synonyms: string[];
166
- score: number;
167
- }
168
-
169
- export interface SearchResults {
170
- results: ChemicalSearchResult[];
171
- }
172
-
173
- export declare class SearchService {
174
- constructor(connection: PegasusConnection);
175
- searchChemicals(query: string, options?: SearchOptions): Promise<SearchResults>;
176
- searchStartsWith(searchTerm: string, limit?: number): Promise<SearchResults>;
177
- searchContains(searchTerm: string, limit?: number): Promise<SearchResults>;
178
- searchExact(searchTerm: string, limit?: number): Promise<SearchResults>;
179
- searchByCAS(casNumber: string, searchType?: string): Promise<SearchResults>;
180
- searchByIdentifier(identifierValue: string, searchType?: string): Promise<SearchResults>;
181
- searchBySynonym(synonymTerm: string, searchType?: string): Promise<SearchResults>;
182
- advancedSearch(queryBuilder: any): Promise<any[]>;
183
- searchWithFilters(searchTerm: string, filters: any, limit: number): Promise<any[]>;
184
- searchByCollection(collectionName: string, searchTerm: string, limit: number): Promise<any[]>;
185
- aggregateByCategory(): Promise<any>;
186
- aggregateByIdentifierType(): Promise<any>;
187
- getSearchSuggestions(partialTerm: string, limit: number): Promise<string[]>;
188
- findSimilarChemicals(chemicalId: string, limit: number): Promise<any[]>;
189
- }
190
-
191
- export declare class SyncService {
192
- constructor(connection: PegasusConnection);
193
- syncBatch(batchSize: number): Promise<number>;
194
- syncAll(): Promise<number>;
195
- syncContinuous(intervalMs: number): Promise<void>;
196
- stopContinuousSync(): Promise<void>;
197
- getPendingCount(): Promise<number>;
198
- getOldestPending(): Promise<Date>;
199
- getSyncLag(): Promise<number>;
200
- getFailedEntries(minRetryCount: number): Promise<OutboxEntry[]>;
201
- retryFailed(outboxId: number): Promise<void>;
202
- retryAllFailed(): Promise<number>;
203
- markAsProcessed(outboxId: number): Promise<void>;
204
- deleteProcessedOlderThan(days: number): Promise<number>;
205
- cleanupOutbox(daysToKeep: number): Promise<number>;
206
- getSyncStats(timeWindowMinutes: number): Promise<any>;
207
- getSyncThroughput(): Promise<number>;
208
- verifySync(chemicalId: string): Promise<boolean>;
209
- forceResync(chemicalId: string): Promise<void>;
210
- getOutboxHealth(): Promise<any>;
211
- }
212
-
213
-
214
- export declare class UtilsService {
215
- constructor(connection: PegasusConnection);
216
- executeBatch(operations: any[], batchSize: number, concurrency: number): Promise<void>;
217
- withTransaction(callback: () => Promise<any>): Promise<any>;
218
- withRetry(operation: () => Promise<any>, maxRetries: number, backoffMs: number): Promise<any>;
219
- validateChemical(chemical: Chemical): boolean;
220
- validateDocument(document: Document): boolean;
221
- validateIdentifier(identifier: Identifier): boolean;
222
- validateCAS(casNumber: string): boolean;
223
- transformForOpenSearch(chemical: Chemical): any;
224
- transformFromElasticsearch(esDocument: any): Chemical;
225
- transformFromDynamoDB(dynamoItem: any): Chemical;
226
- buildOpenSearchQuery(searchTerm: string, searchType: string): any;
227
- buildPostgresFilter(filters: any): any;
228
- parseChemicalIdentifiers(identifiers: any): Identifier[];
229
- parseSynonyms(synonyms: any): string[];
230
- extractCASFromText(text: string): string[];
231
- sanitizeSearchTerm(term: string): string;
232
- generateSourceId(chemical: Chemical): string;
233
- calculateChecksum(data: any): string;
234
- formatError(error: Error): any;
235
- logOperation(operation: string, duration: number, metadata: any): void;
236
- getTimestamp(): Date;
237
- }
238
-
239
-
240
- export default class PegasusSDK {
241
- connection: PegasusConnection;
242
- chemicals: ChemicalsService;
243
- documents: DocumentsService;
244
- search: SearchService;
245
- sync: SyncService;
246
- utils: UtilsService;
247
-
248
- constructor(config: PegasusConfig);
249
- connect(): Promise<void>;
250
- disconnect(): Promise<void>;
251
- healthCheck(): Promise<any>;
252
- }