@adaptic/backend-legacy 0.0.903 → 0.0.905

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 (229) hide show
  1. package/ABTest.cjs +291 -63
  2. package/Account.cjs +291 -63
  3. package/AccountLinkingRequest.cjs +291 -63
  4. package/Action.cjs +291 -63
  5. package/Alert.cjs +291 -63
  6. package/Allocation.cjs +291 -63
  7. package/AlpacaAccount.cjs +291 -63
  8. package/AnalyticsConfiguration.cjs +291 -63
  9. package/AnalyticsSnapshot.cjs +291 -63
  10. package/Asset.cjs +291 -63
  11. package/AuditLog.cjs +291 -63
  12. package/Authenticator.cjs +291 -63
  13. package/Configuration.cjs +291 -63
  14. package/ConflictEvent.cjs +291 -63
  15. package/ConnectionHealthSnapshot.cjs +291 -63
  16. package/Customer.cjs +291 -63
  17. package/DeadLetterMessage.cjs +291 -63
  18. package/EconomicEvent.cjs +291 -63
  19. package/Event.cjs +291 -63
  20. package/EventSnapshot.cjs +291 -63
  21. package/FeatureImportanceAnalysis.cjs +291 -63
  22. package/InstitutionalFlowSignal.cjs +291 -63
  23. package/InstitutionalHolding.cjs +291 -63
  24. package/InstitutionalSentimentAlerts.cjs +291 -63
  25. package/InstitutionalSentimentErrors.cjs +291 -63
  26. package/InstitutionalSentimentHistory.cjs +291 -63
  27. package/InstitutionalSentimentMetrics.cjs +291 -63
  28. package/InviteToken.cjs +291 -63
  29. package/LinkedProvider.cjs +291 -63
  30. package/MLTrainingData.cjs +291 -63
  31. package/MarketSentiment.cjs +291 -63
  32. package/ModelArtifact.cjs +291 -63
  33. package/ModelVersion.cjs +291 -63
  34. package/ModelVersionArtifact.cjs +291 -63
  35. package/NewsArticle.cjs +291 -63
  36. package/NewsArticleAssetSentiment.cjs +291 -63
  37. package/OptionsContract.cjs +291 -63
  38. package/OptionsGreeksHistory.cjs +291 -63
  39. package/OptionsPosition.cjs +291 -63
  40. package/OptionsTradeExecution.cjs +291 -63
  41. package/PortfolioGreeksHistory.cjs +291 -63
  42. package/ScheduledOptionOrder.cjs +291 -63
  43. package/Session.cjs +291 -63
  44. package/SignalGeneratorMetrics.cjs +291 -63
  45. package/SignalLineage.cjs +291 -63
  46. package/SignalOutcome.cjs +291 -63
  47. package/SignalPriorityQueue.cjs +291 -63
  48. package/SyncEvent.cjs +291 -63
  49. package/SystemAlert.cjs +291 -63
  50. package/Trade.cjs +291 -63
  51. package/TradeAuditEvent.cjs +291 -63
  52. package/TradeExecutionHistory.cjs +291 -63
  53. package/User.cjs +291 -63
  54. package/VerificationToken.cjs +291 -63
  55. package/WaitlistEntry.cjs +291 -63
  56. package/esm/ABTest.d.ts.map +1 -1
  57. package/esm/ABTest.js.map +1 -1
  58. package/esm/ABTest.mjs +255 -27
  59. package/esm/Account.d.ts.map +1 -1
  60. package/esm/Account.js.map +1 -1
  61. package/esm/Account.mjs +255 -27
  62. package/esm/AccountLinkingRequest.d.ts.map +1 -1
  63. package/esm/AccountLinkingRequest.js.map +1 -1
  64. package/esm/AccountLinkingRequest.mjs +255 -27
  65. package/esm/Action.d.ts.map +1 -1
  66. package/esm/Action.js.map +1 -1
  67. package/esm/Action.mjs +255 -27
  68. package/esm/Alert.d.ts.map +1 -1
  69. package/esm/Alert.js.map +1 -1
  70. package/esm/Alert.mjs +255 -27
  71. package/esm/Allocation.d.ts.map +1 -1
  72. package/esm/Allocation.js.map +1 -1
  73. package/esm/Allocation.mjs +255 -27
  74. package/esm/AlpacaAccount.d.ts.map +1 -1
  75. package/esm/AlpacaAccount.js.map +1 -1
  76. package/esm/AlpacaAccount.mjs +255 -27
  77. package/esm/AnalyticsConfiguration.d.ts.map +1 -1
  78. package/esm/AnalyticsConfiguration.js.map +1 -1
  79. package/esm/AnalyticsConfiguration.mjs +255 -27
  80. package/esm/AnalyticsSnapshot.d.ts.map +1 -1
  81. package/esm/AnalyticsSnapshot.js.map +1 -1
  82. package/esm/AnalyticsSnapshot.mjs +255 -27
  83. package/esm/Asset.d.ts.map +1 -1
  84. package/esm/Asset.js.map +1 -1
  85. package/esm/Asset.mjs +255 -27
  86. package/esm/AuditLog.d.ts.map +1 -1
  87. package/esm/AuditLog.js.map +1 -1
  88. package/esm/AuditLog.mjs +255 -27
  89. package/esm/Authenticator.d.ts.map +1 -1
  90. package/esm/Authenticator.js.map +1 -1
  91. package/esm/Authenticator.mjs +255 -27
  92. package/esm/Configuration.d.ts.map +1 -1
  93. package/esm/Configuration.js.map +1 -1
  94. package/esm/Configuration.mjs +255 -27
  95. package/esm/ConflictEvent.d.ts.map +1 -1
  96. package/esm/ConflictEvent.js.map +1 -1
  97. package/esm/ConflictEvent.mjs +255 -27
  98. package/esm/ConnectionHealthSnapshot.d.ts.map +1 -1
  99. package/esm/ConnectionHealthSnapshot.js.map +1 -1
  100. package/esm/ConnectionHealthSnapshot.mjs +255 -27
  101. package/esm/Customer.d.ts.map +1 -1
  102. package/esm/Customer.js.map +1 -1
  103. package/esm/Customer.mjs +255 -27
  104. package/esm/DeadLetterMessage.d.ts.map +1 -1
  105. package/esm/DeadLetterMessage.js.map +1 -1
  106. package/esm/DeadLetterMessage.mjs +255 -27
  107. package/esm/EconomicEvent.d.ts.map +1 -1
  108. package/esm/EconomicEvent.js.map +1 -1
  109. package/esm/EconomicEvent.mjs +255 -27
  110. package/esm/Event.d.ts.map +1 -1
  111. package/esm/Event.js.map +1 -1
  112. package/esm/Event.mjs +255 -27
  113. package/esm/EventSnapshot.d.ts.map +1 -1
  114. package/esm/EventSnapshot.js.map +1 -1
  115. package/esm/EventSnapshot.mjs +255 -27
  116. package/esm/FeatureImportanceAnalysis.d.ts.map +1 -1
  117. package/esm/FeatureImportanceAnalysis.js.map +1 -1
  118. package/esm/FeatureImportanceAnalysis.mjs +255 -27
  119. package/esm/InstitutionalFlowSignal.d.ts.map +1 -1
  120. package/esm/InstitutionalFlowSignal.js.map +1 -1
  121. package/esm/InstitutionalFlowSignal.mjs +255 -27
  122. package/esm/InstitutionalHolding.d.ts.map +1 -1
  123. package/esm/InstitutionalHolding.js.map +1 -1
  124. package/esm/InstitutionalHolding.mjs +255 -27
  125. package/esm/InstitutionalSentimentAlerts.d.ts.map +1 -1
  126. package/esm/InstitutionalSentimentAlerts.js.map +1 -1
  127. package/esm/InstitutionalSentimentAlerts.mjs +255 -27
  128. package/esm/InstitutionalSentimentErrors.d.ts.map +1 -1
  129. package/esm/InstitutionalSentimentErrors.js.map +1 -1
  130. package/esm/InstitutionalSentimentErrors.mjs +255 -27
  131. package/esm/InstitutionalSentimentHistory.d.ts.map +1 -1
  132. package/esm/InstitutionalSentimentHistory.js.map +1 -1
  133. package/esm/InstitutionalSentimentHistory.mjs +255 -27
  134. package/esm/InstitutionalSentimentMetrics.d.ts.map +1 -1
  135. package/esm/InstitutionalSentimentMetrics.js.map +1 -1
  136. package/esm/InstitutionalSentimentMetrics.mjs +255 -27
  137. package/esm/InviteToken.d.ts.map +1 -1
  138. package/esm/InviteToken.js.map +1 -1
  139. package/esm/InviteToken.mjs +255 -27
  140. package/esm/LinkedProvider.d.ts.map +1 -1
  141. package/esm/LinkedProvider.js.map +1 -1
  142. package/esm/LinkedProvider.mjs +255 -27
  143. package/esm/MLTrainingData.d.ts.map +1 -1
  144. package/esm/MLTrainingData.js.map +1 -1
  145. package/esm/MLTrainingData.mjs +255 -27
  146. package/esm/MarketSentiment.d.ts.map +1 -1
  147. package/esm/MarketSentiment.js.map +1 -1
  148. package/esm/MarketSentiment.mjs +255 -27
  149. package/esm/ModelArtifact.d.ts.map +1 -1
  150. package/esm/ModelArtifact.js.map +1 -1
  151. package/esm/ModelArtifact.mjs +255 -27
  152. package/esm/ModelVersion.d.ts.map +1 -1
  153. package/esm/ModelVersion.js.map +1 -1
  154. package/esm/ModelVersion.mjs +255 -27
  155. package/esm/ModelVersionArtifact.d.ts.map +1 -1
  156. package/esm/ModelVersionArtifact.js.map +1 -1
  157. package/esm/ModelVersionArtifact.mjs +255 -27
  158. package/esm/NewsArticle.d.ts.map +1 -1
  159. package/esm/NewsArticle.js.map +1 -1
  160. package/esm/NewsArticle.mjs +255 -27
  161. package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
  162. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  163. package/esm/NewsArticleAssetSentiment.mjs +255 -27
  164. package/esm/OptionsContract.d.ts.map +1 -1
  165. package/esm/OptionsContract.js.map +1 -1
  166. package/esm/OptionsContract.mjs +255 -27
  167. package/esm/OptionsGreeksHistory.d.ts.map +1 -1
  168. package/esm/OptionsGreeksHistory.js.map +1 -1
  169. package/esm/OptionsGreeksHistory.mjs +255 -27
  170. package/esm/OptionsPosition.d.ts.map +1 -1
  171. package/esm/OptionsPosition.js.map +1 -1
  172. package/esm/OptionsPosition.mjs +255 -27
  173. package/esm/OptionsTradeExecution.d.ts.map +1 -1
  174. package/esm/OptionsTradeExecution.js.map +1 -1
  175. package/esm/OptionsTradeExecution.mjs +255 -27
  176. package/esm/PortfolioGreeksHistory.d.ts.map +1 -1
  177. package/esm/PortfolioGreeksHistory.js.map +1 -1
  178. package/esm/PortfolioGreeksHistory.mjs +255 -27
  179. package/esm/ScheduledOptionOrder.d.ts.map +1 -1
  180. package/esm/ScheduledOptionOrder.js.map +1 -1
  181. package/esm/ScheduledOptionOrder.mjs +255 -27
  182. package/esm/Session.d.ts.map +1 -1
  183. package/esm/Session.js.map +1 -1
  184. package/esm/Session.mjs +255 -27
  185. package/esm/SignalGeneratorMetrics.d.ts.map +1 -1
  186. package/esm/SignalGeneratorMetrics.js.map +1 -1
  187. package/esm/SignalGeneratorMetrics.mjs +255 -27
  188. package/esm/SignalLineage.d.ts.map +1 -1
  189. package/esm/SignalLineage.js.map +1 -1
  190. package/esm/SignalLineage.mjs +255 -27
  191. package/esm/SignalOutcome.d.ts.map +1 -1
  192. package/esm/SignalOutcome.js.map +1 -1
  193. package/esm/SignalOutcome.mjs +255 -27
  194. package/esm/SignalPriorityQueue.d.ts.map +1 -1
  195. package/esm/SignalPriorityQueue.js.map +1 -1
  196. package/esm/SignalPriorityQueue.mjs +255 -27
  197. package/esm/SyncEvent.d.ts.map +1 -1
  198. package/esm/SyncEvent.js.map +1 -1
  199. package/esm/SyncEvent.mjs +255 -27
  200. package/esm/SystemAlert.d.ts.map +1 -1
  201. package/esm/SystemAlert.js.map +1 -1
  202. package/esm/SystemAlert.mjs +255 -27
  203. package/esm/Trade.d.ts.map +1 -1
  204. package/esm/Trade.js.map +1 -1
  205. package/esm/Trade.mjs +255 -27
  206. package/esm/TradeAuditEvent.d.ts.map +1 -1
  207. package/esm/TradeAuditEvent.js.map +1 -1
  208. package/esm/TradeAuditEvent.mjs +255 -27
  209. package/esm/TradeExecutionHistory.d.ts.map +1 -1
  210. package/esm/TradeExecutionHistory.js.map +1 -1
  211. package/esm/TradeExecutionHistory.mjs +255 -27
  212. package/esm/User.d.ts.map +1 -1
  213. package/esm/User.js.map +1 -1
  214. package/esm/User.mjs +255 -27
  215. package/esm/VerificationToken.d.ts.map +1 -1
  216. package/esm/VerificationToken.js.map +1 -1
  217. package/esm/VerificationToken.mjs +255 -27
  218. package/esm/WaitlistEntry.d.ts.map +1 -1
  219. package/esm/WaitlistEntry.js.map +1 -1
  220. package/esm/WaitlistEntry.mjs +255 -27
  221. package/esm/middleware/audit-logger.d.ts +0 -7
  222. package/esm/middleware/audit-logger.d.ts.map +1 -1
  223. package/esm/middleware/audit-logger.js.map +1 -1
  224. package/esm/middleware/audit-logger.mjs +5 -3
  225. package/esm/prismaClient.d.ts.map +1 -1
  226. package/esm/prismaClient.js.map +1 -1
  227. package/esm/prismaClient.mjs +38 -9
  228. package/package.json +1 -1
  229. package/prismaClient.cjs +38 -9
