adaptic-backend 1.0.340 → 1.0.342

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 (122) hide show
  1. package/Account.cjs +2670 -2264
  2. package/Account.d.ts +19 -2
  3. package/Action.cjs +1195 -839
  4. package/Action.d.ts +19 -2
  5. package/Alert.cjs +2651 -2347
  6. package/Alert.d.ts +19 -2
  7. package/Allocation.cjs +2631 -2304
  8. package/Allocation.d.ts +19 -2
  9. package/AlpacaAccount.cjs +2654 -2104
  10. package/AlpacaAccount.d.ts +19 -2
  11. package/Asset.cjs +2611 -1544
  12. package/Asset.d.ts +19 -2
  13. package/Authenticator.cjs +2603 -2290
  14. package/Authenticator.d.ts +19 -2
  15. package/Customer.cjs +2506 -2220
  16. package/Customer.d.ts +19 -2
  17. package/EconomicEvent.cjs +708 -367
  18. package/EconomicEvent.d.ts +19 -2
  19. package/MarketSentiment.cjs +691 -340
  20. package/MarketSentiment.d.ts +19 -2
  21. package/NewsArticle.cjs +2114 -1655
  22. package/NewsArticle.d.ts +19 -2
  23. package/NewsArticleAssetSentiment.cjs +1873 -1564
  24. package/NewsArticleAssetSentiment.d.ts +19 -2
  25. package/ScheduledOptionOrder.cjs +607 -316
  26. package/ScheduledOptionOrder.d.ts +19 -2
  27. package/Session.cjs +2592 -2294
  28. package/Session.d.ts +19 -2
  29. package/Trade.cjs +1261 -795
  30. package/Trade.d.ts +19 -2
  31. package/User.cjs +2432 -2013
  32. package/User.d.ts +19 -2
  33. package/VerificationToken.cjs +637 -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 +2661 -2262
  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 +1186 -837
  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 +2642 -2345
  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 +2622 -2302
  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 +2645 -2102
  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 +2602 -1542
  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 +2594 -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 +2497 -2218
  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 +699 -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 +682 -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 +2105 -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 +1864 -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 +598 -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 +2583 -2292
  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 +1252 -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 +2423 -2011
  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 +628 -326
  103. package/esm/generated/typegraphql-prisma/enhance.js.map +1 -1
  104. package/esm/generated/typegraphql-prisma/enhance.mjs +1 -1
  105. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
  106. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
  107. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
  108. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.mjs +7 -7
  109. package/esm/prismaClient.d.ts +4 -5
  110. package/esm/prismaClient.d.ts.map +1 -1
  111. package/esm/prismaClient.js.map +1 -1
  112. package/esm/prismaClient.mjs +13 -11
  113. package/generated/typegraphql-prisma/enhance.cjs +1 -1
  114. package/generated/typegraphql-prisma/enhance.js.map +1 -1
  115. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.cjs +6 -6
  116. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
  117. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
  118. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
  119. package/package.json +1 -1
  120. package/prismaClient.cjs +13 -11
  121. package/prismaClient.d.ts +4 -5
  122. package/server.cjs +37 -5
