@carto/api-client 0.5.2-alpha.1 → 0.5.2

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.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/CartoDB/carto-api-client#readme",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "packageManager": "yarn@4.3.1",
11
- "version": "0.5.2-alpha.1",
11
+ "version": "0.5.2",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -67,7 +67,7 @@
67
67
  "@types/geojson": "^7946.0.16",
68
68
  "d3-format": "^3.1.0",
69
69
  "d3-scale": "^4.0.2",
70
- "h3-js": "4.1.0",
70
+ "h3-js": "4.2.1",
71
71
  "quadbin": "^0.4.1-alpha.0"
72
72
  },
73
73
  "devDependencies": {
@@ -123,11 +123,10 @@
123
123
  "typescript": "~5.8.2",
124
124
  "typescript-eslint": "^8.26.1",
125
125
  "vite": "^6.2.2",
126
- "vitest": "3.1.1"
126
+ "vitest": "3.1.2"
127
127
  },
128
128
  "resolutions": {
129
129
  "@carto/api-client": "portal:./",
130
130
  "rollup": "^4.20.0"
131
- },
132
- "stableVersion": "0.5.1"
131
+ }
133
132
  }
@@ -11,7 +11,6 @@ import {
11
11
  scaleThreshold,
12
12
  } from 'd3-scale';
13
13
  import {format as d3Format} from 'd3-format';
14
- import moment from 'moment-timezone';
15
14
 
16
15
  export type LayerType =
17
16
  | 'clusterTile'
@@ -22,7 +21,12 @@ export type LayerType =
22
21
  | 'raster'
23
22
  | 'tileset';
24
23
 
25
- import {createBinaryProxy, scaleIdentity} from './utils.js';
24
+ import {
25
+ createBinaryProxy,
26
+ formatDate,
27
+ formatTimestamp,
28
+ scaleIdentity,
29
+ } from './utils.js';
26
30
  import type {
27
31
  CustomMarkersRange,
28
32
  Dataset,
@@ -33,6 +37,7 @@ import type {
33
37
  } from './types.js';
34
38
  import type {ProviderType} from '../types.js';
35
39
  import {DEFAULT_AGGREGATION_EXP_ALIAS} from '../constants-internal.js';
40
+ import type {SchemaField} from '../types-internal.js';
36
41
 
37
42
  const SCALE_FUNCS: Record<string, () => any> = {
38
43
  linear: scaleLinear,
@@ -457,10 +462,10 @@ export function getSizeAccessor(
457
462
  }
458
463
 
459
464
  const FORMATS: Record<string, (value: any) => string> = {
460
- date: (s) => moment.utc(s).format('MM/DD/YY HH:mm:ssa'),
465
+ date: formatDate,
461
466
  integer: d3Format('i'),
462
467
  float: d3Format('.5f'),
463
- timestamp: (s) => moment.utc(s).format('X'),
468
+ timestamp: formatTimestamp,
464
469
  default: String,
465
470
  };
466
471
 
@@ -495,11 +500,11 @@ export function calculateClusterRadius(
495
500
  export function getDefaultAggregationExpColumnAliasForLayerType(
496
501
  layerType: LayerType,
497
502
  provider: ProviderType,
498
- columns: string[]
503
+ schema: SchemaField[]
499
504
  ): string {
500
- if (columns && layerType === 'clusterTile') {
505
+ if (schema && layerType === 'clusterTile') {
501
506
  return getColumnAliasForAggregationExp(
502
- getDefaultColumnFromSchemaForAggregationExp(columns),
507
+ getDefaultColumnFromSchemaForAggregationExp(schema),
503
508
  'count',
504
509
  provider
505
510
  );
@@ -520,9 +525,9 @@ function getColumnAliasForAggregationExp(
520
525
 
521
526
  /** @privateRemarks Source: Builder */
522
527
  function getDefaultColumnFromSchemaForAggregationExp(
523
- columns: string[]
528
+ schema: SchemaField[]
524
529
  ): string {
525
- return columns ? columns[0] : '';
530
+ return schema ? schema[0].name : '';
526
531
  }
527
532
 
528
533
  /** @privateRemarks Source: Builder */
@@ -279,7 +279,7 @@ function createChannelProps(
279
279
  const aggregationExpAlias = getDefaultAggregationExpColumnAliasForLayerType(
280
280
  type,
281
281
  dataset.providerId,
282
- dataset.columns
282
+ data.schema
283
283
  );
284
284
 
285
285
  result.pointType = visConfig.isTextVisible ? 'circle+text' : 'circle';
@@ -67,3 +67,21 @@ export function isRemoteCalculationSupported(dataset: Dataset) {
67
67
 
68
68
  return true;
69
69
  }
70
+
71
+ const DATE_FORMATTER = new Intl.DateTimeFormat('en-US', {
72
+ year: '2-digit',
73
+ month: 'numeric',
74
+ day: 'numeric',
75
+ hour: 'numeric',
76
+ minute: 'numeric',
77
+ second: 'numeric',
78
+ timeZone: 'UTC',
79
+ });
80
+
81
+ export function formatDate(value: string | number | Date): string {
82
+ return DATE_FORMATTER.format(new Date(value));
83
+ }
84
+
85
+ export function formatTimestamp(value: string | number | Date): string {
86
+ return String(Math.floor(new Date(value).getTime() / 1000));
87
+ }
@@ -55,7 +55,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
55
55
  type: endpoint,
56
56
  source: JSON.stringify(parameters, undefined, 2),
57
57
  };
58
- const mapInstantiation =
58
+ const {tilejson, schema} =
59
59
  await requestWithParameters<TilejsonMapInstantiation>({
60
60
  baseUrl,
61
61
  parameters,
@@ -65,7 +65,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
65
65
  localCache,
66
66
  });
67
67
 
68
- const dataUrl = mapInstantiation.tilejson.url[0];
68
+ const dataUrl = tilejson.url[0];
69
69
  if (cache) {
70
70
  cache.value = parseInt(
71
71
  new URL(dataUrl).searchParams.get('cache') || '',
@@ -85,5 +85,8 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
85
85
  if (accessToken) {
86
86
  json.accessToken = accessToken;
87
87
  }
88
+ if (schema) {
89
+ json.schema = schema;
90
+ }
88
91
  return json;
89
92
  }
@@ -414,7 +414,11 @@ export type RasterMetadata = {
414
414
  pixel_resolution: number;
415
415
  };
416
416
 
417
- export type TilejsonResult = Tilejson & {accessToken: string};
417
+ export type TilejsonResult = Tilejson & {
418
+ accessToken: string;
419
+ schema: SchemaField[];
420
+ };
421
+
418
422
  export type QueryResult = {
419
423
  meta: {cacheHit: boolean; location: string; totalBytesProcessed: string};
420
424
  rows: Record<string, any>[];