Skip to content

Commit

Permalink
feat(storage-client): add touch method
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammad Honarvar <[email protected]>
  • Loading branch information
alimd and mohammadhonarvar committed May 7, 2023
1 parent 9eff3fa commit 5a347b3
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions core/storage-client/src/storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
documentObject: T,
storage: string | undefined = this.config.name,
): Promise<T> {
this._logger.logMethodArgs?.('set', {documentId: documentObject.id});
this._logger.logMethodArgs?.('set', {storage, documentId: documentObject.id});
if (storage == null) throw new Error('storage_not_defined');

const responseJson = await serviceRequest<AlwatrServiceResponseSuccessWithMeta<T>>({
Expand All @@ -201,6 +201,29 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
return responseJson.data;
}

/**
* Touch the storage to make sure storage file exist.
*
* Example:
*
* ```ts
* await userStorage.touch();
* ```
*/
async touch(storage: string | undefined = this.config.name): Promise<void> {
this._logger.logMethodArgs?.('touch', {storage});
if (storage == null) throw new Error('storage_not_defined');

await serviceRequest({
...this.fetchOption,
method: 'GET',
url: this.fetchOption.url + 'touch',
queryParameters: {
storage,
},
});
}

/**
* Delete a document object from the storage.
*
Expand Down Expand Up @@ -236,7 +259,7 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
async getStorage<T extends DocumentType = DocumentType>(
name: string | undefined = this.config.name,
): Promise<AlwatrDocumentStorage<T>> {
this._logger.logMethod?.('getStorage');
this._logger.logMethodArgs?.('getStorage', {name});
if (name == null) throw new Error('storage_not_defined');

const responseJson = (await serviceRequest({
Expand Down Expand Up @@ -269,7 +292,7 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
* ```
*/
async keys(storage: string | undefined = this.config.name): Promise<Array<string>> {
this._logger.logMethod?.('keys');
this._logger.logMethodArgs?.('keys', {storage});
if (storage == null) throw new Error('storage_not_defined');

const responseJson = await serviceRequest({
Expand Down

0 comments on commit 5a347b3

Please sign in to comment.