@hadoku/service-kernel 0.1.211 → 0.1.212

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.
@@ -1,2 +1 @@
1
- export { moveLegacyDir, moveLegacyState, type StateMove } from './state-dir.js';
2
1
  export { atomicWriteJson } from './atomic-write.js';
@@ -1,2 +1 @@
1
- export { moveLegacyDir, moveLegacyState } from "./state-dir.js";
2
1
  export { atomicWriteJson } from "./atomic-write.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/service-kernel",
3
- "version": "0.1.211",
4
- "gitHead": "178f9274df3c7083ddec4b5ac1cf9fcb8b880360",
3
+ "version": "0.1.212",
4
+ "gitHead": "989dce1f6edefb23bc21cdde27935b9e8ef9d35a",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The server parts any game keeps: edge auth and the tier gate, base path and bundle check, health and the busy probe, lifecycle, the JSON logger, the state directory, telemetry and capacity, per-caller limits, the browser relays, the erase registry, and createGameServer, which boots a game from its config and plugins. Knows no game; the app binds its service id, prefix and env names. MIT; imports only node built-ins, express, socket.io, platform-wire and @wolffm/*.",
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "dependencies": {
59
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.178",
59
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.179",
60
60
  "express": "^5.1.0",
61
61
  "socket.io": "^4.8.3"
62
62
  },
@@ -1,39 +0,0 @@
1
- /**
2
- * The boot move from an in-clone layout to a state directory the app sets up
3
- * outside its deploy clone.
4
- *
5
- * Until a deploy builds its new clone aside and swaps it in, everything a
6
- * server writes lives in the clone (e.g. `apps/server/data`, `apps/server/logs`).
7
- * A swapped clone has none of it, so the state has to live outside before that
8
- * deploy is turned on. The first boot that has a state dir moves each entry of
9
- * the old directory into the new one; an entry already there is never
10
- * overwritten, and is left where it was and reported. Runs before anything opens
11
- * a store.
12
- */
13
- export interface StateMove {
14
- from: string;
15
- to: string;
16
- /** Entries moved into `to`. */
17
- moved: string[];
18
- /** Entries left in `from` because `to` already holds one of that name. */
19
- kept: string[];
20
- }
21
- /**
22
- * Move every entry of `from` into `to` that `to` lacks, then remove `from` if
23
- * that emptied it. Null when there was nothing to move: `from` missing, or the
24
- * same directory as `to`.
25
- */
26
- export declare function moveLegacyDir(from: string, to: string): StateMove | null;
27
- /**
28
- * The boot move for a server: its in-clone `data/` and `logs/` into the state
29
- * dir, when one is set. Logs one `state-moved` line per directory that held
30
- * anything, so the cutover is visible in pm2's log.
31
- */
32
- export declare function moveLegacyState(config: {
33
- stateDir: string;
34
- dataDir: string;
35
- logDir: string;
36
- }, legacy: {
37
- dataDir: string;
38
- logDir: string;
39
- }, log: (entry: Record<string, unknown>) => void): StateMove[];
@@ -1,63 +0,0 @@
1
- /**
2
- * The boot move from an in-clone layout to a state directory the app sets up
3
- * outside its deploy clone.
4
- *
5
- * Until a deploy builds its new clone aside and swaps it in, everything a
6
- * server writes lives in the clone (e.g. `apps/server/data`, `apps/server/logs`).
7
- * A swapped clone has none of it, so the state has to live outside before that
8
- * deploy is turned on. The first boot that has a state dir moves each entry of
9
- * the old directory into the new one; an entry already there is never
10
- * overwritten, and is left where it was and reported. Runs before anything opens
11
- * a store.
12
- */
13
- import { cpSync, existsSync, mkdirSync, readdirSync, renameSync, rmdirSync, rmSync } from 'node:fs';
14
- import { join, resolve } from 'node:path';
15
- /** Rename, or copy then delete when `to` is on another filesystem. */
16
- function moveEntry(from, to) {
17
- try {
18
- renameSync(from, to);
19
- }
20
- catch (err) {
21
- if (err.code !== 'EXDEV')
22
- throw err;
23
- cpSync(from, to, { recursive: true, preserveTimestamps: true, verbatimSymlinks: true });
24
- rmSync(from, { recursive: true, force: true });
25
- }
26
- }
27
- /**
28
- * Move every entry of `from` into `to` that `to` lacks, then remove `from` if
29
- * that emptied it. Null when there was nothing to move: `from` missing, or the
30
- * same directory as `to`.
31
- */
32
- export function moveLegacyDir(from, to) {
33
- const src = resolve(from);
34
- const dst = resolve(to);
35
- if (src === dst || !existsSync(src))
36
- return null;
37
- mkdirSync(dst, { recursive: true });
38
- const move = { from: src, to: dst, moved: [], kept: [] };
39
- for (const name of readdirSync(src).sort()) {
40
- if (existsSync(join(dst, name))) {
41
- move.kept.push(name);
42
- continue;
43
- }
44
- moveEntry(join(src, name), join(dst, name));
45
- move.moved.push(name);
46
- }
47
- if (move.kept.length === 0)
48
- rmdirSync(src);
49
- return move;
50
- }
51
- /**
52
- * The boot move for a server: its in-clone `data/` and `logs/` into the state
53
- * dir, when one is set. Logs one `state-moved` line per directory that held
54
- * anything, so the cutover is visible in pm2's log.
55
- */
56
- export function moveLegacyState(config, legacy, log) {
57
- if (!config.stateDir)
58
- return [];
59
- const moves = [moveLegacyDir(legacy.dataDir, config.dataDir), moveLegacyDir(legacy.logDir, config.logDir)].filter((m) => m !== null);
60
- for (const m of moves)
61
- log({ event: m.kept.length ? 'state-moved-partly' : 'state-moved', ...m });
62
- return moves;
63
- }