@carto/api-client 0.5.0-alpha.14 → 0.5.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,6 @@ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
22
22
  import {WidgetSource, WidgetSourceProps} from './widget-source.js';
23
23
  import {Filters} from '../types.js';
24
24
  import {ApiVersion} from '../constants.js';
25
- import {AggregationOptions} from '../sources/types.js';
26
25
 
27
26
  export type WidgetRemoteSourceProps = WidgetSourceProps;
28
27
 
@@ -60,7 +59,6 @@ export abstract class WidgetRemoteSource<
60
59
  filtersLogicalOperator: props.filtersLogicalOperator,
61
60
  spatialDataType: props.spatialDataType,
62
61
  spatialDataColumn: props.spatialDataColumn,
63
- dataResolution: (props as Partial<AggregationOptions>).dataResolution,
64
62
  };
65
63
  }
66
64
 
@@ -73,24 +71,16 @@ export abstract class WidgetRemoteSource<
73
71
  filterOwner,
74
72
  spatialFilter,
75
73
  spatialFiltersMode,
76
- spatialIndexReferenceViewState,
77
74
  ...params
78
75
  } = options;
79
76
  const {column, operation, operationColumn} = params;
80
- const source = this.getModelSource(filters, filterOwner);
81
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
82
- source,
83
- spatialFilter,
84
- spatialIndexReferenceViewState
85
- );
86
77
 
87
78
  type CategoriesModelResponse = {rows: {name: string; value: number}[]};
88
79
 
89
80
  return executeModel({
90
81
  model: 'category',
91
82
  source: {
92
- ...source,
93
- spatialFiltersResolution,
83
+ ...this.getModelSource(filters, filterOwner),
94
84
  spatialFiltersMode,
95
85
  spatialFilter,
96
86
  },
@@ -112,24 +102,16 @@ export abstract class WidgetRemoteSource<
112
102
  filterOwner,
113
103
  spatialFilter,
114
104
  spatialFiltersMode,
115
- spatialIndexReferenceViewState,
116
105
  ...params
117
106
  } = options;
118
107
  const {columns, dataType, featureIds, z, limit, tileResolution} = params;
119
- const source = this.getModelSource(filters, filterOwner);
120
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
121
- source,
122
- spatialFilter,
123
- spatialIndexReferenceViewState
124
- );
125
108
 
126
109
  type FeaturesModelResponse = {rows: Record<string, unknown>[]};
127
110
 
128
111
  return executeModel({
129
112
  model: 'pick',
130
113
  source: {
131
- ...source,
132
- spatialFiltersResolution,
114
+ ...this.getModelSource(filters, filterOwner),
133
115
  spatialFiltersMode,
134
116
  spatialFilter,
135
117
  },
@@ -153,25 +135,17 @@ export abstract class WidgetRemoteSource<
153
135
  filterOwner,
154
136
  spatialFilter,
155
137
  spatialFiltersMode,
156
- spatialIndexReferenceViewState,
157
138
  operationExp,
158
139
  ...params
159
140
  } = options;
160
141
  const {column, operation} = params;
161
- const source = this.getModelSource(filters, filterOwner);
162
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
163
- source,
164
- spatialFilter,
165
- spatialIndexReferenceViewState
166
- );
167
142
 
168
143
  type FormulaModelResponse = {rows: {value: number}[]};
169
144
 
170
145
  return executeModel({
171
146
  model: 'formula',
172
147
  source: {
173
- ...source,
174
- spatialFiltersResolution,
148
+ ...this.getModelSource(filters, filterOwner),
175
149
  spatialFiltersMode,
176
150
  spatialFilter,
177
151
  },
@@ -193,24 +167,16 @@ export abstract class WidgetRemoteSource<
193
167
  filterOwner,
194
168
  spatialFilter,
195
169
  spatialFiltersMode,
196
- spatialIndexReferenceViewState,
197
170
  ...params
198
171
  } = options;
199
172
  const {column, operation, ticks} = params;
200
- const source = this.getModelSource(filters, filterOwner);
201
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
202
- source,
203
- spatialFilter,
204
- spatialIndexReferenceViewState
205
- );
206
173
 
207
174
  type HistogramModelResponse = {rows: {tick: number; value: number}[]};
208
175
 
209
176
  const data = await executeModel({
210
177
  model: 'histogram',
211
178
  source: {
212
- ...source,
213
- spatialFiltersResolution,
179
+ ...this.getModelSource(filters, filterOwner),
214
180
  spatialFiltersMode,
215
181
  spatialFilter,
216
182
  },
@@ -238,24 +204,16 @@ export abstract class WidgetRemoteSource<
238
204
  filterOwner,
239
205
  spatialFilter,
240
206
  spatialFiltersMode,
241
- spatialIndexReferenceViewState,
242
207
  ...params
243
208
  } = options;
244
209
  const {column} = params;
245
- const source = this.getModelSource(filters, filterOwner);
246
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
247
- source,
248
- spatialFilter,
249
- spatialIndexReferenceViewState
250
- );
251
210
 
252
211
  type RangeModelResponse = {rows: {min: number; max: number}[]};
253
212
 
