@intrig/core 0.0.15-3 → 0.0.15-5

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.
Files changed (2) hide show
  1. package/main.js +23 -81
  2. 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 ZodOut<T> = ZodType<T, ZodTypeDef, unknown>;
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: ZodOut<T> | undefined, errorSchema: ZodOut<T> | undefined) => Promise<void>;
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, ZodOut} from './intrig-context';
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?: ZodOut<T>;
7558
- errorSchema?: ZodOut<E>;
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?: ZodOut<T>;
7684
- errorSchema?: ZodOut<T>
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>(null);
7633
+ const controller = useRef<AbortController | undefined>(undefined);
7688
7634
 
7689
7635
  const call = useCallback(
7690
7636
  async (request: RequestType)=> {
@@ -8151,6 +8097,15 @@ async function reactDownloadHookTemplate({ source, data: { paths, operationId, r
8151
8097
  "...params"
8152
8098
  ].join(",");
8153
8099
  const finalRequestBodyBlock = requestBody ? `,data: encode(data, "${contentType}", requestBodySchema)` : '';
8100
+ function responseTypePart() {
8101
+ switch(responseType){
8102
+ case "application/octet-stream":
8103
+ return `responseType: 'blob', adapter: 'fetch',`;
8104
+ case "text/event-stream":
8105
+ return `responseType: 'stream', adapter: 'fetch',`;
8106
+ }
8107
+ return '';
8108
+ }
8154
8109
  return ts`
8155
8110
  ${[
8156
8111
  ...imports
@@ -8229,7 +8184,7 @@ async function reactDownloadHookTemplate({ source, data: { paths, operationId, r
8229
8184
  key: \`${"${source}: ${operation}"}\`,
8230
8185
  source: '${source}'
8231
8186
  ${requestBody ? finalRequestBodyBlock : ''},
8232
- ${responseType === "text/event-stream" ? `responseType: 'stream', adapter: 'fetch',` : ''}
8187
+ ${responseTypePart()}
8233
8188
  })
8234
8189
  return successfulDispatch();
8235
8190
  }, [dispatch])
@@ -9370,23 +9325,8 @@ function typeUtilsTemplate(_path) {
9370
9325
  const ts = typescript(external_path_default().resolve(_path, 'src', 'type-utils.ts'));
9371
9326
  return ts`import { z } from 'zod';
9372
9327
 
9373
- export type BinaryData = Blob | ArrayBuffer | Uint8Array;
9374
-
9375
- export const BinaryDataSchema = z.union([
9376
- // Blob in browsers
9377
- z.instanceof(Blob).optional(), // optional here so union below still validates if Blob is absent in Node
9378
- // Raw buffers
9379
- z.instanceof(ArrayBuffer),
9380
- z.custom<Uint8Array>((v) => v instanceof Uint8Array, { message: 'Expected Uint8Array' }),
9381
- ]).transform((v) => {
9382
- // Normalize to Blob if possible (nice for downloads in browser)
9383
- if (typeof Blob !== 'undefined') {
9384
- if (v instanceof Blob) return v;
9385
- if (v instanceof ArrayBuffer) return new Blob([v]);
9386
- if (v instanceof Uint8Array) return new Blob([v.buffer]);
9387
- }
9388
- return v;
9389
- });
9328
+ export type BinaryData = Blob;
9329
+ export const BinaryDataSchema: z.ZodType<BinaryData> = z.instanceof(Blob);
9390
9330
 
9391
9331
  // Base64 helpers (browser + Node compatible; no Buffer required)
9392
9332
  export function base64ToUint8Array(b64: string): Uint8Array {
@@ -13777,10 +13717,12 @@ const core_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("
13777
13717
 
13778
13718
 
13779
13719
 
13780
- const isVerbose = process.argv.includes('--verbose');
13781
13720
  const logger = new common_namespaceObject.Logger('Main');
13782
13721
  async function bootstrapDeamon() {
13783
13722
  const app = await core_namespaceObject.NestFactory.create(AppModule, {
13723
+ logger: [
13724
+ 'error'
13725
+ ]
13784
13726
  });
13785
13727
  app.enableShutdownHooks();
13786
13728
  app.enableCors();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intrig/core",
3
- "version": "0.0.15-3",
3
+ "version": "0.0.15-5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {