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.
Files changed (110) hide show
  1. package/Account.cjs +2543 -2265
  2. package/Account.d.ts +19 -2
  3. package/Action.cjs +1116 -838
  4. package/Action.d.ts +19 -2
  5. package/Alert.cjs +2626 -2348
  6. package/Alert.d.ts +19 -2
  7. package/Allocation.cjs +2578 -2300
  8. package/Allocation.d.ts +19 -2
  9. package/AlpacaAccount.cjs +2383 -2105
  10. package/AlpacaAccount.d.ts +19 -2
  11. package/Asset.cjs +1813 -1535
  12. package/Asset.d.ts +19 -2
  13. package/Authenticator.cjs +2568 -2290
  14. package/Authenticator.d.ts +19 -2
  15. package/Customer.cjs +2495 -2217
  16. package/Customer.d.ts +19 -2
  17. package/EconomicEvent.cjs +645 -367
  18. package/EconomicEvent.d.ts +19 -2
  19. package/MarketSentiment.cjs +618 -340
  20. package/MarketSentiment.d.ts +19 -2
  21. package/NewsArticle.cjs +1933 -1655
  22. package/NewsArticle.d.ts +19 -2
  23. package/NewsArticleAssetSentiment.cjs +1842 -1564
  24. package/NewsArticleAssetSentiment.d.ts +19 -2
  25. package/ScheduledOptionOrder.cjs +594 -316
  26. package/ScheduledOptionOrder.d.ts +19 -2
  27. package/Session.cjs +2570 -2292
  28. package/Session.d.ts +19 -2
  29. package/Trade.cjs +1073 -795
  30. package/Trade.d.ts +19 -2
  31. package/User.cjs +2288 -2010
  32. package/User.d.ts +19 -2
  33. package/VerificationToken.cjs +606 -328
  34. package/VerificationToken.d.ts +19 -2
  35. package/esm/Account.d.ts +19 -2
  36. package/esm/Account.d.ts.map +1 -1
  37. package/esm/Account.js.map +1 -1
  38. package/esm/Account.mjs +2534 -2263
  39. package/esm/Action.d.ts +19 -2
  40. package/esm/Action.d.ts.map +1 -1
  41. package/esm/Action.js.map +1 -1
  42. package/esm/Action.mjs +1107 -836
  43. package/esm/Alert.d.ts +19 -2
  44. package/esm/Alert.d.ts.map +1 -1
  45. package/esm/Alert.js.map +1 -1
  46. package/esm/Alert.mjs +2617 -2346
  47. package/esm/Allocation.d.ts +19 -2
  48. package/esm/Allocation.d.ts.map +1 -1
  49. package/esm/Allocation.js.map +1 -1
  50. package/esm/Allocation.mjs +2569 -2298
  51. package/esm/AlpacaAccount.d.ts +19 -2
  52. package/esm/AlpacaAccount.d.ts.map +1 -1
  53. package/esm/AlpacaAccount.js.map +1 -1
  54. package/esm/AlpacaAccount.mjs +2374 -2103
  55. package/esm/Asset.d.ts +19 -2
  56. package/esm/Asset.d.ts.map +1 -1
  57. package/esm/Asset.js.map +1 -1
  58. package/esm/Asset.mjs +1804 -1533
  59. package/esm/Authenticator.d.ts +19 -2
  60. package/esm/Authenticator.d.ts.map +1 -1
  61. package/esm/Authenticator.js.map +1 -1
  62. package/esm/Authenticator.mjs +2559 -2288
  63. package/esm/Customer.d.ts +19 -2
  64. package/esm/Customer.d.ts.map +1 -1
  65. package/esm/Customer.js.map +1 -1
  66. package/esm/Customer.mjs +2486 -2215
  67. package/esm/EconomicEvent.d.ts +19 -2
  68. package/esm/EconomicEvent.d.ts.map +1 -1
  69. package/esm/EconomicEvent.js.map +1 -1
  70. package/esm/EconomicEvent.mjs +636 -365
  71. package/esm/MarketSentiment.d.ts +19 -2
  72. package/esm/MarketSentiment.d.ts.map +1 -1
  73. package/esm/MarketSentiment.js.map +1 -1
  74. package/esm/MarketSentiment.mjs +609 -338
  75. package/esm/NewsArticle.d.ts +19 -2
  76. package/esm/NewsArticle.d.ts.map +1 -1
  77. package/esm/NewsArticle.js.map +1 -1
  78. package/esm/NewsArticle.mjs +1924 -1653
  79. package/esm/NewsArticleAssetSentiment.d.ts +19 -2
  80. package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
  81. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  82. package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
  83. package/esm/ScheduledOptionOrder.d.ts +19 -2
  84. package/esm/ScheduledOptionOrder.d.ts.map +1 -1
  85. package/esm/ScheduledOptionOrder.js.map +1 -1
  86. package/esm/ScheduledOptionOrder.mjs +585 -314
  87. package/esm/Session.d.ts +19 -2
  88. package/esm/Session.d.ts.map +1 -1
  89. package/esm/Session.js.map +1 -1
  90. package/esm/Session.mjs +2561 -2290
  91. package/esm/Trade.d.ts +19 -2
  92. package/esm/Trade.d.ts.map +1 -1
  93. package/esm/Trade.js.map +1 -1
  94. package/esm/Trade.mjs +1064 -793
  95. package/esm/User.d.ts +19 -2
  96. package/esm/User.d.ts.map +1 -1
  97. package/esm/User.js.map +1 -1
  98. package/esm/User.mjs +2279 -2008
  99. package/esm/VerificationToken.d.ts +19 -2
  100. package/esm/VerificationToken.d.ts.map +1 -1
  101. package/esm/VerificationToken.js.map +1 -1
  102. package/esm/VerificationToken.mjs +597 -326
  103. package/esm/prismaClient.d.ts +4 -5
  104. package/esm/prismaClient.d.ts.map +1 -1
  105. package/esm/prismaClient.js.map +1 -1
  106. package/esm/prismaClient.mjs +13 -11
  107. package/package.json +1 -1
  108. package/prismaClient.cjs +13 -11
  109. package/prismaClient.d.ts +4 -5
  110. package/server.cjs +37 -5
