lapeh 2.2.7 → 2.2.8
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/bin/index.js +164 -13
- package/package.json +6 -6
- package/api-testing-sepuluh/.env.example +0 -19
- package/api-testing-sepuluh/doc/ARCHITECTURE_GUIDE.md +0 -73
- package/api-testing-sepuluh/doc/CHANGELOG.md +0 -77
- package/api-testing-sepuluh/doc/CHEATSHEET.md +0 -94
- package/api-testing-sepuluh/doc/CLI.md +0 -106
- package/api-testing-sepuluh/doc/CONTRIBUTING.md +0 -105
- package/api-testing-sepuluh/doc/DEPLOYMENT.md +0 -122
- package/api-testing-sepuluh/doc/FAQ.md +0 -81
- package/api-testing-sepuluh/doc/FEATURES.md +0 -165
- package/api-testing-sepuluh/doc/GETTING_STARTED.md +0 -108
- package/api-testing-sepuluh/doc/INTRODUCTION.md +0 -60
- package/api-testing-sepuluh/doc/PACKAGES.md +0 -66
- package/api-testing-sepuluh/doc/PERFORMANCE.md +0 -91
- package/api-testing-sepuluh/doc/ROADMAP.md +0 -93
- package/api-testing-sepuluh/doc/SECURITY.md +0 -93
- package/api-testing-sepuluh/doc/STRUCTURE.md +0 -90
- package/api-testing-sepuluh/doc/TUTORIAL.md +0 -192
- package/api-testing-sepuluh/docker-compose.yml +0 -24
- package/api-testing-sepuluh/eslint.config.mjs +0 -26
- package/api-testing-sepuluh/framework.md +0 -168
- package/api-testing-sepuluh/nodemon.json +0 -6
- package/api-testing-sepuluh/package-lock.json +0 -5539
- package/api-testing-sepuluh/package.json +0 -103
- package/api-testing-sepuluh/prisma/base.prisma.template +0 -7
- package/api-testing-sepuluh/prisma/migrations/20251227034737_init_setup/migration.sql +0 -248
- package/api-testing-sepuluh/prisma/migrations/migration_lock.toml +0 -3
- package/api-testing-sepuluh/prisma/schema.prisma +0 -183
- package/api-testing-sepuluh/prisma/seed.ts +0 -411
- package/api-testing-sepuluh/prisma.config.ts +0 -15
- package/api-testing-sepuluh/readme.md +0 -414
- package/api-testing-sepuluh/scripts/check-update.js +0 -92
- package/api-testing-sepuluh/scripts/compile-schema.js +0 -29
- package/api-testing-sepuluh/scripts/config-clear.js +0 -45
- package/api-testing-sepuluh/scripts/generate-jwt-secret.js +0 -38
- package/api-testing-sepuluh/scripts/init-project.js +0 -178
- package/api-testing-sepuluh/scripts/make-controller.js +0 -205
- package/api-testing-sepuluh/scripts/make-model.js +0 -42
- package/api-testing-sepuluh/scripts/make-module.js +0 -158
- package/api-testing-sepuluh/scripts/verify-rbac-functional.js +0 -187
- package/api-testing-sepuluh/src/controllers/authController.ts +0 -469
- package/api-testing-sepuluh/src/controllers/petController.ts +0 -194
- package/api-testing-sepuluh/src/controllers/rbacController.ts +0 -478
- package/api-testing-sepuluh/src/models/core.prisma +0 -163
- package/api-testing-sepuluh/src/models/pets.prisma +0 -9
- package/api-testing-sepuluh/src/routes/auth.ts +0 -74
- package/api-testing-sepuluh/src/routes/index.ts +0 -10
- package/api-testing-sepuluh/src/routes/pets.ts +0 -13
- package/api-testing-sepuluh/src/routes/rbac.ts +0 -42
- package/api-testing-sepuluh/storage/logs/.gitkeep +0 -0
- package/api-testing-sepuluh/tsconfig.json +0 -39
package/bin/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
@@ -37,10 +37,14 @@ function runDev() {
|
|
|
37
37
|
const tsNodePath = require.resolve('ts-node/register');
|
|
38
38
|
const tsConfigPathsPath = require.resolve('tsconfig-paths/register');
|
|
39
39
|
|
|
40
|
-
// Resolve bootstrap file
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
// Resolve bootstrap file
|
|
41
|
+
// 1. Try to find it in the current project's node_modules (preferred)
|
|
42
|
+
const localBootstrapPath = path.join(process.cwd(), 'node_modules/lapeh/lib/bootstrap.ts');
|
|
43
|
+
|
|
44
|
+
// 2. Fallback to relative to this script (if running from source or global cache without local install)
|
|
45
|
+
const fallbackBootstrapPath = path.resolve(__dirname, '../lib/bootstrap.ts');
|
|
46
|
+
|
|
47
|
+
const bootstrapPath = fs.existsSync(localBootstrapPath) ? localBootstrapPath : fallbackBootstrapPath;
|
|
44
48
|
|
|
45
49
|
// We execute a script that requires ts-node to run lib/bootstrap.ts
|
|
46
50
|
execSync(`npx nodemon --watch src --watch lib --ext ts,json --exec "node -r ${tsNodePath} -r ${tsConfigPathsPath} ${bootstrapPath}"`, { stdio: 'inherit' });
|
|
@@ -210,11 +214,35 @@ async function upgradeProject() {
|
|
|
210
214
|
function createProject() {
|
|
211
215
|
const projectName = args.find(arg => !arg.startsWith('-'));
|
|
212
216
|
const isFull = args.includes('--full');
|
|
213
|
-
|
|
217
|
+
// Allow -y alias for --defaults
|
|
218
|
+
const useDefaults = args.includes('--defaults') || args.includes('-y');
|
|
219
|
+
|
|
220
|
+
// Helper to parse arguments like --key=value
|
|
221
|
+
const getArg = (key) => {
|
|
222
|
+
const prefix = `--${key}=`;
|
|
223
|
+
const arg = args.find(a => a.startsWith(prefix));
|
|
224
|
+
return arg ? arg.substring(prefix.length) : undefined;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const dbTypeArg = getArg('db-type');
|
|
228
|
+
const dbHostArg = getArg('db-host');
|
|
229
|
+
const dbPortArg = getArg('db-port');
|
|
230
|
+
const dbUserArg = getArg('db-user');
|
|
231
|
+
const dbPassArg = getArg('db-pass');
|
|
232
|
+
const dbNameArg = getArg('db-name');
|
|
214
233
|
|
|
215
234
|
if (!projectName) {
|
|
216
235
|
console.error('❌ Please specify the project name:');
|
|
217
|
-
console.error(' npx lapeh-cli <project-name> [--full]');
|
|
236
|
+
console.error(' npx lapeh-cli <project-name> [--full] [--defaults|-y]');
|
|
237
|
+
console.error(' Options:');
|
|
238
|
+
console.error(' --full : Run full setup including seed and dev server');
|
|
239
|
+
console.error(' --defaults, -y: Use default configuration (can be overridden with args)');
|
|
240
|
+
console.error(' --db-type= : pgsql | mysql');
|
|
241
|
+
console.error(' --db-host= : Database host');
|
|
242
|
+
console.error(' --db-port= : Database port');
|
|
243
|
+
console.error(' --db-user= : Database user');
|
|
244
|
+
console.error(' --db-pass= : Database password');
|
|
245
|
+
console.error(' --db-name= : Database name');
|
|
218
246
|
console.error(' OR');
|
|
219
247
|
console.error(' npx lapeh-cli upgrade (inside existing project)');
|
|
220
248
|
process.exit(1);
|
|
@@ -271,12 +299,32 @@ function createProject() {
|
|
|
271
299
|
|
|
272
300
|
if (useDefaults) {
|
|
273
301
|
console.log("ℹ️ Using default configuration (--defaults)...");
|
|
302
|
+
|
|
303
|
+
// Default to PostgreSQL
|
|
274
304
|
dbType = { key: "pgsql", label: "PostgreSQL", provider: "postgresql", defaultPort: "5432" };
|
|
275
305
|
host = "localhost";
|
|
276
306
|
port = "5432";
|
|
277
|
-
user = "postgres";
|
|
278
|
-
password = "password";
|
|
307
|
+
user = "postgres";
|
|
308
|
+
password = "password";
|
|
279
309
|
dbName = projectName.replace(/-/g, '_');
|
|
310
|
+
|
|
311
|
+
// Override with CLI args
|
|
312
|
+
if (dbTypeArg) {
|
|
313
|
+
if (dbTypeArg.toLowerCase() === 'mysql') {
|
|
314
|
+
dbType = { key: "mysql", label: "MySQL", provider: "mysql", defaultPort: "3306" };
|
|
315
|
+
port = "3306";
|
|
316
|
+
} else if (dbTypeArg.toLowerCase() === 'pgsql') {
|
|
317
|
+
dbType = { key: "pgsql", label: "PostgreSQL", provider: "postgresql", defaultPort: "5432" };
|
|
318
|
+
port = "5432";
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (dbHostArg) host = dbHostArg;
|
|
323
|
+
if (dbPortArg) port = dbPortArg;
|
|
324
|
+
if (dbUserArg) user = dbUserArg;
|
|
325
|
+
if (dbPassArg) password = dbPassArg;
|
|
326
|
+
if (dbNameArg) dbName = dbNameArg;
|
|
327
|
+
|
|
280
328
|
} else {
|
|
281
329
|
dbType = await selectOption("Database apa yang akan digunakan?", [
|
|
282
330
|
{ key: "pgsql", label: "PostgreSQL", provider: "postgresql", defaultPort: "5432" },
|
|
@@ -378,6 +426,7 @@ function createProject() {
|
|
|
378
426
|
// Update scripts to use lapeh binary
|
|
379
427
|
packageJson.scripts = {
|
|
380
428
|
...packageJson.scripts,
|
|
429
|
+
"postinstall": "node scripts/compile-schema.js && prisma generate",
|
|
381
430
|
"dev": "lapeh dev",
|
|
382
431
|
"start": "lapeh start",
|
|
383
432
|
"build": "lapeh build",
|
|
@@ -399,6 +448,9 @@ function createProject() {
|
|
|
399
448
|
tsconfig.compilerOptions.paths["@lapeh/*"] = ["./node_modules/lapeh/lib/*"];
|
|
400
449
|
}
|
|
401
450
|
|
|
451
|
+
// Add baseUrl
|
|
452
|
+
tsconfig.compilerOptions.baseUrl = ".";
|
|
453
|
+
|
|
402
454
|
// Add ts-node ignore configuration
|
|
403
455
|
tsconfig["ts-node"] = {
|
|
404
456
|
"ignore": ["node_modules/(?!lapeh)"]
|
|
@@ -501,14 +553,113 @@ function createProject() {
|
|
|
501
553
|
console.log(' Compiling schema...');
|
|
502
554
|
execSync('node scripts/compile-schema.js', { cwd: projectDir, stdio: 'inherit' });
|
|
503
555
|
|
|
504
|
-
console.log(' Generating Prisma Client...');
|
|
505
|
-
execSync('npx prisma generate', { cwd: projectDir, stdio: 'inherit' });
|
|
506
|
-
|
|
507
556
|
// Try to migrate (this will create the DB if it doesn't exist)
|
|
508
557
|
console.log(' Running migration (creates DB if missing)...');
|
|
509
558
|
execSync('npx prisma migrate dev --name init_setup', { cwd: projectDir, stdio: 'inherit' });
|
|
510
559
|
|
|
511
|
-
// Seed
|
|
560
|
+
// Seed (Users & Roles are mandatory, Pets are demo data)
|
|
561
|
+
console.log(' Seeding mandatory data (Users, Roles, Permissions)...');
|
|
562
|
+
// Always seed mandatory data by default or check if --full is meant for demo data only?
|
|
563
|
+
// Based on user request: "user seeder dan pets itu selalu ada karena default, jadi seharusnya tidak digenerate saat user buat project baru"
|
|
564
|
+
// Wait, user says: "user seeder and pets are always there because default, so it SHOULD NOT be generated when user creates new project, UNLESS user starts using framework and adding new tables"
|
|
565
|
+
|
|
566
|
+
// Interpretation: The user implies that `prisma generate` and `prisma migrate` (which creates the physical tables and client code)
|
|
567
|
+
// MIGHT be redundant if the core framework already provides a pre-built client for the default models (Users, Pets).
|
|
568
|
+
// However, Prisma doesn't work like that easily because the Client is generated into node_modules/@prisma/client.
|
|
569
|
+
|
|
570
|
+
// If the user means "don't run migration/seed unless needed", we still need to run them to have a working app.
|
|
571
|
+
// Re-reading carefully: "masalahnya user seeder dan pets itu selalu ada karane default ,jadi seharusnya tidak digenerate saat user buuat project baru , kecuali user mulai menggunakan framework ini dan menambahkan table baru untuk developmen"
|
|
572
|
+
|
|
573
|
+
// AH! The user might mean: Since User/Pets are CORE models, the Prisma Client for them should ALREADY exist or be pre-packaged,
|
|
574
|
+
// so we don't need to run `prisma generate` during project creation?
|
|
575
|
+
// OR: The user means the *migration files* shouldn't be generated?
|
|
576
|
+
|
|
577
|
+
// "seharusnya tidak digenerate saat user buuat project baru" -> The user is annoyed by the `prisma generate` and `migration` step taking time?
|
|
578
|
+
// But we need the DB tables.
|
|
579
|
+
|
|
580
|
+
// Let's assume the user wants to SKIP the `prisma generate` and `migrate` step if possible,
|
|
581
|
+
// but that's impossible for a fresh project connecting to a fresh DB.
|
|
582
|
+
|
|
583
|
+
// Alternative interpretation: The user thinks `prisma generate` is only for NEW tables.
|
|
584
|
+
// But `prisma generate` is required to create the client library itself.
|
|
585
|
+
|
|
586
|
+
// Let's look at the "Pets" part. Maybe the user considers Pets as "bloat" that shouldn't be there by default?
|
|
587
|
+
// "user seeder dan pets itu selalu ada karane default"
|
|
588
|
+
|
|
589
|
+
// Wait, maybe the user is saying: "Since these are default, why do we need to RE-generate/RE-migrate them every time? Can't we just have them ready?"
|
|
590
|
+
// Answer: No, because every user has a different DB connection string.
|
|
591
|
+
|
|
592
|
+
// Let's explain this to the user. Prisma Client is NOT a static library like `lodash`. It is generated based on the schema.
|
|
593
|
+
// If we don't generate it, `import { prisma }` will fail because `node_modules/@prisma/client` will be empty.
|
|
594
|
+
|
|
595
|
+
// However, we CAN optimize.
|
|
596
|
+
// Maybe the user is asking: "Why do we generate migration files (`prisma/migrations`) for default tables?"
|
|
597
|
+
// We can ship the project WITH the migration folder for the default tables already there!
|
|
598
|
+
// If we include `prisma/migrations` in the template, `prisma migrate dev` will see they exist and just apply them,
|
|
599
|
+
// instead of creating a NEW migration `init_setup`.
|
|
600
|
+
|
|
601
|
+
// Let's try to verify if `prisma/migrations` is in the ignore list.
|
|
602
|
+
// Line 367: `'prisma/migrations', // Exclude existing migrations`
|
|
603
|
+
// Yes, we are explicitly excluding them!
|
|
604
|
+
|
|
605
|
+
// If we INCLUDE the base migrations in the template, then we don't need to create a new migration on init.
|
|
606
|
+
// We just run `prisma migrate deploy` (faster) or `dev` (which will see it's in sync).
|
|
607
|
+
|
|
608
|
+
// Let's change the strategy:
|
|
609
|
+
// 1. Remove `prisma/migrations` from ignore list.
|
|
610
|
+
// 2. But wait, the user's template might have dirty migrations.
|
|
611
|
+
|
|
612
|
+
// Let's assume the user wants me to explain/fix the perception.
|
|
613
|
+
// But wait, the user says "seharusnya tidak digenerate".
|
|
614
|
+
|
|
615
|
+
// Let's stick to the most robust interpretation:
|
|
616
|
+
// The user wants to avoid the overhead of generation for default stuff.
|
|
617
|
+
// But generation is fast (ms). Migration is slow.
|
|
618
|
+
|
|
619
|
+
// If the user means the `seed` data (Pets/Users):
|
|
620
|
+
// "user seeder dan pets itu selalu ada... jadi seharusnya tidak digenerate"
|
|
621
|
+
// Maybe the user means: Don't SEED them by default?
|
|
622
|
+
// "kecuali user mulai menggunakan framework ini dan menambahkan table baru"
|
|
623
|
+
|
|
624
|
+
// Let's assume the user is talking about the `prisma generate` process being redundant for default models.
|
|
625
|
+
// I need to explain that it IS required.
|
|
626
|
+
|
|
627
|
+
// BUT, I can make the process cleaner.
|
|
628
|
+
// If I look at the previous context: "postinstall" script.
|
|
629
|
+
// The user is replying to my explanation about "postinstall".
|
|
630
|
+
|
|
631
|
+
// User: "The default models (User/Pets) are always there. So they shouldn't need generation when creating a project. Generation should only happen when I add NEW tables."
|
|
632
|
+
|
|
633
|
+
// This is a misunderstanding of how Prisma works.
|
|
634
|
+
// Prisma Client is NOT installed via npm registry with the models pre-baked.
|
|
635
|
+
// It is an empty shell that fills itself when you run `prisma generate`.
|
|
636
|
+
|
|
637
|
+
// My previous explanation might have been unclear.
|
|
638
|
+
// I should clarify: "Generate is mandatory to install the library itself".
|
|
639
|
+
|
|
640
|
+
// HOWEVER, maybe I can PRE-GENERATE it?
|
|
641
|
+
// No, because it depends on the OS/Architecture of the user's machine.
|
|
642
|
+
|
|
643
|
+
// Let's try to satisfy the user's request by skipping the explicit `prisma generate` step in the CLI
|
|
644
|
+
// IF we rely on `prisma migrate dev` to do it automatically (it does generate client under the hood).
|
|
645
|
+
// Line 557: `execSync('npx prisma generate'...)`
|
|
646
|
+
// Line 561: `execSync('npx prisma migrate dev'...)` -> This AUTOMATICALLY runs generate.
|
|
647
|
+
|
|
648
|
+
// So line 557 is redundant! removing it speeds things up and reduces "generation" noise.
|
|
649
|
+
|
|
650
|
+
// Also, about "seeder":
|
|
651
|
+
// "seharusnya tidak digenerate saat user buuat project baru"
|
|
652
|
+
// If the user means the SEED FILE content.
|
|
653
|
+
// We are copying `prisma/seed.ts` from template.
|
|
654
|
+
|
|
655
|
+
// Let's remove the redundant `prisma generate` call in line 557.
|
|
656
|
+
// And I will explain to the user WHY generation is still needed (internally) but I removed the explicit step.
|
|
657
|
+
|
|
658
|
+
// Wait, if I remove `prisma generate`, `node scripts/compile-schema.js` must run before migrate.
|
|
659
|
+
// It does (Line 554).
|
|
660
|
+
|
|
661
|
+
// Let's remove the explicit `prisma generate` logging and command.
|
|
662
|
+
|
|
512
663
|
if (isFull) {
|
|
513
664
|
console.log(' Seeding database...');
|
|
514
665
|
execSync('npm run db:seed', { cwd: projectDir, stdio: 'inherit' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapeh",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"description": "Framework API Express yang siap pakai (Standardized)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -88,10 +88,7 @@
|
|
|
88
88
|
"winston": "^3.19.0",
|
|
89
89
|
"winston-daily-rotate-file": "^5.0.0",
|
|
90
90
|
"zod": "3.23.8",
|
|
91
|
-
"prisma": "7.2.0"
|
|
92
|
-
},
|
|
93
|
-
"devDependencies": {
|
|
94
|
-
"@eslint/js": "^9.39.2",
|
|
91
|
+
"prisma": "7.2.0",
|
|
95
92
|
"@types/bcryptjs": "2.4.6",
|
|
96
93
|
"@types/compression": "^1.8.1",
|
|
97
94
|
"@types/cors": "2.8.19",
|
|
@@ -100,7 +97,10 @@
|
|
|
100
97
|
"@types/multer": "^2.0.0",
|
|
101
98
|
"@types/node": "25.0.3",
|
|
102
99
|
"@types/pg": "8.16.0",
|
|
103
|
-
"@types/uuid": "10.0.0"
|
|
100
|
+
"@types/uuid": "10.0.0"
|
|
101
|
+
},
|
|
102
|
+
"devDependencies": {
|
|
103
|
+
"@eslint/js": "^9.39.2",
|
|
104
104
|
"eslint": "^9.39.2",
|
|
105
105
|
"globals": "^16.5.0",
|
|
106
106
|
"typescript-eslint": "^8.50.1"
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
PORT=8000
|
|
2
|
-
DATABASE_PROVIDER="postgresql"
|
|
3
|
-
DATABASE_URL="postgresql://sianu:12341234@localhost:5432/db_example_test?schema=public"
|
|
4
|
-
|
|
5
|
-
# Used for all encryption-related tasks in the framework (JWT, etc.)
|
|
6
|
-
JWT_SECRET="replace_this_with_a_secure_random_string"
|
|
7
|
-
|
|
8
|
-
# Framework Timezone
|
|
9
|
-
TZ="Asia/Jakarta"
|
|
10
|
-
|
|
11
|
-
# Redis Configuration (Optional)
|
|
12
|
-
# If REDIS_URL is not set or connection fails, the framework will automatically
|
|
13
|
-
# switch to an in-memory Redis mock (bundled). No installation required for development.
|
|
14
|
-
# REDIS_URL="redis://lapeh:12341234@localhost:6379"
|
|
15
|
-
# NO_REDIS="true"
|
|
16
|
-
|
|
17
|
-
# To force disable Redis and use in-memory mock even if Redis is available:
|
|
18
|
-
# NO_REDIS="true"
|
|
19
|
-
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Panduan Arsitektur: Menuju "Framework as a Dependency" (Next.js Style)
|
|
2
|
-
|
|
3
|
-
Saat ini, Lapeh menggunakan pendekatan **Boilerplate** (seperti Laravel), di mana pengguna mendapatkan seluruh kode sumber (`src/`) dan bertanggung jawab atas `express`, `prisma`, dll.
|
|
4
|
-
|
|
5
|
-
Untuk mengubahnya menjadi seperti **Next.js** (di mana pengguna hanya menginstall `lapeh` dan `package.json` mereka bersih), kita perlu mengubah arsitektur menjadi **Library**.
|
|
6
|
-
|
|
7
|
-
## 1. Perbedaan Utama
|
|
8
|
-
|
|
9
|
-
| Fitur | Boilerplate (Lapeh Saat Ini) | Library (Next.js Style) |
|
|
10
|
-
| :--- | :--- | :--- |
|
|
11
|
-
| **Instalasi** | `git clone` / `npx create-lapeh` | `npm install lapeh` |
|
|
12
|
-
| **package.json** | Banyak dependency (`express`, `cors`, dll) | Sedikit (`lapeh`, `react`) |
|
|
13
|
-
| **Scripts** | Panjang (`nodemon src/index.ts`) | Pendek (`lapeh dev`) |
|
|
14
|
-
| **Core Code** | Terbuka di `src/core/` | Tersembunyi di `node_modules/lapeh` |
|
|
15
|
-
| **Update** | Susah (harus merge manual) | Mudah (`npm update lapeh`) |
|
|
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
|
-
Saya sudah menambahkan command `dev`, `start`, dan `build` ke dalam CLI Lapeh. Ini memungkinkan pengguna menjalankan server tanpa tahu perintah aslinya.
|
|
23
|
-
|
|
24
|
-
```javascript
|
|
25
|
-
// Contoh penggunaan nanti:
|
|
26
|
-
"scripts": {
|
|
27
|
-
"dev": "lapeh dev",
|
|
28
|
-
"build": "lapeh build",
|
|
29
|
-
"start": "lapeh start"
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### B. Struktur Project Pengguna (Target)
|
|
34
|
-
Nantinya, project pengguna Lapeh hanya akan berisi file bisnis mereka:
|
|
35
|
-
|
|
36
|
-
```text
|
|
37
|
-
my-app/
|
|
38
|
-
├── src/
|
|
39
|
-
│ ├── controllers/
|
|
40
|
-
│ ├── routes/
|
|
41
|
-
│ └── models/
|
|
42
|
-
├── lapeh.config.ts <-- Konfigurasi framework (pengganti edit core)
|
|
43
|
-
└── package.json
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Dan `package.json` mereka akan terlihat seperti ini:
|
|
47
|
-
|
|
48
|
-
```json
|
|
49
|
-
{
|
|
50
|
-
"name": "my-app",
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"lapeh": "^2.0.0"
|
|
53
|
-
},
|
|
54
|
-
"scripts": {
|
|
55
|
-
"dev": "lapeh dev",
|
|
56
|
-
"build": "lapeh build",
|
|
57
|
-
"start": "lapeh start"
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### C. Apa yang Harus Dilakukan Selanjutnya?
|
|
63
|
-
|
|
64
|
-
1. **Publish Package**: Anda perlu mempublish folder framework ini ke NPM (atau private registry).
|
|
65
|
-
* Pastikan `express`, `cors`, `helmet`, dll ada di `dependencies` (bukan `devDependencies`).
|
|
66
|
-
2. **Abstraksi `src/index.ts`**:
|
|
67
|
-
* Saat ini `src/index.ts` adalah entry point yang diedit user.
|
|
68
|
-
* Ubah agar `lapeh dev` menjalankan server internal yang **mengimpor** routes/controller user secara dinamis (seperti Next.js pages router).
|
|
69
|
-
3. **Config Loader**:
|
|
70
|
-
* Buat sistem pembacaan `lapeh.config.ts` untuk mengatur Port, Database URL, dll tanpa mengedit kode core.
|
|
71
|
-
|
|
72
|
-
## 3. Kesimpulan
|
|
73
|
-
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).
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# Dokumentasi Perubahan Lapeh Framework
|
|
2
|
-
|
|
3
|
-
File ini mencatat semua perubahan, pembaruan, dan perbaikan yang dilakukan pada framework Lapeh, diurutkan berdasarkan tanggal.
|
|
4
|
-
|
|
5
|
-
## [2025-12-27] - Code Quality & Standardization Update
|
|
6
|
-
|
|
7
|
-
### 🚀 Fitur & Standarisasi
|
|
8
|
-
|
|
9
|
-
- **Standardized Import Paths**:
|
|
10
|
-
- Implementasi path alias `@/` untuk import yang lebih bersih (e.g., `import { prisma } from "@/core/database"`).
|
|
11
|
-
- Penghapusan penggunaan relative paths yang dalam (`../../../`).
|
|
12
|
-
- Konfigurasi `tsconfig.json` tanpa `baseUrl` (mengikuti standar TypeScript 6.0+).
|
|
13
|
-
- **Strict Linting & Code Quality**:
|
|
14
|
-
- Implementasi aturan **ESLint** ketat untuk mencegah "Dead Code".
|
|
15
|
-
- Error otomatis untuk variabel, parameter, dan import yang tidak digunakan (`no-unused-vars`).
|
|
16
|
-
- Script `npm run lint` dan `npm run lint:fix` untuk pembersihan kode otomatis.
|
|
17
|
-
- **Fastify-Style Standardization**:
|
|
18
|
-
- Penerapan standar respon cepat (`sendFastSuccess`) di seluruh controller (`AuthController`, `RbacController`, `PetController`).
|
|
19
|
-
- Penggunaan **Schema-based Serialization** untuk performa JSON maksimal.
|
|
20
|
-
- Konversi otomatis `BigInt` ke `string` dalam respon JSON.
|
|
21
|
-
|
|
22
|
-
## [2025-12-27] - High Performance & Scalability Update
|
|
23
|
-
|
|
24
|
-
### 🚀 Fitur Baru
|
|
25
|
-
|
|
26
|
-
- **High Performance Serialization (Fastify-Style)**:
|
|
27
|
-
- Implementasi `fast-json-stringify` untuk serialisasi JSON super cepat (2x-3x lebih cepat dari `JSON.stringify`).
|
|
28
|
-
- Helper `sendFastSuccess` di `src/utils/response.ts` untuk mem-bypass overhead Express.
|
|
29
|
-
- Caching schema serializer otomatis di `src/core/serializer.ts`.
|
|
30
|
-
- **Scalability & Clustering**:
|
|
31
|
-
- Dukungan **Load Balancing** dengan Nginx.
|
|
32
|
-
- Dukungan **Redis Clustering** untuk Rate Limiter (`rate-limit-redis`).
|
|
33
|
-
- File konfigurasi `docker-compose.cluster.yml` untuk simulasi cluster lokal (1 Nginx + 2 App Instances + 1 Redis).
|
|
34
|
-
- **Smart Error Handling**:
|
|
35
|
-
- Deteksi otomatis port bentrok (`EADDRINUSE`) saat startup.
|
|
36
|
-
- Memberikan saran command _copy-paste_ untuk mematikan process yang memblokir port (support Windows, Mac, Linux).
|
|
37
|
-
- **SEO Optimization**:
|
|
38
|
-
- Update metadata `package.json` dan `README.md` agar framework lebih mudah ditemukan di Google/NPM.
|
|
39
|
-
|
|
40
|
-
## [2025-12-27] - Pembaruan Struktur & Validasi
|
|
41
|
-
|
|
42
|
-
### 🚀 Fitur Baru
|
|
43
|
-
|
|
44
|
-
- **Laravel-style Validator**:
|
|
45
|
-
- Implementasi utility `Validator` baru di `src/utils/validator.ts` yang meniru gaya validasi Laravel.
|
|
46
|
-
- Mendukung rule string seperti `required|string|min:3|email`.
|
|
47
|
-
- Penambahan rule `unique` untuk pengecekan database otomatis (Prisma).
|
|
48
|
-
- Penambahan rule `mimes`, `image`, `max` (file size) untuk validasi upload file.
|
|
49
|
-
- Penambahan rule `sometimes` untuk field opsional.
|
|
50
|
-
- **Framework Hardening (Keamanan & Stabilitas)**:
|
|
51
|
-
- **Rate Limiting**: Middleware anti-spam/brute-force di `src/middleware/rateLimit.ts`.
|
|
52
|
-
- **Request Logger**: Pencatatan log request masuk di `src/middleware/requestLogger.ts`.
|
|
53
|
-
- **Health Check**: Endpoint `/` kini mengembalikan status kesehatan server.
|
|
54
|
-
- **Graceful Shutdown**: Penanganan penutupan koneksi Database dan Redis yang aman saat server berhenti (`SIGTERM`/`SIGINT`).
|
|
55
|
-
- **Environment Validation**: Validasi variabel `.env` wajib (seperti `DATABASE_URL`, `JWT_SECRET`) saat startup.
|
|
56
|
-
- **Struktur Folder Baru**:
|
|
57
|
-
- Pemisahan konfigurasi inti ke `src/core/` (`server.ts`, `database.ts`, `redis.ts`, `realtime.ts`) agar folder `src` lebih bersih.
|
|
58
|
-
- Sentralisasi route di `src/routes/index.ts` (WIP).
|
|
59
|
-
- **CLI Improvements**:
|
|
60
|
-
- `npx lapeh <project-name> --full` kini otomatis menjalankan server dev setelah instalasi selesai, sehingga user bisa langsung melihat hasil tanpa mengetik perintah tambahan.
|
|
61
|
-
|
|
62
|
-
### 🛠️ Perbaikan & Refactoring
|
|
63
|
-
|
|
64
|
-
- **Controller Refactoring**:
|
|
65
|
-
- `AuthController`: Migrasi ke `Validator` baru, termasuk validasi upload avatar.
|
|
66
|
-
- `PetController`: Migrasi ke `Validator` baru.
|
|
67
|
-
- `RbacController`: Migrasi sebagian ke `Validator` baru.
|
|
68
|
-
- **Pembersihan**:
|
|
69
|
-
- Penghapusan folder `src/schema/` (Zod schema lama) karena sudah digantikan oleh `Validator` utility.
|
|
70
|
-
- Penghapusan file duplikat/lama di root `src/` setelah migrasi ke `src/core/`.
|
|
71
|
-
|
|
72
|
-
### 📝 Catatan Teknis
|
|
73
|
-
|
|
74
|
-
- **Validator Async**: Method `fails()`, `passes()`, dan `validated()` kini bersifat `async` untuk mendukung pengecekan database (`unique`).
|
|
75
|
-
- **Type Safety**: Semua perubahan telah diverifikasi dengan `npm run typecheck`.
|
|
76
|
-
|
|
77
|
-
---
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# Lapeh 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>`** | Buat Controller, Route, & Model sekaligus. |
|
|
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
|
-
| **`npm run db:seed`** | Isi data dummy. |
|
|
19
|
-
| **`npm run db:reset`** | Hapus DB & mulai dari nol. |
|
|
20
|
-
|
|
21
|
-
## 🛡️ Validator Rules (Laravel-Style)
|
|
22
|
-
|
|
23
|
-
Gunakan di `Validator.make(data, rules)`.
|
|
24
|
-
|
|
25
|
-
| Rule | Deskripsi | Contoh |
|
|
26
|
-
| :----------------- | :---------------------- | :---------------------------------- | -------- |
|
|
27
|
-
| `required` | Wajib ada & tidak null. | `"required"` |
|
|
28
|
-
| `string` | Harus text. | `"required | string"` |
|
|
29
|
-
| `number` | Harus angka. | `"required | number"` |
|
|
30
|
-
| `email` | Format email valid. | `"required | email"` |
|
|
31
|
-
| `min:X` | Min panjang/nilai. | `"min:8"` (pass), `"min:18"` (umur) |
|
|
32
|
-
| `max:X` | Max panjang/nilai. | `"max:255"` |
|
|
33
|
-
| `unique:table,col` | Cek unik di DB. | `"unique:users,email"` |
|
|
34
|
-
| `exists:table,col` | Cek exist di DB. | `"exists:roles,id"` |
|
|
35
|
-
| `image` | File harus gambar. | `"required | image"` |
|
|
36
|
-
| `mimes:types` | File extension. | `"mimes:pdf,docx"` |
|
|
37
|
-
|
|
38
|
-
## 🔑 Authentication
|
|
39
|
-
|
|
40
|
-
**Middleware di Route:**
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { requireAuth, requireAdmin } from "@/middleware/auth";
|
|
44
|
-
|
|
45
|
-
router.get("/profile", requireAuth, getProfile); // Login User
|
|
46
|
-
router.delete("/user", requireAuth, requireAdmin, del); // Admin Only
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
**Akses User di Controller:**
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
// (req as any).user tersedia setelah requireAuth
|
|
53
|
-
const userId = (req as any).user.userId;
|
|
54
|
-
const role = (req as any).user.role;
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## ⚡ Fast Response (Serializer)
|
|
58
|
-
|
|
59
|
-
**1. Schema:**
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
const schema = {
|
|
63
|
-
type: "object",
|
|
64
|
-
properties: {
|
|
65
|
-
id: { type: "string" },
|
|
66
|
-
name: { type: "string" },
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**2. Serializer:**
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
const serializer = getSerializer("key-name", createResponseSchema(schema));
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
**3. Send:**
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
sendFastSuccess(res, 200, serializer, { ...data });
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## 📦 Redis (Cache)
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import { redis } from "@lapeh/core/redis";
|
|
87
|
-
|
|
88
|
-
// Set Cache (Key, Value, Mode, Detik)
|
|
89
|
-
await redis.set("profile:1", JSON.stringify(data), "EX", 3600);
|
|
90
|
-
|
|
91
|
-
// Get Cache
|
|
92
|
-
const cached = await redis.get("profile:1");
|
|
93
|
-
if (cached) return JSON.parse(cached);
|
|
94
|
-
```
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# CLI Tools & Scripts
|
|
2
|
-
|
|
3
|
-
Lapeh Framework dilengkapi dengan berbagai script CLI untuk mempercepat proses development, mulai dari generate code hingga manajemen database.
|
|
4
|
-
|
|
5
|
-
Semua perintah dijalankan menggunakan `npm run <command>`.
|
|
6
|
-
|
|
7
|
-
## Code Generators
|
|
8
|
-
|
|
9
|
-
Gunakan perintah ini untuk membuat file boilerplate secara otomatis.
|
|
10
|
-
|
|
11
|
-
### 1. Membuat Module Lengkap (`make:module`)
|
|
12
|
-
Membuat Controller, Route, dan Model (Schema) sekaligus.
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npm run make:module <nama-module>
|
|
16
|
-
```
|
|
17
|
-
**Contoh:** `npm run make:module Product`
|
|
18
|
-
|
|
19
|
-
Output:
|
|
20
|
-
- `src/controllers/productController.ts`
|
|
21
|
-
- `src/routes/product.ts`
|
|
22
|
-
- `src/models/product.prisma`
|
|
23
|
-
|
|
24
|
-
### 2. Membuat Controller (`make:controller`)
|
|
25
|
-
Hanya membuat file controller dengan method CRUD dasar.
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm run make:controller <nama-controller>
|
|
29
|
-
```
|
|
30
|
-
**Contoh:** `npm run make:controller Order` (Akan membuat `src/controllers/orderController.ts`)
|
|
31
|
-
|
|
32
|
-
### 3. Membuat Model Database (`make:model`)
|
|
33
|
-
Hanya membuat file schema Prisma baru.
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm run make:model <nama-model>
|
|
37
|
-
```
|
|
38
|
-
**Contoh:** `npm run make:model Transaction` (Akan membuat `src/models/transaction.prisma`)
|
|
39
|
-
|
|
40
|
-
## Database Management (Prisma)
|
|
41
|
-
|
|
42
|
-
Framework ini menggunakan sistem **Multi-File Schema**. Anda tidak mengedit `schema.prisma` secara langsung, melainkan mengedit file kecil di `src/models/*.prisma`.
|
|
43
|
-
|
|
44
|
-
### 1. Migrasi Database (`prisma:migrate`)
|
|
45
|
-
Jalankan setiap kali Anda mengubah definisi model di `src/models/*.prisma`.
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npm run prisma:migrate
|
|
49
|
-
```
|
|
50
|
-
Perintah ini akan:
|
|
51
|
-
1. Menggabungkan semua file `.prisma` di `src/models/` menjadi satu `prisma/schema.prisma`.
|
|
52
|
-
2. Membuat file migrasi SQL.
|
|
53
|
-
3. Menerapkan perubahan ke database lokal.
|
|
54
|
-
4. Men-generate ulang Prisma Client (Type Definitions).
|
|
55
|
-
|
|
56
|
-
### 2. Deploy ke Production (`prisma:deploy`)
|
|
57
|
-
Gunakan di server production. Hanya menerapkan migrasi yang sudah ada tanpa reset data.
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm run prisma:deploy
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### 3. Database Studio (`db:studio`)
|
|
64
|
-
Membuka GUI di browser untuk melihat dan mengedit data database.
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
npm run db:studio
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 4. Seeding Data (`db:seed`)
|
|
71
|
-
Mengisi database dengan data awal yang didefinisikan di `prisma/seed.ts`.
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
npm run db:seed
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### 5. Reset Database (`db:reset`)
|
|
78
|
-
**PERINGATAN:** Menghapus semua data dan tabel, lalu menjalankan migrasi dari awal.
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npm run db:reset
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Code Quality & Utilities
|
|
85
|
-
|
|
86
|
-
### 1. Linting (`lint`)
|
|
87
|
-
Memeriksa kode dari error, variabel tidak terpakai, dan gaya penulisan.
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
npm run lint
|
|
91
|
-
```
|
|
92
|
-
Gunakan `npm run lint:fix` untuk memperbaiki error otomatis.
|
|
93
|
-
|
|
94
|
-
### 2. Type Check (`typecheck`)
|
|
95
|
-
Memeriksa error tipe data TypeScript tanpa melakukan compile.
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
npm run typecheck
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### 3. Generate JWT Secret (`generate:jwt`)
|
|
102
|
-
Membuat random string aman untuk `JWT_SECRET` di file `.env`.
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
npm run generate:jwt
|
|
106
|
-
```
|