bajo 2.23.0 → 2.24.0

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 (108) hide show
  1. package/.jsdoc.conf.json +2 -1
  2. package/class/app.js +220 -107
  3. package/class/bajo.js +246 -174
  4. package/class/base.js +85 -24
  5. package/class/cache.js +8 -16
  6. package/class/err.js +31 -10
  7. package/class/log.js +46 -38
  8. package/class/plugin.js +53 -30
  9. package/class/print.js +18 -15
  10. package/class/tools.js +6 -5
  11. package/docs/App.html +51 -1
  12. package/docs/Bajo.html +1 -1
  13. package/docs/Base.html +34 -1
  14. package/docs/Cache.html +1 -1
  15. package/docs/Err.html +2 -2
  16. package/docs/Log.html +2 -2
  17. package/docs/Main.html +3 -0
  18. package/docs/Plugin.html +1 -1
  19. package/docs/Print.html +1 -1
  20. package/docs/Tools.html +1 -1
  21. package/docs/class_app.js.html +222 -109
  22. package/docs/class_bajo.js.html +260 -179
  23. package/docs/class_base.js.html +87 -26
  24. package/docs/class_cache.js.html +10 -18
  25. package/docs/class_err.js.html +33 -12
  26. package/docs/class_log.js.html +48 -40
  27. package/docs/class_plugin.js.html +55 -32
  28. package/docs/class_print.js.html +20 -17
  29. package/docs/class_tools.js.html +8 -7
  30. package/docs/data/search.json +1 -1
  31. package/docs/extend_bajo_hook.js.html +289 -0
  32. package/docs/global.html +22 -1
  33. package/docs/index.html +1 -1
  34. package/docs/index.js.html +53 -16
  35. package/docs/lib_applet-hook.js.html +328 -0
  36. package/docs/lib_config.js.html +167 -0
  37. package/docs/lib_helper.js.html +186 -192
  38. package/docs/module-Applet.html +3 -0
  39. package/docs/module-Helper-Main.html +3 -0
  40. package/docs/module-Helper.html +1 -8
  41. package/docs/module-Hook.html +1 -1
  42. package/docs/tutorial-01_WELCOME.html +3 -0
  43. package/docs/tutorial-02_GETTING_STARTED.html +125 -0
  44. package/docs/tutorial-03_USER_GUIDE.html +54 -0
  45. package/docs/tutorial-04_DEV_GUIDE.html +178 -0
  46. package/docs/tutorial-05_ECOSYSTEM.html +3 -0
  47. package/extend/bajo/intl/en-US.json +2 -1
  48. package/extend/bajo/intl/id.json +2 -1
  49. package/index.js +51 -14
  50. package/lib/applet-hook.js +325 -0
  51. package/lib/config.js +164 -0
  52. package/lib/helper.js +184 -190
  53. package/package.json +6 -2
  54. package/test/00-global-hooks.test.js +44 -0
  55. package/test/e2e/_run.js +19 -0
  56. package/test/e2e/e2e-applet-process.test.js +66 -0
  57. package/test/e2e/e2e-boot-process.test.js +62 -0
  58. package/test/e2e/e2e-hooks-process.test.js +68 -0
  59. package/test/integration/_setup.js +55 -0
  60. package/test/integration/aspect-01-boot-instance.test.js +24 -0
  61. package/test/integration/aspect-02-plugin-loading.test.js +24 -0
  62. package/test/integration/aspect-03-config-merge.test.js +27 -0
  63. package/test/integration/aspect-04-intl-loading.test.js +29 -0
  64. package/test/integration/aspect-05-cache-roundtrip.test.js +26 -0
  65. package/test/integration/aspect-06-log-file-save.test.js +28 -0
  66. package/test/integration/aspect-07-plugin-data-dir.test.js +25 -0
  67. package/test/integration/aspect-08-plugin-lookup.test.js +25 -0
  68. package/test/integration/aspect-09-config-formats.test.js +26 -0
  69. package/test/integration/aspect-10-hooks.test.js +38 -0
  70. package/test/unit/app.test.js +115 -0
  71. package/test/unit/applet-hook.test.js +10 -0
  72. package/test/unit/bajo.test.js +151 -0
  73. package/test/unit/base.test.js +90 -0
  74. package/test/unit/cache.test.js +89 -0
  75. package/test/unit/config.test.js +14 -0
  76. package/test/unit/err.test.js +57 -0
  77. package/test/unit/helper.test.js +116 -0
  78. package/test/unit/index.test.js +40 -0
  79. package/test/unit/log.test.js +84 -0
  80. package/test/unit/plugin.test.js +95 -0
  81. package/test/unit/print.test.js +72 -0
  82. package/test/unit/tools.test.js +29 -0
  83. package/wiki/CHANGES.md +4 -0
  84. package/wiki/tutorials/01_WELCOME.md +18 -0
  85. package/wiki/tutorials/02_GETTING_STARTED.md +366 -0
  86. package/wiki/tutorials/03_USER_GUIDE.md +262 -0
  87. package/wiki/tutorials/04_DEV_GUIDE.md +386 -0
  88. package/wiki/tutorials/05_ECOSYSTEM.md +95 -0
  89. package/wiki/tutorials/tutorials.json +17 -0
  90. package/lib/hook.js +0 -228
  91. package/test/app.test.js +0 -183
  92. package/test/bajo.test.js +0 -124
  93. package/test/base.test.js +0 -75
  94. package/test/cache.test.js +0 -94
  95. package/test/e2e.test.js +0 -137
  96. package/test/err.test.js +0 -73
  97. package/test/helper.test.js +0 -39
  98. package/test/import-module.test.js +0 -138
  99. package/test/integration.test.js +0 -218
  100. package/test/log.test.js +0 -119
  101. package/test/plugin.test.js +0 -116
  102. package/test/print.test.js +0 -100
  103. package/test/tools.test.js +0 -38
  104. package/wiki/CONFIG.md +0 -36
  105. package/wiki/DEV_GUIDE.md +0 -3
  106. package/wiki/ECOSYSTEM.md +0 -93
  107. package/wiki/GETTING-STARTED.md +0 -356
  108. package/wiki/USER-GUIDE.md +0 -256