package/NewsArticle.cjs CHANGED
@@ -102,70 +102,583 @@ exports.NewsArticle = {
102
102
  * @param client - Apollo Client instance.
103
103
  * @returns The created NewsArticle or null.
104
104
  */
105
+ /**
106
+ * Create a new NewsArticle record.
107
+ * Enhanced with connection resilience against Prisma connection errors.
108
+ * @param props - Properties for the new record.
109
+ * @param globalClient - Apollo Client instance.
110
+ * @returns The created NewsArticle or null.
111
+ */
105
112
  async create(props, globalClient) {
106
- const [modules, client] = await Promise.all([
107
- (0, client_1.getApolloModules)(),
108
- globalClient
109
- ? Promise.resolve(globalClient)
110
- : client_1.client
111
- ]);
112
- const { gql, ApolloError } = modules;
113
- const CREATE_ONE_NEWSARTICLE = gql `
114
- mutation createOneNewsArticle($data: NewsArticleCreateInput!) {
115
- createOneNewsArticle(data: $data) {
116
- ${selectionSet}
117
- }
113
+ var _a, _b, _c, _d, _e;
114
+ // Maximum number of retries for database connection issues
115
+ const MAX_RETRIES = 3;
116
+ let retryCount = 0;
117
+ let lastError = null;
118
+ // Retry loop to handle potential database connection issues
119
+ while (retryCount < MAX_RETRIES) {
120
+ try {
121
+ const [modules, client] = await Promise.all([
122
+ (0, client_1.getApolloModules)(),
123
+ globalClient
124
+ ? Promise.resolve(globalClient)
125
+ : client_1.client
126
+ ]);
127
+ const { gql, ApolloError } = modules;
128
+ const CREATE_ONE_NEWSARTICLE = gql `
129
+ mutation createOneNewsArticle($data: NewsArticleCreateInput!) {
130
+ createOneNewsArticle(data: $data) {
131
+ ${selectionSet}
132
+ }
133
+ }
134
+ `;
135
+ const variables = {
136
+ data: {
137
+ title: props.title !== undefined ? props.title : undefined,
138
+ content: props.content !== undefined ? props.content : undefined,
139
+ source: props.source !== undefined ? props.source : undefined,
140
+ sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
141
+ url: props.url !== undefined ? props.url : undefined,
142
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
143
+ authors: props.authors !== undefined ? {
144
+ set: props.authors
145
+ } : undefined,
146
+ summary: props.summary !== undefined ? props.summary : undefined,
147
+ bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
148
+ timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
149
+ category: props.category !== undefined ? props.category : undefined,
150
+ topics: props.topics !== undefined ? {
151
+ set: props.topics
152
+ } : undefined,
153
+ logo: props.logo !== undefined ? props.logo : undefined,
154
+ assets: props.assets ?
155
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
156
+ connect: props.assets.map((item) => ({
157
+ id: item.id
158
+ }))
159
+ }
160
+ : { connectOrCreate: props.assets.map((item) => ({
161
+ where: {
162
+ id: item.id !== undefined ? item.id : undefined,
163
+ url: item.url !== undefined ? item.url : undefined,
164
+ newsArticleId: item.newsArticleId !== undefined ? {
165
+ equals: item.newsArticleId
166
+ } : undefined,
167
+ },
168
+ create: {
169
+ url: item.url !== undefined ? item.url : undefined,
170
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
171
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
172
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
173
+ asset: item.asset ?
174
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
175
+ ? { connect: {
176
+ id: item.asset.id
177
+ }
178
+ }
179
+ : { connectOrCreate: {
180
+ where: {
181
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
182
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
183
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
184
+ },
185
+ create: {
186
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
187
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
188
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
189
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
190
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
191
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
192
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
193
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
194
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
195
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
196
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
197
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
198
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
199
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
200
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
201
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
202
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
203
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
204
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
205
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
206
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
207
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
208
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
209
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
210
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
211
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
212
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
213
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
214
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
215
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
216
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
217
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
218
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
219
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
220
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
221
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
222
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
223
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
224
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
225
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
226
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
227
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
228
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
229
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
230
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
231
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
232
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
233
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
234
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
235
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
236
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
237
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
238
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
239
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
240
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
241
+ },
242
+ }
243
+ } : undefined,
244
+ },
245
+ }))
246
+ } : undefined,
247
+ },
248
+ };
249
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
250
+ const response = await client.mutate({
251
+ mutation: CREATE_ONE_NEWSARTICLE,
252
+ variables: filteredVariables,
253
+ // Don't cache mutations, but ensure we're using the freshest context
254
+ fetchPolicy: 'no-cache'
255
+ });
256
+ if (response.errors && response.errors.length > 0)
257
+ throw new Error(response.errors[0].message);
258
+ if (response && response.data && response.data.createOneNewsArticle) {
259
+ return response.data.createOneNewsArticle;
260
+ }
261
+ else {
262
+ return null;
263
+ }
264
+ }
265
+ catch (error) {
266
+ lastError = error;
267
+ // Check if this is a database connection error that we should retry
268
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
269
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
270
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
271
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
272
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
273
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
274
+ retryCount++;
275
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
276
+ console.warn("Database connection error, retrying...");
277
+ await new Promise(resolve => setTimeout(resolve, delay));
278
+ continue;
279
+ }
280
+ // Log the error and rethrow
281
+ console.error("Database error occurred:", error);
282
+ throw error;
283
+ }
118
284
  }
119
- `;
120
- const variables = {
121
- data: {
122
- title: props.title !== undefined ? props.title : undefined,
123
- content: props.content !== undefined ? props.content : undefined,
124
- source: props.source !== undefined ? props.source : undefined,
125
- sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
126
- url: props.url !== undefined ? props.url : undefined,
127
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
128
- authors: props.authors !== undefined ? {
129
- set: props.authors
130
- } : undefined,
131
- summary: props.summary !== undefined ? props.summary : undefined,
132
- bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
133
- timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
134
- category: props.category !== undefined ? props.category : undefined,
135
- topics: props.topics !== undefined ? {
136
- set: props.topics
137
- } : undefined,
138
- logo: props.logo !== undefined ? props.logo : undefined,
139
- assets: props.assets ?
140
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
141
- connect: props.assets.map((item) => ({
142
- id: item.id
143
- }))
144
- }
145
- : { connectOrCreate: props.assets.map((item) => ({
146
- where: {
147
- id: item.id !== undefined ? item.id : undefined,
148
- url: item.url !== undefined ? item.url : undefined,
149
- newsArticleId: item.newsArticleId !== undefined ? {
150
- equals: item.newsArticleId
151
- } : undefined,
152
- },
153
- create: {
154
- url: item.url !== undefined ? item.url : undefined,
155
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
156
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
157
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
158
- asset: item.asset ?
159
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
160
- ? { connect: {
161
- id: item.asset.id
162
- }
163
- }
164
- : { connectOrCreate: {
285
+ // If we exhausted retries, throw the last error
286
+ throw lastError;
287
+ },
288
+ /**
289
+ * Create multiple NewsArticle records.
290
+ * Enhanced with connection resilience against Prisma connection errors.
291
+ * @param props - Array of NewsArticle objects for the new records.
292
+ * @param globalClient - Apollo Client instance.
293
+ * @returns The count of created records or null.
294
+ */
295
+ async createMany(props, globalClient) {
296
+ var _a, _b, _c, _d, _e;
297
+ // Maximum number of retries for database connection issues
298
+ const MAX_RETRIES = 3;
299
+ let retryCount = 0;
300
+ let lastError = null;
301
+ // Retry loop to handle potential database connection issues
302
+ while (retryCount < MAX_RETRIES) {
303
+ try {
304
+ const [modules, client] = await Promise.all([
305
+ (0, client_1.getApolloModules)(),
306
+ globalClient
307
+ ? Promise.resolve(globalClient)
308
+ : client_1.client
309
+ ]);
310
+ const { gql, ApolloError } = modules;
311
+ const CREATE_MANY_NEWSARTICLE = gql `
312
+ mutation createManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
313
+ createManyNewsArticle(data: $data) {
314
+ count
315
+ }
316
+ }`;
317
+ const variables = {
318
+ data: props.map(prop => ({
319
+ title: prop.title !== undefined ? prop.title : undefined,
320
+ content: prop.content !== undefined ? prop.content : undefined,
321
+ source: prop.source !== undefined ? prop.source : undefined,
322
+ sourceDomain: prop.sourceDomain !== undefined ? prop.sourceDomain : undefined,
323
+ url: prop.url !== undefined ? prop.url : undefined,
324
+ sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
325
+ authors: prop.authors !== undefined ? {
326
+ set: prop.authors
327
+ } : undefined,
328
+ summary: prop.summary !== undefined ? prop.summary : undefined,
329
+ bannerImage: prop.bannerImage !== undefined ? prop.bannerImage : undefined,
330
+ timePublished: prop.timePublished !== undefined ? prop.timePublished : undefined,
331
+ category: prop.category !== undefined ? prop.category : undefined,
332
+ topics: prop.topics !== undefined ? {
333
+ set: prop.topics
334
+ } : undefined,
335
+ logo: prop.logo !== undefined ? prop.logo : undefined,
336
+ })),
337
+ };
338
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
339
+ const response = await client.mutate({
340
+ mutation: CREATE_MANY_NEWSARTICLE,
341
+ variables: filteredVariables,
342
+ // Don't cache mutations, but ensure we're using the freshest context
343
+ fetchPolicy: 'no-cache'
344
+ });
345
+ if (response.errors && response.errors.length > 0)
346
+ throw new Error(response.errors[0].message);
347
+ if (response && response.data && response.data.createManyNewsArticle) {
348
+ return response.data.createManyNewsArticle;
349
+ }
350
+ else {
351
+ return null;
352
+ }
353
+ }
354
+ catch (error) {
355
+ lastError = error;
356
+ // Check if this is a database connection error that we should retry
357
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
358
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
359
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
360
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
361
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
362
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
363
+ retryCount++;
364
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
365
+ console.warn("Database connection error, retrying...");
366
+ await new Promise(resolve => setTimeout(resolve, delay));
367
+ continue;
368
+ }
369
+ // Log the error and rethrow
370
+ console.error("Database error occurred:", error);
371
+ throw error;
372
+ }
373
+ }
374
+ // If we exhausted retries, throw the last error
375
+ throw lastError;
376
+ },
377
+ /**
378
+ * Update a single NewsArticle record.
379
+ * Enhanced with connection resilience against Prisma connection errors.
380
+ * @param props - Properties to update.
381
+ * @param globalClient - Apollo Client instance.
382
+ * @returns The updated NewsArticle or null.
383
+ */
384
+ async update(props, globalClient) {
385
+ var _a, _b, _c, _d, _e;
386
+ // Maximum number of retries for database connection issues
387
+ const MAX_RETRIES = 3;
388
+ let retryCount = 0;
389
+ let lastError = null;
390
+ // Retry loop to handle potential database connection issues
391
+ while (retryCount < MAX_RETRIES) {
392
+ try {
393
+ const [modules, client] = await Promise.all([
394
+ (0, client_1.getApolloModules)(),
395
+ globalClient
396
+ ? Promise.resolve(globalClient)
397
+ : client_1.client
398
+ ]);
399
+ const { gql, ApolloError } = modules;
400
+ const UPDATE_ONE_NEWSARTICLE = gql `
401
+ mutation updateOneNewsArticle($data: NewsArticleUpdateInput!, $where: NewsArticleWhereUniqueInput!) {
402
+ updateOneNewsArticle(data: $data, where: $where) {
403
+ ${selectionSet}
404
+ }
405
+ }`;
406
+ const variables = {
407
+ where: {
408
+ id: props.id !== undefined ? props.id : undefined,
409
+ url: props.url !== undefined ? props.url : undefined,
410
+ title: props.title !== undefined ? {
411
+ equals: props.title
412
+ } : undefined,
413
+ },
414
+ data: {
415
+ id: props.id !== undefined ? {
416
+ set: props.id
417
+ } : undefined,
418
+ title: props.title !== undefined ? {
419
+ set: props.title
420
+ } : undefined,
421
+ content: props.content !== undefined ? {
422
+ set: props.content
423
+ } : undefined,
424
+ source: props.source !== undefined ? {
425
+ set: props.source
426
+ } : undefined,
427
+ sourceDomain: props.sourceDomain !== undefined ? {
428
+ set: props.sourceDomain
429
+ } : undefined,
430
+ url: props.url !== undefined ? {
431
+ set: props.url
432
+ } : undefined,
433
+ sentiment: props.sentiment !== undefined ? {
434
+ set: props.sentiment
435
+ } : undefined,
436
+ authors: props.authors !== undefined ? {
437
+ set: props.authors
438
+ } : undefined,
439
+ summary: props.summary !== undefined ? {
440
+ set: props.summary
441
+ } : undefined,
442
+ bannerImage: props.bannerImage !== undefined ? {
443
+ set: props.bannerImage
444
+ } : undefined,
445
+ timePublished: props.timePublished !== undefined ? {
446
+ set: props.timePublished
447
+ } : undefined,
448
+ category: props.category !== undefined ? {
449
+ set: props.category
450
+ } : undefined,
451
+ topics: props.topics !== undefined ? {
452
+ set: props.topics
453
+ } : undefined,
454
+ logo: props.logo !== undefined ? {
455
+ set: props.logo
456
+ } : undefined,
457
+ createdAt: props.createdAt !== undefined ? {
458
+ set: props.createdAt
459
+ } : undefined,
460
+ updatedAt: props.updatedAt !== undefined ? {
461
+ set: props.updatedAt
462
+ } : undefined,
463
+ assets: props.assets ?
464
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
465
+ connect: props.assets.map((item) => ({
466
+ id: item.id
467
+ }))
468
+ } : { upsert: props.assets.map((item) => ({
469
+ where: {
470
+ id: item.id !== undefined ? item.id : undefined,
471
+ url: item.url !== undefined ? item.url : undefined,
472
+ assetId: item.assetId !== undefined ? {
473
+ equals: item.assetId
474
+ } : undefined,
475
+ newsArticleId: item.newsArticleId !== undefined ? {
476
+ equals: item.newsArticleId
477
+ } : undefined,
478
+ },
479
+ update: {
480
+ id: item.id !== undefined ? {
481
+ set: item.id
482
+ } : undefined,
483
+ url: item.url !== undefined ? {
484
+ set: item.url
485
+ } : undefined,
486
+ relevancyScore: item.relevancyScore !== undefined ? {
487
+ set: item.relevancyScore
488
+ } : undefined,
489
+ sentimentScore: item.sentimentScore !== undefined ? {
490
+ set: item.sentimentScore
491
+ } : undefined,
492
+ sentimentLabel: item.sentimentLabel !== undefined ? {
493
+ set: item.sentimentLabel
494
+ } : undefined,
495
+ asset: item.asset ?
496
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
497
+ ? {
498
+ connect: {
499
+ id: item.asset.id
500
+ }
501
+ } : { upsert: {
165
502
  where: {
166
- id: item.asset.id !== undefined ? item.asset.id : undefined,
167
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
168
- name: item.asset.name !== undefined ? item.asset.name : undefined,
503
+ id: item.asset.id !== undefined ? {
504
+ equals: item.asset.id
505
+ } : undefined,
506
+ symbol: item.asset.symbol !== undefined ? {
507
+ equals: item.asset.symbol
508
+ } : undefined,
509
+ name: item.asset.name !== undefined ? {
510
+ equals: item.asset.name
511
+ } : undefined,
512
+ },
513
+ update: {
514
+ id: item.asset.id !== undefined ? {
515
+ set: item.asset.id
516
+ } : undefined,
517
+ symbol: item.asset.symbol !== undefined ? {
518
+ set: item.asset.symbol
519
+ } : undefined,
520
+ name: item.asset.name !== undefined ? {
521
+ set: item.asset.name
522
+ } : undefined,
523
+ type: item.asset.type !== undefined ? {
524
+ set: item.asset.type
525
+ } : undefined,
526
+ logoUrl: item.asset.logoUrl !== undefined ? {
527
+ set: item.asset.logoUrl
528
+ } : undefined,
529
+ description: item.asset.description !== undefined ? {
530
+ set: item.asset.description
531
+ } : undefined,
532
+ cik: item.asset.cik !== undefined ? {
533
+ set: item.asset.cik
534
+ } : undefined,
535
+ exchange: item.asset.exchange !== undefined ? {
536
+ set: item.asset.exchange
537
+ } : undefined,
538
+ currency: item.asset.currency !== undefined ? {
539
+ set: item.asset.currency
540
+ } : undefined,
541
+ country: item.asset.country !== undefined ? {
542
+ set: item.asset.country
543
+ } : undefined,
544
+ sector: item.asset.sector !== undefined ? {
545
+ set: item.asset.sector
546
+ } : undefined,
547
+ industry: item.asset.industry !== undefined ? {
548
+ set: item.asset.industry
549
+ } : undefined,
550
+ address: item.asset.address !== undefined ? {
551
+ set: item.asset.address
552
+ } : undefined,
553
+ officialSite: item.asset.officialSite !== undefined ? {
554
+ set: item.asset.officialSite
555
+ } : undefined,
556
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
557
+ set: item.asset.fiscalYearEnd
558
+ } : undefined,
559
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
560
+ set: item.asset.latestQuarter
561
+ } : undefined,
562
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
563
+ set: item.asset.marketCapitalization
564
+ } : undefined,
565
+ ebitda: item.asset.ebitda !== undefined ? {
566
+ set: item.asset.ebitda
567
+ } : undefined,
568
+ peRatio: item.asset.peRatio !== undefined ? {
569
+ set: item.asset.peRatio
570
+ } : undefined,
571
+ pegRatio: item.asset.pegRatio !== undefined ? {
572
+ set: item.asset.pegRatio
573
+ } : undefined,
574
+ bookValue: item.asset.bookValue !== undefined ? {
575
+ set: item.asset.bookValue
576
+ } : undefined,
577
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
578
+ set: item.asset.dividendPerShare
579
+ } : undefined,
580
+ dividendYield: item.asset.dividendYield !== undefined ? {
581
+ set: item.asset.dividendYield
582
+ } : undefined,
583
+ eps: item.asset.eps !== undefined ? {
584
+ set: item.asset.eps
585
+ } : undefined,
586
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
587
+ set: item.asset.revenuePerShareTTM
588
+ } : undefined,
589
+ profitMargin: item.asset.profitMargin !== undefined ? {
590
+ set: item.asset.profitMargin
591
+ } : undefined,
592
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
593
+ set: item.asset.operatingMarginTTM
594
+ } : undefined,
595
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
596
+ set: item.asset.returnOnAssetsTTM
597
+ } : undefined,
598
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
599
+ set: item.asset.returnOnEquityTTM
600
+ } : undefined,
601
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
602
+ set: item.asset.revenueTTM
603
+ } : undefined,
604
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
605
+ set: item.asset.grossProfitTTM
606
+ } : undefined,
607
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
608
+ set: item.asset.dilutedEPSTTM
609
+ } : undefined,
610
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
611
+ set: item.asset.quarterlyEarningsGrowthYOY
612
+ } : undefined,
613
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
614
+ set: item.asset.quarterlyRevenueGrowthYOY
615
+ } : undefined,
616
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
617
+ set: item.asset.analystTargetPrice
618
+ } : undefined,
619
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
620
+ set: item.asset.analystRatingStrongBuy
621
+ } : undefined,
622
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
623
+ set: item.asset.analystRatingBuy
624
+ } : undefined,
625
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
626
+ set: item.asset.analystRatingHold
627
+ } : undefined,
628
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
629
+ set: item.asset.analystRatingSell
630
+ } : undefined,
631
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
632
+ set: item.asset.analystRatingStrongSell
633
+ } : undefined,
634
+ trailingPE: item.asset.trailingPE !== undefined ? {
635
+ set: item.asset.trailingPE
636
+ } : undefined,
637
+ forwardPE: item.asset.forwardPE !== undefined ? {
638
+ set: item.asset.forwardPE
639
+ } : undefined,
640
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
641
+ set: item.asset.priceToSalesRatioTTM
642
+ } : undefined,
643
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
644
+ set: item.asset.priceToBookRatio
645
+ } : undefined,
646
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
647
+ set: item.asset.evToRevenue
648
+ } : undefined,
649
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
650
+ set: item.asset.evToEbitda
651
+ } : undefined,
652
+ beta: item.asset.beta !== undefined ? {
653
+ set: item.asset.beta
654
+ } : undefined,
655
+ week52High: item.asset.week52High !== undefined ? {
656
+ set: item.asset.week52High
657
+ } : undefined,
658
+ week52Low: item.asset.week52Low !== undefined ? {
659
+ set: item.asset.week52Low
660
+ } : undefined,
661
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
662
+ set: item.asset.day50MovingAverage
663
+ } : undefined,
664
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
665
+ set: item.asset.day200MovingAverage
666
+ } : undefined,
667
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
668
+ set: item.asset.sharesOutstanding
669
+ } : undefined,
670
+ dividendDate: item.asset.dividendDate !== undefined ? {
671
+ set: item.asset.dividendDate
672
+ } : undefined,
673
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
674
+ set: item.asset.exDividendDate
675
+ } : undefined,
676
+ askPrice: item.asset.askPrice !== undefined ? {
677
+ set: item.asset.askPrice
678
+ } : undefined,
679
+ bidPrice: item.asset.bidPrice !== undefined ? {
680
+ set: item.asset.bidPrice
681
+ } : undefined,
169
682
  },
170
683
  create: {
171
684
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -226,617 +739,535 @@ exports.NewsArticle = {
226
739
  },
227
740
  }
228
741
  } : undefined,
