Skip to content
Merged
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
32 changes: 32 additions & 0 deletions src/schemas/core/callback.schema.ts
Original file line number Diff line number Diff line change
@@ -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);
Comment thread
vitaligi marked this conversation as resolved.

export const fileMetadataSchema = z.object({
name: z.string(),
url: callbackUrlSchema,
size: z.number(),
});
Comment thread
vitaligi marked this conversation as resolved.

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createCallbackResponseSchema = <T>(dataSchema?: z.ZodType<T>) => {
Comment thread
CL-SHLOMIKONCHA marked this conversation as resolved.
return z.object({
jobId: z.string().uuid(),
taskId: z.string().uuid(),
jobType: z.string(),
taskType: z.string(),
Comment thread
vitaligi marked this conversation as resolved.
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(),
Comment thread
vitaligi marked this conversation as resolved.
data: dataSchema ?? z.unknown(),
});
};
5 changes: 0 additions & 5 deletions src/schemas/core/callbackUrl.schema.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/schemas/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion src/schemas/export/job.schema.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
14 changes: 14 additions & 0 deletions src/schemas/ingestion/callback.schema.ts
Original file line number Diff line number Diff line change
@@ -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(),
Comment thread
vitaligi marked this conversation as resolved.
links: fileMetadataSchema.array().optional(),
})
.describe('validationTaskCallbackDataSchema');

//#endregion Validation
1 change: 1 addition & 0 deletions src/schemas/ingestion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './polygonParts.schema';
export * from './job.schema';
export * from './task.schema';
export * from './layerNameFormats.schema';
export * from './callback.schema';
2 changes: 1 addition & 1 deletion src/schemas/ingestion/job.schema.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 4 additions & 0 deletions src/types/core/callback.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import z from 'zod';
import { createCallbackResponseSchema } from '../../schemas';

export type CallbackResponse<T> = z.infer<ReturnType<typeof createCallbackResponseSchema<T>>>;
2 changes: 1 addition & 1 deletion src/types/export/export.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof roiPropertiesSchema>;
export type RoiFeature = Feature<Polygon | MultiPolygon, RoiProperties>;
Expand Down
4 changes: 4 additions & 0 deletions src/types/ingestion/callback.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import z from 'zod';
import { validationTaskCallbackDataSchema } from '../../schemas/ingestion/callback.schema';

export type ValidationCallbackData = z.infer<typeof validationTaskCallbackDataSchema>;
1 change: 1 addition & 0 deletions src/types/ingestion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './job.type';
export * from './task.type';
export * from './polygonParts.type';
export * from './report.type';
export * from './callback.type';