@mark1russell7/service 0.8.4 → 0.8.5

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 (77) hide show
  1. package/build/{backoff-B-jGWVDm.d.ts → backoff-QTRGfkEK.d.ts} +1 -3
  2. package/build/backoff.d.ts +1 -1
  3. package/build/backoff.js +1 -2
  4. package/build/{builder-DQj3NNNc.d.ts → builder-zO48Vgoj.d.ts} +4 -10
  5. package/build/{call-context-gR8FhbF_.d.ts → call-context-DDhcVvn5.d.ts} +1 -3
  6. package/build/channel.d.ts +0 -2
  7. package/build/channel.js +1 -2
  8. package/build/{core-Dt0HEVMq.d.ts → core-BSzt4RI2.d.ts} +5 -9
  9. package/build/{dial-CSQOl-yj.d.ts → dial-ChwIcvd4.d.ts} +2 -4
  10. package/build/grpc.d.ts +4 -14
  11. package/build/grpc.js +7 -12
  12. package/build/grpc.js.map +1 -1
  13. package/build/heartbeat.d.ts +0 -2
  14. package/build/heartbeat.js +1 -2
  15. package/build/host.d.ts +3 -23
  16. package/build/host.js +21 -33
  17. package/build/host.js.map +1 -1
  18. package/build/http-client.d.ts +4 -16
  19. package/build/http-client.js +7 -13
  20. package/build/http-client.js.map +1 -1
  21. package/build/http.d.ts +3 -9
  22. package/build/http.js +6 -10
  23. package/build/http.js.map +1 -1
  24. package/build/index.d.ts +10 -22
  25. package/build/index.js +26 -43
  26. package/build/index.js.map +1 -1
  27. package/build/{knobs-D2ClI68I.js → knobs-BJcz6m01.js} +3 -5
  28. package/build/{knobs-D2ClI68I.js.map → knobs-BJcz6m01.js.map} +1 -1
  29. package/build/{lifecycle-Br0jAjTk.d.ts → lifecycle-D0J-zwZF.d.ts} +2 -14
  30. package/build/{limiter-BTgM4aXZ.js → limiter-BwGxEWpP.js} +4 -6
  31. package/build/{limiter-BTgM4aXZ.js.map → limiter-BwGxEWpP.js.map} +1 -1
  32. package/build/{limiter-D1aluA0V.d.ts → limiter-Djw39d_S.d.ts} +3 -5
  33. package/build/limiter.d.ts +3 -3
  34. package/build/limiter.js +2 -2
  35. package/build/{logger-BN2BfPgU.d.ts → logger-B6drv9w0.d.ts} +2 -16
  36. package/build/{machine-p4lENJ86.js → machine-mIW1qgEE.js} +7 -11
  37. package/build/{machine-p4lENJ86.js.map → machine-mIW1qgEE.js.map} +1 -1
  38. package/build/mongodb.d.ts +3 -13
  39. package/build/mongodb.js +6 -11
  40. package/build/mongodb.js.map +1 -1
  41. package/build/{operation-DL5RxFds.js → operation-DF73RZOI.js} +2 -3
  42. package/build/{operation-DL5RxFds.js.map → operation-DF73RZOI.js.map} +1 -1
  43. package/build/otel.d.ts +2 -4
  44. package/build/otel.js +1 -2
  45. package/build/pg.d.ts +2 -12
  46. package/build/pg.js +6 -11
  47. package/build/pg.js.map +1 -1
  48. package/build/{policy-G-Y3Meku.js → policy-B23MY52l.js} +2 -3
  49. package/build/{policy-G-Y3Meku.js.map → policy-B23MY52l.js.map} +1 -1
  50. package/build/{policy-CwYR95Sz.d.ts → policy-CBcK2XGg.d.ts} +1 -3
  51. package/build/{ports-CSr7qWrA.d.ts → ports-DZoipkSD.d.ts} +2 -4
  52. package/build/{process-DG_im2zc.js → process-Oe0Abbsm.js} +2 -3
  53. package/build/{process-DG_im2zc.js.map → process-Oe0Abbsm.js.map} +1 -1
  54. package/build/{queue-fIkOXKVG.d.ts → queue-DXdw1vLO.d.ts} +3 -7
  55. package/build/rabbitmq.d.ts +4 -14
  56. package/build/rabbitmq.js +6 -11
  57. package/build/rabbitmq.js.map +1 -1
  58. package/build/redis.d.ts +3 -15
  59. package/build/redis.js +10 -16
  60. package/build/redis.js.map +1 -1
  61. package/build/{requests-BIq9Tr4P.js → requests-DD2ALv0_.js} +6 -9
  62. package/build/{requests-BIq9Tr4P.js.map → requests-DD2ALv0_.js.map} +1 -1
  63. package/build/{retrier-Nt6r4r6R.js → retrier-BObZq10-.js} +3 -4
  64. package/build/{retrier-Nt6r4r6R.js.map → retrier-BObZq10-.js.map} +1 -1
  65. package/build/{rules-BBRopO1e.d.ts → rules-HyFCBStQ.d.ts} +1 -5
  66. package/build/rules.d.ts +1 -1
  67. package/build/rules.js +1 -2
  68. package/build/{store-1CsNoJ8O.d.ts → store-DFwFKrsB.d.ts} +2 -4
  69. package/build/testing.d.ts +4 -14
  70. package/build/testing.js +9 -15
  71. package/build/testing.js.map +1 -1
  72. package/build/{timing-DGRi3XCI.js → timing-DZl36uXs.js} +2 -3
  73. package/build/{timing-DGRi3XCI.js.map → timing-DZl36uXs.js.map} +1 -1
  74. package/build/websocket.d.ts +3 -13
  75. package/build/websocket.js +7 -12
  76. package/build/websocket.js.map +1 -1
  77. package/package.json +4 -3
package/build/rabbitmq.js CHANGED
@@ -1,7 +1,7 @@
1
+ import { A as retrySchedule, B as zeroProblems, C as notSent, D as readyWait, F as timeProblems, G as immediate, H as NEVER, I as trackWithTimer, J as keepaliveSilent, K as keepaliveAnswered, L as wholeProblems, M as sendWithReissue, N as socketEnds, O as retryBackoff, P as stepChecks, R as withinBound, S as ms, U as WHAT, V as MANIFESTATIONS, W as firstDetector, X as unwatched, Y as kernelGiveUp, _ as inFlight, a as helloDial, b as message, c as ageProblems, d as clientProblems, f as clientRecorder, h as finiteMs, j as roundTripCheck, k as retryProblems, l as attachClient, m as dialCheck, n as closeTimer, q as keepaliveReset, r as transition, s as STARTING_POLL, t as clientKnob, u as clientBounds, w as operationTable, y as localStateCheck, z as wrapperTimerProblems } from "./machine-mIW1qgEE.js";
1
2
  import { realClock } from "./clock.js";
2
- import { A as retrySchedule, B as zeroProblems, C as notSent, D as readyWait, F as timeProblems, G as immediate, H as NEVER, I as trackWithTimer, J as keepaliveSilent, K as keepaliveAnswered, L as wholeProblems, M as sendWithReissue, N as socketEnds, O as retryBackoff, P as stepChecks, R as withinBound, S as ms, U as WHAT, V as MANIFESTATIONS, W as firstDetector, X as unwatched, Y as kernelGiveUp, _ as inFlight, a as helloDial, b as message, c as ageProblems, d as clientProblems, f as clientRecorder, h as finiteMs, j as roundTripCheck, k as retryProblems, l as attachClient, m as dialCheck, n as closeTimer, q as keepaliveReset, r as transition, s as STARTING_POLL, t as clientKnob, u as clientBounds, w as operationTable, y as localStateCheck, z as wrapperTimerProblems } from "./machine-p4lENJ86.js";
3
3
  import { quantity } from "@mark1russell7/quantity";
4
- //#region src/rabbitmq/connection.ts
4
+ // src/rabbitmq/connection.ts
5
5
  /**
6
6
  * This factory opens a connection of amqplib. It loads amqplib only when a client connects, thus a
7
7
  * service that does not use RabbitMQ does not need it. The specifier is a value, thus the package
@@ -13,8 +13,7 @@ const nodeAmqp = async ({ url, socketOptions }) => {
13
13
  if (connect === void 0) throw new Error("amqplib gives no connect function");
14
14
  return connect(url, socketOptions);
15
15
  };
16
- //#endregion
17
- //#region src/rabbitmq/meets.ts
16
+ // src/rabbitmq/meets.ts
18
17
  /**
19
18
  * This function gives the manifestations that a RabbitMQ client can meet, and the detectors of each,
20
19
  * from its knobs. The cells of R3 measured them on amqplib 2.2.0 against RabbitMQ 4.3.6:
@@ -104,8 +103,7 @@ const rabbitMeetings = (name, knobs) => {
104
103
  }
105
104
  ];
106
105
  };
107
- //#endregion
108
- //#region src/rabbitmq/client.ts
106
+ // src/rabbitmq/client.ts
109
107
  /** This function gives the problems of a spec: the knobs that the client cannot use. */
110
108
  const specProblems = (name, spec) => {
111
109
  const { knobs } = spec;
@@ -522,8 +520,7 @@ const rabbitClient = (name, spec, options = {}) => {
522
520
  problems: (description) => clientProblems(name, description, clientBounds(knobs))
523
521
  };
524
522
  };
525
- //#endregion
526
- //#region src/rabbitmq/machine.ts
523
+ // src/rabbitmq/machine.ts
527
524
  /** The states where a generation is open, and the states where the client can close. */
528
525
  const OPEN = ["ready", "blocked"];
529
526
  const SERVING = [
@@ -678,8 +675,7 @@ const RABBIT_CLIENT_MACHINE = {
678
675
  transition("end", "closing", "status.end", "end")
679
676
  ]
680
677
  };
