@friggframework/core 2.0.0--canary.517.095e3f6.0 → 2.0.0--canary.517.06fe141.0
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/admin-scripts/index.js +11 -11
- package/admin-scripts/repositories/{admin-process-repository-documentdb.js → admin-script-execution-repository-documentdb.js} +4 -4
- package/admin-scripts/repositories/{admin-process-repository-factory.js → admin-script-execution-repository-factory.js} +14 -14
- package/admin-scripts/repositories/{admin-process-repository-interface.js → admin-script-execution-repository-interface.js} +19 -19
- package/admin-scripts/repositories/{admin-process-repository-mongo.js → admin-script-execution-repository-mongo.js} +24 -24
- package/admin-scripts/repositories/{admin-process-repository-postgres.js → admin-script-execution-repository-postgres.js} +33 -33
- package/application/commands/admin-script-commands.js +35 -35
- package/application/commands/integration-commands.js +43 -4
- package/generated/prisma-mongodb/edge.js +8 -15
- package/generated/prisma-mongodb/index-browser.js +5 -5
- package/generated/prisma-mongodb/index.d.ts +480 -494
- package/generated/prisma-mongodb/index.js +8 -15
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +6 -14
- package/generated/prisma-mongodb/wasm.js +8 -15
- package/generated/prisma-postgresql/edge.js +7 -14
- package/generated/prisma-postgresql/index-browser.js +4 -4
- package/generated/prisma-postgresql/index.d.ts +699 -713
- package/generated/prisma-postgresql/index.js +7 -14
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +6 -14
- package/generated/prisma-postgresql/wasm.js +7 -14
- package/integrations/repositories/integration-repository-documentdb.js +12 -0
- package/integrations/repositories/integration-repository-interface.js +14 -0
- package/integrations/repositories/integration-repository-mongo.js +36 -0
- package/integrations/repositories/integration-repository-postgres.js +39 -0
- package/integrations/tests/doubles/test-integration-repository.js +11 -0
- package/package.json +5 -5
- package/prisma-mongodb/schema.prisma +6 -14
- package/prisma-postgresql/schema.prisma +6 -14
package/admin-scripts/index.js
CHANGED
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
// Repository Interfaces
|
|
19
|
-
const {
|
|
19
|
+
const { AdminScriptExecutionRepositoryInterface } = require('./repositories/admin-script-execution-repository-interface');
|
|
20
20
|
const { ScriptScheduleRepositoryInterface } = require('./repositories/script-schedule-repository-interface');
|
|
21
21
|
|
|
22
22
|
// Repository Factories
|
|
23
23
|
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = require('./repositories/admin-
|
|
24
|
+
createAdminScriptExecutionRepository,
|
|
25
|
+
AdminScriptExecutionRepositoryMongo,
|
|
26
|
+
AdminScriptExecutionRepositoryPostgres,
|
|
27
|
+
AdminScriptExecutionRepositoryDocumentDB,
|
|
28
|
+
} = require('./repositories/admin-script-execution-repository-factory');
|
|
29
29
|
const {
|
|
30
30
|
createScriptScheduleRepository,
|
|
31
31
|
ScriptScheduleRepositoryMongo,
|
|
@@ -35,17 +35,17 @@ const {
|
|
|
35
35
|
|
|
36
36
|
module.exports = {
|
|
37
37
|
// Repository Interfaces
|
|
38
|
-
|
|
38
|
+
AdminScriptExecutionRepositoryInterface,
|
|
39
39
|
ScriptScheduleRepositoryInterface,
|
|
40
40
|
|
|
41
41
|
// Repository Factories (primary exports for use cases)
|
|
42
|
-
|
|
42
|
+
createAdminScriptExecutionRepository,
|
|
43
43
|
createScriptScheduleRepository,
|
|
44
44
|
|
|
45
45
|
// Concrete Implementations (for testing)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
AdminScriptExecutionRepositoryMongo,
|
|
47
|
+
AdminScriptExecutionRepositoryPostgres,
|
|
48
|
+
AdminScriptExecutionRepositoryDocumentDB,
|
|
49
49
|
ScriptScheduleRepositoryMongo,
|
|
50
50
|
ScriptScheduleRepositoryPostgres,
|
|
51
51
|
ScriptScheduleRepositoryDocumentDB,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const {
|
|
2
|
-
|
|
3
|
-
} = require('./admin-
|
|
2
|
+
AdminScriptExecutionRepositoryMongo,
|
|
3
|
+
} = require('./admin-script-execution-repository-mongo');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* DocumentDB Admin Process Repository Adapter
|
|
@@ -12,10 +12,10 @@ const {
|
|
|
12
12
|
* - IDs are strings with ObjectId format
|
|
13
13
|
* - All operations identical to MongoDB implementation
|
|
14
14
|
*/
|
|
15
|
-
class
|
|
15
|
+
class AdminScriptExecutionRepositoryDocumentDB extends AdminScriptExecutionRepositoryMongo {
|
|
16
16
|
constructor() {
|
|
17
17
|
super();
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
module.exports = {
|
|
21
|
+
module.exports = { AdminScriptExecutionRepositoryDocumentDB };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const {
|
|
1
|
+
const { AdminScriptExecutionRepositoryMongo } = require('./admin-script-execution-repository-mongo');
|
|
2
|
+
const { AdminScriptExecutionRepositoryPostgres } = require('./admin-script-execution-repository-postgres');
|
|
3
3
|
const {
|
|
4
|
-
|
|
5
|
-
} = require('./admin-
|
|
4
|
+
AdminScriptExecutionRepositoryDocumentDB,
|
|
5
|
+
} = require('./admin-script-execution-repository-documentdb');
|
|
6
6
|
const config = require('../../database/config');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -16,24 +16,24 @@ const config = require('../../database/config');
|
|
|
16
16
|
*
|
|
17
17
|
* Usage:
|
|
18
18
|
* ```javascript
|
|
19
|
-
* const repository =
|
|
19
|
+
* const repository = createAdminScriptExecutionRepository();
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* @returns {
|
|
22
|
+
* @returns {AdminScriptExecutionRepositoryInterface} Configured repository adapter
|
|
23
23
|
* @throws {Error} If database type is not supported
|
|
24
24
|
*/
|
|
25
|
-
function
|
|
25
|
+
function createAdminScriptExecutionRepository() {
|
|
26
26
|
const dbType = config.DB_TYPE;
|
|
27
27
|
|
|
28
28
|
switch (dbType) {
|
|
29
29
|
case 'mongodb':
|
|
30
|
-
return new
|
|
30
|
+
return new AdminScriptExecutionRepositoryMongo();
|
|
31
31
|
|
|
32
32
|
case 'postgresql':
|
|
33
|
-
return new
|
|
33
|
+
return new AdminScriptExecutionRepositoryPostgres();
|
|
34
34
|
|
|
35
35
|
case 'documentdb':
|
|
36
|
-
return new
|
|
36
|
+
return new AdminScriptExecutionRepositoryDocumentDB();
|
|
37
37
|
|
|
38
38
|
default:
|
|
39
39
|
throw new Error(
|
|
@@ -43,9 +43,9 @@ function createAdminProcessRepository() {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
module.exports = {
|
|
46
|
-
|
|
46
|
+
createAdminScriptExecutionRepository,
|
|
47
47
|
// Export adapters for direct testing
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
AdminScriptExecutionRepositoryMongo,
|
|
49
|
+
AdminScriptExecutionRepositoryPostgres,
|
|
50
|
+
AdminScriptExecutionRepositoryDocumentDB,
|
|
51
51
|
};
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
* - Database migrations
|
|
13
13
|
* - Scheduled maintenance tasks
|
|
14
14
|
*
|
|
15
|
-
* The
|
|
15
|
+
* The AdminScriptExecution model uses a flexible JSON storage pattern:
|
|
16
16
|
* - context: Input parameters, trigger info, audit data, script version
|
|
17
17
|
* - results: Output data, logs, metrics, error details
|
|
18
18
|
*
|
|
19
19
|
* @abstract
|
|
20
20
|
*/
|
|
21
|
-
class
|
|
21
|
+
class AdminScriptExecutionRepositoryInterface {
|
|
22
22
|
/**
|
|
23
23
|
* Create a new admin process record
|
|
24
24
|
*
|
|
@@ -37,8 +37,8 @@ class AdminProcessRepositoryInterface {
|
|
|
37
37
|
* @returns {Promise<Object>} The created process record
|
|
38
38
|
* @abstract
|
|
39
39
|
*/
|
|
40
|
-
async
|
|
41
|
-
throw new Error('Method
|
|
40
|
+
async createExecution({ name, type, context }) {
|
|
41
|
+
throw new Error('Method createExecution must be implemented by subclass');
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -48,9 +48,9 @@ class AdminProcessRepositoryInterface {
|
|
|
48
48
|
* @returns {Promise<Object|null>} The process record or null if not found
|
|
49
49
|
* @abstract
|
|
50
50
|
*/
|
|
51
|
-
async
|
|
51
|
+
async findExecutionById(id) {
|
|
52
52
|
throw new Error(
|
|
53
|
-
'Method
|
|
53
|
+
'Method findExecutionById must be implemented by subclass'
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -67,9 +67,9 @@ class AdminProcessRepositoryInterface {
|
|
|
67
67
|
* @returns {Promise<Array>} Array of process records
|
|
68
68
|
* @abstract
|
|
69
69
|
*/
|
|
70
|
-
async
|
|
70
|
+
async findExecutionsByName(name, options = {}) {
|
|
71
71
|
throw new Error(
|
|
72
|
-
'Method
|
|
72
|
+
'Method findExecutionsByName must be implemented by subclass'
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -85,9 +85,9 @@ class AdminProcessRepositoryInterface {
|
|
|
85
85
|
* @returns {Promise<Array>} Array of process records
|
|
86
86
|
* @abstract
|
|
87
87
|
*/
|
|
88
|
-
async
|
|
88
|
+
async findExecutionsByState(state, options = {}) {
|
|
89
89
|
throw new Error(
|
|
90
|
-
'Method
|
|
90
|
+
'Method findExecutionsByState must be implemented by subclass'
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -99,9 +99,9 @@ class AdminProcessRepositoryInterface {
|
|
|
99
99
|
* @returns {Promise<Object>} Updated process record
|
|
100
100
|
* @abstract
|
|
101
101
|
*/
|
|
102
|
-
async
|
|
102
|
+
async updateExecutionState(id, state) {
|
|
103
103
|
throw new Error(
|
|
104
|
-
'Method
|
|
104
|
+
'Method updateExecutionState must be implemented by subclass'
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -123,9 +123,9 @@ class AdminProcessRepositoryInterface {
|
|
|
123
123
|
* @returns {Promise<Object>} Updated process record
|
|
124
124
|
* @abstract
|
|
125
125
|
*/
|
|
126
|
-
async
|
|
126
|
+
async updateExecutionResults(id, results) {
|
|
127
127
|
throw new Error(
|
|
128
|
-
'Method
|
|
128
|
+
'Method updateExecutionResults must be implemented by subclass'
|
|
129
129
|
);
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -141,9 +141,9 @@ class AdminProcessRepositoryInterface {
|
|
|
141
141
|
* @returns {Promise<Object>} Updated process record
|
|
142
142
|
* @abstract
|
|
143
143
|
*/
|
|
144
|
-
async
|
|
144
|
+
async appendExecutionLog(id, logEntry) {
|
|
145
145
|
throw new Error(
|
|
146
|
-
'Method
|
|
146
|
+
'Method appendExecutionLog must be implemented by subclass'
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -155,11 +155,11 @@ class AdminProcessRepositoryInterface {
|
|
|
155
155
|
* @returns {Promise<Object>} Deletion result with count
|
|
156
156
|
* @abstract
|
|
157
157
|
*/
|
|
158
|
-
async
|
|
158
|
+
async deleteExecutionsOlderThan(date) {
|
|
159
159
|
throw new Error(
|
|
160
|
-
'Method
|
|
160
|
+
'Method deleteExecutionsOlderThan must be implemented by subclass'
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
module.exports = {
|
|
165
|
+
module.exports = { AdminScriptExecutionRepositoryInterface };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { prisma } = require('../../database/prisma');
|
|
2
2
|
const {
|
|
3
|
-
|
|
4
|
-
} = require('./admin-
|
|
3
|
+
AdminScriptExecutionRepositoryInterface,
|
|
4
|
+
} = require('./admin-script-execution-repository-interface');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* MongoDB Admin Process Repository Adapter
|
|
@@ -12,7 +12,7 @@ const {
|
|
|
12
12
|
* - context and results are Json objects
|
|
13
13
|
* - Stores logs in results.logs array
|
|
14
14
|
*/
|
|
15
|
-
class
|
|
15
|
+
class AdminScriptExecutionRepositoryMongo extends AdminScriptExecutionRepositoryInterface {
|
|
16
16
|
constructor() {
|
|
17
17
|
super();
|
|
18
18
|
this.prisma = prisma;
|
|
@@ -27,7 +27,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
27
27
|
* @param {Object} [params.context] - Context data
|
|
28
28
|
* @returns {Promise<Object>} The created process record
|
|
29
29
|
*/
|
|
30
|
-
async
|
|
30
|
+
async createExecution({ name, type, context = {} }) {
|
|
31
31
|
const data = {
|
|
32
32
|
name,
|
|
33
33
|
type,
|
|
@@ -35,7 +35,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
35
35
|
results: { logs: [] },
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const process = await this.prisma.
|
|
38
|
+
const process = await this.prisma.adminScriptExecution.create({
|
|
39
39
|
data,
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -48,8 +48,8 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
48
48
|
* @param {string} id - The process ID
|
|
49
49
|
* @returns {Promise<Object|null>} The process record or null if not found
|
|
50
50
|
*/
|
|
51
|
-
async
|
|
52
|
-
const process = await this.prisma.
|
|
51
|
+
async findExecutionById(id) {
|
|
52
|
+
const process = await this.prisma.adminScriptExecution.findUnique({
|
|
53
53
|
where: { id },
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -67,7 +67,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
67
67
|
* @param {string} [options.sortOrder] - Sort order ('asc' or 'desc')
|
|
68
68
|
* @returns {Promise<Array>} Array of process records
|
|
69
69
|
*/
|
|
70
|
-
async
|
|
70
|
+
async findExecutionsByName(name, options = {}) {
|
|
71
71
|
const {
|
|
72
72
|
limit,
|
|
73
73
|
offset,
|
|
@@ -79,7 +79,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
79
79
|
const where = { name };
|
|
80
80
|
if (state) where.state = state;
|
|
81
81
|
|
|
82
|
-
const processes = await this.prisma.
|
|
82
|
+
const processes = await this.prisma.adminScriptExecution.findMany({
|
|
83
83
|
where,
|
|
84
84
|
orderBy: { [sortBy]: sortOrder },
|
|
85
85
|
take: limit,
|
|
@@ -100,7 +100,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
100
100
|
* @param {string} [options.sortOrder] - Sort order ('asc' or 'desc')
|
|
101
101
|
* @returns {Promise<Array>} Array of process records
|
|
102
102
|
*/
|
|
103
|
-
async
|
|
103
|
+
async findExecutionsByState(state, options = {}) {
|
|
104
104
|
const {
|
|
105
105
|
limit,
|
|
106
106
|
offset,
|
|
@@ -108,7 +108,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
108
108
|
sortOrder = 'desc',
|
|
109
109
|
} = options;
|
|
110
110
|
|
|
111
|
-
const processes = await this.prisma.
|
|
111
|
+
const processes = await this.prisma.adminScriptExecution.findMany({
|
|
112
112
|
where: { state },
|
|
113
113
|
orderBy: { [sortBy]: sortOrder },
|
|
114
114
|
take: limit,
|
|
@@ -125,8 +125,8 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
125
125
|
* @param {string} state - New state value
|
|
126
126
|
* @returns {Promise<Object>} Updated process record
|
|
127
127
|
*/
|
|
128
|
-
async
|
|
129
|
-
const process = await this.prisma.
|
|
128
|
+
async updateExecutionState(id, state) {
|
|
129
|
+
const process = await this.prisma.adminScriptExecution.update({
|
|
130
130
|
where: { id },
|
|
131
131
|
data: { state },
|
|
132
132
|
});
|
|
@@ -142,14 +142,14 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
142
142
|
* @param {Object} results - Results data to merge
|
|
143
143
|
* @returns {Promise<Object>} Updated process record
|
|
144
144
|
*/
|
|
145
|
-
async
|
|
145
|
+
async updateExecutionResults(id, results) {
|
|
146
146
|
// Get current process to merge results
|
|
147
|
-
const currentProcess = await this.prisma.
|
|
147
|
+
const currentProcess = await this.prisma.adminScriptExecution.findUnique({
|
|
148
148
|
where: { id },
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
if (!currentProcess) {
|
|
152
|
-
throw new Error(`
|
|
152
|
+
throw new Error(`AdminScriptExecution ${id} not found`);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// Merge new results with existing results
|
|
@@ -158,7 +158,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
158
158
|
...results,
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
const process = await this.prisma.
|
|
161
|
+
const process = await this.prisma.adminScriptExecution.update({
|
|
162
162
|
where: { id },
|
|
163
163
|
data: { results: mergedResults },
|
|
164
164
|
});
|
|
@@ -177,14 +177,14 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
177
177
|
* @param {string} logEntry.timestamp - ISO timestamp
|
|
178
178
|
* @returns {Promise<Object>} Updated process record
|
|
179
179
|
*/
|
|
180
|
-
async
|
|
180
|
+
async appendExecutionLog(id, logEntry) {
|
|
181
181
|
// Get current process
|
|
182
|
-
const process = await this.prisma.
|
|
182
|
+
const process = await this.prisma.adminScriptExecution.findUnique({
|
|
183
183
|
where: { id },
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
if (!process) {
|
|
187
|
-
throw new Error(`
|
|
187
|
+
throw new Error(`AdminScriptExecution ${id} not found`);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// Get current results and logs
|
|
@@ -193,7 +193,7 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
193
193
|
logs.push(logEntry);
|
|
194
194
|
|
|
195
195
|
// Update with new logs array in results
|
|
196
|
-
const updated = await this.prisma.
|
|
196
|
+
const updated = await this.prisma.adminScriptExecution.update({
|
|
197
197
|
where: { id },
|
|
198
198
|
data: { results: { ...results, logs } },
|
|
199
199
|
});
|
|
@@ -208,8 +208,8 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
208
208
|
* @param {Date} date - Delete processes older than this date
|
|
209
209
|
* @returns {Promise<Object>} Deletion result with count
|
|
210
210
|
*/
|
|
211
|
-
async
|
|
212
|
-
const result = await this.prisma.
|
|
211
|
+
async deleteExecutionsOlderThan(date) {
|
|
212
|
+
const result = await this.prisma.adminScriptExecution.deleteMany({
|
|
213
213
|
where: {
|
|
214
214
|
createdAt: {
|
|
215
215
|
lt: date,
|
|
@@ -224,4 +224,4 @@ class AdminProcessRepositoryMongo extends AdminProcessRepositoryInterface {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
module.exports = {
|
|
227
|
+
module.exports = { AdminScriptExecutionRepositoryMongo };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { prisma } = require('../../database/prisma');
|
|
2
2
|
const {
|
|
3
|
-
|
|
4
|
-
} = require('./admin-
|
|
3
|
+
AdminScriptExecutionRepositoryInterface,
|
|
4
|
+
} = require('./admin-script-execution-repository-interface');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* PostgreSQL Admin Process Repository Adapter
|
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
* - All returned IDs are converted to strings for application layer consistency
|
|
14
14
|
* - context and results are Json objects
|
|
15
15
|
*/
|
|
16
|
-
class
|
|
16
|
+
class AdminScriptExecutionRepositoryPostgres extends AdminScriptExecutionRepositoryInterface {
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
19
|
this.prisma = prisma;
|
|
@@ -41,12 +41,12 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
41
41
|
* @param {Object|null} process - Process object from database
|
|
42
42
|
* @returns {Object|null} Process with string IDs
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
_convertExecutionIds(process) {
|
|
45
45
|
if (!process) return process;
|
|
46
46
|
return {
|
|
47
47
|
...process,
|
|
48
48
|
id: process.id?.toString(),
|
|
49
|
-
|
|
49
|
+
parentExecutionId: process.parentExecutionId?.toString(),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -59,7 +59,7 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
59
59
|
* @param {Object} [params.context] - Context data
|
|
60
60
|
* @returns {Promise<Object>} The created process record with string ID
|
|
61
61
|
*/
|
|
62
|
-
async
|
|
62
|
+
async createExecution({ name, type, context = {} }) {
|
|
63
63
|
const data = {
|
|
64
64
|
name,
|
|
65
65
|
type,
|
|
@@ -67,11 +67,11 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
67
67
|
results: { logs: [] },
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
const process = await this.prisma.
|
|
70
|
+
const process = await this.prisma.adminScriptExecution.create({
|
|
71
71
|
data,
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
return this.
|
|
74
|
+
return this._convertExecutionIds(process);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -80,13 +80,13 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
80
80
|
* @param {string|number} id - The process ID
|
|
81
81
|
* @returns {Promise<Object|null>} The process record with string ID or null if not found
|
|
82
82
|
*/
|
|
83
|
-
async
|
|
83
|
+
async findExecutionById(id) {
|
|
84
84
|
const intId = this._convertId(id);
|
|
85
|
-
const process = await this.prisma.
|
|
85
|
+
const process = await this.prisma.adminScriptExecution.findUnique({
|
|
86
86
|
where: { id: intId },
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
return this.
|
|
89
|
+
return this._convertExecutionIds(process);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
@@ -100,7 +100,7 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
100
100
|
* @param {string} [options.sortOrder] - Sort order ('asc' or 'desc')
|
|
101
101
|
* @returns {Promise<Array>} Array of process records with string IDs
|
|
102
102
|
*/
|
|
103
|
-
async
|
|
103
|
+
async findExecutionsByName(name, options = {}) {
|
|
104
104
|
const {
|
|
105
105
|
limit,
|
|
106
106
|
offset,
|
|
@@ -112,14 +112,14 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
112
112
|
const where = { name };
|
|
113
113
|
if (state) where.state = state;
|
|
114
114
|
|
|
115
|
-
const processes = await this.prisma.
|
|
115
|
+
const processes = await this.prisma.adminScriptExecution.findMany({
|
|
116
116
|
where,
|
|
117
117
|
orderBy: { [sortBy]: sortOrder },
|
|
118
118
|
take: limit,
|
|
119
119
|
skip: offset,
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
return processes.map((process) => this.
|
|
122
|
+
return processes.map((process) => this._convertExecutionIds(process));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -133,7 +133,7 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
133
133
|
* @param {string} [options.sortOrder] - Sort order ('asc' or 'desc')
|
|
134
134
|
* @returns {Promise<Array>} Array of process records with string IDs
|
|
135
135
|
*/
|
|
136
|
-
async
|
|
136
|
+
async findExecutionsByState(state, options = {}) {
|
|
137
137
|
const {
|
|
138
138
|
limit,
|
|
139
139
|
offset,
|
|
@@ -141,14 +141,14 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
141
141
|
sortOrder = 'desc',
|
|
142
142
|
} = options;
|
|
143
143
|
|
|
144
|
-
const processes = await this.prisma.
|
|
144
|
+
const processes = await this.prisma.adminScriptExecution.findMany({
|
|
145
145
|
where: { state },
|
|
146
146
|
orderBy: { [sortBy]: sortOrder },
|
|
147
147
|
take: limit,
|
|
148
148
|
skip: offset,
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
return processes.map((process) => this.
|
|
151
|
+
return processes.map((process) => this._convertExecutionIds(process));
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -158,14 +158,14 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
158
158
|
* @param {string} state - New state value
|
|
159
159
|
* @returns {Promise<Object>} Updated process record with string ID
|
|
160
160
|
*/
|
|
161
|
-
async
|
|
161
|
+
async updateExecutionState(id, state) {
|
|
162
162
|
const intId = this._convertId(id);
|
|
163
|
-
const process = await this.prisma.
|
|
163
|
+
const process = await this.prisma.adminScriptExecution.update({
|
|
164
164
|
where: { id: intId },
|
|
165
165
|
data: { state },
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
return this.
|
|
168
|
+
return this._convertExecutionIds(process);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
@@ -176,16 +176,16 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
176
176
|
* @param {Object} results - Results data to merge
|
|
177
177
|
* @returns {Promise<Object>} Updated process record with string ID
|
|
178
178
|
*/
|
|
179
|
-
async
|
|
179
|
+
async updateExecutionResults(id, results) {
|
|
180
180
|
const intId = this._convertId(id);
|
|
181
181
|
|
|
182
182
|
// Get current process to merge results
|
|
183
|
-
const currentProcess = await this.prisma.
|
|
183
|
+
const currentProcess = await this.prisma.adminScriptExecution.findUnique({
|
|
184
184
|
where: { id: intId },
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
if (!currentProcess) {
|
|
188
|
-
throw new Error(`
|
|
188
|
+
throw new Error(`AdminScriptExecution ${id} not found`);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
// Merge new results with existing results
|
|
@@ -194,12 +194,12 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
194
194
|
...results,
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
const process = await this.prisma.
|
|
197
|
+
const process = await this.prisma.adminScriptExecution.update({
|
|
198
198
|
where: { id: intId },
|
|
199
199
|
data: { results: mergedResults },
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
-
return this.
|
|
202
|
+
return this._convertExecutionIds(process);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/**
|
|
@@ -213,16 +213,16 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
213
213
|
* @param {string} logEntry.timestamp - ISO timestamp
|
|
214
214
|
* @returns {Promise<Object>} Updated process record with string ID
|
|
215
215
|
*/
|
|
216
|
-
async
|
|
216
|
+
async appendExecutionLog(id, logEntry) {
|
|
217
217
|
const intId = this._convertId(id);
|
|
218
218
|
|
|
219
219
|
// Get current process
|
|
220
|
-
const process = await this.prisma.
|
|
220
|
+
const process = await this.prisma.adminScriptExecution.findUnique({
|
|
221
221
|
where: { id: intId },
|
|
222
222
|
});
|
|
223
223
|
|
|
224
224
|
if (!process) {
|
|
225
|
-
throw new Error(`
|
|
225
|
+
throw new Error(`AdminScriptExecution ${id} not found`);
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
// Get current results and logs
|
|
@@ -231,12 +231,12 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
231
231
|
logs.push(logEntry);
|
|
232
232
|
|
|
233
233
|
// Update with new logs array in results
|
|
234
|
-
const updated = await this.prisma.
|
|
234
|
+
const updated = await this.prisma.adminScriptExecution.update({
|
|
235
235
|
where: { id: intId },
|
|
236
236
|
data: { results: { ...results, logs } },
|
|
237
237
|
});
|
|
238
238
|
|
|
239
|
-
return this.
|
|
239
|
+
return this._convertExecutionIds(updated);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/**
|
|
@@ -246,8 +246,8 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
246
246
|
* @param {Date} date - Delete processes older than this date
|
|
247
247
|
* @returns {Promise<Object>} Deletion result with count
|
|
248
248
|
*/
|
|
249
|
-
async
|
|
250
|
-
const result = await this.prisma.
|
|
249
|
+
async deleteExecutionsOlderThan(date) {
|
|
250
|
+
const result = await this.prisma.adminScriptExecution.deleteMany({
|
|
251
251
|
where: {
|
|
252
252
|
createdAt: {
|
|
253
253
|
lt: date,
|
|
@@ -262,4 +262,4 @@ class AdminProcessRepositoryPostgres extends AdminProcessRepositoryInterface {
|
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
module.exports = {
|
|
265
|
+
module.exports = { AdminScriptExecutionRepositoryPostgres };
|