@lenne.tech/ng-base 13.6.5 → 13.6.6

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 (165) hide show
  1. package/base-components/components/checkbox/checkbox.component.d.ts +1 -1
  2. package/base-prototype/base-prototype.module.d.ts +6 -5
  3. package/base-prototype/pages/forgot-password/forgot-password.component.d.ts +7 -2
  4. package/base-prototype/pages/login/login.component.d.ts +8 -2
  5. package/base-prototype/pages/register/register.component.d.ts +8 -2
  6. package/esm2020/base-components/components/checkbox/checkbox.component.mjs +3 -3
  7. package/esm2020/base-components/components/input/input.component.mjs +3 -3
  8. package/esm2020/base-prototype/base-prototype.module.mjs +5 -4
  9. package/esm2020/base-prototype/pages/forgot-password/forgot-password.component.mjs +30 -9
  10. package/esm2020/base-prototype/pages/login/login.component.mjs +46 -9
  11. package/esm2020/base-prototype/pages/register/register.component.mjs +45 -11
  12. package/esm2020/public-api.mjs +1 -42
  13. package/esm2020/shared/classes/auth.class.mjs +16 -0
  14. package/esm2020/shared/classes/basic-user.class.mjs +51 -0
  15. package/esm2020/shared/classes/graphql-enum.class.mjs +9 -0
  16. package/esm2020/shared/classes/graphql-meta.class.mjs +171 -0
  17. package/esm2020/shared/classes/graphql-type.class.mjs +13 -0
  18. package/esm2020/shared/classes/helper.class.mjs +304 -0
  19. package/esm2020/shared/classes/standard.class.mjs +40 -0
  20. package/esm2020/{src → shared}/enums/comparison-operator.enum.mjs +1 -1
  21. package/esm2020/shared/enums/graphql-request-type.enum.mjs +10 -0
  22. package/esm2020/shared/enums/logical-operator.enum.mjs +10 -0
  23. package/esm2020/shared/enums/sort-order.enum.mjs +6 -0
  24. package/esm2020/shared/functions/ws-client.function.mjs +39 -0
  25. package/esm2020/shared/interfaces/base-module-config.interface.mjs +3 -0
  26. package/esm2020/shared/interfaces/can-component-deactivate.interface.mjs +2 -0
  27. package/esm2020/shared/interfaces/combined-filter-input.interface.mjs +2 -0
  28. package/esm2020/shared/interfaces/field-object.interface.mjs +2 -0
  29. package/esm2020/shared/interfaces/field.interface.mjs +2 -0
  30. package/esm2020/shared/interfaces/filter-input.interface.mjs +2 -0
  31. package/esm2020/shared/interfaces/find-args.interface.mjs +2 -0
  32. package/esm2020/shared/interfaces/graphql-fields-object.interface.mjs +2 -0
  33. package/esm2020/shared/interfaces/graphql-options.interface.mjs +2 -0
  34. package/esm2020/shared/interfaces/graphql-plus-options.interfacen.mjs +2 -0
  35. package/esm2020/shared/interfaces/graphql-type-collection.interface.mjs +2 -0
  36. package/esm2020/shared/interfaces/single-filter-input.interface.mjs +2 -0
  37. package/esm2020/shared/interfaces/sort-input.interface.mjs +2 -0
  38. package/esm2020/shared/interfaces/time-components.interface.mjs +2 -0
  39. package/esm2020/shared/lenne.tech-ng-base-shared.mjs +5 -0
  40. package/esm2020/shared/public-api.mjs +51 -0
  41. package/esm2020/shared/services/auth.service.mjs +71 -0
  42. package/esm2020/shared/services/forms.service.mjs +25 -0
  43. package/esm2020/shared/services/graphql-meta.service.mjs +123 -0
  44. package/esm2020/shared/services/graphql-plus.service.mjs +84 -0
  45. package/esm2020/shared/services/graphql.service.mjs +441 -0
  46. package/esm2020/shared/services/image.service.mjs +102 -0
  47. package/esm2020/shared/services/loader.service.mjs +29 -0
  48. package/esm2020/shared/services/scroll.service.mjs +179 -0
  49. package/esm2020/shared/services/storage.service.mjs +132 -0
  50. package/esm2020/shared/services/user.service.mjs +82 -0
  51. package/esm2020/shared/services/ws.service.mjs +16 -0
  52. package/esm2020/shared/types/graphql-fields.type.mjs +2 -0
  53. package/esm2020/shared/types/storage.type.mjs +2 -0
  54. package/esm2020/shared/validators/match.validator.mjs +19 -0
  55. package/esm2020/src/base.module.mjs +14 -11
  56. package/esm2020/src/directives/match-height.directive.mjs +2 -2
  57. package/esm2020/src/factories/apollo-options.factory.mjs +14 -12
  58. package/esm2020/src/guards/auth.guard.mjs +3 -3
  59. package/esm2020/src/guards/can-deactivate.guard.mjs +1 -1
  60. package/esm2020/src/guards/logout.guard.mjs +2 -2
  61. package/esm2020/src/services/theme.service.mjs +2 -2
  62. package/fesm2015/lenne.tech-ng-base-base-components.mjs +4 -4
  63. package/fesm2015/lenne.tech-ng-base-base-components.mjs.map +1 -1
  64. package/fesm2015/lenne.tech-ng-base-base-prototype.mjs +113 -22
  65. package/fesm2015/lenne.tech-ng-base-base-prototype.mjs.map +1 -1
  66. package/fesm2015/lenne.tech-ng-base-shared.mjs +1878 -0
  67. package/fesm2015/lenne.tech-ng-base-shared.mjs.map +1 -0
  68. package/fesm2015/lenne.tech-ng-base.mjs +57 -1799
  69. package/fesm2015/lenne.tech-ng-base.mjs.map +1 -1
  70. package/fesm2020/lenne.tech-ng-base-base-components.mjs +4 -4
  71. package/fesm2020/lenne.tech-ng-base-base-components.mjs.map +1 -1
  72. package/fesm2020/lenne.tech-ng-base-base-prototype.mjs +111 -22
  73. package/fesm2020/lenne.tech-ng-base-base-prototype.mjs.map +1 -1
  74. package/fesm2020/lenne.tech-ng-base-shared.mjs +1939 -0
  75. package/fesm2020/lenne.tech-ng-base-shared.mjs.map +1 -0
  76. package/fesm2020/lenne.tech-ng-base.mjs +57 -1854
  77. package/fesm2020/lenne.tech-ng-base.mjs.map +1 -1
  78. package/package.json +10 -2
  79. package/public-api.d.ts +0 -36
  80. package/shared/classes/auth.class.d.ts +9 -0
  81. package/{src → shared}/classes/basic-user.class.d.ts +0 -0
  82. package/{src → shared}/classes/graphql-enum.class.d.ts +0 -0
  83. package/{src → shared}/classes/graphql-meta.class.d.ts +0 -0
  84. package/{src → shared}/classes/graphql-type.class.d.ts +0 -0
  85. package/{src → shared}/classes/helper.class.d.ts +0 -0
  86. package/{src → shared}/classes/standard.class.d.ts +0 -0
  87. package/{src → shared}/enums/comparison-operator.enum.d.ts +0 -0
  88. package/{src → shared}/enums/graphql-request-type.enum.d.ts +0 -0
  89. package/{src → shared}/enums/logical-operator.enum.d.ts +0 -0
  90. package/{src → shared}/enums/sort-order.enum.d.ts +0 -0
  91. package/shared/functions/ws-client.function.d.ts +5 -0
  92. package/{src → shared}/interfaces/base-module-config.interface.d.ts +1 -1
  93. package/{src → shared}/interfaces/can-component-deactivate.interface.d.ts +0 -0
  94. package/{src → shared}/interfaces/combined-filter-input.interface.d.ts +0 -0
  95. package/{src → shared}/interfaces/field-object.interface.d.ts +0 -0
  96. package/{src → shared}/interfaces/field.interface.d.ts +0 -0
  97. package/{src → shared}/interfaces/filter-input.interface.d.ts +0 -0
  98. package/{src → shared}/interfaces/find-args.interface.d.ts +0 -0
  99. package/{src → shared}/interfaces/graphql-fields-object.interface.d.ts +0 -0
  100. package/{src → shared}/interfaces/graphql-options.interface.d.ts +0 -0
  101. package/{src → shared}/interfaces/graphql-plus-options.interfacen.d.ts +0 -0
  102. package/{src → shared}/interfaces/graphql-type-collection.interface.d.ts +0 -0
  103. package/{src → shared}/interfaces/single-filter-input.interface.d.ts +0 -0
  104. package/{src → shared}/interfaces/sort-input.interface.d.ts +0 -0
  105. package/shared/interfaces/time-components.interface.d.ts +6 -0
  106. package/shared/lenne.tech-ng-base-shared.d.ts +5 -0
  107. package/shared/package.json +10 -0
  108. package/shared/public-api.d.ts +43 -0
  109. package/{src → shared}/services/auth.service.d.ts +0 -0
  110. package/{src → shared}/services/forms.service.d.ts +0 -1
  111. package/{src → shared}/services/graphql-meta.service.d.ts +0 -0
  112. package/{src → shared}/services/graphql-plus.service.d.ts +0 -0
  113. package/{src → shared}/services/graphql.service.d.ts +0 -0
  114. package/{src → shared}/services/image.service.d.ts +0 -0
  115. package/{src → shared}/services/loader.service.d.ts +0 -0
  116. package/{src → shared}/services/scroll.service.d.ts +0 -0
  117. package/{src → shared}/services/storage.service.d.ts +0 -0
  118. package/shared/services/user.service.d.ts +42 -0
  119. package/{src → shared}/services/ws.service.d.ts +2 -2
  120. package/{src → shared}/types/graphql-fields.type.d.ts +0 -0
  121. package/{src → shared}/types/storage.type.d.ts +0 -0
  122. package/shared/validators/match.validator.d.ts +4 -0
  123. package/src/base.module.d.ts +4 -2
  124. package/src/directives/match-height.directive.d.ts +1 -1
  125. package/src/factories/apollo-options.factory.d.ts +1 -3
  126. package/src/guards/auth.guard.d.ts +1 -2
  127. package/src/guards/can-deactivate.guard.d.ts +1 -1
  128. package/src/guards/logout.guard.d.ts +1 -1
  129. package/src/services/theme.service.d.ts +1 -1
  130. package/esm2020/src/classes/basic-user.class.mjs +0 -51
  131. package/esm2020/src/classes/graphql-enum.class.mjs +0 -9
  132. package/esm2020/src/classes/graphql-meta.class.mjs +0 -171
  133. package/esm2020/src/classes/graphql-type.class.mjs +0 -13
  134. package/esm2020/src/classes/helper.class.mjs +0 -304
  135. package/esm2020/src/classes/standard.class.mjs +0 -40
  136. package/esm2020/src/enums/graphql-request-type.enum.mjs +0 -10
  137. package/esm2020/src/enums/logical-operator.enum.mjs +0 -10
  138. package/esm2020/src/enums/sort-order.enum.mjs +0 -6
  139. package/esm2020/src/interfaces/base-module-config.interface.mjs +0 -3
  140. package/esm2020/src/interfaces/can-component-deactivate.interface.mjs +0 -2
  141. package/esm2020/src/interfaces/combined-filter-input.interface.mjs +0 -2
  142. package/esm2020/src/interfaces/field-object.interface.mjs +0 -2
  143. package/esm2020/src/interfaces/field.interface.mjs +0 -2
  144. package/esm2020/src/interfaces/filter-input.interface.mjs +0 -2
  145. package/esm2020/src/interfaces/find-args.interface.mjs +0 -2
  146. package/esm2020/src/interfaces/graphql-fields-object.interface.mjs +0 -2
  147. package/esm2020/src/interfaces/graphql-options.interface.mjs +0 -2
  148. package/esm2020/src/interfaces/graphql-plus-options.interfacen.mjs +0 -2
  149. package/esm2020/src/interfaces/graphql-type-collection.interface.mjs +0 -2
  150. package/esm2020/src/interfaces/single-filter-input.interface.mjs +0 -2
  151. package/esm2020/src/interfaces/sort-input.interface.mjs +0 -2
  152. package/esm2020/src/services/auth.service.mjs +0 -71
  153. package/esm2020/src/services/forms.service.mjs +0 -26
  154. package/esm2020/src/services/graphql-meta.service.mjs +0 -123
  155. package/esm2020/src/services/graphql-plus.service.mjs +0 -84
  156. package/esm2020/src/services/graphql.service.mjs +0 -441
  157. package/esm2020/src/services/image.service.mjs +0 -102
  158. package/esm2020/src/services/loader.service.mjs +0 -29
  159. package/esm2020/src/services/scroll.service.mjs +0 -179
  160. package/esm2020/src/services/storage.service.mjs +0 -132
  161. package/esm2020/src/services/ws.service.mjs +0 -17
  162. package/esm2020/src/types/graphql-fields.type.mjs +0 -2
  163. package/esm2020/src/types/storage.type.mjs +0 -2
  164. package/esm2020/src/validators/must-match.validator.mjs +0 -22
  165. package/src/validators/must-match.validator.d.ts +0 -6
