@faasjs/react 8.0.0-beta.26 → 8.0.0-beta.28
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 +18 -18
- package/dist/index.mjs +18 -20
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, Rea
|
|
|
3
3
|
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
4
|
import { FaasAction, FaasAction as FaasAction$1, FaasActionUnionType, FaasActionUnionType as FaasActionUnionType$1, FaasData, FaasData as FaasData$1, FaasParams, FaasParams as FaasParams$1 } from "@faasjs/types";
|
|
5
5
|
|
|
6
|
-
//#region src/generateId.d.ts
|
|
6
|
+
//#region src/generateId/index.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Generate a random identifier with an optional prefix.
|
|
9
9
|
*
|
|
@@ -23,7 +23,7 @@ import { FaasAction, FaasAction as FaasAction$1, FaasActionUnionType, FaasAction
|
|
|
23
23
|
*/
|
|
24
24
|
declare function generateId(prefix?: string, length?: number): string;
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/browser.d.ts
|
|
26
|
+
//#region src/browser/index.d.ts
|
|
27
27
|
/**
|
|
28
28
|
* Template literal type for URL strings that must end with a forward slash.
|
|
29
29
|
*
|
|
@@ -111,7 +111,7 @@ type Options = RequestInit & {
|
|
|
111
111
|
*
|
|
112
112
|
* Notes:
|
|
113
113
|
* - Headers are case-insensitive in HTTP but stored with exact casing in this object
|
|
114
|
-
* - Common headers include: Content-Type, Authorization,
|
|
114
|
+
* - Common headers include: Content-Type, Authorization, x-faasjs-request-id, X-Custom-Header
|
|
115
115
|
* - No support for multi-value headers (use comma-separated values instead)
|
|
116
116
|
* - Used in Response, ResponseError, and Options types
|
|
117
117
|
* - Simplified model compared to browser's Headers interface (no .get(), .set() methods)
|
|
@@ -250,7 +250,7 @@ type ResponseProps<T = any> = {
|
|
|
250
250
|
* data: { created: true },
|
|
251
251
|
* headers: {
|
|
252
252
|
* 'Content-Type': 'application/json',
|
|
253
|
-
* '
|
|
253
|
+
* 'x-faasjs-request-id': 'req-123',
|
|
254
254
|
* 'X-Cache-Key': 'user-123'
|
|
255
255
|
* }
|
|
256
256
|
* })
|
|
@@ -401,8 +401,8 @@ type ResponseErrorProps = {
|
|
|
401
401
|
* if (error.body) {
|
|
402
402
|
* console.error('Error details:', error.body)
|
|
403
403
|
* }
|
|
404
|
-
* if (error.headers['
|
|
405
|
-
* console.error('Request ID:', error.headers['
|
|
404
|
+
* if (error.headers['x-faasjs-request-id']) {
|
|
405
|
+
* console.error('Request ID:', error.headers['x-faasjs-request-id'])
|
|
406
406
|
* }
|
|
407
407
|
* }
|
|
408
408
|
* }
|
|
@@ -848,7 +848,7 @@ declare class FaasBrowserClient {
|
|
|
848
848
|
action<PathOrData extends FaasActionUnionType$1>(action: FaasAction$1<PathOrData>, params?: FaasParams$1<PathOrData>, options?: Options): Promise<Response<FaasData$1<PathOrData>>>;
|
|
849
849
|
}
|
|
850
850
|
//#endregion
|
|
851
|
-
//#region src/faas.d.ts
|
|
851
|
+
//#region src/faas/index.d.ts
|
|
852
852
|
/**
|
|
853
853
|
* Call the currently configured FaasReactClient.
|
|
854
854
|
*
|
|
@@ -876,7 +876,7 @@ declare class FaasBrowserClient {
|
|
|
876
876
|
*/
|
|
877
877
|
declare function faas<PathOrData extends FaasActionUnionType$1>(action: FaasAction$1<PathOrData>, params: FaasParams$1<PathOrData>, options?: Options): Promise<Response<FaasData$1<PathOrData>>>;
|
|
878
878
|
//#endregion
|
|
879
|
-
//#region src/FaasDataWrapper.d.ts
|
|
879
|
+
//#region src/FaasDataWrapper/index.d.ts
|
|
880
880
|
/**
|
|
881
881
|
* Request state injected by {@link useFaas}, {@link FaasDataWrapper}, and {@link withFaasData}.
|
|
882
882
|
*
|
|
@@ -1073,7 +1073,7 @@ type SharedUseFaasOptions<Params, Data> = {
|
|
|
1073
1073
|
baseUrl?: BaseUrl;
|
|
1074
1074
|
};
|
|
1075
1075
|
//#endregion
|
|
1076
|
-
//#region src/useFaas.d.ts
|
|
1076
|
+
//#region src/useFaas/index.d.ts
|
|
1077
1077
|
/**
|
|
1078
1078
|
* Options that customize the {@link useFaas} request lifecycle.
|
|
1079
1079
|
*
|
|
@@ -1236,7 +1236,7 @@ declare function FaasReactClient(options?: FaasReactClientOptions): FaasReactCli
|
|
|
1236
1236
|
*/
|
|
1237
1237
|
declare function getClient(host?: string): FaasReactClientInstance;
|
|
1238
1238
|
//#endregion
|
|
1239
|
-
//#region src/constant.d.ts
|
|
1239
|
+
//#region src/constant/index.d.ts
|
|
1240
1240
|
/**
|
|
1241
1241
|
* Returns a constant value that is created by the given function.
|
|
1242
1242
|
*
|
|
@@ -1257,7 +1257,7 @@ declare function getClient(host?: string): FaasReactClientInstance;
|
|
|
1257
1257
|
*/
|
|
1258
1258
|
declare function useConstant<T>(fn: () => T): T;
|
|
1259
1259
|
//#endregion
|
|
1260
|
-
//#region src/ErrorBoundary.d.ts
|
|
1260
|
+
//#region src/ErrorBoundary/index.d.ts
|
|
1261
1261
|
/**
|
|
1262
1262
|
* Props for the {@link ErrorBoundary} component.
|
|
1263
1263
|
*/
|
|
@@ -1328,7 +1328,7 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
|
1328
1328
|
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;
|
|
1329
1329
|
}
|
|
1330
1330
|
//#endregion
|
|
1331
|
-
//#region src/equal.d.ts
|
|
1331
|
+
//#region src/equal/index.d.ts
|
|
1332
1332
|
/**
|
|
1333
1333
|
* Compares two values for deep equality.
|
|
1334
1334
|
*
|
|
@@ -1433,7 +1433,7 @@ declare function useEqualMemo<T>(callback: () => T, dependencies: any[]): T;
|
|
|
1433
1433
|
*/
|
|
1434
1434
|
declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T, dependencies: any[]): T;
|
|
1435
1435
|
//#endregion
|
|
1436
|
-
//#region src/OptionalWrapper.d.ts
|
|
1436
|
+
//#region src/OptionalWrapper/index.d.ts
|
|
1437
1437
|
/**
|
|
1438
1438
|
* Props for the {@link OptionalWrapper} helper component.
|
|
1439
1439
|
*
|
|
@@ -1477,7 +1477,7 @@ declare namespace OptionalWrapper {
|
|
|
1477
1477
|
var displayName: string;
|
|
1478
1478
|
}
|
|
1479
1479
|
//#endregion
|
|
1480
|
-
//#region src/splittingContext.d.ts
|
|
1480
|
+
//#region src/splittingContext/index.d.ts
|
|
1481
1481
|
/**
|
|
1482
1482
|
* Create a context whose keys can be consumed independently.
|
|
1483
1483
|
*
|
|
@@ -1593,7 +1593,7 @@ declare function createSplittingContext<T extends Record<string, any>>(defaultVa
|
|
|
1593
1593
|
use: <NewT extends T = T>(this: void) => Readonly<NewT>;
|
|
1594
1594
|
};
|
|
1595
1595
|
//#endregion
|
|
1596
|
-
//#region src/splittingState.d.ts
|
|
1596
|
+
//#region src/splittingState/index.d.ts
|
|
1597
1597
|
/**
|
|
1598
1598
|
* Setter map generated by {@link useSplittingState} for each state key.
|
|
1599
1599
|
*
|
|
@@ -1624,7 +1624,7 @@ type StatesWithSetters<T> = T & StateSetters<T>;
|
|
|
1624
1624
|
*/
|
|
1625
1625
|
declare function useSplittingState<T extends Record<string, unknown>>(initialStates: T): StatesWithSetters<T>;
|
|
1626
1626
|
//#endregion
|
|
1627
|
-
//#region src/useFaasStream.d.ts
|
|
1627
|
+
//#region src/useFaasStream/index.d.ts
|
|
1628
1628
|
/**
|
|
1629
1629
|
* Options that customize the {@link useFaasStream} request lifecycle.
|
|
1630
1630
|
*/
|
|
@@ -1686,7 +1686,7 @@ type UseFaasStreamResult = {
|
|
|
1686
1686
|
*/
|
|
1687
1687
|
declare function useFaasStream(action: string, defaultParams: Record<string, any>, options?: UseFaasStreamOptions): UseFaasStreamResult;
|
|
1688
1688
|
//#endregion
|
|
1689
|
-
//#region src/usePrevious.d.ts
|
|
1689
|
+
//#region src/usePrevious/index.d.ts
|
|
1690
1690
|
/**
|
|
1691
1691
|
* Hook to store the previous value of a state or prop.
|
|
1692
1692
|
*
|
|
@@ -1707,7 +1707,7 @@ declare function useFaasStream(action: string, defaultParams: Record<string, any
|
|
|
1707
1707
|
*/
|
|
1708
1708
|
declare function usePrevious<T = any>(value: T): T | undefined;
|
|
1709
1709
|
//#endregion
|
|
1710
|
-
//#region src/useStateRef.d.ts
|
|
1710
|
+
//#region src/useStateRef/index.d.ts
|
|
1711
1711
|
/**
|
|
1712
1712
|
* Custom hook that returns a stateful value and a ref to that value.
|
|
1713
1713
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component, cloneElement, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
//#region src/generateId.ts
|
|
3
|
+
//#region src/generateId/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* Generate a random identifier with an optional prefix.
|
|
6
6
|
*
|
|
@@ -23,7 +23,7 @@ function generateId(prefix = "", length = 18) {
|
|
|
23
23
|
return `${prefix}${Date.now().toString(36).padStart(8, "0")}${Math.random().toString(36).substring(2, length - 6).padEnd(length - 8, "0")}`;
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/browser.ts
|
|
26
|
+
//#region src/browser/index.ts
|
|
27
27
|
/**
|
|
28
28
|
* Wrapper class for HTTP responses from FaasJS functions.
|
|
29
29
|
*
|
|
@@ -88,7 +88,7 @@ function generateId(prefix = "", length = 18) {
|
|
|
88
88
|
* data: { created: true },
|
|
89
89
|
* headers: {
|
|
90
90
|
* 'Content-Type': 'application/json',
|
|
91
|
-
* '
|
|
91
|
+
* 'x-faasjs-request-id': 'req-123',
|
|
92
92
|
* 'X-Cache-Key': 'user-123'
|
|
93
93
|
* }
|
|
94
94
|
* })
|
|
@@ -235,8 +235,8 @@ var Response = class {
|
|
|
235
235
|
* if (error.body) {
|
|
236
236
|
* console.error('Error details:', error.body)
|
|
237
237
|
* }
|
|
238
|
-
* if (error.headers['
|
|
239
|
-
* console.error('Request ID:', error.headers['
|
|
238
|
+
* if (error.headers['x-faasjs-request-id']) {
|
|
239
|
+
* console.error('Request ID:', error.headers['x-faasjs-request-id'])
|
|
240
240
|
* }
|
|
241
241
|
* }
|
|
242
242
|
* }
|
|
@@ -454,7 +454,6 @@ function normalizeMockResponse(response) {
|
|
|
454
454
|
return new Response(response || {});
|
|
455
455
|
}
|
|
456
456
|
async function resolveMockResponse(action, params, options) {
|
|
457
|
-
console.debug(`[FaasJS] Mock request: ${action} %j`, params);
|
|
458
457
|
if (typeof mock === "function") return normalizeMockResponse(await mock(action, params, options));
|
|
459
458
|
return normalizeMockResponse(mock);
|
|
460
459
|
}
|
|
@@ -659,7 +658,6 @@ var FaasBrowserClient = class {
|
|
|
659
658
|
this.id = `FBC-${generateId()}`;
|
|
660
659
|
this.baseUrl = baseUrl;
|
|
661
660
|
this.defaultOptions = options;
|
|
662
|
-
console.debug(`[FaasJS] Initialize with baseUrl: ${this.baseUrl}`);
|
|
663
661
|
}
|
|
664
662
|
/**
|
|
665
663
|
* Makes a request to a FaasJS function.
|
|
@@ -778,7 +776,7 @@ var FaasBrowserClient = class {
|
|
|
778
776
|
}
|
|
779
777
|
};
|
|
780
778
|
//#endregion
|
|
781
|
-
//#region src/faas.ts
|
|
779
|
+
//#region src/faas/index.ts
|
|
782
780
|
/**
|
|
783
781
|
* Call the currently configured FaasReactClient.
|
|
784
782
|
*
|
|
@@ -814,7 +812,7 @@ async function faas(action, params, options) {
|
|
|
814
812
|
return client.browserClient.action(action, params, options);
|
|
815
813
|
}
|
|
816
814
|
//#endregion
|
|
817
|
-
//#region src/equal.ts
|
|
815
|
+
//#region src/equal/index.ts
|
|
818
816
|
const AsyncFunction = (async () => {}).constructor;
|
|
819
817
|
/**
|
|
820
818
|
* Compares two values for deep equality.
|
|
@@ -1262,7 +1260,7 @@ function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess,
|
|
|
1262
1260
|
if (typeof e?.message === "string" && e.message.toLowerCase().includes("aborted")) return;
|
|
1263
1261
|
if (!failedOnceRef.current && typeof e?.message === "string" && e.message.includes("Failed to fetch")) {
|
|
1264
1262
|
failedOnceRef.current = true;
|
|
1265
|
-
console.warn(`FaasReactClient: ${e.message} retry...`);
|
|
1263
|
+
console.warn(`[FaasJS] FaasReactClient: ${e.message} retry...`);
|
|
1266
1264
|
run();
|
|
1267
1265
|
return;
|
|
1268
1266
|
}
|
|
@@ -1336,7 +1334,7 @@ function useFaasRequest({ action, defaultParams, options, beforeSend, onSuccess,
|
|
|
1336
1334
|
};
|
|
1337
1335
|
}
|
|
1338
1336
|
//#endregion
|
|
1339
|
-
//#region src/useFaas.tsx
|
|
1337
|
+
//#region src/useFaas/index.tsx
|
|
1340
1338
|
/**
|
|
1341
1339
|
* Request FaasJS data and keep request state in React state.
|
|
1342
1340
|
*
|
|
@@ -1512,13 +1510,13 @@ function FaasReactClient(options = { baseUrl: "/" }) {
|
|
|
1512
1510
|
function getClient(host) {
|
|
1513
1511
|
const client = clients[host || Object.keys(clients)[0]];
|
|
1514
1512
|
if (!client) {
|
|
1515
|
-
console.warn("FaasReactClient is not initialized manually, use default.");
|
|
1513
|
+
console.warn("[FaasJS] FaasReactClient is not initialized manually, use default.");
|
|
1516
1514
|
return FaasReactClient();
|
|
1517
1515
|
}
|
|
1518
1516
|
return client;
|
|
1519
1517
|
}
|
|
1520
1518
|
//#endregion
|
|
1521
|
-
//#region src/constant.ts
|
|
1519
|
+
//#region src/constant/index.ts
|
|
1522
1520
|
/**
|
|
1523
1521
|
* Returns a constant value that is created by the given function.
|
|
1524
1522
|
*
|
|
@@ -1543,7 +1541,7 @@ function useConstant(fn) {
|
|
|
1543
1541
|
return ref.current.v;
|
|
1544
1542
|
}
|
|
1545
1543
|
//#endregion
|
|
1546
|
-
//#region src/ErrorBoundary.tsx
|
|
1544
|
+
//#region src/ErrorBoundary/index.tsx
|
|
1547
1545
|
/**
|
|
1548
1546
|
* React error boundary with an optional custom fallback element.
|
|
1549
1547
|
*
|
|
@@ -1617,7 +1615,7 @@ var ErrorBoundary = class extends Component {
|
|
|
1617
1615
|
}
|
|
1618
1616
|
};
|
|
1619
1617
|
//#endregion
|
|
1620
|
-
//#region src/OptionalWrapper.tsx
|
|
1618
|
+
//#region src/OptionalWrapper/index.tsx
|
|
1621
1619
|
/**
|
|
1622
1620
|
* Conditionally wrap children with another component.
|
|
1623
1621
|
*
|
|
@@ -1653,7 +1651,7 @@ function OptionalWrapper(props) {
|
|
|
1653
1651
|
}
|
|
1654
1652
|
OptionalWrapper.displayName = "OptionalWrapper";
|
|
1655
1653
|
//#endregion
|
|
1656
|
-
//#region src/splittingState.tsx
|
|
1654
|
+
//#region src/splittingState/index.tsx
|
|
1657
1655
|
/**
|
|
1658
1656
|
* Create local state entries and matching setters for each key in an object.
|
|
1659
1657
|
*
|
|
@@ -1682,7 +1680,7 @@ function useSplittingState(initialStates) {
|
|
|
1682
1680
|
return states;
|
|
1683
1681
|
}
|
|
1684
1682
|
//#endregion
|
|
1685
|
-
//#region src/splittingContext.tsx
|
|
1683
|
+
//#region src/splittingContext/index.tsx
|
|
1686
1684
|
/**
|
|
1687
1685
|
* Create a context whose keys can be consumed independently.
|
|
1688
1686
|
*
|
|
@@ -1770,7 +1768,7 @@ function createSplittingContext(defaultValue) {
|
|
|
1770
1768
|
};
|
|
1771
1769
|
}
|
|
1772
1770
|
//#endregion
|
|
1773
|
-
//#region src/useFaasStream.tsx
|
|
1771
|
+
//#region src/useFaasStream/index.tsx
|
|
1774
1772
|
/**
|
|
1775
1773
|
* Stream a FaasJS response into React state.
|
|
1776
1774
|
*
|
|
@@ -1871,7 +1869,7 @@ function useFaasStream(action, defaultParams, options = {}) {
|
|
|
1871
1869
|
};
|
|
1872
1870
|
}
|
|
1873
1871
|
//#endregion
|
|
1874
|
-
//#region src/usePrevious.ts
|
|
1872
|
+
//#region src/usePrevious/index.ts
|
|
1875
1873
|
/**
|
|
1876
1874
|
* Hook to store the previous value of a state or prop.
|
|
1877
1875
|
*
|
|
@@ -1898,7 +1896,7 @@ function usePrevious(value) {
|
|
|
1898
1896
|
return ref.current;
|
|
1899
1897
|
}
|
|
1900
1898
|
//#endregion
|
|
1901
|
-
//#region src/useStateRef.ts
|
|
1899
|
+
//#region src/useStateRef/index.ts
|
|
1902
1900
|
/**
|
|
1903
1901
|
* Custom hook that returns a stateful value and a ref to that value.
|
|
1904
1902
|
*
|
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.28",
|
|
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.28",
|
|
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.28"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=24.0.0",
|