@simplito/privmx-webendpoint
Version:
PrivMX Web Endpoint library
180 lines (177 loc) • 7.95 kB
TypeScript
/*!
PrivMX Web Endpoint.
Copyright © 2024 Simplito sp. z o.o.
This file is part of the PrivMX Platform (https://privmx.dev).
This software is Licensed under the PrivMX Free License.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { BaseApi } from "./BaseApi";
import { StoreApiNative } from "../api/StoreApiNative";
import { PagingQuery, PagingList, UserWithPubKey, Store, File, ContainerPolicy, StoreEventSelectorType, StoreEventType } from "../Types";
export declare class StoreApi extends BaseApi {
private native;
constructor(native: StoreApiNative, ptr: number);
/**
* Creates a new Store in given Context.
*
* @param {string} contextId ID of the Context to create the Store in
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the
* created Store
* @param {Uint8Array} publicMeta public (unencrypted) metadata
* @param {Uint8Array} privateMeta private (encrypted) metadata
* @param {ContainerPolicy} policies Store's policies
* @returns {string} created Store ID
*/
createStore(contextId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, policies?: ContainerPolicy): Promise<string>;
/**
* Updates an existing Store.
*
* @param {string} storeId ID of the Store to update
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Store
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the
* created Store
* @param {Uint8Array} publicMeta public (unencrypted) metadata
* @param {Uint8Array} privateMeta private (encrypted) metadata
* @param {number} version current version of the updated Store
* @param {boolean} force force update (without checking version)
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Store
* @param {ContainerPolicy} policies Store's policies
*/
updateStore(storeId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, version: number, force: boolean, forceGenerateNewKey: boolean, policies?: ContainerPolicy): Promise<void>;
/**
* Deletes a Store by given Store ID.
*
* @param {string} storeId ID of the Store to delete
*/
deleteStore(storeId: string): Promise<void>;
/**
* Gets a single Store by given Store ID.
*
* @param {string} storeId ID of the Store to get
* @returns {Store} containing information about the Store
*/
getStore(storeId: string): Promise<Store>;
/**
* Gets a list of Stores in given Context.
*
* @param {string} contextId ID of the Context to get the Stores from
* @param {PagingQuery} pagingQuery with list query parameters
* @returns {PagingList<Store>} containing list of Stores
*/
listStores(contextId: string, pagingQuery: PagingQuery): Promise<PagingList<Store>>;
/**
* Creates a new file in a Store.
*
* @param {string} storeId ID of the Store to create the file in
* @param {Uint8Array} publicMeta public file metadata
* @param {Uint8Array} privateMeta private file metadata
* @param {number} size size of the file
* @param {boolean} [randomWriteSupport] enable random write support for file
* @returns {number} handle to write data
*/
createFile(storeId: string, publicMeta: Uint8Array, privateMeta: Uint8Array, size: number, randomWriteSupport?: boolean): Promise<number>;
/**
* Update an existing file in a Store.
*
* @param {string} fileId ID of the file to update
* @param {Uint8Array} publicMeta public file metadata
* @param {Uint8Array} privateMeta private file metadata
* @param {number} size size of the file
* @returns {number} handle to write file data
*/
updateFile(fileId: string, publicMeta: Uint8Array, privateMeta: Uint8Array, size: number): Promise<number>;
/**
* Update metadata of an existing file in a Store.
*
* @param {string} fileId ID of the file to update
* @param {Uint8Array} publicMeta public file metadata
* @param {Uint8Array} privateMeta private file metadata
*/
updateFileMeta(fileId: string, publicMeta: Uint8Array, privateMeta: Uint8Array): Promise<void>;
/**
* Writes a file data.
*
* @param {number} fileHandle handle to write file data
* @param {Uint8Array} dataChunk file data chunk
* @param {boolean} [truncate] truncate the file from: current pos + dataChunk size
*/
writeToFile(fileHandle: number, dataChunk: Uint8Array, truncate?: boolean): Promise<void>;
/**
* Deletes a file by given ID.
*
* @param {string} fileId ID of the file to delete
*/
deleteFile(fileId: string): Promise<void>;
/**
* Gets a single file by the given file ID.
*
* @param {string} fileId ID of the file to get
* @returns {File} containing information about the file
*/
getFile(fileId: string): Promise<File>;
/**
* Gets a list of files in given Store.
*
* @param {string} storeId ID of the Store to get files from
* @param {PagingQuery} pagingQuery with list query parameters
* @returns {PagingList<File>} containing list of files
*/
listFiles(storeId: string, pagingQuery: PagingQuery): Promise<PagingList<File>>;
/**
* Opens a file to read.
*
* @param {string} fileId ID of the file to read
* @returns {number} handle to read file data
*/
openFile(fileId: string): Promise<number>;
/**
* Reads file data.
* Single read call moves the files's cursor position by declared length or set it at the end of the file.
*
* @param {string} fileHandle handle to write file data
* @param {number} length size of data to read
* @returns {Uint8Array} array buffer with file data chunk
*/
readFromFile(fileHandle: number, length: number): Promise<Uint8Array>;
/**
* Moves read cursor.
*
* @param {string} fileHandle handle to write file data
* @param {number} position new cursor position
*/
seekInFile(fileHandle: number, position: number): Promise<void>;
/**
* Closes the file handle.
*
* @param {string} fileHandle handle to read/write file data
* @returns {string} ID of closed file
*/
closeFile(fileHandle: number): Promise<string>;
/**
* Synchronize file handle data with newest data on server
*
* @param {number} fileHandle handle to read/write file data
*/
syncFile(fileHandle: number): Promise<void>;
/**
* Subscribe for the Store events on the given subscription query.
*
* @param {string[]} subscriptionQueries list of queries
* @return list of subscriptionIds in maching order to subscriptionQueries
*/
subscribeFor(subscriptionQueries: string[]): Promise<string[]>;
/**
* Unsubscribe from events for the given subscriptionId.
* @param {string[]} subscriptionIds list of subscriptionId
*/
unsubscribeFrom(subscriptionIds: string[]): Promise<void>;
/**
* Generate subscription Query for the Store events.
* @param {EventType} eventType type of event which you listen for
* @param {EventSelectorType} selectorType scope on which you listen for events
* @param {string} selectorId ID of the selector
*/
buildSubscriptionQuery(eventType: StoreEventType, selectorType: StoreEventSelectorType, selectorId: string): Promise<string>;
}