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