@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,13 +1,13 @@
1
- import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { c as Logger } from "./logger-B6drv9w0.js";
1
+ import { Clock } from "../clock.js";
2
+ import { Logger } from "../logger.js";
3
3
  /** These options go with one command: the folder that it runs in, and the most time that it can take. */
4
- interface CommandOptions {
4
+ export interface CommandOptions {
5
5
  readonly cwd?: string | undefined;
6
6
  /** This time is the most that the command can take, in milliseconds. After it, the command stops, and its code is 124. */
7
7
  readonly timeout?: number | undefined;
8
8
  }
9
9
  /** A command result is the exit code of a command and the text that it wrote to its output and its error output. */
10
- interface CommandResult {
10
+ export interface CommandResult {
11
11
  /** This code is the exit code. A program that is not found gives 127, and a command at its timeout gives 124. */
12
12
  readonly code: number;
13
13
  readonly out: string;
@@ -16,11 +16,11 @@ interface CommandResult {
16
16
  * A command port starts a program with a list of arguments and gives its result. It does not use a
17
17
  * shell, thus no argument needs a quote. The host uses it for `schtasks`, `systemctl` and `taskkill`.
18
18
  */
19
- interface CommandPort {
19
+ export interface CommandPort {
20
20
  run(file: string, args: readonly string[], options?: CommandOptions): Promise<CommandResult>;
21
21
  }
22
22
  /** A file port is the part of a file system that the host uses. Each path is a full path. */
23
- interface FilePort {
23
+ export interface FilePort {
24
24
  /** This method gives the text of a file in UTF-8, or null when the file does not exist. */
25
25
  read(path: string): Promise<string | null>;
26
26
  /** This method writes a file. It makes the folders of the path, and it replaces the file in one step. */
@@ -37,9 +37,9 @@ interface FilePort {
37
37
  remove(path: string): Promise<void>;
38
38
  }
39
39
  /** These are the signals that the host sends to a process. */
40
- type StopSignal = "SIGINT" | "SIGTERM" | "SIGKILL";
40
+ export type StopSignal = "SIGINT" | "SIGTERM" | "SIGKILL";
41
41
  /** A spawn request tells the program that a child process runs, with its arguments, its folder and its environment. */
42
- interface SpawnRequest {
42
+ export interface SpawnRequest {
43
43
  readonly program: string;
44
44
  readonly args: readonly string[];
45
45
  readonly cwd?: string | undefined;
@@ -48,7 +48,7 @@ interface SpawnRequest {
48
48
  readonly ipc: boolean;
49
49
  }
50
50
  /** A child handle is a child process that the host started. */
51
- interface ChildHandle {
51
+ export interface ChildHandle {
52
52
  /** This number is the process ID, or null when the program did not start. */
53
53
  readonly pid: number | null;
54
54
  /** This flag tells if the child has an IPC channel. */
@@ -67,7 +67,7 @@ interface ChildHandle {
67
67
  * A process port is the part of the processes of the system that the host uses. It finds if a
68
68
  * process is alive, it gives its start time, it sends signals and it starts a child.
69
69
  */
70
- interface ProcessesPort {
70
+ export interface ProcessesPort {
71
71
  /** This method tells if a process with this ID is alive. A process of a different user is alive too. */
72
72
  alive(pid: number): boolean;
73
73
  /** This method gives the start time of a process, in milliseconds after the epoch, or null when the system does not tell. */
@@ -80,13 +80,13 @@ interface ProcessesPort {
80
80
  spawn(request: SpawnRequest): ChildHandle;
81
81
  }
82
82
  /** An HTTP answer is the status and the text of an answer. `complete` is false when the text stopped at the limit. */
83
- interface HttpAnswer {
83
+ export interface HttpAnswer {
84
84
  readonly status: number;
85
85
  readonly body: string;
86
86
  readonly complete: boolean;
87
87
  }
88
88
  /** A net port does the network part of a readiness probe. */
89
- interface NetPort {
89
+ export interface NetPort {
90
90
  /** This method sends a GET request, and gives the status of the answer, or null when no answer came in the timeout. */
91
91
  httpStatus(url: string, timeout: number): Promise<number | null>;
92
92
  /**
@@ -99,7 +99,7 @@ interface NetPort {
99
99
  tcpConnect(host: string, port: number, timeout: number): Promise<boolean>;
100
100
  }
101
101
  /** This record names a process: its ID and its start time, in milliseconds after the epoch. */
102
- interface ProcessMark {
102
+ export interface ProcessMark {
103
103
  readonly pid: number;
104
104
  readonly startedAt: number;
105
105
  }
@@ -107,7 +107,7 @@ interface ProcessMark {
107
107
  * The host ports are each effect of the system that the host uses. A test gives fakes (`fakeHost` of
108
108
  * `./testing`), thus a test installs no task and starts no process. `nodeHostPorts()` gives the ports of Node.
109
109
  */
110
- interface HostPorts {
110
+ export interface HostPorts {
111
111
  /** This text is the platform, as `process.platform` gives it, for example `win32` or `linux`. */
112
112
  readonly platform: string;
113
113
  readonly commands: CommandPort;
@@ -130,5 +130,4 @@ interface HostPorts {
130
130
  readonly logger?: Logger | undefined;
131
131
  }
132
132
  /** This function joins the parts of a path with the separator of the platform. */
133
- declare const joinPath: (platform: string, ...parts: readonly string[]) => string;
134
- export { FilePort as a, NetPort as c, SpawnRequest as d, StopSignal as f, CommandResult as i, ProcessMark as l, CommandOptions as n, HostPorts as o, joinPath as p, CommandPort as r, HttpAnswer as s, ChildHandle as t, ProcessesPort as u };
133
+ export declare const joinPath: (platform: string, ...parts: readonly string[]) => string;
@@ -0,0 +1,17 @@
1
+ // src/host/ports.ts
2
+ /** This function joins the parts of a path with the separator of the platform. */
3
+ const joinPath = (platform, ...parts) => {
4
+ const separator = platform === "win32" ? "\\" : "/";
5
+ const isSeparator = (char) => char === "/" || char === "\\";
6
+ const trim = (part, head) => {
7
+ let start = 0;
8
+ let end = part.length;
9
+ while (head && start < end && isSeparator(part[start])) start += 1;
10
+ while (end > start && isSeparator(part[end - 1])) end -= 1;
11
+ return part.slice(start, end);
12
+ };
13
+ return parts.map((part, at) => trim(part, at !== 0)).filter((part, at) => at === 0 || part !== "").join(separator);
14
+ };
15
+ export { joinPath };
16
+
17
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","names":[],"sources":["../../src/host/ports.ts"],"sourcesContent":["import type { Clock } from \"../clock.ts\";\nimport type { Logger } from \"../logger.ts\";\n\n/** These options go with one command: the folder that it runs in, and the most time that it can take. */\nexport interface CommandOptions {\n readonly cwd?: string | undefined;\n /** This time is the most that the command can take, in milliseconds. After it, the command stops, and its code is 124. */\n readonly timeout?: number | undefined;\n}\n\n/** A command result is the exit code of a command and the text that it wrote to its output and its error output. */\nexport interface CommandResult {\n /** This code is the exit code. A program that is not found gives 127, and a command at its timeout gives 124. */\n readonly code: number;\n readonly out: string;\n}\n\n/**\n * A command port starts a program with a list of arguments and gives its result. It does not use a\n * shell, thus no argument needs a quote. The host uses it for `schtasks`, `systemctl` and `taskkill`.\n */\nexport interface CommandPort {\n run(file: string, args: readonly string[], options?: CommandOptions): Promise<CommandResult>;\n}\n\n/** A file port is the part of a file system that the host uses. Each path is a full path. */\nexport interface FilePort {\n /** This method gives the text of a file in UTF-8, or null when the file does not exist. */\n read(path: string): Promise<string | null>;\n /** This method writes a file. It makes the folders of the path, and it replaces the file in one step. */\n write(path: string, data: string | Uint8Array): Promise<void>;\n /** This method makes a file only when no file has the path, and tells if it made it. It makes the folders of the path. */\n create(path: string, data: string): Promise<boolean>;\n /** This method adds data at the end of a file. It makes the file and its folders when they do not exist. */\n append(path: string, data: string | Uint8Array): Promise<void>;\n /** This method gives the size of a file in bytes, or null when the file does not exist. */\n size(path: string): Promise<number | null>;\n /** This method gives a file a new path. It replaces a file at the new path. */\n rename(from: string, to: string): Promise<void>;\n /** This method removes a file. A file that does not exist is not an error. */\n remove(path: string): Promise<void>;\n}\n\n/** These are the signals that the host sends to a process. */\nexport type StopSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGKILL\";\n\n/** A spawn request tells the program that a child process runs, with its arguments, its folder and its environment. */\nexport interface SpawnRequest {\n readonly program: string;\n readonly args: readonly string[];\n readonly cwd?: string | undefined;\n readonly env: Readonly<Record<string, string>>;\n /** True gives the child an IPC channel. Only a child that is a Node program can use it. */\n readonly ipc: boolean;\n}\n\n/** A child handle is a child process that the host started. */\nexport interface ChildHandle {\n /** This number is the process ID, or null when the program did not start. */\n readonly pid: number | null;\n /** This flag tells if the child has an IPC channel. */\n readonly ipc: boolean;\n /** This method adds a handler for each part of the output and of the error output of the child. */\n onOutput(handler: (stream: \"stdout\" | \"stderr\", chunk: string | Uint8Array) => void): void;\n /**\n * This method adds a handler for the end of the child. The handler gets the exit code, or null after\n * a signal, and the signal. A program that did not start also ends, with a null code.\n */\n onExit(handler: (code: number | null, signal: string | null) => void): void;\n /** This method sends a message on the IPC channel, and tells if it went. */\n send(message: unknown): boolean;\n}\n\n/**\n * A process port is the part of the processes of the system that the host uses. It finds if a\n * process is alive, it gives its start time, it sends signals and it starts a child.\n */\nexport interface ProcessesPort {\n /** This method tells if a process with this ID is alive. A process of a different user is alive too. */\n alive(pid: number): boolean;\n /** This method gives the start time of a process, in milliseconds after the epoch, or null when the system does not tell. */\n startOf(pid: number): Promise<number | null>;\n /** This method sends a signal to one process, and tells if the signal went. */\n signal(pid: number, signal: StopSignal): boolean;\n /** This method sends a signal to the process group whose leader is `pid`, and tells if the signal went. Windows has no process groups. */\n signalGroup(pid: number, signal: StopSignal): boolean;\n /** This method starts a child process. On Linux, the child leads a new process group. */\n spawn(request: SpawnRequest): ChildHandle;\n}\n\n/** An HTTP answer is the status and the text of an answer. `complete` is false when the text stopped at the limit. */\nexport interface HttpAnswer {\n readonly status: number;\n readonly body: string;\n readonly complete: boolean;\n}\n\n/** A net port does the network part of a readiness probe. */\nexport interface NetPort {\n /** This method sends a GET request, and gives the status of the answer, or null when no answer came in the timeout. */\n httpStatus(url: string, timeout: number): Promise<number | null>;\n /**\n * This method sends a GET request, and gives the status and up to `limit` bytes of the text. It gives\n * null when the answer did not end in the timeout. A probe with freshness bounds uses it. It is optional\n * for the net ports that callers wrote before it. `nodeHostPorts` and `fakeHost` have it.\n */\n httpText?(url: string, timeout: number, limit: number): Promise<HttpAnswer | null>;\n /** This method tells if a TCP connection to the host and the port opens in the timeout, in milliseconds. */\n tcpConnect(host: string, port: number, timeout: number): Promise<boolean>;\n}\n\n/** This record names a process: its ID and its start time, in milliseconds after the epoch. */\nexport interface ProcessMark {\n readonly pid: number;\n readonly startedAt: number;\n}\n\n/**\n * The host ports are each effect of the system that the host uses. A test gives fakes (`fakeHost` of\n * `./testing`), thus a test installs no task and starts no process. `nodeHostPorts()` gives the ports of Node.\n */\nexport interface HostPorts {\n /** This text is the platform, as `process.platform` gives it, for example `win32` or `linux`. */\n readonly platform: string;\n readonly commands: CommandPort;\n readonly files: FilePort;\n readonly processes: ProcessesPort;\n readonly net: NetPort;\n /** This clock gives the monotonic time and the timers. */\n readonly clock: Clock;\n /** This function gives the wall time, in milliseconds after the epoch. */\n readonly wall: () => number;\n /** This record names the process of the host itself. */\n readonly self: ProcessMark;\n /** These are the environment variables of the host. */\n readonly env: Readonly<Record<string, string | undefined>>;\n /** This text is the home folder of the user. */\n readonly homeDir: string;\n /** This function gives the user that a Windows task runs as, for example `HOST\\name`. */\n readonly user: () => string;\n /** This logger gets the log entries of the host. Without it, the host writes no log. */\n readonly logger?: Logger | undefined;\n}\n\n/** This function joins the parts of a path with the separator of the platform. */\nexport const joinPath = (platform: string, ...parts: readonly string[]): string => {\n const separator = platform === \"win32\" ? \"\\\\\" : \"/\";\n // a scan and not a regular expression, thus a long run of separators takes linear time\n const isSeparator = (char: string | undefined): boolean => char === \"/\" || char === \"\\\\\";\n const trim = (part: string, head: boolean): string => {\n let start = 0;\n let end = part.length;\n while (head && start < end && isSeparator(part[start])) start += 1;\n while (end > start && isSeparator(part[end - 1])) end -= 1;\n return part.slice(start, end);\n };\n const trimmed = parts.map((part, at) => trim(part, at !== 0));\n return trimmed.filter((part, at) => at === 0 || part !== \"\").join(separator);\n};\n"],"mappings":";;AAiJA,MAAa,YAAY,UAAkB,GAAG,UAAqC;CACjF,MAAM,YAAY,aAAa,UAAU,OAAO;CAEhD,MAAM,eAAe,SAAsC,SAAS,OAAO,SAAS;CACpF,MAAM,QAAQ,MAAc,SAA0B;EACpD,IAAI,QAAQ;EACZ,IAAI,MAAM,KAAK;EACf,OAAO,QAAQ,QAAQ,OAAO,YAAY,KAAK,MAAM,GAAG,SAAS;EACjE,OAAO,MAAM,SAAS,YAAY,KAAK,MAAM,EAAE,GAAG,OAAO;EACzD,OAAO,KAAK,MAAM,OAAO,GAAG;CAC9B;CAEA,OADgB,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM,OAAO,CAAC,CAC9C,CAAC,CAAC,QAAQ,MAAM,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC,CAAC,KAAK,SAAS;AAC7E"}
@@ -0,0 +1,51 @@
1
+ import { HostPorts } from "./ports.js";
2
+ import { Quantity } from "@mark1russell7/quantity";
3
+ /**
4
+ * A freshness bound reads one time in the JSON answer of an http probe. The time is epoch
5
+ * milliseconds or an ISO 8601 text. The probe fails when the time is older than `within`, or when
6
+ * the answer does not have it.
7
+ */
8
+ export interface FreshnessBound {
9
+ /** This JSON Pointer (RFC 6901) names the time in the answer, for example `/delivery/lastTestSendAt`. */
10
+ readonly pointer: string;
11
+ /** This time is the largest age that passes. */
12
+ readonly within: Quantity;
13
+ }
14
+ /**
15
+ * A ready probe tells when a program is ready.
16
+ * - `http`: a GET request to the address gives the status, 200 by default. With `fresh`, the answer
17
+ * is also JSON, and each bound of `fresh` passes. The age of a time is measured from `now`: a
18
+ * JSON Pointer to the time of the target in the answer. Without `now`, the wall clock of the host
19
+ * gives the time.
20
+ * - `tcp`: a TCP connection to the port opens. The default host is `127.0.0.1`.
21
+ * - `command`: a command gives the exit code 0.
22
+ */
23
+ export type ReadyProbe = {
24
+ readonly kind: "http";
25
+ readonly url: string;
26
+ readonly status?: number | undefined;
27
+ readonly fresh?: readonly FreshnessBound[] | undefined;
28
+ readonly now?: string | undefined;
29
+ } | {
30
+ readonly kind: "tcp";
31
+ readonly port: number;
32
+ readonly host?: string | undefined;
33
+ } | {
34
+ readonly kind: "command";
35
+ readonly program: string;
36
+ readonly args: readonly string[];
37
+ readonly cwd?: string | undefined;
38
+ };
39
+ /** A probe result is the result of one use of a probe. A failure tells why. */
40
+ export type ProbeResult = {
41
+ readonly ok: true;
42
+ } | {
43
+ readonly ok: false;
44
+ readonly why: string;
45
+ };
46
+ /** This size is the largest answer that a probe with freshness bounds reads: 1 MiB. */
47
+ export declare const PROBE_BODY_LIMIT = 1048576;
48
+ /** This function gives the problems of a probe: each value that a probe cannot use. */
49
+ export declare const probeProblems: (probe: ReadyProbe) => string[];
50
+ /** This function uses a probe one time, in a timeout of milliseconds. It does not throw. */
51
+ export declare const probeOnce: (probe: ReadyProbe, timeout: number, ports: HostPorts) => Promise<ProbeResult>;
@@ -0,0 +1,139 @@
1
+ import { convertible, formatDuration, isQuantity, valueIn } from "@mark1russell7/quantity";
2
+ // src/host/probes.ts
3
+ /** This size is the largest answer that a probe with freshness bounds reads: 1 MiB. */
4
+ const PROBE_BODY_LIMIT = 1048576;
5
+ const isPointer = (pointer) => typeof pointer === "string" && (pointer === "" || pointer.startsWith("/") && !/~[^01]|~$/.test(pointer));
6
+ /** This function gives the problems of a probe: each value that a probe cannot use. */
7
+ const probeProblems = (probe) => {
8
+ if (probe.kind === "http") {
9
+ const problems = [];
10
+ if (!/^https?:\/\//.test(probe.url)) problems.push(`the address ${JSON.stringify(probe.url)} is not an http or https address`);
11
+ if (probe.status !== void 0 && !(Number.isInteger(probe.status) && probe.status >= 100 && probe.status <= 599)) problems.push(`the status ${probe.status} is not an HTTP status`);
12
+ if (probe.now !== void 0 && !isPointer(probe.now)) problems.push(`the now ${JSON.stringify(probe.now)} is not a JSON Pointer`);
13
+ if (probe.now !== void 0 && probe.fresh === void 0) problems.push("the probe has a now, but no fresh list");
14
+ if (probe.fresh !== void 0 && probe.fresh.length === 0) problems.push("the fresh list is empty");
15
+ for (const bound of probe.fresh ?? []) {
16
+ if (!isPointer(bound.pointer)) problems.push(`the freshness pointer ${JSON.stringify(bound.pointer)} is not a JSON Pointer`);
17
+ if (!(isQuantity(bound.within) && convertible(bound.within.unit, "ms") && valueIn(bound.within, "ms") >= 0)) problems.push(`the freshness bound of ${JSON.stringify(bound.pointer)} is not a time of zero or more`);
18
+ }
19
+ return problems;
20
+ }
21
+ if (probe.kind === "tcp") return Number.isInteger(probe.port) && probe.port >= 1 && probe.port <= 65535 ? [] : [`the port ${probe.port} is not a port from 1 to 65535`];
22
+ if (probe.kind === "command") return probe.program === "" ? ["the program of the command probe is empty"] : [];
23
+ return [`the probe kind ${JSON.stringify(probe.kind)} is not http, tcp or command`];
24
+ };
25
+ /** This function gives the value at a JSON Pointer (RFC 6901), or undefined when the document does not have it. */
26
+ const pointAt = (document, pointer) => {
27
+ if (pointer === "") return document;
28
+ let at = document;
29
+ for (const token of pointer.slice(1).split("/")) {
30
+ const key = token.replaceAll("~1", "/").replaceAll("~0", "~");
31
+ if (Array.isArray(at)) {
32
+ if (!/^(0|[1-9]\d*)$/.test(key) || Number(key) >= at.length) return void 0;
33
+ at = at[Number(key)];
34
+ } else if (at !== null && typeof at === "object" && Object.hasOwn(at, key)) at = at[key];
35
+ else return void 0;
36
+ }
37
+ return at;
38
+ };
39
+ /** This function gives the time of a value in epoch milliseconds: a finite number, or an ISO 8601 text. */
40
+ const timeOf = (value) => {
41
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
42
+ if (typeof value === "string") {
43
+ const time = Date.parse(value);
44
+ return Number.isNaN(time) ? null : time;
45
+ }
46
+ return null;
47
+ };
48
+ /** This function examines the JSON answer of an http probe against its freshness bounds. */
49
+ const freshness = (url, body, bounds, nowPointer, wall) => {
50
+ let document;
51
+ try {
52
+ document = JSON.parse(body);
53
+ } catch {
54
+ return {
55
+ ok: false,
56
+ why: `${url} did not give JSON`
57
+ };
58
+ }
59
+ const now = nowPointer === void 0 ? wall : timeOf(pointAt(document, nowPointer));
60
+ if (now === null) return {
61
+ ok: false,
62
+ why: `${url} has no time at ${nowPointer}`
63
+ };
64
+ const stale = [];
65
+ for (const bound of bounds) {
66
+ const time = timeOf(pointAt(document, bound.pointer));
67
+ if (time === null) {
68
+ stale.push(`${bound.pointer} has no time`);
69
+ continue;
70
+ }
71
+ const age = Math.max(0, now - time);
72
+ if (age > valueIn(bound.within, "ms")) stale.push(`${bound.pointer} is ${formatDuration({
73
+ value: age,
74
+ unit: "ms"
75
+ })} old, above ${formatDuration(bound.within)}`);
76
+ }
77
+ return stale.length === 0 ? { ok: true } : {
78
+ ok: false,
79
+ why: `${url}: ${stale.join("; ")}`
80
+ };
81
+ };
82
+ /** This function uses a probe one time, in a timeout of milliseconds. It does not throw. */
83
+ const probeOnce = async (probe, timeout, ports) => {
84
+ try {
85
+ if (probe.kind === "http") {
86
+ const want = probe.status ?? 200;
87
+ if (probe.fresh !== void 0) {
88
+ if (ports.net.httpText === void 0) return {
89
+ ok: false,
90
+ why: "the net port cannot read an answer, thus it cannot examine freshness"
91
+ };
92
+ const answer = await ports.net.httpText(probe.url, timeout, PROBE_BODY_LIMIT);
93
+ if (answer === null) return {
94
+ ok: false,
95
+ why: `${probe.url} gave no answer in ${timeout} ms`
96
+ };
97
+ if (answer.status !== want) return {
98
+ ok: false,
99
+ why: `${probe.url} gave ${answer.status}, not ${want}`
100
+ };
101
+ if (!answer.complete) return {
102
+ ok: false,
103
+ why: `the answer of ${probe.url} is above ${PROBE_BODY_LIMIT} bytes`
104
+ };
105
+ return freshness(probe.url, answer.body, probe.fresh, probe.now, ports.wall());
106
+ }
107
+ const status = await ports.net.httpStatus(probe.url, timeout);
108
+ if (status === want) return { ok: true };
109
+ return {
110
+ ok: false,
111
+ why: status === null ? `${probe.url} gave no answer in ${timeout} ms` : `${probe.url} gave ${status}, not ${want}`
112
+ };
113
+ }
114
+ if (probe.kind === "tcp") {
115
+ const host = probe.host ?? "127.0.0.1";
116
+ if (await ports.net.tcpConnect(host, probe.port, timeout)) return { ok: true };
117
+ return {
118
+ ok: false,
119
+ why: `no TCP connection to ${host}:${probe.port} in ${timeout} ms`
120
+ };
121
+ }
122
+ const result = await ports.commands.run(probe.program, probe.args, {
123
+ cwd: probe.cwd,
124
+ timeout
125
+ });
126
+ return result.code === 0 ? { ok: true } : {
127
+ ok: false,
128
+ why: `${probe.program} gave the code ${result.code}`
129
+ };
130
+ } catch (error) {
131
+ return {
132
+ ok: false,
133
+ why: `the probe failed: ${error instanceof Error ? error.message : String(error)}`
134
+ };
135
+ }
136
+ };
137
+ export { PROBE_BODY_LIMIT, probeOnce, probeProblems };
138
+
139
+ //# sourceMappingURL=probes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probes.js","names":[],"sources":["../../src/host/probes.ts"],"sourcesContent":["import type { Quantity } from \"@mark1russell7/quantity\";\nimport { convertible, formatDuration, isQuantity, valueIn } from \"@mark1russell7/quantity\";\nimport type { HostPorts } from \"./ports.ts\";\n\n/**\n * A freshness bound reads one time in the JSON answer of an http probe. The time is epoch\n * milliseconds or an ISO 8601 text. The probe fails when the time is older than `within`, or when\n * the answer does not have it.\n */\nexport interface FreshnessBound {\n /** This JSON Pointer (RFC 6901) names the time in the answer, for example `/delivery/lastTestSendAt`. */\n readonly pointer: string;\n /** This time is the largest age that passes. */\n readonly within: Quantity;\n}\n\n/**\n * A ready probe tells when a program is ready.\n * - `http`: a GET request to the address gives the status, 200 by default. With `fresh`, the answer\n * is also JSON, and each bound of `fresh` passes. The age of a time is measured from `now`: a\n * JSON Pointer to the time of the target in the answer. Without `now`, the wall clock of the host\n * gives the time.\n * - `tcp`: a TCP connection to the port opens. The default host is `127.0.0.1`.\n * - `command`: a command gives the exit code 0.\n */\nexport type ReadyProbe =\n | {\n readonly kind: \"http\";\n readonly url: string;\n readonly status?: number | undefined;\n readonly fresh?: readonly FreshnessBound[] | undefined;\n readonly now?: string | undefined;\n }\n | { readonly kind: \"tcp\"; readonly port: number; readonly host?: string | undefined }\n | { readonly kind: \"command\"; readonly program: string; readonly args: readonly string[]; readonly cwd?: string | undefined };\n\n/** A probe result is the result of one use of a probe. A failure tells why. */\nexport type ProbeResult = { readonly ok: true } | { readonly ok: false; readonly why: string };\n\n/** This size is the largest answer that a probe with freshness bounds reads: 1 MiB. */\nexport const PROBE_BODY_LIMIT = 1_048_576;\n\nconst isPointer = (pointer: unknown): pointer is string =>\n typeof pointer === \"string\" && (pointer === \"\" || (pointer.startsWith(\"/\") && !/~[^01]|~$/.test(pointer)));\n\n/** This function gives the problems of a probe: each value that a probe cannot use. */\nexport const probeProblems = (probe: ReadyProbe): string[] => {\n if (probe.kind === \"http\") {\n const problems: string[] = [];\n if (!/^https?:\\/\\//.test(probe.url)) problems.push(`the address ${JSON.stringify(probe.url)} is not an http or https address`);\n if (probe.status !== undefined && !(Number.isInteger(probe.status) && probe.status >= 100 && probe.status <= 599))\n problems.push(`the status ${probe.status} is not an HTTP status`);\n if (probe.now !== undefined && !isPointer(probe.now)) problems.push(`the now ${JSON.stringify(probe.now)} is not a JSON Pointer`);\n if (probe.now !== undefined && probe.fresh === undefined) problems.push(\"the probe has a now, but no fresh list\");\n if (probe.fresh !== undefined && probe.fresh.length === 0) problems.push(\"the fresh list is empty\");\n for (const bound of probe.fresh ?? []) {\n if (!isPointer(bound.pointer)) problems.push(`the freshness pointer ${JSON.stringify(bound.pointer)} is not a JSON Pointer`);\n if (!(isQuantity(bound.within) && convertible(bound.within.unit, \"ms\") && valueIn(bound.within, \"ms\") >= 0))\n problems.push(`the freshness bound of ${JSON.stringify(bound.pointer)} is not a time of zero or more`);\n }\n return problems;\n }\n if (probe.kind === \"tcp\")\n return Number.isInteger(probe.port) && probe.port >= 1 && probe.port <= 65_535 ? [] : [`the port ${probe.port} is not a port from 1 to 65535`];\n if (probe.kind === \"command\") return probe.program === \"\" ? [\"the program of the command probe is empty\"] : [];\n return [`the probe kind ${JSON.stringify((probe as { kind: unknown }).kind)} is not http, tcp or command`];\n};\n\n/** This function gives the value at a JSON Pointer (RFC 6901), or undefined when the document does not have it. */\nconst pointAt = (document: unknown, pointer: string): unknown => {\n if (pointer === \"\") return document;\n let at = document;\n for (const token of pointer.slice(1).split(\"/\")) {\n const key = token.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n if (Array.isArray(at)) {\n if (!/^(0|[1-9]\\d*)$/.test(key) || Number(key) >= at.length) return undefined;\n at = at[Number(key)];\n } else if (at !== null && typeof at === \"object\" && Object.hasOwn(at, key)) {\n at = (at as Record<string, unknown>)[key];\n } else return undefined;\n }\n return at;\n};\n\n/** This function gives the time of a value in epoch milliseconds: a finite number, or an ISO 8601 text. */\nconst timeOf = (value: unknown): number | null => {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"string\") {\n const time = Date.parse(value);\n return Number.isNaN(time) ? null : time;\n }\n return null;\n};\n\n/** This function examines the JSON answer of an http probe against its freshness bounds. */\nconst freshness = (url: string, body: string, bounds: readonly FreshnessBound[], nowPointer: string | undefined, wall: number): ProbeResult => {\n let document: unknown;\n try {\n document = JSON.parse(body);\n } catch {\n return { ok: false, why: `${url} did not give JSON` };\n }\n const now = nowPointer === undefined ? wall : timeOf(pointAt(document, nowPointer));\n if (now === null) return { ok: false, why: `${url} has no time at ${nowPointer}` };\n const stale: string[] = [];\n for (const bound of bounds) {\n const time = timeOf(pointAt(document, bound.pointer));\n if (time === null) {\n stale.push(`${bound.pointer} has no time`);\n continue;\n }\n const age = Math.max(0, now - time);\n if (age > valueIn(bound.within, \"ms\"))\n stale.push(`${bound.pointer} is ${formatDuration({ value: age, unit: \"ms\" })} old, above ${formatDuration(bound.within)}`);\n }\n return stale.length === 0 ? { ok: true } : { ok: false, why: `${url}: ${stale.join(\"; \")}` };\n};\n\n/** This function uses a probe one time, in a timeout of milliseconds. It does not throw. */\nexport const probeOnce = async (probe: ReadyProbe, timeout: number, ports: HostPorts): Promise<ProbeResult> => {\n try {\n if (probe.kind === \"http\") {\n const want = probe.status ?? 200;\n if (probe.fresh !== undefined) {\n if (ports.net.httpText === undefined) return { ok: false, why: \"the net port cannot read an answer, thus it cannot examine freshness\" };\n const answer = await ports.net.httpText(probe.url, timeout, PROBE_BODY_LIMIT);\n if (answer === null) return { ok: false, why: `${probe.url} gave no answer in ${timeout} ms` };\n if (answer.status !== want) return { ok: false, why: `${probe.url} gave ${answer.status}, not ${want}` };\n if (!answer.complete) return { ok: false, why: `the answer of ${probe.url} is above ${PROBE_BODY_LIMIT} bytes` };\n return freshness(probe.url, answer.body, probe.fresh, probe.now, ports.wall());\n }\n const status = await ports.net.httpStatus(probe.url, timeout);\n if (status === want) return { ok: true };\n return { ok: false, why: status === null ? `${probe.url} gave no answer in ${timeout} ms` : `${probe.url} gave ${status}, not ${want}` };\n }\n if (probe.kind === \"tcp\") {\n const host = probe.host ?? \"127.0.0.1\";\n if (await ports.net.tcpConnect(host, probe.port, timeout)) return { ok: true };\n return { ok: false, why: `no TCP connection to ${host}:${probe.port} in ${timeout} ms` };\n }\n const result = await ports.commands.run(probe.program, probe.args, { cwd: probe.cwd, timeout });\n return result.code === 0 ? { ok: true } : { ok: false, why: `${probe.program} gave the code ${result.code}` };\n } catch (error) {\n return { ok: false, why: `the probe failed: ${error instanceof Error ? error.message : String(error)}` };\n }\n};\n"],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ import { HostPorts, ProcessMark } from "./ports.js";
2
+ /**
3
+ * This margin is the time after a recorded start in which a process can start and still be the same
4
+ * process, in milliseconds. A start time on Linux comes in ticks of 10 ms, and a step of the wall clock moves a time.
5
+ */
6
+ export declare const START_MARGIN_MS = 1e3;
7
+ /**
8
+ * This function tells if the process of a mark is alive and is the same process. Windows and Linux
9
+ * use a process ID again after a process stops. Thus a live process that started after the mark is a
10
+ * different process. A start time that the system does not give proves nothing, and the process counts as the same.
11
+ */
12
+ export declare const sameProcess: (mark: ProcessMark, ports: HostPorts) => Promise<boolean>;
13
+ /**
14
+ * A tree stop outcome tells what a tree stop did.
15
+ * - `stopped`: the stop went to the process and to each process under it.
16
+ * - `absent`: no process with the ID was alive.
17
+ * - `failed`: the process is alive and the stop did not go. The problem tells why.
18
+ */
19
+ export type TreeStopOutcome = {
20
+ readonly kind: "stopped";
21
+ } | {
22
+ readonly kind: "absent";
23
+ } | {
24
+ readonly kind: "failed";
25
+ readonly problem: string;
26
+ };
27
+ /**
28
+ * This function stops a process and each process under it, by its ID only. It does not find a process by
29
+ * its name or its command line. On Windows, it starts `taskkill /T /F /PID <pid>`. On Linux, it sends
30
+ * SIGKILL to the process group of the ID, or to the process when it leads no group. It does not throw.
31
+ */
32
+ export declare const stopTree: (pid: number, ports: HostPorts) => Promise<TreeStopOutcome>;
@@ -0,0 +1,63 @@
1
+ // src/host/processes.ts
2
+ /**
3
+ * This margin is the time after a recorded start in which a process can start and still be the same
4
+ * process, in milliseconds. A start time on Linux comes in ticks of 10 ms, and a step of the wall clock moves a time.
5
+ */
6
+ const START_MARGIN_MS = 1e3;
7
+ /**
8
+ * This function tells if the process of a mark is alive and is the same process. Windows and Linux
9
+ * use a process ID again after a process stops. Thus a live process that started after the mark is a
10
+ * different process. A start time that the system does not give proves nothing, and the process counts as the same.
11
+ */
12
+ const sameProcess = async (mark, ports) => {
13
+ if (!Number.isInteger(mark.pid) || mark.pid <= 0) return false;
14
+ if (mark.pid === ports.self.pid) return Math.abs(mark.startedAt - ports.self.startedAt) <= START_MARGIN_MS;
15
+ if (!ports.processes.alive(mark.pid)) return false;
16
+ let started;
17
+ try {
18
+ started = await ports.processes.startOf(mark.pid);
19
+ } catch {
20
+ started = null;
21
+ }
22
+ return started === null || started <= mark.startedAt + 1e3;
23
+ };
24
+ /**
25
+ * This function stops a process and each process under it, by its ID only. It does not find a process by
26
+ * its name or its command line. On Windows, it starts `taskkill /T /F /PID <pid>`. On Linux, it sends
27
+ * SIGKILL to the process group of the ID, or to the process when it leads no group. It does not throw.
28
+ */
29
+ const stopTree = async (pid, ports) => {
30
+ if (!Number.isInteger(pid) || pid <= 0) return {
31
+ kind: "failed",
32
+ problem: `${pid} is not a process ID`
33
+ };
34
+ if (pid === ports.self.pid) return {
35
+ kind: "failed",
36
+ problem: "the host does not stop its own process"
37
+ };
38
+ if (!ports.processes.alive(pid)) return { kind: "absent" };
39
+ if (ports.platform === "win32") {
40
+ const result = await ports.commands.run("taskkill", [
41
+ "/T",
42
+ "/F",
43
+ "/PID",
44
+ String(pid)
45
+ ]).catch((error) => ({
46
+ code: 127,
47
+ out: error instanceof Error ? error.message : String(error)
48
+ }));
49
+ if (result.code === 0 || !ports.processes.alive(pid)) return { kind: "stopped" };
50
+ return {
51
+ kind: "failed",
52
+ problem: `taskkill gave the code ${result.code}: ${result.out}`
53
+ };
54
+ }
55
+ if (ports.processes.signalGroup(pid, "SIGKILL") || ports.processes.signal(pid, "SIGKILL")) return { kind: "stopped" };
56
+ return ports.processes.alive(pid) ? {
57
+ kind: "failed",
58
+ problem: `the signal SIGKILL did not go to the process ${pid}`
59
+ } : { kind: "absent" };
60
+ };
61
+ export { START_MARGIN_MS, sameProcess, stopTree };
62
+
63
+ //# sourceMappingURL=processes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processes.js","names":[],"sources":["../../src/host/processes.ts"],"sourcesContent":["import type { HostPorts, ProcessMark } from \"./ports.ts\";\n\n/**\n * This margin is the time after a recorded start in which a process can start and still be the same\n * process, in milliseconds. A start time on Linux comes in ticks of 10 ms, and a step of the wall clock moves a time.\n */\nexport const START_MARGIN_MS = 1000;\n\n/**\n * This function tells if the process of a mark is alive and is the same process. Windows and Linux\n * use a process ID again after a process stops. Thus a live process that started after the mark is a\n * different process. A start time that the system does not give proves nothing, and the process counts as the same.\n */\nexport const sameProcess = async (mark: ProcessMark, ports: HostPorts): Promise<boolean> => {\n if (!Number.isInteger(mark.pid) || mark.pid <= 0) return false;\n if (mark.pid === ports.self.pid) return Math.abs(mark.startedAt - ports.self.startedAt) <= START_MARGIN_MS;\n if (!ports.processes.alive(mark.pid)) return false;\n let started: number | null;\n try {\n started = await ports.processes.startOf(mark.pid);\n } catch {\n started = null;\n }\n return started === null || started <= mark.startedAt + START_MARGIN_MS;\n};\n\n/**\n * A tree stop outcome tells what a tree stop did.\n * - `stopped`: the stop went to the process and to each process under it.\n * - `absent`: no process with the ID was alive.\n * - `failed`: the process is alive and the stop did not go. The problem tells why.\n */\nexport type TreeStopOutcome =\n | { readonly kind: \"stopped\" }\n | { readonly kind: \"absent\" }\n | { readonly kind: \"failed\"; readonly problem: string };\n\n/**\n * This function stops a process and each process under it, by its ID only. It does not find a process by\n * its name or its command line. On Windows, it starts `taskkill /T /F /PID <pid>`. On Linux, it sends\n * SIGKILL to the process group of the ID, or to the process when it leads no group. It does not throw.\n */\nexport const stopTree = async (pid: number, ports: HostPorts): Promise<TreeStopOutcome> => {\n if (!Number.isInteger(pid) || pid <= 0) return { kind: \"failed\", problem: `${pid} is not a process ID` };\n if (pid === ports.self.pid) return { kind: \"failed\", problem: \"the host does not stop its own process\" };\n if (!ports.processes.alive(pid)) return { kind: \"absent\" };\n if (ports.platform === \"win32\") {\n const result = await ports.commands\n .run(\"taskkill\", [\"/T\", \"/F\", \"/PID\", String(pid)])\n .catch((error: unknown) => ({ code: 127, out: error instanceof Error ? error.message : String(error) }));\n if (result.code === 0 || !ports.processes.alive(pid)) return { kind: \"stopped\" };\n return { kind: \"failed\", problem: `taskkill gave the code ${result.code}: ${result.out}` };\n }\n if (ports.processes.signalGroup(pid, \"SIGKILL\") || ports.processes.signal(pid, \"SIGKILL\")) return { kind: \"stopped\" };\n return ports.processes.alive(pid) ? { kind: \"failed\", problem: `the signal SIGKILL did not go to the process ${pid}` } : { kind: \"absent\" };\n};\n"],"mappings":";;;;;AAMA,MAAa,kBAAkB;;;;;;AAO/B,MAAa,cAAc,OAAO,MAAmB,UAAuC;CAC1F,IAAI,CAAC,OAAO,UAAU,KAAK,GAAG,KAAK,KAAK,OAAO,GAAG,OAAO;CACzD,IAAI,KAAK,QAAQ,MAAM,KAAK,KAAK,OAAO,KAAK,IAAI,KAAK,YAAY,MAAM,KAAK,SAAS,KAAK;CAC3F,IAAI,CAAC,MAAM,UAAU,MAAM,KAAK,GAAG,GAAG,OAAO;CAC7C,IAAI;CACJ,IAAI;EACF,UAAU,MAAM,MAAM,UAAU,QAAQ,KAAK,GAAG;CAClD,QAAQ;EACN,UAAU;CACZ;CACA,OAAO,YAAY,QAAQ,WAAW,KAAK,YAAA;AAC7C;;;;;;AAkBA,MAAa,WAAW,OAAO,KAAa,UAA+C;CACzF,IAAI,CAAC,OAAO,UAAU,GAAG,KAAK,OAAO,GAAG,OAAO;EAAE,MAAM;EAAU,SAAS,GAAG,IAAI;CAAsB;CACvG,IAAI,QAAQ,MAAM,KAAK,KAAK,OAAO;EAAE,MAAM;EAAU,SAAS;CAAyC;CACvG,IAAI,CAAC,MAAM,UAAU,MAAM,GAAG,GAAG,OAAO,EAAE,MAAM,SAAS;CACzD,IAAI,MAAM,aAAa,SAAS;EAC9B,MAAM,SAAS,MAAM,MAAM,SACxB,IAAI,YAAY;GAAC;GAAM;GAAM;GAAQ,OAAO,GAAG;EAAC,CAAC,CAAC,CAClD,OAAO,WAAoB;GAAE,MAAM;GAAK,KAAK,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAAE,EAAE;EACzG,IAAI,OAAO,SAAS,KAAK,CAAC,MAAM,UAAU,MAAM,GAAG,GAAG,OAAO,EAAE,MAAM,UAAU;EAC/E,OAAO;GAAE,MAAM;GAAU,SAAS,0BAA0B,OAAO,KAAK,IAAI,OAAO;EAAM;CAC3F;CACA,IAAI,MAAM,UAAU,YAAY,KAAK,SAAS,KAAK,MAAM,UAAU,OAAO,KAAK,SAAS,GAAG,OAAO,EAAE,MAAM,UAAU;CACpH,OAAO,MAAM,UAAU,MAAM,GAAG,IAAI;EAAE,MAAM;EAAU,SAAS,gDAAgD;CAAM,IAAI,EAAE,MAAM,SAAS;AAC5I"}
@@ -0,0 +1,84 @@
1
+ import { Quantity } from "@mark1russell7/quantity";
2
+ /**
3
+ * A service start tells when the system starts the program.
4
+ * - `logon`: at the logon of the user. The program runs until it stops.
5
+ * - `boot`: at the start of the computer, before a logon. The program runs until it stops. It runs in the background.
6
+ * - `{ daily: "HH:MM" }`: each day at that local time, as a job that runs to its end.
7
+ */
8
+ export type ServiceStart = "logon" | "boot" | {
9
+ readonly daily: string;
10
+ };
11
+ /** A restart policy tells how long the system waits before it starts a program again after it stops. */
12
+ export interface RestartPolicy {
13
+ /** This time is the wait before the next start. On Windows, the task starts again at whole minutes, 1 minute or more. */
14
+ readonly after: Quantity;
15
+ }
16
+ /** A service spec tells which program the system runs as a user service, and when. */
17
+ export interface ServiceSpec {
18
+ /** This name is the name of the Windows task and of the systemd unit: letters, digits, `.`, `_` and `-`. */
19
+ readonly name: string;
20
+ readonly description: string;
21
+ /** This path is the full path of the program, for example the path of Node. */
22
+ readonly program: string;
23
+ readonly args: readonly string[];
24
+ /** This folder is the working folder of the program. */
25
+ readonly cwd?: string | undefined;
26
+ readonly start: ServiceStart;
27
+ /** This policy starts a program at logon or at boot again after it stops. Null starts it only at its start. A daily job has no restart. */
28
+ readonly restart: RestartPolicy | null;
29
+ /**
30
+ * True runs the program when the user is not logged on. On Windows, the task gets an S4U logon, and Task Scheduler
31
+ * then refuses the task from a shell that is not elevated. On Linux, the install sets the linger of the user
32
+ * (`loginctl enable-linger`), thus the user manager of systemd starts at boot and stays after the logout.
33
+ * The default is true for a boot start, and false for the other starts.
34
+ */
35
+ readonly background?: boolean | undefined;
36
+ /** This folder keeps the files of the host, for example the task file of Windows. */
37
+ readonly stateDir: string;
38
+ /** On Windows, `hidden` starts the program through `conhost --headless`, thus no window opens. The default is `hidden`. */
39
+ readonly console?: "hidden" | "visible" | undefined;
40
+ /** This time is the most that one run can take. The default is no limit. */
41
+ readonly timeLimit?: Quantity | undefined;
42
+ }
43
+ /** These are the parts of the task of Windows that come from the system, not from the spec. */
44
+ export interface TaskContext {
45
+ /** This text is the user of the task, for example `HOST\name`. */
46
+ readonly user: string;
47
+ /** This path is the path of `conhost.exe`, for a hidden console. */
48
+ readonly conhost: string;
49
+ }
50
+ /** This function gives the problems of a service spec: each value that the task or the unit cannot use. */
51
+ export declare const serviceProblems: (spec: ServiceSpec) => string[];
52
+ /**
53
+ * This function quotes one argument for a command line of Windows, by the rules of `CommandLineToArgvW`.
54
+ * It doubles each backslash before a quote and at the end. One pass keeps the time linear.
55
+ */
56
+ export declare const windowsArg: (arg: string) => string;
57
+ /**
58
+ * This function quotes one argument for the `ExecStart` line of a systemd unit. It writes `%` as
59
+ * `%%` and `$` as `$$`, thus systemd expands no specifier and no variable. An argument with a space,
60
+ * a quote, a backslash or a `;` goes in double quotes.
61
+ */
62
+ export declare const systemdArg: (arg: string) => string;
63
+ /**
64
+ * This function gives the task file of Windows for a spec, as text. It is a pure function: the same
65
+ * spec and context give the same text. Each start boundary is in the past, thus the task does not wait for a date.
66
+ * - A start at logon gets a logon trigger, and a start at boot gets a boot trigger. With a restart, a time trigger
67
+ * also starts the task each few minutes. The task ignores a start while its program runs (`IgnoreNew`).
68
+ * - A daily start gets a calendar trigger at its time. A start that the computer missed occurs when it can (`StartWhenAvailable`).
69
+ * - A spec in the background gets an S4U logon: the task runs when the user is not logged on, and Windows keeps no password.
70
+ * Otherwise the task runs only in the session of the user (`InteractiveToken`).
71
+ * Task Scheduler reads the file as UTF-16 with a byte order mark: give the text to `utf16le`.
72
+ */
73
+ export declare const renderTaskXml: (spec: ServiceSpec, context: TaskContext) => string;
74
+ /** This function encodes a text as UTF-16, little-endian, with a byte order mark: the encoding that Task Scheduler reads. */
75
+ export declare const utf16le: (text: string) => Uint8Array;
76
+ /**
77
+ * This function gives the systemd user unit of a spec (`<name>.service`), as text. It is a pure function.
78
+ * - A start at logon or at boot is a service of the type `simple`, wanted by `default.target`. With a restart, it has `Restart=on-failure`.
79
+ * The unit is the same for the two starts: the linger of the user (`installService`) starts the user manager at boot.
80
+ * - A daily start is a service of the type `oneshot` with no `[Install]` section. Its timer (`renderSystemdTimer`) starts it.
81
+ */
82
+ export declare const renderSystemdUnit: (spec: ServiceSpec) => string;
83
+ /** This function gives the systemd timer (`<name>.timer`) of a daily spec, or null for a start at logon or at boot. It is a pure function. */
84
+ export declare const renderSystemdTimer: (spec: ServiceSpec) => string | null;