@noodleseed/one 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/commands/author-loop.d.ts.map +1 -1
  2. package/dist/commands/author-loop.js +2 -2
  3. package/dist/commands/author-loop.js.map +1 -1
  4. package/dist/commands/catalog-dispatch.d.ts.map +1 -1
  5. package/dist/commands/catalog-dispatch.js +21 -2
  6. package/dist/commands/catalog-dispatch.js.map +1 -1
  7. package/dist/commands/deploy-ops.d.ts.map +1 -1
  8. package/dist/commands/deploy-ops.js +28 -11
  9. package/dist/commands/deploy-ops.js.map +1 -1
  10. package/dist/first-run.d.ts +11 -0
  11. package/dist/first-run.d.ts.map +1 -1
  12. package/dist/first-run.js +19 -4
  13. package/dist/first-run.js.map +1 -1
  14. package/dist/project-scaffold-templates.d.ts +11 -0
  15. package/dist/project-scaffold-templates.d.ts.map +1 -0
  16. package/dist/project-scaffold-templates.js +359 -0
  17. package/dist/project-scaffold-templates.js.map +1 -0
  18. package/dist/project.d.ts.map +1 -1
  19. package/dist/project.js +1 -323
  20. package/dist/project.js.map +1 -1
  21. package/dist/react.d.ts +2 -2
  22. package/dist/react.d.ts.map +1 -1
  23. package/dist/react.js +1 -1
  24. package/dist/react.js.map +1 -1
  25. package/dist/validate.d.ts +12 -0
  26. package/dist/validate.d.ts.map +1 -1
  27. package/dist/validate.js +11 -0
  28. package/dist/validate.js.map +1 -1
  29. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.d.ts.map +1 -1
  30. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +6 -9
  31. package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
  32. package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
  33. package/node_modules/@noodle-borg/authoring/dist/index.d.ts +3 -3
  34. package/node_modules/@noodle-borg/authoring/dist/index.d.ts.map +1 -1
  35. package/node_modules/@noodle-borg/authoring/dist/index.js +1 -1
  36. package/node_modules/@noodle-borg/authoring/dist/index.js.map +1 -1
  37. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts +302 -7
  38. package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts.map +1 -1
  39. package/node_modules/@noodle-borg/authoring/dist/react/components.js +39 -7
  40. package/node_modules/@noodle-borg/authoring/dist/react/components.js.map +1 -1
  41. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts +4 -2
  42. package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts.map +1 -1
  43. package/node_modules/@noodle-borg/authoring/dist/react/index.js +2 -1
  44. package/node_modules/@noodle-borg/authoring/dist/react/index.js.map +1 -1
  45. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts +2618 -0
  46. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts.map +1 -0
  47. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js +110 -0
  48. package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js.map +1 -0
  49. package/node_modules/@noodle-borg/authoring/dist/react.d.ts +2 -2
  50. package/node_modules/@noodle-borg/authoring/dist/react.d.ts.map +1 -1
  51. package/node_modules/@noodle-borg/authoring/dist/react.js +1 -1
  52. package/node_modules/@noodle-borg/authoring/dist/react.js.map +1 -1
  53. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts +1 -1
  54. package/node_modules/@noodle-borg/authoring/dist/recording.d.ts.map +1 -1
  55. package/node_modules/@noodle-borg/authoring/dist/recording.js +14 -1
  56. package/node_modules/@noodle-borg/authoring/dist/recording.js.map +1 -1
  57. package/node_modules/@noodle-borg/authoring/dist/server.d.ts +25 -2
  58. package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
  59. package/node_modules/@noodle-borg/authoring/dist/server.js +7 -3
  60. package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
  61. package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
  62. package/node_modules/@noodle-borg/compiler/dist/compile.js +20 -8
  63. package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
  64. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +2 -0
  65. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
  66. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +6 -0
  67. package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
  68. package/node_modules/@noodle-borg/connector-http/package.json +1 -1
  69. package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
  70. package/node_modules/@noodle-borg/protocol/dist/mapping.js +8 -0
  71. package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
  72. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +15 -21
  73. package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
  74. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
  75. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +15 -21
  76. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
  77. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
  78. package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
  79. package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
  80. package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
  81. package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
  82. package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
  83. package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
  84. package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
  85. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
  86. package/node_modules/hono/dist/cjs/utils/body.js +12 -4
  87. package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
  88. package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
  89. package/node_modules/hono/dist/helper/css/common.js +3 -1
  90. package/node_modules/hono/dist/helper/css/index.js +9 -1
  91. package/node_modules/hono/dist/jsx/base.js +15 -15
  92. package/node_modules/hono/dist/jsx/components.js +42 -22
  93. package/node_modules/hono/dist/jsx/context.js +129 -5
  94. package/node_modules/hono/dist/jsx/streaming.js +10 -8
  95. package/node_modules/hono/dist/middleware/cors/index.js +2 -5
  96. package/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
  97. package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
  98. package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
  99. package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
  100. package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
  101. package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
  102. package/node_modules/hono/dist/utils/body.js +12 -4
  103. package/node_modules/hono/dist/utils/buffer.js +2 -1
  104. package/node_modules/hono/dist/validator/validator.js +3 -3
  105. package/node_modules/hono/package.json +9 -10
  106. package/node_modules/tailwindcss/dist/chunk-HMCCH6MG.mjs +1 -0
  107. package/node_modules/tailwindcss/dist/default-theme.mjs +1 -1
  108. package/node_modules/tailwindcss/dist/lib.js +13 -13
  109. package/node_modules/tailwindcss/dist/lib.mjs +18 -18
  110. package/node_modules/tailwindcss/package.json +2 -2
  111. package/node_modules/undici/README.md +3 -2
  112. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  113. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  114. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  115. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  116. package/node_modules/undici/docs/docs/api/Client.md +365 -178
  117. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  118. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  119. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  120. package/node_modules/undici/docs/docs/api/Cookies.md +125 -47
  121. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  122. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  123. package/node_modules/undici/docs/docs/api/Dispatcher.md +479 -1093
  124. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
  125. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  126. package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
  127. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  128. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  129. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  130. package/node_modules/undici/docs/docs/api/Interceptors.md +355 -0
  131. package/node_modules/undici/docs/docs/api/MockAgent.md +314 -322
  132. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  133. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  134. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  135. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  136. package/node_modules/undici/docs/docs/api/MockPool.md +299 -263
  137. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  138. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  139. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  140. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  141. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  142. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  143. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  144. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  145. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -186
  146. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  147. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  148. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  149. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  150. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  151. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  152. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  153. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  154. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  155. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  156. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  157. package/node_modules/undici/docs/docs/index.md +779 -0
  158. package/node_modules/undici/docs/docs/site.json +125 -0
  159. package/node_modules/undici/docs/docs/type-map.json +79 -0
  160. package/node_modules/undici/lib/api/api-request.js +7 -1
  161. package/node_modules/undici/lib/api/readable.js +47 -2
  162. package/node_modules/undici/lib/core/errors.js +20 -0
  163. package/node_modules/undici/lib/core/request.js +1 -1
  164. package/node_modules/undici/lib/core/util.js +24 -1
  165. package/node_modules/undici/lib/dispatcher/client-h1.js +92 -1
  166. package/node_modules/undici/lib/dispatcher/client-h2.js +322 -118
  167. package/node_modules/undici/lib/dispatcher/client.js +6 -2
  168. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +1 -0
  169. package/node_modules/undici/lib/dispatcher/proxy-agent.js +42 -7
  170. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +4 -2
  171. package/node_modules/undici/lib/handler/redirect-handler.js +1 -0
  172. package/node_modules/undici/lib/handler/retry-handler.js +57 -19
  173. package/node_modules/undici/lib/util/cache.js +8 -2
  174. package/node_modules/undici/lib/web/cookies/parse.js +20 -27
  175. package/node_modules/undici/lib/web/cookies/util.js +1 -1
  176. package/node_modules/undici/lib/web/eventsource/eventsource.js +7 -18
  177. package/node_modules/undici/lib/web/eventsource/util.js +32 -1
  178. package/node_modules/undici/lib/web/fetch/body.js +43 -0
  179. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  180. package/node_modules/undici/lib/web/fetch/index.js +11 -2
  181. package/node_modules/undici/lib/web/fetch/request.js +1 -0
  182. package/node_modules/undici/lib/web/fetch/util.js +4 -1
  183. package/node_modules/undici/lib/web/websocket/receiver.js +20 -3
  184. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
  185. package/node_modules/undici/lib/web/websocket/websocket.js +3 -1
  186. package/node_modules/undici/package.json +1 -1
  187. package/node_modules/undici/types/client.d.ts +6 -1
  188. package/node_modules/undici/types/cookies.d.ts +1 -1
  189. package/node_modules/undici/types/errors.d.ts +10 -0
  190. package/node_modules/undici/types/fetch.d.ts +1 -0
  191. package/node_modules/undici/types/handlers.d.ts +2 -0
  192. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  193. package/package.json +4 -4
  194. package/react/styles.css +510 -5
  195. package/react/styles.source.css +850 -0
  196. package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
  197. package/node_modules/tailwindcss/dist/chunk-XVOTX5KS.mjs +0 -1
