|
| 1 | +/** |
| 2 | + * How a REPL entry obtains repository operations, or does not. |
| 3 | + * |
| 4 | + * `run-repositories.ts` beside this one answers the same question for `xmd |
| 5 | + * run`, and the two differ in exactly one way that matters here: an ordinary |
| 6 | + * run's provider is installed per execution and remembers nothing, while an |
| 7 | + * entry's is installed per *entry* and retains what that entry did, so an |
| 8 | + * entry interrupted partway through repository work can be reopened and |
| 9 | + * continue instead of repeating it. |
| 10 | + * |
| 11 | + * What this module holds is the contract and nothing else. A factory rather |
| 12 | + * than a value, for the reason the ordinary installer is one and then some: the |
| 13 | + * host belongs to the executing entry's own task, holds that entry's owner, |
| 14 | + * selections, leases, credentials, lanes and publication permission, and ends |
| 15 | + * with it. Constructing one while the command is still assembling itself would |
| 16 | + * give every entry of the session the same owner and make a passive view — a |
| 17 | + * cold history somebody is only reading — acquire a lease and a checkout. |
| 18 | + * |
| 19 | + * Nothing here names a runtime. The shared command path cannot import the Deno |
| 20 | + * adapter at all: its module graph reaches `node:sqlite`, which Bun does not |
| 21 | + * have, so a static import would stop `xmd` loading there rather than refusing |
| 22 | + * a repository operation. The implementation lives beside the entrypoints that |
| 23 | + * can use it, in `deno-repositories.ts`, and a host that supplies none leaves |
| 24 | + * its entries refusing repository work before a lock, a credential, a |
| 25 | + * subprocess or a request exists. |
| 26 | + */ |
| 27 | + |
| 28 | +import type { Operation } from "effection"; |
| 29 | +import type { ExecutionInstallation, FragmentFileAccess } from "@executablemd/core/host"; |
| 30 | + |
| 31 | +/** What one entry tells its host about itself. */ |
| 32 | +export interface ReplEntryHostRequest { |
| 33 | + /** |
| 34 | + * The execution this entry belongs to, as the host established it. |
| 35 | + * |
| 36 | + * Opaque, and the first half of the owner every record this entry writes is |
| 37 | + * retained under. It is the identifier the history file is named by, so a |
| 38 | + * location reopens the entries of that execution and of no other. |
| 39 | + */ |
| 40 | + readonly executionId: string; |
| 41 | + /** |
| 42 | + * This entry's own key, in the order the entries were admitted. |
| 43 | + * |
| 44 | + * Immutable once admitted, which is what makes the owner stable across |
| 45 | + * opens: the same entry of the same execution is the same owner however many |
| 46 | + * times it is reopened, and the entry after it is a different one however |
| 47 | + * identical its text. |
| 48 | + */ |
| 49 | + readonly entryKey: string; |
| 50 | + /** The canonical identity of the source this entry is running. */ |
| 51 | + readonly source: string; |
| 52 | +} |
| 53 | + |
| 54 | +/** What an entry's repository host offers the task that built it. */ |
| 55 | +export interface ReplEntryHost { |
| 56 | + /** |
| 57 | + * What this entry declares to its own execution. |
| 58 | + * |
| 59 | + * Its journal admission, its canonical file-mutation handlers and the |
| 60 | + * repository components it answers for — installed into that one execution |
| 61 | + * and nowhere else. |
| 62 | + */ |
| 63 | + readonly installation: ExecutionInstallation; |
| 64 | + /** |
| 65 | + * The one captured file access this entry's generated fragments run on. |
| 66 | + * |
| 67 | + * Bound into the command's unchanged generated ceiling, so a fragment's write |
| 68 | + * inside a checkout this entry has selected is retained exactly as an |
| 69 | + * authored one is — and a fragment reaches it rather than `API.Files`, which |
| 70 | + * is what keeps a document, a repository component or middleware out from |
| 71 | + * between them. |
| 72 | + */ |
| 73 | + readonly files: FragmentFileAccess; |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + * How one entry's repository host is built, when this runtime has one. |
| 78 | + * |
| 79 | + * Called by the sequential entry task, once per entry, with the trusted |
| 80 | + * execution identity and the admission-order key. Everything it acquires |
| 81 | + * belongs to that task. |
| 82 | + */ |
| 83 | +export type ReplEntryHostFactory = (request: ReplEntryHostRequest) => Operation<ReplEntryHost>; |
0 commit comments