refactor: Introduce dedicated Document and Asset types and migrate codebase from DocumentLike.
This commit is contained in:
@@ -9,13 +9,7 @@ import type { DocumentId } from '../types/identifiers';
|
||||
|
||||
type FolderId = DocumentId | 'root';
|
||||
|
||||
type DocumentLike = {
|
||||
id?: DocumentId;
|
||||
folder_id?: FolderId | null;
|
||||
filename?: string | null;
|
||||
current_version?: Record<string, unknown>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
import type { Document } from '../types/documents';
|
||||
|
||||
type DocumentLink = {
|
||||
url?: string;
|
||||
@@ -29,11 +23,11 @@ type NavigateHandler = (path: string, options?: { replace?: boolean }) => void;
|
||||
interface UseDocumentPreviewArgs {
|
||||
routeDocumentId?: DocumentId | null;
|
||||
documentsManager: {
|
||||
getById: (id: DocumentId) => DocumentLike | null;
|
||||
ensure: (id: DocumentId) => Promise<DocumentLike | null>;
|
||||
getMany: (ids: DocumentId[]) => DocumentLike[];
|
||||
getById: (id: DocumentId) => Document | null;
|
||||
ensure: (id: DocumentId) => Promise<Document | null>;
|
||||
getMany: (ids: DocumentId[]) => Document[];
|
||||
subscribe: (listener: () => void) => () => void;
|
||||
ingest: (docs: unknown[]) => { canonical: DocumentLike[]; changed: boolean };
|
||||
ingest: (docs: unknown[]) => { canonical: Document[]; changed: boolean };
|
||||
};
|
||||
selectedFolder?: FolderId | null;
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
@@ -50,7 +44,7 @@ interface UseDocumentPreviewArgs {
|
||||
interface UseDocumentPreviewResult {
|
||||
documentLinks: Map<DocumentId, DocumentLink>;
|
||||
ensureDownloadUrl: (documentId: DocumentId, options?: { force?: boolean }) => Promise<DocumentLink | null>;
|
||||
ensurePreviewData: (documentId: DocumentId) => Promise<DocumentLike | null>;
|
||||
ensurePreviewData: (documentId: DocumentId) => Promise<Document | null>;
|
||||
openDocumentPreview: (documentId: DocumentId, options?: { replace?: boolean }) => void;
|
||||
closeDocumentPreview: (folderId?: FolderId) => void;
|
||||
resetPreviewState: () => void;
|
||||
@@ -149,7 +143,7 @@ const useDocumentPreview = ({
|
||||
);
|
||||
|
||||
const ensurePreviewData = useCallback(
|
||||
async (documentId: DocumentId): Promise<DocumentLike | null> => {
|
||||
async (documentId: DocumentId): Promise<Document | null> => {
|
||||
if (!documentId) return null;
|
||||
|
||||
const findInCache = () => documentsManager.getById(documentId);
|
||||
@@ -163,7 +157,7 @@ const useDocumentPreview = ({
|
||||
if (!doc) {
|
||||
const fetched = await fetchDocument(documentId);
|
||||
const { canonical } = documentsManager.ingest([fetched as unknown]);
|
||||
doc = (canonical[0] as DocumentLike | undefined) || null;
|
||||
doc = (canonical[0] as Document | undefined) || null;
|
||||
if (!doc) {
|
||||
throw new Error('Document metadata unavailable.');
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { TAG_FILTER_UNTAGGED } from './workspaceUtils';
|
||||
import { listDocuments } from '../lib/apiClient';
|
||||
import type { Identifier } from '../types/identifiers';
|
||||
|
||||
type DocumentLike = { id?: Identifier } & Record<string, unknown>;
|
||||
import type { Document } from '../types/documents';
|
||||
|
||||
type ApiClient = {
|
||||
get: <T = unknown>(url: string, config?: { params?: Record<string, unknown> }) => Promise<{ data: T }>;
|
||||
@@ -23,7 +23,7 @@ interface UseDocumentsSearchArgs {
|
||||
notifyApiError: (error: unknown, message: string) => void;
|
||||
setSearchIncludeDescendants: (value: boolean) => void;
|
||||
documentsManager: {
|
||||
ingest: (docs: unknown[]) => { canonical: DocumentLike[]; changed: boolean };
|
||||
ingest: (docs: unknown[]) => { canonical: Document[]; changed: boolean };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user