@faasjs/react 8.0.0-beta.35 → 8.0.0-beta.36

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/README.md CHANGED
@@ -6,7 +6,6 @@
6
6
  - [equal](functions/equal.md)
7
7
  - [faas](functions/faas.md)
8
8
  - [FaasReactClient](functions/FaasReactClient.md)
9
- - [generateId](functions/generateId.md)
10
9
  - [getClient](functions/getClient.md)
11
10
  - [OptionalWrapper](functions/OptionalWrapper.md)
12
11
  - [setMock](functions/setMock.md)
package/dist/index.d.ts CHANGED
@@ -1,26 +1,6 @@
1
1
  import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, ReactElement, ReactNode, RefObject, SetStateAction } from "react";
2
2
  import { FaasActionPaths, FaasData, FaasParams } from "@faasjs/types";
3
3
 
4
- //#region src/generate-id/index.d.ts
5
- /**
6
- * Generate a random identifier with an optional prefix.
7
- *
8
- * @param {string} [prefix] - Prefix prepended to the generated identifier.
9
- * @param {number} [length] - Length of the generated identifier excluding `prefix`. Must be between `8` and `18`.
10
- * @returns {string} Generated identifier string.
11
- * @throws {Error} When `length` is outside the supported `8` to `18` range.
12
- *
13
- * @example
14
- * ```ts
15
- * import { generateId } from '@faasjs/react'
16
- *
17
- * const id = generateId('prefix-')
18
- *
19
- * id.startsWith('prefix-') // true
20
- * ```
21
- */
22
- declare function generateId(prefix?: string, length?: number): string;
23
- //#endregion
24
4
  //#region src/browser/response.d.ts
25
5
  /**
26
6
  * Wrapper class for HTTP responses from FaasJS functions.
@@ -372,7 +352,7 @@ type FaasDataWrapperRef<Path extends FaasActionPaths> = FaasDataInjection<Path>;
372
352
  * export function UserProfile(props: { id: number }) {
373
353
  * return (
374
354
  * <FaasDataWrapper<User>
375
- * action="/pages/users/get"
355
+ * action="features/users/api/get"
376
356
  * params={{ id: props.id }}
377
357
  * fallback={<div>Loading user...</div>}
378
358
  * render={({ data, error, reload }) => {
@@ -397,7 +377,7 @@ type FaasDataWrapperRef<Path extends FaasActionPaths> = FaasDataInjection<Path>;
397
377
  * export function UserProfileWithChildren(props: { id: number }) {
398
378
  * return (
399
379
  * <FaasDataWrapper<User>
400
- * action="/pages/users/get"
380
+ * action="features/users/api/get"
401
381
  * params={{ id: props.id }}
402
382
  * fallback={<div>Loading user...</div>}
403
383
  * >
@@ -439,7 +419,7 @@ declare const FaasDataWrapper: <Path extends FaasActionPaths>(props: FaasDataWra
439
419
  *
440
420
  * return <div>{data.name}</div>
441
421
  * },
442
- * { action: '/pages/users/get', params: { id: 1 } },
422
+ * { action: 'features/users/api/get', params: { id: 1 } },
443
423
  * )
444
424
  * ```
445
425
  */
@@ -494,7 +474,7 @@ type UseFaasOptions<Path extends FaasActionPaths> = SharedUseFaasOptions<FaasPar
494
474
  * import { useFaas } from '@faasjs/react'
495
475
  *
