@deck.gl/carto 8.10.0-alpha.7 → 9.0.0-alpha.3

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.
Files changed (365) hide show
  1. package/dist/cartoRasterTile-worker.js +32 -24
  2. package/dist/cartoSpatialTile-worker.js +32 -24
  3. package/dist/cartoVectorTile-worker.js +69 -63
  4. package/dist/dist.dev.js +12055 -12562
  5. package/dist/es5/api/carto-api-error.js.map +1 -1
  6. package/dist/es5/api/common.js +25 -0
  7. package/dist/es5/api/common.js.map +1 -0
  8. package/dist/es5/api/endpoints.js +40 -0
  9. package/dist/es5/api/endpoints.js.map +1 -0
  10. package/dist/es5/api/fetch-map.js +560 -0
  11. package/dist/es5/api/fetch-map.js.map +1 -0
  12. package/dist/es5/api/index.js +5 -49
  13. package/dist/es5/api/index.js.map +1 -1
  14. package/dist/es5/api/layer-map.js +43 -45
  15. package/dist/es5/api/layer-map.js.map +1 -1
  16. package/dist/es5/api/{parseMap.js → parse-map.js} +5 -3
  17. package/dist/es5/api/parse-map.js.map +1 -0
  18. package/dist/es5/api/query.js +78 -0
  19. package/dist/es5/api/query.js.map +1 -0
  20. package/dist/es5/{sources/utils.js → api/request-with-parameters.js} +60 -46
  21. package/dist/es5/api/request-with-parameters.js.map +1 -0
  22. package/dist/es5/api/types.js +19 -0
  23. package/dist/es5/api/types.js.map +1 -1
  24. package/dist/es5/index.js +66 -80
  25. package/dist/es5/index.js.map +1 -1
  26. package/dist/es5/layers/h3-tile-layer.js +3 -5
  27. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  28. package/dist/es5/layers/point-label-layer.js.map +1 -1
  29. package/dist/es5/layers/quadbin-layer.js.map +1 -1
  30. package/dist/es5/layers/quadbin-tile-layer.js +1 -4
  31. package/dist/es5/layers/quadbin-tile-layer.js.map +1 -1
  32. package/dist/es5/layers/raster-layer.js +2 -0
  33. package/dist/es5/layers/raster-layer.js.map +1 -1
  34. package/dist/es5/layers/raster-tile-layer.js +1 -3
  35. package/dist/es5/layers/raster-tile-layer.js.map +1 -1
  36. package/dist/es5/layers/schema/carto-properties-tile-loader.js +60 -0
  37. package/dist/es5/layers/schema/carto-properties-tile-loader.js.map +1 -0
  38. package/dist/es5/layers/schema/carto-properties-tile.js +38 -0
  39. package/dist/es5/layers/schema/carto-properties-tile.js.map +1 -0
  40. package/dist/es5/layers/schema/carto-raster-tile-loader.js +1 -1
  41. package/dist/es5/layers/schema/carto-raster-tile-loader.js.map +1 -1
  42. package/dist/es5/layers/schema/carto-spatial-tile-loader.js +1 -1
  43. package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  44. package/dist/es5/layers/schema/carto-vector-tile-loader.js +1 -2
  45. package/dist/es5/layers/schema/carto-vector-tile-loader.js.map +1 -1
  46. package/dist/es5/layers/spatial-index-tile-layer.js +16 -26
  47. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  48. package/dist/es5/layers/utils.js +102 -0
  49. package/dist/es5/layers/utils.js.map +1 -1
  50. package/dist/es5/layers/vector-tile-layer.js +112 -27
  51. package/dist/es5/layers/vector-tile-layer.js.map +1 -1
  52. package/dist/es5/sources/base-source.js +56 -28
  53. package/dist/es5/sources/base-source.js.map +1 -1
  54. package/dist/es5/sources/boundary-query-source.js +51 -0
  55. package/dist/es5/sources/boundary-query-source.js.map +1 -0
  56. package/dist/es5/sources/boundary-table-source.js +51 -0
  57. package/dist/es5/sources/boundary-table-source.js.map +1 -0
  58. package/dist/es5/sources/boundary-tileset-source.js +43 -0
  59. package/dist/es5/sources/boundary-tileset-source.js.map +1 -0
  60. package/dist/es5/sources/h3-query-source.js +9 -11
  61. package/dist/es5/sources/h3-query-source.js.map +1 -1
  62. package/dist/es5/sources/h3-table-source.js +10 -12
  63. package/dist/es5/sources/h3-table-source.js.map +1 -1
  64. package/dist/es5/sources/h3-tileset-source.js +5 -5
  65. package/dist/es5/sources/h3-tileset-source.js.map +1 -1
  66. package/dist/es5/sources/index.js +46 -22
  67. package/dist/es5/sources/index.js.map +1 -1
  68. package/dist/es5/sources/quadbin-query-source.js +10 -12
  69. package/dist/es5/sources/quadbin-query-source.js.map +1 -1
  70. package/dist/es5/sources/quadbin-table-source.js +10 -12
  71. package/dist/es5/sources/quadbin-table-source.js.map +1 -1
  72. package/dist/es5/sources/quadbin-tileset-source.js +5 -5
  73. package/dist/es5/sources/quadbin-tileset-source.js.map +1 -1
  74. package/dist/es5/sources/raster-source.js +5 -5
  75. package/dist/es5/sources/raster-source.js.map +1 -1
  76. package/dist/es5/sources/types.js +2 -0
  77. package/dist/es5/sources/types.js.map +1 -0
  78. package/dist/es5/sources/vector-query-source.js +11 -12
  79. package/dist/es5/sources/vector-query-source.js.map +1 -1
  80. package/dist/es5/sources/vector-table-source.js +12 -13
  81. package/dist/es5/sources/vector-table-source.js.map +1 -1
  82. package/dist/es5/sources/vector-tileset-source.js +5 -5
  83. package/dist/es5/sources/vector-tileset-source.js.map +1 -1
  84. package/dist/es5/style/color-bins-style.js +4 -2
  85. package/dist/es5/style/color-bins-style.js.map +1 -1
  86. package/dist/es5/style/color-categories-style.js +4 -2
  87. package/dist/es5/style/color-categories-style.js.map +1 -1
  88. package/dist/es5/style/color-continuous-style.js +4 -2
  89. package/dist/es5/style/color-continuous-style.js.map +1 -1
  90. package/dist/es5/style/palette.js +1 -1
  91. package/dist/es5/style/palette.js.map +1 -1
  92. package/dist/es5/style/utils.js +4 -11
  93. package/dist/es5/style/utils.js.map +1 -1
  94. package/dist/es5/utils.js +30 -1
  95. package/dist/es5/utils.js.map +1 -1
  96. package/dist/esm/api/carto-api-error.js.map +1 -1
  97. package/dist/esm/api/common.js +13 -0
  98. package/dist/esm/api/common.js.map +1 -0
  99. package/dist/esm/api/endpoints.js +28 -0
  100. package/dist/esm/api/endpoints.js.map +1 -0
  101. package/dist/esm/api/fetch-map.js +291 -0
  102. package/dist/esm/api/fetch-map.js.map +1 -0
  103. package/dist/esm/api/index.js +2 -3
  104. package/dist/esm/api/index.js.map +1 -1
  105. package/dist/esm/api/layer-map.js +43 -35
  106. package/dist/esm/api/layer-map.js.map +1 -1
  107. package/dist/esm/api/{parseMap.js → parse-map.js} +3 -2
  108. package/dist/esm/api/parse-map.js.map +1 -0
  109. package/dist/esm/api/query.js +38 -0
  110. package/dist/esm/api/query.js.map +1 -0
  111. package/dist/esm/{sources/utils.js → api/request-with-parameters.js} +25 -12
  112. package/dist/esm/api/request-with-parameters.js.map +1 -0
  113. package/dist/esm/api/types.js +13 -1
  114. package/dist/esm/api/types.js.map +1 -1
  115. package/dist/esm/index.js +31 -9
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/layers/h3-tile-layer.js +2 -6
  118. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  119. package/dist/esm/layers/point-label-layer.js.map +1 -1
  120. package/dist/esm/layers/quadbin-layer.js.map +1 -1
  121. package/dist/esm/layers/quadbin-tile-layer.js +1 -3
  122. package/dist/esm/layers/quadbin-tile-layer.js.map +1 -1
  123. package/dist/esm/layers/raster-layer.js +1 -0
  124. package/dist/esm/layers/raster-layer.js.map +1 -1
  125. package/dist/esm/layers/raster-tile-layer.js +1 -2
  126. package/dist/esm/layers/raster-tile-layer.js.map +1 -1
  127. package/dist/esm/layers/schema/carto-properties-tile-loader.js +23 -0
  128. package/dist/esm/layers/schema/carto-properties-tile-loader.js.map +1 -0
  129. package/dist/esm/layers/schema/carto-properties-tile.js +18 -0
  130. package/dist/esm/layers/schema/carto-properties-tile.js.map +1 -0
  131. package/dist/esm/layers/schema/carto-raster-tile-loader.js +1 -1
  132. package/dist/esm/layers/schema/carto-raster-tile-loader.js.map +1 -1
  133. package/dist/esm/layers/schema/carto-spatial-tile-loader.js +1 -1
  134. package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  135. package/dist/esm/layers/schema/carto-vector-tile-loader.js +1 -2
  136. package/dist/esm/layers/schema/carto-vector-tile-loader.js.map +1 -1
  137. package/dist/esm/layers/spatial-index-tile-layer.js +9 -24
  138. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  139. package/dist/esm/layers/utils.js +70 -0
  140. package/dist/esm/layers/utils.js.map +1 -1
  141. package/dist/esm/layers/vector-tile-layer.js +40 -12
  142. package/dist/esm/layers/vector-tile-layer.js.map +1 -1
  143. package/dist/esm/sources/base-source.js +33 -10
  144. package/dist/esm/sources/base-source.js.map +1 -1
  145. package/dist/esm/sources/boundary-query-source.js +21 -0
  146. package/dist/esm/sources/boundary-query-source.js.map +1 -0
  147. package/dist/esm/sources/boundary-table-source.js +21 -0
  148. package/dist/esm/sources/boundary-table-source.js.map +1 -0
  149. package/dist/esm/sources/boundary-tileset-source.js +11 -0
  150. package/dist/esm/sources/boundary-tileset-source.js.map +1 -0
  151. package/dist/esm/sources/h3-query-source.js +6 -11
  152. package/dist/esm/sources/h3-query-source.js.map +1 -1
  153. package/dist/esm/sources/h3-table-source.js +7 -12
  154. package/dist/esm/sources/h3-table-source.js.map +1 -1
  155. package/dist/esm/sources/h3-tileset-source.js +3 -6
  156. package/dist/esm/sources/h3-tileset-source.js.map +1 -1
  157. package/dist/esm/sources/index.js +14 -11
  158. package/dist/esm/sources/index.js.map +1 -1
  159. package/dist/esm/sources/quadbin-query-source.js +7 -12
  160. package/dist/esm/sources/quadbin-query-source.js.map +1 -1
  161. package/dist/esm/sources/quadbin-table-source.js +7 -12
  162. package/dist/esm/sources/quadbin-table-source.js.map +1 -1
  163. package/dist/esm/sources/quadbin-tileset-source.js +3 -6
  164. package/dist/esm/sources/quadbin-tileset-source.js.map +1 -1
  165. package/dist/esm/sources/raster-source.js +3 -6
  166. package/dist/esm/sources/raster-source.js.map +1 -1
  167. package/dist/esm/sources/types.js +2 -0
  168. package/dist/esm/sources/types.js.map +1 -0
  169. package/dist/esm/sources/vector-query-source.js +6 -11
  170. package/dist/esm/sources/vector-query-source.js.map +1 -1
  171. package/dist/esm/sources/vector-table-source.js +7 -12
  172. package/dist/esm/sources/vector-table-source.js.map +1 -1
  173. package/dist/esm/sources/vector-tileset-source.js +3 -6
  174. package/dist/esm/sources/vector-tileset-source.js.map +1 -1
  175. package/dist/esm/style/color-bins-style.js +2 -1
  176. package/dist/esm/style/color-bins-style.js.map +1 -1
  177. package/dist/esm/style/color-categories-style.js +2 -1
  178. package/dist/esm/style/color-categories-style.js.map +1 -1
  179. package/dist/esm/style/color-continuous-style.js +2 -1
  180. package/dist/esm/style/color-continuous-style.js.map +1 -1
  181. package/dist/esm/style/palette.js +1 -1
  182. package/dist/esm/style/palette.js.map +1 -1
  183. package/dist/esm/style/utils.js +1 -5
  184. package/dist/esm/style/utils.js.map +1 -1
  185. package/dist/esm/utils.js +24 -1
  186. package/dist/esm/utils.js.map +1 -1
  187. package/dist.min.js +42 -41
  188. package/package.json +10 -9
  189. package/src/.DS_Store +0 -0
  190. package/src/api/carto-api-error.ts +1 -9
  191. package/src/api/common.ts +14 -0
  192. package/src/api/endpoints.ts +38 -0
  193. package/src/api/fetch-map.ts +287 -0
  194. package/src/api/index.ts +5 -5
  195. package/src/api/layer-map.ts +40 -36
  196. package/src/api/{parseMap.ts → parse-map.ts} +2 -2
  197. package/src/api/query.ts +34 -0
  198. package/src/{sources/utils.ts → api/request-with-parameters.ts} +22 -17
  199. package/src/api/types.ts +49 -0
  200. package/src/index.ts +93 -41
  201. package/src/layers/h3-tile-layer.ts +13 -18
  202. package/src/layers/point-label-layer.ts +1 -1
  203. package/src/layers/quadbin-layer.ts +3 -2
  204. package/src/layers/quadbin-tile-layer.ts +10 -11
  205. package/src/layers/raster-layer.ts +2 -2
  206. package/src/layers/raster-tile-layer.ts +11 -9
  207. package/src/layers/schema/carto-properties-tile-loader.ts +25 -0
  208. package/src/layers/schema/carto-properties-tile.ts +21 -0
  209. package/src/layers/schema/carto-vector-tile-loader.ts +1 -1
  210. package/src/layers/spatial-index-tile-layer.ts +18 -26
  211. package/src/layers/utils.ts +71 -0
  212. package/src/layers/vector-tile-layer.ts +40 -21
  213. package/src/sources/base-source.ts +35 -18
  214. package/src/sources/boundary-query-source.ts +31 -0
  215. package/src/sources/boundary-table-source.ts +31 -0
  216. package/src/sources/boundary-tileset-source.ts +14 -0
  217. package/src/sources/h3-query-source.ts +22 -22
  218. package/src/sources/h3-table-source.ts +22 -22
  219. package/src/sources/h3-tileset-source.ts +7 -9
  220. package/src/sources/index.ts +31 -22
  221. package/src/sources/quadbin-query-source.ts +22 -22
  222. package/src/sources/quadbin-table-source.ts +23 -22
  223. package/src/sources/quadbin-tileset-source.ts +7 -9
  224. package/src/sources/raster-source.ts +5 -9
  225. package/src/sources/types.ts +98 -0
  226. package/src/sources/vector-query-source.ts +15 -15
  227. package/src/sources/vector-table-source.ts +15 -15
  228. package/src/sources/vector-tileset-source.ts +7 -9
  229. package/src/style/color-bins-style.ts +2 -1
  230. package/src/style/color-categories-style.ts +2 -1
  231. package/src/style/color-continuous-style.ts +2 -1
  232. package/src/style/palette.ts +1 -1
  233. package/src/style/utils.ts +1 -6
  234. package/src/utils.ts +25 -1
  235. package/typed/api/carto-api-error.d.ts +1 -8
  236. package/typed/api/carto-api-error.d.ts.map +1 -1
  237. package/typed/api/common.d.ts +13 -0
  238. package/typed/api/common.d.ts.map +1 -0
  239. package/typed/api/endpoints.d.ts +12 -0
  240. package/typed/api/endpoints.d.ts.map +1 -0
  241. package/typed/api/fetch-map.d.ts +22 -0
  242. package/typed/api/fetch-map.d.ts.map +1 -0
  243. package/typed/api/index.d.ts +5 -5
  244. package/typed/api/index.d.ts.map +1 -1
  245. package/typed/api/layer-map.d.ts +6 -9
  246. package/typed/api/layer-map.d.ts.map +1 -1
  247. package/typed/api/{parseMap.d.ts → parse-map.d.ts} +1 -1
  248. package/typed/api/parse-map.d.ts.map +1 -0
  249. package/typed/api/query.d.ts +4 -0
  250. package/typed/api/query.d.ts.map +1 -0
  251. package/typed/api/request-with-parameters.d.ts +9 -0
  252. package/typed/api/request-with-parameters.d.ts.map +1 -0
  253. package/typed/api/types.d.ts +40 -0
  254. package/typed/api/types.d.ts.map +1 -1
  255. package/typed/index.d.ts +33 -12
  256. package/typed/index.d.ts.map +1 -1
  257. package/typed/layers/h3-tile-layer.d.ts +12 -7
  258. package/typed/layers/h3-tile-layer.d.ts.map +1 -1
  259. package/typed/layers/point-label-layer.d.ts +2 -2
  260. package/typed/layers/point-label-layer.d.ts.map +1 -1
  261. package/typed/layers/quadbin-layer.d.ts +2 -2
  262. package/typed/layers/quadbin-layer.d.ts.map +1 -1
  263. package/typed/layers/quadbin-tile-layer.d.ts +6 -6
  264. package/typed/layers/quadbin-tile-layer.d.ts.map +1 -1
  265. package/typed/layers/raster-layer.d.ts +2 -2
  266. package/typed/layers/raster-layer.d.ts.map +1 -1
  267. package/typed/layers/raster-tile-layer.d.ts +6 -5
  268. package/typed/layers/raster-tile-layer.d.ts.map +1 -1
  269. package/typed/layers/schema/carto-properties-tile-loader.d.ts +4 -0
  270. package/typed/layers/schema/carto-properties-tile-loader.d.ts.map +1 -0
  271. package/typed/layers/schema/carto-properties-tile.d.ts +10 -0
  272. package/typed/layers/schema/carto-properties-tile.d.ts.map +1 -0
  273. package/typed/layers/spatial-index-tile-layer.d.ts +10 -9
  274. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
  275. package/typed/layers/utils.d.ts +11 -0
  276. package/typed/layers/utils.d.ts.map +1 -1
  277. package/typed/layers/vector-tile-layer.d.ts +6 -11
  278. package/typed/layers/vector-tile-layer.d.ts.map +1 -1
  279. package/typed/sources/base-source.d.ts +4 -3
  280. package/typed/sources/base-source.d.ts.map +1 -1
  281. package/typed/sources/boundary-query-source.d.ts +10 -0
  282. package/typed/sources/boundary-query-source.d.ts.map +1 -0
  283. package/typed/sources/boundary-table-source.d.ts +9 -0
  284. package/typed/sources/boundary-table-source.d.ts.map +1 -0
  285. package/typed/sources/boundary-tileset-source.d.ts +6 -0
  286. package/typed/sources/boundary-tileset-source.d.ts.map +1 -0
  287. package/typed/sources/h3-query-source.d.ts +3 -4
  288. package/typed/sources/h3-query-source.d.ts.map +1 -1
  289. package/typed/sources/h3-table-source.d.ts +3 -4
  290. package/typed/sources/h3-table-source.d.ts.map +1 -1
  291. package/typed/sources/h3-tileset-source.d.ts +3 -4
  292. package/typed/sources/h3-tileset-source.d.ts.map +1 -1
  293. package/typed/sources/index.d.ts +28 -22
  294. package/typed/sources/index.d.ts.map +1 -1
  295. package/typed/sources/quadbin-query-source.d.ts +3 -4
  296. package/typed/sources/quadbin-query-source.d.ts.map +1 -1
  297. package/typed/sources/quadbin-table-source.d.ts +3 -4
  298. package/typed/sources/quadbin-table-source.d.ts.map +1 -1
  299. package/typed/sources/quadbin-tileset-source.d.ts +3 -4
  300. package/typed/sources/quadbin-tileset-source.d.ts.map +1 -1
  301. package/typed/sources/raster-source.d.ts +3 -4
  302. package/typed/sources/raster-source.d.ts.map +1 -1
  303. package/typed/sources/{common.d.ts → types.d.ts} +26 -42
  304. package/typed/sources/types.d.ts.map +1 -0
  305. package/typed/sources/vector-query-source.d.ts +3 -4
  306. package/typed/sources/vector-query-source.d.ts.map +1 -1
  307. package/typed/sources/vector-table-source.d.ts +3 -4
  308. package/typed/sources/vector-table-source.d.ts.map +1 -1
  309. package/typed/sources/vector-tileset-source.d.ts +3 -4
  310. package/typed/sources/vector-tileset-source.d.ts.map +1 -1
  311. package/typed/style/color-bins-style.d.ts.map +1 -1
  312. package/typed/style/color-categories-style.d.ts.map +1 -1
  313. package/typed/style/color-continuous-style.d.ts.map +1 -1
  314. package/typed/style/utils.d.ts +0 -1
  315. package/typed/style/utils.d.ts.map +1 -1
  316. package/typed/utils.d.ts +8 -0
  317. package/typed/utils.d.ts.map +1 -1
  318. package/dist/es5/api/maps-api-common.js +0 -77
  319. package/dist/es5/api/maps-api-common.js.map +0 -1
  320. package/dist/es5/api/maps-client.js +0 -220
  321. package/dist/es5/api/maps-client.js.map +0 -1
  322. package/dist/es5/api/maps-v3-client.js +0 -959
  323. package/dist/es5/api/maps-v3-client.js.map +0 -1
  324. package/dist/es5/api/parseMap.js.map +0 -1
  325. package/dist/es5/config.js +0 -84
  326. package/dist/es5/config.js.map +0 -1
  327. package/dist/es5/layers/carto-layer.js +0 -329
  328. package/dist/es5/layers/carto-layer.js.map +0 -1
  329. package/dist/es5/sources/common.js +0 -48
  330. package/dist/es5/sources/common.js.map +0 -1
  331. package/dist/es5/sources/utils.js.map +0 -1
  332. package/dist/esm/api/maps-api-common.js +0 -54
  333. package/dist/esm/api/maps-api-common.js.map +0 -1
  334. package/dist/esm/api/maps-client.js +0 -148
  335. package/dist/esm/api/maps-client.js.map +0 -1
  336. package/dist/esm/api/maps-v3-client.js +0 -638
  337. package/dist/esm/api/maps-v3-client.js.map +0 -1
  338. package/dist/esm/api/parseMap.js.map +0 -1
  339. package/dist/esm/config.js +0 -60
  340. package/dist/esm/config.js.map +0 -1
  341. package/dist/esm/layers/carto-layer.js +0 -233
  342. package/dist/esm/layers/carto-layer.js.map +0 -1
  343. package/dist/esm/sources/common.js +0 -26
  344. package/dist/esm/sources/common.js.map +0 -1
  345. package/dist/esm/sources/utils.js.map +0 -1
  346. package/src/api/maps-api-common.ts +0 -95
  347. package/src/api/maps-client.ts +0 -196
  348. package/src/api/maps-v3-client.ts +0 -659
  349. package/src/config.ts +0 -70
  350. package/src/layers/carto-layer.ts +0 -340
  351. package/src/sources/common.ts +0 -132
  352. package/typed/api/maps-api-common.d.ts +0 -76
  353. package/typed/api/maps-api-common.d.ts.map +0 -1
  354. package/typed/api/maps-client.d.ts +0 -18
  355. package/typed/api/maps-client.d.ts.map +0 -1
  356. package/typed/api/maps-v3-client.d.ts +0 -49
  357. package/typed/api/maps-v3-client.d.ts.map +0 -1
  358. package/typed/api/parseMap.d.ts.map +0 -1
  359. package/typed/config.d.ts +0 -28
  360. package/typed/config.d.ts.map +0 -1
  361. package/typed/layers/carto-layer.d.ts +0 -126
  362. package/typed/layers/carto-layer.d.ts.map +0 -1
  363. package/typed/sources/common.d.ts.map +0 -1
  364. package/typed/sources/utils.d.ts +0 -15
  365. package/typed/sources/utils.d.ts.map +0 -1
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@deck.gl/carto",
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
- "version": "8.10.0-alpha.7",
5
+ "version": "9.0.0-alpha.3",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -35,11 +35,12 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.0.0",
38
- "@loaders.gl/gis": "^4.0.1",
39
- "@loaders.gl/loader-utils": "^4.0.1",
40
- "@loaders.gl/mvt": "^4.0.1",
41
- "@loaders.gl/tiles": "^4.0.1",
42
- "@luma.gl/constants": "^8.5.20",
38
+ "@loaders.gl/gis": "4.0.3",
39
+ "@loaders.gl/loader-utils": "4.0.3",
40
+ "@loaders.gl/mvt": "4.0.3",
41
+ "@loaders.gl/tiles": "4.0.3",
42
+ "@luma.gl/constants": "9.0.0-alpha.42",
43
+ "@luma.gl/core": "9.0.0-alpha.42",
43
44
  "@math.gl/web-mercator": "^4.0.0",