@@ -23,440 +23,791 @@ 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
+ sentiment: props.sentiment !== undefined ? {
210
+ equals: props.sentiment
211
+ } : undefined,
212
+ description: props.description !== undefined ? {
213
+ equals: props.description
214
+ } : undefined,
215
+ longDescription: props.longDescription !== undefined ? {
216
+ equals: props.longDescription
217
+ } : undefined,
218
+ createdAt: props.createdAt !== undefined ? {
219
+ equals: props.createdAt
220
+ } : undefined,
221
+ updatedAt: props.updatedAt !== undefined ? {
222
+ equals: props.updatedAt
223
+ } : undefined,
224
+ },
225
+ data: {
226
+ id: props.id !== undefined ? {
227
+ set: props.id
228
+ } : undefined,
229
+ sentiment: props.sentiment !== undefined ? {
230
+ set: props.sentiment
231
+ } : undefined,
232
+ description: props.description !== undefined ? {
233
+ set: props.description
234
+ } : undefined,
235
+ longDescription: props.longDescription !== undefined ? {
236
+ set: props.longDescription
237
+ } : undefined,
238
+ createdAt: props.createdAt !== undefined ? {
239
+ set: props.createdAt
240
+ } : undefined,
241
+ updatedAt: props.updatedAt !== undefined ? {
242
+ set: props.updatedAt
243
+ } : undefined,
244
+ },
245
+ };
246
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
247
+ const response = await client.mutate({
248
+ mutation: UPDATE_ONE_MARKETSENTIMENT,
249
+ variables: filteredVariables,
250
+ // Don't cache mutations, but ensure we're using the freshest context
251
+ fetchPolicy: 'no-cache'
252
+ });
253
+ if (response.errors && response.errors.length > 0)
254
+ throw new Error(response.errors[0].message);
255
+ if (response && response.data && response.data.updateOneMarketSentiment) {
256
+ return response.data.updateOneMarketSentiment;
257
+ }
258
+ else {
259
+ return null;
260
+ }
261
+ }
262
+ catch (error) {
263
+ lastError = error;
264
+ // Check if this is a database connection error that we should retry
265
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
266
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
267
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
268
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
269
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
270
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
271
+ retryCount++;
272
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
273
+ console.warn("Database connection error, retrying...");
274
+ await new Promise(resolve => setTimeout(resolve, delay));
275
+ continue;
276
+ }
277
+ // Log the error and rethrow
278
+ console.error("Database error occurred:", error);
279
+ throw error;
164
280
  }
165
281
  }
166
- catch (error) {
167
- console.error('Error in updateOneMarketSentiment:', error);
168
- throw error;
169
- }
282
+ // If we exhausted retries, throw the last error
283
+ throw lastError;
170
284
  },
171
285
  /**
172
286
  * Upsert a single MarketSentiment record.
287
+ * Enhanced with connection resilience against Prisma connection errors.
173
288
  * @param props - Properties to update.
174
289
  * @param globalClient - Apollo Client instance.
175
290
  * @returns The updated MarketSentiment or null.
176
291
  */
177
292
  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;
293
+ var _a, _b, _c, _d, _e;
294
+ // Maximum number of retries for database connection issues
295
+ const MAX_RETRIES = 3;
296
+ let retryCount = 0;
297
+ let lastError = null;
298
+ // Retry loop to handle potential database connection issues
299
+ while (retryCount < MAX_RETRIES) {
300
+ try {
301
+ const [modules, client] = await Promise.all([
302
+ (0, client_1.getApolloModules)(),
303
+ globalClient
304
+ ? Promise.resolve(globalClient)
305
+ : client_1.client
306
+ ]);
307
+ const { gql, ApolloError } = modules;
308
+ const UPSERT_ONE_MARKETSENTIMENT = gql `
309
+ mutation upsertOneMarketSentiment($where: MarketSentimentWhereUniqueInput!, $create: MarketSentimentCreateInput!, $update: MarketSentimentUpdateInput!) {
310
+ upsertOneMarketSentiment(where: $where, create: $create, update: $update) {
311
+ ${selectionSet}
219
312
  }
220
- else {
221
- return null;
313
+ }`;
314
+ const variables = {
315
+ where: {
316
+ id: props.id !== undefined ? props.id : undefined,
317
+ sentiment: props.sentiment !== undefined ? {
318
+ equals: props.sentiment
319
+ } : undefined,
320
+ description: props.description !== undefined ? {
321
+ equals: props.description
322
+ } : undefined,
323
+ longDescription: props.longDescription !== undefined ? {
324
+ equals: props.longDescription
325
+ } : undefined,
326
+ createdAt: props.createdAt !== undefined ? {
327
+ equals: props.createdAt
328
+ } : undefined,
329
+ updatedAt: props.updatedAt !== undefined ? {
330
+ equals: props.updatedAt
331
+ } : undefined,
332
+ },
333
+ create: {
334
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
335
+ description: props.description !== undefined ? props.description : undefined,
336
+ longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
337
+ },
338
+ update: {
339
+ sentiment: props.sentiment !== undefined ? {
340
+ set: props.sentiment
341
+ } : undefined,
342
+ description: props.description !== undefined ? {
343
+ set: props.description
344
+ } : undefined,
345
+ longDescription: props.longDescription !== undefined ? {
346
+ set: props.longDescription
347
+ } : undefined,
348
+ },
349
+ };
350
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
351
+ const response = await client.mutate({
352
+ mutation: UPSERT_ONE_MARKETSENTIMENT,
353
+ variables: filteredVariables,
354
+ // Don't cache mutations, but ensure we're using the freshest context
355
+ fetchPolicy: 'no-cache'
356
+ });
357
+ if (response.errors && response.errors.length > 0)
358
+ throw new Error(response.errors[0].message);
359
+ if (response && response.data && response.data.upsertOneMarketSentiment) {
360
+ return response.data.upsertOneMarketSentiment;
361
+ }
362
+ else {
363
+ return null;
364
+ }
365
+ }
366
+ catch (error) {
367
+ lastError = error;
368
+ // Check if this is a database connection error that we should retry
369
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
370
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
371
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
372
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
373
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
374
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
375
+ retryCount++;
376
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
377
+ console.warn("Database connection error, retrying...");
378
+ await new Promise(resolve => setTimeout(resolve, delay));
379
+ continue;
380
+ }
381
+ // Log the error and rethrow
382
+ console.error("Database error occurred:", error);
383
+ throw error;
222
384
  }
