@systemfsoftware/effect-daemon-spec 5.1.0 → 6.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @systemfsoftware/effect-daemon-spec
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - The supervisor now closes each child incarnation's scope after the medium's `stop` returns, including when `stop` fails. A medium's `stop` no longer closes the scope its `start` ran in; effect 4.0.0's `Scope.close` accepts only `Scope.Closeable`, which the ambient `Scope` is not.
8
+
9
+ - 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.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies:
14
+ - @systemfsoftware/conformance-spec@1.0.0
15
+ - @systemfsoftware/effect-cell-types@12.0.0
16
+
3
17
  ## 5.1.0
4
18
 
5
19
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -1231,22 +1231,15 @@ declare const SupervisionEvent: Schema.Union<readonly [Schema.TaggedStruct<"Supe
1231
1231
  type SupervisionEvent = typeof SupervisionEvent.Type;
1232
1232
  //#endregion
1233
1233
  //#region src/Supervisor/bound-child.d.ts
1234
- /**
1235
- * A child bound to the medium that interprets its program, and to the services
1236
- * that medium needs (KTD9, R15, R17, R18). Every operation already runs in the
1237
- * context the supervisor acquired, so the handle stores one bound child per
1238
- * declared and dynamic child, and the executor never names a medium.
1239
- */
1234
+ interface Incarnation {
1235
+ readonly evidence: Started;
1236
+ readonly scope: Scope.Closeable;
1237
+ }
1240
1238
  interface BoundChild {
1241
- /**
1242
- * Starts one incarnation in a fresh child scope. A medium whose `start` fails
1243
- * produces an abnormal `TerminationReason` instead of a failure, so nothing
1244
- * downstream claims the child started (R15, KTD8).
1245
- */
1246
- readonly start: Effect.Effect<Started, TerminationReason, Scope.Scope>;
1247
- readonly report: (evidence: Started) => Effect.Effect<TerminationReason, never, never>;
1248
- readonly probe: (evidence: Started) => Effect.Effect<boolean, never, never>;
1249
- readonly stop: (evidence: Started, mode: ShutdownMode) => Effect.Effect<Stopped, never, never>;
1239
+ readonly start: Effect.Effect<Incarnation, TerminationReason, Scope.Scope>;
1240
+ readonly report: (incarnation: Incarnation) => Effect.Effect<TerminationReason, never, never>;
1241
+ readonly probe: (incarnation: Incarnation) => Effect.Effect<boolean, never, never>;
1242
+ readonly stop: (incarnation: Incarnation, mode: ShutdownMode) => Effect.Effect<Stopped, never, never>;
1250
1243
  }
1251
1244
  //#endregion
1252
1245
  //#region src/Supervisor/DynamicOutcome.schema.d.ts
@@ -1309,7 +1302,7 @@ interface SupervisorSlot {
1309
1302
  readonly state: Ref.Ref<SupervisorState>;
1310
1303
  readonly mailbox: Queue.Queue<SupervisionEvent>;
1311
1304
  readonly trace: PubSub.PubSub<TraceEntry>;
1312
- readonly evidence: Ref.Ref<HashMap.HashMap<string, Started>>;
1305
+ readonly evidence: Ref.Ref<HashMap.HashMap<string, Incarnation>>;
1313
1306
  readonly replies: Ref.Ref<HashMap.HashMap<string, Deferred.Deferred<DynamicOutcome>>>;
1314
1307
  readonly boundChildren: Ref.Ref<HashMap.HashMap<ChildId, BoundChild>>;
1315
1308
  readonly pending: Ref.Ref<HashMap.HashMap<string, BoundChild>>;
package/dist/index.mjs CHANGED
@@ -350,12 +350,11 @@ var FiberMedium_exports = /* @__PURE__ */ __exportAll({
350
350
  const readyOnStart = (program) => (ready) => Effect.andThen(ready, program);
351
351
  const fiberPort = MediumPort("FiberMedium");
352
352
  const FiberStartedTypeId = Symbol.for("@systemfsoftware/effect-daemon-spec/FiberMedium/Started");
353
- const fiberStarted = (fiber, scope, ready) => ({
353
+ const fiberStarted = (fiber, ready) => ({
354
354
  [StartedTypeId]: StartedTypeId,
355
355
  [FiberStartedTypeId]: FiberStartedTypeId,
356
356
  fiber,
357
- ready,
358
- scope
357
+ ready
359
358
  });
360
359
  const isFiberStarted = (evidence) => FiberStartedTypeId in evidence;
361
360
  const fiberOf = (evidence) => Option.liftPredicate(evidence, isFiberStarted);
@@ -371,15 +370,9 @@ const terminationOf$1 = (exit) => terminationReasonOf({
371
370
  decision: decisionOf(exit),
372
371
  exit
373
372
  });
374
- const closedChild = (self) => Scope.close(self.scope, Exit.void);
375
373
  const forcedChild = (self) => Fiber.interrupt(self.fiber);
376
- /**
377
- * OTP's timed shutdown: the signal (interruption) goes out at once, and the window
378
- * bounds only how long the stop waits for the child's finalizers before closing its
379
- * scope.
380
- */
381
- const signalledWithin = (self, millis) => Effect.andThen(Effect.timeoutOption(forcedChild(self), Duration.millis(millis)), closedChild(self));
382
- const stopOf = (self, mode) => Match.value(mode).pipe(Match.tag("Brutal", () => Effect.andThen(forcedChild(self), closedChild(self))), Match.tag("Graceful", (graceful) => signalledWithin(self, graceful.millis)), Match.tag("Infinity", () => Effect.andThen(forcedChild(self), closedChild(self))), Match.exhaustive);
374
+ const signalledWithin = (self, millis) => Effect.asVoid(Effect.timeoutOption(forcedChild(self), Duration.millis(millis)));
375
+ const stopOf = (self, mode) => Match.value(mode).pipe(Match.tag("Brutal", () => forcedChild(self)), Match.tag("Graceful", (graceful) => signalledWithin(self, graceful.millis)), Match.tag("Infinity", () => forcedChild(self)), Match.exhaustive);
383
376
  const failureCauseOf = (evidence) => Option.map(fiberOf(evidence), (self) => Effect.map(Fiber.await(self.fiber), Exit.getCause));
384
377
  const mediumFor = () => make$1({
385
378
  declaration: {
@@ -390,7 +383,7 @@ const mediumFor = () => make$1({
390
383
  const scope = yield* Effect.scope;
391
384
  const signalled = yield* Deferred.make();
392
385
  const fiber = yield* Effect.forkIn(program(Deferred.succeed(signalled, void 0)), scope);
393
- return fiberStarted(fiber, scope, Deferred.await(signalled));
386
+ return fiberStarted(fiber, Deferred.await(signalled));
394
387
  }),
395
388
  report: (evidence) => Option.match(fiberOf(evidence), {
396
389
  onNone: () => Effect.succeed(shutdownTermination),
@@ -415,22 +408,19 @@ const startOf = (program, medium, context) => Effect.gen(function* () {
415
408
  const scoped = Context.add(context, Scope.Scope, child);
416
409
  const outcome = yield* Effect.exit(Effect.setContext(Effect.mapError(medium.start(program), rendered), scoped));
417
410
  return yield* Exit.match(outcome, {
418
- onSuccess: (evidence) => Effect.succeed(evidence),
411
+ onSuccess: (evidence) => Effect.succeed({
412
+ evidence,
413
+ scope: child
414
+ }),
419
415
  onFailure: (cause) => Effect.andThen(Scope.close(child, Exit.void), Effect.fail(terminationReasonOfCause(cause)))
420
416
  });
421
417
  });
422
418
  const bind = (program, medium, context) => ({
423
419
  start: startOf(program, medium, context),
424
- report: (evidence) => Effect.setContext(medium.report(evidence), context),
425
- probe: (evidence) => Effect.setContext(medium.probe(evidence), context),
426
- stop: (evidence, mode) => Effect.setContext(medium.stop(evidence, mode), context)
420
+ report: (incarnation) => Effect.setContext(medium.report(incarnation.evidence), context),
421
+ probe: (incarnation) => Effect.setContext(medium.probe(incarnation.evidence), context),
422
+ stop: (incarnation, mode) => Effect.ensuring(Effect.setContext(medium.stop(incarnation.evidence, mode), context), Scope.close(incarnation.scope, Exit.void))
427
423
  });
428
- /**
429
- * Binds a program to the medium that interprets it, capturing the services
430
- * resolved at acquisition: the medium's own requirements are read from
431
- * `context` once, and `start` forks a fresh child scope so closing that scope
432
- * owns the child's shutdown (KTD9).
433
- */
434
424
  const Binder = { bind };
435
425
  //#endregion
436
426
  //#region src/Supervisor/DynamicOutcome.schema.ts
@@ -834,10 +824,10 @@ const supervisorTimerEventOf = (kind) => ({
834
824
  target: { _tag: "SupervisorTimer" }
835
825
  });
836
826
  const evidenceKeyOf = (childId, generation) => `${childId}#${generation}`;
837
- const registerStarted = (handle, childId, generation, evidence) => Ref.update(evidenceOf(handle), (known) => HashMap.set(known, evidenceKeyOf(childId, generation), evidence));
827
+ const registerStarted = (handle, childId, generation, incarnation) => Ref.update(evidenceOf(handle), (known) => HashMap.set(known, evidenceKeyOf(childId, generation), incarnation));
838
828
  const knownStarted = (handle, childId, generation) => Effect.map(Ref.get(evidenceOf(handle)), (known) => HashMap.get(known, evidenceKeyOf(childId, generation)));
839
829
  const watchReadiness = (handle, evidence, childId, generation) => Effect.asVoid(Effect.forkIn(Effect.asVoid(Effect.andThen(evidence.ready, stampedNow(handle, readyEventOf(childId, generation)))), ownerScopeOf(handle)));
840
- const watchReport = (handle, child, evidence, childId, generation) => Effect.asVoid(Effect.forkIn(Effect.flatMap(child.report(evidence), (reason) => stampedNow(handle, terminatedEventOf(childId, generation, reason))), ownerScopeOf(handle)));
830
+ const watchReport = (handle, child, incarnation, childId, generation) => Effect.asVoid(Effect.forkIn(Effect.flatMap(child.report(incarnation), (reason) => stampedNow(handle, terminatedEventOf(childId, generation, reason))), ownerScopeOf(handle)));
841
831
  /**
842
832
  * The child bound to an id. Declared children are bound at acquisition and dynamic
843
833
  * ones by `bindDynamicPrograms` before their start runs, so a missing binding is a
@@ -848,7 +838,7 @@ const executeStart = (acquired, command) => Effect.gen(function* () {
848
838
  const child = yield* boundChildFor(acquired.handle, command.childId);
849
839
  const outcome = yield* Effect.exit(child.start);
850
840
  yield* Exit.match(outcome, {
851
- onSuccess: (evidence) => Effect.andThen(registerStarted(acquired.handle, command.childId, command.generation, evidence), Effect.andThen(stampedNow(acquired.handle, startedEventOf(command.childId, command.generation)), Effect.andThen(watchReadiness(acquired.handle, evidence, command.childId, command.generation), watchReport(acquired.handle, child, evidence, command.childId, command.generation)))),
841
+ onSuccess: (incarnation) => Effect.andThen(registerStarted(acquired.handle, command.childId, command.generation, incarnation), Effect.andThen(stampedNow(acquired.handle, startedEventOf(command.childId, command.generation)), Effect.andThen(watchReadiness(acquired.handle, incarnation.evidence, command.childId, command.generation), watchReport(acquired.handle, child, incarnation, command.childId, command.generation)))),
852
842
  onFailure: (cause) => stampedNow(acquired.handle, terminatedEventOf(command.childId, command.generation, terminationReasonOfCause(cause)))
853
843
  });
854
844
  });
@@ -862,7 +852,7 @@ const executeStop = (acquired, command) => Effect.gen(function* () {
862
852
  const found = yield* knownStarted(acquired.handle, command.childId, command.generation);
863
853
  yield* Option.match(found, {
864
854
  onNone: () => Effect.void,
865
- onSome: (evidence) => Effect.asVoid(child.stop(evidence, command.shutdown))
855
+ onSome: (incarnation) => Effect.asVoid(child.stop(incarnation, command.shutdown))
866
856
  });
867
857
  yield* stampedNow(acquired.handle, stoppedEventOf(command.childId, command.generation));
868
858
  });
@@ -871,7 +861,7 @@ const executeArm = (acquired, arm) => Match.value(arm).pipe(Match.tag("ArmChildT
871
861
  const executeReply = (acquired, reply) => Ops.resolveWaiting(repliesOf(acquired.handle), reply.requestId, outcomeOf(reply));
872
862
  const giveUpCauseOf = (handle, exit, reason) => Effect.flatMap(Ref.get(evidenceOf(handle)), (evidence) => Option.match(HashMap.get(evidence, evidenceKeyOf(exit.childId, exit.generation)), {
873
863
  onNone: () => Effect.succeed(Cause.fail(reason)),
874
- onSome: (started) => Option.match(failureCauseOf(started), {
864
+ onSome: (incarnation) => Option.match(failureCauseOf(incarnation.evidence), {
875
865
  onNone: () => Effect.succeed(Cause.fail(reason)),
876
866
  onSome: (awaited) => Effect.map(awaited, (cause) => Option.getOrElse(cause, () => Cause.fail(reason)))
877
867
  })
@@ -904,7 +894,7 @@ const probeOnce = (acquired, childId, generation) => Effect.gen(function* () {
904
894
  const found = yield* knownStarted(acquired.handle, childId, generation);
905
895
  const alive = yield* Option.match(found, {
906
896
  onNone: () => Effect.succeed(false),
907
- onSome: (evidence) => child.probe(evidence)
897
+ onSome: (incarnation) => child.probe(incarnation)
908
898
  });
909
899
  yield* stampedNow(acquired.handle, probeEventOf(childId, generation, alive));
910
900
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@systemfsoftware/effect-daemon-spec",
3
3
  "license": "Apache-2.0",
4
- "version": "5.1.0",
4
+ "version": "6.0.0",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -37,17 +37,17 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@systemfsoftware/effect-cell-types": "^11.0.0"
40
+ "@systemfsoftware/effect-cell-types": "^12.0.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.59.1",
44
44
  "@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
45
- "@systemfsoftware/conformance-spec": "^0.2.0",
46
- "@systemfsoftware/effect-gherkin-spec": "^6.0.1",
47
- "@systemfsoftware/effect-schema-law": "^4.0.1",
48
- "@systemfsoftware/effect-schema-vite": "^2.3.0",
49
- "@systemfsoftware/effect-spec-runtime": "^0.3.2",
50
- "@systemfsoftware/oxlint-config-recommended": "^3.3.0",
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/effect-spec-runtime": "^1.0.0",
50
+ "@systemfsoftware/oxlint-config-recommended": "^4.0.0",
51
51
  "@systemfsoftware/stryker-config": "^0.1.0",
52
52
  "@systemfsoftware/stryker-ignorer-effect-schema-declarations": "latest",
53
53
  "@systemfsoftware/stryker-ignorer-in-source-vitest-block": "latest",
@@ -57,11 +57,11 @@
57
57
  "@systemfsoftware/stryker-test-contribution": "latest",
58
58
  "@systemfsoftware/tsconfig": "^2.0.1",
59
59
  "@systemfsoftware/tsdown-config": "^0.1.0",
60
- "@systemfsoftware/vitest": "^0.3.0",
60
+ "@systemfsoftware/vitest": "^1.0.0",
61
61
  "@systemfsoftware/vitest-config": "^0.1.0",
62
62
  "@types/node": "^26",
63
63
  "@vitest/coverage-v8": "^5",
64
- "effect": "4.0.0-rc.117",
64
+ "effect": "^4",
65
65
  "fast-check": "^4",
66
66
  "oxlint": "~1.82.0",
67
67
  "rimraf": "^6.1.3",
@@ -71,8 +71,8 @@
71
71
  "vitest": "^5"
72
72
  },
73
73
  "peerDependencies": {
74
- "@systemfsoftware/conformance-spec": "^0.2.0",
75
- "effect": "4.0.0-rc.117"
74
+ "@systemfsoftware/conformance-spec": "^1.0.0",
75
+ "effect": "^4"
76
76
  },
77
77
  "peerDependenciesMeta": {
78
78
  "@systemfsoftware/conformance-spec": {