From c6603af0e972283ad4bd529a582e0ea0ca53a1b6 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Fri, 5 Jul 2024 15:19:47 -0400 Subject: [PATCH 1/2] feat: Infer clientId when possible --- src/models/model.ts | 5 +++-- src/sources/wrappers.ts | 32 +++++++++++++++++++------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/models/model.ts b/src/models/model.ts index 5f59cc1..2024aed 100644 --- a/src/models/model.ts +++ b/src/models/model.ts @@ -67,7 +67,8 @@ export function executeModel(props: { ); const {model, source, params, opts} = props; - const {type, apiVersion, apiBaseUrl, accessToken, connectionName} = source; + const {type, apiVersion, apiBaseUrl, accessToken, connectionName, clientId} = + source; assert(apiBaseUrl, 'executeModel: missing apiBaseUrl'); assert(accessToken, 'executeModel: missing accessToken'); @@ -83,7 +84,7 @@ export function executeModel(props: { const queryParams: Record = { type, - client: getClient(), + client: clientId, source: data, params: JSON.stringify(params), queryParameters, diff --git a/src/sources/wrappers.ts b/src/sources/wrappers.ts index d2fe616..e7c8065 100644 --- a/src/sources/wrappers.ts +++ b/src/sources/wrappers.ts @@ -11,6 +11,7 @@ import { H3QuerySourceOptions as _H3QuerySourceOptions, QuadbinTableSourceOptions as _QuadbinTableSourceOptions, QuadbinQuerySourceOptions as _QuadbinQuerySourceOptions, + SourceOptions, } from '@deck.gl/carto'; import {WidgetBaseSourceProps} from './widget-base-source.js'; import {WidgetQuerySource} from './widget-query-source.js'; @@ -54,6 +55,7 @@ export type VectorQuerySourceOptions = export async function vectorTableSource( props: VectorTableSourceOptions ): Promise { + assignDefaultProps(props); const response = await _vectorTableSource(props as _VectorTableSourceOptions); return {...response, widgetSource: new WidgetTableSource(props)}; } @@ -62,15 +64,11 @@ export async function vectorTableSource( export async function vectorQuerySource( props: VectorQuerySourceOptions ): Promise { + assignDefaultProps(props); const response = await _vectorQuerySource(props as _VectorQuerySourceOptions); return {...response, widgetSource: new WidgetQuerySource(props)}; } -/** Wrapper adding Widget API support to [vectorTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */ -export async function vectorTilesetSource() { - throw new Error('not implemented'); -} - /****************************************************************************** * H3 SOURCES */ @@ -82,6 +80,7 @@ export type H3QuerySourceOptions = WrappedSourceOptions<_H3QuerySourceOptions>; export async function h3TableSource( props: H3TableSourceOptions ): Promise { + assignDefaultProps(props); const response = await _h3TableSource(props); return {...response, widgetSource: new WidgetTableSource(props)}; } @@ -90,15 +89,11 @@ export async function h3TableSource( export async function h3QuerySource( props: H3QuerySourceOptions ): Promise { + assignDefaultProps(props); const response = await _h3QuerySource(props); return {...response, widgetSource: new WidgetQuerySource(props)}; } -/** Wrapper adding Widget API support to [h3TilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */ -export async function h3TilesetSource() { - throw new Error('not implemented'); -} - /****************************************************************************** * QUADBIN SOURCES */ @@ -113,6 +108,7 @@ export type QuadbinQuerySourceOptions = export async function quadbinTableSource( props: QuadbinTableSourceOptions & WidgetBaseSourceProps ): Promise { + assignDefaultProps(props); const response = await _quadbinTableSource(props); return {...response, widgetSource: new WidgetTableSource(props)}; } @@ -121,11 +117,21 @@ export async function quadbinTableSource( export async function quadbinQuerySource( props: QuadbinQuerySourceOptions & WidgetBaseSourceProps ): Promise { + assignDefaultProps(props); const response = await _quadbinQuerySource(props); return {...response, widgetSource: new WidgetQuerySource(props)}; } -/** Wrapper adding Widget API support to [quadbinTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */ -export async function quadbinTilesetSource() { - throw new Error('not implemented'); +/****************************************************************************** + * DEFAULT PROPS + */ + +declare const deck: {VERSION?: string} | undefined; +function assignDefaultProps(props: T): void { + if (typeof deck !== 'undefined' && deck && deck.VERSION) { + props.clientId ||= 'deck-gl-carto'; + // TODO: Uncomment if/when `@deck.gl/carto` devDependency is removed, + // and source functions are moved here rather than wrapped. + // props.deckglVersion ||= deck.VERSION; + } } From 301f498413b38aa75494646f5ede784d0a582605 Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Mon, 8 Jul 2024 10:19:20 -0400 Subject: [PATCH 2/2] Remove old tests --- test/sources/wrappers.test.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/sources/wrappers.test.ts b/test/sources/wrappers.test.ts index 35617b5..9dab148 100644 --- a/test/sources/wrappers.test.ts +++ b/test/sources/wrappers.test.ts @@ -2,13 +2,10 @@ import {afterEach, expect, test, vi} from 'vitest'; import { vectorQuerySource, vectorTableSource, - vectorTilesetSource, h3QuerySource, h3TableSource, - h3TilesetSource, quadbinQuerySource, quadbinTableSource, - quadbinTilesetSource, WidgetQuerySource, WidgetTableSource, } from '@carto/api-client'; @@ -60,11 +57,6 @@ test('vectorTableSource', async () => { expect(widgetSource).toBeInstanceOf(WidgetTableSource); }); -test('vectorTilesetSource', async () => { - expect(vectorTilesetSource).toBeDefined(); - expect(() => vectorTilesetSource()).rejects.toThrowError(/not implemented/i); -}); - /****************************************************************************** * H3 SOURCES */ @@ -95,11 +87,6 @@ test('h3TableSource', async () => { expect(widgetSource).toBeInstanceOf(WidgetTableSource); }); -test('h3TilesetSource', async () => { - expect(h3TilesetSource).toBeDefined(); - expect(() => h3TilesetSource()).rejects.toThrowError(/not implemented/i); -}); - /****************************************************************************** * QUADBIN SOURCES */ @@ -129,8 +116,3 @@ test('quadbinTableSource', async () => { expect(widgetSource).toBeInstanceOf(WidgetTableSource); }); - -test('quadbinTilesetSource', async () => { - expect(quadbinTilesetSource).toBeDefined(); - expect(() => quadbinTilesetSource()).rejects.toThrowError(/not implemented/i); -});