@faasjs/react 8.0.0-beta.15 → 8.0.0-beta.17

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/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FaasAction, FaasAction as FaasAction$1, FaasActionUnionType, FaasActionUnionType as FaasActionUnionType$1, FaasData, FaasData as FaasData$1, FaasParams, FaasParams as FaasParams$1 } from "@faasjs/types";
2
2
  import * as react from "react";
3
- import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, JSXElementConstructor, ReactElement, ReactNode, RefObject, SetStateAction } from "react";
3
+ import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, ReactElement, ReactNode, RefObject, SetStateAction } from "react";
4
4
  import * as react_jsx_runtime0 from "react/jsx-runtime";
5
5
 
6
6
  //#region src/generateId.d.ts
@@ -125,11 +125,10 @@ type ResponseHeaders = {
125
125
  *
126
126
  * @template PathOrData - The function path or data type for type safety
127
127
  *
128
- * @param {FaasAction<PathOrData>} action - The function path to call
129
- * @param {FaasParams<PathOrData>} [params] - Optional parameters for the function
130
- * @param {Options} [options] - Optional request options
131
- *
132
- * @returns {Promise<Response<FaasData<PathOrData>> | Response>} - A Promise resolving to a Response object
128
+ * @param action - The function path to call.
129
+ * @param params - Optional parameters for the function.
130
+ * @param options - Optional request overrides.
131
+ * @returns Promise resolving to the request response. In streaming mode the runtime returns the native fetch response.
133
132
  *
134
133
  * Notes:
135
134
  * - Used internally by FaasBrowserClient.action method
@@ -196,9 +195,6 @@ type ResponseProps<T = any> = {
196
195
  * @property {T} [data] - The parsed JSON data from the response.
197
196
  * Optional property that contains the response payload when JSON is provided.
198
197
  *
199
- * @param {ResponseProps<T>} [props] - Response properties including status, headers, body, and data.
200
- * All properties are optional with sensible defaults.
201
- *
202
198
  * Notes:
203
199
  * - status defaults to 200 if data or body is present, 204 otherwise
204
200
  * - body is automatically populated from data if not explicitly provided
@@ -302,6 +298,12 @@ declare class Response<T = any> {
302
298
  readonly headers: ResponseHeaders;
303
299
  readonly body: any;
304
300
  readonly data?: T;
301
+ /**
302
+ * Create a wrapped response object.
303
+ *
304
+ * @param props - Response properties including status, headers, body, and data.
305
+ * @returns Wrapped response instance.
306
+ */
305
307
  constructor(props?: ResponseProps<T>);
306
308
  }
307
309
  type ResponseErrorProps = {
@@ -317,7 +319,6 @@ type ResponseErrorProps = {
317
319
  * Extends the built-in Error class to provide additional information about failed requests,
318
320
  * including HTTP status code, response headers, response body, and the original error.
319
321
  *
320
- * @class ResponseError
321
322
  * @augments Error
322
323
  *
323
324
  * @property {number} status - The HTTP status code of the failed response. Defaults to 500 if not provided.
@@ -325,9 +326,6 @@ type ResponseErrorProps = {
325
326
  * @property {any} body - The response body containing error details or the original error if available.
326
327
  * @property {Error} [originalError] - The original Error object if this ResponseError was created from another Error.
327
328
  *
328
- * @param {string | Error | ResponseErrorProps} data - The error message, an Error object, or a ResponseErrorProps object.
329
- * @param {Omit<ResponseErrorProps, 'message' | 'originalError'>} [options] - Additional options for the error (status, headers, body).
330
- *
331
329
  * @example Basic error with message
332
330
  * ```ts
333
331
  * throw new ResponseError('User not found')
@@ -425,18 +423,18 @@ declare class ResponseError extends Error {
425
423
  * Defines the signature for functions that can mock API requests during testing.
426
424
  * Mock handlers receive request parameters and return simulated responses or errors.
427
425
  *
428
- * @param {string} action - The function path/action being requested (e.g., 'user', 'data/list').
426
+ * @param action - The function path/action being requested (for example, `user` or `data/list`).
429
427
  * Converted to lowercase by the client before being passed to the handler.
430
428
  *
431
- * @param {Record<string, any> | undefined} params - The parameters passed to the action.
429
+ * @param params - The parameters passed to the action.
432
430
  * May be undefined if the action was called without parameters.
433
431
  * Parameters are passed as a plain object (already JSON-serialized if needed).
434
432
  *
435
- * @param {Options} options - The full request options including headers, beforeRequest hook, and other config.
433
+ * @param options - The full request options including headers, beforeRequest hook, and other config.
436
434
  * Includes X-FaasJS-Request-Id header in the headers object.
437
435
  * Contains merged client defaults and per-request options.
438
436
  *
439
- * @returns {Promise<ResponseProps> | Promise<void> | Promise<Error>} - A Promise resolving to:
437
+ * @returns A promise resolving to:
440
438
  * - ResponseProps: Mock response data (status, headers, body, data)
441
439
  * - void: Returns an empty response (204 No Content)
442
440
  * - Error: Throws ResponseError when returning an Error object
@@ -630,11 +628,8 @@ declare class FaasBrowserClient {
630
628
  /**
631
629
  * Creates a new FaasBrowserClient instance.
632
630
  *
633
- * @param baseUrl - Base URL for all API requests. Must end with '/'. Defaults to '/' for relative requests.
634
- * @throws {Error} If baseUrl does not end with '/'
635
- * @param options - Configuration options for the client.
636
- * Supports default headers, beforeRequest hook, custom request function,
637
- * baseUrl override, and streaming mode.
631
+ * @param baseUrl - Base URL for all API requests. Must end with `/`. Defaults to `/` for relative requests.
632
+ * @param options - Default request options such as headers, hooks, request override, or stream mode.
638
633
  *
639
634
  * @example Basic initialization
640
635
  * ```ts
@@ -685,7 +680,7 @@ declare class FaasBrowserClient {
685
680
  * })
686
681
  * ```
687
682
  *
688
- * @throws {Error} When baseUrl does not end with '/'
683
+ * @throws {Error} When `baseUrl` does not end with `/`
689
684
  */
690
685
  constructor(baseUrl?: BaseUrl, options?: Options);
691
686
  /**
@@ -704,7 +699,7 @@ declare class FaasBrowserClient {
704
699
  *
705
700
  * @throws {Error} When action is not provided or is empty
706
701
  * @throws {ResponseError} When the server returns an error response (status >= 400 or body.error exists)
707
- * @throws {NetworkError} When network request fails
702
+ * @throws {Error} When the request fails before a response is received
708
703
  *
709
704
  * Notes:
710
705
  * - All requests are POST requests by default
@@ -758,11 +753,7 @@ declare class FaasBrowserClient {
758
753
  * email: string
759
754
  * }
760
755
  *
761
- * const response = await client.action<{
762
- * action: 'user'
763
- * params: { id: number }
764
- * data: UserData
765
- * }>('user', { id: 123 })
756
+ * const response = await client.action<UserData>('user', { id: 123 })
766
757
  * console.log(response.data.name) // TypeScript knows it's a string
767
758
  * ```
768
759
  *
@@ -774,7 +765,7 @@ declare class FaasBrowserClient {
774
765
  * } catch (error) {
775
766
  * if (error instanceof ResponseError) {
776
767
  * console.error(`Server error: ${error.message}`, error.status)
777
- * if (error.data) console.error('Error details:', error.data)
768
+ * if (error.body) console.error('Error details:', error.body)
778
769
  * } else {
779
770
  * console.error('Network error:', error)
780
771
  * }
@@ -798,17 +789,20 @@ declare class FaasBrowserClient {
798
789
  //#endregion
799
790
  //#region src/faas.d.ts
800
791
  /**
801
- * Request faas server
792
+ * Call the currently configured FaasReactClient.
802
793
  *
803
- * @param action {string} action name
804
- * @param params {object} action params
805
- * @returns {Promise<Response<any>>}
794
+ * @param action - Action path to invoke.
795
+ * @param params - Parameters sent to the action.
796
+ * @param options - Optional per-request overrides such as headers or base URL.
797
+ * @returns Response returned by the active browser client.
806
798
  *
807
799
  * @example
808
800
  * ```ts
809
- * faas<{ title: string }>('post/get', { id: 1 }).then(res => {
810
- * console.log(res.data.title)
811
- * })
801
+ * import { faas } from '@faasjs/react'
802
+ *
803
+ * const response = await faas<{ title: string }>('post/get', { id: 1 })
804
+ *
805
+ * console.log(response.data.title)
812
806
  * ```
813
807
  */
814
808
  declare function faas<PathOrData extends FaasActionUnionType$1>(action: FaasAction$1<PathOrData>, params: FaasParams$1<PathOrData>, options?: Options): Promise<Response<FaasData$1<PathOrData>>>;
@@ -861,9 +855,12 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType$1 = any>(
861
855
  declare function withFaasData<PathOrData extends FaasActionUnionType$1, TComponentProps extends Required<FaasDataInjection<PathOrData>> = Required<FaasDataInjection<PathOrData>>>(Component: React.FC<TComponentProps>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>> & Record<string, any>>;
862
856
  //#endregion
863
857
  //#region src/useFaas.d.ts
858
+ /**
859
+ * Options for {@link useFaas}.
860
+ */
864
861
  type useFaasOptions<PathOrData extends FaasActionUnionType$1> = {
865
- params?: FaasParams$1<PathOrData>;
866
- data?: FaasData$1<PathOrData>;
862
+ /** Override the request params without changing the hook's stored params state. */params?: FaasParams$1<PathOrData>; /** Controlled data value used instead of the hook's internal state. */
863
+ data?: FaasData$1<PathOrData>; /** Controlled setter that is called instead of the hook's internal `setData`. */
867
864
  setData?: React.Dispatch<React.SetStateAction<FaasData$1<PathOrData>>>;
868
865
  /**
869
866
  * If skip is true, the request will not be sent.
@@ -871,20 +868,27 @@ type useFaasOptions<PathOrData extends FaasActionUnionType$1> = {
871
868
  * However, you can still use reload to send the request.
872
869
  */
873
870
  skip?: boolean | ((params: FaasParams$1<PathOrData>) => boolean); /** Send the last request after milliseconds */
874
- debounce?: number;
871
+ debounce?: number; /** Override the default base URL for this hook instance. */
875
872
  baseUrl?: BaseUrl;
876
873
  };
877
874
  /**
878
- * Request faas server with React hook
875
+ * Request FaasJS data and keep request state in React state.
876
+ *
877
+ * `useFaas` sends an initial request unless `skip` is enabled, and returns
878
+ * request state plus helpers for reloading, updating data, and handling errors.
879
879
  *
880
- * @param action {string} action name
881
- * @param defaultParams {object} initial action params
882
- * @returns {FaasDataInjection<any>}
880
+ * @param action - Action path to invoke.
881
+ * @param defaultParams - Params used for the initial request and future reloads.
882
+ * @param options - Optional hook configuration such as controlled data, debounce, and skip logic.
883
+ * @returns Request state and helper methods for the action.
883
884
  *
884
885
  * @example
885
886
  * ```tsx
886
- * function Post ({ id }) {
887
+ * import { useFaas } from '@faasjs/react'
888
+ *
889
+ * function Post({ id }: { id: number }) {
887
890
  * const { data } = useFaas<{ title: string }>('post/get', { id })
891
+ *
888
892
  * return <h1>{data.title}</h1>
889
893
  * }
890
894
  * ```
@@ -893,10 +897,15 @@ declare function useFaas<PathOrData extends FaasActionUnionType$1>(action: FaasA
893
897
  //#endregion
894
898
  //#region src/client.d.ts
895
899
  type OnError = (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
900
+ /**
901
+ * Options for creating a {@link FaasReactClient} instance.
902
+ */
896
903
  type FaasReactClientOptions = {
897
- /** @default `/` */baseUrl?: BaseUrl;
904
+ /** @default `/` */baseUrl?: BaseUrl; /** Default request options forwarded to the underlying browser client. */
898
905
  options?: Options;
899
906
  /**
907
+ * Error hook invoked when `faas` or `useFaas` receives a failed response.
908
+ *
900
909
  * @example
901
910
  * ```ts
902
911
  * onError: (action, params) => async (res) => {
@@ -906,6 +915,9 @@ type FaasReactClientOptions = {
906
915
  */
907
916
  onError?: OnError;
908
917
  };
918
+ /**
919
+ * Public interface returned by {@link FaasReactClient}.
920
+ */
909
921
  type FaasReactClientInstance = {
910
922
  id: string;
911
923
  faas: typeof faas;
@@ -915,14 +927,20 @@ type FaasReactClientInstance = {
915
927
  browserClient: FaasBrowserClient;
916
928
  };
917
929
  /**
918
- * Before use faas, you should initialize a FaasReactClient.
930
+ * Create and register a FaasReactClient instance.
919
931
  *
920
- * @returns FaasReactClient instance.
932
+ * The returned client is stored by `baseUrl` and becomes the default client
933
+ * used by helpers such as {@link faas} and {@link useFaas}.
934
+ *
935
+ * @param options - Client configuration including base URL, default request options, and error hooks.
936
+ * @returns Registered FaasReactClient instance.
921
937
  *
922
938
  * @example
923
939
  * ```ts
940
+ * import { FaasReactClient } from '@faasjs/react'
941
+ *
924
942
  * const client = FaasReactClient({
925
- * baseUrl: 'localhost:8080/api/'
943
+ * baseUrl: 'http://localhost:8080/api/',
926
944
  * })
927
945
  * ```
928
946
  */
@@ -932,16 +950,20 @@ declare function FaasReactClient({
932
950
  onError
933
951
  }?: FaasReactClientOptions): FaasReactClientInstance;
934
952
  /**
935
- * Get FaasReactClient instance
953
+ * Get a registered FaasReactClient instance.
954
+ *
955
+ * When `host` is omitted, the first registered client is returned. If no client
956
+ * has been created yet, a default client is initialized automatically.
936
957
  *
937
- * @param host {string} empty string for default host
938
- * @returns {FaasReactClientInstance}
958
+ * @param host - Registered base URL to look up. Omit it to use the default client.
959
+ * @returns Registered or newly created FaasReactClient instance.
939
960
  *
940
961
  * @example
941
962
  * ```ts
963
+ * import { getClient } from '@faasjs/react'
964
+ *
942
965
  * getClient()
943
- * // or
944
- * getClient('another-host')
966
+ * getClient('http://localhost:8080/api/')
945
967
  * ```
946
968
  */
947
969
  declare function getClient(host?: string): FaasReactClientInstance;
@@ -1019,223 +1041,6 @@ declare function useEqualMemo<T>(callback: () => T, dependencies: any[]): T;
1019
1041
  */
1020
1042
  declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T, dependencies: any[]): T;
1021
1043
  //#endregion
1022
- //#region src/Form/elements/Button.d.ts
1023
- /**
1024
- * Props for the FormButtonElement component.
1025
- *
1026
- * @property {React.ReactNode} [children] - The content to be displayed inside the button.
1027
- * @property {boolean} disabled - Indicates whether the button is disabled.
1028
- * @property {() => Promise<void>} submit - A function to be called when the button is clicked, which returns a promise.
1029
- */
1030
- type FormButtonElementProps = {
1031
- children?: React.ReactNode;
1032
- submitting: boolean;
1033
- submit: () => Promise<void>;
1034
- };
1035
- //#endregion
1036
- //#region src/Form/elements/Input.d.ts
1037
- /**
1038
- * Props for the Form Input Element component.
1039
- *
1040
- * @property {string} name - The name of the input element.
1041
- * @property {any} value - The current value of the input element.
1042
- * @property {(value: any) => void} onChange - Callback function to handle changes to the input value.
1043
- */
1044
- type FormInputElementProps = {
1045
- name: string;
1046
- value: any;
1047
- onChange: (value: any) => void;
1048
- };
1049
- //#endregion
1050
- //#region src/Form/elements/Label.d.ts
1051
- /**
1052
- * Props for the FormLabelElement component.
1053
- *
1054
- * @typedef {Object} FormLabelElementProps
1055
- * @property {string} name - The name of the form element.
1056
- * @property {ReactNode} [title] - Optional title for the form element.
1057
- * @property {ReactNode} [description] - Optional description for the form element.
1058
- * @property {Error} [error] - Optional error associated with the form element.
1059
- * @property {ReactNode} children - The child elements, typically an input element.
1060
- */
1061
- type FormLabelElementProps = {
1062
- name: string;
1063
- title?: ReactNode;
1064
- description?: ReactNode;
1065
- error?: Error; /** as Input element */
1066
- children: ReactNode;
1067
- };
1068
- //#endregion
1069
- //#region src/Form/elements/index.d.ts
1070
- /**
1071
- * Represents the types of form elements used in the form.
1072
- *
1073
- * @typedef {Object} FormElementTypes
1074
- * @property {ComponentType<FormLabelElementProps>} Label - The component type for the form label element.
1075
- * @property {ComponentType<FormInputElementProps>} Input - The component type for the form input element.
1076
- * @property {ComponentType<FormButtonElementProps>} Button - The component type for the form button element.
1077
- */
1078
- type FormElementTypes = {
1079
- Label: ComponentType<FormLabelElementProps>;
1080
- Input: ComponentType<FormInputElementProps>;
1081
- Button: ComponentType<FormButtonElementProps>;
1082
- };
1083
- declare const FormDefaultElements: FormElementTypes;
1084
- //#endregion
1085
- //#region src/Form/lang.d.ts
1086
- declare const FormDefaultLang: {
1087
- submit: string;
1088
- required: string;
1089
- string: string;
1090
- number: string;
1091
- };
1092
- type FormLang = typeof FormDefaultLang;
1093
- //#endregion
1094
- //#region src/Form/rules.d.ts
1095
- /**
1096
- * A type representing a form validation rule.
1097
- *
1098
- * @template Options - The type of the options that can be passed to the rule.
1099
- *
1100
- * @param value - The value to be validated.
1101
- * @param options - Optional. Additional options that can be used in the validation.
1102
- * @param lang - Optional. The language settings that can be used in the validation.
1103
- *
1104
- * @returns A promise that resolves if the validation is successful, or rejects with an error if the validation fails.
1105
- *
1106
- * @example
1107
- * ```ts
1108
- * async function required(value: any, options: boolean, lang?: FormLang) {
1109
- * if (value === null || value === undefined || value === '' || Number.isNaN(value))
1110
- * throw Error(lang?.required)
1111
- * }
1112
- * ```
1113
- */
1114
- type FormRule<Options = any> = (value: any, options?: Options, lang?: FormLang) => Promise<void>;
1115
- type InferRuleOption<T> = T extends ((value: any, options: infer O, lang?: FormLang) => Promise<void>) ? O : never;
1116
- /**
1117
- * A type representing a set of form validation rules.
1118
- *
1119
- * @typedef {Record<string, FormRule>} FormRules
1120
- *
1121
- * Each key in the record represents the name of a form field, and the corresponding value is a `FormRule` object that defines the validation rules for that field.
1122
- */
1123
- type FormRules = Record<string, FormRule>;
1124
- type InferFormRulesOptions<T> = { [K in keyof T]: InferRuleOption<T[K]> };
1125
- /**
1126
- * Default validation rules for a form.
1127
- */
1128
- declare const FormDefaultRules: FormRules;
1129
- type FormDefaultRulesOptions = InferFormRulesOptions<typeof FormDefaultRules>;
1130
- declare function validValues(rules: FormRules, items: FormItemProps[], values: Record<string, any>, lang: FormLang): Promise<Record<string, Error>>;
1131
- //#endregion
1132
- //#region src/Form/Input.d.ts
1133
- type InferFormInputProps<T extends ComponentType<FormInputElementProps> | JSXElementConstructor<any>> = T extends ComponentType<FormInputElementProps> ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
1134
- type FormInputProps<FormElements extends FormElementTypes = FormElementTypes> = {
1135
- Input?: ComponentType<FormInputElementProps>;
1136
- props?: InferFormInputProps<FormElements['Input']>;
1137
- };
1138
- declare function FormInput({
1139
- name,
1140
- rules,
1141
- ...rest
1142
- }: FormInputProps & {
1143
- name: string;
1144
- rules?: FormDefaultRulesOptions;
1145
- }): react_jsx_runtime0.JSX.Element;
1146
- declare namespace FormInput {
1147
- var displayName: string;
1148
- }
1149
- //#endregion
1150
- //#region src/Form/Item.d.ts
1151
- type FormItemName = string;
1152
- type FormItemProps<FormElements extends FormElementTypes = FormElementTypes, FormRulesOptions extends Record<string, any> = FormDefaultRulesOptions> = {
1153
- name: FormItemName;
1154
- label?: Omit<FormLabelElementProps, 'name' | 'children'> & {
1155
- Label?: ComponentType<FormLabelElementProps>;
1156
- };
1157
- input?: FormInputProps<FormElements>;
1158
- rules?: FormRulesOptions;
1159
- };
1160
- declare function FormItem(props: FormItemProps): react_jsx_runtime0.JSX.Element;
1161
- declare namespace FormItem {
1162
- var displayName: string;
1163
- }
1164
- //#endregion
1165
- //#region src/Form/Container.d.ts
1166
- type FormProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
1167
- items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
1168
- onSubmit?: (values: Values) => Promise<void>;
1169
- Elements?: Partial<FormElements>;
1170
- lang?: Partial<FormLang>;
1171
- defaultValues?: Values;
1172
- rules?: typeof FormDefaultRules & Rules;
1173
- };
1174
- /**
1175
- * FormContainer component is a wrapper that provides context and state management for form elements.
1176
- * It initializes form states such as values, errors, submitting status, elements, language, and rules.
1177
- *
1178
- * @template Values - The type of form values, defaults to Record<string, any>.
1179
- * @template FormElements - The type of form elements, defaults to FormElementTypes.
1180
- * @template Rules - The type of form rules, defaults to FormDefaultRules.
1181
- *
1182
- * @param {FormProps<Values, FormElements, Rules>} props - The properties for the FormContainer component.
1183
- * @param {Values} props.defaultValues - The default values for the form fields.
1184
- * @param {FormElements} props.Elements - The form elements to be used in the form.
1185
- * @param {Rules} props.rules - The validation rules for the form fields.
1186
- * @param {FormLang} props.lang - The language settings for the form.
1187
- * @param {Partial<FormContextProps>} props - Additional properties for the form context.
1188
- *
1189
- * @returns {JSX.Element} The FormContainer component.
1190
- *
1191
- * @example
1192
- * ```tsx
1193
- * import { Form } from '@faasjs/react'
1194
- *
1195
- * function MyForm() {
1196
- * return <Form
1197
- * items={[
1198
- * { name: 'name' },
1199
- * ]}
1200
- * />
1201
- * }
1202
- * ```
1203
- */
1204
- declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules>({
1205
- defaultValues,
1206
- Elements,
1207
- rules,
1208
- lang,
1209
- items,
1210
- ...props
1211
- }: FormProps<Values, FormElements, Rules>): react_jsx_runtime0.JSX.Element;
1212
- declare namespace FormContainer {
1213
- var displayName: string;
1214
- }
1215
- //#endregion
1216
- //#region src/Form/context.d.ts
1217
- type FormContextProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
1218
- items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
1219
- onSubmit: (values: Values) => Promise<void>;
1220
- Elements: FormElementTypes;
1221
- lang: FormLang;
1222
- rules: typeof FormDefaultRules & Rules;
1223
- submitting: boolean;
1224
- setSubmitting: Dispatch<SetStateAction<boolean>>;
1225
- values: Values;
1226
- setValues: Dispatch<SetStateAction<Values>>;
1227
- errors: Record<string, Error>;
1228
- setErrors: Dispatch<SetStateAction<Record<string, Error>>>;
1229
- valuesRef: RefObject<Values>;
1230
- };
1231
- declare const FormContextProvider: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>(this: void, props: {
1232
- value?: Partial<NewT>;
1233
- children: react.ReactNode;
1234
- memo?: true | any[];
1235
- initializeStates?: Partial<NewT>;
1236
- }) => react.ReactNode;
1237
- declare const useFormContext: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>(this: void) => Readonly<NewT>;
1238
- //#endregion
1239
1044
  //#region src/OptionalWrapper.d.ts
1240
1045
  type OptionalWrapperProps<TWrapper extends ComponentType<{
1241
1046
  children: ReactNode;
@@ -1385,15 +1190,16 @@ declare function createSplittingContext<T extends Record<string, any>>(defaultVa
1385
1190
  type StateSetters<T> = { [K in keyof T as K extends string ? K extends `${infer First}${infer Rest}` ? `set${Capitalize<First>}${Rest}` : never : never]: Dispatch<SetStateAction<T[K]>> };
1386
1191
  type StatesWithSetters<T> = T & StateSetters<T>;
1387
1192
  /**
1388
- * A hook that initializes and splits state variables and their corresponding setters.
1193
+ * Create local state entries and matching setters for each key in an object.
1389
1194
  *
1390
1195
  * @template T - A generic type that extends a record with string keys and any values.
1391
- * @param {T} initialStates - An object containing the initial states.
1196
+ * @param initialStates - Object whose keys become state values and `setXxx` setters.
1197
+ * @returns Object containing the original keys plus generated setter functions.
1392
1198
  *
1393
1199
  * @example
1394
1200
  * ```tsx
1395
1201
  * function Counter() {
1396
- * const { count, setCount, name, setName } = useSplittingState({ count: 0, name: 'John' });
1202
+ * const { count, setCount, name, setName } = useSplittingState({ count: 0, name: 'John' })
1397
1203
  *
1398
1204
  * return <>{name}: {count}</>
1399
1205
  * }
@@ -1402,9 +1208,12 @@ type StatesWithSetters<T> = T & StateSetters<T>;
1402
1208
  declare function useSplittingState<T extends Record<string, unknown>>(initialStates: T): StatesWithSetters<T>;
1403
1209
  //#endregion
1404
1210
  //#region src/useFaasStream.d.ts
1211
+ /**
1212
+ * Options for {@link useFaasStream}.
1213
+ */
1405
1214
  type UseFaasStreamOptions = {
1406
- params?: Record<string, any>;
1407
- data?: string;
1215
+ /** Override the request params without changing the hook's stored params state. */params?: Record<string, any>; /** Controlled stream text used instead of the hook's internal state. */
1216
+ data?: string; /** Controlled setter that is called instead of the hook's internal `setData`. */
1408
1217
  setData?: React.Dispatch<React.SetStateAction<string>>;
1409
1218
  /**
1410
1219
  * If skip is true, the request will not be sent.
@@ -1412,9 +1221,12 @@ type UseFaasStreamOptions = {
1412
1221
  * However, you can still use reload to send the request.
1413
1222
  */
1414
1223
  skip?: boolean | ((params: Record<string, any>) => boolean); /** Send the last request after milliseconds */
1415
- debounce?: number;
1224
+ debounce?: number; /** Override the default base URL for this hook instance. */
1416
1225
  baseUrl?: BaseUrl;
1417
1226
  };
1227
+ /**
1228
+ * Result returned by {@link useFaasStream}.
1229
+ */
1418
1230
  type UseFaasStreamResult = {
1419
1231
  action: string;
1420
1232
  params: Record<string, any>;
@@ -1428,14 +1240,21 @@ type UseFaasStreamResult = {
1428
1240
  setError: React.Dispatch<React.SetStateAction<any>>;
1429
1241
  };
1430
1242
  /**
1431
- * Stream faas server response with React hook
1243
+ * Stream a FaasJS response into React state.
1244
+ *
1245
+ * The hook sends a streaming request, appends decoded text chunks to `data`,
1246
+ * and exposes reload helpers for retrying the same action.
1432
1247
  *
1433
- * @param action {string} action name
1434
- * @param defaultParams {object} initial action params
1435
- * @returns {UseFaasStreamResult}
1248
+ * @param action - Action path to invoke.
1249
+ * @param defaultParams - Params used for the initial request and future reloads.
1250
+ * @param options - Optional hook configuration such as controlled data, debounce, and skip logic.
1251
+ * @returns Streaming request state and helper methods.
1436
1252
  *
1437
1253
  * @example
1438
1254
  * ```tsx
1255
+ * import { useState } from 'react'
1256
+ * import { useFaasStream } from '@faasjs/react'
1257
+ *
1439
1258
  * function Chat() {
1440
1259
  * const [prompt, setPrompt] = useState('')
1441
1260
  * const { data, loading, reload } = useFaasStream('chat', { prompt })
@@ -1457,8 +1276,8 @@ declare function useFaasStream(action: string, defaultParams: Record<string, any
1457
1276
  * Hook to store the previous value of a state or prop.
1458
1277
  *
1459
1278
  * @template T - The type of the value.
1460
- * @param {T} value - The current value to be stored.
1461
- * @returns {T | undefined} - The previous value, or undefined if there is no previous value.
1279
+ * @param value - The current value to track.
1280
+ * @returns Previous value from the prior render, or `undefined` on the first render.
1462
1281
  */
1463
1282
  declare function usePrevious<T = any>(value: T): T | undefined;
1464
1283
  //#endregion
@@ -1467,24 +1286,26 @@ declare function usePrevious<T = any>(value: T): T | undefined;
1467
1286
  * Custom hook that returns a stateful value and a ref to that value.
1468
1287
  *
1469
1288
  * @template T - The type of the value.
1470
- * @param {T} initialValue - The initial value of the state.
1471
- * @returns {[T, (value: T) => void, RefObject<T>]} - The stateful value, a function to set the value, and a ref to the value.
1289
+ * @param initialValue - Initial state value. When omitted, state starts as `null`.
1290
+ * @returns Tuple containing the current state, the state setter, and a ref that always points at the latest state.
1472
1291
  *
1473
1292
  * @example
1474
1293
  * ```tsx
1475
1294
  * import { useStateRef } from '@faasjs/react'
1476
1295
  *
1477
1296
  * function MyComponent() {
1478
- * const [value, setValue, ref] = useStateRef(0)
1479
- *
1480
- * return (
1481
- * <div>
1482
- * <p>Value: {value}</p>
1483
- * <button onClick={() => setValue(value + 1)}>Increment</button>
1484
- * <button onClick={() => console.log(ref.current)}>Submit</button>
1485
- * </div>
1486
- * )
1297
+ * const [value, setValue, ref] = useStateRef(0)
1298
+ *
1299
+ * return (
1300
+ * <div>
1301
+ * <p>Value: {value}</p>
1302
+ * <button onClick={() => setValue(value + 1)}>Increment</button>
1303
+ * <button onClick={() => console.log(ref.current)}>Submit</button>
1304
+ * </div>
1305
+ * )
1306
+ * }
1307
+ * ```
1487
1308
  */
1488
1309
  declare function useStateRef<T = any>(initialValue?: T): [T | null, Dispatch<SetStateAction<T | null>>, RefObject<T | null>];
1489
1310
  //#endregion
1490
- export { BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, type FaasAction, type FaasActionUnionType, FaasBrowserClient, FaasBrowserClientAction, type FaasData, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, type FaasParams, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, FormContainer as Form, type FormButtonElementProps, FormContextProps, FormContextProvider, FormDefaultElements, FormDefaultLang, FormDefaultRules, FormDefaultRulesOptions, FormElementTypes, FormInput, type FormInputElementProps, FormInputProps, FormItem, FormItemName, FormItemProps, type FormLabelElementProps, FormLang, FormProps, FormRule, FormRules, InferFormInputProps, InferFormRulesOptions, InferRuleOption, MockHandler, OnError, OptionalWrapper, OptionalWrapperProps, Options, Response, ResponseError, ResponseErrorProps, ResponseHeaders, ResponseProps, StateSetters, StatesWithSetters, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, generateId, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasOptions, useFaasStream, useFormContext, usePrevious, useSplittingState, useStateRef, validValues, withFaasData };
1311
+ export { BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, type FaasAction, type FaasActionUnionType, FaasBrowserClient, FaasBrowserClientAction, type FaasData, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, type FaasParams, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, MockHandler, OnError, OptionalWrapper, OptionalWrapperProps, Options, Response, ResponseError, ResponseErrorProps, ResponseHeaders, ResponseProps, StateSetters, StatesWithSetters, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, generateId, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasOptions, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };