Bundle / foldkit-bundle-surface
bundle-surface
Reusable foldkit-bundle widgets read and update a slice of your parent Model through update. Without registering those placements in foldkit-surface, Module.validate cannot catch two widgets colliding on the same Model path or overwriting a field already owned by foldkit-sync or foldkit-remote.
foldkit-bundle-surface generates a Surface ownership contract for each Bundle placement (bundle:Search@search) so Module.validate checks every placement, Sync projection, and Remote store together.
Install
pnpm add foldkit-bundle-surface foldkit-bundle foldkit-surface effect foldkitA first validated module
Wrap your Surface.application with BundleSurface.parent, place a Bundle, and pass the placements to Page.module before calling Module.validate:
import { Schema } from 'effect'
import { defineMessageUnion } from 'foldkit/message'
import { Bundle } from 'foldkit-bundle'
import { BundleSurface } from 'foldkit-bundle-surface'
import { Module, Surface } from 'foldkit-surface'
const Search = Bundle.make('Search', {
Model: Schema.Struct({ query: Schema.String }),
Message: defineMessageUnion({ Typed: { query: Schema.String } }),
init: () => ({ model: { query: '' } }),
update: (_model, message) => ({ model: { query: message.query } }),
})
const Searchbox = Bundle.declare(Search, 'search')
const Model = Schema.Struct({ ...Searchbox.fields })
const Message = defineMessageUnion({ ...Searchbox.cases })
const App = Surface.application({ Model, Message })
const Page = BundleSurface.parent(App)
const placements = Page.assemble(Page.at(Searchbox))
const AppModule = Page.module(placements, [])
Module.validate(AppModule) // []AppModule now records bundle:Search@search as the sole owner of search, and Module.validate(AppModule) returns [] (no conflicts) purely from inspecting declarations. Rendering a Surface over search observes that single owner, and Module.manifest and Module.toMarkdown include every placed Bundle.
Available helpers:
BundleSurface.parent(app): Creates aBundle.parentbound toappwith.module(assembly, items).Page.module(assembly, items)/BundleSurface.module(app, assembly, items): Converts each placement into a contract, keeps any wiring contracts, and appends your other Module items.BundleSurface.contract(app, placement): Builds a single contract forModule.makeorModule.add, recording the owned path, parent Message tags, andargsmetadata when the Bundle declares args.BundleSurface.link(fieldRef, wrapper): Builds aLinkover afoldkit-surfacefield ref for custom placements.
What Module.validate catches
| Mistake | Finding |
|---|---|
| Two placements or a placement + Sync/Remote on one path | ownership-overlap |
| Placement using another application's field ref | foreign-contract |
Wrapper Message missing from the parent Message union | unknown-message |
Link path absent from the parent Model | unknown-path |