@@ -1,43 +1,206 @@
1
- # Class: MockCallHistoryLog
1
+ # MockCallHistoryLog
2
2
 
3
- Access to an instance with :
3
+ <!--introduced_in=v7.5.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/mock/mock-call-history.js -->
6
+
7
+ > Stability: 2 - Stable
8
+
9
+ A `MockCallHistoryLog` is an immutable snapshot of the configuration of a single
10
+ request that was intercepted by a [`MockAgent`][]. Each property mirrors a part
11
+ of the request, with the URL components already parsed by the WHATWG URL parser.
12
+
13
+ Instances are not created directly. They are produced by a [`MockCallHistory`][]
14
+ when call history is enabled on a [`MockAgent`][], and can be retrieved through
15
+ the call history helpers such as `firstCall()`, `lastCall()`, `nthCall()`,
16
+ `calls()`, and `filterCalls()`.
17
+
18
+ ```mjs
19
+ import { MockAgent } from 'undici'
4
20
 
5
- ```js
6
21
  const mockAgent = new MockAgent({ enableCallHistory: true })
7
- mockAgent.getCallHistory()?.firstCall()
22
+
23
+ // after some requests have been intercepted:
24
+ const log = mockAgent.getCallHistory()?.firstCall()
8
25
  ```
9
26
 
10
- ## class properties
27
+ ## Class: `MockCallHistoryLog`
28
+
29
+ <!-- YAML
30
+ added: v7.5.0
31
+ -->
32
+
33
+ Represents the configuration of one intercepted request.
34
+
35
+ ### `new MockCallHistoryLog(requestInit)`
36
+
37
+ <!-- YAML
38
+ added: v7.5.0
39
+ -->
40
+
41
+ * `requestInit` {DispatchOptions} The dispatch options of the intercepted
42
+ request. **Default:** `{}`.
43
+
44
+ Creates a new `MockCallHistoryLog`. The `body`, `headers`, and `method`
45
+ properties are copied directly from `requestInit`, while the URL-derived
46
+ properties (`fullUrl`, `origin`, `path`, `searchParams`, `protocol`, `host`,
47
+ `port`, and `hash`) are computed from `requestInit.path` and `requestInit.origin`
48
+ using the WHATWG URL parser.
49
+
50
+ This constructor is internal-facing: instances are created by
51
+ [`MockCallHistory`][] when a request is intercepted. It is documented because the
52
+ class is part of the public API surface.
53
+
54
+ ### `mockCallHistoryLog.body`
55
+
56
+ <!-- YAML
57
+ added: v7.5.0
58
+ -->
59
+
60
+ * Type: {string|null|undefined}
61
+
62
+ The body of the intercepted request, exactly as supplied to the dispatcher.
63
+
64
+ ### `mockCallHistoryLog.headers`
65
+
66
+ <!-- YAML
67
+ added: v7.5.0
68
+ -->
69
+
70
+ * Type: {Record<string, string|string[]>|null|undefined}
71
+
72
+ The headers of the intercepted request.
73
+
74
+ ### `mockCallHistoryLog.method`
75
+
76
+ <!-- YAML
77
+ added: v7.5.0
78
+ -->
79
+
80
+ * Type: {string}
81
+
82
+ The HTTP method of the intercepted request, for example `'GET'` or `'PUT'`.
83
+
84
+ ### `mockCallHistoryLog.fullUrl`
85
+
86
+ <!-- YAML
87
+ added: v7.5.0
88
+ -->
89
+
90
+ * Type: {string}
91
+
92
+ The full URL of the intercepted request, including protocol, host, path, search
93
+ parameters, and hash.
94
+
95
+ ### `mockCallHistoryLog.origin`
96
+
97
+ <!-- YAML
98
+ added: v7.5.0
99
+ -->
11
100
 
12
- - body `mockAgent.getCallHistory()?.firstCall()?.body`
13
- - headers `mockAgent.getCallHistory()?.firstCall()?.headers` an object
14
- - method `mockAgent.getCallHistory()?.firstCall()?.method` a string
15
- - fullUrl `mockAgent.getCallHistory()?.firstCall()?.fullUrl` a string containing the protocol, origin, path, query and hash
16
- - origin `mockAgent.getCallHistory()?.firstCall()?.origin` a string containing the protocol and the host
17
- - headers `mockAgent.getCallHistory()?.firstCall()?.headers` an object
18
- - path `mockAgent.getCallHistory()?.firstCall()?.path` a string always starting with `/`
19
- - searchParams `mockAgent.getCallHistory()?.firstCall()?.searchParams` an object
20
- - protocol `mockAgent.getCallHistory()?.firstCall()?.protocol` a string (`https:`)
21
- - host `mockAgent.getCallHistory()?.firstCall()?.host` a string
22
- - port `mockAgent.getCallHistory()?.firstCall()?.port` an empty string or a string containing numbers
23
- - hash `mockAgent.getCallHistory()?.firstCall()?.hash` an empty string or a string starting with `#`
101
+ * Type: {string}
24
102
 
