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
package/EconomicEvent.cjs CHANGED
@@ -24,467 +24,808 @@ 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 ? props.title : undefined,
213
+ description: props.description !== undefined ? {
214
+ equals: props.description
215
+ } : undefined,
216
+ date: props.date !== undefined ? {
217
+ equals: props.date
218
+ } : undefined,
219
+ importance: props.importance !== undefined ? {
220
+ equals: props.importance
221
+ } : undefined,
222
+ createdAt: props.createdAt !== undefined ? {
223
+ equals: props.createdAt
224
+ } : undefined,
225
+ updatedAt: props.updatedAt !== undefined ? {
226
+ equals: props.updatedAt
227
+ } : undefined,
228
+ },
229
+ data: {
230
+ id: props.id !== undefined ? {
231
+ set: props.id
232
+ } : undefined,
233
+ title: props.title !== undefined ? {
234
+ set: props.title
235
+ } : undefined,
236
+ description: props.description !== undefined ? {
237
+ set: props.description
238
+ } : undefined,
239
+ date: props.date !== undefined ? {
240
+ set: props.date
241
+ } : undefined,
242
+ importance: props.importance !== undefined ? {
243
+ set: props.importance
244
+ } : undefined,
245
+ createdAt: props.createdAt !== undefined ? {
246
+ set: props.createdAt
247
+ } : undefined,
248
+ updatedAt: props.updatedAt !== undefined ? {
249
+ set: props.updatedAt
250
+ } : undefined,
251
+ },
252
+ };
253
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
254
+ const response = await client.mutate({
255
+ mutation: UPDATE_ONE_ECONOMICEVENT,
256
+ variables: filteredVariables,
257
+ // Don't cache mutations, but ensure we're using the freshest context
258
+ fetchPolicy: 'no-cache'
259
+ });
260
+ if (response.errors && response.errors.length > 0)
261
+ throw new Error(response.errors[0].message);
262
+ if (response && response.data && response.data.updateOneEconomicEvent) {
263
+ return response.data.updateOneEconomicEvent;
264
+ }
265
+ else {
266
+ return null;
267
+ }
268
+ }
269
+ catch (error) {
270
+ lastError = error;
271
+ // Check if this is a database connection error that we should retry
272
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
273
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
274
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
275
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
276
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
277
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
278
+ retryCount++;
279
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
280
+ console.warn("Database connection error, retrying...");
281
+ await new Promise(resolve => setTimeout(resolve, delay));
282
+ continue;
283
+ }
284
+ // Log the error and rethrow
285
+ console.error("Database error occurred:", error);
286
+ throw error;
173
287
  }
174
288
  }
175
- catch (error) {
176
- console.error('Error in updateOneEconomicEvent:', error);
177
- throw error;
178
- }
289
+ // If we exhausted retries, throw the last error
290
+ throw lastError;
179
291
  },
180
292
  /**
181
293
  * Upsert a single EconomicEvent record.
294
+ * Enhanced with connection resilience against Prisma connection errors.
182
295
  * @param props - Properties to update.
183
296
  * @param globalClient - Apollo Client instance.
184
297
  * @returns The updated EconomicEvent or null.
185
298
  */
186
299
  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;
