@procedures/client 0.24.1 → 0.25.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.
- package/CHANGELOG.md +60 -0
- package/README.md +5 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/server/handler.js +7 -2
- package/dist/adapters/http/server/handler.js.map +1 -1
- package/dist/adapters/http/server/ndjson.d.ts +10 -13
- package/dist/adapters/http/server/ndjson.d.ts.map +1 -1
- package/dist/adapters/http/server/ndjson.js +12 -13
- package/dist/adapters/http/server/ndjson.js.map +1 -1
- package/dist/adapters/websocket/shared/rpc.d.ts +5 -8
- package/dist/adapters/websocket/shared/rpc.d.ts.map +1 -1
- package/dist/adapters/websocket/shared/rpc.js +11 -14
- package/dist/adapters/websocket/shared/rpc.js.map +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2 -1
- package/dist/browser.js.map +1 -1
- package/dist/client/middleware/retry.d.ts.map +1 -1
- package/dist/client/middleware/retry.js +3 -1
- package/dist/client/middleware/retry.js.map +1 -1
- package/dist/procedures/core/index.d.ts +19 -3
- package/dist/procedures/core/index.d.ts.map +1 -1
- package/dist/procedures/core/index.js.map +1 -1
- package/dist/procedures/envelope.d.ts +8 -1
- package/dist/procedures/envelope.d.ts.map +1 -1
- package/dist/procedures/envelope.js.map +1 -1
- package/dist/procedures/idempotency.d.ts +5 -0
- package/dist/procedures/idempotency.d.ts.map +1 -1
- package/dist/procedures/idempotency.js +8 -0
- package/dist/procedures/idempotency.js.map +1 -1
- package/dist/procedures/ref.d.ts +4 -0
- package/dist/procedures/ref.d.ts.map +1 -1
- package/dist/procedures/ref.js.map +1 -1
- package/dist/protocol.d.ts +12 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +20 -0
- package/dist/protocol.js.map +1 -1
- package/dist/server/procedure-server.d.ts +3 -6
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +33 -14
- package/dist/server/procedure-server.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/http/server/handler.ts +8 -2
- package/src/adapters/http/server/ndjson.ts +17 -18
- package/src/adapters/websocket/shared/rpc.ts +11 -14
- package/src/browser.ts +2 -1
- package/src/client/middleware/retry.ts +3 -1
- package/src/procedures/core/index.ts +19 -3
- package/src/procedures/envelope.ts +8 -1
- package/src/procedures/idempotency.ts +8 -0
- package/src/procedures/ref.ts +4 -0
- package/src/protocol.ts +19 -0
- package/src/server/procedure-server.ts +32 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @procedures/client
|
|
2
2
|
|
|
3
|
+
## 0.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 75bff3b: Breaking: an in-band end of a stream before its first item gets the default flag of its code (roadmap CLI-68, decision D25). The release before this one marked the old flag `false` as deprecated (D13).
|
|
8
|
+
|
|
9
|
+
The new behavior:
|
|
10
|
+
|
|
11
|
+
- A handler error without a `retryable` flag that ends a stream before its first item gets the flag of its code in `ERROR_CODES`. Thus `UNAVAILABLE`, `CONNECTION_CLOSED` and `RATE_LIMITED` are retryable there. The other codes stay `false`.
|
|
12
|
+
- This applies on each face: the `error` line of NDJSON, the `error` frame of WebSocket and the `_meta.retryable` of the MCP stream result. The HTTP status of an NDJSON stream stays 200.
|
|
13
|
+
- An error before the stream starts already got this default (CLI-48). Thus a streaming handler and a unary handler that throw the same error before their first item now give the same flag.
|
|
14
|
+
- After the first item, an error without a flag still gets `false` (CLI-58). An error with its own flag keeps it, before and after the first item.
|
|
15
|
+
- The retry middleware of the client retries while no item reached the reader. Thus it now retries a stream that fails with `UNAVAILABLE` before its first item. The caller gets the items of the retry, not the error.
|
|
16
|
+
- A keyed call to a procedure that is not idempotent: a retryable end of its stream lets the next try with the same idempotency key run again. Before, the next try got `DUPLICATE`.
|
|
17
|
+
- Without NDJSON (the last item as JSON), a stream error before the first item gets the flag and the HTTP status of its code, for example 503 for `UNAVAILABLE`. After an item, the flag is `false`, thus 500.
|
|
18
|
+
|
|
19
|
+
What a caller sees:
|
|
20
|
+
|
|
21
|
+
| Stream error without a `retryable` flag | Before | From this release |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Before the first item, code `UNAVAILABLE` | `retryable: false`, no retry | `retryable: true`, the retry middleware sends the call again |
|
|
24
|
+
| Before the first item, a code that is not retryable | `retryable: false` | `retryable: false` |
|
|
25
|
+
| After the first item | `retryable: false` | `retryable: false` |
|
|
26
|
+
| A handler gives `retryable: true` or `false` | that flag | that flag |
|
|
27
|
+
|
|
28
|
+
The retry costs time and calls: each try waits for the backoff, and the server gets one more call for each try. A handler with an effect before its error does that effect again on each try.
|
|
29
|
+
|
|
30
|
+
New exports and options:
|
|
31
|
+
|
|
32
|
+
- `retryableOf(error, items)` of `@procedures/client` gives the flag of an error that ends a call, after `items` items. Each face uses it.
|
|
33
|
+
- The `errorOf` option of `writeNdjsonStream` also gets the count of the item lines before the error. A function with one parameter still works.
|
|
34
|
+
- `IdempotencyCache.forget(key, result)` removes the result of a key.
|
|
35
|
+
|
|
36
|
+
The opt-out:
|
|
37
|
+
|
|
38
|
+
- A handler that is not safe to run again gives `retryable: false` in its error. For example, `throw Object.assign(new Error("busy"), { code: "UNAVAILABLE", retryable: false })`.
|
|
39
|
+
- Or the caller does not use the retry middleware for that call. For example, give `shouldRetry` that gives `false` for that method, or set `retry: { maxAttempts: 1 }` in the context of the call.
|
|
40
|
+
|
|
41
|
+
Migration steps:
|
|
42
|
+
|
|
43
|
+
- A streaming handler that throws `UNAVAILABLE`, `CONNECTION_CLOSED` or `RATE_LIMITED` without a flag before its first item: is a second run safe? If not, give `retryable: false`.
|
|
44
|
+
- A test that expects `retryable: false` for such an end before the first item: expect the flag of the code.
|
|
45
|
+
- A custom `errorOf` of `writeNdjsonStream`: read its second parameter to give the same rule.
|
|
46
|
+
- The site: no change is necessary. The lab simulates its server with explicit flags. The streams of the journey do not fail.
|
|
47
|
+
- MiniMongo: no change is necessary. Its browser client has the retry middleware, but its procedures throw no `UNAVAILABLE`, `CONNECTION_CLOSED` or `RATE_LIMITED` without a flag.
|
|
48
|
+
- Graph: no change is necessary. Its handlers give `UNAVAILABLE` with an explicit flag, and it serves no stream procedure of its own.
|
|
49
|
+
- jarvis: no change is necessary. The cuts of its host have their own flag, and it uses no retry middleware.
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- 16562ee: Deprecated: five behaviors of the programs (decision D13). The next MINOR (D26: the programs on the kernel of coeval, roadmap item M14) changes them. This release changes no behavior and no API: it adds the notes "Deprecated behavior (D26)" to the doc comments, and the section "Deprecated behaviors (D26)" of PROGRAM-FORMAT.md. The functions and the options stay, so the notes are not `@deprecated` tags.
|
|
54
|
+
|
|
55
|
+
- `failFast` of `client.parallel`: at this time, the other tasks go on in the background after the first error. From the next MINOR, they stop at their next wait, and their later calls do not start. When those calls must start, wait for the tasks yourself, or do not use `failFast`.
|
|
56
|
+
- `HydrateOptions.parallel`: at this time, the other refs go on in the background after the first error (`Promise.all`). From the next MINOR, the refs always operate with failFast. When their calls must start, give `parallel: false`.
|
|
57
|
+
- A call that throws `undefined`: at this time, the program fails with `undefined`, and the error text of `client.parallel` and `client.tryCatch` is `"undefined"`. From the next MINOR, the program fails with an `Error` that has the reason of the kernel. Throw an `Error`.
|
|
58
|
+
- `resolveScopes()` of `@procedures/compiler`: at this time, the diagnostics come in the order of the program tree. From the next MINOR, the warnings for the raw input come first, and then the diagnostics of the names. Sort the diagnostics by `pointer` when the order matters.
|
|
59
|
+
- The types `["ref"]` and `["lit"]` of the envelope form (arrays of one key): at this time, they are calls of the procedures with these paths. From the next MINOR, they are the kinds `ref` and `lit` of the kernel. For a call of these procedures, write a ref into the world as the type: `{ "type": { "type": "ref", "value": ["world", "ref"] }, "value": input }`. A ref into the world stays a call, and the `$proc` form does not change.
|
|
60
|
+
|
|
61
|
+
PATCH: documentation only. No export, no type and no behavior changes.
|
|
62
|
+
|
|
3
63
|
## 0.24.1
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -364,6 +364,9 @@ interface RetryOptions {
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
// A Retry-After of the server makes the delay at least that long.
|
|
367
|
+
// A stream goes again only while no item reached the reader: its first item is a retryable error.
|
|
368
|
+
// A stream that fails before its first item with an error without a flag gets the flag of its code,
|
|
369
|
+
// so UNAVAILABLE goes again (CLI-68). A handler gives retryable: false to stop that.
|
|
367
370
|
// The overrides of one call, in its context or as route() overrides (maxAttempts counts the tries)
|
|
368
371
|
client.withContext({ retry: { maxAttempts: 5, delay: ms(200), backoffMultiplier: 3, maxDelay: seconds(2), idempotent: true } });
|
|
369
372
|
```
|
|
@@ -645,6 +648,8 @@ createServer((req, res) => {
|
|
|
645
648
|
}).listen(3000);
|
|
646
649
|
```
|
|
647
650
|
|
|
651
|
+
`errorOf` also gets the count of the item lines before the error. The default gives an error without a flag the flag of its code before the first item, and `false` after it (CLI-68).
|
|
652
|
+
|
|
648
653
|
The promise of `writeNdjsonStream` resolves when the response ends. A closed connection or an abort of `signal` stops the stream, and the iterator of the items gets `return()`.
|
|
649
654
|
|
|
650
655
|
#### Procedure handler without a framework
|