streamby-core 0.23.4 → 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.
@@ -60,30 +60,6 @@ function exportRouter(config) {
60
60
  }
61
61
  });
62
62
  router.post('/projects/:id/exports', async (req, res) => {
63
- try {
64
- const auth = await config.authProvider(req);
65
- if (!auth ||
66
- !auth.userId ||
67
- !auth.role) {
68
- return res.status(401).json({ message: 'Unauthorized' });
69
- }
70
- const projectId = req.params.id;
71
- const { name, description, collectionName, fields } = req.body;
72
- if (!name || !collectionName || !fields) {
73
- return res.status(400).json({ message: 'Missing export name, collectionName, or fields' });
74
- }
75
- const project = await Project.findOne({ _id: projectId });
76
- if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
77
- return res.status(403).json({ message: 'Unauthorized project access' });
78
- }
79
- const result = await (0, export_1.createExport)(config, projectId, name, collectionName, fields, project.dbType);
80
- res.status(201).json({ data: result, message: result.message });
81
- }
82
- catch (err) {
83
- res.status(500).json({ message: 'Failed to create export', details: err.message });
84
- }
85
- });
86
- router.post('/projects/:id/exports/raw', async (req, res) => {
87
63
  try {
88
64
  const auth = await config.authProvider(req);
89
65
  if (!auth ||
@@ -100,14 +76,14 @@ function exportRouter(config) {
100
76
  if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
101
77
  return res.status(403).json({ message: 'Unauthorized project access' });
102
78
  }
103
- const result = await (0, export_1.createRawExport)(config, projectId, name, collectionName, jsonData, project.dbType);
79
+ const result = await (0, export_1.createExport)(config, projectId, name, collectionName, jsonData, project.dbType);
104
80
  res.status(201).json({ data: result, message: result.message });
105
81
  }
106
82
  catch (err) {
107
83
  res.status(500).json({ message: 'Failed to create raw export', details: err.message });
108
84
  }
109
85
  });
110
- router.patch('/projects/:id/exports/raw/:export_id', async (req, res) => {
86
+ router.patch('/projects/:id/exports/:export_id', async (req, res) => {
111
87
  try {
112
88
  const auth = await config.authProvider(req);
113
89
  if (!auth || !auth.userId) {
@@ -122,7 +98,7 @@ function exportRouter(config) {
122
98
  if (!project || !(0, auth_1.isProjectMember)(project, auth.userId)) {
123
99
  return res.status(403).json({ message: 'Unauthorized project access' });
124
100
  }
125
- const result = await (0, export_1.updateRawExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType);
101
+ const result = await (0, export_1.updateExport)(config, projectId, exportId, name, collectionName, jsonData, project.dbType);
126
102
  res.status(200).json({ data: result, message: result.message });
127
103
  }
128
104
  catch (err) {
@@ -1,13 +1,12 @@
1
- import { FieldDefinition, DatabaseType } from '../types';
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, fields: FieldDefinition[], dbType: DatabaseType): Promise<CreateExportResult>;
9
- export declare function createRawExport(config: StreamByConfig, projectId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
10
- export declare function updateRawExport(config: StreamByConfig, projectId: string, exportId: string, exportName: string, collectionName: string, jsonData: any, dbType: DatabaseType): Promise<CreateExportResult>;
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>;
11
10
  export declare function deleteExport(config: StreamByConfig, projectId: string, exportId: string, dbType: DatabaseType, collectionName: string): Promise<{
12
11
  message: string;
13
12
  }>;
@@ -1,43 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createExport = createExport;
4
- exports.createRawExport = createRawExport;
5
- exports.updateRawExport = updateRawExport;
4
+ exports.updateExport = updateExport;
6
5
  exports.deleteExport = deleteExport;
7
6
  const manager_1 = require("../models/manager");
8
7
  const mongodb_1 = require("mongodb");
9
8
  const connectionManager_1 = require("../adapters/database/connectionManager");
10
9
  const nosql_1 = require("../adapters/database/nosql");
11
10
  const sql_1 = require("../adapters/database/sql");
12
- async function createExport(config, projectId, exportName, collectionName, fields, dbType) {
13
- const Project = (0, manager_1.getModel)('projects');
14
- const project = await Project.findOne({ _id: projectId });
15
- if (!project) {
16
- throw new Error('Project not found');
17
- }
18
- const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
19
- config.databases?.find(db => db.type === dbType);
20
- if (!targetDb) {
21
- throw new Error(`Database connection not found for type ${dbType}`);
22
- }
23
- const connection = (0, connectionManager_1.getConnection)(targetDb.id);
24
- let result;
25
- if (dbType === 'nosql') {
26
- result = await (0, nosql_1.createNoSQLExportCollection)(connection.client, projectId, exportName, fields);
27
- }
28
- else if (dbType === 'sql') {
29
- result = await (0, sql_1.createSQLExportTable)(connection.client, projectId, exportName, fields);
30
- }
31
- else {
32
- throw new Error('Unsupported database type');
33
- }
34
- // Update the project with the new export reference
35
- // Assuming project metadata is always in NoSQL (MongoDB)
36
- const NoSQLProject = (0, manager_1.getModel)('projects', 'nosql');
37
- 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' } } });
38
- return { ...result, message: 'Export created successfully' };
39
- }
40
- async function createRawExport(config, projectId, exportName, collectionName, jsonData, dbType) {
11
+ async function createExport(config, projectId, exportName, collectionName, jsonData, dbType) {
41
12
  const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
42
13
  config.databases?.find(db => db.type === dbType);
43
14
  if (!targetDb) {
@@ -60,7 +31,7 @@ async function createRawExport(config, projectId, exportName, collectionName, js
60
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' } } });
61
32
  return { ...result, message: 'Raw export created successfully' };
62
33
  }
63
- async function updateRawExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType) {
34
+ async function updateExport(config, projectId, exportId, exportName, collectionName, jsonData, dbType) {
64
35
  const targetDb = config.databases?.find(db => db.type === dbType && db.main) ||
65
36
  config.databases?.find(db => db.type === dbType);
66
37
  if (!targetDb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamby-core",
3
- "version": "0.23.4",
3
+ "version": "0.23.5",
4
4
  "description": "StreamBy middleware framework for media storage management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",