@friggframework/core 2.0.0--canary.490.dfd8df5.0 → 2.0.0--canary.490.1d4d68c.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.
Files changed (30) hide show
  1. package/credential/repositories/credential-repository-factory.js +11 -13
  2. package/credential/repositories/{credential-repository-documentdb.js → credential-repository-mongodb-native.js} +4 -4
  3. package/database/repositories/health-check-repository-factory.js +10 -33
  4. package/database/repositories/{health-check-repository-documentdb.js → health-check-repository-mongodb-native.js} +4 -4
  5. package/integrations/repositories/integration-mapping-repository-factory.js +5 -30
  6. package/integrations/repositories/{integration-mapping-repository-documentdb.js → integration-mapping-repository-mongodb-native.js} +4 -4
  7. package/integrations/repositories/integration-repository-factory.js +11 -12
  8. package/integrations/repositories/{integration-repository-documentdb.js → integration-repository-mongodb-native.js} +12 -4
  9. package/integrations/repositories/process-repository-factory.js +5 -30
  10. package/integrations/repositories/{process-repository-documentdb.js → process-repository-mongodb-native.js} +4 -4
  11. package/modules/repositories/module-repository-factory.js +5 -11
  12. package/modules/repositories/{module-repository-documentdb.js → module-repository-mongodb-native.js} +4 -4
  13. package/package.json +5 -5
  14. package/syncs/repositories/sync-repository-factory.js +5 -11
  15. package/syncs/repositories/{sync-repository-documentdb.js → sync-repository-mongodb-native.js} +4 -4
  16. package/token/repositories/token-repository-factory.js +5 -11
  17. package/token/repositories/{token-repository-documentdb.js → token-repository-mongodb-native.js} +4 -4
  18. package/user/repositories/user-repository-factory.js +7 -32
  19. package/user/repositories/{user-repository-documentdb.js → user-repository-mongodb-native.js} +4 -4
  20. package/websocket/repositories/websocket-connection-repository-factory.js +5 -11
  21. package/websocket/repositories/{websocket-connection-repository-documentdb.js → websocket-connection-repository-mongodb-native.js} +4 -4
  22. package/credential/repositories/credential-repository-mongo.js +0 -311
  23. package/integrations/repositories/integration-mapping-repository-mongo.js +0 -165
  24. package/integrations/repositories/integration-repository-mongo.js +0 -307
  25. package/integrations/repositories/process-repository-mongo.js +0 -194
  26. package/modules/repositories/module-repository-mongo.js +0 -381
  27. package/syncs/repositories/sync-repository-mongo.js +0 -243
  28. package/token/repositories/token-repository-mongo.js +0 -216
  29. package/user/repositories/user-repository-mongo.js +0 -295
  30. package/websocket/repositories/websocket-connection-repository-mongo.js +0 -160
