@daffodil/core 0.94.1-rc.0 → 0.95.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.
@@ -1,1472 +1,850 @@
1
- import { IMAGE_LOADER, isPlatformBrowser } from '@angular/common';
2
- import * as i0 from '@angular/core';
3
- import { makeEnvironmentProviders, PLATFORM_ID, Inject, Injectable, InjectionToken, inject } from '@angular/core';
4
- import { isObservable, from, pipe, throwError, timer, combineLatest, map, catchError } from 'rxjs';
5
- import { retryWhen, mergeMap } from 'rxjs/operators';
6
-
7
- /**
8
- * Creates a Vercel image loader function that optimizes images through Vercel's image optimization service.
9
- *
10
- * @param domain The domain to match against image URLs for transformation
11
- * @param configuration Configuration options for image optimization
12
- * @returns An image loader function that transforms URLs for Vercel image optimization
13
- */
1
+ import { IMAGE_LOADER, isPlatformBrowser } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { Inject, Injectable, InjectionToken, PLATFORM_ID, inject, makeEnvironmentProviders } from "@angular/core";
4
+ import { catchError, combineLatest, from, isObservable, map, pipe, throwError, timer } from "rxjs";
5
+ import { mergeMap, retryWhen } from "rxjs/operators";
14
6
  const createVercelImageLoader = (domain, configuration) => (config) => {
15
- if (!config.src.startsWith(domain + '/')) {
16
- return config.src;
17
- }
18
- const baseUrl = domain + '/_vercel/image';
19
- const path = config.src.replace(domain, '');
20
- const url = encodeURIComponent(path);
21
- const width = config.width || configuration.defaultWidth;
22
- const quality = configuration.quality;
23
- return `${baseUrl}?url=${url}&w=${width}&q=${quality}`;
7
+ if (!config.src.startsWith(domain + "/")) return config.src;
8
+ const baseUrl = domain + "/_vercel/image";
9
+ const path = config.src.replace(domain, "");
10
+ return `${baseUrl}?url=${encodeURIComponent(path)}&w=${config.width || configuration.defaultWidth}&q=${configuration.quality}`;
24
11
  };
25
- /**
26
- * Provides a Vercel image loader as an Angular environment provider.
27
- *
28
- * @param domain The domain to match against image URLs for transformation
29
- * @param configuration Configuration options for image optimization
30
- * @returns Environment providers array containing the Vercel image loader
31
- */
32
12
  const provideVercelImageLoader = (domain, configuration) => makeEnvironmentProviders([{
33
- provide: IMAGE_LOADER,
34
- useFactory: () => createVercelImageLoader(domain, configuration),
35
- }]);
36
-
37
- /**
38
- * A base64 service meant to be loaded into SSR contexts.
39
- *
40
- * @inheritdoc
41
- */
42
- class DaffServerBase64Service {
43
- constructor(platformId) {
44
- if (isPlatformBrowser(platformId)) {
45
- throw new Error('The DaffBrowserBase64Service can only be instantiated on the server.');
46
- }
47
- }
48
- encode(str) {
49
- return Buffer.from(str).toString('base64');
50
- }
51
- decode(str) {
52
- return Buffer.from(str, 'base64').toString('ascii');
53
- }
54
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
55
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerBase64Service, providedIn: 'root' }); }
56
- }
57
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerBase64Service, decorators: [{
58
- type: Injectable,
59
- args: [{
60
- providedIn: 'root',
61
- }]
62
- }], ctorParameters: () => [{ type: undefined, decorators: [{
63
- type: Inject,
64
- args: [PLATFORM_ID]
65
- }] }] });
66
-
67
- /**
68
- * @inheritdoc
69
- */
70
- class DaffBrowserBase64Service {
71
- constructor(platformId) {
72
- if (!isPlatformBrowser(platformId)) {
73
- throw new Error('The DaffBrowserBase64Service can only be instantiated in the browser.');
74
- }
75
- }
76
- encode(str) {
77
- return btoa(str);
78
- }
79
- decode(str) {
80
- return atob(str);
81
- }
82
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffBrowserBase64Service, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
83
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffBrowserBase64Service, providedIn: 'root' }); }
84
- }
85
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffBrowserBase64Service, decorators: [{
86
- type: Injectable,
87
- args: [{
88
- providedIn: 'root',
89
- }]
90
- }], ctorParameters: () => [{ type: undefined, decorators: [{
91
- type: Inject,
92
- args: [PLATFORM_ID]
93
- }] }] });
94
-
95
- /**
96
- * Creates an injection token/provider pair for a single valued DI token.
97
- *
98
- * See {@link DaffSingleInjectionToken}.
99
- */
13
+ provide: IMAGE_LOADER,
14
+ useFactory: () => createVercelImageLoader(domain, configuration)
15
+ }]);
16
+ var DaffServerBase64Service = class DaffServerBase64Service {
17
+ constructor(platformId) {
18
+ if (isPlatformBrowser(platformId)) throw new Error("The DaffBrowserBase64Service can only be instantiated on the server.");
19
+ }
20
+ encode(str) {
21
+ return Buffer.from(str).toString("base64");
22
+ }
23
+ decode(str) {
24
+ return Buffer.from(str, "base64").toString("ascii");
25
+ }
26
+ static {
27
+ this.ɵfac = i0.ɵɵngDeclareFactory({
28
+ minVersion: "12.0.0",
29
+ version: "22.2.4",
30
+ ngImport: i0,
31
+ type: DaffServerBase64Service,
32
+ deps: [{ token: PLATFORM_ID }],
33
+ target: i0.ɵɵFactoryTarget.Injectable
34
+ });
35
+ }
36
+ static {
37
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
38
+ minVersion: "12.0.0",
39
+ version: "22.2.4",
40
+ ngImport: i0,
41
+ type: DaffServerBase64Service,
42
+ providedIn: "root"
43
+ });
44
+ }
45
+ };
46
+ i0.ɵɵngDeclareClassMetadata({
47
+ minVersion: "12.0.0",
48
+ version: "22.2.4",
49
+ ngImport: i0,
50
+ type: DaffServerBase64Service,
51
+ decorators: [{
52
+ type: Injectable,
53
+ args: [{ providedIn: "root" }]
54
+ }],
55
+ ctorParameters: () => [{
56
+ type: void 0,
57
+ decorators: [{
58
+ type: Inject,
59
+ args: [PLATFORM_ID]
60
+ }]
61
+ }]
62
+ });
63
+ var DaffBrowserBase64Service = class DaffBrowserBase64Service {
64
+ constructor(platformId) {
65
+ if (!isPlatformBrowser(platformId)) throw new Error("The DaffBrowserBase64Service can only be instantiated in the browser.");
66
+ }
67
+ encode(str) {
68
+ return btoa(str);
69
+ }
70
+ decode(str) {
71
+ return atob(str);
72
+ }
73
+ static {
74
+ this.ɵfac = i0.ɵɵngDeclareFactory({
75
+ minVersion: "12.0.0",
76
+ version: "22.2.4",
77
+ ngImport: i0,
78
+ type: DaffBrowserBase64Service,
79
+ deps: [{ token: PLATFORM_ID }],
80
+ target: i0.ɵɵFactoryTarget.Injectable
81
+ });
82
+ }
83
+ static {
84
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
85
+ minVersion: "12.0.0",
86
+ version: "22.2.4",
87
+ ngImport: i0,
88
+ type: DaffBrowserBase64Service,
89
+ providedIn: "root"
90
+ });
91
+ }
92
+ };
93
+ i0.ɵɵngDeclareClassMetadata({
94
+ minVersion: "12.0.0",
95
+ version: "22.2.4",
96
+ ngImport: i0,
97
+ type: DaffBrowserBase64Service,
98
+ decorators: [{
99
+ type: Injectable,
100
+ args: [{ providedIn: "root" }]
101
+ }],
102
+ ctorParameters: () => [{
103
+ type: void 0,
104
+ decorators: [{
105
+ type: Inject,
106
+ args: [PLATFORM_ID]
107
+ }]
108
+ }]
109
+ });
100
110
  const createSingleInjectionToken = (desc, options) => {
101
- const token = new InjectionToken(desc, options);
102
- const provider = (value) => ({
103
- provide: token,
104
- useValue: value,
105
- });
106
- const factoryProvider = (factory) => ({
107
- provide: token,
108
- useFactory: factory,
109
- });
110
- return {
111
- token,
112
- provider,
113
- factoryProvider,
114
- };
111
+ const token = new InjectionToken(desc, options);
112
+ const provider = (value) => ({
113
+ provide: token,
114
+ useValue: value
115
+ });
116
+ const factoryProvider = (factory) => ({
117
+ provide: token,
118
+ useFactory: factory
119
+ });
120
+ return {
121
+ token,
122
+ provider,
123
+ factoryProvider
124
+ };
115
125
  };
116
-
117
- // having a single instance of the default factory
118
- // will hopefully reduce memory footprint
119
126
  const defaultFactory$1 = () => [];
120
- /**
121
- * Creates an injection token/provider pair for a multi valued DI token.
122
- *
123
- * See {@link DaffMultiInjectionToken}.
124
- */
125
127
  const createMultiInjectionToken = (desc, options) => {
126
- const token = new InjectionToken(desc, {
127
- factory: defaultFactory$1,
128
- ...options,
129
- });
130
- const provider = (...values) => values.map((value) => ({
131
- provide: token,
132
- useValue: value,
133
- multi: true,
134
- }));
135
- const factoryProvider = (...factories) => factories.map((factory) => ({
136
- provide: token,
137
- useFactory: factory,
138
- multi: true,
139
- }));
140
- return {
141
- token,
142
- provider,
143
- factoryProvider,
144
- };
128
+ const token = new InjectionToken(desc, {
129
+ factory: defaultFactory$1,
130
+ ...options
131
+ });
132
+ const provider = (...values) => values.map((value) => ({
133
+ provide: token,
134
+ useValue: value,
135
+ multi: true
136
+ }));
137
+ const factoryProvider = (...factories) => factories.map((factory) => ({
138
+ provide: token,
139
+ useFactory: factory,
140
+ multi: true
141
+ }));
142
+ return {
143
+ token,
144
+ provider,
145
+ factoryProvider
146
+ };
145
147
  };