229
- },
230
- }))
231
- } : undefined,
232
- },
233
- };
234
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
235
- try {
236
- const response = await client.mutate({ mutation: CREATE_ONE_NEWSARTICLE, variables: filteredVariables });
237
- if (response.errors && response.errors.length > 0)
238
- throw new Error(response.errors[0].message);
239
- if (response && response.data && response.data.createOneNewsArticle) {
240
- return response.data.createOneNewsArticle;
241
- }
242
- else {
243
- return null;
244
- }
245
- }
246
- catch (error) {
247
- console.error('Error in createOneNewsArticle:', error);
248
- throw error;
249
- }
250
- },
251
- /**
252
- * Create multiple NewsArticle records.
253
- * @param props - Array of NewsArticle objects for the new records.
254
- * @param globalClient - Apollo Client instance.
255
- * @returns The count of created records or null.
256
- */
257
- async createMany(props, globalClient) {
258
- const [modules, client] = await Promise.all([
259
- (0, client_1.getApolloModules)(),
260
- globalClient
261
- ? Promise.resolve(globalClient)
262
- : client_1.client
263
- ]);
264
- const { gql, ApolloError } = modules;
265
- const CREATE_MANY_NEWSARTICLE = gql `
266
- mutation createManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
267
- createManyNewsArticle(data: $data) {
268
- count
269
- }
270
- }`;
271
- const variables = {
272
- data: props.map(prop => ({
273
- title: prop.title !== undefined ? prop.title : undefined,
274
- content: prop.content !== undefined ? prop.content : undefined,
275
- source: prop.source !== undefined ? prop.source : undefined,
276
- sourceDomain: prop.sourceDomain !== undefined ? prop.sourceDomain : undefined,
277
- url: prop.url !== undefined ? prop.url : undefined,
278
- sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
279
- authors: prop.authors !== undefined ? {
280
- set: prop.authors
281
- } : undefined,
282
- summary: prop.summary !== undefined ? prop.summary : undefined,
283
- bannerImage: prop.bannerImage !== undefined ? prop.bannerImage : undefined,
284
- timePublished: prop.timePublished !== undefined ? prop.timePublished : undefined,
285
- category: prop.category !== undefined ? prop.category : undefined,
286
- topics: prop.topics !== undefined ? {
287
- set: prop.topics
288
- } : undefined,
289
- logo: prop.logo !== undefined ? prop.logo : undefined,
290
- })),
291
- };
292
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
293
- try {
294
- const response = await client.mutate({ mutation: CREATE_MANY_NEWSARTICLE, variables: filteredVariables });
295
- if (response.errors && response.errors.length > 0)
296
- throw new Error(response.errors[0].message);
297
- if (response && response.data && response.data.createManyNewsArticle) {
298
- return response.data.createManyNewsArticle;
299
- }
300
- else {
301
- return null;
302
- }
303
- }
304
- catch (error) {
305
- console.error('Error in createManyNewsArticle:', error);
306
- throw error;
307
- }
308
- },
309
- /**
310
- * Update a single NewsArticle record.
311
- * @param props - Properties to update.
312
- * @param globalClient - Apollo Client instance.
313
- * @returns The updated NewsArticle or null.
314
- */
315
- async update(props, globalClient) {
316
- const [modules, client] = await Promise.all([
317
- (0, client_1.getApolloModules)(),
318
- globalClient
319
- ? Promise.resolve(globalClient)
320
- : client_1.client
321
- ]);
322
- const { gql, ApolloError } = modules;
323
- const UPDATE_ONE_NEWSARTICLE = gql `
324
- mutation updateOneNewsArticle($data: NewsArticleUpdateInput!, $where: NewsArticleWhereUniqueInput!) {
325
- updateOneNewsArticle(data: $data, where: $where) {
326
- ${selectionSet}
327
- }
328
- }`;
329
- const variables = {
330
- where: {
331
- id: props.id !== undefined ? props.id : undefined,
332
- url: props.url !== undefined ? props.url : undefined,
333
- title: props.title !== undefined ? {
334
- equals: props.title
335
- } : undefined,
336
- },
337
- data: {
338
- id: props.id !== undefined ? {
339
- set: props.id
340
- } : undefined,
341
- title: props.title !== undefined ? {
342
- set: props.title
343
- } : undefined,
344
- content: props.content !== undefined ? {
345
- set: props.content
346
- } : undefined,
347
- source: props.source !== undefined ? {
348
- set: props.source
349
- } : undefined,
350
- sourceDomain: props.sourceDomain !== undefined ? {
351
- set: props.sourceDomain
352
- } : undefined,
353
- url: props.url !== undefined ? {
354
- set: props.url
355
- } : undefined,
356
- sentiment: props.sentiment !== undefined ? {
357
- set: props.sentiment
358
- } : undefined,
359
- authors: props.authors !== undefined ? {
360
- set: props.authors
361
- } : undefined,
362
- summary: props.summary !== undefined ? {
363
- set: props.summary
364
- } : undefined,
365
- bannerImage: props.bannerImage !== undefined ? {
366
- set: props.bannerImage
367
- } : undefined,
368
- timePublished: props.timePublished !== undefined ? {
369
- set: props.timePublished
370
- } : undefined,
371
- category: props.category !== undefined ? {
372
- set: props.category
373
- } : undefined,
374
- topics: props.topics !== undefined ? {
375
- set: props.topics
376
- } : undefined,
377
- logo: props.logo !== undefined ? {
378
- set: props.logo
379
- } : undefined,
380
- createdAt: props.createdAt !== undefined ? {
381
- set: props.createdAt
382
- } : undefined,
383
- updatedAt: props.updatedAt !== undefined ? {
384
- set: props.updatedAt
385
- } : undefined,
386
- assets: props.assets ?
387
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
388
- connect: props.assets.map((item) => ({
389
- id: item.id
390
- }))
391
- } : { upsert: props.assets.map((item) => ({
392
- where: {
393
- id: item.id !== undefined ? item.id : undefined,
394
- url: item.url !== undefined ? item.url : undefined,
395
- assetId: item.assetId !== undefined ? {
396
- equals: item.assetId
397
- } : undefined,
398
- newsArticleId: item.newsArticleId !== undefined ? {
399
- equals: item.newsArticleId
400
- } : undefined,
401
- },
402
- update: {
403
- id: item.id !== undefined ? {
404
- set: item.id
405
- } : undefined,
406
- url: item.url !== undefined ? {
407
- set: item.url
408
- } : undefined,
409
- relevancyScore: item.relevancyScore !== undefined ? {
410
- set: item.relevancyScore
411
- } : undefined,
412
- sentimentScore: item.sentimentScore !== undefined ? {
413
- set: item.sentimentScore
414
- } : undefined,
415
- sentimentLabel: item.sentimentLabel !== undefined ? {
416
- set: item.sentimentLabel
417
- } : undefined,
418
- asset: item.asset ?
419
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
420
- ? {
421
- connect: {
422
- id: item.asset.id
423
- }
424
- } : { upsert: {
425
- where: {
426
- id: item.asset.id !== undefined ? {
427
- equals: item.asset.id
428
- } : undefined,
429
- symbol: item.asset.symbol !== undefined ? {
430
- equals: item.asset.symbol
431
- } : undefined,
432
- name: item.asset.name !== undefined ? {
433
- equals: item.asset.name
434
- } : undefined,
435
- },
436
- update: {
437
- id: item.asset.id !== undefined ? {
438
- set: item.asset.id
439
- } : undefined,
440
- symbol: item.asset.symbol !== undefined ? {
441
- set: item.asset.symbol
442
- } : undefined,
443
- name: item.asset.name !== undefined ? {
444
- set: item.asset.name
445
- } : undefined,
446
- type: item.asset.type !== undefined ? {
447
- set: item.asset.type
448
- } : undefined,
449
- logoUrl: item.asset.logoUrl !== undefined ? {
450
- set: item.asset.logoUrl
451
- } : undefined,
452
- description: item.asset.description !== undefined ? {
453
- set: item.asset.description
454
- } : undefined,
455
- cik: item.asset.cik !== undefined ? {
456
- set: item.asset.cik
457
- } : undefined,
458
- exchange: item.asset.exchange !== undefined ? {
459
- set: item.asset.exchange
460
- } : undefined,
461
- currency: item.asset.currency !== undefined ? {
462
- set: item.asset.currency
463
- } : undefined,
464
- country: item.asset.country !== undefined ? {
465
- set: item.asset.country
466
- } : undefined,
467
- sector: item.asset.sector !== undefined ? {
468
- set: item.asset.sector
469
- } : undefined,
470
- industry: item.asset.industry !== undefined ? {
471
- set: item.asset.industry
472
- } : undefined,
473
- address: item.asset.address !== undefined ? {
474
- set: item.asset.address
475
- } : undefined,
476
- officialSite: item.asset.officialSite !== undefined ? {
477
- set: item.asset.officialSite
478
- } : undefined,
479
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
480
- set: item.asset.fiscalYearEnd
481
- } : undefined,
482
- latestQuarter: item.asset.latestQuarter !== undefined ? {
483
- set: item.asset.latestQuarter
484
- } : undefined,
485
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
486
- set: item.asset.marketCapitalization
487
- } : undefined,
488
- ebitda: item.asset.ebitda !== undefined ? {
489
- set: item.asset.ebitda
490
- } : undefined,
491
- peRatio: item.asset.peRatio !== undefined ? {
492
- set: item.asset.peRatio
493
- } : undefined,
494
- pegRatio: item.asset.pegRatio !== undefined ? {
495
- set: item.asset.pegRatio
496
- } : undefined,
497
- bookValue: item.asset.bookValue !== undefined ? {
498
- set: item.asset.bookValue
499
- } : undefined,
500
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
501
- set: item.asset.dividendPerShare
502
- } : undefined,
503
- dividendYield: item.asset.dividendYield !== undefined ? {
504
- set: item.asset.dividendYield
505
- } : undefined,
506
- eps: item.asset.eps !== undefined ? {
507
- set: item.asset.eps
508
- } : undefined,
509
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
510
- set: item.asset.revenuePerShareTTM
511
- } : undefined,
512
- profitMargin: item.asset.profitMargin !== undefined ? {
513
- set: item.asset.profitMargin
514
- } : undefined,
515
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
516
- set: item.asset.operatingMarginTTM
517
- } : undefined,
518
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
519
- set: item.asset.returnOnAssetsTTM
520
- } : undefined,
521
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
522
- set: item.asset.returnOnEquityTTM
523
- } : undefined,
524
- revenueTTM: item.asset.revenueTTM !== undefined ? {
525
- set: item.asset.revenueTTM
526
- } : undefined,
527
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
528
- set: item.asset.grossProfitTTM
529
- } : undefined,
530
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
531
- set: item.asset.dilutedEPSTTM
532
- } : undefined,
533
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
534
- set: item.asset.quarterlyEarningsGrowthYOY
535
- } : undefined,
536
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
537
- set: item.asset.quarterlyRevenueGrowthYOY
538
- } : undefined,
539
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
540
- set: item.asset.analystTargetPrice
541
- } : undefined,
542
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
543
- set: item.asset.analystRatingStrongBuy
544
- } : undefined,
545
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
546
- set: item.asset.analystRatingBuy
547
- } : undefined,
548
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
549
- set: item.asset.analystRatingHold
550
- } : undefined,
551
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
552
- set: item.asset.analystRatingSell
553
- } : undefined,
554
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
555
- set: item.asset.analystRatingStrongSell
556
- } : undefined,
557
- trailingPE: item.asset.trailingPE !== undefined ? {
558
- set: item.asset.trailingPE
559
- } : undefined,
560
- forwardPE: item.asset.forwardPE !== undefined ? {
561
- set: item.asset.forwardPE
562
- } : undefined,
563
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
564
- set: item.asset.priceToSalesRatioTTM
565
- } : undefined,
566
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
567
- set: item.asset.priceToBookRatio
568
- } : undefined,
569
- evToRevenue: item.asset.evToRevenue !== undefined ? {
570
- set: item.asset.evToRevenue
571
- } : undefined,
572
- evToEbitda: item.asset.evToEbitda !== undefined ? {
573
- set: item.asset.evToEbitda
574
- } : undefined,
575
- beta: item.asset.beta !== undefined ? {
576
- set: item.asset.beta
577
- } : undefined,
578
- week52High: item.asset.week52High !== undefined ? {
579
- set: item.asset.week52High
580
- } : undefined,
581
- week52Low: item.asset.week52Low !== undefined ? {
582
- set: item.asset.week52Low
583
- } : undefined,
584
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
585
- set: item.asset.day50MovingAverage
586
- } : undefined,
587
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
588
- set: item.asset.day200MovingAverage
589
- } : undefined,
590
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
591
- set: item.asset.sharesOutstanding
592
- } : undefined,
593
- dividendDate: item.asset.dividendDate !== undefined ? {
594
- set: item.asset.dividendDate
595
- } : undefined,
596
- exDividendDate: item.asset.exDividendDate !== undefined ? {
597
- set: item.asset.exDividendDate
598
- } : undefined,
599
- askPrice: item.asset.askPrice !== undefined ? {
600
- set: item.asset.askPrice
601
- } : undefined,
602
- bidPrice: item.asset.bidPrice !== undefined ? {
603
- set: item.asset.bidPrice
604
- } : undefined,
605
- },
606
- create: {
607
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
608
- name: item.asset.name !== undefined ? item.asset.name : undefined,
609
- type: item.asset.type !== undefined ? item.asset.type : undefined,
610
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
611
- description: item.asset.description !== undefined ? item.asset.description : undefined,
612
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
613
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
614
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
615
- country: item.asset.country !== undefined ? item.asset.country : undefined,
616
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
617
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
618
- address: item.asset.address !== undefined ? item.asset.address : undefined,
619
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
620
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
621
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
622
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
623
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
624
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
625
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
626
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
627
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
628
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
629
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
630
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
631
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
632
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
633
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
634
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
635
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
636
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
637
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
638
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
639
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
640
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
641
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
642
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
643
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
644
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
645
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
646
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
647
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
648
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
649
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
650
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
651
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
652
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
653
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
654
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
655
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
656
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
657
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
658
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
659
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
660
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
661
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
662
- },
663
- }
664
- } : undefined,
665
- },
666
- create: {
667
- url: item.url !== undefined ? item.url : undefined,
668
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
669
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
670
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
671
- asset: item.asset ?
672
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
673
- ? { connect: {
674
- id: item.asset.id
675
- }
676
- }
677
- : { connectOrCreate: {
678
- where: {
679
- id: item.asset.id !== undefined ? item.asset.id : undefined,
680
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
681
- name: item.asset.name !== undefined ? item.asset.name : undefined,
682
- },
683
- create: {
684
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
685
- name: item.asset.name !== undefined ? item.asset.name : undefined,
686
- type: item.asset.type !== undefined ? item.asset.type : undefined,
687
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
688
- description: item.asset.description !== undefined ? item.asset.description : undefined,
689
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
690
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
691
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
692
- country: item.asset.country !== undefined ? item.asset.country : undefined,
693
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
694
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
695
- address: item.asset.address !== undefined ? item.asset.address : undefined,
696
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
697
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
698
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
699
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
700
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
701
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
702
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
703
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
704
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
705
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
706
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
707
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
708
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
709
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
710
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
711
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
712
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
713
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
714
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
715
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
716
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
717
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
718
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
719
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
720
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
721
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
722
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
723
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
724
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
725
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
726
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
727
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
728
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
729
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
730
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
731
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
732
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
733
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
734
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
735
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
736
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
737
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
738
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
739
- },
740
- }
741
- } : undefined,
742
- },
743
- }))
744
- } : undefined,
745
- },
746
- };
747
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
748
- try {
749
- const response = await client.mutate({ mutation: UPDATE_ONE_NEWSARTICLE, variables: filteredVariables });
750
- if (response.errors && response.errors.length > 0)
751
- throw new Error(response.errors[0].message);
752
- if (response && response.data && response.data.updateOneNewsArticle) {
753
- return response.data.updateOneNewsArticle;
742
+ },
743
+ create: {
744
+ url: item.url !== undefined ? item.url : undefined,
745
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
746
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
747
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
748
+ asset: item.asset ?
749
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
750
+ ? { connect: {
751
+ id: item.asset.id
752
+ }
753
+ }
754
+ : { connectOrCreate: {
755
+ where: {
756
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
757
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
758
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
759
+ },
760
+ create: {
761
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
762
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
763
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
764
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
765
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
766
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
767
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
768
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
769
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
770
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
771
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
772
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
773
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
774
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
775
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
776
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
777
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
778
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
779
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
780
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
781
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
782
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
783
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
784
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
785
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
786
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
787
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
788
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
789
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
790
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
791
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
792
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
793
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
794
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
795
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
796
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
797
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
798
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
799
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
800
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
801
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
802
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
803
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
804
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
805
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
806
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
807
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
808
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
809
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
810
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
811
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
812
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
813
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
814
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
815
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
816
+ },
817
+ }
818
+ } : undefined,
819
+ },
820
+ }))
821
+ } : undefined,
822
+ },
823
+ };
824
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
825
+ const response = await client.mutate({
826
+ mutation: UPDATE_ONE_NEWSARTICLE,
827
+ variables: filteredVariables,
828
+ // Don't cache mutations, but ensure we're using the freshest context
829
+ fetchPolicy: 'no-cache'
830
+ });
831
+ if (response.errors && response.errors.length > 0)
832
+ throw new Error(response.errors[0].message);
833
+ if (response && response.data && response.data.updateOneNewsArticle) {
834
+ return response.data.updateOneNewsArticle;
835
+ }
836
+ else {
837
+ return null;
838
+ }
754
839
  }
