@mark1russell7/service 0.8.19 → 0.8.20

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.
Files changed (331) hide show
  1. package/build/backoff.d.ts +44 -2
  2. package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
  3. package/build/builder.js +499 -0
  4. package/build/builder.js.map +1 -0
  5. package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
  6. package/build/channel.d.ts +1 -1
  7. package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
  8. package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
  9. package/build/client/core.js.map +1 -0
  10. package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
  11. package/build/client/dial.js +52 -0
  12. package/build/client/dial.js.map +1 -0
  13. package/build/client/machine.js +29 -0
  14. package/build/client/machine.js.map +1 -0
  15. package/build/client/meets.d.ts +35 -0
  16. package/build/client/meets.js +78 -0
  17. package/build/client/meets.js.map +1 -0
  18. package/build/clock.d.ts +1 -1
  19. package/build/conformance.d.ts +122 -0
  20. package/build/conformance.js +470 -0
  21. package/build/conformance.js.map +1 -0
  22. package/build/contract.d.ts +28 -0
  23. package/build/contract.js +184 -0
  24. package/build/contract.js.map +1 -0
  25. package/build/description.d.ts +161 -0
  26. package/build/description.js +11 -0
  27. package/build/description.js.map +1 -0
  28. package/build/drains.js +35 -0
  29. package/build/drains.js.map +1 -0
  30. package/build/events.d.ts +25 -0
  31. package/build/fakes.d.ts +43 -0
  32. package/build/fakes.js +93 -0
  33. package/build/fakes.js.map +1 -0
  34. package/build/grpc/client.d.ts +153 -0
  35. package/build/grpc/client.js +474 -0
  36. package/build/grpc/client.js.map +1 -0
  37. package/build/grpc/connection.d.ts +97 -0
  38. package/build/grpc/connection.js +59 -0
  39. package/build/grpc/connection.js.map +1 -0
  40. package/build/grpc/machine.d.ts +12 -0
  41. package/build/grpc/machine.js +149 -0
  42. package/build/grpc/machine.js.map +1 -0
  43. package/build/grpc/meets.d.ts +14 -0
  44. package/build/grpc/meets.js +105 -0
  45. package/build/grpc/meets.js.map +1 -0
  46. package/build/grpc/starting.d.ts +33 -0
  47. package/build/grpc/starting.js +89 -0
  48. package/build/grpc/starting.js.map +1 -0
  49. package/build/grpc.d.ts +9 -303
  50. package/build/grpc.js +7 -854
  51. package/build/health.d.ts +93 -0
  52. package/build/health.js +223 -0
  53. package/build/health.js.map +1 -0
  54. package/build/heartbeat.d.ts +1 -1
  55. package/build/host/discovery.d.ts +61 -0
  56. package/build/host/discovery.js +113 -0
  57. package/build/host/discovery.js.map +1 -0
  58. package/build/host/env.d.ts +14 -0
  59. package/build/host/env.js +57 -0
  60. package/build/host/env.js.map +1 -0
  61. package/build/host/fakes.d.ts +82 -0
  62. package/build/host/fakes.js +239 -0
  63. package/build/host/fakes.js.map +1 -0
  64. package/build/host/group.d.ts +142 -0
  65. package/build/host/group.js +517 -0
  66. package/build/host/group.js.map +1 -0
  67. package/build/host/install.d.ts +96 -0
  68. package/build/host/install.js +330 -0
  69. package/build/host/install.js.map +1 -0
  70. package/build/host/lock.d.ts +78 -0
  71. package/build/host/lock.js +190 -0
  72. package/build/host/lock.js.map +1 -0
  73. package/build/host/logs.d.ts +26 -0
  74. package/build/host/logs.js +48 -0
  75. package/build/host/logs.js.map +1 -0
  76. package/build/host/node.d.ts +14 -0
  77. package/build/host/node.js +309 -0
  78. package/build/host/node.js.map +1 -0
  79. package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
  80. package/build/host/ports.js +17 -0
  81. package/build/host/ports.js.map +1 -0
  82. package/build/host/probes.d.ts +51 -0
  83. package/build/host/probes.js +139 -0
  84. package/build/host/probes.js.map +1 -0
  85. package/build/host/processes.d.ts +32 -0
  86. package/build/host/processes.js +63 -0
  87. package/build/host/processes.js.map +1 -0
  88. package/build/host/render.d.ts +84 -0
  89. package/build/host/render.js +235 -0
  90. package/build/host/render.js.map +1 -0
  91. package/build/host/watch.d.ts +90 -0
  92. package/build/host/watch.js +165 -0
  93. package/build/host/watch.js.map +1 -0
  94. package/build/host.d.ts +13 -671
  95. package/build/host.js +12 -2126
  96. package/build/http/answers.js +29 -0
  97. package/build/http/answers.js.map +1 -0
  98. package/build/http/fake-server.js +61 -0
  99. package/build/http/fake-server.js.map +1 -0
  100. package/build/http/outcome.d.ts +115 -0
  101. package/build/http/outcome.js +325 -0
  102. package/build/http/outcome.js.map +1 -0
  103. package/build/http/probes.d.ts +83 -0
  104. package/build/http/probes.js +232 -0
  105. package/build/http/probes.js.map +1 -0
  106. package/build/http/transport.d.ts +165 -0
  107. package/build/http/transport.js +517 -0
  108. package/build/http/transport.js.map +1 -0
  109. package/build/http-client/client.d.ts +121 -0
  110. package/build/http-client/client.js +330 -0
  111. package/build/http-client/client.js.map +1 -0
  112. package/build/http-client/connection.d.ts +78 -0
  113. package/build/http-client/connection.js +54 -0
  114. package/build/http-client/connection.js.map +1 -0
  115. package/build/http-client/machine.d.ts +14 -0
  116. package/build/http-client/machine.js +109 -0
  117. package/build/http-client/machine.js.map +1 -0
  118. package/build/http-client/meets.d.ts +11 -0
  119. package/build/http-client/meets.js +74 -0
  120. package/build/http-client/meets.js.map +1 -0
  121. package/build/http-client/session.d.ts +87 -0
  122. package/build/http-client/session.js +99 -0
  123. package/build/http-client/session.js.map +1 -0
  124. package/build/http-client/starting.d.ts +25 -0
  125. package/build/http-client/starting.js +65 -0
  126. package/build/http-client/starting.js.map +1 -0
  127. package/build/http-client.d.ts +9 -330
  128. package/build/http-client.js +8 -707
  129. package/build/http.d.ts +5 -353
  130. package/build/http.js +3 -1086
  131. package/build/identity.d.ts +16 -0
  132. package/build/identity.js +44 -0
  133. package/build/identity.js.map +1 -0
  134. package/build/index.d.ts +35 -412
  135. package/build/index.js +24 -3277
  136. package/build/knobs.d.ts +1 -0
  137. package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
  138. package/build/knobs.js.map +1 -0
  139. package/build/latch.d.ts +29 -0
  140. package/build/latch.js +122 -0
  141. package/build/latch.js.map +1 -0
  142. package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
  143. package/build/law.js +149 -0
  144. package/build/law.js.map +1 -0
  145. package/build/lifecycle.d.ts +144 -0
  146. package/build/lifecycle.js +411 -0
  147. package/build/lifecycle.js.map +1 -0
  148. package/build/limiter/machine.d.ts +40 -0
  149. package/build/limiter/machine.js +279 -0
  150. package/build/limiter/machine.js.map +1 -0
  151. package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
  152. package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
  153. package/build/limiter/policy.js.map +1 -0
  154. package/build/{limiter-BNKnwzeY.d.ts → limiter/quota.d.ts} +32 -74
  155. package/build/{limiter-DrM0PQV9.js → limiter/quota.js} +3 -418
  156. package/build/limiter/quota.js.map +1 -0
  157. package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
  158. package/build/limiter/store.js +145 -0
  159. package/build/limiter/store.js.map +1 -0
  160. package/build/limiter.d.ts +4 -3
  161. package/build/limiter.js +4 -2
  162. package/build/lint.d.ts +152 -0
  163. package/build/lint.js +576 -0
  164. package/build/lint.js.map +1 -0
  165. package/build/logger.d.ts +71 -0
  166. package/build/logger.js +183 -0
  167. package/build/logger.js.map +1 -0
  168. package/build/machines.d.ts +41 -0
  169. package/build/machines.js +451 -0
  170. package/build/machines.js.map +1 -0
  171. package/build/metrics.d.ts +53 -0
  172. package/build/metrics.js +111 -0
  173. package/build/metrics.js.map +1 -0
  174. package/build/mongodb/client.d.ts +131 -0
  175. package/build/mongodb/client.js +388 -0
  176. package/build/mongodb/client.js.map +1 -0
  177. package/build/mongodb/connection.d.ts +112 -0
  178. package/build/mongodb/connection.js +12 -0
  179. package/build/mongodb/connection.js.map +1 -0
  180. package/build/mongodb/machine.d.ts +14 -0
  181. package/build/mongodb/machine.js +122 -0
  182. package/build/mongodb/machine.js.map +1 -0
  183. package/build/mongodb/meets.d.ts +15 -0
  184. package/build/mongodb/meets.js +103 -0
  185. package/build/mongodb/meets.js.map +1 -0
  186. package/build/mongodb/starting.d.ts +29 -0
  187. package/build/mongodb/starting.js +77 -0
  188. package/build/mongodb/starting.js.map +1 -0
  189. package/build/mongodb.d.ts +8 -296
  190. package/build/mongodb.js +7 -682
  191. package/build/operation.d.ts +27 -0
  192. package/build/{operation-DF73RZOI.js → operation.js} +2 -2
  193. package/build/operation.js.map +1 -0
  194. package/build/otel.d.ts +2 -2
  195. package/build/pg/client.d.ts +96 -0
  196. package/build/pg/client.js +277 -0
  197. package/build/pg/client.js.map +1 -0
  198. package/build/pg/connection.d.ts +75 -0
  199. package/build/pg/connection.js +11 -0
  200. package/build/pg/connection.js.map +1 -0
  201. package/build/pg/machine.d.ts +13 -0
  202. package/build/pg/machine.js +111 -0
  203. package/build/pg/machine.js.map +1 -0
  204. package/build/pg/meets.d.ts +14 -0
  205. package/build/pg/meets.js +83 -0
  206. package/build/pg/meets.js.map +1 -0
  207. package/build/pg/starting.d.ts +26 -0
  208. package/build/pg/starting.js +62 -0
  209. package/build/pg/starting.js.map +1 -0
  210. package/build/pg.d.ts +8 -219
  211. package/build/pg.js +7 -525
  212. package/build/poller.d.ts +9 -0
  213. package/build/poller.js +152 -0
  214. package/build/poller.js.map +1 -0
  215. package/build/process.d.ts +114 -0
  216. package/build/process.js +170 -0
  217. package/build/process.js.map +1 -0
  218. package/build/profiles.d.ts +68 -0
  219. package/build/profiles.js +120 -0
  220. package/build/profiles.js.map +1 -0
  221. package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
  222. package/build/queue.js +279 -0
  223. package/build/queue.js.map +1 -0
  224. package/build/rabbitmq/client.d.ts +144 -0
  225. package/build/rabbitmq/client.js +426 -0
  226. package/build/rabbitmq/client.js.map +1 -0
  227. package/build/rabbitmq/connection.d.ts +91 -0
  228. package/build/rabbitmq/connection.js +15 -0
  229. package/build/rabbitmq/connection.js.map +1 -0
  230. package/build/rabbitmq/machine.d.ts +13 -0
  231. package/build/rabbitmq/machine.js +159 -0
  232. package/build/rabbitmq/machine.js.map +1 -0
  233. package/build/rabbitmq/meets.d.ts +12 -0
  234. package/build/rabbitmq/meets.js +96 -0
  235. package/build/rabbitmq/meets.js.map +1 -0
  236. package/build/rabbitmq/starting.d.ts +27 -0
  237. package/build/rabbitmq/starting.js +67 -0
  238. package/build/rabbitmq/starting.js.map +1 -0
  239. package/build/rabbitmq.d.ts +8 -283
  240. package/build/rabbitmq.js +7 -742
  241. package/build/redis/client.d.ts +86 -0
  242. package/build/redis/client.js +285 -0
  243. package/build/redis/client.js.map +1 -0
  244. package/build/redis/connection.d.ts +57 -0
  245. package/build/redis/connection.js +11 -0
  246. package/build/redis/connection.js.map +1 -0
  247. package/build/redis/limiter.d.ts +43 -0
  248. package/build/redis/limiter.js +164 -0
  249. package/build/redis/limiter.js.map +1 -0
  250. package/build/redis/machine.d.ts +12 -0
  251. package/build/redis/machine.js +144 -0
  252. package/build/redis/machine.js.map +1 -0
  253. package/build/redis/meets.d.ts +11 -0
  254. package/build/redis/meets.js +75 -0
  255. package/build/redis/meets.js.map +1 -0
  256. package/build/redis/operations.d.ts +5 -0
  257. package/build/redis/operations.js +114 -0
  258. package/build/redis/operations.js.map +1 -0
  259. package/build/redis.d.ts +10 -207
  260. package/build/redis.js +9 -771
  261. package/build/requests.d.ts +66 -0
  262. package/build/requests.js +279 -0
  263. package/build/requests.js.map +1 -0
  264. package/build/retrier.d.ts +62 -0
  265. package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
  266. package/build/retrier.js.map +1 -0
  267. package/build/routes.d.ts +35 -0
  268. package/build/routes.js +77 -0
  269. package/build/routes.js.map +1 -0
  270. package/build/rules.d.ts +19 -2
  271. package/build/stops.d.ts +51 -0
  272. package/build/stops.js +86 -0
  273. package/build/stops.js.map +1 -0
  274. package/build/testing.d.ts +8 -270
  275. package/build/testing.js +4 -1027
  276. package/build/testing.js.map +1 -1
  277. package/build/timing.d.ts +63 -0
  278. package/build/{timing-DZl36uXs.js → timing.js} +2 -2
  279. package/build/timing.js.map +1 -0
  280. package/build/units.d.ts +17 -0
  281. package/build/units.js +236 -0
  282. package/build/units.js.map +1 -0
  283. package/build/watchdog.d.ts +34 -0
  284. package/build/watchdog.js +53 -0
  285. package/build/watchdog.js.map +1 -0
  286. package/build/websocket/client.d.ts +136 -0
  287. package/build/websocket/client.js +422 -0
  288. package/build/websocket/client.js.map +1 -0
  289. package/build/websocket/connection.d.ts +83 -0
  290. package/build/websocket/connection.js +57 -0
  291. package/build/websocket/connection.js.map +1 -0
  292. package/build/websocket/machine.d.ts +12 -0
  293. package/build/websocket/machine.js +155 -0
  294. package/build/websocket/machine.js.map +1 -0
  295. package/build/websocket/meets.d.ts +14 -0
  296. package/build/websocket/meets.js +92 -0
  297. package/build/websocket/meets.js.map +1 -0
  298. package/build/websocket/starting.d.ts +25 -0
  299. package/build/websocket/starting.js +69 -0
  300. package/build/websocket/starting.js.map +1 -0
  301. package/build/websocket.d.ts +9 -264
  302. package/build/websocket.js +8 -774
  303. package/build/worker.d.ts +92 -0
  304. package/build/worker.js +153 -0
  305. package/build/worker.js.map +1 -0
  306. package/package.json +4 -3
  307. package/build/backoff-QTRGfkEK.d.ts +0 -45
  308. package/build/clock-DpVgpY4h.d.ts +0 -2
  309. package/build/grpc.js.map +0 -1
  310. package/build/host.js.map +0 -1
  311. package/build/http-client.js.map +0 -1
  312. package/build/http.js.map +0 -1
  313. package/build/index.js.map +0 -1
  314. package/build/knobs-BJcz6m01.js.map +0 -1
  315. package/build/lifecycle-D0J-zwZF.d.ts +0 -374
  316. package/build/limiter-DrM0PQV9.js.map +0 -1
  317. package/build/logger-B6drv9w0.d.ts +0 -488
  318. package/build/machine-BhVeHr_m.js.map +0 -1
  319. package/build/mongodb.js.map +0 -1
  320. package/build/operation-DF73RZOI.js.map +0 -1
  321. package/build/pg.js.map +0 -1
  322. package/build/policy-UYALkqVq.js.map +0 -1
  323. package/build/process-7R9M29wN.js +0 -437
  324. package/build/process-7R9M29wN.js.map +0 -1
  325. package/build/rabbitmq.js.map +0 -1
  326. package/build/redis.js.map +0 -1
  327. package/build/requests-DD2ALv0_.js +0 -583
  328. package/build/requests-DD2ALv0_.js.map +0 -1
  329. package/build/retrier-Dnjhvxol.js.map +0 -1
  330. package/build/timing-DZl36uXs.js.map +0 -1
  331. package/build/websocket.js.map +0 -1
