streamby-core 0.14.0 → 0.16.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 +134 -16
- package/dist/models/ExportCollection.d.ts +2 -2
- package/dist/mongoose_models/initExportModel.d.ts +61 -0
- package/dist/mongoose_models/initExportModel.js +19 -0
- package/dist/mongoose_models/initProjectModel.d.ts +2503 -0
- package/dist/mongoose_models/initProjectModel.js +34 -0
- package/dist/providers/createDatabaseProvider.d.ts +2 -13
- package/dist/providers/createDatabaseProvider.js +28 -23
- package/dist/providers/createMongooseProvider.d.ts +8 -0
- package/dist/providers/createMongooseProvider.js +33 -0
- package/dist/providers/createPrismaProvider.d.ts +14 -0
- package/dist/providers/createPrismaProvider.js +29 -0
- package/dist/providers/mongoProjectProvider.js +5 -2
- package/dist/providers/mongooseExportProvider.d.ts +3 -0
- package/dist/providers/mongooseExportProvider.js +13 -0
- package/dist/providers/mongooseProjectProvider.d.ts +3 -0
- package/dist/providers/mongooseProjectProvider.js +114 -0
- 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 +54 -12
- package/package.json +4 -2
package/dist/config.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const config: {
|
|
2
|
+
s3: {
|
|
3
|
+
accessKeyId: string;
|
|
4
|
+
secretAccessKey: string;
|
|
5
|
+
region: string;
|
|
6
|
+
bucketName: string;
|
|
7
|
+
};
|
|
8
|
+
gcs: {
|
|
9
|
+
projectId: string;
|
|
10
|
+
keyFilename: string;
|
|
11
|
+
bucketName: string;
|
|
12
|
+
};
|
|
13
|
+
local: {
|
|
14
|
+
storagePath: string;
|
|
15
|
+
};
|
|
16
|
+
mongooseString: string;
|
|
17
|
+
prismaString: 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
|
+
s3: {
|
|
11
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || '',
|
|
12
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || '',
|
|
13
|
+
region: process.env.AWS_REGION || 'us-east-1',
|
|
14
|
+
bucketName: process.env.AWS_BUCKET_NAME || 'streamby-dev',
|
|
15
|
+
},
|
|
16
|
+
gcs: {
|
|
17
|
+
projectId: process.env.GCS_PROJECT_ID || '',
|
|
18
|
+
keyFilename: process.env.GCS_KEY_FILENAME || '',
|
|
19
|
+
bucketName: process.env.GCS_BUCKET_NAME || 'streamby-dev',
|
|
20
|
+
},
|
|
21
|
+
local: {
|
|
22
|
+
storagePath: process.env.LOCAL_STORAGE_PATH || './uploads',
|
|
23
|
+
},
|
|
24
|
+
mongooseString: process.env.MONGOOSE_STRING || '',
|
|
25
|
+
prismaString: process.env.PRISMA_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,51 @@ 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
|
+
return null; // If dbType was provided and no project found in that specific provider, return null.
|
|
132
|
+
}
|
|
133
|
+
// If dbType is not provided, search both nosql and sql
|
|
134
|
+
if (projectProviders.nosql) {
|
|
135
|
+
try {
|
|
136
|
+
const project = await projectProviders.nosql.getById(projectId, true);
|
|
137
|
+
if (project)
|
|
138
|
+
return projectProviders.nosql;
|
|
139
|
+
}
|
|
140
|
+
catch (error) { /* ignore */ }
|
|
141
|
+
}
|
|
142
|
+
if (projectProviders.sql) {
|
|
143
|
+
try {
|
|
144
|
+
const project = await projectProviders.sql.getById(projectId, true);
|
|
145
|
+
if (project)
|
|
146
|
+
return projectProviders.sql;
|
|
147
|
+
}
|
|
148
|
+
catch (error) { /* ignore */ }
|
|
149
|
+
}
|
|
150
|
+
return null; // If not found in either nosql or sql, return null.
|
|
151
|
+
}
|
|
81
152
|
router.get('/projects', async (req, res) => {
|
|
82
153
|
try {
|
|
83
154
|
const auth = await config.authProvider(req);
|
|
84
|
-
const projects =
|
|
155
|
+
const projects = [];
|
|
156
|
+
if (projectProviders.nosql) {
|
|
157
|
+
projects.push(...await projectProviders.nosql.list(auth.userId));
|
|
158
|
+
}
|
|
159
|
+
if (projectProviders.sql) {
|
|
160
|
+
projects.push(...await projectProviders.sql.list(auth.userId));
|
|
161
|
+
}
|
|
162
|
+
if (projectProviders.default) {
|
|
163
|
+
projects.push(...await projectProviders.default.list(auth.userId));
|
|
164
|
+
}
|
|
85
165
|
res.json({ projects });
|
|
86
166
|
}
|
|
87
167
|
catch (err) {
|
|
@@ -94,8 +174,13 @@ function createStreamByRouter(config) {
|
|
|
94
174
|
if (auth.role !== 'admin' && auth.role !== 'editor') {
|
|
95
175
|
return res.status(403).json({ error: 'Permission denied' });
|
|
96
176
|
}
|
|
97
|
-
const { name, description } = req.body;
|
|
98
|
-
const
|
|
177
|
+
const { name, description, dbType } = req.body;
|
|
178
|
+
const provider = dbType ? projectProviders[dbType] : projectProviders.default || projectProviders.nosql || projectProviders.sql;
|
|
179
|
+
if (!provider) {
|
|
180
|
+
return res.status(400).json({ error: 'Invalid dbType' });
|
|
181
|
+
}
|
|
182
|
+
const newProject = await provider.create({
|
|
183
|
+
dbType: dbType || 'nosql',
|
|
99
184
|
name,
|
|
100
185
|
description: description || '',
|
|
101
186
|
members: [{ userId: auth.userId, role: "admin" }]
|
|
@@ -110,7 +195,12 @@ function createStreamByRouter(config) {
|
|
|
110
195
|
try {
|
|
111
196
|
const auth = await config.authProvider(req);
|
|
112
197
|
const projectId = req.params.id;
|
|
113
|
-
const
|
|
198
|
+
const dbType = req.query.dbType;
|
|
199
|
+
const projectProvider = await getProjectProvider(projectId, dbType);
|
|
200
|
+
if (!projectProvider) {
|
|
201
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
202
|
+
}
|
|
203
|
+
const project = await projectProvider.getById(projectId, true);
|
|
114
204
|
if (!project) {
|
|
115
205
|
return res.status(404).json({ error: 'Project not found' });
|
|
116
206
|
}
|
|
@@ -131,7 +221,11 @@ function createStreamByRouter(config) {
|
|
|
131
221
|
}
|
|
132
222
|
const projectId = req.params.id;
|
|
133
223
|
const updates = req.body;
|
|
134
|
-
const
|
|
224
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
225
|
+
if (!projectProvider) {
|
|
226
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
227
|
+
}
|
|
228
|
+
const project = await projectProvider.getById(projectId, true);
|
|
135
229
|
if (!project) {
|
|
136
230
|
return res.status(404).json({ error: 'Project not found' });
|
|
137
231
|
}
|
|
@@ -152,7 +246,11 @@ function createStreamByRouter(config) {
|
|
|
152
246
|
try {
|
|
153
247
|
const auth = await config.authProvider(req);
|
|
154
248
|
const projectId = req.params.id;
|
|
155
|
-
const
|
|
249
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
250
|
+
if (!projectProvider) {
|
|
251
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
252
|
+
}
|
|
253
|
+
const project = await projectProvider.getById(projectId, true);
|
|
156
254
|
if (!project) {
|
|
157
255
|
return res.status(404).json({ error: 'Project not found' });
|
|
158
256
|
}
|
|
@@ -170,7 +268,11 @@ function createStreamByRouter(config) {
|
|
|
170
268
|
try {
|
|
171
269
|
const auth = await config.authProvider(req);
|
|
172
270
|
const projectId = req.params.id;
|
|
173
|
-
const
|
|
271
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
272
|
+
if (!projectProvider) {
|
|
273
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
274
|
+
}
|
|
275
|
+
const project = await projectProvider.getById(projectId, true);
|
|
174
276
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
175
277
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
176
278
|
}
|
|
@@ -185,7 +287,11 @@ function createStreamByRouter(config) {
|
|
|
185
287
|
try {
|
|
186
288
|
const auth = await config.authProvider(req);
|
|
187
289
|
const projectId = req.params.id;
|
|
188
|
-
const
|
|
290
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
291
|
+
if (!projectProvider) {
|
|
292
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
293
|
+
}
|
|
294
|
+
const project = await projectProvider.getById(projectId, true);
|
|
189
295
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
190
296
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
191
297
|
}
|
|
@@ -201,7 +307,11 @@ function createStreamByRouter(config) {
|
|
|
201
307
|
const auth = await config.authProvider(req);
|
|
202
308
|
const projectId = req.params.id;
|
|
203
309
|
const exportId = req.params.export_id;
|
|
204
|
-
const
|
|
310
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
311
|
+
if (!projectProvider) {
|
|
312
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
313
|
+
}
|
|
314
|
+
const project = await projectProvider.getById(projectId, true);
|
|
205
315
|
if (!project) {
|
|
206
316
|
return res.status(404).json({ error: 'Project not found' });
|
|
207
317
|
}
|
|
@@ -223,7 +333,11 @@ function createStreamByRouter(config) {
|
|
|
223
333
|
if (!name || !collectionName) {
|
|
224
334
|
return res.status(400).json({ error: 'Missing export name or collectionName' });
|
|
225
335
|
}
|
|
226
|
-
const
|
|
336
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
337
|
+
if (!projectProvider) {
|
|
338
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
339
|
+
}
|
|
340
|
+
const project = await projectProvider.getById(projectId, true);
|
|
227
341
|
if (!project || !isProjectMember(project, auth.userId)) {
|
|
228
342
|
return res.status(403).json({ error: 'Unauthorized project access' });
|
|
229
343
|
}
|
|
@@ -244,6 +358,10 @@ function createStreamByRouter(config) {
|
|
|
244
358
|
try {
|
|
245
359
|
const auth = await config.authProvider(req);
|
|
246
360
|
const projectId = req.params.id;
|
|
361
|
+
const projectProvider = await getProjectProvider(projectId);
|
|
362
|
+
if (!projectProvider) {
|
|
363
|
+
return res.status(404).json({ error: 'Project not found' });
|
|
364
|
+
}
|
|
247
365
|
const project = await projectProvider.getById(projectId, true);
|
|
248
366
|
if (!project) {
|
|
249
367
|
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
|
} & {
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
collection: string;
|
|
33
|
+
}, {
|
|
34
|
+
createdAt: NativeDate;
|
|
35
|
+
updatedAt: NativeDate;
|
|
36
|
+
} & {
|
|
37
|
+
name: string;
|
|
38
|
+
collectionName: string;
|
|
39
|
+
projectId: mongoose.Types.ObjectId;
|
|
40
|
+
description?: string | null | undefined;
|
|
41
|
+
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
42
|
+
createdAt: NativeDate;
|
|
43
|
+
updatedAt: NativeDate;
|
|
44
|
+
} & {
|
|
45
|
+
name: string;
|
|
46
|
+
collectionName: string;
|
|
47
|
+
projectId: mongoose.Types.ObjectId;
|
|
48
|
+
description?: string | null | undefined;
|
|
49
|
+
}>, {}> & mongoose.FlatRecord<{
|
|
50
|
+
createdAt: NativeDate;
|
|
51
|
+
updatedAt: NativeDate;
|
|
52
|
+
} & {
|
|
53
|
+
name: string;
|
|
54
|
+
collectionName: string;
|
|
55
|
+
projectId: mongoose.Types.ObjectId;
|
|
56
|
+
description?: string | null | undefined;
|
|
57
|
+
}> & {
|
|
58
|
+
_id: mongoose.Types.ObjectId;
|
|
59
|
+
} & {
|
|
60
|
+
__v: number;
|
|
61
|
+
}>>;
|
|
@@ -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.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
|
+
collection: 'streamby_exports'
|
|
17
|
+
});
|
|
18
|
+
return connection.model('Export', exportSchema);
|
|
19
|
+
}
|