fastapi-rtk 2.4.1 → 2.5.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.
- package/dist/.bundled/jsonforms/cjs/_virtual/index11.cjs +2 -2
- package/dist/.bundled/jsonforms/cjs/_virtual/index12.cjs +2 -2
- package/dist/.bundled/jsonforms/esm/_virtual/index11.mjs +2 -2
- package/dist/.bundled/jsonforms/esm/_virtual/index12.mjs +2 -2
- package/dist/.external/cjs/fast-uri@3.1.0/fast-uri/index.cjs +1 -1
- package/dist/.external/cjs/json-schema-traverse@1.0.0/json-schema-traverse/index.cjs +1 -1
- package/dist/.external/esm/fast-uri@3.1.0/fast-uri/index.mjs +1 -1
- package/dist/.external/esm/json-schema-traverse@1.0.0/json-schema-traverse/index.mjs +1 -1
- package/dist/contexts/cjs/ApiContext/ApiContext.cjs +4 -1
- package/dist/contexts/esm/ApiContext/ApiContext.mjs +4 -1
- package/dist/contexts/lib/ApiContext/ApiContext.d.ts +6 -4
- package/dist/contexts/lib/ApiContext/types.d.ts +50 -25
- package/dist/core/cjs/Menu/UserMenu/UserMenu.cjs +2 -2
- package/dist/core/cjs/Wrappers/ApiProvider/hooks/useProvideApi.cjs +1 -1
- package/dist/core/esm/Menu/UserMenu/UserMenu.mjs +1 -1
- package/dist/core/esm/Wrappers/ApiProvider/hooks/useProvideApi.mjs +1 -1
- package/dist/core/lib/Dialogs/types.d.ts +2 -2
- package/dist/core/lib/Wrappers/ApiProvider/hooks/utils/useApiActions.d.ts +2 -2
- package/dist/core/lib/Wrappers/ApiProvider/utils/api/deleteItem.d.ts +1 -1
- package/dist/core/lib/Wrappers/ApiProvider/utils/api/getInfo.d.ts +1 -1
- package/dist/core/lib/Wrappers/ApiProvider/utils/api/getItems.d.ts +1 -1
- package/dist/core/lib/Wrappers/ApiProvider/utils/api/types.d.ts +2 -2
- package/dist/core/lib/fab-react-toolkit-patch/api/utils/api/getItems.d.ts +1 -1
- package/dist/utils/cjs/createFetchParams/createFetchParams.cjs +2 -2
- package/dist/utils/cjs/parseResponse/parseResponse.cjs +3 -0
- package/dist/utils/esm/createFetchParams/createFetchParams.mjs +1 -1
- package/dist/utils/esm/parseResponse/parseResponse.mjs +3 -0
- package/dist/utils/lib/parseResponse/parseResponse.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const index = require("../../../../.bundled/jsonforms/cjs/_virtual/
|
|
3
|
+
const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index12.cjs");
|
|
4
4
|
const utils = require("./lib/utils.cjs");
|
|
5
5
|
const schemes = require("./lib/schemes.cjs");
|
|
6
6
|
var hasRequiredFastUri;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const index = require("../../../../.bundled/jsonforms/cjs/_virtual/
|
|
3
|
+
const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index11.cjs");
|
|
4
4
|
var hasRequiredJsonSchemaTraverse;
|
|
5
5
|
function requireJsonSchemaTraverse() {
|
|
6
6
|
if (hasRequiredJsonSchemaTraverse) return index.__module.exports;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __module as fastUri } from "../../../../.bundled/jsonforms/esm/_virtual/
|
|
1
|
+
import { __module as fastUri } from "../../../../.bundled/jsonforms/esm/_virtual/index12.mjs";
|
|
2
2
|
import { __require as requireUtils } from "./lib/utils.mjs";
|
|
3
3
|
import { __require as requireSchemes } from "./lib/schemes.mjs";
|
|
4
4
|
var hasRequiredFastUri;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __module as jsonSchemaTraverse } from "../../../../.bundled/jsonforms/esm/_virtual/
|
|
1
|
+
import { __module as jsonSchemaTraverse } from "../../../../.bundled/jsonforms/esm/_virtual/index11.mjs";
|
|
2
2
|
var hasRequiredJsonSchemaTraverse;
|
|
3
3
|
function requireJsonSchemaTraverse() {
|
|
4
4
|
if (hasRequiredJsonSchemaTraverse) return jsonSchemaTraverse.exports;
|
|
@@ -4,7 +4,10 @@ const utils = require("fastapi-rtk/utils");
|
|
|
4
4
|
const [ApiContextProvider, useApiProvider] = utils.createSafeContext(
|
|
5
5
|
"useApi must be used within an ApiProvider"
|
|
6
6
|
);
|
|
7
|
-
const useApi = (options) =>
|
|
7
|
+
const useApi = (options) => (
|
|
8
|
+
// #MUSTASSERT #MUSTUNKNOWN the provider stores one untyped runtime value; the per-operation type params are a compile-time view of the same rows, so the resolved conditional types don't structurally overlap the fixed provider type
|
|
9
|
+
useApiProvider(options)
|
|
10
|
+
);
|
|
8
11
|
exports.ApiContextProvider = ApiContextProvider;
|
|
9
12
|
exports.useApi = useApi;
|
|
10
13
|
exports.useApiProvider = useApiProvider;
|
|
@@ -2,7 +2,10 @@ import { createSafeContext } from "fastapi-rtk/utils";
|
|
|
2
2
|
const [ApiContextProvider, useApiProvider] = createSafeContext(
|
|
3
3
|
"useApi must be used within an ApiProvider"
|
|
4
4
|
);
|
|
5
|
-
const useApi = (options) =>
|
|
5
|
+
const useApi = (options) => (
|
|
6
|
+
// #MUSTASSERT #MUSTUNKNOWN the provider stores one untyped runtime value; the per-operation type params are a compile-time view of the same rows, so the resolved conditional types don't structurally overlap the fixed provider type
|
|
7
|
+
useApiProvider(options)
|
|
8
|
+
);
|
|
6
9
|
export {
|
|
7
10
|
ApiContextProvider,
|
|
8
11
|
useApi,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SafeContextOptions } from 'fastapi-rtk/utils';
|
|
2
|
-
import { ApiContextValue } from './types';
|
|
3
|
-
export declare const ApiContextProvider: import('react').Provider<ApiContextValue | null>, useApiProvider: (options?: SafeContextOptions<ApiContextValue
|
|
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>;
|
|
4
4
|
/**
|
|
5
5
|
* Access the API context.
|
|
6
6
|
*
|
|
7
|
+
* @typeParam TDefault - Uniform row/payload type applied to every operation. Defaults to the dynamic `EntryRow`.
|
|
8
|
+
* @typeParam TOverrides - Per-operation overrides (`list` / `get` / `add` / `edit`); each replaces `TDefault` for that operation only.
|
|
7
9
|
* @param options - Options for the context hook.
|
|
8
|
-
* @returns The API context object.
|
|
10
|
+
* @returns The API context object, with `data`, `getEntry`, `addEntry`, `updateEntry`, etc. typed per operation.
|
|
9
11
|
*/
|
|
10
|
-
export declare const useApi: (options?: SafeContextOptions<
|
|
12
|
+
export declare const useApi: <TDefault = EntryRow, TOverrides extends ApiTypeOverrides = ApiTypeOverrides>(options?: SafeContextOptions<UseApiResult<TDefault, TOverrides>>) => UseApiResult<TDefault, TOverrides>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseResponseMany, BaseResponseSingle, ColumnFilterOperator, ColumnInfo, ColumnRelationInfo, ConvertedInfo, FilterInfo, InfoResponse, JsonSchema, Layout, PrimaryKey, QueryFilter, QueryParams } from 'fastapi-rtk/api-types';
|
|
2
2
|
import { InfiniteData, UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { Schema as ValidationSchema } from '../../../.external/lib/yup';
|
|
4
|
-
/** A non-null CRUD result row, mirroring the unwrapped `BaseResponseSingle.result`. */
|
|
5
|
-
type EntryRow = NonNullable<BaseResponseSingle['result']>;
|
|
4
|
+
/** A non-null CRUD result row, mirroring the unwrapped `BaseResponseSingle.result`. Default row type for the API generics. */
|
|
5
|
+
export type EntryRow = NonNullable<BaseResponseSingle['result']>;
|
|
6
6
|
export type APIColumnInfo = ColumnInfo;
|
|
7
7
|
export type APIColumnRelationInfo = ColumnRelationInfo;
|
|
8
8
|
export type APIColumnFilter = ColumnFilterOperator;
|
|
@@ -40,11 +40,11 @@ export type APIQueryParams = Required<Pick<QueryParams, 'page' | 'page_size' | '
|
|
|
40
40
|
* `BaseResponseMany`: `count` / `result` are guaranteed non-null after a successful fetch, and
|
|
41
41
|
* `path` / `queryParams` (the resolved `APIQueryParams`) are always present.
|
|
42
42
|
*/
|
|
43
|
-
export interface APIData extends Omit<BaseResponseMany, 'count' | 'result'> {
|
|
43
|
+
export interface APIData<TData = EntryRow> extends Omit<BaseResponseMany, 'count' | 'result'> {
|
|
44
44
|
/** The total count of items existing in the database for the given query parameters. */
|
|
45
45
|
count: number;
|
|
46
46
|
/** An array of objects representing the API response data. */
|
|
47
|
-
result:
|
|
47
|
+
result: TData[];
|
|
48
48
|
/** The API path. */
|
|
49
49
|
path: string;
|
|
50
50
|
/** The query parameters used in the API request. */
|
|
@@ -56,10 +56,10 @@ export interface APISpecialKey {
|
|
|
56
56
|
/** The key to be used when retrieving actions for `NextGenDataGrid`. Typically `actions`, but can be `_actions` if `actions` is in the list of columns. */
|
|
57
57
|
actions: string;
|
|
58
58
|
}
|
|
59
|
-
export interface APIStreaming {
|
|
59
|
+
export interface APIStreaming<TData = EntryRow> {
|
|
60
60
|
/** The streaming data, organized by the page number. */
|
|
61
61
|
data: {
|
|
62
|
-
[pageNumber: string]:
|
|
62
|
+
[pageNumber: string]: TData[];
|
|
63
63
|
};
|
|
64
64
|
/** Indicates whether the streaming has ended. */
|
|
65
65
|
isEnd: boolean;
|
|
@@ -86,10 +86,10 @@ export interface APIError {
|
|
|
86
86
|
message: string;
|
|
87
87
|
originalError: Error;
|
|
88
88
|
}
|
|
89
|
-
export interface APISetErrorPayload {
|
|
89
|
+
export interface APISetErrorPayload<TData = EntryRow> {
|
|
90
90
|
message: string;
|
|
91
91
|
originalError: Error;
|
|
92
|
-
data?:
|
|
92
|
+
data?: TData;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* `APIInfo` augmented with the normalized add/edit form blocks produced by
|
|
@@ -101,13 +101,34 @@ export interface APISetErrorPayload {
|
|
|
101
101
|
export type APIInfoCanonical = ConvertedInfo<ValidationSchema> & {
|
|
102
102
|
path?: string;
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Per-operation type overrides for `useApi`. Each key maps to a backend column projection and,
|
|
106
|
+
* when set, replaces the uniform default for that operation only: `list` (list response rows,
|
|
107
|
+
* `list_columns`), `get` (a single fetched entry and the record returned by `addEntry` / `updateEntry`,
|
|
108
|
+
* `show_columns`), `add` (the `addEntry` payload, `add_columns`), `edit` (the `updateEntry` payload,
|
|
109
|
+
* `edit_columns`). `upload` (`EntryRow[]`, loosely-typed import rows) and `deleteEntry` (`null`, the 204 no-content response) are not parameterized.
|
|
110
|
+
*/
|
|
111
|
+
export interface ApiTypeOverrides {
|
|
112
|
+
list?: unknown;
|
|
113
|
+
get?: unknown;
|
|
114
|
+
add?: unknown;
|
|
115
|
+
edit?: unknown;
|
|
116
|
+
}
|
|
117
|
+
/** Resolve one operation's type from the override map, falling back to `TDefault`. */
|
|
118
|
+
export type OpType<TOverrides extends ApiTypeOverrides, K extends keyof ApiTypeOverrides, TDefault> = TOverrides extends Record<K, infer T> ? T : TDefault;
|
|
119
|
+
/**
|
|
120
|
+
* @typeParam TList - Row shape of the list response (`data.result`).
|
|
121
|
+
* @typeParam TGet - Shape of a single fetched/affected record (`getEntry`, and the record returned by `addEntry` / `updateEntry`).
|
|
122
|
+
* @typeParam TAdd - Payload accepted by `addEntry`.
|
|
123
|
+
* @typeParam TEdit - Payload accepted by `updateEntry`.
|
|
124
|
+
*/
|
|
125
|
+
export interface ApiContextValue<TList = EntryRow, TGet = EntryRow, TAdd = EntryRow, TEdit = EntryRow> {
|
|
105
126
|
/** The API path. */
|
|
106
127
|
path: string;
|
|
107
128
|
/** Information about the API, including schemas, UI schemas, and the normalized add/edit form blocks. */
|
|
108
129
|
info?: APIInfoCanonical;
|
|
109
130
|
/** The data returned by the API. */
|
|
110
|
-
data?: APIData
|
|
131
|
+
data?: APIData<TList>;
|
|
111
132
|
/** The query parameters used in the API request. */
|
|
112
133
|
queryParams?: APIQueryParams;
|
|
113
134
|
/** Indicates whether the API request is currently loading. */
|
|
@@ -125,11 +146,11 @@ export interface ApiContextValue {
|
|
|
125
146
|
/** The raw React Query object for the info request. */
|
|
126
147
|
infoQuery: UseQueryResult<APIInfoCanonical | undefined>;
|
|
127
148
|
/** The raw React Query object for the data request. */
|
|
128
|
-
dataQuery: UseQueryResult<APIData | null>;
|
|
149
|
+
dataQuery: UseQueryResult<APIData<TList> | null>;
|
|
129
150
|
/** The raw React Query infinite query object for streaming requests. */
|
|
130
|
-
streamingQuery: UseInfiniteQueryResult<InfiniteData<APIData | null>>;
|
|
151
|
+
streamingQuery: UseInfiniteQueryResult<InfiniteData<APIData<TList> | null>>;
|
|
131
152
|
/** Streaming (infinite-scroll) controller. Present only when the `ApiProvider` is configured for streaming; its presence is the streaming-mode signal. When set, `data.result` carries every row fetched so far (all pages) and `streaming.data` is the page-number-keyed breakdown. */
|
|
132
|
-
streaming?: APIStreaming
|
|
153
|
+
streaming?: APIStreaming<TList>;
|
|
133
154
|
/** An object containing special keys for the API query, such as 'all' and 'actions'. */
|
|
134
155
|
specialKey: APISpecialKey;
|
|
135
156
|
/** A function to update the query parameters. */
|
|
@@ -142,25 +163,29 @@ export interface ApiContextValue {
|
|
|
142
163
|
refetchInfo: (options?: {
|
|
143
164
|
force?: boolean;
|
|
144
165
|
}) => Promise<void>;
|
|
145
|
-
/**
|
|
146
|
-
getEntry: (id: PrimaryKey) => Promise<
|
|
147
|
-
/**
|
|
148
|
-
addEntry: (item:
|
|
149
|
-
/**
|
|
150
|
-
updateEntry: (id: PrimaryKey, item:
|
|
151
|
-
/**
|
|
152
|
-
deleteEntry: (id: PrimaryKey) => Promise<
|
|
166
|
+
/** Retrieve a specific entry by ID. Return defaults to the resolved `get` type; override per call (e.g. `getEntry<Custom>(id)`) when the route is customized. */
|
|
167
|
+
getEntry: <R = TGet>(id: PrimaryKey) => Promise<R>;
|
|
168
|
+
/** Add a new entry. Return defaults to the resolved `get` type; override per call for custom routes. */
|
|
169
|
+
addEntry: <R = TGet>(item: TAdd) => Promise<R>;
|
|
170
|
+
/** Edit an existing entry. Return defaults to the resolved `get` type; override per call for custom routes. */
|
|
171
|
+
updateEntry: <R = TGet>(id: PrimaryKey, item: TEdit) => Promise<R>;
|
|
172
|
+
/** Delete an entry. The stock endpoint responds 204 (no body), parsed to `null`, so the return defaults to `null`; override per call for custom `post_delete` payloads. */
|
|
173
|
+
deleteEntry: <R = null>(id: PrimaryKey) => Promise<R>;
|
|
153
174
|
/** A function to download data from the API. */
|
|
154
175
|
download: (label?: string, options?: APIDownloadOptions) => Promise<void>;
|
|
155
|
-
/**
|
|
156
|
-
upload: (file: File, options?: APIUploadOptions) => Promise<
|
|
176
|
+
/** Upload a CSV. The importer returns `list[dict[str, Any]]` (no response_model), so the default is `EntryRow[]` (loosely-typed rows), NOT the model/`TGet` shape; override per call if your route is typed. */
|
|
177
|
+
upload: <R = EntryRow[]>(file: File, options?: APIUploadOptions) => Promise<R>;
|
|
157
178
|
/** A function to get the URL for a file item (file name or File object). */
|
|
158
179
|
getFileURL: (item: string | File) => string;
|
|
159
180
|
/** A function to get the URL for an image item (image name or File object). */
|
|
160
181
|
getImageURL: (item: string | File) => string;
|
|
161
182
|
/** A function to set the error state, surfacing errors thrown by the action functions (`addEntry`, `updateEntry`, ...) through the shared `ErrorDialog`. */
|
|
162
|
-
setError: (error: APISetErrorPayload | undefined) => void;
|
|
183
|
+
setError: (error: APISetErrorPayload<TGet> | undefined) => void;
|
|
163
184
|
/** A function to reset the error state. */
|
|
164
185
|
resetError: () => void;
|
|
165
186
|
}
|
|
166
|
-
|
|
187
|
+
/**
|
|
188
|
+
* The `ApiContextValue` returned by `useApi<TDefault, TOverrides>`: the uniform `TDefault` applied to
|
|
189
|
+
* every operation, with any `TOverrides` keys replacing it per operation.
|
|
190
|
+
*/
|
|
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>>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const core = require("@mantine/core");
|
|
5
5
|
const React = require("react");
|
|
6
|
-
const
|
|
6
|
+
const reactRouter = require("react-router");
|
|
7
7
|
const appWindow = require("../../_virtual/app-window.cjs");
|
|
8
8
|
const chevronDown = require("../../_virtual/chevron-down.cjs");
|
|
9
9
|
const idBadge2 = require("../../_virtual/id-badge-2.cjs");
|
|
@@ -14,7 +14,7 @@ const useAuth = require("../../hooks/auth/useAuth.cjs");
|
|
|
14
14
|
const user_module = require("./user.module.css.cjs");
|
|
15
15
|
function UserMenu(props) {
|
|
16
16
|
const { basePath = "/security", Target, children } = props;
|
|
17
|
-
const navigate =
|
|
17
|
+
const navigate = reactRouter.useNavigate();
|
|
18
18
|
const { user, signout } = useAuth.useAuth();
|
|
19
19
|
const [opened, setOpened] = React.useState(false);
|
|
20
20
|
const securityRoutes = [
|
|
@@ -298,7 +298,7 @@ function useProvideApi(params, api = defaultApi) {
|
|
|
298
298
|
getImageURL: (item) => getItemURL("image", item),
|
|
299
299
|
setError,
|
|
300
300
|
resetError
|
|
301
|
-
// #MUSTASSERT useProvideApi holds raw react-query state (DataPage/StreamingPage data, raw QueryParams, null errors); this is the resolved ApiContextValue surface consumers read, normalized at runtime
|
|
301
|
+
// #MUSTASSERT #MUSTUNKNOWN useProvideApi holds raw react-query state (DataPage/StreamingPage data, raw QueryParams, null errors) and concrete (non-generic) action fns; this is the resolved ApiContextValue surface consumers read, normalized at runtime
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
exports.useProvideApi = useProvideApi;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Menu, UnstyledButton, Group, Text } from "@mantine/core";
|
|
3
3
|
import { useState } from "react";
|
|
4
|
-
import { useNavigate } from "react-router
|
|
4
|
+
import { useNavigate } from "react-router";
|
|
5
5
|
import ForwardRef$3 from "../../_virtual/app-window.mjs";
|
|
6
6
|
import ForwardRef$4 from "../../_virtual/chevron-down.mjs";
|
|
7
7
|
import ForwardRef$1 from "../../_virtual/id-badge-2.mjs";
|
|
@@ -296,7 +296,7 @@ function useProvideApi(params, api = defaultApi) {
|
|
|
296
296
|
getImageURL: (item) => getItemURL("image", item),
|
|
297
297
|
setError,
|
|
298
298
|
resetError
|
|
299
|
-
// #MUSTASSERT useProvideApi holds raw react-query state (DataPage/StreamingPage data, raw QueryParams, null errors); this is the resolved ApiContextValue surface consumers read, normalized at runtime
|
|
299
|
+
// #MUSTASSERT #MUSTUNKNOWN useProvideApi holds raw react-query state (DataPage/StreamingPage data, raw QueryParams, null errors) and concrete (non-generic) action fns; this is the resolved ApiContextValue surface consumers read, normalized at runtime
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
export {
|
|
@@ -31,8 +31,8 @@ export type EditDialogProps = AddDialogOwnProps & DialogModalProps;
|
|
|
31
31
|
export interface DeleteDialogOwnProps {
|
|
32
32
|
/** Custom text or component to display in the delete confirmation dialog. */
|
|
33
33
|
deleteText?: ReactNode;
|
|
34
|
-
/** Callback function triggered on successful
|
|
35
|
-
onSuccess?: (result:
|
|
34
|
+
/** Callback function triggered on successful deletion. Delete responds 204 (no body), parsed to `null`. */
|
|
35
|
+
onSuccess?: (result: null) => void;
|
|
36
36
|
/** Callback function triggered on form submission error. */
|
|
37
37
|
onError?: (error: unknown) => void;
|
|
38
38
|
}
|
|
@@ -4,8 +4,8 @@ export declare const useApiActions: (params: UseApiActionsParams) => {
|
|
|
4
4
|
getEntry: (id: EntryId) => Promise<MRT_RowData>;
|
|
5
5
|
addEntry: (item: MRT_RowData) => Promise<MRT_RowData>;
|
|
6
6
|
updateEntry: (id: EntryId, item: MRT_RowData) => Promise<MRT_RowData>;
|
|
7
|
-
deleteEntry: (id: EntryId) => Promise<MRT_RowData>;
|
|
7
|
+
deleteEntry: (id: EntryId) => Promise<MRT_RowData | null>;
|
|
8
8
|
download: (label?: string, { export_mode, delimiter, quotechar }?: DownloadActionOptions) => Promise<void>;
|
|
9
|
-
upload: (file: File, { delimiter, quotechar }?: UploadActionOptions) => Promise<
|
|
9
|
+
upload: (file: File, { delimiter, quotechar }?: UploadActionOptions) => Promise<import('../../utils/api/types').UploadResponse>;
|
|
10
10
|
getItemURL: (type: string, item: string | File) => string;
|
|
11
11
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { MRT_RowData } from '../../../../../../.external/lib/mantine-react-table';
|
|
2
2
|
import { FetchOptions, ItemId } from './types';
|
|
3
|
-
export declare const deleteItem: (path: string, id: ItemId, options?: FetchOptions) => Promise<MRT_RowData>;
|
|
3
|
+
export declare const deleteItem: (path: string, id: ItemId, options?: FetchOptions) => Promise<MRT_RowData | null>;
|
|
@@ -7,4 +7,4 @@ import { FetchOptions } from './types';
|
|
|
7
7
|
* @returns The data fetched from the given path.
|
|
8
8
|
* @throws {Error} If the response is not ok, throws an error with the response detail.
|
|
9
9
|
*/
|
|
10
|
-
export declare const getInfo: (path: string, options?: FetchOptions) => Promise<string | object>;
|
|
10
|
+
export declare const getInfo: (path: string, options?: FetchOptions) => Promise<string | object | null>;
|
|
@@ -9,4 +9,4 @@ import { FetchOptions } from './types';
|
|
|
9
9
|
* @returns A promise that resolves to the fetched data, either as a JSON object or a text string.
|
|
10
10
|
* @throws {Error} - Throws an error if the response is not ok or if there is an issue with the fetch request.
|
|
11
11
|
*/
|
|
12
|
-
export declare const getItems: (path: string, queryParams?: QueryParams, options?: FetchOptions) => Promise<string | object>;
|
|
12
|
+
export declare const getItems: (path: string, queryParams?: QueryParams, options?: FetchOptions) => Promise<string | object | null>;
|
|
@@ -19,5 +19,5 @@ export interface UploadOptions {
|
|
|
19
19
|
delimiter?: string;
|
|
20
20
|
quotechar?: string;
|
|
21
21
|
}
|
|
22
|
-
/** The
|
|
23
|
-
export type UploadResponse = MRT_RowData;
|
|
22
|
+
/** The rows returned by the upload (CSV import) endpoint; a list of model-driven rows at runtime. */
|
|
23
|
+
export type UploadResponse = MRT_RowData[];
|
|
@@ -9,4 +9,4 @@ import { FetchOptions } from '../../../../Wrappers/ApiProvider/utils/api/types';
|
|
|
9
9
|
* @returns A promise that resolves to the fetched data, either as a JSON object or a text string.
|
|
10
10
|
* @throws {Error} - Throws an error if the response is not ok or if there is an issue with the fetch request.
|
|
11
11
|
*/
|
|
12
|
-
export declare const getItems: (path: string, queryParams?: QueryParams, options?: FetchOptions) => Promise<string | object>;
|
|
12
|
+
export declare const getItems: (path: string, queryParams?: QueryParams, options?: FetchOptions) => Promise<string | object | null>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const reactRouter = require("react-router");
|
|
4
4
|
function createFetchParams(args) {
|
|
5
5
|
const { method, body, queryParams, options: userOptions } = args;
|
|
6
6
|
let path = args.path;
|
|
@@ -11,7 +11,7 @@ function createFetchParams(args) {
|
|
|
11
11
|
acc[key] = String(value);
|
|
12
12
|
return acc;
|
|
13
13
|
}, {});
|
|
14
|
-
const searchParams =
|
|
14
|
+
const searchParams = reactRouter.createSearchParams(data);
|
|
15
15
|
if (searchParams.size > 0) {
|
|
16
16
|
path = path + "?" + searchParams;
|
|
17
17
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const parseResponse = async (response) => {
|
|
4
|
+
if (response.status === 204) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
4
7
|
let newData = void 0;
|
|
5
8
|
const contentType = response.headers.get("content-type");
|
|
6
9
|
if (contentType && contentType.includes("application/json")) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
interface ParseableResponse {
|
|
2
2
|
ok: boolean;
|
|
3
|
+
status: number;
|
|
3
4
|
headers: {
|
|
4
5
|
get(name: string): string | null | undefined;
|
|
5
6
|
};
|
|
@@ -14,5 +15,5 @@ interface ParseableResponse {
|
|
|
14
15
|
* @throws Throws an error if the response is not ok. The error message is derived from the parsed data,
|
|
15
16
|
* using the "detail" or "message" property if available on an object, or by stringifying the object or using the text directly.
|
|
16
17
|
*/
|
|
17
|
-
export declare const parseResponse: (response: ParseableResponse) => Promise<object | string>;
|
|
18
|
+
export declare const parseResponse: (response: ParseableResponse) => Promise<object | string | null>;
|
|
18
19
|
export {};
|
package/package.json
CHANGED