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