diff --git a/lib/facts/blob-service.js b/lib/facts/blob-service.js --- a/lib/facts/blob-service.js +++ b/lib/facts/blob-service.js @@ -35,6 +35,10 @@ path: '/blob', method: 'DELETE', }, + REMOVE_MULTIPLE_HOLDERS: { + path: '/holders', + method: 'DELETE', + }, }); const config: BlobServiceConfig = { diff --git a/lib/types/blob-service-types.js b/lib/types/blob-service-types.js new file mode 100644 --- /dev/null +++ b/lib/types/blob-service-types.js @@ -0,0 +1,78 @@ +// @flow + +import t, { type TInterface } from 'tcomb'; + +import { tShape } from '../utils/validation-utils.js'; + +/* + * This file defines types and validation for HTTP requests and responses + * for the Blob Service. The definitions in this file should remain in sync + * with the structures defined in the `http` submodule of the corresponding + * Rust file at `shared/comm-lib/src/blob/types.rs`. + * + * If you edit the definitions in one file, + * please make sure to update the corresponding definitions in the other. + */ + +export type BlobInfo = { + +blobHash: string, + +holder: string, +}; +export const blobInfoValidator: TInterface = tShape({ + blobHash: t.String, + holder: t.String, +}); + +export type HolderAssignmentResult = $ReadOnly<{ + ...BlobInfo, + // `true` if adding this holder was successful. + // Also true when `holderAlreadyExists` is true. + +success: boolean, + // `true` when given holder already existed + +holderAlreadyExists: boolean, + // `true` if blob hash has been uploaded before. + +dataExists: boolean, +}>; +export const holderAssignmentResultValidator: TInterface = + tShape({ + blobHash: t.String, + holder: t.String, + success: t.Boolean, + holderAlreadyExists: t.Boolean, + dataExists: t.Boolean, + }); + +export type AssignHoldersRequest = { + +requests: $ReadOnlyArray, +}; + +export type AssignHoldersResponse = { + +results: $ReadOnlyArray, +}; +export const assignHoldersResponseValidator: TInterface = + tShape({ + results: t.list(holderAssignmentResultValidator), + }); + +type RemoveHolderItemsRequest = { + +requests: $ReadOnlyArray, + // Whether to instantly delete blob after last holder is removed, without + // waiting for cleanup. Defaults to `false` if not provided. + +instantDelete?: boolean, +}; +type RemoveHoldersByTagRequest = { + +tags: $ReadOnlyArray, +}; +export type RemoveHoldersRequest = + | RemoveHolderItemsRequest + | RemoveHoldersByTagRequest; + +export type RemoveHoldersResponse = { + // Holder removal requests that failed server-side are returned here. + // This can be passed into retry request body. + +failedRequests: $ReadOnlyArray, +}; +export const removeHoldersResponseValidator: TInterface = + tShape({ + failedRequests: t.list(blobInfoValidator), + }); diff --git a/shared/comm-lib/src/blob/types.rs b/shared/comm-lib/src/blob/types.rs --- a/shared/comm-lib/src/blob/types.rs +++ b/shared/comm-lib/src/blob/types.rs @@ -3,6 +3,13 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; +/// This module defines structures for HTTP requests and responses +/// for the Blob Service. The definitions in this file should remain in sync +/// with the types and validators defined in the corresponding +/// JavaScript file at `lib/types/blob-service-types.js`. +/// +/// If you edit the definitions in one file, +/// please make sure to update the corresponding definitions in the other. pub mod http { use serde::{Deserialize, Serialize};