@@ -109,6 +109,27 @@ export const SystemAlert = {
109
109
  }
110
110
  catch (error) {
111
111
  lastError = error;
112
+ // Check for constraint violations FIRST - these are NEVER retryable
113
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
114
+ error.message?.includes('violates unique constraint') ||
115
+ error.message?.includes('violates foreign key constraint') ||
116
+ error.message?.includes('unique constraint') ||
117
+ error.message?.includes('23514') ||
118
+ error.message?.includes('23505') ||
119
+ error.message?.includes('P2002') ||
120
+ error.message?.includes('P2003');
121
+ if (isConstraintViolation) {
122
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
123
+ logger.error("Non-retryable constraint violation in createOneSystemAlert", {
124
+ operation: 'createOneSystemAlert',
125
+ model: 'SystemAlert',
126
+ error: String(error),
127
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
128
+ errorCategory: 'CONSTRAINT_VIOLATION',
129
+ isRetryable: false,
130
+ });
131
+ throw error;
132
+ }
112
133
  // Check if this is a database connection error that we should retry
113
134
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
114
135
  error.message?.includes('Cannot reach database server') ||
@@ -118,12 +139,22 @@ export const SystemAlert = {
118
139
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
119
140
  retryCount++;
120
141
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
121
- logger.warn("Database connection error, retrying...");
142
+ logger.warn("Database connection error in createOneSystemAlert, retrying...", {
143
+ operation: 'createOneSystemAlert',
144
+ model: 'SystemAlert',
145
+ attempt: retryCount,
146
+ maxRetries: MAX_RETRIES,
147
+ });
122
148
  await new Promise(resolve => setTimeout(resolve, delay));
123
149
  continue;
124
150
  }
125
- // Log the error and rethrow
126
- logger.error("Database error occurred", { error: String(error) });
151
+ // Log structured error details and rethrow
152
+ logger.error("Database create operation failed", {
153
+ operation: 'createOneSystemAlert',
154
+ model: 'SystemAlert',
155
+ error: String(error),
156
+ isRetryable: isConnectionError,
157
+ });
127
158
  throw error;
128
159
  }
