Skip to content

Commit aa533ef

Browse files
committed
feat: discord-api-types on docs
1 parent b3db92e commit aa533ef

File tree

15 files changed

+93
-109
lines changed

15 files changed

+93
-109
lines changed

.github/workflows/documentation.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,9 @@ jobs:
105105
- name: Upload documentation to database
106106
if: ${{ env.REF_TYPE == 'tag' && (!inputs.ref || inputs.ref == 'main') }}
107107
env:
108-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
109108
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
110109
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
111110
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
112-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
113111
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
114112
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
115113
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -123,11 +121,9 @@ jobs:
123121
- name: Upload documentation to database
124122
if: ${{ env.REF_TYPE == 'tag' && inputs.ref && inputs.ref != 'main' }}
125123
env:
126-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
127124
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
128125
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
129126
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
130-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
131127
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
132128
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
133129
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -141,7 +137,6 @@ jobs:
141137
- name: Upload split documentation to blob storage
142138
if: ${{ env.REF_TYPE == 'tag' && (!inputs.ref || inputs.ref == 'main') }}
143139
env:
144-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
145140
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
146141
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
147142
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -154,7 +149,6 @@ jobs:
154149
- name: Upload split documentation to blob storage
155150
if: ${{ env.REF_TYPE == 'tag' && inputs.ref && inputs.ref != 'main' }}
156151
env:
157-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
158152
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
159153
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
160154
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -181,11 +175,9 @@ jobs:
181175
- name: Upload documentation to database
182176
if: ${{ env.REF_TYPE == 'branch' && (!inputs.ref || inputs.ref == 'main') }}
183177
env:
184-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
185178
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
186179
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
187180
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
188-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
189181
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
190182
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
191183
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -196,11 +188,9 @@ jobs:
196188
- name: Upload documentation to database
197189
if: ${{ env.REF_TYPE == 'branch' && inputs.ref && inputs.ref != 'main' }}
198190
env:
199-
DATABASE_URL: ${{ secrets.DATABASE_URL }}
200191
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
201192
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
202193
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
203-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
204194
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
205195
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
206196
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -211,7 +201,6 @@ jobs:
211201
- name: Upload split documentation to blob storage
212202
if: ${{ env.REF_TYPE == 'branch' && (!inputs.ref || inputs.ref == 'main') }}
213203
env:
214-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
215204
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
216205
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
217206
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
@@ -221,7 +210,6 @@ jobs:
221210
- name: Upload split documentation to blob storage
222211
if: ${{ env.REF_TYPE == 'branch' && inputs.ref && inputs.ref != 'main' }}
223212
env:
224-
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
225213
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
226214
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
227215
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}

apps/website/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@vercel/analytics": "^1.5.0",
5252
"@vercel/edge-config": "^1.4.0",
5353
"@vercel/postgres": "^0.10.0",
54+
"cloudflare": "^4.2.0",
5455
"cmdk": "^1.1.1",
5556
"cva": "1.0.0-beta.3",
5657
"geist": "^1.3.1",

apps/website/src/app/docs/packages/[packageName]/[version]/[[...item]]/opengraph-image.tsx.bak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default async function Image({
3131

3232
const isMain = version === 'main';
3333
const fileContent = await fetch(
34-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
34+
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.${normalizeItem}.api.json`,
3535
{ next: { revalidate: isMain ? 0 : 604_800 } },
3636
);
3737
const node = await fileContent.json();

apps/website/src/app/docs/packages/[packageName]/[version]/[[...item]]/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Metadata } from 'next';
77
import { MDXRemote } from 'next-mdx-remote-client/rsc';
88
import remarkGfm from 'remark-gfm';
99
import { DocItem } from '@/components/DocItem';
10+
import { PACKAGES_WITH_ENTRY_POINTS } from '@/util/constants';
1011
import { fetchNode } from '@/util/fetchNode';
1112
import { parseDocsPathParams } from '@/util/parseDocsPathParams';
1213
import { getSingletonHighlighter } from '@/util/shiki.bundle';
@@ -52,6 +53,12 @@ export default async function Page({
5253
const { entryPoints: parsedEntrypoints, foundItem } = parseDocsPathParams(item);
5354

5455
if (!foundItem) {
56+
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
57+
58+
if (hasEntryPoint) {
59+
return <>Placeholder</>;
60+
}
61+
5562
const fileContent = await readFile(join(process.cwd(), `src/assets/readme/${packageName}/home-README.md`), 'utf8');
5663

5764
return (

apps/website/src/middleware.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import { sql } from '@vercel/postgres';
1+
import Cloudflare from 'cloudflare';
22
import { NextResponse, type NextRequest } from 'next/server';
33
import { PACKAGES } from './util/constants';
44
import { ENV } from './util/env';
55

6+
const client = new Cloudflare({
7+
apiToken: process.env.CF_D1_DOCS_API_KEY,
8+
});
9+
610
async function fetchLatestVersion(packageName: string): Promise<string> {
711
if (ENV.IS_LOCAL_DEV) {
812
return 'main';
913
}
1014

1115
try {
12-
const { rows } = await sql<{ version: string }>`with ordered_versions as (
13-
select version from documentation where name = ${packageName} and version != 'main' order by string_to_array(version, '.')::int[] desc
14-
)
15-
select version from ordered_versions limit 1`;
16+
const { result } = await client.d1.database.query(process.env.CF_D1_DOCS_ID!, {
17+
account_id: process.env.CF_ACCOUNT_ID!,
18+
sql: `select version from documentation where name = ? and version != 'main' order by version desc limit 1;`,
19+
params: [packageName],
20+
});
1621

17-
return rows[0]?.version ?? 'main';
22+
return (result[0]?.results as { version: string }[] | undefined)?.[0]?.version ?? 'main';
1823
} catch {
1924
return '';
2025
}

apps/website/src/util/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const PACKAGES = [
22
{ name: 'discord.js' },
3+
{ name: 'discord-api-types' },
34
{ name: 'brokers' },
45
{ name: 'builders' },
56
{ name: 'collection' },
@@ -11,7 +12,6 @@ export const PACKAGES = [
1112
{ name: 'util' },
1213
{ name: 'voice' },
1314
{ name: 'ws' },
14-
// { name: 'discord-api-types' },
1515
];
1616

1717
export const PACKAGES_WITH_ENTRY_POINTS = ['discord-api-types'];

apps/website/src/util/fetchDependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function fetchDependencies({
2929
try {
3030
const isMain = version === 'main';
3131
const fileContent = await fetch(
32-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.dependencies.api.json`,
32+
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.dependencies.api.json`,
3333
{ next: { revalidate: isMain ? 0 : 604_800 } },
3434
);
3535
const parsedDependencies = await fileContent.json();
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3-
// import { sql } from '@vercel/postgres';
3+
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
44
import { ENV } from './env';
55

66
export async function fetchEntryPoints(packageName: string, version: string) {
7+
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
8+
9+
if (!hasEntryPoint) {
10+
return [];
11+
}
12+
713
if (ENV.IS_LOCAL_DEV) {
814
const fileContent = await readFile(
9-
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.entrypoints.api.json`),
15+
join(
16+
process.cwd(),
17+
`${hasEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.entrypoints.api.json`,
18+
),
1019
'utf8',
1120
);
1221

1322
return JSON.parse(fileContent);
1423
}
1524