@@ -1,2 +1,44 @@
1
- import { a as backoffDelay, i as backoffBand, n as DelayBand, o as backoffProblems, r as Jitter, t as Backoff } from "./backoff-QTRGfkEK.js";
2
- export { Backoff, DelayBand, Jitter, backoffBand, backoffDelay, backoffProblems };
1
+ /**
2
+ * A jitter is the random part of each delay. The random number `r` is from 0 up to 1.
3
+ * - `none`: the delay is the backoff.
4
+ * - `subtract`: the delay is `backoff × (1 − fraction × r)`. A fraction of 1 is the full jitter: a delay from 0 to the backoff.
5
+ * - `add`: the delay is `backoff + amount × r`, with the amount in milliseconds.
6
+ */
7
+ export type Jitter = {
8
+ readonly kind: "none";
9
+ } | {
10
+ readonly kind: "subtract";
11
+ readonly fraction: number;
12
+ } | {
13
+ readonly kind: "add";
14
+ readonly amount: number;
15
+ };
16
+ /** A backoff policy gives the delay before each try. Each time is in milliseconds. */
17
+ export interface Backoff {
18
+ /** This time is the backoff of the first try. */
19
+ readonly base: number;
20
+ /** This number multiplies the backoff from one try to the next. The default is 2. */
21
+ readonly factor?: number | undefined;
22
+ /** This time is the most that a backoff can be, before its jitter. The default is no limit. */
23
+ readonly cap?: number | undefined;
24
+ /** This jitter gives the random part of each delay. The default is `none`. */
25
+ readonly jitter?: Jitter | undefined;
26
+ }
27
+ /** A band is the least and the most delay that a policy gives, in milliseconds. */
28
+ export interface DelayBand {
29
+ readonly low: number;
30
+ readonly high: number;
31
+ }
32
+ /**
33
+ * This function gives the delay before a try, in milliseconds. The first try is 1. The delay is
34
+ * the backoff of the try with its jitter, and not below zero. The `random` function gives numbers from 0 up to 1.
35
+ */
36
+ export declare const backoffDelay: (policy: Backoff, attempt: number, random?: () => number) => number;
37
+ /**
38
+ * This function gives the band of the delay before a try: the least and the most delay that the
39
+ * jitter can give. Without a try, the band covers each try. The ordering law reads the most delay
40
+ * of a policy from it.
41
+ */
42
+ export declare const backoffBand: (policy: Backoff, attempt?: number) => DelayBand;
43
+ /** This function gives the problems of a policy: each value that the delays cannot use. */
44
+ export declare const backoffProblems: (policy: Backoff) => string[];
@@ -1,101 +1,15 @@
1
- import { $ as ProcessTrigger, E as Phase, F as Timing, N as Poll, O as RepeatSignal, S as ExitCodes, T as MessageTrigger, V as OperationOf, _ as Check, b as Coupling, k as ServiceDescription, q as ExitTrigger, ut as Operation, w as Gate, x as Dependency, y as CooperativeFloor } from "./logger-B6drv9w0.js";
2
- import { D as CheckFn, E as StartOptions, F as Outcome, L as Trace, S as Health, d as TransportImpl, n as HealthServer, o as PhaseWork, r as Lifecycle, s as RunOptions, t as DependencyHandle } from "./lifecycle-D0J-zwZF.js";
3
- import { l as LimiterSpec } from "./policy-CBcK2XGg.js";
4
- import { n as Clock } from "./clock-DpVgpY4h.js";
1
+ import { Check, CooperativeFloor, Coupling, Dependency, MessageTrigger, RepeatSignal, ServiceDescription } from "./description.js";
2
+ import { Health, StartOptions } from "./health.js";
3
+ import { LimiterSpec } from "./limiter/policy.js";
4
+ import { DependencyHandle, HealthServer, Lifecycle, PhaseWork, RunOptions, TransportImpl } from "./lifecycle.js";
5
+ import { Operation } from "./operation.js";
6
+ import { CheckFn } from "./poller.js";
7
+ import { ExitTrigger, ProcessTrigger } from "./process.js";
8
+ import { Profile } from "./profiles.js";
9
+ import { OperationOf } from "./routes.js";
10
+ import { Timing } from "./timing.js";
11
+ import { WatchdogSpec } from "./watchdog.js";
5
12
  import { Extent, Quantity } from "@mark1russell7/quantity";
