Skip to content

Commit

Permalink
feat: add new call to catalog content (#814)
Browse files Browse the repository at this point in the history
Co-authored-by: Chen Jun Chi <[email protected]>
  • Loading branch information
mogagnon and cjun-coveo authored Apr 22, 2024
1 parent b328a6b commit 21f4b32
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/resources/Catalogs/CatalogContent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import API from '../../APICore.js';
import Resource from '../Resource.js';
import {CatalogMetadata, CatalogMetadataName} from './CatalogInterfaces.js';
import {CatalogMetadata, CatalogMetadataName, CatalogObjectType} from './CatalogInterfaces.js';

export type ObjectType = {
objectType: string;
};

export type Version = {
version: number;
};

export default class CatalogContent extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/catalogcontent/source`;

getObjectTypeV2(sourceId: string, version: Version) {
return this.api.get<CatalogObjectType>(
this.buildPath(`${CatalogContent.baseUrl}/${sourceId}/objecttypes`, version),
);
}

getObjectTypes(sourceId: string) {
return this.api.get<string[]>(`${CatalogContent.baseUrl}/${sourceId}/objecttypes`);
}
Expand Down
11 changes: 11 additions & 0 deletions src/resources/Catalogs/CatalogInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ export interface CatalogFieldStatsOptions {
forceRefresh?: boolean;
}

export interface CatalogObjectType {
/**
* If catalog content exist in source
*/
hasCatalogContent: boolean;
/**
* Object type values seen on catalog content
*/
objectTypeValues: string[];
}

export interface CatalogMetadata {
/**
* Metadata seen on catalog documents with a sample of values.
Expand Down
14 changes: 14 additions & 0 deletions src/resources/Catalogs/tests/CatalogContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ describe('CatalogContent', () => {
metadata = new CatalogContent(api, serverlessApi);
});

describe('getObjectTypeV2', () => {
it('should make a GET call to the specific CatalogContent url', () => {
const defaultOptions: queryString.StringifyOptions = {skipEmptyString: true, skipNull: true, sort: false};
const sourceId = 'McDonald';
const version = {version: 2};

metadata.getObjectTypeV2(sourceId, version);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${baseUrl}/${sourceId}/objecttypes?${queryString.stringify(version, {...defaultOptions})}`,
);
});
});

describe('getObjectTypes', () => {
it('should make a GET call to the specific CatalogContent url', () => {
const sourceId = 'McDonald';
Expand Down

0 comments on commit 21f4b32

Please sign in to comment.