@vladimirdev635/gql-client-react 0.0.45 → 0.0.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladimirdev635/gql-client-react",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
package/tests/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { OperationResult } from '@/types.js';
1
2
  import { z } from 'zod/v4';
2
3
  export declare const testOperation: {
3
4
  readonly document: "";
@@ -6,7 +7,7 @@ export declare const testOperation: {
6
7
  readonly variablesSchema: z.ZodObject<{}, z.core.$strip>;
7
8
  readonly resultSchema: z.ZodObject<{}, z.core.$strip>;
8
9
  };
9
- export type TestOperationResult = z.infer<(typeof testOperation)['resultSchema']>;
10
+ export type TestOperationResult = OperationResult<typeof testOperation>;
10
11
  export declare const testSubscription: {
11
12
  readonly document: "";
12
13
  readonly name: "";
@@ -16,5 +17,4 @@ export declare const testSubscription: {
16
17
  number: z.ZodNumber;
17
18
  }, z.core.$strip>;
18
19
  };
19
- export type TestSubscriptionResult = z.infer<(typeof testSubscription)['resultSchema']>;
20
- export declare function asyncTimeout(timeoutMS: number): Promise<void>;
20
+ export type TestSubscriptionResult = OperationResult<typeof testSubscription>;
package/tests/utils.js CHANGED
@@ -13,6 +13,3 @@ export const testSubscription = {
13
13
  variablesSchema: z.object({}),
14
14
  resultSchema: z.object({ number: z.number() })
15
15
  };
16
- export async function asyncTimeout(timeoutMS) {
17
- return await new Promise(resolve => setTimeout(resolve, timeoutMS));
18
- }
package/types.d.ts CHANGED
@@ -1,33 +1,33 @@
1
1
  import { z } from 'zod/v4';
2
- export interface SyncOperation {
2
+ export type SchemaFor<T> = z.ZodType<T>;
3
+ interface BaseOperation<V, R> {
3
4
  name: string;
4
5
  document: string;
6
+ variablesSchema: SchemaFor<V>;
7
+ resultSchema: SchemaFor<R>;
8
+ }
9
+ export interface SyncOperation<V, R> extends BaseOperation<V, R> {
5
10
  type: 'QUERY' | 'MUTATION';
6
- variablesSchema: z.ZodType;
7
- resultSchema: z.ZodType;
8
11
  }
9
- export interface SubscriptionOperation {
10
- name: string;
11
- document: string;
12
+ export interface SubscriptionOperation<V, R> extends BaseOperation<V, R> {
12
13
  type: 'SUBSCRIPTION';
13
- variablesSchema: z.ZodType;
14
- resultSchema: z.ZodType;
15
14
  }
16
- export type Operation = SyncOperation | SubscriptionOperation;
15
+ export type Operation<V, R> = SyncOperation<V, R> | SubscriptionOperation<V, R>;
16
+ export interface RequestContext {
17
+ fetchOptions?: RequestInit;
18
+ }
19
+ export type OperationVariables<T extends Operation<unknown, unknown>> = T extends Operation<infer V, unknown> ? V : never;
20
+ export type OperationResult<T extends Operation<unknown, unknown>> = T extends Operation<unknown, infer R> ? R : never;
17
21
  export interface ExecuteResult<TResult> {
18
22
  result: TResult;
19
23
  response: Response;
20
24
  }
21
- export type OperationResult<T extends Operation> = z.infer<T['resultSchema']>;
22
- export type OperationVariables<T extends Operation> = z.infer<T['variablesSchema']>;
23
25
  export type SubOpAsyncIterable<TResult> = {
24
26
  stream: AsyncIterable<TResult, void, unknown>;
25
27
  close: () => void;
26
28
  };
27
- export interface RequestContext {
28
- fetchOptions?: RequestInit;
29
- }
30
29
  export type Executor<TRequestContext extends RequestContext> = {
31
- <TSyncOp extends SyncOperation>(operation: TSyncOp, variables: OperationVariables<TSyncOp>, context: TRequestContext): Promise<ExecuteResult<OperationResult<TSyncOp>>>;
32
- <TOperation extends SubscriptionOperation>(operation: TOperation, variables: OperationVariables<TOperation>, context: TRequestContext): Promise<ExecuteResult<SubOpAsyncIterable<OperationResult<TOperation>>>>;
30
+ <TSyncOp extends SyncOperation<unknown, unknown>>(operation: TSyncOp, variables: OperationVariables<TSyncOp>, context: TRequestContext): Promise<ExecuteResult<OperationResult<TSyncOp>>>;
31
+ <TOperation extends SubscriptionOperation<unknown, unknown>>(operation: TOperation, variables: OperationVariables<TOperation>, context: TRequestContext): Promise<ExecuteResult<SubOpAsyncIterable<OperationResult<TOperation>>>>;
33
32
  };
33
+ export {};
@@ -13,5 +13,5 @@ export interface UseLazyOperationReturnType<TVariables, TResult, TRequestContext
13
13
  state: LazyOperationState<TResult>;
14
14
  reset: () => void;
15
15
  }
16
- export declare function useLazyOperation<T extends SyncOperation, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T): UseLazyOperationReturnType<OperationVariables<T>, OperationResult<T>, TRequestContext>;
16
+ export declare function useLazyOperation<T extends SyncOperation<unknown, unknown>, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T): UseLazyOperationReturnType<OperationVariables<T>, OperationResult<T>, TRequestContext>;
17
17
  export {};
package/useOperation.d.ts CHANGED
@@ -13,4 +13,4 @@ export type OperationState<TResult> = OperationLoadingState | OperationSuccessSt
13
13
  export declare const loadingState: Readonly<{
14
14
  readonly state: "loading";
15
15
  }>;
16
- export declare function useOperation<T extends SyncOperation, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T, variables: OperationVariables<T>, requestContext: TRequestContext): OperationState<OperationResult<T>>;
16
+ export declare function useOperation<T extends SyncOperation<unknown, unknown>, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T, variables: OperationVariables<T>, requestContext: TRequestContext): OperationState<OperationResult<T>>;
@@ -1,3 +1,3 @@
1
1
  import type { Executor, OperationResult, OperationVariables, RequestContext, SubOpAsyncIterable, SubscriptionOperation } from './types.js';
2
2
  import { type OperationState } from './useOperation.jsx';
3
- export declare function useSubscription<T extends SubscriptionOperation, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T, variables: OperationVariables<T>, requestContext: TRequestContext): OperationState<SubOpAsyncIterable<OperationResult<T>>>;
3
+ export declare function useSubscription<T extends SubscriptionOperation<unknown, unknown>, TRequestContext extends RequestContext>(executor: Executor<TRequestContext>, operation: T, variables: OperationVariables<T>, requestContext: TRequestContext): OperationState<SubOpAsyncIterable<OperationResult<T>>>;