streamby-core 0.25.7 โ 0.26.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/README.md +242 -242
- package/dist/adapters/database/connectionManager.js +41 -41
- package/dist/adapters/database/nosql.d.ts +2 -2
- package/dist/adapters/database/nosql.js +4 -5
- package/dist/adapters/database/sql.d.ts +1 -1
- package/dist/adapters/database/sql.js +22 -18
- package/dist/middleware/createRouter.js +6 -2
- package/dist/middleware/routes/connection.d.ts +3 -0
- package/dist/middleware/routes/connection.js +174 -0
- package/dist/middleware/routes/export.js +82 -70
- package/dist/middleware/routes/member.d.ts +3 -0
- package/dist/middleware/routes/member.js +181 -0
- package/dist/middleware/routes/project.js +10 -33
- package/dist/middleware/routes/user.d.ts +3 -0
- package/dist/middleware/routes/user.js +33 -0
- package/dist/models/Model.js +5 -5
- package/dist/services/export.d.ts +5 -6
- package/dist/services/export.js +18 -81
- package/dist/services/pipeline.d.ts +2 -0
- package/dist/services/pipeline.js +76 -0
- package/dist/types/index.d.ts +10 -4
- package/dist/utils/crypto.d.ts +3 -0
- package/dist/utils/crypto.js +32 -0
- package/package.json +61 -61
package/README.md
CHANGED
|
@@ -1,242 +1,242 @@
|
|
|
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
|
-
---
|
|
32
|
-
|
|
33
|
-
## ๐๏ธ Database Schema Setup
|
|
34
|
-
|
|
35
|
-
`@streamby/core` requires a pre-configured database schema for its internal operations. It does not manage database connections directly; instead, it expects the host application to provide initialized connection instances. This ensures full control and flexibility for the host environment.
|
|
36
|
-
|
|
37
|
-
The library will only interact with the specified schema and will not touch other schemas in your database. The `reset` option is opt-in and will only drop and recreate the specified `streamby` schema if explicitly set to `true`.
|
|
38
|
-
|
|
39
|
-
### PostgreSQL Example
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { Pool } from "pg";
|
|
43
|
-
import { setupStreambyPg } from "@streamby/core/pg/setup"; // Adjust path as per your package structure
|
|
44
|
-
|
|
45
|
-
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
46
|
-
|
|
47
|
-
// Call setupStreambyPg to ensure the schema and tables are created
|
|
48
|
-
// reset: false (default) ensures idempotency and no data loss
|
|
49
|
-
await setupStreambyPg({ pool, schema: "streamby", reset: false });
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### MongoDB Example
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { MongoClient } from "mongodb";
|
|
56
|
-
import { setupStreambyMongo } from "@streamby/core/mongo/setup"; // Adjust path as per your package structure
|
|
57
|
-
|
|
58
|
-
const client = new MongoClient(process.env.MONGO_URL!);
|
|
59
|
-
|
|
60
|
-
// Connect the MongoDB client
|
|
61
|
-
await client.connect();
|
|
62
|
-
|
|
63
|
-
// Call setupStreambyMongo to ensure collections and indexes are created
|
|
64
|
-
await setupStreambyMongo({ client, dbName: "streamby" });
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import express from 'express';
|
|
69
|
-
import { createStreamByRouter } from '@streamby/core';
|
|
70
|
-
|
|
71
|
-
const app = express();
|
|
72
|
-
|
|
73
|
-
app.use('/streamby', createStreamByRouter({
|
|
74
|
-
storageProvider: {
|
|
75
|
-
type: 's3',
|
|
76
|
-
config: {
|
|
77
|
-
bucket: 'your-bucket-name',
|
|
78
|
-
region: 'your-region',
|
|
79
|
-
accessKeyId: 'YOUR_AWS_KEY',
|
|
80
|
-
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
authProvider: async (req) => {
|
|
84
|
-
// extract token/cookie and validate
|
|
85
|
-
return {
|
|
86
|
-
userId: 'demo',
|
|
87
|
-
projects: ['demo-project'],
|
|
88
|
-
role: 'admin',
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
projectProvider: async (projectId) => {
|
|
92
|
-
// fetch project from your DB
|
|
93
|
-
return {
|
|
94
|
-
id: projectId,
|
|
95
|
-
name: 'Demo Project',
|
|
96
|
-
description: 'Demo for StreamBy integration',
|
|
97
|
-
rootFolders: [],
|
|
98
|
-
settings: { allowUpload: true }
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
app.listen(3000);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
---
|
|
107
|
-
|
|
108
|
-
## ๐งช Testing
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
npm run test
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## ๐ Features
|
|
119
|
-
|
|
120
|
-
- ๐ Multi-project access control
|
|
121
|
-
- ๐ Project-aware file uploads & listings
|
|
122
|
-
- ๐งน Modular adapters per storage provider
|
|
123
|
-
- ๐งฐ Built-in testability with mock auth & storage
|
|
124
|
-
- โจ Simple to extend for custom business logic
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## ๐บ๏ธ API Endpoints
|
|
129
|
-
|
|
130
|
-
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
131
|
-
|
|
132
|
-
### `GET /streamby/projects`
|
|
133
|
-
|
|
134
|
-
Lists all projects accessible by the authenticated user.
|
|
135
|
-
|
|
136
|
-
**Query Parameters:**
|
|
137
|
-
- `archived`: (Optional) Filter projects by their archived status.
|
|
138
|
-
- `true`: Returns only archived projects.
|
|
139
|
-
- `false`: Returns only unarchived projects.
|
|
140
|
-
- (Omitted): Returns all projects (both archived and unarchived).
|
|
141
|
-
|
|
142
|
-
**Example Response:**
|
|
143
|
-
```json
|
|
144
|
-
{
|
|
145
|
-
"projects": [
|
|
146
|
-
{
|
|
147
|
-
"id": "project1_id",
|
|
148
|
-
"dbType": "nosql",
|
|
149
|
-
"name": "My NoSQL Project",
|
|
150
|
-
"image": "url_to_image",
|
|
151
|
-
"archived": false
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
"id": "project2_id",
|
|
155
|
-
"dbType": "sql",
|
|
156
|
-
"name": "My SQL Project",
|
|
157
|
-
"image": "url_to_image",
|
|
158
|
-
"archived": true
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### `PATCH /streamby/projects/:id/archive`
|
|
165
|
-
|
|
166
|
-
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
167
|
-
|
|
168
|
-
**Example Response:**
|
|
169
|
-
```json
|
|
170
|
-
{
|
|
171
|
-
"success": true,
|
|
172
|
-
"projects": [
|
|
173
|
-
{
|
|
174
|
-
"id": "project1_id",
|
|
175
|
-
"dbType": "nosql",
|
|
176
|
-
"name": "My NoSQL Project",
|
|
177
|
-
"image": "url_to_image",
|
|
178
|
-
"archived": true
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
"id": "project2_id",
|
|
182
|
-
"dbType": "sql",
|
|
183
|
-
"name": "My SQL Project",
|
|
184
|
-
"image": "url_to_image",
|
|
185
|
-
"archived": false
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### `PATCH /streamby/projects/:id/unarchive`
|
|
192
|
-
|
|
193
|
-
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
194
|
-
|
|
195
|
-
**Example Response:**
|
|
196
|
-
```json
|
|
197
|
-
{
|
|
198
|
-
"success": true,
|
|
199
|
-
"projects": [
|
|
200
|
-
{
|
|
201
|
-
"id": "project1_id",
|
|
202
|
-
"dbType": "nosql",
|
|
203
|
-
"name": "My NoSQL Project",
|
|
204
|
-
"image": "url_to_image",
|
|
205
|
-
"archived": false
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"id": "project2_id",
|
|
209
|
-
"dbType": "sql",
|
|
210
|
-
"name": "My SQL Project",
|
|
211
|
-
"image": "url_to_image",
|
|
212
|
-
"archived": false
|
|
213
|
-
}
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
## ๐ฃ Roadmap
|
|
221
|
-
|
|
222
|
-
- [ ] Support for Google Cloud Storage
|
|
223
|
-
- [ ] CLI tool for uploading files
|
|
224
|
-
- [ ] Role-based access control middleware
|
|
225
|
-
- [ ] Plugin system for extended routes
|
|
226
|
-
- [ ] Streaming support (HLS, audio, etc.)
|
|
227
|
-
|
|
228
|
-
---
|
|
229
|
-
|
|
230
|
-
## ๐งโ๐ป Maintained by
|
|
231
|
-
|
|
232
|
-
**TerminalCore Labs** โ part of [Nhexa Entertainment](https://nhexa.cl)
|
|
233
|
-
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
234
|
-
|
|
235
|
-
Visit us [here](https://terminalcore.cl)
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
## ๐ License
|
|
240
|
-
|
|
241
|
-
[MIT](./LICENSE)
|
|
242
|
-
|
|
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
|
+
---
|
|
32
|
+
|
|
33
|
+
## ๐๏ธ Database Schema Setup
|
|
34
|
+
|
|
35
|
+
`@streamby/core` requires a pre-configured database schema for its internal operations. It does not manage database connections directly; instead, it expects the host application to provide initialized connection instances. This ensures full control and flexibility for the host environment.
|
|
36
|
+
|
|
37
|
+
The library will only interact with the specified schema and will not touch other schemas in your database. The `reset` option is opt-in and will only drop and recreate the specified `streamby` schema if explicitly set to `true`.
|
|
38
|
+
|
|
39
|
+
### PostgreSQL Example
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Pool } from "pg";
|
|
43
|
+
import { setupStreambyPg } from "@streamby/core/pg/setup"; // Adjust path as per your package structure
|
|
44
|
+
|
|
45
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
46
|
+
|
|
47
|
+
// Call setupStreambyPg to ensure the schema and tables are created
|
|
48
|
+
// reset: false (default) ensures idempotency and no data loss
|
|
49
|
+
await setupStreambyPg({ pool, schema: "streamby", reset: false });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### MongoDB Example
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { MongoClient } from "mongodb";
|
|
56
|
+
import { setupStreambyMongo } from "@streamby/core/mongo/setup"; // Adjust path as per your package structure
|
|
57
|
+
|
|
58
|
+
const client = new MongoClient(process.env.MONGO_URL!);
|
|
59
|
+
|
|
60
|
+
// Connect the MongoDB client
|
|
61
|
+
await client.connect();
|
|
62
|
+
|
|
63
|
+
// Call setupStreambyMongo to ensure collections and indexes are created
|
|
64
|
+
await setupStreambyMongo({ client, dbName: "streamby" });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import express from 'express';
|
|
69
|
+
import { createStreamByRouter } from '@streamby/core';
|
|
70
|
+
|
|
71
|
+
const app = express();
|
|
72
|
+
|
|
73
|
+
app.use('/streamby', createStreamByRouter({
|
|
74
|
+
storageProvider: {
|
|
75
|
+
type: 's3',
|
|
76
|
+
config: {
|
|
77
|
+
bucket: 'your-bucket-name',
|
|
78
|
+
region: 'your-region',
|
|
79
|
+
accessKeyId: 'YOUR_AWS_KEY',
|
|
80
|
+
secretAccessKey: 'YOUR_AWS_SECRET'
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
authProvider: async (req) => {
|
|
84
|
+
// extract token/cookie and validate
|
|
85
|
+
return {
|
|
86
|
+
userId: 'demo',
|
|
87
|
+
projects: ['demo-project'],
|
|
88
|
+
role: 'admin',
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
projectProvider: async (projectId) => {
|
|
92
|
+
// fetch project from your DB
|
|
93
|
+
return {
|
|
94
|
+
id: projectId,
|
|
95
|
+
name: 'Demo Project',
|
|
96
|
+
description: 'Demo for StreamBy integration',
|
|
97
|
+
rootFolders: [],
|
|
98
|
+
settings: { allowUpload: true }
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
app.listen(3000);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## ๐งช Testing
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run test
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Unit tests use [Vitest](https://vitest.dev) and [Supertest](https://www.npmjs.com/package/supertest).
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## ๐ Features
|
|
119
|
+
|
|
120
|
+
- ๐ Multi-project access control
|
|
121
|
+
- ๐ Project-aware file uploads & listings
|
|
122
|
+
- ๐งน Modular adapters per storage provider
|
|
123
|
+
- ๐งฐ Built-in testability with mock auth & storage
|
|
124
|
+
- โจ Simple to extend for custom business logic
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## ๐บ๏ธ API Endpoints
|
|
129
|
+
|
|
130
|
+
Here's a summary of the key API endpoints provided by `@streamby/core`:
|
|
131
|
+
|
|
132
|
+
### `GET /streamby/projects`
|
|
133
|
+
|
|
134
|
+
Lists all projects accessible by the authenticated user.
|
|
135
|
+
|
|
136
|
+
**Query Parameters:**
|
|
137
|
+
- `archived`: (Optional) Filter projects by their archived status.
|
|
138
|
+
- `true`: Returns only archived projects.
|
|
139
|
+
- `false`: Returns only unarchived projects.
|
|
140
|
+
- (Omitted): Returns all projects (both archived and unarchived).
|
|
141
|
+
|
|
142
|
+
**Example Response:**
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"projects": [
|
|
146
|
+
{
|
|
147
|
+
"id": "project1_id",
|
|
148
|
+
"dbType": "nosql",
|
|
149
|
+
"name": "My NoSQL Project",
|
|
150
|
+
"image": "url_to_image",
|
|
151
|
+
"archived": false
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": "project2_id",
|
|
155
|
+
"dbType": "sql",
|
|
156
|
+
"name": "My SQL Project",
|
|
157
|
+
"image": "url_to_image",
|
|
158
|
+
"archived": true
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `PATCH /streamby/projects/:id/archive`
|
|
165
|
+
|
|
166
|
+
Archives a specific project. After archiving, it returns the complete list of projects for the user, including the updated project.
|
|
167
|
+
|
|
168
|
+
**Example Response:**
|
|
169
|
+
```json
|
|
170
|
+
{
|
|
171
|
+
"success": true,
|
|
172
|
+
"projects": [
|
|
173
|
+
{
|
|
174
|
+
"id": "project1_id",
|
|
175
|
+
"dbType": "nosql",
|
|
176
|
+
"name": "My NoSQL Project",
|
|
177
|
+
"image": "url_to_image",
|
|
178
|
+
"archived": true
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"id": "project2_id",
|
|
182
|
+
"dbType": "sql",
|
|
183
|
+
"name": "My SQL Project",
|
|
184
|
+
"image": "url_to_image",
|
|
185
|
+
"archived": false
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### `PATCH /streamby/projects/:id/unarchive`
|
|
192
|
+
|
|
193
|
+
Unarchives a specific project. After unarchiving, it returns the complete list of projects for the user, including the updated project.
|
|
194
|
+
|
|
195
|
+
**Example Response:**
|
|
196
|
+
```json
|
|
197
|
+
{
|
|
198
|
+
"success": true,
|
|
199
|
+
"projects": [
|
|
200
|
+
{
|
|
201
|
+
"id": "project1_id",
|
|
202
|
+
"dbType": "nosql",
|
|
203
|
+
"name": "My NoSQL Project",
|
|
204
|
+
"image": "url_to_image",
|
|
205
|
+
"archived": false
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"id": "project2_id",
|
|
209
|
+
"dbType": "sql",
|
|
210
|
+
"name": "My SQL Project",
|
|
211
|
+
"image": "url_to_image",
|
|
212
|
+
"archived": false
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## ๐ฃ Roadmap
|
|
221
|
+
|
|
222
|
+
- [ ] Support for Google Cloud Storage
|
|
223
|
+
- [ ] CLI tool for uploading files
|
|
224
|
+
- [ ] Role-based access control middleware
|
|
225
|
+
- [ ] Plugin system for extended routes
|
|
226
|
+
- [ ] Streaming support (HLS, audio, etc.)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## ๐งโ๐ป Maintained by
|
|
231
|
+
|
|
232
|
+
**TerminalCore Labs** โ part of [Nhexa Entertainment](https://nhexa.cl)
|
|
233
|
+
Developed as open-source infrastructure for creative and media-oriented apps.
|
|
234
|
+
|
|
235
|
+
Visit us [here](https://terminalcore.cl)
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## ๐ License
|
|
240
|
+
|
|
241
|
+
[MIT](./LICENSE)
|
|
242
|
+
|
|
@@ -43,56 +43,56 @@ const getConnection = (id) => {
|
|
|
43
43
|
exports.getConnection = getConnection;
|
|
44
44
|
const ensureTablesExist = async (pool) => {
|
|
45
45
|
try {
|
|
46
|
-
await pool.query(`
|
|
47
|
-
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
49
|
-
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
50
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
51
|
-
name VARCHAR(255) NOT NULL,
|
|
52
|
-
description TEXT,
|
|
53
|
-
image TEXT,
|
|
54
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
55
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
56
|
-
);
|
|
46
|
+
await pool.query(`
|
|
47
|
+
CREATE SCHEMA IF NOT EXISTS streamby;
|
|
48
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
49
|
+
CREATE TABLE IF NOT EXISTS streamby.projects (
|
|
50
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
51
|
+
name VARCHAR(255) NOT NULL,
|
|
52
|
+
description TEXT,
|
|
53
|
+
image TEXT,
|
|
54
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
55
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
56
|
+
);
|
|
57
57
|
`);
|
|
58
58
|
console.log('โ
"projects" table ensured to exist.');
|
|
59
59
|
// Ensure dbType column exists and is correctly configured
|
|
60
|
-
await pool.query(`
|
|
61
|
-
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50);
|
|
60
|
+
await pool.query(`
|
|
61
|
+
ALTER TABLE streamby.projects ADD COLUMN IF NOT EXISTS "dbType" VARCHAR(50);
|
|
62
62
|
`);
|
|
63
|
-
await pool.query(`
|
|
64
|
-
UPDATE streamby.projects SET "dbType" = 'nosql' WHERE "dbType" IS NULL;
|
|
63
|
+
await pool.query(`
|
|
64
|
+
UPDATE streamby.projects SET "dbType" = 'nosql' WHERE "dbType" IS NULL;
|
|
65
65
|
`);
|
|
66
|
-
await pool.query(`
|
|
67
|
-
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET NOT NULL;
|
|
66
|
+
await pool.query(`
|
|
67
|
+
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET NOT NULL;
|
|
68
68
|
`);
|
|
69
|
-
await pool.query(`
|
|
70
|
-
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET DEFAULT 'nosql';
|
|
69
|
+
await pool.query(`
|
|
70
|
+
ALTER TABLE streamby.projects ALTER COLUMN "dbType" SET DEFAULT 'nosql';
|
|
71
71
|
`);
|
|
72
|
-
await pool.query(`
|
|
73
|
-
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
74
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
75
|
-
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
76
|
-
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
77
|
-
"filePath" TEXT,
|
|
78
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
79
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
80
|
-
);
|
|
72
|
+
await pool.query(`
|
|
73
|
+
CREATE TABLE IF NOT EXISTS streamby.exports (
|
|
74
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
75
|
+
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
76
|
+
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
|
77
|
+
"filePath" TEXT,
|
|
78
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
79
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
80
|
+
);
|
|
81
81
|
`);
|
|
82
82
|
console.log('โ
"exports" table ensured to exist.');
|
|
83
|
-
await pool.query(`
|
|
84
|
-
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
85
|
-
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
86
|
-
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
87
|
-
"userId" VARCHAR(255) NOT NULL,
|
|
88
|
-
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
89
|
-
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
90
|
-
"archivedBy" VARCHAR(255),
|
|
91
|
-
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
92
|
-
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
93
|
-
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
94
|
-
UNIQUE ("projectId", "userId")
|
|
95
|
-
);
|
|
83
|
+
await pool.query(`
|
|
84
|
+
CREATE TABLE IF NOT EXISTS streamby.project_members (
|
|
85
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
86
|
+
"projectId" UUID NOT NULL REFERENCES streamby.projects(id) ON DELETE CASCADE,
|
|
87
|
+
"userId" VARCHAR(255) NOT NULL,
|
|
88
|
+
role VARCHAR(255) NOT NULL DEFAULT 'member',
|
|
89
|
+
archived BOOLEAN NOT NULL DEFAULT FALSE,
|
|
90
|
+
"archivedBy" VARCHAR(255),
|
|
91
|
+
"archivedAt" TIMESTAMP WITH TIME ZONE,
|
|
92
|
+
"createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
93
|
+
"updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
94
|
+
UNIQUE ("projectId", "userId")
|
|
95
|
+
);
|
|
96
96
|
`);
|
|
97
97
|
console.log('โ
"project_members" table ensured to exist.');
|
|
98
98
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MongoClient, Document } from 'mongodb';
|
|
2
|
-
import { FieldDefinition } from '../../types';
|
|
2
|
+
import { FieldDefinition, NodeSchema } from '../../types';
|
|
3
3
|
export declare const ensureCollectionsExist: (client: MongoClient) => Promise<void>;
|
|
4
4
|
export declare const createNoSQLExportCollection: (connection: MongoClient, projectId: string, exportName: string, fields: FieldDefinition[]) => Promise<{
|
|
5
5
|
collectionName: string;
|
|
6
6
|
exportId: string;
|
|
7
7
|
}>;
|
|
8
|
-
export declare const createNoSQLRawExportCollection: (connection: MongoClient,
|
|
8
|
+
export declare const createNoSQLRawExportCollection: (connection: MongoClient, exportName: string, method: string, nodeSchema?: NodeSchema) => Promise<{
|
|
9
9
|
collectionName: string;
|
|
10
10
|
exportId: string;
|
|
11
11
|
}>;
|
|
@@ -33,13 +33,12 @@ 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,
|
|
36
|
+
const createNoSQLRawExportCollection = async (connection, exportName, method, nodeSchema) => {
|
|
37
37
|
const db = connection.db();
|
|
38
38
|
const slug = exportName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
39
|
-
const collectionName =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.log(`โ
Raw collection '${collectionName}' created with provided JSON data.`);
|
|
39
|
+
const collectionName = slug;
|
|
40
|
+
const result = await db.collection(collectionName).insertOne({ nodeSchema, name: exportName, method, createdAt: new Date(), updatedAt: new Date() });
|
|
41
|
+
console.log(`โ
Raw collection '${collectionName}' created.`);
|
|
43
42
|
return { collectionName, exportId: result.insertedId.toHexString() };
|
|
44
43
|
};
|
|
45
44
|
exports.createNoSQLRawExportCollection = createNoSQLRawExportCollection;
|
|
@@ -4,7 +4,7 @@ export declare const createSQLExportTable: (connection: Pool, projectId: string,
|
|
|
4
4
|
collectionName: string;
|
|
5
5
|
exportId: string;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const createSQLRawExportTable: (connection: Pool,
|
|
7
|
+
export declare const createSQLRawExportTable: (connection: Pool, exportName: string, nodeSchema?: any) => Promise<{
|
|
8
8
|
collectionName: string;
|
|
9
9
|
exportId: string;
|
|
10
10
|
}>;
|