@biblioteksentralen/bmdb-search 0.0.0-beta.21 → 0.0.0-beta.23

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 (2) hide show
  1. package/README.md +53 -19
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,43 +2,77 @@
2
2
 
3
3
  TypeScript client for searching Bibliotekenes metadatabrønn (BMDB) using [openapi-fetch](https://openapi-ts.dev/openapi-fetch/).
4
4
 
5
- ## Options
6
-
7
5
  ## Usage examples
8
6
 
9
- ### Search works
7
+ ### Setup client
10
8
 
11
9
  ```typescript
12
10
  import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
13
11
 
14
12
  const bmdbSearchClient = createBmdbFetchClient({
15
- host: "https://search.data.bs.no",
13
+ host: "https://search.bmdb.no/",
16
14
  });
15
+ ```
17
16
 
18
- const { data, error } = await bmdbSearchClient.GET("/works/search", { params: { query: { query: "test" } } });
17
+ ### Search works
18
+
19
+ ```typescript
20
+ const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/works/search", {
21
+ params: {
22
+ path: { searchProfile: "global" },
23
+ query: { query: "test" },
24
+ },
25
+ });
19
26
  ```
20
27
 
21
- The arguments and response are fully typed.
28
+ ### Get works
22
29
 
23
- ### Usage with tanstack-query, openapi-react-query and React hooks
30
+ ```typescript
31
+ const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/works", {
32
+ params: {
33
+ path: { searchProfile: "deichman" },
34
+ query: { ids: "1237715,1237713" },
35
+ },
36
+ });
37
+ ```
24
38
 
25
- Using [tanstack](https://tanstack.com/query/latest) for fetching with state management and [openapi-react-query](https://openapi-ts.dev/openapi-react-query/) for typing.
39
+ ### Search agents
26
40
 
27
41
  ```typescript
28
- import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
29
- import createReactQueryClient from "openapi-react-query";
42
+ const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/agents/search", {
43
+ params: {
44
+ path: { searchProfile: "tonsberg" },
45
+ query: { query: "test" },
46
+ },
47
+ });
48
+ ```
30
49
 
31
- const bmdbSearchClient = createBmdbFetchClient({
32
- host: "https://search.data.bs.no"
50
+ ### Find all contributor roles for a given agent
51
+
52
+ ```typescript
53
+ const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/agents/search", {
54
+ params: {
55
+ path: { searchProfile: "global" },
56
+ query: { facet: "role", size: 0, facet_terms_size: 20 },
57
+ },
33
58
  });
59
+ ```
34
60
 
35
- const { useQuery } = createReactQueryClient(bmdbSearchClient);
61
+ The arguments and response are fully typed.
62
+
63
+ ## Usage with Next.js
64
+
65
+ The queries have to happen in a server context. For this purpose we can create a server client:
36
66
 
37
- const Component = () => {
38
- const { data, error, isLoading } = useQuery("get", "/works/search", { params: { query: { query: "test" } } });
39
- if (isLoading) return <div>Loading</div>;
40
- if (error) return <div>Something went wrong</div>;
41
- return <div>Found {data?.total} works</div>;
42
- };
67
+ ```typescript
68
+ "server only";
69
+
70
+ import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
71
+ import { headers } from "next/headers";
43
72
 
73
+ export const getBmdbServerFetchClient = async () =>
74
+ createBmdbFetchClient({
75
+ host: "http://localhost:8092",
76
+ headers: await headers(),
77
+ });
44
78
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biblioteksentralen/bmdb-search",
3
- "version": "0.0.0-beta.21",
3
+ "version": "0.0.0-beta.23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Client for searching Bibliotekenes metadatabrønn (BMDB)",