@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
package/esm/Alert.mjs CHANGED
@@ -377,6 +377,27 @@ export const Alert = {
377
377
  }
378
378
  catch (error) {
379
379
  lastError = error;
380
+ // Check for constraint violations FIRST - these are NEVER retryable
381
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
382
+ error.message?.includes('violates unique constraint') ||
383
+ error.message?.includes('violates foreign key constraint') ||
384
+ error.message?.includes('unique constraint') ||
385
+ error.message?.includes('23514') ||
386
+ error.message?.includes('23505') ||
387
+ error.message?.includes('P2002') ||
388
+ error.message?.includes('P2003');
389
+ if (isConstraintViolation) {
390
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
391
+ logger.error("Non-retryable constraint violation in createOneAlert", {
392
+ operation: 'createOneAlert',
393
+ model: 'Alert',
394
+ error: String(error),
395
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
396
+ errorCategory: 'CONSTRAINT_VIOLATION',
397
+ isRetryable: false,
398
+ });
399
+ throw error;
400
+ }
380
401
  // Check if this is a database connection error that we should retry
381
402
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
382
403
  error.message?.includes('Cannot reach database server') ||
@@ -386,12 +407,22 @@ export const Alert = {
386
407
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
387
408
  retryCount++;
388
409
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
389
- logger.warn("Database connection error, retrying...");
410
+ logger.warn("Database connection error in createOneAlert, retrying...", {
411
+ operation: 'createOneAlert',
412
+ model: 'Alert',
413
+ attempt: retryCount,
414
+ maxRetries: MAX_RETRIES,
415
+ });
390
416
  await new Promise(resolve => setTimeout(resolve, delay));
391
417
  continue;
392
418
  }
393
- // Log the error and rethrow
394
- logger.error("Database error occurred", { error: String(error) });
419
+ // Log structured error details and rethrow
420
+ logger.error("Database create operation failed", {
421
+ operation: 'createOneAlert',
422
+ model: 'Alert',
423
+ error: String(error),
424
+ isRetryable: isConnectionError,
425
+ });
395
426
  throw error;
396
427
  }
397
428
  }
@@ -461,6 +492,27 @@ export const Alert = {
461
492
  }
462
493
  catch (error) {
463
494
  lastError = error;
495
+ // Check for constraint violations FIRST - these are NEVER retryable
496
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
497
+ error.message?.includes('violates unique constraint') ||
498
+ error.message?.includes('violates foreign key constraint') ||
499
+ error.message?.includes('unique constraint') ||
500
+ error.message?.includes('23514') ||
501
+ error.message?.includes('23505') ||
502
+ error.message?.includes('P2002') ||
503
+ error.message?.includes('P2003');
504
+ if (isConstraintViolation) {
505
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
506
+ logger.error("Non-retryable constraint violation in createManyAlert", {
507
+ operation: 'createManyAlert',
508
+ model: 'Alert',
509
+ error: String(error),
510
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
511
+ errorCategory: 'CONSTRAINT_VIOLATION',
512
+ isRetryable: false,
513
+ });
514
+ throw error;
515
+ }
464
516
  // Check if this is a database connection error that we should retry
465
517
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
466
518
  error.message?.includes('Cannot reach database server') ||
@@ -470,12 +522,22 @@ export const Alert = {
470
522
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
471
523
  retryCount++;
472
524
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
473
- logger.warn("Database connection error, retrying...");
525
+ logger.warn("Database connection error in createManyAlert, retrying...", {
526
+ operation: 'createManyAlert',
527
+ model: 'Alert',
528
+ attempt: retryCount,
529
+ maxRetries: MAX_RETRIES,
530
+ });
474
531
  await new Promise(resolve => setTimeout(resolve, delay));
475
532
  continue;
476
533
  }
477
- // Log the error and rethrow
478
- logger.error("Database error occurred", { error: String(error) });
534
+ // Log structured error details and rethrow
535
+ logger.error("Database createMany operation failed", {
536
+ operation: 'createManyAlert',
537
+ model: 'Alert',
538
+ error: String(error),
539
+ isRetryable: isConnectionError,
540
+ });
479
541
  throw error;
480
542
  }
481
543
  }
@@ -1638,6 +1700,28 @@ export const Alert = {
1638
1700
  }