129
160
  }
@@ -200,6 +231,27 @@ export const SystemAlert = {
200
231
  }
201
232
  catch (error) {
202
233
  lastError = error;
234
+ // Check for constraint violations FIRST - these are NEVER retryable
235
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
236
+ error.message?.includes('violates unique constraint') ||
237
+ error.message?.includes('violates foreign key constraint') ||
238
+ error.message?.includes('unique constraint') ||
239
+ error.message?.includes('23514') ||
240
+ error.message?.includes('23505') ||
241
+ error.message?.includes('P2002') ||
242
+ error.message?.includes('P2003');
243
+ if (isConstraintViolation) {
244
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
245
+ logger.error("Non-retryable constraint violation in createManySystemAlert", {
246
+ operation: 'createManySystemAlert',
247
+ model: 'SystemAlert',
248
+ error: String(error),
249
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
250
+ errorCategory: 'CONSTRAINT_VIOLATION',
251
+ isRetryable: false,
252
+ });
253
+ throw error;
254
+ }
203
255
  // Check if this is a database connection error that we should retry
204
256
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
205
257
  error.message?.includes('Cannot reach database server') ||
@@ -209,12 +261,22 @@ export const SystemAlert = {
209
261
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
210
262
  retryCount++;
211
263
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
212
- logger.warn("Database connection error, retrying...");
264
+ logger.warn("Database connection error in createManySystemAlert, retrying...", {
265
+ operation: 'createManySystemAlert',
266
+ model: 'SystemAlert',
267
+ attempt: retryCount,
268
+ maxRetries: MAX_RETRIES,
269
+ });
213
270
  await new Promise(resolve => setTimeout(resolve, delay));
214
271
  continue;
215
272
  }
216
- // Log the error and rethrow
217
- logger.error("Database error occurred", { error: String(error) });
273
+ // Log structured error details and rethrow
274
+ logger.error("Database createMany operation failed", {
275
+ operation: 'createManySystemAlert',
276
+ model: 'SystemAlert',
277
+ error: String(error),
278
+ isRetryable: isConnectionError,
279
+ });
218
280
  throw error;
219
281
  }
