@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.
@@ -0,0 +1,3 @@
1
+ // Generated by LinkML-Scala from https://ohi.neverblink.eu/contracts/lock-error
2
+ // DO NOT EDIT.
3
+ export {};
@@ -0,0 +1,58 @@
1
+ /** Counts for the returned values of one indexed field. */
2
+ export interface FacetCount {
3
+ /** Value counts in search-result order. */
4
+ counts: FacetValueCount[];
5
+ /** Indexed field used for this facet. */
6
+ field_name: string;
7
+ [key: string]: unknown;
8
+ }
9
+ /** A facet value and its matching-publication count. */
10
+ export interface FacetValueCount {
11
+ /** Number of matching publications for this facet value or range. */
12
+ count: number;
13
+ /** Facet value or range label. */
14
+ value: string;
15
+ [key: string]: unknown;
16
+ }
17
+ /** Summary of one immutable publication. */
18
+ export interface SearchHit {
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
+ /** Short description of the ontology's domain and intended use. */
22
+ description: string;
23
+ /** Formats of the publication's available artifacts. Each value identifies both the ontology language and serialization syntax, as in artifact.format. */
24
+ formats: Format[];
25
+ /** Keywords describing the ontology's subject. An empty list means no keywords are provided. */
26
+ keywords?: string[];
27
+ /** 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. */
28
+ licenses: string[];
29
+ /** Short catalog identifier, qualified by namespace. The namespace/name pair identifies the same ontology across releases. URLs must not be derived from this identifier. */
30
+ name: string;
31
+ /** Namespace qualifying the ontology name, such as w3c in w3c/prov-o. */
32
+ namespace: string;
33
+ /** 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. */
34
+ published_at: string;
35
+ /** Display title of the ontology. */
36
+ title: string;
37
+ /** Complete publication version label, including amendments. */
38
+ version: string;
39
+ [key: string]: unknown;
40
+ }
41
+ /** One ordered page of publication summaries, with count, effective paging information and optional facet counts. */
42
+ export interface SearchResult {
43
+ /** Facet values and counts for the query and filters, independently of hit pagination. The number of returned facet values may be limited. */
44
+ facet_counts?: FacetCount[];
45
+ /** Publication summaries in search-result order. */
46
+ hits: SearchHit[];
47
+ /** Effective one-based page for this response. */
48
+ page: number;
49
+ /** Effective requested page size, not the number of returned hits. */
50
+ per_page: number;
51
+ /** Whether search stopped early. When true, hits or total may be incomplete. */
52
+ search_cutoff: boolean;
53
+ /** Matching indexed publications after query and filters, before pagination. May be incomplete when search_cutoff is true. An exact total can exceed the retrieval window. */
54
+ total: number;
55
+ [key: string]: unknown;
56
+ }
57
+ /** A combination of ontology language and syntax. */
58
+ export type Format = "owl-turtle" | "owl-rdfxml" | "rdfs-turtle" | "linkml-yaml" | "ossie-yaml";
@@ -0,0 +1,3 @@
1
+ // Generated by LinkML-Scala from https://ohi.neverblink.eu/contracts/search
2
+ // DO NOT EDIT.
3
+ export {};
@@ -0,0 +1,17 @@
1
+ /** Query and options for retrieving one page of ontology publications. */
2
+ export interface SearchRequest {
3
+ /** Typesense facet expression over facetable fields. */
4
+ facet_by?: string;
5
+ /** Typesense filter expression over filterable fields. */
6
+ filter_by?: string;
7
+ /** Maximum values returned per facet. Omitted uses the backend default. */
8
+ max_facet_values?: number;
9
+ /** One-based page number. Omitted means 1. */
10
+ page?: number;
11
+ /** Maximum hits requested for this page, from 1 through 250. Omitted means 10. */
12
+ per_page?: number;
13
+ /** Text query over the configured search fields. Use the wildcard * for browsing. */
14
+ q: string;
15
+ /** Typesense sort expression. Omitted preserves default search ordering. */
16
+ sort_by?: string;
17
+ }
@@ -0,0 +1,3 @@
1
+ // Generated by LinkML-Scala from https://ohi.neverblink.eu/contracts/search-request
2
+ // DO NOT EDIT.
3
+ export {};
@@ -0,0 +1,10 @@
1
+ export { CatalogClient, CatalogException } from "./catalog.js";
2
+ export { decodePublication } from "./publication.js";
3
+ export { decodeLock, encodeLock, LockException } from "./lock.js";
4
+ export type { Lock, ArtifactSelection, LockedFile } from "./generated_lock.js";
5
+ export type * from "./generated_lock_error.js";
6
+ export type * from "./generated.js";
7
+ export type * from "./generated_config.js";
8
+ export type * from "./generated_error.js";
9
+ export type { FacetCount, FacetValueCount, SearchHit, SearchResult } from "./generated_search.js";
10
+ export type * from "./generated_search_request.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { CatalogClient, CatalogException } from "./catalog.js";
2
+ export { decodePublication } from "./publication.js";
3
+ export { decodeLock, encodeLock, LockException } from "./lock.js";
package/dist/lock.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Lock } from "./generated_lock.js";
2
+ import type { LockError } from "./generated_lock_error.js";
3
+ export declare class LockException extends Error {
4
+ readonly error: LockError;
5
+ constructor(error: LockError, options?: ErrorOptions);
6
+ }
7
+ /** Validate and decode a supplied lock without inspecting publications or retrieving files.
8
+ * Throws LockException for invalid records or unsupported revisions.
9
+ */
10
+ export declare function decodeLock(text: string): Lock;
11
+ /** Validate and encode the complete supplied lock, preserving strings and array order.
12
+ * Throws LockException for invalid records or unsupported revisions.
13
+ */
14
+ export declare function encodeLock(lock: Lock): string;
package/dist/lock.js ADDED
@@ -0,0 +1,62 @@
1
+ import { newAjv } from "./ajv.js";
2
+ import schema from "./lock.schema.json" with { type: "json" };
3
+ const ajv = newAjv();
4
+ const validate = ajv.compile(schema);
5
+ export class LockException extends Error {
6
+ error;
7
+ constructor(error, options) {
8
+ super(error.message, options);
9
+ this.error = error;
10
+ this.name = "LockException";
11
+ }
12
+ }
13
+ function pair({ base_url, url }) {
14
+ return JSON.stringify([base_url, url]);
15
+ }
16
+ function uniquePairs(records, field) {
17
+ const pairs = new Set(records.map(pair));
18
+ if (pairs.size !== records.length)
19
+ throw new Error(`${field} contains a repeated (base_url, url) pair.`);
20
+ return pairs;
21
+ }
22
+ function checkedLock(data, operation) {
23
+ if (typeof data === "object" && data !== null && !Array.isArray(data) &&
24
+ "format_version" in data && Number.isInteger(data.format_version) && data.format_version !== 1) {
25
+ throw new LockException({ code: "UNSUPPORTED_VERSION", operation,
26
+ message: `Unsupported lock revision ${data.format_version}. Supply revision 1 or use a reader supporting this revision.` });
27
+ }
28
+ try {
29
+ if (!validate(data))
30
+ throw new Error(ajv.errorsText(validate.errors));
31
+ const selections = uniquePairs(data.selections, "selections");
32
+ const files = uniquePairs(data.files, "files");
33
+ if ([...selections].some((selection) => !files.has(selection))) {
34
+ throw new Error("Every selection must have a corresponding file record.");
35
+ }
36
+ return data;
37
+ }
38
+ catch (cause) {
39
+ throw new LockException({ code: "INVALID_LOCK", operation,
40
+ message: `Invalid lock. Correct the supplied record. ${cause instanceof Error ? cause.message : String(cause)}` }, { cause });
41
+ }
42
+ }
43
+ /** Validate and decode a supplied lock without inspecting publications or retrieving files.
44
+ * Throws LockException for invalid records or unsupported revisions.
45
+ */
46
+ export function decodeLock(text) {
47
+ let data;
48
+ try {
49
+ data = JSON.parse(text);
50
+ }
51
+ catch (cause) {
52
+ throw new LockException({ code: "INVALID_LOCK", operation: "DECODE",
53
+ message: "Invalid lock JSON. Supply JSON text without a leading BOM." }, { cause });
54
+ }
55
+ return checkedLock(data, "DECODE");
56
+ }
57
+ /** Validate and encode the complete supplied lock, preserving strings and array order.
58
+ * Throws LockException for invalid records or unsupported revisions.
59
+ */
60
+ export function encodeLock(lock) {
61
+ return JSON.stringify(checkedLock(lock, "ENCODE"));
62
+ }
@@ -0,0 +1,111 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://ohi.neverblink.eu/contracts/lock",
4
+ "$ref": "#/$defs/Lock",
5
+ "$defs": {
6
+ "Lock": {
7
+ "title": "Lock",
8
+ "description": "Exact direct selections and the complete file set supplied by the application.",
9
+ "type": "object",
10
+ "required": [
11
+ "format_version",
12
+ "files",
13
+ "selections"
14
+ ],
15
+ "properties": {
16
+ "format_version": {
17
+ "title": "format_version",
18
+ "description": "Lock record revision, independent of ontology and publication schema versions.",
19
+ "type": "integer",
20
+ "minimum": 1,
21
+ "maximum": 1
22
+ },
23
+ "files": {
24
+ "title": "files",
25
+ "description": "Complete supplied artifact download records in supplied order. Each selection must match one file by exact base_url and url. Each pair occurs once.",
26
+ "type": "array",
27
+ "items": {
28
+ "$ref": "#/$defs/LockedFile"
29
+ }
30
+ },
31
+ "selections": {
32
+ "title": "selections",
33
+ "description": "Direct publication and artifact selections in supplied order.",
34
+ "type": "array",
35
+ "items": {
36
+ "$ref": "#/$defs/ArtifactSelection"
37
+ }
38
+ }
39
+ },
40
+ "additionalProperties": false
41
+ },
42
+ "LockedFile": {
43
+ "title": "LockedFile",
44
+ "description": "One artifact download identity and format. Excludes entry roots and integrity metadata.",
45
+ "type": "object",
46
+ "required": [
47
+ "format",
48
+ "base_url",
49
+ "url"
50
+ ],
51
+ "properties": {
52
+ "format": {
53
+ "$ref": "#/$defs/Format",
54
+ "title": "format",
55
+ "description": "Ontology language and syntax of the artifact."
56
+ },
57
+ "base_url": {
58
+ "title": "base_url",
59
+ "description": "Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename.",
60
+ "type": "string",
61
+ "format": "iri"
62
+ },
63
+ "url": {
64
+ "title": "url",
65
+ "description": "Permanent absolute download URL of an immutable ontology file.",
66
+ "type": "string",
67
+ "format": "iri"
68
+ }
69
+ },
70
+ "additionalProperties": false
71
+ },
72
+ "ArtifactSelection": {
73
+ "title": "ArtifactSelection",
74
+ "description": "Exact publication identity and artifact download URL, compared without normalization.",
75
+ "type": "object",
76
+ "required": [
77
+ "base_url",
78
+ "url"
79
+ ],
80
+ "properties": {
81
+ "base_url": {
82
+ "title": "base_url",
83
+ "description": "Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename.",
84
+ "type": "string",
85
+ "format": "iri"
86
+ },
87
+ "url": {
88
+ "title": "url",
89
+ "description": "Permanent absolute download URL of an immutable ontology file.",
90
+ "type": "string",
91
+ "format": "iri"
92
+ }
93
+ },
94
+ "additionalProperties": false
95
+ },
96
+ "Format": {
97
+ "title": "Format",
98
+ "description": "A combination of ontology language and syntax.",
99
+ "type": "string",
100
+ "enum": [
101
+ "owl-turtle",
102
+ "owl-rdfxml",
103
+ "rdfs-turtle",
104
+ "linkml-yaml",
105
+ "ossie-yaml"
106
+ ]
107
+ }
108
+ },
109
+ "title": "Supplied complete file lock",
110
+ "description": "Exact direct selections and the complete file set supplied by the application."
111
+ }
package/dist/node.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { Lock } from "./generated_lock.js";
2
+ /** Read and validate UTF-8 JSON without a BOM.
3
+ * Rejects with LockException for read failures, invalid records or unsupported revisions.
4
+ */
5
+ export declare function readLock(path: string): Promise<Lock>;
6
+ /** Validate before staging and atomically replace the destination entry, including a symlink.
7
+ * The parent must exist. On failure, preserves the previous destination and rejects with
8
+ * LockException, reporting any temporary file that could not be removed.
9
+ */
10
+ export declare function writeLock(path: string, lock: Lock): Promise<void>;
package/dist/node.js ADDED
@@ -0,0 +1,76 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import { basename, dirname, join } from "node:path";
4
+ import { decodeLock, encodeLock, LockException } from "./lock.js";
5
+ function fileFailure(cause, operation, path, message) {
6
+ if (cause instanceof LockException) {
7
+ return new LockException({ ...cause.error, operation, path }, { cause: cause.cause ?? cause });
8
+ }
9
+ return new LockException({ code: "STORAGE_ERROR", operation, path, message }, { cause });
10
+ }
11
+ /** Read and validate UTF-8 JSON without a BOM.
12
+ * Rejects with LockException for read failures, invalid records or unsupported revisions.
13
+ */
14
+ export async function readLock(path) {
15
+ let bytes;
16
+ try {
17
+ bytes = await fs.readFile(path);
18
+ }
19
+ catch (cause) {
20
+ throw fileFailure(cause, "READ", path, "Cannot read the lock. Check the path and read permissions.");
21
+ }
22
+ let text;
23
+ try {
24
+ // Retain the BOM so the JSON parser rejects it instead of silently removing it.
25
+ text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
26
+ }
27
+ catch (cause) {
28
+ throw new LockException({ code: "INVALID_LOCK", operation: "READ", path,
29
+ message: "Invalid lock encoding. Save the file as UTF-8 without a BOM." }, { cause });
30
+ }
31
+ try {
32
+ return decodeLock(text);
33
+ }
34
+ catch (cause) {
35
+ throw fileFailure(cause, "READ", path, "Cannot decode the lock. Correct the supplied file.");
36
+ }
37
+ }
38
+ /** Validate before staging and atomically replace the destination entry, including a symlink.
39
+ * The parent must exist. On failure, preserves the previous destination and rejects with
40
+ * LockException, reporting any temporary file that could not be removed.
41
+ */
42
+ export async function writeLock(path, lock) {
43
+ let text;
44
+ try {
45
+ text = encodeLock(lock);
46
+ }
47
+ catch (cause) {
48
+ throw fileFailure(cause, "WRITE", path, "Cannot encode the lock. Correct the supplied record.");
49
+ }
50
+ let temporary;
51
+ let handle;
52
+ try {
53
+ const candidate = join(dirname(path), `.${basename(path)}.${randomUUID()}.tmp`);
54
+ handle = await fs.open(candidate, "wx");
55
+ temporary = candidate;
56
+ await handle.writeFile(text, "utf8");
57
+ await handle.close();
58
+ handle = undefined;
59
+ await fs.rename(temporary, path);
60
+ temporary = undefined;
61
+ }
62
+ catch (cause) {
63
+ if (handle)
64
+ await handle.close().catch(() => { });
65
+ let message = "Cannot replace the lock. Check the parent directory, permissions and atomic rename support.";
66
+ if (temporary) {
67
+ try {
68
+ await fs.unlink(temporary);
69
+ }
70
+ catch {
71
+ message += ` Remove the retained temporary file ${temporary}.`;
72
+ }
73
+ }
74
+ throw fileFailure(cause, "WRITE", path, message);
75
+ }
76
+ }
@@ -0,0 +1,225 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://ohi.neverblink.eu/contracts/package",
4
+ "$ref": "#/$defs/Publication",
5
+ "$defs": {
6
+ "Publication": {
7
+ "title": "Publication",
8
+ "description": "One immutable release of one ontology, including its metadata, artifacts and dependencies. Package, publication and release refer to the same entity.",
9
+ "type": "object",
10
+ "required": [
11
+ "name",
12
+ "description",
13
+ "schema_version",
14
+ "version",
15
+ "publisher",
16
+ "keywords",
17
+ "title",
18
+ "dependencies",
19
+ "published_at",
20
+ "namespace",
21
+ "licenses",
22
+ "artifacts",
23
+ "base_url"
24
+ ],
25
+ "properties": {
26
+ "name": {
27
+ "title": "name",
28
+ "description": "Short catalog identifier, qualified by namespace. The namespace/name pair identifies the same ontology across releases. URLs must not be derived from this identifier.",
29
+ "type": "string",
30
+ "pattern": "^[\\s\\S]*\\S"
31
+ },
32
+ "description": {
33
+ "title": "description",
34
+ "description": "Short description of the ontology's domain and intended use.",
35
+ "type": "string",
36
+ "pattern": "^[\\s\\S]*\\S"
37
+ },
38
+ "schema_version": {
39
+ "title": "schema_version",
40
+ "description": "Metadata contract revision, independent of the ontology's version.",
41
+ "type": "integer",
42
+ "minimum": 2,
43
+ "maximum": 2
44
+ },
45
+ "version": {
46
+ "title": "version",
47
+ "description": "Complete publication version label, including amendments.",
48
+ "type": "string",
49
+ "pattern": "^[\\s\\S]*\\S"
50
+ },
51
+ "namespace_iri": {
52
+ "title": "namespace_iri",
53
+ "description": "Optional preferred primary RDF term namespace. Preserve the complete value including any trailing delimiter. Not the catalog namespace and not necessarily the ontology IRI.",
54
+ "type": "string",
55
+ "format": "iri"
56
+ },
57
+ "publisher": {
58
+ "title": "publisher",
59
+ "description": "Name of the upstream person or organization responsible for publishing the ontology. Not inferred from catalog namespace.",
60
+ "type": "string",
61
+ "pattern": "^[\\s\\S]*\\S"
62
+ },
63
+ "keywords": {
64
+ "title": "keywords",
65
+ "description": "Keywords describing the ontology's subject. An empty list means no keywords are provided.",
66
+ "type": "array",
67
+ "items": {
68
+ "type": "string"
69
+ }
70
+ },
71
+ "title": {
72
+ "title": "title",
73
+ "description": "Display title of the ontology.",
74
+ "type": "string",
75
+ "pattern": "^[\\s\\S]*\\S"
76
+ },
77
+ "dependencies": {
78
+ "title": "dependencies",
79
+ "description": "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.",
80
+ "type": "array",
81
+ "items": {
82
+ "$ref": "#/$defs/Dependency"
83
+ }
84
+ },
85
+ "published_at": {
86
+ "title": "published_at",
87
+ "description": "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.",
88
+ "type": "string",
89
+ "format": "date-time"
90
+ },
91
+ "namespace": {
92
+ "title": "namespace",
93
+ "description": "Namespace qualifying the ontology name, such as w3c in w3c/prov-o.",
94
+ "type": "string",
95
+ "pattern": "^[\\s\\S]*\\S"
96
+ },
97
+ "licenses": {
98
+ "title": "licenses",
99
+ "description": "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.",
100
+ "type": "array",
101
+ "items": {
102
+ "type": "string",
103
+ "pattern": "^[\\s\\S]*\\S"
104
+ }
105
+ },
106
+ "artifacts": {
107
+ "title": "artifacts",
108
+ "description": "Available artifacts of this ontology. Each artifact URL occurs once. Multiple artifacts may share a format.",
109
+ "type": "array",
110
+ "minItems": 1,
111
+ "items": {
112
+ "$ref": "#/$defs/Artifact"
113
+ }
114
+ },
115
+ "preferred_prefix": {
116
+ "title": "preferred_prefix",
117
+ "description": "Optional abbreviation for namespace_iri, without whitespace or a colon. Requires namespace_iri. This constraint does not certify prefix syntax for every ontology language.",
118
+ "type": "string",
119
+ "pattern": "^[^\\s:]+(?![\\s\\S])"
120
+ },
121
+ "base_url": {
122
+ "title": "base_url",
123
+ "description": "Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename.",
124
+ "type": "string",
125
+ "format": "iri"
126
+ }
127
+ },
128
+ "additionalProperties": true
129
+ },
130
+ "Artifact": {
131
+ "title": "Artifact",
132
+ "description": "Ontology content in a declared format, with explicitly identified entry files.",
133
+ "type": "object",
134
+ "required": [
135
+ "format",
136
+ "url",
137
+ "size_bytes",
138
+ "roots",
139
+ "sha256",
140
+ "origin"
141
+ ],
142
+ "properties": {
143
+ "format": {
144
+ "$ref": "#/$defs/Format",
145
+ "title": "format",
146
+ "description": "Ontology language and syntax of the artifact."
147
+ },
148
+ "url": {
149
+ "title": "url",
150
+ "description": "Permanent absolute download URL of an immutable ontology file.",
151
+ "type": "string",
152
+ "format": "iri"
153
+ },
154
+ "size_bytes": {
155
+ "title": "size_bytes",
156
+ "description": "Byte length of the final immutable artifact file, before HTTP content encoding. Measured from the same bytes as sha256.",
157
+ "type": "integer",
158
+ "minimum": 0
159
+ },
160
+ "roots": {
161
+ "title": "roots",
162
+ "description": "Permanent absolute URLs of the entry files from which this artifact's ontology is loaded.",
163
+ "type": "array",
164
+ "minItems": 1,
165
+ "items": {
166
+ "type": "string",
167
+ "format": "iri"
168
+ }
169
+ },
170
+ "sha256": {
171
+ "title": "sha256",
172
+ "description": "SHA-256 of the final immutable file bytes, before HTTP content encoding, as exactly 64 lowercase hexadecimal characters.",
173
+ "type": "string",
174
+ "pattern": "^[0-9a-f]{64}(?![\\s\\S])"
175
+ },
176
+ "origin": {
177
+ "$ref": "#/$defs/ArtifactOrigin",
178
+ "title": "origin",
179
+ "description": "Origin of the artifact content."
180
+ }
181
+ },
182
+ "additionalProperties": true
183
+ },
184
+ "Dependency": {
185
+ "title": "Dependency",
186
+ "description": "A reference to an exact immutable publication required by this publication.",
187
+ "type": "object",
188
+ "required": [
189
+ "base_url"
190
+ ],
191
+ "properties": {
192
+ "base_url": {
193
+ "title": "base_url",
194
+ "description": "Permanent absolute URL identifying one exact immutable publication. GET this exact URL returns its publication JSON. Do not append a filename.",
195
+ "type": "string",
196
+ "format": "iri"
197
+ }
198
+ },
199
+ "additionalProperties": true
200
+ },
201
+ "ArtifactOrigin": {
202
+ "title": "ArtifactOrigin",
203
+ "description": "Origin of published artifact content.",
204
+ "type": "string",
205
+ "enum": [
206
+ "UPSTREAM",
207
+ "GENERATED"
208
+ ]
209
+ },
210
+ "Format": {
211
+ "title": "Format",
212
+ "description": "A combination of ontology language and syntax.",
213
+ "type": "string",
214
+ "enum": [
215
+ "owl-turtle",
216
+ "owl-rdfxml",
217
+ "rdfs-turtle",
218
+ "linkml-yaml",
219
+ "ossie-yaml"
220
+ ]
221
+ }
222
+ },
223
+ "title": "Publication metadata",
224
+ "description": "Metadata for one immutable ontology release, its artifacts and its dependencies."
225
+ }
@@ -0,0 +1,3 @@
1
+ import type { Publication } from "./generated.js";
2
+ /** Decode publication metadata, validating consumed fields and discarding extras. */
3
+ export declare function decodePublication(text: string): Publication;
@@ -0,0 +1,44 @@
1
+ import { newAjv } from "./ajv.js";
2
+ import schema from "./package.schema.json" with { type: "json" };
3
+ const ajv = newAjv();
4
+ const validate = ajv.compile(schema);
5
+ /** Decode publication metadata, validating consumed fields and discarding extras. */
6
+ export function decodePublication(text) {
7
+ const data = JSON.parse(text);
8
+ if (!validate(data))
9
+ throw new Error(ajv.errorsText(validate.errors));
10
+ if (data.preferred_prefix !== undefined && data.namespace_iri === undefined) {
11
+ throw new Error("preferred_prefix requires namespace_iri");
12
+ }
13
+ if (data.artifacts.some(({ size_bytes }) => !Number.isSafeInteger(size_bytes))) {
14
+ throw new Error("artifact size_bytes exceeds the supported integer range");
15
+ }
16
+ const artifactUrls = data.artifacts.map(({ url }) => url);
17
+ if (new Set(artifactUrls).size !== artifactUrls.length) {
18
+ throw new Error("artifacts must have unique URLs");
19
+ }
20
+ const dependencyUrls = data.dependencies.map(({ base_url }) => base_url);
21
+ if (new Set(dependencyUrls).size !== dependencyUrls.length) {
22
+ throw new Error("dependencies must have unique base_url values");
23
+ }
24
+ if (dependencyUrls.includes(data.base_url)) {
25
+ throw new Error("dependencies must not contain the publication itself");
26
+ }
27
+ return {
28
+ schema_version: data.schema_version,
29
+ base_url: data.base_url,
30
+ version: data.version,
31
+ namespace: data.namespace,
32
+ name: data.name,
33
+ title: data.title,
34
+ published_at: data.published_at,
35
+ publisher: data.publisher,
36
+ licenses: data.licenses,
37
+ ...(data.namespace_iri === undefined ? {} : { namespace_iri: data.namespace_iri }),
38
+ ...(data.preferred_prefix === undefined ? {} : { preferred_prefix: data.preferred_prefix }),
39
+ description: data.description,
40
+ keywords: data.keywords,
41
+ artifacts: data.artifacts.map(({ format, url, origin, roots, size_bytes, sha256 }) => ({ format, url, origin, roots, size_bytes, sha256 })),
42
+ dependencies: data.dependencies.map(({ base_url }) => ({ base_url })),
43
+ };
44
+ }