@procedures/client 0.41.1 → 0.43.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 (63) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapters/http/client/batch.d.ts +98 -0
  4. package/dist/adapters/http/client/batch.d.ts.map +1 -0
  5. package/dist/adapters/http/client/batch.js +414 -0
  6. package/dist/adapters/http/client/batch.js.map +1 -0
  7. package/dist/adapters/http/client/index.d.ts +1 -0
  8. package/dist/adapters/http/client/index.d.ts.map +1 -1
  9. package/dist/adapters/http/client/index.js.map +1 -1
  10. package/dist/adapters/http/client/transport.d.ts +7 -0
  11. package/dist/adapters/http/client/transport.d.ts.map +1 -1
  12. package/dist/adapters/http/client/transport.js +27 -1
  13. package/dist/adapters/http/client/transport.js.map +1 -1
  14. package/dist/adapters/http/client/types.d.ts +9 -0
  15. package/dist/adapters/http/client/types.d.ts.map +1 -1
  16. package/dist/adapters/http/server/addressing.d.ts +5 -0
  17. package/dist/adapters/http/server/addressing.d.ts.map +1 -1
  18. package/dist/adapters/http/server/addressing.js +1 -1
  19. package/dist/adapters/http/server/addressing.js.map +1 -1
  20. package/dist/adapters/http/server/batch.d.ts +105 -0
  21. package/dist/adapters/http/server/batch.d.ts.map +1 -0
  22. package/dist/adapters/http/server/batch.js +172 -0
  23. package/dist/adapters/http/server/batch.js.map +1 -0
  24. package/dist/adapters/http/server/handler.d.ts +8 -0
  25. package/dist/adapters/http/server/handler.d.ts.map +1 -1
  26. package/dist/adapters/http/server/handler.js +103 -16
  27. package/dist/adapters/http/server/handler.js.map +1 -1
  28. package/dist/adapters/http/server/transport.d.ts.map +1 -1
  29. package/dist/adapters/http/server/transport.js +13 -2
  30. package/dist/adapters/http/server/transport.js.map +1 -1
  31. package/dist/adapters/http/server/types.d.ts +7 -0
  32. package/dist/adapters/http/server/types.d.ts.map +1 -1
  33. package/dist/adapters/http/shared/errors.d.ts +6 -8
  34. package/dist/adapters/http/shared/errors.d.ts.map +1 -1
  35. package/dist/adapters/http/shared/errors.js +10 -9
  36. package/dist/adapters/http/shared/errors.js.map +1 -1
  37. package/dist/adapters/http/shared/status-codes.d.ts +13 -9
  38. package/dist/adapters/http/shared/status-codes.d.ts.map +1 -1
  39. package/dist/adapters/http/shared/status-codes.js +21 -19
  40. package/dist/adapters/http/shared/status-codes.js.map +1 -1
  41. package/dist/browser.d.ts +1 -1
  42. package/dist/browser.d.ts.map +1 -1
  43. package/dist/browser.js.map +1 -1
  44. package/dist/client/index.d.ts +1 -1
  45. package/dist/client/index.d.ts.map +1 -1
  46. package/dist/node.d.ts +1 -0
  47. package/dist/node.d.ts.map +1 -1
  48. package/dist/node.js.map +1 -1
  49. package/package.json +3 -3
  50. package/src/adapters/http/client/batch.ts +463 -0
  51. package/src/adapters/http/client/index.ts +1 -0
  52. package/src/adapters/http/client/transport.ts +31 -1
  53. package/src/adapters/http/client/types.ts +10 -0
  54. package/src/adapters/http/server/addressing.ts +1 -1
  55. package/src/adapters/http/server/batch.ts +237 -0
  56. package/src/adapters/http/server/handler.ts +119 -17
  57. package/src/adapters/http/server/transport.ts +15 -4
  58. package/src/adapters/http/server/types.ts +8 -0
  59. package/src/adapters/http/shared/errors.ts +10 -9
  60. package/src/adapters/http/shared/status-codes.ts +21 -21
  61. package/src/browser.ts +1 -0
  62. package/src/client/index.ts +1 -1
  63. package/src/node.ts +2 -0
@@ -6,23 +6,23 @@
6
6
  */
7
7
 
