@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
@@ -500,6 +500,27 @@ export const Allocation = {
500
500
  }
501
501
  catch (error) {
502
502
  lastError = error;
503
+ // Check for constraint violations FIRST - these are NEVER retryable
504
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
505
+ error.message?.includes('violates unique constraint') ||
506
+ error.message?.includes('violates foreign key constraint') ||
507
+ error.message?.includes('unique constraint') ||
508
+ error.message?.includes('23514') ||
509
+ error.message?.includes('23505') ||
510
+ error.message?.includes('P2002') ||
511
+ error.message?.includes('P2003');
512
+ if (isConstraintViolation) {
513
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
514
+ logger.error("Non-retryable constraint violation in createOneAllocation", {
515
+ operation: 'createOneAllocation',
516
+ model: 'Allocation',
517
+ error: String(error),
518
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
519
+ errorCategory: 'CONSTRAINT_VIOLATION',
520
+ isRetryable: false,
521
+ });
522
+ throw error;
523
+ }
503
524
  // Check if this is a database connection error that we should retry
504
525
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
505
526
  error.message?.includes('Cannot reach database server') ||
@@ -509,12 +530,22 @@ export const Allocation = {
509
530
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
510
531
  retryCount++;
511
532
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
512
- logger.warn("Database connection error, retrying...");
533
+ logger.warn("Database connection error in createOneAllocation, retrying...", {
534
+ operation: 'createOneAllocation',
535
+ model: 'Allocation',
536
+ attempt: retryCount,
537
+ maxRetries: MAX_RETRIES,
538
+ });
513
539
  await new Promise(resolve => setTimeout(resolve, delay));
514
540
  continue;
515
541
  }
516
- // Log the error and rethrow
517
- logger.error("Database error occurred", { error: String(error) });
542
+ // Log structured error details and rethrow
543
+ logger.error("Database create operation failed", {
544
+ operation: 'createOneAllocation',
545
+ model: 'Allocation',
546
+ error: String(error),
547
+ isRetryable: isConnectionError,
548
+ });
518
549
  throw error;
519
550
  }
520
551
  }
@@ -580,6 +611,27 @@ export const Allocation = {
580
611
  }
581
612
  catch (error) {
582
613
  lastError = error;
614
+ // Check for constraint violations FIRST - these are NEVER retryable
615
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
616
+ error.message?.includes('violates unique constraint') ||
617
+ error.message?.includes('violates foreign key constraint') ||
618
+ error.message?.includes('unique constraint') ||
619
+ error.message?.includes('23514') ||
620
+ error.message?.includes('23505') ||
621
+ error.message?.includes('P2002') ||
622
+ error.message?.includes('P2003');
623
+ if (isConstraintViolation) {
624
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
625
+ logger.error("Non-retryable constraint violation in createManyAllocation", {
626
+ operation: 'createManyAllocation',
627
+ model: 'Allocation',
628
+ error: String(error),
629
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
630
+ errorCategory: 'CONSTRAINT_VIOLATION',
631
+ isRetryable: false,
632
+ });
633
+ throw error;
634
+ }
583
635
  // Check if this is a database connection error that we should retry
584
636
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
585
637
  error.message?.includes('Cannot reach database server') ||
@@ -589,12 +641,22 @@ export const Allocation = {
589
641
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
590
642
  retryCount++;
591
643
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
592
- logger.warn("Database connection error, retrying...");
644
+ logger.warn("Database connection error in createManyAllocation, retrying...", {
645
+ operation: 'createManyAllocation',
646
+ model: 'Allocation',
647
+ attempt: retryCount,
648
+ maxRetries: MAX_RETRIES,
649
+ });
593
650
  await new Promise(resolve => setTimeout(resolve, delay));
594
651
  continue;
595
652
  }
596
- // Log the error and rethrow
597
- logger.error("Database error occurred", { error: String(error) });
653
+ // Log structured error details and rethrow
654
+ logger.error("Database createMany operation failed", {
655
+ operation: 'createManyAllocation',
656
+ model: 'Allocation',
657
+ error: String(error),
658
+ isRetryable: isConnectionError,
659
+ });
598
660
  throw error;
599
661
  }
600
662
  }
@@ -1774,6 +1836,28 @@ export const Allocation = {
1774
1836
  }
