foldkit-bundle-surface 0.1.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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/index.d.mts +366 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +69 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Glenn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# `foldkit-bundle-surface`
|
|
2
|
+
|
|
3
|
+
Puts [`foldkit-bundle`](../bundle) placements into a
|
|
4
|
+
[`foldkit-surface`](../surface) Module, so **each placement is an owner of its
|
|
5
|
+
Model path**, checked against every other owner.
|
|
6
|
+
|
|
7
|
+
A placement changes one slice of the parent Model through the parent's
|
|
8
|
+
`update`. That makes it an owner in the same sense as a Sync projection or a
|
|
9
|
+
Remote store. `Module.validate` already reports two owners of one path; this
|
|
10
|
+
package gives placements a contract so the check includes them.
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
Search.at(link to model.search) -> contract bundle:Search@search owns search
|
|
14
|
+
TodoSync -> contract sync:Todos owns todos
|
|
15
|
+
Module.validate -> no overlap, every path and Message declared
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add foldkit-bundle-surface foldkit-bundle foldkit-surface effect foldkit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Sixty seconds
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// Search and Row are bundles, Todo a Schema, and TodoSync the application's Sync contract.
|
|
28
|
+
import { Schema } from 'effect'
|
|
29
|
+
import { defineMessageUnion } from 'foldkit/message'
|
|
30
|
+
import { Bundle } from 'foldkit-bundle'
|
|
31
|
+
import { BundleSurface } from 'foldkit-bundle-surface'
|
|
32
|
+
import { Module, Surface } from 'foldkit-surface'
|
|
33
|
+
|
|
34
|
+
const Searchbox = Bundle.declare(Search, 'search')
|
|
35
|
+
const Rows = Bundle.declareEach(Row, 'rows')
|
|
36
|
+
|
|
37
|
+
const Model = Schema.Struct({ ...Searchbox.fields, ...Rows.fields, todos: Schema.Array(Todo) })
|
|
38
|
+
const Message = defineMessageUnion({ ...Searchbox.cases, ...Rows.cases })
|
|
39
|
+
const App = Surface.application({ Model, Message })
|
|
40
|
+
|
|
41
|
+
const Page = BundleSurface.parent(App)
|
|
42
|
+
const placements = Page.assemble(Page.at(Searchbox), Page.each(Rows))
|
|
43
|
+
|
|
44
|
+
const AppModule = Page.module(placements, [TodoSync])
|
|
45
|
+
Module.validate(AppModule) // []
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- **`BundleSurface.parent(app)`** is `Bundle.parent` built from the application's
|
|
49
|
+
own Model and Message, with `module` bound to that application.
|
|
50
|
+
- **`Page.module(assembly, items)`** makes one `bundle` contract per placement,
|
|
51
|
+
brings each wiring's contract as-is, and adds your other contracts. It
|
|
52
|
+
performs no I/O.
|
|
53
|
+
- **`BundleSurface.contract(app, placement)`** is one contract, for
|
|
54
|
+
`Module.make` or `Module.add`. It owns the placement's path, names the parent
|
|
55
|
+
Message tags its Messages travel under, and lists its args as `args`
|
|
56
|
+
metadata when the bundle has an args Schema or is a `bundle.with` preset.
|
|
57
|
+
- **`BundleSurface.link(fieldRef, wrapper)`** is `Link.make` over a Surface field
|
|
58
|
+
ref, for a custom placement. Its contract names the ref's application.
|
|
59
|
+
- **`BundleSurface.module(app, assembly, items)`** is `Page.module` without a
|
|
60
|
+
scope.
|
|
61
|
+
|
|
62
|
+
## What the existing rules catch
|
|
63
|
+
|
|
64
|
+
| Mistake | Finding |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| Two placements on one path, or a placement on a path Sync or Remote owns | `ownership-overlap` |
|
|
67
|
+
| A placement through another application's field ref | `foreign-contract` |
|
|
68
|
+
| A wrapper variant missing from the application's Message | `unknown-message` |
|
|
69
|
+
| A placement's Link path that is not a Model field | `unknown-path` |
|
|
70
|
+
|
|
71
|
+
`Module.manifest` and `Module.toMarkdown` list each placement as the owner of
|
|
72
|
+
its path.
|
|
73
|
+
|
|
74
|
+
## Reading a placement: projections and Mirrors
|
|
75
|
+
|
|
76
|
+
A placement's state is part of the parent Model, so its fields are already in
|
|
77
|
+
the application's ref tree. Observing one needs no bundle API:
|
|
78
|
+
`App.fields.search.query`, `App.fields.search.select(projection)`.
|
|
79
|
+
|
|
80
|
+
To mirror two placements of one bundle, give each mirror its own keys:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const SearchUrl = Mirror.url(App, {
|
|
84
|
+
name: 'search',
|
|
85
|
+
fields: [App.fields.search.query],
|
|
86
|
+
keys: { query: { key: 'search.q' } },
|
|
87
|
+
})
|
|
88
|
+
const FilterUrl = Mirror.url(App, {
|
|
89
|
+
name: 'filter',
|
|
90
|
+
fields: [App.fields.filter.query],
|
|
91
|
+
keys: { query: { key: 'filter.q' } },
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
[`test/mirror.test.ts`](test/mirror.test.ts) writes and reads both.
|
|
96
|
+
|
|
97
|
+
## Why placements are not re-rooted Surfaces
|
|
98
|
+
|
|
99
|
+
A Surface names the Messages a feature may cause by their parent constructors,
|
|
100
|
+
and an agent adapter exposes one capability per constructor. Every Message of a
|
|
101
|
+
placement travels under one wrapper variant, `GotSearchMessage({ message })`,
|
|
102
|
+
so a re-rooted Surface could only offer that single variant, not the child's
|
|
103
|
+
individual Messages. Exposing a placement's Messages one by one needs Surface
|
|
104
|
+
and Agent to understand wrapped variants, which is a change to those packages
|
|
105
|
+
rather than a helper here. Until then, declare a parent Surface over the
|
|
106
|
+
placement's fields and name the wrapper variant in its `messages`.
|
|
107
|
+
|
|
108
|
+
## Limits
|
|
109
|
+
|
|
110
|
+
- A Link composed with `Link.andThen` (or `Link.compose`) from a ref-built Link names the
|
|
111
|
+
application passed to `contract`, not the ref's.
|
|
112
|
+
- Surfaces cannot expose a placement's individual child Messages, for the
|
|
113
|
+
reason above.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { Option, Pipeable, Schema } from "effect";
|
|
2
|
+
import { AnyMessage, AnyPlaced, AnyPlacedCollection, AnyWiring, Bundle, Link, Wrapper } from "foldkit-bundle";
|
|
3
|
+
import { AppScope, Contract, FieldRef, Module, ModuleItem } from "foldkit-surface";
|
|
4
|
+
import * as ManagedResource from "foldkit/managedResource";
|
|
5
|
+
import * as Submodel from "foldkit/submodel";
|
|
6
|
+
import * as Subscription from "foldkit/subscription";
|
|
7
|
+
import * as Update from "foldkit/update";
|
|
8
|
+
import { CallableTaggedStruct } from "foldkit/schema";
|
|
9
|
+
import { Html, HtmlBuilder } from "foldkit/html";
|
|
10
|
+
import "foldkit/url";
|
|
11
|
+
//#region ../bundle/src/link.d.ts
|
|
12
|
+
declare const LinkTypeId: unique symbol;
|
|
13
|
+
/** The parent Message variant `Tag({ message })` that carries a child's Messages. */
|
|
14
|
+
type Wrapped<Tag extends string, ChildMessage> = {
|
|
15
|
+
readonly _tag: Tag;
|
|
16
|
+
readonly message: ChildMessage;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Both directions between a child Message and its parent variant. Spread
|
|
20
|
+
* `cases` into the parent's `defineMessageUnion` so the variant is part of the
|
|
21
|
+
* parent Message.
|
|
22
|
+
*/
|
|
23
|
+
interface Wrapper$1<Tag extends string, ChildMessage> {
|
|
24
|
+
readonly tag: Tag;
|
|
25
|
+
readonly Schema: CallableTaggedStruct<Tag, {
|
|
26
|
+
readonly message: Schema.Codec<ChildMessage, unknown>;
|
|
27
|
+
}>;
|
|
28
|
+
readonly cases: { readonly [K in Tag]: {
|
|
29
|
+
readonly message: Schema.Codec<ChildMessage, unknown>;
|
|
30
|
+
}; };
|
|
31
|
+
readonly make: (message: ChildMessage) => Wrapped<Tag, ChildMessage>;
|
|
32
|
+
readonly toParentMessage: (message: ChildMessage) => Wrapped<Tag, ChildMessage>;
|
|
33
|
+
readonly fromParentMessage: (message: AnyMessage$1) => Option.Option<ChildMessage>;
|
|
34
|
+
}
|
|
35
|
+
/** Every Foldkit Message is tagged; routing only needs the tag. */
|
|
36
|
+
type AnyMessage$1 = {
|
|
37
|
+
readonly _tag: string;
|
|
38
|
+
};
|
|
39
|
+
interface Link$1<Parent, ParentMessage, Child, ChildMessage> extends Pipeable.Pipeable {
|
|
40
|
+
readonly [LinkTypeId]: typeof LinkTypeId;
|
|
41
|
+
readonly read: (parent: Parent) => Option.Option<Child>;
|
|
42
|
+
readonly write: (parent: Parent, child: Child) => Parent;
|
|
43
|
+
readonly toParentMessage: (message: ChildMessage) => ParentMessage;
|
|
44
|
+
/** Recognises this child's variant among all of the parent's Messages. */
|
|
45
|
+
readonly fromParentMessage: (message: AnyMessage$1) => Option.Option<ChildMessage>;
|
|
46
|
+
/** The parent's own gate: while it returns `false`, the child's Subscriptions and resources stop. */
|
|
47
|
+
readonly when: Option.Option<(parent: Parent) => boolean>;
|
|
48
|
+
/** Where the child lives, for placement keys and diagnostics. */
|
|
49
|
+
readonly path: ReadonlyArray<string>;
|
|
50
|
+
/** The parent Message tags this link's Messages travel under, outermost first. */
|
|
51
|
+
readonly messages: ReadonlyArray<string>;
|
|
52
|
+
/** The application a Link built from a Surface field ref belongs to, for its Module contract. */
|
|
53
|
+
readonly owner?: object | undefined;
|
|
54
|
+
}
|
|
55
|
+
interface MakeConfig<Parent, Tag extends string, Child, ChildMessage> {
|
|
56
|
+
readonly read: (parent: Parent) => Option.Option<Child>;
|
|
57
|
+
readonly write: (parent: Parent, child: Child) => Parent;
|
|
58
|
+
readonly wrapper: Wrapper$1<Tag, ChildMessage>;
|
|
59
|
+
readonly when?: (parent: Parent) => boolean;
|
|
60
|
+
readonly path: ReadonlyArray<string>;
|
|
61
|
+
readonly owner?: object | undefined;
|
|
62
|
+
}
|
|
63
|
+
type OptionKeys<Parent> = { [K in keyof Parent]: Parent[K] extends Option.Option<unknown> ? K : never; }[keyof Parent] & string;
|
|
64
|
+
type OptionValue<A> = A extends Option.Option<infer Value> ? Value : never;
|
|
65
|
+
/** The parent Message variant `Tag({ key, message })` that carries one collection item's Messages. */
|
|
66
|
+
type KeyedWrapped<Tag extends string, ChildMessage, Key extends string = string> = {
|
|
67
|
+
readonly _tag: Tag;
|
|
68
|
+
readonly key: Key;
|
|
69
|
+
readonly message: ChildMessage;
|
|
70
|
+
};
|
|
71
|
+
type KeyedFields<ChildMessage, Key extends string> = {
|
|
72
|
+
readonly key: Schema.Codec<Key, string>;
|
|
73
|
+
readonly message: Schema.Codec<ChildMessage, unknown>;
|
|
74
|
+
};
|
|
75
|
+
/** Both directions between an item's Message and its keyed parent variant. */
|
|
76
|
+
interface KeyedWrapper<Tag extends string, ChildMessage, Key extends string = string> {
|
|
77
|
+
readonly tag: Tag;
|
|
78
|
+
readonly Schema: CallableTaggedStruct<Tag, KeyedFields<ChildMessage, Key>>;
|
|
79
|
+
readonly cases: { readonly [K in Tag]: KeyedFields<ChildMessage, Key>; };
|
|
80
|
+
readonly make: (key: Key, message: ChildMessage) => KeyedWrapped<Tag, ChildMessage, Key>;
|
|
81
|
+
readonly fromParentMessage: (message: AnyMessage$1) => Option.Option<readonly [key: Key, message: ChildMessage]>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Where a keyed collection of children lives. The storage is the Link's
|
|
85
|
+
* business: a record by key, an array identified by id, or anything with these
|
|
86
|
+
* operations. `entries` is the order views and Subscriptions follow.
|
|
87
|
+
*/
|
|
88
|
+
interface CollectionLink<Parent, ParentMessage, Child, ChildMessage, Key extends string = string> {
|
|
89
|
+
/** The storage with no items, for a parent's initial Model. */
|
|
90
|
+
readonly empty: unknown;
|
|
91
|
+
readonly entries: (parent: Parent) => ReadonlyArray<readonly [key: Key, child: Child]>;
|
|
92
|
+
readonly get: (parent: Parent, key: Key) => Option.Option<Child>;
|
|
93
|
+
/** Writes one item; `None` removes it. */
|
|
94
|
+
readonly write: (parent: Parent, key: Key, child: Option.Option<Child>) => Parent;
|
|
95
|
+
readonly toParentMessage: (key: Key, message: ChildMessage) => ParentMessage;
|
|
96
|
+
readonly fromParentMessage: (message: AnyMessage$1) => Option.Option<readonly [key: Key, message: ChildMessage]>;
|
|
97
|
+
/** The parent's gate per item: while it returns `false`, that item's Subscriptions stop. */
|
|
98
|
+
readonly when: Option.Option<(parent: Parent, key: Key) => boolean>;
|
|
99
|
+
readonly path: ReadonlyArray<string>;
|
|
100
|
+
/** The parent Message tag this collection's Messages travel under. */
|
|
101
|
+
readonly messages: ReadonlyArray<string>;
|
|
102
|
+
}
|
|
103
|
+
type RecordKeys<Parent> = { [K in keyof Parent]: Parent[K] extends Readonly<Record<string, unknown>> ? K : never; }[keyof Parent] & string;
|
|
104
|
+
type RecordValue<A> = A extends Readonly<Record<string, infer Value>> ? Value : never;
|
|
105
|
+
type ArrayKeys<Parent> = { [K in keyof Parent]: Parent[K] extends ReadonlyArray<unknown> ? K : never; }[keyof Parent] & string;
|
|
106
|
+
type ArrayItem<A> = A extends ReadonlyArray<infer Item> ? Item : never;
|
|
107
|
+
declare const Link$1: {
|
|
108
|
+
readonly wrapper: <const Tag extends string, ChildMessage>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>) => Wrapper$1<Tag, ChildMessage>;
|
|
109
|
+
readonly make: <Parent, const Tag extends string, Child, ChildMessage>(config: MakeConfig<Parent, Tag, Child, ChildMessage>) => Link$1<Parent, Wrapped<Tag, ChildMessage>, Child, ChildMessage>;
|
|
110
|
+
readonly field: <Parent>() => <const Key extends keyof Parent & string, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper$1<Tag, ChildMessage>, options?: {
|
|
111
|
+
readonly when?: (parent: Parent) => boolean;
|
|
112
|
+
}) => Link$1<Parent, Wrapped<Tag, ChildMessage>, Parent[Key], ChildMessage>;
|
|
113
|
+
readonly optional: <Parent>() => <const Key extends OptionKeys<Parent>, const Tag extends string, ChildMessage>(key: Key, wrap: Wrapper$1<Tag, ChildMessage>, options?: {
|
|
114
|
+
readonly when?: (parent: Parent) => boolean;
|
|
115
|
+
}) => Link$1<Parent, Wrapped<Tag, ChildMessage>, OptionValue<Parent[Key]>, ChildMessage>;
|
|
116
|
+
readonly compose: <A, AMessage, B, BMessage extends AnyMessage$1, C, CMessage>(outer: Link$1<A, AMessage, B, BMessage>, inner: Link$1<B, BMessage, C, CMessage>) => Link$1<A, AMessage, C, CMessage>;
|
|
117
|
+
readonly andThen: {
|
|
118
|
+
<B, BMessage extends AnyMessage$1, C, CMessage>(inner: Link$1<B, BMessage, C, CMessage>): <A, AMessage>(outer: Link$1<A, AMessage, B, BMessage>) => Link$1<A, AMessage, C, CMessage>;
|
|
119
|
+
<A, AMessage, B, BMessage extends AnyMessage$1, C, CMessage>(outer: Link$1<A, AMessage, B, BMessage>, inner: Link$1<B, BMessage, C, CMessage>): Link$1<A, AMessage, C, CMessage>;
|
|
120
|
+
};
|
|
121
|
+
readonly when: {
|
|
122
|
+
<Parent>(predicate: (parent: Parent) => boolean): <ParentMessage, Child, ChildMessage>(self: Link$1<Parent, ParentMessage, Child, ChildMessage>) => Link$1<Parent, ParentMessage, Child, ChildMessage>;
|
|
123
|
+
<Parent, ParentMessage, Child, ChildMessage>(self: Link$1<Parent, ParentMessage, Child, ChildMessage>, predicate: (parent: Parent) => boolean): Link$1<Parent, ParentMessage, Child, ChildMessage>;
|
|
124
|
+
};
|
|
125
|
+
readonly keyedWrapper: <const Tag extends string, ChildMessage, Key extends string = string>(tag: Tag, childMessage: Schema.Codec<ChildMessage, unknown>, key?: Schema.Codec<Key, string>) => KeyedWrapper<Tag, ChildMessage, Key>;
|
|
126
|
+
readonly collection: <Parent>() => <const Field extends RecordKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options?: {
|
|
127
|
+
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
128
|
+
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, RecordValue<Parent[Field]>, ChildMessage, Key>;
|
|
129
|
+
readonly collectionById: <Parent>() => <const Field extends ArrayKeys<Parent>, const Tag extends string, ChildMessage, Key extends string>(field: Field, wrap: KeyedWrapper<Tag, ChildMessage, Key>, options: {
|
|
130
|
+
readonly id: (item: ArrayItem<Parent[Field]>) => Key;
|
|
131
|
+
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
132
|
+
}) => CollectionLink<Parent, KeyedWrapped<Tag, ChildMessage, Key>, ArrayItem<Parent[Field]>, ChildMessage, Key>;
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region ../bundle/src/placed.d.ts
|
|
136
|
+
declare const PlacedTypeId: unique symbol;
|
|
137
|
+
interface PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> {
|
|
138
|
+
readonly args?: Args;
|
|
139
|
+
/** Handles the child's OutMessage in parent terms, with the child already written back. */
|
|
140
|
+
readonly onOut?: (outMessage: OutMessage, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
141
|
+
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
142
|
+
readonly key?: string;
|
|
143
|
+
/** A gate beside the Link's own: Subscriptions and resources run only while both hold. */
|
|
144
|
+
readonly when?: (parent: Parent) => boolean;
|
|
145
|
+
}
|
|
146
|
+
/** A lifted resource record: each child entry in parent terms, keyed by the placement. */
|
|
147
|
+
type PlacedResources<Parent, ParentMessage, Resources> = Readonly<Record<string, { readonly [K in keyof Resources]: Resources[K] extends ManagedResource.Entry<any, any, infer Requirements, infer Value, infer Service, any> ? ManagedResource.Entry<Parent, ParentMessage, Requirements, Value, Service> : never; }[keyof Resources]>>;
|
|
148
|
+
type PlacedHelpers<Parent, ParentMessage, R, Helpers> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
|
|
149
|
+
interface Placed<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Resources, Helpers, Field extends string = string> {
|
|
150
|
+
readonly [PlacedTypeId]: typeof PlacedTypeId;
|
|
151
|
+
/** Types only: the top-level Model field this placement owns, or `string` when unknown. */
|
|
152
|
+
readonly field?: Field;
|
|
153
|
+
readonly name: Name;
|
|
154
|
+
/** `Name@path`, or the configured `key`: the prefix of every Subscription and resource key. */
|
|
155
|
+
readonly key: string;
|
|
156
|
+
/** The encoded args as text, when the bundle has an args Schema. */
|
|
157
|
+
readonly argsSummary: string | undefined;
|
|
158
|
+
readonly link: Link$1<Parent, ParentMessage, Model, Message>;
|
|
159
|
+
/** Writes the child's initial Model and starts its `init` Commands. */
|
|
160
|
+
readonly init: Update.Step<Parent, ParentMessage, R>;
|
|
161
|
+
/** Folds the Message when it belongs to this placement; `None` otherwise. */
|
|
162
|
+
readonly update: (parent: Parent, message: AnyMessage$1) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
163
|
+
readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
|
|
164
|
+
readonly resources: PlacedResources<Parent, ParentMessage, Resources>;
|
|
165
|
+
/**
|
|
166
|
+
* Renders the child through `h.submodel`; nothing while the child is absent.
|
|
167
|
+
* Generic over the parent's whole Message, which must include this placement's.
|
|
168
|
+
*/
|
|
169
|
+
readonly view: PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
170
|
+
/**
|
|
171
|
+
* The same view in another slot, for rendering one placement in two DOM
|
|
172
|
+
* positions (desktop and mobile). `h.submodel` throws on a repeated slot.
|
|
173
|
+
*/
|
|
174
|
+
readonly viewIn: (slot: string) => PlacedView<Parent, ParentMessage, ViewInputs>;
|
|
175
|
+
readonly helpers: PlacedHelpers<Parent, ParentMessage, R, Helpers>;
|
|
176
|
+
}
|
|
177
|
+
type PlacedView<Parent, ParentMessage, ViewInputs> = [ViewInputs] extends [void] ? <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>) => Html : <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, viewInputs: ViewInputs) => Html;
|
|
178
|
+
/** A readable type error: intersected onto a parameter, its message names the fix. */
|
|
179
|
+
interface Invalid<Message extends string> {
|
|
180
|
+
readonly invalid: Message;
|
|
181
|
+
}
|
|
182
|
+
type BuilderMessage<H> = H extends HtmlBuilder<infer M> ? M : never;
|
|
183
|
+
/**
|
|
184
|
+
* The parent's `h`, checked to accept this placement's Messages. Generic over the
|
|
185
|
+
* whole builder rather than its Message: inferring a Message through
|
|
186
|
+
* `HtmlBuilder` costs thousands of type instantiations per call, while the
|
|
187
|
+
* builder infers as itself and its Message is extracted once per builder type.
|
|
188
|
+
*/
|
|
189
|
+
type ViewBuilder<H, ParentMessage> = H & ([ParentMessage] extends [BuilderMessage<H>] ? unknown : Invalid<"The parent Message does not include this placement's wrapper variant; spread its Link.wrapper(...).cases into defineMessageUnion">);
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region ../bundle/src/collection.d.ts
|
|
192
|
+
declare const PlacedCollectionTypeId: unique symbol;
|
|
193
|
+
interface EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> {
|
|
194
|
+
/** The args every item's `init` and `update` receive. */
|
|
195
|
+
readonly args?: Args;
|
|
196
|
+
/** Handles an item's OutMessage in parent terms, with the item already written back. */
|
|
197
|
+
readonly onOut?: (outMessage: OutMessage, key: Key, context: Update.FoldContext<Message, LinkMessage>) => Update.Step<NoInfer<Parent>, OutStepMessage, R2>;
|
|
198
|
+
/** Prefix for the collection's Subscription keys. Defaults to `Name@path[]`. */
|
|
199
|
+
readonly key?: string;
|
|
200
|
+
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
201
|
+
}
|
|
202
|
+
type CollectionView<Parent, ParentMessage, ViewInputs, Key extends string = string> = [ViewInputs] extends [void] ? <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key) => Html : <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, key: Key, viewInputs: ViewInputs) => Html;
|
|
203
|
+
type CollectionHelpers<Parent, ParentMessage, R, Helpers, Key extends string = string> = { readonly [K in keyof Helpers]: Helpers[K] extends ((model: any, ...input: infer Input) => any) ? (key: Key, ...input: Input) => Update.Step<Parent, ParentMessage, R> : never; };
|
|
204
|
+
interface PlacedCollection<Name extends string, Parent, ParentMessage, Model, Message, R, S, ViewInputs, Helpers, Field extends string = string, Key extends string = string> {
|
|
205
|
+
readonly [PlacedCollectionTypeId]: typeof PlacedCollectionTypeId;
|
|
206
|
+
/** Types only: the record field this collection owns, or `string` when unknown. */
|
|
207
|
+
readonly field?: Field;
|
|
208
|
+
readonly name: Name;
|
|
209
|
+
/** `Name@path[]`, or the configured `key`: the prefix of every Subscription key. */
|
|
210
|
+
readonly key: string;
|
|
211
|
+
/** The encoded args as text, when the bundle has an args Schema. */
|
|
212
|
+
readonly argsSummary: string | undefined;
|
|
213
|
+
readonly link: CollectionLink<Parent, ParentMessage, Model, Message, Key>;
|
|
214
|
+
/** Folds the Message into its item; `None` when it is not this collection's. A missing key leaves the parent unchanged. */
|
|
215
|
+
readonly update: (parent: Parent, message: AnyMessage$1) => Option.Option<Update.Return<Parent, ParentMessage, R>>;
|
|
216
|
+
/**
|
|
217
|
+
* Writes a new item from `init` and starts its Commands. `prepare` adjusts the
|
|
218
|
+
* initial Model first, for what only the parent knows, such as the item's id.
|
|
219
|
+
* An existing item is replaced.
|
|
220
|
+
*/
|
|
221
|
+
readonly add: (key: Key, prepare?: (model: Model) => Model) => Update.Step<Parent, ParentMessage, R>;
|
|
222
|
+
/** Removes an item; its Subscriptions stop with it, and later Messages for it are ignored. */
|
|
223
|
+
readonly remove: (key: Key) => Update.Step<Parent, ParentMessage, never>;
|
|
224
|
+
readonly subscriptions: Subscription.Subscriptions<Parent, ParentMessage, S>;
|
|
225
|
+
/** One item's view; nothing when the key is missing. */
|
|
226
|
+
readonly view: CollectionView<Parent, ParentMessage, ViewInputs, Key>;
|
|
227
|
+
/** Every item's view, in the order of the Link's `entries`. */
|
|
228
|
+
readonly viewAll: <H extends HtmlBuilder<any>>(parent: Parent, h: ViewBuilder<H, ParentMessage>, ...viewInputs: [ViewInputs] extends [void] ? [] : [viewInputs: ViewInputs]) => ReadonlyArray<Html>;
|
|
229
|
+
readonly helpers: CollectionHelpers<Parent, ParentMessage, R, Helpers, Key>;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region ../bundle/src/declare.d.ts
|
|
233
|
+
/** The type parameters of a Bundle, by name. */
|
|
234
|
+
type BundleParts<B> = B extends Bundle$1<infer Name, infer Args, infer Model, infer Message, infer OutMessage, infer R, infer S, infer ViewInputs, infer Resources, infer Helpers> ? {
|
|
235
|
+
Name: Name;
|
|
236
|
+
Args: Args;
|
|
237
|
+
Model: Model;
|
|
238
|
+
Message: Message;
|
|
239
|
+
OutMessage: OutMessage;
|
|
240
|
+
R: R;
|
|
241
|
+
S: S;
|
|
242
|
+
ViewInputs: ViewInputs;
|
|
243
|
+
Resources: Resources;
|
|
244
|
+
Helpers: Helpers;
|
|
245
|
+
} : never;
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region ../bundle/src/bundle.d.ts
|
|
248
|
+
declare const BundleTypeId: unique symbol;
|
|
249
|
+
/** A child Managed Resource entry: its requirements are an `Option`, so the entry can release. */
|
|
250
|
+
type ResourceEntry<Model, Message> = ManagedResource.Entry<Model, Message, Option.Option<any>, any, any>;
|
|
251
|
+
type ResourceEntries<Model, Message> = Readonly<Record<string, ResourceEntry<Model, Message>>>;
|
|
252
|
+
/** A programmatic entry point, like `Dialog.open`: the child Model plus any input. */
|
|
253
|
+
type Helper<Model, Message, OutMessage, R> = (model: Model, ...input: ReadonlyArray<any>) => Update.ReturnWithOutMessage<Model, Message, OutMessage, R>;
|
|
254
|
+
interface BundleSpec<Name extends string, Args, Model, Message extends AnyMessage$1, OutMessage, R, S, ViewInputs, Resources extends ResourceEntries<Model, Message>, Helpers extends Readonly<Record<string, Helper<Model, Message, OutMessage, R>>>> {
|
|
255
|
+
readonly name: Name;
|
|
256
|
+
readonly Model: Schema.Codec<Model, unknown>;
|
|
257
|
+
readonly Message: Schema.Codec<Message, unknown>;
|
|
258
|
+
/**
|
|
259
|
+
* The args Schema. When given, `Args` is inferred from it, a placement's args
|
|
260
|
+
* are checked against it, and Module lists them.
|
|
261
|
+
*/
|
|
262
|
+
readonly args?: Schema.Codec<Args, unknown>;
|
|
263
|
+
/** Set by `with`: the bound args, encoded as text, for Module. */
|
|
264
|
+
readonly preset?: string | undefined;
|
|
265
|
+
/** Runs when the bundle is placed; its Commands start with the placement. */
|
|
266
|
+
readonly init: (args: Args) => Update.Return<Model, Message, R>;
|
|
267
|
+
readonly update: (model: Model, message: Message, args: Args) => Update.ReturnWithOutMessage<Model, Message, OutMessage, R>;
|
|
268
|
+
readonly subscriptions?: (args: Args) => Subscription.Subscriptions<Model, Message, S>;
|
|
269
|
+
readonly resources?: (args: Args) => Resources;
|
|
270
|
+
readonly view?: Submodel.View<Model, Message, ViewInputs>;
|
|
271
|
+
readonly helpers?: Helpers;
|
|
272
|
+
}
|
|
273
|
+
interface Bundle$1<Name extends string, Args, Model, Message extends AnyMessage$1, OutMessage, R, S, ViewInputs, Resources extends ResourceEntries<Model, Message>, Helpers extends Readonly<Record<string, Helper<Model, Message, OutMessage, R>>>> extends BundleSpec<Name, Args, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>, Pipeable.Pipeable {
|
|
274
|
+
readonly [BundleTypeId]: typeof BundleTypeId;
|
|
275
|
+
/**
|
|
276
|
+
* A preset: the same bundle with its args bound, so placements need no `args`.
|
|
277
|
+
* The args are checked against the args Schema when there is one.
|
|
278
|
+
*/
|
|
279
|
+
readonly with: (args: Args) => Bundle$1<Name, void, Model, Message, OutMessage, R, S, ViewInputs, Resources, Helpers>;
|
|
280
|
+
/** Places the bundle where `link` points. */
|
|
281
|
+
readonly at: <Parent, LinkMessage, OutStepMessage = never, R2 = never>(link: Link$1<Parent, LinkMessage, Model, Message>, ...config: PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>) => Placed<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Resources, Helpers>;
|
|
282
|
+
/** Places the bundle once per key of the collection `link` points at. */
|
|
283
|
+
readonly each: [keyof Resources] extends [never] ? <Parent, LinkMessage, Key extends string, OutStepMessage = never, R2 = never>(link: CollectionLink<Parent, LinkMessage, Model, Message, Key>, ...config: EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>) => PlacedCollection<Name, Parent, LinkMessage | OutStepMessage, Model, Message, R | R2, S, ViewInputs, Helpers, string, Key> : Invalid<'Bundle.each does not support Managed Resources yet: the runtime provides a resource by one tag, so items would share it'>;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* What placing needs: `args` when `init` takes them, and `onOut` when the
|
|
287
|
+
* bundle has an OutMessage, so an OutMessage is never dropped by omission.
|
|
288
|
+
*/
|
|
289
|
+
type PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = {
|
|
290
|
+
/** Prefix for the placement's Subscription and resource keys. Defaults to `Name@path`. */
|
|
291
|
+
readonly key?: string;
|
|
292
|
+
/** A gate beside the Link's own: the child's Subscriptions and resources run only while both hold. */
|
|
293
|
+
readonly when?: (parent: Parent) => boolean;
|
|
294
|
+
} & ([Args] extends [void] ? {
|
|
295
|
+
readonly args?: never;
|
|
296
|
+
} : {
|
|
297
|
+
readonly args: Args;
|
|
298
|
+
}) & ([OutMessage] extends [never] ? {
|
|
299
|
+
readonly onOut?: never;
|
|
300
|
+
} : {
|
|
301
|
+
readonly onOut: Required<PlaceConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>>['onOut'];
|
|
302
|
+
});
|
|
303
|
+
/** The config argument is optional only when it would be empty. */
|
|
304
|
+
type PlaceConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>] : [config: PlacementConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2>];
|
|
305
|
+
type EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = {
|
|
306
|
+
readonly key?: string;
|
|
307
|
+
/** A gate per item beside the Link's own: an item's Subscriptions run only while both hold. */
|
|
308
|
+
readonly when?: (parent: Parent, key: Key) => boolean;
|
|
309
|
+
} & ([Args] extends [void] ? {
|
|
310
|
+
readonly args?: never;
|
|
311
|
+
} : {
|
|
312
|
+
readonly args: Args;
|
|
313
|
+
}) & ([OutMessage] extends [never] ? {
|
|
314
|
+
readonly onOut?: never;
|
|
315
|
+
} : {
|
|
316
|
+
readonly onOut: Required<EachConfig<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>>['onOut'];
|
|
317
|
+
});
|
|
318
|
+
type EachConfigParam<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key extends string = string> = [Args] extends [void] ? [OutMessage] extends [never] ? [config?: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>] : [config: EachOptions<Args, Parent, LinkMessage, Message, OutMessage, OutStepMessage, R2, Key>];
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region ../bundle/src/parent.d.ts
|
|
321
|
+
type P<B> = BundleParts<B>;
|
|
322
|
+
/** Collections cannot place a bundle with Managed Resources; reported at the bundle. */
|
|
323
|
+
type WithoutResources<B> = [keyof P<B>['Resources']] extends [never] ? unknown : Invalid<'A collection cannot place a bundle with Managed Resources: the runtime provides a resource by one tag, so every item would share it'>;
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/index.d.ts
|
|
326
|
+
type AnyPlacement = AnyPlaced | AnyPlacedCollection;
|
|
327
|
+
/** What an assembly lists: placements, collections, and integration wiring. */
|
|
328
|
+
type AssemblyItems = {
|
|
329
|
+
readonly placements: ReadonlyArray<AnyPlacement | AnyWiring>;
|
|
330
|
+
};
|
|
331
|
+
export declare const BundleSurface: {
|
|
332
|
+
readonly link: <Root, Value, const Tag extends string, ChildMessage>(ref: FieldRef<Root, Value>, wrapper: Wrapper<Tag, ChildMessage>, options?: {
|
|
333
|
+
readonly when?: (parent: Root) => boolean;
|
|
334
|
+
}) => Link<Root, import("foldkit-bundle").Wrapped<Tag, ChildMessage>, Value, ChildMessage>;
|
|
335
|
+
readonly contract: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(app: AppScope<Root, F, Cases>, placement: AnyPlacement) => Contract;
|
|
336
|
+
readonly module: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(app: AppScope<Root, F, Cases>, assembly: AssemblyItems, items?: readonly ModuleItem<Root>[]) => Module<Root, F, Cases>;
|
|
337
|
+
readonly parent: <Root, F extends Schema.Struct.Fields, Cases extends Record<string, Schema.Struct.Fields>>(app: AppScope<Root, F, Cases>) => {
|
|
338
|
+
/** A Module of these placements and wiring plus the application's other contracts. */
|
|
339
|
+
module: (assembly: AssemblyItems, items?: readonly ModuleItem<Root>[]) => Module<Root, F, Cases>;
|
|
340
|
+
Model: Schema.Codec<Root, unknown, never, never>;
|
|
341
|
+
Message: Schema.Codec<Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, unknown, never, never>;
|
|
342
|
+
withServices: <S>() => Bundle.Parent<Root, Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, S>;
|
|
343
|
+
at: <B extends Bundle.AnyBundle, const Field extends { [K in keyof Root]: [Root[K]] extends [Bundle.BundleParts<B>["Model"]] ? [Bundle.BundleParts<B>["Model"]] extends [Root[K]] ? K : never : never; }[keyof Root] & string, OutStepMessage = never, R2 = never>(declared: Bundle.Declared<B, Field>, ...config: Bundle.PlaceConfigParam<Bundle.BundleParts<B>["Args"], Root, import("foldkit-bundle").Wrapped<`Got${Capitalize<Field>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Message"], Bundle.BundleParts<B>["OutMessage"], OutStepMessage, R2> & ([import("foldkit-bundle").Wrapped<`Got${Capitalize<Field>}Message`, Bundle.BundleParts<B>["Message"]>] extends [Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage] ? unknown : import("foldkit-bundle").Invalid<"The parent Message does not include this placement's wrapper variant; spread its cases into defineMessageUnion">)) => import("foldkit-bundle").Placed<Bundle.BundleParts<B>["Name"], Root, OutStepMessage | import("foldkit-bundle").Wrapped<`Got${Capitalize<Field>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Model"], Bundle.BundleParts<B>["Message"], R2 | Bundle.BundleParts<B>["R"], Bundle.BundleParts<B>["S"], Bundle.BundleParts<B>["ViewInputs"], Bundle.BundleParts<B>["Resources"], Bundle.BundleParts<B>["Helpers"], Field>;
|
|
344
|
+
place: <B extends Bundle.AnyBundle, const Field_1 extends { [K in keyof Root]: [Root[K]] extends [Bundle.BundleParts<B>["Model"]] ? [Bundle.BundleParts<B>["Model"]] extends [Root[K]] ? K : never : never; }[keyof Root] & string, OutStepMessage_1 = never, R2_1 = never>(bundle: B, field: Field_1, ...config: Bundle.PlaceConfigParam<Bundle.BundleParts<B>["Args"], Root, import("foldkit-bundle").Wrapped<`Got${Capitalize<Field_1>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Message"], Bundle.BundleParts<B>["OutMessage"], OutStepMessage_1, R2_1> & ([import("foldkit-bundle").Wrapped<`Got${Capitalize<Field_1>}Message`, Bundle.BundleParts<B>["Message"]>] extends [Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage] ? unknown : import("foldkit-bundle").Invalid<"The parent Message does not include this placement's wrapper variant; spread its cases into defineMessageUnion">)) => import("foldkit-bundle").Placed<Bundle.BundleParts<B>["Name"], Root, OutStepMessage_1 | import("foldkit-bundle").Wrapped<`Got${Capitalize<Field_1>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Model"], Bundle.BundleParts<B>["Message"], R2_1 | Bundle.BundleParts<B>["R"], Bundle.BundleParts<B>["S"], Bundle.BundleParts<B>["ViewInputs"], Bundle.BundleParts<B>["Resources"], Bundle.BundleParts<B>["Helpers"], Field_1>;
|
|
345
|
+
each: <B extends Bundle.AnyBundle, const Field_2 extends { [K in keyof Root]: Root[K] extends Readonly<Record<string, infer V>> ? [V] extends [Bundle.BundleParts<B>["Model"]] ? [Bundle.BundleParts<B>["Model"]] extends [V] ? K : never : never : never; }[keyof Root] & string, OutStepMessage_2 = never, R2_2 = never>(declared: Bundle.DeclaredEach<B, Field_2>, ...config: Bundle.EachConfigParam<Bundle.BundleParts<B>["Args"], Root, import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_2>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Message"], Bundle.BundleParts<B>["OutMessage"], OutStepMessage_2, R2_2, string> & ([import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_2>}Message`, Bundle.BundleParts<B>["Message"]>] extends [Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage] ? unknown : import("foldkit-bundle").Invalid<"The parent Message does not include this placement's wrapper variant; spread its cases into defineMessageUnion">)) => import("foldkit-bundle").PlacedCollection<Bundle.BundleParts<B>["Name"], Root, OutStepMessage_2 | import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_2>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Model"], Bundle.BundleParts<B>["Message"], R2_2 | Bundle.BundleParts<B>["R"], Bundle.BundleParts<B>["S"], Bundle.BundleParts<B>["ViewInputs"], Bundle.BundleParts<B>["Helpers"], Field_2, string>;
|
|
346
|
+
placeEach: <B extends Bundle.AnyBundle, const Field_3 extends { [K in keyof Root]: Root[K] extends Readonly<Record<string, infer V>> ? [V] extends [Bundle.BundleParts<B>["Model"]] ? [Bundle.BundleParts<B>["Model"]] extends [V] ? K : never : never : never; }[keyof Root] & string, OutStepMessage_3 = never, R2_3 = never>(bundle: B & WithoutResources<B>, field: Field_3, ...config: Bundle.EachConfigParam<Bundle.BundleParts<B>["Args"], Root, import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_3>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Message"], Bundle.BundleParts<B>["OutMessage"], OutStepMessage_3, R2_3, string> & ([import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_3>}Message`, Bundle.BundleParts<B>["Message"]>] extends [Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage] ? unknown : import("foldkit-bundle").Invalid<"The parent Message does not include this placement's wrapper variant; spread its cases into defineMessageUnion">)) => import("foldkit-bundle").PlacedCollection<Bundle.BundleParts<B>["Name"], Root, OutStepMessage_3 | import("foldkit-bundle").KeyedWrapped<`Got${Capitalize<Field_3>}Message`, Bundle.BundleParts<B>["Message"]>, Bundle.BundleParts<B>["Model"], Bundle.BundleParts<B>["Message"], R2_3 | Bundle.BundleParts<B>["R"], Bundle.BundleParts<B>["S"], Bundle.BundleParts<B>["ViewInputs"], Bundle.BundleParts<B>["Helpers"], Field_3, string>;
|
|
347
|
+
assemble: <const Ps extends readonly (import("foldkit-bundle").Placed<string, Root, Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, any, any, any, any, any, any, any, string> | import("foldkit-bundle").PlacedCollection<string, Root, Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, any, any, any, any, any, any, any, any> | import("foldkit-bundle").Wiring<Root, Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, any>)[]>(...items: Ps) => Bundle.Assembly<Root, Schema.Schema.Type<import("foldkit/message").MessageUnion<Cases>> & AnyMessage, Ps, never>;
|
|
348
|
+
link: {
|
|
349
|
+
readonly field: <const Key extends keyof Root & string, const Tag extends string, ChildMessage>(key: Key, wrapper: Wrapper<Tag, ChildMessage>, options?: {
|
|
350
|
+
readonly when?: (parent: Root) => boolean;
|
|
351
|
+
} | undefined) => Link<Root, import("foldkit-bundle").Wrapped<Tag, ChildMessage>, Root[Key], ChildMessage>;
|
|
352
|
+
readonly optional: <const Key extends { [K in keyof Root]: Root[K] extends Option.Option<unknown> ? K : never; }[keyof Root] & string, const Tag_1 extends string, ChildMessage_1>(key: Key, wrap: Wrapper<Tag_1, ChildMessage_1>, options?: {
|
|
353
|
+
readonly when?: (parent: Root) => boolean;
|
|
354
|
+
} | undefined) => Link<Root, import("foldkit-bundle").Wrapped<Tag_1, ChildMessage_1>, Root[Key] extends (infer T) ? T extends Root[Key] ? T extends Option.Option<infer Value> ? Value : never : never : never, ChildMessage_1>;
|
|
355
|
+
readonly collection: <const Field_4 extends { [K in keyof Root]: Root[K] extends Readonly<Record<string, unknown>> ? K : never; }[keyof Root] & string, const Tag_2 extends string, ChildMessage_2, Key extends string>(field: Field_4, wrap: import("foldkit-bundle").KeyedWrapper<Tag_2, ChildMessage_2, Key>, options?: {
|
|
356
|
+
readonly when?: (parent: Root, key: Key) => boolean;
|
|
357
|
+
} | undefined) => import("foldkit-bundle").CollectionLink<Root, import("foldkit-bundle").KeyedWrapped<Tag_2, ChildMessage_2, Key>, Root[Field_4] extends (infer T) ? T extends Root[Field_4] ? T extends Readonly<Record<string, infer Value>> ? Value : never : never : never, ChildMessage_2, Key>;
|
|
358
|
+
readonly collectionById: <const Field_4 extends { [K in keyof Root]: Root[K] extends readonly unknown[] ? K : never; }[keyof Root] & string, const Tag_3 extends string, ChildMessage_3, Key_1 extends string>(field: Field_4, wrap: import("foldkit-bundle").KeyedWrapper<Tag_3, ChildMessage_3, Key_1>, options: {
|
|
359
|
+
readonly id: (item: Root[Field_4] extends (infer T) ? T extends Root[Field_4] ? T extends readonly (infer Item)[] ? Item : never : never : never) => Key_1;
|
|
360
|
+
readonly when?: (parent: Root, key: Key_1) => boolean;
|
|
361
|
+
}) => import("foldkit-bundle").CollectionLink<Root, import("foldkit-bundle").KeyedWrapped<Tag_3, ChildMessage_3, Key_1>, Root[Field_4] extends (infer T) ? T extends Root[Field_4] ? T extends readonly (infer Item)[] ? Item : never : never : never, ChildMessage_3, Key_1>;
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
//#endregion
|
|
366
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../bundle/src/link.d.ts","../../bundle/src/placed.d.ts","../../bundle/src/collection.d.ts","../../bundle/src/declare.d.ts","../../bundle/src/bundle.d.ts","../../bundle/src/parent.d.ts","../src/index.ts"],"mappings":";;;;;;;;;;;cAMc;;KAEF,QAAQ,oBAAoB;WAC3B,MAAM;WACN,SAAS;;;;;;;UAOL,UAAQ,oBAAoB;WAChC,KAAK;WACL,QAAQ,qBAAqB;aACzB,SAAS,OAAO,MAAM;;WAE1B,mBACK,KAAK;aACF,SAAS,OAAO,MAAM;;WAG9B,OAAO,SAAS,iBAAiB,QAAQ,KAAK;WAC9C,kBAAkB,SAAS,iBAAiB,QAAQ,KAAK;WACzD,oBAAoB,SAAS,iBAAe,OAAO,OAAO;;;KAG3D;WACC;;UAEI,OAAK,QAAQ,eAAe,OAAO,sBAAsB,SAAS;YACrE,oBAAoB;WACrB,OAAO,QAAQ,WAAW,OAAO,OAAO;WACxC,QAAQ,QAAQ,QAAQ,OAAO,UAAU;WACzC,kBAAkB,SAAS,iBAAiB;;WAE5C,oBAAoB,SAAS,iBAAe,OAAO,OAAO;;WAE1D,MAAM,OAAO,QAAQ,QAAQ;;WAE7B,MAAM;;WAEN,UAAU;;WAEV;;UAGH,WAAW,QAAQ,oBAAoB,OAAO;WAC3C,OAAO,QAAQ,WAAW,OAAO,OAAO;WACxC,QAAQ,QAAQ,QAAQ,OAAO,UAAU;WACzC,SAAS,UAAQ,KAAK;WACtB,QAAQ,QAAQ;WAChB,MAAM;WACN;;KAER,WAAW,aACX,WAAW,SAAS,OAAO,WAAW,OAAO,kBAAkB,mBAC5D;KACH,YAAY,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}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
import { Bundle, Link } from "foldkit-bundle";
|
|
3
|
+
import { Module } from "foldkit-surface";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* foldkit-bundle assemblies in a foldkit-surface Module: each placement is a
|
|
7
|
+
* contract that owns the Model path its Link points at, and each integration's
|
|
8
|
+
* wiring brings its own contract, so `Module.validate` checks every owner in
|
|
9
|
+
* the one list.
|
|
10
|
+
*/
|
|
11
|
+
const isPlacement = (item) => "link" in item;
|
|
12
|
+
const wiringContract = (wiring) => wiring.contract === void 0 ? [] : [wiring.contract];
|
|
13
|
+
/**
|
|
14
|
+
* A Link from a Surface field ref: `App.model.search`. The contract of a
|
|
15
|
+
* placement through it names the ref's application, so placing a child through
|
|
16
|
+
* another application's ref is a `foreign-contract` finding.
|
|
17
|
+
*/
|
|
18
|
+
const link = (ref, wrapper, options = {}) => {
|
|
19
|
+
return Link.make({
|
|
20
|
+
read: (root) => Option.some(ref.get(root)),
|
|
21
|
+
write: ref.set,
|
|
22
|
+
wrapper,
|
|
23
|
+
path: ref.dependency,
|
|
24
|
+
owner: ref.owner,
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The contract of one placement or collection: it owns its Model path and names
|
|
30
|
+
* the parent Message tags its Messages travel under.
|
|
31
|
+
*/
|
|
32
|
+
const contract = (app, placement) => ({
|
|
33
|
+
kind: "bundle",
|
|
34
|
+
name: placement.key,
|
|
35
|
+
owner: ("owner" in placement.link ? placement.link.owner : void 0) ?? app.owner,
|
|
36
|
+
owns: [placement.link.path],
|
|
37
|
+
observes: [],
|
|
38
|
+
messages: placement.link.messages,
|
|
39
|
+
metadata: placement.argsSummary === void 0 ? [] : [{
|
|
40
|
+
name: "args",
|
|
41
|
+
entries: [placement.argsSummary]
|
|
42
|
+
}]
|
|
43
|
+
});
|
|
44
|
+
/** A Module of an assembly's placements and wiring, plus any other contracts of the application. */
|
|
45
|
+
const module = (app, assembly, items = []) => Module.make(app, [...assembly.placements.flatMap((item) => isPlacement(item) ? [contract(app, item)] : wiringContract(item)), ...items]);
|
|
46
|
+
/**
|
|
47
|
+
* The parent scope of `foldkit-bundle`, built from a Surface application, with
|
|
48
|
+
* `module` bound to it: `const Page = BundleSurface.parent(App)`.
|
|
49
|
+
*/
|
|
50
|
+
const parent = (app) => {
|
|
51
|
+
return {
|
|
52
|
+
...Bundle.parent({
|
|
53
|
+
Model: app.Model,
|
|
54
|
+
Message: app.Message
|
|
55
|
+
}),
|
|
56
|
+
/** A Module of these placements and wiring plus the application's other contracts. */
|
|
57
|
+
module: (assembly, items = []) => module(app, assembly, items)
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const BundleSurface = {
|
|
61
|
+
link,
|
|
62
|
+
contract,
|
|
63
|
+
module,
|
|
64
|
+
parent
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { BundleSurface };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * foldkit-bundle assemblies in a foldkit-surface Module: each placement is a\n * contract that owns the Model path its Link points at, and each integration's\n * wiring brings its own contract, so `Module.validate` checks every owner in\n * the one list.\n */\nimport { Option, type Schema } from 'effect'\nimport {\n Bundle,\n Link,\n type AnyMessage,\n type AnyPlaced,\n type AnyPlacedCollection,\n type AnyWiring,\n type Wrapper,\n} from 'foldkit-bundle'\nimport {\n Module,\n type AppScope,\n type Contract,\n type FieldRef,\n type ModuleItem,\n} from 'foldkit-surface'\n\ntype AnyPlacement = AnyPlaced | AnyPlacedCollection\n\n/** What an assembly lists: placements, collections, and integration wiring. */\ntype AssemblyItems = { readonly placements: ReadonlyArray<AnyPlacement | AnyWiring> }\n\nconst isPlacement = (item: AnyPlacement | AnyWiring): item is AnyPlacement => 'link' in item\n\n// Wiring declares its contract loosely (as `object`) so foldkit-bundle need not\n// import Surface; every integration builds it from Surface's own `Contract`.\nconst wiringContract = (wiring: AnyWiring): ReadonlyArray<Contract> =>\n wiring.contract === undefined ? [] : [wiring.contract as Contract]\n\n/**\n * A Link from a Surface field ref: `App.model.search`. The contract of a\n * placement through it names the ref's application, so placing a child through\n * another application's ref is a `foreign-contract` finding.\n */\nconst link = <Root, Value, const Tag extends string, ChildMessage>(\n ref: FieldRef<Root, Value>,\n wrapper: Wrapper<Tag, ChildMessage>,\n options: { readonly when?: (parent: Root) => boolean } = {},\n) => {\n const made = Link.make<Root, Tag, Value, ChildMessage>({\n read: root => Option.some(ref.get(root)),\n write: ref.set,\n wrapper,\n path: ref.dependency,\n owner: ref.owner,\n ...options,\n })\n return made\n}\n\n/**\n * The contract of one placement or collection: it owns its Model path and names\n * the parent Message tags its Messages travel under.\n */\nconst contract = <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(\n app: AppScope<Root, F, Cases>,\n placement: AnyPlacement,\n): Contract => ({\n kind: 'bundle',\n name: placement.key,\n owner: ('owner' in placement.link ? placement.link.owner : undefined) ?? app.owner,\n owns: [placement.link.path],\n observes: [],\n messages: placement.link.messages,\n metadata:\n placement.argsSummary === undefined ? [] : [{ name: 'args', entries: [placement.argsSummary] }],\n})\n\n/** A Module of an assembly's placements and wiring, plus any other contracts of the application. */\nconst module = <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(\n app: AppScope<Root, F, Cases>,\n assembly: AssemblyItems,\n items: readonly ModuleItem<Root>[] = [],\n) =>\n Module.make(app, [\n ...assembly.placements.flatMap(item =>\n isPlacement(item) ? [contract(app, item)] : wiringContract(item),\n ),\n ...items,\n ])\n\n/**\n * The parent scope of `foldkit-bundle`, built from a Surface application, with\n * `module` bound to it: `const Page = BundleSurface.parent(App)`.\n */\nconst parent = <\n Root,\n F extends Schema.Struct.Fields,\n Cases extends Record<string, Schema.Struct.Fields>,\n>(\n app: AppScope<Root, F, Cases>,\n) => {\n const scope = Bundle.parent({\n Model: app.Model as unknown as Schema.Codec<Root, unknown>,\n Message: app.Message as unknown as Schema.Codec<\n Schema.Schema.Type<typeof app.Message> & AnyMessage,\n unknown\n >,\n })\n return {\n ...scope,\n /** A Module of these placements and wiring plus the application's other contracts. */\n module: (assembly: AssemblyItems, items: readonly ModuleItem<Root>[] = []) =>\n module(app, assembly, items),\n }\n}\n\nexport const BundleSurface = { link, contract, module, parent } as const\n"],"mappings":";;;;;;;;;;AA6BA,MAAM,eAAe,SAAyD,UAAU;AAIxF,MAAM,kBAAkB,WACtB,OAAO,aAAa,KAAA,IAAY,CAAC,IAAI,CAAC,OAAO,QAAoB;;;;;;AAOnE,MAAM,QACJ,KACA,SACA,UAAyD,CAAC,MACvD;CASH,OARa,KAAK,KAAqC;EACrD,OAAM,SAAQ,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC;EACvC,OAAO,IAAI;EACX;EACA,MAAM,IAAI;EACV,OAAO,IAAI;EACX,GAAG;CACL,CACU;AACZ;;;;;AAMA,MAAM,YAKJ,KACA,eACc;CACd,MAAM;CACN,MAAM,UAAU;CAChB,QAAQ,WAAW,UAAU,OAAO,UAAU,KAAK,QAAQ,KAAA,MAAc,IAAI;CAC7E,MAAM,CAAC,UAAU,KAAK,IAAI;CAC1B,UAAU,CAAC;CACX,UAAU,UAAU,KAAK;CACzB,UACE,UAAU,gBAAgB,KAAA,IAAY,CAAC,IAAI,CAAC;EAAE,MAAM;EAAQ,SAAS,CAAC,UAAU,WAAW;CAAE,CAAC;AAClG;;AAGA,MAAM,UAKJ,KACA,UACA,QAAqC,CAAC,MAEtC,OAAO,KAAK,KAAK,CACf,GAAG,SAAS,WAAW,SAAQ,SAC7B,YAAY,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,IAAI,eAAe,IAAI,CACjE,GACA,GAAG,KACL,CAAC;;;;;AAMH,MAAM,UAKJ,QACG;CAQH,OAAO;EACL,GARY,OAAO,OAAO;GAC1B,OAAO,IAAI;GACX,SAAS,IAAI;EAIf,CAES;;EAEP,SAAS,UAAyB,QAAqC,CAAC,MACtE,OAAO,KAAK,UAAU,KAAK;CAC/B;AACF;AAEA,MAAa,gBAAgB;CAAE;CAAM;CAAU;CAAQ;AAAO"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "foldkit-bundle-surface",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "foldkit-bundle placements as foldkit-surface Module contracts: each placement owns its Model path, validated with every other owner.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"foldkit",
|
|
7
|
+
"effect",
|
|
8
|
+
"submodel",
|
|
9
|
+
"surface"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"author": "Patrick Glenn <doeixd@gmail.com>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/doeixd/foldkit-plus.git",
|
|
20
|
+
"directory": "packages/bundle-surface"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/bundle-surface#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/doeixd/foldkit-plus/issues"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"import": "./dist/index.mjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"foldkit-bundle": "0.1.0",
|
|
40
|
+
"foldkit-surface": "0.2.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"effect": "^4.0.0-rc.112",
|
|
44
|
+
"foldkit": "^0.158.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"effect": "4.0.0-rc.112",
|
|
48
|
+
"foldkit": "0.158.2",
|
|
49
|
+
"jsdom": "26.1.0",
|
|
50
|
+
"tsdown": "^0.23.0",
|
|
51
|
+
"typescript": "^5.7.2",
|
|
52
|
+
"foldkit-mirror": "0.2.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"typecheck": "tsc -b"
|
|
57
|
+
}
|
|
58
|
+
}
|