@biblioteksentralen/bmdb-search 0.0.0-beta.5 → 0.0.0-beta.7

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.
package/README.md CHANGED
@@ -16,7 +16,10 @@ name and a contact address in the `clientIdentifier` string. We will only contac
16
16
  ```typescript
17
17
  import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
18
18
 
19
- const bmdbSearchClient = createBmdbFetchClient({ clientIdentifier: "client-unique-description" });
19
+ const bmdbSearchClient = createBmdbFetchClient({
20
+ clientIdentifier: "client-unique-description",
21
+ host: "https://search.data.bs.no",
22
+ });
20
23
  const { data, error } = await bmdbSearchClient.GET("/works/search", { params: { query: { query: "test" } } });
21
24
  ```
22
25
 
package/dist/index.cjs CHANGED
@@ -6,13 +6,29 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
6
 
7
7
  var createFetchClient__default = /*#__PURE__*/_interopDefault(createFetchClient);
8
8
 
9
- // src/client.ts
9
+ // ../api-specifications/dist/utils/formatIsbdTitle.js
10
+ var formatIsbdTitle = (data, options = {}) => {
11
+ const { title, parallelTitles = [] } = data;
12
+ if (title.titleType === "uniform_title_music") {
13
+ return formatUniformTitleMusic(title);
14
+ } else {
15
+ return [title, ...parallelTitles].map((title2) => formatSingleTitle(title2, options)).join(" = ");
16
+ }
17
+ };
18
+ var formatSingleTitle = ({ mainTitle, subtitle, partNumber, partTitle }, options) => mainTitle + (subtitle && !options.skipSubtitle ? ` : ${subtitle}` : "") + (partNumber ? `. ${partNumber}` : "") + (partTitle ? `. ${partTitle}` : "");
19
+ var formatUniformTitleMusic = ({ form, instrumentation, serialNumber, opusNumber, thematicCatalogueNumber, part, key, arrangement }) => form + (instrumentation ? ` ${instrumentation}` : "") + (serialNumber ? `, ${serialNumber}` : "") + (opusNumber ? `, ${opusNumber}` : "") + (thematicCatalogueNumber ? `, ${thematicCatalogueNumber}` : "") + (part ? `, ${part}` : "") + (key ? `, ${key}` : "") + (arrangement ? `, ${arrangement}` : "");
10
20
  var createBmdbFetchClient = ({
11
21
  clientIdentifier,
22
+ host,
12
23
  version = "v1",
13
24
  ...options
14
25
  }) => {
15
- const baseUrl = `${options.baseUrl?.replace(/(.*)\/$/, "$1") ?? ""}/bmdb/api/${version}/`;
26
+ try {
27
+ new URL(host);
28
+ } catch {
29
+ throw new Error(`Invalid host URL: ${host}`);
30
+ }
31
+ const baseUrl = `${host.replace(/(.*)\/$/, "$1")}/bmdb/api/${version}/`;
16
32
  const client = createFetchClient__default.default({
17
33
  baseUrl,
18
34
  querySerializer: { array: { style: "form", explode: false } },
@@ -28,3 +44,4 @@ var createBmdbFetchClient = ({
28
44
  };
29
45
 
30
46
  exports.createBmdbFetchClient = createBmdbFetchClient;
47
+ exports.formatIsbdTitle = formatIsbdTitle;
package/dist/index.d.cts CHANGED
@@ -1133,18 +1133,32 @@ interface operations {
1133
1133
  };
1134
1134
  }
1135
1135
 
1136
+ type BmdbApiSchemas$1 = components["schemas"];
1137
+
1138
+ type TitleLike = Pick<BmdbApiSchemas$1["Title"], "mainTitle" | "subtitle" | "partNumber" | "partTitle" | "titleType">;
1139
+ type UniformTitleMusicLike = Pick<BmdbApiSchemas$1["UniformTitleMusic"], "titleType" | "form" | "instrumentation" | "serialNumber" | "opusNumber" | "thematicCatalogueNumber" | "part" | "key" | "arrangement">;
1140
+ type FormatIsbdTitleProps = {
1141
+ title: TitleLike | UniformTitleMusicLike;
1142
+ parallelTitles?: TitleLike[];
1143
+ };
1144
+ type FormatIsbdTitleOptions = {
1145
+ skipSubtitle?: boolean;
1146
+ };
1147
+ declare const formatIsbdTitle: (data: FormatIsbdTitleProps, options?: FormatIsbdTitleOptions) => string;
1148
+
1136
1149
  type BmdbApiSchemas = components["schemas"];
1137
1150
  type BmdbApiPaths = paths;
1138
1151
 
1139
1152
  type BmdbSearchClientOptions = ClientOptions & {
1140
1153
  clientIdentifier: string;
1154
+ host: string;
1141
1155
  version?: "v1";
1142
1156
  };
1143
1157
  type BmdbSearchClient = Client<BmdbApiPaths>;
1144
- declare const createBmdbFetchClient: ({ clientIdentifier, version, ...options }: BmdbSearchClientOptions) => BmdbSearchClient;
1158
+ declare const createBmdbFetchClient: ({ clientIdentifier, host, version, ...options }: BmdbSearchClientOptions) => BmdbSearchClient;
1145
1159
 
1146
1160
  type BmdbWork = BmdbApiSchemas["Work"];
1147
1161
  type BmdbExpression = BmdbApiSchemas["Expression"];
1148
1162
  type BmdbManifestation = BmdbApiSchemas["Manifestation"];
1149
1163
 
1150
- export { type BmdbExpression, type BmdbManifestation, type BmdbSearchClient, type BmdbSearchClientOptions, type BmdbWork, createBmdbFetchClient };
1164
+ export { type BmdbExpression, type BmdbManifestation, type BmdbSearchClient, type BmdbSearchClientOptions, type BmdbWork, createBmdbFetchClient, formatIsbdTitle };
package/dist/index.d.ts CHANGED
@@ -1133,18 +1133,32 @@ interface operations {
1133
1133
  };
1134
1134
  }
1135
1135
 
1136
+ type BmdbApiSchemas$1 = components["schemas"];
1137
+
1138
+ type TitleLike = Pick<BmdbApiSchemas$1["Title"], "mainTitle" | "subtitle" | "partNumber" | "partTitle" | "titleType">;
1139
+ type UniformTitleMusicLike = Pick<BmdbApiSchemas$1["UniformTitleMusic"], "titleType" | "form" | "instrumentation" | "serialNumber" | "opusNumber" | "thematicCatalogueNumber" | "part" | "key" | "arrangement">;
1140
+ type FormatIsbdTitleProps = {
1141
+ title: TitleLike | UniformTitleMusicLike;
1142
+ parallelTitles?: TitleLike[];
1143
+ };
1144
+ type FormatIsbdTitleOptions = {
1145
+ skipSubtitle?: boolean;
1146
+ };
1147
+ declare const formatIsbdTitle: (data: FormatIsbdTitleProps, options?: FormatIsbdTitleOptions) => string;
1148
+
1136
1149
  type BmdbApiSchemas = components["schemas"];
1137
1150
  type BmdbApiPaths = paths;
1138
1151
 
1139
1152
  type BmdbSearchClientOptions = ClientOptions & {
1140
1153
  clientIdentifier: string;
1154
+ host: string;
1141
1155
  version?: "v1";
1142
1156
  };
1143
1157
  type BmdbSearchClient = Client<BmdbApiPaths>;
1144
- declare const createBmdbFetchClient: ({ clientIdentifier, version, ...options }: BmdbSearchClientOptions) => BmdbSearchClient;
1158
+ declare const createBmdbFetchClient: ({ clientIdentifier, host, version, ...options }: BmdbSearchClientOptions) => BmdbSearchClient;
1145
1159
 
1146
1160
  type BmdbWork = BmdbApiSchemas["Work"];
1147
1161
  type BmdbExpression = BmdbApiSchemas["Expression"];
1148
1162
  type BmdbManifestation = BmdbApiSchemas["Manifestation"];
1149
1163
 
1150
- export { type BmdbExpression, type BmdbManifestation, type BmdbSearchClient, type BmdbSearchClientOptions, type BmdbWork, createBmdbFetchClient };
1164
+ export { type BmdbExpression, type BmdbManifestation, type BmdbSearchClient, type BmdbSearchClientOptions, type BmdbWork, createBmdbFetchClient, formatIsbdTitle };
package/dist/index.js CHANGED
@@ -1,12 +1,28 @@
1
1
  import createFetchClient from 'openapi-fetch';
2
2
 
3
- // src/client.ts
3
+ // ../api-specifications/dist/utils/formatIsbdTitle.js
4
+ var formatIsbdTitle = (data, options = {}) => {
5
+ const { title, parallelTitles = [] } = data;
6
+ if (title.titleType === "uniform_title_music") {
7
+ return formatUniformTitleMusic(title);
8
+ } else {
9
+ return [title, ...parallelTitles].map((title2) => formatSingleTitle(title2, options)).join(" = ");
10
+ }
11
+ };
12
+ var formatSingleTitle = ({ mainTitle, subtitle, partNumber, partTitle }, options) => mainTitle + (subtitle && !options.skipSubtitle ? ` : ${subtitle}` : "") + (partNumber ? `. ${partNumber}` : "") + (partTitle ? `. ${partTitle}` : "");
13
+ var formatUniformTitleMusic = ({ form, instrumentation, serialNumber, opusNumber, thematicCatalogueNumber, part, key, arrangement }) => form + (instrumentation ? ` ${instrumentation}` : "") + (serialNumber ? `, ${serialNumber}` : "") + (opusNumber ? `, ${opusNumber}` : "") + (thematicCatalogueNumber ? `, ${thematicCatalogueNumber}` : "") + (part ? `, ${part}` : "") + (key ? `, ${key}` : "") + (arrangement ? `, ${arrangement}` : "");
4
14
  var createBmdbFetchClient = ({
5
15
  clientIdentifier,
16
+ host,
6
17
  version = "v1",
7
18
  ...options
8
19
  }) => {
9
- const baseUrl = `${options.baseUrl?.replace(/(.*)\/$/, "$1") ?? ""}/bmdb/api/${version}/`;
20
+ try {
21
+ new URL(host);
22
+ } catch {
23
+ throw new Error(`Invalid host URL: ${host}`);
24
+ }
25
+ const baseUrl = `${host.replace(/(.*)\/$/, "$1")}/bmdb/api/${version}/`;
10
26
  const client = createFetchClient({
11
27
  baseUrl,
12
28
  querySerializer: { array: { style: "form", explode: false } },
@@ -21,4 +37,4 @@ var createBmdbFetchClient = ({
21
37
  return client;
22
38
  };
23
39
 
24
- export { createBmdbFetchClient };
40
+ export { createBmdbFetchClient, formatIsbdTitle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biblioteksentralen/bmdb-search",
3
- "version": "0.0.0-beta.5",
3
+ "version": "0.0.0-beta.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Client for searching Bibliotekenes metadatabrønn (BMDB)",