gd-sprest 7.7.0 → 7.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { IBaseExecution } from "gd-sprest-def/lib/base";
2
- import { SearchRequest } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/complextypes";
2
+ import { SearchRequest, SearchResult } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST";
3
3
  import { ISearchService } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/entitytypes";
4
4
  import { ITargetInfoProps } from "../utils";
5
5
 
@@ -9,6 +9,17 @@ import { ITargetInfoProps } from "../utils";
9
9
  */
10
10
  export const Search: ISearch;
11
11
 
12
+ /**
13
+ * Search Post Query
14
+ */
15
+ export interface ISearchPostQuery {
16
+ onQueryCompleted?: (results: SearchResult) => void;
17
+ query: SearchRequest
18
+ targetInfo?: ITargetInfoProps;
19
+ url?: string;
20
+ useBatch?: boolean;
21
+ }
22
+
12
23
  /**
13
24
  * Search
14
25
  * @category Search
@@ -31,11 +42,17 @@ export interface ISearch {
31
42
  * Method to get the query from the search parameters.
32
43
  * @param parameters - The search parameters.
33
44
  */
34
- getQuery: (parameters: SearchRequest /* | Microsoft.Office.Server.Search.REST.SearchSuggestion*/) => Array<string>;
45
+ getQuery(parameters: SearchRequest): Array<string>;
35
46
 
36
47
  /**
37
48
  * Method to get the url of a site, by its id.
38
49
  * @param id - The site id.
39
50
  */
40
51
  getUrlById(id: string): IBaseExecution<{ GetUrlById: string }>;
52
+
53
+ /**
54
+ * Method to execute a post query
55
+ * @param
56
+ */
57
+ postQuery(props: ISearchPostQuery): PromiseLike<SearchResult>;
41
58
  }
@@ -41,3 +41,95 @@ exports.Search.getQuery = function (parameters) {
41
41
  // Return the query
42
42
  return [query];
43
43
  };
44
+ // Static post query method
45
+ exports.Search.postQuery = function (props) {
46
+ // Return a promise
47
+ return new Promise(function (resolve, reject) {
48
+ var queryProps = props.query;
49
+ // Query the first batch
50
+ exports.Search(props.url, props.targetInfo).postquery(queryProps).execute(
51
+ // Success
52
+ function (request) {
53
+ // Updates the table
54
+ var updateRequest = function (searchResult) {
55
+ // Call the event
56
+ props.onQueryCompleted ? props.onQueryCompleted(searchResult) : null;
57
+ // Parse rows
58
+ for (var i = 0; i < searchResult.PrimaryQueryResult.RelevantResults.Table.Rows.results.length; i++) {
59
+ var row = searchResult.PrimaryQueryResult.RelevantResults.Table.Rows.results[i];
60
+ // Append the row
61
+ request.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results.push(row);
62
+ }
63
+ };
64
+ // Call the event
65
+ props.onQueryCompleted ? props.onQueryCompleted(request.postquery) : null;
66
+ // See if more results exist
67
+ var results = request.postquery.PrimaryQueryResult.RelevantResults;
68
+ if (results.TotalRows > results.RowCount) {
69
+ var search = exports.Search(props.url, props.targetInfo);
70
+ var useBatch = typeof (props.useBatch) === "boolean" ? props.useBatch : true;
71
+ // Compute the row count
72
+ var rowCount = 500;
73
+ if (typeof (queryProps.RowLimit) === "number") {
74
+ // Set the custom limit
75
+ rowCount = queryProps.RowLimit;
76
+ }
77
+ else {
78
+ // Default to the max size
79
+ queryProps.RowLimit = rowCount;
80
+ }
81
+ // Compute the total # of requests that we need to make
82
+ var totalPages = Math.ceil(results.TotalRows / rowCount);
83
+ // Loop for the total # of requests
84
+ for (var i = 0; i < totalPages; i++) {
85
+ // Set the start row
86
+ queryProps.StartRow = i * rowCount;
87
+ // See if we are making a batch request
88
+ if (useBatch) {
89
+ // Create a batch request
90
+ search.postquery(queryProps).batch(
91
+ // Success
92
+ function (batchRequest) {
93
+ // Update the request
94
+ updateRequest(batchRequest.postquery);
95
+ },
96
+ // Limit to 100 per request
97
+ i % 100 == 0);
98
+ }
99
+ else {
100
+ // Create the request
101
+ search.postquery(queryProps).execute(
102
+ // Success
103
+ function (batchRequest) {
104
+ // Update the request
105
+ updateRequest(batchRequest.postquery);
106
+ },
107
+ // Wait for the previous request to complete
108
+ true);
109
+ }
110
+ }
111
+ // See if we are making a batch request
112
+ if (useBatch) {
113
+ // Execute the batch requests
114
+ search.execute(function () {
115
+ // Resolve the request
116
+ resolve(request.postquery);
117
+ }, reject);
118
+ }
119
+ else {
120
+ // Wait for the requests to complete
121
+ search.done(function () {
122
+ // Resolve the request
123
+ resolve(request.postquery);
124
+ });
125
+ }
126
+ }
127
+ else {
128
+ // Resolve the request
129
+ resolve(request.postquery);
130
+ }
131
+ },
132
+ // Error
133
+ reject);
134
+ });
135
+ };
package/build/rest.js CHANGED
@@ -8,7 +8,7 @@ var sptypes_1 = require("./sptypes");
8
8
  * SharePoint REST Library
