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