@map-colonies/export-interfaces
v1.5.0
Published
This package define and expose common interfaces & types for export tasks
Downloads
6
Maintainers
Keywords
Readme
Export-Interfaces
npm - @mapcolonies/export-interfaces
This package define and expose common interfaces & types for export tasks
Quickstart
- install
npm install @mapcolonies/export-interfaces
Data in Export-Interfaces
export-interfaces exposes the 'Export Manager' interface with common functions to be implement
export interface IExportManager {
createExportTask: (data: CreateExportTaskRequest<TaskParameters>) => Promise<CreateExportTaskResponse>;
getEstimations: (catalogRecordID: string, ROI: FeatureCollection, additional?: Record<string, unknown>) => Promise<GetEstimationsResponse>;
getFootprint: (catalogRecordID: string) => Promise<FeatureCollection>;
}
most of Export-Interfaces functions uses @turf/turf npm package for geographic data.
- import & implement
import { IExportManager } from '@map-colonies/export-interfaces';
export class ExportManager implements IExportManager {
...
}
- implements IExportManager functions
- createExportTask example:
export class ExportManager implements IExportManager {
public constructor(@inject(SERVICES.LOGGER) private readonly logger: Logger) {}
public async createExportTask(data: CreateExportTaskRequest<TaskParameters>): Promise<CreateExportTaskResponse> {
this.logger.info({ msg: 'log message' });
...
...
const geometry1: Polygon = {
coordinates: [
[
[38.12777806969146, 34.88509668647414],
[37.79098758535008, 34.88509668647414],
[37.79098758535008, 34.557014824377575],
[38.12777806969146, 34.557014824377575],
[38.12777806969146, 34.88509668647414],
],
],
type: 'Polygon',
};
const geometry2: MultiPolygon = {
coordinates: [
[
[30.10241695788926, 27.097838272461956],
[29.991351500386685, 27.0731170944439],
[29.991351500386685, 26.949429475478382],
[30.08853377570128, 26.776038590550044],
[30.310664690705238, 26.98655005029447],
[30.10241695788926, 27.097838272461956],
],
],
type: 'Polygon',
};
const taskGeometries: TaskGeometry[] = [{ geometry: geometry1, metadata: { maxRes: 0.732 } }, { geometry2 }]; // ⇨ 'metadata' is optional here
const createExportTaskResponse: CreateExportTaskResponse = {
jobId: '4b3d6bcd-bbfd-4b2d-9x5d-ab8dfbdd4be4', // uuid format
geometries: taskGeometries,
}
...
return createExportTaskResponse;
}
}
- getEstimatations ⇨ returns the estimated exported data size in bytes and estimated export task time in seconds
- getFootprint ⇨ returns the completed record footprint by id
Event Message
Export-Interfaces exposes different event message types for each events Export-Management usage (expects to receive those message objects in order to handle them while task event has occurred)
Task Events:
- TaskStartedMessage
- TaskCompletedMessage
- TaskFailedMessage
- TaskAbortedMessage
- TaskExpiredMessage
- TaskPausedMessage
publisher should handle those event message types ("DataType") by publishing them into message queue on Redis server ⇨ use BullMQ npm package