bx-rest 0.0.30 → 0.0.32

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.
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgModule, inject, Component, ViewEncapsulation, Inject, Injectable } from '@angular/core';
3
- import { map, catchError, tap, mergeMap as mergeMap$1, first } from 'rxjs/operators';
4
3
  import { Subscription, filter, take, of, throwError, forkJoin, mergeMap } from 'rxjs';
4
+ import { map, catchError, mergeMap as mergeMap$1, first } from 'rxjs/operators';
5
5
  import clone from 'just-clone';
6
6
  import * as i1$1 from '@angular/material/snack-bar';
7
7
  import { MatSnackBarRef, MAT_SNACK_BAR_DATA } from '@angular/material/snack-bar';
@@ -1092,12 +1092,6 @@ class HttpServices extends BaseHttpServices {
1092
1092
  mapBranchResultWithoutKey(res) {
1093
1093
  return flatten(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)));
1094
1094
  }
1095
- post(name, params = {}, textError = '', settings = this.defSettings) {
1096
- return this.httpPost(this.getNameMethod(name), params, textError, settings);
1097
- }
1098
- get(name, params = {}, textError = '', settings = this.defSettings) {
1099
- return this.httpGet(this.getNameMethod(name), params, textError, settings);
1100
- }
1101
1095
  httpPost(url, params = {}, textError = '', settings = this.defSettings) {
1102
1096
  return this.session.getAuthParams().pipe(mergeMap(auth => {
1103
1097
  if (auth) {
@@ -1166,6 +1160,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1166
1160
  }]
1167
1161
  }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: SnackBarService }, { type: SessionKeyServices }]; } });
1168
1162
 
1163
+ function mapResult(v) {
1164
+ if (v && (v.result || typeof v.result === 'boolean')) {
1165
+ return v.result;
1166
+ }
1167
+ return undefined;
1168
+ }
1169
+
1169
1170
  class HttpBXServices extends HttpServices {
1170
1171
  timeNowOnServer() {
1171
1172
  return this.httpGet('server.time').pipe(map(v => {
@@ -1213,11 +1214,27 @@ class HttpBXServices extends HttpServices {
1213
1214
  mapBranchResultWithoutKey(res) {
1214
1215
  return flatten(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)));
1215
1216
  }
1216
- post(name, params = {}, textError = '', settings = this.defSettings) {
1217
- return this.httpPost(this.getNameMethod(name), params, textError, settings);
1218
- }
1219
- get(name, params = {}, textError = '', settings = this.defSettings) {
1220
- return this.httpGet(this.getNameMethod(name), params, textError, settings);
1217
+ post(name, params = {}, textError = '', mapHttp = undefined, settings = this.defSettings) {
1218
+ return this.httpPost(this.getNameMethod(name), params, textError, settings).pipe(map(v => {
1219
+ if (v && v.result && REST_SETTINGS.support.map && mapHttp) {
1220
+ return Array.isArray(v.result)
1221
+ ? Object.assign(v, { result: v.result.map(i => mapHttp(i)) })
1222
+ : Object.assign(v, { result: mapHttp(v.result) });
1223
+ }
1224
+ return v;
1225
+ }), map(v => (v && REST_SETTINGS.support.result) ? mapResult : v));
1226
+ }
1227
+ get(name, params = {}, textError = '', mapHttp = (v) => {
1228
+ return v;
1229
+ }, settings = this.defSettings) {
1230
+ return this.httpGet(this.getNameMethod(name), params, textError, settings).pipe(map(v => {
1231
+ if (v && v.result && REST_SETTINGS.support.map) {
1232
+ return Array.isArray(v.result)
1233
+ ? Object.assign(v, { result: v.result.map(i => mapHttp(i)) })
1234
+ : Object.assign(v, { result: mapHttp(v.result) });
1235
+ }
1236
+ return v;
1237
+ }), map(v => (v && REST_SETTINGS.support.result) ? mapResult : v));
1221
1238
  }
1222
1239
  httpPost(url, params = {}, textError = '', settings = this.defSettings) {
1223
1240
  return this.session.getAuthParams().pipe(mergeMap(auth => {
@@ -1331,10 +1348,9 @@ class BXRestListsElement {
1331
1348
  };
1332
1349
  }
1333
1350
  get(pram) {
1334
- return this.http.post(this.url.get, pram)
1335
- .pipe(map(v => (v && v.result)
1336
- ? Object.assign(v, { result: v.result.map(i => this.mapResult.get(i)) })
1337
- : undefined));
1351
+ return this.http.post(this.url.get, pram, 'Не Удалось получить элемент списка', (v) => v.map(i => this.mapResult.get(i)));
1352
+ }
1353
+ customPipe() {
1338
1354
  }
1339
1355
  }
1340
1356
  BXRestListsElement.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestListsElement, deps: [{ token: HttpBXServices }, { token: BXRestListsElementMap }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -1367,13 +1383,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1367
1383
  }]
1368
1384
  }], ctorParameters: function () { return [{ type: BXRestListsElement }]; } });
1369
1385
 
1370
- function mapResult(v) {
1371
- if (v && (v.result || typeof v.result === 'boolean')) {
1372
- return v.result;
1373
- }
1374
- return undefined;
1375
- }
1376
-
1377
1386
  const save = createAction('[Users Component] Save', props());
1378
1387
  const saveArr = createAction('[Users Component] Save Arr', props());
1379
1388
  const update = createAction('[Users Component] Update', props());
@@ -1569,12 +1578,14 @@ class BXRestUser {
1569
1578
  get(params = {}) {
1570
1579
  let copyParams = clone(params);
1571
1580
  this.setDefParam(copyParams);
1572
- return this.http.post(this.url.get, copyParams, 'Не удалось получить пользователей')
1573
- .pipe(tap(v => {
1574
- if (v && v.result) {
1575
- this.saveArrUser(v.result);
1576
- }
1577
- }));
1581
+ return this.http.post(this.url.get, copyParams, 'Не удалось получить пользователей', (v) => { return v.map(i => this.userMap.HttpToBX(i)); });
1582
+ // .pipe(
1583
+ // tap(v => {
1584
+ // if (v && v.result) {
1585
+ // this.saveArrUser(v.result)
1586
+ // }
1587
+ // })
1588
+ // )
1578
1589
  }
1579
1590
  current(update = false) {
1580
1591
  if (update) {
@@ -1592,17 +1603,14 @@ class BXRestUser {
1592
1603
  }
1593
1604
  }
1594
1605
  getSelfHttp() {
1595
- return this.http.get(this.url.current, {}, 'Не удалось получить пользователя')
1596
- .pipe(map(v => {
1597
- if (v && v.result) {
1598
- return this.userMap.HttpToBX(v.result);
1599
- }
1600
- return undefined;
1601
- }), tap(v => {
1602
- if (v) {
1603
- this.store.dispatch(saveSelf({ self: v }));
1604
- }
1605
- }));
1606
+ return this.http.get(this.url.current, {}, 'Не удалось получить пользователя');
1607
+ // .pipe(
1608
+ // tap(v => {
1609
+ // if (v) {
1610
+ // this.store.dispatch(saveSelf({self: v}))
1611
+ // }
1612
+ // }),
1613
+ // )
1606
1614
  }
1607
1615
  access(access, textError = 'Не удалось получить права') {
1608
1616
  return this.http.get(this.url.access, { ACCESS: access }, textError);
@@ -1726,52 +1734,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1726
1734
  }]
1727
1735
  }], ctorParameters: function () { return [{ type: HttpBXServices }, { type: SnackBarService }, { type: i1$2.Store }, { type: BitrixApiUserMapServices }]; } });
