Skip to content

Commit

Permalink
round out GeoprocessingRequest geometry typing to match sketch types.…
Browse files Browse the repository at this point in the history
… Improve GeoprocessingHandler comments.
  • Loading branch information
twelch committed May 21, 2024
1 parent 2652c24 commit 569e297
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
12 changes: 6 additions & 6 deletions packages/geoprocessing/src/aws/GeoprocessingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,19 @@ export class GeoprocessingHandler<
}

/**
* Parses request event and returns GeoprocessingRequest.
* Parses event and returns GeoprocessingRequestModel object.
*/
parseRequest<G>(event: APIGatewayProxyEvent): GeoprocessingRequestModel<G> {
let request: GeoprocessingRequestModel<G>;
if ("geometry" in event) {
// POST request or aws console, so already in internal model form
if ("geometry" in event || "geometryUri" in event) {
// Is direct aws invocation, so should already be in internal model form
request = event as GeoprocessingRequestModel<G>;
} else if (
event.queryStringParameters &&
event.queryStringParameters["geometryUri"]
) {
// GET request with query string parameters to merge

// Extract extraParams from query string if necessary, though gateway lambda integration seems to do it for us
// Is GET request with query string parameters
// parse extraParams object from query string if necessary, though gateway lambda integration seems to do it for us
const extraString = event.queryStringParameters["extraParams"];
let extraParams: P | undefined;
if (typeof extraString === "string") {
Expand All @@ -465,6 +464,7 @@ export class GeoprocessingHandler<
extraParams,
};
} else if (event.body && typeof event.body === "string") {
// Is POST request
request = JSON.parse(event.body);
} else {
throw new Error("Could not interpret incoming request");
Expand Down
2 changes: 1 addition & 1 deletion packages/geoprocessing/src/datasources/seasketch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Sketch,
SketchCollection,
Geometry,
GeoprocessingRequest,
} from "../types/index.js";
import { GeoprocessingRequest } from "../types/index.js";
import isHostedOnLambda from "./isHostedOnLambda.js";
// Seasketch client

Expand Down
29 changes: 21 additions & 8 deletions packages/geoprocessing/src/types/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { JSONValue } from "./base.js";
import { Polygon, LineString, Point, Feature } from "./geojson.js";
import { Sketch, SketchProperties } from "./sketch.js";
import {
Polygon,
MultiPolygon,
LineString,
Point,
Feature,
} from "./geojson.js";
import {
Sketch,
SketchCollection,
SketchGeometryTypes,
SketchProperties,
} from "./sketch.js";

interface ClientCode {
uri: string; // public bundle location
Expand Down Expand Up @@ -99,13 +110,15 @@ export interface PreprocessingHandlerOptions {
}

/**
* Represents geoprocessing request via HTTP method, fully packed
* Represents geoprocessing request via HTTP method, fully packed (stringified JSON) parameters
*/
export interface GeoprocessingRequest<G = Polygon | LineString | Point> {
export interface GeoprocessingRequest<
G = Polygon | MultiPolygon | LineString | Point,
> {
/** URL to fetch Sketch JSON */
geometryUri?: string; // must be https
/** Sketch JSON */
geometry?: Sketch<G>;
geometry?: Sketch<G> | SketchCollection<G>;
/** Additional runtime parameters, as escaped JSON string */
extraParams?: string;
token?: string;
Expand All @@ -118,13 +131,13 @@ export interface GeoprocessingRequest<G = Polygon | LineString | Point> {
export type GeoprocessingRequestParams = Record<string, JSONValue>;

/**
* Represents geoprocessing request internally, fully unpacked
* Represents geoprocessing request internally, fully unpacked parameters
*/
export interface GeoprocessingRequestModel<G = Polygon | LineString | Point> {
export interface GeoprocessingRequestModel<G = SketchGeometryTypes> {
/** URL to fetch Sketch JSON */
geometryUri?: string; // must be https
/** Sketch JSON */
geometry?: Sketch<G>;
geometry?: Sketch<G> | SketchCollection<G>;
/** Additional runtime parameters */
extraParams?: GeoprocessingRequestParams;
token?: string;
Expand Down

0 comments on commit 569e297

Please sign in to comment.