adaptic-backend 1.0.340 → 1.0.341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Account.cjs +2543 -2265
- package/Account.d.ts +19 -2
- package/Action.cjs +1116 -838
- package/Action.d.ts +19 -2
- package/Alert.cjs +2626 -2348
- package/Alert.d.ts +19 -2
- package/Allocation.cjs +2578 -2300
- package/Allocation.d.ts +19 -2
- package/AlpacaAccount.cjs +2383 -2105
- package/AlpacaAccount.d.ts +19 -2
- package/Asset.cjs +1813 -1535
- package/Asset.d.ts +19 -2
- package/Authenticator.cjs +2568 -2290
- package/Authenticator.d.ts +19 -2
- package/Customer.cjs +2495 -2217
- package/Customer.d.ts +19 -2
- package/EconomicEvent.cjs +645 -367
- package/EconomicEvent.d.ts +19 -2
- package/MarketSentiment.cjs +618 -340
- package/MarketSentiment.d.ts +19 -2
- package/NewsArticle.cjs +1933 -1655
- package/NewsArticle.d.ts +19 -2
- package/NewsArticleAssetSentiment.cjs +1842 -1564
- package/NewsArticleAssetSentiment.d.ts +19 -2
- package/ScheduledOptionOrder.cjs +594 -316
- package/ScheduledOptionOrder.d.ts +19 -2
- package/Session.cjs +2570 -2292
- package/Session.d.ts +19 -2
- package/Trade.cjs +1073 -795
- package/Trade.d.ts +19 -2
- package/User.cjs +2288 -2010
- package/User.d.ts +19 -2
- package/VerificationToken.cjs +606 -328
- package/VerificationToken.d.ts +19 -2
- package/esm/Account.d.ts +19 -2
- package/esm/Account.d.ts.map +1 -1
- package/esm/Account.js.map +1 -1
- package/esm/Account.mjs +2534 -2263
- package/esm/Action.d.ts +19 -2
- package/esm/Action.d.ts.map +1 -1
- package/esm/Action.js.map +1 -1
- package/esm/Action.mjs +1107 -836
- package/esm/Alert.d.ts +19 -2
- package/esm/Alert.d.ts.map +1 -1
- package/esm/Alert.js.map +1 -1
- package/esm/Alert.mjs +2617 -2346
- package/esm/Allocation.d.ts +19 -2
- package/esm/Allocation.d.ts.map +1 -1
- package/esm/Allocation.js.map +1 -1
- package/esm/Allocation.mjs +2569 -2298
- package/esm/AlpacaAccount.d.ts +19 -2
- package/esm/AlpacaAccount.d.ts.map +1 -1
- package/esm/AlpacaAccount.js.map +1 -1
- package/esm/AlpacaAccount.mjs +2374 -2103
- package/esm/Asset.d.ts +19 -2
- package/esm/Asset.d.ts.map +1 -1
- package/esm/Asset.js.map +1 -1
- package/esm/Asset.mjs +1804 -1533
- package/esm/Authenticator.d.ts +19 -2
- package/esm/Authenticator.d.ts.map +1 -1
- package/esm/Authenticator.js.map +1 -1
- package/esm/Authenticator.mjs +2559 -2288
- package/esm/Customer.d.ts +19 -2
- package/esm/Customer.d.ts.map +1 -1
- package/esm/Customer.js.map +1 -1
- package/esm/Customer.mjs +2486 -2215
- package/esm/EconomicEvent.d.ts +19 -2
- package/esm/EconomicEvent.d.ts.map +1 -1
- package/esm/EconomicEvent.js.map +1 -1
- package/esm/EconomicEvent.mjs +636 -365
- package/esm/MarketSentiment.d.ts +19 -2
- package/esm/MarketSentiment.d.ts.map +1 -1
- package/esm/MarketSentiment.js.map +1 -1
- package/esm/MarketSentiment.mjs +609 -338
- package/esm/NewsArticle.d.ts +19 -2
- package/esm/NewsArticle.d.ts.map +1 -1
- package/esm/NewsArticle.js.map +1 -1
- package/esm/NewsArticle.mjs +1924 -1653
- package/esm/NewsArticleAssetSentiment.d.ts +19 -2
- package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
- package/esm/NewsArticleAssetSentiment.js.map +1 -1
- package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
- package/esm/ScheduledOptionOrder.d.ts +19 -2
- package/esm/ScheduledOptionOrder.d.ts.map +1 -1
- package/esm/ScheduledOptionOrder.js.map +1 -1
- package/esm/ScheduledOptionOrder.mjs +585 -314
- package/esm/Session.d.ts +19 -2
- package/esm/Session.d.ts.map +1 -1
- package/esm/Session.js.map +1 -1
- package/esm/Session.mjs +2561 -2290
- package/esm/Trade.d.ts +19 -2
- package/esm/Trade.d.ts.map +1 -1
- package/esm/Trade.js.map +1 -1
- package/esm/Trade.mjs +1064 -793
- package/esm/User.d.ts +19 -2
- package/esm/User.d.ts.map +1 -1
- package/esm/User.js.map +1 -1
- package/esm/User.mjs +2279 -2008
- package/esm/VerificationToken.d.ts +19 -2
- package/esm/VerificationToken.d.ts.map +1 -1
- package/esm/VerificationToken.js.map +1 -1
- package/esm/VerificationToken.mjs +597 -326
- package/esm/prismaClient.d.ts +4 -5
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +13 -11
- package/package.json +1 -1
- package/prismaClient.cjs +13 -11
- package/prismaClient.d.ts +4 -5
- package/server.cjs +37 -5
package/esm/EconomicEvent.mjs
CHANGED
@@ -21,465 +21,736 @@ 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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
101
|
-
|
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
|
-
|
105
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
169
|
-
|
202
|
+
}`;
|
203
|
+
const variables = {
|
204
|
+
where: {
|
205
|
+
id: props.id !== undefined ? props.id : undefined,
|
206
|
+
title: props.title !== undefined ? {
|
207
|
+
equals: props.title
|
208
|
+
} : undefined,
|
209
|
+
},
|
210
|
+
data: {
|
211
|
+
id: props.id !== undefined ? {
|
212
|
+
set: props.id
|
213
|
+
} : undefined,
|
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
|
+
createdAt: props.createdAt !== undefined ? {
|
227
|
+
set: props.createdAt
|
228
|
+
} : undefined,
|
229
|
+
updatedAt: props.updatedAt !== undefined ? {
|
230
|
+
set: props.updatedAt
|
231
|
+
} : undefined,
|
232
|
+
},
|
233
|
+
};
|
234
|
+
const filteredVariables = removeUndefinedProps(variables);
|
235
|
+
const response = await client.mutate({
|
236
|
+
mutation: UPDATE_ONE_ECONOMICEVENT,
|
237
|
+
variables: filteredVariables,
|
238
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
239
|
+
fetchPolicy: 'no-cache'
|
240
|
+
});
|
241
|
+
if (response.errors && response.errors.length > 0)
|
242
|
+
throw new Error(response.errors[0].message);
|
243
|
+
if (response && response.data && response.data.updateOneEconomicEvent) {
|
244
|
+
return response.data.updateOneEconomicEvent;
|
245
|
+
}
|
246
|
+
else {
|
247
|
+
return null;
|
248
|
+
}
|
249
|
+
}
|
250
|
+
catch (error) {
|
251
|
+
lastError = error;
|
252
|
+
// Check if this is a database connection error that we should retry
|
253
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
254
|
+
error.message?.includes('Cannot reach database server') ||
|
255
|
+
error.message?.includes('Connection timed out') ||
|
256
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
257
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
258
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
259
|
+
retryCount++;
|
260
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
261
|
+
console.warn("Database connection error, retrying...");
|
262
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
263
|
+
continue;
|
264
|
+
}
|
265
|
+
// Log the error and rethrow
|
266
|
+
console.error("Database error occurred:", error);
|
267
|
+
throw error;
|
170
268
|
}
|
171
269
|
}
|
172
|
-
|
173
|
-
|
174
|
-
throw error;
|
175
|
-
}
|
270
|
+
// If we exhausted retries, throw the last error
|
271
|
+
throw lastError;
|
176
272
|
},
|
177
273
|
/**
|
178
274
|
* Upsert a single EconomicEvent record.
|
275
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
179
276
|
* @param props - Properties to update.
|
180
277
|
* @param globalClient - Apollo Client instance.
|
181
278
|
* @returns The updated EconomicEvent or null.
|
182
279
|
*/
|
183
280
|
async upsert(props, globalClient) {
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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;
|
281
|
+
// Maximum number of retries for database connection issues
|
282
|
+
const MAX_RETRIES = 3;
|
283
|
+
let retryCount = 0;
|
284
|
+
let lastError = null;
|
285
|
+
// Retry loop to handle potential database connection issues
|
286
|
+
while (retryCount < MAX_RETRIES) {
|
287
|
+
try {
|
288
|
+
const [modules, client] = await Promise.all([
|
289
|
+
getApolloModules(),
|
290
|
+
globalClient
|
291
|
+
? Promise.resolve(globalClient)
|
292
|
+
: importedClient
|
293
|
+
]);
|
294
|
+
const { gql, ApolloError } = modules;
|
295
|
+
const UPSERT_ONE_ECONOMICEVENT = gql `
|
296
|
+
mutation upsertOneEconomicEvent($where: EconomicEventWhereUniqueInput!, $create: EconomicEventCreateInput!, $update: EconomicEventUpdateInput!) {
|
297
|
+
upsertOneEconomicEvent(where: $where, create: $create, update: $update) {
|
298
|
+
${selectionSet}
|
232
299
|
}
|
233
|
-
|
234
|
-
|
300
|
+
}`;
|
301
|
+
const variables = {
|
302
|
+
where: {
|
303
|
+
id: props.id !== undefined ? props.id : undefined,
|
304
|
+
title: props.title !== undefined ? {
|
305
|
+
equals: props.title
|
306
|
+
} : undefined,
|
307
|
+
},
|
308
|
+
create: {
|
309
|
+
title: props.title !== undefined ? props.title : undefined,
|
310
|
+
description: props.description !== undefined ? props.description : undefined,
|
311
|
+
date: props.date !== undefined ? props.date : undefined,
|
312
|
+
importance: props.importance !== undefined ? props.importance : undefined,
|
313
|
+
},
|
314
|
+
update: {
|
315
|
+
title: props.title !== undefined ? {
|
316
|
+
set: props.title
|
317
|
+
} : undefined,
|
318
|
+
description: props.description !== undefined ? {
|
319
|
+
set: props.description
|
320
|
+
} : undefined,
|
321
|
+
date: props.date !== undefined ? {
|
322
|
+
set: props.date
|
323
|
+
} : undefined,
|
324
|
+
importance: props.importance !== undefined ? {
|
325
|
+
set: props.importance
|
326
|
+
} : undefined,
|
327
|
+
},
|
328
|
+
};
|
329
|
+
const filteredVariables = removeUndefinedProps(variables);
|
330
|
+
const response = await client.mutate({
|
331
|
+
mutation: UPSERT_ONE_ECONOMICEVENT,
|
332
|
+
variables: filteredVariables,
|
333
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
334
|
+
fetchPolicy: 'no-cache'
|
335
|
+
});
|
336
|
+
if (response.errors && response.errors.length > 0)
|
337
|
+
throw new Error(response.errors[0].message);
|
338
|
+
if (response && response.data && response.data.upsertOneEconomicEvent) {
|
339
|
+
return response.data.upsertOneEconomicEvent;
|
340
|
+
}
|
341
|
+
else {
|
342
|
+
return null;
|
343
|
+
}
|
344
|
+
}
|
345
|
+
catch (error) {
|
346
|
+
lastError = error;
|
347
|
+
// Check if this is a database connection error that we should retry
|
348
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
349
|
+
error.message?.includes('Cannot reach database server') ||
|
350
|
+
error.message?.includes('Connection timed out') ||
|
351
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
352
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
353
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
354
|
+
retryCount++;
|
355
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
356
|
+
console.warn("Database connection error, retrying...");
|
357
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
358
|
+
continue;
|
359
|
+
}
|
360
|
+
// Log the error and rethrow
|
361
|
+
console.error("Database error occurred:", error);
|
362
|
+
throw error;
|
235
363
|
}
|
236
364
|
}
|
237
|
-
|
238
|
-
|
239
|
-
throw error;
|
240
|
-
}
|
365
|
+
// If we exhausted retries, throw the last error
|
366
|
+
throw lastError;
|
241
367
|
},
|
242
368
|
/**
|
243
369
|
* Update multiple EconomicEvent records.
|
370
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
244
371
|
* @param props - Array of EconomicEvent objects for the updated records.
|
245
372
|
* @param globalClient - Apollo Client instance.
|
246
373
|
* @returns The count of created records or null.
|
247
374
|
*/
|
248
375
|
async updateMany(props, globalClient) {
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
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;
|
376
|
+
// Maximum number of retries for database connection issues
|
377
|
+
const MAX_RETRIES = 3;
|
378
|
+
let retryCount = 0;
|
379
|
+
let lastError = null;
|
380
|
+
// Retry loop to handle potential database connection issues
|
381
|
+
while (retryCount < MAX_RETRIES) {
|
382
|
+
try {
|
383
|
+
const [modules, client] = await Promise.all([
|
384
|
+
getApolloModules(),
|
385
|
+
globalClient
|
386
|
+
? Promise.resolve(globalClient)
|
387
|
+
: importedClient
|
388
|
+
]);
|
389
|
+
const { gql, ApolloError } = modules;
|
390
|
+
const UPDATE_MANY_ECONOMICEVENT = gql `
|
391
|
+
mutation updateManyEconomicEvent($data: [EconomicEventCreateManyInput!]!) {
|
392
|
+
updateManyEconomicEvent(data: $data) {
|
393
|
+
count
|
300
394
|
}
|
301
|
-
|
302
|
-
|
395
|
+
}`;
|
396
|
+
const variables = props.map(prop => ({
|
397
|
+
where: {
|
398
|
+
id: prop.id !== undefined ? prop.id : undefined,
|
399
|
+
title: prop.title !== undefined ? {
|
400
|
+
equals: prop.title
|
401
|
+
} : undefined,
|
402
|
+
},
|
403
|
+
data: {
|
404
|
+
id: prop.id !== undefined ? {
|
405
|
+
set: prop.id
|
406
|
+
} : undefined,
|
407
|
+
title: prop.title !== undefined ? {
|
408
|
+
set: prop.title
|
409
|
+
} : undefined,
|
410
|
+
description: prop.description !== undefined ? {
|
411
|
+
set: prop.description
|
412
|
+
} : undefined,
|
413
|
+
date: prop.date !== undefined ? {
|
414
|
+
set: prop.date
|
415
|
+
} : undefined,
|
416
|
+
importance: prop.importance !== undefined ? {
|
417
|
+
set: prop.importance
|
418
|
+
} : undefined,
|
419
|
+
createdAt: prop.createdAt !== undefined ? {
|
420
|
+
set: prop.createdAt
|
421
|
+
} : undefined,
|
422
|
+
updatedAt: prop.updatedAt !== undefined ? {
|
423
|
+
set: prop.updatedAt
|
424
|
+
} : undefined,
|
425
|
+
},
|
426
|
+
}));
|
427
|
+
const filteredVariables = removeUndefinedProps(variables);
|
428
|
+
const response = await client.mutate({
|
429
|
+
mutation: UPDATE_MANY_ECONOMICEVENT,
|
430
|
+
variables: filteredVariables,
|
431
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
432
|
+
fetchPolicy: 'no-cache'
|
433
|
+
});
|
434
|
+
if (response.errors && response.errors.length > 0)
|
435
|
+
throw new Error(response.errors[0].message);
|
436
|
+
if (response && response.data && response.data.updateManyEconomicEvent) {
|
437
|
+
return response.data.updateManyEconomicEvent;
|
438
|
+
}
|
439
|
+
else {
|
440
|
+
return null;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
catch (error) {
|
444
|
+
lastError = error;
|
445
|
+
// Check if this is a database connection error that we should retry
|
446
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
447
|
+
error.message?.includes('Cannot reach database server') ||
|
448
|
+
error.message?.includes('Connection timed out') ||
|
449
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
450
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
451
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
452
|
+
retryCount++;
|
453
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
454
|
+
console.warn("Database connection error, retrying...");
|
455
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
456
|
+
continue;
|
457
|
+
}
|
458
|
+
// Log the error and rethrow
|
459
|
+
console.error("Database error occurred:", error);
|
460
|
+
throw error;
|
303
461
|
}
|
304
462
|
}
|
305
|
-
|
306
|
-
|
307
|
-
throw error;
|
308
|
-
}
|
463
|
+
// If we exhausted retries, throw the last error
|
464
|
+
throw lastError;
|
309
465
|
},
|
310
466
|
/**
|
311
467
|
* Delete a single EconomicEvent record.
|
312
|
-
*
|
468
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
469
|
+
* @param props - Properties to identify the record to delete.
|
313
470
|
* @param globalClient - Apollo Client instance.
|
314
471
|
* @returns The deleted EconomicEvent or null.
|
315
472
|
*/
|
316
473
|
async delete(props, globalClient) {
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
474
|
+
// Maximum number of retries for database connection issues
|
475
|
+
const MAX_RETRIES = 3;
|
476
|
+
let retryCount = 0;
|
477
|
+
let lastError = null;
|
478
|
+
// Retry loop to handle potential database connection issues
|
479
|
+
while (retryCount < MAX_RETRIES) {
|
480
|
+
try {
|
481
|
+
const [modules, client] = await Promise.all([
|
482
|
+
getApolloModules(),
|
483
|
+
globalClient
|
484
|
+
? Promise.resolve(globalClient)
|
485
|
+
: importedClient
|
486
|
+
]);
|
487
|
+
const { gql, ApolloError } = modules;
|
488
|
+
const DELETE_ONE_ECONOMICEVENT = gql `
|
489
|
+
mutation deleteOneEconomicEvent($where: EconomicEventWhereUniqueInput!) {
|
490
|
+
deleteOneEconomicEvent(where: $where) {
|
491
|
+
id
|
333
492
|
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
493
|
+
}`;
|
494
|
+
const variables = {
|
495
|
+
where: {
|
496
|
+
id: props.id ? props.id : undefined,
|
497
|
+
}
|
498
|
+
};
|
499
|
+
const filteredVariables = removeUndefinedProps(variables);
|
500
|
+
const response = await client.mutate({
|
501
|
+
mutation: DELETE_ONE_ECONOMICEVENT,
|
502
|
+
variables: filteredVariables,
|
503
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
504
|
+
fetchPolicy: 'no-cache'
|
505
|
+
});
|
506
|
+
if (response.errors && response.errors.length > 0)
|
507
|
+
throw new Error(response.errors[0].message);
|
508
|
+
if (response && response.data && response.data.deleteOneEconomicEvent) {
|
509
|
+
return response.data.deleteOneEconomicEvent;
|
510
|
+
}
|
511
|
+
else {
|
512
|
+
return null;
|
513
|
+
}
|
342
514
|
}
|
343
|
-
|
344
|
-
|
515
|
+
catch (error) {
|
516
|
+
lastError = error;
|
517
|
+
// Check if this is a database connection error that we should retry
|
518
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
519
|
+
error.message?.includes('Cannot reach database server') ||
|
520
|
+
error.message?.includes('Connection timed out') ||
|
521
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
522
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
523
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
524
|
+
retryCount++;
|
525
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
526
|
+
console.warn("Database connection error, retrying...");
|
527
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
528
|
+
continue;
|
529
|
+
}
|
530
|
+
// Log the error and rethrow
|
531
|
+
console.error("Database error occurred:", error);
|
532
|
+
throw error;
|
345
533
|
}
|
346
534
|
}
|
347
|
-
|
348
|
-
|
349
|
-
throw error;
|
350
|
-
}
|
535
|
+
// If we exhausted retries, throw the last error
|
536
|
+
throw lastError;
|
351
537
|
},
|
352
538
|
/**
|
353
539
|
* Retrieve a single EconomicEvent record by ID.
|
354
|
-
*
|
540
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
541
|
+
* @param props - Properties to identify the record.
|
355
542
|
* @param globalClient - Apollo Client instance.
|
543
|
+
* @param whereInput - Optional custom where input.
|
356
544
|
* @returns The retrieved EconomicEvent or null.
|
357
545
|
*/
|
358
546
|
async get(props, globalClient, whereInput) {
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
547
|
+
// Maximum number of retries for database connection issues
|
548
|
+
const MAX_RETRIES = 3;
|
549
|
+
let retryCount = 0;
|
550
|
+
let lastError = null;
|
551
|
+
// Retry loop to handle potential database connection issues
|
552
|
+
while (retryCount < MAX_RETRIES) {
|
553
|
+
try {
|
554
|
+
const [modules, client] = await Promise.all([
|
555
|
+
getApolloModules(),
|
556
|
+
globalClient
|
557
|
+
? Promise.resolve(globalClient)
|
558
|
+
: importedClient
|
559
|
+
]);
|
560
|
+
const { gql, ApolloError } = modules;
|
561
|
+
const GET_ECONOMICEVENT = gql `
|
562
|
+
query getEconomicEvent($where: EconomicEventWhereUniqueInput!) {
|
563
|
+
getEconomicEvent(where: $where) {
|
564
|
+
${selectionSet}
|
565
|
+
}
|
566
|
+
}`;
|
567
|
+
const variables = {
|
568
|
+
where: whereInput ? whereInput : {
|
569
|
+
id: props.id !== undefined ? props.id : undefined,
|
570
|
+
title: props.title !== undefined ? {
|
571
|
+
equals: props.title
|
572
|
+
} : undefined,
|
573
|
+
},
|
574
|
+
};
|
575
|
+
const filteredVariables = removeUndefinedProps(variables);
|
576
|
+
const response = await client.query({
|
577
|
+
query: GET_ECONOMICEVENT,
|
578
|
+
variables: filteredVariables,
|
579
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
580
|
+
});
|
581
|
+
if (response.errors && response.errors.length > 0)
|
582
|
+
throw new Error(response.errors[0].message);
|
583
|
+
return response.data?.getEconomicEvent ?? null;
|
390
584
|
}
|
391
|
-
|
392
|
-
|
585
|
+
catch (error) {
|
586
|
+
lastError = error;
|
587
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
588
|
+
if (error.message === 'No EconomicEvent found') {
|
589
|
+
return null;
|
590
|
+
}
|
591
|
+
// Check if this is a database connection error that we should retry
|
592
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
593
|
+
error.message?.includes('Cannot reach database server') ||
|
594
|
+
error.message?.includes('Connection timed out') ||
|
595
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
596
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
597
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
598
|
+
retryCount++;
|
599
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
600
|
+
console.warn("Database connection error, retrying...");
|
601
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
602
|
+
continue;
|
603
|
+
}
|
604
|
+
// Log the error and rethrow
|
605
|
+
console.error("Database error occurred:", error);
|
393
606
|
throw error;
|
394
607
|
}
|
395
608
|
}
|
609
|
+
// If we exhausted retries, throw the last error
|
610
|
+
throw lastError;
|
396
611
|
},
|
397
612
|
/**
|
398
613
|
* Retrieve all EconomicEvents records.
|
614
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
399
615
|
* @param globalClient - Apollo Client instance.
|
400
616
|
* @returns An array of EconomicEvent records or null.
|
401
617
|
*/
|
402
618
|
async getAll(globalClient) {
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
}
|
422
|
-
catch (error) {
|
423
|
-
if (error instanceof ApolloError && error.message === 'No EconomicEvent found') {
|
424
|
-
return null;
|
619
|
+
// Maximum number of retries for database connection issues
|
620
|
+
const MAX_RETRIES = 3;
|
621
|
+
let retryCount = 0;
|
622
|
+
let lastError = null;
|
623
|
+
// Retry loop to handle potential database connection issues
|
624
|
+
while (retryCount < MAX_RETRIES) {
|
625
|
+
try {
|
626
|
+
const [modules, client] = await Promise.all([
|
627
|
+
getApolloModules(),
|
628
|
+
globalClient
|
629
|
+
? Promise.resolve(globalClient)
|
630
|
+
: importedClient
|
631
|
+
]);
|
632
|
+
const { gql, ApolloError } = modules;
|
633
|
+
const GET_ALL_ECONOMICEVENT = gql `
|
634
|
+
query getAllEconomicEvent {
|
635
|
+
economicEvents {
|
636
|
+
${selectionSet}
|
425
637
|
}
|
426
|
-
|
427
|
-
|
638
|
+
}`;
|
639
|
+
const response = await client.query({
|
640
|
+
query: GET_ALL_ECONOMICEVENT,
|
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 response.data?.economicEvents ?? null;
|
646
|
+
}
|
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 = error.message?.includes('Server has closed the connection') ||
|
655
|
+
error.message?.includes('Cannot reach database server') ||
|
656
|
+
error.message?.includes('Connection timed out') ||
|
657
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
658
|
+
(error.networkError && error.networkError.message?.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);
|
428
668
|
throw error;
|
429
669
|
}
|
430
670
|
}
|
671
|
+
// If we exhausted retries, throw the last error
|
672
|
+
throw lastError;
|
431
673
|
},
|
432
674
|
/**
|
433
675
|
* Find multiple EconomicEvent records based on conditions.
|
676
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
434
677
|
* @param props - Conditions to find records.
|
435
678
|
* @param globalClient - Apollo Client instance.
|
679
|
+
* @param whereInput - Optional custom where input.
|
436
680
|
* @returns An array of found EconomicEvent records or null.
|
437
681
|
*/
|
438
682
|
async findMany(props, globalClient, whereInput) {
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
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;
|
683
|
+
// Maximum number of retries for database connection issues
|
684
|
+
const MAX_RETRIES = 3;
|
685
|
+
let retryCount = 0;
|
686
|
+
let lastError = null;
|
687
|
+
// Retry loop to handle potential database connection issues
|
688
|
+
while (retryCount < MAX_RETRIES) {
|
689
|
+
try {
|
690
|
+
const [modules, client] = await Promise.all([
|
691
|
+
getApolloModules(),
|
692
|
+
globalClient
|
693
|
+
? Promise.resolve(globalClient)
|
694
|
+
: importedClient
|
695
|
+
]);
|
696
|
+
const { gql, ApolloError } = modules;
|
697
|
+
const FIND_MANY_ECONOMICEVENT = gql `
|
698
|
+
query findManyEconomicEvent($where: EconomicEventWhereInput!) {
|
699
|
+
economicEvents(where: $where) {
|
700
|
+
${selectionSet}
|
469
701
|
}
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
702
|
+
}`;
|
703
|
+
const variables = {
|
704
|
+
where: whereInput ? whereInput : {
|
705
|
+
id: props.id !== undefined ? {
|
706
|
+
equals: props.id
|
707
|
+
} : undefined,
|
708
|
+
title: props.title !== undefined ? {
|
709
|
+
equals: props.title
|
710
|
+
} : undefined,
|
711
|
+
},
|
712
|
+
};
|
713
|
+
const filteredVariables = removeUndefinedProps(variables);
|
714
|
+
const response = await client.query({
|
715
|
+
query: FIND_MANY_ECONOMICEVENT,
|
716
|
+
variables: filteredVariables,
|
717
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
718
|
+
});
|
719
|
+
if (response.errors && response.errors.length > 0)
|
720
|
+
throw new Error(response.errors[0].message);
|
721
|
+
if (response && response.data && response.data.economicevents) {
|
722
|
+
return response.data.economicEvents;
|
723
|
+
}
|
724
|
+
else {
|
725
|
+
return [];
|
726
|
+
}
|
477
727
|
}
|
478
|
-
|
479
|
-
|
728
|
+
catch (error) {
|
729
|
+
lastError = error;
|
730
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
731
|
+
if (error.message === 'No EconomicEvent found') {
|
732
|
+
return null;
|
733
|
+
}
|
734
|
+
// Check if this is a database connection error that we should retry
|
735
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
736
|
+
error.message?.includes('Cannot reach database server') ||
|
737
|
+
error.message?.includes('Connection timed out') ||
|
738
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
739
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
740
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
741
|
+
retryCount++;
|
742
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
743
|
+
console.warn("Database connection error, retrying...");
|
744
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
745
|
+
continue;
|
746
|
+
}
|
747
|
+
// Log the error and rethrow
|
748
|
+
console.error("Database error occurred:", error);
|
480
749
|
throw error;
|
481
750
|
}
|
482
751
|
}
|
752
|
+
// If we exhausted retries, throw the last error
|
753
|
+
throw lastError;
|
483
754
|
}
|
484
755
|
};
|
485
756
|
//# sourceMappingURL=EconomicEvent.js.map
|