@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
@@ -563,6 +563,27 @@ export const LinkedProvider = {
563
563
  }
564
564
  catch (error) {
565
565
  lastError = error;
566
+ // Check for constraint violations FIRST - these are NEVER retryable
567
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
568
+ error.message?.includes('violates unique constraint') ||
569
+ error.message?.includes('violates foreign key constraint') ||
570
+ error.message?.includes('unique constraint') ||
571
+ error.message?.includes('23514') ||
572
+ error.message?.includes('23505') ||
573
+ error.message?.includes('P2002') ||
574
+ error.message?.includes('P2003');
575
+ if (isConstraintViolation) {
576
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
577
+ logger.error("Non-retryable constraint violation in createOneLinkedProvider", {
578
+ operation: 'createOneLinkedProvider',
579
+ model: 'LinkedProvider',
580
+ error: String(error),
581
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
582
+ errorCategory: 'CONSTRAINT_VIOLATION',
583
+ isRetryable: false,
584
+ });
585
+ throw error;
586
+ }
566
587
  // Check if this is a database connection error that we should retry
567
588
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
568
589
  error.message?.includes('Cannot reach database server') ||
@@ -572,12 +593,22 @@ export const LinkedProvider = {
572
593
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
573
594
  retryCount++;
574
595
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
575
- logger.warn("Database connection error, retrying...");
596
+ logger.warn("Database connection error in createOneLinkedProvider, retrying...", {
597
+ operation: 'createOneLinkedProvider',
598
+ model: 'LinkedProvider',
599
+ attempt: retryCount,
600
+ maxRetries: MAX_RETRIES,
601
+ });
576
602
  await new Promise(resolve => setTimeout(resolve, delay));
577
603
  continue;
578
604
  }
579
- // Log the error and rethrow
580
- logger.error("Database error occurred", { error: String(error) });
605
+ // Log structured error details and rethrow
606
+ logger.error("Database create operation failed", {
607
+ operation: 'createOneLinkedProvider',
608
+ model: 'LinkedProvider',
609
+ error: String(error),
610
+ isRetryable: isConnectionError,
611
+ });
581
612
  throw error;
582
613
  }
583
614
  }
@@ -642,6 +673,27 @@ export const LinkedProvider = {
642
673
  }
643
674
  catch (error) {
644
675
  lastError = error;
676
+ // Check for constraint violations FIRST - these are NEVER retryable
677
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
678
+ error.message?.includes('violates unique constraint') ||
679
+ error.message?.includes('violates foreign key constraint') ||
680
+ error.message?.includes('unique constraint') ||
681
+ error.message?.includes('23514') ||
682
+ error.message?.includes('23505') ||
683
+ error.message?.includes('P2002') ||
684
+ error.message?.includes('P2003');
685
+ if (isConstraintViolation) {
686
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
687
+ logger.error("Non-retryable constraint violation in createManyLinkedProvider", {
688
+ operation: 'createManyLinkedProvider',
689
+ model: 'LinkedProvider',
690
+ error: String(error),
691
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
692
+ errorCategory: 'CONSTRAINT_VIOLATION',
693
+ isRetryable: false,
694
+ });
695
+ throw error;
696
+ }
645
697
  // Check if this is a database connection error that we should retry
646
698
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
647
699
  error.message?.includes('Cannot reach database server') ||
@@ -651,12 +703,22 @@ export const LinkedProvider = {
651
703
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
652
704
  retryCount++;
653
705
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
654
- logger.warn("Database connection error, retrying...");
706
+ logger.warn("Database connection error in createManyLinkedProvider, retrying...", {
707
+ operation: 'createManyLinkedProvider',
708
+ model: 'LinkedProvider',
709
+ attempt: retryCount,
710
+ maxRetries: MAX_RETRIES,
711
+ });
655
712
  await new Promise(resolve => setTimeout(resolve, delay));
656
713
  continue;
657
714
  }
658
- // Log the error and rethrow
659
- logger.error("Database error occurred", { error: String(error) });
715
+ // Log structured error details and rethrow
716
+ logger.error("Database createMany operation failed", {
717
+ operation: 'createManyLinkedProvider',
718
+ model: 'LinkedProvider',
719
+ error: String(error),
720
+ isRetryable: isConnectionError,
721
+ });
660
722
  throw error;
661
723
  }
662
724
  }
@@ -1794,6 +1856,28 @@ export const LinkedProvider = {
1794
1856
  }
