@rapidd/build 1.0.8 → 1.1.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 +12 -18
- package/package.json +1 -1
- package/src/commands/build.js +5 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Dynamic code generator that transforms Prisma schemas into complete Express.js C
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- 🚀 **Automatic CRUD API Generation** - Creates Express.js routes from Prisma models
|
|
8
|
-
- 🔒 **RLS Translation** - Converts PostgreSQL Row-Level Security policies to JavaScript/Prisma filters
|
|
8
|
+
- 🔒 **RLS Translation** - Converts PostgreSQL Row-Level Security policies to JavaScript/Prisma filters (ACL)
|
|
9
9
|
- 🎯 **Dynamic & Schema-Aware** - Zero hardcoding, adapts to any database structure
|
|
10
10
|
- 🔗 **Relationship Handling** - Supports 1:1, 1:n, n:m including junction tables
|
|
11
11
|
- 👥 **Role-Based Access Control** - Properly handles role checks in filters
|
|
@@ -34,7 +34,7 @@ npx rapidd build --model user
|
|
|
34
34
|
# Generate only specific component
|
|
35
35
|
npx rapidd build --only model
|
|
36
36
|
npx rapidd build --only route
|
|
37
|
-
npx rapidd build --only
|
|
37
|
+
npx rapidd build --only acl
|
|
38
38
|
npx rapidd build --only relationship
|
|
39
39
|
|
|
40
40
|
# Combine model and component filters
|
|
@@ -49,7 +49,7 @@ npx rapidd build --user-table accounts
|
|
|
49
49
|
- `-o, --output <path>` - Output directory (default: `./`)
|
|
50
50
|
- `-s, --schema <path>` - Prisma schema file (default: `./prisma/schema.prisma`)
|
|
51
51
|
- `-m, --model <name>` - Generate/update only specific model (e.g., "account", "user")
|
|
52
|
-
- `--only <component>` - Generate only specific component: "model", "route", "
|
|
52
|
+
- `--only <component>` - Generate only specific component: "model", "route", "acl", or "relationship"
|
|
53
53
|
- `--user-table <name>` - User table name for RLS (default: auto-detected)
|
|
54
54
|
|
|
55
55
|
## Selective Generation
|
|
@@ -65,7 +65,7 @@ This will:
|
|
|
65
65
|
- Generate/update `src/Model/Account.js`
|
|
66
66
|
- Generate/update `routes/api/v1/account.js`
|
|
67
67
|
- Update the `account` entry in `rapidd/relationships.json`
|
|
68
|
-
- Update the `account` entry in `rapidd/
|
|
68
|
+
- Update the `account` entry in `rapidd/acl.js`
|
|
69
69
|
|
|
70
70
|
### Update Single Component
|
|
71
71
|
|
|
@@ -73,8 +73,8 @@ This will:
|
|
|
73
73
|
# Regenerate all routes
|
|
74
74
|
npx rapidd build --only route
|
|
75
75
|
|
|
76
|
-
# Regenerate all
|
|
77
|
-
npx rapidd build --only
|
|
76
|
+
# Regenerate all ACL configs
|
|
77
|
+
npx rapidd build --only acl
|
|
78
78
|
|
|
79
79
|
# Regenerate all models
|
|
80
80
|
npx rapidd build --only model
|
|
@@ -89,8 +89,8 @@ npx rapidd build --only relationship
|
|
|
89
89
|
# Update only the route for a specific model
|
|
90
90
|
npx rapidd build --model user --only route
|
|
91
91
|
|
|
92
|
-
# Update
|
|
93
|
-
npx rapidd build --model account --only
|
|
92
|
+
# Update ACL for account model
|
|
93
|
+
npx rapidd build --model account --only acl
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
## Generated Structure
|
|
@@ -106,12 +106,12 @@ npx rapidd build --model account --only rls
|
|
|
106
106
|
│ ├── post.js
|
|
107
107
|
│ └── ...
|
|
108
108
|
└── rapidd/
|
|
109
|
-
├──
|
|
109
|
+
├── acl.js
|
|
110
110
|
├── relationships.json
|
|
111
111
|
└── rapidd.js
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
##
|
|
114
|
+
## ACL Translation Example
|
|
115
115
|
|
|
116
116
|
**PostgreSQL Policy:**
|
|
117
117
|
```sql
|
|
@@ -131,12 +131,6 @@ getAccessFilter: (user) => {
|
|
|
131
131
|
}
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
## Usage with PostgreSQL RLS
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb" npx rapidd build
|
|
138
|
-
```
|
|
139
|
-
|
|
140
134
|
## Use Cases
|
|
141
135
|
|
|
142
136
|
### During Development
|
|
@@ -148,7 +142,7 @@ npx rapidd build --model newModel
|
|
|
148
142
|
npx rapidd build --only relationship
|
|
149
143
|
|
|
150
144
|
# After updating RLS policies
|
|
151
|
-
npx rapidd build --only
|
|
145
|
+
npx rapidd build --only acl
|
|
152
146
|
```
|
|
153
147
|
|
|
154
148
|
### Continuous Integration
|
|
@@ -161,7 +155,7 @@ npx rapidd build --output ./generated
|
|
|
161
155
|
```bash
|
|
162
156
|
# Update specific model after schema changes
|
|
163
157
|
npx rapidd build --model user --only model
|
|
164
|
-
npx rapidd build --model user --only
|
|
158
|
+
npx rapidd build --model user --only acl
|
|
165
159
|
```
|
|
166
160
|
|
|
167
161
|
## License
|
package/package.json
CHANGED
package/src/commands/build.js
CHANGED
|
@@ -597,8 +597,13 @@ const prisma = new PrismaClient({
|
|
|
597
597
|
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
|
|
598
598
|
});
|
|
599
599
|
|
|
600
|
+
const prismaTransaction = async (operations) => prisma.$transaction(async (tx) => {
|
|
601
|
+
return Promise.all(operations.map(op => op(tx)));
|
|
602
|
+
});
|
|
603
|
+
|
|
600
604
|
module.exports = {
|
|
601
605
|
prisma,
|
|
606
|
+
prismaTransaction,
|
|
602
607
|
PrismaClient,
|
|
603
608
|
acl
|
|
604
609
|
};
|