@procedures/client 0.34.0 → 0.35.1

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/CHANGELOG.md +38 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/adapters/http/server/handler.d.ts.map +1 -1
  4. package/dist/adapters/http/server/handler.js +17 -3
  5. package/dist/adapters/http/server/handler.js.map +1 -1
  6. package/dist/adapters/port/transport.d.ts.map +1 -1
  7. package/dist/adapters/port/transport.js +2 -0
  8. package/dist/adapters/port/transport.js.map +1 -1
  9. package/dist/adapters/websocket/server/transport.d.ts.map +1 -1
  10. package/dist/adapters/websocket/server/transport.js +2 -0
  11. package/dist/adapters/websocket/server/transport.js.map +1 -1
  12. package/dist/adapters/websocket/shared/rpc.d.ts.map +1 -1
  13. package/dist/adapters/websocket/shared/rpc.js +14 -5
  14. package/dist/adapters/websocket/shared/rpc.js.map +1 -1
  15. package/dist/browser.d.ts +3 -1
  16. package/dist/browser.d.ts.map +1 -1
  17. package/dist/browser.js +2 -1
  18. package/dist/browser.js.map +1 -1
  19. package/dist/client/errors/index.d.ts +1 -1
  20. package/dist/client/errors/index.d.ts.map +1 -1
  21. package/dist/client/errors/index.js +1 -1
  22. package/dist/client/errors/index.js.map +1 -1
  23. package/dist/client/errors/registry.d.ts +10 -0
  24. package/dist/client/errors/registry.d.ts.map +1 -1
  25. package/dist/client/errors/registry.js +12 -0
  26. package/dist/client/errors/registry.js.map +1 -1
  27. package/dist/client/index.d.ts +1 -1
  28. package/dist/client/index.d.ts.map +1 -1
  29. package/dist/client/index.js +1 -1
  30. package/dist/client/index.js.map +1 -1
  31. package/dist/procedures/collection/changes.d.ts +15 -0
  32. package/dist/procedures/collection/changes.d.ts.map +1 -1
  33. package/dist/procedures/collection/changes.js.map +1 -1
  34. package/dist/server/error-policy.d.ts +96 -0
  35. package/dist/server/error-policy.d.ts.map +1 -0
  36. package/dist/server/error-policy.js +196 -0
  37. package/dist/server/error-policy.js.map +1 -0
  38. package/dist/server/error-response.d.ts +30 -0
  39. package/dist/server/error-response.d.ts.map +1 -0
  40. package/dist/server/error-response.js +90 -0
  41. package/dist/server/error-response.js.map +1 -0
  42. package/dist/server/index.d.ts +2 -0
  43. package/dist/server/index.d.ts.map +1 -1
  44. package/dist/server/index.js +1 -0
  45. package/dist/server/index.js.map +1 -1
  46. package/dist/server/last-resort.d.ts +17 -0
  47. package/dist/server/last-resort.d.ts.map +1 -0
  48. package/dist/server/last-resort.js +19 -0
  49. package/dist/server/last-resort.js.map +1 -0
  50. package/dist/server/procedure-server.d.ts +3 -11
  51. package/dist/server/procedure-server.d.ts.map +1 -1
  52. package/dist/server/procedure-server.js +7 -42
  53. package/dist/server/procedure-server.js.map +1 -1
  54. package/dist/server/server.d.ts +43 -1
  55. package/dist/server/server.d.ts.map +1 -1
  56. package/dist/server/server.js +39 -2
  57. package/dist/server/server.js.map +1 -1
  58. package/dist/server/types.d.ts +12 -0
  59. package/dist/server/types.d.ts.map +1 -1
  60. package/dist/server/types.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/adapters/http/server/handler.ts +18 -3
  63. package/src/adapters/port/transport.ts +2 -0
  64. package/src/adapters/websocket/server/transport.ts +2 -0
  65. package/src/adapters/websocket/shared/rpc.ts +14 -5
  66. package/src/browser.ts +4 -0
  67. package/src/client/errors/index.ts +1 -0
  68. package/src/client/errors/registry.ts +13 -0
  69. package/src/client/index.ts +1 -0
  70. package/src/procedures/collection/changes.ts +12 -0
  71. package/src/server/error-policy.ts +263 -0
  72. package/src/server/error-response.ts +91 -0
  73. package/src/server/index.ts +2 -0
  74. package/src/server/last-resort.ts +23 -0
  75. package/src/server/procedure-server.ts +8 -41
  76. package/src/server/server.ts +73 -3
  77. package/src/server/types.ts +13 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @procedures/client