496
476
  * function Profile({ id }: { id: number }) {
497
- * const { data, error, loading, reload } = useFaas('/pages/users/get', { id })
477
+ * const { data, error, loading, reload } = useFaas('features/users/api/get', { id })
498
478
  *
499
479
  * if (loading) return <div>Loading...</div>
500
480
  *
@@ -625,7 +605,7 @@ declare function FaasReactClient(options?: FaasReactClientOptions): FaasReactCli
625
605
  *
626
606
  * const client = getClient('https://service-b.example.com/api/')
627
607
  *
628
- * await client.faas('/pages/posts/get', { id: 1 })
608
+ * await client.faas('features/posts/api/get', { id: 1 })
629
609
  * ```
630
610
  */
631
611
  declare function getClient(host?: string): FaasReactClientInstance;
@@ -719,7 +699,7 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
719
699
  /**
720
700
  * Render children or the configured fallback for the captured error.
721
701
  */
722
- render(): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
702
+ render(): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
723
703
  }
724
704
  //#endregion
725
705
  //#region src/equal/index.d.ts
@@ -866,7 +846,7 @@ type OptionalWrapperProps<TWrapper extends ComponentType<{
866
846
  * )
867
847
  * ```
868
848
  */
869
- declare function OptionalWrapper(props: OptionalWrapperProps): string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
849
+ declare function OptionalWrapper(props: OptionalWrapperProps): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
870
850
  declare namespace OptionalWrapper {
871
851
  var displayName: string;
872
852
  }
@@ -1067,7 +1047,7 @@ type UseFaasStreamResult<Path extends FaasActionPaths> = {
1067
1047
  * import { useFaasStream } from '@faasjs/react'
1068
1048
  *
1069
1049
  * function Chat({ prompt }: { prompt: string }) {
1070
- * const { data, error, loading, reload } = useFaasStream('/pages/chat/stream', { prompt })
1050
+ * const { data, error, loading, reload } = useFaasStream('features/chat/api/stream', { prompt })
1071
1051
  *
1072
1052
  * if (loading) return <div>Streaming...</div>
1073
1053
  *
@@ -1137,4 +1117,4 @@ declare function usePrevious<T = any>(value: T): T | undefined;
1137
1117
  declare function useStateRef<T>(initialValue: T | (() => T)): [T, Dispatch<SetStateAction<T>>, RefObject<T>];
1138
1118
  declare function useStateRef<T = undefined>(): [T | undefined, Dispatch<SetStateAction<T | undefined>>, RefObject<T | undefined>];
1139
1119
  //#endregion
1140
- export { type BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasBrowserClient, type FaasBrowserClientAction, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, type MockHandler, OnError, OptionalWrapper, OptionalWrapperProps, type Options, Response, ResponseError, type ResponseErrorProps, type ResponseHeaders, type ResponseProps, StateSetters, StatesWithSetters, UseFaasOptions, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, generateId, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };
1120
+ export { type BaseUrl, ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasBrowserClient, type FaasBrowserClientAction, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, type MockHandler, OnError, OptionalWrapper, OptionalWrapperProps, type Options, Response, ResponseError, type ResponseErrorProps, type ResponseHeaders, type ResponseProps, StateSetters, StatesWithSetters, UseFaasOptions, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };
package/dist/index.mjs CHANGED
@@ -1,28 +1,6 @@
1
+ import { generateId } from "@faasjs/utils";
1
2
  import { Component, cloneElement, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
3
  import { jsx, jsxs } from "react/jsx-runtime";
3
- //#region src/generate-id/index.ts
4
- /**
5
- * Generate a random identifier with an optional prefix.
6
- *
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
- * @throws {Error} When `length` is outside the supported `8` to `18` range.
11
- *
12
- * @example
13
- * ```ts
14
- * import { generateId } from '@faasjs/react'
15
- *
16
- * const id = generateId('prefix-')
17
- *
18
- * id.startsWith('prefix-') // true
19
- * ```
20
- */
21
- function generateId(prefix = "", length = 18) {
22
- if (length < 8 || length > 18) throw new Error("Length must be 8 ~ 18");
23
- return `${prefix}${Date.now().toString(36).padStart(8, "0")}${Math.random().toString(36).substring(2, length - 6).padEnd(length - 8, "0")}`;
24
- }
25
- //#endregion
26
4
  //#region src/browser/response.ts
27
5
  /**
28
6
  * Wrapper class for HTTP responses from FaasJS functions.
@@ -650,7 +628,7 @@ function useEqualCallback(callback, dependencies) {
650
628
  * export function UserProfile(props: { id: number }) {
651
629
  * return (
652
630
  * <FaasDataWrapper<User>
653
- * action="/pages/users/get"
631
+ * action="features/users/api/get"
654
632
  * params={{ id: props.id }}
655
633
  * fallback={<div>Loading user...</div>}
656
634
  * render={({ data, error, reload }) => {
@@ -675,7 +653,7 @@ function useEqualCallback(callback, dependencies) {
675
653
  * export function UserProfileWithChildren(props: { id: number }) {
676
654
  * return (
677
655
  * <FaasDataWrapper<User>
678
- * action="/pages/users/get"
656
+ * action="features/users/api/get"
679
657
  * params={{ id: props.id }}
680
658
  * fallback={<div>Loading user...</div>}
681
659
  * >
@@ -748,7 +726,7 @@ Object.assign(FaasDataWrapper, { displayName: "FaasDataWrapper" });
748
726
  *
749
727
  * return <div>{data.name}</div>
750
728
  * },
751
- * { action: '/pages/users/get', params: { id: 1 } },
729
+ * { action: 'features/users/api/get', params: { id: 1 } },
752
730
  * )
753
731
  * ```
754
732
  */
@@ -781,7 +759,7 @@ function withFaasData(Component, faasProps) {
781
759
  * ```ts
782
760
  * function useUserRequest(id: number) {
783
761
  * return useFaasRequest({
784
- * action: '/pages/users/get',
762
+ * action: 'features/users/api/get',
785
763
  * defaultParams: { id },
786
764
  * options: {},
787
765
  * send: async ({ action, params, signal, client, setPromise }) => {
@@ -1016,7 +994,7 @@ function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess,
1016
994
  * import { useFaas } from '@faasjs/react'
1017
995
  *
1018
996
  * function Profile({ id }: { id: number }) {
1019
- * const { data, error, loading, reload } = useFaas('/pages/users/get', { id })
997
+ * const { data, error, loading, reload } = useFaas('features/users/api/get', { id })
1020
998
  *
1021
999
  * if (loading) return <div>Loading...</div>
1022
1000
  *
@@ -1165,7 +1143,7 @@ function FaasReactClient(options = { baseUrl: "/" }) {
1165
1143
  *
1166
1144
  * const client = getClient('https://service-b.example.com/api/')
1167
1145
  *
1168
- * await client.faas('/pages/posts/get', { id: 1 })
1146
+ * await client.faas('features/posts/api/get', { id: 1 })
1169
1147
  * ```
1170
1148
  */
1171
1149
  function getClient(host) {
@@ -1448,7 +1426,7 @@ function createSplittingContext(defaultValue) {
1448
1426
  * import { useFaasStream } from '@faasjs/react'
1449
1427
  *
1450
1428
  * function Chat({ prompt }: { prompt: string }) {
1451
- * const { data, error, loading, reload } = useFaasStream('/pages/chat/stream', { prompt })
1429
+ * const { data, error, loading, reload } = useFaasStream('features/chat/api/stream', { prompt })
1452
1430
  *
1453
1431
  * if (loading) return <div>Streaming...</div>
1454
1432
  *
@@ -1571,4 +1549,4 @@ function useStateRef(initialValue) {
1571
1549
  ];
1572
1550
  }
1573
1551
  //#endregion
1574
- export { ErrorBoundary, FaasBrowserClient, FaasDataWrapper, FaasReactClient, OptionalWrapper, Response, ResponseError, createSplittingContext, equal, faas, generateId, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };
1552
+ export { ErrorBoundary, FaasBrowserClient, FaasDataWrapper, FaasReactClient, OptionalWrapper, Response, ResponseError, createSplittingContext, equal, faas, getClient, setMock, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasStream, usePrevious, useSplittingState, useStateRef, withFaasData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "8.0.0-beta.35",
3
+ "version": "8.0.0-beta.36",
4
4
  "homepage": "https://faasjs.com/doc/react/",
5
5
  "bugs": {
6
6
  "url": "https://github.com/faasjs/faasjs/issues"
@@ -26,12 +26,14 @@
26
26
  }
27
27
  },
28
28
  "devDependencies": {
29
- "@faasjs/types": ">=8.0.0-beta.35",
29
+ "@faasjs/types": ">=8.0.0-beta.36",
30
+ "@faasjs/utils": ">=8.0.0-beta.36",
30
31
  "@types/react": "^19.0.0",
31
32
  "react": "^19.0.0"
32
33
  },
33
34
  "peerDependencies": {
34
- "@faasjs/types": ">=8.0.0-beta.35"
35
+ "@faasjs/types": ">=8.0.0-beta.36",
36
+ "@faasjs/utils": ">=8.0.0-beta.36"
35
37
  },
36
38
  "engines": {
37
39
  "node": ">=26.0.0",