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';
@@ -1087,12 +1087,6 @@ class HttpServices extends BaseHttpServices {
1087
1087
  mapBranchResultWithoutKey(res) {
1088
1088
  return flatten(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)));
1089
1089
  }
1090
- post(name, params = {}, textError = '', settings = this.defSettings) {
1091
- return this.httpPost(this.getNameMethod(name), params, textError, settings);
1092
- }
1093
- get(name, params = {}, textError = '', settings = this.defSettings) {
1094
- return this.httpGet(this.getNameMethod(name), params, textError, settings);
1095
- }
1096
1090
  httpPost(url, params = {}, textError = '', settings = this.defSettings) {
1097
1091
  return this.session.getAuthParams().pipe(mergeMap(auth => {
1098
1092
  if (auth) {
@@ -1161,6 +1155,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1161
1155
  }]
1162
1156
  }], ctorParameters: function () { return [{ type: i1$3.HttpClient }, { type: SnackBarService }, { type: SessionKeyServices }]; } });
1163
1157
 
1158
+ function mapResult(v) {
1159
+ if (v && (v.result || typeof v.result === 'boolean')) {
1160
+ return v.result;
1161
+ }
1162
+ return undefined;
1163
+ }
1164
+
1164
1165
  class HttpBXServices extends HttpServices {
1165
1166
  timeNowOnServer() {
1166
1167
  return this.httpGet('server.time').pipe(map(v => {
@@ -1208,11 +1209,27 @@ class HttpBXServices extends HttpServices {
1208
1209
  mapBranchResultWithoutKey(res) {
1209
1210
  return flatten(Object.assign([], ...res.map(i => (i.result && i.result.result) ? i.result.result : undefined)));
1210
1211
  }
1211
- post(name, params = {}, textError = '', settings = this.defSettings) {
1212
- return this.httpPost(this.getNameMethod(name), params, textError, settings);
1213
- }
1214
- get(name, params = {}, textError = '', settings = this.defSettings) {
1215
- return this.httpGet(this.getNameMethod(name), params, textError, settings);
1212
+ post(name, params = {}, textError = '', mapHttp = undefined, settings = this.defSettings) {
1213
+ return this.httpPost(this.getNameMethod(name), params, textError, settings).pipe(map(v => {
1214
+ if (v && v.result && REST_SETTINGS.support.map && mapHttp) {
1215
+ return Array.isArray(v.result)
1216
+ ? Object.assign(v, { result: v.result.map(i => mapHttp(i)) })
1217
+ : Object.assign(v, { result: mapHttp(v.result) });
1218
+ }
1219
+ return v;
1220
+ }), map(v => (v && REST_SETTINGS.support.result) ? mapResult : v));
1221
+ }
1222
+ get(name, params = {}, textError = '', mapHttp = (v) => {
1223
+ return v;
1224
+ }, settings = this.defSettings) {
1225
+ return this.httpGet(this.getNameMethod(name), params, textError, settings).pipe(map(v => {
1226
+ if (v && v.result && REST_SETTINGS.support.map) {
1227
+ return Array.isArray(v.result)
1228
+ ? Object.assign(v, { result: v.result.map(i => mapHttp(i)) })
1229
+ : Object.assign(v, { result: mapHttp(v.result) });
1230
+ }
1231
+ return v;
1232
+ }), map(v => (v && REST_SETTINGS.support.result) ? mapResult : v));
1216
1233
  }
1217
1234
  httpPost(url, params = {}, textError = '', settings = this.defSettings) {
1218
1235
  return this.session.getAuthParams().pipe(mergeMap(auth => {
@@ -1326,10 +1343,9 @@ class BXRestListsElement {
1326
1343
  };
1327
1344
  }
1328
1345
  get(pram) {
1329
- return this.http.post(this.url.get, pram)
1330
- .pipe(map(v => (v && v.result)
1331
- ? Object.assign(v, { result: v.result.map(i => this.mapResult.get(i)) })
1332
- : undefined));
1346
+ return this.http.post(this.url.get, pram, 'Не Удалось получить элемент списка', (v) => v.map(i => this.mapResult.get(i)));
1347
+ }
1348
+ customPipe() {
1333
1349
  }
1334
1350
  }
1335
1351
  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 });
@@ -1362,13 +1378,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1362
1378
  }]
1363
1379
  }], ctorParameters: function () { return [{ type: BXRestListsElement }]; } });
1364
1380
 
1365
- function mapResult(v) {
1366
- if (v && (v.result || typeof v.result === 'boolean')) {
1367
- return v.result;
1368
- }
1369
- return undefined;
1370
- }
1371
-
1372
1381
  const save = createAction('[Users Component] Save', props());
1373
1382
  const saveArr = createAction('[Users Component] Save Arr', props());
1374
1383
  const update = createAction('[Users Component] Update', props());
@@ -1564,12 +1573,14 @@ class BXRestUser {
1564
1573
  get(params = {}) {
1565
1574
  let copyParams = clone(params);
1566
1575
  this.setDefParam(copyParams);
1567
- return this.http.post(this.url.get, copyParams, 'Не удалось получить пользователей')
1568
- .pipe(tap(v => {
1569
- if (v && v.result) {
1570
- this.saveArrUser(v.result);
1571
- }
1572
- }));
1576
+ return this.http.post(this.url.get, copyParams, 'Не удалось получить пользователей', (v) => { return v.map(i => this.userMap.HttpToBX(i)); });
1577
+ // .pipe(
1578
+ // tap(v => {
1579
+ // if (v && v.result) {
1580
+ // this.saveArrUser(v.result)
1581
+ // }
1582
+ // })
1583
+ // )
1573
1584
  }
1574
1585
  current(update = false) {
1575
1586
  if (update) {
@@ -1587,17 +1598,14 @@ class BXRestUser {
1587
1598
  }
1588
1599
  }
1589
1600
  getSelfHttp() {
1590
- return this.http.get(this.url.current, {}, 'Не удалось получить пользователя')
1591
- .pipe(map(v => {
1592
- if (v && v.result) {
1593
- return this.userMap.HttpToBX(v.result);
1594
- }
1595
- return undefined;
1596
- }), tap(v => {
1597
- if (v) {
1598
- this.store.dispatch(saveSelf({ self: v }));
1599
- }
1600
- }));
1601
+ return this.http.get(this.url.current, {}, 'Не удалось получить пользователя');
1602
+ // .pipe(
1603
+ // tap(v => {
1604
+ // if (v) {
1605
+ // this.store.dispatch(saveSelf({self: v}))
1606
+ // }
1607
+ // }),
1608
+ // )
1601
1609
  }
1602
1610
  access(access, textError = 'Не удалось получить права') {
1603
1611
  return this.http.get(this.url.access, { ACCESS: access }, textError);
@@ -1721,52 +1729,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1721
1729
  }]
1722
1730
  }], ctorParameters: function () { return [{ type: HttpBXServices }, { type: SnackBarService }, { type: i1$2.Store }, { type: BitrixApiUserMapServices }]; } });
