prepare method
- String bundle,
- KnowledgeChange change, {
- required KnowledgeStamp stamp,
- KnowledgeLog logEntry = KnowledgeLog.lifecycle,
- ProfileSelection? selection,
- KnowledgeProjectFiles? projectFiles,
- String? projectRoot,
- WayfinderCancellation? cancel,
Prepares change to the bundle at bundle, stamped with stamp, and
returns the plan commit writes. Writes nothing.
The Profile is selection, or resolver's selection for the bundle
as validate makes it. commit also refuses the plan when a project
file that selection came from changed since (projectFiles):
wayfinder.json and the wayfinder.lock beside it, with each closer
wayfinder.json path binding looked at first, absent; or, when no
configuration binds the bundle, each wayfinder.json path binding
looked at, absent.
A host that selects itself captures projectFiles with its selection,
before selecting (KnowledgeProjectFiles.forBundle or
KnowledgeProjectFiles.read) or from the bytes it read, so a change
between its selection and prepare is refused too. Without them, the
writer reads them now: with a selection, the configuration it names
(a SelectedProfile's config, or the file an UnselectedProfile's
reason is located at), else the files binding the bundle reads; without
one, the files binding the bundle reads, before it selects.
Without selection, the bundle binds through the nearest
wayfinder.json above it. By default that search climbs towards the
filesystem root, as the wayfinder command's does. A host that knows
the project root passes it as projectRoot, and the search then reads
no wayfinder.json above it (WayfinderProjectConfig.bind), so a
bundle with none within it is judged by OKF alone. With a selection,
projectRoot bounds only the search for the project files to track.
cancel is checked between steps and passed to the resolver and the
assessor; a cancelled prepare throws WayfinderException.cancelled.
What the assessor throws, prepare throws; an assessment it returns
without a base throws WayfinderException assessment-failed.
Throws KnowledgeChangeException for a change that cannot be described against the bundle, KnowledgeStaleWriteException when the bundle changed while it was read, KnowledgeWriteFailedException when the bundle cannot be locked or read, and ArgumentError for a change, stamp or log entry the writer cannot record as given.
Implementation
Future<KnowledgeWritePlan> prepare(
String bundle,
KnowledgeChange change, {
required KnowledgeStamp stamp,
KnowledgeLog logEntry = KnowledgeLog.lifecycle,
ProfileSelection? selection,
KnowledgeProjectFiles? projectFiles,
String? projectRoot,
WayfinderCancellation? cancel,
}) async {
_check(change, stamp, logEntry);
throwIfCancelled(cancel);
try {
return await _prepare(
bundle,
change,
stamp: stamp,
log: logEntry,
selection: selection,
projectFiles: projectFiles,
projectRoot: projectRoot,
cancel: cancel,
);
} on FileSystemException catch (error) {
throw KnowledgeWriteFailedException._of(error);
}
}