streamby-core 0.13.0 → 0.14.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/db/initExportModel.d.ts +60 -0
- package/dist/db/initExportModel.js +18 -0
- package/dist/db/initProjectModel.d.ts +6 -0
- package/dist/db/initProjectModel.js +2 -1
- package/dist/db/initUserModel.d.ts +48 -0
- package/dist/db/initUserModel.js +19 -0
- package/dist/middleware/createRouter.js +89 -44
- package/dist/models/ExportCollection.d.ts +54 -0
- package/dist/models/ExportCollection.js +19 -0
- package/dist/providers/createDatabaseProvider.d.ts +1 -0
- package/dist/providers/createDatabaseProvider.js +9 -4
- 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 +51 -32
- package/dist/types/index.d.ts +30 -4
- package/package.json +1 -1
- package/dist/dev/server.d.ts +0 -4
- package/dist/dev/server.js +0 -14
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initExportModel(connection: mongoose.Connection): mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
name: string;
|
|
7
|
+
collectionName: string;
|
|
8
|
+
projectId: mongoose.Types.ObjectId;
|
|
9
|
+
description?: string | null | undefined;
|
|
10
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
11
|
+
createdAt: NativeDate;
|
|
12
|
+
updatedAt: NativeDate;
|
|
13
|
+
} & {
|
|
14
|
+
name: string;
|
|
15
|
+
collectionName: string;
|
|
16
|
+
projectId: mongoose.Types.ObjectId;
|
|
17
|
+
description?: string | null | undefined;
|
|
18
|
+
}> & {
|
|
19
|
+
createdAt: NativeDate;
|
|
20
|
+
updatedAt: NativeDate;
|
|
21
|
+
} & {
|
|
22
|
+
name: string;
|
|
23
|
+
collectionName: string;
|
|
24
|
+
projectId: mongoose.Types.ObjectId;
|
|
25
|
+
description?: string | null | undefined;
|
|
26
|
+
} & {
|
|
27
|
+
_id: mongoose.Types.ObjectId;
|
|
28
|
+
} & {
|
|
29
|
+
__v: number;
|
|
30
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
31
|
+
timestamps: true;
|
|
32
|
+
}, {
|
|
33
|
+
createdAt: NativeDate;
|
|
34
|
+
updatedAt: NativeDate;
|
|
35
|
+
} & {
|
|
36
|
+
name: string;
|
|
37
|
+
collectionName: string;
|
|
38
|
+
projectId: mongoose.Types.ObjectId;
|
|
39
|
+
description?: string | null | undefined;
|
|
40
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
41
|
+
createdAt: NativeDate;
|
|
42
|
+
updatedAt: NativeDate;
|
|
43
|
+
} & {
|
|
44
|
+
name: string;
|
|
45
|
+
collectionName: string;
|
|
46
|
+
projectId: mongoose.Types.ObjectId;
|
|
47
|
+
description?: string | null | undefined;
|
|
48
|
+
}>> & mongoose.FlatRecord<{
|
|
49
|
+
createdAt: NativeDate;
|
|
50
|
+
updatedAt: NativeDate;
|
|
51
|
+
} & {
|
|
52
|
+
name: string;
|
|
53
|
+
collectionName: string;
|
|
54
|
+
projectId: mongoose.Types.ObjectId;
|
|
55
|
+
description?: string | null | undefined;
|
|
56
|
+
}> & {
|
|
57
|
+
_id: mongoose.Types.ObjectId;
|
|
58
|
+
} & {
|
|
59
|
+
__v: number;
|
|
60
|
+
}>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
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.initExportModel = initExportModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
function initExportModel(connection) {
|
|
9
|
+
const exportSchema = new mongoose_1.default.Schema({
|
|
10
|
+
name: { type: String, required: true },
|
|
11
|
+
description: { type: String },
|
|
12
|
+
collectionName: { type: String, required: true },
|
|
13
|
+
projectId: { type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Project', required: true },
|
|
14
|
+
}, {
|
|
15
|
+
timestamps: true
|
|
16
|
+
});
|
|
17
|
+
return connection.model('Export', exportSchema);
|
|
18
|
+
}
|
|
@@ -408,6 +408,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
408
408
|
role: "viewer" | "editor" | "admin";
|
|
409
409
|
archived: boolean;
|
|
410
410
|
}>;
|
|
411
|
+
exports: mongoose.Types.ObjectId[];
|
|
411
412
|
allowUpload: boolean;
|
|
412
413
|
allowSharing: boolean;
|
|
413
414
|
image?: string | null | undefined;
|
|
@@ -821,6 +822,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
821
822
|
role: "viewer" | "editor" | "admin";
|
|
822
823
|
archived: boolean;
|
|
823
824
|
}>;
|
|
825
|
+
exports: mongoose.Types.ObjectId[];
|
|
824
826
|
allowUpload: boolean;
|
|
825
827
|
allowSharing: boolean;
|
|
826
828
|
image?: string | null | undefined;
|
|
@@ -1234,6 +1236,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1234
1236
|
role: "viewer" | "editor" | "admin";
|
|
1235
1237
|
archived: boolean;
|
|
1236
1238
|
}>;
|
|
1239
|
+
exports: mongoose.Types.ObjectId[];
|
|
1237
1240
|
allowUpload: boolean;
|
|
1238
1241
|
allowSharing: boolean;
|
|
1239
1242
|
image?: string | null | undefined;
|
|
@@ -1653,6 +1656,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1653
1656
|
role: "viewer" | "editor" | "admin";
|
|
1654
1657
|
archived: boolean;
|
|
1655
1658
|
}>;
|
|
1659
|
+
exports: mongoose.Types.ObjectId[];
|
|
1656
1660
|
allowUpload: boolean;
|
|
1657
1661
|
allowSharing: boolean;
|
|
1658
1662
|
image?: string | null | undefined;
|
|
@@ -2066,6 +2070,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2066
2070
|
role: "viewer" | "editor" | "admin";
|
|
2067
2071
|
archived: boolean;
|
|
2068
2072
|
}>;
|
|
2073
|
+
exports: mongoose.Types.ObjectId[];
|
|
2069
2074
|
allowUpload: boolean;
|
|
2070
2075
|
allowSharing: boolean;
|
|
2071
2076
|
image?: string | null | undefined;
|
|
@@ -2479,6 +2484,7 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2479
2484
|
role: "viewer" | "editor" | "admin";
|
|
2480
2485
|
archived: boolean;
|
|
2481
2486
|
}>;
|
|
2487
|
+
exports: mongoose.Types.ObjectId[];
|
|
2482
2488
|
allowUpload: boolean;
|
|
2483
2489
|
allowSharing: boolean;
|
|
2484
2490
|
image?: string | null | undefined;
|
|
@@ -23,7 +23,8 @@ function initProjectModel(connection) {
|
|
|
23
23
|
rootFolders: [folderNodeSchema],
|
|
24
24
|
allowUpload: { type: Boolean, default: true },
|
|
25
25
|
allowSharing: { type: Boolean, default: false },
|
|
26
|
-
members: [memberSchema]
|
|
26
|
+
members: [memberSchema],
|
|
27
|
+
exports: [{ type: mongoose_1.default.Schema.Types.ObjectId, ref: 'Export' }]
|
|
27
28
|
}, {
|
|
28
29
|
timestamps: true
|
|
29
30
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
export declare function initUserModel(connection: mongoose.Connection): mongoose.Model<any, {}, {}, {}, any, any> | mongoose.Model<{
|
|
3
|
+
createdAt: NativeDate;
|
|
4
|
+
updatedAt: NativeDate;
|
|
5
|
+
} & {
|
|
6
|
+
username: string;
|
|
7
|
+
email: string;
|
|
8
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
9
|
+
createdAt: NativeDate;
|
|
10
|
+
updatedAt: NativeDate;
|
|
11
|
+
} & {
|
|
12
|
+
username: string;
|
|
13
|
+
email: string;
|
|
14
|
+
}> & {
|
|
15
|
+
createdAt: NativeDate;
|
|
16
|
+
updatedAt: NativeDate;
|
|
17
|
+
} & {
|
|
18
|
+
username: string;
|
|
19
|
+
email: string;
|
|
20
|
+
} & {
|
|
21
|
+
_id: mongoose.Types.ObjectId;
|
|
22
|
+
} & {
|
|
23
|
+
__v: number;
|
|
24
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
25
|
+
timestamps: true;
|
|
26
|
+
}, {
|
|
27
|
+
createdAt: NativeDate;
|
|
28
|
+
updatedAt: NativeDate;
|
|
29
|
+
} & {
|
|
30
|
+
username: string;
|
|
31
|
+
email: string;
|
|
32
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
33
|
+
createdAt: NativeDate;
|
|
34
|
+
updatedAt: NativeDate;
|
|
35
|
+
} & {
|
|
36
|
+
username: string;
|
|
37
|
+
email: string;
|
|
38
|
+
}>> & mongoose.FlatRecord<{
|
|
39
|
+
createdAt: NativeDate;
|
|
40
|
+
updatedAt: NativeDate;
|
|
41
|
+
} & {
|
|
42
|
+
username: string;
|
|
43
|
+
email: string;
|
|
44
|
+
}> & {
|
|
45
|
+
_id: mongoose.Types.ObjectId;
|
|
46
|
+
} & {
|
|
47
|
+
__v: number;
|
|
48
|
+
}>>;
|
|
@@ -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.initUserModel = initUserModel;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
function initUserModel(connection) {
|
|
9
|
+
const userSchema = new mongoose_1.default.Schema({
|
|
10
|
+
username: { type: String, required: true, unique: true },
|
|
11
|
+
email: { type: String, required: true, unique: true },
|
|
12
|
+
}, {
|
|
13
|
+
timestamps: true
|
|
14
|
+
});
|
|
15
|
+
if (connection.models.User) {
|
|
16
|
+
return connection.models.User;
|
|
17
|
+
}
|
|
18
|
+
return connection.model('User', userSchema);
|
|
19
|
+
}
|
|
@@ -15,13 +15,11 @@ 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
|
-
|
|
23
|
-
return dbResult.projectProvider;
|
|
24
|
-
})();
|
|
18
|
+
const dbResult = config.projectProvider
|
|
19
|
+
? { projectProvider: config.projectProvider, exportProvider: config.exportProvider, mongoConnection: undefined }
|
|
20
|
+
: (0, createDatabaseProvider_1.createDatabaseProvider)(config.databases, adapter);
|
|
21
|
+
const projectProvider = dbResult.projectProvider;
|
|
22
|
+
const exportProvider = dbResult.exportProvider;
|
|
25
23
|
router.get('/auth', async (req, res) => {
|
|
26
24
|
try {
|
|
27
25
|
const auth = await config.authProvider(req);
|
|
@@ -80,31 +78,14 @@ function createStreamByRouter(config) {
|
|
|
80
78
|
res.status(500).json({ error: 'Failed to list files', details: err });
|
|
81
79
|
}
|
|
82
80
|
});
|
|
83
|
-
router.get('/projects
|
|
84
|
-
try {
|
|
85
|
-
const auth = await config.authProvider(req);
|
|
86
|
-
const archivedProjects = await projectProvider.listArchived(auth.userId);
|
|
87
|
-
res.json({ projects: archivedProjects });
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
res.status(500).json({ error: 'Failed to list archived projects', details: err });
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
router.get('/projects/:id', async (req, res) => {
|
|
81
|
+
router.get('/projects', async (req, res) => {
|
|
94
82
|
try {
|
|
95
83
|
const auth = await config.authProvider(req);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
if (!project) {
|
|
99
|
-
return res.status(404).json({ error: 'Project not found' });
|
|
100
|
-
}
|
|
101
|
-
if (!isProjectMember(project, auth.userId)) {
|
|
102
|
-
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
103
|
-
}
|
|
104
|
-
res.json({ project });
|
|
84
|
+
const projects = await projectProvider.list(auth.userId);
|
|
85
|
+
res.json({ projects });
|
|
105
86
|
}
|
|
106
87
|
catch (err) {
|
|
107
|
-
res.status(500).json({ error: 'Failed to
|
|
88
|
+
res.status(500).json({ error: 'Failed to list projects', details: err });
|
|
108
89
|
}
|
|
109
90
|
});
|
|
110
91
|
router.post('/projects/create', async (req, res) => {
|
|
@@ -125,6 +106,23 @@ function createStreamByRouter(config) {
|
|
|
125
106
|
res.status(500).json({ error: 'Failed to create project', details: err.message });
|
|
126
107
|
}
|
|
127
108
|
});
|
|
109
|
+
router.get('/projects/:id', async (req, res) => {
|
|
110
|
+
try {
|
|
111
|
+
const auth = await config.authProvider(req);
|
|
112
|
+
const projectId = req.params.id;
|
|
113
|
+
const project = await projectProvider.getById(projectId);
|
|
114
|
+
if (!project) {
|
|
115
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
116
|
+
}
|
|
117
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
118
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
119
|
+
}
|
|
120
|
+
res.json({ project });
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
res.status(500).json({ error: 'Failed to fetch project', details: err.message });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
128
126
|
router.patch('/projects/:id', async (req, res) => {
|
|
129
127
|
try {
|
|
130
128
|
const auth = await config.authProvider(req);
|
|
@@ -168,17 +166,22 @@ function createStreamByRouter(config) {
|
|
|
168
166
|
res.status(500).json({ error: 'Failed to delete project', details: err.message });
|
|
169
167
|
}
|
|
170
168
|
});
|
|
171
|
-
router.
|
|
169
|
+
router.patch('/projects/:id/archive', async (req, res) => {
|
|
172
170
|
try {
|
|
173
171
|
const auth = await config.authProvider(req);
|
|
174
|
-
const
|
|
175
|
-
|
|
172
|
+
const projectId = req.params.id;
|
|
173
|
+
const project = await projectProvider.getById(projectId);
|
|
174
|
+
if (!project || !isProjectMember(project, auth.userId)) {
|
|
175
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
176
|
+
}
|
|
177
|
+
const result = await projectProvider.archive(projectId, auth.userId);
|
|
178
|
+
res.status(200).json(result);
|
|
176
179
|
}
|
|
177
180
|
catch (err) {
|
|
178
|
-
res.status(500).json({ error: 'Failed to
|
|
181
|
+
res.status(500).json({ error: 'Failed to archive project', details: err.message });
|
|
179
182
|
}
|
|
180
183
|
});
|
|
181
|
-
router.patch('/projects/:id/
|
|
184
|
+
router.patch('/projects/:id/unarchive', async (req, res) => {
|
|
182
185
|
try {
|
|
183
186
|
const auth = await config.authProvider(req);
|
|
184
187
|
const projectId = req.params.id;
|
|
@@ -186,30 +189,72 @@ function createStreamByRouter(config) {
|
|
|
186
189
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
187
190
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
188
191
|
}
|
|
189
|
-
await projectProvider.
|
|
190
|
-
|
|
191
|
-
const archivedProjects = await projectProvider.listArchived(auth.userId);
|
|
192
|
-
res.status(200).json({ success: true, projects, archivedProjects });
|
|
192
|
+
const result = await projectProvider.unarchive(projectId, auth.userId);
|
|
193
|
+
res.status(200).json(result);
|
|
193
194
|
}
|
|
194
195
|
catch (err) {
|
|
195
|
-
res.status(500).json({ error: 'Failed to
|
|
196
|
+
res.status(500).json({ error: 'Failed to unarchive project', details: err.message });
|
|
196
197
|
}
|
|
197
198
|
});
|
|
198
|
-
router.
|
|
199
|
+
router.get('/projects/:id/exports/:export_id', async (req, res) => {
|
|
199
200
|
try {
|
|
200
201
|
const auth = await config.authProvider(req);
|
|
201
202
|
const projectId = req.params.id;
|
|
203
|
+
const exportId = req.params.export_id;
|
|
204
|
+
const project = await projectProvider.getById(projectId);
|
|
205
|
+
if (!project) {
|
|
206
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
207
|
+
}
|
|
208
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
209
|
+
return res.status(403).json({ error: 'Unauthorized access' });
|
|
210
|
+
}
|
|
211
|
+
const data = await exportProvider.getById(exportId);
|
|
212
|
+
res.json({ data });
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
res.status(500).json({ error: 'Failed to fetch export data', details: err.message });
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
router.post('/projects/:id/exports', async (req, res) => {
|
|
219
|
+
try {
|
|
220
|
+
const auth = await config.authProvider(req);
|
|
221
|
+
const projectId = req.params.id;
|
|
222
|
+
const { name, description, collectionName } = req.body;
|
|
223
|
+
if (!name || !collectionName) {
|
|
224
|
+
return res.status(400).json({ error: 'Missing export name or collectionName' });
|
|
225
|
+
}
|
|
202
226
|
const project = await projectProvider.getById(projectId);
|
|
203
227
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
204
228
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
205
229
|
}
|
|
206
|
-
await
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
230
|
+
const newExport = await exportProvider.create({
|
|
231
|
+
name,
|
|
232
|
+
description,
|
|
233
|
+
collectionName,
|
|
234
|
+
projectId
|
|
235
|
+
});
|
|
236
|
+
await projectProvider.addExportToProject(projectId, newExport.id);
|
|
237
|
+
res.status(201).json({ data: newExport });
|
|
210
238
|
}
|
|
211
239
|
catch (err) {
|
|
212
|
-
res.status(500).json({ error: 'Failed to
|
|
240
|
+
res.status(500).json({ error: 'Failed to create export', details: err.message });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
router.get('/projects/:id/members', async (req, res) => {
|
|
244
|
+
try {
|
|
245
|
+
const auth = await config.authProvider(req);
|
|
246
|
+
const projectId = req.params.id;
|
|
247
|
+
const project = await projectProvider.getById(projectId, true);
|
|
248
|
+
if (!project) {
|
|
249
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
250
|
+
}
|
|
251
|
+
if (!isProjectMember(project, auth.userId)) {
|
|
252
|
+
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
253
|
+
}
|
|
254
|
+
res.json({ members: project.members });
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
res.status(500).json({ error: 'Failed to fetch project members', details: err.message });
|
|
213
258
|
}
|
|
214
259
|
});
|
|
215
260
|
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
|
+
}
|
|
@@ -6,6 +6,7 @@ export interface DatabaseCredential {
|
|
|
6
6
|
connectionString: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function createDatabaseProvider(databases: DatabaseCredential[], adapter: StorageAdapter): {
|
|
9
|
+
exportProvider: import("../types").ExportProvider;
|
|
9
10
|
projectProvider: import("../types").ProjectProvider;
|
|
10
11
|
mongoConnection: mongoose.Connection;
|
|
11
12
|
};
|
|
@@ -6,20 +6,25 @@ 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");
|
|
10
13
|
function createDatabaseProvider(databases, adapter) {
|
|
11
|
-
// Solo una conexión mongo por ahora
|
|
12
14
|
const mongoConfig = databases.find((db) => db.dbType === 'mongo');
|
|
13
15
|
if (!mongoConfig) {
|
|
14
16
|
throw new Error('No MongoDB configuration provided. Mongo is currently required.');
|
|
15
17
|
}
|
|
16
|
-
// Conexión a MongoDB
|
|
17
18
|
const connection = mongoose_1.default.createConnection(mongoConfig.connectionString, {
|
|
18
|
-
dbName: undefined,
|
|
19
|
+
dbName: undefined,
|
|
19
20
|
});
|
|
21
|
+
const ExportModel = (0, initExportModel_1.initExportModel)(connection);
|
|
20
22
|
const ProjectModel = (0, initProjectModel_1.initProjectModel)(connection);
|
|
21
|
-
const
|
|
23
|
+
const UserModel = (0, initUserModel_1.initUserModel)(connection);
|
|
24
|
+
const exportProvider = (0, mongoExportProvider_1.createMongoExportProvider)(ExportModel);
|
|
25
|
+
const projectProvider = (0, mongoProjectProvider_1.createMongoProjectProvider)(ProjectModel, ExportModel, adapter);
|
|
22
26
|
return {
|
|
27
|
+
exportProvider,
|
|
23
28
|
projectProvider,
|
|
24
29
|
mongoConnection: connection,
|
|
25
30
|
};
|
|
@@ -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;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createMongoProjectProvider = createMongoProjectProvider;
|
|
4
|
-
function createMongoProjectProvider(ProjectModel, adapter) {
|
|
4
|
+
function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
5
5
|
return {
|
|
6
|
-
async getById(projectId) {
|
|
7
|
-
|
|
6
|
+
async getById(projectId, populateMembers = false) {
|
|
7
|
+
let query = ProjectModel.findById(projectId).populate('exports', ['_id', 'collectionName']);
|
|
8
|
+
if (populateMembers) {
|
|
9
|
+
query = query.populate('members.userId');
|
|
10
|
+
}
|
|
11
|
+
const project = await query;
|
|
8
12
|
if (!project)
|
|
9
13
|
throw new Error('Project not found');
|
|
10
14
|
return formatProject(project);
|
|
@@ -28,22 +32,16 @@ function createMongoProjectProvider(ProjectModel, adapter) {
|
|
|
28
32
|
return formatProject(newProject);
|
|
29
33
|
},
|
|
30
34
|
async update(projectId, updates) {
|
|
31
|
-
const updated = await ProjectModel.findByIdAndUpdate(projectId, updates, { new: true });
|
|
35
|
+
const updated = await ProjectModel.findByIdAndUpdate(projectId, updates, { new: true }).populate('exports', ['_id', 'collectionName']);
|
|
32
36
|
if (!updated)
|
|
33
37
|
throw new Error('Project not found');
|
|
34
38
|
return formatProject(updated);
|
|
35
39
|
},
|
|
36
40
|
async list(userId) {
|
|
37
41
|
const all = await ProjectModel.find(userId
|
|
38
|
-
? { 'members': { $elemMatch: { userId
|
|
42
|
+
? { 'members': { $elemMatch: { userId } } }
|
|
39
43
|
: {});
|
|
40
|
-
return all.map(
|
|
41
|
-
},
|
|
42
|
-
async listArchived(userId) {
|
|
43
|
-
const all = await ProjectModel.find(userId
|
|
44
|
-
? { 'members': { $elemMatch: { userId, archived: true } } }
|
|
45
|
-
: {});
|
|
46
|
-
return all.map(formatProject);
|
|
44
|
+
return all.map(doc => formatProjectList(doc, userId));
|
|
47
45
|
},
|
|
48
46
|
async delete(projectId) {
|
|
49
47
|
try {
|
|
@@ -57,29 +55,50 @@ function createMongoProjectProvider(ProjectModel, adapter) {
|
|
|
57
55
|
},
|
|
58
56
|
async archive(projectId, userId) {
|
|
59
57
|
await ProjectModel.updateOne({ _id: projectId, 'members.userId': userId }, { $set: { 'members.$.archived': true } });
|
|
60
|
-
return { success: true, projects: await this.list(userId)
|
|
58
|
+
return { success: true, projects: await this.list(userId) };
|
|
61
59
|
},
|
|
62
60
|
async unarchive(projectId, userId) {
|
|
63
61
|
await ProjectModel.updateOne({ _id: projectId, 'members.userId': userId }, { $set: { 'members.$.archived': false } });
|
|
64
|
-
return { success: true, projects: await this.list(userId)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
userId: m.userId,
|
|
75
|
-
role: m.role,
|
|
76
|
-
archived: m.archived ?? false
|
|
77
|
-
})),
|
|
78
|
-
description: doc.description,
|
|
79
|
-
rootFolders: doc.rootFolders || [],
|
|
80
|
-
settings: {
|
|
81
|
-
allowUpload: doc.allowUpload,
|
|
82
|
-
allowSharing: doc.allowSharing,
|
|
62
|
+
return { success: true, projects: await this.list(userId) };
|
|
63
|
+
},
|
|
64
|
+
async getExport(projectId, exportId) {
|
|
65
|
+
const exportDoc = await ExportModel.findOne({ _id: exportId, project: projectId });
|
|
66
|
+
if (!exportDoc)
|
|
67
|
+
throw new Error('Export not found');
|
|
68
|
+
return exportDoc;
|
|
69
|
+
},
|
|
70
|
+
async addExportToProject(projectId, exportId) {
|
|
71
|
+
await ProjectModel.findByIdAndUpdate(projectId, { $push: { exports: exportId } });
|
|
83
72
|
}
|
|
84
73
|
};
|
|
74
|
+
function formatProject(doc) {
|
|
75
|
+
return {
|
|
76
|
+
id: doc._id.toString(),
|
|
77
|
+
name: doc.name,
|
|
78
|
+
image: doc.image,
|
|
79
|
+
members: doc.members.map((m) => ({
|
|
80
|
+
userId: m.userId?._id || m.userId,
|
|
81
|
+
username: m.userId?.username,
|
|
82
|
+
email: m.userId?.email,
|
|
83
|
+
role: m.role,
|
|
84
|
+
archived: m.archived ?? false
|
|
85
|
+
})),
|
|
86
|
+
description: doc.description,
|
|
87
|
+
rootFolders: doc.rootFolders || [],
|
|
88
|
+
settings: {
|
|
89
|
+
allowUpload: doc.allowUpload,
|
|
90
|
+
allowSharing: doc.allowSharing,
|
|
91
|
+
},
|
|
92
|
+
exports: doc.exports || []
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function formatProjectList(doc, userId) {
|
|
96
|
+
const archived = doc.members?.find((m) => m.userId?.toString() === userId)?.archived ?? false;
|
|
97
|
+
return {
|
|
98
|
+
id: doc._id.toString(),
|
|
99
|
+
name: doc.name,
|
|
100
|
+
image: doc.image,
|
|
101
|
+
archived
|
|
102
|
+
};
|
|
103
|
+
}
|
|
85
104
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -34,11 +34,21 @@ export interface ProjectInfo {
|
|
|
34
34
|
}[];
|
|
35
35
|
description?: string;
|
|
36
36
|
rootFolders?: FolderNode[];
|
|
37
|
+
exports?: {
|
|
38
|
+
_id: string;
|
|
39
|
+
collectionName: string;
|
|
40
|
+
}[];
|
|
37
41
|
settings?: {
|
|
38
42
|
allowUpload?: boolean;
|
|
39
43
|
allowSharing?: boolean;
|
|
40
44
|
};
|
|
41
45
|
}
|
|
46
|
+
export interface ProjectListInfo {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
image?: string;
|
|
50
|
+
archived: boolean;
|
|
51
|
+
}
|
|
42
52
|
export interface FolderNode {
|
|
43
53
|
id: string;
|
|
44
54
|
name: string;
|
|
@@ -56,6 +66,7 @@ export interface StreamByConfig {
|
|
|
56
66
|
}[];
|
|
57
67
|
authProvider: AuthProvider;
|
|
58
68
|
databases?: DatabaseCredential[];
|
|
69
|
+
exportProvider?: ExportProvider;
|
|
59
70
|
projectProvider?: ProjectProvider;
|
|
60
71
|
adapter?: StorageAdapter;
|
|
61
72
|
}
|
|
@@ -66,20 +77,34 @@ export interface AuthContext {
|
|
|
66
77
|
role: 'viewer' | 'editor' | 'admin';
|
|
67
78
|
}
|
|
68
79
|
export type AuthProvider = (req: Request) => Promise<AuthContext>;
|
|
80
|
+
export interface Export {
|
|
81
|
+
id: string;
|
|
82
|
+
collectionName: string;
|
|
83
|
+
projectId: string;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
}
|
|
87
|
+
export interface ExportProvider {
|
|
88
|
+
getById(exportId: string): Promise<Export>;
|
|
89
|
+
create(data: {
|
|
90
|
+
name: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
collectionName: string;
|
|
93
|
+
projectId: string;
|
|
94
|
+
}): Promise<Export>;
|
|
95
|
+
}
|
|
69
96
|
export interface ProjectProvider {
|
|
97
|
+
getExport(projectId: string, exportName: string): Promise<any[]>;
|
|
70
98
|
archive(projectId: string, userId: string): Promise<{
|
|
71
99
|
success: boolean;
|
|
72
100
|
projects: ProjectInfo[];
|
|
73
|
-
archivedProjects: ProjectInfo[];
|
|
74
101
|
}>;
|
|
75
102
|
unarchive(projectId: string, userId: string): Promise<{
|
|
76
103
|
success: boolean;
|
|
77
104
|
projects: ProjectInfo[];
|
|
78
|
-
archivedProjects: ProjectInfo[];
|
|
79
105
|
}>;
|
|
80
106
|
list(userId?: string): Promise<ProjectInfo[]>;
|
|
81
|
-
|
|
82
|
-
getById(projectId: string): Promise<ProjectInfo>;
|
|
107
|
+
getById(projectId: string, populateMembers?: boolean): Promise<ProjectInfo>;
|
|
83
108
|
delete(projectId: string): Promise<{
|
|
84
109
|
success: boolean;
|
|
85
110
|
}>;
|
|
@@ -96,4 +121,5 @@ export interface ProjectProvider {
|
|
|
96
121
|
allowSharing?: boolean;
|
|
97
122
|
rootFolders?: FolderNode[];
|
|
98
123
|
}): Promise<ProjectInfo>;
|
|
124
|
+
addExportToProject(projectId: string, exportId: string): Promise<void>;
|
|
99
125
|
}
|
package/package.json
CHANGED
package/dist/dev/server.d.ts
DELETED
package/dist/dev/server.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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.createDevServer = createDevServer;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const createRouter_1 = require("../middleware/createRouter");
|
|
9
|
-
function createDevServer(config) {
|
|
10
|
-
const app = (0, express_1.default)();
|
|
11
|
-
app.use(express_1.default.json());
|
|
12
|
-
app.use((0, createRouter_1.createStreamByRouter)(config));
|
|
13
|
-
return app;
|
|
14
|
-
}
|