@intrig/next 1.0.7 → 1.0.10
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/eslint.config.cjs +19 -0
- package/jest.config.ts +10 -0
- package/package.json +5 -7
- package/project.json +20 -0
- package/src/extra/{index.d.ts → index.ts} +2 -2
- package/src/extra/useAsNetworkState.ts +53 -0
- package/src/extra/{useAsPromise.d.ts → useAsPromise.ts} +58 -7
- package/src/extra/useLocalReducer.ts +61 -0
- package/src/extra/{useResolvedCachedValue.d.ts → useResolvedCachedValue.ts} +39 -7
- package/src/extra/{useResolvedValue.d.ts → useResolvedValue.ts} +39 -7
- package/src/extra.ts +190 -0
- package/src/{index.d.ts → index.ts} +1 -1
- package/src/intrig-context.ts +66 -0
- package/src/intrig-layout.tsx +18 -0
- package/src/intrig-middleware.ts +31 -0
- package/src/intrig-provider.tsx +454 -0
- package/src/logger.ts +13 -0
- package/src/media-type-utils.ts +184 -0
- package/src/{network-state.d.ts → network-state.tsx} +174 -92
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +14 -0
- package/src/extra/index.js +0 -5
- package/src/extra/index.js.map +0 -1
- package/src/extra/useAsNetworkState.d.ts +0 -13
- package/src/extra/useAsNetworkState.js +0 -41
- package/src/extra/useAsNetworkState.js.map +0 -1
- package/src/extra/useAsPromise.js +0 -30
- package/src/extra/useAsPromise.js.map +0 -1
- package/src/extra/useLocalReducer.d.ts +0 -6
- package/src/extra/useLocalReducer.js +0 -50
- package/src/extra/useLocalReducer.js.map +0 -1
- package/src/extra/useResolvedCachedValue.js +0 -15
- package/src/extra/useResolvedCachedValue.js.map +0 -1
- package/src/extra/useResolvedValue.js +0 -17
- package/src/extra/useResolvedValue.js.map +0 -1
- package/src/extra.d.ts +0 -52
- package/src/extra.js +0 -92
- package/src/extra.js.map +0 -1
- package/src/index.js +0 -4
- package/src/index.js.map +0 -1
- package/src/intrig-context.d.ts +0 -42
- package/src/intrig-context.js +0 -21
- package/src/intrig-context.js.map +0 -1
- package/src/intrig-middleware.d.ts +0 -2
- package/src/intrig-middleware.js +0 -24
- package/src/intrig-middleware.js.map +0 -1
- package/src/intrig-provider.d.ts +0 -102
- package/src/intrig-provider.js +0 -296
- package/src/intrig-provider.js.map +0 -1
- package/src/logger.d.ts +0 -7
- package/src/logger.js +0 -11
- package/src/logger.js.map +0 -1
- package/src/media-type-utils.d.ts +0 -4
- package/src/media-type-utils.js +0 -121
- package/src/media-type-utils.js.map +0 -1
- package/src/network-state.js +0 -185
- package/src/network-state.js.map +0 -1
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useIntrigContext } from '@intrig/next/intrig-context';
|
|
2
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import { error, init, isInit, isSuccess, success } from '@intrig/next/network-state';
|
|
4
|
-
function isPromise(item) {
|
|
5
|
-
return !!item && typeof item.then === 'function' && typeof item.catch === 'function';
|
|
6
|
-
}
|
|
7
|
-
export function useLocalReducer(fn, options) {
|
|
8
|
-
let context = useIntrigContext();
|
|
9
|
-
const key = useMemo(() => {
|
|
10
|
-
return options.key ?? 'default';
|
|
11
|
-
}, []);
|
|
12
|
-
const networkState = useMemo(() => {
|
|
13
|
-
return context.state?.[`localState:reduce:${key}`] ?? init();
|
|
14
|
-
}, [context.state?.[`localState:reduce:${key}`]]);
|
|
15
|
-
const dispatch = useCallback((state) => {
|
|
16
|
-
context.dispatch({ key, operation: 'reduce', source: 'localState', state });
|
|
17
|
-
}, [key, context.dispatch]);
|
|
18
|
-
const execute = useCallback((event) => {
|
|
19
|
-
try {
|
|
20
|
-
if (isSuccess(networkState)) {
|
|
21
|
-
let data = fn(event, networkState.data);
|
|
22
|
-
if (isPromise(data)) {
|
|
23
|
-
dispatch(init());
|
|
24
|
-
data.then(data => dispatch(success(data)));
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
dispatch(success(data));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else if (isInit(networkState)) {
|
|
31
|
-
let data1 = fn(event, options.initState);
|
|
32
|
-
if (isPromise(data1)) {
|
|
33
|
-
dispatch(init());
|
|
34
|
-
data1.then(data => dispatch(success(data)));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
dispatch(success(data1));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
dispatch(error(e));
|
|
43
|
-
}
|
|
44
|
-
}, [networkState, dispatch, fn]);
|
|
45
|
-
const clear = useCallback(() => {
|
|
46
|
-
dispatch(init());
|
|
47
|
-
}, []);
|
|
48
|
-
return [networkState, execute, clear];
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=useLocalReducer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalReducer.js","sourceRoot":"","sources":["../../../../../lib/client-next/src/extra/useLocalReducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAgB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAOnG,SAAS,SAAS,CAAI,IAAS;IAC7B,OAAO,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,UAAU,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,eAAe,CAA6D,EAAK,EAAE,OAAkC;IACnI,IAAI,OAAO,GAAG,gBAAgB,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;QACvB,OAAO,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC;IAClC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,YAAY,GA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AAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC,EAAE,CAAC,YAAY,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAEjC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isSuccess } from '@intrig/next/network-state';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
// **Implementation**
|
|
4
|
-
export function useResolvedCachedValue(hook, options) {
|
|
5
|
-
const [cachedValue, setCachedValue] = useState();
|
|
6
|
-
let [state] = hook(options); // Ensure compatibility with different hook types
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
if (isSuccess(state)) {
|
|
9
|
-
setCachedValue(state.data);
|
|
10
|
-
}
|
|
11
|
-
// Do not clear cached value if state is unsuccessful
|
|
12
|
-
}, [state]);
|
|
13
|
-
return cachedValue;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=useResolvedCachedValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useResolvedCachedValue.js","sourceRoot":"","sources":["../../../../../lib/client-next/src/extra/useResolvedCachedValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAIwC,SAAS,EAKvD,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA6D5C,qBAAqB;AACrB,MAAM,UAAU,sBAAsB,CAAa,IAA4B,EAAE,OAAgC;IAC/G,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAiB,CAAC;IAEhE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAc,CAAC,CAAC,CAAC,iDAAiD;IAErF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QACD,qDAAqD;IACvD,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { isSuccess } from '@intrig/next/network-state';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
// **Implementation**
|
|
4
|
-
export function useResolvedValue(hook, options) {
|
|
5
|
-
const [value, setValue] = useState();
|
|
6
|
-
let [state] = hook(options); // Ensure compatibility with different hook types
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
if (isSuccess(state)) {
|
|
9
|
-
setValue(state.data);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
setValue(undefined);
|
|
13
|
-
}
|
|
14
|
-
}, [state]); // Add `state` to the dependency array to ensure updates
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=useResolvedValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useResolvedValue.js","sourceRoot":"","sources":["../../../../../lib/client-next/src/extra/useResolvedValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAIwC,SAAS,EAKvD,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAwD5C,qBAAqB;AACrB,MAAM,UAAU,gBAAgB,CAAa,IAA4B,EAAE,OAAgC;IACzG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAiB,CAAC;IAEpD,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,OAAc,CAAC,CAAC,CAAC,iDAAiD;IAErF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,wDAAwD;IAErE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/src/extra.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BinaryFunctionHook, BinaryHookOptions, BinaryProduceHook, ConstantHook, NetworkState, UnaryFunctionHook, UnaryHookOptions, UnaryProduceHook, UnitHook, UnitHookOptions } from '@intrig/next/network-state';
|
|
2
|
-
/**
|
|
3
|
-
* Converts a given hook into a promise-based function.
|
|
4
|
-
*
|
|
5
|
-
* @param {IntrigHook<P, B, T>} hook - The hook function to be converted.
|
|
6
|
-
* @param options
|
|
7
|
-
*
|
|
8
|
-
* @return {[(...params: Parameters<ReturnType<IntrigHook<P, B, T>>[1]>) => Promise<T>, () => void]}
|
|
9
|
-
* Returns a tuple containing a function that invokes the hook as a promise and a function to clear the state.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useAsPromise<E>(hook: UnitHook<E>, options: UnitHookOptions): [() => Promise<never>, () => void];
|
|
12
|
-
export declare function useAsPromise<T, E>(hook: ConstantHook<T, E>, options: UnitHookOptions): [() => Promise<T>, () => void];
|
|
13
|
-
export declare function useAsPromise<P, E>(hook: UnaryProduceHook<P, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<never>, () => void];
|
|
14
|
-
export declare function useAsPromise<P, T, E>(hook: UnaryFunctionHook<P, T, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<T>, () => void];
|
|
15
|
-
export declare function useAsPromise<P, B, E>(hook: BinaryProduceHook<P, B, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<never>, () => void];
|
|
16
|
-
export declare function useAsPromise<P, B, T, E>(hook: BinaryFunctionHook<P, B, T, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<T>, () => void];
|
|
17
|
-
/**
|
|
18
|
-
* A custom hook that manages and returns the network state of a promise-based function,
|
|
19
|
-
* providing a way to execute the function and clear its state.
|
|
20
|
-
*
|
|
21
|
-
* @param fn The promise-based function whose network state is to be managed. It should be a function that returns a promise.
|
|
22
|
-
* @param key An optional identifier for the network state. Defaults to 'default'.
|
|
23
|
-
* @return A tuple containing the current network state, a function to execute the promise, and a function to clear the state.
|
|
24
|
-
*/
|
|
25
|
-
export declare function useAsNetworkState<T, F extends ((...args: any) => Promise<T>)>(fn: F, key?: string): [NetworkState<T>, (...params: Parameters<F>) => void, () => void];
|
|
26
|
-
/**
|
|
27
|
-
* A custom hook that resolves the value from the provided hook's state and updates it whenever the state changes.
|
|
28
|
-
*
|
|
29
|
-
* @param {IntrigHook<P, B, T>} hook - The hook that provides the state to observe and resolve data from.
|
|
30
|
-
* @param options
|
|
31
|
-
* @return {T | undefined} The resolved value from the hook's state or undefined if the state is not successful.
|
|
32
|
-
*/
|
|
33
|
-
export declare function useResolvedValue<E>(hook: UnitHook<E>, options: UnitHookOptions): undefined;
|
|
34
|
-
export declare function useResolvedValue<T, E>(hook: ConstantHook<T, E>, options: UnitHookOptions): T | undefined;
|
|
35
|
-
export declare function useResolvedValue<P, E>(hook: UnaryProduceHook<P, E>, options: UnaryHookOptions<P>): undefined;
|
|
36
|
-
export declare function useResolvedValue<P, T, E>(hook: UnaryFunctionHook<P, T, E>, options: UnaryHookOptions<P>): T | undefined;
|
|
37
|
-
export declare function useResolvedValue<P, B, E>(hook: BinaryProduceHook<P, B, E>, options: BinaryHookOptions<P, B>): undefined;
|
|
38
|
-
export declare function useResolvedValue<P, B, T, E>(hook: BinaryFunctionHook<P, B, T, E>, options: BinaryHookOptions<P, B>): T | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* A custom hook that resolves and caches the value from a successful state provided by the given hook.
|
|
41
|
-
* The state is updated only when it is in a successful state.
|
|
42
|
-
*
|
|
43
|
-
* @param {IntrigHook<P, B, T>} hook - The hook that provides the state to observe and cache data from.
|
|
44
|
-
* @param options
|
|
45
|
-
* @return {T | undefined} The cached value from the hook's state or undefined if the state is not successful.
|
|
46
|
-
*/
|
|
47
|
-
export declare function useResolvedCachedValue<E>(hook: UnitHook<E>, options: UnitHookOptions): undefined;
|
|
48
|
-
export declare function useResolvedCachedValue<T, E>(hook: ConstantHook<T, E>, options: UnitHookOptions): T | undefined;
|
|
49
|
-
export declare function useResolvedCachedValue<P, E>(hook: UnaryProduceHook<P, E>, options: UnaryHookOptions<P>): undefined;
|
|
50
|
-
export declare function useResolvedCachedValue<P, T, E>(hook: UnaryFunctionHook<P, T, E>, options: UnaryHookOptions<P>): T | undefined;
|
|
51
|
-
export declare function useResolvedCachedValue<P, B, E>(hook: BinaryProduceHook<P, B, E>, options: BinaryHookOptions<P, B>): undefined;
|
|
52
|
-
export declare function useResolvedCachedValue<P, B, T, E>(hook: BinaryFunctionHook<P, B, T, E>, options: BinaryHookOptions<P, B>): T | undefined;
|
package/src/extra.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { error, init, isError, isSuccess, isValidationError, pending, success } from '@intrig/next/network-state';
|
|
3
|
-
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { useIntrigContext } from '@intrig/next/intrig-context';
|
|
5
|
-
// **Implementation**
|
|
6
|
-
export function useAsPromise(hook, options) {
|
|
7
|
-
const resolveRef = useRef();
|
|
8
|
-
const rejectRef = useRef();
|
|
9
|
-
let [state, dispatch, clear] = hook(options); // Casting to `any` to match all overloads
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (isSuccess(state)) {
|
|
12
|
-
resolveRef.current?.(state.data);
|
|
13
|
-
clear();
|
|
14
|
-
}
|
|
15
|
-
else if (isError(state)) {
|
|
16
|
-
rejectRef.current?.(state.error);
|
|
17
|
-
clear();
|
|
18
|
-
}
|
|
19
|
-
}, [state]);
|
|
20
|
-
const promiseFn = useCallback((...args) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
resolveRef.current = resolve;
|
|
23
|
-
rejectRef.current = reject;
|
|
24
|
-
let dispatchState = dispatch(...args);
|
|
25
|
-
if (isValidationError(dispatchState)) {
|
|
26
|
-
reject(dispatchState.error);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}, [dispatch]);
|
|
30
|
-
return [promiseFn, clear];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* A custom hook that manages and returns the network state of a promise-based function,
|
|
34
|
-
* providing a way to execute the function and clear its state.
|
|
35
|
-
*
|
|
36
|
-
* @param fn The promise-based function whose network state is to be managed. It should be a function that returns a promise.
|
|
37
|
-
* @param key An optional identifier for the network state. Defaults to 'default'.
|
|
38
|
-
* @return A tuple containing the current network state, a function to execute the promise, and a function to clear the state.
|
|
39
|
-
*/
|
|
40
|
-
export function useAsNetworkState(fn, key = 'default') {
|
|
41
|
-
let id = useId();
|
|
42
|
-
let context = useIntrigContext();
|
|
43
|
-
const networkState = useMemo(() => {
|
|
44
|
-
return context.state?.[`promiseState:${id}:${key}}`] ?? init();
|
|
45
|
-
}, [context.state?.[`promiseState:${id}:${key}}`]]);
|
|
46
|
-
const dispatch = useCallback((state) => {
|
|
47
|
-
context.dispatch({ key, operation: id, source: 'promiseState', state });
|
|
48
|
-
}, [key, context.dispatch]);
|
|
49
|
-
const execute = useCallback((...args) => {
|
|
50
|
-
dispatch(pending());
|
|
51
|
-
return fn(...args).then((data) => {
|
|
52
|
-
dispatch(success(data));
|
|
53
|
-
}, (e) => {
|
|
54
|
-
dispatch(error(e));
|
|
55
|
-
});
|
|
56
|
-
}, []);
|
|
57
|
-
const clear = useCallback(() => {
|
|
58
|
-
dispatch(init());
|
|
59
|
-
}, []);
|
|
60
|
-
return [
|
|
61
|
-
networkState,
|
|
62
|
-
execute,
|
|
63
|
-
clear
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
// **Implementation**
|
|
67
|
-
export function useResolvedValue(hook, options) {
|
|
68
|
-
const [value, setValue] = useState();
|
|
69
|
-
let [state] = hook(options); // Ensure compatibility with different hook types
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (isSuccess(state)) {
|
|
72
|
-
setValue(state.data);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
setValue(undefined);
|
|
76
|
-
}
|
|
77
|
-
}, [state]); // Add `state` to the dependency array to ensure updates
|
|
78
|
-
return value;
|
|
79
|
-
}
|
|
80
|
-
// **Implementation**
|
|
81
|
-
export function useResolvedCachedValue(hook, options) {
|
|
82
|
-
const [cachedValue, setCachedValue] = useState();
|
|
83
|
-
let [state] = hook(options); // Ensure compatibility with different hook types
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if (isSuccess(state)) {
|
|
86
|
-
setCachedValue(state.data);
|
|
87
|
-
}
|
|
88
|
-
// Do not clear cached value if state is unsuccessful
|
|
89
|
-
}, [state]);
|
|
90
|
-
return cachedValue;
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=extra.js.map
|
package/src/extra.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extra.js","sourceRoot":"","sources":["../../../../lib/client-next/src/extra.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AACZ,OAAO,EAKL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,SAAS,EACT,iBAAiB,EAEjB,OAAO,EACP,OAAO,EAG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"file":"index.js","sourceRoot":"","sources":["../../../../lib/client-next/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAA"}
|
package/src/intrig-context.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NetworkAction, NetworkState } from '@intrig/next/network-state';
|
|
2
|
-
import { AxiosProgressEvent } from 'axios';
|
|
3
|
-
import { ZodSchema } from 'zod';
|
|
4
|
-
import { DefaultConfigs } from '@intrig/next/intrig-provider';
|
|
5
|
-
type GlobalState = Record<string, NetworkState>;
|
|
6
|
-
interface RequestType<T = any> {
|
|
7
|
-
method: 'get' | 'post' | 'put' | 'delete';
|
|
8
|
-
url: string;
|
|
9
|
-
headers?: Record<string, string>;
|
|
10
|
-
params?: Record<string, any>;
|
|
11
|
-
data?: any;
|
|
12
|
-
originalData?: T;
|
|
13
|
-
onUploadProgress?: (event: AxiosProgressEvent) => void;
|
|
14
|
-
onDownloadProgress?: (event: AxiosProgressEvent) => void;
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
key: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Defines the ContextType interface for managing global state, dispatching actions,
|
|
20
|
-
* and holding a collection of Axios instances.
|
|
21
|
-
*
|
|
22
|
-
* @interface ContextType
|
|
23
|
-
* @property {GlobalState} state - The global state of the application.
|
|
24
|
-
* @property {React.Dispatch<NetworkAction<unknown>>} dispatch - The dispatch function to send network actions.
|
|
25
|
-
* @property {Record<string, AxiosInstance>} axios - A record of Axios instances for making HTTP requests.
|
|
26
|
-
*/
|
|
27
|
-
export interface ContextType {
|
|
28
|
-
state: GlobalState;
|
|
29
|
-
filteredState: GlobalState;
|
|
30
|
-
dispatch: React.Dispatch<NetworkAction<unknown, unknown>>;
|
|
31
|
-
configs: DefaultConfigs;
|
|
32
|
-
execute: <T, E = unknown>(request: RequestType, dispatch: (state: NetworkState<T, E>) => void, schema: ZodSchema<T> | undefined, errorSchema: ZodSchema<E> | undefined) => Promise<void>;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Context object created using `createContext` function. Provides a way to share state, dispatch functions,
|
|
36
|
-
* and axios instance across components without having to pass props down manually at every level.
|
|
37
|
-
*
|
|
38
|
-
* @type {ContextType}
|
|
39
|
-
*/
|
|
40
|
-
declare let Context: import("react").Context<ContextType>;
|
|
41
|
-
export declare function useIntrigContext(): ContextType;
|
|
42
|
-
export { Context, GlobalState, RequestType, };
|
package/src/intrig-context.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { createContext, useContext } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Context object created using `createContext` function. Provides a way to share state, dispatch functions,
|
|
5
|
-
* and axios instance across components without having to pass props down manually at every level.
|
|
6
|
-
*
|
|
7
|
-
* @type {ContextType}
|
|
8
|
-
*/
|
|
9
|
-
let Context = createContext({
|
|
10
|
-
state: {},
|
|
11
|
-
filteredState: {},
|
|
12
|
-
dispatch() { },
|
|
13
|
-
configs: {},
|
|
14
|
-
async execute() {
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
export function useIntrigContext() {
|
|
18
|
-
return useContext(Context);
|
|
19
|
-
}
|
|
20
|
-
export { Context, };
|
|
21
|
-
//# sourceMappingURL=intrig-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-context.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-context.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAIZ,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAmClD;;;;;GAKG;AACH,IAAI,OAAO,GAAG,aAAa,CAAc;IACvC,KAAK,EAAE,EAAE;IACT,aAAa,EAAE,EAAE;IACjB,QAAQ,KAAI,CAAC;IACb,OAAO,EAAE,EAAE;IACX,KAAK,CAAC,OAAO;IAEb,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC;AAED,OAAO,EACL,OAAO,GAGR,CAAA"}
|
package/src/intrig-middleware.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
//@ts-ignore
|
|
4
|
-
let insightHook = await import('intrig-hook');
|
|
5
|
-
import { headers as requestHeaders } from 'next/headers';
|
|
6
|
-
export async function getAxiosInstance(key) {
|
|
7
|
-
const baseURL = process.env[`${key.toUpperCase()}_API_URL`];
|
|
8
|
-
if (!baseURL) {
|
|
9
|
-
throw new Error(`Environment variable ${key.toUpperCase()}_API_URL is not defined.`);
|
|
10
|
-
}
|
|
11
|
-
const axiosInstance = axios.create({ baseURL });
|
|
12
|
-
if (insightHook?.requestInterceptor) {
|
|
13
|
-
axiosInstance.interceptors.request.use(insightHook.requestInterceptor);
|
|
14
|
-
}
|
|
15
|
-
return axiosInstance;
|
|
16
|
-
}
|
|
17
|
-
export async function addResponseToHydrate(key, responseData) {
|
|
18
|
-
let _headers = await requestHeaders();
|
|
19
|
-
let intrigHydrated = _headers.get('INTRIG_HYDRATED');
|
|
20
|
-
let ob = intrigHydrated ? JSON.parse(intrigHydrated) : {};
|
|
21
|
-
ob[key] = responseData;
|
|
22
|
-
_headers.set('INTRIG_HYDRATED', JSON.stringify(ob));
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=intrig-middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"intrig-middleware.js","sourceRoot":"","sources":["../../../../lib/client-next/src/intrig-middleware.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,YAAY;AACZ,IAAI,WAAW,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;AAC9C,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,cAAc,CAAA;AAEtD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,wBAAwB,GAAG,CAAC,WAAW,EAAE,0BAA0B,CACpE,CAAC;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAEhD,IAAI,WAAW,EAAE,kBAAkB,EAAE,CAAC;QACpC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,YAAiB;IACvE,IAAI,QAAQ,GAAG,MAAM,cAAc,EAAE,CAAC;IACtC,IAAI,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACrD,IAAI,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,EAAE,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
package/src/intrig-provider.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
import { IntrigHook, NetworkState } from './network-state';
|
|
3
|
-
import { CreateAxiosDefaults } from 'axios';
|
|
4
|
-
import { ZodSchema } from 'zod';
|
|
5
|
-
import { RequestType, GlobalState } from './intrig-context';
|
|
6
|
-
export interface DefaultConfigs extends CreateAxiosDefaults {
|
|
7
|
-
debounceDelay?: number;
|
|
8
|
-
}
|
|
9
|
-
export interface IntrigProviderProps {
|
|
10
|
-
configs?: DefaultConfigs;
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
initState?: GlobalState;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* IntrigProvider is a context provider component that sets up global state management
|
|
16
|
-
* and provides Axios instances for API requests.
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} props - The properties object.
|
|
19
|
-
* @param {React.ReactNode} props.children - The child components to be wrapped by the provider.
|
|
20
|
-
* @param {Object} [props.configs={}] - Configuration object for Axios instances.
|
|
21
|
-
* @param {Object} [props.configs.defaults={}] - Default configuration for Axios.
|
|
22
|
-
* @param {Object} [props.configs.petstore={}] - Configuration specific to the petstore API.
|
|
23
|
-
* @return {JSX.Element} A context provider component that wraps the provided children.
|
|
24
|
-
*/
|
|
25
|
-
export declare function IntrigProvider({ children, configs, initState, }: IntrigProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
export interface StubType<P, B, T> {
|
|
27
|
-
<P, B, T>(hook: IntrigHook<P, B, T>, fn: (params: P, body: B, dispatch: (state: NetworkState<T>) => void) => Promise<void>): void;
|
|
28
|
-
}
|
|
29
|
-
export type WithStubSupport<T> = T & {
|
|
30
|
-
stubs?: (stub: StubType<any, any, any>) => void;
|
|
31
|
-
};
|
|
32
|
-
export interface IntrigProviderStubProps {
|
|
33
|
-
configs?: DefaultConfigs;
|
|
34
|
-
stubs?: (stub: StubType<any, any, any>) => void;
|
|
35
|
-
children: React.ReactNode;
|
|
36
|
-
}
|
|
37
|
-
export declare function IntrigProviderStub({ children, configs, stubs }: IntrigProviderStubProps): import("react/jsx-runtime").JSX.Element;
|
|
38
|
-
export interface StatusTrapProps {
|
|
39
|
-
type: 'pending' | 'error' | 'pending + error';
|
|
40
|
-
propagate?: boolean;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* StatusTrap component is used to track and manage network request states.
|
|
44
|
-
*
|
|
45
|
-
* @param {Object} props - The properties object.
|
|
46
|
-
* @param {React.ReactNode} props.children - The child elements to be rendered.
|
|
47
|
-
* @param {string} props.type - The type of network state to handle ("error", "pending", "pending + error").
|
|
48
|
-
* @param {boolean} [props.propagate=true] - Whether to propagate the event to the parent context.
|
|
49
|
-
* @return {React.ReactElement} The context provider component with filtered state and custom dispatch.
|
|
50
|
-
*/
|
|
51
|
-
export declare function StatusTrap({ children, type, propagate, }: PropsWithChildren<StatusTrapProps>): import("react/jsx-runtime").JSX.Element;
|
|
52
|
-
export interface NetworkStateProps<T, E = unknown> {
|
|
53
|
-
key: string;
|
|
54
|
-
operation: string;
|
|
55
|
-
source: string;
|
|
56
|
-
schema?: ZodSchema<T>;
|
|
57
|
-
errorSchema?: ZodSchema<E>;
|
|
58
|
-
debounceDelay?: number;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* useNetworkState is a custom hook that manages the network state within the specified context.
|
|
62
|
-
* It handles making network requests, dispatching appropriate states based on the request lifecycle,
|
|
63
|
-
* and allows aborting ongoing requests.
|
|
64
|
-
*
|
|
65
|
-
* @param {Object} params - The parameters required to configure and use the network state.
|
|
66
|
-
* @param {string} params.key - A unique identifier for the network request.
|
|
67
|
-
* @param {string} params.operation - The operation type related to the request.
|
|
68
|
-
* @param {string} params.source - The source or endpoint for the network request.
|
|
69
|
-
* @param {Object} params.schema - The schema used for validating the response data.
|
|
70
|
-
* @param {number} [params.debounceDelay] - The debounce delay for executing the network request.
|
|
71
|
-
*
|
|
72
|
-
* @return {[NetworkState<T>, (request: AxiosRequestConfig) => void, () => void]}
|
|
73
|
-
* Returns a state object representing the current network state,
|
|
74
|
-
* a function to execute the network request, and a function to clear the request.
|
|
75
|
-
*/
|
|
76
|
-
export declare function useNetworkState<T, E = unknown>({ key, operation, source, schema, errorSchema, debounceDelay: requestDebounceDelay, }: NetworkStateProps<T>): [
|
|
77
|
-
NetworkState<T, E>,
|
|
78
|
-
(request: RequestType) => void,
|
|
79
|
-
clear: () => void,
|
|
80
|
-
(state: NetworkState<T, E>) => void
|
|
81
|
-
];
|
|
82
|
-
/**
|
|
83
|
-
* Handles central error extraction from the provided context.
|
|
84
|
-
* It filters the state to retain error states and maps them to a structured error object with additional context information.
|
|
85
|
-
* @return {Object[]} An array of objects representing the error states with context information such as source, operation, and key.
|
|
86
|
-
*/
|
|
87
|
-
export declare function useCentralError(): {
|
|
88
|
-
source: string;
|
|
89
|
-
operation: string;
|
|
90
|
-
key: string;
|
|
91
|
-
state: "error";
|
|
92
|
-
error: unknown;
|
|
93
|
-
statusCode?: number;
|
|
94
|
-
request?: any;
|
|
95
|
-
}[];
|
|
96
|
-
/**
|
|
97
|
-
* Uses central pending state handling by aggregating pending states from context.
|
|
98
|
-
* It calculates the overall progress of pending states if any, or returns an initial state otherwise.
|
|
99
|
-
*
|
|
100
|
-
* @return {NetworkState} The aggregated network state based on the pending states and their progress.
|
|
101
|
-
*/
|
|
102
|
-
export declare function useCentralPendingState(): NetworkState<unknown, unknown>;
|