@carto/api-client 0.0.1-0 → 0.0.1-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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0
4
+
5
+ ### 0.0.1 (UNRELEASED)
6
+
7
+ - Initial release
package/README.md CHANGED
@@ -1,24 +1,136 @@
1
1
  # `@carto/api-client`
2
2
 
3
- ## References
3
+ WORK IN PROGRESS.
4
4
 
5
- - [Product feature brief](https://docs.google.com/document/d/1ZWiVB_rgXf1WAEF1TjJgEHxp92kREYQrWG3O8jYV0Zk/edit)
6
- - [Architecture document](https://app.shortcut.com/cartoteam/write/IkRvYyI6I3V1aWQgIjY2MzE1NDU0LTIyZTAtNDI4YS04NzMzLTc3YzZjN2I2MjVjYSI=?commentId=e509d33c6cdedf90599a5d3a937336d8e&commentThreadId=e7dbf03c9bd7b0fd3de40ebacbea67ee9)
5
+ ## Installation
7
6
 
8
- ## Quickstart
7
+ Install `@carto/api-client`:
9
8
 
10
9
  ```bash
11
- # install dependencies
12
- yarn
10
+ npm install --save @carto/api-client
11
+ ```
12
+
13
+ ## Documentation
14
+
15
+ WORK IN PROGRESS.
16
+
17
+ ### Fetching data
18
+
19
+ Import `vectorTableSource`, `vectorQuerySource`, and other data source functions
20
+ from the `@carto/api-client` package. These are drop-in replacements for the equivalent functions from the `@deck.gl/carto` package, and the same data source may be used with any number of layers or widgets. Tileset sources are not yet supported.
21
+
22
+ ```javascript
23
+ import { vectorTableSource } from '@carto/api-client';
24
+
25
+ const data = vectorTableSource({
26
+ accessToken: '••••',
27
+ connectionName: 'carto_dw',
28
+ tableName: 'carto-demo-data.demo_tables.retail_stores'
29
+ });
30
+
31
+ const { widgetSource } = await data;
32
+
33
+ // → {name: string; value: number}[]
34
+ const categories = await widgetSource.getCategories({
35
+ column: 'store_type',
36
+ operation: 'count',
37
+ });
38
+
39
+ // → {value: number}
40
+ const formula = await widgetSource.getFormula({operation: 'count'});
41
+
42
+ // → {totalCount: number; rows: Record<string, number | string>[]}
43
+ const table = await widgetSource.getTable({
44
+ columns: ['a', 'b', 'c'],
45
+ sortBy: ['a'],
46
+ rowsPerPage: 20
47
+ });
48
+
49
+ ...
50
+ ```
51
+
52
+ ### Column filter
13
53
 
14
- # build package once
15
- yarn build
54
+ To filter the widget source by a non-geospatial column, pass a `filters`
55
+ property to the source factory function.
16
56
 
17
- # build package and watch for changes
18
- yarn build --watch
57
+ ```javascript
58
+ import {vectorTableSource} from '@carto/api-client';
19
59
 
20
- # build package, watch for changes, and start a local server for examples
21
- yarn dev
60
+ const data = vectorTableSource({
61
+ accessToken: '••••',
62
+ connectionName: 'carto_dw',
63
+ tableName: 'carto-demo-data.demo_tables.retail_stores',
64
+ filters: {
65
+ store_type: {owner: 'widget-id', values: ['retail']},
66
+ },
67
+ });
22
68
  ```
23
69
 
24
- After running `yarn dev`, a browser window should open with links to examples. Unless a different port number is required, the local URL will be `localhost:5173`.
70
+ By default, filters affect all layers and widgets using a given data source. To
71
+ exclude a particular widget from the filter, pass a `filterOwner` parameter
72
+ matching the filters from which it should be excluded. In some cases, a widget's
73
+ results should not be affected by a filter that the widget itself created.
74
+
75
+ ```javascript
76
+ // → {name: string; value: number}[]
77
+ const categories = await widgetSource.getCategories({
78
+ filterOwner: 'widget-id',
79
+ column: 'store_type',
80
+ operation: 'count',
81
+ });
82
+ ```
83
+
84
+ ### Spatial filter
85
+
86
+ To filter the widget source to a spatial region, pass a `spatialFilter` parameter (GeoJSON Polygon or MultiPolygon geometry) to any data fetching function.
87
+
88
+ ```javascript
89
+ // → {name: string; value: number}[]
90
+ const categories = await widgetSource.getCategories({
91
+ column: 'store_type',
92
+ operation: 'count',
93
+ spatialFilter: {
94
+ type: "Polygon"
95
+ coordinates: [
96
+ [
97
+ [-74.0562, 40.8331],
98
+ [-74.0562, 40.6933],
99
+ [-73.8734, 40.6933],
100
+ [-73.8734, 40.8331],
101
+ [-74.0562, 40.8331]
102
+ ]
103
+ ],
104
+ }
105
+ });
106
+ ```
107
+
108
+ To create a spatial filter from the current [deck.gl `viewState`](https://deck.gl/docs/developer-guide/views#using-a-view-with-view-state):
109
+
110
+ ```javascript
111
+ import {WebMercatorViewport} from '@deck.gl/core';
112
+
113
+ function createViewStatePolygon(viewState) {
114
+ const viewport = new WebMercatorViewport(viewState);
115
+ return {
116
+ type: 'Polygon',
117
+ coordinates: [
118
+ [
119
+ viewport.unproject([0, 0]),
120
+ viewport.unproject([viewport.width, 0]),
121
+ viewport.unproject([viewport.width, viewport.height]),
122
+ viewport.unproject([0, viewport.height]),
123
+ viewport.unproject([0, 0]),
124
+ ],
125
+ ],
126
+ };
127
+ }
128
+ ```
129
+
130
+ ## Versioning
131
+
132
+ Package versioning follows [Semantic Versioning 2.0.0](https://semver.org/).
133
+
134
+ ## License
135
+
136
+ UNLICENSED. WORK IN PROGRESS.