@intrig/core 0.0.15-2 → 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/README.md +1 -12
- package/main.js +16 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
3
|
-
<g transform="translate(-41.904154,-168.00498)">
|
|
4
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 114.89996,168.10498 c -1.06916,0 -1.9358,0.86714 -1.9358,1.96733 v 3.84059 h -2.61224 c -1.09993,0 -1.9668,0.86664 -1.9668,1.9358 0,1.06918 0.86687,1.9358 1.9668,1.9358 h 2.61224 v 13.58211 c 0,1.09993 0.86664,1.96681 1.9358,1.96681 1.06916,0 1.9358,-0.86688 1.9358,-1.96681 V 177.7845 h 2.55023 c 1.1002,0 1.96681,-0.86662 1.96681,-1.9358 0,-1.06916 -0.86661,-1.9358 -1.96681,-1.9358 h -2.55023 v -3.84059 c 0,-1.10019 -0.86664,-1.96733 -1.9358,-1.96733 z" />
|
|
5
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 105.8658,183.59235 c 0,-3.2075 -2.6002,-5.8077 -5.8077,-5.8077 -3.20751,0 -5.8077,2.6002 -5.8077,5.82483 1.2e-4,4.19734 0,4.49999 0,7.73546 0,1.07815 -0.866741,1.94487 -1.935903,1.94487 -1.069175,0 -1.935901,-0.86672 -1.935901,-1.94487 0,-3.23547 9.4e-5,-3.11312 0,-7.74183 0,-5.35659 4.333654,-9.69026 9.679504,-9.69026 5.34584,0 9.6795,4.33367 9.6795,9.69275 v 7.68735 c 0,1.11218 -0.86674,1.97892 -1.9359,1.97892 -1.06916,0 -1.9359,-0.86674 -1.9359,-1.97892 z" />
|
|
6
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 124.57948,173.88189 c -1.06917,0 -1.9358,0.86662 -1.9358,1.96681 v 7.74371 7.7742 c 0,1.09993 0.86663,1.96681 1.9358,1.96681 1.06915,0 1.9358,-0.86688 1.9358,-1.96681 v -7.75921 c 0,-3.23303 2.62074,-5.85381 5.83065,-5.83841 1.0461,0.0155 1.91306,-0.85113 1.91306,-1.92029 0,-1.06916 -0.86696,-1.936 -1.91306,-1.9513 -2.18669,-0.006 -4.20651,0.71897 -5.83117,1.94458 -0.004,-1.09694 -0.86834,-1.96009 -1.93528,-1.96009 z" />
|
|
7
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 137.48551,193.318 c -1.06916,0 -1.9359,-0.86674 -1.9359,-1.96666 v -10.95446 c 0,-1.10019 0.86674,-1.96693 1.9359,-1.96693 1.06916,0 1.9359,0.86674 1.9359,1.96693 v 10.95446 c 0,1.09992 -0.86674,1.96666 -1.9359,1.96666 z" />
|
|
8
|
-
<circle style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" cx="137.48552" cy="175.84875" r="1.9358984" />
|
|
9
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 159.42593,173.88189 c -1.06916,0 -1.93632,0.86662 -1.93632,1.96681 v 0.001 a 9.6795038,9.6795038 0 0 0 -5.8074,-1.93683 9.6795038,9.6795038 0 0 0 -9.67951,9.67951 9.6795038,9.6795038 0 0 0 9.67951,9.67951 9.6795038,9.6795038 0 0 0 5.8074,-1.9668 v 3.82199 c 0,3.28811 -2.60016,5.88852 -5.83168,5.88078 l -93.953959,-0.008 c -1.099919,0 -1.966805,0.86664 -1.966805,1.9358 0,1.06916 0.866886,1.93631 1.966805,1.93631 l 93.934319,0.005 c 5.38943,0.0105 9.72344,-4.32282 9.72344,-9.74927 v -11.5347 -7.74371 c 0,-1.10019 -0.86662,-1.96681 -1.9358,-1.96681 z m -7.74372,3.90312 a 5.8077041,5.8077041 0 0 1 5.8074,5.80172 v 0.0114 a 5.8077041,5.8077041 0 0 1 -5.8074,5.80223 5.8077041,5.8077041 0 0 1 -5.80791,-5.80792 5.8077041,5.8077041 0 0 1 5.80791,-5.8074 z" />
|
|
10
|
-
<path style="fill:#00D8C0;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 85.216195,193.318 c -1.069162,0 -1.9359,-0.86674 -1.9359,-1.96666 v -20.98655 c 0,-1.10019 0.866738,-1.96693 1.9359,-1.96693 1.069162,0 1.935901,0.86674 1.935901,1.96693 v 20.98655 c 0,1.09992 -0.866739,1.96666 -1.935901,1.96666 z" />
|
|
11
|
-
<path style="fill:#888888;fill-opacity:1;stroke:#ffffff;stroke-width:0.2;stroke-dasharray:none;stroke-opacity:0.2" d="m 81.734029,179.04592 -23.717415,0.004 c -8.78429,0.0146 -16.011886,7.2611 -16.01246,16.03158 v 5.1e-4 5.2e-4 c 5.65e-4,8.77049 7.109474,15.87969 15.953032,15.8812 h 9.220626 c 1.249561,0 2.206067,-0.97006 2.206067,-2.16731 0,-1.19725 -0.956114,-2.16783 -2.231906,-2.16783 l -8.990665,-0.0114 c -6.451791,-0.0129 -11.597742,-5.20849 -11.597742,-11.61738 0,-6.40889 5.145707,-11.60343 11.493355,-11.60343 6.347649,0 11.493356,5.19457 11.493356,11.60343 0,8.81624 7.059408,15.96376 15.695682,15.9644 l 66.275541,0.002 c 9.23414,-3e-5 16.47858,-7.14834 16.47858,-15.96595 0,-4.51466 -1.90726,-8.58331 -5.00021,-11.48715 v 9.75754 c 0.086,0.56895 0.14469,1.14707 0.14469,1.73995 0,6.40551 -5.19367,11.59754 -11.62978,11.60756 l -66.117409,0.009 c -6.422849,0 -11.565661,-5.20583 -11.566219,-11.62771 v -5.2e-4 -5.2e-4 c 4.13e-4,-5.32739 3.16079,-9.8136 7.902877,-11.17968 z" />
|
|
12
|
-
</g>
|
|
13
|
-
</svg>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/intrigsoft/intrig-core/refs/heads/main/docs/images/intrig-logo.svg" alt="Intrig Logo" width="300"/>
|
|
14
3
|
</div>
|
|
15
4
|
|
|
16
5
|
# Intrig Core
|
package/main.js
CHANGED
|
@@ -6110,9 +6110,9 @@ function reactContextTemplate(_path, apisToSync) {
|
|
|
6110
6110
|
${apisToSync.map((a)=>`${a.id}?: DefaultConfigs`).join(",\n ")}
|
|
6111
6111
|
}`;
|
|
6112
6112
|
return ts`
|
|
6113
|
-
|
|
6113
|
+
import { NetworkAction, NetworkState } from '@intrig/react/network-state';
|
|
6114
6114
|
import { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
|
|
6115
|
-
import { ZodSchema } from 'zod';
|
|
6115
|
+
import { ZodSchema, ZodType, ZodTypeDef } from 'zod';
|
|
6116
6116
|
import { createContext, useContext, Dispatch } from 'react';
|
|
6117
6117
|
import { DefaultConfigs } from '@intrig/react/intrig-provider';
|
|
6118
6118
|
|
|
@@ -6124,6 +6124,8 @@ interface RequestType<T = any> extends AxiosRequestConfig {
|
|
|
6124
6124
|
source: string
|
|
6125
6125
|
}
|
|
6126
6126
|
|
|
6127
|
+
export type SchemaOf<T> = ZodType<T, ZodTypeDef, any>;
|
|
6128
|
+
|
|
6127
6129
|
/**
|
|
6128
6130
|
* Defines the ContextType interface for managing global state, dispatching actions,
|
|
6129
6131
|
* and holding a collection of Axios instances.
|
|
@@ -6138,7 +6140,7 @@ export interface ContextType {
|
|
|
6138
6140
|
filteredState: GlobalState;
|
|
6139
6141
|
dispatch: Dispatch<NetworkAction<unknown, unknown>>;
|
|
6140
6142
|
configs: ${configType};
|
|
6141
|
-
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>;
|
|
6142
6144
|
}
|
|
6143
6145
|
|
|
6144
6146
|
/**
|
|
@@ -6194,60 +6196,6 @@ function reactExtraTemplate(_path) {
|
|
|
6194
6196
|
import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
6195
6197
|
import { useIntrigContext } from '@intrig/react/intrig-context';
|
|
6196
6198
|
|
|
6197
|
-
/**
|
|
6198
|
-
* Converts a given hook into a promise-based function.
|
|
6199
|
-
*
|
|
6200
|
-
* @param {IntrigHook<P, B, T>} hook - The hook function to be converted.
|
|
6201
|
-
* @param {string} [key='default'] - An optional key to uniquely identify the hook instance.
|
|
6202
|
-
*
|
|
6203
|
-
* @return {[(...params: Parameters<ReturnType<IntrigHook<P, B, T>>[1]>) => Promise<T>, () => void]}
|
|
6204
|
-
* Returns a tuple containing a function that invokes the hook as a promise and a function to clear the state.
|
|
6205
|
-
*/
|
|
6206
|
-
export function useAsPromise<E>(hook: UnitHook<E>, options: UnitHookOptions): [() => Promise<never>, () => void];
|
|
6207
|
-
export function useAsPromise<T, E>(hook: ConstantHook<T, E>, options: UnitHookOptions): [() => Promise<T>, () => void];
|
|
6208
|
-
export function useAsPromise<P, E>(hook: UnaryProduceHook<P, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<never>, () => void];
|
|
6209
|
-
export function useAsPromise<P, T, E>( hook: UnaryFunctionHook<P, T, E>, options?: UnaryHookOptions<P>): [(params: P) => Promise<T>, () => void];
|
|
6210
|
-
export function useAsPromise<P, B, E>(hook: BinaryProduceHook<P, B, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<never>, () => void];
|
|
6211
|
-
export function useAsPromise<P, B, T, E>(hook: BinaryFunctionHook<P, B, T, E>, options?: BinaryHookOptions<P, B>): [(body: B, params: P) => Promise<T>, () => void];
|
|
6212
|
-
|
|
6213
|
-
// **Implementation**
|
|
6214
|
-
export function useAsPromise<P, B, T, E>(
|
|
6215
|
-
hook: IntrigHook<P, B, T, E>,
|
|
6216
|
-
options?: IntrigHookOptions<P, B>
|
|
6217
|
-
): [(...args: any[]) => Promise<T>, () => void] { // <- Compatible return type
|
|
6218
|
-
const resolveRef = useRef<(value: T) => void>(() => {});
|
|
6219
|
-
const rejectRef = useRef<(reason?: any) => void>(() => {});
|
|
6220
|
-
|
|
6221
|
-
const [state, dispatch, clear] = hook(options as any);
|
|
6222
|
-
|
|
6223
|
-
useEffect(() => {
|
|
6224
|
-
if (isSuccess(state)) {
|
|
6225
|
-
resolveRef.current?.(state.data);
|
|
6226
|
-
clear();
|
|
6227
|
-
} else if (isError(state)) {
|
|
6228
|
-
rejectRef.current?.(state.error);
|
|
6229
|
-
clear()
|
|
6230
|
-
}
|
|
6231
|
-
}, [state]);
|
|
6232
|
-
|
|
6233
|
-
const promiseFn = useCallback((...args: Parameters<ReturnType<IntrigHook<P, B, T>>[1]>) => {
|
|
6234
|
-
return new Promise<T>((resolve, reject) => {
|
|
6235
|
-
resolveRef.current = resolve;
|
|
6236
|
-
rejectRef.current = reject;
|
|
6237
|
-
|
|
6238
|
-
const dispatchState = (dispatch as any)(...args);
|
|
6239
|
-
if (isValidationError(dispatchState)) {
|
|
6240
|
-
reject(dispatchState.error);
|
|
6241
|
-
}
|
|
6242
|
-
});
|
|
6243
|
-
}, [dispatch]);
|
|
6244
|
-
|
|
6245
|
-
return [
|
|
6246
|
-
promiseFn,
|
|
6247
|
-
clear
|
|
6248
|
-
];
|
|
6249
|
-
}
|
|
6250
|
-
|
|
6251
6199
|
/**
|
|
6252
6200
|
* A custom hook that manages and returns the network state of a promise-based function,
|
|
6253
6201
|
* providing a way to execute the function and clear its state.
|
|
@@ -7244,12 +7192,12 @@ import axios, {
|
|
|
7244
7192
|
InternalAxiosRequestConfig,
|
|
7245
7193
|
isAxiosError,
|
|
7246
7194
|
} from 'axios';
|
|
7247
|
-
import { ZodSchema
|
|
7195
|
+
import { ZodSchema } from 'zod';
|
|
7248
7196
|
import logger from './logger';
|
|
7249
7197
|
import {flushSync} from "react-dom";
|
|
7250
7198
|
import {createParser} from "eventsource-parser";
|
|
7251
7199
|
|
|
7252
|
-
import {Context, RequestType, GlobalState} from './intrig-context';
|
|
7200
|
+
import {Context, RequestType, GlobalState, SchemaOf} from './intrig-context';
|
|
7253
7201
|
|
|
7254
7202
|
/**
|
|
7255
7203
|
* Handles state updates for network requests based on the provided action.
|
|
@@ -7552,8 +7500,8 @@ export interface NetworkStateProps<T, E = unknown> {
|
|
|
7552
7500
|
key: string;
|
|
7553
7501
|
operation: string;
|
|
7554
7502
|
source: string;
|
|
7555
|
-
schema?:
|
|
7556
|
-
errorSchema?:
|
|
7503
|
+
schema?: SchemaOf<T>;
|
|
7504
|
+
errorSchema?: SchemaOf<E>;
|
|
7557
7505
|
debounceDelay?: number;
|
|
7558
7506
|
}
|
|
7559
7507
|
|
|
@@ -7666,8 +7614,6 @@ export function useNetworkState<T, E = unknown>({
|
|
|
7666
7614
|
return [networkState, deboundedExecute, clear, dispatch];
|
|
7667
7615
|
}
|
|
7668
7616
|
|
|
7669
|
-
type ZodOut<T> = ZodType<T, ZodTypeDef, unknown>;
|
|
7670
|
-
|
|
7671
7617
|
/**
|
|
7672
7618
|
* A hook for making transient calls that can be aborted and validated against schemas.
|
|
7673
7619
|
*
|
|
@@ -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();
|
|
@@ -13820,7 +13768,7 @@ async function bootstrap() {
|
|
|
13820
13768
|
} else {
|
|
13821
13769
|
try {
|
|
13822
13770
|
await external_nest_commander_namespaceObject.CommandFactory.run(AppModule, {
|
|
13823
|
-
logger:
|
|
13771
|
+
logger: false,
|
|
13824
13772
|
errorHandler (err) {
|
|
13825
13773
|
if (err.code === 'commander.help') {
|
|
13826
13774
|
return process.exit(0);
|