681
- //#endregion
682
- //#region src/rabbitmq/starting.ts
678
+ // src/rabbitmq/starting.ts
683
679
  /**
684
680
  * This poll is the poll of the checks that `RABBIT_STARTING_KNOBS` fits. It is `STARTING_POLL` of
685
681
  * the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.
@@ -742,7 +738,6 @@ const RABBIT_STARTING_KNOBS = {
742
738
  unit: "s"
743
739
  }
744
740
  };
745
- //#endregion
746
741
  export { AMQP_HEADER, MANIFESTATIONS, RABBIT_CLIENT_MACHINE, RABBIT_STARTING_KNOBS, RABBIT_STARTING_POLL, STARTING_POLL, amqpDial, deliveryCount, failureOutcome, firstDetector, nodeAmqp, rabbitClient, rabbitMeetings, rabbitOptions, readyWait, retryBackoff, retryProblems, specProblems, startJudge, unwatched };
747
742
 
748
743
  //# sourceMappingURL=rabbitmq.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rabbitmq.js","names":["knob","t"],"sources":["../src/rabbitmq/connection.ts","../src/rabbitmq/meets.ts","../src/rabbitmq/client.ts","../src/rabbitmq/machine.ts","../src/rabbitmq/starting.ts"],"sourcesContent":["import type { ClientSocket, Factory } from \"../client/core.ts\";\n\n/** A message is a message of the broker, as amqplib gives it from `get`. The wrapper reads only these fields. */\nexport interface RabbitMessage {\n readonly content: Buffer;\n readonly fields: {\n readonly deliveryTag: number;\n readonly redelivered: boolean;\n readonly exchange: string;\n readonly routingKey: string;\n /** This count is the number of messages that stay on the queue after this one. */\n readonly messageCount?: number | undefined;\n };\n readonly properties: { readonly headers?: Readonly<Record<string, unknown>> | undefined; readonly [property: string]: unknown };\n}\n\n/** These are the properties of a publish that amqplib takes, for example `persistent`, `messageId` and `headers`. */\nexport type RabbitPublishOptions = Readonly<Record<string, unknown>>;\n\n/** These are the events of a channel that the wrapper listens to. */\nexport type RabbitChannelEvent = \"error\" | \"close\";\n\n/**\n * A channel is the part of a `ConfirmChannel` of amqplib 2 that the wrapper uses. A confirm channel\n * gives one result to the callback of each publish. The result is null for a `basic.ack`. It is an\n * error for a `basic.nack` and for the end of the channel.\n */\nexport interface RabbitChannel {\n /** This method writes one message. It throws when the channel is closed or closing. */\n publish(exchange: string, routingKey: string, content: Buffer, options: RabbitPublishOptions, callback: (error: Error | null) => void): boolean;\n /** This method takes one message (`basic.get`), or gives false when the queue is empty. It has no timer of its own. */\n get(queue: string, options?: { readonly noAck?: boolean | undefined }): Promise<RabbitMessage | false>;\n /** This method declares an exchange in passive mode: an RPC that changes nothing. The round-trip check uses it. */\n checkExchange(exchange: string): Promise<unknown>;\n /** This method acknowledges one message. It is one frame, with no reply. */\n ack(message: RabbitMessage): void;\n /** This method gives one message back to the broker, to the queue or to its dead-letter route. It is one frame, with no reply. */\n nack(message: RabbitMessage, allUpTo?: boolean, requeue?: boolean): void;\n close(): Promise<void>;\n on(event: RabbitChannelEvent, listener: (error?: Error) => void): unknown;\n off(event: RabbitChannelEvent, listener: (error?: Error) => void): unknown;\n}\n\n/** These are the events of a connection that the wrapper listens to. The event `blocked` gives the reason of the broker. */\nexport type RabbitConnectionEvent = \"error\" | \"close\" | \"blocked\" | \"unblocked\";\n\n/**\n * A connection is the part of a `ChannelModel` of amqplib 2 that the wrapper uses. A `ChannelModel`\n * has each part. A fake for tests has them too. Thus the package depends on no type of amqplib.\n */\nexport interface RabbitConnection {\n /** This method opens a channel with confirms (`confirm.select`). */\n createConfirmChannel(): Promise<RabbitChannel>;\n /** This method sends `connection.close`, and waits for `connection.close-ok`. Behind a black hole, it waits with no bound. */\n close(): Promise<void>;\n on(event: RabbitConnectionEvent, listener: (detail?: unknown) => void): unknown;\n off(event: RabbitConnectionEvent, listener: (detail?: unknown) => void): unknown;\n /** This field holds the socket. The join reads its addresses, and the bounded close destroys it. */\n readonly connection: { readonly stream?: ClientSocket | undefined };\n}\n\n/**\n * These are the socket options that the wrapper gives amqplib. Each one comes from the declaration.\n * At its defaults, amqplib sets no connect timeout, no keepalive and no TCP_NODELAY.\n */\nexport interface RabbitSocketOptions {\n /** This time bounds the TCP connect and the handshake. The timer stops when the connection opens. A time of 0 is no bound. */\n readonly timeout: number;\n /** The library turns Nagle off only when the caller asks. A confirm and a reply then do not wait for a delayed ACK. */\n readonly noDelay: true;\n readonly keepAlive: boolean;\n /** This time is the idle time of TCP keepalive, in milliseconds. Node truncates it to whole seconds. */\n readonly keepAliveDelay?: number | undefined;\n /** The broker shows `connection_name` in its management view and its log, thus the prober can join on it too. */\n readonly clientProperties: { readonly connection_name: string };\n}\n\n/** These are the arguments of `connect(url, socketOptions)`. The URL gives the host, the vhost, the user and the heartbeat. */\nexport interface RabbitConnectOptions {\n readonly url: string;\n readonly socketOptions: RabbitSocketOptions;\n}\n\n/** A connection factory makes one connection of amqplib from its options. A failure to open rejects. */\nexport type RabbitFactory = Factory<RabbitConnectOptions, RabbitConnection>;\n\n/**\n * This factory opens a connection of amqplib. It loads amqplib only when a client connects, thus a\n * service that does not use RabbitMQ does not need it. The specifier is a value, thus the package\n * needs no types of amqplib. The built-in recovery of amqplib stays off, because the wrapper connects again by itself.\n */\nexport const nodeAmqp: RabbitFactory = async ({ url, socketOptions }) => {\n const specifier = \"amqplib\";\n type Connect = (url: string, options: RabbitSocketOptions) => Promise<RabbitConnection>;\n const loaded = (await import(specifier)) as { readonly connect?: Connect; readonly default?: { readonly connect: Connect } };\n const connect = loaded.connect ?? loaded.default?.connect;\n if (connect === undefined) throw new Error(\"amqplib gives no connect function\");\n return connect(url, socketOptions);\n};\n","import type { Extent } from \"@mark1russell7/quantity\";\nimport { quantity } from \"@mark1russell7/quantity\";\nimport type { Detector, Meeting, Situation } from \"../client/meets.ts\";\nimport { NEVER, WHAT, immediate, keepaliveAnswered, keepaliveReset, keepaliveSilent, kernelGiveUp } from \"../client/meets.ts\";\nimport { finiteMs } from \"../client/core.ts\";\nimport type { RabbitKnobs } from \"./client.ts\";\n\n/**\n * This function gives the manifestations that a RabbitMQ client can meet, and the detectors of each,\n * from its knobs. The cells of R3 measured them on amqplib 2.2.0 against RabbitMQ 4.3.6:\n * - The heartbeat ends a silent connection 2 to 3 heartbeats after the last data. The cells measured\n * 180.009 s at 60 s, and 45.009 s at 15 s (O17). It finds a silent broker in flight and idle.\n * - A stopped broker resets each client at once, because each socket of RabbitMQ has linger 0.\n * - At `tcp_retries2 = 7`, the kernel gave up at 53.016 s.\n * - A broker with a resource alarm blocks each connection that publishes, and it still sends its heartbeats.\n */\nexport const rabbitMeetings = (name: string, knobs: RabbitKnobs): Meeting[] => {\n const beat = finiteMs(knobs.heartbeat_interval);\n const detection: Extent = beat === undefined ? NEVER : quantity((3 * beat) / 1000, \"s\");\n const heartbeat = (situation: Situation): Detector => ({\n by: \"heartbeat_detection_time\",\n within: detection,\n situation,\n effect: `the heartbeat of amqplib ends the connection, each call in flight fails as indeterminate, and ${name} connects again`,\n });\n const call: Detector = {\n by: \"request_timeout\",\n within: knobs.request_timeout,\n situation: \"in flight\",\n effect: \"the timer of the wrapper ends the call as indeterminate, and the connection stays\",\n };\n const giveUp = kernelGiveUp(knobs.retrans_giveup_time, \"each call in flight fails as indeterminate\");\n const silent = (manifestation: \"blackhole\" | \"freeze-host\"): Meeting => ({\n manifestation,\n what: WHAT[manifestation],\n detectors: [call, heartbeat(\"in flight\"), giveUp, heartbeat(\"idle\"), keepaliveSilent(knobs.keepalive_idle)],\n });\n return [\n {\n manifestation: \"rst\",\n what: WHAT.rst,\n detectors: [\n immediate(\"in flight\", \"the call fails with ECONNRESET as indeterminate, and the client connects again\"),\n {\n by: \"heartbeat_interval\",\n within: beat === undefined ? NEVER : knobs.heartbeat_interval,\n situation: \"idle\",\n effect: \"the next heartbeat frame of the client gets a reset, and the client connects again\",\n },\n keepaliveReset(knobs.keepalive_idle),\n ],\n },\n {\n manifestation: \"fin\",\n what: WHAT.fin,\n detectors: [\n immediate(\"in flight\", \"the broker closes its socket with linger 0, thus a reset arrives, and the call fails as indeterminate\"),\n immediate(\"idle\", \"the reset of the broker arrives, and the client connects again\"),\n ],\n },\n silent(\"blackhole\"),\n silent(\"freeze-host\"),\n {\n manifestation: \"freeze-process\",\n what: WHAT[\"freeze-process\"],\n detectors: [call, heartbeat(\"in flight\"), heartbeat(\"idle\"), keepaliveAnswered()],\n },\n {\n manifestation: \"app-stall\",\n what: \"the broker stops its confirms and its replies for a time, and still sends its heartbeats: a resource alarm, or a quorum queue with no leader\",\n detectors: [\n call,\n {\n by: \"connection.blocked\",\n within: quantity(0, \"s\"),\n situation: \"idle\",\n effect: \"a resource alarm blocks a connection that publishes at once. The client then refuses each call as not sent, until the unblock\",\n },\n { ...heartbeat(\"idle\"), within: NEVER, effect: \"the broker still sends its heartbeats\" },\n keepaliveAnswered(),\n ],\n },\n ];\n};\n","import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { quantity } from \"@mark1russell7/quantity\";\nimport { realClock } from \"../clock.ts\";\nimport type { Attempt, CheckOptions, Client, ClientJoin, ClientKnobs, ClientOptions, ClientSpec, ClientStep, DialFn, RetryKnobs, SendOptions, Sent } from \"../client/core.ts\";\nimport {\n ageProblems,\n attachClient,\n clientBounds,\n clientProblems,\n clientRecorder,\n dialCheck,\n finiteMs,\n inFlight,\n localStateCheck,\n message,\n ms,\n notSent,\n operationTable,\n readyWait,\n retryBackoff,\n retryProblems,\n retrySchedule,\n roundTripCheck,\n sendWithReissue,\n socketEnds,\n stepChecks,\n timeProblems,\n trackWithTimer,\n wholeProblems,\n withinBound,\n wrapperTimerProblems,\n zeroProblems,\n} from \"../client/core.ts\";\nimport type { Judge } from \"../client/dial.ts\";\nimport { helloDial } from \"../client/dial.ts\";\nimport type { Dependency } from \"../description.ts\";\nimport type { DependencyHandle } from \"../lifecycle.ts\";\nimport type { JobSettle } from \"../queue.ts\";\nimport type { RabbitChannel, RabbitConnectOptions, RabbitConnection, RabbitFactory, RabbitMessage, RabbitPublishOptions } from \"./connection.ts\";\nimport { nodeAmqp } from \"./connection.ts\";\nimport { rabbitMeetings } from \"./meets.ts\";\n\n/**\n * These are the knobs of the client, each a time, by the names of the ordering law where the law\n * has them. The runtime has no defaults, thus each knob is necessary. A bound that nobody gives is\n * \"infinite\", not zero. The constant `RABBIT_STARTING_KNOBS` gives a declaration from the cells of R3. The knobs\n * that each client has come from the core.\n */\nexport interface RabbitKnobs extends ClientKnobs, RetryKnobs {\n /**\n * This time bounds the TCP connect and the handshake (`socketOptions.timeout`). The client also\n * bounds the open of its channel with it. The timer of amqplib stops when the connection opens.\n */\n readonly connect_bound: Quantity;\n /** This time bounds each call: a publish until its confirm, and an RPC until its reply. The wrapper has this timer, because amqplib has none. */\n readonly request_timeout: Quantity;\n /**\n * This time is the heartbeat that the client asks for (`heartbeat` in the URL), in whole seconds.\n * The connection uses the smaller of this value and the value of the broker. The value \"infinite\" asks for no heartbeat.\n */\n readonly heartbeat_interval: Extent;\n /** This time is the first delay before a new try to connect. The delay doubles after each try. */\n readonly retry_base: Quantity;\n /** This time is the most that one delay can be, before its jitter. */\n readonly retry_cap: Quantity;\n /** This time is the idle time of TCP keepalive (`keepAliveDelay`), in whole seconds. The value \"infinite\" turns keepalive off, as amqplib does by default. */\n readonly keepalive_idle: Extent;\n /** The client does not replace its connection at an age, thus this knob must be \"infinite\". */\n readonly max_connection_age: Extent;\n /** This time bounds the close of the client at the shutdown: `connection.close`, then a destroy of the socket. */\n readonly close_bound: Quantity;\n}\n\n/** A seed is one more node of the cluster. The client connects to the next node after each failure, in sequence. */\nexport interface RabbitSeed {\n readonly host: string;\n readonly port: number;\n}\n\n/** A RabbitMQ client spec is the declaration of one RabbitMQ client: where it connects, and its knobs. */\nexport interface RabbitClientSpec extends ClientSpec<RabbitKnobs> {\n /** This name is the virtual host. The default of the broker is \"/\". */\n readonly vhost?: string | undefined;\n /** This name is the user. Without it, amqplib connects as the user \"guest\". */\n readonly username?: string | undefined;\n /** These nodes are more nodes of the cluster, after `host` and `port`. */\n readonly seeds?: readonly RabbitSeed[] | undefined;\n /**\n * These operations are the calls of the service, by name, with their idempotency. A message does\n * not tell if a consumer removes its duplicates. Thus the client sends again only a call that this table names.\n */\n readonly operations?: ClientSpec<RabbitKnobs>[\"operations\"];\n}\n\n/** These options make a client. Without them, it uses amqplib, the real clock, `Math.random`, and a dial with the protocol header. */\nexport interface RabbitClientOptions extends ClientOptions<RabbitFactory> {\n readonly random?: (() => number) | undefined;\n}\n\n/**\n * A join is one generation of the client: one connection and its channel, when the channel is open\n * (D1, D2). The prober joins its kernel records to the view of the broker through it.\n */\nexport interface RabbitJoin extends ClientJoin {\n /** This text is the node of the connection, as `host:port`. */\n readonly address: string;\n /** This text is the name of the connection in the broker, `local:port -> remote:port`, or null when the socket gives no addresses. */\n readonly connectionName: string | null;\n}\n\n/** A publish is one message to an exchange. A string content goes as UTF-8. */\nexport interface RabbitPublish {\n readonly exchange: string;\n readonly routingKey: string;\n readonly content: Buffer | string;\n /** These properties go to amqplib, for example `persistent`, `messageId` and `headers`. */\n readonly properties?: RabbitPublishOptions | undefined;\n}\n\n/** A delivery is one message that the client took from a queue. It stays on the channel of its generation until a settle. */\nexport interface RabbitDelivery {\n readonly message: RabbitMessage;\n /** This number is the generation of the channel that holds the message. */\n readonly generation: number;\n /** This count is the delivery of the message, 1 at the first, from `x-delivery-count` or `redelivered`. */\n readonly delivery: number;\n}\n\n/** These are the source and the settle of a queue drain on one queue: `queueDrain({ source, settle, ... })`. */\nexport interface RabbitJobs {\n /** This function takes one job, or gives null when the queue is empty. It is a `JobSource` of the drain. */\n readonly source: (signal: AbortSignal) => Promise<RabbitDelivery | null>;\n readonly settle: JobSettle<RabbitDelivery>;\n}\n\n/** A RabbitMQ client is a dependency of a service: its declaration, its handle, its checks and its calls. */\nexport interface RabbitClient extends Client<ClientStep, RabbitJoin> {\n /** This text is the state of the client, as `RABBIT_CLIENT_MACHINE` names it. */\n readonly status: string;\n /**\n * This method publishes one message, and waits for its confirm. An ack is `ok`. The client sends\n * again only an idempotent operation, one time at most, after an outcome that is not certain.\n */\n publish(operation: string, message: RabbitPublish, options?: SendOptions): Promise<Sent<void>>;\n /** This method takes one message from a queue (`basic.get`), or gives null when the queue is empty. */\n get(operation: string, queue: string, options?: SendOptions): Promise<Sent<RabbitDelivery | null>>;\n /** This method gives the source and the settle of a queue drain. The source takes each job with `get`. */\n jobs(operation: string, queue: string): RabbitJobs;\n}\n\n/** This function gives the problems of a spec: the knobs that the client cannot use. */\nexport const specProblems = (name: string, spec: RabbitClientSpec): string[] => {\n const { knobs } = spec;\n return [\n ...timeProblems(name, knobs),\n // amqplib reads a socket timeout of 0 as no bound, and a heartbeat of 0 as no heartbeat\n ...zeroProblems(name, \"amqplib\", knobs, { bounded: [\"connect_bound\"], open: [\"heartbeat_interval\", \"keepalive_idle\"] }),\n // the URL takes the heartbeat in whole seconds, and Node truncates the keepalive delay to whole seconds\n ...wholeProblems(name, knobs, { millis: [\"connect_bound\"], seconds: [\"heartbeat_interval\", \"keepalive_idle\"] }),\n ...retryProblems(name, knobs),\n // amqplib has no timer of a call\n ...wrapperTimerProblems(name, knobs, { request_timeout: \"a call\" }),\n ...ageProblems(name, knobs, \"the client does not replace its connection at an age\"),\n ];\n};\n\n/** This function gives the node of a try: `host`, then each seed, in sequence. */\nconst nodeOf = (spec: RabbitClientSpec, index: number): RabbitSeed => {\n const nodes = [{ host: spec.host, port: spec.port }, ...(spec.seeds ?? [])];\n return nodes[index % nodes.length]!;\n};\n\n/**\n * This function gives the arguments of `connect` for one node of a spec. Each timer of amqplib\n * comes from the declaration. The heartbeat goes in the URL, and \"infinite\" is 0, no heartbeat.\n */\nexport const rabbitOptions = (name: string, spec: RabbitClientSpec, index = 0): RabbitConnectOptions => {\n const { knobs } = spec;\n const node = nodeOf(spec, index);\n const user = spec.username === undefined ? \"\" : `${encodeURIComponent(spec.username)}:${encodeURIComponent(spec.password ?? \"\")}@`;\n const heartbeat = finiteMs(knobs.heartbeat_interval);\n const keepalive = finiteMs(knobs.keepalive_idle);\n return {\n url: `amqp://${user}${node.host}:${node.port}/${encodeURIComponent(spec.vhost ?? \"/\")}?heartbeat=${heartbeat === undefined ? 0 : heartbeat / 1000}`,\n socketOptions: {\n timeout: ms(knobs.connect_bound),\n noDelay: true,\n keepAlive: keepalive !== undefined,\n ...(keepalive === undefined ? {} : { keepAliveDelay: keepalive }),\n clientProperties: { connection_name: name },\n },\n };\n};\n\n/** The bytes of the protocol header of AMQP 0-9-1. A broker answers it with `connection.start`, before the authentication. */\nexport const AMQP_HEADER: Uint8Array = Uint8Array.of(0x41, 0x4d, 0x51, 0x50, 0, 0, 9, 1);\n\n/**\n * This judge reads the answer to the protocol header. A broker that takes the version sends a method\n * frame on channel 0: `connection.start`, class 10 and method 10. A broker that refuses the version\n * sends its own protocol header, and closes the socket.\n */\nexport const startJudge: Judge = (received) => {\n if (received.length < 4) return \"more\";\n if (received.toString(\"latin1\", 0, 4) === \"AMQP\") return new Error(`the broker refused the version: it answered ${received.toString(\"hex\")}`);\n if (received.length < 11) return \"more\";\n const type = received[0];\n const channel = received.readUInt16BE(1);\n const classId = received.readUInt16BE(7);\n const methodId = received.readUInt16BE(9);\n if (type !== 1 || channel !== 0) return new Error(`the answer to the header is a frame of type ${type} on channel ${channel}, not a method on channel 0`);\n return classId === 10 && methodId === 10 ? null : new Error(`the answer to the header is the method ${classId}.${methodId}, not connection.start (10.10)`);\n};\n\n/** This dial function opens a TCP connection, sends the protocol header, and waits for `connection.start`. It needs no password. */\nexport const amqpDial: DialFn = helloDial(AMQP_HEADER, startJudge);\n\n/**\n * This function gives the outcome of a failure of amqplib. The library names few classes of error.\n * Thus the wrapper reads the fields:\n * - A throw before the write (`IllegalOperationError`: the channel is closed or closing) is certain: the call did not leave the client.\n * - A reply code of the broker, from the close of the channel, is certain. The broker refused the call, or a call before it.\n * - A nack, and an end of the channel before the reply or the confirm, are not certain.\n */\nexport const failureOutcome = (error: unknown): Attempt<never> => {\n const text = message(error);\n const { name, code } = (typeof error === \"object\" && error !== null ? error : {}) as { name?: unknown; code?: unknown };\n if (name === \"IllegalOperationError\") return notSent(text);\n if (typeof code === \"number\") return { outcome: \"error\", error: `${code} ${text}`, reply: true };\n if (text === \"message nacked\")\n return { outcome: \"indeterminate\", error: \"the broker nacked the message: a queue of the route can hold it, or not\" };\n return { outcome: \"indeterminate\", error: text };\n};\n\n/** This function gives the count of deliveries of a message, 1 at the first. A quorum queue counts in `x-delivery-count`. */\nexport const deliveryCount = (message: RabbitMessage): number => {\n const count = message.properties.headers?.[\"x-delivery-count\"];\n if (typeof count === \"number\" && Number.isInteger(count) && count >= 0) return count + 1;\n return message.fields.redelivered ? 2 : 1;\n};\n\n/** The exchange of each broker: the round-trip check declares it in passive mode, which changes nothing. */\nconst CHECK_EXCHANGE = \"amq.direct\";\n\n/**\n * This function makes a RabbitMQ client, a dependency of a service over amqplib 2.\n * - It has one connection and one confirm channel, as one generation. The end of either one ends\n * the generation. The client then connects again by itself, to the next node, after a backoff.\n * - It sets each timer of amqplib from the declaration. The built-in recovery of amqplib stays off.\n * - Its call is a confirmed publish, or an RPC with a reply. Each call has a timer of the wrapper, because amqplib has none.\n * - It tells the outcome of a call in three values, and it settles each call in flight at the end of its generation (C8, C10).\n * - It records the node and the name of each connection at the open of its channel (D1).\n *\n * These parts come from the core of the clients: the outcomes, the second try, the wait for a ready client and the backoff.\n * The calls in flight, the bounded close and the checks also come from the core. This entry gives what amqplib does in its own way.\n */\nexport const rabbitClient = (name: string, spec: RabbitClientSpec, options: RabbitClientOptions = {}): RabbitClient => {\n const problems = specProblems(name, spec);\n if (problems.length > 0) throw new Error(problems.join(\"; \"));\n const { knobs } = spec;\n const clock = options.clock ?? realClock;\n const random = options.random ?? Math.random;\n const create = options.create ?? nodeAmqp;\n const dial = options.dial ?? amqpDial;\n const operations = operationTable({}, spec.operations);\n const requestTimeout = ms(knobs.request_timeout);\n const backoff = retryBackoff(knobs);\n\n let status = \"none\";\n let connection: RabbitConnection | null = null;\n let channel: RabbitChannel | null = null;\n // the generation of the channel that is open now, and the token of the open that is current\n let generation = 0;\n let token = 0;\n // the index of the node of the next try, and the tries since the last join\n let next = 0;\n const retries = retrySchedule(clock, backoff, random);\n const joins: RabbitJoin[] = [];\n const flight = inFlight();\n const readied = readyWait(clock, () => status === \"ready\");\n\n const emit = clientRecorder(options.record, clock, name);\n const record = (on: string, to: string = status, detail?: string): void => {\n const from = status;\n status = to;\n emit(from, to, on, detail);\n };\n const closing = (): boolean => status === \"closing\" || status === \"end\";\n\n /** This function closes a connection that the client does not use, in `close_bound`, then destroys its socket. */\n const retire = (c: RabbitConnection): void => {\n void withinBound(\n clock,\n ms(knobs.close_bound),\n Promise.resolve().then(() => c.close()),\n ).then((ended) => {\n if (!ended) c.connection.stream?.destroy?.();\n });\n };\n\n /** This function waits for the backoff of the next try, then opens a new generation on the next node. */\n const scheduleRetry = (): void =>\n retries.schedule(() => {\n if (closing()) return;\n record(\"retry.connect\", \"connecting\", `try ${retries.tries}, ${nodeOf(spec, next).host}:${nodeOf(spec, next).port}`);\n void open();\n });\n\n /** This function ends the generation that is open. The calls in flight learn it after the rejections of amqplib, which can hold a reply code. */\n const lose = (on: string, detail: string): void => {\n const c = connection;\n connection = null;\n channel = null;\n if (closing() || c === null) return;\n record(on, \"failing\", detail);\n clock.after(0, () => flight.settleAll(`the generation ended with the call in flight (${detail})`));\n // the end of the channel leaves its connection open: the client closes it\n if (on === \"channel.end\") retire(c);\n scheduleRetry();\n };\n\n /** This function listens to a connection from its creation. The error listener stays: in Node, an error with no listener throws. */\n const watch = (c: RabbitConnection): void => {\n c.on(\"error\", (error) => {\n if (c === connection) record(\"connection.error\", status, message(error));\n });\n c.on(\"close\", (error) => {\n if (c === connection) lose(\"connection.end\", error === undefined ? \"the connection closed\" : message(error));\n });\n c.on(\"blocked\", (reason) => {\n if (c === connection && status === \"ready\") record(\"connection.blocked\", \"blocked\", String(reason));\n });\n c.on(\"unblocked\", () => {\n if (c !== connection || status !== \"blocked\") return;\n record(\"connection.unblocked\", \"ready\");\n readied.wake();\n });\n };\n\n const join = (c: RabbitConnection, ch: RabbitChannel, address: string): void => {\n connection = c;\n channel = ch;\n retries.reset();\n const ends = socketEnds(c.connection.stream);\n generation = joins.length + 1;\n const connectionName =\n ends.localAddress === null ? null : `${ends.localAddress}:${ends.localPort ?? \"?\"} -> ${ends.remoteAddress ?? \"?\"}:${ends.remotePort ?? \"?\"}`;\n joins.push({ generation, at: clock.now(), address, connectionName, ...ends });\n ch.on(\"error\", (error) => {\n if (ch === channel) record(\"channel.error\", status, message(error));\n });\n // amqplib closes each channel of a connection that ends, then it emits the close of the connection in the same turn.\n // Thus the client waits for that turn, and an end of the connection is not recorded as an end of the channel\n ch.on(\"close\", () => {\n queueMicrotask(() => {\n if (ch === channel) lose(\"channel.end\", \"the channel closed\");\n });\n });\n record(\"join\", \"ready\", `generation ${generation}, ${address}`);\n readied.wake();\n };\n\n /**\n * This function opens one generation: a connection, then its confirm channel, in `connect_bound`.\n * A failure goes to `failing`, and the backoff starts. A connection that arrives after its bound\n * or after the close is closed at once. The promise resolves when this try ends.\n */\n const open = (): Promise<void> => {\n const mine = (token += 1);\n const index = next;\n next += 1;\n const node = nodeOf(spec, index);\n const address = `${node.host}:${node.port}`;\n let opened: RabbitConnection | null = null;\n let finish: () => void = () => {};\n const ended = new Promise<void>((resolve) => (finish = resolve));\n const stale = (): boolean => mine !== token || closing();\n const fail = (detail: string): void => {\n bound();\n finish();\n if (stale()) return;\n token += 1;\n if (opened !== null) retire(opened);\n record(\"connect.failed\", \"failing\", `${address}: ${detail}`);\n scheduleRetry();\n };\n const bound = clock.after(ms(knobs.connect_bound), () => fail(\"no open connection and channel in connect_bound\"));\n void (async () => {\n const c = await create(rabbitOptions(name, spec, index));\n opened = c;\n watch(c);\n if (stale()) {\n retire(c);\n return;\n }\n const ch = await c.createConfirmChannel();\n if (stale()) {\n retire(c);\n return;\n }\n bound();\n join(c, ch, address);\n finish();\n })().catch((error: unknown) => fail(message(error)));\n return ended;\n };\n\n /** This function gives the channel for a call, or the reason that the call does not leave the client. */\n const usable = (signal: AbortSignal | undefined): RabbitChannel | Attempt<never> => {\n if (status === \"none\") return notSent(`${name} has not connected`);\n if (status !== \"ready\" || channel === null) return notSent(`${name} is ${status}, not ready: the call did not leave the client`);\n if (signal?.aborted) return notSent(\"the caller aborted the call before it left the client\");\n return channel;\n };\n\n /** This function makes one try of a publish: the write, then the confirm, in `request_timeout`. */\n const publishAttempt = (sent: RabbitPublish, signal: AbortSignal | undefined): Promise<Attempt<void>> => {\n const ch = usable(signal);\n if (\"outcome\" in ch) return Promise.resolve(ch);\n const content = typeof sent.content === \"string\" ? Buffer.from(sent.content, \"utf8\") : sent.content;\n return trackWithTimer<void>(\n flight,\n clock,\n requestTimeout,\n signal,\n \"the caller abandoned the publish after it was written\",\n \"no confirm in request_timeout: the broker can have the message\",\n (settle) => {\n try {\n ch.publish(sent.exchange, sent.routingKey, content, sent.properties ?? {}, (error) =>\n settle(error === null ? { outcome: \"ok\", value: undefined } : failureOutcome(error)),\n );\n } catch (error) {\n settle(failureOutcome(error));\n }\n },\n );\n };\n\n /**\n * This function makes one try of an RPC on the channel, in `request_timeout`. A reply that comes\n * after the call settled goes to `late`, thus a message that nobody receives goes back to its queue.\n */\n const rpcAttempt = <T, R>(\n signal: AbortSignal | undefined,\n what: string,\n run: (ch: RabbitChannel) => Promise<R>,\n value: (reply: R) => T,\n late?: (reply: R, ch: RabbitChannel) => void,\n ): Promise<Attempt<T>> => {\n const ch = usable(signal);\n if (\"outcome\" in ch) return Promise.resolve(ch);\n let finished = false;\n return trackWithTimer<T>(\n flight,\n clock,\n requestTimeout,\n signal,\n `the caller abandoned ${what} after it was sent`,\n `no reply to ${what} in request_timeout`,\n (settle) => {\n Promise.resolve()\n .then(() => run(ch))\n .then(\n (reply) => {\n if (finished) late?.(reply, ch);\n else settle({ outcome: \"ok\", value: value(reply) });\n },\n (error: unknown) => settle(failureOutcome(error)),\n );\n },\n () => {\n finished = true;\n },\n );\n };\n\n const publish = (operation: string, sent: RabbitPublish, sendOptions: SendOptions = {}): Promise<Sent<void>> =>\n sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[operation],\n options: sendOptions,\n attempt: (signal) => publishAttempt(sent, signal),\n // the client connects again by itself: the second try waits for a ready client, in the time that is left\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, operation),\n });\n\n const get = (operation: string, queue: string, sendOptions: SendOptions = {}): Promise<Sent<RabbitDelivery | null>> => {\n const at = (): number => generation;\n return sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[operation],\n options: sendOptions,\n attempt: (signal) => {\n const held = at();\n return rpcAttempt<RabbitDelivery | null, RabbitMessage | false>(\n signal,\n \"basic.get\",\n (ch) => ch.get(queue, { noAck: false }),\n (reply) => (reply === false ? null : { message: reply, generation: held, delivery: deliveryCount(reply) }),\n // a message after the timeout or the abort: nobody holds it, thus it goes back to its queue at once\n (reply, ch) => {\n if (reply === false) return;\n try {\n ch.nack(reply, false, true);\n } catch {\n // the channel ended, and the broker puts the message back by itself\n }\n },\n );\n },\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, operation),\n });\n };\n\n /** This function gives the channel that holds a delivery. A delivery of an ended generation is back on its queue already (at least once). */\n const holder = (job: RabbitDelivery): RabbitChannel => {\n const ch = channel;\n if (ch === null || job.generation !== generation)\n throw new Error(`${name}: the channel of generation ${job.generation} ended, thus the broker put the message back on its queue`);\n return ch;\n };\n\n const jobs = (operation: string, queue: string): RabbitJobs => ({\n source: async (signal) => {\n const taken = await get(operation, queue, { signal });\n if (taken.outcome === \"ok\") return taken.value;\n throw new Error(`${name} could not take a message from ${queue}: ${taken.error}`);\n },\n settle: {\n ack: (job) => holder(job).ack(job.message),\n requeue: (job) => holder(job).nack(job.message, false, true),\n reject: (job) => holder(job).nack(job.message, false, false),\n delivery: (job) => job.delivery,\n },\n });\n\n const handle: DependencyHandle = {\n async connect(signal) {\n if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);\n record(\"status.connecting\", \"connecting\");\n // a broker that is down does not stop the startup: the client connects again in the background,\n // and its checks keep readiness tripped until it is ready (readiness is earned)\n await open();\n },\n async close() {\n if (status === \"none\" || closing()) return;\n record(\"close.request\", \"closing\");\n retries.cancel();\n // an open in flight is stale now: its connection is closed when it arrives\n token += 1;\n const c = connection;\n if (c !== null) {\n // behind a black hole, connection.close waits for close-ok with no bound: the bound destroys the socket\n if (!(await withinBound(clock, ms(knobs.close_bound), Promise.resolve().then(() => c.close())))) {\n record(\"close.bound\", \"closing\");\n record(\"close.destroy\", \"closing\");\n c.connection.stream?.destroy?.();\n }\n }\n connection = null;\n channel = null;\n flight.settleAll(\"the client closed with the call in flight\");\n record(\"status.end\", \"end\");\n },\n };\n\n const heartbeat = finiteMs(knobs.heartbeat_interval);\n const declaration: Omit<Dependency, \"name\"> = {\n system: spec.system,\n knobs: {\n connect_bound: knobs.connect_bound,\n request_timeout: knobs.request_timeout,\n heartbeat_interval: knobs.heartbeat_interval,\n // each side checks for data at each heartbeat, and ends the connection after two checks with\n // none: 2 to 3 heartbeats after the last data. The cells measured 45.009 s at 15 s\n heartbeat_detection_time: heartbeat === undefined ? knobs.heartbeat_interval : quantity((3 * heartbeat) / 1000, \"s\"),\n retry_base: knobs.retry_base,\n retry_cap: knobs.retry_cap,\n keepalive_idle: knobs.keepalive_idle,\n // each side sends a heartbeat frame each half heartbeat when it sent nothing: that refreshes an idle flow (O03)\n idle_refresh_interval: heartbeat === undefined ? knobs.keepalive_idle : quantity(heartbeat / 2000, \"s\"),\n max_connection_age: knobs.max_connection_age,\n close_bound: knobs.close_bound,\n retrans_giveup_time: knobs.retrans_giveup_time,\n },\n operations,\n };\n\n const checks = (checkOptions: CheckOptions) =>\n stepChecks<ClientStep>(name, checkOptions, {\n // the state of the client, without a round trip\n \"local-state\": localStateCheck(() => status === \"ready\"),\n // a passive declare of an exchange of each broker, on the channel of the application\n \"round-trip\": roundTripCheck((sendOptions) =>\n sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: undefined,\n options: sendOptions,\n attempt: (signal) => rpcAttempt(signal, \"a passive exchange.declare\", (ch) => ch.checkExchange(CHECK_EXCHANGE), () => undefined),\n onReissue: () => {},\n }),\n ),\n // a new connection each time, with the protocol header and no login\n dial: dialCheck(dial, spec.host, spec.port),\n });\n\n return {\n name,\n declaration,\n handle,\n meets: rabbitMeetings(name, knobs),\n get status() {\n return status;\n },\n joins,\n publish,\n get,\n jobs,\n checks,\n attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),\n problems: (description) => clientProblems(name, description, clientBounds(knobs)),\n };\n};\n","import type { Machine } from \"@mark1russell7/algebra\";\nimport { clientKnob as knob, closeTimer, transition as t } from \"../client/machine.ts\";\n\n/** The states where a generation is open, and the states where the client can close. */\nconst OPEN = [\"ready\", \"blocked\"] as const;\nconst SERVING = [\"connecting\", ...OPEN, \"failing\"] as const;\nconst LIVE = [...SERVING, \"closing\"] as const;\n\n/**\n * The RabbitMQ client of the service as a `mark1russell7.machine/1` document. It is one generation\n * at a time: one connection of amqplib and its confirm channel. The machines `amqplib` and\n * `rabbitmq-connection` of `@mark1russell7/machines` give the connection and its heartbeat. The states:\n * - `ready`: the channel is open, and the client sends each call.\n * - `blocked`: a resource alarm of the broker blocked the connection. Each call is not sent until the unblock.\n * - `failing`: no generation is open. The client tries the next node after its backoff.\n *\n * The end of the channel or of the connection ends the generation. A test records the transitions\n * of the client and replays them against this document.\n */\nexport const RABBIT_CLIENT_MACHINE: Machine = {\n format: \"mark1russell7.machine/1\",\n id: \"service.machine.rabbitmq-client\",\n title: \"The RabbitMQ client of the service, over amqplib 2\",\n layer: \"driver\",\n version: \"0.1.0\",\n sources: [{ ref: \"packages/service/src/rabbitmq (the client implements this document)\", rung: \"implemented\" }],\n states: {\n none: { initial: true, note: \"the client exists, and its first connection does not\" },\n connecting: { note: \"a connection, its handshake, and the open of its confirm channel, in connect_bound\" },\n ready: { note: \"the channel is open. A black hole stays hidden until the heartbeat or a timer of a call ends it\" },\n blocked: { note: \"a resource alarm blocked the connection: the broker does not read its socket\" },\n failing: { note: \"no generation is open. The client tries the next node after its backoff\" },\n closing: { note: \"connection.close, in close_bound, then a destroy of the socket\" },\n end: { final: true, note: \"the service closed the client\" },\n },\n events: {\n \"status.connecting\": { kind: \"local\" },\n join: { kind: \"rx\", note: \"the confirm channel is open: a new generation (D1)\" },\n \"connect.failed\": { kind: \"local\", note: \"the connection or its channel failed, or did not open in connect_bound\" },\n \"retry.connect\": { kind: \"timer\", note: \"the backoff ended: a try on the next node\" },\n \"connection.error\": { kind: \"rx\", note: \"an error event of the connection. Its close follows\" },\n \"connection.end\": { kind: \"rx\", note: \"the connection closed: a reset, a FIN, the heartbeat, or a close of the broker\" },\n \"channel.error\": { kind: \"rx\", note: \"the broker closed the channel with a reply code\" },\n \"channel.end\": { kind: \"rx\", note: \"the channel closed on a connection that stays: the client closes that connection too\" },\n \"connection.blocked\": { kind: \"rx\", note: \"connection.blocked of the broker: a resource alarm\" },\n \"connection.unblocked\": { kind: \"rx\" },\n \"command.reissue\": { kind: \"local\" },\n \"close.request\": { kind: \"local\" },\n \"close.bound\": { kind: \"timer\", note: \"connection.close got no close-ok in close_bound\" },\n \"close.destroy\": { kind: \"local\", note: \"the bound destroys a socket that a silent broker does not close\" },\n \"status.end\": { kind: \"local\" },\n },\n knobs: {\n connect_bound: knob(\"socketOptions.timeout\"),\n heartbeat_interval: knob(\"heartbeat\"),\n retry_base: knob(\"retry.base\"),\n retry_cap: knob(\"retry.cap\"),\n close_bound: knob(\"close.bound\"),\n },\n timers: {\n connect_timeout: {\n duration: { knob: \"connect_bound\", unit: \"s\" },\n arms: [\"enter:connecting\"],\n cancels: [\"join\", \"connect.failed\"],\n fires: \"connect.failed\",\n note: \"the bound of the wrapper on the connection and its channel. amqplib bounds the connect and the handshake with the same time\",\n },\n heartbeat: {\n duration: { expr: \"3 * heartbeat_interval\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"the heartbeat of amqplib ends a silent connection 2 to 3 heartbeats after the last data. Each frame that arrives starts it again\",\n },\n retry: {\n duration: { expr: \"min(retry_cap, retry_base * pow(2, fired)) + retry_base\", unit: \"s\" },\n arms: [\"connect.failed\", \"connection.end\", \"channel.end\"],\n cancels: [\"close.request\"],\n fires: \"retry.connect\",\n backoff: { resets: [\"join\"] },\n note: \"the most delay: the backoff doubles from retry_base to retry_cap, with a jitter up to retry_base\",\n },\n close: closeTimer(),\n },\n transitions: [\n t(\"connect\", \"none\", \"status.connecting\", \"connecting\"),\n t(\"join\", \"connecting\", \"join\", \"ready\"),\n t(\"connect-failed\", \"connecting\", \"connect.failed\", \"failing\", { timer: \"connect_timeout\" }),\n t(\"retry\", \"failing\", \"retry.connect\", \"connecting\", { timer: \"retry\" }),\n t(\"connection-end\", [...OPEN], \"connection.end\", \"failing\", { timer: \"heartbeat\" }),\n t(\"channel-end\", [...OPEN], \"channel.end\", \"failing\"),\n t(\"blocked\", \"ready\", \"connection.blocked\", \"blocked\"),\n t(\"unblocked\", \"blocked\", \"connection.unblocked\", \"ready\"),\n ...OPEN.map((state) => t(`connection-error-${state}`, state, \"connection.error\", state)),\n ...OPEN.map((state) => t(`channel-error-${state}`, state, \"channel.error\", state)),\n ...LIVE.map((state) => t(`reissue-${state}`, state, \"command.reissue\", state)),\n t(\"close\", [...SERVING], \"close.request\", \"closing\"),\n t(\"close-bound\", \"closing\", \"close.bound\", \"closing\", { timer: \"close\" }),\n t(\"close-destroy\", \"closing\", \"close.destroy\", \"closing\"),\n t(\"end\", \"closing\", \"status.end\", \"end\"),\n ],\n};\n","import { STARTING_POLL } from \"../client/core.ts\";\nimport type { Poll } from \"../timing.ts\";\nimport type { RabbitKnobs } from \"./client.ts\";\n\n/**\n * This poll is the poll of the checks that `RABBIT_STARTING_KNOBS` fits. It is `STARTING_POLL` of\n * the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.\n */\nexport const RABBIT_STARTING_POLL: Poll = STARTING_POLL;\n\n/**\n * These knobs are a declaration to start from, from what the cells of R3 measured on amqplib 2.2.0\n * against RabbitMQ 4.3.6. The runtime has no defaults: a service gives these knobs, or its own.\n * Each value holds the borders that the cells measured:\n * - `connect_bound` 5 s: the connect timeout of DP44. The timer stops when the connection opens.\n * Thus it does not change a fault with a call in flight. At its defaults, amqplib has no connect timeout.\n * - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13). After a loss of the leader of a quorum\n * queue, the first confirm came at 6.61 s, 6.68 s and 8.05 s (T11). A later confirm is indeterminate, not lost.\n * - `heartbeat_interval` 15 s: the heartbeat ended a silent connection 45.009 s after the last data,\n * before the kernel gave up at 53.016 s (O17). The frames each 7.5 s keep a flow through a router\n * that forgets it at 30 s (O03). At the 60 s of the broker, the heartbeat came at 180.009 s.\n * - `retry_base` 1 s: the cells connected to the next node 1 s after the end of a connection.\n * - `retry_cap` 8 s: no cell measured it. With its jitter of 1 s, the most delay is 9 s, in the slowest poll of 10 s.\n * - `keepalive_idle` \"infinite\": amqplib sets no keepalive, and the heartbeat refreshes an idle flow.\n * Linux sends no keepalive probe while data is in flight.\n * - `max_connection_age` \"infinite\": the client does not replace its connection at an age.\n * - `close_bound` 2 s: behind a black hole, `connection.close` waits for its close-ok with no bound.\n * - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.\n */\nexport const RABBIT_STARTING_KNOBS: RabbitKnobs = {\n connect_bound: { value: 5, unit: \"s\" },\n request_timeout: { value: 9.5, unit: \"s\" },\n heartbeat_interval: { value: 15, unit: \"s\" },\n retry_base: { value: 1, unit: \"s\" },\n retry_cap: { value: 8, unit: \"s\" },\n keepalive_idle: { value: \"infinite\", unit: \"s\" },\n max_connection_age: { value: \"infinite\", unit: \"s\" },\n close_bound: { value: 2, unit: \"s\" },\n retrans_giveup_time: { value: 924.6, unit: \"s\" },\n};\n"],"mappings":";;;;;;;;;AA2FA,MAAa,WAA0B,OAAO,EAAE,KAAK,oBAAoB;CAGvE,MAAM,SAAU,MAAM,OAAO;CAC7B,MAAM,UAAU,OAAO,WAA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I;CACzC,oBAAoB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC3C,YAAY;EAAE,OAAO;EAAG,MAAM;CAAI;CAClC,WAAW;EAAE,OAAO;EAAG,MAAM;CAAI;CACjC,gBAAgB;EAAE,OAAO;EAAY,MAAM;CAAI;CAC/C,oBAAoB;EAAE,OAAO;EAAY,MAAM;CAAI;CACnD,aAAa;EAAE,OAAO;EAAG,MAAM;CAAI;CACnC,qBAAqB;EAAE,OAAO;EAAO,MAAM;CAAI;AACjD"}
