@confect/foldkit 10.0.0-next.22 → 10.0.0-next.24
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 +10 -0
- package/dist/Command.d.ts +36 -31
- package/dist/Command.d.ts.map +1 -1
- package/dist/Command.js +17 -13
- package/dist/Command.js.map +1 -1
- package/dist/PaginatedQuery.d.ts +90 -36
- package/dist/PaginatedQuery.d.ts.map +1 -1
- package/dist/PaginatedQuery.js +49 -21
- package/dist/PaginatedQuery.js.map +1 -1
- package/dist/Subscription.d.ts +39 -36
- package/dist/Subscription.d.ts.map +1 -1
- package/dist/Subscription.js +23 -19
- package/dist/Subscription.js.map +1 -1
- package/package.json +9 -7
- package/src/Command.ts +36 -31
- package/src/PaginatedQuery.ts +90 -36
- package/src/Subscription.ts +39 -36
package/src/Subscription.ts
CHANGED
|
@@ -44,17 +44,17 @@ const paginatedError = <Query extends Ref.AnyConfectPublicPaginatedQuery>(
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* The dependency record of a `reactiveQuery` entry. `None` means the
|
|
47
|
-
* subscription is closed; a change from one `Some` to another tears the
|
|
48
|
-
*
|
|
47
|
+
* subscription is closed; a change from one `Some` to another tears the server
|
|
48
|
+
* subscription down and reopens it with the new args.
|
|
49
49
|
*/
|
|
50
50
|
export interface Dependencies<Query extends Ref.AnyConfectPublicQuery> {
|
|
51
51
|
readonly args: Option.Option<Ref.Args<Query>>;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Maps a reactive query's emissions into the app's Messages. Every failure—the
|
|
56
|
-
*
|
|
57
|
-
* requires.
|
|
55
|
+
* Maps a reactive query's emissions into the app's Messages. Every failure—the
|
|
56
|
+
* ref's typed error, a transport error, or a codec error—arrives via `onError`,
|
|
57
|
+
* so the resulting stream's error channel is `never`, as Foldkit requires.
|
|
58
58
|
*/
|
|
59
59
|
export interface Handlers<
|
|
60
60
|
Query extends Ref.AnyConfectPublicQuery,
|
|
@@ -78,13 +78,13 @@ type ArgsConfig<Query extends Ref.AnyConfectPublicQuery, Model> = {
|
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* A `dependenciesToStream` body for a hand-written subscription entry: runs
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* A `dependenciesToStream` body for a hand-written subscription entry: runs the
|
|
82
|
+
* ref as a reactive query against the `Client` resource and maps every emission
|
|
83
|
+
* and every failure into a Message. Query failures are values, so the
|
|
84
|
+
* subscription remains live and can later emit a successful result.
|
|
85
85
|
*
|
|
86
|
-
* Prefer `reactiveQuery`, which builds the whole entry; reach for this when
|
|
87
|
-
*
|
|
86
|
+
* Prefer `reactiveQuery`, which builds the whole entry; reach for this when you
|
|
87
|
+
* need control over the entry's dependencies (custom gating, extra
|
|
88
88
|
* dependencies).
|
|
89
89
|
*/
|
|
90
90
|
export const reactiveQueryStream =
|
|
@@ -108,30 +108,34 @@ export const reactiveQueryStream =
|
|
|
108
108
|
|
|
109
109
|
/**
|
|
110
110
|
* A complete Foldkit subscription entry for a Confect reactive query. The
|
|
111
|
-
* leading thunk fixes the `Model` type (TypeScript cannot partially infer
|
|
112
|
-
*
|
|
113
|
-
*
|
|
111
|
+
* leading thunk fixes the `Model` type (TypeScript cannot partially infer type
|
|
112
|
+
* arguments), so the `args` extractor's parameter is already typed. Pass the
|
|
113
|
+
* result as an entry value to `Subscription.make`:
|
|
114
114
|
*
|
|
115
115
|
* ```ts
|
|
116
|
-
* import * as Confect from "@confect/foldkit"
|
|
117
|
-
* import * as Subscription from "foldkit/subscription"
|
|
116
|
+
* import * as Confect from "@confect/foldkit";
|
|
117
|
+
* import * as Subscription from "foldkit/subscription";
|
|
118
118
|
*
|
|
119
119
|
* const subscriptions = Subscription.make<
|
|
120
120
|
* Model,
|
|
121
121
|
* Message,
|
|
122
122
|
* Confect.Client.Client
|
|
123
123
|
* >()(() => ({
|
|
124
|
-
* note: Confect.Subscription.reactiveQuery<Model>()(
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* })
|
|
124
|
+
* note: Confect.Subscription.reactiveQuery<Model>()(
|
|
125
|
+
* refs.public.notes.get,
|
|
126
|
+
* {
|
|
127
|
+
* args: (model) =>
|
|
128
|
+
* Option.map(model.noteId, (noteId) => ({ noteId })),
|
|
129
|
+
* onSuccess: (note) => SucceededGetNote({ note }),
|
|
130
|
+
* onError: (error) => FailedGetNote({ message: String(error) }),
|
|
131
|
+
* },
|
|
132
|
+
* ),
|
|
133
|
+
* }));
|
|
130
134
|
* ```
|
|
131
135
|
*
|
|
132
136
|
* The entry's dependencies are the query args wrapped in `Option`: `None`
|
|
133
|
-
* closes the subscription, a change from one `Some` to another unsubscribes
|
|
134
|
-
*
|
|
137
|
+
* closes the subscription, a change from one `Some` to another unsubscribes and
|
|
138
|
+
* resubscribes with the new args, and structurally equal args leave the
|
|
135
139
|
* subscription running (equivalence is derived from the ref's args schema).
|
|
136
140
|
* Queries without args may omit `args`, leaving the subscription always open.
|
|
137
141
|
*/
|
|
@@ -169,18 +173,17 @@ export const reactiveQuery =
|
|
|
169
173
|
|
|
170
174
|
/**
|
|
171
175
|
* A complete Foldkit subscription entry that keeps exactly one live reactive
|
|
172
|
-
* page subscription in sync with a `PaginatedQuery` machine in the Model.
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
+
* page subscription in sync with a `PaginatedQuery` machine in the Model. The
|
|
177
|
+
* machine state is the single source of truth: navigation and split-pinning
|
|
178
|
+
* change the derived args, while `Idle` closes the subscription. Pagination ids
|
|
179
|
+
* are allocated here and installed by the first settlement.
|
|
176
180
|
*
|
|
177
|
-
* The leading thunk fixes the `Model` type (TypeScript cannot partially
|
|
178
|
-
*
|
|
179
|
-
* typed:
|
|
181
|
+
* The leading thunk fixes the `Model` type (TypeScript cannot partially infer
|
|
182
|
+
* type arguments), so the `state` extractor's parameter is already typed:
|
|
180
183
|
*
|
|
181
184
|
* ```ts
|
|
182
|
-
* import * as Confect from "@confect/foldkit"
|
|
183
|
-
* import * as Subscription from "foldkit/subscription"
|
|
185
|
+
* import * as Confect from "@confect/foldkit";
|
|
186
|
+
* import * as Subscription from "foldkit/subscription";
|
|
184
187
|
*
|
|
185
188
|
* const subscriptions = Subscription.make<
|
|
186
189
|
* Model,
|
|
@@ -191,13 +194,13 @@ export const reactiveQuery =
|
|
|
191
194
|
* state: (model) => model.notes,
|
|
192
195
|
* onSettled: (settlement) => SettledGetNotesPage({ settlement }),
|
|
193
196
|
* }),
|
|
194
|
-
* }))
|
|
197
|
+
* }));
|
|
195
198
|
* ```
|
|
196
199
|
*
|
|
197
200
|
* Pass the settlement to `PaginatedQuery.settle` in `update`. The request
|
|
198
201
|
* identity is included in both success and failure Messages, so superseded
|
|
199
|
-
* outcomes cannot settle a newer page or pagination session. Query failures
|
|
200
|
-
*
|
|
202
|
+
* outcomes cannot settle a newer page or pagination session. Query failures do
|
|
203
|
+
* not close the Convex subscription; a later result can recover naturally.
|
|
201
204
|
*/
|
|
202
205
|
type DependenciesSchema<Dependencies_> = Schema.Schema<Dependencies_> & {
|
|
203
206
|
readonly fields: Schema.Struct.Fields;
|