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
@@ -1,909 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('qs'), require('@reduxjs/toolkit'), require('rxjs'), require('rxjs/operators'), require('redux')) :
3
- typeof define === 'function' && define.amd ? define('ng-qubee', ['exports', '@angular/core', 'qs', '@reduxjs/toolkit', 'rxjs', 'rxjs/operators', 'redux'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ng-qubee'] = {}, global.ng.core, global.qs, global.toolkit, global.rxjs, global.rxjs.operators, global.redux));
5
- }(this, (function (exports, i0, qs, toolkit, rxjs, operators, redux) { 'use strict';
6
-
7
- var QueryBuilderOptions = /** @class */ (function () {
8
- function QueryBuilderOptions(options) {
9
- this.appends = options.appends || 'append';
10
- this.fields = options.fields || 'fields';
11
- this.filters = options.filters || 'filter';
12
- this.includes = options.includes || 'include';
13
- this.limit = options.limit || 'limit';
14
- this.page = options.page || 'page';
15
- this.sort = options.sort || 'sort';
16
- }
17
- return QueryBuilderOptions;
18
- }());
19
-
20
- /*! *****************************************************************************
21
- Copyright (c) Microsoft Corporation.
22
-
23
- Permission to use, copy, modify, and/or distribute this software for any
24
- purpose with or without fee is hereby granted.
25
-
26
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
27
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
28
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
29
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
30
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
31
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
32
- PERFORMANCE OF THIS SOFTWARE.
33
- ***************************************************************************** */
34
- /* global Reflect, Promise */
35
- var extendStatics = function (d, b) {
36
- extendStatics = Object.setPrototypeOf ||
37
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
38
- function (d, b) { for (var p in b)
39
- if (Object.prototype.hasOwnProperty.call(b, p))
40
- d[p] = b[p]; };
41
- return extendStatics(d, b);
42
- };
43
- function __extends(d, b) {
44
- if (typeof b !== "function" && b !== null)
45
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
46
- extendStatics(d, b);
47
- function __() { this.constructor = d; }
48
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
49
- }
50
- var __assign = function () {
51
- __assign = Object.assign || function __assign(t) {
52
- for (var s, i = 1, n = arguments.length; i < n; i++) {
53
- s = arguments[i];
54
- for (var p in s)
55
- if (Object.prototype.hasOwnProperty.call(s, p))
56
- t[p] = s[p];
57
- }
58
- return t;
59
- };
60
- return __assign.apply(this, arguments);
61
- };
62
- function __rest(s, e) {
63
- var t = {};
64
- for (var p in s)
65
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
66
- t[p] = s[p];
67
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
68
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
69
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
70
- t[p[i]] = s[p[i]];
71
- }
72
- return t;
73
- }
74
- function __decorate(decorators, target, key, desc) {
75
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
76
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
77
- r = Reflect.decorate(decorators, target, key, desc);
78
- else
79
- for (var i = decorators.length - 1; i >= 0; i--)
80
- if (d = decorators[i])
81
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
82
- return c > 3 && r && Object.defineProperty(target, key, r), r;
83
- }
84
- function __param(paramIndex, decorator) {
85
- return function (target, key) { decorator(target, key, paramIndex); };
86
- }
87
- function __metadata(metadataKey, metadataValue) {
88
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
89
- return Reflect.metadata(metadataKey, metadataValue);
90
- }
91
- function __awaiter(thisArg, _arguments, P, generator) {
92
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
93
- return new (P || (P = Promise))(function (resolve, reject) {
94
- function fulfilled(value) { try {
95
- step(generator.next(value));
96
- }
97
- catch (e) {
98
- reject(e);
99
- } }
100
- function rejected(value) { try {
101
- step(generator["throw"](value));
102
- }
103
- catch (e) {
104
- reject(e);
105
- } }
106
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
107
- step((generator = generator.apply(thisArg, _arguments || [])).next());
108
- });
109
- }
110
- function __generator(thisArg, body) {
111
- var _ = { label: 0, sent: function () { if (t[0] & 1)
112
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
113
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
114
- function verb(n) { return function (v) { return step([n, v]); }; }
115
- function step(op) {
116
- if (f)
117
- throw new TypeError("Generator is already executing.");
118
- while (_)
119
- try {
120
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
121
- return t;
122
- if (y = 0, t)
123
- op = [op[0] & 2, t.value];
124
- switch (op[0]) {
125
- case 0:
126
- case 1:
127
- t = op;
128
- break;
129
- case 4:
130
- _.label++;
131
- return { value: op[1], done: false };
132
- case 5:
133
- _.label++;
134
- y = op[1];
135
- op = [0];
136
- continue;
137
- case 7:
138
- op = _.ops.pop();
139
- _.trys.pop();
140
- continue;
141
- default:
142
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
143
- _ = 0;
144
- continue;
145
- }
146
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
147
- _.label = op[1];
148
- break;
149
- }
150
- if (op[0] === 6 && _.label < t[1]) {
151
- _.label = t[1];
152
- t = op;
153
- break;
154
- }
155
- if (t && _.label < t[2]) {
156
- _.label = t[2];
157
- _.ops.push(op);
158
- break;
159
- }
160
- if (t[2])
161
- _.ops.pop();
162
- _.trys.pop();
163
- continue;
164
- }
165
- op = body.call(thisArg, _);
166
- }
167
- catch (e) {
168
- op = [6, e];
169
- y = 0;
170
- }
171
- finally {
172
- f = t = 0;
173
- }
174
- if (op[0] & 5)
175
- throw op[1];
176
- return { value: op[0] ? op[1] : void 0, done: true };
177
- }
178
- }
179
- var __createBinding = Object.create ? (function (o, m, k, k2) {
180
- if (k2 === undefined)
181
- k2 = k;
182
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
183
- }) : (function (o, m, k, k2) {
184
- if (k2 === undefined)
185
- k2 = k;
186
- o[k2] = m[k];
187
- });
188
- function __exportStar(m, o) {
189
- for (var p in m)
190
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
191
- __createBinding(o, m, p);
192
- }
193
- function __values(o) {
194
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
195
- if (m)
196
- return m.call(o);
197
- if (o && typeof o.length === "number")
198
- return {
199
- next: function () {
200
- if (o && i >= o.length)
201
- o = void 0;
202
- return { value: o && o[i++], done: !o };
203
- }
204
- };
205
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
206
- }
207
- function __read(o, n) {
208
- var m = typeof Symbol === "function" && o[Symbol.iterator];
209
- if (!m)
210
- return o;
211
- var i = m.call(o), r, ar = [], e;
212
- try {
213
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
214
- ar.push(r.value);
215
- }
216
- catch (error) {
217
- e = { error: error };
218
- }
219
- finally {
220
- try {
221
- if (r && !r.done && (m = i["return"]))
222
- m.call(i);
223
- }
224
- finally {
225
- if (e)
226
- throw e.error;
227
- }
228
- }
229
- return ar;
230
- }
231
- /** @deprecated */
232
- function __spread() {
233
- for (var ar = [], i = 0; i < arguments.length; i++)
234
- ar = ar.concat(__read(arguments[i]));
235
- return ar;
236
- }
237
- /** @deprecated */
238
- function __spreadArrays() {
239
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
240
- s += arguments[i].length;
241
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
242
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
243
- r[k] = a[j];
244
- return r;
245
- }
246
- function __spreadArray(to, from) {
247
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
248
- to[j] = from[i];
249
- return to;
250
- }
251
- function __await(v) {
252
- return this instanceof __await ? (this.v = v, this) : new __await(v);
253
- }
254
- function __asyncGenerator(thisArg, _arguments, generator) {
255
- if (!Symbol.asyncIterator)
256
- throw new TypeError("Symbol.asyncIterator is not defined.");
257
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
258
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
259
- function verb(n) { if (g[n])
260
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
261
- function resume(n, v) { try {
262
- step(g[n](v));
263
- }
264
- catch (e) {
265
- settle(q[0][3], e);
266
- } }
267
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
268
- function fulfill(value) { resume("next", value); }
269
- function reject(value) { resume("throw", value); }
270
- function settle(f, v) { if (f(v), q.shift(), q.length)
271
- resume(q[0][0], q[0][1]); }
272
- }
273
- function __asyncDelegator(o) {
274
- var i, p;
275
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
276
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
277
- }
278
- function __asyncValues(o) {
279
- if (!Symbol.asyncIterator)
280
- throw new TypeError("Symbol.asyncIterator is not defined.");
281
- var m = o[Symbol.asyncIterator], i;
282
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
283
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
284
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
285
- }
286
- function __makeTemplateObject(cooked, raw) {
287
- if (Object.defineProperty) {
288
- Object.defineProperty(cooked, "raw", { value: raw });
289
- }
290
- else {
291
- cooked.raw = raw;
292
- }
293
- return cooked;
294
- }
295
- ;
296
- var __setModuleDefault = Object.create ? (function (o, v) {
297
- Object.defineProperty(o, "default", { enumerable: true, value: v });
298
- }) : function (o, v) {
299
- o["default"] = v;
300
- };
301
- function __importStar(mod) {
302
- if (mod && mod.__esModule)
303
- return mod;
304
- var result = {};
305
- if (mod != null)
306
- for (var k in mod)
307
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
308
- __createBinding(result, mod, k);
309
- __setModuleDefault(result, mod);
310
- return result;
311
- }
312
- function __importDefault(mod) {
313
- return (mod && mod.__esModule) ? mod : { default: mod };
314
- }
315
- function __classPrivateFieldGet(receiver, privateMap) {
316
- if (!privateMap.has(receiver)) {
317
- throw new TypeError("attempted to get private field on non-instance");
318
- }
319
- return privateMap.get(receiver);
320
- }
321
- function __classPrivateFieldSet(receiver, privateMap, value) {
322
- if (!privateMap.has(receiver)) {
323
- throw new TypeError("attempted to set private field on non-instance");
324
- }
325
- privateMap.set(receiver, value);
326
- return value;
327
- }
328
-
329
- var UnselectableModelError = /** @class */ (function (_super) {
330
- __extends(UnselectableModelError, _super);
331
- function UnselectableModelError(model) {
332
- return _super.call(this, "Unselectable Model: the selected model (" + model + ") is not present neither in the \"model\" property, nor in the includes object.") || this;
333
- }
334
- return UnselectableModelError;
335
- }(Error));
336
-
337
- var SortEnum;
338
- (function (SortEnum) {
339
- SortEnum["ASC"] = "asc";
340
- SortEnum["DESC"] = "desc";
341
- })(SortEnum || (SortEnum = {}));
342
-
343
- // Interfaces
344
- var addFields = toolkit.createAction('[Query Buillder] Add Fields');
345
- var addFilters = toolkit.createAction('[Query Buillder] Add Filters');
346
- var addIncludes = toolkit.createAction('[Query Buillder] Add Includes');
347
- var addSorts = toolkit.createAction('[Query Buillder] Add Sorts');
348
- var deleteFields = toolkit.createAction('[Query Buillder] Delete Fields');
349
- var deleteFilters = toolkit.createAction('[Query Buillder] Delete Filters');
350
- var deleteIncludes = toolkit.createAction('[Query Buillder] Delete Includes');
351
- var deleteSorts = toolkit.createAction('[Query Buillder] Delete Sorts');
352
- var reset = toolkit.createAction('[Query Builder] Reset');
353
- var setBaseUrl = toolkit.createAction('[Query Buillder] Set Base URL');
354
- var setLimit = toolkit.createAction('[Query Buillder] Set Limit');
355
- var setModel = toolkit.createAction('[Query Builder] Set Model');
356
- var setPage = toolkit.createAction('[Query Builder] Set Page');
357
- var updateUri = toolkit.createAction('[Query Builder] Update URI');
358
-
359
- var initialState = {
360
- baseUrl: '',
361
- fields: {},
362
- filters: {},
363
- includes: [],
364
- limit: 15,
365
- model: '',
366
- page: 1,
367
- sort: {},
368
- uri: ''
369
- };
370
- var ɵ0 = function (builder) {
371
- builder.addCase(addFields, function (state, _a) {
372
- var fields = _a.payload.fields;
373
- return (Object.assign(Object.assign({}, state), { fields: Object.assign(Object.assign({}, state.fields), fields) }));
374
- }),
375
- builder.addCase(addFilters, function (state, _a) {
376
- var filters = _a.payload.filters;
377
- return (Object.assign(Object.assign({}, state), { filters: Object.assign(Object.assign({}, state.filters), filters) }));
378
- }),
379
- builder.addCase(addIncludes, function (state, _a) {
380
- var includes = _a.payload.includes;
381
- return (Object.assign(Object.assign({}, state), { includes: __spread(state.includes, includes) }));
382
- }),
383
- builder.addCase(addSorts, function (state, _a) {
384
- var sorts = _a.payload.sorts;
385
- return (Object.assign(Object.assign({}, state), { sort: Object.assign(Object.assign({}, state.sort), sorts) }));
386
- }),
387
- builder.addCase(deleteFields, function (state, _a) {
388
- var fields = _a.payload.fields;
389
- var f = Object.assign({}, state.fields);
390
- Object.keys(fields).forEach(function (k) {
391
- if (!(k in state.fields)) {
392
- return;
393
- }
394
- f[k] = state.fields[k].filter(function (v) { return !fields[k].includes(v); });
395
- });
396
- return Object.assign(Object.assign({}, state), { fields: f });
397
- }),
398
- builder.addCase(deleteFilters, function (state, _a) {
399
- var filters = _a.payload.filters;
400
- var f = Object.assign({}, state.filters);
401
- filters.forEach(function (k) { return delete f[k]; });
402
- return Object.assign(Object.assign({}, state), { filters: f });
403
- }),
404
- builder.addCase(deleteIncludes, function (state, _a) {
405
- var includes = _a.payload.includes;
406
- return Object.assign(Object.assign({}, state), { includes: state.includes.filter(function (v) { return !includes.includes(v); }) });
407
- }),
408
- builder.addCase(deleteSorts, function (state, _a) {
409
- var sorts = _a.payload.sorts;
410
- var s = Object.assign({}, state.sort);
411
- sorts.forEach(function (v) { return delete s[v]; });
412
- return Object.assign(Object.assign({}, state), { sort: s });
413
- }),
414
- builder.addCase(reset, function (state) { return initialState; }),
415
- builder.addCase(setBaseUrl, function (state, _a) {
416
- var baseUrl = _a.payload.baseUrl;
417
- return (Object.assign(Object.assign({}, state), { baseUrl: baseUrl }));
418
- }),
419
- builder.addCase(setLimit, function (state, _a) {
420
- var limit = _a.payload.limit;
421
- return (Object.assign(Object.assign({}, state), { limit: limit }));
422
- }),
423
- builder.addCase(setModel, function (state, _a) {
424
- var model = _a.payload.model;
425
- return (Object.assign(Object.assign({}, state), { model: model }));
426
- }),
427
- builder.addCase(setPage, function (state, _a) {
428
- var page = _a.payload.page;
429
- return (Object.assign(Object.assign({}, state), { page: page }));
430
- }),
431
- builder.addCase(updateUri, function (state, _a) {
432
- var uri = _a.payload.uri;
433
- return (Object.assign(Object.assign({}, state), { uri: uri }));
434
- });
435
- };
436
- var queryBuilderReducer = toolkit.createReducer(initialState, ɵ0);
437
-
438
- var StoreService = /** @class */ (function () {
439
- function StoreService() {
440
- this._store = redux.createStore(redux.combineReducers({ nest: queryBuilderReducer }));
441
- }
442
- Object.defineProperty(StoreService.prototype, "state", {
443
- get: function () {
444
- return this._store.getState();
445
- },
446
- enumerable: false,
447
- configurable: true
448
- });
449
- StoreService.prototype.dispatch = function (action) {
450
- this._store.dispatch(action);
451
- };
452
- StoreService.prototype.subscribe = function (listener) {
453
- this._store.subscribe(listener);
454
- };
455
- return StoreService;
456
- }());
457
- StoreService.ɵprov = i0.ɵɵdefineInjectable({ factory: function StoreService_Factory() { return new StoreService(); }, token: StoreService, providedIn: "root" });
458
- StoreService.decorators = [
459
- { type: i0.Injectable, args: [{
460
- providedIn: 'root'
461
- },] }
462
- ];
463
- StoreService.ctorParameters = function () { return []; };
464
-
465
- var NgQubeeService = /** @class */ (function () {
466
- function NgQubeeService(_store, options) {
467
- var _this = this;
468
- if (options === void 0) { options = {}; }
469
- this._store = _store;
470
- /**
471
- * This property serves as an accumulator for holding the composed string with each query param
472
- */
473
- this._uri = '';
474
- this._uri$ = new rxjs.BehaviorSubject('');
475
- this.uri$ = this._uri$.asObservable().pipe(operators.filter(function (uri) { return !!uri; }));
476
- this._options = new QueryBuilderOptions(options);
477
- this._store.subscribe(function () {
478
- _this._uri$.next(_this._store.state.nest.uri);
479
- });
480
- }
481
- NgQubeeService.prototype._parseFields = function (s) {
482
- var _a;
483
- if (!Object.keys(s.fields).length) {
484
- return this._uri;
485
- }
486
- if (!s.model) {
487
- throw new Error('While selecting fields, the -> model <- is required');
488
- }
489
- if (!(s.model in s.fields)) {
490
- throw new Error("Key " + s.model + " is missing in the fields object");
491
- }
492
- var f = {};
493
- for (var k in s.fields) {
494
- if (s.fields.hasOwnProperty(k)) {
495
- // Check if the key is the model or is declared in "includes".
496
- // If not, it means that has not been selected anywhere and that will cause an error on the API
497
- if (k !== s.model && !s.includes.includes(k)) {
498
- throw new UnselectableModelError(k);
499
- }
500
- Object.assign(f, (_a = {}, _a[this._options.fields + "[" + k + "]"] = s.fields[k].join(','), _a));
501
- }
502
- }
503
- var param = "" + this._prepend(s.model) + qs.stringify(f, { encode: false });
504
- this._uri += param;
505
- return param;
506
- };
507
- NgQubeeService.prototype._parseFilters = function (s) {
508
- var _a;
509
- var keys = Object.keys(s.filters);
510
- if (!keys.length) {
511
- return this._uri;
512
- }
513
- var f = (_a = {},
514
- _a[this._options.filters] = keys.reduce(function (acc, key) {
515
- var _a;
516
- return Object.assign(acc, (_a = {}, _a[key] = s.filters[key].join(','), _a));
517
- }, {}),
518
- _a);
519
- var param = "" + this._prepend(s.model) + qs.stringify(f, { encode: false });
520
- this._uri += param;
521
- return param;
522
- };
523
- NgQubeeService.prototype._parseIncludes = function (s) {
524
- if (!s.includes.length) {
525
- return this._uri;
526
- }
527
- var param = "" + this._prepend(s.model) + this._options.includes + "=" + s.includes;
528
- this._uri += param;
529
- return param;
530
- };
531
- NgQubeeService.prototype._parseLimit = function (s) {
532
- var param = "" + this._prepend(s.model) + this._options.limit + "=" + s.limit;
533
- this._uri += param;
534
- return param;
535
- };
536
- NgQubeeService.prototype._parsePage = function (s) {
537
- var param = "" + this._prepend(s.model) + this._options.page + "=" + s.page;
538
- this._uri += param;
539
- return param;
540
- };
541
- NgQubeeService.prototype._parseSort = function (s) {
542
- var param = '';
543
- var fields = Object.keys(s.sort);
544
- if (!fields.length) {
545
- return param;
546
- }
547
- param = "" + this._prepend(s.model) + this._options.sort + "=";
548
- fields.forEach(function (field, idx) {
549
- param += "" + (s.sort[field] === SortEnum.DESC ? '-' : '') + field;
550
- if (idx < fields.length - 1) {
551
- param += ',';
552
- }
553
- });
554
- this._uri += param;
555
- return param;
556
- };
557
- NgQubeeService.prototype._parse = function (s) {
558
- if (!s.model) {
559
- throw new Error('Set the model property BEFORE adding filters or calling the url() / get() methods');
560
- }
561
- this._parseIncludes(s);
562
- this._parseFields(s);
563
- this._parseFilters(s);
564
- this._parseLimit(s);
565
- this._parsePage(s);
566
- this._parseSort(s);
567
- this._store.dispatch(updateUri({ uri: this._uri }));
568
- };
569
- NgQubeeService.prototype._prepend = function (model) {
570
- return this._uri ? '&' : "/" + model + "?";
571
- };
572
- /**
573
- * Add fields to the select statement for the given model
574
- *
575
- * @param model Model that holds the fields
576
- * @param fields Fields to select
577
- * @returns {this}
578
- */
579
- NgQubeeService.prototype.addFields = function (model, fields) {
580
- var _a;
581
- this._store.dispatch(addFields({
582
- fields: (_a = {},
583
- _a[model] = fields,
584
- _a)
585
- }));
586
- return this;
587
- };
588
- /**
589
- * Add a filter with the given value(s)
590
- * I.e. filter[field]=1 or filter[field]=1,2,3
591
- *
592
- * @param {string} field Name of the field to filter
593
- * @param {string[]} value The needle(s)
594
- * @returns {this}
595
- */
596
- NgQubeeService.prototype.addFilter = function (field) {
597
- var _a;
598
- var values = [];
599
- for (var _i = 1; _i < arguments.length; _i++) {
600
- values[_i - 1] = arguments[_i];
601
- }
602
- this._store.dispatch(addFilters({
603
- filters: (_a = {},
604
- _a[field] = values,
605
- _a)
606
- }));
607
- return this;
608
- };
609
- /**
610
- * Add related entities to include in the request
611
- *
612
- * @param {string[]} models
613
- * @returns
614
- */
615
- NgQubeeService.prototype.addIncludes = function () {
616
- var models = [];
617
- for (var _i = 0; _i < arguments.length; _i++) {
618
- models[_i] = arguments[_i];
619
- }
620
- this._store.dispatch(addIncludes({
621
- includes: models
622
- }));
623
- return this;
624
- };
625
- /**
626
- * Add a field with a sort criteria
627
- *
628
- * @param field Field to use for sorting
629
- * @param {SortEnum} value A value from the SortEnum enumeration
630
- * @returns {this}
631
- */
632
- NgQubeeService.prototype.addSort = function (field, value) {
633
- var _a;
634
- this._store.dispatch(addSorts({
635
- sorts: (_a = {},
636
- _a[field] = value,
637
- _a)
638
- }));
639
- return this;
640
- };
641
- /**
642
- * Delete selected fields for the given model in the current query builder state
643
- *
644
- * @param model Model that holds the fields
645
- * @param {string[]} fields Fields to delete from the state
646
- * @returns {this}
647
- */
648
- NgQubeeService.prototype.deleteFields = function (model) {
649
- var fields = [];
650
- for (var _i = 1; _i < arguments.length; _i++) {
651
- fields[_i - 1] = arguments[_i];
652
- }
653
- this._store.dispatch(deleteFields({ fields: fields }));
654
- return this;
655
- };
656
- /**
657
- * Remove given filters from the query builder state
658
- *
659
- * @param {string[]} filters Filters to remove
660
- * @returns {this}
661
- */
662
- NgQubeeService.prototype.deleteFilters = function () {
663
- var filters = [];
664
- for (var _i = 0; _i < arguments.length; _i++) {
665
- filters[_i] = arguments[_i];
666
- }
667
- this._store.dispatch(deleteFilters({ filters: filters }));
668
- return this;
669
- };
670
- /**
671
- * Remove selected related models from the query builder state
672
- *
673
- * @param {string[]} includes Models to remove
674
- * @returns
675
- */
676
- NgQubeeService.prototype.deleteIncludes = function () {
677
- var includes = [];
678
- for (var _i = 0; _i < arguments.length; _i++) {
679
- includes[_i] = arguments[_i];
680
- }
681
- this._store.dispatch(deleteIncludes({ includes: includes }));
682
- return this;
683
- };
684
- /**
685
- * Remove sorts rules from the query builder state
686
- *
687
- * @param sorts Fields used for sorting to remove
688
- * @returns {this}
689
- */
690
- NgQubeeService.prototype.deleteSorts = function () {
691
- var sorts = [];
692
- for (var _i = 0; _i < arguments.length; _i++) {
693
- sorts[_i] = arguments[_i];
694
- }
695
- this._store.dispatch(deleteSorts({ sorts: sorts }));
696
- return this;
697
- };
698
- /**
699
- * Generate an URI accordingly to the given data
700
- *
701
- * @returns {Observable<string>} An observable that emits the generated uri
702
- */
703
- NgQubeeService.prototype.generateUri = function () {
704
- // Cleanup the previously generated URI
705
- this._uri = '';
706
- this._parse(this._store.state.nest);
707
- return this.uri$;
708
- };
709
- /**
710
- * Clear the current state and reset the Query Builder to a fresh, clean condition
711
- *
712
- * @returns {this}
713
- */
714
- NgQubeeService.prototype.reset = function () {
715
- this._store.dispatch(reset());
716
- return this;
717
- };
718
- /**
719
- * Set the base url to use for composing the address
720
- *
721
- * @param {string} baseUrl
722
- * @returns {this}
723
- */
724
- NgQubeeService.prototype.setBaseUrl = function (baseUrl) {
725
- this._store.dispatch(setBaseUrl({ baseUrl: baseUrl }));
726
- return this;
727
- };
728
- /**
729
- * Set the items per page number
730
- *
731
- * @param limit
732
- * @returns {this}
733
- */
734
- NgQubeeService.prototype.setLimit = function (limit) {
735
- this._store.dispatch(setLimit({ limit: limit }));
736
- return this;
737
- };
738
- /**
739
- * Set the model to use for running the query against
740
- * - I.e. the model "users" will return /users
741
- *
742
- * @param {string} model Model name
743
- * @returns {this}
744
- */
745
- NgQubeeService.prototype.setModel = function (model) {
746
- this._store.dispatch(setModel({ model: model }));
747
- return this;
748
- };
749
- /**
750
- * Set the page that the backend will use to paginate the result set
751
- *
752
- * @param page Page param
753
- * @returns {this}
754
- */
755
- NgQubeeService.prototype.setPage = function (page) {
756
- this._store.dispatch(setPage({ page: page }));
757
- return this;
758
- };
759
- return NgQubeeService;
760
- }());
761
- NgQubeeService.decorators = [
762
- { type: i0.Injectable }
763
- ];
764
- NgQubeeService.ctorParameters = function () { return [
765
- { type: StoreService },
766
- { type: undefined, decorators: [{ type: i0.Inject, args: ['QUERY_PARAMS_CONFIG',] }, { type: i0.Optional }] }
767
- ]; };
768
-
769
- var KeyNotFoundError = /** @class */ (function (_super) {
770
- __extends(KeyNotFoundError, _super);
771
- function KeyNotFoundError(key) {
772
- return _super.call(this, "Cannot find the key " + key + " inside the collection item: does it really exists?") || this;
773
- }
774
- return KeyNotFoundError;
775
- }(Error));
776
-
777
- var PaginatedCollection = /** @class */ (function () {
778
- function PaginatedCollection(data, page, from, to, total, perPage, prevPageUrl, nextPageUrl, lastPage, firstPageUrl, lastPageUrl) {
779
- this.data = data;
780
- this.page = page;
781
- this.from = from;
782
- this.to = to;
783
- this.total = total;
784
- this.perPage = perPage;
785
- this.prevPageUrl = prevPageUrl;
786
- this.nextPageUrl = nextPageUrl;
787
- this.lastPage = lastPage;
788
- this.firstPageUrl = firstPageUrl;
789
- this.lastPageUrl = lastPageUrl;
790
- //
791
- }
792
- /**
793
- * Normalize the collection to a paginated list of ids for state-managed applciations.
794
- *
795
- * This method returns a single key object, where the key is the page number and the associated value is
796
- * an array of ids. Each id is fetched by the collection items, looking up for the "id" key. If an id is supplied
797
- * to this method, it will be used instead of the default "id" key.
798
- *
799
- * Please note that in case the key doesn't exist in the collection's item, the array will be empty
800
- *
801
- * @param k A key to use instead of the default "id": this will be searched inside each element of the collection
802
- */
803
- PaginatedCollection.prototype.normalize = function (id) {
804
- var _a;
805
- return _a = {},
806
- _a[this.page] = this.data.reduce(function (ids, value) {
807
- if (id && value[id]) {
808
- ids.push(value[id]);
809
- }
810
- else if (value.hasOwnProperty('id')) {
811
- ids.push(value['id']);
812
- }
813
- else {
814
- throw new KeyNotFoundError(id || 'id');
815
- }
816
- return ids;
817
- }, []),
818
- _a;
819
- };
820
- return PaginatedCollection;
821
- }());
822
-
823
- var ResponseOptions = /** @class */ (function () {
824
- function ResponseOptions(options) {
825
- this.currentPage = options.currentPage || 'current_page';
826
- this.data = options.data || 'data';
827
- this.firstPageUrl = options.firstPageUrl || 'first_page_url';
828
- this.from = options.from || 'from';
829
- this.lastPage = options.lastPage || 'last_page';
830
- this.lastPageUrl = options.lastPageUrl || 'last_page_url';
831
- this.nextPageUrl = options.nextPageUrl || 'next_page_url';
832
- this.path = options.path || 'path';
833
- this.perPage = options.perPage || 'per_page';
834
- this.prevPageUrl = options.prevPageUrl || 'prev_page_url';
835
- this.to = options.to || 'to';
836
- this.total = options.total || 'total';
837
- }
838
- return ResponseOptions;
839
- }());
840
-
841
- var PaginationService = /** @class */ (function () {
842
- function PaginationService(options) {
843
- if (options === void 0) { options = {}; }
844
- this._options = new ResponseOptions(options);
845
- }
846
- PaginationService.prototype.paginate = function (response) {
847
- 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]);
848
- };
849
- return PaginationService;
850
- }());
851
- PaginationService.decorators = [
852
- { type: i0.Injectable }
853
- ];
854
- PaginationService.ctorParameters = function () { return [
855
- { type: undefined, decorators: [{ type: i0.Inject, args: ['RESPONSE_OPTIONS',] }, { type: i0.Optional }] }
856
- ]; };
857
-
858
- var ɵ0$1 = function (store) { return new NgQubeeService(store, {}); };
859
- // @dynamic
860
- var NgQubeeModule = /** @class */ (function () {
861
- function NgQubeeModule() {
862
- }
863
- NgQubeeModule.forRoot = function (config) {
864
- var _this = this;
865
- if (config === void 0) { config = {}; }
866
- return {
867
- ngModule: NgQubeeModule,
868
- providers: [{
869
- deps: [StoreService],
870
- provide: NgQubeeService,
871
- useFactory: function (store) { return new NgQubeeService(store, Object.assign({}, _this._config.request, config.request)); }
872
- }, {
873
- provide: PaginationService,
874
- useFactory: function () { return new PaginationService(Object.assign({}, _this._config.response, config.response)); }
875
- }]
876
- };
877
- };
878
- return NgQubeeModule;
879
- }());
880
- NgQubeeModule._config = {};
881
- NgQubeeModule.decorators = [
882
- { type: i0.NgModule, args: [{
883
- providers: [{
884
- deps: [StoreService],
885
- provide: NgQubeeService,
886
- useFactory: ɵ0$1
887
- }]
888
- },] }
889
- ];
890
-
891
- /*
892
- * Public API Surface of angular-query-builder
893
- */
894
-
895
- /**
896
- * Generated bundle index. Do not edit.
897
- */
898
-
899
- exports.NgQubeeModule = NgQubeeModule;
900
- exports.NgQubeeService = NgQubeeService;
901
- exports.PaginatedCollection = PaginatedCollection;
902
- exports.PaginationService = PaginationService;
903
- exports.ɵ0 = ɵ0$1;
904
- exports.ɵa = StoreService;
905
-
906
- Object.defineProperty(exports, '__esModule', { value: true });
907
-
908
- })));
909
- //# sourceMappingURL=ng-qubee.umd.js.map