1
+ {"version":3,"file":"rabbitmq.js","names":["knob","t"],"sources":["../src/rabbitmq/connection.ts","../src/rabbitmq/meets.ts","../src/rabbitmq/client.ts","../src/rabbitmq/machine.ts","../src/rabbitmq/starting.ts"],"sourcesContent":["import type { ClientSocket, Factory } from \"../client/core.ts\";\n\n/** A message is a message of the broker, as amqplib gives it from `get`. The wrapper reads only these fields. */\nexport interface RabbitMessage {\n readonly content: Buffer;\n readonly fields: {\n readonly deliveryTag: number;\n readonly redelivered: boolean;\n readonly exchange: string;\n readonly routingKey: string;\n /** This count is the number of messages that stay on the queue after this one. */\n readonly messageCount?: number | undefined;\n };\n readonly properties: { readonly headers?: Readonly<Record<string, unknown>> | undefined; readonly [property: string]: unknown };\n}\n\n/** These are the properties of a publish that amqplib takes, for example `persistent`, `messageId` and `headers`. */\nexport type RabbitPublishOptions = Readonly<Record<string, unknown>>;\n\n/** These are the events of a channel that the wrapper listens to. */\nexport type RabbitChannelEvent = \"error\" | \"close\";\n\n/**\n * A channel is the part of a `ConfirmChannel` of amqplib 2 that the wrapper uses. A confirm channel\n * gives one result to the callback of each publish. The result is null for a `basic.ack`. It is an\n * error for a `basic.nack` and for the end of the channel.\n */\nexport interface RabbitChannel {\n /** This method writes one message. It throws when the channel is closed or closing. */\n publish(exchange: string, routingKey: string, content: Buffer, options: RabbitPublishOptions, callback: (error: Error | null) => void): boolean;\n /** This method takes one message (`basic.get`), or gives false when the queue is empty. It has no timer of its own. */\n get(queue: string, options?: { readonly noAck?: boolean | undefined }): Promise<RabbitMessage | false>;\n /** This method declares an exchange in passive mode: an RPC that changes nothing. The round-trip check uses it. */\n checkExchange(exchange: string): Promise<unknown>;\n /** This method acknowledges one message. It is one frame, with no reply. */\n ack(message: RabbitMessage): void;\n /** This method gives one message back to the broker, to the queue or to its dead-letter route. It is one frame, with no reply. */\n nack(message: RabbitMessage, allUpTo?: boolean, requeue?: boolean): void;\n close(): Promise<void>;\n on(event: RabbitChannelEvent, listener: (error?: Error) => void): unknown;\n off(event: RabbitChannelEvent, listener: (error?: Error) => void): unknown;\n}\n\n/** These are the events of a connection that the wrapper listens to. The event `blocked` gives the reason of the broker. */\nexport type RabbitConnectionEvent = \"error\" | \"close\" | \"blocked\" | \"unblocked\";\n\n/**\n * A connection is the part of a `ChannelModel` of amqplib 2 that the wrapper uses. A `ChannelModel`\n * has each part. A fake for tests has them too. Thus the package depends on no type of amqplib.\n */\nexport interface RabbitConnection {\n /** This method opens a channel with confirms (`confirm.select`). */\n createConfirmChannel(): Promise<RabbitChannel>;\n /** This method sends `connection.close`, and waits for `connection.close-ok`. Behind a black hole, it waits with no bound. */\n close(): Promise<void>;\n on(event: RabbitConnectionEvent, listener: (detail?: unknown) => void): unknown;\n off(event: RabbitConnectionEvent, listener: (detail?: unknown) => void): unknown;\n /** This field holds the socket. The join reads its addresses, and the bounded close destroys it. */\n readonly connection: { readonly stream?: ClientSocket | undefined };\n}\n\n/**\n * These are the socket options that the wrapper gives amqplib. Each one comes from the declaration.\n * At its defaults, amqplib sets no connect timeout, no keepalive and no TCP_NODELAY.\n */\nexport interface RabbitSocketOptions {\n /** This time bounds the TCP connect and the handshake. The timer stops when the connection opens. A time of 0 is no bound. */\n readonly timeout: number;\n /** The library turns Nagle off only when the caller asks. A confirm and a reply then do not wait for a delayed ACK. */\n readonly noDelay: true;\n readonly keepAlive: boolean;\n /** This time is the idle time of TCP keepalive, in milliseconds. Node truncates it to whole seconds. */\n readonly keepAliveDelay?: number | undefined;\n /** The broker shows `connection_name` in its management view and its log, thus the prober can join on it too. */\n readonly clientProperties: { readonly connection_name: string };\n}\n\n/** These are the arguments of `connect(url, socketOptions)`. The URL gives the host, the vhost, the user and the heartbeat. */\nexport interface RabbitConnectOptions {\n readonly url: string;\n readonly socketOptions: RabbitSocketOptions;\n}\n\n/** A connection factory makes one connection of amqplib from its options. A failure to open rejects. */\nexport type RabbitFactory = Factory<RabbitConnectOptions, RabbitConnection>;\n\n/**\n * This factory opens a connection of amqplib. It loads amqplib only when a client connects, thus a\n * service that does not use RabbitMQ does not need it. The specifier is a value, thus the package\n * needs no types of amqplib. The built-in recovery of amqplib stays off, because the wrapper connects again by itself.\n */\nexport const nodeAmqp: RabbitFactory = async ({ url, socketOptions }) => {\n const specifier = \"amqplib\";\n type Connect = (url: string, options: RabbitSocketOptions) => Promise<RabbitConnection>;\n const loaded = (await import(specifier)) as { readonly connect?: Connect; readonly default?: { readonly connect: Connect } };\n const connect = loaded.connect ?? loaded.default?.connect;\n if (connect === undefined) throw new Error(\"amqplib gives no connect function\");\n return connect(url, socketOptions);\n};\n","import type { Extent } from \"@mark1russell7/quantity\";\nimport { quantity } from \"@mark1russell7/quantity\";\nimport type { Detector, Meeting, Situation } from \"../client/meets.ts\";\nimport { NEVER, WHAT, immediate, keepaliveAnswered, keepaliveReset, keepaliveSilent, kernelGiveUp } from \"../client/meets.ts\";\nimport { finiteMs } from \"../client/core.ts\";\nimport type { RabbitKnobs } from \"./client.ts\";\n\n/**\n * This function gives the manifestations that a RabbitMQ client can meet, and the detectors of each,\n * from its knobs. The cells of R3 measured them on amqplib 2.2.0 against RabbitMQ 4.3.6:\n * - The heartbeat ends a silent connection 2 to 3 heartbeats after the last data. The cells measured\n * 180.009 s at 60 s, and 45.009 s at 15 s (O17). It finds a silent broker in flight and idle.\n * - A stopped broker resets each client at once, because each socket of RabbitMQ has linger 0.\n * - At `tcp_retries2 = 7`, the kernel gave up at 53.016 s.\n * - A broker with a resource alarm blocks each connection that publishes, and it still sends its heartbeats.\n */\nexport const rabbitMeetings = (name: string, knobs: RabbitKnobs): Meeting[] => {\n const beat = finiteMs(knobs.heartbeat_interval);\n const detection: Extent = beat === undefined ? NEVER : quantity((3 * beat) / 1000, \"s\");\n const heartbeat = (situation: Situation): Detector => ({\n by: \"heartbeat_detection_time\",\n within: detection,\n situation,\n effect: `the heartbeat of amqplib ends the connection, each call in flight fails as indeterminate, and ${name} connects again`,\n });\n const call: Detector = {\n by: \"request_timeout\",\n within: knobs.request_timeout,\n situation: \"in flight\",\n effect: \"the timer of the wrapper ends the call as indeterminate, and the connection stays\",\n };\n const giveUp = kernelGiveUp(knobs.retrans_giveup_time, \"each call in flight fails as indeterminate\");\n const silent = (manifestation: \"blackhole\" | \"freeze-host\"): Meeting => ({\n manifestation,\n what: WHAT[manifestation],\n detectors: [call, heartbeat(\"in flight\"), giveUp, heartbeat(\"idle\"), keepaliveSilent(knobs.keepalive_idle)],\n });\n return [\n {\n manifestation: \"rst\",\n what: WHAT.rst,\n detectors: [\n immediate(\"in flight\", \"the call fails with ECONNRESET as indeterminate, and the client connects again\"),\n {\n by: \"heartbeat_interval\",\n within: beat === undefined ? NEVER : knobs.heartbeat_interval,\n situation: \"idle\",\n effect: \"the next heartbeat frame of the client gets a reset, and the client connects again\",\n },\n keepaliveReset(knobs.keepalive_idle),\n ],\n },\n {\n manifestation: \"fin\",\n what: WHAT.fin,\n detectors: [\n immediate(\"in flight\", \"the broker closes its socket with linger 0, thus a reset arrives, and the call fails as indeterminate\"),\n immediate(\"idle\", \"the reset of the broker arrives, and the client connects again\"),\n ],\n },\n silent(\"blackhole\"),\n silent(\"freeze-host\"),\n {\n manifestation: \"freeze-process\",\n what: WHAT[\"freeze-process\"],\n detectors: [call, heartbeat(\"in flight\"), heartbeat(\"idle\"), keepaliveAnswered()],\n },\n {\n manifestation: \"app-stall\",\n what: \"the broker stops its confirms and its replies for a time, and still sends its heartbeats: a resource alarm, or a quorum queue with no leader\",\n detectors: [\n call,\n {\n by: \"connection.blocked\",\n within: quantity(0, \"s\"),\n situation: \"idle\",\n effect: \"a resource alarm blocks a connection that publishes at once. The client then refuses each call as not sent, until the unblock\",\n },\n { ...heartbeat(\"idle\"), within: NEVER, effect: \"the broker still sends its heartbeats\" },\n keepaliveAnswered(),\n ],\n },\n ];\n};\n","import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { quantity } from \"@mark1russell7/quantity\";\nimport { realClock } from \"../clock.ts\";\nimport type { Attempt, CheckOptions, Client, ClientJoin, ClientKnobs, ClientOptions, ClientSpec, ClientStep, DialFn, RetryKnobs, SendOptions, Sent } from \"../client/core.ts\";\nimport {\n ageProblems,\n attachClient,\n clientBounds,\n clientProblems,\n clientRecorder,\n dialCheck,\n finiteMs,\n inFlight,\n localStateCheck,\n message,\n ms,\n notSent,\n operationTable,\n readyWait,\n retryBackoff,\n retryProblems,\n retrySchedule,\n roundTripCheck,\n sendWithReissue,\n socketEnds,\n stepChecks,\n timeProblems,\n trackWithTimer,\n wholeProblems,\n withinBound,\n wrapperTimerProblems,\n zeroProblems,\n} from \"../client/core.ts\";\nimport type { Judge } from \"../client/dial.ts\";\nimport { helloDial } from \"../client/dial.ts\";\nimport type { Dependency } from \"../description.ts\";\nimport type { DependencyHandle } from \"../lifecycle.ts\";\nimport type { JobSettle } from \"../queue.ts\";\nimport type { RabbitChannel, RabbitConnectOptions, RabbitConnection, RabbitFactory, RabbitMessage, RabbitPublishOptions } from \"./connection.ts\";\nimport { nodeAmqp } from \"./connection.ts\";\nimport { rabbitMeetings } from \"./meets.ts\";\n\n/**\n * These are the knobs of the client, each a time, by the names of the ordering law where the law\n * has them. The runtime has no defaults, thus each knob is necessary. A bound that nobody gives is\n * \"infinite\", not zero. The constant `RABBIT_STARTING_KNOBS` gives a declaration from the cells of R3. The knobs\n * that each client has come from the core.\n */\nexport interface RabbitKnobs extends ClientKnobs, RetryKnobs {\n /**\n * This time bounds the TCP connect and the handshake (`socketOptions.timeout`). The client also\n * bounds the open of its channel with it. The timer of amqplib stops when the connection opens.\n */\n readonly connect_bound: Quantity;\n /** This time bounds each call: a publish until its confirm, and an RPC until its reply. The wrapper has this timer, because amqplib has none. */\n readonly request_timeout: Quantity;\n /**\n * This time is the heartbeat that the client asks for (`heartbeat` in the URL), in whole seconds.\n * The connection uses the smaller of this value and the value of the broker. The value \"infinite\" asks for no heartbeat.\n */\n readonly heartbeat_interval: Extent;\n /** This time is the first delay before a new try to connect. The delay doubles after each try. */\n readonly retry_base: Quantity;\n /** This time is the most that one delay can be, before its jitter. */\n readonly retry_cap: Quantity;\n /** This time is the idle time of TCP keepalive (`keepAliveDelay`), in whole seconds. The value \"infinite\" turns keepalive off, as amqplib does by default. */\n readonly keepalive_idle: Extent;\n /** The client does not replace its connection at an age, thus this knob must be \"infinite\". */\n readonly max_connection_age: Extent;\n /** This time bounds the close of the client at the shutdown: `connection.close`, then a destroy of the socket. */\n readonly close_bound: Quantity;\n}\n\n/** A seed is one more node of the cluster. The client connects to the next node after each failure, in sequence. */\nexport interface RabbitSeed {\n readonly host: string;\n readonly port: number;\n}\n\n/** A RabbitMQ client spec is the declaration of one RabbitMQ client: where it connects, and its knobs. */\nexport interface RabbitClientSpec extends ClientSpec<RabbitKnobs> {\n /** This name is the virtual host. The default of the broker is \"/\". */\n readonly vhost?: string | undefined;\n /** This name is the user. Without it, amqplib connects as the user \"guest\". */\n readonly username?: string | undefined;\n /** These nodes are more nodes of the cluster, after `host` and `port`. */\n readonly seeds?: readonly RabbitSeed[] | undefined;\n /**\n * These operations are the calls of the service, by name, with their idempotency. A message does\n * not tell if a consumer removes its duplicates. Thus the client sends again only a call that this table names.\n */\n readonly operations?: ClientSpec<RabbitKnobs>[\"operations\"];\n}\n\n/** These options make a client. Without them, it uses amqplib, the real clock, `Math.random`, and a dial with the protocol header. */\nexport interface RabbitClientOptions extends ClientOptions<RabbitFactory> {\n readonly random?: (() => number) | undefined;\n}\n\n/**\n * A join is one generation of the client: one connection and its channel, when the channel is open\n * (D1, D2). The prober joins its kernel records to the view of the broker through it.\n */\nexport interface RabbitJoin extends ClientJoin {\n /** This text is the node of the connection, as `host:port`. */\n readonly address: string;\n /** This text is the name of the connection in the broker, `local:port -> remote:port`, or null when the socket gives no addresses. */\n readonly connectionName: string | null;\n}\n\n/** A publish is one message to an exchange. A string content goes as UTF-8. */\nexport interface RabbitPublish {\n readonly exchange: string;\n readonly routingKey: string;\n readonly content: Buffer | string;\n /** These properties go to amqplib, for example `persistent`, `messageId` and `headers`. */\n readonly properties?: RabbitPublishOptions | undefined;\n}\n\n/** A delivery is one message that the client took from a queue. It stays on the channel of its generation until a settle. */\nexport interface RabbitDelivery {\n readonly message: RabbitMessage;\n /** This number is the generation of the channel that holds the message. */\n readonly generation: number;\n /** This count is the delivery of the message, 1 at the first, from `x-delivery-count` or `redelivered`. */\n readonly delivery: number;\n}\n\n/** These are the source and the settle of a queue drain on one queue: `queueDrain({ source, settle, ... })`. */\nexport interface RabbitJobs {\n /** This function takes one job, or gives null when the queue is empty. It is a `JobSource` of the drain. */\n readonly source: (signal: AbortSignal) => Promise<RabbitDelivery | null>;\n readonly settle: JobSettle<RabbitDelivery>;\n}\n\n/** A RabbitMQ client is a dependency of a service: its declaration, its handle, its checks and its calls. */\nexport interface RabbitClient extends Client<ClientStep, RabbitJoin> {\n /** This text is the state of the client, as `RABBIT_CLIENT_MACHINE` names it. */\n readonly status: string;\n /**\n * This method publishes one message, and waits for its confirm. An ack is `ok`. The client sends\n * again only an idempotent operation, one time at most, after an outcome that is not certain.\n */\n publish(operation: string, message: RabbitPublish, options?: SendOptions): Promise<Sent<void>>;\n /** This method takes one message from a queue (`basic.get`), or gives null when the queue is empty. */\n get(operation: string, queue: string, options?: SendOptions): Promise<Sent<RabbitDelivery | null>>;\n /** This method gives the source and the settle of a queue drain. The source takes each job with `get`. */\n jobs(operation: string, queue: string): RabbitJobs;\n}\n\n/** This function gives the problems of a spec: the knobs that the client cannot use. */\nexport const specProblems = (name: string, spec: RabbitClientSpec): string[] => {\n const { knobs } = spec;\n return [\n ...timeProblems(name, knobs),\n // amqplib reads a socket timeout of 0 as no bound, and a heartbeat of 0 as no heartbeat\n ...zeroProblems(name, \"amqplib\", knobs, { bounded: [\"connect_bound\"], open: [\"heartbeat_interval\", \"keepalive_idle\"] }),\n // the URL takes the heartbeat in whole seconds, and Node truncates the keepalive delay to whole seconds\n ...wholeProblems(name, knobs, { millis: [\"connect_bound\"], seconds: [\"heartbeat_interval\", \"keepalive_idle\"] }),\n ...retryProblems(name, knobs),\n // amqplib has no timer of a call\n ...wrapperTimerProblems(name, knobs, { request_timeout: \"a call\" }),\n ...ageProblems(name, knobs, \"the client does not replace its connection at an age\"),\n ];\n};\n\n/** This function gives the node of a try: `host`, then each seed, in sequence. */\nconst nodeOf = (spec: RabbitClientSpec, index: number): RabbitSeed => {\n const nodes = [{ host: spec.host, port: spec.port }, ...(spec.seeds ?? [])];\n return nodes[index % nodes.length]!;\n};\n\n/**\n * This function gives the arguments of `connect` for one node of a spec. Each timer of amqplib\n * comes from the declaration. The heartbeat goes in the URL, and \"infinite\" is 0, no heartbeat.\n */\nexport const rabbitOptions = (name: string, spec: RabbitClientSpec, index = 0): RabbitConnectOptions => {\n const { knobs } = spec;\n const node = nodeOf(spec, index);\n const user = spec.username === undefined ? \"\" : `${encodeURIComponent(spec.username)}:${encodeURIComponent(spec.password ?? \"\")}@`;\n const heartbeat = finiteMs(knobs.heartbeat_interval);\n const keepalive = finiteMs(knobs.keepalive_idle);\n return {\n url: `amqp://${user}${node.host}:${node.port}/${encodeURIComponent(spec.vhost ?? \"/\")}?heartbeat=${heartbeat === undefined ? 0 : heartbeat / 1000}`,\n socketOptions: {\n timeout: ms(knobs.connect_bound),\n noDelay: true,\n keepAlive: keepalive !== undefined,\n ...(keepalive === undefined ? {} : { keepAliveDelay: keepalive }),\n clientProperties: { connection_name: name },\n },\n };\n};\n\n/** The bytes of the protocol header of AMQP 0-9-1. A broker answers it with `connection.start`, before the authentication. */\nexport const AMQP_HEADER: Uint8Array = Uint8Array.of(0x41, 0x4d, 0x51, 0x50, 0, 0, 9, 1);\n\n/**\n * This judge reads the answer to the protocol header. A broker that takes the version sends a method\n * frame on channel 0: `connection.start`, class 10 and method 10. A broker that refuses the version\n * sends its own protocol header, and closes the socket.\n */\nexport const startJudge: Judge = (received) => {\n if (received.length < 4) return \"more\";\n if (received.toString(\"latin1\", 0, 4) === \"AMQP\") return new Error(`the broker refused the version: it answered ${received.toString(\"hex\")}`);\n if (received.length < 11) return \"more\";\n const type = received[0];\n const channel = received.readUInt16BE(1);\n const classId = received.readUInt16BE(7);\n const methodId = received.readUInt16BE(9);\n if (type !== 1 || channel !== 0) return new Error(`the answer to the header is a frame of type ${type} on channel ${channel}, not a method on channel 0`);\n return classId === 10 && methodId === 10 ? null : new Error(`the answer to the header is the method ${classId}.${methodId}, not connection.start (10.10)`);\n};\n\n/** This dial function opens a TCP connection, sends the protocol header, and waits for `connection.start`. It needs no password. */\nexport const amqpDial: DialFn = helloDial(AMQP_HEADER, startJudge);\n\n/**\n * This function gives the outcome of a failure of amqplib. The library names few classes of error.\n * Thus the wrapper reads the fields:\n * - A throw before the write (`IllegalOperationError`: the channel is closed or closing) is certain: the call did not leave the client.\n * - A reply code of the broker, from the close of the channel, is certain. The broker refused the call, or a call before it.\n * - A nack, and an end of the channel before the reply or the confirm, are not certain.\n */\nexport const failureOutcome = (error: unknown): Attempt<never> => {\n const text = message(error);\n const { name, code } = (typeof error === \"object\" && error !== null ? error : {}) as { name?: unknown; code?: unknown };\n if (name === \"IllegalOperationError\") return notSent(text);\n if (typeof code === \"number\") return { outcome: \"error\", error: `${code} ${text}`, reply: true };\n if (text === \"message nacked\")\n return { outcome: \"indeterminate\", error: \"the broker nacked the message: a queue of the route can hold it, or not\" };\n return { outcome: \"indeterminate\", error: text };\n};\n\n/** This function gives the count of deliveries of a message, 1 at the first. A quorum queue counts in `x-delivery-count`. */\nexport const deliveryCount = (message: RabbitMessage): number => {\n const count = message.properties.headers?.[\"x-delivery-count\"];\n if (typeof count === \"number\" && Number.isInteger(count) && count >= 0) return count + 1;\n return message.fields.redelivered ? 2 : 1;\n};\n\n/** The exchange of each broker: the round-trip check declares it in passive mode, which changes nothing. */\nconst CHECK_EXCHANGE = \"amq.direct\";\n\n/**\n * This function makes a RabbitMQ client, a dependency of a service over amqplib 2.\n * - It has one connection and one confirm channel, as one generation. The end of either one ends\n * the generation. The client then connects again by itself, to the next node, after a backoff.\n * - It sets each timer of amqplib from the declaration. The built-in recovery of amqplib stays off.\n * - Its call is a confirmed publish, or an RPC with a reply. Each call has a timer of the wrapper, because amqplib has none.\n * - It tells the outcome of a call in three values, and it settles each call in flight at the end of its generation (C8, C10).\n * - It records the node and the name of each connection at the open of its channel (D1).\n *\n * These parts come from the core of the clients: the outcomes, the second try, the wait for a ready client and the backoff.\n * The calls in flight, the bounded close and the checks also come from the core. This entry gives what amqplib does in its own way.\n */\nexport const rabbitClient = (name: string, spec: RabbitClientSpec, options: RabbitClientOptions = {}): RabbitClient => {\n const problems = specProblems(name, spec);\n if (problems.length > 0) throw new Error(problems.join(\"; \"));\n const { knobs } = spec;\n const clock = options.clock ?? realClock;\n const random = options.random ?? Math.random;\n const create = options.create ?? nodeAmqp;\n const dial = options.dial ?? amqpDial;\n const operations = operationTable({}, spec.operations);\n const requestTimeout = ms(knobs.request_timeout);\n const backoff = retryBackoff(knobs);\n\n let status = \"none\";\n let connection: RabbitConnection | null = null;\n let channel: RabbitChannel | null = null;\n // the generation of the channel that is open now, and the token of the open that is current\n let generation = 0;\n let token = 0;\n // the index of the node of the next try, and the tries since the last join\n let next = 0;\n const retries = retrySchedule(clock, backoff, random);\n const joins: RabbitJoin[] = [];\n const flight = inFlight();\n const readied = readyWait(clock, () => status === \"ready\");\n\n const emit = clientRecorder(options.record, clock, name);\n const record = (on: string, to: string = status, detail?: string): void => {\n const from = status;\n status = to;\n emit(from, to, on, detail);\n };\n const closing = (): boolean => status === \"closing\" || status === \"end\";\n\n /** This function closes a connection that the client does not use, in `close_bound`, then destroys its socket. */\n const retire = (c: RabbitConnection): void => {\n void withinBound(\n clock,\n ms(knobs.close_bound),\n Promise.resolve().then(() => c.close()),\n ).then((ended) => {\n if (!ended) c.connection.stream?.destroy?.();\n });\n };\n\n /** This function waits for the backoff of the next try, then opens a new generation on the next node. */\n const scheduleRetry = (): void =>\n retries.schedule(() => {\n if (closing()) return;\n record(\"retry.connect\", \"connecting\", `try ${retries.tries}, ${nodeOf(spec, next).host}:${nodeOf(spec, next).port}`);\n void open();\n });\n\n /** This function ends the generation that is open. The calls in flight learn it after the rejections of amqplib, which can hold a reply code. */\n const lose = (on: string, detail: string): void => {\n const c = connection;\n connection = null;\n channel = null;\n if (closing() || c === null) return;\n record(on, \"failing\", detail);\n clock.after(0, () => flight.settleAll(`the generation ended with the call in flight (${detail})`));\n // the end of the channel leaves its connection open: the client closes it\n if (on === \"channel.end\") retire(c);\n scheduleRetry();\n };\n\n /** This function listens to a connection from its creation. The error listener stays: in Node, an error with no listener throws. */\n const watch = (c: RabbitConnection): void => {\n c.on(\"error\", (error) => {\n if (c === connection) record(\"connection.error\", status, message(error));\n });\n c.on(\"close\", (error) => {\n if (c === connection) lose(\"connection.end\", error === undefined ? \"the connection closed\" : message(error));\n });\n c.on(\"blocked\", (reason) => {\n if (c === connection && status === \"ready\") record(\"connection.blocked\", \"blocked\", String(reason));\n });\n c.on(\"unblocked\", () => {\n if (c !== connection || status !== \"blocked\") return;\n record(\"connection.unblocked\", \"ready\");\n readied.wake();\n });\n };\n\n const join = (c: RabbitConnection, ch: RabbitChannel, address: string): void => {\n connection = c;\n channel = ch;\n retries.reset();\n const ends = socketEnds(c.connection.stream);\n generation = joins.length + 1;\n const connectionName =\n ends.localAddress === null ? null : `${ends.localAddress}:${ends.localPort ?? \"?\"} -> ${ends.remoteAddress ?? \"?\"}:${ends.remotePort ?? \"?\"}`;\n joins.push({ generation, at: clock.now(), address, connectionName, ...ends });\n ch.on(\"error\", (error) => {\n if (ch === channel) record(\"channel.error\", status, message(error));\n });\n // amqplib closes each channel of a connection that ends, then it emits the close of the connection in the same turn.\n // Thus the client waits for that turn, and an end of the connection is not recorded as an end of the channel\n ch.on(\"close\", () => {\n queueMicrotask(() => {\n if (ch === channel) lose(\"channel.end\", \"the channel closed\");\n });\n });\n record(\"join\", \"ready\", `generation ${generation}, ${address}`);\n readied.wake();\n };\n\n /**\n * This function opens one generation: a connection, then its confirm channel, in `connect_bound`.\n * A failure goes to `failing`, and the backoff starts. A connection that arrives after its bound\n * or after the close is closed at once. The promise resolves when this try ends.\n */\n const open = (): Promise<void> => {\n const mine = (token += 1);\n const index = next;\n next += 1;\n const node = nodeOf(spec, index);\n const address = `${node.host}:${node.port}`;\n let opened: RabbitConnection | null = null;\n let finish: () => void = () => {};\n const ended = new Promise<void>((resolve) => (finish = resolve));\n const stale = (): boolean => mine !== token || closing();\n const fail = (detail: string): void => {\n bound();\n finish();\n if (stale()) return;\n token += 1;\n if (opened !== null) retire(opened);\n record(\"connect.failed\", \"failing\", `${address}: ${detail}`);\n scheduleRetry();\n };\n const bound = clock.after(ms(knobs.connect_bound), () => fail(\"no open connection and channel in connect_bound\"));\n void (async () => {\n const c = await create(rabbitOptions(name, spec, index));\n opened = c;\n watch(c);\n if (stale()) {\n retire(c);\n return;\n }\n const ch = await c.createConfirmChannel();\n if (stale()) {\n retire(c);\n return;\n }\n bound();\n join(c, ch, address);\n finish();\n })().catch((error: unknown) => fail(message(error)));\n return ended;\n };\n\n /** This function gives the channel for a call, or the reason that the call does not leave the client. */\n const usable = (signal: AbortSignal | undefined): RabbitChannel | Attempt<never> => {\n if (status === \"none\") return notSent(`${name} has not connected`);\n if (status !== \"ready\" || channel === null) return notSent(`${name} is ${status}, not ready: the call did not leave the client`);\n if (signal?.aborted) return notSent(\"the caller aborted the call before it left the client\");\n return channel;\n };\n\n /** This function makes one try of a publish: the write, then the confirm, in `request_timeout`. */\n const publishAttempt = (sent: RabbitPublish, signal: AbortSignal | undefined): Promise<Attempt<void>> => {\n const ch = usable(signal);\n if (\"outcome\" in ch) return Promise.resolve(ch);\n const content = typeof sent.content === \"string\" ? Buffer.from(sent.content, \"utf8\") : sent.content;\n return trackWithTimer<void>(\n flight,\n clock,\n requestTimeout,\n signal,\n \"the caller abandoned the publish after it was written\",\n \"no confirm in request_timeout: the broker can have the message\",\n (settle) => {\n try {\n ch.publish(sent.exchange, sent.routingKey, content, sent.properties ?? {}, (error) =>\n settle(error === null ? { outcome: \"ok\", value: undefined } : failureOutcome(error)),\n );\n } catch (error) {\n settle(failureOutcome(error));\n }\n },\n );\n };\n\n /**\n * This function makes one try of an RPC on the channel, in `request_timeout`. A reply that comes\n * after the call settled goes to `late`, thus a message that nobody receives goes back to its queue.\n */\n const rpcAttempt = <T, R>(\n signal: AbortSignal | undefined,\n what: string,\n run: (ch: RabbitChannel) => Promise<R>,\n value: (reply: R) => T,\n late?: (reply: R, ch: RabbitChannel) => void,\n ): Promise<Attempt<T>> => {\n const ch = usable(signal);\n if (\"outcome\" in ch) return Promise.resolve(ch);\n let finished = false;\n return trackWithTimer<T>(\n flight,\n clock,\n requestTimeout,\n signal,\n `the caller abandoned ${what} after it was sent`,\n `no reply to ${what} in request_timeout`,\n (settle) => {\n Promise.resolve()\n .then(() => run(ch))\n .then(\n (reply) => {\n if (finished) late?.(reply, ch);\n else settle({ outcome: \"ok\", value: value(reply) });\n },\n (error: unknown) => settle(failureOutcome(error)),\n );\n },\n () => {\n finished = true;\n },\n );\n };\n\n const publish = (operation: string, sent: RabbitPublish, sendOptions: SendOptions = {}): Promise<Sent<void>> =>\n sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[operation],\n options: sendOptions,\n attempt: (signal) => publishAttempt(sent, signal),\n // the client connects again by itself: the second try waits for a ready client, in the time that is left\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, operation),\n });\n\n const get = (operation: string, queue: string, sendOptions: SendOptions = {}): Promise<Sent<RabbitDelivery | null>> => {\n const at = (): number => generation;\n return sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[operation],\n options: sendOptions,\n attempt: (signal) => {\n const held = at();\n return rpcAttempt<RabbitDelivery | null, RabbitMessage | false>(\n signal,\n \"basic.get\",\n (ch) => ch.get(queue, { noAck: false }),\n (reply) => (reply === false ? null : { message: reply, generation: held, delivery: deliveryCount(reply) }),\n // a message after the timeout or the abort: nobody holds it, thus it goes back to its queue at once\n (reply, ch) => {\n if (reply === false) return;\n try {\n ch.nack(reply, false, true);\n } catch {\n // the channel ended, and the broker puts the message back by itself\n }\n },\n );\n },\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, operation),\n });\n };\n\n /** This function gives the channel that holds a delivery. A delivery of an ended generation is back on its queue already (at least once). */\n const holder = (job: RabbitDelivery): RabbitChannel => {\n const ch = channel;\n if (ch === null || job.generation !== generation)\n throw new Error(`${name}: the channel of generation ${job.generation} ended, thus the broker put the message back on its queue`);\n return ch;\n };\n\n const jobs = (operation: string, queue: string): RabbitJobs => ({\n source: async (signal) => {\n const taken = await get(operation, queue, { signal });\n if (taken.outcome === \"ok\") return taken.value;\n throw new Error(`${name} could not take a message from ${queue}: ${taken.error}`);\n },\n settle: {\n ack: (job) => holder(job).ack(job.message),\n requeue: (job) => holder(job).nack(job.message, false, true),\n reject: (job) => holder(job).nack(job.message, false, false),\n delivery: (job) => job.delivery,\n },\n });\n\n const handle: DependencyHandle = {\n async connect(signal) {\n if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);\n record(\"status.connecting\", \"connecting\");\n // a broker that is down does not stop the startup: the client connects again in the background,\n // and its checks keep readiness tripped until it is ready (readiness is earned)\n await open();\n },\n async close() {\n if (status === \"none\" || closing()) return;\n record(\"close.request\", \"closing\");\n retries.cancel();\n // an open in flight is stale now: its connection is closed when it arrives\n token += 1;\n const c = connection;\n if (c !== null) {\n // behind a black hole, connection.close waits for close-ok with no bound: the bound destroys the socket\n if (!(await withinBound(clock, ms(knobs.close_bound), Promise.resolve().then(() => c.close())))) {\n record(\"close.bound\", \"closing\");\n record(\"close.destroy\", \"closing\");\n c.connection.stream?.destroy?.();\n }\n }\n connection = null;\n channel = null;\n flight.settleAll(\"the client closed with the call in flight\");\n record(\"status.end\", \"end\");\n },\n };\n\n const heartbeat = finiteMs(knobs.heartbeat_interval);\n const declaration: Omit<Dependency, \"name\"> = {\n system: spec.system,\n knobs: {\n connect_bound: knobs.connect_bound,\n request_timeout: knobs.request_timeout,\n heartbeat_interval: knobs.heartbeat_interval,\n // each side checks for data at each heartbeat, and ends the connection after two checks with\n // none: 2 to 3 heartbeats after the last data. The cells measured 45.009 s at 15 s\n heartbeat_detection_time: heartbeat === undefined ? knobs.heartbeat_interval : quantity((3 * heartbeat) / 1000, \"s\"),\n retry_base: knobs.retry_base,\n retry_cap: knobs.retry_cap,\n keepalive_idle: knobs.keepalive_idle,\n // each side sends a heartbeat frame each half heartbeat when it sent nothing: that refreshes an idle flow (O03)\n idle_refresh_interval: heartbeat === undefined ? knobs.keepalive_idle : quantity(heartbeat / 2000, \"s\"),\n max_connection_age: knobs.max_connection_age,\n close_bound: knobs.close_bound,\n retrans_giveup_time: knobs.retrans_giveup_time,\n },\n operations,\n };\n\n const checks = (checkOptions: CheckOptions) =>\n stepChecks<ClientStep>(name, checkOptions, {\n // the state of the client, without a round trip\n \"local-state\": localStateCheck(() => status === \"ready\"),\n // a passive declare of an exchange of each broker, on the channel of the application\n \"round-trip\": roundTripCheck((sendOptions) =>\n sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: undefined,\n options: sendOptions,\n attempt: (signal) => rpcAttempt(signal, \"a passive exchange.declare\", (ch) => ch.checkExchange(CHECK_EXCHANGE), () => undefined),\n onReissue: () => {},\n }),\n ),\n // a new connection each time, with the protocol header and no login\n dial: dialCheck(dial, spec.host, spec.port),\n });\n\n return {\n name,\n declaration,\n handle,\n meets: rabbitMeetings(name, knobs),\n get status() {\n return status;\n },\n joins,\n publish,\n get,\n jobs,\n checks,\n attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),\n problems: (description) => clientProblems(name, description, clientBounds(knobs)),\n };\n};\n","import type { Machine } from \"@mark1russell7/algebra\";\nimport { clientKnob as knob, closeTimer, transition as t } from \"../client/machine.ts\";\n\n/** The states where a generation is open, and the states where the client can close. */\nconst OPEN = [\"ready\", \"blocked\"] as const;\nconst SERVING = [\"connecting\", ...OPEN, \"failing\"] as const;\nconst LIVE = [...SERVING, \"closing\"] as const;\n\n/**\n * The RabbitMQ client of the service as a `mark1russell7.machine/1` document. It is one generation\n * at a time: one connection of amqplib and its confirm channel. The machines `amqplib` and\n * `rabbitmq-connection` of `@mark1russell7/machines` give the connection and its heartbeat. The states:\n * - `ready`: the channel is open, and the client sends each call.\n * - `blocked`: a resource alarm of the broker blocked the connection. Each call is not sent until the unblock.\n * - `failing`: no generation is open. The client tries the next node after its backoff.\n *\n * The end of the channel or of the connection ends the generation. A test records the transitions\n * of the client and replays them against this document.\n */\nexport const RABBIT_CLIENT_MACHINE: Machine = {\n format: \"mark1russell7.machine/1\",\n id: \"service.machine.rabbitmq-client\",\n title: \"The RabbitMQ client of the service, over amqplib 2\",\n layer: \"driver\",\n version: \"0.1.0\",\n sources: [{ ref: \"packages/service/src/rabbitmq (the client implements this document)\", rung: \"implemented\" }],\n states: {\n none: { initial: true, note: \"the client exists, and its first connection does not\" },\n connecting: { note: \"a connection, its handshake, and the open of its confirm channel, in connect_bound\" },\n ready: { note: \"the channel is open. A black hole stays hidden until the heartbeat or a timer of a call ends it\" },\n blocked: { note: \"a resource alarm blocked the connection: the broker does not read its socket\" },\n failing: { note: \"no generation is open. The client tries the next node after its backoff\" },\n closing: { note: \"connection.close, in close_bound, then a destroy of the socket\" },\n end: { final: true, note: \"the service closed the client\" },\n },\n events: {\n \"status.connecting\": { kind: \"local\" },\n join: { kind: \"rx\", note: \"the confirm channel is open: a new generation (D1)\" },\n \"connect.failed\": { kind: \"local\", note: \"the connection or its channel failed, or did not open in connect_bound\" },\n \"retry.connect\": { kind: \"timer\", note: \"the backoff ended: a try on the next node\" },\n \"connection.error\": { kind: \"rx\", note: \"an error event of the connection. Its close follows\" },\n \"connection.end\": { kind: \"rx\", note: \"the connection closed: a reset, a FIN, the heartbeat, or a close of the broker\" },\n \"channel.error\": { kind: \"rx\", note: \"the broker closed the channel with a reply code\" },\n \"channel.end\": { kind: \"rx\", note: \"the channel closed on a connection that stays: the client closes that connection too\" },\n \"connection.blocked\": { kind: \"rx\", note: \"connection.blocked of the broker: a resource alarm\" },\n \"connection.unblocked\": { kind: \"rx\" },\n \"command.reissue\": { kind: \"local\" },\n \"close.request\": { kind: \"local\" },\n \"close.bound\": { kind: \"timer\", note: \"connection.close got no close-ok in close_bound\" },\n \"close.destroy\": { kind: \"local\", note: \"the bound destroys a socket that a silent broker does not close\" },\n \"status.end\": { kind: \"local\" },\n },\n knobs: {\n connect_bound: knob(\"socketOptions.timeout\"),\n heartbeat_interval: knob(\"heartbeat\"),\n retry_base: knob(\"retry.base\"),\n retry_cap: knob(\"retry.cap\"),\n close_bound: knob(\"close.bound\"),\n },\n timers: {\n connect_timeout: {\n duration: { knob: \"connect_bound\", unit: \"s\" },\n arms: [\"enter:connecting\"],\n cancels: [\"join\", \"connect.failed\"],\n fires: \"connect.failed\",\n note: \"the bound of the wrapper on the connection and its channel. amqplib bounds the connect and the handshake with the same time\",\n },\n heartbeat: {\n duration: { expr: \"3 * heartbeat_interval\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"the heartbeat of amqplib ends a silent connection 2 to 3 heartbeats after the last data. Each frame that arrives starts it again\",\n },\n retry: {\n duration: { expr: \"min(retry_cap, retry_base * pow(2, fired)) + retry_base\", unit: \"s\" },\n arms: [\"connect.failed\", \"connection.end\", \"channel.end\"],\n cancels: [\"close.request\"],\n fires: \"retry.connect\",\n backoff: { resets: [\"join\"] },\n note: \"the most delay: the backoff doubles from retry_base to retry_cap, with a jitter up to retry_base\",\n },\n close: closeTimer(),\n },\n transitions: [\n t(\"connect\", \"none\", \"status.connecting\", \"connecting\"),\n t(\"join\", \"connecting\", \"join\", \"ready\"),\n t(\"connect-failed\", \"connecting\", \"connect.failed\", \"failing\", { timer: \"connect_timeout\" }),\n t(\"retry\", \"failing\", \"retry.connect\", \"connecting\", { timer: \"retry\" }),\n t(\"connection-end\", [...OPEN], \"connection.end\", \"failing\", { timer: \"heartbeat\" }),\n t(\"channel-end\", [...OPEN], \"channel.end\", \"failing\"),\n t(\"blocked\", \"ready\", \"connection.blocked\", \"blocked\"),\n t(\"unblocked\", \"blocked\", \"connection.unblocked\", \"ready\"),\n ...OPEN.map((state) => t(`connection-error-${state}`, state, \"connection.error\", state)),\n ...OPEN.map((state) => t(`channel-error-${state}`, state, \"channel.error\", state)),\n ...LIVE.map((state) => t(`reissue-${state}`, state, \"command.reissue\", state)),\n t(\"close\", [...SERVING], \"close.request\", \"closing\"),\n t(\"close-bound\", \"closing\", \"close.bound\", \"closing\", { timer: \"close\" }),\n t(\"close-destroy\", \"closing\", \"close.destroy\", \"closing\"),\n t(\"end\", \"closing\", \"status.end\", \"end\"),\n ],\n};\n","import { STARTING_POLL } from \"../client/core.ts\";\nimport type { Poll } from \"../timing.ts\";\nimport type { RabbitKnobs } from \"./client.ts\";\n\n/**\n * This poll is the poll of the checks that `RABBIT_STARTING_KNOBS` fits. It is `STARTING_POLL` of\n * the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.\n */\nexport const RABBIT_STARTING_POLL: Poll = STARTING_POLL;\n\n/**\n * These knobs are a declaration to start from, from what the cells of R3 measured on amqplib 2.2.0\n * against RabbitMQ 4.3.6. The runtime has no defaults: a service gives these knobs, or its own.\n * Each value holds the borders that the cells measured:\n * - `connect_bound` 5 s: the connect timeout of DP44. The timer stops when the connection opens.\n * Thus it does not change a fault with a call in flight. At its defaults, amqplib has no connect timeout.\n * - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13). After a loss of the leader of a quorum\n * queue, the first confirm came at 6.61 s, 6.68 s and 8.05 s (T11). A later confirm is indeterminate, not lost.\n * - `heartbeat_interval` 15 s: the heartbeat ended a silent connection 45.009 s after the last data,\n * before the kernel gave up at 53.016 s (O17). The frames each 7.5 s keep a flow through a router\n * that forgets it at 30 s (O03). At the 60 s of the broker, the heartbeat came at 180.009 s.\n * - `retry_base` 1 s: the cells connected to the next node 1 s after the end of a connection.\n * - `retry_cap` 8 s: no cell measured it. With its jitter of 1 s, the most delay is 9 s, in the slowest poll of 10 s.\n * - `keepalive_idle` \"infinite\": amqplib sets no keepalive, and the heartbeat refreshes an idle flow.\n * Linux sends no keepalive probe while data is in flight.\n * - `max_connection_age` \"infinite\": the client does not replace its connection at an age.\n * - `close_bound` 2 s: behind a black hole, `connection.close` waits for its close-ok with no bound.\n * - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.\n */\nexport const RABBIT_STARTING_KNOBS: RabbitKnobs = {\n connect_bound: { value: 5, unit: \"s\" },\n request_timeout: { value: 9.5, unit: \"s\" },\n heartbeat_interval: { value: 15, unit: \"s\" },\n retry_base: { value: 1, unit: \"s\" },\n retry_cap: { value: 8, unit: \"s\" },\n keepalive_idle: { value: \"infinite\", unit: \"s\" },\n max_connection_age: { value: \"infinite\", unit: \"s\" },\n close_bound: { value: 2, unit: \"s\" },\n retrans_giveup_time: { value: 924.6, unit: \"s\" },\n};\n"],"mappings":";;;;;;;;;AA2FA,MAAa,WAA0B,OAAO,EAAE,KAAK,oBAAoB;CAGvE,MAAM,SAAU,MAAM,OAAO;CAC7B,MAAM,UAAU,OAAO,WAAW,OAAO,SAAS;CAClD,IAAI,YAAY,KAAA,GAAW,MAAM,IAAI,MAAM,mCAAmC;CAC9E,OAAO,QAAQ,KAAK,aAAa;AACnC;;;;;;;;;;;AClFA,MAAa,kBAAkB,MAAc,UAAkC;CAC7E,MAAM,OAAO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AC/C,oBAAoB;EAAE,OAAO;EAAY,MAAM;CAAI;CACnD,aAAa;EAAE,OAAO;EAAG,MAAM;CAAI;CACnC,qBAAqB;EAAE,OAAO;EAAO,MAAM;CAAI;AACjD"}
package/build/redis.d.ts CHANGED
@@ -1,10 +1,9 @@
1
+ import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation, y as retryBackoff } from "./core-BSzt4RI2.js";
2
+ import { ut as Operation, z as heartbeatDetection } from "./logger-B6drv9w0.js";
1
3
  import { n as Clock } from "./clock-DpVgpY4h.js";
