millas 0.2.12-beta → 0.2.12-beta-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 (116) hide show
  1. package/package.json +3 -16
  2. package/src/admin/ActivityLog.js +153 -52
  3. package/src/admin/Admin.js +400 -167
  4. package/src/admin/AdminAuth.js +213 -98
  5. package/src/admin/FormGenerator.js +372 -0
  6. package/src/admin/HookRegistry.js +256 -0
  7. package/src/admin/QueryEngine.js +263 -0
  8. package/src/admin/ViewContext.js +309 -0
  9. package/src/admin/WidgetRegistry.js +406 -0
  10. package/src/admin/index.js +17 -0
  11. package/src/admin/resources/AdminResource.js +383 -97
  12. package/src/admin/static/admin.css +1341 -0
  13. package/src/admin/static/date-picker.css +157 -0
  14. package/src/admin/static/date-picker.js +316 -0
  15. package/src/admin/static/json-editor.css +649 -0
  16. package/src/admin/static/json-editor.js +1429 -0
  17. package/src/admin/static/ui.js +1044 -0
  18. package/src/admin/views/layouts/base.njk +65 -1013
  19. package/src/admin/views/pages/detail.njk +40 -16
  20. package/src/admin/views/pages/form.njk +47 -599
  21. package/src/admin/views/pages/list.njk +145 -62
  22. package/src/admin/views/partials/form-field.njk +53 -0
  23. package/src/admin/views/partials/form-footer.njk +28 -0
  24. package/src/admin/views/partials/form-readonly.njk +114 -0
  25. package/src/admin/views/partials/form-scripts.njk +476 -0
  26. package/src/admin/views/partials/form-widget.njk +296 -0
  27. package/src/admin/views/partials/json-dialog.njk +80 -0
  28. package/src/admin/views/partials/json-editor.njk +37 -0
  29. package/src/admin.zip +0 -0
  30. package/src/auth/Auth.js +31 -10
  31. package/src/auth/AuthController.js +3 -1
  32. package/src/auth/AuthUser.js +119 -0
  33. package/src/cli.js +4 -2
  34. package/src/commands/createsuperuser.js +254 -0
  35. package/src/commands/lang.js +589 -0
  36. package/src/commands/migrate.js +154 -81
  37. package/src/commands/serve.js +82 -110
  38. package/src/container/AppInitializer.js +215 -0
  39. package/src/container/Application.js +278 -253
  40. package/src/container/HttpServer.js +156 -0
  41. package/src/container/MillasApp.js +29 -279
  42. package/src/container/MillasConfig.js +192 -0
  43. package/src/core/admin.js +5 -0
  44. package/src/core/auth.js +9 -0
  45. package/src/core/db.js +9 -0
  46. package/src/core/foundation.js +59 -0
  47. package/src/core/http.js +11 -0
  48. package/src/core/lang.js +1 -0
  49. package/src/core/mail.js +6 -0
  50. package/src/core/queue.js +7 -0
  51. package/src/core/validation.js +29 -0
  52. package/src/facades/Admin.js +1 -1
  53. package/src/facades/Auth.js +22 -39
  54. package/src/facades/Cache.js +21 -10
  55. package/src/facades/Database.js +1 -1
  56. package/src/facades/Events.js +18 -17
  57. package/src/facades/Facade.js +197 -0
  58. package/src/facades/Http.js +42 -45
  59. package/src/facades/Log.js +25 -49
  60. package/src/facades/Mail.js +27 -32
  61. package/src/facades/Queue.js +22 -15
  62. package/src/facades/Storage.js +18 -10
  63. package/src/facades/Url.js +53 -0
  64. package/src/http/HttpClient.js +673 -0
  65. package/src/http/ResponseDispatcher.js +18 -111
  66. package/src/http/UrlGenerator.js +375 -0
  67. package/src/http/WelcomePage.js +273 -0
  68. package/src/http/adapters/ExpressAdapter.js +315 -0
  69. package/src/http/adapters/HttpAdapter.js +168 -0
  70. package/src/http/adapters/index.js +9 -0
  71. package/src/i18n/I18nServiceProvider.js +91 -0
  72. package/src/i18n/Translator.js +635 -0
  73. package/src/i18n/defaults.js +122 -0
  74. package/src/i18n/index.js +164 -0
  75. package/src/i18n/locales/en.js +55 -0
  76. package/src/i18n/locales/sw.js +48 -0
  77. package/src/index.js +5 -144
  78. package/src/logger/formatters/PrettyFormatter.js +103 -57
  79. package/src/logger/internal.js +2 -2
  80. package/src/logger/patchConsole.js +91 -81
  81. package/src/middleware/MiddlewareRegistry.js +62 -82
  82. package/src/migrations/system/0001_users.js +21 -0
  83. package/src/migrations/system/0002_admin_log.js +25 -0
  84. package/src/migrations/system/0003_sessions.js +23 -0
  85. package/src/orm/fields/index.js +210 -188
  86. package/src/orm/migration/DefaultValueParser.js +325 -0
  87. package/src/orm/migration/InteractiveResolver.js +191 -0
  88. package/src/orm/migration/Makemigrations.js +312 -0
  89. package/src/orm/migration/MigrationGraph.js +227 -0
  90. package/src/orm/migration/MigrationRunner.js +202 -108
  91. package/src/orm/migration/MigrationWriter.js +463 -0
  92. package/src/orm/migration/ModelInspector.js +412 -344
  93. package/src/orm/migration/ModelScanner.js +225 -0
  94. package/src/orm/migration/ProjectState.js +213 -0
  95. package/src/orm/migration/RenameDetector.js +175 -0
  96. package/src/orm/migration/SchemaBuilder.js +8 -81
  97. package/src/orm/migration/operations/base.js +57 -0
  98. package/src/orm/migration/operations/column.js +191 -0
  99. package/src/orm/migration/operations/fields.js +252 -0
  100. package/src/orm/migration/operations/index.js +55 -0
  101. package/src/orm/migration/operations/models.js +152 -0
  102. package/src/orm/migration/operations/registry.js +131 -0
  103. package/src/orm/migration/operations/special.js +51 -0
  104. package/src/orm/migration/utils.js +208 -0
  105. package/src/orm/model/Model.js +81 -13
  106. package/src/providers/AdminServiceProvider.js +66 -9
  107. package/src/providers/AuthServiceProvider.js +46 -7
  108. package/src/providers/CacheStorageServiceProvider.js +5 -3
  109. package/src/providers/DatabaseServiceProvider.js +3 -2
  110. package/src/providers/EventServiceProvider.js +2 -1
  111. package/src/providers/LogServiceProvider.js +7 -3
  112. package/src/providers/MailServiceProvider.js +4 -3
  113. package/src/providers/QueueServiceProvider.js +4 -3
  114. package/src/router/Router.js +119 -152
  115. package/src/scaffold/templates.js +83 -26
  116. package/src/facades/Validation.js +0 -69
