/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ /** * Upload Executor * * Handles batch execution of pending file uploads at form submission time. * This enables "deferred uploads" — files are selected/previewed immediately * but only uploaded when the user clicks Save. */ import type { Field, StoredFileValue } from '@byline/core'; import type { UploadFieldFn } from '../fields/field-services-types.js'; import type { PendingUpload } from './form-context.js'; export interface UploadResult { fieldPath: string; success: boolean; storedFile?: StoredFileValue; error?: string; } export interface ExecuteUploadsResult { /** All upload results (both successful and failed) */ results: UploadResult[]; /** Map of field path to StoredFileValue for successful uploads */ successful: Map; /** Map of field path to error message for failed uploads */ errors: Map; /** Whether all uploads succeeded */ allSucceeded: boolean; } /** * Optional document context threaded from the form renderer so upload * requests carry the state that server-side `beforeStore` / `afterStore` * hooks need (see `UploadConfig.context` in `@byline/core`). */ export interface UploadExecutionContext { /** * The persisted document id (edit mode). Posted as `documentId` on every * upload request; omitted while the document is unsaved (create mode). */ documentId?: string; /** * The collection's schema fields — used to locate each upload field's * `upload.context` declaration by walking the pending upload's field path. */ fields?: readonly Field[]; /** * Snapshot accessor for the live form values, resolved lazily per upload * so context reflects the state at the moment the request is built. */ getFormValues?: () => Record; } /** * Execute all pending uploads sequentially. * Returns a result object with successful uploads and any errors. * * @param pendingUploads - Map of field path to PendingUpload * @param uploadField - Host-provided upload transport (resolved via * `useBylineFieldServices()` in the calling React tree) * @param executionContext - Optional document/form context appended to each * upload request (documentId, `upload.context` values) * @returns Promise resolving to ExecuteUploadsResult */ export declare function executeUploads(pendingUploads: Map, uploadField: UploadFieldFn, executionContext?: UploadExecutionContext): Promise; /** * Progress callback type for upload execution with progress tracking. */ export type UploadProgressCallback = (info: { current: number; total: number; fieldPath: string; status: 'uploading' | 'done' | 'error'; }) => void; /** * Execute uploads with progress callbacks. * Useful for showing upload progress in the UI. */ export declare function executeUploadsWithProgress(pendingUploads: Map, uploadField: UploadFieldFn, onProgress?: UploadProgressCallback, executionContext?: UploadExecutionContext): Promise;