Skip to content

Commit da6e2f2

Browse files
seamless conversion between search v1 and v2 and vice versa #174
1 parent e3aacda commit da6e2f2

23 files changed

+2475
-805
lines changed

dist/browser/esm/dynamics-web-api.js

Lines changed: 391 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser/esm/dynamics-web-api.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/dynamics-web-api.js

Lines changed: 394 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/dynamics-web-api.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dynamics-web-api.d.ts

Lines changed: 236 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,32 @@ export declare class DynamicsWebApi {
314314
*/
315315
retrieveCsdlMetadata: (request?: CsdlMetadataRequest) => Promise<string>;
316316
/**
317+
* @deprecated Use "query" instead.
317318
* Provides a search results page.
318319
* @param request - An object that represents all possible options for a current request.
319-
* @returns {Promise<SearchResponse<TValue>>} Search result
320+
* @returns {Promise<SearchResponse<TValue>>} Search result.
320321
*/
321322
search: SearchFunction;
323+
/**
324+
* The query operation returns search results based on a search term.
325+
* @param request - An object that represents all possible options for a current request.
326+
* @returns {Promise<QueryResponse>} Query result.
327+
*/
328+
query: QueryFunction;
322329
/**
323330
* Provides suggestions as the user enters text into a form field.
324331
* @param request - An object that represents all possible options for a current request.
325-
* @returns {Promise<SuggestResponse<TValueDocument>>} Suggestions result
332+
* @returns {Promise<SuggestResponse<TValueDocument>>} Suggestions result.
326333
*/
327334
suggest: SuggestFunction;
328335
/**
329336
* Provides autocompletion of input as the user enters text into a form field.
330337
* @param request - An object that represents all possible options for a current request.
331-
* @returns {Promise<AutocompleteResponse>} Result of autocomplete
338+
* @returns {Promise<AutocompleteResponse>} Result of an autocomplete.
332339
*/
333340
autocomplete: AutocompleteFunction;
334341
/**
335-
* Starts/executes a batch request.
342+
* Starts a batch request.
336343
*/
337344
startBatch: () => void;
338345
/**
@@ -807,7 +814,7 @@ export type SearchEntity = {
807814
/**Filters applied on the entity.*/
808815
filter?: string;
809816
};
810-
export type SearchOptions = {
817+
export type SearchOptions = Record<string, any> & {
811818
/**Values can be simple or lucene. */
812819
querytype?: "simple" | "lucene";
813820
/**Enables intelligent query workflow to return probable set of results if no good matches are found for the search request terms.*/
@@ -821,7 +828,7 @@ export interface SearchQueryBase {
821828
/**The search parameter value contains the term to be searched for and has a 100-character limit. For suggestions, min 3 characters in addition. */
822829
search: string;
823830
/**The default table list searches across all Dataverse search–configured tables and columns. The default list is configured by your administrator when Dataverse search is enabled. */
824-
entities?: string[] | SearchEntity[];
831+
entities?: string[] | SearchEntity[] | string;
825832
/**Filters are applied while searching data and are specified in standard OData syntax. */
826833
filter?: string;
827834
}
@@ -831,7 +838,7 @@ export interface Query extends SearchQueryBase {
831838
/**Facets support the ability to drill down into data results after they've been retrieved. */
832839
facets?: string[];
833840
/**
834-
* Specify true to return the total record count; otherwise false. The default is false.
841+
* V1. Specify true to return the total record count; otherwise false. The default is false.
835842
* @deprecated Use "count".
836843
*/
837844
returnTotalRecordCount?: boolean;
@@ -842,14 +849,14 @@ export interface Query extends SearchQueryBase {
842849
/**A list of comma-separated clauses where each clause consists of a column name followed by 'asc' (ascending, which is the default) or 'desc' (descending). This list specifies how to order the results in order of precedence. */
843850
orderBy?: string[];
844851
/**V2. Options are settings configured to search a search term. */
845-
options?: SearchOptions[];
852+
options?: string | SearchOptions;
846853
/**
847-
* Specifies whether any or all the search terms must be matched to count the document as a match. The default is 'any'.
854+
* V1. Specifies whether any or all the search terms must be matched to count the document as a match. The default is 'any'.
848855
* @deprecated Use "options.searchmode".
849856
*/
850857
searchMode?: SearchMode;
851858
/**
852-
* For V2, use "options.querytype". The search type specifies the syntax of a search query. Using 'simple' selects simple query syntax and 'full' selects Lucene query syntax. The default is 'simple'.
859+
* V1. The search type specifies the syntax of a search query. Using 'simple' selects simple query syntax and 'full' selects Lucene query syntax. The default is 'simple'.
853860
* @deprecated Use "options.querytype".
854861
*/
855862
searchType?: SearchType;
@@ -884,11 +891,17 @@ export interface AutocompleteRequest extends BaseRequest {
884891
/**Autocomplete query object */
885892
query: Autocomplete;
886893
}
887-
export interface ApiConfig {
888-
/** API Version to use, for example: "9.2" or "1.0" */
894+
export type SearchApiOptions = {
895+
/**Escapes the search string. Special characters that require escaping include the following: + - & | ! ( ) { } [ ] ^ " ~ * ? : \ /. */
896+
escapeSpecialCharacters?: boolean;
897+
};
898+
export interface ApiConfig<TOptions = any> {
899+
/** API Version to use, for example: "9.2" or "1.0". */
889900
version?: string;
890-
/** API Path, for example: "data" or "search" */
901+
/** API Path, for example: "data" or "search". */
891902
path?: string;
903+
/** Specific API options. Currently it is only available for the Search API .*/
904+
options?: TOptions;
892905
}
893906
export interface AccessToken {
894907
/** Access Token */
@@ -918,7 +931,7 @@ export interface Config {
918931
/**Configuration object for Dataverse Web API (with path "data"). */
919932
dataApi?: ApiConfig;
920933
/**Configuration object for Dataverse Search API (with path "search"). */
921-
searchApi?: ApiConfig;
934+
searchApi?: ApiConfig<SearchApiOptions>;
922935
/**Default headers to supply with each request. */
923936
headers?: HeaderCollection;
924937
}
@@ -1000,26 +1013,103 @@ export interface DownloadResponse {
10001013
/**File Data */
10011014
data: Uint8Array | Buffer;
10021015
}
1016+
/**@deprecated Use QueryResponse instead */
10031017
export interface SearchResponse<TValue = any> {
1004-
/**Search results*/
1018+
/**
1019+
* A collection of matching records.
1020+
* @deprecated Use "response.Value" instead.
1021+
*/
10051022
value: TValue[];
1023+
/**
1024+
* If facets were requested in the query, a dictionary of facet values.
1025+
* @deprecated Use "response.Facets" instead.
1026+
*/
10061027
facets: any | null;
1028+
/**
1029+
* If "Count": true is included in the body of the request, the count of all documents that match the search, ignoring top and skip.
1030+
* @deprecated Use "response.Count" instead.
1031+
*/
10071032
totalrecordcount: number;
1033+
/**
1034+
* This property is used for backend search. It's included for future feature releases and isn't currently used.
1035+
* @deprecated Use "response.QueryContext" instead.
1036+
*/
10081037
querycontext: any | null;
10091038
}
1010-
export interface SuggestResponseValue<TDocument = any> {
1011-
text: string;
1012-
document: TDocument;
1039+
export interface QueryResponse extends SearchResponse<SearchQueryResult> {
1040+
/** Query response */
1041+
response: {
1042+
/**
1043+
* A collection of matching records.
1044+
*/
1045+
Value: SearchQueryResult[];
1046+
/**
1047+
* Provides error information from Azure Cognitive search.
1048+
*/
1049+
Error: SearchErrorDetail | null;
1050+
/**
1051+
* If facets were requested in the query, a dictionary of facet values.
1052+
*/
1053+
Facets: Record<string, SearchFacetResult[]> | null;
1054+
/**
1055+
* This property is used for backend search. It's included for future feature releases and isn't currently used.
1056+
*/
1057+
QueryContext: SearchQueryContext | null;
1058+
/**
1059+
* If "Count": true is included in the body of the request, the count of all documents that match the search, ignoring top and skip.
1060+
*/
1061+
Count: number;
1062+
};
1063+
"@odata.context": string;
10131064
}
10141065
export interface SuggestResponse<TValueDocument = any> {
1015-
/**Suggestions*/
1066+
/**
1067+
* A collection of matching records.
1068+
* @deprecated Use "response.Value" instead.
1069+
*/
10161070
value: SuggestResponseValue<TValueDocument>[];
1071+
/**
1072+
* Suggestions query context
1073+
* @deprecated Use "response.QueryContext" instead.
1074+
*/
10171075
querycontext: any | null;
1076+
/** Suggestion response. */
1077+
response: {
1078+
/** Provides error information from Azure Cognitive search. */
1079+
Error: SearchErrorDetail | null;
1080+
/** A collection of matching records. */
1081+
Value: SuggestResponseValue<TValueDocument>[];
1082+
/**
1083+
* The query context returned as part of response. This property is used for backend search.
1084+
* It's included for future feature releases and isn't currently used.
1085+
*/
1086+
QueryContext: SearchQueryContext | null;
1087+
};
1088+
"@odata.context": string;
10181089
}
10191090
export interface AutocompleteResponse {
1020-
/**Autocomplete result*/
1091+
/**
1092+
* Autocomplete text result.
1093+
* @deprecated Use "response.Value" instead.
1094+
*/
10211095
value: string | null;
1096+
/**
1097+
* This property is used for backend search. It's included for future feature releases and isn't currently used.
1098+
* @deprecated Use "response.QueryContext" instead.
1099+
*/
10221100
querycontext: any | null;
1101+
/** Autocomplete response. */
1102+
response: {
1103+
/** Provides error information from Azure Cognitive search. */
1104+
Error: SearchErrorDetail | null;
1105+
/** Autocomplete text result. */
1106+
Value: string | null;
1107+
/**
1108+
* This property is used for backend search. It's included for future feature releases and isn't currently used.
1109+
*/
1110+
QueryContext: SearchQueryContext | null;
1111+
};
1112+
"@odata.context": string;
10231113
}
10241114
type CallFunction = {
10251115
/**
@@ -1080,6 +1170,7 @@ type CallAction = {
10801170
*/
10811171
<TResponse = any, TAction = any>(request: UnboundActionRequest<TAction>): Promise<TResponse>;
10821172
};
1173+
/**@deprecated Use "QueryFunction" instead */
10831174
type SearchFunction = {
10841175
/**
10851176
* Provides a search results page.
@@ -1094,6 +1185,20 @@ type SearchFunction = {
10941185
*/
10951186
<TValue = any>(request: QueryRequest): Promise<SearchResponse<TValue>>;
10961187
};
1188+
type QueryFunction = {
1189+
/**
1190+
* Provides a search results page.
1191+
* @param term - The term to be searched for and has a max 100-character limit.
1192+
* @returns {Promise<SearchResponse>} Search result
1193+
*/
1194+
(term: string): Promise<QueryResponse>;
1195+
/**
1196+
* Provides a search results page.
1197+
* @param request - An object that represents all possible options for a current request.
1198+
* @returns {Promise<QueryResponse>} Search result
1199+
*/
1200+
(request: QueryRequest): Promise<QueryResponse>;
1201+
};
10971202
type SuggestFunction = {
10981203
/**
10991204
* Provides suggestions as the user enters text into a form field.
@@ -1122,5 +1227,116 @@ type AutocompleteFunction = {
11221227
*/
11231228
(request: AutocompleteRequest): Promise<AutocompleteResponse>;
11241229
};
1230+
/**
1231+
* The Azure Cognitive search error returned as part of the response.
1232+
*/
1233+
export type SearchErrorDetail = {
1234+
/**
1235+
* The error code.
1236+
*/
1237+
code: string;
1238+
/**
1239+
* The error message.
1240+
*/
1241+
message: string;
1242+
/**
1243+
* More error information.
1244+
*/
1245+
propertybag: Record<string, any>;
1246+
};
1247+
/**
1248+
* A facet query result that reports the number of documents with a field falling within a particular range or having a particular value or interval.
1249+
*/
1250+
export type SearchFacetResult = {
1251+
/**
1252+
* The count of documents falling within the bucket described by this facet.
1253+
*/
1254+
count?: number;
1255+
/**
1256+
* Value indicating the inclusive lower bound of the facet's range, or null to indicate that there's no lower bound.
1257+
*/
1258+
from: any;
1259+
/**
1260+
* Value indicating the exclusive upper bound of the facet's range, or null to indicate that there's no upper bound.
1261+
*/
1262+
to: any;
1263+
/**
1264+
* Type of the facet.
1265+
*/
1266+
type: "Value" | "Range";
1267+
/**
1268+
* Value of the facet, or the inclusive lower bound if it's an interval facet.
1269+
*/
1270+
value: any;
1271+
/**
1272+
* Another or optional value of the facet, populated while faceting on lookups.
1273+
*/
1274+
optionalvalue: any;
1275+
};
1276+
/**
1277+
* The query context returned as part of response. This property is used for backend search. It's included for future feature releases and isn't currently used.
1278+
*/
1279+
export type SearchQueryContext = {
1280+
/** The query string as specified in the request. */
1281+
originalquery: string;
1282+
/**
1283+
* The query string that Dataverse search used to perform the query. Dataverse search uses the altered query string
1284+
* if the original query string contained spelling mistakes or didn't yield optimal results.
1285+
*/
1286+
alteredquery: string;
1287+
/** The reasons behind query alter decision by Dataverse search. */
1288+
reason: string[];
1289+
/** The spell suggestion that is the likely words that represent user's intent. Populated only when Dataverse alters the query search due to spell check. */
1290+
spellsuggestions: string[];
1291+
};
1292+
/**
1293+
* Represents a record in Dataverse.
1294+
*/
1295+
export type SearchQueryResult = {
1296+
/**
1297+
* The identifier of the record.
1298+
*/
1299+
Id: string;
1300+
/**
1301+
* The logical name of the table.
1302+
*/
1303+
EntityName: string;
1304+
/**
1305+
* The object type code.
1306+
*/
1307+
ObjectTypeCode: number;
1308+
/**
1309+
* Record attributes
1310+
*/
1311+
Attributes: Record<string, any>;
1312+
/**
1313+
* The highlights.
1314+
*/
1315+
Highlights: Record<string, string[]>;
1316+
/**
1317+
* The document score.
1318+
*/
1319+
Score: number;
1320+
};
1321+
export interface SuggestResponseValue<TDocument = any> {
1322+
/**
1323+
* Provides the suggested text.
1324+
* @deprecated Use "Text" instead.
1325+
*/
1326+
text: string;
1327+
/**
1328+
* Provides the suggested text.
1329+
*/
1330+
Text: string;
1331+
/**
1332+
* The document.
1333+
* @deprecated Use "Document" instead.
1334+
*/
1335+
document: TDocument;
1336+
/**
1337+
* The document.
1338+
*/
1339+
Document: TDocument;
1340+
}
11251341
export {};
11261342
//# sourceMappingURL=dynamics-web-api.d.ts.map

0 commit comments

Comments
 (0)