lapeh 2.6.17 → 3.0.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.
Files changed (67) hide show
  1. package/.env.example +1 -6
  2. package/README.md +19 -85
  3. package/bin/index.js +84 -180
  4. package/dist/lib/bootstrap.d.ts.map +1 -1
  5. package/dist/lib/bootstrap.js +17 -16
  6. package/dist/lib/core/store.d.ts +55 -0
  7. package/dist/lib/core/store.d.ts.map +1 -0
  8. package/dist/lib/core/store.js +66 -0
  9. package/dist/lib/middleware/error.d.ts.map +1 -1
  10. package/dist/lib/middleware/error.js +1 -20
  11. package/dist/lib/utils/validator.d.ts.map +1 -1
  12. package/dist/lib/utils/validator.js +3 -32
  13. package/dist/src/modules/Auth/auth.controller.d.ts.map +1 -1
  14. package/dist/src/modules/Auth/auth.controller.js +118 -105
  15. package/dist/src/modules/Rbac/rbac.controller.d.ts.map +1 -1
  16. package/dist/src/modules/Rbac/rbac.controller.js +141 -140
  17. package/dist/src/routes/index.d.ts.map +1 -1
  18. package/dist/src/routes/index.js +0 -5
  19. package/doc/en/CHEATSHEET.md +3 -7
  20. package/doc/en/CLI.md +16 -41
  21. package/doc/en/DEPLOYMENT.md +171 -245
  22. package/doc/en/GETTING_STARTED.md +1 -25
  23. package/doc/en/PACKAGES.md +2 -3
  24. package/doc/en/STRUCTURE.md +1 -11
  25. package/doc/en/TUTORIAL.md +61 -119
  26. package/doc/id/CHANGELOG.md +16 -0
  27. package/doc/id/CHEATSHEET.md +0 -4
  28. package/doc/id/CLI.md +19 -54
  29. package/doc/id/DEPLOYMENT.md +171 -245
  30. package/doc/id/GETTING_STARTED.md +91 -115
  31. package/doc/id/PACKAGES.md +0 -1
  32. package/doc/id/STRUCTURE.md +1 -11
  33. package/doc/id/TUTORIAL.md +51 -109
  34. package/gitignore.template +0 -10
  35. package/lib/bootstrap.ts +39 -38
  36. package/lib/core/store.ts +116 -0
  37. package/lib/middleware/error.ts +1 -21
  38. package/lib/utils/validator.ts +3 -39
  39. package/package.json +4 -18
  40. package/scripts/init-project.js +2 -108
  41. package/scripts/make-module.js +1 -12
  42. package/scripts/seed-json.js +158 -0
  43. package/src/modules/Auth/auth.controller.ts +156 -106
  44. package/src/modules/Rbac/rbac.controller.ts +193 -138
  45. package/src/routes/index.ts +0 -3
  46. package/src/routes/rbac.ts +42 -42
  47. package/storage/logs/.0337f5062fe676994d1dc340156e089444e3d6e0-audit.json +5 -10
  48. package/storage/logs/lapeh-2025-12-30.log +1093 -0
  49. package/tsconfig.build.json +1 -3
  50. package/tsconfig.json +0 -1
  51. package/lib/core/database.ts +0 -5
  52. package/prisma/base.prisma.template +0 -8
  53. package/prisma/migrations/20251225163737_init/migration.sql +0 -236
  54. package/prisma/migrations/20251226000329_create_pets_table/migration.sql +0 -11
  55. package/prisma/migrations/20251226001249_create_pets_table/migration.sql +0 -82
  56. package/prisma/migrations/20251226001717_restore_core_models/migration.sql +0 -236
  57. package/prisma/migrations/migration_lock.toml +0 -3
  58. package/prisma/schema.prisma +0 -197
  59. package/prisma/seed.ts +0 -411
  60. package/scripts/compile-schema.js +0 -64
  61. package/src/modules/Auth/auth.prisma +0 -106
  62. package/src/modules/Pets/pets.controller.ts +0 -238
  63. package/src/modules/Pets/pets.prisma +0 -9
  64. package/src/modules/Rbac/rbac.prisma +0 -68
  65. package/src/routes/pets.ts +0 -13
  66. package/storage/logs/lapeh-2025-12-26.log +0 -88
  67. package/storage/logs/lapeh-2025-12-27.log +0 -217
