@chamba/adapters 0.11.1 → 0.13.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.
- package/dist/index.d.ts +7 -2
- package/dist/index.js +24 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilesystemPort, DirEntry, ProcessPort, ProcessExecOptions, ProcessResult, ClockPort } from '@chamba/core';
|
|
1
|
+
import { FilesystemPort, DirEntry, ProcessPort, ProcessExecOptions, ProcessResult, SystemPort, SystemResources, ClockPort } from '@chamba/core';
|
|
2
2
|
|
|
3
3
|
/** Node-backed `FilesystemPort`. */
|
|
4
4
|
declare class NodeFilesystem implements FilesystemPort {
|
|
@@ -15,10 +15,15 @@ declare class NodeProcess implements ProcessPort {
|
|
|
15
15
|
exec(command: string, args: string[], options?: ProcessExecOptions): Promise<ProcessResult>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Node-backed `SystemPort` reading live machine resources via `node:os`. */
|
|
19
|
+
declare class NodeSystem implements SystemPort {
|
|
20
|
+
resources(): SystemResources;
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
/** Node-backed `ClockPort` using the system clock. */
|
|
19
24
|
declare class SystemClock implements ClockPort {
|
|
20
25
|
now(): Date;
|
|
21
26
|
today(): string;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
export { NodeFilesystem, NodeProcess, SystemClock };
|
|
29
|
+
export { NodeFilesystem, NodeProcess, NodeSystem, SystemClock };
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,29 @@ var NodeProcess = class {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
// src/node-system.ts
|
|
55
|
+
import { availableParallelism, cpus, freemem, loadavg, totalmem } from "os";
|
|
56
|
+
var NodeSystem = class {
|
|
57
|
+
resources() {
|
|
58
|
+
return {
|
|
59
|
+
totalMemBytes: totalmem(),
|
|
60
|
+
freeMemBytes: freemem(),
|
|
61
|
+
// availableParallelism (Node 19+) is container/affinity-aware; fall back
|
|
62
|
+
// to the raw logical core count if it's ever unavailable.
|
|
63
|
+
cpus: safeParallelism(),
|
|
64
|
+
// loadavg() returns [0, 0, 0] on Windows — treated as "no load" upstream.
|
|
65
|
+
loadAvg1: loadavg()[0] ?? 0
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function safeParallelism() {
|
|
70
|
+
try {
|
|
71
|
+
return availableParallelism();
|
|
72
|
+
} catch {
|
|
73
|
+
return cpus().length || 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
54
77
|
// src/system-clock.ts
|
|
55
78
|
var SystemClock = class {
|
|
56
79
|
now() {
|
|
@@ -63,5 +86,6 @@ var SystemClock = class {
|
|
|
63
86
|
export {
|
|
64
87
|
NodeFilesystem,
|
|
65
88
|
NodeProcess,
|
|
89
|
+
NodeSystem,
|
|
66
90
|
SystemClock
|
|
67
91
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chamba/adapters",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Node implementations of @chamba/core ports (filesystem, process, clock)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"node"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@chamba/core": "0.
|
|
35
|
+
"@chamba/core": "0.13.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^22.0.0",
|