254
213
  return executeModel({
255
214
  model: 'range',
256
215
  source: {
257
- ...source,
258
- spatialFiltersResolution,
216
+ ...this.getModelSource(filters, filterOwner),
259
217
  spatialFiltersMode,
260
218
  spatialFilter,
261
219
  },
@@ -271,19 +229,11 @@ export abstract class WidgetRemoteSource<
271
229
  filterOwner,
272
230
  spatialFilter,
273
231
  spatialFiltersMode,
274
- spatialIndexReferenceViewState,
275
232
  ...params
276
233
  } = options;
277
234
  const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
278
235
  params;
279
236
 
280
- const source = this.getModelSource(filters, filterOwner);
281
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
282
- source,
283
- spatialFilter,
284
- spatialIndexReferenceViewState
285
- );
286
-
287
237
  // Make sure this is sync with the same constant in cloud-native/maps-api
288
238
  const HARD_LIMIT = 500;
289
239
 
@@ -292,8 +242,7 @@ export abstract class WidgetRemoteSource<
292
242
  return executeModel({
293
243
  model: 'scatterplot',
294
244
  source: {
295
- ...source,
296
- spatialFiltersResolution,
245
+ ...this.getModelSource(filters, filterOwner),
297
246
  spatialFiltersMode,
298
247
  spatialFilter,
299
248
  },
@@ -317,16 +266,9 @@ export abstract class WidgetRemoteSource<
317
266
  filterOwner,
318
267
  spatialFilter,
319
268
  spatialFiltersMode,
320
- spatialIndexReferenceViewState,
321
269
  ...params
322
270
  } = options;
323
271
  const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
324
- const source = this.getModelSource(filters, filterOwner);
325
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
326
- source,
327
- spatialFilter,
328
- spatialIndexReferenceViewState
329
- );
330
272
 
331
273
  type TableModelResponse = {
332
274
  rows: Record<string, number | string>[];
@@ -336,8 +278,7 @@ export abstract class WidgetRemoteSource<
336
278
  return executeModel({
337
279
  model: 'table',
338
280
  source: {
339
- ...source,
340
- spatialFiltersResolution,
281
+ ...this.getModelSource(filters, filterOwner),
341
282
  spatialFiltersMode,
342
283
  spatialFilter,
343
284
  },
@@ -365,7 +306,6 @@ export abstract class WidgetRemoteSource<
365
306
  filterOwner,
366
307
  spatialFilter,
367
308
  spatialFiltersMode,
368
- spatialIndexReferenceViewState,
369
309
  ...params
370
310
  } = options;
371
311
  const {
@@ -380,13 +320,6 @@ export abstract class WidgetRemoteSource<
380
320
  splitByCategoryValues,
381
321
  } = params;
382
322
 
383
- const source = this.getModelSource(filters, filterOwner);
384
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
385
- source,
386
- spatialFilter,
387
- spatialIndexReferenceViewState
388
- );
389
-
390
323
  type TimeSeriesModelResponse = {
391
324
  rows: {name: string; value: number}[];
392
325
  metadata: {categories: string[]};
@@ -395,8 +328,7 @@ export abstract class WidgetRemoteSource<
395
328
  return executeModel({
396
329
  model: 'timeseries',
397
330
  source: {
398
- ...source,
399
- spatialFiltersResolution,
331
+ ...this.getModelSource(filters, filterOwner),
400
332
  spatialFiltersMode,
401
333
  spatialFilter,
402
334
  },
@@ -15,14 +15,11 @@ import {
15
15
  TableResponse,
16
16
  TimeSeriesRequestOptions,
17
17
  TimeSeriesResponse,
18
- ViewState,
19
18
  } from './types.js';
20
- import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
19
+ import {FilterLogicalOperator, Filter} from '../types.js';
21
20
  import {getClient} from '../client.js';
22
- import {ModelSource} from '../models/model.js';
23
21
  import {SourceOptions} from '../sources/index.js';
24
22
  import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
25
- import {getSpatialFiltersResolution} from '../spatial-index.js';
26
23
 
27
24
  export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
28
25
  apiVersion?: ApiVersion;
@@ -49,7 +46,11 @@ export abstract class WidgetSource<
49
46
  };
50
47
 
51
48
  constructor(props: Props) {
52
- this.props = {...WidgetSource.defaultProps, ...props};
49
+ this.props = {
50
+ ...WidgetSource.defaultProps,
51
+ clientId: getClient(), // Refresh clientId, default may have changed.
52
+ ...props,
53
+ };
53
54
  }
54
55
 
55
56
  /**
@@ -63,25 +64,6 @@ export abstract class WidgetSource<
63
64
  // no-op in most cases, but required for worker sources.
64
65
  }
65
66
 
66
- protected _getSpatialFiltersResolution(
67
- source: Omit<ModelSource, 'type' | 'data'>,
68
- spatialFilter?: SpatialFilter,
69
- referenceViewState?: ViewState
70
- ): number | undefined {
71
- // spatialFiltersResolution applies only to spatial index sources.
72
- if (!spatialFilter || source.spatialDataType === 'geo') {
73
- return;
74
- }
75
-
76
- if (!referenceViewState) {
77
- throw new Error(
78
- 'Missing required option, "spatialIndexReferenceViewState".'
79
- );
80
- }
81
-
82
- return getSpatialFiltersResolution(source, referenceViewState);
83
- }
84
-
85
67
  /**
86
68
  * Returns a list of labeled datapoints for categorical data. Suitable for
87
69
  * charts including grouped bar charts, pie charts, and tree charts.