@ngrx-traits/common 0.0.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.
Files changed (219) hide show
  1. package/README.md +7 -0
  2. package/async-action/async-action.model.d.ts +19 -0
  3. package/async-action/async-action.trait.d.ts +59 -0
  4. package/async-action/index.d.ts +2 -0
  5. package/bundles/ngrx-traits-common.umd.js +2126 -0
  6. package/bundles/ngrx-traits-common.umd.js.map +1 -0
  7. package/crud-entities/crud-entities.model.d.ts +76 -0
  8. package/crud-entities/crud-entities.trait.actions.d.ts +2 -0
  9. package/crud-entities/crud-entities.trait.d.ts +35 -0
  10. package/crud-entities/crud-entities.trait.mutators.d.ts +3 -0
  11. package/crud-entities/crud-entities.trait.reducer.d.ts +7 -0
  12. package/crud-entities/crud-entities.trait.selectors.d.ts +3 -0
  13. package/crud-entities/index.d.ts +2 -0
  14. package/entities-pagination/entities-pagination.model.d.ts +82 -0
  15. package/entities-pagination/entities-pagination.model.internal.d.ts +12 -0
  16. package/entities-pagination/entities-pagination.trait.actions.d.ts +2 -0
  17. package/entities-pagination/entities-pagination.trait.d.ts +55 -0
  18. package/entities-pagination/entities-pagination.trait.effects.d.ts +8 -0
  19. package/entities-pagination/entities-pagination.trait.mutators.d.ts +3 -0
  20. package/entities-pagination/entities-pagination.trait.reducer.d.ts +7 -0
  21. package/entities-pagination/entities-pagination.trait.selectors.d.ts +4 -0
  22. package/entities-pagination/index.d.ts +2 -0
  23. package/esm2015/async-action/async-action.model.js +2 -0
  24. package/esm2015/async-action/async-action.model.js.map +1 -0
  25. package/esm2015/async-action/async-action.trait.js +96 -0
  26. package/esm2015/async-action/async-action.trait.js.map +1 -0
  27. package/esm2015/async-action/index.js +3 -0
  28. package/esm2015/async-action/index.js.map +1 -0
  29. package/esm2015/crud-entities/crud-entities.model.js +8 -0
  30. package/esm2015/crud-entities/crud-entities.model.js.map +1 -0
  31. package/esm2015/crud-entities/crud-entities.trait.actions.js +20 -0
  32. package/esm2015/crud-entities/crud-entities.trait.actions.js.map +1 -0
  33. package/esm2015/crud-entities/crud-entities.trait.js +53 -0
  34. package/esm2015/crud-entities/crud-entities.trait.js.map +1 -0
  35. package/esm2015/crud-entities/crud-entities.trait.mutators.js +101 -0
  36. package/esm2015/crud-entities/crud-entities.trait.mutators.js.map +1 -0
  37. package/esm2015/crud-entities/crud-entities.trait.reducer.js +15 -0
  38. package/esm2015/crud-entities/crud-entities.trait.reducer.js.map +1 -0
  39. package/esm2015/crud-entities/crud-entities.trait.selectors.js +70 -0
  40. package/esm2015/crud-entities/crud-entities.trait.selectors.js.map +1 -0
  41. package/esm2015/crud-entities/index.js +3 -0
  42. package/esm2015/crud-entities/index.js.map +1 -0
  43. package/esm2015/entities-pagination/entities-pagination.model.internal.js +2 -0
  44. package/esm2015/entities-pagination/entities-pagination.model.internal.js.map +1 -0
  45. package/esm2015/entities-pagination/entities-pagination.model.js +2 -0
  46. package/esm2015/entities-pagination/entities-pagination.model.js.map +1 -0
  47. package/esm2015/entities-pagination/entities-pagination.trait.actions.js +20 -0
  48. package/esm2015/entities-pagination/entities-pagination.trait.actions.js.map +1 -0
  49. package/esm2015/entities-pagination/entities-pagination.trait.effects.js +54 -0
  50. package/esm2015/entities-pagination/entities-pagination.trait.effects.js.map +1 -0
  51. package/esm2015/entities-pagination/entities-pagination.trait.js +80 -0
  52. package/esm2015/entities-pagination/entities-pagination.trait.js.map +1 -0
  53. package/esm2015/entities-pagination/entities-pagination.trait.mutators.js +23 -0
  54. package/esm2015/entities-pagination/entities-pagination.trait.mutators.js.map +1 -0
  55. package/esm2015/entities-pagination/entities-pagination.trait.reducer.js +33 -0
  56. package/esm2015/entities-pagination/entities-pagination.trait.reducer.js.map +1 -0
  57. package/esm2015/entities-pagination/entities-pagination.trait.selectors.js +65 -0
  58. package/esm2015/entities-pagination/entities-pagination.trait.selectors.js.map +1 -0
  59. package/esm2015/entities-pagination/index.js +3 -0
  60. package/esm2015/entities-pagination/index.js.map +1 -0
  61. package/esm2015/filter-entities/filter-entities.model.internal.js +2 -0
  62. package/esm2015/filter-entities/filter-entities.model.internal.js.map +1 -0
  63. package/esm2015/filter-entities/filter-entities.model.js +2 -0
  64. package/esm2015/filter-entities/filter-entities.model.js.map +1 -0
  65. package/esm2015/filter-entities/filter-entities.trait.actions.js +16 -0
  66. package/esm2015/filter-entities/filter-entities.trait.actions.js.map +1 -0
  67. package/esm2015/filter-entities/filter-entities.trait.effect.js +56 -0
  68. package/esm2015/filter-entities/filter-entities.trait.effect.js.map +1 -0
  69. package/esm2015/filter-entities/filter-entities.trait.js +68 -0
  70. package/esm2015/filter-entities/filter-entities.trait.js.map +1 -0
  71. package/esm2015/filter-entities/filter-entities.trait.mutators.js +7 -0
  72. package/esm2015/filter-entities/filter-entities.trait.mutators.js.map +1 -0
  73. package/esm2015/filter-entities/filter-entities.trait.reducer.js +9 -0
  74. package/esm2015/filter-entities/filter-entities.trait.reducer.js.map +1 -0
  75. package/esm2015/filter-entities/filter-entities.trait.selectors.js +9 -0
  76. package/esm2015/filter-entities/filter-entities.trait.selectors.js.map +1 -0
  77. package/esm2015/filter-entities/index.js +3 -0
  78. package/esm2015/filter-entities/index.js.map +1 -0
  79. package/esm2015/index.js +12 -0
  80. package/esm2015/index.js.map +1 -0
  81. package/esm2015/load-entities/index.js +3 -0
  82. package/esm2015/load-entities/index.js.map +1 -0
  83. package/esm2015/load-entities/load-entities.model.js +2 -0
  84. package/esm2015/load-entities/load-entities.model.js.map +1 -0
  85. package/esm2015/load-entities/load-entities.mutators.js +8 -0
  86. package/esm2015/load-entities/load-entities.mutators.js.map +1 -0
  87. package/esm2015/load-entities/load-entities.trait.actions.js +10 -0
  88. package/esm2015/load-entities/load-entities.trait.actions.js.map +1 -0
  89. package/esm2015/load-entities/load-entities.trait.js +57 -0
  90. package/esm2015/load-entities/load-entities.trait.js.map +1 -0
  91. package/esm2015/load-entities/load-entities.trait.reducer.js +12 -0
  92. package/esm2015/load-entities/load-entities.trait.reducer.js.map +1 -0
  93. package/esm2015/load-entities/load-entities.trait.selectors.js +33 -0
  94. package/esm2015/load-entities/load-entities.trait.selectors.js.map +1 -0
  95. package/esm2015/load-entities/load-entities.utils.js +10 -0
  96. package/esm2015/load-entities/load-entities.utils.js.map +1 -0
  97. package/esm2015/load-entity/index.js +3 -0
  98. package/esm2015/load-entity/index.js.map +1 -0
  99. package/esm2015/load-entity/load-entity.model.js +2 -0
  100. package/esm2015/load-entity/load-entity.model.js.map +1 -0
  101. package/esm2015/load-entity/load-entity.traits.js +65 -0
  102. package/esm2015/load-entity/load-entity.traits.js.map +1 -0
  103. package/esm2015/ngrx-traits-common.js +5 -0
  104. package/esm2015/ngrx-traits-common.js.map +1 -0
  105. package/esm2015/public_api.js +2 -0
  106. package/esm2015/public_api.js.map +1 -0
  107. package/esm2015/reset/index.js +2 -0
  108. package/esm2015/reset/index.js.map +1 -0
  109. package/esm2015/reset/reset.trait.js +66 -0
  110. package/esm2015/reset/reset.trait.js.map +1 -0
  111. package/esm2015/select-entities/index.js +4 -0
  112. package/esm2015/select-entities/index.js.map +1 -0
  113. package/esm2015/select-entities/select-entities.model.js +2 -0
  114. package/esm2015/select-entities/select-entities.model.js.map +1 -0
  115. package/esm2015/select-entities/select-entities.trait.actions.js +11 -0
  116. package/esm2015/select-entities/select-entities.trait.actions.js.map +1 -0
  117. package/esm2015/select-entities/select-entities.trait.js +50 -0
  118. package/esm2015/select-entities/select-entities.trait.js.map +1 -0
  119. package/esm2015/select-entities/select-entities.trait.mutators.js +21 -0
  120. package/esm2015/select-entities/select-entities.trait.mutators.js.map +1 -0
  121. package/esm2015/select-entities/select-entities.trait.reducer.js +40 -0
  122. package/esm2015/select-entities/select-entities.trait.reducer.js.map +1 -0
  123. package/esm2015/select-entities/select-entities.trait.selectors.js +28 -0
  124. package/esm2015/select-entities/select-entities.trait.selectors.js.map +1 -0
  125. package/esm2015/select-entities/select-entities.utils.js +25 -0
  126. package/esm2015/select-entities/select-entities.utils.js.map +1 -0
  127. package/esm2015/select-entity/index.js +3 -0
  128. package/esm2015/select-entity/index.js.map +1 -0
  129. package/esm2015/select-entity/select-entity.model.js +2 -0
  130. package/esm2015/select-entity/select-entity.model.js.map +1 -0
  131. package/esm2015/select-entity/select-entity.trait.actions.js +9 -0
  132. package/esm2015/select-entity/select-entity.trait.actions.js.map +1 -0
  133. package/esm2015/select-entity/select-entity.trait.js +47 -0
  134. package/esm2015/select-entity/select-entity.trait.js.map +1 -0
  135. package/esm2015/select-entity/select-entity.trait.mutators.js +17 -0
  136. package/esm2015/select-entity/select-entity.trait.mutators.js.map +1 -0
  137. package/esm2015/select-entity/select-entity.trait.reducer.js +26 -0
  138. package/esm2015/select-entity/select-entity.trait.reducer.js.map +1 -0
  139. package/esm2015/select-entity/select-entity.trait.selectors.js +13 -0
  140. package/esm2015/select-entity/select-entity.trait.selectors.js.map +1 -0
  141. package/esm2015/set-entity/index.js +3 -0
  142. package/esm2015/set-entity/index.js.map +1 -0
  143. package/esm2015/set-entity/set-entity.model.js +2 -0
  144. package/esm2015/set-entity/set-entity.model.js.map +1 -0
  145. package/esm2015/set-entity/set-entity.trait.js +52 -0
  146. package/esm2015/set-entity/set-entity.trait.js.map +1 -0
  147. package/esm2015/sort-entities/index.js +4 -0
  148. package/esm2015/sort-entities/index.js.map +1 -0
  149. package/esm2015/sort-entities/sort-entities.model.js +2 -0
  150. package/esm2015/sort-entities/sort-entities.model.js.map +1 -0
  151. package/esm2015/sort-entities/sort-entities.trait.actions.js +8 -0
  152. package/esm2015/sort-entities/sort-entities.trait.actions.js.map +1 -0
  153. package/esm2015/sort-entities/sort-entities.trait.effect.js +28 -0
  154. package/esm2015/sort-entities/sort-entities.trait.effect.js.map +1 -0
  155. package/esm2015/sort-entities/sort-entities.trait.js +53 -0
  156. package/esm2015/sort-entities/sort-entities.trait.js.map +1 -0
  157. package/esm2015/sort-entities/sort-entities.trait.mutators.js +13 -0
  158. package/esm2015/sort-entities/sort-entities.trait.mutators.js.map +1 -0
  159. package/esm2015/sort-entities/sort-entities.trait.reducer.js +22 -0
  160. package/esm2015/sort-entities/sort-entities.trait.reducer.js.map +1 -0
  161. package/esm2015/sort-entities/sort-entities.trait.selectors.js +10 -0
  162. package/esm2015/sort-entities/sort-entities.trait.selectors.js.map +1 -0
  163. package/esm2015/sort-entities/sort-entities.utils.js +61 -0
  164. package/esm2015/sort-entities/sort-entities.utils.js.map +1 -0
  165. package/fesm2015/ngrx-traits-common.js +1511 -0
  166. package/fesm2015/ngrx-traits-common.js.map +1 -0
  167. package/filter-entities/filter-entities.model.d.ts +57 -0
  168. package/filter-entities/filter-entities.model.internal.d.ts +14 -0
  169. package/filter-entities/filter-entities.trait.actions.d.ts +2 -0
  170. package/filter-entities/filter-entities.trait.d.ts +42 -0
  171. package/filter-entities/filter-entities.trait.effect.d.ts +6 -0
  172. package/filter-entities/filter-entities.trait.mutators.d.ts +2 -0
  173. package/filter-entities/filter-entities.trait.reducer.d.ts +5 -0
  174. package/filter-entities/filter-entities.trait.selectors.d.ts +4 -0
  175. package/filter-entities/index.d.ts +2 -0
  176. package/index.d.ts +11 -0
  177. package/load-entities/index.d.ts +2 -0
  178. package/load-entities/load-entities.model.d.ts +97 -0
  179. package/load-entities/load-entities.mutators.d.ts +3 -0
  180. package/load-entities/load-entities.trait.actions.d.ts +2 -0
  181. package/load-entities/load-entities.trait.d.ts +39 -0
  182. package/load-entities/load-entities.trait.reducer.d.ts +4 -0
  183. package/load-entities/load-entities.trait.selectors.d.ts +3 -0
  184. package/load-entities/load-entities.utils.d.ts +4 -0
  185. package/load-entity/index.d.ts +2 -0
  186. package/load-entity/load-entity.model.d.ts +9 -0
  187. package/load-entity/load-entity.traits.d.ts +64 -0
  188. package/ngrx-traits-common.d.ts +5 -0
  189. package/package.json +28 -0
  190. package/public_api.d.ts +1 -0
  191. package/reset/index.d.ts +1 -0
  192. package/reset/reset.trait.d.ts +32 -0
  193. package/select-entities/index.d.ts +3 -0
  194. package/select-entities/select-entities.model.d.ts +41 -0
  195. package/select-entities/select-entities.trait.actions.d.ts +2 -0
  196. package/select-entities/select-entities.trait.d.ts +34 -0
  197. package/select-entities/select-entities.trait.mutators.d.ts +2 -0
  198. package/select-entities/select-entities.trait.reducer.d.ts +8 -0
  199. package/select-entities/select-entities.trait.selectors.d.ts +3 -0
  200. package/select-entities/select-entities.utils.d.ts +7 -0
  201. package/select-entity/index.d.ts +2 -0
  202. package/select-entity/select-entity.model.d.ts +33 -0
  203. package/select-entity/select-entity.trait.actions.d.ts +2 -0
  204. package/select-entity/select-entity.trait.d.ts +30 -0
  205. package/select-entity/select-entity.trait.mutators.d.ts +2 -0
  206. package/select-entity/select-entity.trait.reducer.d.ts +8 -0
  207. package/select-entity/select-entity.trait.selectors.d.ts +2 -0
  208. package/set-entity/index.d.ts +2 -0
  209. package/set-entity/set-entity.model.d.ts +16 -0
  210. package/set-entity/set-entity.trait.d.ts +39 -0
  211. package/sort-entities/index.d.ts +3 -0
  212. package/sort-entities/sort-entities.model.d.ts +35 -0
  213. package/sort-entities/sort-entities.trait.actions.d.ts +2 -0
  214. package/sort-entities/sort-entities.trait.d.ts +33 -0
  215. package/sort-entities/sort-entities.trait.effect.d.ts +6 -0
  216. package/sort-entities/sort-entities.trait.mutators.d.ts +3 -0
  217. package/sort-entities/sort-entities.trait.reducer.d.ts +4 -0
  218. package/sort-entities/sort-entities.trait.selectors.d.ts +2 -0
  219. package/sort-entities/sort-entities.utils.d.ts +8 -0
