ng2-rest 19.0.3 → 19.0.5

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.
Files changed (92) hide show
  1. package/README.md +135 -135
  2. package/browser/README.md +24 -24
  3. package/browser/fesm2022/ng2-rest.mjs +156 -26
  4. package/browser/fesm2022/ng2-rest.mjs.map +1 -1
  5. package/browser/package.json +1 -1
  6. package/client/README.md +24 -24
  7. package/client/fesm2022/ng2-rest.mjs +156 -26
  8. package/client/fesm2022/ng2-rest.mjs.map +1 -1
  9. package/client/package.json +1 -1
  10. package/index.js.map +1 -1
  11. package/lib/build-info._auto-generated_.d.ts +2 -1
  12. package/lib/build-info._auto-generated_.js +3 -2
  13. package/lib/build-info._auto-generated_.js.map +1 -1
  14. package/lib/content-type.js.map +1 -1
  15. package/lib/cookie.js.map +1 -1
  16. package/lib/helpers.d.ts +1 -1
  17. package/lib/helpers.js +4 -4
  18. package/lib/helpers.js.map +1 -1
  19. package/lib/index._auto-generated_.js.map +1 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib/mapping.d.ts +1 -1
  22. package/lib/mapping.js +60 -60
  23. package/lib/mapping.js.map +1 -1
  24. package/lib/models.d.ts +1 -1
  25. package/lib/models.js +15 -15
  26. package/lib/models.js.map +1 -1
  27. package/lib/other/simple-resource.js.map +1 -1
  28. package/lib/params.js +6 -6
  29. package/lib/params.js.map +1 -1
  30. package/lib/request-cache.js +4 -4
  31. package/lib/request-cache.js.map +1 -1
  32. package/lib/resource-service.d.ts +1 -1
  33. package/lib/resource-service.js +4 -4
  34. package/lib/resource-service.js.map +1 -1
  35. package/lib/rest-headers.js.map +1 -1
  36. package/lib/rest-request.js +12 -12
  37. package/lib/rest-request.js.map +1 -1
  38. package/lib/rest.class.js +2 -2
  39. package/lib/rest.class.js.map +1 -1
  40. package/migrations/index.js.map +1 -1
  41. package/migrations/migrations_index._auto-generated_.js.map +1 -1
  42. package/package.json +1 -1
  43. package/tmp-environment.json +4 -4
  44. package/websql/README.md +24 -24
  45. package/websql/fesm2022/ng2-rest.mjs +156 -26
  46. package/websql/fesm2022/ng2-rest.mjs.map +1 -1
  47. package/websql/package.json +1 -1
  48. package/browser/esm2022/lib/content-type.mjs +0 -13
  49. package/browser/esm2022/lib/cookie.mjs +0 -29
  50. package/browser/esm2022/lib/helpers.mjs +0 -24
  51. package/browser/esm2022/lib/index.mjs +0 -13
  52. package/browser/esm2022/lib/mapping.mjs +0 -250
  53. package/browser/esm2022/lib/models.mjs +0 -172
  54. package/browser/esm2022/lib/other/simple-resource.mjs +0 -118
  55. package/browser/esm2022/lib/params.mjs +0 -279
  56. package/browser/esm2022/lib/request-cache.mjs +0 -101
  57. package/browser/esm2022/lib/resource-service.mjs +0 -220
  58. package/browser/esm2022/lib/rest-headers.mjs +0 -129
  59. package/browser/esm2022/lib/rest-request.mjs +0 -325
  60. package/browser/esm2022/lib/rest.class.mjs +0 -120
  61. package/browser/esm2022/ng2-rest.mjs +0 -5
  62. package/browser/esm2022/public-api.mjs +0 -2
  63. package/client/esm2022/lib/content-type.mjs +0 -13
  64. package/client/esm2022/lib/cookie.mjs +0 -29
  65. package/client/esm2022/lib/helpers.mjs +0 -24
  66. package/client/esm2022/lib/index.mjs +0 -13
  67. package/client/esm2022/lib/mapping.mjs +0 -250
  68. package/client/esm2022/lib/models.mjs +0 -172
  69. package/client/esm2022/lib/other/simple-resource.mjs +0 -118
  70. package/client/esm2022/lib/params.mjs +0 -279
  71. package/client/esm2022/lib/request-cache.mjs +0 -101
  72. package/client/esm2022/lib/resource-service.mjs +0 -220
  73. package/client/esm2022/lib/rest-headers.mjs +0 -129
  74. package/client/esm2022/lib/rest-request.mjs +0 -325
  75. package/client/esm2022/lib/rest.class.mjs +0 -120
  76. package/client/esm2022/ng2-rest.mjs +0 -5
  77. package/client/esm2022/public-api.mjs +0 -2
  78. package/websql/esm2022/lib/content-type.mjs +0 -13
  79. package/websql/esm2022/lib/cookie.mjs +0 -29
  80. package/websql/esm2022/lib/helpers.mjs +0 -24
  81. package/websql/esm2022/lib/index.mjs +0 -13
  82. package/websql/esm2022/lib/mapping.mjs +0 -250
  83. package/websql/esm2022/lib/models.mjs +0 -172
  84. package/websql/esm2022/lib/other/simple-resource.mjs +0 -118
  85. package/websql/esm2022/lib/params.mjs +0 -279
  86. package/websql/esm2022/lib/request-cache.mjs +0 -101
  87. package/websql/esm2022/lib/resource-service.mjs +0 -220
  88. package/websql/esm2022/lib/rest-headers.mjs +0 -129
  89. package/websql/esm2022/lib/rest-request.mjs +0 -325
  90. package/websql/esm2022/lib/rest.class.mjs +0 -120
  91. package/websql/esm2022/ng2-rest.mjs +0 -5
  92. package/websql/esm2022/public-api.mjs +0 -2