44
45
  "cartocolor": "^4.0.2",
45
46
  "d3-array": "^3.2.0",
@@ -52,7 +53,7 @@
52
53
  "quadbin": "^0.1.9"
53
54
  },
54
55
  "devDependencies": {
55
- "@loaders.gl/schema": "^4.0.1",
56
+ "@loaders.gl/schema": "4.0.3",
56
57
  "@types/d3-array": "^3.0.2",
57
58
  "@types/d3-color": "^1.4.2",
58
59
  "@types/d3-scale": "^3.0.0"
@@ -63,7 +64,7 @@
63
64
  "@deck.gl/extensions": "^8.0.0",
64
65
  "@deck.gl/geo-layers": "^8.0.0",
65
66
  "@deck.gl/layers": "^8.0.0",
66
- "@loaders.gl/core": "^4.0.1"
67
+ "@loaders.gl/core": "4.0.3"
67
68
  },
68
- "gitHead": "1c62a9eec914019afd3969bc0c59f1488e491207"
69
+ "gitHead": "51dfb88f9168ccf478d01b28a2c5ada7bd8281c7"
69
70
  }
package/src/.DS_Store ADDED
Binary file
@@ -1,12 +1,4 @@
1
- import {MapType, RequestType} from './maps-api-common';
2
-
3
- export type APIErrorContext = {
4
- requestType: RequestType;
5
- mapId?: string;
6
- connection?: string;
7
- source?: string;
8
- type?: MapType;
9
- };
1
+ import type {APIErrorContext} from './types';
10
2
 