300
+ var _a, _b, _c, _d, _e;
301
+ // Maximum number of retries for database connection issues
302
+ const MAX_RETRIES = 3;
303
+ let retryCount = 0;
304
+ let lastError = null;
305
+ // Retry loop to handle potential database connection issues
306
+ while (retryCount < MAX_RETRIES) {
307
+ try {
308
+ const [modules, client] = await Promise.all([
309
+ (0, client_1.getApolloModules)(),
310
+ globalClient
311
+ ? Promise.resolve(globalClient)
312
+ : client_1.client
313
+ ]);
314
+ const { gql, ApolloError } = modules;
315
+ const UPSERT_ONE_ECONOMICEVENT = gql `
316
+ mutation upsertOneEconomicEvent($where: EconomicEventWhereUniqueInput!, $create: EconomicEventCreateInput!, $update: EconomicEventUpdateInput!) {
317
+ upsertOneEconomicEvent(where: $where, create: $create, update: $update) {
318
+ ${selectionSet}
235
319
  }
236
- else {
237
- return null;
320
+ }`;
321
+ const variables = {
322
+ where: {
323
+ id: props.id !== undefined ? props.id : undefined,
324
+ title: props.title !== undefined ? props.title : undefined,
325
+ description: props.description !== undefined ? {
326
+ equals: props.description
327
+ } : undefined,
328
+ date: props.date !== undefined ? {
329
+ equals: props.date
330
+ } : undefined,
331
+ importance: props.importance !== undefined ? {
332
+ equals: props.importance
333
+ } : undefined,
334
+ createdAt: props.createdAt !== undefined ? {
335
+ equals: props.createdAt
336
+ } : undefined,
337
+ updatedAt: props.updatedAt !== undefined ? {
338
+ equals: props.updatedAt
339
+ } : undefined,
340
+ },
341
+ create: {
342
+ title: props.title !== undefined ? props.title : undefined,
343
+ description: props.description !== undefined ? props.description : undefined,
344
+ date: props.date !== undefined ? props.date : undefined,
345
+ importance: props.importance !== undefined ? props.importance : undefined,
346
+ },
347
+ update: {
348
+ title: props.title !== undefined ? {
349
+ set: props.title
350
+ } : undefined,
351
+ description: props.description !== undefined ? {
352
+ set: props.description
353
+ } : undefined,
354
+ date: props.date !== undefined ? {
355
+ set: props.date
356
+ } : undefined,
357
+ importance: props.importance !== undefined ? {
358
+ set: props.importance
359
+ } : undefined,
360
+ },
361
+ };
362
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
363
+ const response = await client.mutate({
364
+ mutation: UPSERT_ONE_ECONOMICEVENT,
365
+ variables: filteredVariables,
366
+ // Don't cache mutations, but ensure we're using the freshest context
367
+ fetchPolicy: 'no-cache'
368
+ });
369
+ if (response.errors && response.errors.length > 0)
370
+ throw new Error(response.errors[0].message);
371
+ if (response && response.data && response.data.upsertOneEconomicEvent) {
372
+ return response.data.upsertOneEconomicEvent;
373
+ }
374
+ else {
375
+ return null;
376
+ }
377
+ }
378
+ catch (error) {
379
+ lastError = error;
380
+ // Check if this is a database connection error that we should retry
381
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
382
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
383
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
384
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
385
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
386
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
387
+ retryCount++;
388
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
389
+ console.warn("Database connection error, retrying...");
390
+ await new Promise(resolve => setTimeout(resolve, delay));
391
+ continue;
392
+ }
393
+ // Log the error and rethrow
394
+ console.error("Database error occurred:", error);
395
+ throw error;
238
396
  }
239
397
  }
240
- catch (error) {
241
- console.error('Error in upsertOneEconomicEvent:', error);
242
- throw error;
243
- }
398
+ // If we exhausted retries, throw the last error
399
+ throw lastError;
244
400
  },
245
401
  /**
246
402
  * Update multiple EconomicEvent records.
403
+ * Enhanced with connection resilience against Prisma connection errors.
247
404
  * @param props - Array of EconomicEvent objects for the updated records.
248
405
  * @param globalClient - Apollo Client instance.
249
406
  * @returns The count of created records or null.
250
407
  */
251
408
  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;