25
- ## class methods
103
+ The origin of the intercepted request, comprising the protocol and host, for
104
+ example `'https://localhost:4000'`.
26
105
 
27
- ### toMap
106
+ ### `mockCallHistoryLog.path`
28
107
 
29
- Returns a Map instance
108
+ <!-- YAML
109
+ added: v7.5.0
110
+ -->
30
111
 
31
- ```js
32
- mockAgent.getCallHistory()?.firstCall()?.toMap()?.get('hash')
33
- // #hash
112
+ * Type: {string}
113
+
114
+ The pathname of the intercepted request. It always starts with `/` and never
115
+ contains search parameters.
116
+
117
+ ### `mockCallHistoryLog.searchParams`
118
+
119
+ <!-- YAML
120
+ added: v7.5.0
121
+ -->
122
+
123
+ * Type: {Record<string, string>}
124
+
125
+ The search parameters of the intercepted request as a plain object of key/value
126
+ pairs.
127
+
128
+ ### `mockCallHistoryLog.protocol`
129
+
130
+ <!-- YAML
131
+ added: v7.5.0
132
+ -->
133
+
134
+ * Type: {string}
135
+
136
+ The protocol of the intercepted request, including the trailing colon, for
137
+ example `'https:'` or `'http:'`.
138
+
139
+ ### `mockCallHistoryLog.host`
140
+
141
+ <!-- YAML
142
+ added: v7.5.0
143
+ -->
144
+
145
+ * Type: {string}
146
+
147
+ The host of the intercepted request, including the port when present.
148
+
149
+ ### `mockCallHistoryLog.port`
150
+
151
+ <!-- YAML
152
+ added: v7.5.0
153
+ -->
154
+
155
+ * Type: {string}
156
+
157
+ The port of the intercepted request. It is an empty string when no explicit port
158
+ was used, otherwise a string of digits.
159
+
160
+ ### `mockCallHistoryLog.hash`
161
+
162
+ <!-- YAML
163
+ added: v7.5.0
164
+ -->
165
+
166
+ * Type: {string}
167
+
168
+ The hash fragment of the intercepted request. It is an empty string when absent,
169
+ otherwise a string starting with `#`.
170
+
171
+ ### `mockCallHistoryLog.toMap()`
172
+
173
+ <!-- YAML
174
+ added: v7.5.0
175
+ -->
176
+
177
+ * Returns: {Map} A `Map` whose keys are the property names `protocol`, `host`,
178
+ `port`, `origin`, `path`, `hash`, `searchParams`, `fullUrl`, `method`, `body`,
179
+ and `headers`, each mapped to the corresponding value of this log.
180
+
181
+ Returns the log as a `Map` of property name to value.
182
+
183
+ ```mjs
184
+ mockAgent.getCallHistory()?.firstCall()?.toMap().get('hash')
185
+ // '#hash'
34
186
  ```