16-
// try {
17-
// const { rows } = await sql<{
18-
// entryPoint: string;
19-
// }>`select entryPoint from documentation where name = ${packageName} and version = ${version} order by
20-
// case
21-
// when version = 'main' then 0
22-
// else 1
23-
// end,
24-
// case
25-
// when version = 'main' then null
26-
// else string_to_array(version, '.')::int[]
27-
// end desc;
28-
// `;
25+
const isMain = version === 'main';
26+
const fileContent = await fetch(
27+
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.entrypoints.api.json`,
28+
{ next: { revalidate: isMain ? 0 : 604_800 } },
29+
);
30+
31+
if (!fileContent.ok) {
32+
return null;
33+
}
2934

30-
// return rows;
31-
// } catch {
32-
return [];
33-
// }
35+
return fileContent.json();
3436
}

apps/website/src/util/fetchNode.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3+
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
34
import { ENV } from './env';
45

56
export async function fetchNode({
@@ -13,14 +14,15 @@ export async function fetchNode({
1314
readonly packageName: string;
1415
readonly version: string;
1516
}) {
17+
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
1618
const normalizedEntryPoint = entryPoint ? `${entryPoint}.` : '';
1719
const normalizeItem = item.replaceAll(':', '.').toLowerCase();
1820

1921
if (ENV.IS_LOCAL_DEV) {
2022
const fileContent = await readFile(
2123
join(
2224
process.cwd(),
23-
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
25+
`${hasEntryPoint || normalizedEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
2426
),
2527
'utf8',
2628
);
@@ -30,7 +32,7 @@ export async function fetchNode({
3032

3133
const isMain = version === 'main';
3234
const fileContent = await fetch(
33-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
35+
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.${normalizedEntryPoint}${normalizeItem}.api.json`,
3436
{ next: { revalidate: isMain ? 0 : 604_800 } },
3537
);
3638

apps/website/src/util/fetchSitemap.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFile } from 'node:fs/promises';
22
import { join } from 'node:path';
3+
import { PACKAGES_WITH_ENTRY_POINTS } from './constants';
34
import { ENV } from './env';
45

56
export async function fetchSitemap({
@@ -11,13 +12,14 @@ export async function fetchSitemap({
1112
readonly packageName: string;
1213
readonly version: string;
1314
}) {
15+
const hasEntryPoint = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
1416
const normalizedEntryPoint = entryPoint ? `${entryPoint}.` : '';
1517

1618
if (ENV.IS_LOCAL_DEV) {
1719
const fileContent = await readFile(
1820
join(
1921
process.cwd(),
20-
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizedEntryPoint}sitemap.api.json`,
22+
`${hasEntryPoint || normalizedEntryPoint ? `../../../discord-api-types` : `../../packages/${packageName}`}/docs/${packageName}/split/${version}.${normalizedEntryPoint}sitemap.api.json`,
2123
),
2224
'utf8',
2325
);
@@ -27,7 +29,7 @@ export async function fetchSitemap({
2729

2830
const isMain = version === 'main';
2931
const fileContent = await fetch(
30-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizedEntryPoint}sitemap.api.json`,
32+
`${process.env.CF_R2_DOCS_BUCKET_URL}/${packageName}/${version}.${normalizedEntryPoint}sitemap.api.json`,
3133
{
3234
next: { revalidate: isMain ? 0 : 604_800 },
3335
},

0 commit comments

Comments
 (0)