409
+ var _a, _b, _c, _d, _e;
410
+ // Maximum number of retries for database connection issues
411
+ const MAX_RETRIES = 3;
412
+ let retryCount = 0;
413
+ let lastError = null;
414
+ // Retry loop to handle potential database connection issues
415
+ while (retryCount < MAX_RETRIES) {
416
+ try {
417
+ const [modules, client] = await Promise.all([
418
+ (0, client_1.getApolloModules)(),
419
+ globalClient
420
+ ? Promise.resolve(globalClient)
421
+ : client_1.client
422
+ ]);
423
+ const { gql, ApolloError } = modules;
424
+ const UPDATE_MANY_ECONOMICEVENT = gql `
425
+ mutation updateManyEconomicEvent($data: [EconomicEventCreateManyInput!]!) {
426
+ updateManyEconomicEvent(data: $data) {
427
+ count
303
428
  }
304
- else {
305
- return null;
429
+ }`;
430
+ const variables = props.map(prop => ({
431
+ where: {
432
+ id: prop.id !== undefined ? prop.id : undefined,
433
+ title: prop.title !== undefined ? prop.title : undefined,
434
+ description: prop.description !== undefined ? {
435
+ equals: prop.description
436
+ } : undefined,
437
+ date: prop.date !== undefined ? {
438
+ equals: prop.date
439
+ } : undefined,
440
+ importance: prop.importance !== undefined ? {
441
+ equals: prop.importance
442
+ } : undefined,
443
+ createdAt: prop.createdAt !== undefined ? {
444
+ equals: prop.createdAt
445
+ } : undefined,
446
+ updatedAt: prop.updatedAt !== undefined ? {
447
+ equals: prop.updatedAt
448
+ } : undefined,
449
+ },
450
+ data: {
451
+ id: prop.id !== undefined ? {
452
+ set: prop.id
453
+ } : undefined,
454
+ title: prop.title !== undefined ? {
455
+ set: prop.title
456
+ } : undefined,
457
+ description: prop.description !== undefined ? {
458
+ set: prop.description
459
+ } : undefined,
460
+ date: prop.date !== undefined ? {
461
+ set: prop.date
462
+ } : undefined,
463
+ importance: prop.importance !== undefined ? {
464
+ set: prop.importance
465
+ } : undefined,
466
+ createdAt: prop.createdAt !== undefined ? {
467
+ set: prop.createdAt
468
+ } : undefined,
469
+ updatedAt: prop.updatedAt !== undefined ? {
470
+ set: prop.updatedAt
471
+ } : undefined,
472
+ },
473
+ }));
474
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
475
+ const response = await client.mutate({
476
+ mutation: UPDATE_MANY_ECONOMICEVENT,
477
+ variables: filteredVariables,
478
+ // Don't cache mutations, but ensure we're using the freshest context
479
+ fetchPolicy: 'no-cache'
480
+ });
481
+ if (response.errors && response.errors.length > 0)
482
+ throw new Error(response.errors[0].message);
483
+ if (response && response.data && response.data.updateManyEconomicEvent) {
484
+ return response.data.updateManyEconomicEvent;
485
+ }
486
+ else {
487
+ return null;
488
+ }
489
+ }
490
+ catch (error) {
491
+ lastError = error;
492
+ // Check if this is a database connection error that we should retry
493
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
494
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
495
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
496
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
497
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
498
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
499
+ retryCount++;
500
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
501
+ console.warn("Database connection error, retrying...");
502
+ await new Promise(resolve => setTimeout(resolve, delay));
503
+ continue;
504
+ }
505
+ // Log the error and rethrow
506
+ console.error("Database error occurred:", error);
507
+ throw error;
306
508
  }
307
509
  }
308
- catch (error) {
309
- console.error('Error in updateManyEconomicEvent:', error);
310
- throw error;
311
- }
510
+ // If we exhausted retries, throw the last error
511
+ throw lastError;
312
512
  },
313
513
  /**
314
514
  * Delete a single EconomicEvent record.
315
- * @param props - Properties to update.
515
+ * Enhanced with connection resilience against Prisma connection errors.
516
+ * @param props - Properties to identify the record to delete.
316
517
  * @param globalClient - Apollo Client instance.
317
518
  * @returns The deleted EconomicEvent or null.
318
519
  */
