@faasjs/react 8.0.0-beta.21 → 8.0.0-beta.23
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 +148 -192
- package/dist/index.mjs +132 -104
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -7,13 +7,15 @@ import { FaasAction, FaasAction as FaasAction$1, FaasActionUnionType, FaasAction
|
|
|
7
7
|
/**
|
|
8
8
|
* Generate a random identifier with an optional prefix.
|
|
9
9
|
*
|
|
10
|
-
* @param prefix - Prefix prepended to the generated identifier.
|
|
11
|
-
* @param length - Length of the generated identifier excluding `prefix`. Must be between `8` and `18`.
|
|
12
|
-
* @returns Generated identifier string.
|
|
10
|
+
* @param {string} [prefix] - Prefix prepended to the generated identifier.
|
|
11
|
+
* @param {number} [length] - Length of the generated identifier excluding `prefix`. Must be between `8` and `18`.
|
|
12
|
+
* @returns {string} Generated identifier string.
|
|
13
13
|
* @throws {Error} When `length` is outside the supported `8` to `18` range.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
|
+
* import { generateId } from '@faasjs/react'
|
|
18
|
+
*
|
|
17
19
|
* const id = generateId('prefix-')
|
|
18
20
|
*
|
|
19
21
|
* id.startsWith('prefix-') // true
|
|
@@ -35,8 +37,8 @@ declare function generateId(prefix?: string, length?: number): string;
|
|
|
35
37
|
* - Ensures consistent URL formatting across the codebase
|
|
36
38
|
* - Throws Error at runtime if baseUrl doesn't end with '/'
|
|
37
39
|
*
|
|
38
|
-
* @see FaasBrowserClient for usage in client creation
|
|
39
|
-
* @see Options for usage in request options
|
|
40
|
+
* @see {@link FaasBrowserClient} for usage in client creation.
|
|
41
|
+
* @see {@link Options} for usage in request options.
|
|
40
42
|
*/
|
|
41
43
|
type BaseUrl = `${string}/`;
|
|
42
44
|
/**
|
|
@@ -78,8 +80,8 @@ type BaseUrl = `${string}/`;
|
|
|
78
80
|
* When false or undefined, returns a wrapped Response with automatic JSON parsing.
|
|
79
81
|
*
|
|
80
82
|
* @augments RequestInit
|
|
81
|
-
* @see FaasBrowserClient for client creation
|
|
82
|
-
* @see Response for response object structure
|
|
83
|
+
* @see {@link FaasBrowserClient} for client creation.
|
|
84
|
+
* @see {@link Response} for response object structure.
|
|
83
85
|
*/
|
|
84
86
|
type Options = RequestInit & {
|
|
85
87
|
headers?: Record<string, string>; /** Async hook called after request options are merged but before the request is sent. */
|
|
@@ -114,9 +116,9 @@ type Options = RequestInit & {
|
|
|
114
116
|
* - Used in Response, ResponseError, and Options types
|
|
115
117
|
* - Simplified model compared to browser's Headers interface (no .get(), .set() methods)
|
|
116
118
|
*
|
|
117
|
-
* @see Response for usage in response objects
|
|
118
|
-
* @see ResponseError for usage in error objects
|
|
119
|
-
* @see Options for usage in request options
|
|
119
|
+
* @see {@link Response} for usage in response objects.
|
|
120
|
+
* @see {@link ResponseError} for usage in error objects.
|
|
121
|
+
* @see {@link Options} for usage in request options.
|
|
120
122
|
*/
|
|
121
123
|
type ResponseHeaders = {
|
|
122
124
|
[key: string]: string;
|
|
@@ -129,12 +131,12 @@ type ResponseHeaders = {
|
|
|
129
131
|
*
|
|
130
132
|
* @template PathOrData - The function path or data type for type safety
|
|
131
133
|
*
|
|
132
|
-
* @param action - The function path to call.
|
|
133
|
-
* @param params - Optional parameters for the function.
|
|
134
|
-
* @param options - Optional request overrides.
|
|
134
|
+
* @param {FaasAction<PathOrData>} action - The function path to call.
|
|
135
|
+
* @param {FaasParams<PathOrData>} [params] - Optional parameters for the function.
|
|
136
|
+
* @param {Options} [options] - Optional request overrides.
|
|
135
137
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
136
138
|
* `request`, `baseUrl`, and `stream`.
|
|
137
|
-
* @returns Promise resolving to the request response. In streaming mode the runtime returns the native fetch response.
|
|
139
|
+
* @returns {Promise<Response<FaasData<PathOrData>> | Response>} Promise resolving to the request response. In streaming mode the runtime returns the native fetch response.
|
|
138
140
|
*
|
|
139
141
|
* Notes:
|
|
140
142
|
* - Used internally by FaasBrowserClient.action method
|
|
@@ -143,9 +145,9 @@ type ResponseHeaders = {
|
|
|
143
145
|
* - Params are optional and can be undefined
|
|
144
146
|
* - Options override client defaults when provided
|
|
145
147
|
*
|
|
146
|
-
* @see FaasBrowserClient for the class that uses this type
|
|
147
|
-
* @see Response for the return type
|
|
148
|
-
* @see Options for the options parameter type
|
|
148
|
+
* @see {@link FaasBrowserClient} for the class that uses this type.
|
|
149
|
+
* @see {@link Response} for the return type.
|
|
150
|
+
* @see {@link Options} for the options parameter type.
|
|
149
151
|
*/
|
|
150
152
|
type FaasBrowserClientAction = <PathOrData extends FaasActionUnionType$1>(action: FaasAction$1<PathOrData>, params?: FaasParams$1<PathOrData>, options?: Options) => Promise<Response<FaasData$1<PathOrData>> | Response>;
|
|
151
153
|
/**
|
|
@@ -175,8 +177,8 @@ type FaasBrowserClientAction = <PathOrData extends FaasActionUnionType$1>(action
|
|
|
175
177
|
* - If data is provided without body, body is automatically JSON.stringify(data)
|
|
176
178
|
* - Used by Response constructor and mock handlers
|
|
177
179
|
*
|
|
178
|
-
* @see Response for the class that uses these properties
|
|
179
|
-
* @see ResponseErrorProps for error response properties
|
|
180
|
+
* @see {@link Response} for the class that uses these properties.
|
|
181
|
+
* @see {@link ResponseErrorProps} for error response properties.
|
|
180
182
|
*/
|
|
181
183
|
type ResponseProps<T = any> = {
|
|
182
184
|
status?: number;
|
|
@@ -295,9 +297,9 @@ type ResponseProps<T = any> = {
|
|
|
295
297
|
* })
|
|
296
298
|
* ```
|
|
297
299
|
*
|
|
298
|
-
* @see ResponseProps for response property type
|
|
299
|
-
* @see ResponseError for error response handling
|
|
300
|
-
* @see FaasBrowserClient.action for method returning Response
|
|
300
|
+
* @see {@link ResponseProps} for response property type.
|
|
301
|
+
* @see {@link ResponseError} for error response handling.
|
|
302
|
+
* @see {@link FaasBrowserClient.action} for method returning Response.
|
|
301
303
|
*/
|
|
302
304
|
declare class Response<T = any> {
|
|
303
305
|
/**
|
|
@@ -319,12 +321,12 @@ declare class Response<T = any> {
|
|
|
319
321
|
/**
|
|
320
322
|
* Create a wrapped response object.
|
|
321
323
|
*
|
|
322
|
-
* @param props - Response properties including status, headers, body, and data.
|
|
323
|
-
* @param props.status - HTTP status code. Defaults to `200` when `data` or `body` exists, otherwise `204`.
|
|
324
|
-
* @param props.headers - Response headers keyed by header name.
|
|
325
|
-
* @param props.body - Raw response body to expose without additional parsing.
|
|
326
|
-
* @param props.data - Parsed response payload to expose on `response.data`.
|
|
327
|
-
* @returns Wrapped response instance.
|
|
324
|
+
* @param {ResponseProps<T>} [props] - Response properties including status, headers, body, and data.
|
|
325
|
+
* @param {number} [props.status] - HTTP status code. Defaults to `200` when `data` or `body` exists, otherwise `204`.
|
|
326
|
+
* @param {ResponseHeaders} [props.headers] - Response headers keyed by header name.
|
|
327
|
+
* @param {any} [props.body] - Raw response body to expose without additional parsing.
|
|
328
|
+
* @param {T} [props.data] - Parsed response payload to expose on `response.data`.
|
|
329
|
+
* @returns {Response<T>} Wrapped response instance.
|
|
328
330
|
*/
|
|
329
331
|
constructor(props?: ResponseProps<T>);
|
|
330
332
|
}
|
|
@@ -430,9 +432,9 @@ type ResponseErrorProps = {
|
|
|
430
432
|
* - Use instanceof ResponseError to distinguish FaasJS errors from other JavaScript errors
|
|
431
433
|
* - The body property can contain structured error information from the server response
|
|
432
434
|
*
|
|
433
|
-
* @see FaasBrowserClient.action for how ResponseError is thrown in requests
|
|
434
|
-
* @see ResponseProps for the structure of response data
|
|
435
|
-
* @see setMock for mocking errors in tests
|
|
435
|
+
* @see {@link FaasBrowserClient.action} for how ResponseError is thrown in requests.
|
|
436
|
+
* @see {@link ResponseProps} for the structure of response data.
|
|
437
|
+
* @see {@link setMock} for mocking errors in tests.
|
|
436
438
|
*/
|
|
437
439
|
declare class ResponseError extends Error {
|
|
438
440
|
/**
|
|
@@ -454,17 +456,17 @@ declare class ResponseError extends Error {
|
|
|
454
456
|
/**
|
|
455
457
|
* Create a ResponseError from a message, Error, or structured response error payload.
|
|
456
458
|
*
|
|
457
|
-
* @param data - Error message, Error object, or structured response error props.
|
|
458
|
-
* @param data.message - User-facing error message when `data` is a structured object.
|
|
459
|
-
* @param data.status - HTTP status code when `data` is a structured object.
|
|
460
|
-
* @param data.headers - Response headers returned with the error when `data` is a structured object.
|
|
461
|
-
* @param data.body - Raw error body or structured error payload when `data` is a structured object.
|
|
462
|
-
* @param data.originalError - Original error preserved on the instance when `data` is a structured object.
|
|
463
|
-
* @param options - Additional options such as status, headers, and body.
|
|
464
|
-
* @param options.status - HTTP status override used when `data` is a string or `Error`.
|
|
465
|
-
* @param options.headers - Response headers override used when `data` is a string or `Error`.
|
|
466
|
-
* @param options.body - Raw error body override used when `data` is a string or `Error`.
|
|
467
|
-
* @returns ResponseError instance.
|
|
459
|
+
* @param {string | Error | ResponseErrorProps} data - Error message, Error object, or structured response error props.
|
|
460
|
+
* @param {string} data.message - User-facing error message when `data` is a structured object.
|
|
461
|
+
* @param {number} [data.status] - HTTP status code when `data` is a structured object.
|
|
462
|
+
* @param {ResponseHeaders} [data.headers] - Response headers returned with the error when `data` is a structured object.
|
|
463
|
+
* @param {any} [data.body] - Raw error body or structured error payload when `data` is a structured object.
|
|
464
|
+
* @param {Error} [data.originalError] - Original error preserved on the instance when `data` is a structured object.
|
|
465
|
+
* @param {Omit<ResponseErrorProps, 'message' | 'originalError'>} [options] - Additional options such as status, headers, and body.
|
|
466
|
+
* @param {number} [options.status] - HTTP status override used when `data` is a string or `Error`.
|
|
467
|
+
* @param {ResponseHeaders} [options.headers] - Response headers override used when `data` is a string or `Error`.
|
|
468
|
+
* @param {any} [options.body] - Raw error body override used when `data` is a string or `Error`.
|
|
469
|
+
* @returns {ResponseError} ResponseError instance.
|
|
468
470
|
*/
|
|
469
471
|
constructor(data: string | Error, options?: Omit<ResponseErrorProps, 'message' | 'originalError'>);
|
|
470
472
|
constructor(data: ResponseErrorProps);
|
|
@@ -475,20 +477,20 @@ declare class ResponseError extends Error {
|
|
|
475
477
|
* Defines the signature for functions that can mock API requests during testing.
|
|
476
478
|
* Mock handlers receive request parameters and return simulated responses or errors.
|
|
477
479
|
*
|
|
478
|
-
* @param action - The function path/action being requested (for example, `user` or `data/list`).
|
|
480
|
+
* @param {string} action - The function path/action being requested (for example, `user` or `data/list`).
|
|
479
481
|
* Converted to lowercase by the client before being passed to the handler.
|
|
480
482
|
*
|
|
481
|
-
* @param params - The parameters passed to the action.
|
|
483
|
+
* @param {Record<string, any> | undefined} params - The parameters passed to the action.
|
|
482
484
|
* May be undefined if the action was called without parameters.
|
|
483
485
|
* Parameters are passed as a plain object (already JSON-serialized if needed).
|
|
484
486
|
*
|
|
485
|
-
* @param options - The full request options including headers, beforeRequest hook, and other config.
|
|
487
|
+
* @param {Options} options - The full request options including headers, beforeRequest hook, and other config.
|
|
486
488
|
* Includes X-FaasJS-Request-Id header in the headers object.
|
|
487
489
|
* Contains merged client defaults and per-request options.
|
|
488
490
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
489
491
|
* `request`, `baseUrl`, and `stream`.
|
|
490
492
|
*
|
|
491
|
-
* @returns A promise resolving to:
|
|
493
|
+
* @returns {Promise<ResponseProps> | Promise<void> | Promise<Error>} A promise resolving to:
|
|
492
494
|
* - ResponseProps: Mock response data (status, headers, body, data)
|
|
493
495
|
* - void: Returns an empty response (204 No Content)
|
|
494
496
|
* - Error: Throws ResponseError when returning an Error object
|
|
@@ -500,62 +502,15 @@ declare class ResponseError extends Error {
|
|
|
500
502
|
* - Returning an Error object causes the action() method to reject with ResponseError
|
|
501
503
|
* - Async function - must return a Promise
|
|
502
504
|
* - Receives the fully merged options including default headers
|
|
503
|
-
*
|
|
504
|
-
* @
|
|
505
|
-
*
|
|
506
|
-
* setMock(async (action, params, options) => {
|
|
507
|
-
* if (action === 'user') {
|
|
508
|
-
* return {
|
|
509
|
-
* status: 200,
|
|
510
|
-
* data: { id: params.id, name: 'Mock User' }
|
|
511
|
-
* }
|
|
512
|
-
* }
|
|
513
|
-
* return { status: 404, data: { error: 'Not found' } }
|
|
514
|
-
* })
|
|
515
|
-
* ```
|
|
516
|
-
*
|
|
517
|
-
* @example Conditional mock based on parameters
|
|
518
|
-
* ```ts
|
|
519
|
-
* setMock(async (action, params) => {
|
|
520
|
-
* if (action === 'login') {
|
|
521
|
-
* if (params.email === 'admin@example.com' && params.password === 'admin') {
|
|
522
|
-
* return { data: { token: 'admin-token', role: 'admin' } }
|
|
523
|
-
* }
|
|
524
|
-
* return { status: 401, data: { error: 'Invalid credentials' } }
|
|
525
|
-
* }
|
|
526
|
-
* })
|
|
527
|
-
* ```
|
|
528
|
-
*
|
|
529
|
-
* @example Throwing error from mock
|
|
530
|
-
* ```ts
|
|
531
|
-
* setMock(async (action) => {
|
|
532
|
-
* if (action === 'protected') {
|
|
533
|
-
* return new Error('Unauthorized access')
|
|
534
|
-
* // This will be wrapped in ResponseError and thrown
|
|
535
|
-
* }
|
|
536
|
-
* })
|
|
537
|
-
* ```
|
|
538
|
-
*
|
|
539
|
-
* @example Returning void for empty response
|
|
540
|
-
* ```ts
|
|
541
|
-
* setMock(async (action) => {
|
|
542
|
-
* if (action === 'delete') {
|
|
543
|
-
* // Return void for 204 No Content
|
|
544
|
-
* return
|
|
545
|
-
* }
|
|
546
|
-
* return { data: { success: true } }
|
|
547
|
-
* })
|
|
548
|
-
* ```
|
|
549
|
-
*
|
|
550
|
-
* @see setMock for setting up mock handlers
|
|
551
|
-
* @see ResponseProps for response structure
|
|
552
|
-
* @see ResponseError for error handling
|
|
505
|
+
* @see {@link setMock} for setting up mock handlers.
|
|
506
|
+
* @see {@link ResponseProps} for response structure.
|
|
507
|
+
* @see {@link ResponseError} for error handling.
|
|
553
508
|
*/
|
|
554
509
|
type MockHandler = (action: string, params: Record<string, any> | undefined, options: Options) => Promise<ResponseProps> | Promise<void> | Promise<Error>;
|
|
555
510
|
/**
|
|
556
511
|
* Set the global mock handler used by all {@link FaasBrowserClient} instances.
|
|
557
512
|
*
|
|
558
|
-
* @param handler - Mock handler, can be:
|
|
513
|
+
* @param {MockHandler | ResponseProps | Response | null | undefined} handler - Mock handler, can be:
|
|
559
514
|
* - MockHandler function: receives (action, params, options) and returns response data
|
|
560
515
|
* - ResponseProps object: static response data
|
|
561
516
|
* - Response instance: pre-configured Response object
|
|
@@ -711,8 +666,8 @@ declare function setMock(handler: MockHandler | ResponseProps | Response | null
|
|
|
711
666
|
*
|
|
712
667
|
* @throws {Error} When baseUrl does not end with '/'
|
|
713
668
|
*
|
|
714
|
-
* @see setMock for testing support
|
|
715
|
-
* @see ResponseError for error handling
|
|
669
|
+
* @see {@link setMock} for testing support.
|
|
670
|
+
* @see {@link ResponseError} for error handling.
|
|
716
671
|
*/
|
|
717
672
|
declare class FaasBrowserClient {
|
|
718
673
|
/**
|
|
@@ -730,8 +685,8 @@ declare class FaasBrowserClient {
|
|
|
730
685
|
/**
|
|
731
686
|
* Creates a new FaasBrowserClient instance.
|
|
732
687
|
*
|
|
733
|
-
* @param baseUrl - Base URL for all API requests. Must end with `/`. Defaults to `/` for relative requests.
|
|
734
|
-
* @param options - Default request options such as headers, hooks, request override, or stream mode.
|
|
688
|
+
* @param {BaseUrl} [baseUrl] - Base URL for all API requests. Must end with `/`. Defaults to `/` for relative requests.
|
|
689
|
+
* @param {Options} [options] - Default request options such as headers, hooks, request override, or stream mode.
|
|
735
690
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
736
691
|
* `request`, `baseUrl`, and `stream`.
|
|
737
692
|
*
|
|
@@ -791,16 +746,16 @@ declare class FaasBrowserClient {
|
|
|
791
746
|
* Makes a request to a FaasJS function.
|
|
792
747
|
*
|
|
793
748
|
* @template PathOrData - The function path or data type for type safety
|
|
794
|
-
* @param action - The function path to call. Converted to lowercase when constructing the URL.
|
|
749
|
+
* @param {FaasAction<PathOrData>} action - The function path to call. Converted to lowercase when constructing the URL.
|
|
795
750
|
* Must be a non-empty string.
|
|
796
|
-
* @param params - The parameters to send to the function. Will be serialized as JSON.
|
|
751
|
+
* @param {FaasParams<PathOrData>} [params] - The parameters to send to the function. Will be serialized as JSON.
|
|
797
752
|
* Optional if the function accepts no parameters.
|
|
798
|
-
* @param options - Optional request options that override client defaults.
|
|
753
|
+
* @param {Options} [options] - Optional request options that override client defaults.
|
|
799
754
|
* Supports headers, beforeRequest hook, custom request function, baseUrl override, and streaming mode.
|
|
800
755
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
801
756
|
* `request`, `baseUrl`, and `stream`.
|
|
802
757
|
*
|
|
803
|
-
* @returns A promise resolving to the wrapped FaasJS response. When `options.stream`
|
|
758
|
+
* @returns {Promise<Response<FaasData<PathOrData>>>} A promise resolving to the wrapped FaasJS response. When `options.stream`
|
|
804
759
|
* is `true`, the runtime returns the native fetch response so callers can read the stream.
|
|
805
760
|
*
|
|
806
761
|
* @throws {Error} When action is not provided or is empty
|
|
@@ -902,12 +857,12 @@ declare class FaasBrowserClient {
|
|
|
902
857
|
*
|
|
903
858
|
* @template PathOrData - Action path or response data type used for inference.
|
|
904
859
|
*
|
|
905
|
-
* @param action - Action path to invoke.
|
|
906
|
-
* @param params - Parameters sent to the action.
|
|
907
|
-
* @param options - Optional per-request overrides such as headers or base URL.
|
|
908
|
-
* See the
|
|
860
|
+
* @param {FaasAction<PathOrData>} action - Action path to invoke.
|
|
861
|
+
* @param {FaasParams<PathOrData>} params - Parameters sent to the action.
|
|
862
|
+
* @param {Options} [options] - Optional per-request overrides such as headers or base URL.
|
|
863
|
+
* See the browser-client `Options` type for supported fields such as `headers`, `beforeRequest`,
|
|
909
864
|
* `request`, `baseUrl`, and `stream`.
|
|
910
|
-
* @returns Response returned by the active browser client.
|
|
865
|
+
* @returns {Promise<Response<FaasData<PathOrData>>>} Response returned by the active browser client.
|
|
911
866
|
* @throws {ResponseError} When the request fails and the active client does not recover inside `onError`.
|
|
912
867
|
*
|
|
913
868
|
* @example
|
|
@@ -976,16 +931,16 @@ type FaasDataWrapperRef<PathOrData extends FaasActionUnionType$1 = any> = FaasDa
|
|
|
976
931
|
* The wrapper defers rendering `children` or `render` until the first request
|
|
977
932
|
* completes, then keeps passing the latest request state to the rendered output.
|
|
978
933
|
*
|
|
979
|
-
* @param props - Wrapper props controlling the request and rendered fallback.
|
|
980
|
-
* @param props.render - Render prop that receives the resolved Faas request state.
|
|
981
|
-
* @param props.children - Child element cloned with injected Faas request state.
|
|
982
|
-
* @param props.fallback - Element rendered before the first successful load.
|
|
983
|
-
* @param props.action - Action path to request.
|
|
984
|
-
* @param props.params - Params sent to the action.
|
|
985
|
-
* @param props.onDataChange - Callback invoked when the resolved data value changes.
|
|
986
|
-
* @param props.data - Controlled data value used instead of internal state.
|
|
987
|
-
* @param props.setData - Controlled setter used instead of internal state.
|
|
988
|
-
* @param props.baseUrl - Base URL override used for this wrapper instance.
|
|
934
|
+
* @param {FaasDataWrapperProps<PathOrData>} props - Wrapper props controlling the request and rendered fallback.
|
|
935
|
+
* @param {(args: FaasDataInjection<PathOrData>) => JSX.Element | JSX.Element[]} [props.render] - Render prop that receives the resolved Faas request state.
|
|
936
|
+
* @param {React.ReactElement<Partial<FaasDataInjection<PathOrData>>>} [props.children] - Child element cloned with injected Faas request state.
|
|
937
|
+
* @param {JSX.Element | false} [props.fallback] - Element rendered before the first successful load.
|
|
938
|
+
* @param {FaasAction<PathOrData>} props.action - Action path to request.
|
|
939
|
+
* @param {FaasParams<PathOrData>} [props.params] - Params sent to the action.
|
|
940
|
+
* @param {(args: FaasDataInjection<PathOrData>) => void} [props.onDataChange] - Callback invoked when the resolved data value changes.
|
|
941
|
+
* @param {FaasData<PathOrData>} [props.data] - Controlled data value used instead of internal state.
|
|
942
|
+
* @param {React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>} [props.setData] - Controlled setter used instead of internal state.
|
|
943
|
+
* @param {BaseUrl} [props.baseUrl] - Base URL override used for this wrapper instance.
|
|
989
944
|
*
|
|
990
945
|
* @example
|
|
991
946
|
* ```tsx
|
|
@@ -1065,9 +1020,9 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType$1 = any>(
|
|
|
1065
1020
|
*
|
|
1066
1021
|
* @template PathOrData - Action path or response data type used for inference.
|
|
1067
1022
|
* @template TComponentProps - Component props including injected Faas data fields.
|
|
1068
|
-
* @param Component - Component that consumes injected Faas data props.
|
|
1069
|
-
* @param faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
1070
|
-
* @returns Component that accepts the original props minus the injected Faas data fields.
|
|
1023
|
+
* @param {React.FC<TComponentProps>} Component - Component that consumes injected Faas data props.
|
|
1024
|
+
* @param {FaasDataWrapperProps<PathOrData>} faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
1025
|
+
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>> & Record<string, any>>} Component that accepts the original props minus the injected Faas data fields.
|
|
1071
1026
|
*
|
|
1072
1027
|
* @example
|
|
1073
1028
|
* ```tsx
|
|
@@ -1092,6 +1047,16 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType$1 = any>(
|
|
|
1092
1047
|
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>>;
|
|
1093
1048
|
//#endregion
|
|
1094
1049
|
//#region src/useFaasRequest.d.ts
|
|
1050
|
+
/**
|
|
1051
|
+
* Shared request options consumed by `useFaas` and `useFaasStream`.
|
|
1052
|
+
*
|
|
1053
|
+
* @property {Params} [params] - Controlled params override sent with the request without mutating local params state.
|
|
1054
|
+
* @property {Data} [data] - Controlled data value used by higher-level hooks.
|
|
1055
|
+
* @property {React.Dispatch<React.SetStateAction<Data>>} [setData] - Controlled setter paired with `data`.
|
|
1056
|
+
* @property {boolean | ((params: Params) => boolean)} [skip] - Boolean or predicate that suppresses the automatic request.
|
|
1057
|
+
* @property {number} [debounce] - Milliseconds to wait before sending the latest request.
|
|
1058
|
+
* @property {BaseUrl} [baseUrl] - Base URL override used for this request lifecycle.
|
|
1059
|
+
*/
|
|
1095
1060
|
type SharedUseFaasOptions<Params, Data> = {
|
|
1096
1061
|
params?: Params;
|
|
1097
1062
|
data?: Data;
|
|
@@ -1117,16 +1082,11 @@ type useFaasOptions<PathOrData extends FaasActionUnionType$1> = SharedUseFaasOpt
|
|
|
1117
1082
|
*
|
|
1118
1083
|
* @template PathOrData - Action path or response data type used for inference.
|
|
1119
1084
|
*
|
|
1120
|
-
* @param action - Action path to invoke.
|
|
1121
|
-
* @param defaultParams - Params used for the initial request and future reloads.
|
|
1122
|
-
* @param options - Optional hook configuration such as controlled data, debounce, and
|
|
1123
|
-
*
|
|
1124
|
-
* @
|
|
1125
|
-
* @param options.setData - Controlled setter used instead of the hook's internal `setData`.
|
|
1126
|
-
* @param options.skip - Boolean or predicate that suppresses the automatic request until `reload()` runs.
|
|
1127
|
-
* @param options.debounce - Milliseconds to wait before sending the latest request.
|
|
1128
|
-
* @param options.baseUrl - Base URL override used for this hook instance.
|
|
1129
|
-
* @returns Request state and helper methods described by {@link FaasDataInjection}.
|
|
1085
|
+
* @param {FaasAction<PathOrData>} action - Action path to invoke.
|
|
1086
|
+
* @param {FaasParams<PathOrData>} defaultParams - Params used for the initial request and future reloads.
|
|
1087
|
+
* @param {useFaasOptions<PathOrData>} [options] - Optional hook configuration such as controlled data, skip logic, debounce timing, and base URL overrides.
|
|
1088
|
+
* See the `useFaasOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, and `baseUrl`.
|
|
1089
|
+
* @returns {FaasDataInjection<PathOrData>} Request state and helper methods described by {@link FaasDataInjection}.
|
|
1130
1090
|
*
|
|
1131
1091
|
* @example
|
|
1132
1092
|
* ```tsx
|
|
@@ -1165,9 +1125,9 @@ declare function useFaas<PathOrData extends FaasActionUnionType$1>(action: FaasA
|
|
|
1165
1125
|
/**
|
|
1166
1126
|
* Factory for per-request error handlers used by {@link FaasReactClient}.
|
|
1167
1127
|
*
|
|
1168
|
-
* @param action - Action name that failed.
|
|
1169
|
-
* @param params - Params sent with the failed request.
|
|
1170
|
-
* @returns Async callback invoked with the resulting {@link ResponseError}.
|
|
1128
|
+
* @param {string} action - Action name that failed.
|
|
1129
|
+
* @param {Record<string, any>} params - Params sent with the failed request.
|
|
1130
|
+
* @returns {(res: ResponseError) => Promise<void>} Async callback invoked with the resulting {@link ResponseError}.
|
|
1171
1131
|
*/
|
|
1172
1132
|
type OnError = (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
1173
1133
|
/**
|
|
@@ -1212,13 +1172,13 @@ type FaasReactClientInstance = {
|
|
|
1212
1172
|
* The returned client is stored by `baseUrl` and becomes the default client
|
|
1213
1173
|
* used by helpers such as {@link faas} and {@link useFaas}.
|
|
1214
1174
|
*
|
|
1215
|
-
* @param options - Client configuration including base URL, default request options, and error hooks.
|
|
1216
|
-
* @param options.baseUrl - Base URL used to register and route the client instance.
|
|
1217
|
-
* @param options.options - Default browser-client request options forwarded to `FaasBrowserClient`.
|
|
1218
|
-
* @param options.onError - Hook factory used to handle failed `faas` and `useFaas` requests.
|
|
1175
|
+
* @param {FaasReactClientOptions} [options] - Client configuration including base URL, default request options, and error hooks.
|
|
1176
|
+
* @param {BaseUrl} [options.baseUrl] - Base URL used to register and route the client instance.
|
|
1177
|
+
* @param {Options} [options.options] - Default browser-client request options forwarded to `FaasBrowserClient`.
|
|
1178
|
+
* @param {OnError} [options.onError] - Hook factory used to handle failed `faas` and `useFaas` requests.
|
|
1219
1179
|
* See {@link Options} for supported browser-client request fields such as `headers`,
|
|
1220
1180
|
* `beforeRequest`, `request`, `baseUrl`, and `stream`.
|
|
1221
|
-
* @returns Registered FaasReactClient instance.
|
|
1181
|
+
* @returns {FaasReactClientInstance} Registered FaasReactClient instance.
|
|
1222
1182
|
*
|
|
1223
1183
|
* @example
|
|
1224
1184
|
* ```ts
|
|
@@ -1247,8 +1207,8 @@ declare function FaasReactClient(options?: FaasReactClientOptions): FaasReactCli
|
|
|
1247
1207
|
* different base URLs. In normal single-client app code, prefer the default
|
|
1248
1208
|
* `faas`, `useFaas`, or `FaasReactClient` setup directly.
|
|
1249
1209
|
*
|
|
1250
|
-
* @param host - Registered base URL to look up. Omit it to use the default client.
|
|
1251
|
-
* @returns Registered or newly created FaasReactClient instance.
|
|
1210
|
+
* @param {string} [host] - Registered base URL to look up. Omit it to use the default client.
|
|
1211
|
+
* @returns {FaasReactClientInstance} Registered or newly created FaasReactClient instance.
|
|
1252
1212
|
*
|
|
1253
1213
|
* @example
|
|
1254
1214
|
* ```ts
|
|
@@ -1274,7 +1234,8 @@ declare function getClient(host?: string): FaasReactClientInstance;
|
|
|
1274
1234
|
* Returns a constant value that is created by the given function.
|
|
1275
1235
|
*
|
|
1276
1236
|
* @template T - Constant value type returned by the initializer.
|
|
1277
|
-
* @param fn - Initializer that runs only once for the current component instance.
|
|
1237
|
+
* @param {() => T} fn - Initializer that runs only once for the current component instance.
|
|
1238
|
+
* @returns {T} Stable value returned by the initializer.
|
|
1278
1239
|
*
|
|
1279
1240
|
* @example
|
|
1280
1241
|
* ```tsx
|
|
@@ -1341,23 +1302,23 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
|
1341
1302
|
/**
|
|
1342
1303
|
* Create an error boundary with empty error state.
|
|
1343
1304
|
*
|
|
1344
|
-
* @param props - Boundary props.
|
|
1345
|
-
* @param props.children - Descendant elements protected by the boundary.
|
|
1346
|
-
* @param props.onError - Callback invoked after a render error is captured.
|
|
1347
|
-
* @param props.errorChildren - Custom fallback element that receives error details.
|
|
1305
|
+
* @param {ErrorBoundaryProps} props - Boundary props.
|
|
1306
|
+
* @param {ReactNode} [props.children] - Descendant elements protected by the boundary.
|
|
1307
|
+
* @param {(error: Error | null, info: any) => void} [props.onError] - Callback invoked after a render error is captured.
|
|
1308
|
+
* @param {ReactElement<ErrorChildrenProps>} [props.errorChildren] - Custom fallback element that receives error details.
|
|
1348
1309
|
*/
|
|
1349
1310
|
constructor(props: ErrorBoundaryProps);
|
|
1350
1311
|
/**
|
|
1351
1312
|
* Capture rendering errors from descendant components.
|
|
1352
1313
|
*
|
|
1353
|
-
* @param error - Caught render error.
|
|
1354
|
-
* @param info - React component stack metadata.
|
|
1314
|
+
* @param {Error} error - Caught render error.
|
|
1315
|
+
* @param {ErrorInfo} info - React component stack metadata.
|
|
1355
1316
|
*/
|
|
1356
1317
|
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
1357
1318
|
/**
|
|
1358
1319
|
* Render children or the configured fallback for the captured error.
|
|
1359
1320
|
*/
|
|
1360
|
-
render(): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | _$react.ReactPortal | ReactElement<unknown, string | _$react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> |
|
|
1321
|
+
render(): string | number | bigint | boolean | _$react_jsx_runtime0.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | _$react.ReactPortal | ReactElement<unknown, string | _$react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
|
|
1361
1322
|
}
|
|
1362
1323
|
//#endregion
|
|
1363
1324
|
//#region src/equal.d.ts
|
|
@@ -1368,9 +1329,9 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
|
1368
1329
|
* It handles various data types including primitives, arrays, dates, regular expressions, functions,
|
|
1369
1330
|
* maps, sets, and promises.
|
|
1370
1331
|
*
|
|
1371
|
-
* @param a - The first value to compare.
|
|
1372
|
-
* @param b - The second value to compare.
|
|
1373
|
-
* @returns `true` if the values are deeply equal, `false` otherwise.
|
|
1332
|
+
* @param {any} a - The first value to compare.
|
|
1333
|
+
* @param {any} b - The second value to compare.
|
|
1334
|
+
* @returns {boolean} `true` if the values are deeply equal, `false` otherwise.
|
|
1374
1335
|
*
|
|
1375
1336
|
* @example
|
|
1376
1337
|
* ```ts
|
|
@@ -1384,8 +1345,8 @@ declare function equal(a: any, b: any): boolean;
|
|
|
1384
1345
|
/**
|
|
1385
1346
|
* Custom hook that memoizes a value using deep equality comparison.
|
|
1386
1347
|
*
|
|
1387
|
-
* @param value - The value to be memoized.
|
|
1388
|
-
* @returns The memoized value.
|
|
1348
|
+
* @param {any} value - The value to be memoized.
|
|
1349
|
+
* @returns {any} The memoized value.
|
|
1389
1350
|
*
|
|
1390
1351
|
* @example
|
|
1391
1352
|
* ```tsx
|
|
@@ -1402,9 +1363,9 @@ declare function useEqualMemoize(value: any): any;
|
|
|
1402
1363
|
/**
|
|
1403
1364
|
* Custom hook that works like `useEffect` but uses deep comparison on dependencies.
|
|
1404
1365
|
*
|
|
1405
|
-
* @param callback - The effect callback function to run.
|
|
1406
|
-
* @param dependencies - The list of dependencies for the effect.
|
|
1407
|
-
* @returns The result of the `useEffect` hook with memoized dependencies.
|
|
1366
|
+
* @param {React.EffectCallback} callback - The effect callback function to run.
|
|
1367
|
+
* @param {any[]} dependencies - The list of dependencies for the effect.
|
|
1368
|
+
* @returns {void} The result of the `useEffect` hook with memoized dependencies.
|
|
1408
1369
|
*
|
|
1409
1370
|
* @example
|
|
1410
1371
|
* ```tsx
|
|
@@ -1425,9 +1386,9 @@ declare function useEqualEffect(callback: React.EffectCallback, dependencies: an
|
|
|
1425
1386
|
*
|
|
1426
1387
|
* @template T - Memoized value type returned by the callback.
|
|
1427
1388
|
*
|
|
1428
|
-
* @param callback - The callback function to run.
|
|
1429
|
-
* @param dependencies - The list of dependencies.
|
|
1430
|
-
* @returns The result of the `useMemo` hook with memoized dependencies.
|
|
1389
|
+
* @param {() => T} callback - The callback function to run.
|
|
1390
|
+
* @param {any[]} dependencies - The list of dependencies.
|
|
1391
|
+
* @returns {T} The result of the `useMemo` hook with memoized dependencies.
|
|
1431
1392
|
*
|
|
1432
1393
|
* @example
|
|
1433
1394
|
* ```tsx
|
|
@@ -1446,9 +1407,9 @@ declare function useEqualMemo<T>(callback: () => T, dependencies: any[]): T;
|
|
|
1446
1407
|
*
|
|
1447
1408
|
* @template T - Callback signature to memoize.
|
|
1448
1409
|
*
|
|
1449
|
-
* @param callback - The callback function to run.
|
|
1450
|
-
* @param dependencies - The list of dependencies.
|
|
1451
|
-
* @returns The result of the `useCallback` hook with memoized dependencies.
|
|
1410
|
+
* @param {T} callback - The callback function to run.
|
|
1411
|
+
* @param {any[]} dependencies - The list of dependencies.
|
|
1412
|
+
* @returns {T} The result of the `useCallback` hook with memoized dependencies.
|
|
1452
1413
|
*
|
|
1453
1414
|
* @example
|
|
1454
1415
|
* ```tsx
|
|
@@ -1482,12 +1443,12 @@ type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
|
1482
1443
|
/**
|
|
1483
1444
|
* Conditionally wrap children with another component.
|
|
1484
1445
|
*
|
|
1485
|
-
* @param props - Wrapper condition, wrapper component, and child content.
|
|
1486
|
-
* @param props.condition - When `true`, wrap children with `Wrapper`.
|
|
1487
|
-
* @param props.Wrapper - Component used as the wrapper when the condition passes.
|
|
1488
|
-
* @param props.wrapperProps - Props forwarded to the wrapper component.
|
|
1489
|
-
* @param props.children - Content rendered directly or inside the wrapper.
|
|
1490
|
-
* @returns Wrapped children or the original children when `condition` is false.
|
|
1446
|
+
* @param {OptionalWrapperProps} props - Wrapper condition, wrapper component, and child content.
|
|
1447
|
+
* @param {boolean} props.condition - When `true`, wrap children with `Wrapper`.
|
|
1448
|
+
* @param {OptionalWrapperProps['Wrapper']} props.Wrapper - Component used as the wrapper when the condition passes.
|
|
1449
|
+
* @param {OptionalWrapperProps['wrapperProps']} [props.wrapperProps] - Props forwarded to the wrapper component.
|
|
1450
|
+
* @param {ReactNode} props.children - Content rendered directly or inside the wrapper.
|
|
1451
|
+
* @returns {ReactNode} Wrapped children or the original children when `condition` is false.
|
|
1491
1452
|
*
|
|
1492
1453
|
* @example
|
|
1493
1454
|
* ```tsx
|
|
@@ -1504,7 +1465,7 @@ type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
|
1504
1465
|
* )
|
|
1505
1466
|
* ```
|
|
1506
1467
|
*/
|
|
1507
|
-
declare function OptionalWrapper(props: OptionalWrapperProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | _$react.ReactPortal | _$react.ReactElement<unknown, string | _$react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> |
|
|
1468
|
+
declare function OptionalWrapper(props: OptionalWrapperProps): string | number | bigint | boolean | _$react_jsx_runtime0.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | _$react.ReactPortal | _$react.ReactElement<unknown, string | _$react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
|
|
1508
1469
|
declare namespace OptionalWrapper {
|
|
1509
1470
|
var displayName: string;
|
|
1510
1471
|
}
|
|
@@ -1518,8 +1479,8 @@ declare namespace OptionalWrapper {
|
|
|
1518
1479
|
* subscribe to the values they access.
|
|
1519
1480
|
*
|
|
1520
1481
|
* @template T - Context value shape exposed by the provider and hook.
|
|
1521
|
-
* @param defaultValue - Default value map or key list used to create split contexts.
|
|
1522
|
-
* @returns Provider and hook helpers for the split context.
|
|
1482
|
+
* @param {Record<string, any> | (keyof T)[]} defaultValue - Default value map or key list used to create split contexts.
|
|
1483
|
+
* @returns {{ Provider<NewT extends T = T>(this: void, props: { value?: Partial<NewT>; children: ReactNode; memo?: true | any[]; initializeStates?: Partial<NewT> }): ReactNode; use<NewT extends T = T>(this: void): Readonly<NewT> }} Provider and hook helpers for the split context.
|
|
1523
1484
|
*
|
|
1524
1485
|
* @example
|
|
1525
1486
|
* ```tsx
|
|
@@ -1563,7 +1524,7 @@ declare function createSplittingContext<T extends Record<string, any>>(defaultVa
|
|
|
1563
1524
|
/**
|
|
1564
1525
|
* The provider component of the splitting context.
|
|
1565
1526
|
*
|
|
1566
|
-
* @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
|
|
1527
|
+
* @see [Provider docs](https://faasjs.com/doc/react/functions/createSplittingContext.html#provider)
|
|
1567
1528
|
*
|
|
1568
1529
|
* @example
|
|
1569
1530
|
* ```tsx
|
|
@@ -1611,7 +1572,7 @@ declare function createSplittingContext<T extends Record<string, any>>(defaultVa
|
|
|
1611
1572
|
/**
|
|
1612
1573
|
* Hook used to read values from the splitting context.
|
|
1613
1574
|
*
|
|
1614
|
-
* @see https://faasjs.com/doc/react/functions/createSplittingContext.html#use
|
|
1575
|
+
* @see [Hook docs](https://faasjs.com/doc/react/functions/createSplittingContext.html#use)
|
|
1615
1576
|
*
|
|
1616
1577
|
* @example
|
|
1617
1578
|
* ```tsx
|
|
@@ -1642,8 +1603,8 @@ type StatesWithSetters<T> = T & StateSetters<T>;
|
|
|
1642
1603
|
* Create local state entries and matching setters for each key in an object.
|
|
1643
1604
|
*
|
|
1644
1605
|
* @template T - A generic type that extends a record with string keys and any values.
|
|
1645
|
-
* @param initialStates - Object whose keys become state values and `setXxx` setters.
|
|
1646
|
-
* @returns Object containing the original keys plus generated setter functions.
|
|
1606
|
+
* @param {T} initialStates - Object whose keys become state values and `setXxx` setters.
|
|
1607
|
+
* @returns {StatesWithSetters<T>} Object containing the original keys plus generated setter functions.
|
|
1647
1608
|
*
|
|
1648
1609
|
* @example
|
|
1649
1610
|
* ```tsx
|
|
@@ -1683,16 +1644,11 @@ type UseFaasStreamResult = {
|
|
|
1683
1644
|
* It sends a streaming request, appends decoded text chunks to `data`, and
|
|
1684
1645
|
* exposes reload helpers for retrying the same action.
|
|
1685
1646
|
*
|
|
1686
|
-
* @param action - Action path to invoke.
|
|
1687
|
-
* @param defaultParams - Params used for the initial request and future reloads.
|
|
1688
|
-
* @param options - Optional hook configuration such as controlled
|
|
1689
|
-
*
|
|
1690
|
-
* @
|
|
1691
|
-
* @param options.setData - Controlled setter used instead of the hook's internal `setData`.
|
|
1692
|
-
* @param options.skip - Boolean or predicate that suppresses the automatic request until `reload()` runs.
|
|
1693
|
-
* @param options.debounce - Milliseconds to wait before sending the latest request.
|
|
1694
|
-
* @param options.baseUrl - Base URL override used for this hook instance.
|
|
1695
|
-
* @returns Streaming request state and helper methods described by {@link UseFaasStreamResult}.
|
|
1647
|
+
* @param {string} action - Action path to invoke.
|
|
1648
|
+
* @param {Record<string, any>} defaultParams - Params used for the initial request and future reloads.
|
|
1649
|
+
* @param {UseFaasStreamOptions} [options] - Optional hook configuration such as controlled stream text, skip logic, debounce timing, and base URL overrides.
|
|
1650
|
+
* See the `UseFaasStreamOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, and `baseUrl`.
|
|
1651
|
+
* @returns {UseFaasStreamResult} Streaming request state and helper methods described by {@link UseFaasStreamResult}.
|
|
1696
1652
|
*
|
|
1697
1653
|
* @example
|
|
1698
1654
|
* ```tsx
|
|
@@ -1725,8 +1681,8 @@ declare function useFaasStream(action: string, defaultParams: Record<string, any
|
|
|
1725
1681
|
* Hook to store the previous value of a state or prop.
|
|
1726
1682
|
*
|
|
1727
1683
|
* @template T - The type of the value.
|
|
1728
|
-
* @param value - The current value to track.
|
|
1729
|
-
* @returns Previous value from the prior render, or `undefined` on the first render.
|
|
1684
|
+
* @param {T} value - The current value to track.
|
|
1685
|
+
* @returns {T | undefined} Previous value from the prior render, or `undefined` on the first render.
|
|
1730
1686
|
*
|
|
1731
1687
|
* @example
|
|
1732
1688
|
* ```tsx
|
|
@@ -1746,8 +1702,8 @@ declare function usePrevious<T = any>(value: T): T | undefined;
|
|
|
1746
1702
|
* Custom hook that returns a stateful value and a ref to that value.
|
|
1747
1703
|
*
|
|
1748
1704
|
* @template T - The type of the value.
|
|
1749
|
-
* @param initialValue - Initial state value. When omitted, state starts as `null`.
|
|
1750
|
-
* @returns Tuple containing the current state, the state setter, and a ref that always points at the latest state.
|
|
1705
|
+
* @param {T} [initialValue] - Initial state value. When omitted, state starts as `null`.
|
|
1706
|
+
* @returns {[T | null, Dispatch<SetStateAction<T | null>>, RefObject<T | null>]} Tuple containing the current state, the state setter, and a ref that always points at the latest state.
|
|
1751
1707
|
*
|
|
1752
1708
|
* @example
|
|
1753
1709
|
* ```tsx
|
package/dist/index.mjs
CHANGED
|
@@ -4,13 +4,15 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a random identifier with an optional prefix.
|
|
6
6
|
*
|
|
7
|
-
* @param prefix - Prefix prepended to the generated identifier.
|
|
8
|
-
* @param length - Length of the generated identifier excluding `prefix`. Must be between `8` and `18`.
|
|
9
|
-
* @returns Generated identifier string.
|
|
7
|
+
* @param {string} [prefix] - Prefix prepended to the generated identifier.
|
|
8
|
+
* @param {number} [length] - Length of the generated identifier excluding `prefix`. Must be between `8` and `18`.
|
|
9
|
+
* @returns {string} Generated identifier string.
|
|
10
10
|
* @throws {Error} When `length` is outside the supported `8` to `18` range.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
+
* import { generateId } from '@faasjs/react'
|
|
15
|
+
*
|
|
14
16
|
* const id = generateId('prefix-')
|
|
15
17
|
*
|
|
16
18
|
* id.startsWith('prefix-') // true
|
|
@@ -133,9 +135,9 @@ function generateId(prefix = "", length = 18) {
|
|
|
133
135
|
* })
|
|
134
136
|
* ```
|
|
135
137
|
*
|
|
136
|
-
* @see ResponseProps for response property type
|
|
137
|
-
* @see ResponseError for error response handling
|
|
138
|
-
* @see FaasBrowserClient.action for method returning Response
|
|
138
|
+
* @see {@link ResponseProps} for response property type.
|
|
139
|
+
* @see {@link ResponseError} for error response handling.
|
|
140
|
+
* @see {@link FaasBrowserClient.action} for method returning Response.
|
|
139
141
|
*/
|
|
140
142
|
var Response = class {
|
|
141
143
|
/**
|
|
@@ -157,12 +159,12 @@ var Response = class {
|
|
|
157
159
|
/**
|
|
158
160
|
* Create a wrapped response object.
|
|
159
161
|
*
|
|
160
|
-
* @param props - Response properties including status, headers, body, and data.
|
|
161
|
-
* @param props.status - HTTP status code. Defaults to `200` when `data` or `body` exists, otherwise `204`.
|
|
162
|
-
* @param props.headers - Response headers keyed by header name.
|
|
163
|
-
* @param props.body - Raw response body to expose without additional parsing.
|
|
164
|
-
* @param props.data - Parsed response payload to expose on `response.data`.
|
|
165
|
-
* @returns Wrapped response instance.
|
|
162
|
+
* @param {ResponseProps<T>} [props] - Response properties including status, headers, body, and data.
|
|
163
|
+
* @param {number} [props.status] - HTTP status code. Defaults to `200` when `data` or `body` exists, otherwise `204`.
|
|
164
|
+
* @param {ResponseHeaders} [props.headers] - Response headers keyed by header name.
|
|
165
|
+
* @param {any} [props.body] - Raw response body to expose without additional parsing.
|
|
166
|
+
* @param {T} [props.data] - Parsed response payload to expose on `response.data`.
|
|
167
|
+
* @returns {Response<T>} Wrapped response instance.
|
|
166
168
|
*/
|
|
167
169
|
constructor(props = {}) {
|
|
168
170
|
this.status = props.status || (props.data || props.body ? 200 : 204);
|
|
@@ -264,9 +266,9 @@ var Response = class {
|
|
|
264
266
|
* - Use instanceof ResponseError to distinguish FaasJS errors from other JavaScript errors
|
|
265
267
|
* - The body property can contain structured error information from the server response
|
|
266
268
|
*
|
|
267
|
-
* @see FaasBrowserClient.action for how ResponseError is thrown in requests
|
|
268
|
-
* @see ResponseProps for the structure of response data
|
|
269
|
-
* @see setMock for mocking errors in tests
|
|
269
|
+
* @see {@link FaasBrowserClient.action} for how ResponseError is thrown in requests.
|
|
270
|
+
* @see {@link ResponseProps} for the structure of response data.
|
|
271
|
+
* @see {@link setMock} for mocking errors in tests.
|
|
270
272
|
*/
|
|
271
273
|
var ResponseError = class extends Error {
|
|
272
274
|
/**
|
|
@@ -308,7 +310,7 @@ let mock = null;
|
|
|
308
310
|
/**
|
|
309
311
|
* Set the global mock handler used by all {@link FaasBrowserClient} instances.
|
|
310
312
|
*
|
|
311
|
-
* @param handler - Mock handler, can be:
|
|
313
|
+
* @param {MockHandler | ResponseProps | Response | null | undefined} handler - Mock handler, can be:
|
|
312
314
|
* - MockHandler function: receives (action, params, options) and returns response data
|
|
313
315
|
* - ResponseProps object: static response data
|
|
314
316
|
* - Response instance: pre-configured Response object
|
|
@@ -466,8 +468,8 @@ function setMock(handler) {
|
|
|
466
468
|
*
|
|
467
469
|
* @throws {Error} When baseUrl does not end with '/'
|
|
468
470
|
*
|
|
469
|
-
* @see setMock for testing support
|
|
470
|
-
* @see ResponseError for error handling
|
|
471
|
+
* @see {@link setMock} for testing support.
|
|
472
|
+
* @see {@link ResponseError} for error handling.
|
|
471
473
|
*/
|
|
472
474
|
var FaasBrowserClient = class {
|
|
473
475
|
/**
|
|
@@ -485,8 +487,8 @@ var FaasBrowserClient = class {
|
|
|
485
487
|
/**
|
|
486
488
|
* Creates a new FaasBrowserClient instance.
|
|
487
489
|
*
|
|
488
|
-
* @param baseUrl - Base URL for all API requests. Must end with `/`. Defaults to `/` for relative requests.
|
|
489
|
-
* @param options - Default request options such as headers, hooks, request override, or stream mode.
|
|
490
|
+
* @param {BaseUrl} [baseUrl] - Base URL for all API requests. Must end with `/`. Defaults to `/` for relative requests.
|
|
491
|
+
* @param {Options} [options] - Default request options such as headers, hooks, request override, or stream mode.
|
|
490
492
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
491
493
|
* `request`, `baseUrl`, and `stream`.
|
|
492
494
|
*
|
|
@@ -552,16 +554,16 @@ var FaasBrowserClient = class {
|
|
|
552
554
|
* Makes a request to a FaasJS function.
|
|
553
555
|
*
|
|
554
556
|
* @template PathOrData - The function path or data type for type safety
|
|
555
|
-
* @param action - The function path to call. Converted to lowercase when constructing the URL.
|
|
557
|
+
* @param {FaasAction<PathOrData>} action - The function path to call. Converted to lowercase when constructing the URL.
|
|
556
558
|
* Must be a non-empty string.
|
|
557
|
-
* @param params - The parameters to send to the function. Will be serialized as JSON.
|
|
559
|
+
* @param {FaasParams<PathOrData>} [params] - The parameters to send to the function. Will be serialized as JSON.
|
|
558
560
|
* Optional if the function accepts no parameters.
|
|
559
|
-
* @param options - Optional request options that override client defaults.
|
|
561
|
+
* @param {Options} [options] - Optional request options that override client defaults.
|
|
560
562
|
* Supports headers, beforeRequest hook, custom request function, baseUrl override, and streaming mode.
|
|
561
563
|
* See {@link Options} for supported request fields such as `headers`, `beforeRequest`,
|
|
562
564
|
* `request`, `baseUrl`, and `stream`.
|
|
563
565
|
*
|
|
564
|
-
* @returns A promise resolving to the wrapped FaasJS response. When `options.stream`
|
|
566
|
+
* @returns {Promise<Response<FaasData<PathOrData>>>} A promise resolving to the wrapped FaasJS response. When `options.stream`
|
|
565
567
|
* is `true`, the runtime returns the native fetch response so callers can read the stream.
|
|
566
568
|
*
|
|
567
569
|
* @throws {Error} When action is not provided or is empty
|
|
@@ -745,12 +747,12 @@ var FaasBrowserClient = class {
|
|
|
745
747
|
*
|
|
746
748
|
* @template PathOrData - Action path or response data type used for inference.
|
|
747
749
|
*
|
|
748
|
-
* @param action - Action path to invoke.
|
|
749
|
-
* @param params - Parameters sent to the action.
|
|
750
|
-
* @param options - Optional per-request overrides such as headers or base URL.
|
|
751
|
-
* See the
|
|
750
|
+
* @param {FaasAction<PathOrData>} action - Action path to invoke.
|
|
751
|
+
* @param {FaasParams<PathOrData>} params - Parameters sent to the action.
|
|
752
|
+
* @param {Options} [options] - Optional per-request overrides such as headers or base URL.
|
|
753
|
+
* See the browser-client `Options` type for supported fields such as `headers`, `beforeRequest`,
|
|
752
754
|
* `request`, `baseUrl`, and `stream`.
|
|
753
|
-
* @returns Response returned by the active browser client.
|
|
755
|
+
* @returns {Promise<Response<FaasData<PathOrData>>>} Response returned by the active browser client.
|
|
754
756
|
* @throws {ResponseError} When the request fails and the active client does not recover inside `onError`.
|
|
755
757
|
*
|
|
756
758
|
* @example
|
|
@@ -781,9 +783,9 @@ const AsyncFunction = (async () => {}).constructor;
|
|
|
781
783
|
* It handles various data types including primitives, arrays, dates, regular expressions, functions,
|
|
782
784
|
* maps, sets, and promises.
|
|
783
785
|
*
|
|
784
|
-
* @param a - The first value to compare.
|
|
785
|
-
* @param b - The second value to compare.
|
|
786
|
-
* @returns `true` if the values are deeply equal, `false` otherwise.
|
|
786
|
+
* @param {any} a - The first value to compare.
|
|
787
|
+
* @param {any} b - The second value to compare.
|
|
788
|
+
* @returns {boolean} `true` if the values are deeply equal, `false` otherwise.
|
|
787
789
|
*
|
|
788
790
|
* @example
|
|
789
791
|
* ```ts
|
|
@@ -824,8 +826,8 @@ function equal(a, b) {
|
|
|
824
826
|
/**
|
|
825
827
|
* Custom hook that memoizes a value using deep equality comparison.
|
|
826
828
|
*
|
|
827
|
-
* @param value - The value to be memoized.
|
|
828
|
-
* @returns The memoized value.
|
|
829
|
+
* @param {any} value - The value to be memoized.
|
|
830
|
+
* @returns {any} The memoized value.
|
|
829
831
|
*
|
|
830
832
|
* @example
|
|
831
833
|
* ```tsx
|
|
@@ -855,9 +857,9 @@ function useEqualSignal(value) {
|
|
|
855
857
|
/**
|
|
856
858
|
* Custom hook that works like `useEffect` but uses deep comparison on dependencies.
|
|
857
859
|
*
|
|
858
|
-
* @param callback - The effect callback function to run.
|
|
859
|
-
* @param dependencies - The list of dependencies for the effect.
|
|
860
|
-
* @returns The result of the `useEffect` hook with memoized dependencies.
|
|
860
|
+
* @param {React.EffectCallback} callback - The effect callback function to run.
|
|
861
|
+
* @param {any[]} dependencies - The list of dependencies for the effect.
|
|
862
|
+
* @returns {void} The result of the `useEffect` hook with memoized dependencies.
|
|
861
863
|
*
|
|
862
864
|
* @example
|
|
863
865
|
* ```tsx
|
|
@@ -880,9 +882,9 @@ function useEqualEffect(callback, dependencies) {
|
|
|
880
882
|
*
|
|
881
883
|
* @template T - Memoized value type returned by the callback.
|
|
882
884
|
*
|
|
883
|
-
* @param callback - The callback function to run.
|
|
884
|
-
* @param dependencies - The list of dependencies.
|
|
885
|
-
* @returns The result of the `useMemo` hook with memoized dependencies.
|
|
885
|
+
* @param {() => T} callback - The callback function to run.
|
|
886
|
+
* @param {any[]} dependencies - The list of dependencies.
|
|
887
|
+
* @returns {T} The result of the `useMemo` hook with memoized dependencies.
|
|
886
888
|
*
|
|
887
889
|
* @example
|
|
888
890
|
* ```tsx
|
|
@@ -908,9 +910,9 @@ function useEqualMemo(callback, dependencies) {
|
|
|
908
910
|
*
|
|
909
911
|
* @template T - Callback signature to memoize.
|
|
910
912
|
*
|
|
911
|
-
* @param callback - The callback function to run.
|
|
912
|
-
* @param dependencies - The list of dependencies.
|
|
913
|
-
* @returns The result of the `useCallback` hook with memoized dependencies.
|
|
913
|
+
* @param {T} callback - The callback function to run.
|
|
914
|
+
* @param {any[]} dependencies - The list of dependencies.
|
|
915
|
+
* @returns {T} The result of the `useCallback` hook with memoized dependencies.
|
|
914
916
|
*
|
|
915
917
|
* @example
|
|
916
918
|
* ```tsx
|
|
@@ -934,16 +936,16 @@ function useEqualCallback(callback, dependencies) {
|
|
|
934
936
|
* The wrapper defers rendering `children` or `render` until the first request
|
|
935
937
|
* completes, then keeps passing the latest request state to the rendered output.
|
|
936
938
|
*
|
|
937
|
-
* @param props - Wrapper props controlling the request and rendered fallback.
|
|
938
|
-
* @param props.render - Render prop that receives the resolved Faas request state.
|
|
939
|
-
* @param props.children - Child element cloned with injected Faas request state.
|
|
940
|
-
* @param props.fallback - Element rendered before the first successful load.
|
|
941
|
-
* @param props.action - Action path to request.
|
|
942
|
-
* @param props.params - Params sent to the action.
|
|
943
|
-
* @param props.onDataChange - Callback invoked when the resolved data value changes.
|
|
944
|
-
* @param props.data - Controlled data value used instead of internal state.
|
|
945
|
-
* @param props.setData - Controlled setter used instead of internal state.
|
|
946
|
-
* @param props.baseUrl - Base URL override used for this wrapper instance.
|
|
939
|
+
* @param {FaasDataWrapperProps<PathOrData>} props - Wrapper props controlling the request and rendered fallback.
|
|
940
|
+
* @param {(args: FaasDataInjection<PathOrData>) => JSX.Element | JSX.Element[]} [props.render] - Render prop that receives the resolved Faas request state.
|
|
941
|
+
* @param {React.ReactElement<Partial<FaasDataInjection<PathOrData>>>} [props.children] - Child element cloned with injected Faas request state.
|
|
942
|
+
* @param {JSX.Element | false} [props.fallback] - Element rendered before the first successful load.
|
|
943
|
+
* @param {FaasAction<PathOrData>} props.action - Action path to request.
|
|
944
|
+
* @param {FaasParams<PathOrData>} [props.params] - Params sent to the action.
|
|
945
|
+
* @param {(args: FaasDataInjection<PathOrData>) => void} [props.onDataChange] - Callback invoked when the resolved data value changes.
|
|
946
|
+
* @param {FaasData<PathOrData>} [props.data] - Controlled data value used instead of internal state.
|
|
947
|
+
* @param {React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>} [props.setData] - Controlled setter used instead of internal state.
|
|
948
|
+
* @param {BaseUrl} [props.baseUrl] - Base URL override used for this wrapper instance.
|
|
947
949
|
*
|
|
948
950
|
* @example
|
|
949
951
|
* ```tsx
|
|
@@ -1052,9 +1054,9 @@ Object.assign(FaasDataWrapper, { displayName: "FaasDataWrapper" });
|
|
|
1052
1054
|
*
|
|
1053
1055
|
* @template PathOrData - Action path or response data type used for inference.
|
|
1054
1056
|
* @template TComponentProps - Component props including injected Faas data fields.
|
|
1055
|
-
* @param Component - Component that consumes injected Faas data props.
|
|
1056
|
-
* @param faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
1057
|
-
* @returns Component that accepts the original props minus the injected Faas data fields.
|
|
1057
|
+
* @param {React.FC<TComponentProps>} Component - Component that consumes injected Faas data props.
|
|
1058
|
+
* @param {FaasDataWrapperProps<PathOrData>} faasProps - Request configuration forwarded to `FaasDataWrapper`.
|
|
1059
|
+
* @returns {React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>> & Record<string, any>>} Component that accepts the original props minus the injected Faas data fields.
|
|
1058
1060
|
*
|
|
1059
1061
|
* @example
|
|
1060
1062
|
* ```tsx
|
|
@@ -1084,6 +1086,41 @@ function withFaasData(Component, faasProps) {
|
|
|
1084
1086
|
}
|
|
1085
1087
|
//#endregion
|
|
1086
1088
|
//#region src/useFaasRequest.ts
|
|
1089
|
+
/**
|
|
1090
|
+
* Run the shared request lifecycle used by the higher-level FaasJS React hooks.
|
|
1091
|
+
*
|
|
1092
|
+
* It manages loading state, abort signals, debounce timing, retry-on-fetch-failure,
|
|
1093
|
+
* and queued reload promises while delegating the actual transport to `send`.
|
|
1094
|
+
*
|
|
1095
|
+
* @template Params - Request params type tracked by the lifecycle.
|
|
1096
|
+
* @template Result - Successful response payload type.
|
|
1097
|
+
* @template RequestPromise - Promise type exposed through `promiseRef`.
|
|
1098
|
+
* @param {UseFaasRequestArgs<Params, Result, RequestPromise>} args - Request lifecycle configuration.
|
|
1099
|
+
* @param {string} args.action - Action path or request key used to trigger the lifecycle.
|
|
1100
|
+
* @param {Params} args.defaultParams - Initial params value stored by the lifecycle.
|
|
1101
|
+
* @param {Pick<SharedUseFaasOptions<Params, Result>, 'params' | 'skip' | 'debounce' | 'baseUrl'>} args.options - Shared request options used by the lifecycle.
|
|
1102
|
+
* @param {() => void} [args.beforeSend] - Optional callback invoked immediately before a request starts.
|
|
1103
|
+
* @param {(result: Result) => void} [args.onSuccess] - Optional callback invoked after a successful response.
|
|
1104
|
+
* @param {UseFaasRequestArgs<Params, Result, RequestPromise>['send']} args.send - Transport function responsible for creating and resolving the request.
|
|
1105
|
+
* @returns Shared request state, reload helpers, and refs used by `useFaas` and `useFaasStream`.
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* function useUserRequest(id: number) {
|
|
1109
|
+
* return useFaasRequest({
|
|
1110
|
+
* action: '/pages/users/get',
|
|
1111
|
+
* defaultParams: { id },
|
|
1112
|
+
* options: {},
|
|
1113
|
+
* send: async ({ action, params, signal, client, setPromise }) => {
|
|
1114
|
+
* const promise = client.faas(action, params, { signal })
|
|
1115
|
+
*
|
|
1116
|
+
* setPromise(promise)
|
|
1117
|
+
*
|
|
1118
|
+
* return (await promise).data as { name: string }
|
|
1119
|
+
* },
|
|
1120
|
+
* })
|
|
1121
|
+
* }
|
|
1122
|
+
* ```
|
|
1123
|
+
*/
|
|
1087
1124
|
function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess, send }) {
|
|
1088
1125
|
const [loading, setLoading] = useState(true);
|
|
1089
1126
|
const [error, setError] = useState();
|
|
@@ -1213,16 +1250,11 @@ function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess,
|
|
|
1213
1250
|
*
|
|
1214
1251
|
* @template PathOrData - Action path or response data type used for inference.
|
|
1215
1252
|
*
|
|
1216
|
-
* @param action - Action path to invoke.
|
|
1217
|
-
* @param defaultParams - Params used for the initial request and future reloads.
|
|
1218
|
-
* @param options - Optional hook configuration such as controlled data, debounce, and
|
|
1219
|
-
*
|
|
1220
|
-
* @
|
|
1221
|
-
* @param options.setData - Controlled setter used instead of the hook's internal `setData`.
|
|
1222
|
-
* @param options.skip - Boolean or predicate that suppresses the automatic request until `reload()` runs.
|
|
1223
|
-
* @param options.debounce - Milliseconds to wait before sending the latest request.
|
|
1224
|
-
* @param options.baseUrl - Base URL override used for this hook instance.
|
|
1225
|
-
* @returns Request state and helper methods described by {@link FaasDataInjection}.
|
|
1253
|
+
* @param {FaasAction<PathOrData>} action - Action path to invoke.
|
|
1254
|
+
* @param {FaasParams<PathOrData>} defaultParams - Params used for the initial request and future reloads.
|
|
1255
|
+
* @param {useFaasOptions<PathOrData>} [options] - Optional hook configuration such as controlled data, skip logic, debounce timing, and base URL overrides.
|
|
1256
|
+
* See the `useFaasOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, and `baseUrl`.
|
|
1257
|
+
* @returns {FaasDataInjection<PathOrData>} Request state and helper methods described by {@link FaasDataInjection}.
|
|
1226
1258
|
*
|
|
1227
1259
|
* @example
|
|
1228
1260
|
* ```tsx
|
|
@@ -1301,13 +1333,13 @@ const clients = {};
|
|
|
1301
1333
|
* The returned client is stored by `baseUrl` and becomes the default client
|
|
1302
1334
|
* used by helpers such as {@link faas} and {@link useFaas}.
|
|
1303
1335
|
*
|
|
1304
|
-
* @param options - Client configuration including base URL, default request options, and error hooks.
|
|
1305
|
-
* @param options.baseUrl - Base URL used to register and route the client instance.
|
|
1306
|
-
* @param options.options - Default browser-client request options forwarded to `FaasBrowserClient`.
|
|
1307
|
-
* @param options.onError - Hook factory used to handle failed `faas` and `useFaas` requests.
|
|
1336
|
+
* @param {FaasReactClientOptions} [options] - Client configuration including base URL, default request options, and error hooks.
|
|
1337
|
+
* @param {BaseUrl} [options.baseUrl] - Base URL used to register and route the client instance.
|
|
1338
|
+
* @param {Options} [options.options] - Default browser-client request options forwarded to `FaasBrowserClient`.
|
|
1339
|
+
* @param {OnError} [options.onError] - Hook factory used to handle failed `faas` and `useFaas` requests.
|
|
1308
1340
|
* See {@link Options} for supported browser-client request fields such as `headers`,
|
|
1309
1341
|
* `beforeRequest`, `request`, `baseUrl`, and `stream`.
|
|
1310
|
-
* @returns Registered FaasReactClient instance.
|
|
1342
|
+
* @returns {FaasReactClientInstance} Registered FaasReactClient instance.
|
|
1311
1343
|
*
|
|
1312
1344
|
* @example
|
|
1313
1345
|
* ```ts
|
|
@@ -1360,8 +1392,8 @@ function FaasReactClient(options = { baseUrl: "/" }) {
|
|
|
1360
1392
|
* different base URLs. In normal single-client app code, prefer the default
|
|
1361
1393
|
* `faas`, `useFaas`, or `FaasReactClient` setup directly.
|
|
1362
1394
|
*
|
|
1363
|
-
* @param host - Registered base URL to look up. Omit it to use the default client.
|
|
1364
|
-
* @returns Registered or newly created FaasReactClient instance.
|
|
1395
|
+
* @param {string} [host] - Registered base URL to look up. Omit it to use the default client.
|
|
1396
|
+
* @returns {FaasReactClientInstance} Registered or newly created FaasReactClient instance.
|
|
1365
1397
|
*
|
|
1366
1398
|
* @example
|
|
1367
1399
|
* ```ts
|
|
@@ -1394,7 +1426,8 @@ function getClient(host) {
|
|
|
1394
1426
|
* Returns a constant value that is created by the given function.
|
|
1395
1427
|
*
|
|
1396
1428
|
* @template T - Constant value type returned by the initializer.
|
|
1397
|
-
* @param fn - Initializer that runs only once for the current component instance.
|
|
1429
|
+
* @param {() => T} fn - Initializer that runs only once for the current component instance.
|
|
1430
|
+
* @returns {T} Stable value returned by the initializer.
|
|
1398
1431
|
*
|
|
1399
1432
|
* @example
|
|
1400
1433
|
* ```tsx
|
|
@@ -1442,10 +1475,10 @@ var ErrorBoundary = class extends Component {
|
|
|
1442
1475
|
/**
|
|
1443
1476
|
* Create an error boundary with empty error state.
|
|
1444
1477
|
*
|
|
1445
|
-
* @param props - Boundary props.
|
|
1446
|
-
* @param props.children - Descendant elements protected by the boundary.
|
|
1447
|
-
* @param props.onError - Callback invoked after a render error is captured.
|
|
1448
|
-
* @param props.errorChildren - Custom fallback element that receives error details.
|
|
1478
|
+
* @param {ErrorBoundaryProps} props - Boundary props.
|
|
1479
|
+
* @param {ReactNode} [props.children] - Descendant elements protected by the boundary.
|
|
1480
|
+
* @param {(error: Error | null, info: any) => void} [props.onError] - Callback invoked after a render error is captured.
|
|
1481
|
+
* @param {ReactElement<ErrorChildrenProps>} [props.errorChildren] - Custom fallback element that receives error details.
|
|
1449
1482
|
*/
|
|
1450
1483
|
constructor(props) {
|
|
1451
1484
|
super(props);
|
|
@@ -1457,8 +1490,8 @@ var ErrorBoundary = class extends Component {
|
|
|
1457
1490
|
/**
|
|
1458
1491
|
* Capture rendering errors from descendant components.
|
|
1459
1492
|
*
|
|
1460
|
-
* @param error - Caught render error.
|
|
1461
|
-
* @param info - React component stack metadata.
|
|
1493
|
+
* @param {Error} error - Caught render error.
|
|
1494
|
+
* @param {ErrorInfo} info - React component stack metadata.
|
|
1462
1495
|
*/
|
|
1463
1496
|
componentDidCatch(error, info) {
|
|
1464
1497
|
this.setState({
|
|
@@ -1491,12 +1524,12 @@ var ErrorBoundary = class extends Component {
|
|
|
1491
1524
|
/**
|
|
1492
1525
|
* Conditionally wrap children with another component.
|
|
1493
1526
|
*
|
|
1494
|
-
* @param props - Wrapper condition, wrapper component, and child content.
|
|
1495
|
-
* @param props.condition - When `true`, wrap children with `Wrapper`.
|
|
1496
|
-
* @param props.Wrapper - Component used as the wrapper when the condition passes.
|
|
1497
|
-
* @param props.wrapperProps - Props forwarded to the wrapper component.
|
|
1498
|
-
* @param props.children - Content rendered directly or inside the wrapper.
|
|
1499
|
-
* @returns Wrapped children or the original children when `condition` is false.
|
|
1527
|
+
* @param {OptionalWrapperProps} props - Wrapper condition, wrapper component, and child content.
|
|
1528
|
+
* @param {boolean} props.condition - When `true`, wrap children with `Wrapper`.
|
|
1529
|
+
* @param {OptionalWrapperProps['Wrapper']} props.Wrapper - Component used as the wrapper when the condition passes.
|
|
1530
|
+
* @param {OptionalWrapperProps['wrapperProps']} [props.wrapperProps] - Props forwarded to the wrapper component.
|
|
1531
|
+
* @param {ReactNode} props.children - Content rendered directly or inside the wrapper.
|
|
1532
|
+
* @returns {ReactNode} Wrapped children or the original children when `condition` is false.
|
|
1500
1533
|
*
|
|
1501
1534
|
* @example
|
|
1502
1535
|
* ```tsx
|
|
@@ -1528,8 +1561,8 @@ OptionalWrapper.displayName = "OptionalWrapper";
|
|
|
1528
1561
|
* Create local state entries and matching setters for each key in an object.
|
|
1529
1562
|
*
|
|
1530
1563
|
* @template T - A generic type that extends a record with string keys and any values.
|
|
1531
|
-
* @param initialStates - Object whose keys become state values and `setXxx` setters.
|
|
1532
|
-
* @returns Object containing the original keys plus generated setter functions.
|
|
1564
|
+
* @param {T} initialStates - Object whose keys become state values and `setXxx` setters.
|
|
1565
|
+
* @returns {StatesWithSetters<T>} Object containing the original keys plus generated setter functions.
|
|
1533
1566
|
*
|
|
1534
1567
|
* @example
|
|
1535
1568
|
* ```tsx
|
|
@@ -1561,8 +1594,8 @@ function useSplittingState(initialStates) {
|
|
|
1561
1594
|
* subscribe to the values they access.
|
|
1562
1595
|
*
|
|
1563
1596
|
* @template T - Context value shape exposed by the provider and hook.
|
|
1564
|
-
* @param defaultValue - Default value map or key list used to create split contexts.
|
|
1565
|
-
* @returns Provider and hook helpers for the split context.
|
|
1597
|
+
* @param {Record<string, any> | (keyof T)[]} defaultValue - Default value map or key list used to create split contexts.
|
|
1598
|
+
* @returns {{ Provider<NewT extends T = T>(this: void, props: { value?: Partial<NewT>; children: ReactNode; memo?: true | any[]; initializeStates?: Partial<NewT> }): ReactNode; use<NewT extends T = T>(this: void): Readonly<NewT> }} Provider and hook helpers for the split context.
|
|
1566
1599
|
*
|
|
1567
1600
|
* @example
|
|
1568
1601
|
* ```tsx
|
|
@@ -1648,16 +1681,11 @@ function createSplittingContext(defaultValue) {
|
|
|
1648
1681
|
* It sends a streaming request, appends decoded text chunks to `data`, and
|
|
1649
1682
|
* exposes reload helpers for retrying the same action.
|
|
1650
1683
|
*
|
|
1651
|
-
* @param action - Action path to invoke.
|
|
1652
|
-
* @param defaultParams - Params used for the initial request and future reloads.
|
|
1653
|
-
* @param options - Optional hook configuration such as controlled
|
|
1654
|
-
*
|
|
1655
|
-
* @
|
|
1656
|
-
* @param options.setData - Controlled setter used instead of the hook's internal `setData`.
|
|
1657
|
-
* @param options.skip - Boolean or predicate that suppresses the automatic request until `reload()` runs.
|
|
1658
|
-
* @param options.debounce - Milliseconds to wait before sending the latest request.
|
|
1659
|
-
* @param options.baseUrl - Base URL override used for this hook instance.
|
|
1660
|
-
* @returns Streaming request state and helper methods described by {@link UseFaasStreamResult}.
|
|
1684
|
+
* @param {string} action - Action path to invoke.
|
|
1685
|
+
* @param {Record<string, any>} defaultParams - Params used for the initial request and future reloads.
|
|
1686
|
+
* @param {UseFaasStreamOptions} [options] - Optional hook configuration such as controlled stream text, skip logic, debounce timing, and base URL overrides.
|
|
1687
|
+
* See the `UseFaasStreamOptions` type for `params`, `data`, `setData`, `skip`, `debounce`, and `baseUrl`.
|
|
1688
|
+
* @returns {UseFaasStreamResult} Streaming request state and helper methods described by {@link UseFaasStreamResult}.
|
|
1661
1689
|
*
|
|
1662
1690
|
* @example
|
|
1663
1691
|
* ```tsx
|
|
@@ -1732,8 +1760,8 @@ function useFaasStream(action, defaultParams, options = {}) {
|
|
|
1732
1760
|
* Hook to store the previous value of a state or prop.
|
|
1733
1761
|
*
|
|
1734
1762
|
* @template T - The type of the value.
|
|
1735
|
-
* @param value - The current value to track.
|
|
1736
|
-
* @returns Previous value from the prior render, or `undefined` on the first render.
|
|
1763
|
+
* @param {T} value - The current value to track.
|
|
1764
|
+
* @returns {T | undefined} Previous value from the prior render, or `undefined` on the first render.
|
|
1737
1765
|
*
|
|
1738
1766
|
* @example
|
|
1739
1767
|
* ```tsx
|
|
@@ -1759,8 +1787,8 @@ function usePrevious(value) {
|
|
|
1759
1787
|
* Custom hook that returns a stateful value and a ref to that value.
|
|
1760
1788
|
*
|
|
1761
1789
|
* @template T - The type of the value.
|
|
1762
|
-
* @param initialValue - Initial state value. When omitted, state starts as `null`.
|
|
1763
|
-
* @returns Tuple containing the current state, the state setter, and a ref that always points at the latest state.
|
|
1790
|
+
* @param {T} [initialValue] - Initial state value. When omitted, state starts as `null`.
|
|
1791
|
+
* @returns {[T | null, Dispatch<SetStateAction<T | null>>, RefObject<T | null>]} Tuple containing the current state, the state setter, and a ref that always points at the latest state.
|
|
1764
1792
|
*
|
|
1765
1793
|
* @example
|
|
1766
1794
|
* ```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/react",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.23",
|
|
4
4
|
"homepage": "https://faasjs.com/doc/react/",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/faasjs/faasjs/issues"
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@faasjs/types": ">=8.0.0-beta.
|
|
29
|
+
"@faasjs/types": ">=8.0.0-beta.23",
|
|
30
30
|
"@types/react": "^19.0.0",
|
|
31
31
|
"react": "^19.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@faasjs/types": ">=8.0.0-beta.
|
|
34
|
+
"@faasjs/types": ">=8.0.0-beta.23"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=24.0.0",
|