Skip to content

Commit 75163e4

Browse files
committed
refactor(types): rename InferredPluginOptions to InferredExtraOptions for consistency
docs: update plugin and client type references in documentation fix: downgrade prettier to 3.6.2 due to compatibility issues style: reorganize imports in layout.shared.tsx
1 parent fac5753 commit 75163e4

File tree

12 files changed

+144
-115
lines changed

12 files changed

+144
-115
lines changed

.changeset/sparkly-dolls-end.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@zayne-labs/callapi": patch
3+
---
4+
5+
refactor(types): rename InferredPluginOptions to InferredExtraOptions for consistency
6+
7+
docs: update plugin and client type references in documentation
8+
fix: downgrade prettier to 3.6.2 due to compatibility issues
9+
style: reorganize imports in layout.shared.tsx

apps/dev/src/caching-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const cachingPlugin = (cacheConfig: CacheConfig) => {
6666
// eslint-disable-next-line perfectionist/sort-objects -- Ignore
6767
defineExtraOptions: () => CacheConfigSchema,
6868

69-
middlewares: ({ options }: PluginSetupContext<{ InferredPluginOptions: CacheConfig }>) => {
69+
middlewares: ({ options }: PluginSetupContext<{ InferredExtraOptions: CacheConfig }>) => {
7070
const { cacheLifetime = initCacheLifeTime, cachePolicy = initCachePolicy } = options;
7171

7272
return {

apps/dev/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ const pluginTwo = definePlugin({
5050
onSuccess: (_ctx: SuccessContext<{ Data: { foo: string } }>) => console.info("OnSuccess - PLUGIN2"),
5151
} satisfies PluginHooks<{
5252
ErrorData: { foo: string };
53-
InferredPluginOptions: Plugin2Options;
53+
InferredExtraOptions: Plugin2Options;
5454
}>,
5555

5656
id: "2",
5757

5858
name: "plugin",
5959

60-
setup: ({ options, request }: PluginSetupContext<{ InferredPluginOptions: Plugin2Options }>) => {
60+
setup: ({ options, request }: PluginSetupContext<{ InferredExtraOptions: Plugin2Options }>) => {
6161
options.onUploadSuccess?.({ load: 0, tots: 0 });
6262

6363
return {

apps/docs/app/docs/[[...slug]]/page.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import { getMDXComponents } from "@/components/common";
33
import { owner, repo } from "@/lib/github";
44
import { createMetadata } from "@/lib/metadata";
55
import { source } from "@/lib/source";
6+
import {
7+
DocsBody,
8+
DocsDescription,
9+
DocsPage,
10+
DocsTitle,
11+
PageLastUpdate,
12+
} from "fumadocs-ui/layouts/notebook/page";
613
import { createRelativeLink } from "fumadocs-ui/mdx";
7-
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from "fumadocs-ui/page";
14+
import { LucideEdit } from "lucide-react";
815
import type { Metadata } from "next";
916
import { notFound } from "next/navigation";
1017

@@ -21,19 +28,15 @@ async function Page({ params }: PageProps<"/docs/[[...slug]]">) {
2128

2229
const MDX = page.data.body;
2330

31+
const lastModified = page.data.lastModified;
32+
2433
return (
2534
<DocsPage
2635
toc={page.data.toc}
2736
tableOfContent={{
2837
single: false,
2938
style: "clerk",
3039
}}
31-
editOnGithub={{
32-
owner: "zayne-labs",
33-
path: `apps/docs/content/docs/${page.path}`,
34-
repo: "callapi",
35-
sha: "main",
36-
}}
3740
full={page.data.full}
3841
>
3942
<DocsTitle>{page.data.title}</DocsTitle>
@@ -48,6 +51,20 @@ async function Page({ params }: PageProps<"/docs/[[...slug]]">) {
4851
</div>
4952
<MDX components={getMDXComponents({ a: createRelativeLink(source, page) })} />
5053
</DocsBody>
54+
55+
<a
56+
href={`https://github.com/zayne-labs/callapi/blob/main/content/docs/${page.path}`}
57+
rel="noreferrer noopener"
58+
target="_blank"
59+
className="inline-flex w-fit items-center justify-center gap-1.5 rounded-md border
60+
bg-fd-secondary p-2 text-sm font-medium text-fd-secondary-foreground transition-colors
61+
hover:bg-fd-accent hover:text-fd-accent-foreground"
62+
>
63+
<LucideEdit className="size-3.5" />
64+
Edit on GitHub
65+
</a>
66+
67+
{lastModified && <PageLastUpdate date={lastModified} />}
5168
</DocsPage>
5269
);
5370
}

apps/docs/content/docs/hooks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ type User = {
217217

218218
const userCache = new Map<string, User>();
219219

220-
const client = createFetchClient<User[]>({
220+
const client = createFetchClient<{ Data: User[] }>({
221221
onSuccess: ({ data, response, request, options }) => {
222222
// Cache user data
223223
data.forEach((user) => userCache.set(user.id, user));
@@ -515,7 +515,7 @@ type User = {
515515
name: string;
516516
};
517517

518-
const client = createFetchClient<User>({
518+
const client = createFetchClient<{ Data: User }>({
519519
onSuccess: ({ data }) => {
520520
console.log(data.name);
521521
},

apps/docs/content/docs/plugins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const apiVersionPlugin = definePlugin({
180180

181181
defineExtraOptions: () => apiVersionSchema,
182182

183-
setup: (ctx: PluginSetupContext<z.infer<typeof apiVersionSchema>>) => {
183+
setup: (ctx: PluginSetupContext<{ InferredExtraOptions: z.infer<typeof apiVersionSchema> }>) => {
184184
const version = ctx.options.apiVersion ?? "v1";
185185

186186
return {

apps/docs/lib/layout.shared.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { source } from "@/lib/source";
22
import { callApi } from "@zayne-labs/callapi";
33
import { GithubInfo } from "fumadocs-ui/components/github-info";
4-
import type { DocsLayoutProps, LinkItemType } from "fumadocs-ui/layouts/docs";
5-
import type { BaseLayoutProps } from "fumadocs-ui/layouts/shared";
4+
import type { DocsLayoutProps } from "fumadocs-ui/layouts/docs";
5+
import type { BaseLayoutProps, LinkItemType } from "fumadocs-ui/layouts/shared";
66
import { TagIcon } from "lucide-react";
77
import Image from "next/image";
88
import logoImage from "public/logo.png";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"eslint-plugin-react-you-might-not-need-an-effect": "^0.7.0",
5858
"husky": "9.1.7",
5959
"lint-staged": "16.2.7",
60-
"prettier": "3.7.2",
60+
"prettier": "3.6.2",
6161
"tailwindcss": "^4.1.17",
6262
"turbo": "^2.6.1",
6363
"typescript": "^5.9.3"

packages/callapi/src/hooks.ts

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
CallApiRequestOptionsForHooks,
1818
} from "./types/common";
1919
import type { DefaultCallApiContext } from "./types/default-types";
20-
import type { AnyFunction, Awaitable, Prettify, UnmaskType } from "./types/type-helpers";
20+
import type { AnyFunction, Awaitable, Prettify } from "./types/type-helpers";
2121

2222
export interface Hooks<TCallApiContext extends CallApiContext = DefaultCallApiContext> {
2323
/**
@@ -176,7 +176,7 @@ export interface HookConfigOptions {
176176
}
177177

178178
export type RequestContext<
179-
TCallApiContext extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext,
179+
TCallApiContext extends Pick<CallApiContext, "InferredExtraOptions" | "Meta"> = DefaultCallApiContext,
180180
> = {
181181
/**
182182
* Base configuration object passed to createFetchClient.
@@ -214,98 +214,92 @@ export type RequestContext<
214214
};
215215

216216
export type ValidationErrorContext<
217-
TCallApiContext extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext,
218-
> = UnmaskType<
219-
RequestContext<TCallApiContext> & {
220-
error: PossibleValidationError;
221-
response: Response | null;
222-
}
223-
>;
217+
TCallApiContext extends Pick<CallApiContext, "InferredExtraOptions" | "Meta"> = DefaultCallApiContext,
218+
> = RequestContext<TCallApiContext> & {
219+
error: PossibleValidationError;
220+
response: Response | null;
221+
};
224222

225223
export type SuccessContext<
226-
TCallApiContext extends Pick<CallApiContext, "Data" | "InferredPluginOptions" | "Meta"> =
227-
DefaultCallApiContext,
228-
> = UnmaskType<
229-
RequestContext<TCallApiContext> & {
230-
data: NoInfer<TCallApiContext["Data"]>;
231-
response: Response;
232-
}
233-
>;
224+
TCallApiContext extends Pick<
225+
CallApiContext,
226+
"Data" | "InferredExtraOptions" | "Meta"
227+
> = DefaultCallApiContext,
228+
> = RequestContext<TCallApiContext> & {
229+
data: NoInfer<TCallApiContext["Data"]>;
230+
response: Response;
231+
};
234232

235233
export type ResponseContext<
236-
TCallApiContext extends Pick<CallApiContext, "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"> =
237-
DefaultCallApiContext,
238-
> = UnmaskType<
239-
RequestContext<TCallApiContext>
240-
& (
241-
| Prettify<CallApiResultSuccessVariant<TCallApiContext["Data"]>>
242-
| Prettify<
243-
Extract<
244-
CallApiResultErrorVariant<TCallApiContext["ErrorData"]>,
245-
{ error: PossibleHTTPError<TCallApiContext["ErrorData"]> }
246-
>
247-
>
248-
)
249-
>;
234+
TCallApiContext extends Pick<
235+
CallApiContext,
236+
"Data" | "ErrorData" | "InferredExtraOptions" | "Meta"
237+
> = DefaultCallApiContext,
238+
> = RequestContext<TCallApiContext>
239+
& (
240+
| Prettify<CallApiResultSuccessVariant<TCallApiContext["Data"]>>
241+
| Prettify<
242+
Extract<
243+
CallApiResultErrorVariant<TCallApiContext["ErrorData"]>,
244+
{ error: PossibleHTTPError<TCallApiContext["ErrorData"]> }
245+
>
246+
>
247+
);
250248

251249
export type RequestErrorContext<
252-
TCallApiContext extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext,
250+
TCallApiContext extends Pick<CallApiContext, "InferredExtraOptions" | "Meta"> = DefaultCallApiContext,
253251
> = RequestContext<TCallApiContext> & {
254252
error: PossibleJavaScriptError;
255253
response: null;
256254
};
257255

258256
export type ErrorContext<
259-
TCallApiContext extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> =
260-
DefaultCallApiContext,
261-
> = UnmaskType<
262-
RequestContext<TCallApiContext>
263-
& (
264-
| {
265-
error: PossibleHTTPError<TCallApiContext["ErrorData"]>;
266-
response: Response;
267-
}
268-
| {
269-
error: PossibleJavaScriptOrValidationError;
270-
response: Response | null;
271-
}
272-
)
273-
>;
257+
TCallApiContext extends Pick<
258+
CallApiContext,
259+
"ErrorData" | "InferredExtraOptions" | "Meta"
260+
> = DefaultCallApiContext,
261+
> = RequestContext<TCallApiContext>
262+
& (
263+
| {
264+
error: PossibleHTTPError<TCallApiContext["ErrorData"]>;
265+
response: Response;
266+
}
267+
| {
268+
error: PossibleJavaScriptOrValidationError;
269+
response: Response | null;
270+
}
271+
);
274272

275273
export type ResponseErrorContext<
276-
TCallApiContext extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> =
277-
DefaultCallApiContext,
278-
> = UnmaskType<
279-
Extract<ErrorContext<TCallApiContext>, { error: PossibleHTTPError<TCallApiContext["ErrorData"]> }>
280-
& RequestContext<TCallApiContext>
281-
>;
274+
TCallApiContext extends Pick<
275+
CallApiContext,
276+
"ErrorData" | "InferredExtraOptions" | "Meta"
277+
> = DefaultCallApiContext,
278+
> = Extract<ErrorContext<TCallApiContext>, { error: PossibleHTTPError<TCallApiContext["ErrorData"]> }>
279+
& RequestContext<TCallApiContext>;
282280

283281
export type RetryContext<
284-
TCallApiContext extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> =
285-
DefaultCallApiContext,
286-
> = UnmaskType<
287-
ErrorContext<TCallApiContext> & {
288-
retryAttemptCount: number;
289-
}
290-
>;
282+
TCallApiContext extends Pick<
283+
CallApiContext,
284+
"ErrorData" | "InferredExtraOptions" | "Meta"
285+
> = DefaultCallApiContext,
286+
> = ErrorContext<TCallApiContext> & {
287+
retryAttemptCount: number;
288+
};
291289

292290
export type RequestStreamContext<
293-
TCallApiContext extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext,
294-
> = UnmaskType<
295-
RequestContext<TCallApiContext> & {
296-
event: StreamProgressEvent;
297-
requestInstance: Request;
298-
}
299-
>;
291+
TCallApiContext extends Pick<CallApiContext, "InferredExtraOptions" | "Meta"> = DefaultCallApiContext,
292+
> = RequestContext<TCallApiContext> & {
293+
event: StreamProgressEvent;
294+
requestInstance: Request;
295+
};
300296

301297
export type ResponseStreamContext<
302-
TCallApiContext extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext,
303-
> = UnmaskType<
304-
RequestContext<TCallApiContext> & {
305-
event: StreamProgressEvent;
306-
response: Response;
307-
}
308-
>;
298+
TCallApiContext extends Pick<CallApiContext, "InferredExtraOptions" | "Meta"> = DefaultCallApiContext,
299+
> = RequestContext<TCallApiContext> & {
300+
event: StreamProgressEvent;
301+
response: Response;
302+
};
309303

310304
type HookRegistries = Required<{
311305
[Key in keyof Hooks]: Set<Hooks[Key]>;

packages/callapi/src/types/common.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
GetCurrentRouteSchema,
2020
HeadersOption,
2121
InferExtraOptions,
22-
InferPluginOptions,
22+
InferPluginExtraOptions,
2323
InferRequestOptions,
2424
MethodUnion,
2525
ResultModeOption,
@@ -47,7 +47,7 @@ export type GlobalMeta =
4747
export type CallApiContext = {
4848
Data?: DefaultDataType;
4949
ErrorData?: DefaultDataType;
50-
InferredPluginOptions?: unknown;
50+
InferredExtraOptions?: unknown;
5151
Meta?: DefaultMetaObject;
5252
ResultMode?: ResultModeType;
5353
};
@@ -92,18 +92,18 @@ type SharedExtraOptions<
9292
TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,
9393
TResponseType extends ResponseTypeType = ResponseTypeType,
9494
TPluginArray extends CallApiPlugin[] = DefaultPluginArray,
95-
TComputedMergedPluginOptions = Partial<
96-
InferPluginOptions<TPluginArray> & TCallApiContext["InferredPluginOptions"]
95+
TComputedMergedPluginExtraOptions = Partial<
96+
InferPluginExtraOptions<TPluginArray> & TCallApiContext["InferredExtraOptions"]
9797
>,
9898
> = DedupeOptions
9999
& HookConfigOptions
100100
& HooksOrHooksArray<
101-
GetMergedCallApiContext<TCallApiContext, { InferredPluginOptions: TComputedMergedPluginOptions }>
101+
GetMergedCallApiContext<TCallApiContext, { InferredExtraOptions: TComputedMergedPluginExtraOptions }>
102102
>
103103
& Middlewares
104104
& ResultModeOption<TErrorData, TResultMode>
105105
& RetryOptions<TErrorData>
106-
& TComputedMergedPluginOptions
106+
& TComputedMergedPluginExtraOptions
107107
& ThrowOnErrorOption<TErrorData, TThrowOnError>
108108
& URLOptions & {
109109
/**

0 commit comments

Comments
 (0)