Skip to main content
reference

ContextStores

Provides a wrapper for functions used to manage Stores in given Context.

Constructors

constructor

constructor(_endpoint: Endpoint,_eventDispatcher: EventDispatcher)

NameTypeDescription
_endpointEndpoint
_eventDispatcherEventDispatcher

Methods

deleteFile

Deletes file from Store.

async deleteFile(fileId: string)

NameTypeDescription
fileIdstringID of the file to delete

TypeDescription
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;
})

NameTypeDescription
file.fileIdstringfile ID
file.fileNamestringoptional name that will be given to the file
file.progressCallback(progress: number)=>voidoptional callback function to report progress

TypeDescription
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)

NameTypeDescription
fileIdstringID of the file to get the content from
progressCallback(progress: number)=>voidoptional callback function called after fetching each file chunk

TypeDescription
Promise<Uint8Array> content of the file

getFileMetadata

Returns metadata about given file.

async getFileMetadata(fileId: string)

NameTypeDescription
fileIdstringID of the file to get metadata from

TypeDescription
Promise<PrivmxFile> `Promise<PrivmxFile>

list

Lists Stores the user has access to.

async list(query: {
contextId: string;
options: ListOptions;
pageIndex: number;
})

NameTypeDescription
query.contextIdstringindicates from which Context should Stores be fetched
query.optionsListOptionsoptional options object
query.pageIndexnumberindicates from which page the list should start

TypeDescription
Promise<PagingList<Store>> -

new

Creates a Store inside Context

async new(info: {
contextId: string;
managers: UserWithPubKey[];
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
})

NameTypeDescription
info.contextIdstring
info.managersUserWithPubKey[]list of UserWithPubKey with management rights to the Store
info.privateMetaUint8Arrayoptional (encrypted) metadata
info.publicMetaUint8Arrayoptional public (unencrypted) metadata
info.usersUserWithPubKey[]list of UserWithPubKey with access to this Store

TypeDescription
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)

NameTypeDescription
eventTypeTtype of event to listen for
callback(payload: Extract<StoreCreatedEvent, {type: T;}> | Extract<StoreUpdatedEvent, {type: T;}> | Extract<StoreDeletedEvent, {type: T;}> | Extract<StoreStatsChangedEvent, {type: T;}>)=>voidcallback function to execute when the event occurs

TypeDescription
SubscribeForChannel<"store"> & { removeEventListener: ()=>void; } object containing the

overrideFile

Overrides file contents.

async overrideFile(params: {
file: StoreFilePayload;
fileId: string;
progressCallback: (progress: number)=>void;
})

NameTypeDescription
params.fileStoreFilePayload`StoreFilePayload` object
params.fileIdstringID of file to override
params.progressCallback(progress: number)=>voidoptional callback function called after sending each file chunk

TypeDescription
Promise<string> file ID

streamRead

async streamRead(fileId: string)

NameTypeDescription
fileIdstringID of the file to read

TypeDescription
Promise<StreamReader> returns an instance of

subscribeToStores

Subscribes to events related to Stores: - `storeCreated` - `storeDeleted` - `storeStatsChanged` - `storeUpdated`

async subscribeToStores()

TypeDescription
Promise<SubscribeForChannel<"store">> <'store'> `Promise<SubscribeForChannel<'store'>>

unsubscribeFromStoreEvents

Unsubscribes and removes all registered callbacks for events related to Stores.

async unsubscribeFromStoreEvents()

TypeDescription
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;
})

NameTypeDescription
params.dataUint8ArrayNew content of the file
params.fileIdstring`fileId`
params.offsetnumberwhere to start appending data
params.progressCallback(progress: number)=>voidoptional callback function to report progress

TypeDescription
Promise<string> ID of the updated file

updateFileMetaData

Updates file metadata.

async updateFileMetaData(file: {
fileId: string;
privateMeta: Uint8Array;
publicMeta: Uint8Array;
})

NameTypeDescription
file.fileIdstringID of file to update
file.privateMetaUint8Arraymetadata that will be encrypted
file.publicMetaUint8Arraymetadata that will not be encrypted

TypeDescription
Promise<void> - a promise that resolves with void