ng-qubee 2.1.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +378 -54
  2. package/fesm2022/ng-qubee.mjs +1791 -419
  3. package/fesm2022/ng-qubee.mjs.map +1 -1
  4. package/package.json +4 -4
  5. package/types/ng-qubee.d.ts +1544 -0
  6. package/index.d.ts +0 -5
  7. package/lib/enums/sort.enum.d.ts +0 -4
  8. package/lib/errors/invalid-limit.error.d.ts +0 -3
  9. package/lib/errors/invalid-model-name.error.d.ts +0 -3
  10. package/lib/errors/invalid-page-number.error.d.ts +0 -3
  11. package/lib/errors/key-not-found.error.d.ts +0 -3
  12. package/lib/errors/unselectable-model.error.d.ts +0 -3
  13. package/lib/interfaces/config.interface.d.ts +0 -6
  14. package/lib/interfaces/fields.interface.d.ts +0 -3
  15. package/lib/interfaces/filters.interface.d.ts +0 -3
  16. package/lib/interfaces/nest-state.interface.d.ts +0 -4
  17. package/lib/interfaces/normalized.interface.d.ts +0 -3
  18. package/lib/interfaces/page.interface.d.ts +0 -2
  19. package/lib/interfaces/paginated-object.interface.d.ts +0 -3
  20. package/lib/interfaces/pagination-config.interface.d.ts +0 -14
  21. package/lib/interfaces/query-builder-config.interface.d.ts +0 -9
  22. package/lib/interfaces/query-builder-state.interface.d.ts +0 -13
  23. package/lib/interfaces/sort.interface.d.ts +0 -5
  24. package/lib/models/paginated-collection.d.ts +0 -30
  25. package/lib/models/query-builder-options.d.ts +0 -11
  26. package/lib/models/response-options.d.ts +0 -16
  27. package/lib/ng-qubee.module.d.ts +0 -9
  28. package/lib/provide-ngqubee.d.ts +0 -21
  29. package/lib/services/nest.service.d.ts +0 -182
  30. package/lib/services/ng-qubee.service.d.ts +0 -147
  31. package/lib/services/pagination.service.d.ts +0 -13
  32. package/public-api.d.ts +0 -20
