Skip to content

Commit

Permalink
refactor(sources): Add *SourceResponse types (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Dec 19, 2024
1 parent 2faff76 commit 999ce7a
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 78 deletions.
37 changes: 1 addition & 36 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
6 changes: 4 additions & 2 deletions src/sources/boundary-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type UrlParameters = {
queryParameters?: Record<string, unknown> | unknown[];
};

export type BoundaryQuerySourceResponse = TilejsonResult;

export const boundaryQuerySource = async function (
options: BoundaryQuerySourceOptions
): Promise<TilejsonResult> {
): Promise<BoundaryQuerySourceResponse> {
const {
columns,
filters,
Expand All @@ -49,5 +51,5 @@ export const boundaryQuerySource = async function (
'boundary',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<BoundaryQuerySourceResponse>;
};
6 changes: 4 additions & 2 deletions src/sources/boundary-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ type UrlParameters = {
propertiesTableName: string;
};

export type BoundaryTableSourceResponse = TilejsonResult;

export const boundaryTableSource = async function (
options: BoundaryTableSourceOptions
): Promise<TilejsonResult> {
): Promise<BoundaryTableSourceResponse> {
const {filters, tilesetTableName, columns, propertiesTableName} = options;
const urlParameters: UrlParameters = {
tilesetTableName,
Expand All @@ -37,5 +39,5 @@ export const boundaryTableSource = async function (
'boundary',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<BoundaryTableSourceResponse>;
};
4 changes: 3 additions & 1 deletion src/sources/h3-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ type UrlParameters = {
filters?: Record<string, unknown>;
};

export type H3QuerySourceResponse = TilejsonResult & WidgetQuerySourceResult;

export const h3QuerySource = async function (
options: H3QuerySourceOptions
): Promise<TilejsonResult & WidgetQuerySourceResult> {
): Promise<H3QuerySourceResponse> {
const {
aggregationExp,
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
Expand Down
4 changes: 3 additions & 1 deletion src/sources/h3-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ type UrlParameters = {
filters?: Record<string, unknown>;
};

export type H3TableSourceResponse = TilejsonResult & WidgetTableSourceResult;

export const h3TableSource = async function (
options: H3TableSourceOptions
): Promise<TilejsonResult & WidgetTableSourceResult> {
): Promise<H3TableSourceResponse> {
const {
aggregationExp,
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
Expand Down
6 changes: 4 additions & 2 deletions src/sources/h3-tileset-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import type {
export type H3TilesetSourceOptions = SourceOptions & TilesetSourceOptions;
type UrlParameters = {name: string};

export type H3TilesetSourceResponse = TilejsonResult;

export const h3TilesetSource = async function (
options: H3TilesetSourceOptions
): Promise<TilejsonResult> {
): Promise<H3TilesetSourceResponse> {
const {tableName} = options;
const urlParameters: UrlParameters = {name: tableName};

return baseSource<UrlParameters>(
'tileset',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<H3TilesetSourceResponse>;
};
78 changes: 54 additions & 24 deletions src/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 4 additions & 1 deletion src/sources/quadbin-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ type UrlParameters = {
filters?: Record<string, unknown>;
};

export type QuadbinQuerySourceResponse = TilejsonResult &
WidgetQuerySourceResult;

export const quadbinQuerySource = async function (
options: QuadbinQuerySourceOptions
): Promise<TilejsonResult & WidgetQuerySourceResult> {
): Promise<QuadbinQuerySourceResponse> {
const {
aggregationExp,
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
Expand Down
5 changes: 4 additions & 1 deletion src/sources/quadbin-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ type UrlParameters = {
filters?: Record<string, unknown>;
};

export type QuadbinTableSourceResponse = TilejsonResult &
WidgetTableSourceResult;

export const quadbinTableSource = async function (
options: QuadbinTableSourceOptions
): Promise<TilejsonResult & WidgetTableSourceResult> {
): Promise<QuadbinTableSourceResponse> {
const {
aggregationExp,
aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
Expand Down
6 changes: 4 additions & 2 deletions src/sources/quadbin-tileset-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import type {
export type QuadbinTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
type UrlParameters = {name: string};

export type QuadbinTilesetSourceResponse = TilejsonResult;

export const quadbinTilesetSource = async function (
options: QuadbinTilesetSourceOptions
): Promise<TilejsonResult> {
): Promise<QuadbinTilesetSourceResponse> {
const {tableName} = options;
const urlParameters: UrlParameters = {name: tableName};

return baseSource<UrlParameters>(
'tileset',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<QuadbinTilesetSourceResponse>;
};
6 changes: 4 additions & 2 deletions src/sources/raster-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ type UrlParameters = {
filters?: Record<string, unknown>;
};

export type RasterSourceResponse = TilejsonResult;

export const rasterSource = async function (
options: RasterSourceOptions
): Promise<TilejsonResult> {
): Promise<RasterSourceResponse> {
const {tableName, filters} = options;
const urlParameters: UrlParameters = {name: tableName};
if (filters) {
Expand All @@ -30,5 +32,5 @@ export const rasterSource = async function (
'raster',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<RasterSourceResponse>;
};
5 changes: 4 additions & 1 deletion src/sources/vector-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ type UrlParameters = {
queryParameters?: Record<string, unknown> | unknown[];
};

export type VectorQuerySourceResponse = TilejsonResult &
WidgetQuerySourceResult;

export const vectorQuerySource = async function (
options: VectorQuerySourceOptions
): Promise<TilejsonResult & WidgetQuerySourceResult> {
): Promise<VectorQuerySourceResponse> {
const {
columns,
filters,
Expand Down
5 changes: 4 additions & 1 deletion src/sources/vector-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ type UrlParameters = {
name: string;
};

export type VectorTableSourceResponse = TilejsonResult &
WidgetTableSourceResult;

export const vectorTableSource = async function (
options: VectorTableSourceOptions
): Promise<TilejsonResult & WidgetTableSourceResult> {
): Promise<VectorTableSourceResponse> {
const {
columns,
filters,
Expand Down
6 changes: 4 additions & 2 deletions src/sources/vector-tileset-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import type {
export type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
type UrlParameters = {name: string};

export type VectorTilesetSourceResponse = TilejsonResult;

export const vectorTilesetSource = async function (
options: VectorTilesetSourceOptions
): Promise<TilejsonResult> {
): Promise<VectorTilesetSourceResponse> {
const {tableName} = options;
const urlParameters: UrlParameters = {name: tableName};

return baseSource<UrlParameters>(
'tileset',
options,
urlParameters
) as Promise<TilejsonResult>;
) as Promise<VectorTilesetSourceResponse>;
};

0 comments on commit 999ce7a

Please sign in to comment.