d5-api-initializer 1.1.1 → 1.1.3-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d5-api-initializer",
3
- "version": "1.1.1",
3
+ "version": "1.1.3-alpha.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {},
6
6
  "main": "publish/cjs/d5-api-initializer",
@@ -27,7 +27,8 @@
27
27
  "compile": "tsup",
28
28
  "changelog": "node ./scripts/releaseChangelog.mjs changelog -p v1.0.0",
29
29
  "prepublishOnly": "yarn clean",
30
- "prepack": "yarn compile"
30
+ "prepack": "yarn compile",
31
+ "prerelease": "npm version prerelease --preid=alpha"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@babel/core": "7.23.9",
@@ -130,6 +130,9 @@ var ApiResponse = class {
130
130
  getResponse(responseName) {
131
131
  return this._jsWapiResponse.getResponse(responseName || this._objectName);
132
132
  }
133
+ getResponseObject() {
134
+ return this._jsWapiResponse.getResponse();
135
+ }
133
136
  setResponse(response, fieldsMap) {
134
137
  if (Array.isArray(response)) {
135
138
  const data = !fieldsMap ? response : response.map((row) => {
@@ -367,6 +370,7 @@ var UserMessages_default = new UserMessages();
367
370
  var ApiObjectCollectionIterator = class {
368
371
  constructor({ invoker }) {
369
372
  __publicField(this, "_invoker");
373
+ __publicField(this, "_rowsPerPage", 100);
370
374
  this._invoker = invoker;
371
375
  }
372
376
  get objectName() {
@@ -394,22 +398,25 @@ var ApiObjectCollectionIterator = class {
394
398
  this._invoker.addColumns(columns);
395
399
  return this;
396
400
  }
401
+ setRowsPerPage(amount) {
402
+ this._rowsPerPage = amount;
403
+ this._invoker.setRowsPerPage(amount);
404
+ return this;
405
+ }
397
406
  /* ------------------------------Other------------------------------ */
398
407
  *invoke() {
399
408
  let data = null, pageCount = 1;
400
409
  let lastPage = false;
401
- const rowsPerPage = 100;
402
410
  while (!lastPage) {
403
411
  this._invoker.page = pageCount;
404
- this._invoker.rowsPerPage = rowsPerPage;
405
- data = new ApiResponse(this._invoker.invoke(), this.objectName).getResponse();
412
+ data = this._invoker.invoke().getResponse();
406
413
  pageCount++;
407
414
  if (Array.isArray(data)) {
408
415
  for (let i = 0; i < data.length; i++) {
409
416
  yield data[i];
410
417
  }
411
418
  }
412
- lastPage = data.length < rowsPerPage;
419
+ lastPage = data.length < this._rowsPerPage;
413
420
  }
414
421
  }
415
422
  };
@@ -487,6 +494,15 @@ var ApiCore = class {
487
494
  }
488
495
  return new JSWapiException(message);
489
496
  }
497
+ /**
498
+ * Валидирует xml по переданому xsd.
499
+ * Если валидация происходит с ошибками, то бросается исключение.
500
+ */
501
+ validateXml(xml, xsd) {
502
+ if (!this.httpSender.validateXml)
503
+ throw this.newApiException("validateXml() is not allowed");
504
+ return this.httpSender.validateXml(xsd, xml);
505
+ }
490
506
  /*
491
507
  * Will be implemented later
492
508
  *
@@ -63,7 +63,21 @@ declare namespace jsWapi {
63
63
  setRequest(request: any): JSWapiRequest;
64
64
  setHierarchy(parentColumn: string, requestKind?: number): JSWapiRequest;
65
65
  };
66
- type JSWapiResponse = {};
66
+ type JSWapiResponse = {
67
+ getResponse(): {
68
+ [key: string]: Record<string, any>[];
69
+ };
70
+ getResponse(objectName: string): Record<string, any>[] | null;
71
+ putResponse(objectName: string, records: Record<string, any>[]): void;
72
+ setResponse(resp: {
73
+ [key: string]: Record<string, any>[];
74
+ }): void;
75
+ sendHttpResponse(headers: Record<string, any>, body: string | BinaryDataStream): void;
76
+ getPagesPredict(): number;
77
+ setPagesPredict(pagesPredict: number): void;
78
+ getPage(): number;
79
+ setPage(page: number): void;
80
+ };
67
81
  type BinaryDataStream = unknown;
68
82
  interface JSWapiHttpResponse {
69
83
  getStatusCode(): number;
@@ -138,10 +152,11 @@ declare class ApiHttpRequest {
138
152
  declare class ApiResponse {
139
153
  private _jsWapiResponse;
140
154
  private readonly _objectName;
141
- constructor(jsWapiResponse: any, objectName: string);
155
+ constructor(jsWapiResponse: jsWapi.JSWapiResponse, objectName: string);
142
156
  get objectName(): string;
143
157
  set response(response: IMappedCollection | any[]);
144
158
  getResponse(responseName?: string): IMappedCollection[] | any;
159
+ getResponseObject(): IMappedCollection[] | any;
145
160
  setResponse(response: IMappedCollection | any[], fieldsMap?: Record<string, any>): this;
146
161
  sendHttpResponse(headers: IMappedCollection, body: string | jsWapi.BinaryDataStream): this;
147
162
  sendHttpBody(body: string): this;
@@ -157,6 +172,7 @@ interface IInvoker$1<T> {
157
172
  setSorts(sorts: string[]): T;
158
173
  addColumns(columns: string[]): T;
159
174
  addSorts(sorts: string[]): T;
175
+ setRowsPerPage(amount: number): T;
160
176
  objectName: string;
161
177
  }
162
178
  declare class ApiInvoker implements IInvoker$1<ApiInvoker> {
@@ -302,6 +318,7 @@ declare class ApiRequest {
302
318
 
303
319
  declare class ApiObjectCollectionIterator implements IInvoker$1<ApiObjectCollectionIterator> {
304
320
  private _invoker;
321
+ private _rowsPerPage;
305
322
  constructor({ invoker }: {
306
323
  invoker: ApiInvoker;
307
324
  });
@@ -311,6 +328,7 @@ declare class ApiObjectCollectionIterator implements IInvoker$1<ApiObjectCollect
311
328
  setSorts(sorts: string[]): ApiObjectCollectionIterator;
312
329
  addSorts(sorts: string[]): ApiObjectCollectionIterator;
313
330
  addColumns(columns: string[]): ApiObjectCollectionIterator;
331
+ setRowsPerPage(amount: number): ApiObjectCollectionIterator;
314
332
  invoke(): Generator<ApiResponse>;
315
333
  }
316
334
 
@@ -336,6 +354,8 @@ declare class ApiFileInvoker implements IInvoker {
336
354
 
337
355
  type HTTPSender = {
338
356
  newJSWapiHttp(url: string): jsWapi.JSWapiHttp;
357
+ /** Если не валидируется, то будет exception. */
358
+ validateXml?(xsd: string, xml: string): boolean;
339
359
  };
340
360
  declare class ApiCore {
341
361
  private readonly httpSender;
@@ -363,6 +383,11 @@ declare class ApiCore {
363
383
  newApiFileInvoker(objectName: string, keyValue: string | number, fileFieldName: string): ApiFileInvoker;
364
384
  newApiObjectCollectionIterator(objectName: string): ApiObjectCollectionIterator;
365
385
  newApiException(message: string, code?: string | number): Error;
386
+ /**
387
+ * Валидирует xml по переданому xsd.
388
+ * Если валидация происходит с ошибками, то бросается исключение.
389
+ */
390
+ validateXml(xml: string, xsd: string): boolean;
366
391
  }
367
392
 
368
393
  interface IFilterValue {
@@ -94,6 +94,9 @@ var ApiResponse = class {
94
94
  getResponse(responseName) {
95
95
  return this._jsWapiResponse.getResponse(responseName || this._objectName);
96
96
  }
97
+ getResponseObject() {
98
+ return this._jsWapiResponse.getResponse();
99
+ }
97
100
  setResponse(response, fieldsMap) {
98
101
  if (Array.isArray(response)) {
99
102
  const data = !fieldsMap ? response : response.map((row) => {
@@ -331,6 +334,7 @@ var UserMessages_default = new UserMessages();
331
334
  var ApiObjectCollectionIterator = class {
332
335
  constructor({ invoker }) {
333
336
  __publicField(this, "_invoker");
337
+ __publicField(this, "_rowsPerPage", 100);
334
338
  this._invoker = invoker;
335
339
  }
336
340
  get objectName() {
@@ -358,22 +362,25 @@ var ApiObjectCollectionIterator = class {
358
362
  this._invoker.addColumns(columns);
359
363
  return this;
360
364
  }
365
+ setRowsPerPage(amount) {
366
+ this._rowsPerPage = amount;
367
+ this._invoker.setRowsPerPage(amount);
368
+ return this;
369
+ }
361
370
  /* ------------------------------Other------------------------------ */
362
371
  *invoke() {
363
372
  let data = null, pageCount = 1;
364
373
  let lastPage = false;
365
- const rowsPerPage = 100;
366
374
  while (!lastPage) {
367
375
  this._invoker.page = pageCount;
368
- this._invoker.rowsPerPage = rowsPerPage;
369
- data = new ApiResponse(this._invoker.invoke(), this.objectName).getResponse();
376
+ data = this._invoker.invoke().getResponse();
370
377
  pageCount++;
371
378
  if (Array.isArray(data)) {
372
379
  for (let i = 0; i < data.length; i++) {
373
380
  yield data[i];
374
381
  }
375
382
  }
376
- lastPage = data.length < rowsPerPage;
383
+ lastPage = data.length < this._rowsPerPage;
377
384
  }
378
385
  }
379
386
  };
@@ -451,6 +458,15 @@ var ApiCore = class {
451
458
  }
452
459
  return new JSWapiException(message);
453
460
  }
461
+ /**
462
+ * Валидирует xml по переданому xsd.
463
+ * Если валидация происходит с ошибками, то бросается исключение.
464
+ */
465
+ validateXml(xml, xsd) {
466
+ if (!this.httpSender.validateXml)
467
+ throw this.newApiException("validateXml() is not allowed");
468
+ return this.httpSender.validateXml(xsd, xml);
469
+ }
454
470
  /*
455
471
  * Will be implemented later
456
472
  *
@@ -94,6 +94,9 @@ var ApiResponse = class {
94
94
  getResponse(responseName) {
95
95
  return this._jsWapiResponse.getResponse(responseName || this._objectName);
96
96
  }
97
+ getResponseObject() {
98
+ return this._jsWapiResponse.getResponse();
99
+ }
97
100
  setResponse(response, fieldsMap) {
98
101
  if (Array.isArray(response)) {
99
102
  const data = !fieldsMap ? response : response.map((row) => {
@@ -331,6 +334,7 @@ var UserMessages_default = new UserMessages();
331
334
  var ApiObjectCollectionIterator = class {
332
335
  constructor({ invoker }) {
333
336
  __publicField(this, "_invoker");
337
+ __publicField(this, "_rowsPerPage", 100);
334
338
  this._invoker = invoker;
335
339
  }
336
340
  get objectName() {
@@ -358,22 +362,25 @@ var ApiObjectCollectionIterator = class {
358
362
  this._invoker.addColumns(columns);
359
363
  return this;
360
364
  }
365
+ setRowsPerPage(amount) {
366
+ this._rowsPerPage = amount;
367
+ this._invoker.setRowsPerPage(amount);
368
+ return this;
369
+ }
361
370
  /* ------------------------------Other------------------------------ */
362
371
  *invoke() {
363
372
  let data = null, pageCount = 1;
364
373
  let lastPage = false;
365
- const rowsPerPage = 100;
366
374
  while (!lastPage) {
367
375
  this._invoker.page = pageCount;
368
- this._invoker.rowsPerPage = rowsPerPage;
369
- data = new ApiResponse(this._invoker.invoke(), this.objectName).getResponse();
376
+ data = this._invoker.invoke().getResponse();
370
377
  pageCount++;
371
378
  if (Array.isArray(data)) {
372
379
  for (let i = 0; i < data.length; i++) {
373
380
  yield data[i];
374
381
  }
375
382
  }
376
- lastPage = data.length < rowsPerPage;
383
+ lastPage = data.length < this._rowsPerPage;
377
384
  }
378
385
  }
379
386
  };
@@ -451,6 +458,15 @@ var ApiCore = class {
451
458
  }
452
459
  return new JSWapiException(message);
453
460
  }
461
+ /**
462
+ * Валидирует xml по переданому xsd.
463
+ * Если валидация происходит с ошибками, то бросается исключение.
464
+ */
465
+ validateXml(xml, xsd) {
466
+ if (!this.httpSender.validateXml)
467
+ throw this.newApiException("validateXml() is not allowed");
468
+ return this.httpSender.validateXml(xsd, xml);
469
+ }
454
470
  /*
455
471
  * Will be implemented later
456
472
  *