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.
- package/Account.cjs +2670 -2264
- package/Account.d.ts +19 -2
- package/Action.cjs +1195 -839
- package/Action.d.ts +19 -2
- package/Alert.cjs +2651 -2347
- package/Alert.d.ts +19 -2
- package/Allocation.cjs +2631 -2304
- package/Allocation.d.ts +19 -2
- package/AlpacaAccount.cjs +2654 -2104
- package/AlpacaAccount.d.ts +19 -2
- package/Asset.cjs +2611 -1544
- package/Asset.d.ts +19 -2
- package/Authenticator.cjs +2603 -2290
- package/Authenticator.d.ts +19 -2
- package/Customer.cjs +2506 -2220
- package/Customer.d.ts +19 -2
- package/EconomicEvent.cjs +708 -367
- package/EconomicEvent.d.ts +19 -2
- package/MarketSentiment.cjs +691 -340
- package/MarketSentiment.d.ts +19 -2
- package/NewsArticle.cjs +2114 -1655
- package/NewsArticle.d.ts +19 -2
- package/NewsArticleAssetSentiment.cjs +1873 -1564
- package/NewsArticleAssetSentiment.d.ts +19 -2
- package/ScheduledOptionOrder.cjs +607 -316
- package/ScheduledOptionOrder.d.ts +19 -2
- package/Session.cjs +2592 -2294
- package/Session.d.ts +19 -2
- package/Trade.cjs +1261 -795
- package/Trade.d.ts +19 -2
- package/User.cjs +2432 -2013
- package/User.d.ts +19 -2
- package/VerificationToken.cjs +637 -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 +2661 -2262
- 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 +1186 -837
- 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 +2642 -2345
- 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 +2622 -2302
- 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 +2645 -2102
- 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 +2602 -1542
- 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 +2594 -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 +2497 -2218
- 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 +699 -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 +682 -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 +2105 -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 +1864 -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 +598 -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 +2583 -2292
- 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 +1252 -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 +2423 -2011
- 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 +628 -326
- package/esm/generated/typegraphql-prisma/enhance.js.map +1 -1
- package/esm/generated/typegraphql-prisma/enhance.mjs +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.mjs +7 -7
- 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/generated/typegraphql-prisma/enhance.cjs +1 -1
- package/generated/typegraphql-prisma/enhance.js.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.cjs +6 -6
- package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
- package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
- 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,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
|
-
|
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 ? 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
|
-
|
173
|
-
|
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
|
-
|
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;
|
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
|
-
|
234
|
-
|
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
|
-
|
238
|
-
|
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
|
-
|
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;
|
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
|
-
|
302
|
-
|
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
|
-
|
306
|
-
|
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
|
-
*
|
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
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
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
|
-
|
344
|
-
|
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
|
-
|
348
|
-
|
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
|
-
*
|
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
|
-
|
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
|
-
|
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
|
-
|
392
|
-
|
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
|
-
|
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;
|
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
|
-
|
427
|
-
|
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
|
-
|
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;
|
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
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
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
|
-
|
479
|
-
|
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
|