Skip to content

Commit

Permalink
Merge a9b9277 into facc939
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannzhou committed Aug 11, 2022
2 parents facc939 + a9b9277 commit 0a91afa
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export { VerticalSearchResponse } from './searchservice/response/VerticalSearchR
export { Snippet } from './searchservice/response/Snippet';
export { ErrorType } from './searchservice/response/ErrorType';
export { FailedVertical } from './searchservice/response/FailedVertical';
export { FieldType } from './searchservice/response/FieldType';

// Search service common models
export { Matcher } from './searchservice/common/Matcher';
Expand All @@ -78,3 +79,6 @@ export {
LowerNumberRangeLimit,
UpperNumberRangeLimit
} from './searchservice/common/NumberRangeValue';

// Utils
export { EnumOrLiteral } from './utils/EnumOrLiteral';
8 changes: 5 additions & 3 deletions src/models/searchservice/response/DirectAnswer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Result } from './Result';
import { DirectAnswerType } from './DirectAnswerType';
import { FieldType } from './FieldType';
import { EnumOrLiteral } from '../../utils/EnumOrLiteral';

/**
* A direct answer to a search.
*
* @public
*/
export interface DirectAnswer {
export interface DirectAnswer<T = unknown> {
/** The {@link DirectAnswerType}. */
type: DirectAnswerType,
/**
Expand All @@ -15,11 +17,11 @@ export interface DirectAnswer {
* @remarks
* A value will not be present if the {@link DirectAnswer.fieldType} is 'rich_text'.
*/
value?: string,
value?: T,
/** The entity associated with the direct answer. */
relatedResult: Result,
/** The vertical key of the direct answer. */
verticalKey: string,
/** The field type of the direct answer. */
fieldType: string
fieldType: EnumOrLiteral<FieldType>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EnumOrLiteral } from '../../utils/EnumOrLiteral';
import { DirectAnswer } from './DirectAnswer';
import { DirectAnswerType } from './DirectAnswerType';
import { FieldType } from './FieldType';
import { Result } from './Result';
import { Snippet } from './Snippet';

Expand All @@ -18,7 +20,7 @@ export interface FeaturedSnippetDirectAnswer extends DirectAnswer {
/** {@inheritDoc DirectAnswer.verticalKey} */
verticalKey: string,
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: string,
fieldType: EnumOrLiteral<FieldType>,
/** The snippet where the direct answer was found. */
snippet: Snippet
}
21 changes: 21 additions & 0 deletions src/models/searchservice/response/FieldType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Possible field types for {@link DirectAnswer.fieldType}.
* @public
*/
export enum FieldType {
// URL = 'url',
// ComplexURL = 'complex_url',
// IOSAppURL = 'ios_app_url',
// AndroidAppURL = 'android_app_url',
// FacebookURL = 'facebook_url',
// Email = 'email',
// InstagramHandle = 'instagram_handle',
// TwitterHandle = 'twitter_handle',
// Phone = 'phone',
Address = 'address',
// Hours = 'hours',
// Decimal = 'decimal',
// RichText = 'rich_text',
// SingleLineText = 'single_line_text',
// MultiLineText = 'multi_line_text'
}
8 changes: 5 additions & 3 deletions src/models/searchservice/response/FieldValueDirectAnswer.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { EnumOrLiteral } from '../../utils/EnumOrLiteral';
import { DirectAnswer } from './DirectAnswer';
import { DirectAnswerType } from './DirectAnswerType';
import { FieldType } from './FieldType';
import { Result } from './Result';

/**
* A direct answer where the answer came from a field from the knowledge graph.
*
* @public
*/
export interface FieldValueDirectAnswer extends DirectAnswer {
export interface FieldValueDirectAnswer<T = unknown> extends DirectAnswer<T> {
/** {@link DirectAnswerType}.FieldValue. */
type: DirectAnswerType.FieldValue,
/** {@inheritDoc DirectAnswer.value} */
value: string,
value: T,
/** {@inheritDoc DirectAnswer.relatedResult} */
relatedResult: Result,
/** {@inheritDoc DirectAnswer.verticalKey} */
verticalKey: string,
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: string,
fieldType: EnumOrLiteral<FieldType>,
/** The name of the entity that direct answer came from. */
entityName: string,
/** The field name of the direct answer. */
Expand Down
6 changes: 6 additions & 0 deletions src/models/utils/EnumOrLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Produces a union type from the enum passed as a generic which consists of the enum values
* and the string literals of the enum.
* @public
*/
export type EnumOrLiteral<T extends string> = T | `${T}`;

0 comments on commit 0a91afa

Please sign in to comment.