1639
1701
  catch (error) {
1640
1702
  lastError = error;
1703
+ // Check for constraint violations FIRST - these are NEVER retryable
1704
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
1705
+ error.message?.includes('violates unique constraint') ||
1706
+ error.message?.includes('violates foreign key constraint') ||
1707
+ error.message?.includes('unique constraint') ||
1708
+ error.message?.includes('23514') ||
1709
+ error.message?.includes('23505') ||
1710
+ error.message?.includes('P2002') ||
1711
+ error.message?.includes('P2003');
1712
+ if (isConstraintViolation) {
1713
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
1714
+ logger.error("Non-retryable constraint violation in updateOneAlert", {
1715
+ operation: 'updateOneAlert',
1716
+ model: 'Alert',
1717
+ error: String(error),
1718
+ recordId: props.id,
1719
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
1720
+ errorCategory: 'CONSTRAINT_VIOLATION',
1721
+ isRetryable: false,
1722
+ });
1723
+ throw error;
1724
+ }
1641
1725
  // Check if this is a database connection error that we should retry
1642
1726
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
1643
1727
  error.message?.includes('Cannot reach database server') ||
@@ -1647,12 +1731,24 @@ export const Alert = {
1647
1731
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1648
1732
  retryCount++;
1649
1733
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1650
- logger.warn("Database connection error, retrying...");
1734
+ logger.warn("Database connection error in updateOneAlert, retrying...", {
1735
+ operation: 'updateOneAlert',
1736
+ model: 'Alert',
1737
+ attempt: retryCount,
1738
+ maxRetries: MAX_RETRIES,
1739
+ recordId: props.id,
1740
+ });
1651
1741
  await new Promise(resolve => setTimeout(resolve, delay));
1652
1742
  continue;
1653
1743
  }
1654
- // Log the error and rethrow
1655
- logger.error("Database error occurred", { error: String(error) });
1744
+ // Log structured error details and rethrow
1745
+ logger.error("Database update operation failed", {
1746
+ operation: 'updateOneAlert',
1747
+ model: 'Alert',
1748
+ error: String(error),
1749
+ recordId: props.id,
1750
+ isRetryable: isConnectionError,
1751
+ });
1656
1752
  throw error;
1657
1753
  }
1658
1754
  }
@@ -3103,6 +3199,28 @@ export const Alert = {
3103
3199
  }
3104
3200
  catch (error) {
3105
3201
  lastError = error;
3202
+ // Check for constraint violations FIRST - these are NEVER retryable
3203
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
3204
+ error.message?.includes('violates unique constraint') ||
3205
+ error.message?.includes('violates foreign key constraint') ||
3206
+ error.message?.includes('unique constraint') ||
3207
+ error.message?.includes('23514') ||
3208
+ error.message?.includes('23505') ||
3209
+ error.message?.includes('P2002') ||
3210
+ error.message?.includes('P2003');
3211
+ if (isConstraintViolation) {
3212
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
3213
+ logger.error("Non-retryable constraint violation in upsertOneAlert", {
3214
+ operation: 'upsertOneAlert',
3215
+ model: 'Alert',
3216
+ error: String(error),
3217
+ recordId: props.id,
3218
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
3219
+ errorCategory: 'CONSTRAINT_VIOLATION',
3220
+ isRetryable: false,
3221
+ });
3222
+ throw error;
3223
+ }
3106
3224
  // Check if this is a database connection error that we should retry
3107
3225
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
3108
3226
  error.message?.includes('Cannot reach database server') ||
@@ -3112,12 +3230,24 @@ export const Alert = {
3112
3230
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
3113
3231
  retryCount++;
3114
3232
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
3115
- logger.warn("Database connection error, retrying...");
3233
+ logger.warn("Database connection error in upsertOneAlert, retrying...", {
3234
+ operation: 'upsertOneAlert',
3235
+ model: 'Alert',
3236
+ attempt: retryCount,
3237
+ maxRetries: MAX_RETRIES,
3238
+ recordId: props.id,
3239
+ });
3116
3240
  await new Promise(resolve => setTimeout(resolve, delay));
3117
3241
  continue;
3118
3242
  }
3119
- // Log the error and rethrow
3120
- logger.error("Database error occurred", { error: String(error) });
3243
+ // Log structured error details and rethrow
3244
+ logger.error("Database upsert operation failed", {
3245
+ operation: 'upsertOneAlert',
3246
+ model: 'Alert',
3247
+ error: String(error),
3248
+ recordId: props.id,
3249
+ isRetryable: isConnectionError,
3250
+ });
3121
3251
  throw error;
3122
3252
  }
