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