package/index.js CHANGED
@@ -5,26 +5,63 @@ import fs from 'fs-extra'
5
5
  shim()
6
6
 
7
7
  /**
8
- * Main entry point of a Bajo app. Returned value is the app instance itself.
8
+ * To be recognized as a valid Bajo app, your package must be an `ES6 module` and have a `package.json` file
9
+ * with the additional `bajo` property and at least the `type` property set to `app`.
9
10
  *
10
- * While you can code directly around it, you typically write your code the main plugin (```{mainNs}```) or
11
- * writing your own custom plugin.
11
+ * You can also add the `plugins` property to specify which plugins to load. But this will be overridden
12
+ * by the `{dataDir}/config/.plugins` file if it exists.
12
13
  *
13
- * I recommend the second method for its portability.
14
+ * Example:
15
+ * ```json
16
+ * {
17
+ * "name": "my-app",
18
+ * "version": "1.0.0",
19
+ * "description": "My Bajo app",
20
+ * "type": "module",
21
+ * "main": "index.js",
22
+ * "bajo": {
23
+ * "type": "app",
24
+ * "plugins": ["bajo-cli", "bajo-config"]
25
+ * },
26
+ * "dependencies": {
27
+ * "bajo": "^2.23.0",
28
+ * "bajo-cli": "^2.4.0",
29
+ * "bajo-config": "^2.4.0"
30
+ * }
31
+ * }
32
+ * ...
33
+ * ```
34
+ *
35
+ * > **Note**: The dot symbol in `package.json` has been replaced with `·` symbol because of JSDoc theme limitation
36
+ *
37
+ * @global
38
+ * @typedef package·json
39
+ */
40
+
41
+ /**
42
+ * Main entry point of a Bajo app. Returned value is the {@link App} instance itself.
43
+ *
44
+ * Inside your `index.js` file in the root folder, write something like this:
45
+ * ```javascript
46
+ * import { boot } from 'bajo'
47
+ * const app = await boot()
48
+ * // At this point, your app should be ready to use
49
+ * // You can now use `app` to access all plugins and their features
50
+ * ```
51
+ *
52
+ * Even though you can write your codes directly after boot as shown above, we strongly suggest writing
53
+ * your code inside the {@link Main} plugin or even writing a custom {@link Plugin}.
54
+ *
55
+ * We recommend the second method for its portability.
14
56
  *
15
57
  * @global
16
58
  * @async
17
- * @param {Object} [options] App options.
18
- * @param {string} [options.cwd] Set current working directory. Defaults to the script directory.
19
- * @param {string[]} [options.plugins] Array of plugins to load. If provided, it override the list in ```package.json``` and ```.plugins``` file.
20
- * @param {Object} [options.config] Plugin's config object. If provided, plugin configs will no longer be read from its config files.
59
+ * @param {App.TOptions} [options] App options
21
60
  * @returns {App}
22
- * @example
23
- * // index.js file. Your main package entry point
24
- * import bajo from 'bajo'
25
- * await bajo()
61
+ * @see {@link App}
62
+ * @see {@link Bajo}
26
63
  */
