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
package/VerificationToken.cjs
CHANGED
@@ -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
|
-
|
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
|
+
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
|
-
|
159
|
-
|
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
|
-
|
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;
|
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
|
-
|
213
|
-
|
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
|
-
|
217
|
-
|
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
|
-
|
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;
|
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
|
-
|
269
|
-
|
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
|
-
|
273
|
-
|
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
|
-
*
|
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
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
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
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
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
|
-
|
311
|
-
|
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
|
-
|
315
|
-
|
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
|
-
*
|
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
|
-
|
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
|
-
|
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
|
-
|
357
|
-
|
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
|
-
|
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;
|
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
|
-
|
393
|
-
|
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
|
-
|
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;
|
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
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
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
|
-
|
442
|
-
|
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
|