2
- import { ut as Operation, z as heartbeatDetection } from "./logger-BN2BfPgU.js";
3
- import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation, y as retryBackoff } from "./core-Dt0HEVMq.js";
4
- import { n as LimiterStore } from "./store-1CsNoJ8O.js";
4
+ import { n as LimiterStore } from "./store-DFwFKrsB.js";
5
5
  import { Extent, Quantity } from "@mark1russell7/quantity";
6
6
  import { Machine } from "@mark1russell7/algebra";
7
- //#region src/redis/connection.d.ts
8
7
  /**
9
8
  * A Redis connection is the part of an ioredis client that the wrapper uses. An ioredis 6 client has
10
9
  * each part. A fake for tests has them too. Thus the package depends on no type of ioredis.
@@ -61,8 +60,6 @@ type ConnectionFactory = Factory<RedisConnectionOptions, RedisConnection>;
61
60
  * service that does not use Redis does not need ioredis.
62
61
  */
63
62
  export declare const ioredis: ConnectionFactory;
64
- //#endregion
65
- //#region src/redis/client.d.ts
66
63
  /**
67
64
  * These are the knobs of the client, each a time, by the names of the ordering law where the law
68
65
  * has them. The runtime has no defaults, thus each knob is necessary, and a bound that nobody gives
@@ -145,8 +142,6 @@ export declare const tcpDial: DialFn;
145
142
  * from the core of the clients. This entry gives what ioredis does in its own way.
146
143
  */