package/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- /// <amd-module name="ng-qubee" />
5
- export * from './public-api';
@@ -1,4 +0,0 @@
1
- export declare enum SortEnum {
2
- ASC = "asc",
3
- DESC = "desc"
4
- }
@@ -1,3 +0,0 @@
1
- export declare class InvalidLimitError extends Error {
2
- constructor(limit: number);
3
- }
@@ -1,3 +0,0 @@
1
- export declare class InvalidModelNameError extends Error {
2
- constructor(model: string | null | undefined);
3
- }
@@ -1,3 +0,0 @@
1
- export declare class InvalidPageNumberError extends Error {
2
- constructor(page: number);
3
- }
@@ -1,3 +0,0 @@
1
- export declare class KeyNotFoundError extends Error {
2
- constructor(key: string);
3
- }
@@ -1,3 +0,0 @@
1
- export declare class UnselectableModelError extends Error {
2
- constructor(model: string);
3
- }
@@ -1,6 +0,0 @@
1
- import { IPaginationConfig } from "./pagination-config.interface";
2
- import { IQueryBuilderConfig } from "./query-builder-config.interface";
3
- export interface IConfig {
4
- request?: IQueryBuilderConfig;
5
- response?: IPaginationConfig;
6
- }
@@ -1,3 +0,0 @@
1
- export interface IFields {
2
- [model: string]: string[];
3
- }
@@ -1,3 +0,0 @@
1
- export interface IFilters {
2
- [k: string]: (string | number | boolean)[];
3
- }
@@ -1,4 +0,0 @@
1
- import { IQueryBuilderState } from "./query-builder-state.interface";
2
- export interface INestState {
3
- nest: IQueryBuilderState;
4
- }
@@ -1,3 +0,0 @@
1
- export interface INormalized {
2
- [k: number | string]: number[] | string[];
3
- }
@@ -1,2 +0,0 @@
1
- export interface IPage {
2
- }
@@ -1,3 +0,0 @@
1
- export interface IPaginatedObject {
2
- [k: string]: any;
3
- }
@@ -1,14 +0,0 @@
1
- export interface IPaginationConfig {
2
- currentPage?: string;
3
- data?: string;
4
- firstPageUrl?: string;
5
- from?: string;
6
- lastPage?: string;
7
- lastPageUrl?: string;
8
- nextPageUrl?: string;
9
- path?: string;
10
- perPage?: string;
11
- prevPageUrl?: string;
12
- to?: string;
13
- total?: string;
14
- }
@@ -1,9 +0,0 @@
1
- export interface IQueryBuilderConfig {
2
- appends?: string;
3
- fields?: string;
4
- filters?: string;
5
- includes?: string;
6
- limit?: string;
7
- page?: string;
8
- sort?: string;
9
- }
@@ -1,13 +0,0 @@
1
- import { IFields } from "./fields.interface";
2
- import { IFilters } from "./filters.interface";
3
- import { ISort } from "./sort.interface";
4
- export interface IQueryBuilderState {
5
- baseUrl: string;
6
- fields: IFields;
7
- filters: IFilters;
8
- includes: string[];
9
- limit: number;
10
- model: string;
11
- page: number;
12
- sorts: ISort[];
13
- }
@@ -1,5 +0,0 @@
1
- import { SortEnum } from "../enums/sort.enum";
2
- export interface ISort {
3
- field: string;
4
- order: SortEnum;
5
- }
@@ -1,30 +0,0 @@
1
- import { INormalized } from "../interfaces/normalized.interface";
2
- import { IPaginatedObject } from "../interfaces/paginated-object.interface";
3
- export declare class PaginatedCollection<T extends IPaginatedObject> {
4
- data: T[];
5
- readonly page: number;
6
- readonly from?: number | undefined;
7
- readonly to?: number | undefined;
8
- readonly total?: number | undefined;
9
- readonly perPage?: number | undefined;
10
- readonly prevPageUrl?: string | undefined;
11
- readonly nextPageUrl?: string | undefined;
12
- readonly lastPage?: number | undefined;
13
- readonly firstPageUrl?: string | undefined;
14
- readonly lastPageUrl?: string | undefined;
15
- constructor(data: T[], page: number, from?: number | undefined, to?: number | undefined, total?: number | undefined, perPage?: number | undefined, prevPageUrl?: string | undefined, nextPageUrl?: string | undefined, lastPage?: number | undefined, firstPageUrl?: string | undefined, lastPageUrl?: string | undefined);
16
- /**
17
- * Normalize the collection to a paginated list of ids for state-managed applications.
18
- *
19
- * This method returns a single key object, where the key is the page number and the associated value is
20
- * an array of ids. Each id is fetched by the collection items, looking up for the "id" key. If an id is supplied
21
- * to this method, it will be used instead of the default "id" key.
22
- *
23
- * Please note that in case the key doesn't exist in the collection's item, a KeyNotFoundError is thrown
24
- *
25
- * @param k A key to use instead of the default "id": this will be searched inside each element of the collection
26
- * @returns []
27
- * @throws KeyNotFoundItem
28
- */
29
- normalize(id?: string): INormalized;
30
- }
@@ -1,11 +0,0 @@
1
- import { IQueryBuilderConfig } from '../interfaces/query-builder-config.interface';
2
- export declare class QueryBuilderOptions {
3
- readonly appends: string;
4
- readonly fields: string;
5
- readonly filters: string;
6
- readonly includes: string;
7
- readonly limit: string;
8
- readonly page: string;
9
- readonly sort: string;
10
- constructor(options: IQueryBuilderConfig);
11
- }
@@ -1,16 +0,0 @@
1
- import { IPaginationConfig } from '../interfaces/pagination-config.interface';
2
- export declare class ResponseOptions {
3
- readonly currentPage: string;
4
- readonly data: string;
5
- readonly firstPageUrl: string;
6
- readonly from: string;
7
- readonly lastPage: string;
8
- readonly lastPageUrl: string;
9
- readonly nextPageUrl: string;
10
- readonly path: string;
11
- readonly perPage: string;
12
- readonly prevPageUrl: string;
13
- readonly to: string;
14
- readonly total: string;
15
- constructor(options: IPaginationConfig);
16
- }
@@ -1,9 +0,0 @@
1
- import { ModuleWithProviders } from '@angular/core';
2
- import { IConfig } from './interfaces/config.interface';
3
- import * as i0 from "@angular/core";
4
- export declare class NgQubeeModule {
5
- static forRoot(config?: IConfig): ModuleWithProviders<NgQubeeModule>;
6
- static ɵfac: i0.ɵɵFactoryDeclaration<NgQubeeModule, never>;
7
- static ɵmod: i0.ɵɵNgModuleDeclaration<NgQubeeModule, never, never, never>;
8
- static ɵinj: i0.ɵɵInjectorDeclaration<NgQubeeModule>;
9
- }
@@ -1,21 +0,0 @@
1
- import { EnvironmentProviders } from "@angular/core";
2
- import { IConfig } from "./interfaces/config.interface";
3
- /**
4
- * Sets up providers necessary to enable `NgQubee` functionality for the application.
5
- *
6
- * @usageNotes
7
- *
8
- * Basic example of how you can add NgQubee to your application:
9
- * ```
10
- * const config = {};
11
- *
12
- * bootstrapApplication(AppComponent, {
13
- * providers: [provideNgQubee(config)]
14
- * });
15
- * ```
16
- *
17
- * @publicApi
18
- * @param config Configuration object compliant to the IConfig interface
19
- * @returns A set of providers to setup NgQubee
20
- */
21
- export declare function provideNgQubee(config?: IConfig): EnvironmentProviders;
@@ -1,182 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- import { IQueryBuilderState } from '../interfaces/query-builder-state.interface';
3
- import { IFields } from '../interfaces/fields.interface';
4
- import { IFilters } from '../interfaces/filters.interface';
5
- import { ISort } from '../interfaces/sort.interface';
6
- import * as i0 from "@angular/core";
7
- export declare class NestService {
8
- /**
9
- * Private writable signal that holds the Query Builder state
10
- *
11
- * @type {IQueryBuilderState}
12
- */
13
- private _nest;
14
- /**
15
- * A computed signal that makes readonly the writable signal _nest
16
- *
17
- * @type {Signal<IQueryBuilderState>}
18
- */
19
- nest: Signal<IQueryBuilderState>;
20
- constructor();
21
- /**
22
- * Set the base URL for the API
23
- *
24
- * @param {string} baseUrl - The base URL to prepend to generated URIs
25
- * @example
26
- * service.baseUrl = 'https://api.example.com';
27
- */
28
- set baseUrl(baseUrl: string);
29
- /**
30
- * Set the limit for paginated results
31
- * Must be a positive integer greater than 0
32
- *
33
- * @param {number} limit - The number of items per page
34
- * @throws {InvalidLimitError} If limit is not a positive integer
35
- * @example
36
- * service.limit = 25;
37
- */
38
- set limit(limit: number);
39
- /**
40
- * Set the model name for the query
41
- * Must be a non-empty string
42
- *
43
- * @param {string} model - The model/resource name (e.g., 'users', 'posts')
44
- * @throws {InvalidModelNameError} If model is not a non-empty string
45
- * @example
46
- * service.model = 'users';
47
- */
48
- set model(model: string);
49
- /**
50
- * Set the page number for pagination
51
- * Must be a positive integer greater than 0
52
- *
53
- * @param {number} page - The page number to fetch
54
- * @throws {InvalidPageNumberError} If page is not a positive integer
55
- * @example
56
- * service.page = 2;
57
- */
58
- set page(page: number);
59
- private _clone;
60
- /**
61
- * Validates that the model name is a non-empty string
62
- *
63
- * @param {string} model - The model name to validate
64
- * @throws {InvalidModelNameError} If model is not a non-empty string
65
- * @private
66
- */
67
- private _validateModelName;
68
- /**
69
- * Validates that the page number is a positive integer
70
- *
71
- * @param {number} page - The page number to validate
72
- * @throws {InvalidPageNumberError} If page is not a positive integer
73
- * @private
74
- */
75
- private _validatePageNumber;
76
- /**
77
- * Validates that the limit is a positive integer
78
- *
79
- * @param {number} limit - The limit value to validate
80
- * @throws {InvalidLimitError} If limit is not a positive integer
81
- * @private
82
- */
83
- private _validateLimit;
84
- /**
85
- * Add selectable fields for the given model to the request
86
- * Automatically prevents duplicate fields for each model
87
- *
88
- * @param {IFields} fields - Object mapping model names to arrays of field names
89
- * @return {void}
90
- * @example
91
- * service.addFields({ users: ['id', 'email', 'username'] });
92
- * service.addFields({ posts: ['title', 'content'] });
93
- */
94
- addFields(fields: IFields): void;
95
- /**
96
- * Add filters to the request
97
- * Automatically prevents duplicate filter values for each filter key
98
- *
99
- * @param {IFilters} filters - Object mapping filter keys to arrays of values
100
- * @return {void}
101
- * @example
102
- * service.addFilters({ id: [1, 2, 3] });
103
- * service.addFilters({ status: ['active', 'pending'] });
104
- */
105
- addFilters(filters: IFilters): void;
106
- /**
107
- * Add resources to include with the request
108
- * Automatically prevents duplicate includes
109
- *
110
- * @param {string[]} includes - Array of model names to include in the response
111
- * @return {void}
112
- * @example
113
- * service.addIncludes(['profile', 'posts']);
114
- * service.addIncludes(['comments']);
115
- */
116
- addIncludes(includes: string[]): void;
117
- /**
118
- * Add a field that should be used for sorting data
119
- *
120
- * @param {ISort} sort - Sort configuration with field name and order (ASC/DESC)
121
- * @return {void}
122
- * @example
123
- * import { SortEnum } from 'ng-qubee';
124
- * service.addSort({ field: 'created_at', order: SortEnum.DESC });
125
- * service.addSort({ field: 'name', order: SortEnum.ASC });
126
- */
127
- addSort(sort: ISort): void;
128
- /**
129
- * Remove fields for the given model
130
- * Uses deep cloning to prevent mutations to the original state
131
- *
132
- * @param {IFields} fields - Object mapping model names to arrays of field names to remove
133
- * @return {void}
134
- * @example
135
- * service.deleteFields({ users: ['email'] });
136
- * service.deleteFields({ posts: ['content', 'body'] });
137
- */
138
- deleteFields(fields: IFields): void;
139
- /**
140
- * Remove filters from the request
141
- * Uses deep cloning to prevent mutations to the original state
142
- *
143
- * @param {...string[]} filters - Filter keys to remove
144
- * @return {void}
145
- * @example
146
- * service.deleteFilters('id');
147
- * service.deleteFilters('status', 'type');
148
- */
149
- deleteFilters(...filters: string[]): void;
150
- /**
151
- * Remove includes from the request
152
- *
153
- * @param {...string[]} includes - Include names to remove
154
- * @return {void}
155
- * @example
156
- * service.deleteIncludes('profile');
157
- * service.deleteIncludes('posts', 'comments');
158
- */
159
- deleteIncludes(...includes: string[]): void;
160
- /**
161
- * Remove sorts from the request by field name
162
- *
163
- * @param {...string[]} sorts - Field names of sorts to remove
164
- * @return {void}
165
- * @example
166
- * service.deleteSorts('created_at');
167
- * service.deleteSorts('name', 'created_at');
168
- */
169
- deleteSorts(...sorts: string[]): void;
170
- /**
171
- * Reset the query builder state to initial values
172
- * Clears all fields, filters, includes, sorts, and resets pagination
173
- *
174
- * @return {void}
175
- * @example
176
- * service.reset();
177
- * // State is now: { baseUrl: '', fields: {}, filters: {}, includes: [], limit: 15, model: '', page: 1, sorts: [] }
178
- */
179
- reset(): void;
180
- static ɵfac: i0.ɵɵFactoryDeclaration<NestService, never>;
181
- static ɵprov: i0.ɵɵInjectableDeclaration<NestService>;
182
- }
@@ -1,147 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { SortEnum } from '../enums/sort.enum';
3
- import { IFields } from '../interfaces/fields.interface';
4
- import { IQueryBuilderConfig } from '../interfaces/query-builder-config.interface';
5
- import { NestService } from './nest.service';
6
- import * as i0 from "@angular/core";
7
- export declare class NgQubeeService {
8
- private _nestService;
9
- private _options;
10
- /**
11
- * This property serves as an accumulator for holding the composed string with each query param
12
- */
13
- private _uri;
14
- private _uri$;
15
- uri$: Observable<string>;
16
- constructor(_nestService: NestService, options?: IQueryBuilderConfig);
17
- private _parseFields;
18
- private _parseFilters;
19
- private _parseIncludes;
20
- private _parseLimit;
21
- private _parsePage;
22
- private _parseSort;
23
- private _parse;
24
- private _prepend;
25
- /**
26
- * Add fields to the select statement for the given model
27
- *
28
- * @param model Model that holds the fields
29
- * @param fields Fields to select
30
- * @returns {this}
31
- */
32
- addFields(model: string, fields: string[]): this;
33
- /**
34
- * Add a filter with the given value(s)
35
- * I.e. filter[field]=1 or filter[field]=1,2,3
36
- *
37
- * @param {string} field Name of the field to filter
38
- * @param {string[]} value The needle(s)
39
- * @returns {this}
40
- */
41
- addFilter(field: string, ...values: (string | number | boolean)[]): this;
42
- /**
43
- * Add related entities to include in the request
44
- *
45
- * @param {string[]} models
46
- * @returns
47
- */
48
- addIncludes(...models: string[]): this;
49
- /**
50
- * Add a field with a sort criteria
51
- *
52
- * @param field Field to use for sorting
53
- * @param {SortEnum} order A value from the SortEnum enumeration
54
- * @returns {this}
55
- */
56
- addSort(field: string, order: SortEnum): this;
57
- /**
58
- * Delete selected fields for the given models in the current query builder state
59
- *
60
- * ```
61
- * ngQubeeService.deleteFields({
62
- * users: ['email', 'password'],
63
- * address: ['zipcode']
64
- * });
65
- * ```
66
- *
67
- * @param {IFields} fields
68
- * @returns
69
- */
70
- deleteFields(fields: IFields): this;
71
- /**
72
- * Delete selected fields for the given model in the current query builder state
73
- *
74
- * ```
75
- * ngQubeeService.deleteFieldsByModel('users', 'email', 'password']);
76
- * ```
77
- *
78
- * @param model Model that holds the fields
79
- * @param {string[]} fields Fields to delete from the state
80
- * @returns {this}
81
- */
82
- deleteFieldsByModel(model: string, ...fields: string[]): this;
83
- /**
84
- * Remove given filters from the query builder state
85
- *
86
- * @param {string[]} filters Filters to remove
87
- * @returns {this}
88
- */
89
- deleteFilters(...filters: string[]): this;
90
- /**
91
- * Remove selected related models from the query builder state
92
- *
93
- * @param {string[]} includes Models to remove
94
- * @returns
95
- */
96
- deleteIncludes(...includes: string[]): this;
97
- /**
98
- * Remove sorts rules from the query builder state
99
- *
100
- * @param sorts Fields used for sorting to remove
101
- * @returns {this}
102
- */
103
- deleteSorts(...sorts: string[]): this;
104
- /**
105
- * Generate an URI accordingly to the given data
106
- *
107
- * @returns {Observable<string>} An observable that emits the generated uri
108
- */
109
- generateUri(): Observable<string>;
110
- /**
111
- * Clear the current state and reset the Query Builder to a fresh, clean condition
112
- *
113
- * @returns {this}
114
- */
115
- reset(): this;
116
- /**
117
- * Set the base url to use for composing the address
118
- *
119
- * @param {string} baseUrl
120
- * @returns {this}
121
- */
122
- setBaseUrl(baseUrl: string): this;
123
- /**
124
- * Set the items per page number
125
- *
126
- * @param limit
127
- * @returns {this}
128
- */
129
- setLimit(limit: number): this;
130
- /**
131
- * Set the model to use for running the query against
132
- * - I.e. the model "users" will return /users
133
- *
134
- * @param {string} model Model name
135
- * @returns {this}
136
- */
137
- setModel(model: string): this;
138
- /**
139
- * Set the page that the backend will use to paginate the result set
140
- *
141
- * @param page Page param
142
- * @returns {this}
143
- */
144
- setPage(page: number): this;
145
- static ɵfac: i0.ɵɵFactoryDeclaration<NgQubeeService, [null, { optional: true; }]>;
146
- static ɵprov: i0.ɵɵInjectableDeclaration<NgQubeeService>;
147
- }
@@ -1,13 +0,0 @@
1
- import { IPaginationConfig } from "../interfaces/pagination-config.interface";
2
- import { PaginatedCollection } from "../models/paginated-collection";
3
- import { IPaginatedObject } from "../interfaces/paginated-object.interface";
4
- import * as i0 from "@angular/core";
5
- export declare class PaginationService {
6
- private _options;
7
- constructor(options?: IPaginationConfig);
8
- paginate<T extends IPaginatedObject>(response: {
9
- [key: string]: any;
10
- }): PaginatedCollection<T>;
11
- static ɵfac: i0.ɵɵFactoryDeclaration<PaginationService, [{ optional: true; }]>;
12
- static ɵprov: i0.ɵɵInjectableDeclaration<PaginationService>;
13
- }
package/public-api.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export * from './lib/models/paginated-collection';
2
- export * from './lib/ng-qubee.module';
3
- export * from './lib/provide-ngqubee';
4
- export * from './lib/services/ng-qubee.service';
5
- export * from './lib/services/pagination.service';
6
- export * from './lib/enums/sort.enum';
7
- export * from './lib/errors/invalid-limit.error';
8
- export * from './lib/errors/invalid-model-name.error';
9
- export * from './lib/errors/invalid-page-number.error';
10
- export * from './lib/errors/key-not-found.error';
11
- export * from './lib/errors/unselectable-model.error';
12
- export * from './lib/interfaces/config.interface';
13
- export * from './lib/interfaces/fields.interface';
14
- export * from './lib/interfaces/filters.interface';
15
- export * from './lib/interfaces/nest-state.interface';
16
- export * from './lib/interfaces/page.interface';
17
- export * from './lib/interfaces/paginated-object.interface';
18
- export * from './lib/interfaces/pagination-config.interface';
19
- export * from './lib/interfaces/query-builder-config.interface';
20
- export * from './lib/interfaces/sort.interface';