@@ -12,6 +12,8 @@ function getProjectFiles(projectName) {
12
12
  scripts: {
13
13
  start: 'node bootstrap/app.js',
14
14
  dev: 'millas serve',
15
+ makemigrations: 'millas makemigration',
16
+ migrate: 'millas migrate',
15
17
  serve: 'millas serve',
16
18
  },
17
19
  dependencies: {
@@ -66,21 +68,6 @@ storage/logs/*.log
66
68
  storage/uploads/*
67
69
  !storage/uploads/.gitkeep
68
70
  database/database.sqlite
69
- `,
70
-
71
- // ─── millas.config.js ─────────────────────────────────────────
72
- 'millas.config.js': `'use strict';
73
-
74
- module.exports = {
75
- /*
76
- |--------------------------------------------------------------------------
77
- | Millas Framework Configuration
78
- |--------------------------------------------------------------------------
79
- */
80
- providers: [
81
- './providers/AppServiceProvider',
82
- ],
83
- };
84
71
  `,
85
72
 
86
73
  // ─── bootstrap/app.js ─────────────────────────────────────────
@@ -88,18 +75,31 @@ module.exports = {
88
75
 
89
76
  require('dotenv').config();
90
77
 
91
- const { MillasApp } = require('millas');
78
+ const path = require('path');
79
+ const { Millas } = require('millas');
92
80
  const AppServiceProvider = require('../providers/AppServiceProvider');
93
81
 
94
- const app = MillasApp.create()
95
- .providers([AppServiceProvider])
82
+ /**
83
+ * Application configuration and bootstrap.
84
+ *
85
+ * Millas.configure(__dirname/..) sets the project root so the framework
86
+ * locates config files, models, and routes without guessing.
87
+ *
88
+ * Core providers (Database, Auth, Admin, Cache, Mail, Queue, Events)
89
+ * are wired automatically — only add your own app providers below.
90
+ *
91
+ * First-time setup:
92
+ * millas migrate # creates system tables (users, admin_log, sessions)
93
+ * millas createsuperuser # creates your first admin panel user
94
+ */
95
+ module.exports = Millas.configure(path.join(__dirname, '..'))
96
+ .withAdmin()
96
97
  .routes(Route => {
97
98
  require('../routes/web')(Route);
98
99
  require('../routes/api')(Route);
99
100
  })
100
- .withAdmin();
101
-
102
- module.exports = app.start();
101
+ .providers([AppServiceProvider])
102
+ .create();
103
103
  `,
104
104
 
105
105
  // ─── routes/web.js ────────────────────────────────────────────
@@ -152,7 +152,12 @@ module.exports = {
152
152
  key: process.env.APP_KEY || '',
153
153
  debug: process.env.APP_ENV !== 'production',
154
154
  timezone: 'UTC',
155
- locale: 'en',
155
+ locale: 'en',
156
+ fallback: 'en',
157
+
158
+ // Set use_i18n: true to enable the translation system.
159
+ // Then run: millas lang:publish <locale>
160
+ use_i18n: false,
156
161
  };
157
162
  `,
158
163
 
@@ -214,6 +219,50 @@ module.exports = {
214
219
  expiresIn: '1h',
215
220
  },
216
221
  };
222
+ `,
223
+
224
+ // ─── config/admin.js ──────────────────────────────────────────
225
+ 'config/admin.js': `'use strict';
226
+
227
+ /**
228
+ * Admin Panel Configuration
229
+ *
230
+ * Credentials are read from environment variables by default.
231
+ * Set ADMIN_EMAIL and ADMIN_PASSWORD in your .env file, or define
232
+ * static users / a model here.
233
+ */
234
+ module.exports = {
235
+ // URL prefix for the admin panel
236
+ prefix: '/admin',
237
+
238
+ // Title shown in the browser tab and sidebar
239
+ title: process.env.APP_NAME ? \`\${process.env.APP_NAME} Admin\` : 'Millas Admin',
240
+
241
+ auth: {
242
+ // ── Option 1: static user list (simple setups / local dev) ────
243
+ users: [
244
+ {
245
+ email: process.env.ADMIN_EMAIL || 'admin@example.com',
246
+ // Use a bcrypt hash in production; plain text is fine for local dev.
247
+ password: process.env.ADMIN_PASSWORD || 'change-me',
248
+ name: process.env.ADMIN_NAME || 'Admin',
249
+ },
250
+ ],
251
+
252
+ // ── Option 2: model-based lookup ──────────────────────────────
253
+ // Uncomment and set to any Millas Model that has email + password fields.
254
+ // model: require('../app/models/User'),
255
+
256
+ // ── Session cookie settings ───────────────────────────────────
257
+ cookieName: 'millas_admin',
258
+ cookieMaxAge: 60 * 60 * 8, // 8 hours
259
+ rememberAge: 60 * 60 * 24 * 30, // 30 days ("remember me")
260
+
261
+ // ── Brute-force protection ────────────────────────────────────
262
+ maxAttempts: 5,
263
+ lockoutMinutes: 15,
264
+ },
265
+ };
217
266
  `,
218
267
 
219
268
  // ─── config/mail.js ───────────────────────────────────────────
@@ -242,7 +291,7 @@ module.exports = {
242
291
  // ─── providers/AppServiceProvider.js ──────────────────────────
243
292
  'providers/AppServiceProvider.js': `'use strict';
244
293
 
245
- const { ServiceProvider } = require('millas');
294
+ const { ServiceProvider } = require('millas/core/foundation');
246
295
 
247
296
  /**
248
297
  * AppServiceProvider
@@ -263,10 +312,18 @@ class AppServiceProvider extends ServiceProvider {
263
312
  }
264
313
 
265
314
  async boot(container, app) {
266
- // Register Admin resources:
315
+ // Register Admin resources — Admin panel is auto-mounted via .withAdmin()
267
316
  // const { Admin } = require('millas');
317
+ // const { AdminResource, AdminField } = require('millas');
268
318
  // const Post = require('../app/models/Post');
269
- // Admin.register(Post);
319
+ //
320
+ // class PostResource extends AdminResource {
321
+ // static model = Post;
322
+ // static label = 'Posts';
323
+ // static searchable = ['title', 'body'];
324
+ // }
325
+ //
326
+ // Admin.register(PostResource);
270
327
  }
271
328
  }
272
329
 
@@ -326,4 +383,4 @@ providers/ # Service providers
326
383
  };
327
384
  }
328
385
 
329
- module.exports = { getProjectFiles };
386
+ module.exports = { getProjectFiles };
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * millas/facades/Validation
5
- *
6
- * Field validators and schema runner.
7
- *
8
- * const { string, email, number, boolean, date, array, object, file, Validator }
9
- * = require('millas/facades/Validation');
10
- *
11
- * Route.post('/register', async ({ body }) => {
12
- * const data = await body.validate({
13
- * name: string('Must be text').required('Name is required').min(2).max(100),
14
- * email: email().required(),
15
- * age: number().optional().min(0).max(120),
16
- * password: string().required().min(8).confirmed(),
17
- * role: string().oneOf(['admin','user']).default('user'),
18
- * tags: array().of(string().required()).optional(),
19
- * address: object({
20
- * city: string().required(),
21
- * zip: string().matches(/^\d{5}$/, 'Invalid ZIP'),
22
- * }).optional(),
23
- * avatar: file().optional().image().maxSize('2mb'),
24
- * });
25
- * return jsonify(await User.create(data), { status: 201 });
26
- * });
27
- */
28
-
29
- const {
30
- Validator,
31
- BaseValidator,
32
- StringValidator,
33
- EmailValidator,
34
- NumberValidator,
35
- BooleanValidator,
36
- DateValidator,
37
- ArrayValidator,
38
- ObjectValidator,
39
- FileValidator,
40
- string,
41
- email,
42
- number,
43
- boolean,
44
- date,
45
- array,
46
- } = require('../index');
47
-
48
- const { object, file } = require('../validation/Validator');
49
-
50
- module.exports = {
51
- Validator,
52
- BaseValidator,
53
- StringValidator,
54
- EmailValidator,
55
- NumberValidator,
56
- BooleanValidator,
57
- DateValidator,
58
- ArrayValidator,
59
- ObjectValidator,
60
- FileValidator,
61
- string,
62
- email,
63
- number,
64
- boolean,
65
- date,
66
- array,
67
- object,
68
- file,
69
- };