147
144
  export declare const redisClient: (name: string, spec: RedisClientSpec, options?: RedisClientOptions) => RedisClient;
148
- //#endregion
149
- //#region src/redis/meets.d.ts
150
145
  /**
151
146
  * This function gives the manifestations that a Redis client can meet, and the detectors of each, from
152
147
  * its knobs. A reset or a FIN arrives on the next segment. A black hole and a host that is gone give
@@ -154,8 +149,6 @@ export declare const redisClient: (name: string, spec: RedisClientSpec, options?
154
149
  * segment. Thus TCP keepalive does not fire on them, and only the client's own timers find them.
155
150
  */
156
151
  export declare const meetings: (name: string, knobs: RedisKnobs, heartbeat: Extent) => Meeting[];
157
- //#endregion
158
- //#region src/redis/limiter.d.ts
159
152
  /**
160
153
  * This script decides one take in one atomic step of Redis. It does the arithmetic of `decide`, and
161
154
  * it reads `TIME` of the server, the one clock of all replicas. A test can give the time in its place.
@@ -196,8 +189,6 @@ type RedisSender = Pick<RedisClient, "send">;
196
189
  * moves the counts of each key. The replicas still share one clock.
197
190
  */
198
191
  export declare const redisLimiterStore: (client: RedisSender, options: RedisLimiterOptions) => LimiterStore;