220
282
  }
@@ -349,6 +411,28 @@ export const SystemAlert = {
349
411
  }
350
412
  catch (error) {
351
413
  lastError = error;
414
+ // Check for constraint violations FIRST - these are NEVER retryable
415
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
416
+ error.message?.includes('violates unique constraint') ||
417
+ error.message?.includes('violates foreign key constraint') ||
418
+ error.message?.includes('unique constraint') ||
419
+ error.message?.includes('23514') ||
420
+ error.message?.includes('23505') ||
421
+ error.message?.includes('P2002') ||
422
+ error.message?.includes('P2003');
423
+ if (isConstraintViolation) {
424
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
425
+ logger.error("Non-retryable constraint violation in updateOneSystemAlert", {
426
+ operation: 'updateOneSystemAlert',
427
+ model: 'SystemAlert',
428
+ error: String(error),
429
+ recordId: props.id,
430
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
431
+ errorCategory: 'CONSTRAINT_VIOLATION',
432
+ isRetryable: false,
433
+ });
434
+ throw error;
435
+ }
352
436
  // Check if this is a database connection error that we should retry
353
437
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
354
438
  error.message?.includes('Cannot reach database server') ||
@@ -358,12 +442,24 @@ export const SystemAlert = {
358
442
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
359
443
  retryCount++;
360
444
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
361
- logger.warn("Database connection error, retrying...");
445
+ logger.warn("Database connection error in updateOneSystemAlert, retrying...", {
446
+ operation: 'updateOneSystemAlert',
447
+ model: 'SystemAlert',
448
+ attempt: retryCount,
449
+ maxRetries: MAX_RETRIES,
450
+ recordId: props.id,
451
+ });
362
452
  await new Promise(resolve => setTimeout(resolve, delay));
363
453
  continue;
364
454
  }
365
- // Log the error and rethrow
366
- logger.error("Database error occurred", { error: String(error) });
455
+ // Log structured error details and rethrow
456
+ logger.error("Database update operation failed", {
457
+ operation: 'updateOneSystemAlert',
458
+ model: 'SystemAlert',
459
+ error: String(error),
460
+ recordId: props.id,
461
+ isRetryable: isConnectionError,
462
+ });
367
463
  throw error;
368
464
  }
