fastapi-rtk 2.5.1 → 2.6.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.
@@ -1,12 +1,13 @@
1
1
  import { SafeContextOptions } from 'fastapi-rtk/utils';
2
2
  import { ApiContextValue, ApiTypeOverrides, EntryRow, UseApiResult } from './types';
3
- export declare const ApiContextProvider: import('react').Provider<ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow> | null>, useApiProvider: (options?: SafeContextOptions<ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow>>) => ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow>;
3
+ export declare const ApiContextProvider: import('react').Provider<ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, object> | null>, useApiProvider: (options?: SafeContextOptions<ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, object>>) => ApiContextValue<import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, import('fastapi-rtk/api-types').ResultRow, object>;
4
4
  /**
5
5
  * Access the API context.
6
6
  *
7
7
  * @typeParam TDefault - Uniform row/payload type applied to every operation. Defaults to the dynamic `EntryRow`.
8
8
  * @typeParam TOverrides - Per-operation overrides (`list` / `get` / `add` / `edit`); each replaces `TDefault` for that operation only.
9
+ * @typeParam TQuery - Custom query-param keys forwarded to the backend, surfaced typed on `queryParams` / `setQueryParams`.
9
10
  * @param options - Options for the context hook.
10
11
  * @returns The API context object, with `data`, `getEntry`, `addEntry`, `updateEntry`, etc. typed per operation.
11
12
  */
12
- export declare const useApi: <TDefault = EntryRow, TOverrides extends ApiTypeOverrides = ApiTypeOverrides>(options?: SafeContextOptions<UseApiResult<TDefault, TOverrides>>) => UseApiResult<TDefault, TOverrides>;
13
+ export declare const useApi: <TDefault = EntryRow, TOverrides extends ApiTypeOverrides = ApiTypeOverrides, TQuery extends object = object>(options?: SafeContextOptions<UseApiResult<TDefault, TOverrides, TQuery>>) => UseApiResult<TDefault, TOverrides, TQuery>;
@@ -121,8 +121,9 @@ export type OpType<TOverrides extends ApiTypeOverrides, K extends keyof ApiTypeO
121
121
  * @typeParam TGet - Shape of a single fetched/affected record (`getEntry`, and the record returned by `addEntry` / `updateEntry`).
122
122
  * @typeParam TAdd - Payload accepted by `addEntry`.
123
123
  * @typeParam TEdit - Payload accepted by `updateEntry`.
124
+ * @typeParam TQuery - Custom query-param keys forwarded to the backend, intersected onto `queryParams` and `setQueryParams`.
124
125
  */
125
- export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = EntryRow, TEdit = EntryRow> {
126
+ export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = EntryRow, TEdit = EntryRow, TQuery extends object = object> {
126
127
  /** The API path. */
127
128
  path: string;
128
129
  /** Information about the API, including schemas, UI schemas, and the normalized add/edit form blocks. */
@@ -130,7 +131,7 @@ export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = Entry
130
131
  /** The data returned by the API. */
131
132
  data?: APIData<TList>;
132
133
  /** The query parameters used in the API request. */
133
- queryParams?: APIQueryParams;
134
+ queryParams?: APIQueryParams & TQuery;
134
135
  /** Indicates whether the API request is currently loading. */
135
136
  loading: boolean;
136
137
  /** Indicates whether the API info request is currently loading. */
@@ -154,7 +155,7 @@ export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = Entry
154
155
  /** An object containing special keys for the API query, such as 'all' and 'actions'. */
155
156
  specialKey: APISpecialKey;
156
157
  /** A function to update the query parameters. */
157
- setQueryParams: (partialQueryParams: Partial<APIQueryParams> | ((prev: APIQueryParams) => Partial<APIQueryParams>)) => void;
158
+ setQueryParams: (partialQueryParams: Partial<APIQueryParams & TQuery> | ((prev: APIQueryParams & TQuery) => Partial<APIQueryParams & TQuery>)) => void;
158
159
  /** A function to refetch the data from the API. */
159
160
  refetch: (options?: {
160
161
  force?: boolean;
@@ -185,7 +186,7 @@ export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = Entry
185
186
  resetError: () => void;
186
187
  }
187
188
  /**
188
- * The `ApiContextValue` returned by `useApi<TDefault, TOverrides>`: the uniform `TDefault` applied to
189
- * every operation, with any `TOverrides` keys replacing it per operation.
189
+ * The `ApiContextValue` returned by `useApi<TDefault, TOverrides, TQuery>`: the uniform `TDefault` applied to
190
+ * every operation, with any `TOverrides` keys replacing it per operation, and `TQuery` adding custom query-param keys.
190
191
  */
191
- export type UseApiResult<TDefault = EntryRow, TOverrides extends ApiTypeOverrides = ApiTypeOverrides> = ApiContextValue<OpType<TOverrides, 'list', TDefault>, OpType<TOverrides, 'get', TDefault>, OpType<TOverrides, 'add', TDefault>, OpType<TOverrides, 'edit', TDefault>>;
192
+ export type UseApiResult<TDefault = EntryRow, TOverrides extends ApiTypeOverrides = ApiTypeOverrides, TQuery extends object = object> = ApiContextValue<OpType<TOverrides, 'list', TDefault>, OpType<TOverrides, 'get', TDefault>, OpType<TOverrides, 'add', TDefault>, OpType<TOverrides, 'edit', TDefault>, TQuery>;
@@ -3,7 +3,7 @@ import { ApiProviderProps, WithApiProviderOptions } from './types';
3
3
  /**
4
4
  * Provides the API context, bulk actions context, and form contexts to its children.
5
5
  */
6
- export declare function ApiProvider(props: ApiProviderProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function ApiProvider<TQuery extends object = object>(props: ApiProviderProps<TQuery>): import("react/jsx-runtime").JSX.Element;
7
7
  /**
8
8
  * Higher-order component to wrap a component with ApiProvider.
9
9
  *
@@ -3,12 +3,18 @@ import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseQueryOptions } from
3
3
  import { PropsWithChildren } from 'react';
4
4
  import { InfoQueryData, RelationParam } from './hooks/types';
5
5
  import { QueryParams } from './utils/types';
6
- /** Props accepted by the `ApiProvider` component. */
7
- export type ApiProviderProps = PropsWithChildren<{
6
+ /**
7
+ * Props accepted by the `ApiProvider` component.
8
+ *
9
+ * @typeParam TQuery - Custom query-param keys forwarded to the backend (read off `request.query_params`).
10
+ * Surfaced typed on `initialQueryParams`; pass the same shape to `useApi<…, TQuery>()` to type `queryParams` /
11
+ * `setQueryParams` (React context cannot carry the Provider's type param to a distant `useApi` call).
12
+ */
13
+ export type ApiProviderProps<TQuery extends object = object> = PropsWithChildren<{
8
14
  /** The name of the resource to be used in the API path. */
9
15
  resource_name?: string;
10
- /** The initial query parameters to be used in the API requests. */
11
- initialQueryParams?: QueryParams;
16
+ /** The initial query parameters to be used in the API requests. May include custom keys (typed via `TQuery`) forwarded to the backend. */
17
+ initialQueryParams?: QueryParams & Partial<TQuery>;
12
18
  /** The relation to be used in the API requests. */
13
19
  relation?: RelationParam;
14
20
  /** Whether to fetch the `info` for the API requests when the component mounts. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastapi-rtk",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "description": "A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.",
6
6
  "license": "MIT",