Skip to content

Commit

Permalink
Merge 99aa2b5 into edc1689
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannzhou committed Aug 11, 2022
2 parents edc1689 + 99aa2b5 commit ac932de
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
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
}
22 changes: 22 additions & 0 deletions src/models/searchservice/response/FieldType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Type for value of DirectAnswer.
*
* @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
1 change: 1 addition & 0 deletions src/models/utils/EnumOrLiteral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type EnumOrLiteral<T extends string> = T | `${T}`;

0 comments on commit ac932de

Please sign in to comment.