@c9up/ream 0.1.26 → 0.1.28

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 (179) hide show
  1. package/README.md +65 -0
  2. package/dist/Ignitor.d.ts +115 -7
  3. package/dist/Ignitor.d.ts.map +1 -1
  4. package/dist/Ignitor.js +233 -37
  5. package/dist/Ignitor.js.map +1 -1
  6. package/dist/console/BaseCommand.d.ts +217 -0
  7. package/dist/console/BaseCommand.d.ts.map +1 -0
  8. package/dist/console/BaseCommand.js +340 -0
  9. package/dist/console/BaseCommand.js.map +1 -0
  10. package/dist/console/Console.d.ts +86 -0
  11. package/dist/console/Console.d.ts.map +1 -0
  12. package/dist/console/Console.js +134 -0
  13. package/dist/console/Console.js.map +1 -0
  14. package/dist/console/ExceptionHandler.d.ts +28 -0
  15. package/dist/console/ExceptionHandler.d.ts.map +1 -0
  16. package/dist/console/ExceptionHandler.js +76 -0
  17. package/dist/console/ExceptionHandler.js.map +1 -0
  18. package/dist/console/HelpCommand.d.ts +16 -0
  19. package/dist/console/HelpCommand.d.ts.map +1 -0
  20. package/dist/console/HelpCommand.js +40 -0
  21. package/dist/console/HelpCommand.js.map +1 -0
  22. package/dist/console/IndexGenerator.d.ts +24 -0
  23. package/dist/console/IndexGenerator.d.ts.map +1 -0
  24. package/dist/console/IndexGenerator.js +65 -0
  25. package/dist/console/IndexGenerator.js.map +1 -0
  26. package/dist/console/Kernel.d.ts +298 -0
  27. package/dist/console/Kernel.d.ts.map +1 -0
  28. package/dist/console/Kernel.js +1120 -0
  29. package/dist/console/Kernel.js.map +1 -0
  30. package/dist/console/ListCommand.d.ts +18 -0
  31. package/dist/console/ListCommand.d.ts.map +1 -0
  32. package/dist/console/ListCommand.js +60 -0
  33. package/dist/console/ListCommand.js.map +1 -0
  34. package/dist/console/assertions.d.ts +20 -0
  35. package/dist/console/assertions.d.ts.map +1 -0
  36. package/dist/console/assertions.js +84 -0
  37. package/dist/console/assertions.js.map +1 -0
  38. package/dist/console/cliui.d.ts +248 -0
  39. package/dist/console/cliui.d.ts.map +1 -0
  40. package/dist/console/cliui.js +587 -0
  41. package/dist/console/cliui.js.map +1 -0
  42. package/dist/console/decorators.d.ts +90 -0
  43. package/dist/console/decorators.d.ts.map +1 -0
  44. package/dist/console/decorators.js +142 -0
  45. package/dist/console/decorators.js.map +1 -0
  46. package/dist/console/index.d.ts +32 -0
  47. package/dist/console/index.d.ts.map +1 -0
  48. package/dist/console/index.js +24 -0
  49. package/dist/console/index.js.map +1 -0
  50. package/dist/console/loaders.d.ts +52 -0
  51. package/dist/console/loaders.d.ts.map +1 -0
  52. package/dist/console/loaders.js +131 -0
  53. package/dist/console/loaders.js.map +1 -0
  54. package/dist/console/parser.d.ts +86 -0
  55. package/dist/console/parser.d.ts.map +1 -0
  56. package/dist/console/parser.js +440 -0
  57. package/dist/console/parser.js.map +1 -0
  58. package/dist/console/prompts.d.ts +124 -0
  59. package/dist/console/prompts.d.ts.map +1 -0
  60. package/dist/console/prompts.js +364 -0
  61. package/dist/console/prompts.js.map +1 -0
  62. package/dist/console/tracing.d.ts +17 -0
  63. package/dist/console/tracing.d.ts.map +1 -0
  64. package/dist/console/tracing.js +11 -0
  65. package/dist/console/tracing.js.map +1 -0
  66. package/dist/console/types.d.ts +255 -0
  67. package/dist/console/types.d.ts.map +1 -0
  68. package/dist/console/types.js +25 -0
  69. package/dist/console/types.js.map +1 -0
  70. package/dist/console/ui.d.ts +20 -0
  71. package/dist/console/ui.d.ts.map +1 -0
  72. package/dist/console/ui.js +31 -0
  73. package/dist/console/ui.js.map +1 -0
  74. package/dist/console/utils.d.ts +27 -0
  75. package/dist/console/utils.d.ts.map +1 -0
  76. package/dist/console/utils.js +56 -0
  77. package/dist/console/utils.js.map +1 -0
  78. package/dist/container/Container.d.ts.map +1 -1
  79. package/dist/container/Container.js +40 -12
  80. package/dist/container/Container.js.map +1 -1
  81. package/dist/container/types.d.ts +14 -2
  82. package/dist/container/types.d.ts.map +1 -1
  83. package/dist/decorators/Service.d.ts +7 -0
  84. package/dist/decorators/Service.d.ts.map +1 -1
  85. package/dist/decorators/Service.js +23 -3
  86. package/dist/decorators/Service.js.map +1 -1
  87. package/dist/errors/ReamError.d.ts +25 -0
  88. package/dist/errors/ReamError.d.ts.map +1 -1
  89. package/dist/errors/ReamError.js +5 -0
  90. package/dist/errors/ReamError.js.map +1 -1
  91. package/dist/errors/prettyPrintError.d.ts +9 -0
  92. package/dist/errors/prettyPrintError.d.ts.map +1 -0
  93. package/dist/errors/prettyPrintError.js +22 -0
  94. package/dist/errors/prettyPrintError.js.map +1 -0
  95. package/dist/index.d.ts +14 -4
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +16 -2
  98. package/dist/index.js.map +1 -1
  99. package/dist/middleware/Pipeline.d.ts +29 -8
  100. package/dist/middleware/Pipeline.d.ts.map +1 -1
  101. package/dist/middleware/Pipeline.js +39 -1
  102. package/dist/middleware/Pipeline.js.map +1 -1
  103. package/dist/rpc/RpcRouter.d.ts.map +1 -1
  104. package/dist/rpc/RpcRouter.js +13 -2
  105. package/dist/rpc/RpcRouter.js.map +1 -1
  106. package/dist/services/app.d.ts +1 -1
  107. package/dist/services/app.js +1 -1
  108. package/dist/services/console.d.ts +21 -0
  109. package/dist/services/console.d.ts.map +1 -0
  110. package/dist/services/console.js +35 -0
  111. package/dist/services/console.js.map +1 -0
  112. package/dist/testing/ApiResponse.d.ts +218 -0
  113. package/dist/testing/ApiResponse.d.ts.map +1 -0
  114. package/dist/testing/ApiResponse.js +576 -0
  115. package/dist/testing/ApiResponse.js.map +1 -0
  116. package/dist/testing/RequestBuilder.d.ts +132 -72
  117. package/dist/testing/RequestBuilder.d.ts.map +1 -1
  118. package/dist/testing/RequestBuilder.js +389 -222
  119. package/dist/testing/RequestBuilder.js.map +1 -1
  120. package/dist/testing/TestClient.d.ts +34 -39
  121. package/dist/testing/TestClient.d.ts.map +1 -1
  122. package/dist/testing/TestClient.js +48 -56
  123. package/dist/testing/TestClient.js.map +1 -1
  124. package/dist/utils/Macroable.js +3 -3
  125. package/dist/utils/Macroable.js.map +1 -1
  126. package/events.darwin-arm64.node +0 -0
  127. package/events.darwin-x64.node +0 -0
  128. package/events.linux-arm64-gnu.node +0 -0
  129. package/events.linux-x64-gnu.node +0 -0
  130. package/events.win32-x64-msvc.node +0 -0
  131. package/index.darwin-arm64.node +0 -0
  132. package/index.darwin-x64.node +0 -0
  133. package/index.linux-arm64-gnu.node +0 -0
  134. package/index.linux-x64-gnu.node +0 -0
  135. package/index.win32-x64-msvc.node +0 -0
  136. package/package.json +15 -2
  137. package/scheduler.darwin-arm64.node +0 -0
  138. package/scheduler.darwin-x64.node +0 -0
  139. package/scheduler.linux-arm64-gnu.node +0 -0
  140. package/scheduler.linux-x64-gnu.node +0 -0
  141. package/scheduler.win32-x64-msvc.node +0 -0
  142. package/src/Ignitor.ts +340 -42
  143. package/src/console/BaseCommand.ts +467 -0
  144. package/src/console/Console.ts +174 -0
  145. package/src/console/ExceptionHandler.ts +91 -0
  146. package/src/console/HelpCommand.ts +37 -0
  147. package/src/console/IndexGenerator.ts +79 -0
  148. package/src/console/Kernel.ts +1382 -0
  149. package/src/console/ListCommand.ts +55 -0
  150. package/src/console/assertions.ts +114 -0
  151. package/src/console/cliui.ts +756 -0
  152. package/src/console/decorators.ts +199 -0
  153. package/src/console/index.ts +67 -0
  154. package/src/console/loaders.ts +145 -0
  155. package/src/console/parser.ts +598 -0
  156. package/src/console/prompts.ts +556 -0
  157. package/src/console/tracing.ts +22 -0
  158. package/src/console/types.ts +280 -0
  159. package/src/console/ui.ts +37 -0
  160. package/src/console/utils.ts +69 -0
  161. package/src/container/Container.ts +55 -13
  162. package/src/container/types.ts +15 -2
  163. package/src/decorators/Service.ts +28 -3
  164. package/src/errors/ReamError.ts +31 -0
  165. package/src/errors/prettyPrintError.ts +20 -0
  166. package/src/index.ts +30 -4
  167. package/src/middleware/Pipeline.ts +76 -5
  168. package/src/rpc/RpcRouter.ts +16 -2
  169. package/src/services/app.ts +1 -1
  170. package/src/services/console.ts +42 -0
  171. package/src/testing/ApiResponse.ts +691 -0
  172. package/src/testing/RequestBuilder.ts +498 -275
  173. package/src/testing/TestClient.ts +63 -86
  174. package/src/utils/Macroable.ts +3 -3
  175. package/dist/console/CommandRunner.d.ts +0 -18
  176. package/dist/console/CommandRunner.d.ts.map +0 -1
  177. package/dist/console/CommandRunner.js +0 -65
  178. package/dist/console/CommandRunner.js.map +0 -1
  179. package/src/console/CommandRunner.ts +0 -82