755
- else {
756
- return null;
840
+ catch (error) {
841
+ lastError = error;
842
+ // Check if this is a database connection error that we should retry
843
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
844
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
845
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
846
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
847
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
848
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
849
+ retryCount++;
850
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
851
+ console.warn("Database connection error, retrying...");
852
+ await new Promise(resolve => setTimeout(resolve, delay));
853
+ continue;
854
+ }
855
+ // Log the error and rethrow
856
+ console.error("Database error occurred:", error);
857
+ throw error;
757
858
  }
758
859
  }
759
- catch (error) {
760
- console.error('Error in updateOneNewsArticle:', error);
761
- throw error;
762
- }
860
+ // If we exhausted retries, throw the last error
861
+ throw lastError;
763
862
  },
764
863
  /**
765
864
  * Upsert a single NewsArticle record.
865
+ * Enhanced with connection resilience against Prisma connection errors.
766
866
  * @param props - Properties to update.
767
867
  * @param globalClient - Apollo Client instance.
768
868
  * @returns The updated NewsArticle or null.
769
869
  */
770
870
  async upsert(props, globalClient) {
771
- const [modules, client] = await Promise.all([
772
- (0, client_1.getApolloModules)(),
773
- globalClient
774
- ? Promise.resolve(globalClient)
775
- : client_1.client
776
- ]);
777
- const { gql, ApolloError } = modules;
778
- const UPSERT_ONE_NEWSARTICLE = gql `
779
- mutation upsertOneNewsArticle($where: NewsArticleWhereUniqueInput!, $create: NewsArticleCreateInput!, $update: NewsArticleUpdateInput!) {
780
- upsertOneNewsArticle(where: $where, create: $create, update: $update) {
781
- ${selectionSet}
782
- }
783
- }`;
784
- const variables = {
785
- where: {
786
- id: props.id !== undefined ? props.id : undefined,
787
- url: props.url !== undefined ? props.url : undefined,
788
- title: props.title !== undefined ? {
789
- equals: props.title
790
- } : undefined,
791
- },
792
- create: {
793
- title: props.title !== undefined ? props.title : undefined,
794
- content: props.content !== undefined ? props.content : undefined,
795
- source: props.source !== undefined ? props.source : undefined,
796
- sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
797
- url: props.url !== undefined ? props.url : undefined,
798
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
799
- authors: props.authors !== undefined ? {
800
- set: props.authors
801
- } : undefined,
802
- summary: props.summary !== undefined ? props.summary : undefined,
803
- bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
804
- timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
805
- category: props.category !== undefined ? props.category : undefined,
806
- topics: props.topics !== undefined ? {
807
- set: props.topics
808
- } : undefined,
809
- logo: props.logo !== undefined ? props.logo : undefined,
810
- assets: props.assets ?
811
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
812
- connect: props.assets.map((item) => ({
813
- id: item.id
814
- }))
815
- }
816
- : { connectOrCreate: props.assets.map((item) => ({
817
- where: {
818
- id: item.id !== undefined ? item.id : undefined,
819
- url: item.url !== undefined ? item.url : undefined,
820
- newsArticleId: item.newsArticleId !== undefined ? {
821
- equals: item.newsArticleId
822
- } : undefined,
823
- },
824
- create: {
825
- url: item.url !== undefined ? item.url : undefined,
826
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
827
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
828
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
829
- asset: item.asset ?
830
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
831
- ? { connect: {
832
- id: item.asset.id
833
- }
834
- }
835
- : { connectOrCreate: {
871
+ var _a, _b, _c, _d, _e;
872
+ // Maximum number of retries for database connection issues
873
+ const MAX_RETRIES = 3;
874
+ let retryCount = 0;
875
+ let lastError = null;
876
+ // Retry loop to handle potential database connection issues
877
+ while (retryCount < MAX_RETRIES) {
878
+ try {
879
+ const [modules, client] = await Promise.all([
880
+ (0, client_1.getApolloModules)(),
881
+ globalClient
882
+ ? Promise.resolve(globalClient)
883
+ : client_1.client
884
+ ]);
885
+ const { gql, ApolloError } = modules;
886
+ const UPSERT_ONE_NEWSARTICLE = gql `
887
+ mutation upsertOneNewsArticle($where: NewsArticleWhereUniqueInput!, $create: NewsArticleCreateInput!, $update: NewsArticleUpdateInput!) {
888
+ upsertOneNewsArticle(where: $where, create: $create, update: $update) {
889
+ ${selectionSet}
890
+ }
891
+ }`;
892
+ const variables = {
893
+ where: {
894
+ id: props.id !== undefined ? props.id : undefined,
895
+ url: props.url !== undefined ? props.url : undefined,
896
+ title: props.title !== undefined ? {
897
+ equals: props.title
898
+ } : undefined,
899
+ },
900
+ create: {
901
+ title: props.title !== undefined ? props.title : undefined,
902
+ content: props.content !== undefined ? props.content : undefined,
903
+ source: props.source !== undefined ? props.source : undefined,
904
+ sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
905
+ url: props.url !== undefined ? props.url : undefined,
906
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
907
+ authors: props.authors !== undefined ? {
908
+ set: props.authors
909
+ } : undefined,
910
+ summary: props.summary !== undefined ? props.summary : undefined,
911
+ bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
912
+ timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
913
+ category: props.category !== undefined ? props.category : undefined,
914
+ topics: props.topics !== undefined ? {
915
+ set: props.topics
916
+ } : undefined,
917
+ logo: props.logo !== undefined ? props.logo : undefined,
918
+ assets: props.assets ?
919
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
920
+ connect: props.assets.map((item) => ({
921
+ id: item.id
922
+ }))
923
+ }
924
+ : { connectOrCreate: props.assets.map((item) => ({
925
+ where: {
926
+ id: item.id !== undefined ? item.id : undefined,
927
+ url: item.url !== undefined ? item.url : undefined,
928
+ newsArticleId: item.newsArticleId !== undefined ? {
929
+ equals: item.newsArticleId
930
+ } : undefined,
931
+ },
932
+ create: {
933
+ url: item.url !== undefined ? item.url : undefined,
934
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
935
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
936
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
937
+ asset: item.asset ?
938
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
939
+ ? { connect: {
940
+ id: item.asset.id
941
+ }
942
+ }
943
+ : { connectOrCreate: {
944
+ where: {
945
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
946
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
947
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
948
+ },
949
+ create: {
950
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
951
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
952
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
953
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
954
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
955
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
956
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
957
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
958
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
959
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
960
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
961
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
962
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
963
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
964
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
965
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
966
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
967
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
968
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
969
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
970
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
971
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
972
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
973
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
974
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
975
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
976
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
977
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
978
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
979
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
980
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
981
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
982
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
983
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
984
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
985
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
986
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
987
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
988
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
989
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
990
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
991
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
992
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
993
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
994
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
995
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
996
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
997
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
998
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
999
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1000
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1001
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1002
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1003
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1004
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1005
+ },
1006
+ }
1007
+ } : undefined,
1008
+ },
1009
+ }))
1010
+ } : undefined,
1011
+ },
1012
+ update: {
1013
+ title: props.title !== undefined ? {
1014
+ set: props.title
1015
+ } : undefined,
1016
+ content: props.content !== undefined ? {
1017
+ set: props.content
1018
+ } : undefined,
1019
+ source: props.source !== undefined ? {
1020
+ set: props.source
1021
+ } : undefined,
1022
+ sourceDomain: props.sourceDomain !== undefined ? {
1023
+ set: props.sourceDomain
1024
+ } : undefined,
1025
+ url: props.url !== undefined ? {
1026
+ set: props.url
1027
+ } : undefined,
1028
+ sentiment: props.sentiment !== undefined ? {
1029
+ set: props.sentiment
1030
+ } : undefined,
1031
+ authors: props.authors !== undefined ? {
1032
+ set: props.authors
1033
+ } : undefined,
1034
+ summary: props.summary !== undefined ? {
1035
+ set: props.summary
1036
+ } : undefined,
1037
+ bannerImage: props.bannerImage !== undefined ? {
1038
+ set: props.bannerImage
1039
+ } : undefined,
1040
+ timePublished: props.timePublished !== undefined ? {
1041
+ set: props.timePublished
1042
+ } : undefined,
1043
+ category: props.category !== undefined ? {
1044
+ set: props.category
1045
+ } : undefined,
1046
+ topics: props.topics !== undefined ? {
1047
+ set: props.topics
1048
+ } : undefined,
1049
+ logo: props.logo !== undefined ? {
1050
+ set: props.logo
1051
+ } : undefined,
1052
+ assets: props.assets ?
1053
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1054
+ connect: props.assets.map((item) => ({
1055
+ id: item.id
1056
+ }))
1057
+ } : { upsert: props.assets.map((item) => ({
1058
+ where: {
1059
+ id: item.id !== undefined ? item.id : undefined,
1060
+ url: item.url !== undefined ? item.url : undefined,
1061
+ assetId: item.assetId !== undefined ? {
1062
+ equals: item.assetId
1063
+ } : undefined,
1064
+ newsArticleId: item.newsArticleId !== undefined ? {
1065
+ equals: item.newsArticleId
1066
+ } : undefined,
1067
+ },
1068
+ update: {
1069
+ id: item.id !== undefined ? {
1070
+ set: item.id
1071
+ } : undefined,
1072
+ url: item.url !== undefined ? {
1073
+ set: item.url
1074
+ } : undefined,
1075
+ relevancyScore: item.relevancyScore !== undefined ? {
1076
+ set: item.relevancyScore
1077
+ } : undefined,
1078
+ sentimentScore: item.sentimentScore !== undefined ? {
1079
+ set: item.sentimentScore
1080
+ } : undefined,
1081
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1082
+ set: item.sentimentLabel
1083
+ } : undefined,
1084
+ asset: item.asset ?
1085
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1086
+ ? {
1087
+ connect: {
1088
+ id: item.asset.id
1089
+ }
1090
+ } : { upsert: {
836
1091
  where: {
837
- id: item.asset.id !== undefined ? item.asset.id : undefined,
838
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
839
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1092
+ id: item.asset.id !== undefined ? {
1093
+ equals: item.asset.id
1094
+ } : undefined,
1095
+ symbol: item.asset.symbol !== undefined ? {
1096
+ equals: item.asset.symbol
1097
+ } : undefined,
1098
+ name: item.asset.name !== undefined ? {
1099
+ equals: item.asset.name
1100
+ } : undefined,
1101
+ },
1102
+ update: {
1103
+ id: item.asset.id !== undefined ? {
1104
+ set: item.asset.id
1105
+ } : undefined,
1106
+ symbol: item.asset.symbol !== undefined ? {
1107
+ set: item.asset.symbol
1108
+ } : undefined,
1109
+ name: item.asset.name !== undefined ? {
1110
+ set: item.asset.name
1111
+ } : undefined,
1112
+ type: item.asset.type !== undefined ? {
1113
+ set: item.asset.type
1114
+ } : undefined,
1115
+ logoUrl: item.asset.logoUrl !== undefined ? {
1116
+ set: item.asset.logoUrl
1117
+ } : undefined,
1118
+ description: item.asset.description !== undefined ? {
1119
+ set: item.asset.description
1120
+ } : undefined,
1121
+ cik: item.asset.cik !== undefined ? {
1122
+ set: item.asset.cik
1123
+ } : undefined,
1124
+ exchange: item.asset.exchange !== undefined ? {
1125
+ set: item.asset.exchange
1126
+ } : undefined,
1127
+ currency: item.asset.currency !== undefined ? {
1128
+ set: item.asset.currency
1129
+ } : undefined,
1130
+ country: item.asset.country !== undefined ? {
1131
+ set: item.asset.country
1132
+ } : undefined,
1133
+ sector: item.asset.sector !== undefined ? {
1134
+ set: item.asset.sector
1135
+ } : undefined,
1136
+ industry: item.asset.industry !== undefined ? {
1137
+ set: item.asset.industry
1138
+ } : undefined,
1139
+ address: item.asset.address !== undefined ? {
1140
+ set: item.asset.address
1141
+ } : undefined,
1142
+ officialSite: item.asset.officialSite !== undefined ? {
1143
+ set: item.asset.officialSite
1144
+ } : undefined,
1145
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1146
+ set: item.asset.fiscalYearEnd
1147
+ } : undefined,
1148
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1149
+ set: item.asset.latestQuarter
1150
+ } : undefined,
1151
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1152
+ set: item.asset.marketCapitalization
1153
+ } : undefined,
1154
+ ebitda: item.asset.ebitda !== undefined ? {
1155
+ set: item.asset.ebitda
1156
+ } : undefined,
1157
+ peRatio: item.asset.peRatio !== undefined ? {
1158
+ set: item.asset.peRatio
1159
+ } : undefined,
1160
+ pegRatio: item.asset.pegRatio !== undefined ? {
1161
+ set: item.asset.pegRatio
1162
+ } : undefined,
1163
+ bookValue: item.asset.bookValue !== undefined ? {
1164
+ set: item.asset.bookValue
1165
+ } : undefined,
1166
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1167
+ set: item.asset.dividendPerShare
1168
+ } : undefined,
1169
+ dividendYield: item.asset.dividendYield !== undefined ? {
1170
+ set: item.asset.dividendYield
1171
+ } : undefined,
1172
+ eps: item.asset.eps !== undefined ? {
1173
+ set: item.asset.eps
1174
+ } : undefined,
1175
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1176
+ set: item.asset.revenuePerShareTTM
1177
+ } : undefined,
1178
+ profitMargin: item.asset.profitMargin !== undefined ? {
1179
+ set: item.asset.profitMargin
1180
+ } : undefined,
1181
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1182
+ set: item.asset.operatingMarginTTM
1183
+ } : undefined,
1184
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1185
+ set: item.asset.returnOnAssetsTTM
1186
+ } : undefined,
1187
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1188
+ set: item.asset.returnOnEquityTTM
1189
+ } : undefined,
1190
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1191
+ set: item.asset.revenueTTM
1192
+ } : undefined,
1193
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1194
+ set: item.asset.grossProfitTTM
1195
+ } : undefined,
1196
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1197
+ set: item.asset.dilutedEPSTTM
1198
+ } : undefined,
1199
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1200
+ set: item.asset.quarterlyEarningsGrowthYOY
1201
+ } : undefined,
1202
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1203
+ set: item.asset.quarterlyRevenueGrowthYOY
1204
+ } : undefined,
1205
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1206
+ set: item.asset.analystTargetPrice
1207
+ } : undefined,
1208
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1209
+ set: item.asset.analystRatingStrongBuy
1210
+ } : undefined,
1211
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1212
+ set: item.asset.analystRatingBuy
1213
+ } : undefined,
1214
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1215
+ set: item.asset.analystRatingHold
1216
+ } : undefined,
1217
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1218
+ set: item.asset.analystRatingSell
1219
+ } : undefined,
1220
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1221
+ set: item.asset.analystRatingStrongSell
1222
+ } : undefined,
1223
+ trailingPE: item.asset.trailingPE !== undefined ? {
1224
+ set: item.asset.trailingPE
1225
+ } : undefined,
1226
+ forwardPE: item.asset.forwardPE !== undefined ? {
1227
+ set: item.asset.forwardPE
1228
+ } : undefined,
1229
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1230
+ set: item.asset.priceToSalesRatioTTM
1231
+ } : undefined,
1232
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1233
+ set: item.asset.priceToBookRatio
1234
+ } : undefined,
1235
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1236
+ set: item.asset.evToRevenue
1237
+ } : undefined,
1238
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1239
+ set: item.asset.evToEbitda
1240
+ } : undefined,
1241
+ beta: item.asset.beta !== undefined ? {
1242
+ set: item.asset.beta
1243
+ } : undefined,
1244
+ week52High: item.asset.week52High !== undefined ? {
1245
+ set: item.asset.week52High
1246
+ } : undefined,
1247
+ week52Low: item.asset.week52Low !== undefined ? {
1248
+ set: item.asset.week52Low
1249
+ } : undefined,
1250
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1251
+ set: item.asset.day50MovingAverage
1252
+ } : undefined,
1253
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1254
+ set: item.asset.day200MovingAverage
1255
+ } : undefined,
1256
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1257
+ set: item.asset.sharesOutstanding
1258
+ } : undefined,
1259
+ dividendDate: item.asset.dividendDate !== undefined ? {
1260
+ set: item.asset.dividendDate
1261
+ } : undefined,
1262
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1263
+ set: item.asset.exDividendDate
1264
+ } : undefined,
1265
+ askPrice: item.asset.askPrice !== undefined ? {
1266
+ set: item.asset.askPrice
1267
+ } : undefined,
1268
+ bidPrice: item.asset.bidPrice !== undefined ? {
1269
+ set: item.asset.bidPrice
1270
+ } : undefined,
840
1271
  },