199
- //#endregion
200
- //#region src/redis/machine.d.ts
201
192
  /**
202
193
  * The Redis client as a `mark1russell7.machine/1` document. Its states are the states of ioredis.
203
194
  * The wrapper adds its own events: the join at each `ready`, and the misses of its watchdog. It also
@@ -209,12 +200,9 @@ export declare const redisLimiterStore: (client: RedisSender, options: RedisLimi
209
200
  * hidden interval. A timer of this document bounds each hidden interval.
210
201
  */
211
202
  export declare const REDIS_CLIENT_MACHINE: Machine;
212
- //#endregion
213
- //#region src/redis/operations.d.ts
214
203
  /** These are the operations of the client: the idempotency of each command that the table names. */
215
204
  export declare const REDIS_OPERATIONS: Readonly<Record<string, Operation>>;
216
205
  /** This function gives the name of a command as the table writes it: upper case, and CLIENT ID with its subcommand. */
217
206
  export declare const commandName: (command: string, args: readonly unknown[]) => string;
218
- //#endregion
219
207
  export { type Attempt, type CheckOptions, type Client, type ClientJoin, type ClientKnobs, type ClientOptions, type ClientSocket, type ClientSpec, type ClientStep, type ConnectionFactory, type Detector, type DialFn, type Factory, type Join, MANIFESTATIONS, type Manifestation, type Meeting, type RedisClient, type RedisClientOptions, type RedisClientSpec, type RedisConnection, type RedisConnectionOptions, type RedisKnobs, type RedisLimiterOptions, type RedisSender, type RedisSocket, type Sent, type Situation, firstDetector, heartbeatDetection, retryBackoff, unwatched };