@@ -1,74 +1,51 @@
1
- # Tutorial: Membangun API Perpustakaan
1
+ # Tutorial: Building a Library API
2
2
 
3
- Dalam tutorial ini, kita akan membangun fitur "Manajemen Buku" sederhana menggunakan semua fitur unggulan Lapeh Framework:
4
- 1. **CLI** untuk generate kode.
5
- 2. **Validator** untuk validasi input.
6
- 3. **Fast Serialization** untuk respon cepat.
7
- 4. **RBAC** untuk proteksi delete (Admin only).
3
+ In this tutorial, we will build a simple "Book Management" feature using Lapeh Framework's core features:
4
+ 1. **CLI** for code generation.
5
+ 2. **Validator** for input validation.
6
+ 3. **Fast Serialization** for high-performance responses.
8
7
 
9
- ## Langkah 1: Generate Model Database
8
+ > **Note**: This tutorial uses an in-memory array for data storage to keep things simple. Lapeh v3.0.0 is database-agnostic, so you can easily swap this with Prisma, TypeORM, or any other DB library.
10
9
 
11
- Kita butuh tabel `books`. Gunakan CLI `make:model`.
10
+ ## Step 1: Generate Module (Controller & Route)
12
11
 
13
- ```bash
14
- npm run make:model Book
15
- ```
16
-
17
- File baru akan muncul di `src/models/book.prisma`. Edit file tersebut:
18
-
19
- ```prisma
20
- // src/models/book.prisma
21
-
22
- model Book {
23
- id BigInt @id @default(autoincrement())
24
- title String
25
- author String
26
- isbn String @unique
27
- publishedAt DateTime
28
- stock Int @default(0)
29
- created_at DateTime @default(now())
30
- updated_at DateTime @updatedAt
31
-
32
- @@map("books")
33
- }
34
- ```
35
-
36
- Terapkan perubahan ke database:
37
-
38
- ```bash
39
- npm run prisma:migrate
40
- ```
41
-
42
- ## Langkah 2: Generate Module (Controller & Route)
43
-
44
- Kita buat controller dan route sekaligus.
12
+ We will create a controller and route for our Book feature.
45
13
 
46
14
  ```bash
47
15
  npm run make:module Book
48
16
  ```
49
17
 
50
- Framework akan membuat:
18
+ The framework will generate:
51
19
  - `src/controllers/bookController.ts`
52
20
  - `src/routes/book.ts`
53
21
 
54
- ## Langkah 3: Implementasi Controller
22
+ ## Step 2: Implement Controller
55
23
 
56
- Buka `src/controllers/bookController.ts` dan kita implementasikan fitur **Create** dan **List** dengan standar framework.
24
+ Open `src/controllers/bookController.ts` and let's implement **Create** and **List** features.
57
25
 
58
- ### Setup Import & Serializer
26
+ ### Setup Import & Data Store
59
27
 
60
28
  ```typescript
61
29
  import { Request, Response } from "express";
62
- import { prisma } from "@/core/database";
63
30
  import { sendFastSuccess, sendError } from "@/utils/response";
64
31
  import { Validator } from "@/utils/validator";
65
32
  import { getSerializer, createResponseSchema } from "@/core/serializer";
66
33
 
67
- // 1. Definisikan Schema Output (untuk Fastify Serialization)
34
+ // Simple in-memory store
35
+ interface Book {
36
+ id: string;
37
+ title: string;
38
+ author: string;
39
+ isbn: string;
40
+ stock: number;
41
+ }
42
+ const books: Book[] = [];
43
+
44
+ // 1. Define Output Schema (for Fastify Serialization)
68
45
  const bookSchema = {
69
46
  type: "object",
70
47
  properties: {
71
- id: { type: "string" }, // BigInt -> String
48
+ id: { type: "string" },
72
49
  title: { type: "string" },
73
50
  author: { type: "string" },
74
51
  isbn: { type: "string" },
@@ -76,7 +53,7 @@ const bookSchema = {
76
53
  }
77
54
  };
78
55
 
79
- // 2. Buat Serializer
56
+ // 2. Create Serializer
80
57
  const bookDetailSerializer = getSerializer("book-detail", createResponseSchema(bookSchema));
81
58
  const bookListSerializer = getSerializer("book-list", createResponseSchema({
82
59
  type: "array",
@@ -84,109 +61,74 @@ const bookListSerializer = getSerializer("book-list", createResponseSchema({
84
61
  }));
85
62
  ```
