@procedures/store 0.26.1 → 0.27.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 +25 -0
- package/README.md +36 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/storage/feed.d.ts +16 -0
- package/dist/storage/feed.d.ts.map +1 -1
- package/dist/storage/feed.js +25 -3
- package/dist/storage/feed.js.map +1 -1
- package/dist/storage/hybrid.d.ts +102 -2
- package/dist/storage/hybrid.d.ts.map +1 -1
- package/dist/storage/hybrid.js +117 -10
- package/dist/storage/hybrid.js.map +1 -1
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/index.js.map +1 -1
- package/package.json +4 -4
- package/src/browser.ts +9 -1
- package/src/storage/feed.ts +39 -3
- package/src/storage/hybrid.ts +183 -10
- package/src/storage/index.ts +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @procedures/store
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [7eac8b5]
|
|
8
|
+
- @procedures/client@0.27.0
|
|
9
|
+
- @procedures/collections@0.27.0
|
|
10
|
+
|
|
11
|
+
## 0.26.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b7a5167: Added: the option `aroundRemoteApply` of `HybridStorage` puts each apply of the remote changes inside a hook (graph W8). Graph uses it to start a span of a trace with the `traceparent` that the server sends with a change.
|
|
16
|
+
|
|
17
|
+
- `aroundRemoteApply(hint, apply, context)` starts `apply` one time and gives back its promise. `context.cause` is `"delta"`, `"hint"`, `"gap"` or `"pull"`. `context.hints` has the hints of the apply.
|
|
18
|
+
- A delta and a hint of the feed give their hint. A gap and a pull of the storage (the timer of `pullInterval`, `syncFromRemote()`, `sync()` and the first sync) give the hint `undefined`.
|
|
19
|
+
- `RemoteChangeHint` and `RemoteChanges` have the new optional field `extra`. `EventsChangeFeed` puts the other fields of a change event in it, for example `traceparent`.
|
|
20
|
+
- An error of `apply` or of the hook makes the pull fail, and the status keeps it. A hook cannot hide an error of `apply`.
|
|
21
|
+
- When the hook does not start `apply` one time, the pull fails with the new `RemoteApplyHookError`. The changes apply one time all the same.
|
|
22
|
+
- Only the leader of a `TabCoordinator` or a `TabGroup` uses the hook.
|
|
23
|
+
- The package root and `@procedures/store/browser` export `RemoteApplyHookError` and the types `RemoteApplyHook`, `RemoteApplyContext` and `RemoteApplyCause`.
|
|
24
|
+
- Without the hook, the storage applies the changes as before.
|
|
25
|
+
- @procedures/client@0.26.2
|
|
26
|
+
- @procedures/collections@0.26.2
|
|
27
|
+
|
|
3
28
|
## 0.26.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -319,6 +319,42 @@ const users = new HybridStorage(new ApiStorage(client, { collection: "users" }),
|
|
|
319
319
|
- The server serves the events with the option `events` of `ProcedureServer`, for example `{ topics: ["collections.*"] }`. Without a subscriber, the procedures publish nothing.
|
|
320
320
|
- `ApiStorage` sends the `origin` of a write to the procedure. Thus the storage of the server and the event have it.
|
|
321
321
|
|
|
322
|
+
### The hook around a remote apply
|
|
323
|
+
|
|
324
|
+
The option `aroundRemoteApply` puts each apply of the remote changes inside a hook (graph W8). For example, the hook starts a span of a trace with the `traceparent` of the server.
|
|
325
|
+
|
|
326
|
+
- The hook gets `hint`, `apply` and `context`. It starts `apply` one time and gives back its promise.
|
|
327
|
+
- `context.cause` is `"delta"`, `"hint"`, `"gap"` or `"pull"`. `context.hints` has the hints of the apply.
|
|
328
|
+
- A delta and a hint of the feed give their hint. A gap and a pull of the storage give the hint `undefined`.
|
|
329
|
+
- A pull of the storage is the timer of `pullInterval`, `syncFromRemote()`, `sync()` or the first sync.
|
|
330
|
+
- A pull that many hints asked for runs one time. Its hint is the last hint, and `context.hints` has the last 128 hints.
|
|
331
|
+
- `EventsChangeFeed` puts the other fields of a change event in `hint.extra`, for example `traceparent` and `tracestate`.
|
|
332
|
+
- An error of `apply` or of the hook makes the pull fail. The status keeps the error until a pull succeeds.
|
|
333
|
+
- When the hook does not start `apply` one time, the pull fails with `RemoteApplyHookError`. The changes apply one time all the same.
|
|
334
|
+
- Only the leader of a `TabCoordinator` or a `TabGroup` uses the hook. Give the hook in the option `hybrid`.
|
|
335
|
+
- Without the hook, the storage applies the changes as before.
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import { context, propagation, trace } from "@opentelemetry/api";
|
|
339
|
+
|
|
340
|
+
const tracer = trace.getTracer("app");
|
|
341
|
+
|
|
342
|
+
const users = new HybridStorage(new ApiStorage(client, { collection: "users" }), {
|
|
343
|
+
feed: new EventsChangeFeed(client, { collection: "users" }),
|
|
344
|
+
aroundRemoteApply: (hint, apply, { cause }) => {
|
|
345
|
+
const traceparent = hint?.extra?.["traceparent"];
|
|
346
|
+
const parent = typeof traceparent === "string" ? propagation.extract(context.active(), { traceparent }) : context.active();
|
|
347
|
+
return tracer.startActiveSpan("users.apply", { attributes: { cause } }, parent, async (span) => {
|
|
348
|
+
try {
|
|
349
|
+
await apply();
|
|
350
|
+
} finally {
|
|
351
|
+
span.end();
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
322
358
|
### The tabs of a browser
|
|
323
359
|
|
|
324
360
|
`TabCoordinator` of `@procedures/store/browser` lets one leader tab run the sync of a `HybridStorage` (roadmap CLI-25). The other tabs copy its changes. Without it, each tab pulls and pushes, and each tab writes over the queue of the other tabs.
|