Skip to content

Commit

Permalink
Refactor Maps class to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
manmorjim committed Jun 9, 2020
1 parent 809b6a4 commit 84ec830
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
21 changes: 9 additions & 12 deletions src/lib/maps/Maps.ts → src/lib/maps/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const REQUEST_GET_MAX_URL_LENGTH = 2048;
const VECTOR_EXTENT = 2048;
const VECTOR_SIMPLIFY_EXTENT = 2048;

export class Maps {
export class Client {
private _credentials: Credentials;

constructor(credentials: Credentials) {
Expand Down Expand Up @@ -41,10 +41,8 @@ export class Maps {
type: 'mapnik',
options: {
sql: sql || `select * from ${dataset}`,
/* eslint-disable @typescript-eslint/camelcase */
vector_extent: vectorExtent,
vector_simplify_extent: vectorSimplifyExtent,
/* eslint-enable @typescript-eslint/camelcase */
metadata,
aggregation
}
Expand Down Expand Up @@ -80,11 +78,7 @@ export class Maps {
* @param layergroup
* @param options
*/
public async aggregationDataview(
layergroup: any,
dataview: string,
categories?: number
) {
public async aggregationDataview(layergroup: any, dataview: string, categories?: number) {
const {
metadata: {
dataviews: {
Expand All @@ -96,10 +90,7 @@ export class Maps {
const parameters = [encodeParameter('api_key', this._credentials.apiKey)];

if (categories) {
const encodedCategories = encodeParameter(
'categories',
categories.toString()
);
const encodedCategories = encodeParameter('categories', categories.toString());
parameters.push(encodedCategories);
}

Expand Down Expand Up @@ -167,7 +158,9 @@ export class Maps {
}

export interface AggregationColumn {
// eslint-disable-next-line camelcase
aggregate_function: string;
// eslint-disable-next-line camelcase
aggregated_column: string;
}

Expand All @@ -177,7 +170,9 @@ export interface StatsColumn {
}

export interface Sample {
// eslint-disable-next-line camelcase
num_rows: number;
// eslint-disable-next-line camelcase
include_columns: string[];
}

Expand Down Expand Up @@ -210,6 +205,7 @@ interface BufferSizeOptions {

export interface MapInstance {
layergroupid: string;
// eslint-disable-next-line camelcase
last_updated: string;
metadata: {
layers: [
Expand Down Expand Up @@ -250,6 +246,7 @@ export interface MapInstance {
subdomains: string[];
};
};
// eslint-disable-next-line camelcase
cdn_url: {
http: string;
https: string;
Expand Down
13 changes: 6 additions & 7 deletions src/lib/maps/MapsDataviews.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Credentials } from '../core/Credentials';
import { Maps } from './Maps';
import { Client } from './Client';

export class MapsDataviews {
private _source: string;
private _mapClient: Maps;
private _mapClient: Client;

constructor(source: string, credentials: Credentials) {
this._source = source;
this._mapClient = new Maps(credentials);
this._mapClient = new Client(credentials);
}

public async aggregation(
params: AggregationParameters
): Promise<AggregationResponse> {
public async aggregation(params: AggregationParameters): Promise<AggregationResponse> {
const { column, aggregation, operationColumn, limit } = params;

const dataviewName = `${this._source}_${Date.now()}`;
Expand All @@ -38,7 +36,7 @@ export class MapsDataviews {
aggregation: AggregationType,
operationColumn?: string
) {
const sourceMapConfig = Maps.generateMapConfigFromSource(this._source);
const sourceMapConfig = Client.generateMapConfigFromSource(this._source);
const sourceId = sourceMapConfig.analyses[0].id;
const mapConfig = {
...sourceMapConfig,
Expand Down Expand Up @@ -70,6 +68,7 @@ export interface AggregationResponse {
aggregation: AggregationType;
categoriesCount: number;
categories: AggregationCategory[];
// eslint-disable-next-line camelcase
errors_with_context?: { type: string; message: string }[];
errors?: string[];
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/maps/__tests__/Client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Credentials } from '@carto/toolkit-core';
import { MapOptions, Maps as Client } from '../src/Client';
import { Credentials } from '../../core/Credentials';
import { MapOptions, Client } from '../Client';

describe('maps', () => {
it('can be easily created', () => {
Expand Down

0 comments on commit 84ec830

Please sign in to comment.