@progress/sitefinity-webservices-sdk 0.3.1 → 1.0.3

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 (200) 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 +1139 -1738
  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 +64 -82
  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 +451 -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 +16 -16
  135. package/template.html +33 -35
  136. package/tsconfig.json +8 -1
  137. package/version.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 -496
  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
package/src/Sitefinity.ts CHANGED
@@ -1,183 +1,114 @@
1
1
  import { RequestFactory } from './Requests/RequestFactory';
2
- import { Authentication } from './Authentication';
3
2
  import { Data } from './Data';
4
3
  import { Query } from './Query';
5
4
  import { utils } from './utils';
5
+ import { ResponseHandlers } from "./Requests/ExecutableRequest";
6
+ import { BatchRequest } from "./Requests/BatchRequest";
6
7
 
7
- /**
8
- * @class Sitefinity
9
- * @classdesc The constructor of the Sitefinity JavaScript SDK. This is the entry point for the SDK.
10
- * @property {Object} authentication - The authentication object used for authenticating to Sitefinity. See {@link Authentication}
11
- * @param {object} options - An object containing configuration options for the Setup object.
12
- * @param {string} options.serviceUrl - Your service url that points to the configured instance of Sitefinity service.
13
- * @param {string} options.siteId - The ID of the site, for which the query will be executed.
14
- * @param {string} options.handlers - The global handlers for request execution
15
- * @param {string} options.handlers.successCb - The success handler.
16
- * @param {string} options.handlers.failureCb - The failure handler.
17
- */
18
8
  export class Sitefinity {
9
+ public static Query: typeof Query = Query;
10
+
19
11
  private factory: RequestFactory;
20
- private authentication: Authentication;
21
- private profileUrl: string;
12
+ private baseUrl: string;
22
13
  private siteId: string;
23
- public static Query: typeof Query = Query;
24
14
 
25
- constructor(options: any) {
26
- this.profileUrl = utils.addTrailingSlash(options.serviceUrl);
15
+ /**
16
+ * The constructor of the Sitefinity JavaScript SDK. This is the entry point for the SDK.
17
+ */
18
+ constructor(options: SDKOptions) {
19
+ this.baseUrl = options.baseUrl;
27
20
  this.siteId = options.siteId;
28
- this.factory = new RequestFactory({
29
- handlers: options.handlers,
30
- enableUnlimitedChoices: options.enableUnlimitedChoices,
31
- integrationMode: options.integrationMode
32
- });
33
-
34
- this.authentication = new Authentication({
35
- serviceUrl: this.profileUrl,
36
- factory: this.factory
37
- });
21
+ this.factory = new RequestFactory(options);
38
22
  }
39
23
 
40
- /**
41
- * Creates a new {@link Data} class.
42
- * @memberOf Sitefinity
43
- * @instance
44
- * @param {object} options - An object containing configuration options for the Setup object.
45
- * @param {string} options.urlName - The URL name of the type..
46
- * @param {string} [options.providerName] - The name of the provider. If empty the default provider for the site will be used.
47
- * @param {string} [options.cultureName] - The name of the culture. If empty the default culture for the site will be used.
48
- * @example
49
- * var data = sf.data({
50
- * urlName: "newsitems",
51
- * providerName: "OpenAccessDataProvider",
52
- * cultureName: "en"
53
- * });
54
- * @returns {Data}
55
- */
56
- data(options: any) {
57
- var optionsServiceUrl = options.serviceUrl ? utils.addTrailingSlash(options.serviceUrl) : options.serviceUrl;
58
- var dataOptions = {
59
- baseUrl: optionsServiceUrl || this.profileUrl,
60
- SFParams: {
61
- provider: options.providerName,
62
- culture: options.cultureName,
63
- siteId: options.siteId || this.siteId
64
- },
24
+ data(options: TypeOptions): Data {
25
+ const urlOptions: TypeOptions = {
26
+ baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
27
+ provider: options.provider,
28
+ culture: options.culture,
29
+ siteId: options.siteId || this.siteId,
65
30
  additionalQueryParams: options.additionalQueryParams,
66
- entitySet: options.urlName
31
+ entitySet: options.entitySet
67
32
  }
68
33
 
69
- this.factory.token = this.authentication.getToken();
70
- return new Data(dataOptions, this.factory);
34
+ return new Data(urlOptions, this.factory);
71
35
  }
72
36
 
73
- /**
74
- * Creates a new {@link BatchRequest} class. OData batch requests -> {@link http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793748}
75
- * @memberOf Sitefinity
76
- * @instance
77
- * @param {Function} success - The success callback of the batch execution.
78
- * @param {string} options.urlName - The URL name of the type..
79
- * @param {string} [options.providerName] - The name of the provider. If empty the default provider for the site will be used.
80
- * @param {string} [options.cultureName] - The name of the culture. If empty the default culture for the site will be used.
81
- * @example
82
- * var sf = new Sitefinity({
83
- * serviceUrl: 'http://mydomain/route/service/'
84
- * });
85
- *
86
- * var batch = sf.batch(successCbBatch, failureCb);
87
- * batch.get({
88
- * entitySet: entitySet,
89
- * query: query8
90
- * });
91
- *
92
- * var transaction = batch.beginTransaction();
93
- * var createId = transaction.create({
94
- * entitySet: entitySet,
95
- * data: newsItem
96
- * });
97
- *
98
- * batch.endTransaction(transaction);
99
- *
100
- * var transaction2 = batch.beginTransaction();
101
- * var createId2 = transaction2.create({
102
- * entitySet: entitySet,
103
- * data: newsItem
104
- * });
105
- *
106
- * var updateId2 = transaction2.update({
107
- * entitySet: entitySet,
108
- * key: createId2,
109
- * data: newsItemUpdate
110
- * });
111
- *
112
- * batch.endTransaction(transaction2);
113
- *
114
- * batch.get({
115
- * entitySet: entitySet
116
- * });
117
- *
118
- * batch.execute();
119
- * @returns {BatchRequest}
120
- */
121
- batch(success: any, failure: any, progress: any, options: any) {
122
- if (typeof progress !== 'function') {
123
- options = progress;
124
- progress = null;
125
- }
126
-
37
+ batch(success?: Function, failure?: Function, progress?: Function, options?: TypeOptions): BatchRequest {
127
38
  if (!options)
128
39
  options = {};
129
40
 
130
- this.factory.token = this.authentication.getToken();
131
-
132
- var optionsServiceUrl = options.serviceUrl ? utils.addTrailingSlash(options.serviceUrl) : options.serviceUrl;
133
- var batch = this.factory.batch({
41
+ const batch = this.factory.batch({
134
42
  successCb: success,
135
43
  failureCb: failure,
136
44
  progressCb: progress,
137
45
  urlOptions: {
138
- baseUrl: optionsServiceUrl || this.profileUrl,
139
- SFParams: {
140
- provider: options.providerName,
141
- culture: options.cultureName,
142
- siteId: options.siteId || this.siteId
143
- },
46
+ baseUrl: utils.addTrailingSlash(options.baseUrl || this.baseUrl),
47
+ provider: options.provider,
48
+ culture: options.culture,
49
+ siteId: options.siteId || this.siteId,
144
50
  additionalQueryParams: options.additionalQueryParams
145
51
  }
146
52
  });
147
53
 
148
- var executor: any = this.factory.createExecutor(batch);
149
- executor.beginTransaction = () => {
150
- return batch.beginTransaction();
151
- }
54
+ return batch;
55
+ }
152
56
 
153
- executor.endTransaction = (transaction) => {
154
- batch.endTransaction(transaction);
155
- }
57
+ /**
58
+ * Sets the authentication token.
59
+ */
60
+ setToken(token: Token) {
61
+ this.factory.token = token;
62
+ }
63
+ }
156
64
 
157
- executor.get = (options) => {
158
- batch.constructor.prototype.get.call(batch, options);
159
- }
65
+ interface OptionsBase {
66
+ /**
67
+ * Your service url that points to the configured instance of Sitefinity service.
68
+ */
69
+ baseUrl?: string;
160
70
 
161
- executor.getOperations = (options) => {
162
- batch.constructor.prototype.getOperations.call(batch, options);
163
- }
71
+ /**
72
+ * The ID of the site, for which the queries will be executed.
73
+ */
74
+ siteId?: string;
75
+ }
164
76
 
165
- executor.getSingle = (options) => {
166
- batch.constructor.prototype.getSingle.call(batch, options);
167
- }
77
+ /**
78
+ * Defines an object containing configuration options for the SDK object.
79
+ */
80
+ export interface SDKOptions extends OptionsBase {
81
+ /**
82
+ * The global handlers for request execution
83
+ */
84
+ handlers?: ResponseHandlers;
168
85
 
169
- executor.getProperty = (options) => {
170
- batch.constructor.prototype.getProperty.call(batch, options);
171
- }
86
+ enableUnlimitedChoices?: boolean;
87
+ integrationMode?: boolean;
88
+ }
172
89
 
173
- executor.getRelated = (options) => {
174
- batch.constructor.prototype.getRelated.call(batch, options);
175
- }
90
+ /**
91
+ * Defines an object containing configuration options related to a specific type.
92
+ */
93
+ export interface TypeOptions extends OptionsBase {
94
+ /**
95
+ * The URL name of the type.
96
+ */
97
+ entitySet?: string;
176
98
 
177
- executor.getRelatedById = (options) => {
178
- batch.constructor.prototype.getRelatedById.call(batch, options);
179
- }
99
+ /**
100
+ * The name of the provider. If empty the default provider for the site will be used.
101
+ */
102
+ provider?: string;
180
103
 
181
- return executor;
182
- }
104
+ /**
105
+ * The name of the culture. If empty the default culture for the site will be used.
106
+ */
107
+ culture?: string;
108
+ additionalQueryParams?: { [key: string]: string };
109
+ }
110
+
111
+ export interface Token {
112
+ type: string;
113
+ value: string;
183
114
  }
package/src/WhereQuery.ts CHANGED
@@ -1,198 +1,138 @@
1
1
  import { ComplexExpression, BinaryExpression } from './Expression';
2
- const OperatorType = require('./constants').default.ExpressionType;
2
+ import { EXPRESSION_TYPE } from "./constants";
3
3
 
4
4
  /**
5
- * @classdesc A fluent API operation for creating a filter for a query by chaining different rules.
6
- * @class WhereQuery
7
- * @protected
5
+ * A fluent API operation for creating a filter for a query by chaining different rules.
8
6
  */
9
- export class WhereQuery {
10
-
7
+ export class WhereQuery<QueryType> {
11
8
  private expression: ComplexExpression;
12
- constructor(private parent: any, type: string = OperatorType.and) {
9
+
10
+ constructor(private parent: QueryType, type: string = EXPRESSION_TYPE.and) {
13
11
  this.expression = new ComplexExpression(type, []);
14
12
  }
15
13
 
16
14
  /**
17
15
  * Adds an `and` clause to the current condition and returns it for further chaining.
18
- * @method and
19
- * @memberOf WhereQuery.prototype
20
- * @returns {WhereQuery}
21
16
  */
22
- and(): WhereQuery {
23
- return new WhereQuery(this, OperatorType.and);
17
+ and(): WhereQuery<WhereQuery<QueryType>> {
18
+ return new WhereQuery(this, EXPRESSION_TYPE.and);
24
19
  }
20
+
25
21
  /**
26
22
  * Adds an `or` clause to the current condition and returns it for further chaining.
27
- * @method or
28
- * @memberOf WhereQuery.prototype
29
- * @returns {WhereQuery}
30
23
  */
31
- or(): WhereQuery {
32
- return new WhereQuery(this, OperatorType.or);
24
+ or(): WhereQuery<WhereQuery<QueryType>> {
25
+ return new WhereQuery(this, EXPRESSION_TYPE.or);
33
26
  }
34
27
 
35
28
  /**
36
29
  * Adds an `any` clause to the current condition and returns it for further chaining.
37
- * @method any
38
- * @memberOf WhereQuery.prototype
39
- * @returns {WhereQuery}
40
30
  */
41
- any(): WhereQuery {
42
- return new WhereQuery(this, OperatorType.any);
31
+ any(): WhereQuery<WhereQuery<QueryType>> {
32
+ return new WhereQuery(this, EXPRESSION_TYPE.any);
43
33
  }
34
+
44
35
  /**
45
36
  * Adds a `not` clause to the current condition and returns it for further chaining.
46
- * @method not
47
- * @memberOf WhereQuery.prototype
48
- * @returns {WhereQuery}
49
37
  */
50
- not(): WhereQuery {
51
- return new WhereQuery(this, OperatorType.not);
52
- }
53
-
54
- private _simple(type: string, parameter: string, constant: any, caseSensitive: boolean = true): WhereQuery {
55
- var currentExpr = new BinaryExpression(type, parameter, constant, caseSensitive);
56
- var subExpressions = this.expression.getExpressions();
57
- subExpressions.push(currentExpr);
58
-
59
- if (this.expression.getType() === OperatorType.not && subExpressions.length > 1)
60
- throw new Error("Invalid operators count!");
61
-
62
- return this;
38
+ not(): WhereQuery<WhereQuery<QueryType>> {
39
+ return new WhereQuery(this, EXPRESSION_TYPE.not);
63
40
  }
64
41
 
65
42
  /**
66
43
  * Adds a condition that a field must be equal to a specific value.
67
- * @method eq
68
- * @memberOf WhereQuery.prototype
69
- * @param {string} field Field name.
70
- * @param {*} value Comparison value (to which the fields must be equal).
71
- * @returns {WhereQuery}
72
44
  */
73
- eq(parameter: string, constant: any): WhereQuery {
74
- return this._simple(OperatorType.eq, parameter, constant);
45
+ eq(parameter: string, constant: any): WhereQuery<QueryType> {
46
+ return this.simple(EXPRESSION_TYPE.eq, parameter, constant);
75
47
  }
48
+
76
49
  /**
77
50
  * Adds a condition that a field must *not* be equal to a specific value.
78
- * @method ne
79
- * @memberOf WhereQuery.prototype
80
- * @param {string} field Field name.
81
- * @param {*} value Comparison value (to which the field must not be equal).
82
- * @returns {WhereQuery}
83
51
  */
84
- ne(parameter: string, constant: any): WhereQuery {
85
- return this._simple(OperatorType.ne, parameter, constant);
52
+ ne(parameter: string, constant: any): WhereQuery<QueryType> {
53
+ return this.simple(EXPRESSION_TYPE.ne, parameter, constant);
86
54
  }
55
+
87
56
  /**
88
57
  * Adds a condition that a field must be `greater than` a certain value. Applicable to Number, String, and Date fields.
89
- * @method gt
90
- * @memberOf WhereQuery.prototype
91
- * @param {string} field Field name.
92
- * @param {*} value Comparison value (that the field should be greater than).
93
- * @returns {WhereQuery}
94
58
  */
95
59
  gt(parameter: string, constant: any) {
96
- return this._simple(OperatorType.gt, parameter, constant);
60
+ return this.simple(EXPRESSION_TYPE.gt, parameter, constant);
97
61
  }
62
+
98
63
  /**
99
64
  * Adds a condition that a field must be `greater than or equal` to a certain value. Applicable to Number, String, and Date fields.
100
- * @method gte
101
- * @memberOf WhereQuery.prototype
102
- * @param {string} field Field name.
103
- * @param {*} value Comparison value (that the field should be greater than or equal to).
104
- * @returns {WhereQuery}
105
65
  */
106
66
  gte(parameter: string, constant: any) {
107
- return this._simple(OperatorType.ge, parameter, constant);
67
+ return this.simple(EXPRESSION_TYPE.ge, parameter, constant);
108
68
  }
69
+
109
70
  /**
110
71
  * Adds a condition that a field must be `less than` a certain value. Applicable to Number, String, and Date fields.
111
- * @method lt
112
- * @memberOf WhereQuery.prototype
113
- * @param {string} field Field name.
114
- * @param {*} value Comparison value (that the field should be less than).
115
- * @returns {WhereQuery}
116
72
  */
117
73
  lt(parameter: string, constant: any) {
118
- return this._simple(OperatorType.lt, parameter, constant);
74
+ return this.simple(EXPRESSION_TYPE.lt, parameter, constant);
119
75
  }
76
+
120
77
  /**
121
78
  * Adds a condition that a field must be `less than or equal` to a certain value. Applicable to Number, String, and Date fields.
122
- * @method lte
123
- * @memberOf WhereQuery.prototype
124
- * @param {string} field Field name.
125
- * @param {*} value Comparison value (that the field should be less than or equal to).
126
- * @returns {WhereQuery}
127
79
  */
128
80
  lte(parameter: string, constant: any) {
129
- return this._simple(OperatorType.le, parameter, constant);
81
+ return this.simple(EXPRESSION_TYPE.le, parameter, constant);
130
82
  }
83
+
131
84
  /**
132
85
  * Adds a condition that a field value must *start* with a specified string.
133
- * @method startsWith
134
- * @memberOf WhereQuery.prototype
135
- * @param {string} field Field name.
136
- * @param {string} value The string that the field should start with.
137
- * @param {boolean} caseSensitive A flag indicating if tolower should be applied to the parameter
138
- * @param {string} [options] A string of regex options to use. See [specs](http://docs.mongodb.org/manual/reference/operator/query/regex/#op._S_options) for a description of available options.
139
- * @returns {WhereQuery}
140
86
  */
141
- startsWith(parameter: string, constant: any, caseSensitive: boolean = true): WhereQuery {
142
- return this._simple(OperatorType.startsWith, parameter, constant, caseSensitive);
87
+ startsWith(parameter: string, constant: any, caseSensitive = true) {
88
+ return this.simple(EXPRESSION_TYPE.startsWith, parameter, constant, caseSensitive);
143
89
  }
144
90
 
145
91
  /**
146
92
  * Adds a condition that a field value must *contain* a specified string.
147
- * @method startsWith
148
- * @memberOf WhereQuery.prototype
149
- * @param {string} field Field name.
150
- * @param {string} value The string that the field should start with.
151
- * @param {boolean} caseSensitive A flag indicating if tolower should be applied to the parameter
152
- * @param {string} [options] A string of regex options to use. See [specs](http://docs.mongodb.org/manual/reference/operator/query/regex/#op._S_options) for a description of available options.
153
- * @returns {WhereQuery}
154
93
  */
155
- contains(parameter: string, constant: any, caseSensitive: boolean = true) {
156
- return this._simple(OperatorType.contains, parameter, constant, caseSensitive);
94
+ contains(parameter: string, constant: any, caseSensitive = true) {
95
+ return this.simple(EXPRESSION_TYPE.contains, parameter, constant, caseSensitive);
157
96
  }
158
97
 
159
98
  /**
160
99
  * Adds a condition that a field value must *end* with a specified string.
161
- * @method endsWith
162
- * @memberOf WhereQuery.prototype
163
- * @param {string} field Field name.
164
- * @param {string} value The string that the field should end with.
165
- * @param {boolean} caseSensitive A flag indicating if tolower should be applied to the parameter
166
- * @param {string} [options] A string of regex options to use. See [specs](http://docs.mongodb.org/manual/reference/operator/query/regex/#op._S_options) for a description of available options.
167
- * @returns {WhereQuery}
168
100
  */
169
- endsWith(parameter: string, constant: any, caseSensitive: boolean = true) {
170
- return this._simple(OperatorType.endsWith, parameter, constant, caseSensitive);
101
+ endsWith(parameter: string, constant: any, caseSensitive = true) {
102
+ return this.simple(EXPRESSION_TYPE.endsWith, parameter, constant, caseSensitive);
171
103
  }
172
104
 
173
105
  /**
174
106
  * Ends the definition of the current WhereQuery. You need to call this method in order to continue with the definition of the parent {@link QueryBase}. All other `WhereQuery` methods return the current instance of `WhereQuery` to allow chaining.
175
- * @method done
176
- * @memberOf WhereQuery.prototype
177
- * @returns {Query}
178
107
  */
179
- done() {
108
+ done(): QueryType {
180
109
  if (this.parent instanceof WhereQuery) {
181
- this.parent._addComplexExpression(this);
110
+ this.parent.addComplexExpression(this);
182
111
  // TODO: If has and() || or() must call done() twice
183
- if (this.expression.getType() === OperatorType.not)
112
+ if (this.expression.getType() === EXPRESSION_TYPE.not)
184
113
  return this.parent;
185
114
  }
186
115
 
187
116
  return this.parent;
188
117
  }
189
118
 
190
- _getExpression() {
119
+ getExpression(): ComplexExpression {
191
120
  return this.expression;
192
121
  }
193
122
 
194
- private _addComplexExpression(subQuery): void {
195
- var subExpression = subQuery._getExpression();
123
+ private simple(type: string, parameter: string, constant: any, caseSensitive = true): WhereQuery<QueryType> {
124
+ const currentExpr = new BinaryExpression(type, parameter, constant, caseSensitive);
125
+ const subExpressions = this.expression.getExpressions();
126
+ subExpressions.push(currentExpr);
127
+
128
+ if (this.expression.getType() === EXPRESSION_TYPE.not && subExpressions.length > 1)
129
+ throw new Error("Invalid operators count!");
130
+
131
+ return this;
132
+ }
133
+
134
+ private addComplexExpression(subQuery: WhereQuery<QueryType>): void {
135
+ const subExpression = subQuery.getExpression();
196
136
  this.expression.getExpressions().push(subExpression);
197
137
  }
198
138
  }
package/src/constants.ts CHANGED
@@ -1,41 +1,60 @@
1
- const constants = {
2
- ExpressionType: {
3
- query: 1,
4
- where: 100,
5
- and: 'and',
6
- or: 'or',
7
- not: 'not',
8
- eq: 'eq',
9
- ne: 'ne',
10
- lt: 'lt',
11
- le: 'le',
12
- gt: 'gt',
13
- ge: 'ge',
14
- any: 'any',
15
- /*isin: 126,
16
- notin: 127,
17
- all: 128,
18
- size: 129,
19
- regex: 130,*/
20
- contains: 'contains',
21
- startsWith: 'startsWith',
22
- endsWith: 'endsWith'
23
- },
24
- ODataParams: {
25
- $filter: '$filter',
26
- $select: '$select',
27
- $expand: '$expand',
28
- $orderby: '$orderby',
29
- $skip: '$skip',
30
- $top: '$top',
31
- $count: '$count',
32
- $search: '$search'
33
- },
34
- SfParams: {
35
- provider: 'sf_provider',
36
- culture: 'sf_culture',
37
- siteId: 'sf_site'
38
- }
1
+ export const EXPRESSION_TYPE = {
2
+ query: 1,
3
+ where: 100,
4
+ and: 'and',
5
+ or: 'or',
6
+ not: 'not',
7
+ eq: 'eq',
8
+ ne: 'ne',
9
+ lt: 'lt',
10
+ le: 'le',
11
+ gt: 'gt',
12
+ ge: 'ge',
13
+ any: 'any',
14
+ contains: 'contains',
15
+ startsWith: 'startsWith',
16
+ endsWith: 'endsWith'
17
+ }
18
+
19
+ export const ODATA_PARAMS = {
20
+ $filter: '$filter',
21
+ $select: '$select',
22
+ $expand: '$expand',
23
+ $orderby: '$orderby',
24
+ $skip: '$skip',
25
+ $top: '$top',
26
+ $count: '$count',
27
+ $search: '$search'
28
+ }
29
+
30
+ export const SF_PARAMS = {
31
+ provider: 'sf_provider',
32
+ culture: 'sf_culture',
33
+ siteId: 'sf_site',
34
+ fallbackParams: "sf_fallback_prop_names",
35
+ parentId: "parentId"
36
+ }
37
+
38
+ export const HEADER_NAMES = {
39
+ contentType: "Content-Type",
40
+ authorization: "Authorization",
41
+ contentEncoding: "Content-Encoding",
42
+ operation: "X-Operation",
43
+ properties: "X-Sf-Properties",
44
+ fileName: "X-File-Name",
45
+ serviceRequest: "X-SF-Service-Request",
46
+ choicesBinaryRepresentation: "X-SF-Binary-Choice-Representation",
47
+ integrationMode: "X-SF-Integration-Mode"
48
+ }
49
+
50
+ export const HTTP_METHODS = {
51
+ get: "GET",
52
+ put: "PUT",
53
+ post: "POST",
54
+ patch: "PATCH",
55
+ delete: "DELETE"
39
56
  };
40
57
 
41
- export default constants;
58
+ export const CONTENT_TYPES = {
59
+ json: "application/json"
60
+ }