@intrig/core 0.0.14-2 → 0.0.14-3
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 +48 -27
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -5991,7 +5991,7 @@ function context_template_contextTemplate(_path) {
|
|
|
5991
5991
|
import { NetworkAction, NetworkState } from '@intrig/react/network-state';
|
|
5992
5992
|
import { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
|
|
5993
5993
|
import { ZodSchema } from 'zod';
|
|
5994
|
-
import { createContext, useContext } from 'react';
|
|
5994
|
+
import { createContext, useContext, Dispatch } from 'react';
|
|
5995
5995
|
import { DefaultConfigs } from '@intrig/react/intrig-provider';
|
|
5996
5996
|
|
|
5997
5997
|
type GlobalState = Record<string, NetworkState>;
|
|
@@ -6008,13 +6008,13 @@ interface RequestType<T = any> extends AxiosRequestConfig {
|
|
|
6008
6008
|
*
|
|
6009
6009
|
* @interface ContextType
|
|
6010
6010
|
* @property {GlobalState} state - The global state of the application.
|
|
6011
|
-
* @property {
|
|
6011
|
+
* @property {Dispatch<NetworkAction<unknown>>} dispatch - The dispatch function to send network actions.
|
|
6012
6012
|
* @property {Record<string, AxiosInstance>} axios - A record of Axios instances for making HTTP requests.
|
|
6013
6013
|
*/
|
|
6014
6014
|
export interface ContextType {
|
|
6015
6015
|
state: GlobalState;
|
|
6016
6016
|
filteredState: GlobalState;
|
|
6017
|
-
dispatch:
|
|
6017
|
+
dispatch: Dispatch<NetworkAction<unknown, unknown>>;
|
|
6018
6018
|
configs: DefaultConfigs;
|
|
6019
6019
|
execute: <T>(request: RequestType, dispatch: (state: NetworkState<T>) => void, schema: ZodSchema<T> | undefined, errorSchema: ZodSchema<T> | undefined) => Promise<void>;
|
|
6020
6020
|
}
|
|
@@ -6134,11 +6134,13 @@ export function useAsPromise<P, B, T, E>(
|
|
|
6134
6134
|
* @param key An optional identifier for the network state. Defaults to 'default'.
|
|
6135
6135
|
* @return A tuple containing the current network state, a function to execute the promise, and a function to clear the state.
|
|
6136
6136
|
*/
|
|
6137
|
-
export function useAsNetworkState<T, F extends ((...args: any) => Promise<T>)>(fn: F,
|
|
6137
|
+
export function useAsNetworkState<T, F extends ((...args: any) => Promise<T>)>(fn: F, options: any = {}): [NetworkState<T>, (...params: Parameters<F>) => void, () => void] {
|
|
6138
6138
|
let id = useId();
|
|
6139
6139
|
|
|
6140
6140
|
let context = useIntrigContext();
|
|
6141
6141
|
|
|
6142
|
+
let key = options.key ?? 'default';
|
|
6143
|
+
|
|
6142
6144
|
const networkState = useMemo(() => {
|
|
6143
6145
|
return context.state?.[${"`promiseState:${id}:${key}}`"}] ?? init()
|
|
6144
6146
|
}, [context.state?.[${"`promiseState:${id}:${key}}`"}]]);
|
|
@@ -6150,7 +6152,7 @@ export function useAsNetworkState<T, F extends ((...args: any) => Promise<T>)>(f
|
|
|
6150
6152
|
[key, context.dispatch]
|
|
6151
6153
|
);
|
|
6152
6154
|
|
|
6153
|
-
const execute = useCallback((...args:
|
|
6155
|
+
const execute = useCallback((...args: any[]) => {
|
|
6154
6156
|
dispatch(pending())
|
|
6155
6157
|
return fn(...args).then(
|
|
6156
6158
|
(data) => {
|
|
@@ -7011,7 +7013,9 @@ export function isResponseValidationError<T, E>(value: IntrigError<T, E>): value
|
|
|
7011
7013
|
;// ../../lib/react-binding/src/lib/templates/packageJson.template.ts
|
|
7012
7014
|
|
|
7013
7015
|
|
|
7016
|
+
|
|
7014
7017
|
function packageJson_template_packageJsonTemplate(_path) {
|
|
7018
|
+
const packageJson = external_fs_extra_namespaceObject.readJsonSync(external_path_namespaceObject.resolve(_path, '..', '..', 'package.json'));
|
|
7015
7019
|
const json = jsonLiteral(external_path_namespaceObject.resolve(_path, 'package.json'));
|
|
7016
7020
|
return json`
|
|
7017
7021
|
{
|
|
@@ -7033,9 +7037,16 @@ function packageJson_template_packageJsonTemplate(_path) {
|
|
|
7033
7037
|
"module-alias": "^2.2.2",
|
|
7034
7038
|
"zod": "^3.23.8"
|
|
7035
7039
|
},
|
|
7040
|
+
"devDependencies": {
|
|
7041
|
+
"@swc/cli": "^0.7.7",
|
|
7042
|
+
"@swc/core": "^1.12.6",
|
|
7043
|
+
"@types/node": "^24.0.4",
|
|
7044
|
+
"react": "${packageJson.dependencies.react}",
|
|
7045
|
+
"react-dom": "${packageJson.dependencies['react-dom']}"
|
|
7046
|
+
},
|
|
7036
7047
|
"peerDependencies": {
|
|
7037
|
-
"react": "18.
|
|
7038
|
-
"react-dom": "18.
|
|
7048
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
7049
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
7039
7050
|
},
|
|
7040
7051
|
"_moduleAliases": {
|
|
7041
7052
|
"@intrig/react": "./src"
|
|
@@ -7418,7 +7429,7 @@ export function useNetworkState<T, E = unknown>({
|
|
|
7418
7429
|
}: NetworkStateProps<T>): [
|
|
7419
7430
|
NetworkState<T, E>,
|
|
7420
7431
|
(request: RequestType) => void,
|
|
7421
|
-
|
|
7432
|
+
() => void,
|
|
7422
7433
|
(state: NetworkState<T, E>) => void
|
|
7423
7434
|
] {
|
|
7424
7435
|
const context = useContext(Context);
|
|
@@ -7530,7 +7541,7 @@ export function useTransientCall<T, E = unknown>({
|
|
|
7530
7541
|
{ ...request, signal: abort.signal },
|
|
7531
7542
|
(state) => {
|
|
7532
7543
|
if (isSuccess(state)) {
|
|
7533
|
-
resolve(state.data);
|
|
7544
|
+
resolve(state.data as T);
|
|
7534
7545
|
} else if (isError(state)) {
|
|
7535
7546
|
reject(state.error);
|
|
7536
7547
|
}
|
|
@@ -7547,7 +7558,7 @@ export function useTransientCall<T, E = unknown>({
|
|
|
7547
7558
|
controller.current?.abort();
|
|
7548
7559
|
}, []);
|
|
7549
7560
|
|
|
7550
|
-
return [call, abort]
|
|
7561
|
+
return [call, abort];
|
|
7551
7562
|
}
|
|
7552
7563
|
|
|
7553
7564
|
function debounce<T extends (...args: any[]) => void>(func: T, delay: number) {
|
|
@@ -7572,7 +7583,7 @@ export function useCentralError() {
|
|
|
7572
7583
|
const ctx = useContext(Context);
|
|
7573
7584
|
|
|
7574
7585
|
return useMemo(() => {
|
|
7575
|
-
return Object.entries(ctx.filteredState)
|
|
7586
|
+
return Object.entries(ctx.filteredState as Record<string, NetworkState>)
|
|
7576
7587
|
.filter(([, state]) => isError(state))
|
|
7577
7588
|
.map(([k, state]) => {
|
|
7578
7589
|
let [source, operation, key] = k.split(':');
|
|
@@ -7596,7 +7607,7 @@ export function useCentralPendingState() {
|
|
|
7596
7607
|
const ctx = useContext(Context);
|
|
7597
7608
|
|
|
7598
7609
|
const result: NetworkState = useMemo(() => {
|
|
7599
|
-
let pendingStates = Object.values(ctx.filteredState).filter(isPending);
|
|
7610
|
+
let pendingStates = Object.values(ctx.filteredState as Record<string, NetworkState>).filter(isPending);
|
|
7600
7611
|
if (!pendingStates.length) {
|
|
7601
7612
|
return init();
|
|
7602
7613
|
}
|
|
@@ -7634,6 +7645,7 @@ function tsconfig_template_tsConfigTemplate(_path) {
|
|
|
7634
7645
|
"outDir": "./dist",
|
|
7635
7646
|
"strict": true,
|
|
7636
7647
|
"esModuleInterop": true,
|
|
7648
|
+
"noImplicitAny": false,
|
|
7637
7649
|
"moduleResolution": "node",
|
|
7638
7650
|
"baseUrl": "./",
|
|
7639
7651
|
"paths": {
|
|
@@ -7875,22 +7887,34 @@ async function requestHook_template_requestHookTemplate({ source, data: { paths,
|
|
|
7875
7887
|
;// ../../lib/react-binding/src/lib/templates/source/controller/method/download.template.ts
|
|
7876
7888
|
|
|
7877
7889
|
|
|
7878
|
-
function
|
|
7890
|
+
function download_template_extractHookShapeAndOptionsShape(response, requestBody, imports) {
|
|
7879
7891
|
if (response) {
|
|
7880
7892
|
if (requestBody) {
|
|
7881
|
-
imports.add(`import { BinaryFunctionHook } from "@intrig/react"`);
|
|
7882
|
-
return
|
|
7893
|
+
imports.add(`import { BinaryFunctionHook, BinaryHookOptions } from "@intrig/react"`);
|
|
7894
|
+
return {
|
|
7895
|
+
hookShape: `BinaryFunctionHook<Params, RequestBody, Response, _ErrorType>`,
|
|
7896
|
+
optionsShape: `BinaryHookOptions<Params, RequestBody>`
|
|
7897
|
+
};
|
|
7883
7898
|
} else {
|
|
7884
|
-
imports.add(`import { UnaryFunctionHook } from "@intrig/react"`);
|
|
7885
|
-
return
|
|
7899
|
+
imports.add(`import { UnaryFunctionHook, UnaryHookOptions } from "@intrig/react"`);
|
|
7900
|
+
return {
|
|
7901
|
+
hookShape: `UnaryFunctionHook<Params, Response, _ErrorType>`,
|
|
7902
|
+
optionsShape: `UnaryHookOptions<Params>`
|
|
7903
|
+
};
|
|
7886
7904
|
}
|
|
7887
7905
|
} else {
|
|
7888
7906
|
if (requestBody) {
|
|
7889
|
-
imports.add(`import { BinaryProduceHook } from "@intrig/react"`);
|
|
7890
|
-
return
|
|
7907
|
+
imports.add(`import { BinaryProduceHook, BinaryHookOptions } from "@intrig/react"`);
|
|
7908
|
+
return {
|
|
7909
|
+
hookShape: `BinaryProduceHook<Params, RequestBody, _ErrorType>`,
|
|
7910
|
+
optionsShape: `BinaryHookOptions<Params, RequestBody>`
|
|
7911
|
+
};
|
|
7891
7912
|
} else {
|
|
7892
|
-
imports.add(`import { UnaryProduceHook } from "@intrig/react"`);
|
|
7893
|
-
return
|
|
7913
|
+
imports.add(`import { UnaryProduceHook, UnaryHookOptions } from "@intrig/react"`);
|
|
7914
|
+
return {
|
|
7915
|
+
hookShape: `UnaryProduceHook<Params, _ErrorType>`,
|
|
7916
|
+
optionsShape: `UnaryHookOptions<Params>`
|
|
7917
|
+
};
|
|
7894
7918
|
}
|
|
7895
7919
|
}
|
|
7896
7920
|
}
|
|
@@ -7945,7 +7969,7 @@ async function download_template_downloadHookTemplate({ source, data: { paths, o
|
|
|
7945
7969
|
imports.add(`import { z } from 'zod'`);
|
|
7946
7970
|
imports.add(`import { useCallback } from 'react'`);
|
|
7947
7971
|
imports.add(`import {useNetworkState, NetworkState, DispatchState, pending, success, error, successfulDispatch, validationError, encode} from "@intrig/react"`);
|
|
7948
|
-
const hookShape =
|
|
7972
|
+
const { hookShape, optionsShape } = download_template_extractHookShapeAndOptionsShape(response, requestBody, imports);
|
|
7949
7973
|
const { paramExpression, paramType } = download_template_extractParamDeconstruction(variables, requestBody);
|
|
7950
7974
|
if (requestBody) {
|
|
7951
7975
|
imports.add(`import { ${requestBody} as RequestBody, ${requestBody}Schema as requestBodySchema } from "@intrig/react/${source}/components/schemas/${requestBody}"`);
|
|
@@ -8003,9 +8027,9 @@ async function download_template_downloadHookTemplate({ source, data: { paths, o
|
|
|
8003
8027
|
const operation = "${method.toUpperCase()} ${requestUrl}| ${contentType} -> ${responseType}"
|
|
8004
8028
|
const source = "${source}"
|
|
8005
8029
|
|
|
8006
|
-
function use${pascalCase(operationId)}Hook(
|
|
8030
|
+
function use${pascalCase(operationId)}Hook(options: ${optionsShape} = {}): [NetworkState<Response, _ErrorType>, (${paramType}) => DispatchState<any>, () => void] {
|
|
8007
8031
|
let [state,, clear, dispatch] = useNetworkState<Response, _ErrorType>({
|
|
8008
|
-
key,
|
|
8032
|
+
key: options?.key ?? 'default',
|
|
8009
8033
|
operation,
|
|
8010
8034
|
source,
|
|
8011
8035
|
schema,
|
|
@@ -10769,9 +10793,6 @@ class OperationsService {
|
|
|
10769
10793
|
}
|
|
10770
10794
|
async installDependencies(ctx) {
|
|
10771
10795
|
await this.packageManagerService.install(this.generateDir);
|
|
10772
|
-
await this.packageManagerService.installDependency("@swc/core", true, false, this.generateDir);
|
|
10773
|
-
await this.packageManagerService.installDependency("@swc/cli", true, false, this.generateDir);
|
|
10774
|
-
await this.packageManagerService.installDependency("@types/node", true, false, this.generateDir);
|
|
10775
10796
|
}
|
|
10776
10797
|
async generateGlobalContent(ctx, apisToSync) {
|
|
10777
10798
|
await this.generatorBinding.generateGlobal(apisToSync);
|