223
385
  }
224
- catch (error) {
225
- console.error('Error in upsertOneMarketSentiment:', error);
226
- throw error;
227
- }
386
+ // If we exhausted retries, throw the last error
387
+ throw lastError;
228
388
  },
229
389
  /**
230
390
  * Update multiple MarketSentiment records.
391
+ * Enhanced with connection resilience against Prisma connection errors.
231
392
  * @param props - Array of MarketSentiment objects for the updated records.
232
393
  * @param globalClient - Apollo Client instance.
233
394
  * @returns The count of created records or null.
234
395
  */
235
396
  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;
397
+ var _a, _b, _c, _d, _e;
398
+ // Maximum number of retries for database connection issues
399
+ const MAX_RETRIES = 3;
400
+ let retryCount = 0;
401
+ let lastError = null;
402
+ // Retry loop to handle potential database connection issues
403
+ while (retryCount < MAX_RETRIES) {
404
+ try {
405
+ const [modules, client] = await Promise.all([
406
+ (0, client_1.getApolloModules)(),
407
+ globalClient
408
+ ? Promise.resolve(globalClient)
409
+ : client_1.client
410
+ ]);
411
+ const { gql, ApolloError } = modules;
412
+ const UPDATE_MANY_MARKETSENTIMENT = gql `
413
+ mutation updateManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
414
+ updateManyMarketSentiment(data: $data) {
415
+ count
281
416
  }
282
- else {
283
- return null;
417
+ }`;
418
+ const variables = props.map(prop => ({
419
+ where: {
420
+ id: prop.id !== undefined ? prop.id : undefined,
421
+ sentiment: prop.sentiment !== undefined ? {
422
+ equals: prop.sentiment
423
+ } : undefined,
424
+ description: prop.description !== undefined ? {
425
+ equals: prop.description
426
+ } : undefined,
427
+ longDescription: prop.longDescription !== undefined ? {
428
+ equals: prop.longDescription
429
+ } : undefined,
430
+ createdAt: prop.createdAt !== undefined ? {
431
+ equals: prop.createdAt
432
+ } : undefined,
433
+ updatedAt: prop.updatedAt !== undefined ? {
434
+ equals: prop.updatedAt
435
+ } : undefined,
436
+ },
437
+ data: {
438
+ id: prop.id !== undefined ? {
439
+ set: prop.id
440
+ } : undefined,
441
+ sentiment: prop.sentiment !== undefined ? {
442
+ set: prop.sentiment
443
+ } : undefined,
444
+ description: prop.description !== undefined ? {
445
+ set: prop.description
446
+ } : undefined,
447
+ longDescription: prop.longDescription !== undefined ? {
448
+ set: prop.longDescription
449
+ } : undefined,
450
+ createdAt: prop.createdAt !== undefined ? {
451
+ set: prop.createdAt
452
+ } : undefined,
453
+ updatedAt: prop.updatedAt !== undefined ? {
454
+ set: prop.updatedAt
455
+ } : undefined,
456
+ },
457
+ }));
458
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
459
+ const response = await client.mutate({
460
+ mutation: UPDATE_MANY_MARKETSENTIMENT,
461
+ variables: filteredVariables,
462
+ // Don't cache mutations, but ensure we're using the freshest context
463
+ fetchPolicy: 'no-cache'
464
+ });
465
+ if (response.errors && response.errors.length > 0)
466
+ throw new Error(response.errors[0].message);
467
+ if (response && response.data && response.data.updateManyMarketSentiment) {
468
+ return response.data.updateManyMarketSentiment;
469
+ }
470
+ else {
471
+ return null;
472
+ }
473
+ }
474
+ catch (error) {
475
+ lastError = error;
476
+ // Check if this is a database connection error that we should retry
477
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
478
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
479
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
480
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
481
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
482
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
483
+ retryCount++;
484
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
485
+ console.warn("Database connection error, retrying...");
486
+ await new Promise(resolve => setTimeout(resolve, delay));
487
+ continue;
488
+ }
489
+ // Log the error and rethrow
490
+ console.error("Database error occurred:", error);
491
+ throw error;
284
492
  }