841
1272
  create: {
842
1273
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -897,1062 +1328,909 @@ exports.NewsArticle = {
897
1328
  },
898
1329
  }
899
1330
  } : undefined,
900
- },
901
- }))
902
- } : undefined,
903
- },
904
- update: {
905
- title: props.title !== undefined ? {
906
- set: props.title
907
- } : undefined,
908
- content: props.content !== undefined ? {
909
- set: props.content
910
- } : undefined,
911
- source: props.source !== undefined ? {
912
- set: props.source
913
- } : undefined,
914
- sourceDomain: props.sourceDomain !== undefined ? {
915
- set: props.sourceDomain
916
- } : undefined,
917
- url: props.url !== undefined ? {
918
- set: props.url
919
- } : undefined,
920
- sentiment: props.sentiment !== undefined ? {
921
- set: props.sentiment
922
- } : undefined,
923
- authors: props.authors !== undefined ? {
924
- set: props.authors
925
- } : undefined,
926
- summary: props.summary !== undefined ? {
927
- set: props.summary
928
- } : undefined,
929
- bannerImage: props.bannerImage !== undefined ? {
930
- set: props.bannerImage
931
- } : undefined,
932
- timePublished: props.timePublished !== undefined ? {
933
- set: props.timePublished
934
- } : undefined,
935
- category: props.category !== undefined ? {
936
- set: props.category
937
- } : undefined,
938
- topics: props.topics !== undefined ? {
939
- set: props.topics
940
- } : undefined,
941
- logo: props.logo !== undefined ? {
942
- set: props.logo
943
- } : undefined,
944
- assets: props.assets ?
945
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
946
- connect: props.assets.map((item) => ({
947
- id: item.id
948
- }))
949
- } : { upsert: props.assets.map((item) => ({
950
- where: {
951
- id: item.id !== undefined ? item.id : undefined,
952
- url: item.url !== undefined ? item.url : undefined,
953
- assetId: item.assetId !== undefined ? {
954
- equals: item.assetId
955
- } : undefined,
956
- newsArticleId: item.newsArticleId !== undefined ? {
957
- equals: item.newsArticleId
958
- } : undefined,
959
- },
960
- update: {
961
- id: item.id !== undefined ? {
962
- set: item.id
963
- } : undefined,
964
- url: item.url !== undefined ? {
965
- set: item.url
966
- } : undefined,
967
- relevancyScore: item.relevancyScore !== undefined ? {
968
- set: item.relevancyScore
969
- } : undefined,
970
- sentimentScore: item.sentimentScore !== undefined ? {
971
- set: item.sentimentScore
972
- } : undefined,
973
- sentimentLabel: item.sentimentLabel !== undefined ? {
974
- set: item.sentimentLabel
975
- } : undefined,
976
- asset: item.asset ?
977
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
978
- ? {
979
- connect: {
980
- id: item.asset.id
981
- }
982
- } : { upsert: {
983
- where: {
984
- id: item.asset.id !== undefined ? {
985
- equals: item.asset.id
986
- } : undefined,
987
- symbol: item.asset.symbol !== undefined ? {
988
- equals: item.asset.symbol
989
- } : undefined,
990
- name: item.asset.name !== undefined ? {
991
- equals: item.asset.name
992
- } : undefined,
993
- },
994
- update: {
995
- id: item.asset.id !== undefined ? {
996
- set: item.asset.id
997
- } : undefined,
998
- symbol: item.asset.symbol !== undefined ? {
999
- set: item.asset.symbol
1000
- } : undefined,
1001
- name: item.asset.name !== undefined ? {
1002
- set: item.asset.name
1003
- } : undefined,
1004
- type: item.asset.type !== undefined ? {
1005
- set: item.asset.type
1006
- } : undefined,
1007
- logoUrl: item.asset.logoUrl !== undefined ? {
1008
- set: item.asset.logoUrl
1009
- } : undefined,
1010
- description: item.asset.description !== undefined ? {
1011
- set: item.asset.description
1012
- } : undefined,
1013
- cik: item.asset.cik !== undefined ? {
1014
- set: item.asset.cik
1015
- } : undefined,
1016
- exchange: item.asset.exchange !== undefined ? {
1017
- set: item.asset.exchange
1018
- } : undefined,
1019
- currency: item.asset.currency !== undefined ? {
1020
- set: item.asset.currency
1021
- } : undefined,
1022
- country: item.asset.country !== undefined ? {
1023
- set: item.asset.country
1024
- } : undefined,
1025
- sector: item.asset.sector !== undefined ? {
1026
- set: item.asset.sector
1027
- } : undefined,
1028
- industry: item.asset.industry !== undefined ? {
1029
- set: item.asset.industry
1030
- } : undefined,
1031
- address: item.asset.address !== undefined ? {
1032
- set: item.asset.address
1033
- } : undefined,
1034
- officialSite: item.asset.officialSite !== undefined ? {
1035
- set: item.asset.officialSite
1036
- } : undefined,
1037
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1038
- set: item.asset.fiscalYearEnd
1039
- } : undefined,
1040
- latestQuarter: item.asset.latestQuarter !== undefined ? {
1041
- set: item.asset.latestQuarter
1042
- } : undefined,
1043
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1044
- set: item.asset.marketCapitalization
1045
- } : undefined,
1046
- ebitda: item.asset.ebitda !== undefined ? {
1047
- set: item.asset.ebitda
1048
- } : undefined,
1049
- peRatio: item.asset.peRatio !== undefined ? {
1050
- set: item.asset.peRatio
1051
- } : undefined,
1052
- pegRatio: item.asset.pegRatio !== undefined ? {
1053
- set: item.asset.pegRatio
1054
- } : undefined,
1055
- bookValue: item.asset.bookValue !== undefined ? {
1056
- set: item.asset.bookValue
1057
- } : undefined,
1058
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1059
- set: item.asset.dividendPerShare
1060
- } : undefined,
1061
- dividendYield: item.asset.dividendYield !== undefined ? {
1062
- set: item.asset.dividendYield
1063
- } : undefined,
1064
- eps: item.asset.eps !== undefined ? {
1065
- set: item.asset.eps
1066
- } : undefined,
1067
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1068
- set: item.asset.revenuePerShareTTM
1069
- } : undefined,
1070
- profitMargin: item.asset.profitMargin !== undefined ? {
1071
- set: item.asset.profitMargin
1072
- } : undefined,
1073
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1074
- set: item.asset.operatingMarginTTM
1075
- } : undefined,
1076
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1077
- set: item.asset.returnOnAssetsTTM
1078
- } : undefined,
1079
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1080
- set: item.asset.returnOnEquityTTM
1081
- } : undefined,
1082
- revenueTTM: item.asset.revenueTTM !== undefined ? {
1083
- set: item.asset.revenueTTM
1084
- } : undefined,
1085
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1086
- set: item.asset.grossProfitTTM
1087
- } : undefined,
1088
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1089
- set: item.asset.dilutedEPSTTM
1090
- } : undefined,
1091
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1092
- set: item.asset.quarterlyEarningsGrowthYOY
1093
- } : undefined,
1094
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1095
- set: item.asset.quarterlyRevenueGrowthYOY
1096
- } : undefined,
1097
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1098
- set: item.asset.analystTargetPrice
1099
- } : undefined,
1100
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1101
- set: item.asset.analystRatingStrongBuy
1102
- } : undefined,
1103
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1104
- set: item.asset.analystRatingBuy
1105
- } : undefined,
1106
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1107
- set: item.asset.analystRatingHold
1108
- } : undefined,
1109
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1110
- set: item.asset.analystRatingSell
1111
- } : undefined,
1112
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1113
- set: item.asset.analystRatingStrongSell
1114
- } : undefined,
1115
- trailingPE: item.asset.trailingPE !== undefined ? {
1116
- set: item.asset.trailingPE
1117
- } : undefined,
1118
- forwardPE: item.asset.forwardPE !== undefined ? {
1119
- set: item.asset.forwardPE
1120
- } : undefined,
1121
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1122
- set: item.asset.priceToSalesRatioTTM
1123
- } : undefined,
1124
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1125
- set: item.asset.priceToBookRatio
1126
- } : undefined,
1127
- evToRevenue: item.asset.evToRevenue !== undefined ? {
1128
- set: item.asset.evToRevenue
1129
- } : undefined,
1130
- evToEbitda: item.asset.evToEbitda !== undefined ? {
1131
- set: item.asset.evToEbitda
1132
- } : undefined,
1133
- beta: item.asset.beta !== undefined ? {
1134
- set: item.asset.beta
1135
- } : undefined,
1136
- week52High: item.asset.week52High !== undefined ? {
1137
- set: item.asset.week52High
1138
- } : undefined,
1139
- week52Low: item.asset.week52Low !== undefined ? {
1140
- set: item.asset.week52Low
1141
- } : undefined,
1142
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1143
- set: item.asset.day50MovingAverage
1144
- } : undefined,
1145
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1146
- set: item.asset.day200MovingAverage
1147
- } : undefined,
1148
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1149
- set: item.asset.sharesOutstanding
1150
- } : undefined,
1151
- dividendDate: item.asset.dividendDate !== undefined ? {
1152
- set: item.asset.dividendDate
1153
- } : undefined,
1154
- exDividendDate: item.asset.exDividendDate !== undefined ? {
1155
- set: item.asset.exDividendDate
1156
- } : undefined,
1157
- askPrice: item.asset.askPrice !== undefined ? {
1158
- set: item.asset.askPrice
1159
- } : undefined,
1160
- bidPrice: item.asset.bidPrice !== undefined ? {
1161
- set: item.asset.bidPrice
1162
- } : undefined,
1163
- },
1164
- create: {
1165
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1166
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1167
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1168
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1169
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1170
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1171
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1172
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1173
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1174
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1175
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1176
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1177
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1178
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1179
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1180
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1181
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1182
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1183
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1184
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1185
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1186
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1187
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1188
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1189
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1190
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1191
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1192
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1193
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1194
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1195
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1196
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1197
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1198
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1199
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1200
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1201
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1202
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1203
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1204
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1205
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1206
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1207
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1208
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1209
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1210
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1211
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1212
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1213
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1214
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1215
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1216
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1217
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1218
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1219
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1220
- },
1221
- }
1222
- } : undefined,
1223
- },
1224
- create: {
1225
- url: item.url !== undefined ? item.url : undefined,
1226
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1227
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1228
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1229
- asset: item.asset ?
1230
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1231
- ? { connect: {
1232
- id: item.asset.id
1233
- }
1234
- }
1235
- : { connectOrCreate: {
1236
- where: {
1237
- id: item.asset.id !== undefined ? item.asset.id : undefined,
1238
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1239
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1240
- },
1241
- create: {
1242
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1243
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1244
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1245
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1246
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1247
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1248
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1249
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1250
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1251
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1252
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1253
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1254
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1255
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1256
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1257
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1258
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1259
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1260
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1261
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1262
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1263
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1264
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1265
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1266
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1267
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1268
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1269
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1270
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1271
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1272
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1273
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1274
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1275
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1276
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1277
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1278
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1279
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1280
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1281
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1282
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1283
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1284
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1285
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1286
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1287
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1288
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1289
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1290
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1291
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1292
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1293
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1294
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1295
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1296
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1297
- },
1298
- }
1299
- } : undefined,
1300
- },
1301
- }))
1302
- } : undefined,
1303
- },
1304
- };
1305
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1306
- try {
1307
- const response = await client.mutate({ mutation: UPSERT_ONE_NEWSARTICLE, variables: filteredVariables });
1308
- if (response.errors && response.errors.length > 0)
1309
- throw new Error(response.errors[0].message);
1310
- if (response && response.data && response.data.upsertOneNewsArticle) {
1311
- return response.data.upsertOneNewsArticle;
1331
+ },
1332
+ create: {
1333
+ url: item.url !== undefined ? item.url : undefined,
1334
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1335
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1336
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1337
+ asset: item.asset ?
1338
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1339
+ ? { connect: {
1340
+ id: item.asset.id
1341
+ }
1342
+ }
1343
+ : { connectOrCreate: {
1344
+ where: {
1345
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1346
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1347
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1348
+ },
1349
+ create: {
1350
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1351
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1352
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1353
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1354
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1355
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1356
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1357
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1358
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1359
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1360
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1361
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1362
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1363
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1364
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1365
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1366
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1367
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1368
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1369
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1370
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1371
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1372
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1373
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1374
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1375
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1376
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1377
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1378
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1379
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1380
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1381
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1382
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1383
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1384
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1385
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1386
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1387
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1388
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1389
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1390
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1391
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1392
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1393
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1394
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1395
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1396
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1397
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1398
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1399
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1400
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1401
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1402
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1403
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1404
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1405
+ },
1406
+ }
1407
+ } : undefined,
1408
+ },
1409
+ }))
1410
+ } : undefined,
1411
+ },
1412
+ };
1413
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1414
+ const response = await client.mutate({
1415
+ mutation: UPSERT_ONE_NEWSARTICLE,
1416
+ variables: filteredVariables,
1417
+ // Don't cache mutations, but ensure we're using the freshest context
1418
+ fetchPolicy: 'no-cache'
1419
+ });
1420
+ if (response.errors && response.errors.length > 0)
1421
+ throw new Error(response.errors[0].message);
1422
+ if (response && response.data && response.data.upsertOneNewsArticle) {
1423
+ return response.data.upsertOneNewsArticle;
1424
+ }
1425
+ else {
1426
+ return null;
1427
+ }
1312
1428
  }
