adaptic-backend 1.0.340 → 1.0.341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Account.cjs +2543 -2265
- package/Account.d.ts +19 -2
- package/Action.cjs +1116 -838
- package/Action.d.ts +19 -2
- package/Alert.cjs +2626 -2348
- package/Alert.d.ts +19 -2
- package/Allocation.cjs +2578 -2300
- package/Allocation.d.ts +19 -2
- package/AlpacaAccount.cjs +2383 -2105
- package/AlpacaAccount.d.ts +19 -2
- package/Asset.cjs +1813 -1535
- package/Asset.d.ts +19 -2
- package/Authenticator.cjs +2568 -2290
- package/Authenticator.d.ts +19 -2
- package/Customer.cjs +2495 -2217
- package/Customer.d.ts +19 -2
- package/EconomicEvent.cjs +645 -367
- package/EconomicEvent.d.ts +19 -2
- package/MarketSentiment.cjs +618 -340
- package/MarketSentiment.d.ts +19 -2
- package/NewsArticle.cjs +1933 -1655
- package/NewsArticle.d.ts +19 -2
- package/NewsArticleAssetSentiment.cjs +1842 -1564
- package/NewsArticleAssetSentiment.d.ts +19 -2
- package/ScheduledOptionOrder.cjs +594 -316
- package/ScheduledOptionOrder.d.ts +19 -2
- package/Session.cjs +2570 -2292
- package/Session.d.ts +19 -2
- package/Trade.cjs +1073 -795
- package/Trade.d.ts +19 -2
- package/User.cjs +2288 -2010
- package/User.d.ts +19 -2
- package/VerificationToken.cjs +606 -328
- package/VerificationToken.d.ts +19 -2
- package/esm/Account.d.ts +19 -2
- package/esm/Account.d.ts.map +1 -1
- package/esm/Account.js.map +1 -1
- package/esm/Account.mjs +2534 -2263
- package/esm/Action.d.ts +19 -2
- package/esm/Action.d.ts.map +1 -1
- package/esm/Action.js.map +1 -1
- package/esm/Action.mjs +1107 -836
- package/esm/Alert.d.ts +19 -2
- package/esm/Alert.d.ts.map +1 -1
- package/esm/Alert.js.map +1 -1
- package/esm/Alert.mjs +2617 -2346
- package/esm/Allocation.d.ts +19 -2
- package/esm/Allocation.d.ts.map +1 -1
- package/esm/Allocation.js.map +1 -1
- package/esm/Allocation.mjs +2569 -2298
- package/esm/AlpacaAccount.d.ts +19 -2
- package/esm/AlpacaAccount.d.ts.map +1 -1
- package/esm/AlpacaAccount.js.map +1 -1
- package/esm/AlpacaAccount.mjs +2374 -2103
- package/esm/Asset.d.ts +19 -2
- package/esm/Asset.d.ts.map +1 -1
- package/esm/Asset.js.map +1 -1
- package/esm/Asset.mjs +1804 -1533
- package/esm/Authenticator.d.ts +19 -2
- package/esm/Authenticator.d.ts.map +1 -1
- package/esm/Authenticator.js.map +1 -1
- package/esm/Authenticator.mjs +2559 -2288
- package/esm/Customer.d.ts +19 -2
- package/esm/Customer.d.ts.map +1 -1
- package/esm/Customer.js.map +1 -1
- package/esm/Customer.mjs +2486 -2215
- package/esm/EconomicEvent.d.ts +19 -2
- package/esm/EconomicEvent.d.ts.map +1 -1
- package/esm/EconomicEvent.js.map +1 -1
- package/esm/EconomicEvent.mjs +636 -365
- package/esm/MarketSentiment.d.ts +19 -2
- package/esm/MarketSentiment.d.ts.map +1 -1
- package/esm/MarketSentiment.js.map +1 -1
- package/esm/MarketSentiment.mjs +609 -338
- package/esm/NewsArticle.d.ts +19 -2
- package/esm/NewsArticle.d.ts.map +1 -1
- package/esm/NewsArticle.js.map +1 -1
- package/esm/NewsArticle.mjs +1924 -1653
- package/esm/NewsArticleAssetSentiment.d.ts +19 -2
- package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
- package/esm/NewsArticleAssetSentiment.js.map +1 -1
- package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
- package/esm/ScheduledOptionOrder.d.ts +19 -2
- package/esm/ScheduledOptionOrder.d.ts.map +1 -1
- package/esm/ScheduledOptionOrder.js.map +1 -1
- package/esm/ScheduledOptionOrder.mjs +585 -314
- package/esm/Session.d.ts +19 -2
- package/esm/Session.d.ts.map +1 -1
- package/esm/Session.js.map +1 -1
- package/esm/Session.mjs +2561 -2290
- package/esm/Trade.d.ts +19 -2
- package/esm/Trade.d.ts.map +1 -1
- package/esm/Trade.js.map +1 -1
- package/esm/Trade.mjs +1064 -793
- package/esm/User.d.ts +19 -2
- package/esm/User.d.ts.map +1 -1
- package/esm/User.js.map +1 -1
- package/esm/User.mjs +2279 -2008
- package/esm/VerificationToken.d.ts +19 -2
- package/esm/VerificationToken.d.ts.map +1 -1
- package/esm/VerificationToken.js.map +1 -1
- package/esm/VerificationToken.mjs +597 -326
- package/esm/prismaClient.d.ts +4 -5
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +13 -11
- package/package.json +1 -1
- package/prismaClient.cjs +13 -11
- package/prismaClient.d.ts +4 -5
- package/server.cjs +37 -5
package/esm/MarketSentiment.mjs
CHANGED
@@ -20,438 +20,709 @@ 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
|
+
},
|
204
|
+
data: {
|
205
|
+
id: props.id !== undefined ? {
|
206
|
+
set: props.id
|
207
|
+
} : undefined,
|
208
|
+
sentiment: props.sentiment !== undefined ? {
|
209
|
+
set: props.sentiment
|
210
|
+
} : undefined,
|
211
|
+
description: props.description !== undefined ? {
|
212
|
+
set: props.description
|
213
|
+
} : undefined,
|
214
|
+
longDescription: props.longDescription !== undefined ? {
|
215
|
+
set: props.longDescription
|
216
|
+
} : undefined,
|
217
|
+
createdAt: props.createdAt !== undefined ? {
|
218
|
+
set: props.createdAt
|
219
|
+
} : undefined,
|
220
|
+
updatedAt: props.updatedAt !== undefined ? {
|
221
|
+
set: props.updatedAt
|
222
|
+
} : undefined,
|
223
|
+
},
|
224
|
+
};
|
225
|
+
const filteredVariables = removeUndefinedProps(variables);
|
226
|
+
const response = await client.mutate({
|
227
|
+
mutation: UPDATE_ONE_MARKETSENTIMENT,
|
228
|
+
variables: filteredVariables,
|
229
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
230
|
+
fetchPolicy: 'no-cache'
|
231
|
+
});
|
232
|
+
if (response.errors && response.errors.length > 0)
|
233
|
+
throw new Error(response.errors[0].message);
|
234
|
+
if (response && response.data && response.data.updateOneMarketSentiment) {
|
235
|
+
return response.data.updateOneMarketSentiment;
|
236
|
+
}
|
237
|
+
else {
|
238
|
+
return null;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
catch (error) {
|
242
|
+
lastError = error;
|
243
|
+
// Check if this is a database connection error that we should retry
|
244
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
245
|
+
error.message?.includes('Cannot reach database server') ||
|
246
|
+
error.message?.includes('Connection timed out') ||
|
247
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
248
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
249
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
250
|
+
retryCount++;
|
251
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
252
|
+
console.warn("Database connection error, retrying...");
|
253
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
254
|
+
continue;
|
255
|
+
}
|
256
|
+
// Log the error and rethrow
|
257
|
+
console.error("Database error occurred:", error);
|
258
|
+
throw error;
|
161
259
|
}
|
162
260
|
}
|
163
|
-
|
164
|
-
|
165
|
-
throw error;
|
166
|
-
}
|
261
|
+
// If we exhausted retries, throw the last error
|
262
|
+
throw lastError;
|
167
263
|
},
|
168
264
|
/**
|
169
265
|
* Upsert a single MarketSentiment record.
|
266
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
170
267
|
* @param props - Properties to update.
|
171
268
|
* @param globalClient - Apollo Client instance.
|
172
269
|
* @returns The updated MarketSentiment or null.
|
173
270
|
*/
|
174
271
|
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;
|
272
|
+
// Maximum number of retries for database connection issues
|
273
|
+
const MAX_RETRIES = 3;
|
274
|
+
let retryCount = 0;
|
275
|
+
let lastError = null;
|
276
|
+
// Retry loop to handle potential database connection issues
|
277
|
+
while (retryCount < MAX_RETRIES) {
|
278
|
+
try {
|
279
|
+
const [modules, client] = await Promise.all([
|
280
|
+
getApolloModules(),
|
281
|
+
globalClient
|
282
|
+
? Promise.resolve(globalClient)
|
283
|
+
: importedClient
|
284
|
+
]);
|
285
|
+
const { gql, ApolloError } = modules;
|
286
|
+
const UPSERT_ONE_MARKETSENTIMENT = gql `
|
287
|
+
mutation upsertOneMarketSentiment($where: MarketSentimentWhereUniqueInput!, $create: MarketSentimentCreateInput!, $update: MarketSentimentUpdateInput!) {
|
288
|
+
upsertOneMarketSentiment(where: $where, create: $create, update: $update) {
|
289
|
+
${selectionSet}
|
216
290
|
}
|
217
|
-
|
218
|
-
|
291
|
+
}`;
|
292
|
+
const variables = {
|
293
|
+
where: {
|
294
|
+
id: props.id !== undefined ? props.id : undefined,
|
295
|
+
},
|
296
|
+
create: {
|
297
|
+
sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
|
298
|
+
description: props.description !== undefined ? props.description : undefined,
|
299
|
+
longDescription: props.longDescription !== undefined ? props.longDescription : undefined,
|
300
|
+
},
|
301
|
+
update: {
|
302
|
+
sentiment: props.sentiment !== undefined ? {
|
303
|
+
set: props.sentiment
|
304
|
+
} : undefined,
|
305
|
+
description: props.description !== undefined ? {
|
306
|
+
set: props.description
|
307
|
+
} : undefined,
|
308
|
+
longDescription: props.longDescription !== undefined ? {
|
309
|
+
set: props.longDescription
|
310
|
+
} : undefined,
|
311
|
+
},
|
312
|
+
};
|
313
|
+
const filteredVariables = removeUndefinedProps(variables);
|
314
|
+
const response = await client.mutate({
|
315
|
+
mutation: UPSERT_ONE_MARKETSENTIMENT,
|
316
|
+
variables: filteredVariables,
|
317
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
318
|
+
fetchPolicy: 'no-cache'
|
319
|
+
});
|
320
|
+
if (response.errors && response.errors.length > 0)
|
321
|
+
throw new Error(response.errors[0].message);
|
322
|
+
if (response && response.data && response.data.upsertOneMarketSentiment) {
|
323
|
+
return response.data.upsertOneMarketSentiment;
|
324
|
+
}
|
325
|
+
else {
|
326
|
+
return null;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
catch (error) {
|
330
|
+
lastError = error;
|
331
|
+
// Check if this is a database connection error that we should retry
|
332
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
333
|
+
error.message?.includes('Cannot reach database server') ||
|
334
|
+
error.message?.includes('Connection timed out') ||
|
335
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
336
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
337
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
338
|
+
retryCount++;
|
339
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
340
|
+
console.warn("Database connection error, retrying...");
|
341
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
342
|
+
continue;
|
343
|
+
}
|
344
|
+
// Log the error and rethrow
|
345
|
+
console.error("Database error occurred:", error);
|
346
|
+
throw error;
|
219
347
|
}
|
220
348
|
}
|
221
|
-
|
222
|
-
|
223
|
-
throw error;
|
224
|
-
}
|
349
|
+
// If we exhausted retries, throw the last error
|
350
|
+
throw lastError;
|
225
351
|
},
|
226
352
|
/**
|
227
353
|
* Update multiple MarketSentiment records.
|
354
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
228
355
|
* @param props - Array of MarketSentiment objects for the updated records.
|
229
356
|
* @param globalClient - Apollo Client instance.
|
230
357
|
* @returns The count of created records or null.
|
231
358
|
*/
|
232
359
|
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;
|
360
|
+
// Maximum number of retries for database connection issues
|
361
|
+
const MAX_RETRIES = 3;
|
362
|
+
let retryCount = 0;
|
363
|
+
let lastError = null;
|
364
|
+
// Retry loop to handle potential database connection issues
|
365
|
+
while (retryCount < MAX_RETRIES) {
|
366
|
+
try {
|
367
|
+
const [modules, client] = await Promise.all([
|
368
|
+
getApolloModules(),
|
369
|
+
globalClient
|
370
|
+
? Promise.resolve(globalClient)
|
371
|
+
: importedClient
|
372
|
+
]);
|
373
|
+
const { gql, ApolloError } = modules;
|
374
|
+
const UPDATE_MANY_MARKETSENTIMENT = gql `
|
375
|
+
mutation updateManyMarketSentiment($data: [MarketSentimentCreateManyInput!]!) {
|
376
|
+
updateManyMarketSentiment(data: $data) {
|
377
|
+
count
|
278
378
|
}
|
279
|
-
|
280
|
-
|
379
|
+
}`;
|
380
|
+
const variables = props.map(prop => ({
|
381
|
+
where: {
|
382
|
+
id: prop.id !== undefined ? prop.id : undefined,
|
383
|
+
},
|
384
|
+
data: {
|
385
|
+
id: prop.id !== undefined ? {
|
386
|
+
set: prop.id
|
387
|
+
} : undefined,
|
388
|
+
sentiment: prop.sentiment !== undefined ? {
|
389
|
+
set: prop.sentiment
|
390
|
+
} : undefined,
|
391
|
+
description: prop.description !== undefined ? {
|
392
|
+
set: prop.description
|
393
|
+
} : undefined,
|
394
|
+
longDescription: prop.longDescription !== undefined ? {
|
395
|
+
set: prop.longDescription
|
396
|
+
} : undefined,
|
397
|
+
createdAt: prop.createdAt !== undefined ? {
|
398
|
+
set: prop.createdAt
|
399
|
+
} : undefined,
|
400
|
+
updatedAt: prop.updatedAt !== undefined ? {
|
401
|
+
set: prop.updatedAt
|
402
|
+
} : undefined,
|
403
|
+
},
|
404
|
+
}));
|
405
|
+
const filteredVariables = removeUndefinedProps(variables);
|
406
|
+
const response = await client.mutate({
|
407
|
+
mutation: UPDATE_MANY_MARKETSENTIMENT,
|
408
|
+
variables: filteredVariables,
|
409
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
410
|
+
fetchPolicy: 'no-cache'
|
411
|
+
});
|
412
|
+
if (response.errors && response.errors.length > 0)
|
413
|
+
throw new Error(response.errors[0].message);
|
414
|
+
if (response && response.data && response.data.updateManyMarketSentiment) {
|
415
|
+
return response.data.updateManyMarketSentiment;
|
416
|
+
}
|
417
|
+
else {
|
418
|
+
return null;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
catch (error) {
|
422
|
+
lastError = error;
|
423
|
+
// Check if this is a database connection error that we should retry
|
424
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
425
|
+
error.message?.includes('Cannot reach database server') ||
|
426
|
+
error.message?.includes('Connection timed out') ||
|
427
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
428
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
429
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
430
|
+
retryCount++;
|
431
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
432
|
+
console.warn("Database connection error, retrying...");
|
433
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
434
|
+
continue;
|
435
|
+
}
|
436
|
+
// Log the error and rethrow
|
437
|
+
console.error("Database error occurred:", error);
|
438
|
+
throw error;
|
281
439
|
}
|
282
440
|
}
|
283
|
-
|
284
|
-
|
285
|
-
throw error;
|
286
|
-
}
|
441
|
+
// If we exhausted retries, throw the last error
|
442
|
+
throw lastError;
|
287
443
|
},
|
288
444
|
/**
|
289
445
|
* Delete a single MarketSentiment record.
|
290
|
-
*
|
446
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
447
|
+
* @param props - Properties to identify the record to delete.
|
291
448
|
* @param globalClient - Apollo Client instance.
|
292
449
|
* @returns The deleted MarketSentiment or null.
|
293
450
|
*/
|
294
451
|
async delete(props, globalClient) {
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
452
|
+
// Maximum number of retries for database connection issues
|
453
|
+
const MAX_RETRIES = 3;
|
454
|
+
let retryCount = 0;
|
455
|
+
let lastError = null;
|
456
|
+
// Retry loop to handle potential database connection issues
|
457
|
+
while (retryCount < MAX_RETRIES) {
|
458
|
+
try {
|
459
|
+
const [modules, client] = await Promise.all([
|
460
|
+
getApolloModules(),
|
461
|
+
globalClient
|
462
|
+
? Promise.resolve(globalClient)
|
463
|
+
: importedClient
|
464
|
+
]);
|
465
|
+
const { gql, ApolloError } = modules;
|
466
|
+
const DELETE_ONE_MARKETSENTIMENT = gql `
|
467
|
+
mutation deleteOneMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
|
468
|
+
deleteOneMarketSentiment(where: $where) {
|
469
|
+
id
|
311
470
|
}
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
471
|
+
}`;
|
472
|
+
const variables = {
|
473
|
+
where: {
|
474
|
+
id: props.id ? props.id : undefined,
|
475
|
+
}
|
476
|
+
};
|
477
|
+
const filteredVariables = removeUndefinedProps(variables);
|
478
|
+
const response = await client.mutate({
|
479
|
+
mutation: DELETE_ONE_MARKETSENTIMENT,
|
480
|
+
variables: filteredVariables,
|
481
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
482
|
+
fetchPolicy: 'no-cache'
|
483
|
+
});
|
484
|
+
if (response.errors && response.errors.length > 0)
|
485
|
+
throw new Error(response.errors[0].message);
|
486
|
+
if (response && response.data && response.data.deleteOneMarketSentiment) {
|
487
|
+
return response.data.deleteOneMarketSentiment;
|
488
|
+
}
|
489
|
+
else {
|
490
|
+
return null;
|
491
|
+
}
|
320
492
|
}
|
321
|
-
|
322
|
-
|
493
|
+
catch (error) {
|
494
|
+
lastError = error;
|
495
|
+
// Check if this is a database connection error that we should retry
|
496
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
497
|
+
error.message?.includes('Cannot reach database server') ||
|
498
|
+
error.message?.includes('Connection timed out') ||
|
499
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
500
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
501
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
502
|
+
retryCount++;
|
503
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
504
|
+
console.warn("Database connection error, retrying...");
|
505
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
506
|
+
continue;
|
507
|
+
}
|
508
|
+
// Log the error and rethrow
|
509
|
+
console.error("Database error occurred:", error);
|
510
|
+
throw error;
|
323
511
|
}
|
324
512
|
}
|
325
|
-
|
326
|
-
|
327
|
-
throw error;
|
328
|
-
}
|
513
|
+
// If we exhausted retries, throw the last error
|
514
|
+
throw lastError;
|
329
515
|
},
|
330
516
|
/**
|
331
517
|
* Retrieve a single MarketSentiment record by ID.
|
332
|
-
*
|
518
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
519
|
+
* @param props - Properties to identify the record.
|
333
520
|
* @param globalClient - Apollo Client instance.
|
521
|
+
* @param whereInput - Optional custom where input.
|
334
522
|
* @returns The retrieved MarketSentiment or null.
|
335
523
|
*/
|
336
524
|
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
|
-
|
525
|
+
// Maximum number of retries for database connection issues
|
526
|
+
const MAX_RETRIES = 3;
|
527
|
+
let retryCount = 0;
|
528
|
+
let lastError = null;
|
529
|
+
// Retry loop to handle potential database connection issues
|
530
|
+
while (retryCount < MAX_RETRIES) {
|
531
|
+
try {
|
532
|
+
const [modules, client] = await Promise.all([
|
533
|
+
getApolloModules(),
|
534
|
+
globalClient
|
535
|
+
? Promise.resolve(globalClient)
|
536
|
+
: importedClient
|
537
|
+
]);
|
538
|
+
const { gql, ApolloError } = modules;
|
539
|
+
const GET_MARKETSENTIMENT = gql `
|
540
|
+
query getMarketSentiment($where: MarketSentimentWhereUniqueInput!) {
|
541
|
+
getMarketSentiment(where: $where) {
|
542
|
+
${selectionSet}
|
543
|
+
}
|
544
|
+
}`;
|
545
|
+
const variables = {
|
546
|
+
where: whereInput ? whereInput : {
|
547
|
+
id: props.id !== undefined ? props.id : undefined,
|
548
|
+
},
|
549
|
+
};
|
550
|
+
const filteredVariables = removeUndefinedProps(variables);
|
551
|
+
const response = await client.query({
|
552
|
+
query: GET_MARKETSENTIMENT,
|
553
|
+
variables: filteredVariables,
|
554
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
555
|
+
});
|
556
|
+
if (response.errors && response.errors.length > 0)
|
557
|
+
throw new Error(response.errors[0].message);
|
558
|
+
return response.data?.getMarketSentiment ?? null;
|
365
559
|
}
|
366
|
-
|
367
|
-
|
560
|
+
catch (error) {
|
561
|
+
lastError = error;
|
562
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
563
|
+
if (error.message === 'No MarketSentiment found') {
|
564
|
+
return null;
|
565
|
+
}
|
566
|
+
// Check if this is a database connection error that we should retry
|
567
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
568
|
+
error.message?.includes('Cannot reach database server') ||
|
569
|
+
error.message?.includes('Connection timed out') ||
|
570
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
571
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
572
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
573
|
+
retryCount++;
|
574
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
575
|
+
console.warn("Database connection error, retrying...");
|
576
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
577
|
+
continue;
|
578
|
+
}
|
579
|
+
// Log the error and rethrow
|
580
|
+
console.error("Database error occurred:", error);
|
368
581
|
throw error;
|
369
582
|
}
|
370
583
|
}
|
584
|
+
// If we exhausted retries, throw the last error
|
585
|
+
throw lastError;
|
371
586
|
},
|
372
587
|
/**
|
373
588
|
* Retrieve all MarketSentiments records.
|
589
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
374
590
|
* @param globalClient - Apollo Client instance.
|
375
591
|
* @returns An array of MarketSentiment records or null.
|
376
592
|
*/
|
377
593
|
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;
|
594
|
+
// Maximum number of retries for database connection issues
|
595
|
+
const MAX_RETRIES = 3;
|
596
|
+
let retryCount = 0;
|
597
|
+
let lastError = null;
|
598
|
+
// Retry loop to handle potential database connection issues
|
599
|
+
while (retryCount < MAX_RETRIES) {
|
600
|
+
try {
|
601
|
+
const [modules, client] = await Promise.all([
|
602
|
+
getApolloModules(),
|
603
|
+
globalClient
|
604
|
+
? Promise.resolve(globalClient)
|
605
|
+
: importedClient
|
606
|
+
]);
|
607
|
+
const { gql, ApolloError } = modules;
|
608
|
+
const GET_ALL_MARKETSENTIMENT = gql `
|
609
|
+
query getAllMarketSentiment {
|
610
|
+
marketSentiments {
|
611
|
+
${selectionSet}
|
400
612
|
}
|
401
|
-
|
402
|
-
|
613
|
+
}`;
|
614
|
+
const response = await client.query({
|
615
|
+
query: GET_ALL_MARKETSENTIMENT,
|
616
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
617
|
+
});
|
618
|
+
if (response.errors && response.errors.length > 0)
|
619
|
+
throw new Error(response.errors[0].message);
|
620
|
+
return response.data?.marketSentiments ?? null;
|
621
|
+
}
|
622
|
+
catch (error) {
|
623
|
+
lastError = error;
|
624
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
625
|
+
if (error.message === 'No MarketSentiment found') {
|
626
|
+
return null;
|
627
|
+
}
|
628
|
+
// Check if this is a database connection error that we should retry
|
629
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
630
|
+
error.message?.includes('Cannot reach database server') ||
|
631
|
+
error.message?.includes('Connection timed out') ||
|
632
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
633
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
634
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
635
|
+
retryCount++;
|
636
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
637
|
+
console.warn("Database connection error, retrying...");
|
638
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
639
|
+
continue;
|
640
|
+
}
|
641
|
+
// Log the error and rethrow
|
642
|
+
console.error("Database error occurred:", error);
|
403
643
|
throw error;
|
404
644
|
}
|
405
645
|
}
|
646
|
+
// If we exhausted retries, throw the last error
|
647
|
+
throw lastError;
|
406
648
|
},
|
407
649
|
/**
|
408
650
|
* Find multiple MarketSentiment records based on conditions.
|
651
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
409
652
|
* @param props - Conditions to find records.
|
410
653
|
* @param globalClient - Apollo Client instance.
|
654
|
+
* @param whereInput - Optional custom where input.
|
411
655
|
* @returns An array of found MarketSentiment records or null.
|
412
656
|
*/
|
413
657
|
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;
|
658
|
+
// Maximum number of retries for database connection issues
|
659
|
+
const MAX_RETRIES = 3;
|
660
|
+
let retryCount = 0;
|
661
|
+
let lastError = null;
|
662
|
+
// Retry loop to handle potential database connection issues
|
663
|
+
while (retryCount < MAX_RETRIES) {
|
664
|
+
try {
|
665
|
+
const [modules, client] = await Promise.all([
|
666
|
+
getApolloModules(),
|
667
|
+
globalClient
|
668
|
+
? Promise.resolve(globalClient)
|
669
|
+
: importedClient
|
670
|
+
]);
|
671
|
+
const { gql, ApolloError } = modules;
|
672
|
+
const FIND_MANY_MARKETSENTIMENT = gql `
|
673
|
+
query findManyMarketSentiment($where: MarketSentimentWhereInput!) {
|
674
|
+
marketSentiments(where: $where) {
|
675
|
+
${selectionSet}
|
441
676
|
}
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
677
|
+
}`;
|
678
|
+
const variables = {
|
679
|
+
where: whereInput ? whereInput : {
|
680
|
+
id: props.id !== undefined ? {
|
681
|
+
equals: props.id
|
682
|
+
} : undefined,
|
683
|
+
},
|
684
|
+
};
|
685
|
+
const filteredVariables = removeUndefinedProps(variables);
|
686
|
+
const response = await client.query({
|
687
|
+
query: FIND_MANY_MARKETSENTIMENT,
|
688
|
+
variables: filteredVariables,
|
689
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
690
|
+
});
|
691
|
+
if (response.errors && response.errors.length > 0)
|
692
|
+
throw new Error(response.errors[0].message);
|
693
|
+
if (response && response.data && response.data.marketsentiments) {
|
694
|
+
return response.data.marketSentiments;
|
695
|
+
}
|
696
|
+
else {
|
697
|
+
return [];
|
698
|
+
}
|
449
699
|
}
|
450
|
-
|
451
|
-
|
700
|
+
catch (error) {
|
701
|
+
lastError = error;
|
702
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
703
|
+
if (error.message === 'No MarketSentiment found') {
|
704
|
+
return null;
|
705
|
+
}
|
706
|
+
// Check if this is a database connection error that we should retry
|
707
|
+
const isConnectionError = error.message?.includes('Server has closed the connection') ||
|
708
|
+
error.message?.includes('Cannot reach database server') ||
|
709
|
+
error.message?.includes('Connection timed out') ||
|
710
|
+
error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
|
711
|
+
(error.networkError && error.networkError.message?.includes('Failed to fetch'));
|
712
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
713
|
+
retryCount++;
|
714
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
715
|
+
console.warn("Database connection error, retrying...");
|
716
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
717
|
+
continue;
|
718
|
+
}
|
719
|
+
// Log the error and rethrow
|
720
|
+
console.error("Database error occurred:", error);
|
452
721
|
throw error;
|
453
722
|
}
|
454
723
|
}
|
724
|
+
// If we exhausted retries, throw the last error
|
725
|
+
throw lastError;
|
455
726
|
}
|
456
727
|
};
|
457
728
|
//# sourceMappingURL=MarketSentiment.js.map
|