@@ -1,17 +1,21 @@
1
- import type { TestResponse } from './TestClient.js';
2
1
  /**
3
- * Fluent HTTP request builder with assertion methods.
2
+ * Fluent HTTP request builder with assertion methods (`@japa/api-client` model).
4
3
  *
5
4
  * await client
6
- * .fluent('GET', '/api/users/42')
5
+ * .get('/api/users/42')
7
6
  * .withAuth(user)
8
- * .expectStatus(200)
9
- * .expectJson({ id: 42 })
7
+ * .assertOk()
8
+ * .assertBody({ id: 42 })
10
9
  *
11
- * The builder chains: setters return `this`, assertion methods send the
12
- * request on first call (memoised) and return a `Promise<this>` so further
13
- * assertions can be awaited or chained via `await`.
10
+ * The builder chains SYNCHRONOUSLY: setters and assertion methods both return
11
+ * `this`. Assertions are LAZY — each registers a check; the request is sent once
12
+ * and every check runs, in order, when the builder is awaited (it is thenable,
13
+ * so `await builder` resolves to the {@link ApiResponse}). A plain
14
+ * `await client.get('/x')` (no assertion) just sends and returns the response.
14
15
  */
16
+ import type { Readable } from 'node:stream';
17
+ import { ApiResponse, type StatusAssertions, type TestResponse } from './ApiResponse.js';
18
+ export { ApiResponse, deepEqual, partialMatch, type ResponseCookie, type ResponseError, type ResponseFile, type TestResponse, } from './ApiResponse.js';
15
19
  export interface AuthSubject {
16
20
  /** String or numeric user id — used by `withAuth` / `asUser` to sign the session. */
17
21
  id: string | number;
@@ -24,11 +28,20 @@ export interface AuthStrategy {
24
28
  /** Compute cookies for session-based strategies. */
25
29
  cookiesFor?(subject: AuthSubject): Record<string, string> | Promise<Record<string, string>>;
26
30
  }
27
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
31
+ /**
32
+ * HTTP methods. The common verbs are named; `request(url, method)` also accepts
33
+ * any other method (e.g. `TRACE`, `CONNECT`) — Japa parity — via the wider
34
+ * string fallback.
35
+ */
36
+ export type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'TRACE' | 'CONNECT' | (string & {});
28
37
  /** Primitive accepted as a query-string value (mirrors `.qs()` in japa/api-client). */
29
38
  type QueryValue = string | number | boolean;
30
39
  /** Query-string map — a value or an array of values (repeated key). */
31
40
  export type QueryParams = Record<string, QueryValue | ReadonlyArray<QueryValue>>;
41
+ /** A scalar accepted by `form()`/`fields()` — Japa parity (arrays repeat the key). */
42
+ export type FieldValue = string | number | boolean | Buffer;
43
+ /** A value accepted by a multipart `field()`/`file()` — Japa parity (incl. streams/blobs). */
44
+ export type MultipartValue = string | number | boolean | Buffer | Blob | Readable;
32
45
  /**
33
46
  * Internal low-level sender — matches what the TestClient exposes.
34
47
  * Accepting it as an injected callable keeps RequestBuilder framework-agnostic.
@@ -36,10 +49,12 @@ export type QueryParams = Record<string, QueryValue | ReadonlyArray<QueryValue>>
36
49
  export type HttpSender = (method: HttpMethod, path: string, init: {
37
50
  headers: Record<string, string>;
38
51
  body: Buffer;
52
+ /** Per-request socket timeout (ms) — Japa `.timeout()`. Sender may honour it. */
53
+ timeoutMs?: number;
39
54
  }) => Promise<TestResponse>;
