Skip to content

Commit d510efe

Browse files
authored
refactor: update raster-shared dependency to version 1.7.0 and adjust related types (#110)
* fix: update raster-shared dependency to version 1.7.0 and adjust related types * fix: update raster-shared dependency to version 1.7.1 and adjust related interfaces * fix: use optional chaining * fix: rename estimate function and update callbackURLs to callbackUrlArray
1 parent 266121d commit d510efe

File tree

9 files changed

+44
-36
lines changed

9 files changed

+44
-36
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@map-colonies/mc-priority-queue": "^8.2.1",
4040
"@map-colonies/mc-utils": "^3.2.0",
4141
"@map-colonies/openapi-express-viewer": "^3.0.0",
42-
"@map-colonies/raster-shared": "^1.6.0",
42+
"@map-colonies/raster-shared": "^1.7.1",
4343
"@map-colonies/read-pkg": "0.0.1",
4444
"@map-colonies/schemas": "v1.3.0",
4545
"@map-colonies/telemetry": "^7.0.1",

src/common/interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { ICreateJobBody, IJobResponse, OperationStatus } from '@map-colonies/mc-
33
import {
44
CallbackUrlsTargetArray,
55
ExportJobParameters,
6-
LinksDefinition,
6+
FileNamesTemplates,
77
PolygonPartsEntityName,
88
RasterProductTypes,
99
RoiFeatureCollection,
1010
TileFormatStrategy,
1111
TileOutputFormat,
1212
} from '@map-colonies/raster-shared';
1313
import { BBox, Geometry } from 'geojson';
14+
import z from 'zod';
1415

1516
export interface IConfig {
1617
get: <T>(setting: string) => T;
@@ -72,7 +73,7 @@ export interface IExportInitRequest {
7273
crs: string;
7374
roi: RoiFeatureCollection;
7475
callbackUrls?: CallbackUrlsTargetArray;
75-
fileNamesTemplates: LinksDefinition;
76+
fileNamesTemplates: FileNamesTemplates;
7677
relativeDirectoryPath: string;
7778
catalogId: string;
7879
priority?: number;

src/common/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const parseFeatureCollection = (featuresCollection: RoiFeatureCollection)
2929
return parsedGeoRecord;
3030
};
3131

32-
export const calculateEstimateGpkgSize = (featuresRecords: IGeometryRecord[], tileOutputFormat: TileOutputFormat): number => {
32+
export const calculateEstimatedGpkgSize = (featuresRecords: IGeometryRecord[], tileOutputFormat: TileOutputFormat): number => {
3333
const tileEstimatedSize = getTileEstimatedSize(tileOutputFormat);
3434
const batches: ITileRange[] = [];
3535
featuresRecords.forEach((record) => {

src/export/models/exportManager.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import { feature, featureCollection } from '@turf/helpers';
88
import { withSpanAsyncV4, withSpanV4 } from '@map-colonies/telemetry';
99
import { IConfig, ICreateExportJobResponse, IExportInitRequest, IGeometryRecord, IJobStatusResponse } from '@src/common/interfaces';
1010
import { MultiPolygon, Polygon } from 'geojson';
11-
import { calculateEstimateGpkgSize, parseFeatureCollection } from '@src/common/utils';
11+
import { calculateEstimatedGpkgSize, parseFeatureCollection } from '@src/common/utils';
1212
import {
13-
LinksDefinition,
1413
TileFormatStrategy,
1514
SourceType,
1615
CallbackExportResponse,
17-
CallbackUrls,
1816
RoiProperties,
1917
RasterProductTypes,
2018
RoiFeatureCollection,
2119
RasterLayerMetadata,
2220
CORE_VALIDATIONS,
2321
generateEntityName,
22+
CallbackUrl,
23+
FileNamesTemplates,
2424
} from '@map-colonies/raster-shared';
2525
import { v4 as uuidv4 } from 'uuid';
2626
import { CreateExportRequest } from '@src/utils/zod/schemas';
@@ -49,7 +49,7 @@ export class ExportManager {
4949

5050
@withSpanAsyncV4
5151
public async createExport(exportRequest: CreateExportRequest): Promise<ICreateExportJobResponse | CallbackExportResponse> {
52-
const { dbId: catalogId, crs, priority, callbackURLs, description } = exportRequest;
52+
const { dbId: catalogId, crs, priority, callbackUrlArray, description } = exportRequest;
5353
const layerMetadata = await this.validationManager.findLayer(catalogId);
5454

5555
let roi = exportRequest.roi;
@@ -61,7 +61,13 @@ export class ExportManager {
6161

6262
const { productId, productVersion: version, maxResolutionDeg: srcRes } = layerMetadata;
6363
const productType = layerMetadata.productType as RasterProductTypes;
64-
const callbacks = callbackURLs ? callbackURLs.map((url) => <CallbackUrls>{ url }) : undefined;
64+
const callbackUrls = callbackUrlArray?.map(
65+
(url) =>
66+
<CallbackUrl>{
67+
url,
68+
}
69+
);
70+
6571
const maxZoom = degreesPerPixelToZoomLevel(srcRes);
6672

6773
// ROI vs layer validation section - zoom + geo intersection
@@ -72,34 +78,34 @@ export class ExportManager {
7278
srcRes
7379
);
7480

75-
const duplicationExist = await this.findJobDuplications(productId, version, catalogId, roi, crs ?? DEFAULT_CRS, callbacks);
81+
const duplicationExist = await this.findJobDuplications(productId, version, catalogId, roi, crs ?? DEFAULT_CRS, callbackUrls);
7682
if (duplicationExist) {
7783
return duplicationExist;
7884
}
7985

80-
const estimatesGpkgSize = calculateEstimateGpkgSize(featuresRecords, layerMetadata.tileOutputFormat);
81-
await this.validationManager.validateFreeSpace(estimatesGpkgSize, this.gpkgsLocation);
86+
const gpkgEstimatedSize = calculateEstimatedGpkgSize(featuresRecords, layerMetadata.tileOutputFormat);
87+
await this.validationManager.validateFreeSpace(gpkgEstimatedSize, this.gpkgsLocation);
8288

8389
//creation of params
8490
const computedAttributes = this.computeFilePathAttributes(productType, productId, version, featuresRecords);
8591
const polygonPartsEntityName = generateEntityName(productId, productType);
8692

8793
const exportInitRequest: IExportInitRequest = {
8894
crs: crs ?? DEFAULT_CRS,
89-
roi: roi,
90-
callbackUrls: callbacks,
95+
roi,
96+
callbackUrls,
9197
fileNamesTemplates: computedAttributes.fileNamesTemplates,
9298
relativeDirectoryPath: computedAttributes.additionalIdentifiers,
9399
packageRelativePath: computedAttributes.packageRelativePath,
94100
catalogId,
95-
version: version,
101+
version,
96102
productId,
97103
productType,
98104
priority: priority ?? DEFAULT_PRIORITY,
99105
description,
100106
targetFormat: layerMetadata.tileOutputFormat,
101107
outputFormatStrategy: TileFormatStrategy.MIXED,
102-
gpkgEstimatedSize: estimatesGpkgSize,
108+
gpkgEstimatedSize,
103109
jobTrackerUrl: this.jobTrackerUrl,
104110
polygonPartsEntityName,
105111
};
@@ -126,9 +132,9 @@ export class ExportManager {
126132
catalogId: string,
127133
roi: RoiFeatureCollection,
128134
crs: string,
129-
callbacks?: CallbackUrls[]
135+
callbackUrls?: CallbackUrl[]
130136
): Promise<CallbackExportResponse | ICreateExportJobResponse | undefined> {
131-
const duplicationExist = await this.validationManager.checkForExportDuplicate(productId, version, catalogId, roi, crs, callbacks);
137+
const duplicationExist = await this.validationManager.checkForExportDuplicate(productId, version, catalogId, roi, crs, callbackUrls);
132138

133139
if (duplicationExist && duplicationExist.status === OperationStatus.COMPLETED) {
134140
const callbackParam = duplicationExist as CallbackExportResponse;
@@ -174,11 +180,11 @@ export class ExportManager {
174180
productId: string,
175181
version: string,
176182
featuresRecords: IGeometryRecord[]
177-
): { fileNamesTemplates: LinksDefinition; additionalIdentifiers: string; packageRelativePath: string } {
183+
): { fileNamesTemplates: FileNamesTemplates; additionalIdentifiers: string; packageRelativePath: string } {
178184
const prefixPackageName = this.generateExportFileNames(productType, productId, version, featuresRecords);
179185
const packageName = `${prefixPackageName}.gpkg`;
180-
const fileNamesTemplates: LinksDefinition = {
181-
dataURI: packageName,
186+
const fileNamesTemplates = {
187+
packageName,
182188
};
183189
const additionalIdentifiers = uuidv4();
184190
const separator = this.getSeparator();

src/utils/zod/schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { roiFeatureCollectionSchema } from '@map-colonies/raster-shared';
1+
import { callbackUrlSchema, roiFeatureCollectionSchema } from '@map-colonies/raster-shared';
22
import z from 'zod';
33

44
export const createExportRequestSchema = z.object({
55
dbId: z.string(),
66
crs: z.string().optional(),
77
priority: z.number().optional(),
88
roi: roiFeatureCollectionSchema.optional(),
9-
callbackURLs: z.array(z.string()).optional(),
9+
callbackUrlArray: callbackUrlSchema.shape.url.array().optional(),
1010
description: z.string().optional(),
1111
});
1212

tests/mocks/data.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const createExportData: IExportInitRequest = {
131131
},
132132
],
133133
fileNamesTemplates: {
134-
dataURI: 'Orthophoto_SOME_NAME_1_0_0_2025_01_06T09_29_04_933Z.gpkg',
134+
packageName: 'Orthophoto_SOME_NAME_1_0_0_2025_01_06T09_29_04_933Z.gpkg',
135135
},
136136
relativeDirectoryPath: 'e315e6d204d92b1d2dbfdaab96ff2a7e',
137137
packageRelativePath: 'e315e6d204d92b1d2dbfdaab96ff2a7e/Orthophoto_SOME_NAME_1_0_0_2025_01_06T09_29_04_933Z.gpkg',
@@ -233,7 +233,7 @@ export const initExportRequestBody = {
233233
},
234234
additionalParams: {
235235
fileNamesTemplates: {
236-
dataURI: 'Orthophoto_SOME_NAME_1_0_0_2025_01_09T10_04_06_711Z.gpkg',
236+
packageName: 'Orthophoto_SOME_NAME_1_0_0_2025_01_09T10_04_06_711Z.gpkg',
237237
},
238238
relativeDirectoryPath: '63baedae-cb5b-4c0a-a7db-8eb6b9105cb7',
239239
packageRelativePath: '63baedae-cb5b-4c0a-a7db-8eb6b9105cb7/Orthophoto_SOME_NAME_1_0_0_2025_01_09T10_04_06_711Z.gpkg',
@@ -318,7 +318,7 @@ export const initExportRequestBodyNoRoiWithCallback = {
318318
},
319319
additionalParams: {
320320
fileNamesTemplates: {
321-
dataURI: 'Orthophoto_SOME_NAME_1_0_0_2025_01_09T12_39_36_961Z.gpkg',
321+
packageName: 'Orthophoto_SOME_NAME_1_0_0_2025_01_09T12_39_36_961Z.gpkg',
322322
},
323323
relativeDirectoryPath: 'b30e5a99b78a6c10e65164fd54b14ad0',
324324
packageRelativePath: 'b30e5a99b78a6c10e65164fd54b14ad0/Orthophoto_SOME_NAME_1_0_0_2025_01_09T12_39_36_961Z.gpkg',
@@ -600,18 +600,18 @@ export const createExportRequestWithoutCallback: CreateExportRequest = {
600600

601601
export const createExportRequestNoRoiWithCallback: CreateExportRequest = {
602602
dbId: catalogId,
603-
callbackURLs: ['http://callback1'],
603+
callbackUrlArray: ['http://callback1'],
604604
};
605605

606606
export const createExportRequestWithRoiAndCallback: CreateExportRequest = {
607607
dbId: catalogId,
608-
callbackURLs: ['http://example.getmap.com/callback', 'http://example.getmap.com/callback2'],
608+
callbackUrlArray: ['http://example.getmap.com/callback', 'http://example.getmap.com/callback2'],
609609
roi: defaultRoi,
610610
};
611611

612612
export const createExportRequestWithRoiAndNewCallback: CreateExportRequest = {
613613
dbId: catalogId,
614-
callbackURLs: ['http://example.getmap.com/callback3'],
614+
callbackUrlArray: ['http://example.getmap.com/callback3'],
615615
roi: defaultRoi,
616616
};
617617

tests/mocks/processingRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const inProgressJobsResponse = [
6262
parameters: {
6363
additionalParams: {
6464
fileNamesTemplates: {
65-
dataURI: 'Orthophoto_SOME_NAME_1_0_0_2025_01_02T12_00_02_621Z.gpkg',
65+
packageName: 'Orthophoto_SOME_NAME_1_0_0_2025_01_02T12_00_02_621Z.gpkg',
6666
},
6767
packageRelativePath: '63baedae-cb5b-4c0a-a7db-8eb6b9105cb7/Orthophoto_SOME_NAME_1_0_0_2025_01_02T12_00_02_621Z.gpkg',
6868
relativeDirectoryPath: '63baedae-cb5b-4c0a-a7db-8eb6b9105cb7',
@@ -158,7 +158,7 @@ export const inProgressJobsResponse = [
158158
parameters: {
159159
additionalParams: {
160160
fileNamesTemplates: {
161-
dataURI: 'Orthophoto_SOME_NAME_1_0_0_2025_01_05T09_37_40_928Z.gpkg',
161+
packageName: 'Orthophoto_SOME_NAME_1_0_0_2025_01_05T09_37_40_928Z.gpkg',
162162
},
163163
packageRelativePath: '65adbc306ad555ca82ca12df9153dee1/Orthophoto_SOME_NAME_1_0_0_2025_01_05T09_37_40_928Z.gpkg',
164164
relativeDirectoryPath: '65adbc306ad555ca82ca12df9153dee1',

tests/unit/utils/zod/schemas.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('SchemasValidations', () => {
5151
});
5252

5353
it('should throw an error if callbackURLs is not an array of strings', () => {
54-
expect(() => createExportRequestSchema.parse({ ...validUserExportRequest, callbackURLs: [123] })).toThrow();
54+
expect(() => createExportRequestSchema.parse({ ...validUserExportRequest, callbackUrlArray: [123] })).toThrow();
5555
});
5656

5757
it('should throw an error if priority is not a number', () => {

0 commit comments

Comments
 (0)