foldkit-surface 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.
- package/README.md +27 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +76 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -148,6 +148,33 @@ Projection.fromReader(codec, read) // escape hatch for a non-ModelRef value
|
|
|
148
148
|
mix local fields with remote or replicated values. A nested projection
|
|
149
149
|
contributes its dependencies and metadata to the parent.
|
|
150
150
|
|
|
151
|
+
### Derivations
|
|
152
|
+
|
|
153
|
+
A view often works out a value from the Model on every render: a filtered
|
|
154
|
+
list, a count, a summary of many server reads. `Projection.derive(on, derive)`
|
|
155
|
+
works it out again only when a value at one of the paths `on` names is a new
|
|
156
|
+
object:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
const Open = Projection.derive([App.model.todos], model =>
|
|
160
|
+
model.todos.filter(todo => !todo.done),
|
|
161
|
+
)
|
|
162
|
+
Open.read(model) // the same array while `model.todos` is
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`on` takes field references and Projections, whose `dependencies` it reads;
|
|
166
|
+
`derive` must read nothing else, or it shows what it read last. A Remote read
|
|
167
|
+
declares no path (its data is named by its metadata), and a `struct` holding
|
|
168
|
+
one declares only its other entries' paths, so while `on` holds such a read
|
|
169
|
+
the value is worked out on every read. Name the store's field,
|
|
170
|
+
`App.model.remote`, in `on` in its place, reading the Remote read inside
|
|
171
|
+
`derive`, and the value is kept while the store holds. A new result
|
|
172
|
+
with the same fields as the last (shallowly) gives the last back, so a memo
|
|
173
|
+
keyed on it downstream holds. It keeps one result, the one for the Model it
|
|
174
|
+
was last given, and an empty `on` throws, since nothing could tell it to work
|
|
175
|
+
the value out again. What it returns is `{ dependencies, read }`, which
|
|
176
|
+
`foldkit-mixins`' `SlotView.region` takes, and a region uses the same rule.
|
|
177
|
+
|
|
151
178
|
### Metadata
|
|
152
179
|
|
|
153
180
|
`Metadata` is [`foldkit-metadata`](../metadata/README.md), re-exported so an
|
package/dist/index.d.ts
CHANGED
|
@@ -129,6 +129,11 @@ type EntryRoots<Entries> = { readonly [K in keyof Entries]: EntryRoot<Entries[K]
|
|
|
129
129
|
/** `true` when the union has more than one member. Used to reject mixed roots. */
|
|
130
130
|
type IsUnion<T, U = T> = [T] extends [never] ? false : T extends unknown ? [U] extends [T] ? false : true : never;
|
|
131
131
|
type StructValue<Entries> = { readonly [K in keyof Entries]: EntryValue<Entries[K]>; } extends (infer Value) ? { readonly [K in keyof Value]: Value[K]; } : never;
|
|
132
|
+
/** A value derived from the Model and the paths it reads: what `Projection.derive` makes. */
|
|
133
|
+
export interface Derived<Root, Value> {
|
|
134
|
+
readonly dependencies: DependencyTree;
|
|
135
|
+
readonly read: (root: Root) => Value;
|
|
136
|
+
}
|
|
132
137
|
export declare const Projection: {
|
|
133
138
|
of: <F extends Schema.Struct.Fields>(schema: Schema.Struct<F>) => <const Sel extends OfSelection<F>>(selection: Sel) => Projection<Schema.Struct.Type<F>, OfValue<F, Sel>>;
|
|
134
139
|
struct: <const Entries extends Record<string, Projection<any, any> | ModelRef<any, any>>>(entries: Entries & (IsUnion<EntryRoots<Entries>[keyof Entries]> extends true ? never : unknown)) => Projection<EntryRoot<Entries[keyof Entries]>, StructValue<Entries>>;
|
|
@@ -150,6 +155,29 @@ export declare const Projection: {
|
|
|
150
155
|
readonly dependencies?: DependencyTree;
|
|
151
156
|
readonly metadata?: Metadata$1;
|
|
152
157
|
}) => Projection<Root, Value>;
|
|
158
|
+
/**
|
|
159
|
+
* A value worked out from the Model, and worked out again only when a value
|
|
160
|
+
* at a path it reads is a new object: the value counterpart of
|
|
161
|
+
* `foldkit-mixins`' `SlotView.region`, and what a region can be drawn from.
|
|
162
|
+
* `on` names what `derive` reads, as field references or Projections;
|
|
163
|
+
* `derive` must read nothing else, or it shows what it read last. While
|
|
164
|
+
* something in `on` reads what no path of its names (a Remote read, alone or
|
|
165
|
+
* inside a `struct`), the value is worked out on every read. A result with
|
|
166
|
+
* the same fields as the last, shallowly, gives the last back, so a memo
|
|
167
|
+
* keyed on it holds. It keeps one result: the one for the last Model it was
|
|
168
|
+
* given.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const shown = Projection.derive([App.model.todos, App.model.filter], (model: Model) =>
|
|
173
|
+
* model.todos.filter(todo => model.filter === 'all' || todo.done === (model.filter === 'done')),
|
|
174
|
+
* )
|
|
175
|
+
* // In the view: shown.read(model)
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
derive: <Root, Value>(on: ReadonlyArray<ModelRef<Root, any> | {
|
|
179
|
+
readonly dependencies: DependencyTree;
|
|
180
|
+
}>, derive: (root: Root) => Value) => Derived<Root, Value>;
|
|
153
181
|
/**
|
|
154
182
|
* Derives a writable projection from generated Model field references:
|
|
155
183
|
* `Projection.pick(App.model.todos, App.model.selectedTodoId)` infers
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Metadata","MetadataSummary","ManagedResourceEntry"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;qBAkCa;;iBAGI,MAAM,MAAM,OAAO;;WAEzB,QAAQ,OAAO,MAAM,OAAO;WAC5B,OAAO,MAAM,SAAS,MAAM;;WAE5B;WACA,MAAM,MAAM,SAAS;WACrB,MAAM,MAAM,MAAM,OAAO,UAAU;;;;;;;WAOnC,SAAS,MAAM,MAAM,KAAK,OAAO,UAAU,UAAU;;;;;;iBAO/C,SAAS,MAAM,OAAO;YAC3B,YAAY,MAAM,MAAM,OAAO;;;;;;;iBAQ1B,SACf,MACA,OACA,6BACA,2BACQ,SAAS,MAAM,OAAO;YACpB,YAAY,MAAM,MAAM,OAAO;aAC9B,KAAK;;aAEL;;;qBAmBA;;;;;EAKX,YAAY,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iBAIL,OACf,MACA,UAAU,OAAO,OAAO,QACxB,cAAc,eAAe,OAAO,OAAO;WAElC,KAAK,SAAS,MAAM,GAAG;WACvB,oBAAoB;;iBAGd;WACN;;WAQA;WACA;;;iBAIM;WACN;WACA;aAAkB;aAAuB;;;iBAGnC;WACN;WACA;WACA,oBAAoB;WACpB,oBAAoB,KAAK;WACzB,mBAAmB;;;YAIlB,WAAW,QACnB;WACW,UAAU;IACrB,QAAQ;;;;;;;;;;;qBAwCC;EACX,OAAO,MAAM,UAAU,OAAO,OAAO,QAAQ,cAAc,eAAe,OAAO,OAAO,SAAO,KACxF,SAAS,MAAM,GAAG,QAAM,iBACb,WAAW,YAC1B,OAAO,MAAM,GAAG;;EAGnB,MAAM,MAAM,UAAU,OAAO,OAAO,QAAQ,cAAc,eAAe,OAAO,OAAO,SAAO,QACpF,OAAO,MAAM,GAAG,WAAM,gBACX,WAAW,YAC7B,OAAO,MAAM,GAAG;;;;;;;EAWnB,WAAQ,QAAW,mCAAiC;;;;;;EA8EpD,WAAQ,QAAW,0BAAwB;;EA0B3C,aAAU,QAAW;;;;;EAgCrB,YAAS,QAAW"}
|
package/dist/index.js
CHANGED
|
@@ -125,22 +125,48 @@ function makeProjection(Model, dependencies, read, metadata = Metadata$1.empty)
|
|
|
125
125
|
function objectSchema(fields) {
|
|
126
126
|
return Object.keys(fields).length === 0 ? Schema.Record(Schema.String, Schema.Never) : Schema.Struct(fields);
|
|
127
127
|
}
|
|
128
|
+
const readsUnnamed = /* @__PURE__ */ new WeakSet();
|
|
129
|
+
const unnamed = (entry) => entry.dependencies.length === 0 || readsUnnamed.has(entry);
|
|
130
|
+
const markedBy = (composed, parts) => {
|
|
131
|
+
if (parts.some(unnamed)) readsUnnamed.add(composed);
|
|
132
|
+
return composed;
|
|
133
|
+
};
|
|
134
|
+
const valueAt = (root, path) => {
|
|
135
|
+
let value = root;
|
|
136
|
+
for (const key of path) {
|
|
137
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
138
|
+
value = value[key];
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
const keepAlike = (before, value) => sameFields(before, value) ? before : value;
|
|
143
|
+
const sameFields = (left, right) => {
|
|
144
|
+
if (Object.is(left, right)) return true;
|
|
145
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
|
|
146
|
+
const prototype = Object.getPrototypeOf(left);
|
|
147
|
+
if (!(prototype === Object.prototype || prototype === null || Array.isArray(left)) || Object.getPrototypeOf(right) !== prototype) return false;
|
|
148
|
+
const keys = Object.keys(left);
|
|
149
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && Object.is(left[key], right[key]));
|
|
150
|
+
};
|
|
128
151
|
const Projection = {
|
|
129
152
|
of: (schema) => (selection) => {
|
|
130
153
|
const picked = Object.create(null);
|
|
131
154
|
const dependencies = [];
|
|
132
155
|
const metadata = [];
|
|
156
|
+
const parts = [];
|
|
133
157
|
const readers = [];
|
|
134
158
|
for (const key of Object.keys(selection)) {
|
|
135
159
|
const choice = selection[key];
|
|
136
160
|
if (choice === true) {
|
|
137
161
|
picked[key] = schema.fields[key];
|
|
162
|
+
parts.push({ dependencies: [] });
|
|
138
163
|
readers.push([key, (root) => propertyReader(root, key)]);
|
|
139
164
|
} else {
|
|
140
165
|
const nested = choice;
|
|
141
166
|
picked[key] = nested.Model;
|
|
142
167
|
dependencies.push(...nested.dependencies);
|
|
143
168
|
metadata.push(nested.metadata);
|
|
169
|
+
parts.push(nested);
|
|
144
170
|
readers.push([key, (root) => nested.read(propertyReader(root, key))]);
|
|
145
171
|
}
|
|
146
172
|
}
|
|
@@ -149,12 +175,13 @@ const Projection = {
|
|
|
149
175
|
for (const [key, reader] of readers) out[key] = reader(root);
|
|
150
176
|
return out;
|
|
151
177
|
};
|
|
152
|
-
return makeProjection(objectSchema(picked), mergeDependencies(dependencies), read, Metadata$1.combine(metadata));
|
|
178
|
+
return markedBy(makeProjection(objectSchema(picked), mergeDependencies(dependencies), read, Metadata$1.combine(metadata)), parts);
|
|
153
179
|
},
|
|
154
180
|
struct: (entries) => {
|
|
155
181
|
const picked = Object.create(null);
|
|
156
182
|
const dependencies = [];
|
|
157
183
|
const metadata = [];
|
|
184
|
+
const nesteds = [];
|
|
158
185
|
const readers = [];
|
|
159
186
|
for (const key of Object.keys(entries)) {
|
|
160
187
|
const entry = entries[key];
|
|
@@ -167,6 +194,7 @@ const Projection = {
|
|
|
167
194
|
picked[key] = entry.Model;
|
|
168
195
|
dependencies.push(...entry.dependencies);
|
|
169
196
|
metadata.push(entry.metadata);
|
|
197
|
+
nesteds.push(entry);
|
|
170
198
|
readers.push([key, entry.read]);
|
|
171
199
|
}
|
|
172
200
|
}
|
|
@@ -175,26 +203,26 @@ const Projection = {
|
|
|
175
203
|
for (const [key, reader] of readers) out[key] = reader(root);
|
|
176
204
|
return out;
|
|
177
205
|
};
|
|
178
|
-
return makeProjection(objectSchema(picked), mergeDependencies(dependencies), read, Metadata$1.combine(metadata));
|
|
206
|
+
return markedBy(makeProjection(objectSchema(picked), mergeDependencies(dependencies), read, Metadata$1.combine(metadata)), nesteds);
|
|
179
207
|
},
|
|
180
208
|
/**
|
|
181
209
|
* Maps a Projection over an array: `array(p): Projection<ReadonlyArray<Root>,
|
|
182
210
|
* ReadonlyArray<Value>>`. Nesting is explicit (an array of arrays stays an
|
|
183
211
|
* array of arrays); there is no flatten or double-wrap.
|
|
184
212
|
*/
|
|
185
|
-
array: (projection) => ({
|
|
213
|
+
array: (projection) => markedBy({
|
|
186
214
|
Model: Schema.Array(projection.Model),
|
|
187
215
|
dependencies: projection.dependencies,
|
|
188
216
|
metadata: projection.metadata,
|
|
189
217
|
read: (root) => root.map((value) => projection.read(value))
|
|
190
|
-
}),
|
|
218
|
+
}, [projection]),
|
|
191
219
|
/** Maps a Projection inside an Option, preserving absence. */
|
|
192
|
-
option: (projection) => ({
|
|
220
|
+
option: (projection) => markedBy({
|
|
193
221
|
Model: Schema.Option(projection.Model),
|
|
194
222
|
dependencies: projection.dependencies,
|
|
195
223
|
metadata: projection.metadata,
|
|
196
224
|
read: (root) => Option.map(root, (value) => projection.read(value))
|
|
197
|
-
}),
|
|
225
|
+
}, [projection]),
|
|
198
226
|
read: (projection, root) => projection.read(root),
|
|
199
227
|
/**
|
|
200
228
|
* Low-level escape hatch: a Projection from a Schema and a reader, for
|
|
@@ -208,6 +236,48 @@ const Projection = {
|
|
|
208
236
|
read
|
|
209
237
|
}),
|
|
210
238
|
/**
|
|
239
|
+
* A value worked out from the Model, and worked out again only when a value
|
|
240
|
+
* at a path it reads is a new object: the value counterpart of
|
|
241
|
+
* `foldkit-mixins`' `SlotView.region`, and what a region can be drawn from.
|
|
242
|
+
* `on` names what `derive` reads, as field references or Projections;
|
|
243
|
+
* `derive` must read nothing else, or it shows what it read last. While
|
|
244
|
+
* something in `on` reads what no path of its names (a Remote read, alone or
|
|
245
|
+
* inside a `struct`), the value is worked out on every read. A result with
|
|
246
|
+
* the same fields as the last, shallowly, gives the last back, so a memo
|
|
247
|
+
* keyed on it holds. It keeps one result: the one for the last Model it was
|
|
248
|
+
* given.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const shown = Projection.derive([App.model.todos, App.model.filter], (model: Model) =>
|
|
253
|
+
* model.todos.filter(todo => model.filter === 'all' || todo.done === (model.filter === 'done')),
|
|
254
|
+
* )
|
|
255
|
+
* // In the view: shown.read(model)
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
derive: (on, derive) => {
|
|
259
|
+
if (on.length === 0) throw new Error("Projection.derive: it names nothing it reads, so nothing could tell it to work the value out again. Name field references, or Projections built from them.");
|
|
260
|
+
const parts = on.map((entry) => RefTypeId in entry ? { dependencies: [entry[RefTypeId].dependency] } : entry);
|
|
261
|
+
const dependencies = mergeDependencies(parts.flatMap((part) => part.dependencies));
|
|
262
|
+
const always = parts.some(unnamed);
|
|
263
|
+
let last;
|
|
264
|
+
const derived = {
|
|
265
|
+
dependencies,
|
|
266
|
+
read: (root) => {
|
|
267
|
+
const values = dependencies.map((path) => valueAt(root, path));
|
|
268
|
+
const before = last;
|
|
269
|
+
const value = before === void 0 ? derive(root) : !always && values.every((value, index) => Object.is(value, before.values[index])) ? before.value : keepAlike(before.value, derive(root));
|
|
270
|
+
last = {
|
|
271
|
+
values,
|
|
272
|
+
value
|
|
273
|
+
};
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
if (always) readsUnnamed.add(derived);
|
|
278
|
+
return derived;
|
|
279
|
+
},
|
|
280
|
+
/**
|
|
211
281
|
* Derives a writable projection from generated Model field references:
|
|
212
282
|
* `Projection.pick(App.model.todos, App.model.selectedTodoId)` infers
|
|
213
283
|
* `{ todos, selectedTodoId }` and its codec. Every reference must share one
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Metadata"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-surface` — the observation boundary for a Foldkit application.\n *\n * A Surface is a pure projection of the Model: it declares which fields a\n * feature reads and which Messages it may construct, from the application's\n * own Schema rather than a second hand-written interface. `foldkit-remote`,\n * `foldkit-sync`, `foldkit-agent`, and `foldkit-mirror` all read this boundary,\n * and `Module` validates that each Model path has one owner.\n *\n * Nothing here runs: the deliverable is the type surface, pinned by\n * `test/inference.test-d.ts`.\n */\nimport { Optic, Option, Predicate, Result, Schema } from 'effect'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { MessageUnion } from 'foldkit/message'\nimport type { Entry as ManagedResourceEntry } from 'foldkit/managedResource'\nimport type { Subscriptions } from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport type { Url } from 'foldkit/url'\nimport { Metadata, type MetadataSummary } from 'foldkit-metadata'\n\nexport { Metadata, MetadataTypeId, type MetadataKey, type MetadataSummary } from 'foldkit-metadata'\nexport { Diagnostics, type Diagnostic, type ReportDiagnostic } from './diagnostics.js'\n\n// ===========================================================================\n// ModelRef and the typed Model tree (Phase 0 cases 1)\n// ===========================================================================\n\n/**\n * The key a ref keeps its own members under; read them with `ModelRef.focus`.\n * A ref's string keys are the Model's fields, whatever their names (#331),\n * and no Schema field reaches a symbol. `Symbol.for`, so two copies of this\n * package read each other's refs.\n */\nexport const RefTypeId: unique symbol = Symbol.for('foldkit-surface/ModelRef')\n\n/** What a ref points at and how to read and write it: `ModelRef.focus(ref)`. */\nexport interface Focus<Root, Value, Encoded = unknown> {\n /** A pure codec: Foldkit Model fields carry no decoding or encoding services. */\n readonly Schema: Schema.Codec<Value, Encoded, never, never>\n readonly optic: Optic.Optional<Root, Value>\n /** The Model path the ref points at. */\n readonly dependency: readonly string[]\n readonly get: (root: Root) => Value\n readonly set: (root: Root, value: Value) => Root\n /**\n * Focused structural replacement: `set` of `fn` applied to `get`. This\n * delegates through the focus's own `set`, so container-aware setters\n * (`at`/`index` insertion and removal) keep working — never `optic`\n * calls directly. Infrastructure seam, not an application transition.\n */\n readonly modify: (root: Root, fn: (value: Value) => Value) => Root\n}\n\n/**\n * A reference to a place in the Model. Its string keys are the fields below\n * it; its own members are its `Focus`, read with `ModelRef.focus`.\n */\nexport interface ModelRef<Root, Value, Encoded = unknown> {\n readonly [RefTypeId]: Focus<Root, Value, Encoded>\n}\n\n/**\n * A `ModelRef` generated for a named Model field. `key` is the literal field\n * name, so a reference-based selection can infer its output keys without a\n * parallel field registry or string paths.\n */\nexport interface FieldRef<\n Root,\n Value,\n Key extends string = string,\n Encoded = unknown,\n> extends ModelRef<Root, Value, Encoded> {\n readonly [RefTypeId]: Focus<Root, Value, Encoded> & {\n readonly key: Key\n /** The application definition this field was generated from. */\n readonly owner: object\n }\n}\n\nconst makeFocus = <Root, Value>(\n Schema: Schema.Codec<Value, unknown, never, never>,\n optic: Optic.Optional<Root, Value>,\n dependency: readonly string[],\n get: (root: Root) => Value,\n set: (root: Root, value: Value) => Root,\n): Focus<Root, Value> => ({\n Schema,\n optic,\n dependency,\n get,\n set,\n modify: (root, fn) => set(root, fn(get(root))),\n})\n\nexport const ModelRef = {\n /**\n * Low-level escape hatch for a focus with no Model path of its own. Prefer\n * the `App.model` tree; use this for an optic that is not part of the Model.\n */\n fromOptic: <Root, Value>(\n Schema: Schema.Schema<Value>,\n optic: Optic.Optional<Root, Value>,\n dependency: readonly string[] = [],\n ): ModelRef<Root, Value> => ({\n [RefTypeId]: makeFocus(\n Schema as unknown as Schema.Codec<Value, unknown, never, never>,\n optic,\n dependency,\n root => Result.getOrThrow(optic.getResult(root)),\n (root, value) => optic.replace(value, root),\n ),\n }),\n /**\n * A ref's own members: where it points, how to read and write it, and, as\n * its value allows, `at` (a record), `index` (an array) and `select`. They\n * are kept apart from the ref's string keys, which are the Model's fields.\n */\n focus: <R extends { readonly [RefTypeId]: object }>(ref: R): R[typeof RefTypeId] =>\n ref[RefTypeId],\n /** Whether a value is a ref, as opposed to a Projection or a plain object. */\n is: (value: unknown): value is ModelRef<unknown, unknown> =>\n typeof value === 'object' && value !== null && RefTypeId in value,\n}\n\nexport type RefTree<Root, F extends Schema.Struct.Fields> = {\n readonly [K in keyof F & string]: RefNode<Root, F[K], K>\n}\n\n/** A ref whose focus can `select` a Projection of its value. */\nexport interface Selects<Root, Value> {\n readonly [RefTypeId]: {\n readonly select: <P>(projection: Projection<Value, P>) => Projection<Root, P>\n }\n}\n\n/** A ref to an optional value, whose focus selects inside the Option. */\nexport interface SelectsSome<Root, Inner> {\n readonly [RefTypeId]: {\n readonly select: <P>(projection: Projection<Inner, P>) => Projection<Root, Option.Option<P>>\n }\n}\n\n/** A ref to an array, whose focus reaches an item: `ModelRef.focus(ref).index(0)`. */\nexport interface Indexes<Root, Item> {\n readonly [RefTypeId]: {\n readonly index: (index: number) => OptionalRef<Root, Option.Option<Item>>\n }\n}\n\n/** A ref to a record, whose focus reaches an entry: `ModelRef.focus(ref).at(key)`. */\nexport interface Entries<Root, Key extends string, Value> {\n readonly [RefTypeId]: {\n readonly at: (key: Key) => OptionalRef<Root, Option.Option<Value>>\n }\n}\n\n// Tuple-wrapped so the conditional is *non-distributive*: without it,\n// `Value = Option<V>` distributes over `None | Some<V>` and `select` would\n// return a union of two unrelated projections.\ntype Select<Root, Value> = [Value] extends [Option.Option<infer Inner>]\n ? SelectsSome<Root, Inner>\n : Selects<Root, Value>\n\ntype Selectable<Root, Value, Key extends string, Encoded = unknown> = FieldRef<\n Root,\n Value,\n Key,\n Encoded\n> &\n Select<Root, Value>\n\n/**\n * A dynamic focus from `at`/`index`. Deliberately not a `FieldRef`: its key is\n * a record key or index, not a Model field, so a static `Projection.pick`\n * cannot infer a field name from it.\n */\nexport type OptionalRef<Root, Value> = ModelRef<Root, Value> & Select<Root, Value>\n\ntype RefNode<Root, S, Key extends string> =\n S extends Schema.Codec<infer A, infer Encoded, any, any>\n ? S extends Schema.Struct<infer F>\n ? Selectable<Root, A, Key, Encoded> & RefTree<Root, F>\n : A extends ReadonlyArray<infer E>\n ? Selectable<Root, A, Key, Encoded> & Indexes<Root, E>\n : A extends Readonly<Record<infer K extends string, infer V>>\n ? Selectable<Root, A, Key, Encoded> & Entries<Root, K, V>\n : Selectable<Root, A, Key, Encoded>\n : never\n\ntype AnySchema = Schema.Codec<unknown, unknown>\n\n// A key may be a stored id (`at(id)`), so only the container's own keys count.\nfunction propertyReader(root: unknown, key: string): unknown {\n return root === null || root === undefined || !Object.hasOwn(root, key)\n ? undefined\n : (root as Record<string, unknown>)[key]\n}\n\nfunction optionalReader(value: unknown): Option.Option<unknown> {\n return value === undefined ? Option.none() : Option.some(value)\n}\n\n/** Reads the tag off a Foldkit Message constructor without constructing one. */\nconst messageTag = (constructor: unknown): string | undefined => {\n const literal = (constructor as { fields?: { _tag?: { ast?: { literal?: unknown } } } }).fields\n ?._tag?.ast?.literal\n return typeof literal === 'string' ? literal : undefined\n}\n\n/** Whether a Message, of an application this cannot name, has one of `tags`. */\nconst hasTagIn = (tags: ReadonlySet<string>, message: unknown): boolean =>\n Predicate.hasProperty(message, '_tag') &&\n typeof message._tag === 'string' &&\n tags.has(message._tag)\n\n/** The tags of the Messages a Surface lists in `messages`. */\nconst messageTags = (surface: { readonly messages: readonly unknown[] }): ReadonlyArray<string> =>\n surface.messages.map(messageTag).filter((tag): tag is string => tag !== undefined)\n\nfunction makeTree(\n schema: AnySchema,\n path: readonly string[],\n optic: Optic.Optional<unknown, unknown>,\n get: (root: unknown) => unknown,\n optional = false,\n set: ((root: unknown, value: unknown) => unknown) | undefined,\n owner: object,\n): Record<string, unknown> {\n const erasedOptic = optic as {\n key(key: string): Optic.Optional<unknown, unknown>\n at(key: string): Optic.Optional<unknown, unknown>\n }\n // `Optic.at` cannot *insert* or *remove* an absent key (`replace` is a no-op\n // when the prism fails), so optional foci get container-aware setters below.\n const setFocus = set ?? ((root: unknown, value: unknown): unknown => optic.replace(value, root))\n const focus: Record<string, unknown> = {\n ...makeFocus(schema as never, optic, path, get, setFocus),\n key: path[path.length - 1] ?? '',\n owner,\n }\n const node: Record<PropertyKey, unknown> = { [RefTypeId]: focus }\n\n const fields = (schema as { readonly fields?: Schema.Struct.Fields }).fields\n if (fields !== undefined) {\n for (const key of Object.keys(fields)) {\n // Defined, not assigned: assigning `__proto__` would set the prototype.\n Object.defineProperty(node, key, {\n value: makeTree(\n fields[key] as AnySchema,\n [...path, key],\n erasedOptic.key(key),\n root => propertyReader(get(root), key),\n false,\n undefined,\n owner,\n ),\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n }\n\n focus.at = (key: string) =>\n makeTree(\n schema,\n [...path, key],\n erasedOptic.at(key),\n root => optionalReader(propertyReader(get(root), key)),\n true,\n (root, value) => {\n const container = get(root) as Record<string, unknown>\n const option = value as Option.Option<unknown>\n if (Option.isSome(option)) {\n return setFocus(root, { ...container, [key]: option.value })\n }\n const { [key]: _removed, ...rest } = container\n return setFocus(root, rest)\n },\n owner,\n )\n focus.index = (index: number) =>\n makeTree(\n schema,\n [...path, String(index)],\n optic,\n root =>\n optionalReader(\n Array.isArray(get(root)) ? (get(root) as ReadonlyArray<unknown>)[index] : undefined,\n ),\n true,\n (root, value) => {\n const array = (Array.isArray(get(root)) ? get(root) : []) as ReadonlyArray<unknown>\n const option = value as Option.Option<unknown>\n const next = Option.isSome(option)\n ? array.map((item, i) => (i === index ? option.value : item))\n : array.filter((_, i) => i !== index)\n return setFocus(root, next)\n },\n owner,\n )\n focus.select = (projection: Projection<unknown, unknown>) => {\n const dependencies = mergeDependencies([path, ...projection.dependencies])\n return optional\n ? makeProjection(\n Schema.Option(projection.Model),\n dependencies,\n root => Option.map(get(root) as Option.Option<unknown>, value => projection.read(value)),\n projection.metadata,\n )\n : makeProjection(\n projection.Model,\n dependencies,\n root => projection.read(get(root)),\n projection.metadata,\n )\n }\n return node\n}\n\n// ===========================================================================\n// Projection (Phase 0 case 2)\n// ===========================================================================\n\nexport type DependencyTree = readonly (readonly string[])[]\n\n/** Unions dependency trees, dropping duplicates; the result is a set. */\nfunction mergeDependencies(dependencies: DependencyTree): DependencyTree {\n const seen = new Set<string>()\n const merged: (readonly string[])[] = []\n for (const dependency of dependencies) {\n const key = dependency.join('\\u0000')\n if (seen.has(key)) continue\n seen.add(key)\n merged.push(dependency)\n }\n return merged\n}\n\nexport interface Projection<Root, Value> {\n readonly Model: Schema.Codec<Value, unknown>\n readonly dependencies: DependencyTree\n /** Interpreter-owned facts about this node and everything it composes. */\n readonly metadata: Metadata\n readonly read: (root: Root) => Value\n}\n\n/**\n * A projection Surface can install back into a Model. Public reads use the\n * read-only `Projection`; only a writable selection carries installation.\n * `set` writes exactly the declared fields, so an excess field in an untrusted\n * value cannot reach local state.\n */\nexport interface WritableProjection<Model, Fields extends Schema.Struct.Fields> {\n readonly schema: Schema.Struct<Fields>\n readonly dependencies: DependencyTree\n readonly get: (model: Model) => Schema.Struct.Type<Fields>\n readonly set: (model: Model, shared: Schema.Struct.Type<Fields>) => Model\n}\n\nfunction makeProjection<Value>(\n Model: Schema.Codec<Value, unknown>,\n dependencies: DependencyTree,\n read: (root: unknown) => Value,\n metadata: Metadata = Metadata.empty,\n): Projection<unknown, Value> {\n return { Model, dependencies, metadata, read }\n}\n\n/**\n * `Schema.Struct({})` is not an empty-object schema: it accepts `{foo:1}`, `[]`,\n * and `\"str\"` even with `onExcessProperty: 'error'`. A genuinely empty selection\n * needs a `never`-valued record.\n */\nfunction objectSchema(fields: Record<string, AnySchema>): AnySchema {\n return Object.keys(fields).length === 0\n ? Schema.Record(Schema.String, Schema.Never)\n : Schema.Struct(fields)\n}\n\ntype OfSelection<F extends Schema.Struct.Fields> = {\n readonly [K in keyof F]?: true | Projection<Schema.Schema.Type<F[K]>, unknown>\n}\n\ntype OfValue<F extends Schema.Struct.Fields, Sel> = {\n readonly [K in keyof Sel & keyof F]: Sel[K] extends true\n ? Schema.Schema.Type<F[K]>\n : Sel[K] extends Projection<any, infer V>\n ? V\n : never\n}\n\ntype EntryValue<E> =\n E extends Projection<any, infer V> ? V : E extends ModelRef<any, infer V> ? V : never\n\ntype EntryRoot<E> =\n E extends Projection<infer R, any> ? R : E extends ModelRef<infer R, any> ? R : never\n\ntype EntryRoots<Entries> = { readonly [K in keyof Entries]: EntryRoot<Entries[K]> }\n\n/** `true` when the union has more than one member. Used to reject mixed roots. */\ntype IsUnion<T, U = T> = [T] extends [never]\n ? false\n : T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never\n\ntype StructValue<Entries> = {\n readonly [K in keyof Entries]: EntryValue<Entries[K]>\n} extends infer Value\n ? { readonly [K in keyof Value]: Value[K] }\n : never\n\nexport const Projection = {\n of:\n <F extends Schema.Struct.Fields>(schema: Schema.Struct<F>) =>\n <const Sel extends OfSelection<F>>(\n selection: Sel,\n ): Projection<Schema.Struct.Type<F>, OfValue<F, Sel>> => {\n // No prototype, so a field named `__proto__` stays a key (see `struct`).\n const picked: Record<string, AnySchema> = Object.create(null)\n const dependencies: (readonly string[])[] = []\n const metadata: Metadata[] = []\n const readers: (readonly [string, (root: unknown) => unknown])[] = []\n\n for (const key of Object.keys(selection)) {\n const choice = (selection as Record<string, unknown>)[key]\n if (choice === true) {\n picked[key] = schema.fields[key] as AnySchema\n readers.push([key, root => propertyReader(root, key)])\n } else {\n const nested = choice as Projection<unknown, unknown>\n picked[key] = nested.Model\n dependencies.push(...nested.dependencies)\n metadata.push(nested.metadata)\n readers.push([key, root => nested.read(propertyReader(root, key))])\n }\n }\n\n const read = (root: unknown): unknown => {\n const out: Record<string, unknown> = Object.create(null)\n for (const [key, reader] of readers) out[key] = reader(root)\n return out\n }\n return makeProjection(\n objectSchema(picked),\n mergeDependencies(dependencies),\n read,\n Metadata.combine(metadata),\n ) as unknown as Projection<Schema.Struct.Type<F>, OfValue<F, Sel>>\n },\n\n struct: <const Entries extends Record<string, Projection<any, any> | ModelRef<any, any>>>(\n entries: Entries & (IsUnion<EntryRoots<Entries>[keyof Entries]> extends true ? never : unknown),\n ): Projection<EntryRoot<Entries[keyof Entries]>, StructValue<Entries>> => {\n // Keys may be stored ids (a page's node ids), so `__proto__` must stay a key.\n const picked: Record<string, AnySchema> = Object.create(null)\n const dependencies: (readonly string[])[] = []\n const metadata: Metadata[] = []\n const readers: (readonly [string, (root: unknown) => unknown])[] = []\n\n for (const key of Object.keys(entries)) {\n const entry = entries[key] as Projection<unknown, unknown> | ModelRef<unknown, unknown>\n if (ModelRef.is(entry)) {\n const focus = entry[RefTypeId]\n picked[key] = focus.Schema\n dependencies.push(focus.dependency)\n readers.push([key, focus.get])\n } else {\n picked[key] = entry.Model\n dependencies.push(...entry.dependencies)\n metadata.push(entry.metadata)\n readers.push([key, entry.read])\n }\n }\n\n const read = (root: unknown): unknown => {\n const out: Record<string, unknown> = Object.create(null)\n for (const [key, reader] of readers) out[key] = reader(root)\n return out\n }\n return makeProjection(\n objectSchema(picked),\n mergeDependencies(dependencies),\n read,\n Metadata.combine(metadata),\n ) as unknown as Projection<EntryRoot<Entries[keyof Entries]>, StructValue<Entries>>\n },\n\n /**\n * Maps a Projection over an array: `array(p): Projection<ReadonlyArray<Root>,\n * ReadonlyArray<Value>>`. Nesting is explicit (an array of arrays stays an\n * array of arrays); there is no flatten or double-wrap.\n */\n array: <Root, Value>(\n projection: Projection<Root, Value>,\n ): Projection<ReadonlyArray<Root>, ReadonlyArray<Value>> => ({\n Model: Schema.Array(projection.Model),\n dependencies: projection.dependencies,\n metadata: projection.metadata,\n read: root => root.map(value => projection.read(value)),\n }),\n\n /** Maps a Projection inside an Option, preserving absence. */\n option: <Root, Value>(\n projection: Projection<Root, Value>,\n ): Projection<Option.Option<Root>, Option.Option<Value>> => ({\n Model: Schema.Option(projection.Model),\n dependencies: projection.dependencies,\n metadata: projection.metadata,\n read: root => Option.map(root, value => projection.read(value)),\n }),\n\n read: <Root, Value>(projection: Projection<Root, Value>, root: Root): Value =>\n projection.read(root),\n\n /**\n * Low-level escape hatch: a Projection from a Schema and a reader, for\n * projections not derived from ModelRefs (agent context, adapters). Prefer\n * `of`/`struct`/`select`; dependencies default to empty.\n */\n fromReader: <Root, Value>(\n Model: Schema.Codec<Value, unknown>,\n read: (root: Root) => Value,\n options?: {\n readonly dependencies?: DependencyTree\n readonly metadata?: Metadata\n },\n ): Projection<Root, Value> => ({\n Model,\n dependencies: options?.dependencies ?? [],\n metadata: options?.metadata ?? Metadata.empty,\n read,\n }),\n\n /**\n * Derives a writable projection from generated Model field references:\n * `Projection.pick(App.model.todos, App.model.selectedTodoId)` infers\n * `{ todos, selectedTodoId }` and its codec. Every reference must share one\n * Root; a raw optic or an unrelated application is rejected. Repeated\n * identical members deduplicate; a conflicting definition throws.\n */\n pick: <const Refs extends readonly FieldRef<any, any, string>[]>(\n ...refs: Refs & (IsUnion<RefRoots<Refs>[number]> extends true ? never : unknown)\n ): WritableProjection<RefRoots<Refs>[number], PickFields<Refs>> => {\n const selected = refs.map(ref => ref[RefTypeId])\n // Two applications can have structurally identical Models, so the root type\n // check cannot separate them; the owner token can.\n const owner = selected[0]?.owner\n for (const focus of selected) {\n if (focus.owner !== owner) {\n throw new Error('Projection.pick: references from different applications')\n }\n }\n // A picked field is named by its last key alone, so two fields at\n // different paths with the same name would be one field: `get` would keep\n // one value and `set` would write it into both. The same field picked twice\n // is harmless and kept once; two different ones are refused here.\n // No prototype: a field named `constructor` must not read as already picked.\n const fields: Record<string, AnySchema> = Object.create(null)\n const paths: Record<string, string> = Object.create(null)\n for (const focus of [...selected]) {\n const path = focus.dependency.join('.')\n const existing = paths[focus.key]\n if (existing !== undefined) {\n if (existing === path) {\n selected.splice(selected.indexOf(focus), 1)\n continue\n }\n throw new Error(\n `Projection.pick: \"${existing}\" and \"${path}\" would both be read as \"${focus.key}\". Pick them in separate projections.`,\n )\n }\n paths[focus.key] = path\n fields[focus.key] = focus.Schema\n }\n return {\n schema: objectSchema(fields) as never,\n dependencies: mergeDependencies(selected.map(focus => focus.dependency)),\n get: model => {\n const out: Record<string, unknown> = Object.create(null)\n for (const focus of selected) out[focus.key] = focus.get(model as never)\n return out as never\n },\n set: (model, shared) => {\n let next = model\n for (const focus of selected)\n next = focus.set(next as never, (shared as Record<string, unknown>)[focus.key] as never)\n return next\n },\n }\n },\n\n /**\n * Merges disjoint writable projections into one: `Projection.compose(Todos,\n * Selection)`. Every projection must own the same Model; a field defined twice\n * with a different codec throws, while an identical definition deduplicates.\n * `set` installs each part, so composed fields keep their own write behaviour.\n */\n compose: <const Ps extends readonly WritableProjection<any, any>[]>(\n ...projections: Ps & (IsUnion<ProjectionModel<Ps[number]>> extends true ? never : unknown)\n ): WritableProjection<ProjectionModel<Ps[number]>, MergeFields<Ps>> => {\n const parts = [...projections]\n const fields: Record<string, AnySchema> = Object.create(null)\n // Where each field is read from, where the part says: a dependency path\n // ending in the field's name. The same name from two different paths is two\n // fields that would be read as one, as in `pick`.\n const paths: Record<string, string> = Object.create(null)\n const pathOf = (part: (typeof parts)[number], key: string): string | undefined =>\n part.dependencies.find(dependency => dependency.at(-1) === key)?.join('.')\n for (const part of parts) {\n for (const [key, codec] of Object.entries(part.schema.fields)) {\n const existing = fields[key]\n const path = pathOf(part, key)\n if (existing !== undefined) {\n const previous = paths[key]\n if (previous !== undefined && path !== undefined && previous !== path) {\n throw new Error(\n `Projection.compose: \"${previous}\" and \"${path}\" would both be read as \"${key}\"`,\n )\n }\n if (existing === codec) continue\n throw new Error(`Projection.compose: conflicting definitions for \"${key}\"`)\n }\n fields[key] = codec as AnySchema\n if (path !== undefined) paths[key] = path\n }\n }\n return {\n schema: objectSchema(fields) as never,\n dependencies: mergeDependencies(parts.flatMap(part => [...part.dependencies])),\n get: model => {\n const out: Record<string, unknown> = Object.create(null)\n for (const part of parts) Object.assign(out, part.get(model as never))\n return out as never\n },\n set: (model, shared) => {\n let next = model\n // Each part reads only its own fields from the merged value.\n for (const part of parts) next = part.set(next as never, shared as never)\n return next\n },\n }\n },\n}\n\n// ===========================================================================\n// Surface (Phase 0 case 3)\n// ===========================================================================\n\nexport interface AppScope<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n readonly model: RefTree<Root, F>\n /** Identity token shared by this application's references and subsets. */\n readonly owner: object\n}\n\nexport interface SurfaceInspection {\n readonly name: string\n readonly dependencies: DependencyTree\n readonly metadata: readonly MetadataSummary[]\n readonly emits: readonly unknown[]\n}\n\n/**\n * A Surface's params codec: present when the Surface declares params, absent\n * when `Params` is `void`, and possibly either when `Params` is `any`/`unknown`\n * so a params Surface still fits a `Surface<…, any>` position.\n */\nexport type ParamsSchema<Params> = unknown extends Params\n ? Schema.Codec<Params, unknown> | undefined\n : [Params] extends [void]\n ? [void] extends [Params]\n ? // Exactly `void`: no params, no schema.\n undefined\n : // `undefined` also extends `void`, but a Surface may still declare its schema.\n Schema.Codec<Params, unknown> | undefined\n : [void] extends [Params]\n ? // `void | X`: the schema is optional.\n Schema.Codec<Params, unknown> | undefined\n : Schema.Codec<Params, unknown>\n\n/**\n * The params argument of `Surface.read`, `contract` and `inspect`: required\n * unless `undefined` is a params value, as it is for a Surface without params.\n */\ntype ParamsArgument<Params> = undefined extends Params ? [params?: Params] : [params: Params]\n\nexport interface Surface<Root, Model, Message, Params> {\n readonly name: string\n /** Identity token of the application this Surface belongs to. */\n readonly owner: object\n readonly Params: ParamsSchema<Params>\n readonly Message: Schema.Schema<Message>\n readonly messages: readonly unknown[]\n readonly projection: (params: Params) => Projection<Root, Model>\n}\n\n/**\n * A Surface as the Model activates it: its params are a function of the Model\n * (`undefined` while inactive), so its requirements are too. `Surface.at`\n * builds one; a Subscription derives what to fetch, subscribe, and retain\n * from a list of them.\n */\n/**\n * Why a Surface is active, when that is something other than a callback.\n *\n * `Surface.at` takes an arbitrary function of the Model, which is correct and\n * opaque: nothing can say *why* the Surface is on without running it. When\n * activation is a tagged value at a known place — a route, a mode, a\n * selection — `Surface.when` records the place and the tag, and a manifest can\n * be built without evaluating anything.\n */\n/**\n * What `Surface.when` needs of a place in the Model: where it is, and how to\n * read it.\n *\n * A ref whose focus can be read, and deliberately not a whole `ModelRef`.\n * Activation **observes** — it never installs a value — so asking for a\n * writable reference would claim an authority it does not use. It also makes\n * the common case work: a field holding a tagged union is a *union of*\n * `FieldRef`s, one per case, which no single `ModelRef<Root, Value>` accepts.\n */\nexport interface ModelPlace<Root> {\n readonly [RefTypeId]: {\n /** Where the value lives, as `ModelRef.focus(place).dependency` gives it. */\n readonly dependency: readonly string[]\n readonly get: (root: Root) => unknown\n }\n}\n\nexport interface Activation {\n /** The Model path the tagged value lives at, as a focus's `dependency` gives it. */\n readonly path: readonly string[]\n /** The tag the Surface is active under; a Site node reading the viewer waits for one too. */\n readonly tag: string\n}\n\nexport interface ActiveSurface<Root, Model = unknown> {\n readonly name: string\n /** Identity token of the application the Surface belongs to. */\n readonly owner: object\n /** The projection for the params the Model gives; none while the Surface is inactive. */\n readonly projectionOf: (model: Root) => Option.Option<Projection<Root, Model>>\n /** The tags of the Messages the Surface lists in `messages`: what it may send. */\n readonly messages: ReadonlyArray<string>\n /**\n * Present when a tagged value at a known place activates the Surface\n * (`Surface.when`, or a Site node); absent for a bare `Surface.at`.\n */\n readonly activation?: Activation | undefined\n}\n\n/**\n * One Surface definition instantiated with concrete params: the unit a\n * `SurfaceSource` resolves to. `key` distinguishes instances of one Surface\n * (a Composition node id, say); a lone `Surface.at`/`Surface.when` instance\n * is keyed by its Surface name.\n */\nexport interface SurfaceInstance<Root, Model = unknown, Params = unknown> {\n readonly key: string\n readonly surface: Surface<Root, Model, unknown, Params>\n readonly params: Params\n readonly projection: Projection<Root, Model>\n}\n\n/**\n * A source of active Surface instances: what `Data.subscriptions`,\n * `Data.wiring`, `Remote.resume`, an SSR plan, an agent manifest, or DevTools\n * resolves a declaration to. `Surface.at` and `Surface.when` are sources of\n * zero or one instance; `Surface.each` of zero to many.\n */\nexport interface SurfaceSource<Root> {\n readonly name: string\n /** Identity token of the application the Surfaces belong to. */\n readonly owner: object\n /** The tags of the Messages the Surface lists: what an instance may send. */\n readonly messages: ReadonlyArray<string>\n readonly instancesOf: (model: Root) => ReadonlyArray<SurfaceInstance<Root, any, any>>\n}\n\n/**\n * One Surface definition instantiated per item of a parent Surface's Model:\n * `Surface.each` as data. `from` names the prerequisite — the family resolves\n * no instances until the parent is active — so consumers can tell the\n * requirements needed to *discover* instances from the requirements *of* the\n * discovered instances. That distinction is what lets `Data.satisfy` reach a\n * fixed point: first the parent, then what the parent reveals.\n */\nexport interface SurfaceFamily<\n Root,\n ParentModel,\n Model,\n Message,\n Params,\n> extends SurfaceSource<Root> {\n readonly from: ActiveSurface<Root, ParentModel>\n readonly child: Surface<Root, Model, Message, Params>\n /** The tags of the Messages the child Surface lists: what an instance may send. */\n readonly messages: ReadonlyArray<string>\n}\n\ndeclare const invalid: unique symbol\n\n/**\n * A compile-time failure that names its cause. Intersected onto a parameter\n * type when a type-level check fails, so the error reads as one line\n * (`Property '[invalid]' is missing … required in type 'Invalid<\"…\">'`)\n * naming the descriptor, instead of a wall of structural mismatch.\n */\nexport interface Invalid<Message extends string> {\n readonly [invalid]: Message\n}\n\n/** The fields of a `Schema.Struct`, or a schema, where params are declared. */\ntype ParamsShape = Schema.Struct.Fields | Schema.Top\n\ntype ParamsOf<P> = P extends Schema.Top\n ? Schema.Schema.Type<P>\n : P extends Schema.Struct.Fields\n ? Schema.Struct.Type<P>\n : void\n\n/** What a Surface's `model` may return: a Projection, or an object of Projections and refs to lift. */\ntype ModelShape<Root> =\n | Projection<Root, unknown>\n | Record<string, Projection<Root, any> | ModelRef<Root, any>>\n\ntype ModelOf<Root, R> = R extends Projection<Root, infer M> ? M : StructValue<R>\n\nconst isProjection = (value: unknown): value is Projection<unknown, unknown> =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { read?: unknown }).read === 'function' &&\n Metadata.is((value as { metadata?: unknown }).metadata)\n\ntype MsgOf<Ms extends readonly unknown[]> = {\n readonly [K in keyof Ms]: Ms[K] extends (...args: never[]) => infer M ? M : never\n}[number]\n\n/** The union of Messages a tuple of constructors produces. */\ntype SubsetOf<Ms extends readonly unknown[]> = Ms[number] extends (...args: never[]) => infer M\n ? M\n : never\n\ntype AppMessage<Cases extends Record<string, Schema.Struct.Fields>> = Schema.Schema.Type<\n MessageUnion<Cases>\n>\n\n/** A Message constructor whose produced Message belongs to the App's universe. */\ntype MessageConstructor<Cases extends Record<string, Schema.Struct.Fields>> = (\n ...args: never[]\n) => AppMessage<Cases>\n\n/**\n * The renderer's builder: the real `HtmlBuilder` with its private\n * `MessageUniverse` phantom removed, so the renderer's `OnClick` accepts only\n * the Surface's Message subset. `HtmlBuilder<M>` stays invariant even without\n * the phantom (`OnClick` returns `{ message: M }`), so a superset builder is\n * not assignable to this; `Surface.view` casts, which is sound because the\n * renderer can only construct subset Messages and the real builder accepts the\n * superset.\n */\ntype ViewBuilder<Message> = Omit<HtmlBuilder<Message>, keyof HtmlBuilder<never> & symbol>\n\n/** A renderer for a Surface's projected Model, with its Message set narrowed. */\nexport type Renderer<Model, Message> = (model: Model, h: ViewBuilder<Message>) => Html\n\n/** `unknown` when `Sub` is a subtype of `Super`, `never` otherwise. */\ntype Subset<Sub, Super> = [Sub] extends [Super] ? unknown : never\n\ntype RefRoot<R> = R extends ModelRef<infer Root, any> ? Root : never\n\ntype RefRoots<Refs extends readonly unknown[]> = {\n readonly [K in keyof Refs]: RefRoot<Refs[K]>\n}\n\n/** The struct fields a reference selection produces, keyed by each ref's field. */\ntype PickFields<Refs extends readonly FieldRef<any, any, string>[]> = {\n readonly [R in Refs[number] as R[typeof RefTypeId]['key']]: R[typeof RefTypeId]['Schema']\n}\n\ntype ProjectionModel<P> = P extends WritableProjection<infer M, any> ? M : never\n\ntype ProjectionFields<P> = P extends WritableProjection<any, infer F> ? F : never\n\ntype Merge2<A, B> = {\n readonly [K in keyof A | keyof B]: K extends keyof A ? A[K] : K extends keyof B ? B[K] : never\n}\n\n/** Merges the fields of several projections; an overlapping key is rejected at runtime. */\nexport type MergeFields<Ps extends readonly WritableProjection<any, any>[]> = Ps extends readonly [\n infer Head extends WritableProjection<any, any>,\n ...infer Tail extends readonly WritableProjection<any, any>[],\n]\n ? Merge2<ProjectionFields<Head>, MergeFields<Tail>>\n : {}\n\n/**\n * An application definition: the Model and Message schemas and the generated\n * field references. It is data, not a running instance, so it can be inspected\n * without mounting anything. Context, replication, and validation all read the\n * same `App.model` references.\n */\nexport interface Application<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> extends AppScope<Root, F, Cases> {\n /**\n * @deprecated Use `App.model`, the same references under the name the rest\n * of the API uses: `App.surface` hands a Surface `{ model }`, and\n * `Remote.make` and `Editor.at` take `model: App.model.…`. Removed in a\n * later minor.\n */\n readonly fields: RefTree<Root, F>\n /**\n * `Surface.make` with the mechanical wrappers lifted: `params` are the\n * fields of a `Schema.Struct` (or a schema), and `model` may return an\n * object of Projections and refs, which becomes `Projection.struct`.\n */\n readonly surface: <\n const Params extends ParamsShape | undefined = undefined,\n Shape extends ModelShape<Root> = Projection<Root, unknown>,\n const Ms extends readonly MessageConstructor<Cases>[] = readonly [],\n >(\n name: string,\n config: {\n readonly params?: Params\n readonly model: (context: {\n readonly model: RefTree<Root, F>\n readonly params: ParamsOf<Params>\n }) => Shape\n readonly messages?: Ms\n },\n ) => Surface<Root, ModelOf<Root, Shape>, MsgOf<Ms>, ParamsOf<Params>>\n /**\n * This application made runnable, once its update exists: the same\n * references and the same owner, with the initial Model and the transition\n * function a replicator replays. An update is often built from what is made\n * over the references (a Remote domain, a placed Bundle), so it cannot be\n * given when they are; this joins the two without a second application,\n * whose references would be another owner's.\n */\n readonly runnable: <Resources = never>(config: {\n readonly initial: Root\n readonly update: (\n model: Root,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<Root, Schema.Schema.Type<MessageUnion<Cases>>, Resources>\n }) => RunnableApplication<Root, F, Cases, Resources>\n}\n\n/**\n * An `Application` that also carries the initial Model and the transition\n * function, so a replicator can derive the initial shared value and replay.\n * `Resources` is whatever `update`'s Commands need.\n */\nexport interface RunnableApplication<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Resources = never,\n> extends Application<Root, F, Cases> {\n readonly initial: Root\n readonly update: (\n model: Root,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<Root, Schema.Schema.Type<MessageUnion<Cases>>, Resources>\n}\n\ndeclare const messageSubsetRoot: unique symbol\n\n/**\n * A typed subset of one application's Messages: the selected constructors, a\n * codec for exactly those variants, and a runtime membership test. Surface does\n * not label a subset agent-visible, durable, or presence; `Agent` and `Sync`\n * attach their own policy to the same value.\n */\n/** The union of encoded types a tuple of constructor schemas produces. */\ntype SubsetEncoded<Ms extends readonly unknown[]> =\n Ms[number] extends Schema.Codec<any, infer Encoded, any, any> ? Encoded : never\n\nexport interface MessageSet<\n Root,\n Message,\n Subset extends Message,\n Ms extends readonly ((...args: never[]) => Message)[],\n Cases extends Record<string, Schema.Struct.Fields> = Record<string, Schema.Struct.Fields>,\n Encoded = unknown,\n> {\n /** Phantom owner, so a subset cannot be crossed between applications. */\n readonly [messageSubsetRoot]?: Root\n /** The application identity token, checked when subsets compose. */\n readonly owner: object\n readonly constructors: Ms\n /** A pure codec for exactly the selected variants. */\n readonly schema: Schema.Codec<Subset, Encoded, never, never>\n readonly tags: ReadonlySet<string>\n readonly includes: (message: Message) => message is Subset\n}\n\nconst makeScope = <\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n}): AppScope<Schema.Struct.Type<F>, F, Cases> => {\n // One token per application, so a selection cannot silently mix two\n // applications whose Models happen to be structurally identical.\n const owner: object = {}\n return {\n Model: config.Model,\n Message: config.Message,\n owner,\n model: makeTree(\n // A generic `F` hides the Struct's services; a Foldkit Model is pure.\n config.Model as unknown as AnySchema,\n [],\n Optic.id(),\n root => root,\n false,\n undefined,\n owner,\n ) as unknown as RefTree<Schema.Struct.Type<F>, F>,\n }\n}\n\n/**\n * Captures an application's pure references once. `initial` and `update` are\n * optional: an agent needs only the Model, Message, and field references, while\n * a replicator needs them to derive the initial shared value and replay. A\n * `RunnableApplication` is returned when both are supplied.\n */\nfunction application<\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Resources = never,\n ManagedResourceServices = never,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n readonly initial: Schema.Struct.Type<F>\n readonly update: (\n model: Schema.Struct.Type<F>,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<\n Schema.Struct.Type<F>,\n Schema.Schema.Type<MessageUnion<Cases>>,\n Resources | ManagedResourceServices\n >\n}): RunnableApplication<Schema.Struct.Type<F>, F, Cases, Resources | ManagedResourceServices>\nfunction application<\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n}): Application<Schema.Struct.Type<F>, F, Cases>\nfunction application(config: any): any {\n const scope = makeScope(config)\n const surface = (\n name: string,\n surfaceConfig: {\n readonly params?: ParamsShape | undefined\n readonly model: (context: { readonly model: unknown; readonly params: unknown }) => unknown\n readonly messages?: readonly unknown[]\n },\n ) =>\n Surface.make(scope, name, {\n ...(surfaceConfig.params === undefined\n ? {}\n : {\n Params: Schema.isSchema(surfaceConfig.params)\n ? surfaceConfig.params\n : Schema.Struct(surfaceConfig.params),\n }),\n model: (context: { readonly model: unknown; readonly params: unknown }) => {\n const shape = surfaceConfig.model(context)\n return isProjection(shape) ? shape : Projection.struct(shape as never)\n },\n messages: surfaceConfig.messages,\n } as never)\n const made = { ...scope, fields: scope.model, surface }\n const runnable = (run: { readonly initial: unknown; readonly update: unknown }): unknown => ({\n ...made,\n runnable,\n initial: run.initial,\n update: run.update,\n })\n return { ...made, runnable, initial: config.initial, update: config.update }\n}\n\ntype ConstructorOfSubset<S> = S extends MessageSet<any, any, any, infer Ms, any> ? Ms : never\ntype ValueOfSubset<S> = S extends MessageSet<any, any, infer V, any, any> ? V : never\ntype RootOfSubset<S> = S extends MessageSet<infer R, any, any, any, any> ? R : never\ntype MessageOfSubset<S> = S extends MessageSet<any, infer M, any, any, any> ? M : never\ntype CasesOfSubset<S> = S extends MessageSet<any, any, any, any, infer C> ? C : never\n\ntype Concat<A extends readonly unknown[], B extends readonly unknown[]> = [...A, ...B]\n\n/** Concatenates the constructor tuples of several subsets, preserving each. */\nexport type MergeConstructors<Subs extends readonly MessageSet<any, any, any, any, any>[]> =\n Subs extends readonly [\n infer Head extends MessageSet<any, any, any, any, any>,\n ...infer Tail extends readonly MessageSet<any, any, any, any, any>[],\n ]\n ? Concat<ConstructorOfSubset<Head>, MergeConstructors<Tail>>\n : []\n\n/** Typed Message subsets of one application, by constructor reference. */\nexport const MessageSet = {\n /**\n * Selects a typed Message subset by constructor reference:\n * `MessageSet.make(App, [Message.CreatedTodo, Message.RenamedTodo])`. Each\n * constructor must be this application's own variant; a duplicate or a variant\n * from another union throws.\n */\n make: <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n const Ms extends readonly MessageConstructor<Cases>[],\n >(\n app: AppScope<Root, F, Cases>,\n messages: Ms,\n ): MessageSet<\n Root,\n Schema.Schema.Type<MessageUnion<Cases>>,\n SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>>,\n Ms,\n Cases,\n SubsetEncoded<Ms>\n > => {\n const tags = new Set<string>()\n for (const constructor of messages) {\n const tag = messageTag(constructor)\n if (tag === undefined) {\n throw new Error('MessageSet.make: expected Message constructors')\n }\n if ((app.Message as unknown as Record<string, unknown>)[tag] !== constructor) {\n throw new Error(\n `MessageSet.make: \"${tag}\" is not a variant of this application's Message union`,\n )\n }\n if (tags.has(tag)) throw new Error(`MessageSet.make: duplicate \"${tag}\"`)\n tags.add(tag)\n }\n return {\n owner: app.owner,\n constructors: messages,\n schema: Schema.Union([...messages] as unknown as ReadonlyArray<\n Schema.Schema<unknown>\n >) as unknown as Schema.Codec<\n SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>>,\n SubsetEncoded<Ms>,\n never,\n never\n >,\n tags,\n includes: (message): message is SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>> =>\n hasTagIn(tags, message),\n }\n },\n\n /**\n * Unions several Message subsets into one. Every subset must belong to the\n * same application; a tag declared twice throws. Disjoint feature modules can\n * each declare their own subset and compose them here.\n */\n union: <const Subs extends readonly MessageSet<any, any, any, any, any>[]>(\n ...subsets: Subs\n ): MessageSet<\n RootOfSubset<Subs[number]>,\n MessageOfSubset<Subs[number]>,\n ValueOfSubset<Subs[number]>,\n MergeConstructors<Subs>,\n CasesOfSubset<Subs[number]>,\n SubsetEncoded<MergeConstructors<Subs>>\n > => {\n const parts = [...subsets]\n const owner = parts[0]?.owner\n const tags = new Set<string>()\n const constructors: Array<Schema.Schema<unknown>> = []\n for (const part of parts) {\n if (part.owner !== owner) {\n throw new Error('MessageSet.union: subsets from different applications')\n }\n for (const constructor of part.constructors) {\n const tag = messageTag(constructor)\n if (tag === undefined) continue\n if (tags.has(tag)) throw new Error(`MessageSet.union: duplicate \"${tag}\"`)\n tags.add(tag)\n constructors.push(constructor as Schema.Schema<unknown>)\n }\n }\n return {\n owner: owner as object,\n constructors: constructors as never,\n schema: Schema.Union(constructors) as unknown as Schema.Codec<\n ValueOfSubset<Subs[number]>,\n SubsetEncoded<MergeConstructors<Subs>>,\n never,\n never\n >,\n tags,\n includes: (message): message is ValueOfSubset<Subs[number]> => hasTagIn(tags, message),\n }\n },\n}\n\n// ===========================================================================\n// Action: a named capability that ends in an existing Message\n// ===========================================================================\n\n/**\n * A capability a consumer may invoke by name with data, such as an agent's\n * tool or a page Block's button. It ends in one of the application's own\n * Messages, so `update` stays the only place a Message has effects, and its\n * input is decoded by its Schema before `toMessage` sees it: stored or\n * untrusted data never executes.\n */\n// `Input` defaults to `never`: an Action known only as an Action takes no input but through `run`.\nexport interface Action<\n Name extends string = string,\n Input = never,\n Encoded = unknown,\n Message = unknown,\n> {\n readonly _tag: 'Action'\n readonly name: Name\n /** What it does, for a person choosing it or an agent deciding to. */\n readonly description: string\n readonly input: Schema.Codec<Input, Encoded, never, never>\n readonly toMessage: (input: Input) => Message\n}\n\nexport const Action = {\n /** An Action: `Action.define({ name: 'addToCart', description, input, toMessage })`. */\n define: <const Name extends string, Input, Encoded, Message>(config: {\n readonly name: Name\n readonly description: string\n readonly input: Schema.Codec<Input, Encoded, never, never>\n readonly toMessage: (input: Input) => Message\n }): Action<Name, Input, Encoded, Message> => {\n if (config.name.length === 0) throw new Error('Action.define: an Action needs a name')\n return Object.freeze({ _tag: 'Action', ...config })\n },\n\n /** Whether a value is an Action. */\n is: (value: unknown): value is Action =>\n typeof value === 'object' && Predicate.isTagged(value, 'Action'),\n\n /**\n * The Message an Action makes of `data`, decoded as its input first; a\n * failure says why the input was refused and makes no Message.\n */\n run: <Input, Encoded, Message>(\n action: Action<string, Input, Encoded, Message>,\n data: unknown,\n ): Result.Result<Message, Schema.SchemaError> =>\n Result.map(Schema.decodeUnknownResult(action.input)(data), action.toMessage),\n}\n\nexport const Surface = {\n application,\n\n /**\n * A Surface as the Model activates it. `params` is the value, or a function\n * of the Model returning it (none while the Surface is inactive, e.g. on\n * another route); the Surface's requirements then follow the Model.\n */\n at: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n params: Params | ((model: Root) => Option.Option<Params>),\n ): ActiveSurface<Root, Model> & SurfaceSource<Root> => {\n const paramsOf = (model: Root): Option.Option<Params> =>\n typeof params === 'function'\n ? (params as (model: Root) => Option.Option<Params>)(model)\n : Option.some(params)\n const projectionOf = (model: Root): Option.Option<Projection<Root, Model>> =>\n Option.map(paramsOf(model), surface.projection)\n return {\n name: surface.name,\n owner: surface.owner,\n messages: messageTags(surface),\n projectionOf,\n instancesOf: model => {\n const value = paramsOf(model)\n if (Option.isNone(value)) return []\n return [\n {\n key: surface.name,\n surface,\n params: value.value,\n projection: surface.projection(value.value),\n },\n ]\n },\n }\n },\n\n /**\n * A Surface active while a tagged value at a known place has a given tag.\n *\n * ```ts\n * Surface.when(ProjectPage, App.model.route, AppRoute.Project, route => ({\n * projectId: route.projectId,\n * }))\n * ```\n *\n * The same thing `Surface.at` does with a callback, and one fact more: the\n * place and the tag are **values**, so what activates the Surface can be read\n * without running anything. That is what a route-to-Surface manifest, a\n * prefetch analysis, or an explanation of why a read is happening needs.\n *\n * Deliberately **not router-specific.** A route is one kind of tagged Model\n * state; a mode, a wizard step and a selected tab are others, and none of\n * them should need their own helper.\n *\n * `Surface.at` stays, and is still the answer when activation is a genuine\n * computation rather than a tag.\n */\n when: <Root, Model, Message, Params, Case extends Schema.Top>(\n surface: Surface<Root, Model, Message, Params>,\n place: ModelPlace<Root>,\n tagged: Case,\n params: (value: Schema.Schema.Type<Case>) => Params,\n ): ActiveSurface<Root, Model> & SurfaceSource<Root> => {\n const tag = messageTag(tagged)\n if (tag === undefined) {\n throw new Error(\n `Surface.when: expected a tagged constructor for \"${surface.name}\", which is what names the case that activates it`,\n )\n }\n const focus = place[RefTypeId]\n const paramsOf = (model: Root): Option.Option<Params> => {\n const value = focus.get(model)\n return Predicate.isTagged(value, tag)\n ? Option.some(params(value as Schema.Schema.Type<Case>))\n : Option.none()\n }\n return {\n name: surface.name,\n owner: surface.owner,\n messages: messageTags(surface),\n activation: { path: focus.dependency, tag },\n projectionOf: model => Option.map(paramsOf(model), surface.projection),\n instancesOf: model => {\n const value = paramsOf(model)\n if (Option.isNone(value)) return []\n return [\n {\n key: surface.name,\n surface,\n params: value.value,\n projection: surface.projection(value.value),\n },\n ]\n },\n }\n },\n\n /**\n * One Surface definition for each item of a parent Surface's Model: zero to\n * many keyed instances, where `Surface.at`/`Surface.when` give zero or one.\n *\n * ```ts\n * Surface.each(ProductGrid, {\n * from: CmsPage,\n * instances: ({ document }) => nodesOf(document).map(node => ({\n * key: node.id,\n * params: { category: node.props.category },\n * })),\n * })\n * ```\n *\n * Keys must be non-empty strings that survive as record keys: `__proto__`\n * is refused, and duplicates throw. Consumers looking instances up by key\n * must still read through `Object.hasOwn` or a `Map`: any string key is\n * otherwise admitted.\n */\n each: <Root, ParentModel, Model, Message, Params>(\n child: Surface<Root, Model, Message, Params>,\n config: {\n readonly from: ActiveSurface<Root, ParentModel>\n readonly instances: (\n parent: ParentModel,\n ) => ReadonlyArray<{ readonly key: string; readonly params: Params }>\n },\n ): SurfaceFamily<Root, ParentModel, Model, Message, Params> => ({\n name: child.name,\n owner: child.owner,\n from: config.from,\n child,\n messages: messageTags(child),\n instancesOf: model => {\n const parent = config.from.projectionOf(model)\n if (Option.isNone(parent)) return []\n const seen = new Set<string>()\n return config.instances(parent.value.read(model)).map(({ key, params }) => {\n if (typeof key !== 'string' || key.length === 0)\n throw new Error(\n `Surface.each: \"${child.name}\" needs a non-empty string key for every instance`,\n )\n if (key === '__proto__')\n throw new Error(`Surface.each: \"${child.name}\" refuses \"__proto__\" as an instance key`)\n if (seen.has(key))\n throw new Error(`Surface.each: \"${child.name}\" has two instances keyed \"${key}\"`)\n seen.add(key)\n return { key, surface: child, params, projection: child.projection(params) }\n })\n },\n }),\n\n /**\n * What a source resolves to for a Model: the family's instances, or the\n * lone instance of a `Surface.at`/`Surface.when` value. Hand-written\n * `ActiveSurface` values predate sources; they are not sources until they\n * grow `instancesOf`, and consumers that still take them read `projectionOf`\n * directly.\n */\n instances: <Root>(\n source: SurfaceSource<Root>,\n model: Root,\n ): ReadonlyArray<SurfaceInstance<Root, any, any>> => source.instancesOf(model),\n\n make: <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Params = void,\n Model = unknown,\n const Ms extends readonly MessageConstructor<Cases>[] = readonly [],\n >(\n app: AppScope<Root, F, Cases>,\n name: string,\n config: {\n readonly Params?: Schema.Codec<Params, unknown>\n readonly model: (context: {\n readonly model: RefTree<Root, F>\n readonly params: Params\n }) => Projection<Root, Model>\n readonly messages?: Ms\n },\n ): Surface<Root, Model, MsgOf<Ms>, Params> => {\n // Deliberately no eager `projection(undefined)`: a parameterized Surface's\n // projection may read `params`.\n const projection = (params: Params): Projection<Root, Model> => {\n // The types refuse a missing argument; a caller typed `any`, or plain\n // JavaScript, otherwise meets a TypeError from inside `model`.\n if (\n params === undefined &&\n config.Params !== undefined &&\n !Schema.is(config.Params)(undefined)\n ) {\n throw new Error(`Surface \"${name}\" declares params, and was given none`)\n }\n return config.model({ model: app.model, params })\n }\n return {\n name,\n owner: app.owner,\n // Absent only when `Params` is exactly `void`; `ParamsSchema` keeps it optional otherwise.\n Params: config.Params as ParamsSchema<Params>,\n Message: Schema.Never as unknown as Schema.Schema<MsgOf<Ms>>,\n messages: config.messages ?? [],\n projection,\n }\n },\n\n read: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n root: Root,\n ...params: ParamsArgument<Params>\n ): Model => surface.projection(params[0] as Params).read(root),\n\n /**\n * Binds a renderer to a Surface's projected Model and Message set. A\n * type-level binder: the renderer already has this shape, but `Model` and\n * `Message` are derived from the Surface instead of written by hand.\n */\n view: <Root, Model, Message, Params>(\n _surface: Surface<Root, Model, Message, Params>,\n render: Renderer<Model, Message>,\n ): Renderer<Model, Message> => render,\n\n /**\n * The application boundary: consume the Root Model, project it, and hand the\n * projected Model to the renderer. `Subset` rejects a Surface whose Messages\n * the application builder cannot route.\n */\n rootView: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n params: Params,\n render: Renderer<Model, Message>,\n ): (<AppMessage>(\n root: Root,\n h: HtmlBuilder<AppMessage> & Subset<Message, AppMessage>,\n ) => Html) => {\n const projection = surface.projection(params)\n // Sound narrowing: the renderer can only construct this Surface's Messages,\n // and `Subset` guarantees the application builder accepts them.\n return <AppMessage>(\n root: Root,\n h: HtmlBuilder<AppMessage> & Subset<Message, AppMessage>,\n ): Html => render(projection.read(root), h as unknown as ViewBuilder<Message>)\n },\n\n /**\n * Embeds a child renderer in a parent view. `ParentModel extends ChildModel`\n * enforces \"child Model requirement ⊆ parent projected Model\"; `Subset`\n * enforces \"child Message set ⊆ parent Message set\".\n */\n embed:\n <ChildModel, ChildMessage>(child: Renderer<ChildModel, ChildMessage>) =>\n <ParentModel extends ChildModel, ParentMessage>(\n model: ParentModel,\n h: ViewBuilder<ParentMessage> & Subset<ChildMessage, ParentMessage>,\n ): Html =>\n child(model, h as unknown as ViewBuilder<ChildMessage>),\n\n /**\n * A Surface as a `Contract` for `Module`: what it observes, requires, and may\n * emit. A parameterized Surface needs its `params` to build the projection.\n */\n contract: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n ...params: ParamsArgument<Params>\n ): Contract => {\n const projection = surface.projection(params[0] as Params)\n return {\n kind: 'surface',\n name: surface.name,\n owner: surface.owner,\n owns: [],\n observes: projection.dependencies,\n messages: messageTags(surface),\n metadata: Metadata.summarize(projection.metadata),\n }\n },\n\n /**\n * Pure introspection for DevTools: what a Surface observes (dependencies,\n * requirements) and what it may emit. No behavior change, no I/O.\n */\n inspect: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n ...params: ParamsArgument<Params>\n ): SurfaceInspection => {\n const projection = surface.projection(params[0] as Params)\n return {\n name: surface.name,\n dependencies: projection.dependencies,\n metadata: Metadata.summarize(projection.metadata),\n emits: surface.messages,\n }\n },\n}\n\n// ===========================================================================\n// Entity, Selection, Remote moved to `foldkit-remote` (Phase 3).\n// ===========================================================================\n\n// ===========================================================================\n// Module: the pure composition root\n// ===========================================================================\n\n/**\n * What one contract claims about an application, as data. Sync, Remote, and\n * Agent attach one to the values they produce; `Surface.contract` derives one\n * from a Surface. `owns` are the Model paths the contract is the authority for\n * (a replicated projection, a remote store); `observes` are the paths it reads.\n */\nexport interface Contract {\n readonly kind: string\n readonly name: string\n /** The application's identity token; absent when the value cannot know it. */\n readonly owner?: object | undefined\n readonly owns: DependencyTree\n readonly observes: DependencyTree\n /** Message tags the contract may cause, expose, or record. */\n readonly messages: readonly string[]\n /** What interpreters attached to the contract's reads, as text. */\n readonly metadata: readonly MetadataSummary[]\n}\n\n/**\n * How one integration joins an application, as data and pure functions: the\n * Messages it routes, what it runs at startup and on a URL change, its\n * Subscriptions and Managed Resources, and its contract. Remote, Mirror, Sync,\n * and Agent produce one; `foldkit-bundle`'s assembly derives the application's\n * `update`, initial state, runtime config, and Module from a list of them.\n * `R` is the services its Commands and Subscriptions need.\n */\nexport interface Wiring<Model, Message, R = never, Claims extends string = string> {\n /** Names the integration in errors and the Module: `remote:Board`, `mirror:filters`. */\n readonly key: string\n /**\n * Message tags `route` handles. Two integrations handling one tag is an error\n * unless it is `shared`. Typed as literals (`Claims`), the tags it does not\n * share leave the parent's own update in `foldkit-bundle`'s assembly. A wiring\n * with literal `Claims` that shares some gives `shared` a literal type too: a\n * plain `string[]` there reads as sharing none.\n */\n readonly handles: ReadonlyArray<Claims>\n /** Tags several integrations may handle, each for its own values (Mirror's `MirrorRestored`, by name). */\n readonly shared?: readonly string[] | undefined\n /**\n * Folds a Message this integration handles; `None` for any other. A method, so\n * a wiring that routes only its own variants fits an assembly over the whole\n * application union.\n */\n route?(model: Model, message: Message): Option.Option<Update.Return<Model, Message, R>>\n /** Runs once when the application starts, after placements: a restore Command, a warm-up. */\n readonly init?: Update.Step<Model, Message, R> | undefined\n /** Applies the URL to the Model, at startup and whenever the URL changes. */\n readonly onUrl?: ((model: Model, url: Url) => Model) | undefined\n readonly subscriptions?: Subscriptions<Model, Message, R> | undefined\n readonly resources?:\n | Readonly<Record<string, ManagedResourceEntry<Model, Message, any, any, any>>>\n | undefined\n /** Its Module contract; absent for wiring that owns and observes nothing. */\n readonly contract?: Contract | undefined\n}\n\n/** Contracts of one application, in declaration order. Data, not a runtime. */\nexport interface Module<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> {\n readonly app: AppScope<Root, F, Cases>\n readonly contracts: readonly Contract[]\n}\n\nexport interface Finding {\n readonly rule:\n | 'foreign-contract'\n | 'duplicate-name'\n | 'ownership-overlap'\n | 'message-claimed-twice'\n | 'unknown-path'\n | 'unknown-message'\n /** `kind:name` of each contract involved. */\n readonly contracts: readonly string[]\n readonly message: string\n}\n\n/** Who owns a Model path; `undefined` is local state. */\nexport interface Ownership {\n readonly path: readonly string[]\n readonly owner: { readonly kind: string; readonly name: string } | undefined\n}\n\nexport interface ModuleManifest {\n readonly fields: readonly string[]\n readonly messages: readonly string[]\n readonly ownership: readonly Ownership[]\n readonly contracts: readonly Omit<Contract, 'owner'>[]\n readonly findings: readonly Finding[]\n}\n\n/** A value `Module.make` accepts: a contract, a value carrying one, or a Surface without params. */\nexport type ModuleItem<Root> =\n | Contract\n | { readonly contract: Contract }\n | Surface<Root, any, any, void>\n\nconst label = (contract: Contract): string => `${contract.kind}:${contract.name}`\n/** Metadata summaries are application data (a query's input), so they cannot break the table. */\nconst tableCell = (text: string): string =>\n text\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r\\n?|\\n/g, ' ')\nconst pathKey = (path: readonly string[]): string => path.join('.')\nconst isPrefix = (prefix: readonly string[], path: readonly string[]): boolean =>\n prefix.length <= path.length && prefix.every((segment, index) => segment === path[index])\n\n// A carried contract wins: a sync contract also has a `projection` (writable, not a function).\nconst toContract = <Root>(item: ModuleItem<Root>): Contract =>\n 'contract' in item\n ? item.contract\n : 'projection' in item\n ? Surface.contract(item, undefined)\n : item\n\nconst applicationTags = (app: AppScope<any, any, any>): readonly string[] =>\n Object.entries(app.Message as unknown as Record<string, unknown>)\n .filter(([key, value]) => messageTag(value) === key)\n .map(([key]) => key)\n\n/** Contracts that own at least one path, with a stable label. */\nconst owners = (module: Module<any, any, any>) =>\n module.contracts.filter(contract => contract.owns.length > 0)\n\n/**\n * Collects an application's contracts as pure data so their relationships can\n * be validated and inspected without starting a runtime.\n *\n * ```ts\n * const Project = Module.make(App, [BoardSurface, ProjectSync, ProjectRemote, ProjectAgent])\n * Module.validate(Project) // findings, or []\n * Module.toMarkdown(Project)\n * ```\n */\nexport const Module = {\n make: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(\n app: AppScope<Root, F, Cases>,\n items: readonly ModuleItem<Root>[] = [],\n ): Module<Root, F, Cases> => ({ app, contracts: items.map(toContract) }),\n\n /** A new Module with more contracts; the input is unchanged. */\n add: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(\n module: Module<Root, F, Cases>,\n ...items: readonly ModuleItem<Root>[]\n ): Module<Root, F, Cases> => ({\n app: module.app,\n contracts: [...module.contracts, ...items.map(toContract)],\n }),\n\n /**\n * Cross-contract invariants the types cannot express: a contract from another\n * application, a duplicate `kind:name`, two owners of overlapping Model paths,\n * a Message recorded by two replication contracts, and a path or Message the\n * application does not declare.\n */\n validate: (module: Module<any, any, any>): readonly Finding[] => {\n const findings: Finding[] = []\n const fields = new Set(Object.keys(module.app.Model.fields))\n const tags = new Set(applicationTags(module.app))\n const seen = new Map<string, Contract>()\n\n for (const contract of module.contracts) {\n const name = label(contract)\n if (contract.owner !== undefined && contract.owner !== module.app.owner)\n findings.push({\n rule: 'foreign-contract',\n contracts: [name],\n message: `${name} belongs to a different application`,\n })\n const duplicate = seen.get(name)\n if (duplicate !== undefined && duplicate !== contract)\n findings.push({\n rule: 'duplicate-name',\n contracts: [name],\n message: `${name} is declared twice`,\n })\n seen.set(name, contract)\n for (const path of [...contract.owns, ...contract.observes]) {\n const head = path[0]\n if (head === undefined || !fields.has(head))\n findings.push({\n rule: 'unknown-path',\n contracts: [name],\n message: `${name} references \"${pathKey(path)}\", which is not a Model field`,\n })\n }\n for (const tag of contract.messages)\n if (!tags.has(tag))\n findings.push({\n rule: 'unknown-message',\n contracts: [name],\n message: `${name} names \"${tag}\", which is not a Message of this application`,\n })\n }\n\n // The same value listed twice is one owner, as `duplicate-name` treats it.\n const owning = [...new Set(owners(module))]\n for (let i = 0; i < owning.length; i += 1)\n for (let j = i + 1; j < owning.length; j += 1) {\n const a = owning[i]!\n const b = owning[j]!\n for (const pa of a.owns)\n for (const pb of b.owns)\n // An empty path is reported as `unknown-path`, not as owning everything.\n if (pa.length > 0 && pb.length > 0 && (isPrefix(pa, pb) || isPrefix(pb, pa)))\n findings.push({\n rule: 'ownership-overlap',\n contracts: [label(a), label(b)],\n message: `${label(a)} owns \"${pathKey(pa)}\" and ${label(b)} owns \"${pathKey(pb)}\"`,\n })\n }\n\n const recorded = new Map<string, Contract>()\n for (const contract of module.contracts.filter(contract => contract.kind === 'sync'))\n for (const tag of contract.messages) {\n const other = recorded.get(tag)\n if (other !== undefined && other !== contract)\n findings.push({\n rule: 'message-claimed-twice',\n contracts: [label(other), label(contract)],\n message: `\"${tag}\" is durable in both ${label(other)} and ${label(contract)}`,\n })\n else recorded.set(tag, contract)\n }\n\n return findings\n },\n\n /**\n * The application's fields and Messages, who owns each Model path (local when\n * no contract does), every contract, and the findings. Reproducible for a\n * given Module, so it can be committed and diffed.\n */\n manifest: (module: Module<any, any, any>): ModuleManifest => {\n const ownership: Ownership[] = []\n const owning = owners(module)\n for (const field of Object.keys(module.app.Model.fields)) {\n const claims = owning.flatMap(contract =>\n contract.owns\n .filter(path => path[0] === field)\n .map(path => ({ path, owner: { kind: contract.kind, name: contract.name } })),\n )\n const whole = claims.find(claim => claim.path.length === 1)\n if (whole !== undefined) ownership.push(whole)\n else {\n ownership.push({ path: [field], owner: undefined })\n ownership.push(...claims.sort((a, b) => pathKey(a.path).localeCompare(pathKey(b.path))))\n }\n }\n return {\n fields: Object.keys(module.app.Model.fields),\n messages: applicationTags(module.app),\n ownership,\n contracts: module.contracts.map(({ owner: _owner, ...rest }) => rest),\n findings: Module.validate(module),\n }\n },\n\n /** The manifest as Markdown: the ownership tree, a table of contracts, and findings. */\n toMarkdown: (module: Module<any, any, any>): string => {\n const manifest = Module.manifest(module)\n const lines: string[] = ['```text', 'Model']\n const width = Math.max(0, ...manifest.ownership.map(row => pathKey(row.path).length))\n manifest.ownership.forEach((row, index) => {\n const last = index === manifest.ownership.length - 1\n const owner =\n row.owner === undefined ? 'LOCAL' : `${row.owner.kind.toUpperCase()} ${row.owner.name}`\n lines.push(`${last ? '└── ' : '├── '}${pathKey(row.path).padEnd(width)} ${owner}`)\n })\n lines.push(\n '```',\n '',\n '| Contract | Owns | Observes | Messages | Metadata |',\n '| --- | --- | --- | --- | --- |',\n )\n for (const contract of manifest.contracts)\n lines.push(\n `| ${contract.kind}:${contract.name} | ${contract.owns.map(pathKey).join(', ')} | ${contract.observes.map(pathKey).join(', ')} | ${contract.messages.join(', ')} | ${tableCell(contract.metadata.map(summary => `${summary.name}: ${summary.entries.join(', ')}`).join('; '))} |`,\n )\n if (manifest.findings.length > 0) {\n lines.push('', '## Findings', '')\n for (const finding of manifest.findings)\n lines.push(`- **${finding.rule}** ${finding.message}`)\n }\n return lines.join('\\n')\n },\n\n /**\n * The manifest as a Mermaid flowchart: Model fields in a subgraph, one node\n * per contract, a solid edge for ownership and a dotted edge for observation.\n */\n toMermaid: (module: Module<any, any, any>): string => {\n const manifest = Module.manifest(module)\n const lines = ['flowchart LR', ' subgraph Model']\n manifest.fields.forEach((field, index) => lines.push(` f${index}[\"${field}\"]`))\n lines.push(' end')\n // A path outside the Model (reported by `validate`) draws no edge.\n const fieldId = (path: readonly string[]): string | undefined => {\n const index = path.length === 0 ? -1 : manifest.fields.indexOf(path[0]!)\n return index < 0 ? undefined : `f${index}`\n }\n manifest.contracts.forEach((contract, index) => {\n lines.push(` c${index}[\"${contract.kind}:${contract.name}\"]`)\n for (const path of contract.owns) {\n const field = fieldId(path)\n if (field !== undefined) lines.push(` c${index} -->|owns| ${field}`)\n }\n for (const path of contract.observes) {\n const field = fieldId(path)\n if (field !== undefined && !contract.owns.some(owned => pathKey(owned) === pathKey(path)))\n lines.push(` c${index} -.-> ${field}`)\n }\n })\n return lines.join('\\n')\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,YAA2B,OAAO,IAAI,0BAA0B;AA8C7E,MAAM,aACJ,QACA,OACA,YACA,KACA,SACwB;CACxB;CACA;CACA;CACA;CACA;CACA,SAAS,MAAM,OAAO,IAAI,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC;AAC/C;AAEA,MAAa,WAAW;;;;;CAKtB,YACE,QACA,OACA,aAAgC,CAAC,OACN,GAC1B,YAAY,UACX,QACA,OACA,aACA,SAAQ,OAAO,WAAW,MAAM,UAAU,IAAI,CAAC,IAC9C,MAAM,UAAU,MAAM,QAAQ,OAAO,IAAI,CAC5C,EACF;;;;;;CAMA,QAAoD,QAClD,IAAI;;CAEN,KAAK,UACH,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;AAChE;AAsEA,SAAS,eAAe,MAAe,KAAsB;CAC3D,OAAO,SAAS,QAAQ,SAAS,KAAA,KAAa,CAAC,OAAO,OAA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ata"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-surface` — the observation boundary for a Foldkit application.\n *\n * A Surface is a pure projection of the Model: it declares which fields a\n * feature reads and which Messages it may construct, from the application's\n * own Schema rather than a second hand-written interface. `foldkit-remote`,\n * `foldkit-sync`, `foldkit-agent`, and `foldkit-mirror` all read this boundary,\n * and `Module` validates that each Model path has one owner.\n *\n * Nothing here runs: the deliverable is the type surface, pinned by\n * `test/inference.test-d.ts`.\n */\nimport { Optic, Option, Predicate, Result, Schema } from 'effect'\nimport type { Html, HtmlBuilder } from 'foldkit/html'\nimport type { MessageUnion } from 'foldkit/message'\nimport type { Entry as ManagedResourceEntry } from 'foldkit/managedResource'\nimport type { Subscriptions } from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport type { Url } from 'foldkit/url'\nimport { Metadata, type MetadataSummary } from 'foldkit-metadata'\n\nexport { Metadata, MetadataTypeId, type MetadataKey, type MetadataSummary } from 'foldkit-metadata'\nexport { Diagnostics, type Diagnostic, type ReportDiagnostic } from './diagnostics.js'\n\n// ===========================================================================\n// ModelRef and the typed Model tree (Phase 0 cases 1)\n// ===========================================================================\n\n/**\n * The key a ref keeps its own members under; read them with `ModelRef.focus`.\n * A ref's string keys are the Model's fields, whatever their names (#331),\n * and no Schema field reaches a symbol. `Symbol.for`, so two copies of this\n * package read each other's refs.\n */\nexport const RefTypeId: unique symbol = Symbol.for('foldkit-surface/ModelRef')\n\n/** What a ref points at and how to read and write it: `ModelRef.focus(ref)`. */\nexport interface Focus<Root, Value, Encoded = unknown> {\n /** A pure codec: Foldkit Model fields carry no decoding or encoding services. */\n readonly Schema: Schema.Codec<Value, Encoded, never, never>\n readonly optic: Optic.Optional<Root, Value>\n /** The Model path the ref points at. */\n readonly dependency: readonly string[]\n readonly get: (root: Root) => Value\n readonly set: (root: Root, value: Value) => Root\n /**\n * Focused structural replacement: `set` of `fn` applied to `get`. This\n * delegates through the focus's own `set`, so container-aware setters\n * (`at`/`index` insertion and removal) keep working — never `optic`\n * calls directly. Infrastructure seam, not an application transition.\n */\n readonly modify: (root: Root, fn: (value: Value) => Value) => Root\n}\n\n/**\n * A reference to a place in the Model. Its string keys are the fields below\n * it; its own members are its `Focus`, read with `ModelRef.focus`.\n */\nexport interface ModelRef<Root, Value, Encoded = unknown> {\n readonly [RefTypeId]: Focus<Root, Value, Encoded>\n}\n\n/**\n * A `ModelRef` generated for a named Model field. `key` is the literal field\n * name, so a reference-based selection can infer its output keys without a\n * parallel field registry or string paths.\n */\nexport interface FieldRef<\n Root,\n Value,\n Key extends string = string,\n Encoded = unknown,\n> extends ModelRef<Root, Value, Encoded> {\n readonly [RefTypeId]: Focus<Root, Value, Encoded> & {\n readonly key: Key\n /** The application definition this field was generated from. */\n readonly owner: object\n }\n}\n\nconst makeFocus = <Root, Value>(\n Schema: Schema.Codec<Value, unknown, never, never>,\n optic: Optic.Optional<Root, Value>,\n dependency: readonly string[],\n get: (root: Root) => Value,\n set: (root: Root, value: Value) => Root,\n): Focus<Root, Value> => ({\n Schema,\n optic,\n dependency,\n get,\n set,\n modify: (root, fn) => set(root, fn(get(root))),\n})\n\nexport const ModelRef = {\n /**\n * Low-level escape hatch for a focus with no Model path of its own. Prefer\n * the `App.model` tree; use this for an optic that is not part of the Model.\n */\n fromOptic: <Root, Value>(\n Schema: Schema.Schema<Value>,\n optic: Optic.Optional<Root, Value>,\n dependency: readonly string[] = [],\n ): ModelRef<Root, Value> => ({\n [RefTypeId]: makeFocus(\n Schema as unknown as Schema.Codec<Value, unknown, never, never>,\n optic,\n dependency,\n root => Result.getOrThrow(optic.getResult(root)),\n (root, value) => optic.replace(value, root),\n ),\n }),\n /**\n * A ref's own members: where it points, how to read and write it, and, as\n * its value allows, `at` (a record), `index` (an array) and `select`. They\n * are kept apart from the ref's string keys, which are the Model's fields.\n */\n focus: <R extends { readonly [RefTypeId]: object }>(ref: R): R[typeof RefTypeId] =>\n ref[RefTypeId],\n /** Whether a value is a ref, as opposed to a Projection or a plain object. */\n is: (value: unknown): value is ModelRef<unknown, unknown> =>\n typeof value === 'object' && value !== null && RefTypeId in value,\n}\n\nexport type RefTree<Root, F extends Schema.Struct.Fields> = {\n readonly [K in keyof F & string]: RefNode<Root, F[K], K>\n}\n\n/** A ref whose focus can `select` a Projection of its value. */\nexport interface Selects<Root, Value> {\n readonly [RefTypeId]: {\n readonly select: <P>(projection: Projection<Value, P>) => Projection<Root, P>\n }\n}\n\n/** A ref to an optional value, whose focus selects inside the Option. */\nexport interface SelectsSome<Root, Inner> {\n readonly [RefTypeId]: {\n readonly select: <P>(projection: Projection<Inner, P>) => Projection<Root, Option.Option<P>>\n }\n}\n\n/** A ref to an array, whose focus reaches an item: `ModelRef.focus(ref).index(0)`. */\nexport interface Indexes<Root, Item> {\n readonly [RefTypeId]: {\n readonly index: (index: number) => OptionalRef<Root, Option.Option<Item>>\n }\n}\n\n/** A ref to a record, whose focus reaches an entry: `ModelRef.focus(ref).at(key)`. */\nexport interface Entries<Root, Key extends string, Value> {\n readonly [RefTypeId]: {\n readonly at: (key: Key) => OptionalRef<Root, Option.Option<Value>>\n }\n}\n\n// Tuple-wrapped so the conditional is *non-distributive*: without it,\n// `Value = Option<V>` distributes over `None | Some<V>` and `select` would\n// return a union of two unrelated projections.\ntype Select<Root, Value> = [Value] extends [Option.Option<infer Inner>]\n ? SelectsSome<Root, Inner>\n : Selects<Root, Value>\n\ntype Selectable<Root, Value, Key extends string, Encoded = unknown> = FieldRef<\n Root,\n Value,\n Key,\n Encoded\n> &\n Select<Root, Value>\n\n/**\n * A dynamic focus from `at`/`index`. Deliberately not a `FieldRef`: its key is\n * a record key or index, not a Model field, so a static `Projection.pick`\n * cannot infer a field name from it.\n */\nexport type OptionalRef<Root, Value> = ModelRef<Root, Value> & Select<Root, Value>\n\ntype RefNode<Root, S, Key extends string> =\n S extends Schema.Codec<infer A, infer Encoded, any, any>\n ? S extends Schema.Struct<infer F>\n ? Selectable<Root, A, Key, Encoded> & RefTree<Root, F>\n : A extends ReadonlyArray<infer E>\n ? Selectable<Root, A, Key, Encoded> & Indexes<Root, E>\n : A extends Readonly<Record<infer K extends string, infer V>>\n ? Selectable<Root, A, Key, Encoded> & Entries<Root, K, V>\n : Selectable<Root, A, Key, Encoded>\n : never\n\ntype AnySchema = Schema.Codec<unknown, unknown>\n\n// A key may be a stored id (`at(id)`), so only the container's own keys count.\nfunction propertyReader(root: unknown, key: string): unknown {\n return root === null || root === undefined || !Object.hasOwn(root, key)\n ? undefined\n : (root as Record<string, unknown>)[key]\n}\n\nfunction optionalReader(value: unknown): Option.Option<unknown> {\n return value === undefined ? Option.none() : Option.some(value)\n}\n\n/** Reads the tag off a Foldkit Message constructor without constructing one. */\nconst messageTag = (constructor: unknown): string | undefined => {\n const literal = (constructor as { fields?: { _tag?: { ast?: { literal?: unknown } } } }).fields\n ?._tag?.ast?.literal\n return typeof literal === 'string' ? literal : undefined\n}\n\n/** Whether a Message, of an application this cannot name, has one of `tags`. */\nconst hasTagIn = (tags: ReadonlySet<string>, message: unknown): boolean =>\n Predicate.hasProperty(message, '_tag') &&\n typeof message._tag === 'string' &&\n tags.has(message._tag)\n\n/** The tags of the Messages a Surface lists in `messages`. */\nconst messageTags = (surface: { readonly messages: readonly unknown[] }): ReadonlyArray<string> =>\n surface.messages.map(messageTag).filter((tag): tag is string => tag !== undefined)\n\nfunction makeTree(\n schema: AnySchema,\n path: readonly string[],\n optic: Optic.Optional<unknown, unknown>,\n get: (root: unknown) => unknown,\n optional = false,\n set: ((root: unknown, value: unknown) => unknown) | undefined,\n owner: object,\n): Record<string, unknown> {\n const erasedOptic = optic as {\n key(key: string): Optic.Optional<unknown, unknown>\n at(key: string): Optic.Optional<unknown, unknown>\n }\n // `Optic.at` cannot *insert* or *remove* an absent key (`replace` is a no-op\n // when the prism fails), so optional foci get container-aware setters below.\n const setFocus = set ?? ((root: unknown, value: unknown): unknown => optic.replace(value, root))\n const focus: Record<string, unknown> = {\n ...makeFocus(schema as never, optic, path, get, setFocus),\n key: path[path.length - 1] ?? '',\n owner,\n }\n const node: Record<PropertyKey, unknown> = { [RefTypeId]: focus }\n\n const fields = (schema as { readonly fields?: Schema.Struct.Fields }).fields\n if (fields !== undefined) {\n for (const key of Object.keys(fields)) {\n // Defined, not assigned: assigning `__proto__` would set the prototype.\n Object.defineProperty(node, key, {\n value: makeTree(\n fields[key] as AnySchema,\n [...path, key],\n erasedOptic.key(key),\n root => propertyReader(get(root), key),\n false,\n undefined,\n owner,\n ),\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n }\n\n focus.at = (key: string) =>\n makeTree(\n schema,\n [...path, key],\n erasedOptic.at(key),\n root => optionalReader(propertyReader(get(root), key)),\n true,\n (root, value) => {\n const container = get(root) as Record<string, unknown>\n const option = value as Option.Option<unknown>\n if (Option.isSome(option)) {\n return setFocus(root, { ...container, [key]: option.value })\n }\n const { [key]: _removed, ...rest } = container\n return setFocus(root, rest)\n },\n owner,\n )\n focus.index = (index: number) =>\n makeTree(\n schema,\n [...path, String(index)],\n optic,\n root =>\n optionalReader(\n Array.isArray(get(root)) ? (get(root) as ReadonlyArray<unknown>)[index] : undefined,\n ),\n true,\n (root, value) => {\n const array = (Array.isArray(get(root)) ? get(root) : []) as ReadonlyArray<unknown>\n const option = value as Option.Option<unknown>\n const next = Option.isSome(option)\n ? array.map((item, i) => (i === index ? option.value : item))\n : array.filter((_, i) => i !== index)\n return setFocus(root, next)\n },\n owner,\n )\n focus.select = (projection: Projection<unknown, unknown>) => {\n const dependencies = mergeDependencies([path, ...projection.dependencies])\n return optional\n ? makeProjection(\n Schema.Option(projection.Model),\n dependencies,\n root => Option.map(get(root) as Option.Option<unknown>, value => projection.read(value)),\n projection.metadata,\n )\n : makeProjection(\n projection.Model,\n dependencies,\n root => projection.read(get(root)),\n projection.metadata,\n )\n }\n return node\n}\n\n// ===========================================================================\n// Projection (Phase 0 case 2)\n// ===========================================================================\n\nexport type DependencyTree = readonly (readonly string[])[]\n\n/** Unions dependency trees, dropping duplicates; the result is a set. */\nfunction mergeDependencies(dependencies: DependencyTree): DependencyTree {\n const seen = new Set<string>()\n const merged: (readonly string[])[] = []\n for (const dependency of dependencies) {\n const key = dependency.join('\\u0000')\n if (seen.has(key)) continue\n seen.add(key)\n merged.push(dependency)\n }\n return merged\n}\n\nexport interface Projection<Root, Value> {\n readonly Model: Schema.Codec<Value, unknown>\n readonly dependencies: DependencyTree\n /** Interpreter-owned facts about this node and everything it composes. */\n readonly metadata: Metadata\n readonly read: (root: Root) => Value\n}\n\n/**\n * A projection Surface can install back into a Model. Public reads use the\n * read-only `Projection`; only a writable selection carries installation.\n * `set` writes exactly the declared fields, so an excess field in an untrusted\n * value cannot reach local state.\n */\nexport interface WritableProjection<Model, Fields extends Schema.Struct.Fields> {\n readonly schema: Schema.Struct<Fields>\n readonly dependencies: DependencyTree\n readonly get: (model: Model) => Schema.Struct.Type<Fields>\n readonly set: (model: Model, shared: Schema.Struct.Type<Fields>) => Model\n}\n\nfunction makeProjection<Value>(\n Model: Schema.Codec<Value, unknown>,\n dependencies: DependencyTree,\n read: (root: unknown) => Value,\n metadata: Metadata = Metadata.empty,\n): Projection<unknown, Value> {\n return { Model, dependencies, metadata, read }\n}\n\n/**\n * `Schema.Struct({})` is not an empty-object schema: it accepts `{foo:1}`, `[]`,\n * and `\"str\"` even with `onExcessProperty: 'error'`. A genuinely empty selection\n * needs a `never`-valued record.\n */\nfunction objectSchema(fields: Record<string, AnySchema>): AnySchema {\n return Object.keys(fields).length === 0\n ? Schema.Record(Schema.String, Schema.Never)\n : Schema.Struct(fields)\n}\n\ntype OfSelection<F extends Schema.Struct.Fields> = {\n readonly [K in keyof F]?: true | Projection<Schema.Schema.Type<F[K]>, unknown>\n}\n\ntype OfValue<F extends Schema.Struct.Fields, Sel> = {\n readonly [K in keyof Sel & keyof F]: Sel[K] extends true\n ? Schema.Schema.Type<F[K]>\n : Sel[K] extends Projection<any, infer V>\n ? V\n : never\n}\n\ntype EntryValue<E> =\n E extends Projection<any, infer V> ? V : E extends ModelRef<any, infer V> ? V : never\n\ntype EntryRoot<E> =\n E extends Projection<infer R, any> ? R : E extends ModelRef<infer R, any> ? R : never\n\ntype EntryRoots<Entries> = { readonly [K in keyof Entries]: EntryRoot<Entries[K]> }\n\n/** `true` when the union has more than one member. Used to reject mixed roots. */\ntype IsUnion<T, U = T> = [T] extends [never]\n ? false\n : T extends unknown\n ? [U] extends [T]\n ? false\n : true\n : never\n\ntype StructValue<Entries> = {\n readonly [K in keyof Entries]: EntryValue<Entries[K]>\n} extends infer Value\n ? { readonly [K in keyof Value]: Value[K] }\n : never\n\n// What reads something no path of its own names: a Remote read, named by its\n// metadata, declares no path, and a Projection composing one declares only its\n// other parts' paths. `derive` cannot skip a read of either. A set, not a\n// field, since only a derivation asks.\nconst readsUnnamed = new WeakSet<object>()\n\nconst unnamed = (entry: { readonly dependencies: DependencyTree }): boolean =>\n entry.dependencies.length === 0 || readsUnnamed.has(entry)\n\nconst markedBy = <P extends object>(\n composed: P,\n parts: ReadonlyArray<{ readonly dependencies: DependencyTree }>,\n): P => {\n if (parts.some(unnamed)) readsUnnamed.add(composed)\n return composed\n}\n\n/** A value derived from the Model and the paths it reads: what `Projection.derive` makes. */\nexport interface Derived<Root, Value> {\n readonly dependencies: DependencyTree\n readonly read: (root: Root) => Value\n}\n\nconst valueAt = (root: unknown, path: ReadonlyArray<string>): unknown => {\n let value = root\n for (const key of path) {\n if (typeof value !== 'object' || value === null) return undefined\n value = (value as Record<string, unknown>)[key]\n }\n return value\n}\n\n// The earlier value when the new one holds the same fields: a struct is a new record every time.\nconst keepAlike = <Value>(before: Value, value: Value): Value =>\n sameFields(before, value) ? before : value\n\nconst sameFields = (left: unknown, right: unknown): boolean => {\n if (Object.is(left, right)) return true\n if (typeof left !== 'object' || typeof right !== 'object' || left === null || right === null)\n return false\n const prototype = Object.getPrototypeOf(left)\n const plain = prototype === Object.prototype || prototype === null || Array.isArray(left)\n if (!plain || Object.getPrototypeOf(right) !== prototype) return false\n const keys = Object.keys(left)\n return (\n keys.length === Object.keys(right).length &&\n keys.every(\n key =>\n Object.hasOwn(right, key) &&\n Object.is((left as Record<string, unknown>)[key], (right as Record<string, unknown>)[key]),\n )\n )\n}\n\nexport const Projection = {\n of:\n <F extends Schema.Struct.Fields>(schema: Schema.Struct<F>) =>\n <const Sel extends OfSelection<F>>(\n selection: Sel,\n ): Projection<Schema.Struct.Type<F>, OfValue<F, Sel>> => {\n // No prototype, so a field named `__proto__` stays a key (see `struct`).\n const picked: Record<string, AnySchema> = Object.create(null)\n const dependencies: (readonly string[])[] = []\n const metadata: Metadata[] = []\n // A field picked with `true` declares no path of its own.\n const parts: { readonly dependencies: DependencyTree }[] = []\n const readers: (readonly [string, (root: unknown) => unknown])[] = []\n\n for (const key of Object.keys(selection)) {\n const choice = (selection as Record<string, unknown>)[key]\n if (choice === true) {\n picked[key] = schema.fields[key] as AnySchema\n parts.push({ dependencies: [] })\n readers.push([key, root => propertyReader(root, key)])\n } else {\n const nested = choice as Projection<unknown, unknown>\n picked[key] = nested.Model\n dependencies.push(...nested.dependencies)\n metadata.push(nested.metadata)\n parts.push(nested)\n readers.push([key, root => nested.read(propertyReader(root, key))])\n }\n }\n\n const read = (root: unknown): unknown => {\n const out: Record<string, unknown> = Object.create(null)\n for (const [key, reader] of readers) out[key] = reader(root)\n return out\n }\n return markedBy(\n makeProjection(\n objectSchema(picked),\n mergeDependencies(dependencies),\n read,\n Metadata.combine(metadata),\n ),\n parts,\n ) as unknown as Projection<Schema.Struct.Type<F>, OfValue<F, Sel>>\n },\n\n struct: <const Entries extends Record<string, Projection<any, any> | ModelRef<any, any>>>(\n entries: Entries & (IsUnion<EntryRoots<Entries>[keyof Entries]> extends true ? never : unknown),\n ): Projection<EntryRoot<Entries[keyof Entries]>, StructValue<Entries>> => {\n // Keys may be stored ids (a page's node ids), so `__proto__` must stay a key.\n const picked: Record<string, AnySchema> = Object.create(null)\n const dependencies: (readonly string[])[] = []\n const metadata: Metadata[] = []\n const nesteds: Projection<unknown, unknown>[] = []\n const readers: (readonly [string, (root: unknown) => unknown])[] = []\n\n for (const key of Object.keys(entries)) {\n const entry = entries[key] as Projection<unknown, unknown> | ModelRef<unknown, unknown>\n if (ModelRef.is(entry)) {\n const focus = entry[RefTypeId]\n picked[key] = focus.Schema\n dependencies.push(focus.dependency)\n readers.push([key, focus.get])\n } else {\n picked[key] = entry.Model\n dependencies.push(...entry.dependencies)\n metadata.push(entry.metadata)\n nesteds.push(entry)\n readers.push([key, entry.read])\n }\n }\n\n const read = (root: unknown): unknown => {\n const out: Record<string, unknown> = Object.create(null)\n for (const [key, reader] of readers) out[key] = reader(root)\n return out\n }\n return markedBy(\n makeProjection(\n objectSchema(picked),\n mergeDependencies(dependencies),\n read,\n Metadata.combine(metadata),\n ),\n nesteds,\n ) as unknown as Projection<EntryRoot<Entries[keyof Entries]>, StructValue<Entries>>\n },\n\n /**\n * Maps a Projection over an array: `array(p): Projection<ReadonlyArray<Root>,\n * ReadonlyArray<Value>>`. Nesting is explicit (an array of arrays stays an\n * array of arrays); there is no flatten or double-wrap.\n */\n array: <Root, Value>(\n projection: Projection<Root, Value>,\n ): Projection<ReadonlyArray<Root>, ReadonlyArray<Value>> =>\n markedBy(\n {\n Model: Schema.Array(projection.Model),\n dependencies: projection.dependencies,\n metadata: projection.metadata,\n read: root => root.map(value => projection.read(value)),\n },\n [projection],\n ),\n\n /** Maps a Projection inside an Option, preserving absence. */\n option: <Root, Value>(\n projection: Projection<Root, Value>,\n ): Projection<Option.Option<Root>, Option.Option<Value>> =>\n markedBy(\n {\n Model: Schema.Option(projection.Model),\n dependencies: projection.dependencies,\n metadata: projection.metadata,\n read: root => Option.map(root, value => projection.read(value)),\n },\n [projection],\n ),\n\n read: <Root, Value>(projection: Projection<Root, Value>, root: Root): Value =>\n projection.read(root),\n\n /**\n * Low-level escape hatch: a Projection from a Schema and a reader, for\n * projections not derived from ModelRefs (agent context, adapters). Prefer\n * `of`/`struct`/`select`; dependencies default to empty.\n */\n fromReader: <Root, Value>(\n Model: Schema.Codec<Value, unknown>,\n read: (root: Root) => Value,\n options?: {\n readonly dependencies?: DependencyTree\n readonly metadata?: Metadata\n },\n ): Projection<Root, Value> => ({\n Model,\n dependencies: options?.dependencies ?? [],\n metadata: options?.metadata ?? Metadata.empty,\n read,\n }),\n\n /**\n * A value worked out from the Model, and worked out again only when a value\n * at a path it reads is a new object: the value counterpart of\n * `foldkit-mixins`' `SlotView.region`, and what a region can be drawn from.\n * `on` names what `derive` reads, as field references or Projections;\n * `derive` must read nothing else, or it shows what it read last. While\n * something in `on` reads what no path of its names (a Remote read, alone or\n * inside a `struct`), the value is worked out on every read. A result with\n * the same fields as the last, shallowly, gives the last back, so a memo\n * keyed on it holds. It keeps one result: the one for the last Model it was\n * given.\n *\n * @example\n * ```ts\n * const shown = Projection.derive([App.model.todos, App.model.filter], (model: Model) =>\n * model.todos.filter(todo => model.filter === 'all' || todo.done === (model.filter === 'done')),\n * )\n * // In the view: shown.read(model)\n * ```\n */\n derive: <Root, Value>(\n on: ReadonlyArray<ModelRef<Root, any> | { readonly dependencies: DependencyTree }>,\n derive: (root: Root) => Value,\n ): Derived<Root, Value> => {\n if (on.length === 0) {\n throw new Error(\n 'Projection.derive: it names nothing it reads, so nothing could tell it to work the value out again. Name field references, or Projections built from them.',\n )\n }\n const parts = on.map(entry =>\n RefTypeId in entry ? { dependencies: [entry[RefTypeId].dependency] } : entry,\n )\n const dependencies = mergeDependencies(parts.flatMap(part => part.dependencies))\n // No path changes when what such a read reads does, so none can skip it.\n const always = parts.some(unnamed)\n let last: { readonly values: ReadonlyArray<unknown>; readonly value: Value } | undefined\n const derived: Derived<Root, Value> = {\n dependencies,\n read: root => {\n const values = dependencies.map(path => valueAt(root, path))\n const before = last\n const value =\n before === undefined\n ? derive(root)\n : !always && values.every((value, index) => Object.is(value, before.values[index]))\n ? before.value\n : keepAlike(before.value, derive(root))\n last = { values, value }\n return value\n },\n }\n if (always) readsUnnamed.add(derived)\n return derived\n },\n\n /**\n * Derives a writable projection from generated Model field references:\n * `Projection.pick(App.model.todos, App.model.selectedTodoId)` infers\n * `{ todos, selectedTodoId }` and its codec. Every reference must share one\n * Root; a raw optic or an unrelated application is rejected. Repeated\n * identical members deduplicate; a conflicting definition throws.\n */\n pick: <const Refs extends readonly FieldRef<any, any, string>[]>(\n ...refs: Refs & (IsUnion<RefRoots<Refs>[number]> extends true ? never : unknown)\n ): WritableProjection<RefRoots<Refs>[number], PickFields<Refs>> => {\n const selected = refs.map(ref => ref[RefTypeId])\n // Two applications can have structurally identical Models, so the root type\n // check cannot separate them; the owner token can.\n const owner = selected[0]?.owner\n for (const focus of selected) {\n if (focus.owner !== owner) {\n throw new Error('Projection.pick: references from different applications')\n }\n }\n // A picked field is named by its last key alone, so two fields at\n // different paths with the same name would be one field: `get` would keep\n // one value and `set` would write it into both. The same field picked twice\n // is harmless and kept once; two different ones are refused here.\n // No prototype: a field named `constructor` must not read as already picked.\n const fields: Record<string, AnySchema> = Object.create(null)\n const paths: Record<string, string> = Object.create(null)\n for (const focus of [...selected]) {\n const path = focus.dependency.join('.')\n const existing = paths[focus.key]\n if (existing !== undefined) {\n if (existing === path) {\n selected.splice(selected.indexOf(focus), 1)\n continue\n }\n throw new Error(\n `Projection.pick: \"${existing}\" and \"${path}\" would both be read as \"${focus.key}\". Pick them in separate projections.`,\n )\n }\n paths[focus.key] = path\n fields[focus.key] = focus.Schema\n }\n return {\n schema: objectSchema(fields) as never,\n dependencies: mergeDependencies(selected.map(focus => focus.dependency)),\n get: model => {\n const out: Record<string, unknown> = Object.create(null)\n for (const focus of selected) out[focus.key] = focus.get(model as never)\n return out as never\n },\n set: (model, shared) => {\n let next = model\n for (const focus of selected)\n next = focus.set(next as never, (shared as Record<string, unknown>)[focus.key] as never)\n return next\n },\n }\n },\n\n /**\n * Merges disjoint writable projections into one: `Projection.compose(Todos,\n * Selection)`. Every projection must own the same Model; a field defined twice\n * with a different codec throws, while an identical definition deduplicates.\n * `set` installs each part, so composed fields keep their own write behaviour.\n */\n compose: <const Ps extends readonly WritableProjection<any, any>[]>(\n ...projections: Ps & (IsUnion<ProjectionModel<Ps[number]>> extends true ? never : unknown)\n ): WritableProjection<ProjectionModel<Ps[number]>, MergeFields<Ps>> => {\n const parts = [...projections]\n const fields: Record<string, AnySchema> = Object.create(null)\n // Where each field is read from, where the part says: a dependency path\n // ending in the field's name. The same name from two different paths is two\n // fields that would be read as one, as in `pick`.\n const paths: Record<string, string> = Object.create(null)\n const pathOf = (part: (typeof parts)[number], key: string): string | undefined =>\n part.dependencies.find(dependency => dependency.at(-1) === key)?.join('.')\n for (const part of parts) {\n for (const [key, codec] of Object.entries(part.schema.fields)) {\n const existing = fields[key]\n const path = pathOf(part, key)\n if (existing !== undefined) {\n const previous = paths[key]\n if (previous !== undefined && path !== undefined && previous !== path) {\n throw new Error(\n `Projection.compose: \"${previous}\" and \"${path}\" would both be read as \"${key}\"`,\n )\n }\n if (existing === codec) continue\n throw new Error(`Projection.compose: conflicting definitions for \"${key}\"`)\n }\n fields[key] = codec as AnySchema\n if (path !== undefined) paths[key] = path\n }\n }\n return {\n schema: objectSchema(fields) as never,\n dependencies: mergeDependencies(parts.flatMap(part => [...part.dependencies])),\n get: model => {\n const out: Record<string, unknown> = Object.create(null)\n for (const part of parts) Object.assign(out, part.get(model as never))\n return out as never\n },\n set: (model, shared) => {\n let next = model\n // Each part reads only its own fields from the merged value.\n for (const part of parts) next = part.set(next as never, shared as never)\n return next\n },\n }\n },\n}\n\n// ===========================================================================\n// Surface (Phase 0 case 3)\n// ===========================================================================\n\nexport interface AppScope<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n readonly model: RefTree<Root, F>\n /** Identity token shared by this application's references and subsets. */\n readonly owner: object\n}\n\nexport interface SurfaceInspection {\n readonly name: string\n readonly dependencies: DependencyTree\n readonly metadata: readonly MetadataSummary[]\n readonly emits: readonly unknown[]\n}\n\n/**\n * A Surface's params codec: present when the Surface declares params, absent\n * when `Params` is `void`, and possibly either when `Params` is `any`/`unknown`\n * so a params Surface still fits a `Surface<…, any>` position.\n */\nexport type ParamsSchema<Params> = unknown extends Params\n ? Schema.Codec<Params, unknown> | undefined\n : [Params] extends [void]\n ? [void] extends [Params]\n ? // Exactly `void`: no params, no schema.\n undefined\n : // `undefined` also extends `void`, but a Surface may still declare its schema.\n Schema.Codec<Params, unknown> | undefined\n : [void] extends [Params]\n ? // `void | X`: the schema is optional.\n Schema.Codec<Params, unknown> | undefined\n : Schema.Codec<Params, unknown>\n\n/**\n * The params argument of `Surface.read`, `contract` and `inspect`: required\n * unless `undefined` is a params value, as it is for a Surface without params.\n */\ntype ParamsArgument<Params> = undefined extends Params ? [params?: Params] : [params: Params]\n\nexport interface Surface<Root, Model, Message, Params> {\n readonly name: string\n /** Identity token of the application this Surface belongs to. */\n readonly owner: object\n readonly Params: ParamsSchema<Params>\n readonly Message: Schema.Schema<Message>\n readonly messages: readonly unknown[]\n readonly projection: (params: Params) => Projection<Root, Model>\n}\n\n/**\n * A Surface as the Model activates it: its params are a function of the Model\n * (`undefined` while inactive), so its requirements are too. `Surface.at`\n * builds one; a Subscription derives what to fetch, subscribe, and retain\n * from a list of them.\n */\n/**\n * Why a Surface is active, when that is something other than a callback.\n *\n * `Surface.at` takes an arbitrary function of the Model, which is correct and\n * opaque: nothing can say *why* the Surface is on without running it. When\n * activation is a tagged value at a known place — a route, a mode, a\n * selection — `Surface.when` records the place and the tag, and a manifest can\n * be built without evaluating anything.\n */\n/**\n * What `Surface.when` needs of a place in the Model: where it is, and how to\n * read it.\n *\n * A ref whose focus can be read, and deliberately not a whole `ModelRef`.\n * Activation **observes** — it never installs a value — so asking for a\n * writable reference would claim an authority it does not use. It also makes\n * the common case work: a field holding a tagged union is a *union of*\n * `FieldRef`s, one per case, which no single `ModelRef<Root, Value>` accepts.\n */\nexport interface ModelPlace<Root> {\n readonly [RefTypeId]: {\n /** Where the value lives, as `ModelRef.focus(place).dependency` gives it. */\n readonly dependency: readonly string[]\n readonly get: (root: Root) => unknown\n }\n}\n\nexport interface Activation {\n /** The Model path the tagged value lives at, as a focus's `dependency` gives it. */\n readonly path: readonly string[]\n /** The tag the Surface is active under; a Site node reading the viewer waits for one too. */\n readonly tag: string\n}\n\nexport interface ActiveSurface<Root, Model = unknown> {\n readonly name: string\n /** Identity token of the application the Surface belongs to. */\n readonly owner: object\n /** The projection for the params the Model gives; none while the Surface is inactive. */\n readonly projectionOf: (model: Root) => Option.Option<Projection<Root, Model>>\n /** The tags of the Messages the Surface lists in `messages`: what it may send. */\n readonly messages: ReadonlyArray<string>\n /**\n * Present when a tagged value at a known place activates the Surface\n * (`Surface.when`, or a Site node); absent for a bare `Surface.at`.\n */\n readonly activation?: Activation | undefined\n}\n\n/**\n * One Surface definition instantiated with concrete params: the unit a\n * `SurfaceSource` resolves to. `key` distinguishes instances of one Surface\n * (a Composition node id, say); a lone `Surface.at`/`Surface.when` instance\n * is keyed by its Surface name.\n */\nexport interface SurfaceInstance<Root, Model = unknown, Params = unknown> {\n readonly key: string\n readonly surface: Surface<Root, Model, unknown, Params>\n readonly params: Params\n readonly projection: Projection<Root, Model>\n}\n\n/**\n * A source of active Surface instances: what `Data.subscriptions`,\n * `Data.wiring`, `Remote.resume`, an SSR plan, an agent manifest, or DevTools\n * resolves a declaration to. `Surface.at` and `Surface.when` are sources of\n * zero or one instance; `Surface.each` of zero to many.\n */\nexport interface SurfaceSource<Root> {\n readonly name: string\n /** Identity token of the application the Surfaces belong to. */\n readonly owner: object\n /** The tags of the Messages the Surface lists: what an instance may send. */\n readonly messages: ReadonlyArray<string>\n readonly instancesOf: (model: Root) => ReadonlyArray<SurfaceInstance<Root, any, any>>\n}\n\n/**\n * One Surface definition instantiated per item of a parent Surface's Model:\n * `Surface.each` as data. `from` names the prerequisite — the family resolves\n * no instances until the parent is active — so consumers can tell the\n * requirements needed to *discover* instances from the requirements *of* the\n * discovered instances. That distinction is what lets `Data.satisfy` reach a\n * fixed point: first the parent, then what the parent reveals.\n */\nexport interface SurfaceFamily<\n Root,\n ParentModel,\n Model,\n Message,\n Params,\n> extends SurfaceSource<Root> {\n readonly from: ActiveSurface<Root, ParentModel>\n readonly child: Surface<Root, Model, Message, Params>\n /** The tags of the Messages the child Surface lists: what an instance may send. */\n readonly messages: ReadonlyArray<string>\n}\n\ndeclare const invalid: unique symbol\n\n/**\n * A compile-time failure that names its cause. Intersected onto a parameter\n * type when a type-level check fails, so the error reads as one line\n * (`Property '[invalid]' is missing … required in type 'Invalid<\"…\">'`)\n * naming the descriptor, instead of a wall of structural mismatch.\n */\nexport interface Invalid<Message extends string> {\n readonly [invalid]: Message\n}\n\n/** The fields of a `Schema.Struct`, or a schema, where params are declared. */\ntype ParamsShape = Schema.Struct.Fields | Schema.Top\n\ntype ParamsOf<P> = P extends Schema.Top\n ? Schema.Schema.Type<P>\n : P extends Schema.Struct.Fields\n ? Schema.Struct.Type<P>\n : void\n\n/** What a Surface's `model` may return: a Projection, or an object of Projections and refs to lift. */\ntype ModelShape<Root> =\n | Projection<Root, unknown>\n | Record<string, Projection<Root, any> | ModelRef<Root, any>>\n\ntype ModelOf<Root, R> = R extends Projection<Root, infer M> ? M : StructValue<R>\n\nconst isProjection = (value: unknown): value is Projection<unknown, unknown> =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { read?: unknown }).read === 'function' &&\n Metadata.is((value as { metadata?: unknown }).metadata)\n\ntype MsgOf<Ms extends readonly unknown[]> = {\n readonly [K in keyof Ms]: Ms[K] extends (...args: never[]) => infer M ? M : never\n}[number]\n\n/** The union of Messages a tuple of constructors produces. */\ntype SubsetOf<Ms extends readonly unknown[]> = Ms[number] extends (...args: never[]) => infer M\n ? M\n : never\n\ntype AppMessage<Cases extends Record<string, Schema.Struct.Fields>> = Schema.Schema.Type<\n MessageUnion<Cases>\n>\n\n/** A Message constructor whose produced Message belongs to the App's universe. */\ntype MessageConstructor<Cases extends Record<string, Schema.Struct.Fields>> = (\n ...args: never[]\n) => AppMessage<Cases>\n\n/**\n * The renderer's builder: the real `HtmlBuilder` with its private\n * `MessageUniverse` phantom removed, so the renderer's `OnClick` accepts only\n * the Surface's Message subset. `HtmlBuilder<M>` stays invariant even without\n * the phantom (`OnClick` returns `{ message: M }`), so a superset builder is\n * not assignable to this; `Surface.view` casts, which is sound because the\n * renderer can only construct subset Messages and the real builder accepts the\n * superset.\n */\ntype ViewBuilder<Message> = Omit<HtmlBuilder<Message>, keyof HtmlBuilder<never> & symbol>\n\n/** A renderer for a Surface's projected Model, with its Message set narrowed. */\nexport type Renderer<Model, Message> = (model: Model, h: ViewBuilder<Message>) => Html\n\n/** `unknown` when `Sub` is a subtype of `Super`, `never` otherwise. */\ntype Subset<Sub, Super> = [Sub] extends [Super] ? unknown : never\n\ntype RefRoot<R> = R extends ModelRef<infer Root, any> ? Root : never\n\ntype RefRoots<Refs extends readonly unknown[]> = {\n readonly [K in keyof Refs]: RefRoot<Refs[K]>\n}\n\n/** The struct fields a reference selection produces, keyed by each ref's field. */\ntype PickFields<Refs extends readonly FieldRef<any, any, string>[]> = {\n readonly [R in Refs[number] as R[typeof RefTypeId]['key']]: R[typeof RefTypeId]['Schema']\n}\n\ntype ProjectionModel<P> = P extends WritableProjection<infer M, any> ? M : never\n\ntype ProjectionFields<P> = P extends WritableProjection<any, infer F> ? F : never\n\ntype Merge2<A, B> = {\n readonly [K in keyof A | keyof B]: K extends keyof A ? A[K] : K extends keyof B ? B[K] : never\n}\n\n/** Merges the fields of several projections; an overlapping key is rejected at runtime. */\nexport type MergeFields<Ps extends readonly WritableProjection<any, any>[]> = Ps extends readonly [\n infer Head extends WritableProjection<any, any>,\n ...infer Tail extends readonly WritableProjection<any, any>[],\n]\n ? Merge2<ProjectionFields<Head>, MergeFields<Tail>>\n : {}\n\n/**\n * An application definition: the Model and Message schemas and the generated\n * field references. It is data, not a running instance, so it can be inspected\n * without mounting anything. Context, replication, and validation all read the\n * same `App.model` references.\n */\nexport interface Application<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> extends AppScope<Root, F, Cases> {\n /**\n * @deprecated Use `App.model`, the same references under the name the rest\n * of the API uses: `App.surface` hands a Surface `{ model }`, and\n * `Remote.make` and `Editor.at` take `model: App.model.…`. Removed in a\n * later minor.\n */\n readonly fields: RefTree<Root, F>\n /**\n * `Surface.make` with the mechanical wrappers lifted: `params` are the\n * fields of a `Schema.Struct` (or a schema), and `model` may return an\n * object of Projections and refs, which becomes `Projection.struct`.\n */\n readonly surface: <\n const Params extends ParamsShape | undefined = undefined,\n Shape extends ModelShape<Root> = Projection<Root, unknown>,\n const Ms extends readonly MessageConstructor<Cases>[] = readonly [],\n >(\n name: string,\n config: {\n readonly params?: Params\n readonly model: (context: {\n readonly model: RefTree<Root, F>\n readonly params: ParamsOf<Params>\n }) => Shape\n readonly messages?: Ms\n },\n ) => Surface<Root, ModelOf<Root, Shape>, MsgOf<Ms>, ParamsOf<Params>>\n /**\n * This application made runnable, once its update exists: the same\n * references and the same owner, with the initial Model and the transition\n * function a replicator replays. An update is often built from what is made\n * over the references (a Remote domain, a placed Bundle), so it cannot be\n * given when they are; this joins the two without a second application,\n * whose references would be another owner's.\n */\n readonly runnable: <Resources = never>(config: {\n readonly initial: Root\n readonly update: (\n model: Root,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<Root, Schema.Schema.Type<MessageUnion<Cases>>, Resources>\n }) => RunnableApplication<Root, F, Cases, Resources>\n}\n\n/**\n * An `Application` that also carries the initial Model and the transition\n * function, so a replicator can derive the initial shared value and replay.\n * `Resources` is whatever `update`'s Commands need.\n */\nexport interface RunnableApplication<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Resources = never,\n> extends Application<Root, F, Cases> {\n readonly initial: Root\n readonly update: (\n model: Root,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<Root, Schema.Schema.Type<MessageUnion<Cases>>, Resources>\n}\n\ndeclare const messageSubsetRoot: unique symbol\n\n/**\n * A typed subset of one application's Messages: the selected constructors, a\n * codec for exactly those variants, and a runtime membership test. Surface does\n * not label a subset agent-visible, durable, or presence; `Agent` and `Sync`\n * attach their own policy to the same value.\n */\n/** The union of encoded types a tuple of constructor schemas produces. */\ntype SubsetEncoded<Ms extends readonly unknown[]> =\n Ms[number] extends Schema.Codec<any, infer Encoded, any, any> ? Encoded : never\n\nexport interface MessageSet<\n Root,\n Message,\n Subset extends Message,\n Ms extends readonly ((...args: never[]) => Message)[],\n Cases extends Record<string, Schema.Struct.Fields> = Record<string, Schema.Struct.Fields>,\n Encoded = unknown,\n> {\n /** Phantom owner, so a subset cannot be crossed between applications. */\n readonly [messageSubsetRoot]?: Root\n /** The application identity token, checked when subsets compose. */\n readonly owner: object\n readonly constructors: Ms\n /** A pure codec for exactly the selected variants. */\n readonly schema: Schema.Codec<Subset, Encoded, never, never>\n readonly tags: ReadonlySet<string>\n readonly includes: (message: Message) => message is Subset\n}\n\nconst makeScope = <\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n}): AppScope<Schema.Struct.Type<F>, F, Cases> => {\n // One token per application, so a selection cannot silently mix two\n // applications whose Models happen to be structurally identical.\n const owner: object = {}\n return {\n Model: config.Model,\n Message: config.Message,\n owner,\n model: makeTree(\n // A generic `F` hides the Struct's services; a Foldkit Model is pure.\n config.Model as unknown as AnySchema,\n [],\n Optic.id(),\n root => root,\n false,\n undefined,\n owner,\n ) as unknown as RefTree<Schema.Struct.Type<F>, F>,\n }\n}\n\n/**\n * Captures an application's pure references once. `initial` and `update` are\n * optional: an agent needs only the Model, Message, and field references, while\n * a replicator needs them to derive the initial shared value and replay. A\n * `RunnableApplication` is returned when both are supplied.\n */\nfunction application<\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Resources = never,\n ManagedResourceServices = never,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n readonly initial: Schema.Struct.Type<F>\n readonly update: (\n model: Schema.Struct.Type<F>,\n message: Schema.Schema.Type<MessageUnion<Cases>>,\n ) => Update.Return<\n Schema.Struct.Type<F>,\n Schema.Schema.Type<MessageUnion<Cases>>,\n Resources | ManagedResourceServices\n >\n}): RunnableApplication<Schema.Struct.Type<F>, F, Cases, Resources | ManagedResourceServices>\nfunction application<\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(config: {\n readonly Model: Schema.Struct<F>\n readonly Message: MessageUnion<Cases>\n}): Application<Schema.Struct.Type<F>, F, Cases>\nfunction application(config: any): any {\n const scope = makeScope(config)\n const surface = (\n name: string,\n surfaceConfig: {\n readonly params?: ParamsShape | undefined\n readonly model: (context: { readonly model: unknown; readonly params: unknown }) => unknown\n readonly messages?: readonly unknown[]\n },\n ) =>\n Surface.make(scope, name, {\n ...(surfaceConfig.params === undefined\n ? {}\n : {\n Params: Schema.isSchema(surfaceConfig.params)\n ? surfaceConfig.params\n : Schema.Struct(surfaceConfig.params),\n }),\n model: (context: { readonly model: unknown; readonly params: unknown }) => {\n const shape = surfaceConfig.model(context)\n return isProjection(shape) ? shape : Projection.struct(shape as never)\n },\n messages: surfaceConfig.messages,\n } as never)\n const made = { ...scope, fields: scope.model, surface }\n const runnable = (run: { readonly initial: unknown; readonly update: unknown }): unknown => ({\n ...made,\n runnable,\n initial: run.initial,\n update: run.update,\n })\n return { ...made, runnable, initial: config.initial, update: config.update }\n}\n\ntype ConstructorOfSubset<S> = S extends MessageSet<any, any, any, infer Ms, any> ? Ms : never\ntype ValueOfSubset<S> = S extends MessageSet<any, any, infer V, any, any> ? V : never\ntype RootOfSubset<S> = S extends MessageSet<infer R, any, any, any, any> ? R : never\ntype MessageOfSubset<S> = S extends MessageSet<any, infer M, any, any, any> ? M : never\ntype CasesOfSubset<S> = S extends MessageSet<any, any, any, any, infer C> ? C : never\n\ntype Concat<A extends readonly unknown[], B extends readonly unknown[]> = [...A, ...B]\n\n/** Concatenates the constructor tuples of several subsets, preserving each. */\nexport type MergeConstructors<Subs extends readonly MessageSet<any, any, any, any, any>[]> =\n Subs extends readonly [\n infer Head extends MessageSet<any, any, any, any, any>,\n ...infer Tail extends readonly MessageSet<any, any, any, any, any>[],\n ]\n ? Concat<ConstructorOfSubset<Head>, MergeConstructors<Tail>>\n : []\n\n/** Typed Message subsets of one application, by constructor reference. */\nexport const MessageSet = {\n /**\n * Selects a typed Message subset by constructor reference:\n * `MessageSet.make(App, [Message.CreatedTodo, Message.RenamedTodo])`. Each\n * constructor must be this application's own variant; a duplicate or a variant\n * from another union throws.\n */\n make: <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n const Ms extends readonly MessageConstructor<Cases>[],\n >(\n app: AppScope<Root, F, Cases>,\n messages: Ms,\n ): MessageSet<\n Root,\n Schema.Schema.Type<MessageUnion<Cases>>,\n SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>>,\n Ms,\n Cases,\n SubsetEncoded<Ms>\n > => {\n const tags = new Set<string>()\n for (const constructor of messages) {\n const tag = messageTag(constructor)\n if (tag === undefined) {\n throw new Error('MessageSet.make: expected Message constructors')\n }\n if ((app.Message as unknown as Record<string, unknown>)[tag] !== constructor) {\n throw new Error(\n `MessageSet.make: \"${tag}\" is not a variant of this application's Message union`,\n )\n }\n if (tags.has(tag)) throw new Error(`MessageSet.make: duplicate \"${tag}\"`)\n tags.add(tag)\n }\n return {\n owner: app.owner,\n constructors: messages,\n schema: Schema.Union([...messages] as unknown as ReadonlyArray<\n Schema.Schema<unknown>\n >) as unknown as Schema.Codec<\n SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>>,\n SubsetEncoded<Ms>,\n never,\n never\n >,\n tags,\n includes: (message): message is SubsetOf<Ms> & Schema.Schema.Type<MessageUnion<Cases>> =>\n hasTagIn(tags, message),\n }\n },\n\n /**\n * Unions several Message subsets into one. Every subset must belong to the\n * same application; a tag declared twice throws. Disjoint feature modules can\n * each declare their own subset and compose them here.\n */\n union: <const Subs extends readonly MessageSet<any, any, any, any, any>[]>(\n ...subsets: Subs\n ): MessageSet<\n RootOfSubset<Subs[number]>,\n MessageOfSubset<Subs[number]>,\n ValueOfSubset<Subs[number]>,\n MergeConstructors<Subs>,\n CasesOfSubset<Subs[number]>,\n SubsetEncoded<MergeConstructors<Subs>>\n > => {\n const parts = [...subsets]\n const owner = parts[0]?.owner\n const tags = new Set<string>()\n const constructors: Array<Schema.Schema<unknown>> = []\n for (const part of parts) {\n if (part.owner !== owner) {\n throw new Error('MessageSet.union: subsets from different applications')\n }\n for (const constructor of part.constructors) {\n const tag = messageTag(constructor)\n if (tag === undefined) continue\n if (tags.has(tag)) throw new Error(`MessageSet.union: duplicate \"${tag}\"`)\n tags.add(tag)\n constructors.push(constructor as Schema.Schema<unknown>)\n }\n }\n return {\n owner: owner as object,\n constructors: constructors as never,\n schema: Schema.Union(constructors) as unknown as Schema.Codec<\n ValueOfSubset<Subs[number]>,\n SubsetEncoded<MergeConstructors<Subs>>,\n never,\n never\n >,\n tags,\n includes: (message): message is ValueOfSubset<Subs[number]> => hasTagIn(tags, message),\n }\n },\n}\n\n// ===========================================================================\n// Action: a named capability that ends in an existing Message\n// ===========================================================================\n\n/**\n * A capability a consumer may invoke by name with data, such as an agent's\n * tool or a page Block's button. It ends in one of the application's own\n * Messages, so `update` stays the only place a Message has effects, and its\n * input is decoded by its Schema before `toMessage` sees it: stored or\n * untrusted data never executes.\n */\n// `Input` defaults to `never`: an Action known only as an Action takes no input but through `run`.\nexport interface Action<\n Name extends string = string,\n Input = never,\n Encoded = unknown,\n Message = unknown,\n> {\n readonly _tag: 'Action'\n readonly name: Name\n /** What it does, for a person choosing it or an agent deciding to. */\n readonly description: string\n readonly input: Schema.Codec<Input, Encoded, never, never>\n readonly toMessage: (input: Input) => Message\n}\n\nexport const Action = {\n /** An Action: `Action.define({ name: 'addToCart', description, input, toMessage })`. */\n define: <const Name extends string, Input, Encoded, Message>(config: {\n readonly name: Name\n readonly description: string\n readonly input: Schema.Codec<Input, Encoded, never, never>\n readonly toMessage: (input: Input) => Message\n }): Action<Name, Input, Encoded, Message> => {\n if (config.name.length === 0) throw new Error('Action.define: an Action needs a name')\n return Object.freeze({ _tag: 'Action', ...config })\n },\n\n /** Whether a value is an Action. */\n is: (value: unknown): value is Action =>\n typeof value === 'object' && Predicate.isTagged(value, 'Action'),\n\n /**\n * The Message an Action makes of `data`, decoded as its input first; a\n * failure says why the input was refused and makes no Message.\n */\n run: <Input, Encoded, Message>(\n action: Action<string, Input, Encoded, Message>,\n data: unknown,\n ): Result.Result<Message, Schema.SchemaError> =>\n Result.map(Schema.decodeUnknownResult(action.input)(data), action.toMessage),\n}\n\nexport const Surface = {\n application,\n\n /**\n * A Surface as the Model activates it. `params` is the value, or a function\n * of the Model returning it (none while the Surface is inactive, e.g. on\n * another route); the Surface's requirements then follow the Model.\n */\n at: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n params: Params | ((model: Root) => Option.Option<Params>),\n ): ActiveSurface<Root, Model> & SurfaceSource<Root> => {\n const paramsOf = (model: Root): Option.Option<Params> =>\n typeof params === 'function'\n ? (params as (model: Root) => Option.Option<Params>)(model)\n : Option.some(params)\n const projectionOf = (model: Root): Option.Option<Projection<Root, Model>> =>\n Option.map(paramsOf(model), surface.projection)\n return {\n name: surface.name,\n owner: surface.owner,\n messages: messageTags(surface),\n projectionOf,\n instancesOf: model => {\n const value = paramsOf(model)\n if (Option.isNone(value)) return []\n return [\n {\n key: surface.name,\n surface,\n params: value.value,\n projection: surface.projection(value.value),\n },\n ]\n },\n }\n },\n\n /**\n * A Surface active while a tagged value at a known place has a given tag.\n *\n * ```ts\n * Surface.when(ProjectPage, App.model.route, AppRoute.Project, route => ({\n * projectId: route.projectId,\n * }))\n * ```\n *\n * The same thing `Surface.at` does with a callback, and one fact more: the\n * place and the tag are **values**, so what activates the Surface can be read\n * without running anything. That is what a route-to-Surface manifest, a\n * prefetch analysis, or an explanation of why a read is happening needs.\n *\n * Deliberately **not router-specific.** A route is one kind of tagged Model\n * state; a mode, a wizard step and a selected tab are others, and none of\n * them should need their own helper.\n *\n * `Surface.at` stays, and is still the answer when activation is a genuine\n * computation rather than a tag.\n */\n when: <Root, Model, Message, Params, Case extends Schema.Top>(\n surface: Surface<Root, Model, Message, Params>,\n place: ModelPlace<Root>,\n tagged: Case,\n params: (value: Schema.Schema.Type<Case>) => Params,\n ): ActiveSurface<Root, Model> & SurfaceSource<Root> => {\n const tag = messageTag(tagged)\n if (tag === undefined) {\n throw new Error(\n `Surface.when: expected a tagged constructor for \"${surface.name}\", which is what names the case that activates it`,\n )\n }\n const focus = place[RefTypeId]\n const paramsOf = (model: Root): Option.Option<Params> => {\n const value = focus.get(model)\n return Predicate.isTagged(value, tag)\n ? Option.some(params(value as Schema.Schema.Type<Case>))\n : Option.none()\n }\n return {\n name: surface.name,\n owner: surface.owner,\n messages: messageTags(surface),\n activation: { path: focus.dependency, tag },\n projectionOf: model => Option.map(paramsOf(model), surface.projection),\n instancesOf: model => {\n const value = paramsOf(model)\n if (Option.isNone(value)) return []\n return [\n {\n key: surface.name,\n surface,\n params: value.value,\n projection: surface.projection(value.value),\n },\n ]\n },\n }\n },\n\n /**\n * One Surface definition for each item of a parent Surface's Model: zero to\n * many keyed instances, where `Surface.at`/`Surface.when` give zero or one.\n *\n * ```ts\n * Surface.each(ProductGrid, {\n * from: CmsPage,\n * instances: ({ document }) => nodesOf(document).map(node => ({\n * key: node.id,\n * params: { category: node.props.category },\n * })),\n * })\n * ```\n *\n * Keys must be non-empty strings that survive as record keys: `__proto__`\n * is refused, and duplicates throw. Consumers looking instances up by key\n * must still read through `Object.hasOwn` or a `Map`: any string key is\n * otherwise admitted.\n */\n each: <Root, ParentModel, Model, Message, Params>(\n child: Surface<Root, Model, Message, Params>,\n config: {\n readonly from: ActiveSurface<Root, ParentModel>\n readonly instances: (\n parent: ParentModel,\n ) => ReadonlyArray<{ readonly key: string; readonly params: Params }>\n },\n ): SurfaceFamily<Root, ParentModel, Model, Message, Params> => ({\n name: child.name,\n owner: child.owner,\n from: config.from,\n child,\n messages: messageTags(child),\n instancesOf: model => {\n const parent = config.from.projectionOf(model)\n if (Option.isNone(parent)) return []\n const seen = new Set<string>()\n return config.instances(parent.value.read(model)).map(({ key, params }) => {\n if (typeof key !== 'string' || key.length === 0)\n throw new Error(\n `Surface.each: \"${child.name}\" needs a non-empty string key for every instance`,\n )\n if (key === '__proto__')\n throw new Error(`Surface.each: \"${child.name}\" refuses \"__proto__\" as an instance key`)\n if (seen.has(key))\n throw new Error(`Surface.each: \"${child.name}\" has two instances keyed \"${key}\"`)\n seen.add(key)\n return { key, surface: child, params, projection: child.projection(params) }\n })\n },\n }),\n\n /**\n * What a source resolves to for a Model: the family's instances, or the\n * lone instance of a `Surface.at`/`Surface.when` value. Hand-written\n * `ActiveSurface` values predate sources; they are not sources until they\n * grow `instancesOf`, and consumers that still take them read `projectionOf`\n * directly.\n */\n instances: <Root>(\n source: SurfaceSource<Root>,\n model: Root,\n ): ReadonlyArray<SurfaceInstance<Root, any, any>> => source.instancesOf(model),\n\n make: <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n Params = void,\n Model = unknown,\n const Ms extends readonly MessageConstructor<Cases>[] = readonly [],\n >(\n app: AppScope<Root, F, Cases>,\n name: string,\n config: {\n readonly Params?: Schema.Codec<Params, unknown>\n readonly model: (context: {\n readonly model: RefTree<Root, F>\n readonly params: Params\n }) => Projection<Root, Model>\n readonly messages?: Ms\n },\n ): Surface<Root, Model, MsgOf<Ms>, Params> => {\n // Deliberately no eager `projection(undefined)`: a parameterized Surface's\n // projection may read `params`.\n const projection = (params: Params): Projection<Root, Model> => {\n // The types refuse a missing argument; a caller typed `any`, or plain\n // JavaScript, otherwise meets a TypeError from inside `model`.\n if (\n params === undefined &&\n config.Params !== undefined &&\n !Schema.is(config.Params)(undefined)\n ) {\n throw new Error(`Surface \"${name}\" declares params, and was given none`)\n }\n return config.model({ model: app.model, params })\n }\n return {\n name,\n owner: app.owner,\n // Absent only when `Params` is exactly `void`; `ParamsSchema` keeps it optional otherwise.\n Params: config.Params as ParamsSchema<Params>,\n Message: Schema.Never as unknown as Schema.Schema<MsgOf<Ms>>,\n messages: config.messages ?? [],\n projection,\n }\n },\n\n read: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n root: Root,\n ...params: ParamsArgument<Params>\n ): Model => surface.projection(params[0] as Params).read(root),\n\n /**\n * Binds a renderer to a Surface's projected Model and Message set. A\n * type-level binder: the renderer already has this shape, but `Model` and\n * `Message` are derived from the Surface instead of written by hand.\n */\n view: <Root, Model, Message, Params>(\n _surface: Surface<Root, Model, Message, Params>,\n render: Renderer<Model, Message>,\n ): Renderer<Model, Message> => render,\n\n /**\n * The application boundary: consume the Root Model, project it, and hand the\n * projected Model to the renderer. `Subset` rejects a Surface whose Messages\n * the application builder cannot route.\n */\n rootView: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n params: Params,\n render: Renderer<Model, Message>,\n ): (<AppMessage>(\n root: Root,\n h: HtmlBuilder<AppMessage> & Subset<Message, AppMessage>,\n ) => Html) => {\n const projection = surface.projection(params)\n // Sound narrowing: the renderer can only construct this Surface's Messages,\n // and `Subset` guarantees the application builder accepts them.\n return <AppMessage>(\n root: Root,\n h: HtmlBuilder<AppMessage> & Subset<Message, AppMessage>,\n ): Html => render(projection.read(root), h as unknown as ViewBuilder<Message>)\n },\n\n /**\n * Embeds a child renderer in a parent view. `ParentModel extends ChildModel`\n * enforces \"child Model requirement ⊆ parent projected Model\"; `Subset`\n * enforces \"child Message set ⊆ parent Message set\".\n */\n embed:\n <ChildModel, ChildMessage>(child: Renderer<ChildModel, ChildMessage>) =>\n <ParentModel extends ChildModel, ParentMessage>(\n model: ParentModel,\n h: ViewBuilder<ParentMessage> & Subset<ChildMessage, ParentMessage>,\n ): Html =>\n child(model, h as unknown as ViewBuilder<ChildMessage>),\n\n /**\n * A Surface as a `Contract` for `Module`: what it observes, requires, and may\n * emit. A parameterized Surface needs its `params` to build the projection.\n */\n contract: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n ...params: ParamsArgument<Params>\n ): Contract => {\n const projection = surface.projection(params[0] as Params)\n return {\n kind: 'surface',\n name: surface.name,\n owner: surface.owner,\n owns: [],\n observes: projection.dependencies,\n messages: messageTags(surface),\n metadata: Metadata.summarize(projection.metadata),\n }\n },\n\n /**\n * Pure introspection for DevTools: what a Surface observes (dependencies,\n * requirements) and what it may emit. No behavior change, no I/O.\n */\n inspect: <Root, Model, Message, Params>(\n surface: Surface<Root, Model, Message, Params>,\n ...params: ParamsArgument<Params>\n ): SurfaceInspection => {\n const projection = surface.projection(params[0] as Params)\n return {\n name: surface.name,\n dependencies: projection.dependencies,\n metadata: Metadata.summarize(projection.metadata),\n emits: surface.messages,\n }\n },\n}\n\n// ===========================================================================\n// Entity, Selection, Remote moved to `foldkit-remote` (Phase 3).\n// ===========================================================================\n\n// ===========================================================================\n// Module: the pure composition root\n// ===========================================================================\n\n/**\n * What one contract claims about an application, as data. Sync, Remote, and\n * Agent attach one to the values they produce; `Surface.contract` derives one\n * from a Surface. `owns` are the Model paths the contract is the authority for\n * (a replicated projection, a remote store); `observes` are the paths it reads.\n */\nexport interface Contract {\n readonly kind: string\n readonly name: string\n /** The application's identity token; absent when the value cannot know it. */\n readonly owner?: object | undefined\n readonly owns: DependencyTree\n readonly observes: DependencyTree\n /** Message tags the contract may cause, expose, or record. */\n readonly messages: readonly string[]\n /** What interpreters attached to the contract's reads, as text. */\n readonly metadata: readonly MetadataSummary[]\n}\n\n/**\n * How one integration joins an application, as data and pure functions: the\n * Messages it routes, what it runs at startup and on a URL change, its\n * Subscriptions and Managed Resources, and its contract. Remote, Mirror, Sync,\n * and Agent produce one; `foldkit-bundle`'s assembly derives the application's\n * `update`, initial state, runtime config, and Module from a list of them.\n * `R` is the services its Commands and Subscriptions need.\n */\nexport interface Wiring<Model, Message, R = never, Claims extends string = string> {\n /** Names the integration in errors and the Module: `remote:Board`, `mirror:filters`. */\n readonly key: string\n /**\n * Message tags `route` handles. Two integrations handling one tag is an error\n * unless it is `shared`. Typed as literals (`Claims`), the tags it does not\n * share leave the parent's own update in `foldkit-bundle`'s assembly. A wiring\n * with literal `Claims` that shares some gives `shared` a literal type too: a\n * plain `string[]` there reads as sharing none.\n */\n readonly handles: ReadonlyArray<Claims>\n /** Tags several integrations may handle, each for its own values (Mirror's `MirrorRestored`, by name). */\n readonly shared?: readonly string[] | undefined\n /**\n * Folds a Message this integration handles; `None` for any other. A method, so\n * a wiring that routes only its own variants fits an assembly over the whole\n * application union.\n */\n route?(model: Model, message: Message): Option.Option<Update.Return<Model, Message, R>>\n /** Runs once when the application starts, after placements: a restore Command, a warm-up. */\n readonly init?: Update.Step<Model, Message, R> | undefined\n /** Applies the URL to the Model, at startup and whenever the URL changes. */\n readonly onUrl?: ((model: Model, url: Url) => Model) | undefined\n readonly subscriptions?: Subscriptions<Model, Message, R> | undefined\n readonly resources?:\n | Readonly<Record<string, ManagedResourceEntry<Model, Message, any, any, any>>>\n | undefined\n /** Its Module contract; absent for wiring that owns and observes nothing. */\n readonly contract?: Contract | undefined\n}\n\n/** Contracts of one application, in declaration order. Data, not a runtime. */\nexport interface Module<\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n> {\n readonly app: AppScope<Root, F, Cases>\n readonly contracts: readonly Contract[]\n}\n\nexport interface Finding {\n readonly rule:\n | 'foreign-contract'\n | 'duplicate-name'\n | 'ownership-overlap'\n | 'message-claimed-twice'\n | 'unknown-path'\n | 'unknown-message'\n /** `kind:name` of each contract involved. */\n readonly contracts: readonly string[]\n readonly message: string\n}\n\n/** Who owns a Model path; `undefined` is local state. */\nexport interface Ownership {\n readonly path: readonly string[]\n readonly owner: { readonly kind: string; readonly name: string } | undefined\n}\n\nexport interface ModuleManifest {\n readonly fields: readonly string[]\n readonly messages: readonly string[]\n readonly ownership: readonly Ownership[]\n readonly contracts: readonly Omit<Contract, 'owner'>[]\n readonly findings: readonly Finding[]\n}\n\n/** A value `Module.make` accepts: a contract, a value carrying one, or a Surface without params. */\nexport type ModuleItem<Root> =\n | Contract\n | { readonly contract: Contract }\n | Surface<Root, any, any, void>\n\nconst label = (contract: Contract): string => `${contract.kind}:${contract.name}`\n/** Metadata summaries are application data (a query's input), so they cannot break the table. */\nconst tableCell = (text: string): string =>\n text\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\\|/g, '\\\\|')\n .replace(/\\r\\n?|\\n/g, ' ')\nconst pathKey = (path: readonly string[]): string => path.join('.')\nconst isPrefix = (prefix: readonly string[], path: readonly string[]): boolean =>\n prefix.length <= path.length && prefix.every((segment, index) => segment === path[index])\n\n// A carried contract wins: a sync contract also has a `projection` (writable, not a function).\nconst toContract = <Root>(item: ModuleItem<Root>): Contract =>\n 'contract' in item\n ? item.contract\n : 'projection' in item\n ? Surface.contract(item, undefined)\n : item\n\nconst applicationTags = (app: AppScope<any, any, any>): readonly string[] =>\n Object.entries(app.Message as unknown as Record<string, unknown>)\n .filter(([key, value]) => messageTag(value) === key)\n .map(([key]) => key)\n\n/** Contracts that own at least one path, with a stable label. */\nconst owners = (module: Module<any, any, any>) =>\n module.contracts.filter(contract => contract.owns.length > 0)\n\n/**\n * Collects an application's contracts as pure data so their relationships can\n * be validated and inspected without starting a runtime.\n *\n * ```ts\n * const Project = Module.make(App, [BoardSurface, ProjectSync, ProjectRemote, ProjectAgent])\n * Module.validate(Project) // findings, or []\n * Module.toMarkdown(Project)\n * ```\n */\nexport const Module = {\n make: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(\n app: AppScope<Root, F, Cases>,\n items: readonly ModuleItem<Root>[] = [],\n ): Module<Root, F, Cases> => ({ app, contracts: items.map(toContract) }),\n\n /** A new Module with more contracts; the input is unchanged. */\n add: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(\n module: Module<Root, F, Cases>,\n ...items: readonly ModuleItem<Root>[]\n ): Module<Root, F, Cases> => ({\n app: module.app,\n contracts: [...module.contracts, ...items.map(toContract)],\n }),\n\n /**\n * Cross-contract invariants the types cannot express: a contract from another\n * application, a duplicate `kind:name`, two owners of overlapping Model paths,\n * a Message recorded by two replication contracts, and a path or Message the\n * application does not declare.\n */\n validate: (module: Module<any, any, any>): readonly Finding[] => {\n const findings: Finding[] = []\n const fields = new Set(Object.keys(module.app.Model.fields))\n const tags = new Set(applicationTags(module.app))\n const seen = new Map<string, Contract>()\n\n for (const contract of module.contracts) {\n const name = label(contract)\n if (contract.owner !== undefined && contract.owner !== module.app.owner)\n findings.push({\n rule: 'foreign-contract',\n contracts: [name],\n message: `${name} belongs to a different application`,\n })\n const duplicate = seen.get(name)\n if (duplicate !== undefined && duplicate !== contract)\n findings.push({\n rule: 'duplicate-name',\n contracts: [name],\n message: `${name} is declared twice`,\n })\n seen.set(name, contract)\n for (const path of [...contract.owns, ...contract.observes]) {\n const head = path[0]\n if (head === undefined || !fields.has(head))\n findings.push({\n rule: 'unknown-path',\n contracts: [name],\n message: `${name} references \"${pathKey(path)}\", which is not a Model field`,\n })\n }\n for (const tag of contract.messages)\n if (!tags.has(tag))\n findings.push({\n rule: 'unknown-message',\n contracts: [name],\n message: `${name} names \"${tag}\", which is not a Message of this application`,\n })\n }\n\n // The same value listed twice is one owner, as `duplicate-name` treats it.\n const owning = [...new Set(owners(module))]\n for (let i = 0; i < owning.length; i += 1)\n for (let j = i + 1; j < owning.length; j += 1) {\n const a = owning[i]!\n const b = owning[j]!\n for (const pa of a.owns)\n for (const pb of b.owns)\n // An empty path is reported as `unknown-path`, not as owning everything.\n if (pa.length > 0 && pb.length > 0 && (isPrefix(pa, pb) || isPrefix(pb, pa)))\n findings.push({\n rule: 'ownership-overlap',\n contracts: [label(a), label(b)],\n message: `${label(a)} owns \"${pathKey(pa)}\" and ${label(b)} owns \"${pathKey(pb)}\"`,\n })\n }\n\n const recorded = new Map<string, Contract>()\n for (const contract of module.contracts.filter(contract => contract.kind === 'sync'))\n for (const tag of contract.messages) {\n const other = recorded.get(tag)\n if (other !== undefined && other !== contract)\n findings.push({\n rule: 'message-claimed-twice',\n contracts: [label(other), label(contract)],\n message: `\"${tag}\" is durable in both ${label(other)} and ${label(contract)}`,\n })\n else recorded.set(tag, contract)\n }\n\n return findings\n },\n\n /**\n * The application's fields and Messages, who owns each Model path (local when\n * no contract does), every contract, and the findings. Reproducible for a\n * given Module, so it can be committed and diffed.\n */\n manifest: (module: Module<any, any, any>): ModuleManifest => {\n const ownership: Ownership[] = []\n const owning = owners(module)\n for (const field of Object.keys(module.app.Model.fields)) {\n const claims = owning.flatMap(contract =>\n contract.owns\n .filter(path => path[0] === field)\n .map(path => ({ path, owner: { kind: contract.kind, name: contract.name } })),\n )\n const whole = claims.find(claim => claim.path.length === 1)\n if (whole !== undefined) ownership.push(whole)\n else {\n ownership.push({ path: [field], owner: undefined })\n ownership.push(...claims.sort((a, b) => pathKey(a.path).localeCompare(pathKey(b.path))))\n }\n }\n return {\n fields: Object.keys(module.app.Model.fields),\n messages: applicationTags(module.app),\n ownership,\n contracts: module.contracts.map(({ owner: _owner, ...rest }) => rest),\n findings: Module.validate(module),\n }\n },\n\n /** The manifest as Markdown: the ownership tree, a table of contracts, and findings. */\n toMarkdown: (module: Module<any, any, any>): string => {\n const manifest = Module.manifest(module)\n const lines: string[] = ['```text', 'Model']\n const width = Math.max(0, ...manifest.ownership.map(row => pathKey(row.path).length))\n manifest.ownership.forEach((row, index) => {\n const last = index === manifest.ownership.length - 1\n const owner =\n row.owner === undefined ? 'LOCAL' : `${row.owner.kind.toUpperCase()} ${row.owner.name}`\n lines.push(`${last ? '└── ' : '├── '}${pathKey(row.path).padEnd(width)} ${owner}`)\n })\n lines.push(\n '```',\n '',\n '| Contract | Owns | Observes | Messages | Metadata |',\n '| --- | --- | --- | --- | --- |',\n )\n for (const contract of manifest.contracts)\n lines.push(\n `| ${contract.kind}:${contract.name} | ${contract.owns.map(pathKey).join(', ')} | ${contract.observes.map(pathKey).join(', ')} | ${contract.messages.join(', ')} | ${tableCell(contract.metadata.map(summary => `${summary.name}: ${summary.entries.join(', ')}`).join('; '))} |`,\n )\n if (manifest.findings.length > 0) {\n lines.push('', '## Findings', '')\n for (const finding of manifest.findings)\n lines.push(`- **${finding.rule}** ${finding.message}`)\n }\n return lines.join('\\n')\n },\n\n /**\n * The manifest as a Mermaid flowchart: Model fields in a subgraph, one node\n * per contract, a solid edge for ownership and a dotted edge for observation.\n */\n toMermaid: (module: Module<any, any, any>): string => {\n const manifest = Module.manifest(module)\n const lines = ['flowchart LR', ' subgraph Model']\n manifest.fields.forEach((field, index) => lines.push(` f${index}[\"${field}\"]`))\n lines.push(' end')\n // A path outside the Model (reported by `validate`) draws no edge.\n const fieldId = (path: readonly string[]): string | undefined => {\n const index = path.length === 0 ? -1 : manifest.fields.indexOf(path[0]!)\n return index < 0 ? undefined : `f${index}`\n }\n manifest.contracts.forEach((contract, index) => {\n lines.push(` c${index}[\"${contract.kind}:${contract.name}\"]`)\n for (const path of contract.owns) {\n const field = fieldId(path)\n if (field !== undefined) lines.push(` c${index} -->|owns| ${field}`)\n }\n for (const path of contract.observes) {\n const field = fieldId(path)\n if (field !== undefined && !contract.owns.some(owned => pathKey(owned) === pathKey(path)))\n lines.push(` c${index} -.-> ${field}`)\n }\n })\n return lines.join('\\n')\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,YAA2B,OAAO,IAAI,0BAA0B;AA8C7E,MAAM,aACJ,QACA,OACA,YACA,KACA,SACwB;CACxB;CACA;CACA;CACA;CACA;CACA,SAAS,MAAM,OAAO,IAAI,MAAM,GAAG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,MAAM,KAAK,IAAI,eAAe,EAAE;GAChC,KAAK,MAAM,WAAW,SAAS,UAC7B,MAAM,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ,SAAS;EACzD;EACA,OAAO,MAAM,KAAK,IAAI;CACxB;;;;;CAMA,YAAY,WAA0C;EACpD,MAAM,WAAW,OAAO,SAAS,MAAM;EACvC,MAAM,QAAQ,CAAC,gBAAgB,kBAAkB;EACjD,SAAS,OAAO,SAAS,OAAO,UAAU,MAAM,KAAK,QAAQ,MAAM,IAAI,MAAM,GAAG,CAAC;EACjF,MAAM,KAAK,OAAO;EAElB,MAAM,WAAW,SAAgD;GAC/D,MAAM,QAAQ,KAAK,WAAW,IAAI,KAAK,SAAS,OAAO,QAAQ,KAAK,EAAG;GACvE,OAAO,QAAQ,IAAI,KAAA,IAAY,IAAI;EACrC;EACA,SAAS,UAAU,SAAS,UAAU,UAAU;GAC9C,MAAM,KAAK,MAAM,MAAM,IAAI,SAAS,KAAK,GAAG,SAAS,KAAK,GAAG;GAC7D,KAAK,MAAM,QAAQ,SAAS,MAAM;IAChC,MAAM,QAAQ,QAAQ,IAAI;IAC1B,IAAI,UAAU,KAAA,GAAW,MAAM,KAAK,MAAM,MAAM,aAAa,OAAO;GACtE;GACA,KAAK,MAAM,QAAQ,SAAS,UAAU;IACpC,MAAM,QAAQ,QAAQ,IAAI;IAC1B,IAAI,UAAU,KAAA,KAAa,CAAC,SAAS,KAAK,MAAK,UAAS,QAAQ,KAAK,MAAM,QAAQ,IAAI,CAAC,GACtF,MAAM,KAAK,MAAM,MAAM,QAAQ,OAAO;GAC1C;EACF,CAAC;EACD,OAAO,MAAM,KAAK,IAAI;CACxB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-surface",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Typed observation and capability boundaries for Foldkit: ModelRef, Projection, and Surface.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"foldkit": "^0.170.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@effect/platform-browser": "^4.1.
|
|
50
|
-
"effect": "^4.1.
|
|
49
|
+
"@effect/platform-browser": "^4.1.1",
|
|
50
|
+
"effect": "^4.1.1",
|
|
51
51
|
"foldkit": "0.170.0",
|
|
52
52
|
"tsdown": "^0.23.1",
|
|
53
53
|
"typescript": "7.0.2"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"build": "tsdown",
|
|
56
|
+
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|
|
57
57
|
"typecheck": "tsc -b"
|
|
58
58
|
}
|
|
59
59
|
}
|