6
- /**
7
- * A profile is a part of a declaration as data: policies, phases and the rules of the shutdown.
8
- * `svc.profile(profile)` declares each field, as its method does. The runtime has no defaults, and
9
- * a profile is not a default, because the caller gives it. The caller can change each field with a
10
- * spread. `describe()` then shows the values of the profile.
11
- *
12
- * svc.profile({ ...kubernetes({ grace: s(60), preStop: s(5) }), onRepeatSignal: "exit" });
13
- */
14
- interface Profile {
15
- readonly readiness?: Timing | undefined;
16
- readonly liveness?: Timing | undefined;
17
- readonly startup?: Quantity | undefined;
18
- readonly couplings?: readonly Coupling[] | undefined;
19
- /** These are the phases of the shutdown, in their sequence. */
20
- readonly phases?: readonly Phase[] | undefined;
21
- readonly cooperativeWindow?: Extent | undefined;
22
- readonly cooperativeFloor?: CooperativeFloor | undefined;
23
- readonly onRepeatSignal?: RepeatSignal | undefined;
24
- readonly triggers?: readonly ProcessTrigger[] | undefined;
25
- /** These messages of the IPC channel start the shutdown, as `svc.trigger("ipc-message", message)` declares each one. */
26
- readonly messages?: readonly MessageTrigger[] | undefined;
27
- readonly exitCodes?: ExitCodes | undefined;
28
- }
29
- /**
30
- * This profile is for a service on the computer of a developer. No load balancer routes to it,
31
- * thus it has no readiness hold. Its caps sum to 10 s, and a second signal exits at once. It
32
- * declares no checks, thus the caller declares readiness, liveness and the startup budget.
33
- */
34
- declare const localDev: Profile;
35
- /**
36
- * This profile is for a background host on the computer of a developer, under a supervisor or a
37
- * command that stops it. It has the caps of `localDev`. A repeat signal has no effect, thus the
38
- * host ends its drain. It has no process trigger: a background host has no parent on stdin.
39
- */
40
- declare const daemon: Profile;
41
- /**
42
- * This profile is for a small process: a command that runs one time, or a child process on stdio.
43
- * It has no checks and no probes, and its policies gate nothing. The cooperative abort occurs at the
44
- * start of the drain, thus a first Ctrl-C stops the work at once. A second signal exits at once.
45
- * The exit codes tell the shell how the process stopped: 130 for SIGINT, 143 for SIGTERM and 131
46
- * for SIGQUIT. A stdio child also declares `triggers: ["stdin-close"]`.
47
- */
48
- declare const ephemeral: Profile;
49
- /** These are the settings of a pod that the profile `kubernetes` derives its caps from. */
50
- interface PodTiming {
51
- /** This time is `terminationGracePeriodSeconds`: from the deletion of the pod to SIGKILL. */
52
- readonly grace: Quantity;
53
- /** This time is the preStop sleep, or 0 for no preStop hook. SIGTERM comes after it. */
54
- readonly preStop: Quantity;
55
- }
56
- /**
57
- * This function gives the profile of a pod in Kubernetes. The budget is the grace less the preStop
58
- * sleep: the time from SIGTERM to SIGKILL. Each stage gets a part of the budget, rounded down to
59
- * the millisecond.
60
- * - The parts in thirtieths are 2, 5, 15, 2, 1, 2 and 1, in the sequence of the stages. Thus 2
61
- * thirtieths of the budget stay as a margin before SIGKILL.
62
- * - The cooperative window is 5 thirtieths of the budget.
63
- * - The kubelet sends SIGTERM one time, thus a repeat signal has no effect.
64
- *
65
- * At the defaults of Kubernetes (a grace of 30 s and no preStop hook), the caps are 2, 5, 15, 2, 1,
66
- * 2 and 1 s. Thus the sum of the caps and the preStop sleep fits in the grace (O10). The window is
67
- * shorter than the drain, which is shorter than the budget (O16).
68
- */
69
- declare const kubernetes: (pod: PodTiming) => Profile;
70
- /**
71
- * A watchdog spec declares a watchdog of the event loop. The service declares it as a check whose
72
- * function the watchdog gives: the process's own wedge, which a liveness window reads.
73
- */
74
- interface WatchdogSpec {
75
- readonly name: string;
76
- /** This time is the interval of the tick of the watchdog. */
77
- readonly tick: Quantity;
78
- /** This time is the most that a tick can be late before the loop counts as blocked. */
79
- readonly threshold: Quantity;
80
- /** This gate is the policy that the check controls, or null for a check that only reports. */
81
- readonly gates: Gate | null;
82
- readonly poll: Poll;
83
- }
84
- /**
85
- * A watchdog measures how late its own tick comes. A blocked event loop delays each timer, thus a
86
- * tick that comes later than the threshold shows the block. Its states are `watching`, `blocked`
87
- * and `stopped`.
88
- */
89
- interface Watchdog {
90
- /** This function is the check: it fails when a tick since the last poll came late, or the loop is still blocked. */
91
- readonly check: () => Outcome;
92
- /** This time is the most that a tick was late, in milliseconds, since the start. */
93
- readonly worst: number;
94
- readonly blocked: boolean;
95
- stop(): void;
96
- }
97
- /** This function starts a watchdog on a clock. */
98
- declare const watchdog: (clock: Clock, spec: WatchdogSpec, trace?: Trace) => Watchdog;
99
13
  /**
100
14
  * The caller composes a service with plain method uses before it starts. The builder is imperative, and
101
15
  * it holds static knowledge. The service does not use an `init` function that gives registrations.
@@ -119,7 +33,7 @@ declare const watchdog: (clock: Clock, spec: WatchdogSpec, trace?: Trace) => Wat
119
33
  * `start()` starts only the health runtime. `run()` starts the whole lifecycle: the startup in its
120
34
  * sequence, the exit signals, the capped phases of the shutdown, and the exit of the process.
121
35
  */
