ContextStores
Provides a wrapper for functions used to manage Stores in given Context.
Constructors
constructor
constructor(_endpoint: Endpoint,_eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
_endpoint | Endpoint | |
_eventDispatcher | EventDispatcher |
Methods
deleteFile
Deletes file from Store.
async deleteFile(fileId: string)
Name | Type | Description |
---|---|---|
fileId | string | ID of the file to delete |
Type | Description |
---|---|
Promise<void> | promise that resolves when the file is successfully deleted |
downloadFile
Downloads file from Store to your local environment. On platforms that supports FileAPI 'showFilePicker' method it will fetch file in chunks. Otherwise, File will be downloaded to memory first.
async downloadFile(file: {
fileId: string;
fileName: string;
progressCallback: (progress: number)=>void;
})
Name | Type | Description |
---|---|---|
file.fileId | string | file ID |
file.fileName | string | optional name that will be given to the file |
file.progressCallback | (progress: number)=>void | optional callback function to report progress |
Type | Description |
---|---|
Promise<void> | a promise that resolves with void and downloads the file to the browser environment |
getFileContents
Gets the content of given file. File is fetched in chunks and stored in memory.
async getFileContents(fileId: string, progressCallback: (progress: number)=>void)
Name | Type | Description |
---|---|---|
fileId | string | ID of the file to get the content from |
progressCallback | (progress: number)=>void | optional callback function called after fetching each file chunk |
Type | Description |
---|---|
Promise<Uint8Array> | content of the file |
getFileMetadata
Returns metadata about given file.
async getFileMetadata(fileId: string)
Name | Type | Description |
---|---|---|
fileId | string | ID of the file to get metadata from |
Type | Description |
---|---|
Promise<PrivmxFile> | `Promise<PrivmxFile> |
list
Lists Stores the user has access to.
async list(query: {
contextId: string;
options: ListOptions;
pageIndex: number;
})
Name | Type | Description |
---|---|---|
query.contextId | string | indicates from which Context should Stores be fetched |
query.options | ListOptions | optional options object |
query.pageIndex | number | indicates from which page the list should start |
Type | Description |
---|---|
Promise<PagingList<Store>> | - |
new
Creates a Store inside Context
async new(info: {
contextId: string;
managers: UserWithPubKey[];
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
})
Name | Type | Description |
---|---|---|
info.contextId | string | |
info.managers | UserWithPubKey[] | list of UserWithPubKey with management rights to the Store |
info.privateMeta | Uint8Array | optional (encrypted) metadata |
info.publicMeta | Uint8Array | optional public (unencrypted) metadata |
info.users | UserWithPubKey[] | list of UserWithPubKey with access to this Store |
Type | Description |
---|---|
Promise<string> | ID of the created Store |
on
Registers an event listener for Store-related events.
on(eventType: T, callback: (payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>void)
Name | Type | Description |
---|---|---|
eventType | T | type of event to listen for |
callback | (payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>void | callback function to execute when the event occurs |
Type | Description |
---|---|
SubscribeForChannel<"store"> & {
removeEventListener: ()=>void;
} | object containing the |
overrideFile
Overrides file contents.
async overrideFile(params: {
file: StoreFilePayload;
fileId: string;
progressCallback: (progress: number)=>void;
})
Name | Type | Description |
---|---|---|
params.file | StoreFilePayload | `StoreFilePayload` object |
params.fileId | string | ID of file to override |
params.progressCallback | (progress: number)=>void | optional callback function called after sending each file chunk |
Type | Description |
---|---|
Promise<string> | file ID |
streamRead
async streamRead(fileId: string)
Name | Type | Description |
---|---|---|
fileId | string | ID of the file to read |
Type | Description |
---|---|
Promise<StreamReader> | returns an instance of |
subscribeToStores
Subscribes to events related to Stores: - `storeCreated` - `storeDeleted` - `storeStatsChanged` - `storeUpdated`
async subscribeToStores()
Type | Description |
---|---|
Promise<SubscribeForChannel<"store">> | <'store'> `Promise<SubscribeForChannel<'store'>> |
unsubscribeFromStoreEvents
Unsubscribes and removes all registered callbacks for events related to Stores.
async unsubscribeFromStoreEvents()
Type | Description |
---|---|
Promise<void> | - a promise that resolves with void |
updateFile
Updates file contents.
async updateFile(params: {
data: Uint8Array;
fileId: string;
offset: number;
progressCallback: (progress: number)=>void;
})
Name | Type | Description |
---|---|---|
params.data | Uint8Array | New content of the file |
params.fileId | string | `fileId` |
params.offset | number | where to start appending data |
params.progressCallback | (progress: number)=>void | optional callback function to report progress |
Type | Description |
---|---|
Promise<string> | ID of the updated file |
updateFileMetaData
Updates file metadata.
async updateFileMetaData(file: {
fileId: string;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
})
Name | Type | Description |
---|---|---|
file.fileId | string | ID of file to update |
file.privateMeta | Uint8Array | metadata that will be encrypted |
file.publicMeta | Uint8Array | metadata that will not be encrypted |
Type | Description |
---|---|
Promise<void> | - a promise that resolves with void |