Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ console.log(playerUrl);
#### Delete the video

```ts
// Delete the video from the collection
await video.delete();
// Delete the video from the collection (pass true to confirm)
await video.delete(true);
```

### 🌟 More on `Collection` object
Expand All @@ -460,7 +460,8 @@ const myVideo = coll.getVideo(id);
#### Delete a video

```ts
await coll.deleteVideo();
// Delete a video from the collection (pass true to confirm)
await coll.deleteVideo('VIDEO_ID', true);
```

---
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/core_audio.Audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Initializes a VideoDB Instance

### delete

▸ **delete**(): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **delete**(force: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

Returns an empty promise that resolves when the audio is deleted

Expand Down
21 changes: 12 additions & 9 deletions docs/classes/core_collection.Collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ The base class through which all videodb actions are possible

## Methods

### deleteAudio
### deleteAudio(audioId, force)

▸ **deleteAudio**(`audioId`): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **deleteAudio**(`audioId`: string, `force`: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `audioId` | `string` |
| `force` | `boolean` | Must be true to confirm deletion. |

#### Returns

Expand All @@ -94,23 +95,24 @@ A promise that resolves when delete is successful

**`Throws`**

an error if the request fails
Error if force is false, VideodbError or InvalidRequestError if request fails

#### Defined in

[src/core/collection.ts:130](https://github.com/omgate234/videodb-node/blob/047cbbf/src/core/collection.ts#L130)

___

### deleteImage
### deleteImage(imageId, force)

▸ **deleteImage**(`imageId`): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **deleteImage**(`imageId`: string, `force`: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `imageId` | `string` |
| `force` | `boolean` | Must be true to confirm deletion. |

#### Returns

Expand All @@ -120,23 +122,24 @@ A promise that resolves when delete is successful

**`Throws`**

an error if the request fails
Error if force is false, VideodbError or InvalidRequestError if request fails

#### Defined in

[src/core/collection.ts:177](https://github.com/omgate234/videodb-node/blob/047cbbf/src/core/collection.ts#L177)

___

### deleteVideo
### deleteVideo(videoId, force)

▸ **deleteVideo**(`videoId`): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **deleteVideo**(`videoId`: string, `force`: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `videoId` | `string` | Id of the video to be deleted |
| `force` | `boolean` | Must be true to confirm deletion. |

#### Returns

Expand All @@ -146,7 +149,7 @@ A promise that resolves when delete is successful

**`Throws`**

an error if the request fails
Error if force is false, VideodbError or InvalidRequestError if request fails

#### Implementation of

Expand Down
6 changes: 3 additions & 3 deletions docs/classes/core_image.Image.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ Initializes a VideoDB Instance

## Methods

### delete
### delete(force)

▸ **delete**(): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **delete**(force: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

Returns an empty promise that resolves when the image is deleted
Deletes the image with confirmation when force is true.

#### Returns

Expand Down
6 changes: 3 additions & 3 deletions docs/classes/core_video.Video.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ an awaited stream url for subtitled overlayed video

___

### delete
### delete(force)

▸ **delete**(): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>
▸ **delete**(force: boolean): `Promise`\<[`ResponseOf`](../modules/types_response.md#responseof)\<`Record`\<`string`, `never`\>\>\>

Returns an empty promise that resolves when the video is deleted
Deletes the video with confirmation when force is true.

#### Returns

Expand Down
22 changes: 13 additions & 9 deletions src/core/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ export class Audio implements IAudio {
this.meta = data;
this.#vhttp = http;
}

/**
* Returns an empty promise that resolves when the audio is deleted
* @returns A promise that resolves when delete is successful
* @throws an InvalidRequestError if the request fails
* Deletes the audio with confirmation.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false, InvalidRequestError if request fails.
*/
public delete = async () => {
return await this.#vhttp.delete<Record<string, never>>([
audio,
this.meta.id,
]);
public delete = async (force: boolean) => {
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[audio, this.meta.id],
{ data: { force } }
);
};
}
59 changes: 43 additions & 16 deletions src/core/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,23 @@ export class Collection implements ICollection {
};

/**
*
* @param videoId - Id of the video to be deleted
* @returns A promise that resolves when delete is successful
* @throws an error if the request fails
* Deletes a video from the collection with confirmation.
* @param videoId - Id of the video to be deleted.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false, VideodbError or InvalidRequestError if request fails.
*/
public deleteVideo = async (videoId: string) => {
public deleteVideo = async (videoId: string, force: boolean) => {
if (!videoId.trim()) {
throw new VideodbError('Video ID cannot be empty');
}
return await this.#vhttp.delete<Record<string, never>>([video, videoId], {
params: { collection_id: this.meta.id },
});
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[video, videoId],
{ params: { collection_id: this.meta.id }, data: { force } }
);
};

/** * Get all audios from the collection
Expand Down Expand Up @@ -127,13 +132,24 @@ export class Collection implements ICollection {
* @returns A promise that resolves when delete is successful
* @throws an error if the request fails
*/
public deleteAudio = async (audioId: string) => {
/**
* Deletes an audio from the collection with confirmation.
* @param audioId - Id of the audio to be deleted.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false, VideodbError or InvalidRequestError if request fails.
*/
public deleteAudio = async (audioId: string, force: boolean) => {
if (!audioId.trim()) {
throw new VideodbError('Audio ID cannot be empty');
}
return await this.#vhttp.delete<Record<string, never>>([audio, audioId], {
params: { collection_id: this.meta.id },
});
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[audio, audioId],
{ params: { collection_id: this.meta.id }, data: { force } }
);
};

/** * Get all images from the collection
Expand Down Expand Up @@ -174,13 +190,24 @@ export class Collection implements ICollection {
* @returns A promise that resolves when delete is successful
* @throws an error if the request fails
*/
public deleteImage = async (imageId: string) => {
/**
* Deletes an image from the collection with confirmation.
* @param imageId - Id of the image to be deleted.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false, VideodbError or InvalidRequestError if request fails.
*/
public deleteImage = async (imageId: string, force: boolean) => {
if (!imageId.trim()) {
throw new VideodbError('Image ID cannot be empty');
}
return await this.#vhttp.delete<Record<string, never>>([image, imageId], {
params: { collection_id: this.meta.id },
});
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[image, imageId],
{ params: { collection_id: this.meta.id }, data: { force } }
);
};