9
9
  */
10
10
  exports.$REST = {
11
- __ver: 7.70,
11
+ __ver: 7.71,
12
12
  AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); },
13
13
  Apps: Lib.Apps,
14
14
  ContextInfo: Lib.ContextInfo,
@@ -464,7 +464,7 @@ exports.Request = {
464
464
  return xml.nodeValue;
465
465
  }
466
466
  // Return the collection if it exists, otherwise the object
467
- return results ? results : objData;
467
+ return results ? { results: results } : objData;
468
468
  },
469
469
  // Method to convert the input arguments into an object
470
470
  updateDataObject: function (base, isBatchRequest, batchIdx) {
@@ -9,7 +9,7 @@
9
9
  // ../gd-sprest-def/lib/Microsoft/SharePoint/Portal/entitytypes
10
10
  // ../gd-sprest-def/lib/Microsoft/SharePoint/Navigation/REST/entitytypes
11
11
  // ../gd-sprest-def/lib/SP/UserProfiles/entitytypes
12
- // ../gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/complextypes
12
+ // ../gd-sprest-def/lib/Microsoft/Office/Server/Search/REST
13
13
  // ../gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/entitytypes
14
14
  // ../gd-sprest-def/lib/SP/Publishing/entitytypes
15
15
  // ../gd-sprest-def/lib/SP/Social/complextypes
@@ -1569,7 +1569,7 @@ declare module 'gd-sprest/lib/profileLoader' {
1569
1569
 
1570
1570
  declare module 'gd-sprest/lib/search' {
1571
1571
  import { IBaseExecution } from "gd-sprest-def/lib/base";
1572
- import { SearchRequest } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/complextypes";
1572
+ import { SearchRequest, SearchResult } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST";
1573
1573
  import { ISearchService } from "gd-sprest-def/lib/Microsoft/Office/Server/Search/REST/entitytypes";
1574
1574
  import { ITargetInfoProps } from "gd-sprest/utils";
1575
1575
 
@@ -1579,6 +1579,17 @@ declare module 'gd-sprest/lib/search' {
1579
1579
  */
1580
1580
  export const Search: ISearch;
1581
1581
 
1582
+ /**
1583
+ * Search Post Query
1584
+ */
1585
+ export interface ISearchPostQuery {
1586
+ onQueryCompleted?: (results: SearchResult) => void;
1587
+ query: SearchRequest
1588
+ targetInfo?: ITargetInfoProps;
1589
+ url?: string;
1590
+ useBatch?: boolean;
1591
+ }
1592
+
1582
1593
  /**
1583
1594
  * Search
1584
1595
  * @category Search
@@ -1601,13 +1612,19 @@ declare module 'gd-sprest/lib/search' {
1601
1612
  * Method to get the query from the search parameters.
1602
1613
  * @param parameters - The search parameters.
1603
1614
  */
1604
- getQuery: (parameters: SearchRequest /* | Microsoft.Office.Server.Search.REST.SearchSuggestion*/) => Array<string>;
1615
+ getQuery(parameters: SearchRequest): Array<string>;
1605
1616
 
1606
1617
  /**
1607
1618
  * Method to get the url of a site, by its id.
1608
1619
  * @param id - The site id.
1609
1620
  */
1610
1621
  getUrlById(id: string): IBaseExecution<{ GetUrlById: string }>;
1622
+
1623
+ /**
1624
+ * Method to execute a post query
1625
+ * @param
1626
+ */
1627
+ postQuery(props: ISearchPostQuery): PromiseLike<SearchResult>;
1611
1628
  }
1612
1629
  }
1613
1630