285
493
  }
286
- catch (error) {
287
- console.error('Error in updateManyMarketSentiment:', error);
288
- throw error;
289
- }
494
+ // If we exhausted retries, throw the last error
495
+ throw lastError;
290
496
  },
291
497
  /**
292
498
  * Delete a single MarketSentiment record.
293
- * @param props - Properties to update.
499
+ * Enhanced with connection resilience against Prisma connection errors.
500
+ * @param props - Properties to identify the record to delete.
294
501
  * @param globalClient - Apollo Client instance.
295
502
  * @returns The deleted MarketSentiment or null.
296
503
  */
297
504
  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,
505
+ var _a, _b, _c, _d, _e;
506
+ // Maximum number of retries for database connection issues
507
+ const MAX_RETRIES = 3;
508
+ let retryCount = 0;
509
+ let lastError = null;
510
+ // Retry loop to handle potential database connection issues
511
+ while (retryCount < MAX_RETRIES) {
512
+ try {
513
+ const [modules, client] = await Promise.all([
514
+ (0, client_1.getApolloModules)(),
515
+ globalClient
516
+ ? Promise.resolve(globalClient)
517
+ : client_1.client
518
+ ]);
519
+ const { gql, ApolloError } = modules;
520
+ const DELETE_ONE_MARKETSENTIMENT = gql `
521
+ mutation deleteOneMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
522
+ deleteOneMarketSentiment(where: $where) {
523
+ id
314
524
  }
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;
525
+ }`;
526
+ const variables = {
527
+ where: {
528
+ id: props.id ? props.id : undefined,
529
+ }
530
+ };
531
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
532
+ const response = await client.mutate({
533
+ mutation: DELETE_ONE_MARKETSENTIMENT,
534
+ variables: filteredVariables,
535
+ // Don't cache mutations, but ensure we're using the freshest context
536
+ fetchPolicy: 'no-cache'
537
+ });
538
+ if (response.errors && response.errors.length > 0)
539
+ throw new Error(response.errors[0].message);
540
+ if (response && response.data && response.data.deleteOneMarketSentiment) {
541
+ return response.data.deleteOneMarketSentiment;
542
+ }
543
+ else {
544
+ return null;
545
+ }
323
546
  }
324
- else {
325
- return null;
547
+ catch (error) {
548
+ lastError = error;
549
+ // Check if this is a database connection error that we should retry
550
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
551
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
552
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
553
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
554
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
555
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
556
+ retryCount++;
557
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
558
+ console.warn("Database connection error, retrying...");
559
+ await new Promise(resolve => setTimeout(resolve, delay));
560
+ continue;
561
+ }
562
+ // Log the error and rethrow
563
+ console.error("Database error occurred:", error);
564
+ throw error;
326
565
  }
327
566
  }
328
- catch (error) {
329
- console.error('Error in deleteOneMarketSentiment:', error);
330
- throw error;
331
- }
567
+ // If we exhausted retries, throw the last error
568
+ throw lastError;
332
569
  },
333
570
  /**
334
571
  * Retrieve a single MarketSentiment record by ID.
335
- * @param props - Properties to update.
572
+ * Enhanced with connection resilience against Prisma connection errors.
573
+ * @param props - Properties to identify the record.
336
574
  * @param globalClient - Apollo Client instance.
575
+ * @param whereInput - Optional custom where input.
337
576
  * @returns The retrieved MarketSentiment or null.
338
577
  */
339
578
  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;
