millas 0.2.12-beta-1 → 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 (82) hide show
  1. package/package.json +1 -1
  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 +18 -2
  31. package/src/auth/AuthUser.js +65 -44
  32. package/src/cli.js +3 -1
  33. package/src/commands/createsuperuser.js +254 -0
  34. package/src/commands/lang.js +589 -0
  35. package/src/commands/migrate.js +154 -81
  36. package/src/commands/serve.js +1 -0
  37. package/src/container/AppInitializer.js +65 -8
  38. package/src/container/MillasApp.js +10 -3
  39. package/src/container/MillasConfig.js +35 -6
  40. package/src/core/admin.js +5 -0
  41. package/src/core/db.js +2 -1
  42. package/src/core/foundation.js +1 -9
  43. package/src/core/lang.js +1 -0
  44. package/src/i18n/I18nServiceProvider.js +91 -0
  45. package/src/i18n/Translator.js +635 -0
  46. package/src/i18n/defaults.js +122 -0
  47. package/src/i18n/index.js +164 -0
  48. package/src/i18n/locales/en.js +55 -0
  49. package/src/i18n/locales/sw.js +48 -0
  50. package/src/logger/formatters/PrettyFormatter.js +101 -65
  51. package/src/migrations/system/0001_users.js +21 -0
  52. package/src/migrations/system/0002_admin_log.js +25 -0
  53. package/src/migrations/system/0003_sessions.js +23 -0
  54. package/src/orm/fields/index.js +210 -188
  55. package/src/orm/migration/DefaultValueParser.js +325 -0
  56. package/src/orm/migration/InteractiveResolver.js +191 -0
  57. package/src/orm/migration/Makemigrations.js +312 -0
  58. package/src/orm/migration/MigrationGraph.js +227 -0
  59. package/src/orm/migration/MigrationRunner.js +202 -108
  60. package/src/orm/migration/MigrationWriter.js +463 -0
  61. package/src/orm/migration/ModelInspector.js +143 -74
  62. package/src/orm/migration/ModelScanner.js +225 -0
  63. package/src/orm/migration/ProjectState.js +213 -0
  64. package/src/orm/migration/RenameDetector.js +175 -0
  65. package/src/orm/migration/SchemaBuilder.js +8 -81
  66. package/src/orm/migration/operations/base.js +57 -0
  67. package/src/orm/migration/operations/column.js +191 -0
  68. package/src/orm/migration/operations/fields.js +252 -0
  69. package/src/orm/migration/operations/index.js +55 -0
  70. package/src/orm/migration/operations/models.js +152 -0
  71. package/src/orm/migration/operations/registry.js +131 -0
  72. package/src/orm/migration/operations/special.js +51 -0
  73. package/src/orm/migration/utils.js +208 -0
  74. package/src/orm/model/Model.js +81 -13
  75. package/src/providers/AdminServiceProvider.js +66 -9
  76. package/src/providers/AuthServiceProvider.js +40 -5
  77. package/src/providers/CacheStorageServiceProvider.js +2 -2
  78. package/src/providers/DatabaseServiceProvider.js +3 -2
  79. package/src/providers/LogServiceProvider.js +4 -1
  80. package/src/providers/MailServiceProvider.js +1 -1
  81. package/src/providers/QueueServiceProvider.js +1 -1
  82. package/src/scaffold/templates.js +77 -21
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const ServiceProvider = require('../providers/ServiceProvider');
6
+ const Translator = require('./Translator');
7
+
8
+ /**
9
+ * I18nServiceProvider
10
+ *
11
+ * Boots the translation system and registers the Trans singleton
12
+ * into the DI container.
13
+ *
14
+ * ── Setup in bootstrap/app.js ─────────────────────────────────────────────
15
+ *
16
+ * const { Millas } = require('millas');
17
+ * const I18nServiceProvider = require('millas/src/i18n/I18nServiceProvider');
18
+ *
19
+ * module.exports = Millas.config()
20
+ * .providers([I18nServiceProvider, AppServiceProvider])
21
+ * .create();
22
+ *
23
+ * ── config/app.js ─────────────────────────────────────────────────────────
24
+ *
25
+ * module.exports = {
26
+ * locale: 'en', // default locale
27
+ * fallback: 'en', // fallback when translation missing
28
+ * };
29
+ *
30
+ * ── lang/ directory ───────────────────────────────────────────────────────
31
+ *
32
+ * Place translation files at <basePath>/lang/:
33
+ *
34
+ * lang/
35
+ * en.js ← source language
36
+ * sw.js ← Swahili
37
+ * fr.js ← French
38
+ *
39
+ * ── Route-level locale switching ──────────────────────────────────────────
40
+ *
41
+ * Use the built-in middleware to auto-detect locale from requests:
42
+ *
43
+ * const { Trans } = require('millas/src/i18n');
44
+ * app.use(Trans.middleware());
45
+ *
46
+ * Or manually in a route:
47
+ * Trans.setLocale('sw');
48
+ */
49
+ class I18nServiceProvider extends ServiceProvider {
50
+
51
+ register(container) {
52
+ // Register the Trans singleton into the DI container
53
+ const trans = require('./index').Trans;
54
+ container.instance('trans', trans);
55
+ container.instance('Trans', trans);
56
+ container.alias('i18n', 'trans');
57
+ }
58
+
59
+ async boot(container, app) {
60
+ const basePath = container.make('basePath') || process.cwd();
61
+ const trans = container.make('trans');
62
+
63
+ // Load config/app.js for locale settings
64
+ let locale = 'en';
65
+ let fallback = 'en';
66
+ let warnMissing = process.env.NODE_ENV !== 'production';
67
+
68
+ try {
69
+ const appConfig = require(path.join(basePath, 'config/app'));
70
+ if (appConfig.locale) locale = appConfig.locale;
71
+ if (appConfig.fallback) fallback = appConfig.fallback;
72
+ } catch { /* config/app.js not found or no locale keys */ }
73
+
74
+ // Lang path: <basePath>/lang/
75
+ const langPath = path.join(basePath, 'lang');
76
+
77
+ trans.configure({ locale, fallback, langPath, warnMissing });
78
+
79
+ // Log available locales on startup in debug mode
80
+ if (process.env.DEBUG || process.env.NODE_ENV === 'development') {
81
+ const available = trans.availableLocales();
82
+ if (available.length > 0 && !(available.length === 1 && available[0] === 'en')) {
83
+ process.stdout.write(
84
+ `[i18n] Locale: ${locale} | Fallback: ${fallback} | Available: ${available.join(', ')}\n`
85
+ );
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ module.exports = I18nServiceProvider;