35
187
 
36
- ### toString
188
+ ### `mockCallHistoryLog.toString()`
37
189
 
38
- Returns a string computed with any class property name and value pair
190
+ <!-- YAML
191
+ added: v7.5.0
192
+ -->
39
193
 
40
- ```js
194
+ * Returns: {string} A string representation of the log.
195
+
196
+ Returns a string built from every property name and value pair. Each pair is
197
+ joined with `->` and pairs are separated with `|`. Object values such as
198
+ `searchParams` and `headers` are serialized with `JSON.stringify()`.
199
+
200
+ ```mjs
41
201
  mockAgent.getCallHistory()?.firstCall()?.toString()
42
202
  // protocol->https:|host->localhost:4000|port->4000|origin->https://localhost:4000|path->/endpoint|hash->#here|searchParams->{"query":"value"}|fullUrl->https://localhost:4000/endpoint?query=value#here|method->PUT|body->"{ "data": "hello" }"|headers->{"content-type":"application/json"}
43
203
  ```
204
+
205
+ [`MockAgent`]: MockAgent.md#class-mockagent
206
+ [`MockCallHistory`]: MockCallHistory.md#class-mockcallhistory
@@ -1,73 +1,183 @@
1
- # Class: MockClient
1
+ # MockClient
2
2
 
3
- Extends: `undici.Client`
3
+ <!--introduced_in=v4.0.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/mock/mock-client.js -->
4
6
 
5
- A mock client class that implements the same api as [MockPool](/docs/docs/api/MockPool.md).
7
+ > Stability: 2 - Stable
6
8
 
7
- ## `new MockClient(origin, [options])`
9
+ A `MockClient` is a [`Client`][] that intercepts requests matching registered
10
+ routes and replies with mocked responses instead of contacting the network.
11
+ It is created by a [`MockAgent`][] when the agent is configured with a single
12
+ connection, and it exposes the same interception API as [`MockPool`][].
8
13
 
9
- Arguments:
14
+ A `MockClient` is not constructed directly in most cases; instead it is obtained
15
+ through [`mockAgent.get(origin)`][] once the agent has `connections` set to `1`.
10
16
 
11
- * **origin** `string` - It should only include the **protocol, hostname, and port**.
12
- * **options** `MockClientOptions` - It extends the `Client` options.
17
+ ```mjs
18
+ import { MockAgent } from 'undici'
13
19
 
