@ryneex/api-client 1.0.0-beta.2 → 1.0.0-beta.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.
Files changed (3) hide show
  1. package/index.d.ts +8 -5
  2. package/index.js +3 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -9,14 +9,14 @@ type ClientPayload<TInput, TVariables> = {} & (unknown extends TInput ? unknown
9
9
  variables: TVariables;
10
10
  });
11
11
  type OptionalPayload<T> = object extends T ? void : T;
12
- type ClientOptions<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.infer<TOutputSchema>, TInput = z.infer<TInputSchema>, TVariables = z.infer<TVariablesSchema>> = {
12
+ type ClientOptions<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.output<TOutputSchema>, TInput = z.input<TInputSchema>, TVariables = z.input<TVariablesSchema>> = {
13
13
  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
14
14
  path: string | ((payload: ClientPayload<TInput, TVariables>) => string);
15
15
  axiosOptions?: (payload: ClientPayload<TInput, TVariables>) => AxiosRequestConfig;
16
16
  variablesSchema?: TVariablesSchema;
17
17
  inputSchema?: TInputSchema;
18
18
  outputSchema: TOutputSchema;
19
- transform?: (data: z.infer<TOutputSchema>, payload: ClientPayload<TInput, TVariables>) => TOutput;
19
+ transform?: (data: z.output<TOutputSchema>, payload: ClientPayload<TInput, TVariables>) => TOutput;
20
20
  };
21
21
 
22
22
  type ReactQueryOptions<TOutput, TInput, TVariables> = Omit<UseQueryOptions<TOutput, ClientError>, "queryFn" | "queryKey"> & {
@@ -42,9 +42,12 @@ type Err<E> = {
42
42
  type Result<T, E> = Ok<T> | Err<E>;
43
43
 
44
44
  declare function createClient(axios: AxiosInstance): {
45
- create: <TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.core.output<TOutputSchema>, TInput = z.core.output<TInputSchema>, TVariables = z.core.output<TVariablesSchema>>(opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables>) => ((_payload: OptionalPayload<ClientPayload<TInput, TVariables>>) => Promise<Result<TOutput, ClientError>>) & {
45
+ create: <TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.core.output<TOutputSchema>, TInput = z.core.input<TInputSchema>, TVariables = z.core.input<TVariablesSchema>>(opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables>) => ((_payload: OptionalPayload<ClientPayload<TInput, TVariables>>) => Promise<Result<TOutput, ClientError>>) & {
46
+ call: (_payload: OptionalPayload<ClientPayload<TInput, TVariables>>) => Promise<Result<TOutput, ClientError>>;
46
47
  queryOptions: (_opts: object extends ClientPayload<TInput, TVariables> ? ReactQueryOptions<TOutput, TInput, TVariables> | void : ReactQueryOptions<TOutput, TInput, TVariables>) => UseQueryOptions<TOutput, ClientError>;
47
48
  mutationOptions: (_opts: ReactMutationOptions<TOutput, TInput, TVariables> | void) => UseMutationOptions<TOutput, ClientError, object extends ClientPayload<TInput, TVariables> ? void : ClientPayload<TInput, TVariables>>;
49
+ queryKey: (data?: ClientPayload<TInput, TVariables>) => (string | ClientPayload<TInput, TVariables>)[];
50
+ mutationKey: () => string[];
48
51
  config: {
49
52
  inputSchema: undefined extends TInputSchema ? undefined : NonNullable<TInputSchema>;
50
53
  variablesSchema: undefined extends TVariablesSchema ? undefined : NonNullable<TVariablesSchema>;
@@ -58,10 +61,10 @@ declare function createClient(axios: AxiosInstance): {
58
61
  };
59
62
  };
60
63
 
61
- declare function callApi<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.infer<TOutputSchema>, TInput = z.infer<TInputSchema>, TVariables = z.infer<TVariablesSchema>>(opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables> & {
64
+ declare function callApi<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.output<TOutputSchema>, TInput = z.input<TInputSchema>, TVariables = z.input<TVariablesSchema>>(opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables> & {
62
65
  axios: AxiosInstance;
63
66
  }, data: ClientPayload<TInput, TVariables>): Promise<Result<TOutput, ClientError>>;
64
- declare function getResponse<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.infer<TOutputSchema>, TInput = z.infer<TInputSchema>, TVariables = z.infer<TVariablesSchema>>(request: Promise<AxiosResponse<TOutput>>, opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables>, payload: ClientPayload<TInput, TVariables>): Promise<Result<TOutput, ClientError>>;
67
+ declare function getResponse<TOutputSchema extends z.ZodType, TInputSchema extends z.ZodType, TVariablesSchema extends z.ZodType, TOutput = z.output<TOutputSchema>, TInput = z.input<TInputSchema>, TVariables = z.input<TVariablesSchema>>(request: Promise<AxiosResponse<TOutput>>, opts: ClientOptions<TOutputSchema, TInputSchema, TVariablesSchema, TOutput, TInput, TVariables>, payload: ClientPayload<TInput, TVariables>): Promise<Result<TOutput, ClientError>>;
65
68
 
66
69
  declare const VALIDATION_ERROR_NAMES: {
67
70
  readonly INPUT: "InputValidationError";
package/index.js CHANGED
@@ -42,8 +42,11 @@ function createClient(axios) {
42
42
  };
43
43
  };
44
44
  return Object.assign(call, {
45
+ call,
45
46
  queryOptions,
46
47
  mutationOptions,
48
+ queryKey,
49
+ mutationKey,
47
50
  config: {
48
51
  ...apiOptionas,
49
52
  inputSchema: opts.inputSchema,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ryneex/api-client",
3
3
  "module": "src/index.ts",
4
4
  "type": "module",
5
- "version": "1.0.0-beta.2",
5
+ "version": "1.0.0-beta.3",
6
6
  "exports": {
7
7
  ".": "./index.js"
8
8
  },