@adobe/cc-ext-uxp-types
Version:
Typescript definitions for the Adobe UXP JS API
1,026 lines (1,024 loc) • 465 kB
TypeScript
/*
* Copyright 2023 Adobe Systems Incorporated. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the Licrrense for the specific language
* governing permissions and limitations under the License.
*
*/
// Type definitions for Unified Extensibility Platform (UXP) 7.3
// Project: https://adobe.io/photoshop/uxp/2022/uxp-api/
// Definitions by: Adobe UXP <https://github.com/adobe-uxp>
// Apoorva Sharma <https://github.com/Apoorva2405>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'uxp' {
namespace storage {
/**
* Common locations that we can use when displaying a file picker.
*/
namespace domains {
/**
* The user's desktop folder
*/
var userDesktop: symbol;
/**
* The user's documents folder
*/
var userDocuments: symbol;
/**
* The user's pictures folder or library
*/
var userPictures: symbol;
/**
* The user's videos / movies folder or library
*/
var userVideos: symbol;
/**
* The user's music folder or library
*/
var userMusic: symbol;
/**
* Local application data
*/
var appLocalData: symbol;
/**
* Local application library
*/
var appLocalLibrary: symbol;
/**
* Local application cache directory (persistence not guaranteed)
*/
var appLocalCache: symbol;
/**
* Local application shared data folder
*/
var appLocalShared: symbol;
/**
* Local temporary directory
*/
var appLocalTemporary: symbol;
/**
* Roaming application data
*/
var appRoamingData: symbol;
/**
* Roaming application library data
*/
var appRoamingLibrary: symbol;
}
/**
* This namespace describes the various file type extensions that can used be used in some FS file open methods.
*/
namespace fileTypes {
/**
* Text file extensions
*/
var text: string[];
/**
* Image file extensions
*/
var images: string[];
/**
* All file types
*/
var all: string[];
}
/**
* This namespace describes the file content formats supported in FS methods like read and write.
*/
namespace formats {
/**
* UTF8 File encoding
*/
var utf8: symbol;
/**
* Binary file encoding
*/
var binary: symbol;
}
/**
* This namespace describes the file open modes. for eg: open file in read-only or both read-write
*/
namespace modes {
/**
* The file is read-only; attempts to write will fail.
*/
var readOnly: symbol;
/**
* The file is read-write.
*/
var readWrite: symbol;
}
/**
* This namespace describes the type of the entry. Whether file or folder etc.
*/
namespace types {
/**
* A file; used when creating an entity
*/
var file: symbol;
/**
* A folder; used when creating an entity
*/
var folder: symbol;
}
/**
* An `Entry` is the base class for `File` and `Folder`.
* You can get an instance of Entry via the `localFileSystem` by fetching an instance of a File or Folder
*
* <b>Example</b>
* ```js
* // Since Entry cannot be called directly we can use a File or Folder object to invoke Entry as shown below
* const fs = require('uxp').storage.localFileSystem;
* const folder = await fs.getPluginFolder(); // returns a Folder instance
* const folderEntry = await folder.getEntry("entryName.txt");
*
* // Now we can use folderEntry to invoke the APIs provided by Entry
* console.log(folderEntry.isEntry); // isEntry is an API of Entry, in this example it will return true
* ```
*/
class Entry {
/**
* Indicates that this instance is an `Entry`. Useful for type-checking.
* @example
* if (something.isEntry) {
* return something.getMetadata();
* }
*/
isEntry: boolean;
/**
* Indicates that this instance is **not** a `File`. Useful for type-
* checking.
* @example
* if (!anEntry.isFile) {
* return "This entry is not a file.";
* }
*/
readonly isFile: boolean;
/**
* Indicates that this instance is **not** a folder. Useful for type-
* checking.
* @example
* if (!anEntry.isFolder) {
* return "This entry is not a folder.";
* }
*/
readonly isFolder: boolean;
/**
* The name of this entry. Read-only.
* @example
* console.log(anEntry.name);
*/
readonly name: string;
/**
* The associated provider that services this entry. Read-only.
* @example
* if (entryOne.provider !== entryTwo.provider) {
* throw new Error("Providers are not the same");
* }
*/
readonly provider: FileSystemProvider;
/**
* The url of this entry. You can use this url as input to other entities of the extension system like for eg: set as src attribute of a Image widget in UI. Read-only.
* @example
* console.log(anEntry.url);
*/
readonly url: string;
/**
* Returns the details of the given entry like name, type and native path in a readable string format.
*/
toString(): string;
/**
* The platform native file-system path of this entry. Read-only
* @example
* console.log(anEntry.nativePath);
*/
readonly nativePath: string;
/**
* Copies this entry to the specified `folder`.
* @example
* await someFile.copyTo(someFolder);
* @example
* await someFile.copyTo(someFolder, {overwrite: true});
* @example
* await someFolder.copyTo(anotherFolder, {overwrite: true, allowFolderCopy: true});
* @param folder - the folder to which to copy this entry
* @param [options.overwrite = false] - if `true`, allows overwriting existing entries
* @param [options.allowFolderCopy = false] - if `true`, allows copying the folder
* @returns `Promise<File | Folder>`
*/
copyTo(folder: Folder, options: {
overwrite?: boolean;
allowFolderCopy?: boolean;
}): any;
/**
* Moves this entry to the target folder, optionally specifying a new name.
* @example
* await someFile.moveTo(someFolder);
* @example
* await someFile.moveTo(someFolder, {overwrite: true});
* @example
* await someFolder.moveTo(anotherFolder, {overwrite: true});
* @example
* await someFile.moveTo(someFolder, {newName: 'masterpiece.txt'})
* @example
* await someFile.moveTo(someFolder, {newName: 'novel.txt', {overwrite: true})
* @param folder - the folder to which to move this entry
* @param [options.overwrite = false] - If `true` allows the move to overwrite existing files
* @param [options.newName] - If specified, the entry is renamed to this name
* @returns `Promise<void>`
*/
moveTo(folder: Folder, options: {
overwrite?: boolean;
newName?: string;
}): any;
/**
* Removes this entry from the file system. If the entry is a folder, it must be empty before deletion.
* Note: Currently when using this method, a permission denied error will occur if attempting to delete
* a folder that was selected from a storage picker or added via drag-and-drop.
* @example
* await aFile.delete();
* @returns `Promise<number>` - the number is 0 if succeeded, otherwise throws an Error
*/
delete(): any;
/**
* Returns this entry's metadata.
* @example
* const metadata = aFile.getMetadata();
* @returns `Promise<EntryMetadata>`
*/
getMetadata(): any;
}
/**
* Metadata for an `Entry`. It includes useful information such as:
*
* * size of the file (if a file)
* * date created
* * date modified
* * name
*
* Instantiate `EntryMetadata` by using {@link Entry.md#getmetadata|Entry's - getMetadata()}.
* In order to instantiate `Entry`, you will need to first invoke the `localFileSystem` and then fetch an instance of a File or Folder.
*
* <b>Example</b>
* ```js
* const fs = require('uxp').storage.localFileSystem;
* const folder = await fs.getPluginFolder(); // Gets an instance of Folder (or Entry)
* const entryMetaData = await folder.getMetadata();
* console.log(entryMetaData.name);
* ```
*/
class EntryMetadata {
/**
* The name of the entry.
*/
name: string;
/**
* The size of the entry, if a file. Zero if a folder.
*/
size: number;
/**
* The date this entry was created.
*/
dateCreated: Date;
/**
* The date this entry was modified.
*/
dateModified: Date;
/**
* Indicates if the entry is a file
*/
isFile: boolean;
/**
* Indicates if the entry is a folder
*/
isFolder: boolean;
}
/**
* Represents a file on a file system. Provides methods for reading from and
* writing to the file. You'll never instantiate a `File` directly; instead
* you'll get access via a [storage.FileSystemProvider]{@link ./FileSystemProvider}.
* Keep in mind that `File` as such doesn't need a `require()` statement, however a `localFileSystem` will need it.
*
* <b>Example</b>
* ```js
* // Get the object of a File instance
* const fs = require('uxp').storage.localFileSystem;
* const file = await fs.createEntryWithUrl("file:/Users/user/Documents/tmp"); // Gets a File instance
* console.log(file.isFile); // returns true
* ```
*/
class File {
/**
* Indicates that this instance is a file.
* @example
* if (anEntry.isFile) {
* await anEntry.read();
* }
*/
isFile: any;
/**
* Indicates whether this file is read-only or read-write. See [readOnly]{@link ./modes#readonly--symbol} and [readWrite]{@link ./modes#readwrite--symbol}.
* @example
* if (aFile.mode === modes.readOnly) {
* throw new Error("Can't write to a file opened as read-only.");
* }
*/
mode: symbol;
/**
* Reads data from the file and returns it. The file format can be specified
* with the `format` option. If a format is not supplied, the file is assumed
* to be a text file using UTF8 encoding.
* @example
* const text = await myNovel.read();
* @example
* const data = await myNovel.read({format: formats.binary});
* @param [options.format = formats.utf8] - The format of the file; see [utf8]{@link ./formats#utf8--symbol} and [binary]{@link ./formats#binary--symbol}.
* @returns `Promise<string|ArrayBuffer>` the contents of the file
*/
read(options: {
format?: symbol;
}): any;
/**
* Writes data to a file, appending if desired. The format of the file
* is controlled via the `format` option, and defaults to UTF8.
* @example
* await myNovel.write("It was a dark and stormy night.\n");
* await myNovel.write("Cliches and tropes aside, it really was.", {append: true});
* @example
* const data = new ArrayBuffer();
* await aDataFile.write(data, {format: formats.binary});
* @param data - the data to write to the file
* @param [options.format = formats.utf8] - the format of the file; see [utf8]{@link ./formats#utf8--symbol} and [binary]{@link ./formats#binary--symbol}.
* @param [options.append = false] - if `true`, the data is written to the end of the file
* @returns `Promise<number>` - the length of the contents written to the file
*/
write(data: string | ArrayBuffer, options: {
format?: symbol;
append?: boolean;
}): any;
/**
* Determines if the entry is a file or not. This is safe to use even if the
* entry is `null` or `undefined`.
* @param entry - the entry to check
* @returns if `true`, the entry is a file.
*/
static isFile(entry: any): boolean;
}
/**
* Provides access to files and folders on a file system. You'll typically not
* instantiate this directly; instead you'll use an instance of one that has
* already been created for you by UXP.
* @example
* const fs = uxp.fs.localFileSystem;
*/
class FileSystemProvider {
/**
* Indicates that this is a `FileSystemProvider`. Useful for type-checking.
*/
isFileSystemProvider: boolean;
/**
* An array of the domains this file system supports. If the file system can
* open a file picker to the user's `documents` folder, for example, then [userDocuments]{@link ./domains#module-storage-domains-userdocuments} will be in this list.
* @example
* if (fs.supportedDomains.contains(domains.userDocuments)) {
* console.log("We can open a picker to the user's documents.")
* }
*/
supportedDomains: symbol[];
/**
* Gets a file (or files) from the file system provider for the purpose of
* opening them. Files are read-only.
*
* Multiple files can be returned if the `allowMultiple` option` is `true`.
* @example
* const folder = await fs.getFolder({initialDomain: domains.userDocuments});
* const file = await fs.getFileForOpening({initialLocation: folder});
* if (!file) {
* // no file selected
* return;
* }
* const text = await file.read();
* @example
* const files = await fs.getFileForOpening({allowMultiple: true, types: fileTypes.images});
* if (files.length === 0) {
* // no files selected
* }
* @param [options.initialDomain] - the preferred initial location of the file picker. If not defined, the most recently used domain from a file picker is used instead.
* @param [options.types = [".*"]] - array of file types that the file open picker displays.
* @param [options.initialLocation] - the initial location of the file picker.
* You can pass an existing file or folder entry to suggest the picker to start at this location.
* If this is a file entry then the method will pick its parent folder as initial location. This will override initialDomain option.
* @param [options.allowMultiple = false] - if true, multiple files can be selected
* @returns `Promise<File|Array<File>>` based on `allowMultiple`. Return empty if no file was selected.
*/
getFileForOpening(options: {
initialDomain?: symbol;
types?: string[];
initialLocation?: File | Folder;
allowMultiple?: boolean;
}): any;
/**
* Gets a file reference suitable for read-write. Displays a file picker to select a location to "Save" the file.
*
* If the act of writing to the file would overwrite it, the file picker
* will prompt the user to confirm before returning a result to you.
* @example
* const file = await fs.getFileForSaving("output.txt", { types: [ "txt" ]});
* if (!file) {
* // file picker was cancelled
* return;
* }
* await file.write("It was a dark and stormy night");
* @param suggestedName - Required when `options.types` is not defined.
* @param [options.initialDomain] - The preferred initial location of the file picker. If not defined, the most recently used domain from a file picker is used instead.
* @param [options.types] - Allowed file extensions, with no "." prefix.
* @returns `Promise<File>` - returns the selected file, or `null` if no file were selected.
*/
getFileForSaving(suggestedName: string, options: {
initialDomain?: symbol;
types?: string[];
}): any;
/**
* Gets a folder from the file system via a folder picker dialog. The files
* and folders within can be accessed via [Folder#getEntries]{@link ./Folder#getentries}. Any
* files within are read-write.
*
* If the user dismisses the picker, `null` is returned instead.
* @example
* const folder = await fs.getFolder();
* const myNovel = (await fs.getEntries()).filter(entry => entry.name.indexOf('novel') > 0);
* const text = await myNovel.read();
* @param [options.initialDomain] - the preferred initial location of the file picker. If not defined, the most recently used domain from a file picker is used instead.
* @returns `Promise<Folder | null>` - the selected folder or `null` if no folder is selected.
*/
getFolder(options: {
initialDomain?: symbol;
}): any;
/**
* Returns a temporary folder. The contents of the folder will be removed when
* the extension is disposed.
* @example
* const temp = await fs.getTemporaryFolder();
* @returns `Promise<Folder>`
*/
getTemporaryFolder(): any;
/**
* Returns a folder that can be used for extension's data storage without user interaction.
* It is persistent across host-app version upgrades.
* @returns `Promise<Folder>`
*/
getDataFolder(): any;
/**
* Returns an plugin's folder – this folder and everything within it are read only.
* This contains all the Plugin related packaged assets.
* @returns `Promise<Folder>`
*/
getPluginFolder(): any;
/**
* Creates an entry for the given url and returns the appropriate instance.
* @example
* const newImgFolder = await fs.createEntryWithUrl("plugin-temp:/img", { type: types.folder });
* const newTmpFolder = await fs.createEntryWithUrl("file:/Users/user/Documents/tmp", { type: types.folder });
* @example
* const newDatFile = await fs.createEntryWithUrl("plugin-temp:/tmp/test.dat", { overwrite: true });
* const newTxtFile = await fs.createEntryWithUrl("file:/Users/user/Documents/test.txt", { overwrite: true });
* @param url - the url to create an Entry object.
* Note that file: scheme has limited support in UWP due to the strict [File access permissions]{@link https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions}
* @param [options.type = types.file] - indicates which kind of entry to create. Pass types.folder to create a new folder.
* Note that if the type is file then this method just create"s" a file entry object and not the actual file on the disk.
* File on the storage is created when data is written into the file. eg: call write method on the file entry object.
* @param [options.overwrite = false] - if true, the create attempt can overwrite an existing file
* @returns `Promise<File|Folder>` the File or Folder object which is created for the given url
*/
public createEntryWithUrl(url: string, options: {
type?: symbol;
overwrite?: boolean;
}): any;
/**
* Gets an entry of the given url and returns the appropriate instance.
* @example
* const tmpFolder = await fs.getEntryWithUrl("plugin-temp:/tmp");
* const docFolder = await fs.getEntryWithUrl("file:/Users/user/Documents");
* @example
* const tmpFile = await fs.getEntryWithUrl("plugin-temp:/tmp/test.dat");
* const docFile = await fs.getEntryWithUrl("file:/Users/user/Documents/test.txt");
* @param url - the url to get an Entry object
* Note that file: scheme has limited support in UWP due to the strict [File access permissions]{@link https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions}
* @returns `Promise<File|Folder>` the File or Folder object for the given url
*/
public getEntryWithUrl(url: string): any;
/**
* Returns the fs url of given entry.
* @returns `string`
*/
public getFsUrl(entry: Entry): any;
/**
* Returns the platform native file system path of given entry.
* @returns `string`
*/
public getNativePath(entry: Entry): any;
/**
* Returns a token suitable for use with certain host-specific APIs (such as Photoshop). This token is valid only for the current plugin session. As such, it is of no use if you serialize the token to persistent storage, as the token will be invalid in the future.
*
* Note: When using the Photoshop DOM API, pass the instance of the file instead of a session token -- Photoshop will convert the entry into a session token automatically on your behalf.
* @example
* const fs = require('uxp').storage.localFileSystem;
* let entry = await fs.getFileForOpening();
* let token = fs.createSessionToken(entry);
* let result = await require('photoshop').action.batchPlay([{
* _obj: "open",
* "target": {
* _path: token, // Rather than a system path, this expects a session token
* _kind: "local",
* }
* }], {});
* @returns the session token for the given entry
*/
createSessionToken(entry: Entry): string;
/**
* Returns the file system Entry that corresponds to the session token obtained from `createSessionToken`. If an entry cannot be found that matches the token, then a `Reference Error: token is not defined` error is thrown.
* @returns the corresponding entry for the session token
*/
getEntryForSessionToken(token: string): Entry;
/**
* Returns a token suitable for use with host-specific APIs (such as Photoshop), or for storing a persistent reference to an entry (useful if you want to only ask for permission to access a file or folder once). A persistent token is not guaranteed to last forever -- certain scenarios can cause the token to longer work (including moving files, changing permissions, or OS-specific limitations). If a persistent token cannot be reused, you'll get an error at the time of use.
* @example
* const fs = require('uxp').storage.localFileSystem;
* let entry = await fs.getFileForOpening();
* let token = await fs.createPersistentToken(entry);
* localStorage.setItem("persistent-file", token);
* @returns `Promise<string>` - the persistent token for the given entry
*/
createPersistentToken(entry: Entry): any;
/**
* Returns the file system Entry that corresponds to the persistent token obtained from `createPersistentToken`. If an entry cannot be found that matches the token, then a `Reference Error: token is not defined` error is thrown.
*
* Note: retrieving an entry for a persistent token does _not_ guarantee that the entry is valid for use. You'll need to properly handle the case where the entry no longer exists on the disk, or the permissions have changed by catching the appropriate errors. If that occurs, the suggested practice is to prompt the user for the entry again and store the new token.
* @example
* const fs = require('uxp').storage.localFileSystem;
* let entry, contents, tries = 3, success = false;
* while (tries > 0) {
* try {
* entry = await fs.getEntryForPersistentToken(localStorage.getItem("persistent-file"));
* contents = await entry.read();
* tries = 0;
* success = true;
* } catch (err) {
* entry = await fs.getFileForOpening();
* localStorage.setItem("persistent-token", await fs.createPersistentToken(entry));
* tries--;
* }
* }
* if (!success) {
* // fail gracefully somehow
* }
* @returns `Promise<Entry>` - the corresponding entry for the persistent token
*/
getEntryForPersistentToken(token: string): any;
/**
* Checks if the supplied object is a `FileSystemProvider`. It's safe to use even
* if the object is `null` or `undefined`. Useful for type checking.
* @param fs - the object to check
* @returns If `true`, the object is a file system provider
*/
static isFileSystemProvider(fs: any): boolean;
}
/**
* Represents a folder on a file system. You'll never instantiate this directly,
* but will get it by calling [FileSystemProvider.getTemporaryFolder]{@link ./storage#gettemporaryfolder},
* [FileSystemProvider.getFolder]{@link ./storage#getfolderoptions}, or via [Folder.getEntries]{@link ./Folder#getentries}.
*
* <b>Example</b>
* ```js
* // Get the Folder instance via localFileSystem
* const fs = require('uxp').storage.localFileSystem;
* const folder = await fs.getTemporaryFolder(); // Gets the Folder instance
* console.log(folder.isFolder); // returns true
* ```
*/
class Folder extends Entry {
/**
* Indicates that this instance is a folder. Useful for type checking.
*/
isFolder: any;
/**
* Returns an array of entries contained within this folder.
* @example
* const entries = await aFolder.getEntries();
* const allFiles = entries.filter(entry => entry.isFile);
* @returns `Promise<Array<Entry>>` - The entries within the folder.
*/
getEntries(): any;
/**
* Creates an entry within this folder and returns the appropriate instance.
* @example
* const myNovel = await aFolder.createEntry("mynovel.txt");
* @example
* const catImageCollection = await aFolder.createEntry("cats", {type: types.folder});
* @param name - the name of the entry to create
* @param [options.type = types.file] - Indicates which kind of entry to create. Pass `Folder` to create a new folder.
* Note that if the type is file then this method just create a file entry object and not the actual file on the disk.
* The file actually gets created when you call for eg: write method on the file entry object.
* @param [options.overwrite = false] - If `true`, the create attempt can overwrite an existing file
* @returns `Promise<File | Folder>` the created entry
*/
createEntry(name: string, options: {
type?: symbol;
overwrite?: boolean;
}): any;
/**
* Creates a File Entry object within this folder and returns the appropriate instance.
* Note that this method just create a file entry object and not the actual file on the disk.
* The file actually gets created when you call for eg: write method on the file entry object.
* @example
* const myNovelTxtFile = await aFolder.createFile("mynovel.txt");
* @param name - the name of the file to create.
* @param [options.overwrite = false] - If `true`, the create attempt can overwrite an existing file
* @returns `Promise<File>` - the created file entry
*/
createFile(name: string, options: {
overwrite?: boolean;
}): any;
/**
* Creates a Folder within this folder and returns the appropriate instance.
* @example
* const myCollectionsFolder = await aFolder.createFolder("collections");
* @param name - the name of the folder to create.
* @returns `Promise<Folder>` - the created folder entry object
*/
createFolder(name: string): any;
/**
* Gets an entry from within this folder and returns the appropriate instance.
* @example
* const myNovel = await aFolder.getEntry("mynovel.txt");
* @param filePath - the name/path of the entry to fetch
* @returns `Promise<File | Folder>` the fetched entry.
*/
getEntry(filePath: string): any;
/**
* Renames an entry to a new name.
* @example
* await myNovels.rename(myNovel, "myFantasticNovel.txt");
* @param entry - the entry to rename
* @param newName - the new name to assign
* @param [options.overwrite = false] - if `true`, renaming can overwrite an existing entry
* @returns `Promise<void>`
*/
renameEntry(entry: Entry, newName: string, options: {
overwrite?: boolean;
}): any;
/**
* Checks if an entry is a folder. Safe to use if entry might be `null` or
* `undefined`. Useful for type checking.
*/
static isFolder: boolean;
}
}
}
/**
* Provides a local key-value store useful for setting preferences and other kinds of data.
* This data is technically persistent, but can be cleared in a variety of ways,
* so you should not store data using localStorage that you cannot otherwise reconstruct.
* <InlineAlert variant="warning" slots="text"/>
*
* Do not store passwords or other secure forms of data using `localStorage`. Instead, use [storage.secureStorage]{@link /uxp-api/reference-js/Modules/uxp/Key-Value%20Storage/SecureStorage/}
*/
declare class LocalStorage {
/**
* Number of items stored in the local storage.
*/
readonly length: number;
/**
* Returns the name of the nth key in the local storage.
* @param index - Integer representing the number of the key
* @returns Name of the key. If the index does not exist, null is returned.
*/
key(index: number): string;
/**
* Gets the value for the key from the local storage.
* Returns null if the key does not exist.
* @param key - Key to retrieve the value of.
* @returns Value corresponding to the key as string. If the key does not exist, null is returned.
*/
getItem(key: string): string;
/**
* Adds key and value to the local storage.
* Updates the value if the given key already exists.
* @param key - Key to set value
* @param value - Value for the key
*/
setItem(key: string, value: string): void;
/**
* Removes a key/value pair from the local storage if it exists.
* Nothing happens if there's no item associated with the given key.
* @param key - Key to remove
*/
removeItem(key: string): void;
/**
* Remove all key/value pairs from the local storage.
*/
clear(): void;
}
declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
/**
* SessionStorage is available as `window.sessionStorage`
* Provides a local key/value store useful for storing data that persists only for the plugin's current session.
* For more information about the API itself, see the [localStorage]{@link ./LocalStorage} API
*/
declare class SessionStorage {
}
/**
* Creates a new CountQueuingStrategy object with the provided high water mark.
* @param init - Object with high water mark property.
* @param init.highWaterMark - The total number of chunks that can be contained in the internal queue before backpressure is applied.
*/
declare class CountQueuingStrategy {
constructor(init: {
highWaterMark: number;
});
/**
* The high water mark.
*/
highWaterMark: number;
/**
* The size of chunk, always 1.
*/
size(): void;
}
declare class ReadableStreamDefaultController {
/**
* Returns the desired size to fill the controlled stream’s internal queue.
* It can be negative, if the queue is over-full.
*/
desiredSize: number;
/**
* Closes the controlled readable stream.
* Consumers will still be able to read any previously-enqueued chunks from the stream,
* but once those are read, the stream will become closed.
*/
close(): void;
/**
* Enqueues the given chunk in the controlled readable stream.
*/
enqueue(chunk: any): void;
/**
* Errors the controlled readable stream, making all future interactions with it fail with the given error.
*/
error(error: any): void;
}
/**
* Create a new ReadableStreamDefaultReader object and locks the stream to the new reader.
*/
declare class ReadableStreamDefaultReader {
constructor(stream: ReadableStream);
/**
* Returns a promise that will be fulfilled when the stream becomes closed,
* or rejected if the stream ever errors or the reader’s lock is released before the stream finishes closing.
*/
closed: any;
/**
* Cancels the stream, signaling a loss of interest in the stream by a consumer.
* The supplied reason argument will be given to the underlying source’s cancel() method.
* The returned promise will fulfill if the stream shuts down successfully,
* or reject if the underlying source signaled that there was an error doing so.
* It will reject with a TypeError (without attempting to cancel the stream) if the stream is currently locked.
* @returns `Promise<string>`
*/
cancel(reason: string): any;
/**
* Returns a promise that allows access to the next chunk from the stream’s internal queue, if available.
* @returns <br></br> If a chunk is available, the promise will be fulfilled with an object of the form
* { value: theChunk, done: false }.
* <br></br> If the stream becomes closed, the promise will be fulfilled with an object of the form
* { value: undefined, done: true }.
* <br></br> If the stream becomes errored, the promise will be rejected with the relevant error.
*/
read(): Promise<object>;
/**
* Releases the reader’s lock on the corresponding stream.
* After the lock is released, the reader is no longer active.
* If the associated stream is errored when the lock is released,
* the reader will appear errored in the same way from now on; otherwise, the reader will appear closed.
* If the reader’s lock is released while it still has pending read requests,
* then the promises returned by the reader’s read() method are immediately rejected with a TypeError.
* Any unread chunks remain in the stream’s internal queue and can be read later by acquiring a new reader.
*/
releaseLock(): void;
}
/**
* Creates a ReadableStream object from the given handlers.
* <br></br>Note that `underlyingSource.type` and `underlyingSource.autoAllocateChunkSize` are not supported.
* @param underlyingSource - Define how the constructed stream instance will behave.
* @param underlyingSource.start(controller) - Called immediately when the object is constructed.
* This method needs to do anything else required to set up the stream functionality.
* If this process is to be done asynchronously, it can return a promise to signal success or failure.
* The controller parameter passed to this method is a ReadableStreamDefaultController.
* @param underlyingSource.pull(controller) - Called repeatedly when the stream's internal queue of chunks is not full,
* up until it reaches its high water mark.
* If pull() returns a promise, then it won't be called again until that promise fulfills.
* If the promise rejects, the stream will become errored.
* The controller parameter passed to this method is a ReadableStreamDefaultController.
* @param underlyingSource.cancel(reason) - Called if the app signals that the stream is to be cancelled.
* The contents should do whatever is necessary to release access to the stream source.
* If this process is asynchronous, it can return a promise to signal success or failure.
* The reason parameter contains a string describing why the stream was cancelled.
* @param strategy - Defines a queuing strategy for the stream.
* @param strategy.highWaterMark - Defines the total number of chunks that can be contained in the internal queue
* before backpressure is applied.
* @param strategy.size(chunk) - Indicates the size to use for each chunk, in bytes.
*/
declare class ReadableStream {
constructor(underlyingSource: {
start(controller: ReadableStreamDefaultController): (...params: any[]) => any;
pull(controller: ReadableStreamDefaultController): (...params: any[]) => any;
cancel(reason: string): (...params: any[]) => any;
}, strategy: {
highWaterMark: number;
size(chunk: number): (...params: any[]) => any;
});
/**
* Indicate whether the readable stream is locked.
*/
readonly locked: boolean;
/**
* Cancel the readable stream.
* @param reason - reason for the cancellation.
* @returns `Promise<void>`
*/
cancel(reason: string): any;
/**
* Create a reader and lock the stream to it.
* <br></br>Note that currently ReadableStreamDefaultReader object is returned as options.mode <b>"byob" is not supported.</b>
* @param options - Object with mode property.
* @param options.mode - ReadableStreamDefaultReader being created, defaults to `undefined` and `byob` is not yet supported.
*/
getReader(options: {
mode: any;
}): ReadableStreamDefaultReader;
/**
* Provides a chainable way of piping the current stream through a transform stream.
* @param transform - TransformStream or an object with the structure {writable, readable}
* @param options.preventClose - If true, the source ReadableStream closing will no loger cause the destination WritableStream
* to be closed.
* @param options.preventAbort - If true, errors in the source ReadableStream will no longer abort the destination WritableStream.
* @param options.preventCancel - If true, errors in the destination WritableStream will no longer cancel the source ReadableStream.
* @param options.signal - If aborted, ongoing pipe operations can be aborted.
* @returns ReadableStream of the input transform stream.
*/
pipeThrough(transform: TransformStream | WritableAndReadable, options: {
preventClose: boolean;
preventAbort: boolean;
preventCancel: boolean;
signal: AbortSignal;
}): ReadableStream;
/**
* Pipes this readable stream to a given writable stream destination.
* @param destination - Final destination for the ReadableStream.
* @param options - (Optional) Used when piping to the writable stream.
* @param options.preventClose - If true, the source ReadableStream closing will no loger cause the destination WritableStream to be closed.
* @param options.preventAbort - If true, errors in the source ReadableStream will no longer abort the destination WritableStream.
* @param options.preventCancel - If true, errors in the destination WritableStream will no longer cancel the source ReadableStream.
* @param options.signal - If aborted, ongoing pipe operations can be aborted.
* @returns `Promise<void>` resolves when the piping process has completed.
*/
pipeTo(destination: WritableStream, options: {
preventClose: boolean;
preventAbort: boolean;
preventCancel: boolean;
signal: AbortSignal;
}): any;
/**
* Tees the current ReadableStream, returning a two-element array
* containing the two resulting branches as new ReadableStream instances.
* @returns an array containing two ReadableStream instances.
*/
tee(): any[];
}
/**
* Object with the structure {writable, readable}
*/
declare type WritableAndReadable = any;
declare class TransformStreamDefaultController {
/**
* Returns the desired size to fill the readable side’s internal queue.
* It can be negative, if the queue is over-full.
*/
desiredSize: number;
/**
* Enqueues the given chunk chunk in the readable side of the controlled transform stream.
* @param chunk - The chunk being queued. A chunk is a single piece of data.
*/
enqueue(chunk: any): void;
/**
* Errors both the readable side and the writable side of the controlled transform stream,
* making all future interactions with it fail with the given error.
* Any chunks queued for transformation will be discarded.
*/
error(reason: string): void;
/**
* Closes the readable side and errors the writable side of the controlled transform stream.
* This is useful when the transformer only needs to consume a portion of the chunks written to the writable side.
*/
terminate(): void;
}
/**
* Cretes a new TransformStream object wrapping the provided transformer.
* If no transformer argument is supplied, then the result will be an identity transform stream.
* @param transformer - Defines algorithms for the specific transformation to be performed.
* @param transformer.start - Called when the TransfromStream is constructed.
* @param transformer.transform - Called when a chunk written to the writable is ready to be transformed.
* If no transform method is supplied, the identity transform is used.
* @param transformer.flush - Called after all chunks written to the writable have been successfully transformed,
* and the writable is about to be closed.
* @param writableStrategy - Queuing strategy for the stream.
* @param writableStrategy.highWaterMark - A non-negative number.
* The total number of chunks that can be contained in the internal queue before backpressure is applied
* @param writableStrategy.size - The size to use for each chunk, in bytes.
* @param readableStrategy - Queuing strategy for the stream.
* @param readableStrategy.highWaterMark - A non-negative number.
* The total number of chunks that can be contained in the internal queue before backpressure is applied
* @param readableStrategy.size - The size to use for each chunk, in bytes.
*/
declare class TransformStream {
constructor(transformer: {
start: (...params: any[]) => any;
transform: (...params: any[]) => any;
flush: (...params: any[]) => any;
}, writableStrategy: {
highWaterMark: number;
size: (...params: any[]) => any;
}, readableStrategy: {
highWaterMark: number;
size: (...params: any[]) => any;
});
/**
* ReadableStream representing the readable of this TransformStream.
*/
readable: ReadableStream;
/**
* WritableStream representing the writable of this TransformStream.
*/
writable: WritableStream;
}
declare class WritableStreamDefaultController {
/**
* Returns AbortSignal that can be used to abort the pending write or close operation when the stream is aborted.
*/
signal: AbortSignal;
/**
* Closes the controlled writable stream, making all future interactions with it fails with the given error.
*/
error(message: string): void;
}
/**
* Creates a new WritableStreamDefaultWriter object.
*/
declare class WritableStreamDefaultWriter {
constructor(stream: WritableStream);
/**
* Returns a Promise that fullfils if the stream becomes closed,
* or rejects if the stream errors or the writer's lock is released.
*/
closed: Promise<void>;
/**
* The desired size required to fill the stream's internal queue.
* It will return null if the stream cannot be successfully written to.
* It will return zero if the stream is closed.
*/
desiredSize: number;
/**
* Returns a Promise that resolves when the desired size of the stream's internal queue transitions
* from non-positive to positive, signaling that it is no longer applying backpressure.
* Once the desired size dips back to zero or below, the getter will return a new promise that stays pending until the next transition.
* If the stream becomes errored or aborted, or the writer’s lock is released, the returned promise will become rejected.
*/
ready: Promise<void>;
/**
* Aborts the stream, signaling that the producer can no longer successfully write to the stream
* and it is to be immediately moved to an errored state, with any queued-up writes discarded.
* The returned promise will fulfill if the stream shuts down successfully, or reject if the underlying sink signaled that there was an error doing so.
* It will reject with a TypeError if the stream is curretly locked.
* @returns `Promise<void>`
*/
abort(reason: string): any;
/**
* Closes the stream and returns a Promise that will fulfill if all remaining chunks are successfully written
* and the stream successfully closes, or rejects if an error is encountered during this process.
* It will reject with a TypeError (without attempting to cancel the stream) if the stream is currently locked.
* @returns `Promise<void>`
*/
close(): any;
/**
* Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
* If the associated stream is errored when the lock is released, the writer will appear errored in the same way from now on;
* otherwise, the writer will appear closed.
*/
releaseLock(): void;
/**
* Writes the given chunk to the writable stream and its underlying sink,
* then returns a Promise that reso