@neverblink/ohi 0.18.6 → 0.18.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 +7 -0
- package/dist/catalog.d.ts +13 -4
- package/dist/catalog.js +49 -11
- package/dist/generated.d.ts +83 -2
- package/dist/version-tag.d.ts +17 -0
- package/dist/version-tag.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,13 @@ if (page.hits.length > 0) {
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
`inspect` and `latest` also take an ontology reference such as `w3c/dcat@3` instead of a URL, see [ontology references](https://ohi.dev/docs/reference/cli/#ontology-references-and-formats).
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const hit = await client.latest("w3c/dcat@3"); // search hit, or undefined
|
|
29
|
+
const publication = await client.inspect("w3c/dcat@3");
|
|
30
|
+
```
|
|
31
|
+
|
|
25
32
|
`get` returns the file's bytes as a `Uint8Array`. File reading and writing are in `@neverblink/ohi/node`.
|
|
26
33
|
|
|
27
34
|
**See the [SDK documentation](https://ohi.dev/docs/reference/sdks/)** for configuration, file selections, metadata and errors.
|
package/dist/catalog.d.ts
CHANGED
|
@@ -9,14 +9,23 @@ export declare class CatalogClient {
|
|
|
9
9
|
private readonly timeoutMs;
|
|
10
10
|
private readonly base;
|
|
11
11
|
private readonly latestUrl;
|
|
12
|
+
private readonly latestRevisionUrl;
|
|
12
13
|
constructor(config?: CatalogConfig);
|
|
13
14
|
search(request: SearchRequest): Promise<SearchResult>;
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/** Run a search against one collection's search URL. */
|
|
16
|
+
private searchAt;
|
|
17
|
+
/** Return the search hit of the release a reference requests, or undefined when the catalog has none.
|
|
18
|
+
*
|
|
19
|
+
* `namespace/name` requests the latest version, `namespace/name@1.0` the latest revision of 1.0,
|
|
20
|
+
* `namespace/name@1.0-no-revision` the 1.0 version without its revisions, and `namespace/name@1.0-revision-2026-12-01`
|
|
21
|
+
* exactly that revision.
|
|
16
22
|
*/
|
|
17
23
|
latest(reference: string): Promise<SearchHit | undefined>;
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
24
|
+
/** The latest revision of a version from packages_latest_revision, or undefined when it has none there. A hub
|
|
25
|
+
* before 0.2.0 doesn't have that collection.
|
|
26
|
+
*/
|
|
27
|
+
private latestRevision;
|
|
28
|
+
/** Fetch the publication at an absolute HTTP(S) URL, or of the release a reference requests, as `latest` describes.
|
|
20
29
|
*/
|
|
21
30
|
inspect(baseUrl: string): Promise<Publication>;
|
|
22
31
|
get(url: string): Promise<Uint8Array>;
|
package/dist/catalog.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { decodePublication, formats as knownFormats, isNew } from "./publication.js";
|
|
2
|
+
import { parseVersionTag } from "./version-tag.js";
|
|
2
3
|
const searchPath = "/search/collections/packages/documents/search";
|
|
3
4
|
const referencePattern = /^([^/@\p{White_Space}`]+)\/([^/@\p{White_Space}`]+)(?:@([^/@\p{White_Space}+`]+))?$/u;
|
|
4
5
|
export class CatalogException extends Error {
|
|
@@ -70,6 +71,7 @@ export class CatalogClient {
|
|
|
70
71
|
timeoutMs;
|
|
71
72
|
base;
|
|
72
73
|
latestUrl;
|
|
74
|
+
latestRevisionUrl;
|
|
73
75
|
constructor(config = {}) {
|
|
74
76
|
const url = config.search_url;
|
|
75
77
|
if ((config.search_url === undefined) !== (config.query_by === undefined)) {
|
|
@@ -95,9 +97,13 @@ export class CatalogClient {
|
|
|
95
97
|
this.timeoutMs = config.timeout_ms ?? 30000;
|
|
96
98
|
this.base = this.config.search_url.slice(0, -searchPath.length);
|
|
97
99
|
this.latestUrl = `${this.base}/search/collections/packages_latest/documents/search`;
|
|
100
|
+
this.latestRevisionUrl = `${this.base}/search/collections/packages_latest_revision/documents/search`;
|
|
98
101
|
}
|
|
99
102
|
async search(request) {
|
|
100
|
-
|
|
103
|
+
return this.searchAt(request.all_releases ? this.config.search_url : this.latestUrl, request);
|
|
104
|
+
}
|
|
105
|
+
/** Run a search against one collection's search URL. */
|
|
106
|
+
async searchAt(endpoint, request) {
|
|
101
107
|
const page = request.page ?? 1;
|
|
102
108
|
const perPage = request.per_page ?? 10;
|
|
103
109
|
const url = new URL(endpoint);
|
|
@@ -122,23 +128,52 @@ export class CatalogClient {
|
|
|
122
128
|
message: "The search response is invalid." }, { cause });
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
|
-
/** Return the search hit
|
|
126
|
-
*
|
|
131
|
+
/** Return the search hit of the release a reference requests, or undefined when the catalog has none.
|
|
132
|
+
*
|
|
133
|
+
* `namespace/name` requests the latest version, `namespace/name@1.0` the latest revision of 1.0,
|
|
134
|
+
* `namespace/name@1.0-no-revision` the 1.0 version without its revisions, and `namespace/name@1.0-revision-2026-12-01`
|
|
135
|
+
* exactly that revision.
|
|
127
136
|
*/
|
|
128
137
|
async latest(reference) {
|
|
129
138
|
const parts = referencePattern.exec(reference);
|
|
130
|
-
if (parts === null
|
|
139
|
+
if (parts === null) {
|
|
131
140
|
throw new CatalogException({ code: "INVALID_INPUT", operation: "SEARCH", url: reference,
|
|
132
|
-
message: "Supply an ontology reference namespace/name
|
|
141
|
+
message: "Supply an ontology reference namespace/name[@version]." });
|
|
133
142
|
}
|
|
134
|
-
const [, namespace, name] = parts;
|
|
143
|
+
const [, namespace, name, version] = parts;
|
|
135
144
|
const filter = `namespace:=\`${namespace}\` && name:=\`${name}\``;
|
|
136
|
-
const result = await this.search({ q: "*", filter_by: filter });
|
|
137
145
|
// The := filter ignores case and separators, so look-alikes such as w3c/DCAT can match.
|
|
138
|
-
|
|
146
|
+
const same = (hit) => hit.namespace === namespace && hit.name === name;
|
|
147
|
+
if (version === undefined) {
|
|
148
|
+
return (await this.search({ q: "*", filter_by: filter })).hits.find(same);
|
|
149
|
+
}
|
|
150
|
+
const { original, exact } = parseVersionTag(version);
|
|
151
|
+
if (exact === undefined) {
|
|
152
|
+
const hit = await this.latestRevision(filter, original, same);
|
|
153
|
+
if (hit !== undefined)
|
|
154
|
+
return hit;
|
|
155
|
+
}
|
|
156
|
+
// The release itself; for a version, also on a hub without revisions or before its revisions are indexed
|
|
157
|
+
const release = exact ?? original;
|
|
158
|
+
const releases = await this.searchAt(this.config.search_url, { q: "*", filter_by: `${filter} && version:=\`${release}\`` });
|
|
159
|
+
return releases.hits.find((hit) => same(hit) && hit.version === release);
|
|
160
|
+
}
|
|
161
|
+
/** The latest revision of a version from packages_latest_revision, or undefined when it has none there. A hub
|
|
162
|
+
* before 0.2.0 doesn't have that collection.
|
|
163
|
+
*/
|
|
164
|
+
async latestRevision(filter, original, same) {
|
|
165
|
+
try {
|
|
166
|
+
const result = await this.searchAt(this.latestRevisionUrl, { q: "*", filter_by: `${filter} && original_version:=\`${original}\`` });
|
|
167
|
+
return result.hits.find((hit) => same(hit) && hit.original_version === original);
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (error instanceof CatalogException && error.error.code === "HTTP_ERROR" && error.error.status === 404) {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
139
175
|
}
|
|
140
|
-
/** Fetch the publication at an absolute HTTP(S) URL, of the release
|
|
141
|
-
* version of `namespace/name`.
|
|
176
|
+
/** Fetch the publication at an absolute HTTP(S) URL, or of the release a reference requests, as `latest` describes.
|
|
142
177
|
*/
|
|
143
178
|
async inspect(baseUrl) {
|
|
144
179
|
let url = baseUrl;
|
|
@@ -146,7 +181,10 @@ export class CatalogClient {
|
|
|
146
181
|
if (parts !== null) {
|
|
147
182
|
const [, namespace, name, version] = parts;
|
|
148
183
|
if (version !== undefined) {
|
|
149
|
-
|
|
184
|
+
const { exact } = parseVersionTag(version);
|
|
185
|
+
const release = `${this.base}/files/packages/${[namespace, name, exact ?? version].map(encodeURIComponent).join("/")}/`;
|
|
186
|
+
// The release path when the catalog doesn't know the version
|
|
187
|
+
url = exact !== undefined ? release : (await this.latest(baseUrl))?.base_url ?? release;
|
|
150
188
|
}
|
|
151
189
|
else {
|
|
152
190
|
const hit = await this.latest(baseUrl);
|
package/dist/generated.d.ts
CHANGED
|
@@ -83,6 +83,31 @@ export interface FacetValueCount {
|
|
|
83
83
|
value: string;
|
|
84
84
|
[key: string]: unknown;
|
|
85
85
|
}
|
|
86
|
+
/** File that is part of this publication */
|
|
87
|
+
export interface File {
|
|
88
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
89
|
+
url: string;
|
|
90
|
+
}
|
|
91
|
+
/** File that was generated from a remote source */
|
|
92
|
+
export interface GeneratedFile {
|
|
93
|
+
/** The input file for this conversion */
|
|
94
|
+
source: string;
|
|
95
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
96
|
+
url: string;
|
|
97
|
+
/** Tool that was used for the conversion */
|
|
98
|
+
using: string;
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}
|
|
101
|
+
/** File that was fetched from the ohi-index repository directly */
|
|
102
|
+
export interface IndexFile {
|
|
103
|
+
/** Commit sha of ohi-index the package was read at */
|
|
104
|
+
commit: string;
|
|
105
|
+
/** Path to the file in the repository. */
|
|
106
|
+
path: string;
|
|
107
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
108
|
+
url: string;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
}
|
|
86
111
|
/** Direct selections and their artifact files. */
|
|
87
112
|
export interface Lock {
|
|
88
113
|
/** Each (base_url, url) pair is unique. Every selection matches a file by that pair. */
|
|
@@ -110,6 +135,28 @@ export interface LockedFile {
|
|
|
110
135
|
/** SHA-256 of the file bytes before HTTP content encoding. */
|
|
111
136
|
sha256?: string;
|
|
112
137
|
}
|
|
138
|
+
/** File which was created by patching another */
|
|
139
|
+
export interface PatchedFile {
|
|
140
|
+
/** The base IRI, if it was patched in. */
|
|
141
|
+
added_base_iri?: string;
|
|
142
|
+
/** True if the line endings were converted from CRLF to LF. */
|
|
143
|
+
converted_line_endings?: boolean;
|
|
144
|
+
/** The input file for this patch */
|
|
145
|
+
from: string;
|
|
146
|
+
/** The base url of the JSON-Patch file, if the ontology was patched this way. */
|
|
147
|
+
json_patch?: string;
|
|
148
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
149
|
+
url: string;
|
|
150
|
+
[key: string]: unknown;
|
|
151
|
+
}
|
|
152
|
+
/** Provenance of the files */
|
|
153
|
+
export interface Provenance {
|
|
154
|
+
generated?: GeneratedFile[];
|
|
155
|
+
index?: IndexFile[];
|
|
156
|
+
patched?: PatchedFile[];
|
|
157
|
+
remote?: RemoteFile[];
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
113
160
|
/** One immutable release of one ontology, including its metadata, artifacts and dependencies. Package, publication and release refer to the same entity. */
|
|
114
161
|
export interface Publication {
|
|
115
162
|
/** Available artifacts of this ontology. Each artifact URL occurs once. Multiple artifacts may share a format. */
|
|
@@ -126,8 +173,12 @@ export interface Publication {
|
|
|
126
173
|
description: string;
|
|
127
174
|
/** Number of LinkML elements in the publication. */
|
|
128
175
|
element_count?: number;
|
|
176
|
+
/** Hub version that released this publication. */
|
|
177
|
+
hub_version?: string;
|
|
129
178
|
/** Keywords describing the ontology's subject. An empty list means no keywords are provided. */
|
|
130
179
|
keywords: string[];
|
|
180
|
+
/** Links to files with the licensing/copyright text. */
|
|
181
|
+
license_files?: string[];
|
|
131
182
|
/** Reported license names or standard identifiers such as Apache-2.0. Empty means no information supplied. The list specifies neither AND nor OR combination semantics. */
|
|
132
183
|
licenses: string[];
|
|
133
184
|
/** The third-party people or organizations that maintain the ontology in the ohi index. */
|
|
@@ -144,6 +195,8 @@ export interface Publication {
|
|
|
144
195
|
original_sources: string[];
|
|
145
196
|
/** Optional abbreviation for namespace_iri, without whitespace or a colon. Requires namespace_iri. This constraint does not certify prefix syntax for every ontology language. */
|
|
146
197
|
preferred_prefix?: string;
|
|
198
|
+
/** Provenance information about this Publication, if it has any */
|
|
199
|
+
provenance?: Provenance;
|
|
147
200
|
/** Papers that introduce or describe the ontology. */
|
|
148
201
|
publications?: Citation[];
|
|
149
202
|
/** First successful Hub publication time for this immutable release. Backend emits UTC date-time text with Z. Consumers accept timezone-bearing RFC 3339 text. Fixed for the lifetime of this publication. Not an upstream release date. */
|
|
@@ -152,14 +205,36 @@ export interface Publication {
|
|
|
152
205
|
publisher: string;
|
|
153
206
|
/** The people or organizations that publish the ontology upstream. */
|
|
154
207
|
publishers: Agent[];
|
|
208
|
+
/** Revision information about this Publication, if it has any */
|
|
209
|
+
revision?: RevisionInfo;
|
|
155
210
|
/** Metadata contract revision, independent of the ontology's version. */
|
|
156
211
|
schema_version: number;
|
|
157
212
|
/** Display title of the ontology. */
|
|
158
213
|
title: string;
|
|
159
|
-
/** Complete publication version label, including
|
|
214
|
+
/** Complete publication version label, including the revision id if present. */
|
|
160
215
|
version: string;
|
|
161
216
|
[key: string]: unknown;
|
|
162
217
|
}
|
|
218
|
+
/** File that was fetched from a remote source */
|
|
219
|
+
export interface RemoteFile {
|
|
220
|
+
/** The URI that was queried for the file */
|
|
221
|
+
from: string;
|
|
222
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
223
|
+
url: string;
|
|
224
|
+
[key: string]: unknown;
|
|
225
|
+
}
|
|
226
|
+
/** Information about the revision */
|
|
227
|
+
export interface RevisionInfo {
|
|
228
|
+
/** An identifier of the revision, added as a suffix to the version */
|
|
229
|
+
id: string;
|
|
230
|
+
/** Original version of the ontology, prefix of the full version */
|
|
231
|
+
original_version: string;
|
|
232
|
+
/** Reason why this revision was created */
|
|
233
|
+
reason?: string;
|
|
234
|
+
/** base_uri of the revised ontology */
|
|
235
|
+
revises: string;
|
|
236
|
+
[key: string]: unknown;
|
|
237
|
+
}
|
|
163
238
|
/** Summary of one immutable publication. */
|
|
164
239
|
export interface SearchHit {
|
|
165
240
|
/** The people or organizations that made the ontology. */
|
|
@@ -174,6 +249,8 @@ export interface SearchHit {
|
|
|
174
249
|
element_count?: number;
|
|
175
250
|
/** Formats of the publication's available artifacts. Each value identifies both the ontology language and serialization syntax, as in artifact.format. */
|
|
176
251
|
formats: Format[];
|
|
252
|
+
/** Hub version that released this publication. */
|
|
253
|
+
hub_version?: string;
|
|
177
254
|
/** Keywords describing the ontology's subject. An empty list means no keywords are provided. */
|
|
178
255
|
keywords: string[];
|
|
179
256
|
/** Reported license names or standard identifiers such as Apache-2.0. Empty means no information supplied. The list specifies neither AND nor OR combination semantics. */
|
|
@@ -188,15 +265,19 @@ export interface SearchHit {
|
|
|
188
265
|
native_element_count?: number;
|
|
189
266
|
/** Upstream official sources of the ontology, such as its homepage or repository. */
|
|
190
267
|
original_sources: string[];
|
|
268
|
+
/** The version first published. For a revision, the original_version of its revision, otherwise the version itself. Filtering on it finds a release and all its revisions. */
|
|
269
|
+
original_version?: string;
|
|
191
270
|
/** Papers that introduce or describe the ontology. */
|
|
192
271
|
publications?: Citation[];
|
|
193
272
|
/** First successful Hub publication time for this immutable release. Backend emits UTC date-time text with Z. Consumers accept timezone-bearing RFC 3339 text. Fixed for the lifetime of this publication. Not an upstream release date. */
|
|
194
273
|
published_at: string;
|
|
195
274
|
/** The people or organizations that publish the ontology upstream. */
|
|
196
275
|
publishers: Agent[];
|
|
276
|
+
/** The id of the revision, only for a revision. The latest revision of a version is its document in packages_latest_revision. */
|
|
277
|
+
revision_id?: string;
|
|
197
278
|
/** Display title of the ontology. */
|
|
198
279
|
title: string;
|
|
199
|
-
/** Complete publication version label, including
|
|
280
|
+
/** Complete publication version label, including the revision id if present. */
|
|
200
281
|
version: string;
|
|
201
282
|
[key: string]: unknown;
|
|
202
283
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The release the version of a reference `namespace/name@version` requests. A published version can be fixed in
|
|
2
|
+
* revisions, `{original}-revision-{id}`:
|
|
3
|
+
* - `1.0` requests the latest revision of 1.0, or 1.0 itself when it has none
|
|
4
|
+
* - `1.0-revision-2026-12-31` requests exactly that revision
|
|
5
|
+
* - `1.0-no-revision` requests the 1.0 version without its revisions
|
|
6
|
+
*/
|
|
7
|
+
export interface VersionTag {
|
|
8
|
+
/** The version first published. */
|
|
9
|
+
original: string;
|
|
10
|
+
/** The version to use as it is, or undefined for the latest revision of `original`. */
|
|
11
|
+
exact?: string;
|
|
12
|
+
}
|
|
13
|
+
/** What separates a revision's original version from its id. */
|
|
14
|
+
export declare const revisionSeparator = "-revision-";
|
|
15
|
+
/** What requests a version without its revisions. */
|
|
16
|
+
export declare const noRevisionSuffix = "-no-revision";
|
|
17
|
+
export declare function parseVersionTag(version: string): VersionTag;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What separates a revision's original version from its id. */
|
|
2
|
+
export const revisionSeparator = "-revision-";
|
|
3
|
+
/** What requests a version without its revisions. */
|
|
4
|
+
export const noRevisionSuffix = "-no-revision";
|
|
5
|
+
export function parseVersionTag(version) {
|
|
6
|
+
if (version.endsWith(noRevisionSuffix) && version.length > noRevisionSuffix.length) {
|
|
7
|
+
const original = version.slice(0, -noRevisionSuffix.length);
|
|
8
|
+
return { original, exact: original };
|
|
9
|
+
}
|
|
10
|
+
const at = version.indexOf(revisionSeparator);
|
|
11
|
+
return at > 0 ? { original: version.slice(0, at), exact: version } : { original: version };
|
|
12
|
+
}
|
package/package.json
CHANGED