foldkit-remote 0.20.0 → 0.22.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 (198) hide show
  1. package/README.md +987 -198
  2. package/dist/answerGaps.d.ts +16 -0
  3. package/dist/answerGaps.d.ts.map +1 -0
  4. package/dist/answerGaps.js +60 -0
  5. package/dist/answerGaps.js.map +1 -0
  6. package/dist/client-B055kQuP.d.ts +110 -0
  7. package/dist/client-B055kQuP.d.ts.map +1 -0
  8. package/dist/client.d.ts +2 -0
  9. package/dist/client.js +142 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/coalesce-CLAr92Nk.d.ts +34 -0
  12. package/dist/coalesce-CLAr92Nk.d.ts.map +1 -0
  13. package/dist/coalesce.d.ts +2 -0
  14. package/dist/coalesce.js +131 -0
  15. package/dist/coalesce.js.map +1 -0
  16. package/dist/connection-BRyaJy89.d.ts +45 -0
  17. package/dist/connection-BRyaJy89.d.ts.map +1 -0
  18. package/dist/connection.d.ts +2 -0
  19. package/dist/connection.js +170 -0
  20. package/dist/connection.js.map +1 -0
  21. package/dist/data.d.ts +7 -0
  22. package/dist/data.d.ts.map +1 -0
  23. package/dist/data.js +21 -0
  24. package/dist/data.js.map +1 -0
  25. package/dist/diagnostics-DHhVYflV.d.ts +125 -0
  26. package/dist/diagnostics-DHhVYflV.d.ts.map +1 -0
  27. package/dist/diagnostics.d.ts +2 -0
  28. package/dist/diagnostics.js +60 -0
  29. package/dist/diagnostics.js.map +1 -0
  30. package/dist/entity-CgsG5Uel.d.ts +196 -0
  31. package/dist/entity-CgsG5Uel.d.ts.map +1 -0
  32. package/dist/entity-DuDxaa3n.js +279 -0
  33. package/dist/entity-DuDxaa3n.js.map +1 -0
  34. package/dist/entity.d.ts +2 -0
  35. package/dist/entity.js +1 -0
  36. package/dist/held.d.ts +19 -0
  37. package/dist/held.d.ts.map +1 -0
  38. package/dist/held.js +70 -0
  39. package/dist/held.js.map +1 -0
  40. package/dist/impact.d.ts +79 -0
  41. package/dist/impact.d.ts.map +1 -0
  42. package/dist/impact.js +166 -0
  43. package/dist/impact.js.map +1 -0
  44. package/dist/index.d.ts +1542 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +2791 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/inspect-DtRQGCRP.d.ts +134 -0
  49. package/dist/inspect-DtRQGCRP.d.ts.map +1 -0
  50. package/dist/inspect.d.ts +2 -0
  51. package/dist/inspect.js +33 -0
  52. package/dist/inspect.js.map +1 -0
  53. package/dist/json-DowLl1eB.d.ts +52 -0
  54. package/dist/json-DowLl1eB.d.ts.map +1 -0
  55. package/dist/json.d.ts +2 -0
  56. package/dist/json.js +123 -0
  57. package/dist/json.js.map +1 -0
  58. package/dist/law.d.ts +56 -0
  59. package/dist/law.d.ts.map +1 -0
  60. package/dist/law.js +201 -0
  61. package/dist/law.js.map +1 -0
  62. package/dist/live-BpTzlCnY.d.ts +79 -0
  63. package/dist/live-BpTzlCnY.d.ts.map +1 -0
  64. package/dist/live.d.ts +2 -0
  65. package/dist/live.js +126 -0
  66. package/dist/live.js.map +1 -0
  67. package/dist/matching-DF5F9Us8.d.ts +100 -0
  68. package/dist/matching-DF5F9Us8.d.ts.map +1 -0
  69. package/dist/matching.d.ts +2 -0
  70. package/dist/matching.js +172 -0
  71. package/dist/matching.js.map +1 -0
  72. package/dist/model-B6zk1NMB.d.ts +710 -0
  73. package/dist/model-B6zk1NMB.d.ts.map +1 -0
  74. package/dist/model.d.ts +2 -0
  75. package/dist/model.js +1308 -0
  76. package/dist/model.js.map +1 -0
  77. package/dist/mutation.d.ts +2 -0
  78. package/dist/mutation.js +612 -0
  79. package/dist/mutation.js.map +1 -0
  80. package/dist/optimistic-CECsfNGY.d.ts +523 -0
  81. package/dist/optimistic-CECsfNGY.d.ts.map +1 -0
  82. package/dist/optimistic.d.ts +2 -0
  83. package/dist/optimistic.js +336 -0
  84. package/dist/optimistic.js.map +1 -0
  85. package/dist/outbox-DNuc4kZp.d.ts +259 -0
  86. package/dist/outbox-DNuc4kZp.d.ts.map +1 -0
  87. package/dist/outbox.d.ts +2 -0
  88. package/dist/outbox.js +326 -0
  89. package/dist/outbox.js.map +1 -0
  90. package/dist/patchValues.d.ts +10 -0
  91. package/dist/patchValues.d.ts.map +1 -0
  92. package/dist/patchValues.js +57 -0
  93. package/dist/patchValues.js.map +1 -0
  94. package/dist/persistence-CCMnvg7-.d.ts +114 -0
  95. package/dist/persistence-CCMnvg7-.d.ts.map +1 -0
  96. package/dist/persistence.d.ts +2 -0
  97. package/dist/persistence.js +205 -0
  98. package/dist/persistence.js.map +1 -0
  99. package/dist/placement-jZdsIpmj.d.ts +50 -0
  100. package/dist/placement-jZdsIpmj.d.ts.map +1 -0
  101. package/dist/placement.d.ts +2 -0
  102. package/dist/placement.js +116 -0
  103. package/dist/placement.js.map +1 -0
  104. package/dist/plan-D9cftxC_.d.ts +35 -0
  105. package/dist/plan-D9cftxC_.d.ts.map +1 -0
  106. package/dist/plan.d.ts +2 -0
  107. package/dist/plan.js +100 -0
  108. package/dist/plan.js.map +1 -0
  109. package/dist/policy-DsWHmIAq.d.ts +42 -0
  110. package/dist/policy-DsWHmIAq.d.ts.map +1 -0
  111. package/dist/policy.d.ts +2 -0
  112. package/dist/policy.js +32 -0
  113. package/dist/policy.js.map +1 -0
  114. package/dist/{port.d.mts → port.d.ts} +3 -2
  115. package/dist/port.d.ts.map +1 -0
  116. package/dist/{port.mjs → port.js} +3 -2
  117. package/dist/port.js.map +1 -0
  118. package/dist/query-BuIU93xA.d.ts +141 -0
  119. package/dist/query-BuIU93xA.d.ts.map +1 -0
  120. package/dist/query.d.ts +2 -0
  121. package/dist/query.js +0 -0
  122. package/dist/query.js.map +1 -0
  123. package/dist/record.d.ts +11 -0
  124. package/dist/record.d.ts.map +1 -0
  125. package/dist/record.js +21 -0
  126. package/dist/record.js.map +1 -0
  127. package/dist/relation-BLBGOZom.d.ts +59 -0
  128. package/dist/relation-BLBGOZom.d.ts.map +1 -0
  129. package/dist/relation.d.ts +2 -0
  130. package/dist/relation.js +93 -0
  131. package/dist/relation.js.map +1 -0
  132. package/dist/remoteData-mK1suYi1.d.ts +148 -0
  133. package/dist/remoteData-mK1suYi1.d.ts.map +1 -0
  134. package/dist/remoteData.d.ts +2 -0
  135. package/dist/remoteData.js +179 -0
  136. package/dist/remoteData.js.map +1 -0
  137. package/dist/reporting.d.ts +12 -0
  138. package/dist/reporting.d.ts.map +1 -0
  139. package/dist/reporting.js +45 -0
  140. package/dist/reporting.js.map +1 -0
  141. package/dist/requirement-D57S2LpH.d.ts +64 -0
  142. package/dist/requirement-D57S2LpH.d.ts.map +1 -0
  143. package/dist/requirement.d.ts +2 -0
  144. package/dist/requirement.js +114 -0
  145. package/dist/requirement.js.map +1 -0
  146. package/dist/resume-Ct5R6yli.d.ts +92 -0
  147. package/dist/resume-Ct5R6yli.d.ts.map +1 -0
  148. package/dist/resume.d.ts +2 -0
  149. package/dist/resume.js +222 -0
  150. package/dist/resume.js.map +1 -0
  151. package/dist/retain-BfNTvBRb.d.ts +48 -0
  152. package/dist/retain-BfNTvBRb.d.ts.map +1 -0
  153. package/dist/retain.d.ts +2 -0
  154. package/dist/retain.js +107 -0
  155. package/dist/retain.js.map +1 -0
  156. package/dist/selection.d.ts +2 -0
  157. package/dist/selection.js +1 -0
  158. package/dist/shown.d.ts +20 -0
  159. package/dist/shown.d.ts.map +1 -0
  160. package/dist/shown.js +40 -0
  161. package/dist/shown.js.map +1 -0
  162. package/dist/sse-C7LhdbiQ.d.ts +17 -0
  163. package/dist/sse-C7LhdbiQ.d.ts.map +1 -0
  164. package/dist/sse.d.ts +2 -0
  165. package/dist/sse.js +127 -0
  166. package/dist/sse.js.map +1 -0
  167. package/dist/store-ah2qjcJW.d.ts +100 -0
  168. package/dist/store-ah2qjcJW.d.ts.map +1 -0
  169. package/dist/store.d.ts +2 -0
  170. package/dist/store.js +218 -0
  171. package/dist/store.js.map +1 -0
  172. package/dist/testing.d.ts +133 -0
  173. package/dist/testing.d.ts.map +1 -0
  174. package/dist/testing.js +0 -0
  175. package/dist/testing.js.map +1 -0
  176. package/dist/why-kgp_Wr3z.d.ts +483 -0
  177. package/dist/why-kgp_Wr3z.d.ts.map +1 -0
  178. package/dist/why.d.ts +2 -0
  179. package/dist/why.js +293 -0
  180. package/dist/why.js.map +1 -0
  181. package/dist/whyReasons.d.ts +42 -0
  182. package/dist/whyReasons.d.ts.map +1 -0
  183. package/dist/whyReasons.js +211 -0
  184. package/dist/whyReasons.js.map +1 -0
  185. package/dist/wire-DthPcTM6.d.ts +787 -0
  186. package/dist/wire-DthPcTM6.d.ts.map +1 -0
  187. package/dist/wire.d.ts +2 -0
  188. package/dist/wire.js +329 -0
  189. package/dist/wire.js.map +1 -0
  190. package/package.json +19 -14
  191. package/dist/index-BEvVAL76.d.mts +0 -4097
  192. package/dist/index-BEvVAL76.d.mts.map +0 -1
  193. package/dist/index.d.mts +0 -2
  194. package/dist/index.mjs +0 -1
  195. package/dist/port.d.mts.map +0 -1
  196. package/dist/port.mjs.map +0 -1
  197. package/dist/src-BDqn7Ocr.mjs +0 -6344
  198. package/dist/src-BDqn7Ocr.mjs.map +0 -1