86
63
 
87
- ### Implementasi Create (dengan Validasi)
64
+ ### Implement Create (with Validation)
88
65
 
89
66
  ```typescript
90
67
  export async function createBook(req: Request, res: Response) {
91
- // 1. Validasi Input
68
+ // 1. Validate Input
92
69
  const validator = await Validator.make(req.body, {
93
70
  title: "required|string|min:3",
94
71
  author: "required|string",
95
- isbn: "required|string|unique:books,isbn", // Cek unik di tabel books
96
- stock: "required|number|min:1",
97
- publishedAt: "required|string" // Format tanggal ISO
72
+ isbn: "required|string",
73
+ stock: "required|number|min:1"
98
74
  });
99
75
 
100
76
  if (validator.fails()) {
101
77
  return sendError(res, 400, "Validation Error", validator.errors());
102
78
  }
103
79
 
104
- const data = validator.validated();
105
-
106
- // 2. Simpan ke Database
107
- const book = await prisma.book.create({
108
- data: {
109
- title: data.title,
110
- author: data.author,
111
- isbn: data.isbn,
112
- stock: data.stock,
113
- publishedAt: new Date(data.publishedAt)
114
- }
115
- });
80
+ // 2. Save Data (In-Memory)
81
+ const newBook: Book = {
82
+ id: Date.now().toString(),
83
+ ...validator.validated()
84
+ };
85
+ books.push(newBook);
116
86
 
117
- // 3. Return Response Cepat
118
- return sendFastSuccess(res, 201, bookDetailSerializer, {
119
- status: "success",
120
- message: "Buku berhasil ditambahkan",
121
- data: { ...book, id: book.id.toString() } // Konversi BigInt manual jika perlu
122
- });
87
+ // 3. Send Response (Serialized)
88
+ return sendFastSuccess(res, bookDetailSerializer(newBook), 201);
123
89
  }
124
- ```
125
-
126
- ### Implementasi List (High Performance)
127
-
128
- ```typescript
129
- export async function getBooks(req: Request, res: Response) {
130
- const books = await prisma.book.findMany({
131
- take: 50, // Limit 50
132
- orderBy: { created_at: "desc" }
133
- });
134
-
135
- // Convert BigInt to string sebelum passing ke serializer (opsional, tapi aman)
136
- const safeBooks = books.map(b => ({ ...b, id: b.id.toString() }));
137
90
 
138
- return sendFastSuccess(res, 200, bookListSerializer, {
139
- status: "success",
140
- message: "Daftar buku",
141
- data: safeBooks
142
- });
91
+ export async function listBooks(req: Request, res: Response) {
92
+ // Return all books
93
+ return sendFastSuccess(res, bookListSerializer(books));
143
94
  }
144
95
  ```
145
96
 
146
- ## Langkah 4: Daftarkan Route & Proteksi
97
+ ## Step 3: Register Route
147
98
 
148
- Buka `src/routes/book.ts` (atau file yang digenerate). Pastikan route terhubung dan tambahkan middleware auth.
99
+ Open `src/routes/book.ts`. The CLI has already generated the basic structure. We just need to connect it to our controller functions.
149
100
 