146
-
147
- /**
148
- * Creates an injection token/provider pair for a DI token that holds a configuration.
149
- *
150
- * See {@link DaffConfigInjectionToken}.
151
- */
152
148
  const createConfigInjectionToken = (defaultConfig, desc, options) => {
153
- const token = new InjectionToken(desc, {
154
- factory: () => defaultConfig instanceof InjectionToken ? inject(defaultConfig) : defaultConfig,
155
- ...options,
156
- });
157
- const provider = (config) => ({
158
- provide: token,
159
- useFactory: () => ({
160
- ...(defaultConfig instanceof InjectionToken ? inject(defaultConfig) : defaultConfig),
161
- ...(config instanceof InjectionToken ? inject(config) : config),
162
- }),
163
- });
164
- return {
165
- token,
166
- provider,
167
- };
149
+ const token = new InjectionToken(desc, {
150
+ factory: () => defaultConfig instanceof InjectionToken ? inject(defaultConfig) : defaultConfig,
151
+ ...options
152
+ });
153
+ const provider = (config) => ({
154
+ provide: token,
155
+ useFactory: () => ({
156
+ ...defaultConfig instanceof InjectionToken ? inject(defaultConfig) : defaultConfig,
157
+ ...config instanceof InjectionToken ? inject(config) : config
158
+ })
159
+ });
160
+ return {
161
+ token,
162
+ provider
163
+ };
168
164
  };
169
-
170
- // having a single instance of the default factory
171
- // will hopefully reduce memory footprint
172
165
  const defaultFactory = () => [];
173
- /**
174
- * Creates an injection token/provider pair for a DI token that holds services.
175
- *
176
- * See {@link DaffServicesInjectionToken}.
177
- */
178
166
  const createServicesInjectionToken = (desc, options) => {
179
- const token = new InjectionToken(desc, {
180
- factory: defaultFactory,
181
- ...options,
182
- });
183
- const provider = (...classes) => classes.map((klass) => ({
184
- provide: token,
185
- useExisting: klass,
186
- multi: true,
187
- }));
188
- return {
189
- token,
190
- provider,
191
- };
167
+ const token = new InjectionToken(desc, {
168
+ factory: defaultFactory,
169
+ ...options
170
+ });
171
+ const provider = (...classes) => classes.map((klass) => ({
172
+ provide: token,
173
+ useExisting: klass,
174
+ multi: true
175
+ }));
176
+ return {
177
+ token,
178
+ provider
179
+ };
192
180
  };
193
-
194
- /**
195
- * Creates an injection token/provider pair for a DI token that holds a singleton service.
196
- *
197
- * See {@link DaffSingletonInjectionToken}.
198
- */
199
181
  const createSingletonInjectionToken = (desc, options) => {
200
- const token = new InjectionToken(desc, options);
201
- const provider = (klass) => ({
202
- provide: token,
203
- useExisting: klass,
204
- });
205
- return {
206
- token,
207
- provider,
208
- };
182
+ const token = new InjectionToken(desc, options);
183
+ const provider = (klass) => ({
184
+ provide: token,
185
+ useExisting: klass
186
+ });
187
+ return {
188
+ token,
189
+ provider
190
+ };
209
191
  };
