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/Action.cjs
CHANGED
@@ -27,939 +27,1295 @@ exports.Action = {
|
|
27
27
|
* @param client - Apollo Client instance.
|
28
28
|
* @returns The created Action or null.
|
29
29
|
*/
|
30
|
+
/**
|
31
|
+
* Create a new Action record.
|
32
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
33
|
+
* @param props - Properties for the new record.
|
34
|
+
* @param globalClient - Apollo Client instance.
|
35
|
+
* @returns The created Action or null.
|
36
|
+
*/
|
30
37
|
async create(props, globalClient) {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
?
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
:
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
38
|
+
var _a, _b, _c, _d, _e;
|
39
|
+
// Maximum number of retries for database connection issues
|
40
|
+
const MAX_RETRIES = 3;
|
41
|
+
let retryCount = 0;
|
42
|
+
let lastError = null;
|
43
|
+
// Retry loop to handle potential database connection issues
|
44
|
+
while (retryCount < MAX_RETRIES) {
|
45
|
+
try {
|
46
|
+
const [modules, client] = await Promise.all([
|
47
|
+
(0, client_1.getApolloModules)(),
|
48
|
+
globalClient
|
49
|
+
? Promise.resolve(globalClient)
|
50
|
+
: client_1.client
|
51
|
+
]);
|
52
|
+
const { gql, ApolloError } = modules;
|
53
|
+
const CREATE_ONE_ACTION = gql `
|
54
|
+
mutation createOneAction($data: ActionCreateInput!) {
|
55
|
+
createOneAction(data: $data) {
|
56
|
+
${selectionSet}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
`;
|
60
|
+
const variables = {
|
61
|
+
data: {
|
62
|
+
sequence: props.sequence !== undefined ? props.sequence : undefined,
|
63
|
+
type: props.type !== undefined ? props.type : undefined,
|
64
|
+
primary: props.primary !== undefined ? props.primary : undefined,
|
65
|
+
note: props.note !== undefined ? props.note : undefined,
|
66
|
+
status: props.status !== undefined ? props.status : undefined,
|
67
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
68
|
+
trade: props.trade ?
|
69
|
+
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && Object.keys(props.trade)[0] === 'id'
|
70
|
+
? { connect: {
|
71
|
+
id: props.trade.id
|
72
|
+
}
|
73
|
+
}
|
74
|
+
: { connectOrCreate: {
|
75
|
+
where: {
|
76
|
+
id: props.trade.id !== undefined ? props.trade.id : undefined,
|
77
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
78
|
+
equals: props.trade.alpacaAccountId
|
79
|
+
} : undefined,
|
80
|
+
symbol: props.trade.symbol !== undefined ? {
|
81
|
+
equals: props.trade.symbol
|
82
|
+
} : undefined,
|
83
|
+
},
|
84
|
+
create: {
|
85
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
86
|
+
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
87
|
+
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
88
|
+
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
89
|
+
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
90
|
+
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
91
|
+
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
92
|
+
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
93
|
+
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
94
|
+
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
95
|
+
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
96
|
+
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
97
|
+
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
98
|
+
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
99
|
+
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
100
|
+
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
101
|
+
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
102
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
103
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
104
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
105
|
+
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
106
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
107
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
108
|
+
},
|
109
|
+
}
|
110
|
+
} : undefined,
|
111
|
+
},
|
112
|
+
};
|
113
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
114
|
+
const response = await client.mutate({
|
115
|
+
mutation: CREATE_ONE_ACTION,
|
116
|
+
variables: filteredVariables,
|
117
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
118
|
+
fetchPolicy: 'no-cache'
|
119
|
+
});
|
120
|
+
if (response.errors && response.errors.length > 0)
|
121
|
+
throw new Error(response.errors[0].message);
|
122
|
+
if (response && response.data && response.data.createOneAction) {
|
123
|
+
return response.data.createOneAction;
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
return null;
|
127
|
+
}
|
105
128
|
}
|
106
|
-
|
107
|
-
|
129
|
+
catch (error) {
|
130
|
+
lastError = error;
|
131
|
+
// Check if this is a database connection error that we should retry
|
132
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
133
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
134
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
135
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
136
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
137
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
138
|
+
retryCount++;
|
139
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
140
|
+
console.warn("Database connection error, retrying...");
|
141
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
142
|
+
continue;
|
143
|
+
}
|
144
|
+
// Log the error and rethrow
|
145
|
+
console.error("Database error occurred:", error);
|
146
|
+
throw error;
|
108
147
|
}
|
109
148
|
}
|
110
|
-
|
111
|
-
|
112
|
-
throw error;
|
113
|
-
}
|
149
|
+
// If we exhausted retries, throw the last error
|
150
|
+
throw lastError;
|
114
151
|
},
|
115
152
|
/**
|
116
153
|
* Create multiple Action records.
|
154
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
117
155
|
* @param props - Array of Action objects for the new records.
|
118
156
|
* @param globalClient - Apollo Client instance.
|
119
157
|
* @returns The count of created records or null.
|
120
158
|
*/
|
121
159
|
async createMany(props, globalClient) {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
note: prop.note !== undefined ? prop.note : undefined,
|
142
|
-
status: prop.status !== undefined ? prop.status : undefined,
|
143
|
-
alpacaOrderId: prop.alpacaOrderId !== undefined ? prop.alpacaOrderId : undefined,
|
144
|
-
})),
|
145
|
-
};
|
146
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
147
|
-
try {
|
148
|
-
const response = await client.mutate({ mutation: CREATE_MANY_ACTION, 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.createManyAction) {
|
152
|
-
return response.data.createManyAction;
|
160
|
+
var _a, _b, _c, _d, _e;
|
161
|
+
// Maximum number of retries for database connection issues
|
162
|
+
const MAX_RETRIES = 3;
|
163
|
+
let retryCount = 0;
|
164
|
+
let lastError = null;
|
165
|
+
// Retry loop to handle potential database connection issues
|
166
|
+
while (retryCount < MAX_RETRIES) {
|
167
|
+
try {
|
168
|
+
const [modules, client] = await Promise.all([
|
169
|
+
(0, client_1.getApolloModules)(),
|
170
|
+
globalClient
|
171
|
+
? Promise.resolve(globalClient)
|
172
|
+
: client_1.client
|
173
|
+
]);
|
174
|
+
const { gql, ApolloError } = modules;
|
175
|
+
const CREATE_MANY_ACTION = gql `
|
176
|
+
mutation createManyAction($data: [ActionCreateManyInput!]!) {
|
177
|
+
createManyAction(data: $data) {
|
178
|
+
count
|
153
179
|
}
|
154
|
-
|
155
|
-
|
180
|
+
}`;
|
181
|
+
const variables = {
|
182
|
+
data: props.map(prop => ({
|
183
|
+
sequence: prop.sequence !== undefined ? prop.sequence : undefined,
|
184
|
+
tradeId: prop.tradeId !== undefined ? prop.tradeId : undefined,
|
185
|
+
type: prop.type !== undefined ? prop.type : undefined,
|
186
|
+
primary: prop.primary !== undefined ? prop.primary : undefined,
|
187
|
+
note: prop.note !== undefined ? prop.note : undefined,
|
188
|
+
status: prop.status !== undefined ? prop.status : undefined,
|
189
|
+
alpacaOrderId: prop.alpacaOrderId !== undefined ? prop.alpacaOrderId : undefined,
|
190
|
+
})),
|
191
|
+
};
|
192
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
193
|
+
const response = await client.mutate({
|
194
|
+
mutation: CREATE_MANY_ACTION,
|
195
|
+
variables: filteredVariables,
|
196
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
197
|
+
fetchPolicy: 'no-cache'
|
198
|
+
});
|
199
|
+
if (response.errors && response.errors.length > 0)
|
200
|
+
throw new Error(response.errors[0].message);
|
201
|
+
if (response && response.data && response.data.createManyAction) {
|
202
|
+
return response.data.createManyAction;
|
203
|
+
}
|
204
|
+
else {
|
205
|
+
return null;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
catch (error) {
|
209
|
+
lastError = error;
|
210
|
+
// Check if this is a database connection error that we should retry
|
211
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
212
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
213
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
214
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
215
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
216
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
217
|
+
retryCount++;
|
218
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
219
|
+
console.warn("Database connection error, retrying...");
|
220
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
221
|
+
continue;
|
222
|
+
}
|
223
|
+
// Log the error and rethrow
|
224
|
+
console.error("Database error occurred:", error);
|
225
|
+
throw error;
|
156
226
|
}
|
157
227
|
}
|
158
|
-
|
159
|
-
|
160
|
-
throw error;
|
161
|
-
}
|
228
|
+
// If we exhausted retries, throw the last error
|
229
|
+
throw lastError;
|
162
230
|
},
|
163
231
|
/**
|
164
232
|
* Update a single Action record.
|
233
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
165
234
|
* @param props - Properties to update.
|
166
235
|
* @param globalClient - Apollo Client instance.
|
167
236
|
* @returns The updated Action or null.
|
168
237
|
*/
|
169
238
|
async update(props, globalClient) {
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
} : undefined,
|
190
|
-
},
|
191
|
-
data: {
|
192
|
-
id: props.id !== undefined ? {
|
193
|
-
set: props.id
|
194
|
-
} : undefined,
|
195
|
-
sequence: props.sequence !== undefined ? {
|
196
|
-
set: props.sequence
|
197
|
-
} : undefined,
|
198
|
-
type: props.type !== undefined ? {
|
199
|
-
set: props.type
|
200
|
-
} : undefined,
|
201
|
-
primary: props.primary !== undefined ? {
|
202
|
-
set: props.primary
|
203
|
-
} : undefined,
|
204
|
-
note: props.note !== undefined ? {
|
205
|
-
set: props.note
|
206
|
-
} : undefined,
|
207
|
-
status: props.status !== undefined ? {
|
208
|
-
set: props.status
|
209
|
-
} : undefined,
|
210
|
-
createdAt: props.createdAt !== undefined ? {
|
211
|
-
set: props.createdAt
|
212
|
-
} : undefined,
|
213
|
-
updatedAt: props.updatedAt !== undefined ? {
|
214
|
-
set: props.updatedAt
|
215
|
-
} : undefined,
|
216
|
-
alpacaOrderId: props.alpacaOrderId !== undefined ? {
|
217
|
-
set: props.alpacaOrderId
|
218
|
-
} : undefined,
|
219
|
-
trade: props.trade ?
|
220
|
-
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && (Object.keys(props.trade)[0] === 'id' || Object.keys(props.trade)[0] === 'symbol')
|
221
|
-
? {
|
222
|
-
connect: {
|
223
|
-
id: props.trade.id
|
224
|
-
}
|
225
|
-
} : { upsert: {
|
226
|
-
where: {
|
227
|
-
id: props.trade.id !== undefined ? {
|
228
|
-
equals: props.trade.id
|
229
|
-
} : undefined,
|
230
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
231
|
-
equals: props.trade.alpacaAccountId
|
232
|
-
} : undefined,
|
233
|
-
symbol: props.trade.symbol !== undefined ? {
|
234
|
-
equals: props.trade.symbol
|
235
|
-
} : undefined,
|
236
|
-
},
|
237
|
-
update: {
|
238
|
-
id: props.trade.id !== undefined ? {
|
239
|
-
set: props.trade.id
|
240
|
-
} : undefined,
|
241
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
242
|
-
set: props.trade.alpacaAccountId
|
243
|
-
} : undefined,
|
244
|
-
signal: props.trade.signal !== undefined ? {
|
245
|
-
set: props.trade.signal
|
246
|
-
} : undefined,
|
247
|
-
strategy: props.trade.strategy !== undefined ? {
|
248
|
-
set: props.trade.strategy
|
249
|
-
} : undefined,
|
250
|
-
analysis: props.trade.analysis !== undefined ? {
|
251
|
-
set: props.trade.analysis
|
252
|
-
} : undefined,
|
253
|
-
summary: props.trade.summary !== undefined ? {
|
254
|
-
set: props.trade.summary
|
255
|
-
} : undefined,
|
256
|
-
confidence: props.trade.confidence !== undefined ? {
|
257
|
-
set: props.trade.confidence
|
258
|
-
} : undefined,
|
259
|
-
timestamp: props.trade.timestamp !== undefined ? {
|
260
|
-
set: props.trade.timestamp
|
261
|
-
} : undefined,
|
262
|
-
status: props.trade.status !== undefined ? {
|
263
|
-
set: props.trade.status
|
264
|
-
} : undefined,
|
265
|
-
symbol: props.trade.symbol !== undefined ? {
|
266
|
-
set: props.trade.symbol
|
267
|
-
} : undefined,
|
268
|
-
entryPrice: props.trade.entryPrice !== undefined ? {
|
269
|
-
set: props.trade.entryPrice
|
270
|
-
} : undefined,
|
271
|
-
exitPrice: props.trade.exitPrice !== undefined ? {
|
272
|
-
set: props.trade.exitPrice
|
273
|
-
} : undefined,
|
274
|
-
entryQty: props.trade.entryQty !== undefined ? {
|
275
|
-
set: props.trade.entryQty
|
276
|
-
} : undefined,
|
277
|
-
exitQty: props.trade.exitQty !== undefined ? {
|
278
|
-
set: props.trade.exitQty
|
279
|
-
} : undefined,
|
280
|
-
entryValue: props.trade.entryValue !== undefined ? {
|
281
|
-
set: props.trade.entryValue
|
282
|
-
} : undefined,
|
283
|
-
exitValue: props.trade.exitValue !== undefined ? {
|
284
|
-
set: props.trade.exitValue
|
285
|
-
} : undefined,
|
286
|
-
entryTime: props.trade.entryTime !== undefined ? {
|
287
|
-
set: props.trade.entryTime
|
288
|
-
} : undefined,
|
289
|
-
exitTime: props.trade.exitTime !== undefined ? {
|
290
|
-
set: props.trade.exitTime
|
291
|
-
} : undefined,
|
292
|
-
pnlAmount: props.trade.pnlAmount !== undefined ? {
|
293
|
-
set: props.trade.pnlAmount
|
294
|
-
} : undefined,
|
295
|
-
pnlPercent: props.trade.pnlPercent !== undefined ? {
|
296
|
-
set: props.trade.pnlPercent
|
297
|
-
} : undefined,
|
298
|
-
durationMinutes: props.trade.durationMinutes !== undefined ? {
|
299
|
-
set: props.trade.durationMinutes
|
300
|
-
} : undefined,
|
301
|
-
marketPhase: props.trade.marketPhase !== undefined ? {
|
302
|
-
set: props.trade.marketPhase
|
303
|
-
} : undefined,
|
304
|
-
marketVolatility: props.trade.marketVolatility !== undefined ? {
|
305
|
-
set: props.trade.marketVolatility
|
306
|
-
} : undefined,
|
307
|
-
thresholdsJson: props.trade.thresholdsJson !== undefined ? {
|
308
|
-
set: props.trade.thresholdsJson
|
309
|
-
} : undefined,
|
310
|
-
},
|
311
|
-
create: {
|
312
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
313
|
-
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
314
|
-
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
315
|
-
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
316
|
-
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
317
|
-
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
318
|
-
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
319
|
-
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
320
|
-
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
321
|
-
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
322
|
-
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
323
|
-
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
324
|
-
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
325
|
-
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
326
|
-
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
327
|
-
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
328
|
-
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
329
|
-
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
330
|
-
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
331
|
-
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
332
|
-
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
333
|
-
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
334
|
-
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
335
|
-
},
|
336
|
-
}
|
337
|
-
} : undefined,
|
338
|
-
},
|
339
|
-
};
|
340
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
341
|
-
try {
|
342
|
-
const response = await client.mutate({ mutation: UPDATE_ONE_ACTION, variables: filteredVariables });
|
343
|
-
if (response.errors && response.errors.length > 0)
|
344
|
-
throw new Error(response.errors[0].message);
|
345
|
-
if (response && response.data && response.data.updateOneAction) {
|
346
|
-
return response.data.updateOneAction;
|
239
|
+
var _a, _b, _c, _d, _e;
|
240
|
+
// Maximum number of retries for database connection issues
|
241
|
+
const MAX_RETRIES = 3;
|
242
|
+
let retryCount = 0;
|
243
|
+
let lastError = null;
|
244
|
+
// Retry loop to handle potential database connection issues
|
245
|
+
while (retryCount < MAX_RETRIES) {
|
246
|
+
try {
|
247
|
+
const [modules, client] = await Promise.all([
|
248
|
+
(0, client_1.getApolloModules)(),
|
249
|
+
globalClient
|
250
|
+
? Promise.resolve(globalClient)
|
251
|
+
: client_1.client
|
252
|
+
]);
|
253
|
+
const { gql, ApolloError } = modules;
|
254
|
+
const UPDATE_ONE_ACTION = gql `
|
255
|
+
mutation updateOneAction($data: ActionUpdateInput!, $where: ActionWhereUniqueInput!) {
|
256
|
+
updateOneAction(data: $data, where: $where) {
|
257
|
+
${selectionSet}
|
347
258
|
}
|
348
|
-
|
349
|
-
|
259
|
+
}`;
|
260
|
+
const variables = {
|
261
|
+
where: {
|
262
|
+
id: props.id !== undefined ? props.id : undefined,
|
263
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
264
|
+
sequence: props.sequence !== undefined ? {
|
265
|
+
equals: props.sequence
|
266
|
+
} : undefined,
|
267
|
+
tradeId: props.tradeId !== undefined ? props.tradeId : undefined,
|
268
|
+
type: props.type !== undefined ? {
|
269
|
+
equals: props.type
|
270
|
+
} : undefined,
|
271
|
+
note: props.note !== undefined ? {
|
272
|
+
equals: props.note
|
273
|
+
} : undefined,
|
274
|
+
status: props.status !== undefined ? {
|
275
|
+
equals: props.status
|
276
|
+
} : undefined,
|
277
|
+
createdAt: props.createdAt !== undefined ? {
|
278
|
+
equals: props.createdAt
|
279
|
+
} : undefined,
|
280
|
+
updatedAt: props.updatedAt !== undefined ? {
|
281
|
+
equals: props.updatedAt
|
282
|
+
} : undefined,
|
283
|
+
},
|
284
|
+
data: {
|
285
|
+
id: props.id !== undefined ? {
|
286
|
+
set: props.id
|
287
|
+
} : undefined,
|
288
|
+
sequence: props.sequence !== undefined ? {
|
289
|
+
set: props.sequence
|
290
|
+
} : undefined,
|
291
|
+
type: props.type !== undefined ? {
|
292
|
+
set: props.type
|
293
|
+
} : undefined,
|
294
|
+
primary: props.primary !== undefined ? {
|
295
|
+
set: props.primary
|
296
|
+
} : undefined,
|
297
|
+
note: props.note !== undefined ? {
|
298
|
+
set: props.note
|
299
|
+
} : undefined,
|
300
|
+
status: props.status !== undefined ? {
|
301
|
+
set: props.status
|
302
|
+
} : undefined,
|
303
|
+
createdAt: props.createdAt !== undefined ? {
|
304
|
+
set: props.createdAt
|
305
|
+
} : undefined,
|
306
|
+
updatedAt: props.updatedAt !== undefined ? {
|
307
|
+
set: props.updatedAt
|
308
|
+
} : undefined,
|
309
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? {
|
310
|
+
set: props.alpacaOrderId
|
311
|
+
} : undefined,
|
312
|
+
trade: props.trade ?
|
313
|
+
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && (Object.keys(props.trade)[0] === 'id' || Object.keys(props.trade)[0] === 'symbol')
|
314
|
+
? {
|
315
|
+
connect: {
|
316
|
+
id: props.trade.id
|
317
|
+
}
|
318
|
+
} : { upsert: {
|
319
|
+
where: {
|
320
|
+
id: props.trade.id !== undefined ? {
|
321
|
+
equals: props.trade.id
|
322
|
+
} : undefined,
|
323
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
324
|
+
equals: props.trade.alpacaAccountId
|
325
|
+
} : undefined,
|
326
|
+
symbol: props.trade.symbol !== undefined ? {
|
327
|
+
equals: props.trade.symbol
|
328
|
+
} : undefined,
|
329
|
+
},
|
330
|
+
update: {
|
331
|
+
id: props.trade.id !== undefined ? {
|
332
|
+
set: props.trade.id
|
333
|
+
} : undefined,
|
334
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
335
|
+
set: props.trade.alpacaAccountId
|
336
|
+
} : undefined,
|
337
|
+
signal: props.trade.signal !== undefined ? {
|
338
|
+
set: props.trade.signal
|
339
|
+
} : undefined,
|
340
|
+
strategy: props.trade.strategy !== undefined ? {
|
341
|
+
set: props.trade.strategy
|
342
|
+
} : undefined,
|
343
|
+
analysis: props.trade.analysis !== undefined ? {
|
344
|
+
set: props.trade.analysis
|
345
|
+
} : undefined,
|
346
|
+
summary: props.trade.summary !== undefined ? {
|
347
|
+
set: props.trade.summary
|
348
|
+
} : undefined,
|
349
|
+
confidence: props.trade.confidence !== undefined ? {
|
350
|
+
set: props.trade.confidence
|
351
|
+
} : undefined,
|
352
|
+
timestamp: props.trade.timestamp !== undefined ? {
|
353
|
+
set: props.trade.timestamp
|
354
|
+
} : undefined,
|
355
|
+
status: props.trade.status !== undefined ? {
|
356
|
+
set: props.trade.status
|
357
|
+
} : undefined,
|
358
|
+
symbol: props.trade.symbol !== undefined ? {
|
359
|
+
set: props.trade.symbol
|
360
|
+
} : undefined,
|
361
|
+
entryPrice: props.trade.entryPrice !== undefined ? {
|
362
|
+
set: props.trade.entryPrice
|
363
|
+
} : undefined,
|
364
|
+
exitPrice: props.trade.exitPrice !== undefined ? {
|
365
|
+
set: props.trade.exitPrice
|
366
|
+
} : undefined,
|
367
|
+
entryQty: props.trade.entryQty !== undefined ? {
|
368
|
+
set: props.trade.entryQty
|
369
|
+
} : undefined,
|
370
|
+
exitQty: props.trade.exitQty !== undefined ? {
|
371
|
+
set: props.trade.exitQty
|
372
|
+
} : undefined,
|
373
|
+
entryValue: props.trade.entryValue !== undefined ? {
|
374
|
+
set: props.trade.entryValue
|
375
|
+
} : undefined,
|
376
|
+
exitValue: props.trade.exitValue !== undefined ? {
|
377
|
+
set: props.trade.exitValue
|
378
|
+
} : undefined,
|
379
|
+
entryTime: props.trade.entryTime !== undefined ? {
|
380
|
+
set: props.trade.entryTime
|
381
|
+
} : undefined,
|
382
|
+
exitTime: props.trade.exitTime !== undefined ? {
|
383
|
+
set: props.trade.exitTime
|
384
|
+
} : undefined,
|
385
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? {
|
386
|
+
set: props.trade.pnlAmount
|
387
|
+
} : undefined,
|
388
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? {
|
389
|
+
set: props.trade.pnlPercent
|
390
|
+
} : undefined,
|
391
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? {
|
392
|
+
set: props.trade.durationMinutes
|
393
|
+
} : undefined,
|
394
|
+
marketPhase: props.trade.marketPhase !== undefined ? {
|
395
|
+
set: props.trade.marketPhase
|
396
|
+
} : undefined,
|
397
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? {
|
398
|
+
set: props.trade.marketVolatility
|
399
|
+
} : undefined,
|
400
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? {
|
401
|
+
set: props.trade.thresholdsJson
|
402
|
+
} : undefined,
|
403
|
+
},
|
404
|
+
create: {
|
405
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
406
|
+
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
407
|
+
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
408
|
+
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
409
|
+
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
410
|
+
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
411
|
+
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
412
|
+
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
413
|
+
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
414
|
+
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
415
|
+
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
416
|
+
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
417
|
+
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
418
|
+
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
419
|
+
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
420
|
+
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
421
|
+
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
422
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
423
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
424
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
425
|
+
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
426
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
427
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
428
|
+
},
|
429
|
+
}
|
430
|
+
} : undefined,
|
431
|
+
},
|
432
|
+
};
|
433
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
434
|
+
const response = await client.mutate({
|
435
|
+
mutation: UPDATE_ONE_ACTION,
|
436
|
+
variables: filteredVariables,
|
437
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
438
|
+
fetchPolicy: 'no-cache'
|
439
|
+
});
|
440
|
+
if (response.errors && response.errors.length > 0)
|
441
|
+
throw new Error(response.errors[0].message);
|
442
|
+
if (response && response.data && response.data.updateOneAction) {
|
443
|
+
return response.data.updateOneAction;
|
444
|
+
}
|
445
|
+
else {
|
446
|
+
return null;
|
447
|
+
}
|
448
|
+
}
|
449
|
+
catch (error) {
|
450
|
+
lastError = error;
|
451
|
+
// Check if this is a database connection error that we should retry
|
452
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
453
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
454
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
455
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
456
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
457
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
458
|
+
retryCount++;
|
459
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
460
|
+
console.warn("Database connection error, retrying...");
|
461
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
462
|
+
continue;
|
463
|
+
}
|
464
|
+
// Log the error and rethrow
|
465
|
+
console.error("Database error occurred:", error);
|
466
|
+
throw error;
|
350
467
|
}
|
351
468
|
}
|
352
|
-
|
353
|
-
|
354
|
-
throw error;
|
355
|
-
}
|
469
|
+
// If we exhausted retries, throw the last error
|
470
|
+
throw lastError;
|
356
471
|
},
|
357
472
|
/**
|
358
473
|
* Upsert a single Action record.
|
474
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
359
475
|
* @param props - Properties to update.
|
360
476
|
* @param globalClient - Apollo Client instance.
|
361
477
|
* @returns The updated Action or null.
|
362
478
|
*/
|
363
479
|
async upsert(props, globalClient) {
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
} : undefined,
|
384
|
-
},
|
385
|
-
create: {
|
386
|
-
sequence: props.sequence !== undefined ? props.sequence : undefined,
|
387
|
-
type: props.type !== undefined ? props.type : undefined,
|
388
|
-
primary: props.primary !== undefined ? props.primary : undefined,
|
389
|
-
note: props.note !== undefined ? props.note : undefined,
|
390
|
-
status: props.status !== undefined ? props.status : undefined,
|
391
|
-
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
392
|
-
trade: props.trade ?
|
393
|
-
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && Object.keys(props.trade)[0] === 'id'
|
394
|
-
? { connect: {
|
395
|
-
id: props.trade.id
|
396
|
-
}
|
397
|
-
}
|
398
|
-
: { connectOrCreate: {
|
399
|
-
where: {
|
400
|
-
id: props.trade.id !== undefined ? props.trade.id : undefined,
|
401
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
402
|
-
equals: props.trade.alpacaAccountId
|
403
|
-
} : undefined,
|
404
|
-
symbol: props.trade.symbol !== undefined ? {
|
405
|
-
equals: props.trade.symbol
|
406
|
-
} : undefined,
|
407
|
-
},
|
408
|
-
create: {
|
409
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
410
|
-
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
411
|
-
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
412
|
-
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
413
|
-
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
414
|
-
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
415
|
-
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
416
|
-
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
417
|
-
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
418
|
-
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
419
|
-
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
420
|
-
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
421
|
-
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
422
|
-
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
423
|
-
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
424
|
-
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
425
|
-
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
426
|
-
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
427
|
-
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
428
|
-
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
429
|
-
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
430
|
-
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
431
|
-
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
432
|
-
},
|
433
|
-
}
|
434
|
-
} : undefined,
|
435
|
-
},
|
436
|
-
update: {
|
437
|
-
sequence: props.sequence !== undefined ? {
|
438
|
-
set: props.sequence
|
439
|
-
} : undefined,
|
440
|
-
type: props.type !== undefined ? {
|
441
|
-
set: props.type
|
442
|
-
} : undefined,
|
443
|
-
primary: props.primary !== undefined ? {
|
444
|
-
set: props.primary
|
445
|
-
} : undefined,
|
446
|
-
note: props.note !== undefined ? {
|
447
|
-
set: props.note
|
448
|
-
} : undefined,
|
449
|
-
status: props.status !== undefined ? {
|
450
|
-
set: props.status
|
451
|
-
} : undefined,
|
452
|
-
alpacaOrderId: props.alpacaOrderId !== undefined ? {
|
453
|
-
set: props.alpacaOrderId
|
454
|
-
} : undefined,
|
455
|
-
trade: props.trade ?
|
456
|
-
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && (Object.keys(props.trade)[0] === 'id' || Object.keys(props.trade)[0] === 'symbol')
|
457
|
-
? {
|
458
|
-
connect: {
|
459
|
-
id: props.trade.id
|
460
|
-
}
|
461
|
-
} : { upsert: {
|
462
|
-
where: {
|
463
|
-
id: props.trade.id !== undefined ? {
|
464
|
-
equals: props.trade.id
|
465
|
-
} : undefined,
|
466
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
467
|
-
equals: props.trade.alpacaAccountId
|
468
|
-
} : undefined,
|
469
|
-
symbol: props.trade.symbol !== undefined ? {
|
470
|
-
equals: props.trade.symbol
|
471
|
-
} : undefined,
|
472
|
-
},
|
473
|
-
update: {
|
474
|
-
id: props.trade.id !== undefined ? {
|
475
|
-
set: props.trade.id
|
476
|
-
} : undefined,
|
477
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
478
|
-
set: props.trade.alpacaAccountId
|
479
|
-
} : undefined,
|
480
|
-
signal: props.trade.signal !== undefined ? {
|
481
|
-
set: props.trade.signal
|
482
|
-
} : undefined,
|
483
|
-
strategy: props.trade.strategy !== undefined ? {
|
484
|
-
set: props.trade.strategy
|
485
|
-
} : undefined,
|
486
|
-
analysis: props.trade.analysis !== undefined ? {
|
487
|
-
set: props.trade.analysis
|
488
|
-
} : undefined,
|
489
|
-
summary: props.trade.summary !== undefined ? {
|
490
|
-
set: props.trade.summary
|
491
|
-
} : undefined,
|
492
|
-
confidence: props.trade.confidence !== undefined ? {
|
493
|
-
set: props.trade.confidence
|
494
|
-
} : undefined,
|
495
|
-
timestamp: props.trade.timestamp !== undefined ? {
|
496
|
-
set: props.trade.timestamp
|
497
|
-
} : undefined,
|
498
|
-
status: props.trade.status !== undefined ? {
|
499
|
-
set: props.trade.status
|
500
|
-
} : undefined,
|
501
|
-
symbol: props.trade.symbol !== undefined ? {
|
502
|
-
set: props.trade.symbol
|
503
|
-
} : undefined,
|
504
|
-
entryPrice: props.trade.entryPrice !== undefined ? {
|
505
|
-
set: props.trade.entryPrice
|
506
|
-
} : undefined,
|
507
|
-
exitPrice: props.trade.exitPrice !== undefined ? {
|
508
|
-
set: props.trade.exitPrice
|
509
|
-
} : undefined,
|
510
|
-
entryQty: props.trade.entryQty !== undefined ? {
|
511
|
-
set: props.trade.entryQty
|
512
|
-
} : undefined,
|
513
|
-
exitQty: props.trade.exitQty !== undefined ? {
|
514
|
-
set: props.trade.exitQty
|
515
|
-
} : undefined,
|
516
|
-
entryValue: props.trade.entryValue !== undefined ? {
|
517
|
-
set: props.trade.entryValue
|
518
|
-
} : undefined,
|
519
|
-
exitValue: props.trade.exitValue !== undefined ? {
|
520
|
-
set: props.trade.exitValue
|
521
|
-
} : undefined,
|
522
|
-
entryTime: props.trade.entryTime !== undefined ? {
|
523
|
-
set: props.trade.entryTime
|
524
|
-
} : undefined,
|
525
|
-
exitTime: props.trade.exitTime !== undefined ? {
|
526
|
-
set: props.trade.exitTime
|
527
|
-
} : undefined,
|
528
|
-
pnlAmount: props.trade.pnlAmount !== undefined ? {
|
529
|
-
set: props.trade.pnlAmount
|
530
|
-
} : undefined,
|
531
|
-
pnlPercent: props.trade.pnlPercent !== undefined ? {
|
532
|
-
set: props.trade.pnlPercent
|
533
|
-
} : undefined,
|
534
|
-
durationMinutes: props.trade.durationMinutes !== undefined ? {
|
535
|
-
set: props.trade.durationMinutes
|
536
|
-
} : undefined,
|
537
|
-
marketPhase: props.trade.marketPhase !== undefined ? {
|
538
|
-
set: props.trade.marketPhase
|
539
|
-
} : undefined,
|
540
|
-
marketVolatility: props.trade.marketVolatility !== undefined ? {
|
541
|
-
set: props.trade.marketVolatility
|
542
|
-
} : undefined,
|
543
|
-
thresholdsJson: props.trade.thresholdsJson !== undefined ? {
|
544
|
-
set: props.trade.thresholdsJson
|
545
|
-
} : undefined,
|
546
|
-
},
|
547
|
-
create: {
|
548
|
-
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
549
|
-
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
550
|
-
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
551
|
-
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
552
|
-
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
553
|
-
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
554
|
-
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
555
|
-
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
556
|
-
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
557
|
-
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
558
|
-
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
559
|
-
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
560
|
-
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
561
|
-
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
562
|
-
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
563
|
-
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
564
|
-
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
565
|
-
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
566
|
-
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
567
|
-
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
568
|
-
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
569
|
-
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
570
|
-
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
571
|
-
},
|
572
|
-
}
|
573
|
-
} : undefined,
|
574
|
-
},
|
575
|
-
};
|
576
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
577
|
-
try {
|
578
|
-
const response = await client.mutate({ mutation: UPSERT_ONE_ACTION, variables: filteredVariables });
|
579
|
-
if (response.errors && response.errors.length > 0)
|
580
|
-
throw new Error(response.errors[0].message);
|
581
|
-
if (response && response.data && response.data.upsertOneAction) {
|
582
|
-
return response.data.upsertOneAction;
|
480
|
+
var _a, _b, _c, _d, _e;
|
481
|
+
// Maximum number of retries for database connection issues
|
482
|
+
const MAX_RETRIES = 3;
|
483
|
+
let retryCount = 0;
|
484
|
+
let lastError = null;
|
485
|
+
// Retry loop to handle potential database connection issues
|
486
|
+
while (retryCount < MAX_RETRIES) {
|
487
|
+
try {
|
488
|
+
const [modules, client] = await Promise.all([
|
489
|
+
(0, client_1.getApolloModules)(),
|
490
|
+
globalClient
|
491
|
+
? Promise.resolve(globalClient)
|
492
|
+
: client_1.client
|
493
|
+
]);
|
494
|
+
const { gql, ApolloError } = modules;
|
495
|
+
const UPSERT_ONE_ACTION = gql `
|
496
|
+
mutation upsertOneAction($where: ActionWhereUniqueInput!, $create: ActionCreateInput!, $update: ActionUpdateInput!) {
|
497
|
+
upsertOneAction(where: $where, create: $create, update: $update) {
|
498
|
+
${selectionSet}
|
583
499
|
}
|
584
|
-
|
585
|
-
|
500
|
+
}`;
|
501
|
+
const variables = {
|
502
|
+
where: {
|
503
|
+
id: props.id !== undefined ? props.id : undefined,
|
504
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
505
|
+
sequence: props.sequence !== undefined ? {
|
506
|
+
equals: props.sequence
|
507
|
+
} : undefined,
|
508
|
+
tradeId: props.tradeId !== undefined ? props.tradeId : undefined,
|
509
|
+
type: props.type !== undefined ? {
|
510
|
+
equals: props.type
|
511
|
+
} : undefined,
|
512
|
+
note: props.note !== undefined ? {
|
513
|
+
equals: props.note
|
514
|
+
} : undefined,
|
515
|
+
status: props.status !== undefined ? {
|
516
|
+
equals: props.status
|
517
|
+
} : undefined,
|
518
|
+
createdAt: props.createdAt !== undefined ? {
|
519
|
+
equals: props.createdAt
|
520
|
+
} : undefined,
|
521
|
+
updatedAt: props.updatedAt !== undefined ? {
|
522
|
+
equals: props.updatedAt
|
523
|
+
} : undefined,
|
524
|
+
},
|
525
|
+
create: {
|
526
|
+
sequence: props.sequence !== undefined ? props.sequence : undefined,
|
527
|
+
type: props.type !== undefined ? props.type : undefined,
|
528
|
+
primary: props.primary !== undefined ? props.primary : undefined,
|
529
|
+
note: props.note !== undefined ? props.note : undefined,
|
530
|
+
status: props.status !== undefined ? props.status : undefined,
|
531
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
532
|
+
trade: props.trade ?
|
533
|
+
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && Object.keys(props.trade)[0] === 'id'
|
534
|
+
? { connect: {
|
535
|
+
id: props.trade.id
|
536
|
+
}
|
537
|
+
}
|
538
|
+
: { connectOrCreate: {
|
539
|
+
where: {
|
540
|
+
id: props.trade.id !== undefined ? props.trade.id : undefined,
|
541
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
542
|
+
equals: props.trade.alpacaAccountId
|
543
|
+
} : undefined,
|
544
|
+
symbol: props.trade.symbol !== undefined ? {
|
545
|
+
equals: props.trade.symbol
|
546
|
+
} : undefined,
|
547
|
+
},
|
548
|
+
create: {
|
549
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
550
|
+
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
551
|
+
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
552
|
+
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
553
|
+
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
554
|
+
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
555
|
+
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
556
|
+
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
557
|
+
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
558
|
+
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
559
|
+
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
560
|
+
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
561
|
+
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
562
|
+
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
563
|
+
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
564
|
+
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
565
|
+
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
566
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
567
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
568
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
569
|
+
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
570
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
571
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
572
|
+
},
|
573
|
+
}
|
574
|
+
} : undefined,
|
575
|
+
},
|
576
|
+
update: {
|
577
|
+
sequence: props.sequence !== undefined ? {
|
578
|
+
set: props.sequence
|
579
|
+
} : undefined,
|
580
|
+
type: props.type !== undefined ? {
|
581
|
+
set: props.type
|
582
|
+
} : undefined,
|
583
|
+
primary: props.primary !== undefined ? {
|
584
|
+
set: props.primary
|
585
|
+
} : undefined,
|
586
|
+
note: props.note !== undefined ? {
|
587
|
+
set: props.note
|
588
|
+
} : undefined,
|
589
|
+
status: props.status !== undefined ? {
|
590
|
+
set: props.status
|
591
|
+
} : undefined,
|
592
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? {
|
593
|
+
set: props.alpacaOrderId
|
594
|
+
} : undefined,
|
595
|
+
trade: props.trade ?
|
596
|
+
typeof props.trade === 'object' && Object.keys(props.trade).length === 1 && (Object.keys(props.trade)[0] === 'id' || Object.keys(props.trade)[0] === 'symbol')
|
597
|
+
? {
|
598
|
+
connect: {
|
599
|
+
id: props.trade.id
|
600
|
+
}
|
601
|
+
} : { upsert: {
|
602
|
+
where: {
|
603
|
+
id: props.trade.id !== undefined ? {
|
604
|
+
equals: props.trade.id
|
605
|
+
} : undefined,
|
606
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
607
|
+
equals: props.trade.alpacaAccountId
|
608
|
+
} : undefined,
|
609
|
+
symbol: props.trade.symbol !== undefined ? {
|
610
|
+
equals: props.trade.symbol
|
611
|
+
} : undefined,
|
612
|
+
},
|
613
|
+
update: {
|
614
|
+
id: props.trade.id !== undefined ? {
|
615
|
+
set: props.trade.id
|
616
|
+
} : undefined,
|
617
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? {
|
618
|
+
set: props.trade.alpacaAccountId
|
619
|
+
} : undefined,
|
620
|
+
signal: props.trade.signal !== undefined ? {
|
621
|
+
set: props.trade.signal
|
622
|
+
} : undefined,
|
623
|
+
strategy: props.trade.strategy !== undefined ? {
|
624
|
+
set: props.trade.strategy
|
625
|
+
} : undefined,
|
626
|
+
analysis: props.trade.analysis !== undefined ? {
|
627
|
+
set: props.trade.analysis
|
628
|
+
} : undefined,
|
629
|
+
summary: props.trade.summary !== undefined ? {
|
630
|
+
set: props.trade.summary
|
631
|
+
} : undefined,
|
632
|
+
confidence: props.trade.confidence !== undefined ? {
|
633
|
+
set: props.trade.confidence
|
634
|
+
} : undefined,
|
635
|
+
timestamp: props.trade.timestamp !== undefined ? {
|
636
|
+
set: props.trade.timestamp
|
637
|
+
} : undefined,
|
638
|
+
status: props.trade.status !== undefined ? {
|
639
|
+
set: props.trade.status
|
640
|
+
} : undefined,
|
641
|
+
symbol: props.trade.symbol !== undefined ? {
|
642
|
+
set: props.trade.symbol
|
643
|
+
} : undefined,
|
644
|
+
entryPrice: props.trade.entryPrice !== undefined ? {
|
645
|
+
set: props.trade.entryPrice
|
646
|
+
} : undefined,
|
647
|
+
exitPrice: props.trade.exitPrice !== undefined ? {
|
648
|
+
set: props.trade.exitPrice
|
649
|
+
} : undefined,
|
650
|
+
entryQty: props.trade.entryQty !== undefined ? {
|
651
|
+
set: props.trade.entryQty
|
652
|
+
} : undefined,
|
653
|
+
exitQty: props.trade.exitQty !== undefined ? {
|
654
|
+
set: props.trade.exitQty
|
655
|
+
} : undefined,
|
656
|
+
entryValue: props.trade.entryValue !== undefined ? {
|
657
|
+
set: props.trade.entryValue
|
658
|
+
} : undefined,
|
659
|
+
exitValue: props.trade.exitValue !== undefined ? {
|
660
|
+
set: props.trade.exitValue
|
661
|
+
} : undefined,
|
662
|
+
entryTime: props.trade.entryTime !== undefined ? {
|
663
|
+
set: props.trade.entryTime
|
664
|
+
} : undefined,
|
665
|
+
exitTime: props.trade.exitTime !== undefined ? {
|
666
|
+
set: props.trade.exitTime
|
667
|
+
} : undefined,
|
668
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? {
|
669
|
+
set: props.trade.pnlAmount
|
670
|
+
} : undefined,
|
671
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? {
|
672
|
+
set: props.trade.pnlPercent
|
673
|
+
} : undefined,
|
674
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? {
|
675
|
+
set: props.trade.durationMinutes
|
676
|
+
} : undefined,
|
677
|
+
marketPhase: props.trade.marketPhase !== undefined ? {
|
678
|
+
set: props.trade.marketPhase
|
679
|
+
} : undefined,
|
680
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? {
|
681
|
+
set: props.trade.marketVolatility
|
682
|
+
} : undefined,
|
683
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? {
|
684
|
+
set: props.trade.thresholdsJson
|
685
|
+
} : undefined,
|
686
|
+
},
|
687
|
+
create: {
|
688
|
+
alpacaAccountId: props.trade.alpacaAccountId !== undefined ? props.trade.alpacaAccountId : undefined,
|
689
|
+
signal: props.trade.signal !== undefined ? props.trade.signal : undefined,
|
690
|
+
strategy: props.trade.strategy !== undefined ? props.trade.strategy : undefined,
|
691
|
+
analysis: props.trade.analysis !== undefined ? props.trade.analysis : undefined,
|
692
|
+
summary: props.trade.summary !== undefined ? props.trade.summary : undefined,
|
693
|
+
confidence: props.trade.confidence !== undefined ? props.trade.confidence : undefined,
|
694
|
+
timestamp: props.trade.timestamp !== undefined ? props.trade.timestamp : undefined,
|
695
|
+
status: props.trade.status !== undefined ? props.trade.status : undefined,
|
696
|
+
symbol: props.trade.symbol !== undefined ? props.trade.symbol : undefined,
|
697
|
+
entryPrice: props.trade.entryPrice !== undefined ? props.trade.entryPrice : undefined,
|
698
|
+
exitPrice: props.trade.exitPrice !== undefined ? props.trade.exitPrice : undefined,
|
699
|
+
entryQty: props.trade.entryQty !== undefined ? props.trade.entryQty : undefined,
|
700
|
+
exitQty: props.trade.exitQty !== undefined ? props.trade.exitQty : undefined,
|
701
|
+
entryValue: props.trade.entryValue !== undefined ? props.trade.entryValue : undefined,
|
702
|
+
exitValue: props.trade.exitValue !== undefined ? props.trade.exitValue : undefined,
|
703
|
+
entryTime: props.trade.entryTime !== undefined ? props.trade.entryTime : undefined,
|
704
|
+
exitTime: props.trade.exitTime !== undefined ? props.trade.exitTime : undefined,
|
705
|
+
pnlAmount: props.trade.pnlAmount !== undefined ? props.trade.pnlAmount : undefined,
|
706
|
+
pnlPercent: props.trade.pnlPercent !== undefined ? props.trade.pnlPercent : undefined,
|
707
|
+
durationMinutes: props.trade.durationMinutes !== undefined ? props.trade.durationMinutes : undefined,
|
708
|
+
marketPhase: props.trade.marketPhase !== undefined ? props.trade.marketPhase : undefined,
|
709
|
+
marketVolatility: props.trade.marketVolatility !== undefined ? props.trade.marketVolatility : undefined,
|
710
|
+
thresholdsJson: props.trade.thresholdsJson !== undefined ? props.trade.thresholdsJson : undefined,
|
711
|
+
},
|
712
|
+
}
|
713
|
+
} : undefined,
|
714
|
+
},
|
715
|
+
};
|
716
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
717
|
+
const response = await client.mutate({
|
718
|
+
mutation: UPSERT_ONE_ACTION,
|
719
|
+
variables: filteredVariables,
|
720
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
721
|
+
fetchPolicy: 'no-cache'
|
722
|
+
});
|
723
|
+
if (response.errors && response.errors.length > 0)
|
724
|
+
throw new Error(response.errors[0].message);
|
725
|
+
if (response && response.data && response.data.upsertOneAction) {
|
726
|
+
return response.data.upsertOneAction;
|
727
|
+
}
|
728
|
+
else {
|
729
|
+
return null;
|
730
|
+
}
|
731
|
+
}
|
732
|
+
catch (error) {
|
733
|
+
lastError = error;
|
734
|
+
// Check if this is a database connection error that we should retry
|
735
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
736
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
737
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
738
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
739
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
740
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
741
|
+
retryCount++;
|
742
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
743
|
+
console.warn("Database connection error, retrying...");
|
744
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
745
|
+
continue;
|
746
|
+
}
|
747
|
+
// Log the error and rethrow
|
748
|
+
console.error("Database error occurred:", error);
|
749
|
+
throw error;
|
586
750
|
}
|
587
751
|
}
|
588
|
-
|
589
|
-
|
590
|
-
throw error;
|
591
|
-
}
|
752
|
+
// If we exhausted retries, throw the last error
|
753
|
+
throw lastError;
|
592
754
|
},
|
593
755
|
/**
|
594
756
|
* Update multiple Action records.
|
757
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
595
758
|
* @param props - Array of Action objects for the updated records.
|
596
759
|
* @param globalClient - Apollo Client instance.
|
597
760
|
* @returns The count of created records or null.
|
598
761
|
*/
|
599
762
|
async updateMany(props, globalClient) {
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
} : undefined,
|
620
|
-
},
|
621
|
-
data: {
|
622
|
-
id: prop.id !== undefined ? {
|
623
|
-
set: prop.id
|
624
|
-
} : undefined,
|
625
|
-
sequence: prop.sequence !== undefined ? {
|
626
|
-
set: prop.sequence
|
627
|
-
} : undefined,
|
628
|
-
type: prop.type !== undefined ? {
|
629
|
-
set: prop.type
|
630
|
-
} : undefined,
|
631
|
-
primary: prop.primary !== undefined ? {
|
632
|
-
set: prop.primary
|
633
|
-
} : undefined,
|
634
|
-
note: prop.note !== undefined ? {
|
635
|
-
set: prop.note
|
636
|
-
} : undefined,
|
637
|
-
status: prop.status !== undefined ? {
|
638
|
-
set: prop.status
|
639
|
-
} : undefined,
|
640
|
-
createdAt: prop.createdAt !== undefined ? {
|
641
|
-
set: prop.createdAt
|
642
|
-
} : undefined,
|
643
|
-
updatedAt: prop.updatedAt !== undefined ? {
|
644
|
-
set: prop.updatedAt
|
645
|
-
} : undefined,
|
646
|
-
alpacaOrderId: prop.alpacaOrderId !== undefined ? {
|
647
|
-
set: prop.alpacaOrderId
|
648
|
-
} : undefined,
|
649
|
-
trade: prop.trade ?
|
650
|
-
typeof prop.trade === 'object' && Object.keys(prop.trade).length === 1 && (Object.keys(prop.trade)[0] === 'id' || Object.keys(prop.trade)[0] === 'symbol')
|
651
|
-
? {
|
652
|
-
connect: {
|
653
|
-
id: prop.trade.id
|
654
|
-
}
|
655
|
-
} : { upsert: {
|
656
|
-
where: {
|
657
|
-
id: prop.trade.id !== undefined ? {
|
658
|
-
equals: prop.trade.id
|
659
|
-
} : undefined,
|
660
|
-
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? {
|
661
|
-
equals: prop.trade.alpacaAccountId
|
662
|
-
} : undefined,
|
663
|
-
symbol: prop.trade.symbol !== undefined ? {
|
664
|
-
equals: prop.trade.symbol
|
665
|
-
} : undefined,
|
666
|
-
},
|
667
|
-
update: {
|
668
|
-
id: prop.trade.id !== undefined ? {
|
669
|
-
set: prop.trade.id
|
670
|
-
} : undefined,
|
671
|
-
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? {
|
672
|
-
set: prop.trade.alpacaAccountId
|
673
|
-
} : undefined,
|
674
|
-
signal: prop.trade.signal !== undefined ? {
|
675
|
-
set: prop.trade.signal
|
676
|
-
} : undefined,
|
677
|
-
strategy: prop.trade.strategy !== undefined ? {
|
678
|
-
set: prop.trade.strategy
|
679
|
-
} : undefined,
|
680
|
-
analysis: prop.trade.analysis !== undefined ? {
|
681
|
-
set: prop.trade.analysis
|
682
|
-
} : undefined,
|
683
|
-
summary: prop.trade.summary !== undefined ? {
|
684
|
-
set: prop.trade.summary
|
685
|
-
} : undefined,
|
686
|
-
confidence: prop.trade.confidence !== undefined ? {
|
687
|
-
set: prop.trade.confidence
|
688
|
-
} : undefined,
|
689
|
-
timestamp: prop.trade.timestamp !== undefined ? {
|
690
|
-
set: prop.trade.timestamp
|
691
|
-
} : undefined,
|
692
|
-
status: prop.trade.status !== undefined ? {
|
693
|
-
set: prop.trade.status
|
694
|
-
} : undefined,
|
695
|
-
symbol: prop.trade.symbol !== undefined ? {
|
696
|
-
set: prop.trade.symbol
|
697
|
-
} : undefined,
|
698
|
-
entryPrice: prop.trade.entryPrice !== undefined ? {
|
699
|
-
set: prop.trade.entryPrice
|
700
|
-
} : undefined,
|
701
|
-
exitPrice: prop.trade.exitPrice !== undefined ? {
|
702
|
-
set: prop.trade.exitPrice
|
703
|
-
} : undefined,
|
704
|
-
entryQty: prop.trade.entryQty !== undefined ? {
|
705
|
-
set: prop.trade.entryQty
|
706
|
-
} : undefined,
|
707
|
-
exitQty: prop.trade.exitQty !== undefined ? {
|
708
|
-
set: prop.trade.exitQty
|
709
|
-
} : undefined,
|
710
|
-
entryValue: prop.trade.entryValue !== undefined ? {
|
711
|
-
set: prop.trade.entryValue
|
712
|
-
} : undefined,
|
713
|
-
exitValue: prop.trade.exitValue !== undefined ? {
|
714
|
-
set: prop.trade.exitValue
|
715
|
-
} : undefined,
|
716
|
-
entryTime: prop.trade.entryTime !== undefined ? {
|
717
|
-
set: prop.trade.entryTime
|
718
|
-
} : undefined,
|
719
|
-
exitTime: prop.trade.exitTime !== undefined ? {
|
720
|
-
set: prop.trade.exitTime
|
721
|
-
} : undefined,
|
722
|
-
pnlAmount: prop.trade.pnlAmount !== undefined ? {
|
723
|
-
set: prop.trade.pnlAmount
|
724
|
-
} : undefined,
|
725
|
-
pnlPercent: prop.trade.pnlPercent !== undefined ? {
|
726
|
-
set: prop.trade.pnlPercent
|
727
|
-
} : undefined,
|
728
|
-
durationMinutes: prop.trade.durationMinutes !== undefined ? {
|
729
|
-
set: prop.trade.durationMinutes
|
730
|
-
} : undefined,
|
731
|
-
marketPhase: prop.trade.marketPhase !== undefined ? {
|
732
|
-
set: prop.trade.marketPhase
|
733
|
-
} : undefined,
|
734
|
-
marketVolatility: prop.trade.marketVolatility !== undefined ? {
|
735
|
-
set: prop.trade.marketVolatility
|
736
|
-
} : undefined,
|
737
|
-
thresholdsJson: prop.trade.thresholdsJson !== undefined ? {
|
738
|
-
set: prop.trade.thresholdsJson
|
739
|
-
} : undefined,
|
740
|
-
},
|
741
|
-
create: {
|
742
|
-
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? prop.trade.alpacaAccountId : undefined,
|
743
|
-
signal: prop.trade.signal !== undefined ? prop.trade.signal : undefined,
|
744
|
-
strategy: prop.trade.strategy !== undefined ? prop.trade.strategy : undefined,
|
745
|
-
analysis: prop.trade.analysis !== undefined ? prop.trade.analysis : undefined,
|
746
|
-
summary: prop.trade.summary !== undefined ? prop.trade.summary : undefined,
|
747
|
-
confidence: prop.trade.confidence !== undefined ? prop.trade.confidence : undefined,
|
748
|
-
timestamp: prop.trade.timestamp !== undefined ? prop.trade.timestamp : undefined,
|
749
|
-
status: prop.trade.status !== undefined ? prop.trade.status : undefined,
|
750
|
-
symbol: prop.trade.symbol !== undefined ? prop.trade.symbol : undefined,
|
751
|
-
entryPrice: prop.trade.entryPrice !== undefined ? prop.trade.entryPrice : undefined,
|
752
|
-
exitPrice: prop.trade.exitPrice !== undefined ? prop.trade.exitPrice : undefined,
|
753
|
-
entryQty: prop.trade.entryQty !== undefined ? prop.trade.entryQty : undefined,
|
754
|
-
exitQty: prop.trade.exitQty !== undefined ? prop.trade.exitQty : undefined,
|
755
|
-
entryValue: prop.trade.entryValue !== undefined ? prop.trade.entryValue : undefined,
|
756
|
-
exitValue: prop.trade.exitValue !== undefined ? prop.trade.exitValue : undefined,
|
757
|
-
entryTime: prop.trade.entryTime !== undefined ? prop.trade.entryTime : undefined,
|
758
|
-
exitTime: prop.trade.exitTime !== undefined ? prop.trade.exitTime : undefined,
|
759
|
-
pnlAmount: prop.trade.pnlAmount !== undefined ? prop.trade.pnlAmount : undefined,
|
760
|
-
pnlPercent: prop.trade.pnlPercent !== undefined ? prop.trade.pnlPercent : undefined,
|
761
|
-
durationMinutes: prop.trade.durationMinutes !== undefined ? prop.trade.durationMinutes : undefined,
|
762
|
-
marketPhase: prop.trade.marketPhase !== undefined ? prop.trade.marketPhase : undefined,
|
763
|
-
marketVolatility: prop.trade.marketVolatility !== undefined ? prop.trade.marketVolatility : undefined,
|
764
|
-
thresholdsJson: prop.trade.thresholdsJson !== undefined ? prop.trade.thresholdsJson : undefined,
|
765
|
-
},
|
766
|
-
}
|
767
|
-
} : undefined,
|
768
|
-
},
|
769
|
-
}));
|
770
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
771
|
-
try {
|
772
|
-
const response = await client.mutate({ mutation: UPDATE_MANY_ACTION, variables: filteredVariables });
|
773
|
-
if (response.errors && response.errors.length > 0)
|
774
|
-
throw new Error(response.errors[0].message);
|
775
|
-
if (response && response.data && response.data.updateManyAction) {
|
776
|
-
return response.data.updateManyAction;
|
763
|
+
var _a, _b, _c, _d, _e;
|
764
|
+
// Maximum number of retries for database connection issues
|
765
|
+
const MAX_RETRIES = 3;
|
766
|
+
let retryCount = 0;
|
767
|
+
let lastError = null;
|
768
|
+
// Retry loop to handle potential database connection issues
|
769
|
+
while (retryCount < MAX_RETRIES) {
|
770
|
+
try {
|
771
|
+
const [modules, client] = await Promise.all([
|
772
|
+
(0, client_1.getApolloModules)(),
|
773
|
+
globalClient
|
774
|
+
? Promise.resolve(globalClient)
|
775
|
+
: client_1.client
|
776
|
+
]);
|
777
|
+
const { gql, ApolloError } = modules;
|
778
|
+
const UPDATE_MANY_ACTION = gql `
|
779
|
+
mutation updateManyAction($data: [ActionCreateManyInput!]!) {
|
780
|
+
updateManyAction(data: $data) {
|
781
|
+
count
|
777
782
|
}
|
778
|
-
|
779
|
-
|
783
|
+
}`;
|
784
|
+
const variables = props.map(prop => ({
|
785
|
+
where: {
|
786
|
+
id: prop.id !== undefined ? prop.id : undefined,
|
787
|
+
alpacaOrderId: prop.alpacaOrderId !== undefined ? prop.alpacaOrderId : undefined,
|
788
|
+
sequence: prop.sequence !== undefined ? {
|
789
|
+
equals: prop.sequence
|
790
|
+
} : undefined,
|
791
|
+
tradeId: prop.tradeId !== undefined ? prop.tradeId : undefined,
|
792
|
+
type: prop.type !== undefined ? {
|
793
|
+
equals: prop.type
|
794
|
+
} : undefined,
|
795
|
+
note: prop.note !== undefined ? {
|
796
|
+
equals: prop.note
|
797
|
+
} : undefined,
|
798
|
+
status: prop.status !== undefined ? {
|
799
|
+
equals: prop.status
|
800
|
+
} : undefined,
|
801
|
+
createdAt: prop.createdAt !== undefined ? {
|
802
|
+
equals: prop.createdAt
|
803
|
+
} : undefined,
|
804
|
+
updatedAt: prop.updatedAt !== undefined ? {
|
805
|
+
equals: prop.updatedAt
|
806
|
+
} : undefined,
|
807
|
+
},
|
808
|
+
data: {
|
809
|
+
id: prop.id !== undefined ? {
|
810
|
+
set: prop.id
|
811
|
+
} : undefined,
|
812
|
+
sequence: prop.sequence !== undefined ? {
|
813
|
+
set: prop.sequence
|
814
|
+
} : undefined,
|
815
|
+
type: prop.type !== undefined ? {
|
816
|
+
set: prop.type
|
817
|
+
} : undefined,
|
818
|
+
primary: prop.primary !== undefined ? {
|
819
|
+
set: prop.primary
|
820
|
+
} : undefined,
|
821
|
+
note: prop.note !== undefined ? {
|
822
|
+
set: prop.note
|
823
|
+
} : undefined,
|
824
|
+
status: prop.status !== undefined ? {
|
825
|
+
set: prop.status
|
826
|
+
} : undefined,
|
827
|
+
createdAt: prop.createdAt !== undefined ? {
|
828
|
+
set: prop.createdAt
|
829
|
+
} : undefined,
|
830
|
+
updatedAt: prop.updatedAt !== undefined ? {
|
831
|
+
set: prop.updatedAt
|
832
|
+
} : undefined,
|
833
|
+
alpacaOrderId: prop.alpacaOrderId !== undefined ? {
|
834
|
+
set: prop.alpacaOrderId
|
835
|
+
} : undefined,
|
836
|
+
trade: prop.trade ?
|
837
|
+
typeof prop.trade === 'object' && Object.keys(prop.trade).length === 1 && (Object.keys(prop.trade)[0] === 'id' || Object.keys(prop.trade)[0] === 'symbol')
|
838
|
+
? {
|
839
|
+
connect: {
|
840
|
+
id: prop.trade.id
|
841
|
+
}
|
842
|
+
} : { upsert: {
|
843
|
+
where: {
|
844
|
+
id: prop.trade.id !== undefined ? {
|
845
|
+
equals: prop.trade.id
|
846
|
+
} : undefined,
|
847
|
+
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? {
|
848
|
+
equals: prop.trade.alpacaAccountId
|
849
|
+
} : undefined,
|
850
|
+
symbol: prop.trade.symbol !== undefined ? {
|
851
|
+
equals: prop.trade.symbol
|
852
|
+
} : undefined,
|
853
|
+
},
|
854
|
+
update: {
|
855
|
+
id: prop.trade.id !== undefined ? {
|
856
|
+
set: prop.trade.id
|
857
|
+
} : undefined,
|
858
|
+
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? {
|
859
|
+
set: prop.trade.alpacaAccountId
|
860
|
+
} : undefined,
|
861
|
+
signal: prop.trade.signal !== undefined ? {
|
862
|
+
set: prop.trade.signal
|
863
|
+
} : undefined,
|
864
|
+
strategy: prop.trade.strategy !== undefined ? {
|
865
|
+
set: prop.trade.strategy
|
866
|
+
} : undefined,
|
867
|
+
analysis: prop.trade.analysis !== undefined ? {
|
868
|
+
set: prop.trade.analysis
|
869
|
+
} : undefined,
|
870
|
+
summary: prop.trade.summary !== undefined ? {
|
871
|
+
set: prop.trade.summary
|
872
|
+
} : undefined,
|
873
|
+
confidence: prop.trade.confidence !== undefined ? {
|
874
|
+
set: prop.trade.confidence
|
875
|
+
} : undefined,
|
876
|
+
timestamp: prop.trade.timestamp !== undefined ? {
|
877
|
+
set: prop.trade.timestamp
|
878
|
+
} : undefined,
|
879
|
+
status: prop.trade.status !== undefined ? {
|
880
|
+
set: prop.trade.status
|
881
|
+
} : undefined,
|
882
|
+
symbol: prop.trade.symbol !== undefined ? {
|
883
|
+
set: prop.trade.symbol
|
884
|
+
} : undefined,
|
885
|
+
entryPrice: prop.trade.entryPrice !== undefined ? {
|
886
|
+
set: prop.trade.entryPrice
|
887
|
+
} : undefined,
|
888
|
+
exitPrice: prop.trade.exitPrice !== undefined ? {
|
889
|
+
set: prop.trade.exitPrice
|
890
|
+
} : undefined,
|
891
|
+
entryQty: prop.trade.entryQty !== undefined ? {
|
892
|
+
set: prop.trade.entryQty
|
893
|
+
} : undefined,
|
894
|
+
exitQty: prop.trade.exitQty !== undefined ? {
|
895
|
+
set: prop.trade.exitQty
|
896
|
+
} : undefined,
|
897
|
+
entryValue: prop.trade.entryValue !== undefined ? {
|
898
|
+
set: prop.trade.entryValue
|
899
|
+
} : undefined,
|
900
|
+
exitValue: prop.trade.exitValue !== undefined ? {
|
901
|
+
set: prop.trade.exitValue
|
902
|
+
} : undefined,
|
903
|
+
entryTime: prop.trade.entryTime !== undefined ? {
|
904
|
+
set: prop.trade.entryTime
|
905
|
+
} : undefined,
|
906
|
+
exitTime: prop.trade.exitTime !== undefined ? {
|
907
|
+
set: prop.trade.exitTime
|
908
|
+
} : undefined,
|
909
|
+
pnlAmount: prop.trade.pnlAmount !== undefined ? {
|
910
|
+
set: prop.trade.pnlAmount
|
911
|
+
} : undefined,
|
912
|
+
pnlPercent: prop.trade.pnlPercent !== undefined ? {
|
913
|
+
set: prop.trade.pnlPercent
|
914
|
+
} : undefined,
|
915
|
+
durationMinutes: prop.trade.durationMinutes !== undefined ? {
|
916
|
+
set: prop.trade.durationMinutes
|
917
|
+
} : undefined,
|
918
|
+
marketPhase: prop.trade.marketPhase !== undefined ? {
|
919
|
+
set: prop.trade.marketPhase
|
920
|
+
} : undefined,
|
921
|
+
marketVolatility: prop.trade.marketVolatility !== undefined ? {
|
922
|
+
set: prop.trade.marketVolatility
|
923
|
+
} : undefined,
|
924
|
+
thresholdsJson: prop.trade.thresholdsJson !== undefined ? {
|
925
|
+
set: prop.trade.thresholdsJson
|
926
|
+
} : undefined,
|
927
|
+
},
|
928
|
+
create: {
|
929
|
+
alpacaAccountId: prop.trade.alpacaAccountId !== undefined ? prop.trade.alpacaAccountId : undefined,
|
930
|
+
signal: prop.trade.signal !== undefined ? prop.trade.signal : undefined,
|
931
|
+
strategy: prop.trade.strategy !== undefined ? prop.trade.strategy : undefined,
|
932
|
+
analysis: prop.trade.analysis !== undefined ? prop.trade.analysis : undefined,
|
933
|
+
summary: prop.trade.summary !== undefined ? prop.trade.summary : undefined,
|
934
|
+
confidence: prop.trade.confidence !== undefined ? prop.trade.confidence : undefined,
|
935
|
+
timestamp: prop.trade.timestamp !== undefined ? prop.trade.timestamp : undefined,
|
936
|
+
status: prop.trade.status !== undefined ? prop.trade.status : undefined,
|
937
|
+
symbol: prop.trade.symbol !== undefined ? prop.trade.symbol : undefined,
|
938
|
+
entryPrice: prop.trade.entryPrice !== undefined ? prop.trade.entryPrice : undefined,
|
939
|
+
exitPrice: prop.trade.exitPrice !== undefined ? prop.trade.exitPrice : undefined,
|
940
|
+
entryQty: prop.trade.entryQty !== undefined ? prop.trade.entryQty : undefined,
|
941
|
+
exitQty: prop.trade.exitQty !== undefined ? prop.trade.exitQty : undefined,
|
942
|
+
entryValue: prop.trade.entryValue !== undefined ? prop.trade.entryValue : undefined,
|
943
|
+
exitValue: prop.trade.exitValue !== undefined ? prop.trade.exitValue : undefined,
|
944
|
+
entryTime: prop.trade.entryTime !== undefined ? prop.trade.entryTime : undefined,
|
945
|
+
exitTime: prop.trade.exitTime !== undefined ? prop.trade.exitTime : undefined,
|
946
|
+
pnlAmount: prop.trade.pnlAmount !== undefined ? prop.trade.pnlAmount : undefined,
|
947
|
+
pnlPercent: prop.trade.pnlPercent !== undefined ? prop.trade.pnlPercent : undefined,
|
948
|
+
durationMinutes: prop.trade.durationMinutes !== undefined ? prop.trade.durationMinutes : undefined,
|
949
|
+
marketPhase: prop.trade.marketPhase !== undefined ? prop.trade.marketPhase : undefined,
|
950
|
+
marketVolatility: prop.trade.marketVolatility !== undefined ? prop.trade.marketVolatility : undefined,
|
951
|
+
thresholdsJson: prop.trade.thresholdsJson !== undefined ? prop.trade.thresholdsJson : undefined,
|
952
|
+
},
|
953
|
+
}
|
954
|
+
} : undefined,
|
955
|
+
},
|
956
|
+
}));
|
957
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
958
|
+
const response = await client.mutate({
|
959
|
+
mutation: UPDATE_MANY_ACTION,
|
960
|
+
variables: filteredVariables,
|
961
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
962
|
+
fetchPolicy: 'no-cache'
|
963
|
+
});
|
964
|
+
if (response.errors && response.errors.length > 0)
|
965
|
+
throw new Error(response.errors[0].message);
|
966
|
+
if (response && response.data && response.data.updateManyAction) {
|
967
|
+
return response.data.updateManyAction;
|
968
|
+
}
|
969
|
+
else {
|
970
|
+
return null;
|
971
|
+
}
|
972
|
+
}
|
973
|
+
catch (error) {
|
974
|
+
lastError = error;
|
975
|
+
// Check if this is a database connection error that we should retry
|
976
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
977
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
978
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
979
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
980
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
981
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
982
|
+
retryCount++;
|
983
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
984
|
+
console.warn("Database connection error, retrying...");
|
985
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
986
|
+
continue;
|
987
|
+
}
|
988
|
+
// Log the error and rethrow
|
989
|
+
console.error("Database error occurred:", error);
|
990
|
+
throw error;
|
780
991
|
}
|
781
992
|
}
|
782
|
-
|
783
|
-
|
784
|
-
throw error;
|
785
|
-
}
|
993
|
+
// If we exhausted retries, throw the last error
|
994
|
+
throw lastError;
|
786
995
|
},
|
787
996
|
/**
|
788
997
|
* Delete a single Action record.
|
789
|
-
*
|
998
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
999
|
+
* @param props - Properties to identify the record to delete.
|
790
1000
|
* @param globalClient - Apollo Client instance.
|
791
1001
|
* @returns The deleted Action or null.
|
792
1002
|
*/
|
793
1003
|
async delete(props, globalClient) {
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
1004
|
+
var _a, _b, _c, _d, _e;
|
1005
|
+
// Maximum number of retries for database connection issues
|
1006
|
+
const MAX_RETRIES = 3;
|
1007
|
+
let retryCount = 0;
|
1008
|
+
let lastError = null;
|
1009
|
+
// Retry loop to handle potential database connection issues
|
1010
|
+
while (retryCount < MAX_RETRIES) {
|
1011
|
+
try {
|
1012
|
+
const [modules, client] = await Promise.all([
|
1013
|
+
(0, client_1.getApolloModules)(),
|
1014
|
+
globalClient
|
1015
|
+
? Promise.resolve(globalClient)
|
1016
|
+
: client_1.client
|
1017
|
+
]);
|
1018
|
+
const { gql, ApolloError } = modules;
|
1019
|
+
const DELETE_ONE_ACTION = gql `
|
1020
|
+
mutation deleteOneAction($where: ActionWhereUniqueInput!) {
|
1021
|
+
deleteOneAction(where: $where) {
|
1022
|
+
id
|
810
1023
|
}
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
1024
|
+
}`;
|
1025
|
+
const variables = {
|
1026
|
+
where: {
|
1027
|
+
id: props.id ? props.id : undefined,
|
1028
|
+
}
|
1029
|
+
};
|
1030
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
1031
|
+
const response = await client.mutate({
|
1032
|
+
mutation: DELETE_ONE_ACTION,
|
1033
|
+
variables: filteredVariables,
|
1034
|
+
// Don't cache mutations, but ensure we're using the freshest context
|
1035
|
+
fetchPolicy: 'no-cache'
|
1036
|
+
});
|
1037
|
+
if (response.errors && response.errors.length > 0)
|
1038
|
+
throw new Error(response.errors[0].message);
|
1039
|
+
if (response && response.data && response.data.deleteOneAction) {
|
1040
|
+
return response.data.deleteOneAction;
|
1041
|
+
}
|
1042
|
+
else {
|
1043
|
+
return null;
|
1044
|
+
}
|
819
1045
|
}
|
820
|
-
|
821
|
-
|
1046
|
+
catch (error) {
|
1047
|
+
lastError = error;
|
1048
|
+
// Check if this is a database connection error that we should retry
|
1049
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
1050
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
1051
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
1052
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
1053
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
1054
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
1055
|
+
retryCount++;
|
1056
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
1057
|
+
console.warn("Database connection error, retrying...");
|
1058
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
1059
|
+
continue;
|
1060
|
+
}
|
1061
|
+
// Log the error and rethrow
|
1062
|
+
console.error("Database error occurred:", error);
|
1063
|
+
throw error;
|
822
1064
|
}
|
823
1065
|
}
|
824
|
-
|
825
|
-
|
826
|
-
throw error;
|
827
|
-
}
|
1066
|
+
// If we exhausted retries, throw the last error
|
1067
|
+
throw lastError;
|
828
1068
|
},
|
829
1069
|
/**
|
830
1070
|
* Retrieve a single Action record by ID.
|
831
|
-
*
|
1071
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
1072
|
+
* @param props - Properties to identify the record.
|
832
1073
|
* @param globalClient - Apollo Client instance.
|
1074
|
+
* @param whereInput - Optional custom where input.
|
833
1075
|
* @returns The retrieved Action or null.
|
834
1076
|
*/
|
835
1077
|
async get(props, globalClient, whereInput) {
|
836
|
-
var _a, _b;
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
equals: props.tradeId
|
856
|
-
} : undefined,
|
857
|
-
},
|
858
|
-
};
|
859
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
860
|
-
try {
|
861
|
-
const response = await client.query({ query: GET_ACTION, variables: filteredVariables });
|
862
|
-
if (response.errors && response.errors.length > 0)
|
863
|
-
throw new Error(response.errors[0].message);
|
864
|
-
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getAction) !== null && _b !== void 0 ? _b : null;
|
865
|
-
}
|
866
|
-
catch (error) {
|
867
|
-
if (error instanceof ApolloError && error.message === 'No Action found') {
|
868
|
-
return null;
|
1078
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
1079
|
+
// Maximum number of retries for database connection issues
|
1080
|
+
const MAX_RETRIES = 3;
|
1081
|
+
let retryCount = 0;
|
1082
|
+
let lastError = null;
|
1083
|
+
// Retry loop to handle potential database connection issues
|
1084
|
+
while (retryCount < MAX_RETRIES) {
|
1085
|
+
try {
|
1086
|
+
const [modules, client] = await Promise.all([
|
1087
|
+
(0, client_1.getApolloModules)(),
|
1088
|
+
globalClient
|
1089
|
+
? Promise.resolve(globalClient)
|
1090
|
+
: client_1.client
|
1091
|
+
]);
|
1092
|
+
const { gql, ApolloError } = modules;
|
1093
|
+
const GET_ACTION = gql `
|
1094
|
+
query getAction($where: ActionWhereUniqueInput!) {
|
1095
|
+
getAction(where: $where) {
|
1096
|
+
${selectionSet}
|
869
1097
|
}
|
870
|
-
|
871
|
-
|
1098
|
+
}`;
|
1099
|
+
const variables = {
|
1100
|
+
where: whereInput ? whereInput : {
|
1101
|
+
id: props.id !== undefined ? props.id : undefined,
|
1102
|
+
alpacaOrderId: props.alpacaOrderId !== undefined ? props.alpacaOrderId : undefined,
|
1103
|
+
sequence: props.sequence !== undefined ? {
|
1104
|
+
equals: props.sequence
|
1105
|
+
} : undefined,
|
1106
|
+
tradeId: props.tradeId !== undefined ? props.tradeId : undefined,
|
1107
|
+
type: props.type !== undefined ? {
|
1108
|
+
equals: props.type
|
1109
|
+
} : undefined,
|
1110
|
+
note: props.note !== undefined ? {
|
1111
|
+
equals: props.note
|
1112
|
+
} : undefined,
|
1113
|
+
status: props.status !== undefined ? {
|
1114
|
+
equals: props.status
|
1115
|
+
} : undefined,
|
1116
|
+
createdAt: props.createdAt !== undefined ? {
|
1117
|
+
equals: props.createdAt
|
1118
|
+
} : undefined,
|
1119
|
+
updatedAt: props.updatedAt !== undefined ? {
|
1120
|
+
equals: props.updatedAt
|
1121
|
+
} : undefined,
|
1122
|
+
},
|
1123
|
+
};
|
1124
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
1125
|
+
const response = await client.query({
|
1126
|
+
query: GET_ACTION,
|
1127
|
+
variables: filteredVariables,
|
1128
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
1129
|
+
});
|
1130
|
+
if (response.errors && response.errors.length > 0)
|
1131
|
+
throw new Error(response.errors[0].message);
|
1132
|
+
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.getAction) !== null && _b !== void 0 ? _b : null;
|
1133
|
+
}
|
1134
|
+
catch (error) {
|
1135
|
+
lastError = error;
|
1136
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
1137
|
+
if (error.message === 'No Action found') {
|
1138
|
+
return null;
|
1139
|
+
}
|
1140
|
+
// Check if this is a database connection error that we should retry
|
1141
|
+
const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
|
1142
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
|
1143
|
+
((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
|
1144
|
+
((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
1145
|
+
(error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
|
1146
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
1147
|
+
retryCount++;
|
1148
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
1149
|
+
console.warn("Database connection error, retrying...");
|
1150
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
1151
|
+
continue;
|
1152
|
+
}
|
1153
|
+
// Log the error and rethrow
|
1154
|
+
console.error("Database error occurred:", error);
|
872
1155
|
throw error;
|
873
1156
|
}
|
874
1157
|
}
|
1158
|
+
// If we exhausted retries, throw the last error
|
1159
|
+
throw lastError;
|
875
1160
|
},
|
876
1161
|
/**
|
877
1162
|
* Retrieve all Actions records.
|
1163
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
878
1164
|
* @param globalClient - Apollo Client instance.
|
879
1165
|
* @returns An array of Action records or null.
|
880
1166
|
*/
|
881
1167
|
async getAll(globalClient) {
|
882
|
-
var _a, _b;
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
}
|
902
|
-
catch (error) {
|
903
|
-
if (error instanceof ApolloError && error.message === 'No Action found') {
|
904
|
-
return null;
|
1168
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
1169
|
+
// Maximum number of retries for database connection issues
|
1170
|
+
const MAX_RETRIES = 3;
|
1171
|
+
let retryCount = 0;
|
1172
|
+
let lastError = null;
|
1173
|
+
// Retry loop to handle potential database connection issues
|
1174
|
+
while (retryCount < MAX_RETRIES) {
|
1175
|
+
try {
|
1176
|
+
const [modules, client] = await Promise.all([
|
1177
|
+
(0, client_1.getApolloModules)(),
|
1178
|
+
globalClient
|
1179
|
+
? Promise.resolve(globalClient)
|
1180
|
+
: client_1.client
|
1181
|
+
]);
|
1182
|
+
const { gql, ApolloError } = modules;
|
1183
|
+
const GET_ALL_ACTION = gql `
|
1184
|
+
query getAllAction {
|
1185
|
+
actions {
|
1186
|
+
${selectionSet}
|
905
1187
|
}
|
906
|
-
|
907
|
-
|
1188
|
+
}`;
|
1189
|
+
const response = await client.query({
|
1190
|
+
query: GET_ALL_ACTION,
|
1191
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
1192
|
+
});
|
1193
|
+
if (response.errors && response.errors.length > 0)
|
1194
|
+
throw new Error(response.errors[0].message);
|
1195
|
+
return (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.actions) !== null && _b !== void 0 ? _b : null;
|
1196
|
+
}
|
1197
|
+
catch (error) {
|
1198
|
+
lastError = error;
|
1199
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
1200
|
+
if (error.message === 'No Action found') {
|
1201
|
+
return null;
|
1202
|
+
}
|
1203
|
+
// Check if this is a database connection error that we should retry
|
1204
|
+
const isConnectionError = ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Server has closed the connection')) ||
|
1205
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Cannot reach database server')) ||
|
1206
|
+
((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('Connection timed out')) ||
|
1207
|
+
((_f = error.message) === null || _f === void 0 ? void 0 : _f.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
1208
|
+
(error.networkError && ((_g = error.networkError.message) === null || _g === void 0 ? void 0 : _g.includes('Failed to fetch')));
|
1209
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
1210
|
+
retryCount++;
|
1211
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
1212
|
+
console.warn("Database connection error, retrying...");
|
1213
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
1214
|
+
continue;
|
1215
|
+
}
|
1216
|
+
// Log the error and rethrow
|
1217
|
+
console.error("Database error occurred:", error);
|
908
1218
|
throw error;
|
909
1219
|
}
|
910
1220
|
}
|
1221
|
+
// If we exhausted retries, throw the last error
|
1222
|
+
throw lastError;
|
911
1223
|
},
|
912
1224
|
/**
|
913
1225
|
* Find multiple Action records based on conditions.
|
1226
|
+
* Enhanced with connection resilience against Prisma connection errors.
|
914
1227
|
* @param props - Conditions to find records.
|
915
1228
|
* @param globalClient - Apollo Client instance.
|
1229
|
+
* @param whereInput - Optional custom where input.
|
916
1230
|
* @returns An array of found Action records or null.
|
917
1231
|
*/
|
918
1232
|
async findMany(props, globalClient, whereInput) {
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
equals: props.tradeId
|
939
|
-
} : undefined,
|
940
|
-
},
|
941
|
-
};
|
942
|
-
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
943
|
-
try {
|
944
|
-
const response = await client.query({ query: FIND_MANY_ACTION, variables: filteredVariables });
|
945
|
-
if (response.errors && response.errors.length > 0)
|
946
|
-
throw new Error(response.errors[0].message);
|
947
|
-
if (response && response.data && response.data.actions) {
|
948
|
-
return response.data.actions;
|
949
|
-
}
|
950
|
-
else {
|
951
|
-
return [];
|
1233
|
+
var _a, _b, _c, _d, _e;
|
1234
|
+
// Maximum number of retries for database connection issues
|
1235
|
+
const MAX_RETRIES = 3;
|
1236
|
+
let retryCount = 0;
|
1237
|
+
let lastError = null;
|
1238
|
+
// Retry loop to handle potential database connection issues
|
1239
|
+
while (retryCount < MAX_RETRIES) {
|
1240
|
+
try {
|
1241
|
+
const [modules, client] = await Promise.all([
|
1242
|
+
(0, client_1.getApolloModules)(),
|
1243
|
+
globalClient
|
1244
|
+
? Promise.resolve(globalClient)
|
1245
|
+
: client_1.client
|
1246
|
+
]);
|
1247
|
+
const { gql, ApolloError } = modules;
|
1248
|
+
const FIND_MANY_ACTION = gql `
|
1249
|
+
query findManyAction($where: ActionWhereInput!) {
|
1250
|
+
actions(where: $where) {
|
1251
|
+
${selectionSet}
|
952
1252
|
}
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
1253
|
+
}`;
|
1254
|
+
const variables = {
|
1255
|
+
where: whereInput ? whereInput : {
|
1256
|
+
id: props.id !== undefined ? props.id : undefined,
|
1257
|
+
sequence: props.sequence !== undefined ? {
|
1258
|
+
equals: props.sequence
|
1259
|
+
} : undefined,
|
1260
|
+
tradeId: props.tradeId !== undefined ? props.tradeId : undefined,
|
1261
|
+
type: props.type !== undefined ? {
|
1262
|
+
equals: props.type
|
1263
|
+
} : undefined,
|
1264
|
+
note: props.note !== undefined ? {
|
1265
|
+
equals: props.note
|
1266
|
+
} : undefined,
|
1267
|
+
status: props.status !== undefined ? {
|
1268
|
+
equals: props.status
|
1269
|
+
} : undefined,
|
1270
|
+
createdAt: props.createdAt !== undefined ? {
|
1271
|
+
equals: props.createdAt
|
1272
|
+
} : undefined,
|
1273
|
+
updatedAt: props.updatedAt !== undefined ? {
|
1274
|
+
equals: props.updatedAt
|
1275
|
+
} : undefined,
|
1276
|
+
},
|
1277
|
+
};
|
1278
|
+
const filteredVariables = (0, utils_1.removeUndefinedProps)(variables);
|
1279
|
+
const response = await client.query({
|
1280
|
+
query: FIND_MANY_ACTION,
|
1281
|
+
variables: filteredVariables,
|
1282
|
+
fetchPolicy: 'network-only', // Force network request to avoid stale cache
|
1283
|
+
});
|
1284
|
+
if (response.errors && response.errors.length > 0)
|
1285
|
+
throw new Error(response.errors[0].message);
|
1286
|
+
if (response && response.data && response.data.actions) {
|
1287
|
+
return response.data.actions;
|
1288
|
+
}
|
1289
|
+
else {
|
1290
|
+
return [];
|
1291
|
+
}
|
957
1292
|
}
|
958
|
-
|
959
|
-
|
1293
|
+
catch (error) {
|
1294
|
+
lastError = error;
|
1295
|
+
// Check if this is a "No record found" error - this is an expected condition, not a failure
|
1296
|
+
if (error.message === 'No Action found') {
|
1297
|
+
return null;
|
1298
|
+
}
|
1299
|
+
// Check if this is a database connection error that we should retry
|
1300
|
+
const isConnectionError = ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Server has closed the connection')) ||
|
1301
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Cannot reach database server')) ||
|
1302
|
+
((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes('Connection timed out')) ||
|
1303
|
+
((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('Accelerate')) || // Prisma Accelerate proxy errors
|
1304
|
+
(error.networkError && ((_e = error.networkError.message) === null || _e === void 0 ? void 0 : _e.includes('Failed to fetch')));
|
1305
|
+
if (isConnectionError && retryCount < MAX_RETRIES - 1) {
|
1306
|
+
retryCount++;
|
1307
|
+
const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
|
1308
|
+
console.warn("Database connection error, retrying...");
|
1309
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
1310
|
+
continue;
|
1311
|
+
}
|
1312
|
+
// Log the error and rethrow
|
1313
|
+
console.error("Database error occurred:", error);
|
960
1314
|
throw error;
|
961
1315
|
}
|
962
1316
|
}
|
1317
|
+
// If we exhausted retries, throw the last error
|
1318
|
+
throw lastError;
|
963
1319
|
}
|
964
1320
|
};
|
965
1321
|
//# sourceMappingURL=Action.js.map
|