streamby-core 0.22.0 → 0.23.1
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.
|
@@ -5,7 +5,7 @@ export declare const createNoSQLExportCollection: (connection: MongoClient, proj
|
|
|
5
5
|
collectionName: string;
|
|
6
6
|
exportId: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare const createNoSQLRawExportCollection: (connection: MongoClient, projectId: string, exportName: string, jsonData: any) => Promise<{
|
|
8
|
+
export declare const createNoSQLRawExportCollection: (connection: MongoClient, projectId: string, exportName: string, jsonData: any, method: string) => Promise<{
|
|
9
9
|
collectionName: string;
|
|
10
10
|
exportId: string;
|
|
11
11
|
}>;
|
|
@@ -33,14 +33,14 @@ const createNoSQLExportCollection = async (connection, projectId, exportName, fi
|
|
|
33
33
|
return { collectionName, exportId: collectionName };
|
|
34
34
|
};
|
|
35
35
|
exports.createNoSQLExportCollection = createNoSQLExportCollection;
|
|
36
|
-
const createNoSQLRawExportCollection = async (connection, projectId, exportName, jsonData) => {
|
|
36
|
+
const createNoSQLRawExportCollection = async (connection, projectId, exportName, jsonData, method) => {
|
|
37
37
|
const db = connection.db();
|
|
38
38
|
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
39
39
|
const collectionName = `raw_export_${projectId}_${slug}`;
|
|
40
40
|
// Insert the raw JSON data directly into the new collection
|
|
41
|
-
await db.collection(collectionName).insertOne(jsonData);
|
|
41
|
+
const result = await db.collection(collectionName).insertOne({ json: jsonData, name: exportName, method, collectionName, createdAt: new Date(), updatedAt: new Date() });
|
|
42
42
|
console.log(`✅ Raw collection '${collectionName}' created with provided JSON data.`);
|
|
43
|
-
return { collectionName, exportId:
|
|
43
|
+
return { collectionName, exportId: result.insertedId.toHexString() };
|
|
44
44
|
};
|
|
45
45
|
exports.createNoSQLRawExportCollection = createNoSQLRawExportCollection;
|
|
46
46
|
exports.nosqlAdapter = {
|
|
@@ -5,6 +5,8 @@ const express_1 = require("express");
|
|
|
5
5
|
const manager_1 = require("../../models/manager");
|
|
6
6
|
const auth_1 = require("../../utils/auth");
|
|
7
7
|
const export_1 = require("../../services/export");
|
|
8
|
+
const connectionManager_1 = require("../../adapters/database/connectionManager");
|
|
9
|
+
const mongodb_1 = require("mongodb");
|
|
8
10
|
function exportRouter(config) {
|
|
9
11
|
const router = (0, express_1.Router)();
|
|
10
12
|
const Project = (0, manager_1.getModel)('projects');
|
|
@@ -25,9 +27,33 @@ function exportRouter(config) {
|
|
|
25
27
|
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
26
28
|
return res.status(403).json({ message: 'Unauthorized access' });
|
|
27
29
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const exportMetadata = project.exports.find((e) => e.id.toString() === exportId);
|
|
31
|
+
if (!exportMetadata) {
|
|
32
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
33
|
+
}
|
|
34
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
35
|
+
if (!targetDb) {
|
|
36
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
37
|
+
}
|
|
38
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
39
|
+
let data;
|
|
40
|
+
if (project.dbType === 'nosql') {
|
|
41
|
+
const db = connection.client.db();
|
|
42
|
+
if (exportMetadata.type === 'raw') {
|
|
43
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
44
|
+
data = rawData ? { json: rawData.json, name: rawData.name, method: rawData.method, collectionName: rawData.collectionName, createdAt: rawData.createdAt, updatedAt: rawData.updatedAt, type: exportMetadata.type } : null;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (project.dbType === 'sql') {
|
|
51
|
+
// ... SQL implementation needed
|
|
52
|
+
}
|
|
53
|
+
if (!data) {
|
|
54
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
55
|
+
}
|
|
56
|
+
res.json({ data, message: 'Export data fetched successfully' });
|
|
31
57
|
}
|
|
32
58
|
catch (err) {
|
|
33
59
|
res.status(500).json({ message: 'Failed to fetch export data', details: err.message });
|
|
@@ -81,5 +107,45 @@ function exportRouter(config) {
|
|
|
81
107
|
res.status(500).json({ message: 'Failed to create raw export', details: err.message });
|
|
82
108
|
}
|
|
83
109
|
});
|
|
110
|
+
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
|
111
|
+
try {
|
|
112
|
+
const { projectId, exportName } = req.params;
|
|
113
|
+
const project = await Project.findOne({ _id: projectId });
|
|
114
|
+
if (!project) {
|
|
115
|
+
return res.status(404).json({ message: 'Project not found' });
|
|
116
|
+
}
|
|
117
|
+
const exportMetadata = project.exports.find((e) => e.name === exportName);
|
|
118
|
+
if (!exportMetadata) {
|
|
119
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
120
|
+
}
|
|
121
|
+
const targetDb = config.databases?.find(db => db.type === project.dbType);
|
|
122
|
+
if (!targetDb) {
|
|
123
|
+
return res.status(500).json({ message: `Database connection not found for type ${project.dbType}` });
|
|
124
|
+
}
|
|
125
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
126
|
+
let data;
|
|
127
|
+
if (project.dbType === 'nosql') {
|
|
128
|
+
const db = connection.client.db();
|
|
129
|
+
if (exportMetadata.type === 'raw') {
|
|
130
|
+
const rawData = await db.collection(exportMetadata.collectionName).findOne({ _id: new mongodb_1.ObjectId(exportMetadata.id) });
|
|
131
|
+
data = rawData ? rawData.json : null;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
data = await db.collection(exportMetadata.collectionName).find({ __metadata: { $exists: false } }).toArray();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (project.dbType === 'sql') {
|
|
138
|
+
// SQL implementation for public exports will go here
|
|
139
|
+
return res.status(501).json({ message: 'SQL public exports not yet implemented' });
|
|
140
|
+
}
|
|
141
|
+
if (!data) {
|
|
142
|
+
return res.status(404).json({ message: 'Export data not found' });
|
|
143
|
+
}
|
|
144
|
+
res.json(data); // Return the raw data directly
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
res.status(500).json({ message: 'Failed to fetch public export data', details: err.message });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
84
150
|
return router;
|
|
85
151
|
}
|
|
@@ -146,14 +146,14 @@ function projectRouter(config) {
|
|
|
146
146
|
if (!(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
147
147
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
148
148
|
}
|
|
149
|
-
await Project.delete({ _id: projectId });
|
|
149
|
+
await Project.useDbType(project.dbType).delete({ _id: projectId });
|
|
150
150
|
const allProjects = await Project.find({});
|
|
151
151
|
const projects = allProjects
|
|
152
|
-
.filter(
|
|
153
|
-
const isMember =
|
|
152
|
+
.filter(p => {
|
|
153
|
+
const isMember = p.members?.some((m) => m.userId?.toString() === auth.userId?.toString());
|
|
154
154
|
return isMember; // Only include projects where the user is a member
|
|
155
155
|
})
|
|
156
|
-
.map(
|
|
156
|
+
.map(p => mapProjectToResponseFormat(p, auth.userId));
|
|
157
157
|
res.status(200).json({ success: true, projects: projects, message: 'Project deleted successfully' });
|
|
158
158
|
}
|
|
159
159
|
catch (err) {
|
package/dist/models/Model.js
CHANGED
|
@@ -34,11 +34,11 @@ class Model {
|
|
|
34
34
|
if (this.tableName === 'projects' && processedFilter.members && processedFilter.members.$elemMatch) {
|
|
35
35
|
// Handle members filter for SQL projects
|
|
36
36
|
const userId = processedFilter.members.$elemMatch.userId;
|
|
37
|
-
const query = `
|
|
38
|
-
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
-
FROM "projects" p
|
|
40
|
-
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
-
WHERE pm."userId" = $1
|
|
37
|
+
const query = `
|
|
38
|
+
SELECT p.*, pm."userId" as memberUserId, pm.archived as memberArchived
|
|
39
|
+
FROM "projects" p
|
|
40
|
+
JOIN "project_members" pm ON p.id = pm."projectId"
|
|
41
|
+
WHERE pm."userId" = $1
|
|
42
42
|
`;
|
|
43
43
|
const result = await connection.query(query, [userId]);
|
|
44
44
|
sqlResults = result.rows.map(row => ({
|
package/dist/services/export.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createExport = createExport;
|
|
4
4
|
exports.createRawExport = createRawExport;
|
|
5
5
|
const manager_1 = require("../models/manager");
|
|
6
|
+
const mongodb_1 = require("mongodb");
|
|
6
7
|
const connectionManager_1 = require("../adapters/database/connectionManager");
|
|
7
8
|
const nosql_1 = require("../adapters/database/nosql");
|
|
8
9
|
const sql_1 = require("../adapters/database/sql");
|
|
@@ -31,7 +32,7 @@ async function createExport(config, projectId, exportName, collectionName, field
|
|
|
31
32
|
// Update the project with the new export reference
|
|
32
33
|
// Assuming project metadata is always in NoSQL (MongoDB)
|
|
33
34
|
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
34
|
-
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: result.exportId, collectionName: result.collectionName, type: 'structured', fields } } });
|
|
35
|
+
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: result.exportId, collectionName: result.collectionName, type: 'structured', fields, method: 'GET' } } });
|
|
35
36
|
return { ...result, message: 'Export created successfully' };
|
|
36
37
|
}
|
|
37
38
|
async function createRawExport(config, projectId, exportName, collectionName, jsonData, dbType) {
|
|
@@ -43,7 +44,7 @@ async function createRawExport(config, projectId, exportName, collectionName, js
|
|
|
43
44
|
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
44
45
|
let result;
|
|
45
46
|
if (dbType === 'nosql') {
|
|
46
|
-
result = await (0, nosql_1.createNoSQLRawExportCollection)(connection.client, projectId, exportName, jsonData);
|
|
47
|
+
result = await (0, nosql_1.createNoSQLRawExportCollection)(connection.client, projectId, exportName, jsonData, 'GET');
|
|
47
48
|
}
|
|
48
49
|
else if (dbType === 'sql') {
|
|
49
50
|
result = await (0, sql_1.createSQLRawExportTable)(connection.client, projectId, exportName, jsonData);
|
|
@@ -54,6 +55,6 @@ async function createRawExport(config, projectId, exportName, collectionName, js
|
|
|
54
55
|
// Update the project with the new export reference
|
|
55
56
|
// Assuming project metadata is always in NoSQL (MongoDB)
|
|
56
57
|
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
57
|
-
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: result.exportId, collectionName: result.collectionName, type: 'raw',
|
|
58
|
+
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: dbType === 'nosql' ? new mongodb_1.ObjectId(result.exportId) : result.exportId, name: exportName, collectionName: result.collectionName, type: 'raw', method: 'GET' } } });
|
|
58
59
|
return { ...result, message: 'Raw export created successfully' };
|
|
59
60
|
}
|