infinibrowser
Version:
A TypeScript wrapper for the Infinibrowser API
169 lines • 4.46 kB
text/typescript
//#region src/types/items.d.ts
type ElementType = {
readonly id: string;
readonly emoji: string;
};
type RecipeType = readonly [ElementType, ElementType];
type UseType = {
readonly pair: ElementType;
readonly result: ElementType;
};
type StepType = {
readonly a: ElementType;
readonly b: ElementType;
readonly result: ElementType;
};
type LineageType = readonly StepType[];
type ShareStepType = readonly [ElementType, ElementType, ElementType];
type ShareLineageType = readonly ShareStepType[];
//#endregion
//#region src/types/data.d.ts
type ItemDataType = {
readonly id: number;
readonly text: string;
readonly emoji: string;
readonly use_count: number;
readonly recipe_count: number;
readonly depth: number;
};
type RecipesDataType = {
readonly total: number;
readonly recipes: RecipeType[];
};
type UsesDataType = {
readonly total: number;
readonly uses: UseType[];
};
type LineageDataType = {
readonly steps: LineageType;
readonly missing: Record<string, "loop" | (string & {})>;
};
type CustomLineageDataType = LineageDataType;
//#endregion
//#region src/types/errors.d.ts
interface UknownElement {
code: 404;
message: "Unknown element";
}
interface InvalidElementId {
code: 400;
message: "Invalid element ID";
}
//#endregion
//#region src/client.d.ts
interface InfinibrowserConfig<TApiUrl extends string, TTimeOut extends number> {
readonly API_URL: TApiUrl;
readonly timeout: TTimeOut;
readonly request?: Readonly<RequestInit>;
}
type FetchResponseError = Readonly<{
ok: false;
error_code: "SYNTAX_ERROR";
error: SyntaxError;
} | {
ok: false;
error_code: "TIMEOUT";
error: DOMException;
} | {
ok: false;
error_code: "UNKNOWN_ERROR";
error: unknown;
}>;
declare class Infinibrowser<TApiUrl extends string, TTimeOut extends number> {
#private;
readonly $config: InfinibrowserConfig<TApiUrl, TTimeOut>;
constructor(config: InfinibrowserConfig<TApiUrl, TTimeOut>);
$refined<TApiUrl extends string, TTimeOut extends number>(config: InfinibrowserConfig<TApiUrl, TTimeOut>): Infinibrowser<TApiUrl, TTimeOut>;
getItem(id: string): Promise<FetchResponseError | Readonly<{
ok: true;
data: ItemDataType;
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: UknownElement;
response: Response;
}>>;
getRecipes(id: string, {
offset
}?: {
offset?: number;
}): Promise<FetchResponseError | Readonly<{
ok: true;
data: RecipesDataType;
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: UknownElement;
response: Response;
}>>;
getUses(id: string, {
offset
}?: {
offset?: number;
}): Promise<FetchResponseError | Readonly<{
ok: true;
data: UsesDataType;
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: UknownElement;
response: Response;
}>>;
getLineage(id: string): Promise<FetchResponseError | Readonly<{
ok: true;
data: LineageDataType;
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: UknownElement;
response: Response;
}>>;
getCustomLineage(id: string): Promise<FetchResponseError | Readonly<{
ok: true;
data: LineageDataType;
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: InvalidElementId;
response: Response;
}>>;
optimizeLineage(id: string): Promise<FetchResponseError | Readonly<{
ok: true;
data: {
readonly id: string;
readonly before: number;
readonly after: number;
};
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: unknown;
response: Response;
}>>;
shareLineage(steps: ShareLineageType): Promise<FetchResponseError | Readonly<{
ok: true;
data: {
readonly id: string;
};
response: Response;
} | {
ok: false;
error_code: "NOT_OK";
data: unknown;
response: Response;
}>>;
}
declare const API_URL = "https://infinibrowser.wiki/api";
declare const DEFAULT_OPTIONS: {
readonly API_URL: "https://infinibrowser.wiki/api";
readonly timeout: 1000;
};
declare const ib: Infinibrowser<"https://infinibrowser.wiki/api", 1000>;
//#endregion
export { API_URL, CustomLineageDataType, DEFAULT_OPTIONS, ElementType, Infinibrowser, InvalidElementId, ItemDataType, LineageDataType, LineageType, RecipeType, RecipesDataType, ShareLineageType, ShareStepType, StepType, UknownElement, UseType, UsesDataType, ib };