@intrig/core 0.0.15-3 → 0.0.15-4
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/main.js +11 -63
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -6124,7 +6124,7 @@ interface RequestType<T = any> extends AxiosRequestConfig {
|
|
|
6124
6124
|
source: string
|
|
6125
6125
|
}
|
|
6126
6126
|
|
|
6127
|
-
export type
|
|
6127
|
+
export type SchemaOf<T> = ZodType<T, ZodTypeDef, any>;
|
|
6128
6128
|
|
|
6129
6129
|
/**
|
|
6130
6130
|
* Defines the ContextType interface for managing global state, dispatching actions,
|
|
@@ -6140,7 +6140,7 @@ export interface ContextType {
|
|
|
6140
6140
|
filteredState: GlobalState;
|
|
6141
6141
|
dispatch: Dispatch<NetworkAction<unknown, unknown>>;
|
|
6142
6142
|
configs: ${configType};
|
|
6143
|
-
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema:
|
|
6143
|
+
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: SchemaOf<T> | undefined, errorSchema: SchemaOf<T> | undefined) => Promise<void>;
|
|
6144
6144
|
}
|
|
6145
6145
|
|
|
6146
6146
|
/**
|
|
@@ -6196,60 +6196,6 @@ function reactExtraTemplate(_path) {
|
|
|
6196
6196
|
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
6197
6197
|
import { useIntrigContext } from '@intrig/react/intrig-context';
|
|
6198
6198
|
|
|
6199
|
-
/**
|
|
6200
|
-
* Converts a given hook into a promise-based function.
|
|
6201
|
-
*
|
|
6202
|
-
* @param {IntrigHook<P, B, T>} hook - The hook function to be converted.
|
|
6203
|
-
* @param {string} [key='default'] - An optional key to uniquely identify the hook instance.
|
|
6204
|
-
*
|
|
6205
|
-
* @return {[(...params: Parameters<ReturnType<IntrigHook<P, B, T>>[1]>) => Promise<T>, () => void]}
|
|
6206
|
-
* Returns a tuple containing a function that invokes the hook as a promise and a function to clear the state.
|
|
6207
|
-
*/
|
|
6208
|
-
export function useAsPromise<E>(hook: UnitHook<E>, options: UnitHookOptions): [() => Promise<never>, () => void];
|
|
6209
|
-
export function useAsPromise<T, E>(hook: ConstantHook<T, E>, options: UnitHookOptions): [() => Promise<T>, () => void];
|
|
6210
|
-
export function useAsPromise<P, E>(hook: UnaryProduceHook<P, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<never>, () => void];
|
|
6211
|
-
export function useAsPromise<P, T, E>( hook: UnaryFunctionHook<P, T, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<T>, () => void];
|
|
6212
|
-
export function useAsPromise<P, B, E>(hook: BinaryProduceHook<P, B, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<never>, () => void];
|
|
6213
|
-
export function useAsPromise<P, B, T, E>(hook: BinaryFunctionHook<P, B, T, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<T>, () => void];
|
|
6214
|
-
|
|
6215
|
-
// **Implementation**
|
|
6216
|
-
export function useAsPromise<P, B, T, E>(
|
|
6217
|
-
hook: IntrigHook<P, B, T, E>,
|
|
6218
|
-
options?: IntrigHookOptions<P, B>
|
|
6219
|
-
): [(...args: any[]) => Promise<T>, () => void] { // <- Compatible return type
|
|
6220
|
-
const resolveRef = useRef<(value: T) => void>(() => {});
|
|
6221
|
-
const rejectRef = useRef<(reason?: any) => void>(() => {});
|
|
6222
|
-
|
|
6223
|
-
const [state, dispatch, clear] = hook(options as any);
|
|
6224
|
-
|
|
6225
|
-
useEffect(() => {
|
|
6226
|
-
if (isSuccess(state)) {
|
|
6227
|
-
resolveRef.current?.(state.data);
|
|
6228
|
-
clear();
|
|
6229
|
-
} else if (isError(state)) {
|
|
6230
|
-
rejectRef.current?.(state.error);
|
|
6231
|
-
clear()
|
|
6232
|
-
}
|
|
6233
|
-
}, [state]);
|
|
6234
|
-
|
|
6235
|
-
const promiseFn = useCallback((...args: Parameters<ReturnType<IntrigHook<P, B, T>>[1]>) => {
|
|
6236
|
-
return new Promise<T>((resolve, reject) => {
|
|
6237
|
-
resolveRef.current = resolve;
|
|
6238
|
-
rejectRef.current = reject;
|
|
6239
|
-
|
|
6240
|
-
const dispatchState = (dispatch as any)(...args);
|
|
6241
|
-
if (isValidationError(dispatchState)) {
|
|
6242
|
-
reject(dispatchState.error);
|
|
6243
|
-
}
|
|
6244
|
-
});
|
|
6245
|
-
}, [dispatch]);
|
|
6246
|
-
|
|
6247
|
-
return [
|
|
6248
|
-
promiseFn,
|
|
6249
|
-
clear
|
|
6250
|
-
];
|
|
6251
|
-
}
|
|
6252
|
-
|
|
6253
6199
|
/**
|
|
6254
6200
|
* A custom hook that manages and returns the network state of a promise-based function,
|
|
6255
6201
|
* providing a way to execute the function and clear its state.
|
|
@@ -7251,7 +7197,7 @@ import logger from './logger';
|
|
|
7251
7197
|
import {flushSync} from "react-dom";
|
|
7252
7198
|
import {createParser} from "eventsource-parser";
|
|
7253
7199
|
|
|
7254
|
-
import {Context, RequestType, GlobalState,
|
|
7200
|
+
import {Context, RequestType, GlobalState, SchemaOf} from './intrig-context';
|
|
7255
7201
|
|
|
7256
7202
|
/**
|
|
7257
7203
|
* Handles state updates for network requests based on the provided action.
|
|
@@ -7554,8 +7500,8 @@ export interface NetworkStateProps<T, E = unknown> {
|
|
|
7554
7500
|
key: string;
|
|
7555
7501
|
operation: string;
|
|
7556
7502
|
source: string;
|
|
7557
|
-
schema?:
|
|
7558
|
-
errorSchema?:
|
|
7503
|
+
schema?: SchemaOf<T>;
|
|
7504
|
+
errorSchema?: SchemaOf<E>;
|
|
7559
7505
|
debounceDelay?: number;
|
|
7560
7506
|
}
|
|
7561
7507
|
|
|
@@ -7680,11 +7626,11 @@ export function useTransientCall<T, E = unknown>({
|
|
|
7680
7626
|
schema,
|
|
7681
7627
|
errorSchema
|
|
7682
7628
|
}: {
|
|
7683
|
-
schema?:
|
|
7684
|
-
errorSchema?:
|
|
7629
|
+
schema?: SchemaOf<T>;
|
|
7630
|
+
errorSchema?: SchemaOf<T>
|
|
7685
7631
|
}): [(request: RequestType) => Promise<T>, () => void] {
|
|
7686
7632
|
const ctx = useContext(Context);
|
|
7687
|
-
const controller = useRef<AbortController>(
|
|
7633
|
+
const controller = useRef<AbortController | undefined>(undefined);
|
|
7688
7634
|
|
|
7689
7635
|
const call = useCallback(
|
|
7690
7636
|
async (request: RequestType)=> {
|
|
@@ -13777,10 +13723,12 @@ const core_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("
|
|
|
13777
13723
|
|
|
13778
13724
|
|
|
13779
13725
|
|
|
13780
|
-
const isVerbose = process.argv.includes('--verbose');
|
|
13781
13726
|
const logger = new common_namespaceObject.Logger('Main');
|
|
13782
13727
|
async function bootstrapDeamon() {
|
|
13783
13728
|
const app = await core_namespaceObject.NestFactory.create(AppModule, {
|
|
13729
|
+
logger: [
|
|
13730
|
+
'error'
|
|
13731
|
+
]
|
|
13784
13732
|
});
|
|
13785
13733
|
app.enableShutdownHooks();
|
|
13786
13734
|
app.enableCors();
|