1313
- else {
1314
- return null;
1429
+ catch (error) {
1430
+ lastError = error;
1431
+ // Check if this is a database connection error that we should retry
1432
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
1433
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
1434
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
1435
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
1436
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
1437
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1438
+ retryCount++;
1439
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1440
+ console.warn("Database connection error, retrying...");
1441
+ await new Promise(resolve => setTimeout(resolve, delay));
1442
+ continue;
1443
+ }
1444
+ // Log the error and rethrow
1445
+ console.error("Database error occurred:", error);
1446
+ throw error;
1315
1447
  }
1316
1448
  }
1317
- catch (error) {
1318
- console.error('Error in upsertOneNewsArticle:', error);
1319
- throw error;
1320
- }
1449
+ // If we exhausted retries, throw the last error
1450
+ throw lastError;
1321
1451
  },
1322
1452
  /**
1323
1453
  * Update multiple NewsArticle records.
1454
+ * Enhanced with connection resilience against Prisma connection errors.
1324
1455
  * @param props - Array of NewsArticle objects for the updated records.
1325
1456
  * @param globalClient - Apollo Client instance.
1326
1457
  * @returns The count of created records or null.
1327
1458
  */
1328
1459
  async updateMany(props, globalClient) {
1329
- const [modules, client] = await Promise.all([
1330
- (0, client_1.getApolloModules)(),
1331
- globalClient
1332
- ? Promise.resolve(globalClient)
1333
- : client_1.client
1334
- ]);
1335
- const { gql, ApolloError } = modules;
1336
- const UPDATE_MANY_NEWSARTICLE = gql `
1337
- mutation updateManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
1338
- updateManyNewsArticle(data: $data) {
1339
- count
1340
- }
1341
- }`;
1342
- const variables = props.map(prop => ({
1343
- where: {
1344
- id: prop.id !== undefined ? prop.id : undefined,
1345
- url: prop.url !== undefined ? prop.url : undefined,
1346
- title: prop.title !== undefined ? {
1347
- equals: prop.title
1348
- } : undefined,
1349
- },
1350
- data: {
1351
- id: prop.id !== undefined ? {
1352
- set: prop.id
1353
- } : undefined,
1354
- title: prop.title !== undefined ? {
1355
- set: prop.title
1356
- } : undefined,
1357
- content: prop.content !== undefined ? {
1358
- set: prop.content
1359
- } : undefined,
1360
- source: prop.source !== undefined ? {
1361
- set: prop.source
1362
- } : undefined,
1363
- sourceDomain: prop.sourceDomain !== undefined ? {
1364
- set: prop.sourceDomain
1365
- } : undefined,
1366
- url: prop.url !== undefined ? {
1367
- set: prop.url
1368
- } : undefined,
1369
- sentiment: prop.sentiment !== undefined ? {
1370
- set: prop.sentiment
1371
- } : undefined,
1372
- authors: prop.authors !== undefined ? {
1373
- set: prop.authors
1374
- } : undefined,
1375
- summary: prop.summary !== undefined ? {
1376
- set: prop.summary
1377
- } : undefined,
1378
- bannerImage: prop.bannerImage !== undefined ? {
1379
- set: prop.bannerImage
1380
- } : undefined,
1381
- timePublished: prop.timePublished !== undefined ? {
1382
- set: prop.timePublished
1383
- } : undefined,
1384
- category: prop.category !== undefined ? {
1385
- set: prop.category
1386
- } : undefined,
1387
- topics: prop.topics !== undefined ? {
1388
- set: prop.topics
1389
- } : undefined,
1390
- logo: prop.logo !== undefined ? {
1391
- set: prop.logo
1392
- } : undefined,
1393
- createdAt: prop.createdAt !== undefined ? {
1394
- set: prop.createdAt
1395
- } : undefined,
1396
- updatedAt: prop.updatedAt !== undefined ? {
1397
- set: prop.updatedAt
1398
- } : undefined,
1399
- assets: prop.assets ?
1400
- Array.isArray(prop.assets) && prop.assets.length > 0 && prop.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1401
- connect: prop.assets.map((item) => ({
1402
- id: item.id
1403
- }))
1404
- } : { upsert: prop.assets.map((item) => ({
1405
- where: {
1406
- id: item.id !== undefined ? item.id : undefined,
1407
- url: item.url !== undefined ? item.url : undefined,
1408
- assetId: item.assetId !== undefined ? {
1409
- equals: item.assetId
1410
- } : undefined,
1411
- newsArticleId: item.newsArticleId !== undefined ? {
1412
- equals: item.newsArticleId
1413
- } : undefined,
1414
- },
1415
- update: {
1416
- id: item.id !== undefined ? {
1417
- set: item.id
1418
- } : undefined,
1419
- url: item.url !== undefined ? {
1420
- set: item.url
1421
- } : undefined,
1422
- relevancyScore: item.relevancyScore !== undefined ? {
1423
- set: item.relevancyScore
1424
- } : undefined,
1425
- sentimentScore: item.sentimentScore !== undefined ? {
1426
- set: item.sentimentScore
1427
- } : undefined,
1428
- sentimentLabel: item.sentimentLabel !== undefined ? {
1429
- set: item.sentimentLabel
1430
- } : undefined,
1431
- asset: item.asset ?
1432
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1433
- ? {
1434
- connect: {
1435
- id: item.asset.id
1436
- }
1437
- } : { upsert: {
1438
- where: {
1439
- id: item.asset.id !== undefined ? {
1440
- equals: item.asset.id
1441
- } : undefined,
1442
- symbol: item.asset.symbol !== undefined ? {
1443
- equals: item.asset.symbol
1444
- } : undefined,
1445
- name: item.asset.name !== undefined ? {
1446
- equals: item.asset.name
1447
- } : undefined,
1448
- },
1449
- update: {
1450
- id: item.asset.id !== undefined ? {
1451
- set: item.asset.id
1452
- } : undefined,
1453
- symbol: item.asset.symbol !== undefined ? {
1454
- set: item.asset.symbol
1455
- } : undefined,
1456
- name: item.asset.name !== undefined ? {
1457
- set: item.asset.name
1458
- } : undefined,
1459
- type: item.asset.type !== undefined ? {
1460
- set: item.asset.type
1461
- } : undefined,
1462
- logoUrl: item.asset.logoUrl !== undefined ? {
1463
- set: item.asset.logoUrl
1464
- } : undefined,
1465
- description: item.asset.description !== undefined ? {
1466
- set: item.asset.description
1467
- } : undefined,
1468
- cik: item.asset.cik !== undefined ? {
1469
- set: item.asset.cik
1470
- } : undefined,
1471
- exchange: item.asset.exchange !== undefined ? {
1472
- set: item.asset.exchange
1473
- } : undefined,
1474
- currency: item.asset.currency !== undefined ? {
1475
- set: item.asset.currency
1476
- } : undefined,
1477
- country: item.asset.country !== undefined ? {
1478
- set: item.asset.country
1479
- } : undefined,
1480
- sector: item.asset.sector !== undefined ? {
1481
- set: item.asset.sector
1482
- } : undefined,
1483
- industry: item.asset.industry !== undefined ? {
1484
- set: item.asset.industry
1485
- } : undefined,
1486
- address: item.asset.address !== undefined ? {
1487
- set: item.asset.address
1488
- } : undefined,
1489
- officialSite: item.asset.officialSite !== undefined ? {
1490
- set: item.asset.officialSite
1491
- } : undefined,
1492
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1493
- set: item.asset.fiscalYearEnd
1494
- } : undefined,
1495
- latestQuarter: item.asset.latestQuarter !== undefined ? {
1496
- set: item.asset.latestQuarter
1497
- } : undefined,
1498
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1499
- set: item.asset.marketCapitalization
1500
- } : undefined,
1501
- ebitda: item.asset.ebitda !== undefined ? {
1502
- set: item.asset.ebitda
1503
- } : undefined,
1504
- peRatio: item.asset.peRatio !== undefined ? {
1505
- set: item.asset.peRatio
1506
- } : undefined,
1507
- pegRatio: item.asset.pegRatio !== undefined ? {
1508
- set: item.asset.pegRatio
1509
- } : undefined,
1510
- bookValue: item.asset.bookValue !== undefined ? {
1511
- set: item.asset.bookValue
1512
- } : undefined,
1513
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1514
- set: item.asset.dividendPerShare
1515
- } : undefined,
1516
- dividendYield: item.asset.dividendYield !== undefined ? {
1517
- set: item.asset.dividendYield
1518
- } : undefined,
1519
- eps: item.asset.eps !== undefined ? {
1520
- set: item.asset.eps
1521
- } : undefined,
1522
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1523
- set: item.asset.revenuePerShareTTM
1524
- } : undefined,
1525
- profitMargin: item.asset.profitMargin !== undefined ? {
1526
- set: item.asset.profitMargin
1527
- } : undefined,
1528
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1529
- set: item.asset.operatingMarginTTM
1530
- } : undefined,
1531
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1532
- set: item.asset.returnOnAssetsTTM
1533
- } : undefined,
1534
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1535
- set: item.asset.returnOnEquityTTM
1536
- } : undefined,
1537
- revenueTTM: item.asset.revenueTTM !== undefined ? {
1538
- set: item.asset.revenueTTM
1539
- } : undefined,
1540
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1541
- set: item.asset.grossProfitTTM
1542
- } : undefined,
1543
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1544
- set: item.asset.dilutedEPSTTM
1545
- } : undefined,
1546
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1547
- set: item.asset.quarterlyEarningsGrowthYOY
1548
- } : undefined,
1549
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1550
- set: item.asset.quarterlyRevenueGrowthYOY
1551
- } : undefined,
1552
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1553
- set: item.asset.analystTargetPrice
1554
- } : undefined,
1555
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1556
- set: item.asset.analystRatingStrongBuy
1557
- } : undefined,
1558
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1559
- set: item.asset.analystRatingBuy
1560
- } : undefined,
1561
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1562
- set: item.asset.analystRatingHold
1563
- } : undefined,
1564
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1565
- set: item.asset.analystRatingSell
1566
- } : undefined,
1567
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1568
- set: item.asset.analystRatingStrongSell
1569
- } : undefined,
1570
- trailingPE: item.asset.trailingPE !== undefined ? {
1571
- set: item.asset.trailingPE
1572
- } : undefined,
1573
- forwardPE: item.asset.forwardPE !== undefined ? {
1574
- set: item.asset.forwardPE
1575
- } : undefined,
1576
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1577
- set: item.asset.priceToSalesRatioTTM
1578
- } : undefined,
1579
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1580
- set: item.asset.priceToBookRatio
1581
- } : undefined,
1582
- evToRevenue: item.asset.evToRevenue !== undefined ? {
1583
- set: item.asset.evToRevenue
1584
- } : undefined,
1585
- evToEbitda: item.asset.evToEbitda !== undefined ? {
1586
- set: item.asset.evToEbitda
1587
- } : undefined,
1588
- beta: item.asset.beta !== undefined ? {
1589
- set: item.asset.beta
1590
- } : undefined,
1591
- week52High: item.asset.week52High !== undefined ? {
1592
- set: item.asset.week52High
1593
- } : undefined,
1594
- week52Low: item.asset.week52Low !== undefined ? {
1595
- set: item.asset.week52Low
1596
- } : undefined,
1597
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1598
- set: item.asset.day50MovingAverage
1599
- } : undefined,
1600
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1601
- set: item.asset.day200MovingAverage
1602
- } : undefined,
1603
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1604
- set: item.asset.sharesOutstanding
1605
- } : undefined,
1606
- dividendDate: item.asset.dividendDate !== undefined ? {
1607
- set: item.asset.dividendDate
1608
- } : undefined,
1609
- exDividendDate: item.asset.exDividendDate !== undefined ? {
1610
- set: item.asset.exDividendDate
1611
- } : undefined,
1612
- askPrice: item.asset.askPrice !== undefined ? {
1613
- set: item.asset.askPrice
1614
- } : undefined,
1615
- bidPrice: item.asset.bidPrice !== undefined ? {
1616
- set: item.asset.bidPrice
1617
- } : undefined,
1618
- },
1619
- create: {
1620
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1621
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1622
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1623
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1624
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1625
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1626
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1627
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1628
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1629
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1630
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1631
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1632
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1633
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1634
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1635
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1636
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1637
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1638
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1639
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1640
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1641
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1642
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1643
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1644
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1645
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1646
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1647
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1648
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1649
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1650
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1651
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1652
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1653
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1654
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1655
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1656
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1657
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1658
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1659
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1660
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1661
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1662
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1663
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1664
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1665
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1666
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1667
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1668
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1669
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1670
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1671
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1672
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1673
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1674
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1675
- },
1676
- }
1677
- } : undefined,
1678
- },
1679
- create: {
1680
- url: item.url !== undefined ? item.url : undefined,
1681
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1682
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1683
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1684
- asset: item.asset ?
1685
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1686
- ? { connect: {
1687
- id: item.asset.id
1688
- }
1689
- }
1690
- : { connectOrCreate: {
1691
- where: {
1692
- id: item.asset.id !== undefined ? item.asset.id : undefined,
1693
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1694
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1695
- },
1696
- create: {
1697
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1698
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1699
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1700
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1701
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1702
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1703
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1704
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1705
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1706
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1707
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1708
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1709
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1710
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1711
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1712
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1713
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1714
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1715
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1716
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1717
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1718
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1719
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1720
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1721
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1722
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1723
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1724
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1725
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1726
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1727
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1728
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1729
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1730
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1731
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1732
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1733
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1734
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1735
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1736
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1737
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1738
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1739
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1740
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1741
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1742
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1743
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1744
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1745
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1746
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1747
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1748
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1749
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1750
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1751
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1752
- },
1753
- }
1460
+ var _a, _b, _c, _d, _e;
1461
+ // Maximum number of retries for database connection issues
1462
+ const MAX_RETRIES = 3;
1463
+ let retryCount = 0;
1464
+ let lastError = null;
1465
+ // Retry loop to handle potential database connection issues
1466
+ while (retryCount < MAX_RETRIES) {
1467
+ try {
1468
+ const [modules, client] = await Promise.all([
1469
+ (0, client_1.getApolloModules)(),
1470
+ globalClient
1471
+ ? Promise.resolve(globalClient)
1472
+ : client_1.client
1473
+ ]);
1474
+ const { gql, ApolloError } = modules;
1475
+ const UPDATE_MANY_NEWSARTICLE = gql `
1476
+ mutation updateManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
1477
+ updateManyNewsArticle(data: $data) {
1478
+ count
1479
+ }
1480
+ }`;
1481
+ const variables = props.map(prop => ({
1482
+ where: {
1483
+ id: prop.id !== undefined ? prop.id : undefined,
1484
+ url: prop.url !== undefined ? prop.url : undefined,
1485
+ title: prop.title !== undefined ? {
1486
+ equals: prop.title
1487
+ } : undefined,
1488
+ },
1489
+ data: {
1490
+ id: prop.id !== undefined ? {
1491
+ set: prop.id
1492
+ } : undefined,
1493
+ title: prop.title !== undefined ? {
1494
+ set: prop.title
1495
+ } : undefined,
1496
+ content: prop.content !== undefined ? {
1497
+ set: prop.content
1498
+ } : undefined,
1499
+ source: prop.source !== undefined ? {
1500
+ set: prop.source
1501
+ } : undefined,
1502
+ sourceDomain: prop.sourceDomain !== undefined ? {
1503
+ set: prop.sourceDomain
1504
+ } : undefined,
1505
+ url: prop.url !== undefined ? {
1506
+ set: prop.url
1507
+ } : undefined,
1508
+ sentiment: prop.sentiment !== undefined ? {
1509
+ set: prop.sentiment
1510
+ } : undefined,
1511
+ authors: prop.authors !== undefined ? {
1512
+ set: prop.authors
1513
+ } : undefined,
1514
+ summary: prop.summary !== undefined ? {
1515
+ set: prop.summary
1516
+ } : undefined,
1517
+ bannerImage: prop.bannerImage !== undefined ? {
1518
+ set: prop.bannerImage
1519
+ } : undefined,
1520
+ timePublished: prop.timePublished !== undefined ? {
1521
+ set: prop.timePublished
1522
+ } : undefined,
1523
+ category: prop.category !== undefined ? {
1524
+ set: prop.category
1525
+ } : undefined,
1526
+ topics: prop.topics !== undefined ? {
1527
+ set: prop.topics
1528
+ } : undefined,
1529
+ logo: prop.logo !== undefined ? {
1530
+ set: prop.logo
1531
+ } : undefined,
1532
+ createdAt: prop.createdAt !== undefined ? {
1533
+ set: prop.createdAt
1534
+ } : undefined,
1535
+ updatedAt: prop.updatedAt !== undefined ? {
1536
+ set: prop.updatedAt
1537
+ } : undefined,
1538
+ assets: prop.assets ?
1539
+ Array.isArray(prop.assets) && prop.assets.length > 0 && prop.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1540
+ connect: prop.assets.map((item) => ({
1541
+ id: item.id
1542
+ }))
1543
+ } : { upsert: prop.assets.map((item) => ({
1544
+ where: {
1545
+ id: item.id !== undefined ? item.id : undefined,
1546
+ url: item.url !== undefined ? item.url : undefined,
1547
+ assetId: item.assetId !== undefined ? {
1548
+ equals: item.assetId
1549
+ } : undefined,
1550
+ newsArticleId: item.newsArticleId !== undefined ? {
1551
+ equals: item.newsArticleId
1754
1552
  } : undefined,
1755
- },
1756
- }))
1757
- } : undefined,
1758
- },
1759
- }));
1760
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1761
- try {
1762
- const response = await client.mutate({ mutation: UPDATE_MANY_NEWSARTICLE, variables: filteredVariables });
1763
- if (response.errors && response.errors.length > 0)
1764
- throw new Error(response.errors[0].message);
1765
- if (response && response.data && response.data.updateManyNewsArticle) {
1766
- return response.data.updateManyNewsArticle;
1553
+ },
1554
+ update: {
1555
+ id: item.id !== undefined ? {
1556
+ set: item.id
1557
+ } : undefined,
1558
+ url: item.url !== undefined ? {
1559
+ set: item.url
1560
+ } : undefined,
1561
+ relevancyScore: item.relevancyScore !== undefined ? {
1562
+ set: item.relevancyScore
1563
+ } : undefined,
1564
+ sentimentScore: item.sentimentScore !== undefined ? {
1565
+ set: item.sentimentScore
1566
+ } : undefined,
1567
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1568
+ set: item.sentimentLabel
1569
+ } : undefined,
1570
+ asset: item.asset ?
1571
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1572
+ ? {
1573
+ connect: {
1574
+ id: item.asset.id
1575
+ }
1576
+ } : { upsert: {
1577
+ where: {
1578
+ id: item.asset.id !== undefined ? {
1579
+ equals: item.asset.id
1580
+ } : undefined,
1581
+ symbol: item.asset.symbol !== undefined ? {
1582
+ equals: item.asset.symbol
1583
+ } : undefined,
1584
+ name: item.asset.name !== undefined ? {
1585
+ equals: item.asset.name
1586
+ } : undefined,
1587
+ },
1588
+ update: {
1589
+ id: item.asset.id !== undefined ? {
1590
+ set: item.asset.id
1591
+ } : undefined,
1592
+ symbol: item.asset.symbol !== undefined ? {
1593
+ set: item.asset.symbol
1594
+ } : undefined,
1595
+ name: item.asset.name !== undefined ? {
1596
+ set: item.asset.name
1597
+ } : undefined,
1598
+ type: item.asset.type !== undefined ? {
1599
+ set: item.asset.type
1600
+ } : undefined,
1601
+ logoUrl: item.asset.logoUrl !== undefined ? {
1602
+ set: item.asset.logoUrl
1603
+ } : undefined,
1604
+ description: item.asset.description !== undefined ? {
1605
+ set: item.asset.description
1606
+ } : undefined,
1607
+ cik: item.asset.cik !== undefined ? {
1608
+ set: item.asset.cik
1609
+ } : undefined,
1610
+ exchange: item.asset.exchange !== undefined ? {
1611
+ set: item.asset.exchange
1612
+ } : undefined,
1613
+ currency: item.asset.currency !== undefined ? {
1614
+ set: item.asset.currency
1615
+ } : undefined,
1616
+ country: item.asset.country !== undefined ? {
1617
+ set: item.asset.country
1618
+ } : undefined,
1619
+ sector: item.asset.sector !== undefined ? {
1620
+ set: item.asset.sector
1621
+ } : undefined,
1622
+ industry: item.asset.industry !== undefined ? {
1623
+ set: item.asset.industry
1624
+ } : undefined,
1625
+ address: item.asset.address !== undefined ? {
1626
+ set: item.asset.address
1627
+ } : undefined,
1628
+ officialSite: item.asset.officialSite !== undefined ? {
1629
+ set: item.asset.officialSite
1630
+ } : undefined,
1631
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1632
+ set: item.asset.fiscalYearEnd
1633
+ } : undefined,
1634
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1635
+ set: item.asset.latestQuarter
1636
+ } : undefined,
1637
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1638
+ set: item.asset.marketCapitalization
1639
+ } : undefined,
1640
+ ebitda: item.asset.ebitda !== undefined ? {
1641
+ set: item.asset.ebitda
1642
+ } : undefined,
1643
+ peRatio: item.asset.peRatio !== undefined ? {
1644
+ set: item.asset.peRatio
1645
+ } : undefined,
1646
+ pegRatio: item.asset.pegRatio !== undefined ? {
1647
+ set: item.asset.pegRatio
1648
+ } : undefined,
1649
+ bookValue: item.asset.bookValue !== undefined ? {
1650
+ set: item.asset.bookValue
1651
+ } : undefined,
1652
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1653
+ set: item.asset.dividendPerShare
1654
+ } : undefined,
1655
+ dividendYield: item.asset.dividendYield !== undefined ? {
1656
+ set: item.asset.dividendYield
1657
+ } : undefined,
1658
+ eps: item.asset.eps !== undefined ? {
1659
+ set: item.asset.eps
1660
+ } : undefined,
1661
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1662
+ set: item.asset.revenuePerShareTTM
1663
+ } : undefined,
1664
+ profitMargin: item.asset.profitMargin !== undefined ? {
1665
+ set: item.asset.profitMargin
1666
+ } : undefined,
1667
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1668
+ set: item.asset.operatingMarginTTM
1669
+ } : undefined,
1670
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1671
+ set: item.asset.returnOnAssetsTTM
1672
+ } : undefined,
1673
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1674
+ set: item.asset.returnOnEquityTTM
1675
+ } : undefined,
1676
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1677
+ set: item.asset.revenueTTM
1678
+ } : undefined,
1679
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1680
+ set: item.asset.grossProfitTTM
1681
+ } : undefined,
1682
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1683
+ set: item.asset.dilutedEPSTTM
1684
+ } : undefined,
1685
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1686
+ set: item.asset.quarterlyEarningsGrowthYOY
1687
+ } : undefined,
1688
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1689
+ set: item.asset.quarterlyRevenueGrowthYOY
1690
+ } : undefined,
1691
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1692
+ set: item.asset.analystTargetPrice
1693
+ } : undefined,
1694
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1695
+ set: item.asset.analystRatingStrongBuy
1696
+ } : undefined,
1697
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1698
+ set: item.asset.analystRatingBuy
1699
+ } : undefined,
1700
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1701
+ set: item.asset.analystRatingHold
1702
+ } : undefined,
1703
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1704
+ set: item.asset.analystRatingSell
1705
+ } : undefined,
1706
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1707
+ set: item.asset.analystRatingStrongSell
1708
+ } : undefined,
1709
+ trailingPE: item.asset.trailingPE !== undefined ? {
1710
+ set: item.asset.trailingPE
1711
+ } : undefined,
1712
+ forwardPE: item.asset.forwardPE !== undefined ? {
1713
+ set: item.asset.forwardPE
1714
+ } : undefined,
1715
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1716
+ set: item.asset.priceToSalesRatioTTM
1717
+ } : undefined,
1718
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1719
+ set: item.asset.priceToBookRatio
1720
+ } : undefined,
1721
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1722
+ set: item.asset.evToRevenue
1723
+ } : undefined,
1724
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1725
+ set: item.asset.evToEbitda
1726
+ } : undefined,
1727
+ beta: item.asset.beta !== undefined ? {
1728
+ set: item.asset.beta
1729
+ } : undefined,
1730
+ week52High: item.asset.week52High !== undefined ? {
1731
+ set: item.asset.week52High
1732
+ } : undefined,
1733
+ week52Low: item.asset.week52Low !== undefined ? {
1734
+ set: item.asset.week52Low
1735
+ } : undefined,
1736
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1737
+ set: item.asset.day50MovingAverage
1738
+ } : undefined,
1739
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1740
+ set: item.asset.day200MovingAverage
1741
+ } : undefined,
1742
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1743
+ set: item.asset.sharesOutstanding
1744
+ } : undefined,
1745
+ dividendDate: item.asset.dividendDate !== undefined ? {
1746
+ set: item.asset.dividendDate
1747
+ } : undefined,
1748
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1749
+ set: item.asset.exDividendDate
1750
+ } : undefined,
1751
+ askPrice: item.asset.askPrice !== undefined ? {
1752
+ set: item.asset.askPrice
1753
+ } : undefined,
1754
+ bidPrice: item.asset.bidPrice !== undefined ? {
1755
+ set: item.asset.bidPrice
1756
+ } : undefined,
1757
+ },
1758
+ create: {
1759
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1760
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1761
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1762
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1763
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1764
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1765
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1766
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1767
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1768
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1769
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1770
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1771
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1772
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1773
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1774
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1775
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1776
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1777
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1778
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1779
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1780
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1781
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1782
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1783
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1784
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1785
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1786
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1787
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1788
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1789
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1790
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1791
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1792
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1793
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1794
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1795
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1796
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1797
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1798
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1799
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1800
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1801
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1802
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1803
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1804
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1805
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1806
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1807
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1808
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1809
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1810
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1811
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1812
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1813
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1814
+ },
1815
+ }
1816
+ } : undefined,
1817
+ },
1818
+ create: {
1819
+ url: item.url !== undefined ? item.url : undefined,
1820
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1821
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1822
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1823
+ asset: item.asset ?
1824
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1825
+ ? { connect: {
1826
+ id: item.asset.id
1827
+ }
1828
+ }
1829
+ : { connectOrCreate: {
1830
+ where: {
1831
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1832
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1833
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1834
+ },
1835
+ create: {
1836
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1837
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1838
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1839
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1840
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1841
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1842
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1843
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1844
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1845
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1846
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1847
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1848
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1849
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1850
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1851
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1852
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1853
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1854
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1855
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1856
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1857
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1858
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1859
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1860
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1861
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1862
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1863
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1864
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1865
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1866
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1867
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1868
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1869
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1870
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1871
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1872
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1873
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1874
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1875
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1876
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1877
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1878
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1879
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1880
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1881
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1882
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1883
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1884
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1885
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1886
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1887
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1888
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1889
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1890
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1891
+ },
1892
+ }
1893
+ } : undefined,
1894
+ },
1895
+ }))
1896
+ } : undefined,
1897
+ },
1898
+ }));
1899
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1900
+ const response = await client.mutate({
1901
+ mutation: UPDATE_MANY_NEWSARTICLE,
1902
+ variables: filteredVariables,
1903
+ // Don't cache mutations, but ensure we're using the freshest context
1904
+ fetchPolicy: 'no-cache'
1905
+ });
1906
+ if (response.errors && response.errors.length > 0)
1907
+ throw new Error(response.errors[0].message);
1908
+ if (response && response.data && response.data.updateManyNewsArticle) {
1909
+ return response.data.updateManyNewsArticle;
1910
+ }
1911
+ else {
1912
+ return null;
1913
+ }
1767
1914
  }
