UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

156 lines (155 loc) 5.38 kB
import { JSONValue } from "./base.js"; import { Polygon, LineString, Point, Feature } from "./geojson.js"; import { Sketch, SketchCollection, SketchGeometryTypes, SketchProperties } from "./sketch.js"; interface ClientCode { uri: string; offlineSupported: boolean; } type RateLimitPeriod = "monthly" | "daily"; type GeoprocessingServiceType = "javascript" | "container"; /** Expected public service metadata for each function */ export interface GeoprocessingServiceMetadata extends GeoprocessingHandlerOptions { restrictedAccess?: boolean; /** Seconds */ medianDuration: number; /** USD */ medianCost: number; endpoint: string; type: GeoprocessingServiceType; clientSideBundle?: ClientCode; issAllowList: string[]; rateLimited: boolean; rateLimit: number; rateLimitPeriod: RateLimitPeriod; rateLimitConsumed: number; uri?: string; } export interface PreprocessingServiceMetadata extends PreprocessingHandlerOptions { restrictedAccess: boolean; /** Seconds */ medianDuration: number; /** USD */ medianCost: number; endpoint: string; type: GeoprocessingServiceType; clientSideBundle?: ClientCode; issAllowList: string[]; rateLimited: boolean; rateLimit: number; rateLimitPeriod: RateLimitPeriod; rateLimitConsumed: number; uri: string; } export type ExecutionMode = "async" | "sync"; export interface GeoprocessingHandlerOptions { /** Title will appear in service metadata and be referenced by clients */ title: string; /** Appears in service metadata */ description: string; /** Seconds */ timeout: number; /** Megabytes, 128 - 3008 */ memory?: number; /** Choose `sync` for functions that are expected to return quickly (< 2s) * and `async` for longer running functions, especially contain/docker jobs. */ executionMode: ExecutionMode; /** Specify the ids of any Sketch Class form fields that must be provided in * order to run the function */ requiresProperties?: string[]; /** Whether to rate limit beyond basic DDoS protection */ rateLimited?: boolean; rateLimit?: number; /** `daily` or `monthly` */ rateLimitPeriod?: RateLimitPeriod; /** Whether function should respect group access-control headers */ restrictedAccess?: boolean; /** List domains, e.g. myproject.seasketch.org. * When restrictedAccess is enabled, this function can be configured to only * work with specified projects. */ issAllowList?: string[]; /** Names of worker functions used by this function. Must be sync geoprocessing functions */ workers?: string[]; } export interface PreprocessingHandlerOptions { title: string; description: string; /** Seconds */ timeout: number; /** Megabytes, 128 - 10240, defaults to 1024 */ memory?: number; requiresProperties?: string[]; } export type GeoprocessingRequestParams = Record<string, JSONValue>; /** * Geoprocessing request internal data model, with full objects, no JSON strings */ export interface GeoprocessingRequestModel<G = SketchGeometryTypes> { /** URL to fetch Sketch JSON */ geometryUri?: string; /** Sketch JSON */ geometry?: Sketch<G> | SketchCollection<G>; /** Sketch Geobuf base64 string */ geometryGeobuf?: string; /** Additional runtime parameters */ extraParams?: GeoprocessingRequestParams; token?: string; /** Cache key for this task */ cacheKey?: string; wss?: string; /** If true, only check cache and do not run worker */ checkCacheOnly?: string; onSocketConnect?: string; /** If true, task state and result is not cached server-side. Only use for sync functions in a worker use case where its results are not needed */ disableCache?: boolean; } /** * Geoprocessing request sent via HTTP GET, with extraParams as url-encoded JSON string */ export type GeoprocessingRequest<G = SketchGeometryTypes> = Omit<GeoprocessingRequestModel<G>, "extraParams"> & { extraParams?: string; }; export interface SeaSketchReportingMessageEvent { client: string; sketchProperties: SketchProperties; geometryUri: string; type: "SeaSketchReportingMessageEventType"; visibleLayers?: string[]; language?: string; } export interface SeaSketchReportingVisibleLayersChangeEvent { visibleLayers: string[]; type: "SeaSketchReportingVisibleLayersChangeEvent"; } export interface SeaSketchReportingToggleLayerVisibilityEvent { layerId: string; on: boolean; type: "SeaSketchReportingToggleLayerVisibilityEvent"; } export interface SeaSketchReportingToggleLanguageEvent { language: string; on: boolean; type: "SeaSketchReportingToggleLanguageEvent"; } export interface PreprocessingRequest { /** Geometry drawn by the user. Typically simple */ feature: Feature<Polygon | Point | LineString>; /** Additional runtime parameters */ extraParams?: string; /** Defaults to geojson */ responseFormat?: "application/json"; } export interface PreprocessingResponse<ResponseType = Feature> { status: "ok" | "error" | "validationError"; data?: ResponseType; error?: string; } export interface PreprocessingService { title: string; description: string; endpoint: string; requiresProperties: string[]; } export {};