@progress/sitefinity-webservices-sdk 1.1.16 → 2.0.0

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 (233) hide show
  1. package/README.md +84 -51
  2. package/esm/chunks/chunk-2ID24RPE.mjs +179 -0
  3. package/esm/chunks/chunk-2ID24RPE.mjs.map +7 -0
  4. package/esm/chunks/chunk-AHDZ2CWQ.mjs +93 -0
  5. package/esm/chunks/chunk-AHDZ2CWQ.mjs.map +7 -0
  6. package/esm/chunks/chunk-BFLQBM7R.mjs +136 -0
  7. package/esm/chunks/chunk-BFLQBM7R.mjs.map +7 -0
  8. package/esm/chunks/chunk-CMGV26CS.mjs +66 -0
  9. package/esm/chunks/chunk-CMGV26CS.mjs.map +7 -0
  10. package/esm/chunks/chunk-DHWDJAGV.mjs +180 -0
  11. package/esm/chunks/chunk-DHWDJAGV.mjs.map +7 -0
  12. package/esm/chunks/chunk-EH4CERVO.mjs +82 -0
  13. package/esm/chunks/chunk-EH4CERVO.mjs.map +7 -0
  14. package/esm/chunks/chunk-F4CWOE7M.mjs +57 -0
  15. package/esm/chunks/chunk-F4CWOE7M.mjs.map +7 -0
  16. package/esm/chunks/chunk-FUFBYOIF.mjs +98 -0
  17. package/esm/chunks/chunk-FUFBYOIF.mjs.map +7 -0
  18. package/esm/chunks/chunk-J2B7UDVZ.mjs +132 -0
  19. package/esm/chunks/chunk-J2B7UDVZ.mjs.map +7 -0
  20. package/esm/chunks/chunk-L3IMDFA5.mjs +1 -0
  21. package/esm/chunks/chunk-L3IMDFA5.mjs.map +7 -0
  22. package/esm/chunks/chunk-NNYY2VBC.mjs +383 -0
  23. package/esm/chunks/chunk-NNYY2VBC.mjs.map +7 -0
  24. package/esm/chunks/chunk-PI55MBSL.mjs +256 -0
  25. package/esm/chunks/chunk-PI55MBSL.mjs.map +7 -0
  26. package/esm/chunks/chunk-PXPK2IV6.mjs +568 -0
  27. package/esm/chunks/chunk-PXPK2IV6.mjs.map +7 -0
  28. package/esm/chunks/chunk-QPSEKUOI.mjs +35 -0
  29. package/esm/chunks/chunk-QPSEKUOI.mjs.map +7 -0
  30. package/esm/chunks/chunk-RQAAYOY6.mjs +72 -0
  31. package/esm/chunks/chunk-RQAAYOY6.mjs.map +7 -0
  32. package/esm/chunks/chunk-TTVNTTW5.mjs +145 -0
  33. package/esm/chunks/chunk-TTVNTTW5.mjs.map +7 -0
  34. package/esm/chunks/chunk-VLDX2FH2.mjs +235 -0
  35. package/esm/chunks/chunk-VLDX2FH2.mjs.map +7 -0
  36. package/esm/chunks/chunk-VWT2RJET.mjs +102 -0
  37. package/esm/chunks/chunk-VWT2RJET.mjs.map +7 -0
  38. package/esm/chunks/chunk-W2OWM3L7.mjs +19 -0
  39. package/esm/chunks/chunk-W2OWM3L7.mjs.map +7 -0
  40. package/esm/chunks/chunk-WX5J7F5D.mjs +43 -0
  41. package/esm/chunks/chunk-WX5J7F5D.mjs.map +7 -0
  42. package/esm/chunks/chunk-YB2LMPUX.mjs +54 -0
  43. package/esm/chunks/chunk-YB2LMPUX.mjs.map +7 -0
  44. package/package.json +67 -36
  45. package/sitefinity-webservices-sdk.cjs +2761 -0
  46. package/sitefinity-webservices-sdk.cjs.map +7 -0
  47. package/sitefinity-webservices-sdk.d.mts +1 -0
  48. package/{dist/sitefinity-webservices-sdk.d.ts → sitefinity-webservices-sdk.d.ts} +6 -0
  49. package/sitefinity-webservices-sdk.global.d.ts +5 -0
  50. package/sitefinity-webservices-sdk.js +2764 -0
  51. package/sitefinity-webservices-sdk.js.map +7 -0
  52. package/sitefinity-webservices-sdk.min.js +3 -0
  53. package/sitefinity-webservices-sdk.mjs +124 -0
  54. package/sitefinity-webservices-sdk.mjs.map +7 -0
  55. package/src/BlobBuilder.d.ts +12 -0
  56. package/src/Data.d.ts +259 -0
  57. package/src/Expression.d.ts +37 -0
  58. package/src/OrderProperty.d.ts +24 -0
  59. package/src/Query.d.ts +104 -0
  60. package/src/QueryBase.d.ts +40 -0
  61. package/src/QueryBuilder.d.ts +29 -0
  62. package/src/Requests/BatchRequest.d.ts +174 -0
  63. package/src/Requests/ExecutableRequest.d.ts +43 -0
  64. package/src/Requests/Request.d.ts +225 -0
  65. package/src/Requests/RequestBase.d.ts +58 -0
  66. package/{dist/src → src}/Requests/RequestFactory.d.ts +24 -2
  67. package/src/Sitefinity.d.ts +141 -0
  68. package/src/Transport/FetchTransport.d.ts +17 -0
  69. package/src/Transport/HttpTransport.d.ts +69 -0
  70. package/src/Transport/XhrTransport.d.ts +8 -0
  71. package/src/WhereQuery.d.ts +88 -0
  72. package/src/chunk-upload/chunk-upload.sdk.d.ts +305 -0
  73. package/src/chunk-upload/chunked-file-upload.utilities.d.ts +58 -0
  74. package/{dist/src → src}/constants.d.ts +21 -0
  75. package/src/utils.d.ts +103 -0
  76. package/.editorconfig +0 -29
  77. package/.eslintignore +0 -4
  78. package/.eslintrc.js +0 -40
  79. package/.github/copilot-instructions.md +0 -72
  80. package/.github/instructions/sitefinity-webservices-sdk.instructions.md +0 -53
  81. package/config/helpers.ts +0 -8
  82. package/config/webpack.common.ts +0 -39
  83. package/config/webpack.dev.ts +0 -37
  84. package/config/webpack.prod.ts +0 -17
  85. package/dist/docs/.nojekyll +0 -1
  86. package/dist/docs/assets/highlight.css +0 -71
  87. package/dist/docs/assets/main.js +0 -58
  88. package/dist/docs/assets/search.js +0 -1
  89. package/dist/docs/assets/style.css +0 -1280
  90. package/dist/docs/classes/BlobBuilder.BlobBuilder.html +0 -137
  91. package/dist/docs/classes/Data.Data.html +0 -387
  92. package/dist/docs/classes/Expression.BinaryExpression.html +0 -184
  93. package/dist/docs/classes/Expression.ComplexExpression.html +0 -146
  94. package/dist/docs/classes/Expression.ExpressionBase.html +0 -125
  95. package/dist/docs/classes/OrderProperty.OrderProperty.html +0 -151
  96. package/dist/docs/classes/Query.Query.html +0 -353
  97. package/dist/docs/classes/QueryBase.QueryBase.html +0 -185
  98. package/dist/docs/classes/QueryBuilder.QueryBuilder.html +0 -206
  99. package/dist/docs/classes/Requests_BatchRequest.BatchRequest.html +0 -731
  100. package/dist/docs/classes/Requests_BatchRequest.Transaction.html +0 -332
  101. package/dist/docs/classes/Requests_ExecutableRequest.ExecutableRequest.html +0 -340
  102. package/dist/docs/classes/Requests_Request.CommitChunksRequest.html +0 -303
  103. package/dist/docs/classes/Requests_Request.CreateRelatedRequest.html +0 -310
  104. package/dist/docs/classes/Requests_Request.CreateRequest.html +0 -307
  105. package/dist/docs/classes/Requests_Request.DeleteRelatedByIdRequest.html +0 -309
  106. package/dist/docs/classes/Requests_Request.DeleteRelatedRequest.html +0 -302
  107. package/dist/docs/classes/Requests_Request.DeleteRequest.html +0 -298
  108. package/dist/docs/classes/Requests_Request.GetByIdRequest.html +0 -298
  109. package/dist/docs/classes/Requests_Request.GetRelatedByIdRequest.html +0 -309
  110. package/dist/docs/classes/Requests_Request.GetRelatedRequest.html +0 -302
  111. package/dist/docs/classes/Requests_Request.GetRequest.html +0 -295
  112. package/dist/docs/classes/Requests_Request.UpdateRequest.html +0 -309
  113. package/dist/docs/classes/Requests_Request.UploadChunkRequest.html +0 -359
  114. package/dist/docs/classes/Requests_Request.UploadRequest.html +0 -329
  115. package/dist/docs/classes/Requests_RequestBase.RequestBase.html +0 -275
  116. package/dist/docs/classes/Requests_RequestFactory.RequestFactory.html +0 -344
  117. package/dist/docs/classes/Sitefinity.Sitefinity.html +0 -188
  118. package/dist/docs/classes/WhereQuery.WhereQuery.html +0 -436
  119. package/dist/docs/classes/chunk_upload_chunk_upload_sdk.ChunkUploadSdk.html +0 -231
  120. package/dist/docs/classes/chunk_upload_chunked_file_upload_utilities.ChunkedFileUploadUtilities.html +0 -131
  121. package/dist/docs/classes/utils.utils.html +0 -303
  122. package/dist/docs/index.html +0 -129
  123. package/dist/docs/interfaces/Data.CreateRelatedRequestOptions.html +0 -155
  124. package/dist/docs/interfaces/Data.CreateRequestOptions.html +0 -153
  125. package/dist/docs/interfaces/Data.OperationsRequestOptions.html +0 -145
  126. package/dist/docs/interfaces/Data.PropertyRequestOptions.html +0 -149
  127. package/dist/docs/interfaces/Data.RequestOptionsBase.html +0 -136
  128. package/dist/docs/interfaces/Data.SingleRelatedItemRequestOptions.html +0 -155
  129. package/dist/docs/interfaces/Data.UpdateRequestOptions.html +0 -155
  130. package/dist/docs/interfaces/Data.UploadRequestOptions.html +0 -169
  131. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRelatedRequestOptions.html +0 -161
  132. package/dist/docs/interfaces/Requests_BatchRequest.BatchCreateRequestOptions.html +0 -153
  133. package/dist/docs/interfaces/Requests_BatchRequest.BatchPropertyRequestOptions.html +0 -153
  134. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsBase.html +0 -145
  135. package/dist/docs/interfaces/Requests_BatchRequest.BatchRequestOptionsExtended.html +0 -153
  136. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleItemRequestOptions.html +0 -145
  137. package/dist/docs/interfaces/Requests_BatchRequest.BatchSingleRelatedItemRequestOptions.html +0 -161
  138. package/dist/docs/interfaces/Requests_BatchRequest.BatchUpdateRequestOptions.html +0 -161
  139. package/dist/docs/interfaces/Requests_ExecutableRequest.ResponseHandlers.html +0 -98
  140. package/dist/docs/interfaces/Requests_Request.CommitChunksRequestOptionsExtended.html +0 -215
  141. package/dist/docs/interfaces/Requests_Request.PostRequestOptionsExtended.html +0 -159
  142. package/dist/docs/interfaces/Requests_Request.PutRequestOptionsExtended.html +0 -161
  143. package/dist/docs/interfaces/Requests_Request.RelatedByIdRequestOptionsExtended.html +0 -169
  144. package/dist/docs/interfaces/Requests_Request.RelatedRequestOptionsExtended.html +0 -163
  145. package/dist/docs/interfaces/Requests_Request.UploadChunkRequestOptionsExtended.html +0 -217
  146. package/dist/docs/interfaces/Requests_Request.UploadRequestOptionsExtended.html +0 -180
  147. package/dist/docs/interfaces/Requests_RequestBase.RequestOptionsBaseExtended.html +0 -148
  148. package/dist/docs/interfaces/Sitefinity.SDKOptions.html +0 -128
  149. package/dist/docs/interfaces/Sitefinity.Token.html +0 -94
  150. package/dist/docs/interfaces/Sitefinity.TypeOptions.html +0 -160
  151. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadInfoDTO.html +0 -159
  152. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.ChunkUploadResult.html +0 -111
  153. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CleanUpChunksRequestOptions.html +0 -171
  154. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.CommitChunksRequestOptions.html +0 -204
  155. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.GetChunkUploadInfoRequestOptions.html +0 -166
  156. package/dist/docs/interfaces/chunk_upload_chunk_upload_sdk.UploadChunkRequestOptions.html +0 -206
  157. package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.ChunkFileResult.html +0 -101
  158. package/dist/docs/interfaces/chunk_upload_chunked_file_upload_utilities.FileUploadChunk.html +0 -94
  159. package/dist/docs/modules/BlobBuilder.html +0 -73
  160. package/dist/docs/modules/Data.html +0 -92
  161. package/dist/docs/modules/Expression.html +0 -77
  162. package/dist/docs/modules/OrderProperty.html +0 -73
  163. package/dist/docs/modules/Query.html +0 -73
  164. package/dist/docs/modules/QueryBase.html +0 -73
  165. package/dist/docs/modules/QueryBuilder.html +0 -73
  166. package/dist/docs/modules/Requests_BatchRequest.html +0 -94
  167. package/dist/docs/modules/Requests_ExecutableRequest.html +0 -78
  168. package/dist/docs/modules/Requests_Request.html +0 -114
  169. package/dist/docs/modules/Requests_RequestBase.html +0 -78
  170. package/dist/docs/modules/Requests_RequestFactory.html +0 -73
  171. package/dist/docs/modules/Sitefinity.html +0 -82
  172. package/dist/docs/modules/WhereQuery.html +0 -73
  173. package/dist/docs/modules/chunk_upload_chunk_upload_sdk.html +0 -88
  174. package/dist/docs/modules/chunk_upload_chunked_file_upload_utilities.html +0 -80
  175. package/dist/docs/modules/constants.html +0 -83
  176. package/dist/docs/modules/utils.html +0 -73
  177. package/dist/docs/modules.html +0 -80
  178. package/dist/docs/variables/constants.CONTENT_TYPES.html +0 -76
  179. package/dist/docs/variables/constants.EXPRESSION_TYPE.html +0 -106
  180. package/dist/docs/variables/constants.HEADER_NAMES.html +0 -102
  181. package/dist/docs/variables/constants.HTTP_METHODS.html +0 -84
  182. package/dist/docs/variables/constants.ODATA_PARAMS.html +0 -90
  183. package/dist/docs/variables/constants.SF_PARAMS.html +0 -84
  184. package/dist/samples.html +0 -625
  185. package/dist/sitefinity-webservices-sdk.js +0 -3243
  186. package/dist/sitefinity-webservices-sdk.js.map +0 -1
  187. package/dist/sitefinity-webservices-sdk.min.js +0 -1
  188. package/dist/src/BlobBuilder.d.ts +0 -14
  189. package/dist/src/Data.d.ts +0 -154
  190. package/dist/src/Data.spec.d.ts +0 -1
  191. package/dist/src/Expression.d.ts +0 -19
  192. package/dist/src/OrderProperty.d.ts +0 -8
  193. package/dist/src/Query.d.ts +0 -59
  194. package/dist/src/QueryBase.d.ts +0 -18
  195. package/dist/src/QueryBuilder.d.ts +0 -13
  196. package/dist/src/Requests/BatchRequest.d.ts +0 -146
  197. package/dist/src/Requests/ExecutableRequest.d.ts +0 -22
  198. package/dist/src/Requests/Request.d.ts +0 -132
  199. package/dist/src/Requests/RequestBase.d.ts +0 -27
  200. package/dist/src/Requests/request.spec.d.ts +0 -1
  201. package/dist/src/Sitefinity.d.ts +0 -75
  202. package/dist/src/Sitefinity.spec.d.ts +0 -1
  203. package/dist/src/WhereQuery.d.ts +0 -72
  204. package/dist/src/chunk-upload/chunk-upload.sdk.d.ts +0 -295
  205. package/dist/src/chunk-upload/chunk-upload.sdk.spec.d.ts +0 -1
  206. package/dist/src/chunk-upload/chunked-file-upload.utilities.d.ts +0 -13
  207. package/dist/src/utils.d.ts +0 -16
  208. package/karma.conf.js +0 -29
  209. package/sitefinity-webservices-sdk.ts +0 -15
  210. package/src/BlobBuilder.ts +0 -20
  211. package/src/Data.spec.ts +0 -160
  212. package/src/Data.ts +0 -418
  213. package/src/Expression.ts +0 -36
  214. package/src/OrderProperty.ts +0 -39
  215. package/src/Query.ts +0 -106
  216. package/src/QueryBase.ts +0 -57
  217. package/src/QueryBuilder.ts +0 -180
  218. package/src/Requests/BatchRequest.ts +0 -807
  219. package/src/Requests/ExecutableRequest.ts +0 -117
  220. package/src/Requests/Request.ts +0 -327
  221. package/src/Requests/RequestBase.ts +0 -163
  222. package/src/Requests/RequestFactory.ts +0 -75
  223. package/src/Requests/request.spec.ts +0 -154
  224. package/src/Sitefinity.spec.ts +0 -483
  225. package/src/Sitefinity.ts +0 -125
  226. package/src/WhereQuery.ts +0 -145
  227. package/src/chunk-upload/chunk-upload.sdk.spec.ts +0 -347
  228. package/src/chunk-upload/chunk-upload.sdk.ts +0 -439
  229. package/src/chunk-upload/chunked-file-upload.utilities.ts +0 -64
  230. package/src/constants.ts +0 -66
  231. package/src/utils.ts +0 -125
  232. package/template.html +0 -625
  233. package/tsconfig.json +0 -38
