@ethlete/query 3.0.4 → 4.0.1

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.
package/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from './lib/query-creator';
10
10
  export * from './lib/query-form';
11
11
  export * from './lib/query-store';
12
12
  export * from './lib/request';
13
+ export * from './lib/symfony';
13
14
  export * from './lib/utils';
@@ -1,6 +1,7 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { EntityStore } from '../entity';
3
3
  import { AnyQueryCreator, ConstructQuery, QueryDataOf, QueryResponseOf } from '../query-creator';
4
+ import { QueryForm } from '../query-form';
4
5
  import { Method, PathParams, QueryParams, RequestError, RequestProgress } from '../request';
5
6
  import { Query } from './query';
6
7
  export interface QueryAutoRefreshConfig {
@@ -287,3 +288,14 @@ export type AnyQueryCollection = QueryCollectionOf<AnyQueryCreatorCollection>;
287
288
  export type QueryOf<T extends AnyQueryCollection | AnyQuery | null> = T extends AnyQuery ? T : T extends AnyQueryCollection ? T['query'] : never;
288
289
  export type AnyQueryCollectionResponse<T extends AnyQueryCollection> = QueryResponseOf<T['query']>;
289
290
  export type AnyQueryCollectionData<T extends AnyQueryCollection> = QueryDataOf<T['query']>;
291
+ export interface ResetPageOnErrorOperatorConfig<J extends QueryForm<any>> {
292
+ /**
293
+ * The query form to reset the page of.
294
+ */
295
+ queryForm: J;
296
+ /**
297
+ * The key of the page control in the query form.
298
+ * @default 'page'
299
+ */
300
+ pageControlKey?: string;
301
+ }
@@ -3,8 +3,9 @@ import { BehaviorSubject, Observable } from 'rxjs';
3
3
  import { EntityStore } from '../entity';
4
4
  import { QueryClient } from '../query-client';
5
5
  import { AnyQueryCreator, QueryArgsOf, QueryCreator, QueryDataOf, QueryResponseOf, QueryStoreIdOf, QueryStoreOf } from '../query-creator';
6
+ import { QueryForm } from '../query-form';
6
7
  import { Method, RequestHeaders, RequestHeadersMethodMap } from '../request';
7
- import { AnyGqlQueryConfig, AnyQuery, AnyQueryCreatorCollection, AnyRestQueryConfig, BaseArguments, Cancelled, Failure, GqlQueryConfig, Loading, Prepared, QueryCollectionOf, QueryState, QueryStateResponseOf, QueryStateType, RouteType, Success } from './query.types';
8
+ import { AnyGqlQueryConfig, AnyQuery, AnyQueryCreatorCollection, AnyRestQueryConfig, BaseArguments, Cancelled, Failure, GqlQueryConfig, Loading, Prepared, QueryCollectionOf, QueryState, QueryStateResponseOf, QueryStateType, ResetPageOnErrorOperatorConfig, RouteType, Success } from './query.types';
8
9
  type OmitNull<T> = T extends null ? never : T;
9
10
  export declare function filterSuccess(): <T extends QueryState<unknown> | null, Response_1 extends QueryStateResponseOf<OmitNull<T>>>(source: Observable<T>) => Observable<Success<Response_1>>;
10
11
  export declare function ignoreAutoRefresh(): <T extends QueryState<unknown> | null>(source: Observable<T>) => Observable<T>;
@@ -19,6 +20,7 @@ export declare function switchQueryCollectionState(): <T extends {
19
20
  type: string;
20
21
  query: import("@ethlete/query").Query<any, any, any, any, any, any>;
21
22
  } | null, Data extends QueryDataOf<OmitNull<T>["query"]>>(source: Observable<T>) => Observable<QueryState<Data> | null>;
23
+ export declare const resetPageOnError: <T extends AnyQuery | null | undefined, J extends QueryForm<any>>(config: ResetPageOnErrorOperatorConfig<J>) => (source: Observable<T>) => Observable<T | QueryState<any>>;
22
24
  export declare const isQueryStateLoading: (state: QueryState | null | undefined) => state is Loading;
23
25
  export declare const isQueryStateSuccess: (state: QueryState | null | undefined) => state is Success<unknown>;
24
26
  export declare const isQueryStateFailure: (state: QueryState | null | undefined) => state is Failure;
@@ -1,6 +1,6 @@
1
1
  import { FormGroup } from '@angular/forms';
2
2
  import { Observable } from 'rxjs';
3
- import { QueryFieldOptions, QueryFormGroup, QueryFormValue } from './query-form.types';
3
+ import { QueryFieldOptions, QueryFormGroup, QueryFormObserveOptions, QueryFormValue } from './query-form.types';
4
4
  export declare class QueryField<T> {
5
5
  data: QueryFieldOptions<T>;
6
6
  changes$: Observable<T | null>;
@@ -19,9 +19,10 @@ export declare class QueryForm<T extends Record<string, QueryField<any>>> {
19
19
  private _defaultValues;
20
20
  form: FormGroup<QueryFormGroup<T>>;
21
21
  constructor(_fields: T);
22
- observe(options?: {
23
- syncViaUrlQueryParams?: boolean;
24
- }): Observable<QueryFormValue<T>>;
22
+ observe(options?: QueryFormObserveOptions): Observable<{
23
+ previousValue: QueryFormValue<T>;
24
+ currentValue: QueryFormValue<T>;
25
+ }>;
25
26
  setFormValueFromUrlQueryParams(options?: {
26
27
  skipDebounce?: boolean;
27
28
  }): void;
@@ -21,6 +21,14 @@ export interface QueryFieldOptions<T = unknown> {
21
21
  * @default true
22
22
  */
23
23
  appendToUrl?: boolean;
24
+ /**
25
+ * Reset the field's value to the default value if one or more of the specified fields are changed.
26
+ *
27
+ * @example
28
+ * // Given this field is a `page` field, the field will be reset if the `limit`, `query` or `search` fields are changed.
29
+ * ['limit', 'query', 'search']
30
+ */
31
+ isResetBy?: string | string[];
24
32
  /**
25
33
  * A function that transforms the the value gotten from the url query params to a value required by the field.
26
34
  * E.g. for a number field, the value from the url query params is a string, but the field requires a number.
@@ -51,3 +59,9 @@ export type QueryFormGroup<T extends Record<string, QueryField<any>>> = {
51
59
  export type QueryFormValue<T extends Record<string, QueryField<any>>> = {
52
60
  [Property in keyof T]: T[Property]['control']['value'];
53
61
  };
62
+ export interface QueryFormObserveOptions {
63
+ /**
64
+ * Whether the form value should be synced to the url query params.
65
+ */
66
+ syncViaUrlQueryParams?: boolean;
67
+ }
@@ -8,6 +8,6 @@ export declare const transformToDate: (value: unknown) => Date | null;
8
8
  export declare const transformToDateArray: (value: unknown) => Date[] | null;
9
9
  export declare const transformToSort: (value: unknown) => {
10
10
  active: string;
11
- direction: "desc" | "asc";
11
+ direction: "asc" | "desc";
12
12
  } | null;
13
13
  export declare const transformToSortQueryParam: (value: unknown) => string | null;
@@ -0,0 +1,2 @@
1
+ export * from './symfony.types';
2
+ export * from './symfony.utils';
@@ -0,0 +1,19 @@
1
+ import { HttpStatusCode } from '../request';
2
+ export interface SymfonyErrorTrace {
3
+ args: string[];
4
+ class: string;
5
+ file: string;
6
+ function: string;
7
+ line: number;
8
+ namespace: string;
9
+ short_class: string;
10
+ type: string;
11
+ }
12
+ export interface SymfonyError {
13
+ class: string;
14
+ detail: string;
15
+ status: HttpStatusCode;
16
+ title: string;
17
+ trace: SymfonyErrorTrace[];
18
+ type: string;
19
+ }
@@ -0,0 +1,3 @@
1
+ import { SymfonyError } from './symfony.types';
2
+ export declare const isSymfonyError: (error: unknown) => error is SymfonyError;
3
+ export declare const isSymfonyPagerfantaOutOfRangeError: (error: unknown) => error is SymfonyError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/query",
3
- "version": "3.0.4",
3
+ "version": "4.0.1",
4
4
  "dependencies": {
5
5
  "tslib": "^2.5.0"
6
6
  },