All files / src/lib/uploads types.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 0/0
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171              62x     62x                                                                                                                                                                                                                                                                                                                                
import type {
  InitiateMultipartUploadResponse as GeneratedInitiateMultipartUploadResponse,
  MultipartStatusResponse as GeneratedMultipartStatusResponse,
  UploadedPart as GeneratedUploadedPart,
} from "@/api/apiStore.gen";
 
/** Version tag for the persisted upload-resume payload stored in localStorage. */
export const RESUMABLE_UPLOAD_STORAGE_VERSION = 1;
 
/** The only CSV delimiters accepted by both frontend pre-scan and backend validation. */
export const SUPPORTED_CSV_DELIMITERS = [",", ";"] as const;
 
export type CsvDelimiter = (typeof SUPPORTED_CSV_DELIMITERS)[number];
 
/** Backend-recognized upload purposes for object-storage-backed CSV workflows. */
export type UploadPurpose =
  | "ml_training_csv"
  | "scenario_csv"
  | "pinch_utility_csv";
 
export type MultipartUploadSessionStatus =
  | "initiated"
  | "uploading"
  | "completed"
  | "aborted"
  | "failed"
  | "expired";
 
export type MultipartUploadStatus =
  | "idle"
  | "resume_available"
  | "uploading"
  | "uploaded"
  | "failed"
  | "aborted";
 
export type PersistedUploadPhase = "in_progress" | "uploaded";
 
export type UploadFileFingerprint = {
  name: string;
  size: number;
  lastModified: number;
  type: string;
};
 
export type MultipartUploadContext = {
  purpose: UploadPurpose;
  flowsheet_id: number;
  scenario_id?: number;
  simulationObject_id?: number;
};
 
export type MultipartInitiateRequest = MultipartUploadContext & {
  original_filename: string;
  content_type: string;
  size_bytes: number;
};
 
export type MultipartInitiateResponse = Omit<
  GeneratedInitiateMultipartUploadResponse,
  "upload_session_id"
> & {
  upload_session_id: string;
};
 
export type MultipartPartUrlsResponse = {
  urls: Record<number, string>;
};
 
export type UploadedMultipartPart = GeneratedUploadedPart;
 
export type MultipartStatusResponse = Omit<
  GeneratedMultipartStatusResponse,
  "status" | "uploaded_parts"
> & {
  status: MultipartUploadSessionStatus;
  uploaded_parts: UploadedMultipartPart[];
};
 
export type MultipartCompleteRequest = {
  upload_session_id: string;
  parts: Array<Pick<UploadedMultipartPart, "part_number" | "etag">>;
};
 
export type MultipartCompleteResponse = {
  bucket: string;
  object_key: string;
  size_bytes: number;
  etag?: string;
};
 
export type CsvInspectResponse = {
  headers: string[];
  detected_delimiter: CsvDelimiter;
  preview_rows?: Record<string, string>[];
  warnings?: string[];
};
 
export type MultipartUploadResumeState = MultipartUploadContext & {
  version: typeof RESUMABLE_UPLOAD_STORAGE_VERSION;
  upload_session_id: string;
  upload_phase: PersistedUploadPhase;
  file: UploadFileFingerprint;
  original_filename: string;
  content_type: string;
};
 
export type LocalCsvHeaderScanResult = {
  headers: string[];
  guessedDelimiter: CsvDelimiter | null;
  warnings: string[];
};
 
export type LocalCsvHeaderScanOptions = {
  bytesToRead?: number;
  warnOnNonNumericColumns?: boolean;
};
 
export type PlannedUploadPart = {
  partNumber: number;
  startByte: number;
  endByteExclusive: number;
  sizeBytes: number;
};
 
export type CompletedMultipartUpload = MultipartCompleteResponse & {
  upload_session_id: string;
  original_filename: string;
};
 
export type MultipartUploadProgress = {
  uploadedBytes: number;
  totalBytes: number;
  uploadedParts: number;
  totalParts: number;
  percentage: number;
};
 
export type ResumableMultipartUploadState = {
  status: MultipartUploadStatus;
  error: string | null;
  uploadSessionId: string | null;
  fileName: string | null;
  progress: MultipartUploadProgress;
  resumeState: MultipartUploadResumeState | null;
};
 
export type MultipartUploadApi = {
  initiateMultipartUpload: (
    request: MultipartInitiateRequest,
    signal?: AbortSignal,
  ) => Promise<MultipartInitiateResponse>;
  getMultipartPartUrls: (
    uploadSessionId: string,
    partNumbers: number[],
    signal?: AbortSignal,
  ) => Promise<MultipartPartUrlsResponse>;
  getMultipartUploadStatus: (
    uploadSessionId: string,
    signal?: AbortSignal,
  ) => Promise<MultipartStatusResponse>;
  completeMultipartUpload: (
    request: MultipartCompleteRequest,
    signal?: AbortSignal,
  ) => Promise<MultipartCompleteResponse>;
  abortMultipartUpload: (
    uploadSessionId: string,
    signal?: AbortSignal,
  ) => Promise<void>;
};