evikit 2.4.0 → 2.5.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.
@@ -0,0 +1,26 @@
1
+ when:
2
+ - event: push
3
+ branch: main
4
+ - event: pull_request
5
+
6
+ steps:
7
+ - name: build
8
+ image: node:24-alpine
9
+ commands:
10
+ - apk add git
11
+ # Are types correct?
12
+ - npm i
13
+ - npm run lint
14
+ - npx tsc
15
+ # Does todo app example build?
16
+ - npm create evikit my-app
17
+ - rm -rf my-app/node_modules/evikit
18
+ - (cd my-app/node_modules; git clone ../.. evikit)
19
+ - (cd my-app; npm run build)
20
+ # Does real-world application pass tests?
21
+ - git clone https://codeberg.org/nykula/lanquiz
22
+ - (cd lanquiz; npm i)
23
+ - rm -rf lanquiz/node_modules/evikit
24
+ - (cd lanquiz/node_modules; git clone ../.. evikit)
25
+ - (cd lanquiz; npm run build)
26
+ - (cd lanquiz; npm test -- --test-concurrency=1)
package/README.md CHANGED
@@ -932,6 +932,26 @@ Change your `index.html` like this:
932
932
 
933
933
  Style your app however you like.
934
934
 
935
+ ### Background worker
936
+
937
+ You can run something repeatedly in main process, not in listeners for each CPU core. In development, it will restart whenever you edit api routes.
938
+
939
+ Add to `src/lib/db/index.js`:
940
+
941
+ ```js
942
+ import { daemon } from "evikit/server";
943
+
944
+ // ...
945
+
946
+ const unique = crypto.randomUUID();
947
+ daemon(() => {
948
+ const interval = setInterval(() => {
949
+ console.log({ now: Date.now(), unique });
950
+ }, 1000);
951
+ return () => clearInterval(interval);
952
+ });
953
+ ```
954
+
935
955
  ### Testing
936
956
 
937
957
  A practical integration test for EviKit itself is [Lanquiz](https://codeberg.org/nykula/lanquiz), an app to host quizzes in LAN from a laptop, which is built on top of EviKit.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "evikit",
3
3
  "description": "Preact/SQLite SSR framework for small web apps",
4
- "version": "2.4.0",
4
+ "version": "2.5.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./index.js",
package/server.d.ts CHANGED
@@ -8,6 +8,8 @@ import type {
8
8
  ServerText,
9
9
  } from "./server-generic.js";
10
10
 
11
+ export function daemon(callback: () => () => void): void;
12
+
11
13
  export const endpoint: ServerEndpoint;
12
14
 
13
15
  export const json: ServerJson;
package/server.js CHANGED
@@ -20,6 +20,21 @@ import {
20
20
 
21
21
  import { Po } from "./i18n.js";
22
22
 
23
+ /** @param {() => () => void} callback */
24
+ export function daemon(callback) {
25
+ if (
26
+ (process.env["npm_command"] == "start" && cluster.isPrimary) ||
27
+ process.env["npm_lifecycle_event"] == "dev"
28
+ ) {
29
+ /** @type {any} */
30
+ const self = globalThis;
31
+ if (self.clearDaemon) {
32
+ self.clearDaemon();
33
+ }
34
+ self.clearDaemon = callback();
35
+ }
36
+ }
37
+
23
38
  /** @type {import("./server-generic.js").ServerEndpoint} */
24
39
  export function endpoint({ input, outputs }, handler) {
25
40
  const arrayOf = ArrayOf(input);