14
- Returns: `MockClient`
20
+ // `connections: 1` makes the agent hand out `MockClient` instances.
21
+ const mockAgent = new MockAgent({ connections: 1 })
22
+ const mockClient = mockAgent.get('http://localhost:3000')
23
+ ```
15
24
 
16
- ### Parameter: `MockClientOptions`
25
+ ```cjs
26
+ const { MockAgent } = require('undici')
17
27
 
18
- Extends: `ClientOptions`
28
+ const mockAgent = new MockAgent({ connections: 1 })
29
+ const mockClient = mockAgent.get('http://localhost:3000')
30
+ ```
31
+
32
+ ## Class: `MockClient`
19
33
 
20
- * **agent** `Agent` - the agent to associate this MockClient with.
34
+ <!-- YAML
35
+ added: v4.0.0
36
+ -->
21
37
 
22
- ### Example - Basic MockClient instantiation
38
+ * Extends: {Client}
23
39
 
24
- We can use MockAgent to instantiate a MockClient ready to be used to intercept specified requests. It will not do anything until registered as the agent to use and any mock request are registered.
40
+ Extends [`Client`][] and implements the `Interceptable` interface, allowing
41
+ requests made through it to be matched against registered mocks.
25
42
 
26
- ```js
43
+ ### `new MockClient(origin[, options])`
44
+
45
+ <!-- YAML
46
+ added: v4.0.0
47
+ -->
48
+
49
+ * `origin` {string} The origin to associate this mock client with. It should
50
+ only include the protocol, hostname, and port.
51
+ * `options` {MockClientOptions} Extends the [`Client`][] options.
52
+ * Returns: {MockClient}
53
+
54
+ The `agent` option is required and must implement the `Agent` interface;
55
+ otherwise an `InvalidArgumentError` is thrown.
56
+
57
+ #### Parameter: `MockClientOptions`
58
+
59
+ Extends: `ClientOptions`
60
+
61
+ * `agent` {MockAgent} The agent to associate this mock client with.
62
+ * `ignoreTrailingSlash` {boolean} Whether trailing slashes should be ignored
63
+ when matching the path of intercepted requests. **Default:** `false`.
64
+
65
+ ### `mockClient.intercept(options)`
66
+
67
+ <!-- YAML
68
+ added: v4.0.0
69
+ -->
70
+
71
+ * `options` {MockInterceptor.Options} The matching criteria for the requests to
72
+ intercept.
73
+ * `path` {string|RegExp|Function} The path to match against. A function
74
+ receives the request path as a `string` and returns a `boolean`.
75
+ * `method` {string|RegExp|Function} The method to match against. A function
76
+ receives the request method as a `string` and returns a `boolean`.
77
+ **Default:** `'GET'`.
78
+ * `body` {string|RegExp|Function} The body to match against. A function
79
+ receives the request body as a `string` and returns a `boolean`.
80
+ * `headers` {Object|Function} The headers to match against, as a map of header
81
+ name to a `string`, `RegExp`, or matching function, or a single function
82
+ that receives all headers and returns a `boolean`.
83
+ * `query` {Object} The query parameters to match against.
84
+ * `ignoreTrailingSlash` {boolean} Whether a trailing slash on `path` is
85
+ ignored when matching. Inherited from the mock client's
86
+ `ignoreTrailingSlash` option when not set.
87
+ * Returns: {MockInterceptor} The interceptor used to define the mocked reply.
88
+
89
+ Registers a route on the mock client and returns a [`MockInterceptor`][] for any
90
+ matching request that uses the same origin as this mock client. The interceptor
91
+ is then used to define the reply, for example with `reply()` or
92
+ `replyWithError()`.
93
+
94
+ ```mjs
27
95
  import { MockAgent } from 'undici'
28
96
 
29
- // Connections must be set to 1 to return a MockClient instance
30
97
  const mockAgent = new MockAgent({ connections: 1 })
98
+ const mockClient = mockAgent.get('http://localhost:3000')
99
+
100
+ mockClient.intercept({ path: '/foo', method: 'GET' }).reply(200, 'foo')
101
+ ```
102
+
103
+ ### `mockClient.cleanMocks()`
104
+
105
+ <!-- YAML
106
+ added: v7.11.0
107
+ -->
31
108
 