579
+ var _a, _b, _c, _d, _e, _f, _g;
580
+ // Maximum number of retries for database connection issues
581
+ const MAX_RETRIES = 3;
582
+ let retryCount = 0;
583
+ let lastError = null;
584
+ // Retry loop to handle potential database connection issues
585
+ while (retryCount < MAX_RETRIES) {
586
+ try {
587
+ const [modules, client] = await Promise.all([
588
+ (0, client_1.getApolloModules)(),
589
+ globalClient
590
+ ? Promise.resolve(globalClient)
591
+ : client_1.client
592
+ ]);
593
+ const { gql, ApolloError } = modules;
594
+ const GET_MARKETSENTIMENT = gql `
595
+ query getMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
596
+ getMarketSentiment(where: $where) {
597
+ ${selectionSet}
598
+ }
599
+ }`;
600
+ const variables = {
601
+ where: whereInput ? whereInput : {
602
+ id: props.id !== undefined ? props.id : undefined,
603
+ sentiment: props.sentiment !== undefined ? {
604
+ equals: props.sentiment
605
+ } : undefined,
606
+ description: props.description !== undefined ? {
607
+ equals: props.description
608
+ } : undefined,
609
+ longDescription: props.longDescription !== undefined ? {
610
+ equals: props.longDescription
611
+ } : undefined,
612
+ createdAt: props.createdAt !== undefined ? {
613
+ equals: props.createdAt
614
+ } : undefined,
615
+ updatedAt: props.updatedAt !== undefined ? {
616
+ equals: props.updatedAt
617
+ } : undefined,
618
+ },
619
+ };
620
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
621
+ const response = await client.query({
622
+ query: GET_MARKETSENTIMENT,
623
+ variables: filteredVariables,
624
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
625
+ });
626
+ if (response.errors && response.errors.length > 0)
627
+ throw new Error(response.errors[0].message);
628
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getMarketSentiment) !== null && _b !== void 0 ? _b : null;
369
629
  }
370
- else {
371
- console.error('Error in getMarketSentiment:', error);
630
+ catch (error) {
631
+ lastError = error;
632
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
633
+ if (error.message === 'No MarketSentiment found') {
634
+ return null;
635
+ }
636
+ // Check if this is a database connection error that we should retry
637
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
638
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
639
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
640
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
641
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
642
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
643
+ retryCount++;
644
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
645
+ console.warn("Database connection error, retrying...");
646
+ await new Promise(resolve => setTimeout(resolve, delay));
647
+ continue;
648
+ }
649
+ // Log the error and rethrow
650
+ console.error("Database error occurred:", error);
372
651
  throw error;
373
652
  }
374
653
  }
654
+ // If we exhausted retries, throw the last error
655
+ throw lastError;
375
656
  },
376
657
  /**
377
658
  * Retrieve all MarketSentiments records.
659
+ * Enhanced with connection resilience against Prisma connection errors.
378
660
  * @param globalClient - Apollo Client instance.
379
661
  * @returns An array of MarketSentiment records or null.
380
662
  */
381
663
  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;
664
+ var _a, _b, _c, _d, _e, _f, _g;
665
+ // Maximum number of retries for database connection issues
666
+ const MAX_RETRIES = 3;
667
+ let retryCount = 0;
668
+ let lastError = null;
669
+ // Retry loop to handle potential database connection issues
670
+ while (retryCount < MAX_RETRIES) {
671
+ try {
672
+ const [modules, client] = await Promise.all([
673
+ (0, client_1.getApolloModules)(),
674
+ globalClient
675
+ ? Promise.resolve(globalClient)
676
+ : client_1.client
677
+ ]);
678
+ const { gql, ApolloError } = modules;
679
+ const GET_ALL_MARKETSENTIMENT = gql `
680
+ query getAllMarketSentiment {
681
+ marketSentiments {
682
+ ${selectionSet}
405
683
  }
406
- else {
407
- console.error('Error in getMarketSentiment:', error);
684
+ }`;
685
+ const response = await client.query({
686
+ query: GET_ALL_MARKETSENTIMENT,
687
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
688
+ });
689
+ if (response.errors && response.errors.length > 0)
690
+ throw new Error(response.errors[0].message);
691
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.marketSentiments) !== null && _b !== void 0 ? _b : null;
692
+ }
693
+ catch (error) {
694
+ lastError = error;
695
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
696
+ if (error.message === 'No MarketSentiment found') {
697
+ return null;
698
+ }
699
+ // Check if this is a database connection error that we should retry
700
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
701
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
702
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
703
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
704
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
705
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
706
+ retryCount++;
707
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
708
+ console.warn("Database connection error, retrying...");
709
+ await new Promise(resolve => setTimeout(resolve, delay));
710
+ continue;
711
+ }
712
+ // Log the error and rethrow
713
+ console.error("Database error occurred:", error);
408
714
  throw error;
