ochre-sdk 1.0.79 → 1.1.1
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 +60 -3
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/categories.d.mts +249 -0
- package/dist/categories.mjs +259 -0
- package/dist/constants.d.mts +14 -0
- package/dist/constants.mjs +18 -1
- package/dist/errors.d.mts +23 -0
- package/dist/{utilities.mjs → errors.mjs} +33 -84
- package/dist/fetchers/gallery.mjs +15 -51
- package/dist/fetchers/item-children.mjs +20 -66
- package/dist/fetchers/item-links.mjs +26 -79
- package/dist/fetchers/item-ocr-data.d.mts +2 -2
- package/dist/fetchers/item-ocr-data.mjs +11 -15
- package/dist/fetchers/item.d.mts +0 -15
- package/dist/fetchers/item.mjs +20 -72
- package/dist/fetchers/request.d.mts +70 -0
- package/dist/fetchers/request.mjs +100 -0
- package/dist/fetchers/set/items.mjs +27 -73
- package/dist/fetchers/set/property-values.d.mts +2 -3
- package/dist/fetchers/set/property-values.mjs +96 -130
- package/dist/fetchers/website-metadata.mjs +35 -57
- package/dist/fetchers/website.d.mts +2 -3
- package/dist/fetchers/website.mjs +22 -31
- package/dist/getters.d.mts +86 -145
- package/dist/getters.mjs +136 -207
- package/dist/helpers.d.mts +0 -4
- package/dist/helpers.mjs +19 -6
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +6 -4
- package/dist/ocr.d.mts +37 -0
- package/dist/ocr.mjs +52 -0
- package/dist/parsers/helpers.d.mts +21 -1
- package/dist/parsers/helpers.mjs +26 -6
- package/dist/parsers/index.d.mts +0 -8
- package/dist/parsers/index.mjs +118 -259
- package/dist/parsers/languages.d.mts +72 -0
- package/dist/parsers/languages.mjs +132 -0
- package/dist/parsers/multilingual.d.mts +134 -58
- package/dist/parsers/multilingual.mjs +191 -143
- package/dist/parsers/property-token.d.mts +34 -0
- package/dist/parsers/property-token.mjs +29 -0
- package/dist/parsers/string.d.mts +19 -0
- package/dist/parsers/string.mjs +45 -25
- package/dist/parsers/website/bounds.d.mts +10 -0
- package/dist/parsers/website/bounds.mjs +28 -0
- package/dist/parsers/website/components.d.mts +91 -0
- package/dist/parsers/website/components.mjs +681 -0
- package/dist/parsers/website/index.d.mts +0 -7
- package/dist/parsers/website/index.mjs +92 -1153
- package/dist/parsers/website/links.d.mts +36 -0
- package/dist/parsers/website/links.mjs +58 -0
- package/dist/parsers/website/messages.d.mts +24 -0
- package/dist/parsers/website/messages.mjs +31 -0
- package/dist/parsers/website/options.d.mts +6 -0
- package/dist/parsers/website/options.mjs +114 -0
- package/dist/parsers/website/properties.d.mts +12 -0
- package/dist/parsers/website/properties.mjs +158 -0
- package/dist/parsers/website/reader.d.mts +54 -4
- package/dist/parsers/website/reader.mjs +65 -20
- package/dist/parsers/website/slug.d.mts +64 -0
- package/dist/parsers/website/slug.mjs +82 -0
- package/dist/parsers/website/styles.d.mts +28 -0
- package/dist/parsers/website/styles.mjs +103 -0
- package/dist/parsers/website/walk.d.mts +68 -0
- package/dist/parsers/website/walk.mjs +116 -0
- package/dist/query.d.mts +66 -21
- package/dist/query.mjs +178 -44
- package/dist/reflection.d.mts +64 -0
- package/dist/reflection.mjs +79 -0
- package/dist/schemas.d.mts +7 -0
- package/dist/schemas.mjs +12 -3
- package/dist/types/index.d.mts +31 -31
- package/dist/types/utilities.d.mts +9 -0
- package/dist/types/utilities.mjs +1 -0
- package/dist/types/website.d.mts +54 -58
- package/dist/xml/metadata.d.mts +16 -0
- package/dist/xml/metadata.mjs +32 -11
- package/dist/xml/schemas.d.mts +5970 -3
- package/dist/xml/schemas.mjs +43 -45
- package/dist/xml/types.d.mts +14 -30
- package/dist/xquery.d.mts +46 -0
- package/dist/xquery.mjs +66 -0
- package/package.json +3 -3
- package/dist/utilities.d.mts +0 -54
package/dist/ocr.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { stringLiteral } from "./xquery.mjs";
|
|
2
|
+
//#region src/ocr.ts
|
|
3
|
+
const ALTO_NAMESPACE = "http://www.loc.gov/standards/alto/ns-v2#";
|
|
4
|
+
/**
|
|
5
|
+
* The local names OCHRE serves OCR word elements under
|
|
6
|
+
*
|
|
7
|
+
* OCHRE varies the casing, and serves the elements both in the ALTO namespace
|
|
8
|
+
* and in no namespace at all. Every selector over the layer has to accept all
|
|
9
|
+
* of them: an `xs:QName("String")` narrowing matches 2 of the 18,446 documents
|
|
10
|
+
* carrying an OCR layer, while the ALTO-namespaced `String` matches 14,650.
|
|
11
|
+
*/
|
|
12
|
+
const OCR_WORD_LOCAL_NAMES = ["String", "string"];
|
|
13
|
+
const OCR_WORD_CASE_FOLDED_LOCAL_NAME = "string";
|
|
14
|
+
/**
|
|
15
|
+
* The name of the element wrapping an OCR layer inside an OCHRE document
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
const OCR_LAYER_ELEMENT_NAME = "ocr";
|
|
19
|
+
/**
|
|
20
|
+
* The attribute an OCR word element holds its word in
|
|
21
|
+
*
|
|
22
|
+
* The word is in the attribute rather than in the element's text content.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
const OCR_WORD_CONTENT_ATTRIBUTE = "CONTENT";
|
|
26
|
+
/**
|
|
27
|
+
* An XQuery sequence of every QName an OCR word element can carry
|
|
28
|
+
*
|
|
29
|
+
* Use with the `cts:element-*` query constructors, which need concrete QNames
|
|
30
|
+
* and cannot match on a case-folded local name the way {@link buildOcrWordPath}
|
|
31
|
+
* does. This has to stay in agreement with that path: a word element the
|
|
32
|
+
* narrowing misses is a document the search silently drops.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
const OCR_WORD_QNAMES = `(${[...OCR_WORD_LOCAL_NAMES.map((localName) => `fn:QName(${stringLiteral(ALTO_NAMESPACE)}, ${stringLiteral(localName)})`), ...OCR_WORD_LOCAL_NAMES.map((localName) => `xs:QName(${stringLiteral(localName)})`)].join(", ")})`;
|
|
36
|
+
/**
|
|
37
|
+
* Build an XQuery path selecting every OCR word element beneath a node
|
|
38
|
+
*
|
|
39
|
+
* Matches the layer and the word elements on a case-folded `local-name()`
|
|
40
|
+
* rather than a name test, because a name test silently matches nothing when
|
|
41
|
+
* OCHRE varies the casing or serves the elements in a namespace. Word elements
|
|
42
|
+
* are selected at any depth, because the hierarchy between the layer and its
|
|
43
|
+
* words is irregular and is not parsed.
|
|
44
|
+
* @param rootExpression - The XQuery expression to select from
|
|
45
|
+
* @returns The XQuery path
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
function buildOcrWordPath(rootExpression) {
|
|
49
|
+
return `${rootExpression}//*[lower-case(local-name(.)) = ${stringLiteral("ocr")}]//*[lower-case(local-name(.)) = ${stringLiteral(OCR_WORD_CASE_FOLDED_LOCAL_NAME)}][@${OCR_WORD_CONTENT_ATTRIBUTE}]`;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { OCR_LAYER_ELEMENT_NAME, OCR_WORD_CONTENT_ATTRIBUTE, OCR_WORD_QNAMES, buildOcrWordPath };
|
|
@@ -6,14 +6,34 @@ export type FetchFunction = (input: string | URL | globalThis.Request, init?: Re
|
|
|
6
6
|
export type FetchBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
|
|
7
7
|
languages?: TLanguages;
|
|
8
8
|
fetch?: FetchFunction;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
timeoutMilliseconds?: number;
|
|
9
11
|
};
|
|
10
12
|
export type FetchRuntimeOptions = FetchBaseOptions<ReadonlyArray<string>>;
|
|
11
13
|
export type FetchLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
|
|
12
14
|
export type ParserOptions<T extends ReadonlyArray<string>> = {
|
|
13
15
|
languages: T;
|
|
16
|
+
/**
|
|
17
|
+
* The language the dataset declares as its default
|
|
18
|
+
*
|
|
19
|
+
* Threaded into every {@link MultilingualString} so a read with no language
|
|
20
|
+
* resolves to the dataset's default rather than whichever language happens to
|
|
21
|
+
* come first in the payload.
|
|
22
|
+
*/
|
|
23
|
+
defaultLanguage?: T[number];
|
|
14
24
|
};
|
|
15
25
|
export declare function getParserOptions<T extends ReadonlyArray<string>>(options: ParserOptions<T>): ParserOptions<T>;
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Drop the keys whose value is undefined
|
|
28
|
+
*
|
|
29
|
+
* Constrained to `object` rather than `Record<string, unknown>`, which an
|
|
30
|
+
* interface never satisfies for want of an index signature. `Object.entries`
|
|
31
|
+
* cannot be typed precisely, so the one cast that costs is here rather than at
|
|
32
|
+
* the call site.
|
|
33
|
+
* @param object - The object to clean
|
|
34
|
+
* @returns A copy carrying only the defined keys
|
|
35
|
+
*/
|
|
36
|
+
export declare function cleanObject<T extends object>(object: T): Partial<T>;
|
|
17
37
|
export declare function parseLicense(availability: {
|
|
18
38
|
license: XMLString & {
|
|
19
39
|
target?: string;
|
package/dist/parsers/helpers.mjs
CHANGED
|
@@ -4,11 +4,25 @@ import { parseXMLContent, parseXMLString } from "./string.mjs";
|
|
|
4
4
|
//#region src/parsers/helpers.ts
|
|
5
5
|
const FALLBACK_PARSER_OPTIONS = { languages: DEFAULT_LANGUAGES };
|
|
6
6
|
function getParserOptions(options) {
|
|
7
|
-
return {
|
|
7
|
+
return {
|
|
8
|
+
languages: options.languages,
|
|
9
|
+
defaultLanguage: options.defaultLanguage
|
|
10
|
+
};
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Drop the keys whose value is undefined
|
|
14
|
+
*
|
|
15
|
+
* Constrained to `object` rather than `Record<string, unknown>`, which an
|
|
16
|
+
* interface never satisfies for want of an index signature. `Object.entries`
|
|
17
|
+
* cannot be typed precisely, so the one cast that costs is here rather than at
|
|
18
|
+
* the call site.
|
|
19
|
+
* @param object - The object to clean
|
|
20
|
+
* @returns A copy carrying only the defined keys
|
|
21
|
+
*/
|
|
9
22
|
function cleanObject(object) {
|
|
23
|
+
const entries = Object.entries(object);
|
|
10
24
|
const cleaned = {};
|
|
11
|
-
for (const [key, value] of
|
|
25
|
+
for (const [key, value] of entries) if (value !== void 0) cleaned[key] = value;
|
|
12
26
|
return cleaned;
|
|
13
27
|
}
|
|
14
28
|
function parseLicense(availability) {
|
|
@@ -29,16 +43,19 @@ function isXMLContent(value) {
|
|
|
29
43
|
function multilingualFromText(text, options) {
|
|
30
44
|
const content = {};
|
|
31
45
|
for (const language of options.languages) content[language] = text;
|
|
32
|
-
return MultilingualString.fromObject(content, options.languages);
|
|
46
|
+
return MultilingualString.fromObject(content, options.languages, { defaultLanguage: options.defaultLanguage });
|
|
33
47
|
}
|
|
34
48
|
function parseContentLike(value, options) {
|
|
35
49
|
if (value == null) return null;
|
|
36
50
|
if (typeof value === "string") return multilingualFromText(value, options);
|
|
37
51
|
if (!isXMLContent(value)) return multilingualFromText(parseXMLString(value), options);
|
|
38
|
-
return parseXMLContent(value, {
|
|
52
|
+
return parseXMLContent(value, {
|
|
53
|
+
languages: options.languages,
|
|
54
|
+
defaultLanguage: options.defaultLanguage
|
|
55
|
+
});
|
|
39
56
|
}
|
|
40
57
|
function parseRequiredContentLike(value, options) {
|
|
41
|
-
return parseContentLike(value, options) ?? MultilingualString.empty(options.languages);
|
|
58
|
+
return parseContentLike(value, options) ?? MultilingualString.empty(options.languages, { defaultLanguage: options.defaultLanguage });
|
|
42
59
|
}
|
|
43
60
|
function parseContentLikeText(value, options) {
|
|
44
61
|
return parseContentLike(value, options)?.getText().trim() ?? "";
|
|
@@ -46,7 +63,10 @@ function parseContentLikeText(value, options) {
|
|
|
46
63
|
function parseStringContent(value, options = FALLBACK_PARSER_OPTIONS) {
|
|
47
64
|
if (value == null) return "";
|
|
48
65
|
if (typeof value === "string") return value;
|
|
49
|
-
if (isXMLContent(value)) return parseXMLContent(value, {
|
|
66
|
+
if (isXMLContent(value)) return parseXMLContent(value, {
|
|
67
|
+
languages: options.languages,
|
|
68
|
+
defaultLanguage: options.defaultLanguage
|
|
69
|
+
}).getText();
|
|
50
70
|
return parseXMLString(value).text;
|
|
51
71
|
}
|
|
52
72
|
//#endregion
|
package/dist/parsers/index.d.mts
CHANGED
|
@@ -21,14 +21,6 @@ export declare function parseBibliographyList<T extends ReadonlyArray<string>>(r
|
|
|
21
21
|
bibliography: Array<XMLBibliography>;
|
|
22
22
|
} | undefined, options: ParserOptions<T>): Array<Bibliography<T, "embedded">>;
|
|
23
23
|
export declare function parsePersonList<T extends ReadonlyArray<string>>(rawPersons: Array<XMLPerson> | undefined, options: ParserOptions<T>): Array<Person<T, "embedded">>;
|
|
24
|
-
export declare function parseMetadataLanguages(rawOchre: {
|
|
25
|
-
metadata: XMLMetadata;
|
|
26
|
-
languages?: string;
|
|
27
|
-
}): Array<string>;
|
|
28
|
-
export declare function resolveLanguages<T extends ReadonlyArray<string>>(requestedLanguages: T | undefined, metadataLanguages: Array<string>): T;
|
|
29
|
-
export declare function resolveDefaultLanguage<T extends ReadonlyArray<string>>(rawOchre: {
|
|
30
|
-
metadata: XMLMetadata;
|
|
31
|
-
}, languages: T): T[number];
|
|
32
24
|
export declare function parseMetadata<T extends ReadonlyArray<string>>(rawOchre: {
|
|
33
25
|
uuidBelongsTo: string;
|
|
34
26
|
metadata: XMLMetadata;
|