369
465
  }
@@ -511,6 +607,28 @@ export const SystemAlert = {
511
607
  }
512
608
  catch (error) {
513
609
  lastError = error;
610
+ // Check for constraint violations FIRST - these are NEVER retryable
611
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
612
+ error.message?.includes('violates unique constraint') ||
613
+ error.message?.includes('violates foreign key constraint') ||
614
+ error.message?.includes('unique constraint') ||
615
+ error.message?.includes('23514') ||
616
+ error.message?.includes('23505') ||
617
+ error.message?.includes('P2002') ||
618
+ error.message?.includes('P2003');
619
+ if (isConstraintViolation) {
620
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
621
+ logger.error("Non-retryable constraint violation in upsertOneSystemAlert", {
622
+ operation: 'upsertOneSystemAlert',
623
+ model: 'SystemAlert',
624
+ error: String(error),
625
+ recordId: props.id,
626
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
627
+ errorCategory: 'CONSTRAINT_VIOLATION',
628
+ isRetryable: false,
629
+ });
630
+ throw error;
631
+ }
514
632
  // Check if this is a database connection error that we should retry
515
633
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
516
634
  error.message?.includes('Cannot reach database server') ||
@@ -520,12 +638,24 @@ export const SystemAlert = {
520
638
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
521
639
  retryCount++;
522
640
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
523
- logger.warn("Database connection error, retrying...");
641
+ logger.warn("Database connection error in upsertOneSystemAlert, retrying...", {
642
+ operation: 'upsertOneSystemAlert',
643
+ model: 'SystemAlert',
644
+ attempt: retryCount,
645
+ maxRetries: MAX_RETRIES,
646
+ recordId: props.id,
647
+ });
524
648
  await new Promise(resolve => setTimeout(resolve, delay));
525
649
  continue;
526
650
  }
527
- // Log the error and rethrow
528
- logger.error("Database error occurred", { error: String(error) });
651
+ // Log structured error details and rethrow
652
+ logger.error("Database upsert operation failed", {
653
+ operation: 'upsertOneSystemAlert',
654
+ model: 'SystemAlert',
655
+ error: String(error),
656
+ recordId: props.id,
657
+ isRetryable: isConnectionError,
658
+ });
529
659
  throw error;
530
660
  }