1775
1837
  catch (error) {
1776
1838
  lastError = error;
1839
+ // Check for constraint violations FIRST - these are NEVER retryable
1840
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
1841
+ error.message?.includes('violates unique constraint') ||
1842
+ error.message?.includes('violates foreign key constraint') ||
1843
+ error.message?.includes('unique constraint') ||
1844
+ error.message?.includes('23514') ||
1845
+ error.message?.includes('23505') ||
1846
+ error.message?.includes('P2002') ||
1847
+ error.message?.includes('P2003');
1848
+ if (isConstraintViolation) {
1849
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
1850
+ logger.error("Non-retryable constraint violation in updateOneAllocation", {
1851
+ operation: 'updateOneAllocation',
1852
+ model: 'Allocation',
1853
+ error: String(error),
1854
+ recordId: props.id,
1855
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
1856
+ errorCategory: 'CONSTRAINT_VIOLATION',
1857
+ isRetryable: false,
1858
+ });
1859
+ throw error;
1860
+ }
1777
1861
  // Check if this is a database connection error that we should retry
1778
1862
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
1779
1863
  error.message?.includes('Cannot reach database server') ||
@@ -1783,12 +1867,24 @@ export const Allocation = {
1783
1867
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1784
1868
  retryCount++;
1785
1869
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1786
- logger.warn("Database connection error, retrying...");
1870
+ logger.warn("Database connection error in updateOneAllocation, retrying...", {
1871
+ operation: 'updateOneAllocation',
1872
+ model: 'Allocation',
1873
+ attempt: retryCount,
1874
+ maxRetries: MAX_RETRIES,
1875
+ recordId: props.id,
1876
+ });
1787
1877
  await new Promise(resolve => setTimeout(resolve, delay));
1788
1878
  continue;
1789
1879
  }
1790
- // Log the error and rethrow
1791
- logger.error("Database error occurred", { error: String(error) });
1880
+ // Log structured error details and rethrow
1881
+ logger.error("Database update operation failed", {
1882
+ operation: 'updateOneAllocation',
1883
+ model: 'Allocation',
1884
+ error: String(error),
1885
+ recordId: props.id,
1886
+ isRetryable: isConnectionError,
1887
+ });
1792
1888
  throw error;
1793
1889
  }
1794
1890
  }
@@ -3252,6 +3348,28 @@ export const Allocation = {
3252
3348
  }
3253
3349
  catch (error) {
3254
3350
  lastError = error;
3351
+ // Check for constraint violations FIRST - these are NEVER retryable
3352
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
3353
+ error.message?.includes('violates unique constraint') ||
3354
+ error.message?.includes('violates foreign key constraint') ||
3355
+ error.message?.includes('unique constraint') ||
3356
+ error.message?.includes('23514') ||
3357
+ error.message?.includes('23505') ||
3358
+ error.message?.includes('P2002') ||
3359
+ error.message?.includes('P2003');
3360
+ if (isConstraintViolation) {
3361
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
3362
+ logger.error("Non-retryable constraint violation in upsertOneAllocation", {
3363
+ operation: 'upsertOneAllocation',
3364
+ model: 'Allocation',
3365
+ error: String(error),
3366
+ recordId: props.id,
3367
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
3368
+ errorCategory: 'CONSTRAINT_VIOLATION',
3369
+ isRetryable: false,
3370
+ });
3371
+ throw error;
3372
+ }
3255
3373
  // Check if this is a database connection error that we should retry
3256
3374
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
3257
3375
  error.message?.includes('Cannot reach database server') ||
@@ -3261,12 +3379,24 @@ export const Allocation = {
3261
3379
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
3262
3380
  retryCount++;
3263
3381
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
3264
- logger.warn("Database connection error, retrying...");
3382
+ logger.warn("Database connection error in upsertOneAllocation, retrying...", {
3383
+ operation: 'upsertOneAllocation',
3384
+ model: 'Allocation',
3385
+ attempt: retryCount,
3386
+ maxRetries: MAX_RETRIES,
3387
+ recordId: props.id,
3388
+ });
3265
3389
  await new Promise(resolve => setTimeout(resolve, delay));
3266
3390
  continue;
3267
3391
  }
3268
- // Log the error and rethrow
3269
- logger.error("Database error occurred", { error: String(error) });
3392
+ // Log structured error details and rethrow
3393
+ logger.error("Database upsert operation failed", {
3394
+ operation: 'upsertOneAllocation',
3395
+ model: 'Allocation',
3396
+ error: String(error),
3397
+ recordId: props.id,
3398
+ isRetryable: isConnectionError,
3399
+ });
3270
3400
  throw error;
3271
3401
  }
