@daffodil/core 0.85.0 → 0.87.0
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.
- package/fesm2022/daffodil-core.mjs +533 -526
- package/fesm2022/daffodil-core.mjs.map +1 -1
- package/graphql/apollo/public_api.d.ts +1 -0
- package/graphql/apollo/validator/type.d.ts +8 -0
- package/package.json +1 -1
- package/public_api.d.ts +8 -7
- package/types/html.type.d.ts +5 -0
- package/types/public_api.d.ts +1 -0
- package/validator/field-presence.d.ts +6 -0
- package/validator/public_api.d.ts +1 -0
|
@@ -1,383 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as i0 from '@angular/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { retryWhen, mergeMap } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Recurses through a tree, collecting each element in that tree and returning it in an array.
|
|
9
|
-
* The value of getKey should be a field that contains a list of the same type of object.
|
|
10
|
-
* Accepts an optional depth argument which will limit the traversal. This should be used for trees with circular references.
|
|
11
|
-
*/
|
|
12
|
-
const collect = (obj, getChildren, depth) => !depth || depth > 0
|
|
13
|
-
? [obj].concat(...getChildren(obj).map((child) => collect(child, getChildren, depth - 1)))
|
|
14
|
-
: [obj];
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A helper function to compute a power of 10 required to convert a decimal number to an integer
|
|
18
|
-
* This function will fail if the given number has more than 16 significant figures or
|
|
19
|
-
* the value of the number is greater than 10^11
|
|
20
|
-
*
|
|
21
|
-
* @param number
|
|
22
|
-
*/
|
|
23
|
-
function daffPrecision(number) {
|
|
24
|
-
let p = 1;
|
|
25
|
-
if (number === undefined ||
|
|
26
|
-
number === null ||
|
|
27
|
-
Number.isNaN(number) ||
|
|
28
|
-
number === Infinity ||
|
|
29
|
-
number === -Infinity) {
|
|
30
|
-
return p;
|
|
31
|
-
}
|
|
32
|
-
while (Math.round(number * p) / p !== number) {
|
|
33
|
-
p *= 10;
|
|
34
|
-
if (p >= 1e11) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return p;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* A function to add long numbers accurately with conversions and integer math.
|
|
42
|
-
* This function only guarantees correct answers when the numbers given and the result are less than
|
|
43
|
-
* 16 significant figures and less than 10^11
|
|
44
|
-
*
|
|
45
|
-
* @param numbers
|
|
46
|
-
*/
|
|
47
|
-
function daffAdd(...numbers) {
|
|
48
|
-
if (numbers.length === 0) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
if (numbers.length === 1) {
|
|
52
|
-
return numbers[0];
|
|
53
|
-
}
|
|
54
|
-
const precision = Math.max(...numbers.map(daffPrecision));
|
|
55
|
-
return numbers.slice(1).reduce((acc, number) => acc + Math.round(number * precision), Math.round(numbers[0] * precision)) / precision;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A function to subtract long numbers accurately with conversions and integer math.
|
|
59
|
-
* This function only guarantees correct answers when the numbers given and the result are each less than
|
|
60
|
-
* 16 significant figures and less than 10^11
|
|
61
|
-
*
|
|
62
|
-
* @param numbers
|
|
63
|
-
*/
|
|
64
|
-
function daffSubtract(...numbers) {
|
|
65
|
-
if (numbers.length === 0) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
if (numbers.length === 1) {
|
|
69
|
-
return numbers[0];
|
|
70
|
-
}
|
|
71
|
-
const precision = Math.max(...numbers.map(daffPrecision));
|
|
72
|
-
return numbers.slice(1).reduce((acc, number) => acc - Math.round(number * precision), Math.round(numbers[0] * precision)) / precision;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* A function to multiply long numbers accurately with conversions and integer math.
|
|
76
|
-
* This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
|
|
77
|
-
* and less than 10^11
|
|
78
|
-
*
|
|
79
|
-
* @param numbers
|
|
80
|
-
*/
|
|
81
|
-
function daffMultiply(...numbers) {
|
|
82
|
-
if (numbers.length === 0) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
if (numbers.length === 1) {
|
|
86
|
-
return numbers[0];
|
|
87
|
-
}
|
|
88
|
-
const precision = Math.max(...numbers.map(daffPrecision));
|
|
89
|
-
return numbers.reduce((acc, number) => acc * Math.round(number * precision), 1) / Math.pow(precision, numbers.length);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* A function to divide long numbers accurately with conversions and integer math.
|
|
93
|
-
* This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
|
|
94
|
-
* and less than 10^11
|
|
95
|
-
*
|
|
96
|
-
* Returns NaN when attempting to use NaN as an input.
|
|
97
|
-
* Returns NaN when attempting to divide by 0 or null.
|
|
98
|
-
*
|
|
99
|
-
* @param numbers
|
|
100
|
-
*/
|
|
101
|
-
function daffDivide(...numbers) {
|
|
102
|
-
if (numbers.length === 0) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
if (numbers.length === 1) {
|
|
106
|
-
return numbers[0];
|
|
107
|
-
}
|
|
108
|
-
const precision = Math.max(...numbers.map(daffPrecision));
|
|
109
|
-
return numbers.slice(1).reduce((acc, number) => acc / Math.round(number * precision), Math.round(numbers[0] * precision)) * Math.pow(precision, numbers.length - 2);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Converts an array into a dictionary.
|
|
114
|
-
* Dictionary values are keyed by the return of the specified `getKey`.
|
|
115
|
-
*/
|
|
116
|
-
const daffArrayToDict = (array, getKey) => array.reduce((dict, val) => {
|
|
117
|
-
dict[getKey(val)] = val;
|
|
118
|
-
return dict;
|
|
119
|
-
}, {});
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Returns a random slice of an array.
|
|
123
|
-
* An optional length may be specified.
|
|
124
|
-
*
|
|
125
|
-
* @param array
|
|
126
|
-
*/
|
|
127
|
-
const randomSlice = (array, length) => {
|
|
128
|
-
if (array.length === 0) {
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
131
|
-
;
|
|
132
|
-
if (length > array.length) {
|
|
133
|
-
throw new Error('Requested length is longer than array length.');
|
|
134
|
-
}
|
|
135
|
-
const arrayLength = length || Math.floor(Math.random() * array.length);
|
|
136
|
-
const start = Math.floor(Math.random() * (array.length - arrayLength + 1));
|
|
137
|
-
const end = start + arrayLength;
|
|
138
|
-
return array.slice(start, end);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Immutable Fisher-Yates Shuffle
|
|
143
|
-
* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
144
|
-
*/
|
|
145
|
-
const shuffle = (array) => {
|
|
146
|
-
const result = [];
|
|
147
|
-
array.forEach((el, i) => {
|
|
148
|
-
const s = Math.floor(Math.random() * (i + 1));
|
|
149
|
-
if (s !== i) {
|
|
150
|
-
result[i] = result[s];
|
|
151
|
-
}
|
|
152
|
-
result[s] = el;
|
|
153
|
-
});
|
|
154
|
-
return result;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Returns a random subset of an array in a random order.
|
|
159
|
-
*
|
|
160
|
-
* @param array
|
|
161
|
-
* @param length
|
|
162
|
-
*/
|
|
163
|
-
const randomSubset = (array, length) => {
|
|
164
|
-
if (length > array.length) {
|
|
165
|
-
throw new Error('Requested length is longer than array length.');
|
|
166
|
-
}
|
|
167
|
-
length = length ? length : Math.floor(Math.random() * array.length);
|
|
168
|
-
return shuffle(array).slice(0, length);
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Range
|
|
173
|
-
*
|
|
174
|
-
* Range accepts two inputs, a `start` and an `end`
|
|
175
|
-
* and returns an array filled with numbers from
|
|
176
|
-
* `start` to `end`.
|
|
177
|
-
*
|
|
178
|
-
* @param start
|
|
179
|
-
* @param end
|
|
180
|
-
* @returns number
|
|
181
|
-
*/
|
|
182
|
-
const range = (start, end) => Array(end - start + 1).fill(0).map((val, index) => index + start);
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Returns a random element of an array.
|
|
186
|
-
*/
|
|
187
|
-
const sample = (array) => randomSlice(array, 1)[0];
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Shallow compares two objects using a list of provided property keys to enumerate the values.
|
|
191
|
-
* `null` and `undefined` are considered equal for the purposes of the comparison.
|
|
192
|
-
* A strict equality comparison is used for truthy property values.
|
|
193
|
-
*/
|
|
194
|
-
function shallowCompare(obj1, obj2, props) {
|
|
195
|
-
return !!(obj1 && obj2 && props.reduce((acc, prop) => {
|
|
196
|
-
const p1 = obj1[prop];
|
|
197
|
-
const p2 = obj2[prop];
|
|
198
|
-
return acc && (
|
|
199
|
-
// undefined and null are treated as equal
|
|
200
|
-
(p1 === undefined || p1 === null) && (p2 === undefined || p2 === null)
|
|
201
|
-
|| p1 === p2);
|
|
202
|
-
}, true));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Filters an array of elements, removing duplicates.
|
|
207
|
-
* Does not guarantee order of filtered elements.
|
|
208
|
-
*
|
|
209
|
-
* An optional comparator function may be passed for arbitrary comparison behavior.
|
|
210
|
-
* The default is a strict equality comparison: `a === b`.
|
|
211
|
-
*/
|
|
212
|
-
const unique = (array, comparator = (a, b) => a === b) => array.filter((a, index) => array.slice(index + 1).filter(b => comparator(a, b)).length === 0);
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* The unary identity function.
|
|
216
|
-
* Returns whatever is passed to it.
|
|
217
|
-
*/
|
|
218
|
-
function identity(v) {
|
|
219
|
-
return v;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Converts a value to an observable.
|
|
224
|
-
* If the value is an observable, just returns that observable.
|
|
225
|
-
* If the value is a promise, converts it to an observable (see rxjs `from`).
|
|
226
|
-
* If the value is neither, just returns an observable that immediately emits the value.
|
|
227
|
-
*/
|
|
228
|
-
function observe(val) {
|
|
229
|
-
return isObservable(val) ? val : from(Promise.resolve(val));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* A class which allows you to appropriately check the inheritance of an error.
|
|
234
|
-
*
|
|
235
|
-
* In typescript, when you try to extend an error with a specialized error class,
|
|
236
|
-
* if you try to call something like:
|
|
237
|
-
*
|
|
238
|
-
* ```ts
|
|
239
|
-
* class MyError extends Error {}
|
|
240
|
-
*
|
|
241
|
-
* let myError = new MyError();
|
|
242
|
-
*
|
|
243
|
-
* myError instanceof MyError; // returns false
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* You will see unexpected things. This class fixes that issue as described here
|
|
247
|
-
* https://github.com/microsoft/TypeScript/issues/13965
|
|
248
|
-
*/
|
|
249
|
-
class DaffInheritableError extends Error {
|
|
250
|
-
constructor(message) {
|
|
251
|
-
super(message);
|
|
252
|
-
this.recoverable = false;
|
|
253
|
-
const trueProto = new.target.prototype;
|
|
254
|
-
Object.setPrototypeOf(this, trueProto);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Checks if the passed object is a {@link DaffError}
|
|
260
|
-
*/
|
|
261
|
-
const daffIsError = (error) => error instanceof DaffInheritableError || !!error.code;
|
|
262
|
-
|
|
263
|
-
const DAFF_STORAGE_SERVICE_ERROR_CODE = 'DAFF_STORAGE_FAILURE';
|
|
264
|
-
class DaffStorageServiceError extends DaffInheritableError {
|
|
265
|
-
constructor(message) {
|
|
266
|
-
super(message);
|
|
267
|
-
this.message = message;
|
|
268
|
-
this.code = DAFF_STORAGE_SERVICE_ERROR_CODE;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* @inheritdoc
|
|
274
|
-
*/
|
|
275
|
-
class DaffErrorStorageService {
|
|
276
|
-
static { this.ERROR_MESSAGE = 'The DaffErrorStorageService always throws an error.'; }
|
|
277
|
-
setItem(key, value) {
|
|
278
|
-
this.throwError();
|
|
279
|
-
}
|
|
280
|
-
getItem(key) {
|
|
281
|
-
this.throwError();
|
|
282
|
-
}
|
|
283
|
-
removeItem(key) {
|
|
284
|
-
this.throwError();
|
|
285
|
-
}
|
|
286
|
-
clear() {
|
|
287
|
-
this.throwError();
|
|
288
|
-
}
|
|
289
|
-
throwError() {
|
|
290
|
-
throw new DaffStorageServiceError(DaffErrorStorageService.ERROR_MESSAGE);
|
|
291
|
-
}
|
|
292
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
293
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, providedIn: 'root' }); }
|
|
294
|
-
}
|
|
295
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, decorators: [{
|
|
296
|
-
type: Injectable,
|
|
297
|
-
args: [{
|
|
298
|
-
providedIn: 'root',
|
|
299
|
-
}]
|
|
300
|
-
}] });
|
|
301
|
-
|
|
302
|
-
const DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE = 'DAFF_SERVER_STORAGE_FAILURE';
|
|
303
|
-
/**
|
|
304
|
-
* An error thrown when there is an attempt to access storage on the server and none is available.
|
|
305
|
-
*/
|
|
306
|
-
class DaffServerSideStorageError extends DaffStorageServiceError {
|
|
307
|
-
constructor(message) {
|
|
308
|
-
super(message);
|
|
309
|
-
this.message = message;
|
|
310
|
-
this.code = DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { PLATFORM_ID, Inject, Injectable, InjectionToken, inject } from '@angular/core';
|
|
4
|
+
import { from, isObservable, pipe, throwError, timer, combineLatest, map, catchError } from 'rxjs';
|
|
5
|
+
import { retryWhen, mergeMap } from 'rxjs/operators';
|
|
313
6
|
|
|
314
7
|
/**
|
|
315
|
-
* A
|
|
316
|
-
* It will always throw the {@link DaffServerSideStorageError}.
|
|
8
|
+
* A base64 service meant to be loaded into SSR contexts.
|
|
317
9
|
*
|
|
318
10
|
* @inheritdoc
|
|
319
11
|
*/
|
|
320
|
-
class
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
getItem(key) {
|
|
326
|
-
this.throwError();
|
|
327
|
-
}
|
|
328
|
-
removeItem(key) {
|
|
329
|
-
this.throwError();
|
|
12
|
+
class DaffServerBase64Service {
|
|
13
|
+
constructor(platformId) {
|
|
14
|
+
if (isPlatformBrowser(platformId)) {
|
|
15
|
+
throw new Error('The DaffBrowserBase64Service can only be instantiated on the server.');
|
|
16
|
+
}
|
|
330
17
|
}
|
|
331
|
-
|
|
332
|
-
|
|
18
|
+
encode(str) {
|
|
19
|
+
return Buffer.from(str).toString('base64');
|
|
333
20
|
}
|
|
334
|
-
|
|
335
|
-
|
|
21
|
+
decode(str) {
|
|
22
|
+
return Buffer.from(str, 'base64').toString('ascii');
|
|
336
23
|
}
|
|
337
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
338
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
24
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
25
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, providedIn: 'root' }); }
|
|
339
26
|
}
|
|
340
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
27
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, decorators: [{
|
|
341
28
|
type: Injectable,
|
|
342
29
|
args: [{
|
|
343
30
|
providedIn: 'root',
|
|
344
31
|
}]
|
|
345
|
-
}]
|
|
32
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
33
|
+
type: Inject,
|
|
34
|
+
args: [PLATFORM_ID]
|
|
35
|
+
}] }] });
|
|
346
36
|
|
|
347
37
|
/**
|
|
348
38
|
* @inheritdoc
|
|
349
39
|
*/
|
|
350
|
-
class
|
|
40
|
+
class DaffBrowserBase64Service {
|
|
351
41
|
constructor(platformId) {
|
|
352
42
|
if (!isPlatformBrowser(platformId)) {
|
|
353
|
-
throw new Error('The
|
|
43
|
+
throw new Error('The DaffBrowserBase64Service can only be instantiated in the browser.');
|
|
354
44
|
}
|
|
355
45
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*/
|
|
359
|
-
setItem(key, value) {
|
|
360
|
-
localStorage.setItem(key, value);
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Retrieve the given item from localstorage.
|
|
364
|
-
*/
|
|
365
|
-
getItem(key) {
|
|
366
|
-
return localStorage.getItem(key);
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Remove a given item from localstorage
|
|
370
|
-
*/
|
|
371
|
-
removeItem(key) {
|
|
372
|
-
localStorage.removeItem(key);
|
|
46
|
+
encode(str) {
|
|
47
|
+
return btoa(str);
|
|
373
48
|
}
|
|
374
|
-
|
|
375
|
-
|
|
49
|
+
decode(str) {
|
|
50
|
+
return atob(str);
|
|
376
51
|
}
|
|
377
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
378
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
52
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
53
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, providedIn: 'root' }); }
|
|
379
54
|
}
|
|
380
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type:
|
|
55
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, decorators: [{
|
|
381
56
|
type: Injectable,
|
|
382
57
|
args: [{
|
|
383
58
|
providedIn: 'root',
|
|
@@ -387,28 +62,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImpo
|
|
|
387
62
|
args: [PLATFORM_ID]
|
|
388
63
|
}] }] });
|
|
389
64
|
|
|
390
|
-
/**
|
|
391
|
-
* @inheritdoc
|
|
392
|
-
*/
|
|
393
|
-
class DaffNoopStorageService {
|
|
394
|
-
setItem(key, value) { }
|
|
395
|
-
;
|
|
396
|
-
getItem(key) { }
|
|
397
|
-
;
|
|
398
|
-
clear() { }
|
|
399
|
-
;
|
|
400
|
-
removeItem(key) { }
|
|
401
|
-
;
|
|
402
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
403
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, providedIn: 'root' }); }
|
|
404
|
-
}
|
|
405
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, decorators: [{
|
|
406
|
-
type: Injectable,
|
|
407
|
-
args: [{
|
|
408
|
-
providedIn: 'root',
|
|
409
|
-
}]
|
|
410
|
-
}] });
|
|
411
|
-
|
|
412
65
|
/**
|
|
413
66
|
* Creates an injection token/provider pair for a single valued DI token.
|
|
414
67
|
*
|
|
@@ -514,147 +167,62 @@ const createSingletonInjectionToken = (desc, options) => {
|
|
|
514
167
|
};
|
|
515
168
|
};
|
|
516
169
|
|
|
517
|
-
const { token: DaffPersistenceServiceToken,
|
|
518
|
-
/**
|
|
519
|
-
* Provider function for {@link DaffPersistenceServiceToken}.
|
|
520
|
-
*/
|
|
521
|
-
provider: provideDaffPersistenceService, } = createSingleInjectionToken('DaffPersistenceServiceToken', {
|
|
522
|
-
providedIn: 'root',
|
|
523
|
-
factory: () => isPlatformBrowser(inject(PLATFORM_ID))
|
|
524
|
-
? new DaffLocalStorageService(inject(PLATFORM_ID))
|
|
525
|
-
: new DaffServerErrorStorageService(),
|
|
526
|
-
});
|
|
527
|
-
|
|
528
170
|
const {
|
|
529
171
|
/**
|
|
530
|
-
*
|
|
172
|
+
* A token which creates a base64 service appropriate for the current environment, i.e., browser vs. server.
|
|
531
173
|
*/
|
|
532
|
-
token:
|
|
174
|
+
token: DaffBase64ServiceToken,
|
|
533
175
|
/**
|
|
534
|
-
* Provider function for {@link
|
|
176
|
+
* Provider function for {@link DaffBase64ServiceToken}.
|
|
535
177
|
*/
|
|
536
|
-
provider:
|
|
178
|
+
provider: provideDaffBase64Service, } = createSingleInjectionToken('DaffBase64ServiceToken', {
|
|
537
179
|
providedIn: 'root',
|
|
538
180
|
factory: () => isPlatformBrowser(inject(PLATFORM_ID))
|
|
539
|
-
? inject(
|
|
540
|
-
: inject(
|
|
181
|
+
? new DaffBrowserBase64Service(inject(PLATFORM_ID))
|
|
182
|
+
: new DaffServerBase64Service(inject(PLATFORM_ID)),
|
|
541
183
|
});
|
|
542
184
|
|
|
543
185
|
/**
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* @param ms The initial amount of time
|
|
548
|
-
*/
|
|
549
|
-
function backoff(maxTries, ms) {
|
|
550
|
-
return pipe(retryWhen(attempt => attempt.pipe(mergeMap((shadowedAttempt, i) => {
|
|
551
|
-
if (i >= maxTries) {
|
|
552
|
-
return throwError(shadowedAttempt);
|
|
553
|
-
}
|
|
554
|
-
return timer(ms * Math.pow(2, i));
|
|
555
|
-
}))));
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Accepts a list of input observables and emits true when any of the inputs emit a truthy value.
|
|
560
|
-
* Does not emit until all of the input streams have emitted at least once.
|
|
561
|
-
*/
|
|
562
|
-
const anyOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg || el, false)));
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Accepts a list of input observables and emits true when all of the inputs emit a truthy value.
|
|
566
|
-
* Does not emit until all of the input streams have emitted at least once.
|
|
567
|
-
*/
|
|
568
|
-
const allOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg && el, true)));
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Catches errors and invokes the callback with an array of errors.
|
|
186
|
+
* The direction in which to sort a list of elements, e.g. if the list was
|
|
187
|
+
* sorted alphabetically, "Ascending" would be from "A-Z",
|
|
188
|
+
* and "Descending" would be from "Z-A".
|
|
572
189
|
*/
|
|
573
|
-
|
|
190
|
+
var DaffSortDirectionEnum;
|
|
191
|
+
(function (DaffSortDirectionEnum) {
|
|
192
|
+
DaffSortDirectionEnum["Ascending"] = "ASC";
|
|
193
|
+
DaffSortDirectionEnum["Descending"] = "DSC";
|
|
194
|
+
})(DaffSortDirectionEnum || (DaffSortDirectionEnum = {}));
|
|
574
195
|
|
|
575
196
|
/**
|
|
576
|
-
* A
|
|
197
|
+
* A class which allows you to appropriately check the inheritance of an error.
|
|
577
198
|
*
|
|
578
|
-
*
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
593
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, providedIn: 'root' }); }
|
|
594
|
-
}
|
|
595
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerBase64Service, decorators: [{
|
|
596
|
-
type: Injectable,
|
|
597
|
-
args: [{
|
|
598
|
-
providedIn: 'root',
|
|
599
|
-
}]
|
|
600
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
601
|
-
type: Inject,
|
|
602
|
-
args: [PLATFORM_ID]
|
|
603
|
-
}] }] });
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* @inheritdoc
|
|
607
|
-
*/
|
|
608
|
-
class DaffBrowserBase64Service {
|
|
609
|
-
constructor(platformId) {
|
|
610
|
-
if (!isPlatformBrowser(platformId)) {
|
|
611
|
-
throw new Error('The DaffBrowserBase64Service can only be instantiated in the browser.');
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
encode(str) {
|
|
615
|
-
return btoa(str);
|
|
616
|
-
}
|
|
617
|
-
decode(str) {
|
|
618
|
-
return atob(str);
|
|
619
|
-
}
|
|
620
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
621
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, providedIn: 'root' }); }
|
|
622
|
-
}
|
|
623
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffBrowserBase64Service, decorators: [{
|
|
624
|
-
type: Injectable,
|
|
625
|
-
args: [{
|
|
626
|
-
providedIn: 'root',
|
|
627
|
-
}]
|
|
628
|
-
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
629
|
-
type: Inject,
|
|
630
|
-
args: [PLATFORM_ID]
|
|
631
|
-
}] }] });
|
|
632
|
-
|
|
633
|
-
const {
|
|
634
|
-
/**
|
|
635
|
-
* A token which creates a base64 service appropriate for the current environment, i.e., browser vs. server.
|
|
636
|
-
*/
|
|
637
|
-
token: DaffBase64ServiceToken,
|
|
638
|
-
/**
|
|
639
|
-
* Provider function for {@link DaffBase64ServiceToken}.
|
|
199
|
+
* In typescript, when you try to extend an error with a specialized error class,
|
|
200
|
+
* if you try to call something like:
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* class MyError extends Error {}
|
|
204
|
+
*
|
|
205
|
+
* let myError = new MyError();
|
|
206
|
+
*
|
|
207
|
+
* myError instanceof MyError; // returns false
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* You will see unexpected things. This class fixes that issue as described here
|
|
211
|
+
* https://github.com/microsoft/TypeScript/issues/13965
|
|
640
212
|
*/
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
213
|
+
class DaffInheritableError extends Error {
|
|
214
|
+
constructor(message) {
|
|
215
|
+
super(message);
|
|
216
|
+
this.recoverable = false;
|
|
217
|
+
const trueProto = new.target.prototype;
|
|
218
|
+
Object.setPrototypeOf(this, trueProto);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
647
221
|
|
|
648
222
|
/**
|
|
649
|
-
*
|
|
650
|
-
* sorted alphabetically, "Ascending" would be from "A-Z",
|
|
651
|
-
* and "Descending" would be from "Z-A".
|
|
223
|
+
* Checks if the passed object is a {@link DaffError}
|
|
652
224
|
*/
|
|
653
|
-
|
|
654
|
-
(function (DaffSortDirectionEnum) {
|
|
655
|
-
DaffSortDirectionEnum["Ascending"] = "ASC";
|
|
656
|
-
DaffSortDirectionEnum["Descending"] = "DSC";
|
|
657
|
-
})(DaffSortDirectionEnum || (DaffSortDirectionEnum = {}));
|
|
225
|
+
const daffIsError = (error) => error instanceof DaffInheritableError || !!error.code;
|
|
658
226
|
|
|
659
227
|
const DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE = 'DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS';
|
|
660
228
|
/**
|
|
@@ -1154,38 +722,263 @@ const daffFilterRangeToRequest = (filter) => {
|
|
|
1154
722
|
};
|
|
1155
723
|
|
|
1156
724
|
/**
|
|
1157
|
-
* Transforms a {@link DaffFilterRangeNumeric} into a {@link DaffFilterRangeNumericRequest}
|
|
725
|
+
* Transforms a {@link DaffFilterRangeNumeric} into a {@link DaffFilterRangeNumericRequest}
|
|
726
|
+
*/
|
|
727
|
+
const daffFilterRangeNumericToRequest = (filter) => daffFilterRangeToRequest(filter);
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Builds a filter request from a filter.
|
|
731
|
+
* Returns null if the filter does not have at least one applied option.
|
|
732
|
+
*/
|
|
733
|
+
function daffFilterToRequest(filter) {
|
|
734
|
+
switch (filter.type) {
|
|
735
|
+
case DaffFilterType.RangeNumeric:
|
|
736
|
+
return daffFilterRangeNumericToRequest(filter);
|
|
737
|
+
case DaffFilterType.Equal:
|
|
738
|
+
return daffFilterEqualToRequest(filter);
|
|
739
|
+
default:
|
|
740
|
+
throw new DaffFilterUnknownType('Unknown filter type');
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
;
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Builds a list of filter requests from a list of filters.
|
|
747
|
+
* Requests are only built for the filters that have at least one applied option.
|
|
748
|
+
*/
|
|
749
|
+
function daffFiltersToRequests(filters) {
|
|
750
|
+
return Object.keys(filters).map((key) => filters[key]).reduce((acc, filter) => {
|
|
751
|
+
const request = daffFilterToRequest(filter);
|
|
752
|
+
if (request) {
|
|
753
|
+
acc.push(request);
|
|
754
|
+
}
|
|
755
|
+
return acc;
|
|
756
|
+
}, []);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Recurses through a tree, collecting each element in that tree and returning it in an array.
|
|
761
|
+
* The value of getKey should be a field that contains a list of the same type of object.
|
|
762
|
+
* Accepts an optional depth argument which will limit the traversal. This should be used for trees with circular references.
|
|
763
|
+
*/
|
|
764
|
+
const collect = (obj, getChildren, depth) => !depth || depth > 0
|
|
765
|
+
? [obj].concat(...getChildren(obj).map((child) => collect(child, getChildren, depth - 1)))
|
|
766
|
+
: [obj];
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* A helper function to compute a power of 10 required to convert a decimal number to an integer
|
|
770
|
+
* This function will fail if the given number has more than 16 significant figures or
|
|
771
|
+
* the value of the number is greater than 10^11
|
|
772
|
+
*
|
|
773
|
+
* @param number
|
|
774
|
+
*/
|
|
775
|
+
function daffPrecision(number) {
|
|
776
|
+
let p = 1;
|
|
777
|
+
if (number === undefined ||
|
|
778
|
+
number === null ||
|
|
779
|
+
Number.isNaN(number) ||
|
|
780
|
+
number === Infinity ||
|
|
781
|
+
number === -Infinity) {
|
|
782
|
+
return p;
|
|
783
|
+
}
|
|
784
|
+
while (Math.round(number * p) / p !== number) {
|
|
785
|
+
p *= 10;
|
|
786
|
+
if (p >= 1e11) {
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return p;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* A function to add long numbers accurately with conversions and integer math.
|
|
794
|
+
* This function only guarantees correct answers when the numbers given and the result are less than
|
|
795
|
+
* 16 significant figures and less than 10^11
|
|
796
|
+
*
|
|
797
|
+
* @param numbers
|
|
798
|
+
*/
|
|
799
|
+
function daffAdd(...numbers) {
|
|
800
|
+
if (numbers.length === 0) {
|
|
801
|
+
return undefined;
|
|
802
|
+
}
|
|
803
|
+
if (numbers.length === 1) {
|
|
804
|
+
return numbers[0];
|
|
805
|
+
}
|
|
806
|
+
const precision = Math.max(...numbers.map(daffPrecision));
|
|
807
|
+
return numbers.slice(1).reduce((acc, number) => acc + Math.round(number * precision), Math.round(numbers[0] * precision)) / precision;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* A function to subtract long numbers accurately with conversions and integer math.
|
|
811
|
+
* This function only guarantees correct answers when the numbers given and the result are each less than
|
|
812
|
+
* 16 significant figures and less than 10^11
|
|
813
|
+
*
|
|
814
|
+
* @param numbers
|
|
815
|
+
*/
|
|
816
|
+
function daffSubtract(...numbers) {
|
|
817
|
+
if (numbers.length === 0) {
|
|
818
|
+
return undefined;
|
|
819
|
+
}
|
|
820
|
+
if (numbers.length === 1) {
|
|
821
|
+
return numbers[0];
|
|
822
|
+
}
|
|
823
|
+
const precision = Math.max(...numbers.map(daffPrecision));
|
|
824
|
+
return numbers.slice(1).reduce((acc, number) => acc - Math.round(number * precision), Math.round(numbers[0] * precision)) / precision;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* A function to multiply long numbers accurately with conversions and integer math.
|
|
828
|
+
* This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
|
|
829
|
+
* and less than 10^11
|
|
830
|
+
*
|
|
831
|
+
* @param numbers
|
|
832
|
+
*/
|
|
833
|
+
function daffMultiply(...numbers) {
|
|
834
|
+
if (numbers.length === 0) {
|
|
835
|
+
return undefined;
|
|
836
|
+
}
|
|
837
|
+
if (numbers.length === 1) {
|
|
838
|
+
return numbers[0];
|
|
839
|
+
}
|
|
840
|
+
const precision = Math.max(...numbers.map(daffPrecision));
|
|
841
|
+
return numbers.reduce((acc, number) => acc * Math.round(number * precision), 1) / Math.pow(precision, numbers.length);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* A function to divide long numbers accurately with conversions and integer math.
|
|
845
|
+
* This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
|
|
846
|
+
* and less than 10^11
|
|
847
|
+
*
|
|
848
|
+
* Returns NaN when attempting to use NaN as an input.
|
|
849
|
+
* Returns NaN when attempting to divide by 0 or null.
|
|
850
|
+
*
|
|
851
|
+
* @param numbers
|
|
852
|
+
*/
|
|
853
|
+
function daffDivide(...numbers) {
|
|
854
|
+
if (numbers.length === 0) {
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
if (numbers.length === 1) {
|
|
858
|
+
return numbers[0];
|
|
859
|
+
}
|
|
860
|
+
const precision = Math.max(...numbers.map(daffPrecision));
|
|
861
|
+
return numbers.slice(1).reduce((acc, number) => acc / Math.round(number * precision), Math.round(numbers[0] * precision)) * Math.pow(precision, numbers.length - 2);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Converts an array into a dictionary.
|
|
866
|
+
* Dictionary values are keyed by the return of the specified `getKey`.
|
|
867
|
+
*/
|
|
868
|
+
const daffArrayToDict = (array, getKey) => array.reduce((dict, val) => {
|
|
869
|
+
dict[getKey(val)] = val;
|
|
870
|
+
return dict;
|
|
871
|
+
}, {});
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Returns a random slice of an array.
|
|
875
|
+
* An optional length may be specified.
|
|
876
|
+
*
|
|
877
|
+
* @param array
|
|
878
|
+
*/
|
|
879
|
+
const randomSlice = (array, length) => {
|
|
880
|
+
if (array.length === 0) {
|
|
881
|
+
return [];
|
|
882
|
+
}
|
|
883
|
+
;
|
|
884
|
+
if (length > array.length) {
|
|
885
|
+
throw new Error('Requested length is longer than array length.');
|
|
886
|
+
}
|
|
887
|
+
const arrayLength = length || Math.floor(Math.random() * array.length);
|
|
888
|
+
const start = Math.floor(Math.random() * (array.length - arrayLength + 1));
|
|
889
|
+
const end = start + arrayLength;
|
|
890
|
+
return array.slice(start, end);
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Immutable Fisher-Yates Shuffle
|
|
895
|
+
* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
896
|
+
*/
|
|
897
|
+
const shuffle = (array) => {
|
|
898
|
+
const result = [];
|
|
899
|
+
array.forEach((el, i) => {
|
|
900
|
+
const s = Math.floor(Math.random() * (i + 1));
|
|
901
|
+
if (s !== i) {
|
|
902
|
+
result[i] = result[s];
|
|
903
|
+
}
|
|
904
|
+
result[s] = el;
|
|
905
|
+
});
|
|
906
|
+
return result;
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Returns a random subset of an array in a random order.
|
|
911
|
+
*
|
|
912
|
+
* @param array
|
|
913
|
+
* @param length
|
|
914
|
+
*/
|
|
915
|
+
const randomSubset = (array, length) => {
|
|
916
|
+
if (length > array.length) {
|
|
917
|
+
throw new Error('Requested length is longer than array length.');
|
|
918
|
+
}
|
|
919
|
+
length = length ? length : Math.floor(Math.random() * array.length);
|
|
920
|
+
return shuffle(array).slice(0, length);
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Range
|
|
925
|
+
*
|
|
926
|
+
* Range accepts two inputs, a `start` and an `end`
|
|
927
|
+
* and returns an array filled with numbers from
|
|
928
|
+
* `start` to `end`.
|
|
929
|
+
*
|
|
930
|
+
* @param start
|
|
931
|
+
* @param end
|
|
932
|
+
* @returns number
|
|
933
|
+
*/
|
|
934
|
+
const range = (start, end) => Array(end - start + 1).fill(0).map((val, index) => index + start);
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Returns a random element of an array.
|
|
938
|
+
*/
|
|
939
|
+
const sample = (array) => randomSlice(array, 1)[0];
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Shallow compares two objects using a list of provided property keys to enumerate the values.
|
|
943
|
+
* `null` and `undefined` are considered equal for the purposes of the comparison.
|
|
944
|
+
* A strict equality comparison is used for truthy property values.
|
|
945
|
+
*/
|
|
946
|
+
function shallowCompare(obj1, obj2, props) {
|
|
947
|
+
return !!(obj1 && obj2 && props.reduce((acc, prop) => {
|
|
948
|
+
const p1 = obj1[prop];
|
|
949
|
+
const p2 = obj2[prop];
|
|
950
|
+
return acc && (
|
|
951
|
+
// undefined and null are treated as equal
|
|
952
|
+
(p1 === undefined || p1 === null) && (p2 === undefined || p2 === null)
|
|
953
|
+
|| p1 === p2);
|
|
954
|
+
}, true));
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Filters an array of elements, removing duplicates.
|
|
959
|
+
* Does not guarantee order of filtered elements.
|
|
960
|
+
*
|
|
961
|
+
* An optional comparator function may be passed for arbitrary comparison behavior.
|
|
962
|
+
* The default is a strict equality comparison: `a === b`.
|
|
1158
963
|
*/
|
|
1159
|
-
const
|
|
964
|
+
const unique = (array, comparator = (a, b) => a === b) => array.filter((a, index) => array.slice(index + 1).filter(b => comparator(a, b)).length === 0);
|
|
1160
965
|
|
|
1161
966
|
/**
|
|
1162
|
-
*
|
|
1163
|
-
* Returns
|
|
967
|
+
* The unary identity function.
|
|
968
|
+
* Returns whatever is passed to it.
|
|
1164
969
|
*/
|
|
1165
|
-
function
|
|
1166
|
-
|
|
1167
|
-
case DaffFilterType.RangeNumeric:
|
|
1168
|
-
return daffFilterRangeNumericToRequest(filter);
|
|
1169
|
-
case DaffFilterType.Equal:
|
|
1170
|
-
return daffFilterEqualToRequest(filter);
|
|
1171
|
-
default:
|
|
1172
|
-
throw new DaffFilterUnknownType('Unknown filter type');
|
|
1173
|
-
}
|
|
970
|
+
function identity(v) {
|
|
971
|
+
return v;
|
|
1174
972
|
}
|
|
1175
|
-
;
|
|
1176
973
|
|
|
1177
974
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
975
|
+
* Converts a value to an observable.
|
|
976
|
+
* If the value is an observable, just returns that observable.
|
|
977
|
+
* If the value is a promise, converts it to an observable (see rxjs `from`).
|
|
978
|
+
* If the value is neither, just returns an observable that immediately emits the value.
|
|
1180
979
|
*/
|
|
1181
|
-
function
|
|
1182
|
-
return
|
|
1183
|
-
const request = daffFilterToRequest(filter);
|
|
1184
|
-
if (request) {
|
|
1185
|
-
acc.push(request);
|
|
1186
|
-
}
|
|
1187
|
-
return acc;
|
|
1188
|
-
}, []);
|
|
980
|
+
function observe(val) {
|
|
981
|
+
return isObservable(val) ? val : from(Promise.resolve(val));
|
|
1189
982
|
}
|
|
1190
983
|
|
|
1191
984
|
/**
|
|
@@ -1321,9 +1114,223 @@ const daffMerge = (dicts, strategy = {}) => dicts.reduce((acc, dict) => {
|
|
|
1321
1114
|
return acc;
|
|
1322
1115
|
}, {});
|
|
1323
1116
|
|
|
1117
|
+
/**
|
|
1118
|
+
* Retries failed Observables
|
|
1119
|
+
*
|
|
1120
|
+
* @param maxTries The maximum number of tries the observable will be tried
|
|
1121
|
+
* @param ms The initial amount of time
|
|
1122
|
+
*/
|
|
1123
|
+
function backoff(maxTries, ms) {
|
|
1124
|
+
return pipe(retryWhen(attempt => attempt.pipe(mergeMap((shadowedAttempt, i) => {
|
|
1125
|
+
if (i >= maxTries) {
|
|
1126
|
+
return throwError(shadowedAttempt);
|
|
1127
|
+
}
|
|
1128
|
+
return timer(ms * Math.pow(2, i));
|
|
1129
|
+
}))));
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* Accepts a list of input observables and emits true when any of the inputs emit a truthy value.
|
|
1134
|
+
* Does not emit until all of the input streams have emitted at least once.
|
|
1135
|
+
*/
|
|
1136
|
+
const anyOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg || el, false)));
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Accepts a list of input observables and emits true when all of the inputs emit a truthy value.
|
|
1140
|
+
* Does not emit until all of the input streams have emitted at least once.
|
|
1141
|
+
*/
|
|
1142
|
+
const allOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg && el, true)));
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Catches errors and invokes the callback with an array of errors.
|
|
1146
|
+
*/
|
|
1147
|
+
const catchAndArrayifyErrors = (transformError) => pipe(catchError((err) => transformError(Array.isArray(err) ? err : [err])));
|
|
1148
|
+
|
|
1149
|
+
const DAFF_STORAGE_SERVICE_ERROR_CODE = 'DAFF_STORAGE_FAILURE';
|
|
1150
|
+
class DaffStorageServiceError extends DaffInheritableError {
|
|
1151
|
+
constructor(message) {
|
|
1152
|
+
super(message);
|
|
1153
|
+
this.message = message;
|
|
1154
|
+
this.code = DAFF_STORAGE_SERVICE_ERROR_CODE;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* @inheritdoc
|
|
1160
|
+
*/
|
|
1161
|
+
class DaffErrorStorageService {
|
|
1162
|
+
static { this.ERROR_MESSAGE = 'The DaffErrorStorageService always throws an error.'; }
|
|
1163
|
+
setItem(key, value) {
|
|
1164
|
+
this.throwError();
|
|
1165
|
+
}
|
|
1166
|
+
getItem(key) {
|
|
1167
|
+
this.throwError();
|
|
1168
|
+
}
|
|
1169
|
+
removeItem(key) {
|
|
1170
|
+
this.throwError();
|
|
1171
|
+
}
|
|
1172
|
+
clear() {
|
|
1173
|
+
this.throwError();
|
|
1174
|
+
}
|
|
1175
|
+
throwError() {
|
|
1176
|
+
throw new DaffStorageServiceError(DaffErrorStorageService.ERROR_MESSAGE);
|
|
1177
|
+
}
|
|
1178
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1179
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, providedIn: 'root' }); }
|
|
1180
|
+
}
|
|
1181
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffErrorStorageService, decorators: [{
|
|
1182
|
+
type: Injectable,
|
|
1183
|
+
args: [{
|
|
1184
|
+
providedIn: 'root',
|
|
1185
|
+
}]
|
|
1186
|
+
}] });
|
|
1187
|
+
|
|
1188
|
+
const DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE = 'DAFF_SERVER_STORAGE_FAILURE';
|
|
1189
|
+
/**
|
|
1190
|
+
* An error thrown when there is an attempt to access storage on the server and none is available.
|
|
1191
|
+
*/
|
|
1192
|
+
class DaffServerSideStorageError extends DaffStorageServiceError {
|
|
1193
|
+
constructor(message) {
|
|
1194
|
+
super(message);
|
|
1195
|
+
this.message = message;
|
|
1196
|
+
this.code = DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* A storage service meant to be loaded into SSR contexts.
|
|
1202
|
+
* It will always throw the {@link DaffServerSideStorageError}.
|
|
1203
|
+
*
|
|
1204
|
+
* @inheritdoc
|
|
1205
|
+
*/
|
|
1206
|
+
class DaffServerErrorStorageService {
|
|
1207
|
+
static { this.ERROR_MESSAGE = 'The DaffServerErrorStorageService always throws an error.'; }
|
|
1208
|
+
setItem(key, value) {
|
|
1209
|
+
this.throwError();
|
|
1210
|
+
}
|
|
1211
|
+
getItem(key) {
|
|
1212
|
+
this.throwError();
|
|
1213
|
+
}
|
|
1214
|
+
removeItem(key) {
|
|
1215
|
+
this.throwError();
|
|
1216
|
+
}
|
|
1217
|
+
clear() {
|
|
1218
|
+
this.throwError();
|
|
1219
|
+
}
|
|
1220
|
+
throwError() {
|
|
1221
|
+
throw new DaffServerSideStorageError(DaffServerErrorStorageService.ERROR_MESSAGE);
|
|
1222
|
+
}
|
|
1223
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerErrorStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1224
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerErrorStorageService, providedIn: 'root' }); }
|
|
1225
|
+
}
|
|
1226
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffServerErrorStorageService, decorators: [{
|
|
1227
|
+
type: Injectable,
|
|
1228
|
+
args: [{
|
|
1229
|
+
providedIn: 'root',
|
|
1230
|
+
}]
|
|
1231
|
+
}] });
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* @inheritdoc
|
|
1235
|
+
*/
|
|
1236
|
+
class DaffLocalStorageService {
|
|
1237
|
+
constructor(platformId) {
|
|
1238
|
+
if (!isPlatformBrowser(platformId)) {
|
|
1239
|
+
throw new Error('The DaffLocalStorageService can only be instantiated in the browser.');
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Persist the given item into local storage.
|
|
1244
|
+
*/
|
|
1245
|
+
setItem(key, value) {
|
|
1246
|
+
localStorage.setItem(key, value);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Retrieve the given item from localstorage.
|
|
1250
|
+
*/
|
|
1251
|
+
getItem(key) {
|
|
1252
|
+
return localStorage.getItem(key);
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Remove a given item from localstorage
|
|
1256
|
+
*/
|
|
1257
|
+
removeItem(key) {
|
|
1258
|
+
localStorage.removeItem(key);
|
|
1259
|
+
}
|
|
1260
|
+
clear() {
|
|
1261
|
+
localStorage.clear();
|
|
1262
|
+
}
|
|
1263
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffLocalStorageService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1264
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffLocalStorageService, providedIn: 'root' }); }
|
|
1265
|
+
}
|
|
1266
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffLocalStorageService, decorators: [{
|
|
1267
|
+
type: Injectable,
|
|
1268
|
+
args: [{
|
|
1269
|
+
providedIn: 'root',
|
|
1270
|
+
}]
|
|
1271
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
1272
|
+
type: Inject,
|
|
1273
|
+
args: [PLATFORM_ID]
|
|
1274
|
+
}] }] });
|
|
1275
|
+
|
|
1276
|
+
/**
|
|
1277
|
+
* @inheritdoc
|
|
1278
|
+
*/
|
|
1279
|
+
class DaffNoopStorageService {
|
|
1280
|
+
setItem(key, value) { }
|
|
1281
|
+
;
|
|
1282
|
+
getItem(key) { }
|
|
1283
|
+
;
|
|
1284
|
+
clear() { }
|
|
1285
|
+
;
|
|
1286
|
+
removeItem(key) { }
|
|
1287
|
+
;
|
|
1288
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1289
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, providedIn: 'root' }); }
|
|
1290
|
+
}
|
|
1291
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.11", ngImport: i0, type: DaffNoopStorageService, decorators: [{
|
|
1292
|
+
type: Injectable,
|
|
1293
|
+
args: [{
|
|
1294
|
+
providedIn: 'root',
|
|
1295
|
+
}]
|
|
1296
|
+
}] });
|
|
1297
|
+
|
|
1298
|
+
const { token: DaffPersistenceServiceToken,
|
|
1299
|
+
/**
|
|
1300
|
+
* Provider function for {@link DaffPersistenceServiceToken}.
|
|
1301
|
+
*/
|
|
1302
|
+
provider: provideDaffPersistenceService, } = createSingleInjectionToken('DaffPersistenceServiceToken', {
|
|
1303
|
+
providedIn: 'root',
|
|
1304
|
+
factory: () => isPlatformBrowser(inject(PLATFORM_ID))
|
|
1305
|
+
? new DaffLocalStorageService(inject(PLATFORM_ID))
|
|
1306
|
+
: new DaffServerErrorStorageService(),
|
|
1307
|
+
});
|
|
1308
|
+
|
|
1309
|
+
const {
|
|
1310
|
+
/**
|
|
1311
|
+
* Provides noop for the persistence service on the server.
|
|
1312
|
+
*/
|
|
1313
|
+
token: DaffServerSafePersistenceServiceToken,
|
|
1314
|
+
/**
|
|
1315
|
+
* Provider function for {@link DaffServerSafePersistenceServiceToken}.
|
|
1316
|
+
*/
|
|
1317
|
+
provider: provideDaffServerSafePersistenceServiceToken, } = createSingleInjectionToken('DaffServerSafePersistenceService', {
|
|
1318
|
+
providedIn: 'root',
|
|
1319
|
+
factory: () => isPlatformBrowser(inject(PLATFORM_ID))
|
|
1320
|
+
? inject(DaffPersistenceServiceToken)
|
|
1321
|
+
: inject(DaffNoopStorageService),
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* Validates whether all the specified fields are defined in the passed object.
|
|
1326
|
+
* Uses `Object.hasOwn` to do the check, so even if a field has been set to `null`
|
|
1327
|
+
* or `undefined`, they will be treated as present.
|
|
1328
|
+
*/
|
|
1329
|
+
const validateFieldPresence = (model, ...fields) => fields.reduce((acc, field) => acc && Object.hasOwn(model, field), true);
|
|
1330
|
+
|
|
1324
1331
|
/**
|
|
1325
1332
|
* Generated bundle index. Do not edit.
|
|
1326
1333
|
*/
|
|
1327
1334
|
|
|
1328
|
-
export { DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE, DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE, DAFF_STORAGE_SERVICE_ERROR_CODE, DaffBase64ServiceToken, DaffBrowserBase64Service, DaffCollectionPageOutOfBoundsError, DaffErrorStorageService, DaffFilterFromToFilterSeparator, DaffFilterNotFound, DaffFilterRequestNameMismatch, DaffFilterRequestTypeMismatch, DaffFilterType, DaffFilterUnknownType, DaffInheritableError, DaffLocalStorageService, DaffNoopStorageService, DaffPersistenceServiceToken, DaffServerBase64Service, DaffServerErrorStorageService, DaffServerSafePersistenceServiceToken, DaffServerSideStorageError, DaffSortDirectionEnum, DaffStorageServiceError, allOf, anyOf, backoff, catchAndArrayifyErrors, collect, createConfigInjectionToken, createMultiInjectionToken, createServicesInjectionToken, createSingleInjectionToken, createSingletonInjectionToken, daffAdd, daffApplyFilter, daffApplyRequestToFilters, daffApplyRequestsToFilters, daffArrayConcatMerger, daffArrayToDict, daffClearFilter, daffClearFilters, daffCollectionBuildMetadataFromRequest, daffCollectionBuildRequestFromMetadata, daffCollectionErrorMap, daffComputeAppliedFilters, daffDictAssignMerger, daffDivide, daffFilterArrayToDict, daffFilterComputeRangePairLabel, daffFilterEqualOptionArrayToDict, daffFilterFindAppliedOptions, daffFilterRangePairArrayToDict, daffFilterToRequest, daffFilterValidateRequestNameMatch, daffFilterValidateRequestTypeMatch, daffFiltersToRequests, daffIdentifiableArrayToDict, daffIsError, daffIsFilterApplied, daffIsToggleRequestAppliedToFilter, daffMerge, daffMultiply, daffPrecision, daffRemoveFilter, daffRemoveRequestFromFilters, daffRemoveRequestsFromFilters, daffSubtract, daffToggleFilter, daffToggleRequestOnFilters, identity, observe, randomSlice, randomSubset, range, sample, shallowCompare, shuffle, unique };
|
|
1335
|
+
export { DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE, DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE, DAFF_STORAGE_SERVICE_ERROR_CODE, DaffBase64ServiceToken, DaffBrowserBase64Service, DaffCollectionPageOutOfBoundsError, DaffErrorStorageService, DaffFilterFromToFilterSeparator, DaffFilterNotFound, DaffFilterRequestNameMismatch, DaffFilterRequestTypeMismatch, DaffFilterType, DaffFilterUnknownType, DaffInheritableError, DaffLocalStorageService, DaffNoopStorageService, DaffPersistenceServiceToken, DaffServerBase64Service, DaffServerErrorStorageService, DaffServerSafePersistenceServiceToken, DaffServerSideStorageError, DaffSortDirectionEnum, DaffStorageServiceError, allOf, anyOf, backoff, catchAndArrayifyErrors, collect, createConfigInjectionToken, createMultiInjectionToken, createServicesInjectionToken, createSingleInjectionToken, createSingletonInjectionToken, daffAdd, daffApplyFilter, daffApplyRequestToFilters, daffApplyRequestsToFilters, daffArrayConcatMerger, daffArrayToDict, daffClearFilter, daffClearFilters, daffCollectionBuildMetadataFromRequest, daffCollectionBuildRequestFromMetadata, daffCollectionErrorMap, daffComputeAppliedFilters, daffDictAssignMerger, daffDivide, daffFilterArrayToDict, daffFilterComputeRangePairLabel, daffFilterEqualOptionArrayToDict, daffFilterFindAppliedOptions, daffFilterRangePairArrayToDict, daffFilterToRequest, daffFilterValidateRequestNameMatch, daffFilterValidateRequestTypeMatch, daffFiltersToRequests, daffIdentifiableArrayToDict, daffIsError, daffIsFilterApplied, daffIsToggleRequestAppliedToFilter, daffMerge, daffMultiply, daffPrecision, daffRemoveFilter, daffRemoveRequestFromFilters, daffRemoveRequestsFromFilters, daffSubtract, daffToggleFilter, daffToggleRequestOnFilters, identity, observe, randomSlice, randomSubset, range, sample, shallowCompare, shuffle, unique, validateFieldPresence };
|
|
1329
1336
|
//# sourceMappingURL=daffodil-core.mjs.map
|