lapeeh 1.0.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/.env.example +14 -0
- package/LICENSE +21 -0
- package/bin/index.js +934 -0
- package/doc/en/ARCHITECTURE_GUIDE.md +79 -0
- package/doc/en/CHANGELOG.md +203 -0
- package/doc/en/CHEATSHEET.md +90 -0
- package/doc/en/CLI.md +111 -0
- package/doc/en/CONTRIBUTING.md +119 -0
- package/doc/en/DEPLOYMENT.md +171 -0
- package/doc/en/FAQ.md +69 -0
- package/doc/en/FEATURES.md +99 -0
- package/doc/en/GETTING_STARTED.md +84 -0
- package/doc/en/INTRODUCTION.md +62 -0
- package/doc/en/PACKAGES.md +63 -0
- package/doc/en/PERFORMANCE.md +98 -0
- package/doc/en/ROADMAP.md +104 -0
- package/doc/en/SECURITY.md +95 -0
- package/doc/en/STRUCTURE.md +79 -0
- package/doc/en/TUTORIAL.md +145 -0
- package/doc/id/ARCHITECTURE_GUIDE.md +76 -0
- package/doc/id/CHANGELOG.md +203 -0
- package/doc/id/CHEATSHEET.md +90 -0
- package/doc/id/CLI.md +139 -0
- package/doc/id/CONTRIBUTING.md +119 -0
- package/doc/id/DEPLOYMENT.md +171 -0
- package/doc/id/FAQ.md +69 -0
- package/doc/id/FEATURES.md +169 -0
- package/doc/id/GETTING_STARTED.md +91 -0
- package/doc/id/INTRODUCTION.md +62 -0
- package/doc/id/PACKAGES.md +63 -0
- package/doc/id/PERFORMANCE.md +100 -0
- package/doc/id/ROADMAP.md +107 -0
- package/doc/id/SECURITY.md +94 -0
- package/doc/id/STRUCTURE.md +79 -0
- package/doc/id/TUTORIAL.md +145 -0
- package/docker-compose.yml +24 -0
- package/ecosystem.config.js +17 -0
- package/eslint.config.mjs +26 -0
- package/gitignore.template +30 -0
- package/lib/bootstrap.ts +210 -0
- package/lib/core/realtime.ts +34 -0
- package/lib/core/redis.ts +139 -0
- package/lib/core/serializer.ts +63 -0
- package/lib/core/server.ts +70 -0
- package/lib/core/store.ts +116 -0
- package/lib/middleware/auth.ts +63 -0
- package/lib/middleware/error.ts +50 -0
- package/lib/middleware/multipart.ts +13 -0
- package/lib/middleware/rateLimit.ts +14 -0
- package/lib/middleware/requestLogger.ts +27 -0
- package/lib/middleware/visitor.ts +178 -0
- package/lib/utils/logger.ts +100 -0
- package/lib/utils/pagination.ts +56 -0
- package/lib/utils/response.ts +88 -0
- package/lib/utils/validator.ts +394 -0
- package/nodemon.json +6 -0
- package/package.json +126 -0
- package/readme.md +357 -0
- package/scripts/check-update.js +92 -0
- package/scripts/config-clear.js +45 -0
- package/scripts/generate-jwt-secret.js +38 -0
- package/scripts/init-project.js +84 -0
- package/scripts/make-module.js +89 -0
- package/scripts/release.js +494 -0
- package/scripts/seed-json.js +158 -0
- package/scripts/verify-rbac-functional.js +187 -0
- package/src/config/app.ts +9 -0
- package/src/config/cors.ts +5 -0
- package/src/modules/Auth/auth.controller.ts +519 -0
- package/src/modules/Rbac/rbac.controller.ts +533 -0
- package/src/routes/auth.ts +74 -0
- package/src/routes/index.ts +7 -0
- package/src/routes/rbac.ts +42 -0
- package/storage/logs/.gitkeep +0 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Panduan Arsitektur: Menuju "Framework as a Dependency" (Next.js Style)
|
|
2
|
+
|
|
3
|
+
Saat ini, lapeeh menggunakan pendekatan **Boilerplate** (seperti Laravel), di mana pengguna mendapatkan seluruh kode sumber (`src/`) dan bertanggung jawab atas `express`, `driver database`, dll.
|
|
4
|
+
|
|
5
|
+
Untuk mengubahnya menjadi seperti **Next.js** (di mana pengguna hanya menginstall `lapeeh` dan `package.json` mereka bersih), kita perlu mengubah arsitektur menjadi **Library**.
|
|
6
|
+
|
|
7
|
+
## 1. Perbedaan Utama
|
|
8
|
+
|
|
9
|
+
| Fitur | Boilerplate (lapeeh Saat Ini) | Library (Next.js Style) |
|
|
10
|
+
| :--------------- | :----------------------------------------- | :----------------------------------- |
|
|
11
|
+
| **Instalasi** | `git clone` / `npx create-lapeeh` | `npm install lapeeh` |
|
|
12
|
+
| **package.json** | Banyak dependency (`express`, `cors`, dll) | Sedikit (`lapeeh`, `react`) |
|
|
13
|
+
| **Scripts** | Panjang (`nodemon src/index.ts`) | Pendek (`lapeeh dev`) |
|
|
14
|
+
| **Core Code** | Terbuka di `src/core/` | Tersembunyi di `node_modules/lapeeh` |
|
|
15
|
+
| **Update** | Susah (harus merge manual) | Mudah (`npm update lapeeh`) |
|
|
16
|
+
|
|
17
|
+
## 2. Langkah Implementasi
|
|
18
|
+
|
|
19
|
+
Saya telah memulai langkah pertama dengan menambahkan **CLI Runner** di `bin/index.js`.
|
|
20
|
+
|
|
21
|
+
### A. Update CLI (`bin/index.js`) ✅ (Sudah Dilakukan)
|
|
22
|
+
|
|
23
|
+
Saya sudah menambahkan command `dev`, `start`, dan `build` ke dalam CLI lapeeh. Ini memungkinkan pengguna menjalankan server tanpa tahu perintah aslinya.
|
|
24
|
+
I have added `dev`, `start`, and `build` commands to the Lapeeh CLI. This allows users to run the server without knowing the underlying commands.
|
|
25
|
+
|
|
26
|
+
// Contoh penggunaan nanti:
|
|
27
|
+
// Example usage later:
|
|
28
|
+
"dev": "lapeeh dev",
|
|
29
|
+
"build": "lapeeh build",
|
|
30
|
+
"start": "lapeeh start"
|
|
31
|
+
"start": "lapeeh start"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
````
|
|
35
|
+
### B. Struktur Project Pengguna (Target)
|
|
36
|
+
Nantinya, project pengguna lapeeh hanya akan berisi file bisnis mereka:
|
|
37
|
+
|
|
38
|
+
Eventually, the Lapeeh user project will only contain their business files:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
my-app/
|
|
42
|
+
├── src/
|
|
43
|
+
│ ├── controllers/
|
|
44
|
+
├── lapeeh.config.ts <-- Konfigurasi framework (pengganti edit core)
|
|
45
|
+
│ └── models/
|
|
46
|
+
├── lapeeh.config.ts <-- Framework configuration (replaces core edits)
|
|
47
|
+
└── package.json
|
|
48
|
+
Dan `package.json` mereka akan terlihat seperti ini:
|
|
49
|
+
|
|
50
|
+
And their `package.json` will look like this:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"lapeeh": "^2.0.0"
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@lapeeh/lapeeh": "^2.0.0"
|
|
57
|
+
"dev": "lapeeh dev",
|
|
58
|
+
"build": "lapeeh build",
|
|
59
|
+
"start": "lapeeh start"
|
|
60
|
+
"build": "lapeeh build",
|
|
61
|
+
"start": "lapeeh start"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
### C. Apa yang Harus Dilakukan Selanjutnya?
|
|
65
|
+
|
|
66
|
+
1. **Publish Package**: Anda perlu mempublish folder framework ini ke NPM (atau private registry).
|
|
67
|
+
* Pastikan `express`, `cors`, `helmet`, dll ada di `dependencies` (bukan `devDependencies`).
|
|
68
|
+
2. **Abstraksi `src/index.ts`**:
|
|
69
|
+
* Saat ini `src/index.ts` adalah entry point yang diedit user.
|
|
70
|
+
* Ubah agar `lapeeh dev` menjalankan server internal yang **mengimpor** routes/controller user secara dinamis (seperti Next.js pages router).
|
|
71
|
+
- Currently `src/index.ts` is the entry point edited by the user.
|
|
72
|
+
* Buat sistem pembacaan `lapeeh.config.ts` untuk mengatur Port, Database URL, dll tanpa mengedit kode core.
|
|
73
|
+
3. **Config Loader**:
|
|
74
|
+
## 3. Kesimpulan
|
|
75
|
+
Perubahan yang saya lakukan di `bin/index.js` adalah fondasi untuk CLI style. Untuk mencapai "Clean package.json" sepenuhnya, Anda harus memisahkan **Framework Core** (repo ini) dengan **User Project** (repo baru yang menginstall framework ini).
|
|
76
|
+
## 3. Conclusion
|
|
77
|
+
|
|
78
|
+
The changes I made in `bin/index.js` are the foundation for the CLI style. To achieve "Clean package.json" fully, you must separate **Framework Core** (this repo) with **User Project** (new repo installing this framework).
|
|
79
|
+
````
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Dokumentasi Perubahan lapeeh Framework
|
|
2
|
+
|
|
3
|
+
File ini mencatat semua perubahan, pembaruan, dan perbaikan yang dilakukan pada framework lapeeh, diurutkan berdasarkan tanggal.
|
|
4
|
+
|
|
5
|
+
## [2025-12-30] - Tuesday, December 30, 2025 - Smart Blog Automation (v3.0.8)
|
|
6
|
+
|
|
7
|
+
### 🤖 Release Script Improvements
|
|
8
|
+
|
|
9
|
+
- **Smart Blog Generation**: The `release.js` script now intelligently reads content from `CHANGELOG.md` (both ID and EN) to generate release blog posts. No more generic "Routine maintenance" content!
|
|
10
|
+
- **Flexible Version Detection**: Improved Regex to detect versions in various changelog header formats.
|
|
11
|
+
- **Bilingual Support**: Ensures release notes are accurately available in both Indonesian and English.
|
|
12
|
+
|
|
13
|
+
## [2025-12-30] - Tuesday, December 30, 2025 - Documentation & CLI (v3.0.7)
|
|
14
|
+
|
|
15
|
+
### 📚 Documentation
|
|
16
|
+
|
|
17
|
+
- **Project Structure Guide**: Comprehensive update to `STRUCTURE.md` to accurately reflect the No-ORM architecture and Core folder separation.
|
|
18
|
+
- **Scripts Documentation**: Added detailed explanation for `release.js` and `make-module.js` automation scripts.
|
|
19
|
+
|
|
20
|
+
### 🛠️ CLI Improvements
|
|
21
|
+
|
|
22
|
+
- **Cleanup**: Improved `init` and `upgrade` commands to better handle legacy configuration files.
|
|
23
|
+
|
|
24
|
+
## [2025-12-30] - Tuesday, December 30, 2025 - Major Release v3.0.0 (No-ORM)
|
|
25
|
+
|
|
26
|
+
### ⚠️ Breaking Changes
|
|
27
|
+
|
|
28
|
+
- **Prisma ORM Removal**: lapeeh Framework now **no longer includes a built-in ORM**. We provide full freedom for users to choose their own database stack (TypeORM, Drizzle, etc).
|
|
29
|
+
- **CLI Updates**:
|
|
30
|
+
- `init`: No longer asks for database configuration.
|
|
31
|
+
- `make:module`: No longer creates `.model.ts` files instead of `.prisma`.
|
|
32
|
+
- Removed `compile-schema.js` script and related schema splitting logic.
|
|
33
|
+
|
|
34
|
+
### 🚀 Features & Refactor
|
|
35
|
+
|
|
36
|
+
- **In-Memory Mock Data**: Built-in modules (Auth, RBAC, Pets) now use in-memory dummy data for demonstration without database setup.
|
|
37
|
+
- **Redis Caching**: Redis caching implementation on Pets controller.
|
|
38
|
+
- **Documentation**: Comprehensive update to documentation to reflect database agnostic philosophy.
|
|
39
|
+
|
|
40
|
+
## ⚠️ Deprecated Versions
|
|
41
|
+
|
|
42
|
+
Starting from release v3.0.0, all previous versions (v1.x and v2.x) are considered **DEPRECATED**. There will be no further feature updates or bug fixes for these versions unless for critical security issues. Users are strongly advised to migrate to v3.0.0.
|
|
43
|
+
|
|
44
|
+
## [2025-12-29] - Monday, December 29, 2025 - CLI Init Bug Fix (v2.6.7)
|
|
45
|
+
|
|
46
|
+
### 🛠️ Bug Fixes
|
|
47
|
+
|
|
48
|
+
- **CLI `init` Command**:
|
|
49
|
+
- **Prisma Client Generation**: Fixed `MODULE_NOT_FOUND` error for `.prisma/client/default` during seeding by forcing `npx prisma generate` before the seed process.
|
|
50
|
+
- **Project Name Parsing**: Fixed a critical bug where running `npx lapeeh init <project-name>` would incorrectly interpret `init` as the project name.
|
|
51
|
+
- **Dependency Management**: Reverted to **Prisma v6** (`^6.0.0`) and removed `prisma.config.ts` to resolve `PrismaClientConstructorValidationError` ("engine type client" error) on Windows environments. This restores standard `schema.prisma` configuration with `url = env("DATABASE_URL")`.
|
|
52
|
+
- **Peer Dependencies**: Removed `peerDependencies` from generated projects to prevent package manager conflicts.
|
|
53
|
+
|
|
54
|
+
## [2025-12-29] - Monday, December 29, 2025 - Upgrade CLI Improvements & MongoDB Support (v2.6.6)
|
|
55
|
+
|
|
56
|
+
### 🚀 Features & Improvements
|
|
57
|
+
|
|
58
|
+
- **Enhanced CLI `upgrade` Command**:
|
|
59
|
+
|
|
60
|
+
- The `upgrade` command now intelligently detects and preserves local `file:` dependencies in `package.json`. This is critical for framework contributors and local testing, ensuring that upgrading doesn't overwrite local links with npm versions.
|
|
61
|
+
- Standard users will still receive the latest npm version updates automatically.
|
|
62
|
+
|
|
63
|
+
- **MongoDB & Prisma Compatibility**:
|
|
64
|
+
|
|
65
|
+
- **BigInt Fixes**: Resolved serialization issues where `BigInt` IDs (common in SQL) caused crashes in MongoDB environments. All IDs in `auth` and `rbac` controllers now safely convert to `String` before response.
|
|
66
|
+
- **RBAC Schema**: Added missing RBAC models (`roles`, `permissions`, `user_roles`, `role_permissions`) to the core `prisma/schema.prisma` generation pipeline. This ensures `npx prisma generate` works flawlessly without manual schema adjustments.
|
|
67
|
+
|
|
68
|
+
- **CLI Initialization Flags**:
|
|
69
|
+
- Added new flags to `npx lapeeh init` for faster setup:
|
|
70
|
+
- `--full`: Sets up a complete project with dummy data (users/roles).
|
|
71
|
+
- `--default` (or `--y`): Skips interactive prompts and uses default settings (PostgreSQL).
|
|
72
|
+
|
|
73
|
+
## [2025-12-28] - Sunday, December 28, 2025 - Multi-Database & Cleanup (v2.4.10)
|
|
74
|
+
|
|
75
|
+
### 🚀 Features & Improvements
|
|
76
|
+
|
|
77
|
+
- **Multi-Database Support (CLI)**:
|
|
78
|
+
|
|
79
|
+
- Added full support for project initialization with **MongoDB** and **MySQL**, alongside **PostgreSQL**.
|
|
80
|
+
- Fixed database provider replacement logic in `schema.prisma` templates for better accuracy.
|
|
81
|
+
- Added `--db-type=mongo|pgsql|mysql` CLI argument for zero-interaction automated installation.
|
|
82
|
+
- Handled MongoDB migration differences by conditionally using `prisma db push`.
|
|
83
|
+
|
|
84
|
+
- **Package Cleanup**:
|
|
85
|
+
|
|
86
|
+
- Removed unnecessary development files/folders (`test-local-run`, `init`, `framework.md`, etc.) from the public NPM package.
|
|
87
|
+
- Explicitly added the `LICENSE` (MIT) file to the package.
|
|
88
|
+
- Ensured `dist` folder is cleanly regenerated during publication.
|
|
89
|
+
|
|
90
|
+
- **Documentation & Website**:
|
|
91
|
+
- Added basic admin dashboard structure to the website documentation.
|
|
92
|
+
- Added local telemetry API simulation script for website development.
|
|
93
|
+
|
|
94
|
+
## [2025-12-28] - Sunday, December 28, 2025 - Upgrade & Testing Improvements (v2.4.9)
|
|
95
|
+
|
|
96
|
+
### 🚀 Features & Fixes
|
|
97
|
+
|
|
98
|
+
- **Smart Upgrade CLI**:
|
|
99
|
+
|
|
100
|
+
- Updated `npx lapeeh upgrade` to perform full synchronization (mirroring).
|
|
101
|
+
- Files removed in the latest framework version are now automatically removed from user projects, keeping them clean.
|
|
102
|
+
- Removed `bin` folder from synchronization as it is managed by the package.
|
|
103
|
+
|
|
104
|
+
- **Comprehensive Testing Support**:
|
|
105
|
+
- Updated `tsconfig.json` to support `@lapeeh/*` path aliases within the `tests` folder.
|
|
106
|
+
- The `tests` folder is now excluded from production builds (via `tsconfig.build.json`), resulting in a cleaner `dist/` folder.
|
|
107
|
+
- Jest documentation and configuration have been adjusted for seamless integration.
|
|
108
|
+
|
|
109
|
+
## [2025-12-28] - Minggu, 28 Desember 2025 - Perbaikan Kompatibilitas & Automasi
|
|
110
|
+
|
|
111
|
+
### 🛠️ Perbaikan Bug (Bug Fixes)
|
|
112
|
+
|
|
113
|
+
- **Linux/Mac Path Compatibility (v2.4.1)**:
|
|
114
|
+
|
|
115
|
+
- Memperbaiki masalah `MODULE_NOT_FOUND` pada sistem operasi Linux dan macOS ketika path proyek mengandung spasi (misalnya: `/Folder Saya/Proyek lapeeh`).
|
|
116
|
+
- Mengubah logika escaping argumen pada `nodemon` di `bin/index.js` agar menggunakan _single quotes_ pada sistem berbasis Unix.
|
|
117
|
+
|
|
118
|
+
- **Auto Prisma Generate (v2.4.2)**:
|
|
119
|
+
|
|
120
|
+
- Memperbaiki error `Cannot find module '.prisma/client/default'` yang sering muncul setelah instalasi bersih.
|
|
121
|
+
- Menambahkan eksekusi otomatis `npx prisma generate` saat menjalankan perintah `npm run dev` dan `npm run build`.
|
|
122
|
+
- Memastikan Prisma Client selalu tersedia sebelum server berjalan, meningkatkan pengalaman pengguna baru.
|
|
123
|
+
|
|
124
|
+
- **PM2 Ecosystem Config (v2.4.4)**:
|
|
125
|
+
- Menambahkan file `ecosystem.config.js` secara otomatis ke dalam proyek baru dan proyek yang di-upgrade.
|
|
126
|
+
- File ini berisi konfigurasi siap pakai untuk menjalankan aplikasi dalam mode **Cluster** (load balancing) di production menggunakan PM2.
|
|
127
|
+
- Memperbarui dokumentasi `doc/DEPLOYMENT.md` dengan instruksi penggunaan PM2 yang baru.
|
|
128
|
+
|
|
129
|
+
## [2025-12-27] - Code Quality & Standardization Update
|
|
130
|
+
|
|
131
|
+
### 🚀 Fitur & Standarisasi
|
|
132
|
+
|
|
133
|
+
- **Standardized Import Paths**:
|
|
134
|
+
- Implementasi path alias `@/` untuk import yang lebih bersih (e.g., `import { prisma } from "@/core/database"`).
|
|
135
|
+
- Penghapusan penggunaan relative paths yang dalam (`../../../`).
|
|
136
|
+
- Konfigurasi `tsconfig.json` tanpa `baseUrl` (mengikuti standar TypeScript 6.0+).
|
|
137
|
+
- **Strict Linting & Code Quality**:
|
|
138
|
+
- Implementasi aturan **ESLint** ketat untuk mencegah "Dead Code".
|
|
139
|
+
- Error otomatis untuk variabel, parameter, dan import yang tidak digunakan (`no-unused-vars`).
|
|
140
|
+
- Script `npm run lint` dan `npm run lint:fix` untuk pembersihan kode otomatis.
|
|
141
|
+
- **Fastify-Style Standardization**:
|
|
142
|
+
- Penerapan standar respon cepat (`sendFastSuccess`) di seluruh controller (`AuthController`, `RbacController`, `PetController`).
|
|
143
|
+
- Penggunaan **Schema-based Serialization** untuk performa JSON maksimal.
|
|
144
|
+
- Konversi otomatis `BigInt` ke `string` dalam respon JSON.
|
|
145
|
+
|
|
146
|
+
## [2025-12-27] - High Performance & Scalability Update
|
|
147
|
+
|
|
148
|
+
### 🚀 Fitur Baru
|
|
149
|
+
|
|
150
|
+
- **High Performance Serialization (Fastify-Style)**:
|
|
151
|
+
- Implementasi `fast-json-stringify` untuk serialisasi JSON super cepat (2x-3x lebih cepat dari `JSON.stringify`).
|
|
152
|
+
- Helper `sendFastSuccess` di `src/utils/response.ts` untuk mem-bypass overhead Express.
|
|
153
|
+
- Caching schema serializer otomatis di `src/core/serializer.ts`.
|
|
154
|
+
- **Scalability & Clustering**:
|
|
155
|
+
- Dukungan **Load Balancing** dengan Nginx.
|
|
156
|
+
- Dukungan **Redis Clustering** untuk Rate Limiter (`rate-limit-redis`).
|
|
157
|
+
- File konfigurasi `docker-compose.cluster.yml` untuk simulasi cluster lokal (1 Nginx + 2 App Instances + 1 Redis).
|
|
158
|
+
- **Smart Error Handling**:
|
|
159
|
+
- Deteksi otomatis port bentrok (`EADDRINUSE`) saat startup.
|
|
160
|
+
- Memberikan saran command _copy-paste_ untuk mematikan process yang memblokir port (support Windows, Mac, Linux).
|
|
161
|
+
- **SEO Optimization**:
|
|
162
|
+
- Update metadata `package.json` dan `README.md` agar framework lebih mudah ditemukan di Google/NPM.
|
|
163
|
+
|
|
164
|
+
## [2025-12-27] - Pembaruan Struktur & Validasi
|
|
165
|
+
|
|
166
|
+
### 🚀 Fitur Baru
|
|
167
|
+
|
|
168
|
+
- **Expressive Validator**:
|
|
169
|
+
- Implementasi utility `Validator` baru di `src/utils/validator.ts` dengan gaya validasi yang lebih ekspresif.
|
|
170
|
+
- Mendukung rule string seperti `required|string|min:3|email`.
|
|
171
|
+
- Penambahan rule `unique` untuk pengecekan database otomatis (Prisma).
|
|
172
|
+
- Penambahan rule `mimes`, `image`, `max` (file size) untuk validasi upload file.
|
|
173
|
+
- Penambahan rule `sometimes` untuk field opsional.
|
|
174
|
+
- **Framework Hardening (Keamanan & Stabilitas)**:
|
|
175
|
+
- **Rate Limiting**: Middleware anti-spam/brute-force di `src/middleware/rateLimit.ts`.
|
|
176
|
+
- **Request Logger**: Pencatatan log request masuk di `src/middleware/requestLogger.ts`.
|
|
177
|
+
- **Health Check**: Endpoint `/` kini mengembalikan status kesehatan server.
|
|
178
|
+
- **Graceful Shutdown**: Penanganan penutupan koneksi Database dan Redis yang aman saat server berhenti (`SIGTERM`/`SIGINT`).
|
|
179
|
+
- **Environment Validation**: Validasi variabel `.env` wajib (seperti `DATABASE_URL`, `JWT_SECRET`) saat startup.
|
|
180
|
+
- **Struktur Folder Baru**:
|
|
181
|
+
- Pemisahan konfigurasi inti ke `src/core/` (`server.ts`, `database.ts`, `redis.ts`, `realtime.ts`) agar folder `src` lebih bersih.
|
|
182
|
+
- Sentralisasi route di `src/routes/index.ts` (WIP).
|
|
183
|
+
- **CLI Improvements**:
|
|
184
|
+
- `npx lapeeh <project-name> --full` kini otomatis menjalankan server dev setelah instalasi selesai, sehingga user bisa langsung melihat hasil tanpa mengetik perintah tambahan.
|
|
185
|
+
|
|
186
|
+
### 🛠️ Perbaikan & Refactoring
|
|
187
|
+
|
|
188
|
+
- **Controller Refactoring**:
|
|
189
|
+
- `AuthController`: Migrasi ke `Validator` baru, termasuk validasi upload avatar.
|
|
190
|
+
- `PetController`: Migrasi ke `Validator` baru.
|
|
191
|
+
- `RbacController`: Migrasi sebagian ke `Validator` baru.
|
|
192
|
+
- **Pembersihan**:
|
|
193
|
+
- Penghapusan folder `src/schema/` (Zod schema lama) karena sudah digantikan oleh `Validator` utility.
|
|
194
|
+
- Penghapusan file duplikat/lama di root `src/` setelah migrasi ke `src/core/`.
|
|
195
|
+
|
|
196
|
+
### 📝 Catatan Teknis
|
|
197
|
+
|
|
198
|
+
- **Validator Async**: Method `fails()`, `passes()`, dan `validated()` kini bersifat `async` untuk mendukung pengecekan database (`unique`).
|
|
199
|
+
- **Type Safety**: Semua perubahan telah diverifikasi dengan `npm run typecheck`.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
- CLI Tools for rapid development.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# lapeeh Framework Cheatsheet
|
|
2
|
+
|
|
3
|
+
Referensi cepat untuk perintah dan kode yang sering digunakan.
|
|
4
|
+
|
|
5
|
+
## 💻 CLI Commands
|
|
6
|
+
|
|
7
|
+
| Perintah | Fungsi |
|
|
8
|
+
| :----------------------------------- | :------------------------------------------- |
|
|
9
|
+
| **`npm run dev`** | Menjalankan server development (hot-reload). |
|
|
10
|
+
| **`npm run typecheck`** | Cek error TypeScript (tanpa compile). |
|
|
11
|
+
| **`npm run lint`** | Cek kode kotor/variabel tidak terpakai. |
|
|
12
|
+
| **`npm run lint:fix`** | Perbaiki kode kotor otomatis. |
|
|
13
|
+
| **`npm run make:module <Name>`** | Create Controller, Route, & Model. |
|
|
14
|
+
| **`npm run make:controller <Name>`** | Create Controller only. |
|
|
15
|
+
| **`npm run db:seed`** | Seed dummy data. |
|
|
16
|
+
|
|
17
|
+
## 🛡️ Validator Rules (Simple Syntax)
|
|
18
|
+
|
|
19
|
+
Gunakan di `Validator.make(data, rules)`.
|
|
20
|
+
|
|
21
|
+
| Rule | Deskripsi | Contoh |
|
|
22
|
+
| :----------------- | :---------------------- | :---------------------------------- | -------- |
|
|
23
|
+
| `required` | Wajib ada & tidak null. | `"required"` |
|
|
24
|
+
| `string` | Harus text. | `"required | string"` |
|
|
25
|
+
| `number` | Harus angka. | `"required | number"` |
|
|
26
|
+
| `email` | Format email valid. | `"required | email"` |
|
|
27
|
+
| `min:X` | Min panjang/nilai. | `"min:8"` (pass), `"min:18"` (umur) |
|
|
28
|
+
| `max:X` | Max panjang/nilai. | `"max:255"` |
|
|
29
|
+
| `unique:table,col` | Cek unik di DB. | `"unique:users,email"` |
|
|
30
|
+
| `exists:table,col` | Cek exist di DB. | `"exists:roles,id"` |
|
|
31
|
+
| `image` | File harus gambar. | `"required | image"` |
|
|
32
|
+
| `mimes:types` | File extension. | `"mimes:pdf,docx"` |
|
|
33
|
+
|
|
34
|
+
## 🔑 Authentication
|
|
35
|
+
|
|
36
|
+
**Middleware di Route:**
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { requireAuth, requireAdmin } from "@/middleware/auth";
|
|
40
|
+
|
|
41
|
+
router.get("/profile", requireAuth, getProfile); // Login User
|
|
42
|
+
router.delete("/user", requireAuth, requireAdmin, del); // Admin Only
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Akses User di Controller:**
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// (req as any).user tersedia setelah requireAuth
|
|
49
|
+
const userId = (req as any).user.userId;
|
|
50
|
+
const role = (req as any).user.role;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## ⚡ Fast Response (Serializer)
|
|
54
|
+
|
|
55
|
+
**1. Schema:**
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const schema = {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
id: { type: "string" },
|
|
62
|
+
name: { type: "string" },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**2. Serializer:**
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const serializer = getSerializer("key-name", createResponseSchema(schema));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**3. Send:**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
sendFastSuccess(res, 200, serializer, { ...data });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## 📦 Redis (Cache)
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { redis } from "@lapeeh/core/redis";
|
|
83
|
+
|
|
84
|
+
// Set Cache (Key, Value, Mode, Detik)
|
|
85
|
+
await redis.set("profile:1", JSON.stringify(data), "EX", 3600);
|
|
86
|
+
|
|
87
|
+
// Get Cache
|
|
88
|
+
const cached = await redis.get("profile:1");
|
|
89
|
+
if (cached) return JSON.parse(cached);
|
|
90
|
+
```
|
package/doc/en/CLI.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# CLI Tools & Scripts
|
|
2
|
+
|
|
3
|
+
lapeeh Framework comes with various CLI scripts to speed up the development process.
|
|
4
|
+
|
|
5
|
+
All commands are executed using `npm run <command>`.
|
|
6
|
+
|
|
7
|
+
> **Info:** Behind the scenes, these `npm run` scripts call the internal framework CLI (`lapeeh`). You can also run these commands directly using `npx lapeeh <command>`.
|
|
8
|
+
|
|
9
|
+
## Core Commands
|
|
10
|
+
|
|
11
|
+
Main commands to run the application:
|
|
12
|
+
|
|
13
|
+
### 1. Initialize Project (`init`)
|
|
14
|
+
|
|
15
|
+
Creates a new project from scratch.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx lapeeh@latest init <project-name> [flags]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Available Flags:**
|
|
22
|
+
|
|
23
|
+
- `--full`: Initialize with full setup (includes dummy users, roles, permissions).
|
|
24
|
+
- `--default`: Initialize with default configuration (PostgreSQL) skipping interactive prompts.
|
|
25
|
+
- `--y`: Alias for `--default`.
|
|
26
|
+
|
|
27
|
+
**Examples:**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Interactive Mode
|
|
31
|
+
npx lapeeh init my-app
|
|
32
|
+
|
|
33
|
+
# Full Setup (Recommended for learning)
|
|
34
|
+
npx lapeeh init my-app --full
|
|
35
|
+
|
|
36
|
+
# Fast Setup (Default Postgres)
|
|
37
|
+
npx lapeeh init my-app --y
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Upgrade Framework (`upgrade`)
|
|
41
|
+
|
|
42
|
+
Upgrades the lapeeh framework to the latest version in your existing project.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx lapeeh upgrade
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Features:**
|
|
49
|
+
|
|
50
|
+
- Automatically updates `package.json` dependencies.
|
|
51
|
+
- Syncs core framework files while preserving your custom code.
|
|
52
|
+
- **Smart Dependency Handling**: Preserves local `file:` dependencies if you are developing the framework locally, otherwise updates to the latest npm version.
|
|
53
|
+
|
|
54
|
+
### 3. Development Server (`dev`)
|
|
55
|
+
|
|
56
|
+
Runs the server in development mode with hot-reload feature.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run dev
|
|
60
|
+
# or
|
|
61
|
+
npx lapeeh dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Production Server (`start`)
|
|
65
|
+
|
|
66
|
+
Runs the server in production mode (ensure it has been built).
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run start
|
|
70
|
+
# or
|
|
71
|
+
npx lapeeh start
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. Build Project (`build`)
|
|
75
|
+
|
|
76
|
+
Compiles TypeScript code to JavaScript in the `dist` folder.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm run build
|
|
80
|
+
# or
|
|
81
|
+
npx lapeeh build
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Code Generators
|
|
85
|
+
|
|
86
|
+
Use these commands to create boilerplate files automatically.
|
|
87
|
+
|
|
88
|
+
### 1. Create Complete Module (`make:module`)
|
|
89
|
+
|
|
90
|
+
Creates Controller and Route at once.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run make:module <module-name>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Example:** `npm run make:module Product`
|
|
97
|
+
|
|
98
|
+
Output:
|
|
99
|
+
|
|
100
|
+
- `src/controllers/productController.ts`
|
|
101
|
+
- `src/routes/product.ts`
|
|
102
|
+
|
|
103
|
+
### 2. Create Controller (`make:controller`)
|
|
104
|
+
|
|
105
|
+
Only creates a controller file with basic CRUD methods.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm run make:controller <controller-name>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Example:** `npm run make:controller Order` (Will create `src/controllers/orderController.ts`)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Panduan Kontribusi (Contributing Guide)
|
|
2
|
+
|
|
3
|
+
Terima kasih atas ketertarikan Anda untuk berkontribusi pada pengembangan **lapeeh Framework**! 🎉
|
|
4
|
+
|
|
5
|
+
Proyek ini bersifat **Open Source** dan kami sangat menghargai setiap bentuk kontribusi, baik itu perbaikan bug, penambahan fitur, dokumentasi, maupun sekadar laporan error (issue).
|
|
6
|
+
|
|
7
|
+
Dokumen ini akan memandu Anda tentang cara berkontribusi dengan benar dan efisien.
|
|
8
|
+
|
|
9
|
+
## 🚀 Memulai Kontribusi
|
|
10
|
+
|
|
11
|
+
### 1. Persiapan Lingkungan (Prerequisites)
|
|
12
|
+
|
|
13
|
+
Pastikan Anda sudah menginstal:
|
|
14
|
+
|
|
15
|
+
- **Node.js** (v18 ke atas)
|
|
16
|
+
- **Git**
|
|
17
|
+
- **Code Editor** (VS Code disarankan, dengan ekstensi ESLint & Prettier)
|
|
18
|
+
|
|
19
|
+
### 2. Fork & Clone Repository
|
|
20
|
+
|
|
21
|
+
1. **Fork** repository ini ke akun GitHub Anda (tombol "Fork" di pojok kanan atas).
|
|
22
|
+
2. **Clone** hasil fork ke komputer lokal Anda:
|
|
23
|
+
```bash
|
|
24
|
+
git clone https://github.com/USERNAME_ANDA/lapeeh.git
|
|
25
|
+
cd lapeeh
|
|
26
|
+
```
|
|
27
|
+
3. **Tambahkan Remote Upstream** (agar bisa sinkron dengan repo asli):
|
|
28
|
+
```bash
|
|
29
|
+
git remote add upstream https://github.com/robyajo/lapeeh.git
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 3. Instalasi Dependencies
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Jangan lupa jalankan setup awal:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
cp .env.example .env
|
|
42
|
+
# Konfigurasi .env sesuai kebutuhan (terutama bagian Database)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 🛠️ Workflow Pengembangan
|
|
46
|
+
|
|
47
|
+
### 1. Buat Branch Baru
|
|
48
|
+
|
|
49
|
+
Jangan bekerja langsung di branch `main`. Buat branch baru yang deskriptif:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git checkout -b feature/tambah-validasi-email
|
|
53
|
+
# atau
|
|
54
|
+
git checkout -b fix/typo-dokumentasi
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Standar Koding (Coding Standards)
|
|
58
|
+
|
|
59
|
+
Kami menerapkan aturan yang ketat demi menjaga kualitas kode.
|
|
60
|
+
|
|
61
|
+
- **TypeScript**: Gunakan tipe data eksplisit. Hindari `any` sebisa mungkin.
|
|
62
|
+
- **Linter**: Pastikan tidak ada error ESLint. Variabel tidak terpakai harus dihapus atau diberi prefix `_`.
|
|
63
|
+
- **Formatter**: Kode harus rapi.
|
|
64
|
+
|
|
65
|
+
Sebelum commit, **WAJIB** jalankan perintah ini untuk memastikan kode Anda bersih:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run typecheck # Cek error TypeScript
|
|
69
|
+
npm run lint # Cek error Linter
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3. Commit Message Convention
|
|
73
|
+
|
|
74
|
+
Gunakan format **Conventional Commits** agar history mudah dibaca:
|
|
75
|
+
|
|
76
|
+
- `feat: ...` untuk fitur baru.
|
|
77
|
+
- `fix: ...` untuk perbaikan bug.
|
|
78
|
+
- `docs: ...` untuk perubahan dokumentasi.
|
|
79
|
+
- `chore: ...` untuk perubahan kecil (config, script).
|
|
80
|
+
- `refactor: ...` untuk perbaikan struktur kode tanpa mengubah fitur.
|
|
81
|
+
|
|
82
|
+
**Contoh:**
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
feat: add email validation rule to validator
|
|
86
|
+
fix: resolve EADDRINUSE error on windows
|
|
87
|
+
docs: update installation guide
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 📮 Mengirim Pull Request (PR)
|
|
91
|
+
|
|
92
|
+
1. **Push** branch Anda ke GitHub:
|
|
93
|
+
```bash
|
|
94
|
+
git push origin feature/nama-fitur
|
|
95
|
+
```
|
|
96
|
+
2. Buka repository fork Anda di GitHub, lalu klik **Compare & pull request**.
|
|
97
|
+
3. Isi judul dan deskripsi PR dengan jelas:
|
|
98
|
+
- Jelaskan apa yang Anda ubah.
|
|
99
|
+
- Sertakan screenshot (jika ada perubahan visual/output).
|
|
100
|
+
- Referensikan Issue jika ada (contoh: `Closes #123`).
|
|
101
|
+
4. Tunggu review dari maintainer. Kami mungkin akan meminta revisi kecil.
|
|
102
|
+
5. Setelah disetujui, kode Anda akan di-merge! 🚀
|
|
103
|
+
|
|
104
|
+
## 🐛 Melaporkan Bug (Issues)
|
|
105
|
+
|
|
106
|
+
Jika Anda menemukan bug tapi belum bisa memperbaikinya, silakan buat **Issue** baru.
|
|
107
|
+
|
|
108
|
+
- Gunakan judul yang jelas.
|
|
109
|
+
- Jelaskan langkah-langkah untuk mereproduksi bug (Steps to Reproduce).
|
|
110
|
+
- Sertakan log error atau screenshot.
|
|
111
|
+
- Sebutkan versi Node.js dan OS yang digunakan.
|
|
112
|
+
|
|
113
|
+
## 💡 Ide & Diskusi
|
|
114
|
+
|
|
115
|
+
Punya ide fitur baru? Jangan ragu untuk membukanya di **GitHub Discussions** atau buat Issue dengan label `enhancement` sebelum mulai koding, agar kita bisa mendiskusikan desainnya terlebih dahulu.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
Selamat berkontribusi! Kode Anda akan membantu developer lain membangun aplikasi dengan lebih cepat dan menyenangkan. ❤️
|