109
+ Removes all registered interceptors from the mock client. Pending mocks defined
110
+ before this call no longer match incoming requests.
111
+
112
+ ```mjs
113
+ import { MockAgent } from 'undici'
114
+
115
+ const mockAgent = new MockAgent({ connections: 1 })
32
116
  const mockClient = mockAgent.get('http://localhost:3000')
117
+
118
+ mockClient.intercept({ path: '/foo' }).reply(200, 'foo')
119
+ mockClient.cleanMocks()
33
120
  ```
34
121
 
35
- ## Instance Methods
122
+ ### `mockClient.close()`
36
123
 
37
- ### `MockClient.intercept(options)`
124
+ <!-- YAML
125
+ added: v4.0.0
126
+ -->
38
127
 
39
- Implements: [`MockPool.intercept(options)`](/docs/docs/api/MockPool.md#mockpoolinterceptoptions)
128
+ * Returns: {Promise} Fulfills with `undefined` once the mock client is closed.
40
129
 
41
- ### `MockClient.cleanMocks()`
130
+ Closes the mock client, gracefully waiting for any enqueued requests to
131
+ complete, and removes it from the associated [`MockAgent`][].
42
132
 
43
- Implements: [`MockPool.cleanMocks()`](/docs/docs/api/MockPool.md#mockpoolcleanmocks)
133
+ ```mjs
134
+ import { MockAgent } from 'undici'
44
135
 
45
- ### `MockClient.close()`
136
+ const mockAgent = new MockAgent({ connections: 1 })
137
+ const mockClient = mockAgent.get('http://localhost:3000')
138
+
139
+ await mockClient.close()
140
+ ```
46
141
 
47
- Implements: [`MockPool.close()`](/docs/docs/api/MockPool.md#mockpoolclose)
142
+ ### `mockClient.dispatch(options, handlers)`
48
143
 
49
- ### `MockClient.dispatch(options, handlers)`
144
+ <!-- YAML
145
+ added: v4.0.0
146
+ -->
50
147
 
51
- Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
148
+ * `options` {DispatchOptions} The request options.
149
+ * `handlers` {DispatchHandler} The handlers invoked over the request lifecycle.
150
+ * Returns: {boolean} `false` if the dispatcher is busy and the caller should
151
+ wait before dispatching further requests, otherwise `true`.
52
152
 
53
- ### `MockClient.request(options[, callback])`
153
+ Dispatches a request, matching it against the registered mocks. This override of
154
+ [`dispatcher.dispatch(options, handlers)`][] is what drives the mocking
155
+ behaviour for every higher-level method such as `request`.
54
156
 
55
- See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
157
+ ### `mockClient.request(options[, callback])`
56
158
 
57
- #### Example - MockClient request
159
+ <!-- YAML
160
+ added: v4.0.0
161
+ -->
58
162
 
59
- ```js
163
+ * `options` {DispatchOptions}
164
+ * `callback` {Function} (optional) Invoked with the response when no `Promise`
165
+ is requested.
166
+ * Returns: {Promise} Fulfills with the mocked response when no `callback` is
167
+ provided.
168
+
169
+ Performs a request and resolves it against the registered mocks. Inherited from
170
+ [`Client`][]; see [`dispatcher.request(options[, callback])`][] for the full
171
+ parameter and return value documentation.
172
+
173
+ ```mjs
60
174
  import { MockAgent } from 'undici'
61
175
 
62
176
  const mockAgent = new MockAgent({ connections: 1 })
63
-
64
177
  const mockClient = mockAgent.get('http://localhost:3000')
65
178
  mockClient.intercept({ path: '/foo' }).reply(200, 'foo')
66
179
 
67
- const {
68
- statusCode,
69
- body
70
- } = await mockClient.request({
180
+ const { statusCode, body } = await mockClient.request({
71
181
  origin: 'http://localhost:3000',
72
182
  path: '/foo',
73
183
  method: 'GET'
@@ -79,3 +189,11 @@ for await (const data of body) {
79
189
  console.log('data', data.toString('utf8')) // data foo
80
190
  }
81
191
  ```
192
+
193
+ [`Client`]: Client.md#class-client
194
+ [`MockAgent`]: MockAgent.md#class-mockagent
195
+ [`MockInterceptor`]: MockPool.md#return-mockinterceptor
196
+ [`MockPool`]: MockPool.md#class-mockpool
197
+ [`dispatcher.dispatch(options, handlers)`]: Dispatcher.md#dispatcherdispatchoptions-handler
198
+ [`dispatcher.request(options[, callback])`]: Dispatcher.md#dispatcherrequestoptions-callback
199
+ [`mockAgent.get(origin)`]: MockAgent.md#mockagentgetorigin
@@ -1,12 +1,63 @@
1
1
  # MockErrors
2
2
 
3
- Undici exposes a variety of mock error objects that you can use to enhance your mock error handling.
4
- You can find all the mock error objects inside the `mockErrors` key.
3
+ <!--introduced_in=v4.0.0-->
4
+ <!--type=module-->
5
+ <!-- source_link=lib/mock/mock-errors.js -->
6
+
7
+ > Stability: 2 - Stable
8
+
9
+ undici raises a dedicated error when a mocked request cannot be matched against
10
+ any registered interceptor. The mock error classes are exposed through the
11
+ `mockErrors` namespace of the package:
12
+
13
+ ```js
14
+ import { mockErrors } from 'undici'
15
+
16
+ if (err instanceof mockErrors.MockNotMatchedError) {
17
+ // handle an unmatched mocked request
18
+ }
19
+ ```
20
+
21
+ Like every other undici error, the classes in this namespace extend
22
+ [`UndiciError`][] and carry a stable `code` string, so failures can be
23
+ distinguished programmatically without relying on the error message.
24
+
25
+ ## Class: `MockNotMatchedError`
26
+
27
+ <!-- YAML
28
+ added: v4.0.0
29
+ -->
30
+
31
+ * Extends: {UndiciError}
32
+
33
+ Thrown when a request issued against a [`MockAgent`][] does not match any of the
34
+ registered mock dispatches and the agent is configured to disable net connect.
35
+
36
+ * `name` {string} Always `'MockNotMatchedError'`.
37
+ * `code` {string} Always `'UND_MOCK_ERR_MOCK_NOT_MATCHED'`.
38
+
39
+ ### `new MockNotMatchedError([message])`
40
+
41
+ <!-- YAML
42
+ added: v4.0.0
43
+ -->
44
+
45
+ * `message` {string} The error message. **Default:** `'The request does not match any registered mock dispatches'`.
46
+
47
+ Creates a new `MockNotMatchedError`. When `message` is omitted, a default
48
+ message describing the unmatched request is used.
5
49
 
6
50
  ```js
7
51
  import { mockErrors } from 'undici'
52
+
53
+ try {
54
+ // ... perform a request that no mock matches ...
55
+ } catch (err) {
56
+ if (err.code === 'UND_MOCK_ERR_MOCK_NOT_MATCHED') {
57
+ console.error('No registered mock matched the request')
58
+ }
59
+ }
8
60
  ```
9
61
 
10
- | Mock Error | Mock Error Codes | Description |
11
- | --------------------- | ------------------------------- | ---------------------------------------------------------- |
12
- | `MockNotMatchedError` | `UND_MOCK_ERR_MOCK_NOT_MATCHED` | The request does not match any registered mock dispatches. |
62
+ [`MockAgent`]: MockAgent.md#class-mockagent
63
+ [`UndiciError`]: Errors.md#class-undicierror