319
520
  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,
521
+ var _a, _b, _c, _d, _e;
522
+ // Maximum number of retries for database connection issues
523
+ const MAX_RETRIES = 3;
524
+ let retryCount = 0;
525
+ let lastError = null;
526
+ // Retry loop to handle potential database connection issues
527
+ while (retryCount < MAX_RETRIES) {
528
+ try {
529
+ const [modules, client] = await Promise.all([
530
+ (0, client_1.getApolloModules)(),
531
+ globalClient
532
+ ? Promise.resolve(globalClient)
533
+ : client_1.client
534
+ ]);
535
+ const { gql, ApolloError } = modules;
536
+ const DELETE_ONE_ECONOMICEVENT = gql `
537
+ mutation deleteOneEconomicEvent($where: EconomicEventWhereUniqueInput!) {
538
+ deleteOneEconomicEvent(where: $where) {
539
+ id
336
540
  }
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;
541
+ }`;
542
+ const variables = {
543
+ where: {
544
+ id: props.id ? props.id : undefined,
545
+ }
546
+ };
547
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
548
+ const response = await client.mutate({
549
+ mutation: DELETE_ONE_ECONOMICEVENT,
550
+ variables: filteredVariables,
551
+ // Don't cache mutations, but ensure we're using the freshest context
552
+ fetchPolicy: 'no-cache'
553
+ });
554
+ if (response.errors && response.errors.length > 0)
555
+ throw new Error(response.errors[0].message);
556
+ if (response && response.data && response.data.deleteOneEconomicEvent) {
557
+ return response.data.deleteOneEconomicEvent;
558
+ }
559
+ else {
560
+ return null;
561
+ }
345
562
  }
346
- else {
347
- return null;
563
+ catch (error) {
564
+ lastError = error;
565
+ // Check if this is a database connection error that we should retry
566
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
567
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
568
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
569
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
570
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
571
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
572
+ retryCount++;
573
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
574
+ console.warn("Database connection error, retrying...");
575
+ await new Promise(resolve => setTimeout(resolve, delay));
576
+ continue;
577
+ }
578
+ // Log the error and rethrow
579
+ console.error("Database error occurred:", error);
580
+ throw error;
348
581
  }
349
582
  }
350
- catch (error) {
351
- console.error('Error in deleteOneEconomicEvent:', error);
352
- throw error;
353
- }
583
+ // If we exhausted retries, throw the last error
584
+ throw lastError;
354
585
  },
355
586
  /**
356
587
  * Retrieve a single EconomicEvent record by ID.
357
- * @param props - Properties to update.
588
+ * Enhanced with connection resilience against Prisma connection errors.
589
+ * @param props - Properties to identify the record.
358
590
  * @param globalClient - Apollo Client instance.
591
+ * @param whereInput - Optional custom where input.
359
592
  * @returns The retrieved EconomicEvent or null.
360
593
  */
361
594
  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;
