ng-qubee 1.0.9 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +90 -67
  2. package/esm2022/lib/enums/sort.enum.mjs +6 -0
  3. package/esm2022/lib/errors/key-not-found.error.mjs +6 -0
  4. package/esm2022/lib/errors/unselectable-model.error.mjs +6 -0
  5. package/esm2022/lib/interfaces/config.interface.mjs +2 -0
  6. package/esm2022/lib/interfaces/fields.interface.mjs +2 -0
  7. package/esm2022/lib/interfaces/filters.interface.mjs +2 -0
  8. package/esm2022/lib/interfaces/normalized.interface.mjs +2 -0
  9. package/esm2022/lib/interfaces/paginated-object.interface.mjs +2 -0
  10. package/esm2022/lib/interfaces/pagination-config.interface.mjs +2 -0
  11. package/esm2022/lib/interfaces/query-builder-config.interface.mjs +2 -0
  12. package/esm2022/lib/interfaces/query-builder-state.interface.mjs +2 -0
  13. package/esm2022/lib/interfaces/sort.interface.mjs +2 -0
  14. package/esm2022/lib/models/paginated-collection.mjs +47 -0
  15. package/esm2022/lib/models/query-builder-options.mjs +12 -0
  16. package/esm2022/lib/models/response-options.mjs +17 -0
  17. package/esm2022/lib/ng-qubee.module.mjs +42 -0
  18. package/esm2022/lib/provide-ngqubee.mjs +39 -0
  19. package/esm2022/lib/services/nest.service.mjs +173 -0
  20. package/esm2022/lib/services/ng-qubee.service.mjs +319 -0
  21. package/esm2022/lib/services/pagination.service.mjs +23 -0
  22. package/esm2022/ng-qubee.mjs +5 -0
  23. package/esm2022/public-api.mjs +9 -0
  24. package/fesm2022/ng-qubee.mjs +678 -0
  25. package/fesm2022/ng-qubee.mjs.map +1 -0
  26. package/index.d.ts +5 -0
  27. package/lib/interfaces/normalized.interface.d.ts +3 -0
  28. package/lib/interfaces/paginated-object.interface.d.ts +3 -0
  29. package/lib/interfaces/query-builder-state.interface.d.ts +1 -2
  30. package/lib/interfaces/sort.interface.d.ts +2 -1
  31. package/lib/models/paginated-collection.d.ts +18 -16
  32. package/lib/ng-qubee.module.d.ts +4 -1
  33. package/lib/provide-ngqubee.d.ts +21 -0
  34. package/lib/services/nest.service.d.ts +81 -0
  35. package/lib/{ng-qubee.service.d.ts → services/ng-qubee.service.d.ts} +30 -8
  36. package/lib/services/pagination.service.d.ts +5 -1
  37. package/package.json +20 -18
  38. package/public-api.d.ts +3 -2
  39. package/bundles/ng-qubee.umd.js +0 -909
  40. package/bundles/ng-qubee.umd.js.map +0 -1
  41. package/bundles/ng-qubee.umd.min.js +0 -16
  42. package/bundles/ng-qubee.umd.min.js.map +0 -1
  43. package/esm2015/lib/actions/query-builder.actions.js +0 -17
  44. package/esm2015/lib/enums/sort.enum.js +0 -6
  45. package/esm2015/lib/errors/key-not-found.error.js +0 -6
  46. package/esm2015/lib/errors/unselectable-model.error.js +0 -6
  47. package/esm2015/lib/interfaces/config.interface.js +0 -2
  48. package/esm2015/lib/interfaces/fields.interface.js +0 -2
  49. package/esm2015/lib/interfaces/filters.interface.js +0 -2
  50. package/esm2015/lib/interfaces/nest-state.interface.js +0 -2
  51. package/esm2015/lib/interfaces/pagination-config.interface.js +0 -2
  52. package/esm2015/lib/interfaces/query-builder-config.interface.js +0 -2
  53. package/esm2015/lib/interfaces/query-builder-state.interface.js +0 -2
  54. package/esm2015/lib/interfaces/sort.interface.js +0 -2
  55. package/esm2015/lib/models/paginated-collection.js +0 -45
  56. package/esm2015/lib/models/query-builder-options.js +0 -12
  57. package/esm2015/lib/models/response-options.js +0 -17
  58. package/esm2015/lib/ng-qubee.module.js +0 -33
  59. package/esm2015/lib/ng-qubee.service.js +0 -280
  60. package/esm2015/lib/reducers/query-builder.reducer.js +0 -51
  61. package/esm2015/lib/services/pagination.service.js +0 -18
  62. package/esm2015/lib/services/store.service.js +0 -26
  63. package/esm2015/ng-qubee.js +0 -6
  64. package/esm2015/public-api.js +0 -8
  65. package/fesm2015/ng-qubee.js +0 -508
  66. package/fesm2015/ng-qubee.js.map +0 -1
  67. package/lib/actions/query-builder.actions.d.ts +0 -43
  68. package/lib/interfaces/nest-state.interface.d.ts +0 -4
  69. package/lib/reducers/query-builder.reducer.d.ts +0 -2
  70. package/lib/services/store.service.d.ts +0 -9
  71. package/ng-qubee.d.ts +0 -7
  72. package/ng-qubee.metadata.json +0 -1
