@neverblink/ohi 0.18.3 → 0.18.4
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/dist/catalog.js +7 -6
- package/dist/publication.d.ts +2 -2
- package/dist/publication.js +3 -19
- package/package.json +1 -1
package/dist/catalog.js
CHANGED
|
@@ -33,6 +33,10 @@ function searchResult(bytes, page, perPage) {
|
|
|
33
33
|
if (!object(raw) || "grouped_hits" in raw || !Array.isArray(raw.hits) || !object(raw.request_params)) {
|
|
34
34
|
throw new Error("Expected an ungrouped search response with hits and request_params.");
|
|
35
35
|
}
|
|
36
|
+
if (raw.facet_counts !== undefined &&
|
|
37
|
+
!(Array.isArray(raw.facet_counts) && raw.facet_counts.every((facet) => object(facet) && Array.isArray(facet.counts)))) {
|
|
38
|
+
throw new Error("Expected facet_counts to be a list of facets with counts.");
|
|
39
|
+
}
|
|
36
40
|
const result = {
|
|
37
41
|
hits: raw.hits.map((hit) => {
|
|
38
42
|
if (!object(hit) || !object(hit.document))
|
|
@@ -51,15 +55,12 @@ function searchResult(bytes, page, perPage) {
|
|
|
51
55
|
return {
|
|
52
56
|
...result,
|
|
53
57
|
// Formats added after this SDK version are discarded
|
|
54
|
-
hits: result.hits.flatMap((
|
|
58
|
+
hits: result.hits.flatMap((hit) => {
|
|
59
|
+
const { formats } = hit;
|
|
55
60
|
const known = Array.isArray(formats) ? formats.filter((format) => !isNew(format, knownFormats)) : formats;
|
|
56
61
|
if (Array.isArray(formats) && formats.length > 0 && known.length === 0)
|
|
57
62
|
return [];
|
|
58
|
-
return [{
|
|
59
|
-
...(keywords === undefined ? {} : { keywords }) }];
|
|
60
|
-
}),
|
|
61
|
-
...(result.facet_counts === undefined ? {} : {
|
|
62
|
-
facet_counts: result.facet_counts.map(({ field_name, counts }) => ({ field_name, counts: counts.map(({ value, count }) => ({ value, count })) })),
|
|
63
|
+
return [{ ...hit, formats: known }];
|
|
63
64
|
}),
|
|
64
65
|
};
|
|
65
66
|
}
|
package/dist/publication.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const formats: Record<Format, true>;
|
|
|
3
3
|
/** Whether a value is text outside an enum, so added to it after this SDK version. */
|
|
4
4
|
export declare function isNew(value: unknown, known: object): boolean;
|
|
5
5
|
/**
|
|
6
|
-
* Decode publication metadata, discarding
|
|
7
|
-
*
|
|
6
|
+
* Decode publication metadata, discarding artifacts with a format or origin added after this SDK
|
|
7
|
+
* version. Fields that the model doesn't have are kept. Field values are not validated.
|
|
8
8
|
*/
|
|
9
9
|
export declare function decodePublication(text: string): Publication;
|
package/dist/publication.js
CHANGED
|
@@ -9,8 +9,8 @@ export function isNew(value, known) {
|
|
|
9
9
|
return typeof value === "string" && !Object.hasOwn(known, value);
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Decode publication metadata, discarding
|
|
13
|
-
*
|
|
12
|
+
* Decode publication metadata, discarding artifacts with a format or origin added after this SDK
|
|
13
|
+
* version. Fields that the model doesn't have are kept. Field values are not validated.
|
|
14
14
|
*/
|
|
15
15
|
export function decodePublication(text) {
|
|
16
16
|
const data = JSON.parse(text);
|
|
@@ -32,21 +32,5 @@ export function decodePublication(text) {
|
|
|
32
32
|
if (dependencyUrls.includes(data.base_url)) {
|
|
33
33
|
throw new Error("dependencies must not contain the publication itself");
|
|
34
34
|
}
|
|
35
|
-
return {
|
|
36
|
-
schema_version: data.schema_version,
|
|
37
|
-
base_url: data.base_url,
|
|
38
|
-
version: data.version,
|
|
39
|
-
namespace: data.namespace,
|
|
40
|
-
name: data.name,
|
|
41
|
-
title: data.title,
|
|
42
|
-
published_at: data.published_at,
|
|
43
|
-
publisher: data.publisher,
|
|
44
|
-
licenses: data.licenses,
|
|
45
|
-
...(data.namespace_iri === undefined ? {} : { namespace_iri: data.namespace_iri }),
|
|
46
|
-
...(data.preferred_prefix === undefined ? {} : { preferred_prefix: data.preferred_prefix }),
|
|
47
|
-
description: data.description,
|
|
48
|
-
keywords: data.keywords,
|
|
49
|
-
artifacts: artifacts.map(({ format, url, origin, roots, size_bytes, sha256 }) => ({ format, url, origin, roots, size_bytes, sha256 })),
|
|
50
|
-
dependencies: data.dependencies.map(({ base_url }) => ({ base_url })),
|
|
51
|
-
};
|
|
35
|
+
return { ...data, artifacts };
|
|
52
36
|
}
|
package/package.json
CHANGED