@@ -0,0 +1,710 @@
1
+ import { i as RemoteError } from "./remoteData-mK1suYi1.js";
2
+ import { o as RemoteDiagnostic } from "./diagnostics-DHhVYflV.js";
3
+ import { i as Edge, n as Connection, o as Segment } from "./connection-BRyaJy89.js";
4
+ import { r as EntityStore } from "./store-ah2qjcJW.js";
5
+ import { D as MutationState, a as OptimisticOperation, k as NormalizedPatch, o as OptimisticState, t as ConnectionChange } from "./optimistic-CECsfNGY.js";
6
+ import { i as LivePolicy } from "./query-BuIU93xA.js";
7
+ import { a as Requirement, n as RelationRequirement } from "./requirement-D57S2LpH.js";
8
+ import { t as AnswerRead, w as ReadBatchResult } from "./wire-DthPcTM6.js";
9
+ import { a as LiveEvent, s as LiveState } from "./live-BpTzlCnY.js";
10
+ import { c as ReadEntry, i as OutboxState } from "./outbox-DNuc4kZp.js";
11
+ import { r as RetentionRoots } from "./retain-BfNTvBRb.js";
12
+ import { t as MergePolicy } from "./persistence-CCMnvg7-.js";
13
+ import { Option, Schema } from "effect";
14
+ /**
15
+ * The normalized cache as a Foldkit Submodel. `Remote.define` returns a schema
16
+ * and an `update` for this shape; `updateRemote` reconciles every producer.
17
+ */
18
+ interface RemoteModel {
19
+ /** Entity values, presence, staleness, tombstones, and applied windows. */
20
+ readonly entities: EntityStore;
21
+ /** Normalized ordered connections, keyed by connection identity. */
22
+ readonly connections: Readonly<Record<string, Connection>>;
23
+ /**
24
+ * How many rows `Data.more` has grown a read's window to, by
25
+ * `windowGrowthKey`. A read shows at most its window, so this is what "load
26
+ * more" changes; it lives here because a list holds no state of its own.
27
+ */
28
+ readonly grown: Readonly<Record<string, number>>;
29
+ /** Optimistic entity layers and connection overlays over the base store. */
30
+ readonly optimistic: OptimisticState;
31
+ /** Live cursor and boundary state, keyed by the subscription's stream key. */
32
+ readonly live: Readonly<Record<string, LiveState>>;
33
+ /** Mutation pending/applied/failed ledger. */
34
+ readonly mutations: MutationState;
35
+ /**
36
+ * The durable writes (`Data.mutate`'s `durable`) not yet settled, every
37
+ * tab's, in the order the outbox sends them, and what its store holds.
38
+ * Each is in `mutations` too, as any write is.
39
+ */
40
+ readonly outbox: OutboxState;
41
+ /**
42
+ * Streams that broke, by an error or by an event ahead of their cursor, and
43
+ * have not resubscribed since: changes after the break are missed until the
44
+ * live entry restarts them and refetches what they cover.
45
+ */
46
+ readonly gaps: ReadonlySet<string>;
47
+ /** Each live stream that has ever broken, by stream key. One that never broke is absent. */
48
+ readonly streams: Readonly<Record<string, StreamHealth>>;
49
+ /**
50
+ * The `entity\0id\0field` marks a read is currently fetching. A field absent
51
+ * from the store reads as `Loading` while its mark is here and `Initial`
52
+ * otherwise, which is what separates "being fetched" from "nothing is
53
+ * fetching this".
54
+ */
55
+ readonly loading: ReadonlySet<string>;
56
+ /**
57
+ * `Remote.refresh` generations, held per field rather than for the store as a
58
+ * whole. A read entry restarts when the generation over the fields it plans
59
+ * moves, so a read sent before a refresh of its own fields cannot land after
60
+ * it, and a refresh of one field leaves every other entry's read alone.
61
+ */
62
+ readonly refresh: RefreshState;
63
+ /**
64
+ * The reads that failed and have not been settled since, so a read can say
65
+ * `Failed` rather than `Initial`.
66
+ *
67
+ * Without them a read that failed before anything loaded read exactly like
68
+ * one nobody had asked for, and nothing asked again: a read entry restarts
69
+ * only when what it plans changes, and a failure changed nothing. What failed
70
+ * is not planned again on its own either, so a persistent error is not
71
+ * retried every time an unrelated read restarts the entry. `Remote.refresh`
72
+ * is how a view retries.
73
+ */
74
+ readonly failures: Failures;
75
+ /**
76
+ * The storage key the cache was last restored from, through `Hydrated`'s
77
+ * `from`. `Data.persistence` saves under a key only once its own snapshot is
78
+ * in, so a save at startup cannot write the empty store over it, and
79
+ * restores only a key the Model is not yet restored from.
80
+ */
81
+ readonly restoredFrom: Option.Option<string>;
82
+ /**
83
+ * Under `verifyPredictions`, the order each list was placed in, by edge key,
84
+ * and the rows placing took out of its first page, until the server's page
85
+ * for it arrives to be compared with them.
86
+ */
87
+ readonly placed: Readonly<Record<string, PlacedOrder>>;
88
+ /**
89
+ * What the client met and kept going past, oldest first: under
90
+ * `verifyPredictions` each part of a prediction the server's answer
91
+ * disagreed with, and each failed write the application's update does not
92
+ * hear. The newest
93
+ * 256 are kept; the wiring reports each as it is recorded.
94
+ */
95
+ readonly diagnostics: ReadonlyArray<RemoteDiagnostic>;
96
+ /**
97
+ * What retention keeps: the active Surfaces' roots, after those of the
98
+ * Surfaces most recently left (`departedLimit`). A list left is held stale,
99
+ * so going back reads it `Refreshing` while it refetches.
100
+ */
101
+ readonly recent: RetentionRoots;
102
+ }
103
+ /** A list's first page as the client placed it: its keys in order, and those it took out. */
104
+ interface PlacedOrder {
105
+ readonly order: ReadonlyArray<string>;
106
+ readonly dropped: ReadonlyArray<string>;
107
+ }
108
+ /** How a live stream has fared, as its live entry restarts it. */
109
+ interface StreamHealth {
110
+ /** How many times it broke. The live entry restarts on each, so it only grows. */
111
+ readonly restarts: number;
112
+ /** Breaks since its last applied event: what the restart's backoff grows with. */
113
+ readonly failures: number;
114
+ /** Why it last broke; none for a gap, which is not an error. */
115
+ readonly error: Option.Option<RemoteError>;
116
+ /**
117
+ * The server's refusal of what it asks (`RemoteLiveRefused`). A refused
118
+ * stream is no gap and does not restart: asking again is refused again.
119
+ */
120
+ readonly refused: Option.Option<RemoteError>;
121
+ }
122
+ /**
123
+ * Failed reads, as the errors they failed with.
124
+ *
125
+ * `connections` is by connection identity, and is settled by a page arriving,
126
+ * an invalidation, or retention dropping the connection. `fields` is by field
127
+ * mark (`entity\0id\0field`, the marks `loading` uses), and is settled by the
128
+ * field being written again, a refresh asking for it, or retention dropping the
129
+ * entity. A read of it in flight reads `Loading` over the failure without
130
+ * settling it: if that read fails too, the failure is simply recorded again.
131
+ */
132
+ interface Failures {
133
+ readonly connections: Readonly<Record<string, RemoteError>>;
134
+ readonly fields: Readonly<Record<string, RemoteError>>;
135
+ }
136
+ declare const noFailures: Failures;
137
+ /**
138
+ * `Remote.refresh` generations, per field mark. `generation` is the last one
139
+ * handed out; `requested` is when each field was last refreshed, and `started`
140
+ * is the generation each field's read last began under. Holding them per field
141
+ * is what keeps one Projection's refresh from restarting every read entry.
142
+ */
143
+ interface RefreshState {
144
+ readonly generation: number;
145
+ readonly requested: ReadonlyMap<string, number>;
146
+ readonly started: ReadonlyMap<string, number>;
147
+ /**
148
+ * The generation every entry is refreshed at, at least: `forgetRemote` moves
149
+ * it, so every read and live entry restarts, and a read or stream begun for
150
+ * the principal before is interrupted rather than landing after.
151
+ */
152
+ readonly floor: number;
153
+ }
154
+ declare const emptyRefresh: RefreshState;
155
+ /**
156
+ * The Model with everything the server told it forgotten: values, tombstones,
157
+ * unavailable fields, connections, live cursors, failures, and what is in
158
+ * flight. For a change of principal, whose facts these were. The mutation
159
+ * sequence is kept, so request ids stay unique, and a mutation in flight is
160
+ * treated as applied: its answer, when it comes, writes nothing here.
161
+ *
162
+ * `restoredFrom` is kept too: the emptied store is now what that key holds,
163
+ * so `Data.persistence` saves it over the old snapshot and never restores the
164
+ * key again. Restoring would bring back exactly what was forgotten.
165
+ */
166
+ declare const forgetRemote: (model: RemoteModel) => RemoteModel;
167
+ declare const initialRemoteModel: RemoteModel;
168
+ declare const remoteModelSchema: () => Schema.Codec<RemoteModel, unknown>;
169
+ /** The submodel's Messages; each reduces to `RemoteModel` through `updateRemote`. */
170
+ type RemoteMessage = {
171
+ readonly _tag: 'ReadReceived';
172
+ readonly requests: readonly Requirement[];
173
+ readonly result: Schema.Schema.Type<typeof ReadBatchResult>;
174
+ readonly now: number;
175
+ } | {
176
+ readonly _tag: 'ReadFailed';
177
+ readonly requests: readonly Requirement[];
178
+ readonly error: RemoteError;
179
+ /**
180
+ * The live stream whose subscription broke, when this is that rather
181
+ * than a read. Nothing was being read, so no field failed: the stream is
182
+ * recorded as a gap, since changes after it are missed until the live
183
+ * entry restarts it.
184
+ */
185
+ readonly stream?: string | undefined;
186
+ } |
187
+ /** A refetch of present fields began; they read as `Refreshing` until it lands. */
188
+ {
189
+ readonly _tag: 'RefreshStarted';
190
+ readonly requests: readonly Requirement[];
191
+ } |
192
+ /** A read began; the fields it asks for that the store lacks read as `Loading`. */
193
+ {
194
+ readonly _tag: 'ReadStarted';
195
+ readonly requests: readonly Requirement[];
196
+ /** The refresh generation the read was planned under. */
197
+ readonly refresh?: number | undefined;
198
+ } |
199
+ /**
200
+ * Queries for these connections were sent. One with nothing to show reads
201
+ * `Loading` until its page or its failure arrives, which is what separates
202
+ * "being fetched" from `Initial`, "nothing is fetching this".
203
+ */
204
+ {
205
+ readonly _tag: 'QueryStarted';
206
+ readonly connections: readonly string[];
207
+ } |
208
+ /** The active Surfaces' roots changed; everything they do not reach is collected. */
209
+ {
210
+ readonly _tag: 'RetentionChanged';
211
+ readonly roots: RetentionRoots;
212
+ } |
213
+ /** A restored snapshot meets the store; runtime state is untouched. */
214
+ {
215
+ readonly _tag: 'Hydrated';
216
+ readonly entities: EntityStore;
217
+ /**
218
+ * The connections a snapshot declared should survive, as their edges.
219
+ * Restored with **unknown** boundaries and marked stale: the rows show
220
+ * at once and the connection is refetched, because a persisted cursor
221
+ * may name server state that is gone.
222
+ */
223
+ readonly connections?: Readonly<Record<string, ReadonlyArray<ReadonlyArray<Edge>>>> | undefined;
224
+ readonly merge: MergePolicy;
225
+ /** The storage key the snapshot was read from, when it was: `restoredFrom`. */
226
+ readonly from?: string | undefined;
227
+ } |
228
+ /** A mutation began; its optimistic operations show until it settles. */
229
+ {
230
+ readonly _tag: 'MutationStarted';
231
+ readonly requestId: string;
232
+ readonly optimistic?: ReadonlyArray<OptimisticOperation> | undefined;
233
+ /**
234
+ * Who the operation is predicted for: what a list's `Expr.viewer` reads
235
+ * while the client places the rows it changes. `Data.mutate` gives
236
+ * `Remote.make`'s viewer; absent, a list over the viewer is the server's.
237
+ */
238
+ readonly viewer?: {
239
+ readonly entity: string;
240
+ readonly id: string;
241
+ } | undefined;
242
+ /**
243
+ * Which mutation, with what input: what the ledger keeps until the
244
+ * request applies, so a failure can be listed and retried. `Data.mutate`
245
+ * always gives it.
246
+ */
247
+ readonly write?: {
248
+ readonly mutation: string;
249
+ readonly input: unknown;
250
+ readonly keys?: ReadonlyArray<string> | undefined;
251
+ /** When the reader acted: what the request sends, and a retry sends again. */
252
+ readonly now?: number | undefined;
253
+ /**
254
+ * Queued in the outbox rather than sent: the input encoded, and
255
+ * what the reader was shown, as the store keeps them. The request
256
+ * id is the operation id.
257
+ */
258
+ readonly durable?: {
259
+ readonly input: unknown;
260
+ readonly shown: ReadonlyArray<RelationRequirement>;
261
+ } | undefined;
262
+ } | undefined;
263
+ } |
264
+ /** What `Data.mutate`'s Command answers for a durable write, which the outbox sends: nothing. */
265
+ {
266
+ readonly _tag: 'MutationQueued';
267
+ readonly requestId: string;
268
+ } |
269
+ /**
270
+ * What the outbox's store under `key` holds, read entry by entry: written
271
+ * there by this page or another tab. `session` is given by a restore, for
272
+ * a page that has none; `unsaved` says why the store could not be written,
273
+ * when it could not, and the entries are then this page's own.
274
+ */
275
+ {
276
+ readonly _tag: 'OutboxRead';
277
+ readonly key: string;
278
+ readonly scope: string;
279
+ readonly session?: string | undefined;
280
+ readonly entries: ReadonlyArray<ReadEntry>;
281
+ readonly done: ReadonlyArray<string>;
282
+ readonly unsaved?: string | undefined;
283
+ } |
284
+ /** A durable write was sent and nothing answered; it is sent again after a wait. */
285
+ {
286
+ readonly _tag: 'OutboxDelayed';
287
+ readonly requestId: string;
288
+ readonly attempt: number;
289
+ readonly error: RemoteError;
290
+ } | {
291
+ readonly _tag: 'MutationSucceeded';
292
+ readonly requestId: string;
293
+ readonly entities: readonly NormalizedPatch[];
294
+ /** Connection changes the server confirmed; they replace the request's own. */
295
+ readonly connections?: ReadonlyArray<ConnectionChange> | undefined;
296
+ /** Entities the mutation deleted: tombstoned, which hides them from every connection. */
297
+ readonly deleted?: ReadonlyArray<{
298
+ readonly entity: string;
299
+ readonly id: string;
300
+ }> | undefined;
301
+ /**
302
+ * What the answer read of the rows it names, for the fields the request
303
+ * said it shows: written as a read is, in the same reduction.
304
+ */
305
+ readonly read?: Schema.Schema.Type<typeof AnswerRead> | undefined;
306
+ /** Injected clock reading of the answer: how fresh the written entities are. */
307
+ readonly now: number;
308
+ } | {
309
+ readonly _tag: 'MutationFailed';
310
+ readonly requestId: string;
311
+ readonly error: RemoteError;
312
+ /** The operation id it was sent with, for a retry to send again. */
313
+ readonly operation: string;
314
+ } |
315
+ /**
316
+ * Operations shown over the store with no request behind them, until they are
317
+ * lifted: a preview of a change nobody has made. Showing an id again replaces
318
+ * what it showed.
319
+ */
320
+ {
321
+ readonly _tag: 'OverlayShown';
322
+ readonly id: string;
323
+ readonly optimistic: ReadonlyArray<OptimisticOperation>;
324
+ } | {
325
+ readonly _tag: 'OverlayLifted';
326
+ readonly id: string;
327
+ } |
328
+ /** `Data.more`: a read's window, by `windowGrowthKey`, now shows `size` rows. */
329
+ {
330
+ readonly _tag: 'WindowGrown';
331
+ readonly window: string;
332
+ readonly size: number;
333
+ } | {
334
+ readonly _tag: 'LiveReceived';
335
+ readonly stream: string;
336
+ readonly event: LiveEvent;
337
+ readonly policy?: LivePolicy;
338
+ readonly now: number;
339
+ } | {
340
+ readonly _tag: 'GapCleared';
341
+ readonly stream: string;
342
+ } | {
343
+ readonly _tag: 'ConnectionMerged';
344
+ readonly connection: string;
345
+ readonly page: Segment;
346
+ /** The page answers the connection's refresh, so the merge also clears `stale`. */
347
+ readonly refreshes?: boolean | undefined;
348
+ /**
349
+ * The slice the query asked for, so the payload's entities write like a
350
+ * read: one request per matching edge. Absent for a page from a server
351
+ * that predates payload planning, which carries edges only.
352
+ */
353
+ readonly select?: RelationRequirement | undefined;
354
+ /** The selected fields of the page's items, as a read batch returns them. */
355
+ readonly entities?: ReadonlyArray<{
356
+ readonly entity: string;
357
+ readonly id: string;
358
+ readonly values: Record<string, unknown>;
359
+ }> | undefined;
360
+ /** Fields asked for that the server settled without a value. */
361
+ readonly settled?: ReadonlyArray<{
362
+ readonly entity: string;
363
+ readonly id: string;
364
+ readonly fields: ReadonlyArray<string>;
365
+ }> | undefined;
366
+ /** Injected clock reading of the answer, dating what the payload writes. */
367
+ readonly now?: number | undefined;
368
+ } | {
369
+ readonly _tag: 'ConnectionInvalidated';
370
+ readonly connection: string;
371
+ } | {
372
+ readonly _tag: 'ConnectionRefreshed';
373
+ readonly connection: string;
374
+ } |
375
+ /**
376
+ * A query for the connection failed. Its pages stay as they were, and it
377
+ * reads `Failed` — with them as `previous`, when it has any — until a page
378
+ * arrives, it is invalidated, or retention drops it.
379
+ */
380
+ {
381
+ readonly _tag: 'QueryFailed';
382
+ readonly connection: string;
383
+ readonly error: RemoteError;
384
+ } |
385
+ /**
386
+ * What `Data.preload` read for a destination, as the Messages that wrote it,
387
+ * reduced in order into the Model as it is now rather than the one the
388
+ * preload started from.
389
+ */
390
+ {
391
+ readonly _tag: 'Preloaded';
392
+ readonly messages: ReadonlyArray<RemoteMessage>;
393
+ } |
394
+ /**
395
+ * What the Command reporting recorded diagnostics returns once it has. It
396
+ * changes nothing: the diagnostics stay in the Model.
397
+ */
398
+ {
399
+ readonly _tag: 'CompletedReportDiagnostics';
400
+ };
401
+ declare const retentionRootsSchema: Schema.Struct<{
402
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
403
+ readonly connections: Schema.$Array<Schema.Struct<{
404
+ readonly identity: Schema.String;
405
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
406
+ }>>;
407
+ }>;
408
+ /**
409
+ * The Messages' fields by tag, without `_tag`: what `defineMessageUnion` takes,
410
+ * so an application spreads them into its own union (`Remote.messages`).
411
+ */
412
+ declare const remoteMessageCases: {
413
+ ReadReceived: {
414
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
415
+ result: Schema.Struct<{
416
+ readonly entities: Schema.$Array<Schema.Struct<{
417
+ readonly entity: Schema.String;
418
+ readonly id: Schema.String;
419
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
420
+ }>>;
421
+ readonly settled: Schema.$Array<Schema.Struct<{
422
+ readonly entity: Schema.String;
423
+ readonly id: Schema.String;
424
+ readonly fields: Schema.$Array<Schema.String>;
425
+ }>>;
426
+ }>;
427
+ now: Schema.Number;
428
+ };
429
+ ReadFailed: {
430
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
431
+ error: Schema.Struct<{
432
+ readonly _tag: Schema.String;
433
+ readonly message: Schema.String;
434
+ readonly refusal: Schema.optional<Schema.Unknown>;
435
+ readonly reason: Schema.optional<Schema.String>;
436
+ }>;
437
+ stream: Schema.optional<Schema.String>;
438
+ };
439
+ RefreshStarted: {
440
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
441
+ };
442
+ ReadStarted: {
443
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
444
+ refresh: Schema.optional<Schema.Number>;
445
+ };
446
+ QueryStarted: {
447
+ connections: Schema.$Array<Schema.String>;
448
+ };
449
+ RetentionChanged: {
450
+ roots: Schema.Struct<{
451
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
452
+ readonly connections: Schema.$Array<Schema.Struct<{
453
+ readonly identity: Schema.String;
454
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
455
+ }>>;
456
+ }>;
457
+ };
458
+ Hydrated: {
459
+ connections: Schema.optional<Schema.Unknown>;
460
+ from: Schema.optional<Schema.String>;
461
+ entities: Schema.Unknown;
462
+ merge: Schema.Union<readonly [Schema.Literal<"replace">, Schema.Literal<"preserve-existing">]>;
463
+ };
464
+ MutationStarted: {
465
+ requestId: Schema.String;
466
+ optimistic: Schema.optional<Schema.$Array<Schema.Unknown>>;
467
+ viewer: Schema.optional<Schema.Struct<{
468
+ readonly entity: Schema.String;
469
+ readonly id: Schema.String;
470
+ }>>;
471
+ write: Schema.optional<Schema.Struct<{
472
+ readonly mutation: Schema.String;
473
+ readonly input: Schema.Unknown;
474
+ readonly keys: Schema.optional<Schema.$Array<Schema.String>>;
475
+ readonly now: Schema.optional<Schema.Number>;
476
+ readonly durable: Schema.optional<Schema.Struct<{
477
+ readonly input: Schema.Unknown;
478
+ readonly shown: Schema.$Array<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
479
+ }>>;
480
+ }>>;
481
+ };
482
+ MutationQueued: {
483
+ requestId: Schema.String;
484
+ };
485
+ OutboxRead: {
486
+ key: Schema.String;
487
+ scope: Schema.String;
488
+ session: Schema.optional<Schema.String>;
489
+ entries: Schema.$Array<Schema.Unknown>;
490
+ done: Schema.$Array<Schema.String>;
491
+ unsaved: Schema.optional<Schema.String>;
492
+ };
493
+ OutboxDelayed: {
494
+ requestId: Schema.String;
495
+ attempt: Schema.Number;
496
+ error: Schema.Struct<{
497
+ readonly _tag: Schema.String;
498
+ readonly message: Schema.String;
499
+ readonly refusal: Schema.optional<Schema.Unknown>;
500
+ readonly reason: Schema.optional<Schema.String>;
501
+ }>;
502
+ };
503
+ MutationSucceeded: {
504
+ requestId: Schema.String;
505
+ entities: Schema.$Array<Schema.Struct<{
506
+ readonly entity: Schema.String;
507
+ readonly id: Schema.String;
508
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
509
+ }>>;
510
+ connections: Schema.optional<Schema.$Array<Schema.Unknown>>;
511
+ deleted: Schema.optional<Schema.$Array<Schema.Struct<{
512
+ readonly entity: Schema.String;
513
+ readonly id: Schema.String;
514
+ }>>>;
515
+ read: Schema.optional<Schema.Struct<{
516
+ readonly requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
517
+ readonly result: Schema.Struct<{
518
+ readonly entities: Schema.$Array<Schema.Struct<{
519
+ readonly entity: Schema.String;
520
+ readonly id: Schema.String;
521
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
522
+ }>>;
523
+ readonly settled: Schema.$Array<Schema.Struct<{
524
+ readonly entity: Schema.String;
525
+ readonly id: Schema.String;
526
+ readonly fields: Schema.$Array<Schema.String>;
527
+ }>>;
528
+ }>;
529
+ }>>;
530
+ now: Schema.Number;
531
+ };
532
+ MutationFailed: {
533
+ requestId: Schema.String;
534
+ error: Schema.Struct<{
535
+ readonly _tag: Schema.String;
536
+ readonly message: Schema.String;
537
+ readonly refusal: Schema.optional<Schema.Unknown>;
538
+ readonly reason: Schema.optional<Schema.String>;
539
+ }>;
540
+ operation: Schema.String;
541
+ };
542
+ OverlayShown: {
543
+ id: Schema.String;
544
+ optimistic: Schema.$Array<Schema.Unknown>;
545
+ };
546
+ OverlayLifted: {
547
+ id: Schema.String;
548
+ };
549
+ WindowGrown: {
550
+ window: Schema.String;
551
+ size: Schema.Number;
552
+ };
553
+ LiveReceived: {
554
+ stream: Schema.String;
555
+ event: Schema.Unknown;
556
+ policy: Schema.optional<Schema.Unknown>;
557
+ now: Schema.Number;
558
+ };
559
+ GapCleared: {
560
+ stream: Schema.String;
561
+ };
562
+ ConnectionMerged: {
563
+ connection: Schema.String;
564
+ page: Schema.Unknown;
565
+ refreshes: Schema.optional<Schema.Boolean>;
566
+ select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
567
+ entities: Schema.optional<Schema.$Array<Schema.Struct<{
568
+ readonly entity: Schema.String;
569
+ readonly id: Schema.String;
570
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
571
+ }>>>;
572
+ settled: Schema.optional<Schema.$Array<Schema.Struct<{
573
+ readonly entity: Schema.String;
574
+ readonly id: Schema.String;
575
+ readonly fields: Schema.$Array<Schema.String>;
576
+ }>>>;
577
+ now: Schema.optional<Schema.Number>;
578
+ };
579
+ ConnectionInvalidated: {
580
+ connection: Schema.String;
581
+ };
582
+ ConnectionRefreshed: {
583
+ connection: Schema.String;
584
+ };
585
+ QueryFailed: {
586
+ connection: Schema.String;
587
+ error: Schema.Struct<{
588
+ readonly _tag: Schema.String;
589
+ readonly message: Schema.String;
590
+ readonly refusal: Schema.optional<Schema.Unknown>;
591
+ readonly reason: Schema.optional<Schema.String>;
592
+ }>;
593
+ };
594
+ Preloaded: {
595
+ messages: Schema.$Array<Schema.suspend<Schema.Codec<RemoteMessage, unknown, never, never>>>;
596
+ };
597
+ CompletedReportDiagnostics: {};
598
+ };
599
+ type RemoteMessageTag = RemoteMessage['_tag'];
600
+ /**
601
+ * A Remote Message as an application's union constructs it from
602
+ * `remoteMessageCases`: the same shape `RemoteMessage` names, with the runtime
603
+ * slots (`entities`, `event`, `page`) typed `unknown` by their schemas.
604
+ */
605
+ type RemoteMessageInput = { [Tag in RemoteMessageTag]: {
606
+ readonly _tag: Tag;
607
+ } & Schema.Struct.Type<(typeof remoteMessageCases)[Tag]>; }[RemoteMessageTag];
608
+ /**
609
+ * Whether a Message is one of Remote's, by tag. Narrows an application's union
610
+ * to its Remote cases, and its complement to the application's own.
611
+ */
612
+ declare const isRemoteMessage: <M extends {
613
+ readonly _tag: string;
614
+ }>(message: M) => message is Extract<M, {
615
+ readonly _tag: RemoteMessageTag;
616
+ }>;
617
+ declare const remoteMessageSchema: Schema.Codec<RemoteMessage, unknown>;
618
+ /** The ids `OverlayShown` shows now, each once, in the order they are drawn. */
619
+ declare const overlaysOf: (model: RemoteModel) => ReadonlyArray<string>;
620
+ /** The key a grown window is kept under: its connection and the window first asked for. */
621
+ declare const windowGrowthKey: (identity: string, window: string) => string;
622
+ /**
623
+ * Whether only overlays show this entity: the server has told the store
624
+ * nothing of it and no request's layer writes it, so nothing will fetch what an
625
+ * overlay leaves out.
626
+ */
627
+ declare const onlyOverlaid: (model: RemoteModel, entity: string, id: string) => boolean;
628
+ /**
629
+ * One mark per requested field, `entity\0id\0field`. A read is identified by
630
+ * what it asks for, not by a request id: two reads asking for one field share
631
+ * its mark, so the first answer clears it. Over-clearing shows `Initial` rather
632
+ * than a spinner, which is the safer way to be wrong. The refresh generations
633
+ * below key off the same marks, so "what a read asks for" means one thing.
634
+ */
635
+ declare const fieldMark: (entity: string, id: string, field: string) => string;
636
+ /** Whether a query for this connection is in flight. */
637
+ declare const isQueryLoading: (model: RemoteModel, identity: string) => boolean;
638
+ /**
639
+ * The generation a read is planned under: the highest any of the fields it
640
+ * reads or connections it runs was refreshed at. A read entry carries this as a
641
+ * dependency, so it restarts when what it observes is refreshed and not when
642
+ * anything else is.
643
+ */
644
+ declare const refreshedAt: (refresh: RefreshState, requests: ReadonlyArray<Requirement>, connections?: ReadonlyArray<string>) => number;
645
+ /**
646
+ * Marks every field of `requests` and every connection in `connections`
647
+ * refreshed at the next generation.
648
+ */
649
+ declare const withRefreshRequested: (refresh: RefreshState, requests: ReadonlyArray<Requirement>, connections?: ReadonlyArray<string>) => RefreshState;
650
+ /**
651
+ * Marks connections as needing to be asked again, and restarts a read of them
652
+ * already in flight: a page requested before what invalidated it could land
653
+ * after it, saying what is no longer true. `Remote.refresh` marks the same way.
654
+ */
655
+ declare const invalidateConnections: (model: RemoteModel, connections: ReadonlyArray<string>) => RemoteModel;
656
+ /**
657
+ * Whether one field's read already began under the generation that field was
658
+ * last refreshed at. Such a read is in flight and would otherwise outlive the
659
+ * refresh, so the refresh takes a new generation to restart it even though the
660
+ * field is already stale.
661
+ */
662
+ declare const refreshIsInFlight: (refresh: RefreshState, request: Requirement, field: string) => boolean;
663
+ /**
664
+ * Whether a read is fetching any of `fields` for this entity. Consulted only
665
+ * when the store lacks the value, which is what separates `Loading` from
666
+ * `Initial`.
667
+ */
668
+ declare const isLoading: (model: RemoteModel, entity: string, id: string, fields: ReadonlyArray<string>) => boolean;
669
+ /**
670
+ * The pure reducer all four producers share. A live event that arrives ahead of
671
+ * its cursor is a gap: it is not applied, and the stream is recorded so its
672
+ * live entry restarts it rather than silently missing facts. When every field a Message
673
+ * touches keeps its identity, `model` itself is returned, so the application's
674
+ * root keeps its identity and Foldkit does not render. The common no-ops do (a
675
+ * duplicate live event, a repeated `ReadStarted`); a repeated failure, or a
676
+ * `preserve-existing` restore of entities already held, still makes an equal
677
+ * copy.
678
+ */
679
+ declare const updateRemote: (model: RemoteModel, message: RemoteMessage) => RemoteModel;
680
+ /**
681
+ * The Remote Model with a failed or unreadable durable write settled by the
682
+ * reader (`Data.dismiss`): out of the queue and the ledger, and done, so every
683
+ * tab drops it. A waiting one, or one not queued, is the Model itself.
684
+ */
685
+ declare const dismissQueued: (model: RemoteModel, requestId: string) => RemoteModel;
686
+ /** Whether this field's last read failed and nothing has settled it since. */
687
+ declare const isFieldFailed: (model: RemoteModel, entity: string, id: string, field: string) => boolean;
688
+ /**
689
+ * Whether a read is fetching any field `relation` reads of an entity, its own
690
+ * or, through each relation the store holds, its targets'. A value whose owner
691
+ * is being fetched is loading, not `Initial`: nothing is missing a fetch.
692
+ */
693
+ declare const isLoadingThrough: (model: RemoteModel, entity: string, id: string, relation: RelationRequirement) => boolean;
694
+ /**
695
+ * The first failure among the fields `relation` reads of an entity, following
696
+ * each relation the store holds into its targets, as `assemble` does. A read
697
+ * that consults it shows `Failed` for a related entity's failure too, rather
698
+ * than waiting on a field nothing will fetch.
699
+ */
700
+ declare const failureOf: (model: RemoteModel, entity: string, id: string, relation: RelationRequirement) => RemoteError | undefined;
701
+ /**
702
+ * Writes a read result into the store, recording each field's applied window so
703
+ * a later request with a different window refetches. A relation page requested
704
+ * with a cursor is merged onto the page already stored, so "load more"
705
+ * accumulates rather than replaces. Every read path should use this rather than
706
+ * reducing `writeEntity` by hand.
707
+ */
708
+ declare const writeRead: (store: EntityStore, requests: ReadonlyArray<Requirement>, result: Schema.Schema.Type<typeof ReadBatchResult>, now?: number) => EntityStore;
709
+ export { updateRemote as A, overlaysOf as C, remoteMessageSchema as D, remoteMessageCases as E, withRefreshRequested as M, writeRead as N, remoteModelSchema as O, onlyOverlaid as S, refreshedAt as T, isLoading as _, RemoteMessageInput as a, isRemoteMessage as b, StreamHealth as c, failureOf as d, fieldMark as f, isFieldFailed as g, invalidateConnections as h, RemoteMessage as i, windowGrowthKey as j, retentionRootsSchema as k, dismissQueued as l, initialRemoteModel as m, PlacedOrder as n, RemoteMessageTag as o, forgetRemote as p, RefreshState as r, RemoteModel as s, Failures as t, emptyRefresh as u, isLoadingThrough as v, refreshIsInFlight as w, noFailures as x, isQueryLoading as y };
710
+ //# sourceMappingURL=model-B6zk1NMB.d.ts.map