streamby-core 0.16.1 → 0.16.2

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.
@@ -9,10 +9,12 @@ const file_1 = require("../services/file");
9
9
  const presign_1 = require("../services/presign");
10
10
  const createStorageProvider_1 = require("../providers/createStorageProvider");
11
11
  const createDatabaseProvider_1 = require("../providers/createDatabaseProvider");
12
+ const pushPrismaSchema_1 = require("../utils/pushPrismaSchema");
12
13
  function isProjectMember(project, userId) {
13
14
  return project.members?.some((m) => m.userId?.toString() === userId?.toString());
14
15
  }
15
16
  function createStreamByRouter(config) {
17
+ (0, pushPrismaSchema_1.pushPrismaSchema)();
16
18
  const router = express_1.default.Router();
17
19
  const adapter = config.adapter || (0, createStorageProvider_1.createStorageProvider)(config.storageProviders);
18
20
  const projectProviders = {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Executes `prisma db push` programmatically to sync the schema with the database.
3
+ * Ensures the command is only run once per application lifecycle.
4
+ */
5
+ export declare function pushPrismaSchema(): void;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pushPrismaSchema = pushPrismaSchema;
7
+ const child_process_1 = require("child_process");
8
+ const path_1 = __importDefault(require("path"));
9
+ let schemaPushed = false;
10
+ /**
11
+ * Executes `prisma db push` programmatically to sync the schema with the database.
12
+ * Ensures the command is only run once per application lifecycle.
13
+ */
14
+ function pushPrismaSchema() {
15
+ if (schemaPushed) {
16
+ console.log('[StreamBy] Prisma schema has already been pushed. Skipping.');
17
+ return;
18
+ }
19
+ try {
20
+ // Resolve the path to the schema.prisma file relative to the compiled JS file.
21
+ // __dirname will be /path/to/your/project/node_modules/streamby-core/dist/utils
22
+ const schemaPath = path_1.default.resolve(__dirname, '..', '..', 'prisma', 'schema.prisma');
23
+ console.log(`[StreamBy] Locating Prisma schema at: ${schemaPath}`);
24
+ console.log('[StreamBy] Pushing Prisma schema to the database...');
25
+ const command = `npx prisma db push --schema="${schemaPath}"`;
26
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
27
+ console.log('[StreamBy] Prisma schema pushed successfully.');
28
+ schemaPushed = true;
29
+ }
30
+ catch (error) {
31
+ console.error('[StreamBy] Failed to push Prisma schema:', error);
32
+ // Optional: decide if the application should exit on failure
33
+ // process.exit(1);
34
+ }
35
+ }
package/package.json CHANGED
@@ -1,56 +1,57 @@
1
- {
2
- "name": "streamby-core",
3
- "version": "0.16.1",
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
- "mongoose": "^8.13.2",
39
- "prisma": "^6.12.0"
40
- },
41
- "devDependencies": {
42
- "@types/bcrypt": "^5.0.2",
43
- "@types/cors": "^2.8.18",
44
- "@types/express": "^4.17.17",
45
- "@types/node": "^22.15.21",
46
- "@types/supertest": "^6.0.3",
47
- "cors": "^2.8.5",
48
- "supertest": "^7.1.0",
49
- "ts-node-dev": "^2.0.0",
50
- "typescript": "^5.8.3",
51
- "vitest": "^3.1.1"
52
- },
53
- "peerDependencies": {
54
- "express": "^4.0.0"
55
- }
56
- }
1
+ {
2
+ "name": "streamby-core",
3
+ "version": "0.16.2",
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
+ "prisma"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "vitest",
14
+ "dev": "ts-node-dev --respawn --clear dev.ts",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/GwerhDev/StreamBy-Package.git"
20
+ },
21
+ "keywords": [
22
+ "streamby",
23
+ "middleware",
24
+ "upload",
25
+ "storage",
26
+ "s3",
27
+ "express",
28
+ "typescript"
29
+ ],
30
+ "author": "TerminalCore Labs",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@aws-sdk/client-s3": "^3.528.0",
34
+ "@aws-sdk/s3-request-presigner": "^3.787.0",
35
+ "@prisma/client": "^6.12.0",
36
+ "bcrypt": "^5.1.1",
37
+ "dotenv": "^16.5.0",
38
+ "express": "^4.0.0",
39
+ "mongoose": "^8.13.2",
40
+ "prisma": "^6.12.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/bcrypt": "^5.0.2",
44
+ "@types/cors": "^2.8.18",
45
+ "@types/express": "^4.17.17",
46
+ "@types/node": "^22.15.21",
47
+ "@types/supertest": "^6.0.3",
48
+ "cors": "^2.8.5",
49
+ "supertest": "^7.1.0",
50
+ "ts-node-dev": "^2.0.0",
51
+ "typescript": "^5.8.3",
52
+ "vitest": "^3.1.1"
53
+ },
54
+ "peerDependencies": {
55
+ "express": "^4.0.0"
56
+ }
57
+ }
@@ -0,0 +1,90 @@
1
+ -- CreateTable
2
+ CREATE TABLE "streamby"."Project" (
3
+ "id" TEXT NOT NULL,
4
+ "dbType" TEXT NOT NULL,
5
+ "name" TEXT NOT NULL,
6
+ "description" TEXT,
7
+ "image" TEXT,
8
+ "allowUpload" BOOLEAN NOT NULL DEFAULT true,
9
+ "allowSharing" BOOLEAN NOT NULL DEFAULT false,
10
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
11
+ "updatedAt" TIMESTAMP(3) NOT NULL,
12
+
13
+ CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
14
+ );
15
+
16
+ -- CreateTable
17
+ CREATE TABLE "streamby"."FolderNode" (
18
+ "id" TEXT NOT NULL,
19
+ "name" TEXT NOT NULL,
20
+ "projectId" TEXT NOT NULL,
21
+ "parentId" TEXT,
22
+
23
+ CONSTRAINT "FolderNode_pkey" PRIMARY KEY ("id")
24
+ );
25
+
26
+ -- CreateTable
27
+ CREATE TABLE "streamby"."Member" (
28
+ "id" TEXT NOT NULL,
29
+ "userId" TEXT NOT NULL,
30
+ "role" TEXT NOT NULL,
31
+ "archived" BOOLEAN NOT NULL DEFAULT false,
32
+ "projectId" TEXT NOT NULL,
33
+
34
+ CONSTRAINT "Member_pkey" PRIMARY KEY ("id")
35
+ );
36
+
37
+ -- CreateTable
38
+ CREATE TABLE "streamby"."Export" (
39
+ "id" TEXT NOT NULL,
40
+ "name" TEXT NOT NULL,
41
+ "description" TEXT,
42
+ "collectionName" TEXT NOT NULL,
43
+ "projectId" TEXT NOT NULL,
44
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
45
+ "updatedAt" TIMESTAMP(3) NOT NULL,
46
+
47
+ CONSTRAINT "Export_pkey" PRIMARY KEY ("id")
48
+ );
49
+
50
+ -- CreateTable
51
+ CREATE TABLE "streamby"."ExportCollection" (
52
+ "id" TEXT NOT NULL,
53
+ "projectId" TEXT NOT NULL,
54
+ "name" TEXT NOT NULL,
55
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
56
+ "updatedAt" TIMESTAMP(3) NOT NULL,
57
+
58
+ CONSTRAINT "ExportCollection_pkey" PRIMARY KEY ("id")
59
+ );
60
+
61
+ -- CreateTable
62
+ CREATE TABLE "streamby"."ExportEntry" (
63
+ "id" TEXT NOT NULL,
64
+ "key" TEXT NOT NULL,
65
+ "value" TEXT NOT NULL,
66
+ "exportCollectionId" TEXT NOT NULL,
67
+
68
+ CONSTRAINT "ExportEntry_pkey" PRIMARY KEY ("id")
69
+ );
70
+
71
+ -- CreateIndex
72
+ CREATE UNIQUE INDEX "ExportCollection_projectId_name_key" ON "streamby"."ExportCollection"("projectId", "name");
73
+
74
+ -- AddForeignKey
75
+ ALTER TABLE "streamby"."FolderNode" ADD CONSTRAINT "FolderNode_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "streamby"."Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
76
+
77
+ -- AddForeignKey
78
+ ALTER TABLE "streamby"."FolderNode" ADD CONSTRAINT "FolderNode_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "streamby"."FolderNode"("id") ON DELETE SET NULL ON UPDATE CASCADE;
79
+
80
+ -- AddForeignKey
81
+ ALTER TABLE "streamby"."Member" ADD CONSTRAINT "Member_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "streamby"."Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
82
+
83
+ -- AddForeignKey
84
+ ALTER TABLE "streamby"."Export" ADD CONSTRAINT "Export_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "streamby"."Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
85
+
86
+ -- AddForeignKey
87
+ ALTER TABLE "streamby"."ExportCollection" ADD CONSTRAINT "ExportCollection_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "streamby"."Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
88
+
89
+ -- AddForeignKey
90
+ ALTER TABLE "streamby"."ExportEntry" ADD CONSTRAINT "ExportEntry_exportCollectionId_fkey" FOREIGN KEY ("exportCollectionId") REFERENCES "streamby"."ExportCollection"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
1
+ # Please do not edit this file manually
2
+ # It should be added in your version-control system (e.g., Git)
3
+ provider = "postgresql"
@@ -0,0 +1,87 @@
1
+ datasource db {
2
+ provider = "postgresql"
3
+ url = env("PRISMA_STRING")
4
+ schemas = ["streamby"]
5
+ }
6
+
7
+ generator client {
8
+ provider = "prisma-client-js"
9
+ previewFeatures = ["multiSchema"]
10
+ }
11
+
12
+ model Project {
13
+ id String @id @default(uuid())
14
+ dbType String
15
+ name String
16
+ description String?
17
+ image String?
18
+ allowUpload Boolean @default(true)
19
+ allowSharing Boolean @default(false)
20
+ createdAt DateTime @default(now())
21
+ updatedAt DateTime @updatedAt
22
+ folders FolderNode[]
23
+ members Member[]
24
+ exports Export[]
25
+ exportCollections ExportCollection[]
26
+
27
+ @@schema("streamby")
28
+ }
29
+
30
+ model FolderNode {
31
+ id String @id @default(uuid())
32
+ name String
33
+ projectId String
34
+ parentId String?
35
+ project Project @relation(fields: [projectId], references: [id])
36
+ parent FolderNode? @relation("FolderChildren", fields: [parentId], references: [id])
37
+ children FolderNode[] @relation("FolderChildren")
38
+
39
+ @@schema("streamby")
40
+ }
41
+
42
+ model Member {
43
+ id String @id @default(uuid())
44
+ userId String
45
+ role String
46
+ archived Boolean @default(false)
47
+ projectId String
48
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
49
+
50
+ @@schema("streamby")
51
+ }
52
+
53
+ model Export {
54
+ id String @id @default(uuid())
55
+ name String
56
+ description String?
57
+ collectionName String
58
+ projectId String
59
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
60
+ createdAt DateTime @default(now())
61
+ updatedAt DateTime @updatedAt
62
+
63
+ @@schema("streamby")
64
+ }
65
+
66
+ model ExportCollection {
67
+ id String @id @default(uuid())
68
+ projectId String
69
+ name String
70
+ createdAt DateTime @default(now())
71
+ updatedAt DateTime @updatedAt
72
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
73
+ entries ExportEntry[]
74
+
75
+ @@unique([projectId, name])
76
+ @@schema("streamby")
77
+ }
78
+
79
+ model ExportEntry {
80
+ id String @id @default(uuid())
81
+ key String
82
+ value String
83
+ exportCollectionId String
84
+ exportCollection ExportCollection @relation(fields: [exportCollectionId], references: [id])
85
+
86
+ @@schema("streamby")
87
+ }