diff --git a/src/schemas/core/callback.schema.ts b/src/schemas/core/callback.schema.ts new file mode 100644 index 0000000..68f2b47 --- /dev/null +++ b/src/schemas/core/callback.schema.ts @@ -0,0 +1,32 @@ +import z from 'zod'; +import { OperationStatus } from '@map-colonies/mc-priority-queue'; +import { rasterProductTypeSchema, resourceIdSchema, versionSchema } from './job.schema'; + +export const callbackUrlSchema = z.string().url(); + +export const callbackUrlsArraySchema = z.array(callbackUrlSchema); + +export const fileMetadataSchema = z.object({ + name: z.string(), + url: callbackUrlSchema, + size: z.number(), +}); + +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export const createCallbackResponseSchema = (dataSchema?: z.ZodType) => { + return z.object({ + jobId: z.string().uuid(), + taskId: z.string().uuid(), + jobType: z.string(), + taskType: z.string(), + productId: resourceIdSchema, + productType: rasterProductTypeSchema, + version: versionSchema, + status: z.nativeEnum(OperationStatus), + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + progress: z.number().min(0).max(100).optional(), + message: z.string().optional(), + error: z.string().optional(), + data: dataSchema ?? z.unknown(), + }); +}; diff --git a/src/schemas/core/callbackUrl.schema.ts b/src/schemas/core/callbackUrl.schema.ts deleted file mode 100644 index 00cf90b..0000000 --- a/src/schemas/core/callbackUrl.schema.ts +++ /dev/null @@ -1,5 +0,0 @@ -import z from 'zod'; - -export const callbackUrlSchema = z.string().url(); - -export const callbackUrlsArraySchema = z.array(callbackUrlSchema); diff --git a/src/schemas/core/index.ts b/src/schemas/core/index.ts index f4083f2..0ffd356 100644 --- a/src/schemas/core/index.ts +++ b/src/schemas/core/index.ts @@ -3,4 +3,4 @@ export * from './job.schema'; export * from './task.schema'; export * from './mime.schema'; export * from './aggregation.schema'; -export * from './callbackUrl.schema'; +export * from './callback.schema'; diff --git a/src/schemas/export/job.schema.ts b/src/schemas/export/job.schema.ts index 7bb71f7..aafd996 100644 --- a/src/schemas/export/job.schema.ts +++ b/src/schemas/export/job.schema.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; import { CORE_VALIDATIONS, TileFormatStrategy, TileOutputFormat } from '../../constants'; import { polygonPartsEntityNameSchema } from '../ingestion'; -import { callbackUrlsArraySchema } from '../core/callbackUrl.schema'; +import { callbackUrlsArraySchema } from '../core/callback.schema'; import { callbackExportResponseSchema, cleanupDataSchema, roiFeatureCollectionSchema, fileNamesTemplatesSchema } from './export.schema'; export const exportInputParamsSchema = z.object({ diff --git a/src/schemas/ingestion/callback.schema.ts b/src/schemas/ingestion/callback.schema.ts new file mode 100644 index 0000000..a2a40f0 --- /dev/null +++ b/src/schemas/ingestion/callback.schema.ts @@ -0,0 +1,14 @@ +import z from 'zod'; +import { fileMetadataSchema } from '../core'; + +//#region Validation + +export const validationTaskCallbackDataSchema = z + .object({ + isValid: z.boolean(), + sourceName: z.string(), + links: fileMetadataSchema.array().optional(), + }) + .describe('validationTaskCallbackDataSchema'); + +//#endregion Validation diff --git a/src/schemas/ingestion/index.ts b/src/schemas/ingestion/index.ts index ceb3365..ba8424a 100644 --- a/src/schemas/ingestion/index.ts +++ b/src/schemas/ingestion/index.ts @@ -5,3 +5,4 @@ export * from './polygonParts.schema'; export * from './job.schema'; export * from './task.schema'; export * from './layerNameFormats.schema'; +export * from './callback.schema'; diff --git a/src/schemas/ingestion/job.schema.ts b/src/schemas/ingestion/job.schema.ts index ac49eb5..edd1569 100644 --- a/src/schemas/ingestion/job.schema.ts +++ b/src/schemas/ingestion/job.schema.ts @@ -1,6 +1,6 @@ import z from 'zod'; import { CORE_VALIDATIONS } from '../../constants'; -import { callbackUrlsArraySchema } from '../core/callbackUrl.schema'; +import { callbackUrlsArraySchema } from '../core/callback.schema'; import { newAdditionalParamsSchema, swapUpdateAdditionalParamsSchema, updateAdditionalParamsSchema } from './additionalParams.schema'; import { inputFilesSchema } from './inputFiles.schema'; import { newRasterLayerMetadataSchema, updateRasterLayerMetadataSchema } from './metadata.schema'; diff --git a/src/types/core/callback.type.ts b/src/types/core/callback.type.ts new file mode 100644 index 0000000..4adb59b --- /dev/null +++ b/src/types/core/callback.type.ts @@ -0,0 +1,4 @@ +import z from 'zod'; +import { createCallbackResponseSchema } from '../../schemas'; + +export type CallbackResponse = z.infer>>; diff --git a/src/types/export/export.type.ts b/src/types/export/export.type.ts index e6bd03e..4028013 100644 --- a/src/types/export/export.type.ts +++ b/src/types/export/export.type.ts @@ -10,7 +10,7 @@ import { linksSchema, roiPropertiesSchema, } from '../../schemas/export/export.schema'; -import { callbackUrlsArraySchema, callbackUrlSchema } from '../../schemas/core/callbackUrl.schema'; +import { callbackUrlsArraySchema, callbackUrlSchema } from '../../schemas/core/callback.schema'; export type RoiProperties = z.infer; export type RoiFeature = Feature; diff --git a/src/types/ingestion/callback.type.ts b/src/types/ingestion/callback.type.ts new file mode 100644 index 0000000..4a22125 --- /dev/null +++ b/src/types/ingestion/callback.type.ts @@ -0,0 +1,4 @@ +import z from 'zod'; +import { validationTaskCallbackDataSchema } from '../../schemas/ingestion/callback.schema'; + +export type ValidationCallbackData = z.infer; diff --git a/src/types/ingestion/index.ts b/src/types/ingestion/index.ts index 0bd3c01..29713e7 100644 --- a/src/types/ingestion/index.ts +++ b/src/types/ingestion/index.ts @@ -3,3 +3,4 @@ export * from './job.type'; export * from './task.type'; export * from './polygonParts.type'; export * from './report.type'; +export * from './callback.type';