1795
1857
  catch (error) {
1796
1858
  lastError = error;
1859
+ // Check for constraint violations FIRST - these are NEVER retryable
1860
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
1861
+ error.message?.includes('violates unique constraint') ||
1862
+ error.message?.includes('violates foreign key constraint') ||
1863
+ error.message?.includes('unique constraint') ||
1864
+ error.message?.includes('23514') ||
1865
+ error.message?.includes('23505') ||
1866
+ error.message?.includes('P2002') ||
1867
+ error.message?.includes('P2003');
1868
+ if (isConstraintViolation) {
1869
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
1870
+ logger.error("Non-retryable constraint violation in updateOneLinkedProvider", {
1871
+ operation: 'updateOneLinkedProvider',
1872
+ model: 'LinkedProvider',
1873
+ error: String(error),
1874
+ recordId: props.id,
1875
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
1876
+ errorCategory: 'CONSTRAINT_VIOLATION',
1877
+ isRetryable: false,
1878
+ });
1879
+ throw error;
1880
+ }
1797
1881
  // Check if this is a database connection error that we should retry
1798
1882
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
1799
1883
  error.message?.includes('Cannot reach database server') ||
@@ -1803,12 +1887,24 @@ export const LinkedProvider = {
1803
1887
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1804
1888
  retryCount++;
1805
1889
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1806
- logger.warn("Database connection error, retrying...");
1890
+ logger.warn("Database connection error in updateOneLinkedProvider, retrying...", {
1891
+ operation: 'updateOneLinkedProvider',
1892
+ model: 'LinkedProvider',
1893
+ attempt: retryCount,
1894
+ maxRetries: MAX_RETRIES,
1895
+ recordId: props.id,
1896
+ });
1807
1897
  await new Promise(resolve => setTimeout(resolve, delay));
1808
1898
  continue;
1809
1899
  }
1810
- // Log the error and rethrow
1811
- logger.error("Database error occurred", { error: String(error) });
1900
+ // Log structured error details and rethrow
1901
+ logger.error("Database update operation failed", {
1902
+ operation: 'updateOneLinkedProvider',
1903
+ model: 'LinkedProvider',
1904
+ error: String(error),
1905
+ recordId: props.id,
1906
+ isRetryable: isConnectionError,
1907
+ });
1812
1908
  throw error;
1813
1909
  }
1814
1910
  }
@@ -3257,6 +3353,28 @@ export const LinkedProvider = {
3257
3353
  }
3258
3354
  catch (error) {
3259
3355
  lastError = error;
3356
+ // Check for constraint violations FIRST - these are NEVER retryable
3357
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
3358
+ error.message?.includes('violates unique constraint') ||
3359
+ error.message?.includes('violates foreign key constraint') ||
3360
+ error.message?.includes('unique constraint') ||
3361
+ error.message?.includes('23514') ||
3362
+ error.message?.includes('23505') ||
3363
+ error.message?.includes('P2002') ||
3364
+ error.message?.includes('P2003');
3365
+ if (isConstraintViolation) {
3366
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
3367
+ logger.error("Non-retryable constraint violation in upsertOneLinkedProvider", {
3368
+ operation: 'upsertOneLinkedProvider',
3369
+ model: 'LinkedProvider',
3370
+ error: String(error),
3371
+ recordId: props.id,
3372
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
3373
+ errorCategory: 'CONSTRAINT_VIOLATION',
3374
+ isRetryable: false,
3375
+ });
3376
+ throw error;
3377
+ }
3260
3378
  // Check if this is a database connection error that we should retry
3261
3379
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
3262
3380
  error.message?.includes('Cannot reach database server') ||
@@ -3266,12 +3384,24 @@ export const LinkedProvider = {
3266
3384
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
3267
3385
  retryCount++;
3268
3386
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
3269
- logger.warn("Database connection error, retrying...");
3387
+ logger.warn("Database connection error in upsertOneLinkedProvider, retrying...", {
3388
+ operation: 'upsertOneLinkedProvider',
3389
+ model: 'LinkedProvider',
3390
+ attempt: retryCount,
3391
+ maxRetries: MAX_RETRIES,
3392
+ recordId: props.id,
3393
+ });
3270
3394
  await new Promise(resolve => setTimeout(resolve, delay));
3271
3395
  continue;
3272
3396
  }
3273
- // Log the error and rethrow
3274
- logger.error("Database error occurred", { error: String(error) });
3397
+ // Log structured error details and rethrow
3398
+ logger.error("Database upsert operation failed", {
3399
+ operation: 'upsertOneLinkedProvider',
3400
+ model: 'LinkedProvider',
3401
+ error: String(error),
3402
+ recordId: props.id,
3403
+ isRetryable: isConnectionError,
3404
+ });
3275
3405
  throw error;
3276
3406
  }
