streamby-core 0.23.3 β 0.23.5
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/README.md +206 -206
- package/dist/middleware/routes/export.js +21 -23
- package/dist/models/Model.js +5 -5
- package/dist/services/export.d.ts +6 -4
- package/dist/services/export.js +22 -32
- package/package.json +60 -60
package/README.md
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
# @streamby/core
|
|
2
|
-
|
|
3
|
-
Middleware framework for building storage-agnostic media APIs.
|
|
4
|
-
Part of the [StreamBy](https://streamby.nhexa.cl) ecosystem by TerminalCore Labs.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## π What is it?
|
|
9
|
-
|
|
10
|
-
`@streamby/core` is a plug-and-play middleware for Express (or compatible frameworks) that enables file uploads, listings and **multi-project access** over services like:
|
|
11
|
-
|
|
12
|
-
- β
AWS S3
|
|
13
|
-
- β
Google Cloud Storage (soon)
|
|
14
|
-
- β
Cloudflare R2 (soon)
|
|
15
|
-
- β
Local/Personal servers (soon)
|
|
16
|
-
|
|
17
|
-
It's designed to be installed inside your existing API as a library β **no need to run a separate backend**.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## π¦ Installation
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install @streamby/core
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## π§± Basic usage
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import express from 'express';
|
|
33
|
-
import { createStreamByRouter } from '@streamby/core';
|
|
34
|
-
|
|
35
|
-
const app = express();
|
|
36
|
-
|
|
37
|
-
app.use('/streamby', createStreamByRouter({
|
|
38
|
-
storageProvider: {
|
|
39
|
-
type: 's3',
|
|
40
|
-
config: {
|
|
41
|
-
bucket: 'your-bucket-name',
|
|
42
|
-
region: 'your-region',
|
|
43
|
-
accessKeyId: 'YOUR_AWS_KEY',
|
|
44
|
-
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
authProvider: async (req) => {
|
|
48
|
-
// extract token/cookie and validate
|
|
49
|
-
return {
|
|
50
|
-
userId: 'demo',
|
|
51
|
-
projects: ['demo-project'],
|
|
52
|
-
role: 'admin',
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
projectProvider: async (projectId) => {
|
|
56
|
-
// fetch project from your DB
|
|
57
|
-
return {
|
|
58
|
-
id: projectId,
|
|
59
|
-
name: 'Demo Project',
|
|
60
|
-
description: 'Demo for StreamBy integration',
|
|
61
|
-
rootFolders: [],
|
|
62
|
-
settings: { allowUpload: true }
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
app.listen(3000);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## π§ͺ Testing
|
|
73
|
-
|
|
74
|
-
```bash
|
|
75
|
-
npm run test
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## π Features
|
|
83
|
-
|
|
84
|
-
- π Multi-project access control
|
|
85
|
-
- π Project-aware file uploads & listings
|
|
86
|
-
- π§Ή Modular adapters per storage provider
|
|
87
|
-
- π§° Built-in testability with mock auth & storage
|
|
88
|
-
- β¨ Simple to extend for custom business logic
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## πΊοΈ API Endpoints
|
|
93
|
-
|
|
94
|
-
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
95
|
-
|
|
96
|
-
### `GET /streamby/projects`
|
|
97
|
-
|
|
98
|
-
Lists all projects accessible by the authenticated user.
|
|
99
|
-
|
|
100
|
-
**Query Parameters:**
|
|
101
|
-
- `archived`: (Optional) Filter projects by their archived status.
|
|
102
|
-
- `true`: Returns only archived projects.
|
|
103
|
-
- `false`: Returns only unarchived projects.
|
|
104
|
-
- (Omitted): Returns all projects (both archived and unarchived).
|
|
105
|
-
|
|
106
|
-
**Example Response:**
|
|
107
|
-
```json
|
|
108
|
-
{
|
|
109
|
-
"projects": [
|
|
110
|
-
{
|
|
111
|
-
"id": "project1_id",
|
|
112
|
-
"dbType": "nosql",
|
|
113
|
-
"name": "My NoSQL Project",
|
|
114
|
-
"image": "url_to_image",
|
|
115
|
-
"archived": false
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"id": "project2_id",
|
|
119
|
-
"dbType": "sql",
|
|
120
|
-
"name": "My SQL Project",
|
|
121
|
-
"image": "url_to_image",
|
|
122
|
-
"archived": true
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### `PATCH /streamby/projects/:id/archive`
|
|
129
|
-
|
|
130
|
-
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
131
|
-
|
|
132
|
-
**Example Response:**
|
|
133
|
-
```json
|
|
134
|
-
{
|
|
135
|
-
"success": true,
|
|
136
|
-
"projects": [
|
|
137
|
-
{
|
|
138
|
-
"id": "project1_id",
|
|
139
|
-
"dbType": "nosql",
|
|
140
|
-
"name": "My NoSQL Project",
|
|
141
|
-
"image": "url_to_image",
|
|
142
|
-
"archived": true
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
"id": "project2_id",
|
|
146
|
-
"dbType": "sql",
|
|
147
|
-
"name": "My SQL Project",
|
|
148
|
-
"image": "url_to_image",
|
|
149
|
-
"archived": false
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### `PATCH /streamby/projects/:id/unarchive`
|
|
156
|
-
|
|
157
|
-
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
158
|
-
|
|
159
|
-
**Example Response:**
|
|
160
|
-
```json
|
|
161
|
-
{
|
|
162
|
-
"success": true,
|
|
163
|
-
"projects": [
|
|
164
|
-
{
|
|
165
|
-
"id": "project1_id",
|
|
166
|
-
"dbType": "nosql",
|
|
167
|
-
"name": "My NoSQL Project",
|
|
168
|
-
"image": "url_to_image",
|
|
169
|
-
"archived": false
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
"id": "project2_id",
|
|
173
|
-
"dbType": "sql",
|
|
174
|
-
"name": "My SQL Project",
|
|
175
|
-
"image": "url_to_image",
|
|
176
|
-
"archived": false
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## π£ Roadmap
|
|
185
|
-
|
|
186
|
-
- [ ] Support for Google Cloud Storage
|
|
187
|
-
- [ ] CLI tool for uploading files
|
|
188
|
-
- [ ] Role-based access control middleware
|
|
189
|
-
- [ ] Plugin system for extended routes
|
|
190
|
-
- [ ] Streaming support (HLS, audio, etc.)
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## π§βπ» Maintained by
|
|
195
|
-
|
|
196
|
-
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
197
|
-
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
198
|
-
|
|
199
|
-
Visit us [here](https://terminalcore.cl)
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
## π License
|
|
204
|
-
|
|
205
|
-
[MIT](./LICENSE)
|
|
206
|
-
|
|
1
|
+
# @streamby/core
|
|
2
|
+
|
|
3
|
+
Middleware framework for building storage-agnostic media APIs.
|
|
4
|
+
Part of the [StreamBy](https://streamby.nhexa.cl) ecosystem by TerminalCore Labs.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## π What is it?
|
|
9
|
+
|
|
10
|
+
`@streamby/core` is a plug-and-play middleware for Express (or compatible frameworks) that enables file uploads, listings and **multi-project access** over services like:
|
|
11
|
+
|
|
12
|
+
- β
AWS S3
|
|
13
|
+
- β
Google Cloud Storage (soon)
|
|
14
|
+
- β
Cloudflare R2 (soon)
|
|
15
|
+
- β
Local/Personal servers (soon)
|
|
16
|
+
|
|
17
|
+
It's designed to be installed inside your existing API as a library β **no need to run a separate backend**.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## π¦ Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @streamby/core
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## π§± Basic usage
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import express from 'express';
|
|
33
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
34
|
+
|
|
35
|
+
const app = express();
|
|
36
|
+
|
|
37
|
+
app.use('/streamby', createStreamByRouter({
|
|
38
|
+
storageProvider: {
|
|
39
|
+
type: 's3',
|
|
40
|
+
config: {
|
|
41
|
+
bucket: 'your-bucket-name',
|
|
42
|
+
region: 'your-region',
|
|
43
|
+
accessKeyId: 'YOUR_AWS_KEY',
|
|
44
|
+
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
authProvider: async (req) => {
|
|
48
|
+
// extract token/cookie and validate
|
|
49
|
+
return {
|
|
50
|
+
userId: 'demo',
|
|
51
|
+
projects: ['demo-project'],
|
|
52
|
+
role: 'admin',
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
projectProvider: async (projectId) => {
|
|
56
|
+
// fetch project from your DB
|
|
57
|
+
return {
|
|
58
|
+
id: projectId,
|
|
59
|
+
name: 'Demo Project',
|
|
60
|
+
description: 'Demo for StreamBy integration',
|
|
61
|
+
rootFolders: [],
|
|
62
|
+
settings: { allowUpload: true }
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
app.listen(3000);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## π§ͺ Testing
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm run test
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## π Features
|
|
83
|
+
|
|
84
|
+
- π Multi-project access control
|
|
85
|
+
- π Project-aware file uploads & listings
|
|
86
|
+
- π§Ή Modular adapters per storage provider
|
|
87
|
+
- π§° Built-in testability with mock auth & storage
|
|
88
|
+
- β¨ Simple to extend for custom business logic
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## πΊοΈ API Endpoints
|
|
93
|
+
|
|
94
|
+
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
95
|
+
|
|
96
|
+
### `GET /streamby/projects`
|
|
97
|
+
|
|
98
|
+
Lists all projects accessible by the authenticated user.
|
|
99
|
+
|
|
100
|
+
**Query Parameters:**
|
|
101
|
+
- `archived`: (Optional) Filter projects by their archived status.
|
|
102
|
+
- `true`: Returns only archived projects.
|
|
103
|
+
- `false`: Returns only unarchived projects.
|
|
104
|
+
- (Omitted): Returns all projects (both archived and unarchived).
|
|
105
|
+
|
|
106
|
+
**Example Response:**
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"projects": [
|
|
110
|
+
{
|
|
111
|
+
"id": "project1_id",
|
|
112
|
+
"dbType": "nosql",
|
|
113
|
+
"name": "My NoSQL Project",
|
|
114
|
+
"image": "url_to_image",
|
|
115
|
+
"archived": false
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "project2_id",
|
|
119
|
+
"dbType": "sql",
|
|
120
|
+
"name": "My SQL Project",
|
|
121
|
+
"image": "url_to_image",
|
|
122
|
+
"archived": true
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### `PATCH /streamby/projects/:id/archive`
|
|
129
|
+
|
|
130
|
+
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
131
|
+
|
|
132
|
+
**Example Response:**
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"success": true,
|
|
136
|
+
"projects": [
|
|
137
|
+
{
|
|
138
|
+
"id": "project1_id",
|
|
139
|
+
"dbType": "nosql",
|
|
140
|
+
"name": "My NoSQL Project",
|
|
141
|
+
"image": "url_to_image",
|
|
142
|
+
"archived": true
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "project2_id",
|
|
146
|
+
"dbType": "sql",
|
|
147
|
+
"name": "My SQL Project",
|
|
148
|
+
"image": "url_to_image",
|
|
149
|
+
"archived": false
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `PATCH /streamby/projects/:id/unarchive`
|
|
156
|
+
|
|
157
|
+
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
158
|
+
|
|
159
|
+
**Example Response:**
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"success": true,
|
|
163
|
+
"projects": [
|
|
164
|
+
{
|
|
165
|
+
"id": "project1_id",
|
|
166
|
+
"dbType": "nosql",
|
|
167
|
+
"name": "My NoSQL Project",
|
|
168
|
+
"image": "url_to_image",
|
|
169
|
+
"archived": false
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"id": "project2_id",
|
|
173
|
+
"dbType": "sql",
|
|
174
|
+
"name": "My SQL Project",
|
|
175
|
+
"image": "url_to_image",
|
|
176
|
+
"archived": false
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## π£ Roadmap
|
|
185
|
+
|
|
186
|
+
- [ ] Support for Google Cloud Storage
|
|
187
|
+
- [ ] CLI tool for uploading files
|
|
188
|
+
- [ ] Role-based access control middleware
|
|
189
|
+
- [ ] Plugin system for extended routes
|
|
190
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## π§βπ» Maintained by
|
|
195
|
+
|
|
196
|
+
**TerminalCore Labs** β part of [Nhexa Entertainment](https://nhexa.cl)
|
|
197
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
198
|
+
|
|
199
|
+
Visit us [here](https://terminalcore.cl)
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## π License
|
|
204
|
+
|
|
205
|
+
[MIT](./LICENSE)
|
|
206
|
+
|
|
@@ -68,65 +68,63 @@ function exportRouter(config) {
|
|
|
68
68
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
69
69
|
}
|
|
70
70
|
const projectId = req.params.id;
|
|
71
|
-
const { name, description, collectionName,
|
|
72
|
-
if (!name || !collectionName || !
|
|
73
|
-
return res.status(400).json({ message: 'Missing export name, collectionName, or
|
|
71
|
+
const { name, description, collectionName, jsonData } = req.body;
|
|
72
|
+
if (!name || !collectionName || !jsonData) {
|
|
73
|
+
return res.status(400).json({ message: 'Missing export name, collectionName, or jsonData' });
|
|
74
74
|
}
|
|
75
75
|
const project = await Project.findOne({ _id: projectId });
|
|
76
76
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
77
77
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
78
78
|
}
|
|
79
|
-
const result = await (0, export_1.createExport)(config, projectId, name, collectionName,
|
|
79
|
+
const result = await (0, export_1.createExport)(config, projectId, name, collectionName, jsonData, project.dbType);
|
|
80
80
|
res.status(201).json({ data: result, message: result.message });
|
|
81
81
|
}
|
|
82
82
|
catch (err) {
|
|
83
|
-
res.status(500).json({ message: 'Failed to create export', details: err.message });
|
|
83
|
+
res.status(500).json({ message: 'Failed to create raw export', details: err.message });
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
|
-
router.
|
|
86
|
+
router.patch('/projects/:id/exports/:export_id', async (req, res) => {
|
|
87
87
|
try {
|
|
88
88
|
const auth = await config.authProvider(req);
|
|
89
|
-
if (!auth ||
|
|
90
|
-
!auth.userId ||
|
|
91
|
-
!auth.role) {
|
|
89
|
+
if (!auth || !auth.userId) {
|
|
92
90
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
93
91
|
}
|
|
94
|
-
const projectId = req.params
|
|
95
|
-
const { name,
|
|
92
|
+
const { id: projectId, export_id: exportId } = req.params;
|
|
93
|
+
const { name, collectionName, description, jsonData } = req.body;
|
|
96
94
|
if (!name || !collectionName || !jsonData) {
|
|
97
|
-
return res.status(400).json({ message: 'Missing
|
|
95
|
+
return res.status(400).json({ message: 'Missing name, collectionName, or jsonData' });
|
|
98
96
|
}
|
|
99
97
|
const project = await Project.findOne({ _id: projectId });
|
|
100
98
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
101
99
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
102
100
|
}
|
|
103
|
-
const result = await (0, export_1.
|
|
104
|
-
res.status(
|
|
101
|
+
const result = await (0, export_1.updateExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType);
|
|
102
|
+
res.status(200).json({ data: result, message: result.message });
|
|
105
103
|
}
|
|
106
104
|
catch (err) {
|
|
107
|
-
res.status(500).json({ message: 'Failed to
|
|
105
|
+
res.status(500).json({ message: 'Failed to update raw export', details: err.message });
|
|
108
106
|
}
|
|
109
107
|
});
|
|
110
|
-
router.
|
|
108
|
+
router.delete('/projects/:id/exports/:export_id', async (req, res) => {
|
|
111
109
|
try {
|
|
112
110
|
const auth = await config.authProvider(req);
|
|
113
111
|
if (!auth || !auth.userId) {
|
|
114
112
|
return res.status(401).json({ message: 'Unauthorized' });
|
|
115
113
|
}
|
|
116
114
|
const { id: projectId, export_id: exportId } = req.params;
|
|
117
|
-
const { name, collectionName, description, jsonData } = req.body;
|
|
118
|
-
if (!name || !collectionName || !jsonData) {
|
|
119
|
-
return res.status(400).json({ message: 'Missing name, collectionName, or jsonData' });
|
|
120
|
-
}
|
|
121
115
|
const project = await Project.findOne({ _id: projectId });
|
|
122
116
|
if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
|
|
123
117
|
return res.status(403).json({ message: 'Unauthorized project access' });
|
|
124
118
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
119
|
+
const exportMetadata = project.exports.find((e) => e.id.toString() === exportId);
|
|
120
|
+
if (!exportMetadata) {
|
|
121
|
+
return res.status(404).json({ message: 'Export not found in this project' });
|
|
122
|
+
}
|
|
123
|
+
await (0, export_1.deleteExport)(config, projectId, exportId, project.dbType, exportMetadata.collectionName);
|
|
124
|
+
res.status(200).json({ message: 'Export deleted successfully' });
|
|
127
125
|
}
|
|
128
126
|
catch (err) {
|
|
129
|
-
res.status(500).json({ message: 'Failed to
|
|
127
|
+
res.status(500).json({ message: 'Failed to delete export', details: err.message });
|
|
130
128
|
}
|
|
131
129
|
});
|
|
132
130
|
router.get('/:projectId/public-export/:exportName', async (req, res) => {
|
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 => ({
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DatabaseType } from '../types';
|
|
2
2
|
interface CreateExportResult {
|
|
3
3
|
exportId: string;
|
|
4
4
|
collectionName: string;
|
|
5
5
|
message: string;
|
|
6
6
|
}
|
|
7
7
|
import { StreamByConfig } from '../types';
|
|
8
|
-
export declare function createExport(config: StreamByConfig, projectId: string, exportName: string, collectionName: string,
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
8
|
+
export declare function createExport(config: StreamByConfig, projectId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
|
|
9
|
+
export declare function updateExport(config: StreamByConfig, projectId: string, exportId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
|
|
10
|
+
export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, collectionName: string): Promise<{
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
11
13
|
export {};
|
package/dist/services/export.js
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createExport = createExport;
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
4
|
+
exports.updateExport = updateExport;
|
|
5
|
+
exports.deleteExport = deleteExport;
|
|
6
6
|
const manager_1 = require("../models/manager");
|
|
7
7
|
const mongodb_1 = require("mongodb");
|
|
8
8
|
const connectionManager_1 = require("../adapters/database/connectionManager");
|
|
9
9
|
const nosql_1 = require("../adapters/database/nosql");
|
|
10
10
|
const sql_1 = require("../adapters/database/sql");
|
|
11
|
-
async function createExport(config, projectId, exportName, collectionName,
|
|
12
|
-
const Project = (0, manager_1.getModel)('projects');
|
|
13
|
-
const project = await Project.findOne({ _id: projectId });
|
|
14
|
-
if (!project) {
|
|
15
|
-
throw new Error('Project not found');
|
|
16
|
-
}
|
|
17
|
-
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
18
|
-
config.databases?.find(db => db.type === dbType);
|
|
19
|
-
if (!targetDb) {
|
|
20
|
-
throw new Error(`Database connection not found for type ${dbType}`);
|
|
21
|
-
}
|
|
22
|
-
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
23
|
-
let result;
|
|
24
|
-
if (dbType === 'nosql') {
|
|
25
|
-
result = await (0, nosql_1.createNoSQLExportCollection)(connection.client, projectId, exportName, fields);
|
|
26
|
-
}
|
|
27
|
-
else if (dbType === 'sql') {
|
|
28
|
-
result = await (0, sql_1.createSQLExportTable)(connection.client, projectId, exportName, fields);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
throw new Error('Unsupported database type');
|
|
32
|
-
}
|
|
33
|
-
// Update the project with the new export reference
|
|
34
|
-
// Assuming project metadata is always in NoSQL (MongoDB)
|
|
35
|
-
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
36
|
-
await NoSQLProject.update({ _id: projectId }, { $push: { exports: { id: dbType === 'nosql' ? new mongodb_1.ObjectId(result.exportId) : result.exportId, name: exportName, collectionName: result.collectionName, type: 'structured', fields, method: 'GET' } } });
|
|
37
|
-
return { ...result, message: 'Export created successfully' };
|
|
38
|
-
}
|
|
39
|
-
async function createRawExport(config, projectId, exportName, collectionName, jsonData, dbType) {
|
|
11
|
+
async function createExport(config, projectId, exportName, collectionName, jsonData, dbType) {
|
|
40
12
|
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
41
13
|
config.databases?.find(db => db.type === dbType);
|
|
42
14
|
if (!targetDb) {
|
|
@@ -59,7 +31,7 @@ async function createRawExport(config, projectId, exportName, collectionName, js
|
|
|
59
31
|
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' } } });
|
|
60
32
|
return { ...result, message: 'Raw export created successfully' };
|
|
61
33
|
}
|
|
62
|
-
async function
|
|
34
|
+
async function updateExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType) {
|
|
63
35
|
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
64
36
|
config.databases?.find(db => db.type === dbType);
|
|
65
37
|
if (!targetDb) {
|
|
@@ -88,3 +60,21 @@ async function updateRawExport(config, projectId, exportId, exportName, collecti
|
|
|
88
60
|
console.log(result);
|
|
89
61
|
return { ...result, message: 'Raw export updated successfully' };
|
|
90
62
|
}
|
|
63
|
+
async function deleteExport(config, projectId, exportId, dbType, collectionName) {
|
|
64
|
+
const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
|
|
65
|
+
config.databases?.find(db => db.type === dbType);
|
|
66
|
+
if (!targetDb) {
|
|
67
|
+
throw new Error(`Database connection not found for type ${dbType}`);
|
|
68
|
+
}
|
|
69
|
+
const connection = (0, connectionManager_1.getConnection)(targetDb.id);
|
|
70
|
+
if (dbType === 'nosql') {
|
|
71
|
+
const db = connection.client.db();
|
|
72
|
+
await db.collection(collectionName).deleteOne({ _id: new mongodb_1.ObjectId(exportId) });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error('Unsupported database type for delete');
|
|
76
|
+
}
|
|
77
|
+
const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
|
|
78
|
+
await NoSQLProject.update({ _id: new mongodb_1.ObjectId(projectId) }, { $pull: { exports: { id: new mongodb_1.ObjectId(exportId) } } });
|
|
79
|
+
return { message: 'Export deleted successfully' };
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "streamby-core",
|
|
3
|
-
"version": "0.23.
|
|
4
|
-
"description": "StreamBy middleware framework for media storage management",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"test": "vitest",
|
|
13
|
-
"dev": "ts-node-dev --respawn --clear dev.ts",
|
|
14
|
-
"prepublishOnly": "npm run build"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "https://github.com/GwerhDev/StreamBy-Package.git"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"streamby",
|
|
22
|
-
"middleware",
|
|
23
|
-
"upload",
|
|
24
|
-
"storage",
|
|
25
|
-
"s3",
|
|
26
|
-
"express",
|
|
27
|
-
"typescript"
|
|
28
|
-
],
|
|
29
|
-
"author": "TerminalCore Labs",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@aws-sdk/client-s3": "^3.528.0",
|
|
33
|
-
"@aws-sdk/s3-request-presigner": "^3.787.0",
|
|
34
|
-
"@prisma/client": "^6.12.0",
|
|
35
|
-
"bcrypt": "^5.1.1",
|
|
36
|
-
"dotenv": "^16.5.0",
|
|
37
|
-
"express": "^4.0.0",
|
|
38
|
-
"mongodb": "^6.17.0",
|
|
39
|
-
"mongoose": "^8.13.2",
|
|
40
|
-
"pg": "^8.16.3",
|
|
41
|
-
"prisma": "^6.12.0"
|
|
42
|
-
},
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@types/bcrypt": "^5.0.2",
|
|
45
|
-
"@types/cors": "^2.8.18",
|
|
46
|
-
"@types/express": "^4.17.17",
|
|
47
|
-
"@types/mongodb": "^4.0.7",
|
|
48
|
-
"@types/node": "^22.15.21",
|
|
49
|
-
"@types/pg": "^8.15.4",
|
|
50
|
-
"@types/supertest": "^6.0.3",
|
|
51
|
-
"cors": "^2.8.5",
|
|
52
|
-
"supertest": "^7.1.4",
|
|
53
|
-
"ts-node-dev": "^2.0.0",
|
|
54
|
-
"typescript": "^5.8.3",
|
|
55
|
-
"vitest": "^3.1.1"
|
|
56
|
-
},
|
|
57
|
-
"peerDependencies": {
|
|
58
|
-
"express": "^4.0.0"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "streamby-core",
|
|
3
|
+
"version": "0.23.5",
|
|
4
|
+
"description": "StreamBy middleware framework for media storage management",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "vitest",
|
|
13
|
+
"dev": "ts-node-dev --respawn --clear dev.ts",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/GwerhDev/StreamBy-Package.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"streamby",
|
|
22
|
+
"middleware",
|
|
23
|
+
"upload",
|
|
24
|
+
"storage",
|
|
25
|
+
"s3",
|
|
26
|
+
"express",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"author": "TerminalCore Labs",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@aws-sdk/client-s3": "^3.528.0",
|
|
33
|
+
"@aws-sdk/s3-request-presigner": "^3.787.0",
|
|
34
|
+
"@prisma/client": "^6.12.0",
|
|
35
|
+
"bcrypt": "^5.1.1",
|
|
36
|
+
"dotenv": "^16.5.0",
|
|
37
|
+
"express": "^4.0.0",
|
|
38
|
+
"mongodb": "^6.17.0",
|
|
39
|
+
"mongoose": "^8.13.2",
|
|
40
|
+
"pg": "^8.16.3",
|
|
41
|
+
"prisma": "^6.12.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/bcrypt": "^5.0.2",
|
|
45
|
+
"@types/cors": "^2.8.18",
|
|
46
|
+
"@types/express": "^4.17.17",
|
|
47
|
+
"@types/mongodb": "^4.0.7",
|
|
48
|
+
"@types/node": "^22.15.21",
|
|
49
|
+
"@types/pg": "^8.15.4",
|
|
50
|
+
"@types/supertest": "^6.0.3",
|
|
51
|
+
"cors": "^2.8.5",
|
|
52
|
+
"supertest": "^7.1.4",
|
|
53
|
+
"ts-node-dev": "^2.0.0",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.1.1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"express": "^4.0.0"
|
|
59
|
+
}
|
|
60
|
+
}
|