8
8
  import { HTTPStatus, HTTP } from "./constants.js";
9
+ import { ERROR_REGISTRY } from "../../../client/errors/registry.js";
10
+ import { httpStatusToErrorCode } from "../../../client/errors/http-errors.js";
9
11
 
10
12
  /**
11
13
  * HTTP Status Code to String Code Mapping
12
14
  *
13
- * Maps numeric status codes to semantic string codes.
15
+ * This table maps numeric status codes to semantic string codes.
14
16
  *
15
- * `createHTTPStatusError()` takes the error code of a status from this table. Three error codes of
16
- * the table are not in `ERROR_REGISTRY`. They are deprecated as error codes. The next MINOR of the
17
- * client group gives the code of `ERROR_REGISTRY` in their place, as `httpStatusToErrorCode()` does:
17
+ * The table holds the names of the statuses. It does not hold the error codes.
18
+ * `createHTTPStatusError()` gives the code of `ERROR_REGISTRY` for a status. Three names are not
19
+ * error codes:
18
20
  *
19
- * | Status | The code at this time | The code of the next MINOR | Retryable in the next MINOR |
21
+ * | Status | Name | Error code | Retryable |
20
22
  * |---|---|---|---|
21
23
  * | 408 | `REQUEST_TIMEOUT` | `TIMEOUT` | true: the server did not read the full request, so the call did not start |
22
24
  * | 500 | `INTERNAL_SERVER_ERROR` | `INTERNAL_ERROR` | false, as `ERROR_CODES` gives: the call can have had its effect |
23
25
  * | 599 | `HTTP_NETWORK_CONNECT_TIMEOUT_ERROR` | `HTTP_NETWORK_CONNECT_TIMEOUT` | true, as `ERROR_REGISTRY` gives |
24
- *
25
- * The table stays as the names of the statuses.
26
26
  */