27
- async function boot (options = {}) {
64
+ export async function boot (options = {}) {
28
65
  if (!options.cwd) {
29
66
  const item = process.argv.find(item => item.startsWith('--cwd='))
30
67
  if (item) options.cwd = item.slice(6)
@@ -33,7 +70,7 @@ async function boot (options = {}) {
33
70
  const pkgFile = `${options.cwd}/package.json`
34
71
  const pkg = fs.readJsonSync(pkgFile)
35
72
  if (pkg.type !== 'module') {
36
- console.error(`Please turn on ES6 parsing by adding "type": "module" to ${pkgFile}!`)
73
+ console.error('A Bajo app must be an ES6 module. Your package.json is missing the "type": "module" property')
37
74
  process.exit(1)
38
75
  }
39
76
  const app = new App(options)
@@ -0,0 +1,325 @@
1
+ /**
2
+ * # Applet
3
+ *
4
+ * Bajo has a built-in applet system that allows you to run your app as an applet.
5
+ * An applet is a small command-line app that can be embedded inside a plugin, purposefully designed
6
+ * to run a simple task mostly bound to the plugin itself. It is a convenient way to run a plugin's task
7
+ * without having to write a separate script.
8
+ *
9
+ * Since it is embedded inside a plugin, it behaves like running the whole app but doing only task
10
+ * that you want to run.
11
+ *
12
+ * Applet needs {@link https://ardhi.github.io/bajo-cli/|bajo-cli} plugin to be installed and loaded.
13
+ * This is because applet is a command-line app and `bajo-cli` plugin is specifically designed to provide
14
+ * the necessary command-line interface and function helpers to run command-line based app.
15
+ *
16
+ * So please make sure that `bajo-cli` is in your app's `package.json` file and in the `plugins`
17
+ * array of your app's config before you run an applet. Otherwise, it will throw an error.
18
+ *
19
+ * You can run an applet by using the following command:
20
+ * - `node index.js -a` or `node index.js --applet` to list all available applets and choose one to run
21
+ * - `node index.js -a <pluginNs>` to list all `pluginNs` only applets and choose one to run
22
+ * - `node index.js -a <pluginNs:appletName>` to run the specific applet directly
23
+ *
24
+ * On all cases, you might require to provide additional arguments and/or options to the applet.
25
+ *
26
+ * By default, applet won't show you any log output. This is by design because it could clutter your
27
+ * terminal output. If you insist on seeing the log output, you have to add the `--log-applet` option.
28
+ *
29
+ * > **Note**: all standard bajo's command line arguments and options are also available to applet,
30
+ * e.g. `--env=prod`, `--lang=id`, `--log-level=trace`, etc.
31
+ *
32
+ * > **Development** : Please visit {@link https://ardhi.github.io/bajo-cli/module-Applet.html|applet development}
33
+ * for more details on how to create an applet.
34
+ * @module Applet
35
+ */
36
+
37
+ /**
38
+ * # Hook
39
+ *
40
+ * Bajo has a hook system that allows you to run custom code before or after certain events in the framework.
41
+ * You can use hooks to modify the behavior of the framework or to add new functionality.
42
+ *
43
+ * Your hook should be put in:
44
+ * - your plugin's hook folder (also valid for app's `main` plugin), which is located in `{pluginRoot}/extend/bajo/hook`. In this case:
45
+ * - the file should be named as `{hookName}.js` for hook that listens for one name or `{hookName1}${hookName2}${hookName3}.js`
46
+ * for hook that listens for many names. It should be exported as default export
47
+ * - you can use the exact hook name or follow our convention to use kebab case for the file name, e.g. `bajo.override:after-read-config.js` for `bajo.override:afterReadConfig` hook
48
+ * - content should be a single {@link module:Hook.THook} object. If `name` property is there, it will be used as
49
+ * the hook name, otherwise it will be reconstructed from the file name. Hence the file name is important
50
+ * - or simply a function that will be used as the hook handler. In this case, all missing properties will be set to their default values
51
+ * - or as array of hook object in `{pluginRoot}/extend/bajo/hook.js` file that follows the {@link module:Hook.THook} structure
52
+ *
53
+ * > **Note**: Hook handlers can have `.` dot symbol in their name, but in documentation, the dot symbol will be replaced with `·`
54
+ * symbol because of JSDoc limitation. For example, a hook handler named `bajo.override:afterReadConfig` will be
55
+ * documented as `bajo·override:afterReadConfig`.
56
+ *
57
+ * > **Warning**: Even though hooks is a powerfull and convenient feature, it should be used with caution. Overusing hooks can lead to code
58
+ * that is difficult to understand and maintain. Use hooks only when necessary and avoid using them for simple tasks
59
+ * that can be accomplished with regular code.
60
+ * @module Hook
61
+ */
62
+
63
+ /**
64
+ * Hook structure definition. Your hook listener should be an object that follows this structure.
65
+ *
66
+ * @memberof module:Hook
67
+ * @typedef THook
68
+ * @type {Object}
69
+ * @property {string|string[]} name - Hook name or array of hook names
70
+ * @property {module:Hook.hookHandler} handler - Hook handler function
71
+ * @property {number} [level=999] - Hook level (lower number means higher priority)
72
+ * @property {string} src - Hook source (origin plugin name). Bajo will set this automatically, any value you set will be overriden.
73
+ * @property {boolean} [noWait=false] - If `true`, Bajo will not wait for this hook to complete before proceeding to the next hook. Default is `false`.
74
+ */
75
+
76
+ /**
77
+ * This is the hook handler function that will be called when the hook is triggered.
78
+ * This handler is scoped to the owning plugin, so you can use `this` to access the plugin instance and
79
+ * its properties.
80
+ * @async
81
+ * @method
82
+ * @callback hookHandler
83
+ * @memberof module:Hook
84
+ * @param {...any} args - Arguments passed to the hook handler
85
+ * @returns {Promise<void>} The return value of the hook handler
86
+ */
87
+
88
+ /**
89
+ * Hook handler that runs before boot process. You can use this hook to do some pre-boot process.
90
+ *
91
+ * @name bajo:beforeBoot
92
+ * @async
93
+ * @method
94
+ * @memberof module:Hook
95
+ */
96
+
97
+ /**
98
+ * Hook handler that runs after boot process. You can use this hook to do some post-boot process.
99
+ *
100
+ * @name bajo:afterBoot
101
+ * @async
102
+ * @method
103
+ * @memberof module:Hook
104
+ */
105
+
106
+ /**
107
+ * Hook handler that runs after hooks are collected. You can use this hook to modify the collected hooks before
108
+ * they are recognized as application hooks.
109
+ *
110
+ * @async
111
+ * @method
112
+ * @name bajo:afterCollectHooks
113
+ * @memberof module:Hook
114
+ * @param {Array<module:Hook~THook>} hooks - Array of hook objects
115
+ * @see module:Helper.collectHooks
116
+ */
117
+
118
+ /**
119
+ * Hook handler that runs before all plugins are initialized. You can use this hook to do some pre-initialization process.
120
+ *
121
+ * @async
122
+ * @method
123
+ * @name bajo:beforeAllInit
124
+ * @memberof module:Hook
125
+ * @see module:Helper.run
126
+ */
127
+
128
+ /**
129
+ * Hook handler that runs after all plugins are initialized. You can use this hook to do some post-initialization process.
130
+ *
131
+ * @async
132
+ * @method
133
+ * @memberof module:Hook
134
+ * @name bajo:afterAllInit
135
+ * @see module:Helper.run
136
+ */
137
+
138
+ /**
139
+ * Hook handler that runs before all plugins are started. You can use this hook to do some pre-start process.
140
+ *
141
+ * @async
142
+ * @method
143
+ * @name bajo:beforeAllStart
144
+ * @memberof module:Hook
145
+ * @see module:Helper.run
146
+ */
147
+
148
+ /**
149
+ * Hook handler that runs after all plugins are started. You can use this hook to do some post-start process.
150
+ *
151
+ * @async
152
+ * @method
153
+ * @name bajo:afterAllStart
154
+ * @memberof module:Hook
155
+ * @see module:Helper.run
156
+ */
157
+
158
+ /**
159
+ * Hook handler that runs before `{ns}` plugins are initialized. You can use this hook to do some pre-initialization process.
160
+ *
161
+ * @async
162
+ * @method
163
+ * @memberof module:Hook
164
+ * @name {ns}:beforeInit
165
+ * @see module:Helper.run
166
+ */
167
+
168
+ /**
169
+ * Hook handler that runs after `{ns}` plugins are initialized. You can use this hook to do some post-initialization process.
170
+ *
171
+ * @async
172
+ * @method
173
+ * @memberof module:Hook
174
+ * @name {ns}:afterInit
175
+ * @see module:Helper.run
176
+ */
177
+
178
+ /**
179
+ * Hook handler that runs before `{ns}` plugins are started. You can use this hook to do some pre-start process.
180
+ *
181
+ * @async
182
+ * @method
183
+ * @memberof module:Hook
184
+ * @name {ns}:beforeStart
185
+ * @see module:Helper.run
186
+ */
187
+
188
+ /**
189
+ * Hook handler that runs after `{ns}` plugins are started. You can use this hook to do some post-start process.
190
+ *
191
+ * @async
192
+ * @method
193
+ * @memberof module:Hook
194
+ * @name {ns}:afterStart
195
+ * @see module:Helper.run
196
+ */
197
+
198
+ /**
199
+ * Hook handler that runs before applet is run. `{ns}` is the applet's namespace
200
+ *
201
+ * @name {ns}:beforeAppletRun
202
+ * @async
203
+ * @method
204
+ * @memberof module:Hook
205
+ * @param {...any} args - Arguments passed to the applet
206
+ * @see module:Helper.runAsApplet
207
+ */
208
+
209
+ /**
210
+ * Hook handler that runs after applet is run. `{ns}` is the applet's namespace
211
+ *
212
+ * @name {ns}:afterAppletRun
213
+ * @async
214
+ * @method
215
+ * @memberof module:Hook
216
+ * @param {...any} args - Arguments passed to the applet
217
+ * @see module:Helper.runAsApplet
218
+ */
219
+
220
+ /**
221
+ * Hook handler that runs after a non override/extended configuration file is read.
222
+ *
223
+ * @async
224
+ * @method
225
+ * @name bajo·default:afterReadConfig
226
+ * @memberof module:Hook
227
+ * @param {string} file - Config file path
228
+ * @param {string} orgObj - Original config object before parsing
229
+ * @param {object} options - readConfig options
230
+ */
231
+
232
+ /**
233
+ * Hook handler that runs before a configuration file override is read.
234
+ *
235
+ * @async
236
+ * @method
237
+ * @name bajo·override:beforeReadConfig
238
+ * @memberof module:Hook
239
+ * @param {string} fileExt - Config file extension
240
+ * @param {object} options - readConfig options
241
+ */
242
+
243
+ /**
244
+ * Hook handler that runs after a configuration file override is read.
245
+ *
246
+ * @async
247
+ * @method
248
+ * @name bajo·override:afterReadConfig
249
+ * @memberof module:Hook
250
+ * @param {string} fileExt - Config file extension
251
+ * @param {object} result - Resulting config object after parsing
252
+ * @param {object} options - readConfig options
253
+ */
254
+
255
+ /**
256
+ * Hook handler that runs before a extended configuration file is read.
257
+ *
258
+ * @async
259
+ * @method
260
+ * @name bajo.extend:beforeReadConfig
261
+ * @memberof module:Hook
262
+ * @param {string} fileExt - Config file extension
263
+ * @param {object} options - readConfig options
264
+ */
265
+
266
+ /**
267
+ * Hook handler that runs after a extended configuration file is read.
268
+ *
269
+ * @async
270
+ * @method
271
+ * @name bajo.extend:afterReadConfig
272
+ * @memberof module:Hook
273
+ * @param {string} fileExt - Config file extension
274
+ * @param {object} result - Resulting config object after parsing
275
+ * @param {object} options - readConfig options
276
+ */
277
+
278
+ /**
279
+ * Hook handler that runs before a configuration file is read.
280
+ *
281
+ * @async
282
+ * @method
283
+ * @name bajo:beforeReadConfig
284
+ * @memberof module:Hook
285
+ * @param {string} file - Config file path
286
+ * @param {object} options - readConfig options
287
+ */
288
+
289
+ /**
290
+ * Hook handler that runs after all read processes of a configuration file are completed.
291
+ *
292
+ * @async
293
+ * @method
294
+ * @name bajo:afterReadConfig
295
+ * @memberof module:Hook
296
+ * @param {string} file - Config file path
297
+ * @param {object} result - Resulting config object after parsing
298
+ * @param {object} options - readConfig options
299
+ */
300
+
301
+ /**
302
+ * Hook handler that runs before a collection is built. `{ns}` is the collection's namespace. This hook is useful
303
+ * to modify the collection items before they are built.
304
+ *
305
+ * @async
306
+ * @method
307
+ * @name {ns}:beforeBuildCollection
308
+ * @memberof module:Hook
309
+ * @param {string} container - Collection container name
310
+ * @param {array<object>} items - Collection items
311
+ * @see Bajo#buildCollections
312
+ */
313
+
314
+ /**
315
+ * Hook handler that runs after a collection is built. `{ns}` is the collection's namespace. This hook is useful
316
+ * to modify the collection items after they are built.
317
+ *
318
+ * @async
319
+ * @method
320
+ * @name {ns}:afterBuildCollection
321
+ * @memberof module:Hook
322
+ * @param {string} container - Collection container name
323
+ * @param {array<object>} items - Collection items
324
+ * @see Bajo#buildCollections
325
+ */
package/lib/config.js ADDED
@@ -0,0 +1,164 @@
1
+ /**
2
+ * This is the default configuration object for Bajo and its plugins (see note below). It contains various settings that control the behavior of the framework.
3
+ * You can override these settings by providing your own configuration object through the following methods in the order of priority:
4
+ * 1. **Environment variables**:
5
+ * You can set configuration options using environment variables too. `dotenv` is also supported.
6
+ * The environment variable names should be in uppercase. Use double underscores instead of dots and single underscores
7
+ * to form camel cased name. For example, `LOG__TIME_TAKEN=true` will set `log.timeTaken` to `true`
8
+ * 2. **Command-line arguments**:
9
+ * You can pass configuration options as command-line arguments when starting the application. For example, you can use `--env=prod` to set the environment to `prod`.
10
+ * For nested configuration options, use dash notation. For example, `--log-timeTaken` will set `log.timeTaken` to `true`.
11
+ * 3. **Configuration files**:
12
+ * Create/open `{dataDir}/config/bajo.{ext}` file, where `{ext}` is the file extension of your choice.
13
+ * This file is read during the boot process with app's {@link App#configHandlers} and merged with the default configuration object.
14
+ *
15
+ * By default, the supported file extensions are `.js`, `.json`, and `.yml/.yaml`. More extensions can be added by plugins.
16
+ * For example, the {@link https://ardhi.github.io/bajo-config bajo-config} plugin provides support for `.toml` format.
17
+ *
18
+ * If the same filename with different extension exists, the one with higher priority will be used. The priorities are as follows:
19
+ * 1. `.js` - use this if you want to use dynamic config file that can be generated programmatically.
20
+ * 2. `.json` - use this if you want to use static config file that can be easily edited by humans.
21
+ * 3. `.yml/.yaml` - use this if you want to use static config file that can be easily edited by humans and supports comments.
22
+ *
23
+ * To have an environment-specific configuration, create a file named `bajo-{env}.{ext}` where `{env}` is the environment name (e.g. `dev`, `prod`)
24
+ * in the same folder.
25
+ *
26
+ * > **Note**: all plugin's configuration files follow the same rules as above, but with the following differences:
27
+ * > - The configuration file should be named as `{pluginName}.{ext}` or `{pluginName}-{env}.{ext}` for environment-specific configuration, where `{pluginName}` is the name of the plugin.
28
+ * > - Command-line arguments should be prefixed with the plugin name followed by a colon. For example, `--{pluginName}:my-configKey` will set `my.configKey` to the value provided for the plugin's configuration.
29
+ * > - Environment variables should be prefixed with the plugin name followed by a dot. For example, `{PLUGINNAME}.MY__CONFIG_KEY` will set `my.configKey` to the value provided for the plugin's configuration.
30
+ * >
31
+ * > Plugin's configuration objects are mutable only during the boot process. After a plugin is started, they are frozen and cannot be modified.
32
+ * Your only options to do modifications is to use `{pluginName}:{before|after}{Init|Start}` hooks.
33
+ *
34
+ * @typedef TConfig
35
+ * @global
36
+ * @type {Object}
37
+ */
38
+
39
+ /**
40
+ * @typedef TConfig
41
+ * @memberof Bajo
42
+ * @type {Object}
43
+ * @property {string} env - Environment name (`dev` or `prod`)
44
+ * @property {Object} [runtime={}] - Runtime configuration
45
+ * @property {boolean} [runtime.noWarning=false] - If `true`, Bajo will not show any warning messages. Default is `false`
46
+ * @property {Object} [log={}] - Logging configuration
47
+ * @property {boolean} [log.timeTaken=false] - If `true`, Bajo will log the time taken for each operation. Default is `false`
48
+ * @property {string} [log.dateFormat='YYYY-MM-DDTHH:mm:ss.SSS'] - Date format for logging
49
+ * @property {boolean} [log.useUtc=false] - If `true`, Bajo will use UTC instead of local time for logging. Default is `false`
50
+ * @property {boolean} [log.pretty=false] - If `true`, Bajo will use pretty logging format. Default is `false`
51
+ * @property {boolean} [log.applet=false] - Whether to log when in applet mode or not. Default is `false`
52
+ * @property {boolean} [log.save=false] - Whether to save logs to file. Default is `false`
53
+ * @property {Object} [log.rotation={}] - Log rotation configuration, used only if `log.save` is `true`
54
+ * @property {string} [log.rotation.cycle='none'] - Rotation cycle (`none`, `daily`, `weekly`, `monthly`). Default is `none`
55
+ * @property {boolean} [log.rotation.compressOld=true] - Whether to compress old logs. Default is `true`
56
+ * @property {boolean} [log.rotation.byPlugin=false] - Whether to rotate logs by plugin. Default is `false`
57
+ * @property {number} [log.rotation.retain=5] - Number of old logs to retain. Default is `5`
58
+ * @property {Object} [dump={}] - Dump configuration
59
+ * @property {number} [dump.depth=2] - Depth of object to dump. Default is `2`
60
+ * @property {boolean} [dump.compact=false] - If `true`, Bajo will dump objects in compact format. Default is `false`
61
+ * @property {boolean} [dump.colors=true] - If `true`, Bajo will dump objects with colors. Default is `true`
62
+ * @property {number} [dump.breakLength=80] - Break length for dumping objects. Default is `80`
63
+ * @property {boolean} [dump.caller=true] - If `true`, Bajo will dump the caller of the dump function. Default is `true`
64
+ * @property {Object} [dump.frame={}] - Display frame configuration for dumping objects
65
+ * @property {string} [dump.frame.titleAlignment='center'] - Title alignment for dumping objects. Default is `center`
66
+ * @property {number} [dump.frame.padding=1] - Padding for dumping objects. Default is `1`
67
+ * @property {number} [dump.frame.margin=1] - Margin for dumping objects. Default is `1`
68
+ * @property {string} [dump.frame.borderStyle='round'] - Border style for dumping objects. Default is `round`
69
+ * @property {string} [lang] - Default language for internationalization. Default is the system language or `en-US` if not available
70
+ * @property {Object} [intl={}] - Internationalization configuration
71
+ * @property {string[]} [intl.supported=['en-US', 'id']] - Supported languages. Default is `en-US` and `id`. Add more if you want it
72
+ * @property {string} [intl.fallback='en-US'] - Fallback language if the requested language is not supported. Default is `en-US`
73
+ * @property {string[]} [intl.lookupOrder=[]] - Lookup order for languages. Default is empty array
74
+ * @property {Object} [intl.format={}] - Formatting configuration
75
+ * @property {string} [intl.format.emptyValue=''] - Value to use for empty values. Default is empty string
76
+ * @property {Object} [intl.format.datetime] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat|Intl.DateTimeFormat} for more information
77
+ * @property {Object} [intl.format.date] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat|Intl.DateTimeFormat} for more information
78
+ * @property {Object} [intl.format.time] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat|Intl.DateTimeFormat} for more information
79
+ * @property {Object} [intl.format.float] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat|Intl.NumberFormat} for more information
80
+ * @property {Object} [intl.format.double] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat|Intl.NumberFormat} for more information
81
+ * @property {Object} [intl.format.smallint] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat|Intl.NumberFormat} for more information
82
+ * @property {Object} [intl.format.integer] - See {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat|Intl.NumberFormat} for more information
83
+ * @property {Object} [intl.unitSys={}] - Unit system configuration. Object with keys as language codes and values as unit systems. Supported values are `metric`, `imperial` and `nautical`
84
+ * @property {string} [intl.unitSys.en-US='imperial'] - Unit system for `en-US`. Default is `imperial`
85
+ * @property {string} [intl.unitSys.id='metric'] - Unit system for `id`. Default is `metric`
86
+ * @property {boolean} [exitHandler=true] - Whether to attach exit handlers for graceful shutdown. Default is `true`
87
+ * @property {Object} [cache={}] - Cache configuration
88
+ * @property {string[]} [cache.purge=[]] - List of cache names to purge on startup. Default is empty array
89
+ * @property {string|number} [cache.purgeIntvDur='5m'] - Interval duration for purging cache. Default is `5m`
90
+ */
91
+ const config = {
92
+ env: 'dev',
93
+ runtime: {
94
+ noWarning: false
95
+ },
96
+ log: {
97
+ timeTaken: false,
98
+ dateFormat: 'YYYY-MM-DDTHH:mm:ss.SSS',
99
+ useUtc: false,
100
+ pretty: false,
101
+ applet: false,
102
+ save: false,
103
+ rotation: {
104
+ cycle: 'none', // none, daily, weekly, monthly
105
+ compressOld: true,
106
+ byPlugin: false,
107
+ retain: 5
108
+ }
109
+ },
110
+ dump: {
111
+ depth: 2,
112
+ compact: false,
113
+ colors: true,
114
+ breakLength: 80,
115
+ caller: true,
116
+ frame: {
117
+ titleAlignment: 'center',
118
+ padding: 1,
119
+ margin: 1,
120
+ borderStyle: 'round'
121
+ }
122
+ },
123
+ lang: Intl.DateTimeFormat().resolvedOptions().lang ?? 'en-US',
124
+ intl: {
125
+ supported: ['en-US', 'id'],
126
+ fallback: 'en-US',
127
+ lookupOrder: [],
128
+ format: {
129
+ emptyValue: '',
130
+ datetime: {
131
+ dateStyle: 'medium',
132
+ timeStyle: 'short',
133
+ timeZone: 'UTC'
134
+ },
135
+ date: {
136
+ dateStyle: 'medium',
137
+ timeZone: 'UTC'
138
+ },
139
+ time: {
140
+ timeStyle: 'short',
141
+ timeZone: 'UTC'
142
+ },
143
+ float: {
144
+ maximumFractionDigits: 2
145
+ },
146
+ double: {
147
+ maximumFractionDigits: 5
148
+ },
149
+ smallint: {},
150
+ integer: {}
151
+ },
152
+ unitSys: {
153
+ 'en-US': 'imperial',
154
+ id: 'metric'
155
+ }
156
+ },
157
+ exitHandler: true,
158
+ cache: {
159
+ purge: [],
160
+ purgeIntvDur: '5m'
161
+ }
162
+ }
163
+
164
+ export default config