3277
3407
  }
@@ -4409,6 +4539,27 @@ export const LinkedProvider = {
4409
4539
  }
4410
4540
  catch (error) {
4411
4541
  lastError = error;
4542
+ // Check for constraint violations FIRST - these are NEVER retryable
4543
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4544
+ error.message?.includes('violates unique constraint') ||
4545
+ error.message?.includes('violates foreign key constraint') ||
4546
+ error.message?.includes('unique constraint') ||
4547
+ error.message?.includes('23514') ||
4548
+ error.message?.includes('23505') ||
4549
+ error.message?.includes('P2002') ||
4550
+ error.message?.includes('P2003');
4551
+ if (isConstraintViolation) {
4552
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4553
+ logger.error("Non-retryable constraint violation in updateManyLinkedProvider", {
4554
+ operation: 'updateManyLinkedProvider',
4555
+ model: 'LinkedProvider',
4556
+ error: String(error),
4557
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4558
+ errorCategory: 'CONSTRAINT_VIOLATION',
4559
+ isRetryable: false,
4560
+ });
4561
+ throw error;
4562
+ }
4412
4563
  // Check if this is a database connection error that we should retry
4413
4564
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4414
4565
  error.message?.includes('Cannot reach database server') ||
@@ -4418,12 +4569,22 @@ export const LinkedProvider = {
4418
4569
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4419
4570
  retryCount++;
4420
4571
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4421
- logger.warn("Database connection error, retrying...");
4572
+ logger.warn("Database connection error in updateManyLinkedProvider, retrying...", {
4573
+ operation: 'updateManyLinkedProvider',
4574
+ model: 'LinkedProvider',
4575
+ attempt: retryCount,
4576
+ maxRetries: MAX_RETRIES,
4577
+ });
4422
4578
  await new Promise(resolve => setTimeout(resolve, delay));
4423
4579
  continue;
4424
4580
  }
4425
- // Log the error and rethrow
4426
- logger.error("Database error occurred", { error: String(error) });
4581
+ // Log structured error details and rethrow
4582
+ logger.error("Database updateMany operation failed", {
4583
+ operation: 'updateManyLinkedProvider',
4584
+ model: 'LinkedProvider',
4585
+ error: String(error),
4586
+ isRetryable: isConnectionError,
4587
+ });
4427
4588
  throw error;
4428
4589
  }
4429
4590
  }
@@ -4481,6 +4642,31 @@ export const LinkedProvider = {
4481
4642
  }
4482
4643
  catch (error) {
4483
4644
  lastError = error;
4645
+ // Check for constraint violations FIRST - these are NEVER retryable
4646
+ // (e.g., foreign key constraints preventing deletion)
4647
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4648
+ error.message?.includes('violates unique constraint') ||
4649
+ error.message?.includes('violates foreign key constraint') ||
4650
+ error.message?.includes('unique constraint') ||
4651
+ error.message?.includes('23514') ||
4652
+ error.message?.includes('23505') ||
4653
+ error.message?.includes('23503') ||
4654
+ error.message?.includes('P2002') ||
4655
+ error.message?.includes('P2003') ||
4656
+ error.message?.includes('P2014');
4657
+ if (isConstraintViolation) {
4658
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4659
+ logger.error("Non-retryable constraint violation in deleteOneLinkedProvider", {
4660
+ operation: 'deleteOneLinkedProvider',
4661
+ model: 'LinkedProvider',
4662
+ error: String(error),
4663
+ recordId: props.id,
4664
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4665
+ errorCategory: 'CONSTRAINT_VIOLATION',
4666
+ isRetryable: false,
4667
+ });
4668
+ throw error;
4669
+ }
4484
4670
  // Check if this is a database connection error that we should retry
4485
4671
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4486
4672
  error.message?.includes('Cannot reach database server') ||
@@ -4490,12 +4676,24 @@ export const LinkedProvider = {
4490
4676
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4491
4677
  retryCount++;
4492
4678
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4493
- logger.warn("Database connection error, retrying...");
4679
+ logger.warn("Database connection error in deleteOneLinkedProvider, retrying...", {
4680
+ operation: 'deleteOneLinkedProvider',
4681
+ model: 'LinkedProvider',
4682
+ attempt: retryCount,
4683
+ maxRetries: MAX_RETRIES,
4684
+ recordId: props.id,
4685
+ });
4494
4686
  await new Promise(resolve => setTimeout(resolve, delay));
4495
4687
  continue;
4496
4688
  }
4497
- // Log the error and rethrow
4498
- logger.error("Database error occurred", { error: String(error) });
4689
+ // Log structured error details and rethrow
4690
+ logger.error("Database delete operation failed", {
4691
+ operation: 'deleteOneLinkedProvider',
4692
+ model: 'LinkedProvider',
4693
+ error: String(error),
4694
+ recordId: props.id,
4695
+ isRetryable: isConnectionError,
4696
+ });
4499
4697
  throw error;
4500
4698
  }
