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,87 @@ +// @flow + +import t, { type TInterface, type TUnion } from 'tcomb'; + +import { tShape } from '../utils/validation-utils.js'; + +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 AssignMultipleHoldersRequest = { + +requests: $ReadOnlyArray, +}; +export const assignMultipleHoldersRequestValidator: TInterface = + tShape({ + requests: t.list(blobInfoValidator), + }); + +export type AssignMultipleHoldersResponse = { + +results: $ReadOnlyArray, +}; +export const assignMultipleHoldersResponseValidator: TInterface = + tShape({ + results: t.list(holderAssignmentResultValidator), + }); + +export type RemoveMultipleHolderItemsRequest = { + +requests: $ReadOnlyArray, + // Whether to instantly delete blob after last holder is removed, without + // waiting for cleanup. Defaults to `false` if not provided. + +instantDelete?: boolean, +}; +export const removeMultipleHolderItemsRequestValidator: TInterface = + tShape({ + requests: t.list(blobInfoValidator), + }); + +export type RemoveMultipleHoldersByTagRequest = { + +tags: $ReadOnlyArray, +}; +export const removeMultipleHoldersByTagRequestValidator: TInterface = + tShape({ + tags: t.list(t.String), + }); + +export type RemoveMultipleHoldersRequest = + | RemoveMultipleHolderItemsRequest + | RemoveMultipleHoldersByTagRequest; +export const removeMultipleHoldersRequestValidator: TUnion = + t.union([ + removeMultipleHolderItemsRequestValidator, + removeMultipleHoldersByTagRequestValidator, + ]); + +export type RemoveMultipleHoldersResponse = { + // Holder removal requests that failed server-side are returned here. + // This can be passed into retry request body. + +failedRequests: $ReadOnlyArray, +}; +export const removeMultipleHoldersResponseValidator: TInterface = + tShape({ + failedRequests: t.list(blobInfoValidator), + });