3272
3402
  }
@@ -4437,6 +4567,27 @@ export const Allocation = {
4437
4567
  }
4438
4568
  catch (error) {
4439
4569
  lastError = error;
4570
+ // Check for constraint violations FIRST - these are NEVER retryable
4571
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4572
+ error.message?.includes('violates unique constraint') ||
4573
+ error.message?.includes('violates foreign key constraint') ||
4574
+ error.message?.includes('unique constraint') ||
4575
+ error.message?.includes('23514') ||
4576
+ error.message?.includes('23505') ||
4577
+ error.message?.includes('P2002') ||
4578
+ error.message?.includes('P2003');
4579
+ if (isConstraintViolation) {
4580
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4581
+ logger.error("Non-retryable constraint violation in updateManyAllocation", {
4582
+ operation: 'updateManyAllocation',
4583
+ model: 'Allocation',
4584
+ error: String(error),
4585
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4586
+ errorCategory: 'CONSTRAINT_VIOLATION',
4587
+ isRetryable: false,
4588
+ });
4589
+ throw error;
4590
+ }
4440
4591
  // Check if this is a database connection error that we should retry
4441
4592
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4442
4593
  error.message?.includes('Cannot reach database server') ||
@@ -4446,12 +4597,22 @@ export const Allocation = {
4446
4597
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4447
4598
  retryCount++;
4448
4599
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4449
- logger.warn("Database connection error, retrying...");
4600
+ logger.warn("Database connection error in updateManyAllocation, retrying...", {
4601
+ operation: 'updateManyAllocation',
4602
+ model: 'Allocation',
4603
+ attempt: retryCount,
4604
+ maxRetries: MAX_RETRIES,
4605
+ });
4450
4606
  await new Promise(resolve => setTimeout(resolve, delay));
4451
4607
  continue;
4452
4608
  }
4453
- // Log the error and rethrow
4454
- logger.error("Database error occurred", { error: String(error) });
4609
+ // Log structured error details and rethrow
4610
+ logger.error("Database updateMany operation failed", {
4611
+ operation: 'updateManyAllocation',
4612
+ model: 'Allocation',
4613
+ error: String(error),
4614
+ isRetryable: isConnectionError,
4615
+ });
4455
4616
  throw error;
4456
4617
  }
4457
4618
  }
@@ -4509,6 +4670,31 @@ export const Allocation = {
4509
4670
  }
4510
4671
  catch (error) {
4511
4672
  lastError = error;
4673
+ // Check for constraint violations FIRST - these are NEVER retryable
4674
+ // (e.g., foreign key constraints preventing deletion)
4675
+ const isConstraintViolation = error.message?.includes('violates check constraint') ||
4676
+ error.message?.includes('violates unique constraint') ||
4677
+ error.message?.includes('violates foreign key constraint') ||
4678
+ error.message?.includes('unique constraint') ||
4679
+ error.message?.includes('23514') ||
4680
+ error.message?.includes('23505') ||
4681
+ error.message?.includes('23503') ||
4682
+ error.message?.includes('P2002') ||
4683
+ error.message?.includes('P2003') ||
4684
+ error.message?.includes('P2014');
4685
+ if (isConstraintViolation) {
4686
+ const constraintMatch = error.message?.match(/constraint\s+"([^"]+)"/);
4687
+ logger.error("Non-retryable constraint violation in deleteOneAllocation", {
4688
+ operation: 'deleteOneAllocation',
4689
+ model: 'Allocation',
4690
+ error: String(error),
4691
+ recordId: props.id,
4692
+ constraintName: constraintMatch ? constraintMatch[1] : undefined,
4693
+ errorCategory: 'CONSTRAINT_VIOLATION',
4694
+ isRetryable: false,
4695
+ });
4696
+ throw error;
4697
+ }
4512
4698
  // Check if this is a database connection error that we should retry
4513
4699
  const isConnectionError = error.message?.includes('Server has closed the connection') ||
4514
4700
  error.message?.includes('Cannot reach database server') ||
@@ -4518,12 +4704,24 @@ export const Allocation = {
4518
4704
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4519
4705
  retryCount++;
4520
4706
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4521
- logger.warn("Database connection error, retrying...");
4707
+ logger.warn("Database connection error in deleteOneAllocation, retrying...", {
4708
+ operation: 'deleteOneAllocation',
4709
+ model: 'Allocation',
4710
+ attempt: retryCount,
4711
+ maxRetries: MAX_RETRIES,
4712
+ recordId: props.id,
4713
+ });
4522
4714
  await new Promise(resolve => setTimeout(resolve, delay));
4523
4715
  continue;
4524
4716
  }
