d5-api-initializer 1.1.2 → 1.1.3-alpha.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/CHANGELOG.md +0 -0
- package/README.md +6 -6
- package/package.json +47 -46
- package/publish/cjs/d5-api-initializer.cjs +0 -946
- package/publish/d5-api-initializer.d.ts +0 -486
- package/publish/d5-api-initializer.legacy-esm.js +0 -910
- package/publish/d5-api-initializer.mjs +0 -910
|
@@ -1,910 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/classes/ApiHttpResponse.ts
|
|
9
|
-
var ApiHttpResponse = class {
|
|
10
|
-
constructor(jsWapiHttpResponse) {
|
|
11
|
-
__publicField(this, "_jsWapiHttpResponse");
|
|
12
|
-
this._jsWapiHttpResponse = jsWapiHttpResponse;
|
|
13
|
-
}
|
|
14
|
-
get statusCode() {
|
|
15
|
-
return this._jsWapiHttpResponse.getStatusCode();
|
|
16
|
-
}
|
|
17
|
-
get body() {
|
|
18
|
-
return this._jsWapiHttpResponse.getBody();
|
|
19
|
-
}
|
|
20
|
-
get bodyAsStream() {
|
|
21
|
-
return this._jsWapiHttpResponse.getBodyAsInputStream();
|
|
22
|
-
}
|
|
23
|
-
getHeader(name) {
|
|
24
|
-
return this._jsWapiHttpResponse.getHeader(name);
|
|
25
|
-
}
|
|
26
|
-
isSuccessful() {
|
|
27
|
-
return this._jsWapiHttpResponse.isSuccessful();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/classes/ApiHttpRequest.ts
|
|
32
|
-
var ApiHttpRequest = class {
|
|
33
|
-
constructor(jsWapiHttp) {
|
|
34
|
-
__publicField(this, "_jsWapiHttp");
|
|
35
|
-
this._jsWapiHttp = jsWapiHttp;
|
|
36
|
-
}
|
|
37
|
-
set headers(headers) {
|
|
38
|
-
for (const headersKey in headers) {
|
|
39
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(headersKey, JSON.stringify(headers[headersKey]));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
set timeout(milliseconds) {
|
|
43
|
-
this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
|
|
44
|
-
}
|
|
45
|
-
setHeader(name, value) {
|
|
46
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(name, "".concat(value));
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
setHeaders(headers) {
|
|
50
|
-
for (const headersKey in headers) {
|
|
51
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(headersKey, "".concat(headers[headersKey]));
|
|
52
|
-
}
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
setTimeout(milliseconds) {
|
|
56
|
-
this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
GET(callback) {
|
|
60
|
-
return this._jsWapiHttp.GET(this._getWrappedCallback(callback));
|
|
61
|
-
}
|
|
62
|
-
POST(requestBody, callback) {
|
|
63
|
-
return this._jsWapiHttp.POST(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
64
|
-
}
|
|
65
|
-
PUT(requestBody, callback) {
|
|
66
|
-
return this._jsWapiHttp.PUT(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
67
|
-
}
|
|
68
|
-
PATCH(requestBody, callback) {
|
|
69
|
-
return this._jsWapiHttp.PATCH(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
70
|
-
}
|
|
71
|
-
_getWrappedCallback(callback) {
|
|
72
|
-
return (res) => {
|
|
73
|
-
if (callback) {
|
|
74
|
-
return callback(new ApiHttpResponse(res));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// src/classes/ApiResponse.ts
|
|
81
|
-
var ApiResponse = class {
|
|
82
|
-
constructor(jsWapiResponse, objectName) {
|
|
83
|
-
__publicField(this, "_jsWapiResponse");
|
|
84
|
-
__publicField(this, "_objectName");
|
|
85
|
-
this._jsWapiResponse = jsWapiResponse;
|
|
86
|
-
this._objectName = objectName;
|
|
87
|
-
}
|
|
88
|
-
get objectName() {
|
|
89
|
-
return this._objectName;
|
|
90
|
-
}
|
|
91
|
-
set response(response) {
|
|
92
|
-
this.setResponse(response);
|
|
93
|
-
}
|
|
94
|
-
getResponse(responseName) {
|
|
95
|
-
return this._jsWapiResponse.getResponse(responseName || this._objectName);
|
|
96
|
-
}
|
|
97
|
-
setResponse(response, fieldsMap) {
|
|
98
|
-
if (Array.isArray(response)) {
|
|
99
|
-
const data = !fieldsMap ? response : response.map((row) => {
|
|
100
|
-
const res = {};
|
|
101
|
-
for (const externalKey in fieldsMap) {
|
|
102
|
-
res[fieldsMap[externalKey]] = row[externalKey];
|
|
103
|
-
}
|
|
104
|
-
return res;
|
|
105
|
-
});
|
|
106
|
-
this._jsWapiResponse.putResponse(this._objectName, data);
|
|
107
|
-
} else {
|
|
108
|
-
this._jsWapiResponse.setResponse(response);
|
|
109
|
-
}
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
sendHttpResponse(headers, body) {
|
|
113
|
-
this._jsWapiResponse.sendHttpResponse(headers, body);
|
|
114
|
-
return this;
|
|
115
|
-
}
|
|
116
|
-
sendHttpBody(body) {
|
|
117
|
-
this._jsWapiResponse.sendHttpResponse({}, body);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
getPage() {
|
|
121
|
-
return this._jsWapiResponse.getPage();
|
|
122
|
-
}
|
|
123
|
-
setPage(page) {
|
|
124
|
-
this._jsWapiResponse.setPage(page);
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
getPagesPredict() {
|
|
128
|
-
return this._jsWapiResponse.getPagesPredict();
|
|
129
|
-
}
|
|
130
|
-
setPagesPredict(pagesPredict) {
|
|
131
|
-
this._jsWapiResponse.setPagesPredict(pagesPredict);
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// src/classes/ApiInvoker.ts
|
|
137
|
-
var ApiInvoker = class {
|
|
138
|
-
constructor(jsWapiInvoker, objectName) {
|
|
139
|
-
__publicField(this, "_jsWapiInvoker");
|
|
140
|
-
__publicField(this, "_objectName");
|
|
141
|
-
this._jsWapiInvoker = jsWapiInvoker;
|
|
142
|
-
this._objectName = objectName;
|
|
143
|
-
}
|
|
144
|
-
/* ----------------------------Accessors---------------------------- */
|
|
145
|
-
get objectName() {
|
|
146
|
-
return this._objectName;
|
|
147
|
-
}
|
|
148
|
-
set filters(filters) {
|
|
149
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setFilters(filters);
|
|
150
|
-
}
|
|
151
|
-
set params(params) {
|
|
152
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setParams(params);
|
|
153
|
-
}
|
|
154
|
-
set rowsPerPage(amount) {
|
|
155
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setRowsPerPage(amount);
|
|
156
|
-
}
|
|
157
|
-
set page(number) {
|
|
158
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setPage(number);
|
|
159
|
-
}
|
|
160
|
-
set pagesPredict(amount) {
|
|
161
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setPagesPredict(amount);
|
|
162
|
-
}
|
|
163
|
-
set request(request) {
|
|
164
|
-
if (Array.isArray(request)) {
|
|
165
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putRequest(this._objectName, request);
|
|
166
|
-
} else {
|
|
167
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setRequest(request);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
get request() {
|
|
171
|
-
return this._jsWapiInvoker.getRequest();
|
|
172
|
-
}
|
|
173
|
-
set columns(columns) {
|
|
174
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setColumns(columns);
|
|
175
|
-
}
|
|
176
|
-
set sorts(sorts) {
|
|
177
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setSorts(sorts);
|
|
178
|
-
}
|
|
179
|
-
set aggregatedColumns(aggregatedColumns) {
|
|
180
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setAggregatedColumns(aggregatedColumns);
|
|
181
|
-
}
|
|
182
|
-
set nestedColumns(nestedColumns) {
|
|
183
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setNestedColumns(nestedColumns);
|
|
184
|
-
}
|
|
185
|
-
set autocompleteLinkedObjectFields(value) {
|
|
186
|
-
this._jsWapiInvoker.putRequestModes((rm) => rm.setAutocompleteLinkedObjectFields(value));
|
|
187
|
-
}
|
|
188
|
-
set autocompleteKeyField(value) {
|
|
189
|
-
this._jsWapiInvoker.putRequestModes((rm) => rm.setAutocompleteKeyField(value));
|
|
190
|
-
}
|
|
191
|
-
/* -----------------------------Setters----------------------------- */
|
|
192
|
-
setAutocompleteLinkedObjectFields(value) {
|
|
193
|
-
this.autocompleteLinkedObjectFields = value;
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
setAutocompleteKeyField(value) {
|
|
197
|
-
this.autocompleteKeyField = value;
|
|
198
|
-
return this;
|
|
199
|
-
}
|
|
200
|
-
setHierarchy(parentColumn, requestKind) {
|
|
201
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setHierarchy(parentColumn, requestKind);
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
setFilters(filters) {
|
|
205
|
-
this.filters = filters;
|
|
206
|
-
return this;
|
|
207
|
-
}
|
|
208
|
-
setParams(params) {
|
|
209
|
-
this.params = params;
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
setPage(number) {
|
|
213
|
-
this.page = number;
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
setRowsPerPage(amount) {
|
|
217
|
-
this.rowsPerPage = amount;
|
|
218
|
-
return this;
|
|
219
|
-
}
|
|
220
|
-
setPagesPredict(amount) {
|
|
221
|
-
this.pagesPredict = amount;
|
|
222
|
-
return this;
|
|
223
|
-
}
|
|
224
|
-
setRequest(request) {
|
|
225
|
-
this.request = request;
|
|
226
|
-
return this;
|
|
227
|
-
}
|
|
228
|
-
getRequest(requestName) {
|
|
229
|
-
return this._jsWapiInvoker.getRequest(requestName);
|
|
230
|
-
}
|
|
231
|
-
setSrcRequest(srcRequest) {
|
|
232
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setSrcRequest(srcRequest);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
getSrcRequest() {
|
|
236
|
-
throw new Error("not implemented");
|
|
237
|
-
return this._jsWapiInvoker.getSrcRequest();
|
|
238
|
-
}
|
|
239
|
-
setColumns(columns) {
|
|
240
|
-
this.columns = columns;
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
setAggregatedColumns(aggregatedColumns) {
|
|
244
|
-
this.aggregatedColumns = aggregatedColumns;
|
|
245
|
-
return this;
|
|
246
|
-
}
|
|
247
|
-
setNestedColumns(nestedColumns) {
|
|
248
|
-
this.nestedColumns = nestedColumns;
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
setSorts(sorts) {
|
|
252
|
-
this.sorts = sorts;
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
setFirstRows(firstRows) {
|
|
256
|
-
this._jsWapiInvoker.setFirstRows(firstRows);
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
setOperRightCheck(check) {
|
|
260
|
-
this._jsWapiInvoker.setOperRightCheck(check);
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
263
|
-
getFirstRows() {
|
|
264
|
-
return this._jsWapiInvoker.getFirstRows();
|
|
265
|
-
}
|
|
266
|
-
/* -----------------------------Adders------------------------------ */
|
|
267
|
-
addColumns(columns) {
|
|
268
|
-
this._jsWapiInvoker = this._jsWapiInvoker.addColumns(columns);
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
addAggregatedColumns(aggregatedColumns) {
|
|
272
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putAggregatedColumns(aggregatedColumns);
|
|
273
|
-
return this;
|
|
274
|
-
}
|
|
275
|
-
addNestedColumns(nestedColumns) {
|
|
276
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putNestedColumns(nestedColumns);
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
addSorts(sorts) {
|
|
280
|
-
this._jsWapiInvoker = this._jsWapiInvoker.addSorts(sorts);
|
|
281
|
-
return this;
|
|
282
|
-
}
|
|
283
|
-
/* ------------------------------Other------------------------------ */
|
|
284
|
-
invoke() {
|
|
285
|
-
return new ApiResponse(this._jsWapiInvoker.invoke(), this._objectName);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// src/api-interfaces.ts
|
|
290
|
-
var LanguageCode = /* @__PURE__ */ ((LanguageCode2) => {
|
|
291
|
-
LanguageCode2["ua"] = "ua";
|
|
292
|
-
LanguageCode2["ru"] = "ru";
|
|
293
|
-
LanguageCode2["en"] = "eng";
|
|
294
|
-
return LanguageCode2;
|
|
295
|
-
})(LanguageCode || {});
|
|
296
|
-
|
|
297
|
-
// src/classes/UserMessages.ts
|
|
298
|
-
function formatMessage(text, args = []) {
|
|
299
|
-
let str = text;
|
|
300
|
-
for (let v in args) {
|
|
301
|
-
str = str.replace(`{${v}}`, args[v] == null ? "" : args[v]);
|
|
302
|
-
}
|
|
303
|
-
return str;
|
|
304
|
-
}
|
|
305
|
-
var UserMessages = class {
|
|
306
|
-
constructor() {
|
|
307
|
-
__publicField(this, "_messages", {});
|
|
308
|
-
__publicField(this, "_lang", "ua" /* ua */);
|
|
309
|
-
}
|
|
310
|
-
appendDictionary(newDictionary) {
|
|
311
|
-
if (Array.isArray(newDictionary) || !newDictionary || typeof newDictionary !== "object")
|
|
312
|
-
return;
|
|
313
|
-
for (const key in newDictionary) {
|
|
314
|
-
if (!this._messages.hasOwnProperty(key)) {
|
|
315
|
-
this._messages[key] = {};
|
|
316
|
-
}
|
|
317
|
-
this._messages[key] = Object.assign(this._messages[key], newDictionary[key]);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
format(msgKey, params) {
|
|
321
|
-
const msg = this._messages[this._lang]?.[msgKey] ?? msgKey;
|
|
322
|
-
return formatMessage(msg, params);
|
|
323
|
-
}
|
|
324
|
-
set lang(value) {
|
|
325
|
-
this._lang = value;
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
var UserMessages_default = new UserMessages();
|
|
329
|
-
|
|
330
|
-
// src/classes/ApiObjectCollectionIterator.ts
|
|
331
|
-
var ApiObjectCollectionIterator = class {
|
|
332
|
-
constructor({ invoker }) {
|
|
333
|
-
__publicField(this, "_invoker");
|
|
334
|
-
__publicField(this, "_rowsPerPage", 100);
|
|
335
|
-
this._invoker = invoker;
|
|
336
|
-
}
|
|
337
|
-
get objectName() {
|
|
338
|
-
return this._invoker.objectName;
|
|
339
|
-
}
|
|
340
|
-
/* -----------------------------Setters----------------------------- */
|
|
341
|
-
setColumns(columns) {
|
|
342
|
-
this._invoker.setColumns(columns);
|
|
343
|
-
return this;
|
|
344
|
-
}
|
|
345
|
-
setFilters(filters) {
|
|
346
|
-
this._invoker.setFilters(filters);
|
|
347
|
-
return this;
|
|
348
|
-
}
|
|
349
|
-
setSorts(sorts) {
|
|
350
|
-
this._invoker.setSorts(sorts);
|
|
351
|
-
return this;
|
|
352
|
-
}
|
|
353
|
-
/* -----------------------------Adders------------------------------ */
|
|
354
|
-
addSorts(sorts) {
|
|
355
|
-
this._invoker.addSorts(sorts);
|
|
356
|
-
return this;
|
|
357
|
-
}
|
|
358
|
-
addColumns(columns) {
|
|
359
|
-
this._invoker.addColumns(columns);
|
|
360
|
-
return this;
|
|
361
|
-
}
|
|
362
|
-
setRowsPerPage(amount) {
|
|
363
|
-
this._rowsPerPage = amount;
|
|
364
|
-
this._invoker.setRowsPerPage(amount);
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
/* ------------------------------Other------------------------------ */
|
|
368
|
-
*invoke() {
|
|
369
|
-
let data = null, pageCount = 1;
|
|
370
|
-
let lastPage = false;
|
|
371
|
-
while (!lastPage) {
|
|
372
|
-
this._invoker.page = pageCount;
|
|
373
|
-
data = new ApiResponse(this._invoker.invoke(), this.objectName).getResponse();
|
|
374
|
-
pageCount++;
|
|
375
|
-
if (Array.isArray(data)) {
|
|
376
|
-
for (let i = 0; i < data.length; i++) {
|
|
377
|
-
yield data[i];
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
lastPage = data.length < this._rowsPerPage;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
// src/classes/ApiFileInvoker.ts
|
|
386
|
-
var ApiFileInvoker = class {
|
|
387
|
-
constructor(jsWapiInvoker, params) {
|
|
388
|
-
__publicField(this, "_jsWapiInvoker");
|
|
389
|
-
__publicField(this, "_objectName");
|
|
390
|
-
this._jsWapiInvoker = jsWapiInvoker;
|
|
391
|
-
this._objectName = params.objectName;
|
|
392
|
-
this.setParams(params.keyValue, params.fileFieldName);
|
|
393
|
-
}
|
|
394
|
-
get objectName() {
|
|
395
|
-
return this._objectName;
|
|
396
|
-
}
|
|
397
|
-
setParams(keyValue, fileFieldName) {
|
|
398
|
-
this._jsWapiInvoker.setSingleColumn(fileFieldName);
|
|
399
|
-
this._jsWapiInvoker.setKeyValue(keyValue);
|
|
400
|
-
}
|
|
401
|
-
getExcelFileAsJson() {
|
|
402
|
-
return this._jsWapiInvoker.invokeAndGetExcelFileAsJson();
|
|
403
|
-
}
|
|
404
|
-
getFileAsString() {
|
|
405
|
-
return this._jsWapiInvoker.invokeAndGetFileAsString();
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/classes/ApiCore.ts
|
|
410
|
-
var ApiCore = class {
|
|
411
|
-
constructor({ http, request }) {
|
|
412
|
-
__publicField(this, "httpSender");
|
|
413
|
-
__publicField(this, "_request");
|
|
414
|
-
this.httpSender = http;
|
|
415
|
-
this._request = request;
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Переводит и форматирует строку из словаря переводов согласно текущего языка приложения.
|
|
419
|
-
* @param msgKey
|
|
420
|
-
* @param params
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* {
|
|
424
|
-
* ...
|
|
425
|
-
* "myKey": 'some text with {0}'
|
|
426
|
-
* ...
|
|
427
|
-
* }
|
|
428
|
-
* t('myKey', ['placeholder text']) // 'some text with placeholder text'
|
|
429
|
-
*/
|
|
430
|
-
t(msgKey, params) {
|
|
431
|
-
UserMessages_default.lang = this._request.lang || "ua" /* ua */;
|
|
432
|
-
return UserMessages_default.format(msgKey, params);
|
|
433
|
-
}
|
|
434
|
-
newHttpRequest(url) {
|
|
435
|
-
return new ApiHttpRequest(this.httpSender.newJSWapiHttp(url));
|
|
436
|
-
}
|
|
437
|
-
newApiInvoker(objectName, operName) {
|
|
438
|
-
return new ApiInvoker(this._request.newJSWapiInvoker(objectName, operName), objectName);
|
|
439
|
-
}
|
|
440
|
-
newApiFileInvoker(objectName, keyValue, fileFieldName) {
|
|
441
|
-
return new ApiFileInvoker(this._request.newJSWapiInvoker(objectName, "List"), {
|
|
442
|
-
objectName,
|
|
443
|
-
keyValue,
|
|
444
|
-
fileFieldName
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
newApiObjectCollectionIterator(objectName) {
|
|
448
|
-
return new ApiObjectCollectionIterator({
|
|
449
|
-
invoker: this.newApiInvoker(objectName, "List")
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
newApiException(message, code) {
|
|
453
|
-
if (code) {
|
|
454
|
-
return new JSWapiException(code.toString(), message);
|
|
455
|
-
}
|
|
456
|
-
return new JSWapiException(message);
|
|
457
|
-
}
|
|
458
|
-
/*
|
|
459
|
-
* Will be implemented later
|
|
460
|
-
*
|
|
461
|
-
newApiJoinInvoker(alias: string, request: ApiRequest | ApiInvoker): ApiJoinInvoker {
|
|
462
|
-
if (request instanceof ApiRequest) {
|
|
463
|
-
return new ApiJoinInvoker(this._jsWapiRequest.newJSWapiJoinInvoker(alias, request._jsWapiRequest));
|
|
464
|
-
} else if (request instanceof ApiInvoker) {
|
|
465
|
-
return new ApiJoinInvoker(this._jsWapiRequest.newJSWapiJoinInvoker(alias, request._jsWapiInvoker));
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
*/
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
// src/classes/ApiRequest.ts
|
|
472
|
-
var ApiRequest = class {
|
|
473
|
-
constructor(jsWapiRequest, objectName) {
|
|
474
|
-
__publicField(this, "_jsWapiRequest");
|
|
475
|
-
__publicField(this, "_objectName");
|
|
476
|
-
this._jsWapiRequest = jsWapiRequest;
|
|
477
|
-
this._objectName = objectName;
|
|
478
|
-
}
|
|
479
|
-
/* ----------------------------Accessors---------------------------- */
|
|
480
|
-
get objectName() {
|
|
481
|
-
return this._objectName;
|
|
482
|
-
}
|
|
483
|
-
get columns() {
|
|
484
|
-
return this._jsWapiRequest.getColumns();
|
|
485
|
-
}
|
|
486
|
-
get aggregatedColumns() {
|
|
487
|
-
return this._jsWapiRequest.getAggregatedColumns();
|
|
488
|
-
}
|
|
489
|
-
get nestedColumns() {
|
|
490
|
-
return this._jsWapiRequest.getNestedColumns();
|
|
491
|
-
}
|
|
492
|
-
get filters() {
|
|
493
|
-
return this._jsWapiRequest.getFilters();
|
|
494
|
-
}
|
|
495
|
-
get params() {
|
|
496
|
-
return this._jsWapiRequest.getParams();
|
|
497
|
-
}
|
|
498
|
-
get request() {
|
|
499
|
-
return this._jsWapiRequest.getRequest(this._objectName);
|
|
500
|
-
}
|
|
501
|
-
get userId() {
|
|
502
|
-
return this._jsWapiRequest.getUserId();
|
|
503
|
-
}
|
|
504
|
-
get page() {
|
|
505
|
-
return this._jsWapiRequest.getPage();
|
|
506
|
-
}
|
|
507
|
-
get rowsPerPage() {
|
|
508
|
-
return this._jsWapiRequest.getRowsPerPage();
|
|
509
|
-
}
|
|
510
|
-
get sorts() {
|
|
511
|
-
return this._jsWapiRequest.getSorts();
|
|
512
|
-
}
|
|
513
|
-
get lang() {
|
|
514
|
-
return this._jsWapiRequest.getLanguage();
|
|
515
|
-
}
|
|
516
|
-
set columns(columns) {
|
|
517
|
-
this._jsWapiRequest = this._jsWapiRequest.setColumns(columns);
|
|
518
|
-
}
|
|
519
|
-
set aggregatedColumns(columns) {
|
|
520
|
-
this._jsWapiRequest = this._jsWapiRequest.setAggregatedColumns(columns);
|
|
521
|
-
}
|
|
522
|
-
set nestedColumns(columns) {
|
|
523
|
-
this._jsWapiRequest = this._jsWapiRequest.setNestedColumns(columns);
|
|
524
|
-
}
|
|
525
|
-
set filters(filters) {
|
|
526
|
-
this._jsWapiRequest = this._jsWapiRequest.setFilters(filters);
|
|
527
|
-
}
|
|
528
|
-
set params(params) {
|
|
529
|
-
this._jsWapiRequest = this._jsWapiRequest.setParams(params);
|
|
530
|
-
}
|
|
531
|
-
set sorts(sorts) {
|
|
532
|
-
this._jsWapiRequest = this._jsWapiRequest.setSorts(sorts);
|
|
533
|
-
}
|
|
534
|
-
set page(number) {
|
|
535
|
-
this._jsWapiRequest = this._jsWapiRequest.setPage(number);
|
|
536
|
-
}
|
|
537
|
-
set rowsPerPage(amount) {
|
|
538
|
-
this._jsWapiRequest = this._jsWapiRequest.setRowsPerPage(amount);
|
|
539
|
-
}
|
|
540
|
-
/* -----------------------------Getters----------------------------- */
|
|
541
|
-
getFilter(filterName) {
|
|
542
|
-
return this._jsWapiRequest.getFilter(filterName);
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Вернуть значение фильтра типа "равно".
|
|
546
|
-
* Возможные варианты:
|
|
547
|
-
* "поле": "значение"
|
|
548
|
-
* "поле": {"=": "значение"}
|
|
549
|
-
* "поле": ["значение"]
|
|
550
|
-
* "поле": {"=": [123]}
|
|
551
|
-
* Это чтобы не парсить каждый раз все эти варианты.
|
|
552
|
-
*
|
|
553
|
-
* Работает только для условия "равно", для други возвращает null!!!!
|
|
554
|
-
*/
|
|
555
|
-
getFilterValue(fieldName) {
|
|
556
|
-
return this._jsWapiRequest.getFilterEqualOneValue(fieldName);
|
|
557
|
-
}
|
|
558
|
-
getParam(paramName) {
|
|
559
|
-
return this._jsWapiRequest.getParam(paramName);
|
|
560
|
-
}
|
|
561
|
-
getExcelFileAsJson(fileRequestId) {
|
|
562
|
-
return this._jsWapiRequest.getExcelFileAsJson(fileRequestId);
|
|
563
|
-
}
|
|
564
|
-
getFileAsString(fileRequestId) {
|
|
565
|
-
return this._jsWapiRequest.getFileAsString(fileRequestId);
|
|
566
|
-
}
|
|
567
|
-
getFilesListAsString(filesRequestIds) {
|
|
568
|
-
return this._jsWapiRequest.getMultiFileAsString(...this._getWithStringifiedElements(filesRequestIds));
|
|
569
|
-
}
|
|
570
|
-
getExcelFilesListAsJson(filesRequestIds) {
|
|
571
|
-
return this._jsWapiRequest.getMultiExcelFileAsJson(...this._getWithStringifiedElements(filesRequestIds));
|
|
572
|
-
}
|
|
573
|
-
getRequest(requestName) {
|
|
574
|
-
return this._jsWapiRequest.getRequest(requestName);
|
|
575
|
-
}
|
|
576
|
-
/* -----------------------------Setters----------------------------- */
|
|
577
|
-
setHierarchy(parentColumn, requestKind) {
|
|
578
|
-
this._jsWapiRequest = this._jsWapiRequest.setHierarchy(parentColumn, requestKind);
|
|
579
|
-
return this;
|
|
580
|
-
}
|
|
581
|
-
setColumns(columns) {
|
|
582
|
-
this.columns = columns;
|
|
583
|
-
return this;
|
|
584
|
-
}
|
|
585
|
-
setNestedColumns(nestedColumns) {
|
|
586
|
-
this.nestedColumns = nestedColumns;
|
|
587
|
-
return this;
|
|
588
|
-
}
|
|
589
|
-
setAggregatedColumns(aggregatedColumns) {
|
|
590
|
-
this.aggregatedColumns = aggregatedColumns;
|
|
591
|
-
return this;
|
|
592
|
-
}
|
|
593
|
-
setFilters(filters) {
|
|
594
|
-
this.filters = filters;
|
|
595
|
-
return this;
|
|
596
|
-
}
|
|
597
|
-
setSorts(sorts) {
|
|
598
|
-
this.sorts = sorts;
|
|
599
|
-
return this;
|
|
600
|
-
}
|
|
601
|
-
setParams(params) {
|
|
602
|
-
this.params = params;
|
|
603
|
-
return this;
|
|
604
|
-
}
|
|
605
|
-
setPage(number) {
|
|
606
|
-
this.page = number;
|
|
607
|
-
return this;
|
|
608
|
-
}
|
|
609
|
-
setRowsPerPage(amount) {
|
|
610
|
-
this.rowsPerPage = amount;
|
|
611
|
-
return this;
|
|
612
|
-
}
|
|
613
|
-
setRequest(request) {
|
|
614
|
-
if (Array.isArray(request)) {
|
|
615
|
-
this._jsWapiRequest = this._jsWapiRequest.putRequest(this._objectName, request);
|
|
616
|
-
} else {
|
|
617
|
-
this._jsWapiRequest = this._jsWapiRequest.setRequest(request);
|
|
618
|
-
}
|
|
619
|
-
return this;
|
|
620
|
-
}
|
|
621
|
-
setFirstRows(firstRows) {
|
|
622
|
-
this._jsWapiRequest.setFirstRows(firstRows);
|
|
623
|
-
return this;
|
|
624
|
-
}
|
|
625
|
-
getFirstRows() {
|
|
626
|
-
return this._jsWapiRequest.getFirstRows();
|
|
627
|
-
}
|
|
628
|
-
addSorts(sorts) {
|
|
629
|
-
this._jsWapiRequest = this._jsWapiRequest.addSorts(sorts);
|
|
630
|
-
return this;
|
|
631
|
-
}
|
|
632
|
-
addColumns(columns) {
|
|
633
|
-
this._jsWapiRequest = this._jsWapiRequest.addColumns(columns);
|
|
634
|
-
return this;
|
|
635
|
-
}
|
|
636
|
-
addAggregatedColumns(columns) {
|
|
637
|
-
this._jsWapiRequest = this._jsWapiRequest.putAggregatedColumns(columns);
|
|
638
|
-
return this;
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* @link http://d5.develop.erp-director.com/userscript-docs/docs/server_scripts/api-request/api-request#addnestedcolumnscolumns
|
|
642
|
-
* @example
|
|
643
|
-
* apiRequest.addNestedColumns({
|
|
644
|
-
* 'AuthorsNested': {
|
|
645
|
-
* 'Columns': ['ID', 'Name']
|
|
646
|
-
* }
|
|
647
|
-
* });
|
|
648
|
-
*/
|
|
649
|
-
addNestedColumns(columns) {
|
|
650
|
-
this._jsWapiRequest = this._jsWapiRequest.putNestedColumns(columns);
|
|
651
|
-
return this;
|
|
652
|
-
}
|
|
653
|
-
addFilters(filters) {
|
|
654
|
-
this._jsWapiRequest = this._jsWapiRequest.putFilters(filters);
|
|
655
|
-
return this;
|
|
656
|
-
}
|
|
657
|
-
addParams(params) {
|
|
658
|
-
for (const name in params) {
|
|
659
|
-
this._jsWapiRequest = this._jsWapiRequest.putParam(name, params[name]);
|
|
660
|
-
}
|
|
661
|
-
return this;
|
|
662
|
-
}
|
|
663
|
-
/* ----------------------------Removers----------------------------- */
|
|
664
|
-
removeSorts(sortsNames) {
|
|
665
|
-
this._jsWapiRequest = this._jsWapiRequest.removeSorts(sortsNames);
|
|
666
|
-
return this;
|
|
667
|
-
}
|
|
668
|
-
removeColumns(columnsNames) {
|
|
669
|
-
this._jsWapiRequest = this._jsWapiRequest.removeColumns(columnsNames);
|
|
670
|
-
return this;
|
|
671
|
-
}
|
|
672
|
-
removeAggregatedColumns(aggregatedColumnsNames) {
|
|
673
|
-
this._jsWapiRequest = this._jsWapiRequest.removeAggregatedColumns(aggregatedColumnsNames);
|
|
674
|
-
return this;
|
|
675
|
-
}
|
|
676
|
-
removeNestedColumns(nestedColumnsNames) {
|
|
677
|
-
this._jsWapiRequest = this._jsWapiRequest.removeNestedColumns(nestedColumnsNames);
|
|
678
|
-
return this;
|
|
679
|
-
}
|
|
680
|
-
removeParams(paramsNames) {
|
|
681
|
-
this._jsWapiRequest = this._jsWapiRequest.removeParams(paramsNames);
|
|
682
|
-
return this;
|
|
683
|
-
}
|
|
684
|
-
removeFilters(filtersNames) {
|
|
685
|
-
this._jsWapiRequest = this._jsWapiRequest.removeFilters(filtersNames);
|
|
686
|
-
return this;
|
|
687
|
-
}
|
|
688
|
-
/* ------------------------------Other------------------------------ */
|
|
689
|
-
hasFilter(filterName) {
|
|
690
|
-
return this._jsWapiRequest.isFilterExists(filterName);
|
|
691
|
-
}
|
|
692
|
-
invoke() {
|
|
693
|
-
return new ApiResponse(this._jsWapiRequest.invoke(), this._objectName);
|
|
694
|
-
}
|
|
695
|
-
newJSWapiInvoker(objectName, operName) {
|
|
696
|
-
return this._jsWapiRequest.newJSWapiInvoker(objectName, operName);
|
|
697
|
-
}
|
|
698
|
-
newApiInvoker(objectName, operName) {
|
|
699
|
-
return new ApiInvoker(this.newJSWapiInvoker(objectName, operName), objectName);
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Переводит и форматирует строку из словаря переводов согласно текущего языка приложения.
|
|
703
|
-
* @param msgKey
|
|
704
|
-
* @param params
|
|
705
|
-
*
|
|
706
|
-
* @example
|
|
707
|
-
* {
|
|
708
|
-
* ...
|
|
709
|
-
* "myKey": 'some text with {0}'
|
|
710
|
-
* ...
|
|
711
|
-
* }
|
|
712
|
-
* t('myKey', ['placeholder text']) // 'some text with placeholder text'
|
|
713
|
-
*/
|
|
714
|
-
t(msgKey, params) {
|
|
715
|
-
UserMessages_default.lang = this.lang || "ua" /* ua */;
|
|
716
|
-
return UserMessages_default.format(msgKey, params);
|
|
717
|
-
}
|
|
718
|
-
/* -------------------------Support methods------------------------- */
|
|
719
|
-
_getWithStringifiedElements(array) {
|
|
720
|
-
return array.map((element) => element.toString());
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
// src/classes/ApiObjectInitializer.ts
|
|
725
|
-
var ApiInitializer = class {
|
|
726
|
-
constructor(settings, operations, options) {
|
|
727
|
-
__publicField(this, "_api");
|
|
728
|
-
__publicField(this, "_operations");
|
|
729
|
-
this._api = jsWapi;
|
|
730
|
-
const throwError = (msg) => {
|
|
731
|
-
throw new Error(msg);
|
|
732
|
-
};
|
|
733
|
-
if (typeof settings === "string") {
|
|
734
|
-
if (!operations)
|
|
735
|
-
throwError('The second argument "operations" is required');
|
|
736
|
-
this._operations = operations;
|
|
737
|
-
this.internalCreate(settings);
|
|
738
|
-
options?.translations && this.initTranslation(options.translations);
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
const { objectName, operations: opers, translations } = settings;
|
|
742
|
-
if (!opers)
|
|
743
|
-
throwError('Property "operations" in the settings is required');
|
|
744
|
-
this._operations = opers;
|
|
745
|
-
this.internalCreate(objectName);
|
|
746
|
-
translations && this.initTranslation(translations);
|
|
747
|
-
}
|
|
748
|
-
_initOperations(objectName) {
|
|
749
|
-
for (const operationName in this._operations) {
|
|
750
|
-
this.putOperation(operationName, objectName);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Инициализация словаря переводов.
|
|
755
|
-
* @param translations
|
|
756
|
-
* @example Пример строки перевода
|
|
757
|
-
* { ...
|
|
758
|
-
* "ru": {"key": 'some text {0} {1}'}
|
|
759
|
-
* ...
|
|
760
|
-
* }
|
|
761
|
-
*
|
|
762
|
-
* core.t('key', ['test1', 'test2']); // 'some text test1 test2'
|
|
763
|
-
*/
|
|
764
|
-
initTranslation(translations) {
|
|
765
|
-
UserMessages_default.appendDictionary(translations);
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
var ApiObjectInitializer = class extends ApiInitializer {
|
|
769
|
-
constructor() {
|
|
770
|
-
super(...arguments);
|
|
771
|
-
__publicField(this, "jsWapiObject");
|
|
772
|
-
}
|
|
773
|
-
internalCreate(objectName) {
|
|
774
|
-
this._api.putJSWapiObject(objectName, (jsWapiObject) => {
|
|
775
|
-
this.jsWapiObject = jsWapiObject;
|
|
776
|
-
this._initOperations(objectName);
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
putOperation(operationName, objectName) {
|
|
780
|
-
this.jsWapiObject.putJSWapiOper(operationName, (jsWapiRequest, jsWapiResponse) => {
|
|
781
|
-
const request = new ApiRequest(jsWapiRequest, objectName);
|
|
782
|
-
return this._operations[operationName](
|
|
783
|
-
new ApiCore({ http: this.jsWapiObject, request }),
|
|
784
|
-
request,
|
|
785
|
-
new ApiResponse(jsWapiResponse, objectName)
|
|
786
|
-
);
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
|
|
791
|
-
// src/classes/EngineInitializer.ts
|
|
792
|
-
var EngineInitializer = class {
|
|
793
|
-
constructor(arg1, arg2) {
|
|
794
|
-
__publicField(this, "engine");
|
|
795
|
-
__publicField(this, "_operations");
|
|
796
|
-
let operations = arg1.operations || arg1;
|
|
797
|
-
let translations = arg1.translations || arg2?.translations;
|
|
798
|
-
const throwError = (msg) => {
|
|
799
|
-
throw new Error(msg);
|
|
800
|
-
};
|
|
801
|
-
if (!operations)
|
|
802
|
-
throwError('Property "operations" in the settings is required');
|
|
803
|
-
this._operations = operations;
|
|
804
|
-
this.internalCreate();
|
|
805
|
-
translations && this.initTranslation(translations);
|
|
806
|
-
}
|
|
807
|
-
internalCreate() {
|
|
808
|
-
jsWapi.setJSWapiEngine((engine) => {
|
|
809
|
-
this.engine = engine;
|
|
810
|
-
for (const operationName in this._operations) {
|
|
811
|
-
this.putOperation(operationName);
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
putOperation(operationName) {
|
|
816
|
-
this.engine.putJSWapiOper(operationName, (jsWapiRequest, jsWapiResponse) => {
|
|
817
|
-
const request = new ApiRequest(jsWapiRequest, this.engine.getName());
|
|
818
|
-
const apiCore = new ApiCore({ http: this.engine, request });
|
|
819
|
-
return this._operations[operationName](apiCore, request, new ApiResponse(jsWapiResponse, this.engine.getName()), {
|
|
820
|
-
parameters: this.engine.getExternalSystemParameters(),
|
|
821
|
-
objectName: this.engine.getName(),
|
|
822
|
-
externalObject: this.engine.getExternalName(),
|
|
823
|
-
externalFieldsMap: this.engine.getExternalObjectFields()
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Инициализация словаря переводов.
|
|
829
|
-
* @param translations
|
|
830
|
-
* @example Пример строки перевода
|
|
831
|
-
* { ...
|
|
832
|
-
* "ru": {"key": 'some text {0} {1}'}
|
|
833
|
-
* ...
|
|
834
|
-
* }
|
|
835
|
-
*
|
|
836
|
-
* core.t('key', ['test1', 'test2']); // 'some text test1 test2'
|
|
837
|
-
*/
|
|
838
|
-
initTranslation(translations) {
|
|
839
|
-
UserMessages_default.appendDictionary(translations);
|
|
840
|
-
}
|
|
841
|
-
call({
|
|
842
|
-
apiCore,
|
|
843
|
-
apiRequest,
|
|
844
|
-
apiResponse,
|
|
845
|
-
operation,
|
|
846
|
-
meta
|
|
847
|
-
}) {
|
|
848
|
-
return this._operations[operation](apiCore, apiRequest, apiResponse, meta);
|
|
849
|
-
}
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
// src/classes/ApplicationInitializer.ts
|
|
853
|
-
var ApplicationInitializer = class {
|
|
854
|
-
constructor(operations) {
|
|
855
|
-
__publicField(this, "jSWapiApplication");
|
|
856
|
-
__publicField(this, "_operations");
|
|
857
|
-
const throwError = (msg) => {
|
|
858
|
-
throw new Error(msg);
|
|
859
|
-
};
|
|
860
|
-
if (!operations)
|
|
861
|
-
throwError('Property "operations" in the settings is required');
|
|
862
|
-
this._operations = operations;
|
|
863
|
-
this.internalCreate();
|
|
864
|
-
}
|
|
865
|
-
internalCreate() {
|
|
866
|
-
jsWapi.setJSWapiObject((jSWapiApplication) => {
|
|
867
|
-
this.jSWapiApplication = jSWapiApplication;
|
|
868
|
-
for (const operationName in this._operations) {
|
|
869
|
-
this.putOperation(operationName);
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
putOperation(operationName) {
|
|
874
|
-
this.jSWapiApplication.putJSWapiOper(operationName, (jsWapiRequest, jsWapiResponse) => {
|
|
875
|
-
const request = new ApiRequest(jsWapiRequest, this.jSWapiApplication.getName());
|
|
876
|
-
return this._operations[operationName](
|
|
877
|
-
new ApiCore({ http: this.jSWapiApplication, request }),
|
|
878
|
-
request,
|
|
879
|
-
new ApiResponse(jsWapiResponse, this.jSWapiApplication.getName())
|
|
880
|
-
);
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
// src/classes/ApiJoinInvoker.ts
|
|
886
|
-
var ApiJoinInvoker = class {
|
|
887
|
-
constructor(jsWapiJoinInvoker) {
|
|
888
|
-
__publicField(this, "_jsWapiJoinInvoker");
|
|
889
|
-
this._jsWapiJoinInvoker = jsWapiJoinInvoker;
|
|
890
|
-
}
|
|
891
|
-
//TODO: implement methods.
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
// src/lib-index.ts
|
|
895
|
-
var lib_index_default = ApiObjectInitializer;
|
|
896
|
-
export {
|
|
897
|
-
ApiCore,
|
|
898
|
-
ApiHttpRequest,
|
|
899
|
-
ApiHttpResponse,
|
|
900
|
-
ApiInvoker,
|
|
901
|
-
ApiJoinInvoker,
|
|
902
|
-
ApiObjectCollectionIterator,
|
|
903
|
-
ApiRequest,
|
|
904
|
-
ApiResponse,
|
|
905
|
-
ApplicationInitializer,
|
|
906
|
-
EngineInitializer,
|
|
907
|
-
LanguageCode,
|
|
908
|
-
UserMessages_default as UserMessages,
|
|
909
|
-
lib_index_default as default
|
|
910
|
-
};
|