@collective-intelligence/extensions-sdk-frontend-react 0.11.0 → 0.12.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 (47) hide show
  1. package/AGENTS.md +29 -10
  2. package/README.md +20 -21
  3. package/dist/effect/effect-runtime/query-cache.d.ts +3 -146
  4. package/dist/effect.d.ts +1 -1
  5. package/dist/effect.js +1 -1
  6. package/dist/record-layer/collection-ids.d.ts +8 -0
  7. package/dist/record-layer/collections/id-reads.d.ts +26 -0
  8. package/dist/record-layer/collections/query.d.ts +55 -0
  9. package/dist/record-layer/collections/realtime.d.ts +124 -0
  10. package/dist/record-layer/errors.d.ts +64 -0
  11. package/dist/record-layer/identity.d.ts +57 -0
  12. package/dist/record-layer/index.d.ts +23 -0
  13. package/dist/record-layer/layer.d.ts +11 -0
  14. package/dist/record-layer/machines.d.ts +45 -0
  15. package/dist/record-layer/outbox.d.ts +141 -0
  16. package/dist/record-layer/outbox.test-support.d.ts +182 -0
  17. package/dist/record-layer/ports.d.ts +141 -0
  18. package/dist/record-layer/position.d.ts +12 -0
  19. package/dist/record-layer/seed/client.d.ts +38 -0
  20. package/dist/record-layer/seed/freshness.d.ts +19 -0
  21. package/dist/record-layer/seed/server.d.ts +77 -0
  22. package/dist/record-layer/server.d.ts +6 -0
  23. package/dist/record-layer/service.d.ts +48 -0
  24. package/dist/record-layer/targets.d.ts +50 -0
  25. package/dist/record-layer/write-lock.d.ts +23 -0
  26. package/dist/record-layer/writes.d.ts +85 -0
  27. package/dist/records/adapters.d.ts +37 -0
  28. package/dist/records/runtime-provider.d.ts +22 -0
  29. package/dist/records.d.ts +12 -0
  30. package/dist/records.js +2 -0
  31. package/dist/records.server.d.ts +4 -0
  32. package/dist/records.server.js +1 -0
  33. package/dist/studio-api/@tanstack/react-query.gen.d.ts +14 -14
  34. package/dist/workflow.js +2 -1
  35. package/dist/workflows/default-template-ui/inputs/default-input-details.d.ts +9 -0
  36. package/dist/workflows/default-template-ui/inputs/translations.d.ts +5 -0
  37. package/dist/workflows/field-editor/authored-value.d.ts +4 -0
  38. package/dist/workflows/workflow-runtime/read-only-saved-value-field.d.ts +10 -0
  39. package/dist/workflows/workflow-runtime/translations.d.ts +1 -0
  40. package/docs/effect.md +8 -90
  41. package/docs/guide/ai/index.md +1 -1
  42. package/docs/record-collections.md +147 -0
  43. package/docs/tanstack-skills.md +74 -0
  44. package/package.json +29 -7
  45. package/skills/extensions-sdk-frontend-react-move-to-record-collections/SKILL.md +54 -0
  46. package/skills/extensions-sdk-frontend-react-record-collections/SKILL.md +48 -0
  47. package/skills/extensions-sdk-frontend-react-tanstack-db-ssr/SKILL.md +34 -0
package/AGENTS.md CHANGED
@@ -1,24 +1,25 @@
1
1
  # `@collective-intelligence/extensions-sdk-frontend-react`: agent guide
2
2
 
3
3
  Host-neutral React contracts of Collective Intelligence (CI) Studio and
4
- Dashboard contributions, and the Studio API. The package `README.md` holds
5
- the full API.
4
+ Dashboard contributions, the Studio API, and the record layer (Record
5
+ Collections on TanStack DB). The package `README.md` holds the full API.
6
6
 
7
7
  ## Rules
8
8
 
9
9
  - Import each contribution kind from its subpath (`/studio`, `/dashboard`,
10
10
  `/workflow`, `/ui-react`, `/frontend`), and the `StudioApi` service and the
11
11
  write parts (`fromEffect`, `EffectRuntimeProvider`, `useEffectRuntime`,
12
- `QueryCache`) from `/effect`.
12
+ `QueryCache`) from `/effect`, and the record layer (`RecordCollections`,
13
+ `RecordWrites`, `fromLiveQuery`, `fromTransaction`) from `/records`.
13
14
  - Keep one `effect` (`^4.1.0`) in the extension package. It is a required
14
- peer. `react`, `react-dom` and `xstate` come from the host.
15
+ peer. `react`, `react-dom` and `xstate` come from the host. Install the
16
+ TanStack DB peers with the exact versions of the package's
17
+ `peerDependencies`.
15
18
  - Write in a `fromEffect` actor, never with `useMutation` or `fromPromise`;
16
- after the write, refresh the reads through `QueryCache`. An optimistic
17
- write of one key uses `QueryCache.optimisticUpdate`; build its payload in a
18
- `write` function, which gets the confirmed value when the Studio API gets
19
- the write, and give the Studio API's answer to `confirm`. Its edit must
20
- give the same value for a value that already holds it, as a fetch can end
21
- under it. A write of several keys calls `QueryCache.cancel` on them before
19
+ after the write, refresh the reads through `QueryCache`. `QueryCache` has
20
+ no optimistic write; update a view data item with `RecordWrites` and
21
+ `studioViewWriteTarget` of `/records`, and for an optimistic create or
22
+ delete, file an SDK gap. A write of several keys calls `QueryCache.cancel` on them before
22
23
  `update`, and `invalidate` when the write settles. Mount
23
24
  `EffectRuntimeProvider` at the root of each widget.
24
25
  - Test machines with `makeTestQueryCache()` of `/effect`, never with a double
@@ -27,9 +28,17 @@ the full API.
27
28
  - Call the Studio API from Effect code through `StudioApi`. A Studio Widget
28
29
  gives `layerStudioApi()` no base URL: the Studio Host binds the client.
29
30
  - Decode `StudioApiError.body` with a Schema before use; it is `unknown`.
31
+ - Keep lists of records that a widget shows or follows in a Query Record
32
+ Collection, read through a live query. The Studio Host gives no Change
33
+ Hints, so a Realtime Record Collection fails its sync in Studio.
30
34
 
31
35
  ## Index
32
36
 
37
+ - [docs/record-collections.md](docs/record-collections.md): read when a
38
+ widget reads or writes records, or you choose between a Query Record
39
+ Collection and a plain query.
40
+ - [docs/tanstack-skills.md](docs/tanstack-skills.md): read before you load
41
+ TanStack DB skills or follow the repository `tanstack-query` skill.
33
42
  - [docs/effect.md](docs/effect.md): read when a widget or view calls the
34
43
  Studio API from Effect, writes data, refreshes reads after a write, or you
35
44
  give the base URL of a test host.
