streamby-core 0.13.0 → 0.15.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/dist/config.d.ts +18 -0
- package/dist/config.js +25 -0
- package/dist/db/initExportModel.d.ts +60 -0
- package/dist/db/initExportModel.js +18 -0
- package/dist/db/initProjectModel.d.ts +72 -60
- package/dist/db/initProjectModel.js +3 -1
- package/dist/db/initUserModel.d.ts +48 -0
- package/dist/db/initUserModel.js +19 -0
- package/dist/middleware/createRouter.js +217 -47
- package/dist/models/ExportCollection.d.ts +54 -0
- package/dist/models/ExportCollection.js +19 -0
- package/dist/providers/createDatabaseProvider.d.ts +69 -9
- package/dist/providers/createDatabaseProvider.js +44 -12
- package/dist/providers/createPrismaProvider.d.ts +8 -0
- package/dist/providers/createPrismaProvider.js +18 -0
- package/dist/providers/mongoExportProvider.d.ts +3 -0
- package/dist/providers/mongoExportProvider.js +13 -0
- package/dist/providers/mongoProjectProvider.d.ts +1 -1
- package/dist/providers/mongoProjectProvider.js +55 -33
- package/dist/providers/prismaExportCollectionProvider.d.ts +61 -0
- package/dist/providers/prismaExportCollectionProvider.js +45 -0
- package/dist/providers/prismaExportProvider.d.ts +3 -0
- package/dist/providers/prismaExportProvider.js +13 -0
- package/dist/providers/prismaProjectProvider.d.ts +3 -0
- package/dist/providers/prismaProjectProvider.js +147 -0
- package/dist/types/index.d.ts +69 -12
- package/package.json +4 -2
- package/dist/dev/server.d.ts +0 -4
- package/dist/dev/server.js +0 -14
|
@@ -15,13 +15,27 @@ function isProjectMember(project, userId) {
|
|
|
15
15
|
function createStreamByRouter(config) {
|
|
16
16
|
const router = express_1.default.Router();
|
|
17
17
|
const adapter = config.adapter || (0, createStorageProvider_1.createStorageProvider)(config.storageProviders);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const projectProviders = {};
|
|
19
|
+
let exportProvider;
|
|
20
|
+
let exportCollectionProvider;
|
|
21
|
+
if (config.databases) {
|
|
22
|
+
const db = (0, createDatabaseProvider_1.createDatabaseProvider)(config.databases, adapter);
|
|
23
|
+
projectProviders.nosql = db.projectProviders.nosql;
|
|
24
|
+
projectProviders.sql = db.projectProviders.sql;
|
|
25
|
+
exportProvider = db.exportProvider;
|
|
26
|
+
exportCollectionProvider = db.exportCollectionProvider;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
projectProviders.default = config.projectProvider;
|
|
30
|
+
exportProvider = config.exportProvider;
|
|
31
|
+
exportCollectionProvider = config.exportCollectionProvider;
|
|
32
|
+
}
|
|
33
|
+
if (!projectProviders.nosql && !projectProviders.sql) {
|
|
34
|
+
throw new Error('Project provider is not initialized. Please check your database configuration.');
|
|
35
|
+
}
|
|
36
|
+
if (!exportProvider) {
|
|
37
|
+
throw new Error('Export provider is not initialized. Please check your database configuration.');
|
|
38
|
+
}
|
|
25
39
|
router.get('/auth', async (req, res) => {
|
|
26
40
|
try {
|
|
27
41
|
const auth = await config.authProvider(req);
|
|
@@ -31,6 +45,25 @@ function createStreamByRouter(config) {
|
|
|
31
45
|
res.status(401).json({ logged: false });
|
|
32
46
|
}
|
|
33
47
|
});
|
|
48
|
+
router.get('/databases', async (req, res) => {
|
|
49
|
+
try {
|
|
50
|
+
const auth = await config.authProvider(req);
|
|
51
|
+
if (!auth) {
|
|
52
|
+
return res.status(401).json({ error: 'Unauthorized' });
|
|
53
|
+
}
|
|
54
|
+
const databases = [];
|
|
55
|
+
if (projectProviders.nosql) {
|
|
56
|
+
databases.push({ name: "NoSQL (Mongo)", value: "nosql" });
|
|
57
|
+
}
|
|
58
|
+
if (projectProviders.sql) {
|
|
59
|
+
databases.push({ name: "SQL (Prisma)", value: "sql" });
|
|
60
|
+
}
|
|
61
|
+
res.status(200).json({ databases });
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
res.status(500).json({ error: 'Failed to get databases' });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
34
67
|
router.get('/upload-project-image-url/:id', async (req, res) => {
|
|
35
68
|
try {
|
|
36
69
|
const auth = await config.authProvider(req);
|
|
@@ -59,7 +92,11 @@ function createStreamByRouter(config) {
|
|
|
59
92
|
return res.status(400).json({ error: 'Missing projectId' });
|
|
60
93
|
}
|
|
61
94
|
await (0, file_1.deleteProjectImage)(adapter, projectId);
|
|
62
|
-
const
|
|
95
|
+
const provider = await getProjectProvider(projectId);
|
|
96
|
+
if (!provider) {
|
|
97
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
98
|
+
}
|
|
99
|
+
const updated = await provider.update(projectId, { image: '' });
|
|
63
100
|
res.status(201).json(updated);
|
|
64
101
|
}
|
|
65
102
|
catch (err) {
|
|
@@ -80,31 +117,62 @@ function createStreamByRouter(config) {
|
|
|
80
117
|
res.status(500).json({ error: 'Failed to list files', details: err });
|
|
81
118
|
}
|
|
82
119
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
async function getProjectProvider(projectId, dbType) {
|
|
121
|
+
if (dbType) {
|
|
122
|
+
const specificProvider = projectProviders[dbType];
|
|
123
|
+
if (specificProvider) {
|
|
124
|
+
try {
|
|
125
|
+
const project = await specificProvider.getById(projectId, true);
|
|
126
|
+
if (project)
|
|
127
|
+
return specificProvider;
|
|
128
|
+
}
|
|
129
|
+
catch (error) { /* ignore */ }
|
|
130
|
+
}
|
|
88
131
|
}
|
|
89
|
-
|
|
90
|
-
|
|
132
|
+
// Fallback to searching all providers if dbType is not provided or project not found in specific dbType
|
|
133
|
+
if (projectProviders.nosql) {
|
|
134
|
+
try {
|
|
135
|
+
const project = await projectProviders.nosql.getById(projectId, true);
|
|
136
|
+
if (project)
|
|
137
|
+
return projectProviders.nosql;
|
|
138
|
+
}
|
|
139
|
+
catch (error) { /* ignore */ }
|
|
91
140
|
}
|
|
92
|
-
|
|
93
|
-
|
|
141
|
+
if (projectProviders.sql) {
|
|
142
|
+
try {
|
|
143
|
+
const project = await projectProviders.sql.getById(projectId, true);
|
|
144
|
+
if (project)
|
|
145
|
+
return projectProviders.sql;
|
|
146
|
+
}
|
|
147
|
+
catch (error) { /* ignore */ }
|
|
148
|
+
}
|
|
149
|
+
if (projectProviders.default) {
|
|
150
|
+
try {
|
|
151
|
+
const project = await projectProviders.default.getById(projectId, true);
|
|
152
|
+
if (project)
|
|
153
|
+
return projectProviders.default;
|
|
154
|
+
}
|
|
155
|
+
catch (error) { /* ignore */ }
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
router.get('/projects', async (req, res) => {
|
|
94
160
|
try {
|
|
95
161
|
const auth = await config.authProvider(req);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return res.status(404).json({ error: 'Project not found' });
|
|
162
|
+
const projects = [];
|
|
163
|
+
if (projectProviders.nosql) {
|
|
164
|
+
projects.push(...await projectProviders.nosql.list(auth.userId));
|
|
100
165
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
166
|
+
if (projectProviders.sql) {
|
|
167
|
+
projects.push(...await projectProviders.sql.list(auth.userId));
|
|
103
168
|
}
|
|
104
|
-
|
|
169
|
+
if (projectProviders.default) {
|
|
170
|
+
projects.push(...await projectProviders.default.list(auth.userId));
|
|
171
|
+
}
|
|
172
|
+
res.json({ projects });
|
|
105
173
|
}
|
|
106
174
|
catch (err) {
|
|
107
|
-
res.status(500).json({ error: 'Failed to
|
|
175
|
+
res.status(500).json({ error: 'Failed to list projects', details: err });
|
|
108
176
|
}
|
|
109
177
|
});
|
|
110
178
|
router.post('/projects/create', async (req, res) => {
|
|
@@ -113,8 +181,13 @@ function createStreamByRouter(config) {
|
|
|
113
181
|
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
114
182
|
return res.status(403).json({ error: 'Permission denied' });
|
|
115
183
|
}
|
|
116
|
-
const { name, description } = req.body;
|
|
117
|
-
const
|
|
184
|
+
const { name, description, dbType } = req.body;
|
|
185
|
+
const provider = dbType ? projectProviders[dbType] : projectProviders.default || projectProviders.nosql || projectProviders.sql;
|
|
186
|
+
if (!provider) {
|
|
187
|
+
return res.status(400).json({ error: 'Invalid dbType' });
|
|
188
|
+
}
|
|
189
|
+
const newProject = await provider.create({
|
|
190
|
+
dbType: dbType || 'nosql',
|
|
118
191
|
name,
|
|
119
192
|
description: description || '',
|
|
120
193
|
members: [{ userId: auth.userId, role: "admin" }]
|
|
@@ -125,6 +198,28 @@ function createStreamByRouter(config) {
|
|
|
125
198
|
res.status(500).json({ error: 'Failed to create project', details: err.message });
|
|
126
199
|
}
|
|
127
200
|
});
|
|
201
|
+
router.get('/projects/:id', async (req, res) => {
|
|
202
|
+
try {
|
|
203
|
+
const auth = await config.authProvider(req);
|
|
204
|
+
const projectId = req.params.id;
|
|
205
|
+
const dbType = req.query.dbType;
|
|
206
|
+
const projectProvider = await getProjectProvider(projectId, dbType);
|
|
207
|
+
if (!projectProvider) {
|
|
208
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
209
|
+
}
|
|
210
|
+
const project = await projectProvider.getById(projectId, true);
|
|
211
|
+
if (!project) {
|
|
212
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
213
|
+
}
|
|
214
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
215
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
216
|
+
}
|
|
217
|
+
res.json({ project });
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
res.status(500).json({ error: 'Failed to fetch project', details: err.message });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
128
223
|
router.patch('/projects/:id', async (req, res) => {
|
|
129
224
|
try {
|
|
130
225
|
const auth = await config.authProvider(req);
|
|
@@ -133,7 +228,11 @@ function createStreamByRouter(config) {
|
|
|
133
228
|
}
|
|
134
229
|
const projectId = req.params.id;
|
|
135
230
|
const updates = req.body;
|
|
136
|
-
const
|
|
231
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
232
|
+
if (!projectProvider) {
|
|
233
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
234
|
+
}
|
|
235
|
+
const project = await projectProvider.getById(projectId, true);
|
|
137
236
|
if (!project) {
|
|
138
237
|
return res.status(404).json({ error: 'Project not found' });
|
|
139
238
|
}
|
|
@@ -154,7 +253,11 @@ function createStreamByRouter(config) {
|
|
|
154
253
|
try {
|
|
155
254
|
const auth = await config.authProvider(req);
|
|
156
255
|
const projectId = req.params.id;
|
|
157
|
-
const
|
|
256
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
257
|
+
if (!projectProvider) {
|
|
258
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
259
|
+
}
|
|
260
|
+
const project = await projectProvider.getById(projectId, true);
|
|
158
261
|
if (!project) {
|
|
159
262
|
return res.status(404).json({ error: 'Project not found' });
|
|
160
263
|
}
|
|
@@ -168,48 +271,115 @@ function createStreamByRouter(config) {
|
|
|
168
271
|
res.status(500).json({ error: 'Failed to delete project', details: err.message });
|
|
169
272
|
}
|
|
170
273
|
});
|
|
171
|
-
router.
|
|
274
|
+
router.patch('/projects/:id/archive', async (req, res) => {
|
|
172
275
|
try {
|
|
173
276
|
const auth = await config.authProvider(req);
|
|
174
|
-
const
|
|
175
|
-
|
|
277
|
+
const projectId = req.params.id;
|
|
278
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
279
|
+
if (!projectProvider) {
|
|
280
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
281
|
+
}
|
|
282
|
+
const project = await projectProvider.getById(projectId, true);
|
|
283
|
+
if (!project || !isProjectMember(project, auth.userId)) {
|
|
284
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
285
|
+
}
|
|
286
|
+
const result = await projectProvider.archive(projectId, auth.userId);
|
|
287
|
+
res.status(200).json(result);
|
|
176
288
|
}
|
|
177
289
|
catch (err) {
|
|
178
|
-
res.status(500).json({ error: 'Failed to
|
|
290
|
+
res.status(500).json({ error: 'Failed to archive project', details: err.message });
|
|
179
291
|
}
|
|
180
292
|
});
|
|
181
|
-
router.patch('/projects/:id/
|
|
293
|
+
router.patch('/projects/:id/unarchive', async (req, res) => {
|
|
182
294
|
try {
|
|
183
295
|
const auth = await config.authProvider(req);
|
|
184
296
|
const projectId = req.params.id;
|
|
185
|
-
const
|
|
297
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
298
|
+
if (!projectProvider) {
|
|
299
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
300
|
+
}
|
|
301
|
+
const project = await projectProvider.getById(projectId, true);
|
|
186
302
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
187
303
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
188
304
|
}
|
|
189
|
-
await projectProvider.
|
|
190
|
-
|
|
191
|
-
const archivedProjects = await projectProvider.listArchived(auth.userId);
|
|
192
|
-
res.status(200).json({ success: true, projects, archivedProjects });
|
|
305
|
+
const result = await projectProvider.unarchive(projectId, auth.userId);
|
|
306
|
+
res.status(200).json(result);
|
|
193
307
|
}
|
|
194
308
|
catch (err) {
|
|
195
|
-
res.status(500).json({ error: 'Failed to
|
|
309
|
+
res.status(500).json({ error: 'Failed to unarchive project', details: err.message });
|
|
196
310
|
}
|
|
197
311
|
});
|
|
198
|
-
router.
|
|
312
|
+
router.get('/projects/:id/exports/:export_id', async (req, res) => {
|
|
199
313
|
try {
|
|
200
314
|
const auth = await config.authProvider(req);
|
|
201
315
|
const projectId = req.params.id;
|
|
202
|
-
const
|
|
316
|
+
const exportId = req.params.export_id;
|
|
317
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
318
|
+
if (!projectProvider) {
|
|
319
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
320
|
+
}
|
|
321
|
+
const project = await projectProvider.getById(projectId, true);
|
|
322
|
+
if (!project) {
|
|
323
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
324
|
+
}
|
|
325
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
326
|
+
return res.status(403).json({ error: 'Unauthorized access' });
|
|
327
|
+
}
|
|
328
|
+
const data = await exportProvider.getById(exportId);
|
|
329
|
+
res.json({ data });
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
res.status(500).json({ error: 'Failed to fetch export data', details: err.message });
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
router.post('/projects/:id/exports', async (req, res) => {
|
|
336
|
+
try {
|
|
337
|
+
const auth = await config.authProvider(req);
|
|
338
|
+
const projectId = req.params.id;
|
|
339
|
+
const { name, description, collectionName } = req.body;
|
|
340
|
+
if (!name || !collectionName) {
|
|
341
|
+
return res.status(400).json({ error: 'Missing export name or collectionName' });
|
|
342
|
+
}
|
|
343
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
344
|
+
if (!projectProvider) {
|
|
345
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
346
|
+
}
|
|
347
|
+
const project = await projectProvider.getById(projectId, true);
|
|
203
348
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
204
349
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
205
350
|
}
|
|
206
|
-
await
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
351
|
+
const newExport = await exportProvider.create({
|
|
352
|
+
name,
|
|
353
|
+
description,
|
|
354
|
+
collectionName,
|
|
355
|
+
projectId
|
|
356
|
+
});
|
|
357
|
+
await projectProvider.addExportToProject(projectId, newExport.id);
|
|
358
|
+
res.status(201).json({ data: newExport });
|
|
210
359
|
}
|
|
211
360
|
catch (err) {
|
|
212
|
-
res.status(500).json({ error: 'Failed to
|
|
361
|
+
res.status(500).json({ error: 'Failed to create export', details: err.message });
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
router.get('/projects/:id/members', async (req, res) => {
|
|
365
|
+
try {
|
|
366
|
+
const auth = await config.authProvider(req);
|
|
367
|
+
const projectId = req.params.id;
|
|
368
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
369
|
+
if (!projectProvider) {
|
|
370
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
371
|
+
}
|
|
372
|
+
const project = await projectProvider.getById(projectId, true);
|
|
373
|
+
if (!project) {
|
|
374
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
375
|
+
}
|
|
376
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
377
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
378
|
+
}
|
|
379
|
+
res.json({ members: project.members });
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
res.status(500).json({ error: 'Failed to fetch project members', details: err.message });
|
|
213
383
|
}
|
|
214
384
|
});
|
|
215
385
|
return router;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initExportCollectionModel(connection: mongoose.Connection): mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
name: string;
|
|
7
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
8
|
+
projectId: mongoose.Types.ObjectId;
|
|
9
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
10
|
+
createdAt: NativeDate;
|
|
11
|
+
updatedAt: NativeDate;
|
|
12
|
+
} & {
|
|
13
|
+
name: string;
|
|
14
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
15
|
+
projectId: mongoose.Types.ObjectId;
|
|
16
|
+
}, {}> & {
|
|
17
|
+
createdAt: NativeDate;
|
|
18
|
+
updatedAt: NativeDate;
|
|
19
|
+
} & {
|
|
20
|
+
name: string;
|
|
21
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
22
|
+
projectId: mongoose.Types.ObjectId;
|
|
23
|
+
} & {
|
|
24
|
+
_id: mongoose.Types.ObjectId;
|
|
25
|
+
} & {
|
|
26
|
+
__v: number;
|
|
27
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
28
|
+
timestamps: true;
|
|
29
|
+
}, {
|
|
30
|
+
createdAt: NativeDate;
|
|
31
|
+
updatedAt: NativeDate;
|
|
32
|
+
} & {
|
|
33
|
+
name: string;
|
|
34
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
35
|
+
projectId: mongoose.Types.ObjectId;
|
|
36
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
37
|
+
createdAt: NativeDate;
|
|
38
|
+
updatedAt: NativeDate;
|
|
39
|
+
} & {
|
|
40
|
+
name: string;
|
|
41
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
42
|
+
projectId: mongoose.Types.ObjectId;
|
|
43
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
44
|
+
createdAt: NativeDate;
|
|
45
|
+
updatedAt: NativeDate;
|
|
46
|
+
} & {
|
|
47
|
+
name: string;
|
|
48
|
+
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
49
|
+
projectId: mongoose.Types.ObjectId;
|
|
50
|
+
}> & {
|
|
51
|
+
_id: mongoose.Types.ObjectId;
|
|
52
|
+
} & {
|
|
53
|
+
__v: number;
|
|
54
|
+
}>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initExportCollectionModel = initExportCollectionModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const ExportEntrySchema = new mongoose_1.default.Schema({}, { strict: false, _id: false });
|
|
9
|
+
const ExportCollectionSchema = new mongoose_1.default.Schema({
|
|
10
|
+
projectId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Project', required: true },
|
|
11
|
+
name: { type: String, required: true }, // e.g., "experience"
|
|
12
|
+
entries: [ExportEntrySchema],
|
|
13
|
+
}, {
|
|
14
|
+
timestamps: true,
|
|
15
|
+
});
|
|
16
|
+
ExportCollectionSchema.index({ projectId: 1, name: 1 }, { unique: true });
|
|
17
|
+
function initExportCollectionModel(connection) {
|
|
18
|
+
return connection.model('ExportCollection', ExportCollectionSchema);
|
|
19
|
+
}
|
|
@@ -1,12 +1,72 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
|
-
import { StorageAdapter } from '../types';
|
|
3
|
-
|
|
4
|
-
export interface DatabaseCredential {
|
|
5
|
-
dbType: SupportedDbType;
|
|
6
|
-
connectionString: string;
|
|
7
|
-
}
|
|
2
|
+
import { StorageAdapter, DatabaseCredential } from '../types';
|
|
3
|
+
import { PrismaClient } from '@prisma/client';
|
|
8
4
|
export declare function createDatabaseProvider(databases: DatabaseCredential[], adapter: StorageAdapter): {
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
exportProvider: import("../types").ExportProvider | undefined;
|
|
6
|
+
projectProviders: {
|
|
7
|
+
nosql: import("../types").ProjectProvider | undefined;
|
|
8
|
+
sql: import("../types").ProjectProvider | undefined;
|
|
9
|
+
};
|
|
10
|
+
exportCollectionProvider: {
|
|
11
|
+
getById(id: string): Promise<({
|
|
12
|
+
entries: {
|
|
13
|
+
id: string;
|
|
14
|
+
exportCollectionId: string;
|
|
15
|
+
key: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}[];
|
|
18
|
+
} & {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
projectId: string;
|
|
24
|
+
}) | null>;
|
|
25
|
+
create(data: {
|
|
26
|
+
projectId: string;
|
|
27
|
+
name: string;
|
|
28
|
+
entries: Array<{
|
|
29
|
+
key: string;
|
|
30
|
+
value: string;
|
|
31
|
+
}>;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
entries: {
|
|
34
|
+
id: string;
|
|
35
|
+
exportCollectionId: string;
|
|
36
|
+
key: string;
|
|
37
|
+
value: string;
|
|
38
|
+
}[];
|
|
39
|
+
} & {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
projectId: string;
|
|
45
|
+
}>;
|
|
46
|
+
update(id: string, data: {
|
|
47
|
+
name?: string;
|
|
48
|
+
entries?: Array<{
|
|
49
|
+
key: string;
|
|
50
|
+
value: string;
|
|
51
|
+
}>;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
entries: {
|
|
54
|
+
id: string;
|
|
55
|
+
exportCollectionId: string;
|
|
56
|
+
key: string;
|
|
57
|
+
value: string;
|
|
58
|
+
}[];
|
|
59
|
+
} & {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
createdAt: Date;
|
|
63
|
+
updatedAt: Date;
|
|
64
|
+
projectId: string;
|
|
65
|
+
}>;
|
|
66
|
+
delete(id: string): Promise<{
|
|
67
|
+
success: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
} | undefined;
|
|
70
|
+
mongoConnection: mongoose.Connection | undefined;
|
|
71
|
+
prismaClient: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs> | undefined;
|
|
11
72
|
};
|
|
12
|
-
export {};
|
|
@@ -6,21 +6,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createDatabaseProvider = createDatabaseProvider;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const initProjectModel_1 = require("../db/initProjectModel");
|
|
9
|
+
const initUserModel_1 = require("../db/initUserModel");
|
|
10
|
+
const mongoExportProvider_1 = require("./mongoExportProvider");
|
|
9
11
|
const mongoProjectProvider_1 = require("./mongoProjectProvider");
|
|
12
|
+
const initExportModel_1 = require("../db/initExportModel");
|
|
13
|
+
const createPrismaProvider_1 = require("./createPrismaProvider");
|
|
14
|
+
const prismaExportProvider_1 = require("./prismaExportProvider");
|
|
15
|
+
const prismaProjectProvider_1 = require("./prismaProjectProvider");
|
|
16
|
+
const prismaExportCollectionProvider_1 = require("./prismaExportCollectionProvider");
|
|
10
17
|
function createDatabaseProvider(databases, adapter) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
let mongoConnection;
|
|
19
|
+
let prismaClient;
|
|
20
|
+
const mongoConfig = databases.find((db) => db.dbType === 'nosql');
|
|
21
|
+
if (mongoConfig) {
|
|
22
|
+
if (!mongoConfig.connectionString) {
|
|
23
|
+
throw new Error('MongoDB connection string is required for mongo dbType.');
|
|
24
|
+
}
|
|
25
|
+
mongoConnection = mongoose_1.default.createConnection(mongoConfig.connectionString, {
|
|
26
|
+
dbName: undefined,
|
|
27
|
+
});
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
const prismaConfig = databases.find((db) => db.dbType === 'sql');
|
|
30
|
+
if (prismaConfig) {
|
|
31
|
+
if (!prismaConfig.connectionString) {
|
|
32
|
+
throw new Error('Prisma connection string is required for prisma dbType.');
|
|
33
|
+
}
|
|
34
|
+
prismaClient = (0, createPrismaProvider_1.createPrismaProvider)(prismaConfig.connectionString) || undefined;
|
|
35
|
+
}
|
|
36
|
+
if (!mongoConnection && !prismaClient) {
|
|
37
|
+
throw new Error('At least one database configuration (mongo or prisma) is required.');
|
|
38
|
+
}
|
|
39
|
+
// If mongoConnection is not defined, we can't create mongo-based providers
|
|
40
|
+
const ExportModel = mongoConnection ? (0, initExportModel_1.initExportModel)(mongoConnection) : undefined;
|
|
41
|
+
const ProjectModel = mongoConnection ? (0, initProjectModel_1.initProjectModel)(mongoConnection) : undefined;
|
|
42
|
+
const UserModel = mongoConnection ? (0, initUserModel_1.initUserModel)(mongoConnection) : undefined;
|
|
43
|
+
const mongoExportProvider = ExportModel ? (0, mongoExportProvider_1.createMongoExportProvider)(ExportModel) : undefined;
|
|
44
|
+
const mongoProjectProvider = ProjectModel && ExportModel ? (0, mongoProjectProvider_1.createMongoProjectProvider)(ProjectModel, ExportModel, adapter) : undefined;
|
|
45
|
+
const prismaExportProvider = prismaClient ? (0, prismaExportProvider_1.createPrismaExportProvider)(prismaClient) : undefined;
|
|
46
|
+
const prismaProjectProvider = prismaClient ? (0, prismaProjectProvider_1.createPrismaProjectProvider)(prismaClient, adapter) : undefined;
|
|
47
|
+
const prismaExportCollectionProvider = prismaClient ? (0, prismaExportCollectionProvider_1.createPrismaExportCollectionProvider)(prismaClient) : undefined;
|
|
22
48
|
return {
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
exportProvider: mongoExportProvider || prismaExportProvider,
|
|
50
|
+
projectProviders: {
|
|
51
|
+
nosql: mongoProjectProvider,
|
|
52
|
+
sql: prismaProjectProvider,
|
|
53
|
+
},
|
|
54
|
+
exportCollectionProvider: prismaExportCollectionProvider, // Solo Prisma tiene este por ahora
|
|
55
|
+
mongoConnection,
|
|
56
|
+
prismaClient,
|
|
25
57
|
};
|
|
26
58
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrismaProvider = createPrismaProvider;
|
|
4
|
+
const client_1 = require("@prisma/client");
|
|
5
|
+
function createPrismaProvider(connectionString) {
|
|
6
|
+
if (!connectionString) {
|
|
7
|
+
console.warn('Connection string is not provided. Prisma client will not be initialized.');
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const prisma = new client_1.PrismaClient({
|
|
11
|
+
datasources: {
|
|
12
|
+
db: {
|
|
13
|
+
url: connectionString,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return prisma;
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMongoExportProvider = createMongoExportProvider;
|
|
4
|
+
function createMongoExportProvider(ExportModel) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(exportId) {
|
|
7
|
+
return await ExportModel.findById(exportId).lean();
|
|
8
|
+
},
|
|
9
|
+
async create(data) {
|
|
10
|
+
return await ExportModel.create(data);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectProvider, StorageAdapter } from '../types';
|
|
2
2
|
import { Model } from 'mongoose';
|
|
3
|
-
export declare function createMongoProjectProvider(ProjectModel: Model<any>, adapter: StorageAdapter): ProjectProvider;
|
|
3
|
+
export declare function createMongoProjectProvider(ProjectModel: Model<any>, ExportModel: Model<any>, adapter: StorageAdapter): ProjectProvider;
|