foldkit-remote 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +987 -198
- package/dist/answerGaps.d.ts +16 -0
- package/dist/answerGaps.d.ts.map +1 -0
- package/dist/answerGaps.js +60 -0
- package/dist/answerGaps.js.map +1 -0
- package/dist/client-B055kQuP.d.ts +110 -0
- package/dist/client-B055kQuP.d.ts.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +142 -0
- package/dist/client.js.map +1 -0
- package/dist/coalesce-CLAr92Nk.d.ts +34 -0
- package/dist/coalesce-CLAr92Nk.d.ts.map +1 -0
- package/dist/coalesce.d.ts +2 -0
- package/dist/coalesce.js +131 -0
- package/dist/coalesce.js.map +1 -0
- package/dist/connection-BRyaJy89.d.ts +45 -0
- package/dist/connection-BRyaJy89.d.ts.map +1 -0
- package/dist/connection.d.ts +2 -0
- package/dist/connection.js +170 -0
- package/dist/connection.js.map +1 -0
- package/dist/data.d.ts +7 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +21 -0
- package/dist/data.js.map +1 -0
- package/dist/diagnostics-DHhVYflV.d.ts +125 -0
- package/dist/diagnostics-DHhVYflV.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +60 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/entity-CgsG5Uel.d.ts +196 -0
- package/dist/entity-CgsG5Uel.d.ts.map +1 -0
- package/dist/entity-DuDxaa3n.js +279 -0
- package/dist/entity-DuDxaa3n.js.map +1 -0
- package/dist/entity.d.ts +2 -0
- package/dist/entity.js +1 -0
- package/dist/held.d.ts +19 -0
- package/dist/held.d.ts.map +1 -0
- package/dist/held.js +70 -0
- package/dist/held.js.map +1 -0
- package/dist/impact.d.ts +79 -0
- package/dist/impact.d.ts.map +1 -0
- package/dist/impact.js +166 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +1542 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2791 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect-DtRQGCRP.d.ts +134 -0
- package/dist/inspect-DtRQGCRP.d.ts.map +1 -0
- package/dist/inspect.d.ts +2 -0
- package/dist/inspect.js +33 -0
- package/dist/inspect.js.map +1 -0
- package/dist/json-DowLl1eB.d.ts +52 -0
- package/dist/json-DowLl1eB.d.ts.map +1 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +123 -0
- package/dist/json.js.map +1 -0
- package/dist/law.d.ts +56 -0
- package/dist/law.d.ts.map +1 -0
- package/dist/law.js +201 -0
- package/dist/law.js.map +1 -0
- package/dist/live-BpTzlCnY.d.ts +79 -0
- package/dist/live-BpTzlCnY.d.ts.map +1 -0
- package/dist/live.d.ts +2 -0
- package/dist/live.js +126 -0
- package/dist/live.js.map +1 -0
- package/dist/matching-DF5F9Us8.d.ts +100 -0
- package/dist/matching-DF5F9Us8.d.ts.map +1 -0
- package/dist/matching.d.ts +2 -0
- package/dist/matching.js +172 -0
- package/dist/matching.js.map +1 -0
- package/dist/model-B6zk1NMB.d.ts +710 -0
- package/dist/model-B6zk1NMB.d.ts.map +1 -0
- package/dist/model.d.ts +2 -0
- package/dist/model.js +1308 -0
- package/dist/model.js.map +1 -0
- package/dist/mutation.d.ts +2 -0
- package/dist/mutation.js +612 -0
- package/dist/mutation.js.map +1 -0
- package/dist/optimistic-CECsfNGY.d.ts +523 -0
- package/dist/optimistic-CECsfNGY.d.ts.map +1 -0
- package/dist/optimistic.d.ts +2 -0
- package/dist/optimistic.js +336 -0
- package/dist/optimistic.js.map +1 -0
- package/dist/outbox-DNuc4kZp.d.ts +259 -0
- package/dist/outbox-DNuc4kZp.d.ts.map +1 -0
- package/dist/outbox.d.ts +2 -0
- package/dist/outbox.js +326 -0
- package/dist/outbox.js.map +1 -0
- package/dist/patchValues.d.ts +10 -0
- package/dist/patchValues.d.ts.map +1 -0
- package/dist/patchValues.js +57 -0
- package/dist/patchValues.js.map +1 -0
- package/dist/persistence-CCMnvg7-.d.ts +114 -0
- package/dist/persistence-CCMnvg7-.d.ts.map +1 -0
- package/dist/persistence.d.ts +2 -0
- package/dist/persistence.js +205 -0
- package/dist/persistence.js.map +1 -0
- package/dist/placement-jZdsIpmj.d.ts +50 -0
- package/dist/placement-jZdsIpmj.d.ts.map +1 -0
- package/dist/placement.d.ts +2 -0
- package/dist/placement.js +116 -0
- package/dist/placement.js.map +1 -0
- package/dist/plan-D9cftxC_.d.ts +35 -0
- package/dist/plan-D9cftxC_.d.ts.map +1 -0
- package/dist/plan.d.ts +2 -0
- package/dist/plan.js +100 -0
- package/dist/plan.js.map +1 -0
- package/dist/policy-DsWHmIAq.d.ts +42 -0
- package/dist/policy-DsWHmIAq.d.ts.map +1 -0
- package/dist/policy.d.ts +2 -0
- package/dist/policy.js +32 -0
- package/dist/policy.js.map +1 -0
- package/dist/{port.d.mts → port.d.ts} +3 -2
- package/dist/port.d.ts.map +1 -0
- package/dist/{port.mjs → port.js} +3 -2
- package/dist/port.js.map +1 -0
- package/dist/query-BuIU93xA.d.ts +141 -0
- package/dist/query-BuIU93xA.d.ts.map +1 -0
- package/dist/query.d.ts +2 -0
- package/dist/query.js +0 -0
- package/dist/query.js.map +1 -0
- package/dist/record.d.ts +11 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +21 -0
- package/dist/record.js.map +1 -0
- package/dist/relation-BLBGOZom.d.ts +59 -0
- package/dist/relation-BLBGOZom.d.ts.map +1 -0
- package/dist/relation.d.ts +2 -0
- package/dist/relation.js +93 -0
- package/dist/relation.js.map +1 -0
- package/dist/remoteData-mK1suYi1.d.ts +148 -0
- package/dist/remoteData-mK1suYi1.d.ts.map +1 -0
- package/dist/remoteData.d.ts +2 -0
- package/dist/remoteData.js +179 -0
- package/dist/remoteData.js.map +1 -0
- package/dist/reporting.d.ts +12 -0
- package/dist/reporting.d.ts.map +1 -0
- package/dist/reporting.js +45 -0
- package/dist/reporting.js.map +1 -0
- package/dist/requirement-D57S2LpH.d.ts +64 -0
- package/dist/requirement-D57S2LpH.d.ts.map +1 -0
- package/dist/requirement.d.ts +2 -0
- package/dist/requirement.js +114 -0
- package/dist/requirement.js.map +1 -0
- package/dist/resume-Ct5R6yli.d.ts +92 -0
- package/dist/resume-Ct5R6yli.d.ts.map +1 -0
- package/dist/resume.d.ts +2 -0
- package/dist/resume.js +222 -0
- package/dist/resume.js.map +1 -0
- package/dist/retain-BfNTvBRb.d.ts +48 -0
- package/dist/retain-BfNTvBRb.d.ts.map +1 -0
- package/dist/retain.d.ts +2 -0
- package/dist/retain.js +107 -0
- package/dist/retain.js.map +1 -0
- package/dist/selection.d.ts +2 -0
- package/dist/selection.js +1 -0
- package/dist/shown.d.ts +20 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +40 -0
- package/dist/shown.js.map +1 -0
- package/dist/sse-C7LhdbiQ.d.ts +17 -0
- package/dist/sse-C7LhdbiQ.d.ts.map +1 -0
- package/dist/sse.d.ts +2 -0
- package/dist/sse.js +127 -0
- package/dist/sse.js.map +1 -0
- package/dist/store-ah2qjcJW.d.ts +100 -0
- package/dist/store-ah2qjcJW.d.ts.map +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +218 -0
- package/dist/store.js.map +1 -0
- package/dist/testing.d.ts +133 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +0 -0
- package/dist/testing.js.map +1 -0
- package/dist/why-kgp_Wr3z.d.ts +483 -0
- package/dist/why-kgp_Wr3z.d.ts.map +1 -0
- package/dist/why.d.ts +2 -0
- package/dist/why.js +293 -0
- package/dist/why.js.map +1 -0
- package/dist/whyReasons.d.ts +42 -0
- package/dist/whyReasons.d.ts.map +1 -0
- package/dist/whyReasons.js +211 -0
- package/dist/whyReasons.js.map +1 -0
- package/dist/wire-DthPcTM6.d.ts +787 -0
- package/dist/wire-DthPcTM6.d.ts.map +1 -0
- package/dist/wire.d.ts +2 -0
- package/dist/wire.js +329 -0
- package/dist/wire.js.map +1 -0
- package/package.json +19 -14
- package/dist/index-BEvVAL76.d.mts +0 -4097
- package/dist/index-BEvVAL76.d.mts.map +0 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/port.d.mts.map +0 -1
- package/dist/port.mjs.map +0 -1
- package/dist/src-BDqn7Ocr.mjs +0 -6344
- package/dist/src-BDqn7Ocr.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":["storeEntry","unknownBoundary"],"sources":["../src/model.ts"],"sourcesContent":["/**\n * The Remote submodel: the store, connections, mutations, live state, and\n * optimistic layers an application keeps in its Model, the Messages that\n * change it, and the pure reducer over them.\n */\nimport { Option, Schema } from 'effect'\nimport {\n liveRefused,\n outboxUnreadable,\n outboxUnsaved,\n PredictionPart,\n predictionMismatch,\n withDiagnostics,\n type RemoteDiagnostic,\n} from './diagnostics.js'\nimport type { RelationRequirement, Requirement } from './requirement.js'\nimport {\n emptyConnection,\n merge,\n unknown as unknownBoundary,\n type Boundary,\n type Connection,\n type Edge,\n type Segment,\n} from './connection.js'\nimport {\n beginOptimistic,\n emptyOptimistic,\n pruneOverlays,\n settleFailure,\n settleSuccess,\n type ConnectionChange,\n type OptimisticState,\n type OptimisticOperation,\n} from './optimistic.js'\nimport {\n applyConnectionEvent,\n applyEntityEvent,\n emptyLiveState,\n type LiveEvent,\n type LiveState,\n} from './live.js'\nimport {\n beginMutation,\n emptyMutationState,\n failMutation,\n forgetFailure,\n settledLater,\n type MutationState,\n type NormalizedPatch,\n} from './mutation.js'\nimport {\n emptyOutbox,\n operationOf,\n Queued,\n revisionOf,\n withDone,\n type OutboxState,\n type ReadEntry,\n type StoredWrite,\n} from './outbox.js'\nimport {\n askAgain,\n entityKey,\n entry as storeEntry,\n emptyStore,\n isTombstone,\n readField,\n remove,\n setStale,\n setUnavailable,\n tombstone,\n writeEntities,\n type EntityStore,\n type EntityWrite,\n} from './store.js'\nimport { windowKey } from './plan.js'\nimport { isRefPage, targetsOf, type RefPageValue } from './relation.js'\nimport { gc, reachable, recentRoots, type Retained, type RetentionRoots } from './retain.js'\nimport { RemotePersistence, type MergePolicy } from './persistence.js'\nimport {\n AnswerRead,\n NormalizedEntity,\n ReadBatchResult,\n ReadRequest,\n RelationRequest,\n SettledFields,\n type RemoteLiveRefused,\n} from './wire.js'\nimport { put } from './record.js'\nimport { remoteErrorSchema, type RemoteError } from './remoteData.js'\nimport type { LivePolicy } from './query.js'\n\n/**\n * The normalized cache as a Foldkit Submodel. `Remote.define` returns a schema\n * and an `update` for this shape; `updateRemote` reconciles every producer.\n */\nexport interface RemoteModel {\n /** Entity values, presence, staleness, tombstones, and applied windows. */\n readonly entities: EntityStore\n /** Normalized ordered connections, keyed by connection identity. */\n readonly connections: Readonly<Record<string, Connection>>\n /**\n * How many rows `Data.more` has grown a read's window to, by\n * `windowGrowthKey`. A read shows at most its window, so this is what \"load\n * more\" changes; it lives here because a list holds no state of its own.\n */\n readonly grown: Readonly<Record<string, number>>\n /** Optimistic entity layers and connection overlays over the base store. */\n readonly optimistic: OptimisticState\n /** Live cursor and boundary state, keyed by the subscription's stream key. */\n readonly live: Readonly<Record<string, LiveState>>\n /** Mutation pending/applied/failed ledger. */\n readonly mutations: MutationState\n /**\n * The durable writes (`Data.mutate`'s `durable`) not yet settled, every\n * tab's, in the order the outbox sends them, and what its store holds.\n * Each is in `mutations` too, as any write is.\n */\n readonly outbox: OutboxState\n /**\n * Streams that broke, by an error or by an event ahead of their cursor, and\n * have not resubscribed since: changes after the break are missed until the\n * live entry restarts them and refetches what they cover.\n */\n readonly gaps: ReadonlySet<string>\n /** Each live stream that has ever broken, by stream key. One that never broke is absent. */\n readonly streams: Readonly<Record<string, StreamHealth>>\n /**\n * The `entity\\0id\\0field` marks a read is currently fetching. A field absent\n * from the store reads as `Loading` while its mark is here and `Initial`\n * otherwise, which is what separates \"being fetched\" from \"nothing is\n * fetching this\".\n */\n readonly loading: ReadonlySet<string>\n /**\n * `Remote.refresh` generations, held per field rather than for the store as a\n * whole. A read entry restarts when the generation over the fields it plans\n * moves, so a read sent before a refresh of its own fields cannot land after\n * it, and a refresh of one field leaves every other entry's read alone.\n */\n readonly refresh: RefreshState\n /**\n * The reads that failed and have not been settled since, so a read can say\n * `Failed` rather than `Initial`.\n *\n * Without them a read that failed before anything loaded read exactly like\n * one nobody had asked for, and nothing asked again: a read entry restarts\n * only when what it plans changes, and a failure changed nothing. What failed\n * is not planned again on its own either, so a persistent error is not\n * retried every time an unrelated read restarts the entry. `Remote.refresh`\n * is how a view retries.\n */\n readonly failures: Failures\n /**\n * The storage key the cache was last restored from, through `Hydrated`'s\n * `from`. `Data.persistence` saves under a key only once its own snapshot is\n * in, so a save at startup cannot write the empty store over it, and\n * restores only a key the Model is not yet restored from.\n */\n readonly restoredFrom: Option.Option<string>\n /**\n * Under `verifyPredictions`, the order each list was placed in, by edge key,\n * and the rows placing took out of its first page, until the server's page\n * for it arrives to be compared with them.\n */\n readonly placed: Readonly<Record<string, PlacedOrder>>\n /**\n * What the client met and kept going past, oldest first: under\n * `verifyPredictions` each part of a prediction the server's answer\n * disagreed with, and each failed write the application's update does not\n * hear. The newest\n * 256 are kept; the wiring reports each as it is recorded.\n */\n readonly diagnostics: ReadonlyArray<RemoteDiagnostic>\n /**\n * What retention keeps: the active Surfaces' roots, after those of the\n * Surfaces most recently left (`departedLimit`). A list left is held stale,\n * so going back reads it `Refreshing` while it refetches.\n */\n readonly recent: RetentionRoots\n}\n\n/** A list's first page as the client placed it: its keys in order, and those it took out. */\nexport interface PlacedOrder {\n readonly order: ReadonlyArray<string>\n readonly dropped: ReadonlyArray<string>\n}\n\n/** How a live stream has fared, as its live entry restarts it. */\nexport interface StreamHealth {\n /** How many times it broke. The live entry restarts on each, so it only grows. */\n readonly restarts: number\n /** Breaks since its last applied event: what the restart's backoff grows with. */\n readonly failures: number\n /** Why it last broke; none for a gap, which is not an error. */\n readonly error: Option.Option<RemoteError>\n /**\n * The server's refusal of what it asks (`RemoteLiveRefused`). A refused\n * stream is no gap and does not restart: asking again is refused again.\n */\n readonly refused: Option.Option<RemoteError>\n}\n\n/**\n * Failed reads, as the errors they failed with.\n *\n * `connections` is by connection identity, and is settled by a page arriving,\n * an invalidation, or retention dropping the connection. `fields` is by field\n * mark (`entity\\0id\\0field`, the marks `loading` uses), and is settled by the\n * field being written again, a refresh asking for it, or retention dropping the\n * entity. A read of it in flight reads `Loading` over the failure without\n * settling it: if that read fails too, the failure is simply recorded again.\n */\nexport interface Failures {\n readonly connections: Readonly<Record<string, RemoteError>>\n readonly fields: Readonly<Record<string, RemoteError>>\n}\n\nexport const noFailures: Failures = { connections: {}, fields: {} }\n\n/**\n * `Remote.refresh` generations, per field mark. `generation` is the last one\n * handed out; `requested` is when each field was last refreshed, and `started`\n * is the generation each field's read last began under. Holding them per field\n * is what keeps one Projection's refresh from restarting every read entry.\n */\nexport interface RefreshState {\n readonly generation: number\n readonly requested: ReadonlyMap<string, number>\n readonly started: ReadonlyMap<string, number>\n /**\n * The generation every entry is refreshed at, at least: `forgetRemote` moves\n * it, so every read and live entry restarts, and a read or stream begun for\n * the principal before is interrupted rather than landing after.\n */\n readonly floor: number\n}\n\nexport const emptyRefresh: RefreshState = {\n generation: 0,\n requested: new Map(),\n started: new Map(),\n floor: 0,\n}\n\n/**\n * The Model with everything the server told it forgotten: values, tombstones,\n * unavailable fields, connections, live cursors, failures, and what is in\n * flight. For a change of principal, whose facts these were. The mutation\n * sequence is kept, so request ids stay unique, and a mutation in flight is\n * treated as applied: its answer, when it comes, writes nothing here.\n *\n * `restoredFrom` is kept too: the emptied store is now what that key holds,\n * so `Data.persistence` saves it over the old snapshot and never restores the\n * key again. Restoring would bring back exactly what was forgotten.\n */\nexport const forgetRemote = (model: RemoteModel): RemoteModel => {\n const generation = model.refresh.generation + 1\n return {\n ...initialRemoteModel,\n restoredFrom: model.restoredFrom,\n refresh: { generation, requested: new Map(), started: new Map(), floor: generation },\n mutations: {\n ...emptyMutationState,\n sequence: model.mutations.sequence,\n applied: new Set([...model.mutations.applied, ...model.mutations.pending]),\n },\n // The writes stay in their own key's store, for that principal's return.\n // The session is this page's, and keeps naming its operations.\n outbox: { ...emptyOutbox, session: model.outbox.session },\n }\n}\n\nexport const initialRemoteModel: RemoteModel = {\n entities: emptyStore,\n connections: {},\n grown: {},\n optimistic: emptyOptimistic,\n live: {},\n mutations: emptyMutationState,\n outbox: emptyOutbox,\n gaps: new Set(),\n streams: {},\n loading: new Set(),\n refresh: emptyRefresh,\n failures: noFailures,\n restoredFrom: Option.none(),\n placed: {},\n diagnostics: [],\n recent: { requirements: [], connections: [] },\n}\n\n/** The entity store and the mutation ledger are runtime values, not wire shapes. */\nconst runtimeSchema = Schema.Unknown\n\nexport const remoteModelSchema = (): Schema.Codec<RemoteModel, unknown> =>\n // The runtime fields decode as `unknown`; their types come from `RemoteModel`.\n Schema.Struct({\n entities: runtimeSchema,\n connections: Schema.Record(Schema.String, runtimeSchema),\n grown: Schema.Record(Schema.String, Schema.Number),\n optimistic: runtimeSchema,\n live: Schema.Record(Schema.String, runtimeSchema),\n mutations: runtimeSchema,\n outbox: runtimeSchema,\n gaps: runtimeSchema,\n streams: Schema.Record(Schema.String, runtimeSchema),\n loading: runtimeSchema,\n refresh: runtimeSchema,\n failures: Schema.Struct({\n connections: Schema.Record(Schema.String, remoteErrorSchema),\n fields: Schema.Record(Schema.String, remoteErrorSchema),\n }),\n restoredFrom: runtimeSchema,\n placed: runtimeSchema,\n diagnostics: runtimeSchema,\n recent: runtimeSchema,\n }) as unknown as Schema.Codec<RemoteModel, unknown>\n\n/** The submodel's Messages; each reduces to `RemoteModel` through `updateRemote`. */\nexport type RemoteMessage =\n | {\n readonly _tag: 'ReadReceived'\n readonly requests: readonly Requirement[]\n readonly result: Schema.Schema.Type<typeof ReadBatchResult>\n readonly now: number\n }\n | {\n readonly _tag: 'ReadFailed'\n readonly requests: readonly Requirement[]\n readonly error: RemoteError\n /**\n * The live stream whose subscription broke, when this is that rather\n * than a read. Nothing was being read, so no field failed: the stream is\n * recorded as a gap, since changes after it are missed until the live\n * entry restarts it.\n */\n readonly stream?: string | undefined\n }\n /** A refetch of present fields began; they read as `Refreshing` until it lands. */\n | { readonly _tag: 'RefreshStarted'; readonly requests: readonly Requirement[] }\n /** A read began; the fields it asks for that the store lacks read as `Loading`. */\n | {\n readonly _tag: 'ReadStarted'\n readonly requests: readonly Requirement[]\n /** The refresh generation the read was planned under. */\n readonly refresh?: number | undefined\n }\n /**\n * Queries for these connections were sent. One with nothing to show reads\n * `Loading` until its page or its failure arrives, which is what separates\n * \"being fetched\" from `Initial`, \"nothing is fetching this\".\n */\n | { readonly _tag: 'QueryStarted'; readonly connections: readonly string[] }\n /** The active Surfaces' roots changed; everything they do not reach is collected. */\n | { readonly _tag: 'RetentionChanged'; readonly roots: RetentionRoots }\n /** A restored snapshot meets the store; runtime state is untouched. */\n | {\n readonly _tag: 'Hydrated'\n readonly entities: EntityStore\n /**\n * The connections a snapshot declared should survive, as their edges.\n * Restored with **unknown** boundaries and marked stale: the rows show\n * at once and the connection is refetched, because a persisted cursor\n * may name server state that is gone.\n */\n readonly connections?:\n | Readonly<Record<string, ReadonlyArray<ReadonlyArray<Edge>>>>\n | undefined\n readonly merge: MergePolicy\n /** The storage key the snapshot was read from, when it was: `restoredFrom`. */\n readonly from?: string | undefined\n }\n /** A mutation began; its optimistic operations show until it settles. */\n | {\n readonly _tag: 'MutationStarted'\n readonly requestId: string\n readonly optimistic?: ReadonlyArray<OptimisticOperation> | undefined\n /**\n * Who the operation is predicted for: what a list's `Expr.viewer` reads\n * while the client places the rows it changes. `Data.mutate` gives\n * `Remote.make`'s viewer; absent, a list over the viewer is the server's.\n */\n readonly viewer?: { readonly entity: string; readonly id: string } | undefined\n /**\n * Which mutation, with what input: what the ledger keeps until the\n * request applies, so a failure can be listed and retried. `Data.mutate`\n * always gives it.\n */\n readonly write?:\n | {\n readonly mutation: string\n readonly input: unknown\n readonly keys?: ReadonlyArray<string> | undefined\n /** When the reader acted: what the request sends, and a retry sends again. */\n readonly now?: number | undefined\n /**\n * Queued in the outbox rather than sent: the input encoded, and\n * what the reader was shown, as the store keeps them. The request\n * id is the operation id.\n */\n readonly durable?:\n | {\n readonly input: unknown\n readonly shown: ReadonlyArray<RelationRequirement>\n }\n | undefined\n }\n | undefined\n }\n /** What `Data.mutate`'s Command answers for a durable write, which the outbox sends: nothing. */\n | { readonly _tag: 'MutationQueued'; readonly requestId: string }\n /**\n * What the outbox's store under `key` holds, read entry by entry: written\n * there by this page or another tab. `session` is given by a restore, for\n * a page that has none; `unsaved` says why the store could not be written,\n * when it could not, and the entries are then this page's own.\n */\n | {\n readonly _tag: 'OutboxRead'\n readonly key: string\n readonly scope: string\n readonly session?: string | undefined\n readonly entries: ReadonlyArray<ReadEntry>\n readonly done: ReadonlyArray<string>\n readonly unsaved?: string | undefined\n }\n /** A durable write was sent and nothing answered; it is sent again after a wait. */\n | {\n readonly _tag: 'OutboxDelayed'\n readonly requestId: string\n readonly attempt: number\n readonly error: RemoteError\n }\n | {\n readonly _tag: 'MutationSucceeded'\n readonly requestId: string\n readonly entities: readonly NormalizedPatch[]\n /** Connection changes the server confirmed; they replace the request's own. */\n readonly connections?: ReadonlyArray<ConnectionChange> | undefined\n /** Entities the mutation deleted: tombstoned, which hides them from every connection. */\n readonly deleted?: ReadonlyArray<{ readonly entity: string; readonly id: string }> | undefined\n /**\n * What the answer read of the rows it names, for the fields the request\n * said it shows: written as a read is, in the same reduction.\n */\n readonly read?: Schema.Schema.Type<typeof AnswerRead> | undefined\n /** Injected clock reading of the answer: how fresh the written entities are. */\n readonly now: number\n }\n | {\n readonly _tag: 'MutationFailed'\n readonly requestId: string\n readonly error: RemoteError\n /** The operation id it was sent with, for a retry to send again. */\n readonly operation: string\n }\n /**\n * Operations shown over the store with no request behind them, until they are\n * lifted: a preview of a change nobody has made. Showing an id again replaces\n * what it showed.\n */\n | {\n readonly _tag: 'OverlayShown'\n readonly id: string\n readonly optimistic: ReadonlyArray<OptimisticOperation>\n }\n | { readonly _tag: 'OverlayLifted'; readonly id: string }\n /** `Data.more`: a read's window, by `windowGrowthKey`, now shows `size` rows. */\n | { readonly _tag: 'WindowGrown'; readonly window: string; readonly size: number }\n | {\n readonly _tag: 'LiveReceived'\n readonly stream: string\n readonly event: LiveEvent\n readonly policy?: LivePolicy\n readonly now: number\n }\n | { readonly _tag: 'GapCleared'; readonly stream: string }\n | {\n readonly _tag: 'ConnectionMerged'\n readonly connection: string\n readonly page: Segment\n /** The page answers the connection's refresh, so the merge also clears `stale`. */\n readonly refreshes?: boolean | undefined\n /**\n * The slice the query asked for, so the payload's entities write like a\n * read: one request per matching edge. Absent for a page from a server\n * that predates payload planning, which carries edges only.\n */\n readonly select?: RelationRequirement | undefined\n /** The selected fields of the page's items, as a read batch returns them. */\n readonly entities?:\n | ReadonlyArray<{\n readonly entity: string\n readonly id: string\n readonly values: Record<string, unknown>\n }>\n | undefined\n /** Fields asked for that the server settled without a value. */\n readonly settled?:\n | ReadonlyArray<{\n readonly entity: string\n readonly id: string\n readonly fields: ReadonlyArray<string>\n }>\n | undefined\n /** Injected clock reading of the answer, dating what the payload writes. */\n readonly now?: number | undefined\n }\n | { readonly _tag: 'ConnectionInvalidated'; readonly connection: string }\n | { readonly _tag: 'ConnectionRefreshed'; readonly connection: string }\n /**\n * A query for the connection failed. Its pages stay as they were, and it\n * reads `Failed` — with them as `previous`, when it has any — until a page\n * arrives, it is invalidated, or retention drops it.\n */\n | { readonly _tag: 'QueryFailed'; readonly connection: string; readonly error: RemoteError }\n /**\n * What `Data.preload` read for a destination, as the Messages that wrote it,\n * reduced in order into the Model as it is now rather than the one the\n * preload started from.\n */\n | { readonly _tag: 'Preloaded'; readonly messages: ReadonlyArray<RemoteMessage> }\n /**\n * What the Command reporting recorded diagnostics returns once it has. It\n * changes nothing: the diagnostics stay in the Model.\n */\n | { readonly _tag: 'CompletedReportDiagnostics' }\n\nexport const retentionRootsSchema = Schema.Struct({\n requirements: Schema.Array(ReadRequest),\n connections: Schema.Array(\n Schema.Struct({ identity: Schema.String, select: Schema.optional(RelationRequest) }),\n ),\n})\n\n/**\n * The Messages' fields by tag, without `_tag`: what `defineMessageUnion` takes,\n * so an application spreads them into its own union (`Remote.messages`).\n */\nexport const remoteMessageCases = {\n ReadReceived: {\n requests: Schema.Array(ReadRequest),\n result: ReadBatchResult,\n now: Schema.Number,\n },\n ReadFailed: {\n requests: Schema.Array(ReadRequest),\n error: remoteErrorSchema,\n stream: Schema.optional(Schema.String),\n },\n RefreshStarted: { requests: Schema.Array(ReadRequest) },\n ReadStarted: { requests: Schema.Array(ReadRequest), refresh: Schema.optional(Schema.Number) },\n QueryStarted: { connections: Schema.Array(Schema.String) },\n RetentionChanged: { roots: retentionRootsSchema },\n Hydrated: {\n connections: Schema.optional(Schema.Unknown),\n from: Schema.optional(Schema.String),\n entities: runtimeSchema,\n merge: Schema.Union([Schema.Literal('replace'), Schema.Literal('preserve-existing')]),\n },\n MutationStarted: {\n requestId: Schema.String,\n optimistic: Schema.optional(Schema.Array(Schema.Unknown)),\n viewer: Schema.optional(Schema.Struct({ entity: Schema.String, id: Schema.String })),\n write: Schema.optional(\n Schema.Struct({\n mutation: Schema.String,\n input: Schema.Unknown,\n keys: Schema.optional(Schema.Array(Schema.String)),\n now: Schema.optional(Schema.Number),\n durable: Schema.optional(\n Schema.Struct({ input: Schema.Unknown, shown: Schema.Array(RelationRequest) }),\n ),\n }),\n ),\n },\n MutationQueued: { requestId: Schema.String },\n OutboxRead: {\n key: Schema.String,\n scope: Schema.String,\n session: Schema.optional(Schema.String),\n entries: Schema.Array(Schema.Unknown),\n done: Schema.Array(Schema.String),\n unsaved: Schema.optional(Schema.String),\n },\n OutboxDelayed: { requestId: Schema.String, attempt: Schema.Number, error: remoteErrorSchema },\n MutationSucceeded: {\n requestId: Schema.String,\n entities: Schema.Array(NormalizedEntity),\n connections: Schema.optional(Schema.Array(Schema.Unknown)),\n deleted: Schema.optional(\n Schema.Array(Schema.Struct({ entity: Schema.String, id: Schema.String })),\n ),\n read: Schema.optional(AnswerRead),\n now: Schema.Number,\n },\n MutationFailed: { requestId: Schema.String, error: remoteErrorSchema, operation: Schema.String },\n OverlayShown: { id: Schema.String, optimistic: Schema.Array(Schema.Unknown) },\n OverlayLifted: { id: Schema.String },\n WindowGrown: { window: Schema.String, size: Schema.Number },\n LiveReceived: {\n stream: Schema.String,\n event: Schema.Unknown,\n policy: Schema.optional(Schema.Unknown),\n now: Schema.Number,\n },\n GapCleared: { stream: Schema.String },\n ConnectionMerged: {\n connection: Schema.String,\n page: Schema.Unknown,\n refreshes: Schema.optional(Schema.Boolean),\n select: Schema.optional(RelationRequest),\n entities: Schema.optional(Schema.Array(NormalizedEntity)),\n settled: Schema.optional(Schema.Array(SettledFields)),\n now: Schema.optional(Schema.Number),\n },\n ConnectionInvalidated: { connection: Schema.String },\n ConnectionRefreshed: { connection: Schema.String },\n QueryFailed: { connection: Schema.String, error: remoteErrorSchema },\n Preloaded: {\n messages: Schema.Array(Schema.suspend(() => remoteMessageSchema)),\n },\n CompletedReportDiagnostics: {},\n} satisfies Record<RemoteMessage['_tag'], Schema.Struct.Fields>\n\nexport type RemoteMessageTag = RemoteMessage['_tag']\n\n/**\n * A Remote Message as an application's union constructs it from\n * `remoteMessageCases`: the same shape `RemoteMessage` names, with the runtime\n * slots (`entities`, `event`, `page`) typed `unknown` by their schemas.\n */\nexport type RemoteMessageInput = {\n [Tag in RemoteMessageTag]: { readonly _tag: Tag } & Schema.Struct.Type<\n (typeof remoteMessageCases)[Tag]\n >\n}[RemoteMessageTag]\n\n/**\n * Whether a Message is one of Remote's, by tag. Narrows an application's union\n * to its Remote cases, and its complement to the application's own.\n */\nexport const isRemoteMessage = <M extends { readonly _tag: string }>(\n message: M,\n): message is Extract<M, { readonly _tag: RemoteMessageTag }> =>\n Object.hasOwn(remoteMessageCases, message._tag)\n\nexport const remoteMessageSchema = Schema.Union(\n Object.entries(remoteMessageCases).map(([tag, fields]) =>\n Schema.Struct({ _tag: Schema.Literal(tag), ...fields }),\n ),\n) as unknown as Schema.Codec<RemoteMessage, unknown>\n\n/** An overlay's layer, named apart from every request's: a request id is the application's to choose too. */\nconst OVERLAY = 'overlay:'\nconst overlayLayer = (id: string): string => `${OVERLAY}${id}`\n\n/** The ids `OverlayShown` shows now, each once, in the order they are drawn. */\nexport const overlaysOf = (model: RemoteModel): ReadonlyArray<string> => [\n ...new Set(\n [...model.optimistic.layers, ...model.optimistic.overlays].flatMap(({ id }) =>\n id.startsWith(OVERLAY) ? [id.slice(OVERLAY.length)] : [],\n ),\n ),\n]\n\n/** The key a grown window is kept under: its connection and the window first asked for. */\nexport const windowGrowthKey = (identity: string, window: string): string =>\n `${identity}\\u0000${window}`\n\n/**\n * Whether only overlays show this entity: the server has told the store\n * nothing of it and no request's layer writes it, so nothing will fetch what an\n * overlay leaves out.\n */\nexport const onlyOverlaid = (model: RemoteModel, entity: string, id: string): boolean => {\n if (Object.hasOwn(model.entities, entityKey(entity, id))) return false\n const writers = model.optimistic.layers.filter(layer =>\n layer.patches.some(patch => patch.entity === entity && patch.id === id),\n )\n return writers.length > 0 && writers.every(layer => layer.id.startsWith('overlay:'))\n}\n\nconst marksOf = (\n requests: ReadonlyArray<Requirement>,\n): ReadonlyArray<readonly [string, ReadonlyArray<string>]> =>\n requests.map(request => [entityKey(request.entity, request.id), request.fields] as const)\n\n/**\n * One mark per requested field, `entity\\0id\\0field`. A read is identified by\n * what it asks for, not by a request id: two reads asking for one field share\n * its mark, so the first answer clears it. Over-clearing shows `Initial` rather\n * than a spinner, which is the safer way to be wrong. The refresh generations\n * below key off the same marks, so \"what a read asks for\" means one thing.\n */\nexport const fieldMark = (entity: string, id: string, field: string): string =>\n `${entityKey(entity, id)}\\u0000${field}`\n\nconst fieldMarks = function* (requests: ReadonlyArray<Requirement>): Generator<string> {\n for (const request of requests) {\n for (const field of request.fields) yield fieldMark(request.entity, request.id, field)\n }\n}\n\nconst withLoading = (\n loading: ReadonlySet<string>,\n requests: ReadonlyArray<Requirement>,\n): ReadonlySet<string> => {\n const next = new Set(loading)\n for (const mark of fieldMarks(requests)) next.add(mark)\n return next.size === loading.size ? loading : next\n}\n\nconst withoutLoading = (\n loading: ReadonlySet<string>,\n requests: ReadonlyArray<Requirement>,\n): ReadonlySet<string> => {\n if (loading.size === 0) return loading\n const next = new Set(loading)\n for (const mark of fieldMarks(requests)) next.delete(mark)\n return next.size === loading.size ? loading : next\n}\n\n/**\n * A connection's mark. The leading separator keeps it out of the field marks'\n * space, whatever a connection identity happens to spell.\n */\nconst connectionPrefix = '\\u0000connection\\u0000'\nconst connectionMark = (identity: string): string => `${connectionPrefix}${identity}`\n\n/** Whether a query for this connection is in flight. */\nexport const isQueryLoading = (model: RemoteModel, identity: string): boolean =>\n model.loading.size !== 0 && model.loading.has(connectionMark(identity))\n\nconst withoutQueryLoading = (loading: ReadonlySet<string>, identity: string) => {\n if (!loading.has(connectionMark(identity))) return loading\n const next = new Set(loading)\n next.delete(connectionMark(identity))\n return next\n}\n\n/**\n * The in-flight marks of connections the roots still name. A query the entry\n * stopped waiting for — it was restarted or deactivated before an answer came —\n * leaves its mark behind, and a connection released with that mark would read\n * `Loading` forever the next time something asked for it before sending.\n */\nconst prunedLoading = (\n loading: ReadonlySet<string>,\n roots: RetentionRoots,\n reached: () => ReadonlySet<string>,\n): ReadonlySet<string> => {\n if (loading.size === 0) return loading\n const named = new Set(roots.connections.map(root => connectionMark(root.identity)))\n // A field mark goes with its entity, exactly as a connection's goes with the\n // connection: a read the entry stopped waiting for must not leave a value\n // reading `Loading` with nothing fetching it.\n const kept = [...loading].filter(mark =>\n mark.startsWith(connectionPrefix) ? named.has(mark) : reached().has(markEntity(mark)),\n )\n return kept.length === loading.size ? loading : new Set(kept)\n}\n\n/**\n * The windows grown on connections retention keeps; a dropped one starts over.\n * The same record when every one is kept.\n */\nconst keptWindows = (\n grown: RemoteModel['grown'],\n connections: Retained['connections'],\n): RemoteModel['grown'] => {\n const kept = Object.entries(grown).filter(([key]) =>\n Object.hasOwn(connections, key.slice(0, key.lastIndexOf('\\u0000'))),\n )\n return kept.length === Object.keys(grown).length ? grown : Object.fromEntries(kept)\n}\n\n/** The placements awaiting a page of a list retention still keeps; a dropped list's page never comes. */\nconst keptPlacements = (\n placed: RemoteModel['placed'],\n connections: Retained['connections'],\n): RemoteModel['placed'] => {\n const kept = Object.entries(placed).filter(([key]) => Object.hasOwn(connections, key))\n return kept.length === Object.keys(placed).length ? placed : Object.fromEntries(kept)\n}\n\n/**\n * Drops the refresh marks of entities and connections that were collected.\n * Nothing observes a collected entity — the retention roots are the active\n * Surfaces — so no read entry's generation can fall back when its mark goes.\n * Without this the generations would be bounded by how many things the\n * application has ever refreshed rather than by what it currently holds, which\n * for a list refreshed on a timer is the same as not bounded at all.\n */\nconst prunedRefresh = (refresh: RefreshState, retained: Retained): RefreshState => {\n const live = (mark: string): boolean =>\n mark.startsWith(connectionPrefix)\n ? retained.connections[mark.slice(connectionPrefix.length)] !== undefined\n : retained.entities[mark.slice(0, mark.indexOf('\\u0000'))] !== undefined\n const keep = (marks: ReadonlyMap<string, number>): ReadonlyMap<string, number> => {\n const next = new Map<string, number>()\n for (const [mark, generation] of marks) if (live(mark)) next.set(mark, generation)\n return next.size === marks.size ? marks : next\n }\n const requested = keep(refresh.requested)\n const started = keep(refresh.started)\n return requested === refresh.requested && started === refresh.started\n ? refresh\n : { ...refresh, requested, started }\n}\n\n/**\n * The generation a read is planned under: the highest any of the fields it\n * reads or connections it runs was refreshed at. A read entry carries this as a\n * dependency, so it restarts when what it observes is refreshed and not when\n * anything else is.\n */\nexport const refreshedAt = (\n refresh: RefreshState,\n requests: ReadonlyArray<Requirement>,\n connections: ReadonlyArray<string> = [],\n): number => {\n let at = refresh.floor\n for (const mark of fieldMarks(requests)) at = Math.max(at, refresh.requested.get(mark) ?? 0)\n for (const identity of connections) {\n at = Math.max(at, refresh.requested.get(connectionMark(identity)) ?? 0)\n }\n return at\n}\n\n/**\n * Marks every field of `requests` and every connection in `connections`\n * refreshed at the next generation.\n */\nexport const withRefreshRequested = (\n refresh: RefreshState,\n requests: ReadonlyArray<Requirement>,\n connections: ReadonlyArray<string> = [],\n): RefreshState => {\n const generation = refresh.generation + 1\n const requested = new Map(refresh.requested)\n for (const mark of fieldMarks(requests)) requested.set(mark, generation)\n for (const identity of connections) requested.set(connectionMark(identity), generation)\n return { ...refresh, generation, requested }\n}\n\n/**\n * Marks connections as needing to be asked again, and restarts a read of them\n * already in flight: a page requested before what invalidated it could land\n * after it, saying what is no longer true. `Remote.refresh` marks the same way.\n */\nexport const invalidateConnections = (\n model: RemoteModel,\n connections: ReadonlyArray<string>,\n): RemoteModel => {\n if (connections.length === 0) return model\n const marked = connections.reduce(\n (current, connection) => updateRemote(current, { _tag: 'ConnectionInvalidated', connection }),\n model,\n )\n return { ...marked, refresh: withRefreshRequested(marked.refresh, [], connections) }\n}\n\n/**\n * Records that a read of `requests` began under `generation`. A read that\n * carries no generation began under none, and leaves the marks as they are.\n */\nconst withRefreshStarted = (\n refresh: RefreshState,\n requests: ReadonlyArray<Requirement>,\n generation: number | undefined,\n): RefreshState => {\n if (generation === undefined || generation === 0) return refresh\n let started: Map<string, number> | undefined\n for (const mark of fieldMarks(requests)) {\n if ((refresh.started.get(mark) ?? 0) >= generation) continue\n started ??= new Map(refresh.started)\n started.set(mark, generation)\n }\n return started === undefined ? refresh : { ...refresh, started }\n}\n\n/**\n * Whether one field's read already began under the generation that field was\n * last refreshed at. Such a read is in flight and would otherwise outlive the\n * refresh, so the refresh takes a new generation to restart it even though the\n * field is already stale.\n */\nexport const refreshIsInFlight = (\n refresh: RefreshState,\n request: Requirement,\n field: string,\n): boolean => {\n const mark = fieldMark(request.entity, request.id, field)\n return (refresh.started.get(mark) ?? 0) === (refresh.requested.get(mark) ?? 0)\n}\n\n/**\n * Whether a read is fetching any of `fields` for this entity. Consulted only\n * when the store lacks the value, which is what separates `Loading` from\n * `Initial`.\n */\nexport const isLoading = (\n model: RemoteModel,\n entity: string,\n id: string,\n fields: ReadonlyArray<string>,\n): boolean => {\n if (model.loading.size === 0) return false\n return fields.some(field => model.loading.has(fieldMark(entity, id, field)))\n}\n\nconst setConnectionStale = (\n connections: Readonly<Record<string, Connection>>,\n connection: string,\n stale: boolean,\n): Readonly<Record<string, Connection>> => {\n const current = connections[connection]\n if (current?.stale === stale) return connections\n return { ...connections, [connection]: { ...(current ?? emptyConnection), stale } }\n}\n\n/**\n * How many streams `live` and `streams` keep. Which streams the active\n * Surfaces hold is not in the Model (retention roots merge every Surface's\n * requirements, and a stream key is one entry's), so the ledger keeps those\n * most recently heard from, as `failed` keeps the latest failures. A stream\n * dropped while still open meets its next event as a gap, which restarts it\n * and refetches what it covers.\n */\nconst STREAM_WINDOW = 256\n\n/** `record` with `stream` set as the most recent, the oldest dropped past the window. */\nconst heard = <V>(\n record: Readonly<Record<string, V>>,\n stream: string,\n value: V,\n): Readonly<Record<string, V>> => {\n const { [stream]: _previous, ...rest } = record\n const next: Record<string, V> = { ...rest, [stream]: value }\n const keys = Object.keys(next)\n for (const key of keys.slice(0, Math.max(0, keys.length - STREAM_WINDOW))) delete next[key]\n return next\n}\n\nconst withLiveState = (\n live: RemoteModel['live'],\n stream: string,\n state: LiveState,\n): RemoteModel['live'] => (live[stream] === state ? live : heard(live, stream, state))\n\nconst noHealth: StreamHealth = {\n restarts: 0,\n failures: 0,\n error: Option.none(),\n refused: Option.none(),\n}\n\n/**\n * A stream broke: it is marked a gap and its restart count moves, which\n * restarts its live entry. A stream already broken and not yet restarted\n * changes nothing, so the events a dying stream still delivers restart it once.\n */\nconst broke = (\n model: RemoteModel,\n stream: string,\n error: Option.Option<RemoteError>,\n): RemoteModel => {\n if (model.gaps.has(stream)) return model\n const health = model.streams[stream] ?? noHealth\n const streams = heard(model.streams, stream, {\n restarts: health.restarts + 1,\n failures: health.failures + 1,\n error,\n // An attempt after a refusal answered otherwise: the refusal no longer stands.\n refused: Option.none(),\n })\n // A gap is kept only beside its stream's health, which counts its restarts.\n const gaps = new Set([...model.gaps, stream].filter(key => Object.hasOwn(streams, key)))\n return { ...model, gaps, streams }\n}\n\n/** The tag of the server's refusal of a live stream, which `RemoteError` carries open. */\nconst refusedTag: RemoteLiveRefused['_tag'] = 'RemoteLiveRefused'\n\n/**\n * The server refused a stream for what it asks: it is marked refused and not a\n * gap, so its live entry does not restart it, and the refusal is recorded as\n * a diagnostic once.\n */\nconst refused = (model: RemoteModel, stream: string, error: RemoteError): RemoteModel => {\n const health = model.streams[stream] ?? noHealth\n if (Option.isSome(health.refused)) return model\n const streams = heard(model.streams, stream, {\n ...health,\n error: Option.some(error),\n refused: Option.some(error),\n })\n return {\n ...clearGap(model, stream),\n streams,\n diagnostics: withDiagnostics(model.diagnostics, [liveRefused({ stream, error })]),\n }\n}\n\n/**\n * An event applied on a stream that resubscribed: it works, so its next break\n * backs off from the start. A broken stream's last events prove nothing.\n */\nconst healthy = (model: RemoteModel, stream: string): RemoteModel => {\n const health = model.streams[stream]\n // A refused stream that applies an event was opened again and admitted.\n const settled = health !== undefined && health.failures === 0 && Option.isNone(health.refused)\n return health === undefined || settled || model.gaps.has(stream)\n ? model\n : {\n ...model,\n streams: heard(model.streams, stream, {\n ...health,\n failures: 0,\n error: Option.none(),\n refused: Option.none(),\n }),\n }\n}\n\nconst clearGap = (model: RemoteModel, stream: string): RemoteModel =>\n model.gaps.has(stream)\n ? { ...model, gaps: new Set([...model.gaps].filter(entry => entry !== stream)) }\n : model\n\n/**\n * The pure reducer all four producers share. A live event that arrives ahead of\n * its cursor is a gap: it is not applied, and the stream is recorded so its\n * live entry restarts it rather than silently missing facts. When every field a Message\n * touches keeps its identity, `model` itself is returned, so the application's\n * root keeps its identity and Foldkit does not render. The common no-ops do (a\n * duplicate live event, a repeated `ReadStarted`); a repeated failure, or a\n * `preserve-existing` restore of entities already held, still makes an equal\n * copy.\n */\nexport const updateRemote = (model: RemoteModel, message: RemoteMessage): RemoteModel => {\n const next = reduceRemote(model, message)\n return next === model || !sameFields(model, next) ? next : model\n}\n\n/** Whether every field of `next` is the one `model` holds. */\nconst sameFields = (model: RemoteModel, next: RemoteModel): boolean => {\n const keys = Object.keys(next) as Array<keyof RemoteModel>\n return (\n keys.length === Object.keys(model).length && keys.every(key => Object.is(model[key], next[key]))\n )\n}\n\n/**\n * A placement compared with the server's first page of the list it placed\n * in, under `verifyPredictions`: the keys as far as both reach must agree, and\n * no row placing took out may be one the page still lists. The record goes\n * once compared; a disagreement is kept.\n */\nconst checkedPlacement = (\n model: RemoteModel,\n connection: string,\n page: { readonly edges: ReadonlyArray<{ readonly key: string }>; readonly start: Boundary },\n refreshes: boolean,\n): Pick<RemoteModel, 'placed' | 'diagnostics'> => {\n const placed = model.placed[connection]\n if (placed === undefined || !refreshes || page.start._tag !== 'Terminal') {\n return { placed: model.placed, diagnostics: model.diagnostics }\n }\n const { [connection]: _, ...rest } = model.placed\n const reach = Math.min(placed.order.length, page.edges.length)\n const served = page.edges.slice(0, reach).map(edge => edge.key)\n const asPlaced = placed.order.slice(0, reach)\n const listed = new Set(page.edges.map(edge => edge.key))\n const agrees =\n served.every((key, index) => key === asPlaced[index]) &&\n !placed.dropped.some(key => listed.has(key))\n return {\n placed: rest,\n diagnostics: agrees\n ? model.diagnostics\n : withDiagnostics(model.diagnostics, [\n predictionMismatch(PredictionPart.Placement({ connection, placed: asPlaced, served })),\n ]),\n }\n}\n\ntype MutationStartedMessage = Extract<RemoteMessage, { readonly _tag: 'MutationStarted' }>\n\n/** The queue with `queued` in place of the entry of its operation, or after the rest. */\nconst placedIn = (queue: ReadonlyArray<Queued>, queued: Queued): ReadonlyArray<Queued> => {\n const operation = operationOf(queued)\n return queue.some(each => operationOf(each) === operation)\n ? queue.map(each => (operationOf(each) === operation ? queued : each))\n : [...queue, queued]\n}\n\n/** A durable write queued to wait its turn: new, or a failed one retried, its revision moved on. */\nconst queuedWrite = (\n outbox: OutboxState,\n operation: string,\n write: NonNullable<MutationStartedMessage['write']>,\n message: MutationStartedMessage,\n): OutboxState => {\n const prior = outbox.queue.find(queued => operationOf(queued) === operation)\n const stored: StoredWrite = {\n operation,\n mutation: write.mutation,\n input: write.durable?.input,\n ...(write.keys === undefined ? {} : { keys: write.keys }),\n ...(write.now === undefined ? {} : { now: write.now }),\n optimistic: message.optimistic ?? [],\n ...(message.viewer === undefined ? {} : { viewer: message.viewer }),\n shown: write.durable?.shown ?? [],\n revision: prior === undefined ? 0 : revisionOf(prior) + 1,\n state: { _tag: 'Waiting' },\n }\n return {\n ...outbox,\n queue: placedIn(\n outbox.queue,\n Queued.Readable({ write: stored, stored: false, attempt: 0, delayed: Option.none() }),\n ),\n }\n}\n\n/** The outbox with the readable write of `operation` changed by `change`; itself when it has none. */\nconst withQueued = (\n outbox: OutboxState,\n operation: string,\n change: (queued: Extract<Queued, { readonly _tag: 'Readable' }>) => Queued,\n): OutboxState => {\n const at = outbox.queue.findIndex(queued => operationOf(queued) === operation)\n const queued = outbox.queue[at]\n if (queued?._tag !== 'Readable') return outbox\n return {\n ...outbox,\n queue: outbox.queue.map((each, index) => (index === at ? change(queued) : each)),\n }\n}\n\n/** The outbox with `operation` settled: out of the queue, and remembered as done. */\nconst withoutQueued = (outbox: OutboxState, operation: string): OutboxState =>\n outbox.queue.some(queued => operationOf(queued) === operation)\n ? {\n ...outbox,\n queue: outbox.queue.filter(queued => operationOf(queued) !== operation),\n done: withDone(outbox.done, [operation]),\n }\n : outbox\n\nconst storedAs = (queued: Queued, stored: boolean): Queued =>\n queued.stored === stored ? queued : { ...queued, stored }\n\n/** A stored entry as the queue holds it: in the store, as read. */\nconst queuedOf = (entry: ReadEntry): Queued =>\n entry._tag === 'Readable'\n ? Queued.Readable({ write: entry.write, stored: true, attempt: 0, delayed: Option.none() })\n : Queued.Unreadable({\n operation: entry.operation,\n revision: entry.revision,\n raw: entry.raw,\n reason: entry.reason,\n stored: true,\n })\n\nconst entryOperation = (entry: ReadEntry): string =>\n entry._tag === 'Readable' ? entry.write.operation : entry.operation\n\nconst entryRevision = (entry: ReadEntry): number =>\n entry._tag === 'Readable' ? entry.write.revision : entry.revision\n\n/** Whether the queued write waits its turn: in the ledger in flight, its layer shown. */\nconst isWaiting = (queued: Queued): boolean =>\n queued._tag === 'Readable' && queued.write.state._tag === 'Waiting'\n\n/** The ledger and layers without a queued write: nothing of it shown or listed. */\nconst releasedFrom = (model: RemoteModel, queued: Queued): RemoteModel => {\n const operation = operationOf(queued)\n if (!model.mutations.pending.has(operation)) {\n return { ...model, mutations: forgetFailure(model.mutations, operation) }\n }\n const pending = new Set(model.mutations.pending)\n pending.delete(operation)\n const writes = new Map(model.mutations.writes)\n writes.delete(operation)\n // No answer of it is awaited here, so nothing is held back for one.\n const order = new Map(model.mutations.order)\n order.delete(operation)\n return {\n ...model,\n mutations: { ...model.mutations, pending, writes, order },\n optimistic: settleFailure(model.optimistic, operation),\n }\n}\n\n/**\n * The ledger and layers with a stored entry adopted in place of what the\n * page held of it (`prior`): a write waiting is begun, its layer shown; one\n * failed is failed, its layer gone; one this version cannot read is not in\n * the ledger at all.\n */\nconst adopted = (model: RemoteModel, prior: Queued | undefined, entry: ReadEntry): RemoteModel => {\n const released = prior === undefined ? model : releasedFrom(model, prior)\n if (entry._tag === 'Unreadable') return released\n const { write } = entry\n const begun = {\n ...released,\n mutations: beginMutation(released.mutations, write.operation, {\n mutation: write.mutation,\n input: entry.input,\n keys: write.keys,\n now: Option.fromUndefinedOr(write.now),\n optimistic: write.optimistic,\n }),\n }\n return write.state._tag === 'Waiting'\n ? {\n ...begun,\n optimistic: beginOptimistic(\n begun.optimistic,\n write.operation,\n write.optimistic,\n Option.fromUndefinedOr(write.viewer),\n ),\n }\n : {\n ...begun,\n mutations: failMutation(\n begun.mutations,\n write.operation,\n write.state.error,\n write.operation,\n ),\n }\n}\n\n/**\n * Writes another tab settled, whose answers this page did not see: their\n * layers go, every row they showed is asked for again and every list is\n * refetched, since what the server made of them is not known here.\n */\nconst settledElsewhere = (model: RemoteModel, settled: ReadonlyArray<Queued>): RemoteModel => {\n const released = settled.reduce(releasedFrom, model)\n const rows = new Map<string, { readonly entity: string; readonly id: string }>()\n for (const queued of settled) {\n if (queued._tag !== 'Readable' || queued.write.state._tag !== 'Waiting') continue\n for (const operation of queued.write.optimistic) {\n if ('entity' in operation) rows.set(entityKey(operation.entity, operation.id), operation)\n }\n }\n if (!settled.some(isWaiting)) return released\n const requests = [...rows.entries()].flatMap(([key, row]) =>\n Option.match(storeEntry(released.entities, key), {\n onNone: () => [],\n onSome: held =>\n held.present.size === 0\n ? []\n : [{ entity: row.entity, id: row.id, fields: [...held.present] }],\n }),\n )\n const asked =\n requests.length === 0 ? released : reduceRemote(released, { _tag: 'RefreshStarted', requests })\n return invalidateConnections(asked, Object.keys(asked.connections))\n}\n\n/**\n * What the store holds, met by what the page holds: an entry the store has a\n * newer revision of is adopted, one it has as the page does is marked\n * stored, one it lacks is written again, and one it settled goes. A read\n * under another key replaces the page's queue (its writes stay in their own\n * store). The Model itself when nothing changed.\n */\nconst readOutbox = (\n model: RemoteModel,\n message: Extract<RemoteMessage, { readonly _tag: 'OutboxRead' }>,\n): RemoteModel => {\n const switching =\n (Option.isSome(model.outbox.key) && model.outbox.key.value !== message.key) ||\n (Option.isSome(model.outbox.scope) && model.outbox.scope.value !== message.scope)\n const start: RemoteModel = switching\n ? {\n ...model.outbox.queue.reduce(releasedFrom, model),\n outbox: { ...model.outbox, queue: [], done: [] },\n }\n : model\n const before = start.outbox\n const done = withDone(before.done, message.done)\n const gone = new Set(done)\n const held = new Map(before.queue.map(queued => [operationOf(queued), queued]))\n const read = new Set<string>()\n const queue: Queued[] = []\n const recorded: RemoteDiagnostic[] = []\n let next = start\n for (const entry of message.entries) {\n const operation = entryOperation(entry)\n if (gone.has(operation) || read.has(operation)) continue\n read.add(operation)\n const prior = held.get(operation)\n const revision = entryRevision(entry)\n // The page's copy is newer: the store has not caught up, and is written again.\n if (prior !== undefined && revisionOf(prior) > revision) queue.push(prior)\n else if (prior !== undefined && revisionOf(prior) === revision) {\n queue.push(storedAs(prior, true))\n } else {\n next = adopted(next, prior, entry)\n if (entry._tag === 'Unreadable' && prior === undefined) {\n recorded.push(outboxUnreadable({ requestId: operation, reason: entry.reason }))\n }\n queue.push(queuedOf(entry))\n }\n }\n const settled: Queued[] = []\n for (const queued of before.queue) {\n const operation = operationOf(queued)\n if (read.has(operation)) continue\n if (gone.has(operation)) settled.push(queued)\n else queue.push(storedAs(queued, false))\n }\n next = settledElsewhere(next, settled)\n // Said once a page: every save after fails alike until storage frees up.\n const said = next.diagnostics.some(\n diagnostic => diagnostic._tag === 'OutboxUnsaved' && diagnostic.key === message.key,\n )\n if (message.unsaved !== undefined && !said) {\n recorded.push(outboxUnsaved({ key: message.key, reason: message.unsaved }))\n }\n const session = Option.orElse(before.session, () => Option.fromUndefinedOr(message.session))\n const unchanged =\n !switching &&\n next === start &&\n recorded.length === 0 &&\n done === before.done &&\n Option.contains(before.key, message.key) &&\n Option.contains(before.scope, message.scope) &&\n Option.isSome(before.session) === Option.isSome(session) &&\n queue.length === before.queue.length &&\n queue.every((queued, index) => queued === before.queue[index])\n if (unchanged) return model\n return {\n ...next,\n outbox: {\n session,\n key: Option.some(message.key),\n scope: Option.some(message.scope),\n queue,\n done,\n },\n diagnostics: withDiagnostics(next.diagnostics, recorded),\n }\n}\n\n/**\n * The Remote Model with a failed or unreadable durable write settled by the\n * reader (`Data.dismiss`): out of the queue and the ledger, and done, so every\n * tab drops it. A waiting one, or one not queued, is the Model itself.\n */\nexport const dismissQueued = (model: RemoteModel, requestId: string): RemoteModel => {\n const queued = model.outbox.queue.find(each => operationOf(each) === requestId)\n if (queued === undefined || isWaiting(queued)) return model\n return {\n ...model,\n mutations: forgetFailure(model.mutations, requestId),\n outbox: withoutQueued(model.outbox, requestId),\n }\n}\n\nconst reduceRemote = (model: RemoteModel, message: RemoteMessage): RemoteModel => {\n switch (message._tag) {\n case 'Preloaded':\n return message.messages.reduce(reduceRemote, model)\n case 'CompletedReportDiagnostics':\n return model\n case 'ReadReceived':\n return {\n ...model,\n entities: writeRead(model.entities, message.requests, message.result, message.now),\n loading: withoutLoading(model.loading, message.requests),\n // What was asked, and what came back: a relation riding on the request\n // writes its targets too, and a target's old failure must not outlive\n // the value that answers it.\n failures: withoutFieldFailures(model.failures, [\n ...fieldMarks(message.requests),\n ...patchedMarks(message.result.entities),\n ]),\n }\n case 'ReadFailed':\n // A broken live stream is not a failed read. Marking its fields failed\n // would take them out of the read entry's plan, and restart it, which is\n // the opposite of what missing changes calls for.\n if (message.stream !== undefined) {\n // tag-check: open — a RemoteError carries any transport failure's tag.\n return message.error._tag === refusedTag\n ? refused(model, message.stream, message.error)\n : broke(model, message.stream, Option.some(message.error))\n }\n // The read is over. Fields it refreshed read as they did, and every field\n // it asked for carries the error until something settles it.\n return {\n ...model,\n entities: setStale(model.entities, marksOf(message.requests), false),\n loading: withoutLoading(model.loading, message.requests),\n failures: withFieldFailures(model.failures, message.requests, message.error),\n }\n case 'RetentionChanged': {\n const recent = recentRoots(model.recent, message.roots)\n const retained = gc(model, recent)\n const active = new Set(message.roots.connections.map(root => root.identity))\n // A list no active Surface shows is held for going back, and refetched then.\n const connections = recent.connections.reduce(\n (held, { identity }) =>\n active.has(identity) || held[identity] === undefined\n ? held\n : setConnectionStale(held, identity, true),\n retained.connections,\n )\n // Retention's own walk over the Model before collection. It counts a\n // relation's target and a list's row the store does not hold, which is\n // exactly a value whose first read failed or is still in flight.\n let reachedKeys: ReadonlySet<string> | undefined\n const reached = () =>\n (reachedKeys ??= reachable(\n model.entities,\n message.roots,\n model.connections,\n model.optimistic,\n model.mutations.pending,\n ))\n return {\n ...model,\n ...retained,\n connections,\n recent,\n grown: keptWindows(model.grown, retained.connections),\n placed: keptPlacements(model.placed, retained.connections),\n refresh: prunedRefresh(model.refresh, retained),\n failures: prunedFailures(model.failures, message.roots, reached),\n loading: prunedLoading(model.loading, message.roots, reached),\n }\n }\n case 'Hydrated': {\n // A restored connection is evidence about its rows and about nothing\n // else. Its boundaries are `Unknown` — not `Terminal`, which would claim\n // there is no more, and not the cursors it had, which the server may no\n // longer honour — and it is stale, so the planner refetches it while the\n // rows it held are already on screen.\n const restored = Object.entries(message.connections ?? {}).map(\n ([identity, segments]) =>\n [\n identity,\n {\n // One segment per saved segment: the gaps between them are what\n // says \"these rows do not adjoin\", and merging them into one run\n // would invent an adjacency nobody established.\n segments: segments.map(edges => ({\n edges: [...edges],\n start: unknownBoundary,\n end: unknownBoundary,\n })),\n stale: true,\n },\n ] as const,\n )\n // A restored value is a write like any other, and settles a failure on the\n // field it writes: every field under `replace`, and only fields of\n // entities the store did not hold under `preserve-existing`.\n const written = Object.entries(message.entities).flatMap(([key, entry]) =>\n message.merge === 'replace' || !(key in model.entities)\n ? [...entry.present].map(field => `${key}\\u0000${field}`)\n : [],\n )\n return {\n ...model,\n entities: RemotePersistence.mergeStores(model.entities, message.entities, message.merge),\n failures: withoutFieldFailures(model.failures, written),\n connections:\n restored.length === 0\n ? model.connections\n : message.merge === 'replace'\n ? { ...model.connections, ...Object.fromEntries(restored) }\n : { ...Object.fromEntries(restored), ...model.connections },\n restoredFrom: message.from === undefined ? model.restoredFrom : Option.some(message.from),\n }\n }\n case 'RefreshStarted': {\n // An entity known to be absent stays so while it is asked about again,\n // so the rows and reads it took away stay away until the answer (#263).\n // A field the server settled without a value is asked for again, and\n // reads `Loading` while it is.\n const marks = marksOf(message.requests)\n const entities = setUnavailable(\n setStale(askAgain(model.entities, marks), marks, true),\n marks,\n false,\n )\n // Asking again is also how a failed field is retried, including one that\n // never loaded and so has nothing to mark stale, and one on a relation's\n // target, which the request reaches only through the store: a server need\n // not expand a relation, and the target is then planned by id once more.\n const reached = reachedMarks(model.entities, message.requests)\n const failures = withoutFieldFailures(model.failures, reached)\n // A failed field reads `Loading` from here, not `Initial`, until its read\n // lands: a retry keeps the failure's place. The mark takes the failure's,\n // so the same roots prune it.\n const retried = reached.filter(mark => mark in model.failures.fields)\n const loading = retried.length === 0 ? model.loading : new Set([...model.loading, ...retried])\n return { ...model, entities, failures, loading }\n }\n case 'QueryStarted': {\n const loading = new Set(model.loading)\n for (const identity of message.connections) loading.add(connectionMark(identity))\n return loading.size === model.loading.size ? model : { ...model, loading }\n }\n case 'ReadStarted':\n return {\n ...model,\n loading: withLoading(model.loading, message.requests),\n refresh: withRefreshStarted(model.refresh, message.requests, message.refresh),\n }\n case 'MutationStarted':\n return {\n ...model,\n outbox:\n message.write?.durable === undefined\n ? model.outbox\n : queuedWrite(model.outbox, message.requestId, message.write, message),\n mutations: beginMutation(\n model.mutations,\n message.requestId,\n message.write === undefined\n ? undefined\n : {\n mutation: message.write.mutation,\n input: message.write.input,\n keys: message.write.keys,\n now: Option.fromUndefinedOr(message.write.now),\n optimistic: message.optimistic ?? [],\n },\n ),\n optimistic: beginOptimistic(\n model.optimistic,\n message.requestId,\n message.optimistic ?? [],\n Option.fromUndefinedOr(message.viewer),\n ),\n }\n case 'MutationSucceeded': {\n // Settling is release-the-layer-and-overlays, so overlapping optimistic\n // layers rebase instead of needing inverse patches.\n const settled = settleSuccess(\n model.entities,\n model.optimistic,\n model.mutations,\n message.requestId,\n message,\n )\n // What the answer read lands with it, so no frame shows the row without\n // a field the layer showed. A repeated answer writes nothing, read included,\n // and the read leaves what a later request settled, as the patch does.\n const read =\n message.read === undefined || model.mutations.applied.has(message.requestId)\n ? undefined\n : unsettledRead(message.read, settledLater(model.mutations, message.requestId))\n return {\n ...model,\n entities:\n read === undefined\n ? settled.store\n : writeRead(settled.store, read.requests, read.result, message.now),\n mutations: settled.state,\n outbox: withoutQueued(model.outbox, message.requestId),\n optimistic: settled.optimistic,\n failures: withoutFieldFailures(model.failures, [\n ...(read === undefined\n ? []\n : [...fieldMarks(read.requests), ...patchedMarks(read.result.entities)]),\n ...patchedMarks(message.entities),\n ...(message.deleted ?? []).flatMap(ref =>\n entityFailureMarks(model.failures, entityKey(ref.entity, ref.id)),\n ),\n ]),\n }\n }\n case 'MutationQueued':\n return model\n case 'OutboxDelayed':\n return {\n ...model,\n outbox: withQueued(model.outbox, message.requestId, queued =>\n Queued.Readable({\n ...queued,\n attempt: message.attempt,\n delayed: Option.some(message.error),\n }),\n ),\n }\n case 'OutboxRead':\n return readOutbox(model, message)\n case 'OverlayShown':\n return {\n ...model,\n optimistic: beginOptimistic(\n settleFailure(model.optimistic, overlayLayer(message.id)),\n overlayLayer(message.id),\n message.optimistic,\n ),\n }\n case 'WindowGrown':\n return { ...model, grown: { ...model.grown, [message.window]: message.size } }\n case 'OverlayLifted': {\n const optimistic = settleFailure(model.optimistic, overlayLayer(message.id))\n return optimistic.layers.length === model.optimistic.layers.length &&\n optimistic.overlays.length === model.optimistic.overlays.length\n ? model\n : { ...model, optimistic }\n }\n case 'MutationFailed':\n return {\n ...model,\n // Only a write in flight fails: a repeated failure moves nothing on.\n outbox: !model.mutations.pending.has(message.requestId)\n ? model.outbox\n : withQueued(model.outbox, message.requestId, queued =>\n Queued.Readable({\n write: {\n ...queued.write,\n revision: queued.write.revision + 1,\n state: { _tag: 'Failed', error: message.error },\n },\n stored: false,\n attempt: 0,\n delayed: Option.none(),\n }),\n ),\n mutations: failMutation(\n model.mutations,\n message.requestId,\n message.error,\n message.operation,\n ),\n optimistic: settleFailure(model.optimistic, message.requestId),\n }\n case 'LiveReceived': {\n const state = model.live[message.stream] ?? emptyLiveState\n if (message.event._tag === 'EntityPatched' || message.event._tag === 'EntityDeleted') {\n const event = message.event\n const applied = applyEntityEvent(state, model.entities, event, message.now)\n if (applied.outcome === 'gap') return broke(model, message.stream, Option.none())\n // A value the server sent is newer than any failure to fetch it.\n const settled =\n applied.outcome !== 'applied'\n ? []\n : event._tag === 'EntityPatched'\n ? [...patchedMarks([{ ...event.ref, values: event.values }])]\n : entityFailureMarks(model.failures, entityKey(event.ref.entity, event.ref.id))\n const next = {\n ...model,\n entities: applied.store,\n live: withLiveState(model.live, message.stream, applied.state),\n failures: withoutFieldFailures(model.failures, settled),\n }\n return applied.outcome === 'applied' ? healthy(next, message.stream) : next\n }\n const applied = applyConnectionEvent(state, model.optimistic, message.event, message.policy)\n if (applied.outcome === 'gap') return broke(model, message.stream, Option.none())\n const written = {\n ...model,\n optimistic: applied.optimistic,\n live: withLiveState(model.live, message.stream, applied.state),\n }\n const next = applied.outcome === 'applied' ? healthy(written, message.stream) : written\n // An invalidating event means exactly what `ConnectionInvalidated` means,\n // so it goes through the same reduction rather than a parallel one.\n return applied.invalidated === undefined\n ? next\n : invalidateConnections(next, [applied.invalidated])\n }\n case 'GapCleared':\n return clearGap(model, message.stream)\n case 'ConnectionMerged': {\n const current = model.connections[message.connection] ?? emptyConnection\n const loading = withoutQueryLoading(model.loading, message.connection)\n // The page answering an invalidation is the server's list as it now is, so it\n // replaces the pages: removed and reordered items go, and later pages are paged\n // again. A re-run of a connection that was not invalidated still merges.\n const replaces = message.refreshes === true && current.stale\n const merged = merge(replaces ? emptyConnection : current, message.page)\n // A query payload writes like a read: one synthetic request per matching\n // edge, so windows, nested relations and settled fields behave as they do\n // for `ReadReceived`. A page without a payload only merges the connection.\n // Entities without a select are unsolicited and ignored: there is nowhere\n // to write them, and they must not clear failures they do not answer.\n const payload = message.select === undefined ? [] : (message.entities ?? [])\n const settled = message.select === undefined ? [] : (message.settled ?? [])\n const requests =\n message.select === undefined || (payload.length === 0 && settled.length === 0)\n ? []\n : message.page.edges\n .filter(edge => edge.ref.entity === message.select!.entity)\n .map(edge => ({ ...message.select!, id: edge.ref.id }))\n const entities =\n requests.length === 0\n ? model.entities\n : writeRead(\n model.entities,\n requests,\n { entities: [...payload], settled: [...settled] },\n message.now ?? 0,\n )\n // Like `ReadReceived`: the answer settles what it was asked, whether\n // with values or as settled, so a prior failure does not outlive it.\n const failures = withoutFieldFailures(\n withoutConnectionFailure(model.failures, message.connection),\n [...fieldMarks(requests), ...patchedMarks(payload)],\n )\n return {\n ...model,\n ...checkedPlacement(model, message.connection, message.page, message.refreshes === true),\n entities,\n connections: {\n ...model.connections,\n [message.connection]: message.refreshes === true ? { ...merged, stale: false } : merged,\n },\n optimistic: pruneOverlays(\n model.optimistic,\n message.connection,\n new Set(message.page.edges.map(edge => edge.key)),\n model.mutations.pending,\n ),\n failures,\n loading,\n }\n }\n case 'ConnectionInvalidated':\n // Asking again is also how a failed query is retried, so the failure goes\n // with the mark.\n // A connection is often both: a failed refresh stays due, and `Hydrated`\n // restores one stale. Asking again must still settle its failure, and\n // its mark becomes a loading one, so a list with no page to show reads\n // `Loading` until its query answers.\n return {\n ...model,\n connections: setConnectionStale(model.connections, message.connection, true),\n failures: withoutConnectionFailure(model.failures, message.connection),\n loading:\n message.connection in model.failures.connections\n ? new Set([...model.loading, connectionMark(message.connection)])\n : model.loading,\n }\n case 'QueryFailed':\n // The pages stay as they were, and a refresh that failed is still owed:\n // the connection stays stale. The failure is what stops the planner\n // asking again on its own; whatever settles it next (a retry, or a page\n // from \"load more\") leaves the connection due, so the refresh then runs\n // rather than a later page quietly passing for current.\n return {\n ...model,\n failures: {\n ...model.failures,\n connections: { ...model.failures.connections, [message.connection]: message.error },\n },\n loading: withoutQueryLoading(model.loading, message.connection),\n }\n case 'ConnectionRefreshed':\n return {\n ...model,\n connections: setConnectionStale(model.connections, message.connection, false),\n }\n }\n}\n\n/** The failures without one connection's, keeping identity when it had none. */\nconst withoutConnectionFailure = (failures: Failures, connection: string): Failures => {\n if (!(connection in failures.connections)) return failures\n const { [connection]: _settled, ...connections } = failures.connections\n return { ...failures, connections }\n}\n\n/** The failures with every field a read asked for failed with `error`. */\nconst withFieldFailures = (\n failures: Failures,\n requests: ReadonlyArray<Requirement>,\n error: RemoteError,\n): Failures => {\n const fields = { ...failures.fields }\n for (const mark of fieldMarks(requests)) fields[mark] = error\n return { ...failures, fields }\n}\n\n/**\n * The failures without the fields `settled` names, keeping identity when none\n * of them had failed, which is nearly always: this runs on every write.\n */\nconst withoutFieldFailures = (failures: Failures, settled: Iterable<string>): Failures => {\n if (Object.keys(failures.fields).length === 0) return failures\n const marks = [...settled].filter(mark => mark in failures.fields)\n if (marks.length === 0) return failures\n const fields = { ...failures.fields }\n for (const mark of marks) delete fields[mark]\n return { ...failures, fields }\n}\n\n/** Every failed field of one entity: what deleting the entity settles. */\nconst entityFailureMarks = (failures: Failures, key: string): ReadonlyArray<string> =>\n Object.keys(failures.fields).filter(mark => mark.startsWith(`${key}\\u0000`))\n\n/** The field marks of written values: each patch settles the fields it carries. */\nconst patchedMarks = function* (\n patches: ReadonlyArray<{ readonly entity: string; readonly id: string; readonly values: object }>,\n): Generator<string> {\n for (const patch of patches) {\n for (const field of Object.keys(patch.values)) yield fieldMark(patch.entity, patch.id, field)\n }\n}\n\n/**\n * Every field a read's requests reach: their own, and through each relation\n * the store already holds, the fields they ask of its targets. A request with\n * a relation riding on it names no target id; the store does, and a failure\n * recorded on a target is reached only this way.\n */\nconst reachedMarks = (\n store: EntityStore,\n requests: ReadonlyArray<Requirement>,\n): ReadonlyArray<string> => {\n const marks: string[] = []\n const walked = new Map<string, Set<RelationRequirement>>()\n const walk = (entity: string, id: string, requirement: RelationRequirement): void => {\n const key = entityKey(entity, id)\n const seen = walked.get(key) ?? new Set()\n if (seen.has(requirement)) return\n seen.add(requirement)\n walked.set(key, seen)\n for (const field of requirement.fields) {\n marks.push(fieldMark(entity, id, field))\n const nested = requirement.relations?.[field]\n if (nested === undefined) continue\n const value = readField(store, key, field)\n if (value._tag === 'None') continue\n for (const ref of targetsOf(value.value, nested)) walk(ref.entity, ref.id, nested)\n }\n }\n for (const request of requests) walk(request.entity, request.id, request)\n return marks\n}\n\n/** The entity key a field mark belongs to. */\nconst markEntity = (mark: string): string => mark.slice(0, mark.indexOf('\\u0000'))\n\n/**\n * The failures of what the roots still reach. A released connection's or\n * entity's failure goes with it, so asking for it again later asks the server\n * again rather than repeating an error that may no longer hold.\n *\n * Reached is retention's own walk, taken over the Model before collection. It\n * counts a relation's target and a list's row that the store does not hold,\n * which is exactly a value whose first read failed: it is still on screen,\n * behind the parent that refers to it.\n */\nconst prunedFailures = (\n failures: Failures,\n roots: RetentionRoots,\n reached: () => ReadonlySet<string>,\n): Failures => {\n const named = new Set(roots.connections.map(root => root.identity))\n const connections = Object.entries(failures.connections).filter(([identity]) =>\n named.has(identity),\n )\n const fields =\n Object.keys(failures.fields).length === 0\n ? []\n : Object.entries(failures.fields).filter(([mark]) => reached().has(markEntity(mark)))\n return connections.length === Object.keys(failures.connections).length &&\n fields.length === Object.keys(failures.fields).length\n ? failures\n : { connections: Object.fromEntries(connections), fields: Object.fromEntries(fields) }\n}\n\n/** Whether this field's last read failed and nothing has settled it since. */\nexport const isFieldFailed = (\n model: RemoteModel,\n entity: string,\n id: string,\n field: string,\n): boolean => fieldMark(entity, id, field) in model.failures.fields\n\n/**\n * Whether a read is fetching any field `relation` reads of an entity, its own\n * or, through each relation the store holds, its targets'. A value whose owner\n * is being fetched is loading, not `Initial`: nothing is missing a fetch.\n */\nexport const isLoadingThrough = (\n model: RemoteModel,\n entity: string,\n id: string,\n relation: RelationRequirement,\n): boolean => {\n if (model.loading.size === 0) return false\n const walked = new Map<string, Set<RelationRequirement>>()\n const walk = (target: string, targetId: string, requirement: RelationRequirement): boolean => {\n const key = entityKey(target, targetId)\n const seen = walked.get(key) ?? new Set()\n if (seen.has(requirement)) return false\n seen.add(requirement)\n walked.set(key, seen)\n for (const field of requirement.fields) {\n if (model.loading.has(fieldMark(target, targetId, field))) return true\n const nested = requirement.relations?.[field]\n if (nested === undefined) continue\n const value = readField(model.entities, key, field)\n if (value._tag === 'None') continue\n for (const ref of targetsOf(value.value, nested)) {\n if (walk(ref.entity, ref.id, nested)) return true\n }\n }\n return false\n }\n return walk(entity, id, relation)\n}\n\n/**\n * The first failure among the fields `relation` reads of an entity, following\n * each relation the store holds into its targets, as `assemble` does. A read\n * that consults it shows `Failed` for a related entity's failure too, rather\n * than waiting on a field nothing will fetch.\n */\nexport const failureOf = (\n model: RemoteModel,\n entity: string,\n id: string,\n relation: RelationRequirement,\n): RemoteError | undefined => {\n const failed = model.failures.fields\n if (Object.keys(failed).length === 0) return undefined\n // Once per entity and requirement, as retention walks: two relations can\n // reach one entity for different fields, and skipping the second would hide\n // its failure. A requirement tree is finite, so cyclic data still ends.\n const walked = new Map<string, Set<RelationRequirement>>()\n const walk = (\n target: string,\n targetId: string,\n requirement: RelationRequirement,\n ): RemoteError | undefined => {\n const key = entityKey(target, targetId)\n const seen = walked.get(key) ?? new Set()\n if (seen.has(requirement)) return undefined\n seen.add(requirement)\n walked.set(key, seen)\n for (const field of requirement.fields) {\n const error = failed[fieldMark(target, targetId, field)]\n if (error !== undefined) return error\n const nested = requirement.relations?.[field]\n if (nested === undefined) continue\n const value = readField(model.entities, key, field)\n if (value._tag === 'None') continue\n for (const ref of targetsOf(value.value, nested)) {\n const found = walk(ref.entity, ref.id, nested)\n if (found !== undefined) return found\n }\n }\n return undefined\n }\n return walk(entity, id, relation)\n}\n\n/** Appends (after) or prepends (before) an incoming page onto the stored one. */\nconst mergeWireRefPages = (\n current: RefPageValue,\n next: RefPageValue,\n direction: 'after' | 'before',\n): RefPageValue => {\n const refs =\n direction === 'after'\n ? [...new Set([...current.refs, ...next.refs])]\n : [...new Set([...next.refs, ...current.refs])]\n // The far boundary is the incoming page's; the near one is still the stored page's.\n return direction === 'after'\n ? { refs, hasNext: next.hasNext, hasPrevious: current.hasPrevious }\n : { refs, hasNext: current.hasNext, hasPrevious: next.hasPrevious }\n}\n\n/**\n * A mutation answer's read without what a later request settled (#288): a\n * field it wrote, a row it deleted, and the absence of a row it wrote, which\n * the read would otherwise tombstone.\n */\nconst unsettledRead = (\n read: Schema.Schema.Type<typeof AnswerRead>,\n { newer, rewritten }: ReturnType<typeof settledLater>,\n): Schema.Schema.Type<typeof AnswerRead> => {\n const entities = read.result.entities.flatMap(entity => {\n if (newer(entityKey(entity.entity, entity.id))) return []\n const values = Object.fromEntries(\n Object.entries(entity.values).filter(\n ([field]) => !newer(fieldMark(entity.entity, entity.id, field)),\n ),\n )\n return Object.keys(values).length === 0 ? [] : [{ ...entity, values }]\n })\n const settled = read.result.settled.flatMap(entry => {\n if (newer(entityKey(entry.entity, entry.id))) return []\n const fields = entry.fields.filter(field => !newer(fieldMark(entry.entity, entry.id, field)))\n return fields.length === 0 ? [] : [{ ...entry, fields }]\n })\n const answered = new Set(\n [...entities, ...settled].map(entry => entityKey(entry.entity, entry.id)),\n )\n // A request is kept for its windows, or to tombstone a row no later request wrote.\n const requests = read.requests.filter(request => {\n const key = entityKey(request.entity, request.id)\n return answered.has(key) || !rewritten(key)\n })\n return { requests, result: { entities, settled } }\n}\n\n/**\n * Writes a read result into the store, recording each field's applied window so\n * a later request with a different window refetches. A relation page requested\n * with a cursor is merged onto the page already stored, so \"load more\"\n * accumulates rather than replaces. Every read path should use this rather than\n * reducing `writeEntity` by hand.\n */\nexport const writeRead = (\n store: EntityStore,\n requests: ReadonlyArray<Requirement>,\n result: Schema.Schema.Type<typeof ReadBatchResult>,\n now = 0,\n): EntityStore => {\n const returned = new Map<string, Record<string, unknown>>()\n for (const entity of result.entities) {\n const key = entityKey(entity.entity, entity.id)\n returned.set(key, { ...returned.get(key), ...entity.values })\n }\n const byEntity = new Map<\n string,\n { windows: Record<string, string>; merge: Map<string, 'after' | 'before'> }\n >()\n // A request's windows apply to its entity; a relation's windows apply to\n // each target the returned refs name, and so on down the graph.\n const record = (\n key: string,\n windows: Requirement['windows'],\n relations: Requirement['relations'],\n ): void => {\n let entry = byEntity.get(key)\n if (entry === undefined) {\n entry = { windows: {}, merge: new Map() }\n byEntity.set(key, entry)\n }\n for (const [field, window] of Object.entries(windows ?? {})) {\n put(entry.windows, field, windowKey(window))\n const direction =\n window.after !== undefined ? 'after' : window.before !== undefined ? 'before' : undefined\n if (direction !== undefined) entry.merge.set(field, direction)\n }\n const values = returned.get(key)\n if (values === undefined) return\n for (const [field, relation] of Object.entries(relations ?? {})) {\n for (const ref of targetsOf(values[field], relation)) {\n record(entityKey(ref.entity, ref.id), relation.windows, relation.relations)\n }\n }\n }\n for (const request of requests) {\n record(entityKey(request.entity, request.id), request.windows, request.relations)\n }\n\n const writes: EntityWrite[] = []\n const pending = new Map<string, Record<string, unknown>>()\n for (const entity of result.entities) {\n const key = entityKey(entity.entity, entity.id)\n const entry = byEntity.get(key)\n let values = entity.values\n if (entry !== undefined && entry.merge.size > 0) {\n // A cursor page merges onto the page stored (or written earlier in this result).\n const previous = pending.get(key) ?? store[key]?.values\n if (previous !== undefined) {\n const merged: Record<string, unknown> = { ...values }\n for (const [field, direction] of entry.merge) {\n const incoming = values[field]\n const existing = previous[field]\n if (isRefPage(incoming) && isRefPage(existing)) {\n merged[field] = mergeWireRefPages(existing, incoming, direction)\n }\n }\n values = merged\n }\n }\n pending.set(key, { ...pending.get(key), ...values })\n writes.push({ key, values, windows: entry?.windows })\n }\n // The server was asked for these ids by name and answered without them, and\n // without settling any of their fields: whether the entity never existed or\n // is gone, the client knows the same thing: it is not there. Without this the\n // read would stay `Loading` for good. A forced plan (`refresh`) asks again,\n // and any later write clears the tombstone.\n //\n // An id the server settled fields of is not absent: it was asked about and\n // the answer was \"not this\", which is about the fields, not the entity. What\n // the store already holds of it stays, and a tombstone asked about again is\n // forgotten, so the settled fields can be recorded.\n //\n // Only ids asked for directly: the target of a returned ref is left alone. A\n // server need not expand a relation that rides on a request; the planner\n // follows a relation the store holds and asks for its targets by id next, and\n // a tombstone here would stop it.\n const settled = new Set(result.settled.map(entry => entityKey(entry.entity, entry.id)))\n let answered = store\n for (const request of requests) {\n const key = entityKey(request.entity, request.id)\n if (!returned.has(key) && !settled.has(key)) answered = tombstone(answered, key)\n else if (settled.has(key) && isTombstone(answered, key)) answered = remove(answered, key)\n }\n // Settled after the values: a field the same result also answers is present,\n // and a present field is never marked.\n return setUnavailable(\n writeEntities(answered, writes, now),\n result.settled.map(entry => [entityKey(entry.entity, entry.id), entry.fields] as const),\n true,\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2NA,MAAa,aAAuB;CAAE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AAQ,IAAI,GAAG,KAAK,MAAM,IAAI,EAAE;GACjD,IAAI,aAAa,KAAA,GAAW;IAC1B,MAAM,SAAkC,EAAE,GAAG,OAAO;IACpD,KAAK,MAAM,CAAC,OAAO,cAAc,MAAM,OAAO;KAC5C,MAAM,WAAW,OAAO;KACxB,MAAM,WAAW,SAAS;KAC1B,IAAI,UAAU,QAAQ,KAAK,UAAU,QAAQ,GAC3C,OAAO,SAAS,kBAAkB,UAAU,UAAU,SAAS;IAEnE;IACA,SAAS;GACX;EACF;EACA,QAAQ,IAAI,KAAK;GAAE,GAAG,QAAQ,IAAI,GAAG;GAAG,GAAG;EAAO,CAAC;EACnD,OAAO,KAAK;GAAE;GAAK;GAAQ,SAAS,OAAO;EAAQ,CAAC;CACtD;CAgBA,MAAM,UAAU,IAAI,IAAI,OAAO,QAAQ,KAAI,UAAS,UAAU,MAAM,QAAQ,MAAM,EAAE,CAAC,CAAC;CACtF,IAAI,WAAW;CACf,KAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,MAAM,UAAU,QAAQ,QAAQ,QAAQ,EAAE;EAChD,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,CAAC,QAAQ,IAAI,GAAG,GAAG,WAAW,UAAU,UAAU,GAAG;OAC1E,IAAI,QAAQ,IAAI,GAAG,KAAK,YAAY,UAAU,GAAG,GAAG,WAAW,OAAO,UAAU,GAAG;CAC1F;CAGA,OAAO,eACL,cAAc,UAAU,QAAQ,GAAG,GACnC,OAAO,QAAQ,KAAI,UAAS,CAAC,UAAU,MAAM,QAAQ,MAAM,EAAE,GAAG,MAAM,MAAM,CAAU,GACtF,IACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as PendingDelete, B as derivedOfWrite, C as DerivedBy, D as MutationState, E as MutationDescriptor, F as SchemaOrFields, G as mutationStatus, H as failMutation, I as StartedWrite, J as predictionOfWrite, K as optimisticOfWrite, L as TypeOf, M as Reconciled, N as Refusal, O as MutationStatus, P as RefusalOfWrite, R as beginMutation, T as MutationAnswer, U as forbiddenByWrite, V as emptyMutationState, W as forgetFailure, X as schemaOf, Y as reconcileMutation, Z as settledLater, j as PendingPatch, k as NormalizedPatch, q as patchOfWrite, w as Mutation, z as brokenByWrite } from "./optimistic-CECsfNGY.js";
|
|
2
|
+
export { DerivedBy, Mutation, MutationAnswer, MutationDescriptor, MutationState, MutationStatus, NormalizedPatch, PendingDelete, PendingPatch, Reconciled, Refusal, RefusalOfWrite, SchemaOrFields, StartedWrite, TypeOf, beginMutation, brokenByWrite, derivedOfWrite, emptyMutationState, failMutation, forbiddenByWrite, forgetFailure, mutationStatus, optimisticOfWrite, patchOfWrite, predictionOfWrite, reconcileMutation, schemaOf, settledLater };
|