@mark1russell7/service 0.5.1 → 0.5.2

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 CHANGED
@@ -80,6 +80,7 @@ A process has one service, and one entry that uses `run()`. A component gives pa
80
80
  - **The parts.** A component gives a `TransportImpl` for each source of work, a `DependencyHandle` for each dependency that it owns, and each check with its `CheckFn`. It can also give work for a declared phase (`onPhase`).
81
81
  - **The entry.** The entry declares one service: the parts of each component, the policies, the startup budget, the phases and the cooperative window. Only the entry uses `run()`. Thus the process has one set of signal handlers, one staged shutdown and one exit.
82
82
  - **What a component does not do.** A component does not use `start()` or `run()`. It installs no signal handler, and it does not end the process. A service has one health server, thus the entry chooses it.
83
+ - **An entry in a process that another part owns.** A script, a test of an application or a library entry can start a service in a process that it does not own. It gives `run()` the port `embeddedProcess()`. That port adds no signal handler, it does not hold the process, and its `exit` only records the code. The caller stops the service with `life.shutdown()` and reads the code from `life.done`.
83
84
  - **Names.** A service refuses a second part of one kind with the same name. Thus the entry gives each component a prefix, for example `app.http` and `ingest.http`.
84
85
  - **The sequence.** The lifecycle connects the dependencies of all components in their declared sequence, and then it starts each transport. Each stage of the shutdown acts on the transports of all components together. The dependencies close in the reverse sequence.
85
86
  - **Requests.** The transports start before the startup ends, but `run()` gives the `Lifecycle` only at that end. Thus each transport gets the lifecycle at its start (`start(signal, life)`), and its request tracking operates at once.
@@ -1,5 +1,5 @@
1
1
  import { n as Clock } from "./clock-D-38uH_z.js";
2
- import { B as Gate, D as Outcome, E as CheckFn, F as CooperativeFloor, H as Phase, I as Coupling, J as Poll, L as Dependency, N as Check, R as ExitCodes, T as StartOptions, U as RepeatSignal, V as MessageTrigger, W as ServiceDescription, X as Timing, d as TransportImpl, k as Trace, n as HealthServer, nt as OperationOf, o as PhaseWork, pt as ProcessTrigger, r as Lifecycle, s as RunOptions, st as ExitTrigger, t as DependencyHandle, x as Health, xt as Operation } from "./lifecycle-DtJZW09J.js";
2
+ import { B as Gate, Ct as Operation, D as Outcome, E as CheckFn, F as CooperativeFloor, H as Phase, I as Coupling, J as Poll, L as Dependency, N as Check, R as ExitCodes, T as StartOptions, U as RepeatSignal, V as MessageTrigger, W as ServiceDescription, X as Timing, ct as ExitTrigger, d as TransportImpl, k as Trace, mt as ProcessTrigger, n as HealthServer, nt as OperationOf, o as PhaseWork, r as Lifecycle, s as RunOptions, t as DependencyHandle, x as Health } from "./lifecycle-DjEpgpRk.js";
3
3
  import { Extent, Quantity } from "@mark1russell7/quantity";
4
4
  //#region src/profiles.d.ts
