ng-qubee 1.0.11 → 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 (71) 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/{fesm2015/ng-qubee.js → fesm2022/ng-qubee.mjs} +369 -217
  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 -927
  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 -298
  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.map +0 -1
  66. package/lib/actions/query-builder.actions.d.ts +0 -43
  67. package/lib/interfaces/nest-state.interface.d.ts +0 -4
  68. package/lib/reducers/query-builder.reducer.d.ts +0 -2
  69. package/lib/services/store.service.d.ts +0 -9
  70. package/ng-qubee.d.ts +0 -7
  71. package/ng-qubee.metadata.json +0 -1
@@ -1,927 +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
- if (!fields.length) {
582
- return this;
583
- }
584
- this._store.dispatch(addFields({
585
- fields: (_a = {},
586
- _a[model] = fields,
587
- _a)
588
- }));
589
- return this;
590
- };
591
- /**
592
- * Add a filter with the given value(s)
593
- * I.e. filter[field]=1 or filter[field]=1,2,3
594
- *
595
- * @param {string} field Name of the field to filter
596
- * @param {string[]} value The needle(s)
597
- * @returns {this}
598
- */
599
- NgQubeeService.prototype.addFilter = function (field) {
600
- var _a;
601
- var values = [];
602
- for (var _i = 1; _i < arguments.length; _i++) {
603
- values[_i - 1] = arguments[_i];
604
- }
605
- if (!values.length) {
606
- return this;
607
- }
608
- this._store.dispatch(addFilters({
609
- filters: (_a = {},
610
- _a[field] = values,
611
- _a)
612
- }));
613
- return this;
614
- };
615
- /**
616
- * Add related entities to include in the request
617
- *
618
- * @param {string[]} models
619
- * @returns
620
- */
621
- NgQubeeService.prototype.addIncludes = function () {
622
- var models = [];
623
- for (var _i = 0; _i < arguments.length; _i++) {
624
- models[_i] = arguments[_i];
625
- }
626
- if (!models) {
627
- return this;
628
- }
629
- this._store.dispatch(addIncludes({
630
- includes: models
631
- }));
632
- return this;
633
- };
634
- /**
635
- * Add a field with a sort criteria
636
- *
637
- * @param field Field to use for sorting
638
- * @param {SortEnum} value A value from the SortEnum enumeration
639
- * @returns {this}
640
- */
641
- NgQubeeService.prototype.addSort = function (field, value) {
642
- var _a;
643
- this._store.dispatch(addSorts({
644
- sorts: (_a = {},
645
- _a[field] = value,
646
- _a)
647
- }));
648
- return this;
649
- };
650
- /**
651
- * Delete selected fields for the given model in the current query builder state
652
- *
653
- * @param model Model that holds the fields
654
- * @param {string[]} fields Fields to delete from the state
655
- * @returns {this}
656
- */
657
- NgQubeeService.prototype.deleteFields = function (model) {
658
- var fields = [];
659
- for (var _i = 1; _i < arguments.length; _i++) {
660
- fields[_i - 1] = arguments[_i];
661
- }
662
- if (!fields.length) {
663
- return this;
664
- }
665
- this._store.dispatch(deleteFields({ fields: fields }));
666
- return this;
667
- };
668
- /**
669
- * Remove given filters from the query builder state
670
- *
671
- * @param {string[]} filters Filters to remove
672
- * @returns {this}
673
- */
674
- NgQubeeService.prototype.deleteFilters = function () {
675
- var filters = [];
676
- for (var _i = 0; _i < arguments.length; _i++) {
677
- filters[_i] = arguments[_i];
678
- }
679
- if (!filters.length) {
680
- return this;
681
- }
682
- this._store.dispatch(deleteFilters({ filters: filters }));
683
- return this;
684
- };
685
- /**
686
- * Remove selected related models from the query builder state
687
- *
688
- * @param {string[]} includes Models to remove
689
- * @returns
690
- */
691
- NgQubeeService.prototype.deleteIncludes = function () {
692
- var includes = [];
693
- for (var _i = 0; _i < arguments.length; _i++) {
694
- includes[_i] = arguments[_i];
695
- }
696
- if (!includes.length) {
697
- return this;
698
- }
699
- this._store.dispatch(deleteIncludes({ includes: includes }));
700
- return this;
701
- };
702
- /**
703
- * Remove sorts rules from the query builder state
704
- *
705
- * @param sorts Fields used for sorting to remove
706
- * @returns {this}
707
- */
708
- NgQubeeService.prototype.deleteSorts = function () {
709
- var sorts = [];
710
- for (var _i = 0; _i < arguments.length; _i++) {
711
- sorts[_i] = arguments[_i];
712
- }
713
- this._store.dispatch(deleteSorts({ sorts: sorts }));
714
- return this;
715
- };
716
- /**
717
- * Generate an URI accordingly to the given data
718
- *
719
- * @returns {Observable<string>} An observable that emits the generated uri
720
- */
721
- NgQubeeService.prototype.generateUri = function () {
722
- // Cleanup the previously generated URI
723
- this._uri = '';
724
- this._parse(this._store.state.nest);
725
- return this.uri$;
726
- };
727
- /**
728
- * Clear the current state and reset the Query Builder to a fresh, clean condition
729
- *
730
- * @returns {this}
731
- */
732
- NgQubeeService.prototype.reset = function () {
733
- this._store.dispatch(reset());
734
- return this;
735
- };
736
- /**
737
- * Set the base url to use for composing the address
738
- *
739
- * @param {string} baseUrl
740
- * @returns {this}
741
- */
742
- NgQubeeService.prototype.setBaseUrl = function (baseUrl) {
743
- this._store.dispatch(setBaseUrl({ baseUrl: baseUrl }));
744
- return this;
745
- };
746
- /**
747
- * Set the items per page number
748
- *
749
- * @param limit
750
- * @returns {this}
751
- */
752
- NgQubeeService.prototype.setLimit = function (limit) {
753
- this._store.dispatch(setLimit({ limit: limit }));
754
- return this;
755
- };
756
- /**
757
- * Set the model to use for running the query against
758
- * - I.e. the model "users" will return /users
759
- *
760
- * @param {string} model Model name
761
- * @returns {this}
762
- */
763
- NgQubeeService.prototype.setModel = function (model) {
764
- this._store.dispatch(setModel({ model: model }));
765
- return this;
766
- };
767
- /**
768
- * Set the page that the backend will use to paginate the result set
769
- *
770
- * @param page Page param
771
- * @returns {this}
772
- */
773
- NgQubeeService.prototype.setPage = function (page) {
774
- this._store.dispatch(setPage({ page: page }));
775
- return this;
776
- };
777
- return NgQubeeService;
778
- }());
779
- NgQubeeService.decorators = [
780
- { type: i0.Injectable }
781
- ];
782
- NgQubeeService.ctorParameters = function () { return [
783
- { type: StoreService },
784
- { type: undefined, decorators: [{ type: i0.Inject, args: ['QUERY_PARAMS_CONFIG',] }, { type: i0.Optional }] }
785
- ]; };
786
-
787
- var KeyNotFoundError = /** @class */ (function (_super) {
788
- __extends(KeyNotFoundError, _super);
789
- function KeyNotFoundError(key) {
790
- return _super.call(this, "Cannot find the key " + key + " inside the collection item: does it really exists?") || this;
791
- }
792
- return KeyNotFoundError;
793
- }(Error));
794
-
795
- var PaginatedCollection = /** @class */ (function () {
796
- function PaginatedCollection(data, page, from, to, total, perPage, prevPageUrl, nextPageUrl, lastPage, firstPageUrl, lastPageUrl) {
797
- this.data = data;
798
- this.page = page;
799
- this.from = from;
800
- this.to = to;
801
- this.total = total;
802
- this.perPage = perPage;
803
- this.prevPageUrl = prevPageUrl;
804
- this.nextPageUrl = nextPageUrl;
805
- this.lastPage = lastPage;
806
- this.firstPageUrl = firstPageUrl;
807
- this.lastPageUrl = lastPageUrl;
808
- //
809
- }
810
- /**
811
- * Normalize the collection to a paginated list of ids for state-managed applciations.
812
- *
813
- * This method returns a single key object, where the key is the page number and the associated value is
814
- * an array of ids. Each id is fetched by the collection items, looking up for the "id" key. If an id is supplied
815
- * to this method, it will be used instead of the default "id" key.
816
- *
817
- * Please note that in case the key doesn't exist in the collection's item, the array will be empty
818
- *
819
- * @param k A key to use instead of the default "id": this will be searched inside each element of the collection
820
- */
821
- PaginatedCollection.prototype.normalize = function (id) {
822
- var _a;
823
- return _a = {},
824
- _a[this.page] = this.data.reduce(function (ids, value) {
825
- if (id && value[id]) {
826
- ids.push(value[id]);
827
- }
828
- else if (value.hasOwnProperty('id')) {
829
- ids.push(value['id']);
830
- }
831
- else {
832
- throw new KeyNotFoundError(id || 'id');
833
- }
834
- return ids;
835
- }, []),
836
- _a;
837
- };
838
- return PaginatedCollection;
839
- }());
840
-
841
- var ResponseOptions = /** @class */ (function () {
842
- function ResponseOptions(options) {
843
- this.currentPage = options.currentPage || 'current_page';
844
- this.data = options.data || 'data';
845
- this.firstPageUrl = options.firstPageUrl || 'first_page_url';
846
- this.from = options.from || 'from';
847
- this.lastPage = options.lastPage || 'last_page';
848
- this.lastPageUrl = options.lastPageUrl || 'last_page_url';
849
- this.nextPageUrl = options.nextPageUrl || 'next_page_url';
850
- this.path = options.path || 'path';
851
- this.perPage = options.perPage || 'per_page';
852
- this.prevPageUrl = options.prevPageUrl || 'prev_page_url';
853
- this.to = options.to || 'to';
854
- this.total = options.total || 'total';
855
- }
856
- return ResponseOptions;
857
- }());
858
-
859
- var PaginationService = /** @class */ (function () {
860
- function PaginationService(options) {
861
- if (options === void 0) { options = {}; }
862
- this._options = new ResponseOptions(options);
863
- }
864
- PaginationService.prototype.paginate = function (response) {
865
- 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]);
866
- };
867
- return PaginationService;
868
- }());
869
- PaginationService.decorators = [
870
- { type: i0.Injectable }
871
- ];
872
- PaginationService.ctorParameters = function () { return [
873
- { type: undefined, decorators: [{ type: i0.Inject, args: ['RESPONSE_OPTIONS',] }, { type: i0.Optional }] }
874
- ]; };
875
-
876
- var ɵ0$1 = function (store) { return new NgQubeeService(store, {}); };
877
- // @dynamic
878
- var NgQubeeModule = /** @class */ (function () {
879
- function NgQubeeModule() {
880
- }
881
- NgQubeeModule.forRoot = function (config) {
882
- var _this = this;
883
- if (config === void 0) { config = {}; }
884
- return {
885
- ngModule: NgQubeeModule,
886
- providers: [{
887
- deps: [StoreService],
888
- provide: NgQubeeService,
889
- useFactory: function (store) { return new NgQubeeService(store, Object.assign({}, _this._config.request, config.request)); }
890
- }, {
891
- provide: PaginationService,
892
- useFactory: function () { return new PaginationService(Object.assign({}, _this._config.response, config.response)); }
893
- }]
894
- };
895
- };
896
- return NgQubeeModule;
897
- }());
898
- NgQubeeModule._config = {};
899
- NgQubeeModule.decorators = [
900
- { type: i0.NgModule, args: [{
901
- providers: [{
902
- deps: [StoreService],
903
- provide: NgQubeeService,
904
- useFactory: ɵ0$1
905
- }]
906
- },] }
907
- ];
908
-
909
- /*
910
- * Public API Surface of angular-query-builder
911
- */
912
-
913
- /**
914
- * Generated bundle index. Do not edit.
915
- */
916
-
917
- exports.NgQubeeModule = NgQubeeModule;
918
- exports.NgQubeeService = NgQubeeService;
919
- exports.PaginatedCollection = PaginatedCollection;
920
- exports.PaginationService = PaginationService;
921
- exports.ɵ0 = ɵ0$1;
922
- exports.ɵa = StoreService;
923
-
924
- Object.defineProperty(exports, '__esModule', { value: true });
925
-
926
- })));
927
- //# sourceMappingURL=ng-qubee.umd.js.map