miolo 3.0.0-beta.21 → 3.0.0-beta.210
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/build/build.mjs +53 -0
- package/bin/build/build_bin.mjs +17 -0
- package/bin/build/cli/client.mjs +52 -0
- package/bin/build/cli/css.mjs +22 -0
- package/bin/build/cli/index.mjs +40 -0
- package/bin/build/cli/ssr.mjs +21 -0
- package/bin/build/server/aliases.mjs +112 -0
- package/bin/build/server/babel.config.js +24 -0
- package/bin/build/server/banner.mjs +20 -0
- package/bin/build/server/bundle.mjs +111 -0
- package/bin/build/server/fix.mjs +15 -0
- package/bin/build/server/index.mjs +69 -0
- package/bin/build/server/options.mjs +83 -0
- package/bin/create/auth.mjs +23 -0
- package/bin/create/copy.mjs +175 -0
- package/bin/create/docker.mjs +25 -0
- package/bin/create/index.mjs +137 -0
- package/bin/create/pkgjson.mjs +72 -0
- package/bin/create/prepare-template.mjs +158 -0
- package/bin/create/validation.mjs +27 -0
- package/bin/dev/dev.mjs +32 -23
- package/bin/dev/dev_start.mjs +6 -5
- package/bin/index.mjs +94 -52
- package/bin/prod-bin/create-bin.mjs +42 -27
- package/bin/prod-bin/run.mjs +13 -9
- package/bin/{prod-run → run}/pid.mjs +4 -4
- package/bin/run/restart.mjs +13 -0
- package/bin/run/start.mjs +18 -0
- package/bin/run/stop.mjs +20 -0
- package/bin/util.mjs +35 -11
- package/package.json +59 -39
- package/src/config/.env +34 -12
- package/src/config/defaults.mjs +253 -185
- package/src/config/env.mjs +40 -22
- package/src/config/index.mjs +19 -24
- package/src/config/util.mjs +25 -10
- package/src/db-conn.mjs +34 -0
- package/src/engines/cron/emails.mjs +10 -5
- package/src/engines/cron/index.mjs +45 -51
- package/src/engines/cron/init.mjs +16 -17
- package/src/engines/cron/ipsum.mjs +65 -60
- package/src/engines/cron/syscheck.mjs +30 -30
- package/src/engines/emailer/index.mjs +1 -2
- package/src/engines/emailer/queue.mjs +14 -20
- package/src/engines/emailer/transporter.mjs +86 -74
- package/src/engines/geoip/index.mjs +23 -28
- package/src/engines/http/index.mjs +26 -15
- package/src/engines/logger/buildErrorEmailBody.mjs +72 -0
- package/src/engines/logger/index.mjs +114 -122
- package/src/engines/logger/injectStackTrace.mjs +59 -0
- package/src/engines/logger/logger_mail.mjs +47 -61
- package/src/engines/logger/reopenTransportOnHupSignal.mjs +12 -13
- package/src/engines/parser/Parser.mjs +77 -60
- package/src/engines/parser/index.mjs +1 -1
- package/src/engines/schema/diffObjs.mjs +41 -0
- package/src/engines/schema/index.mjs +4 -0
- package/src/engines/schema/input.mjs +54 -0
- package/src/engines/schema/output.mjs +66 -0
- package/src/engines/socket/index.mjs +44 -46
- package/src/index.mjs +15 -10
- package/src/middleware/auth/basic.mjs +41 -40
- package/src/middleware/auth/custom.mjs +10 -13
- package/src/middleware/auth/guest.mjs +27 -27
- package/src/middleware/auth/passport/index.mjs +374 -0
- package/src/middleware/auth/passport/session/index.mjs +43 -0
- package/src/middleware/auth/{credentials → passport}/session/store.mjs +35 -15
- package/src/middleware/auth/passport/session/store_koa_redis.mjs +3 -0
- package/src/middleware/context/cache/index.mjs +78 -33
- package/src/middleware/context/cache/options.mjs +19 -21
- package/src/middleware/context/db.mjs +45 -20
- package/src/middleware/context/index.mjs +12 -12
- package/src/middleware/extra.mjs +4 -5
- package/src/middleware/http/body.mjs +25 -25
- package/src/middleware/http/catcher.mjs +81 -8
- package/src/middleware/http/custom_blacklist.mjs +19 -16
- package/src/middleware/http/headers.mjs +37 -34
- package/src/middleware/http/ratelimit.mjs +16 -23
- package/src/middleware/http/request.mjs +60 -65
- package/src/middleware/routes/catch_js_error.mjs +30 -23
- package/src/middleware/routes/robots.mjs +4 -7
- package/src/middleware/routes/router/crud/attachCrudRoutes.mjs +108 -90
- package/src/middleware/routes/router/crud/getCrudConfig.mjs +31 -55
- package/src/middleware/routes/router/defaults.mjs +6 -19
- package/src/middleware/routes/router/index.mjs +17 -21
- package/src/middleware/routes/router/queries/attachQueriesRoutes.mjs +227 -50
- package/src/middleware/routes/router/queries/getQueriesConfig.mjs +45 -55
- package/src/middleware/routes/router/utils.mjs +41 -26
- package/src/middleware/ssr/context.mjs +5 -7
- package/src/middleware/ssr/html.mjs +66 -43
- package/src/middleware/ssr/loader.mjs +11 -14
- package/src/middleware/ssr/ssr_render.mjs +39 -22
- package/src/middleware/static/index.mjs +33 -14
- package/src/middleware/vite/devserver.mjs +38 -22
- package/src/middleware/vite/watcher.mjs +12 -14
- package/src/server-cron.mjs +13 -8
- package/src/server-dev.mjs +13 -16
- package/src/server.mjs +49 -51
- package/template/.agent/skills/miolo-app-arch/SKILL.md +218 -0
- package/template/.agent/skills/miolo-auth/SKILL.md +450 -0
- package/template/.agent/skills/miolo-cli-router/SKILL.md +394 -0
- package/template/.agent/skills/miolo-database/SKILL.md +358 -0
- package/template/.agent/skills/miolo-react-patterns/SKILL.md +426 -0
- package/template/.agent/skills/miolo-routing/SKILL.md +326 -0
- package/template/.agent/skills/miolo-schemas/SKILL.md +329 -0
- package/template/.agent/skills/miolo-session-context/SKILL.md +397 -0
- package/template/.agent/skills/miolo-ssr/SKILL.md +433 -0
- package/template/.editorconfig +18 -0
- package/template/.env +120 -0
- package/template/biome.json +63 -0
- package/template/components.json +21 -0
- package/template/db/init.sh +89 -0
- package/template/db/sql/00_drop.sql +2 -0
- package/template/db/sql/01_users.sql +31 -0
- package/template/db/sql/02_todos.sql +20 -0
- package/template/docker/Dockerfile +13 -0
- package/template/docker/docker-compose.yaml +79 -0
- package/template/gitignore +42 -0
- package/template/jsconfig.json +18 -0
- package/template/package.json +88 -0
- package/template/postcss.config.js +9 -0
- package/template/src/cli/App.jsx +25 -0
- package/template/src/cli/components/JsonTreeViewer.jsx +128 -0
- package/template/src/cli/components/shadcn-io/spinner/index.jsx +232 -0
- package/template/src/cli/components/stepper.jsx +408 -0
- package/template/src/cli/components/ui/avatar.jsx +36 -0
- package/template/src/cli/components/ui/badge.jsx +31 -0
- package/template/src/cli/components/ui/breadcrumb.jsx +97 -0
- package/template/src/cli/components/ui/card.jsx +73 -0
- package/template/src/cli/components/ui/collapsible.jsx +16 -0
- package/template/src/cli/components/ui/dropdown-menu.jsx +179 -0
- package/template/src/cli/components/ui/field.jsx +217 -0
- package/template/src/cli/components/ui/input.jsx +19 -0
- package/template/src/cli/components/ui/label.jsx +17 -0
- package/template/src/cli/components/ui/pagination.jsx +99 -0
- package/template/src/cli/components/ui/patched/alert.jsx +56 -0
- package/template/src/cli/components/ui/patched/button.jsx +45 -0
- package/template/src/cli/components/ui/patched/dialog.jsx +114 -0
- package/template/src/cli/components/ui/patched/sidebar.jsx +660 -0
- package/template/src/cli/components/ui/select.jsx +141 -0
- package/template/src/cli/components/ui/separator.jsx +21 -0
- package/template/src/cli/components/ui/sheet.jsx +115 -0
- package/template/src/cli/components/ui/skeleton.jsx +13 -0
- package/template/src/cli/components/ui/sonner.jsx +22 -0
- package/template/src/cli/components/ui/switch.jsx +25 -0
- package/template/src/cli/components/ui/table.jsx +88 -0
- package/template/src/cli/components/ui/textarea.jsx +16 -0
- package/template/src/cli/components/ui/tooltip.jsx +45 -0
- package/template/src/cli/config/store_keys.mjs +2 -0
- package/template/src/cli/context/data/DataContext.jsx +5 -0
- package/template/src/cli/context/data/DataProvider.jsx +44 -0
- package/template/src/cli/context/data/useBreads.mjs +15 -0
- package/template/src/cli/context/data/useDataContext.mjs +4 -0
- package/template/src/cli/context/session/SessionContext.mjs +4 -0
- package/template/src/cli/context/session/SessionProvider.jsx +31 -0
- package/template/src/cli/context/session/makePermissioner.mjs +34 -0
- package/template/src/cli/context/session/useSessionContext.mjs +6 -0
- package/template/src/cli/context/theme/ThemeContext.mjs +4 -0
- package/template/src/cli/context/theme/ThemeProvider.jsx +49 -0
- package/template/src/cli/context/theme/useThemeContext.mjs +6 -0
- package/template/src/cli/context/ui/UIContext.jsx +5 -0
- package/template/src/cli/context/ui/UIProvider.jsx +16 -0
- package/template/src/cli/context/ui/useUIContext.mjs +4 -0
- package/template/src/cli/context/util.mjs +17 -0
- package/template/src/cli/entry-cli.jsx +33 -0
- package/template/src/cli/hooks/useIsMobile.mjs +19 -0
- package/template/src/cli/hooks/useStoragedState.mjs +63 -0
- package/template/src/cli/index.html +29 -0
- package/template/src/cli/layout/app-sidebar.jsx +25 -0
- package/template/src/cli/layout/main-layout.jsx +63 -0
- package/template/src/cli/layout/nav-last-todos.jsx +72 -0
- package/template/src/cli/layout/nav-main.jsx +39 -0
- package/template/src/cli/layout/nav-user.jsx +105 -0
- package/template/src/cli/layout/prop-switcher.jsx +93 -0
- package/template/src/cli/lib/utils.mjs +10 -0
- package/template/src/cli/pages/Index.jsx +13 -0
- package/template/src/cli/pages/IndexOffline.jsx +13 -0
- package/template/src/cli/pages/IndexOnline.jsx +18 -0
- package/template/src/cli/pages/dash/Dashboard.jsx +29 -0
- package/template/src/cli/pages/offline/Login.jsx +43 -0
- package/template/src/cli/pages/offline/LoginForm.jsx +115 -0
- package/template/src/cli/pages/security/Security.jsx +39 -0
- package/template/src/cli/pages/security/SecurityForm.jsx +106 -0
- package/template/src/cli/pages/todos/TodoActions.jsx +99 -0
- package/template/src/cli/pages/todos/TodoAdd.jsx +43 -0
- package/template/src/cli/pages/todos/TodoList.jsx +60 -0
- package/template/src/cli/pages/todos/Todos.jsx +23 -0
- package/template/src/cli/pages/todos/context/TodosContext.jsx +5 -0
- package/template/src/cli/pages/todos/context/TodosProvider.jsx +191 -0
- package/template/src/cli/pages/todos/context/useTodosContext.mjs +4 -0
- package/template/src/ns/models/Todo.mjs +29 -0
- package/template/src/ns/models/TodoList.mjs +8 -0
- package/template/src/ns/models/User.mjs +40 -0
- package/template/src/server/bot/check_today.mjs +10 -0
- package/template/src/server/io/cache/base.mjs +21 -0
- package/template/src/server/io/db/filter.mjs +92 -0
- package/template/src/server/io/db/todos/delete.mjs +29 -0
- package/template/src/server/io/db/todos/find.mjs +13 -0
- package/template/src/server/io/db/todos/read.mjs +83 -0
- package/template/src/server/io/db/todos/toggle.mjs +37 -0
- package/template/src/server/io/db/todos/upsave.mjs +32 -0
- package/template/src/server/io/db/triggers/user.mjs +13 -0
- package/template/src/server/io/db/users/auth.mjs +132 -0
- package/template/src/server/io/db/users/pwd.mjs +38 -0
- package/template/src/server/io/db/users/save.mjs +17 -0
- package/template/src/server/miolo/auth/basic.mjs +15 -0
- package/template/src/server/miolo/auth/guest.mjs +3 -0
- package/template/src/server/miolo/auth/passport.mjs +73 -0
- package/template/src/server/miolo/cache.mjs +11 -0
- package/template/src/server/miolo/cron/foo.mjs +7 -0
- package/template/src/server/miolo/cron/index.mjs +28 -0
- package/template/src/server/miolo/cron/invalidate.mjs +21 -0
- package/template/src/server/miolo/db.mjs +36 -0
- package/template/src/server/miolo/http.mjs +14 -0
- package/template/src/server/miolo/index.mjs +43 -0
- package/template/src/server/miolo/routes/crud.mjs +16 -0
- package/template/src/server/miolo/routes/index.mjs +8 -0
- package/template/src/server/miolo/ssr/entry-server.jsx +13 -0
- package/template/src/server/miolo/ssr/loader.mjs +18 -0
- package/template/src/server/routes/index.mjs +66 -0
- package/template/src/server/routes/todos/mod.mjs +52 -0
- package/template/src/server/routes/todos/read.mjs +45 -0
- package/template/src/server/routes/todos/special.mjs +47 -0
- package/template/src/server/routes/users/user.mjs +54 -0
- package/template/src/server/server.mjs +10 -0
- package/template/src/server/utils/crypt.mjs +38 -0
- package/template/src/server/utils/io.mjs +15 -0
- package/template/src/server/utils/pwdfor.mjs +25 -0
- package/template/src/server/utils/schema.mjs +22 -0
- package/template/src/static/img/default/profile.png +0 -0
- package/template/src/static/img/favicon.ico +0 -0
- package/template/src/static/img/miolo_logo.png +0 -0
- package/template/src/static/img/miolo_name.png +0 -0
- package/template/src/static/public/manifest.json +21 -0
- package/template/src/static/public/sw.js +79 -0
- package/template/src/static/style/globals.css +156 -0
- package/template/src/static/style/json-tree.css +54 -0
- package/template/src/static/style/skeleton.css +49 -0
- package/bin/prod-build/build-client.mjs +0 -67
- package/bin/prod-build/build-server.mjs +0 -58
- package/bin/prod-run/restart.mjs +0 -9
- package/bin/prod-run/start.mjs +0 -15
- package/bin/prod-run/stop.mjs +0 -20
- package/src/engines/logger/verify.mjs +0 -22
- package/src/middleware/auth/credentials/index.mjs +0 -151
- package/src/middleware/auth/credentials/session/index.mjs +0 -24
- package/src/middleware/auth/credentials/session/store_koa_redis.mjs +0 -3
package/src/config/env.mjs
CHANGED
|
@@ -1,33 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
import { config } from "@dotenvx/dotenvx"
|
|
4
|
+
import { intre_locale_init } from "intre"
|
|
5
|
+
import { findClosestPackageJson, getInfoFromPkg } from "./util.mjs"
|
|
6
|
+
|
|
7
|
+
function _get_miolo_config_path(proyEnvPath, appName) {
|
|
8
|
+
const mioloEnv =
|
|
9
|
+
appName === "miolo-demo" || appName === "miolo-sample"
|
|
10
|
+
? "../miolo/src/config/.env"
|
|
11
|
+
: "node_modules/miolo/src/config/.env"
|
|
12
|
+
|
|
13
|
+
const mioloPath = path.join(proyEnvPath, mioloEnv)
|
|
14
|
+
if (existsSync(mioloPath)) {
|
|
15
|
+
return mioloPath
|
|
16
|
+
}
|
|
17
|
+
return null
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
function _get_miolo_config_path_on_build(proyEnvPath, srvDest) {
|
|
21
|
+
const mioloPath = path.join(proyEnvPath, srvDest, ".env")
|
|
22
|
+
if (existsSync(mioloPath)) {
|
|
23
|
+
return mioloPath
|
|
24
|
+
}
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
16
27
|
|
|
17
|
-
export function init_env_config(
|
|
18
|
-
process.env.
|
|
19
|
-
intre_locale_init(process.env.MIOLO_INTRE_LOCALE)
|
|
28
|
+
export function init_env_config() {
|
|
29
|
+
intre_locale_init(process.env.MIOLO_INTRE_LOCALE)
|
|
20
30
|
|
|
21
31
|
const proyEnvPath = findClosestPackageJson(process.cwd())
|
|
22
|
-
const
|
|
32
|
+
const [appName, srvDest] = getInfoFromPkg(proyEnvPath)
|
|
33
|
+
const debug = process.env.DOTENVX_DEBUG === "true"
|
|
23
34
|
|
|
24
35
|
// miolo defaults
|
|
25
|
-
const libEnvPath = _get_miolo_config_path(proyEnvPath)
|
|
26
|
-
|
|
36
|
+
const libEnvPath = _get_miolo_config_path(proyEnvPath, appName)
|
|
37
|
+
if (libEnvPath) {
|
|
38
|
+
config({ path: libEnvPath, debug })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Maybe miolo defs are on proyect's build folder
|
|
42
|
+
const buildEnvPath = _get_miolo_config_path_on_build(proyEnvPath, srvDest)
|
|
43
|
+
if (buildEnvPath) {
|
|
44
|
+
config({ path: buildEnvPath, debug })
|
|
45
|
+
}
|
|
27
46
|
|
|
28
|
-
// proyect config
|
|
29
|
-
|
|
47
|
+
// proyect root config
|
|
30
48
|
if (proyEnvPath) {
|
|
31
|
-
config({ path: path.join(proyEnvPath,
|
|
49
|
+
config({ path: path.join(proyEnvPath, ".env"), override: true, debug })
|
|
32
50
|
}
|
|
33
51
|
}
|
package/src/config/index.mjs
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import merge from
|
|
2
|
-
import {
|
|
3
|
-
import make_config_defaults from
|
|
4
|
-
|
|
5
|
-
function _get_auth_type(config) {
|
|
6
|
-
if (config?.auth?.basic) {
|
|
7
|
-
return 'basic'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (config?.auth?.credentials) {
|
|
11
|
-
return 'credentials'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (config?.auth?.custom) {
|
|
15
|
-
return 'custom'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return 'guest'
|
|
19
|
-
}
|
|
20
|
-
|
|
1
|
+
import merge from "deepmerge"
|
|
2
|
+
import { isPlainObject } from "is-plain-object"
|
|
3
|
+
import make_config_defaults from "./defaults.mjs"
|
|
4
|
+
import { init_env_config } from "./env.mjs"
|
|
21
5
|
|
|
22
6
|
export function init_config(makeConfig) {
|
|
23
7
|
// Init environment vars
|
|
@@ -26,11 +10,22 @@ export function init_config(makeConfig) {
|
|
|
26
10
|
// delay import of defaults, so env vars can be there
|
|
27
11
|
const base_config = make_config_defaults()
|
|
28
12
|
const custom_config = makeConfig()
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
|
|
14
|
+
// isMergeableObject: objects like Joi schemas should be copied not merged
|
|
15
|
+
const all_config = merge(base_config, custom_config, { isMergeableObject: isPlainObject })
|
|
16
|
+
|
|
31
17
|
// Some addendum
|
|
32
|
-
all_config.
|
|
33
|
-
|
|
18
|
+
all_config.use_catcher = all_config?.http?.catcher_url !== undefined
|
|
19
|
+
|
|
20
|
+
for (const auth_type of ["guest", "basic", "passport"]) {
|
|
21
|
+
if (all_config.auth?.[auth_type] === undefined) {
|
|
22
|
+
all_config.auth[auth_type] = {
|
|
23
|
+
enabled: false
|
|
24
|
+
}
|
|
25
|
+
} else if (all_config.auth[auth_type]?.enabled === undefined) {
|
|
26
|
+
all_config.auth[auth_type].enabled = true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
34
29
|
|
|
35
30
|
return all_config
|
|
36
31
|
}
|
package/src/config/util.mjs
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path from
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
2
|
+
import path from "node:path"
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function getInfoFromPkg(pkgPath) {
|
|
5
5
|
try {
|
|
6
|
-
const packageJsonPath = path.join(pkgPath,
|
|
7
|
-
const content = readFileSync(packageJsonPath,
|
|
6
|
+
const packageJsonPath = path.join(pkgPath, "package.json")
|
|
7
|
+
const content = readFileSync(packageJsonPath, "utf8")
|
|
8
8
|
const packageData = JSON.parse(content)
|
|
9
|
-
|
|
9
|
+
const appName = packageData.name
|
|
10
|
+
|
|
11
|
+
let srvDest = "./build/server"
|
|
12
|
+
try {
|
|
13
|
+
const start = packageData.scripts.start
|
|
14
|
+
if (start) {
|
|
15
|
+
const regex = /^node\s+(.*?)\/run\.mjs(?:$|\s)/
|
|
16
|
+
const match = start.match(regex)
|
|
17
|
+
if (match) {
|
|
18
|
+
srvDest = match[1]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error("[miolo] Error reading <start> package.json:", err)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [appName, srvDest]
|
|
10
26
|
} catch (error) {
|
|
11
|
-
console.error(
|
|
12
|
-
return
|
|
27
|
+
console.error("[miolo] Error reading <name> package.json:", error)
|
|
28
|
+
return ["miolo", "./build/server"]
|
|
13
29
|
}
|
|
14
30
|
}
|
|
15
31
|
|
|
16
32
|
export function findClosestPackageJson(dir) {
|
|
17
|
-
if (existsSync(path.join(dir,
|
|
33
|
+
if (existsSync(path.join(dir, "package.json"))) {
|
|
18
34
|
return dir
|
|
19
35
|
}
|
|
20
36
|
const parentDir = path.dirname(dir)
|
|
@@ -23,4 +39,3 @@ export function findClosestPackageJson(dir) {
|
|
|
23
39
|
}
|
|
24
40
|
return findClosestPackageJson(parentDir)
|
|
25
41
|
}
|
|
26
|
-
|
package/src/db-conn.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { dropConnections, getConnection } from "calustra"
|
|
2
|
+
import { init_config } from "./config/index.mjs"
|
|
3
|
+
import { init_logger } from "./engines/logger/index.mjs"
|
|
4
|
+
import { miolo_cacher_options_for_calustra } from "./middleware/context/cache/options.mjs"
|
|
5
|
+
|
|
6
|
+
export async function miolo_db_connection_pg(makeConfig, options = undefined) {
|
|
7
|
+
const config = init_config(makeConfig)
|
|
8
|
+
|
|
9
|
+
// init logger first
|
|
10
|
+
const logger = init_logger(config.log, undefined, config?.name)
|
|
11
|
+
|
|
12
|
+
if (config.db.config.dialect === "sqlite") {
|
|
13
|
+
logger.error(`[miolo] SQLite is not supported yet`)
|
|
14
|
+
return undefined
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// parse db options
|
|
18
|
+
const dbOptions = {
|
|
19
|
+
...config.db.options,
|
|
20
|
+
...(options || {}),
|
|
21
|
+
log: logger,
|
|
22
|
+
cache: miolo_cacher_options_for_calustra(config, logger)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const conn = await getConnection(config.db.config, dbOptions)
|
|
26
|
+
|
|
27
|
+
conn.get_model = conn.getModel
|
|
28
|
+
|
|
29
|
+
return conn
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function miolo_db_drop_connections() {
|
|
33
|
+
await dropConnections()
|
|
34
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
export function sys_email_queue_config() {
|
|
2
2
|
return {
|
|
3
|
-
name:
|
|
4
|
-
cronTime:
|
|
3
|
+
name: "Emailer",
|
|
4
|
+
cronTime: "* * * * *",
|
|
5
5
|
onTick: async (miolo, _onCompleted) => {
|
|
6
|
-
await miolo.emailer.queue_send_emails(miolo.logger)
|
|
6
|
+
const n = await miolo.emailer.queue_send_emails(miolo.logger)
|
|
7
|
+
if (n === -1) {
|
|
8
|
+
miolo.logger.error(`[emailer] Error sending emails`)
|
|
9
|
+
} else {
|
|
10
|
+
miolo.logger.verbose(`[emailer] Sent ${n} emails`)
|
|
11
|
+
}
|
|
7
12
|
},
|
|
8
|
-
start: true
|
|
13
|
+
start: true
|
|
9
14
|
}
|
|
10
|
-
}
|
|
15
|
+
}
|
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from './syscheck.mjs'
|
|
7
|
-
import {
|
|
8
|
-
ipsum_config
|
|
9
|
-
} from './ipsum.mjs'
|
|
10
|
-
import { cyan, green_bold, yellow_bold } from 'tinguir'
|
|
11
|
-
import { sys_email_queue_config } from './emails.mjs'
|
|
12
|
-
|
|
1
|
+
import { cyan, green_bold, yellow_bold } from "tinguir"
|
|
2
|
+
import { sys_email_queue_config } from "./emails.mjs"
|
|
3
|
+
import { init_cron_job } from "./init.mjs"
|
|
4
|
+
import { ipsum_config } from "./ipsum.mjs"
|
|
5
|
+
import { sys_check_config } from "./syscheck.mjs"
|
|
13
6
|
|
|
14
7
|
export function init_cron(app, custom) {
|
|
15
8
|
const miolo = app.context.miolo
|
|
16
|
-
const logger= miolo.logger
|
|
17
|
-
|
|
18
|
-
const jobConfigs= [
|
|
9
|
+
const logger = miolo.logger
|
|
10
|
+
|
|
11
|
+
const jobConfigs = [
|
|
19
12
|
sys_check_config(),
|
|
20
13
|
ipsum_config(),
|
|
21
14
|
sys_email_queue_config(),
|
|
22
|
-
...custom || []
|
|
15
|
+
...(custom || [])
|
|
23
16
|
]
|
|
24
|
-
|
|
17
|
+
|
|
25
18
|
// Keep trace of conr jobs to be accessible later
|
|
26
|
-
const jobInfos= [
|
|
27
|
-
// {name: 'name', job: <job>, isActive: true/false}
|
|
19
|
+
const jobInfos = [
|
|
20
|
+
// {name: 'name', job: <job>, isActive: true/false}
|
|
28
21
|
]
|
|
29
|
-
|
|
30
|
-
jobConfigs.
|
|
22
|
+
|
|
23
|
+
jobConfigs.forEach((config) => {
|
|
31
24
|
const name = config.name
|
|
32
|
-
const job= init_cron_job(miolo, config)
|
|
25
|
+
const job = init_cron_job(miolo, config)
|
|
33
26
|
jobInfos.push({
|
|
34
|
-
name,
|
|
27
|
+
name,
|
|
35
28
|
job,
|
|
36
29
|
isActive: false
|
|
37
|
-
})
|
|
30
|
+
})
|
|
38
31
|
})
|
|
39
|
-
|
|
32
|
+
|
|
40
33
|
const _find_job_by_idx_or_name = (idxOrName) => {
|
|
41
34
|
let jobInfo
|
|
42
|
-
if (typeof idxOrName
|
|
43
|
-
jobInfo= jobInfos[idxOrName]
|
|
35
|
+
if (typeof idxOrName === "number") {
|
|
36
|
+
jobInfo = jobInfos[idxOrName]
|
|
44
37
|
} else {
|
|
45
|
-
jobInfo= jobInfos.filter(j => j.name
|
|
38
|
+
jobInfo = jobInfos.filter((j) => j.name === idxOrName)[0]
|
|
46
39
|
}
|
|
47
40
|
|
|
48
41
|
if (!jobInfo) {
|
|
@@ -55,15 +48,15 @@ export function init_cron(app, custom) {
|
|
|
55
48
|
const _start_job = async (jobInfo) => {
|
|
56
49
|
try {
|
|
57
50
|
await jobInfo.job.start()
|
|
58
|
-
jobInfo.isActive= true
|
|
59
|
-
logger.debug(`[cron][Job ${cyan(jobInfo.name)}] ${green_bold(
|
|
51
|
+
jobInfo.isActive = true
|
|
52
|
+
logger.debug(`[cron][Job ${cyan(jobInfo.name)}] ${green_bold("started!")}`)
|
|
60
53
|
return 1
|
|
61
|
-
} catch(e) {
|
|
54
|
+
} catch (e) {
|
|
62
55
|
logger.error(`[cron][Job ${cyan(jobInfo.name)}] Error starting it`)
|
|
63
56
|
logger.error(e)
|
|
64
57
|
return 0
|
|
65
58
|
}
|
|
66
|
-
}
|
|
59
|
+
}
|
|
67
60
|
|
|
68
61
|
const _start_job_by_idx_or_name = async (idxOrName) => {
|
|
69
62
|
const jobInfo = _find_job_by_idx_or_name(idxOrName)
|
|
@@ -71,15 +64,16 @@ export function init_cron(app, custom) {
|
|
|
71
64
|
const done = await _start_job(jobInfo)
|
|
72
65
|
return [done, jobInfo.name]
|
|
73
66
|
}
|
|
74
|
-
return [0,
|
|
67
|
+
return [0, ""]
|
|
75
68
|
}
|
|
76
69
|
|
|
77
70
|
const _start_all_jobs = async () => {
|
|
78
71
|
try {
|
|
79
|
-
|
|
72
|
+
const started = [],
|
|
73
|
+
errors = []
|
|
80
74
|
for (const jobInfo of jobInfos) {
|
|
81
|
-
const done= await _start_job(jobInfo)
|
|
82
|
-
if (done
|
|
75
|
+
const done = await _start_job(jobInfo)
|
|
76
|
+
if (done === 1) {
|
|
83
77
|
started.push(jobInfo.name)
|
|
84
78
|
} else {
|
|
85
79
|
errors.push(jobInfo.name)
|
|
@@ -91,19 +85,18 @@ export function init_cron(app, custom) {
|
|
|
91
85
|
if (errors.length > 0) {
|
|
92
86
|
logger.warn(`[cron] Could not start ${errors.length} jobs: ${errors}`)
|
|
93
87
|
}
|
|
94
|
-
} catch(error) {
|
|
88
|
+
} catch (error) {
|
|
95
89
|
logger.error(`[cron] start() error: ${error}`)
|
|
96
90
|
}
|
|
97
|
-
|
|
98
91
|
}
|
|
99
92
|
|
|
100
93
|
const _stop_job = async (jobInfo) => {
|
|
101
94
|
try {
|
|
102
95
|
await jobInfo.job.stop()
|
|
103
|
-
jobInfo.isActive= false
|
|
104
|
-
logger.debug(`[cron][Job ${cyan(jobInfo.name)}] ${yellow_bold(
|
|
96
|
+
jobInfo.isActive = false
|
|
97
|
+
logger.debug(`[cron][Job ${cyan(jobInfo.name)}] ${yellow_bold("stopped!")}`)
|
|
105
98
|
return 1
|
|
106
|
-
} catch(e) {
|
|
99
|
+
} catch (e) {
|
|
107
100
|
logger.error(`[cron][Job ${cyan(jobInfo.name)}] Error stopping it`)
|
|
108
101
|
logger.error(e)
|
|
109
102
|
return 0
|
|
@@ -116,15 +109,16 @@ export function init_cron(app, custom) {
|
|
|
116
109
|
const done = await _stop_job(jobInfo)
|
|
117
110
|
return [done, jobInfo.name]
|
|
118
111
|
}
|
|
119
|
-
return [0,
|
|
112
|
+
return [0, ""]
|
|
120
113
|
}
|
|
121
114
|
|
|
122
115
|
const _stop_all_jobs = async () => {
|
|
123
116
|
try {
|
|
124
|
-
|
|
117
|
+
const stopped = [],
|
|
118
|
+
errors = []
|
|
125
119
|
for (const jobInfo of jobInfos) {
|
|
126
|
-
const done= await _stop_job(jobInfo)
|
|
127
|
-
if (done
|
|
120
|
+
const done = await _stop_job(jobInfo)
|
|
121
|
+
if (done === 1) {
|
|
128
122
|
stopped.push(jobInfo.name)
|
|
129
123
|
} else {
|
|
130
124
|
errors.push(jobInfo.name)
|
|
@@ -136,17 +130,17 @@ export function init_cron(app, custom) {
|
|
|
136
130
|
if (errors.length > 0) {
|
|
137
131
|
logger.warn(`[cron] Could not stop ${errors.length} jobs: ${errors}`)
|
|
138
132
|
}
|
|
139
|
-
} catch(error) {
|
|
133
|
+
} catch (error) {
|
|
140
134
|
logger.error(`[cron] stop() error: ${error}`)
|
|
141
135
|
}
|
|
142
136
|
}
|
|
143
137
|
|
|
144
|
-
app.cron= {
|
|
145
|
-
jobs:
|
|
138
|
+
app.cron = {
|
|
139
|
+
jobs: jobInfos,
|
|
146
140
|
start_one: _start_job_by_idx_or_name,
|
|
147
|
-
start:
|
|
148
|
-
stop_one
|
|
149
|
-
stop:
|
|
141
|
+
start: _start_all_jobs,
|
|
142
|
+
stop_one: _stop_job_by_idx_or_name,
|
|
143
|
+
stop: _stop_all_jobs
|
|
150
144
|
}
|
|
151
145
|
|
|
152
146
|
return app
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { cyan, green_bold } from 'tinguir'
|
|
1
|
+
import { CronJob } from "cron"
|
|
2
|
+
import { cyan, green_bold } from "tinguir"
|
|
4
3
|
|
|
5
4
|
export function init_cron_job(miolo, config) {
|
|
6
|
-
const logger= miolo.logger
|
|
5
|
+
const logger = miolo.logger
|
|
7
6
|
const onTickName = config?.onTick?.name
|
|
8
|
-
? config.onTick.name
|
|
7
|
+
? config.onTick.name !== "onTick"
|
|
9
8
|
? config.onTick.name
|
|
10
|
-
:
|
|
11
|
-
|
|
9
|
+
: "custom"
|
|
10
|
+
: "custom"
|
|
12
11
|
|
|
13
12
|
const name = config?.name || onTickName
|
|
14
13
|
|
|
15
|
-
const job= new CronJob(
|
|
14
|
+
const job = new CronJob(
|
|
16
15
|
// cronTime
|
|
17
|
-
config?.cronTime ||
|
|
18
|
-
|
|
16
|
+
config?.cronTime || "*/5 * * * *",
|
|
17
|
+
|
|
19
18
|
// onTick(miolo, onComplete)
|
|
20
19
|
async (onComplete) => {
|
|
21
20
|
try {
|
|
22
|
-
logger.silly(`[cron][Custom Job ${cyan(name)}] ${green_bold(
|
|
21
|
+
logger.silly(`[cron][Custom Job ${cyan(name)}] ${green_bold("ticks!")}`)
|
|
23
22
|
await config.onTick(miolo, onComplete)
|
|
24
|
-
} catch(e) {
|
|
23
|
+
} catch (e) {
|
|
25
24
|
logger.error(`[cron][Custom Job ${cyan(name)}] Error at onTick()`)
|
|
26
25
|
logger.error(e)
|
|
27
26
|
}
|
|
@@ -29,11 +28,11 @@ export function init_cron_job(miolo, config) {
|
|
|
29
28
|
|
|
30
29
|
// onComplete(miolo)
|
|
31
30
|
async () => {
|
|
32
|
-
logger.silly(`[cron][Custom Job ${cyan(name)}] ${green_bold(
|
|
31
|
+
logger.silly(`[cron][Custom Job ${cyan(name)}] ${green_bold("completed!")}`)
|
|
33
32
|
if (config?.onComplete) {
|
|
34
33
|
try {
|
|
35
34
|
await config.onComplete(miolo)
|
|
36
|
-
} catch(e) {
|
|
35
|
+
} catch (e) {
|
|
37
36
|
logger.error(`[cron][Custom Job ${cyan(name)}] Error at onComplete()`)
|
|
38
37
|
logger.error(e)
|
|
39
38
|
}
|
|
@@ -43,11 +42,11 @@ export function init_cron_job(miolo, config) {
|
|
|
43
42
|
// Do not start yet
|
|
44
43
|
false,
|
|
45
44
|
|
|
46
|
-
config?.timezone ||
|
|
45
|
+
config?.timezone || "Europe/Madrid"
|
|
47
46
|
// config?.context || null,
|
|
48
47
|
// config?.runOnInit || null,
|
|
49
48
|
// config?.utcOffset || null,
|
|
50
49
|
// config?.unrefTimeout || null,
|
|
51
|
-
)
|
|
50
|
+
)
|
|
52
51
|
return job
|
|
53
|
-
}
|
|
52
|
+
}
|