@progress/sitefinity-webservices-sdk 0.3.0 → 1.0.2

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.
Files changed (201) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +19 -0
  3. package/ci/pipelines/ci.yml +219 -0
  4. package/config/helpers.js +0 -6
  5. package/config/webpack.common.js +1 -3
  6. package/config/webpack.dev.js +2 -9
  7. package/config/webpack.prod.js +5 -6
  8. package/dist/docs/.nojekyll +1 -0
  9. package/dist/docs/assets/highlight.css +57 -0
  10. package/dist/docs/assets/icons.css +1043 -0
  11. package/dist/docs/assets/icons.png +0 -0
  12. package/dist/docs/assets/icons@2x.png +0 -0
  13. package/dist/docs/assets/main.js +52 -0
  14. package/dist/docs/assets/search.js +1 -0
  15. package/dist/docs/assets/style.css +1413 -0
  16. package/dist/docs/assets/{images/widgets.png → widgets.png} +0 -0
  17. package/dist/docs/assets/{images/widgets@2x.png → widgets@2x.png} +0 -0
  18. package/dist/docs/classes/BlobBuilder.BlobBuilder-1.html +7 -0
  19. package/dist/docs/classes/Data.Data-1.html +65 -0
  20. package/dist/docs/classes/Expression.BinaryExpression.html +1 -0
  21. package/dist/docs/classes/Expression.ComplexExpression.html +1 -0
  22. package/dist/docs/classes/Expression.ExpressionBase.html +1 -0
  23. package/dist/docs/classes/OrderProperty.OrderProperty-1.html +1 -0
  24. package/dist/docs/classes/Query.Query-1.html +33 -0
  25. package/dist/docs/classes/QueryBase.QueryBase-1.html +7 -0
  26. package/dist/docs/classes/QueryBuilder.QueryBuilder-1.html +1 -0
  27. package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +17 -0
  28. package/dist/docs/classes/Requests_BatchRequest.Transaction.html +17 -0
  29. package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +1 -0
  30. package/dist/docs/classes/Requests_Request.CreateRelatedRequest.html +1 -0
  31. package/dist/docs/classes/Requests_Request.CreateRequest.html +1 -0
  32. package/dist/docs/classes/Requests_Request.DeleteRelatedByIdRequest.html +1 -0
  33. package/dist/docs/classes/Requests_Request.DeleteRelatedRequest.html +1 -0
  34. package/dist/docs/classes/Requests_Request.DeleteRequest.html +1 -0
  35. package/dist/docs/classes/Requests_Request.GetByIdRequest.html +1 -0
  36. package/dist/docs/classes/Requests_Request.GetRelatedByIdRequest.html +1 -0
  37. package/dist/docs/classes/Requests_Request.GetRelatedRequest.html +1 -0
  38. package/dist/docs/classes/Requests_Request.GetRequest.html +1 -0
  39. package/dist/docs/classes/Requests_Request.UpdateRequest.html +1 -0
  40. package/dist/docs/classes/Requests_Request.UploadRequest.html +1 -0
  41. package/dist/docs/classes/Requests_RequestBase.RequestBase.html +1 -0
  42. package/dist/docs/classes/Requests_RequestFactory.RequestFactory.html +1 -0
  43. package/dist/docs/classes/Sitefinity.Sitefinity-1.html +5 -0
  44. package/dist/docs/classes/WhereQuery.WhereQuery-1.html +31 -0
  45. package/dist/docs/classes/utils.utils-1.html +1 -0
  46. package/dist/docs/index.html +54 -242
  47. package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +1 -0
  48. package/dist/docs/interfaces/Data.CreateRequestOptions.html +1 -0
  49. package/dist/docs/interfaces/Data.OperationsRequestOptions.html +1 -0
  50. package/dist/docs/interfaces/Data.PropertyRequestOptions.html +1 -0
  51. package/dist/docs/interfaces/Data.RequestOptionsBase.html +1 -0
  52. package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +1 -0
  53. package/dist/docs/interfaces/Data.UpdateRequestOptions.html +1 -0
  54. package/dist/docs/interfaces/Data.UploadRequestOptions.html +1 -0
  55. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRelatedRequestOptions.html +1 -0
  56. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRequestOptions.html +1 -0
  57. package/dist/docs/interfaces/Requests_BatchRequest.BatchPropertyRequestOptions.html +1 -0
  58. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsBase.html +1 -0
  59. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsExtended.html +1 -0
  60. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleItemRequestOptions.html +1 -0
  61. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleRelatedItemRequestOptions.html +1 -0
  62. package/dist/docs/interfaces/Requests_BatchRequest.BatchUpdateRequestOptions.html +1 -0
  63. package/dist/docs/interfaces/Requests_ExecutableRequest.ResponseHandlers.html +5 -0
  64. package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +1 -0
  65. package/dist/docs/interfaces/Requests_Request.PutRequestOptionsExtended.html +1 -0
  66. package/dist/docs/interfaces/Requests_Request.RelatedByIdRequestOptionsExtended.html +1 -0
  67. package/dist/docs/interfaces/Requests_Request.RelatedRequestOptionsExtended.html +1 -0
  68. package/dist/docs/interfaces/Requests_Request.UploadRequestOptionsExtended.html +1 -0
  69. package/dist/docs/interfaces/Requests_RequestBase.RequestOptionsBaseExtended.html +1 -0
  70. package/dist/docs/interfaces/Sitefinity.SDKOptions.html +9 -0
  71. package/dist/docs/interfaces/Sitefinity.Token.html +1 -0
  72. package/dist/docs/interfaces/Sitefinity.TypeOptions.html +13 -0
  73. package/dist/docs/modules/BlobBuilder.html +1 -0
  74. package/dist/docs/modules/Data.html +1 -0
  75. package/dist/docs/modules/Expression.html +1 -0
  76. package/dist/docs/modules/OrderProperty.html +1 -0
  77. package/dist/docs/modules/Query.html +1 -0
  78. package/dist/docs/modules/QueryBase.html +1 -0
  79. package/dist/docs/modules/QueryBuilder.html +1 -0
  80. package/dist/docs/modules/Requests_BatchRequest.html +1 -0
  81. package/dist/docs/modules/Requests_ExecutableRequest.html +1 -0
  82. package/dist/docs/modules/Requests_Request.html +1 -0
  83. package/dist/docs/modules/Requests_RequestBase.html +1 -0
  84. package/dist/docs/modules/Requests_RequestFactory.html +1 -0
  85. package/dist/docs/modules/Sitefinity.html +1 -0
  86. package/dist/docs/modules/WhereQuery.html +1 -0
  87. package/dist/docs/modules/constants.html +1 -0
  88. package/dist/docs/modules/utils.html +1 -0
  89. package/dist/docs/modules.html +1 -0
  90. package/dist/samples.html +33 -81
  91. package/dist/sitefinity-webservices-sdk.d.ts +16 -0
  92. package/dist/sitefinity-webservices-sdk.js +1140 -1734
  93. package/dist/sitefinity-webservices-sdk.js.map +1 -1
  94. package/dist/sitefinity-webservices-sdk.min.js +2 -16
  95. package/dist/sitefinity-webservices-sdk.min.js.LICENSE.txt +14 -0
  96. package/dist/src/BlobBuilder.d.ts +14 -0
  97. package/dist/src/Data.d.ts +144 -0
  98. package/dist/src/Expression.d.ts +19 -0
  99. package/dist/src/OrderProperty.d.ts +8 -0
  100. package/dist/src/Query.d.ts +59 -0
  101. package/dist/src/QueryBase.d.ts +18 -0
  102. package/dist/src/QueryBuilder.d.ts +13 -0
  103. package/dist/src/Requests/BatchRequest.d.ts +146 -0
  104. package/dist/src/Requests/ExecutableRequest.d.ts +20 -0
  105. package/dist/src/Requests/Request.d.ts +88 -0
  106. package/dist/src/Requests/RequestBase.d.ts +28 -0
  107. package/dist/src/Requests/RequestFactory.d.ts +22 -0
  108. package/dist/src/Sitefinity.d.ts +66 -0
  109. package/dist/src/WhereQuery.d.ts +68 -0
  110. package/dist/src/constants.d.ts +55 -0
  111. package/dist/src/utils.d.ts +16 -0
  112. package/karma.conf.js +29 -0
  113. package/package-lock.json +16108 -6805
  114. package/package.json +28 -10
  115. package/sitefinity-webservices-sdk.ts +16 -0
  116. package/src/BlobBuilder.ts +7 -12
  117. package/src/Data.spec.ts +160 -0
  118. package/src/Data.ts +132 -207
  119. package/src/Expression.ts +0 -1
  120. package/src/OrderProperty.ts +4 -5
  121. package/src/Query.ts +52 -78
  122. package/src/QueryBase.ts +21 -47
  123. package/src/QueryBuilder.ts +68 -83
  124. package/src/Requests/BatchRequest.ts +312 -335
  125. package/src/Requests/ExecutableRequest.ts +46 -73
  126. package/src/Requests/Request.ts +134 -260
  127. package/src/Requests/RequestBase.ts +161 -0
  128. package/src/Requests/RequestFactory.ts +36 -54
  129. package/src/Requests/request.spec.ts +108 -0
  130. package/src/Sitefinity.spec.ts +418 -0
  131. package/src/Sitefinity.ts +77 -146
  132. package/src/WhereQuery.ts +52 -112
  133. package/src/constants.ts +58 -39
  134. package/src/utils.ts +17 -14
  135. package/template.html +33 -35
  136. package/tsconfig.json +8 -1
  137. package/type.txt +1 -1
  138. package/config/html.conf.json +0 -5
  139. package/dist/docs/assets/css/main.css +0 -865
  140. package/dist/docs/assets/css/main.css.map +0 -7
  141. package/dist/docs/assets/images/icons.png +0 -0
  142. package/dist/docs/assets/images/icons@2x.png +0 -0
  143. package/dist/docs/assets/js/main.js +0 -5
  144. package/dist/docs/assets/js/search.js +0 -3
  145. package/dist/docs/classes/_authentication_.authentication.html +0 -527
  146. package/dist/docs/classes/_blobbuilder_.blobbuilder.html +0 -351
  147. package/dist/docs/classes/_data_.data.html +0 -974
  148. package/dist/docs/classes/_expression_.binaryexpression.html +0 -450
  149. package/dist/docs/classes/_expression_.complexexpression.html +0 -374
  150. package/dist/docs/classes/_expression_.expressionbase.html +0 -336
  151. package/dist/docs/classes/_orderproperty_.orderproperty.html +0 -381
  152. package/dist/docs/classes/_query_.query.html +0 -896
  153. package/dist/docs/classes/_querybase_.querybase.html +0 -518
  154. package/dist/docs/classes/_querybuilder_.querybuilder.html +0 -493
  155. package/dist/docs/classes/_requests_batchrequest_.batchrequest.html +0 -1511
  156. package/dist/docs/classes/_requests_batchrequest_.transaction.html +0 -804
  157. package/dist/docs/classes/_requests_executablerequest_.executablerequest.html +0 -549
  158. package/dist/docs/classes/_requests_request_.createrelatedrequest.html +0 -689
  159. package/dist/docs/classes/_requests_request_.createrequest.html +0 -680
  160. package/dist/docs/classes/_requests_request_.deleterelatedbyidrequest.html +0 -687
  161. package/dist/docs/classes/_requests_request_.deleterelatedrequest.html +0 -673
  162. package/dist/docs/classes/_requests_request_.deleterequest.html +0 -666
  163. package/dist/docs/classes/_requests_request_.getbyidrequest.html +0 -666
  164. package/dist/docs/classes/_requests_request_.getrelatedbyidrequest.html +0 -687
  165. package/dist/docs/classes/_requests_request_.getrelatedrequest.html +0 -673
  166. package/dist/docs/classes/_requests_request_.getrequest.html +0 -658
  167. package/dist/docs/classes/_requests_request_.requestbase.html +0 -687
  168. package/dist/docs/classes/_requests_request_.updaterequest.html +0 -686
  169. package/dist/docs/classes/_requests_request_.uploadrequest.html +0 -715
  170. package/dist/docs/classes/_requests_requestfactory_.requestfactory.html +0 -724
  171. package/dist/docs/classes/_sitefinity_.sitefinity.html +0 -521
  172. package/dist/docs/classes/_utils_.utils.html +0 -597
  173. package/dist/docs/classes/_wherequery_.wherequery.html +0 -992
  174. package/dist/docs/globals.html +0 -238
  175. package/dist/docs/modules/_authentication_.html +0 -225
  176. package/dist/docs/modules/_blobbuilder_.html +0 -225
  177. package/dist/docs/modules/_constants_.html +0 -528
  178. package/dist/docs/modules/_contenttypes_.html +0 -248
  179. package/dist/docs/modules/_data_.html +0 -225
  180. package/dist/docs/modules/_expression_.html +0 -233
  181. package/dist/docs/modules/_headers_.html +0 -328
  182. package/dist/docs/modules/_httpmethods_.html +0 -288
  183. package/dist/docs/modules/_main_.html +0 -209
  184. package/dist/docs/modules/_orderproperty_.html +0 -225
  185. package/dist/docs/modules/_query_.html +0 -225
  186. package/dist/docs/modules/_querybase_.html +0 -225
  187. package/dist/docs/modules/_querybuilder_.html +0 -247
  188. package/dist/docs/modules/_requests_batchrequest_.html +0 -265
  189. package/dist/docs/modules/_requests_executablerequest_.html +0 -296
  190. package/dist/docs/modules/_requests_request_.html +0 -333
  191. package/dist/docs/modules/_requests_requestfactory_.html +0 -247
  192. package/dist/docs/modules/_sitefinity_.html +0 -225
  193. package/dist/docs/modules/_utils_.html +0 -225
  194. package/dist/docs/modules/_wherequery_.html +0 -247
  195. package/dist/index.html +0 -474
  196. package/src/Authentication.ts +0 -96
  197. package/src/ContentTypes.ts +0 -5
  198. package/src/Headers.ts +0 -12
  199. package/src/HttpMethods.ts +0 -9
  200. package/src/main.ts +0 -2
  201. package/version.txt +0 -1
