miolo 3.0.0-beta.206 → 3.0.0-beta.208

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miolo",
3
- "version": "3.0.0-beta.206",
3
+ "version": "3.0.0-beta.208",
4
4
  "description": "all-in-one koa-based server",
5
5
  "author": "Donato Lorenzo <donato@afialapis.com>",
6
6
  "contributors": [
@@ -25,6 +25,7 @@ export async function init_ssr_render_middleware(app, config, devRender = undefi
25
25
  port: httpConfig?.port,
26
26
  catcher_url: httpConfig?.catcher_url,
27
27
  auth_method: ctx.session?.auth_method,
28
+ log_level: ctx.miolo.logger.level,
28
29
  login_url:
29
30
  ctx.session?.auth_method === "google"
30
31
  ? authConfig?.passport?.google_url_login
package/template/.env CHANGED
@@ -59,7 +59,7 @@ MIOLO_DB_POOL_IDLE_TIMEOUT_MS=10000
59
59
  # Logging
60
60
  #
61
61
 
62
- MIOLO_LOG_LEVEL=info
62
+ MIOLO_LOG_LEVEL=verbose
63
63
  MIOLO_LOG_CONSOLE_ENABLED=true
64
64
  MIOLO_LOG_FILE_ENABLED=false
65
65
  MIOLO_LOG_MAIL_ENABLED=false
@@ -45,9 +45,9 @@
45
45
  "intre": "^3.0.0-beta.4",
46
46
  "joi": "^18.2.1",
47
47
  "lucide-react": "^1.17.0",
48
- "miolo-cli": "^3.0.0-beta.206",
48
+ "miolo-cli": "^3.0.0-beta.208",
49
49
  "miolo-model": "file:../miolo-model",
50
- "miolo-react": "^3.0.0-beta.206",
50
+ "miolo-react": "^3.0.0-beta.208",
51
51
  "next-themes": "^0.4.6",
52
52
  "radix-ui": "^1.4.3",
53
53
  "react": "^19.2.7",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "devDependencies": {
64
64
  "@biomejs/biome": "2.4.16",
65
- "miolo": "^3.0.0-beta.206",
65
+ "miolo": "^3.0.0-beta.208",
66
66
  "sass-embedded": "^1.100.0"
67
67
  },
68
68
  "overrides": {
@@ -1,3 +1,4 @@
1
+ import { useMioloContext } from "miolo-react"
1
2
  import { useCallback, useEffect, useState } from "react"
2
3
  import useSessionContext from "#cli/context/session/useSessionContext.mjs"
3
4
  import useUIContext from "#cli/context/ui/useUIContext.mjs"
@@ -6,6 +7,7 @@ import TodosContext from "./TodosContext.jsx"
6
7
 
7
8
  const TodosProvider = ({ children }) => {
8
9
  // const [status, setStatus] = useState("loaded")
10
+ const { logger } = useMioloContext()
9
11
  const { useSsrData, fetcher, socket, authenticated } = useSessionContext()
10
12
  const { toast } = useUIContext()
11
13
  const [useCrud, setUseCrud] = useState(true)
@@ -15,7 +17,8 @@ const TodosProvider = ({ children }) => {
15
17
  data: todoList,
16
18
  setData: setTodoList,
17
19
  refresh: refreshTodoList,
18
- ready
20
+ ready,
21
+ invalidate: invalidateTodoList
19
22
  } = useSsrData("todos", {
20
23
  model: TodoList,
21
24
  loader: useCallback(
@@ -31,7 +34,8 @@ const TodosProvider = ({ children }) => {
31
34
  return data.sort((a, b) => b.created_at - a.created_at)
32
35
  },
33
36
  [useCrud, toast]
34
- )
37
+ ),
38
+ cache: true
35
39
  })
36
40
 
37
41
  const addTodo = useCallback(
@@ -152,14 +156,14 @@ const TodosProvider = ({ children }) => {
152
156
  setSocketInited(true)
153
157
 
154
158
  socket.on("connect", () => {
155
- console.log("Connected to server!")
159
+ logger.info("Connected to server!")
156
160
  })
157
161
 
158
162
  socket.on("todos-update", (data) => {
159
- console.log("TODOS UPDATED!!!")
160
- console.log(data)
163
+ logger.info("TODOS UPDATED!!!")
164
+ logger.info(data)
161
165
  })
162
- }, [socket, socketInited])
166
+ }, [socket, socketInited, logger])
163
167
 
164
168
  return (
165
169
  <TodosContext.Provider
@@ -1,4 +1,5 @@
1
1
  import { onTickFoo } from "./foo.mjs"
2
+ import { cacheInvalidate } from "./invalidate.mjs"
2
3
 
3
4
  // check https://github.com/kelektiv/node-cron#readme
4
5
  //
@@ -14,6 +15,13 @@ export default function init_cron() {
14
15
  start: true
15
16
  })
16
17
 
18
+ cronList.push({
19
+ name: "miolo-sample-cache-invalidate",
20
+ cronTime: "*/1 * * * *",
21
+ onTick: cacheInvalidate,
22
+ start: true
23
+ })
24
+
17
25
  console.log(`[miolo-sample][cron] ${cronList.length} custom cron jobs loaded`)
18
26
 
19
27
  return cronList
@@ -0,0 +1,10 @@
1
+ import { blue } from "tinguir"
2
+
3
+ export const cacheInvalidate = async (miolo) => {
4
+ miolo.logger.info(`${blue("[cron][cache_invalidate]")} Invalidating cache...`)
5
+
6
+ // broadcast an event to all clients
7
+ miolo.io.emit("ssr-invalidate", { name: "todos" })
8
+
9
+ miolo.logger.info(`${blue("[cron][cache_invalidate]")} Cache invalidated!`)
10
+ }
@@ -1,38 +0,0 @@
1
- import { cyan, gray_light, red, yellow } from "tinguir"
2
-
3
- function _msg(msg, prefix) {
4
- const _m = typeof msg === "string" ? msg : JSON.stringify(msg || "")
5
- return `${prefix ? `[${prefix}]` : ""} ${_m}`
6
- }
7
-
8
- // export function mioloLog(msg, prefix = 'app') {
9
- // console.log(`\u001b[0;34m${_msg(msg, prefix)}\u001b[0;39m`)
10
- // }
11
- //
12
- // export function mioloLogDebug(msg, prefix = 'app') {
13
- // console.log(`\u001b[38;5;244m${_msg(msg, prefix)}\u001b[38;5;39m`)
14
- // }
15
- //
16
- // export function mioloWarn(msg, prefix = 'app') {
17
- // console.log(`\u001b[0;31m${_msg(msg, prefix)}\u001b[0;39m`)
18
- // }
19
- //
20
- // export function mioloError(msg, prefix = 'app') {
21
- // console.log(`\u001b[0;31m${_msg(msg, prefix)}\u001b[0;39m`)
22
- // }
23
-
24
- export function mioloLogDebug(msg, prefix = "app") {
25
- console.log(gray_light(_msg(msg, prefix)))
26
- }
27
-
28
- export function mioloLog(msg, prefix = "app") {
29
- console.log(cyan(_msg(msg, prefix)))
30
- }
31
-
32
- export function mioloWarn(msg, prefix = "app") {
33
- console.log(yellow(_msg(msg, prefix)))
34
- }
35
-
36
- export function mioloError(msg, prefix = "app") {
37
- console.log(red(_msg(msg, prefix)))
38
- }