@ethlete/query 5.16.0 → 5.16.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 (184) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/esm2022/ethlete-query.mjs +5 -0
  3. package/esm2022/index.mjs +20 -0
  4. package/esm2022/lib/auth/auth-provider.types.mjs +2 -0
  5. package/esm2022/lib/auth/auth-provider.utils.mjs +25 -0
  6. package/esm2022/lib/auth/basic-auth-provider.mjs +15 -0
  7. package/esm2022/lib/auth/bearer-auth-provider.mjs +168 -0
  8. package/esm2022/lib/auth/custom-header-auth-provider.mjs +12 -0
  9. package/esm2022/lib/auth/index.mjs +6 -0
  10. package/esm2022/lib/class-validator/class-validator.types.mjs +2 -0
  11. package/esm2022/lib/class-validator/class-validator.utils.mjs +4 -0
  12. package/esm2022/lib/class-validator/index.mjs +3 -0
  13. package/esm2022/lib/devtools/components/query-devtools/index.mjs +2 -0
  14. package/esm2022/lib/devtools/components/query-devtools/query-devtools.component.mjs +297 -0
  15. package/esm2022/lib/devtools/pipes/index.mjs +2 -0
  16. package/esm2022/lib/devtools/pipes/query-short-name.pipe.mjs +24 -0
  17. package/esm2022/lib/devtools/utils/index.mjs +2 -0
  18. package/esm2022/lib/devtools/utils/query-client.utils.mjs +13 -0
  19. package/esm2022/lib/directives/index.mjs +4 -0
  20. package/esm2022/lib/directives/infinity-query-trigger.directive.mjs +56 -0
  21. package/esm2022/lib/directives/infinity-query.directive.mjs +147 -0
  22. package/esm2022/lib/directives/query.directive.mjs +123 -0
  23. package/esm2022/lib/entity/entity-store.mjs +127 -0
  24. package/esm2022/lib/entity/entity.types.mjs +2 -0
  25. package/esm2022/lib/entity/entity.utils.mjs +29 -0
  26. package/esm2022/lib/entity/index.mjs +4 -0
  27. package/esm2022/lib/gql/gql.mjs +23 -0
  28. package/esm2022/lib/gql/index.mjs +2 -0
  29. package/esm2022/lib/infinite-query/index.mjs +4 -0
  30. package/esm2022/lib/infinite-query/infinity-query.mjs +171 -0
  31. package/esm2022/lib/infinite-query/infinity-query.types.mjs +2 -0
  32. package/esm2022/lib/infinite-query/infinity-query.utils.mjs +3 -0
  33. package/esm2022/lib/logger/index.mjs +2 -0
  34. package/esm2022/lib/logger/logger.mjs +16 -0
  35. package/esm2022/lib/query/index.mjs +4 -0
  36. package/esm2022/lib/query/query.mjs +430 -0
  37. package/esm2022/lib/query/query.types.mjs +2 -0
  38. package/esm2022/lib/query/query.utils.mjs +253 -0
  39. package/esm2022/lib/query-client/index.mjs +4 -0
  40. package/esm2022/lib/query-client/query-client.mjs +80 -0
  41. package/esm2022/lib/query-client/query-client.types.mjs +2 -0
  42. package/esm2022/lib/query-client/query-client.utils.mjs +20 -0
  43. package/esm2022/lib/query-creator/index.mjs +3 -0
  44. package/esm2022/lib/query-creator/query-creator.mjs +55 -0
  45. package/esm2022/lib/query-creator/query-creator.types.mjs +2 -0
  46. package/esm2022/lib/query-form/index.mjs +4 -0
  47. package/esm2022/lib/query-form/query-form.mjs +379 -0
  48. package/esm2022/lib/query-form/query-form.types.mjs +2 -0
  49. package/esm2022/lib/query-form/query-form.utils.mjs +97 -0
  50. package/esm2022/lib/query-store/index.mjs +2 -0
  51. package/esm2022/lib/query-store/query-store.mjs +144 -0
  52. package/esm2022/lib/request/index.mjs +4 -0
  53. package/esm2022/lib/request/request.mjs +196 -0
  54. package/esm2022/lib/request/request.types.mjs +2 -0
  55. package/esm2022/lib/request/request.util.mjs +252 -0
  56. package/esm2022/lib/symfony/index.mjs +3 -0
  57. package/esm2022/lib/symfony/symfony.types.mjs +2 -0
  58. package/esm2022/lib/symfony/symfony.utils.mjs +31 -0
  59. package/esm2022/lib/utils/data.utils.mjs +138 -0
  60. package/esm2022/lib/utils/deep-freeze.util.mjs +17 -0
  61. package/esm2022/lib/utils/def.util.mjs +8 -0
  62. package/esm2022/lib/utils/index.mjs +4 -0
  63. package/fesm2022/ethlete-query.mjs +3289 -0
  64. package/fesm2022/ethlete-query.mjs.map +1 -0
  65. package/{src/index.ts → index.d.ts} +0 -2
  66. package/lib/auth/auth-provider.types.d.ts +133 -0
  67. package/lib/auth/auth-provider.utils.d.ts +9 -0
  68. package/lib/auth/basic-auth-provider.d.ts +10 -0
  69. package/lib/auth/bearer-auth-provider.d.ts +23 -0
  70. package/lib/auth/custom-header-auth-provider.d.ts +9 -0
  71. package/{src/lib/class-validator/class-validator.types.ts → lib/class-validator/class-validator.types.d.ts} +3 -4
  72. package/lib/class-validator/class-validator.utils.d.ts +2 -0
  73. package/lib/devtools/components/query-devtools/query-devtools.component.d.ts +151 -0
  74. package/lib/devtools/pipes/query-short-name.pipe.d.ts +8 -0
  75. package/lib/devtools/utils/query-client.utils.d.ts +12 -0
  76. package/lib/directives/infinity-query-trigger.directive.d.ts +15 -0
  77. package/lib/directives/infinity-query.directive.d.ts +49 -0
  78. package/lib/directives/query.directive.d.ts +63 -0
  79. package/lib/entity/entity-store.d.ts +25 -0
  80. package/lib/entity/entity.types.d.ts +25 -0
  81. package/lib/entity/entity.utils.d.ts +12 -0
  82. package/lib/gql/gql.d.ts +6 -0
  83. package/lib/infinite-query/infinity-query.d.ts +29 -0
  84. package/lib/infinite-query/infinity-query.types.d.ts +104 -0
  85. package/lib/infinite-query/infinity-query.utils.d.ts +4 -0
  86. package/lib/logger/logger.d.ts +12 -0
  87. package/lib/query/query.d.ts +60 -0
  88. package/lib/query/query.types.d.ts +388 -0
  89. package/lib/query/query.utils.d.ts +82 -0
  90. package/lib/query-client/query-client.d.ts +29 -0
  91. package/lib/query-client/query-client.types.d.ts +82 -0
  92. package/lib/query-client/query-client.utils.d.ts +4 -0
  93. package/lib/query-creator/query-creator.d.ts +20 -0
  94. package/lib/query-creator/query-creator.types.d.ts +13 -0
  95. package/lib/query-form/query-form.d.ts +91 -0
  96. package/lib/query-form/query-form.types.d.ts +145 -0
  97. package/lib/query-form/query-form.utils.d.ts +13 -0
  98. package/lib/query-store/query-store.d.ts +31 -0
  99. package/lib/request/request.d.ts +3 -0
  100. package/lib/request/request.types.d.ts +126 -0
  101. package/lib/request/request.util.d.ts +92 -0
  102. package/lib/symfony/symfony.types.d.ts +19 -0
  103. package/lib/symfony/symfony.utils.d.ts +6 -0
  104. package/lib/utils/data.utils.d.ts +59 -0
  105. package/lib/utils/deep-freeze.util.d.ts +1 -0
  106. package/{src/lib/utils/def.util.ts → lib/utils/def.util.d.ts} +1 -1
  107. package/package.json +23 -6
  108. package/.eslintrc.json +0 -40
  109. package/jest.config.ts +0 -23
  110. package/ng-package.json +0 -8
  111. package/project.json +0 -37
  112. package/src/lib/auth/auth-provider.types.ts +0 -160
  113. package/src/lib/auth/auth-provider.utils.ts +0 -39
  114. package/src/lib/auth/basic-auth-provider.ts +0 -17
  115. package/src/lib/auth/bearer-auth-provider.ts +0 -243
  116. package/src/lib/auth/custom-header-auth-provider.ts +0 -13
  117. package/src/lib/class-validator/class-validator.utils.ts +0 -5
  118. package/src/lib/devtools/components/query-devtools/query-devtools.component.html +0 -402
  119. package/src/lib/devtools/components/query-devtools/query-devtools.component.scss +0 -360
  120. package/src/lib/devtools/components/query-devtools/query-devtools.component.ts +0 -427
  121. package/src/lib/devtools/pipes/query-short-name.pipe.ts +0 -24
  122. package/src/lib/devtools/utils/query-client.utils.ts +0 -25
  123. package/src/lib/directives/infinity-query-trigger.directive.ts +0 -58
  124. package/src/lib/directives/infinity-query.directive.ts +0 -208
  125. package/src/lib/directives/query.directive.ts +0 -201
  126. package/src/lib/entity/entity-store.ts +0 -180
  127. package/src/lib/entity/entity.types.ts +0 -34
  128. package/src/lib/entity/entity.utils.ts +0 -51
  129. package/src/lib/gql/gql.ts +0 -22
  130. package/src/lib/infinite-query/infinity-query.ts +0 -245
  131. package/src/lib/infinite-query/infinity-query.types.ts +0 -149
  132. package/src/lib/infinite-query/infinity-query.utils.ts +0 -14
  133. package/src/lib/logger/logger.ts +0 -30
  134. package/src/lib/query/query.ts +0 -631
  135. package/src/lib/query/query.types.ts +0 -532
  136. package/src/lib/query/query.utils.spec.ts +0 -92
  137. package/src/lib/query/query.utils.ts +0 -450
  138. package/src/lib/query-client/query-client.spec.ts +0 -77
  139. package/src/lib/query-client/query-client.ts +0 -195
  140. package/src/lib/query-client/query-client.types.ts +0 -101
  141. package/src/lib/query-client/query-client.utils.spec.ts +0 -61
  142. package/src/lib/query-client/query-client.utils.ts +0 -28
  143. package/src/lib/query-creator/query-creator.ts +0 -103
  144. package/src/lib/query-creator/query-creator.types.ts +0 -74
  145. package/src/lib/query-form/query-form.ts +0 -526
  146. package/src/lib/query-form/query-form.types.ts +0 -169
  147. package/src/lib/query-form/query-form.utils.ts +0 -116
  148. package/src/lib/query-store/query-store.ts +0 -192
  149. package/src/lib/request/request.ts +0 -253
  150. package/src/lib/request/request.types.ts +0 -164
  151. package/src/lib/request/request.util.spec.ts +0 -177
  152. package/src/lib/request/request.util.ts +0 -399
  153. package/src/lib/stories/angular-example-page.mdx +0 -85
  154. package/src/lib/stories/authentication-page.mdx +0 -35
  155. package/src/lib/stories/changelog-page.mdx +0 -9
  156. package/src/lib/stories/client-page.mdx +0 -100
  157. package/src/lib/stories/queries-page.mdx +0 -117
  158. package/src/lib/symfony/symfony.types.ts +0 -21
  159. package/src/lib/symfony/symfony.utils.ts +0 -43
  160. package/src/lib/utils/data.utils.ts +0 -280
  161. package/src/lib/utils/deep-freeze.util.ts +0 -21
  162. package/src/test-setup.ts +0 -1
  163. package/tsconfig.json +0 -29
  164. package/tsconfig.lib.json +0 -12
  165. package/tsconfig.lib.prod.json +0 -10
  166. package/tsconfig.spec.json +0 -11
  167. /package/{src/lib/auth/index.ts → lib/auth/index.d.ts} +0 -0
  168. /package/{src/lib/class-validator/index.ts → lib/class-validator/index.d.ts} +0 -0
  169. /package/{src/lib/devtools/components/query-devtools/index.ts → lib/devtools/components/query-devtools/index.d.ts} +0 -0
  170. /package/{src/lib/devtools/pipes/index.ts → lib/devtools/pipes/index.d.ts} +0 -0
  171. /package/{src/lib/devtools/utils/index.ts → lib/devtools/utils/index.d.ts} +0 -0
  172. /package/{src/lib/directives/index.ts → lib/directives/index.d.ts} +0 -0
  173. /package/{src/lib/entity/index.ts → lib/entity/index.d.ts} +0 -0
  174. /package/{src/lib/gql/index.ts → lib/gql/index.d.ts} +0 -0
  175. /package/{src/lib/infinite-query/index.ts → lib/infinite-query/index.d.ts} +0 -0
  176. /package/{src/lib/logger/index.ts → lib/logger/index.d.ts} +0 -0
  177. /package/{src/lib/query/index.ts → lib/query/index.d.ts} +0 -0
  178. /package/{src/lib/query-client/index.ts → lib/query-client/index.d.ts} +0 -0
  179. /package/{src/lib/query-creator/index.ts → lib/query-creator/index.d.ts} +0 -0
  180. /package/{src/lib/query-form/index.ts → lib/query-form/index.d.ts} +0 -0
  181. /package/{src/lib/query-store/index.ts → lib/query-store/index.d.ts} +0 -0
  182. /package/{src/lib/request/index.ts → lib/request/index.d.ts} +0 -0
  183. /package/{src/lib/symfony/index.ts → lib/symfony/index.d.ts} +0 -0
  184. /package/{src/lib/utils/index.ts → lib/utils/index.d.ts} +0 -0