3123
3253
  }
@@ -4280,6 +4410,27 @@ export const Alert = {
4280
4410
  }
4281
4411
  catch (error) {
4282
4412
  lastError = error;
4413
+ // Check for constraint violations FIRST - these are NEVER retryable
4414
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4415
+ error.message?.includes('violates unique constraint') ||
4416
+ error.message?.includes('violates foreign key constraint') ||
4417
+ error.message?.includes('unique constraint') ||
4418
+ error.message?.includes('23514') ||
4419
+ error.message?.includes('23505') ||
4420
+ error.message?.includes('P2002') ||
4421
+ error.message?.includes('P2003');
4422
+ if (isConstraintViolation) {
4423
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4424
+ logger.error("Non-retryable constraint violation in updateManyAlert", {
4425
+ operation: 'updateManyAlert',
4426
+ model: 'Alert',
4427
+ error: String(error),
4428
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4429
+ errorCategory: 'CONSTRAINT_VIOLATION',
4430
+ isRetryable: false,
4431
+ });
4432
+ throw error;
4433
+ }
4283
4434
  // Check if this is a database connection error that we should retry
4284
4435
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4285
4436
  error.message?.includes('Cannot reach database server') ||
@@ -4289,12 +4440,22 @@ export const Alert = {
4289
4440
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4290
4441
  retryCount++;
4291
4442
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4292
- logger.warn("Database connection error, retrying...");
4443
+ logger.warn("Database connection error in updateManyAlert, retrying...", {
4444
+ operation: 'updateManyAlert',
4445
+ model: 'Alert',
4446
+ attempt: retryCount,
4447
+ maxRetries: MAX_RETRIES,
4448
+ });
4293
4449
  await new Promise(resolve => setTimeout(resolve, delay));
4294
4450
  continue;
4295
4451
  }
4296
- // Log the error and rethrow
4297
- logger.error("Database error occurred", { error: String(error) });
4452
+ // Log structured error details and rethrow
4453
+ logger.error("Database updateMany operation failed", {
4454
+ operation: 'updateManyAlert',
4455
+ model: 'Alert',
4456
+ error: String(error),
4457
+ isRetryable: isConnectionError,
4458
+ });
4298
4459
  throw error;
4299
4460
  }
4300
4461
  }
@@ -4352,6 +4513,31 @@ export const Alert = {
4352
4513
  }
4353
4514
  catch (error) {
4354
4515
  lastError = error;
4516
+ // Check for constraint violations FIRST - these are NEVER retryable
4517
+ // (e.g., foreign key constraints preventing deletion)
4518
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4519
+ error.message?.includes('violates unique constraint') ||
4520
+ error.message?.includes('violates foreign key constraint') ||
4521
+ error.message?.includes('unique constraint') ||
4522
+ error.message?.includes('23514') ||
4523
+ error.message?.includes('23505') ||
4524
+ error.message?.includes('23503') ||
4525
+ error.message?.includes('P2002') ||
4526
+ error.message?.includes('P2003') ||
4527
+ error.message?.includes('P2014');
4528
+ if (isConstraintViolation) {
4529
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4530
+ logger.error("Non-retryable constraint violation in deleteOneAlert", {
4531
+ operation: 'deleteOneAlert',
4532
+ model: 'Alert',
4533
+ error: String(error),
4534
+ recordId: props.id,
4535
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4536
+ errorCategory: 'CONSTRAINT_VIOLATION',
4537
+ isRetryable: false,
4538
+ });
4539
+ throw error;
4540
+ }
4355
4541
  // Check if this is a database connection error that we should retry
4356
4542
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4357
4543
  error.message?.includes('Cannot reach database server') ||
@@ -4361,12 +4547,24 @@ export const Alert = {
4361
4547
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4362
4548
  retryCount++;
4363
4549
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4364
- logger.warn("Database connection error, retrying...");
4550
+ logger.warn("Database connection error in deleteOneAlert, retrying...", {
4551
+ operation: 'deleteOneAlert',
4552
+ model: 'Alert',
4553
+ attempt: retryCount,
4554
+ maxRetries: MAX_RETRIES,
4555
+ recordId: props.id,
4556
+ });
4365
4557
  await new Promise(resolve => setTimeout(resolve, delay));
4366
4558
  continue;
4367
4559
  }
4368
- // Log the error and rethrow
4369
- logger.error("Database error occurred", { error: String(error) });
4560
+ // Log structured error details and rethrow
4561
+ logger.error("Database delete operation failed", {
4562
+ operation: 'deleteOneAlert',
4563
+ model: 'Alert',
4564
+ error: String(error),
4565
+ recordId: props.id,
4566
+ isRetryable: isConnectionError,
4567
+ });
4370
4568
  throw error;
4371
4569
  }