@@ -0,0 +1,2126 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngrx/store'), require('@ngrx-traits/core'), require('@ngrx/entity'), require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@ngrx/effects')) :
3
+ typeof define === 'function' && define.amd ? define('@ngrx-traits/common', ['exports', '@ngrx/store', '@ngrx-traits/core', '@ngrx/entity', '@angular/core', 'rxjs', 'rxjs/operators', '@ngrx/effects'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngrx-traits'] = global['ngrx-traits'] || {}, global['ngrx-traits'].common = {}), global.i2, global.core, global.entity, global.ng.core, global.rxjs, global.rxjs.operators, global.i1));
5
+ }(this, (function (exports, i2, core, entity, i0, rxjs, operators, i1) { 'use strict';
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () {
17
+ return e[k];
18
+ }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n['default'] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
28
+ var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
29
+ var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
30
+
31
+ var loadEntitiesTraitKey = 'loadEntities';
32
+
33
+ /*! *****************************************************************************
34
+ Copyright (c) Microsoft Corporation.
35
+
36
+ Permission to use, copy, modify, and/or distribute this software for any
37
+ purpose with or without fee is hereby granted.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
40
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
41
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
42
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
43
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
44
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
45
+ PERFORMANCE OF THIS SOFTWARE.
46
+ ***************************************************************************** */
47
+ /* global Reflect, Promise */
48
+ var extendStatics = function (d, b) {
49
+ extendStatics = Object.setPrototypeOf ||
50
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
51
+ function (d, b) { for (var p in b)
52
+ if (Object.prototype.hasOwnProperty.call(b, p))
53
+ d[p] = b[p]; };
54
+ return extendStatics(d, b);
55
+ };
56
+ function __extends(d, b) {
57
+ if (typeof b !== "function" && b !== null)
58
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
59
+ extendStatics(d, b);
60
+ function __() { this.constructor = d; }
61
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
62
+ }
63
+ var __assign = function () {
64
+ __assign = Object.assign || function __assign(t) {
65
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
66
+ s = arguments[i];
67
+ for (var p in s)
68
+ if (Object.prototype.hasOwnProperty.call(s, p))
69
+ t[p] = s[p];
70
+ }
71
+ return t;
72
+ };
73
+ return __assign.apply(this, arguments);
74
+ };
75
+ function __rest(s, e) {
76
+ var t = {};
77
+ for (var p in s)
78
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
79
+ t[p] = s[p];
80
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
81
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
82
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
83
+ t[p[i]] = s[p[i]];
84
+ }
85
+ return t;
86
+ }
87
+ function __decorate(decorators, target, key, desc) {
88
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
89
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
90
+ r = Reflect.decorate(decorators, target, key, desc);
91
+ else
92
+ for (var i = decorators.length - 1; i >= 0; i--)
93
+ if (d = decorators[i])
94
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
95
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
96
+ }
97
+ function __param(paramIndex, decorator) {
98
+ return function (target, key) { decorator(target, key, paramIndex); };
99
+ }
100
+ function __metadata(metadataKey, metadataValue) {
101
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
102
+ return Reflect.metadata(metadataKey, metadataValue);
103
+ }
104
+ function __awaiter(thisArg, _arguments, P, generator) {
105
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
106
+ return new (P || (P = Promise))(function (resolve, reject) {
107
+ function fulfilled(value) { try {
108
+ step(generator.next(value));
109
+ }
110
+ catch (e) {
111
+ reject(e);
112
+ } }
113
+ function rejected(value) { try {
114
+ step(generator["throw"](value));
115
+ }
116
+ catch (e) {
117
+ reject(e);
118
+ } }
119
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
120
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
121
+ });
122
+ }
123
+ function __generator(thisArg, body) {
124
+ var _ = { label: 0, sent: function () { if (t[0] & 1)
125
+ throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
126
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
127
+ function verb(n) { return function (v) { return step([n, v]); }; }
128
+ function step(op) {
129
+ if (f)
130
+ throw new TypeError("Generator is already executing.");
131
+ while (_)
132
+ try {
133
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
134
+ return t;
135
+ if (y = 0, t)
136
+ op = [op[0] & 2, t.value];
137
+ switch (op[0]) {
138
+ case 0:
139
+ case 1:
140
+ t = op;
141
+ break;
142
+ case 4:
143
+ _.label++;
144
+ return { value: op[1], done: false };
145
+ case 5:
146
+ _.label++;
147
+ y = op[1];
148
+ op = [0];
149
+ continue;
150
+ case 7:
151
+ op = _.ops.pop();
152
+ _.trys.pop();
153
+ continue;
154
+ default:
155
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
156
+ _ = 0;
157
+ continue;
158
+ }
159
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
160
+ _.label = op[1];
161
+ break;
162
+ }
163
+ if (op[0] === 6 && _.label < t[1]) {
164
+ _.label = t[1];
165
+ t = op;
166
+ break;
167
+ }
168
+ if (t && _.label < t[2]) {
169
+ _.label = t[2];
170
+ _.ops.push(op);
171
+ break;
172
+ }
173
+ if (t[2])
174
+ _.ops.pop();
175
+ _.trys.pop();
176
+ continue;
177
+ }
178
+ op = body.call(thisArg, _);
179
+ }
180
+ catch (e) {
181
+ op = [6, e];
182
+ y = 0;
183
+ }
184
+ finally {
185
+ f = t = 0;
186
+ }
187
+ if (op[0] & 5)
188
+ throw op[1];
189
+ return { value: op[0] ? op[1] : void 0, done: true };
190
+ }
191
+ }
192
+ var __createBinding = Object.create ? (function (o, m, k, k2) {
193
+ if (k2 === undefined)
194
+ k2 = k;
195
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
196
+ }) : (function (o, m, k, k2) {
197
+ if (k2 === undefined)
198
+ k2 = k;
199
+ o[k2] = m[k];
200
+ });
201
+ function __exportStar(m, o) {
202
+ for (var p in m)
203
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
204
+ __createBinding(o, m, p);
205
+ }
206
+ function __values(o) {
207
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
208
+ if (m)
209
+ return m.call(o);
210
+ if (o && typeof o.length === "number")
211
+ return {
212
+ next: function () {
213
+ if (o && i >= o.length)
214
+ o = void 0;
215
+ return { value: o && o[i++], done: !o };
216
+ }
217
+ };
218
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
219
+ }
220
+ function __read(o, n) {
221
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
222
+ if (!m)
223
+ return o;
224
+ var i = m.call(o), r, ar = [], e;
225
+ try {
226
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
227
+ ar.push(r.value);
228
+ }
229
+ catch (error) {
230
+ e = { error: error };
231
+ }
232
+ finally {
233
+ try {
234
+ if (r && !r.done && (m = i["return"]))
235
+ m.call(i);
236
+ }
237
+ finally {
238
+ if (e)
239
+ throw e.error;
240
+ }
241
+ }
242
+ return ar;
243
+ }
244
+ /** @deprecated */
245
+ function __spread() {
246
+ for (var ar = [], i = 0; i < arguments.length; i++)
247
+ ar = ar.concat(__read(arguments[i]));
248
+ return ar;
249
+ }
250
+ /** @deprecated */
251
+ function __spreadArrays() {
252
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
253
+ s += arguments[i].length;
254
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
255
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
256
+ r[k] = a[j];
257
+ return r;
258
+ }
259
+ function __spreadArray(to, from, pack) {
260
+ if (pack || arguments.length === 2)
261
+ for (var i = 0, l = from.length, ar; i < l; i++) {
262
+ if (ar || !(i in from)) {
263
+ if (!ar)
264
+ ar = Array.prototype.slice.call(from, 0, i);
265
+ ar[i] = from[i];
266
+ }
267
+ }
268
+ return to.concat(ar || from);
269
+ }
270
+ function __await(v) {
271
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
272
+ }
273
+ function __asyncGenerator(thisArg, _arguments, generator) {
274
+ if (!Symbol.asyncIterator)
275
+ throw new TypeError("Symbol.asyncIterator is not defined.");
276
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
277
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
278
+ function verb(n) { if (g[n])
279
+ i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
280
+ function resume(n, v) { try {
281
+ step(g[n](v));
282
+ }
283
+ catch (e) {
284
+ settle(q[0][3], e);
285
+ } }
286
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
287
+ function fulfill(value) { resume("next", value); }
288
+ function reject(value) { resume("throw", value); }
289
+ function settle(f, v) { if (f(v), q.shift(), q.length)
290
+ resume(q[0][0], q[0][1]); }
291
+ }
292
+ function __asyncDelegator(o) {
293
+ var i, p;
294
+ return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
295
+ function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
296
+ }
297
+ function __asyncValues(o) {
298
+ if (!Symbol.asyncIterator)
299
+ throw new TypeError("Symbol.asyncIterator is not defined.");
300
+ var m = o[Symbol.asyncIterator], i;
301
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
302
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
303
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
304
+ }
305
+ function __makeTemplateObject(cooked, raw) {
306
+ if (Object.defineProperty) {
307
+ Object.defineProperty(cooked, "raw", { value: raw });
308
+ }
309
+ else {
310
+ cooked.raw = raw;
311
+ }
312
+ return cooked;
313
+ }
314
+ ;
315
+ var __setModuleDefault = Object.create ? (function (o, v) {
316
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
317
+ }) : function (o, v) {
318
+ o["default"] = v;
319
+ };
320
+ function __importStar(mod) {
321
+ if (mod && mod.__esModule)
322
+ return mod;
323
+ var result = {};
324
+ if (mod != null)
325
+ for (var k in mod)
326
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
327
+ __createBinding(result, mod, k);
328
+ __setModuleDefault(result, mod);
329
+ return result;
330
+ }
331
+ function __importDefault(mod) {
332
+ return (mod && mod.__esModule) ? mod : { default: mod };
333
+ }
334
+ function __classPrivateFieldGet(receiver, state, kind, f) {
335
+ if (kind === "a" && !f)
336
+ throw new TypeError("Private accessor was defined without a getter");
337
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
338
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
339
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
340
+ }
341
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
342
+ if (kind === "m")
343
+ throw new TypeError("Private method is not writable");
344
+ if (kind === "a" && !f)
345
+ throw new TypeError("Private accessor was defined without a setter");
346
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
347
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
348
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
349
+ }
350
+
351
+ function createLoadEntitiesInitialState(previousInitialState, allConfigs) {
352
+ if (previousInitialState === void 0) { previousInitialState = {}; }
353
+ var traitConfig = allConfigs.loadEntities;
354
+ var adapter = traitConfig.adapter;
355
+ return Object.assign(Object.assign(Object.assign({}, previousInitialState), adapter.getInitialState()), { status: undefined });
356
+ }
357
+ function createLoadEntitiesTraitReducer(initialState, actions, allMutators, allConfigs) {
358
+ var handleEntitiesMerge = !(allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.pagination);
359
+ return i2.createReducer.apply(void 0, __spreadArray([initialState, i2.on(actions.loadEntities, function (state) { return (Object.assign(Object.assign({}, state), { status: 'loading' })); }), i2.on(actions.loadEntitiesFail, function (state) { return (Object.assign(Object.assign({}, state), { status: 'fail' })); }), i2.on(actions.loadEntitiesSuccess, function (state) { return (Object.assign(Object.assign({}, state), { status: 'success' })); })], __read(core.insertIf(handleEntitiesMerge, function () { return i2.on(actions.loadEntitiesSuccess, function (state, _a) {
360
+ var entities = _a.entities;
361
+ return allMutators.setEntitiesList(entities, Object.assign({}, state));
362
+ }); }))));
363
+ }
364
+
365
+ function createLoadEntitiesTraitMutators(allConfigs) {
366
+ var _a;
367
+ var adapter = (_a = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.loadEntities) === null || _a === void 0 ? void 0 : _a.adapter;
368
+ return {
369
+ setEntitiesList: adapter === null || adapter === void 0 ? void 0 : adapter.setAll,
370
+ };
371
+ }
372
+
373
+ function createLoadEntitiesTraitActions(actionsGroupKey, entitiesName) {
374
+ var actions = {
375
+ loadEntities: i2.createAction(actionsGroupKey + " Load " + entitiesName),
376
+ loadEntitiesSuccess: i2.createAction(actionsGroupKey + " Load " + entitiesName + " Success", i2.props()),
377
+ loadEntitiesFail: i2.createAction(actionsGroupKey + " Load " + entitiesName + " Fail", function (props) { return ({ error: props === null || props === void 0 ? void 0 : props.error }); }),
378
+ };
379
+ return actions;
380
+ }
381
+
382
+ function isLoading(state) {
383
+ return state.status === 'loading';
384
+ }
385
+ function isSuccess(state) {
386
+ return state.status === 'success';
387
+ }
388
+ function isFail(state) {
389
+ return state.status === 'fail';
390
+ }
391
+
392
+ function selectEntitiesFilter(state) {
393
+ return state.filters;
394
+ }
395
+ function createFilterTraitSelectors() {
396
+ return {
397
+ selectEntitiesFilter: selectEntitiesFilter,
398
+ };
399
+ }
400
+
401
+ function createLoadEntitiesTraitSelectors(allConfigs) {
402
+ var _a, _b;
403
+ var adapter = (_a = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.loadEntities) === null || _a === void 0 ? void 0 : _a.adapter;
404
+ var entitySelectors = adapter.getSelectors();
405
+ var filterFunction = (_b = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.filter) === null || _b === void 0 ? void 0 : _b.filterFn;
406
+ var selectors = {
407
+ selectEntitiesList: entitySelectors.selectAll,
408
+ selectEntitiesMap: entitySelectors.selectEntities,
409
+ selectEntitiesIdsList: entitySelectors.selectIds,
410
+ selectEntitiesTotal: entitySelectors.selectTotal,
411
+ isEntitiesLoadingFail: isFail,
412
+ isEntitiesLoading: isLoading,
413
+ isEntitiesLoadingSuccess: isSuccess,
414
+ };
415
+ if (filterFunction && entitySelectors) {
416
+ var selectEntitiesList = i2.createSelector(entitySelectors.selectAll, selectEntitiesFilter, function (entities, filters) { return filters ? entities.filter(function (e) { return filterFunction(filters, e); }) : entities; });
417
+ selectors = Object.assign(Object.assign({}, selectors), { selectEntitiesList: selectEntitiesList, selectEntitiesMap: i2.createSelector(selectors.selectEntitiesMap, selectEntitiesFilter, function (entities, filters) {
418
+ var result = {};
419
+ for (var id in entities) {
420
+ var e = entities[id];
421
+ if (filterFunction(filters, e)) {
422
+ result[id] = e;
423
+ }
424
+ }
425
+ return result;
426
+ }), selectEntitiesTotal: i2.createSelector(selectEntitiesList, function (entities) { return entities.length; }), selectEntitiesIdsList: i2.createSelector(selectEntitiesList, function (entities) { return entities.map(function (e) { return adapter === null || adapter === void 0 ? void 0 : adapter.selectId(e); }); }) });
427
+ }
428
+ return selectors;
429
+ }
430
+
431
+ /**
432
+ * Generates the ngrx code needed to load a list of entities from the backend
433
+ * with a load[EntitiesName], load[EntitiesName]Success, load[EntitiesName]Fail actions, and selectors to query the
434
+ * entities like selectEntity[EntitiesName]List, selectEntity[EntitiesName]Ids, selectEntity[EntitiesName]Map, and its progress loading
435
+ * with isLoading[EntitiesName],isLoading[EntitiesName]Success, isLoading[EntitiesName]Fail. This trait is the base for all other traits related
436
+ * to a list of entities, the other will call loadEntities when needing data.
437
+ * @param traitConfig - Config object fot the trait factory
438
+ * @param traitConfig.selectId - Function that returns the id of an entity
439
+ * @param traitConfig.sortComparer - Default sort function for to @ngrx/entity EntityAdapter
440
+ *
441
+ * @example
442
+ * // The following trait config
443
+ *
444
+ * export interface TestState
445
+ * extends LoadEntitiesState<Todo>{}
446
+ *
447
+ * const traits = createEntityFeatureFactory(
448
+ * {entityName: 'Todo'},
449
+ * addLoadEntitiesTrait<Todo>(),
450
+ * )({
451
+ * actionsGroupKey: '[Todos]',
452
+ * featureSelector: createFeatureSelector<TestState>>(
453
+ * 'todos',
454
+ * ),
455
+ * });
456
+ * // will generate the actions and selectors
457
+ * traits.actions.loadTodos()
458
+ * traits.actions.loadTodosSuccess({entities: todos})
459
+ * traits.actions.loadTodosFail();
460
+ * traits.selectors.selectTodosList
461
+ * traits.selectors.selectTodosMap
462
+ * traits.selectors.selectTodosIds
463
+ * traits.selectors.selectTodosTotal
464
+ * traits.selectors.isLoadingTodos
465
+ * traits.selectors.isSuccessTodosSuccess
466
+ * traits.selectors.isFailTodosFail
467
+ */
468
+ function addLoadEntitiesTrait(traitConfig) {
469
+ var adapter = entity.createEntityAdapter(traitConfig);
470
+ return core.createTraitFactory({
471
+ key: loadEntitiesTraitKey,
472
+ config: Object.assign(Object.assign({}, traitConfig), { adapter: adapter }),
473
+ actions: function (_a) {
474
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
475
+ return createLoadEntitiesTraitActions(actionsGroupKey, entitiesName);
476
+ },
477
+ selectors: function (_a) {
478
+ var allConfigs = _a.allConfigs;
479
+ return createLoadEntitiesTraitSelectors(allConfigs);
480
+ },
481
+ mutators: function (_a) {
482
+ var allConfigs = _a.allConfigs;
483
+ return createLoadEntitiesTraitMutators(allConfigs);
484
+ },
485
+ initialState: function (_a) {
486
+ var previousInitialState = _a.previousInitialState, allConfigs = _a.allConfigs;
487
+ return createLoadEntitiesInitialState(previousInitialState, allConfigs);
488
+ },
489
+ reducer: function (_a) {
490
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
491
+ return createLoadEntitiesTraitReducer(initialState, allActions, allMutators, allConfigs);
492
+ },
493
+ });
494
+ }
495
+
496
+ var entitiesPaginationTraitKey = 'pagination';
497
+
498
+ function createFilterTraitEffects(allActions, allSelectors, allConfigs) {
499
+ var traitConfig = allConfigs.filter;
500
+ var FilterEffect = /** @class */ (function (_super) {
501
+ __extends(FilterEffect, _super);
502
+ function FilterEffect() {
503
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
504
+ _this.storeFilter$ = i1.createEffect(function () { return function (_a) {
505
+ var _b = _a === void 0 ? {} : _a, _c = _b.debounce, debounceTime = _c === void 0 ? traitConfig.defaultDebounceTime : _c, _d = _b.scheduler, scheduler = _d === void 0 ? rxjs.asyncScheduler : _d;
506
+ return _this.actions$.pipe(i1.ofType(allActions.filterEntities), operators.debounce(function (value) { return (value === null || value === void 0 ? void 0 : value.forceLoad) ? rxjs.EMPTY : rxjs.timer(debounceTime, scheduler); }), operators.concatMap(function (payload) { return payload.patch
507
+ ? _this.store.select(allSelectors.selectEntitiesFilter).pipe(operators.first(), operators.map(function (storedFilters) { return (Object.assign(Object.assign({}, payload), { filters: Object.assign(Object.assign({}, storedFilters), payload === null || payload === void 0 ? void 0 : payload.filters) })); }))
508
+ : rxjs.of(payload); }), operators.distinctUntilChanged(function (previous, current) { return !(current === null || current === void 0 ? void 0 : current.forceLoad) &&
509
+ JSON.stringify(previous === null || previous === void 0 ? void 0 : previous.filters) ===
510
+ JSON.stringify(current === null || current === void 0 ? void 0 : current.filters); }), (traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.isRemoteFilter)
511
+ ? rxjs.pipe(operators.startWith({
512
+ filters: traitConfig.defaultFilter,
513
+ patch: false,
514
+ }), operators.pairwise(), operators.concatMap(function (_a) {
515
+ var _b = __read(_a, 2), previous = _b[0], current = _b[1];
516
+ return (traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.isRemoteFilter(previous === null || previous === void 0 ? void 0 : previous.filters, current === null || current === void 0 ? void 0 : current.filters))
517
+ ? [
518
+ allActions.storeEntitiesFilter({
519
+ filters: current === null || current === void 0 ? void 0 : current.filters,
520
+ patch: current === null || current === void 0 ? void 0 : current.patch,
521
+ }),
522
+ allActions.loadEntities(),
523
+ ]
524
+ : [
525
+ allActions.storeEntitiesFilter({
526
+ filters: current === null || current === void 0 ? void 0 : current.filters,
527
+ patch: current === null || current === void 0 ? void 0 : current.patch,
528
+ }),
529
+ ];
530
+ }))
531
+ : operators.map(function (action) { return allActions.storeEntitiesFilter({
532
+ filters: action === null || action === void 0 ? void 0 : action.filters,
533
+ patch: action === null || action === void 0 ? void 0 : action.patch,
534
+ }); }));
535
+ }; });
536
+ _this.loadEntities$ = (!(traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.filterFn) || (traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.isRemoteFilter)) &&
537
+ i1.createEffect(function () {
538
+ return _this.actions$.pipe(i1.ofType(allActions['storeEntitiesFilter']), operators.concatMap(function () { return (allActions === null || allActions === void 0 ? void 0 : allActions.loadEntitiesFirstPage)
539
+ ? [
540
+ allActions.clearEntitiesPagesCache(),
541
+ allActions.loadEntitiesFirstPage(),
542
+ ]
543
+ : [allActions.loadEntities()]; }));
544
+ });
545
+ return _this;
546
+ }
547
+ return FilterEffect;
548
+ }(core.TraitEffect));
549
+ FilterEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: FilterEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
550
+ FilterEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: FilterEffect });
551
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: FilterEffect, decorators: [{
552
+ type: i0.Injectable
553
+ }] });
554
+ return [FilterEffect];
555
+ }
556
+
557
+ function createFilterInitialState(previousInitialState, allConfigs) {
558
+ var _a;
559
+ return Object.assign(Object.assign({}, previousInitialState), { filters: (_a = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.filter) === null || _a === void 0 ? void 0 : _a.defaultFilter });
560
+ }
561
+ function createFilterTraitReducer(initialState, allActions, allMutators) {
562
+ return i2.createReducer(initialState, i2.on(allActions.storeEntitiesFilter, function (state, _b) {
563
+ var filters = _b.filters;
564
+ return allMutators.setEntitiesFilters(filters, state);
565
+ }));
566
+ }
567
+
568
+ var filterEntitiesTraitKey = 'filter';
569
+
570
+ function createFilterTraitMutators() {
571
+ function setEntitiesFilters(filters, state) {
572
+ return Object.assign(Object.assign({}, state), { filters: filters });
573
+ }
574
+ return { setEntitiesFilters: setEntitiesFilters };
575
+ }
576
+
577
+ function createFilterTraitActions(actionsGroupKey, entitiesName) {
578
+ var actions = {
579
+ filterEntities: i2.createAction(actionsGroupKey + " Filter " + entitiesName, function (props) { return ({
580
+ filters: props === null || props === void 0 ? void 0 : props.filters,
581
+ forceLoad: props === null || props === void 0 ? void 0 : props.forceLoad,
582
+ patch: props === null || props === void 0 ? void 0 : props.patch,
583
+ }); }),
584
+ storeEntitiesFilter: i2.createAction(actionsGroupKey + " Store " + entitiesName + " Filter", function (props) { return ({
585
+ filters: props === null || props === void 0 ? void 0 : props.filters,
586
+ patch: props === null || props === void 0 ? void 0 : props.patch,
587
+ }); }),
588
+ };
589
+ return actions;
590
+ }
591
+
592
+ /**
593
+ * Generates the ngrx code needed to filter a list of entities locally or remotely, adds a filter
594
+ * action and a selectFilter selector, the filter action is debounced and the filter will only
595
+ * call the loadEntities action if the params have changed, so there is no need to implement that in
596
+ * the components. The filter action has a `forceLoad` param which can
597
+ * be use to skip that restriction for one call or setting the `defaultDebounceTime` to 0 for all calls.
598
+ * Calling the filter action will also replace the `filters` param in the store, if the `patch` param is set
599
+ * the filters are merged with the previous value in the store.
600
+ * @param traitConfig - Config object fot the trait factory
601
+ * @param traitConfig.defaultFilter - Initial value for the filter
602
+ * @param traitConfig.filterFn - Function to filter entities in memory, if not present then its expected
603
+ * is filtered by the backend unless isRemoteFilter is defned
604
+ * @param traitConfig.defaultDebounceTime - Value in milliseconds. Default to 400ms
605
+ * @param traitConfig.isRemoteFilter - Function to when it returns true it fires loadEntities so a remote
606
+ * backend filtering can run, otherwise it uses filterFn to do a local filtering
607
+ *
608
+ * @example
609
+ * // The following trait config
610
+ *
611
+ * export interface TestState
612
+ * extends EntityAndStatusState<Todo>,FilterState<TodoFilter>{}
613
+ *
614
+ * const traits = createEntityFeatureFactory(
615
+ * addLoadEntitiesTrait<Todo>(),
616
+ * //addFilterEntitiesTrait<Todo,TodoFilter>() // no params uses remote filtering
617
+ * addFilterEntitiesTrait<Todo,TodoFilter>({filterFn: (filter, entity) => // local filtering
618
+ * filter?.content && entity.content?.includes(filter?.content) || false})
619
+ * // or use the following function to switch between remote search and local
620
+ * // depending on which properties have changed in the filter
621
+ * // isRemoteFilter: (previous, current) => previous?.someRemoteParam !== current?.someRemoteParam,
622
+ * )({
623
+ * actionsGroupKey: '[Todos]',
624
+ * featureSelector: createFeatureSelector<TestState>>(
625
+ * 'todos',
626
+ * ),
627
+ * });
628
+ * // will generate the following actions and selectors, plus the ones generated by other traits
629
+ * traits.actions.filterTodos()
630
+ * traits.selectors.selectTodosFilter()
631
+ */
632
+ function addFilterEntitiesTrait(_a) {
633
+ var _b = _a === void 0 ? {} : _a, _c = _b.defaultDebounceTime, defaultDebounceTime = _c === void 0 ? 400 : _c, defaultFilter = _b.defaultFilter, filterFn = _b.filterFn, isRemoteFilter = _b.isRemoteFilter;
634
+ return core.createTraitFactory({
635
+ key: filterEntitiesTraitKey,
636
+ depends: [entitiesPaginationTraitKey, loadEntitiesTraitKey],
637
+ config: {
638
+ defaultDebounceTime: defaultDebounceTime,
639
+ defaultFilter: defaultFilter,
640
+ filterFn: filterFn,
641
+ isRemoteFilter: isRemoteFilter,
642
+ },
643
+ actions: function (_a) {
644
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
645
+ return createFilterTraitActions(actionsGroupKey, entitiesName);
646
+ },
647
+ selectors: function () { return createFilterTraitSelectors(); },
648
+ mutators: function () { return createFilterTraitMutators(); },
649
+ initialState: function (_a) {
650
+ var previousInitialState = _a.previousInitialState, allConfigs = _a.allConfigs;
651
+ return createFilterInitialState(previousInitialState, allConfigs);
652
+ },
653
+ reducer: function (_a) {
654
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators;
655
+ return createFilterTraitReducer(initialState, allActions, allMutators);
656
+ },
657
+ effects: function (_a) {
658
+ var allActions = _a.allActions, allSelectors = _a.allSelectors, allConfigs = _a.allConfigs;
659
+ return createFilterTraitEffects(allActions, allSelectors, allConfigs);
660
+ },
661
+ });
662
+ }
663
+
664
+ function createPaginationTraitSelectors(previousSelectors, allConfigs) {
665
+ var _a;
666
+ var selectEntitiesList = previousSelectors.selectEntitiesList, isEntitiesLoading = previousSelectors.isEntitiesLoading;
667
+ var filterFunction = (_a = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.filter) === null || _a === void 0 ? void 0 : _a.filterFn;
668
+ function selectPagination(state) {
669
+ return state.pagination;
670
+ }
671
+ var selectPaginationFiltered = filterFunction
672
+ ? i2.createSelector(selectEntitiesList, selectPagination, function (entities, pagination) {
673
+ return Object.assign(Object.assign({}, pagination), { total: entities.length, cache: Object.assign(Object.assign({}, pagination.cache), { start: 0, end: entities.length }) });
674
+ })
675
+ : selectPagination;
676
+ var selectPageEntitiesList = i2.createSelector(selectEntitiesList, selectPaginationFiltered, function (entities, pagination, _b) {
677
+ var _c = _b === void 0 ? { page: pagination.currentPage } : _b, page = _c.page;
678
+ var startIndex = page * pagination.pageSize - pagination.cache.start;
679
+ var endIndex = startIndex + pagination.pageSize;
680
+ endIndex =
681
+ endIndex < pagination.cache.end ? endIndex : pagination.cache.end;
682
+ return entities.slice(startIndex, endIndex);
683
+ });
684
+ var selectEntitiesPageInfo = i2.createSelector(selectPaginationFiltered, function (pagination) {
685
+ var pagesCount = pagination.total && pagination.total > 0
686
+ ? Math.ceil(pagination.total / pagination.pageSize)
687
+ : undefined;
688
+ return {
689
+ pageIndex: pagination.currentPage,
690
+ total: pagination.total,
691
+ pageSize: pagination.pageSize,
692
+ pagesCount: pagesCount,
693
+ hasPrevious: pagination.currentPage - 1 >= 0,
694
+ hasNext: pagination.total && pagination.total > 0
695
+ ? pagination.currentPage + 1 < pagesCount
696
+ : true,
697
+ cacheType: pagination.cache.type,
698
+ };
699
+ });
700
+ var isEntitiesPageInCache = i2.createSelector(selectPaginationFiltered, function (pagination, _b) {
701
+ var _c = _b === void 0 ? { page: pagination.currentPage } : _b, page = _c.page;
702
+ var startIndex = page * pagination.pageSize;
703
+ var endIndex = startIndex + pagination.pageSize - 1;
704
+ endIndex =
705
+ pagination.total && endIndex > pagination.total
706
+ ? pagination.total - 1
707
+ : endIndex;
708
+ return (startIndex >= pagination.cache.start && endIndex <= pagination.cache.end);
709
+ });
710
+ var selectEntitiesPage = i2.createSelector(selectPageEntitiesList, selectEntitiesPageInfo,
711
+ // props look unsued but they are pass to the selectPageEntities
712
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
713
+ function (entities, pageInfo, props) {
714
+ if (props === void 0) { props = { page: pageInfo.pageIndex }; }
715
+ return (Object.assign({ entities: entities }, pageInfo));
716
+ });
717
+ var selectEntitiesPagedRequest = i2.createSelector(selectPagination, function (pagination) { return ({
718
+ startIndex: pagination.pageSize * pagination.requestPage,
719
+ size: pagination.pageSize * pagination.pagesToCache,
720
+ page: pagination.requestPage,
721
+ }); });
722
+ var isLoadingEntitiesPage = i2.createSelector(isEntitiesLoading, selectPagination, function (isLoading, pagination) { return isLoading && pagination.requestPage === pagination.currentPage; });
723
+ return {
724
+ selectPageEntitiesList: selectPageEntitiesList,
725
+ isEntitiesPageInCache: isEntitiesPageInCache,
726
+ selectEntitiesPage: selectEntitiesPage,
727
+ selectEntitiesPagedRequest: selectEntitiesPagedRequest,
728
+ selectEntitiesPageInfo: selectEntitiesPageInfo,
729
+ isLoadingEntitiesPage: isLoadingEntitiesPage,
730
+ };
731
+ }
732
+
733
+ function createPaginationTraitActions(actionsGroupKey, entitiesName) {
734
+ var actions = {
735
+ loadEntitiesPage: i2.createAction(actionsGroupKey + " Load " + entitiesName + " Page", function (_a) {
736
+ var index = _a.index, forceLoad = _a.forceLoad;
737
+ return ({
738
+ index: index,
739
+ forceLoad: forceLoad,
740
+ });
741
+ }),
742
+ loadEntitiesPageSuccess: i2.createAction(actionsGroupKey + " Load " + entitiesName + "\n Page Success"),
743
+ loadEntitiesPageFail: i2.createAction(actionsGroupKey + " Load " + entitiesName + " Page Fail"),
744
+ loadEntitiesPreviousPage: i2.createAction(actionsGroupKey + " Load Previous " + entitiesName + " Page"),
745
+ loadEntitiesNextPage: i2.createAction(actionsGroupKey + " Load Next " + entitiesName + " Page"),
746
+ loadEntitiesFirstPage: i2.createAction(actionsGroupKey + " Load First " + entitiesName + " Page", function (forceLoad) { return ({ forceLoad: forceLoad }); }),
747
+ loadEntitiesLastPage: i2.createAction(actionsGroupKey + " Load Last " + entitiesName + " Page"),
748
+ clearEntitiesPagesCache: i2.createAction(actionsGroupKey + " Clear " + entitiesName + " Cache"),
749
+ setEntitiesRequestPage: i2.createAction(actionsGroupKey + " Set " + entitiesName + " Request Page", i2.props()),
750
+ };
751
+ return actions;
752
+ }
753
+
754
+ function createPaginationInitialState(previousInitialState, allConfigs) {
755
+ var _b = allConfigs.pagination, currentPage = _b.currentPage, pageSize = _b.pageSize, cacheType = _b.cacheType, pagesToCache = _b.pagesToCache;
756
+ return Object.assign(Object.assign({}, previousInitialState), { pagination: {
757
+ pageSize: pageSize,
758
+ currentPage: currentPage,
759
+ requestPage: currentPage,
760
+ pagesToCache: pagesToCache,
761
+ cache: {
762
+ type: cacheType,
763
+ start: 0,
764
+ end: 0,
765
+ },
766
+ } });
767
+ }
768
+ function createPaginationTraitReducer(initialState, allActions, allSelectors, allMutators, allConfigs) {
769
+ var _a;
770
+ function addToCacheTotal(state, add) {
771
+ var _a;
772
+ return Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { total: ((_a = state.pagination.total) !== null && _a !== void 0 ? _a : 0) + add }) });
773
+ }
774
+ function clearPagesCache(state) {
775
+ return Object.assign(Object.assign({}, state), { entities: {}, ids: [], pagination: Object.assign(Object.assign({}, state.pagination), { currentPage: 0, total: 0, cache: Object.assign(Object.assign({}, state.pagination.cache), { start: 0, end: 0 }) }) });
776
+ }
777
+ function recalculateTotal(state) {
778
+ var total = allSelectors.selectEntitiesTotal(state);
779
+ return Object.assign(Object.assign({}, state), { status: 'success', pagination: Object.assign(Object.assign({}, state.pagination), { currentPage: 0, total: total, cache: Object.assign(Object.assign({}, state.pagination.cache), { start: 0, end: total }) }) });
780
+ }
781
+ var filterRemote = !((_a = allConfigs === null || allConfigs === void 0 ? void 0 : allConfigs.filter) === null || _a === void 0 ? void 0 : _a.filterFn);
782
+ return i2.createReducer.apply(void 0, __spreadArray(__spreadArray(__spreadArray(__spreadArray([initialState, i2.on(allActions.loadEntitiesPage, function (state, _b) {
783
+ var index = _b.index;
784
+ return (Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { currentPage: index, requestPage: index }), status: 'loading' }));
785
+ }), i2.on(allActions.setEntitiesRequestPage, function (state, _b) {
786
+ var index = _b.index;
787
+ return (Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { requestPage: index }), status: 'loading' }));
788
+ }), i2.on(allActions.loadEntitiesPageSuccess, function (state) { return (Object.assign(Object.assign({}, state), { status: 'success' })); }), i2.on(allActions.loadEntitiesPageFail, function (state) { return (Object.assign(Object.assign({}, state), { status: 'fail' })); }), i2.on(allActions.clearEntitiesPagesCache, function (state) { return clearPagesCache(state); }), i2.on(allActions.loadEntitiesSuccess, function (state, _b) {
789
+ var entities = _b.entities, total = _b.total;
790
+ return allMutators.mergePaginatedEntities(entities, total, Object.assign(Object.assign({}, state), { status: 'success' }));
791
+ })], __read(core.insertIf(allActions.addEntities, function () { return i2.on(allActions.addEntities, function (state, _b) {
792
+ var entities = _b.entities;
793
+ return addToCacheTotal(state, entities.length);
794
+ }); }))), __read(core.insertIf(allActions.removeEntities, function () { return i2.on(allActions.removeEntities, function (state, _b) {
795
+ var keys = _b.keys;
796
+ return addToCacheTotal(state, -keys.length);
797
+ }); }))), __read(core.insertIf(filterRemote && allActions.filterEntities, function () { return i2.on(allActions.filterEntities, function (state) { return recalculateTotal(state); }); }))), __read(core.insertIf(allActions.removeAllEntities, function () { return i2.on(allActions.removeAllEntities, function (state) { return clearPagesCache(state); }); }))));
798
+ }
799
+
800
+ function createPaginationTraitEffects(allActions, allSelectors) {
801
+ var PaginationEffect = /** @class */ (function (_super) {
802
+ __extends(PaginationEffect, _super);
803
+ function PaginationEffect() {
804
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
805
+ _this.loadPage$ = i1.createEffect(function () {
806
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesPage), i1.concatLatestFrom(function () { return _this.store.select(allSelectors.isEntitiesPageInCache); }), operators.map(function (_a) {
807
+ var _b = __read(_a, 2), forceLoad = _b[0].forceLoad, isInCache = _b[1];
808
+ return !forceLoad && isInCache
809
+ ? allActions.loadEntitiesPageSuccess()
810
+ : allActions.loadEntities();
811
+ }));
812
+ });
813
+ _this.preloadNextPage$ = i1.createEffect(function () {
814
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesPageSuccess), operators.concatMapTo(_this.store.select(allSelectors.selectEntitiesPageInfo).pipe(operators.first())), operators.filter(function (pageInfo) { return !!pageInfo.total &&
815
+ pageInfo.hasNext &&
816
+ pageInfo.cacheType !== 'full'; }), operators.concatMap(function (pageInfo) { return _this.store
817
+ .select(allSelectors.isEntitiesPageInCache, {
818
+ page: pageInfo.pageIndex + 1,
819
+ })
820
+ .pipe(operators.first(), operators.map(function (isInCache) { return (!isInCache && pageInfo) || undefined; })); }), operators.filter(function (pageInfo) { return !!pageInfo; }), operators.concatMap(function (pageInfo) { return [
821
+ allActions.setEntitiesRequestPage({ index: pageInfo.pageIndex + 1 }),
822
+ allActions.loadEntities(),
823
+ ]; }));
824
+ });
825
+ _this.loadFirstPage$ = i1.createEffect(function () {
826
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesFirstPage), operators.map(function () { return allActions.loadEntitiesPage({ index: 0 }); }));
827
+ });
828
+ _this.loadPreviousPage$ = i1.createEffect(function () {
829
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesPreviousPage), operators.concatMapTo(_this.store.select(allSelectors.selectEntitiesPageInfo).pipe(operators.first())), operators.map(function (page) { return page.hasPrevious
830
+ ? allActions.loadEntitiesPage({ index: page.pageIndex - 1 })
831
+ : allActions.loadEntitiesPageFail(); }));
832
+ });
833
+ _this.loadNextPage$ = i1.createEffect(function () {
834
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesNextPage), operators.concatMapTo(_this.store.select(allSelectors.selectEntitiesPageInfo).pipe(operators.first())), operators.map(function (page) { return page.hasNext
835
+ ? allActions.loadEntitiesPage({ index: page.pageIndex + 1 })
836
+ : allActions.loadEntitiesPageFail(); }));
837
+ });
838
+ _this.loadLastPage$ = i1.createEffect(function () {
839
+ return _this.actions$.pipe(i1.ofType(allActions.loadEntitiesLastPage), operators.concatMapTo(_this.store.select(allSelectors.selectEntitiesPageInfo).pipe(operators.first())), operators.map(function (page) { return page.hasNext && page.pagesCount
840
+ ? allActions.loadEntitiesPage({ index: page.pagesCount - 1 })
841
+ : allActions.loadEntitiesPageFail(); }));
842
+ });
843
+ return _this;
844
+ }
845
+ return PaginationEffect;
846
+ }(core.TraitEffect));
847
+ PaginationEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: PaginationEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
848
+ PaginationEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: PaginationEffect });
849
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: PaginationEffect, decorators: [{
850
+ type: i0.Injectable
851
+ }] });
852
+ return [PaginationEffect];
853
+ }
854
+
855
+ function createPaginationTraitMutators(allSelectors, allConfigs) {
856
+ var adapter = allConfigs.loadEntities.adapter;
857
+ function mergePaginatedEntities(entities, total, state) {
858
+ if (total === void 0) { total = undefined; }
859
+ var cacheType = state.pagination.cache.type;
860
+ switch (cacheType) {
861
+ case 'full':
862
+ return adapter.setAll(entities, Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { total: entities.length, cache: Object.assign(Object.assign({}, state.pagination.cache), { start: 0, end: entities.length }) }) }));
863
+ case 'partial': {
864
+ var isPreloadNextPages = state.pagination.currentPage + 1 === state.pagination.requestPage;
865
+ var start = state.pagination.currentPage * state.pagination.pageSize;
866
+ var newEntities = isPreloadNextPages
867
+ ? __spreadArray(__spreadArray([], __read(allSelectors.selectPageEntitiesList(state))), __read(entities)) : entities;
868
+ return adapter.setAll(newEntities, Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { total: total, cache: Object.assign(Object.assign({}, state.pagination.cache), { start: start, end: start + entities.length }) }) }));
869
+ }
870
+ case 'grow':
871
+ return adapter.addMany(entities, Object.assign(Object.assign({}, state), { pagination: Object.assign(Object.assign({}, state.pagination), { total: total, cache: Object.assign(Object.assign({}, state.pagination.cache), { end: state.ids.length + entities.length }) }) }));
872
+ }
873
+ return state;
874
+ }
875
+ return { mergePaginatedEntities: mergePaginatedEntities };
876
+ }
877
+
878
+ /**
879
+ * Generates ngrx code to paginate an list of entities, this has 3 cache `cacheType`
880
+ * - 'full': The full result is cache in memory and split in pages to render, useful
881
+ * for small result but not so small that requires been render in pages
882
+ * - 'partial': Backend returns partial results because is are to big, this has a cache a few pages forward
883
+ * to avoid calling the backend on each page, the cache is clean when a new loadEntities is required
884
+ * - 'grow': Similar to partial that the backend returns partial result, but in this case the cache grows,
885
+ * after each loadEntities the cache is appended to the previous cache, this mode is ideal for infinite scrolls,
886
+ * where you will only call loadNextPage.
887
+ * To make the pagination experience smoother the loadEntities to get new pages is done when the current page is change to
888
+ * the last cached page.
889
+ * @param config
890
+ * @param config.cacheType - Default to 'full', change the cache mode
891
+ * @param config.pageSize - Default to 20, number of entities on each page
892
+ * @param config.currentPage - Default to 0, starting page
893
+ * @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of
894
+ * extra pages kept in cache to avoid calling the backend on each page
895
+ *
896
+ * @example
897
+ * // The following trait config
898
+ *
899
+ * export interface TestState
900
+ * extends EntityAndStatusState<Todo>,SingleSelectionState{}
901
+ *
902
+ * const traits = createEntityFeatureFactory(
903
+ * addLoadEntitiesTrait<Todo>(),
904
+ * addEntitiesPaginationTrait<Todo>()
905
+ * )({
906
+ * actionsGroupKey: '[Todos]',
907
+ * featureSelector: createFeatureSelector<TestState>>(
908
+ * 'todos',
909
+ * ),
910
+ * });
911
+ * // will generate the following actions and selectors, plus the ones generated by other traits
912
+ * traits.actions.loadTodosPage({index})
913
+ * traits.actions.loadTodosPageSuccess()
914
+ * traits.actions.loadTodosPageFail()
915
+ * traits.actions.loadTodosNextPage()
916
+ * traits.actions.loadTodosPreviousPage()
917
+ * traits.actions.loadTodosFirstPage()
918
+ * traits.actions.loadTodosLastPage()
919
+ * traits.actions.clearTodosPagesCache()
920
+ *
921
+ * // page param is optional and defaults to current page
922
+ * traits.selectors.isTodosPageInCache({page})
923
+ * traits.selectors.selectPageTodosList({page})
924
+ * traits.selectors.isLoadingTodosPage({page})
925
+ * // prefer isLoadingTodosPage over isLoadingTodos which will return true even
926
+ * // if the page loading is not the current one
927
+ * traits.selectors.selectTodosPage({page})
928
+ * traits.selectors.selectTodosPagedRequest()// use in effects to get paging parameter
929
+ * traits.selectors.selectTodosPageInfo()
930
+ */
931
+ function addEntitiesPaginationTrait(_a) {
932
+ var _b = _a === void 0 ? {} : _a, _c = _b.cacheType, cacheType = _c === void 0 ? 'full' : _c, _d = _b.pageSize, pageSize = _d === void 0 ? 20 : _d, _e = _b.currentPage, currentPage = _e === void 0 ? 0 : _e, _f = _b.pagesToCache, pagesToCache = _f === void 0 ? 3 : _f;
933
+ return core.createTraitFactory({
934
+ key: entitiesPaginationTraitKey,
935
+ depends: [loadEntitiesTraitKey],
936
+ config: {
937
+ cacheType: cacheType,
938
+ pageSize: pageSize,
939
+ currentPage: currentPage,
940
+ pagesToCache: pagesToCache,
941
+ },
942
+ actions: function (_a) {
943
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
944
+ return createPaginationTraitActions(actionsGroupKey, entitiesName);
945
+ },
946
+ selectors: function (_a) {
947
+ var previousSelectors = _a.previousSelectors, allConfigs = _a.allConfigs;
948
+ return createPaginationTraitSelectors(previousSelectors, allConfigs);
949
+ },
950
+ mutators: function (_a) {
951
+ var allSelectors = _a.allSelectors, allConfigs = _a.allConfigs;
952
+ return createPaginationTraitMutators(allSelectors, allConfigs);
953
+ },
954
+ initialState: function (_a) {
955
+ var previousInitialState = _a.previousInitialState, allConfigs = _a.allConfigs;
956
+ return createPaginationInitialState(previousInitialState, allConfigs);
957
+ },
958
+ reducer: function (_a) {
959
+ var initialState = _a.initialState, allActions = _a.allActions, allSelectors = _a.allSelectors, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
960
+ return createPaginationTraitReducer(initialState, allActions, allSelectors, allMutators, allConfigs);
961
+ },
962
+ effects: function (_a) {
963
+ var allActions = _a.allActions, allSelectors = _a.allSelectors;
964
+ return createPaginationTraitEffects(allActions, allSelectors);
965
+ },
966
+ });
967
+ }
968
+
969
+ function createSelectEntitiesTraitActions(actionsGroupKey, entitiesName) {
970
+ return {
971
+ selectEntities: i2.createAction(actionsGroupKey + " Select " + entitiesName, i2.props()),
972
+ deselectEntities: i2.createAction(actionsGroupKey + " Deselect " + entitiesName, i2.props()),
973
+ toggleSelectEntities: i2.createAction(actionsGroupKey + " Toggle Select " + entitiesName, i2.props()),
974
+ toggleSelectAllEntities: i2.createAction(actionsGroupKey + " Toggle Select All " + entitiesName),
975
+ clearEntitiesSelection: i2.createAction(actionsGroupKey + " Clear " + entitiesName + " Selection"),
976
+ };
977
+ }
978
+
979
+ function deselectEntities(id, state) {
980
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
981
+ var _a = state.selectedIds, _b = id, _value = _a[_b], selectedIds = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
982
+ return Object.assign(Object.assign({}, state), { selectedIds: selectedIds });
983
+ }
984
+ function selectEntities(id, state) {
985
+ var _c;
986
+ return Object.assign(Object.assign({}, state), { selectedIds: Object.assign(Object.assign({}, state.selectedIds), (_c = {}, _c[id] = true, _c)) });
987
+ }
988
+ function toggleSelectEntities(id, state) {
989
+ var selected = state.selectedIds[id];
990
+ if (selected) {
991
+ return deselectEntities(id, state);
992
+ }
993
+ else {
994
+ return selectEntities(id, state);
995
+ }
996
+ }
997
+ function clearEntitiesSelection(state) {
998
+ return Object.assign(Object.assign({}, state), { selectedIds: {} });
999
+ }
1000
+ function selectTotalSelectedEntities(state) {
1001
+ return Object.keys(state.selectedIds).length;
1002
+ }
1003
+
1004
+ function createSelectEntitiesTraitSelectors(previousSelectors) {
1005
+ var selectEntitiesMap = previousSelectors.selectEntitiesMap, selectEntitiesTotal = previousSelectors.selectEntitiesTotal;
1006
+ function selectEntitiesIdsSelectedMap(state) {
1007
+ return state.selectedIds;
1008
+ }
1009
+ var selectEntitiesIdsSelectedList = i2.createSelector(selectEntitiesIdsSelectedMap, function (ids) { return Object.keys(ids); });
1010
+ var selectEntitiesSelectedMap = i2.createSelector(selectEntitiesIdsSelectedList, selectEntitiesMap, function (selectedIds, entities) { return selectedIds.reduce(function (acum, id) {
1011
+ acum[id] = entities[id];
1012
+ return acum;
1013
+ }, {}); });
1014
+ var selectEntitiesSelectedList = i2.createSelector(selectEntitiesIdsSelectedList, selectEntitiesMap, function (selectedIds, entities) { return selectedIds.map(function (id) { return entities[id]; }); });
1015
+ var isAllEntitiesSelected = i2.createSelector(function (state) { return selectEntitiesTotal(state); }, selectTotalSelectedEntities, function (total, totalSelected) { return totalSelected > 0 && totalSelected === total
1016
+ ? 'all'
1017
+ : totalSelected === 0
1018
+ ? 'none'
1019
+ : 'some'; });
1020
+ return {
1021
+ selectEntitiesIdsSelectedMap: selectEntitiesIdsSelectedMap,
1022
+ selectEntitiesIdsSelectedList: selectEntitiesIdsSelectedList,
1023
+ selectEntitiesSelectedMap: selectEntitiesSelectedMap,
1024
+ selectEntitiesSelectedList: selectEntitiesSelectedList,
1025
+ selectTotalSelectedEntities: selectTotalSelectedEntities,
1026
+ isAllEntitiesSelected: isAllEntitiesSelected,
1027
+ };
1028
+ }
1029
+
1030
+ function createSelectEntitiesInitialState(previousInitialState) {
1031
+ return Object.assign(Object.assign({}, previousInitialState), { selectedIds: {} });
1032
+ }
1033
+ function createSelectEntitiesTraitReducer(initialState, allActions, allMutators, allConfigs) {
1034
+ var _a, _b;
1035
+ var adapter = allConfigs.loadEntities.adapter;
1036
+ var sortRemote = (_a = allConfigs.sort) === null || _a === void 0 ? void 0 : _a.remote;
1037
+ var paginationCacheType = (_b = allConfigs.pagination) === null || _b === void 0 ? void 0 : _b.cacheType;
1038
+ function updateSelectedIdsChanged(state, updates) {
1039
+ var changedIds = updates.reduce(function (acc, updated) {
1040
+ var id = adapter.selectId(updated.changes);
1041
+ if (id && id !== updated.id && state.selectedIds[updated.id] != null) {
1042
+ acc.push(updated);
1043
+ return acc;
1044
+ }
1045
+ return acc;
1046
+ }, []);
1047
+ if (changedIds.length) {
1048
+ var selectedIds_1 = Object.assign({}, state.selectedIds);
1049
+ changedIds.forEach(function (updated) {
1050
+ var id = adapter.selectId(updated.changes);
1051
+ var value = selectedIds_1[updated.id];
1052
+ delete selectedIds_1[updated.id];
1053
+ selectedIds_1[id] = value;
1054
+ });
1055
+ return Object.assign(Object.assign({}, state), { selectedIds: selectedIds_1 });
1056
+ }
1057
+ return state;
1058
+ }
1059
+ return i2.createReducer.apply(void 0, __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([initialState, i2.on(allActions.selectEntities, function (state, _c) {
1060
+ var id = _c.id;
1061
+ return allMutators.selectEntities(id, state);
1062
+ }), i2.on(allActions.deselectEntities, function (state, _c) {
1063
+ var id = _c.id;
1064
+ return allMutators.deselectEntities(id, state);
1065
+ }), i2.on(allActions.toggleSelectEntities, function (state, _c) {
1066
+ var id = _c.id;
1067
+ return allMutators.toggleSelectEntities(id, state);
1068
+ }), i2.on(allActions.toggleSelectAllEntities, function (state) { return allMutators.toggleSelectAllEntities(state); })], __read(core.insertIf(allActions.removeEntities, function () { return i2.on(allActions.removeEntities, function (state, _c) {
1069
+ var keys = _c.keys;
1070
+ var selectedIds = Object.assign({}, state.selectedIds);
1071
+ keys.forEach(function (v) {
1072
+ delete selectedIds[v];
1073
+ });
1074
+ return Object.assign(Object.assign({}, state), { selectedIds: selectedIds });
1075
+ }); }))), __read(core.insertIf(allActions.updateEntities, function () { return i2.on(allActions.updateEntities, function (state, _c) {
1076
+ var updates = _c.updates;
1077
+ return updateSelectedIdsChanged(state, updates);
1078
+ }); }))), [i2.on(allActions.clearEntitiesSelection, function (state) { return allMutators.clearEntitiesSelection(state); })]), __read(core.insertIf(allActions.removeAllEntities, function () { return i2.on(allActions.removeAllEntities, function (state) { return allMutators.clearEntitiesSelection(state); }); }))), __read(core.insertIf(sortRemote, function () { return i2.on(allActions.sortEntities, function (state) { return allMutators.clearEntitiesSelection(state); }); }))), __read(core.insertIf(allActions.filterEntities, function () { return i2.on(allActions.filterEntities, function (state) { return allMutators.clearEntitiesSelection(state); }); }))), __read(core.insertIf(!allActions.loadEntitiesPageSuccess, function () { return i2.on(allActions.loadEntitiesSuccess, function (state) { return allMutators.clearEntitiesSelection(state); }); }))), __read(core.insertIf(!!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial', function () { return i2.on(allActions.loadEntitiesPageSuccess, function (state) { return allMutators.clearEntitiesSelection(state); }); }))));
1079
+ }
1080
+
1081
+ function createSelectEntitiesTraitMutators(_a) {
1082
+ var isAllEntitiesSelected = _a.isAllEntitiesSelected;
1083
+ function toggleSelectAllEntities(state) {
1084
+ var allSelected = isAllEntitiesSelected(state);
1085
+ if (allSelected === 'all') {
1086
+ return Object.assign(Object.assign({}, state), { selectedIds: {} });
1087
+ }
1088
+ else {
1089
+ return Object.assign(Object.assign({}, state), { selectedIds: core.toMap(state.ids) });
1090
+ }
1091
+ }
1092
+ return {
1093
+ selectEntities: selectEntities,
1094
+ deselectEntities: deselectEntities,
1095
+ toggleSelectEntities: toggleSelectEntities,
1096
+ toggleSelectAllEntities: toggleSelectAllEntities,
1097
+ clearEntitiesSelection: clearEntitiesSelection,
1098
+ };
1099
+ }
1100
+
1101
+ /**
1102
+ * Generates ngrx code to add multi selection to a list
1103
+ *
1104
+ * @example
1105
+ * // The following trait config
1106
+ *
1107
+ * export interface TestState
1108
+ * extends EntityAndStatusState<Todo>,MultipleSelectionState{}
1109
+ *
1110
+ * const traits = createEntityFeatureFactory(
1111
+ * addLoadEntitiesTrait<Todo>(),
1112
+ * addSelectEntitiesTrait<Todo>()
1113
+ * )({
1114
+ * actionsGroupKey: '[Todos]',
1115
+ * featureSelector: createFeatureSelector<TestState>>(
1116
+ * 'todos',
1117
+ * ),
1118
+ * });
1119
+ * // will generate the following actions and selectors, plus the ones generated by other traits
1120
+ * traits.actions.selectTodos({id})
1121
+ * traits.actions.deselectTodos({id})
1122
+ * traits.actions.toggleSectTodos({id})
1123
+ * traits.actions.toggleSelectAllTodos()
1124
+ * traits.actions.clearTodosSelection()
1125
+ *
1126
+ * traits.selectors.isAllTodosSelected()
1127
+ * traits.selectors.selectTodosIdsSelectedMap()
1128
+ * traits.selectors.selectTodosIdsSelectedList()
1129
+ * traits.selectors.selectTodosSelectedMap()
1130
+ * traits.selectors.selectTodosSelectedList()
1131
+ * traits.selectors.selectTotalSelectedTodos()
1132
+ */
1133
+ function addSelectEntitiesTrait() {
1134
+ return core.createTraitFactory({
1135
+ key: 'SelectEntities',
1136
+ depends: [loadEntitiesTraitKey],
1137
+ actions: function (_a) {
1138
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
1139
+ return createSelectEntitiesTraitActions(actionsGroupKey, entitiesName);
1140
+ },
1141
+ selectors: function (_a) {
1142
+ var previousSelectors = _a.previousSelectors;
1143
+ return createSelectEntitiesTraitSelectors(previousSelectors);
1144
+ },
1145
+ initialState: function (_a) {
1146
+ var previousInitialState = _a.previousInitialState;
1147
+ return createSelectEntitiesInitialState(previousInitialState);
1148
+ },
1149
+ mutators: function (_a) {
1150
+ var allSelectors = _a.allSelectors;
1151
+ return createSelectEntitiesTraitMutators(allSelectors);
1152
+ },
1153
+ reducer: function (_a) {
1154
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
1155
+ return createSelectEntitiesTraitReducer(initialState, allActions, allMutators, allConfigs);
1156
+ },
1157
+ });
1158
+ }
1159
+
1160
+ function createSelectEntityTraitActions(actionsGroupKey, entityName) {
1161
+ return {
1162
+ selectEntity: i2.createAction(actionsGroupKey + " Select " + entityName, i2.props()),
1163
+ deselectEntity: i2.createAction(actionsGroupKey + " Deselect " + entityName),
1164
+ toggleSelectEntity: i2.createAction(actionsGroupKey + " Toggle Select " + entityName, i2.props()),
1165
+ };
1166
+ }
1167
+
1168
+ function createSelectEntityTraitSelectors() {
1169
+ function selectEntityIdSelected(state) {
1170
+ return state.selectedId;
1171
+ }
1172
+ function selectEntitySelected(state) {
1173
+ return (state.selectedId && state.entities[state.selectedId]) || undefined;
1174
+ }
1175
+ return {
1176
+ selectEntityIdSelected: selectEntityIdSelected,
1177
+ selectEntitySelected: selectEntitySelected,
1178
+ };
1179
+ }
1180
+
1181
+ function createSelectEntityInitialState(previousInitialState, allConfigs) {
1182
+ var _a;
1183
+ var selectedId = (_a = allConfigs.singleSelection) === null || _a === void 0 ? void 0 : _a.selectedId;
1184
+ return Object.assign(Object.assign({}, previousInitialState), { selectedId: selectedId });
1185
+ }
1186
+ function createSelectEntityTraitReducer(initialState, allActions, allMutators, allConfigs) {
1187
+ var _a, _b;
1188
+ var adapter = allConfigs.loadEntities.adapter;
1189
+ var sortRemote = (_a = allConfigs.sort) === null || _a === void 0 ? void 0 : _a.remote;
1190
+ var paginationCacheType = (_b = allConfigs.pagination) === null || _b === void 0 ? void 0 : _b.cacheType;
1191
+ return i2.createReducer.apply(void 0, __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([initialState, i2.on(allActions.selectEntity, function (state, _c) {
1192
+ var id = _c.id;
1193
+ return allMutators.selectEntity(id, state);
1194
+ }), i2.on(allActions.deselectEntity, function (state) { return allMutators.deselectEntity(state); }), i2.on(allActions.toggleSelectEntity, function (state, _c) {
1195
+ var id = _c.id;
1196
+ return allMutators.toggleSelectEntity(id, state);
1197
+ })], __read(core.insertIf(allActions.removeAllEntities, function () { return i2.on(allActions.removeAllEntities, function (state) { return allMutators.deselectEntity(state); }); }))), __read(core.insertIf(sortRemote, function () { return i2.on(allActions.sortEntities, function (state) { return allMutators.deselectEntity(state); }); }))), __read(core.insertIf(allActions.filterEntities, function () { return i2.on(allActions.filterEntities, function (state) { return allMutators.deselectEntity(state); }); }))), __read(core.insertIf(!allActions.loadEntitiesPageSuccess, function () { return i2.on(allActions.loadEntitiesSuccess, function (state) { return allMutators.deselectEntity(state); }); }))), __read(core.insertIf(!!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial', function () { return i2.on(allActions.loadEntitiesPageSuccess, function (state) { return allMutators.deselectEntity(state); }); }))), __read(core.insertIf(allActions.removeEntities, function () { return i2.on(allActions.removeEntities, function (state, _c) {
1198
+ var keys = _c.keys;
1199
+ var shouldDeselect = keys.some(function (v) { return v === state.selectedId; });
1200
+ return shouldDeselect
1201
+ ? Object.assign(Object.assign({}, state), { selectedId: undefined }) : state;
1202
+ }); }))), __read(core.insertIf(allActions.updateEntities, function () { return i2.on(allActions.updateEntities, function (state, _c) {
1203
+ var updates = _c.updates;
1204
+ var change = updates.find(function (updated) {
1205
+ var id = adapter.selectId(updated.changes);
1206
+ return id && id !== updated.id && state.selectedId === updated.id;
1207
+ });
1208
+ return change
1209
+ ? Object.assign(Object.assign({}, state), { selectedId: adapter.selectId(change.changes) }) : state;
1210
+ }); }))));
1211
+ }
1212
+
1213
+ function createSelectEntityTraitMutators() {
1214
+ function selectEntity(id, state) {
1215
+ return Object.assign(Object.assign({}, state), { selectedId: id });
1216
+ }
1217
+ function deselectEntity(state) {
1218
+ return Object.assign(Object.assign({}, state), { selectedId: undefined });
1219
+ }
1220
+ function toggleSelectEntity(id, state) {
1221
+ return Object.assign(Object.assign({}, state), { selectedId: state.selectedId === id ? undefined : id });
1222
+ }
1223
+ return {
1224
+ selectEntity: selectEntity,
1225
+ deselectEntity: deselectEntity,
1226
+ toggleSelectEntity: toggleSelectEntity,
1227
+ };
1228
+ }
1229
+
1230
+ /**
1231
+ * Generates ngrx code to add single selection to a list
1232
+ * @param config
1233
+ * @param config.selectedId - Default selected id
1234
+ *
1235
+ * @example
1236
+ * // The following trait config
1237
+ *
1238
+ * export interface TestState
1239
+ * extends EntityAndStatusState<Todo>,SelectEntityState{}
1240
+ *
1241
+ * const traits = createEntityFeatureFactory(
1242
+ * addLoadEntitiesTrait<Todo>(),
1243
+ * addSelectEntityTrait<Todo>()
1244
+ * )({
1245
+ * actionsGroupKey: '[Todos]',
1246
+ * featureSelector: createFeatureSelector<TestState>>(
1247
+ * 'todos',
1248
+ * ),
1249
+ * });
1250
+ * // will generate the following actions and selectors, plus the ones generated by other traits
1251
+ * traits.actions.selectTodo({id})
1252
+ * traits.actions.deselectTodo()
1253
+ * traits.actions.toggleSelectTodo({id})
1254
+ *
1255
+ * traits.selectors.selectTodoIdSelected()
1256
+ * traits.selectors.selectTodoSelected()
1257
+ */
1258
+ function addSelectEntityTrait(config) {
1259
+ return core.createTraitFactory({
1260
+ key: 'singleSelection',
1261
+ depends: [loadEntitiesTraitKey],
1262
+ config: config,
1263
+ actions: function (_a) {
1264
+ var actionsGroupKey = _a.actionsGroupKey, entityName = _a.entityName;
1265
+ return createSelectEntityTraitActions(actionsGroupKey, entityName);
1266
+ },
1267
+ selectors: function () { return createSelectEntityTraitSelectors(); },
1268
+ mutators: function () { return createSelectEntityTraitMutators(); },
1269
+ initialState: function (_a) {
1270
+ var previousInitialState = _a.previousInitialState, allConfigs = _a.allConfigs;
1271
+ return createSelectEntityInitialState(previousInitialState, allConfigs);
1272
+ },
1273
+ reducer: function (_a) {
1274
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
1275
+ return createSelectEntityTraitReducer(initialState, allActions, allMutators, allConfigs);
1276
+ },
1277
+ });
1278
+ }
1279
+
1280
+ var selectEntityTraitKey = 'singleSelection';
1281
+
1282
+ exports.ChangeType = void 0;
1283
+ (function (ChangeType) {
1284
+ ChangeType["CREATED"] = "c";
1285
+ ChangeType["UPDATED"] = "u";
1286
+ ChangeType["DELETED"] = "d";
1287
+ })(exports.ChangeType || (exports.ChangeType = {}));
1288
+ var crudEntitiesTraitKey = 'crud';
1289
+
1290
+ function createCrudTraitActions(actionsGroupKey, entitiesName) {
1291
+ return {
1292
+ addEntities: i2.createAction(actionsGroupKey + " Add " + entitiesName, function () {
1293
+ var entities = [];
1294
+ for (var _i = 0; _i < arguments.length; _i++) {
1295
+ entities[_i] = arguments[_i];
1296
+ }
1297
+ return ({
1298
+ entities: entities,
1299
+ });
1300
+ }),
1301
+ removeEntities: i2.createAction(actionsGroupKey + " Remove " + entitiesName, function () {
1302
+ var keys = [];
1303
+ for (var _i = 0; _i < arguments.length; _i++) {
1304
+ keys[_i] = arguments[_i];
1305
+ }
1306
+ return ({
1307
+ keys: keys,
1308
+ });
1309
+ }),
1310
+ updateEntities: i2.createAction(actionsGroupKey + " Update " + entitiesName, function () {
1311
+ var updates = [];
1312
+ for (var _i = 0; _i < arguments.length; _i++) {
1313
+ updates[_i] = arguments[_i];
1314
+ }
1315
+ return ({
1316
+ updates: updates,
1317
+ });
1318
+ }),
1319
+ upsertEntities: i2.createAction(actionsGroupKey + " Upsert " + entitiesName, function () {
1320
+ var entities = [];
1321
+ for (var _i = 0; _i < arguments.length; _i++) {
1322
+ entities[_i] = arguments[_i];
1323
+ }
1324
+ return ({
1325
+ entities: entities,
1326
+ });
1327
+ }),
1328
+ removeAllEntities: i2.createAction(actionsGroupKey + " Remove All " + entitiesName, function (predicate) { return ({ predicate: predicate }); }),
1329
+ clearEntitiesChanges: i2.createAction(actionsGroupKey + " Clear " + entitiesName + " Changes"),
1330
+ };
1331
+ }
1332
+
1333
+ function createCrudTraitSelectors(previousSelectors) {
1334
+ function selectChanges(state) {
1335
+ return state.changes;
1336
+ }
1337
+ function selectFilteredChanges(state) {
1338
+ var cache = {};
1339
+ return state.changes.reduce(function (acc, value) {
1340
+ var changes = cache[value.id];
1341
+ if (!changes) {
1342
+ cache[value.id] = [value.changeType];
1343
+ acc.push(value);
1344
+ return acc;
1345
+ }
1346
+ if (value.changeType === exports.ChangeType.UPDATED) {
1347
+ return acc;
1348
+ }
1349
+ if (value.changeType === exports.ChangeType.DELETED &&
1350
+ changes.includes(exports.ChangeType.CREATED)) {
1351
+ delete cache[value.id];
1352
+ return acc.filter(function (v) { return v.id !== value.id; });
1353
+ }
1354
+ if (value.changeType === exports.ChangeType.DELETED) {
1355
+ delete cache[value.id];
1356
+ var newAcc = acc.filter(function (v) { return v.id !== value.id; });
1357
+ newAcc.push(value);
1358
+ return newAcc;
1359
+ }
1360
+ return acc;
1361
+ }, []);
1362
+ }
1363
+ var selectEntitiesMap = previousSelectors.selectEntitiesMap;
1364
+ var selectEntitiesChangesList = i2.createSelector(function (state) { return selectEntitiesMap(state); }, selectChanges, function (entities, changed, _b) {
1365
+ var type = _b.type;
1366
+ if (type)
1367
+ return changed
1368
+ .filter(function (c) { return c.changeType === type; })
1369
+ .map(function (change) {
1370
+ var _a;
1371
+ return ({
1372
+ changeType: change.changeType,
1373
+ entity: (_a = entities[change.id]) !== null && _a !== void 0 ? _a : {
1374
+ id: change.id,
1375
+ },
1376
+ });
1377
+ });
1378
+ var map = changed.map(function (change) {
1379
+ var _a;
1380
+ return ({
1381
+ changeType: change.changeType,
1382
+ entity: (_a = entities[change.id]) !== null && _a !== void 0 ? _a : {
1383
+ id: change.id,
1384
+ },
1385
+ });
1386
+ });
1387
+ return map;
1388
+ });
1389
+ var selectFilteredEntitiesChangesList = i2.createSelector(selectFilteredChanges, function (state) { return selectEntitiesMap(state); }, function (changes, entities) { return changes.map(function (c) {
1390
+ var _a;
1391
+ return {
1392
+ entity: (_a = entities[c.id]) !== null && _a !== void 0 ? _a : { id: c.id },
1393
+ changeType: c.changeType,
1394
+ };
1395
+ }); });
1396
+ return {
1397
+ selectEntitiesChangesList: selectEntitiesChangesList,
1398
+ selectFilteredEntitiesChangesList: selectFilteredEntitiesChangesList,
1399
+ };
1400
+ }
1401
+
1402
+ function createCrudInitialState(previousInitialState) {
1403
+ return Object.assign(Object.assign({}, previousInitialState), { changes: [] });
1404
+ }
1405
+ function createCrudTraitReducer(initialState, allActions, allMutators, allConfigs) {
1406
+ var _a, _b, _c;
1407
+ var sortRemote = (_a = allConfigs.sort) === null || _a === void 0 ? void 0 : _a.remote;
1408
+ var filterRemote = allConfigs.filter && !((_b = allConfigs.filter) === null || _b === void 0 ? void 0 : _b.filterFn);
1409
+ var paginationCacheType = (_c = allConfigs.pagination) === null || _c === void 0 ? void 0 : _c.cacheType;
1410
+ return i2.createReducer.apply(void 0, __spreadArray(__spreadArray(__spreadArray(__spreadArray([initialState, i2.on(allActions.addEntities, function (state, _d) {
1411
+ var entities = _d.entities;
1412
+ return allMutators.addEntities(entities, state);
1413
+ }), i2.on(allActions.updateEntities, function (state, _d) {
1414
+ var updates = _d.updates;
1415
+ return allMutators.updateEntities(updates, state);
1416
+ }), i2.on(allActions.upsertEntities, function (state, _d) {
1417
+ var entities = _d.entities;
1418
+ return allMutators.upsertEntities(entities, state);
1419
+ }), i2.on(allActions.removeEntities, function (state, _d) {
1420
+ var keys = _d.keys;
1421
+ return allMutators.removeEntities(keys, state);
1422
+ }), i2.on(allActions.removeAllEntities, function (state, _d) {
1423
+ var predicate = _d.predicate;
1424
+ return predicate
1425
+ ? allMutators.removeEntities(predicate, state)
1426
+ : allMutators.removeAllEntities(state);
1427
+ }), i2.on(allActions.clearEntitiesChanges, function (state) { return allMutators.clearEntitiesChanges(state); })], __read(core.insertIf(sortRemote, function () { return i2.on(allActions.sortEntities, function (state) { return allMutators.clearEntitiesChanges(state); }); }))), __read(core.insertIf(filterRemote, function () { return i2.on(allActions.filterEntities, function (state) { return allMutators.clearEntitiesChanges(state); }); }))), __read(core.insertIf(!allActions.loadEntitiesPageSuccess, function () { return i2.on(allActions.loadEntitiesSuccess, function (state) { return allMutators.clearEntitiesChanges(state); }); }))), __read(core.insertIf(!!allActions.loadEntitiesPageSuccess && paginationCacheType === 'partial', function () { return i2.on(allActions.loadEntitiesPageSuccess, function (state) { return allMutators.clearEntitiesChanges(state); }); }))));
1428
+ }
1429
+
1430
+ function createCrudTraitMutators(allConfigs) {
1431
+ var storeChanges = (allConfigs.crud || {}).storeChanges;
1432
+ var adapter = allConfigs.loadEntities.adapter;
1433
+ function generateChangeEntry(entity, changeType, customId) {
1434
+ return {
1435
+ id: customId !== null && customId !== void 0 ? customId : adapter.selectId(entity),
1436
+ changeType: changeType,
1437
+ entityChanges: (storeChanges && entity) || undefined,
1438
+ };
1439
+ }
1440
+ function addEntities(entities, state, addFirst) {
1441
+ if (addFirst === void 0) { addFirst = false; }
1442
+ var changes = __spreadArray(__spreadArray([], __read(state.changes)), __read(entities.map(function (entity) { return generateChangeEntry(entity, exports.ChangeType.CREATED); })));
1443
+ if (!addFirst)
1444
+ return adapter.addMany(entities, Object.assign(Object.assign({}, state), { changes: changes }));
1445
+ var newIds = entities.map(function (e) { return adapter.selectId(e); });
1446
+ var newEntities = Object.assign({}, state.entities);
1447
+ entities.forEach(function (e) {
1448
+ var id = adapter.selectId(e);
1449
+ newEntities[id] = e;
1450
+ });
1451
+ return Object.assign(Object.assign({}, state), { ids: __spreadArray(__spreadArray([], __read(newIds)), __read(state.ids)), entities: newEntities, changes: changes });
1452
+ }
1453
+ function upsertEntities(entities, state) {
1454
+ var oldChanges = __spreadArray([], __read(state.changes));
1455
+ var existingIds = adapter.getSelectors().selectIds(state);
1456
+ var _b = __read(entities.reduce(function (_b, entity) {
1457
+ var _c = __read(_b, 2), a = _c[0], u = _c[1];
1458
+ return existingIds.indexOf(adapter.selectId(entity)) !== -1
1459
+ ? [a, __spreadArray(__spreadArray([], __read(u)), [entity])]
1460
+ : [__spreadArray(__spreadArray([], __read(a)), [entity]), u];
1461
+ }, [new Array(), new Array()]), 2), additions = _b[0], updates = _b[1];
1462
+ return adapter.upsertMany(entities, Object.assign(Object.assign({}, state), { changes: __spreadArray(__spreadArray(__spreadArray([], __read(oldChanges)), __read(additions.map(function (entity) { return generateChangeEntry(entity, exports.ChangeType.CREATED); }))), __read(updates.map(function (entity) { return generateChangeEntry(entity, exports.ChangeType.UPDATED); }))) }));
1463
+ }
1464
+ function removeEntities(keysOrPredicate, state) {
1465
+ if (typeof keysOrPredicate === 'function') {
1466
+ return adapter.removeMany(keysOrPredicate, Object.assign(Object.assign({}, state), { changes: __spreadArray(__spreadArray([], __read(state.changes)), __read(state.ids.map(function (id) { return ({
1467
+ id: id,
1468
+ changeType: exports.ChangeType.DELETED,
1469
+ }); }))) }));
1470
+ }
1471
+ return adapter.removeMany(keysOrPredicate, Object.assign(Object.assign({}, state), { changes: __spreadArray(__spreadArray([], __read(state.changes)), __read(keysOrPredicate.map(function (key) { return ({
1472
+ id: key,
1473
+ changeType: exports.ChangeType.DELETED,
1474
+ }); }))) }));
1475
+ }
1476
+ function removeAllEntities(state) {
1477
+ return adapter.removeAll(Object.assign(Object.assign({}, state), { changes: __spreadArray(__spreadArray([], __read(state.changes)), __read(state.ids.map(function (id) { return ({
1478
+ id: id,
1479
+ changeType: exports.ChangeType.DELETED,
1480
+ }); }))) }));
1481
+ }
1482
+ function clearEntitiesChanges(state) {
1483
+ return Object.assign(Object.assign({}, state), { changes: [] });
1484
+ }
1485
+ function updateEntities(updates, state) {
1486
+ var oldChanges = __spreadArray([], __read(state.changes));
1487
+ updates.forEach(function (updated) {
1488
+ var id = adapter.selectId(updated.changes);
1489
+ if (id && id !== updated.id) {
1490
+ // if the id changes update the id of pold changes
1491
+ var index = oldChanges.findIndex(function (v) { return v.id === updated.id; });
1492
+ var oldChange = oldChanges[index];
1493
+ oldChanges[index] = Object.assign(Object.assign({}, oldChange), { id: id });
1494
+ }
1495
+ });
1496
+ return adapter.updateMany(updates, Object.assign(Object.assign({}, state), { changes: __spreadArray(__spreadArray([], __read(oldChanges)), __read(updates.map(function (updated) {
1497
+ var _a;
1498
+ return ({
1499
+ id: (_a = adapter.selectId(updated.changes)) !== null && _a !== void 0 ? _a : updated.id,
1500
+ changeType: exports.ChangeType.UPDATED,
1501
+ entityChanges: (storeChanges && updated.changes) || undefined,
1502
+ });
1503
+ }))) }));
1504
+ }
1505
+ return {
1506
+ addEntities: addEntities,
1507
+ removeEntities: removeEntities,
1508
+ updateEntities: updateEntities,
1509
+ removeAllEntities: removeAllEntities,
1510
+ clearEntitiesChanges: clearEntitiesChanges,
1511
+ upsertEntities: upsertEntities,
1512
+ };
1513
+ }
1514
+
1515
+ /**
1516
+ * Generates ngrx code to add, remove update, upsert entities on a list, it also
1517
+ * tracks the changes made, helpful for implementing batch updates. The `storeChanges` (false by default),
1518
+ * will store for add and update the changed entity props in the property `entityChanges` of the `Change` object.
1519
+ * @param config
1520
+ * @param config.storeChanges - Will store the changes made, default fals
1521
+ *
1522
+ * @example
1523
+ * // The following trait config
1524
+ *
1525
+ * export interface TestState
1526
+ * extends EntityAndStatusState<Todo>, CrudState<Todo>{}
1527
+ *
1528
+ * const traits = createEntityFeatureFactory(
1529
+ * addLoadEntitiesTrait<Todo>(),
1530
+ * addCrudEntitiesTrait<Todo>()
1531
+ * )({
1532
+ * actionsGroupKey: '[Todos]',
1533
+ * featureSelector: createFeatureSelector<TestState>>(
1534
+ * 'todos',
1535
+ * ),
1536
+ * });
1537
+ * // will generate the following actions and selectors, plus the ones generated by other traits
1538
+ * traits.actions.addTodos(entity1,entity2...)
1539
+ * traits.actions.updateTodos({id: id1, changes:{prop1}},{id: id2, changes:{prop2}} ...)
1540
+ * traits.actions.upsertTodos(entity1,entity2...)
1541
+ * traits.actions.removeAllTodos()
1542
+ * traits.actions.clearTodosChanges()
1543
+ *
1544
+ * traits.selectors.selectTodosChangesList()
1545
+ * traits.selectors.selectFilteredTodosChangesList()
1546
+ * traits.selectors.selectAllFilteredChanges()
1547
+ */
1548
+ function addCrudEntitiesTrait(_a) {
1549
+ var _b = _a === void 0 ? {} : _a, _c = _b.storeChanges, storeChanges = _c === void 0 ? false : _c;
1550
+ return core.createTraitFactory({
1551
+ key: crudEntitiesTraitKey,
1552
+ depends: [loadEntitiesTraitKey],
1553
+ config: { storeChanges: storeChanges },
1554
+ actions: function (_a) {
1555
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
1556
+ return createCrudTraitActions(actionsGroupKey, entitiesName);
1557
+ },
1558
+ selectors: function (_a) {
1559
+ var previousSelectors = _a.previousSelectors;
1560
+ return createCrudTraitSelectors(previousSelectors);
1561
+ },
1562
+ mutators: function (_a) {
1563
+ var allConfigs = _a.allConfigs;
1564
+ return createCrudTraitMutators(allConfigs);
1565
+ },
1566
+ initialState: function (_a) {
1567
+ var previousInitialState = _a.previousInitialState;
1568
+ return createCrudInitialState(previousInitialState);
1569
+ },
1570
+ reducer: function (_a) {
1571
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
1572
+ return createCrudTraitReducer(initialState, allActions, allMutators, allConfigs);
1573
+ },
1574
+ });
1575
+ }
1576
+
1577
+ var sortTraitKey = 'sort';
1578
+
1579
+ var MAX_SAFE_INTEGER = 9007199254740991;
1580
+ function _isNumberValue(value) {
1581
+ // parseFloat(value) handles most of the cases we're interested in (it treats null, empty string,
1582
+ // and other non-number values as NaN, where Number just uses 0) but it considers the string
1583
+ // '123hello' to be a valid number. Therefore we also check if Number(value) is NaN.
1584
+ return !isNaN(parseFloat(value)) && !isNaN(Number(value));
1585
+ }
1586
+ function sortingDataAccessor(data, sortHeaderId) {
1587
+ var value = data[sortHeaderId];
1588
+ if (_isNumberValue(value)) {
1589
+ var numberValue = Number(value);
1590
+ // Numbers beyond `MAX_SAFE_INTEGER` can't be compared reliably so we
1591
+ // leave them as strings. For more info: https://goo.gl/y5vbSg
1592
+ return numberValue < MAX_SAFE_INTEGER ? numberValue : value;
1593
+ }
1594
+ return value;
1595
+ }
1596
+ /**
1597
+ * Gets a sorted copy of the data array based on the state of the Sort.
1598
+ * @param data The array of data that should be sorted.
1599
+ * @param sort The connected MatSort that holds the current sort state.
1600
+ */
1601
+ function sortData(data, sort) {
1602
+ var active = sort.active;
1603
+ var direction = sort.direction;
1604
+ if (!active || direction === '') {
1605
+ return data;
1606
+ }
1607
+ return data.sort(function (a, b) {
1608
+ var valueA = sortingDataAccessor(a, active);
1609
+ var valueB = sortingDataAccessor(b, active);
1610
+ // If both valueA and valueB exist (truthy), then compare the two. Otherwise, check if
1611
+ // one value exists while the other doesn't. In this case, existing value should come last.
1612
+ // This avoids inconsistent results when comparing values to undefined/null.
1613
+ // If neither value exists, return 0 (equal).
1614
+ var comparatorResult = 0;
1615
+ if (valueA != null && valueB != null) {
1616
+ // Check if one value is greater than the other; if equal, comparatorResult should remain 0.
1617
+ if (typeof valueA === 'string' || typeof valueB === 'string') {
1618
+ // if either values are a string, then force both to be strings before localCompare
1619
+ comparatorResult = valueA.toString().localeCompare(valueB.toString());
1620
+ }
1621
+ else {
1622
+ if (valueA > valueB) {
1623
+ comparatorResult = 1;
1624
+ }
1625
+ else if (valueA < valueB) {
1626
+ comparatorResult = -1;
1627
+ }
1628
+ }
1629
+ }
1630
+ else if (valueA != null) {
1631
+ comparatorResult = 1;
1632
+ }
1633
+ else if (valueB != null) {
1634
+ comparatorResult = -1;
1635
+ }
1636
+ return comparatorResult * (direction === 'asc' ? 1 : -1);
1637
+ });
1638
+ }
1639
+
1640
+ function createSortTraitMutators(_a, allConfigs) {
1641
+ var selectEntitiesList = _a.selectEntitiesList;
1642
+ function sortEntities(_a, state) {
1643
+ var active = _a.active, direction = _a.direction;
1644
+ var adapter = allConfigs.loadEntities.adapter;
1645
+ var entities = selectEntitiesList(state);
1646
+ var sortedIds = sortData(entities, { active: active, direction: direction }).map(function (v) { return adapter.selectId(v); });
1647
+ return Object.assign(Object.assign({}, state), { ids: sortedIds, sort: Object.assign(Object.assign({}, state.sort), { current: { active: active, direction: direction } }) });
1648
+ }
1649
+ return {
1650
+ sortEntities: sortEntities,
1651
+ };
1652
+ }
1653
+
1654
+ function createSortInitialState(previousInitialState, allConfigs) {
1655
+ var defaultSort = allConfigs.sort.defaultSort;
1656
+ return Object.assign(Object.assign({}, previousInitialState), { sort: {
1657
+ current: defaultSort,
1658
+ default: defaultSort,
1659
+ } });
1660
+ }
1661
+ function createSortTraitReducer(initialState, allActions, allMutators, allConfigs) {
1662
+ var remote = allConfigs.sort.remote;
1663
+ return i2.createReducer(initialState, i2.on(allActions.sortEntities, function (state, _d) {
1664
+ var active = _d.active, direction = _d.direction;
1665
+ return !remote
1666
+ ? allMutators.sortEntities({ active: active, direction: direction }, state)
1667
+ : Object.assign(Object.assign({}, state), { sort: Object.assign(Object.assign({}, state.sort), { current: { active: active, direction: direction } }) });
1668
+ }), i2.on(allActions.resetEntitiesSort, function (state) {
1669
+ var _a, _b, _c;
1670
+ return ((_a = state.sort) === null || _a === void 0 ? void 0 : _a.default)
1671
+ ? !remote
1672
+ ? allMutators.sortEntities((_b = state.sort) === null || _b === void 0 ? void 0 : _b.default, state)
1673
+ : Object.assign(Object.assign({}, state), { sort: Object.assign(Object.assign({}, state.sort), { current: (_c = state.sort) === null || _c === void 0 ? void 0 : _c.default }) })
1674
+ : state;
1675
+ }));
1676
+ }
1677
+
1678
+ function createSortTraitSelectors() {
1679
+ function selectEntitiesSort(state) {
1680
+ var _a;
1681
+ return (_a = state.sort) === null || _a === void 0 ? void 0 : _a.current;
1682
+ }
1683
+ return {
1684
+ selectEntitiesSort: selectEntitiesSort,
1685
+ };
1686
+ }
1687
+
1688
+ function createSortTraitEffect(allActions, allConfigs) {
1689
+ var remote = allConfigs.sort.remote;
1690
+ var SortEffect = /** @class */ (function (_super) {
1691
+ __extends(SortEffect, _super);
1692
+ function SortEffect() {
1693
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1694
+ _this.remoteSort$ = i1.createEffect(function () {
1695
+ return _this.actions$.pipe(i1.ofType(allActions.sortEntities, allActions.resetEntitiesSort), operators.concatMap(function () { return allActions.loadEntitiesFirstPage
1696
+ ? [
1697
+ allActions.clearEntitiesPagesCache(),
1698
+ allActions.loadEntitiesFirstPage(),
1699
+ ]
1700
+ : [allActions.loadEntities()]; }));
1701
+ });
1702
+ return _this;
1703
+ }
1704
+ return SortEffect;
1705
+ }(core.TraitEffect));
1706
+ SortEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: SortEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
1707
+ SortEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: SortEffect });
1708
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: SortEffect, decorators: [{
1709
+ type: i0.Injectable
1710
+ }] });
1711
+ return remote ? [SortEffect] : [];
1712
+ }
1713
+
1714
+ function createSortTraitActions(actionsGroupKey, entitiesName) {
1715
+ return {
1716
+ sortEntities: i2.createAction(actionsGroupKey + " Sort " + entitiesName, i2.props()),
1717
+ resetEntitiesSort: i2.createAction(actionsGroupKey + " Reset " + entitiesName + " Sort"),
1718
+ };
1719
+ }
1720
+
1721
+ /**
1722
+ * Generates ngrx code to sort locally or remotely a list of entities
1723
+ * @param config
1724
+ * @param config.defaultSort - Required, Default entity prop for the sort
1725
+ * @param config.remote - Optional field, default to false, when true disables local
1726
+ * sorting and every sort action call will now trigger a loadEntities action and the backend
1727
+ * should sort the data, use selectSort in the effect that call backend to get the requested sort,
1728
+ * when false all sorting is done in memory when the sort action is fired
1729
+ *
1730
+ * @example
1731
+ * // The following trait config
1732
+ * export interface TestState
1733
+ * extends EntityAndStatusState<Todo>, SortState<Todo>{}
1734
+ *
1735
+ * const traits = createEntityFeatureFactory(
1736
+ * addLoadEntitiesTrait<Todo>(),
1737
+ * addSortEntitiesTrait<Todo>({
1738
+ * defaultSort: {active:'id', direction:'asc'}
1739
+ * })
1740
+ * )({
1741
+ * actionsGroupKey: '[Todos]',
1742
+ * featureSelector: createFeatureSelector<TestState>>(
1743
+ * 'todos',
1744
+ * ),
1745
+ * });
1746
+ * // will generate the following actions and selectors, plus the ones generated by other traits
1747
+ * traits.actions.sortTodos({active:'id', direction:'desc'})
1748
+ * traits.actions.resetTodosSort()
1749
+ *
1750
+ * traits.selectors.selectTodosSort()
1751
+ */
1752
+ function addSortEntitiesTrait(_a) {
1753
+ var _b = _a.remote, remote = _b === void 0 ? false : _b, defaultSort = _a.defaultSort;
1754
+ return core.createTraitFactory({
1755
+ key: sortTraitKey,
1756
+ depends: [loadEntitiesTraitKey],
1757
+ config: { remote: remote, defaultSort: defaultSort },
1758
+ actions: function (_a) {
1759
+ var actionsGroupKey = _a.actionsGroupKey, entitiesName = _a.entitiesName;
1760
+ return createSortTraitActions(actionsGroupKey, entitiesName);
1761
+ },
1762
+ selectors: function () { return createSortTraitSelectors(); },
1763
+ mutators: function (_a) {
1764
+ var allSelectors = _a.allSelectors, allConfigs = _a.allConfigs;
1765
+ return createSortTraitMutators(allSelectors, allConfigs);
1766
+ },
1767
+ initialState: function (_a) {
1768
+ var previousInitialState = _a.previousInitialState, allConfigs = _a.allConfigs;
1769
+ return createSortInitialState(previousInitialState, allConfigs);
1770
+ },
1771
+ reducer: function (_a) {
1772
+ var initialState = _a.initialState, allActions = _a.allActions, allMutators = _a.allMutators, allConfigs = _a.allConfigs;
1773
+ return createSortTraitReducer(initialState, allActions, allMutators, allConfigs);
1774
+ },
1775
+ effects: function (_a) {
1776
+ var allActions = _a.allActions, allConfigs = _a.allConfigs;
1777
+ return createSortTraitEffect(allActions, allConfigs);
1778
+ },
1779
+ });
1780
+ }
1781
+
1782
+ /**
1783
+ * Generates the ngrx code needed to reset the current state to the initial state.
1784
+ * @param traitConfig - Config object fot the trait factory
1785
+ * @param traitConfig.resetOn - set an extra action which will also trigger a reset state,
1786
+ * useful if you want to create an action that reset several features states
1787
+ *
1788
+ * @example
1789
+ * // The following trait config
1790
+ *
1791
+ * export interface TestState
1792
+ * extends EntityAndStatusState<Todo>,FilterState<TodoFilter>{}
1793
+ *
1794
+ * const traits = createEntityFeatureFactory(
1795
+ * addLoadEntitiesTrait<Todo>(),
1796
+ * addResetEntitiesStateTrait()
1797
+ * )({
1798
+ * actionsGroupKey: '[Todos]',
1799
+ * featureSelector: createFeatureSelector<TestState>>(
1800
+ * 'todos',
1801
+ * ),
1802
+ * });
1803
+ * // will generate the following actions, plus the ones generated by other traits
1804
+ * traits.actions.resetTodosState()
1805
+ */
1806
+ function addResetEntitiesStateTrait(traitConfig) {
1807
+ if (traitConfig === void 0) { traitConfig = {}; }
1808
+ return core.createTraitFactory({
1809
+ key: 'reset',
1810
+ config: traitConfig,
1811
+ actions: function (_b) {
1812
+ var actionsGroupKey = _b.actionsGroupKey, entitiesName = _b.entitiesName;
1813
+ return ({
1814
+ resetEntitiesState: i2.createAction(actionsGroupKey + " Reset " + entitiesName + " State"),
1815
+ });
1816
+ },
1817
+ reducer: function (_b) {
1818
+ var allActions = _b.allActions, initialState = _b.initialState;
1819
+ return i2.createReducer(initialState, i2.on(allActions.resetEntitiesState, function () { return initialState; }));
1820
+ },
1821
+ effects: function (_b) {
1822
+ var allActions = _b.allActions;
1823
+ var _a;
1824
+ var ResetEffect = /** @class */ (function (_super) {
1825
+ __extends(ResetEffect, _super);
1826
+ //TODO: not sure why Im forced to override this constructor
1827
+ // or test wont pass, strangely doesnt happen in other files
1828
+ // with similar case like pagination.effects.ts
1829
+ function ResetEffect(actions$, store) {
1830
+ var _this = this;
1831
+ var _a;
1832
+ _this = _super.call(this, actions$, store) || this;
1833
+ _this.externalReset$ = ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) &&
1834
+ i1.createEffect(function () {
1835
+ return _this.actions$.pipe(i1.ofType.apply(void 0, __spreadArray([], __read(traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn))), operators.mapTo(allActions.resetEntitiesState()));
1836
+ });
1837
+ return _this;
1838
+ }
1839
+ return ResetEffect;
1840
+ }(core.TraitEffect));
1841
+ ResetEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect, deps: [{ token: i1__namespace.Actions }, { token: i2__namespace.Store }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1842
+ ResetEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect });
1843
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect, decorators: [{
1844
+ type: i0.Injectable
1845
+ }], ctorParameters: function () { return [{ type: i1__namespace.Actions }, { type: i2__namespace.Store }]; } });
1846
+ return ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) ? [ResetEffect] : [];
1847
+ },
1848
+ });
1849
+ }
1850
+
1851
+ /**
1852
+ * Generates the typical ngrx code need to make a async action with
1853
+ * a request, success and failure actions, plus a status property to track its progress
1854
+ * and selectors to query the status.
1855
+ *
1856
+ * @param options - Config object for the trait factory
1857
+ * @param options.name - Name of the main request action, should be in camel case
1858
+ * @param options.actionProps - Optional param for the main request action, use the props()
1859
+ * function for its value, if not present action will have no params,
1860
+ * @param options.actionSuccessProps - Optional param for the request success action,
1861
+ * use the props() function for its value, if not present action success will have no params
1862
+ * @param options.actionFailProps - Optional param for the request fail action,
1863
+ * use the props() function for its value, if not present action fail will have no params
1864
+ * @returns the trait factory
1865
+ *
1866
+ * @example
1867
+ * // The following trait config
1868
+ * const traits = createEntityFeatureFactory(
1869
+ * {entityName: 'Todo'},
1870
+ * addAsyncActionTrait({
1871
+ * name: 'createClient',
1872
+ * actionProps: props<{ name: string }>(),
1873
+ * actionSuccessProps: props<{ id: string }>(),
1874
+ * }),
1875
+ * )({
1876
+ * actionsGroupKey: 'Client',
1877
+ * featureSelector: createFeatureSelector<AsyncActionState<'createClient'>>(
1878
+ * 'client',
1879
+ * ),
1880
+ * });
1881
+ * // will generate the actions and selectors
1882
+ * traits.actions.createClient({name:'Pedro'})
1883
+ * traits.actions.createClientSuccess({id:'123'})
1884
+ * traits.actions.createClientFail();
1885
+ * traits.selectors.isLoadingCreateClient
1886
+ * traits.selectors.isSuccessCreateClient
1887
+ * traits.selectors.isFailCreateClient
1888
+ */
1889
+ function addAsyncActionTrait(_a) {
1890
+ var name = _a.name, actionProps = _a.actionProps, actionSuccessProps = _a.actionSuccessProps, actionFailProps = _a.actionFailProps;
1891
+ var nameAsSentence = core.camelCaseToSentence(name);
1892
+ var internalActions;
1893
+ return core.createTraitFactory({
1894
+ key: name + '-call',
1895
+ config: {
1896
+ name: name,
1897
+ actionProps: actionProps,
1898
+ actionSuccessProps: actionSuccessProps,
1899
+ actionFailProps: actionFailProps,
1900
+ },
1901
+ actions: function (_a) {
1902
+ var _b;
1903
+ var actionsGroupKey = _a.actionsGroupKey;
1904
+ internalActions = {
1905
+ request: (actionProps
1906
+ ? i2.createAction(actionsGroupKey + " " + nameAsSentence, actionProps)
1907
+ : i2.createAction(actionsGroupKey + " " + nameAsSentence)),
1908
+ requestSuccess: (actionSuccessProps
1909
+ ? i2.createAction(actionsGroupKey + " " + nameAsSentence + " Success", actionSuccessProps)
1910
+ : i2.createAction(actionsGroupKey + " " + nameAsSentence + " Success")),
1911
+ requestFail: (actionFailProps
1912
+ ? i2.createAction(actionsGroupKey + " " + nameAsSentence + " Failure", actionFailProps)
1913
+ : i2.createAction(actionsGroupKey + " " + nameAsSentence + " Failure")),
1914
+ };
1915
+ if (name) {
1916
+ return _b = {},
1917
+ _b["" + name] = internalActions.request,
1918
+ _b[name + "Success"] = internalActions.requestSuccess,
1919
+ _b[name + "Fail"] = internalActions.requestFail,
1920
+ _b;
1921
+ }
1922
+ return internalActions;
1923
+ },
1924
+ selectors: function () {
1925
+ var _a;
1926
+ function isLoadingEntity(state) {
1927
+ return state[name + "Status"] === 'loading';
1928
+ }
1929
+ function isSuccessEntity(state) {
1930
+ return state[name + "Status"] === 'success';
1931
+ }
1932
+ function isFailEntity(state) {
1933
+ return state[name + "Status"] === 'fail';
1934
+ }
1935
+ var capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
1936
+ return _a = {},
1937
+ _a["isLoading" + capitalizedName] = isLoadingEntity,
1938
+ _a["isSuccess" + capitalizedName] = isSuccessEntity,
1939
+ _a["isFail" + capitalizedName] = isFailEntity,
1940
+ _a;
1941
+ },
1942
+ initialState: function (_a) {
1943
+ var previousInitialState = _a.previousInitialState;
1944
+ return previousInitialState;
1945
+ },
1946
+ reducer: function (_a) {
1947
+ var initialState = _a.initialState;
1948
+ return i2.createReducer(initialState, i2.on(internalActions.request, function (state) {
1949
+ var _a;
1950
+ return (Object.assign(Object.assign({}, state), (_a = {}, _a[name + "Status"] = 'loading', _a)));
1951
+ }), i2.on(internalActions.requestFail, function (state) {
1952
+ var _a;
1953
+ return (Object.assign(Object.assign({}, state), (_a = {}, _a[name + "Status"] = 'fail', _a)));
1954
+ }), i2.on(internalActions.requestSuccess, function (state) {
1955
+ var _a;
1956
+ return (Object.assign(Object.assign({}, state), (_a = {}, _a[name + "Status"] = 'success', _a)));
1957
+ }));
1958
+ },
1959
+ });
1960
+ }
1961
+
1962
+ /**
1963
+ * Generates ngrx code needed to load and entity and store it in a state
1964
+ * @param entityName - Entity name, should be in camel case
1965
+ * @param options.actionProps - Optional param for the main request action,
1966
+ * use the props() function for its value, if not present action will have no params,
1967
+ * @param options.actionSuccessProps - Optional param for the request success
1968
+ * action, use the props() function for its value, if not present action success will have no params
1969
+ * @param options.actionFailProps - Optional param for the request fail action,
1970
+ * use the props() function for its value, if not present action fail will have no params
1971
+ * @returns the trait factory
1972
+ *
1973
+ * @example
1974
+ * const traits = createEntityFeatureFactory(
1975
+ * ...addLoadEntityTraits({
1976
+ * entityName: 'client',
1977
+ * requestProps: props<{ id: string }>(),
1978
+ * responseProps: props<{ client: Client }>(),
1979
+ * }),
1980
+ * )({
1981
+ * actionsGroupKey: 'Client',
1982
+ * featureSelector: createFeatureSelector<
1983
+ * LoadEntityState<Client, 'client'>
1984
+ * >('client'),
1985
+ * });
1986
+ *
1987
+ * // will generate
1988
+ * traits.actions.loadClient({id:123});
1989
+ * traits.actions.loadClientSuccess({client: {id: '123', name: 'gabs'}});
1990
+ * traits.actions.loadClientFail();
1991
+ * traits.selectors.selectClient
1992
+ * traits.selectors.isLoadingLoadClient
1993
+ * traits.selectors.isSuccessLoadClient
1994
+ * traits.selectors.isFailLoadClient
1995
+ */
1996
+ function addLoadEntityTraits(_a) {
1997
+ var entityName = _a.entityName, actionProps = _a.actionProps, actionSuccessProps = _a.actionSuccessProps, actionFailProps = _a.actionFailProps;
1998
+ var capitalizedName = core.capitalize(entityName);
1999
+ return [
2000
+ addAsyncActionTrait({
2001
+ name: ('load' + capitalizedName),
2002
+ actionProps: actionProps,
2003
+ actionSuccessProps: actionSuccessProps,
2004
+ actionFailProps: actionFailProps,
2005
+ }),
2006
+ core.createTraitFactory({
2007
+ key: "load" + capitalizedName,
2008
+ config: { entityName: entityName, actionProps: actionProps, actionSuccessProps: actionSuccessProps, actionFailProps: actionFailProps },
2009
+ selectors: function () {
2010
+ var _a;
2011
+ function selectEntity(state) {
2012
+ return state["" + entityName];
2013
+ }
2014
+ return _a = {},
2015
+ _a["select" + capitalizedName] = selectEntity,
2016
+ _a;
2017
+ },
2018
+ initialState: function (_a) {
2019
+ var previousInitialState = _a.previousInitialState;
2020
+ return previousInitialState;
2021
+ },
2022
+ reducer: function (_a) {
2023
+ var initialState = _a.initialState, allActions = _a.allActions;
2024
+ return i2.createReducer(initialState, i2.on(allActions["load" + capitalizedName + "Success"], function (state, action) {
2025
+ var _a;
2026
+ return (Object.assign(Object.assign({}, state), (_a = {}, _a[entityName] = action[entityName], _a)));
2027
+ }));
2028
+ },
2029
+ }),
2030
+ ];
2031
+ }
2032
+
2033
+ /**
2034
+ * Generates ngrx code needed to set and entity in the store state
2035
+ * @param entityName - Entity name, should be in camel case
2036
+ * @param options.actionProps - param for the main request action,
2037
+ * use the props() function for its value
2038
+ * @returns the trait factory
2039
+ *
2040
+ * @example
2041
+ * const traits = createEntityFeatureFactory(
2042
+ * addSetEntityTraits({
2043
+ * entityName: 'client',
2044
+ * actionProps: props<{ client: { id: number; name: string } }
2045
+ * }),
2046
+ * )({
2047
+ * actionsGroupKey: 'Client',
2048
+ * featureSelector: createFeatureSelector<
2049
+ * SetEntityState<Client, 'client'>
2050
+ * >('client'),
2051
+ * });
2052
+ *
2053
+ * // will generate
2054
+ * traits.actions.setClient({client: {id:123, name: 'gabs'}});
2055
+ * traits.selectors.selectClient
2056
+ */
2057
+ function addSetEntityTrait(_a) {
2058
+ var entityName = _a.entityName, actionProps = _a.actionProps;
2059
+ var capitalizedName = core.capitalize(entityName);
2060
+ return core.createTraitFactory({
2061
+ key: "load" + capitalizedName,
2062
+ config: { entityName: entityName, actionProps: actionProps },
2063
+ actions: function (_a) {
2064
+ var _b;
2065
+ var actionsGroupKey = _a.actionsGroupKey;
2066
+ var setEntity = i2.createAction(actionsGroupKey + " Set " + capitalizedName, actionProps);
2067
+ return _b = {},
2068
+ _b["set" + capitalizedName] = setEntity,
2069
+ _b;
2070
+ },
2071
+ selectors: function () {
2072
+ var _a;
2073
+ function selectEntity(state) {
2074
+ return state["" + entityName];
2075
+ }
2076
+ return _a = {},
2077
+ _a["select" + capitalizedName] = selectEntity,
2078
+ _a;
2079
+ },
2080
+ initialState: function (_a) {
2081
+ var previousInitialState = _a.previousInitialState;
2082
+ return previousInitialState;
2083
+ },
2084
+ reducer: function (_a) {
2085
+ var initialState = _a.initialState, allActions = _a.allActions;
2086
+ return i2.createReducer(initialState, i2.on(allActions["set" + capitalizedName], function (state, action) {
2087
+ var _a;
2088
+ return (Object.assign(Object.assign({}, state), (_a = {}, _a[entityName] = action[entityName], _a)));
2089
+ }));
2090
+ },
2091
+ });
2092
+ }
2093
+
2094
+ /**
2095
+ * Generated bundle index. Do not edit.
2096
+ */
2097
+
2098
+ exports._isNumberValue = _isNumberValue;
2099
+ exports.addAsyncActionTrait = addAsyncActionTrait;
2100
+ exports.addCrudEntitiesTrait = addCrudEntitiesTrait;
2101
+ exports.addEntitiesPaginationTrait = addEntitiesPaginationTrait;
2102
+ exports.addFilterEntitiesTrait = addFilterEntitiesTrait;
2103
+ exports.addLoadEntitiesTrait = addLoadEntitiesTrait;
2104
+ exports.addLoadEntityTraits = addLoadEntityTraits;
2105
+ exports.addResetEntitiesStateTrait = addResetEntitiesStateTrait;
2106
+ exports.addSelectEntitiesTrait = addSelectEntitiesTrait;
2107
+ exports.addSelectEntityTrait = addSelectEntityTrait;
2108
+ exports.addSetEntityTrait = addSetEntityTrait;
2109
+ exports.addSortEntitiesTrait = addSortEntitiesTrait;
2110
+ exports.clearEntitiesSelection = clearEntitiesSelection;
2111
+ exports.crudEntitiesTraitKey = crudEntitiesTraitKey;
2112
+ exports.deselectEntities = deselectEntities;
2113
+ exports.entitiesPaginationTraitKey = entitiesPaginationTraitKey;
2114
+ exports.filterEntitiesTraitKey = filterEntitiesTraitKey;
2115
+ exports.loadEntitiesTraitKey = loadEntitiesTraitKey;
2116
+ exports.selectEntities = selectEntities;
2117
+ exports.selectEntityTraitKey = selectEntityTraitKey;
2118
+ exports.selectTotalSelectedEntities = selectTotalSelectedEntities;
2119
+ exports.sortData = sortData;
2120
+ exports.sortTraitKey = sortTraitKey;
2121
+ exports.toggleSelectEntities = toggleSelectEntities;
2122
+
2123
+ Object.defineProperty(exports, '__esModule', { value: true });
2124
+
2125
+ })));
2126
+ //# sourceMappingURL=ngrx-traits-common.umd.js.map