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