531
661
  }
@@ -660,6 +790,27 @@ export const SystemAlert = {
660
790
  }
661
791
  catch (error) {
662
792
  lastError = error;
793
+ // Check for constraint violations FIRST - these are NEVER retryable
794
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
795
+ error.message?.includes('violates unique constraint') ||
796
+ error.message?.includes('violates foreign key constraint') ||
797
+ error.message?.includes('unique constraint') ||
798
+ error.message?.includes('23514') ||
799
+ error.message?.includes('23505') ||
800
+ error.message?.includes('P2002') ||
801
+ error.message?.includes('P2003');
802
+ if (isConstraintViolation) {
803
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
804
+ logger.error("Non-retryable constraint violation in updateManySystemAlert", {
805
+ operation: 'updateManySystemAlert',
806
+ model: 'SystemAlert',
807
+ error: String(error),
808
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
809
+ errorCategory: 'CONSTRAINT_VIOLATION',
810
+ isRetryable: false,
811
+ });
812
+ throw error;
813
+ }
663
814
  // Check if this is a database connection error that we should retry
664
815
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
665
816
  error.message?.includes('Cannot reach database server') ||
@@ -669,12 +820,22 @@ export const SystemAlert = {
669
820
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
670
821
  retryCount++;
671
822
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
672
- logger.warn("Database connection error, retrying...");
823
+ logger.warn("Database connection error in updateManySystemAlert, retrying...", {
824
+ operation: 'updateManySystemAlert',
825
+ model: 'SystemAlert',
826
+ attempt: retryCount,
827
+ maxRetries: MAX_RETRIES,
828
+ });
673
829
  await new Promise(resolve => setTimeout(resolve, delay));
674
830
  continue;
675
831
  }
676
- // Log the error and rethrow
677
- logger.error("Database error occurred", { error: String(error) });
832
+ // Log structured error details and rethrow
833
+ logger.error("Database updateMany operation failed", {
834
+ operation: 'updateManySystemAlert',
835
+ model: 'SystemAlert',
836
+ error: String(error),
837
+ isRetryable: isConnectionError,
838
+ });
678
839
  throw error;
679
840
  }
