@systemfsoftware/effect-daemon-process 0.2.0 → 1.0.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/CHANGELOG.md +20 -0
- package/README.md +1 -2
- package/dist/mod.d.ts +1 -1
- package/dist/mod.mjs +96 -23
- package/package.json +13 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @systemfsoftware/effect-daemon-process
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Require `effect` `^4` (stable 4.0.0). Release candidates are no longer supported: imports follow 4.0.0's module layout (`effect/http`, `effect/rpc`, `effect/http-api`, `effect/cluster`, `effect/process`, `effect/socket`, `effect/persistence`, `effect/reactivity`, `effect/encoding`, `effect/Arbitrary`), which does not exist in any 4.0.0 RC.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies:
|
|
12
|
+
- @systemfsoftware/effect-cell-types@12.0.0
|
|
13
|
+
- @systemfsoftware/effect-daemon-conformance@1.0.0
|
|
14
|
+
- @systemfsoftware/effect-daemon-spec@6.0.0
|
|
15
|
+
|
|
16
|
+
## 0.2.1
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies:
|
|
21
|
+
- @systemfsoftware/effect-cell-types@11.0.0
|
|
22
|
+
|
|
3
23
|
## 0.2.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ import { NodeChildProcessSpawner, NodeFileSystem, NodePath } from '@effect/platf
|
|
|
35
35
|
import { ProcessMedium } from '@systemfsoftware/effect-daemon-process'
|
|
36
36
|
import { Supervisor } from '@systemfsoftware/effect-daemon-spec'
|
|
37
37
|
import { Effect, Layer } from 'effect'
|
|
38
|
-
import { ChildProcess } from 'effect/
|
|
38
|
+
import { ChildProcess } from 'effect/process'
|
|
39
39
|
|
|
40
40
|
const program = ChildProcess.make('node', ['server.js'], { env: { PORT: '8080' } })
|
|
41
41
|
|
|
@@ -104,7 +104,6 @@ medium under proof reads as readiness.
|
|
|
104
104
|
pnpm --filter @systemfsoftware/effect-daemon-process typecheck
|
|
105
105
|
pnpm --filter @systemfsoftware/effect-daemon-process lint
|
|
106
106
|
pnpm --filter @systemfsoftware/effect-daemon-process test
|
|
107
|
-
pnpm --filter @systemfsoftware/effect-daemon-process test:contract
|
|
108
107
|
pnpm --filter @systemfsoftware/effect-daemon-process build
|
|
109
108
|
```
|
|
110
109
|
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Layer, Scope } from "effect";
|
|
2
2
|
import * as PlatformError from "effect/PlatformError";
|
|
3
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/
|
|
3
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
4
4
|
import { Supervisor } from "@systemfsoftware/effect-daemon-spec";
|
|
5
5
|
import { Conformance } from "@systemfsoftware/effect-daemon-conformance";
|
|
6
6
|
//#region src/ProcessMedium/conformance-driver.d.ts
|
package/dist/mod.mjs
CHANGED
|
@@ -1,8 +1,92 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import { Deferred, Duration, Effect, HashMap, Layer, Match, Option, Queue, Ref, Stream } from "effect";
|
|
2
|
+
import { Deferred, Duration, Effect, HashMap, Layer, Match, Option, Queue, Ref, Schema, Stream } from "effect";
|
|
3
3
|
import "effect/PlatformError";
|
|
4
|
-
import { ChildProcess, ChildProcessSpawner } from "effect/
|
|
4
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
5
5
|
import { Supervisor } from "@systemfsoftware/effect-daemon-spec";
|
|
6
|
+
import { absurd } from "effect/Function";
|
|
7
|
+
import * as Result from "effect/Result";
|
|
8
|
+
import { Workflow } from "@systemfsoftware/effect-cell-types";
|
|
9
|
+
//#region src/ProcessMedium/ProcessExit.schema.ts
|
|
10
|
+
const Exited = Schema.TaggedStruct("Exited", { code: Schema.Int });
|
|
11
|
+
const Signaled = Schema.TaggedStruct("Signaled", { detail: Schema.String });
|
|
12
|
+
const ProcessExit = Schema.Union([Exited, Signaled]);
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/ProcessMedium/ProcessExitDecision.schema.ts
|
|
15
|
+
const ProcessExitDecisionTypeId = Symbol.for("@systemfsoftware/effect-daemon-process/ProcessExitDecision");
|
|
16
|
+
var ProcessExitNormal = class extends Schema.TaggedClass()("ProcessExitNormal", {}) {
|
|
17
|
+
[ProcessExitDecisionTypeId] = ProcessExitDecisionTypeId;
|
|
18
|
+
};
|
|
19
|
+
var ProcessExitAbnormal = class extends Schema.TaggedClass()("ProcessExitAbnormal", {
|
|
20
|
+
code: Schema.Int,
|
|
21
|
+
signal: Schema.String
|
|
22
|
+
}) {
|
|
23
|
+
[ProcessExitDecisionTypeId] = ProcessExitDecisionTypeId;
|
|
24
|
+
};
|
|
25
|
+
const ProcessExitDecision = Schema.Union([ProcessExitNormal, ProcessExitAbnormal]);
|
|
26
|
+
const NORMAL = { _tag: "Normal" };
|
|
27
|
+
const abnormalExitOf = (code, signal) => ({
|
|
28
|
+
_tag: "Abnormal",
|
|
29
|
+
report: {
|
|
30
|
+
_tag: "ExitReport",
|
|
31
|
+
code,
|
|
32
|
+
signal
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const terminationReasonOf = (decision) => Match.value(decision).pipe(Match.tag("ProcessExitNormal", () => NORMAL), Match.tag("ProcessExitAbnormal", (abnormal) => abnormalExitOf(abnormal.code, abnormal.signal)), Match.exhaustive);
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/ProcessMedium/classify-process-exit.workflow.ts
|
|
38
|
+
var ClassifyProcessExit = class extends Schema.TaggedClass()("ClassifyProcessExit", { exit: ProcessExit }) {
|
|
39
|
+
static [Workflow.InstrumentationBrand] = {};
|
|
40
|
+
};
|
|
41
|
+
const SIGNAL_IN_DETAIL = /signal: '([A-Z0-9]+)'/;
|
|
42
|
+
const NO_EXIT_CODE = 0;
|
|
43
|
+
const signalNameIn = (detail) => Option.getOrElse(Option.flatMap(Option.fromNullishOr(SIGNAL_IN_DETAIL.exec(detail)), (found) => Option.fromNullishOr(found[1])), () => "");
|
|
44
|
+
const abnormalOf = (code, signal) => new ProcessExitAbnormal({
|
|
45
|
+
code,
|
|
46
|
+
signal
|
|
47
|
+
});
|
|
48
|
+
const classifyCode = (code) => Match.value(code === 0).pipe(Match.when(true, () => new ProcessExitNormal({})), Match.when(false, () => abnormalOf(code, "")), Match.exhaustive);
|
|
49
|
+
const decideProcessExit = (command) => Result.succeed(Match.value(command.exit).pipe(Match.tag("Exited", (exited) => classifyCode(exited.code)), Match.tag("Signaled", (signaled) => abnormalOf(NO_EXIT_CODE, signalNameIn(signaled.detail))), Match.exhaustive));
|
|
50
|
+
const classifyProcessExit = Workflow.make({
|
|
51
|
+
command: ClassifyProcessExit,
|
|
52
|
+
decision: ProcessExitDecision,
|
|
53
|
+
error: Schema.Never,
|
|
54
|
+
decide: decideProcessExit
|
|
55
|
+
});
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/ProcessMedium/KillSignalDecision.schema.ts
|
|
58
|
+
const KillSignalDecisionTypeId = Symbol.for("@systemfsoftware/effect-daemon-process/KillSignalDecision");
|
|
59
|
+
var BrutalKill = class extends Schema.TaggedClass()("BrutalKill", {}) {
|
|
60
|
+
[KillSignalDecisionTypeId] = KillSignalDecisionTypeId;
|
|
61
|
+
};
|
|
62
|
+
var GracefulKill = class extends Schema.TaggedClass()("GracefulKill", { forceKillAfterMillis: Schema.Int }) {
|
|
63
|
+
[KillSignalDecisionTypeId] = KillSignalDecisionTypeId;
|
|
64
|
+
};
|
|
65
|
+
var PatientKill = class extends Schema.TaggedClass()("PatientKill", {}) {
|
|
66
|
+
[KillSignalDecisionTypeId] = KillSignalDecisionTypeId;
|
|
67
|
+
};
|
|
68
|
+
const KillSignalDecision = Schema.Union([
|
|
69
|
+
BrutalKill,
|
|
70
|
+
GracefulKill,
|
|
71
|
+
PatientKill
|
|
72
|
+
]);
|
|
73
|
+
const killOptionsOf = (decision) => Match.value(decision).pipe(Match.tag("BrutalKill", () => ({ killSignal: "SIGKILL" })), Match.tag("GracefulKill", (graceful) => ({
|
|
74
|
+
killSignal: "SIGTERM",
|
|
75
|
+
forceKillAfter: Duration.millis(graceful.forceKillAfterMillis)
|
|
76
|
+
})), Match.tag("PatientKill", () => ({ killSignal: "SIGTERM" })), Match.exhaustive);
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/ProcessMedium/select-kill-signals.workflow.ts
|
|
79
|
+
var SelectKillSignals = class extends Schema.TaggedClass()("SelectKillSignals", { mode: Supervisor.Medium.ShutdownMode }) {
|
|
80
|
+
static [Workflow.InstrumentationBrand] = {};
|
|
81
|
+
};
|
|
82
|
+
const decideKillSignals = (command) => Result.succeed(Match.value(command.mode).pipe(Match.tag("Brutal", () => new BrutalKill({})), Match.tag("Graceful", (graceful) => new GracefulKill({ forceKillAfterMillis: graceful.millis })), Match.tag("Infinity", () => new PatientKill({})), Match.exhaustive));
|
|
83
|
+
const selectKillSignals = Workflow.make({
|
|
84
|
+
command: SelectKillSignals,
|
|
85
|
+
decision: KillSignalDecision,
|
|
86
|
+
error: Schema.Never,
|
|
87
|
+
decide: decideKillSignals
|
|
88
|
+
});
|
|
89
|
+
//#endregion
|
|
6
90
|
//#region src/ProcessMedium/medium.ts
|
|
7
91
|
/**
|
|
8
92
|
* The `effect-daemon-spec` medium over operating-system child processes (R20, KTD17): a
|
|
@@ -20,22 +104,12 @@ const declaration = {
|
|
|
20
104
|
/** The port a process child is declared against (KTD9): the command spec is the program. */
|
|
21
105
|
const port = Supervisor.Medium.MediumPort("ProcessMedium");
|
|
22
106
|
const ProcessStartedTypeId = Symbol.for("@systemfsoftware/effect-daemon-process/ProcessMedium/Started");
|
|
23
|
-
const NO_EXIT_CODE = 0;
|
|
24
|
-
/** The platform's own wording for a signal death, `Process interrupted due to receipt of signal: 'SIGKILL'`. */
|
|
25
|
-
const SIGNAL_IN_DETAIL = /signal: '([A-Z0-9]+)'/;
|
|
26
|
-
const NORMAL = { _tag: "Normal" };
|
|
27
107
|
const SHUTDOWN = { _tag: "Shutdown" };
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
report: {
|
|
32
|
-
_tag: "ExitReport",
|
|
33
|
-
code,
|
|
34
|
-
signal
|
|
35
|
-
}
|
|
108
|
+
const decisionOf = (result) => Result.match(result, {
|
|
109
|
+
onFailure: (error) => absurd(error),
|
|
110
|
+
onSuccess: (decision) => decision
|
|
36
111
|
});
|
|
37
|
-
const
|
|
38
|
-
const terminationOf = (exit) => Match.value(exit).pipe(Match.tag("Exited", (exited) => exitedOf(exited.code)), Match.tag("Signaled", (signaled) => abnormalExitOf(NO_EXIT_CODE, signalNameIn(signaled.detail))), Match.exhaustive);
|
|
112
|
+
const terminationOf = (exit) => classifyProcessExit(new ClassifyProcessExit({ exit })).pipe(decisionOf, terminationReasonOf);
|
|
39
113
|
const processStartedOf = (handle, ready, stopping) => ({
|
|
40
114
|
[Supervisor.Medium.StartedTypeId]: Supervisor.Medium.StartedTypeId,
|
|
41
115
|
[ProcessStartedTypeId]: ProcessStartedTypeId,
|
|
@@ -49,7 +123,10 @@ const processOf = (evidence) => Option.liftPredicate(evidence, isProcessStarted)
|
|
|
49
123
|
* A signal name reaches the medium only through the failure `exitCode` raises, so the
|
|
50
124
|
* platform's own words are the detail this observation carries.
|
|
51
125
|
*/
|
|
52
|
-
const platformDetailOf = (error) =>
|
|
126
|
+
const platformDetailOf = (error) => Option.match(Schema.decodeUnknownOption(Schema.Struct({ message: Schema.String }))(error.reason.cause), {
|
|
127
|
+
onNone: () => error.message,
|
|
128
|
+
onSome: (cause) => cause.message
|
|
129
|
+
});
|
|
53
130
|
const observationOf = (handle) => Effect.match(handle.exitCode, {
|
|
54
131
|
onSuccess: (code) => ({
|
|
55
132
|
_tag: "Exited",
|
|
@@ -65,18 +142,14 @@ const watchReady = (handle, ready, options) => Option.match(Option.fromNullishOr
|
|
|
65
142
|
onNone: () => Effect.asVoid(Deferred.succeed(ready, void 0)),
|
|
66
143
|
onSome: (line) => Effect.asVoid(Effect.forkScoped(readyLineSeen(handle, line, ready)))
|
|
67
144
|
});
|
|
68
|
-
|
|
69
|
-
const killOptionsOf = (mode) => Match.value(mode).pipe(Match.tag("Brutal", () => ({ killSignal: "SIGKILL" })), Match.tag("Graceful", (graceful) => ({
|
|
70
|
-
killSignal: "SIGTERM",
|
|
71
|
-
forceKillAfter: Duration.millis(graceful.millis)
|
|
72
|
-
})), Match.tag("Infinity", () => ({ killSignal: "SIGTERM" })), Match.exhaustive);
|
|
145
|
+
const killOptionsFor = (mode) => selectKillSignals(new SelectKillSignals({ mode })).pipe(decisionOf, killOptionsOf);
|
|
73
146
|
/**
|
|
74
147
|
* Owned shutdown (R4, R15): the stop latch answers the report as a `Shutdown` before any
|
|
75
148
|
* signal goes out — the ordering the fiber medium gives an interrupted fiber — and the
|
|
76
149
|
* kill's own await is what makes the stop atomic, because the platform's `kill` returns
|
|
77
150
|
* only once the process group has gone.
|
|
78
151
|
*/
|
|
79
|
-
const stopOf = (self, mode) => Effect.andThen(Deferred.succeed(self.stopping, void 0), Effect.ignore(self.handle.kill(
|
|
152
|
+
const stopOf = (self, mode) => Effect.andThen(Deferred.succeed(self.stopping, void 0), Effect.ignore(self.handle.kill(killOptionsFor(mode))));
|
|
80
153
|
const spawnIn = (command, options) => Effect.gen(function* () {
|
|
81
154
|
const handle = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).spawn(command);
|
|
82
155
|
const ready = yield* Deferred.make();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@systemfsoftware/effect-daemon-process",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
"./package.json": "./package.json"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@systemfsoftware/effect-cell-types": "^
|
|
38
|
-
"@systemfsoftware/effect-daemon-conformance": "^0.
|
|
39
|
-
"@systemfsoftware/effect-daemon-spec": "^
|
|
37
|
+
"@systemfsoftware/effect-cell-types": "^12.0.0",
|
|
38
|
+
"@systemfsoftware/effect-daemon-conformance": "^1.0.0",
|
|
39
|
+
"@systemfsoftware/effect-daemon-spec": "^6.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@effect/platform-node-shared": "4
|
|
42
|
+
"@effect/platform-node-shared": "^4",
|
|
43
43
|
"@microsoft/api-extractor": "^7.59.1",
|
|
44
44
|
"@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
|
|
45
|
-
"@systemfsoftware/conformance-spec": "^0.
|
|
46
|
-
"@systemfsoftware/effect-gherkin-spec": "^
|
|
47
|
-
"@systemfsoftware/effect-schema-law": "^
|
|
48
|
-
"@systemfsoftware/effect-schema-vite": "^
|
|
49
|
-
"@systemfsoftware/oxlint-config-recommended": "^
|
|
45
|
+
"@systemfsoftware/conformance-spec": "^1.0.0",
|
|
46
|
+
"@systemfsoftware/effect-gherkin-spec": "^7.0.0",
|
|
47
|
+
"@systemfsoftware/effect-schema-law": "^5.0.0",
|
|
48
|
+
"@systemfsoftware/effect-schema-vite": "^3.0.0",
|
|
49
|
+
"@systemfsoftware/oxlint-config-recommended": "^4.0.0",
|
|
50
50
|
"@systemfsoftware/stryker-config": "^0.1.0",
|
|
51
51
|
"@systemfsoftware/stryker-ignorer-effect-schema-declarations": "latest",
|
|
52
52
|
"@systemfsoftware/stryker-ignorer-in-source-vitest-block": "latest",
|
|
@@ -56,11 +56,10 @@
|
|
|
56
56
|
"@systemfsoftware/stryker-test-contribution": "latest",
|
|
57
57
|
"@systemfsoftware/tsconfig": "^2.0.1",
|
|
58
58
|
"@systemfsoftware/tsdown-config": "^0.1.0",
|
|
59
|
-
"@systemfsoftware/vitest": "^0.
|
|
59
|
+
"@systemfsoftware/vitest": "^1.0.0",
|
|
60
60
|
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
61
61
|
"@types/node": "^26",
|
|
62
|
-
"effect": "4
|
|
63
|
-
"fast-check": "^4",
|
|
62
|
+
"effect": "^4",
|
|
64
63
|
"oxlint": "~1.82.0",
|
|
65
64
|
"rimraf": "^6.1.3",
|
|
66
65
|
"tsdown": "^0.23.0",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"vitest": "^5"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
|
-
"effect": "4
|
|
70
|
+
"effect": "^4",
|
|
72
71
|
"typescript": ">=7.0.0"
|
|
73
72
|
},
|
|
74
73
|
"publishConfig": {
|
|
@@ -80,7 +79,6 @@
|
|
|
80
79
|
"build": "tsdown -l warn && pnpm api:check",
|
|
81
80
|
"typecheck": "tsc -b",
|
|
82
81
|
"test": "vitest run --project unit --project conformance",
|
|
83
|
-
"test:contract": "vitest run --project contract",
|
|
84
82
|
"mutation": "stryker run",
|
|
85
83
|
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
|
|
86
84
|
"attw": "attw --pack .",
|