streamby-core 0.14.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 +2 -2
- package/dist/db/initProjectModel.d.ts +67 -61
- package/dist/db/initProjectModel.js +1 -0
- package/dist/db/initUserModel.d.ts +2 -2
- package/dist/middleware/createRouter.js +141 -16
- package/dist/models/ExportCollection.d.ts +2 -2
- package/dist/providers/createDatabaseProvider.d.ts +69 -10
- package/dist/providers/createDatabaseProvider.js +41 -14
- package/dist/providers/createPrismaProvider.d.ts +8 -0
- package/dist/providers/createPrismaProvider.js +18 -0
- package/dist/providers/mongoProjectProvider.js +5 -2
- 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 +42 -11
- package/package.json +4 -2
package/dist/config.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const config: {
|
|
2
|
+
mongoUri: string;
|
|
3
|
+
s3: {
|
|
4
|
+
accessKeyId: string;
|
|
5
|
+
secretAccessKey: string;
|
|
6
|
+
region: string;
|
|
7
|
+
bucketName: string;
|
|
8
|
+
};
|
|
9
|
+
gcs: {
|
|
10
|
+
projectId: string;
|
|
11
|
+
keyFilename: string;
|
|
12
|
+
bucketName: string;
|
|
13
|
+
};
|
|
14
|
+
local: {
|
|
15
|
+
storagePath: string;
|
|
16
|
+
};
|
|
17
|
+
supabaseString: string;
|
|
18
|
+
};
|
package/dist/config.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
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.config = void 0;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
dotenv_1.default.config();
|
|
9
|
+
exports.config = {
|
|
10
|
+
mongoUri: process.env.MONGO_URI || '',
|
|
11
|
+
s3: {
|
|
12
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || '',
|
|
13
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || '',
|
|
14
|
+
region: process.env.AWS_REGION || 'us-east-1',
|
|
15
|
+
bucketName: process.env.AWS_BUCKET_NAME || 'streamby-dev',
|
|
16
|
+
},
|
|
17
|
+
gcs: {
|
|
18
|
+
projectId: process.env.GCS_PROJECT_ID || '',
|
|
19
|
+
keyFilename: process.env.GCS_KEY_FILENAME || '',
|
|
20
|
+
bucketName: process.env.GCS_BUCKET_NAME || 'streamby-dev',
|
|
21
|
+
},
|
|
22
|
+
local: {
|
|
23
|
+
storagePath: process.env.LOCAL_STORAGE_PATH || './uploads',
|
|
24
|
+
},
|
|
25
|
+
supabaseString: process.env.SUPABASE_STRING || '',
|
|
26
|
+
};
|
|
@@ -15,7 +15,7 @@ export declare function initExportModel(connection: mongoose.Connection): mongoo
|
|
|
15
15
|
collectionName: string;
|
|
16
16
|
projectId: mongoose.Types.ObjectId;
|
|
17
17
|
description?: string | null | undefined;
|
|
18
|
-
}> & {
|
|
18
|
+
}, {}> & {
|
|
19
19
|
createdAt: NativeDate;
|
|
20
20
|
updatedAt: NativeDate;
|
|
21
21
|
} & {
|
|
@@ -45,7 +45,7 @@ export declare function initExportModel(connection: mongoose.Connection): mongoo
|
|
|
45
45
|
collectionName: string;
|
|
46
46
|
projectId: mongoose.Types.ObjectId;
|
|
47
47
|
description?: string | null | undefined;
|
|
48
|
-
}
|
|
48
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
49
49
|
createdAt: NativeDate;
|
|
50
50
|
updatedAt: NativeDate;
|
|
51
51
|
} & {
|
|
@@ -3,6 +3,22 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
3
3
|
createdAt: NativeDate;
|
|
4
4
|
updatedAt: NativeDate;
|
|
5
5
|
} & {
|
|
6
|
+
dbType: string;
|
|
7
|
+
name: string;
|
|
8
|
+
members: mongoose.Types.DocumentArray<{
|
|
9
|
+
userId: mongoose.Types.ObjectId;
|
|
10
|
+
role: "viewer" | "editor" | "admin";
|
|
11
|
+
archived: boolean;
|
|
12
|
+
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
13
|
+
userId: mongoose.Types.ObjectId;
|
|
14
|
+
role: "viewer" | "editor" | "admin";
|
|
15
|
+
archived: boolean;
|
|
16
|
+
}> & {
|
|
17
|
+
userId: mongoose.Types.ObjectId;
|
|
18
|
+
role: "viewer" | "editor" | "admin";
|
|
19
|
+
archived: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
exports: mongoose.Types.ObjectId[];
|
|
6
22
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
7
23
|
children: mongoose.Types.DocumentArray<{
|
|
8
24
|
entries?: {} | null | undefined;
|
|
@@ -394,6 +410,15 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
394
410
|
id?: string | null | undefined;
|
|
395
411
|
name?: string | null | undefined;
|
|
396
412
|
}>;
|
|
413
|
+
allowUpload: boolean;
|
|
414
|
+
allowSharing: boolean;
|
|
415
|
+
image?: string | null | undefined;
|
|
416
|
+
description?: string | null | undefined;
|
|
417
|
+
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
418
|
+
createdAt: NativeDate;
|
|
419
|
+
updatedAt: NativeDate;
|
|
420
|
+
} & {
|
|
421
|
+
dbType: string;
|
|
397
422
|
name: string;
|
|
398
423
|
members: mongoose.Types.DocumentArray<{
|
|
399
424
|
userId: mongoose.Types.ObjectId;
|
|
@@ -409,14 +434,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
409
434
|
archived: boolean;
|
|
410
435
|
}>;
|
|
411
436
|
exports: mongoose.Types.ObjectId[];
|
|
412
|
-
allowUpload: boolean;
|
|
413
|
-
allowSharing: boolean;
|
|
414
|
-
image?: string | null | undefined;
|
|
415
|
-
description?: string | null | undefined;
|
|
416
|
-
}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
417
|
-
createdAt: NativeDate;
|
|
418
|
-
updatedAt: NativeDate;
|
|
419
|
-
} & {
|
|
420
437
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
421
438
|
children: mongoose.Types.DocumentArray<{
|
|
422
439
|
entries?: {} | null | undefined;
|
|
@@ -808,6 +825,15 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
808
825
|
id?: string | null | undefined;
|
|
809
826
|
name?: string | null | undefined;
|
|
810
827
|
}>;
|
|
828
|
+
allowUpload: boolean;
|
|
829
|
+
allowSharing: boolean;
|
|
830
|
+
image?: string | null | undefined;
|
|
831
|
+
description?: string | null | undefined;
|
|
832
|
+
}, {}> & {
|
|
833
|
+
createdAt: NativeDate;
|
|
834
|
+
updatedAt: NativeDate;
|
|
835
|
+
} & {
|
|
836
|
+
dbType: string;
|
|
811
837
|
name: string;
|
|
812
838
|
members: mongoose.Types.DocumentArray<{
|
|
813
839
|
userId: mongoose.Types.ObjectId;
|
|
@@ -823,14 +849,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
823
849
|
archived: boolean;
|
|
824
850
|
}>;
|
|
825
851
|
exports: mongoose.Types.ObjectId[];
|
|
826
|
-
allowUpload: boolean;
|
|
827
|
-
allowSharing: boolean;
|
|
828
|
-
image?: string | null | undefined;
|
|
829
|
-
description?: string | null | undefined;
|
|
830
|
-
}> & {
|
|
831
|
-
createdAt: NativeDate;
|
|
832
|
-
updatedAt: NativeDate;
|
|
833
|
-
} & {
|
|
834
852
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
835
853
|
children: mongoose.Types.DocumentArray<{
|
|
836
854
|
entries?: {} | null | undefined;
|
|
@@ -1222,6 +1240,21 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1222
1240
|
id?: string | null | undefined;
|
|
1223
1241
|
name?: string | null | undefined;
|
|
1224
1242
|
}>;
|
|
1243
|
+
allowUpload: boolean;
|
|
1244
|
+
allowSharing: boolean;
|
|
1245
|
+
image?: string | null | undefined;
|
|
1246
|
+
description?: string | null | undefined;
|
|
1247
|
+
} & {
|
|
1248
|
+
_id: mongoose.Types.ObjectId;
|
|
1249
|
+
} & {
|
|
1250
|
+
__v: number;
|
|
1251
|
+
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
1252
|
+
timestamps: true;
|
|
1253
|
+
}, {
|
|
1254
|
+
createdAt: NativeDate;
|
|
1255
|
+
updatedAt: NativeDate;
|
|
1256
|
+
} & {
|
|
1257
|
+
dbType: string;
|
|
1225
1258
|
name: string;
|
|
1226
1259
|
members: mongoose.Types.DocumentArray<{
|
|
1227
1260
|
userId: mongoose.Types.ObjectId;
|
|
@@ -1237,20 +1270,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1237
1270
|
archived: boolean;
|
|
1238
1271
|
}>;
|
|
1239
1272
|
exports: mongoose.Types.ObjectId[];
|
|
1240
|
-
allowUpload: boolean;
|
|
1241
|
-
allowSharing: boolean;
|
|
1242
|
-
image?: string | null | undefined;
|
|
1243
|
-
description?: string | null | undefined;
|
|
1244
|
-
} & {
|
|
1245
|
-
_id: mongoose.Types.ObjectId;
|
|
1246
|
-
} & {
|
|
1247
|
-
__v: number;
|
|
1248
|
-
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
1249
|
-
timestamps: true;
|
|
1250
|
-
}, {
|
|
1251
|
-
createdAt: NativeDate;
|
|
1252
|
-
updatedAt: NativeDate;
|
|
1253
|
-
} & {
|
|
1254
1273
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
1255
1274
|
children: mongoose.Types.DocumentArray<{
|
|
1256
1275
|
entries?: {} | null | undefined;
|
|
@@ -1642,6 +1661,15 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1642
1661
|
id?: string | null | undefined;
|
|
1643
1662
|
name?: string | null | undefined;
|
|
1644
1663
|
}>;
|
|
1664
|
+
allowUpload: boolean;
|
|
1665
|
+
allowSharing: boolean;
|
|
1666
|
+
image?: string | null | undefined;
|
|
1667
|
+
description?: string | null | undefined;
|
|
1668
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
1669
|
+
createdAt: NativeDate;
|
|
1670
|
+
updatedAt: NativeDate;
|
|
1671
|
+
} & {
|
|
1672
|
+
dbType: string;
|
|
1645
1673
|
name: string;
|
|
1646
1674
|
members: mongoose.Types.DocumentArray<{
|
|
1647
1675
|
userId: mongoose.Types.ObjectId;
|
|
@@ -1657,14 +1685,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
1657
1685
|
archived: boolean;
|
|
1658
1686
|
}>;
|
|
1659
1687
|
exports: mongoose.Types.ObjectId[];
|
|
1660
|
-
allowUpload: boolean;
|
|
1661
|
-
allowSharing: boolean;
|
|
1662
|
-
image?: string | null | undefined;
|
|
1663
|
-
description?: string | null | undefined;
|
|
1664
|
-
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
1665
|
-
createdAt: NativeDate;
|
|
1666
|
-
updatedAt: NativeDate;
|
|
1667
|
-
} & {
|
|
1668
1688
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
1669
1689
|
children: mongoose.Types.DocumentArray<{
|
|
1670
1690
|
entries?: {} | null | undefined;
|
|
@@ -2056,6 +2076,15 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2056
2076
|
id?: string | null | undefined;
|
|
2057
2077
|
name?: string | null | undefined;
|
|
2058
2078
|
}>;
|
|
2079
|
+
allowUpload: boolean;
|
|
2080
|
+
allowSharing: boolean;
|
|
2081
|
+
image?: string | null | undefined;
|
|
2082
|
+
description?: string | null | undefined;
|
|
2083
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
2084
|
+
createdAt: NativeDate;
|
|
2085
|
+
updatedAt: NativeDate;
|
|
2086
|
+
} & {
|
|
2087
|
+
dbType: string;
|
|
2059
2088
|
name: string;
|
|
2060
2089
|
members: mongoose.Types.DocumentArray<{
|
|
2061
2090
|
userId: mongoose.Types.ObjectId;
|
|
@@ -2071,14 +2100,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2071
2100
|
archived: boolean;
|
|
2072
2101
|
}>;
|
|
2073
2102
|
exports: mongoose.Types.ObjectId[];
|
|
2074
|
-
allowUpload: boolean;
|
|
2075
|
-
allowSharing: boolean;
|
|
2076
|
-
image?: string | null | undefined;
|
|
2077
|
-
description?: string | null | undefined;
|
|
2078
|
-
}>> & mongoose.FlatRecord<{
|
|
2079
|
-
createdAt: NativeDate;
|
|
2080
|
-
updatedAt: NativeDate;
|
|
2081
|
-
} & {
|
|
2082
2103
|
rootFolders: mongoose.Types.DocumentArray<{
|
|
2083
2104
|
children: mongoose.Types.DocumentArray<{
|
|
2084
2105
|
entries?: {} | null | undefined;
|
|
@@ -2470,21 +2491,6 @@ export declare function initProjectModel(connection: mongoose.Connection): mongo
|
|
|
2470
2491
|
id?: string | null | undefined;
|
|
2471
2492
|
name?: string | null | undefined;
|
|
2472
2493
|
}>;
|
|
2473
|
-
name: string;
|
|
2474
|
-
members: mongoose.Types.DocumentArray<{
|
|
2475
|
-
userId: mongoose.Types.ObjectId;
|
|
2476
|
-
role: "viewer" | "editor" | "admin";
|
|
2477
|
-
archived: boolean;
|
|
2478
|
-
}, mongoose.Types.Subdocument<mongoose.Types.ObjectId, any, {
|
|
2479
|
-
userId: mongoose.Types.ObjectId;
|
|
2480
|
-
role: "viewer" | "editor" | "admin";
|
|
2481
|
-
archived: boolean;
|
|
2482
|
-
}> & {
|
|
2483
|
-
userId: mongoose.Types.ObjectId;
|
|
2484
|
-
role: "viewer" | "editor" | "admin";
|
|
2485
|
-
archived: boolean;
|
|
2486
|
-
}>;
|
|
2487
|
-
exports: mongoose.Types.ObjectId[];
|
|
2488
2494
|
allowUpload: boolean;
|
|
2489
2495
|
allowSharing: boolean;
|
|
2490
2496
|
image?: string | null | undefined;
|
|
@@ -17,6 +17,7 @@ function initProjectModel(connection) {
|
|
|
17
17
|
archived: { type: Boolean, default: false }
|
|
18
18
|
}, { _id: false });
|
|
19
19
|
const projectSchema = new mongoose_1.default.Schema({
|
|
20
|
+
dbType: { type: String, required: true },
|
|
20
21
|
name: { type: String, required: true },
|
|
21
22
|
description: { type: String },
|
|
22
23
|
image: { type: String },
|
|
@@ -11,7 +11,7 @@ export declare function initUserModel(connection: mongoose.Connection): mongoose
|
|
|
11
11
|
} & {
|
|
12
12
|
username: string;
|
|
13
13
|
email: string;
|
|
14
|
-
}> & {
|
|
14
|
+
}, {}> & {
|
|
15
15
|
createdAt: NativeDate;
|
|
16
16
|
updatedAt: NativeDate;
|
|
17
17
|
} & {
|
|
@@ -35,7 +35,7 @@ export declare function initUserModel(connection: mongoose.Connection): mongoose
|
|
|
35
35
|
} & {
|
|
36
36
|
username: string;
|
|
37
37
|
email: string;
|
|
38
|
-
}
|
|
38
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
39
39
|
createdAt: NativeDate;
|
|
40
40
|
updatedAt: NativeDate;
|
|
41
41
|
} & {
|
|
@@ -15,11 +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
|
-
|
|
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
|
+
}
|
|
23
39
|
router.get('/auth', async (req, res) => {
|
|
24
40
|
try {
|
|
25
41
|
const auth = await config.authProvider(req);
|
|
@@ -29,6 +45,25 @@ function createStreamByRouter(config) {
|
|
|
29
45
|
res.status(401).json({ logged: false });
|
|
30
46
|
}
|
|
31
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
|
+
});
|
|
32
67
|
router.get('/upload-project-image-url/:id', async (req, res) => {
|
|
33
68
|
try {
|
|
34
69
|
const auth = await config.authProvider(req);
|
|
@@ -57,7 +92,11 @@ function createStreamByRouter(config) {
|
|
|
57
92
|
return res.status(400).json({ error: 'Missing projectId' });
|
|
58
93
|
}
|
|
59
94
|
await (0, file_1.deleteProjectImage)(adapter, projectId);
|
|
60
|
-
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: '' });
|
|
61
100
|
res.status(201).json(updated);
|
|
62
101
|
}
|
|
63
102
|
catch (err) {
|
|
@@ -78,10 +117,58 @@ function createStreamByRouter(config) {
|
|
|
78
117
|
res.status(500).json({ error: 'Failed to list files', details: err });
|
|
79
118
|
}
|
|
80
119
|
});
|
|
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
|
+
}
|
|
131
|
+
}
|
|
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 */ }
|
|
140
|
+
}
|
|
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
|
+
}
|
|
81
159
|
router.get('/projects', async (req, res) => {
|
|
82
160
|
try {
|
|
83
161
|
const auth = await config.authProvider(req);
|
|
84
|
-
const projects =
|
|
162
|
+
const projects = [];
|
|
163
|
+
if (projectProviders.nosql) {
|
|
164
|
+
projects.push(...await projectProviders.nosql.list(auth.userId));
|
|
165
|
+
}
|
|
166
|
+
if (projectProviders.sql) {
|
|
167
|
+
projects.push(...await projectProviders.sql.list(auth.userId));
|
|
168
|
+
}
|
|
169
|
+
if (projectProviders.default) {
|
|
170
|
+
projects.push(...await projectProviders.default.list(auth.userId));
|
|
171
|
+
}
|
|
85
172
|
res.json({ projects });
|
|
86
173
|
}
|
|
87
174
|
catch (err) {
|
|
@@ -94,8 +181,13 @@ function createStreamByRouter(config) {
|
|
|
94
181
|
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
95
182
|
return res.status(403).json({ error: 'Permission denied' });
|
|
96
183
|
}
|
|
97
|
-
const { name, description } = req.body;
|
|
98
|
-
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',
|
|
99
191
|
name,
|
|
100
192
|
description: description || '',
|
|
101
193
|
members: [{ userId: auth.userId, role: "admin" }]
|
|
@@ -110,7 +202,12 @@ function createStreamByRouter(config) {
|
|
|
110
202
|
try {
|
|
111
203
|
const auth = await config.authProvider(req);
|
|
112
204
|
const projectId = req.params.id;
|
|
113
|
-
const
|
|
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);
|
|
114
211
|
if (!project) {
|
|
115
212
|
return res.status(404).json({ error: 'Project not found' });
|
|
116
213
|
}
|
|
@@ -131,7 +228,11 @@ function createStreamByRouter(config) {
|
|
|
131
228
|
}
|
|
132
229
|
const projectId = req.params.id;
|
|
133
230
|
const updates = req.body;
|
|
134
|
-
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);
|
|
135
236
|
if (!project) {
|
|
136
237
|
return res.status(404).json({ error: 'Project not found' });
|
|
137
238
|
}
|
|
@@ -152,7 +253,11 @@ function createStreamByRouter(config) {
|
|
|
152
253
|
try {
|
|
153
254
|
const auth = await config.authProvider(req);
|
|
154
255
|
const projectId = req.params.id;
|
|
155
|
-
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);
|
|
156
261
|
if (!project) {
|
|
157
262
|
return res.status(404).json({ error: 'Project not found' });
|
|
158
263
|
}
|
|
@@ -170,7 +275,11 @@ function createStreamByRouter(config) {
|
|
|
170
275
|
try {
|
|
171
276
|
const auth = await config.authProvider(req);
|
|
172
277
|
const projectId = req.params.id;
|
|
173
|
-
const
|
|
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);
|
|
174
283
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
175
284
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
176
285
|
}
|
|
@@ -185,7 +294,11 @@ function createStreamByRouter(config) {
|
|
|
185
294
|
try {
|
|
186
295
|
const auth = await config.authProvider(req);
|
|
187
296
|
const projectId = req.params.id;
|
|
188
|
-
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);
|
|
189
302
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
190
303
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
191
304
|
}
|
|
@@ -201,7 +314,11 @@ function createStreamByRouter(config) {
|
|
|
201
314
|
const auth = await config.authProvider(req);
|
|
202
315
|
const projectId = req.params.id;
|
|
203
316
|
const exportId = req.params.export_id;
|
|
204
|
-
const
|
|
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);
|
|
205
322
|
if (!project) {
|
|
206
323
|
return res.status(404).json({ error: 'Project not found' });
|
|
207
324
|
}
|
|
@@ -223,7 +340,11 @@ function createStreamByRouter(config) {
|
|
|
223
340
|
if (!name || !collectionName) {
|
|
224
341
|
return res.status(400).json({ error: 'Missing export name or collectionName' });
|
|
225
342
|
}
|
|
226
|
-
const
|
|
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);
|
|
227
348
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
228
349
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
229
350
|
}
|
|
@@ -244,6 +365,10 @@ function createStreamByRouter(config) {
|
|
|
244
365
|
try {
|
|
245
366
|
const auth = await config.authProvider(req);
|
|
246
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
|
+
}
|
|
247
372
|
const project = await projectProvider.getById(projectId, true);
|
|
248
373
|
if (!project) {
|
|
249
374
|
return res.status(404).json({ error: 'Project not found' });
|
|
@@ -13,7 +13,7 @@ export declare function initExportCollectionModel(connection: mongoose.Connectio
|
|
|
13
13
|
name: string;
|
|
14
14
|
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
15
15
|
projectId: mongoose.Types.ObjectId;
|
|
16
|
-
}> & {
|
|
16
|
+
}, {}> & {
|
|
17
17
|
createdAt: NativeDate;
|
|
18
18
|
updatedAt: NativeDate;
|
|
19
19
|
} & {
|
|
@@ -40,7 +40,7 @@ export declare function initExportCollectionModel(connection: mongoose.Connectio
|
|
|
40
40
|
name: string;
|
|
41
41
|
entries: mongoose.Types.DocumentArray<{}, mongoose.Types.Subdocument<unknown, any, {}>>;
|
|
42
42
|
projectId: mongoose.Types.ObjectId;
|
|
43
|
-
}
|
|
43
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
44
44
|
createdAt: NativeDate;
|
|
45
45
|
updatedAt: NativeDate;
|
|
46
46
|
} & {
|
|
@@ -1,13 +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
|
-
exportProvider: import("../types").ExportProvider;
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
72
|
};
|
|
13
|
-
export {};
|
|
@@ -10,22 +10,49 @@ const initUserModel_1 = require("../db/initUserModel");
|
|
|
10
10
|
const mongoExportProvider_1 = require("./mongoExportProvider");
|
|
11
11
|
const mongoProjectProvider_1 = require("./mongoProjectProvider");
|
|
12
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");
|
|
13
17
|
function createDatabaseProvider(databases, adapter) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
});
|
|
17
28
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
48
|
return {
|
|
27
|
-
exportProvider,
|
|
28
|
-
|
|
29
|
-
|
|
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,
|
|
30
57
|
};
|
|
31
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
|
+
}
|
|
@@ -15,6 +15,7 @@ function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
|
15
15
|
},
|
|
16
16
|
async create(data) {
|
|
17
17
|
const newProject = await ProjectModel.create({
|
|
18
|
+
dbType: data.dbType,
|
|
18
19
|
members: [
|
|
19
20
|
{
|
|
20
21
|
userId: data.members?.[0].userId,
|
|
@@ -25,7 +26,7 @@ function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
|
25
26
|
name: data.name,
|
|
26
27
|
description: data.description || '',
|
|
27
28
|
image: data.image || '',
|
|
28
|
-
rootFolders: data.
|
|
29
|
+
rootFolders: data.folders || [],
|
|
29
30
|
allowUpload: data.allowUpload ?? true,
|
|
30
31
|
allowSharing: data.allowSharing ?? false,
|
|
31
32
|
});
|
|
@@ -74,6 +75,7 @@ function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
|
74
75
|
function formatProject(doc) {
|
|
75
76
|
return {
|
|
76
77
|
id: doc._id.toString(),
|
|
78
|
+
dbType: doc.dbType,
|
|
77
79
|
name: doc.name,
|
|
78
80
|
image: doc.image,
|
|
79
81
|
members: doc.members.map((m) => ({
|
|
@@ -84,7 +86,7 @@ function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
|
84
86
|
archived: m.archived ?? false
|
|
85
87
|
})),
|
|
86
88
|
description: doc.description,
|
|
87
|
-
|
|
89
|
+
folders: doc.rootFolders || [],
|
|
88
90
|
settings: {
|
|
89
91
|
allowUpload: doc.allowUpload,
|
|
90
92
|
allowSharing: doc.allowSharing,
|
|
@@ -96,6 +98,7 @@ function createMongoProjectProvider(ProjectModel, ExportModel, adapter) {
|
|
|
96
98
|
const archived = doc.members?.find((m) => m.userId?.toString() === userId)?.archived ?? false;
|
|
97
99
|
return {
|
|
98
100
|
id: doc._id.toString(),
|
|
101
|
+
dbType: doc.dbType,
|
|
99
102
|
name: doc.name,
|
|
100
103
|
image: doc.image,
|
|
101
104
|
archived
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
export declare function createPrismaExportCollectionProvider(prisma: PrismaClient): {
|
|
3
|
+
getById(id: string): Promise<({
|
|
4
|
+
entries: {
|
|
5
|
+
id: string;
|
|
6
|
+
exportCollectionId: string;
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
} & {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
updatedAt: Date;
|
|
15
|
+
projectId: string;
|
|
16
|
+
}) | null>;
|
|
17
|
+
create(data: {
|
|
18
|
+
projectId: string;
|
|
19
|
+
name: string;
|
|
20
|
+
entries: Array<{
|
|
21
|
+
key: string;
|
|
22
|
+
value: string;
|
|
23
|
+
}>;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
entries: {
|
|
26
|
+
id: string;
|
|
27
|
+
exportCollectionId: string;
|
|
28
|
+
key: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
} & {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
36
|
+
projectId: string;
|
|
37
|
+
}>;
|
|
38
|
+
update(id: string, data: {
|
|
39
|
+
name?: string;
|
|
40
|
+
entries?: Array<{
|
|
41
|
+
key: string;
|
|
42
|
+
value: string;
|
|
43
|
+
}>;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
entries: {
|
|
46
|
+
id: string;
|
|
47
|
+
exportCollectionId: string;
|
|
48
|
+
key: string;
|
|
49
|
+
value: string;
|
|
50
|
+
}[];
|
|
51
|
+
} & {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
projectId: string;
|
|
57
|
+
}>;
|
|
58
|
+
delete(id: string): Promise<{
|
|
59
|
+
success: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrismaExportCollectionProvider = createPrismaExportCollectionProvider;
|
|
4
|
+
function createPrismaExportCollectionProvider(prisma) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(id) {
|
|
7
|
+
return prisma.exportCollection.findUnique({
|
|
8
|
+
where: { id },
|
|
9
|
+
include: { entries: true },
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
async create(data) {
|
|
13
|
+
const { entries, ...rest } = data;
|
|
14
|
+
return prisma.exportCollection.create({
|
|
15
|
+
data: {
|
|
16
|
+
...rest,
|
|
17
|
+
entries: {
|
|
18
|
+
createMany: { data: entries },
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
include: { entries: true },
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
async update(id, data) {
|
|
25
|
+
const { entries, ...rest } = data;
|
|
26
|
+
const updateData = { ...rest };
|
|
27
|
+
if (entries) {
|
|
28
|
+
// Eliminar entradas existentes y crear nuevas
|
|
29
|
+
await prisma.exportEntry.deleteMany({ where: { exportCollectionId: id } });
|
|
30
|
+
updateData.entries = {
|
|
31
|
+
createMany: { data: entries },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return prisma.exportCollection.update({
|
|
35
|
+
where: { id },
|
|
36
|
+
data: updateData,
|
|
37
|
+
include: { entries: true },
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
async delete(id) {
|
|
41
|
+
await prisma.exportCollection.delete({ where: { id } });
|
|
42
|
+
return { success: true };
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrismaExportProvider = createPrismaExportProvider;
|
|
4
|
+
function createPrismaExportProvider(prisma) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(exportId) {
|
|
7
|
+
return await prisma.export.findUnique({ where: { id: exportId } });
|
|
8
|
+
},
|
|
9
|
+
async create(data) {
|
|
10
|
+
return await prisma.export.create({ data });
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrismaProjectProvider = createPrismaProjectProvider;
|
|
4
|
+
function createPrismaProjectProvider(prisma, adapter) {
|
|
5
|
+
return {
|
|
6
|
+
async getById(projectId, populateMembers = false) {
|
|
7
|
+
const project = await prisma.project.findUnique({
|
|
8
|
+
where: { id: projectId },
|
|
9
|
+
include: {
|
|
10
|
+
exports: { select: { id: true, collectionName: true } },
|
|
11
|
+
members: populateMembers ? true : false,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
if (!project)
|
|
15
|
+
throw new Error('Project not found');
|
|
16
|
+
return formatProject(project);
|
|
17
|
+
},
|
|
18
|
+
async create(data) {
|
|
19
|
+
const newProject = await prisma.project.create({
|
|
20
|
+
data: {
|
|
21
|
+
dbType: data.dbType,
|
|
22
|
+
name: data.name,
|
|
23
|
+
description: data.description || '',
|
|
24
|
+
image: data.image || '',
|
|
25
|
+
allowUpload: data.allowUpload ?? true,
|
|
26
|
+
allowSharing: data.allowSharing ?? false,
|
|
27
|
+
members: {
|
|
28
|
+
create: data.members?.[0] ? {
|
|
29
|
+
userId: data.members[0].userId,
|
|
30
|
+
role: data.members[0].role,
|
|
31
|
+
archived: false,
|
|
32
|
+
} : undefined,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
include: {
|
|
36
|
+
exports: { select: { id: true, collectionName: true } },
|
|
37
|
+
members: true,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return formatProject(newProject);
|
|
41
|
+
},
|
|
42
|
+
async update(projectId, updates) {
|
|
43
|
+
const updated = await prisma.project.update({
|
|
44
|
+
where: { id: projectId },
|
|
45
|
+
data: {
|
|
46
|
+
name: updates.name,
|
|
47
|
+
description: updates.description,
|
|
48
|
+
image: updates.image,
|
|
49
|
+
allowUpload: updates.settings?.allowUpload,
|
|
50
|
+
allowSharing: updates.settings?.allowSharing,
|
|
51
|
+
},
|
|
52
|
+
include: {
|
|
53
|
+
exports: { select: { id: true, collectionName: true } },
|
|
54
|
+
members: true,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (!updated)
|
|
58
|
+
throw new Error('Project not found');
|
|
59
|
+
return formatProject(updated);
|
|
60
|
+
},
|
|
61
|
+
async list(userId) {
|
|
62
|
+
const all = await prisma.project.findMany({
|
|
63
|
+
where: userId ? { members: { some: { userId } } } : {},
|
|
64
|
+
include: {
|
|
65
|
+
members: true,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return all.map(doc => formatProjectList(doc, userId));
|
|
69
|
+
},
|
|
70
|
+
async delete(projectId) {
|
|
71
|
+
try {
|
|
72
|
+
await prisma.project.delete({ where: { id: projectId } });
|
|
73
|
+
await adapter.deleteProjectDirectory(projectId);
|
|
74
|
+
return { success: true };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new Error('Project not found');
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
async archive(projectId, userId) {
|
|
81
|
+
await prisma.member.updateMany({
|
|
82
|
+
where: { projectId, userId },
|
|
83
|
+
data: { archived: true },
|
|
84
|
+
});
|
|
85
|
+
return { success: true, projects: await this.list(userId) };
|
|
86
|
+
},
|
|
87
|
+
async unarchive(projectId, userId) {
|
|
88
|
+
await prisma.member.updateMany({
|
|
89
|
+
where: { projectId, userId },
|
|
90
|
+
data: { archived: false },
|
|
91
|
+
});
|
|
92
|
+
return { success: true, projects: await this.list(userId) };
|
|
93
|
+
},
|
|
94
|
+
async getExport(projectId, exportId) {
|
|
95
|
+
const exportDoc = await prisma.export.findFirst({
|
|
96
|
+
where: { id: exportId, projectId: projectId },
|
|
97
|
+
});
|
|
98
|
+
if (!exportDoc)
|
|
99
|
+
throw new Error('Export not found');
|
|
100
|
+
return exportDoc;
|
|
101
|
+
},
|
|
102
|
+
async addExportToProject(projectId, exportId) {
|
|
103
|
+
// En Prisma, la relación ya está definida en el modelo Export.
|
|
104
|
+
// No es necesario actualizar el Project directamente.
|
|
105
|
+
// Si se necesita vincular un Export existente a un Project, se haría al crear o actualizar el Export.
|
|
106
|
+
// Por ejemplo, al crear un Export:
|
|
107
|
+
// prisma.export.create({ data: { ..., projectId: projectId } });
|
|
108
|
+
// O al actualizar un Export:
|
|
109
|
+
// prisma.export.update({ where: { id: exportId }, data: { projectId: projectId } });
|
|
110
|
+
// Dado que el método original de Mongoose solo añade el ID, asumimos que el Export ya existe y tiene el projectId correcto.
|
|
111
|
+
// Si la lógica requiere añadir un Export existente a un Project, y el Export no tiene el projectId, se debería actualizar el Export.
|
|
112
|
+
// Por ahora, no se requiere ninguna acción aquí si la relación ya está establecida en el modelo Export.
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
function formatProject(doc) {
|
|
116
|
+
return {
|
|
117
|
+
id: doc.id,
|
|
118
|
+
dbType: doc.dbType,
|
|
119
|
+
name: doc.name,
|
|
120
|
+
image: doc.image,
|
|
121
|
+
members: doc.members?.map((m) => ({
|
|
122
|
+
userId: m.userId,
|
|
123
|
+
username: m.username, // Asumimos que el username y email se obtendrán de un servicio externo si es necesario
|
|
124
|
+
email: m.email,
|
|
125
|
+
role: m.role,
|
|
126
|
+
archived: m.archived ?? false
|
|
127
|
+
})) || [],
|
|
128
|
+
description: doc.description,
|
|
129
|
+
folders: doc.folders || [], // Prisma usa 'folders' en lugar de 'rootFolders'
|
|
130
|
+
settings: {
|
|
131
|
+
allowUpload: doc.allowUpload,
|
|
132
|
+
allowSharing: doc.allowSharing,
|
|
133
|
+
},
|
|
134
|
+
exports: doc.exports || []
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function formatProjectList(doc, userId) {
|
|
138
|
+
const archived = doc.members?.find((m) => m.userId === userId)?.archived ?? false;
|
|
139
|
+
return {
|
|
140
|
+
id: doc.id,
|
|
141
|
+
dbType: doc.dbType,
|
|
142
|
+
name: doc.name,
|
|
143
|
+
image: doc.image,
|
|
144
|
+
archived
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface StorageAdapter {
|
|
|
25
25
|
}
|
|
26
26
|
export interface ProjectInfo {
|
|
27
27
|
id: string;
|
|
28
|
+
dbType: DatabaseType;
|
|
28
29
|
name: string;
|
|
29
30
|
image?: string;
|
|
30
31
|
members?: {
|
|
@@ -33,9 +34,9 @@ export interface ProjectInfo {
|
|
|
33
34
|
archived?: boolean;
|
|
34
35
|
}[];
|
|
35
36
|
description?: string;
|
|
36
|
-
|
|
37
|
+
folders?: FolderNode[];
|
|
37
38
|
exports?: {
|
|
38
|
-
|
|
39
|
+
id: string;
|
|
39
40
|
collectionName: string;
|
|
40
41
|
}[];
|
|
41
42
|
settings?: {
|
|
@@ -45,6 +46,7 @@ export interface ProjectInfo {
|
|
|
45
46
|
}
|
|
46
47
|
export interface ProjectListInfo {
|
|
47
48
|
id: string;
|
|
49
|
+
dbType: DatabaseType;
|
|
48
50
|
name: string;
|
|
49
51
|
image?: string;
|
|
50
52
|
archived: boolean;
|
|
@@ -54,10 +56,10 @@ export interface FolderNode {
|
|
|
54
56
|
name: string;
|
|
55
57
|
children?: FolderNode[];
|
|
56
58
|
}
|
|
57
|
-
export type DatabaseType = '
|
|
59
|
+
export type DatabaseType = 'sql' | 'nosql';
|
|
58
60
|
export interface DatabaseCredential {
|
|
59
61
|
dbType: DatabaseType;
|
|
60
|
-
connectionString
|
|
62
|
+
connectionString?: string;
|
|
61
63
|
}
|
|
62
64
|
export interface StreamByConfig {
|
|
63
65
|
storageProviders: {
|
|
@@ -68,6 +70,7 @@ export interface StreamByConfig {
|
|
|
68
70
|
databases?: DatabaseCredential[];
|
|
69
71
|
exportProvider?: ExportProvider;
|
|
70
72
|
projectProvider?: ProjectProvider;
|
|
73
|
+
exportCollectionProvider?: ExportCollectionProvider;
|
|
71
74
|
adapter?: StorageAdapter;
|
|
72
75
|
}
|
|
73
76
|
export interface AuthContext {
|
|
@@ -85,7 +88,7 @@ export interface Export {
|
|
|
85
88
|
updatedAt: Date;
|
|
86
89
|
}
|
|
87
90
|
export interface ExportProvider {
|
|
88
|
-
getById(exportId: string): Promise<Export>;
|
|
91
|
+
getById(exportId: string): Promise<Export | null>;
|
|
89
92
|
create(data: {
|
|
90
93
|
name: string;
|
|
91
94
|
description?: string;
|
|
@@ -94,22 +97,23 @@ export interface ExportProvider {
|
|
|
94
97
|
}): Promise<Export>;
|
|
95
98
|
}
|
|
96
99
|
export interface ProjectProvider {
|
|
97
|
-
getExport(projectId: string,
|
|
100
|
+
getExport(projectId: string, exportId: string): Promise<any | null>;
|
|
98
101
|
archive(projectId: string, userId: string): Promise<{
|
|
99
102
|
success: boolean;
|
|
100
|
-
projects:
|
|
103
|
+
projects: ProjectListInfo[];
|
|
101
104
|
}>;
|
|
102
105
|
unarchive(projectId: string, userId: string): Promise<{
|
|
103
106
|
success: boolean;
|
|
104
|
-
projects:
|
|
107
|
+
projects: ProjectListInfo[];
|
|
105
108
|
}>;
|
|
106
|
-
list(userId?: string): Promise<
|
|
109
|
+
list(userId?: string): Promise<ProjectListInfo[]>;
|
|
107
110
|
getById(projectId: string, populateMembers?: boolean): Promise<ProjectInfo>;
|
|
108
111
|
delete(projectId: string): Promise<{
|
|
109
112
|
success: boolean;
|
|
110
113
|
}>;
|
|
111
|
-
update(projectId: string, updates: Partial<Omit<ProjectInfo, 'id' | '
|
|
114
|
+
update(projectId: string, updates: Partial<Omit<ProjectInfo, 'id' | 'folders'>>): Promise<ProjectInfo>;
|
|
112
115
|
create(data: {
|
|
116
|
+
dbType: DatabaseType;
|
|
113
117
|
name: string;
|
|
114
118
|
image?: string;
|
|
115
119
|
members?: {
|
|
@@ -119,7 +123,34 @@ export interface ProjectProvider {
|
|
|
119
123
|
description?: string;
|
|
120
124
|
allowUpload?: boolean;
|
|
121
125
|
allowSharing?: boolean;
|
|
122
|
-
|
|
126
|
+
folders?: FolderNode[];
|
|
123
127
|
}): Promise<ProjectInfo>;
|
|
124
128
|
addExportToProject(projectId: string, exportId: string): Promise<void>;
|
|
125
129
|
}
|
|
130
|
+
export interface ExportEntry {
|
|
131
|
+
id: string;
|
|
132
|
+
key: string;
|
|
133
|
+
value: string;
|
|
134
|
+
exportCollectionId: string;
|
|
135
|
+
}
|
|
136
|
+
export interface ExportCollectionProvider {
|
|
137
|
+
getById(id: string): Promise<any | null>;
|
|
138
|
+
create(data: {
|
|
139
|
+
projectId: string;
|
|
140
|
+
name: string;
|
|
141
|
+
entries: Array<{
|
|
142
|
+
key: string;
|
|
143
|
+
value: string;
|
|
144
|
+
}>;
|
|
145
|
+
}): Promise<any>;
|
|
146
|
+
update(id: string, data: {
|
|
147
|
+
name?: string;
|
|
148
|
+
entries?: Array<{
|
|
149
|
+
key: string;
|
|
150
|
+
value: string;
|
|
151
|
+
}>;
|
|
152
|
+
}): Promise<any>;
|
|
153
|
+
delete(id: string): Promise<{
|
|
154
|
+
success: boolean;
|
|
155
|
+
}>;
|
|
156
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamby-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "StreamBy middleware framework for media storage management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,10 +31,12 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@aws-sdk/client-s3": "^3.528.0",
|
|
33
33
|
"@aws-sdk/s3-request-presigner": "^3.787.0",
|
|
34
|
+
"@prisma/client": "^6.12.0",
|
|
34
35
|
"bcrypt": "^5.1.1",
|
|
35
36
|
"dotenv": "^16.5.0",
|
|
36
37
|
"express": "^4.0.0",
|
|
37
|
-
"mongoose": "^8.13.2"
|
|
38
|
+
"mongoose": "^8.13.2",
|
|
39
|
+
"prisma": "^6.12.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/bcrypt": "^5.0.2",
|