2
2
 
3
+ ## 0.35.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 9f0405d: `watchStorageChanges()` publishes the change stream of a `MongoDocumentStorage` collection as collection hints, and `versionOfStored()` gives the version of a raw stored document (roadmap CLI-77).
8
+
9
+ PATCH: the change only adds exports and new optional options, and keeps each behavior of 0.35.0 (the watcher is not released yet). Before 1.0.0, a new feature raises the PATCH. The fixed group shares one version, so this rides the next release (0.35.0 when it is not out yet).
10
+
11
+ - `versionOfStored(doc, form?, partition?)` gives the version that `storage.versionOf(id)` gives for a stored document: `_seq` as text, `0` for a document without `_seq`, and `undefined` for a tombstone or a document without an id. It gives the value that `versionOf()` reads.
12
+ - `watchStorageChanges(storage, publish, options?)` watches the change stream of the collection. It publishes each change on the topic of the collection procedures, `collectionChangeTopic(name, partition)`, with the partition from `storage.form.partitionOf()`. The event is a `CollectionChangeEvent` without `since` (a hint), with the id in `changed` or `deleted` and the version of the item in `versions`. A tombstone and a delete are deletes. It returns `{ ready, stop() }`.
13
+ - With `ownWrites: "skip"` (the default), the watcher skips the events of the writes of this process through the storage, because the collection procedures publish them already. Each write of the storage notes its sequence numbers while a watcher is open. `ownWrites: "publish"` publishes each change.
14
+ - With `rawWrites: "adopt"` (the default), the watcher gives a raw write a new `_seq` through the write path of the storage, so `changes(since)` has it. It reads from the event alone whether a write is raw. It gives back the storage fields and the partition fields that a raw replace took, and never changes a field of the item. The write matches only the state that the event saw, so one of two racing watchers wins and the other does nothing. The event of that write publishes the hint with the new version; a raw write does not carry its old version. The adoptions of a watcher wait in one bounded queue, one at a time, in batches that take one block of numbers. The watcher keeps the ids of the raw writes that do not fit in a full queue or whose last try failed (up to 10,000), and adopts them again when the queue is empty, with the documents then. A failure that can go away tries again after the backoff. A failed last try, a second failure, or an id over that limit gives the partition a reset hint. The adoption is exact only with `changeStreamPreAndPostImages`. With the images before the change (`changeStreamPreAndPostImages`), a raw delete becomes a tombstone; without them, it is a hint without a version. A prune of tombstones publishes nothing. `rawWrites: "ignore"` writes nothing and publishes a hint without a version. A read-only user gets the same hint, with one log.
15
+ - With `sweep` (on by default with `rawWrites: "adopt"`), the watcher adopts each document without `_seq` after each gap, in pages of the index of `_id`. `sweepAtOpen: true` (off by default) also sweeps when the stream opens: the first watcher on a legacy collection adopts every legacy document, and the next delta of every subscriber is the whole collection. A document that the sweep cannot place goes to the log once, and the next sweeps leave it.
16
+ - `ready` rejects when the first open fails with an error that does not go away (a single server, a refused access, a wrong option). The watcher asks the server with `hello` first, so on a single server `ready` rejects at once. The watcher tries again after other errors.
17
+ - After an error of the stream, the watcher opens it again after a backoff (`backoff`, on the injected `clock`), from the resume token of the last event. When the server does not know the token any more, or the collection was dropped or renamed, it publishes a reset hint (no ids, `reset: true`) on the plain topic, on each partition of the counters, on each partition that it saw, and on each channel of the bus of the collection. The option `gapPartitions` adds more.
18
+ - `@procedures/client`: `CollectionChangeEvent` has the new optional field `versions`, `[{ id, version }]`: the version of each changed item, as `versionOf(id)` of the storage gives it. A publisher that knows the versions sets it. The new optional field `reset`: `true` tells the subscriber to read the collection in full, with `changes` and no `since`. PATCH: new optional fields of an output type, and before 1.0.0 a new feature raises the PATCH.
19
+ - `@procedures/store`: `EventsChangeFeed` reads `versions` and `reset` of an event, and `HybridStorage` does a full pull for a hint with `reset: true`. PATCH: a fix, so that a store does not miss the changes of a reset.
20
+ - `storageChangeOf(change, form?)` reads the change of an item from a change event, for an app that watches the collection itself.
21
+ - Fix: `ViewMaterializer` leaves `_seq` and `_tomb` of a source out of the content of a row, before the hash. A row is no write of a storage, so the watcher of the target does not read it as a raw write. The other fields of the source stay in the row.
22
+ - f5c2407: PATCH: a new optional option whose default keeps the old behavior. The error policy of a server (roadmap CLI-80).
23
+
24
+ - The new option `errors` of `Server` and `ProcedureServer` tells what an error tells the caller. A host gives it with `serverOptions`. `Server.handle()` applies it, so each face sends the same error: HTTP, WebSocket, MCP and a message port.
25
+ - `expose: "all"` is the default. Each error goes to the caller as before.
26
+ - `expose: "coded"` sends an error with a known code as it is. Each other error goes to the caller as `INTERNAL_ERROR` with the message `internal error` and its real retryable flag. It keeps only the metadata keys of the new option `keepMetadata`: by default the trace keys `traceparent` and `tracestate`. The server gives the real error to `onError`, or to `console.error` without `onError`.
27
+ - A known code is a code of `ERROR_CODES` or of `ERROR_REGISTRY`, for example `NOT_FOUND` or `CONFLICT`. The new function `isKnownErrorCode(code)` does this check. `ECONNREFUSED` and a numeric code of MongoDB are not known codes.
28
+ - The option `codes` adds the codes of the application that go out as they are, for example `QUOTA_EXCEEDED`.
29
+ - The codes `OUTPUT_VALIDATION_ERROR` and `NO_OUTPUT` tell of a failure of the server, so `"coded"` hides them, with `INTERNAL_ERROR`, `HANDLER_ERROR` and `UNKNOWN`.
30
+ - The server applies `map(error, { path, transport })` first, with the real error of its own class. Its result goes to the caller as it is, with its `retryAfterMs` and its conflicts. `undefined` gives the error to `expose`.
31
+ - The policy applies to an error before a stream and to the error that ends a stream. A nested call of `ctx.client` keeps the real error.
32
+ - The new optional field `transport` of `ServerRequest` names the face of a request. The HTTP, WebSocket, message port and MCP faces set it.
33
+ - The last-resort catch of each face applies the same policy when `handle()` throws. This is true for the HTTP, WebSocket, message port and MCP faces, and for the tracked call of a host (`@procedures/peer`). The new function `lastResortError(handler, error, request)` and the new optional method `RequestHandler.exposeError()` do this. The logger gets each hidden error one time.
34
+ - The new types are `ServerErrorPolicy`, `ExposedError` and `ErrorCall`. The new exports are `exposeError`, `lastResortError`, `HIDDEN_ERROR_MESSAGE` and `DEFAULT_KEPT_METADATA`.
35
+ - An MCP result for an unknown tool has `_meta` with the code `NOT_FOUND`.
36
+
37
+ ## 0.35.0
38
+
39
+ No changes in this release.
40
+
3
41
  ## 0.34.0
4
42
 
5
43
  ### Minor Changes