4372
4570
  }
@@ -4438,12 +4636,22 @@ export const Alert = {
4438
4636
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4439
4637
  retryCount++;
4440
4638
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4441
- logger.warn("Database connection error, retrying...");
4639
+ logger.warn("Database connection error in getAlert, retrying...", {
4640
+ operation: 'getAlert',
4641
+ model: 'Alert',
4642
+ attempt: retryCount,
4643
+ maxRetries: MAX_RETRIES,
4644
+ });
4442
4645
  await new Promise(resolve => setTimeout(resolve, delay));
4443
4646
  continue;
4444
4647
  }
4445
- // Log the error and rethrow
4446
- logger.error("Database error occurred", { error: String(error) });
4648
+ // Log structured error details and rethrow
4649
+ logger.error("Database get operation failed", {
4650
+ operation: 'getAlert',
4651
+ model: 'Alert',
4652
+ error: String(error),
4653
+ isRetryable: isConnectionError,
4654
+ });
4447
4655
  throw error;
4448
4656
  }
4449
4657
  }
@@ -4500,12 +4708,22 @@ export const Alert = {
4500
4708
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4501
4709
  retryCount++;
4502
4710
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4503
- logger.warn("Database connection error, retrying...");
4711
+ logger.warn("Database connection error in getAllAlert, retrying...", {
4712
+ operation: 'getAllAlert',
4713
+ model: 'Alert',
4714
+ attempt: retryCount,
4715
+ maxRetries: MAX_RETRIES,
4716
+ });
4504
4717
  await new Promise(resolve => setTimeout(resolve, delay));
4505
4718
  continue;
4506
4719
  }
4507
- // Log the error and rethrow
4508
- logger.error("Database error occurred", { error: String(error) });
4720
+ // Log structured error details and rethrow
4721
+ logger.error("Database getAll operation failed", {
4722
+ operation: 'getAllAlert',
4723
+ model: 'Alert',
4724
+ error: String(error),
4725
+ isRetryable: isConnectionError,
4726
+ });
4509
4727
  throw error;
4510
4728
  }
4511
4729
  }
@@ -4584,12 +4802,22 @@ export const Alert = {
4584
4802
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4585
4803
  retryCount++;
4586
4804
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4587
- logger.warn("Database connection error, retrying...");
4805
+ logger.warn("Database connection error in findManyAlert, retrying...", {
4806
+ operation: 'findManyAlert',
4807
+ model: 'Alert',
4808
+ attempt: retryCount,
4809
+ maxRetries: MAX_RETRIES,
4810
+ });
4588
4811
  await new Promise(resolve => setTimeout(resolve, delay));
4589
4812
  continue;
4590
4813
  }
4591
- // Log the error and rethrow
4592
- logger.error("Database error occurred", { error: String(error) });
4814
+ // Log structured error details and rethrow
4815
+ logger.error("Database findMany operation failed", {
4816
+ operation: 'findManyAlert',
4817
+ model: 'Alert',
4818
+ error: String(error),
4819
+ isRetryable: isConnectionError,
4820
+ });
4593
4821
  throw error;
4594
4822
  }
4595
4823
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Allocation.d.ts","sourceRoot":"","sources":["../../src/Allocation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,kDAAkD,CAAC;AAChG,OAAO,EAA4B,gBAAgB,EAAE,qBAAqB,EAAoB,MAAM,UAAU,CAAC;AA0I7G,eAAO,MAAM,UAAU;IAErB;;;;;OAKG;IAEH;;;;;;OAMG;kBACiB,cAAc,iBAAiB,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAkYtH;;;;;;OAMG;sBACqB,cAAc,EAAE,iBAAiB,gBAAgB,CAAC,qB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