@@ -1,307 +0,0 @@
1
- const { prisma } = require('../../database/prisma');
2
- const {
3
- IntegrationRepositoryInterface,
4
- } = require('./integration-repository-interface');
5
- const { BaseRepositoryMongoDB } = require('../../database/repositories/base-repository-mongodb');
6
-
7
- /**
8
- * MongoDB Integration Repository Adapter
9
- * Handles integration persistence using Prisma with MongoDB
10
- *
11
- * MongoDB-specific characteristics:
12
- * - Uses scalar fields for relations (userId, entityIds)
13
- * - IDs are strings with @db.ObjectId
14
- * - Arrays used for many-to-many relationships
15
- *
16
- * Migration from Mongoose:
17
- * - Constructor injection of Prisma client
18
- * - populate() → include in Prisma queries
19
- * - lean: true → No longer needed (Prisma returns plain objects)
20
- * - toString() conversions → Done automatically by Prisma
21
- */
22
- class IntegrationRepositoryMongo extends IntegrationRepositoryInterface {
23
- constructor() {
24
- super();
25
-
26
- // Use MongoDB base repository for DocumentDB compatibility
27
- const mongoBase = new BaseRepositoryMongoDB({ prismaClient: prisma });
28
- this.prisma = mongoBase.prisma;
29
- }
30
-
31
- /**
32
- * Find all integrations for a user
33
- * Replaces: IntegrationModel.find({ user: userId }).populate('entities')
34
- *
35
- * @param {string} userId - User ID (MongoDB ObjectId as string)
36
- * @returns {Promise<Array>} Array of integration objects
37
- */
38
- async findIntegrationsByUserId(userId) {
39
- const integrations = await this.prisma.integration.findMany({
40
- where: { userId },
41
- include: {
42
- entities: true,
43
- },
44
- });
45
-
46
- // Map to domain objects (maintains same API)
47
- return integrations.map((integration) => ({
48
- id: integration.id,
49
- entitiesIds: integration.entities.map((e) => e.id),
50
- userId: integration.userId,
51
- config: integration.config,
52
- version: integration.version,
53
- status: integration.status,
54
- messages: integration.messages,
55
- }));
56
- }
57
-
58
- /**
59
- * Delete integration by ID
60
- * Replaces: IntegrationModel.deleteOne({ _id: integrationId })
61
- *
62
- * @param {string} integrationId - Integration ID
63
- * @returns {Promise<Object>} Deletion result
64
- */
65
- async deleteIntegrationById(integrationId) {
66
- await this.prisma.integration.delete({
67
- where: { id: integrationId },
68
- });
69
-
70
- // Return Mongoose-compatible result
71
- return { acknowledged: true, deletedCount: 1 };
72
- }
73
-
74
- /**
75
- * Find integration by name
76
- * Replaces: IntegrationModel.findOne({ 'config.type': name }).populate('entities')
77
- *
78
- * @param {string} name - Integration type name
79
- * @returns {Promise<Object>} Integration object
80
- */
81
- async findIntegrationByName(name) {
82
- const integration = await this.prisma.integration.findFirst({
83
- where: {
84
- config: {
85
- path: ['type'],
86
- equals: name,
87
- },
88
- },
89
- include: {
90
- entities: true,
91
- },
92
- });
93
-
94
- if (!integration) {
95
- throw new Error(`Integration with name ${name} not found`);
96
- }
97
-
98
- return {
99
- id: integration.id,
100
- entitiesIds: integration.entities.map((e) => e.id),
101
- userId: integration.userId,
102
- config: integration.config,
103
- version: integration.version,
104
- status: integration.status,
105
- messages: integration.messages,
106
- };
107
- }
108
-
109
- /**
110
- * Find integration by ID
111
- * Replaces: IntegrationModel.findById(id).populate('entities')
112
- *
113
- * @param {string} id - Integration ID
114
- * @returns {Promise<Object>} Integration object
115
- */
116
- async findIntegrationById(id) {
117
- const integration = await this.prisma.integration.findUnique({
118
- where: { id },
119
- include: {
120
- entities: true,
121
- },
122
- });
123
-
124
- if (!integration) {
125
- throw new Error(`Integration with id ${id} not found`);
126
- }
127
-
128
- return {
129
- id: integration.id,
130
- entitiesIds: integration.entities.map((e) => e.id),
131
- userId: integration.userId,
132
- config: integration.config,
133
- version: integration.version,
134
- status: integration.status,
135
- messages: integration.messages,
136
- };
137
- }
138
-
139
- /**
140
- * Update integration status
141
- * Replaces: IntegrationModel.updateOne({ _id: integrationId }, { status })
142
- *
143
- * @param {string} integrationId - Integration ID
144
- * @param {string} status - New status
145
- * @returns {Promise<boolean>} Success indicator
146
- */
147
- async updateIntegrationStatus(integrationId, status) {
148
- await this.prisma.integration.update({
149
- where: { id: integrationId },
150
- data: { status },
151
- });
152
-
153
- return true; // Mongoose compatibility
154
- }
155
-
156
- /**
157
- * Update integration messages
158
- * Replaces: IntegrationModel.updateOne with $push operator
159
- *
160
- * @param {string} integrationId - Integration ID
161
- * @param {string} messageType - Type of message (errors, warnings, info, logs)
162
- * @param {string} messageTitle - Message title
163
- * @param {string} messageBody - Message body
164
- * @param {Date} messageTimestamp - Message timestamp
165
- * @returns {Promise<boolean>} Success indicator
166
- */
167
- async updateIntegrationMessages(
168
- integrationId,
169
- messageType,
170
- messageTitle,
171
- messageBody,
172
- messageTimestamp
173
- ) {
174
- // Get current integration
175
- const integration = await this.prisma.integration.findUnique({
176
- where: { id: integrationId },
177
- });
178
-
179
- if (!integration) {
180
- throw new Error(`Integration ${integrationId} not found`);
181
- }
182
-
183
- // Parse existing messages (JSON field)
184
- const messages = integration.messages || {};
185
- const messageArray = Array.isArray(messages[messageType])
186
- ? messages[messageType]
187
- : [];
188
-
189
- // Add new message
190
- messageArray.push({
191
- title: messageTitle,
192
- message: messageBody,
193
- timestamp: messageTimestamp,
194
- });
195
-
196
- // Update messages
197
- await this.prisma.integration.update({
198
- where: { id: integrationId },
199
- data: {
200
- [messageType]: messageArray,
201
- },
202
- });
203
-
204
- return true; // Mongoose compatibility
205
- }
206
-
207
- /**
208
- * Create a new integration
209
- * Replaces: IntegrationModel.create({ entities, user, config })
210
- *
211
- * MongoDB-specific: Uses scalar fields for relations
212
- *
213
- * @param {Array<string>} entities - Array of entity IDs (MongoDB ObjectIds)
214
- * @param {string} userId - User ID (MongoDB ObjectId)
215
- * @param {Object} config - Integration configuration
216
- * @returns {Promise<Object>} Created integration object
217
- */
218
- async createIntegration(entities, userId, config) {
219
- const data = {
220
- config,
221
- version: '0.0.0',
222
- userId: userId,
223
- entityIds: entities,
224
- };
225
-
226
- const integration = await this.prisma.integration.create({
227
- data,
228
- include: {
229
- entities: true,
230
- },
231
- });
232
-
233
- return {
234
- id: integration.id,
235
- entitiesIds: integration.entities.map((e) => e.id),
236
- userId: integration.userId,
237
- config: integration.config,
238
- version: integration.version,
239
- status: integration.status,
240
- messages: integration.messages,
241
- };
242
- }
243
-
244
- /**
245
- * Find integration by user ID (returns single integration)
246
- * Replaces: IntegrationModel.findOne({ user: userId }).populate('entities')
247
- *
248
- * @param {string} userId - User ID
249
- * @returns {Promise<Object|null>} Integration object or null
250
- */
251
- async findIntegrationByUserId(userId) {
252
- const integration = await this.prisma.integration.findFirst({
253
- where: { userId },
254
- include: {
255
- entities: true,
256
- },
257
- });
258
-
259
- if (!integration) {
260
- return null;
261
- }
262
-
263
- return {
264
- id: integration.id,
265
- entitiesIds: integration.entities.map((e) => e.id),
266
- userId: integration.userId,
267
- config: integration.config,
268
- version: integration.version,
269
- status: integration.status,
270
- messages: integration.messages,
271
- };
272
- }
273
-
274
- /**
275
- * Update integration configuration
276
- * Replaces: IntegrationModel.updateOne({ _id: integrationId }, { config })
277
- *
278
- * @param {string} integrationId - Integration ID (MongoDB ObjectId as string)
279
- * @param {Object} config - Updated configuration object
280
- * @returns {Promise<Object>} Updated integration object
281
- */
282
- async updateIntegrationConfig(integrationId, config) {
283
- if (config === null || config === undefined) {
284
- throw new Error('Config parameter is required');
285
- }
286
-
287
- const integration = await this.prisma.integration.update({
288
- where: { id: integrationId },
289
- data: { config },
290
- include: {
291
- entities: true,
292
- },
293
- });
294
-
295
- return {
296
- id: integration.id,
297
- entitiesIds: integration.entities.map((e) => e.id),
298
- userId: integration.userId,
299
- config: integration.config,
300
- version: integration.version,
301
- status: integration.status,
302
- messages: integration.messages,
303
- };
304
- }
305
- }
306
-
307
- module.exports = { IntegrationRepositoryMongo };
@@ -1,194 +0,0 @@
1
- const { prisma } = require('../../database/prisma');
2
- const { ProcessRepositoryInterface } = require('./process-repository-interface');
3
- const { BaseRepositoryMongoDB } = require('../../database/repositories/base-repository-mongodb');
4
-
5
- /**
6
- * MongoDB Process Repository Adapter
7
- * Handles process persistence using Prisma with MongoDB
8
- *
9
- * MongoDB-specific characteristics:
10
- * - Uses scalar fields for relations (userId, integrationId)
11
- * - IDs are strings with @db.ObjectId
12
- * - JSON fields for flexible context and results storage
13
- * - Array field for childProcesses references
14
- *
15
- * Design Philosophy:
16
- * - Generic Process model supports any type of long-running operation
17
- * - Context and results stored as JSON for maximum flexibility
18
- * - Integration-specific logic lives in use cases and services
19
- */
20
- class ProcessRepositoryMongo extends ProcessRepositoryInterface {
21
- constructor() {
22
- super();
23
-
24
- // Use MongoDB base repository for DocumentDB compatibility
25
- const mongoBase = new BaseRepositoryMongoDB({ prismaClient: prisma });
26
- this.prisma = mongoBase.prisma;
27
- }
28
-
29
- /**
30
- * Create a new process record
31
- * @param {Object} processData - Process data to create
32
- * @returns {Promise<Object>} Created process record
33
- */
34
- async create(processData) {
35
- const process = await this.prisma.process.create({
36
- data: {
37
- userId: processData.userId,
38
- integrationId: processData.integrationId,
39
- name: processData.name,
40
- type: processData.type,
41
- state: processData.state || 'INITIALIZING',
42
- context: processData.context || {},
43
- results: processData.results || {},
44
- childProcesses: processData.childProcesses || [],
45
- parentProcessId: processData.parentProcessId || null,
46
- },
47
- });
48
-
49
- return this._toPlainObject(process);
50
- }
51
-
52
- /**
53
- * Find a process by ID
54
- * @param {string} processId - Process ID to find
55
- * @returns {Promise<Object|null>} Process record or null if not found
56
- */
57
- async findById(processId) {
58
- const process = await this.prisma.process.findUnique({
59
- where: { id: processId },
60
- });
61
-
62
- return process ? this._toPlainObject(process) : null;
63
- }
64
-
65
- /**
66
- * Update a process record
67
- * @param {string} processId - Process ID to update
68
- * @param {Object} updates - Fields to update
69
- * @returns {Promise<Object>} Updated process record
70
- */
71
- async update(processId, updates) {
72
- // Prepare update data, excluding undefined values
73
- const updateData = {};
74
-
75
- if (updates.state !== undefined) {
76
- updateData.state = updates.state;
77
- }
78
- if (updates.context !== undefined) {
79
- updateData.context = updates.context;
80
- }
81
- if (updates.results !== undefined) {
82
- updateData.results = updates.results;
83
- }
84
- if (updates.childProcesses !== undefined) {
85
- updateData.childProcesses = updates.childProcesses;
86
- }
87
- if (updates.parentProcessId !== undefined) {
88
- updateData.parentProcessId = updates.parentProcessId;
89
- }
90
-
91
- const process = await this.prisma.process.update({
92
- where: { id: processId },
93
- data: updateData,
94
- });
95
-
96
- return this._toPlainObject(process);
97
- }
98
-
99
- /**
100
- * Find processes by integration and type
101
- * @param {string} integrationId - Integration ID
102
- * @param {string} type - Process type
103
- * @returns {Promise<Array>} Array of process records
104
- */
105
- async findByIntegrationAndType(integrationId, type) {
106
- const processes = await this.prisma.process.findMany({
107
- where: {
108
- integrationId,
109
- type,
110
- },
111
- orderBy: {
112
- createdAt: 'desc',
113
- },
114
- });
115
-
116
- return processes.map((p) => this._toPlainObject(p));
117
- }
118
-
119
- /**
120
- * Find active processes (not in excluded states)
121
- * @param {string} integrationId - Integration ID
122
- * @param {string[]} [excludeStates=['COMPLETED', 'ERROR']] - States to exclude
123
- * @returns {Promise<Array>} Array of active process records
124
- */
125
- async findActiveProcesses(integrationId, excludeStates = ['COMPLETED', 'ERROR']) {
126
- const processes = await this.prisma.process.findMany({
127
- where: {
128
- integrationId,
129
- state: {
130
- notIn: excludeStates,
131
- },
132
- },
133
- orderBy: {
134
- createdAt: 'desc',
135
- },
136
- });
137
-
138
- return processes.map((p) => this._toPlainObject(p));
139
- }
140
-
141
- /**
142
- * Find a process by name (most recent)
143
- * @param {string} name - Process name
144
- * @returns {Promise<Object|null>} Most recent process with given name, or null
145
- */
146
- async findByName(name) {
147
- const process = await this.prisma.process.findFirst({
148
- where: { name },
149
- orderBy: {
150
- createdAt: 'desc',
151
- },
152
- });
153
-
154
- return process ? this._toPlainObject(process) : null;
155
- }
156
-
157
- /**
158
- * Delete a process by ID
159
- * @param {string} processId - Process ID to delete
160
- * @returns {Promise<void>}
161
- */
162
- async deleteById(processId) {
163
- await this.prisma.process.delete({
164
- where: { id: processId },
165
- });
166
- }
167
-
168
- /**
169
- * Convert Prisma model to plain JavaScript object
170
- * Ensures consistent API across repository implementations
171
- * @private
172
- * @param {Object} process - Prisma process model
173
- * @returns {Object} Plain process object
174
- */
175
- _toPlainObject(process) {
176
- return {
177
- id: process.id,
178
- userId: process.userId,
179
- integrationId: process.integrationId,
180
- name: process.name,
181
- type: process.type,
182
- state: process.state,
183
- context: process.context,
184
- results: process.results,
185
- childProcesses: process.childProcesses,
186
- parentProcessId: process.parentProcessId,
187
- createdAt: process.createdAt,
188
- updatedAt: process.updatedAt,
189
- };
190
- }
191
- }
192
-
193
- module.exports = { ProcessRepositoryMongo };
194
-