Skip to content

Commit 42467db

Browse files
committed
refactor(api): remove namespace exports and use unique identifiers for API methods
BREAKING CHANGE: All API methods are now exported as unique identifiers instead of namespace exports. This improves documentation compatibility and enables better tree-shaking.
1 parent 3476c26 commit 42467db

File tree

14 files changed

+45
-90
lines changed

14 files changed

+45
-90
lines changed

api.ts

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,5 @@
1-
export * as pages from "./api/pages.ts";
2-
export * as projects from "./api/projects.ts";
3-
export * as users from "./api/users.ts";
1+
export * from "./api/pages.ts";
2+
export * from "./api/projects.ts";
3+
export * from "./api/users.ts";
44
export type { HTTPError, TypedError } from "./error.ts";
55
export type { BaseOptions, ExtendedOptions, OAuthOptions } from "./util.ts";
6-
7-
export {
8-
get as listPages,
9-
list as listPagesStream,
10-
type ListPagesOption,
11-
type ListPagesStreamOption,
12-
makeGetRequest as makeListPagesRequest,
13-
} from "./api/pages/project.ts";
14-
export {
15-
makePostRequest as makeReplaceLinksRequest,
16-
post as replaceLinks,
17-
} from "./api/pages/project/replace/links.ts";
18-
export {
19-
get as searchForPages,
20-
makeGetRequest as makeSearchForPagesRequest,
21-
} from "./api/pages/project/search/query.ts";
22-
export {
23-
get as getLinks,
24-
type GetLinksOptions,
25-
list as readLinks,
26-
makeGetRequest as makeGetLinksRequest,
27-
} from "./api/pages/project/search/titles.ts";
28-
export {
29-
get as getPage,
30-
type GetPageOption,
31-
makeGetRequest as makeGetPageRequest,
32-
} from "./api/pages/project/title.ts";
33-
export {
34-
get as getText,
35-
type GetTextOption,
36-
makeGetRequest as makeGetTextRequest,
37-
} from "./api/pages/project/title/text.ts";
38-
export {
39-
get as getIcon,
40-
type GetIconOption,
41-
makeGetRequest as makeGetIconRequest,
42-
} from "./api/pages/project/title/icon.ts";
43-
export {
44-
get as getProject,
45-
makeGetRequest as makeGetProjectRequest,
46-
} from "./api/projects/project.ts";
47-
export {
48-
get as getUser,
49-
makeGetRequest as makeGetUserRequest,
50-
} from "./api/users/me.ts";

api/pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * as project from "./pages/project.ts";
1+
export * from "./pages/project.ts";

api/pages/project.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { pooledMap } from "@std/async/pool";
2121
import { range } from "@core/iterutil/range";
2222
import { flatten } from "@core/iterutil/async/flatten";
2323