210
-
211
- const {
212
- /**
213
- * A token which creates a base64 service appropriate for the current environment, i.e., browser vs. server.
214
- */
215
- token: DaffBase64ServiceToken,
216
- /**
217
- * Provider function for {@link DaffBase64ServiceToken}.
218
- */
219
- provider: provideDaffBase64Service, } = createSingleInjectionToken('DaffBase64ServiceToken', {
220
- providedIn: 'root',
221
- factory: () => isPlatformBrowser(inject(PLATFORM_ID))
222
- ? new DaffBrowserBase64Service(inject(PLATFORM_ID))
223
- : new DaffServerBase64Service(inject(PLATFORM_ID)),
192
+ const { token: DaffBase64ServiceToken, provider: provideDaffBase64Service } = createSingleInjectionToken("DaffBase64ServiceToken", {
193
+ providedIn: "root",
194
+ factory: () => isPlatformBrowser(inject(PLATFORM_ID)) ? new DaffBrowserBase64Service(inject(PLATFORM_ID)) : new DaffServerBase64Service(inject(PLATFORM_ID))
224
195
  });
225
-
226
- /**
227
- * The direction in which to sort a list of elements, e.g. if the list was
228
- * sorted alphabetically, "Ascending" would be from "A-Z",
229
- * and "Descending" would be from "Z-A".
230
- */
231
196
  var DaffSortDirectionEnum;
232
- (function (DaffSortDirectionEnum) {
233
- DaffSortDirectionEnum["Ascending"] = "ASC";
234
- DaffSortDirectionEnum["Descending"] = "DSC";
197
+ (function(DaffSortDirectionEnum) {
198
+ DaffSortDirectionEnum["Ascending"] = "ASC";
199
+ DaffSortDirectionEnum["Descending"] = "DSC";
235
200
  })(DaffSortDirectionEnum || (DaffSortDirectionEnum = {}));
236
-
237
- /**
238
- * A class which allows you to appropriately check the inheritance of an error.
239
- *
240
- * In typescript, when you try to extend an error with a specialized error class,
241
- * if you try to call something like:
242
- *
243
- * ```ts
244
- * class MyError extends Error {}
245
- *
246
- * let myError = new MyError();
247
- *
248
- * myError instanceof MyError; // returns false
249
- * ```
250
- *
251
- * You will see unexpected things. This class fixes that issue as described here
252
- * https://github.com/microsoft/TypeScript/issues/13965
253
- */
254
- class DaffInheritableError extends Error {
255
- constructor(message) {
256
- super(message);
257
- this.recoverable = false;
258
- const trueProto = new.target.prototype;
259
- Object.setPrototypeOf(this, trueProto);
260
- }
261
- }
262
-
263
- /**
264
- * Checks if the passed object is a {@link DaffError}
265
- */
201
+ var DaffInheritableError = class extends Error {
202
+ constructor(message) {
203
+ super(message);
204
+ this.recoverable = false;
205
+ const trueProto = new.target.prototype;
206
+ Object.setPrototypeOf(this, trueProto);
207
+ }
208
+ };
266
209
  const daffIsError = (error) => error instanceof DaffInheritableError || !!error.code;
267
-
268
- const DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE = 'DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS';
269
- /**
270
- * An error thrown when the requested page is greater than the number of available pages.
271
- */
272
- class DaffCollectionPageOutOfBoundsError extends DaffInheritableError {
273
- constructor(message) {
274
- super(message);
275
- this.code = DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE;
276
- }
277
- }
278
-
279
- const daffCollectionErrorMap = {
280
- [DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE]: DaffCollectionPageOutOfBoundsError,
210
+ const DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE = "DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS";
211
+ var DaffCollectionPageOutOfBoundsError = class extends DaffInheritableError {
212
+ constructor(message) {
213
+ super(message);
214
+ this.code = DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE;
215
+ }
281
216
  };
282
-
217
+ const daffCollectionErrorMap = { [DAFF_COLLECTION_PAGE_OUT_OF_BOUNDS_ERROR_CODE]: DaffCollectionPageOutOfBoundsError };
283
218
  const allowedMetadataKeys = [
284
- 'appliedSortOption',
285
- 'appliedSortDirection',
286
- 'currentPage',
287
- 'pageSize',
219
+ "appliedSortOption",
220
+ "appliedSortDirection",
221
+ "currentPage",
222
+ "pageSize"
288
223
  ];
289
- /**
290
- * Extracts the part of the {@link DaffCollectionRequest} that can be directly set in {@link DaffCollectionMetadata}.
291
- */
292
224
  const daffCollectionBuildMetadataFromRequest = (request) => allowedMetadataKeys.reduce((acc, key) => {
293
- if (request[key]) {
294
- acc[key] = request[key];
295
- }
296
- return acc;
225
+ if (request[key]) acc[key] = request[key];
226
+ return acc;
297
227
  }, {});
298
-
299
- /**
300
- * The known types of filters.
301
- */
302
228
  var DaffFilterType;
303
- (function (DaffFilterType) {
304
- DaffFilterType["Equal"] = "equal";
305
- DaffFilterType["RangeNumeric"] = "rangeNumeric";
229
+ (function(DaffFilterType) {
230
+ DaffFilterType["Equal"] = "equal";
231
+ DaffFilterType["RangeNumeric"] = "rangeNumeric";
306
232
  })(DaffFilterType || (DaffFilterType = {}));
307
-
308
- /**
309
- * The separator between a range type filter's values
310
- * e.g. "price": "30-40".
311
- */
312
- const DaffFilterFromToFilterSeparator = '-';
313
-
314
- /**
315
- * The error codes applicable to the filter behaviors of `@daffodil/core`.
316
- */
233
+ const DaffFilterFromToFilterSeparator = "-";
317
234
  var DaffFilterErrorCodes;
318
- (function (DaffFilterErrorCodes) {
319
- DaffFilterErrorCodes["FILTER_REQUEST_TYPE_MISMATCH"] = "DAFF_FILTER_REQUEST_TYPE_MISMATCH";
320
- DaffFilterErrorCodes["FILTER_REQUEST_NAME_MISMATCH"] = "DAFF_FILTER_REQUEST_NAME_MISMATCH";
321
- DaffFilterErrorCodes["FILTER_NOT_FOUND"] = "DAFF_FILTER_NOT_FOUND";
322
- DaffFilterErrorCodes["UNKNOWN_FILTER_TYPE"] = "DAFF_FILTER_UNKNOWN_TYPE";
235
+ (function(DaffFilterErrorCodes) {
236
+ DaffFilterErrorCodes["FILTER_REQUEST_TYPE_MISMATCH"] = "DAFF_FILTER_REQUEST_TYPE_MISMATCH";
237
+ DaffFilterErrorCodes["FILTER_REQUEST_NAME_MISMATCH"] = "DAFF_FILTER_REQUEST_NAME_MISMATCH";
238
+ DaffFilterErrorCodes["FILTER_NOT_FOUND"] = "DAFF_FILTER_NOT_FOUND";
239
+ DaffFilterErrorCodes["UNKNOWN_FILTER_TYPE"] = "DAFF_FILTER_UNKNOWN_TYPE";
323
240
  })(DaffFilterErrorCodes || (DaffFilterErrorCodes = {}));
324
-
325
- /**
326
- * An error thrown when an operation targeting a filter matches a type unknown
327
- * to Daffodil.
328
- */
329
- class DaffFilterUnknownType extends DaffInheritableError {
330
- constructor(message) {
331
- super(message);
332
- this.code = DaffFilterErrorCodes.UNKNOWN_FILTER_TYPE;
333
- }
334
- }
335
-
336
- /**
337
- * Applies a {@link DaffFilterEqualRequest} to a {@link DaffFilterEqual}
338
- *
339
- * @idempotent {filter}
340
- * @docs-private
341
- */
241
+ var DaffFilterUnknownType = class extends DaffInheritableError {
242
+ constructor(message) {
243
+ super(message);
244
+ this.code = DaffFilterErrorCodes.UNKNOWN_FILTER_TYPE;
245
+ }
246
+ };
342
247
  const daffApplyFilterEqual = (request, filter) => ({
343
- ...filter,
344
- options: request.value.reduce((acc, value) => {
345
- const option = filter.options[value];
346
- if (option) {
347
- acc[value] = {
348
- ...option,
349
- applied: true,
350
- };
351
- }
352
- return acc;
353
- }, { ...filter.options }),
248
+ ...filter,
249
+ options: request.value.reduce((acc, value) => {
250
+ const option = filter.options[value];
251
+ if (option) acc[value] = {
252
+ ...option,
253
+ applied: true
254
+ };
255
+ return acc;
256
+ }, { ...filter.options })
354
257
  });
355
-
356
- const daffFilterComputeRangePairLabel = (min, max) => `${min}${DaffFilterFromToFilterSeparator}${max}`;
357
-
358
- /**
359
- * Applies a {@link DaffFilterRangeRequestBase} to a {@link DaffFilterRangeBase}
360
- *
361
- * @idempotent {filter}
362
- * @docs-private
363
- */
258
+ const daffFilterComputeRangePairLabel = (min, max) => `${min}-${max}`;
364
259
  const daffApplyFilterRange = (request, filter) => ({
365
- ...filter,
366
- options: {
367
- [daffFilterComputeRangePairLabel(request.value.min, request.value.max)]: {
368
- min: {
369
- value: request.value.min,
370
- label: String(request.value.min),
371
- },
372
- max: {
373
- value: request.value.max,
374
- label: String(request.value.max),
375
- },
376
- applied: true,
377
- },
378
- },
260
+ ...filter,
261
+ options: { [daffFilterComputeRangePairLabel(request.value.min, request.value.max)]: {
262
+ min: {
263
+ value: request.value.min,
264
+ label: String(request.value.min)
265
+ },
266
+ max: {
267
+ value: request.value.max,
268
+ label: String(request.value.max)
269
+ },
270
+ applied: true
271
+ } }
379
272
  });
380
-
381
- /**
382
- * An error thrown when a lookup for a filter.
383
- */
384
- class DaffFilterNotFound extends DaffInheritableError {
385
- constructor(message) {
386
- super(message);
387
- this.code = DaffFilterErrorCodes.FILTER_NOT_FOUND;
388
- }
389
- }
390
-
391
- /**
392
- * An error thrown when an operation targeting a filter matching one name
393
- * matches a filter of another name.
394
- */
395
- class DaffFilterRequestNameMismatch extends DaffInheritableError {
396
- constructor(message) {
397
- super(message);
398
- this.code = DaffFilterErrorCodes.FILTER_REQUEST_NAME_MISMATCH;
399
- }
400
- }
401
-
402
- /**
403
- * Ensures that the names of the filter and the filter request match.
404
- *
405
- * @throws {@link DaffFilterNotFound} if the names do not match.
406
- */
273
+ var DaffFilterNotFound = class extends DaffInheritableError {
274
+ constructor(message) {
275
+ super(message);
276
+ this.code = DaffFilterErrorCodes.FILTER_NOT_FOUND;
277
+ }
278
+ };
279
+ var DaffFilterRequestNameMismatch = class extends DaffInheritableError {
280
+ constructor(message) {
281
+ super(message);
282
+ this.code = DaffFilterErrorCodes.FILTER_REQUEST_NAME_MISMATCH;
283
+ }
284
+ };
407
285
  const daffFilterValidateRequestNameMatch = (request, filter) => {
408
- if (!filter) {
409
- throw new DaffFilterNotFound('Filter does not exist');
410
- }
411
- if (request.name !== filter.name) {
412
- throw new DaffFilterRequestNameMismatch('Filter name does not match request name');
413
- }
286
+ if (!filter) throw new DaffFilterNotFound("Filter does not exist");
287
+ if (request.name !== filter.name) throw new DaffFilterRequestNameMismatch("Filter name does not match request name");
288
+ };
289
+ var DaffFilterRequestTypeMismatch = class extends DaffInheritableError {
290
+ constructor(message) {
291
+ super(message);
292
+ this.code = DaffFilterErrorCodes.FILTER_REQUEST_TYPE_MISMATCH;
293
+ }
414
294
  };
415
-
416
- /**
417
- * An error thrown when an operation targeting a filter matching one type
418
- * matches a filter of another type.
419
- */
420
- class DaffFilterRequestTypeMismatch extends DaffInheritableError {
421
- constructor(message) {
422
- super(message);
423
- this.code = DaffFilterErrorCodes.FILTER_REQUEST_TYPE_MISMATCH;
424
- }
425
- }
426
-
427
- /**
428
- * Ensures that the types of the filter and the filter request match.
429
- *
430
- * @throws {@link DaffFilterRequestTypeMismatch} if the types do not match.
431
- */
432
295
  const daffFilterValidateRequestTypeMatch = (request, filter) => {
433
- if (request.type !== filter.type) {
434
- throw new DaffFilterRequestTypeMismatch('Filter types don\'t match');
435
- }
296
+ if (request.type !== filter.type) throw new DaffFilterRequestTypeMismatch("Filter types don't match");
436
297
  };
437
-
438
- /**
439
- * Applies a filter request to the matching filter.
440
- *
441
- * @idempotent {filter}
442
- * @throws {@link DaffFilterUnknownType}
443
- */
444
298
  const daffApplyFilter = (request, filter) => {
445
- daffFilterValidateRequestNameMatch(request, filter);
446
- daffFilterValidateRequestTypeMatch(request, filter);
447
- switch (request.type) {
448
- case DaffFilterType.Equal:
449
- return daffApplyFilterEqual(request, filter);
450
- case (DaffFilterType.RangeNumeric):
451
- return daffApplyFilterRange(request, filter);
452
- default:
453
- throw new DaffFilterUnknownType('Unknown filter type');
454
- }
299
+ daffFilterValidateRequestNameMatch(request, filter);
300
+ daffFilterValidateRequestTypeMatch(request, filter);
301
+ switch (request.type) {
302
+ case DaffFilterType.Equal: return daffApplyFilterEqual(request, filter);
303
+ case DaffFilterType.RangeNumeric: return daffApplyFilterRange(request, filter);
304
+ default: throw new DaffFilterUnknownType("Unknown filter type");
305
+ }
455
306
  };
456
-
457
- /**
458
- * Applies a {@link DaffFilterRequest} to a dictionary of {@link DaffFilter}
459
- * returning the updated dictionary.
460
- *
461
- * @idempotent {filters}
462
- */
463
307
  const daffApplyRequestToFilters = (request, filters) => ({
464
- ...filters,
465
- [request.name]: daffApplyFilter(request, filters[request.name]),
308
+ ...filters,
309
+ [request.name]: daffApplyFilter(request, filters[request.name])
466
310
  });
467
-
468
- /**
469
- * Applies filters from a {@link DaffFilterRequest} to a dictionary
470
- * of {@link DaffFilter}.
471
- *
472
- * @idempotent {filters}
473
- */
474
311
  const daffApplyRequestsToFilters = (filtersRequests, filters) => filtersRequests.reduce((acc, request) => {
475
- acc[request.name] = daffApplyFilter(request, filters[request.name]);
476
- return acc;
312
+ acc[request.name] = daffApplyFilter(request, filters[request.name]);
313
+ return acc;
477
314
  }, { ...filters });
478
-
479
- /**
480
- * Unapplies the applied filter options of a {@link DaffFilterEqual}
481
- *
482
- * @idempotent {filter}
483
- * @docs-private
484
- */
485
315
  const daffClearFilterEqual = (filter) => ({
486
- ...filter,
487
- options: Object.keys(filter.options).map((key) => filter.options[key]).reduce((acc, option) => {
488
- acc[option.value] = {
489
- ...option,
490
- applied: false,
491
- };
492
- return acc;
493
- }, { ...filter.options }),
316
+ ...filter,
317
+ options: Object.keys(filter.options).map((key) => filter.options[key]).reduce((acc, option) => {
318
+ acc[option.value] = {
319
+ ...option,
320
+ applied: false
321
+ };
322
+ return acc;
323
+ }, { ...filter.options })
494
324
  });
495
-
496
- /**
497
- * Unapplies the applied filter options of a {@link DaffFilterRangeBase}
498
- *
499
- * @idempotent {filter}
500
- * @docs-private
501
- */
502
325
  const daffClearFilterRange = (filter) => ({
503
- ...filter,
504
- options: {},
326
+ ...filter,
327
+ options: {}
505
328
  });
506
-
507
- /**
508
- * Undoes the applied state of all applied filter options of a {@link DaffFilter}
509
- * returning the filter.
510
- *
511
- * @idempotent {filter}
512
- */
513
329
  const daffClearFilter = (filter) => {
514
- switch (filter.type) {
515
- case DaffFilterType.RangeNumeric:
516
- return daffClearFilterRange(filter);
517
- case DaffFilterType.Equal:
518
- return daffClearFilterEqual(filter);
519
- default:
520
- throw new DaffFilterUnknownType('Unknown filter type');
521
- }
330
+ switch (filter.type) {
331
+ case DaffFilterType.RangeNumeric: return daffClearFilterRange(filter);
332
+ case DaffFilterType.Equal: return daffClearFilterEqual(filter);
333
+ default: throw new DaffFilterUnknownType("Unknown filter type");
334
+ }
522
335
  };
523
-
524
- /**
525
- * Undoes the applied state of all applied filter options of a dictionary of {@link DaffFilter}
526
- * returning updated dictionary.
527
- *
528
- * @idempotent {filters}
529
- */
530
336
  const daffClearFilters = (filters) => Object.keys(filters).map((key) => filters[key]).reduce((acc, filter) => {
531
- acc[filter.name] = daffClearFilter(filter);
532
- return acc;
337
+ acc[filter.name] = daffClearFilter(filter);
338
+ return acc;
533
339
  }, {});
534
-
535
- /**
536
- * Removes the matching filter options of a {@link DaffFilterEqual}
537
- * that match the {@link DaffFilterEqualRequest}
538
- *
539
- * If there are no matching options, returns the original {@link DaffFilterEqual}
540
- *
541
- * @idempotent {filter}
542
- * @docs-private
543
- */
544
340
  const daffRemoveFilterEqual = (request, filter) => ({
545
- ...filter,
546
- options: request.value.reduce((acc, value) => {
547
- const option = filter.options[value];
548
- if (option) {
549
- acc[value] = {
550
- ...option,
551
- applied: false,
552
- };
553
- }
554
- return acc;
555
- }, { ...filter.options }),
341
+ ...filter,
342
+ options: request.value.reduce((acc, value) => {
343
+ const option = filter.options[value];
344
+ if (option) acc[value] = {
345
+ ...option,
346
+ applied: false
347
+ };
348
+ return acc;
349
+ }, { ...filter.options })
556
350
  });
557
-
558
- /**
559
- * Removes the matching filter options of a {@link DaffFilterRangeBase}
560
- * that match the {@link DaffFilterRangeRequestBase}
561
- *
562
- * If there are no matching options, returns the original {@link DaffFilterRangeBase}
563
- *
564
- * @idempotent {filter}
565
- * @docs-private
566
- */
567
- const daffRemoveFilterRange = (request, filter) => filter.options[daffFilterComputeRangePairLabel(request.value.min, request.value.max)]
568
- ? ({
569
- ...filter,
570
- options: {},
571
- })
572
- : filter;
573
-
574
- /**
575
- * Undoes any applied options of a {@link DaffFilter} that match the
576
- * {@link DaffFilterRequest}, returning the {@link DaffFilter}.
577
- *
578
- * @idempotent {filter}
579
- * @pure
580
- */
351
+ const daffRemoveFilterRange = (request, filter) => filter.options[daffFilterComputeRangePairLabel(request.value.min, request.value.max)] ? {
352
+ ...filter,
353
+ options: {}
354
+ } : filter;
581
355
  const daffRemoveFilter = (request, filter) => {
582
- daffFilterValidateRequestNameMatch(request, filter);
583
- daffFilterValidateRequestTypeMatch(request, filter);
584
- switch (request.type) {
585
- case DaffFilterType.Equal:
586
- return daffRemoveFilterEqual(request, filter);
587
- case (DaffFilterType.RangeNumeric):
588
- return daffRemoveFilterRange(request, filter);
589
- default:
590
- throw new DaffFilterUnknownType('Unknown filter type');
591
- }
356
+ daffFilterValidateRequestNameMatch(request, filter);
357
+ daffFilterValidateRequestTypeMatch(request, filter);
358
+ switch (request.type) {
359
+ case DaffFilterType.Equal: return daffRemoveFilterEqual(request, filter);
360
+ case DaffFilterType.RangeNumeric: return daffRemoveFilterRange(request, filter);
361
+ default: throw new DaffFilterUnknownType("Unknown filter type");
362
+ }
592
363
  };
593
-
594
- /**
595
- * Undoes any applied options of a particular filter of a dictionary of {@link DaffFilter}
596
- * that match the {@link DaffFilterRequest}, returning the dictionary of {@link DaffFilter}.
597
- *
598
- * @idempotent {filters}
599
- */
600
364
  const daffRemoveRequestFromFilters = (request, filters) => ({
601
- ...filters,
602
- [request.name]: daffRemoveFilter(request, filters[request.name]),
365
+ ...filters,
366
+ [request.name]: daffRemoveFilter(request, filters[request.name])
603
367
  });
604
-
605
- /**
606
- * Undoes all applied options of a dictionary of {@link DaffFilter}
607
- * that match any of the {@link DaffFilterRequest},
608
- * returning the updated dictionary of {@link DaffFilter}.
609
- *
610
- * @idempotent {filters}
611
- */
612
368
  const daffRemoveRequestsFromFilters = (requests, filters) => requests.reduce((acc, request) => {
613
- acc[request.name] = daffRemoveFilter(request, filters[request.name]);
614
- return acc;
369
+ acc[request.name] = daffRemoveFilter(request, filters[request.name]);
370
+ return acc;
615
371
  }, { ...filters });
616
-
617
- /**
618
- * Oscillates the applied state of the matching filter options of a {@link DaffFilterEqual}
619
- * that match the {@link DaffFilterEqualRequest}
620
- *
621
- * If there are no matching options, returns the original {@link DaffFilterEqual}
622
- *
623
- * @docs-private
624
- */
625
372
  const daffToggleFilterEqual = (request, filter) => {
626
- const option = filter.options[request.value];
627
- return option
628
- ? {
629
- ...filter,
630
- options: {
631
- ...filter.options,
632
- [option.value]: {
633
- ...option,
634
- applied: !option.applied,
635
- },
636
- },
637
- }
638
- : filter;
373
+ const option = filter.options[request.value];
374
+ return option ? {
375
+ ...filter,
376
+ options: {
377
+ ...filter.options,
378
+ [option.value]: {
379
+ ...option,
380
+ applied: !option.applied
381
+ }
382
+ }
383
+ } : filter;
639
384
  };
640
-
641
- /**
642
- * Oscillates the applied state of the matching filter options of a {@link DaffFilterRangeBase}
643
- * that match the {@link DaffFilterRangeRequestBase}
644
- *
645
- * If there are no matching options, returns the original {@link DaffFilterRangeBase}
646
- *
647
- * @docs-private
648
- */
649
- const daffToggleFilterRange = (request, filter) => filter.options[daffFilterComputeRangePairLabel(request.value.min, request.value.max)]
650
- ? daffRemoveFilterRange(request, filter)
651
- : daffApplyFilterRange(request, filter);
652
-
653
- /**
654
- * Toggles the state of the filters (and their options) in the {@link DaffFilter}
655
- * that match the {@link DaffFilterToggleRequest} .
656
- */
385
+ const daffToggleFilterRange = (request, filter) => filter.options[daffFilterComputeRangePairLabel(request.value.min, request.value.max)] ? daffRemoveFilterRange(request, filter) : daffApplyFilterRange(request, filter);
657
386
  function daffToggleFilter(request, filter) {
658
- daffFilterValidateRequestNameMatch(request, filter);
659
- daffFilterValidateRequestTypeMatch(request, filter);
660
- switch (request.type) {
661
- case DaffFilterType.Equal:
662
- return daffToggleFilterEqual(request, filter);
663
- case (DaffFilterType.RangeNumeric):
664
- return daffToggleFilterRange(request, filter);
665
- default:
666
- throw new DaffFilterUnknownType('Unknown filter type');
667
- }
387
+ daffFilterValidateRequestNameMatch(request, filter);
388
+ daffFilterValidateRequestTypeMatch(request, filter);
389
+ switch (request.type) {
390
+ case DaffFilterType.Equal: return daffToggleFilterEqual(request, filter);
391
+ case DaffFilterType.RangeNumeric: return daffToggleFilterRange(request, filter);
392
+ default: throw new DaffFilterUnknownType("Unknown filter type");
393
+ }
668
394
  }
669
-
670
- /**
671
- * Toggles the state of a filter option in the {@link DaffFilters}
672
- * that matches the {@link DaffFilterToggleRequest}.
673
- */
674
395
  const daffToggleRequestOnFilters = (request, filters) => ({
675
- ...filters,
676
- [request.name]: daffToggleFilter(request, filters[request.name]),
396
+ ...filters,
397
+ [request.name]: daffToggleFilter(request, filters[request.name])
677
398
  });
678
-
679
- /**
680
- * Determines whether or not the {@link DaffFilterEqual} has any applied options.
681
- */
682
- const daffIsFilterEqualApplied = (filter) => Object.keys(filter.options).map((key) => filter.options[key]).findIndex(option => option.applied) > -1;
683
-
684
- /**
685
- * Determines whether or not a {@link DaffFilterRangeBase} has any applied options.
686
- */
399
+ const daffIsFilterEqualApplied = (filter) => Object.keys(filter.options).map((key) => filter.options[key]).findIndex((option) => option.applied) > -1;
687
400
  const daffIsFilterRangeApplied = (filter) => Object.keys(filter.options).length > 0;
688
-
689
- /**
690
- * Determines whether or not a filter has any currently applied options.
691
- */
692
401
  const daffIsFilterApplied = (filter) => {
693
- switch (filter.type) {
694
- case DaffFilterType.RangeNumeric:
695
- return daffIsFilterRangeApplied(filter);
696
- case DaffFilterType.Equal:
697
- return daffIsFilterEqualApplied(filter);
698
- default:
699
- throw new DaffFilterUnknownType('Unknown filter type');
700
- }
402
+ switch (filter.type) {
403
+ case DaffFilterType.RangeNumeric: return daffIsFilterRangeApplied(filter);
404
+ case DaffFilterType.Equal: return daffIsFilterEqualApplied(filter);
405
+ default: throw new DaffFilterUnknownType("Unknown filter type");
406
+ }
701
407
  };
702
-
703
- /**
704
- * Determines whether or not any {@link DaffFilterEqual} options matching {@link DaffFilterEqualToggleRequest} are applied.
705
- */
706
408
  const daffIsEqualToggleRequestAppliedToFilter = (request, filter) => !!filter.options[request.value]?.applied;
707
-
708
- /**
709
- * Determines whether or not any {@link DaffFilterRangeBase} options matching {@link DaffFilterRangeRequestBase} are applied.
710
- */
711
409
  const daffIsRangeToggleRequestAppliedToFilter = (request, filter) => daffFilterComputeRangePairLabel(request.value.min, request.value.max) in filter.options;
712
-
713
- /**
714
- * Determines whether or not a {@link DaffFilterToggleRequest} is already applied to a {@link DaffFilter}.
715
- */
716
410
  const daffIsToggleRequestAppliedToFilter = (request, filter) => {
717
- switch (filter.type) {
718
- case DaffFilterType.RangeNumeric:
719
- return daffIsRangeToggleRequestAppliedToFilter(request, filter);
720
- case DaffFilterType.Equal:
721
- return daffIsEqualToggleRequestAppliedToFilter(request, filter);
722
- default:
723
- throw new DaffFilterUnknownType('Unknown filter type');
724
- }
411
+ switch (filter.type) {
412
+ case DaffFilterType.RangeNumeric: return daffIsRangeToggleRequestAppliedToFilter(request, filter);
413
+ case DaffFilterType.Equal: return daffIsEqualToggleRequestAppliedToFilter(request, filter);
414
+ default: throw new DaffFilterUnknownType("Unknown filter type");
415
+ }
725
416
  };
726
-
727
- /**
728
- * Finds the applied options in the filter.
729
- */
730
417
  const daffFilterFindAppliedOptions = (filter) => Object.keys(filter.options).map((key) => filter.options[key]).filter((option) => option.applied);
731
-
732
- /**
733
- * Builds an {@link DaffFilterEqualRequest} from the passed filter and options.
734
- */
735
418
  const daffFilterEqualToRequest = (filter) => {
736
- const options = daffFilterFindAppliedOptions(filter);
737
- if (!options.length) {
738
- return null;
739
- }
740
- return {
741
- type: DaffFilterType.Equal,
742
- name: filter.name,
743
- value: options.map(option => option.value),
744
- };
419
+ const options = daffFilterFindAppliedOptions(filter);
420
+ if (!options.length) return null;
421
+ return {
422
+ type: DaffFilterType.Equal,
423
+ name: filter.name,
424
+ value: options.map((option) => option.value)
425
+ };
745
426
  };
746
-
747
- /**
748
- * Builds a {@link DaffFilterRangeRequestBase} from the passed {@link DaffFilterRangeBase} and options.
749
- */
750
427
  const daffFilterRangeToRequest = (filter) => {
751
- const options = daffFilterFindAppliedOptions(filter);
752
- if (!options.length) {
753
- return null;
754
- }
755
- return {
756
- type: filter.type,
757
- name: filter.name,
758
- value: {
759
- min: options[0].min.value,
760
- max: options[0].max.value,
761
- },
762
- };
428
+ const options = daffFilterFindAppliedOptions(filter);
429
+ if (!options.length) return null;
430
+ return {
431
+ type: filter.type,
432
+ name: filter.name,
433
+ value: {
434
+ min: options[0].min.value,
435
+ max: options[0].max.value
436
+ }
437
+ };
763
438
  };
764
-
765
- /**
766
- * Transforms a {@link DaffFilterRangeNumeric} into a {@link DaffFilterRangeNumericRequest}
767
- */
768
439
  const daffFilterRangeNumericToRequest = (filter) => daffFilterRangeToRequest(filter);
769
-
770
- /**
771
- * Builds a filter request from a filter.
772
- * Returns null if the filter does not have at least one applied option.
773
- */
774
440
  function daffFilterToRequest(filter) {
775
- switch (filter.type) {
776
- case DaffFilterType.RangeNumeric:
777
- return daffFilterRangeNumericToRequest(filter);
778
- case DaffFilterType.Equal:
779
- return daffFilterEqualToRequest(filter);
780
- default:
781
- throw new DaffFilterUnknownType('Unknown filter type');
782
- }
441
+ switch (filter.type) {
442
+ case DaffFilterType.RangeNumeric: return daffFilterRangeNumericToRequest(filter);
443
+ case DaffFilterType.Equal: return daffFilterEqualToRequest(filter);
444
+ default: throw new DaffFilterUnknownType("Unknown filter type");
445
+ }
783
446
  }
784
- ;
785
-
786
- /**
787
- * Builds a list of filter requests from a list of filters.
788
- * Requests are only built for the filters that have at least one applied option.
789
- */
790
447
  function daffFiltersToRequests(filters) {
791
- return Object.keys(filters).map((key) => filters[key]).reduce((acc, filter) => {
792
- const request = daffFilterToRequest(filter);
793
- if (request) {
794
- acc.push(request);
795
- }
796
- return acc;
797
- }, []);
448
+ return Object.keys(filters).map((key) => filters[key]).reduce((acc, filter) => {
449
+ const request = daffFilterToRequest(filter);
450
+ if (request) acc.push(request);
451
+ return acc;
452
+ }, []);
798
453
  }
799
-
800
- /**
801
- * Recurses through a tree, collecting each element in that tree and returning it in an array.
802
- * The value of getKey should be a field that contains a list of the same type of object.
803
- * Accepts an optional depth argument which will limit the traversal. This should be used for trees with circular references.
804
- */
805
- const collect = (obj, getChildren, depth) => !depth || depth > 0
806
- ? [obj].concat(...getChildren(obj).map((child) => collect(child, getChildren, depth - 1)))
807
- : [obj];
808
-
809
- /**
810
- * A helper function to compute a power of 10 required to convert a decimal number to an integer
811
- * This function will fail if the given number has more than 16 significant figures or
812
- * the value of the number is greater than 10^11
813
- *
814
- * @param value
815
- */
454
+ const collect = (obj, getChildren, depth) => !depth || depth > 0 ? [obj].concat(...getChildren(obj).map((child) => collect(child, getChildren, depth - 1))) : [obj];
816
455
  function daffPrecision(value) {
817
- let p = 1;
818
- if (value === undefined ||
819
- value === null ||
820
- Number.isNaN(value) ||
821
- value === Infinity ||
822
- value === -Infinity) {
823
- return p;
824
- }
825
- while (Math.round(value * p) / p !== value) {
826
- p *= 10;
827
- if (p >= 1e11) {
828
- break;
829
- }
830
- }
831
- return p;
456
+ let p = 1;
457
+ if (value === void 0 || value === null || Number.isNaN(value) || value === Infinity || value === -Infinity) return p;
458
+ while (Math.round(value * p) / p !== value) {
459
+ p *= 10;
460
+ if (p >= 1e11) break;
461
+ }
462
+ return p;
832
463
  }
833
- /**
834
- * A function to add long numbers accurately with conversions and integer math.
835
- * This function only guarantees correct answers when the numbers given and the result are less than
836
- * 16 significant figures and less than 10^11
837
- *
838
- * @param numbers
839
- */
840
464
  function daffAdd(...numbers) {
841
- if (numbers.length === 0) {
842
- return undefined;
843
- }
844
- if (numbers.length === 1) {
845
- return numbers[0];
846
- }
847
- const precision = Math.max(...numbers.map(daffPrecision));
848
- return numbers.slice(1).reduce((acc, value) => acc + Math.round(value * precision), Math.round(numbers[0] * precision)) / precision;
465
+ if (numbers.length === 0) return;
466
+ if (numbers.length === 1) return numbers[0];
467
+ const precision = Math.max(...numbers.map(daffPrecision));
468
+ return numbers.slice(1).reduce((acc, value) => acc + Math.round(value * precision), Math.round(numbers[0] * precision)) / precision;
849
469
  }
850
- /**
851
- * A function to subtract long numbers accurately with conversions and integer math.
852
- * This function only guarantees correct answers when the numbers given and the result are each less than
853
- * 16 significant figures and less than 10^11
854
- *
855
- * @param numbers
856
- */
857
470
  function daffSubtract(...numbers) {
858
- if (numbers.length === 0) {
859
- return undefined;
860
- }
861
- if (numbers.length === 1) {
862
- return numbers[0];
863
- }
864
- const precision = Math.max(...numbers.map(daffPrecision));
865
- return numbers.slice(1).reduce((acc, value) => acc - Math.round(value * precision), Math.round(numbers[0] * precision)) / precision;
471
+ if (numbers.length === 0) return;
472
+ if (numbers.length === 1) return numbers[0];
473
+ const precision = Math.max(...numbers.map(daffPrecision));
474
+ return numbers.slice(1).reduce((acc, value) => acc - Math.round(value * precision), Math.round(numbers[0] * precision)) / precision;
866
475
  }
867
- /**
868
- * A function to multiply long numbers accurately with conversions and integer math.
869
- * This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
870
- * and less than 10^11
871
- *
872
- * @param numbers
873
- */
874
476
  function daffMultiply(...numbers) {
875
- if (numbers.length === 0) {
876
- return undefined;
877
- }
878
- if (numbers.length === 1) {
879
- return numbers[0];
880
- }
881
- const precision = Math.max(...numbers.map(daffPrecision));
882
- return numbers.reduce((acc, value) => acc * Math.round(value * precision), 1) / Math.pow(precision, numbers.length);
477
+ if (numbers.length === 0) return;
478
+ if (numbers.length === 1) return numbers[0];
479
+ const precision = Math.max(...numbers.map(daffPrecision));
480
+ return numbers.reduce((acc, value) => acc * Math.round(value * precision), 1) / Math.pow(precision, numbers.length);
883
481
  }
884
- /**
885
- * A function to divide long numbers accurately with conversions and integer math.
886
- * This function only guarantees correct answers when the numbers given and the result are each less than 16 significant figures
887
- * and less than 10^11
888
- *
889
- * Returns NaN when attempting to use NaN as an input.
890
- * Returns NaN when attempting to divide by 0 or null.
891
- *
892
- * @param numbers
893
- */
894
482
  function daffDivide(...numbers) {
895
- if (numbers.length === 0) {
896
- return undefined;
897
- }
898
- if (numbers.length === 1) {
899
- return numbers[0];
900
- }
901
- const precision = Math.max(...numbers.map(daffPrecision));
902
- return numbers.slice(1).reduce((acc, value) => acc / Math.round(value * precision), Math.round(numbers[0] * precision)) * Math.pow(precision, numbers.length - 2);
483
+ if (numbers.length === 0) return;
484
+ if (numbers.length === 1) return numbers[0];
485
+ const precision = Math.max(...numbers.map(daffPrecision));
486
+ return numbers.slice(1).reduce((acc, value) => acc / Math.round(value * precision), Math.round(numbers[0] * precision)) * Math.pow(precision, numbers.length - 2);
903
487
  }
904
-
905
- /**
906
- * Converts an array into a dictionary.
907
- * Dictionary values are keyed by the return of the specified `getKey`.
908
- */
909
488
  const daffArrayToDict = (array, getKey) => array.reduce((dict, val) => {
910
- dict[getKey(val)] = val;
911
- return dict;
489
+ dict[getKey(val)] = val;
490
+ return dict;
912
491
  }, {});
913
-
914
- /**
915
- * Returns a random slice of an array.
916
- * An optional length may be specified.
917
- *
918
- * @param array
919
- */
920
492
  const randomSlice = (array, length) => {
921
- if (array.length === 0) {
922
- return [];
923
- }
924
- ;
925
- if (length > array.length) {
926
- throw new Error('Requested length is longer than array length.');
927
- }
928
- const arrayLength = length || Math.floor(Math.random() * array.length);
929
- const start = Math.floor(Math.random() * (array.length - arrayLength + 1));
930
- const end = start + arrayLength;
931
- return array.slice(start, end);
493
+ if (array.length === 0) return [];
494
+ if (length > array.length) throw new Error("Requested length is longer than array length.");
495
+ const arrayLength = length || Math.floor(Math.random() * array.length);
496
+ const start = Math.floor(Math.random() * (array.length - arrayLength + 1));
497
+ const end = start + arrayLength;
498
+ return array.slice(start, end);
932
499
  };
933
-
934
- /**
935
- * Immutable Fisher-Yates Shuffle
936
- * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
937
- */
938
500
  const shuffle = (array) => {
939
- const result = [];
940
- array.forEach((el, i) => {
941
- const s = Math.floor(Math.random() * (i + 1));
942
- if (s !== i) {
943
- result[i] = result[s];
944
- }
945
- result[s] = el;
946
- });
947
- return result;
501
+ const result = [];
502
+ array.forEach((el, i) => {
503
+ const s = Math.floor(Math.random() * (i + 1));
504
+ if (s !== i) result[i] = result[s];
505
+ result[s] = el;
506
+ });
507
+ return result;
948
508
  };
949
-
950
- /**
951
- * Returns a random subset of an array in a random order.
952
- *
953
- * @param array
954
- * @param length
955
- */
956
509
  const randomSubset = (array, length) => {
957
- if (length > array.length) {
958
- throw new Error('Requested length is longer than array length.');
959
- }
960
- length = length ? length : Math.floor(Math.random() * array.length);
961
- return shuffle(array).slice(0, length);
510
+ if (length > array.length) throw new Error("Requested length is longer than array length.");
511
+ length = length ? length : Math.floor(Math.random() * array.length);
512
+ return shuffle(array).slice(0, length);
962
513
  };
963
-
964
- /**
965
- * Range
966
- *
967
- * Range accepts two inputs, a `start` and an `end`
968
- * and returns an array filled with numbers from
969
- * `start` to `end`.
970
- *
971
- * @param start
972
- * @param end
973
- * @returns number
974
- */
975
514
  const range = (start, end) => Array(end - start + 1).fill(0).map((val, index) => index + start);
976
-
977
- /**
978
- * Returns a random element of an array.
979
- */
980
515
  const sample = (array) => randomSlice(array, 1)[0];
981
-
982
- /**
983
- * Shallow compares two objects using a list of provided property keys to enumerate the values.
984
- * `null` and `undefined` are considered equal for the purposes of the comparison.
985
- * A strict equality comparison is used for truthy property values.
986
- */
987
516
  function shallowCompare(obj1, obj2, props) {
988
- return !!(obj1 && obj2 && props.reduce((acc, prop) => {
989
- const p1 = obj1[prop];
990
- const p2 = obj2[prop];
991
- return acc && (
992
- // undefined and null are treated as equal
993
- (p1 === undefined || p1 === null) && (p2 === undefined || p2 === null)
994
- || p1 === p2);
995
- }, true));
517
+ return !!(obj1 && obj2 && props.reduce((acc, prop) => {
518
+ const p1 = obj1[prop];
519
+ const p2 = obj2[prop];
520
+ return acc && ((p1 === void 0 || p1 === null) && (p2 === void 0 || p2 === null) || p1 === p2);
521
+ }, true));
996
522
  }
997
-
998
- /**
999
- * Filters an array of elements, removing duplicates.
1000
- * Does not guarantee order of filtered elements.
1001
- *
1002
- * An optional comparator function may be passed for arbitrary comparison behavior.
1003
- * The default is a strict equality comparison: `a === b`.
1004
- */
1005
- const unique = (array, comparator = (a, b) => a === b) => array.filter((a, index) => array.slice(index + 1).filter(b => comparator(a, b)).length === 0);
1006
-
1007
- /**
1008
- * The unary identity function.
1009
- * Returns whatever is passed to it.
1010
- */
523
+ const unique = (array, comparator = (a, b) => a === b) => array.filter((a, index) => array.slice(index + 1).filter((b) => comparator(a, b)).length === 0);
1011
524
  function identity(v) {
1012
- return v;
525
+ return v;
1013
526
  }
1014
-
1015
- /**
1016
- * Converts a value to an observable.
1017
- * If the value is an observable, just returns that observable.
1018
- * If the value is a promise, converts it to an observable (see rxjs `from`).
1019
- * If the value is neither, just returns an observable that immediately emits the value.
1020
- */
1021
527
  function observe(val) {
1022
- return isObservable(val) ? val : from(Promise.resolve(val));
528
+ return isObservable(val) ? val : from(Promise.resolve(val));
1023
529
  }
1024
-
1025
- /**
1026
- * Transforms an {@link DaffFilterRangePair[]} to a dictionary.
1027
- */
1028
- const daffFilterRangePairArrayToDict = (pairs) => daffArrayToDict(pairs, pair => daffFilterComputeRangePairLabel(pair.min.value, pair.max.value));
1029
-
1030
- /**
1031
- * Converts a list of equal filter options to a dict of options keyed by option value.
1032
- */
1033
- const daffFilterEqualOptionArrayToDict = (options) => daffArrayToDict(options, option => option.value);
1034
-
1035
- /**
1036
- * Converts a list of filters into a dictionary of filters keyed by filter name.
1037
- */
1038
- const daffFilterArrayToDict = (filters) => daffArrayToDict(filters, filter => filter.name);
1039
-
1040
- /**
1041
- * Returns a {@link DaffFilters} and only their applied options.
1042
- * {@link DaffFilter} that have no applied options will be omitted.
1043
- */
1044
- const daffComputeAppliedFilters = (filters) => Object.keys(filters).map(key => filters[key]).reduce((acc, filter) => {
1045
- const appliedOptions = daffFilterFindAppliedOptions(filter);
1046
- if (appliedOptions.length > 0) {
1047
- acc[filter.name] = {
1048
- ...filter,
1049
- options: filter.type === DaffFilterType.Equal
1050
- ? daffFilterEqualOptionArrayToDict(appliedOptions)
1051
- : daffFilterRangePairArrayToDict(appliedOptions),
1052
- };
1053
- }
1054
- return acc;
530
+ const daffFilterRangePairArrayToDict = (pairs) => daffArrayToDict(pairs, (pair) => daffFilterComputeRangePairLabel(pair.min.value, pair.max.value));
531
+ const daffFilterEqualOptionArrayToDict = (options) => daffArrayToDict(options, (option) => option.value);
532
+ const daffFilterArrayToDict = (filters) => daffArrayToDict(filters, (filter) => filter.name);
533
+ const daffComputeAppliedFilters = (filters) => Object.keys(filters).map((key) => filters[key]).reduce((acc, filter) => {
534
+ const appliedOptions = daffFilterFindAppliedOptions(filter);
535
+ if (appliedOptions.length > 0) acc[filter.name] = {
536
+ ...filter,
537
+ options: filter.type === DaffFilterType.Equal ? daffFilterEqualOptionArrayToDict(appliedOptions) : daffFilterRangePairArrayToDict(appliedOptions)
538
+ };
539
+ return acc;
1055
540
  }, {});
1056
-
1057
- /**
1058
- * Builds a {@link DaffCollectionRequest} from {@link DaffCollectionMetadata}.
1059
- */
1060
541
  const daffCollectionBuildRequestFromMetadata = (metadata) => ({
1061
- appliedSortOption: metadata.appliedSortOption,
1062
- appliedSortDirection: metadata.appliedSortDirection,
1063
- currentPage: metadata.currentPage,
1064
- pageSize: metadata.pageSize,
1065
- filterRequests: daffFiltersToRequests(metadata.filters),
542
+ appliedSortOption: metadata.appliedSortOption,
543
+ appliedSortDirection: metadata.appliedSortDirection,
544
+ currentPage: metadata.currentPage,
545
+ pageSize: metadata.pageSize,
546
+ filterRequests: daffFiltersToRequests(metadata.filters)
1066
547
  });
1067
-
1068
- /**
1069
- * Finds and returns the most recently created entity.
1070
- */
1071
548
  function daffCreateableMostRecent(createables) {
1072
- return createables.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0];
549
+ return createables.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0];
1073
550
  }
1074
-
1075
- /**
1076
- * A utility decorator that delays method execution until after a specified delay period has elapsed since the last invocation.
1077
- *
1078
- * @param delay - The delay in milliseconds before the method executes. Defaults to 100ms.
1079
- * @returns A method decorator that can be applied to class methods.
1080
- *
1081
- * @example Basic usage with custom delay
1082
- * ```ts
1083
- * import { debounce } from '@daffodil/core';
1084
- *
1085
- * class SearchComponent {
1086
- * @debounce(300)
1087
- * onSearchInput(value: string) {
1088
- * // Only executes after 300ms
1089
- * this.performSearch(value);
1090
- * }
1091
- * }
1092
- * ```
1093
- *
1094
- * @example Using default delay (100ms)
1095
- * ```ts
1096
- * class MyComponent {
1097
- * @debounce() // Uses 100ms default
1098
- * onInputChange(value: string) {
1099
- * console.log('Input changed:', value);
1100
- * }
1101
- * }
1102
- * ```
1103
- *
1104
- * @example Angular component integration
1105
- * ```ts
1106
- * import { Component } from '@angular/core';
1107
- * import { debounce } from '@daffodil/core';
1108
- *
1109
- * @Component({
1110
- * selector: 'app-search',
1111
- * template: '<input (input)="onSearchInput($event.target.value)" />',
1112
- * })
1113
- * export class SearchComponent {
1114
- * @debounce(500)
1115
- * onSearchInput(value: string) {
1116
- * this.searchService.search(value);
1117
- * }
1118
- * }
1119
- * ```
1120
- */
1121
551
  const debounce = (delay = 100) => (target, propertyKey, descriptor) => {
1122
- const originalMethod = descriptor.value;
1123
- let timeoutId = null;
1124
- descriptor.value = function (...args) {
1125
- if (timeoutId) {
1126
- clearTimeout(timeoutId);
1127
- timeoutId = null;
1128
- }
1129
- timeoutId = setTimeout(() => {
1130
- originalMethod.apply(this, args);
1131
- timeoutId = null;
1132
- }, delay);
1133
- };
1134
- return descriptor;
552
+ const originalMethod = descriptor.value;
553
+ let timeoutId = null;
554
+ descriptor.value = function(...args) {
555
+ if (timeoutId) {
556
+ clearTimeout(timeoutId);
557
+ timeoutId = null;
558
+ }
559
+ timeoutId = setTimeout(() => {
560
+ originalMethod.apply(this, args);
561
+ timeoutId = null;
562
+ }, delay);
563
+ };
564
+ return descriptor;
1135
565
  };
1136
-
1137
- /**
1138
- * Transforms an array of {@link DaffIdentifiable} objects to a dictionary of those objects keyed by ID.
1139
- */
1140
566
  const daffIdentifiableArrayToDict = (ary) => daffArrayToDict(ary, ({ id }) => id);
1141
-
1142
567
  function daffArrayConcatMerger(a, b) {
1143
- return a.concat(b);
568
+ return a.concat(b);
1144
569
  }
1145
-
1146
570
  function daffDictAssignMerger(a, b) {
1147
- return {
1148
- ...a,
1149
- ...b,
1150
- };
571
+ return {
572
+ ...a,
573
+ ...b
574
+ };
1151
575
  }
1152
-
1153
- /**
1154
- * Merges dictionaries with a specific strategy for handling collisions.
1155
- * @see {@link DaffMergeStrategy}.
1156
- *
1157
- * @example Merging two dictionaries with predefined mergers
1158
- *
1159
- * ```ts
1160
- * const a = {
1161
- * ary: [1, 2],
1162
- * obj: {foo: 5, bar: 10}
1163
- * }
1164
- * const a = {
1165
- * ary: [3, 4],
1166
- * obj: {foo: 6},
1167
- * fish: 'tacos'
1168
- * }
1169
- * const result = daffMerge(
1170
- * [a, b],
1171
- * {
1172
- * ary: daffArrayConcatMerger,
1173
- * obj: daffDictAssignMerger
1174
- * }
1175
- * )
1176
- * ```
1177
- * the value of result would be:
1178
- * ```ts
1179
- * {
1180
- * ary: [1, 2, 3, 4],
1181
- * obj: {foo: 6, bar: 10},
1182
- * fish: 'tacos'
1183
- * }
1184
- * ```
1185
- *
1186
- * @example Merging two dictionaries with predefined mergers
1187
- *
1188
- * ```ts
1189
- * const a = {
1190
- * ary: [1, 2],
1191
- * obj: {foo: 5, bar: 10}
1192
- * }
1193
- * const a = {
1194
- * ary: [3, 4],
1195
- * obj: {foo: 6},
1196
- * fish: 'tacos'
1197
- * }
1198
- * const result = daffMerge(
1199
- * [a, b],
1200
- * {
1201
- * ary: daffArrayConcatMerger,
1202
- * obj: daffDictAssignMerger
1203
- * }
1204
- * )
1205
- * ```
1206
- * the value of result would be:
1207
- * ```ts
1208
- * {
1209
- * ary: [1, 2, 3, 4],
1210
- * obj: {foo: 6, bar: 10},
1211
- * fish: 'tacos'
1212
- * }
1213
- * ```
1214
- */
1215
576
  const daffMerge = (dicts, strategy = {}) => dicts.reduce((acc, dict) => {
1216
- for (const k in dict) {
1217
- if (Object.hasOwn(acc, k) && strategy[k]) {
1218
- acc[k] = strategy[k](acc[k], dict[k]);
1219
- }
1220
- else {
1221
- acc[k] = dict[k];
1222
- }
1223
- }
1224
- return acc;
577
+ for (const k in dict) if (Object.hasOwn(acc, k) && strategy[k]) acc[k] = strategy[k](acc[k], dict[k]);
578
+ else acc[k] = dict[k];
579
+ return acc;
1225
580
  }, {});
1226
-
1227
- /**
1228
- * Retries failed Observables
1229
- *
1230
- * @param maxTries The maximum number of tries the observable will be tried
1231
- * @param ms The initial amount of time
1232
- */
1233
581
  function backoff(maxTries, ms) {
1234
- return pipe(retryWhen(attempt => attempt.pipe(mergeMap((shadowedAttempt, i) => {
1235
- if (i >= maxTries) {
1236
- return throwError(shadowedAttempt);
1237
- }
1238
- return timer(ms * Math.pow(2, i));
1239
- }))));
582
+ return pipe(retryWhen((attempt) => attempt.pipe(mergeMap((shadowedAttempt, i) => {
583
+ if (i >= maxTries) return throwError(shadowedAttempt);
584
+ return timer(ms * Math.pow(2, i));
585
+ }))));
1240
586
  }
1241
-
1242
- /**
1243
- * Accepts a list of input observables and emits true when any of the inputs emit a truthy value.
1244
- * Does not emit until all of the input streams have emitted at least once.
1245
- */
1246
587
  const anyOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg || el, false)));
1247
-
1248
- /**
1249
- * Accepts a list of input observables and emits true when all of the inputs emit a truthy value.
1250
- * Does not emit until all of the input streams have emitted at least once.
1251
- */
1252
588
  const allOf = (items) => combineLatest(items).pipe(map((els) => els.reduce((agg, el) => agg && el, true)));
1253
-
1254
- /**
1255
- * Catches errors and invokes the callback with an array of errors.
1256
- */
1257
589
  const catchAndArrayifyErrors = (transformError) => pipe(catchError((err) => transformError(Array.isArray(err) ? err : [err])));
1258
-
1259
- const DAFF_STORAGE_SERVICE_ERROR_CODE = 'DAFF_STORAGE_FAILURE';
1260
- class DaffStorageServiceError extends DaffInheritableError {
1261
- constructor(message) {
1262
- super(message);
1263
- this.message = message;
1264
- this.code = DAFF_STORAGE_SERVICE_ERROR_CODE;
1265
- }
1266
- }
1267
-
1268
- /**
1269
- * @inheritdoc
1270
- */
1271
- class DaffErrorStorageService {
1272
- static { this.ERROR_MESSAGE = 'The DaffErrorStorageService always throws an error.'; }
1273
- setItem(key, value) {
1274
- this.throwError();
1275
- }
1276
- getItem(key) {
1277
- this.throwError();
1278
- }
1279
- removeItem(key) {
1280
- this.throwError();
1281
- }
1282
- clear() {
1283
- this.throwError();
1284
- }
1285
- throwError() {
1286
- throw new DaffStorageServiceError(DaffErrorStorageService.ERROR_MESSAGE);
1287
- }
1288
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffErrorStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1289
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffErrorStorageService, providedIn: 'root' }); }
1290
- }
1291
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffErrorStorageService, decorators: [{
1292
- type: Injectable,
1293
- args: [{
1294
- providedIn: 'root',
1295
- }]
1296
- }] });
1297
-
1298
- const DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE = 'DAFF_SERVER_STORAGE_FAILURE';
1299
- /**
1300
- * An error thrown when there is an attempt to access storage on the server and none is available.
1301
- */
1302
- class DaffServerSideStorageError extends DaffStorageServiceError {
1303
- constructor(message) {
1304
- super(message);
1305
- this.message = message;
1306
- this.code = DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE;
1307
- }
1308
- }
1309
-
1310
- /**
1311
- * A storage service meant to be loaded into SSR contexts.
1312
- * It will always throw the {@link DaffServerSideStorageError}.
1313
- *
1314
- * @inheritdoc
1315
- */
1316
- class DaffServerErrorStorageService {
1317
- static { this.ERROR_MESSAGE = 'The DaffServerErrorStorageService always throws an error.'; }
1318
- setItem(key, value) {
1319
- this.throwError();
1320
- }
1321
- getItem(key) {
1322
- this.throwError();
1323
- }
1324
- removeItem(key) {
1325
- this.throwError();
1326
- }
1327
- clear() {
1328
- this.throwError();
1329
- }
1330
- throwError() {
1331
- throw new DaffServerSideStorageError(DaffServerErrorStorageService.ERROR_MESSAGE);
1332
- }
1333
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerErrorStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1334
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerErrorStorageService, providedIn: 'root' }); }
1335
- }
1336
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffServerErrorStorageService, decorators: [{
1337
- type: Injectable,
1338
- args: [{
1339
- providedIn: 'root',
1340
- }]
1341
- }] });
1342
-
1343
- /**
1344
- * @inheritdoc
1345
- */
1346
- class DaffLocalStorageService {
1347
- constructor(platformId) {
1348
- if (!isPlatformBrowser(platformId)) {
1349
- throw new Error('The DaffLocalStorageService can only be instantiated in the browser.');
1350
- }
1351
- }
1352
- /**
1353
- * Persist the given item into local storage.
1354
- */
1355
- setItem(key, value) {
1356
- localStorage.setItem(key, value);
1357
- }
1358
- /**
1359
- * Retrieve the given item from localstorage.
1360
- */
1361
- getItem(key) {
1362
- return localStorage.getItem(key);
1363
- }
1364
- /**
1365
- * Remove a given item from localstorage
1366
- */
1367
- removeItem(key) {
1368
- localStorage.removeItem(key);
1369
- }
1370
- clear() {
1371
- localStorage.clear();
1372
- }
1373
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffLocalStorageService, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
1374
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffLocalStorageService, providedIn: 'root' }); }
1375
- }
1376
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffLocalStorageService, decorators: [{
1377
- type: Injectable,
1378
- args: [{
1379
- providedIn: 'root',
1380
- }]
1381
- }], ctorParameters: () => [{ type: undefined, decorators: [{
1382
- type: Inject,
1383
- args: [PLATFORM_ID]
1384
- }] }] });
1385
-
1386
- /**
1387
- * @inheritdoc
1388
- */
1389
- class DaffNoopStorageService {
1390
- setItem(key, value) { }
1391
- ;
1392
- getItem(key) { }
1393
- ;
1394
- clear() { }
1395
- ;
1396
- removeItem(key) { }
1397
- ;
1398
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffNoopStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1399
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffNoopStorageService, providedIn: 'root' }); }
1400
- }
1401
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffNoopStorageService, decorators: [{
1402
- type: Injectable,
1403
- args: [{
1404
- providedIn: 'root',
1405
- }]
1406
- }] });
1407
-
1408
- /**
1409
- * @inheritdoc
1410
- */
1411
- class DaffMemoryStorageService {
1412
- constructor() {
1413
- this.memory = {};
1414
- }
1415
- setItem(key, value) {
1416
- this.memory[key] = value;
1417
- }
1418
- getItem(key) {
1419
- return this.memory[key];
1420
- }
1421
- clear() {
1422
- this.memory = {};
1423
- }
1424
- /**
1425
- * We abuse destructuring to remove the key
1426
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
1427
- */
1428
- removeItem(key) {
1429
- const { [key]: value, ...noKey } = this.memory;
1430
- this.memory = noKey;
1431
- }
1432
- }
1433
-
1434
- const { token: DaffPersistenceServiceToken,
1435
- /**
1436
- * Provider function for {@link DaffPersistenceServiceToken}.
1437
- */
1438
- provider: provideDaffPersistenceService, } = createSingleInjectionToken('DaffPersistenceServiceToken', {
1439
- providedIn: 'root',
1440
- factory: () => isPlatformBrowser(inject(PLATFORM_ID))
1441
- ? new DaffLocalStorageService(inject(PLATFORM_ID))
1442
- : new DaffServerErrorStorageService(),
590
+ const DAFF_STORAGE_SERVICE_ERROR_CODE = "DAFF_STORAGE_FAILURE";
591
+ var DaffStorageServiceError = class extends DaffInheritableError {
592
+ constructor(message) {
593
+ super(message);
594
+ this.message = message;
595
+ this.code = DAFF_STORAGE_SERVICE_ERROR_CODE;
596
+ }
597
+ };
598
+ var DaffErrorStorageService = class DaffErrorStorageService {
599
+ static {
600
+ this.ERROR_MESSAGE = "The DaffErrorStorageService always throws an error.";
601
+ }
602
+ setItem(key, value) {
603
+ this.throwError();
604
+ }
605
+ getItem(key) {
606
+ this.throwError();
607
+ }
608
+ removeItem(key) {
609
+ this.throwError();
610
+ }
611
+ clear() {
612
+ this.throwError();
613
+ }
614
+ throwError() {
615
+ throw new DaffStorageServiceError(DaffErrorStorageService.ERROR_MESSAGE);
616
+ }
617
+ static {
618
+ this.ɵfac = i0.ɵɵngDeclareFactory({
619
+ minVersion: "12.0.0",
620
+ version: "22.2.4",
621
+ ngImport: i0,
622
+ type: DaffErrorStorageService,
623
+ deps: [],
624
+ target: i0.ɵɵFactoryTarget.Injectable
625
+ });
626
+ }
627
+ static {
628
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
629
+ minVersion: "12.0.0",
630
+ version: "22.2.4",
631
+ ngImport: i0,
632
+ type: DaffErrorStorageService,
633
+ providedIn: "root"
634
+ });
635
+ }
636
+ };
637
+ i0.ɵɵngDeclareClassMetadata({
638
+ minVersion: "12.0.0",
639
+ version: "22.2.4",
640
+ ngImport: i0,
641
+ type: DaffErrorStorageService,
642
+ decorators: [{
643
+ type: Injectable,
644
+ args: [{ providedIn: "root" }]
645
+ }]
1443
646
  });