5
5
  /**
@@ -201,4 +201,4 @@ interface ServiceBuilder {
201
201
  declare const service: (name: string) => ServiceBuilder;
202
202
  //#endregion
203
203
  export { WatchdogSpec as a, Profile as c, kubernetes as d, localDev as f, Watchdog as i, daemon as l, ServiceBuilder as n, watchdog as o, service as r, PodTiming as s, ControllerBuilder as t, ephemeral as u };
204
- //# sourceMappingURL=builder-QVxu1WcL.d.ts.map
204
+ //# sourceMappingURL=builder-BzjhWk2E.d.ts.map
package/build/http.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as Clock } from "./clock-D-38uH_z.js";
2
- import { d as TransportImpl, m as RequestEnd, n as HealthServer, r as Lifecycle, v as RequestStream, x as Health, y as RequestWork } from "./lifecycle-DtJZW09J.js";
2
+ import { d as TransportImpl, m as RequestEnd, n as HealthServer, r as Lifecycle, v as RequestStream, x as Health, y as RequestWork } from "./lifecycle-DjEpgpRk.js";
3
3
  import { Extent, Quantity } from "@mark1russell7/quantity";
4
4
  import { ListenOptions } from "node:net";
5
5
  import { IncomingMessage, Server, ServerEventMap, ServerResponse } from "node:http";
package/build/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as backoffDelay, i as backoffBand, n as DelayBand, o as backoffProblems, r as Jitter, t as Backoff } from "./backoff-B-jGWVDm.js";
2
2
  import { a as realClock, i as platformClock, n as Clock, r as PlatformClockOptions, t as Cancel } from "./clock-D-38uH_z.js";
3
3
  import { Heartbeat, HeartbeatOptions, detectionTime, heartbeat } from "./heartbeat.js";
4
- import { $ as failSpan, A as LifecycleEvent, B as Gate, C as ProbeAnswer, D as Outcome, E as CheckFn, F as CooperativeFloor, G as Step, H as Phase, I as Coupling, J as Poll, K as Transport, L as Dependency, M as Recorder, N as Check, O as Result, P as Controller, Q as asWindow, R as ExitCodes, S as HealthVerdict, St as mayReissue, T as StartOptions, U as RepeatSignal, V as MessageTrigger, W as ServiceDescription, X as Timing, Y as Span, Z as asDebounce, _ as RequestOptions, _t as matchesMessage, a as PhaseContext, at as EXIT_SIGNALS, b as CheckVerdict, bt as Idempotency, c as STAGES, ct as HostStream, d as TransportImpl, dt as ProcessHost, et as heartbeatDetection, f as cooperativeAbortAt, ft as ProcessPort, g as RequestFn, gt as isMessageShape, h as RequestEvent, ht as isExitSignal, i as LifecycleState, it as RouteRequest, j as MachineName, l as ShutdownOptions, lt as MessageShape, m as RequestEnd, mt as isExitCode, n as HealthServer, nt as OperationOf, o as PhaseWork, ot as ExitSignal, p as stageRank, pt as ProcessTrigger, q as FailsBy, r as Lifecycle, rt as RoutePattern, s as RunOptions, st as ExitTrigger, t as DependencyHandle, tt as recoverSpan, u as Stage, ut as PROCESS_TRIGGERS, v as RequestStream, vt as nodeProcess, w as ProbeKind, x as Health, xt as Operation, y as RequestWork, yt as processPortOf, z as FORMAT } from "./lifecycle-DtJZW09J.js";
5
- import { a as WatchdogSpec, c as Profile, d as kubernetes, f as localDev, i as Watchdog, l as daemon, n as ServiceBuilder, o as watchdog, r as service, s as PodTiming, t as ControllerBuilder, u as ephemeral } from "./builder-QVxu1WcL.js";
4
+ import { $ as failSpan, A as LifecycleEvent, B as Gate, C as ProbeAnswer, Ct as Operation, D as Outcome, E as CheckFn, F as CooperativeFloor, G as Step, H as Phase, I as Coupling, J as Poll, K as Transport, L as Dependency, M as Recorder, N as Check, O as Result, P as Controller, Q as asWindow, R as ExitCodes, S as HealthVerdict, St as Idempotency, T as StartOptions, U as RepeatSignal, V as MessageTrigger, W as ServiceDescription, X as Timing, Y as Span, Z as asDebounce, _ as RequestOptions, _t as isExitSignal, a as PhaseContext, at as EXIT_SIGNALS, b as CheckVerdict, bt as nodeProcess, c as STAGES, ct as ExitTrigger, d as TransportImpl, dt as PROCESS_TRIGGERS, et as heartbeatDetection, f as cooperativeAbortAt, ft as ProcessHost, g as RequestFn, gt as isExitCode, h as RequestEvent, ht as embeddedProcess, i as LifecycleState, it as RouteRequest, j as MachineName, l as ShutdownOptions, lt as HostStream, m as RequestEnd, mt as ProcessTrigger, n as HealthServer, nt as OperationOf, o as PhaseWork, ot as EmbeddedProcess, p as stageRank, pt as ProcessPort, q as FailsBy, r as Lifecycle, rt as RoutePattern, s as RunOptions, st as ExitSignal, t as DependencyHandle, tt as recoverSpan, u as Stage, ut as MessageShape, v as RequestStream, vt as isMessageShape, w as ProbeKind, wt as mayReissue, x as Health, xt as processPortOf, y as RequestWork, yt as matchesMessage, z as FORMAT } from "./lifecycle-DjEpgpRk.js";
5
+ import { a as WatchdogSpec, c as Profile, d as kubernetes, f as localDev, i as Watchdog, l as daemon, n as ServiceBuilder, o as watchdog, r as service, s as PodTiming, t as ControllerBuilder, u as ephemeral } from "./builder-BzjhWk2E.js";
6
6
  import { Extent, Quantity } from "@mark1russell7/quantity";
7
7
  import { replay } from "@mark1russell7/algebra/replay";
8
8
  import { Machine } from "@mark1russell7/algebra";
@@ -408,5 +408,5 @@ export declare const drainMachine: (description: ServiceDescription) => Machine;
408
408
  /** These are the static machines of the runtime, by the name that their events carry. */