1728
1736
 
1729
- // import { Observable } from 'rxjs'
1730
- // import BXRestListsElementMap from './map/lists/element'
1731
- // import { map } from 'rxjs/operators'
1732
- // import { mapResult } from './functions/mapResult'
1733
- class BXRestBase {
1737
+ class BXRest {
1734
1738
  constructor(user, lists) {
1735
1739
  this.user = user;
1736
1740
  this.lists = lists;
1737
1741
  }
1738
1742
  }
1739
- BXRestBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestBase, deps: [{ token: BXRestUser }, { token: BXRestLists }], target: i0.ɵɵFactoryTarget.Injectable });
1740
- BXRestBase.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestBase, providedIn: 'root' });
1741
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestBase, decorators: [{
1742
- type: Injectable,
1743
- args: [{
1744
- providedIn: 'root'
1745
- }]
1746
- }], ctorParameters: function () { return [{ type: BXRestUser }, { type: BXRestLists }]; } });
1747
- class BXRest extends new Proxy(BXRestBase, {
1748
- get(target, prop, receiver) {
1749
- const res = Reflect.get(target, prop, receiver);
1750
- console.log('res', res);
1751
- if (typeof res === 'function') {
1752
- // let mapRes = new BXRestListsElementMap()
1753
- console.log('res', res);
1754
- return Reflect.get(target, prop, receiver).pipe(
1755
- // @ts-ignore
1756
- map(v => (v && v.result)
1757
- // @ts-ignore
1758
- ? Object.assign(v, { result: v.result.map(i => mapRes.get(i)) })
1759
- : undefined),
1760
- // @ts-ignore
1761
- map(v => mapResult(v)));
1762
- }
1763
- return res;
1764
- }
1765
- }) {
1766
- }
1767
- BXRest.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1743
+ BXRest.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, deps: [{ token: BXRestUser }, { token: BXRestLists }], target: i0.ɵɵFactoryTarget.Injectable });
1768
1744
  BXRest.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, providedIn: 'root' });
1769
1745
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, decorators: [{
1770
1746
  type: Injectable,
1771
1747
  args: [{
1772
1748
  providedIn: 'root'
1773
1749
  }]
1774
- }] });
1750
+ }], ctorParameters: function () { return [{ type: BXRestUser }, { type: BXRestLists }]; } });
1775
1751
 
1776
1752
  /*
1777
1753
  * Public API Surface of bx-rest