streamby-core 0.17.0 → 0.19.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.
Files changed (94) hide show
  1. package/README.md +206 -114
  2. package/dist/adapters/database/connectionManager.d.ts +6 -0
  3. package/dist/adapters/database/connectionManager.js +47 -0
  4. package/dist/adapters/database/nosql.d.ts +8 -0
  5. package/dist/adapters/database/nosql.js +46 -0
  6. package/dist/adapters/database/nosqlAdapter.d.ts +8 -0
  7. package/dist/adapters/database/nosqlAdapter.js +30 -0
  8. package/dist/adapters/database/sql.d.ts +8 -0
  9. package/dist/adapters/database/sql.js +42 -0
  10. package/dist/adapters/database/sqlAdapter.d.ts +8 -0
  11. package/dist/adapters/database/sqlAdapter.js +42 -0
  12. package/dist/adapters/s3.d.ts +11 -2
  13. package/dist/adapters/s3.js +59 -76
  14. package/dist/adapters/storage/gcs.d.ts +0 -0
  15. package/dist/adapters/storage/gcs.js +1 -0
  16. package/dist/adapters/storage/local.d.ts +0 -0
  17. package/dist/adapters/storage/local.js +1 -0
  18. package/dist/adapters/storage/s3.d.ts +11 -0
  19. package/dist/adapters/storage/s3.js +65 -0
  20. package/dist/database/Model.d.ts +11 -0
  21. package/dist/database/Model.js +95 -0
  22. package/dist/database/connectionManager.d.ts +5 -0
  23. package/dist/database/connectionManager.js +32 -0
  24. package/dist/database/index.d.ts +3 -0
  25. package/dist/database/index.js +19 -0
  26. package/dist/database/model.d.ts +20 -0
  27. package/dist/database/model.js +2 -0
  28. package/dist/database/modelManager.d.ts +8 -0
  29. package/dist/database/modelManager.js +38 -0
  30. package/dist/database/modelRegistry.d.ts +3 -0
  31. package/dist/database/modelRegistry.js +17 -0
  32. package/dist/database/mongoAdapter.d.ts +11 -0
  33. package/dist/database/mongoAdapter.js +42 -0
  34. package/dist/database/sqlAdapter.d.ts +12 -0
  35. package/dist/database/sqlAdapter.js +68 -0
  36. package/dist/middleware/createRouter.js +76 -140
  37. package/dist/models/Model.d.ts +12 -0
  38. package/dist/models/Model.js +146 -0
  39. package/dist/models/manager.d.ts +2 -0
  40. package/dist/models/manager.js +7 -0
  41. package/dist/models/modelManager.d.ts +2 -0
  42. package/dist/models/modelManager.js +7 -0
  43. package/dist/models/modelRegistry.d.ts +3 -0
  44. package/dist/models/modelRegistry.js +17 -0
  45. package/dist/models/register.d.ts +1 -0
  46. package/dist/models/register.js +8 -0
  47. package/dist/models/registerModel.d.ts +1 -0
  48. package/dist/models/registerModel.js +8 -0
  49. package/dist/models/registry.d.ts +3 -0
  50. package/dist/models/registry.js +17 -0
  51. package/dist/providers/createStorageProvider.d.ts +1 -1
  52. package/dist/providers/createStorageProvider.js +9 -13
  53. package/dist/providers/storage.d.ts +2 -0
  54. package/dist/providers/storage.js +12 -0
  55. package/dist/services/auth.d.ts +0 -1
  56. package/dist/services/auth.js +0 -11
  57. package/dist/types/index.d.ts +4 -95
  58. package/package.json +5 -1
  59. package/dist/config.d.ts +0 -18
  60. package/dist/config.js +0 -26
  61. package/dist/db/initExportModel.d.ts +0 -60
  62. package/dist/db/initExportModel.js +0 -18
  63. package/dist/db/initProjectModel.d.ts +0 -2502
  64. package/dist/db/initProjectModel.js +0 -33
  65. package/dist/db/initUserModel.d.ts +0 -48
  66. package/dist/db/initUserModel.js +0 -19
  67. package/dist/models/ExportCollection.d.ts +0 -54
  68. package/dist/models/ExportCollection.js +0 -19
  69. package/dist/mongoose_models/initExportModel.d.ts +0 -61
  70. package/dist/mongoose_models/initExportModel.js +0 -19
  71. package/dist/mongoose_models/initProjectModel.d.ts +0 -2503
  72. package/dist/mongoose_models/initProjectModel.js +0 -34
  73. package/dist/providers/createDatabaseProvider.d.ts +0 -2
  74. package/dist/providers/createDatabaseProvider.js +0 -36
  75. package/dist/providers/createMongooseProvider.d.ts +0 -8
  76. package/dist/providers/createMongooseProvider.js +0 -33
  77. package/dist/providers/createPrismaProvider.d.ts +0 -14
  78. package/dist/providers/createPrismaProvider.js +0 -29
  79. package/dist/providers/mongoExportProvider.d.ts +0 -3
  80. package/dist/providers/mongoExportProvider.js +0 -13
  81. package/dist/providers/mongoProjectProvider.d.ts +0 -3
  82. package/dist/providers/mongoProjectProvider.js +0 -107
  83. package/dist/providers/mongooseExportProvider.d.ts +0 -3
  84. package/dist/providers/mongooseExportProvider.js +0 -13
  85. package/dist/providers/mongooseProjectProvider.d.ts +0 -3
  86. package/dist/providers/mongooseProjectProvider.js +0 -114
  87. package/dist/providers/prismaExportCollectionProvider.d.ts +0 -61
  88. package/dist/providers/prismaExportCollectionProvider.js +0 -45
  89. package/dist/providers/prismaExportProvider.d.ts +0 -3
  90. package/dist/providers/prismaExportProvider.js +0 -13
  91. package/dist/providers/prismaProjectProvider.d.ts +0 -3
  92. package/dist/providers/prismaProjectProvider.js +0 -148
  93. package/dist/utils/pushPrismaSchema.d.ts +0 -5
  94. package/dist/utils/pushPrismaSchema.js +0 -35