409
409
  export declare const MACHINES: Readonly<Record<Exclude<MachineName, "drain" | "client">, Machine>>;
410
410
  //#endregion
411
- export { type Backoff, type Binding, type Bound, type Cancel, type Check, type CheckFn, type CheckVerdict, type Clock, type Controller, type ControllerBuilder, type CooperativeFloor, type Coupling, type DelayBand, type Dependency, type DependencyHandle, EXIT_SIGNALS, type Evaluated, type ExitCodes, type ExitSignal, type ExitTrigger, FORMAT, type FailsBy, type Finding, type Gate, type Health, type HealthServer, type HealthVerdict, type Heartbeat, type HeartbeatOptions, type HostStream, type Idempotency, type Inequality, type IterationContext, type Jitter, type JobAction, type JobContext, type JobFailure, type JobSettle, type JobSource, type Lifecycle, type LifecycleEvent, type LifecycleState, type MachineName, type MessageShape, type MessageTrigger, type Operation, type OperationOf, type Outcome, PROCESS_TRIGGERS, type Phase, type PhaseContext, type PhaseWork, type PlatformClockOptions, type PodTiming, type Poll, type ProbeAnswer, type ProbeKind, type ProcessHost, type ProcessPort, type ProcessTrigger, type Profile, type QueueDrain, type QueueDrainOptions, type QueueKnobs, type Recorder, type RedeliveryPolicy, type RepeatSignal, type RequestEnd, type RequestEvent, type RequestFn, type RequestOptions, type RequestStream, type RequestWork, type RequeueCause, type Result, type RoutePattern, type RouteRequest, type Rule, type RunOptions, STAGES, type Scenario, type ServiceBuilder, type ServiceDescription, type ShutdownOptions, type Side, type Span, type Stage, type StartOptions, type Step, type Term, type Timing, type Transport, type TransportImpl, type UnitRequest, type Verdict, type Watchdog, type WatchdogSpec, type WorkerKnobs, type WorkerLoop, type WorkerLoopOptions, asDebounce, asWindow, backoffBand, backoffDelay, backoffProblems, cooperativeAbortAt, daemon, detectionTime, ephemeral, failSpan, heartbeat, heartbeatDetection, isExitCode, isExitSignal, isMessageShape, kubernetes, localDev, matchesMessage, mayReissue, nodeProcess, platformClock, processPortOf, realClock, recoverSpan, replay, service, stageRank, watchdog };
411
+ export { type Backoff, type Binding, type Bound, type Cancel, type Check, type CheckFn, type CheckVerdict, type Clock, type Controller, type ControllerBuilder, type CooperativeFloor, type Coupling, type DelayBand, type Dependency, type DependencyHandle, EXIT_SIGNALS, type EmbeddedProcess, type Evaluated, type ExitCodes, type ExitSignal, type ExitTrigger, FORMAT, type FailsBy, type Finding, type Gate, type Health, type HealthServer, type HealthVerdict, type Heartbeat, type HeartbeatOptions, type HostStream, type Idempotency, type Inequality, type IterationContext, type Jitter, type JobAction, type JobContext, type JobFailure, type JobSettle, type JobSource, type Lifecycle, type LifecycleEvent, type LifecycleState, type MachineName, type MessageShape, type MessageTrigger, type Operation, type OperationOf, type Outcome, PROCESS_TRIGGERS, type Phase, type PhaseContext, type PhaseWork, type PlatformClockOptions, type PodTiming, type Poll, type ProbeAnswer, type ProbeKind, type ProcessHost, type ProcessPort, type ProcessTrigger, type Profile, type QueueDrain, type QueueDrainOptions, type QueueKnobs, type Recorder, type RedeliveryPolicy, type RepeatSignal, type RequestEnd, type RequestEvent, type RequestFn, type RequestOptions, type RequestStream, type RequestWork, type RequeueCause, type Result, type RoutePattern, type RouteRequest, type Rule, type RunOptions, STAGES, type Scenario, type ServiceBuilder, type ServiceDescription, type ShutdownOptions, type Side, type Span, type Stage, type StartOptions, type Step, type Term, type Timing, type Transport, type TransportImpl, type UnitRequest, type Verdict, type Watchdog, type WatchdogSpec, type WorkerKnobs, type WorkerLoop, type WorkerLoopOptions, asDebounce, asWindow, backoffBand, backoffDelay, backoffProblems, cooperativeAbortAt, daemon, detectionTime, embeddedProcess, ephemeral, failSpan, heartbeat, heartbeatDetection, isExitCode, isExitSignal, isMessageShape, kubernetes, localDev, matchesMessage, mayReissue, nodeProcess, platformClock, processPortOf, realClock, recoverSpan, replay, service, stageRank, watchdog };
412
412
  //# sourceMappingURL=index.d.ts.map
