foldkit-remote 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.
@@ -0,0 +1,3526 @@
1
+ import { Context, Duration, Effect, Layer, Option, Result, Schema, Stream } from "effect";
2
+ import * as Domain from "foldkit-entity";
3
+ import { AnyEntity, AnyQuery, Dependencies, InputExpr, Query } from "foldkit-entity";
4
+ import { Command } from "foldkit/command";
5
+ import { EntryWithoutKeepAlive } from "foldkit/subscription";
6
+ import { ActiveSurface, Contract, Invalid, Metadata, ModelRef, Projection, Surface, Wiring } from "foldkit-surface";
7
+ import { Rpc, RpcClientError, RpcGroup } from "effect/rpc";
8
+ import { KeyValueStore } from "effect/persistence";
9
+ import * as Update from "foldkit/update";
10
+ //#region ../metadata/src/index.d.ts
11
+ /** Marks a `Metadata` value. Its entries are private to this module. */
12
+ declare const MetadataTypeId: unique symbol;
13
+ type MetadataTypeId = typeof MetadataTypeId;
14
+ /**
15
+ * Declarative facts an interpreter attaches to a node it does not own, such as
16
+ * the server data a Remote selection needs. The carrier holds and combines
17
+ * them without knowing what they mean; a package reads only the key it owns.
18
+ *
19
+ * Opaque: only a key's `of` and `Metadata.combine` make one, so entries cannot
20
+ * be forged past a key's type or `merge`, and they are frozen.
21
+ */
22
+ interface Metadata$1 {
23
+ readonly [MetadataTypeId]: MetadataTypeId;
24
+ }
25
+ /**
26
+ * An interpreter's typed slot in `Metadata`. Lookup is by the key object, never
27
+ * its `name`, so two packages cannot collide by choosing the same string.
28
+ */
29
+ interface MetadataKey<A> {
30
+ /** For tooling output only. */
31
+ readonly name: string;
32
+ /** Normalizes the entries gathered from combined values, e.g. unioning duplicates. */
33
+ readonly merge: (values: ReadonlyArray<A>) => ReadonlyArray<A>;
34
+ /** One line per entry for tooling output. */
35
+ readonly summarize: (value: A) => string;
36
+ readonly of: (...values: ReadonlyArray<A>) => Metadata$1;
37
+ readonly get: (metadata: Metadata$1) => ReadonlyArray<A>;
38
+ }
39
+ /** One key's entries as serializable text, named by the key. */
40
+ interface MetadataSummary {
41
+ readonly name: string;
42
+ readonly entries: readonly string[];
43
+ }
44
+ declare const Metadata$1: {
45
+ /**
46
+ * Declares an interpreter's slot. Call once per package, at module level:
47
+ * entries are found by the key object, so two copies of a package (a
48
+ * duplicated install, a reloaded module) do not see each other's entries.
49
+ */
50
+ key: <A>(name: string, options: {
51
+ readonly merge: (values: ReadonlyArray<A>) => ReadonlyArray<A>;
52
+ readonly summarize: (value: A) => string;
53
+ }) => MetadataKey<A>;
54
+ empty: Metadata$1;
55
+ /** True only for a value this module made; a copy or a hand-built brand is not one. */
56
+ is: (value: unknown) => value is Metadata$1;
57
+ /** Gathers every part's entries and runs each key's `merge` over its group. */
58
+ combine: (parts: ReadonlyArray<Metadata$1>) => Metadata$1;
59
+ summarize: (metadata: Metadata$1) => readonly MetadataSummary[];
60
+ };
61
+ //#endregion
62
+ //#region src/connection.d.ts
63
+ interface EdgeRef {
64
+ readonly entity: string;
65
+ readonly id: string;
66
+ }
67
+ /** `key` is the edge identity used for de-duplication. */
68
+ interface Edge {
69
+ readonly key: string;
70
+ readonly ref: EdgeRef;
71
+ }
72
+ declare const edge: (ref: EdgeRef, key?: string) => Edge;
73
+ type Cursor = string;
74
+ type Boundary = {
75
+ readonly _tag: 'Terminal';
76
+ } | {
77
+ readonly _tag: 'Cursor';
78
+ readonly cursor: Cursor;
79
+ } | {
80
+ readonly _tag: 'Unknown';
81
+ };
82
+ declare const terminal: Boundary;
83
+ declare const unknown: Boundary;
84
+ declare const cursor: (value: Cursor) => Boundary;
85
+ interface Segment {
86
+ readonly edges: readonly Edge[];
87
+ readonly start: Boundary;
88
+ readonly end: Boundary;
89
+ }
90
+ interface Connection {
91
+ readonly segments: readonly Segment[];
92
+ readonly stale: boolean;
93
+ }
94
+ declare const emptyConnection: Connection;
95
+ declare const segment: (edges: readonly Edge[], start: Boundary, end: Boundary) => Segment;
96
+ /** Adds a page to the connection, joining contiguous or overlapping segments. */
97
+ declare const merge: (current: Connection, page: Segment) => Connection;
98
+ /** Visible edges, segment by segment. */
99
+ declare const items: (connection: Connection) => ReadonlyArray<Edge>;
100
+ /** There is more before the known region. Derived from boundaries, never row count. */
101
+ declare const hasPrevious: (connection: Connection) => boolean;
102
+ /** There is more after the known region. Derived from boundaries, never row count. */
103
+ declare const hasNext: (connection: Connection) => boolean;
104
+ /** A connection with more than one segment has an explicit unknown gap. */
105
+ declare const isGapped: (connection: Connection) => boolean;
106
+ //#endregion
107
+ //#region src/remoteData.d.ts
108
+ interface RemoteError {
109
+ readonly _tag: string;
110
+ readonly message: string;
111
+ }
112
+ type RemoteData<A> = {
113
+ readonly _tag: 'Initial';
114
+ } | {
115
+ readonly _tag: 'Loading';
116
+ } | {
117
+ readonly _tag: 'Ready';
118
+ readonly value: A;
119
+ } | {
120
+ readonly _tag: 'Refreshing';
121
+ readonly value: A;
122
+ } | {
123
+ readonly _tag: 'Failed';
124
+ readonly error: RemoteError;
125
+ readonly previous?: A;
126
+ } | {
127
+ readonly _tag: 'NotFound';
128
+ };
129
+ /**
130
+ * What `RemoteData.render` tells the `data` branch about the value it is
131
+ * given: whether a newer answer is on its way, and whether this one is what
132
+ * was last known good before a read failed. It is one tag rather than two
133
+ * booleans because a value cannot be both at once, and a type that can say so
134
+ * invites a view to handle a state that never arrives.
135
+ */
136
+ type Freshness = {
137
+ readonly _tag: 'Fresh';
138
+ } | {
139
+ readonly _tag: 'Refreshing';
140
+ } | {
141
+ readonly _tag: 'Stale';
142
+ readonly error: RemoteError;
143
+ };
144
+ declare const remoteErrorSchema: Schema.Struct<{
145
+ readonly _tag: Schema.String;
146
+ readonly message: Schema.String;
147
+ }>;
148
+ declare const remoteDataSchema: <A>(value: Schema.Schema<A>) => Schema.Codec<RemoteData<A>, unknown>;
149
+ declare const RemoteData: {
150
+ /**
151
+ * The `RemoteData` schema for a value schema. Exposed so a `RemoteData` can
152
+ * be embedded in a hand-written Model schema, not only through `Remote.select`.
153
+ */
154
+ schema: <A>(value: Schema.Schema<A>) => Schema.Schema<RemoteData<A>>;
155
+ /** Exhaustive: omitting a state is a compile error. */
156
+ match: <A, R>(data: RemoteData<A>, cases: {
157
+ readonly Initial: () => R;
158
+ readonly Loading: () => R;
159
+ readonly Ready: (value: A) => R;
160
+ readonly Refreshing: (value: A) => R;
161
+ readonly Failed: (error: RemoteError, previous: Option.Option<A>) => R;
162
+ readonly NotFound: () => R;
163
+ }) => R;
164
+ /**
165
+ * The view-oriented fold: the six states as the three things a view actually
166
+ * draws, under the policy that useful data stays on screen. A value that is
167
+ * being refetched, or that a later read failed to replace, still reaches
168
+ * `data` — with `freshness` saying which — instead of being replaced by a
169
+ * spinner or an error the reader cannot act on.
170
+ *
171
+ * ```ts
172
+ * RemoteData.render(model.user, {
173
+ * loading: () => UserSkeleton(),
174
+ * notFound: () => NoSuchUser(),
175
+ * failed: error => ErrorView(error),
176
+ * data: (user, freshness) => UserView({ user, dimmed: freshness._tag !== 'Fresh' }),
177
+ * })
178
+ * ```
179
+ *
180
+ * `notFound` is its own branch and not optional: a row the server answered
181
+ * for and does not have is neither loading nor a failure, and drawing it as
182
+ * either is a spinner that never ends or an error nobody can fix.
183
+ *
184
+ * This does not replace `match`, which is the exhaustive fold over the states
185
+ * themselves. Reach for `match` when the six states really do draw
186
+ * differently, and for this when they draw the usual three ways.
187
+ */
188
+ render: <A, R>(data: RemoteData<A>, cases: {
189
+ readonly loading: () => R;
190
+ readonly notFound: () => R;
191
+ readonly failed: (error: RemoteError) => R;
192
+ readonly data: (value: A, freshness: Freshness) => R;
193
+ }) => R;
194
+ map: <A, B>(data: RemoteData<A>, f: (value: A) => B) => RemoteData<B>;
195
+ };
196
+ //#endregion
197
+ //#region src/store.d.ts
198
+ type EntityKey = string;
199
+ interface EntityEntry {
200
+ readonly values: Readonly<Record<string, unknown>>;
201
+ readonly present: ReadonlySet<string>;
202
+ /** Present fields whose value may be outdated (revalidation needed). */
203
+ readonly stale: ReadonlySet<string>;
204
+ /**
205
+ * Fields the server settled without a value: asked for, and answered without
206
+ * them, whatever the reason. Not planned again until a refresh asks; a later
207
+ * write of the field clears it.
208
+ */
209
+ readonly unavailable: ReadonlySet<string>;
210
+ /** The entity is known to be absent; a later write clears this. */
211
+ readonly tombstone: boolean;
212
+ /** Injected clock reading of the last write; never read from ambient state. */
213
+ readonly updatedAt: number;
214
+ /**
215
+ * The canonical window each present field was fetched with (`""` for none).
216
+ * A later request with a *known, different* window is planned as missing.
217
+ */
218
+ readonly windows: Readonly<Record<string, string>>;
219
+ }
220
+ type EntityStore = Readonly<Record<EntityKey, EntityEntry>>;
221
+ /** The separator keeps an untrusted id from colliding with a prototype key. */
222
+ declare const entityKey: (entity: string, id: string) => EntityKey;
223
+ declare const emptyStore: EntityStore;
224
+ interface EntityWrite {
225
+ readonly key: EntityKey;
226
+ readonly values: Readonly<Record<string, unknown>>;
227
+ /** The canonical window each written relation field was fetched with. */
228
+ readonly windows?: Readonly<Record<string, string>> | undefined;
229
+ /** When this write dates the entity, instead of the batch's `now`. */
230
+ readonly updatedAt?: number | undefined;
231
+ }
232
+ /**
233
+ * Merges known values into many entities, copying the store once. Every
234
+ * written field becomes present and non-stale; a tombstone is cleared because
235
+ * the entity is evidently not absent.
236
+ */
237
+ declare const writeEntities: (store: EntityStore, writes: ReadonlyArray<EntityWrite>, now?: number) => EntityStore;
238
+ /** `writeEntities` for one entity. */
239
+ declare const writeEntity: (store: EntityStore, key: EntityKey, values: Readonly<Record<string, unknown>>, now?: number, windows?: Readonly<Record<string, string>>) => EntityStore;
240
+ /**
241
+ * Marks present fields stale (`true`) or ends their staleness (`false`) across
242
+ * many entities, copying the store once. A field never present stays missing;
243
+ * an unknown entity is left alone.
244
+ */
245
+ declare const setStale: (store: EntityStore, marks: ReadonlyArray<readonly [key: EntityKey, fields: Iterable<string>]>, stale: boolean) => EntityStore;
246
+ /** Marks present fields stale; fields that were never present stay missing. */
247
+ declare const markStale: (store: EntityStore, key: EntityKey, fields: Iterable<string>) => EntityStore;
248
+ /** Ends a refresh that did not land: the fields are present again as they were. */
249
+ declare const clearStale: (store: EntityStore, key: EntityKey, fields: Iterable<string>) => EntityStore;
250
+ /**
251
+ * Records fields the server settled without a value. A present field is left
252
+ * as it is: the answer that settled it was not about the value it holds.
253
+ * `false` forgets the marks, which is how a refresh asks again.
254
+ */
255
+ declare const setUnavailable: (store: EntityStore, marks: ReadonlyArray<readonly [key: EntityKey, fields: Iterable<string>]>, unavailable: boolean) => EntityStore;
256
+ /** Whether the server settled this field without a value, and nothing has written it since. */
257
+ declare const isFieldUnavailable: (store: EntityStore, key: EntityKey, field: string) => boolean;
258
+ /** Records that the entity is known to be absent, so it is not refetched. */
259
+ declare const tombstone: (store: EntityStore, key: EntityKey) => EntityStore;
260
+ /** Forgets everything known about the entity, including a tombstone. */
261
+ declare const remove: (store: EntityStore, key: EntityKey) => EntityStore;
262
+ declare const entry: (store: EntityStore, key: EntityKey) => Option.Option<EntityEntry>;
263
+ declare const isTombstone: (store: EntityStore, key: EntityKey) => boolean;
264
+ /** A field is known only if it is present and not stale. */
265
+ declare const hasField: (store: EntityStore, key: EntityKey, field: string) => boolean;
266
+ /** A present field whose value may be outdated; absent fields are not stale. */
267
+ declare const isFieldStale: (store: EntityStore, key: EntityKey, field: string) => boolean;
268
+ /**
269
+ * Reads a present field, stale or not. Absence and a tombstone both yield
270
+ * `Option.none()`; a present `undefined`/`null` yields `Option.some`.
271
+ */
272
+ declare const readField: (store: EntityStore, key: EntityKey, field: string) => Option.Option<unknown>;
273
+ /**
274
+ * The fields the planner must fetch. A tombstone makes every field known
275
+ * (absent), so it returns an empty list and the entity is not refetched, and a
276
+ * field the server settled without a value is known the same way. A
277
+ * requested window that differs from the one a field was fetched with also
278
+ * marks it missing, but only when the stored window is known (never `""`), so a
279
+ * writer that does not record windows cannot cause a refetch loop.
280
+ */
281
+ declare const missingFields: (store: EntityStore, key: EntityKey, fields: Iterable<string>, windows?: Readonly<Record<string, string>>) => ReadonlyArray<string>;
282
+ //#endregion
283
+ //#region src/mutation.d.ts
284
+ interface NormalizedPatch {
285
+ readonly entity: string;
286
+ readonly id: string;
287
+ readonly values: Readonly<Record<string, unknown>>;
288
+ }
289
+ interface MutationState {
290
+ readonly pending: ReadonlySet<string>;
291
+ readonly applied: ReadonlySet<string>;
292
+ readonly failed: ReadonlySet<string>;
293
+ /** Why each request in `failed` failed, kept exactly as long as `failed` keeps its id. */
294
+ readonly errors: ReadonlyMap<string, RemoteError>;
295
+ /**
296
+ * How many mutations this model has started. A bound domain takes its next
297
+ * request id from here, so `update` stays pure and the id exists before the
298
+ * Command runs.
299
+ */
300
+ readonly sequence: number;
301
+ }
302
+ declare const emptyMutationState: MutationState;
303
+ declare const beginMutation: (state: MutationState, requestId: string) => MutationState;
304
+ declare const failMutation: (state: MutationState, requestId: string, error: RemoteError) => MutationState;
305
+ /** What Remote knows of one mutation request, by the id `mutate` returned. */
306
+ type MutationStatus =
307
+ /** Never started here, or settled so long ago its id has left the window. */
308
+ {
309
+ readonly _tag: 'Unknown';
310
+ } | {
311
+ readonly _tag: 'Pending';
312
+ } | {
313
+ readonly _tag: 'Applied';
314
+ } | {
315
+ readonly _tag: 'Failed';
316
+ readonly error: RemoteError;
317
+ };
318
+ declare const mutationStatus: (state: MutationState, requestId: string) => MutationStatus;
319
+ interface Reconciled {
320
+ readonly store: EntityStore;
321
+ readonly state: MutationState;
322
+ }
323
+ /** What a settled mutation wrote, as `MutationSucceeded` carries it. */
324
+ interface MutationAnswer {
325
+ readonly entities: ReadonlyArray<NormalizedPatch>;
326
+ /** Entities the mutation deleted; each is tombstoned. */
327
+ readonly deleted?: ReadonlyArray<{
328
+ readonly entity: string;
329
+ readonly id: string;
330
+ }> | undefined;
331
+ /** Injected clock reading of the answer, which dates what it writes. */
332
+ readonly now: number;
333
+ }
334
+ /**
335
+ * Applies a mutation result once and marks the request settled. A second call
336
+ * with the same `requestId` (a retry, or a live event describing the same change)
337
+ * does not re-apply the entities, but still clears `pending`.
338
+ */
339
+ declare const reconcileMutation: (store: EntityStore, state: MutationState, requestId: string, answer: MutationAnswer) => Reconciled;
340
+ /** A mutation an application declares: its name and input/output codecs. */
341
+ interface MutationDescriptor<Name extends string, Input, Output> {
342
+ readonly name: Name;
343
+ readonly Input: Schema.Codec<Input>;
344
+ readonly Output: Schema.Codec<Output>;
345
+ }
346
+ /** A codec, or the fields of a `Schema.Struct` where one is expected. */
347
+ type SchemaOrFields = Schema.Codec<any, any, any, any> | Schema.Struct.Fields;
348
+ /** The decoded type of a codec, or of the Struct the fields describe. */
349
+ type TypeOf<S extends SchemaOrFields> = S extends Schema.Codec<infer T, any, any, any> ? T : S extends Schema.Struct.Fields ? Schema.Struct.Type<S> : never;
350
+ /** The codec itself, or a `Schema.Struct` over the fields. */
351
+ declare const schemaOf: <S extends SchemaOrFields>(shape: S) => Schema.Codec<TypeOf<S>>;
352
+ declare const Mutation: {
353
+ /**
354
+ * Declares a mutation. `Input` and `Output` are codecs, or the fields of the
355
+ * `Schema.Struct` they would be (`{ id: ProjectId, name: Schema.String }`).
356
+ */
357
+ make: <const Name extends string, Input extends SchemaOrFields, Output extends SchemaOrFields>(name: Name, config: {
358
+ readonly Input: Input;
359
+ readonly Output: Output;
360
+ }) => MutationDescriptor<Name, TypeOf<Input>, TypeOf<Output>>;
361
+ };
362
+ //#endregion
363
+ //#region src/query.d.ts
364
+ type LiveInsertion = 'visible' | 'boundary' | 'invalidate' | 'ignore';
365
+ interface LivePolicy {
366
+ readonly prepend?: LiveInsertion;
367
+ readonly append?: LiveInsertion;
368
+ }
369
+ interface ConnectionSpec<Entity extends string = string> {
370
+ readonly entity: Entity;
371
+ readonly edgeKey?: Schema.Schema<unknown>;
372
+ readonly live?: LivePolicy;
373
+ }
374
+ interface QueryWindow {
375
+ readonly first?: number | undefined;
376
+ readonly last?: number | undefined;
377
+ readonly after?: Cursor | undefined;
378
+ readonly before?: Cursor | undefined;
379
+ }
380
+ interface QueryRef<Name extends string, Input> {
381
+ readonly query: Name;
382
+ readonly input: Input;
383
+ /** The input codec, so a `QueryRef` can encode itself without its descriptor. */
384
+ readonly Input: Schema.Codec<Input>;
385
+ readonly window: QueryWindow;
386
+ /** Connection identity: descriptor + canonical input, excluding the window. */
387
+ readonly identity: string;
388
+ }
389
+ interface QueryDescriptor<Name extends string, Input, Result> {
390
+ readonly name: Name;
391
+ readonly Input: Schema.Codec<Input>;
392
+ readonly Result: Result;
393
+ readonly ref: (input: Input) => QueryRef<Name, Input>;
394
+ /**
395
+ * What the query means, when it was declared with `Query.define`: the rows it
396
+ * is about, as a value an interpreter can compile. A descriptor from
397
+ * `Query.make` has none — its meaning lives in whatever the server registered
398
+ * to answer it — and a source is free to answer either.
399
+ */
400
+ readonly body?: AnyQuery | undefined;
401
+ }
402
+ /**
403
+ * The inputs of a definition's body: one placeholder per key of `Input`, typed
404
+ * as that key's value. A body is built once, so these stand for what the query
405
+ * will be given rather than being it.
406
+ */
407
+ type QueryInputs<Input> = { readonly [K in keyof Input & string]: InputExpr<Input[K]>; };
408
+ /**
409
+ * What separates a query's name from its canonical encoded input in a
410
+ * connection identity.
411
+ *
412
+ * NUL, because `JSON.stringify` escapes it inside a string (`\u0000`) and a
413
+ * query name is a TypeScript identifier — so the first occurrence is always the
414
+ * boundary, and a name or an input value cannot forge one. Anything recovering
415
+ * the query from an identity splits here.
416
+ */
417
+ declare const IDENTITY_SEPARATOR = "\0";
418
+ /** Stable stringify: object keys sorted, undefined-valued keys dropped, so equal inputs encode equally. */
419
+ declare const stableStringify: (value: unknown) => string;
420
+ /**
421
+ * `Result: Project` (or anything with the entity's `name`, as `Query.connection`
422
+ * takes) means a connection over it; a `ConnectionSpec` names its `entity`
423
+ * instead and is the result as given.
424
+ */
425
+ type ResultOf<Result> = Result extends {
426
+ readonly name: infer Entity extends string;
427
+ } ? ConnectionSpec<Entity> : Result;
428
+ /** A relational `Query` over one Entity, as `Query.define`'s body returns. */
429
+ type RelationalQueryOf<E extends AnyEntity> = ReturnType<typeof Query.from<E>>;
430
+ declare const Query$1: {
431
+ /** Declares the entity and options a query's result is a connection over. */
432
+ connection: <Entity extends string>(entity: {
433
+ readonly name: Entity;
434
+ }, options?: {
435
+ readonly edgeKey?: Schema.Schema<unknown>;
436
+ readonly live?: LivePolicy;
437
+ }) => ConnectionSpec<Entity>;
438
+ /**
439
+ * Declares a query. `Input` is a codec or the fields of the `Schema.Struct` it
440
+ * would be; `Result` is a `Query.connection(...)`, or the entity the result is
441
+ * a connection over.
442
+ */
443
+ make: <const Name extends string, Input extends SchemaOrFields, Result>(name: Name, config: {
444
+ readonly Input: Input;
445
+ readonly Result: Result;
446
+ }) => QueryDescriptor<Name, TypeOf<Input>, ResultOf<Result>>;
447
+ /**
448
+ * Declares a query by what it means. The body is built once, here, and the
449
+ * `input` it is given holds placeholders rather than values — there is
450
+ * nothing yet to branch on, so a condition that depends on what was passed is
451
+ * a comparison over the placeholder:
452
+ *
453
+ * ```ts
454
+ * const PostsBySlug = Query.define('PostsBySlug', { slug: Schema.String }, ({ input }) =>
455
+ * Query.from(Post).pipe(
456
+ * Query.where(Expr.eq(Post.fields.slug, input.slug)),
457
+ * Query.orderBy(Order.asc(Post.fields.id)),
458
+ * ),
459
+ * )
460
+ * ```
461
+ *
462
+ * What comes back is an ordinary `QueryDescriptor` — the same name, `Input`,
463
+ * `ref` and connection identity `Query.make` gives — carrying its `body`
464
+ * besides. A server can compile that body instead of being told the same
465
+ * thing again in its own dialect, and one that would rather answer the query
466
+ * its own way still can.
467
+ *
468
+ * The result is a connection over the Entity the body reads, so it is not
469
+ * named twice.
470
+ */
471
+ define: <const Name extends string, Input extends SchemaOrFields, E extends AnyEntity>(name: Name, Input: Input, body: (context: {
472
+ readonly input: QueryInputs<TypeOf<Input>>;
473
+ }) => RelationalQueryOf<E>, options?: {
474
+ readonly edgeKey?: Schema.Schema<unknown>;
475
+ readonly live?: LivePolicy;
476
+ }) => QueryDescriptor<Name, TypeOf<Input>, ConnectionSpec<E["name"]>>;
477
+ first: (count: number) => <R extends QueryRef<string, unknown>>(ref: R) => R;
478
+ last: (count: number) => <R extends QueryRef<string, unknown>>(ref: R) => R;
479
+ after: (cursor: Cursor) => <R extends QueryRef<string, unknown>>(ref: R) => R;
480
+ before: (cursor: Cursor) => <R extends QueryRef<string, unknown>>(ref: R) => R;
481
+ from: <E extends AnyEntity>(entity: E) => Query<E>;
482
+ where: (...predicates: ReadonlyArray<import("foldkit-entity").Predicate>) => <E extends AnyEntity>(self: Query<E>) => Query<E>;
483
+ orderBy: (...terms: ReadonlyArray<import("foldkit-entity").OrderTerm>) => <E extends AnyEntity>(self: Query<E>) => Query<E>;
484
+ dependencies: (self: AnyQuery) => import("foldkit-entity").Dependencies;
485
+ unsupported: (self: AnyQuery, supported: ReadonlyArray<import("foldkit-entity").Operation>) => ReadonlyArray<import("foldkit-entity").Operation>;
486
+ show: (self: AnyQuery) => string;
487
+ };
488
+ //#endregion
489
+ //#region src/requirement.d.ts
490
+ /**
491
+ * The slice required of an entity. `windows` carries a pagination window per
492
+ * relation field, and `relations` the slice required of each relation's
493
+ * target, so one requirement describes a whole selection graph.
494
+ */
495
+ interface RelationRequirement {
496
+ readonly entity: string;
497
+ readonly fields: readonly string[];
498
+ readonly windows?: Readonly<Record<string, QueryWindow>> | undefined;
499
+ readonly relations?: Readonly<Record<string, RelationRequirement>> | undefined;
500
+ }
501
+ interface Requirement extends RelationRequirement {
502
+ readonly id: string;
503
+ /** The projection also subscribes to changes of this entity (`Data.live`). */
504
+ readonly live?: boolean | undefined;
505
+ }
506
+ /**
507
+ * A query connection a projection reads: the page it first asks for and the
508
+ * slice it selects of each item. `identity` is the connection's (query plus
509
+ * canonical input, excluding the window).
510
+ */
511
+ interface ConnectionRequirement {
512
+ readonly identity: string;
513
+ readonly window: QueryWindow;
514
+ readonly select: RelationRequirement;
515
+ }
516
+ /**
517
+ * Merges connection requirements for the same connection and window into one,
518
+ * unioning what they select of each item; the first keeps its other properties.
519
+ */
520
+ declare function mergeConnections(connections: readonly ConnectionRequirement[]): readonly ConnectionRequirement[];
521
+ /** Unions two relation slices for the same target: fields, windows, and nested relations. */
522
+ declare function mergeRelation(current: RelationRequirement, next: RelationRequirement): RelationRequirement;
523
+ /** Unions requirements for the same entity + id, dropping duplicate fields. */
524
+ declare function mergeRequirements(requirements: readonly Requirement[]): readonly Requirement[];
525
+ /**
526
+ * Requirement helpers, for the packages that plan and serve requirements.
527
+ * `merge` unions same-entity+id requirements; `mergeRelation` unions two
528
+ * slices of one target (fields, windows, nested relations).
529
+ */
530
+ declare const Requirement: {
531
+ merge: typeof mergeRequirements;
532
+ mergeRelation: typeof mergeRelation;
533
+ mergeConnections: typeof mergeConnections;
534
+ };
535
+ /** Remote's entity requirements on a Projection, unioned per entity and id as nodes compose. */
536
+ declare const RemoteRequirements: MetadataKey<Requirement>;
537
+ /** Remote's query connections on a Projection, unioned per connection and window. */
538
+ declare const RemoteConnections: MetadataKey<ConnectionRequirement>;
539
+ /** The entity requirements a Projection carries. */
540
+ declare const requirementsOf: (projection: {
541
+ readonly metadata: Metadata;
542
+ }) => ReadonlyArray<Requirement>;
543
+ /** The query connections a Projection carries. */
544
+ declare const connectionsOf: (projection: {
545
+ readonly metadata: Metadata;
546
+ }) => ReadonlyArray<ConnectionRequirement>;
547
+ //#endregion
548
+ //#region src/optimistic.d.ts
549
+ interface EntityLayer {
550
+ readonly id: string;
551
+ readonly patches: ReadonlyArray<NormalizedPatch>;
552
+ }
553
+ /**
554
+ * Edges placed outside a connection's server-known region (`prepend`,
555
+ * `append`) or hidden from it (`remove`), owned by the request or live event
556
+ * that produced them.
557
+ */
558
+ interface ConnectionOverlay {
559
+ readonly id: string;
560
+ readonly connection: string;
561
+ readonly edges: ReadonlyArray<Edge>;
562
+ readonly position: 'prepend' | 'append' | 'remove';
563
+ }
564
+ /** A connection change a request makes optimistically or a mutation result confirms. */
565
+ type ConnectionChange = {
566
+ readonly _tag: 'Insert';
567
+ readonly connection: string;
568
+ readonly position: 'prepend' | 'append';
569
+ readonly edge: Edge;
570
+ } | {
571
+ readonly _tag: 'Remove';
572
+ readonly connection: string;
573
+ readonly edge: Edge;
574
+ };
575
+ /** What a request changes before the server answers: entity patches and connection changes. */
576
+ type OptimisticOperation = NormalizedPatch | ConnectionChange;
577
+ /** A connection, by identity string or by anything that carries one (a `QueryRef`). */
578
+ type ConnectionIdentity = string | {
579
+ readonly identity: string;
580
+ };
581
+ declare const connectionIdentity: (connection: ConnectionIdentity) => string;
582
+ /**
583
+ * Constructors for connection changes: what a request shows optimistically
584
+ * (`MutateOptions.optimistic`) and what a mutation source reports it made
585
+ * (`MutationOutcome.connections`).
586
+ */
587
+ declare const ConnectionChange: {
588
+ /** Show `ref` at the front of the connection until the request settles. */
589
+ prepend: (connection: ConnectionIdentity, ref: {
590
+ readonly entity: string;
591
+ readonly id: string;
592
+ }) => ConnectionChange;
593
+ /** Show `ref` at the end of the connection until the request settles. */
594
+ append: (connection: ConnectionIdentity, ref: {
595
+ readonly entity: string;
596
+ readonly id: string;
597
+ }) => ConnectionChange;
598
+ /** Hide `ref` from the connection until the request settles. */
599
+ remove: (connection: ConnectionIdentity, ref: {
600
+ readonly entity: string;
601
+ readonly id: string;
602
+ }) => ConnectionChange;
603
+ };
604
+ /**
605
+ * Applies a request's operations: its patches become one layer and its
606
+ * connection changes become overlays, all owned by `requestId` so settling
607
+ * removes every one of them together.
608
+ */
609
+ declare const beginOptimistic: (optimistic: OptimisticState, requestId: string, operations: ReadonlyArray<OptimisticOperation>) => OptimisticState;
610
+ /** Pending entity layers and connection overlays over the base store. */
611
+ interface OptimisticState {
612
+ readonly layers: ReadonlyArray<EntityLayer>;
613
+ readonly overlays: ReadonlyArray<ConnectionOverlay>;
614
+ }
615
+ declare const emptyOptimistic: OptimisticState;
616
+ declare const addLayer: (optimistic: OptimisticState, layer: EntityLayer) => OptimisticState;
617
+ declare const removeLayer: (optimistic: OptimisticState, id: string) => OptimisticState;
618
+ declare const addOverlay: (optimistic: OptimisticState, overlay: ConnectionOverlay) => OptimisticState;
619
+ declare const removeOverlay: (optimistic: OptimisticState, id: string) => OptimisticState;
620
+ /**
621
+ * Base store with every layer applied in order. Later layers win. A patch is
622
+ * not news from the server, so it keeps the date of the value under it; an
623
+ * entity only a request holds (a temporary id) is not the server's to age, and
624
+ * is dated `Infinity`, so freshness never plans or times it.
625
+ */
626
+ declare const visibleStore: (base: EntityStore, optimistic: OptimisticState) => EntityStore;
627
+ /**
628
+ * A fresh page is newer than any settled overlay it covers: an edge the page
629
+ * carries no longer needs an insert overlay, and a `remove` overlay hiding it
630
+ * is stale (the server says it is back). A pending request's overlays are
631
+ * left alone; they settle with the request.
632
+ */
633
+ declare const pruneOverlays: (optimistic: OptimisticState, connection: string, covered: ReadonlySet<string>, pending: ReadonlySet<string>) => OptimisticState;
634
+ /**
635
+ * Applies a result idempotently and releases the request's layer and overlays:
636
+ * a later layer re-wins on rebase. Confirmed connection changes are recorded
637
+ * once per request, as overlays the request no longer owns.
638
+ */
639
+ declare const settleSuccess: (base: EntityStore, optimistic: OptimisticState, state: MutationState, requestId: string, answer: MutationAnswer & {
640
+ /** Connection changes the server confirmed; they replace the request's own. */
641
+ readonly connections?: ReadonlyArray<ConnectionChange> | undefined;
642
+ }) => {
643
+ readonly store: EntityStore;
644
+ readonly state: MutationState;
645
+ readonly optimistic: OptimisticState;
646
+ };
647
+ /** A failed request's layer and overlays are dropped; the base was never mutated. */
648
+ declare const settleFailure: (optimistic: OptimisticState, requestId: string) => OptimisticState;
649
+ /**
650
+ * Visible edges for one connection: applicable overlays are placed outside the
651
+ * server-known segments and de-duplicated by edge identity (across overlays too),
652
+ * so a pending insert never corrupts server-known ordering; a `remove` overlay
653
+ * hides its edges wherever they are, and so does a tombstone on the edge's
654
+ * target when `store` is given. A later prepend lands before an earlier one, a
655
+ * later append after, so pending inserts read in the order they were made.
656
+ * Boundaries still come from the connection's segments.
657
+ */
658
+ declare const visibleItems: (connection: Connection, connectionId: string, overlays: ReadonlyArray<ConnectionOverlay>, store?: EntityStore) => ReadonlyArray<Edge>;
659
+ //#endregion
660
+ //#region src/live.d.ts
661
+ type LiveCursor = number;
662
+ type LiveEvent = {
663
+ readonly _tag: 'EntityPatched';
664
+ readonly ref: EdgeRef;
665
+ readonly values: Readonly<Record<string, unknown>>;
666
+ readonly changed: ReadonlyArray<string>;
667
+ readonly cursor: LiveCursor;
668
+ } | {
669
+ readonly _tag: 'EntityDeleted';
670
+ readonly ref: EdgeRef;
671
+ readonly cursor: LiveCursor;
672
+ } | {
673
+ readonly _tag: 'ConnectionInsert';
674
+ readonly connection: string;
675
+ readonly position: 'prepend' | 'append';
676
+ readonly edge: Edge;
677
+ readonly cursor: LiveCursor;
678
+ } | {
679
+ readonly _tag: 'ConnectionRemove';
680
+ readonly connection: string;
681
+ readonly edge: Edge;
682
+ readonly cursor: LiveCursor;
683
+ } | {
684
+ readonly _tag: 'ConnectionInvalidate';
685
+ readonly connection: string;
686
+ readonly cursor: LiveCursor;
687
+ };
688
+ interface BoundaryCounts {
689
+ readonly before: number;
690
+ readonly after: number;
691
+ }
692
+ interface LiveState {
693
+ /** Last applied cursor for this stream. */
694
+ readonly cursor: LiveCursor;
695
+ /** Edges recorded outside the loaded boundary, not visible in `items`. */
696
+ readonly boundary: Readonly<Record<string, BoundaryCounts>>;
697
+ }
698
+ declare const emptyLiveState: LiveState;
699
+ type LiveOutcome = 'applied' | 'duplicate' | 'gap';
700
+ /**
701
+ * Ordering per stream: at most the next cursor; ahead is a gap. Cursor `0` means
702
+ * "no baseline yet" (cursors are 1-based), so the first event of a stream is
703
+ * accepted whatever its cursor — otherwise a stream not starting at 1 would be a
704
+ * spurious gap.
705
+ */
706
+ declare const classifyLive: (state: LiveState, cursor: LiveCursor) => LiveOutcome;
707
+ interface EntityApplied {
708
+ readonly state: LiveState;
709
+ readonly store: EntityStore;
710
+ readonly outcome: LiveOutcome;
711
+ }
712
+ declare const applyEntityEvent: (state: LiveState, store: EntityStore, event: Extract<LiveEvent, {
713
+ _tag: "EntityPatched" | "EntityDeleted";
714
+ }>, now?: number) => EntityApplied;
715
+ interface ConnectionApplied {
716
+ readonly state: LiveState;
717
+ readonly optimistic: OptimisticState;
718
+ readonly outcome: LiveOutcome;
719
+ /**
720
+ * A connection the event says to refetch. Reported rather than recorded here,
721
+ * because staleness lives on the connection in the Model — which is what the
722
+ * planner and every read consult. It used to be written into a set on this
723
+ * live state that nothing read, so an invalidating event did nothing at all.
724
+ */
725
+ readonly invalidated?: string | undefined;
726
+ }
727
+ declare const applyConnectionEvent: (state: LiveState, optimistic: OptimisticState, event: Extract<LiveEvent, {
728
+ _tag: "ConnectionInsert" | "ConnectionRemove" | "ConnectionInvalidate";
729
+ }>, policy?: LivePolicy) => ConnectionApplied;
730
+ /** `hasPrevious` accounting for edges recorded outside the loaded boundary. */
731
+ declare const liveHasPrevious: (connection: Connection, state: LiveState, connectionId: string) => boolean;
732
+ /** `hasNext` accounting for edges recorded outside the loaded boundary. */
733
+ declare const liveHasNext: (connection: Connection, state: LiveState, connectionId: string) => boolean;
734
+ //#endregion
735
+ //#region src/retain.d.ts
736
+ /** A connection to keep: its identity, and what a page of it selects of each item, if a projection reads it. */
737
+ interface ConnectionRoot {
738
+ readonly identity: string;
739
+ readonly select?: RelationRequirement | undefined;
740
+ }
741
+ interface RetentionRoots {
742
+ readonly requirements: ReadonlyArray<Requirement>;
743
+ /** Connections (`QueryRef.identity`) to keep, with their edges' targets and what `select` reaches through them. */
744
+ readonly connections: ReadonlyArray<ConnectionRoot>;
745
+ }
746
+ interface Retained {
747
+ readonly entities: EntityStore;
748
+ readonly connections: Readonly<Record<string, Connection>>;
749
+ readonly optimistic: OptimisticState;
750
+ }
751
+ /**
752
+ * The entity keys the roots reach: each root entity, the targets its retained
753
+ * fields refer to, and recursively the targets a nested relation selects.
754
+ */
755
+ declare const reachable: (store: EntityStore, roots: RetentionRoots, connections: Readonly<Record<string, Connection>>, optimistic: OptimisticState, pending: ReadonlySet<string>) => ReadonlySet<EntityKey>;
756
+ /**
757
+ * Drops every entity the roots do not reach, every connection they do not
758
+ * name, and every settled overlay on a dropped connection, keeping whatever a
759
+ * pending request's layer or overlays touch. Pure.
760
+ */
761
+ declare const gc: (state: Retained & {
762
+ readonly mutations: MutationState;
763
+ }, roots: RetentionRoots) => Retained;
764
+ //#endregion
765
+ //#region src/persistence.d.ts
766
+ /** Bump when the serialized shape changes; a mismatch discards the cache. */
767
+ declare const REMOTE_CACHE_VERSION = 5;
768
+ /**
769
+ * What survives a reload: the entity cache, and the connections an application
770
+ * **declared** should come back.
771
+ *
772
+ * Connections are session state by default and stay that way — `snapshotOf`
773
+ * takes none unless asked. What a declared one keeps is its **edges and
774
+ * nothing else**, which is not a simplification but the rule: a connection's
775
+ * boundaries are cursors the server minted, and a cursor may name server state
776
+ * that no longer exists. Restoring one would be claiming to know where the
777
+ * page ends. The shape has nowhere to put a cursor, so that cannot be got
778
+ * wrong later.
779
+ */
780
+ interface Snapshot {
781
+ readonly entities: EntityStore;
782
+ /**
783
+ * By connection identity: its **segments**, each a run of edges. No
784
+ * boundaries.
785
+ *
786
+ * Segments rather than one flat list, because the gaps between them are
787
+ * knowledge too. A connection paged from both ends holds a head and a tail
788
+ * with an unfetched middle; flattening those into one run would claim the
789
+ * tail's first row follows the head's last, which is a thing the client was
790
+ * never told.
791
+ */
792
+ readonly connections: Readonly<Record<string, ReadonlyArray<ReadonlyArray<Edge>>>>;
793
+ }
794
+ interface SnapshotOptions {
795
+ /**
796
+ * Who or what the snapshot is for (a user id, a tenant, a build). A snapshot
797
+ * taken under another scope is discarded rather than shown to the wrong
798
+ * reader. Default: unscoped, which only matches unscoped.
799
+ */
800
+ readonly scope?: string | undefined;
801
+ /** Snapshots larger than this many bytes are not written and not read. */
802
+ readonly maxBytes?: number | undefined;
803
+ }
804
+ /** How a snapshot meets a store that already has entries. */
805
+ type MergePolicy = 'replace' | 'preserve-existing';
806
+ /**
807
+ * The snapshot text, or `undefined` when it would exceed `maxBytes`. Build the
808
+ * snapshot with `snapshotOf`, which is where the connections that survive are
809
+ * named; runtime state — optimistic layers, live cursors, gaps, the mutation
810
+ * ledger — is never in one.
811
+ */
812
+ declare function dehydrate(snapshot: Snapshot, options?: SnapshotOptions & {
813
+ readonly maxBytes?: undefined;
814
+ }): string;
815
+ declare function dehydrate(snapshot: Snapshot, options?: SnapshotOptions): string | undefined;
816
+ declare const RemotePersistence: {
817
+ /** The snapshot text, or `undefined` when it would exceed `maxBytes`. */
818
+ dehydrate: typeof dehydrate;
819
+ /** What a snapshot text holds, or `undefined` when it is refused. */
820
+ hydrate: (raw: string | undefined | null, options?: SnapshotOptions) => Snapshot | undefined;
821
+ /**
822
+ * What to keep of a Model, naming the connections that should survive a
823
+ * reload. Naming none is the default and is what Remote always did.
824
+ */
825
+ snapshotOf: (model: {
826
+ readonly entities: EntityStore;
827
+ readonly connections: Readonly<Record<string, Connection>>;
828
+ }, options?: {
829
+ readonly connections?: ReadonlyArray<ConnectionIdentity> | undefined;
830
+ }) => Snapshot;
831
+ /** A snapshot's entities brought into a store by policy. */
832
+ mergeStores: (current: EntityStore, snapshot: EntityStore, policy: MergePolicy) => EntityStore;
833
+ /** The cache as a fresh session has it; what a refused `restore` yields. */
834
+ emptySnapshot: Snapshot;
835
+ /**
836
+ * Writes the snapshot under `key`, or removes the key when the store would
837
+ * exceed `maxBytes`, so a stale smaller snapshot cannot outlive a larger
838
+ * store it no longer describes.
839
+ */
840
+ save: (snapshot: Snapshot, options: {
841
+ readonly key: string;
842
+ } & SnapshotOptions) => Effect.Effect<void, KeyValueStore.KeyValueStoreError, KeyValueStore.KeyValueStore>;
843
+ /**
844
+ * Reads the cache. A missing key yields `emptySnapshot`; anything `hydrate`
845
+ * refuses yields `emptySnapshot` and removes the key, so the next `restore`
846
+ * is clean and the planner refetches.
847
+ */
848
+ restore: (options: {
849
+ readonly key: string;
850
+ } & SnapshotOptions) => Effect.Effect<Snapshot, KeyValueStore.KeyValueStoreError, KeyValueStore.KeyValueStore>;
851
+ };
852
+ //#endregion
853
+ //#region src/wire.d.ts
854
+ /**
855
+ * The read/live protocol version. A batch names the version it speaks and the
856
+ * server refuses a mismatch with `RemoteProtocolError`, so a shape change never
857
+ * drifts silently: bump it whenever `ReadRequest` or `LiveRequirement` change.
858
+ */
859
+ declare const REMOTE_PROTOCOL_VERSION = 4;
860
+ declare const RemoteReadError_base: Schema.Class<RemoteReadError, Schema.TaggedStruct<"RemoteReadError", {
861
+ readonly message: Schema.String;
862
+ }>, import("effect/Cause").YieldableError>;
863
+ declare class RemoteReadError extends RemoteReadError_base {}
864
+ declare const RemoteMutationError_base: Schema.Class<RemoteMutationError, Schema.TaggedStruct<"RemoteMutationError", {
865
+ readonly message: Schema.String;
866
+ }>, import("effect/Cause").YieldableError>;
867
+ declare class RemoteMutationError extends RemoteMutationError_base {}
868
+ declare const RemoteLiveError_base: Schema.Class<RemoteLiveError, Schema.TaggedStruct<"RemoteLiveError", {
869
+ readonly message: Schema.String;
870
+ }>, import("effect/Cause").YieldableError>;
871
+ declare class RemoteLiveError extends RemoteLiveError_base {}
872
+ declare const RemoteProtocolError_base: Schema.Class<RemoteProtocolError, Schema.TaggedStruct<"RemoteProtocolError", {
873
+ readonly message: Schema.String;
874
+ readonly expected: Schema.Number;
875
+ readonly received: Schema.Number;
876
+ }>, import("effect/Cause").YieldableError>;
877
+ /** The peer speaks another protocol version; nothing was read. */
878
+ declare class RemoteProtocolError extends RemoteProtocolError_base {}
879
+ /** A page size: a non-negative integer, refused at decode otherwise rather than defaulted. */
880
+ declare const PageSize: Schema.Number;
881
+ declare const WindowSchema: Schema.Struct<{
882
+ readonly first: Schema.optional<Schema.Number>;
883
+ readonly last: Schema.optional<Schema.Number>;
884
+ readonly after: Schema.optional<Schema.String>;
885
+ readonly before: Schema.optional<Schema.String>;
886
+ }>;
887
+ /** A request may not name more fields of one entity than this; a selection never does. */
888
+ declare const MAX_FIELDS_PER_REQUEST = 256;
889
+ /** A selection may not nest relations deeper than this; the wire refuses more. */
890
+ declare const MAX_RELATION_DEPTH = 8;
891
+ declare const RelationRequest: Schema.Codec<RelationRequirement, RelationRequirement, never, never>;
892
+ declare const ReadRequest: Schema.Codec<Requirement, Requirement>;
893
+ declare const ReadBatch: Schema.Struct<{
894
+ readonly version: Schema.Number;
895
+ readonly requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
896
+ }>;
897
+ declare const NormalizedEntity: Schema.Struct<{
898
+ readonly entity: Schema.String;
899
+ readonly id: Schema.String;
900
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
901
+ }>;
902
+ /**
903
+ * Fields a read asked for that the server answered without, and will not
904
+ * answer with: the client stops asking. It says nothing about why, so a rule
905
+ * that withholds a field is not itself on the wire.
906
+ */
907
+ declare const SettledFields: Schema.Struct<{
908
+ readonly entity: Schema.String;
909
+ readonly id: Schema.String;
910
+ readonly fields: Schema.$Array<Schema.String>;
911
+ }>;
912
+ declare const ReadBatchResult: Schema.Struct<{
913
+ readonly entities: Schema.$Array<Schema.Struct<{
914
+ readonly entity: Schema.String;
915
+ readonly id: Schema.String;
916
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
917
+ }>>;
918
+ readonly settled: Schema.$Array<Schema.Struct<{
919
+ readonly entity: Schema.String;
920
+ readonly id: Schema.String;
921
+ readonly fields: Schema.$Array<Schema.String>;
922
+ }>>;
923
+ }>;
924
+ declare const MutationRequest: Schema.Struct<{
925
+ /** Stable across transport retries so a mutation is not applied twice. */
926
+ readonly requestId: Schema.String;
927
+ readonly mutation: Schema.String;
928
+ readonly input: Schema.Unknown;
929
+ }>;
930
+ declare const LiveEdge: Schema.Struct<{
931
+ readonly entity: Schema.String;
932
+ readonly id: Schema.String;
933
+ readonly key: Schema.String;
934
+ }>;
935
+ /** A connection change a mutation confirms: the same facts a live event carries, without a cursor. */
936
+ declare const ConnectionChangeSchema: Schema.Union<readonly [Schema.Struct<{
937
+ readonly _tag: Schema.Literal<"Insert">;
938
+ readonly connection: Schema.String;
939
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
940
+ readonly edge: Schema.Struct<{
941
+ readonly entity: Schema.String;
942
+ readonly id: Schema.String;
943
+ readonly key: Schema.String;
944
+ }>;
945
+ }>, Schema.Struct<{
946
+ readonly _tag: Schema.Literal<"Remove">;
947
+ readonly connection: Schema.String;
948
+ readonly edge: Schema.Struct<{
949
+ readonly entity: Schema.String;
950
+ readonly id: Schema.String;
951
+ readonly key: Schema.String;
952
+ }>;
953
+ }>]>;
954
+ declare const MutationResult: Schema.Struct<{
955
+ readonly output: Schema.Unknown;
956
+ readonly entities: Schema.$Array<Schema.Struct<{
957
+ readonly entity: Schema.String;
958
+ readonly id: Schema.String;
959
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
960
+ }>>;
961
+ /** Connection changes the mutation made, applied alongside its entity patches. */
962
+ readonly connections: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
963
+ readonly _tag: Schema.Literal<"Insert">;
964
+ readonly connection: Schema.String;
965
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
966
+ readonly edge: Schema.Struct<{
967
+ readonly entity: Schema.String;
968
+ readonly id: Schema.String;
969
+ readonly key: Schema.String;
970
+ }>;
971
+ }>, Schema.Struct<{
972
+ readonly _tag: Schema.Literal<"Remove">;
973
+ readonly connection: Schema.String;
974
+ readonly edge: Schema.Struct<{
975
+ readonly entity: Schema.String;
976
+ readonly id: Schema.String;
977
+ readonly key: Schema.String;
978
+ }>;
979
+ }>]>>>;
980
+ /** Entities the mutation deleted; the client knows them absent from then on. */
981
+ readonly deleted: Schema.optional<Schema.$Array<Schema.Struct<{
982
+ readonly entity: Schema.String;
983
+ readonly id: Schema.String;
984
+ }>>>;
985
+ }>;
986
+ declare const LiveRequirement: Schema.Struct<{
987
+ readonly version: Schema.Number;
988
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
989
+ /** Resume cursor; events at or before it are duplicates. */
990
+ readonly after: Schema.Number;
991
+ }>;
992
+ /**
993
+ * A live change. Entity changes update the store; connection changes alter
994
+ * membership and ordering; both carry a per-stream cursor.
995
+ */
996
+ declare const LiveChange: Schema.Union<readonly [Schema.Struct<{
997
+ readonly _tag: Schema.Literal<"EntityPatched">;
998
+ readonly cursor: Schema.Number;
999
+ readonly entity: Schema.String;
1000
+ readonly id: Schema.String;
1001
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1002
+ readonly changed: Schema.$Array<Schema.String>;
1003
+ }>, Schema.Struct<{
1004
+ readonly _tag: Schema.Literal<"EntityDeleted">;
1005
+ readonly cursor: Schema.Number;
1006
+ readonly entity: Schema.String;
1007
+ readonly id: Schema.String;
1008
+ }>, Schema.Struct<{
1009
+ readonly _tag: Schema.Literal<"ConnectionInsert">;
1010
+ readonly cursor: Schema.Number;
1011
+ readonly connection: Schema.String;
1012
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
1013
+ readonly edge: Schema.Struct<{
1014
+ readonly entity: Schema.String;
1015
+ readonly id: Schema.String;
1016
+ readonly key: Schema.String;
1017
+ }>;
1018
+ }>, Schema.Struct<{
1019
+ readonly _tag: Schema.Literal<"ConnectionRemove">;
1020
+ readonly cursor: Schema.Number;
1021
+ readonly connection: Schema.String;
1022
+ readonly edge: Schema.Struct<{
1023
+ readonly entity: Schema.String;
1024
+ readonly id: Schema.String;
1025
+ readonly key: Schema.String;
1026
+ }>;
1027
+ }>, Schema.Struct<{
1028
+ readonly _tag: Schema.Literal<"ConnectionInvalidate">;
1029
+ readonly cursor: Schema.Number;
1030
+ readonly connection: Schema.String;
1031
+ }>]>;
1032
+ declare const Read: Rpc.Rpc<"FoldkitRemoteRead", Schema.Struct<{
1033
+ readonly version: Schema.Number;
1034
+ readonly requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1035
+ }>, Schema.Struct<{
1036
+ readonly entities: Schema.$Array<Schema.Struct<{
1037
+ readonly entity: Schema.String;
1038
+ readonly id: Schema.String;
1039
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1040
+ }>>;
1041
+ readonly settled: Schema.$Array<Schema.Struct<{
1042
+ readonly entity: Schema.String;
1043
+ readonly id: Schema.String;
1044
+ readonly fields: Schema.$Array<Schema.String>;
1045
+ }>>;
1046
+ }>, Schema.Union<readonly [typeof RemoteReadError, typeof RemoteProtocolError]>, never, never>;
1047
+ declare const Mutate: Rpc.Rpc<"FoldkitRemoteMutate", Schema.Struct<{
1048
+ /** Stable across transport retries so a mutation is not applied twice. */
1049
+ readonly requestId: Schema.String;
1050
+ readonly mutation: Schema.String;
1051
+ readonly input: Schema.Unknown;
1052
+ }>, Schema.Struct<{
1053
+ readonly output: Schema.Unknown;
1054
+ readonly entities: Schema.$Array<Schema.Struct<{
1055
+ readonly entity: Schema.String;
1056
+ readonly id: Schema.String;
1057
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1058
+ }>>;
1059
+ /** Connection changes the mutation made, applied alongside its entity patches. */
1060
+ readonly connections: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
1061
+ readonly _tag: Schema.Literal<"Insert">;
1062
+ readonly connection: Schema.String;
1063
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
1064
+ readonly edge: Schema.Struct<{
1065
+ readonly entity: Schema.String;
1066
+ readonly id: Schema.String;
1067
+ readonly key: Schema.String;
1068
+ }>;
1069
+ }>, Schema.Struct<{
1070
+ readonly _tag: Schema.Literal<"Remove">;
1071
+ readonly connection: Schema.String;
1072
+ readonly edge: Schema.Struct<{
1073
+ readonly entity: Schema.String;
1074
+ readonly id: Schema.String;
1075
+ readonly key: Schema.String;
1076
+ }>;
1077
+ }>]>>>;
1078
+ /** Entities the mutation deleted; the client knows them absent from then on. */
1079
+ readonly deleted: Schema.optional<Schema.$Array<Schema.Struct<{
1080
+ readonly entity: Schema.String;
1081
+ readonly id: Schema.String;
1082
+ }>>>;
1083
+ }>, typeof RemoteMutationError, never, never>;
1084
+ declare const Live: Rpc.Rpc<"FoldkitRemoteLive", Schema.Struct<{
1085
+ readonly version: Schema.Number;
1086
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1087
+ /** Resume cursor; events at or before it are duplicates. */
1088
+ readonly after: Schema.Number;
1089
+ }>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Struct<{
1090
+ readonly _tag: Schema.Literal<"EntityPatched">;
1091
+ readonly cursor: Schema.Number;
1092
+ readonly entity: Schema.String;
1093
+ readonly id: Schema.String;
1094
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1095
+ readonly changed: Schema.$Array<Schema.String>;
1096
+ }>, Schema.Struct<{
1097
+ readonly _tag: Schema.Literal<"EntityDeleted">;
1098
+ readonly cursor: Schema.Number;
1099
+ readonly entity: Schema.String;
1100
+ readonly id: Schema.String;
1101
+ }>, Schema.Struct<{
1102
+ readonly _tag: Schema.Literal<"ConnectionInsert">;
1103
+ readonly cursor: Schema.Number;
1104
+ readonly connection: Schema.String;
1105
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
1106
+ readonly edge: Schema.Struct<{
1107
+ readonly entity: Schema.String;
1108
+ readonly id: Schema.String;
1109
+ readonly key: Schema.String;
1110
+ }>;
1111
+ }>, Schema.Struct<{
1112
+ readonly _tag: Schema.Literal<"ConnectionRemove">;
1113
+ readonly cursor: Schema.Number;
1114
+ readonly connection: Schema.String;
1115
+ readonly edge: Schema.Struct<{
1116
+ readonly entity: Schema.String;
1117
+ readonly id: Schema.String;
1118
+ readonly key: Schema.String;
1119
+ }>;
1120
+ }>, Schema.Struct<{
1121
+ readonly _tag: Schema.Literal<"ConnectionInvalidate">;
1122
+ readonly cursor: Schema.Number;
1123
+ readonly connection: Schema.String;
1124
+ }>]>, Schema.Union<readonly [typeof RemoteLiveError, typeof RemoteProtocolError]>>, Schema.Never, never, never>;
1125
+ declare const RemoteQueryError_base: Schema.Class<RemoteQueryError, Schema.TaggedStruct<"RemoteQueryError", {
1126
+ readonly message: Schema.String;
1127
+ }>, import("effect/Cause").YieldableError>;
1128
+ declare class RemoteQueryError extends RemoteQueryError_base {}
1129
+ declare const WireBoundary: Schema.Union<readonly [Schema.Struct<{
1130
+ readonly _tag: Schema.Literal<"Terminal">;
1131
+ }>, Schema.Struct<{
1132
+ readonly _tag: Schema.Literal<"Cursor">;
1133
+ readonly cursor: Schema.String;
1134
+ }>, Schema.Struct<{
1135
+ readonly _tag: Schema.Literal<"Unknown">;
1136
+ }>]>;
1137
+ declare const QueryRequest: Schema.Struct<{
1138
+ readonly query: Schema.String;
1139
+ readonly input: Schema.Unknown;
1140
+ readonly window: Schema.Struct<{
1141
+ readonly first: Schema.optional<Schema.Number>;
1142
+ readonly last: Schema.optional<Schema.Number>;
1143
+ readonly after: Schema.optional<Schema.String>;
1144
+ readonly before: Schema.optional<Schema.String>;
1145
+ }>;
1146
+ /**
1147
+ * What to read of each item, as the relation slice a read asks the server
1148
+ * for. Absent for a query run without one: the response carries only edges,
1149
+ * and the client's read entry fetches fields in a second round trip.
1150
+ */
1151
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1152
+ }>;
1153
+ declare const QueryEdge: Schema.Struct<{
1154
+ readonly entity: Schema.String;
1155
+ readonly id: Schema.String;
1156
+ readonly key: Schema.String;
1157
+ }>;
1158
+ declare const QueryResult: Schema.Struct<{
1159
+ readonly edges: Schema.$Array<Schema.Struct<{
1160
+ readonly entity: Schema.String;
1161
+ readonly id: Schema.String;
1162
+ readonly key: Schema.String;
1163
+ }>>;
1164
+ readonly start: Schema.Union<readonly [Schema.Struct<{
1165
+ readonly _tag: Schema.Literal<"Terminal">;
1166
+ }>, Schema.Struct<{
1167
+ readonly _tag: Schema.Literal<"Cursor">;
1168
+ readonly cursor: Schema.String;
1169
+ }>, Schema.Struct<{
1170
+ readonly _tag: Schema.Literal<"Unknown">;
1171
+ }>]>;
1172
+ readonly end: Schema.Union<readonly [Schema.Struct<{
1173
+ readonly _tag: Schema.Literal<"Terminal">;
1174
+ }>, Schema.Struct<{
1175
+ readonly _tag: Schema.Literal<"Cursor">;
1176
+ readonly cursor: Schema.String;
1177
+ }>, Schema.Struct<{
1178
+ readonly _tag: Schema.Literal<"Unknown">;
1179
+ }>]>;
1180
+ /**
1181
+ * The selected fields of the page's items, in the same shape a read batch
1182
+ * returns. Absent from a server that predates payload planning: the client
1183
+ * reads it as empty and fetches fields as before.
1184
+ */
1185
+ readonly entities: Schema.optional<Schema.$Array<Schema.Struct<{
1186
+ readonly entity: Schema.String;
1187
+ readonly id: Schema.String;
1188
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1189
+ }>>>;
1190
+ readonly settled: Schema.optional<Schema.$Array<Schema.Struct<{
1191
+ readonly entity: Schema.String;
1192
+ readonly id: Schema.String;
1193
+ readonly fields: Schema.$Array<Schema.String>;
1194
+ }>>>;
1195
+ }>;
1196
+ declare const QueryRpc: Rpc.Rpc<"FoldkitRemoteQuery", Schema.Struct<{
1197
+ readonly query: Schema.String;
1198
+ readonly input: Schema.Unknown;
1199
+ readonly window: Schema.Struct<{
1200
+ readonly first: Schema.optional<Schema.Number>;
1201
+ readonly last: Schema.optional<Schema.Number>;
1202
+ readonly after: Schema.optional<Schema.String>;
1203
+ readonly before: Schema.optional<Schema.String>;
1204
+ }>;
1205
+ /**
1206
+ * What to read of each item, as the relation slice a read asks the server
1207
+ * for. Absent for a query run without one: the response carries only edges,
1208
+ * and the client's read entry fetches fields in a second round trip.
1209
+ */
1210
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1211
+ }>, Schema.Struct<{
1212
+ readonly edges: Schema.$Array<Schema.Struct<{
1213
+ readonly entity: Schema.String;
1214
+ readonly id: Schema.String;
1215
+ readonly key: Schema.String;
1216
+ }>>;
1217
+ readonly start: Schema.Union<readonly [Schema.Struct<{
1218
+ readonly _tag: Schema.Literal<"Terminal">;
1219
+ }>, Schema.Struct<{
1220
+ readonly _tag: Schema.Literal<"Cursor">;
1221
+ readonly cursor: Schema.String;
1222
+ }>, Schema.Struct<{
1223
+ readonly _tag: Schema.Literal<"Unknown">;
1224
+ }>]>;
1225
+ readonly end: Schema.Union<readonly [Schema.Struct<{
1226
+ readonly _tag: Schema.Literal<"Terminal">;
1227
+ }>, Schema.Struct<{
1228
+ readonly _tag: Schema.Literal<"Cursor">;
1229
+ readonly cursor: Schema.String;
1230
+ }>, Schema.Struct<{
1231
+ readonly _tag: Schema.Literal<"Unknown">;
1232
+ }>]>;
1233
+ /**
1234
+ * The selected fields of the page's items, in the same shape a read batch
1235
+ * returns. Absent from a server that predates payload planning: the client
1236
+ * reads it as empty and fetches fields as before.
1237
+ */
1238
+ readonly entities: Schema.optional<Schema.$Array<Schema.Struct<{
1239
+ readonly entity: Schema.String;
1240
+ readonly id: Schema.String;
1241
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1242
+ }>>>;
1243
+ readonly settled: Schema.optional<Schema.$Array<Schema.Struct<{
1244
+ readonly entity: Schema.String;
1245
+ readonly id: Schema.String;
1246
+ readonly fields: Schema.$Array<Schema.String>;
1247
+ }>>>;
1248
+ }>, typeof RemoteQueryError, never, never>;
1249
+ declare const RemoteRpc: RpcGroup.RpcGroup<Rpc.Rpc<"FoldkitRemoteRead", Schema.Struct<{
1250
+ readonly version: Schema.Number;
1251
+ readonly requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1252
+ }>, Schema.Struct<{
1253
+ readonly entities: Schema.$Array<Schema.Struct<{
1254
+ readonly entity: Schema.String;
1255
+ readonly id: Schema.String;
1256
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1257
+ }>>;
1258
+ readonly settled: Schema.$Array<Schema.Struct<{
1259
+ readonly entity: Schema.String;
1260
+ readonly id: Schema.String;
1261
+ readonly fields: Schema.$Array<Schema.String>;
1262
+ }>>;
1263
+ }>, Schema.Union<readonly [typeof RemoteReadError, typeof RemoteProtocolError]>, never, never> | Rpc.Rpc<"FoldkitRemoteMutate", Schema.Struct<{
1264
+ /** Stable across transport retries so a mutation is not applied twice. */
1265
+ readonly requestId: Schema.String;
1266
+ readonly mutation: Schema.String;
1267
+ readonly input: Schema.Unknown;
1268
+ }>, Schema.Struct<{
1269
+ readonly output: Schema.Unknown;
1270
+ readonly entities: Schema.$Array<Schema.Struct<{
1271
+ readonly entity: Schema.String;
1272
+ readonly id: Schema.String;
1273
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1274
+ }>>;
1275
+ /** Connection changes the mutation made, applied alongside its entity patches. */
1276
+ readonly connections: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
1277
+ readonly _tag: Schema.Literal<"Insert">;
1278
+ readonly connection: Schema.String;
1279
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
1280
+ readonly edge: Schema.Struct<{
1281
+ readonly entity: Schema.String;
1282
+ readonly id: Schema.String;
1283
+ readonly key: Schema.String;
1284
+ }>;
1285
+ }>, Schema.Struct<{
1286
+ readonly _tag: Schema.Literal<"Remove">;
1287
+ readonly connection: Schema.String;
1288
+ readonly edge: Schema.Struct<{
1289
+ readonly entity: Schema.String;
1290
+ readonly id: Schema.String;
1291
+ readonly key: Schema.String;
1292
+ }>;
1293
+ }>]>>>;
1294
+ /** Entities the mutation deleted; the client knows them absent from then on. */
1295
+ readonly deleted: Schema.optional<Schema.$Array<Schema.Struct<{
1296
+ readonly entity: Schema.String;
1297
+ readonly id: Schema.String;
1298
+ }>>>;
1299
+ }>, typeof RemoteMutationError, never, never> | Rpc.Rpc<"FoldkitRemoteLive", Schema.Struct<{
1300
+ readonly version: Schema.Number;
1301
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1302
+ /** Resume cursor; events at or before it are duplicates. */
1303
+ readonly after: Schema.Number;
1304
+ }>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Struct<{
1305
+ readonly _tag: Schema.Literal<"EntityPatched">;
1306
+ readonly cursor: Schema.Number;
1307
+ readonly entity: Schema.String;
1308
+ readonly id: Schema.String;
1309
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1310
+ readonly changed: Schema.$Array<Schema.String>;
1311
+ }>, Schema.Struct<{
1312
+ readonly _tag: Schema.Literal<"EntityDeleted">;
1313
+ readonly cursor: Schema.Number;
1314
+ readonly entity: Schema.String;
1315
+ readonly id: Schema.String;
1316
+ }>, Schema.Struct<{
1317
+ readonly _tag: Schema.Literal<"ConnectionInsert">;
1318
+ readonly cursor: Schema.Number;
1319
+ readonly connection: Schema.String;
1320
+ readonly position: Schema.Union<readonly [Schema.Literal<"prepend">, Schema.Literal<"append">]>;
1321
+ readonly edge: Schema.Struct<{
1322
+ readonly entity: Schema.String;
1323
+ readonly id: Schema.String;
1324
+ readonly key: Schema.String;
1325
+ }>;
1326
+ }>, Schema.Struct<{
1327
+ readonly _tag: Schema.Literal<"ConnectionRemove">;
1328
+ readonly cursor: Schema.Number;
1329
+ readonly connection: Schema.String;
1330
+ readonly edge: Schema.Struct<{
1331
+ readonly entity: Schema.String;
1332
+ readonly id: Schema.String;
1333
+ readonly key: Schema.String;
1334
+ }>;
1335
+ }>, Schema.Struct<{
1336
+ readonly _tag: Schema.Literal<"ConnectionInvalidate">;
1337
+ readonly cursor: Schema.Number;
1338
+ readonly connection: Schema.String;
1339
+ }>]>, Schema.Union<readonly [typeof RemoteLiveError, typeof RemoteProtocolError]>>, Schema.Never, never, never> | Rpc.Rpc<"FoldkitRemoteQuery", Schema.Struct<{
1340
+ readonly query: Schema.String;
1341
+ readonly input: Schema.Unknown;
1342
+ readonly window: Schema.Struct<{
1343
+ readonly first: Schema.optional<Schema.Number>;
1344
+ readonly last: Schema.optional<Schema.Number>;
1345
+ readonly after: Schema.optional<Schema.String>;
1346
+ readonly before: Schema.optional<Schema.String>;
1347
+ }>;
1348
+ /**
1349
+ * What to read of each item, as the relation slice a read asks the server
1350
+ * for. Absent for a query run without one: the response carries only edges,
1351
+ * and the client's read entry fetches fields in a second round trip.
1352
+ */
1353
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1354
+ }>, Schema.Struct<{
1355
+ readonly edges: Schema.$Array<Schema.Struct<{
1356
+ readonly entity: Schema.String;
1357
+ readonly id: Schema.String;
1358
+ readonly key: Schema.String;
1359
+ }>>;
1360
+ readonly start: Schema.Union<readonly [Schema.Struct<{
1361
+ readonly _tag: Schema.Literal<"Terminal">;
1362
+ }>, Schema.Struct<{
1363
+ readonly _tag: Schema.Literal<"Cursor">;
1364
+ readonly cursor: Schema.String;
1365
+ }>, Schema.Struct<{
1366
+ readonly _tag: Schema.Literal<"Unknown">;
1367
+ }>]>;
1368
+ readonly end: Schema.Union<readonly [Schema.Struct<{
1369
+ readonly _tag: Schema.Literal<"Terminal">;
1370
+ }>, Schema.Struct<{
1371
+ readonly _tag: Schema.Literal<"Cursor">;
1372
+ readonly cursor: Schema.String;
1373
+ }>, Schema.Struct<{
1374
+ readonly _tag: Schema.Literal<"Unknown">;
1375
+ }>]>;
1376
+ /**
1377
+ * The selected fields of the page's items, in the same shape a read batch
1378
+ * returns. Absent from a server that predates payload planning: the client
1379
+ * reads it as empty and fetches fields as before.
1380
+ */
1381
+ readonly entities: Schema.optional<Schema.$Array<Schema.Struct<{
1382
+ readonly entity: Schema.String;
1383
+ readonly id: Schema.String;
1384
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1385
+ }>>>;
1386
+ readonly settled: Schema.optional<Schema.$Array<Schema.Struct<{
1387
+ readonly entity: Schema.String;
1388
+ readonly id: Schema.String;
1389
+ readonly fields: Schema.$Array<Schema.String>;
1390
+ }>>>;
1391
+ }>, typeof RemoteQueryError, never, never>>;
1392
+ //#endregion
1393
+ //#region src/model.d.ts
1394
+ /**
1395
+ * The normalized cache as a Foldkit Submodel. `Remote.define` returns a schema
1396
+ * and an `update` for this shape; `updateRemote` reconciles every producer.
1397
+ */
1398
+ interface RemoteModel {
1399
+ /** Entity values, presence, staleness, tombstones, and applied windows. */
1400
+ readonly entities: EntityStore;
1401
+ /** Normalized ordered connections, keyed by connection identity. */
1402
+ readonly connections: Readonly<Record<string, Connection>>;
1403
+ /**
1404
+ * How many rows `Data.more` has grown a read's window to, by
1405
+ * `windowGrowthKey`. A read shows at most its window, so this is what "load
1406
+ * more" changes; it lives here because a list holds no state of its own.
1407
+ */
1408
+ readonly grown: Readonly<Record<string, number>>;
1409
+ /** Optimistic entity layers and connection overlays over the base store. */
1410
+ readonly optimistic: OptimisticState;
1411
+ /** Live cursor and boundary state, keyed by the subscription's stream key. */
1412
+ readonly live: Readonly<Record<string, LiveState>>;
1413
+ /** Mutation pending/applied/failed ledger. */
1414
+ readonly mutations: MutationState;
1415
+ /** Streams whose live cursor fell behind; the caller should resync or refetch. */
1416
+ readonly gaps: ReadonlySet<string>;
1417
+ /**
1418
+ * The `entity\0id\0field` marks a read is currently fetching. A field absent
1419
+ * from the store reads as `Loading` while its mark is here and `Initial`
1420
+ * otherwise, which is what separates "being fetched" from "nothing is
1421
+ * fetching this".
1422
+ */
1423
+ readonly loading: ReadonlySet<string>;
1424
+ /**
1425
+ * `Remote.refresh` generations, held per field rather than for the store as a
1426
+ * whole. A read entry restarts when the generation over the fields it plans
1427
+ * moves, so a read sent before a refresh of its own fields cannot land after
1428
+ * it, and a refresh of one field leaves every other entry's read alone.
1429
+ */
1430
+ readonly refresh: RefreshState;
1431
+ /**
1432
+ * The reads that failed and have not been settled since, so a read can say
1433
+ * `Failed` rather than `Initial`.
1434
+ *
1435
+ * Without them a read that failed before anything loaded read exactly like
1436
+ * one nobody had asked for, and nothing asked again: a read entry restarts
1437
+ * only when what it plans changes, and a failure changed nothing. What failed
1438
+ * is not planned again on its own either, so a persistent error is not
1439
+ * retried every time an unrelated read restarts the entry. `Remote.refresh`
1440
+ * is how a view retries.
1441
+ */
1442
+ readonly failures: Failures;
1443
+ }
1444
+ /**
1445
+ * Failed reads, as the errors they failed with.
1446
+ *
1447
+ * `connections` is by connection identity, and is settled by a page arriving,
1448
+ * an invalidation, or retention dropping the connection. `fields` is by field
1449
+ * mark (`entity\0id\0field`, the marks `loading` uses), and is settled by the
1450
+ * field being written again, a refresh asking for it, or retention dropping the
1451
+ * entity. A read of it in flight reads `Loading` over the failure without
1452
+ * settling it: if that read fails too, the failure is simply recorded again.
1453
+ */
1454
+ interface Failures {
1455
+ readonly connections: Readonly<Record<string, RemoteError>>;
1456
+ readonly fields: Readonly<Record<string, RemoteError>>;
1457
+ }
1458
+ declare const noFailures: Failures;
1459
+ /**
1460
+ * `Remote.refresh` generations, per field mark. `generation` is the last one
1461
+ * handed out; `requested` is when each field was last refreshed, and `started`
1462
+ * is the generation each field's read last began under. Holding them per field
1463
+ * is what keeps one Projection's refresh from restarting every read entry.
1464
+ */
1465
+ interface RefreshState {
1466
+ readonly generation: number;
1467
+ readonly requested: ReadonlyMap<string, number>;
1468
+ readonly started: ReadonlyMap<string, number>;
1469
+ /**
1470
+ * The generation every entry is refreshed at, at least: `forgetRemote` moves
1471
+ * it, so every read and live entry restarts, and a read or stream begun for
1472
+ * the principal before is interrupted rather than landing after.
1473
+ */
1474
+ readonly floor: number;
1475
+ }
1476
+ declare const emptyRefresh: RefreshState;
1477
+ /**
1478
+ * The Model with everything the server told it forgotten: values, tombstones,
1479
+ * unavailable fields, connections, live cursors, failures, and what is in
1480
+ * flight. For a change of principal, whose facts these were. The mutation
1481
+ * sequence is kept, so request ids stay unique, and a mutation in flight is
1482
+ * treated as applied: its answer, when it comes, writes nothing here.
1483
+ */
1484
+ declare const forgetRemote: (model: RemoteModel) => RemoteModel;
1485
+ declare const initialRemoteModel: RemoteModel;
1486
+ declare const remoteModelSchema: () => Schema.Codec<RemoteModel, unknown>;
1487
+ /** The submodel's Messages; each reduces to `RemoteModel` through `updateRemote`. */
1488
+ type RemoteMessage = {
1489
+ readonly _tag: 'ReadReceived';
1490
+ readonly requests: readonly Requirement[];
1491
+ readonly result: Schema.Schema.Type<typeof ReadBatchResult>;
1492
+ readonly now: number;
1493
+ } | {
1494
+ readonly _tag: 'ReadFailed';
1495
+ readonly requests: readonly Requirement[];
1496
+ readonly error: RemoteError;
1497
+ /**
1498
+ * The live stream whose subscription broke, when this is that rather
1499
+ * than a read. Nothing was being read, so no field failed: the stream is
1500
+ * recorded as a gap, since changes after it are missed until the host
1501
+ * resubscribes.
1502
+ */
1503
+ readonly stream?: string | undefined;
1504
+ } |
1505
+ /** A refetch of present fields began; they read as `Refreshing` until it lands. */
1506
+ {
1507
+ readonly _tag: 'RefreshStarted';
1508
+ readonly requests: readonly Requirement[];
1509
+ } |
1510
+ /** A read began; the fields it asks for that the store lacks read as `Loading`. */
1511
+ {
1512
+ readonly _tag: 'ReadStarted';
1513
+ readonly requests: readonly Requirement[];
1514
+ /** The refresh generation the read was planned under. */
1515
+ readonly refresh?: number | undefined;
1516
+ } |
1517
+ /**
1518
+ * Queries for these connections were sent. One with nothing to show reads
1519
+ * `Loading` until its page or its failure arrives, which is what separates
1520
+ * "being fetched" from `Initial`, "nothing is fetching this".
1521
+ */
1522
+ {
1523
+ readonly _tag: 'QueryStarted';
1524
+ readonly connections: readonly string[];
1525
+ } |
1526
+ /** The active Surfaces' roots changed; everything they do not reach is collected. */
1527
+ {
1528
+ readonly _tag: 'RetentionChanged';
1529
+ readonly roots: RetentionRoots;
1530
+ } |
1531
+ /** A restored snapshot meets the store; runtime state is untouched. */
1532
+ {
1533
+ readonly _tag: 'Hydrated';
1534
+ readonly entities: EntityStore;
1535
+ /**
1536
+ * The connections a snapshot declared should survive, as their edges.
1537
+ * Restored with **unknown** boundaries and marked stale: the rows show
1538
+ * at once and the connection is refetched, because a persisted cursor
1539
+ * may name server state that is gone.
1540
+ */
1541
+ readonly connections?: Readonly<Record<string, ReadonlyArray<ReadonlyArray<Edge>>>> | undefined;
1542
+ readonly merge: MergePolicy;
1543
+ } |
1544
+ /** A mutation began; its optimistic operations show until it settles. */
1545
+ {
1546
+ readonly _tag: 'MutationStarted';
1547
+ readonly requestId: string;
1548
+ readonly optimistic?: ReadonlyArray<OptimisticOperation> | undefined;
1549
+ } | {
1550
+ readonly _tag: 'MutationSucceeded';
1551
+ readonly requestId: string;
1552
+ readonly entities: readonly NormalizedPatch[];
1553
+ /** Connection changes the server confirmed; they replace the request's own. */
1554
+ readonly connections?: ReadonlyArray<ConnectionChange> | undefined;
1555
+ /** Entities the mutation deleted: tombstoned, which hides them from every connection. */
1556
+ readonly deleted?: ReadonlyArray<{
1557
+ readonly entity: string;
1558
+ readonly id: string;
1559
+ }> | undefined;
1560
+ /** Injected clock reading of the answer: how fresh the written entities are. */
1561
+ readonly now: number;
1562
+ } | {
1563
+ readonly _tag: 'MutationFailed';
1564
+ readonly requestId: string;
1565
+ readonly error: RemoteError;
1566
+ } |
1567
+ /**
1568
+ * Operations shown over the store with no request behind them, until they are
1569
+ * lifted: a preview of a change nobody has made. Showing an id again replaces
1570
+ * what it showed.
1571
+ */
1572
+ {
1573
+ readonly _tag: 'OverlayShown';
1574
+ readonly id: string;
1575
+ readonly optimistic: ReadonlyArray<OptimisticOperation>;
1576
+ } | {
1577
+ readonly _tag: 'OverlayLifted';
1578
+ readonly id: string;
1579
+ } |
1580
+ /** `Data.more`: a read's window, by `windowGrowthKey`, now shows `size` rows. */
1581
+ {
1582
+ readonly _tag: 'WindowGrown';
1583
+ readonly window: string;
1584
+ readonly size: number;
1585
+ } | {
1586
+ readonly _tag: 'LiveReceived';
1587
+ readonly stream: string;
1588
+ readonly event: LiveEvent;
1589
+ readonly policy?: LivePolicy;
1590
+ readonly now: number;
1591
+ } | {
1592
+ readonly _tag: 'GapCleared';
1593
+ readonly stream: string;
1594
+ } | {
1595
+ readonly _tag: 'ConnectionMerged';
1596
+ readonly connection: string;
1597
+ readonly page: Segment;
1598
+ /** The page answers the connection's refresh, so the merge also clears `stale`. */
1599
+ readonly refreshes?: boolean | undefined;
1600
+ /**
1601
+ * The slice the query asked for, so the payload's entities write like a
1602
+ * read: one request per matching edge. Absent for a page from a server
1603
+ * that predates payload planning, which carries edges only.
1604
+ */
1605
+ readonly select?: RelationRequirement | undefined;
1606
+ /** The selected fields of the page's items, as a read batch returns them. */
1607
+ readonly entities?: ReadonlyArray<{
1608
+ readonly entity: string;
1609
+ readonly id: string;
1610
+ readonly values: Record<string, unknown>;
1611
+ }> | undefined;
1612
+ /** Fields asked for that the server settled without a value. */
1613
+ readonly settled?: ReadonlyArray<{
1614
+ readonly entity: string;
1615
+ readonly id: string;
1616
+ readonly fields: ReadonlyArray<string>;
1617
+ }> | undefined;
1618
+ /** Injected clock reading of the answer, dating what the payload writes. */
1619
+ readonly now?: number | undefined;
1620
+ } | {
1621
+ readonly _tag: 'ConnectionInvalidated';
1622
+ readonly connection: string;
1623
+ } | {
1624
+ readonly _tag: 'ConnectionRefreshed';
1625
+ readonly connection: string;
1626
+ } |
1627
+ /**
1628
+ * A query for the connection failed. Its pages stay as they were, and it
1629
+ * reads `Failed` — with them as `previous`, when it has any — until a page
1630
+ * arrives, it is invalidated, or retention drops it.
1631
+ */
1632
+ {
1633
+ readonly _tag: 'QueryFailed';
1634
+ readonly connection: string;
1635
+ readonly error: RemoteError;
1636
+ };
1637
+ declare const retentionRootsSchema: Schema.Struct<{
1638
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1639
+ readonly connections: Schema.$Array<Schema.Struct<{
1640
+ readonly identity: Schema.String;
1641
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1642
+ }>>;
1643
+ }>;
1644
+ /**
1645
+ * The Messages' fields by tag, without `_tag`: what `defineMessageUnion` takes,
1646
+ * so an application spreads them into its own union (`Remote.messages`).
1647
+ */
1648
+ declare const remoteMessageCases: {
1649
+ ReadReceived: {
1650
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1651
+ result: Schema.Struct<{
1652
+ readonly entities: Schema.$Array<Schema.Struct<{
1653
+ readonly entity: Schema.String;
1654
+ readonly id: Schema.String;
1655
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1656
+ }>>;
1657
+ readonly settled: Schema.$Array<Schema.Struct<{
1658
+ readonly entity: Schema.String;
1659
+ readonly id: Schema.String;
1660
+ readonly fields: Schema.$Array<Schema.String>;
1661
+ }>>;
1662
+ }>;
1663
+ now: Schema.Number;
1664
+ };
1665
+ ReadFailed: {
1666
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1667
+ error: Schema.Struct<{
1668
+ readonly _tag: Schema.String;
1669
+ readonly message: Schema.String;
1670
+ }>;
1671
+ stream: Schema.optional<Schema.String>;
1672
+ };
1673
+ RefreshStarted: {
1674
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1675
+ };
1676
+ ReadStarted: {
1677
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1678
+ refresh: Schema.optional<Schema.Number>;
1679
+ };
1680
+ QueryStarted: {
1681
+ connections: Schema.$Array<Schema.String>;
1682
+ };
1683
+ RetentionChanged: {
1684
+ roots: Schema.Struct<{
1685
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
1686
+ readonly connections: Schema.$Array<Schema.Struct<{
1687
+ readonly identity: Schema.String;
1688
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1689
+ }>>;
1690
+ }>;
1691
+ };
1692
+ Hydrated: {
1693
+ connections: Schema.optional<Schema.Unknown>;
1694
+ entities: Schema.Unknown;
1695
+ merge: Schema.Union<readonly [Schema.Literal<"replace">, Schema.Literal<"preserve-existing">]>;
1696
+ };
1697
+ MutationStarted: {
1698
+ requestId: Schema.String;
1699
+ optimistic: Schema.optional<Schema.$Array<Schema.Unknown>>;
1700
+ };
1701
+ MutationSucceeded: {
1702
+ requestId: Schema.String;
1703
+ entities: Schema.$Array<Schema.Struct<{
1704
+ readonly entity: Schema.String;
1705
+ readonly id: Schema.String;
1706
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1707
+ }>>;
1708
+ connections: Schema.optional<Schema.$Array<Schema.Unknown>>;
1709
+ deleted: Schema.optional<Schema.$Array<Schema.Struct<{
1710
+ readonly entity: Schema.String;
1711
+ readonly id: Schema.String;
1712
+ }>>>;
1713
+ now: Schema.Number;
1714
+ };
1715
+ MutationFailed: {
1716
+ requestId: Schema.String;
1717
+ error: Schema.Struct<{
1718
+ readonly _tag: Schema.String;
1719
+ readonly message: Schema.String;
1720
+ }>;
1721
+ };
1722
+ OverlayShown: {
1723
+ id: Schema.String;
1724
+ optimistic: Schema.$Array<Schema.Unknown>;
1725
+ };
1726
+ OverlayLifted: {
1727
+ id: Schema.String;
1728
+ };
1729
+ WindowGrown: {
1730
+ window: Schema.String;
1731
+ size: Schema.Number;
1732
+ };
1733
+ LiveReceived: {
1734
+ stream: Schema.String;
1735
+ event: Schema.Unknown;
1736
+ policy: Schema.optional<Schema.Unknown>;
1737
+ now: Schema.Number;
1738
+ };
1739
+ GapCleared: {
1740
+ stream: Schema.String;
1741
+ };
1742
+ ConnectionMerged: {
1743
+ connection: Schema.String;
1744
+ page: Schema.Unknown;
1745
+ refreshes: Schema.optional<Schema.Boolean>;
1746
+ select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
1747
+ entities: Schema.optional<Schema.$Array<Schema.Struct<{
1748
+ readonly entity: Schema.String;
1749
+ readonly id: Schema.String;
1750
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
1751
+ }>>>;
1752
+ settled: Schema.optional<Schema.$Array<Schema.Struct<{
1753
+ readonly entity: Schema.String;
1754
+ readonly id: Schema.String;
1755
+ readonly fields: Schema.$Array<Schema.String>;
1756
+ }>>>;
1757
+ now: Schema.optional<Schema.Number>;
1758
+ };
1759
+ ConnectionInvalidated: {
1760
+ connection: Schema.String;
1761
+ };
1762
+ ConnectionRefreshed: {
1763
+ connection: Schema.String;
1764
+ };
1765
+ QueryFailed: {
1766
+ connection: Schema.String;
1767
+ error: Schema.Struct<{
1768
+ readonly _tag: Schema.String;
1769
+ readonly message: Schema.String;
1770
+ }>;
1771
+ };
1772
+ };
1773
+ type RemoteMessageTag = RemoteMessage['_tag'];
1774
+ /**
1775
+ * A Remote Message as an application's union constructs it from
1776
+ * `remoteMessageCases`: the same shape `RemoteMessage` names, with the runtime
1777
+ * slots (`entities`, `event`, `page`) typed `unknown` by their schemas.
1778
+ */
1779
+ type RemoteMessageInput = { [Tag in RemoteMessageTag]: {
1780
+ readonly _tag: Tag;
1781
+ } & Schema.Struct.Type<(typeof remoteMessageCases)[Tag]>; }[RemoteMessageTag];
1782
+ /**
1783
+ * Whether a Message is one of Remote's, by tag. Narrows an application's union
1784
+ * to its Remote cases, and its complement to the application's own.
1785
+ */
1786
+ declare const isRemoteMessage: <M extends {
1787
+ readonly _tag: string;
1788
+ }>(message: M) => message is Extract<M, {
1789
+ readonly _tag: RemoteMessageTag;
1790
+ }>;
1791
+ declare const remoteMessageSchema: Schema.Schema<RemoteMessage>;
1792
+ /** The key a grown window is kept under: its connection and the window first asked for. */
1793
+ declare const windowGrowthKey: (identity: string, window: string) => string;
1794
+ /**
1795
+ * Whether only overlays show this entity: the server has told the store
1796
+ * nothing of it and no request's layer writes it, so nothing will fetch what an
1797
+ * overlay leaves out.
1798
+ */
1799
+ declare const onlyOverlaid: (model: RemoteModel, entity: string, id: string) => boolean;
1800
+ /** Whether a query for this connection is in flight. */
1801
+ declare const isQueryLoading: (model: RemoteModel, identity: string) => boolean;
1802
+ /**
1803
+ * The generation a read is planned under: the highest any of the fields it
1804
+ * reads or connections it runs was refreshed at. A read entry carries this as a
1805
+ * dependency, so it restarts when what it observes is refreshed and not when
1806
+ * anything else is.
1807
+ */
1808
+ declare const refreshedAt: (refresh: RefreshState, requests: ReadonlyArray<Requirement>, connections?: ReadonlyArray<string>) => number;
1809
+ /**
1810
+ * Marks every field of `requests` and every connection in `connections`
1811
+ * refreshed at the next generation.
1812
+ */
1813
+ declare const withRefreshRequested: (refresh: RefreshState, requests: ReadonlyArray<Requirement>, connections?: ReadonlyArray<string>) => RefreshState;
1814
+ /**
1815
+ * Whether one field's read already began under the generation that field was
1816
+ * last refreshed at. Such a read is in flight and would otherwise outlive the
1817
+ * refresh, so the refresh takes a new generation to restart it even though the
1818
+ * field is already stale.
1819
+ */
1820
+ declare const refreshIsInFlight: (refresh: RefreshState, request: Requirement, field: string) => boolean;
1821
+ /**
1822
+ * Whether a read is fetching any of `fields` for this entity. Consulted only
1823
+ * when the store lacks the value, which is what separates `Loading` from
1824
+ * `Initial`.
1825
+ */
1826
+ declare const isLoading: (model: RemoteModel, entity: string, id: string, fields: ReadonlyArray<string>) => boolean;
1827
+ /**
1828
+ * The pure reducer all four producers share. A live event that arrives ahead of
1829
+ * its cursor is a gap: it is not applied, and the stream is recorded so the host
1830
+ * can resubscribe rather than silently miss facts. When every field a Message
1831
+ * touches keeps its identity, `model` itself is returned, so the application's
1832
+ * root keeps its identity and Foldkit does not render. The common no-ops do (a
1833
+ * duplicate live event, a repeated `ReadStarted`); a repeated failure, or a
1834
+ * `preserve-existing` restore of entities already held, still makes an equal
1835
+ * copy.
1836
+ */
1837
+ declare const updateRemote: (model: RemoteModel, message: RemoteMessage) => RemoteModel;
1838
+ /** Whether this field's last read failed and nothing has settled it since. */
1839
+ declare const isFieldFailed: (model: RemoteModel, entity: string, id: string, field: string) => boolean;
1840
+ /**
1841
+ * Whether a read is fetching any field `relation` reads of an entity, its own
1842
+ * or, through each relation the store holds, its targets'. A value whose owner
1843
+ * is being fetched is loading, not `Initial`: nothing is missing a fetch.
1844
+ */
1845
+ declare const isLoadingThrough: (model: RemoteModel, entity: string, id: string, relation: RelationRequirement) => boolean;
1846
+ /**
1847
+ * The first failure among the fields `relation` reads of an entity, following
1848
+ * each relation the store holds into its targets, as `assemble` does. A read
1849
+ * that consults it shows `Failed` for a related entity's failure too, rather
1850
+ * than waiting on a field nothing will fetch.
1851
+ */
1852
+ declare const failureOf: (model: RemoteModel, entity: string, id: string, relation: RelationRequirement) => RemoteError | undefined;
1853
+ /**
1854
+ * Writes a read result into the store, recording each field's applied window so
1855
+ * a later request with a different window refetches. A relation page requested
1856
+ * with a cursor is merged onto the page already stored, so "load more"
1857
+ * accumulates rather than replaces. Every read path should use this rather than
1858
+ * reducing `writeEntity` by hand.
1859
+ */
1860
+ declare const writeRead: (store: EntityStore, requests: ReadonlyArray<Requirement>, result: Schema.Schema.Type<typeof ReadBatchResult>, now?: number) => EntityStore;
1861
+ //#endregion
1862
+ //#region src/resume.d.ts
1863
+ /**
1864
+ * A resume part, in the shape `foldkit-ssr`'s `SSR.plan` takes in `parts`.
1865
+ * Declared here structurally, so neither package depends on the other.
1866
+ */
1867
+ interface RemoteResumePart<AppModel> {
1868
+ readonly id: string;
1869
+ /** The metadata key names whose reads this part resumes. */
1870
+ readonly covers: ReadonlyArray<string>;
1871
+ readonly capture: (model: AppModel, projections: ReadonlyArray<{
1872
+ readonly metadata: Metadata;
1873
+ }>) => unknown;
1874
+ readonly restore: (model: AppModel, value: unknown) => Result.Result<AppModel, string>;
1875
+ /** Whether a Subscription entry is one of this domain's, which may start late. */
1876
+ readonly deferrable: (key: string, entry: unknown) => boolean;
1877
+ }
1878
+ //#endregion
1879
+ //#region src/coalesce.d.ts
1880
+ type Batch = Schema.Schema.Type<typeof ReadBatch>;
1881
+ type BatchResult = Schema.Schema.Type<typeof ReadBatchResult>;
1882
+ type ReadError = RemoteReadError | RemoteProtocolError;
1883
+ type BatchRead = (batch: Batch) => Effect.Effect<BatchResult, ReadError>;
1884
+ type QueryRequestValue = Schema.Schema.Type<typeof QueryRequest>;
1885
+ type QueryResultValue = Schema.Schema.Type<typeof QueryResult>;
1886
+ type QueryRun = (request: QueryRequestValue) => Effect.Effect<QueryResultValue, RemoteQueryError>;
1887
+ interface CoalesceOptions {
1888
+ /**
1889
+ * How long a batch waits to collect more requirements before it runs.
1890
+ * Requirements issued concurrently coalesce even at the default of no wait.
1891
+ */
1892
+ readonly window?: Duration.Input | undefined;
1893
+ }
1894
+ /** A stable key for a requirement, so an equal requirement in flight is joined. */
1895
+ declare const requirementKey: (requirement: Requirement) => string;
1896
+ /**
1897
+ * Wraps a raw query so that an identical query in flight (same query, input,
1898
+ * and window) is joined rather than run again; distinct queries run
1899
+ * concurrently. A page answers exactly one window, so nothing is batched.
1900
+ */
1901
+ declare const coalesceQueries: (query: QueryRun, options?: CoalesceOptions) => Effect.Effect<QueryRun>;
1902
+ /**
1903
+ * Wraps a raw batch read so that requirements are batched and deduplicated.
1904
+ * Every waiter receives the whole batch result; `Remote.writeRead` is
1905
+ * idempotent, so writing it more than once is harmless.
1906
+ */
1907
+ declare const coalesceReads: (read: BatchRead, options?: CoalesceOptions) => Effect.Effect<BatchRead>;
1908
+ //#endregion
1909
+ //#region src/client.d.ts
1910
+ declare const RemoteClient_base: Context.ServiceClass<RemoteClient, "foldkit-remote/RemoteClient", {
1911
+ readonly read: (batch: Schema.Schema.Type<typeof ReadBatch>) => Effect.Effect<Schema.Schema.Type<typeof ReadBatchResult>, RemoteReadError | RemoteProtocolError>;
1912
+ readonly query: (request: Schema.Schema.Type<typeof QueryRequest>) => Effect.Effect<Schema.Schema.Type<typeof QueryResult>, RemoteQueryError>;
1913
+ readonly mutate: (request: Schema.Schema.Type<typeof MutationRequest>) => Effect.Effect<Schema.Schema.Type<typeof MutationResult>, RemoteMutationError>;
1914
+ readonly live: (request: {
1915
+ readonly requirements: ReadonlyArray<Requirement>;
1916
+ readonly after: LiveCursor;
1917
+ }) => Stream.Stream<LiveEvent, RemoteLiveError | RemoteProtocolError>;
1918
+ }>;
1919
+ /**
1920
+ * The transport boundary. `foldkit-remote` never talks to a transport directly;
1921
+ * it depends on this Effect service, which a later phase wires to Effect RPC.
1922
+ */
1923
+ declare class RemoteClient extends RemoteClient_base {}
1924
+ /**
1925
+ * The methods an Effect RPC client for `RemoteRpc` exposes. `R` is the
1926
+ * environment a handler needs; it defaults to `never`, which is what a real
1927
+ * transport client satisfies. `RemoteServer.handlers` returns this type with its
1928
+ * own `R`, so the two sides cannot drift apart.
1929
+ *
1930
+ * `TransportError` is what the transport itself may fail with on top of the
1931
+ * declared errors: `RpcClientError` for the client `RpcClient.make` builds,
1932
+ * `never` for in-process handlers.
1933
+ */
1934
+ interface RemoteRpcClient<R = never, TransportError = never> {
1935
+ readonly FoldkitRemoteRead: (payload: Schema.Schema.Type<typeof ReadBatch>) => Effect.Effect<Schema.Schema.Type<typeof ReadBatchResult>, RemoteReadError | RemoteProtocolError | TransportError, R>;
1936
+ readonly FoldkitRemoteQuery: (payload: Schema.Schema.Type<typeof QueryRequest>) => Effect.Effect<Schema.Schema.Type<typeof QueryResult>, RemoteQueryError | TransportError, R>;
1937
+ readonly FoldkitRemoteMutate: (payload: Schema.Schema.Type<typeof MutationRequest>) => Effect.Effect<Schema.Schema.Type<typeof MutationResult>, RemoteMutationError | TransportError, R>;
1938
+ readonly FoldkitRemoteLive: (payload: Schema.Schema.Type<typeof LiveRequirement>) => Stream.Stream<Schema.Schema.Type<typeof LiveChange>, RemoteLiveError | RemoteProtocolError | TransportError, R>;
1939
+ }
1940
+ /** Reconstructs the client's `ConnectionChange` from the wire's flattened edge. */
1941
+ declare const connectionChangeOf: (change: Schema.Schema.Type<typeof ConnectionChangeSchema>) => ConnectionChange;
1942
+ /** Reconstructs the client's `LiveEvent` from the wire's flattened `LiveChange`. */
1943
+ declare const liveEventOf: (change: Schema.Schema.Type<typeof LiveChange>) => LiveEvent;
1944
+ declare const remoteError: (error: {
1945
+ readonly _tag: string;
1946
+ readonly message: string;
1947
+ }) => RemoteError;
1948
+ declare const coalescedLayer: <E, R>(layer: Layer.Layer<RemoteClient, E, R>, options?: CoalesceOptions) => Layer.Layer<RemoteClient, E, R>;
1949
+ /**
1950
+ * `Remote.mutate` as a standalone effect, so `Remote.mutateInto` can reuse it
1951
+ * without the object literal referencing itself.
1952
+ */
1953
+ declare const mutateRemote: <Name extends string, Input, Output>(mutation: MutationDescriptor<Name, Input, Output>, input: Input, requestId: string) => Effect.Effect<{
1954
+ output: Output;
1955
+ entities: readonly {
1956
+ readonly entity: string;
1957
+ readonly id: string;
1958
+ readonly values: {
1959
+ readonly [x: string]: unknown;
1960
+ };
1961
+ }[];
1962
+ connections: ConnectionChange[];
1963
+ deleted: readonly {
1964
+ readonly entity: string;
1965
+ readonly id: string;
1966
+ }[];
1967
+ }, RemoteMutationError, RemoteClient>;
1968
+ //#endregion
1969
+ //#region src/json.d.ts
1970
+ /** A request: which of Remote's calls, and its payload as the RPC protocol encodes it. */
1971
+ declare const RemoteJsonRequest: Schema.Struct<{
1972
+ readonly operation: Schema.Literals<readonly ["read", "query", "mutate"]>;
1973
+ readonly payload: Schema.Unknown;
1974
+ }>;
1975
+ type RemoteJsonRequest = typeof RemoteJsonRequest.Type;
1976
+ /** An answer: the call's result, or why there is none. */
1977
+ declare const RemoteJsonAnswer: Schema.Union<readonly [Schema.Struct<{
1978
+ readonly result: Schema.Unknown;
1979
+ }>, Schema.Struct<{
1980
+ readonly error: Schema.String;
1981
+ }>]>;
1982
+ type RemoteJsonAnswer = typeof RemoteJsonAnswer.Type;
1983
+ /**
1984
+ * Sends one request's text and resolves with its answer as parsed JSON. It
1985
+ * rejects when nothing came back, and the call fails with that message.
1986
+ */
1987
+ type RemoteJsonSend = (request: string) => Promise<unknown>;
1988
+ //#endregion
1989
+ //#region src/relation.d.ts
1990
+ interface RefParts {
1991
+ readonly entity: string;
1992
+ readonly id: string;
1993
+ }
1994
+ /** A page of refs as the wire and the store hold it. */
1995
+ interface RefPageValue {
1996
+ readonly refs: ReadonlyArray<string>;
1997
+ readonly hasNext: boolean;
1998
+ readonly hasPrevious: boolean;
1999
+ }
2000
+ /** Marks the codec `Entity.ref`/`Entity.refPage` produce, so a Selection can tell the field's shape. */
2001
+ declare const RelationAnnotation = "foldkitRemoteRelation";
2002
+ /** The target entity's name on the same codec, so a nested selection of another entity is refused. */
2003
+ declare const RelationEntityAnnotation = "foldkitRemoteRelationEntity";
2004
+ type RelationKind = 'one' | 'many' | 'page';
2005
+ interface RelationShape {
2006
+ readonly kind: RelationKind;
2007
+ readonly nullable: boolean;
2008
+ readonly entity: string;
2009
+ }
2010
+ /**
2011
+ * A page of a relation that is a whole list is read under a name of its own, the
2012
+ * field's name and the page's size: `comments@first=10`. It is a field like any
2013
+ * other to the store, the planner, and the wire, so the whole list and a page of
2014
+ * it are held side by side, merged, marked stale, and persisted each on its own.
2015
+ * The server reads the name apart, reads the relation with the window, and
2016
+ * answers under the alias. A cursor is not part of the name: a page read from a
2017
+ * cursor merges onto the page it continues.
2018
+ */
2019
+ declare const RELATION_ALIAS = "@";
2020
+ /** The alias a relation field is read under, for a window of this size. */
2021
+ declare const relationAlias: (field: string, window: {
2022
+ readonly first?: number | undefined;
2023
+ readonly last?: number | undefined;
2024
+ readonly after?: string | undefined;
2025
+ readonly before?: string | undefined;
2026
+ }) => string;
2027
+ /** The field an alias reads; a name that is no alias is its own field. */
2028
+ declare const aliasedField: (name: string) => string;
2029
+ /** Splits a ref key (`"Entity:id"`, the store key too) back into its parts. */
2030
+ declare const refParts: (encoded: string) => RefParts;
2031
+ /**
2032
+ * The refs a relation value carries, in order. Anything that is not a ref key,
2033
+ * an array of them, or a page of them contributes nothing.
2034
+ */
2035
+ declare const refsIn: (value: unknown) => ReadonlyArray<RefParts>;
2036
+ /** The refs in a relation value that name the relation's target entity, and no other. */
2037
+ declare const targetsOf: (value: unknown, relation: RelationRequirement) => ReadonlyArray<RefParts>;
2038
+ declare const isRefPage: (value: unknown) => value is RefPageValue;
2039
+ /**
2040
+ * The relation shape an entity field schema declares: a ref (`one`), a nullable
2041
+ * ref, an array of refs (`many`), or a page of refs (`page`). `undefined` for a
2042
+ * scalar field, which cannot take a nested selection.
2043
+ */
2044
+ declare const relationShape: (schema: Schema.Top) => RelationShape | undefined;
2045
+ //#endregion
2046
+ //#region src/selection.d.ts
2047
+ /** One page of a paginated relation with each target assembled through a nested selection. */
2048
+ interface Page<Item> {
2049
+ readonly items: ReadonlyArray<Item>;
2050
+ readonly hasNext: boolean;
2051
+ readonly hasPrevious: boolean;
2052
+ }
2053
+ /**
2054
+ * The fields a projection reads of one entity, plus the slice it reads of each
2055
+ * relation's target. `Shape` tells a parent selection whether this one is a
2056
+ * paginated relation (`connection`) or a plain entity slice (`entity`).
2057
+ */
2058
+ interface Selection<Value, Name extends string = string, Shape extends 'entity' | 'connection' = 'entity' | 'connection'> {
2059
+ readonly entity: Name;
2060
+ readonly fields: readonly string[];
2061
+ /** A pure codec: entity fields carry no decoding or encoding services. */
2062
+ readonly schema: Schema.Codec<Value, unknown, never, never>;
2063
+ /** Pagination windows for nested relation fields, keyed by field name. */
2064
+ readonly connections?: Readonly<Record<string, QueryWindow>> | undefined;
2065
+ /** The slice required of each nested relation's target, keyed by field name. */
2066
+ readonly relations?: Readonly<Record<string, RelationRequirement>> | undefined;
2067
+ /** Present when this selection is itself a paginated relation. */
2068
+ readonly window?: QueryWindow | undefined;
2069
+ /** Phantom: see `Shape`. */
2070
+ readonly shape?: Shape | undefined;
2071
+ }
2072
+ /** Flattens a mapped type so hovers show the picked fields, not the machinery. */
2073
+ type Simplify<T> = T extends (infer O) ? { readonly [K in keyof O]: O[K]; } : never;
2074
+ /** The value a Selection reads: `Selection.Value<typeof ProjectCard>`. */
2075
+ type SelectionValueOf<S> = S extends Selection<infer V, any, any> ? V : never;
2076
+ /** The nested selections a relation field admits: of its target entity, in the shapes its value takes. */
2077
+ type NestedFor<Field> = Exclude<Field, null | undefined> extends ReadonlyArray<EntityRef<infer Name, any>> ? Selection<unknown, Name, 'entity' | 'connection'> : Exclude<Field, null | undefined> extends RefPage<infer Name, any> ? Selection<unknown, Name, 'entity' | 'connection'> : Exclude<Field, null | undefined> extends EntityRef<infer Name, any> ? Selection<unknown, Name, 'entity'> : never;
2078
+ /** What a selection of an entity with fields `F` may pick: `true` per scalar, a nested selection per relation. */
2079
+ type SelectionOf<F extends Schema.Struct.Fields> = { readonly [K in keyof F]?: true | NestedFor<Schema.Schema.Type<F[K]>>; };
2080
+ /** `T | null` when the field admits `null` or `undefined` (both assemble to `null`). */
2081
+ type Nullable<Field, T> = [Extract<Field, null | undefined>] extends [never] ? T : T | null;
2082
+ /** A nested selection's value takes the shape of the field it selects through. */
2083
+ type NestedValue<Field, Sel> = Sel extends Selection<infer V, string, 'connection'> ? Nullable<Field, V> : Sel extends Selection<infer V, string, 'entity'> ? Nullable<Field, Exclude<Field, null | undefined> extends ReadonlyArray<EntityRef<any, any>> ? ReadonlyArray<V> : Exclude<Field, null | undefined> extends RefPage<any, any> ? Page<V> : V> : never;
2084
+ /** The value a selection `Sel` of fields `F` reads. */
2085
+ type SelectionValue<F extends Schema.Struct.Fields, Sel> = Simplify<{ readonly [K in keyof Sel & keyof F]: Sel[K] extends true ? Schema.Schema.Type<F[K]> : NestedValue<Schema.Schema.Type<F[K]>, Sel[K]>; }>;
2086
+ declare const pageSchema: (item: AnySchema) => AnySchema;
2087
+ /** The requirement a nested selection contributes for its relation's target. */
2088
+ declare const relationOf: (selection: Selection<unknown>) => RelationRequirement;
2089
+ declare const Selection: {
2090
+ /**
2091
+ * The Remote Selection of a `foldkit-entity` Selection: the same members, read
2092
+ * from Remote's store. `true` on a relation reads its refs, as it does here.
2093
+ */
2094
+ from: <Name extends string, S extends Schema.Constraint>(selection: Domain.Selection<Name, unknown, S>) => Selection<S["Type"], Name, "entity">;
2095
+ /**
2096
+ * The fields to read of `entity`. A nested `Selection` on a relation field
2097
+ * reads through the ref (or refs, or page of refs) the field holds into the
2098
+ * target's fields; a scalar field cannot take one.
2099
+ */
2100
+ make: <Name extends string, F extends Schema.Struct.Fields, const Sel extends SelectionOf<F>>(entity: EntityDescriptor<Name, F>, selection: Sel) => Selection<SelectionValue<F, Sel>, Name, "entity">;
2101
+ /**
2102
+ * A paginated relation: one page of refs to `entity` with a window, or, with
2103
+ * a nested selection, one page of targets assembled through it.
2104
+ */
2105
+ connection: {
2106
+ <Name extends string, F extends Schema.Struct.Fields>(entity: EntityDescriptor<Name, F>, window: QueryWindow): Selection<RefPage<Name, F>, Name, "connection">;
2107
+ <Name extends string, F extends Schema.Struct.Fields, Item>(entity: EntityDescriptor<Name, F>, window: QueryWindow, selection: Selection<Item, NoInfer<Name>, "entity">): Selection<Page<Item>, Name, "connection">;
2108
+ };
2109
+ };
2110
+ interface Assembled {
2111
+ readonly values: unknown;
2112
+ readonly refreshing: boolean;
2113
+ }
2114
+ /**
2115
+ * Reads an entity's selected fields out of the store, following each nested
2116
+ * relation into its targets. `undefined` means some field, at any depth, is
2117
+ * not present yet. A tombstoned target reads as `null` (or is dropped from a
2118
+ * list), so the Selection's codec decides whether that is a failure.
2119
+ */
2120
+ declare const assemble: (store: EntityStore, key: string, requirement: RelationRequirement) => Assembled | undefined;
2121
+ /**
2122
+ * The first field `requirement` reads, at any depth, that the server settled
2123
+ * without a value, as `Entity:id.field`. A read that consults it says why it
2124
+ * cannot assemble rather than waiting on a field nothing will fetch.
2125
+ */
2126
+ declare const unavailableOf: (store: EntityStore, key: string, requirement: RelationRequirement) => string | undefined;
2127
+ //#endregion
2128
+ //#region src/entity.d.ts
2129
+ type AnySchema = Schema.Schema<unknown>;
2130
+ declare const entityRefFields: unique symbol;
2131
+ /**
2132
+ * A normalized reference to an entity. `F` is a phantom carrying the entity's
2133
+ * fields so `Entity.patch` can type its patch; it is absent at runtime.
2134
+ */
2135
+ interface EntityRef<Name extends string, F extends Schema.Struct.Fields = Schema.Struct.Fields> {
2136
+ readonly entity: Name;
2137
+ readonly id: string;
2138
+ readonly [entityRefFields]?: F;
2139
+ }
2140
+ interface EntityDescriptor<Name extends string, F extends Schema.Struct.Fields> {
2141
+ readonly name: Name;
2142
+ readonly schema: Schema.Struct<F>;
2143
+ readonly fields: F;
2144
+ ref(id: Schema.Schema.Type<F['id']>): EntityRef<Name, F>;
2145
+ /** The fields a Surface reads of this entity; `Selection.make(entity, …)` with the entity as receiver. */
2146
+ select<const Sel extends SelectionOf<F>>(selection: Sel): Selection<SelectionValue<F, Sel>, Name, 'entity'>;
2147
+ /** A patch of this entity's wire-shaped values; `Entity.patch(entity.ref(id), values)`. */
2148
+ patch(id: Schema.Schema.Type<F['id']>, values: Partial<Schema.Struct.Encoded<F>>): EntityPatch<Name, F>;
2149
+ }
2150
+ /**
2151
+ * Relations are **references**, never inline target schemas: a ref cannot
2152
+ * reconstruct a full entity, and dereferencing is a store concern. Because the
2153
+ * target schema is not inlined, recursive relations cannot arise through the
2154
+ * schema graph.
2155
+ */
2156
+ /**
2157
+ * A ref as the wire carries it: the target's name, a colon, and its id. Typed
2158
+ * with the name, so a relation to `User` takes `'User:u1'` and not a ref to
2159
+ * some other entity, which would read as a row that does not exist.
2160
+ */
2161
+ type RefKey<Name extends string> = `${Name}:${string}`;
2162
+ /**
2163
+ * A patch in wire shape: the values the store holds, so a relation is its ref
2164
+ * key (`Entity.refKey`), not an `EntityRef`.
2165
+ */
2166
+ interface EntityPatch<Name extends string, F extends Schema.Struct.Fields> {
2167
+ readonly entity: Name;
2168
+ readonly id: string;
2169
+ readonly values: Partial<Schema.Struct.Encoded<F>>;
2170
+ }
2171
+ /**
2172
+ * One authoritative page of a paginated relation: refs (never inline entities)
2173
+ * plus whether more exist. The adapter does not hold segmentation state; the
2174
+ * client merges pages.
2175
+ */
2176
+ interface RefPage<Name extends string, F extends Schema.Struct.Fields = Schema.Struct.Fields> {
2177
+ readonly refs: ReadonlyArray<EntityRef<Name, F>>;
2178
+ readonly hasNext: boolean;
2179
+ readonly hasPrevious: boolean;
2180
+ }
2181
+ /** The ref codec a `foldkit-entity` relation becomes: one ref, a nullable ref, or an array of refs. */
2182
+ type RelationField<Spec> = Spec extends Domain.RelationSpec<infer Target, infer Cardinality, infer Optional> ? Cardinality extends 'many' ? Schema.$Array<Schema.Codec<EntityRef<Target['name']>, RefKey<Target['name']>>> : Optional extends true ? Schema.NullOr<Schema.Codec<EntityRef<Target['name']>, RefKey<Target['name']>>> : Schema.Codec<EntityRef<Target['name']>, RefKey<Target['name']>> : never;
2183
+ /**
2184
+ * The fields Remote stores for a `foldkit-entity` Entity: its own fields, its
2185
+ * derived members (the server supplies them like any field), and each relation
2186
+ * as refs.
2187
+ */
2188
+ type FieldsFrom<E> = E extends Domain.Entity<any, infer Fields, infer Relations, infer Derived> ? Fields & { readonly [K in keyof Derived]: Derived[K]['schema']; } & { readonly [K in keyof Relations]: RelationField<Relations[K]>; } : never;
2189
+ declare const Entity$2: {
2190
+ /**
2191
+ * The Remote descriptor of a `foldkit-entity` Entity. Relations declared with
2192
+ * `Entity.relate` become ref fields, so the store, the planner, and the server
2193
+ * treat it as they treat an `Entity.make` descriptor.
2194
+ */
2195
+ from: <E extends Domain.AnyEntity>(entity: E & {
2196
+ readonly fields: {
2197
+ readonly id: unknown;
2198
+ };
2199
+ }) => EntityDescriptor<E["name"], FieldsFrom<E>>;
2200
+ make: <const Name extends string, const F extends Schema.Struct.Fields & {
2201
+ readonly id: Schema.Schema<unknown>;
2202
+ }>(name: Name, schema: Schema.Struct<F>) => EntityDescriptor<Name, F>;
2203
+ /** A relation to a known entity, decoded as a reference. */
2204
+ ref: <Name extends string, F extends Schema.Struct.Fields>(entity: EntityDescriptor<Name, F>) => Schema.Codec<EntityRef<Name, F>, RefKey<Name>>;
2205
+ /** A relation by name, for recursive or forward references. */
2206
+ refTo: <Name extends string>(name: Name) => Schema.Codec<EntityRef<Name>, RefKey<Name>>;
2207
+ /**
2208
+ * The wire key a relation field carries (`"Entity:id"`). Adapters that read a
2209
+ * foreign key emit this so the ref codec can decode it on the client.
2210
+ */
2211
+ refKey: (ref: {
2212
+ readonly entity: string;
2213
+ readonly id: string;
2214
+ }) => string;
2215
+ /** Splits a ref key back into its entity and id. */
2216
+ refParts: (encoded: string) => RefParts;
2217
+ /** A relation value of one authoritative page of refs. */
2218
+ refPage: <Name extends string, F extends Schema.Struct.Fields>(entity: EntityDescriptor<Name, F>) => Schema.Codec<RefPage<Name, F>, {
2219
+ readonly refs: ReadonlyArray<string>;
2220
+ readonly hasNext: boolean;
2221
+ readonly hasPrevious: boolean;
2222
+ }>;
2223
+ /**
2224
+ * A normalized patch for an entity, typed against its fields' wire shape:
2225
+ * write a relation as its ref key (`Entity.refKey`), as the server does.
2226
+ */
2227
+ patch: <Name extends string, F extends Schema.Struct.Fields>(ref: EntityRef<Name, F>, patch: Partial<Schema.Struct.Encoded<F>>) => EntityPatch<Name, F>;
2228
+ };
2229
+ //#endregion
2230
+ //#region src/matching.d.ts
2231
+ /**
2232
+ * An answer over the rows the client holds — never over the rows that exist.
2233
+ *
2234
+ * `complete` is the whole reason this is its own type rather than a `Page`. A
2235
+ * `Page` carries `hasNext`/`hasPrevious`, which are facts the *server* stated
2236
+ * about rows beyond the ones it delivered; a local answer has no such facts and
2237
+ * cannot invent them. What it can say is whether the population it judged was
2238
+ * all of it, which is decidable: a connection terminal at both ends is wholly
2239
+ * held, and nothing was skipped for a missing field.
2240
+ *
2241
+ * An incomplete answer is not wrong — it is an answer about less than the
2242
+ * caller may have meant, and the flag is what lets a view say "3 so far" rather
2243
+ * than "3", or a caller decide to ask the server.
2244
+ */
2245
+ interface Matched<A> {
2246
+ readonly items: ReadonlyArray<A>;
2247
+ /** Whether every row the answer is about was judged. */
2248
+ readonly complete: boolean;
2249
+ }
2250
+ /**
2251
+ * What the rows the client holds had to say about a body.
2252
+ *
2253
+ * `skipped` is the honest half. A row missing a field the body reads cannot be
2254
+ * judged — it is neither a match nor a non-match — and dropping it silently
2255
+ * would turn "I could not tell" into "no". Naming it lets a caller decide:
2256
+ * fetch the field, ask the server, or say the answer is partial.
2257
+ */
2258
+ interface Judged {
2259
+ /** Keys of the rows that satisfy the body, in the order the body asks for. */
2260
+ readonly matched: ReadonlyArray<EntityKey>;
2261
+ /** Keys of rows held but missing a field the body reads, so not judged either way. */
2262
+ readonly skipped: ReadonlyArray<EntityKey>;
2263
+ }
2264
+ interface MatchingOptions {
2265
+ /**
2266
+ * Judge only these keys. Without it every row of the body's Entity in the
2267
+ * store is a candidate, which is what a filter over a loaded list wants; with
2268
+ * it, a caller narrows to a connection's own edges.
2269
+ */
2270
+ readonly among?: ReadonlyArray<EntityKey> | undefined;
2271
+ }
2272
+ /**
2273
+ * The rows of `descriptor`'s Entity that the store holds and the body matches.
2274
+ *
2275
+ * The input is given **decoded**, as an application writes it, and encoded here
2276
+ * through the descriptor's own `Input` codec. That is deliberate and is the
2277
+ * whole reason this takes a descriptor rather than a bare body: a store holds
2278
+ * wire values, so an input has to be in that space to be compared against them,
2279
+ * and handing an interpreter a decoded value is a mistake **no runtime error
2280
+ * catches** — the reference interpreter answers "no rows", which reads exactly
2281
+ * like a correct answer. Doing it here means a caller cannot get it wrong.
2282
+ *
2283
+ * Literals in the body are deliberately *not* encoded. A literal written in
2284
+ * domain terms is already broken against the server, which binds it to a column
2285
+ * the same way; accepting it here would make the client quietly more permissive
2286
+ * than the thing it has to agree with.
2287
+ */
2288
+ declare const matching: <Name extends string, Input>(store: EntityStore, descriptor: QueryDescriptor<Name, Input, unknown>, input: Input, options?: MatchingOptions) => Judged;
2289
+ /**
2290
+ * Whether one row belongs to a query, as far as the client can tell.
2291
+ *
2292
+ * Three answers, and the third is the one that makes this usable. `'unknown'`
2293
+ * is a row the store never fetched, or holds without a field the body reads —
2294
+ * a caller that collapses it into `'no'` has turned "I could not tell" into an
2295
+ * answer, which is the mistake this whole module is shaped against.
2296
+ *
2297
+ * **Membership is decidable where position is not.** Whether a row satisfies
2298
+ * `eq`, `isNull` or `contains` needs no collation: equality on text is exact
2299
+ * and `contains` folds ASCII, both stated in §6.0.1. *Where* a row sorts needs
2300
+ * text collation, which is the backend's and deliberately outside the
2301
+ * conformant subset — so this answers the half that is always answerable, and
2302
+ * ordering stays the server's until a query can declare its collation.
2303
+ */
2304
+ type Belongs = 'yes' | 'no' | 'unknown';
2305
+ /**
2306
+ * Takes the input **encoded**, because its one caller holds it that way: a
2307
+ * connection identity carries the canonical encoded input, and making it decode
2308
+ * only for this to encode again would be a round trip that can fail.
2309
+ *
2310
+ * A decoded-input sibling was written first and deleted: nothing called it. The
2311
+ * asymmetry with `matching`, which takes a decoded input, is the shape of the
2312
+ * two real callers rather than an oversight.
2313
+ */
2314
+ declare const belongsEncoded: <Name extends string, Input>(store: EntityStore, descriptor: QueryDescriptor<Name, Input, unknown>, encoded: Readonly<Record<string, unknown>>, key: EntityKey) => Belongs;
2315
+ //#endregion
2316
+ //#region src/inspect.d.ts
2317
+ /** A query body's `Dependencies` as plain data: each field by its Entity's name and key. */
2318
+ interface ExplainedDependencies {
2319
+ readonly fields: ReadonlyArray<{
2320
+ readonly entity: string;
2321
+ readonly key: string;
2322
+ }>;
2323
+ readonly inputs: Dependencies['inputs'];
2324
+ readonly operations: Dependencies['operations'];
2325
+ }
2326
+ /** A serializable summary of a RemoteModel for DevTools and diagnostics. */
2327
+ interface RemoteInspection {
2328
+ readonly entities: ReadonlyArray<{
2329
+ readonly key: string;
2330
+ readonly present: ReadonlyArray<string>;
2331
+ readonly stale: ReadonlyArray<string>;
2332
+ readonly unavailable: ReadonlyArray<string>;
2333
+ readonly tombstone: boolean;
2334
+ readonly updatedAt: number;
2335
+ readonly windows: Readonly<Record<string, string>>;
2336
+ }>;
2337
+ readonly connections: ReadonlyArray<string>;
2338
+ readonly live: ReadonlyArray<string>;
2339
+ readonly gaps: ReadonlyArray<string>;
2340
+ /**
2341
+ * The `entity\0id\0field` marks of reads in flight, and a
2342
+ * `\0connection\0identity` mark for each query in flight. This is what "Remote is
2343
+ * working" means here, and it is read from the Model rather than from the
2344
+ * fibers doing the work: a tool that shows it shows something the Model can
2345
+ * be replayed to, and nothing that needs the runtime to be asked.
2346
+ */
2347
+ readonly loading: ReadonlyArray<string>;
2348
+ /**
2349
+ * The reads that failed and are not yet settled: queries by connection
2350
+ * identity, entity fields by `entity\0id\0field` mark, each with its error.
2351
+ */
2352
+ readonly failures: Failures;
2353
+ readonly mutations: {
2354
+ readonly pending: ReadonlyArray<string>;
2355
+ readonly failed: ReadonlyArray<string>;
2356
+ readonly applied: number;
2357
+ };
2358
+ }
2359
+ /** A pure, serializable view of the whole cache. */
2360
+ declare const inspectRemote: (model: RemoteModel) => RemoteInspection;
2361
+ /** A pure, serializable view of one entity, or `undefined` if unknown. */
2362
+ declare const inspectEntity: (model: RemoteModel, key: string) => RemoteInspection["entities"][number] | undefined;
2363
+ /**
2364
+ * Why a read shows what it shows, in words, and for `Initial`, which of the
2365
+ * usual mistakes it is.
2366
+ *
2367
+ * `Initial` means nothing is fetching the read, and that is almost always
2368
+ * wiring rather than the network: no active Surface reads it, or one does and
2369
+ * Remote's Subscriptions are not running. The Model can tell those apart when
2370
+ * it is given the active record, so this says which, and what to do.
2371
+ */
2372
+ interface ReadDiagnosis {
2373
+ readonly state: RemoteData<unknown>['_tag'];
2374
+ /**
2375
+ * For `Initial` only. `NotObserved`: no active Surface reads it.
2376
+ * `NotFetching`: one does, and nothing is fetching it, so Remote's
2377
+ * Subscriptions are most likely not installed. `Unknown`: no active record
2378
+ * was given to tell.
2379
+ */
2380
+ readonly reason?: 'NotObserved' | 'NotFetching' | 'Unknown' | undefined;
2381
+ /** One or two sentences a developer can act on. */
2382
+ readonly message: string;
2383
+ /** The active Surfaces reading it, when the active record was given. */
2384
+ readonly surfaces?: ReadonlyArray<string> | undefined;
2385
+ }
2386
+ /**
2387
+ * What one query read is, and what it currently is — data-query-DESIGN §29.1.
2388
+ *
2389
+ * Every member is gathered from something that already existed: the read was
2390
+ * always this many pieces, and nothing had ever been asked to put them in one
2391
+ * place. It is plain serializable data, so a DevTools panel, a log line and a
2392
+ * test assert on the same value.
2393
+ *
2394
+ * Two members of §29.1's sketch are **not** here, and their absence is the
2395
+ * finding rather than an omission:
2396
+ *
2397
+ * - **Surface.** A Projection does not know which Surface reads it, and often
2398
+ * several do — so it is not a property of the read, and `explain` cannot
2399
+ * recover it alone. Given the active Surfaces (the same record
2400
+ * `subscriptions` takes), it reports **every** Surface reading the connection
2401
+ * rather than guessing one, and omits the member entirely when it was not
2402
+ * given them.
2403
+ * - **Executor.** The thing that answers a query is a `RemoteClient` Layer in
2404
+ * the runtime, not a value in the Model, and a pure read of the Model cannot
2405
+ * see it. That is the same boundary that makes this function pure and
2406
+ * replayable, so it is worth more than the line of text.
2407
+ *
2408
+ * And one that the design proposed and this does not want: *expectation*
2409
+ * (required versus optional). §11 left it unbuilt for want of a consumer, and
2410
+ * the explanation was the likeliest consumer. It turns out not to need it — a
2411
+ * query's result is a connection, so the shape is a `Page`, decided by the
2412
+ * definition rather than by the read. Nothing here has an opinion about whether
2413
+ * an empty one is an error, because nothing here has to have one.
2414
+ */
2415
+ interface QueryExplanation {
2416
+ /** The bound Remote domain that answers it. */
2417
+ readonly domain: string;
2418
+ /** The definition's name. */
2419
+ readonly query: string;
2420
+ /** The input as encoded, which is what the identity is built from. */
2421
+ readonly input: unknown;
2422
+ /** The connection identity: definition plus canonical input, excluding the window. */
2423
+ readonly identity: string;
2424
+ /** How much of the connection this read asks for. */
2425
+ readonly window: QueryWindow;
2426
+ /** What it reads of each item, as the slice asked of the server. */
2427
+ readonly select: RelationRequirement;
2428
+ /**
2429
+ * What the query means, as readable text — `Query.show`, and so neither SQL
2430
+ * nor whatever the backend compiled. Absent for a definition made with
2431
+ * `Query.make`, whose meaning lives on the server that answers it.
2432
+ */
2433
+ readonly body?: string | undefined;
2434
+ /**
2435
+ * The fields, inputs and operations the body reads; absent with the body.
2436
+ * Plain data, so it serializes: a field is its Entity's name and key, which
2437
+ * is unambiguous because a query reads one Entity.
2438
+ */
2439
+ readonly dependencies?: ExplainedDependencies | undefined;
2440
+ /** What the read answers from this Model right now. */
2441
+ readonly state: RemoteData<unknown>['_tag'];
2442
+ /**
2443
+ * The active Surfaces reading this connection at this Model, if the active
2444
+ * record was supplied. Plural because several may, which is why a Projection
2445
+ * cannot carry the answer itself.
2446
+ */
2447
+ readonly surfaces?: ReadonlyArray<string> | undefined;
2448
+ /**
2449
+ * Why each of those Surfaces is active, where it was placed with
2450
+ * `Surface.when` — the Model path and the tag, without running anything. A
2451
+ * Surface placed with `Surface.at` has no entry: a callback cannot be read.
2452
+ */
2453
+ readonly activation?: ReadonlyArray<{
2454
+ readonly surface: string;
2455
+ readonly path: readonly string[];
2456
+ readonly tag: string;
2457
+ }> | undefined;
2458
+ }
2459
+ //#endregion
2460
+ //#region src/plan.d.ts
2461
+ type Window = NonNullable<Requirement['windows']>[string];
2462
+ /** A stable key for a window, so two equal windows compare equal. */
2463
+ declare const windowKey: (window: Window) => string;
2464
+ interface PlanFreshness {
2465
+ readonly now: number;
2466
+ /** A present entry older than this many milliseconds is refreshed whole. */
2467
+ readonly freshness: number;
2468
+ }
2469
+ interface PlanOptions {
2470
+ readonly freshness?: PlanFreshness | undefined;
2471
+ /** Plan every requested field, present or not, tombstoned or not. */
2472
+ readonly force?: boolean | undefined;
2473
+ }
2474
+ /** When present values next go stale, and the requirements of the entities that do. */
2475
+ interface Deadline {
2476
+ readonly at: number;
2477
+ readonly due: ReadonlyArray<Requirement>;
2478
+ }
2479
+ /**
2480
+ * The earliest moment a value `requirements` read, following the relations the
2481
+ * store holds as `plan` does, goes stale under `freshness`, with the
2482
+ * requirements of the entities that go stale then. A field the server settled
2483
+ * without a value ages with its entity too, since `plan` asks for it again once
2484
+ * the entity expires. Nothing when no such field is still fresh: what is
2485
+ * already expired or stale is planned, not awaited, which is what keeps a
2486
+ * timer from firing on what it already fired on. It is the next moment the
2487
+ * plan can change with the clock alone, which the read entry relies on to
2488
+ * reuse its plan until then.
2489
+ */
2490
+ declare const deadlineOf: (store: EntityStore, requirements: readonly Requirement[], freshness: PlanFreshness) => Deadline | undefined;
2491
+ declare const plan: (store: EntityStore, requirements: readonly Requirement[], options?: PlanOptions) => ReadonlyArray<Requirement>;
2492
+ //#endregion
2493
+ //#region src/policy.d.ts
2494
+ type RemotePolicy =
2495
+ /** Fetch only fields the store lacks (missing, stale, or re-windowed). */
2496
+ {
2497
+ readonly _tag: 'CacheFirst';
2498
+ } |
2499
+ /**
2500
+ * Keep present values visible, read them as `Refreshing`, and refetch an
2501
+ * entry older than `maxAge` milliseconds.
2502
+ */
2503
+ {
2504
+ readonly _tag: 'StaleWhileRevalidate';
2505
+ readonly maxAge: number;
2506
+ } |
2507
+ /** Fetch every selected field regardless of coverage; cached values stay visible meanwhile. */
2508
+ {
2509
+ readonly _tag: 'NetworkOnly';
2510
+ };
2511
+ declare const RemotePolicy: {
2512
+ /** Fetch only what the store lacks. */
2513
+ cacheFirst: {
2514
+ readonly _tag: "CacheFirst";
2515
+ };
2516
+ /** Keep present values visible, read as `Refreshing`, and refetch an entry older than `maxAge` ms. */
2517
+ staleWhileRevalidate: (options: {
2518
+ readonly maxAge: number;
2519
+ }) => RemotePolicy;
2520
+ /** Fetch every selected field regardless of coverage; cached values stay visible meanwhile. */
2521
+ networkOnly: {
2522
+ readonly _tag: "NetworkOnly";
2523
+ };
2524
+ /** The planner options a policy compiles to at `now`. */
2525
+ toPlan: (policy: RemotePolicy, now: number) => PlanOptions;
2526
+ /**
2527
+ * Whether a read under this policy may refetch fields the store already
2528
+ * holds, so an observer marks them stale (read as `Refreshing`) while the
2529
+ * request is pending.
2530
+ */
2531
+ refreshes: (policy: RemotePolicy) => boolean;
2532
+ };
2533
+ //#endregion
2534
+ //#region src/index.d.ts
2535
+ /** What a domain registers: a Remote descriptor, or a `foldkit-entity` Entity (read through `Entity.from`). */
2536
+ type EntityLike = EntityDescriptor<any, any> | Domain.AnyEntity;
2537
+ /**
2538
+ * What a read selects: a Remote Selection, or a `foldkit-entity` Selection
2539
+ * (read through `Selection.from`).
2540
+ */
2541
+ type EntitySelection<Value, Name extends string, Id extends string = string> = Selection<Value, Name, 'entity'> | Domain.Selection<Name, unknown, Schema.Constraint & {
2542
+ readonly Type: Value;
2543
+ }, Id>;
2544
+ /** The Remote descriptor either kind of entity reads as, at the type level. */
2545
+ type DescriptorOf<E extends EntityLike> = E extends EntityDescriptor<any, any> ? E : E extends Domain.AnyEntity ? EntityDescriptor<E['name'], FieldsFrom<E>> : never;
2546
+ type NameOf<E extends EntityLike> = DescriptorOf<E> extends EntityDescriptor<infer N, any> ? N : never;
2547
+ type FieldsOf<E extends EntityLike> = DescriptorOf<E> extends EntityDescriptor<any, infer F> ? F : never;
2548
+ type EntityName<D> = D extends {
2549
+ readonly name: infer Name extends string;
2550
+ } ? Name : never;
2551
+ type QueryName<D> = D extends QueryDescriptor<infer Name, any, any> ? Name : never;
2552
+ type MutationName<D> = D extends MutationDescriptor<infer Name, any, any> ? Name : never;
2553
+ /**
2554
+ * Nothing when `Name` is one of the domain's registered `Names`; otherwise a
2555
+ * branded failure naming the descriptor, so `Data.get(Team.select(…))` for an
2556
+ * unregistered `Team` errors at the selection in one line.
2557
+ */
2558
+ type Registered<Name extends string, Names extends string, Kind extends string> = [Name] extends [Names] ? unknown : Invalid<`${Kind} "${Name}" is not registered with this Remote domain`>;
2559
+ /** Nothing when a selection is of the query's entity; otherwise a branded failure naming both. */
2560
+ type SelectsEntity<Entity extends string, Of extends string> = [Entity] extends [Of] ? unknown : Invalid<`the selection is of "${Entity}", but the query lists "${Of}"`>;
2561
+ interface RemoteDescriptor<Entities extends readonly EntityLike[] = readonly EntityLike[], Queries extends readonly QueryDescriptor<any, any, any>[] = readonly QueryDescriptor<any, any, any>[], Mutations extends readonly MutationDescriptor<any, any, any>[] = readonly MutationDescriptor<any, any, any>[]> {
2562
+ readonly entities: Entities;
2563
+ readonly queries: Queries;
2564
+ readonly mutations: Mutations;
2565
+ readonly Model: Schema.Codec<RemoteModel, unknown>;
2566
+ readonly initial: RemoteModel;
2567
+ readonly Message: Schema.Schema<RemoteMessage>;
2568
+ readonly update: (model: RemoteModel, message: RemoteMessage) => RemoteModel;
2569
+ readonly rpc: typeof RemoteRpc;
2570
+ /** Name-keyed lookups built from the declared entities, queries, and mutations. */
2571
+ readonly registry: {
2572
+ readonly entities: ReadonlyMap<string, EntityDescriptor<any, any>>;
2573
+ readonly queries: ReadonlyMap<string, QueryDescriptor<any, any, any>>;
2574
+ readonly mutations: ReadonlyMap<string, MutationDescriptor<any, any, any>>;
2575
+ };
2576
+ }
2577
+ declare const boundRemoteNames: unique symbol;
2578
+ interface BoundRemote<AppModel, Store extends RemoteModel, Names extends string = string> {
2579
+ readonly definition: RemoteDescriptor;
2580
+ readonly store: ModelRef<AppModel, Store>;
2581
+ /** For `Module`: owns the store's Model path. */
2582
+ readonly contract: Contract;
2583
+ /** Phantom: the entity names this Remote definition registers. */
2584
+ readonly [boundRemoteNames]?: Names;
2585
+ }
2586
+ type MutationInput<M> = M extends MutationDescriptor<any, infer Input, any> ? Input : never;
2587
+ interface DomainMutateOptions {
2588
+ /** Overrides the generated id, for a retry, a durable bridge, or a test. */
2589
+ readonly requestId?: string | undefined;
2590
+ /**
2591
+ * What the request changes before the server answers, released when it
2592
+ * settles. A function receives the generated ids, so a created entity can
2593
+ * carry `tempId` until the result names the real one.
2594
+ */
2595
+ readonly optimistic?: ReadonlyArray<OptimisticOperation> | ((ids: {
2596
+ readonly requestId: string;
2597
+ readonly tempId: string;
2598
+ }) => ReadonlyArray<OptimisticOperation>) | undefined;
2599
+ /** The clock `MutationSucceeded` stamps the answer with; default `Date.now`, read at each use. */
2600
+ readonly now?: (() => number) | undefined;
2601
+ }
2602
+ /** A Foldkit Subscription entry of the Remote domain, emitting its Messages through `RemoteClient`. */
2603
+ type RemoteEntry<AppModel, Dependencies> = EntryWithoutKeepAlive<AppModel, RemoteMessage, Dependencies, RemoteClient>;
2604
+ /**
2605
+ * The entries `RemoteDomain.subscriptions` returns for an active record: a read
2606
+ * and a live entry per key (the live one idles when nothing is read live), and
2607
+ * `retain`.
2608
+ */
2609
+ type SubscriptionEntries<AppModel, Active, Message = RemoteMessage> = { readonly [K in keyof Active & (string | number) as `${K}.read`]: EntryWithoutKeepAlive<AppModel, Message, ReadDependencies, RemoteClient>; } & { readonly [K in keyof Active & (string | number) as `${K}.live`]: EntryWithoutKeepAlive<AppModel, Message, LiveDependencies, RemoteClient>; } & {
2610
+ readonly retain: EntryWithoutKeepAlive<AppModel, Message, RetentionRoots, never>;
2611
+ };
2612
+ /** The dependencies of a live entry: what it subscribes to, and where a restart resumes. */
2613
+ interface LiveDependencies {
2614
+ readonly requirements: ReadonlyArray<Requirement>;
2615
+ readonly cursor: LiveCursor;
2616
+ readonly floor: number;
2617
+ }
2618
+ interface SubscriptionsOptions extends ObserveOptions, LiveOptions, RetainOptions {}
2619
+ /** A Remote domain's wiring for an assembly: it routes Remote's Messages into `reduce`, brings its Subscriptions and contract, and requires `RemoteClient` from the runtime's resources Layer. */
2620
+ type RemoteWiring<AppModel> = Wiring<AppModel, RemoteMessage | RemoteMessageInput, RemoteClient>;
2621
+ /** What `RemoteDomain.mutate` hands `update`: the Model with the request started, and the Command that settles it. */
2622
+ interface MutationStarted<AppModel> {
2623
+ readonly model: AppModel;
2624
+ readonly requestId: string;
2625
+ readonly tempId: string;
2626
+ /** Yields `MutationSucceeded` or `MutationFailed`; never fails. */
2627
+ readonly command: Command<RemoteMessage, never, RemoteClient>;
2628
+ }
2629
+ /**
2630
+ * A Remote domain bound to its place in the application Model: the descriptor
2631
+ * (`Remote.define`), the binding (`Remote.at`), and the application-facing
2632
+ * operations over them. Every method compiles to the `Remote.*` function of the
2633
+ * same name, which stays exported for tooling, SSR, and tests.
2634
+ */
2635
+ interface RemoteDomain<AppModel, Store extends RemoteModel, Entities extends readonly EntityLike[], Queries extends readonly QueryDescriptor<any, any, any>[], Mutations extends readonly MutationDescriptor<any, any, any>[]> extends BoundRemote<AppModel, Store, EntityName<Entities[number]>>, RemoteDescriptor<Entities, Queries, Mutations> {
2636
+ /** `Remote.select`: a Projection reading one entity through a selection of a registered entity. */
2637
+ get<Value, Name extends string, Id extends string = string>(selection: EntitySelection<Value, Name, Id> & Registered<Name, EntityName<Entities[number]>, 'Entity'>, id: NoInfer<Id>): Projection<AppModel, RemoteData<Value>>;
2638
+ /**
2639
+ * `get`, and the projection also subscribes to the entity's changes: its
2640
+ * requirements are marked `live`, so `subscriptions` derives a live entry for
2641
+ * the Surfaces that read it.
2642
+ */
2643
+ live<Value, Name extends string, Id extends string = string>(selection: EntitySelection<Value, Name, Id> & Registered<Name, EntityName<Entities[number]>, 'Entity'>, id: NoInfer<Id>): Projection<AppModel, RemoteData<Value>>;
2644
+ /**
2645
+ * A query connection read as a `Page` of items selected of the query's
2646
+ * entity: `Initial` until the page and every item's selected fields are
2647
+ * present, `Refreshing` while any of them is being refetched. The window is
2648
+ * the page first asked for; the pages `next`, `previous` and `fetch` merge
2649
+ * onto the connection read through the same projection.
2650
+ */
2651
+ query<Q extends QueryDescriptor<any, any, any>, Value, Entity extends string>(query: Q & Registered<Q['name'], QueryName<Queries[number]>, 'Query'>, input: QueryInput<Q>, options: QueryOptions<Value, Entity, QueryEntity<Q>>): QueryProjection<AppModel, Value, Q['name'], QueryInput<Q>>;
2652
+ /**
2653
+ * "Load more": the Model with the read's window grown by one page, so it
2654
+ * shows that many more rows; the read entry fetches what the connection
2655
+ * lacks. None when the read shows everything there is (or is not a sized
2656
+ * window). Called from `update`.
2657
+ */
2658
+ more<Name extends string, Input>(model: AppModel, projection: QueryProjection<AppModel, any, Name, Input>): Option.Option<AppModel>;
2659
+ /**
2660
+ * What a query read is and what it currently is, as one serializable value —
2661
+ * data-query-DESIGN §29.1: the domain, the definition and its input, the
2662
+ * connection identity, the window, the Selection, the body as readable text
2663
+ * with what it depends on, and what the read answers from this Model.
2664
+ *
2665
+ * Pure, so a DevTools panel showing it shows something the Model can be
2666
+ * replayed to.
2667
+ *
2668
+ * Given `surfaces` — the same active record `subscriptions` takes — it also
2669
+ * reports which of them read this connection, and why each is active where
2670
+ * that is a readable fact (`Surface.when`) rather than a callback
2671
+ * (`Surface.at`). A Projection cannot carry this itself: several Surfaces may
2672
+ * read one connection, so it is not a property of the read.
2673
+ */
2674
+ explain<Name extends string, Input>(model: AppModel, projection: QueryProjection<AppModel, any, Name, Input>, options?: {
2675
+ readonly surfaces?: Readonly<Record<string, ActiveSurface<AppModel>>> | undefined;
2676
+ }): QueryExplanation;
2677
+ /**
2678
+ * Why a read shows what it shows, in words. Any Remote read: `Data.get`,
2679
+ * `Data.live` or `Data.query`.
2680
+ *
2681
+ * Its point is `Initial`, which means nothing is fetching the read and is
2682
+ * almost always a wiring mistake. Given `surfaces`, the same active record
2683
+ * `subscriptions` takes, it says which: no active Surface reads it, or one
2684
+ * does and Remote's Subscriptions are not running. Pure, like `explain`.
2685
+ */
2686
+ why(model: AppModel, projection: Projection<AppModel, RemoteData<unknown>>, options?: {
2687
+ readonly surfaces?: Readonly<Record<string, ActiveSurface<AppModel>>> | undefined;
2688
+ }): ReadDiagnosis;
2689
+ /**
2690
+ * The rows of a loaded list that a body matches, decoded as the list decodes
2691
+ * them — a filter that asks the server nothing.
2692
+ *
2693
+ * **It filters a list; it does not run a query.** That distinction is what
2694
+ * keeps it honest. "Which rows match" would need to know that the list holds
2695
+ * every row the body could match, which is predicate containment and is
2696
+ * deliberately not built. "Which rows *of this list* match" is decidable from
2697
+ * what is already here, and is what a search box over a loaded page actually
2698
+ * wants.
2699
+ *
2700
+ * `complete` says whether the answer is about the whole list: every edge
2701
+ * judged, and the connection terminal at both ends. An incomplete answer is
2702
+ * not wrong — it is about less than the caller may have meant, which is why
2703
+ * it is said rather than left for a view to assume.
2704
+ *
2705
+ * Creates no connection, so there is nothing new to retain and nothing new to
2706
+ * fetch. The server stays authoritative for which rows exist.
2707
+ */
2708
+ filtered<Value, Name extends string, Input, Q extends QueryDescriptor<any, any, any>>(model: AppModel, over: QueryProjection<AppModel, Value, Name, Input>, by: Q & Registered<Q['name'], QueryName<Queries[number]>, 'Query'>, input: QueryInput<Q>): Matched<Value>;
2709
+ /**
2710
+ * Shows operations over the store with no request behind them, as a mutation's
2711
+ * `optimistic` ones show while it is in flight: every Selection and view draws
2712
+ * them. For a preview of a change nobody has made. They stay until `lift`;
2713
+ * showing an id again replaces what it showed. Called from `update`. A read
2714
+ * of an entity only overlays show, lacking a field it selects, is `Failed`
2715
+ * (`Overlaid`): nothing will fetch that field.
2716
+ */
2717
+ overlay(model: AppModel, id: string, optimistic: ReadonlyArray<OptimisticOperation>): AppModel;
2718
+ /** Lifts what `overlay` showed under this id. Lifting nothing returns the same Model. */
2719
+ lift(model: AppModel, id: string): AppModel;
2720
+ /** `Remote.refresh`: marks what a projection or a Surface requires as due, for its read entry to refetch. */
2721
+ refresh(model: AppModel, target: Projection<AppModel, unknown> | Surface<AppModel, any, any, void>): AppModel;
2722
+ /** `Remote.forget`: the Model with every server-derived fact gone, for a change of principal. */
2723
+ forget(model: AppModel): AppModel;
2724
+ /**
2725
+ * A read of this domain as an active Surface, for `subscriptions` and
2726
+ * `wiring`: `projectionOf` is what it reads for a Model, none while it
2727
+ * reads nothing. It belongs to the domain's application, and lists no
2728
+ * Messages: it is a requirement, not a sender. A domain made from a raw
2729
+ * optic names no application, so this throws for one.
2730
+ */
2731
+ active<Value>(name: string, projectionOf: (model: AppModel) => Option.Option<Projection<AppModel, Value>>): ActiveSurface<AppModel>;
2732
+ /**
2733
+ * The Foldkit Subscription entries for the active Surfaces, keyed for
2734
+ * `Subscription.make`: a read entry per Surface (`Remote.observe`), a live
2735
+ * entry per Surface that reads through `live` (`Remote.live`), and one
2736
+ * retain entry (`Remote.retain`). Retention is the domain's: the retain
2737
+ * entry of every call roots the active Surfaces of every call, so reads
2738
+ * split over calls (one per policy) do not collect each other's data. A
2739
+ * Surface's params are a function of the Model (`Surface.at`), so what is
2740
+ * fetched, subscribed, and retained follows the Model.
2741
+ */
2742
+ subscriptions<const Active extends Readonly<Record<string, ActiveSurface<AppModel> | Surface<AppModel, any, any, void>>>>(active: Active, options?: SubscriptionsOptions): SubscriptionEntries<AppModel, Active>;
2743
+ /** `Remote.plan`: the requirements the store does not satisfy. */
2744
+ plan<Value>(model: AppModel, projection: Projection<AppModel, Value>, options?: PlanOptions): ReadonlyArray<Requirement>;
2745
+ /** `Remote.meta`: when what a projection shows was last received, and whether it is stale or loading. */
2746
+ meta<Value>(model: AppModel, projection: Projection<AppModel, Value>): ReadMeta;
2747
+ /** `Remote.storeOf`: the visible store, base under the pending optimistic layers. */
2748
+ storeOf(model: AppModel): EntityStore;
2749
+ /**
2750
+ * `Remote.confirmed`: the same projection read against the server-derived
2751
+ * store alone, with every pending optimistic layer and connection overlay
2752
+ * left off. What it plans is unchanged — the requirements are the
2753
+ * projection's own — so observing it reads exactly what observing the
2754
+ * projection reads; only what it *shows* differs.
2755
+ *
2756
+ * A view usually wants the projection itself, which is the visible read:
2757
+ * the optimistic layers are there so a change shows before the server has
2758
+ * agreed to it. This is for the reader that must not believe a change until
2759
+ * the server has confirmed it, which in practice is an Agent capability
2760
+ * reporting that what it was asked to do is done:
2761
+ *
2762
+ * ```ts
2763
+ * Agent.when({
2764
+ * projection: Data.confirmed(ProjectPage.model.project),
2765
+ * predicate: (project, request) => project.name === request.name,
2766
+ * })
2767
+ * ```
2768
+ *
2769
+ * There is deliberately no `visible`: a projection is already the visible
2770
+ * read, and a wrapper that only forwards would be a second name for it.
2771
+ */
2772
+ confirmed<P extends Projection<AppModel, any>>(projection: P): P;
2773
+ /**
2774
+ * The plan run through `RemoteClient` and reduced into the Model: the
2775
+ * projection's pending queries first, then the fields it lacks (the pages'
2776
+ * items included). For SSR, route or hover prefetch, and tests.
2777
+ */
2778
+ prefetch<Value>(model: AppModel, projection: Projection<AppModel, Value>, options?: ObserveOptions): Effect.Effect<AppModel, RemoteReadError | RemoteProtocolError | RemoteQueryError, RemoteClient>;
2779
+ /**
2780
+ * The Model with everything the active Surfaces read, for a render that
2781
+ * fetches nothing (SSR, a prerender). Each pass prefetches every Surface
2782
+ * that plans a read, over the Model the one before it left, so a Surface
2783
+ * active only once another's read has arrived is read in the next pass (or
2784
+ * the same one, when it comes later in `active`). It stops at the first
2785
+ * pass that plans nothing, and fails with `RemoteUnsatisfied` when
2786
+ * `options.passes` run out first. Reads are cache-first: a field already
2787
+ * held is not asked again.
2788
+ */
2789
+ satisfy(model: AppModel, active: Readonly<Record<string, ActiveSurface<AppModel> | Surface<AppModel, any, any, void>>>, options?: SatisfyOptions): Effect.Effect<AppModel, RemoteReadError | RemoteProtocolError | RemoteQueryError | RemoteUnsatisfied, RemoteClient>;
2790
+ /**
2791
+ * Starts a registered mutation from `update`: applies `MutationStarted` (with
2792
+ * the optimistic operations) to the Model and returns the Command that runs
2793
+ * it and yields the settling Message. The request id comes from the model's
2794
+ * mutation sequence unless `options.requestId` is given.
2795
+ */
2796
+ mutate<M extends MutationDescriptor<any, any, any>>(model: AppModel, mutation: M & Registered<M['name'], MutationName<Mutations[number]>, 'Mutation'>, input: MutationInput<M>, options?: DomainMutateOptions): MutationStarted<AppModel>;
2797
+ /**
2798
+ * What Remote knows of a mutation `mutate` started, by its request id:
2799
+ * pending, applied, or failed with the error the server or transport gave.
2800
+ */
2801
+ mutation(model: AppModel, requestId: string): MutationStatus;
2802
+ /** `updateRemote` on the bound slice: reduces one of Remote's Messages, as `RemoteMessage` or as the application's union constructs it. */
2803
+ reduce(model: AppModel, message: RemoteMessage | RemoteMessageInput): AppModel;
2804
+ /**
2805
+ * How this domain joins an assembly: it routes Remote's Messages into
2806
+ * `reduce`, brings its Subscriptions and contract, and requires
2807
+ * `RemoteClient` from the runtime's resources Layer. One assembly holds at
2808
+ * most one Remote wiring: every domain claims the same tags, and routing
2809
+ * takes the first claimant.
2810
+ */
2811
+ wiring: <const Active extends Readonly<Record<string, ActiveSurface<AppModel> | Surface<AppModel, any, any, void>>>>(active: Active, options?: SubscriptionsOptions) => RemoteWiring<AppModel>;
2812
+ /** `Remote.inspect` of the bound slice. */
2813
+ inspect(model: AppModel): RemoteInspection;
2814
+ }
2815
+ /** What `Remote.fold(Data, …).mutate` starts: `Data.mutate`'s result with its Command lifted. */
2816
+ type FoldedMutationStarted<AppModel, ParentMessage> = Omit<MutationStarted<AppModel>, 'command'> & {
2817
+ readonly command: Command<ParentMessage, never, RemoteClient>;
2818
+ };
2819
+ /**
2820
+ * A bound domain folded under one of the application's own Message variants,
2821
+ * from `Remote.fold`. Calling it reduces a Remote Message into the Model; the
2822
+ * members that produce Messages, `fetch`, `mutate`, and `subscriptions`,
2823
+ * yield the wrapper Message instead of `RemoteMessage`, with the lift recorded
2824
+ * so Story and Scene can resolve a fetch or a mutation by Remote's own answer.
2825
+ * Members that only read or write the Model (`get`, `refresh`, `next`,
2826
+ * `overlay`, and the rest) stay on the domain itself.
2827
+ */
2828
+ interface RemoteFold<AppModel, ParentMessage, Domain extends RemoteDomain<AppModel, any, any, any, any>> {
2829
+ (model: AppModel, message: RemoteMessage | RemoteMessageInput): Update.Return<AppModel, ParentMessage>;
2830
+ /** `Data.mutate`, its Command lifted. */
2831
+ readonly mutate: (...args: Parameters<Domain['mutate']>) => FoldedMutationStarted<AppModel, ParentMessage>;
2832
+ /** `Data.subscriptions`, every entry lifted to the wrapper Message. */
2833
+ readonly subscriptions: <const Active extends Readonly<Record<string, ActiveSurface<AppModel> | Surface<AppModel, any, any, void>>>>(active: Active, options?: SubscriptionsOptions) => SubscriptionEntries<AppModel, Active, ParentMessage>;
2834
+ }
2835
+ /** The application Model a bound domain is over. */
2836
+ type ModelOfDomain<Domain> = Domain extends RemoteDomain<infer AppModel, any, any, any, any> ? AppModel : never;
2837
+ /** A projection's connection requirement with the `QueryRef` that runs it. */
2838
+ interface QueryRequirement extends ConnectionRequirement {
2839
+ readonly ref: QueryRef<string, unknown>;
2840
+ }
2841
+ /** A page forward (`first`, `after`) or back (`last`, `before`); mixing the two is a type error. */
2842
+ type QueryWindowOptions = {
2843
+ readonly first?: number | undefined;
2844
+ readonly after?: string | undefined;
2845
+ readonly last?: undefined;
2846
+ readonly before?: undefined;
2847
+ } | {
2848
+ readonly last: number;
2849
+ readonly before?: string | undefined;
2850
+ readonly first?: undefined;
2851
+ readonly after?: undefined;
2852
+ };
2853
+ type QueryOptions<Value, Entity extends string, Of extends string = Entity> = {
2854
+ /** What to read of each item: a selection of the query's entity (`Of`). */
2855
+ readonly select: EntitySelection<Value, Entity> & SelectsEntity<Entity, Of>;
2856
+ } & QueryWindowOptions;
2857
+ /** A query connection read as a `Page` of selected items; `ref` is the connection with its first window. */
2858
+ interface QueryProjection<AppModel, Value, Name extends string, Input> extends Projection<AppModel, RemoteData<Page<Value>>> {
2859
+ readonly ref: QueryRef<Name, Input>;
2860
+ /** What it reads of each item, so a filter over the same list decodes identically. */
2861
+ readonly selection: Selection<Value, string>;
2862
+ }
2863
+ /** The input of a query descriptor. */
2864
+ type QueryInput<Q> = Q extends QueryDescriptor<any, infer Input, any> ? Input : never;
2865
+ /** The entity a query's connection is over. */
2866
+ type QueryEntity<Q> = Q extends QueryDescriptor<any, any, ConnectionSpec<infer Entity>> ? Entity : string;
2867
+ /**
2868
+ * When what a projection shows was last received, and whether it is stale
2869
+ * or loading. See `Remote.meta`.
2870
+ */
2871
+ interface ReadMeta {
2872
+ /** The newest server write among what is shown; none received reads `undefined`. */
2873
+ readonly updatedAt: number | undefined;
2874
+ /** Any shown field or connection is marked stale. */
2875
+ readonly stale: boolean;
2876
+ /** Any shown field or connection is in flight. */
2877
+ readonly loading: boolean;
2878
+ }
2879
+ interface MutateOptions {
2880
+ /** What the request changes before the server answers; released when it settles. */
2881
+ readonly optimistic?: ReadonlyArray<OptimisticOperation> | undefined;
2882
+ /** The clock `MutationSucceeded` stamps the answer with; default `Date.now`, read at each use. */
2883
+ readonly now?: (() => number) | undefined;
2884
+ }
2885
+ interface RetainOptions {
2886
+ /** The query connections the application shows, by `QueryRef` or identity. */
2887
+ readonly connections?: ReadonlyArray<ConnectionIdentity> | undefined;
2888
+ /** How long the roots must be stable before collecting; default none. */
2889
+ readonly grace?: Duration.Input | undefined;
2890
+ }
2891
+ /** How `Remote.observe` and `Remote.prefetch` treat fields the store already holds. */
2892
+ interface ObserveOptions {
2893
+ /** Default `RemotePolicy.cacheFirst`. */
2894
+ readonly policy?: RemotePolicy | undefined;
2895
+ /** The clock a refreshing policy reads; default `Date.now`, read at each use. */
2896
+ readonly now?: (() => number) | undefined;
2897
+ }
2898
+ /** How `Data.satisfy` reads: how many passes it may take, and the clock. */
2899
+ interface SatisfyOptions {
2900
+ /** At most this many passes over the Surfaces; default 8. */
2901
+ readonly passes?: number | undefined;
2902
+ /** The clock the reads are stamped with; default `Date.now`, read at each use. */
2903
+ readonly now?: (() => number) | undefined;
2904
+ }
2905
+ declare const RemoteUnsatisfied_base: Schema.Class<RemoteUnsatisfied, Schema.TaggedStruct<"RemoteUnsatisfied", {
2906
+ readonly surfaces: Schema.$Array<Schema.String>;
2907
+ readonly passes: Schema.Number;
2908
+ }>, import("effect/Cause").YieldableError>;
2909
+ /**
2910
+ * `Data.satisfy` reached its bound with Surfaces still reading, such as a
2911
+ * chain whose every read reveals one more. It names them, so a page that
2912
+ * would have rendered them loading fails instead. (A read the server leaves
2913
+ * unanswered settles as missing and ends the loop.)
2914
+ */
2915
+ declare class RemoteUnsatisfied extends RemoteUnsatisfied_base {}
2916
+ interface LiveOptions {
2917
+ /** The clock `LiveReceived` stamps events with; default `Date.now`, read at each use. */
2918
+ readonly now?: (() => number) | undefined;
2919
+ }
2920
+ /** A query the read entry runs, as its dependencies carry it: plain data Foldkit compares. */
2921
+ declare const PlannedQuery: Schema.Struct<{
2922
+ readonly identity: Schema.String;
2923
+ readonly window: Schema.Struct<{
2924
+ readonly first: Schema.optional<Schema.Number>;
2925
+ readonly last: Schema.optional<Schema.Number>;
2926
+ readonly after: Schema.optional<Schema.String>;
2927
+ readonly before: Schema.optional<Schema.String>;
2928
+ }>;
2929
+ readonly select: Schema.Codec<RelationRequirement, RelationRequirement, never, never>;
2930
+ }>;
2931
+ /** The dependencies of the read entry: the entity fields to read and the queries to run. */
2932
+ interface ReadDependencies {
2933
+ readonly requirements: ReadonlyArray<Requirement>;
2934
+ readonly queries: ReadonlyArray<Schema.Schema.Type<typeof PlannedQuery>>;
2935
+ /**
2936
+ * The highest generation the fields this entry reads were refreshed at: a
2937
+ * refresh of any of them restarts the entry, and a refresh of anything else
2938
+ * leaves it running.
2939
+ */
2940
+ readonly refresh: number;
2941
+ /**
2942
+ * Under a refreshing policy, when a value the entry holds next ages out and
2943
+ * what is due then. Time reaches Remote only as a Message: the entry sleeps
2944
+ * until then and emits `RefreshStarted`, which marks the fields stale, and
2945
+ * the plan that follows fetches them. A Model that does not change past its
2946
+ * `maxAge` is otherwise never looked at again.
2947
+ */
2948
+ readonly expires: Deadline | null;
2949
+ }
2950
+ declare const Remote: {
2951
+ /** The submodel's schema, the same for every domain; embed it in the application Model. */
2952
+ Model: Schema.Codec<RemoteModel, unknown, never, never>;
2953
+ /** The submodel's initial value. */
2954
+ initial: RemoteModel;
2955
+ /**
2956
+ * Remote's Message cases for `defineMessageUnion`: spread them into the
2957
+ * application's union, and reduce the ones `Remote.reduces` recognizes with
2958
+ * `RemoteDomain.reduce`.
2959
+ */
2960
+ messages: {
2961
+ ReadReceived: {
2962
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
2963
+ result: Schema.Struct<{
2964
+ readonly entities: Schema.$Array<Schema.Struct<{
2965
+ readonly entity: Schema.String;
2966
+ readonly id: Schema.String;
2967
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
2968
+ }>>;
2969
+ readonly settled: Schema.$Array<Schema.Struct<{
2970
+ readonly entity: Schema.String;
2971
+ readonly id: Schema.String;
2972
+ readonly fields: Schema.$Array<Schema.String>;
2973
+ }>>;
2974
+ }>;
2975
+ now: Schema.Number;
2976
+ };
2977
+ ReadFailed: {
2978
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
2979
+ error: Schema.Struct<{
2980
+ readonly _tag: Schema.String;
2981
+ readonly message: Schema.String;
2982
+ }>;
2983
+ stream: Schema.optional<Schema.String>;
2984
+ };
2985
+ RefreshStarted: {
2986
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
2987
+ };
2988
+ ReadStarted: {
2989
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
2990
+ refresh: Schema.optional<Schema.Number>;
2991
+ };
2992
+ QueryStarted: {
2993
+ connections: Schema.$Array<Schema.String>;
2994
+ };
2995
+ RetentionChanged: {
2996
+ roots: Schema.Struct<{
2997
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
2998
+ readonly connections: Schema.$Array<Schema.Struct<{
2999
+ readonly identity: Schema.String;
3000
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
3001
+ }>>;
3002
+ }>;
3003
+ };
3004
+ Hydrated: {
3005
+ connections: Schema.optional<Schema.Unknown>;
3006
+ entities: Schema.Unknown;
3007
+ merge: Schema.Union<readonly [Schema.Literal<"replace">, Schema.Literal<"preserve-existing">]>;
3008
+ };
3009
+ MutationStarted: {
3010
+ requestId: Schema.String;
3011
+ optimistic: Schema.optional<Schema.$Array<Schema.Unknown>>;
3012
+ };
3013
+ MutationSucceeded: {
3014
+ requestId: Schema.String;
3015
+ entities: Schema.$Array<Schema.Struct<{
3016
+ readonly entity: Schema.String;
3017
+ readonly id: Schema.String;
3018
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
3019
+ }>>;
3020
+ connections: Schema.optional<Schema.$Array<Schema.Unknown>>;
3021
+ deleted: Schema.optional<Schema.$Array<Schema.Struct<{
3022
+ readonly entity: Schema.String;
3023
+ readonly id: Schema.String;
3024
+ }>>>;
3025
+ now: Schema.Number;
3026
+ };
3027
+ MutationFailed: {
3028
+ requestId: Schema.String;
3029
+ error: Schema.Struct<{
3030
+ readonly _tag: Schema.String;
3031
+ readonly message: Schema.String;
3032
+ }>;
3033
+ };
3034
+ OverlayShown: {
3035
+ id: Schema.String;
3036
+ optimistic: Schema.$Array<Schema.Unknown>;
3037
+ };
3038
+ OverlayLifted: {
3039
+ id: Schema.String;
3040
+ };
3041
+ WindowGrown: {
3042
+ window: Schema.String;
3043
+ size: Schema.Number;
3044
+ };
3045
+ LiveReceived: {
3046
+ stream: Schema.String;
3047
+ event: Schema.Unknown;
3048
+ policy: Schema.optional<Schema.Unknown>;
3049
+ now: Schema.Number;
3050
+ };
3051
+ GapCleared: {
3052
+ stream: Schema.String;
3053
+ };
3054
+ ConnectionMerged: {
3055
+ connection: Schema.String;
3056
+ page: Schema.Unknown;
3057
+ refreshes: Schema.optional<Schema.Boolean>;
3058
+ select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
3059
+ entities: Schema.optional<Schema.$Array<Schema.Struct<{
3060
+ readonly entity: Schema.String;
3061
+ readonly id: Schema.String;
3062
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
3063
+ }>>>;
3064
+ settled: Schema.optional<Schema.$Array<Schema.Struct<{
3065
+ readonly entity: Schema.String;
3066
+ readonly id: Schema.String;
3067
+ readonly fields: Schema.$Array<Schema.String>;
3068
+ }>>>;
3069
+ now: Schema.optional<Schema.Number>;
3070
+ };
3071
+ ConnectionInvalidated: {
3072
+ connection: Schema.String;
3073
+ };
3074
+ ConnectionRefreshed: {
3075
+ connection: Schema.String;
3076
+ };
3077
+ QueryFailed: {
3078
+ connection: Schema.String;
3079
+ error: Schema.Struct<{
3080
+ readonly _tag: Schema.String;
3081
+ readonly message: Schema.String;
3082
+ }>;
3083
+ };
3084
+ };
3085
+ /** Whether a Message is one of Remote's, by tag. */
3086
+ reduces: <M extends {
3087
+ readonly _tag: string;
3088
+ }>(message: M) => message is Extract<M, {
3089
+ readonly _tag: RemoteMessageTag;
3090
+ }>;
3091
+ /**
3092
+ * Remote's Messages as one Schema, for a wrapper variant in the
3093
+ * application's union: `GotRemoteMessage: { message: Remote.Message }`. With
3094
+ * a wrapper, `update` matches the application's union exhaustively and
3095
+ * `Remote.fold` reduces what arrives inside it.
3096
+ */
3097
+ Message: import("foldkit/message").MessageUnion<{
3098
+ ReadReceived: {
3099
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
3100
+ result: Schema.Struct<{
3101
+ readonly entities: Schema.$Array<Schema.Struct<{
3102
+ readonly entity: Schema.String;
3103
+ readonly id: Schema.String;
3104
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
3105
+ }>>;
3106
+ readonly settled: Schema.$Array<Schema.Struct<{
3107
+ readonly entity: Schema.String;
3108
+ readonly id: Schema.String;
3109
+ readonly fields: Schema.$Array<Schema.String>;
3110
+ }>>;
3111
+ }>;
3112
+ now: Schema.Number;
3113
+ };
3114
+ ReadFailed: {
3115
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
3116
+ error: Schema.Struct<{
3117
+ readonly _tag: Schema.String;
3118
+ readonly message: Schema.String;
3119
+ }>;
3120
+ stream: Schema.optional<Schema.String>;
3121
+ };
3122
+ RefreshStarted: {
3123
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
3124
+ };
3125
+ ReadStarted: {
3126
+ requests: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
3127
+ refresh: Schema.optional<Schema.Number>;
3128
+ };
3129
+ QueryStarted: {
3130
+ connections: Schema.$Array<Schema.String>;
3131
+ };
3132
+ RetentionChanged: {
3133
+ roots: Schema.Struct<{
3134
+ readonly requirements: Schema.$Array<Schema.Codec<Requirement, Requirement, never, never>>;
3135
+ readonly connections: Schema.$Array<Schema.Struct<{
3136
+ readonly identity: Schema.String;
3137
+ readonly select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
3138
+ }>>;
3139
+ }>;
3140
+ };
3141
+ Hydrated: {
3142
+ connections: Schema.optional<Schema.Unknown>;
3143
+ entities: Schema.Unknown;
3144
+ merge: Schema.Union<readonly [Schema.Literal<"replace">, Schema.Literal<"preserve-existing">]>;
3145
+ };
3146
+ MutationStarted: {
3147
+ requestId: Schema.String;
3148
+ optimistic: Schema.optional<Schema.$Array<Schema.Unknown>>;
3149
+ };
3150
+ MutationSucceeded: {
3151
+ requestId: Schema.String;
3152
+ entities: Schema.$Array<Schema.Struct<{
3153
+ readonly entity: Schema.String;
3154
+ readonly id: Schema.String;
3155
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
3156
+ }>>;
3157
+ connections: Schema.optional<Schema.$Array<Schema.Unknown>>;
3158
+ deleted: Schema.optional<Schema.$Array<Schema.Struct<{
3159
+ readonly entity: Schema.String;
3160
+ readonly id: Schema.String;
3161
+ }>>>;
3162
+ now: Schema.Number;
3163
+ };
3164
+ MutationFailed: {
3165
+ requestId: Schema.String;
3166
+ error: Schema.Struct<{
3167
+ readonly _tag: Schema.String;
3168
+ readonly message: Schema.String;
3169
+ }>;
3170
+ };
3171
+ OverlayShown: {
3172
+ id: Schema.String;
3173
+ optimistic: Schema.$Array<Schema.Unknown>;
3174
+ };
3175
+ OverlayLifted: {
3176
+ id: Schema.String;
3177
+ };
3178
+ WindowGrown: {
3179
+ window: Schema.String;
3180
+ size: Schema.Number;
3181
+ };
3182
+ LiveReceived: {
3183
+ stream: Schema.String;
3184
+ event: Schema.Unknown;
3185
+ policy: Schema.optional<Schema.Unknown>;
3186
+ now: Schema.Number;
3187
+ };
3188
+ GapCleared: {
3189
+ stream: Schema.String;
3190
+ };
3191
+ ConnectionMerged: {
3192
+ connection: Schema.String;
3193
+ page: Schema.Unknown;
3194
+ refreshes: Schema.optional<Schema.Boolean>;
3195
+ select: Schema.optional<Schema.Codec<RelationRequirement, RelationRequirement, never, never>>;
3196
+ entities: Schema.optional<Schema.$Array<Schema.Struct<{
3197
+ readonly entity: Schema.String;
3198
+ readonly id: Schema.String;
3199
+ readonly values: Schema.$Record<Schema.String, Schema.Unknown>;
3200
+ }>>>;
3201
+ settled: Schema.optional<Schema.$Array<Schema.Struct<{
3202
+ readonly entity: Schema.String;
3203
+ readonly id: Schema.String;
3204
+ readonly fields: Schema.$Array<Schema.String>;
3205
+ }>>>;
3206
+ now: Schema.optional<Schema.Number>;
3207
+ };
3208
+ ConnectionInvalidated: {
3209
+ connection: Schema.String;
3210
+ };
3211
+ ConnectionRefreshed: {
3212
+ connection: Schema.String;
3213
+ };
3214
+ QueryFailed: {
3215
+ connection: Schema.String;
3216
+ error: Schema.Struct<{
3217
+ readonly _tag: Schema.String;
3218
+ readonly message: Schema.String;
3219
+ }>;
3220
+ };
3221
+ }>;
3222
+ /**
3223
+ * A bound domain under one wrapper variant of the application's union, the
3224
+ * same shape Foldkit gives a Submodel: `toParentMessage` wraps Remote's
3225
+ * Messages, the fold reduces them, and its `fetch`, `mutate`, and
3226
+ * `subscriptions` yield the wrapper. Spreading `Remote.messages` and
3227
+ * narrowing with `Remote.reduces` remains the shorter path for an
3228
+ * application whose `update` only reduces.
3229
+ *
3230
+ * @example
3231
+ * ```ts
3232
+ * const Message = defineMessageUnion({ GotRemoteMessage: { message: Remote.Message } })
3233
+ * const foldData = Remote.fold(Data, message => Message.GotRemoteMessage({ message }))
3234
+ *
3235
+ * const update = (model: Model, message: Message): Return =>
3236
+ * Message.match(message, {
3237
+ * GotRemoteMessage: ({ message }) => foldData(model, message),
3238
+ * })
3239
+ * const subscriptions = Subscription.make<Model, Message, RemoteClient>()(() =>
3240
+ * foldData.subscriptions({ page: Surface.at(ProjectPage, …) }),
3241
+ * )
3242
+ * ```
3243
+ */
3244
+ fold: <Domain extends RemoteDomain<any, any, any, any, any>, ParentMessage>(domain: Domain, toParentMessage: (message: RemoteMessage) => ParentMessage) => RemoteFold<ModelOfDomain<Domain>, ParentMessage, Domain>;
3245
+ /**
3246
+ * A patch of one entity's values, for a mutation's `optimistic` list or an
3247
+ * overlay. Takes a `foldkit-entity` Entity or a Remote descriptor alike, so
3248
+ * the domain you declared once is the one you patch:
3249
+ * `Remote.patch(Project, 'p1', { name: 'Apollo II' })`. Values are the
3250
+ * fields' wire shape, as the server writes them; a relation is its ref key
3251
+ * (`'User:u1'`).
3252
+ */
3253
+ patch: <E extends EntityLike>(entity: E, id: string, values: Partial<Schema.Struct.Encoded<FieldsOf<E>>>) => EntityPatch<NameOf<E>, FieldsOf<E>>;
3254
+ /**
3255
+ * A reference to one entity, for `ConnectionChange` and anything else that
3256
+ * names a row: `Remote.ref(Project, 'p3')`. Either kind of entity, as with
3257
+ * `Remote.patch`.
3258
+ */
3259
+ ref: <E extends EntityLike>(entity: E, id: string) => EntityRef<NameOf<E>, FieldsOf<E>>;
3260
+ /**
3261
+ * Declares a Remote domain and binds it to its place in the application Model
3262
+ * in one step; the result carries the application-facing operations. The
3263
+ * descriptor alone is `Remote.define`, the binding alone `Remote.at`.
3264
+ */
3265
+ make: <AppModel, Store extends RemoteModel, const Entities extends readonly EntityLike[], const Queries extends readonly QueryDescriptor<any, any, any>[] = readonly [], const Mutations extends readonly MutationDescriptor<any, any, any>[] = readonly []>(config: {
3266
+ readonly model: ModelRef<AppModel, Store>;
3267
+ readonly entities: Entities;
3268
+ readonly queries?: Queries;
3269
+ readonly mutations?: Mutations;
3270
+ }) => RemoteDomain<AppModel, Store, Entities, Queries, Mutations>;
3271
+ /**
3272
+ * Declares a Remote domain without binding it: its entities, queries, and
3273
+ * mutations, plus the submodel. For a domain reused across applications or
3274
+ * bound in a test; `Remote.make` is the one-step form.
3275
+ */
3276
+ define: <const Entities extends readonly EntityLike[], const Queries extends readonly QueryDescriptor<any, any, any>[] = readonly QueryDescriptor<any, any, any>[], const Mutations extends readonly MutationDescriptor<any, any, any>[] = readonly MutationDescriptor<any, any, any>[]>(config: {
3277
+ readonly entities: Entities;
3278
+ readonly queries?: Queries;
3279
+ readonly mutations?: Mutations;
3280
+ }) => RemoteDescriptor<Entities, Queries, Mutations>;
3281
+ /**
3282
+ * Binds a Remote domain to its store's location in the application Model. The
3283
+ * registered entity names are carried on the returned value, so `Remote.select`
3284
+ * rejects a selection for an entity this domain never declared.
3285
+ */
3286
+ at: <AppModel, Store extends RemoteModel, Entities extends readonly EntityLike[], Queries extends readonly QueryDescriptor<any, any, any>[], Mutations extends readonly MutationDescriptor<any, any, any>[]>(definition: RemoteDescriptor<Entities, Queries, Mutations>, store: ModelRef<AppModel, Store>) => BoundRemote<AppModel, Store, EntityName<Entities[number]>>;
3287
+ /**
3288
+ * The resume part for this domain, for `foldkit-ssr`'s `SSR.plan({ parts })`:
3289
+ * a server render sends what the plan's active Surfaces read from the store,
3290
+ * each connection with its boundaries and each live cursor with it, and
3291
+ * nothing else. `id` tells two domains in one application apart.
3292
+ */
3293
+ resume: <AppModel, Store extends RemoteModel>(domain: {
3294
+ readonly store: ModelRef<AppModel, Store>;
3295
+ }, options?: {
3296
+ readonly id?: string | undefined;
3297
+ }) => RemoteResumePart<AppModel>;
3298
+ /**
3299
+ * A Projection node that reads a `RemoteData` value out of the store. The id
3300
+ * is supplied by the caller, usually from a Surface's params. The assembled
3301
+ * value is decoded against the Selection, so malformed server data surfaces
3302
+ * as `Failed` instead of being asserted into `Value`. A present value with a
3303
+ * stale field reads as `Refreshing`: an observer is refetching it.
3304
+ */
3305
+ select: <AppModel, Store extends RemoteModel, Names extends string, Value, Name extends string>(bound: BoundRemote<AppModel, Store, Names>, given: EntitySelection<Value, Name> & Registered<Name, Names, "Entity">) => (id: string) => Projection<AppModel, RemoteData<Value>>;
3306
+ /**
3307
+ * When what a projection shows was last received, and whether it is stale
3308
+ * or loading. Pure, so a view can show "updated 5s ago" without I/O.
3309
+ *
3310
+ * `updatedAt` is the newest server write among what is shown, as the
3311
+ * store dates it; `undefined` when nothing shown was received (nothing
3312
+ * loaded, or only an optimistic preview). `stale` is any shown field or
3313
+ * connection marked stale; `loading` is any of them in flight. Optimistic
3314
+ * previews do not date: showing only one reads `updatedAt: undefined`.
3315
+ */
3316
+ meta: <AppModel, Store extends RemoteModel, Value>(bound: BoundRemote<AppModel, Store>, model: AppModel, projection: Projection<AppModel, Value>) => ReadMeta;
3317
+ /**
3318
+ * The pure plan for a projection against a Model: the requirements its
3319
+ * remote store does not satisfy, under `options` (freshness, force). A
3320
+ * Surface's projection is `surface.projection(params)`.
3321
+ */
3322
+ plan: <AppModel, Store extends RemoteModel, Value>(bound: BoundRemote<AppModel, Store>, model: AppModel, projection: Projection<AppModel, Value>, options?: PlanOptions) => ReadonlyArray<Requirement>;
3323
+ /**
3324
+ * The queries a projection needs run before its connections read: those the
3325
+ * Model does not hold, or holds stale (every one under `force`).
3326
+ */
3327
+ planQueries: <AppModel, Store extends RemoteModel, Value>(bound: BoundRemote<AppModel, Store>, model: AppModel, projection: Projection<AppModel, Value>, options?: PlanOptions) => ReadonlyArray<QueryRef<string, unknown>>;
3328
+ /**
3329
+ * The store reads see: the base store under the pending optimistic layers.
3330
+ * One store is shared by every read and plan of a Model whose remote state
3331
+ * has not changed.
3332
+ */
3333
+ storeOf: <AppModel, Store extends RemoteModel>(bound: BoundRemote<AppModel, Store>, model: AppModel) => EntityStore;
3334
+ /**
3335
+ * The projection read against the server-derived store alone: the same
3336
+ * requirements, planned the same way, with the pending optimistic layers and
3337
+ * connection overlays left off. See the bound `Remote.confirmed`.
3338
+ */
3339
+ confirmed: <AppModel, Store extends RemoteModel, P extends Projection<AppModel, any>>(bound: BoundRemote<AppModel, Store>, projection: P) => P;
3340
+ /**
3341
+ * Executes the plan against the `RemoteClient` and returns a new store. Used
3342
+ * for SSR route prefetch, hover prefetch, and tests. Never called during render.
3343
+ * `policy` decides what a present field means (default cache-first); `now`
3344
+ * is the clock it reads, so the planner itself stays pure and time-injected.
3345
+ */
3346
+ prefetch: <AppModel, Store extends RemoteModel, Value>(bound: BoundRemote<AppModel, Store, string>, model: AppModel, projection: Projection<AppModel, Value>, options?: ObserveOptions | undefined) => Effect.Effect<Readonly<Record<string, EntityEntry>>, RemoteReadError | RemoteProtocolError, RemoteClient>;
3347
+ /**
3348
+ * Marks what a projection, or a Surface without params, requires as due again.
3349
+ * Called from `update`: every selected field the store holds reads `Refreshing`,
3350
+ * and every loaded query connection is invalidated. Nothing is fetched here.
3351
+ * The read entries `Data.subscriptions` derives refetch it, because a stale
3352
+ * field or connection is planned again under every policy, so a refresh never
3353
+ * sends a request beside the entry already observing the same data.
3354
+ *
3355
+ * A refreshed connection's page replaces its pages, so items the server removed
3356
+ * or reordered follow it; pages loaded past the first are dropped and paged
3357
+ * again with `next`/`previous`. The read entries restart, so a read or query
3358
+ * sent before the refresh is not applied after it.
3359
+ *
3360
+ * It is also how a failed query is retried: a connection whose query failed
3361
+ * is not run again on its own, so its read stays `Failed` until this asks.
3362
+ *
3363
+ * The projection must be observed, which it is while it is on screen. Live
3364
+ * subscriptions are left as they are. For data nothing observes (SSR, tests),
3365
+ * use `Remote.prefetch` with `RemotePolicy.networkOnly`. Refreshing what is
3366
+ * already being refreshed returns the same Model.
3367
+ */
3368
+ refresh: <AppModel, Store extends RemoteModel>(bound: BoundRemote<AppModel, Store>, model: AppModel, target: Projection<AppModel, unknown> | Surface<AppModel, any, any, void>) => AppModel;
3369
+ /**
3370
+ * Forgets everything the server told this Model: values, tombstones,
3371
+ * unavailable fields, connections, live cursors, failures. What is known is
3372
+ * known for a principal, and this is the one boundary for a login, a logout
3373
+ * or a switch of organization: called from `update`, it performs no I/O, and
3374
+ * every active Surface's read and live entries restart, so the screen asks
3375
+ * again as whoever the client now is. A read or stream begun before is
3376
+ * interrupted rather than landing after. A mutation in flight is treated as
3377
+ * applied: its answer writes nothing here.
3378
+ */
3379
+ forget: <AppModel, Store extends RemoteModel>(bound: BoundRemote<AppModel, Store>, model: AppModel) => AppModel;
3380
+ /**
3381
+ * Writes a read result into the store, recording each field's applied window.
3382
+ * `requests` are the planned requirements the result answers.
3383
+ */
3384
+ writeRead: (store: EntityStore, requests: ReadonlyArray<Requirement>, result: Schema.Schema.Type<typeof ReadBatchResult>, now?: number) => EntityStore;
3385
+ /**
3386
+ * Adapts an Effect RPC client for `RemoteRpc` to `RemoteClient`, so an
3387
+ * application provides the transport's RPC layer instead of writing the
3388
+ * `LiveChange`-to-`LiveEvent` mapping by hand. The client `RpcClient.make`
3389
+ * builds is accepted as it is: when its transport fails (`RpcClientError`),
3390
+ * the call fails with its own Remote error, which the application shows and
3391
+ * retries like any failed read, query, mutation or live stream.
3392
+ */
3393
+ /**
3394
+ * Remote's client over any way of sending one JSON request and receiving its
3395
+ * answer, for `clientLayer`: a worker, a server in the page. `RemoteServer.answer`
3396
+ * is the other end.
3397
+ */
3398
+ json: (send: RemoteJsonSend) => RemoteRpcClient;
3399
+ /**
3400
+ * Remote's client over HTTP, for `clientLayer`: each call a `POST` of the JSON
3401
+ * request to `url`. `headers` is read per request (a session token, say).
3402
+ */
3403
+ http: (url: string, options?: {
3404
+ readonly headers?: () => Readonly<Record<string, string>>;
3405
+ }) => RemoteRpcClient;
3406
+ clientLayer: <R = never>(client: RemoteRpcClient<R, RpcClientError.RpcClientError>, options?: CoalesceOptions) => Layer.Layer<RemoteClient, never, R>;
3407
+ /**
3408
+ * Wraps a `RemoteClient` layer so its reads coalesce: requirements issued
3409
+ * together become one batch, and a requirement already in flight is joined.
3410
+ * `Remote.clientLayer` applies this; use it on a hand-written client.
3411
+ */
3412
+ coalesced: <E, R>(layer: Layer.Layer<RemoteClient, E, R>, options?: CoalesceOptions) => Layer.Layer<RemoteClient, E, R>;
3413
+ /**
3414
+ * A Foldkit Subscription entry that keeps the cache to what the active
3415
+ * Surfaces reach. `projections` are the ones the application observes (the
3416
+ * same it passes to `Remote.observe`), `connections` the query connections
3417
+ * it shows; anything else is collected once the roots have been stable for
3418
+ * `grace`, so a route transition that comes straight back does not thrash.
3419
+ */
3420
+ retain: <AppModel, Message = RemoteMessage>(projections: ReadonlyArray<Projection<AppModel, unknown>>, toMessage?: (message: RemoteMessage) => Message, options?: RetainOptions) => EntryWithoutKeepAlive<AppModel, Message, RetentionRoots, never>;
3421
+ /**
3422
+ * Runs a `Query` through `RemoteClient`, encoding its input from the ref.
3423
+ * Pair the result with `Remote.queryMessage` to merge the page into the Model.
3424
+ * With `select`, the server also returns the selected fields of the page's
3425
+ * items, so one response populates both the connection and the store.
3426
+ */
3427
+ query: <Name extends string, Input>(ref: QueryRef<Name, Input>, select?: RelationRequirement | undefined) => Effect.Effect<{
3428
+ readonly edges: readonly {
3429
+ readonly entity: string;
3430
+ readonly id: string;
3431
+ readonly key: string;
3432
+ }[];
3433
+ readonly start: {
3434
+ readonly _tag: "Terminal";
3435
+ } | {
3436
+ readonly _tag: "Cursor";
3437
+ readonly cursor: string;
3438
+ } | {
3439
+ readonly _tag: "Unknown";
3440
+ };
3441
+ readonly end: {
3442
+ readonly _tag: "Terminal";
3443
+ } | {
3444
+ readonly _tag: "Cursor";
3445
+ readonly cursor: string;
3446
+ } | {
3447
+ readonly _tag: "Unknown";
3448
+ };
3449
+ readonly entities?: readonly {
3450
+ readonly entity: string;
3451
+ readonly id: string;
3452
+ readonly values: {
3453
+ readonly [x: string]: unknown;
3454
+ };
3455
+ }[] | undefined;
3456
+ readonly settled?: readonly {
3457
+ readonly entity: string;
3458
+ readonly id: string;
3459
+ readonly fields: readonly string[];
3460
+ }[] | undefined;
3461
+ }, RemoteQueryError, RemoteClient>;
3462
+ /** The `RemoteMessage` that merges a query page into its connection. */
3463
+ queryMessage: <Name extends string, Input>(ref: QueryRef<Name, Input>, result: Schema.Schema.Type<typeof QueryResult>, select?: RelationRequirement | undefined, now?: number | undefined) => RemoteMessage;
3464
+ /**
3465
+ * The edges a connection shows: its server-known region with pending and
3466
+ * confirmed overlays placed around it, minus removed edges and edges whose
3467
+ * target is a tombstone.
3468
+ */
3469
+ visibleItems: (model: RemoteModel, connection: ConnectionIdentity) => ReadonlyArray<Edge>;
3470
+ /** A pure, serializable view of the whole cache. */
3471
+ inspect: (model: RemoteModel) => RemoteInspection;
3472
+ /** A pure, serializable view of one entity, or `undefined` if unknown. */
3473
+ inspectEntity: (model: RemoteModel, key: string) => RemoteInspection["entities"][number] | undefined;
3474
+ /**
3475
+ * Runs a mutation through `RemoteClient`, decoding its typed Output and
3476
+ * returning the result's normalized patches so the caller can reconcile them
3477
+ * through `updateRemote`'s `MutationSucceeded` (or `Remote.mutateInto`).
3478
+ */
3479
+ mutate: <Name extends string, Input, Output>(mutation: MutationDescriptor<Name, Input, Output>, input: Input, requestId: string) => Effect.Effect<{
3480
+ output: Output;
3481
+ entities: readonly {
3482
+ readonly entity: string;
3483
+ readonly id: string;
3484
+ readonly values: {
3485
+ readonly [x: string]: unknown;
3486
+ };
3487
+ }[];
3488
+ connections: ConnectionChange[];
3489
+ deleted: readonly {
3490
+ readonly entity: string;
3491
+ readonly id: string;
3492
+ }[];
3493
+ }, RemoteMutationError, RemoteClient>;
3494
+ /**
3495
+ * Runs a mutation and reconciles its patches into a `RemoteModel` in one step,
3496
+ * returning the new model alongside the typed Output. The model-level form of
3497
+ * `MutationStarted` → `RemoteClient.mutate` → `MutationSucceeded`; in an
3498
+ * application the three are `update` (with `optimistic`), a Command, and the
3499
+ * Message the Command returns, so the optimistic operations show meanwhile.
3500
+ */
3501
+ mutateInto: <Name extends string, Input, Output, AppModel, Store extends RemoteModel>(bound: BoundRemote<AppModel, Store, string>, model: AppModel, mutation: MutationDescriptor<Name, Input, Output>, input: Input, requestId: string, options?: MutateOptions | undefined) => Effect.Effect<{
3502
+ output: Output;
3503
+ model: AppModel;
3504
+ }, RemoteMutationError, RemoteClient>;
3505
+ /**
3506
+ * A Foldkit Subscription entry that plans a Surface's missing fields from the
3507
+ * Model and fetches them through `RemoteClient`, emitting a `RemoteMessage`
3508
+ * per outcome. Wrap it in an application Message (`toMessage`) and reduce it
3509
+ * with the domain's `update`. Under a refreshing `policy` the entry first
3510
+ * emits `RefreshStarted`, so the fields being refetched read as `Refreshing`
3511
+ * while the request is pending.
3512
+ */
3513
+ observe: <AppModel, Store extends RemoteModel, Names extends string, Model, SurfaceMessage, Params, Message = RemoteMessage>(bound: BoundRemote<AppModel, Store, Names>, surface: Surface<AppModel, Model, SurfaceMessage, Params>, params: Params, toMessage?: (message: RemoteMessage) => Message, options?: ObserveOptions) => EntryWithoutKeepAlive<AppModel, Message, ReadDependencies, RemoteClient>;
3514
+ /**
3515
+ * A Foldkit Subscription entry that consumes the live stream for a Surface's
3516
+ * requirements, emitting a `LiveReceived` per event and a `ReadFailed`
3517
+ * carrying its `stream` when the stream breaks (including
3518
+ * `ResumeUnavailable`). That records a gap on the stream rather than a failed
3519
+ * read, since nothing was being read. The resume cursor is read
3520
+ * from `RemoteModel.live`, so the application tracks no cursor of its own.
3521
+ */
3522
+ live: <AppModel, Store extends RemoteModel, Names extends string, Model, SurfaceMessage, Params, Message = RemoteMessage>(bound: BoundRemote<AppModel, Store, Names>, surface: Surface<AppModel, Model, SurfaceMessage, Params>, params: Params, toMessage?: (message: RemoteMessage) => Message, options?: LiveOptions) => EntryWithoutKeepAlive<AppModel, Message, LiveDependencies, RemoteClient>;
3523
+ };
3524
+ //#endregion
3525
+ export { Entity$2 as $, isGapped as $i, Snapshot as $n, ResultOf as $r, failureOf as $t, SelectsEntity as A, readField as Ai, PageSize as An, pruneOverlays as Ar, RemoteJsonRequest as At, ExplainedDependencies as B, remoteDataSchema as Bi, RelationRequest as Bn, RemoteRequirements as Br, CoalesceOptions as Bt, RemoteDomain as C, entry as Ci, LiveRequirement as Cn, OptimisticOperation as Cr, isRefPage as Ct, RemoteWiring as D, isTombstone as Di, MutationRequest as Dn, beginOptimistic as Dr, relationShape as Dt, RemoteUnsatisfied as E, isFieldUnavailable as Ei, Mutate as En, addOverlay as Er, relationAlias as Et, PlanFreshness as F, writeEntities as Fi, REMOTE_PROTOCOL_VERSION as Fn, visibleItems as Fr, connectionChangeOf as Ft, inspectRemote as G, Edge as Gi, RemoteReadError as Gn, IDENTITY_SEPARATOR as Gr, RemoteResumePart as Gt, ReadDiagnosis as H, Boundary as Hi, RemoteMutationError as Hn, connectionsOf as Hr, coalesceQueries as Ht, PlanOptions as I, writeEntity as Ii, Read as In, visibleStore as Ir, liveEventOf as It, Matched as J, cursor as Ji, WindowSchema as Jn, Query$1 as Jr, RemoteMessage as Jt, Belongs as K, EdgeRef as Ki, RemoteRpc as Kn, LiveInsertion as Kr, Failures as Kt, deadlineOf as L, Freshness as Li, ReadBatch as Ln, ConnectionRequirement as Lr, mutateRemote as Lt, SubscriptionsOptions as M, setStale as Mi, QueryRequest as Mn, removeOverlay as Mr, RemoteClient as Mt, RemotePolicy as N, setUnavailable as Ni, QueryResult as Nn, settleFailure as Nr, RemoteRpcClient as Nt, RetainOptions as O, markStale as Oi, MutationResult as On, connectionIdentity as Or, targetsOf as Ot, Deadline as P, tombstone as Pi, QueryRpc as Pn, settleSuccess as Pr, coalescedLayer as Pt, AnySchema as Q, hasPrevious as Qi, RemotePersistence as Qn, QueryWindow as Qr, emptyRefresh as Qt, plan as R, RemoteData as Ri, ReadBatchResult as Rn, RelationRequirement as Rr, remoteError as Rt, RemoteDescriptor as S, entityKey as Si, LiveEdge as Sn, EntityLayer as Sr, aliasedField as St, RemoteFold as T, isFieldStale as Ti, MAX_RELATION_DEPTH as Tn, addLayer as Tr, refsIn as Tt, RemoteInspection as U, Connection as Ui, RemoteProtocolError as Un, requirementsOf as Ur, coalesceReads as Ut, QueryExplanation as V, remoteErrorSchema as Vi, RemoteLiveError as Vn, Requirement as Vr, QueryRun as Vt, inspectEntity as W, Cursor as Wi, RemoteQueryError as Wn, ConnectionSpec as Wr, requirementKey as Wt, belongsEncoded as X, emptyConnection as Xi, MergePolicy as Xn, QueryInputs as Xr, RemoteMessageTag as Xt, MatchingOptions as Y, edge as Yi, WireBoundary as Yn, QueryDescriptor as Yr, RemoteMessageInput as Yt, matching as Z, hasNext as Zi, REMOTE_CACHE_VERSION as Zn, QueryRef as Zr, RemoteModel as Zt, QueryWindowOptions as _, EntityKey as _i, withRefreshRequested as _n, liveHasNext as _r, RefParts as _t, FoldedMutationStarted as a, MutationStatus as ai, isQueryLoading as an, reachable as ar, RefPage as at, Registered as b, clearStale as bi, Live as bn, ConnectionIdentity as br, RelationKind as bt, ModelOfDomain as c, SchemaOrFields as ci, onlyOverlaid as cn, EntityApplied as cr, SelectionOf as ct, ObserveOptions as d, emptyMutationState as di, remoteMessageCases as dn, LiveOutcome as dr, assemble as dt, items as ea, stableStringify as ei, forgetRemote as en, SnapshotOptions as er, EntityDescriptor as et, QueryEntity as f, failMutation as fi, remoteMessageSchema as fn, LiveState as fr, pageSchema as ft, QueryRequirement as g, EntityEntry as gi, windowGrowthKey as gn, emptyLiveState as gr, RefPageValue as gt, QueryProjection as h, schemaOf as hi, updateRemote as hn, classifyLive as hr, RELATION_ALIAS as ht, EntitySelection as i, unknown as ia, MutationState as ii, isLoadingThrough as in, gc as ir, RefKey as it, SubscriptionEntries as j, remove as ji, QueryEdge as jn, removeLayer as jr, RemoteJsonSend as jt, SatisfyOptions as k, missingFields as ki, NormalizedEntity as kn, emptyOptimistic as kr, RemoteJsonAnswer as kt, MutateOptions as l, TypeOf as li, refreshIsInFlight as ln, LiveCursor as lr, SelectionValue as lt, QueryOptions as m, reconcileMutation as mi, retentionRootsSchema as mn, applyEntityEvent as mr, unavailableOf as mt, DomainMutateOptions as n, segment as na, MutationAnswer as ni, isFieldFailed as nn, Retained as nr, EntityRef as nt, LiveDependencies as o, NormalizedPatch as oi, isRemoteMessage as on, BoundaryCounts as or, Page as ot, QueryInput as p, mutationStatus as pi, remoteModelSchema as pn, applyConnectionEvent as pr, relationOf as pt, Judged as q, Segment as qi, SettledFields as qn, LivePolicy as qr, RefreshState as qt, EntityLike as r, terminal as ra, MutationDescriptor as ri, isLoading as rn, RetentionRoots as rr, FieldsFrom as rt, LiveOptions as s, Reconciled as si, noFailures as sn, ConnectionApplied as sr, Selection as st, BoundRemote as t, merge as ta, Mutation as ti, initialRemoteModel as tn, ConnectionRoot as tr, EntityPatch as tt, MutationStarted as u, beginMutation as ui, refreshedAt as un, LiveEvent as ur, SelectionValueOf as ut, ReadDependencies as v, EntityStore as vi, writeRead as vn, liveHasPrevious as vr, RelationAnnotation as vt, RemoteEntry as w, hasField as wi, MAX_FIELDS_PER_REQUEST as wn, OptimisticState as wr, refParts as wt, Remote as x, emptyStore as xi, LiveChange as xn, ConnectionOverlay as xr, RelationShape as xt, ReadMeta as y, EntityWrite as yi, ConnectionChangeSchema as yn, ConnectionChange as yr, RelationEntityAnnotation as yt, windowKey as z, RemoteError as zi, ReadRequest as zn, RemoteConnections as zr, BatchRead as zt };
3526
+ //# sourceMappingURL=index-njA5CxbS.d.mts.map