package/README.md CHANGED
@@ -1,114 +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
- ## 🚣 Roadmap
93
-
94
- - [ ] Support for Google Cloud Storage
95
- - [ ] CLI tool for uploading files
96
- - [ ] Role-based access control middleware
97
- - [ ] Plugin system for extended routes
98
- - [ ] Streaming support (HLS, audio, etc.)
99
-
100
- ---
101
-
102
- ## 🧑‍💻 Maintained by
103
-
104
- **TerminalCore Labs** – part of [Nhexa Entertainment](https://nhexa.cl)
105
- Developed as open-source infrastructure for creative and media-oriented apps.
106
-
107
- Visit us [here](https://terminalcore.cl)
108
-
109
- ---
110
-
111
- ## 📟 License
112
-
113
- [MIT](./LICENSE)
114
-
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
+
@@ -0,0 +1,6 @@
1
+ import { Pool } from 'pg';
2
+ import { MongoClient } from 'mongodb';
3
+ import { DatabaseCredential } from '../../types';
4
+ export declare const initConnections: (configs: DatabaseCredential[]) => Promise<void>;
5
+ export declare const getConnection: (id: string) => Pool | MongoClient;
6
+ export declare const getConnectedIds: () => string[];
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConnectedIds = exports.getConnection = exports.initConnections = void 0;
4
+ const pg_1 = require("pg");
5
+ const mongodb_1 = require("mongodb");
6
+ const clients = {};
7
+ const connectedIds = [];
8
+ const initConnections = async (configs) => {
9
+ for (const config of configs) {
10
+ if (!config.connectionString) {
11
+ console.error(`❌ Connection string not provided for database config with ID: ${config.id}. Skipping connection.`);
12
+ continue;
13
+ }
14
+ try {
15
+ if (config.type === 'sql') {
16
+ const pool = new pg_1.Pool({ connectionString: config.connectionString });
17
+ await pool.connect();
18
+ clients[config.id] = pool;
19
+ connectedIds.push(config.id);
20
+ console.log(`🟢 PostgreSQL connection established for ID: ${config.id}`);
21
+ }
22
+ else if (config.type === 'nosql') {
23
+ const client = new mongodb_1.MongoClient(config.connectionString);
24
+ await client.connect();
25
+ clients[config.id] = client;
26
+ connectedIds.push(config.id);
27
+ console.log(`🟢 MongoDB connection established for ID: ${config.id}`);
28
+ }
29
+ }
30
+ catch (error) {
31
+ console.error(`❌ Failed to establish ${config.type} connection for ID: ${config.id}. Error:`, error);
32
+ }
33
+ }
34
+ };
35
+ exports.initConnections = initConnections;
36
+ const getConnection = (id) => {
37
+ const client = clients[id];
38
+ if (!client) {
39
+ throw new Error(`Connection with id ${id} not found.`);
40
+ }
41
+ return client;
42
+ };
43
+ exports.getConnection = getConnection;
44
+ const getConnectedIds = () => {
45
+ return connectedIds;
46
+ };
47
+ exports.getConnectedIds = getConnectedIds;
@@ -0,0 +1,8 @@
1
+ import { MongoClient, Document } from 'mongodb';
2
+ export declare const nosqlAdapter: {
3
+ find: (connection: MongoClient, tableName: string, filter: any) => Promise<Document[]>;
4
+ findOne: (connection: MongoClient, tableName: string, filter: any) => Promise<Document | null>;
5
+ create: <T extends Document>(connection: MongoClient, tableName: string, data: T) => Promise<T>;
6
+ update: (connection: MongoClient, tableName: string, filter: any, data: Partial<Document>) => Promise<Document | null>;
7
+ delete: (connection: MongoClient, tableName: string, filter: any) => Promise<number>;
8
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nosqlAdapter = void 0;
4
+ const mongodb_1 = require("mongodb");
5
+ exports.nosqlAdapter = {
6
+ find: async (connection, tableName, filter) => {
7
+ const db = connection.db();
8
+ const result = await db.collection(tableName).find(filter).toArray();
9
+ return result;
10
+ },
11
+ findOne: async (connection, tableName, filter) => {
12
+ const db = connection.db();
13
+ let processedFilter = { ...filter };
14
+ if (processedFilter._id && typeof processedFilter._id === 'string') {
15
+ processedFilter._id = new mongodb_1.ObjectId(processedFilter._id);
16
+ }
17
+ const result = await db.collection(tableName).findOne(processedFilter);
18
+ return result;
19
+ },
20
+ create: async (connection, tableName, data) => {
21
+ const db = connection.db();
22
+ const result = await db.collection(tableName).insertOne(data);
23
+ return { ...data, _id: result.insertedId };
24
+ },
25
+ update: async (connection, tableName, filter, data) => {
26
+ const db = connection.db();
27
+ let processedFilter = { ...filter };
28
+ if (processedFilter._id && typeof processedFilter._id === 'string') {
29
+ processedFilter._id = new mongodb_1.ObjectId(processedFilter._id);
30
+ }
31
+ const result = await db.collection(tableName).findOneAndUpdate(processedFilter, { $set: data }, { returnDocument: 'after' });
32
+ if (!result) {
33
+ return null;
34
+ }
35
+ return result;
36
+ },
37
+ delete: async (connection, tableName, filter) => {
38
+ const db = connection.db();
39
+ let processedFilter = { ...filter };
40
+ if (processedFilter._id && typeof processedFilter._id === 'string') {
41
+ processedFilter._id = new mongodb_1.ObjectId(processedFilter._id);
42
+ }
43
+ const result = await db.collection(tableName).deleteMany(processedFilter);
44
+ return result.deletedCount;
45
+ },
46
+ };
@@ -0,0 +1,8 @@
1
+ import { MongoClient, Document } from 'mongodb';
2
+ export declare const nosqlAdapter: {
3
+ find: <T extends Document>(connection: MongoClient, tableName: string, filter: any) => Promise<T[]>;
4
+ findOne: <T extends Document>(connection: MongoClient, tableName: string, filter: any) => Promise<T | null>;
5
+ create: <T extends Document>(connection: MongoClient, tableName: string, data: T) => Promise<T>;
6
+ update: <T extends Document>(connection: MongoClient, tableName: string, filter: any, data: Partial<T>) => Promise<number>;
7
+ delete: <T extends Document>(connection: MongoClient, tableName: string, filter: any) => Promise<number>;
8
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nosqlAdapter = void 0;
4
+ exports.nosqlAdapter = {
5
+ find: async (connection, tableName, filter) => {
6
+ const db = connection.db();
7
+ const result = await db.collection(tableName).find(filter).toArray();
8
+ return result;
9
+ },
10
+ findOne: async (connection, tableName, filter) => {
11
+ const db = connection.db();
12
+ const result = await db.collection(tableName).findOne(filter);
13
+ return result;
14
+ },
15
+ create: async (connection, tableName, data) => {
16
+ const db = connection.db();
17
+ const result = await db.collection(tableName).insertOne(data);
18
+ return { ...data, _id: result.insertedId };
19
+ },
20
+ update: async (connection, tableName, filter, data) => {
21
+ const db = connection.db();
22
+ const result = await db.collection(tableName).updateMany(filter, { $set: data });
23
+ return result.modifiedCount;
24
+ },
25
+ delete: async (connection, tableName, filter) => {
26
+ const db = connection.db();
27
+ const result = await db.collection(tableName).deleteMany(filter);
28
+ return result.deletedCount;
29
+ },
30
+ };
@@ -0,0 +1,8 @@
1
+ import { Pool } from 'pg';
2
+ export declare const sqlAdapter: {
3
+ find: (connection: Pool, tableName: string, filter: any) => Promise<any[]>;
4
+ findOne: (connection: Pool, tableName: string, filter: any) => Promise<any | null>;
5
+ create: (connection: Pool, tableName: string, data: any) => Promise<any>;
6
+ update: (connection: Pool, tableName: string, filter: any, data: any) => Promise<any | null>;
7
+ delete: (connection: Pool, tableName: string, filter: any) => Promise<number>;
8
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sqlAdapter = void 0;
4
+ exports.sqlAdapter = {
5
+ find: async (connection, tableName, filter) => {
6
+ const keys = Object.keys(filter);
7
+ const values = Object.values(filter);
8
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
9
+ const result = await connection.query(`SELECT * FROM "${tableName}" WHERE ${where}`, values);
10
+ return result.rows;
11
+ },
12
+ findOne: async (connection, tableName, filter) => {
13
+ const keys = Object.keys(filter);
14
+ const values = Object.values(filter);
15
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
16
+ const result = await connection.query(`SELECT * FROM "${tableName}" WHERE ${where} LIMIT 1`, values);
17
+ return result.rows[0] || null;
18
+ },
19
+ create: async (connection, tableName, data) => {
20
+ const keys = Object.keys(data).join(', ');
21
+ const values = Object.values(data);
22
+ const placeholders = values.map((_, i) => `$${i + 1}`).join(', ');
23
+ const result = await connection.query(`INSERT INTO "${tableName}" (${keys}) VALUES (${placeholders}) RETURNING *`, values);
24
+ return result.rows[0];
25
+ },
26
+ update: async (connection, tableName, filter, data) => {
27
+ const dataKeys = Object.keys(data);
28
+ const filterKeys = Object.keys(filter);
29
+ const values = [...Object.values(data), ...Object.values(filter)];
30
+ const setClause = dataKeys.map((key, i) => `"${key}" = $${i + 1}`).join(', ');
31
+ const whereClause = filterKeys.map((key, i) => `"${key}" = $${dataKeys.length + i + 1}`).join(' AND ');
32
+ const result = await connection.query(`UPDATE "${tableName}" SET ${setClause} WHERE ${whereClause} RETURNING *`, values);
33
+ return result.rows[0] || null;
34
+ },
35
+ delete: async (connection, tableName, filter) => {
36
+ const keys = Object.keys(filter);
37
+ const values = Object.values(filter);
38
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
39
+ const result = await connection.query(`DELETE FROM "${tableName}" WHERE ${where}`, values);
40
+ return result.rowCount || 0;
41
+ },
42
+ };
@@ -0,0 +1,8 @@
1
+ import { Pool } from 'pg';
2
+ export declare const sqlAdapter: {
3
+ find: <T>(connection: Pool, tableName: string, filter: any) => Promise<T[]>;
4
+ findOne: <T>(connection: Pool, tableName: string, filter: any) => Promise<T | null>;
5
+ create: <T>(connection: Pool, tableName: string, data: T) => Promise<T>;
6
+ update: <T>(connection: Pool, tableName: string, filter: any, data: Partial<T>) => Promise<number>;
7
+ delete: (connection: Pool, tableName: string, filter: any) => Promise<number>;
8
+ };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sqlAdapter = void 0;
4
+ exports.sqlAdapter = {
5
+ find: async (connection, tableName, filter) => {
6
+ const keys = Object.keys(filter);
7
+ const values = Object.values(filter);
8
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
9
+ const result = await connection.query(`SELECT * FROM "${tableName}" WHERE ${where}`, values);
10
+ return result.rows;
11
+ },
12
+ findOne: async (connection, tableName, filter) => {
13
+ const keys = Object.keys(filter);
14
+ const values = Object.values(filter);
15
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
16
+ const result = await connection.query(`SELECT * FROM "${tableName}" WHERE ${where} LIMIT 1`, values);
17
+ return result.rows[0] || null;
18
+ },
19
+ create: async (connection, tableName, data) => {
20
+ const keys = Object.keys(data).join(', ');
21
+ const values = Object.values(data);
22
+ const placeholders = values.map((_, i) => `$${i + 1}`).join(', ');
23
+ const result = await connection.query(`INSERT INTO "${tableName}" (${keys}) VALUES (${placeholders}) RETURNING *`, values);
24
+ return result.rows[0];
25
+ },
26
+ update: async (connection, tableName, filter, data) => {
27
+ const dataKeys = Object.keys(data);
28
+ const filterKeys = Object.keys(filter);
29
+ const values = [...Object.values(data), ...Object.values(filter)];
30
+ const setClause = dataKeys.map((key, i) => `"${key}" = $${i + 1}`).join(', ');
31
+ const whereClause = filterKeys.map((key, i) => `"${key}" = $${dataKeys.length + i + 1}`).join(' AND ');
32
+ const result = await connection.query(`UPDATE "${tableName}" SET ${setClause} WHERE ${whereClause}`, values);
33
+ return result.rowCount || 0;
34
+ },
35
+ delete: async (connection, tableName, filter) => {
36
+ const keys = Object.keys(filter);
37
+ const values = Object.values(filter);
38
+ const where = keys.map((key, i) => `"${key}" = $${i + 1}`).join(' AND ');
39
+ const result = await connection.query(`DELETE FROM "${tableName}" WHERE ${where}`, values);
40
+ return result.rowCount || 0;
41
+ },
42
+ };
@@ -1,2 +1,11 @@
1
- import { StorageAdapter, S3Config } from '../types';
2
- export declare function createS3Adapter(config: S3Config): StorageAdapter;
1
+ import { S3Config, StorageAdapter } from '../types';
2
+ export declare class S3Adapter implements StorageAdapter {
3
+ private s3;
4
+ private bucket;
5
+ constructor(config: S3Config);
6
+ listFiles(projectId: string): Promise<any[]>;
7
+ deleteProjectImage(projectId: string): Promise<any>;
8
+ deleteProjectDirectory(projectId: string): Promise<any>;
9
+ getPresignedUrl(contentType: string, projectId: string): Promise<any>;
10
+ getPresignedProjectImageUrl(projectId: string): Promise<any>;
11
+ }