@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
123 lines • 4.23 kB
JavaScript
import { generateManifest } from "../build/generateManifest.js";
import { PreprocessingHandler, GeoprocessingHandler } from "../../src/index.js";
import { DEFAULTS as VECTOR_SOURCE_DEFAULTS } from "../../src/index.js";
import { point } from "@turf/turf";
/**
* Creates project core assets in-memory, with the components requested, and returns the resulting manifest
* Useful for stubbing projects for testing purposes
*/
export default async function createTestProjectManifest(projectName,
/** test components to add */
components) {
// Create source package
const pkgGeo = {
name: projectName,
version: "1.0.0",
description: `Test project with components ${components.join(", ")}`,
dependencies: {},
devDependencies: {},
author: "Test",
license: "UNLICENSED",
};
// Create project assets
let gpConfig = {
author: "Test <test@test.com>",
organization: "Test Org",
region: "us-west-1",
preprocessingFunctions: [],
geoprocessingFunctions: [],
clients: [],
};
let preprocessingBundles = [];
let geoprocessingBundles = [];
const testPpFunction = async () => {
return point([0, 0]);
};
const testGpFunction = async () => {
return { result: 50 };
};
const testSources = [
{
url: "https://testsource.com",
options: VECTOR_SOURCE_DEFAULTS,
},
];
if (components.includes("preprocessor")) {
gpConfig = {
...gpConfig,
preprocessingFunctions: ["src/functions/testPreprocessor.ts"],
};
const pHandler = new PreprocessingHandler(testPpFunction, {
title: "testPreprocessor",
description: "",
timeout: 1,
requiresProperties: [],
memory: 256, // test non-default value
});
preprocessingBundles = preprocessingBundles.concat({
handler: pHandler.lambdaHandler,
handlerFilename: "testPreprocessor.ts",
options: pHandler.options,
sources: testSources,
});
}
if (components.includes("syncGeoprocessor")) {
gpConfig = {
...gpConfig,
geoprocessingFunctions: [
...gpConfig.geoprocessingFunctions,
"src/functions/testSyncGeoprocessor.ts",
],
};
const sgHandler = new GeoprocessingHandler(testGpFunction, {
title: "testSyncGeoprocessor",
description: "",
timeout: 2,
executionMode: "sync",
requiresProperties: [],
});
geoprocessingBundles = geoprocessingBundles.concat({
handler: sgHandler.lambdaHandler,
handlerFilename: "testSyncGeoprocessor.ts",
options: sgHandler.options,
sources: testSources,
});
}
if (components.includes("asyncGeoprocessor")) {
gpConfig = {
...gpConfig,
geoprocessingFunctions: [
...gpConfig.geoprocessingFunctions,
"src/functions/testAsyncGeoprocessor.ts",
],
};
const agHandler = new GeoprocessingHandler(testGpFunction, {
title: "testAsyncGeoprocessor",
description: "",
timeout: 2,
executionMode: "async",
requiresProperties: [],
});
geoprocessingBundles = geoprocessingBundles.concat({
handler: agHandler.lambdaHandler,
handlerFilename: "testAsyncGeoprocessor.ts",
options: agHandler.options,
sources: testSources,
});
}
if (components.includes("client")) {
gpConfig = {
...gpConfig,
clients: [
...gpConfig.clients,
{
name: "TestClient",
description: "client description",
source: "src/clients/TestClient.tsx",
},
],
};
}
return generateManifest(gpConfig, pkgGeo, preprocessingBundles, geoprocessingBundles, pkgGeo.version);
}
//# sourceMappingURL=createTestProjectManifest.js.map