@@ -0,0 +1,1878 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injectable, Inject } from '@angular/core';
3
+ import { BehaviorSubject, of, throwError, Observable, map as map$1 } from 'rxjs';
4
+ import * as i1 from 'apollo-angular';
5
+ import { gql } from 'apollo-angular';
6
+ import { buildClientSchema, getIntrospectionQuery } from 'graphql';
7
+ import { map } from 'rxjs/operators';
8
+ import { FormControl, FormGroup } from '@angular/forms';
9
+ import { __awaiter } from 'tslib';
10
+ import * as i1$1 from '@angular/router';
11
+ import { createClient } from 'graphql-ws';
12
+
13
+ /**
14
+ * Helper class
15
+ */
16
+ class Helper {
17
+ /**
18
+ * Simple filter function for plain objects
19
+ */
20
+ static filter(objects, filter) {
21
+ return ((objects === null || objects === void 0 ? void 0 : objects.filter((element) => {
22
+ for (const [key, value] of Object.entries(filter)) {
23
+ if (Array.isArray(element[key])) {
24
+ for (const item of element[key]) {
25
+ if (!element[key].includs(value)) {
26
+ return false;
27
+ }
28
+ }
29
+ }
30
+ else if (element[key] !== value) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ })) || []);
36
+ }
37
+ /**
38
+ * Convert to a url/uri conform string
39
+ * Only:
40
+ * - lower case
41
+ * - chars, numbers and hyphens
42
+ */
43
+ static urlString(str, options = {}) {
44
+ // Config
45
+ const config = Object.assign({ allowAll: false }, options);
46
+ // To string
47
+ str = str + '';
48
+ // Trim
49
+ str = str.trim();
50
+ // Lower case
51
+ str = str.toLowerCase();
52
+ if (!config.allowAll) {
53
+ // Replace spaces
54
+ str = str.trim().replace(/\s+/g, '-');
55
+ // Replace some special chars
56
+ str = str.replace('ä', 'ae');
57
+ str = str.replace('ö', 'oe');
58
+ str = str.replace('ü', 'ue');
59
+ str = str.replace('ß', 'ss');
60
+ // Remove other special chars
61
+ str = str.replace(/[^a-zA-Z0-9-]/g, '');
62
+ }
63
+ // Return url conform string
64
+ return encodeURI(str);
65
+ }
66
+ /**
67
+ * Simple map function
68
+ */
69
+ static map(source, target, options = {}) {
70
+ // Set config
71
+ const config = Object.assign({ funcAllowed: false, dateStringToDate: true }, options);
72
+ // Check source
73
+ if (!source || typeof source !== 'object' || Array.isArray(source)) {
74
+ return target;
75
+ }
76
+ // Update properties
77
+ for (const key of Object.keys(target)) {
78
+ if (source[key] !== undefined && (config.funcAllowed || typeof (source[key] !== 'function'))) {
79
+ if (typeof source[key] === 'string' && config.dateStringToDate) {
80
+ if (Array.isArray(config.dateStringToDate)) {
81
+ if (config.dateStringToDate.includes(key)) {
82
+ target[key] = Helper.parseDate(source[key]);
83
+ }
84
+ }
85
+ else {
86
+ target[key] = Helper.parseDate(source[key]);
87
+ }
88
+ }
89
+ else {
90
+ target[key] = source[key];
91
+ }
92
+ }
93
+ }
94
+ // Return target
95
+ return target;
96
+ }
97
+ /**
98
+ * Create Object or Objects of specified type with specified data
99
+ */
100
+ static maps(data, targetClass) {
101
+ // Check data
102
+ if (!data || typeof data !== 'object') {
103
+ return undefined;
104
+ }
105
+ // Check array
106
+ if (!Array.isArray(data)) {
107
+ data = [data];
108
+ }
109
+ // Map
110
+ return data.map((item) => {
111
+ return targetClass.map(item);
112
+ });
113
+ }
114
+ /**
115
+ * Get plain parameter
116
+ */
117
+ static getPlainParameter(parameter) {
118
+ var _a, _b, _c;
119
+ if (!parameter) {
120
+ return parameter;
121
+ }
122
+ return (_c = (_b = (_a = parameter === null || parameter === void 0 ? void 0 : parameter.split('?')) === null || _a === void 0 ? void 0 : _a.shift()) === null || _b === void 0 ? void 0 : _b.split('#')) === null || _c === void 0 ? void 0 : _c.shift();
123
+ }
124
+ /**
125
+ * Get ID of an url parameter
126
+ */
127
+ static getParameterId(parameter) {
128
+ var _a;
129
+ if (!parameter) {
130
+ return parameter;
131
+ }
132
+ return (_a = Helper.getPlainParameter(parameter)) === null || _a === void 0 ? void 0 : _a.split('-').pop();
133
+ }
134
+ /**
135
+ * Delay
136
+ */
137
+ static delay(ms) {
138
+ const promise = new Promise((resolve) => setTimeout(resolve, ms));
139
+ return promise;
140
+ }
141
+ /**
142
+ * Deep freeze
143
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#What_is_shallow_freeze
144
+ */
145
+ static deepFreeze(object, preparedObjects = []) {
146
+ // Prevent infinit regress
147
+ if (preparedObjects.includes(object)) {
148
+ return object;
149
+ }
150
+ preparedObjects.push(object);
151
+ // Retrieve the property names defined on object
152
+ const propNames = Object.getOwnPropertyNames(object);
153
+ // Freeze properties before freezing self
154
+ for (const name of propNames) {
155
+ const value = object[name];
156
+ if (value && typeof value === 'object') {
157
+ Helper.deepFreeze(value, preparedObjects);
158
+ }
159
+ }
160
+ return Object.freeze(object);
161
+ }
162
+ /**
163
+ * Generates an unique identifier with 24 characters
164
+ */
165
+ static getUID() {
166
+ let dt = new Date().getTime();
167
+ const uuid = 'xxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
168
+ // eslint-disable-next-line no-bitwise
169
+ const r = (dt + Math.random() * 16) % 16 | 0;
170
+ dt = Math.floor(dt / 16);
171
+ // eslint-disable-next-line no-bitwise
172
+ return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
173
+ });
174
+ return uuid;
175
+ }
176
+ /**
177
+ * Parse date string to date object
178
+ */
179
+ static parseDate(dateString) {
180
+ const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/;
181
+ const reMsAjax = /^\/Date\((d|-|.*)\)[\/|\\]$/;
182
+ if (typeof dateString === 'string') {
183
+ const isoExec = reISO.exec(dateString);
184
+ if (isoExec) {
185
+ return new Date(dateString);
186
+ }
187
+ const msAjaxExec = reMsAjax.exec(dateString);
188
+ if (msAjaxExec) {
189
+ const cleaned = msAjaxExec[1].split(/[-+,.]/);
190
+ return new Date(cleaned[0] ? +cleaned[0] : 0 - +cleaned[1]);
191
+ }
192
+ }
193
+ return dateString;
194
+ }
195
+ /**
196
+ * Get browser name and version
197
+ */
198
+ static getBrowser() {
199
+ const userAgent = navigator.userAgent;
200
+ let data = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
201
+ let version;
202
+ if (/trident/i.test(data[1])) {
203
+ version = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
204
+ return { name: 'IE', version: version[1] || '' };
205
+ }
206
+ if (data[1] === 'Chrome') {
207
+ version = userAgent.match(/\bOPR|Edge\/(\d+)/);
208
+ if (version != null) {
209
+ return { name: 'Opera', version: version[1] };
210
+ }
211
+ }
212
+ data = data[2] ? [data[1], data[2]] : [navigator.appName, navigator.appVersion, '-?'];
213
+ version = userAgent.match(/version\/(\d+)/i);
214
+ if (version !== null) {
215
+ data.splice(1, 1, version[1]);
216
+ }
217
+ return {
218
+ name: data[0],
219
+ version: data[1],
220
+ };
221
+ }
222
+ /**
223
+ * Whether first parameter is a deep subset of second parameter
224
+ * Hint: functions will be ignored
225
+ */
226
+ static isSubset(a, b) {
227
+ // Equal
228
+ if (a === b) {
229
+ return true;
230
+ }
231
+ // Different type
232
+ if (typeof a !== typeof b) {
233
+ return false;
234
+ }
235
+ // Process array
236
+ if (Array.isArray(a)) {
237
+ for (const [key, value] of Object.entries(a)) {
238
+ if (Helper.isSubset(value, b[key])) {
239
+ return false;
240
+ }
241
+ }
242
+ return true;
243
+ }
244
+ // Process object
245
+ if (typeof a === 'object') {
246
+ const plain = JSON.parse(JSON.stringify(a));
247
+ for (const [key, value] of Object.entries(plain)) {
248
+ if (Helper.isSubset(value, b[key])) {
249
+ return false;
250
+ }
251
+ }
252
+ return true;
253
+ }
254
+ // Else
255
+ return true;
256
+ }
257
+ /**
258
+ * Whether parameters are equal (have equal properties)
259
+ * Hint: functions will be ignored
260
+ */
261
+ static isEqual(a, b) {
262
+ return Helper.isSubset(a, b) && Helper.isSubset(b, a);
263
+ }
264
+ /**
265
+ * First level difference of two objects
266
+ * Hint: functions will be ignored and when an array or an object is different the hole array or object will used as property value
267
+ *
268
+ * @returns Record<string, any> Object with properties from first object
269
+ */
270
+ static getDiff(a, b, clone = true) {
271
+ const result = {};
272
+ let firstObject = a;
273
+ if (clone) {
274
+ firstObject = JSON.parse(JSON.stringify(a));
275
+ }
276
+ for (const [key, value] of Object.entries(firstObject)) {
277
+ if (!Helper.isSubset(value, b[key])) {
278
+ result[key] = value;
279
+ }
280
+ }
281
+ return result;
282
+ }
283
+ /**
284
+ * Check if propertie is type of HTMLCollection or NodeList
285
+ * See https://stackoverflow.com/a/7238344
286
+ *
287
+ * @param nodes
288
+ */
289
+ static isNodeList(nodes) {
290
+ try {
291
+ const stringRepr = Object.prototype.toString.call(nodes);
292
+ return (typeof nodes === 'object' &&
293
+ /^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) &&
294
+ typeof nodes.length === 'number' &&
295
+ (nodes.length === 0 || (typeof nodes[0] === 'object' && nodes[0].nodeType > 0)));
296
+ }
297
+ catch (e) {
298
+ return false;
299
+ }
300
+ }
301
+ static arrayBufferToBase64(buffer) {
302
+ let binary = '';
303
+ const bytes = new Uint8Array(buffer);
304
+ const len = bytes.byteLength;
305
+ for (let i = 0; i < len; i++) {
306
+ binary += String.fromCharCode(bytes[i]);
307
+ }
308
+ return `data:image/*;base64, ${window.btoa(binary)}`;
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Standard class
314
+ * Other classes should extend the Standard class, if they offer own functions
315
+ * If the extended class uses object properties with own map functions, it should implement its own map function
316
+ */
317
+ class Standard {
318
+ /**
319
+ * Static map method
320
+ */
321
+ static map(data, item = new this()) {
322
+ return item.map(data);
323
+ }
324
+ /**
325
+ * Map data into an object
326
+ */
327
+ map(data) {
328
+ return Helper.map(data, this);
329
+ }
330
+ /**
331
+ * Clone object (and map additional data)
332
+ */
333
+ clone(mapData) {
334
+ const current = JSON.parse(JSON.stringify(this));
335
+ if (mapData) {
336
+ Object.assign(current, mapData);
337
+ }
338
+ return new this.constructor().map(current);
339
+ }
340
+ /**
341
+ * Compare this with another object
342
+ * Hint: functions will be ignored and when an array or an object is different the hole array or object will used as property value
343
+ *
344
+ * @return Record<string, any> with properties of this object which are different
345
+ */
346
+ getDiff(compare, clone = true) {
347
+ return Helper.getDiff(this, compare, clone);
348
+ }
349
+ }
350
+
351
+ /**
352
+ * User class
353
+ */
354
+ class BasicUser extends Standard {
355
+ constructor() {
356
+ super(...arguments);
357
+ this.id = undefined;
358
+ this.email = undefined;
359
+ this.firstName = undefined;
360
+ this.lastName = undefined;
361
+ this.roles = [];
362
+ this.username = undefined;
363
+ }
364
+ // ===================================================================================================================
365
+ // Methods
366
+ // ===================================================================================================================
367
+ /**
368
+ * Mapping
369
+ */
370
+ map(data) {
371
+ Helper.map(data, this);
372
+ return this;
373
+ }
374
+ /**
375
+ * Checks whether the user has at least one of the required roles
376
+ */
377
+ hasRole(roles) {
378
+ if (typeof roles === 'string') {
379
+ roles = [roles];
380
+ }
381
+ if (!this.roles || this.roles.length < 1) {
382
+ return false;
383
+ }
384
+ return !roles || roles.length < 1 ? true : this.roles.some((role) => roles.includes(role));
385
+ }
386
+ /**
387
+ * Checks whether the user has all required roles
388
+ */
389
+ hasAllRoles(roles) {
390
+ if (typeof roles === 'string') {
391
+ roles = [roles];
392
+ }
393
+ if (!this.roles || this.roles.length < 1) {
394
+ return false;
395
+ }
396
+ return !roles ? true : roles.every((role) => this.roles.includes(role));
397
+ }
398
+ }
399
+
400
+ /**
401
+ * GraphQL enum
402
+ */
403
+ class GraphQLEnum {
404
+ constructor(value) {
405
+ this.value = value;
406
+ }
407
+ }
408
+
409
+ /**
410
+ * GraphQL type
411
+ */
412
+ class GraphQLType extends Standard {
413
+ constructor() {
414
+ super(...arguments);
415
+ this.type = '';
416
+ this.isEnum = false;
417
+ this.validEnums = [];
418
+ }
419
+ }
420
+
421
+ /**
422
+ * GraphQL meta
423
+ */
424
+ class GraphQLMeta {
425
+ /**
426
+ * Integrate schema
427
+ */
428
+ constructor(schema) {
429
+ this.schema = schema;
430
+ // Frozen caches
431
+ this.args = {};
432
+ this.fields = {};
433
+ if (!schema) {
434
+ throw Error('Missing schema');
435
+ }
436
+ }
437
+ /**
438
+ * Get arguments of GraphQL function
439
+ */
440
+ getArgs(functionName, options = {}) {
441
+ const { cache, freeze, type } = Object.assign({ cache: true, freeze: true, type: undefined }, options);
442
+ // Get cache
443
+ if (cache && freeze) {
444
+ const args = this.args[functionName + type];
445
+ if (args) {
446
+ return args;
447
+ }
448
+ }
449
+ const func = this.getFunction(functionName, { type });
450
+ const result = {};
451
+ if (func === null || func === void 0 ? void 0 : func.args) {
452
+ func.args.forEach((item) => {
453
+ result[item.name] = this.getDeepType(item.type);
454
+ });
455
+ }
456
+ // Set cache
457
+ if (freeze) {
458
+ this.args[functionName + type] = Helper.deepFreeze(result);
459
+ }
460
+ return result;
461
+ }
462
+ /**
463
+ * Get fields of GraphQL function
464
+ */
465
+ getFields(functionName, options = {}) {
466
+ const { cache, freeze, type } = Object.assign({ cache: true, freeze: true, type: undefined }, options);
467
+ // Get cache
468
+ if (cache && freeze) {
469
+ const args = this.fields[functionName + type];
470
+ if (args) {
471
+ return args;
472
+ }
473
+ }
474
+ const func = this.getFunction(functionName, options);
475
+ const result = this.getDeepType(func.type);
476
+ // Set cache
477
+ if (freeze) {
478
+ this.fields[functionName + type] = Helper.deepFreeze(result);
479
+ }
480
+ return result;
481
+ }
482
+ /**
483
+ * Get GraphQL function
484
+ */
485
+ getFunction(name, options = {}) {
486
+ // Set config
487
+ const config = Object.assign({}, options);
488
+ // Init possible functions
489
+ let functions = {};
490
+ // If function type is set
491
+ if (config.type) {
492
+ const graphQLType = config.type.charAt(0).toUpperCase() + config.type.slice(1);
493
+ const type = this.schema.getType(graphQLType);
494
+ if (type) {
495
+ functions = type.getFields();
496
+ }
497
+ }
498
+ // If function type is not set
499
+ else {
500
+ ['Subscription', 'Mutation', 'Query'].forEach((item) => {
501
+ const type = this.schema.getType(item);
502
+ if (type) {
503
+ functions = Object.assign(Object.assign({}, functions), (type.getFields() || {}));
504
+ }
505
+ });
506
+ }
507
+ // Get function via name
508
+ return functions[name];
509
+ }
510
+ /**
511
+ * Get type
512
+ */
513
+ getType(name) {
514
+ return this.schema.getType(name);
515
+ }
516
+ /**
517
+ * Get deep type data
518
+ */
519
+ getDeepType(type, prepared = new WeakMap()) {
520
+ // Check type
521
+ if (!type) {
522
+ return type;
523
+ }
524
+ // Infinite regress protection
525
+ const preparedObject = {};
526
+ // Check prepared
527
+ if (typeof type === 'object') {
528
+ const preparedType = prepared.get(type);
529
+ if (preparedType) {
530
+ return preparedType;
531
+ }
532
+ // Set prepared
533
+ prepared.set(type, preparedObject);
534
+ }
535
+ // Search deeper
536
+ if (type.ofType) {
537
+ const ofTypeResult = this.getDeepType(type.ofType, prepared);
538
+ Object.assign(preparedObject, ofTypeResult);
539
+ return ofTypeResult;
540
+ }
541
+ // Process fields
542
+ if (type._fields) {
543
+ const result = {};
544
+ for (const [key, value] of Object.entries(type._fields)) {
545
+ result[key] = this.getDeepType(value, prepared);
546
+ }
547
+ Object.assign(preparedObject, result);
548
+ return result;
549
+ }
550
+ // Get type name
551
+ if (type.type) {
552
+ const typeResult = this.getDeepType(type.type, prepared);
553
+ Object.assign(preparedObject, typeResult);
554
+ return typeResult;
555
+ }
556
+ // Initialize GraphQLType
557
+ const graphqlType = GraphQLType.map({
558
+ type: type.name,
559
+ });
560
+ // Set enum values
561
+ if (!!type._values) {
562
+ graphqlType.isEnum = true;
563
+ for (const [key, value] of Object.entries(type._nameLookup)) {
564
+ if (!value.isDeprecated) {
565
+ graphqlType.validEnums.push(key);
566
+ }
567
+ }
568
+ }
569
+ // Finish
570
+ prepared.set(type, graphqlType);
571
+ return graphqlType;
572
+ }
573
+ }
574
+
575
+ class Auth extends Standard {
576
+ constructor() {
577
+ super(...arguments);
578
+ this.token = undefined;
579
+ this.user = undefined;
580
+ }
581
+ map(data) {
582
+ Helper.map(data, this);
583
+ this.user = (data === null || data === void 0 ? void 0 : data.user) ? BasicUser.map(data.user) : this.user;
584
+ return this;
585
+ }
586
+ }
587
+
588
+ const BASE_MODULE_CONFIG = new InjectionToken('BASE_MODULE_CONFIG');
589
+
590
+ /**
591
+ * Storage service for local data storage
592
+ */
593
+ class StorageService {
594
+ /**
595
+ * Initializations
596
+ */
597
+ constructor(moduleConfig) {
598
+ this.moduleConfig = moduleConfig;
599
+ /**
600
+ * Storage
601
+ */
602
+ this.storage = null;
603
+ /**
604
+ * Prefix for storage keys
605
+ */
606
+ this.prefix = '';
607
+ // Set storage
608
+ const type = moduleConfig.storageType ? moduleConfig.storageType : 'local';
609
+ if (window[type + 'Storage']) {
610
+ this.storage = window[type + 'Storage'];
611
+ }
612
+ // Set prefix
613
+ this.prefix = '';
614
+ if (moduleConfig.prefix) {
615
+ this.prefix += moduleConfig.prefix + '_';
616
+ }
617
+ if (moduleConfig.version) {
618
+ this.prefix += moduleConfig.version + '_';
619
+ }
620
+ }
621
+ /**
622
+ * Save itemKeys
623
+ *
624
+ * If you want to save one item, use itemKeys and value parameters like these:
625
+ * save('KEY_OF_THE_ITEM', ITEM)
626
+ *
627
+ * If you want to save multiple items, use itemKeys only (value parameter will be ignored):
628
+ * save({'KEY_OF_ITEM_1': ITEM_1, 'KEY_OF_ITEM_2': ITEM_2, ...})
629
+ */
630
+ save(itemKeys, value) {
631
+ // Check local storage
632
+ if (!this.storage) {
633
+ return false;
634
+ }
635
+ // Check item keys and value
636
+ if (!itemKeys ||
637
+ (typeof itemKeys === 'object' && !Object.keys(itemKeys).length) ||
638
+ (typeof itemKeys === 'string' && value === undefined)) {
639
+ return false;
640
+ }
641
+ if (typeof itemKeys === 'object') {
642
+ for (const [itemKey, itemValue] of Object.entries(itemKeys)) {
643
+ this.storage.setItem(this.prefix + itemKey, JSON.stringify(itemValue));
644
+ }
645
+ return true;
646
+ }
647
+ this.storage.setItem(this.prefix + itemKeys, JSON.stringify(value));
648
+ return true;
649
+ }
650
+ /**
651
+ * Load items via key(s)
652
+ */
653
+ load(itemKeys) {
654
+ // Check local storage
655
+ if (!this.storage) {
656
+ return;
657
+ }
658
+ // Check item keys
659
+ if (!itemKeys || (Array.isArray(itemKeys) && !itemKeys.length)) {
660
+ return null;
661
+ }
662
+ if (Array.isArray(itemKeys)) {
663
+ const back = {};
664
+ itemKeys.forEach((itemKey) => {
665
+ const loadedItem = this.storage.getItem(this.prefix + itemKey);
666
+ if (loadedItem) {
667
+ back[itemKey] = JSON.parse(loadedItem);
668
+ }
669
+ else {
670
+ back[itemKey] = null;
671
+ }
672
+ });
673
+ return back;
674
+ }
675
+ let value = this.storage.getItem(this.prefix + itemKeys);
676
+ if (value) {
677
+ value = JSON.parse(value);
678
+ }
679
+ return value;
680
+ }
681
+ /**
682
+ * Remove item from storage
683
+ *
684
+ * @param itemKeys keys or key to remove
685
+ */
686
+ remove(itemKeys) {
687
+ // Check local storage
688
+ if (!this.storage) {
689
+ return false;
690
+ }
691
+ if (Array.isArray(itemKeys)) {
692
+ itemKeys.forEach((key) => {
693
+ this.storage.removeItem(this.prefix + key);
694
+ });
695
+ return true;
696
+ }
697
+ this.storage.removeItem(this.prefix + itemKeys);
698
+ return true;
699
+ }
700
+ /**
701
+ * Clear local storage
702
+ */
703
+ reset() {
704
+ this.storage.clear();
705
+ }
706
+ }
707
+ StorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: StorageService, deps: [{ token: BASE_MODULE_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
708
+ StorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: StorageService, providedIn: 'root' });
709
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: StorageService, decorators: [{
710
+ type: Injectable,
711
+ args: [{
712
+ providedIn: 'root',
713
+ }]
714
+ }], ctorParameters: function () {
715
+ return [{ type: undefined, decorators: [{
716
+ type: Inject,
717
+ args: [BASE_MODULE_CONFIG]
718
+ }] }];
719
+ } });
720
+
721
+ class WsService {
722
+ reconnect() {
723
+ var _a;
724
+ (_a = this.client) === null || _a === void 0 ? void 0 : _a.restart();
725
+ }
726
+ }
727
+ WsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: WsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
728
+ WsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: WsService, providedIn: 'root' });
729
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: WsService, decorators: [{
730
+ type: Injectable,
731
+ args: [{
732
+ providedIn: 'root',
733
+ }]
734
+ }] });
735
+
736
+ /**
737
+ * Authentication service
738
+ */
739
+ class AuthService {
740
+ /**
741
+ * Constructor
742
+ */
743
+ constructor(moduleConfig, storageService, wsService) {
744
+ this.moduleConfig = moduleConfig;
745
+ this.storageService = storageService;
746
+ this.wsService = wsService;
747
+ // Subjects
748
+ this._currentUser = new BehaviorSubject(null);
749
+ this._token = new BehaviorSubject(null);
750
+ this.token = this.storageService.load('token');
751
+ this.currentUser = this.storageService.load('currentUser');
752
+ }
753
+ /**
754
+ * Logout
755
+ */
756
+ logout() {
757
+ this.storageService.remove(['token', 'currentUser']);
758
+ this.currentUser = null;
759
+ this.token = null;
760
+ }
761
+ // #################################################################
762
+ // Current User
763
+ // #################################################################
764
+ get currentUser() {
765
+ return this._currentUser.value;
766
+ }
767
+ set currentUser(user) {
768
+ this._currentUser.next(user);
769
+ this.storageService.save('currentUser', user);
770
+ }
771
+ get currentUserObservable() {
772
+ return this._currentUser.asObservable();
773
+ }
774
+ // #################################################################
775
+ // Token
776
+ // #################################################################
777
+ get token() {
778
+ return this._token.value;
779
+ }
780
+ set token(token) {
781
+ this._token.next(token);
782
+ this.storageService.save('token', token);
783
+ this.wsService.reconnect();
784
+ }
785
+ get tokenObservable() {
786
+ return this._token.asObservable();
787
+ }
788
+ }
789
+ AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthService, deps: [{ token: BASE_MODULE_CONFIG }, { token: StorageService }, { token: WsService }], target: i0.ɵɵFactoryTarget.Injectable });
790
+ AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthService, providedIn: 'root' });
791
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: AuthService, decorators: [{
792
+ type: Injectable,
793
+ args: [{
794
+ providedIn: 'root',
795
+ }]
796
+ }], ctorParameters: function () {
797
+ return [{ type: undefined, decorators: [{
798
+ type: Inject,
799
+ args: [BASE_MODULE_CONFIG]
800
+ }] }, { type: StorageService }, { type: WsService }];
801
+ } });
802
+
803
+ /**
804
+ * GraphQL request type enum
805
+ */
806
+ var GraphQLRequestType;
807
+ (function (GraphQLRequestType) {
808
+ GraphQLRequestType["QUERY"] = "query";
809
+ GraphQLRequestType["MUTATION"] = "mutation";
810
+ GraphQLRequestType["SUBSCRIPTION"] = "subscription";
811
+ })(GraphQLRequestType || (GraphQLRequestType = {}));
812
+
813
+ /**
814
+ * GraphQL meta service
815
+ *
816
+ * For collecting meta information of the GraphQL API
817
+ */
818
+ class GraphQLMetaService {
819
+ /**
820
+ * Include services
821
+ */
822
+ constructor(apollo) {
823
+ this.apollo = apollo;
824
+ }
825
+ /**
826
+ * Getter of introspectionQuery
827
+ */
828
+ get introspectionQuery() {
829
+ return JSON.parse(JSON.stringify(this._introspectionQuery));
830
+ }
831
+ /**
832
+ * Get schema for API
833
+ * See https://www.apollographql.com/blog/three-ways-to-represent-your-graphql-schema-a41f4175100d
834
+ */
835
+ getSchema(options = {}) {
836
+ // Get configurations
837
+ const config = Object.assign({ cache: true, freeze: true }, options);
838
+ // Use caching
839
+ if (config.cache) {
840
+ if (config.freeze && this._frozenSchema) {
841
+ return of(this._frozenSchema);
842
+ }
843
+ if (this._introspectionQuery) {
844
+ return of(buildClientSchema(this.introspectionQuery));
845
+ }
846
+ if (config.freeze && this._frozenSchemaObservable) {
847
+ return this._frozenSchemaObservable;
848
+ }
849
+ else if (!config.freeze && this._schemaObservable) {
850
+ return this._schemaObservable;
851
+ }
852
+ }
853
+ // Request schema from server
854
+ const observable = this.apollo
855
+ .query({
856
+ query: gql(getIntrospectionQuery({ descriptions: false })),
857
+ })
858
+ .pipe(map((schema) => {
859
+ // Cache introspectionQuery
860
+ this._introspectionQuery = schema.data;
861
+ // Convert schema to GraphQLSchema
862
+ this._frozenSchema = Helper.deepFreeze(buildClientSchema(this.introspectionQuery));
863
+ // Return GraphQLSchema
864
+ if (config.freeze) {
865
+ return this._frozenSchema;
866
+ }
867
+ return buildClientSchema(schema.data);
868
+ }));
869
+ // Set observables
870
+ if (config.freeze) {
871
+ this._frozenSchemaObservable = observable;
872
+ }
873
+ else {
874
+ this._schemaObservable = observable;
875
+ }
876
+ // Return result
877
+ return observable;
878
+ }
879
+ /**
880
+ * Get meta for API
881
+ * See https://www.apollographql.com/blog/three-ways-to-represent-your-graphql-schema-a41f4175100d
882
+ */
883
+ getMeta(options = {}) {
884
+ // Get configurations
885
+ const config = Object.assign({ cache: true, log: false }, options);
886
+ // Use caching
887
+ if (config.cache) {
888
+ if (this._meta) {
889
+ return of(this._meta);
890
+ }
891
+ else if (this._metaObservable) {
892
+ return this._metaObservable;
893
+ }
894
+ }
895
+ // Request schema from server
896
+ const observable = this.getSchema(options).pipe(map((schema) => {
897
+ // Log
898
+ if (config.log) {
899
+ console.log({ schema });
900
+ }
901
+ this._meta = new GraphQLMeta(schema);
902
+ return this._meta;
903
+ }));
904
+ // Set observables
905
+ this._metaObservable = observable;
906
+ // Return result
907
+ return observable;
908
+ }
909
+ }
910
+ GraphQLMetaService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLMetaService, deps: [{ token: i1.Apollo }], target: i0.ɵɵFactoryTarget.Injectable });
911
+ GraphQLMetaService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLMetaService, providedIn: 'root' });
912
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLMetaService, decorators: [{
913
+ type: Injectable,
914
+ args: [{
915
+ providedIn: 'root',
916
+ }]
917
+ }], ctorParameters: function () { return [{ type: i1.Apollo }]; } });
918
+
919
+ /**
920
+ * GraphQL service
921
+ */
922
+ class GraphQLService {
923
+ /**
924
+ * Include services
925
+ */
926
+ constructor(apollo, graphQLMetaService) {
927
+ this.apollo = apollo;
928
+ this.graphQLMetaService = graphQLMetaService;
929
+ }
930
+ /**
931
+ * GraphQL request
932
+ */
933
+ graphQl(graphql, options = {}) {
934
+ // Check arguments
935
+ if (!graphql) {
936
+ throwError('Missing graphql argument');
937
+ }
938
+ // Get config
939
+ const config = Object.assign({ arguments: null, fields: null, log: false, model: null, type: GraphQLRequestType.QUERY }, options);
940
+ // Convert class to Object for arguments
941
+ if (typeof config.arguments === 'function') {
942
+ config.arguments = new config.arguments();
943
+ }
944
+ // Convert class to Object for fields
945
+ if (typeof config.fields === 'function') {
946
+ config.fields = new config.fields();
947
+ }
948
+ // Log
949
+ if (config.log) {
950
+ console.log({ config });
951
+ }
952
+ // Send request
953
+ return new Observable((subscriber) => {
954
+ // Get meta
955
+ this.graphQLMetaService.getMeta({ log: config.log }).subscribe((meta) => {
956
+ // Prepare fields
957
+ let fields;
958
+ let allowedFields;
959
+ // Log meta
960
+ if (config.log) {
961
+ console.log({ meta });
962
+ }
963
+ if (config.fields) {
964
+ allowedFields = meta.getFields(graphql, { type: config.type });
965
+ // Log meta
966
+ if (config.log) {
967
+ console.log({ allowedFields });
968
+ }
969
+ const fieldsData = this.prepareFields(config.fields, {
970
+ allowed: allowedFields,
971
+ });
972
+ // Log fields data
973
+ if (config.log) {
974
+ fieldsData.usedFields.sort();
975
+ fieldsData.schemaFields.sort();
976
+ const filtered = fieldsData.schemaFields.filter((field) => !fieldsData.usedFields.includes(field));
977
+ const unused = this.graphQLTypeCollectionToStringArray(allowedFields).filter((field) => !fieldsData.usedFields.includes(field));
978
+ console.log({ fieldsData, filtered, unused });
979
+ }
980
+ fields = fieldsData.fieldsString;
981
+ }
982
+ if (fields && !fields.startsWith('{')) {
983
+ fields = '{' + fields + '\n}';
984
+ }
985
+ // Log fields
986
+ if (config.log) {
987
+ console.log({ fields });
988
+ }
989
+ // Get allowed args
990
+ const allowedArgs = meta.getArgs(graphql, { type: config.type });
991
+ // Log allowed args
992
+ if (config.log) {
993
+ console.log({ allowedArgs });
994
+ }
995
+ const argsData = this.prepareArguments(config.arguments, {
996
+ allowed: allowedArgs,
997
+ });
998
+ // Log args data
999
+ if (config.log) {
1000
+ argsData.usedArgs.sort();
1001
+ argsData.schemaArgs.sort();
1002
+ const filtered = argsData.schemaArgs.filter((field) => !argsData.usedArgs.includes(field));
1003
+ const unused = this.graphQLTypeCollectionToStringArray(allowedArgs)
1004
+ .sort()
1005
+ .filter((field) => !argsData.usedArgs.includes(field));
1006
+ console.log({ argsData, filtered, unused });
1007
+ }
1008
+ const args = (argsData === null || argsData === void 0 ? void 0 : argsData.argsString) || '';
1009
+ // Log
1010
+ if (config.log) {
1011
+ console.log({ graphQL: graphql, args, fields, type: config.type });
1012
+ }
1013
+ // Prepare request
1014
+ const documentNode = fields
1015
+ ? gql(config.type + '{\n' + graphql + args + fields + '\n}')
1016
+ : gql(config.type + '{\n' + graphql + args + '\n}');
1017
+ // Log
1018
+ if (config.log) {
1019
+ console.log({ documentNode });
1020
+ }
1021
+ const request = {};
1022
+ request[config.type] = documentNode;
1023
+ // Log
1024
+ if (config.log) {
1025
+ console.log({ request });
1026
+ }
1027
+ let func;
1028
+ if (config.type === GraphQLRequestType.MUTATION) {
1029
+ func = 'mutate';
1030
+ request[config.type] = documentNode;
1031
+ }
1032
+ else if (config.type === GraphQLRequestType.SUBSCRIPTION) {
1033
+ func = 'subscribe';
1034
+ request.query = documentNode;
1035
+ }
1036
+ else {
1037
+ func = config.type;
1038
+ request[config.type] = documentNode;
1039
+ }
1040
+ this.apollo[func](request).subscribe((result) => {
1041
+ var _a;
1042
+ const data = ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a[graphql]) !== undefined ? result.data[graphql] : result;
1043
+ // Direct data
1044
+ if (!config.model) {
1045
+ subscriber.next(data);
1046
+ }
1047
+ // Map data as array
1048
+ else if (Array.isArray(data)) {
1049
+ subscriber.next(data.map((item) => {
1050
+ return config.model.map(item);
1051
+ }));
1052
+ }
1053
+ // Map data
1054
+ else {
1055
+ subscriber.next(config.model.map(data));
1056
+ }
1057
+ if (config.type !== GraphQLRequestType.SUBSCRIPTION) {
1058
+ // Done
1059
+ subscriber.complete();
1060
+ }
1061
+ }, (error) => {
1062
+ subscriber.error(error);
1063
+ subscriber.complete();
1064
+ });
1065
+ });
1066
+ });
1067
+ }
1068
+ /**
1069
+ * Get fields / args from IGraphQLTypeCollection
1070
+ */
1071
+ graphQLTypeCollectionToStringArray(collection, current = '', result = [], cacheNode = []) {
1072
+ if (collection) {
1073
+ if (collection instanceof GraphQLType) {
1074
+ result.push(current);
1075
+ }
1076
+ else {
1077
+ if (current === null || current === void 0 ? void 0 : current.includes('.')) {
1078
+ cacheNode.push(current.split('.')[1]);
1079
+ }
1080
+ else if (current) {
1081
+ cacheNode.push(current);
1082
+ }
1083
+ for (const key of Object.keys(collection)) {
1084
+ if (current === key || cacheNode.includes(key)) {
1085
+ continue;
1086
+ }
1087
+ this.graphQLTypeCollectionToStringArray(collection[key], current ? current + '.' + key : key, result, cacheNode);
1088
+ }
1089
+ }
1090
+ }
1091
+ return result;
1092
+ }
1093
+ /**
1094
+ * Prepare arguments for GraphQL request
1095
+ */
1096
+ prepareArguments(args, options = {}) {
1097
+ // Init config variables
1098
+ const { allowed, level, parent, schemaArgs, usedArgs } = Object.assign({ allowed: null, level: 1, parent: '', schemaArgs: [], usedArgs: [] }, options);
1099
+ // Check args
1100
+ if (args === undefined || args === null) {
1101
+ return { argsString: '', schemaArgs, usedArgs };
1102
+ }
1103
+ // Init args
1104
+ const result = [];
1105
+ // Process array
1106
+ if (Array.isArray(args)) {
1107
+ const allowedKeys = allowed ? Object.keys(allowed) : null;
1108
+ for (const item of args) {
1109
+ let key = null;
1110
+ if (allowed) {
1111
+ if (allowed.length < 1) {
1112
+ break;
1113
+ }
1114
+ key = allowedKeys === null || allowedKeys === void 0 ? void 0 : allowedKeys.shift();
1115
+ }
1116
+ // Process value
1117
+ result.push(this.prepareArguments(item, {
1118
+ allowed: key ? allowed[key] : null,
1119
+ level: level + 1,
1120
+ parent: parent + key + '.',
1121
+ schemaArgs,
1122
+ usedArgs,
1123
+ }).argsString);
1124
+ }
1125
+ // Encapsulation of the array result
1126
+ if (result.length) {
1127
+ // Complete result, encapsulated via round brackets
1128
+ if (level === 1) {
1129
+ return { argsString: '(' + result.join(', ') + ')', schemaArgs, usedArgs };
1130
+ }
1131
+ // Deeper result part, encapsulated via square brackets
1132
+ else {
1133
+ return { argsString: '[' + result.join(', ') + ']', schemaArgs, usedArgs };
1134
+ }
1135
+ }
1136
+ }
1137
+ // Process object
1138
+ else if (typeof args === 'object') {
1139
+ // Check object is empty
1140
+ if (args && Object.keys(args).length === 0 && Object.getPrototypeOf(args) === Object.prototype) {
1141
+ return { argsString: '{}', schemaArgs, usedArgs };
1142
+ }
1143
+ // Process all object entries
1144
+ for (const [key, value] of Object.entries(args)) {
1145
+ // Init data for current entry
1146
+ const currentKey = parent + key;
1147
+ schemaArgs.push(currentKey);
1148
+ // If the allowed key handling is enabled and the current key is not included in the list of allowed keys,
1149
+ // the current key will be skipped
1150
+ if (allowed && !allowed[key]) {
1151
+ continue;
1152
+ }
1153
+ // Skip value if not exists
1154
+ if (value === undefined || value === null) {
1155
+ continue;
1156
+ }
1157
+ // Add current key to metadata
1158
+ usedArgs.push(currentKey);
1159
+ // Process GraphQLEnum
1160
+ if (value instanceof GraphQLEnum) {
1161
+ result.push(key + ':' + value.value);
1162
+ continue;
1163
+ }
1164
+ // Process array
1165
+ else if (Array.isArray(value)) {
1166
+ result.push(key +
1167
+ ': [' +
1168
+ value.map((item) => this.prepareArguments(item, {
1169
+ allowed: allowed[key],
1170
+ level: level + 1,
1171
+ parent: currentKey + '.',
1172
+ schemaArgs,
1173
+ usedArgs,
1174
+ }).argsString) +
1175
+ ']');
1176
+ continue;
1177
+ }
1178
+ // Prepare additional result string
1179
+ let additionalResult = key + ': ';
1180
+ // Value is a date object
1181
+ if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Date]') {
1182
+ additionalResult += `"""${value.toString()}"""`;
1183
+ }
1184
+ // Value is a string
1185
+ else if (typeof value === 'string') {
1186
+ // Enum (doesn't need quotation marks)
1187
+ if (allowed[key].isEnum) {
1188
+ additionalResult += value;
1189
+ }
1190
+ // String
1191
+ else {
1192
+ additionalResult += `"""${value.replace(/"/g, '\\"')}"""`;
1193
+ }
1194
+ }
1195
+ // Value is a simple boolean or a number
1196
+ else if (typeof value === 'boolean' || typeof value === 'number') {
1197
+ additionalResult += value;
1198
+ }
1199
+ // Others
1200
+ else {
1201
+ additionalResult += this.prepareArguments(value, {
1202
+ allowed: allowed[key],
1203
+ level: level + 1,
1204
+ parent: currentKey + '.',
1205
+ schemaArgs,
1206
+ usedArgs,
1207
+ }).argsString;
1208
+ }
1209
+ // Push deeper part into result array
1210
+ result.push(additionalResult);
1211
+ }
1212
+ // Encapsulation of the object result
1213
+ if (result.length) {
1214
+ // Complete result, encapsulated via round brackets
1215
+ if (level === 1) {
1216
+ return { argsString: '(' + result.join(', ') + ')', schemaArgs, usedArgs };
1217
+ }
1218
+ // Deeper result part, encapsulated via curly brackets
1219
+ else {
1220
+ return { argsString: '{' + result.join(', ') + '}', schemaArgs, usedArgs };
1221
+ }
1222
+ }
1223
+ }
1224
+ // Prepare and process other / unknown values as JSON
1225
+ else {
1226
+ return { argsString: JSON.stringify(args), schemaArgs, usedArgs };
1227
+ }
1228
+ }
1229
+ /**
1230
+ * Prepare fields for GraphQL request
1231
+ */
1232
+ prepareFields(fields, options = {}) {
1233
+ // Config
1234
+ const { allowed, parent, schemaFields, spaces, tab, usedFields } = Object.assign({ allowed: null, parent: '', schemaFields: [], spaces: 2, tab: 1, usedFields: [] }, options);
1235
+ // Init fields string
1236
+ let fieldsString = '';
1237
+ // Check fields
1238
+ if (!fields) {
1239
+ return { fieldsString, schemaFields, usedFields };
1240
+ }
1241
+ // Process string
1242
+ if (typeof fields === 'string') {
1243
+ if (allowed &&
1244
+ ((typeof allowed === 'string' && allowed !== fields) || (typeof allowed === 'object' && !allowed[fields]))) {
1245
+ return { fieldsString, schemaFields, usedFields };
1246
+ }
1247
+ return { fieldsString: '\n' + ' '.repeat(spaces).repeat(tab) + fields, schemaFields, usedFields };
1248
+ }
1249
+ // Process array
1250
+ else if (Array.isArray(fields)) {
1251
+ for (const item of fields) {
1252
+ if (typeof item === 'object') {
1253
+ fieldsString =
1254
+ fieldsString +
1255
+ this.prepareFields(item, {
1256
+ allowed,
1257
+ parent,
1258
+ spaces,
1259
+ schemaFields,
1260
+ tab: tab + 1,
1261
+ usedFields,
1262
+ }).fieldsString;
1263
+ continue;
1264
+ }
1265
+ const currentPath = parent + item;
1266
+ schemaFields.push(currentPath);
1267
+ if (allowed && !(allowed === null || allowed === void 0 ? void 0 : allowed[item])) {
1268
+ continue;
1269
+ }
1270
+ usedFields.push(currentPath);
1271
+ fieldsString =
1272
+ fieldsString +
1273
+ this.prepareFields(item, {
1274
+ allowed: typeof (allowed === null || allowed === void 0 ? void 0 : allowed[item]) === 'object' && !((allowed === null || allowed === void 0 ? void 0 : allowed[item]) instanceof GraphQLType) ? allowed === null || allowed === void 0 ? void 0 : allowed[item] : item,
1275
+ parent: currentPath + '.',
1276
+ spaces,
1277
+ schemaFields,
1278
+ tab: tab + 1,
1279
+ usedFields,
1280
+ }).fieldsString;
1281
+ }
1282
+ }
1283
+ // Process object
1284
+ else if (typeof fields === 'object') {
1285
+ for (const [key, val] of Object.entries(fields)) {
1286
+ const currentPath = parent + key;
1287
+ schemaFields.push(currentPath);
1288
+ if (allowed && !allowed[key]) {
1289
+ continue;
1290
+ }
1291
+ usedFields.push(currentPath);
1292
+ if (typeof val !== 'object' || !Object.keys(val).length) {
1293
+ fieldsString = fieldsString + '\n' + ' '.repeat(spaces).repeat(tab) + key;
1294
+ }
1295
+ else {
1296
+ fieldsString =
1297
+ fieldsString +
1298
+ '\n' +
1299
+ ' '.repeat(spaces).repeat(tab) +
1300
+ key +
1301
+ ' ' +
1302
+ '{' +
1303
+ this.prepareFields(val, {
1304
+ allowed: typeof (allowed === null || allowed === void 0 ? void 0 : allowed[key]) === 'object' && !((allowed === null || allowed === void 0 ? void 0 : allowed[key]) instanceof GraphQLType) ? allowed === null || allowed === void 0 ? void 0 : allowed[key] : key,
1305
+ parent: currentPath + '.',
1306
+ spaces,
1307
+ schemaFields,
1308
+ tab: tab + 1,
1309
+ usedFields,
1310
+ }).fieldsString +
1311
+ '\n' +
1312
+ ' '.repeat(spaces).repeat(tab) +
1313
+ '}';
1314
+ }
1315
+ }
1316
+ }
1317
+ // Return result
1318
+ return { fieldsString, schemaFields, usedFields };
1319
+ }
1320
+ }
1321
+ GraphQLService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLService, deps: [{ token: i1.Apollo }, { token: GraphQLMetaService }], target: i0.ɵɵFactoryTarget.Injectable });
1322
+ GraphQLService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLService, providedIn: 'root' });
1323
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLService, decorators: [{
1324
+ type: Injectable,
1325
+ args: [{
1326
+ providedIn: 'root',
1327
+ }]
1328
+ }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }]; } });
1329
+
1330
+ /**
1331
+ * Loader service for loading indication
1332
+ */
1333
+ class LoaderService {
1334
+ constructor() {
1335
+ this.isLoading = new BehaviorSubject(false);
1336
+ }
1337
+ start() {
1338
+ this.isLoading.next(true);
1339
+ }
1340
+ stop() {
1341
+ this.isLoading.next(false);
1342
+ }
1343
+ getAsObservable() {
1344
+ return this.isLoading.asObservable();
1345
+ }
1346
+ }
1347
+ LoaderService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: LoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1348
+ LoaderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: LoaderService, providedIn: 'root' });
1349
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: LoaderService, decorators: [{
1350
+ type: Injectable,
1351
+ args: [{
1352
+ providedIn: 'root',
1353
+ }]
1354
+ }] });
1355
+
1356
+ /**
1357
+ * GraphQL plus service, for extra error handling and loading indication
1358
+ */
1359
+ class GraphQLPlusService extends GraphQLService {
1360
+ /**
1361
+ * Include services
1362
+ */
1363
+ constructor(apollo, graphqlMetaService, loaderService) {
1364
+ super(apollo, graphqlMetaService);
1365
+ this.apollo = apollo;
1366
+ this.graphqlMetaService = graphqlMetaService;
1367
+ this.loaderService = loaderService;
1368
+ }
1369
+ graphQl(graphql, options = {}) {
1370
+ this.handleLoader('start', options);
1371
+ return new Observable((subscriber) => {
1372
+ super.graphQl(graphql, options).subscribe((response) => {
1373
+ if (response && response.errors) {
1374
+ this.handleError(response.errors, options.excludedErrors);
1375
+ subscriber.error(response);
1376
+ this.handleLoader('stop', options);
1377
+ subscriber.complete();
1378
+ }
1379
+ subscriber.next(response);
1380
+ this.handleLoader('stop', options);
1381
+ if (options.type !== GraphQLRequestType.SUBSCRIPTION) {
1382
+ subscriber.complete();
1383
+ }
1384
+ }, (error) => {
1385
+ if (!options.ignoreErrors) {
1386
+ this.handleError(error, options.excludedErrors);
1387
+ }
1388
+ subscriber.error(error);
1389
+ this.handleLoader('stop', options);
1390
+ subscriber.complete();
1391
+ });
1392
+ });
1393
+ }
1394
+ handleLoader(state, options) {
1395
+ if (options.loading) {
1396
+ if (state === 'start') {
1397
+ this.loaderService.start();
1398
+ }
1399
+ else if (state === 'stop') {
1400
+ this.loaderService.stop();
1401
+ }
1402
+ }
1403
+ }
1404
+ handleError(error, excludedErrors = null) {
1405
+ if (excludedErrors) {
1406
+ if (Array.isArray(excludedErrors)) {
1407
+ excludedErrors.forEach((excludedError) => {
1408
+ if (error.message.includes(excludedError.toLowerCase())) {
1409
+ return;
1410
+ }
1411
+ });
1412
+ }
1413
+ else if (error.message.toLowerCase().includes(excludedErrors === null || excludedErrors === void 0 ? void 0 : excludedErrors.toLowerCase())) {
1414
+ return;
1415
+ }
1416
+ }
1417
+ this.displayError(error);
1418
+ }
1419
+ displayError(error) {
1420
+ console.error(error);
1421
+ }
1422
+ }
1423
+ GraphQLPlusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLPlusService, deps: [{ token: i1.Apollo }, { token: GraphQLMetaService }, { token: LoaderService }], target: i0.ɵɵFactoryTarget.Injectable });
1424
+ GraphQLPlusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLPlusService, providedIn: 'root' });
1425
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: GraphQLPlusService, decorators: [{
1426
+ type: Injectable,
1427
+ args: [{
1428
+ providedIn: 'root',
1429
+ }]
1430
+ }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }]; } });
1431
+
1432
+ class FormsService {
1433
+ validateAllFormFields(formGroup) {
1434
+ Object.keys(formGroup.controls).forEach((field) => {
1435
+ const control = formGroup.get(field);
1436
+ if (control instanceof FormControl) {
1437
+ control.markAsTouched({ onlySelf: true });
1438
+ }
1439
+ else if (control instanceof FormGroup) {
1440
+ this.validateAllFormFields(control);
1441
+ }
1442
+ });
1443
+ }
1444
+ }
1445
+ FormsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: FormsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1446
+ FormsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: FormsService, providedIn: 'root' });
1447
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: FormsService, decorators: [{
1448
+ type: Injectable,
1449
+ args: [{
1450
+ providedIn: 'root',
1451
+ }]
1452
+ }] });
1453
+
1454
+ class UserService extends GraphQLPlusService {
1455
+ constructor(apollo, graphqlMetaService, loaderService, authService) {
1456
+ super(apollo, graphqlMetaService, loaderService);
1457
+ this.apollo = apollo;
1458
+ this.graphqlMetaService = graphqlMetaService;
1459
+ this.loaderService = loaderService;
1460
+ this.authService = authService;
1461
+ }
1462
+ /**
1463
+ * Login
1464
+ *
1465
+ * @param input
1466
+ */
1467
+ login(input) {
1468
+ return this.graphQl('signIn', {
1469
+ arguments: { input },
1470
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles'] }],
1471
+ type: GraphQLRequestType.QUERY,
1472
+ loading: true,
1473
+ }).pipe(map$1((response) => {
1474
+ this.authService.token = response.token;
1475
+ this.authService.currentUser = BasicUser.map(response.user);
1476
+ return Auth.map({
1477
+ token: response.token,
1478
+ user: BasicUser.map(response.user),
1479
+ });
1480
+ }));
1481
+ }
1482
+ /**
1483
+ * Register
1484
+ *
1485
+ * @param input
1486
+ */
1487
+ register(input) {
1488
+ return this.graphQl('signUp', {
1489
+ arguments: { input },
1490
+ fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles'] }],
1491
+ type: GraphQLRequestType.MUTATION,
1492
+ loading: true,
1493
+ }).pipe(map$1((response) => {
1494
+ this.authService.token = response.token;
1495
+ this.authService.currentUser = BasicUser.map(response.user);
1496
+ return Auth.map({
1497
+ token: response.token,
1498
+ user: BasicUser.map(response.user),
1499
+ });
1500
+ }));
1501
+ }
1502
+ /**
1503
+ * Request password reset mail
1504
+ *
1505
+ * @param email
1506
+ */
1507
+ requestPasswordResetMail(email) {
1508
+ return this.graphQl('requestPasswordResetMail', {
1509
+ arguments: { email },
1510
+ fields: [],
1511
+ type: GraphQLRequestType.QUERY,
1512
+ loading: true,
1513
+ });
1514
+ }
1515
+ }
1516
+ UserService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: UserService, deps: [{ token: i1.Apollo }, { token: GraphQLMetaService }, { token: LoaderService }, { token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable });
1517
+ UserService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: UserService, providedIn: 'root' });
1518
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: UserService, decorators: [{
1519
+ type: Injectable,
1520
+ args: [{
1521
+ providedIn: 'root',
1522
+ }]
1523
+ }], ctorParameters: function () { return [{ type: i1.Apollo }, { type: GraphQLMetaService }, { type: LoaderService }, { type: AuthService }]; } });
1524
+
1525
+ /**
1526
+ * Image service
1527
+ */
1528
+ class ImageService {
1529
+ /**
1530
+ * Preaload images (for lazy handling)
1531
+ *
1532
+ * @param options
1533
+ * @protected
1534
+ */
1535
+ preLoadImages(options) {
1536
+ // Init configuration
1537
+ const config = Object.assign({ doneFunnction: undefined, elements: document, regExp: undefined }, options);
1538
+ return new Promise((resolve) => {
1539
+ var _a;
1540
+ // Convert element(s) into array
1541
+ if (!Array.isArray(config.elements)) {
1542
+ // NodeList or HTMLCollection
1543
+ if (Helper.isNodeList(config.elements)) {
1544
+ config.elements = Array.from(config.elements);
1545
+ }
1546
+ // Single element
1547
+ else {
1548
+ config.elements = [config.elements];
1549
+ }
1550
+ }
1551
+ // Init loading
1552
+ const promises = [];
1553
+ // Get all images
1554
+ let images = [];
1555
+ config.elements.forEach((element) => {
1556
+ images = images.concat(Array.from(element.getElementsByTagName('img')));
1557
+ });
1558
+ // Prepare images
1559
+ for (let image of images) {
1560
+ const src = image.getAttribute('src');
1561
+ // Check if changes are necessary and possible
1562
+ if ((image.complete && image.naturalHeight !== 0) || // already laoded
1563
+ !src || // Image has no src
1564
+ ((_a = config.regExp) === null || _a === void 0 ? void 0 : _a.test(src)) // Test if src matches regular expression
1565
+ ) {
1566
+ continue;
1567
+ }
1568
+ // Replace lazy loading image with immediately loading image
1569
+ if (image.getAttribute('loading') === 'lazy') {
1570
+ const newImage = document.createElement('img');
1571
+ Array.from(image.attributes).forEach((attr) => {
1572
+ if (attr.name !== 'loading' && attr.name !== 'src') {
1573
+ newImage.setAttribute(attr.name, attr.value);
1574
+ }
1575
+ });
1576
+ image.replaceWith(newImage);
1577
+ image = newImage;
1578
+ }
1579
+ // Wait for laoding
1580
+ promises.push(this.loadImage(image, src));
1581
+ }
1582
+ // Wait until all images loaded
1583
+ Promise.all(promises)
1584
+ .catch((e) => console.error('Error during image loading', e))
1585
+ .finally(() => __awaiter(this, void 0, void 0, function* () {
1586
+ // Return result
1587
+ let result;
1588
+ if (config.doneFunnction) {
1589
+ result = yield config.doneFunction();
1590
+ }
1591
+ resolve(result);
1592
+ }));
1593
+ });
1594
+ }
1595
+ /**
1596
+ * Load image for image element
1597
+ *
1598
+ * @param imageElement
1599
+ * @param src
1600
+ * @protected
1601
+ */
1602
+ loadImage(imageElement, src) {
1603
+ return __awaiter(this, void 0, void 0, function* () {
1604
+ src = src || imageElement.src;
1605
+ return new Promise((resolve, reject) => {
1606
+ imageElement.onload = () => resolve(imageElement);
1607
+ imageElement.onerror = reject;
1608
+ imageElement.src = src;
1609
+ });
1610
+ });
1611
+ }
1612
+ }
1613
+ ImageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ImageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1614
+ ImageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ImageService, providedIn: 'root' });
1615
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ImageService, decorators: [{
1616
+ type: Injectable,
1617
+ args: [{
1618
+ providedIn: 'root',
1619
+ }]
1620
+ }] });
1621
+
1622
+ /**
1623
+ * Scroll service for autoscroll to specific fragments
1624
+ */
1625
+ class ScrollService {
1626
+ /**
1627
+ * Initializer
1628
+ */
1629
+ constructor(router, moduleConfig, imageService) {
1630
+ this.router = router;
1631
+ this.moduleConfig = moduleConfig;
1632
+ this.imageService = imageService;
1633
+ /**
1634
+ * Is a scroll listener set
1635
+ *
1636
+ * @protected
1637
+ */
1638
+ this.scrollListener = false;
1639
+ /**
1640
+ * Current scroll timer;
1641
+ *
1642
+ * @protected
1643
+ */
1644
+ this.scrollTimer = -1;
1645
+ const config = Object.assign({ scrollDetectionOffset: 200, scrollOffset: 100, scrollSamplingRate: 100 }, moduleConfig);
1646
+ this.detectionOffset = config.scrollDetectionOffset;
1647
+ this.scrollOffset = config.scrollOffset;
1648
+ this.scrollSamplingRate = config.scrollSamplingRate;
1649
+ }
1650
+ /**
1651
+ * Scroll to structureElement with specific ID
1652
+ */
1653
+ scrollTo(id, options = {}) {
1654
+ return __awaiter(this, void 0, void 0, function* () {
1655
+ // Prepare config
1656
+ const config = Object.assign({ checkUrl: false, loadImagesBefore: true, resetStyles: false, setOverflow: true, stopPropagation: true }, options);
1657
+ // Check current URL
1658
+ if (config.checkUrl && this.router.url !== '/' && !this.router.url.startsWith('/#')) {
1659
+ yield this.router.navigate(['/'], { fragment: id });
1660
+ return !config.stopPropagation;
1661
+ }
1662
+ // Check if target element exits
1663
+ const el = document.getElementById(id);
1664
+ if (!el) {
1665
+ console.error('Missing scroll element with ID:', id);
1666
+ return !config.stopPropagation;
1667
+ }
1668
+ // Check if body overflow is visible
1669
+ // This is necessary for scroll handling
1670
+ const body = document.querySelector('body');
1671
+ let undoOverflowChanges = false;
1672
+ const scrollBodyStyles = JSON.parse(JSON.stringify(window.getComputedStyle(body)));
1673
+ if (config.setOverflow && (scrollBodyStyles.overflowX !== 'visible' || scrollBodyStyles.overflowY !== 'visible')) {
1674
+ // Set body overflow to visible
1675
+ console.warn('Style of body element for overflowX and overflowY will be set to "visible" for scrolling!');
1676
+ body.style.overflowX = 'visible';
1677
+ body.style.overflowY = 'visible';
1678
+ undoOverflowChanges = true;
1679
+ }
1680
+ // Load images before scrolling (once)
1681
+ if (config.loadImagesBefore) {
1682
+ yield this.imageService.preLoadImages();
1683
+ }
1684
+ // Get get bounding rect of target element
1685
+ const cords = el.getBoundingClientRect();
1686
+ // Scroll to element
1687
+ window.scrollBy({ top: cords.top - this.scrollOffset, behavior: 'smooth' });
1688
+ yield this.scrollDone({
1689
+ doneFunction: () => {
1690
+ // Undo changes
1691
+ if (undoOverflowChanges && config.resetStyles) {
1692
+ body.style.overflowX = scrollBodyStyles.overflowX;
1693
+ body.style.overflowY = scrollBodyStyles.overflowY;
1694
+ console.warn('Original style of body element for overflowX and overflowY is set.');
1695
+ }
1696
+ },
1697
+ });
1698
+ // Return stop propagation configuration
1699
+ return !config.stopPropagation;
1700
+ });
1701
+ }
1702
+ /**
1703
+ * Get last active structureElement
1704
+ */
1705
+ getLastActiveElement(list) {
1706
+ const currentScrollPosition = window.scrollY;
1707
+ const elementsWithId = document.querySelectorAll('[id]');
1708
+ let lastId = null;
1709
+ let lastPosition = 0 - this.detectionOffset - 1;
1710
+ elementsWithId.forEach((element) => {
1711
+ const cords = element.getBoundingClientRect();
1712
+ const top = cords.top + window.pageYOffset - this.detectionOffset;
1713
+ if ((!list || !list.length || list.includes(element.id)) && // In list
1714
+ top < currentScrollPosition && // In active area
1715
+ lastPosition < top // Higher than the last one
1716
+ ) {
1717
+ lastId = element.id;
1718
+ lastPosition = top;
1719
+ }
1720
+ });
1721
+ return lastId;
1722
+ }
1723
+ /**
1724
+ * Check if ID is active
1725
+ */
1726
+ isActive(id, list, isFirst) {
1727
+ const lastActiveElement = this.getLastActiveElement(list);
1728
+ return id === lastActiveElement || (lastActiveElement === null && isFirst);
1729
+ }
1730
+ /**
1731
+ * Scroll done promise
1732
+ */
1733
+ scrollDone(options = {}) {
1734
+ return __awaiter(this, void 0, void 0, function* () {
1735
+ // Init configuration
1736
+ const config = Object.assign({ doneFunction: undefined }, options);
1737
+ // Wait for scroll done
1738
+ yield this.scrollDoneDetection();
1739
+ // Get result
1740
+ if (config.doneFunction) {
1741
+ return config.doneFunction();
1742
+ }
1743
+ });
1744
+ }
1745
+ /**
1746
+ * Scroll done detecton
1747
+ *
1748
+ * @protected
1749
+ */
1750
+ scrollDoneDetection() {
1751
+ // Return current scroll promise (Singelton)
1752
+ if (this.scrollPromise) {
1753
+ return this.scrollPromise;
1754
+ }
1755
+ // Create current scroll promise
1756
+ this.scrollPromise = new Promise((resolve) => {
1757
+ this.scrollPromiseResolve = resolve;
1758
+ if (this.scrollTimer !== -1) {
1759
+ window.clearTimeout(this.scrollTimer);
1760
+ }
1761
+ this.scrollTimer = window.setTimeout(() => {
1762
+ window.removeEventListener('scroll', this.scrollDoneDetection.bind(this));
1763
+ this.scrollPromise = undefined;
1764
+ resolve();
1765
+ }, this.scrollSamplingRate);
1766
+ });
1767
+ // Lisitening to scroll event;
1768
+ window.addEventListener('scroll', this.scrollDoneDetection.bind(this));
1769
+ // Return promise
1770
+ return this.scrollPromise;
1771
+ }
1772
+ }
1773
+ ScrollService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ScrollService, deps: [{ token: i1$1.Router }, { token: BASE_MODULE_CONFIG }, { token: ImageService }], target: i0.ɵɵFactoryTarget.Injectable });
1774
+ ScrollService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ScrollService, providedIn: 'root' });
1775
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.3", ngImport: i0, type: ScrollService, decorators: [{
1776
+ type: Injectable,
1777
+ args: [{
1778
+ providedIn: 'root',
1779
+ }]
1780
+ }], ctorParameters: function () {
1781
+ return [{ type: i1$1.Router }, { type: undefined, decorators: [{
1782
+ type: Inject,
1783
+ args: [BASE_MODULE_CONFIG]
1784
+ }] }, { type: ImageService }];
1785
+ } });
1786
+
1787
+ /**
1788
+ * Comparison operator enum
1789
+ */
1790
+ var ComparisonOperatorEnum;
1791
+ (function (ComparisonOperatorEnum) {
1792
+ ComparisonOperatorEnum["EQ"] = "EQ";
1793
+ ComparisonOperatorEnum["GT"] = "GT";
1794
+ ComparisonOperatorEnum["GTE"] = "GTE";
1795
+ ComparisonOperatorEnum["IN"] = "IN";
1796
+ ComparisonOperatorEnum["LT"] = "LT";
1797
+ ComparisonOperatorEnum["LTE"] = "LTE";
1798
+ ComparisonOperatorEnum["NE"] = "NE";
1799
+ ComparisonOperatorEnum["NIN"] = "NIN";
1800
+ ComparisonOperatorEnum["REGEX"] = "REGEX";
1801
+ })(ComparisonOperatorEnum || (ComparisonOperatorEnum = {}));
1802
+
1803
+ /**
1804
+ * Logical operator enum
1805
+ */
1806
+ var LogicalOperatorEnum;
1807
+ (function (LogicalOperatorEnum) {
1808
+ LogicalOperatorEnum["AND"] = "AND";
1809
+ LogicalOperatorEnum["NOR"] = "NOR";
1810
+ LogicalOperatorEnum["OR"] = "OR";
1811
+ })(LogicalOperatorEnum || (LogicalOperatorEnum = {}));
1812
+
1813
+ var SortOrderEnum;
1814
+ (function (SortOrderEnum) {
1815
+ SortOrderEnum["ASC"] = "ASC";
1816
+ SortOrderEnum["DESC"] = "DESC";
1817
+ })(SortOrderEnum || (SortOrderEnum = {}));
1818
+
1819
+ class Validation {
1820
+ static match(controlName, checkControlName) {
1821
+ return (controls) => {
1822
+ var _a, _b;
1823
+ const control = controls.get(controlName);
1824
+ const checkControl = controls.get(checkControlName);
1825
+ if ((checkControl === null || checkControl === void 0 ? void 0 : checkControl.errors) && !((_a = checkControl.errors) === null || _a === void 0 ? void 0 : _a.matching)) {
1826
+ return null;
1827
+ }
1828
+ if ((control === null || control === void 0 ? void 0 : control.value) !== (checkControl === null || checkControl === void 0 ? void 0 : checkControl.value)) {
1829
+ (_b = controls.get(checkControlName)) === null || _b === void 0 ? void 0 : _b.setErrors({ matching: true });
1830
+ return { matching: true };
1831
+ }
1832
+ else {
1833
+ return null;
1834
+ }
1835
+ };
1836
+ }
1837
+ }
1838
+
1839
+ function createRestartableClient(options) {
1840
+ let restartRequested = false;
1841
+ let restart = () => {
1842
+ restartRequested = true;
1843
+ };
1844
+ const { on = undefined } = options;
1845
+ const client = createClient(Object.assign(Object.assign({}, options), { on: Object.assign(Object.assign({}, on), { connected: (socket) => {
1846
+ var _a;
1847
+ // @ts-ignore
1848
+ (_a = on === null || on === void 0 ? void 0 : on.connected) === null || _a === void 0 ? void 0 : _a.call(on, socket);
1849
+ restart = () => {
1850
+ if (socket.readyState === WebSocket.OPEN) {
1851
+ // if the socket is still open for the restart, do the restart
1852
+ socket.close(4205, 'Client Restart');
1853
+ }
1854
+ else {
1855
+ // otherwise the socket might've closed, indicate that you want
1856
+ // a restart on the next connected event
1857
+ restartRequested = true;
1858
+ }
1859
+ };
1860
+ // just in case you were eager to restart
1861
+ if (restartRequested) {
1862
+ restartRequested = false;
1863
+ restart();
1864
+ }
1865
+ } }) }));
1866
+ return Object.assign(Object.assign({}, client), { restart: () => restart() });
1867
+ }
1868
+
1869
+ /**
1870
+ * Exports for public API
1871
+ */
1872
+
1873
+ /**
1874
+ * Generated bundle index. Do not edit.
1875
+ */
1876
+
1877
+ export { Auth, AuthService, BASE_MODULE_CONFIG, BasicUser, ComparisonOperatorEnum, FormsService, GraphQLEnum, GraphQLMeta, GraphQLMetaService, GraphQLPlusService, GraphQLRequestType, GraphQLService, GraphQLType, Helper, ImageService, LoaderService, LogicalOperatorEnum, ScrollService, SortOrderEnum, Standard, StorageService, UserService, Validation, WsService, createRestartableClient };
1878
+ //# sourceMappingURL=lenne.tech-ng-base-shared.mjs.map