@@ -1,245 +0,0 @@
1
- import { BehaviorSubject, Observable, combineLatest, map, of, shareReplay, switchMap, tap } from 'rxjs';
2
- import { filterSuccess } from '../query';
3
- import { AnyQueryCreator, ConstructQuery, QueryArgsOf, QueryDataOf } from '../query-creator';
4
- import { InfinityQueryConfig, InfinityQueryParamLocation } from './infinity-query.types';
5
-
6
- export class InfinityQuery<
7
- QueryCreator extends AnyQueryCreator,
8
- Query extends ConstructQuery<QueryCreator>,
9
- Args extends QueryArgsOf<QueryCreator>,
10
- QueryResponse extends QueryDataOf<QueryCreator>,
11
- InfinityResponse extends unknown[],
12
- > {
13
- private readonly _queries$ = new BehaviorSubject<Query[]>([]);
14
- private readonly _currentPage$ = new BehaviorSubject<number | null>(null);
15
- private readonly _currentCalculatedPage$ = new BehaviorSubject<number | null>(null);
16
- private readonly _totalPages$ = new BehaviorSubject<number | null>(null);
17
- private readonly _itemsPerPage$ = new BehaviorSubject<number>(this._config.limitParam?.value ?? 10);
18
-
19
- private readonly _data$ = this._queries$.pipe(
20
- switchMap((queries) => {
21
- if (!queries.length) {
22
- return of([]);
23
- }
24
-
25
- return combineLatest(
26
- queries.map((query) =>
27
- query.state$.pipe(
28
- filterSuccess(),
29
- map((state) => ({ state, query })),
30
- ),
31
- ),
32
- );
33
- }),
34
- tap((stateMaps) => {
35
- const lastState = stateMaps[stateMaps.length - 1]?.state;
36
- const lastQuery = stateMaps[stateMaps.length - 1]?.query;
37
-
38
- if (!lastState || !lastQuery) {
39
- return;
40
- }
41
-
42
- const totalPages =
43
- this._config.response.totalPagesExtractor?.({
44
- response: lastState.response as QueryResponse,
45
- itemsPerPage: this.itemsPerPage,
46
- args: lastQuery._arguments,
47
- }) ??
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- (lastState.response as any)?.totalPages ??
50
- null;
51
-
52
- this._totalPages$.next(totalPages);
53
- }),
54
- map((stateMaps) => {
55
- if (!stateMaps.length) {
56
- return null;
57
- }
58
-
59
- const fullData = stateMaps.reduce(
60
- (acc, stateMap) => {
61
- const valExtractFn = this._config?.response?.valueExtractor;
62
- let data = valExtractFn
63
- ? valExtractFn?.(stateMap.state.response as QueryResponse)
64
- : (stateMap.state.response as InfinityResponse);
65
-
66
- if (this._config.response.reverse) {
67
- data = [...data].reverse() as InfinityResponse;
68
- }
69
-
70
- if (this._config.response.appendItemsTo === 'start') {
71
- acc.unshift(...data);
72
- } else {
73
- acc.push(...data);
74
- }
75
- return acc;
76
- },
77
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
- [] as any as InfinityResponse,
79
- );
80
-
81
- return fullData;
82
- }),
83
- shareReplay({ bufferSize: 1, refCount: true }),
84
- );
85
-
86
- private readonly _lastQuery$ = this._queries$.pipe(
87
- map((queries) => queries[queries.length - 1] ?? null),
88
- shareReplay({ bufferSize: 1, refCount: true }),
89
- );
90
-
91
- get currentPage$() {
92
- return this._currentPage$.asObservable();
93
- }
94
-
95
- get currentPage() {
96
- return this._currentPage$.getValue();
97
- }
98
-
99
- get currentCalculatedPage$() {
100
- return this._currentCalculatedPage$.asObservable();
101
- }
102
-
103
- get currentCalculatedPage() {
104
- return this._currentCalculatedPage$.getValue();
105
- }
106
-
107
- get totalPages$() {
108
- return this._totalPages$.asObservable();
109
- }
110
-
111
- get totalPages() {
112
- return this._totalPages$.getValue();
113
- }
114
-
115
- get itemsPerPage$() {
116
- return this._itemsPerPage$.asObservable();
117
- }
118
-
119
- get itemsPerPage() {
120
- return this._itemsPerPage$.getValue();
121
- }
122
-
123
- get data$() {
124
- return this._data$;
125
- }
126
-
127
- get currentQuery$() {
128
- return this._lastQuery$;
129
- }
130
-
131
- constructor(
132
- private _config: InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>,
133
- private _destroy$: Observable<boolean>,
134
- ) {}
135
-
136
- nextPage() {
137
- const newPage = (this._currentPage$.value ?? 0) + 1;
138
- const calculatedPage =
139
- this._config?.pageParam?.valueCalculator?.({
140
- page: newPage,
141
- totalPages: this.totalPages,
142
- itemsPerPage: this.itemsPerPage,
143
- }) ?? newPage;
144
-
145
- if (this.totalPages !== null && newPage > this.totalPages) {
146
- console.error(
147
- 'Cannot load more pages, already at the end. Make sure to not render the infinity query trigger using *ngIf canLoadMore',
148
- );
149
- return;
150
- }
151
-
152
- const args = this._prepareArgs(this._config, calculatedPage);
153
-
154
- const query = this._config.queryCreator.prepare(args).execute() as Query;
155
-
156
- if (this._config.pollingInterval) {
157
- query.poll({ interval: this._config.pollingInterval, takeUntil: this._destroy$ });
158
- }
159
-
160
- this._queries$.next([...this._queries$.value, query]);
161
-
162
- this._currentPage$.next(newPage);
163
- this._currentCalculatedPage$.next(calculatedPage);
164
- }
165
-
166
- reset(
167
- newConfig?: Omit<
168
- InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>,
169
- 'queryCreator' | 'response'
170
- >,
171
- ) {
172
- this._config = { ...this._config, ...(newConfig ?? {}) };
173
-
174
- this._currentPage$.next(null);
175
- this._currentCalculatedPage$.next(null);
176
- this._totalPages$.next(null);
177
- this._itemsPerPage$.next(this._config.limitParam?.value ?? 10);
178
- this._queries$.next([]);
179
-
180
- this.nextPage();
181
- }
182
-
183
- private _prepareArgs(config: InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>, page: number) {
184
- const pageParamLocation = this._getPageParamLocation(config?.pageParam?.location);
185
-
186
- const pageArgs = {
187
- [pageParamLocation]: {
188
- [config?.pageParam?.key ?? 'page']: page,
189
- },
190
- };
191
-
192
- const limitParamLocation = this._getPageParamLocation(config?.limitParam?.location);
193
-
194
- const limitArgs = {
195
- [limitParamLocation]: {
196
- [config?.limitParam?.key ?? 'limit']: config?.limitParam?.value ?? 10,
197
- },
198
- };
199
-
200
- const defaultConfig = config?.defaultArgs ?? {};
201
-
202
- const mergedArgs =
203
- pageParamLocation === limitParamLocation
204
- ? {
205
- ...defaultConfig,
206
- [pageParamLocation]: {
207
- ...(config?.defaultArgs?.[pageParamLocation] ?? {}),
208
- ...pageArgs[limitParamLocation],
209
- ...limitArgs[limitParamLocation],
210
- },
211
- }
212
- : {
213
- ...defaultConfig,
214
- [pageParamLocation]: {
215
- ...(config?.defaultArgs?.[pageParamLocation] ?? {}),
216
- ...pageArgs[pageParamLocation],
217
- },
218
- [limitParamLocation]: {
219
- ...(config?.defaultArgs?.[limitParamLocation] ?? {}),
220
- ...limitArgs[limitParamLocation],
221
- },
222
- };
223
-
224
- return mergedArgs;
225
- }
226
-
227
- private _getPageParamLocation(location: InfinityQueryParamLocation | undefined) {
228
- const loc = location ?? 'query';
229
-
230
- switch (loc) {
231
- case 'path':
232
- return 'pathParams';
233
- case 'query':
234
- return 'queryParams';
235
- case 'body':
236
- return 'body';
237
- case 'header':
238
- return 'headers';
239
- case 'variable':
240
- return 'variables';
241
- default:
242
- throw new Error(`Invalid pageParamLocation: ${loc}`);
243
- }
244
- }
245
- }
@@ -1,149 +0,0 @@
1
- import { BaseArguments, WithHeaders } from '../query';
2
- import { AnyQueryCreator, ConstructQuery, QueryArgsOf, QueryDataOf } from '../query-creator';
3
- import { InfinityQuery } from './infinity-query';
4
-
5
- export type InfinityQueryParamLocation = 'path' | 'query' | 'body' | 'header' | 'variable';
6
-
7
- export type AppendItemsLocation = 'start' | 'end';
8
-
9
- export interface PageParamCalculatorOptions {
10
- page: number;
11
- totalPages: number | null;
12
- itemsPerPage: number;
13
- }
14
-
15
- export interface TotalPagesExtractorOptions<Arguments extends BaseArguments | undefined, QueryResponse> {
16
- response: QueryResponse;
17
- itemsPerPage: number;
18
- args: Arguments;
19
- }
20
-
21
- export interface InfinityQueryConfig<
22
- QueryCreator extends AnyQueryCreator,
23
- Arguments extends BaseArguments | undefined,
24
- QueryResponse,
25
- InfinityResponse extends unknown[],
26
- > {
27
- /**
28
- * The query creator to use for fetching pages.
29
- */
30
- queryCreator: QueryCreator;
31
-
32
- /**
33
- * The interval in milliseconds to poll on. If not provided, polling will be disabled.
34
- * @default undefined
35
- */
36
- pollingInterval?: number;
37
-
38
- /**
39
- * The args that will be merged with the page arg.
40
- */
41
- defaultArgs?: Arguments & WithHeaders;
42
-
43
- pageParam?: {
44
- /**
45
- * The location where the page param is in request.
46
- *
47
- * @default "query"
48
- */
49
- location?: InfinityQueryParamLocation;
50
-
51
- /**
52
- * Used as page param name.
53
- *
54
- * @default "page"
55
- */
56
- key?: string;
57
-
58
- /**
59
- * A function that calculates the page value for the next request.
60
- * E.g. if the pagination is done with a `skip` param, the `pageParamName` should be `skip` and this function should return the correct value.
61
- */
62
- valueCalculator?: (data: PageParamCalculatorOptions) => number;
63
- };
64
-
65
- limitParam?: {
66
- /**
67
- * The location where the limit param is in request.
68
- *
69
- * @default "query"
70
- */
71
- location?: InfinityQueryParamLocation;
72
-
73
- /**
74
- * Used as limit param name.
75
- *
76
- * @default "limit"
77
- */
78
- key?: string;
79
-
80
- /**
81
- * The value of the limit param.
82
- *
83
- * @default 10
84
- */
85
- value?: number;
86
- };
87
-
88
- response: {
89
- /**
90
- * Determines if the response should get reversed before appending to the data array.
91
- *
92
- * @default false
93
- */
94
- reverse?: boolean;
95
-
96
- /**
97
- * Determines where to put the new items in the data array.
98
- *
99
- * @default "end"
100
- */
101
- appendItemsTo?: AppendItemsLocation;
102
-
103
- /**
104
- * The type of the array that will be created by the infinite query.
105
- */
106
- arrayType: InfinityResponse;
107
-
108
- /**
109
- * A function that returns the data array from the response.
110
- * This function should return the type provided in `responseArrayType`.
111
- */
112
- valueExtractor?: (response: QueryResponse) => InfinityResponse;
113
-
114
- /**
115
- * The property in the response that contains the total page count.
116
- *
117
- * @default "totalPages"
118
- */
119
- totalPagesExtractor?: (
120
- data: TotalPagesExtractorOptions<QueryArgsOf<QueryCreator> & WithHeaders, QueryResponse>,
121
- ) => number;
122
- };
123
- }
124
-
125
- type OmitUndefined<T> = T extends undefined ? never : T;
126
-
127
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
- export type AnyInfinityQueryConfig = InfinityQueryConfig<any, any, any, any>;
129
-
130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
- export type AnyInfinityQuery = InfinityQuery<any, any, any, any, any>;
132
-
133
- export type InfinityQueryConfigType<
134
- QueryCreator extends AnyQueryCreator,
135
- InfinityResponse extends unknown[],
136
- > = InfinityQueryConfig<
137
- QueryCreator,
138
- OmitUndefined<QueryArgsOf<QueryCreator>>,
139
- QueryDataOf<QueryCreator>,
140
- InfinityResponse
141
- >;
142
-
143
- export type InfinityQueryOf<Cfg extends AnyInfinityQueryConfig | null> = InfinityQuery<
144
- NonNullable<Cfg>['queryCreator'],
145
- ConstructQuery<NonNullable<Cfg>['queryCreator']>,
146
- QueryArgsOf<NonNullable<Cfg>['queryCreator']>,
147
- QueryDataOf<NonNullable<Cfg>['queryCreator']>,
148
- NonNullable<Cfg>['response']['arrayType']
149
- >;
@@ -1,14 +0,0 @@
1
- import { AnyQueryCreator, QueryArgsOf, QueryDataOf } from '../query-creator';
2
- import { InfinityQueryConfig, PageParamCalculatorOptions } from './infinity-query.types';
3
-
4
- export const createInfinityQueryConfig = <
5
- QueryCreator extends AnyQueryCreator,
6
- Args extends QueryArgsOf<QueryCreator>,
7
- QueryResponse extends QueryDataOf<QueryCreator>,
8
- InfinityResponse extends unknown[],
9
- >(
10
- config: InfinityQueryConfig<QueryCreator, Args, QueryResponse, InfinityResponse>,
11
- ) => config;
12
-
13
- export const skipPaginationPageParamCalculator = ({ page, itemsPerPage }: PageParamCalculatorOptions) =>
14
- itemsPerPage * (page - 1);
@@ -1,30 +0,0 @@
1
- export const buildErrorMessage = (code: string, message: string) => `[@ethlete\\query:${code}] ${message}`;
2
-
3
- export class QueryError extends Error {
4
- data?: unknown;
5
-
6
- constructor(code: string, message: string, data?: unknown) {
7
- super(buildErrorMessage(code, message));
8
- this.name = 'QueryError';
9
- this.data = data;
10
- }
11
- }
12
-
13
- export const invalidBaseRouteError = (data: unknown) =>
14
- new QueryError('001', 'The baseRoute must not end with a slash', data);
15
-
16
- export const invalidRouteError = (data: unknown) => new QueryError('002', 'The route must start with a slash', data);
17
-
18
- export const pathParamsMissingInRouteFunctionError = (data: unknown) =>
19
- new QueryError('003', 'The route is a function but pathParams are missing', data);
20
-
21
- export const queryStateAlreadyHasKeyError = (data: unknown) =>
22
- new QueryError('004', 'The query state already contains the provided key', data);
23
-
24
- export const queryStateDoesNotContainKeyError = (data: unknown) =>
25
- new QueryError('005', 'The query state does not contain the provided key', data);
26
-
27
- export const queryStateCannotTransformError = (data: unknown) =>
28
- new QueryError('006', 'The query state cannot be transformed because it is not loading', data);
29
-
30
- export const invalidBodyError = (data: unknown) => new QueryError('007', 'The body is not valid or upsupported', data);