595
+ var _a, _b, _c, _d, _e, _f, _g;
596
+ // Maximum number of retries for database connection issues
597
+ const MAX_RETRIES = 3;
598
+ let retryCount = 0;
599
+ let lastError = null;
600
+ // Retry loop to handle potential database connection issues
601
+ while (retryCount < MAX_RETRIES) {
602
+ try {
603
+ const [modules, client] = await Promise.all([
604
+ (0, client_1.getApolloModules)(),
605
+ globalClient
606
+ ? Promise.resolve(globalClient)
607
+ : client_1.client
608
+ ]);
609
+ const { gql, ApolloError } = modules;
610
+ const GET_ECONOMICEVENT = gql `
611
+ query getEconomicEvent($where: EconomicEventWhereUniqueInput!) {
612
+ getEconomicEvent(where: $where) {
613
+ ${selectionSet}
614
+ }
615
+ }`;
616
+ const variables = {
617
+ where: whereInput ? whereInput : {
618
+ id: props.id !== undefined ? props.id : undefined,
619
+ title: props.title !== undefined ? props.title : undefined,
620
+ description: props.description !== undefined ? {
621
+ equals: props.description
622
+ } : undefined,
623
+ date: props.date !== undefined ? {
624
+ equals: props.date
625
+ } : undefined,
626
+ importance: props.importance !== undefined ? {
627
+ equals: props.importance
628
+ } : undefined,
629
+ createdAt: props.createdAt !== undefined ? {
630
+ equals: props.createdAt
631
+ } : undefined,
632
+ updatedAt: props.updatedAt !== undefined ? {
633
+ equals: props.updatedAt
634
+ } : undefined,
635
+ },
636
+ };
637
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
638
+ const response = await client.query({
639
+ query: GET_ECONOMICEVENT,
640
+ variables: filteredVariables,
641
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
642
+ });
643
+ if (response.errors && response.errors.length > 0)
644
+ throw new Error(response.errors[0].message);
645
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getEconomicEvent) !== null && _b !== void 0 ? _b : null;
394
646
  }
395
- else {
396
- console.error('Error in getEconomicEvent:', error);
647
+ catch (error) {
648
+ lastError = error;
649
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
650
+ if (error.message === 'No EconomicEvent found') {
651
+ return null;
652
+ }
653
+ // Check if this is a database connection error that we should retry
654
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
655
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
656
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
657
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
658
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
659
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
660
+ retryCount++;
661
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
662
+ console.warn("Database connection error, retrying...");
663
+ await new Promise(resolve => setTimeout(resolve, delay));
664
+ continue;
665
+ }
666
+ // Log the error and rethrow
667
+ console.error("Database error occurred:", error);
397
668
  throw error;
398
669
  }
399
670
  }
671
+ // If we exhausted retries, throw the last error
672
+ throw lastError;
400
673
  },
401
674
  /**
402
675
  * Retrieve all EconomicEvents records.
676
+ * Enhanced with connection resilience against Prisma connection errors.
403
677
  * @param globalClient - Apollo Client instance.
404
678
  * @returns An array of EconomicEvent records or null.
405
679
  */
406
680
  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;
681
+ var _a, _b, _c, _d, _e, _f, _g;
682
+ // Maximum number of retries for database connection issues
683
+ const MAX_RETRIES = 3;
684
+ let retryCount = 0;
685
+ let lastError = null;
686
+ // Retry loop to handle potential database connection issues
687
+ while (retryCount < MAX_RETRIES) {
688
+ try {
689
+ const [modules, client] = await Promise.all([
690
+ (0, client_1.getApolloModules)(),
691
+ globalClient
692
+ ? Promise.resolve(globalClient)
693
+ : client_1.client
694
+ ]);
695
+ const { gql, ApolloError } = modules;
696
+ const GET_ALL_ECONOMICEVENT = gql `
697
+ query getAllEconomicEvent {
698
+ economicEvents {
699
+ ${selectionSet}
430
700
  }
431
- else {
432
- console.error('Error in getEconomicEvent:', error);
701
+ }`;
702
+ const response = await client.query({
703
+ query: GET_ALL_ECONOMICEVENT,
704
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
705
+ });
706
+ if (response.errors && response.errors.length > 0)
707
+ throw new Error(response.errors[0].message);
708
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.economicEvents) !== null && _b !== void 0 ? _b : null;
709
+ }
710
+ catch (error) {
711
+ lastError = error;
712
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
713
+ if (error.message === 'No EconomicEvent found') {
714
+ return null;
715
+ }
716
+ // Check if this is a database connection error that we should retry
717
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
718
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
719
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
720
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
721
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
722
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
723
+ retryCount++;
724
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
725
+ console.warn("Database connection error, retrying...");
726
+ await new Promise(resolve => setTimeout(resolve, delay));
727
+ continue;
728
+ }
729
+ // Log the error and rethrow
730
+ console.error("Database error occurred:", error);
433
731
  throw error;
