@hadoku/service-kernel 0.1.243 → 0.1.245

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.
@@ -10,20 +10,10 @@ export interface Embed {
10
10
  url: string;
11
11
  color: number;
12
12
  }
13
- /**
14
- * How release-notes file names are ordered: the kernel knows no directory layout of its own, so
15
- * the app supplies this (cardtable's adapter binds `packages/devkit/src/release/build-version.ts`).
16
- */
17
- export interface ReleaseOrdering {
18
- /** The newest release file name among `names`, or null when there is none. */
19
- newest(names: readonly string[]): string | null;
20
- /** Every release file name among `names`, newest first. */
21
- newestFirst(names: readonly string[]): string[];
22
- }
23
- /** The newest release notes in `dir`, by `ordering`, or null when there are none. */
24
- export declare function latestRelease(dir: string, ordering: ReleaseOrdering): Promise<ReleaseNotes | null>;
25
- /** Every release's notes in `dir`, newest first, by `ordering`. */
26
- export declare function allReleases(dir: string, ordering: ReleaseOrdering): Promise<ReleaseNotes[]>;
13
+ /** The newest release notes in `dir`, or null when there are none. */
14
+ export declare function latestRelease(dir: string): Promise<ReleaseNotes | null>;
15
+ /** Every release's notes in `dir`, newest first. */
16
+ export declare function allReleases(dir: string): Promise<ReleaseNotes[]>;
27
17
  /** The `# ` heading is the title; everything after it is the body. */
28
18
  export declare function parseNotes(version: string, text: string): ReleaseNotes;
29
19
  /**
@@ -74,7 +64,6 @@ export declare function creditsBody(releases: readonly ReleaseNotes[], earlier:
74
64
  export interface AnnounceOptions {
75
65
  /** This app's id: the idempotency key and `source` field are `<service>-release-<version>` / `service`. */
76
66
  service: string;
77
- ordering: ReleaseOrdering;
78
67
  releasesDir: string;
79
68
  /** The app's webhook secret; empty = skip. */
80
69
  secret: string;
@@ -20,31 +20,29 @@
20
20
  * `secret` is the app's webhook secret (empty = skip, never an error); a failed post never blocks
21
21
  * boot, and the next boot retries it.
22
22
  *
23
- * `ordering` decides which release files are newest: the kernel does not read a release-notes
24
- * directory layout itself. The app supplies it (cardtable's adapter injects
25
- * `packages/devkit/src/release/build-version.ts`'s `newestReleaseFile`/`releaseFilesNewestFirst`, since the
26
- * kernel cannot import `scripts/`).
23
+ * Which files are releases, and which is newest, is `release-files.ts`: `vX.Y.Z.md` by semver.
27
24
  *
28
25
  * Imports only; nothing runs at import.
29
26
  */
30
27
  import { readdir, readFile } from 'node:fs/promises';
31
28
  import { join } from 'node:path';
32
29
  import { archivebotPost } from "./archivebot.js";
30
+ import { newestReleaseFile, releaseFilesNewestFirst } from "./release-files.js";
33
31
  /** Discord's (and ArchiveBot's) per-embed description cap. */
34
32
  const DESCRIPTION_MAX = 4096;
35
33
  /** Discord's cap on one message's embeds: their titles and descriptions together. */
36
34
  const MESSAGE_MAX = 6000;
37
35
  const COLOR = 0x2f855a;