220
208
  //# sourceMappingURL=redis.d.ts.map
package/build/redis.js CHANGED
@@ -1,10 +1,10 @@
1
+ import { C as notSent, D as readyWait, F as timeProblems, G as immediate, J as keepaliveSilent, K as keepaliveAnswered, M as sendWithReissue, N as socketEnds, O as retryBackoff, P as stepChecks, R as withinBound, S as ms, U as WHAT, V as MANIFESTATIONS, W as firstDetector, X as unwatched, Y as kernelGiveUp, _ as inFlight, a as helloDial, b as message, d as clientProblems, f as clientRecorder, h as finiteMs, j as roundTripCheck, k as retryProblems, l as attachClient, m as dialCheck, n as closeTimer, q as keepaliveReset, r as transition, t as clientKnob, u as clientBounds, w as operationTable, x as missesProblems, y as localStateCheck } from "./machine-mIW1qgEE.js";
2
+ import { backoffDelay } from "./backoff.js";
1
3
  import { realClock } from "./clock.js";
2
4
  import { heartbeat } from "./heartbeat.js";
3
- import { i as heartbeatDetection } from "./timing-DGRi3XCI.js";
4
- import { c as overCapacity, u as unitsOf } from "./policy-G-Y3Meku.js";
5
- import { backoffDelay } from "./backoff.js";
6
- import { C as notSent, D as readyWait, F as timeProblems, G as immediate, J as keepaliveSilent, K as keepaliveAnswered, M as sendWithReissue, N as socketEnds, O as retryBackoff, P as stepChecks, R as withinBound, S as ms, U as WHAT, V as MANIFESTATIONS, W as firstDetector, X as unwatched, Y as kernelGiveUp, _ as inFlight, a as helloDial, b as message, d as clientProblems, f as clientRecorder, h as finiteMs, j as roundTripCheck, k as retryProblems, l as attachClient, m as dialCheck, n as closeTimer, q as keepaliveReset, r as transition, t as clientKnob, u as clientBounds, w as operationTable, x as missesProblems, y as localStateCheck } from "./machine-p4lENJ86.js";
7
- //#region src/redis/connection.ts
5
+ import { i as heartbeatDetection } from "./timing-DZl36uXs.js";
6
+ import { c as overCapacity, u as unitsOf } from "./policy-B23MY52l.js";
7
+ // src/redis/connection.ts
8
8
  /**
9
9
  * This factory makes an ioredis client. It loads ioredis only when a client connects, thus a
10
10
  * service that does not use Redis does not need ioredis.
@@ -12,8 +12,7 @@ import { C as notSent, D as readyWait, F as timeProblems, G as immediate, J as k
12
12
  const ioredis = async (options) => {
13
13
  return new (await (import("ioredis"))).default(options);
14
14
  };
15
- //#endregion
16
- //#region src/redis/meets.ts
15
+ // src/redis/meets.ts
17
16
  /**
18
17
  * This function gives the manifestations that a Redis client can meet, and the detectors of each, from
19
18
  * its knobs. A reset or a FIN arrives on the next segment. A black hole and a host that is gone give
@@ -84,8 +83,7 @@ const meetings = (name, knobs, heartbeat) => {
84
83
  acknowledged("app-stall", "the server stops its replies for a time, for example a long command, and its kernel stays up")
85
84
  ];
86
85
  };
87
- //#endregion
88
- //#region src/redis/operations.ts
86
+ // src/redis/operations.ts
89
87
  /**
90
88
  * These are the Redis commands whose idempotency the client declares when the declaration does not
91
89
  * say. A second issue of an idempotent command has the same effect. Thus the client can send it
@@ -196,8 +194,7 @@ const commandName = (command, args) => {
196
194
  if ((name === "CLIENT" || name === "CONFIG" || name === "DEBUG") && typeof args[0] === "string") return `${name} ${args[0].toUpperCase()}`;
197
195
  return name;
198
196
  };
199
- //#endregion
200
- //#region src/redis/client.ts
197
+ // src/redis/client.ts
201
198
  /** This function gives the problems of a spec: the knobs that the client cannot use. */