4525
- // Log the error and rethrow
4526
- logger.error("Database error occurred", { error: String(error) });
4717
+ // Log structured error details and rethrow
4718
+ logger.error("Database delete operation failed", {
4719
+ operation: 'deleteOneAllocation',
4720
+ model: 'Allocation',
4721
+ error: String(error),
4722
+ recordId: props.id,
4723
+ isRetryable: isConnectionError,
4724
+ });
4527
4725
  throw error;
4528
4726
  }
4529
4727
  }
@@ -4590,12 +4788,22 @@ export const Allocation = {
4590
4788
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4591
4789
  retryCount++;
4592
4790
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4593
- logger.warn("Database connection error, retrying...");
4791
+ logger.warn("Database connection error in getAllocation, retrying...", {
4792
+ operation: 'getAllocation',
4793
+ model: 'Allocation',
4794
+ attempt: retryCount,
4795
+ maxRetries: MAX_RETRIES,
4796
+ });
4594
4797
  await new Promise(resolve => setTimeout(resolve, delay));
4595
4798
  continue;
4596
4799
  }
4597
- // Log the error and rethrow
4598
- logger.error("Database error occurred", { error: String(error) });
4800
+ // Log structured error details and rethrow
4801
+ logger.error("Database get operation failed", {
4802
+ operation: 'getAllocation',
4803
+ model: 'Allocation',
4804
+ error: String(error),
4805
+ isRetryable: isConnectionError,
4806
+ });
4599
4807
  throw error;
4600
4808
  }
4601
4809
  }
@@ -4652,12 +4860,22 @@ export const Allocation = {
4652
4860
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4653
4861
  retryCount++;
4654
4862
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4655
- logger.warn("Database connection error, retrying...");
4863
+ logger.warn("Database connection error in getAllAllocation, retrying...", {
4864
+ operation: 'getAllAllocation',
4865
+ model: 'Allocation',
4866
+ attempt: retryCount,
4867
+ maxRetries: MAX_RETRIES,
4868
+ });
4656
4869
  await new Promise(resolve => setTimeout(resolve, delay));
4657
4870
  continue;
4658
4871
  }
4659
- // Log the error and rethrow
4660
- logger.error("Database error occurred", { error: String(error) });
4872
+ // Log structured error details and rethrow
4873
+ logger.error("Database getAll operation failed", {
4874
+ operation: 'getAllAllocation',
4875
+ model: 'Allocation',
4876
+ error: String(error),
4877
+ isRetryable: isConnectionError,
4878
+ });
4661
4879
  throw error;
4662
4880
  }
4663
4881
  }
@@ -4733,12 +4951,22 @@ export const Allocation = {
4733
4951
  if (isConnectionError && retryCount < MAX_RETRIES - 1) {
4734
4952
  retryCount++;
4735
4953
  const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
4736
- logger.warn("Database connection error, retrying...");
4954
+ logger.warn("Database connection error in findManyAllocation, retrying...", {
4955
+ operation: 'findManyAllocation',
4956
+ model: 'Allocation',
4957
+ attempt: retryCount,
4958
+ maxRetries: MAX_RETRIES,
4959
+ });
4737
4960
  await new Promise(resolve => setTimeout(resolve, delay));
4738
4961
  continue;
4739
4962
  }
4740
- // Log the error and rethrow
4741
- logger.error("Database error occurred", { error: String(error) });
4963
+ // Log structured error details and rethrow
4964
+ logger.error("Database findMany operation failed", {
4965
+ operation: 'findManyAllocation',
4966
+ model: 'Allocation',
4967
+ error: String(error),
4968
+ isRetryable: isConnectionError,
4969
+ });
4742
4970
  throw error;
4743
4971
  }
4744
4972
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AlpacaAccount.d.ts","sourceRoot":"","sources":["../../src/AlpacaAccount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,qDAAqD,CAAC;AACzG,OAAO,EAA4B,gBAAgB,EAAE,qBAAqB,EAAoB,MAAM,UAAU,CAAC;AAsJ7G,eAAO,MAAM,aAAa;IAExB;;;;;OAKG;IAEH;;;;;;OAMG;kBACiB,iBAAiB,iBAAiB,gBAAgB,CAAC,qBAAqB,CAAC,GAAG,O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