150
101
  ```typescript
151
102
  import { Router } from "express";
152
- import { createBook, getBooks } from "../controllers/bookController";
153
- import { requireAuth, requireAdmin } from "../middleware/auth";
103
+ import { createBook, listBooks } from "../controllers/bookController";
154
104
 
155
- export const bookRouter = Router();
105
+ const router = Router();
156
106
 
157
- // Public route (bisa diakses siapa saja)
158
- bookRouter.get("/", getBooks);
107
+ router.post("/", createBook);
108
+ router.get("/", listBooks);
159
109
 
160
- // Admin only (Butuh login + role admin)
161
- bookRouter.post("/", requireAuth, requireAdmin, createBook);
110
+ export default router;
162
111
  ```
163
112
 
164
- Terakhir, daftarkan router ini di `src/routes/index.ts` (jika belum otomatis):
113
+ ## Step 4: Test Your API
165
114
 
166
- ```typescript
167
- import { bookRouter } from "./book";
168
- // ...
169
- router.use("/books", bookRouter);
115
+ Run the server:
116
+ ```bash
117
+ npm run dev
170
118
  ```
171
119
 
172
- ## Langkah 5: Testing
120
+ Test with curl or Postman:
173
121
 
174
- Jalankan server:
122
+ **Create Book:**
175
123
  ```bash
176
- npm run dev
124
+ curl -X POST http://localhost:4000/api/book \
125
+ -H "Content-Type: application/json" \
126
+ -d '{"title":"Lapeh Guide", "author":"Team", "isbn":"12345", "stock":10}'
177
127
  ```
178
128
 
179
- Coba hit endpoint:
180
- 1. **POST /api/books** (Tanpa token) -> 401 Unauthorized.
181
- 2. **POST /api/books** (Token User Biasa) -> 403 Forbidden.
182
- 3. **POST /api/books** (Token Admin + Data Invalid) -> 400 Validation Error.
183
- 4. **POST /api/books** (Token Admin + Data Valid) -> 201 Created.
184
- 5. **GET /api/books** -> 200 OK (Super Cepat).
185
-
186
- ## Kesimpulan
129
+ **List Books:**
130
+ ```bash
131
+ curl http://localhost:4000/api/book
132
+ ```
187
133
 
188
- Dengan Lapeh Framework, Anda telah membuat API yang:
189
- - **Aman** (Validasi, Auth, RBAC).
190
- - **Cepat** (Fast Serialization).
191
- - **Rapi** (Struktur terstandarisasi).
192
- - **Mudah** (CLI Generator).
134
+ Congratulations! You have built a fast, validated API without getting bogged down in database configuration.
@@ -2,6 +2,22 @@
2
2
 
3
3
  File ini mencatat semua perubahan, pembaruan, dan perbaikan yang dilakukan pada framework Lapeh, diurutkan berdasarkan tanggal.
4
4
 
5
+ ## [2025-12-30] - Selasa, 30 Desember 2025 - Major Release v3.0.0 (No-ORM)
6
+
7
+ ### ⚠️ Perubahan Besar (Breaking Changes)
8
+
9
+ - **Penghapusan Prisma ORM**: Lapeh Framework kini **tidak lagi menyertakan ORM bawaan** (seperti Prisma). Kami memberikan kebebasan penuh kepada pengguna untuk memilih stack database mereka sendiri (Prisma, TypeORM, Drizzle, dll).
10
+ - **Update CLI**:
11
+ - `init`: Tidak lagi menanyakan konfigurasi database.
12
+ - `make:module`: Tidak lagi membuat file `.prisma`.
13
+ - Penghapusan script `compile-schema.js` dan logika terkait split-schema Prisma.
14
+
15
+ ### 🚀 Fitur & Refactor
16
+
17
+ - **In-Memory Mock Data**: Modul bawaan (Auth, RBAC, Pets) kini menggunakan data dummy in-memory untuk demonstrasi tanpa perlu setup database.
18
+ - **Redis Caching**: Implementasi caching Redis pada Pets controller.
19
+ - **Dokumentasi**: Pembaruan menyeluruh pada dokumentasi untuk mencerminkan filosofi agnostik database.
20
+
5
21
  ## [2025-12-29] - Senin, 29 Desember 2025 - Perbaikan Bug CLI Init (v2.6.7)
6
22
 
7
23
  ### 🛠️ Perbaikan Bug
@@ -12,11 +12,7 @@ Referensi cepat untuk perintah dan kode yang sering digunakan.
12
12
  | **`npm run lint:fix`** | Perbaiki kode kotor otomatis. |
13
13
  | **`npm run make:module <Name>`** | Buat Controller, Route, & Model sekaligus. |
14
14
  | **`npm run make:controller <Name>`** | Buat Controller saja. |
15
- | **`npm run make:model <Name>`** | Buat Model Prisma saja. |
16
- | **`npm run prisma:migrate`** | Apply perubahan schema ke DB lokal. |
17
- | **`npm run db:studio`** | Buka GUI Database. |
18
15
  | **`npm run db:seed`** | Isi data dummy. |
19
- | **`npm run db:reset`** | Hapus DB & mulai dari nol. |
20
16
 
21
17
  ## 🛡️ Validator Rules (Simple Syntax)
22
18
 
package/doc/id/CLI.md CHANGED
@@ -11,6 +11,7 @@ Semua perintah dijalankan menggunakan `npm run <command>`.
11
11
  Perintah utama untuk menjalankan aplikasi:
12
12
 
13
13
  ### 1. Inisialisasi Project (`init`)
14
+
14
15
  Membuat project baru dari awal.
15
16
 
16
17
  ```bash