680
841
  }
@@ -732,6 +893,31 @@ export const SystemAlert = {
732
893
  }
733
894
  catch (error) {
734
895
  lastError = error;
896
+ // Check for constraint violations FIRST - these are NEVER retryable
897
+ // (e.g., foreign key constraints preventing deletion)
898
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
899
+ error.message?.includes('violates unique constraint') ||
900
+ error.message?.includes('violates foreign key constraint') ||
901
+ error.message?.includes('unique constraint') ||
902
+ error.message?.includes('23514') ||
903
+ error.message?.includes('23505') ||
904
+ error.message?.includes('23503') ||
905
+ error.message?.includes('P2002') ||
906
+ error.message?.includes('P2003') ||
907
+ error.message?.includes('P2014');
908
+ if (isConstraintViolation) {
909
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
910
+ logger.error("Non-retryable constraint violation in deleteOneSystemAlert", {
911
+ operation: 'deleteOneSystemAlert',
912
+ model: 'SystemAlert',
913
+ error: String(error),
914
+ recordId: props.id,
915
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
916
+ errorCategory: 'CONSTRAINT_VIOLATION',
917
+ isRetryable: false,
918
+ });
919
+ throw error;
920
+ }
735
921
  // Check if this is a database connection error that we should retry
736
922
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
737
923
  error.message?.includes('Cannot reach database server') ||
@@ -741,12 +927,24 @@ export const SystemAlert = {
741
927
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
742
928
  retryCount++;
743
929
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
744
- logger.warn("Database connection error, retrying...");
930
+ logger.warn("Database connection error in deleteOneSystemAlert, retrying...", {
931
+ operation: 'deleteOneSystemAlert',
932
+ model: 'SystemAlert',
933
+ attempt: retryCount,
934
+ maxRetries: MAX_RETRIES,
935
+ recordId: props.id,
936
+ });
745
937
  await new Promise(resolve => setTimeout(resolve, delay));
746
938
  continue;
747
939
  }
748
- // Log the error and rethrow
749
- logger.error("Database error occurred", { error: String(error) });
940
+ // Log structured error details and rethrow
941
+ logger.error("Database delete operation failed", {
942
+ operation: 'deleteOneSystemAlert',
943
+ model: 'SystemAlert',
944
+ error: String(error),
945
+ recordId: props.id,
946
+ isRetryable: isConnectionError,
947
+ });
750
948
  throw error;
751
949
  }