27
27
  export const HTTPStatusToCode: Record<HTTPStatus, string> = {
28
28
  [HTTPStatus.UNKNOWN]: "UNKNOWN",
@@ -56,7 +56,6 @@ export const HTTPStatusToCode: Record<HTTPStatus, string> = {
56
56
  [HTTPStatus.METHOD_NOT_ALLOWED]: "METHOD_NOT_ALLOWED",
57
57
  [HTTPStatus.NOT_ACCEPTABLE]: "NOT_ACCEPTABLE",
58
58
  [HTTPStatus.PROXY_AUTHENTICATION_REQUIRED]: "PROXY_AUTHENTICATION_REQUIRED",
59
- /** @deprecated As an error code. The next MINOR gives `TIMEOUT` of `ERROR_REGISTRY`. */
60
59
  [HTTPStatus.REQUEST_TIMEOUT]: "REQUEST_TIMEOUT",
61
60
  [HTTPStatus.CONFLICT]: "CONFLICT",
62
61
  [HTTPStatus.GONE]: "GONE",
@@ -80,7 +79,6 @@ export const HTTPStatusToCode: Record<HTTPStatus, string> = {
80
79
  "REQUEST_HEADER_FIELDS_TOO_LARGE",
81
80
  [HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS]: "UNAVAILABLE_FOR_LEGAL_REASONS",
82
81
  [HTTPStatus.CLIENT_CLOSED_REQUEST]: "CLIENT_CLOSED_REQUEST",
83
- /** @deprecated As an error code. The next MINOR gives `INTERNAL_ERROR` of `ERROR_REGISTRY`. */
84
82
  [HTTPStatus.INTERNAL_SERVER_ERROR]: "INTERNAL_SERVER_ERROR",
85
83
  [HTTPStatus.NOT_IMPLEMENTED]: "NOT_IMPLEMENTED",
86
84
  [HTTPStatus.BAD_GATEWAY]: "BAD_GATEWAY",
@@ -93,7 +91,6 @@ export const HTTPStatusToCode: Record<HTTPStatus, string> = {
93
91
  [HTTPStatus.NOT_EXTENDED]: "NOT_EXTENDED",
94
92
  [HTTPStatus.NETWORK_AUTHENTICATION_REQUIRED]:
95
93
  "NETWORK_AUTHENTICATION_REQUIRED",
96
- /** @deprecated As an error code. The next MINOR gives `HTTP_NETWORK_CONNECT_TIMEOUT` of `ERROR_REGISTRY`. */
97
94
  [HTTPStatus.HTTP_NETWORK_CONNECT_TIMEOUT_ERROR]:
98
95
  "HTTP_NETWORK_CONNECT_TIMEOUT_ERROR",
99
96
  } as const satisfies Record<HTTPStatus, string>;
@@ -158,24 +155,27 @@ export function isErrorStatus(status: HTTPStatus): boolean {
158
155
  /**
159
156
  * Check if status code is typically retryable
160
157
  *
161
- * Default policy: server errors and specific client errors (timeout, rate limit) are retryable.
162
- * Can be overridden via retry middleware configuration.
158
+ * The flag of a status is the retryable flag of its entry in `ERROR_REGISTRY`. That entry is the
159
+ * entry of the code from `httpStatusToErrorCode()`, when the entry has this status.
160
+ *
161
+ * - 408 is retryable: the server did not read the full request, so the call did not start. Its
162
+ * code `TIMEOUT` has the status 504 in the registry.
163
+ * - A status without an entry is retryable when it is a server error (5xx).
164
+ *
165
+ * The configuration of the retry middleware can override this policy.
163
166
  */
164
167
  export function isRetryableStatus(status: HTTPStatus): boolean {
165
- // Server errors are generally retryable
166
- if (isServerErrorStatus(status)) {
168
+ // The deadline of a TIMEOUT (504) passed, but the call of a 408 did not start
169
+ if (status === HTTPStatus.REQUEST_TIMEOUT) {
167
170
  return true;
168
171
  }
169
172
 
170
- // Specific client errors that are retryable
171
- if (
172
- status === HTTPStatus.REQUEST_TIMEOUT ||
173
- status === HTTPStatus.TOO_MANY_REQUESTS
174
- ) {
175
- return true;
173
+ const entry = ERROR_REGISTRY[httpStatusToErrorCode(status)];
174
+ if (entry?.httpStatus === status) {
175
+ return entry.retryable;
176
176
  }
177
177
 
178
- return false;
178
+ return isServerErrorStatus(status);
179
179
  }
180
180
 
181
181
  /**
package/src/browser.ts CHANGED
@@ -42,6 +42,7 @@ export type {
42
42
  ClientMiddleware,
43
43
  ClientOptions,
44
44
  HttpTransportOptions,
45
+ HttpBatchOptions,
45
46
  UrlStrategy,
46
47
  HttpMethodStrategy,
47
48
  LocalTransportOptions,
@@ -24,7 +24,7 @@ export {
24
24
 
25
25
  // Transport Adapters
26
26
  export { HttpTransport, defaultUrlPattern, restfulHttpMethodStrategy, postOnlyStrategy } from "../adapters/http/client/index.js";
27
- export type { HttpTransportOptions, UrlStrategy, HttpMethodStrategy } from "../adapters/http/client/index.js";
27
+ export type { HttpTransportOptions, HttpBatchOptions, UrlStrategy, HttpMethodStrategy } from "../adapters/http/client/index.js";
28
28
 
29
29
  export { LocalTransport } from "../adapters/local/client/index.js";
30
30
  export type { LocalTransportOptions, Handler } from "../adapters/local/client/index.js";
package/src/node.ts CHANGED
@@ -32,6 +32,8 @@ export { procedureHandler } from "./adapters/http/server/handler.js";
32
32
  // The JSON body of a request, read to a limit: the procedure handler and the MCP face read it so (CLI-35)
33
33
  export { readJsonBody, BodyError } from "./adapters/http/server/body.js";
34
34
  export type { ProcedureHandlerOptions, NodeProcedureHandler, NodeUrlStrategy, UrlRequest } from "./adapters/http/server/handler.js";
35
+ // The batches of calls of the procedure handler (CLI-32)
36
+ export type { HandlerBatchOptions } from "./adapters/http/server/batch.js";
35
37
  export type { CorsOptions, CredentialedCorsOptions } from "./adapters/http/server/cors.js";
36
38
  // The credentialed CORS of the trusted origins of a host, for a route of the app (CLI-49)
37
39
  export { credentialedCors } from "./adapters/http/server/cors.js";