@@ -18,11 +19,13 @@ npx lapeh@latest init <nama-project> [flags]
18
19
  ```
19
20
 
20
21
  **Flag Tersedia:**
22
+
21
23
  - `--full`: Inisialisasi dengan setup lengkap (termasuk dummy user, role, permission).
22
24
  - `--default`: Inisialisasi dengan konfigurasi default (PostgreSQL) melewati prompt interaktif.
23
25
  - `--y`: Alias untuk `--default`.
24
26
 
25
27
  **Contoh:**
28
+
26
29
  ```bash
27
30
  # Mode Interaktif
28
31
  npx lapeh init my-app
@@ -35,17 +38,21 @@ npx lapeh init my-app --y
35
38
  ```
36
39
 
37
40
  ### 2. Upgrade Framework (`upgrade`)
41
+
38
42
  Memperbarui framework Lapeh ke versi terbaru di project yang sudah ada.
39
43
 
40
44
  ```bash
41
45
  npx lapeh upgrade
42
46
  ```
47
+
43
48
  **Fitur:**
49
+
44
50
  - Secara otomatis memperbarui dependensi `package.json`.
45
51
  - Menyinkronkan file inti framework sambil menjaga kode kustom Anda.
46
52
  - **Smart Dependency Handling**: Mempertahankan dependensi `file:` lokal jika Anda mengembangkan framework secara lokal, jika tidak akan mengupdate ke versi npm terbaru.
47
53
 
48
54
  ### 3. Development Server (`dev`)
55
+
49
56
  Menjalankan server dalam mode development dengan fitur hot-reload.
50
57
 
51
58
  ```bash
@@ -55,6 +62,7 @@ npx lapeh dev
55
62
  ```
56
63
 
57
64
  ### 2. Production Server (`start`)
65
+
58
66
  Menjalankan server dalam mode production (pastikan sudah dibuild).
59
67
 
60
68
  ```bash
@@ -64,6 +72,7 @@ npx lapeh start
64
72
  ```
65
73
 
66
74
  ### 3. Build Project (`build`)
75
+
67
76
  Mengompilasi kode TypeScript ke JavaScript di folder `dist`.
68
77
 
69
78
  ```bash
@@ -77,89 +86,44 @@ npx lapeh build
77
86
  Gunakan perintah ini untuk membuat file boilerplate secara otomatis.
78
87
 
79
88
  ### 1. Membuat Module Lengkap (`make:module`)
