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