61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import type { ExactReference, ManagedReference } from "@quixos/camino-react";
|
|
import type { ComponentProps as ReactProps } from "react";
|
|
import type { Modules } from "./gen/client.js";
|
|
export type Root = ReactProps<Modules["Reader"]>["input"]["body"]["root"];
|
|
export type NavigationValues = ReactProps<Modules["Reader"]>["input"]["nav"]["root"];
|
|
export type FeatureNode = Root["features"]["entries"][number]["node"];
|
|
export type ReaderNode = Root["readers"]["entries"][number]["node"];
|
|
export type TaskNode = Root["tasks"]["entries"][number]["node"];
|
|
export type Catalog = readonly {
|
|
key: string;
|
|
label: string;
|
|
strategy: string;
|
|
scope: string;
|
|
processorRevision: string;
|
|
config: string;
|
|
}[];
|
|
export type DocNode = {
|
|
_camino: { ref: ExactReference };
|
|
data: { title: string; text: string; sourceRevision: string; source: string; url: string; attribution: string };
|
|
reader: { _camino: { ref: ExactReference } } | null;
|
|
canonical: { data: { title: string } } | null;
|
|
adaptation: string;
|
|
jobs: { entries: readonly { node: JobNode }[] };
|
|
};
|
|
export type JobNode = {
|
|
configuration: string;
|
|
_camino: { ref: ExactReference };
|
|
data: {
|
|
key: string;
|
|
kind: string;
|
|
featureRevision: number;
|
|
sourceRevision: string;
|
|
start: number;
|
|
end: number;
|
|
status: string;
|
|
output: string;
|
|
error: string;
|
|
createdAt: string;
|
|
};
|
|
feature: { _camino: { ref: ExactReference } } | null;
|
|
request: { _camino: { ref: ExactReference }; progress: { status: string; reason: string } } | null;
|
|
};
|
|
export const asInterface = <Name extends string>(
|
|
ref: ExactReference,
|
|
name: Name,
|
|
): ManagedReference<"interface", `interface:reading:${Name}@1`> => ({
|
|
...ref,
|
|
expectation: { kind: "interface", id: `interface:reading:${name}@1` },
|
|
});
|
|
export const asAtom = (ref: ExactReference, name: string): ExactReference => ({
|
|
...ref,
|
|
expectation: { kind: "atom", id: `atom:reading:${name}` },
|
|
});
|
|
export const errorMessage = (error: unknown) => (error instanceof Error ? error.message : String(error));
|
|
/** Remote and transaction operations have the same accepted/rejected ticket boundary. */
|
|
export async function accepted<T>(ticket: { settled: Promise<{ status: string; value?: T }> }): Promise<T> {
|
|
const outcome = await ticket.settled;
|
|
if (outcome.status !== "accepted") throw Error(JSON.stringify(outcome));
|
|
return outcome.value as T;
|
|
}
|