package/src/Query.ts CHANGED
@@ -4,28 +4,26 @@ import { OrderProperty } from './OrderProperty';
4
4
  import { QueryBuilder } from './QueryBuilder';
5
5
 
6
6
  /**
7
- * @classdesc The query class is used for constructing queries.
8
- * @class Query
9
- * @augments QueryBase
7
+ * The query class is used for constructing queries.
10
8
  * @example
11
- * var query = new Sitefinity.Query();
12
- * var query0 = query.where().and().endsWith("Title", "Record").done().or().startsWith('Title', 'asd').done().done();
13
- * var query1 = query.where().or().endsWith("Record", "Title").ne('age', '15').eq('Content', 'test').done().done();
14
- * var query2 = query.where().and().endsWith("Title", "Record").done().done();
15
- * var query3 = query.where().endsWith("Record", "Title").or().ne('age', '15').eq('Content', 'test').done().done();
16
- * var query4 = query.where().not().endsWith("Record", "Title").done().and().not().eq('Content', 'test').done().done().done();
17
- * var query5 = query.where().not().and().endsWith("Record", "Title").eq('Content', 'test').done().done().done();
18
- * var query6 = query.select("Id", "Title", "Content").expand('Tags').order("Title desc").where().ne('Title', 'zzz').eq('Title', 'newTitle').done()//.count();
19
- * var query7 = query.order("Title desc").where().eq('Title', 'newTitleUPDATE1').done().select("Title", "Content");
20
- * var query8 = query.where().eq('Title', 'newTitleN11').done();
9
+ * const query = new Sitefinity.Query();
10
+ * const query0 = query.where().and().endsWith("Title", "Record").done().or().startsWith('Title', 'asd').done().done();
11
+ * const query1 = query.where().or().endsWith("Record", "Title").ne('age', '15').eq('Content', 'test').done().done();
12
+ * const query2 = query.where().and().endsWith("Title", "Record").done().done();
13
+ * const query3 = query.where().endsWith("Record", "Title").or().ne('age', '15').eq('Content', 'test').done().done();
14
+ * const query4 = query.where().not().endsWith("Record", "Title").done().and().not().eq('Content', 'test').done().done().done();
15
+ * const query5 = query.where().not().and().endsWith("Record", "Title").eq('Content', 'test').done().done().done();
16
+ * const query6 = query.select("Id", "Title", "Content").expand('Tags').order("Title desc").where().ne('Title', 'zzz').eq('Title', 'newTitle').done()//.count();
17
+ * const query7 = query.order("Title desc").where().eq('Title', 'newTitleUPDATE1').done().select("Title", "Content");
18
+ * const query8 = query.where().eq('Title', 'newTitleN11').done();
21
19
  */
