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