adaptic-backend 1.0.340 → 1.0.341

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 (110) hide show
  1. package/Account.cjs +2543 -2265
  2. package/Account.d.ts +19 -2
  3. package/Action.cjs +1116 -838
  4. package/Action.d.ts +19 -2
  5. package/Alert.cjs +2626 -2348
  6. package/Alert.d.ts +19 -2
  7. package/Allocation.cjs +2578 -2300
  8. package/Allocation.d.ts +19 -2
  9. package/AlpacaAccount.cjs +2383 -2105
  10. package/AlpacaAccount.d.ts +19 -2
  11. package/Asset.cjs +1813 -1535
  12. package/Asset.d.ts +19 -2
  13. package/Authenticator.cjs +2568 -2290
  14. package/Authenticator.d.ts +19 -2
  15. package/Customer.cjs +2495 -2217
  16. package/Customer.d.ts +19 -2
  17. package/EconomicEvent.cjs +645 -367
  18. package/EconomicEvent.d.ts +19 -2
  19. package/MarketSentiment.cjs +618 -340
  20. package/MarketSentiment.d.ts +19 -2
  21. package/NewsArticle.cjs +1933 -1655
  22. package/NewsArticle.d.ts +19 -2
  23. package/NewsArticleAssetSentiment.cjs +1842 -1564
  24. package/NewsArticleAssetSentiment.d.ts +19 -2
  25. package/ScheduledOptionOrder.cjs +594 -316
  26. package/ScheduledOptionOrder.d.ts +19 -2
  27. package/Session.cjs +2570 -2292
  28. package/Session.d.ts +19 -2
  29. package/Trade.cjs +1073 -795
  30. package/Trade.d.ts +19 -2
  31. package/User.cjs +2288 -2010
  32. package/User.d.ts +19 -2
  33. package/VerificationToken.cjs +606 -328
  34. package/VerificationToken.d.ts +19 -2
  35. package/esm/Account.d.ts +19 -2
  36. package/esm/Account.d.ts.map +1 -1
  37. package/esm/Account.js.map +1 -1
  38. package/esm/Account.mjs +2534 -2263
  39. package/esm/Action.d.ts +19 -2
  40. package/esm/Action.d.ts.map +1 -1
  41. package/esm/Action.js.map +1 -1
  42. package/esm/Action.mjs +1107 -836
  43. package/esm/Alert.d.ts +19 -2
  44. package/esm/Alert.d.ts.map +1 -1
  45. package/esm/Alert.js.map +1 -1
  46. package/esm/Alert.mjs +2617 -2346
  47. package/esm/Allocation.d.ts +19 -2
  48. package/esm/Allocation.d.ts.map +1 -1
  49. package/esm/Allocation.js.map +1 -1
  50. package/esm/Allocation.mjs +2569 -2298
  51. package/esm/AlpacaAccount.d.ts +19 -2
  52. package/esm/AlpacaAccount.d.ts.map +1 -1
  53. package/esm/AlpacaAccount.js.map +1 -1
  54. package/esm/AlpacaAccount.mjs +2374 -2103
  55. package/esm/Asset.d.ts +19 -2
  56. package/esm/Asset.d.ts.map +1 -1
  57. package/esm/Asset.js.map +1 -1
  58. package/esm/Asset.mjs +1804 -1533
  59. package/esm/Authenticator.d.ts +19 -2
  60. package/esm/Authenticator.d.ts.map +1 -1
  61. package/esm/Authenticator.js.map +1 -1
  62. package/esm/Authenticator.mjs +2559 -2288
  63. package/esm/Customer.d.ts +19 -2
  64. package/esm/Customer.d.ts.map +1 -1
  65. package/esm/Customer.js.map +1 -1
  66. package/esm/Customer.mjs +2486 -2215
  67. package/esm/EconomicEvent.d.ts +19 -2
  68. package/esm/EconomicEvent.d.ts.map +1 -1
  69. package/esm/EconomicEvent.js.map +1 -1
  70. package/esm/EconomicEvent.mjs +636 -365
  71. package/esm/MarketSentiment.d.ts +19 -2
  72. package/esm/MarketSentiment.d.ts.map +1 -1
  73. package/esm/MarketSentiment.js.map +1 -1
  74. package/esm/MarketSentiment.mjs +609 -338
  75. package/esm/NewsArticle.d.ts +19 -2
  76. package/esm/NewsArticle.d.ts.map +1 -1
  77. package/esm/NewsArticle.js.map +1 -1
  78. package/esm/NewsArticle.mjs +1924 -1653
  79. package/esm/NewsArticleAssetSentiment.d.ts +19 -2
  80. package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
  81. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  82. package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
  83. package/esm/ScheduledOptionOrder.d.ts +19 -2
  84. package/esm/ScheduledOptionOrder.d.ts.map +1 -1
  85. package/esm/ScheduledOptionOrder.js.map +1 -1
  86. package/esm/ScheduledOptionOrder.mjs +585 -314
  87. package/esm/Session.d.ts +19 -2
  88. package/esm/Session.d.ts.map +1 -1
  89. package/esm/Session.js.map +1 -1
  90. package/esm/Session.mjs +2561 -2290
  91. package/esm/Trade.d.ts +19 -2
  92. package/esm/Trade.d.ts.map +1 -1
  93. package/esm/Trade.js.map +1 -1
  94. package/esm/Trade.mjs +1064 -793
  95. package/esm/User.d.ts +19 -2
  96. package/esm/User.d.ts.map +1 -1
  97. package/esm/User.js.map +1 -1
  98. package/esm/User.mjs +2279 -2008
  99. package/esm/VerificationToken.d.ts +19 -2
  100. package/esm/VerificationToken.d.ts.map +1 -1
  101. package/esm/VerificationToken.js.map +1 -1
  102. package/esm/VerificationToken.mjs +597 -326
  103. package/esm/prismaClient.d.ts +4 -5
  104. package/esm/prismaClient.d.ts.map +1 -1
  105. package/esm/prismaClient.js.map +1 -1
  106. package/esm/prismaClient.mjs +13 -11
  107. package/package.json +1 -1
  108. package/prismaClient.cjs +13 -11
  109. package/prismaClient.d.ts +4 -5
  110. package/server.cjs +37 -5