package/src/Query.ts DELETED
@@ -1,106 +0,0 @@
1
- import { QueryBase } from "./QueryBase";
2
- import { WhereQuery } from "./WhereQuery";
3
- import { OrderProperty } from "./OrderProperty";
4
- import { QueryBuilder } from "./QueryBuilder";
5
-
6
- /**
7
- * The query class is used for constructing queries.
8
- * @example
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();
19
- */
20
- export class Query extends QueryBase {
21
- orderProperties: OrderProperty[] = null;
22
- skipValue: number = null;
23
- takeValue: number = null;
24
- searchValue: string = null;
25
- inlineCount: boolean;
26
- filter: WhereQuery<Query> = null;
27
-
28
- constructor() {
29
- super();
30
- }
31
-
32
- /**
33
- * Begins a where clause for filtering the items.
34
- */
35
- where(): WhereQuery<Query> {
36
- const clone: Query = this.clone((newObj: Query) => {
37
- newObj.filter = new WhereQuery(newObj);
38
- });
39
-
40
- return clone.filter;
41
- }
42
-
43
- /**
44
- * Specifies the order by clause.
45
- * @example
46
- * order by single field
47
- * order("Title desc")
48
- * @example
49
- * order by multiple fields
50
- * order("Title desc", "Description asc")
51
- */
52
- order(...properties: string[]): Query {
53
- properties = properties ?? [];
54
- this.validatePropertyPaths(properties);
55
-
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);
61
- orderItems.push(orderProp);
62
- }
63
- newObj.orderProperties = orderItems;
64
- });
65
- }
66
-
67
- /**
68
- * Skips a certain number of items from the beginning before returning the rest of the items. Used for paging.
69
- */
70
- skip(value: number): Query {
71
- return this.clone((newObj: Query) => {
72
- newObj.skipValue = value;
73
- });
74
- }
75
-
76
- /**
77
- * Takes a specified number of items from the query result. Used for paging.
78
- */
79
- take(value: number): Query {
80
- return this.clone((newObj: Query) => {
81
- newObj.takeValue = value;
82
- });
83
- }
84
-
85
- /**
86
- * Searches for the items matching the specified expression.
87
- */
88
- search(value: string): Query {
89
- return this.clone((newObj: Query) => {
90
- newObj.searchValue = value;
91
- });
92
- }
93
-
94
- /**
95
- * Returns the total item count with the result. Used for paging.
96
- */
97
- count(inline = true): Query {
98
- return this.clone((newObj: Query) => {
99
- newObj.inlineCount = inline;
100
- });
101
- }
102
-
103
- build() {
104
- return new QueryBuilder(this).build();
105
- }
106
- }
package/src/QueryBase.ts DELETED
@@ -1,57 +0,0 @@
1
- import { utils } from "./utils";
2
-
3
- /**
4
- * The base class for dealing with queries.
5
- */
6
- export class QueryBase {
7
- selectProperties: string[];
8
- expandProperties: string[];
9
-
10
- constructor() {
11
- this.selectProperties = null;
12
- this.expandProperties = null;
13
- }
14
-
15
- /**
16
- * Selects which fields will be returned when querying the service.
17
- */
18
- select(...properties: string[]): QueryBase {
19
- properties = properties ?? [];
20
-
21
- this.validatePropertyPaths(properties);
22
-
23
- return this.clone((newObj: QueryBase) => {
24
- newObj.selectProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
25
- });
26
- }
27
-
28
- /**
29
- * Selects which navigation properties will be returned when querying the service.
30
- */
31
- expand(...properties: string[]): QueryBase {
32
- properties = properties ?? [];
33
- this.validatePropertyPaths(properties);
34
-
35
- return this.clone((newObj: QueryBase) => {
36
- newObj.expandProperties = properties.filter((prop, index, props) => props.indexOf(prop) === index);
37
- });
38
- }
39
-
40
- protected validatePropertyPaths(propPaths: string[], allowNested = false) {
41
- for (let i = 0; i < propPaths.length; i++) {
42
- const member = propPaths[i];
43
- if (!utils.isString(member)) {
44
- throw new Error("Invalid argument in clause");
45
- }
46
-
47
- if (!allowNested && member.indexOf(".") > -1) {
48
- throw new Error("Invalid argument in clause");
49
- }
50
- }
51
- }
52
-
53
- protected clone(setter: Function = null) {
54
- const newObj = utils.clone(this, new QueryBase(), setter);
55
- return newObj;
56
- }
57
- }
@@ -1,180 +0,0 @@
1
- import { WhereQuery } from "./WhereQuery";
2
- import { ComplexExpression, BinaryExpression } from "./Expression";
3
- import { OrderProperty } from "./OrderProperty";
4
- import { utils } from "./utils";
5
- import { ODATA_PARAMS, EXPRESSION_TYPE } from "./constants";
6
- import { Query } from "./Query";
7
-
8
- export class QueryBuilder {
9
- constructor(private query: Query) {
10
- }
11
-
12
- build(): { [key: string]: string } {
13
- const queryParameters = {};
14
- const whereClause = this.query.filter;
15
- if (whereClause instanceof WhereQuery) {
16
- const expression = whereClause.getExpression();
17
- if (expression instanceof ComplexExpression) {
18
- const result = this.buildComplexExpression(expression, null);
19
- if (result) {
20
- queryParameters[ODATA_PARAMS.$filter] = result;
21
- }
22
- }
23
- }
24
-
25
- const selectClause = this.query.selectProperties;
26
- if (selectClause instanceof Array) {
27
- queryParameters[ODATA_PARAMS.$select] = selectClause.join(", ");
28
- }
29
-
30
- const expandClause = this.query.expandProperties;
31
- if (expandClause instanceof Array)
32
- queryParameters[ODATA_PARAMS.$expand] = expandClause.join(", ");
33
-
34
- const orderByClause = this.query.orderProperties;
35
- if (orderByClause instanceof Array) {
36
- const order = [];
37
- for (const i in orderByClause) {
38
- if (orderByClause[i] instanceof OrderProperty)
39
- order.push(orderByClause[i].getValue());
40
- }
41
- queryParameters[ODATA_PARAMS.$orderby] = order.join(", ");
42
- }
43
-
44
- const take = this.query.takeValue;
45
- if (utils.isNumber(take))
46
- queryParameters[ODATA_PARAMS.$top] = take;
47
-
48
- const skip = this.query.skipValue;
49
- if (utils.isNumber(skip))
50
- queryParameters[ODATA_PARAMS.$skip] = skip;
51
-
52
- const search = this.query.searchValue;
53
- if (search)
54
- queryParameters[ODATA_PARAMS.$search] = search;
55
-
56
- if (this.query.inlineCount !== null) {
57
- queryParameters[ODATA_PARAMS.$count] = this.query.inlineCount;
58
- }
59
-
60
- return queryParameters;
61
- }
62
-
63
- private buildComplexExpression(expression: ComplexExpression, parent: string): string {
64
- if (!(expression instanceof ComplexExpression))
65
- throw new Error("Invalid complex expression");
66
-
67
- let counter = 0;
68
- let result = "";
69
- const subExpressions = expression.getExpressions();
70
- if (!subExpressions.length) {
71
- return result;
72
- }
73
-
74
- while (true) {
75
- const currentExp = subExpressions[counter];
76
- if (currentExp instanceof BinaryExpression) {
77
- result += this.buildBinaryExpression(currentExp);
78
- }
79
- else if (currentExp instanceof ComplexExpression) {
80
- const complexResult = this.buildComplexExpression(currentExp, expression.type);
81
- if (complexResult) {
82
- result += "(" + complexResult + ")";
83
- }
84
- }
85
-
86
- if (expression.getType() === EXPRESSION_TYPE.not)
87
- result = expression.getType() + " " + result;
88
- // TODOSDK: Rethink this!
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)
93
- exprVal.push(subExpressions[index].type.toLowerCase() + "(x, '" + (subExpressions[index] as BinaryExpression).constant + "')");
94
- else
95
- exprVal.push("x " + subExpressions[index].type.toLowerCase() + " " + this.checkType((subExpressions[index] as BinaryExpression).constant));
96
- }
97
- result = (currentExp as BinaryExpression).parameter + "/" + expression.getType() + "(x:" + exprVal.join(" " + parent + " ") + ")";
98
- }
99
-
100
- counter++;
101
- if (counter == subExpressions.length)
102
- break;
103
-
104
- result += " " + expression.getType() + " ";
105
- }
106
-
107
- return result;
108
- }
109
-
110
- private buildBinaryExpression(expression: BinaryExpression): string {
111
- let result: string = null;
112
- const type = expression.getType();
113
- switch (type) {
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)})`;
122
- break;
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(), true);
129
- const expressionValue = this.applyCaseSensitiveSettings(expression, expressionConstant);
130
-
131
- result = `${type.toLowerCase()}(${expressionParameter}, ${expressionValue})`;
132
- break;
133
- }
134
- case EXPRESSION_TYPE.in: {
135
- const valueArray = expression.getConstant();
136
- if (!Array.isArray(valueArray)) {
137
- throw new Error("Parameter is not an array!");
138
- }
139
-
140
- result = `${expression.getParameter()} in (${valueArray.join(", ")})`;
141
- break;
142
- }
143
- default: {
144
- const msg = `Unsupported operator ${type}`;
145
- throw new Error(msg);
146
- }
147
- }
148
-
149
- return result;
150
- }
151
-
152
- private applyCaseSensitiveSettings(expression: BinaryExpression, value: string): string {
153
- if (expression.isCaseSensitive()) {
154
- return value;
155
- }
156
-
157
- return `tolower(${value})`;
158
- }
159
-
160
- private checkType(constant: any, treatAsString = false): string {
161
- if (this.isGuid(constant) && !treatAsString)
162
- return constant;
163
-
164
- if (constant == null)
165
- return null;
166
-
167
- constant = constant.replace(/[+/?%#&]/g, function ($0) {
168
- return encodeURIComponent($0);
169
- });
170
-
171
- // escapes the apostrophes
172
- constant = constant.replace(/'/g, "''");
173
-
174
- return "'" + constant + "'";
175
- }
176
-
177
- private isGuid(constant: string): boolean {
178
- 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);
179
- }
180
- }