From 999ce7a431452a14557cd41cd71b2e2e46fb69a6 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Thu, 19 Dec 2024 18:09:25 -0500 Subject: [PATCH] refactor(sources): Add *SourceResponse types (#47) --- src/index.ts | 37 +------------ src/sources/boundary-query-source.ts | 6 ++- src/sources/boundary-table-source.ts | 6 ++- src/sources/h3-query-source.ts | 4 +- src/sources/h3-table-source.ts | 4 +- src/sources/h3-tileset-source.ts | 6 ++- src/sources/index.ts | 78 ++++++++++++++++++--------- src/sources/quadbin-query-source.ts | 5 +- src/sources/quadbin-table-source.ts | 5 +- src/sources/quadbin-tileset-source.ts | 6 ++- src/sources/raster-source.ts | 6 ++- src/sources/vector-query-source.ts | 5 +- src/sources/vector-table-source.ts | 5 +- src/sources/vector-tileset-source.ts | 6 ++- 14 files changed, 101 insertions(+), 78 deletions(-) diff --git a/src/index.ts b/src/index.ts index dda6dec..ff0b61a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ export * from './client.js'; export * from './constants.js'; export * from './filters.js'; export * from './geo.js'; +export * from './sources/index.js'; export * from './widget-sources/index.js'; export * from './types.js'; @@ -15,39 +16,3 @@ export { query, requestWithParameters, } from './api/index.js'; - -export { - BoundaryQuerySourceOptions, - BoundaryTableSourceOptions, - GeojsonResult, - H3QuerySourceOptions, - H3TableSourceOptions, - H3TilesetSourceOptions, - JsonResult, - QuadbinQuerySourceOptions, - QuadbinTableSourceOptions, - QuadbinTilesetSourceOptions, - QueryResult, - QuerySourceOptions, - RasterSourceOptions, - SOURCE_DEFAULTS, - SourceOptions, - TableSourceOptions, - TilejsonResult, - TilesetSourceOptions, - VectorQuerySourceOptions, - VectorTableSourceOptions, - VectorTilesetSourceOptions, - boundaryQuerySource, - boundaryTableSource, - h3QuerySource, - h3TableSource, - h3TilesetSource, - quadbinQuerySource, - quadbinTableSource, - quadbinTilesetSource, - rasterSource, - vectorQuerySource, - vectorTableSource, - vectorTilesetSource, -} from './sources/index.js'; diff --git a/src/sources/boundary-query-source.ts b/src/sources/boundary-query-source.ts index de2d7bf..c5f6379 100644 --- a/src/sources/boundary-query-source.ts +++ b/src/sources/boundary-query-source.ts @@ -21,9 +21,11 @@ type UrlParameters = { queryParameters?: Record | unknown[]; }; +export type BoundaryQuerySourceResponse = TilejsonResult; + export const boundaryQuerySource = async function ( options: BoundaryQuerySourceOptions -): Promise { +): Promise { const { columns, filters, @@ -49,5 +51,5 @@ export const boundaryQuerySource = async function ( 'boundary', options, urlParameters - ) as Promise; + ) as Promise; }; diff --git a/src/sources/boundary-table-source.ts b/src/sources/boundary-table-source.ts index 05d3dae..23ad270 100644 --- a/src/sources/boundary-table-source.ts +++ b/src/sources/boundary-table-source.ts @@ -18,9 +18,11 @@ type UrlParameters = { propertiesTableName: string; }; +export type BoundaryTableSourceResponse = TilejsonResult; + export const boundaryTableSource = async function ( options: BoundaryTableSourceOptions -): Promise { +): Promise { const {filters, tilesetTableName, columns, propertiesTableName} = options; const urlParameters: UrlParameters = { tilesetTableName, @@ -37,5 +39,5 @@ export const boundaryTableSource = async function ( 'boundary', options, urlParameters - ) as Promise; + ) as Promise; }; diff --git a/src/sources/h3-query-source.ts b/src/sources/h3-query-source.ts index 230b357..a08eef7 100644 --- a/src/sources/h3-query-source.ts +++ b/src/sources/h3-query-source.ts @@ -29,9 +29,11 @@ type UrlParameters = { filters?: Record; }; +export type H3QuerySourceResponse = TilejsonResult & WidgetQuerySourceResult; + export const h3QuerySource = async function ( options: H3QuerySourceOptions -): Promise { +): Promise { const { aggregationExp, aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3, diff --git a/src/sources/h3-table-source.ts b/src/sources/h3-table-source.ts index 6bad8a9..43b62d7 100644 --- a/src/sources/h3-table-source.ts +++ b/src/sources/h3-table-source.ts @@ -29,9 +29,11 @@ type UrlParameters = { filters?: Record; }; +export type H3TableSourceResponse = TilejsonResult & WidgetTableSourceResult; + export const h3TableSource = async function ( options: H3TableSourceOptions -): Promise { +): Promise { const { aggregationExp, aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3, diff --git a/src/sources/h3-tileset-source.ts b/src/sources/h3-tileset-source.ts index ac1752c..eae15cc 100644 --- a/src/sources/h3-tileset-source.ts +++ b/src/sources/h3-tileset-source.ts @@ -12,9 +12,11 @@ import type { export type H3TilesetSourceOptions = SourceOptions & TilesetSourceOptions; type UrlParameters = {name: string}; +export type H3TilesetSourceResponse = TilejsonResult; + export const h3TilesetSource = async function ( options: H3TilesetSourceOptions -): Promise { +): Promise { const {tableName} = options; const urlParameters: UrlParameters = {name: tableName}; @@ -22,5 +24,5 @@ export const h3TilesetSource = async function ( 'tileset', options, urlParameters - ) as Promise; + ) as Promise; }; diff --git a/src/sources/index.ts b/src/sources/index.ts index 99028fa..2d2d148 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -4,56 +4,86 @@ export {SOURCE_DEFAULTS} from './base-source'; export type { - VectorLayer, - RasterMetadataBandStats, - RasterBandColorinterp, - RasterMetadataBand, - RasterMetadata, - TilejsonResult, GeojsonResult, JsonResult, QueryResult, + QuerySourceOptions, + RasterBandColorinterp, + RasterMetadata, + RasterMetadataBand, + RasterMetadataBandStats, + SourceOptions, + TableSourceOptions, + TilejsonResult, + TilesetSourceOptions, + VectorLayer, } from './types'; export {boundaryQuerySource} from './boundary-query-source'; -export type {BoundaryQuerySourceOptions} from './boundary-query-source'; +export type { + BoundaryQuerySourceOptions, + BoundaryQuerySourceResponse, +} from './boundary-query-source'; export {boundaryTableSource} from './boundary-table-source'; -export type {BoundaryTableSourceOptions} from './boundary-table-source'; +export type { + BoundaryTableSourceOptions, + BoundaryTableSourceResponse, +} from './boundary-table-source'; export {h3QuerySource} from './h3-query-source'; -export type {H3QuerySourceOptions} from './h3-query-source'; +export type { + H3QuerySourceOptions, + H3QuerySourceResponse, +} from './h3-query-source'; export {h3TableSource} from './h3-table-source'; -export type {H3TableSourceOptions} from './h3-table-source'; +export type { + H3TableSourceOptions, + H3TableSourceResponse, +} from './h3-table-source'; export {h3TilesetSource} from './h3-tileset-source'; -export type {H3TilesetSourceOptions} from './h3-tileset-source'; +export type { + H3TilesetSourceOptions, + H3TilesetSourceResponse, +} from './h3-tileset-source'; export {rasterSource} from './raster-source'; -export type {RasterSourceOptions} from './raster-source'; +export type {RasterSourceOptions, RasterSourceResponse} from './raster-source'; export {quadbinQuerySource} from './quadbin-query-source'; -export type {QuadbinQuerySourceOptions} from './quadbin-query-source'; +export type { + QuadbinQuerySourceOptions, + QuadbinQuerySourceResponse, +} from './quadbin-query-source'; export {quadbinTableSource} from './quadbin-table-source'; -export type {QuadbinTableSourceOptions} from './quadbin-table-source'; +export type { + QuadbinTableSourceOptions, + QuadbinTableSourceResponse, +} from './quadbin-table-source'; export {quadbinTilesetSource} from './quadbin-tileset-source'; -export type {QuadbinTilesetSourceOptions} from './quadbin-tileset-source'; +export type { + QuadbinTilesetSourceOptions, + QuadbinTilesetSourceResponse, +} from './quadbin-tileset-source'; export {vectorQuerySource} from './vector-query-source'; -export type {VectorQuerySourceOptions} from './vector-query-source'; +export type { + VectorQuerySourceOptions, + VectorQuerySourceResponse, +} from './vector-query-source'; export {vectorTableSource} from './vector-table-source'; -export type {VectorTableSourceOptions} from './vector-table-source'; +export type { + VectorTableSourceOptions, + VectorTableSourceResponse, +} from './vector-table-source'; export {vectorTilesetSource} from './vector-tileset-source'; -export type {VectorTilesetSourceOptions} from './vector-tileset-source'; - export type { - SourceOptions, - QuerySourceOptions, - TableSourceOptions, - TilesetSourceOptions, -} from './types'; + VectorTilesetSourceOptions, + VectorTilesetSourceResponse, +} from './vector-tileset-source'; diff --git a/src/sources/quadbin-query-source.ts b/src/sources/quadbin-query-source.ts index 0e6ea7f..0f84bda 100644 --- a/src/sources/quadbin-query-source.ts +++ b/src/sources/quadbin-query-source.ts @@ -30,9 +30,12 @@ type UrlParameters = { filters?: Record; }; +export type QuadbinQuerySourceResponse = TilejsonResult & + WidgetQuerySourceResult; + export const quadbinQuerySource = async function ( options: QuadbinQuerySourceOptions -): Promise { +): Promise { const { aggregationExp, aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN, diff --git a/src/sources/quadbin-table-source.ts b/src/sources/quadbin-table-source.ts index 91b7a1c..8f4555c 100644 --- a/src/sources/quadbin-table-source.ts +++ b/src/sources/quadbin-table-source.ts @@ -29,9 +29,12 @@ type UrlParameters = { filters?: Record; }; +export type QuadbinTableSourceResponse = TilejsonResult & + WidgetTableSourceResult; + export const quadbinTableSource = async function ( options: QuadbinTableSourceOptions -): Promise { +): Promise { const { aggregationExp, aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN, diff --git a/src/sources/quadbin-tileset-source.ts b/src/sources/quadbin-tileset-source.ts index db188df..e7c87f6 100644 --- a/src/sources/quadbin-tileset-source.ts +++ b/src/sources/quadbin-tileset-source.ts @@ -12,9 +12,11 @@ import type { export type QuadbinTilesetSourceOptions = SourceOptions & TilesetSourceOptions; type UrlParameters = {name: string}; +export type QuadbinTilesetSourceResponse = TilejsonResult; + export const quadbinTilesetSource = async function ( options: QuadbinTilesetSourceOptions -): Promise { +): Promise { const {tableName} = options; const urlParameters: UrlParameters = {name: tableName}; @@ -22,5 +24,5 @@ export const quadbinTilesetSource = async function ( 'tileset', options, urlParameters - ) as Promise; + ) as Promise; }; diff --git a/src/sources/raster-source.ts b/src/sources/raster-source.ts index 565ead4..9d878b7 100644 --- a/src/sources/raster-source.ts +++ b/src/sources/raster-source.ts @@ -18,9 +18,11 @@ type UrlParameters = { filters?: Record; }; +export type RasterSourceResponse = TilejsonResult; + export const rasterSource = async function ( options: RasterSourceOptions -): Promise { +): Promise { const {tableName, filters} = options; const urlParameters: UrlParameters = {name: tableName}; if (filters) { @@ -30,5 +32,5 @@ export const rasterSource = async function ( 'raster', options, urlParameters - ) as Promise; + ) as Promise; }; diff --git a/src/sources/vector-query-source.ts b/src/sources/vector-query-source.ts index 93db9a4..202095c 100644 --- a/src/sources/vector-query-source.ts +++ b/src/sources/vector-query-source.ts @@ -33,9 +33,12 @@ type UrlParameters = { queryParameters?: Record | unknown[]; }; +export type VectorQuerySourceResponse = TilejsonResult & + WidgetQuerySourceResult; + export const vectorQuerySource = async function ( options: VectorQuerySourceOptions -): Promise { +): Promise { const { columns, filters, diff --git a/src/sources/vector-table-source.ts b/src/sources/vector-table-source.ts index 85dc4db..62707ef 100644 --- a/src/sources/vector-table-source.ts +++ b/src/sources/vector-table-source.ts @@ -31,9 +31,12 @@ type UrlParameters = { name: string; }; +export type VectorTableSourceResponse = TilejsonResult & + WidgetTableSourceResult; + export const vectorTableSource = async function ( options: VectorTableSourceOptions -): Promise { +): Promise { const { columns, filters, diff --git a/src/sources/vector-tileset-source.ts b/src/sources/vector-tileset-source.ts index 506f64d..a2f42f4 100644 --- a/src/sources/vector-tileset-source.ts +++ b/src/sources/vector-tileset-source.ts @@ -12,9 +12,11 @@ import type { export type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions; type UrlParameters = {name: string}; +export type VectorTilesetSourceResponse = TilejsonResult; + export const vectorTilesetSource = async function ( options: VectorTilesetSourceOptions -): Promise { +): Promise { const {tableName} = options; const urlParameters: UrlParameters = {name: tableName}; @@ -22,5 +24,5 @@ export const vectorTilesetSource = async function ( 'tileset', options, urlParameters - ) as Promise; + ) as Promise; };