@@ -23,440 +23,718 @@ exports.MarketSentiment = {
23
23
  * @param client - Apollo Client instance.
24
24
  * @returns The created MarketSentiment or null.
25
25
  */
26
+ /**
27
+ * Create a new MarketSentiment record.
28
+ * Enhanced with connection resilience against Prisma connection errors.
29
+ * @param props - Properties for the new record.
30
+ * @param globalClient - Apollo Client instance.
31
+ * @returns The created MarketSentiment or null.
32
+ */
26
33
  async create(props, globalClient) {
27
- const [modules, client] = await Promise.all([
28
- (0, client_1.getApolloModules)(),
29
- globalClient
30
- ? Promise.resolve(globalClient)
31
- : client_1.client
32
- ]);
33
- const { gql, ApolloError } = modules;
34
- const CREATE_ONE_MARKETSENTIMENT = gql `
35
- mutation createOneMarketSentiment($data: MarketSentimentCreateInput!) {
36
- createOneMarketSentiment(data: $data) {
37
- ${selectionSet}
38
- }
39
- }
40
- `;
41
- const variables = {
42
- data: {
43
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
44
- description: props.description !== undefined ? props.description : undefined,
45
- longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
46
- },
47
- };
48
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
49
- try {
50
- const response = await client.mutate({ mutation: CREATE_ONE_MARKETSENTIMENT, variables: filteredVariables });
51
- if (response.errors && response.errors.length > 0)
52
- throw new Error(response.errors[0].message);
53
- if (response && response.data && response.data.createOneMarketSentiment) {
54
- return response.data.createOneMarketSentiment;
34
+ var _a, _b, _c, _d, _e;
35
+ // Maximum number of retries for database connection issues
36
+ const MAX_RETRIES = 3;
37
+ let retryCount = 0;
38
+ let lastError = null;
39
+ // Retry loop to handle potential database connection issues
40
+ while (retryCount < MAX_RETRIES) {
41
+ try {
42
+ const [modules, client] = await Promise.all([
43
+ (0, client_1.getApolloModules)(),
44
+ globalClient
45
+ ? Promise.resolve(globalClient)
46
+ : client_1.client
47
+ ]);
48
+ const { gql, ApolloError } = modules;
49
+ const CREATE_ONE_MARKETSENTIMENT = gql `
50
+ mutation createOneMarketSentiment($data: MarketSentimentCreateInput!) {
51
+ createOneMarketSentiment(data: $data) {
52
+ ${selectionSet}
53
+ }
54
+ }
55
+ `;
56
+ const variables = {
57
+ data: {
58
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
59
+ description: props.description !== undefined ? props.description : undefined,
60
+ longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
61
+ },
62
+ };
63
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
64
+ const response = await client.mutate({
65
+ mutation: CREATE_ONE_MARKETSENTIMENT,
66
+ variables: filteredVariables,
67
+ // Don't cache mutations, but ensure we're using the freshest context
68
+ fetchPolicy: 'no-cache'
69
+ });
70
+ if (response.errors && response.errors.length > 0)
71
+ throw new Error(response.errors[0].message);
72
+ if (response && response.data && response.data.createOneMarketSentiment) {
73
+ return response.data.createOneMarketSentiment;
74
+ }
75
+ else {
76
+ return null;
77
+ }
55
78
  }
56
- else {
57
- return null;
79
+ catch (error) {
80
+ lastError = error;
81
+ // Check if this is a database connection error that we should retry
82
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
83
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
84
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
85
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
86
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
87
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
88
+ retryCount++;
89
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
90
+ console.warn("Database connection error, retrying...");
91
+ await new Promise(resolve => setTimeout(resolve, delay));
92
+ continue;
93
+ }
94
+ // Log the error and rethrow
95
+ console.error("Database error occurred:", error);
96
+ throw error;
58
97
  }
59
98
  }
60
- catch (error) {
61
- console.error('Error in createOneMarketSentiment:', error);
62
- throw error;
63
- }
99
+ // If we exhausted retries, throw the last error
100
+ throw lastError;
64
101
  },
65
102
  /**
66
103
  * Create multiple MarketSentiment records.
104
+ * Enhanced with connection resilience against Prisma connection errors.
67
105
  * @param props - Array of MarketSentiment objects for the new records.
68
106
  * @param globalClient - Apollo Client instance.
69
107
  * @returns The count of created records or null.
70
108
  */
71
109
  async createMany(props, globalClient) {
72
- const [modules, client] = await Promise.all([
73
- (0, client_1.getApolloModules)(),
74
- globalClient
75
- ? Promise.resolve(globalClient)
76
- : client_1.client
77
- ]);
78
- const { gql, ApolloError } = modules;
79
- const CREATE_MANY_MARKETSENTIMENT = gql `
80
- mutation createManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
81
- createManyMarketSentiment(data: $data) {
82
- count
83
- }
84
- }`;
85
- const variables = {
86
- data: props.map(prop => ({
87
- sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
88
- description: prop.description !== undefined ? prop.description : undefined,
89
- longDescription: prop.longDescription !== undefined ? prop.longDescription : undefined,
90
- })),
91
- };
92
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
93
- try {
94
- const response = await client.mutate({ mutation: CREATE_MANY_MARKETSENTIMENT, variables: filteredVariables });
95
- if (response.errors && response.errors.length > 0)
96
- throw new Error(response.errors[0].message);
97
- if (response && response.data && response.data.createManyMarketSentiment) {
98
- return response.data.createManyMarketSentiment;
110
+ var _a, _b, _c, _d, _e;
111
+ // Maximum number of retries for database connection issues
112
+ const MAX_RETRIES = 3;
113
+ let retryCount = 0;
114
+ let lastError = null;
115
+ // Retry loop to handle potential database connection issues
116
+ while (retryCount < MAX_RETRIES) {
117
+ try {
118
+ const [modules, client] = await Promise.all([
119
+ (0, client_1.getApolloModules)(),
120
+ globalClient
121
+ ? Promise.resolve(globalClient)
122
+ : client_1.client
123
+ ]);
124
+ const { gql, ApolloError } = modules;
125
+ const CREATE_MANY_MARKETSENTIMENT = gql `
126
+ mutation createManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
127
+ createManyMarketSentiment(data: $data) {
128
+ count
99
129
  }
100
- else {
101
- return null;
130
+ }`;
131
+ const variables = {
132
+ data: props.map(prop => ({
133
+ sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
134
+ description: prop.description !== undefined ? prop.description : undefined,
135
+ longDescription: prop.longDescription !== undefined ? prop.longDescription : undefined,
136
+ })),
137
+ };
138
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
139
+ const response = await client.mutate({
140
+ mutation: CREATE_MANY_MARKETSENTIMENT,
141
+ variables: filteredVariables,
142
+ // Don't cache mutations, but ensure we're using the freshest context
143
+ fetchPolicy: 'no-cache'
144
+ });
145
+ if (response.errors && response.errors.length > 0)
146
+ throw new Error(response.errors[0].message);
147
+ if (response && response.data && response.data.createManyMarketSentiment) {
148
+ return response.data.createManyMarketSentiment;
149
+ }
150
+ else {
151
+ return null;
152
+ }
153
+ }
154
+ catch (error) {
155
+ lastError = error;
156
+ // Check if this is a database connection error that we should retry
157
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
158
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
159
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
160
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
161
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
162
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
163
+ retryCount++;
164
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
165
+ console.warn("Database connection error, retrying...");
166
+ await new Promise(resolve => setTimeout(resolve, delay));
167
+ continue;
168
+ }
169
+ // Log the error and rethrow
170
+ console.error("Database error occurred:", error);
171
+ throw error;
102
172
  }
103
173
  }
104
- catch (error) {
105
- console.error('Error in createManyMarketSentiment:', error);
106
- throw error;
107
- }
174
+ // If we exhausted retries, throw the last error
175
+ throw lastError;
108
176
  },
109
177
  /**
110
178
  * Update a single MarketSentiment record.
179
+ * Enhanced with connection resilience against Prisma connection errors.
111
180
  * @param props - Properties to update.
112
181
  * @param globalClient - Apollo Client instance.
113
182
  * @returns The updated MarketSentiment or null.
114
183
  */
115
184
  async update(props, globalClient) {
116
- const [modules, client] = await Promise.all([
117
- (0, client_1.getApolloModules)(),
118
- globalClient
119
- ? Promise.resolve(globalClient)
120
- : client_1.client
121
- ]);
122
- const { gql, ApolloError } = modules;
123
- const UPDATE_ONE_MARKETSENTIMENT = gql `
124
- mutation updateOneMarketSentiment($data: MarketSentimentUpdateInput!, $where: MarketSentimentWhereUniqueInput!) {
125
- updateOneMarketSentiment(data: $data, where: $where) {
126
- ${selectionSet}
127
- }
128
- }`;
129
- const variables = {
130
- where: {
131
- id: props.id !== undefined ? props.id : undefined,
132
- },
133
- data: {
134
- id: props.id !== undefined ? {
135
- set: props.id
136
- } : undefined,
137
- sentiment: props.sentiment !== undefined ? {
138
- set: props.sentiment
139
- } : undefined,
140
- description: props.description !== undefined ? {
141
- set: props.description
142
- } : undefined,
143
- longDescription: props.longDescription !== undefined ? {
144
- set: props.longDescription
145
- } : undefined,
146
- createdAt: props.createdAt !== undefined ? {
147
- set: props.createdAt
148
- } : undefined,
149
- updatedAt: props.updatedAt !== undefined ? {
150
- set: props.updatedAt
151
- } : undefined,
152
- },
153
- };
154
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
155
- try {
156
- const response = await client.mutate({ mutation: UPDATE_ONE_MARKETSENTIMENT, variables: filteredVariables });
157
- if (response.errors && response.errors.length > 0)
158
- throw new Error(response.errors[0].message);
159
- if (response && response.data && response.data.updateOneMarketSentiment) {
160
- return response.data.updateOneMarketSentiment;
185
+ var _a, _b, _c, _d, _e;
186
+ // Maximum number of retries for database connection issues
187
+ const MAX_RETRIES = 3;
188
+ let retryCount = 0;
189
+ let lastError = null;
190
+ // Retry loop to handle potential database connection issues
191
+ while (retryCount < MAX_RETRIES) {
192
+ try {
193
+ const [modules, client] = await Promise.all([
194
+ (0, client_1.getApolloModules)(),
195
+ globalClient
196
+ ? Promise.resolve(globalClient)
197
+ : client_1.client
198
+ ]);
199
+ const { gql, ApolloError } = modules;
200
+ const UPDATE_ONE_MARKETSENTIMENT = gql `
201
+ mutation updateOneMarketSentiment($data: MarketSentimentUpdateInput!, $where: MarketSentimentWhereUniqueInput!) {
202
+ updateOneMarketSentiment(data: $data, where: $where) {
203
+ ${selectionSet}
161
204
  }
162
- else {
163
- return null;
205
+ }`;
206
+ const variables = {
207
+ where: {
208
+ id: props.id !== undefined ? props.id : undefined,
209
+ },
210
+ data: {
211
+ id: props.id !== undefined ? {
212
+ set: props.id
213
+ } : undefined,
214
+ sentiment: props.sentiment !== undefined ? {
215
+ set: props.sentiment
216
+ } : undefined,
217
+ description: props.description !== undefined ? {
218
+ set: props.description
219
+ } : undefined,
220
+ longDescription: props.longDescription !== undefined ? {
221
+ set: props.longDescription
222
+ } : undefined,
223
+ createdAt: props.createdAt !== undefined ? {
224
+ set: props.createdAt
225
+ } : undefined,
226
+ updatedAt: props.updatedAt !== undefined ? {
227
+ set: props.updatedAt
228
+ } : undefined,
229
+ },
230
+ };
231
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
232
+ const response = await client.mutate({
233
+ mutation: UPDATE_ONE_MARKETSENTIMENT,
234
+ variables: filteredVariables,
235
+ // Don't cache mutations, but ensure we're using the freshest context
236
+ fetchPolicy: 'no-cache'
237
+ });
238
+ if (response.errors && response.errors.length > 0)
239
+ throw new Error(response.errors[0].message);
240
+ if (response && response.data && response.data.updateOneMarketSentiment) {
241
+ return response.data.updateOneMarketSentiment;
242
+ }
243
+ else {
244
+ return null;
245
+ }
246
+ }
247
+ catch (error) {
248
+ lastError = error;
249
+ // Check if this is a database connection error that we should retry
250
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
251
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
252
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
253
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
254
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
255
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
256
+ retryCount++;
257
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
258
+ console.warn("Database connection error, retrying...");
259
+ await new Promise(resolve => setTimeout(resolve, delay));
260
+ continue;
261
+ }
262
+ // Log the error and rethrow
263
+ console.error("Database error occurred:", error);
264
+ throw error;
164
265
  }
165
266
  }
166
- catch (error) {
167
- console.error('Error in updateOneMarketSentiment:', error);
168
- throw error;
169
- }
267
+ // If we exhausted retries, throw the last error
268
+ throw lastError;
170
269
  },
171
270
  /**
172
271
  * Upsert a single MarketSentiment record.
272
+ * Enhanced with connection resilience against Prisma connection errors.
173
273
  * @param props - Properties to update.
174
274
  * @param globalClient - Apollo Client instance.
175
275
  * @returns The updated MarketSentiment or null.
176
276
  */
177
277
  async upsert(props, globalClient) {
178
- const [modules, client] = await Promise.all([
179
- (0, client_1.getApolloModules)(),
180
- globalClient
181
- ? Promise.resolve(globalClient)
182
- : client_1.client
183
- ]);
184
- const { gql, ApolloError } = modules;
185
- const UPSERT_ONE_MARKETSENTIMENT = gql `
186
- mutation upsertOneMarketSentiment($where: MarketSentimentWhereUniqueInput!, $create: MarketSentimentCreateInput!, $update: MarketSentimentUpdateInput!) {
187
- upsertOneMarketSentiment(where: $where, create: $create, update: $update) {
188
- ${selectionSet}
189
- }
190
- }`;
191
- const variables = {
192
- where: {
193
- id: props.id !== undefined ? props.id : undefined,
194
- },
195
- create: {
196
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
197
- description: props.description !== undefined ? props.description : undefined,
198
- longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
199
- },
200
- update: {
201
- sentiment: props.sentiment !== undefined ? {
202
- set: props.sentiment
203
- } : undefined,
204
- description: props.description !== undefined ? {
205
- set: props.description
206
- } : undefined,
207
- longDescription: props.longDescription !== undefined ? {
208
- set: props.longDescription
209
- } : undefined,
210
- },
211
- };
212
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
213
- try {
214
- const response = await client.mutate({ mutation: UPSERT_ONE_MARKETSENTIMENT, variables: filteredVariables });
215
- if (response.errors && response.errors.length > 0)
216
- throw new Error(response.errors[0].message);
217
- if (response && response.data && response.data.upsertOneMarketSentiment) {
218
- return response.data.upsertOneMarketSentiment;
278
+ var _a, _b, _c, _d, _e;
279
+ // Maximum number of retries for database connection issues
280
+ const MAX_RETRIES = 3;
281
+ let retryCount = 0;
282
+ let lastError = null;
283
+ // Retry loop to handle potential database connection issues
284
+ while (retryCount < MAX_RETRIES) {
285
+ try {
286
+ const [modules, client] = await Promise.all([
287
+ (0, client_1.getApolloModules)(),
288
+ globalClient
289
+ ? Promise.resolve(globalClient)
290
+ : client_1.client
291
+ ]);
292
+ const { gql, ApolloError } = modules;
293
+ const UPSERT_ONE_MARKETSENTIMENT = gql `
294
+ mutation upsertOneMarketSentiment($where: MarketSentimentWhereUniqueInput!, $create: MarketSentimentCreateInput!, $update: MarketSentimentUpdateInput!) {
295
+ upsertOneMarketSentiment(where: $where, create: $create, update: $update) {
296
+ ${selectionSet}
219
297
  }
220
- else {
221
- return null;
298
+ }`;
299
+ const variables = {
300
+ where: {
301
+ id: props.id !== undefined ? props.id : undefined,
302
+ },
303
+ create: {
304
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
305
+ description: props.description !== undefined ? props.description : undefined,
306
+ longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
307
+ },
308
+ update: {
309
+ sentiment: props.sentiment !== undefined ? {
310
+ set: props.sentiment
311
+ } : undefined,
312
+ description: props.description !== undefined ? {
313
+ set: props.description
314
+ } : undefined,
315
+ longDescription: props.longDescription !== undefined ? {
316
+ set: props.longDescription
317
+ } : undefined,
318
+ },
319
+ };
320
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
321
+ const response = await client.mutate({
322
+ mutation: UPSERT_ONE_MARKETSENTIMENT,
323
+ variables: filteredVariables,
324
+ // Don't cache mutations, but ensure we're using the freshest context
325
+ fetchPolicy: 'no-cache'
326
+ });
327
+ if (response.errors && response.errors.length > 0)
328
+ throw new Error(response.errors[0].message);
329
+ if (response && response.data && response.data.upsertOneMarketSentiment) {
330
+ return response.data.upsertOneMarketSentiment;
331
+ }
332
+ else {
333
+ return null;
334
+ }
335
+ }
336
+ catch (error) {
337
+ lastError = error;
338
+ // Check if this is a database connection error that we should retry
339
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
340
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
341
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
342
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
343
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
344
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
345
+ retryCount++;
346
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
347
+ console.warn("Database connection error, retrying...");
348
+ await new Promise(resolve => setTimeout(resolve, delay));
349
+ continue;
350
+ }
351
+ // Log the error and rethrow
352
+ console.error("Database error occurred:", error);
353
+ throw error;
222
354
  }
223
355
  }
224
- catch (error) {
225
- console.error('Error in upsertOneMarketSentiment:', error);
226
- throw error;
227
- }
356
+ // If we exhausted retries, throw the last error
357
+ throw lastError;
228
358
  },
229
359
  /**
230
360
  * Update multiple MarketSentiment records.
361
+ * Enhanced with connection resilience against Prisma connection errors.
231
362
  * @param props - Array of MarketSentiment objects for the updated records.
232
363
  * @param globalClient - Apollo Client instance.
233
364
  * @returns The count of created records or null.
234
365
  */
235
366
  async updateMany(props, globalClient) {
236
- const [modules, client] = await Promise.all([
237
- (0, client_1.getApolloModules)(),
238
- globalClient
239
- ? Promise.resolve(globalClient)
240
- : client_1.client
241
- ]);
242
- const { gql, ApolloError } = modules;
243
- const UPDATE_MANY_MARKETSENTIMENT = gql `
244
- mutation updateManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
245
- updateManyMarketSentiment(data: $data) {
246
- count
247
- }
248
- }`;
249
- const variables = props.map(prop => ({
250
- where: {
251
- id: prop.id !== undefined ? prop.id : undefined,
252
- },
253
- data: {
254
- id: prop.id !== undefined ? {
255
- set: prop.id
256
- } : undefined,
257
- sentiment: prop.sentiment !== undefined ? {
258
- set: prop.sentiment
259
- } : undefined,
260
- description: prop.description !== undefined ? {
261
- set: prop.description
262
- } : undefined,
263
- longDescription: prop.longDescription !== undefined ? {
264
- set: prop.longDescription
265
- } : undefined,
266
- createdAt: prop.createdAt !== undefined ? {
267
- set: prop.createdAt
268
- } : undefined,
269
- updatedAt: prop.updatedAt !== undefined ? {
270
- set: prop.updatedAt
271
- } : undefined,
272
- },
273
- }));
274
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
275
- try {
276
- const response = await client.mutate({ mutation: UPDATE_MANY_MARKETSENTIMENT, variables: filteredVariables });
277
- if (response.errors && response.errors.length > 0)
278
- throw new Error(response.errors[0].message);
279
- if (response && response.data && response.data.updateManyMarketSentiment) {
280
- return response.data.updateManyMarketSentiment;
367
+ var _a, _b, _c, _d, _e;
368
+ // Maximum number of retries for database connection issues
369
+ const MAX_RETRIES = 3;
370
+ let retryCount = 0;
371
+ let lastError = null;
372
+ // Retry loop to handle potential database connection issues
373
+ while (retryCount < MAX_RETRIES) {
374
+ try {
375
+ const [modules, client] = await Promise.all([
376
+ (0, client_1.getApolloModules)(),
377
+ globalClient
378
+ ? Promise.resolve(globalClient)
379
+ : client_1.client
380
+ ]);
381
+ const { gql, ApolloError } = modules;
382
+ const UPDATE_MANY_MARKETSENTIMENT = gql `
383
+ mutation updateManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
384
+ updateManyMarketSentiment(data: $data) {
385
+ count
281
386
  }
282
- else {
283
- return null;
387
+ }`;
388
+ const variables = props.map(prop => ({
389
+ where: {
390
+ id: prop.id !== undefined ? prop.id : undefined,
391
+ },
392
+ data: {
393
+ id: prop.id !== undefined ? {
394
+ set: prop.id
395
+ } : undefined,
396
+ sentiment: prop.sentiment !== undefined ? {
397
+ set: prop.sentiment
398
+ } : undefined,
399
+ description: prop.description !== undefined ? {
400
+ set: prop.description
401
+ } : undefined,
402
+ longDescription: prop.longDescription !== undefined ? {
403
+ set: prop.longDescription
404
+ } : undefined,
405
+ createdAt: prop.createdAt !== undefined ? {
406
+ set: prop.createdAt
407
+ } : undefined,
408
+ updatedAt: prop.updatedAt !== undefined ? {
409
+ set: prop.updatedAt
410
+ } : undefined,
411
+ },
412
+ }));
413
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
414
+ const response = await client.mutate({
415
+ mutation: UPDATE_MANY_MARKETSENTIMENT,
416
+ variables: filteredVariables,
417
+ // Don't cache mutations, but ensure we're using the freshest context
418
+ fetchPolicy: 'no-cache'
419
+ });
420
+ if (response.errors && response.errors.length > 0)
421
+ throw new Error(response.errors[0].message);
422
+ if (response && response.data && response.data.updateManyMarketSentiment) {
423
+ return response.data.updateManyMarketSentiment;
424
+ }
425
+ else {
426
+ return null;
427
+ }
428
+ }
429
+ catch (error) {
430
+ lastError = error;
431
+ // Check if this is a database connection error that we should retry
432
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
433
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
434
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
435
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
436
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
437
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
438
+ retryCount++;
439
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
440
+ console.warn("Database connection error, retrying...");
441
+ await new Promise(resolve => setTimeout(resolve, delay));
442
+ continue;
443
+ }
444
+ // Log the error and rethrow
445
+ console.error("Database error occurred:", error);
446
+ throw error;
284
447
  }
285
448
  }
286
- catch (error) {
287
- console.error('Error in updateManyMarketSentiment:', error);
288
- throw error;
289
- }
449
+ // If we exhausted retries, throw the last error
450
+ throw lastError;
290
451
  },
291
452
  /**
292
453
  * Delete a single MarketSentiment record.
293
- * @param props - Properties to update.
454
+ * Enhanced with connection resilience against Prisma connection errors.
455
+ * @param props - Properties to identify the record to delete.
294
456
  * @param globalClient - Apollo Client instance.
295
457
  * @returns The deleted MarketSentiment or null.
296
458
  */
297
459
  async delete(props, globalClient) {
298
- const [modules, client] = await Promise.all([
299
- (0, client_1.getApolloModules)(),
300
- globalClient
301
- ? Promise.resolve(globalClient)
302
- : client_1.client
303
- ]);
304
- const { gql, ApolloError } = modules;
305
- const DELETE_ONE_MARKETSENTIMENT = gql `
306
- mutation deleteOneMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
307
- deleteOneMarketSentiment(where: $where) {
308
- id
309
- }
310
- }`;
311
- const variables = {
312
- where: {
313
- id: props.id ? props.id : undefined,
460
+ var _a, _b, _c, _d, _e;
461
+ // Maximum number of retries for database connection issues
462
+ const MAX_RETRIES = 3;
463
+ let retryCount = 0;
464
+ let lastError = null;
465
+ // Retry loop to handle potential database connection issues
466
+ while (retryCount < MAX_RETRIES) {
467
+ try {
468
+ const [modules, client] = await Promise.all([
469
+ (0, client_1.getApolloModules)(),
470
+ globalClient
471
+ ? Promise.resolve(globalClient)
472
+ : client_1.client
473
+ ]);
474
+ const { gql, ApolloError } = modules;
475
+ const DELETE_ONE_MARKETSENTIMENT = gql `
476
+ mutation deleteOneMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
477
+ deleteOneMarketSentiment(where: $where) {
478
+ id
314
479
  }
315
- };
316
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
317
- try {
318
- const response = await client.mutate({ mutation: DELETE_ONE_MARKETSENTIMENT, variables: filteredVariables });
319
- if (response.errors && response.errors.length > 0)
320
- throw new Error(response.errors[0].message);
321
- if (response && response.data && response.data.deleteOneMarketSentiment) {
322
- return response.data.deleteOneMarketSentiment;
480
+ }`;
481
+ const variables = {
482
+ where: {
483
+ id: props.id ? props.id : undefined,
484
+ }
485
+ };
486
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
487
+ const response = await client.mutate({
488
+ mutation: DELETE_ONE_MARKETSENTIMENT,
489
+ variables: filteredVariables,
490
+ // Don't cache mutations, but ensure we're using the freshest context
491
+ fetchPolicy: 'no-cache'
492
+ });
493
+ if (response.errors && response.errors.length > 0)
494
+ throw new Error(response.errors[0].message);
495
+ if (response && response.data && response.data.deleteOneMarketSentiment) {
496
+ return response.data.deleteOneMarketSentiment;
497
+ }
498
+ else {
499
+ return null;
500
+ }
323
501
  }
324
- else {
325
- return null;
502
+ catch (error) {
503
+ lastError = error;
504
+ // Check if this is a database connection error that we should retry
505
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
506
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
507
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
508
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
509
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
510
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
511
+ retryCount++;
512
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
513
+ console.warn("Database connection error, retrying...");
514
+ await new Promise(resolve => setTimeout(resolve, delay));
515
+ continue;
516
+ }
517
+ // Log the error and rethrow
518
+ console.error("Database error occurred:", error);
519
+ throw error;
326
520
  }
327
521
  }
328
- catch (error) {
329
- console.error('Error in deleteOneMarketSentiment:', error);
330
- throw error;
331
- }
522
+ // If we exhausted retries, throw the last error
523
+ throw lastError;
332
524
  },
333
525
  /**
334
526
  * Retrieve a single MarketSentiment record by ID.
335
- * @param props - Properties to update.
527
+ * Enhanced with connection resilience against Prisma connection errors.
528
+ * @param props - Properties to identify the record.
336
529
  * @param globalClient - Apollo Client instance.
530
+ * @param whereInput - Optional custom where input.
337
531
  * @returns The retrieved MarketSentiment or null.
338
532
  */
339
533
  async get(props, globalClient, whereInput) {
340
- var _a, _b;
341
- const [modules, client] = await Promise.all([
342
- (0, client_1.getApolloModules)(),
343
- globalClient
344
- ? Promise.resolve(globalClient)
345
- : client_1.client
346
- ]);
347
- const { gql, ApolloError } = modules;
348
- const GET_MARKETSENTIMENT = gql `
349
- query getMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
350
- getMarketSentiment(where: $where) {
351
- ${selectionSet}
352
- }
353
- }`;
354
- const variables = {
355
- where: whereInput ? whereInput : {
356
- id: props.id !== undefined ? props.id : undefined,
357
- },
358
- };
359
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
360
- try {
361
- const response = await client.query({ query: GET_MARKETSENTIMENT, variables: filteredVariables });
362
- if (response.errors && response.errors.length > 0)
363
- throw new Error(response.errors[0].message);
364
- return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getMarketSentiment) !== null && _b !== void 0 ? _b : null;
365
- }
366
- catch (error) {
367
- if (error instanceof ApolloError && error.message === 'No MarketSentiment found') {
368
- return null;
534
+ var _a, _b, _c, _d, _e, _f, _g;
535
+ // Maximum number of retries for database connection issues
536
+ const MAX_RETRIES = 3;
537
+ let retryCount = 0;
538
+ let lastError = null;
539
+ // Retry loop to handle potential database connection issues
540
+ while (retryCount < MAX_RETRIES) {
541
+ try {
542
+ const [modules, client] = await Promise.all([
543
+ (0, client_1.getApolloModules)(),
544
+ globalClient
545
+ ? Promise.resolve(globalClient)
546
+ : client_1.client
547
+ ]);
548
+ const { gql, ApolloError } = modules;
549
+ const GET_MARKETSENTIMENT = gql `
550
+ query getMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
551
+ getMarketSentiment(where: $where) {
552
+ ${selectionSet}
553
+ }
554
+ }`;
555
+ const variables = {
556
+ where: whereInput ? whereInput : {
557
+ id: props.id !== undefined ? props.id : undefined,
558
+ },
559
+ };
560
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
561
+ const response = await client.query({
562
+ query: GET_MARKETSENTIMENT,
563
+ variables: filteredVariables,
564
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
565
+ });
566
+ if (response.errors && response.errors.length > 0)
567
+ throw new Error(response.errors[0].message);
568
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getMarketSentiment) !== null && _b !== void 0 ? _b : null;
369
569
  }
370
- else {
371
- console.error('Error in getMarketSentiment:', error);
570
+ catch (error) {
571
+ lastError = error;
572
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
573
+ if (error.message === 'No MarketSentiment found') {
574
+ return null;
575
+ }
576
+ // Check if this is a database connection error that we should retry
577
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
578
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
579
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
580
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
581
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
582
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
583
+ retryCount++;
584
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
585
+ console.warn("Database connection error, retrying...");
586
+ await new Promise(resolve => setTimeout(resolve, delay));
587
+ continue;
588
+ }
589
+ // Log the error and rethrow
590
+ console.error("Database error occurred:", error);
372
591
  throw error;
373
592
  }
374
593
  }
594
+ // If we exhausted retries, throw the last error
595
+ throw lastError;
375
596
  },
376
597
  /**
377
598
  * Retrieve all MarketSentiments records.
599
+ * Enhanced with connection resilience against Prisma connection errors.
378
600
  * @param globalClient - Apollo Client instance.
379
601
  * @returns An array of MarketSentiment records or null.
380
602
  */
381
603
  async getAll(globalClient) {
382
- var _a, _b;
383
- const [modules, client] = await Promise.all([
384
- (0, client_1.getApolloModules)(),
385
- globalClient
386
- ? Promise.resolve(globalClient)
387
- : client_1.client
388
- ]);
389
- const { gql, ApolloError } = modules;
390
- const GET_ALL_MARKETSENTIMENT = gql `
391
- query getAllMarketSentiment {
392
- marketSentiments {
393
- ${selectionSet}
394
- }
395
- }`;
396
- try {
397
- const response = await client.query({ query: GET_ALL_MARKETSENTIMENT });
398
- if (response.errors && response.errors.length > 0)
399
- throw new Error(response.errors[0].message);
400
- return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.marketSentiments) !== null && _b !== void 0 ? _b : null;
401
- }
402
- catch (error) {
403
- if (error instanceof ApolloError && error.message === 'No MarketSentiment found') {
404
- return null;
604
+ var _a, _b, _c, _d, _e, _f, _g;
605
+ // Maximum number of retries for database connection issues
606
+ const MAX_RETRIES = 3;
607
+ let retryCount = 0;
608
+ let lastError = null;
609
+ // Retry loop to handle potential database connection issues
610
+ while (retryCount < MAX_RETRIES) {
611
+ try {
612
+ const [modules, client] = await Promise.all([
613
+ (0, client_1.getApolloModules)(),
614
+ globalClient
615
+ ? Promise.resolve(globalClient)
616
+ : client_1.client
617
+ ]);
618
+ const { gql, ApolloError } = modules;
619
+ const GET_ALL_MARKETSENTIMENT = gql `
620
+ query getAllMarketSentiment {
621
+ marketSentiments {
622
+ ${selectionSet}
405
623
  }
406
- else {
407
- console.error('Error in getMarketSentiment:', error);
624
+ }`;
625
+ const response = await client.query({
626
+ query: GET_ALL_MARKETSENTIMENT,
627
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
628
+ });
629
+ if (response.errors && response.errors.length > 0)
630
+ throw new Error(response.errors[0].message);
631
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.marketSentiments) !== null && _b !== void 0 ? _b : null;
632
+ }
633
+ catch (error) {
634
+ lastError = error;
635
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
636
+ if (error.message === 'No MarketSentiment found') {
637
+ return null;
638
+ }
639
+ // Check if this is a database connection error that we should retry
640
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
641
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
642
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
643
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
644
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
645
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
646
+ retryCount++;
647
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
648
+ console.warn("Database connection error, retrying...");
649
+ await new Promise(resolve => setTimeout(resolve, delay));
650
+ continue;
651
+ }
652
+ // Log the error and rethrow
653
+ console.error("Database error occurred:", error);
408
654
  throw error;
409
655
  }
410
656
  }
657
+ // If we exhausted retries, throw the last error
658
+ throw lastError;
411
659
  },
412
660
  /**
413
661
  * Find multiple MarketSentiment records based on conditions.
662
+ * Enhanced with connection resilience against Prisma connection errors.
414
663
  * @param props - Conditions to find records.
415
664
  * @param globalClient - Apollo Client instance.
665
+ * @param whereInput - Optional custom where input.
416
666
  * @returns An array of found MarketSentiment records or null.
417
667
  */
418
668
  async findMany(props, globalClient, whereInput) {
419
- const [modules, client] = await Promise.all([
420
- (0, client_1.getApolloModules)(),
421
- globalClient
422
- ? Promise.resolve(globalClient)
423
- : client_1.client
424
- ]);
425
- const { gql, ApolloError } = modules;
426
- const FIND_MANY_MARKETSENTIMENT = gql `
427
- query findManyMarketSentiment($where: MarketSentimentWhereInput!) {
428
- marketSentiments(where: $where) {
429
- ${selectionSet}
430
- }
431
- }`;
432
- const variables = {
433
- where: whereInput ? whereInput : {
434
- id: props.id !== undefined ? {
435
- equals: props.id
436
- } : undefined,
437
- },
438
- };
439
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
440
- try {
441
- const response = await client.query({ query: FIND_MANY_MARKETSENTIMENT, variables: filteredVariables });
442
- if (response.errors && response.errors.length > 0)
443
- throw new Error(response.errors[0].message);
444
- if (response && response.data && response.data.marketsentiments) {
445
- return response.data.marketSentiments;
669
+ var _a, _b, _c, _d, _e;
670
+ // Maximum number of retries for database connection issues
671
+ const MAX_RETRIES = 3;
672
+ let retryCount = 0;
673
+ let lastError = null;
674
+ // Retry loop to handle potential database connection issues
675
+ while (retryCount < MAX_RETRIES) {
676
+ try {
677
+ const [modules, client] = await Promise.all([
678
+ (0, client_1.getApolloModules)(),
679
+ globalClient
680
+ ? Promise.resolve(globalClient)
681
+ : client_1.client
682
+ ]);
683
+ const { gql, ApolloError } = modules;
684
+ const FIND_MANY_MARKETSENTIMENT = gql `
685
+ query findManyMarketSentiment($where: MarketSentimentWhereInput!) {
686
+ marketSentiments(where: $where) {
687
+ ${selectionSet}
446
688
  }
447
- else {
448
- return [];
449
- }
450
- }
451
- catch (error) {
452
- if (error instanceof ApolloError && error.message === 'No MarketSentiment found') {
453
- return null;
689
+ }`;
690
+ const variables = {
691
+ where: whereInput ? whereInput : {
692
+ id: props.id !== undefined ? {
693
+ equals: props.id
694
+ } : undefined,
695
+ },
696
+ };
697
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
698
+ const response = await client.query({
699
+ query: FIND_MANY_MARKETSENTIMENT,
700
+ variables: filteredVariables,
701
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
702
+ });
703
+ if (response.errors && response.errors.length > 0)
704
+ throw new Error(response.errors[0].message);
705
+ if (response && response.data && response.data.marketsentiments) {
706
+ return response.data.marketSentiments;
707
+ }
708
+ else {
709
+ return [];
710
+ }
454
711
  }
455
- else {
456
- console.error('Error in getMarketSentiment:', error);
712
+ catch (error) {
713
+ lastError = error;
714
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
715
+ if (error.message === 'No MarketSentiment found') {
716
+ return null;
717
+ }
718
+ // Check if this is a database connection error that we should retry
719
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
720
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
721
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
722
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
723
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
724
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
725
+ retryCount++;
726
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
727
+ console.warn("Database connection error, retrying...");
728
+ await new Promise(resolve => setTimeout(resolve, delay));
729
+ continue;
730
+ }
731
+ // Log the error and rethrow
732
+ console.error("Database error occurred:", error);
457
733
  throw error;
458
734
  }
459
735
  }
736
+ // If we exhausted retries, throw the last error
737
+ throw lastError;
460
738
  }
461
739
  };
462
740
  //# sourceMappingURL=MarketSentiment.js.map