package/build/index.js CHANGED
@@ -616,6 +616,33 @@ const processPortOf = (find) => {
616
616
  };
617
617
  /** This port is the process of Node. */
618
618
  const nodeProcess = processPortOf(() => globalThis.process);
619
+ /**
620
+ * This function gives a process port for a lifecycle in a process that another part owns. That
621
+ * part is a script, a test of an application, or a library entry. The port adds no handler of a signal or of
622
+ * a trigger, it does not hold the process, and its `exit` only records the code. The caller stops
623
+ * the lifecycle with `life.shutdown()`. A process with a service of its own gives its parts to
624
+ * that service, and does not use this port.
625
+ */
626
+ const embeddedProcess = () => {
627
+ let code = null;
628
+ let resolve = () => {};
629
+ return {
630
+ on() {
631
+ return () => {};
632
+ },
633
+ exit(requested) {
634
+ if (code !== null) return;
635
+ code = requested;
636
+ resolve(requested);
637
+ },
638
+ get exitCode() {
639
+ return code;
640
+ },
641
+ exited: new Promise((done) => {
642
+ resolve = done;
643
+ })
644
+ };
645
+ };
619
646
  //#endregion
620
647
  //#region src/routes.ts
621
648
  const NAME = /^[A-Za-z_][A-Za-z0-9_]*/;
@@ -3225,6 +3252,6 @@ const MACHINES = {
3225
3252
  watchdog: WATCHDOG_MACHINE
3226
3253
  };
3227
3254
  //#endregion
3228
- export { DECLARATION_RULE, EXIT_MACHINE, EXIT_SIGNALS, FORMAT, GATE_MACHINE, LATCH_MACHINE, MACHINES, POLLER_MACHINE, PROCESS_TRIGGERS, SERVICE_RULES, STAGES, WATCHDOG_MACHINE, WINDOW_MACHINE, asDebounce, asWindow, backoffBand, backoffDelay, backoffProblems, capKnob, cooperativeAbortAt, daemon, detectionTime, drainMachine, ephemeral, evaluate, failSpan, heartbeat, heartbeatDetection, inequalities, isExitCode, isExitSignal, isMessageShape, kubernetes, lint, localDev, matchesMessage, mayReissue, nodeProcess, platformClock, processPortOf, queueDrain, realClock, recoverSpan, redeliverOnce, replay, service, serviceBindings, stageRank, symbolsOf, verdictOf, watchdog, workerLoop };
3255
+ export { DECLARATION_RULE, EXIT_MACHINE, EXIT_SIGNALS, FORMAT, GATE_MACHINE, LATCH_MACHINE, MACHINES, POLLER_MACHINE, PROCESS_TRIGGERS, SERVICE_RULES, STAGES, WATCHDOG_MACHINE, WINDOW_MACHINE, asDebounce, asWindow, backoffBand, backoffDelay, backoffProblems, capKnob, cooperativeAbortAt, daemon, detectionTime, drainMachine, embeddedProcess, ephemeral, evaluate, failSpan, heartbeat, heartbeatDetection, inequalities, isExitCode, isExitSignal, isMessageShape, kubernetes, lint, localDev, matchesMessage, mayReissue, nodeProcess, platformClock, processPortOf, queueDrain, realClock, recoverSpan, redeliverOnce, replay, service, serviceBindings, stageRank, symbolsOf, verdictOf, watchdog, workerLoop };
3229
3256
 
3230
3257
  //# sourceMappingURL=index.js.map