@runic-artifex/views
BridgeDiagnosticinterfaceA failure or terminal event the Views runtime observed.
BridgeDiagnosticListenertype aliastype BridgeDiagnosticListener = (diagnostic: BridgeDiagnostic) => void;No documentation.
BridgeErrorclassA Bridge call that .NET or the transport did not complete.
BridgeErrorKindtype aliastype BridgeErrorKind = "rejected" | "cancelled" | "failed" | "disconnected" | "timeout" | "unavailable";Why a Bridge call did not complete.
unavailablemeans no host installedwindow.__runicBridge;timeoutmeans a Bridge exists but did not connect in time.BridgeErrorOptionsinterfacebridgeFailurefunctionfunction bridgeFailure<TFailure>(failure: TFailure): BridgeOutcome<never, TFailure>;An outcome with the declared
failure.BridgeFailureDetailinterfaceLocal failure detail that .NET adds to an error reply only in development (host environment
Development, orBridgeDiagnostics.IncludeFailureDetail).BridgeInteractionContextinterfaceBridgeOperationinterfaceA recoverable .NET command execution identified by its request id.
BridgeOperationCancelKindtype aliastype BridgeOperationCancelKind = "cancellation-requested" | "not-running" | "unknown" | "expired";No documentation.
BridgeOperationCancelResultinterfaceBridgeOperationDeliveryinterfaceWhy a completed operation's result or failure could not be delivered.
BridgeOperationDeliveryKindtype aliastype BridgeOperationDeliveryKind = "result-too-large" | "result-encoding-failed" | "stream-overflow" | "stream-retention-too-large";No documentation.
BridgeOperationStatustype aliastype BridgeOperationStatus<TResult = void, TFailure = never> = [ TFailure ] extends [ never ] ? Exclude<BridgeOperationStatusOf<TResult, never>, { readonly kind: "domain-failed"; }> : BridgeOperationStatusOf<TResult, TFailure>;The status of an operation, discriminated by
kind. An operation that declares no failure type never reportsdomain-failed.BridgeOperationStatusKindtype aliastype BridgeOperationStatusKind = "running" | "succeeded" | "domain-failed" | "failed" | "cancelled" | "expired" | "unknown" | "timedOut";domain-failedmeans the command failed with its declared failure type.timedOutis a client-side terminal state:wait({ timeout })passed its deadline and sent a cancellation request. .NET never reports it.BridgeOperationStatusOftype aliastype BridgeOperationStatusOf<TResult, TFailure> = BridgeOperationIdentity & { readonly kind: "running"; } | BridgeOperationIdentity & { readonly kind: "succeeded"; readonly result?: TResult; readonly delivery?: BridgeOperationDelivery; readonly stream?: true; } | BridgeOperationIdentity & { readonly kind: "domain-failed"; readonly failure?: TFailure; readonly delivery?: BridgeOperationDelivery; readonly stream?: true; } | BridgeOperationIdentity & { readonly kind: "failed"; readonly error: { readonly kind: "failed"; readonly message: string; readonly detail?: BridgeFailureDetail; }; readonly stream?: true; } | BridgeOperationIdentity & { readonly kind: "cancelled" | "expired" | "unknown"; readonly stream?: true; } | BridgeOperationIdentity & { readonly kind: "timedOut"; readonly cancellation: BridgeOperationCancelKind | "unobserved"; };Every operation status, including
domain-failed. Generic code that builds statuses uses this type; applications readBridgeOperationStatus.BridgeOperationStreamIteminterfaceBridgeOperationStreamPageinterfaceBridgeOperationUncertainErrorclassThe client could not observe whether .NET admitted or completed an operation.
BridgeOperationWaitOptionsinterfaceBridgeOutcometype aliastype BridgeOutcome<TValue, TFailure> = { readonly ok: true; readonly value: TValue; readonly [outcomeBrand]: true; } | { readonly ok: false; readonly failure: TFailure; readonly [outcomeBrand]: true; };How a command or operation that declares a failure type ended:
okwith its value, or notokwith the declaredfailure. Unexpected failures still reject withBridgeError.BridgeOutcomeFailuretype aliastype BridgeOutcomeFailure<T> = [ OutcomeOf<T> ] extends [ never ] ? never : OutcomeOf<T> extends { readonly failure: infer F; } ? F : never;The declared failure type of a command result:
Ffor aBridgeOutcome<_, F>, otherwisenever.BridgeStreamOperationinterfaceAn operation whose command yields a stream of
TItemvalues, read throughstream(). Its status andoutcome()carry no value, so it is aBridgeOperation<void, TFailure>.bridgeSuccessfunctionfunction bridgeSuccess<TValue>(value: TValue): BridgeOutcome<TValue, never>;A successful outcome with
value.BridgeValidationMessageinterfaceBridgeValidationStateinterfacecollectionViewportfunctionfunction collectionViewport(options: { readonly totalCount: number; readonly scrollTop: number; readonly height: number; readonly rowHeight: number; readonly overscan?: number; }): CollectionViewport;Computes a bounded viewport for fixed-height rows in any web framework.
CollectionViewportinterfaceCollectionViewportControllerinterfaceFollows a scroll container and publishes its
CollectionViewport. Framework bindings attach their element and pass the current row count.CollectionViewportOptionsinterfaceThe list a viewport controller measures: its row count, fixed row height and overscan.
CommandControllerinterfaceRuns a command and tracks whether it is pending and why it last failed.
CommandStateinterfaceOne consistent reading of a
CommandController.createCollectionViewportControllerfunctionfunction createCollectionViewportController(options: CollectionViewportOptions): CollectionViewportController;Creates the framework-neutral viewport tracker behind each binding's
useCollectionViewport. Scroll events are coalesced to one measurement per animation frame, and aResizeObserverfollows the container's height.currentonly changes when the requested range or sizes change.createCommandControllerfunctionfunction createCommandController<TArgs extends readonly unknown[], TReturn>(command: (...args: TArgs) => TReturn): CommandController<TArgs, Awaited<TReturn>, BridgeOutcomeFailure<Awaited<TReturn>>>;Creates the framework-neutral command runner behind
useCommandandinjectCommand. The command may return a plain value orundefined, for example() => client?.increment()while the client is still connecting. It may also return one of several commands' promises, such asname => name === "save" ? client.save() : client.discard(); the result is then their union andfailurethe union of their declared failures.createViewControllerfunctionfunction createViewController<TClient extends ViewClient>(options?: ViewControllerOptions<TClient>): ViewController<TClient>;Creates the framework-neutral controller behind
useViewandinjectView.FieldBaselinetype aliastype FieldBaseline<T> = { readonly value: T; readonly version: number; };No documentation.
FieldWriteOptionstype aliastype FieldWriteOptions<T> = { readonly requestId: string; readonly baseline: FieldBaseline<T>; };No documentation.
FieldWriteReceipttype aliastype FieldWriteReceipt<T> = { readonly kind: "applied"; readonly snapshot: FieldBaseline<T>; readonly validation?: string; } | { readonly kind: "committed-with-error"; readonly snapshot: FieldBaseline<T>; readonly message: string; } | { readonly kind: "rejected"; readonly message: string; } | { readonly kind: "conflict"; readonly incoming: FieldBaseline<T>; readonly message: string; };No documentation.
InteractionSurfaceinterfaceisBridgeOutcomefunctionfunction isBridgeOutcome(value: unknown): value is BridgeOutcome<unknown, unknown>;True for an outcome created by
bridgeSuccessorbridgeFailure, including by another copy of this package.isViewClientfunctionfunction isViewClient<TClient extends ViewClient>(source: ViewConnector<TClient> | TClient): source is TClient;True for a connected client; false for a connector.
matchCasefunctionfunction matchCase<F extends { readonly $case: string; }, H extends { readonly [K in F["$case"]]: (value: Extract<F, { readonly $case: K; }>) => unknown; }>(value: F, cases: H): ReturnType<H[F["$case"]]>;Handles every case of a
$caseunion, such as a declared failure:const message = matchCase(outcome.failure, { titleRequired: () => "A note needs a title.", titleTaken: failure => `"${failure.existingTitle}" exists.`, });A missing handler is a type error. The result is the union of the handlers' return types.
onBridgeDiagnosticfunctionfunction onBridgeDiagnostic(listener: BridgeDiagnosticListener): () => void;Observes Views runtime failures: failed routes (with their .NET detail in development), a missing or unconnected Bridge, operation timeouts and errors the runtime caught from listeners. The Vite plugin forwards these to the Runic DevTools dock. Returns a function that stops observing.
RunicBridgeClientinterfaceThe host-neutral Bridge a host script installs as
window.__runicBridge.ViewClientinterfaceThe framework-neutral surface every generated client shares.
ViewConnectorinterfaceAnything that connects a client: a generated page reference or
{ connect: connect<Name> }.ViewControllerinterfaceThe connect, observe and release state machine that every framework binding shares. A binding feeds it the current source and renders
current.ViewControllerOptionsinterfaceViewControllerStateinterfaceOne consistent reading of a
ViewController. A new object is published for every change.ViewReferenceinterfaceA generated content reference: a logical .NET View presented in a ViewModel slot.
ViewSourcetype aliastype ViewSource<TClient extends ViewClient> = ViewConnector<TClient> | TClient | null | undefined;What a framework binding follows. A connector is connected and released by the binding; an already connected client is only observed, and its owner disposes it.
viewSourceIdentityfunctionfunction viewSourceIdentity<TClient extends ViewClient>(source: ViewSource<TClient>): object | undefined;The identity a binding compares to decide whether a source changed: the client itself or the connect function.
waitForBridgefunctionfunction waitForBridge(timeoutMilliseconds?: number): Promise<RunicBridgeClient>; function waitForBridge(options?: WaitForBridgeOptions): Promise<RunicBridgeClient>;Waits for the installed host Bridge to report a connection to .NET. Rejects with an
unavailableBridgeError when no host installedwindow.__runicBridge, and with atimeoutBridgeError when it did not connect in time.WaitForBridgeOptionsinterface
@runic-artifex/views/generated
BridgeCollectionDefinitioninterfaceGenerated item codecs and stable keys for an incremental state collection.
BridgeCollectionsinterfaceThe keyed collections of one generated client, passed to
connectViewascollections. A View without keyed collections does not bundle this code.BridgeInteractionstype aliastype BridgeInteractions = (scope: InteractionScope) => InteractionSession;The interactions of one generated client, passed to
connectViewasinteractions. A View without interactions does not bundle this code.BridgeOperationRuntimeHandletype aliastype BridgeOperationRuntimeHandle<TResult, TFailure> = BridgeOperation<TResult, TFailure> & BridgeStreamOperation<TResult, TFailure>;What the runtime returns for a started or recovered operation: either handle shape.
bridgeOperationsconstantconst bridgeOperations: BridgeOperations;No documentation.
BridgeOperationsinterfaceThe operation protocol, passed to
connectViewasoperationsby a generated client with operations. A View without operations does not bundle it.decodeFailureis given for an operation that declares a failure type.connectViewfunctionfunction connectView<TState>(options: ViewConnectOptions<TState>): Promise<ViewConnection<TState>>;Connects one generated client lease to its route. Leases of one route share a single snapshot, push callback and revision; each lease has its own listeners, mount token and interaction handlers.
decodeBridgeValidationfunctionfunction decodeBridgeValidation(value: unknown): BridgeValidationState;Decodes the
validationstate of a ViewModel with validation.defineCollectionfunctionfunction defineCollection<T>(decode: (wire: unknown) => T, key: (item: T) => string): BridgeCollectionDefinition;Keeps collection codecs typed in generated clients.
defineCollectionsfunctionfunction defineCollections(definitions: Readonly<Record<string, BridgeCollectionDefinition>>): BridgeCollections;Binds the collection codecs of a generated client to the code that applies their changes.
defineInteractionsfunctionfunction defineInteractions(definitions: Readonly<Record<string, InteractionDefinition>>): BridgeInteractions;Binds the interaction codecs of a generated client to the interaction protocol.
InteractionDefinitioninterfaceGenerated codec and contract of one ReactiveUI interaction.
InteractionScopeinterfaceThe connection one presentation's interaction handlers run in.
InteractionSessioninterfaceThe interaction handlers of one connected presentation.
OperationScopeinterfaceThe connection an operation starts on.
ViewConnectioninterfaceThe runtime half of a generated client. Generated code is its only intended caller.
ViewConnectOptionsinterfaceHow a generated module connects one ViewModel route.
viewReferencesfunctionfunction viewReferences<R extends object>(create: (id: string) => R): (id: string) => R;Returns a per-module cache of content references. A reference stays the same object while it is reachable, so frameworks can key Views by identity.
@runic-artifex/views/generated/wire
arrayfunctionfunction array<T>(value: unknown, decode: (item: unknown) => T): readonly T[];No documentation.
bigintfunctionfunction decodeBigInt(value: unknown, minimum?: string, maximum?: string): bigint;No documentation.
booleanfunctionfunction decodeBoolean(value: unknown): boolean;No documentation.
dateOnlyfunctionfunction dateOnly(value: unknown): string;No documentation.
dateTimefunctionfunction dateTime(value: unknown): string;No documentation.
dateTimeOffsetfunctionfunction dateTimeOffset(value: unknown): string;No documentation.
decimalfunctionfunction decimal(value: unknown): string;No documentation.
durationfunctionfunction duration(value: unknown): string;No documentation.
encodeUnionfunctionfunction encodeUnion(value: unknown): Record<string, unknown>;No documentation.
enumNamefunctionfunction enumName<T extends string = string>(value: unknown, names?: readonly T[]): T;No documentation.
finiteNumberfunctionfunction finiteNumber(value: unknown): number;No documentation.
guidfunctionfunction guid(value: unknown): string;No documentation.
int64Stringfunctionfunction int64String(value: unknown): string;No documentation.
integerfunctionfunction integer(value: unknown, minimum: number, maximum: number): number;No documentation.
objectfunctionfunction decodeObject<T>(value: unknown, decode: (item: Record<string, unknown>) => T): T;No documentation.
stringfunctionfunction decodeString(value: unknown): string;No documentation.
stringRecordfunctionfunction stringRecord<T>(value: unknown, decode: (item: unknown) => T): Readonly<Record<string, T>>;No documentation.
timeOnlyfunctionfunction timeOnly(value: unknown): string;No documentation.
unionfunctionfunction union(value: unknown): any;No documentation.
@runic-artifex/views/mock
createMockBridgefunctionfunction createMockBridge(options?: MockBridgeOptions): MockBridge;No documentation.
installMockBridgefunctionfunction installMockBridge(bridge?: MockBridge): MockBridge;Installs a mock as
window.__runicBridge, so generated clients connect to it instead of waiting for a .NET host. Call it before the firstconnect*().MockBridgeinterfaceAn in-memory
__runicBridgethat answers generated-client routes without .NET.mockBridgeInternalsfunctionfunction mockBridgeInternals(bridge: MockBridge): MockBridgeInternals;No documentation.
MockBridgeInternalsinterfaceInternal hooks the generated typed mocks use. Not part of the public API.
MockBridgeOptionsinterfaceMockCallinterfaceMockCollectioninterfaceEdits one keyed collection of a mock View and pushes each edit as a delta frame, like a .NET
[RunicCollection]. InsideMockView.batchthe edits share one frame.MockCollectionChangeinterfaceOne keyed collection edit of a delta frame, as .NET writes it.
MockCommandHandlertype aliastype MockCommandHandler<TState, TArgs extends readonly unknown[] = [ ]> = (state: TState, ...args: TArgs) => Awaitable<Patch<TState> | void>;Runs a command and returns the state changes it makes. A thrown error becomes the client's BridgeError;
throw mockFailure(failure)resolves the client's outcome with the declared failure.MockDomainFailureinterfaceA declared failure (
domain-failed) the mock answers instead of running a handler. A command replies with it; aStart{Command}admits an operation that has already failed with it.MockErrorFailureinterfaceAn unexpected failure the mock answers instead of running a handler.
mockFailurefunctionfunction mockFailure<TFailure>(failure: TFailure, message?: string): Error;An error that a mock command or operation handler throws to fail with its declared failure:
throw mockFailure({ $case: "titleRequired" }).MockFailuretype aliastype MockFailure = MockErrorFailure | MockDomainFailure;A failure the mock answers instead of running a handler.
mockFailureOffunctionfunction mockFailureOf(error: unknown): { readonly failure: unknown; } | undefined;No documentation.
MockFailureOftype aliastype MockFailureOf<TMethod> = TMethod extends (...args: never[]) => Promise<infer R> ? R extends { outcome(...args: never[]): Promise<infer O>; } ? BridgeOutcomeFailure<O> : BridgeOutcomeFailure<R> : never;The declared failure type of a client method:
Ffor a command that resolvesBridgeOutcome<_, F>or astart{Command}whose operation declaresF.MockInteractionOptionsinterfaceMockInteractionReplytype aliastype MockInteractionReply = { readonly kind: "answered"; readonly output: unknown; } | { readonly kind: "cancelled"; } | { readonly kind: "failed"; } | { readonly kind: "unhandled"; };How the browser answered an interaction request.
MockMethodNametype aliastype MockMethodName<TClient> = Exclude<keyof TClient & string, "snapshot" | "subscribe" | "dispose" | "interactions" | "fieldBaseline" | `recover${string}` | `${string}WithRequestId`>;A client method name a failure can target, such as
save,startSave,setTitleorcanSetViewport.MockOperationinterfaceAn operation a client started with
start{Command}().MockOperationHandlertype aliastype MockOperationHandler = (state: MockState, input: unknown, operation: MockOperation) => MockOperationOutcome | void | Promise<MockOperationOutcome | void>;Runs a started operation. When the returned promise resolves, a still running operation succeeds with its outcome; a throw fails it, or cancels it after the client asked to cancel, and
throw mockFailure(failure)ends itdomain-failed. Cancellation is cooperative, as in .NET: a cancel request abortsoperation.signal, and the operation keeps running until its handler stops."manual"leaves every operation running until the test settles it throughMockView.operations().MockOperationKindtype aliastype MockOperationKind = "running" | "succeeded" | "domain-failed" | "failed" | "cancelled";No documentation.
MockOperationOutcomeinterfaceWhat an operation handler's completion means.
MockReferenceinterfaceThe wire form of a content reference in a mock state, such as
{ kind: "editor", id: "1" }.MockRegisteredViewinterfaceThe mock's internal state of one View route.
MockRoutetype aliastype MockRoute = (state: MockState, ...args: unknown[]) => MockState | boolean | string | void | Promise<MockState | boolean | string | void>;Answers one route suffix of a mock View. A returned object is merged into the state, a boolean answers a
Can{Command}query, and a string is the raw reply. A thrown error becomes a failed reply with its type, message and stack asdetail; an error with akindkeeps that kind.throw mockFailure(failure)replies with a declared failure (domain-failed).MockSchedulingtype aliastype MockScheduling = "immediate" | "manual";When the mock delivers replies and pushed states.
immediate(the default) answers each call as soon as its handler returns and pushes synchronously.manualqueues calls and pushes untilflush(),flushUntil()oradvance(), so a test decides exactly when the client observes each one.MockSetterHandlertype aliastype MockSetterHandler<TState, TValue> = (state: TState, value: TValue) => Awaitable<Patch<TState> | void>;Runs before a setter or checked write applies
value. Return more state changes, such as a dirty flag; throw to reject the value.MockStatetype aliastype MockState = Record<string, unknown>;A wire state as .NET serializes it, without
revision.MockTypedCollectioninterfaceA keyed collection of a typed mock. Each edit pushes a delta frame.
MockTypedInteractioninterfaceAn interaction that .NET asks the browser to handle.
MockTypedOperationinterfaceAn operation that a client started with
start{Command}(), with typed input and results.MockTypedOperationHandlertype aliastype MockTypedOperationHandler<TState, TInput, TResult, TFailure = never> = (state: TState, input: TInput, operation: MockTypedOperation<TInput, TResult, TFailure>) => Awaitable<MockTypedOperationOutcome<TState, TResult> | void>;Runs a started operation. When it returns, a still running operation succeeds with the outcome; a throw fails it, and
throw mockFailure(failure)ends it with its declared failure. Return a promise that waits on the operation's signal, or use"manual", to settle it from the test.MockTypedOperationOutcomeinterfacemockTypedViewfunctionfunction mockTypedView(bridge: MockBridge, spec: MockTypedViewSpec, definition: MockTypedViewDefinition): unknown;Registers a typed mock View. Generated
mock{Name}()helpers call this with their client's codecs; applications call the generated helper.MockTypedViewinterfaceThe typed mock of one generated client, created by a generated
mock{Name}().MockTypedViewDefinitioninterfaceThe loose shape of a generated mock definition.
MockTypedViewSpecinterfaceWhat a generated
mock{Name}()knows about its client. Generated code is its only intended caller.MockViewinterfaceMockViewDefinitioninterface