1444
-
1445
- const {
1446
- /**
1447
- * Provides noop for the persistence service on the server.
1448
- */
1449
- token: DaffServerSafePersistenceServiceToken,
1450
- /**
1451
- * Provider function for {@link DaffServerSafePersistenceServiceToken}.
1452
- */
1453
- provider: provideDaffServerSafePersistenceServiceToken, } = createSingleInjectionToken('DaffServerSafePersistenceService', {
1454
- providedIn: 'root',
1455
- factory: () => isPlatformBrowser(inject(PLATFORM_ID))
1456
- ? inject(DaffPersistenceServiceToken)
1457
- : inject(DaffNoopStorageService),
647
+ const DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE = "DAFF_SERVER_STORAGE_FAILURE";
648
+ var DaffServerSideStorageError = class extends DaffStorageServiceError {
649
+ constructor(message) {
650
+ super(message);
651
+ this.message = message;
652
+ this.code = DAFF_SERVER_STORAGE_SERVICE_ERROR_CODE;
653
+ }
654
+ };
655
+ var DaffServerErrorStorageService = class DaffServerErrorStorageService {
656
+ static {
657
+ this.ERROR_MESSAGE = "The DaffServerErrorStorageService always throws an error.";
658
+ }
659
+ setItem(key, value) {
660
+ this.throwError();
661
+ }
662
+ getItem(key) {
663
+ this.throwError();
664
+ }
665
+ removeItem(key) {
666
+ this.throwError();
667
+ }
668
+ clear() {
669
+ this.throwError();
670
+ }
671
+ throwError() {
672
+ throw new DaffServerSideStorageError(DaffServerErrorStorageService.ERROR_MESSAGE);
673
+ }
674
+ static {
675
+ this.ɵfac = i0.ɵɵngDeclareFactory({
676
+ minVersion: "12.0.0",
677
+ version: "22.2.4",
678
+ ngImport: i0,
679
+ type: DaffServerErrorStorageService,
680
+ deps: [],
681
+ target: i0.ɵɵFactoryTarget.Injectable
682
+ });
683
+ }
684
+ static {
685
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
686
+ minVersion: "12.0.0",
687
+ version: "22.2.4",
688
+ ngImport: i0,
689
+ type: DaffServerErrorStorageService,
690
+ providedIn: "root"
691
+ });
692
+ }
693
+ };
694
+ i0.ɵɵngDeclareClassMetadata({
695
+ minVersion: "12.0.0",
696
+ version: "22.2.4",
697
+ ngImport: i0,
698
+ type: DaffServerErrorStorageService,
699
+ decorators: [{
700
+ type: Injectable,
701
+ args: [{ providedIn: "root" }]
702
+ }]
703
+ });
704
+ var DaffLocalStorageService = class DaffLocalStorageService {
705
+ constructor(platformId) {
706
+ if (!isPlatformBrowser(platformId)) throw new Error("The DaffLocalStorageService can only be instantiated in the browser.");
707
+ }
708
+ setItem(key, value) {
709
+ localStorage.setItem(key, value);
710
+ }
711
+ getItem(key) {
712
+ return localStorage.getItem(key);
713
+ }
714
+ removeItem(key) {
715
+ localStorage.removeItem(key);
716
+ }
717
+ clear() {
718
+ localStorage.clear();
719
+ }
720
+ static {
721
+ this.ɵfac = i0.ɵɵngDeclareFactory({
722
+ minVersion: "12.0.0",
723
+ version: "22.2.4",
724
+ ngImport: i0,
725
+ type: DaffLocalStorageService,
726
+ deps: [{ token: PLATFORM_ID }],
727
+ target: i0.ɵɵFactoryTarget.Injectable
728
+ });
729
+ }
730
+ static {
731
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
732
+ minVersion: "12.0.0",
733
+ version: "22.2.4",
734
+ ngImport: i0,
735
+ type: DaffLocalStorageService,
736
+ providedIn: "root"
737
+ });
738
+ }
739
+ };
740
+ i0.ɵɵngDeclareClassMetadata({
741
+ minVersion: "12.0.0",
742
+ version: "22.2.4",
743
+ ngImport: i0,
744
+ type: DaffLocalStorageService,
745
+ decorators: [{
746
+ type: Injectable,
747
+ args: [{ providedIn: "root" }]
748
+ }],
749
+ ctorParameters: () => [{
750
+ type: void 0,
751
+ decorators: [{
752
+ type: Inject,
753
+ args: [PLATFORM_ID]
754
+ }]
755
+ }]
756
+ });
757
+ var DaffNoopStorageService = class DaffNoopStorageService {
758
+ setItem(key, value) {}
759
+ getItem(key) {}
760
+ clear() {}
761
+ removeItem(key) {}
762
+ static {
763
+ this.ɵfac = i0.ɵɵngDeclareFactory({
764
+ minVersion: "12.0.0",
765
+ version: "22.2.4",
766
+ ngImport: i0,
767
+ type: DaffNoopStorageService,
768
+ deps: [],
769
+ target: i0.ɵɵFactoryTarget.Injectable
770
+ });
771
+ }
772
+ static {
773
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
774
+ minVersion: "12.0.0",
775
+ version: "22.2.4",
776
+ ngImport: i0,
777
+ type: DaffNoopStorageService,
778
+ providedIn: "root"
779
+ });
780
+ }
781
+ };
782
+ i0.ɵɵngDeclareClassMetadata({
783
+ minVersion: "12.0.0",
784
+ version: "22.2.4",
785
+ ngImport: i0,
786
+ type: DaffNoopStorageService,
787
+ decorators: [{
788
+ type: Injectable,
789
+ args: [{ providedIn: "root" }]
790
+ }]
791
+ });
792
+ var DaffMemoryStorageService = class DaffMemoryStorageService {
793
+ constructor() {
794
+ this.memory = {};
795
+ }
796
+ setItem(key, value) {
797
+ this.memory[key] = value;
798
+ }
799
+ getItem(key) {
800
+ return this.memory[key];
801
+ }
802
+ clear() {
803
+ this.memory = {};
804
+ }
805
+ removeItem(key) {
806
+ const { [key]: value, ...noKey } = this.memory;
807
+ this.memory = noKey;
808
+ }
809
+ static {
810
+ this.ɵfac = i0.ɵɵngDeclareFactory({
811
+ minVersion: "12.0.0",
812
+ version: "22.2.4",
813
+ ngImport: i0,
814
+ type: DaffMemoryStorageService,
815
+ deps: [],
816
+ target: i0.ɵɵFactoryTarget.Injectable
817
+ });
818
+ }
819
+ static {
820
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
821
+ minVersion: "12.0.0",
822
+ version: "22.2.4",
823
+ ngImport: i0,
824
+ type: DaffMemoryStorageService,
825
+ providedIn: "root"
826
+ });
827
+ }
828
+ };
829
+ i0.ɵɵngDeclareClassMetadata({
830
+ minVersion: "12.0.0",
831
+ version: "22.2.4",
832
+ ngImport: i0,
833
+ type: DaffMemoryStorageService,
834
+ decorators: [{
835
+ type: Injectable,
836
+ args: [{ providedIn: "root" }]
837
+ }]
838
+ });
839
+ const { token: DaffPersistenceServiceToken, provider: provideDaffPersistenceService } = createSingleInjectionToken("DaffPersistenceServiceToken", {
840
+ providedIn: "root",
841
+ factory: () => isPlatformBrowser(inject(PLATFORM_ID)) ? new DaffLocalStorageService(inject(PLATFORM_ID)) : new DaffServerErrorStorageService()
842
+ });
843
+ const { token: DaffServerSafePersistenceServiceToken, provider: provideDaffServerSafePersistenceServiceToken } = createSingleInjectionToken("DaffServerSafePersistenceService", {
844
+ providedIn: "root",
845
+ factory: () => isPlatformBrowser(inject(PLATFORM_ID)) ? inject(DaffPersistenceServiceToken) : inject(DaffNoopStorageService)
1458
846
  });