38
- /** The newest release notes in `dir`, by `ordering`, or null when there are none. */
39
- export async function latestRelease(dir, ordering) {
40
- const newest = ordering.newest(await readdir(dir));
36
+ /** The newest release notes in `dir`, or null when there are none. */
37
+ export async function latestRelease(dir) {
38
+ const newest = newestReleaseFile(await readdir(dir));
41
39
  if (newest === null)
42
40
  return null;
43
41
  return parseNotes(newest.slice(0, -'.md'.length), await readFile(join(dir, newest), 'utf8'));
44
42
  }
45
- /** Every release's notes in `dir`, newest first, by `ordering`. */
46
- export async function allReleases(dir, ordering) {
47
- const names = ordering.newestFirst(await readdir(dir));
43
+ /** Every release's notes in `dir`, newest first. */
44
+ export async function allReleases(dir) {
45
+ const names = releaseFilesNewestFirst(await readdir(dir));
48
46
  return Promise.all(names.map(async (name) => parseNotes(name.slice(0, -'.md'.length), await readFile(join(dir, name), 'utf8'))));
49
47
  }
50
48
  /** The `# ` heading is the title; everything after it is the body. */
@@ -322,14 +320,14 @@ async function readEarlierCredits(file) {
322
320
  * logged, never thrown.
323
321
  */
324
322
  export async function announceRelease(options) {
325
- const { log, service, ordering } = options;
323
+ const { log, service } = options;
326
324
  if (options.secret === '') {
327
325
  log({ event: 'release-announce', outcome: 'skipped', reason: `no ${options.secretEnvName}` });
328
326
  return;
329
327
  }
330
328
  let releases;
331
329
  try {
332
- releases = await allReleases(options.releasesDir, ordering);
330
+ releases = await allReleases(options.releasesDir);
333
331
  }
334
332
  catch (err) {
335
333
  log({ event: 'release-announce', outcome: 'failed', ...thrown(err) });
@@ -2,5 +2,6 @@ export { arrivedVia, busyHandler, isLocalProbe, type BusyReport, type BusyRun }
2
2
  export { bootClock } from './bootClock.js';
3
3
  export { closeConnections, sendThenFlush, type Closable, type Flushable } from './flush-sockets.js';
4
4
  export { toggleInspector } from './inspector.js';
5
- export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, postMessages, releaseMessages, showCredits, splitBody, type AnnounceOptions, type CreditCount, type Embed, type ReleaseNotes, type ReleaseOrdering, } from './announce.js';
5
+ export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, postMessages, releaseMessages, showCredits, splitBody, type AnnounceOptions, type CreditCount, type Embed, type ReleaseNotes, } from './announce.js';
6
+ export { newestReleaseFile, releaseFilesNewestFirst } from './release-files.js';
6
7
  export { archivebotPost, type ArchivebotReply, type ArchivebotTarget } from './archivebot.js';
@@ -3,4 +3,5 @@ export { bootClock } from "./bootClock.js";
3
3
  export { closeConnections, sendThenFlush } from "./flush-sockets.js";
4
4
  export { toggleInspector } from "./inspector.js";
5
5
  export { allReleases, announceRelease, creditCounts, creditMark, creditsBody, creditsIn, CREDITS_TITLE, forDiscord, latestRelease, parseNotes, postMessages, releaseMessages, showCredits, splitBody, } from "./announce.js";
6
+ export { newestReleaseFile, releaseFilesNewestFirst } from "./release-files.js";
6
7
  export { archivebotPost } from "./archivebot.js";
@@ -0,0 +1,4 @@
1
+ /** The `vX.Y.Z.md` file names, newest first by semver (the name itself). */
2
+ export declare function releaseFilesNewestFirst(names: readonly string[]): string[];
3
+ /** The newest `vX.Y.Z.md` among file names, by semver (the name itself); null when there is none. */
4
+ export declare function newestReleaseFile(names: readonly string[]): string | null;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Which release-notes files a directory holds, newest first: `vX.Y.Z.md` by semver. The release
3
+ * announce reads the notes through it, and a build's version (devkit's `build-version.ts`) is the
4
+ * newest of them. Imports nothing.
5
+ */
6
+ const RELEASE_FILE = /^v(\d+)\.(\d+)\.(\d+)\.md$/;
7
+ /** The `vX.Y.Z.md` file names, newest first by semver (the name itself). */
8
+ export function releaseFilesNewestFirst(names) {
9
+ const parsed = names.flatMap((name) => {
10
+ const m = RELEASE_FILE.exec(name);
11
+ return m === null ? [] : [{ name, parts: [Number(m[1]), Number(m[2]), Number(m[3])] }];
12
+ });
13
+ parsed.sort((a, b) => b.parts[0] - a.parts[0] || b.parts[1] - a.parts[1] || b.parts[2] - a.parts[2]);
14
+ return parsed.map((p) => p.name);
15
+ }
16
+ /** The newest `vX.Y.Z.md` among file names, by semver (the name itself); null when there is none. */
17
+ export function newestReleaseFile(names) {
18
+ return releaseFilesNewestFirst(names)[0] ?? null;
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/service-kernel",
3
- "version": "0.1.243",
4
- "gitHead": "ca9b709efeb5904d97fe93c939ef8a8ee21dcec2",
3
+ "version": "0.1.245",
4
+ "gitHead": "a9e2641a46c10f8803503badaf42ec88a15b23e9",
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.210",
59
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.212",
60
60
  "express": "^5.1.0",
61
61
  "socket.io": "^4.8.3"
62
62
  },