22
20
  export class Query extends QueryBase {
23
- protected _order: any = null;
24
- protected _skip: any = null;
25
- protected _take: any = null;
26
- protected _search: any = null;
27
- protected _count: any = null;
28
- private expr: any = null;
21
+ orderProperties: OrderProperty[] = null;
22
+ skipValue: number = null;
23
+ takeValue: number = null;
24
+ searchValue: string = null;
25
+ inlineCount: boolean;
26
+ filter: WhereQuery<Query> = null;
29
27
 
30
28
  constructor() {
31
29
  super();
@@ -33,99 +31,75 @@ export class Query extends QueryBase {
33
31
 
34
32
  /**
35
33
  * Begins a where clause for filtering the items.
36
- * @memberOf Query
37
- * @returns {@link WhereQuery}
38
34
  */
39
- where() {
40
- var clone = this._clone((newObj) => {
41
- newObj.expr = new WhereQuery(newObj);
35
+ where(): WhereQuery<Query> {
36
+ const clone: Query = this.clone((newObj: Query) => {
37
+ newObj.filter = new WhereQuery(newObj);
42
38
  });
43
39
 
44
- return clone.expr;
40
+ return clone.filter;
45
41
  }
46
42
 
47
-
48
43
  /**
49
44
  * Specifies the order by clause.
50
- * @memberOf Query
51
45
  * @example
52
- * // filter by single field
46
+ * order by single field
53
47
  * order("Title desc")
54
48
  * @example
55
- * // filter by multiple fields
49
+ * order by multiple fields
56
50
  * order("Title desc", "Description asc")
57
- * @returns {@link Query}
58
51
  */
59
- order() {
60
- var orderPropPaths = this._extractArguments(arguments);
61
- this._validatePropertyPaths(orderPropPaths);
52
+ order(...properties: string[]): Query {
53
+ properties = properties ?? [];
54
+ this.validatePropertyPaths(properties);
62
55
 
63
- return this._clone(function (newObj) {
64
- var orderItems = [];
65
- for (var i = 0; i < orderPropPaths.length; i++) {
66
- var member = orderPropPaths[i];
67
- var orderProp = new OrderProperty(member);
56
+ return this.clone((newObj: Query) => {
57
+ const orderItems: OrderProperty[] = [];
58
+ for (let i = 0; i < properties.length; i++) {
59
+ const member = properties[i];
60
+ const orderProp = new OrderProperty(member);
68
61
  orderItems.push(orderProp);
69
62
  }
70
- newObj._order = orderItems;
63
+ newObj.orderProperties = orderItems;
71
64
  });
72
65
  }
73
66
 
74
- /** Skips a certain number of items from the beginning before returning the rest of the items. Used for paging.
75
- * @memberOf Query.prototype
76
- * @method skip
77
- * @see [query.take]{@link query.take}
78
- * @param {number} value The number of items to skip.
79
- * @returns {Query}
67
+ /**
68
+ * Skips a certain number of items from the beginning before returning the rest of the items. Used for paging.
80
69
  */
81
- skip(value: number) {
82
- // validate
83
- return this._clone((newObj) => {
84
- newObj._skip = value;
70
+ skip(value: number): Query {
71
+ return this.clone((newObj: Query) => {
72
+ newObj.skipValue = value;
85
73
  });
86
74
  }
87
75
 
88
- /** Takes a specified number of items from the query result. Used for paging.
89
- * @memberOf Query.prototype
90
- * @param {number} value The number of items to take.
91
- * @returns {Query}
76
+ /**
77
+ * Takes a specified number of items from the query result. Used for paging.
92
78
  */
93
- take(value: number) {
94
- return this._clone(function (newObj) {
95
- newObj._take = value;
79
+ take(value: number): Query {
80
+ return this.clone((newObj: Query) => {
81
+ newObj.takeValue = value;
96
82
  });
97
83
  }
98
84
 
99
- /** Searches for the items matching the specified expression.
100
- * @memberOf Query.prototype
101
- * @param {string} value The search expression.
102
- * @returns {Query}
85
+ /**
86
+ * Searches for the items matching the specified expression.
103
87
  */
104
- search(value: string) {
105
- return this._clone(function (newObj) {
106
- newObj._search = value;
88
+ search(value: string): Query {
89
+ return this.clone((newObj: Query) => {
90
+ newObj.searchValue = value;
107
91
  });
108
92
  }
109
93
 
110
- /** Returns the total item count with the result. Used for paging.
111
- * @memberOf Query.prototype
112
- * @param {inline} inline Whether to return only the count of the items with or without their JSON representation.
113
- * @returns {Query}
94
+ /**
95
+ * Returns the total item count with the result. Used for paging.
114
96
  */
115
- count(inline: boolean = true) {
116
- return this._clone(function (newObj) {
117
- newObj._count = inline;
97
+ count(inline = true): Query {
98
+ return this.clone((newObj: Query) => {
99
+ newObj.inlineCount = inline;
118
100
  });
119
101
  }
120
102
 
121
- _getFilter() {
122
- return this.expr;
123
- }
124
-
125
- _getOrderBy() {
126
- return this._order;
127
- }
128
-
129
103
  build() {
130
104
  return new QueryBuilder(this).build();
131
105
  }
package/src/QueryBase.ts CHANGED
@@ -1,70 +1,45 @@
1
1
  import { utils } from './utils';
2
2
 
3
3
  /**
4
- * @classdesc The base class for dealing with queries.
5
- * @class QueryBase
4
+ * The base class for dealing with queries.
6
5
  */
7
6
  export class QueryBase {
8
- private _select: any;
9
- private _expand: any;
7
+ selectProperties: string[];
8
+ expandProperties: string[];
9
+
10
10
  constructor() {
11
- this._select = null;
12
- this._expand = null;
11
+ this.selectProperties = null;
12
+ this.expandProperties = null;
13
13
  }
14
14
 
15
15
  /**
16
16
  * Selects which fields will be returned when querying the service.
17
- * @memberOf QueryBase
18
- * @instance
19
- * @param {string} arguments - an array of fields to include in the $select statement.
20
- * @returns {QueryBase}
21
17
  */
22
- select() {
23
- var selectPropPaths = this._extractArguments(arguments);
18
+ select(...properties: string[]): QueryBase {
19
+ properties = properties ?? [];
24
20
 
25
- this._validatePropertyPaths(selectPropPaths);
21
+ this.validatePropertyPaths(properties);
26
22
 
27
- return this._clone((newObj) => {
28
- newObj._select = selectPropPaths.filter((prop, index, props) => props.indexOf(prop) === index);
23
+ return this.clone((newObj: QueryBase) => {
24
+ newObj.selectProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
29
25
  });
30
26
  }
31
27
 
32
28
  /**
33
29
  * Selects which navigation properties will be returned when querying the service.
34
- * @memberOf QueryBase
35
- * @instance
36
- * @param {string} arguments - an array of fields to include in the $expand statement.
37
- * @returns {QueryBase}
38
30
  */
39
- expand() {
40
- var propPaths = this._extractArguments(arguments);
41
- this._validatePropertyPaths(propPaths);
31
+ expand(...properties: string[]): QueryBase {
32
+ properties = properties ?? [];
33
+ this.validatePropertyPaths(properties);
42
34
 
43
- return this._clone(function (newObj) {
44
- newObj._expand = propPaths.filter((prop, index, props) => props.indexOf(prop) === index);
35
+ return this.clone((newObj: QueryBase) => {
36
+ newObj.expandProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
45
37
  });
46
38
  }
47
39
 
48
- _extractArguments(arg: IArguments) {
49
- var values = [];
50
- for (var index = 0; index < arg.length; index++) {
51
- values.push(arg[index]);
52
- }
53
-
54
- return values;
55
- }
56
-
57
- _getSelect() {
58
- return this._select;
59
- }
60
-
61
- _getExpand() {
62
- return this._expand;
63
- }
64
-
65
- _validatePropertyPaths(propPaths: any, allowNested: boolean = false) {
66
- for (var i = 0; i < propPaths.length; i++) {
67
- var member = propPaths[i];
40
+ protected validatePropertyPaths(propPaths: string[], allowNested = false) {
41
+ for (let i = 0; i < propPaths.length; i++) {
42
+ const member = propPaths[i];
68
43
  if (!utils.isString(member)) {
69
44
  throw new Error('Invalid argument in clause');
70
45
  }
@@ -75,9 +50,8 @@ export class QueryBase {
75
50
  }
76
51
  }
77
52
 
78
- _clone(setter: any = null) {
79
- var newObj = utils.clone(this, new QueryBase(), setter);
80
-
53
+ protected clone(setter: Function = null) {
54
+ const newObj = utils.clone(this, new QueryBase(), setter);
81
55
  return newObj;
82
56
  }
83
57
  }
@@ -2,109 +2,97 @@
2
2
  import { ComplexExpression, BinaryExpression } from './Expression';
3
3
  import { OrderProperty } from './OrderProperty';
4
4
  import { utils } from './utils';
5
-
6
- var constants = require('./constants').default;
5
+ import { ODATA_PARAMS, EXPRESSION_TYPE } from "./constants";
6
+ import { Query } from "./Query";
7
7
 
8
8
  export class QueryBuilder {
9
- constructor(private query: any) {
10
-
11
- }
12
-
13
- build(): any {
14
- var queryParameters = {};
15
- this._buildODataQueryParams(this.query, queryParameters);
16
- return queryParameters;
9
+ constructor(private query: Query) {
17
10
  }
18
11
 
19
- private _buildODataQueryParams(query, queryParameters) {
20
- var queryParams = constants.ODataParams;
21
-
22
- var whereClause = query._getFilter();
12
+ build(): { [key: string]: string } {
13
+ const queryParameters = {};
14
+ const whereClause = this.query.filter;
23
15
  if (whereClause instanceof WhereQuery) {
24
- var expression = whereClause._getExpression();
16
+ const expression = whereClause.getExpression();
25
17
  if (expression instanceof ComplexExpression) {
26
- var result = this._buildComplexExpression(expression, null);
18
+ const result = this.buildComplexExpression(expression, null);
27
19
  if (result) {
28
- queryParameters[queryParams.$filter] = result;
20
+ queryParameters[ODATA_PARAMS.$filter] = result;
29
21
  }
30
22
  }
31
23
  }
32
24
 
33
- var selectClause = query._getSelect();
25
+ const selectClause = this.query.selectProperties;
34
26
  if (selectClause instanceof Array) {
35
- queryParameters[queryParams.$select] = selectClause.join(', ');
27
+ queryParameters[ODATA_PARAMS.$select] = selectClause.join(', ');
36
28
  }
37
29
 
38
- var expandClause = query._getExpand();
30
+ const expandClause = this.query.expandProperties;
39
31
  if (expandClause instanceof Array)
40
- queryParameters[queryParams.$expand] = expandClause.join(', ');
32
+ queryParameters[ODATA_PARAMS.$expand] = expandClause.join(', ');
41
33
 
42
- var orderByClause = query._order;
34
+ const orderByClause = this.query.orderProperties;
43
35
  if (orderByClause instanceof Array) {
44
- var order = [];
45
- for (var i in orderByClause) {
36
+ const order = [];
37
+ for (const i in orderByClause) {
46
38
  if (orderByClause[i] instanceof OrderProperty)
47
39
  order.push(orderByClause[i].getValue());
48
40
  }
49
- queryParameters[queryParams.$orderby] = order.join(', ');
41
+ queryParameters[ODATA_PARAMS.$orderby] = order.join(', ');
50
42
  }
51
43
 
52
- var take = query._take;
44
+ const take = this.query.takeValue;
53
45
  if (utils.isNumber(take))
54
- queryParameters[queryParams.$top] = take;
46
+ queryParameters[ODATA_PARAMS.$top] = take;
55
47
 
56
- var skip = query._skip;
48
+ const skip = this.query.skipValue;
57
49
  if (utils.isNumber(skip))
58
- queryParameters[queryParams.$skip] = skip;
50
+ queryParameters[ODATA_PARAMS.$skip] = skip;
59
51
 
60
- var search = query._search;
52
+ const search = this.query.searchValue;
61
53
  if (search)
62
- queryParameters[queryParams.$search] = search;
54
+ queryParameters[ODATA_PARAMS.$search] = search;
63
55
 
64
- var count = query._count;
65
-
66
- // means that the count is required inline
67
- if (count !== null) {
68
- queryParameters[queryParams.$count] = count;
56
+ if (this.query.inlineCount !== null) {
57
+ queryParameters[ODATA_PARAMS.$count] = this.query.inlineCount;
69
58
  }
70
59
 
71
60
  return queryParameters;
72
61
  }
73
62
 
74
- private _buildComplexExpression(expression, parent) {
63
+ private buildComplexExpression(expression: ComplexExpression, parent: string): string {
75
64
  if (!(expression instanceof ComplexExpression))
76
65
  throw new Error('Invalid complex expression');
77
66
 
78
- var OperatorType = constants.ExpressionType;
79
- var counter = 0;
80
- var result = '';
81
- var subExpressions = expression.getExpressions();
67
+ let counter = 0;
68
+ let result = '';
69
+ const subExpressions = expression.getExpressions();
82
70
  if (!subExpressions.length) {
83
71
  return result;
84
72
  }
85
73
 
86
74
  while (true) {
87
- var currentExp = subExpressions[counter];
75
+ const currentExp = subExpressions[counter];
88
76
  if (currentExp instanceof BinaryExpression) {
89
- result += this._buildBinaryExpression(currentExp);
77
+ result += this.buildBinaryExpression(currentExp);
90
78
  }
91
79
  else if (currentExp instanceof ComplexExpression) {
92
- var complexResult = this._buildComplexExpression(currentExp, expression.type);
80
+ const complexResult = this.buildComplexExpression(currentExp, expression.type);
93
81
  if (complexResult) {
94
82
  result += '(' + complexResult + ')';
95
83
  }
96
84
  }
97
85
 
98
- if (expression.getType() === OperatorType.not)
86
+ if (expression.getType() === EXPRESSION_TYPE.not)
99
87
  result = expression.getType() + ' ' + result;
100
88
  // TODOSDK: Rethink this!
101
- if (expression.getType() === OperatorType.any) {
102
- var exprVal = [];
103
- for (var index = 0; index < subExpressions.length; index++) {
104
- if (subExpressions[index].type == OperatorType.contains || subExpressions[index].type == OperatorType.startsWith || subExpressions[index].type == OperatorType.endsWith)
89
+ if (expression.getType() === EXPRESSION_TYPE.any) {
90
+ const exprVal = [];
91
+ for (let index = 0; index < subExpressions.length; index++) {
92
+ if (subExpressions[index].type == EXPRESSION_TYPE.contains || subExpressions[index].type == EXPRESSION_TYPE.startsWith || subExpressions[index].type == EXPRESSION_TYPE.endsWith)
105
93
  exprVal.push(subExpressions[index].type.toLowerCase() + "(x, '" + (subExpressions[index] as BinaryExpression).constant + "')");
106
94
  else
107
- exprVal.push('x ' + subExpressions[index].type.toLowerCase() + ' ' + this._checkType((subExpressions[index] as BinaryExpression).constant));
95
+ exprVal.push('x ' + subExpressions[index].type.toLowerCase() + ' ' + this.checkType((subExpressions[index] as BinaryExpression).constant));
108
96
  }
109
97
  result = (currentExp as BinaryExpression).parameter + '/' + expression.getType() + '(x:' + exprVal.join(' ' + parent + ' ') + ')';
110
98
  }
@@ -119,52 +107,49 @@ export class QueryBuilder {
119
107
  return result;
120
108
  }
121
109
 
122
- private _buildBinaryExpression(expression) {
123
- if (!(expression instanceof BinaryExpression))
124
- throw new Error('Invalid binary expression');
125
-
126
- var ExpressionType = constants.ExpressionType;
127
- var result = null;
128
- var type = expression.getType();
110
+ private buildBinaryExpression(expression: BinaryExpression): string {
111
+ let result: string = null;
112
+ const type = expression.getType();
129
113
  switch (type) {
130
- case ExpressionType.eq:
131
- case ExpressionType.ne:
132
- case ExpressionType.lt:
133
- case ExpressionType.le:
134
- case ExpressionType.gt:
135
- case ExpressionType.ge:
136
- var constant = expression.getConstant();
137
- /*var template = '({0} {1} \'{2}\')';
138
- if (/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(constant))
139
- template = '({0} {1} {2})';*/
140
-
141
- result = `(${expression.getParameter()} ${type} ${this._checkType(constant)})`;
114
+ case EXPRESSION_TYPE.eq:
115
+ case EXPRESSION_TYPE.ne:
116
+ case EXPRESSION_TYPE.lt:
117
+ case EXPRESSION_TYPE.le:
118
+ case EXPRESSION_TYPE.gt:
119
+ case EXPRESSION_TYPE.ge: {
120
+ const constant = expression.getConstant();
121
+ result = `(${expression.getParameter()} ${type} ${this.checkType(constant)})`;
142
122
  break;
143
- // TODO contains is substringOf in Odata ?
144
- case ExpressionType.contains:
145
- case ExpressionType.startsWith:
146
- case ExpressionType.endsWith:
147
- var expressionParameter = this._buildExpressionParameter(expression);
148
- result = `${type.toLowerCase()}(${expressionParameter}, ${this._checkType(expression.getConstant())})`;
123
+ }
124
+ case EXPRESSION_TYPE.contains:
125
+ case EXPRESSION_TYPE.startsWith:
126
+ case EXPRESSION_TYPE.endsWith: {
127
+ const expressionParameter = this.applyCaseSensitiveSettings(expression, expression.getParameter());
128
+ const expressionConstant = this.checkType(expression.getConstant());
129
+ const expressionValue = this.applyCaseSensitiveSettings(expression, expressionConstant);
130
+
131
+ result = `${type.toLowerCase()}(${expressionParameter}, ${expressionValue})`;
149
132
  break;
150
- default:
151
- var msg = `Unsupported operator ${type}`;
133
+ }
134
+ default: {
135
+ const msg = `Unsupported operator ${type}`;
152
136
  throw new Error(msg);
137
+ }
153
138
  }
154
139
 
155
140
  return result;
156
141
  }
157
142
 
158
- private _buildExpressionParameter(expression) {
143
+ private applyCaseSensitiveSettings(expression: BinaryExpression, value: string): string {
159
144
  if (expression.isCaseSensitive()) {
160
- return `${expression.getParameter()}`
145
+ return value;
161
146
  }
162
147
 
163
- return `tolower(${expression.getParameter()})`
148
+ return `tolower(${value})`;
164
149
  }
165
150
 
166
- private _checkType(constant: any) {
167
- if (this._isGuid(constant))
151
+ private checkType(constant: any): string {
152
+ if (this.isGuid(constant))
168
153
  return constant;
169
154
 
170
155
  if (constant == null)
@@ -180,7 +165,7 @@ export class QueryBuilder {
180
165
  return "'" + constant + "'";
181
166
  }
182
167
 
183
- private _isGuid(constant: string) {
168
+ private isGuid(constant: string): boolean {
184
169
  return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(constant);
185
170
  }
186
171
  }