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.
- package/package.json +3 -16
- package/src/admin/ActivityLog.js +153 -52
- package/src/admin/Admin.js +400 -167
- package/src/admin/AdminAuth.js +213 -98
- package/src/admin/FormGenerator.js +372 -0
- package/src/admin/HookRegistry.js +256 -0
- package/src/admin/QueryEngine.js +263 -0
- package/src/admin/ViewContext.js +309 -0
- package/src/admin/WidgetRegistry.js +406 -0
- package/src/admin/index.js +17 -0
- package/src/admin/resources/AdminResource.js +383 -97
- package/src/admin/static/admin.css +1341 -0
- package/src/admin/static/date-picker.css +157 -0
- package/src/admin/static/date-picker.js +316 -0
- package/src/admin/static/json-editor.css +649 -0
- package/src/admin/static/json-editor.js +1429 -0
- package/src/admin/static/ui.js +1044 -0
- package/src/admin/views/layouts/base.njk +65 -1013
- package/src/admin/views/pages/detail.njk +40 -16
- package/src/admin/views/pages/form.njk +47 -599
- package/src/admin/views/pages/list.njk +145 -62
- package/src/admin/views/partials/form-field.njk +53 -0
- package/src/admin/views/partials/form-footer.njk +28 -0
- package/src/admin/views/partials/form-readonly.njk +114 -0
- package/src/admin/views/partials/form-scripts.njk +476 -0
- package/src/admin/views/partials/form-widget.njk +296 -0
- package/src/admin/views/partials/json-dialog.njk +80 -0
- package/src/admin/views/partials/json-editor.njk +37 -0
- package/src/admin.zip +0 -0
- package/src/auth/Auth.js +31 -10
- package/src/auth/AuthController.js +3 -1
- package/src/auth/AuthUser.js +119 -0
- package/src/cli.js +4 -2
- package/src/commands/createsuperuser.js +254 -0
- package/src/commands/lang.js +589 -0
- package/src/commands/migrate.js +154 -81
- package/src/commands/serve.js +82 -110
- package/src/container/AppInitializer.js +215 -0
- package/src/container/Application.js +278 -253
- package/src/container/HttpServer.js +156 -0
- package/src/container/MillasApp.js +29 -279
- package/src/container/MillasConfig.js +192 -0
- package/src/core/admin.js +5 -0
- package/src/core/auth.js +9 -0
- package/src/core/db.js +9 -0
- package/src/core/foundation.js +59 -0
- package/src/core/http.js +11 -0
- package/src/core/lang.js +1 -0
- package/src/core/mail.js +6 -0
- package/src/core/queue.js +7 -0
- package/src/core/validation.js +29 -0
- package/src/facades/Admin.js +1 -1
- package/src/facades/Auth.js +22 -39
- package/src/facades/Cache.js +21 -10
- package/src/facades/Database.js +1 -1
- package/src/facades/Events.js +18 -17
- package/src/facades/Facade.js +197 -0
- package/src/facades/Http.js +42 -45
- package/src/facades/Log.js +25 -49
- package/src/facades/Mail.js +27 -32
- package/src/facades/Queue.js +22 -15
- package/src/facades/Storage.js +18 -10
- package/src/facades/Url.js +53 -0
- package/src/http/HttpClient.js +673 -0
- package/src/http/ResponseDispatcher.js +18 -111
- package/src/http/UrlGenerator.js +375 -0
- package/src/http/WelcomePage.js +273 -0
- package/src/http/adapters/ExpressAdapter.js +315 -0
- package/src/http/adapters/HttpAdapter.js +168 -0
- package/src/http/adapters/index.js +9 -0
- package/src/i18n/I18nServiceProvider.js +91 -0
- package/src/i18n/Translator.js +635 -0
- package/src/i18n/defaults.js +122 -0
- package/src/i18n/index.js +164 -0
- package/src/i18n/locales/en.js +55 -0
- package/src/i18n/locales/sw.js +48 -0
- package/src/index.js +5 -144
- package/src/logger/formatters/PrettyFormatter.js +103 -57
- package/src/logger/internal.js +2 -2
- package/src/logger/patchConsole.js +91 -81
- package/src/middleware/MiddlewareRegistry.js +62 -82
- package/src/migrations/system/0001_users.js +21 -0
- package/src/migrations/system/0002_admin_log.js +25 -0
- package/src/migrations/system/0003_sessions.js +23 -0
- package/src/orm/fields/index.js +210 -188
- package/src/orm/migration/DefaultValueParser.js +325 -0
- package/src/orm/migration/InteractiveResolver.js +191 -0
- package/src/orm/migration/Makemigrations.js +312 -0
- package/src/orm/migration/MigrationGraph.js +227 -0
- package/src/orm/migration/MigrationRunner.js +202 -108
- package/src/orm/migration/MigrationWriter.js +463 -0
- package/src/orm/migration/ModelInspector.js +412 -344
- package/src/orm/migration/ModelScanner.js +225 -0
- package/src/orm/migration/ProjectState.js +213 -0
- package/src/orm/migration/RenameDetector.js +175 -0
- package/src/orm/migration/SchemaBuilder.js +8 -81
- package/src/orm/migration/operations/base.js +57 -0
- package/src/orm/migration/operations/column.js +191 -0
- package/src/orm/migration/operations/fields.js +252 -0
- package/src/orm/migration/operations/index.js +55 -0
- package/src/orm/migration/operations/models.js +152 -0
- package/src/orm/migration/operations/registry.js +131 -0
- package/src/orm/migration/operations/special.js +51 -0
- package/src/orm/migration/utils.js +208 -0
- package/src/orm/model/Model.js +81 -13
- package/src/providers/AdminServiceProvider.js +66 -9
- package/src/providers/AuthServiceProvider.js +46 -7
- package/src/providers/CacheStorageServiceProvider.js +5 -3
- package/src/providers/DatabaseServiceProvider.js +3 -2
- package/src/providers/EventServiceProvider.js +2 -1
- package/src/providers/LogServiceProvider.js +7 -3
- package/src/providers/MailServiceProvider.js +4 -3
- package/src/providers/QueueServiceProvider.js +4 -3
- package/src/router/Router.js +119 -152
- package/src/scaffold/templates.js +83 -26
- package/src/facades/Validation.js +0 -69
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const express = require('express');
|
|
4
|
+
const Application = require('./Application');
|
|
5
|
+
const HttpServer = require('./HttpServer');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* AppInitialiser
|
|
9
|
+
*
|
|
10
|
+
* The internal engine that receives what bootstrap/app.js exports
|
|
11
|
+
* (a MillasInstance), extracts its config, and wires up everything:
|
|
12
|
+
*
|
|
13
|
+
* - ExpressAdapter
|
|
14
|
+
* - Application kernel (DI container, providers, routes, middleware)
|
|
15
|
+
* - Admin panel
|
|
16
|
+
* - HttpServer (port, signals, startup log, IPC ready signal)
|
|
17
|
+
*
|
|
18
|
+
* Developers never see or interact with this class.
|
|
19
|
+
* It is used exclusively by runner.js (millas serve) and the no-reload path.
|
|
20
|
+
*
|
|
21
|
+
* ── Flow ─────────────────────────────────────────────────────────────────────
|
|
22
|
+
*
|
|
23
|
+
* bootstrap/app.js → MillasInstance → AppInitialiser.boot()
|
|
24
|
+
* ├─ builds ExpressAdapter
|
|
25
|
+
* ├─ builds Application
|
|
26
|
+
* ├─ registers core providers
|
|
27
|
+
* │ Log → Database → Auth → Admin
|
|
28
|
+
* │ → Cache → Mail → Queue → Events
|
|
29
|
+
* ├─ registers app providers
|
|
30
|
+
* ├─ registers routes
|
|
31
|
+
* ├─ registers middleware aliases
|
|
32
|
+
* ├─ boots all providers
|
|
33
|
+
* ├─ mounts routes
|
|
34
|
+
* ├─ mounts admin panel
|
|
35
|
+
* ├─ mounts fallbacks
|
|
36
|
+
* └─ starts HttpServer
|
|
37
|
+
*/
|
|
38
|
+
class AppInitializer {
|
|
39
|
+
/**
|
|
40
|
+
* @param {Object} config — the sealed export of bootstrap/app.js
|
|
41
|
+
*/
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this._config = config;
|
|
44
|
+
this._kernel = null;
|
|
45
|
+
this._adapter = null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Boot the full application and start the HTTP server.
|
|
50
|
+
* Returns a Promise that resolves once the server is listening.
|
|
51
|
+
*/
|
|
52
|
+
async boot() {
|
|
53
|
+
const cfg = this._config;
|
|
54
|
+
|
|
55
|
+
// ── Build the HTTP adapter ───────────────────────────────────────────────
|
|
56
|
+
const ExpressAdapter = require('../http/adapters/ExpressAdapter');
|
|
57
|
+
const expressApp = express();
|
|
58
|
+
this._adapter = new ExpressAdapter(expressApp);
|
|
59
|
+
this._adapter.applyBodyParsers();
|
|
60
|
+
|
|
61
|
+
// Raw adapter middleware (helmet, compression, etc.)
|
|
62
|
+
for (const mw of (cfg.adapterMiddleware || [])) {
|
|
63
|
+
this._adapter.applyMiddleware(mw);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── Build the Application kernel ─────────────────────────────────────────
|
|
67
|
+
this._kernel = new Application(this._adapter);
|
|
68
|
+
|
|
69
|
+
// Bind basePath so all providers can resolve config/model paths
|
|
70
|
+
// without calling process.cwd() at runtime.
|
|
71
|
+
const basePath = cfg.basePath || process.cwd();
|
|
72
|
+
this._kernel._container.instance('basePath', basePath);
|
|
73
|
+
|
|
74
|
+
// Core providers (auto-enabled unless disabled in config)
|
|
75
|
+
const coreProviders = this._buildCoreProviders(cfg);
|
|
76
|
+
this._kernel.providers([...coreProviders, ...cfg.providers]);
|
|
77
|
+
|
|
78
|
+
// Named middleware aliases
|
|
79
|
+
for (const {alias, handler} of (cfg.middleware || [])) {
|
|
80
|
+
this._kernel.middleware(alias, handler);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Route definitions
|
|
84
|
+
if (cfg.routes) {
|
|
85
|
+
this._kernel.routes(cfg.routes);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ── Boot providers ───────────────────────────────────────────────────────
|
|
89
|
+
await this._kernel.boot();
|
|
90
|
+
|
|
91
|
+
// ── Mount routes ─────────────────────────────────────────────────────────
|
|
92
|
+
if (!process.env.MILLAS_ROUTE_LIST) {
|
|
93
|
+
this._kernel.mountRoutes();
|
|
94
|
+
|
|
95
|
+
// Admin panel — mounted between routes and fallbacks
|
|
96
|
+
if (cfg.admin !== null) {
|
|
97
|
+
try {
|
|
98
|
+
const Admin = require('../admin/Admin');
|
|
99
|
+
if (cfg.admin && Object.keys(cfg.admin).length) {
|
|
100
|
+
Admin.configure(cfg.admin);
|
|
101
|
+
}
|
|
102
|
+
Admin.mount(expressApp);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
process.stderr.write(`[millas] Admin mount failed: ${err.message}\n`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this._kernel.mountFallbacks();
|
|
109
|
+
|
|
110
|
+
// ── Start the HTTP server ──────────────────────────────────────────────
|
|
111
|
+
const server = new HttpServer(this._kernel, {
|
|
112
|
+
onStart: cfg.onStart || undefined,
|
|
113
|
+
onShutdown: cfg.onShutdown || undefined,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await server.start();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── Internal ───────────────────────────────────────────────────────────────
|
|
121
|
+
|
|
122
|
+
_buildCoreProviders(cfg) {
|
|
123
|
+
const providers = [];
|
|
124
|
+
const load = (p) => {
|
|
125
|
+
try { return require(p); } catch { return null; }
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// ── 1. Logging ───────────────────────────────────────────────────────
|
|
129
|
+
if (cfg.logging !== false) {
|
|
130
|
+
const p = load('../providers/LogServiceProvider');
|
|
131
|
+
if (p) providers.push(p);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── 2. Database ──────────────────────────────────────────────────────
|
|
135
|
+
if (cfg.database !== false) {
|
|
136
|
+
const p = load('../providers/DatabaseServiceProvider');
|
|
137
|
+
if (p) providers.push(p);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ── 3. Auth — always on unless explicitly disabled ───────────────────
|
|
141
|
+
// Mirrors Django: django.contrib.auth is in INSTALLED_APPS by default.
|
|
142
|
+
// Provides Auth.login/register, JWT middleware, the User model.
|
|
143
|
+
// Requires Database to be booted first.
|
|
144
|
+
if (cfg.auth !== false) {
|
|
145
|
+
const p = load('../providers/AuthServiceProvider');
|
|
146
|
+
if (p) providers.push(p);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ── 4. Admin — on when .withAdmin() was called ───────────────────────
|
|
150
|
+
// Mirrors Django: django.contrib.admin is in INSTALLED_APPS by default.
|
|
151
|
+
// Requires Auth to be booted first (needs the resolved User model).
|
|
152
|
+
if (cfg.admin !== null && cfg.admin !== undefined) {
|
|
153
|
+
const p = load('../providers/AdminServiceProvider');
|
|
154
|
+
if (p) providers.push(p);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── 5. Cache + Storage ───────────────────────────────────────────────
|
|
158
|
+
if (cfg.cache !== false || cfg.storage !== false) {
|
|
159
|
+
const p = load('../providers/CacheStorageServiceProvider');
|
|
160
|
+
if (p) {
|
|
161
|
+
if (cfg.cache !== false && p.CacheServiceProvider) providers.push(p.CacheServiceProvider);
|
|
162
|
+
if (cfg.storage !== false && p.StorageServiceProvider) providers.push(p.StorageServiceProvider);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── 6. Mail ──────────────────────────────────────────────────────────
|
|
167
|
+
if (cfg.mail !== false) {
|
|
168
|
+
const p = load('../providers/MailServiceProvider');
|
|
169
|
+
if (p) providers.push(p);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ── 7. Queue ─────────────────────────────────────────────────────────
|
|
173
|
+
if (cfg.queue !== false) {
|
|
174
|
+
const p = load('../providers/QueueServiceProvider');
|
|
175
|
+
if (p) providers.push(p);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ── 8. Events ────────────────────────────────────────────────────────
|
|
179
|
+
if (cfg.events !== false) {
|
|
180
|
+
const p = load('../providers/EventServiceProvider');
|
|
181
|
+
if (p) providers.push(p);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// ── 9. i18n — opt-in via config/app.js use_i18n: true ───────────────
|
|
185
|
+
// Mirrors Django's USE_I18N = True in settings.py.
|
|
186
|
+
// Booted last so translations are available in all request handlers.
|
|
187
|
+
if (this._resolveI18nEnabled(cfg)) {
|
|
188
|
+
const p = load('../i18n/I18nServiceProvider');
|
|
189
|
+
if (p) providers.push(p);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return providers;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Resolve whether i18n should be enabled.
|
|
197
|
+
* Reads use_i18n from config/app.js — the single source of truth.
|
|
198
|
+
*
|
|
199
|
+
* // config/app.js
|
|
200
|
+
* module.exports = {
|
|
201
|
+
* use_i18n: true,
|
|
202
|
+
* locale: 'sw',
|
|
203
|
+
* fallback: 'en',
|
|
204
|
+
* };
|
|
205
|
+
*/
|
|
206
|
+
_resolveI18nEnabled(cfg) {
|
|
207
|
+
try {
|
|
208
|
+
const basePath = cfg.basePath || process.cwd();
|
|
209
|
+
const appConfig = require(basePath + '/config/app');
|
|
210
|
+
return appConfig.use_i18n === true;
|
|
211
|
+
} catch { return false; }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
module.exports = AppInitializer;
|