24-
/** Options for {@linkcode get}
24+
/** Options for {@linkcode listPages}
2525
*
2626
* @experimental **UNSTABLE**: New API, yet to be vetted.
2727
*/
@@ -102,7 +102,7 @@ export const makeGetRequest = <R extends Response | undefined>(
102102
* - {@linkcode NotLoggedInError}: Authentication required
103103
* - {@linkcode NotMemberError}: User lacks access
104104
*/
105-
export const get = <R extends Response | undefined = Response>(
105+
export const listPages = <R extends Response | undefined = Response>(
106106
project: string,
107107
options?: ListPagesOption<R>,
108108
): Promise<
@@ -125,7 +125,7 @@ export const get = <R extends Response | undefined = Response>(
125125
>;
126126

127127
/**
128-
* Options for {@linkcode list}
128+
* Options for {@linkcode listPagesStream}
129129
*
130130
* @experimental **UNSTABLE**: New API, yet to be vetted.
131131
*/
@@ -147,7 +147,7 @@ export interface ListPagesStreamOption<R extends Response | undefined>
147147
* @param options Configuration options for pagination and sorting
148148
* @throws {HTTPError | TypedError<"NotLoggedInError" | "NotMemberError" | "NotFoundError">} If any requests in the pagination sequence fail
149149
*/
150-
export async function* list(
150+
export async function* listPagesStream(
151151
project: string,
152152
options?: ListPagesStreamOption<Response>,
153153
): AsyncGenerator<BasePage, void, unknown> {
@@ -156,7 +156,7 @@ export async function* list(
156156
skip: options?.skip ?? 0,
157157
limit: options?.limit ?? 100,
158158
};
159-
const response = await ensureResponse(await get(project, props));
159+
const response = await ensureResponse(await listPages(project, props));
160160
const list = await response.json();
161161
yield* list.pages;
162162

@@ -170,7 +170,7 @@ export async function* list(
170170
range(0, times - 1),
171171
async (i) => {
172172
const response = await ensureResponse(
173-
await get(project, { ...props, skip: skip + i * limit, limit }),
173+
await listPages(project, { ...props, skip: skip + i * limit, limit }),
174174
);
175175
const list = await response.json();
176176
return list.pages;
@@ -203,6 +203,6 @@ const ensureResponse = async (
203203
}
204204
};
205205

206-
export * as replace from "./project/replace.ts";
207-
export * as search from "./project/search.ts";
208-
export * as title from "./project/title.ts";
206+
export * from "./project/replace.ts";
207+
export * from "./project/search.ts";
208+
export * from "./project/title.ts";

api/pages/project/replace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * as links from "./replace/links.ts";
1+
export * from "./replace/links.ts";

api/pages/project/replace/links.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import type { ResponseOfEndpoint } from "../../../../targeted_response.ts";
77
import { type ExtendedOptions, setDefaults } from "../../../../util.ts";
88
import { cookie } from "../../../../rest/auth.ts";
9-
import { get } from "../../../users/me.ts";
9+
import { getUser } from "../../../users/me.ts";
1010

1111
/** Constructs a request for the `/api/pages/:project/replace/links` endpoint
1212
*
@@ -18,7 +18,7 @@ import { get } from "../../../users/me.ts";
1818
* @param init - Additional configuration options
1919
* @returns A {@linkcode Request} object for replacing links in `project`
2020
*/
21-
export const makePostRequest = <R extends Response | undefined>(
21+
export const makeReplaceLinksRequest = <R extends Response | undefined>(
2222
project: string,
2323
from: string,
2424
to: string,
@@ -55,7 +55,7 @@ export const makePostRequest = <R extends Response | undefined>(
5555
* - {@linkcode NotLoggedInError}: Authentication required
5656
* - {@linkcode NotMemberError}: User lacks access
5757
*/
58-
export const post = async <R extends Response | undefined = Response>(
58+
export const replaceLinks = async <R extends Response | undefined = Response>(
5959
project: string,
6060
from: string,
6161
to: string,
@@ -71,13 +71,13 @@ export const post = async <R extends Response | undefined = Response>(
7171
let { csrf, fetch, ...init2 } = setDefaults(init ?? {});
7272

7373
if (!csrf) {
74-
const res = await get(init2);
74+
const res = await getUser(init2);
7575
if (!res.ok) return res;
7676
csrf = (await res.json()).csrfToken;
7777
}
7878

7979
return fetch(
80-
makePostRequest(project, from, to, { csrf, ...init2 }),
80+
makeReplaceLinksRequest(project, from, to, { csrf, ...init2 }),
8181
) as Promise<
8282
ResponseOfEndpoint<{
8383
200: string;

api/pages/project/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * as query from "./search/query.ts";
2-
export * as titles from "./search/titles.ts";
1+
export * from "./search/query.ts";
2+
export * from "./search/titles.ts";

api/pages/project/search/query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { cookie } from "../../../../rest/auth.ts";
1717
* @param options - Additional configuration options
1818
* @returns A {@linkcode Request} object for fetching page data
1919
*/
20-
export const makeGetRequest = <R extends Response | undefined>(
20+
export const makeSearchForPagesRequest = <R extends Response | undefined>(
2121
project: string,
2222
query: string,
2323
options?: BaseOptions<R>,
@@ -41,7 +41,7 @@ export const makeGetRequest = <R extends Response | undefined>(
4141
* @param options Additional configuration options for the request
4242
* @returns A {@linkcode Response} object containing the search results
4343
*/
44-
export const get = <R extends Response | undefined = Response>(
44+
export const searchForPages = <R extends Response | undefined = Response>(
4545
project: string,
4646
query: string,
4747
options?: BaseOptions<R>,
@@ -55,7 +55,7 @@ export const get = <R extends Response | undefined = Response>(
5555
}, R>
5656
> =>
5757
setDefaults(options ?? {}).fetch(
58-
makeGetRequest(project, query, options),
58+
makeSearchForPagesRequest(project, query, options),
5959
) as Promise<
6060
ResponseOfEndpoint<{
6161
200: SearchResult;

api/pages/project/title.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface GetPageOption<R extends Response | undefined>
3232
* @param options - Additional configuration options
3333
* @returns A {@linkcode Request} object for fetching page data
3434
*/
35-
export const makeGetRequest = <R extends Response | undefined>(
35+
export const makeGetPageRequest = <R extends Response | undefined>(
3636
project: string,
3737
title: string,
3838
options?: GetPageOption<R>,
@@ -64,7 +64,7 @@ export const makeGetRequest = <R extends Response | undefined>(
6464
* - {@linkcode NotLoggedInError}: Authentication required
6565
* - {@linkcode NotMemberError}: User lacks access
6666
*/
67-
export const get = <R extends Response | undefined = Response>(
67+
export const getPage = <R extends Response | undefined = Response>(
6868
project: string,
6969
title: string,
7070
options?: GetPageOption<R>,
@@ -77,7 +77,7 @@ export const get = <R extends Response | undefined = Response>(
7777
}, R>
7878
> =>
7979
setDefaults(options ?? {}).fetch(
80-
makeGetRequest(project, title, options),
80+
makeGetPageRequest(project, title, options),
8181
) as Promise<
8282
ResponseOfEndpoint<{
8383
200: Page;
@@ -87,5 +87,5 @@ export const get = <R extends Response | undefined = Response>(
8787
}, R>
8888
>;
8989

90-
export * as text from "./title/text.ts";
91-
export * as icon from "./title/icon.ts";
90+
export * from "./title/text.ts";
91+
export * from "./title/icon.ts";

api/pages/project/title/icon.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { encodeTitleURI } from "../../../../title.ts";
99
import { cookie } from "../../../../rest/auth.ts";
1010

1111
/**
12-
* Options for {@linkcode get}
12+
* Options for {@linkcode getIcon}
1313
*
1414
* @experimental **UNSTABLE**: New API, yet to be vetted.
1515
*/
@@ -28,7 +28,7 @@ export interface GetIconOption<R extends Response | undefined>
2828
* @param options - Additional configuration options
2929
* @returns A {@linkcode Request} object for fetching page data
3030
*/
31-
export const makeGetRequest = <R extends Response | undefined>(
31+
export const makeGetIconRequest = <R extends Response | undefined>(
3232
project: string,
3333
title: string,
3434
options?: GetIconOption<R>,
@@ -52,7 +52,7 @@ export const makeGetRequest = <R extends Response | undefined>(
5252
* @param options Additional configuration options for the request
5353
* @returns A {@linkcode Response} object containing the page image
5454
*/
55-
export const get = <R extends Response | undefined = Response>(
55+
export const getIcon = <R extends Response | undefined = Response>(
5656
project: string,
5757
title: string,
5858
options?: GetIconOption<R>,
@@ -65,7 +65,7 @@ export const get = <R extends Response | undefined = Response>(
6565
}, R>
6666
> =>
6767
setDefaults(options ?? {}).fetch(
68-
makeGetRequest(project, title, options),
68+
makeGetIconRequest(project, title, options),
6969
) as Promise<
7070
ResponseOfEndpoint<{
7171
200: Blob;

api/pages/project/title/text.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { encodeTitleURI } from "../../../../title.ts";
99
import { cookie } from "../../../../rest/auth.ts";
1010

1111
/**
12-
* Options for {@linkcode get}
12+
* Options for {@linkcode getText}
1313
*
1414
* @experimental **UNSTABLE**: New API, yet to be vetted.
1515
*/
@@ -28,7 +28,7 @@ export interface GetTextOption<R extends Response | undefined>
2828
* @param options - Additional configuration options
2929
* @returns A {@linkcode Request} object for fetching page data
3030
*/
31-
export const makeGetRequest = <R extends Response | undefined>(
31+
export const makeGetTextRequest = <R extends Response | undefined>(
3232
project: string,
3333
title: string,
3434
options?: GetTextOption<R>,
@@ -52,7 +52,7 @@ export const makeGetRequest = <R extends Response | undefined>(
5252
* @param options Additional configuration options for the request
5353
* @returns A {@linkcode Response} object containing the page text
5454
*/
55-
export const get = <R extends Response | undefined = Response>(
55+
export const getText = <R extends Response | undefined = Response>(
5656
project: string,
5757
title: string,
5858
options?: GetTextOption<R>,
@@ -65,7 +65,7 @@ export const get = <R extends Response | undefined = Response>(
6565
}, R>
6666
> =>
6767
setDefaults(options ?? {}).fetch(
68-
makeGetRequest(project, title, options),
68+
makeGetTextRequest(project, title, options),
6969
) as Promise<
7070
ResponseOfEndpoint<{
7171
200: string;

0 commit comments

Comments
 (0)