@@ -38,6 +47,16 @@ the full API.
38
47
  - [skills/extensions-sdk-frontend-react-move-to-effect/SKILL.md](skills/extensions-sdk-frontend-react-move-to-effect/SKILL.md):
39
48
  run when Effect code calls the `/studio-api` client through
40
49
  `Effect.tryPromise`, or lint reports `ci-solution/effect-subpath`.
50
+ - [skills/extensions-sdk-frontend-react-record-collections/SKILL.md](skills/extensions-sdk-frontend-react-record-collections/SKILL.md):
51
+ run when a widget shows or follows a list of records, or code imports
52
+ `@tanstack/db` or `@tanstack/react-db`.
53
+ - [skills/extensions-sdk-frontend-react-move-to-record-collections/SKILL.md](skills/extensions-sdk-frontend-react-move-to-record-collections/SKILL.md):
54
+ run when the type-check fails on `optimisticUpdate`, `pending`,
55
+ `QueryCacheWriteValues` or `QueryCacheOptimisticOptions`, or code imports
56
+ an `optimistic-write` module.
57
+ - [skills/extensions-sdk-frontend-react-tanstack-db-ssr/SKILL.md](skills/extensions-sdk-frontend-react-tanstack-db-ssr/SKILL.md):
58
+ run when a widget asks for server rendering or hydration of Record
59
+ Collections.
41
60
 
42
61
  ## Platform guide
43
62
 
package/README.md CHANGED
@@ -13,7 +13,14 @@ and the package build keeps it external. The `/effect` entrypoint exports the
13
13
  also exports `fromEffect`, `EffectRuntimeProvider`, `useEffectRuntime` and
14
14
  `QueryCache`, the parts of a write in a Studio Widget; see