752
950
  }
@@ -818,12 +1016,22 @@ export const SystemAlert = {
818
1016
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
819
1017
  retryCount++;
820
1018
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
821
- logger.warn("Database connection error, retrying...");
1019
+ logger.warn("Database connection error in getSystemAlert, retrying...", {
1020
+ operation: 'getSystemAlert',
1021
+ model: 'SystemAlert',
1022
+ attempt: retryCount,
1023
+ maxRetries: MAX_RETRIES,
1024
+ });
822
1025
  await new Promise(resolve => setTimeout(resolve, delay));
823
1026
  continue;
824
1027
  }
825
- // Log the error and rethrow
826
- logger.error("Database error occurred", { error: String(error) });
1028
+ // Log structured error details and rethrow
1029
+ logger.error("Database get operation failed", {
1030
+ operation: 'getSystemAlert',
1031
+ model: 'SystemAlert',
1032
+ error: String(error),
1033
+ isRetryable: isConnectionError,
1034
+ });
827
1035
  throw error;
828
1036
  }
829
1037
  }
@@ -880,12 +1088,22 @@ export const SystemAlert = {
880
1088
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
881
1089
  retryCount++;
882
1090
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
883
- logger.warn("Database connection error, retrying...");
1091
+ logger.warn("Database connection error in getAllSystemAlert, retrying...", {
1092
+ operation: 'getAllSystemAlert',
1093
+ model: 'SystemAlert',
1094
+ attempt: retryCount,
1095
+ maxRetries: MAX_RETRIES,
1096
+ });
884
1097
  await new Promise(resolve => setTimeout(resolve, delay));
885
1098
  continue;
886
1099
  }
887
- // Log the error and rethrow
888
- logger.error("Database error occurred", { error: String(error) });
1100
+ // Log structured error details and rethrow
1101
+ logger.error("Database getAll operation failed", {
1102
+ operation: 'getAllSystemAlert',
1103
+ model: 'SystemAlert',
1104
+ error: String(error),
1105
+ isRetryable: isConnectionError,
1106
+ });
889
1107
  throw error;
890
1108
  }
891
1109
  }
@@ -964,12 +1182,22 @@ export const SystemAlert = {
964
1182
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
965
1183
  retryCount++;
966
1184
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
967
- logger.warn("Database connection error, retrying...");
1185
+ logger.warn("Database connection error in findManySystemAlert, retrying...", {
1186
+ operation: 'findManySystemAlert',
1187
+ model: 'SystemAlert',
1188
+ attempt: retryCount,
1189
+ maxRetries: MAX_RETRIES,
1190
+ });
968
1191
  await new Promise(resolve => setTimeout(resolve, delay));
969
1192
  continue;
970
1193
  }
971
- // Log the error and rethrow
972
- logger.error("Database error occurred", { error: String(error) });
1194
+ // Log structured error details and rethrow
1195
+ logger.error("Database findMany operation failed", {
1196
+ operation: 'findManySystemAlert',
1197
+ model: 'SystemAlert',
1198
+ error: String(error),
1199
+ isRetryable: isConnectionError,
1200
+ });
973
1201
  throw error;
974
1202
  }
975
1203
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Trade.d.ts","sourceRoot":"","sources":["../../src/Trade.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAA4B,gBAAgB,EAAE,qBAAqB,EAAoB,MAAM,UAAU,CAAC;AAsD7G,eAAO,MAAM,KAAK;IAEhB;;;;;OAKG;IAEH;;;;;;OAMG;kBACiB,SAAS,iBAAiB,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IA8H5G;;;;;;OAMG;sBACqB,SAAS,EAAE,iBAAiB,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAmG/H;;;;;;OAMG;kBACiB,SAAS,iBAAiB,gBAAgB,CAAC,qBAAqB,CAAC,GAAG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