@@ -10,6 +10,7 @@ import axios from 'axios';
10
10
  var Mapping;
11
11
  (function (Mapping) {
12
12
  function decode(json, autodetect = false) {
13
+ // console.log('DECODE isBrowser', HelpersLog.isBrowser)
13
14
  if (_.isUndefined(json)) {
14
15
  return void 0;
15
16
  }
@@ -48,6 +49,7 @@ var Mapping;
48
49
  return {};
49
50
  }
50
51
  const className = CLASS.getName(entity);
52
+ // console.log(`getMaping for: '${className}' `)
51
53
  let enityOWnMapping = _.isArray(entity[SYMBOL.MODELS_MAPPING]) ?
52
54
  entity[SYMBOL.MODELS_MAPPING] : [{ '': className }];
53
55
  let res = {};
@@ -56,6 +58,7 @@ var Mapping;
56
58
  .map(m => m['']);
57
59
  enityOWnMapping.reverse().forEach(m => {
58
60
  m = _.cloneDeep(m);
61
+ // console.log(`'${className}' m:`, m)
59
62
  Object.keys(m).forEach(key => {
60
63
  const v = m[key];
61
64
  const isArr = _.isArray(v);
@@ -67,6 +70,7 @@ var Mapping;
67
70
  res = _.merge(res, m);
68
71
  });
69
72
  res[''] = className;
73
+ // console.log(`mapping for ${className} : ${JSON.stringify(res)}`)
70
74
  return res;
71
75
  }
72
76
  Mapping.getModelsMapping = getModelsMapping;
@@ -107,6 +111,7 @@ var Mapping;
107
111
  const v = c[p];
108
112
  if (Array.isArray(v) && v.length > 0) { // reducer as impovement
109
113
  v.forEach((elem, i) => {
114
+ // const currentPaht = [`path[${i}]`, p].filter(c => c.trim() != '').join('.');
110
115
  const currentPaht = [path, p].filter(c => c.trim() != '').join('.');
111
116
  getMappingNaive(elem, currentPaht, mapping, level);
112
117
  });
@@ -135,6 +140,7 @@ var Mapping;
135
140
  }
136
141
  function setMappingCirc(json, mapping = {}, circular = []) {
137
142
  const mainClassFn = !_.isArray(json) && CLASS.getBy(mapping['']);
143
+ // console.log(mapping)
138
144
  walk.Object(json, (v, lodashPath, changeValue) => {
139
145
  if (!_.isUndefined(v) && !_.isNull(v)) {
140
146
  const mappingPath = getMappingPathFrom(lodashPath);
@@ -144,6 +150,7 @@ var Mapping;
144
150
  const className = isArray ? _.first(mapping[mappingPath]) : mapping[mappingPath];
145
151
  const classFN = CLASS.getBy(className);
146
152
  if (_.isFunction(classFN)) {
153
+ // console.log(`mapping: '${mappingPath}', lp: '${lodashPath}' class: '${className}' , set `, v.location)
147
154
  changeValue(_.merge(new classFN(), v));
148
155
  }
149
156
  }
@@ -160,6 +167,7 @@ var Mapping;
160
167
  return json;
161
168
  }
162
169
  function setMapping(json, mapping = {}) {
170
+ // console.log('mapping', mapping)
163
171
  if (Array.isArray(json)) {
164
172
  return json.map(j => {
165
173
  return setMapping(j, mapping);
@@ -168,6 +176,9 @@ var Mapping;
168
176
  const mainClassFn = CLASS.getBy(mapping['']);
169
177
  for (const key in json) {
170
178
  if (json.hasOwnProperty(key)) {
179
+ // if (mainClassFn && mainClassFn.name === 'Project') {
180
+ // // console.log(`OWn property: "${key}"`)
181
+ // }
171
182
  if (_.isArray(json[key])) {
172
183
  json[key] = json[key].map(arrObj => {
173
184
  const objMapping = getModelsMapping(CLASS.getBy(mapping[key]));
@@ -179,11 +190,17 @@ var Mapping;
179
190
  json[key] = setMapping(json[key], objMapping);
180
191
  }
181
192
  }
193
+ // else {
194
+ // if (mainClassFn && mainClassFn.name === 'Project') {
195
+ // // console.log(`Not own property: "${key}"`)
196
+ // }
197
+ // }
182
198
  }
183
199
  Object
184
200
  .keys(mapping)
185
201
  .filter(key => key !== '' && key.split('.').length >= 2)
186
202
  .forEach(lodasPath => {
203
+ // console.log(`Loadsh path: ${lodasPath}`)
187
204
  const objMapping = getModelsMapping(CLASS.getBy(mapping[lodasPath]));
188
205
  const input = _.get(json, lodasPath);
189
206
  if (!_.isUndefined(input)) {
@@ -222,6 +239,7 @@ var Mapping;
222
239
  const describedTarget = CLASS
223
240
  .describeProperites(target)
224
241
  .filter(prop => /^([a-zA-Z0-9]|\_|\#)+$/.test(prop));
242
+ // console.log(`describedTarget: ${describedTarget} for ${target.name}`)
225
243
  describedTarget.forEach(propDefInConstr => {
226
244
  if (defaultModelValues[propDefInConstr]) {
227
245
  console.warn(`
@@ -236,6 +254,7 @@ var Mapping;
236
254
  toMerge[propDefInConstr] = null; // TODO from toString I can't know that
237
255
  }
238
256
  });
257
+ // console.log(`merge "${JSON.stringify(target.prototype)}" with "${JSON.stringify(defaultModelValues)}"`)
239
258
  target[SYMBOL.DEFAULT_MODEL] = _.merge(toMerge, defaultModelValues);
240
259
  const propsToOmmit = Object
241
260
  .keys(target[SYMBOL.DEFAULT_MODEL])
@@ -245,13 +264,12 @@ var Mapping;
245
264
  return !!descriptor;
246
265
  });
247
266
  _.merge(target.prototype, _.omit(target[SYMBOL.DEFAULT_MODEL], propsToOmmit));
267
+ // console.log(`DEFAULT VALUE MERGE for ${target.name}`)
248
268
  }
249
269
  };
250
270
  }
251
271
  Mapping.DefaultModelWithMapping = DefaultModelWithMapping;
252
272
  })(Mapping || (Mapping = {}));
253
- ;
254
- ({}); // @--end-of-file-for-module=ng2-rest lib/mapping.ts
255
273
 
256
274
  // @ts-ignore
257
275
  class Helpers extends CoreHelpers {
@@ -271,8 +289,6 @@ class Helpers extends CoreHelpers {
271
289
  return regex.test(url);
272
290
  }
273
291
  }
274
- ;
275
- ({}); // @--end-of-file-for-module=ng2-rest lib/helpers.ts
276
292
 
277
293
  const log$3 = Log.create('[ng2-rest] params', Level.__NOTHING);
278
294
  /** check if string is a valid pattern */
@@ -307,9 +323,12 @@ function getRestPramsNames(pattern) {
307
323
  function containsModels(url, models) {
308
324
  if (url.charAt(0) !== '/')
309
325
  url = '/' + url;
326
+ // url = url.replace(new RegExp('\/', 'g'), '');
310
327
  let res = models.filter(m => {
311
328
  let word = '/' + m;
329
+ // log.d('word', word)
312
330
  let iii = url.indexOf(word);
331
+ // log.d('iii', iii)
313
332
  if (iii + word.length < url.length && url.charAt(iii + word.length) !== '/') {
314
333
  return false;
315
334
  }
@@ -319,6 +338,7 @@ function containsModels(url, models) {
319
338
  }
320
339
  return false;
321
340
  }).length;
341
+ // log.d('containsModels', res);
322
342
  return res === models.length;
323
343
  }
324
344
  function stars(n) {
@@ -330,11 +350,13 @@ function stars(n) {
330
350
  function getRestParams(url, pattern) {
331
351
  let res = {};
332
352
  let models = getRestPramsNames(pattern);
353
+ // log.d('models', models);
333
354
  models.forEach(m => {
334
355
  pattern = pattern.replace(`:${m}`, stars(m.length));
335
356
  });
336
357
  let currentModel = void 0;
337
358
  diffChars(pattern, url).forEach(d => {
359
+ // log.d('d', d);
338
360
  if (d.added) {
339
361
  if (!isNaN(Number(d.value)))
340
362
  res[currentModel] = Number(d.value);
@@ -347,6 +369,7 @@ function getRestParams(url, pattern) {
347
369
  currentModel = void 0;
348
370
  }
349
371
  let m = d.value.replace(':', "");
372
+ // log.d('model m', m)
350
373
  if (d.removed) {
351
374
  currentModel = models.shift();
352
375
  }
@@ -363,6 +386,7 @@ function cutUrlModel(params, models, output) {
363
386
  let m = models.pop();
364
387
  let param = m.match(/:[a-zA-Z0-9\.]+/)[0].replace(':', '');
365
388
  const paramIsPath = regexisPath.test(param);
389
+ // log.i('cut param', param)
366
390
  let model = m.match(/[a-zA-Z0-9]+\//)[0].replace('\/', '');
367
391
  if (params === void 0 ||
368
392
  (paramIsPath ? _.get(params, param) === void 0 : params[param] === void 0) ||
@@ -373,11 +397,13 @@ function cutUrlModel(params, models, output) {
373
397
  }
374
398
  else {
375
399
  if (paramIsPath) {
400
+ // log.i('param is path', param)
376
401
  let mrep = m.replace(new RegExp(`:${param}`, 'g'), `${_.get(params, param)}`);
377
402
  output.unshift(mrep);
378
403
  return cutUrlModel(params, models, output);
379
404
  }
380
405
  else {
406
+ // log.i('param is normal', param)
381
407
  let mrep = m.replace(new RegExp(`:${param}`, 'g'), `${params[param]}`);
382
408
  output.unshift(mrep);
383
409
  return cutUrlModel(params, models, output);
@@ -387,10 +413,13 @@ function cutUrlModel(params, models, output) {
387
413
  function interpolateParamsToUrl(params, url) {
388
414
  const regexInt = /\[\[([^\..]+\.[^\..]+)+\]\]/g;
389
415
  url = url.split('/').map(p => {
416
+ // log.d('url parts', p)
390
417
  let isParam = p.startsWith(':');
391
418
  if (isParam) {
392
419
  let part = p.slice(1);
420
+ // log.d('url param part', p)
393
421
  if (regexInt.test(part)) {
422
+ // let level = (url.split('.').length - 1)
394
423
  part = part.replace('[[', '');
395
424
  part = part.replace(']]', '');
396
425
  }
@@ -398,28 +427,35 @@ function interpolateParamsToUrl(params, url) {
398
427
  }
399
428
  return p;
400
429
  }).join('/');
430
+ // log.i('URL TO EXPOSE', url)
431
+ // log.i('params', params)
401
432
  let slash = {
402
433
  start: url.charAt(0) === '\/',
403
434
  end: url.charAt(url.length - 1) === '\/'
404
435
  };
405
436
  let morePramsOnEnd = url.match(/(\/:[a-zA-Z0-9\.]+){2,10}/g);
406
437
  if (morePramsOnEnd && (Array.isArray(morePramsOnEnd) && morePramsOnEnd.length === 1)) {
438
+ // log.i('morePramsOnEnd', morePramsOnEnd)
407
439
  let m = morePramsOnEnd[0];
408
440
  let match = m.match(/\/:[a-zA-Z0-9\.]+/g);
441
+ // log.i('match', match)
409
442
  match.forEach(e => {
410
443
  let c = e.replace('\/:', '');
444
+ // log.i('c', c)
411
445
  if (regexisPath.test(c)) {
412
446
  url = url.replace(e, `/${_.get(params, c)}`);
413
447
  }
414
448
  else {
415
449
  url = url.replace(e, `/${params[c]}`);
416
450
  }
451
+ // log.i('prog url', url)
417
452
  });
418
453
  return url;
419
454
  }
420
455
  let nestedParams = url.match(/[a-zA-Z0-9]+\/:[a-zA-Z0-9\.]+/g);
421
456
  if (!nestedParams || (Array.isArray(nestedParams) && nestedParams.length === 0))
422
457
  return url;
458
+ // check alone params
423
459
  if (!slash.end)
424
460
  url = `${url}/`;
425
461
  let addUndefinedForAlone = (!/:[a-zA-Z0-9\.]+\/$/g.test(url) && /[a-zA-Z0-9]+\/$/g.test(url));
@@ -456,12 +492,14 @@ function decodeUrl(url) {
456
492
  continue;
457
493
  }
458
494
  if (paramsObject.hasOwnProperty(p)) {
495
+ // chcek if property is number
459
496
  let n = Number(params[p]);
460
497
  if (!isNaN(n)) {
461
498
  params[p] = n;
462
499
  continue;
463
500
  }
464
501
  if (typeof params[p] === 'string') {
502
+ // check if property is object
465
503
  let json;
466
504
  try {
467
505
  json = JSON.parse(params[p]);
@@ -471,6 +509,12 @@ function decodeUrl(url) {
471
509
  params[p] = json;
472
510
  continue;
473
511
  }
512
+ // chcek if property value is like regular rexpression
513
+ // let regexExpression;
514
+ // try {
515
+ // regexExpression = new RegExp(params[p]);
516
+ // } catch (e) { }
517
+ // if (regexExpression !== undefined) params[p] = regexExpression;
474
518
  }
475
519
  }
476
520
  }
@@ -546,8 +590,6 @@ function prepareUrlOldWay(params) {
546
590
  }
547
591
  return this.endpoint + '/' + params;
548
592
  }
549
- ;
550
- ({}); // @--end-of-file-for-module=ng2-rest lib/params.ts
551
593
 
552
594
  class RestHeaders {
553
595
  static from(headers) {
@@ -579,6 +621,9 @@ class RestHeaders {
579
621
  */
580
622
  static fromResponseHeaderString(headersString) {
581
623
  const headers = new RestHeaders();
624
+ // console.log({
625
+ // headersString
626
+ // })
582
627
  headersString.split('\n').forEach(line => {
583
628
  const index = line.indexOf(':');
584
629
  if (index > 0) {
@@ -651,13 +696,20 @@ class RestHeaders {
651
696
  /**
652
697
  * Returns string of all headers.
653
698
  */
699
+ // TODO(vicb): returns {[name: string]: string[]}
654
700
  toJSON() {
655
701
  const serialized = {};
656
702
  if (!this._headers) {
703
+ // debugger
657
704
  }
705
+ // console.log('serializing headers',this._headers)
658
706
  this._headers.forEach((values, name) => {
659
707
  const split = [];
660
708
  values.forEach(v => split.push(...v.split(',')));
709
+ // console.log({
710
+ // values
711
+ // })
712
+ // values.forEach(v => split.push(...(v ? v : '').split(',')));
661
713
  serialized[this._normalizedNames.get(name)] = split;
662
714
  });
663
715
  return serialized;
@@ -675,8 +727,6 @@ class RestHeaders {
675
727
  }
676
728
  }
677
729
  }
678
- ;
679
- ({}); // @--end-of-file-for-module=ng2-rest lib/rest-headers.ts
680
730
 
681
731
  const CONTENT_TYPE = {
682
732
  APPLICATION_JSON: RestHeaders.from({
@@ -688,8 +738,8 @@ const CONTENT_TYPE = {
688
738
  'Accept': 'application/vnd.api+json'
689
739
  }),
690
740
  };
691
- ({}); // @--end-of-file-for-module=ng2-rest lib/content-type.ts
692
741
 
742
+ //#endregion
693
743
  class Rest {
694
744
  mock(mock) {
695
745
  if ((typeof mock === 'function') || (typeof mock === 'object')) {
@@ -730,7 +780,10 @@ class Rest {
730
780
  this.request = request;
731
781
  this.meta = meta;
732
782
  this.customContentType = customContentType;
783
+ //#endregion
784
+ //#region constructor
733
785
  this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
786
+ //#endregion
734
787
  this.array = {
735
788
  get: (params = void 0, doNotSerializeParams) => {
736
789
  return this.req('get', void 0, params, doNotSerializeParams, true);
@@ -756,11 +809,14 @@ class Rest {
756
809
  };
757
810
  this.__meta_endpoint = endpoint;
758
811
  }
812
+ //#endregion
813
+ //#region req
759
814
  req(method, requestBody, params, doNotSerializeParams = false, isArray = false) {
760
815
  const modelUrl = this.creatUrl(params, doNotSerializeParams);
761
816
  const body = (CLASS.getNameFromObject(requestBody) === 'FormData')
762
817
  ? requestBody
763
818
  : (requestBody ? JSON.stringify(requestBody) : void 0);
819
+ // console.log('this.customContentType', this.customContentType)
764
820
  if (this.customContentType) {
765
821
  const customHeaderKeys = this.customContentType.keys();
766
822
  const currentHeaderKeys = this._headers.keys();
@@ -774,10 +830,14 @@ class Rest {
774
830
  else {
775
831
  this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
776
832
  }
833
+ // console.log("_headers", this.headers)
777
834
  const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
778
835
  this.mockHttp = void 0;
779
836
  return result;
780
837
  }
838
+ //#endregion
839
+ //#region http methods
840
+ //#region replay
781
841
  replay(method) {
782
842
  this.request.replay(method, this.meta);
783
843
  }
@@ -803,8 +863,6 @@ class Rest {
803
863
  return this.req('jsonp', void 0, params, doNotSerializeParams);
804
864
  }
805
865
  }
806
- ;
807
- ({}); // @--end-of-file-for-module=ng2-rest lib/rest.class.ts
808
866
 
809
867
  class Cookie {
810
868
  static get Instance() {
@@ -832,8 +890,6 @@ class Cookie {
832
890
  this.write(name, "", -1);
833
891
  }
834
892
  }
835
- ;
836
- ({}); // @--end-of-file-for-module=ng2-rest lib/cookie.ts
837
893
 
838
894
  const log$2 = Log.create('request-cache', Level.__NOTHING);
839
895
  /**
@@ -929,11 +985,10 @@ class RequestCache {
929
985
  }
930
986
  }
931
987
  }
932
- ;
933
- ({}); // @--end-of-file-for-module=ng2-rest lib/request-cache.ts
934
988
 
935
989
  /* */
936
990
  /* */
991
+ // const log = Log.create('rest namespace', Level.__NOTHING)
937
992
  var Models;
938
993
  (function (Models) {
939
994
  Models.MethodConfig = Models$1.MethodConfig;
@@ -1044,6 +1099,9 @@ var Models;
1044
1099
  Models.BaseResponse = BaseResponse;
1045
1100
  class HttpResponse extends BaseResponse {
1046
1101
  constructor(sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray = false) {
1102
+ // console.log({
1103
+ // sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray
1104
+ // })
1047
1105
  super(responseText, headers, statusCode, isArray);
1048
1106
  this.sourceRequest = sourceRequest;
1049
1107
  this.responseText = responseText;
@@ -1057,12 +1115,14 @@ var Models;
1057
1115
  }
1058
1116
  init() {
1059
1117
  if (typeof this.entity === 'string') {
1118
+ // const headerWithMapping = headers.get(entity);
1060
1119
  let entityJSON = this.headers?.getAll(this.entity);
1061
1120
  if (!!entityJSON) {
1062
1121
  this.entity = JSON.parse(entityJSON.join());
1063
1122
  }
1064
1123
  }
1065
1124
  if (typeof this.circular === 'string') {
1125
+ // const headerWithMapping = headers.get(circular);
1066
1126
  let circuralJSON = this.headers?.getAll(this.circular);
1067
1127
  if (!!circuralJSON) {
1068
1128
  this.circular = JSON.parse(circuralJSON.join());
@@ -1079,6 +1139,8 @@ var Models;
1079
1139
  }
1080
1140
  Models.HttpResponse = HttpResponse;
1081
1141
  class HttpResponseError extends BaseResponse {
1142
+ // public tryRecconect() {
1143
+ // }
1082
1144
  constructor(message, responseText, headers, statusCode, jobid) {
1083
1145
  super(responseText, headers, statusCode);
1084
1146
  this.message = message;
@@ -1094,8 +1156,6 @@ var Models;
1094
1156
  /* */
1095
1157
  /* */
1096
1158
  })(Models || (Models = {}));
1097
- ;
1098
- ({}); // @--end-of-file-for-module=ng2-rest lib/models.ts
1099
1159
 
1100
1160
  const log$1 = Log.create('[ng2-rest] rest-request', Level.__NOTHING);
1101
1161
  /**
@@ -1105,10 +1165,13 @@ const jobIDkey = 'jobID';
1105
1165
  const customObs = 'customObs';
1106
1166
  const cancelFn = 'cancelFn';
1107
1167
  const isCanceled = 'isCanceled';
1168
+ //#region mock request
1169
+ //#endregion
1108
1170
  class RestRequest {
1109
1171
  constructor() {
1110
1172
  this.subjectInuUse = {};
1111
1173
  this.meta = {};
1174
+ //#endregion
1112
1175
  this.replaySubjects = {};
1113
1176
  }
1114
1177
  static { this.jobId = 0; }
@@ -1116,6 +1179,7 @@ class RestRequest {
1116
1179
  if (_.isUndefined(options)) {
1117
1180
  options = {};
1118
1181
  }
1182
+ // log.d(`HANDLE RESULT (jobid:${options.jobid}) ${sourceRequest.url}`);
1119
1183
  const { res, jobid, isArray, method } = options;
1120
1184
  if (typeof res !== 'object') {
1121
1185
  throw new Error('No resposnse for request. ');
@@ -1123,6 +1187,7 @@ class RestRequest {
1123
1187
  if (Helpers$1.isBrowser) {
1124
1188
  res.headers = RestHeaders.from(res.headers);
1125
1189
  }
1190
+ // error no internet
1126
1191
  if (res.error) {
1127
1192
  this.subjectInuUse[jobid].error(new Models.HttpResponseError(res.error, res.data, res.headers, res.code, jobid));
1128
1193
  return;
@@ -1139,12 +1204,14 @@ class RestRequest {
1139
1204
  checkCache(sourceRequest, jobid) {
1140
1205
  const existedInCache = RequestCache.findBy(sourceRequest);
1141
1206
  if (existedInCache) {
1207
+ // log.i('cache exists', existedInCache)
1142
1208
  const success = Resource['_listenSuccess'];
1143
1209
  success.next(existedInCache.response);
1144
1210
  this.subjectInuUse[jobid].next(existedInCache);
1145
1211
  this.subjectInuUse[jobid].complete();
1146
1212
  return true;
1147
1213
  }
1214
+ // log.i(`cache not exists for jobid ${jobid}`)
1148
1215
  return false;
1149
1216
  }
1150
1217
  async req(url, method, headers, body, jobid, isArray = false, mockHttp) {
@@ -1185,6 +1252,9 @@ class RestRequest {
1185
1252
  const responseType = headersJson.responsetypeaxios ? headersJson.responsetypeaxios : 'text';
1186
1253
  try {
1187
1254
  if (!response) {
1255
+ // console.log(`[${method}] (jobid=${jobid}) request to: ${url}`);
1256
+ // console.log('headers axios:', headers.toJSON())
1257
+ // console.log({ responseType, headersJson, body, method, url })
1188
1258
  response = await axios({
1189
1259
  url,
1190
1260
  method,
@@ -1192,8 +1262,11 @@ class RestRequest {
1192
1262
  responseType,
1193
1263
  headers: headersJson,
1194
1264
  cancelToken: source.token,
1265
+ // withCredentials: true, // this can be done manually
1195
1266
  });
1267
+ // log.d(`after response of jobid: ${jobid}`);
1196
1268
  }
1269
+ // console.log('AXIOS RESPONES', response)
1197
1270
  if (this.subjectInuUse[jobid][isCanceled]) {
1198
1271
  return;
1199
1272
  }
@@ -1219,9 +1292,14 @@ class RestRequest {
1219
1292
  if (this.subjectInuUse[jobid][isCanceled]) {
1220
1293
  return;
1221
1294
  }
1295
+ // console.log('ERROR RESPONESE catchedError typeof ', typeof catchedError)
1296
+ // console.log('ERROR RESPONESE catchedError', catchedError)
1222
1297
  if (typeof catchedError === 'object' && catchedError.response && catchedError.response.data) {
1223
1298
  const err = catchedError.response.data;
1224
1299
  const msg = catchedError.response.data.message || '';
1300
+ // console.log({
1301
+ // 'err.stack': err?.stack
1302
+ // })
1225
1303
  let stack = (err.stack || '').split('\n');
1226
1304
  const errObs = Resource['_listenErrors'];
1227
1305
  errObs.next({
@@ -1253,21 +1331,27 @@ class RestRequest {
1253
1331
  }
1254
1332
  getReplay(method, meta, onlyGetLastReplayForMethod) {
1255
1333
  let replay;
1334
+ //#region prevent empty tree
1256
1335
  if (_.isUndefined(this.replaySubjects[meta.endpoint])) {
1336
+ // log.i(`(${meta.endpoint}) `);
1257
1337
  this.replaySubjects[meta.endpoint] = {};
1258
1338
  }
1259
1339
  if (_.isUndefined(this.replaySubjects[meta.endpoint][meta.path])) {
1340
+ // log.i(`(${meta.endpoint})(${meta.path}) `);
1260
1341
  this.replaySubjects[meta.endpoint][meta.path] = {};
1261
1342
  }
1262
1343
  if (_.isUndefined(this.replaySubjects[meta.endpoint][meta.path][method])) {
1344
+ // log.i(`(${meta.endpoint})(${meta.path}) `);
1263
1345
  this.replaySubjects[meta.endpoint][meta.path][method] = {};
1264
1346
  }
1347
+ //#endregion
1265
1348
  const objectIDToCreateOrLast = (Object.keys(this.replaySubjects[meta.endpoint][meta.path][method]).length) +
1266
1349
  (onlyGetLastReplayForMethod ? 0 : 1);
1267
1350
  if (onlyGetLastReplayForMethod && (objectIDToCreateOrLast === 0)) {
1268
1351
  return replay;
1269
1352
  }
1270
1353
  if (_.isUndefined(this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast])) {
1354
+ // log.i(`(${meta.endpoint})(${meta.path})(${method}) `);
1271
1355
  this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast] = {
1272
1356
  subject: new Subject(),
1273
1357
  data: void 0,
@@ -1285,7 +1369,10 @@ class RestRequest {
1285
1369
  this.meta[jobid] = meta;
1286
1370
  this.subjectInuUse[jobid] = subject;
1287
1371
  this.subjectInuUse[jobid][customObs] = new Observable((observer) => {
1372
+ // observer.remove(() => {
1373
+ // });
1288
1374
  observer.add(() => {
1375
+ // console.log(`cancel observable job${jobid}`)
1289
1376
  if (!this.subjectInuUse[jobid][isCanceled]) {
1290
1377
  this.subjectInuUse[jobid][isCanceled] = true;
1291
1378
  if (typeof this.subjectInuUse[jobid][cancelFn] === 'function') {
@@ -1293,6 +1380,7 @@ class RestRequest {
1293
1380
  }
1294
1381
  }
1295
1382
  else {
1383
+ // console.log(`somehow second time cancel ${jobid}`)
1296
1384
  }
1297
1385
  });
1298
1386
  const sub = subject.subscribe({
@@ -1304,13 +1392,26 @@ class RestRequest {
1304
1392
  },
1305
1393
  });
1306
1394
  });
1395
+ //#region DISPOSE @UNCOMMENT AFTER TESTS
1396
+ // if (objectIDToCreateOrLast > 2) {
1397
+ // const oldReq: Models.ReplayData = this.replaySubjects[meta.endpoint][meta.path][method][(objectIDToCreateOrLast - 2)];
1398
+ // if (_.isUndefined(this.meta[oldReq.id])) {
1399
+ // // cant delete this - for counter purpose
1400
+ // this.replaySubjects[meta.endpoint][meta.path][method][(objectIDToCreateOrLast - 2)] = {};
1401
+ // delete this.subjectInuUse[oldReq.id];
1402
+ // delete this.meta[oldReq.id];
1403
+ // }
1404
+ // }
1405
+ //#endregion
1307
1406
  }
1308
1407
  return replay;
1309
1408
  }
1409
+ //#region http methods
1310
1410
  generalReq(method, url, body, headers, meta, isArray, mockHttp) {
1311
1411
  const replay = this.getReplay(method, meta, false);
1312
1412
  replay.data = { url, body, headers, isArray };
1313
1413
  ((pthis, purl, pmethod, pheaders, pbody, pid, pisArray, pmockHttp) => {
1414
+ // log.d(`for ${purl} jobid ${pid}`);
1314
1415
  setTimeout(() => pthis.req(purl, pmethod, pheaders, pbody, pid, pisArray, pmockHttp));
1315
1416
  })(this, url, method, headers, body, replay.id, isArray, mockHttp);
1316
1417
  const resp = firstValueFrom(replay.subject[customObs]);
@@ -1408,8 +1509,6 @@ class RestRequest {
1408
1509
  setTimeout(() => this.req(url, method, headers, body, replay.id, isArray));
1409
1510
  }
1410
1511
  }
1411
- ;
1412
- ({}); // @--end-of-file-for-module=ng2-rest lib/rest-request.ts
1413
1512
 
1414
1513
  const log = Log.create('resouce-service', Level.__NOTHING);
1415
1514
  class Resource {
@@ -1422,6 +1521,7 @@ class Resource {
1422
1521
  return this._listenSuccess.asObservable();
1423
1522
  }
1424
1523
  static { this.enableWarnings = true; }
1524
+ //#region private mthods and fields
1425
1525
  getZone() {
1426
1526
  const isNode = (typeof window === 'undefined');
1427
1527
  if (isNode) {
@@ -1461,6 +1561,7 @@ class Resource {
1461
1561
  RestRequest.zone = zone;
1462
1562
  }
1463
1563
  checkNestedModels(model, allModels) {
1564
+ // if (model.indexOf('/') !== -1) { //TODO make this better, becouse now I unecesary checking shit
1464
1565
  for (let p in allModels) {
1465
1566
  if (allModels.hasOwnProperty(p)) {
1466
1567
  let m = allModels[p];
@@ -1473,6 +1574,7 @@ class Resource {
1473
1574
  }
1474
1575
  }
1475
1576
  }
1577
+ // }
1476
1578
  return model;
1477
1579
  }
1478
1580
  static { this.instance = new Resource(); }
@@ -1487,6 +1589,8 @@ class Resource {
1487
1589
  return Resource.endpoints[endpoint].models[model];
1488
1590
  }
1489
1591
  static { this.request = new RestRequest(); }
1592
+ //#endregion
1593
+ //#region create
1490
1594
  static create(e, model, entityMapping, circular, customContentType) {
1491
1595
  const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
1492
1596
  const matchArr = model.match(badRestRegEX) || [];
@@ -1504,6 +1608,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1504
1608
  ;
1505
1609
  Resource.map(e, e);
1506
1610
  Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
1611
+ // if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
1507
1612
  return {
1508
1613
  model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
1509
1614
  replay: (method) => {
@@ -1514,9 +1619,13 @@ Instead use nested approach: /book/:bookid/author/:authorid
1514
1619
  }
1515
1620
  };
1516
1621
  }
1622
+ //#endregion
1623
+ //#region reset
1517
1624
  static reset() {
1518
1625
  Resource.endpoints = {};
1519
1626
  }
1627
+ //#endregion
1628
+ //#region constructor
1520
1629
  constructor() {
1521
1630
  setTimeout(() => {
1522
1631
  const zone = this.getZone();
@@ -1526,7 +1635,9 @@ Instead use nested approach: /book/:bookid/author/:authorid
1526
1635
  ;
1527
1636
  });
1528
1637
  }
1638
+ //#endregion
1529
1639
  static { this.Cookies = Cookie.Instance; }
1640
+ //#region map
1530
1641
  static map(endpoint, url) {
1531
1642
  log.i('url', url);
1532
1643
  let regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
@@ -1550,6 +1661,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1550
1661
  log.i('enpoints', Resource.endpoints);
1551
1662
  return true;
1552
1663
  }
1664
+ //#endregion
1553
1665
  static prepareModel(model) {
1554
1666
  if (model.charAt(model.length - 1) === '/')
1555
1667
  model = model.slice(0, model.length - 1);
@@ -1557,6 +1669,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1557
1669
  model = model.slice(1, model.length);
1558
1670
  return model;
1559
1671
  }
1672
+ //#region add
1560
1673
  /**
1561
1674
  * And enipoint to application
1562
1675
  *
@@ -1589,6 +1702,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
1589
1702
  }, customContentType); // TODO put custom content type in meta ?
1590
1703
  return;
1591
1704
  }
1705
+ //#endregion
1706
+ //#region api
1592
1707
  /**
1593
1708
  * Access api throught endpoint
1594
1709
  *
@@ -1597,6 +1712,10 @@ Instead use nested approach: /book/:bookid/author/:authorid
1597
1712
  * @returns {Rest<T, TA>}
1598
1713
  */
1599
1714
  api(endpoint, model) {
1715
+ // log.i(`[api]
1716
+ // creating for endpoint: "${endpoint}"
1717
+ // model: "${model}"
1718
+ // `)
1600
1719
  if (model.charAt(0) === '/')
1601
1720
  model = model.slice(1, model.length);
1602
1721
  let e = (endpoint).toString();
@@ -1607,22 +1726,37 @@ Instead use nested approach: /book/:bookid/author/:authorid
1607
1726
  let orgModel = model;
1608
1727
  model = this.checkNestedModels(model, allModels);
1609
1728
  if (Resource.endpoints[e].models[model] === void 0) {
1729
+ // log.d('Resource.endpoints', Resource.endpoints);
1610
1730
  throw `Model '${model}' is undefined in endpoint: ${Resource.endpoints[e].url} `;
1611
1731
  }
1612
1732
  let res = Resource.endpoints[(endpoint).toString()].models[model];
1733
+ // log.d(`
1734
+ // orgModel: ${orgModel}
1735
+ // model: ${model}
1736
+ // `)
1613
1737
  if (orgModel !== model) {
1614
1738
  let baseUrl = Resource.endpoints[(endpoint).toString()].url;
1739
+ // log.d('base', Resource.endpoints[<string>(endpoint).toString()])
1740
+ // log.d('baseUrl', baseUrl)
1741
+ // log.d('orgModel', orgModel)
1615
1742
  res.__rest_endpoint = `${baseUrl}/${orgModel}`;
1616
1743
  }
1617
1744
  else {
1618
1745
  res.__rest_endpoint = void 0;
1619
1746
  }
1620
1747
  ;
1748
+ // log.i(`Resource.endpoints`, Resource.endpoints)
1621
1749
  return res;
1622
1750
  }
1623
1751
  }
1624
- ;
1625
- ({}); // @--end-of-file-for-module=ng2-rest lib/resource-service.ts
1752
+ // const res = Resource.create('')
1753
+ // res.model()
1754
+ // .mock({
1755
+ // code: 500,
1756
+ // data: {},
1757
+ // isArray: true
1758
+ // })
1759
+ // .array.
1626
1760
 
1627
1761
  /**
1628
1762
  *
@@ -1639,6 +1773,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1639
1773
  class ExtendedResource {
1640
1774
  static { this.doNotSerializeQueryParams = false; }
1641
1775
  static { this.handlers = []; }
1776
+ // add(endpoint: E, model: string, group?: string, name?: string, description?: string) { }
1642
1777
  constructor(endpoint, path_model) {
1643
1778
  this.endpoint = endpoint;
1644
1779
  this.path_model = path_model;
@@ -1737,11 +1872,6 @@ class SimpleResource {
1737
1872
  this.model = rest.model;
1738
1873
  }
1739
1874
  }
1740
- ;
1741
- ({}); // @--end-of-file-for-module=ng2-rest lib/other/simple-resource.ts
1742
-
1743
- ;
1744
- ({}); // @--end-of-file-for-module=ng2-rest lib/index.ts
1745
1875
 
1746
1876
  /**
1747
1877
  * Generated bundle index. Do not edit.