/**
Expand Down
20 changes: 12 additions & 8 deletions src/core/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ export class Image implements IImage {
}

/**
* Returns an empty promise that resolves when the image is deleted
* @returns A promise that resolves when delete is successful
* @throws an InvalidRequestError if the request fails
* Deletes the image with confirmation.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false and InvalidRequestError if request fails.
*/
public delete = async () => {
return await this.#vhttp.delete<Record<string, never>>([
ApiPath.image,
this.meta.id,
]);
public delete = async (force: boolean) => {
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[ApiPath.image, this.meta.id],
{ data: { force } }
);
};
}

Expand Down
19 changes: 14 additions & 5 deletions src/core/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,20 @@ export class Video implements IVideo {
* @returns A promise that resolves when delete is successful
* @throws an InvalidRequestError if the request fails
*/
public delete = async () => {
return await this.#vhttp.delete<Record<string, never>>([
video,
this.meta.id,
]);
/**
* Deletes the video with confirmation.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
* @throws Error if force is false and InvalidRequestError if request fails.
*/
public delete = async (force: boolean) => {
if (!force) {
throw new Error("Parameter 'force' must be true to confirm deletion.");
}
return await this.#vhttp.delete<Record<string, never>>(
[video, this.meta.id],
{ data: { force } }
);
};

/**
Expand Down
17 changes: 16 additions & 1 deletion src/interfaces/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ export interface ICollection {
meta: CollectionBase;
getVideos: () => Promise<Video[]>;
getVideo: (videoId: string) => Promise<Video>;
deleteVideo: (videoId: string) => Promise<object>;
/**
* Deletes a video from the collection with confirmation.
* @param videoId - Id of the video to be deleted.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
*/
deleteVideo: (videoId: string, force: boolean) => Promise<object>;
uploadFile: (data: FileUploadConfig) => Promise<void | UploadJob>;
uploadURL: (data: URLUploadConfig) => Promise<void | UploadJob>;
/**
* Searches within a collection.
*/
search: (query: string, searchType?: SearchType) => Promise<SearchResult>;
}

Expand Down Expand Up @@ -76,6 +85,12 @@ export interface AudioBase {
*/
export interface IAudio {
meta: AudioBase;
/**
* Deletes the audio with confirmation.
* @param force - Must be true to confirm deletion.
* @returns A promise that resolves when deletion is successful.
*/
delete(force: boolean): Promise<Record<string, never>>;
}

/**
Expand Down