@sigil-dev/plugin-namepool 0.8.6 → 0.9.1
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/README.md +55 -1
- package/index.ts +10 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sigil-dev/plugin-namepool
|
|
2
|
+
|
|
3
|
+
Assigns human-readable names to Grimoire workers instead of the default `mode-index` identifiers like `api-0`, `ws-1`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @sigil-dev/plugin-namepool
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from "@sigil-dev/grimoire";
|
|
15
|
+
import { namepool } from "@sigil-dev/plugin-namepool";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [
|
|
19
|
+
namepool({ names: ["Rei", "Asuka", "Misato", "Kaworu", "Ritsuko"] }),
|
|
20
|
+
],
|
|
21
|
+
dev: true,
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Workers are assigned names by `globalIndex` — the first worker across all modes gets `names[0]`, the second gets `names[1]`, and so on. If there are more workers than names, the remainder fall back to `mode-index`.
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
interface NamepoolOptions {
|
|
31
|
+
names: string[];
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Option | Type | Description |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `names` | `string[]` | Ordered list of names to assign to workers by global index. |
|
|
38
|
+
|
|
39
|
+
## Integration with plugin-health
|
|
40
|
+
|
|
41
|
+
When both plugins are registered, `plugin-health` automatically picks up the name pool and uses it to report `reserved` workers — names in the pool that have no live worker assigned. No manual wiring needed.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { namepool } from "@sigil-dev/plugin-namepool";
|
|
45
|
+
import { healthPlugin } from "@sigil-dev/plugin-health";
|
|
46
|
+
|
|
47
|
+
export default defineConfig({
|
|
48
|
+
plugins: [
|
|
49
|
+
namepool({ names: ["Rei", "Asuka", "Shinji"] }),
|
|
50
|
+
healthPlugin(), // finds namepool automatically via onPluginsResolved
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The `/health` endpoint will include all three names in the cluster array, marking any without a live worker as `"reserved"`.
|
package/index.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
// packages/grimoire/src/plugins/namepool.ts
|
|
2
1
|
import type {
|
|
3
2
|
GrimoirePlugin,
|
|
4
3
|
WorkerDescriptor,
|
|
5
4
|
WorkerEnv,
|
|
6
|
-
//@ts-expect-error
|
|
5
|
+
//@ts-expect-error the import is there, and tests pass, but fucking LSP cries and bitches
|
|
7
6
|
} from "@sigil/grimoire";
|
|
8
7
|
|
|
9
8
|
export function namepool(options: { names: string[] }): GrimoirePlugin {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
9
|
+
return {
|
|
10
|
+
name: "namepool",
|
|
11
|
+
names: options.names,
|
|
12
|
+
onWorkerSpawn(worker: WorkerDescriptor): WorkerEnv {
|
|
13
|
+
const name = options.names[worker.globalIndex] ?? `${worker.mode}-${worker.index}`;
|
|
14
|
+
return { name };
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigil-dev/plugin-namepool",
|
|
3
|
+
"description": "Automatic worker names for Sigil",
|
|
3
4
|
"module": "index.ts",
|
|
4
|
-
"version": "0.
|
|
5
|
+
"version": "0.9.1",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"private": false,
|
|
7
8
|
"devDependencies": {
|
|
@@ -9,6 +10,6 @@
|
|
|
9
10
|
},
|
|
10
11
|
"peerDependencies": {
|
|
11
12
|
"typescript": "^5",
|
|
12
|
-
"@sigil-dev/grimoire": "0.
|
|
13
|
+
"@sigil-dev/grimoire": "0.9.1"
|
|
13
14
|
}
|
|
14
15
|
}
|