@microsoft/msgraph-sdk-core
Version:
Core functionalities for the Microsoft Graph JavaScript SDK
149 lines • 6.09 kB
TypeScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @module LargeFileUploadTask
**/
import { Parsable, RequestAdapter, ParsableFactory, ParseNode, ErrorMappings } from "@microsoft/kiota-abstractions";
import { SeekableStreamReader } from "./SeekableStreamReader.js";
/**
* @interface
* Signature to represent progress receiver
* @property {number} progress - The progress value (This is the last uploaded byte)
*/
export interface IProgress {
report(progress: number): void;
}
/**
* @interface
* Signature to represent an upload session, i.e the response returned by the server after for a pending upload
*
* @property {Date} expirationDateTime - The expiration time of the session
* @property {string[]} nextExpectedRanges - The next expected ranges
* @property {string} odataType - The type of the object
* @property {string} uploadUrl - The URL to which the file upload needs to be done
*/
export interface UploadSession {
expirationDateTime?: Date | null;
nextExpectedRanges?: string[] | null;
odataType?: string | null;
uploadUrl?: string | null;
}
/**
* @interface
* Signature to represent the result of an upload
*/
export interface UploadResult<T> {
itemResponse?: T | null;
location?: string;
}
/**
* UploadSession ParsableFactory
* Creates a factory function to deserialize the upload session response.
*
* @param {ParseNode} _parseNode - The parse node to deserialize.
* @returns {Function} - A function that takes an instance of Parsable and returns a record of deserialization functions.
*/
export declare const createUploadSessionFromDiscriminatorValue: (_parseNode: ParseNode | undefined) => ((instance?: Parsable) => Record<string, (node: ParseNode) => void>);
/**
* Deserializes the upload session response body.
*
* @param {Partial<UploadSession>} [uploadSession] - The upload session object to deserialize into.
* @returns {Record<string, (node: ParseNode) => void>} - A record of deserialization functions.
*/
export declare const deserializeIntoUploadSession: (uploadSession?: Partial<UploadSession> | undefined) => Record<string, (node: ParseNode) => void>;
/**
* A class representing LargeFileUploadTask
*/
export declare class LargeFileUploadTask<T extends Parsable> {
private readonly requestAdapter;
private readonly maxSliceSize;
private readonly parsableFactory;
/**
* @private
* The ranges to upload
*/
rangesRemaining: number[][];
/**
* @private
* The error mappings
*/
errorMappings: ErrorMappings;
/**
* @private
* The seekable stream reader
*/
seekableStreamReader: SeekableStreamReader;
/**
* @private
* The upload session
*/
Session: UploadSession;
/**
* Constructs a new instance of the LargeFileUploadTask class.
*
* @param {RequestAdapter} requestAdapter - The request adapter to use for making HTTP requests.
* @param {Parsable} uploadSession - The upload session information.
* @param {ReadableStream<Uint8Array>} uploadStream - Returns an instance of an unconsumed new stream to be uploaded.
* @param {number} [maxSliceSize=-1] - The maximum size of each file slice to be uploaded.
* @param {ParsableFactory<T>} parsableFactory - The factory to create parsable objects.
* @param {ErrorMappings} [errorMappings] - error mappings.
*
* @throws {Error} If any of the required parameters are undefined or invalid.
*/
constructor(requestAdapter: RequestAdapter, uploadSession: Parsable, uploadStream: ReadableStream<Uint8Array>, maxSliceSize: number | undefined, parsableFactory: ParsableFactory<T>, errorMappings: ErrorMappings);
/**
* Uploads the file in a sequential order by slicing the file in terms of ranges.
*
* @param {IProgress} [progress] - Optional progress receiver to report upload progress.
* @returns {Promise<UploadResult<T>>} - The result of the upload.
* @throws {Error} If the upload fails.
*/
upload(progress?: IProgress): Promise<UploadResult<T>>;
/**
* @public
* Resumes the current upload session
* @param progress
*/
resume(progress?: IProgress): Promise<UploadResult<T>>;
/**
* Refreshes the current upload session status by making a GET request to the upload URL.
* Updates the session expiration date, next expected ranges, and remaining ranges based on the response.
*
* @returns {Promise<UploadSession | undefined>} - A promise that resolves to the updated upload session.
* @throws {Error} If the request fails.
*/
updateSession(): Promise<UploadSession | undefined>;
/**
* Deletes the current upload session.
* Sends a PUT request to the upload URL to cancel the session.
*
* @returns {Promise<void>} A promise that resolves when the session is canceled.
*/
deleteSession(): Promise<void>;
/**
* Extracts the upload session information from a parsable object.
*
* @param {Parsable} parsable - The parsable object containing the upload session information.
* @returns {UploadSession} - The extracted upload session information.
*/
private extractSessionInfo;
/**
* Calculates the size of the next slice to be uploaded.
*
* @param {number} currentRangeBegin - The beginning of the current range.
* @param {number} currentRangeEnd - The end of the current range.
* @returns {number} - The size of the next slice.
*/
private nextSliceSize;
/**
* @private
* Parses the upload session response and returns a nested number array of ranges pending upload
* @param uploadSession
*/
private getRangesRemaining;
}
//# sourceMappingURL=LargeFileUploadTask.d.ts.map