streamby-core 0.20.2 → 0.21.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.
- package/dist/adapters/database/connectionManager.d.ts +5 -1
- package/dist/adapters/database/connectionManager.js +66 -10
- package/dist/adapters/database/nosql.d.ts +1 -0
- package/dist/adapters/database/nosql.js +15 -1
- package/dist/adapters/database/sql.js +7 -3
- package/dist/middleware/createRouter.js +96 -14
- package/dist/models/Model.js +167 -36
- package/dist/services/auth.d.ts +1 -3
- package/dist/services/auth.js +0 -10
- package/dist/types/index.d.ts +1 -2
- package/package.json +1 -1
- package/dist/adapters/database/nosqlAdapter.d.ts +0 -8
- package/dist/adapters/database/nosqlAdapter.js +0 -30
- package/dist/adapters/database/sqlAdapter.d.ts +0 -8
- package/dist/adapters/database/sqlAdapter.js +0 -42
- package/dist/adapters/gcs.d.ts +0 -0
- package/dist/adapters/gcs.js +0 -1
- package/dist/adapters/local.d.ts +0 -0
- package/dist/adapters/local.js +0 -1
- package/dist/adapters/s3.d.ts +0 -11
- package/dist/adapters/s3.js +0 -65
- package/dist/database/Model.d.ts +0 -11
- package/dist/database/Model.js +0 -95
- package/dist/database/connectionManager.d.ts +0 -5
- package/dist/database/connectionManager.js +0 -32
- package/dist/database/index.d.ts +0 -3
- package/dist/database/index.js +0 -19
- package/dist/database/model.d.ts +0 -20
- package/dist/database/model.js +0 -2
- package/dist/database/modelManager.d.ts +0 -8
- package/dist/database/modelManager.js +0 -38
- package/dist/database/modelRegistry.d.ts +0 -3
- package/dist/database/modelRegistry.js +0 -17
- package/dist/database/mongoAdapter.d.ts +0 -11
- package/dist/database/mongoAdapter.js +0 -42
- package/dist/database/sqlAdapter.d.ts +0 -12
- package/dist/database/sqlAdapter.js +0 -68
- package/dist/models/modelManager.d.ts +0 -2
- package/dist/models/modelManager.js +0 -7
- package/dist/models/modelRegistry.d.ts +0 -3
- package/dist/models/modelRegistry.js +0 -17
- package/dist/models/registerModel.d.ts +0 -1
- package/dist/models/registerModel.js +0 -8
- package/dist/providers/createStorageProvider.d.ts +0 -2
- package/dist/providers/createStorageProvider.js +0 -12
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConnection = exports.initConnections = void 0;
|
|
4
|
-
const pg_1 = require("pg");
|
|
5
|
-
const mongodb_1 = require("mongodb");
|
|
6
|
-
const clients = {};
|
|
7
|
-
const initConnections = async (configs) => {
|
|
8
|
-
for (const config of configs) {
|
|
9
|
-
if (!config.connectionString) {
|
|
10
|
-
throw new Error(`Connection string not provided for database config with id ${config.id}`);
|
|
11
|
-
}
|
|
12
|
-
if (config.type === 'sql') {
|
|
13
|
-
const pool = new pg_1.Pool({ connectionString: config.connectionString });
|
|
14
|
-
await pool.connect();
|
|
15
|
-
clients[config.id] = pool;
|
|
16
|
-
}
|
|
17
|
-
else if (config.type === 'nosql') {
|
|
18
|
-
const client = new mongodb_1.MongoClient(config.connectionString);
|
|
19
|
-
await client.connect();
|
|
20
|
-
clients[config.id] = client;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
exports.initConnections = initConnections;
|
|
25
|
-
const getConnection = (id) => {
|
|
26
|
-
const client = clients[id];
|
|
27
|
-
if (!client) {
|
|
28
|
-
throw new Error(`Connection with id ${id} not found.`);
|
|
29
|
-
}
|
|
30
|
-
return client;
|
|
31
|
-
};
|
|
32
|
-
exports.getConnection = getConnection;
|
package/dist/database/index.d.ts
DELETED
package/dist/database/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./connectionManager"), exports);
|
|
18
|
-
__exportStar(require("./Model"), exports);
|
|
19
|
-
__exportStar(require("./modelRegistry"), exports);
|
package/dist/database/model.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface BaseModel {
|
|
2
|
-
id?: string;
|
|
3
|
-
}
|
|
4
|
-
export interface ModelDefinition<T extends BaseModel> {
|
|
5
|
-
name: string;
|
|
6
|
-
connectionName: string;
|
|
7
|
-
}
|
|
8
|
-
export interface QueryOptions {
|
|
9
|
-
filter?: Record<string, any>;
|
|
10
|
-
limit?: number;
|
|
11
|
-
offset?: number;
|
|
12
|
-
sort?: Record<string, 1 | -1>;
|
|
13
|
-
}
|
|
14
|
-
export interface ModelOperations<T extends BaseModel> {
|
|
15
|
-
find(options?: QueryOptions): Promise<T[]>;
|
|
16
|
-
findById(id: string): Promise<T | null>;
|
|
17
|
-
create(data: Omit<T, 'id'>): Promise<T>;
|
|
18
|
-
update(id: string, data: Partial<Omit<T, 'id'>>): Promise<T | null>;
|
|
19
|
-
delete(id: string): Promise<boolean>;
|
|
20
|
-
}
|
package/dist/database/model.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseModel, ModelDefinition, ModelOperations } from './model';
|
|
2
|
-
declare class ModelManager {
|
|
3
|
-
private models;
|
|
4
|
-
registerModel<T extends BaseModel>(definition: ModelDefinition<T>): void;
|
|
5
|
-
getModel<T extends BaseModel>(name: string): ModelOperations<T>;
|
|
6
|
-
}
|
|
7
|
-
export declare const modelManager: ModelManager;
|
|
8
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.modelManager = void 0;
|
|
4
|
-
const connectionManager_1 = require("./connectionManager");
|
|
5
|
-
const sqlAdapter_1 = require("./sqlAdapter");
|
|
6
|
-
const mongoAdapter_1 = require("./mongoAdapter");
|
|
7
|
-
const mongodb_1 = require("mongodb");
|
|
8
|
-
class ModelManager {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.models = new Map();
|
|
11
|
-
}
|
|
12
|
-
registerModel(definition) {
|
|
13
|
-
const client = connectionManager_1.connectionManager.getClient(definition.connectionName);
|
|
14
|
-
if (!client) {
|
|
15
|
-
throw new Error(`Connection '${definition.connectionName}' not found for model '${definition.name}'`);
|
|
16
|
-
}
|
|
17
|
-
let adapter;
|
|
18
|
-
if (client instanceof mongodb_1.Pool) {
|
|
19
|
-
adapter = new sqlAdapter_1.SqlAdapter(client, definition.name.toLowerCase() + 's'); // Assuming table name is plural of model name
|
|
20
|
-
}
|
|
21
|
-
else if (client instanceof mongodb_1.MongoClient) {
|
|
22
|
-
adapter = new mongoAdapter_1.MongoAdapter(client, definition.name.toLowerCase() + 's'); // Assuming collection name is plural of model name
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
throw new Error(`Unsupported client type for connection '${definition.connectionName}'`);
|
|
26
|
-
}
|
|
27
|
-
this.models.set(definition.name, adapter);
|
|
28
|
-
console.log(`Model '${definition.name}' registered with connection '${definition.connectionName}'`);
|
|
29
|
-
}
|
|
30
|
-
getModel(name) {
|
|
31
|
-
const model = this.models.get(name);
|
|
32
|
-
if (!model) {
|
|
33
|
-
throw new Error(`Model '${name}' not found. Make sure it is registered.`);
|
|
34
|
-
}
|
|
35
|
-
return model;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.modelManager = new ModelManager();
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getModel = exports.defineModel = void 0;
|
|
4
|
-
const Model_1 = require("./Model");
|
|
5
|
-
const models = {};
|
|
6
|
-
const defineModel = (name, connectionId, tableName) => {
|
|
7
|
-
models[name] = new Model_1.Model(connectionId, tableName);
|
|
8
|
-
};
|
|
9
|
-
exports.defineModel = defineModel;
|
|
10
|
-
const getModel = (name) => {
|
|
11
|
-
const model = models[name];
|
|
12
|
-
if (!model) {
|
|
13
|
-
throw new Error(`Model ${name} not defined.`);
|
|
14
|
-
}
|
|
15
|
-
return model;
|
|
16
|
-
};
|
|
17
|
-
exports.getModel = getModel;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { MongoClient } from 'mongodb';
|
|
2
|
-
import { BaseModel, ModelOperations, QueryOptions } from './model';
|
|
3
|
-
export declare class MongoAdapter<T extends BaseModel> implements ModelOperations<T> {
|
|
4
|
-
private collection;
|
|
5
|
-
constructor(client: MongoClient, collectionName: string);
|
|
6
|
-
find(options?: QueryOptions): Promise<T[]>;
|
|
7
|
-
findById(id: string): Promise<T | null>;
|
|
8
|
-
create(data: Omit<T, 'id'>): Promise<T>;
|
|
9
|
-
update(id: string, data: Partial<Omit<T, 'id'>>): Promise<T | null>;
|
|
10
|
-
delete(id: string): Promise<boolean>;
|
|
11
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MongoAdapter = void 0;
|
|
4
|
-
const mongodb_1 = require("mongodb");
|
|
5
|
-
class MongoAdapter {
|
|
6
|
-
constructor(client, collectionName) {
|
|
7
|
-
// Assuming a default database name for now, or it could be passed in config
|
|
8
|
-
const db = client.db();
|
|
9
|
-
this.collection = db.collection(collectionName);
|
|
10
|
-
}
|
|
11
|
-
async find(options) {
|
|
12
|
-
let cursor = this.collection.find(options?.filter || {});
|
|
13
|
-
if (options?.sort) {
|
|
14
|
-
cursor = cursor.sort(options.sort);
|
|
15
|
-
}
|
|
16
|
-
if (options?.limit) {
|
|
17
|
-
cursor = cursor.limit(options.limit);
|
|
18
|
-
}
|
|
19
|
-
if (options?.offset) {
|
|
20
|
-
cursor = cursor.skip(options.offset);
|
|
21
|
-
}
|
|
22
|
-
const result = await cursor.toArray();
|
|
23
|
-
return result.map(doc => ({ ...doc, id: doc._id?.toString() }));
|
|
24
|
-
}
|
|
25
|
-
async findById(id) {
|
|
26
|
-
const doc = await this.collection.findOne({ _id: new mongodb_1.ObjectId(id) });
|
|
27
|
-
return doc ? { ...doc, id: doc._id?.toString() } : null;
|
|
28
|
-
}
|
|
29
|
-
async create(data) {
|
|
30
|
-
const result = await this.collection.insertOne(data);
|
|
31
|
-
return { ...data, id: result.insertedId.toString() };
|
|
32
|
-
}
|
|
33
|
-
async update(id, data) {
|
|
34
|
-
const result = await this.collection.findOneAndUpdate({ _id: new mongodb_1.ObjectId(id) }, { $set: data }, { returnDocument: 'after' });
|
|
35
|
-
return result.value ? { ...result.value, id: result.value._id?.toString() } : null;
|
|
36
|
-
}
|
|
37
|
-
async delete(id) {
|
|
38
|
-
const result = await this.collection.deleteOne({ _id: new mongodb_1.ObjectId(id) });
|
|
39
|
-
return result.deletedCount > 0;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.MongoAdapter = MongoAdapter;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Pool } from 'pg';
|
|
2
|
-
import { BaseModel, ModelOperations, QueryOptions } from './model';
|
|
3
|
-
export declare class SqlAdapter<T extends BaseModel> implements ModelOperations<T> {
|
|
4
|
-
private client;
|
|
5
|
-
private tableName;
|
|
6
|
-
constructor(client: Pool, tableName: string);
|
|
7
|
-
find(options?: QueryOptions): Promise<T[]>;
|
|
8
|
-
findById(id: string): Promise<T | null>;
|
|
9
|
-
create(data: Omit<T, 'id'>): Promise<T>;
|
|
10
|
-
update(id: string, data: Partial<Omit<T, 'id'>>): Promise<T | null>;
|
|
11
|
-
delete(id: string): Promise<boolean>;
|
|
12
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SqlAdapter = void 0;
|
|
4
|
-
class SqlAdapter {
|
|
5
|
-
constructor(client, tableName) {
|
|
6
|
-
this.client = client;
|
|
7
|
-
this.tableName = tableName;
|
|
8
|
-
}
|
|
9
|
-
async find(options) {
|
|
10
|
-
let query = `SELECT * FROM ${this.tableName}`;
|
|
11
|
-
const values = [];
|
|
12
|
-
const conditions = [];
|
|
13
|
-
let paramIndex = 1;
|
|
14
|
-
if (options?.filter) {
|
|
15
|
-
for (const key in options.filter) {
|
|
16
|
-
conditions.push(`${key} = $${paramIndex++}`);
|
|
17
|
-
values.push(options.filter[key]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (conditions.length > 0) {
|
|
21
|
-
query += ` WHERE ${conditions.join(' AND ')}`;
|
|
22
|
-
}
|
|
23
|
-
if (options?.sort) {
|
|
24
|
-
const sortKeys = Object.keys(options.sort);
|
|
25
|
-
if (sortKeys.length > 0) {
|
|
26
|
-
const orderBy = sortKeys.map(key => `${key} ${options.sort[key] === 1 ? 'ASC' : 'DESC'}`).join(', ');
|
|
27
|
-
query += ` ORDER BY ${orderBy}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (options?.limit) {
|
|
31
|
-
query += ` LIMIT $${paramIndex++}`;
|
|
32
|
-
values.push(options.limit);
|
|
33
|
-
}
|
|
34
|
-
if (options?.offset) {
|
|
35
|
-
query += ` OFFSET $${paramIndex++}`;
|
|
36
|
-
values.push(options.offset);
|
|
37
|
-
}
|
|
38
|
-
const result = await this.client.query(query, values);
|
|
39
|
-
return result.rows;
|
|
40
|
-
}
|
|
41
|
-
async findById(id) {
|
|
42
|
-
const query = `SELECT * FROM ${this.tableName} WHERE id = $1`;
|
|
43
|
-
const result = await this.client.query(query, [id]);
|
|
44
|
-
return result.rows[0] || null;
|
|
45
|
-
}
|
|
46
|
-
async create(data) {
|
|
47
|
-
const keys = Object.keys(data);
|
|
48
|
-
const values = Object.values(data);
|
|
49
|
-
const placeholders = keys.map((_, i) => `$${i + 1}`).join(', ');
|
|
50
|
-
const query = `INSERT INTO ${this.tableName} (${keys.join(', ')}) VALUES (${placeholders}) RETURNING *`;
|
|
51
|
-
const result = await this.client.query(query, values);
|
|
52
|
-
return result.rows[0];
|
|
53
|
-
}
|
|
54
|
-
async update(id, data) {
|
|
55
|
-
const keys = Object.keys(data);
|
|
56
|
-
const values = Object.values(data);
|
|
57
|
-
const setClauses = keys.map((key, i) => `${key} = $${i + 1}`).join(', ');
|
|
58
|
-
const query = `UPDATE ${this.tableName} SET ${setClauses} WHERE id = $${keys.length + 1} RETURNING *`;
|
|
59
|
-
const result = await this.client.query(query, [...values, id]);
|
|
60
|
-
return result.rows[0] || null;
|
|
61
|
-
}
|
|
62
|
-
async delete(id) {
|
|
63
|
-
const query = `DELETE FROM ${this.tableName} WHERE id = $1`;
|
|
64
|
-
const result = await this.client.query(query, [id]);
|
|
65
|
-
return result.rowCount > 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.SqlAdapter = SqlAdapter;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getModel = exports.registerModel = void 0;
|
|
4
|
-
var registerModel_1 = require("./registerModel");
|
|
5
|
-
Object.defineProperty(exports, "registerModel", { enumerable: true, get: function () { return registerModel_1.registerModel; } });
|
|
6
|
-
var modelRegistry_1 = require("./modelRegistry");
|
|
7
|
-
Object.defineProperty(exports, "getModel", { enumerable: true, get: function () { return modelRegistry_1.getModel; } });
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getModel = exports.defineModel = void 0;
|
|
4
|
-
const Model_1 = require("./Model");
|
|
5
|
-
const models = {};
|
|
6
|
-
const defineModel = (name, connectionId, tableName) => {
|
|
7
|
-
models[name] = new Model_1.Model(connectionId, tableName);
|
|
8
|
-
};
|
|
9
|
-
exports.defineModel = defineModel;
|
|
10
|
-
const getModel = (name) => {
|
|
11
|
-
const model = models[name];
|
|
12
|
-
if (!model) {
|
|
13
|
-
throw new Error(`Model ${name} not defined.`);
|
|
14
|
-
}
|
|
15
|
-
return model;
|
|
16
|
-
};
|
|
17
|
-
exports.getModel = getModel;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const registerModel: (name: string, connectionId: string, tableName: string) => void;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerModel = void 0;
|
|
4
|
-
const modelRegistry_1 = require("./modelRegistry");
|
|
5
|
-
const registerModel = (name, connectionId, tableName) => {
|
|
6
|
-
(0, modelRegistry_1.defineModel)(name, connectionId, tableName);
|
|
7
|
-
};
|
|
8
|
-
exports.registerModel = registerModel;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStorageProvider = void 0;
|
|
4
|
-
const s3_1 = require("../adapters/storage/s3");
|
|
5
|
-
const createStorageProvider = (providers) => {
|
|
6
|
-
const s3Provider = providers.find(p => p.type === 's3');
|
|
7
|
-
if (s3Provider) {
|
|
8
|
-
return new s3_1.S3Adapter(s3Provider.config);
|
|
9
|
-
}
|
|
10
|
-
throw new Error('No storage provider configured.');
|
|
11
|
-
};
|
|
12
|
-
exports.createStorageProvider = createStorageProvider;
|