d5-api-initializer 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d5-api-initializer",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "license": "MIT",
5
5
  "dependencies": {},
6
6
  "main": "publish/cjs/d5-api-initializer",
@@ -128,8 +128,8 @@ var ApiHttpRequest = class {
128
128
  set timeout(milliseconds) {
129
129
  this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
130
130
  }
131
- setHeader(name, value) {
132
- this._jsWapiHttp = this._jsWapiHttp.setHeader(name, "".concat(value));
131
+ setHeader(header, value) {
132
+ this._jsWapiHttp = this._jsWapiHttp.setHeader(header, "".concat(value));
133
133
  return this;
134
134
  }
135
135
  setHeaders(headers) {
@@ -145,7 +145,7 @@ var ApiHttpRequest = class {
145
145
  GET(callback) {
146
146
  return this._jsWapiHttp.GET(this._getWrappedCallback(callback));
147
147
  }
148
- POST(request, callback) {
148
+ POST(request = {}, callback) {
149
149
  return this._jsWapiHttp.POST((req) => {
150
150
  if (request instanceof FileLink)
151
151
  return req.setBody((body) => body.setFileLink(request.link));
@@ -154,6 +154,9 @@ var ApiHttpRequest = class {
154
154
  if (request instanceof MultipartFormData) {
155
155
  return this.setMultipartBody(req, request);
156
156
  }
157
+ if (typeof request === "string") {
158
+ return req.setBody(request);
159
+ }
157
160
  return req.setBody(JSON.stringify(request));
158
161
  }, this._getWrappedCallback(callback));
159
162
  }
@@ -177,11 +180,11 @@ var ApiHttpRequest = class {
177
180
  return body;
178
181
  });
179
182
  }
180
- PUT(requestBody, callback) {
181
- return this._jsWapiHttp.PUT(JSON.stringify(requestBody), this._getWrappedCallback(callback));
183
+ PUT(body = {}, callback) {
184
+ return this._jsWapiHttp.PUT(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
182
185
  }
183
- PATCH(requestBody, callback) {
184
- return this._jsWapiHttp.PATCH(JSON.stringify(requestBody), this._getWrappedCallback(callback));
186
+ PATCH(body = {}, callback) {
187
+ return this._jsWapiHttp.PATCH(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
185
188
  }
186
189
  _getWrappedCallback(callback) {
187
190
  return (res) => {
@@ -227,12 +230,20 @@ var ApiResponse = class {
227
230
  }
228
231
  return this;
229
232
  }
230
- sendHttpResponse(headers, body) {
231
- this._jsWapiResponse.sendHttpResponse(headers, body);
232
- return this;
233
+ sendHttpResponse() {
234
+ const args = [...arguments];
235
+ if (args[0] && args[1]) {
236
+ this._jsWapiResponse.sendHttpResponse(args[0], args[1]);
237
+ return this;
238
+ }
239
+ if (args[0] && !args[1]) {
240
+ this._jsWapiResponse.sendHttpResponse(args[0]);
241
+ return this;
242
+ }
243
+ throw new Error("Wrong parameters in function sendHttpResponse()");
233
244
  }
234
245
  sendHttpBody(body) {
235
- this._jsWapiResponse.sendHttpResponse({}, body);
246
+ this._jsWapiResponse.sendHttpResponse(body);
236
247
  return this;
237
248
  }
238
249
  getPage() {
@@ -72,6 +72,7 @@ declare namespace jsWapi {
72
72
  setResponse(resp: {
73
73
  [key: string]: Record<string, any>[];
74
74
  }): void;
75
+ sendHttpResponse(body: string | BinaryDataStream): void;
75
76
  sendHttpResponse(headers: Record<string, any>, body: string | BinaryDataStream): void;
76
77
  getPagesPredict(): number;
77
78
  setPagesPredict(pagesPredict: number): void;
@@ -173,16 +174,16 @@ declare class MultipartFormData {
173
174
  declare class ApiHttpRequest {
174
175
  private _jsWapiHttp;
175
176
  constructor(jsWapiHttp: jsWapi.JSWapiHttp);
176
- set headers(headers: IMappedCollection);
177
+ set headers(headers: Record<string, string>);
177
178
  set timeout(milliseconds: number);
178
- setHeader(name: string, value: any): ApiHttpRequest;
179
- setHeaders(headers: IMappedCollection): ApiHttpRequest;
179
+ setHeader(header: string, value: string): ApiHttpRequest;
180
+ setHeaders(headers: Record<string, string>): ApiHttpRequest;
180
181
  setTimeout(milliseconds: number): ApiHttpRequest;
181
182
  GET(callback?: IHttpCallback): any;
182
- POST(request: FileLink | FileRequestId | MultipartFormData | Record<string, any>, callback?: IHttpCallback): any;
183
+ POST(request?: FileLink | FileRequestId | MultipartFormData | Record<string, any> | string, callback?: IHttpCallback): any;
183
184
  private setMultipartBody;
184
- PUT(requestBody: IMappedCollection, callback?: IHttpCallback): any;
185
- PATCH(requestBody: IMappedCollection, callback: IHttpCallback): any;
185
+ PUT(body?: Record<string, any> | string, callback?: IHttpCallback): any;
186
+ PATCH(body: Record<string, any> | string, callback: IHttpCallback): any;
186
187
  private _getWrappedCallback;
187
188
  }
188
189
 
@@ -195,8 +196,9 @@ declare class ApiResponse {
195
196
  getResponse(responseName?: string): IMappedCollection[] | any;
196
197
  getResponseObject(): IMappedCollection[] | any;
197
198
  setResponse(response: IMappedCollection | any[], fieldsMap?: Record<string, any>): this;
198
- sendHttpResponse(headers: IMappedCollection, body: string | jsWapi.BinaryDataStream): this;
199
- sendHttpBody(body: string): this;
199
+ sendHttpResponse(body: string | jsWapi.BinaryDataStream): ApiResponse;
200
+ sendHttpResponse(headers: Record<string, string>, body: string | jsWapi.BinaryDataStream): ApiResponse;
201
+ sendHttpBody(body: string | jsWapi.BinaryDataStream): this;
200
202
  getPage(): number;
201
203
  setPage(page: number): this;
202
204
  getPagesPredict(): number;
@@ -438,22 +440,25 @@ declare class ApiHttpResponse {
438
440
  }
439
441
 
440
442
  interface IFilterValue {
441
- '='?: string | number | Array<string | number>;
442
- '>'?: string | number | Array<string | number>;
443
- '>='?: string | number | Array<string | number>;
444
- '<'?: string | number | Array<string | number>;
445
- '<='?: string | number | Array<string | number>;
446
- '!='?: string | number | Array<string | number>;
447
- 'between'?: string | number | Array<string | number>;
448
- 'like'?: string | number | Array<string | number>;
449
- '%'?: string | number | Array<string | number>;
443
+ '='?: string | number | null | Array<string | number>;
444
+ '=~'?: string | null | Array<string>;
445
+ '>'?: string | number;
446
+ '>='?: string | number;
447
+ '<'?: string | number;
448
+ '<='?: string | number;
449
+ '!='?: string | number | null | Array<string | number>;
450
+ '<>'?: string | number | null | Array<string | number>;
451
+ 'between'?: [string | number, string | number];
452
+ 'like'?: string | number;
453
+ '%'?: string;
454
+ '%~'?: string;
450
455
  }
451
456
  interface IFilter {
452
457
  [fieldName: string]: IFilterValue;
453
458
  }
454
- interface IFiltersCollection {
455
- [property: string]: IFilterValue | IFilter[];
456
- }
459
+ type IFiltersCollection = {
460
+ [fieldName: string]: IFilterValue | IFilterValue[] | IFiltersCollection[];
461
+ };
457
462
  interface IMappedCollection {
458
463
  [name: string]: any;
459
464
  }
@@ -89,8 +89,8 @@ var ApiHttpRequest = class {
89
89
  set timeout(milliseconds) {
90
90
  this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
91
91
  }
92
- setHeader(name, value) {
93
- this._jsWapiHttp = this._jsWapiHttp.setHeader(name, "".concat(value));
92
+ setHeader(header, value) {
93
+ this._jsWapiHttp = this._jsWapiHttp.setHeader(header, "".concat(value));
94
94
  return this;
95
95
  }
96
96
  setHeaders(headers) {
@@ -106,7 +106,7 @@ var ApiHttpRequest = class {
106
106
  GET(callback) {
107
107
  return this._jsWapiHttp.GET(this._getWrappedCallback(callback));
108
108
  }
109
- POST(request, callback) {
109
+ POST(request = {}, callback) {
110
110
  return this._jsWapiHttp.POST((req) => {
111
111
  if (request instanceof FileLink)
112
112
  return req.setBody((body) => body.setFileLink(request.link));
@@ -115,6 +115,9 @@ var ApiHttpRequest = class {
115
115
  if (request instanceof MultipartFormData) {
116
116
  return this.setMultipartBody(req, request);
117
117
  }
118
+ if (typeof request === "string") {
119
+ return req.setBody(request);
120
+ }
118
121
  return req.setBody(JSON.stringify(request));
119
122
  }, this._getWrappedCallback(callback));
120
123
  }
@@ -138,11 +141,11 @@ var ApiHttpRequest = class {
138
141
  return body;
139
142
  });
140
143
  }
141
- PUT(requestBody, callback) {
142
- return this._jsWapiHttp.PUT(JSON.stringify(requestBody), this._getWrappedCallback(callback));
144
+ PUT(body = {}, callback) {
145
+ return this._jsWapiHttp.PUT(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
143
146
  }
144
- PATCH(requestBody, callback) {
145
- return this._jsWapiHttp.PATCH(JSON.stringify(requestBody), this._getWrappedCallback(callback));
147
+ PATCH(body = {}, callback) {
148
+ return this._jsWapiHttp.PATCH(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
146
149
  }
147
150
  _getWrappedCallback(callback) {
148
151
  return (res) => {
@@ -188,12 +191,20 @@ var ApiResponse = class {
188
191
  }
189
192
  return this;
190
193
  }
191
- sendHttpResponse(headers, body) {
192
- this._jsWapiResponse.sendHttpResponse(headers, body);
193
- return this;
194
+ sendHttpResponse() {
195
+ const args = [...arguments];
196
+ if (args[0] && args[1]) {
197
+ this._jsWapiResponse.sendHttpResponse(args[0], args[1]);
198
+ return this;
199
+ }
200
+ if (args[0] && !args[1]) {
201
+ this._jsWapiResponse.sendHttpResponse(args[0]);
202
+ return this;
203
+ }
204
+ throw new Error("Wrong parameters in function sendHttpResponse()");
194
205
  }
195
206
  sendHttpBody(body) {
196
- this._jsWapiResponse.sendHttpResponse({}, body);
207
+ this._jsWapiResponse.sendHttpResponse(body);
197
208
  return this;
198
209
  }
199
210
  getPage() {
@@ -89,8 +89,8 @@ var ApiHttpRequest = class {
89
89
  set timeout(milliseconds) {
90
90
  this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
91
91
  }
92
- setHeader(name, value) {
93
- this._jsWapiHttp = this._jsWapiHttp.setHeader(name, "".concat(value));
92
+ setHeader(header, value) {
93
+ this._jsWapiHttp = this._jsWapiHttp.setHeader(header, "".concat(value));
94
94
  return this;
95
95
  }
96
96
  setHeaders(headers) {
@@ -106,7 +106,7 @@ var ApiHttpRequest = class {
106
106
  GET(callback) {
107
107
  return this._jsWapiHttp.GET(this._getWrappedCallback(callback));
108
108
  }
109
- POST(request, callback) {
109
+ POST(request = {}, callback) {
110
110
  return this._jsWapiHttp.POST((req) => {
111
111
  if (request instanceof FileLink)
112
112
  return req.setBody((body) => body.setFileLink(request.link));
@@ -115,6 +115,9 @@ var ApiHttpRequest = class {
115
115
  if (request instanceof MultipartFormData) {
116
116
  return this.setMultipartBody(req, request);
117
117
  }
118
+ if (typeof request === "string") {
119
+ return req.setBody(request);
120
+ }
118
121
  return req.setBody(JSON.stringify(request));
119
122
  }, this._getWrappedCallback(callback));
120
123
  }
@@ -138,11 +141,11 @@ var ApiHttpRequest = class {
138
141
  return body;
139
142
  });
140
143
  }
141
- PUT(requestBody, callback) {
142
- return this._jsWapiHttp.PUT(JSON.stringify(requestBody), this._getWrappedCallback(callback));
144
+ PUT(body = {}, callback) {
145
+ return this._jsWapiHttp.PUT(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
143
146
  }
144
- PATCH(requestBody, callback) {
145
- return this._jsWapiHttp.PATCH(JSON.stringify(requestBody), this._getWrappedCallback(callback));
147
+ PATCH(body = {}, callback) {
148
+ return this._jsWapiHttp.PATCH(typeof body === "string" ? body : JSON.stringify(body), this._getWrappedCallback(callback));
146
149
  }
147
150
  _getWrappedCallback(callback) {
148
151
  return (res) => {
@@ -188,12 +191,20 @@ var ApiResponse = class {
188
191
  }
189
192
  return this;
190
193
  }
191
- sendHttpResponse(headers, body) {
192
- this._jsWapiResponse.sendHttpResponse(headers, body);
193
- return this;
194
+ sendHttpResponse() {
195
+ const args = [...arguments];
196
+ if (args[0] && args[1]) {
197
+ this._jsWapiResponse.sendHttpResponse(args[0], args[1]);
198
+ return this;
199
+ }
200
+ if (args[0] && !args[1]) {
201
+ this._jsWapiResponse.sendHttpResponse(args[0]);
202
+ return this;
203
+ }
204
+ throw new Error("Wrong parameters in function sendHttpResponse()");
194
205
  }
195
206
  sendHttpBody(body) {
196
- this._jsWapiResponse.sendHttpResponse({}, body);
207
+ this._jsWapiResponse.sendHttpResponse(body);
197
208
  return this;
198
209
  }
199
210
  getPage() {