import { delay } from "@milaboratories/helpers"; import type { AuthorMarker, BlockOutputsBase, BlockState, FileLike, ImportFileHandle, ListFilesResult, LocalImportFileHandle, NavigationState, OpenDialogOps, OpenMultipleFilesResponse, OpenSingleFileResponse, PlatformaV2, ResultOrError, StorageHandle, ValueWithUTag, ValueWithUTagAndAuthor, } from "@platforma-sdk/model"; import type { Operation } from "fast-json-patch"; import type { BlockMock } from "./BlockMock"; import { getLsFilesResult } from "./utils"; export function createMockApi< Args, Outputs extends BlockOutputsBase, UiState = unknown, Href extends `/${string}` = `/${string}`, >(block: BlockMock): PlatformaV2 { return { apiVersion: 2, sdkInfo: { sdkVersion: "dev", }, async dispose(): Promise> { return block.dispose(); }, loadBlockState: async function (): Promise< ResultOrError>> > { return block.loadBlockState(); }, getPatches: async function ( uTag: string, ): Promise>> { return block.getPatches(uTag); }, async setBlockArgs(value: Args, author?: AuthorMarker): Promise> { return block.setBlockArgs(value, author); }, async setBlockUiState(value: UiState, author?: AuthorMarker): Promise> { return block.setBlockUiState(value, author); }, async setBlockArgsAndUiState( args: Args, uiState: UiState, author?: AuthorMarker, ): Promise> { return block.setBlockArgsAndUiState(args, uiState, author); }, async setNavigationState(navigationState: NavigationState): Promise> { return block.setNavigationState(navigationState); }, // eslint-disable-next-line @typescript-eslint/no-explicit-any blobDriver: undefined as any, // eslint-disable-next-line @typescript-eslint/no-explicit-any logDriver: undefined as any, lsDriver: { async getStorageList() { return [ { id: "local", name: "local", handle: "local://test", initialFullPath: "/", isInitialPathHome: false, }, ]; }, async listFiles(_storage: StorageHandle, fullPath: string): Promise { await delay(10); return getLsFilesResult(fullPath); }, async getLocalFileContent(_file: LocalImportFileHandle): Promise { return Uint8Array.of(0, 1); }, async getLocalFileSize(_file: LocalImportFileHandle): Promise { return 3; }, async showOpenMultipleFilesDialog(_ops: OpenDialogOps): Promise { return {}; }, async showOpenSingleFileDialog(_ops: OpenDialogOps): Promise { return {}; }, async fileToImportHandle(_file: FileLike): Promise { return "" as ImportFileHandle; }, }, // eslint-disable-next-line @typescript-eslint/no-explicit-any pFrameDriver: undefined as any, }; }