@@ -0,0 +1,678 @@
1
+ import * as i0 from '@angular/core';
2
+ import { signal, computed, Injectable, Inject, Optional, NgModule, makeEnvironmentProviders } from '@angular/core';
3
+ import * as qs from 'qs';
4
+ import { BehaviorSubject, filter } from 'rxjs';
5
+
6
+ class KeyNotFoundError extends Error {
7
+ constructor(key) {
8
+ super(`Cannot find the key ${key} inside the collection item: does it really exists?`);
9
+ }
10
+ }
11
+
12
+ class PaginatedCollection {
13
+ constructor(data, page, from, to, total, perPage, prevPageUrl, nextPageUrl, lastPage, firstPageUrl, lastPageUrl) {
14
+ this.data = data;
15
+ this.page = page;
16
+ this.from = from;
17
+ this.to = to;
18
+ this.total = total;
19
+ this.perPage = perPage;
20
+ this.prevPageUrl = prevPageUrl;
21
+ this.nextPageUrl = nextPageUrl;
22
+ this.lastPage = lastPage;
23
+ this.firstPageUrl = firstPageUrl;
24
+ this.lastPageUrl = lastPageUrl;
25
+ //
26
+ }
27
+ /**
28
+ * Normalize the collection to a paginated list of ids for state-managed applications.
29
+ *
30
+ * This method returns a single key object, where the key is the page number and the associated value is
31
+ * an array of ids. Each id is fetched by the collection items, looking up for the "id" key. If an id is supplied
32
+ * to this method, it will be used instead of the default "id" key.
33
+ *
34
+ * Please note that in case the key doesn't exist in the collection's item, a KeyNotFoundError is thrown
35
+ *
36
+ * @param k A key to use instead of the default "id": this will be searched inside each element of the collection
37
+ * @returns []
38
+ * @throws KeyNotFoundItem
39
+ */
40
+ normalize(id) {
41
+ return {
42
+ [this.page]: this.data.reduce((ids, value) => {
43
+ if (id && id in value) {
44
+ ids.push(value[id]);
45
+ }
46
+ else if (value.hasOwnProperty('id')) {
47
+ ids.push(value['id']);
48
+ }
49
+ else {
50
+ throw new KeyNotFoundError(id || 'id');
51
+ }
52
+ return ids;
53
+ }, [])
54
+ };
55
+ }
56
+ }
57
+
58
+ var SortEnum;
59
+ (function (SortEnum) {
60
+ SortEnum["ASC"] = "asc";
61
+ SortEnum["DESC"] = "desc";
62
+ })(SortEnum || (SortEnum = {}));
63
+
64
+ class UnselectableModelError extends Error {
65
+ constructor(model) {
66
+ super(`Unselectable Model: the selected model (${model}) is not present neither in the "model" property, nor in the includes object.`);
67
+ }
68
+ }
69
+
70
+ class QueryBuilderOptions {
71
+ constructor(options) {
72
+ this.appends = options.appends || 'append';
73
+ this.fields = options.fields || 'fields';
74
+ this.filters = options.filters || 'filter';
75
+ this.includes = options.includes || 'include';
76
+ this.limit = options.limit || 'limit';
77
+ this.page = options.page || 'page';
78
+ this.sort = options.sort || 'sort';
79
+ }
80
+ }
81
+
82
+ const INITIAL_STATE = {
83
+ baseUrl: '',
84
+ fields: {},
85
+ filters: {},
86
+ includes: [],
87
+ limit: 15,
88
+ model: '',
89
+ page: 1,
90
+ sorts: []
91
+ };
92
+ class NestService {
93
+ constructor() {
94
+ /**
95
+ * Private writable signal that holds the Query Builder state
96
+ *
97
+ * @type {IQueryBuilderState}
98
+ */
99
+ this._nest = signal(this._clone(INITIAL_STATE));
100
+ /**
101
+ * A computed signal that makes readonly the writable signal _nest
102
+ *
103
+ * @type {Signal<IQueryBuilderState>}
104
+ */
105
+ this.nest = computed(() => this._clone(this._nest()));
106
+ // Nothing to see here 👮🏻‍♀️
107
+ }
108
+ set baseUrl(baseUrl) {
109
+ this._nest.update(nest => ({
110
+ ...nest,
111
+ baseUrl
112
+ }));
113
+ }
114
+ set limit(limit) {
115
+ this._nest.update(nest => ({
116
+ ...nest,
117
+ limit
118
+ }));
119
+ }
120
+ set model(model) {
121
+ this._nest.update(nest => ({
122
+ ...nest,
123
+ model
124
+ }));
125
+ }
126
+ set page(page) {
127
+ this._nest.update(nest => ({
128
+ ...nest,
129
+ page
130
+ }));
131
+ }
132
+ _clone(obj) {
133
+ return JSON.parse(JSON.stringify(obj));
134
+ }
135
+ /**
136
+ * Add selectable fields for the given model to the request
137
+ *
138
+ * @param {IFields} fields
139
+ * @return {void}
140
+ * @todo Avoid duplicated fields
141
+ */
142
+ addFields(fields) {
143
+ this._nest.update(nest => ({
144
+ ...nest,
145
+ fields: { ...nest.fields, ...fields }
146
+ }));
147
+ }
148
+ /**
149
+ * Add filters to the request
150
+ *
151
+ * @param {IFilters} filters
152
+ * @todo Avoid duplicated filters
153
+ */
154
+ addFilters(filters) {
155
+ this._nest.update(nest => ({
156
+ ...nest,
157
+ filters: { ...nest.filters, ...filters }
158
+ }));
159
+ }
160
+ /**
161
+ * Add resources to include with the request
162
+ *
163
+ * @param {string[]} includes models to include to the request
164
+ * @return {void}
165
+ * @todo Avoid duplicated includes
166
+ */
167
+ addIncludes(includes) {
168
+ this._nest.update(nest => ({
169
+ ...nest,
170
+ includes: [...nest.includes, ...includes]
171
+ }));
172
+ }
173
+ /**
174
+ * Add a field that should be used for sorting data
175
+ *
176
+ * @param {ISort} sort
177
+ * @return {void}
178
+ */
179
+ addSort(sort) {
180
+ this._nest.update(nest => ({
181
+ ...nest,
182
+ sorts: [...nest.sorts, sort]
183
+ }));
184
+ }
185
+ /**
186
+ * Remove fields for the given model
187
+ *
188
+ * @param {IFields} fields
189
+ */
190
+ deleteFields(fields) {
191
+ const f = Object.assign({}, this.nest().fields);
192
+ Object.keys(fields).forEach(k => {
193
+ if (!(k in f)) {
194
+ return;
195
+ }
196
+ f[k] = this._nest().fields[k].filter(v => !fields[k].includes(v));
197
+ });
198
+ this._nest.update(nest => ({
199
+ ...nest,
200
+ fields: f
201
+ }));
202
+ }
203
+ /**
204
+ *
205
+ * @param filters
206
+ * @todo Create a clone of the filter obj before assigning to f
207
+ */
208
+ deleteFilters(...filters) {
209
+ const f = Object.assign({}, this._nest().filters);
210
+ filters.forEach(k => delete f[k]);
211
+ this._nest.update(nest => ({
212
+ ...nest,
213
+ filters: f
214
+ }));
215
+ }
216
+ /**
217
+ *
218
+ * @param includes
219
+ */
220
+ deleteIncludes(...includes) {
221
+ this._nest.update(nest => ({
222
+ ...nest,
223
+ includes: nest.includes.filter(v => !includes.includes(v))
224
+ }));
225
+ }
226
+ /**
227
+ *
228
+ * @param sorts
229
+ */
230
+ deleteSorts(...sorts) {
231
+ const s = [...this._nest().sorts];
232
+ sorts.forEach(field => {
233
+ const p = this.nest().sorts.findIndex(sort => sort.field === field);
234
+ if (p > -1) {
235
+ s.splice(p, 1);
236
+ }
237
+ });
238
+ this._nest.update(nest => ({
239
+ ...nest,
240
+ sorts: s
241
+ }));
242
+ }
243
+ reset() {
244
+ this._nest.update(_ => this._clone(INITIAL_STATE));
245
+ }
246
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NestService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
247
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NestService }); }
248
+ }
249
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NestService, decorators: [{
250
+ type: Injectable
251
+ }], ctorParameters: () => [] });
252
+
253
+ class NgQubeeService {
254
+ constructor(_nestService, options = {}) {
255
+ this._nestService = _nestService;
256
+ /**
257
+ * This property serves as an accumulator for holding the composed string with each query param
258
+ */
259
+ this._uri = '';
260
+ this._uri$ = new BehaviorSubject('');
261
+ this.uri$ = this._uri$.asObservable().pipe(filter(uri => !!uri));
262
+ this._options = new QueryBuilderOptions(options);
263
+ }
264
+ _parseFields(s) {
265
+ if (!Object.keys(s.fields).length) {
266
+ return this._uri;
267
+ }
268
+ if (!s.model) {
269
+ throw new Error('While selecting fields, the -> model <- is required');
270
+ }
271
+ if (!(s.model in s.fields)) {
272
+ throw new Error(`Key ${s.model} is missing in the fields object`);
273
+ }
274
+ const f = {};
275
+ for (const k in s.fields) {
276
+ if (s.fields.hasOwnProperty(k)) {
277
+ // Check if the key is the model or is declared in "includes".
278
+ // If not, it means that has not been selected anywhere and that will cause an error on the API
279
+ if (k !== s.model && !s.includes.includes(k)) {
280
+ throw new UnselectableModelError(k);
281
+ }
282
+ Object.assign(f, { [`${this._options.fields}[${k}]`]: s.fields[k].join(',') });
283
+ }
284
+ }
285
+ const param = `${this._prepend(s.model)}${qs.stringify(f, { encode: false })}`;
286
+ this._uri += param;
287
+ return param;
288
+ }
289
+ _parseFilters(s) {
290
+ const keys = Object.keys(s.filters);
291
+ if (!keys.length) {
292
+ return this._uri;
293
+ }
294
+ const f = {
295
+ [`${this._options.filters}`]: keys.reduce((acc, key) => {
296
+ return Object.assign(acc, { [key]: s.filters[key].join(',') });
297
+ }, {})
298
+ };
299
+ const param = `${this._prepend(s.model)}${qs.stringify(f, { encode: false })}`;
300
+ this._uri += param;
301
+ return param;
302
+ }
303
+ _parseIncludes(s) {
304
+ if (!s.includes.length) {
305
+ return this._uri;
306
+ }
307
+ const param = `${this._prepend(s.model)}${this._options.includes}=${s.includes}`;
308
+ this._uri += param;
309
+ return param;
310
+ }
311
+ _parseLimit(s) {
312
+ const param = `${this._prepend(s.model)}${this._options.limit}=${s.limit}`;
313
+ this._uri += param;
314
+ return param;
315
+ }
316
+ _parsePage(s) {
317
+ const param = `${this._prepend(s.model)}${this._options.page}=${s.page}`;
318
+ this._uri += param;
319
+ return param;
320
+ }
321
+ _parseSort(s) {
322
+ let param = '';
323
+ if (!s.sorts.length) {
324
+ return param;
325
+ }
326
+ param = `${this._prepend(s.model)}${this._options.sort}=`;
327
+ s.sorts.forEach((sort, idx) => {
328
+ param += `${sort.order === SortEnum.DESC ? '-' : ''}${sort.field}`;
329
+ if (idx < s.sorts.length - 1) {
330
+ param += ',';
331
+ }
332
+ });
333
+ this._uri += param;
334
+ return param;
335
+ }
336
+ _parse(s) {
337
+ if (!s.model) {
338
+ throw new Error('Set the model property BEFORE adding filters or calling the url() / get() methods');
339
+ }
340
+ // Cleanup the previously generated URI
341
+ this._uri = '';
342
+ this._parseIncludes(s);
343
+ this._parseFields(s);
344
+ this._parseFilters(s);
345
+ this._parseLimit(s);
346
+ this._parsePage(s);
347
+ this._parseSort(s);
348
+ return this._uri;
349
+ }
350
+ _prepend(model) {
351
+ return this._uri ? '&' : `/${model}?`;
352
+ }
353
+ // private _removeArgIfEmpty(arg: string): string {
354
+ // const params = new URL(this._uri).searchParams;
355
+ // if (!params.get(arg)) {
356
+ // params.delete(arg);
357
+ // }
358
+ // }
359
+ /**
360
+ * Add fields to the select statement for the given model
361
+ *
362
+ * @param model Model that holds the fields
363
+ * @param fields Fields to select
364
+ * @returns {this}
365
+ */
366
+ addFields(model, fields) {
367
+ if (!fields.length) {
368
+ return this;
369
+ }
370
+ this._nestService.addFields({ [model]: fields });
371
+ return this;
372
+ }
373
+ /**
374
+ * Add a filter with the given value(s)
375
+ * I.e. filter[field]=1 or filter[field]=1,2,3
376
+ *
377
+ * @param {string} field Name of the field to filter
378
+ * @param {string[]} value The needle(s)
379
+ * @returns {this}
380
+ */
381
+ addFilter(field, ...values) {
382
+ if (!values.length) {
383
+ return this;
384
+ }
385
+ this._nestService.addFilters({
386
+ [field]: values
387
+ });
388
+ return this;
389
+ }
390
+ /**
391
+ * Add related entities to include in the request
392
+ *
393
+ * @param {string[]} models
394
+ * @returns
395
+ */
396
+ addIncludes(...models) {
397
+ if (!models.length) {
398
+ return this;
399
+ }
400
+ this._nestService.addIncludes(models);
401
+ return this;
402
+ }
403
+ /**
404
+ * Add a field with a sort criteria
405
+ *
406
+ * @param field Field to use for sorting
407
+ * @param {SortEnum} order A value from the SortEnum enumeration
408
+ * @returns {this}
409
+ */
410
+ addSort(field, order) {
411
+ this._nestService.addSort({
412
+ field,
413
+ order
414
+ });
415
+ return this;
416
+ }
417
+ /**
418
+ * Delete selected fields for the given models in the current query builder state
419
+ *
420
+ * ```
421
+ * ngQubeeService.deleteFields({
422
+ * users: ['email', 'password'],
423
+ * address: ['zipcode']
424
+ * });
425
+ * ```
426
+ *
427
+ * @param {IFields} fields
428
+ * @returns
429
+ */
430
+ deleteFields(fields) {
431
+ this._nestService.deleteFields(fields);
432
+ return this;
433
+ }
434
+ /**
435
+ * Delete selected fields for the given model in the current query builder state
436
+ *
437
+ * ```
438
+ * ngQubeeService.deleteFieldsByModel('users', 'email', 'password']);
439
+ * ```
440
+ *
441
+ * @param model Model that holds the fields
442
+ * @param {string[]} fields Fields to delete from the state
443
+ * @returns {this}
444
+ */
445
+ deleteFieldsByModel(model, ...fields) {
446
+ if (!fields.length) {
447
+ return this;
448
+ }
449
+ this._nestService.deleteFields({
450
+ [model]: fields
451
+ });
452
+ return this;
453
+ }
454
+ /**
455
+ * Remove given filters from the query builder state
456
+ *
457
+ * @param {string[]} filters Filters to remove
458
+ * @returns {this}
459
+ */
460
+ deleteFilters(...filters) {
461
+ if (!filters.length) {
462
+ return this;
463
+ }
464
+ this._nestService.deleteFilters(...filters);
465
+ return this;
466
+ }
467
+ /**
468
+ * Remove selected related models from the query builder state
469
+ *
470
+ * @param {string[]} includes Models to remove
471
+ * @returns
472
+ */
473
+ deleteIncludes(...includes) {
474
+ if (!includes.length) {
475
+ return this;
476
+ }
477
+ this._nestService.deleteIncludes(...includes);
478
+ return this;
479
+ }
480
+ /**
481
+ * Remove sorts rules from the query builder state
482
+ *
483
+ * @param sorts Fields used for sorting to remove
484
+ * @returns {this}
485
+ */
486
+ deleteSorts(...sorts) {
487
+ this._nestService.deleteSorts(...sorts);
488
+ return this;
489
+ }
490
+ /**
491
+ * Generate an URI accordingly to the given data
492
+ *
493
+ * @returns {Observable<string>} An observable that emits the generated uri
494
+ */
495
+ generateUri() {
496
+ this._uri$.next(this._parse(this._nestService.nest()));
497
+ return this.uri$;
498
+ }
499
+ /**
500
+ * Clear the current state and reset the Query Builder to a fresh, clean condition
501
+ *
502
+ * @returns {this}
503
+ */
504
+ reset() {
505
+ this._nestService.reset();
506
+ return this;
507
+ }
508
+ /**
509
+ * Set the base url to use for composing the address
510
+ *
511
+ * @param {string} baseUrl
512
+ * @returns {this}
513
+ */
514
+ setBaseUrl(baseUrl) {
515
+ this._nestService.baseUrl = baseUrl;
516
+ return this;
517
+ }
518
+ /**
519
+ * Set the items per page number
520
+ *
521
+ * @param limit
522
+ * @returns {this}
523
+ */
524
+ setLimit(limit) {
525
+ this._nestService.limit = limit;
526
+ return this;
527
+ }
528
+ /**
529
+ * Set the model to use for running the query against
530
+ * - I.e. the model "users" will return /users
531
+ *
532
+ * @param {string} model Model name
533
+ * @returns {this}
534
+ */
535
+ setModel(model) {
536
+ this._nestService.model = model;
537
+ return this;
538
+ }
539
+ /**
540
+ * Set the page that the backend will use to paginate the result set
541
+ *
542
+ * @param page Page param
543
+ * @returns {this}
544
+ */
545
+ setPage(page) {
546
+ this._nestService.page = page;
547
+ return this;
548
+ }
549
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeService, deps: [{ token: NestService }, { token: 'QUERY_PARAMS_CONFIG', optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
550
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeService }); }
551
+ }
552
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeService, decorators: [{
553
+ type: Injectable
554
+ }], ctorParameters: () => [{ type: NestService }, { type: undefined, decorators: [{
555
+ type: Inject,
556
+ args: ['QUERY_PARAMS_CONFIG']
557
+ }, {
558
+ type: Optional
559
+ }] }] });
560
+
561
+ class ResponseOptions {
562
+ constructor(options) {
563
+ this.currentPage = options.currentPage || 'current_page';
564
+ this.data = options.data || 'data';
565
+ this.firstPageUrl = options.firstPageUrl || 'first_page_url';
566
+ this.from = options.from || 'from';
567
+ this.lastPage = options.lastPage || 'last_page';
568
+ this.lastPageUrl = options.lastPageUrl || 'last_page_url';
569
+ this.nextPageUrl = options.nextPageUrl || 'next_page_url';
570
+ this.path = options.path || 'path';
571
+ this.perPage = options.perPage || 'per_page';
572
+ this.prevPageUrl = options.prevPageUrl || 'prev_page_url';
573
+ this.to = options.to || 'to';
574
+ this.total = options.total || 'total';
575
+ }
576
+ }
577
+
578
+ class PaginationService {
579
+ constructor(options = {}) {
580
+ this._options = new ResponseOptions(options);
581
+ }
582
+ paginate(response) {
583
+ return new PaginatedCollection(response[this._options.data], response[this._options.currentPage], response[this._options.from], response[this._options.to], response[this._options.total], response[this._options.perPage], response[this._options.prevPageUrl], response[this._options.nextPageUrl], response[this._options.lastPage], response[this._options.firstPageUrl], response[this._options.lastPageUrl]);
584
+ }
585
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: PaginationService, deps: [{ token: 'RESPONSE_OPTIONS', optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
586
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: PaginationService }); }
587
+ }
588
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: PaginationService, decorators: [{
589
+ type: Injectable
590
+ }], ctorParameters: () => [{ type: undefined, decorators: [{
591
+ type: Inject,
592
+ args: ['RESPONSE_OPTIONS']
593
+ }, {
594
+ type: Optional
595
+ }] }] });
596
+
597
+ // @dynamic
598
+ class NgQubeeModule {
599
+ static forRoot(config = {}) {
600
+ return {
601
+ ngModule: NgQubeeModule,
602
+ providers: [
603
+ NestService,
604
+ {
605
+ deps: [NestService],
606
+ provide: NgQubeeService,
607
+ useFactory: (nestService) => new NgQubeeService(nestService, Object.assign({}, config.request))
608
+ }, {
609
+ provide: PaginationService,
610
+ useFactory: () => new PaginationService(Object.assign({}, config.response))
611
+ }
612
+ ]
613
+ };
614
+ }
615
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
616
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeModule }); }
617
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeModule, providers: [{
618
+ deps: [NestService],
619
+ provide: NgQubeeService,
620
+ useFactory: (nestService) => new NgQubeeService(nestService, {})
621
+ }] }); }
622
+ }
623
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.3", ngImport: i0, type: NgQubeeModule, decorators: [{
624
+ type: NgModule,
625
+ args: [{
626
+ providers: [{
627
+ deps: [NestService],
628
+ provide: NgQubeeService,
629
+ useFactory: (nestService) => new NgQubeeService(nestService, {})
630
+ }]
631
+ }]
632
+ }] });
633
+
634
+ /**
635
+ * Sets up providers necessary to enable `NgQubee` functionality for the application.
636
+ *
637
+ * @usageNotes
638
+ *
639
+ * Basic example of how you can add NgQubee to your application:
640
+ * ```
641
+ * const config = {};
642
+ *
643
+ * bootstrapApplication(AppComponent, {
644
+ * providers: [provideNgQubee(config)]
645
+ * });
646
+ * ```
647
+ *
648
+ * @publicApi
649
+ * @param config Configuration object compliant to the IConfig interface
650
+ * @returns A set of providers to setup NgQubee
651
+ */
652
+ function provideNgQubee(config = {}) {
653
+ return makeEnvironmentProviders([
654
+ {
655
+ provide: NestService,
656
+ useClass: NestService
657
+ },
658
+ {
659
+ deps: [NestService],
660
+ provide: NgQubeeService,
661
+ useFactory: (nestService) => new NgQubeeService(nestService, Object.assign({}, config.request))
662
+ }, {
663
+ provide: PaginationService,
664
+ useFactory: () => new PaginationService(Object.assign({}, config.response))
665
+ }
666
+ ]);
667
+ }
668
+
669
+ /*
670
+ * Public API Surface of angular-query-builder
671
+ */
672
+
673
+ /**
674
+ * Generated bundle index. Do not edit.
675
+ */
676
+
677
+ export { NgQubeeModule, NgQubeeService, PaginatedCollection, PaginationService, provideNgQubee };
678
+ //# sourceMappingURL=ng-qubee.mjs.map