80
- Membuat Controller, Route, dan Model (Schema) sekaligus.
89
+
90
+ Membuat Controller dan Route sekaligus.
81
91
 
82
92
  ```bash
83
93
  npm run make:module <nama-module>
84
94
  ```
95
+
85
96
  **Contoh:** `npm run make:module Product`
86
97
 
87
98
  Output:
99
+
88
100
  - `src/controllers/productController.ts`
89
101
  - `src/routes/product.ts`
90
- - `src/models/product.prisma`
91
102
 
92
103
  ### 2. Membuat Controller (`make:controller`)
104
+
93
105
  Hanya membuat file controller dengan method CRUD dasar.
94
106
 
95
107
  ```bash
96
108
  npm run make:controller <nama-controller>
97
109
  ```
98
- **Contoh:** `npm run make:controller Order` (Akan membuat `src/controllers/orderController.ts`)
99
-
100
- ### 3. Membuat Model Database (`make:model`)
101
- Hanya membuat file schema Prisma baru.
102
-
103
- ```bash
104
- npm run make:model <nama-model>
105
- ```
106
- **Contoh:** `npm run make:model Transaction` (Akan membuat `src/models/transaction.prisma`)
107
-
108
- ## Database Management (Prisma)
109
-
110
- Framework ini menggunakan sistem **Multi-File Schema**. Anda tidak mengedit `schema.prisma` secara langsung, melainkan mengedit file kecil di `src/models/*.prisma`.
111
-
112
- ### 1. Migrasi Database (`prisma:migrate`)
113
- Jalankan setiap kali Anda mengubah definisi model di `src/models/*.prisma`.
114
-
115
- ```bash
116
- npm run prisma:migrate
117
- ```
118
- Perintah ini akan:
119
- 1. Menggabungkan semua file `.prisma` di `src/models/` menjadi satu `prisma/schema.prisma`.
120
- 2. Membuat file migrasi SQL.
121
- 3. Menerapkan perubahan ke database lokal.
122
- 4. Men-generate ulang Prisma Client (Type Definitions).
123
-
124
- ### 2. Deploy ke Production (`prisma:deploy`)
125
- Gunakan di server production. Hanya menerapkan migrasi yang sudah ada tanpa reset data.
126
-
127
- ```bash
128
- npm run prisma:deploy
129
- ```
130
-
131
- ### 3. Database Studio (`db:studio`)
132
- Membuka GUI di browser untuk melihat dan mengedit data database.
133
-
134
- ```bash
135
- npm run db:studio
136
- ```
137
-
138
- ### 4. Seeding Data (`db:seed`)
139
- Mengisi database dengan data awal yang didefinisikan di `prisma/seed.ts`.
140
-
141
- ```bash
142
- npm run db:seed
143
- ```
144
110
 
145
- ### 5. Reset Database (`db:reset`)
146
- **PERINGATAN:** Menghapus semua data dan tabel, lalu menjalankan migrasi dari awal.
147
-
148
- ```bash
149
- npm run db:reset
150
- ```
111
+ **Contoh:** `npm run make:controller Order` (Akan membuat `src/controllers/orderController.ts`)
151
112
 
152
113
  ## Code Quality & Utilities
153
114
 
154
115
  ### 1. Linting (`lint`)
116
+
155
117
  Memeriksa kode dari error, variabel tidak terpakai, dan gaya penulisan.
156
118
 
157
119
  ```bash
158
120
  npm run lint
159
121
  ```
122
+
160
123
  Gunakan `npm run lint:fix` untuk memperbaiki error otomatis.
161
124
 
162
125
  ### 2. Type Check (`typecheck`)
126
+
163
127
  Memeriksa error tipe data TypeScript tanpa melakukan compile.
164
128
 
165
129
  ```bash
@@ -167,6 +131,7 @@ npm run typecheck
167
131
  ```
168
132
 
169
133
  ### 3. Generate JWT Secret (`generate:jwt`)
134
+
170
135
  Membuat random string aman untuk `JWT_SECRET` di file `.env`.
171
136
 
172
137
  ```bash