202
199
  const specProblems = (name, spec) => {
203
200
  const problems = [];
@@ -470,8 +467,7 @@ const redisClient = (name, spec, options = {}) => {
470
467
  problems: (description) => clientProblems(name, description, clientBounds(knobs))
471
468
  };
472
469
  };
473
- //#endregion
474
- //#region src/redis/limiter.ts
470
+ // src/redis/limiter.ts
475
471
  /**
476
472
  * This script decides one take in one atomic step of Redis. It does the arithmetic of `decide`, and
477
473
  * it reads `TIME` of the server, the one clock of all replicas. A test can give the time in its place.
@@ -631,8 +627,7 @@ const replyOf = (limiter, reply) => {
631
627
  }
632
628
  throw new Error(`the limiter store ${limiter} gave a reply that is not a decision: ${JSON.stringify(reply)}`);
633
629
  };
634
- //#endregion
635
- //#region src/redis/machine.ts
630
+ // src/redis/machine.ts
636
631
  /** The states where the connection exists or tries to exist, thus where it can close. */
637
632
  const LIVE = [
638
633
  "connecting",
@@ -772,7 +767,6 @@ const REDIS_CLIENT_MACHINE = {
772
767
  ...ANY.map((state) => transition(`close-destroy-${state}`, state, "close.destroy", state))
773
768
  ]
774
769
  };
775
- //#endregion
776
770
  export { LIMITER_SCRIPT, MANIFESTATIONS, REDIS_CLIENT_MACHINE, REDIS_OPERATIONS, commandName, firstDetector, heartbeatDetection, ioredis, meetings, redisClient, redisLimiterStore, retryBackoff, specProblems, tcpDial, unwatched };
777
771
 
778
772
  //# sourceMappingURL=redis.js.map