1459
-
1460
- /**
1461
- * Validates whether all the specified fields are defined in the passed object.
1462
- * Uses `Object.hasOwn` to do the check, so even if a field has been set to `null`
1463
- * or `undefined`, they will be treated as present.
1464
- */
1465
847
  const validateFieldPresence = (model, ...fields) => fields.reduce((acc, field) => acc && Object.hasOwn(model, field), true);
1466
-
1467
- /**
1468
- * Generated bundle index. Do not edit.
1469
- */
1470
-
1471
848
  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, DaffMemoryStorageService, 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, daffCreateableMostRecent, daffDictAssignMerger, daffDivide, daffFilterArrayToDict, daffFilterComputeRangePairLabel, daffFilterEqualOptionArrayToDict, daffFilterFindAppliedOptions, daffFilterRangePairArrayToDict, daffFilterToRequest, daffFilterValidateRequestNameMatch, daffFilterValidateRequestTypeMatch, daffFiltersToRequests, daffIdentifiableArrayToDict, daffIsError, daffIsFilterApplied, daffIsToggleRequestAppliedToFilter, daffMerge, daffMultiply, daffPrecision, daffRemoveFilter, daffRemoveRequestFromFilters, daffRemoveRequestsFromFilters, daffSubtract, daffToggleFilter, daffToggleRequestOnFilters, debounce, identity, observe, provideVercelImageLoader, randomSlice, randomSubset, range, sample, shallowCompare, shuffle, unique, validateFieldPresence };
1472
- //# sourceMappingURL=daffodil-core.mjs.map
849
+
850
+ //# sourceMappingURL=daffodil-core.mjs.map