4501
4699
  }
@@ -4570,12 +4768,22 @@ export const LinkedProvider = {
4570
4768
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4571
4769
  retryCount++;
4572
4770
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4573
- logger.warn("Database connection error, retrying...");
4771
+ logger.warn("Database connection error in getLinkedProvider, retrying...", {
4772
+ operation: 'getLinkedProvider',
4773
+ model: 'LinkedProvider',
4774
+ attempt: retryCount,
4775
+ maxRetries: MAX_RETRIES,
4776
+ });
4574
4777
  await new Promise(resolve => setTimeout(resolve, delay));
4575
4778
  continue;
4576
4779
  }
4577
- // Log the error and rethrow
4578
- logger.error("Database error occurred", { error: String(error) });
4780
+ // Log structured error details and rethrow
4781
+ logger.error("Database get operation failed", {
4782
+ operation: 'getLinkedProvider',
4783
+ model: 'LinkedProvider',
4784
+ error: String(error),
4785
+ isRetryable: isConnectionError,
4786
+ });
4579
4787
  throw error;
4580
4788
  }
4581
4789
  }
@@ -4632,12 +4840,22 @@ export const LinkedProvider = {
4632
4840
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4633
4841
  retryCount++;
4634
4842
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4635
- logger.warn("Database connection error, retrying...");
4843
+ logger.warn("Database connection error in getAllLinkedProvider, retrying...", {
4844
+ operation: 'getAllLinkedProvider',
4845
+ model: 'LinkedProvider',
4846
+ attempt: retryCount,
4847
+ maxRetries: MAX_RETRIES,
4848
+ });
4636
4849
  await new Promise(resolve => setTimeout(resolve, delay));
4637
4850
  continue;
4638
4851
  }
4639
- // Log the error and rethrow
4640
- logger.error("Database error occurred", { error: String(error) });
4852
+ // Log structured error details and rethrow
4853
+ logger.error("Database getAll operation failed", {
4854
+ operation: 'getAllLinkedProvider',
4855
+ model: 'LinkedProvider',
4856
+ error: String(error),
4857
+ isRetryable: isConnectionError,
4858
+ });
4641
4859
  throw error;
4642
4860
  }
4643
4861
  }
@@ -4719,12 +4937,22 @@ export const LinkedProvider = {
4719
4937
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4720
4938
  retryCount++;
4721
4939
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4722
- logger.warn("Database connection error, retrying...");
4940
+ logger.warn("Database connection error in findManyLinkedProvider, retrying...", {
4941
+ operation: 'findManyLinkedProvider',
4942
+ model: 'LinkedProvider',
4943
+ attempt: retryCount,
4944
+ maxRetries: MAX_RETRIES,
4945
+ });
4723
4946
  await new Promise(resolve => setTimeout(resolve, delay));
4724
4947
  continue;
4725
4948
  }
4726
- // Log the error and rethrow
4727
- logger.error("Database error occurred", { error: String(error) });
4949
+ // Log structured error details and rethrow
4950
+ logger.error("Database findMany operation failed", {
4951
+ operation: 'findManyLinkedProvider',
4952
+ model: 'LinkedProvider',
4953
+ error: String(error),
4954
+ isRetryable: isConnectionError,
4955
+ });
4728
4956
  throw error;
4729
4957
  }
4730
4958
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MLTrainingData.d.ts","sourceRoot":"","sources":["../../src/MLT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