434
732
  }
435
733
  }
734
+ // If we exhausted retries, throw the last error
735
+ throw lastError;
436
736
  },
437
737
  /**
438
738
  * Find multiple EconomicEvent records based on conditions.
739
+ * Enhanced with connection resilience against Prisma connection errors.
439
740
  * @param props - Conditions to find records.
440
741
  * @param globalClient - Apollo Client instance.
742
+ * @param whereInput - Optional custom where input.
441
743
  * @returns An array of found EconomicEvent records or null.
442
744
  */
443
745
  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;
746
+ var _a, _b, _c, _d, _e;
747
+ // Maximum number of retries for database connection issues
748
+ const MAX_RETRIES = 3;
749
+ let retryCount = 0;
750
+ let lastError = null;
751
+ // Retry loop to handle potential database connection issues
752
+ while (retryCount < MAX_RETRIES) {
753
+ try {
754
+ const [modules, client] = await Promise.all([
755
+ (0, client_1.getApolloModules)(),
756
+ globalClient
757
+ ? Promise.resolve(globalClient)
758
+ : client_1.client
759
+ ]);
760
+ const { gql, ApolloError } = modules;
761
+ const FIND_MANY_ECONOMICEVENT = gql `
762
+ query findManyEconomicEvent($where: EconomicEventWhereInput!) {
763
+ economicEvents(where: $where) {
764
+ ${selectionSet}
474
765
  }
475
- else {
476
- return [];
477
- }
478
- }
479
- catch (error) {
480
- if (error instanceof ApolloError && error.message === 'No EconomicEvent found') {
481
- return null;
766
+ }`;
767
+ const variables = {
768
+ where: whereInput ? whereInput : {
769
+ id: props.id !== undefined ? props.id : undefined,
770
+ title: props.title !== undefined ? props.title : undefined,
771
+ description: props.description !== undefined ? {
772
+ equals: props.description
773
+ } : undefined,
774
+ date: props.date !== undefined ? {
775
+ equals: props.date
776
+ } : undefined,
777
+ importance: props.importance !== undefined ? {
778
+ equals: props.importance
779
+ } : undefined,
780
+ createdAt: props.createdAt !== undefined ? {
781
+ equals: props.createdAt
782
+ } : undefined,
783
+ updatedAt: props.updatedAt !== undefined ? {
784
+ equals: props.updatedAt
785
+ } : undefined,
786
+ },
787
+ };
788
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
789
+ const response = await client.query({
790
+ query: FIND_MANY_ECONOMICEVENT,
791
+ variables: filteredVariables,
792
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
793
+ });
794
+ if (response.errors && response.errors.length > 0)
795
+ throw new Error(response.errors[0].message);
796
+ if (response && response.data && response.data.economicevents) {
797
+ return response.data.economicEvents;
798
+ }
799
+ else {
800
+ return [];
801
+ }
482
802
  }
483
- else {
484
- console.error('Error in getEconomicEvent:', error);
803
+ catch (error) {
804
+ lastError = error;
805
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
806
+ if (error.message === 'No EconomicEvent found') {
807
+ return null;
808
+ }
809
+ // Check if this is a database connection error that we should retry
810
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
811
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
812
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
813
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
814
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
815
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
816
+ retryCount++;
817
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
818
+ console.warn("Database connection error, retrying...");
819
+ await new Promise(resolve => setTimeout(resolve, delay));
820
+ continue;
821
+ }
822
+ // Log the error and rethrow
823
+ console.error("Database error occurred:", error);
485
824
  throw error;
486
825
  }
487
826
  }
827
+ // If we exhausted retries, throw the last error
828
+ throw lastError;
488
829
  }
489
830
  };
490
831
  //# sourceMappingURL=EconomicEvent.js.map