Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Infer clientId where possible #7

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -83,7 +84,7 @@ export function executeModel(props: {

const queryParams: Record<string, string> = {
type,
client: getClient(),
client: clientId,
source: data,
params: JSON.stringify(params),
queryParameters,
Expand Down
32 changes: 19 additions & 13 deletions src/sources/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,6 +55,7 @@ export type VectorQuerySourceOptions =
export async function vectorTableSource(
props: VectorTableSourceOptions
): Promise<VectorTableSourceResponse> {
assignDefaultProps(props);
const response = await _vectorTableSource(props as _VectorTableSourceOptions);
return {...response, widgetSource: new WidgetTableSource(props)};
}
Expand All @@ -62,15 +64,11 @@ export async function vectorTableSource(
export async function vectorQuerySource(
props: VectorQuerySourceOptions
): Promise<VectorQuerySourceResponse> {
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
*/
Expand All @@ -82,6 +80,7 @@ export type H3QuerySourceOptions = WrappedSourceOptions<_H3QuerySourceOptions>;
export async function h3TableSource(
props: H3TableSourceOptions
): Promise<H3TableSourceResponse> {
assignDefaultProps(props);
const response = await _h3TableSource(props);
return {...response, widgetSource: new WidgetTableSource(props)};
}
Expand All @@ -90,15 +89,11 @@ export async function h3TableSource(
export async function h3QuerySource(
props: H3QuerySourceOptions
): Promise<H3QuerySourceResponse> {
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
*/
Expand All @@ -113,6 +108,7 @@ export type QuadbinQuerySourceOptions =
export async function quadbinTableSource(
props: QuadbinTableSourceOptions & WidgetBaseSourceProps
): Promise<QuadbinTableSourceResponse> {
assignDefaultProps(props);
const response = await _quadbinTableSource(props);
return {...response, widgetSource: new WidgetTableSource(props)};
}
Expand All @@ -121,11 +117,21 @@ export async function quadbinTableSource(
export async function quadbinQuerySource(
props: QuadbinQuerySourceOptions & WidgetBaseSourceProps
): Promise<QuadbinQuerySourceResponse> {
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<T extends SourceOptions>(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;
}
}
18 changes: 0 additions & 18 deletions test/sources/wrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -129,8 +116,3 @@ test('quadbinTableSource', async () => {

expect(widgetSource).toBeInstanceOf(WidgetTableSource);
});

test('quadbinTilesetSource', async () => {
expect(quadbinTilesetSource).toBeDefined();
expect(() => quadbinTilesetSource()).rejects.toThrowError(/not implemented/i);
});