1768
- else {
1769
- return null;
1915
+ catch (error) {
1916
+ lastError = error;
1917
+ // Check if this is a database connection error that we should retry
1918
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
1919
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
1920
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
1921
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
1922
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
1923
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1924
+ retryCount++;
1925
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1926
+ console.warn("Database connection error, retrying...");
1927
+ await new Promise(resolve => setTimeout(resolve, delay));
1928
+ continue;
1929
+ }
1930
+ // Log the error and rethrow
1931
+ console.error("Database error occurred:", error);
1932
+ throw error;
1770
1933
  }
1771
1934
  }
1772
- catch (error) {
1773
- console.error('Error in updateManyNewsArticle:', error);
1774
- throw error;
1775
- }
1935
+ // If we exhausted retries, throw the last error
1936
+ throw lastError;
1776
1937
  },
1777
1938
  /**
1778
1939
  * Delete a single NewsArticle record.
1779
- * @param props - Properties to update.
1940
+ * Enhanced with connection resilience against Prisma connection errors.
1941
+ * @param props - Properties to identify the record to delete.
1780
1942
  * @param globalClient - Apollo Client instance.
1781
1943
  * @returns The deleted NewsArticle or null.
1782
1944
  */
1783
1945
  async delete(props, globalClient) {
1784
- const [modules, client] = await Promise.all([
1785
- (0, client_1.getApolloModules)(),
1786
- globalClient
1787
- ? Promise.resolve(globalClient)
1788
- : client_1.client
1789
- ]);
1790
- const { gql, ApolloError } = modules;
1791
- const DELETE_ONE_NEWSARTICLE = gql `
1792
- mutation deleteOneNewsArticle($where: NewsArticleWhereUniqueInput!) {
1793
- deleteOneNewsArticle(where: $where) {
1794
- id
1795
- }
1796
- }`;
1797
- const variables = {
1798
- where: {
1799
- id: props.id ? props.id : undefined,
1946
+ var _a, _b, _c, _d, _e;
1947
+ // Maximum number of retries for database connection issues
1948
+ const MAX_RETRIES = 3;
1949
+ let retryCount = 0;
1950
+ let lastError = null;
1951
+ // Retry loop to handle potential database connection issues
1952
+ while (retryCount < MAX_RETRIES) {
1953
+ try {
1954
+ const [modules, client] = await Promise.all([
1955
+ (0, client_1.getApolloModules)(),
1956
+ globalClient
1957
+ ? Promise.resolve(globalClient)
1958
+ : client_1.client
1959
+ ]);
1960
+ const { gql, ApolloError } = modules;
1961
+ const DELETE_ONE_NEWSARTICLE = gql `
1962
+ mutation deleteOneNewsArticle($where: NewsArticleWhereUniqueInput!) {
1963
+ deleteOneNewsArticle(where: $where) {
1964
+ id
1800
1965
  }
1801
- };
1802
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1803
- try {
1804
- const response = await client.mutate({ mutation: DELETE_ONE_NEWSARTICLE, variables: filteredVariables });
1805
- if (response.errors && response.errors.length > 0)
1806
- throw new Error(response.errors[0].message);
1807
- if (response && response.data && response.data.deleteOneNewsArticle) {
1808
- return response.data.deleteOneNewsArticle;
1966
+ }`;
1967
+ const variables = {
1968
+ where: {
1969
+ id: props.id ? props.id : undefined,
1970
+ }
1971
+ };
1972
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1973
+ const response = await client.mutate({
1974
+ mutation: DELETE_ONE_NEWSARTICLE,
1975
+ variables: filteredVariables,
1976
+ // Don't cache mutations, but ensure we're using the freshest context
1977
+ fetchPolicy: 'no-cache'
1978
+ });
1979
+ if (response.errors && response.errors.length > 0)
1980
+ throw new Error(response.errors[0].message);
1981
+ if (response && response.data && response.data.deleteOneNewsArticle) {
1982
+ return response.data.deleteOneNewsArticle;
1983
+ }
1984
+ else {
1985
+ return null;
1986
+ }
1809
1987
  }
1810
- else {
1811
- return null;
1988
+ catch (error) {
1989
+ lastError = error;
1990
+ // Check if this is a database connection error that we should retry
1991
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
1992
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
1993
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
1994
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
1995
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
1996
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1997
+ retryCount++;
1998
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1999
+ console.warn("Database connection error, retrying...");
2000
+ await new Promise(resolve => setTimeout(resolve, delay));
2001
+ continue;
2002
+ }
2003
+ // Log the error and rethrow
2004
+ console.error("Database error occurred:", error);
2005
+ throw error;
1812
2006
  }
1813
2007
  }
1814
- catch (error) {
1815
- console.error('Error in deleteOneNewsArticle:', error);
1816
- throw error;
1817
- }
2008
+ // If we exhausted retries, throw the last error
2009
+ throw lastError;
1818
2010
  },
1819
2011
  /**
1820
2012
  * Retrieve a single NewsArticle record by ID.
1821
- * @param props - Properties to update.
2013
+ * Enhanced with connection resilience against Prisma connection errors.
2014
+ * @param props - Properties to identify the record.
1822
2015
  * @param globalClient - Apollo Client instance.
2016
+ * @param whereInput - Optional custom where input.
1823
2017
  * @returns The retrieved NewsArticle or null.
1824
2018
  */
1825
2019
  async get(props, globalClient, whereInput) {
1826
- var _a, _b;
1827
- const [modules, client] = await Promise.all([
1828
- (0, client_1.getApolloModules)(),
1829
- globalClient
1830
- ? Promise.resolve(globalClient)
1831
- : client_1.client
1832
- ]);
1833
- const { gql, ApolloError } = modules;
1834
- const GET_NEWSARTICLE = gql `
1835
- query getNewsArticle($where: NewsArticleWhereUniqueInput!) {
1836
- getNewsArticle(where: $where) {
1837
- ${selectionSet}
1838
- }
1839
- }`;
1840
- const variables = {
1841
- where: whereInput ? whereInput : {
1842
- id: props.id !== undefined ? props.id : undefined,
1843
- url: props.url !== undefined ? props.url : undefined,
1844
- title: props.title !== undefined ? {
1845
- equals: props.title
1846
- } : undefined,
1847
- },
1848
- };
1849
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1850
- try {
1851
- const response = await client.query({ query: GET_NEWSARTICLE, variables: filteredVariables });
1852
- if (response.errors && response.errors.length > 0)
1853
- throw new Error(response.errors[0].message);
1854
- return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getNewsArticle) !== null && _b !== void 0 ? _b : null;
1855
- }
1856
- catch (error) {
1857
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1858
- return null;
2020
+ var _a, _b, _c, _d, _e, _f, _g;
2021
+ // Maximum number of retries for database connection issues
2022
+ const MAX_RETRIES = 3;
2023
+ let retryCount = 0;
2024
+ let lastError = null;
2025
+ // Retry loop to handle potential database connection issues
2026
+ while (retryCount < MAX_RETRIES) {
2027
+ try {
2028
+ const [modules, client] = await Promise.all([
2029
+ (0, client_1.getApolloModules)(),
2030
+ globalClient
2031
+ ? Promise.resolve(globalClient)
2032
+ : client_1.client
2033
+ ]);
2034
+ const { gql, ApolloError } = modules;
2035
+ const GET_NEWSARTICLE = gql `
2036
+ query getNewsArticle($where: NewsArticleWhereUniqueInput!) {
2037
+ getNewsArticle(where: $where) {
2038
+ ${selectionSet}
2039
+ }
2040
+ }`;
2041
+ const variables = {
2042
+ where: whereInput ? whereInput : {
2043
+ id: props.id !== undefined ? props.id : undefined,
2044
+ url: props.url !== undefined ? props.url : undefined,
2045
+ title: props.title !== undefined ? {
2046
+ equals: props.title
2047
+ } : undefined,
2048
+ },
2049
+ };
2050
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
2051
+ const response = await client.query({
2052
+ query: GET_NEWSARTICLE,
2053
+ variables: filteredVariables,
2054
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2055
+ });
2056
+ if (response.errors && response.errors.length > 0)
2057
+ throw new Error(response.errors[0].message);
2058
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getNewsArticle) !== null && _b !== void 0 ? _b : null;
1859
2059
  }
1860
- else {
1861
- console.error('Error in getNewsArticle:', error);
2060
+ catch (error) {
2061
+ lastError = error;
2062
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2063
+ if (error.message === 'No NewsArticle found') {
2064
+ return null;
2065
+ }
2066
+ // Check if this is a database connection error that we should retry
2067
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
2068
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
2069
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
2070
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
2071
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
2072
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2073
+ retryCount++;
2074
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2075
+ console.warn("Database connection error, retrying...");
2076
+ await new Promise(resolve => setTimeout(resolve, delay));
2077
+ continue;
2078
+ }
2079
+ // Log the error and rethrow
2080
+ console.error("Database error occurred:", error);
1862
2081
  throw error;
1863
2082
  }
1864
2083
  }
2084
+ // If we exhausted retries, throw the last error
2085
+ throw lastError;
1865
2086
  },
1866
2087
  /**
1867
2088
  * Retrieve all NewsArticles records.
2089
+ * Enhanced with connection resilience against Prisma connection errors.
1868
2090
  * @param globalClient - Apollo Client instance.
1869
2091
  * @returns An array of NewsArticle records or null.
1870
2092
  */
1871
2093
  async getAll(globalClient) {
1872
- var _a, _b;
1873
- const [modules, client] = await Promise.all([
1874
- (0, client_1.getApolloModules)(),
1875
- globalClient
1876
- ? Promise.resolve(globalClient)
1877
- : client_1.client
1878
- ]);
1879
- const { gql, ApolloError } = modules;
1880
- const GET_ALL_NEWSARTICLE = gql `
1881
- query getAllNewsArticle {
1882
- newsArticles {
1883
- ${selectionSet}
1884
- }
1885
- }`;
1886
- try {
1887
- const response = await client.query({ query: GET_ALL_NEWSARTICLE });
1888
- if (response.errors && response.errors.length > 0)
1889
- throw new Error(response.errors[0].message);
1890
- return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.newsArticles) !== null && _b !== void 0 ? _b : null;
1891
- }
1892
- catch (error) {
1893
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1894
- return null;
2094
+ var _a, _b, _c, _d, _e, _f, _g;
2095
+ // Maximum number of retries for database connection issues
2096
+ const MAX_RETRIES = 3;
2097
+ let retryCount = 0;
2098
+ let lastError = null;
2099
+ // Retry loop to handle potential database connection issues
2100
+ while (retryCount < MAX_RETRIES) {
2101
+ try {
2102
+ const [modules, client] = await Promise.all([
2103
+ (0, client_1.getApolloModules)(),
2104
+ globalClient
2105
+ ? Promise.resolve(globalClient)
2106
+ : client_1.client
2107
+ ]);
2108
+ const { gql, ApolloError } = modules;
2109
+ const GET_ALL_NEWSARTICLE = gql `
2110
+ query getAllNewsArticle {
2111
+ newsArticles {
2112
+ ${selectionSet}
2113
+ }
2114
+ }`;
2115
+ const response = await client.query({
2116
+ query: GET_ALL_NEWSARTICLE,
2117
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2118
+ });
2119
+ if (response.errors && response.errors.length > 0)
2120
+ throw new Error(response.errors[0].message);
2121
+ return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.newsArticles) !== null && _b !== void 0 ? _b : null;
1895
2122
  }
1896
- else {
1897
- console.error('Error in getNewsArticle:', error);
2123
+ catch (error) {
2124
+ lastError = error;
2125
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2126
+ if (error.message === 'No NewsArticle found') {
2127
+ return null;
2128
+ }
2129
+ // Check if this is a database connection error that we should retry
2130
+ const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
2131
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
2132
+ ((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
2133
+ ((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
2134
+ (error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
2135
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2136
+ retryCount++;
2137
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2138
+ console.warn("Database connection error, retrying...");
2139
+ await new Promise(resolve => setTimeout(resolve, delay));
2140
+ continue;
2141
+ }
2142
+ // Log the error and rethrow
2143
+ console.error("Database error occurred:", error);
1898
2144
  throw error;
1899
2145
  }
1900
2146
  }
2147
+ // If we exhausted retries, throw the last error
2148
+ throw lastError;
1901
2149
  },
1902
2150
  /**
1903
2151
  * Find multiple NewsArticle records based on conditions.
2152
+ * Enhanced with connection resilience against Prisma connection errors.
1904
2153
  * @param props - Conditions to find records.
1905
2154
  * @param globalClient - Apollo Client instance.
2155
+ * @param whereInput - Optional custom where input.
1906
2156
  * @returns An array of found NewsArticle records or null.
1907
2157
  */
1908
2158
  async findMany(props, globalClient, whereInput) {
1909
- const [modules, client] = await Promise.all([
1910
- (0, client_1.getApolloModules)(),
1911
- globalClient
1912
- ? Promise.resolve(globalClient)
1913
- : client_1.client
1914
- ]);
1915
- const { gql, ApolloError } = modules;
1916
- const FIND_MANY_NEWSARTICLE = gql `
1917
- query findManyNewsArticle($where: NewsArticleWhereInput!) {
1918
- newsArticles(where: $where) {
1919
- ${selectionSet}
1920
- }
1921
- }`;
1922
- const variables = {
1923
- where: whereInput ? whereInput : {
1924
- id: props.id !== undefined ? {
1925
- equals: props.id
1926
- } : undefined,
1927
- title: props.title !== undefined ? {
1928
- equals: props.title
1929
- } : undefined,
1930
- url: props.url !== undefined ? {
1931
- equals: props.url
1932
- } : undefined,
1933
- },
1934
- };
1935
- const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
1936
- try {
1937
- const response = await client.query({ query: FIND_MANY_NEWSARTICLE, variables: filteredVariables });
1938
- if (response.errors && response.errors.length > 0)
1939
- throw new Error(response.errors[0].message);
1940
- if (response && response.data && response.data.newsarticles) {
1941
- return response.data.newsArticles;
1942
- }
1943
- else {
1944
- return [];
2159
+ var _a, _b, _c, _d, _e;
2160
+ // Maximum number of retries for database connection issues
2161
+ const MAX_RETRIES = 3;
2162
+ let retryCount = 0;
2163
+ let lastError = null;
2164
+ // Retry loop to handle potential database connection issues
2165
+ while (retryCount < MAX_RETRIES) {
2166
+ try {
2167
+ const [modules, client] = await Promise.all([
2168
+ (0, client_1.getApolloModules)(),
2169
+ globalClient
2170
+ ? Promise.resolve(globalClient)
2171
+ : client_1.client
2172
+ ]);
2173
+ const { gql, ApolloError } = modules;
2174
+ const FIND_MANY_NEWSARTICLE = gql `
2175
+ query findManyNewsArticle($where: NewsArticleWhereInput!) {
2176
+ newsArticles(where: $where) {
2177
+ ${selectionSet}
1945
2178
  }
1946
- }
1947
- catch (error) {
1948
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1949
- return null;
2179
+ }`;
2180
+ const variables = {
2181
+ where: whereInput ? whereInput : {
2182
+ id: props.id !== undefined ? {
2183
+ equals: props.id
2184
+ } : undefined,
2185
+ title: props.title !== undefined ? {
2186
+ equals: props.title
2187
+ } : undefined,
2188
+ url: props.url !== undefined ? {
2189
+ equals: props.url
2190
+ } : undefined,
2191
+ },
2192
+ };
2193
+ const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
2194
+ const response = await client.query({
2195
+ query: FIND_MANY_NEWSARTICLE,
2196
+ variables: filteredVariables,
2197
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2198
+ });
2199
+ if (response.errors && response.errors.length > 0)
2200
+ throw new Error(response.errors[0].message);
2201
+ if (response && response.data && response.data.newsarticles) {
2202
+ return response.data.newsArticles;
2203
+ }
2204
+ else {
2205
+ return [];
2206
+ }
1950
2207
  }
1951
- else {
1952
- console.error('Error in getNewsArticle:', error);
2208
+ catch (error) {
2209
+ lastError = error;
2210
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2211
+ if (error.message === 'No NewsArticle found') {
2212
+ return null;
2213
+ }
2214
+ // Check if this is a database connection error that we should retry
2215
+ const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
2216
+ ((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
2217
+ ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
2218
+ ((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
2219
+ (error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
2220
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2221
+ retryCount++;
2222
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2223
+ console.warn("Database connection error, retrying...");
2224
+ await new Promise(resolve => setTimeout(resolve, delay));
2225
+ continue;
2226
+ }
2227
+ // Log the error and rethrow
2228
+ console.error("Database error occurred:", error);
1953
2229
  throw error;
1954
2230
  }
1955
2231
  }
2232
+ // If we exhausted retries, throw the last error
2233
+ throw lastError;
1956
2234
  }
1957
2235
  };
1958
2236
  //# sourceMappingURL=NewsArticle.js.map