adaptic-backend 1.0.340 → 1.0.342

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