Types

The TypeScript library provides classes for every Spade type. These classes are used as type annotations in handler metadata and as the values your handler receives and returns.

Type reference🔗

Single-file types🔗

ClassManifest typeManifest formatPropertyDescription
Filefile--path: stringA generic single file
RasterFilefileGeoTIFFpath: stringA raster data file
VectorFilefileGeoJSONpath: stringA vector data file
TabularFilefileCSVpath: stringA tabular data file
JsonFilejson--path: stringA JSON data file

All single-file types extend File and expose a path property pointing to the file on disk.

Directory type🔗

ClassManifest typePropertyDescription
Directorydirectorypath: stringA directory input or output

Collection types🔗

ClassManifest typeManifest formatPropertyDescription
FileCollectioncollection--paths: string[]A collection of generic files
RasterFileCollectioncollectionGeoTIFFpaths: string[]A collection of raster files
VectorFileCollectioncollectionGeoJSONpaths: string[]A collection of vector files
TabularFileCollectioncollectionCSVpaths: string[]A collection of tabular files

Collection types extend FileCollection and expose a paths property with an array of file paths.

Scalar types (parameters)🔗

Scalar types are specified as string literals in metadata rather than as classes:

LiteralManifest typeTypeScript typeDescription
"string"stringstringA text parameter
"number"numbernumberA numeric parameter
"boolean"booleanbooleanA boolean parameter

Class hierarchy🔗

File
  RasterFile
  VectorFile
  TabularFile
  JsonFile

Directory

FileCollection
  RasterFileCollection
  VectorFileCollection
  TabularFileCollection

All single-file classes inherit from File. All collection classes inherit from FileCollection. Directory is a standalone class.

Using types in metadata🔗

Types appear in the inputs object of your SpadeMetadata. File and directory types use the class constructor; scalar types use string literals:

import { spadeBlock, RasterFile, VectorFile } from "spade";

const handler = spadeBlock({
  inputs: {
    raster: RasterFile,       // file type -- uses class
    boundary: VectorFile,     // file type -- uses class
    buffer: "number",         // scalar type -- uses string literal
    label: "string",          // scalar type -- uses string literal
  },
  output: RasterFile,
})(function handler({ raster, boundary, buffer, label }) {
  // raster is a RasterFile instance
  // boundary is a VectorFile instance
  // buffer is a number
  // label is a string
  return new RasterFile("outputs/raster/result.tif");
});

Constructing output values🔗

When returning values from your handler, construct the appropriate type:

// Single file
return new RasterFile("path/to/result.tif");

// Directory
return new Directory("path/to/output_dir");

// Collection
return new RasterFileCollection([
  "path/to/tile_001.tif",
  "path/to/tile_002.tif",
]);

How input scanning works🔗

When run() executes, it scans the inputs/ directory. Each subdirectory becomes an input argument. The metadata's type hint controls how the input is constructed:

  • File subclass -- the first file in the subdirectory is used to construct the instance
  • Directory -- the subdirectory path itself is passed to the constructor
  • FileCollection subclass -- all files in the subdirectory are collected into the array
  • Scalar type -- the value comes from params.yaml, not from inputs/

If no metadata is provided, inputs default to File for single-file directories and FileCollection for multi-file directories.

Importing🔗

All types are exported from the main package:

import {
  File,
  RasterFile,
  VectorFile,
  TabularFile,
  JsonFile,
  Directory,
  FileCollection,
  RasterFileCollection,
  VectorFileCollection,
  TabularFileCollection,
} from "spade";