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