1723
1731
 
1724
- // import { Observable } from 'rxjs'
1725
- // import BXRestListsElementMap from './map/lists/element'
1726
- // import { map } from 'rxjs/operators'
1727
- // import { mapResult } from './functions/mapResult'
1728
- class BXRestBase {
1732
+ class BXRest {
1729
1733
  constructor(user, lists) {
1730
1734
  this.user = user;
1731
1735
  this.lists = lists;
1732
1736
  }
1733
1737
  }
1734
- 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 });
1735
- BXRestBase.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestBase, providedIn: 'root' });
1736
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRestBase, decorators: [{
1737
- type: Injectable,
1738
- args: [{
1739
- providedIn: 'root'
1740
- }]
1741
- }], ctorParameters: function () { return [{ type: BXRestUser }, { type: BXRestLists }]; } });
1742
- class BXRest extends new Proxy(BXRestBase, {
1743
- get(target, prop, receiver) {
1744
- const res = Reflect.get(target, prop, receiver);
1745
- console.log('res', res);
1746
- if (typeof res === 'function') {
1747
- // let mapRes = new BXRestListsElementMap()
1748
- console.log('res', res);
1749
- return Reflect.get(target, prop, receiver).pipe(
1750
- // @ts-ignore
1751
- map(v => (v && v.result)
1752
- // @ts-ignore
1753
- ? Object.assign(v, { result: v.result.map(i => mapRes.get(i)) })
1754
- : undefined),
1755
- // @ts-ignore
1756
- map(v => mapResult(v)));
1757
- }
1758
- return res;
1759
- }
1760
- }) {
1761
- }
1762
- BXRest.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1738
+ 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 });
1763
1739
  BXRest.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, providedIn: 'root' });
1764
1740
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: BXRest, decorators: [{
1765
1741
  type: Injectable,
1766
1742
  args: [{
1767
1743
  providedIn: 'root'
1768
1744
  }]
1769
- }] });
1745
+ }], ctorParameters: function () { return [{ type: BXRestUser }, { type: BXRestLists }]; } });
1770
1746
 
1771
1747
  /*
1772
1748
  * Public API Surface of bx-rest