diff --git a/src/schemas/core/index.ts b/src/schemas/core/index.ts index 6438621..ee5ad72 100644 --- a/src/schemas/core/index.ts +++ b/src/schemas/core/index.ts @@ -8,3 +8,4 @@ export * from './link.schema'; export * from './file.schema'; export * from './polygonParts.schema'; export * from './tile.schema'; +export * from './storage.schema'; diff --git a/src/schemas/core/storage.schema.ts b/src/schemas/core/storage.schema.ts new file mode 100644 index 0000000..d56f4c3 --- /dev/null +++ b/src/schemas/core/storage.schema.ts @@ -0,0 +1,13 @@ +import { z } from 'zod'; +import { SourceType } from '../../constants/core/constants'; + +export const fsStorageSchema = z.object({ + storageProvider: z.literal(SourceType.FS), +}); + +export const s3StorageSchema = z.object({ + storageProvider: z.literal(SourceType.S3), + bucket: z.string().min(1), +}); + +export const storageSchema = z.discriminatedUnion('storageProvider', [fsStorageSchema, s3StorageSchema]); diff --git a/src/schemas/deletion/task.schema.ts b/src/schemas/deletion/task.schema.ts index b5371fb..27c89dc 100644 --- a/src/schemas/deletion/task.schema.ts +++ b/src/schemas/deletion/task.schema.ts @@ -1,7 +1,5 @@ import { z } from 'zod'; -import { SourceType } from '../../constants/core/constants'; - -export const sourceProviderSchema = z.union([z.literal(SourceType.S3), z.literal(SourceType.FS)]); +import { storageSchema } from '../core'; export const deleteTaskParamsSchema = z .object({ @@ -12,19 +10,10 @@ export const deleteTaskParamsSchema = z }) .describe('deleteTaskParamsSchema'); -export const deletionParamsBaseSchema = z.object({ - sourceProvider: sourceProviderSchema, - bucket: z.string().optional(), +export const deleteStoredResourcesParamsBaseSchema = z.object({ + paths: z.array(z.string().min(1)).min(1), }); -export const layerTilesDeletionParamsSchema = deletionParamsBaseSchema - .extend({ - catalogId: z.string().uuid(), - }) - .describe('layerTilesDeletionParamsSchema'); - -export const artifactsDeletionParamsSchema = deletionParamsBaseSchema - .extend({ - paths: z.array(z.string().min(1)).min(1), // explicit thumbnail/legend object keys (s3) or file paths (fs) - }) - .describe('artifactsDeletionParamsSchema'); +export const deleteStoredResourcesParamsSchema = deleteStoredResourcesParamsBaseSchema + .and(storageSchema) + .describe('deleteStoredResourcesParamsSchema'); diff --git a/src/types/core/index.ts b/src/types/core/index.ts index b27df06..53328de 100644 --- a/src/types/core/index.ts +++ b/src/types/core/index.ts @@ -8,3 +8,4 @@ export * from './file.type'; export * from './callback.type'; export * from './polygonParts.type'; export * from './tile.type'; +export * from './storage.type'; diff --git a/src/types/core/storage.type.ts b/src/types/core/storage.type.ts new file mode 100644 index 0000000..ebb6bb6 --- /dev/null +++ b/src/types/core/storage.type.ts @@ -0,0 +1,6 @@ +import type { z } from 'zod'; +import type { fsStorageSchema, s3StorageSchema, storageSchema } from '../../schemas'; + +export type FsStorage = z.infer; +export type S3Storage = z.infer; +export type Storage = z.infer; diff --git a/src/types/deletion/task.type.ts b/src/types/deletion/task.type.ts index afe8c6e..0a1e256 100644 --- a/src/types/deletion/task.type.ts +++ b/src/types/deletion/task.type.ts @@ -1,6 +1,5 @@ import z from 'zod'; -import { deleteTaskParamsSchema, layerTilesDeletionParamsSchema, artifactsDeletionParamsSchema } from '../../schemas/deletion/task.schema'; +import { deleteTaskParamsSchema, deleteStoredResourcesParamsSchema } from '../../schemas/deletion/task.schema'; export type DeleteTaskParams = z.infer; -export type LayerTilesDeletionParams = z.infer; -export type ArtifactsDeletionParams = z.infer; +export type DeleteStoredResourcesParams = z.infer;