15
15
  [Writes in a Studio Widget](#writes-in-a-studio-widget). They need the
16
- required `xstate` peer, which the Studio and Dashboard Hosts provide.
16
+ required `xstate` peer, which the Studio and Dashboard Hosts provide. The
17
+ `/records` entrypoint exports the record layer: `RecordCollections`,
18
+ `RecordWrites` with `studioViewWriteTarget`, `RecordId` and `IdempotencyKey`,
19
+ `fromLiveQuery`, `fromTransaction`, the record errors, and
20
+ `RecordRuntimeProvider` with `useRecordRuntime`, the widget runtime that
21
+ provides them. A Studio Widget uses Query Record Collections; the Studio Host gives no Change
22
+ Hints for Realtime Record Collections. The packed
23
+ `docs/record-collections.md` guide explains it.
17
24
 
18
25
  ```tsx
19
26
  import { declareFrontendCatalogContribution } from "@collective-intelligence/extensions-sdk-frontend"
@@ -326,6 +333,15 @@ and after the write the actor refreshes the reads through `QueryCache`.
326
333
  the Studio Host. The Host mounts no Effect runtime. Each widget mounts
327
334
  `EffectRuntimeProvider` at its root: the bundle of each widget has its own
328
335
  copy of `/effect`, so it does not see the provider of another bundle.
336
+ `/effect` loads without TanStack DB.
337
+ - `RecordRuntimeProvider` of `/records` gives its tree a runtime with the
338
+ `QueryCache`, `RecordCollections` and `RecordWrites` over the same
339
+ `QueryClient`; `useRecordRuntime()` gives it. A widget that uses Record
340
+ Collections mounts it in place of `EffectRuntimeProvider`. Query Record
341
+ Collections keep their rows on that `QueryClient`, and record writes go
342
+ through the Studio API client that the Host binds. The Studio Host gives no
343
+ Change Hints, so a Realtime Record Collection fails its sync in Studio.
344
+ Writes to one record from every bundle run one at a time.
329
345
  - `useEffectRuntime()` gives that runtime. A view passes it to the machines it
330
346
  starts, in their input.
331
347
  - `fromEffect(run)` makes XState actor logic that runs the effect of `run` on
@@ -334,31 +350,14 @@ and after the write the actor refreshes the reads through `QueryCache`.
334
350
  It is the `fromEffect` of `@collective-intelligence/effect-xstate/actors`,
335
351
  which the package depends on at the release version.
336
352
  - `QueryCache` has `fetch`, `invalidate`, `cancel`, `setData`, `update`,
337
- `remove`, `optimisticUpdate` and `pending`. `invalidate`, `cancel`, `update` and `remove` apply to the key and
353
+ and `remove`. `invalidate`, `cancel`, `update` and `remove` apply to the key and
338
354
  to each key below it. `fetch` runs its query once, without a retry, and fails
339
355
  with `StudioApiError` or `StudioApiTransportError`; another failure is a
340
356
  Defect. A cancel of the key interrupts the query; the waiting `fetch` then
341
357
  returns the cached value, or is interrupted when the key has no value.
342
358
  `cancel` cancels the running fetches, so they write no value; it keeps the
343
- cached values and starts no fetch. `optimisticUpdate(key, edit, write,
344
- options?)` is an optimistic write of one key: it runs `write` and gives its
345
- result. Each pending write of the key is a layer of its `edit` over the
346
- confirmed value, and views show the layers in call order at once. The
347
- writes to one key, of every `QueryCache` over the same `QueryClient`, go to
348
- the Studio API one at a time in call order; when the Studio API gets one,
349
- the running fetch of the key is cancelled, and a `write` function gets
350
- `{ confirmed, optimistic }` of that moment, so a refused write before it is
351
- not in its payload. A fetch that ends while writes are pending updates the
352
- confirmed value, and the layers show over it again. When the Studio API
353
- confirms the write, the confirmed value becomes
354
- `options.confirm(result, confirmed)` or gets the edit; when `write` fails,
355
- is interrupted or dies, only its own layer goes. A value that `setData`,
356
- `update` or `remove` puts meanwhile stays, and the `confirm` of the writes
357
- before it does not run. Each run of the effect is one write. The key is
358
- invalidated when `write` ends, also when `confirm` throws. The
359
- `QueryClient` holds the writes, so widgets that each bundle `/effect`
360
- share them. `pending(key)` gives the number of
361
- optimistic writes of the key that wait or run. The Host and all widgets
359
+ cached values and starts no fetch. It has no optimistic write: write records through `RecordWrites` on a
360
+ Record Collection (`./records`). The Host and all widgets
362
361
  share one `QueryClient`, so start each key with the package name.
363
362
  - `makeTestQueryCache(options?)` gives a machine test the `QueryCache` over a
364
363
  real `QueryClient` of its own: `layer` for `ManagedRuntime.make`,
@@ -10,32 +10,6 @@ export type QueryCacheFetchOptions<Data> = Readonly<{
10
10
  /** Milliseconds for which a cached value stays fresh; without it, the QueryClient default applies. */
11
11
  staleTime?: number;
12
12
  }>;
13
- /** The values of the entry of a key when CI gets its optimistic write. */
14
- export type QueryCacheWriteValues<Data> = Readonly<{
15
- /**
16
- * CI's value of the key: the value of the last fetch with the answers of
17
- * the writes before this one, without any pending edit. `undefined` when
18
- * the entry has no value.
19
- */
20
- confirmed: Data | undefined;
21
- /**
22
- * `confirmed` with the edit of this write only, so a refused write before
23
- * it is not in it. `undefined` when the entry has no value.
24
- */
25
- optimistic: Data | undefined;
26
- }>;
27
- export type QueryCacheOptimisticOptions<Data, A> = Readonly<{
28
- /**
29
- * The confirmed value after CI confirms the write with `result`, for
30
- * example CI's row with its new revision in `confirmed`. Without it, or
31
- * when it gives `undefined`, the confirmed value gets the edit. It does not
32
- * run when `setData`, `update` or `remove` replaced the value of the key
33
- * after the edit: the newer value stays. When it throws, the write dies
34
- * with its error, and the key still shows its other layers and is
35
- * invalidated.
36
- */
37
- confirm?: (result: A, confirmed: Data | undefined) => Data | undefined;
38
- }>;
39
13
  export type QueryCacheValue = Readonly<{
40
14
  /**
41
15
  * The fresh cached value of `queryKey`, or the value of one run of `query`,
@@ -52,9 +26,7 @@ export type QueryCacheValue = Readonly<{
52
26
  * interrupts their queries, so these fetches write no value. Keeps the
53
27
  * cached values and starts no fetch, so a view of a key whose first fetch
54
28
  * it cancels shows no value until the next fetch. Call it before an
55
- * optimistic `update`, so that a fetch that ends later does not replace the
56
- * new value, and `invalidate` when the write ends; `optimisticUpdate` does
57
- * these steps for one key.
29
+ * `update`, so that a fetch that ends later does not replace the new value.
58
30
  */
59
31
  cancel: (queryKey: QueryKey) => Effect.Effect<void>;
60
32
  /** Caches `data` as the value of `queryKey`; views show it at once. */
@@ -76,43 +48,6 @@ export type QueryCacheValue = Readonly<{
76
48
  * keeps its last result until it renders again.
77
49
  */
78
50
  remove: (queryKey: QueryKey) => Effect.Effect<void>;
79
- /**
80
- * Runs `write`, the remote write of an optimistic edit of the entry of
81
- * `queryKey`, and gives its result. Each pending write of a key is a layer
82
- * of its edit over the confirmed value, CI's value of the key, and views
83
- * show the layers in call order at once; an entry without a value shows no
84
- * edit until a fetch gives it one. The writes to one key, of every
85
- * `QueryCache` over the same `QueryClient`, go to CI one at a time in call
86
- * order; writes to other keys, also keys below `queryKey`, do not wait.
87
- * The `QueryClient` holds these writes, so each bundled copy of the SDK
88
- * over it shares them. Each run of the returned effect is one write, so an
89
- * effect that runs twice writes twice.
90
- *
91
- * When CI gets the write, the running fetch of the key is cancelled, and a
92
- * `write` function is called with the `QueryCacheWriteValues` of that
93
- * moment: the confirmed value with the answers of the writes before it,
94
- * and that value with this edit only. A fetch that ends while writes are
95
- * pending updates the confirmed value, and the edits show over it again,
96
- * so each edit must give the same value for a value that already holds
97
- * it, for example set fields or replace a row by its id.
98
- *
99
- * When CI confirms the write, its layer goes, and the confirmed value
100
- * becomes `options.confirm(result, confirmed)` or gets the edit. When
101
- * `write` fails, is interrupted or dies, only its own layer goes: the
102
- * other layers show over the confirmed value. A value that `setData`,
103
- * `update` or `remove` puts while writes are pending stays: the edits
104
- * before it no longer show or roll back, and CI's answer to them does not
105
- * change the value. When the write ends, the key is invalidated, and its
106
- * views read it again. The key is the entry that `getQueryData` finds,
107
- * also with a `queryKeyHashFn` of the `QueryClient`.
108
- */
109
- optimisticUpdate: <Data, A, E, R>(queryKey: QueryKey, edit: (current: Data) => Data, write: Effect.Effect<A, E, R> | ((values: QueryCacheWriteValues<Data>) => Effect.Effect<A, E, R>), options?: QueryCacheOptimisticOptions<Data, A>) => Effect.Effect<A, E, R>;
110
- /**
111
- * The number of optimistic writes of `queryKey` that wait for CI or run,
112
- * of every `QueryCache` over the same `QueryClient`, also of another
113
- * bundled copy of the SDK. Keys below `queryKey` do not count.
114
- */
115
- pending: (queryKey: QueryKey) => Effect.Effect<number>;
116
51
  }>;
117
52
  declare const QueryCache_base: Context.ServiceClass<QueryCache, "@collective-intelligence/extensions-sdk-frontend-react/QueryCache", Readonly<{
118
53
  /**
@@ -130,9 +65,7 @@ declare const QueryCache_base: Context.ServiceClass<QueryCache, "@collective-int
130
65
  * interrupts their queries, so these fetches write no value. Keeps the
131
66
  * cached values and starts no fetch, so a view of a key whose first fetch
132
67
  * it cancels shows no value until the next fetch. Call it before an
133
- * optimistic `update`, so that a fetch that ends later does not replace the
134
- * new value, and `invalidate` when the write ends; `optimisticUpdate` does
135
- * these steps for one key.
68
+ * `update`, so that a fetch that ends later does not replace the new value.
136
69
  */
137
70
  cancel: (queryKey: QueryKey) => Effect.Effect<void>;
138
71
  /** Caches `data` as the value of `queryKey`; views show it at once. */
@@ -154,43 +87,6 @@ declare const QueryCache_base: Context.ServiceClass<QueryCache, "@collective-int
154
87
  * keeps its last result until it renders again.
155
88
  */
156
89
  remove: (queryKey: QueryKey) => Effect.Effect<void>;
157
- /**
158
- * Runs `write`, the remote write of an optimistic edit of the entry of
159
- * `queryKey`, and gives its result. Each pending write of a key is a layer
160
- * of its edit over the confirmed value, CI's value of the key, and views
161
- * show the layers in call order at once; an entry without a value shows no
162
- * edit until a fetch gives it one. The writes to one key, of every
163
- * `QueryCache` over the same `QueryClient`, go to CI one at a time in call
164
- * order; writes to other keys, also keys below `queryKey`, do not wait.
165
- * The `QueryClient` holds these writes, so each bundled copy of the SDK
166
- * over it shares them. Each run of the returned effect is one write, so an
167
- * effect that runs twice writes twice.
168
- *
169
- * When CI gets the write, the running fetch of the key is cancelled, and a
170
- * `write` function is called with the `QueryCacheWriteValues` of that
171
- * moment: the confirmed value with the answers of the writes before it,
172
- * and that value with this edit only. A fetch that ends while writes are
173
- * pending updates the confirmed value, and the edits show over it again,
174
- * so each edit must give the same value for a value that already holds
175
- * it, for example set fields or replace a row by its id.
176
- *
177
- * When CI confirms the write, its layer goes, and the confirmed value
178
- * becomes `options.confirm(result, confirmed)` or gets the edit. When
179
- * `write` fails, is interrupted or dies, only its own layer goes: the
180
- * other layers show over the confirmed value. A value that `setData`,
181
- * `update` or `remove` puts while writes are pending stays: the edits
182
- * before it no longer show or roll back, and CI's answer to them does not
183
- * change the value. When the write ends, the key is invalidated, and its
184
- * views read it again. The key is the entry that `getQueryData` finds,
185
- * also with a `queryKeyHashFn` of the `QueryClient`.
186
- */
187
- optimisticUpdate: <Data, A, E, R>(queryKey: QueryKey, edit: (current: Data) => Data, write: Effect.Effect<A, E, R> | ((values: QueryCacheWriteValues<Data>) => Effect.Effect<A, E, R>), options?: QueryCacheOptimisticOptions<Data, A>) => Effect.Effect<A, E, R>;
188
- /**
189
- * The number of optimistic writes of `queryKey` that wait for CI or run,
190
- * of every `QueryCache` over the same `QueryClient`, also of another
191
- * bundled copy of the SDK. Keys below `queryKey` do not count.
192
- */
193
- pending: (queryKey: QueryKey) => Effect.Effect<number>;
194
90
  }>>;
195
91
  /**
196
92
  * The remote data of the Studio Host's `QueryClient`, as the machine actors of
@@ -217,9 +113,7 @@ export declare const make: (queryClient: QueryClient) => Readonly<{
217
113
  * interrupts their queries, so these fetches write no value. Keeps the
218
114
  * cached values and starts no fetch, so a view of a key whose first fetch
219
115
  * it cancels shows no value until the next fetch. Call it before an
220
- * optimistic `update`, so that a fetch that ends later does not replace the
221
- * new value, and `invalidate` when the write ends; `optimisticUpdate` does
222
- * these steps for one key.
116
+ * `update`, so that a fetch that ends later does not replace the new value.
223
117
  */
224
118
  cancel: (queryKey: QueryKey) => Effect.Effect<void>;
225
119
  /** Caches `data` as the value of `queryKey`; views show it at once. */
@@ -241,43 +135,6 @@ export declare const make: (queryClient: QueryClient) => Readonly<{
241
135
  * keeps its last result until it renders again.
242
136
  */
243
137
  remove: (queryKey: QueryKey) => Effect.Effect<void>;
244
- /**
245
- * Runs `write`, the remote write of an optimistic edit of the entry of
246
- * `queryKey`, and gives its result. Each pending write of a key is a layer
247
- * of its edit over the confirmed value, CI's value of the key, and views
248
- * show the layers in call order at once; an entry without a value shows no
249
- * edit until a fetch gives it one. The writes to one key, of every
250
- * `QueryCache` over the same `QueryClient`, go to CI one at a time in call
251
- * order; writes to other keys, also keys below `queryKey`, do not wait.
252
- * The `QueryClient` holds these writes, so each bundled copy of the SDK
253
- * over it shares them. Each run of the returned effect is one write, so an
254
- * effect that runs twice writes twice.
255
- *
256
- * When CI gets the write, the running fetch of the key is cancelled, and a
257
- * `write` function is called with the `QueryCacheWriteValues` of that
258
- * moment: the confirmed value with the answers of the writes before it,
259
- * and that value with this edit only. A fetch that ends while writes are
260
- * pending updates the confirmed value, and the edits show over it again,
261
- * so each edit must give the same value for a value that already holds
262
- * it, for example set fields or replace a row by its id.
263
- *
264
- * When CI confirms the write, its layer goes, and the confirmed value
265
- * becomes `options.confirm(result, confirmed)` or gets the edit. When
266
- * `write` fails, is interrupted or dies, only its own layer goes: the
267
- * other layers show over the confirmed value. A value that `setData`,
268
- * `update` or `remove` puts while writes are pending stays: the edits
269
- * before it no longer show or roll back, and CI's answer to them does not
270
- * change the value. When the write ends, the key is invalidated, and its
271
- * views read it again. The key is the entry that `getQueryData` finds,
272
- * also with a `queryKeyHashFn` of the `QueryClient`.
273
- */
274
- optimisticUpdate: <Data, A, E, R>(queryKey: QueryKey, edit: (current: Data) => Data, write: Effect.Effect<A, E, R> | ((values: QueryCacheWriteValues<Data>) => Effect.Effect<A, E, R>), options?: QueryCacheOptimisticOptions<Data, A>) => Effect.Effect<A, E, R>;
275
- /**
276
- * The number of optimistic writes of `queryKey` that wait for CI or run,
277
- * of every `QueryCache` over the same `QueryClient`, also of another
278
- * bundled copy of the SDK. Keys below `queryKey` do not count.
279
- */
280
- pending: (queryKey: QueryKey) => Effect.Effect<number>;
281
138
  }>;
282
139
  /** A layer of the `QueryCache` over `queryClient`. */
283
140
  export declare const layer: (queryClient: QueryClient) => Layer.Layer<QueryCache, never, never>;
package/dist/effect.d.ts CHANGED
@@ -5,6 +5,6 @@ export { makeTestQueryCache } from "./effect/effect-runtime/query-cache-testing.
5
5
  export { EffectRuntimeProvider, useEffectRuntime } from "./effect/effect-runtime/runtime-provider.js";
6
6
  export { StudioApi, layer as layerStudioApi, layerConfig as layerStudioApiConfig } from "./effect/studio-api/service.js";
7
7
  export type { EffectRunner } from "@collective-intelligence/effect-xstate/actors";
8
- export type { QueryCacheFetchOptions, QueryCacheOptimisticOptions, QueryCacheWriteValues } from "./effect/effect-runtime/query-cache.js";
8
+ export type { QueryCacheFetchOptions } from "./effect/effect-runtime/query-cache.js";
9
9
  export type { QueryCacheCall, TestQueryCache, TestQueryCacheOptions } from "./effect/effect-runtime/query-cache-testing.js";
10
10
  export type { StudioApiOperation, StudioApiOperationName, StudioApiOptions, StudioApiRequest, StudioApiSuccess, StudioApiValue } from "./effect/studio-api/service.js";
package/dist/effect.js CHANGED
@@ -1 +1 @@
1
- import{fromEffect as Ne}from"@collective-intelligence/effect-xstate/actors";import*as y from"effect/Schema";class S extends y.TaggedError()("StudioApiError",{body:y.Unknown,status:y.Int}){}class l extends y.TaggedError()("StudioApiTransportError",{cause:y.Defect()}){}import{isCancelledError as q,QueryObserver as P}from"@tanstack/react-query";import*as v from"effect/Context";import*as a from"effect/Effect";import*as p from"effect/Exit";import{constVoid as F}from"effect/Function";import*as k from"effect/Layer";import*as g from"effect/Schema";class m extends v.Service()("@collective-intelligence/extensions-sdk-frontend-react/QueryCache"){}var C=Symbol.for("@collective-intelligence/query-cache/optimistic-writes/v1"),O=(t)=>t[C],L=(t,i)=>t.defaultQueryOptions({queryKey:i}).queryHash,Q=(t)=>{for(let i of t.layers)i.shown=!1},w=(t,i)=>{if(i.confirmed===void 0)return;let r=i.confirmed;for(let e of i.layers)if(e.shown)r=e.apply(r);i.showing=!0;try{t.setQueryData(i.queryKey,r)}finally{i.showing=!1}},B=(t,i)=>(r)=>{let e=i.get(r.query.queryHash);if(e===void 0||e.showing)return;if(r.type==="removed"){e.confirmed=void 0,Q(e);return}if(r.type!=="updated")return;let{action:s}=r;if(s.type==="success")if(e.confirmed=r.query.state.data,s.manual===!0)Q(e);else w(t,e);else if(s.type==="setState")if(r.query.state.data===void 0)e.confirmed=void 0,Q(e);else w(t,e)},H=(t)=>{let i=new Map,r={keys:i,stop:t.getQueryCache().subscribe(B(t,i))};return Object.defineProperty(t,C,{configurable:!0,value:r}),r},x=(t,i)=>{let r=t.layers.indexOf(i);if(r===-1)return!1;return t.layers.splice(r,1),!0},j=(t)=>{t.layers[0]?.wake?.()},z=(t,i)=>a.callback((r)=>{if(t.layers[0]===i){r(a.undefined);return}return i.wake=()=>{i.wake=void 0,r(a.undefined)},a.sync(()=>{i.wake=void 0})}),W=(t,i)=>{let r=O(t);if(i.layers.length>0||r?.keys.get(i.hash)!==i)return;if(r.keys.delete(i.hash),r.keys.size===0)r.stop(),Reflect.deleteProperty(t,C)},J=(t,i,r)=>{let e=O(t)??H(t),s=L(t,i),u=e.keys.get(s)??{confirmed:t.getQueryData(i),hash:s,layers:[],queryKey:i,showing:!1};e.keys.set(s,u),u.layers.push(r);try{w(t,u)}catch(o){throw x(u,r),W(t,u),o}return u},V=(t)=>{let i=async({query:e,...s},u)=>{try{return p.succeed(await t.fetchQuery({...s,queryFn:({signal:o})=>a.runPromiseWith(u)(e,{signal:o}),retry:!1}))}catch(o){if(q(o))return p.interrupt();return g.is(S)(o)||g.is(l)(o)?p.fail(o):p.die(o)}},r=(e)=>a.sync(()=>new P(t,{enabled:!1,queryKey:e}).subscribe(F));return m.of({cancel:(e)=>a.promise(()=>t.cancelQueries({queryKey:e})),fetch:(e)=>a.flatMap(a.context(),(s)=>a.acquireUseRelease(r(e.queryKey),()=>a.flatten(a.promise(()=>i(e,s))),(u)=>a.sync(u))),invalidate:(e)=>a.promise(()=>t.invalidateQueries({queryKey:e})),optimisticUpdate:(e,s,u,o)=>a.suspend(()=>{let c={apply:s,confirm:(n,d)=>{if(!c.shown)return n;let E=o?.confirm?.(d,n);if(E!==void 0)return E;return n===void 0?void 0:s(n)},send:(n)=>a.isEffect(u)?u:u({confirmed:n,optimistic:n===void 0?void 0:s(n)}),shown:!0,wake:void 0},f=c,R=(n,d)=>a.sync(()=>{x(n,f);let E=n.confirmed;try{if(p.isSuccess(d))n.confirmed=f.confirm(n.confirmed,d.value)}finally{if(c.shown||n.confirmed!==E)w(t,n);t.invalidateQueries({exact:!0,queryKey:e})}});return a.acquireUseRelease(a.sync(()=>J(t,e,f)),(n)=>z(n,f).pipe(a.andThen(a.promise(()=>t.cancelQueries({exact:!0,queryKey:e})).pipe(a.andThen(a.suspend(()=>f.send(n.confirmed))),a.onExit((d)=>R(n,d))))),(n)=>a.sync(()=>{if(x(n,f)&&c.shown)w(t,n);j(n),W(t,n)}))}),pending:(e)=>a.sync(()=>O(t)?.keys.get(L(t,e))?.layers.length??0),remove:(e)=>a.sync(()=>{t.removeQueries({queryKey:e})}),setData:(e,s)=>a.sync(()=>{t.setQueryData(e,s)}),update:(e,s)=>a.sync(()=>{t.setQueriesData({queryKey:e},s)})})},K=(t)=>k.succeed(m,V(t));import{QueryClient as X}from"@tanstack/react-query";import*as b from"effect/Effect";import*as G from"effect/Layer";var Y=(t={})=>{let i=t.queryClient??new X({defaultOptions:{queries:{gcTime:1/0}}});for(let[o,c]of t.seed??[])i.setQueryData(o,c);let r=V(i),e=t.overrides??{},s=[],u=(o,c,f)=>b.suspend(()=>(s.push({member:o,queryKey:c}),f()));return{calls:s,layer:G.succeed(m,m.of({cancel:(o)=>u("cancel",o,()=>(e.cancel??r.cancel)(o)),fetch:(o)=>u("fetch",o.queryKey,()=>(e.fetch??r.fetch)(o)),invalidate:(o)=>u("invalidate",o,()=>(e.invalidate??r.invalidate)(o)),optimisticUpdate:(o,c,f,R)=>u("optimisticUpdate",o,()=>(e.optimisticUpdate??r.optimisticUpdate)(o,c,f,R)),pending:(o)=>u("pending",o,()=>(e.pending??r.pending)(o)),remove:(o)=>u("remove",o,()=>(e.remove??r.remove)(o)),setData:(o,c)=>u("setData",o,()=>(e.setData??r.setData)(o,c)),update:(o,c)=>u("update",o,()=>(e.update??r.update)(o,c))})),queryClient:i}};import{EffectRuntimeProvider as Z,makeEffectRuntimeContext as _,useEffectRuntime as ee}from"@collective-intelligence/effect-xstate/react";import{useQueryClient as te}from"@tanstack/react-query";import*as N from"effect/ManagedRuntime";import{useMemo as re}from"react";import{jsx as oe}from"react/jsx-runtime";var I=_(),ie=({children:t})=>{let i=te(),r=re(()=>N.make(K(i)),[i]);return oe(Z,{context:I,runtime:r,children:t})},ae=()=>ee(I);import{client as se,studioAgentRunsGet as ne,studioAgentRunsList as ue,studioViewDataGetItem as ce,studioViewDataSearch as fe,studioViewDataSearchMembers as de,studioViewDataUpdateItem as pe,studioWorkflowRunsGet as ye,studioWorkflowRunsList as le}from"@collective-intelligence/extensions-sdk-frontend-react/studio-api";import*as T from"effect/Config";import*as U from"effect/Context";import*as h from"effect/Effect";import*as D from"effect/Layer";class A extends U.Service()("@collective-intelligence/extensions-sdk-frontend-react/StudioApi"){}var me=(t={})=>{let i=t.baseUrl===void 0?{}:{baseUrl:t.baseUrl},r=(e,s)=>h.fn(`StudioApi.${e}`)(function*(o){let c=!1,f=se.getConfig().fetch??globalThis.fetch,R=Object.assign(async(d,E)=>(c=!0,await f(d,E)),f),n=yield*h.tryPromise({catch:(d)=>{if(c)return new l({cause:d});throw d},try:(d)=>s(o,{...i,fetch:R,responseStyle:"fields",signal:d,throwOnError:!1})});if(n.response===void 0)return yield*new l({cause:n.error});if(!n.response.ok)return yield*new S({body:n.error,status:n.response.status});return n.data});return A.of({studioAgentRunsGet:r("studioAgentRunsGet",(e,s)=>ne({...e,...s})),studioAgentRunsList:r("studioAgentRunsList",(e,s)=>ue({...e,...s})),studioViewDataGetItem:r("studioViewDataGetItem",(e,s)=>ce({...e,...s})),studioViewDataSearch:r("studioViewDataSearch",(e,s)=>fe({...e,...s})),studioViewDataSearchMembers:r("studioViewDataSearchMembers",(e,s)=>de({...e,...s})),studioViewDataUpdateItem:r("studioViewDataUpdateItem",(e,s)=>pe({...e,...s})),studioWorkflowRunsGet:r("studioWorkflowRunsGet",(e,s)=>ye({...e,...s})),studioWorkflowRunsList:r("studioWorkflowRunsList",(e,s)=>le({...e,...s}))})},M=(t={})=>D.sync(A,()=>me(t)),Ee=(t)=>D.unwrap(h.map(T.unwrap(t),M));export{ie as EffectRuntimeProvider,m as QueryCache,A as StudioApi,S as StudioApiError,l as StudioApiTransportError,Ne as fromEffect,M as layerStudioApi,Ee as layerStudioApiConfig,Y as makeTestQueryCache,ae as useEffectRuntime};
1
+ import{fromEffect as Ce}from"@collective-intelligence/effect-xstate/actors";import*as c from"effect/Schema";class l extends c.TaggedError()("StudioApiError",{body:c.Unknown,status:c.Int}){}class f extends c.TaggedError()("StudioApiTransportError",{cause:c.Defect()}){}import{isCancelledError as N,QueryObserver as q}from"@tanstack/react-query";import*as w from"effect/Context";import*as a from"effect/Effect";import*as d from"effect/Exit";import{constVoid as I}from"effect/Function";import*as x from"effect/Layer";import*as D from"effect/Schema";class p extends w.Service()("@collective-intelligence/extensions-sdk-frontend-react/QueryCache"){}var A=(o)=>{let u=async({query:e,...r},s)=>{try{return d.succeed(await o.fetchQuery({...r,queryFn:({signal:t})=>a.runPromiseWith(s)(e,{signal:t}),retry:!1}))}catch(t){if(N(t))return d.interrupt();return D.is(l)(t)||D.is(f)(t)?d.fail(t):d.die(t)}},i=(e)=>a.sync(()=>new q(o,{enabled:!1,queryKey:e}).subscribe(I));return p.of({cancel:(e)=>a.promise(()=>o.cancelQueries({queryKey:e})),fetch:(e)=>a.flatMap(a.context(),(r)=>a.acquireUseRelease(i(e.queryKey),()=>a.flatten(a.promise(()=>u(e,r))),(s)=>a.sync(s))),invalidate:(e)=>a.promise(()=>o.invalidateQueries({queryKey:e})),remove:(e)=>a.sync(()=>{o.removeQueries({queryKey:e})}),setData:(e,r)=>a.sync(()=>{o.setQueryData(e,r)}),update:(e,r)=>a.sync(()=>{o.setQueriesData({queryKey:e},r)})})},C=(o)=>x.succeed(p,A(o));import{QueryClient as T}from"@tanstack/react-query";import*as g from"effect/Effect";import*as Q from"effect/Layer";var W=(o={})=>{let u=o.queryClient??new T({defaultOptions:{queries:{gcTime:1/0}}});for(let[t,n]of o.seed??[])u.setQueryData(t,n);let i=A(u),e=o.overrides??{},r=[],s=(t,n,E)=>g.suspend(()=>(r.push({member:t,queryKey:n}),E()));return{calls:r,layer:Q.succeed(p,p.of({cancel:(t)=>s("cancel",t,()=>(e.cancel??i.cancel)(t)),fetch:(t)=>s("fetch",t.queryKey,()=>(e.fetch??i.fetch)(t)),invalidate:(t)=>s("invalidate",t,()=>(e.invalidate??i.invalidate)(t)),remove:(t)=>s("remove",t,()=>(e.remove??i.remove)(t)),setData:(t,n)=>s("setData",t,()=>(e.setData??i.setData)(t,n)),update:(t,n)=>s("update",t,()=>(e.update??i.update)(t,n))})),queryClient:u}};import{EffectRuntimeProvider as U,makeEffectRuntimeContext as K,useEffectRuntime as M}from"@collective-intelligence/effect-xstate/react";import{useQueryClient as P}from"@tanstack/react-query";import*as V from"effect/ManagedRuntime";import{useMemo as F}from"react";import{jsx as z}from"react/jsx-runtime";var v=K(),B=({children:o})=>{let u=P(),i=F(()=>V.make(C(u)),[u]);return z(U,{context:v,runtime:i,children:o})},j=()=>M(v);import{client as H,studioAgentRunsGet as J,studioAgentRunsList as X,studioViewDataGetItem as Y,studioViewDataSearch as Z,studioViewDataSearchMembers as _,studioViewDataUpdateItem as ee,studioWorkflowRunsGet as te,studioWorkflowRunsList as re}from"@collective-intelligence/extensions-sdk-frontend-react/studio-api";import*as k from"effect/Config";import*as G from"effect/Context";import*as S from"effect/Effect";import*as R from"effect/Layer";class h extends G.Service()("@collective-intelligence/extensions-sdk-frontend-react/StudioApi"){}var oe=(o={})=>{let u=o.baseUrl===void 0?{}:{baseUrl:o.baseUrl},i=(e,r)=>S.fn(`StudioApi.${e}`)(function*(t){let n=!1,E=H.getConfig().fetch??globalThis.fetch,L=Object.assign(async(y,b)=>(n=!0,await E(y,b)),E),m=yield*S.tryPromise({catch:(y)=>{if(n)return new f({cause:y});throw y},try:(y)=>r(t,{...u,fetch:L,responseStyle:"fields",signal:y,throwOnError:!1})});if(m.response===void 0)return yield*new f({cause:m.error});if(!m.response.ok)return yield*new l({body:m.error,status:m.response.status});return m.data});return h.of({studioAgentRunsGet:i("studioAgentRunsGet",(e,r)=>J({...e,...r})),studioAgentRunsList:i("studioAgentRunsList",(e,r)=>X({...e,...r})),studioViewDataGetItem:i("studioViewDataGetItem",(e,r)=>Y({...e,...r})),studioViewDataSearch:i("studioViewDataSearch",(e,r)=>Z({...e,...r})),studioViewDataSearchMembers:i("studioViewDataSearchMembers",(e,r)=>_({...e,...r})),studioViewDataUpdateItem:i("studioViewDataUpdateItem",(e,r)=>ee({...e,...r})),studioWorkflowRunsGet:i("studioWorkflowRunsGet",(e,r)=>te({...e,...r})),studioWorkflowRunsList:i("studioWorkflowRunsList",(e,r)=>re({...e,...r}))})},O=(o={})=>R.sync(h,()=>oe(o)),ae=(o)=>R.unwrap(S.map(k.unwrap(o),O));export{B as EffectRuntimeProvider,p as QueryCache,h as StudioApi,l as StudioApiError,f as StudioApiTransportError,Ce as fromEffect,O as layerStudioApi,ae as layerStudioApiConfig,W as makeTestQueryCache,j as useEffectRuntime};
@@ -0,0 +1,8 @@
1
+ import type { QueryKey } from "@tanstack/query-core";
2
+ import type { RecordTopic } from "./ports.js";
3
+ /**
4
+ * The ids of Record Collections. A server seed and the browser collection it
5
+ * hydrates meet by id, so both take it from here.
6
+ */
7
+ export declare const realtimeCollectionId: ({ filter, schema }: RecordTopic) => string;
8
+ export declare const queryCollectionId: (queryKey: QueryKey) => string;
@@ -0,0 +1,26 @@
1
+ import type * as Duration from "effect/Duration";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Option from "effect/Option";
4
+ import type { RecordSyncFailed } from "../errors.js";
5
+ import type { RecordId, UndecodedRecord } from "../ports.js";
6
+ /** What CI answered for one id: the record, or `None` when the user cannot read one. */
7
+ export type IdRead = Option.Option<UndecodedRecord>;
8
+ export type IdReadsOptions = Readonly<{
9
+ /** The most ids that the cache keeps. */
10
+ capacity: number;
11
+ /** How long a successful read serves later hints of the same revision. */
12
+ timeToLive: Duration.Input;
13
+ }>;
14
+ export declare const defaultIdReadsOptions: IdReadsOptions;
15
+ /**
16
+ * Reads records by id through an exit-aware `Cache`. A failed read is never
17
+ * kept, so the next hint reads again. A kept read serves a hint only when it
18
+ * holds the hinted revision; otherwise the record is read again, so no hint
19
+ * gets a row older than its revision.
20
+ */
21
+ export declare const makeIdReads: (read: (id: RecordId) => Effect.Effect<IdRead, RecordSyncFailed>, options?: Readonly<{
22
+ /** The most ids that the cache keeps. */
23
+ capacity: number;
24
+ /** How long a successful read serves later hints of the same revision. */
25
+ timeToLive: Duration.Input;
26
+ }> | undefined) => Effect.Effect<(id: string & import("effect/Brand").Brand<"RecordId">, revision: string & import("effect/Brand").Brand<"RecordRevision">) => Effect.Effect<IdRead, RecordSyncFailed, never>, never, never>;
@@ -0,0 +1,55 @@
1
+ import type { Collection } from "@tanstack/db";
2
+ import type { QueryClient, QueryKey } from "@tanstack/react-query";
3
+ import type * as Context from "effect/Context";
4
+ import * as Effect from "effect/Effect";
5
+ import type { RecordValueSchema, RecordWriteTarget, UndecodedRecord } from "../ports.js";
6
+ import { RecordSyncFailed } from "../errors.js";
7
+ /** A Record Collection kept fresh by `queryCollectionOptions` on the app's shared QueryClient. */
8
+ export type QueryRecordCollection<T extends object> = Collection<T, string>;
9
+ export type QueryRecordCollectionOptions<Value extends object, E = never, R = never> = Readonly<{
10
+ /** The key of the rows on the app's shared QueryClient. */
11
+ queryKey: QueryKey;
12
+ schema: RecordValueSchema<Value>;
13
+ /** Reads every record of the query, as CI holds it. */
14
+ load: Effect.Effect<readonly UndecodedRecord[], E, R>;
15
+ /**
16
+ * The write target of the query's records, if they have one: a record
17
+ * write of that target then shows in the rows this collection holds.
18
+ */
19
+ target?: RecordWriteTarget;
20
+ }>;
21
+ /**
22
+ * The TanStack DB options of a Query Record Collection. Its query function
23
+ * runs `load` with the context of the caller of `RecordCollections.query`
24
+ * and decodes each record; a record that does not decode fails the load with
25
+ * `RecordSyncFailed`.
26
+ */
27
+ export declare const queryRecordCollectionOptions: <Value extends object, E, R>({ context, id, options, queryClient }: Readonly<{
28
+ context: Context.Context<R>;
29
+ id: string;
30
+ options: QueryRecordCollectionOptions<Value, E, R>;
31
+ queryClient: QueryClient;
32
+ }>) => import("@tanstack/db").CollectionConfig<Readonly<{
33
+ id: import("..").RecordId;
34
+ revision: import("..").RecordRevision | null;
35
+ value: Value;
36
+ }>, string, never, import("@tanstack/query-db-collection").QueryCollectionUtils<Readonly<{
37
+ id: import("..").RecordId;
38
+ revision: import("..").RecordRevision | null;
39
+ value: Value;
40
+ }>, string, Readonly<{
41
+ id: import("..").RecordId;
42
+ revision: import("..").RecordRevision | null;
43
+ value: Value;
44
+ }>, E | RecordSyncFailed>> & {
45
+ schema?: never;
46
+ utils: import("@tanstack/query-db-collection").QueryCollectionUtils<Readonly<{
47
+ id: import("..").RecordId;
48
+ revision: import("..").RecordRevision | null;
49
+ value: Value;
50
+ }>, string, Readonly<{
51
+ id: import("..").RecordId;
52
+ revision: import("..").RecordRevision | null;
53
+ value: Value;
54
+ }>, E | RecordSyncFailed>;
55
+ };
@@ -0,0 +1,124 @@
1
+ import type { Collection, SyncConfig } from "@tanstack/db";
2
+ import type * as Duration from "effect/Duration";
3
+ import * as Effect from "effect/Effect";
4
+ import type { RealtimeChangeSource, RecordRow, RecordTopic, RecordValueSchema } from "../ports.js";
5
+ import type { RecordPosition } from "../position.js";
6
+ import { RecordId } from "../ports.js";
7
+ import { RealtimeSyncMeta } from "../position.js";
8
+ /** A Record Collection kept fresh by the Change Hints of one Realtime Topic. */
9
+ export type RealtimeRecordCollection<T extends object> = Collection<T, string>;
10
+ /** How a Realtime Record Collection groups its Change Hints and reads their records. */
11
+ export type RealtimeSyncLimits = Readonly<{
12
+ /** The most Change Hints that wait for the sync; the stream waits when it is full. */
13
+ queueCapacity: number;
14
+ /** The most Change Hints in one TanStack DB transaction. */
15
+ batchSize: number;
16
+ /** How long the first Change Hint of a batch waits for others. */
17
+ batchWindow: Duration.Input;
18
+ /** The most reads by id of one batch that run at once. */
19
+ readConcurrency: number;
20
+ }>;
21
+ export declare const defaultRealtimeSyncLimits: RealtimeSyncLimits;
22
+ /** The calls that TanStack DB gives one sync run of a Record Collection. */
23
+ export type RecordSyncParams<Value extends object> = Parameters<SyncConfig<RecordRow<Value>, string>["sync"]>[0];
24
+ /**
25
+ * Where the stream of one Realtime Record Collection starts: the position of
26
+ * the read that its rows came from (P18). A server seed brings it in the sync
27
+ * metadata (`importSyncMeta`), and each reload keeps its own read's.
28
+ */
29
+ export type RealtimeStart = Readonly<{
30
+ /** The position of the last read, read at each stream open. */
31
+ position: Effect.Effect<RecordPosition | undefined>;
32
+ /** Keeps the position of a new read; undefined when the read had none. */
33
+ keep: (position: RecordPosition | undefined) => Effect.Effect<void>;
34
+ exportSyncMeta: () => RealtimeSyncMeta | undefined;
35
+ /** Takes the sync metadata that TanStack DB hydrates, as `exportSyncMeta` gave it. */
36
+ importSyncMeta: NonNullable<SyncConfig<object, string>["importSyncMeta"]>;
37
+ }>;
38
+ /** The start position of one Realtime Record Collection, with no read yet. */
39
+ export declare const makeRealtimeStart: () => RealtimeStart;
40
+ export type FollowTopicOptions<Value extends object> = Readonly<{
41
+ topic: RecordTopic;
42
+ schema: RecordValueSchema<Value>;
43
+ source: RealtimeChangeSource["Service"];
44
+ sync: RecordSyncParams<Value>;
45
+ limits: RealtimeSyncLimits;
46
+ start: RealtimeStart;
47
+ }>;
48
+ /**
49
+ * Keeps the rows of one Realtime Record Collection fresh from the Change
50
+ * Hints of its topic, until the hints end or fail or the fiber is
51
+ * interrupted. A collection with no seed and no position first loads every
52
+ * record of the topic; it is ready once the topic's stream starts, and a
53
+ * first load that failed is loaded again as the reload of a Resync that the
54
+ * collection starts itself. A `change` reads its record by id and writes
55
+ * it; `delete` and `leave` remove the row. A read that CI may still answer
56
+ * is tried again (`retrySchedule`); a hint whose read still fails keeps
57
+ * its row and waits for the next batch, which reads it again unless a
58
+ * reload covers it. A batch that holds Resyncs reloads once: it loads every
59
+ * record of the topic and replaces all rows in one TanStack DB transaction,
60
+ * then applies the hints that came after its last Resync. A load that CI
61
+ * may still answer is tried again (`retrySchedule`); a reload whose load
62
+ * still fails covers nothing: the batch applies all its hints, and the next
63
+ * batch reloads, with a Resync or without. A reload runs for every Resync,
64
+ * whatever its generation: each connection numbers its own.
65
+ * Each batch of hints is one TanStack DB transaction. Each stream open starts
66
+ * the topic at the position of the last read (`start`): the seed's, the
67
+ * first load's or the last reload's. Only a collection whose reads gave no
68
+ * position replays from the page's age.
69
+ */
70
+ export declare const followTopic: <Value extends object>(args_0: Readonly<{
71
+ topic: Readonly<{
72
+ schema: string;
73
+ filter?: Readonly<{
74
+ field: string;
75
+ eq: string | number | boolean | null;
76
+ }>;
77
+ }>;
78
+ schema: RecordValueSchema<Value>;
79
+ source: RealtimeChangeSource["Service"];
80
+ sync: {
81
+ collection: Collection<Readonly<{
82
+ id: RecordId;
83
+ revision: import("..").RecordRevision | null;
84
+ value: Value;
85
+ }>, string, any, any, any>;
86
+ begin: (options?: {
87
+ snapshot?: boolean;
88
+ }) => void;
89
+ write: (message: import("@tanstack/db").ChangeMessageOrDeleteKeyMessage<Readonly<{
90
+ id: RecordId;
91
+ revision: import("..").RecordRevision | null;
92
+ value: Value;
93
+ }>, string>) => void;
94
+ commit: (signal?: AbortSignal) => import("@tanstack/db").SyncAppliedReceipt;
95
+ markReady: () => void;
96
+ reportError: (error: unknown) => void;
97
+ fail: (error: unknown) => void;
98
+ reportHealthy: (error?: unknown) => void;
99
+ truncate: (options?: {
100
+ markReady?: boolean;
101
+ }) => void;
102
+ invalidateLoadedSubsets: () => void;
103
+ metadata?: import("@tanstack/db").SyncMetadataApi<string>;
104
+ };
105
+ limits: Readonly<{
106
+ /** The most Change Hints that wait for the sync; the stream waits when it is full. */
107
+ queueCapacity: number;
108
+ /** The most Change Hints in one TanStack DB transaction. */
109
+ batchSize: number;
110
+ /** How long the first Change Hint of a batch waits for others. */
111
+ batchWindow: Duration.Input;
112
+ /** The most reads by id of one batch that run at once. */
113
+ readConcurrency: number;
114
+ }>;
115
+ start: Readonly<{
116
+ /** The position of the last read, read at each stream open. */
117
+ position: Effect.Effect<RecordPosition | undefined>;
118
+ /** Keeps the position of a new read; undefined when the read had none. */
119
+ keep: (position: RecordPosition | undefined) => Effect.Effect<void>;
120
+ exportSyncMeta: () => RealtimeSyncMeta | undefined;
121
+ /** Takes the sync metadata that TanStack DB hydrates, as `exportSyncMeta` gave it. */
122
+ importSyncMeta: NonNullable<SyncConfig<object, string>["importSyncMeta"]>;
123
+ }>;
124
+ }>) => Effect.Effect<void, never, never>;