11
3
  /**
12
4
  *
@@ -0,0 +1,14 @@
1
+ export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
2
+ export const DEFAULT_CLIENT = 'deck-gl-carto';
3
+ export const V3_MINOR_VERSION = '3.3';
4
+ export const MAX_GET_LENGTH = 8192;
5
+
6
+ export const DEFAULT_PARAMETERS = {
7
+ client: DEFAULT_CLIENT,
8
+ v: V3_MINOR_VERSION
9
+ };
10
+
11
+ export const DEFAULT_HEADERS = {
12
+ Accept: 'application/json',
13
+ 'Content-Type': 'application/json'
14
+ };
@@ -0,0 +1,38 @@
1
+ import {MapType} from './types';
2
+
3
+ export type V3Endpoint = 'maps' | 'stats' | 'sql';
4
+
5
+ function buildUrlFromBase(apiBaseUrl: string, endpoint: V3Endpoint) {
6
+ let suffix = `/v3/${endpoint}`;
7
+ if (apiBaseUrl.endsWith('/')) {
8
+ suffix = suffix.substring(1);
9
+ }
10
+
11
+ return `${apiBaseUrl}${suffix}`;
12
+ }
13
+
14
+ export function buildMapsUrlFromBase(apiBaseUrl: string): string {
15
+ return buildUrlFromBase(apiBaseUrl, 'maps');
16
+ }
17
+
18
+ export function buildStatsUrlFromBase(apiBaseUrl: string): string {
19
+ return buildUrlFromBase(apiBaseUrl, 'stats');
20
+ }
21
+
22
+ export function buildQueryUrlFromBase(apiBaseUrl: string): string {
23
+ return buildUrlFromBase(apiBaseUrl, 'sql');
24
+ }
25
+
26
+ export function buildSourceUrl({
27
+ apiBaseUrl,
28
+ connectionName,
29
+ endpoint,
30
+ mapsUrl
31
+ }: {
32
+ apiBaseUrl: string;
33
+ connectionName: string;
34
+ endpoint: MapType;
35
+ mapsUrl?: string;
36
+ }): string {
37
+ return `${mapsUrl || buildMapsUrlFromBase(apiBaseUrl)}/${connectionName}/${endpoint}`;
38
+ }
@@ -0,0 +1,287 @@
1
+ /* eslint-disable camelcase */
2
+ /**
3
+ * Maps API Client for Carto 3
4
+ */
5
+ import {CartoAPIError} from './carto-api-error';
6
+ import {DEFAULT_API_BASE_URL, DEFAULT_CLIENT} from './common';
7
+ import {buildMapsUrlFromBase, buildStatsUrlFromBase} from './endpoints';
8
+ import {
9
+ GeojsonResult,
10
+ JsonResult,
11
+ TilejsonResult,
12
+ h3QuerySource,
13
+ h3TableSource,
14
+ quadbinQuerySource,
15
+ quadbinTableSource,
16
+ vectorQuerySource,
17
+ vectorTableSource,
18
+ vectorTilesetSource
19
+ } from '../sources';
20
+ import {parseMap} from './parse-map';
21
+ import {requestWithParameters} from './request-with-parameters';
22
+ import {assert} from '../utils';
23
+ import type {APIErrorContext, Format, MapType, QueryParameters} from './types';
24
+
25
+ type Dataset = {
26
+ id: string;
27
+ type: MapType;
28
+ source: string;
29
+ cache?: number;
30
+ connectionName: string;
31
+ geoColumn: string;
32
+ data: TilejsonResult | GeojsonResult | JsonResult;
33
+ columns: string[];
34
+ format: Format;
35
+ aggregationExp: string;
36
+ aggregationResLevel: number;
37
+ queryParameters: QueryParameters;
38
+ };
39
+
40
+ /* global clearInterval, setInterval, URL */
41
+ /* eslint-disable complexity, max-statements */
42
+ async function _fetchMapDataset(
43
+ dataset: Dataset,
44
+ accessToken: string,
45
+ apiBaseUrl: string,
46
+ clientId?: string,
47
+ headers?: Record<string, string>
48
+ ) {
49
+ const {
50
+ aggregationExp,
51
+ aggregationResLevel,
52
+ connectionName,
53
+ columns,
54
+ format,
55
+ geoColumn,
56
+ source,
57
+ type,
58
+ queryParameters
59
+ } = dataset;
60
+
61
+ const cache: {value?: number} = {};
62
+ const globalOptions: any = {
63
+ accessToken,
64
+ apiBaseUrl,
65
+ cache,
66
+ clientId,
67
+ connectionName,
68
+ format,
69
+ headers
70
+ };
71
+
72
+ if (type === 'tileset') {
73
+ // TODO do we want a generic tilesetSource?
74
+ // @ts-ignore
75
+ dataset.data = await vectorTilesetSource({...globalOptions, tableName: source});
76
+ } else {
77
+ const [spatialDataType, spatialDataColumn] = geoColumn ? geoColumn.split(':') : ['geom'];
78
+ if (spatialDataType === 'geom') {
79
+ const options = {...globalOptions, spatialDataColumn};
80
+ if (type === 'table') {
81
+ dataset.data = await vectorTableSource({...options, columns, tableName: source});
82
+ } else if (type === 'query') {
83
+ dataset.data = await vectorQuerySource({...options, sqlQuery: source, queryParameters});
84
+ }
85
+ } else if (spatialDataType === 'h3') {
86
+ const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
87
+ if (type === 'table') {
88
+ dataset.data = await h3TableSource({...options, columns, tableName: source});
89
+ } else if (type === 'query') {
90
+ dataset.data = await h3QuerySource({...options, sqlQuery: source, queryParameters});
91
+ }
92
+ } else if (spatialDataType === 'quadbin') {
93
+ const options = {...globalOptions, aggregationExp, aggregationResLevel, spatialDataColumn};
94
+ if (type === 'table') {
95
+ dataset.data = await quadbinTableSource({...options, columns, tableName: source});
96
+ } else if (type === 'query') {
97
+ dataset.data = await quadbinQuerySource({...options, sqlQuery: source, queryParameters});
98
+ }
99
+ }
100
+ }
101
+ let cacheChanged = true;
102
+ if (cache.value) {
103
+ cacheChanged = dataset.cache !== cache.value;
104
+ dataset.cache = cache.value;
105
+ }
106
+
107
+ return cacheChanged;
108
+ }
109
+
110
+ async function _fetchTilestats(
111
+ attribute,
112
+ dataset: Dataset,
113
+ accessToken: string,
114
+ apiBaseUrl: string
115
+ ) {
116
+ const {connectionName: connection, data, id, source, type} = dataset;
117
+ const errorContext: APIErrorContext = {requestType: 'Tile stats', connection, type, source};
118
+ if (!('tilestats' in data)) {
119
+ throw new CartoAPIError(new Error(`Invalid dataset for tilestats: ${id}`), errorContext);
120
+ }
121
+
122
+ const statsUrl = buildStatsUrlFromBase(apiBaseUrl);
123
+ let baseUrl = `${statsUrl}/${connection}/`;
124
+ if (type === 'query') {
125
+ baseUrl += attribute;
126
+ } else {
127
+ // MAP_TYPE.TABLE
128
+ baseUrl += `${source}/${attribute}`;
129
+ }
130
+
131
+ const headers = {Authorization: `Bearer ${accessToken}`};
132
+ const stats = await requestWithParameters({
133
+ baseUrl,
134
+ headers,
135
+ parameters: type === 'query' ? {q: source} : {},
136
+ errorContext
137
+ });
138
+
139
+ // Replace tilestats for attribute with value from API
140
+ const {attributes} = data.tilestats.layers[0];
141
+ const index = attributes.findIndex(d => d.attribute === attribute);
142
+ attributes[index] = stats;
143
+ return true;
144
+ }
145
+
146
+ async function fillInMapDatasets(
147
+ {datasets, token}: {datasets: Dataset[]; token: string},
148
+ clientId: string,
149
+ apiBaseUrl: string,
150
+ headers?: Record<string, string>
151
+ ) {
152
+ const promises = datasets.map(dataset =>
153
+ _fetchMapDataset(dataset, token, apiBaseUrl, clientId, headers)
154
+ );
155
+ return await Promise.all(promises);
156
+ }
157
+
158
+ async function fillInTileStats(
159
+ {datasets, keplerMapConfig, token}: {datasets: Dataset[]; keplerMapConfig: any; token: string},
160
+ apiBaseUrl: string
161
+ ) {
162
+ const attributes: {attribute?: string; dataset?: any}[] = [];
163
+ const {layers} = keplerMapConfig.config.visState;
164
+ for (const layer of layers) {
165
+ for (const channel of Object.keys(layer.visualChannels)) {
166
+ const attribute = layer.visualChannels[channel]?.name;
167
+ if (attribute) {
168
+ const dataset = datasets.find(d => d.id === layer.config.dataId);
169
+ if (dataset && dataset.type !== 'tileset' && (dataset.data as TilejsonResult).tilestats) {
170
+ // Only fetch stats for QUERY & TABLE map types
171
+ attributes.push({attribute, dataset});
172
+ }
173
+ }
174
+ }
175
+ }
176
+ // Remove duplicates to avoid repeated requests
177
+ const filteredAttributes: {attribute?: string; dataset?: any}[] = [];
178
+ for (const a of attributes) {
179
+ if (
180
+ !filteredAttributes.find(
181
+ ({attribute, dataset}) => attribute === a.attribute && dataset === a.dataset
182
+ )
183
+ ) {
184
+ filteredAttributes.push(a);
185
+ }
186
+ }
187
+
188
+ const promises = filteredAttributes.map(({attribute, dataset}) =>
189
+ _fetchTilestats(attribute, dataset, token, apiBaseUrl)
190
+ );
191
+ return await Promise.all(promises);
192
+ }
193
+
194
+ export type FetchMapOptions = {
195
+ apiBaseUrl?: string;
196
+ cartoMapId: string;
197
+ clientId?: string;
198
+ headers?: Record<string, string>;
199
+ mapsUrl?: string;
200
+ autoRefresh?: number;
201
+ onNewData?: (map: any) => void;
202
+ };
203
+
204
+ /* eslint-disable max-statements */
205
+ export async function fetchMap({
206
+ apiBaseUrl = DEFAULT_API_BASE_URL,
207
+ cartoMapId,
208
+ clientId = DEFAULT_CLIENT,
209
+ headers = {},
210
+ mapsUrl,
211
+ autoRefresh,
212
+ onNewData
213
+ }: FetchMapOptions) {
214
+ assert(cartoMapId, 'Must define CARTO map id: fetchMap({cartoMapId: "XXXX-XXXX-XXXX"})');
215
+ assert(apiBaseUrl, 'Must define apiBaseUrl');
216
+
217
+ if (autoRefresh || onNewData) {
218
+ assert(onNewData, 'Must define `onNewData` when using autoRefresh');
219
+ assert(typeof onNewData === 'function', '`onNewData` must be a function');
220
+ assert(
221
+ typeof autoRefresh === 'number' && autoRefresh > 0,
222
+ '`autoRefresh` must be a positive number'
223
+ );
224
+ }
225
+
226
+ const baseUrl = `${mapsUrl || buildMapsUrlFromBase(apiBaseUrl)}/public/${cartoMapId}`;
227
+ const errorContext: APIErrorContext = {requestType: 'Public map', mapId: cartoMapId};
228
+ const map = await requestWithParameters({baseUrl, headers, errorContext});
229
+
230
+ // Periodically check if the data has changed. Note that this
231
+ // will not update when a map is published.
232
+ let stopAutoRefresh: (() => void) | undefined;
233
+ if (autoRefresh) {
234
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
235
+ const intervalId = setInterval(async () => {
236
+ const changed = await fillInMapDatasets(map, clientId, apiBaseUrl, {
237
+ ...headers,
238
+ 'If-Modified-Since': new Date().toUTCString()
239
+ });
240
+ if (onNewData && changed.some(v => v === true)) {
241
+ onNewData(parseMap(map));
242
+ }
243
+ }, autoRefresh * 1000);
244
+ stopAutoRefresh = () => {
245
+ clearInterval(intervalId);
246
+ };
247
+ }
248
+
249
+ const geojsonLayers = map.keplerMapConfig.config.visState.layers.filter(
250
+ ({type}) => type === 'geojson' || type === 'point'
251
+ );
252
+ const geojsonDatasetIds = geojsonLayers.map(({config}) => config.dataId);
253
+ map.datasets.forEach(dataset => {
254
+ if (geojsonDatasetIds.includes(dataset.id)) {
255
+ const {config} = geojsonLayers.find(({config}) => config.dataId === dataset.id);
256
+ dataset.format = 'geojson';
257
+ // Support for very old maps. geoColumn was not stored in the past
258
+ if (!dataset.geoColumn && config.columns.geojson) {
259
+ dataset.geoColumn = config.columns.geojson;
260
+ }
261
+ }
262
+ });
263
+
264
+ // Mutates map.datasets so that dataset.data contains data
265
+ await fillInMapDatasets(map, clientId, apiBaseUrl, headers);
266
+
267
+ // Mutates attributes in visualChannels to contain tile stats
268
+ await fillInTileStats(map, apiBaseUrl);
269
+ const out = {...parseMap(map), ...{stopAutoRefresh}};
270
+
271
+ const textLayers = out.layers.filter(layer => {
272
+ const pointType = layer.props.pointType || '';
273
+ return pointType.includes('text');
274
+ });
275
+
276
+ /* global FontFace, window, document */
277
+ if (textLayers.length && window.FontFace && !document.fonts.check('12px Inter')) {
278
+ // Fetch font needed for labels
279
+ const font = new FontFace(
280
+ 'Inter',
281
+ 'url(https://fonts.gstatic.com/s/inter/v12/UcC73FwrK3iLTeHuS_fvQtMwCp50KnMa1ZL7W0Q5nw.woff2)'
282
+ );
283
+ await font.load().then(f => document.fonts.add(f));
284
+ }
285
+
286
+ return out;
287
+ }
package/src/api/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export {CartoAPIError} from './carto-api-error';
2
- export type {APIErrorContext} from './carto-api-error';
3
- export {FORMATS, TILE_FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';
4
- export type {QueryParameters} from './maps-api-common';
5
- export {getDataV2, CONNECTIONS} from './maps-client';
6
- export {fetchLayerData, fetchMap, mapInstantiation} from './maps-v3-client';
2
+ export {fetchMap} from './fetch-map';
3
+ export type {FetchMapOptions} from './fetch-map';
4
+ export type {APIErrorContext, Format, MapType, RequestType, QueryParameters} from './types';
5
+ export {query} from './query';
6
+ export type {QueryOptions} from './query';
@@ -22,8 +22,8 @@ import H3TileLayer from '../layers/h3-tile-layer';
22
22
  import QuadbinTileLayer from '../layers/quadbin-tile-layer';
23
23
  import RasterTileLayer from '../layers/raster-tile-layer';
24
24
  import VectorTileLayer from '../layers/vector-tile-layer';
25
- import {MapType, TILE_FORMATS, TileFormat} from './maps-api-common';
26
- import {assert, createBinaryProxy} from '../utils';
25
+ import {MapType} from './types';
26
+ import {assert, createBinaryProxy, scaleIdentity} from '../utils';
27
27
  import {
28
28
  CustomMarkersRange,
29
29
  MapDataset,
@@ -41,7 +41,8 @@ const SCALE_FUNCS = {
41
41
  quantile: scaleQuantile,
42
42
  quantize: scaleQuantize,
43
43
  sqrt: scaleSqrt,
44
- custom: scaleThreshold
44
+ custom: scaleThreshold,
45
+ identity: scaleIdentity
45
46
  };
46
47
  export type SCALE_TYPE = keyof typeof SCALE_FUNCS;
47
48
 
@@ -201,7 +202,6 @@ export function getLayer(
201
202
  }
202
203
 
203
204
  export function layerFromTileDataset(
204
- formatTiles: TileFormat | null = TILE_FORMATS.MVT,
205
205
  scheme: string,
206
206
  type?: MapType
207
207
  ): typeof VectorTileLayer | typeof H3TileLayer | typeof QuadbinTileLayer {
@@ -222,22 +222,16 @@ function getTileLayer(dataset: MapDataset, basePropMap) {
222
222
  const {
223
223
  aggregationExp,
224
224
  aggregationResLevel,
225
- data: {
226
- scheme,
227
- tiles: [tileUrl]
228
- }
225
+ data: {scheme}
229
226
  } = dataset;
230
- /* global URL */
231
- const formatTiles = new URL(tileUrl).searchParams.get('formatTiles') as TileFormat;
232
227
 
233
228
  return {
234
- Layer: layerFromTileDataset(formatTiles, scheme),
229
+ Layer: layerFromTileDataset(scheme),
235
230
  propMap: basePropMap,
236
231
  defaultProps: {
237
232
  ...defaultProps,
238
233
  ...(aggregationExp && {aggregationExp}),
239
234
  ...(aggregationResLevel && {aggregationResLevel}),
240
- formatTiles,
241
235
  uniqueIdProperty: 'geoid'
242
236
  }
243
237
  };
@@ -313,7 +307,7 @@ export function opacityToAlpha(opacity?: number) {
313
307
  return opacity !== undefined ? Math.round(255 * Math.pow(opacity, 1 / 2.2)) : 255;
314
308
  }
315
309
 
316
- function getAccessorKeys(name: string, aggregation: string | undefined): string[] {
310
+ function getAccessorKeys(name: string, aggregation?: string | undefined): string[] {
317
311
  let keys = [name];
318
312
  if (aggregation) {
319
313
  // Snowflake will capitalized the keys, need to check lower and upper case version
@@ -339,33 +333,13 @@ export function getColorValueAccessor({name}, colorAggregation, data: any) {
339
333
  }
340
334
 
341
335
  export function getColorAccessor(
342
- {name},
336
+ {name, colorColumn}: VisualChannelField,
343
337
  scaleType: SCALE_TYPE,
344
- {aggregation, range: {colors, colorMap}},
338
+ {aggregation, range},
345
339
  opacity: number | undefined,
346
340
  data: any
347
341
  ) {
348
- const scale = SCALE_FUNCS[scaleType as any]();
349
- let domain: (string | number)[] = [];
350
- let scaleColor: string[] = [];
351
-
352
- if (Array.isArray(colorMap)) {
353
- colorMap.forEach(([value, color]) => {
354
- domain.push(value);
355
- scaleColor.push(color);
356
- });
357
- } else {
358
- domain = calculateDomain(data, name, scaleType, colors.length);
359
- scaleColor = colors;
360
- }
361
-
362
- if (scaleType === 'ordinal') {
363
- domain = domain.slice(0, scaleColor.length);
364
- }
365
-
366
- scale.domain(domain);
367
- scale.range(scaleColor);
368
- scale.unknown(UNKNOWN_COLOR);
342
+ const scale = calculateLayerScale(colorColumn || name, scaleType, range, data);
369
343
  const alpha = opacityToAlpha(opacity);
370
344
 
371
345
  let accessorKeys = getAccessorKeys(name, aggregation);
@@ -380,6 +354,36 @@ export function getColorAccessor(
380
354
  return normalizeAccessor(accessor, data);
381
355
  }
382
356
 
357
+ function calculateLayerScale(name, scaleType, range, data) {
358
+ const scale = SCALE_FUNCS[scaleType]();
359
+ let domain: (string | number)[] = [];
360
+ let scaleColor: string[] = [];
361
+
362
+ if (scaleType !== 'identity') {
363
+ const {colorMap, colors} = range;
364
+
365
+ if (Array.isArray(colorMap)) {
366
+ colorMap.forEach(([value, color]) => {
367
+ domain.push(value);
368
+ scaleColor.push(color);
369
+ });
370
+ } else {
371
+ domain = calculateDomain(data, name, scaleType, colors.length);
372
+ scaleColor = colors;
373
+ }
374
+
375
+ if (scaleType === 'ordinal') {
376
+ domain = domain.slice(0, scaleColor.length);
377
+ }
378
+ }
379
+
380
+ scale.domain(domain);
381
+ scale.range(scaleColor);
382
+ scale.unknown(UNKNOWN_COLOR);
383
+
384
+ return scale;
385
+ }
386
+
383
387
  const FALLBACK_ICON =
384
388
  'data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCiAgPGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNTAiLz4NCjwvc3ZnPg==';
385
389
 
@@ -1,4 +1,5 @@
1
- import GL from '@luma.gl/constants';
1
+ import {GL} from '@luma.gl/constants';
2
+ import {log} from '@deck.gl/core';
2
3
  import {
3
4
  AGGREGATION,
4
5
  getLayer,
@@ -13,7 +14,6 @@ import {
13
14
  getMaxMarkerSize
14
15
  } from './layer-map';
15
16
  import PointLabelLayer from '../layers/point-label-layer';
16
- import {log} from '@deck.gl/core';
17
17
  import {CollisionFilterExtension} from '@deck.gl/extensions';
18
18
  import {assert} from '../utils';
19
19
  import {MapDataset, MapLayerConfig, VisualChannels} from './types';
@@ -0,0 +1,34 @@
1
+ import {SOURCE_DEFAULTS} from '../sources';
2
+ import type {SourceOptions, QuerySourceOptions, QueryResult} from '../sources/types';
3
+ import {buildQueryUrlFromBase} from './endpoints';
4
+ import {requestWithParameters} from './request-with-parameters';
5
+ import {APIErrorContext} from './types';
6
+
7
+ export type QueryOptions = SourceOptions & Omit<QuerySourceOptions, 'spatialDataColumn'>;
8
+ type UrlParameters = {q: string; queryParameters?: string};
9
+
10
+ export const query = async function (options: QueryOptions): Promise<QueryResult> {
11
+ const {apiBaseUrl, connectionName, sqlQuery, queryParameters} = options;
12
+ const urlParameters: UrlParameters = {q: sqlQuery};
13
+
14
+ if (queryParameters) {
15
+ urlParameters.queryParameters = JSON.stringify(queryParameters);
16
+ }
17
+
18
+ const queryUrl = buildQueryUrlFromBase(apiBaseUrl || SOURCE_DEFAULTS.apiBaseUrl);
19
+ const baseUrl = `${queryUrl}/${connectionName}/query`;
20
+ const headers = {Authorization: `Bearer ${options.accessToken}`, ...options.headers};
21
+
22
+ const errorContext: APIErrorContext = {
23
+ requestType: 'SQL',
24
+ connection: options.connectionName,
25
+ type: 'query',
26
+ source: JSON.stringify(urlParameters, undefined, 2)
27
+ };
28
+ return await requestWithParameters<QueryResult>({
29
+ baseUrl,
30
+ parameters: urlParameters,
31
+ headers,
32
+ errorContext
33
+ });
34
+ };
@@ -1,19 +1,33 @@
1
- import {APIErrorContext, CartoAPIError} from '../api/carto-api-error';
2
- import {encodeParameter, MapType} from '../api/maps-api-common';
1
+ import {CartoAPIError} from './carto-api-error';
3
2
  import {DEFAULT_HEADERS, DEFAULT_PARAMETERS, MAX_GET_LENGTH} from './common';
4
- import {buildMapsUrlFromBase} from '../config';
3
+ import type {APIErrorContext} from './types';
5
4
 
5
+ /**
6
+ * Simple encode parameter
7
+ */
8
+ function encodeParameter(name: string, value: string | boolean | number): string {
9
+ return `${name}=${encodeURIComponent(value)}`;
10
+ }
11
+
12
+ const REQUEST_CACHE = new Map();
6
13
  export async function requestWithParameters<T = any>({
14
+ accessToken,
7
15
  baseUrl,
8
16
  parameters,
9
17
  headers: customHeaders,
10
18
  errorContext
11
19
  }: {
20
+ accessToken?: string;
12
21
  baseUrl: string;
13
22
  parameters?: Record<string, string>;
14
23
  headers: Record<string, string>;
15
24
  errorContext: APIErrorContext;
16
25
  }): Promise<T> {
26
+ const key = JSON.stringify({baseUrl, parameters, customHeaders});
27
+ if (REQUEST_CACHE.has(key)) {
28
+ return REQUEST_CACHE.get(key);
29
+ }
30
+
17
31
  let url = baseUrl;
18
32
  if (parameters) {
19
33
  const allParameters = {...DEFAULT_PARAMETERS, ...parameters};
@@ -35,29 +49,20 @@ export async function requestWithParameters<T = any>({
35
49
  let json: any;
36
50
  try {
37
51
  json = await response.json();
52
+ if (accessToken) {
53
+ json.accessToken = accessToken;
54
+ }
38
55
  } catch {
39
56
  json = {error: ''};
40
57
  }
41
58
  if (!response.ok) {
59
+ REQUEST_CACHE.delete(key);
42
60
  throw new CartoAPIError(json.error, errorContext, response);
43
61
  }
44
62
 
63
+ REQUEST_CACHE.set(key, json);
45
64
  return json;
46
65
  } catch (error) {
47
66
  throw new CartoAPIError(error as Error, errorContext);
48
67
  }
49
68
  }
50
-
51
- export function buildApiEndpoint({
52
- apiBaseUrl,
53
- connectionName,
54
- endpoint,
55
- mapsUrl
56
- }: {
57
- apiBaseUrl: string;
58
- connectionName: string;
59
- endpoint: MapType;
60
- mapsUrl?: string;
61
- }): string {
62
- return `${mapsUrl || buildMapsUrlFromBase(apiBaseUrl)}/${connectionName}/${endpoint}`;
63
- }