409
715
  }
410
716
  }
717
+ // If we exhausted retries, throw the last error
718
+ throw lastError;
411
719
  },
412
720
  /**
413
721
  * Find multiple MarketSentiment records based on conditions.
722
+ * Enhanced with connection resilience against Prisma connection errors.
414
723
  * @param props - Conditions to find records.
415
724
  * @param globalClient - Apollo Client instance.
725
+ * @param whereInput - Optional custom where input.
416
726
  * @returns An array of found MarketSentiment records or null.
417
727
  */
418
728
  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;
729
+ var _a, _b, _c, _d, _e;
730
+ // Maximum number of retries for database connection issues
731
+ const MAX_RETRIES = 3;
732
+ let retryCount = 0;
733
+ let lastError = null;
734
+ // Retry loop to handle potential database connection issues
735
+ while (retryCount < MAX_RETRIES) {
736
+ try {
737
+ const [modules, client] = await Promise.all([
738
+ (0, client_1.getApolloModules)(),
739
+ globalClient
740
+ ? Promise.resolve(globalClient)
741
+ : client_1.client
742
+ ]);
743
+ const { gql, ApolloError } = modules;
744
+ const FIND_MANY_MARKETSENTIMENT = gql `
745
+ query findManyMarketSentiment($where: MarketSentimentWhereInput!) {
746
+ marketSentiments(where: $where) {
747
+ ${selectionSet}
446
748
  }
447
- else {
448
- return [];
449
- }
450
- }
451
- catch (error) {
452
- if (error instanceof ApolloError && error.message === 'No MarketSentiment found') {
453
- return null;
749
+ }`;
750
+ const variables = {
751
+ where: whereInput ? whereInput : {
752
+ id: props.id !== undefined ? props.id : undefined,
753
+ sentiment: props.sentiment !== undefined ? {
754
+ equals: props.sentiment
755
+ } : undefined,
756
+ description: props.description !== undefined ? {
757
+ equals: props.description
758
+ } : undefined,
759
+ longDescription: props.longDescription !== undefined ? {
760
+ equals: props.longDescription
761
+ } : undefined,
762
+ createdAt: props.createdAt !== undefined ? {
763
+ equals: props.createdAt
764
+ } : undefined,
765
+ updatedAt: props.updatedAt !== undefined ? {
766
+ equals: props.updatedAt
767
+ } : undefined,
768
+ },
769
+ };
770
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
771
+ const response = await client.query({
772
+ query: FIND_MANY_MARKETSENTIMENT,
773
+ variables: filteredVariables,
774
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
775
+ });
776
+ if (response.errors && response.errors.length > 0)
777
+ throw new Error(response.errors[0].message);
778
+ if (response && response.data && response.data.marketsentiments) {
779
+ return response.data.marketSentiments;
780
+ }
781
+ else {
782
+ return [];
783
+ }
454
784
  }
455
- else {
456
- console.error('Error in getMarketSentiment:', error);
785
+ catch (error) {
786
+ lastError = error;
787
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
788
+ if (error.message === 'No MarketSentiment found') {
789
+ return null;
790
+ }
791
+ // Check if this is a database connection error that we should retry
792
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
793
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
794
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
795
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
796
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
797
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
798
+ retryCount++;
799
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
800
+ console.warn("Database connection error, retrying...");
801
+ await new Promise(resolve => setTimeout(resolve, delay));
802
+ continue;
803
+ }
804
+ // Log the error and rethrow
805
+ console.error("Database error occurred:", error);
457
806
  throw error;
458
807
  }
459
808
  }
809
+ // If we exhausted retries, throw the last error
810
+ throw lastError;
460
811
  }
461
812
  };
462
813
  //# sourceMappingURL=MarketSentiment.js.map