122
- interface ControllerBuilder {
36
+ export interface ControllerBuilder {
123
37
  /** This method declares the dependencies that its routes need. The controller is ready only while they are ready. */
124
38
  requires(...dependencies: string[]): ControllerBuilder;
125
39
  /** This method declares a route that the controller serves, and if its callers can send it again. */
@@ -131,7 +45,7 @@ interface ControllerBuilder {
131
45
  pattern(pattern: string, operations: Readonly<Record<string, Operation>>, operationOf?: OperationOf): ControllerBuilder;
132
46
  }
133
47
  /** A service builder composes a service, gives it as data, and starts it. */
134
- interface ServiceBuilder {
48
+ export interface ServiceBuilder {
135
49
  readonly name: string;
136
50
  /** This method declares a dependency, and the handle that connects to it and closes it, if it has one. */
137
51
  dependency(name: string, spec: Omit<Dependency, "name">, handle?: DependencyHandle): ServiceBuilder;
@@ -201,5 +115,4 @@ interface ServiceBuilder {
201
115
  readonly lifecycle: Lifecycle | null;
202
116
  }
203
117
  /** This function starts the composition of a service. */
204
- declare const service: (name: string) => ServiceBuilder;
205
- 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 };
118
+ export declare const service: (name: string) => ServiceBuilder;
@@ -0,0 +1,499 @@
1
+ import { FORMAT } from "./description.js";
2
+ import { realClock } from "./clock.js";
3
+ import { limiterProblems } from "./limiter/policy.js";
4
+ import { healthRuntime } from "./health.js";
5
+ import { logEvents } from "./logger.js";
6
+ import { STAGES, lifecycle, lifecycleProblems, stageRank, uncaughtProblems } from "./lifecycle.js";
7
+ import { operationProblems } from "./operation.js";
8
+ import { EXIT_SIGNALS, PROCESS_TRIGGERS, isExitCode, isExitSignal, isMessageShape } from "./process.js";
9
+ import { routePatternProblems } from "./routes.js";
10
+ import { watchdog } from "./watchdog.js";
11
+ import { convertible, valueIn } from "@mark1russell7/quantity";
12
+ // src/builder.ts
13
+ const isTime = (amount) => convertible(amount.unit, "s");
14
+ const above = (amount) => amount.value === "infinite" || isTime(amount) && valueIn(amount, "s") > 0;
15
+ const whole = (count) => Number.isInteger(count) && count >= 1;
16
+ /** This function copies a check, with its poll and the loops that mark it. */
17
+ const copyCheck = (check) => ({
18
+ ...check,
19
+ poll: { ...check.poll },
20
+ ...check.marks === void 0 ? {} : { marks: {
21
+ loops: [...check.marks.loops],
22
+ stall: { ...check.marks.stall }
23
+ } }
24
+ });
25
+ /** This function gives the problems of the loops that mark a check. `lint()` compares the stall time with the loops. */
26
+ const marksProblems = (check) => {
27
+ const marks = check.marks;
28
+ if (marks === void 0) return [];
29
+ const problems = [];
30
+ if (check.step !== "progress") problems.push(`check ${check.name} names the loops that mark it, but its step is ${check.step}, not progress`);
31
+ if (marks.loops.length === 0) problems.push(`check ${check.name} names no loop that marks it`);
32
+ if (typeof marks.stall.value !== "number" || !above(marks.stall)) problems.push(`check ${check.name} has a stall time that is not a time above zero`);
33
+ return problems;
34
+ };
35
+ /** This function gives the problems of a timing: a zero interval or count fails decoding. */
36
+ const timingProblems = (policy, timing) => {
37
+ if (timing.type === "debounce") {
38
+ const problems = [];
39
+ if (!above(timing.interval)) problems.push(`the ${policy} debounce polls at an interval that is not above zero`);
40
+ if (!whole(timing.failAfter)) problems.push(`the ${policy} debounce fails after ${timing.failAfter} polls, not a whole number above zero`);
41
+ if (!whole(timing.recoverAfter)) problems.push(`the ${policy} debounce recovers after ${timing.recoverAfter} polls, not a whole number above zero`);
42
+ return problems;
43
+ }
44
+ const negative = (amount) => amount !== void 0 && (!isTime(amount) || valueIn(amount, "s") < 0);
45
+ return negative(timing.failAfter) || negative(timing.recoverAfter) ? [`the ${policy} window is not a time of zero or more`] : [];
46
+ };
47
+ /** This function gives the problems of the rules of the shutdown: an unknown name, or an exit code that a process cannot give. */
48
+ const shutdownProblems = (floor, repeat, triggers, exitCodes, messages) => {
49
+ const problems = [];
50
+ if (floor !== void 0 && floor !== "half" && floor !== "none") problems.push(`the cooperative floor ${String(floor)} is not "half" or "none"`);
51
+ if (repeat !== void 0 && repeat !== "ignore" && repeat !== "exit") problems.push(`the policy of a repeat signal ${String(repeat)} is not "ignore" or "exit"`);
52
+ for (const trigger of triggers) if (!PROCESS_TRIGGERS.includes(trigger)) problems.push(`the trigger ${String(trigger)} is not a process trigger (${PROCESS_TRIGGERS.join(", ")})`);
53
+ if (triggers.includes("ipc-message") && messages.length === 0) problems.push(`the trigger ipc-message has no message to match: declare it with svc.trigger("ipc-message", { match })`);
54
+ for (const message of messages) {
55
+ if (!isMessageShape(message.match)) problems.push(`the match of a message trigger is not a value of JSON: ${String(message.match)}`);
56
+ if (message.as !== void 0 && !isExitSignal(message.as)) problems.push(`a message trigger stands for ${String(message.as)}, not an exit signal (${EXIT_SIGNALS.join(", ")})`);
57
+ }
58
+ for (const [trigger, code] of Object.entries(exitCodes)) {
59
+ if (!(EXIT_SIGNALS.includes(trigger) || triggers.includes(trigger))) problems.push(`the exit code of ${trigger} names no exit signal and no declared trigger`);
60
+ if (code === void 0 || !isExitCode(code)) problems.push(`the exit code of ${trigger} is ${String(code)}, not a whole number from 0 to 255`);
61
+ }
62
+ return problems;
63
+ };
64
+ /**
65
+ * This function gives the options with one recorder for the recorder and the logger of the options.
66
+ * Without a logger, it gives the same options.
67
+ */
68
+ const withLogger = (options, description) => {
69
+ if (options.logger === void 0) return options;
70
+ const given = options.record;
71
+ const log = logEvents(options.logger, description);
72
+ return {
73
+ ...options,
74
+ record: (event) => {
75
+ given?.(event);
76
+ log(event);
77
+ }
78
+ };
79
+ };
80
+ /** This function starts the composition of a service. */
81
+ const service = (name) => {
82
+ if (name.trim().length === 0) throw new Error("a service needs a name");
83
+ const transports = [];
84
+ const dependencies = [];
85
+ const controllers = [];
86
+ const choices = /* @__PURE__ */ new Map();
87
+ const checks = [];
88
+ const runs = /* @__PURE__ */ new Map();
89
+ const limiters = [];
90
+ const couplings = [];
91
+ const phases = [];
92
+ let readiness;
93
+ let liveness;
94
+ let startup;
95
+ let cooperative;
96
+ let floor;
97
+ let repeat;
98
+ const triggers = [];
99
+ const messages = [];
100
+ const exitCodes = {};
101
+ let started = false;
102
+ let partial = false;
103
+ let runtime;
104
+ let live;
105
+ let running;
106
+ let life;
107
+ const transportImpls = /* @__PURE__ */ new Map();
108
+ const handles = /* @__PURE__ */ new Map();
109
+ const phaseWork = /* @__PURE__ */ new Map();
110
+ const watchdogs = [];
111
+ let probes = null;
112
+ /** This function stops a change to the shape of the service after the start. */
113
+ const composing = (what) => {
114
+ if (started) throw new Error(`${name} has started: ${what} is declared before svc.start()`);
115
+ };
116
+ const once = (list, entry, what) => {
117
+ if (list.some((held) => held.name === entry)) throw new Error(`${name} already has a ${what} named ${entry}`);
118
+ };
119
+ const transport = (kind) => (entry, knobs, impl) => {
120
+ composing(`a ${kind}`);
121
+ once(transports, entry, "transport");
122
+ transports.push({
123
+ name: entry,
124
+ kind,
125
+ knobs: { ...knobs }
126
+ });
127
+ if (impl !== void 0) transportImpls.set(entry, impl);
128
+ return builder;
129
+ };
130
+ /** This function makes the runtime of the declaration: its checks, and a watchdog for each spec. */
131
+ const makeRuntime = (given) => {
132
+ const description = builder.describe();
133
+ const options = withLogger(given, description);
134
+ const clock = options.clock ?? realClock;
135
+ const dogs = [];
136
+ const all = new Map(runs);
137
+ for (const spec of watchdogs) {
138
+ const dog = watchdog(clock, spec, (from, to, on) => options.record?.({
139
+ at: clock.now(),
140
+ machine: "watchdog",
141
+ instance: spec.name,
142
+ from,
143
+ to,
144
+ on
145
+ }));
146
+ dogs.push(dog);
147
+ all.set(spec.name, () => dog.check());
148
+ }
149
+ const stopPollers = () => {
150
+ for (const dog of dogs) dog.stop();
151
+ };
152
+ let made;
153
+ try {
154
+ made = healthRuntime(description, all, options);
155
+ } catch (error) {
156
+ stopPollers();
157
+ throw error;
158
+ }
159
+ return {
160
+ runtime: {
161
+ ...made,
162
+ stop: () => {
163
+ made.stop();
164
+ stopPollers();
165
+ }
166
+ },
167
+ description,
168
+ stopPollers,
169
+ options
170
+ };
171
+ };
172
+ const builder = {
173
+ name,
174
+ get health() {
175
+ return live ?? null;
176
+ },
177
+ get lifecycle() {
178
+ return life ?? null;
179
+ },
180
+ dependency(entry, spec, handle) {
181
+ once(dependencies, entry, "dependency");
182
+ if (handle !== void 0 && !started) handles.set(entry, handle);
183
+ dependencies.push({
184
+ name: entry,
185
+ ...spec,
186
+ knobs: { ...spec.knobs },
187
+ operations: { ...spec.operations }
188
+ });
189
+ if (started) {
190
+ partial = true;
191
+ live?.addDependency(entry);
192
+ }
193
+ return builder;
194
+ },
195
+ server: transport("server"),
196
+ consumer: transport("consumer"),
197
+ worker: transport("worker"),
198
+ controller(entry) {
199
+ composing("a controller");
200
+ once(controllers, entry, "controller");
201
+ const held = {
202
+ name: entry,
203
+ requires: [],
204
+ routes: {},
205
+ patterns: []
206
+ };
207
+ controllers.push(held);
208
+ const handle = {
209
+ requires(...needed) {
210
+ composing(`what ${entry} requires`);
211
+ held.requires.push(...needed);
212
+ return handle;
213
+ },
214
+ route(served, operation) {
215
+ composing(`${entry}'s routes`);
216
+ if (held.routes[served] !== void 0) throw new Error(`${entry} already serves ${served}`);
217
+ held.routes[served] = { ...operation };
218
+ return handle;
219
+ },
220
+ pattern(pattern, operations, operationOf) {
221
+ composing(`${entry}'s route patterns`);
222
+ if (held.patterns.some((each) => each.pattern === pattern)) throw new Error(`${entry} already has the route pattern ${pattern}`);
223
+ if (operationOf === void 0 && Object.keys(operations).length > 1) throw new Error(`${entry}'s pattern ${pattern} has ${Object.keys(operations).length} operations, thus it needs the function that picks one`);
224
+ held.patterns.push({
225
+ pattern,
226
+ operations: Object.fromEntries(Object.entries(operations).map(([name, operation]) => [name, { ...operation }]))
227
+ });
228
+ if (operationOf !== void 0) {
229
+ const mine = choices.get(entry) ?? /* @__PURE__ */ new Map();
230
+ mine.set(pattern, operationOf);
231
+ choices.set(entry, mine);
232
+ }
233
+ return handle;
234
+ }
235
+ };
236
+ return handle;
237
+ },
238
+ check(check, run) {
239
+ once(checks, check.name, "check");
240
+ if (started && run === void 0) throw new Error(`check ${check.name} joins after the start, thus it needs its function`);
241
+ checks.push(copyCheck(check));
242
+ if (run !== void 0) runs.set(check.name, run);
243
+ if (started) {
244
+ partial = true;
245
+ live?.addCheck(copyCheck(check), run);
246
+ }
247
+ return builder;
248
+ },
249
+ limiter(entry, spec) {
250
+ composing(`the limiter ${entry}`);
251
+ once(limiters, entry, "limiter");
252
+ const given = spec ?? {};
253
+ limiters.push({
254
+ name: entry,
255
+ ...given,
256
+ ...given.policy === void 0 ? {} : { policy: { ...given.policy } },
257
+ ...given.store === void 0 ? {} : { store: { ...given.store } },
258
+ ...given.evict === void 0 ? {} : { evict: { ...given.evict } }
259
+ });
260
+ return builder;
261
+ },
262
+ healthServer(server) {
263
+ composing("the health server");
264
+ if (probes !== null) throw new Error(`${name} already has a health server`);
265
+ probes = server;
266
+ return builder;
267
+ },
268
+ onPhase(phase, work) {
269
+ composing(`work for the phase ${phase}`);
270
+ phaseWork.set(phase, [...phaseWork.get(phase) ?? [], work]);
271
+ return builder;
272
+ },
273
+ watchdog(spec) {
274
+ composing(`the watchdog ${spec.name}`);
275
+ once(checks, spec.name, "check");
276
+ checks.push({
277
+ name: spec.name,
278
+ dependency: null,
279
+ step: "local-state",
280
+ ownConnection: true,
281
+ gates: spec.gates,
282
+ poll: { ...spec.poll }
283
+ });
284
+ watchdogs.push(spec);
285
+ return builder;
286
+ },
287
+ readiness(timing) {
288
+ composing("readiness");
289
+ readiness = timing;
290
+ return builder;
291
+ },
292
+ liveness(timing) {
293
+ composing("liveness");
294
+ liveness = timing;
295
+ return builder;
296
+ },
297
+ startup(budget) {
298
+ composing("the startup budget");
299
+ startup = budget;
300
+ return builder;
301
+ },
302
+ couple(coupling) {
303
+ composing("a coupling");
304
+ couplings.push({ ...coupling });
305
+ return builder;
306
+ },
307
+ phase(entry, cap) {
308
+ composing("a shutdown phase");
309
+ once(phases, entry, "shutdown phase");
310
+ phases.push({
311
+ name: entry,
312
+ cap
313
+ });
314
+ return builder;
315
+ },
316
+ cooperativeWindow(window) {
317
+ composing("the cooperative window");
318
+ cooperative = window;
319
+ return builder;
320
+ },
321
+ cooperativeFloor(given) {
322
+ composing("the cooperative floor");
323
+ floor = given;
324
+ return builder;
325
+ },
326
+ onRepeatSignal(policy) {
327
+ composing("the policy of a repeat signal");
328
+ repeat = policy;
329
+ return builder;
330
+ },
331
+ trigger(...given) {
332
+ composing("a trigger");
333
+ const [first, message] = given;
334
+ if (first === "ipc-message" && typeof message === "object" && message !== null) {
335
+ if (!triggers.includes("ipc-message")) triggers.push("ipc-message");
336
+ messages.push({ ...message });
337
+ return builder;
338
+ }
339
+ for (const each of given) if (typeof each === "string" && !triggers.includes(each)) triggers.push(each);
340
+ return builder;
341
+ },
342
+ exitCode(trigger, code) {
343
+ composing(`the exit code of ${trigger}`);
344
+ exitCodes[trigger] = code;
345
+ return builder;
346
+ },
347
+ profile(given) {
348
+ composing("a profile");
349
+ if (given.readiness !== void 0) builder.readiness(given.readiness);
350
+ if (given.liveness !== void 0) builder.liveness(given.liveness);
351
+ if (given.startup !== void 0) builder.startup(given.startup);
352
+ for (const coupling of given.couplings ?? []) builder.couple(coupling);
353
+ for (const each of given.phases ?? []) builder.phase(each.name, each.cap);
354
+ if (given.cooperativeWindow !== void 0) builder.cooperativeWindow(given.cooperativeWindow);
355
+ if (given.cooperativeFloor !== void 0) builder.cooperativeFloor(given.cooperativeFloor);
356
+ if (given.onRepeatSignal !== void 0) builder.onRepeatSignal(given.onRepeatSignal);
357
+ if (given.triggers !== void 0) builder.trigger(...given.triggers);
358
+ for (const message of given.messages ?? []) builder.trigger("ipc-message", message);
359
+ for (const [trigger, code] of Object.entries(given.exitCodes ?? {})) if (code !== void 0) builder.exitCode(trigger, code);
360
+ return builder;
361
+ },
362
+ describe() {
363
+ const missing = [];
364
+ if (readiness === void 0) missing.push("readiness (svc.readiness)");
365
+ if (liveness === void 0) missing.push("liveness (svc.liveness)");
366
+ if (startup === void 0) missing.push("a startup budget (svc.startup)");
367
+ if (phases.length === 0) missing.push("its shutdown phases (svc.phase)");
368
+ if (cooperative === void 0) missing.push("a cooperative window, or no bound (svc.cooperativeWindow)");
369
+ if (repeat === void 0) missing.push(`what a repeat signal does, "ignore" or "exit" (svc.onRepeatSignal)`);
370
+ if (missing.length > 0) throw new Error(`${name} does not declare ${missing.join("; ")}: the runtime has no defaults`);
371
+ const known = new Set(dependencies.map((entry) => entry.name));
372
+ const problems = [];
373
+ const policies = {
374
+ readiness,
375
+ liveness
376
+ };
377
+ for (const gate of ["readiness", "liveness"]) problems.push(...timingProblems(gate, policies[gate]));
378
+ for (const check of checks) {
379
+ if (check.dependency !== null && !known.has(check.dependency)) problems.push(`check ${check.name} exercises ${check.dependency}, which is not a dependency`);
380
+ if (!isTime(check.poll.interval) || !isTime(check.poll.timeout)) problems.push(`check ${check.name} polls in a unit that is not a time`);
381
+ else if (!above(check.poll.interval) || !above(check.poll.timeout)) problems.push(`check ${check.name} polls with an interval or a timeout that is not above zero`);
382
+ if (!(check.poll.jitter >= 0 && check.poll.jitter < 1)) problems.push(`check ${check.name} has a jitter of ${check.poll.jitter}, not a fraction below 1`);
383
+ problems.push(...marksProblems(check));
384
+ const timing = check.gates === null ? null : policies[check.gates];
385
+ if (timing?.type === "debounce" && isTime(check.poll.interval) && above(timing.interval) && valueIn(check.poll.interval, "s") !== valueIn(timing.interval, "s")) problems.push(`check ${check.name} polls every ${valueIn(check.poll.interval, "s")} s, but the ${check.gates} debounce counts polls every ${valueIn(timing.interval, "s")} s`);
386
+ }
387
+ for (const controller of controllers) {
388
+ for (const needed of controller.requires) if (!known.has(needed)) problems.push(`controller ${controller.name} requires ${needed}, which is not a dependency`);
389
+ for (const [route, operation] of Object.entries(controller.routes)) problems.push(...operationProblems(`controller ${controller.name}`, route, operation));
390
+ for (const declared of controller.patterns) problems.push(...routePatternProblems(`controller ${controller.name}`, declared));
391
+ }
392
+ for (const limiter of limiters) {
393
+ const { name: entry, ...spec } = limiter;
394
+ problems.push(...limiterProblems(entry, spec));
395
+ if (limiter.store?.kind === "shared" && typeof limiter.store.dependency === "string" && !known.has(limiter.store.dependency)) problems.push(`limiter ${entry} keeps its counts in ${limiter.store.dependency}, which is not a dependency`);
396
+ }
397
+ for (const dependency of dependencies) for (const [name, operation] of Object.entries(dependency.operations)) problems.push(...operationProblems(`dependency ${dependency.name}`, name, operation));
398
+ for (const phase of phases) if (!isTime(phase.cap)) problems.push(`phase ${phase.name}'s cap is not a time`);
399
+ problems.push(...shutdownProblems(floor, repeat, triggers, exitCodes, messages));
400
+ const ranked = phases.map((phase) => phase.name).filter((each) => stageRank(each) >= 0);
401
+ for (let at = 1; at < ranked.length; at += 1) if (stageRank(ranked[at]) < stageRank(ranked[at - 1])) problems.push(`the phase "${ranked[at]}" comes after "${ranked[at - 1]}", but the stages go ${STAGES.join(", ")}`);
402
+ if (problems.length > 0) throw new Error(`${name}: ${problems.join("; ")}`);
403
+ const controllersOut = controllers.map((entry) => ({
404
+ name: entry.name,
405
+ requires: [...entry.requires],
406
+ routes: { ...entry.routes },
407
+ ...entry.patterns.length === 0 ? {} : { patterns: entry.patterns.map((each) => ({
408
+ pattern: each.pattern,
409
+ operations: { ...each.operations }
410
+ })) }
411
+ }));
412
+ return {
413
+ format: FORMAT,
414
+ name,
415
+ partial,
416
+ transports: transports.map((entry) => ({
417
+ ...entry,
418
+ knobs: { ...entry.knobs }
419
+ })),
420
+ dependencies: dependencies.map((entry) => ({
421
+ ...entry,
422
+ knobs: { ...entry.knobs },
423
+ operations: { ...entry.operations }
424
+ })),
425
+ controllers: controllersOut,
426
+ checks: checks.map(copyCheck),
427
+ ...limiters.length === 0 ? {} : { limiters: limiters.map((entry) => ({
428
+ ...entry,
429
+ policy: { ...entry.policy },
430
+ store: { ...entry.store },
431
+ evict: { maxKeys: { ...entry.evict.maxKeys } }
432
+ })) },
433
+ policies: {
434
+ readiness,
435
+ liveness,
436
+ startup
437
+ },
438
+ couplings: couplings.map((entry) => ({ ...entry })),
439
+ shutdown: {
440
+ phases: phases.map((entry) => ({ ...entry })),
441
+ cooperativeWindow: cooperative,
442
+ ...floor === void 0 ? {} : { cooperativeFloor: floor },
443
+ onRepeatSignal: repeat,
444
+ ...triggers.length === 0 ? {} : { triggers: [...triggers] },
445
+ ...messages.length === 0 ? {} : { messages: messages.map((each) => ({ ...each })) },
446
+ ...Object.keys(exitCodes).length === 0 ? {} : { exitCodes: { ...exitCodes } }
447
+ }
448
+ };
449
+ },
450
+ start(options = {}) {
451
+ if (runtime !== void 0) return runtime;
452
+ if (running !== void 0) return Promise.reject(/* @__PURE__ */ new Error(`${name} runs its lifecycle: use its health`));
453
+ let made;
454
+ try {
455
+ made = makeRuntime(options).runtime;
456
+ } catch (error) {
457
+ return Promise.reject(error);
458
+ }
459
+ started = true;
460
+ live = made;
461
+ runtime = made.warmUp().then(() => made);
462
+ return runtime;
463
+ },
464
+ run(options = {}) {
465
+ if (running !== void 0) return running;
466
+ if (runtime !== void 0) return Promise.reject(/* @__PURE__ */ new Error(`${name} started its health only: run() starts the whole lifecycle`));
467
+ try {
468
+ const description = builder.describe();
469
+ const components = {
470
+ transports: transportImpls,
471
+ dependencies: handles,
472
+ healthServer: probes,
473
+ phaseWork,
474
+ choices,
475
+ stopPollers: () => {}
476
+ };
477
+ const problems = [...lifecycleProblems(description, components), ...uncaughtProblems(options.uncaught)];
478
+ if (problems.length > 0) throw new Error(`${name}: ${problems.join("; ")}`);
479
+ const made = makeRuntime(options);
480
+ started = true;
481
+ live = made.runtime;
482
+ const ran = lifecycle(made.description, made.runtime, {
483
+ ...components,
484
+ stopPollers: made.stopPollers
485
+ }, made.options, (given) => {
486
+ life = given;
487
+ });
488
+ running = ran.started.then(() => ran);
489
+ } catch (error) {
490
+ return Promise.reject(error);
491
+ }
492
+ return running;
493
+ }
494
+ };
495
+ return builder;
496
+ };
497
+ export { service };
498
+
499
+ //# sourceMappingURL=builder.js.map