Skip to content

Commit cb91644

Browse files
committed
Add Algolia search script
1 parent 8c1a4a8 commit cb91644

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

docs/src/components/Header/Search.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/** @jsxImportSource react */
22
import { useState, useCallback, useRef } from "react";
33
import "@docsearch/css";
4-
import "./Search.css";
5-
6-
import { createPortal } from "react-dom";
74
import * as docSearchReact from "@docsearch/react";
5+
import { createPortal } from "react-dom";
6+
import "./Search.css";
87

98
/** FIXME: This is still kinda nasty, but DocSearch is not ESM ready. */
109
const DocSearchModal = docSearchReact.DocSearchModal || (docSearchReact as any).default.DocSearchModal;

docs/src/components/LeftSidebar/LeftSidebar.astro

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---
2-
import { SIDEBAR } from "../../consts.js";
3-
42
type Props = {
53
currentPage: string;
64
};

docs/src/layouts/MainLayout.astro

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ type Props = CollectionEntry<"docs">["data"] & {
1515
headings: MarkdownHeading[];
1616
};
1717
18+
interface Link {
19+
url: string;
20+
text: string;
21+
}
22+
1823
const { headings, ...data } = Astro.props;
1924
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
2025
const currentPage = Astro.url.pathname;
@@ -138,5 +143,14 @@ const nextLink: Record<string, Link | undefined> = {
138143
<RightSidebar headings={headings} githubEditUrl={githubEditUrl} />
139144
</aside>
140145
</main>
146+
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
147+
<script is:inline type="text/javascript">
148+
docsearch({
149+
appId: import.meta.env.VITE_ALGOLIA_APP_ID,
150+
apiKey: import.meta.env.VITE_ALGOLIA_SEARCH_KEY,
151+
indexName: import.meta.env.VITE_ALGOLIA_INDEX_NAME,
152+
container: "#grid-main",
153+
});
154+
</script>
141155
</body>
142156
</html>

packages/openapi-fetch/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# openapi-fetch
22

3+
## 0.1.4
4+
5+
### Patch Changes
6+
7+
- 63ebe48: Fix request body type when optional (#48)
8+
9+
## 0.1.3
10+
11+
### Patch Changes
12+
13+
- 8c01480: Fix querySerializer signature
14+
315
## 0.1.2
416

517
### Patch Changes

packages/openapi-fetch/src/index.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,42 @@ describe("post()", () => {
351351
// assert error is empty
352352
expect(error).toBe(undefined);
353353
});
354+
355+
it("request body type when optional", async () => {
356+
fetchMocker.mockResponse(() => ({ status: 201, body: "{}" }));
357+
const client = createClient<paths>();
358+
359+
// expect error on wrong body type
360+
// @ts-expect-error
361+
await client.post("/post/optional", { body: { error: true } });
362+
363+
// (no error)
364+
await client.post("/post/optional", {
365+
body: {
366+
title: "",
367+
publish_date: 3,
368+
body: "",
369+
},
370+
});
371+
});
372+
373+
it("request body type when optional inline", async () => {
374+
fetchMocker.mockResponse(() => ({ status: 201, body: "{}" }));
375+
const client = createClient<paths>();
376+
377+
// expect error on wrong body type
378+
// @ts-expect-error
379+
await client.post("/post/optional/inline", { body: { error: true } });
380+
381+
// (no error)
382+
await client.post("/post/optional/inline", {
383+
body: {
384+
title: "",
385+
publish_date: 3,
386+
body: "",
387+
},
388+
});
389+
});
354390
});
355391

356392
describe("delete()", () => {

packages/openapi-fetch/src/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ export type FilterKeys<Obj, Matchers> = { [K in keyof Obj]: K extends Matchers ?
3434
/** handle "application/json", "application/vnd.api+json", "appliacation/json;charset=utf-8" and more */
3535
export type JSONLike = `${string}json${string}`;
3636

37-
// fetch types
37+
// general purpose types
3838
export type Params<O> = O extends { parameters: any } ? { params: NonNullable<O["parameters"]> } : BaseParams;
39-
export type RequestBodyObj<O> = O extends { requestBody: any } ? O["requestBody"] : never;
39+
export type RequestBodyObj<O> = O extends { requestBody?: any } ? O["requestBody"] : never;
4040
export type RequestBodyContent<O> = undefined extends RequestBodyObj<O> ? FilterKeys<NonNullable<RequestBodyObj<O>>, "content"> | undefined : FilterKeys<RequestBodyObj<O>, "content">;
4141
export type RequestBodyJSON<O> = FilterKeys<RequestBodyContent<O>, JSONLike> extends never ? FilterKeys<NonNullable<RequestBodyContent<O>>, JSONLike> | undefined : FilterKeys<RequestBodyContent<O>, JSONLike>;
4242
export type RequestBody<O> = undefined extends RequestBodyJSON<O> ? { body?: RequestBodyJSON<O> } : { body: RequestBodyJSON<O> };
4343
export type QuerySerializer<O> = (query: O extends { parameters: { query: any } } ? O["parameters"]["query"] : Record<string, unknown>) => string;
44-
export type FetchOptions<T> = Params<T> & RequestBody<T> & Omit<RequestInit, "body"> & { querySerializer?: QuerySerializer<T> };
44+
export type RequestOptions<T> = Params<T> & RequestBody<T> & { querySerializer?: QuerySerializer<T> };
4545
export type Success<O> = FilterKeys<FilterKeys<O, OkStatus>, "content">;
4646
export type Error<O> = FilterKeys<FilterKeys<O, ErrorStatus>, "content">;
47+
48+
// fetch types
49+
export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body">;
4750
export type FetchResponse<T> =
4851
| { data: T extends { responses: any } ? NonNullable<FilterKeys<Success<T["responses"]>, JSONLike>> : unknown; error?: never; response: Response }
4952
| { data?: never; error: T extends { responses: any } ? NonNullable<FilterKeys<Error<T["responses"]>, JSONLike>> : unknown; response: Response };

0 commit comments

Comments
 (0)