40
55
  /** Options for a multipart file part — mirrors Adonis/japa's `.file()` options. */
41
56
  export interface FilePart {
42
- /** Filename advertised in the part's `Content-Disposition`. Defaults to the field name. */
57
+ /** Filename advertised in the part's `Content-Disposition`. Defaults to the field name / basename. */
43
58
  filename?: string;
44
59
  /** MIME type of the part. Defaults to `application/octet-stream`. */
45
60
  contentType?: string;
@@ -48,24 +63,32 @@ export declare class RequestBuilder {
48
63
  #private;
49
64
  constructor(sender: HttpSender, method: HttpMethod, path: string, authStrategy?: AuthStrategy | null);
50
65
  headers(map: Record<string, string>): this;
51
- header(name: string, value: string): this;
66
+ header(name: string, value: string | string[]): this;
52
67
  json(data: unknown): this;
68
+ /** Japa `.unsafeJson()` — set a JSON body without any transform (alias of {@link json}). */
69
+ unsafeJson(data: unknown): this;
53
70
  body(data: Buffer | string, contentType?: string): this;
54
- form(data: Record<string, string>): this;
71
+ form(data: Record<string, FieldValue | FieldValue[]>): this;
72
+ /** Japa `.unsafeForm()` — set a urlencoded body without transform (alias of {@link form}). */
73
+ unsafeForm(data: Record<string, FieldValue | FieldValue[]>): this;
55
74
  /**
56
- * Add a `multipart/form-data` text field — mirrors Adonis/japa's `.field()`.
57
- * Calling `.field()` or `.file()` switches the body to multipart (use
58
- * `.form()` for `application/x-www-form-urlencoded`). The boundary +
59
- * `Content-Type` header are produced at send time.
75
+ * Add a `multipart/form-data` field — mirrors Adonis/japa's `.field()`. Accepts
76
+ * a string/number/boolean, a Buffer, a Blob, a Readable stream, or an array of
77
+ * these (repeated part). Calling `.field()`/`.fields()`/`.file()` switches the
78
+ * body to multipart; the boundary + `Content-Type` header are produced at send
79
+ * time (streams/blobs are drained to Buffers then).
60
80
  */
61
- field(name: string, value: string): this;
81
+ field(name: string, value: MultipartValue | MultipartValue[]): this;
82
+ /** Add several multipart fields at once — Japa `.fields()`. */
83
+ fields(map: Record<string, MultipartValue | MultipartValue[]>): this;
62
84
  /**
63
85
  * Attach a file as a `multipart/form-data` part — mirrors Adonis/japa's
64
- * `.file(field, contents, { filename, contentType })`. `contents` is a
65
- * Buffer (binary) or a string (encoded as utf8). Server-side
66
- * `request.file(field, …)` reads the resulting part.
86
+ * `.file(field, value, { filename, contentType })`. `value` is a Buffer, a
87
+ * Blob, a Readable stream, OR a string absolute PATH to a file on disk (read at
88
+ * call time, Japa parity). The filename defaults to the path basename / field
89
+ * name; streams/blobs are drained to Buffers at send time.
67
90
  */
68
- file(field: string, contents: Buffer | string, options?: FilePart): this;
91
+ file(field: string, value: Buffer | string | Blob | Readable, options?: FilePart): this;
69
92
  cookies(map: Record<string, string>): this;
70
93
  cookie(name: string, value: string): this;
71
94
  /**
@@ -74,75 +97,112 @@ export declare class RequestBuilder {
74
97
  * string already on the path and with earlier `.qs()` calls.
75
98
  */
76
99
  qs(params: QueryParams): this;
100
+ /**
101
+ * Append query params WITHOUT any validation/normalisation — Japa
102
+ * `.unsafeQs({ … })`. Values are still URL-encoded so the wire stays valid, but
103
+ * (unlike `.qs()`) no key filtering is applied; arrays repeat the key.
104
+ */
105
+ unsafeQs(params: QueryParams): this;
77
106
  /** Pass a bearer token as the `Authorization` header — japa `.bearerToken()`. */
78
107
  bearerToken(token: string): this;
79
108
  /** Pass HTTP Basic credentials as the `Authorization` header — japa `.basicAuth()`. */
80
109
  basicAuth(user: string, password: string): this;
110
+ /**
111
+ * Set the request `Content-Type` from a shorthand (`'json'`, `'form'`, …) or a
112
+ * full MIME type — mirrors japa/api-client's `.type()`.
113
+ */
114
+ type(mime: string): this;
115
+ /**
116
+ * Set the `Accept` header from a shorthand (`'json'`, `'html'`, …) or a full
117
+ * MIME type — mirrors japa/api-client's `.accept()`.
118
+ */
119
+ accept(mime: string): this;
120
+ /** Per-request timeout in ms — Japa `.timeout()`. Honoured by the sender. */
121
+ timeout(ms: number): this;
122
+ /**
123
+ * Follow up to `count` redirects before resolving — Japa `.redirects()`.
124
+ * Defaults to 5 (Japa default); pass `0` to disable following.
125
+ */
126
+ redirects(count: number): this;
127
+ /** No-op: the loopback test server has no TLS — Japa `.trustLocalhost()`. */
128
+ trustLocalhost(_trust?: boolean): this;
129
+ /** No-op: no TLS on the loopback test server — Japa `.ca()`. */
130
+ ca(_cert: string): this;
131
+ /** No-op: no TLS on the loopback test server — Japa `.cert()`. */
132
+ cert(_chain: string): this;
133
+ /** No-op: no TLS on the loopback test server — Japa `.privateKey()`. */
134
+ privateKey(_key: string): this;
135
+ /** No-op: no TLS on the loopback test server — Japa `.pfx()`. */
136
+ pfx(_encoded: string | Buffer): this;
137
+ /** No-op: no TLS on the loopback test server — Japa `.disableTLSCerts()`. */
138
+ disableTLSCerts(): this;
81
139
  /**
82
140
  * Satisfy blackhole's signed double-submit CSRF check: echo the `XSRF-TOKEN`
83
141
  * cookie back in the `X-XSRF-TOKEN` header (the pair the server compares).
84
- *
85
- * With a `token` argument, sets both the cookie and the header — useful when
86
- * you already hold a signed token. Without one, reads the token from a cookie
87
- * set earlier on this request (typically extracted from a prior safe GET's
88
- * `Set-Cookie`); throws if none is present so the mistake is caught at the
89
- * call site instead of surfacing as a confusing 403.
90
142
  */
91
143
  withCsrf(token?: string): this;
144
+ /** japa/api-client's spelling of {@link withCsrf}. */
145
+ withCsrfToken(token?: string): this;
92
146
  /**
93
147
  * Attach auth for a user. Uses the strategy passed to `client`'s `auth`
94
- * option — Warden's session/JWT/API-key strategy decides the header/cookie
95
- * shape. Without a strategy, throws at send time.
148
+ * option. Without a strategy, throws at send time.
96
149
  */
97
150
  withAuth(subject: AuthSubject): this;
98
151
  /** Shortcut for `withAuth({ id: userId })` — user is identified by id only. */
99
152
  asUser(userId: string | number): this;
100
- /** Fire the request (once) and return the raw response. Idempotent. */
101
- send(): Promise<TestResponse>;
102
- expectStatus(code: number): Promise<this>;
103
- expectHeader(name: string, value: string | RegExp): Promise<this>;
104
- expectCookie(name: string, value?: string | RegExp): Promise<this>;
105
- expectJson(expected: unknown): Promise<this>;
106
- /** Assert a 200 OK response. */
107
- assertOk(): Promise<this>;
108
- /** Assert a 201 Created response. */
109
- assertCreated(): Promise<this>;
110
- /** Assert a 204 No Content response. */
111
- assertNoContent(): Promise<this>;
112
- /** Assert a 400 Bad Request response. */
113
- assertBadRequest(): Promise<this>;
114
- /** Assert a 401 Unauthorized response. */
115
- assertUnauthorized(): Promise<this>;
116
- /** Assert a 403 Forbidden response. */
117
- assertForbidden(): Promise<this>;
118
- /** Assert a 404 Not Found response. */
119
- assertNotFound(): Promise<this>;
153
+ /** Fire the request (once) and return the rich response. Idempotent. */
154
+ send(): Promise<ApiResponse>;
155
+ /**
156
+ * Thenable — `await client.get('/x')` sends the request and resolves to the
157
+ * {@link ApiResponse} (Japa/api-client parity). Assertion methods return `this`;
158
+ * awaiting one resolves via this `then` to the response after running the checks.
159
+ */
160
+ then<R1 = ApiResponse, R2 = never>(onFulfilled?: ((value: ApiResponse) => R1 | PromiseLike<R1>) | null, onRejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
161
+ expectStatus(code: number): this;
162
+ expectHeader(name: string, value: string | RegExp): this;
163
+ expectCookie(name: string, value?: string | RegExp): this;
164
+ expectJson(expected: unknown): this;
165
+ assertStatus(code: number): this;
166
+ assertHeader(name: string, value?: string | RegExp): this;
167
+ assertHeaderMissing(name: string): this;
168
+ assertCookie(name: string, value?: string | RegExp): this;
169
+ assertCookieMissing(name: string): this;
170
+ assertBody(expected: unknown): this;
171
+ assertBodyContains(subset: unknown): this;
172
+ assertBodyNotContains(subset: unknown): this;
173
+ assertTextIncludes(substring: string): this;
174
+ assertRedirectsTo(path: string): this;
175
+ /** Print the pending request (method/path/headers/body) — Japa `request.dump()`. */
176
+ dump(): this;
177
+ /** Print only the pending request body — Japa `request.dumpBody()`. */
178
+ dumpBody(): this;
179
+ /** Print only the pending request headers — Japa `request.dumpHeaders()`. */
180
+ dumpHeaders(): this;
181
+ /** Print only the pending request cookies — Japa `request.dumpCookies()`. */
182
+ dumpCookies(): this;
120
183
  /**
121
- * Assert a redirect (3xx) whose `Location` resolves to `path`. Compares the
122
- * pathname (query/host ignored), mirroring japa's `assertRedirectsTo`.
184
+ * Serialize `data` with a registered serializer and set it as the request body
185
+ * — the send-side twin of {@link ApiResponse.addParser}. Register serializers
186
+ * via {@link RequestBuilder.addSerializer} (Japa `ApiRequest.addSerializer`).
123
187
  */
124
- assertRedirectsTo(path: string): Promise<this>;
125
- /** Assert the JSON body contains `subset` (deep partial) — japa `assertBodyContains`. */
126
- assertBodyContains(subset: unknown): Promise<this>;
127
- /** Assert the JSON body does NOT contain `subset` — japa `assertBodyNotContains`. */
128
- assertBodyNotContains(subset: unknown): Promise<this>;
188
+ serialize(name: string, data: unknown): this;
129
189
  /**
130
- * Assert a response header is present, and equals `value` when given. Unlike
131
- * {@link expectHeader}, the value is optional (presence-only check).
190
+ * Register a shared property (Japa `ApiRequest.macro`) or lazy getter
191
+ * (`ApiRequest.getter`). The callback is invoked with `this` bound to the
192
+ * builder AND the builder as its first arg, so both Japa's
193
+ * `function () { return this.header('x') }` and `(req) => …` work.
132
194
  */
133
- assertHeader(name: string, value?: string): Promise<this>;
134
- /** Assert a response header is absent — japa `assertHeaderMissing`. */
135
- assertHeaderMissing(name: string): Promise<this>;
136
- /** Assert the response set a cookie, optionally with a given value — japa `assertCookie`. */
137
- assertCookie(name: string, value?: string): Promise<this>;
138
- /** Assert the response did NOT set a cookie — japa `assertCookieMissing`. */
139
- assertCookieMissing(name: string): Promise<this>;
195
+ static macro(name: string, value: unknown): void;
196
+ static getter(name: string, fn: (this: RequestBuilder, req: RequestBuilder) => unknown): void;
197
+ /** Register a request body serializer — Japa `ApiRequest.addSerializer`. */
198
+ static addSerializer(name: string, fn: (data: unknown) => {
199
+ body: Buffer;
200
+ contentType: string;
201
+ }): void;
202
+ /** Register a response body parser — Japa `ApiRequest.addParser` (delegates to ApiResponse). */
203
+ static addParser(contentType: string, fn: (body: string, headers: Record<string, string>) => unknown): void;
204
+ }
205
+ /** The status-shortcut assertions (lazy) are typed onto the builder. */
206
+ export interface RequestBuilder extends StatusAssertions<RequestBuilder> {
140
207
  }
141
- /**
142
- * Partial deep-match. For objects, every key in `expected` must match in
143
- * `actual`. For arrays, every element in `expected` must match SOMEWHERE in
144
- * `actual` (order-independent). Primitives compared by strict equality.
145
- */
146
- export declare function partialMatch(actual: unknown, expected: unknown): boolean;
147
- export {};
148
208
  //# sourceMappingURL=RequestBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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