@neverblink/ohi 0.0.1 → 0.17.2
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/LICENSE +201 -0
- package/README.md +17 -0
- package/dist/ajv.d.ts +3 -0
- package/dist/ajv.js +38 -0
- package/dist/catalog-config.schema.json +35 -0
- package/dist/catalog.d.ts +19 -0
- package/dist/catalog.js +190 -0
- package/dist/generated.d.ts +60 -0
- package/dist/generated.js +3 -0
- package/dist/generated_config.d.ts +8 -0
- package/dist/generated_config.js +3 -0
- package/dist/generated_error.d.ts +16 -0
- package/dist/generated_error.js +3 -0
- package/dist/generated_lock.d.ts +27 -0
- package/dist/generated_lock.js +3 -0
- package/dist/generated_lock_error.d.ts +10 -0
- package/dist/generated_lock_error.js +3 -0
- package/dist/generated_search.d.ts +58 -0
- package/dist/generated_search.js +3 -0
- package/dist/generated_search_request.d.ts +17 -0
- package/dist/generated_search_request.js +3 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +3 -0
- package/dist/lock.d.ts +14 -0
- package/dist/lock.js +62 -0
- package/dist/lock.schema.json +111 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.js +76 -0
- package/dist/package.schema.json +225 -0
- package/dist/publication.d.ts +3 -0
- package/dist/publication.js +44 -0
- package/dist/search-request.schema.json +63 -0
- package/dist/search.schema.json +211 -0
- package/package.json +36 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 NeverBlink sp. z o.o.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Ohi SDK
|
|
2
|
+
|
|
3
|
+
The Ohi SDK lets Python and TypeScript applications search publications, inspect metadata, download selected files and save supplied file selections.
|
|
4
|
+
|
|
5
|
+
Install on Python 3.10 or later:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install ohi-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install for Node 22 or later, or a browser application:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @neverblink/ohi
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
See the [SDK guide](https://github.com/NeverBlink-OSS/linkml-scala/blob/main/ohi/README.md) for usage, browser requirements and API behavior.
|
package/dist/ajv.d.ts
ADDED
package/dist/ajv.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
|
+
import addFormats from "ajv-formats";
|
|
3
|
+
/** A validator that knows every format the generated schemas use. */
|
|
4
|
+
export function newAjv() {
|
|
5
|
+
const ajv = new Ajv2020();
|
|
6
|
+
// The CommonJS plugin exposes its callable default under NodeNext.
|
|
7
|
+
addFormats.default(ajv, ["uri", "date-time"]);
|
|
8
|
+
// ajv-formats has no `iri`. RFC 3987 maps an IRI to a URI by percent-encoding its non-ASCII
|
|
9
|
+
// characters, so an IRI is valid when that URI is.
|
|
10
|
+
const isUri = ajv.compile({ type: "string", format: "uri" });
|
|
11
|
+
ajv.addFormat("iri", (s) => {
|
|
12
|
+
const uri = toUri(s);
|
|
13
|
+
return uri !== undefined && isUri(uri);
|
|
14
|
+
});
|
|
15
|
+
return ajv;
|
|
16
|
+
}
|
|
17
|
+
/** The URI for an IRI, or undefined if the IRI has a character that is neither ASCII nor `ucschar`. */
|
|
18
|
+
function toUri(iri) {
|
|
19
|
+
let uri = "";
|
|
20
|
+
for (const c of iri) {
|
|
21
|
+
const cp = c.codePointAt(0);
|
|
22
|
+
if (cp < 0x80)
|
|
23
|
+
uri += c;
|
|
24
|
+
else if (isUcsChar(cp))
|
|
25
|
+
uri += encodeURIComponent(c);
|
|
26
|
+
else
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return uri;
|
|
30
|
+
}
|
|
31
|
+
/** True for a code point in RFC 3987's `ucschar`, which an IRI may carry unencoded. */
|
|
32
|
+
function isUcsChar(cp) {
|
|
33
|
+
return (cp >= 0xa0 && cp <= 0xd7ff) || (cp >= 0xf900 && cp <= 0xfdcf) ||
|
|
34
|
+
(cp >= 0xfdf0 && cp <= 0xffef) ||
|
|
35
|
+
// Planes 1 to 13, each without its last two code points, then most of plane 14.
|
|
36
|
+
(cp >= 0x10000 && cp <= 0xdfffd && (cp & 0xffff) <= 0xfffd) ||
|
|
37
|
+
(cp >= 0xe1000 && cp <= 0xefffd);
|
|
38
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://ohi.neverblink.eu/contracts/catalog-config",
|
|
4
|
+
"$ref": "#/$defs/CatalogConfig",
|
|
5
|
+
"$defs": {
|
|
6
|
+
"CatalogConfig": {
|
|
7
|
+
"title": "CatalogConfig",
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"search_url": {
|
|
11
|
+
"title": "search_url",
|
|
12
|
+
"description": "Complete HTTP search endpoint, including its collection path. Omit both search_url and query_by to use https://api.ohi.dev/search/collections/packages/documents/search. Supply both to select another catalog.",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"format": "iri"
|
|
15
|
+
},
|
|
16
|
+
"query_by": {
|
|
17
|
+
"title": "query_by",
|
|
18
|
+
"description": "Comma-separated indexed fields used for text search. Omit both query_by and search_url to use title,name,description,namespace at ohi.dev. Supply both to select another catalog.",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"pattern": "^[\\s\\S]*\\S"
|
|
21
|
+
},
|
|
22
|
+
"timeout_ms": {
|
|
23
|
+
"title": "timeout_ms",
|
|
24
|
+
"description": "Positive native request timeout in milliseconds. Omitted means 30000.",
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"minimum": 1,
|
|
27
|
+
"maximum": 2147483647
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"additionalProperties": false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"title": "Catalog connection settings",
|
|
34
|
+
"description": "Search endpoint and request timeout settings for a catalog client."
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Publication } from "./generated.js";
|
|
2
|
+
import type { CatalogConfig } from "./generated_config.js";
|
|
3
|
+
import type { CatalogError } from "./generated_error.js";
|
|
4
|
+
import type { SearchRequest } from "./generated_search_request.js";
|
|
5
|
+
import type { SearchResult } from "./generated_search.js";
|
|
6
|
+
export declare class CatalogException extends Error {
|
|
7
|
+
readonly error: CatalogError;
|
|
8
|
+
constructor(error: CatalogError, options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
/** HTTP operations. Omitting both search settings selects ohi.dev. */
|
|
11
|
+
export declare class CatalogClient {
|
|
12
|
+
private readonly config;
|
|
13
|
+
private readonly timeoutMs;
|
|
14
|
+
constructor(config?: CatalogConfig);
|
|
15
|
+
search(request: SearchRequest): Promise<SearchResult>;
|
|
16
|
+
inspect(baseUrl: string): Promise<Publication>;
|
|
17
|
+
get(url: string): Promise<Uint8Array>;
|
|
18
|
+
private request;
|
|
19
|
+
}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { newAjv } from "./ajv.js";
|
|
2
|
+
import { decodePublication } from "./publication.js";
|
|
3
|
+
import configSchema from "./catalog-config.schema.json" with { type: "json" };
|
|
4
|
+
import requestSchema from "./search-request.schema.json" with { type: "json" };
|
|
5
|
+
import resultSchema from "./search.schema.json" with { type: "json" };
|
|
6
|
+
const ajv = newAjv();
|
|
7
|
+
const validateConfig = ajv.compile(configSchema);
|
|
8
|
+
const validateRequest = ajv.compile(requestSchema);
|
|
9
|
+
const validateResult = ajv.compile(resultSchema);
|
|
10
|
+
const validateUri = ajv.compile({ type: "string", format: "uri" });
|
|
11
|
+
export class CatalogException extends Error {
|
|
12
|
+
error;
|
|
13
|
+
constructor(error, options) {
|
|
14
|
+
super(error.message, options);
|
|
15
|
+
this.error = error;
|
|
16
|
+
this.name = "CatalogException";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function httpUrl(value, operation) {
|
|
20
|
+
try {
|
|
21
|
+
if (!validateUri(value))
|
|
22
|
+
throw new TypeError("Invalid URI.");
|
|
23
|
+
const url = new URL(value);
|
|
24
|
+
if (!(url.protocol === "http:" || url.protocol === "https:") || !url.hostname || url.username || url.password) {
|
|
25
|
+
throw new TypeError("Invalid HTTP(S) URL.");
|
|
26
|
+
}
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
catch (cause) {
|
|
30
|
+
throw new CatalogException({ code: "INVALID_INPUT", operation, url: value,
|
|
31
|
+
message: "Supply an absolute HTTP(S) URL with a host and no credentials." }, { cause });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function object(value) {
|
|
35
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
}
|
|
37
|
+
function json(bytes) {
|
|
38
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
39
|
+
}
|
|
40
|
+
function searchResult(bytes, page, perPage) {
|
|
41
|
+
const raw = json(bytes);
|
|
42
|
+
if (!object(raw) || "grouped_hits" in raw || !Array.isArray(raw.hits) || !object(raw.request_params)) {
|
|
43
|
+
throw new Error("Expected an ungrouped search response with hits and request_params.");
|
|
44
|
+
}
|
|
45
|
+
const result = {
|
|
46
|
+
hits: raw.hits.map((hit) => {
|
|
47
|
+
if (!object(hit) || !object(hit.document))
|
|
48
|
+
throw new Error("Expected a search hit document.");
|
|
49
|
+
return hit.document;
|
|
50
|
+
}),
|
|
51
|
+
total: raw.found,
|
|
52
|
+
page: raw.page,
|
|
53
|
+
per_page: raw.request_params.per_page,
|
|
54
|
+
search_cutoff: raw.search_cutoff,
|
|
55
|
+
...(raw.facet_counts === undefined ? {} : { facet_counts: raw.facet_counts }),
|
|
56
|
+
};
|
|
57
|
+
if (!validateResult(result))
|
|
58
|
+
throw new Error(ajv.errorsText(validateResult.errors));
|
|
59
|
+
if (!Number.isSafeInteger(result.total) ||
|
|
60
|
+
result.facet_counts?.some(({ counts }) => counts.some(({ count }) => !Number.isSafeInteger(count)))) {
|
|
61
|
+
throw new Error("Search integers exceed the supported range.");
|
|
62
|
+
}
|
|
63
|
+
if (result.page !== page || result.per_page !== perPage || result.hits.length > perPage) {
|
|
64
|
+
throw new Error("Search response does not match the requested page and page size.");
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
...result,
|
|
68
|
+
hits: result.hits.map(({ base_url, namespace, name, version, title, description, formats, licenses, published_at, keywords }) => ({ base_url, namespace, name, version, title, description, formats, licenses, published_at,
|
|
69
|
+
...(keywords === undefined ? {} : { keywords }) })),
|
|
70
|
+
...(result.facet_counts === undefined ? {} : {
|
|
71
|
+
facet_counts: result.facet_counts.map(({ field_name, counts }) => ({ field_name, counts: counts.map(({ value, count }) => ({ value, count })) })),
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** HTTP operations. Omitting both search settings selects ohi.dev. */
|
|
76
|
+
export class CatalogClient {
|
|
77
|
+
config;
|
|
78
|
+
timeoutMs;
|
|
79
|
+
constructor(config = {}) {
|
|
80
|
+
const url = config.search_url;
|
|
81
|
+
if (!validateConfig(config)) {
|
|
82
|
+
throw new CatalogException({ code: "INVALID_INPUT", operation: "CONFIGURE",
|
|
83
|
+
...(typeof url === "string" ? { url } : {}), message: ajv.errorsText(validateConfig.errors) });
|
|
84
|
+
}
|
|
85
|
+
if ((config.search_url === undefined) !== (config.query_by === undefined)) {
|
|
86
|
+
throw new CatalogException({ code: "INVALID_INPUT", operation: "CONFIGURE",
|
|
87
|
+
...(url === undefined ? {} : { url }), message: "Supply both search_url and query_by, or omit both." });
|
|
88
|
+
}
|
|
89
|
+
if (url !== undefined) {
|
|
90
|
+
httpUrl(url, "CONFIGURE");
|
|
91
|
+
if (url.includes("?") || url.includes("#")) {
|
|
92
|
+
throw new CatalogException({ code: "INVALID_INPUT", operation: "CONFIGURE", url,
|
|
93
|
+
message: "Supply a search_url without a query or fragment." });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.config = {
|
|
97
|
+
...config,
|
|
98
|
+
search_url: config.search_url ?? "https://api.ohi.dev/search/collections/packages/documents/search",
|
|
99
|
+
query_by: config.query_by ?? "title,name,description,namespace",
|
|
100
|
+
};
|
|
101
|
+
this.timeoutMs = config.timeout_ms ?? 30000;
|
|
102
|
+
}
|
|
103
|
+
async search(request) {
|
|
104
|
+
const endpoint = this.config.search_url;
|
|
105
|
+
if (!validateRequest(request) ||
|
|
106
|
+
(request.page !== undefined && !Number.isSafeInteger(request.page)) ||
|
|
107
|
+
(request.max_facet_values !== undefined && !Number.isSafeInteger(request.max_facet_values))) {
|
|
108
|
+
throw new CatalogException({ code: "INVALID_INPUT", operation: "SEARCH",
|
|
109
|
+
url: endpoint, message: "Supply a valid search query and representable integer parameters." });
|
|
110
|
+
}
|
|
111
|
+
const page = request.page ?? 1;
|
|
112
|
+
const perPage = request.per_page ?? 10;
|
|
113
|
+
const url = new URL(endpoint);
|
|
114
|
+
url.searchParams.set("q", request.q);
|
|
115
|
+
url.searchParams.set("query_by", this.config.query_by);
|
|
116
|
+
url.searchParams.set("page", String(page));
|
|
117
|
+
url.searchParams.set("per_page", String(perPage));
|
|
118
|
+
if (request.filter_by !== undefined)
|
|
119
|
+
url.searchParams.set("filter_by", request.filter_by);
|
|
120
|
+
if (request.sort_by !== undefined)
|
|
121
|
+
url.searchParams.set("sort_by", request.sort_by);
|
|
122
|
+
if (request.facet_by !== undefined)
|
|
123
|
+
url.searchParams.set("facet_by", request.facet_by);
|
|
124
|
+
if (request.max_facet_values !== undefined)
|
|
125
|
+
url.searchParams.set("max_facet_values", String(request.max_facet_values));
|
|
126
|
+
const bytes = await this.request(url, "SEARCH", endpoint);
|
|
127
|
+
try {
|
|
128
|
+
return searchResult(bytes, page, perPage);
|
|
129
|
+
}
|
|
130
|
+
catch (cause) {
|
|
131
|
+
throw new CatalogException({ code: "INVALID_RESPONSE", operation: "SEARCH", url: endpoint, status: 200,
|
|
132
|
+
message: "The search response is invalid." }, { cause });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async inspect(baseUrl) {
|
|
136
|
+
const bytes = await this.request(httpUrl(baseUrl, "INSPECT"), "INSPECT", baseUrl);
|
|
137
|
+
try {
|
|
138
|
+
return decodePublication(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
139
|
+
}
|
|
140
|
+
catch (cause) {
|
|
141
|
+
throw new CatalogException({ code: "INVALID_RESPONSE", operation: "INSPECT", url: baseUrl, status: 200,
|
|
142
|
+
message: "The publication metadata is invalid." }, { cause });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async get(url) {
|
|
146
|
+
return this.request(httpUrl(url, "GET"), "GET", url);
|
|
147
|
+
}
|
|
148
|
+
async request(target, operation, url) {
|
|
149
|
+
const controller = new AbortController();
|
|
150
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
151
|
+
let response;
|
|
152
|
+
const transferError = (cause) => new CatalogException({
|
|
153
|
+
code: controller.signal.aborted ? "TIMEOUT" : "CONNECTION_ERROR", operation, url,
|
|
154
|
+
...(response === undefined ? {} : { status: response.status }),
|
|
155
|
+
message: controller.signal.aborted ? "The request exceeded timeout_ms." : "The HTTP transfer failed.",
|
|
156
|
+
}, { cause });
|
|
157
|
+
try {
|
|
158
|
+
try {
|
|
159
|
+
response = await fetch(target, { signal: controller.signal, credentials: "omit", redirect: "error" });
|
|
160
|
+
}
|
|
161
|
+
catch (cause) {
|
|
162
|
+
throw transferError(cause);
|
|
163
|
+
}
|
|
164
|
+
if (response.status !== 200) {
|
|
165
|
+
let responseJson;
|
|
166
|
+
try {
|
|
167
|
+
const value = json(new Uint8Array(await response.arrayBuffer()));
|
|
168
|
+
if (object(value))
|
|
169
|
+
responseJson = value;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// A known failure status takes precedence over an unreadable error body.
|
|
173
|
+
}
|
|
174
|
+
throw new CatalogException({ code: "HTTP_ERROR", operation, url, status: response.status,
|
|
175
|
+
...(responseJson === undefined ? {} : { response_json: responseJson }),
|
|
176
|
+
message: `HTTP ${response.status} for ${url}` });
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
180
|
+
}
|
|
181
|
+
catch (cause) {
|
|
182
|
+
throw transferError(cause);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
clearTimeout(timer);
|
|
187
|
+
controller.abort();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Ontology content in a declared format, with explicitly identified entry files. */
|
|
2
|
+
export interface Artifact {
|
|
3
|
+
/** Ontology language and syntax of the artifact. */
|
|
4
|
+
format: Format;
|
|
5
|
+
/** Origin of the artifact content. */
|
|
6
|
+
origin: ArtifactOrigin;
|
|
7
|
+
/** Permanent absolute URLs of the entry files from which this artifact's ontology is loaded. */
|
|
8
|
+
roots: string[];
|
|
9
|
+
/** SHA-256 of the final immutable file bytes, before HTTP content encoding, as exactly 64 lowercase hexadecimal characters. */
|
|
10
|
+
sha256: string;
|
|
11
|
+
/** Byte length of the final immutable artifact file, before HTTP content encoding. Measured from the same bytes as sha256. */
|
|
12
|
+
size_bytes: number;
|
|
13
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
14
|
+
url: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** A reference to an exact immutable publication required by this publication. */
|
|
18
|
+
export interface Dependency {
|
|
19
|
+
/** Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename. */
|
|
20
|
+
base_url: string;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** One immutable release of one ontology, including its metadata, artifacts and dependencies. Package, publication and release refer to the same entity. */
|
|
24
|
+
export interface Publication {
|
|
25
|
+
/** Available artifacts of this ontology. Each artifact URL occurs once. Multiple artifacts may share a format. */
|
|
26
|
+
artifacts: Artifact[];
|
|
27
|
+
/** Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename. */
|
|
28
|
+
base_url: string;
|
|
29
|
+
/** Complete set of direct and indirect runtime dependency publications, excluding this publication. Each base_url occurs once. An empty list means this publication has no runtime dependencies. */
|
|
30
|
+
dependencies: Dependency[];
|
|
31
|
+
/** Short description of the ontology's domain and intended use. */
|
|
32
|
+
description: string;
|
|
33
|
+
/** Keywords describing the ontology's subject. An empty list means no keywords are provided. */
|
|
34
|
+
keywords: string[];
|
|
35
|
+
/** 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. */
|
|
36
|
+
licenses: string[];
|
|
37
|
+
/** Short catalog identifier, qualified by namespace. The namespace/name pair identifies the same ontology across releases. URLs must not be derived from this identifier. */
|
|
38
|
+
name: string;
|
|
39
|
+
/** Namespace qualifying the ontology name, such as w3c in w3c/prov-o. */
|
|
40
|
+
namespace: string;
|
|
41
|
+
/** Optional preferred primary RDF term namespace. Preserve the complete value including any trailing delimiter. Not the catalog namespace and not necessarily the ontology IRI. */
|
|
42
|
+
namespace_iri?: string;
|
|
43
|
+
/** Optional abbreviation for namespace_iri, without whitespace or a colon. Requires namespace_iri. This constraint does not certify prefix syntax for every ontology language. */
|
|
44
|
+
preferred_prefix?: string;
|
|
45
|
+
/** 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. */
|
|
46
|
+
published_at: string;
|
|
47
|
+
/** Name of the upstream person or organization responsible for publishing the ontology. Not inferred from catalog namespace. */
|
|
48
|
+
publisher: string;
|
|
49
|
+
/** Metadata contract revision, independent of the ontology's version. */
|
|
50
|
+
schema_version: number;
|
|
51
|
+
/** Display title of the ontology. */
|
|
52
|
+
title: string;
|
|
53
|
+
/** Complete publication version label, including amendments. */
|
|
54
|
+
version: string;
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
/** Origin of published artifact content. */
|
|
58
|
+
export type ArtifactOrigin = "UPSTREAM" | "GENERATED";
|
|
59
|
+
/** A combination of ontology language and syntax. */
|
|
60
|
+
export type Format = "owl-turtle" | "owl-rdfxml" | "rdfs-turtle" | "linkml-yaml" | "ossie-yaml";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface CatalogConfig {
|
|
2
|
+
/** Comma-separated indexed fields used for text search. Omit both query_by and search_url to use title,name,description,namespace at ohi.dev. Supply both to select another catalog. */
|
|
3
|
+
query_by?: string;
|
|
4
|
+
/** Complete HTTP search endpoint, including its collection path. Omit both search_url and query_by to use https://api.ohi.dev/search/collections/packages/documents/search. Supply both to select another catalog. */
|
|
5
|
+
search_url?: string;
|
|
6
|
+
/** Positive native request timeout in milliseconds. Omitted means 30000. */
|
|
7
|
+
timeout_ms?: number;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface CatalogError {
|
|
2
|
+
/** Stable SDK failure category. */
|
|
3
|
+
code: CatalogErrorCode;
|
|
4
|
+
/** Human-readable explanation of the failure. */
|
|
5
|
+
message: string;
|
|
6
|
+
/** Client construction or operation that failed. */
|
|
7
|
+
operation: CatalogOperation;
|
|
8
|
+
/** Parsed JSON object from an HTTP failure, preserving nested server fields. */
|
|
9
|
+
response_json?: unknown;
|
|
10
|
+
/** HTTP response status when visible to the client. */
|
|
11
|
+
status?: number;
|
|
12
|
+
/** Original target supplied by the caller, when available. */
|
|
13
|
+
url?: string;
|
|
14
|
+
}
|
|
15
|
+
export type CatalogErrorCode = "INVALID_INPUT" | "HTTP_ERROR" | "CONNECTION_ERROR" | "TIMEOUT" | "INVALID_RESPONSE";
|
|
16
|
+
export type CatalogOperation = "CONFIGURE" | "SEARCH" | "INSPECT" | "GET";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Exact publication identity and artifact download URL, compared without normalization. */
|
|
2
|
+
export interface ArtifactSelection {
|
|
3
|
+
/** Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename. */
|
|
4
|
+
base_url: string;
|
|
5
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
6
|
+
url: string;
|
|
7
|
+
}
|
|
8
|
+
/** Exact direct selections and the complete file set supplied by the application. */
|
|
9
|
+
export interface Lock {
|
|
10
|
+
/** Complete supplied artifact download records in supplied order. Each selection must match one file by exact base_url and url. Each pair occurs once. */
|
|
11
|
+
files: LockedFile[];
|
|
12
|
+
/** Lock record revision, independent of ontology and publication schema versions. */
|
|
13
|
+
format_version: number;
|
|
14
|
+
/** Direct publication and artifact selections in supplied order. */
|
|
15
|
+
selections: ArtifactSelection[];
|
|
16
|
+
}
|
|
17
|
+
/** One artifact download identity and format. Excludes entry roots and integrity metadata. */
|
|
18
|
+
export interface LockedFile {
|
|
19
|
+
/** Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename. */
|
|
20
|
+
base_url: string;
|
|
21
|
+
/** Ontology language and syntax of the artifact. */
|
|
22
|
+
format: Format;
|
|
23
|
+
/** Permanent absolute download URL of an immutable ontology file. */
|
|
24
|
+
url: string;
|
|
25
|
+
}
|
|
26
|
+
/** A combination of ontology language and syntax. */
|
|
27
|
+
export type Format = "owl-turtle" | "owl-rdfxml" | "rdfs-turtle" | "linkml-yaml" | "ossie-yaml";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface LockError {
|
|
2
|
+
code: LockErrorCode;
|
|
3
|
+
/** Human-readable explanation of the failure. */
|
|
4
|
+
message: string;
|
|
5
|
+
operation: LockOperation;
|
|
6
|
+
/** Explicit path supplied to a file operation. Absent for text operations. */
|
|
7
|
+
path?: string;
|
|
8
|
+
}
|
|
9
|
+
export type LockErrorCode = "INVALID_LOCK" | "UNSUPPORTED_VERSION" | "STORAGE_ERROR";
|
|
10
|
+
export type LockOperation = "DECODE" | "ENCODE" | "READ" | "WRITE";
|