ochre-sdk 1.0.29 → 1.0.31
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 +3 -0
- package/dist/fetchers/item-children.d.mts +37 -0
- package/dist/fetchers/item-children.mjs +130 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/parsers/index.mjs +2 -1
- package/dist/types/index.d.mts +15 -6
- package/dist/xml/schemas.mjs +22 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,6 +52,9 @@ present and `error` is `null`; on failure, the parsed value is `null` and
|
|
|
52
52
|
controls how nested Tree or Set contents are parsed. For large recursive item
|
|
53
53
|
categories, pass `shouldOmitEmbeddedItems: true` to fetch the top-level item
|
|
54
54
|
without its embedded item hierarchy.
|
|
55
|
+
- `fetchItemChildren(uuid, options)` fetches only the direct child items for an
|
|
56
|
+
OCHRE item UUID. Passing
|
|
57
|
+
`category` lets the XQuery search only the matching OCHRE collection.
|
|
55
58
|
- `fetchItemLinks(uuid, options)` fetches items linked from a source item and
|
|
56
59
|
parses them as embedded OCHRE items.
|
|
57
60
|
- `fetchGallery(params, options)` fetches paginated resource galleries with an
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemContainerCategory, SetItemCategory, TreeItemCategory } from "../types/index.mjs";
|
|
2
|
+
import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/fetchers/item-children.d.ts
|
|
5
|
+
type FetchItemChildrenResult<TItems> = Promise<{
|
|
6
|
+
items: TItems;
|
|
7
|
+
error: null;
|
|
8
|
+
detailedError: null;
|
|
9
|
+
} | {
|
|
10
|
+
items: null;
|
|
11
|
+
error: string;
|
|
12
|
+
detailedError: string;
|
|
13
|
+
}>;
|
|
14
|
+
type ItemChildCategory<U extends ItemCategory> = U extends "tree" ? TreeItemCategory : U extends "set" ? SetItemCategory : U extends "bibliography" ? "bibliography" : U extends "concept" ? "concept" : U extends "spatialUnit" ? "spatialUnit" : U extends "period" ? "period" : U extends "resource" ? "resource" : never;
|
|
15
|
+
type ItemChildrenPayloadKind<U extends ItemCategory> = U extends "tree" | "set" ? "embedded" : "standaloneChild";
|
|
16
|
+
/**
|
|
17
|
+
* Fetches direct child items for an OCHRE item UUID without fetching parent
|
|
18
|
+
* item data.
|
|
19
|
+
*
|
|
20
|
+
* @param uuid - The UUID of the OCHRE item whose children should be fetched
|
|
21
|
+
* @param options - Fetch and parser options
|
|
22
|
+
* @param options.category - Optional parent item category. Passing it lets the XQuery search only the matching OCHRE collection.
|
|
23
|
+
* @param options.containedItemCategory - The category of items inside returned Trees/Sets to parse. Tree accepts one category; Set accepts one category or an array.
|
|
24
|
+
* @param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
|
|
25
|
+
* @param options.fetch - Custom fetch function to use instead of the default fetch
|
|
26
|
+
* @returns An object containing parsed child items
|
|
27
|
+
*/
|
|
28
|
+
declare function fetchItemChildren<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
|
|
29
|
+
category?: undefined;
|
|
30
|
+
containedItemCategory?: TContainedItemCategory;
|
|
31
|
+
}): FetchItemChildrenResult<Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, "embedded" | "standaloneChild">>>;
|
|
32
|
+
declare function fetchItemChildren<const TCategory extends ItemCategoryOption, const TChildCategory extends ItemCategory = ItemChildCategory<ItemCategoryFromOption<TCategory>>, const TContainedItemCategory extends ContainedItemCategoryOption<TChildCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
|
|
33
|
+
category: TCategory;
|
|
34
|
+
containedItemCategory?: TContainedItemCategory;
|
|
35
|
+
}): FetchItemChildrenResult<Array<Item<TChildCategory, ContainedItemCategoryFromOption<TChildCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, ItemChildrenPayloadKind<ItemCategoryFromOption<TCategory>>>>>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { fetchItemChildren };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../constants.mjs";
|
|
2
|
+
import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
|
|
3
|
+
import { iso639_3Schema, uuidSchema } from "../schemas.mjs";
|
|
4
|
+
import { restoreXMLMetadata } from "../xml/metadata.mjs";
|
|
5
|
+
import { parseLinkedItems } from "../parsers/index.mjs";
|
|
6
|
+
import { XMLItemLinksData } from "../xml/schemas.mjs";
|
|
7
|
+
import * as v from "valibot";
|
|
8
|
+
import { XMLParser } from "fast-xml-parser";
|
|
9
|
+
//#region src/fetchers/item-children.ts
|
|
10
|
+
const ITEM_COLLECTION_CATEGORIES = [
|
|
11
|
+
"tree",
|
|
12
|
+
"bibliography",
|
|
13
|
+
"concept",
|
|
14
|
+
"spatialUnit",
|
|
15
|
+
"period",
|
|
16
|
+
"person",
|
|
17
|
+
"propertyVariable",
|
|
18
|
+
"propertyValue",
|
|
19
|
+
"resource",
|
|
20
|
+
"text",
|
|
21
|
+
"set"
|
|
22
|
+
];
|
|
23
|
+
function parseLanguages(languages) {
|
|
24
|
+
const parsedLanguages = [];
|
|
25
|
+
for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
|
|
26
|
+
return parsedLanguages;
|
|
27
|
+
}
|
|
28
|
+
function isRecord(value) {
|
|
29
|
+
return typeof value === "object" && value !== null;
|
|
30
|
+
}
|
|
31
|
+
function collectContentLanguages(value, languages) {
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
for (const item of value) collectContentLanguages(item, languages);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!isRecord(value)) return;
|
|
37
|
+
const content = value.content;
|
|
38
|
+
if (Array.isArray(content)) for (const contentItem of content) {
|
|
39
|
+
if (!isRecord(contentItem)) continue;
|
|
40
|
+
const language = contentItem.lang;
|
|
41
|
+
if (typeof language === "string" && language !== "zxx") languages.add(language);
|
|
42
|
+
}
|
|
43
|
+
for (const child of Object.values(value)) collectContentLanguages(child, languages);
|
|
44
|
+
}
|
|
45
|
+
function resolveItemChildrenLanguages(data, requestedLanguages) {
|
|
46
|
+
if (requestedLanguages.length > 0) return requestedLanguages;
|
|
47
|
+
const languages = /* @__PURE__ */ new Set();
|
|
48
|
+
collectContentLanguages(data.result.ochre.items, languages);
|
|
49
|
+
return languages.size > 0 ? [...languages] : [...DEFAULT_LANGUAGES];
|
|
50
|
+
}
|
|
51
|
+
function buildXQuery(uuid, category) {
|
|
52
|
+
const categories = category == null ? ITEM_COLLECTION_CATEGORIES : typeof category === "string" ? [category] : category;
|
|
53
|
+
const collectionQueries = [];
|
|
54
|
+
for (const possibleCategory of categories) collectionQueries.push(`cts:search(fn:collection("ochre/${possibleCategory}")/ochre, $uuid-query)`);
|
|
55
|
+
return `xquery version "1.0-ml";
|
|
56
|
+
|
|
57
|
+
declare function local:item-children($nodes as node()*) as node()* {
|
|
58
|
+
for $node in $nodes
|
|
59
|
+
return
|
|
60
|
+
if (local-name($node) = "heading")
|
|
61
|
+
then local:item-children($node/*)
|
|
62
|
+
else $node
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let $uuid := ${stringLiteral(uuid)}
|
|
66
|
+
let $uuid-query := cts:element-attribute-value-query(xs:QName("ochre"), xs:QName("uuid"), $uuid, "exact")
|
|
67
|
+
let $ochre := (
|
|
68
|
+
${collectionQueries.join(",\n ")}
|
|
69
|
+
)[1]
|
|
70
|
+
let $item := (
|
|
71
|
+
$ochre/tree,
|
|
72
|
+
$ochre/bibliography,
|
|
73
|
+
$ochre/concept,
|
|
74
|
+
$ochre/spatialUnit,
|
|
75
|
+
$ochre/period,
|
|
76
|
+
$ochre/person,
|
|
77
|
+
$ochre/propertyVariable,
|
|
78
|
+
$ochre/propertyValue,
|
|
79
|
+
$ochre/resource,
|
|
80
|
+
$ochre/text,
|
|
81
|
+
$ochre/set
|
|
82
|
+
)[1]
|
|
83
|
+
let $category := local-name($item)
|
|
84
|
+
let $children :=
|
|
85
|
+
if (empty($item)) then ()
|
|
86
|
+
else if ($category = ("tree", "set")) then local:item-children($item/items/*)
|
|
87
|
+
else if ($category = "bibliography") then $item/bibliography
|
|
88
|
+
else if ($category = "concept") then $item/concept
|
|
89
|
+
else if ($category = "spatialUnit") then $item/spatialUnit
|
|
90
|
+
else if ($category = "period") then $item/period
|
|
91
|
+
else if ($category = "resource") then $item/resource
|
|
92
|
+
else ()
|
|
93
|
+
return
|
|
94
|
+
<ochre>
|
|
95
|
+
<items>{$children}</items>
|
|
96
|
+
</ochre>`;
|
|
97
|
+
}
|
|
98
|
+
async function fetchItemChildren(uuid, options) {
|
|
99
|
+
try {
|
|
100
|
+
const parsedUuid = v.parse(uuidSchema, uuid);
|
|
101
|
+
const requestedLanguages = options?.languages == null ? [] : parseLanguages(options.languages);
|
|
102
|
+
const response = await (options?.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: buildXQuery(parsedUuid, options?.category),
|
|
105
|
+
headers: { "Content-Type": "application/xquery" }
|
|
106
|
+
});
|
|
107
|
+
if (!response.ok) throw new Error("Failed to fetch OCHRE item children", { cause: response.statusText });
|
|
108
|
+
const dataRaw = await response.text();
|
|
109
|
+
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
110
|
+
const { success, issues, output } = v.safeParse(XMLItemLinksData, data);
|
|
111
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE item children", issues);
|
|
112
|
+
restoreXMLMetadata(output, data);
|
|
113
|
+
const languages = resolveItemChildrenLanguages(output, requestedLanguages);
|
|
114
|
+
return {
|
|
115
|
+
items: parseLinkedItems(output.result.ochre.items, {
|
|
116
|
+
containedItemCategory: options?.containedItemCategory,
|
|
117
|
+
languages
|
|
118
|
+
}),
|
|
119
|
+
error: null,
|
|
120
|
+
detailedError: null
|
|
121
|
+
};
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return {
|
|
124
|
+
items: null,
|
|
125
|
+
...getErrorOutput(error, "Unknown error")
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
export { fetchItemChildren };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { MultilingualOptions, MultilingualString, MultilingualStringEntries, Mul
|
|
|
2
2
|
import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebAccordionItem, WebBlock, WebBlockByLayout, WebBlockItem, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType } from "./types/website.mjs";
|
|
3
3
|
import { AnyBibliography, AnyConcept, AnyItem, AnyPeriod, AnyPerson, AnyPropertyValue, AnyPropertyVariable, AnyResource, AnySet, AnySpatialUnit, AnyText, AnyTree, BaseItem, BaseItemLink, BelongsTo, Bibliography, BibliographyEntryInfo, BibliographyItemLink, BibliographySourceDocument, Concept, ConceptItemLink, ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Context, ContextItem, ContextItemCategory, ContextNode, Coordinates, CoordinatesSource, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemCategoryFromOption, ItemCategoryOption, ItemCategoryWithEmbeddedItems, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyRelation, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink } from "./types/index.mjs";
|
|
4
4
|
import { fetchGallery } from "./fetchers/gallery.mjs";
|
|
5
|
+
import { fetchItemChildren } from "./fetchers/item-children.mjs";
|
|
5
6
|
import { fetchItemLinks } from "./fetchers/item-links.mjs";
|
|
6
7
|
import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
|
|
7
8
|
import { fetchSetItems } from "./fetchers/set/items.mjs";
|
|
@@ -10,4 +11,4 @@ import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
|
|
|
10
11
|
import { fetchWebsite } from "./fetchers/website.mjs";
|
|
11
12
|
import { PropertyOptions, filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels } from "./getters.mjs";
|
|
12
13
|
import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
|
|
13
|
-
export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemCategoryFromOption, type ItemCategoryOption, type ItemCategoryWithEmbeddedItems, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Property, type PropertyLike, PropertyOptions, type PropertyRelation, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebAccordionItem, type WebBlock, type WebBlockByLayout, type WebBlockItem, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
|
14
|
+
export { type AccordionWebBlock, type AnyBibliography, type AnyConcept, type AnyItem, type AnyPeriod, type AnyPerson, type AnyPropertyValue, type AnyPropertyVariable, type AnyResource, type AnySet, type AnySpatialUnit, type AnyText, type AnyTree, type BaseItem, type BaseItemLink, type BelongsTo, type Bibliography, type BibliographyEntryInfo, type BibliographyItemLink, type BibliographySourceDocument, type Concept, type ConceptItemLink, type ContainedItemCategory, type ContainedItemCategoryFromOption, type ContainedItemCategoryOption, type Context, type ContextItem, type ContextItemCategory, type ContextNode, type ContextTree, type ContextTreeFilterLevel, type ContextTreeLevel, type ContextTreeLevelItem, type Coordinates, type CoordinatesSource, DEFAULT_PAGE_SIZE, type DictionaryUnitItemLink, type EmbeddedBibliography, type EmbeddedConcept, type EmbeddedItem, type EmbeddedPeriod, type EmbeddedPerson, type EmbeddedPropertyValue, type EmbeddedPropertyVariable, type EmbeddedResource, type EmbeddedSet, type EmbeddedSpatialUnit, type EmbeddedText, type EmbeddedTree, type Event, type Gallery, type Heading, type HeadingItemCategory, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type Item, type ItemCategory, type ItemCategoryFromOption, type ItemCategoryOption, type ItemCategoryWithEmbeddedItems, type ItemContainerCategory, type ItemLink, type ItemLinkCategory, type ItemLinks, type ItemPayloadKind, type ItemProperty, type ItemWithoutEmbeddedItems, type LanguageCodes, type License, type Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, type Note, type Observation, type Period, type PeriodItemLink, type Person, type PersonItemLink, type Property, type PropertyLike, PropertyOptions, type PropertyRelation, type PropertyValue, type PropertyValueContent, type PropertyValueDataType, type PropertyValueItemLink, type PropertyValueQueryItem, type PropertyVariable, type PropertyVariableItemLink, type Query, type QueryGroup, type QueryLeaf, type QueryablePropertyValueDataType, type RecursiveItemCategory, type Resource, type ResourceItemLink, type Scope, type Section, type Set, type SetAttributeValueQueryItem, type SetBibliography, type SetConcept, type SetItem, type SetItemCategory, type SetItemLink, type SetItemProperty, type SetItemSimplifiedProperty, type SetItemsSort, type SetItemsSortDirection, type SetPeriod, type SetResource, type SetSpatialUnit, type SetTree, type SimplifiedProperty, type SpatialUnit, type SpatialUnitItemLink, type Style, type StylesheetCategory, type StylesheetItem, type Text, type TextItemLink, type TopLevelItem, type Tree, type TreeItemCategory, type TreeItemLink, type WebAccordionItem, type WebBlock, type WebBlockByLayout, type WebBlockItem, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebTitle, type Webpage, type Website, type WebsiteMetadata, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
package/dist/index.mjs
CHANGED
|
@@ -2,10 +2,11 @@ import { filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, ge
|
|
|
2
2
|
import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
|
|
3
3
|
import { MultilingualString } from "./parsers/multilingual.mjs";
|
|
4
4
|
import { fetchGallery } from "./fetchers/gallery.mjs";
|
|
5
|
+
import { fetchItemChildren } from "./fetchers/item-children.mjs";
|
|
5
6
|
import { fetchItemLinks } from "./fetchers/item-links.mjs";
|
|
6
7
|
import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
|
|
7
8
|
import { fetchSetItems } from "./fetchers/set/items.mjs";
|
|
8
9
|
import { fetchSetPropertyValues } from "./fetchers/set/property-values.mjs";
|
|
9
10
|
import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
|
|
10
11
|
import { fetchWebsite } from "./fetchers/website.mjs";
|
|
11
|
-
export { DEFAULT_PAGE_SIZE, MultilingualString, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
|
12
|
+
export { DEFAULT_PAGE_SIZE, MultilingualString, defineLanguages, fetchGallery, fetchItem, fetchItemChildren, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, fetchWebsiteMetadata, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
package/dist/parsers/index.mjs
CHANGED
|
@@ -1108,7 +1108,8 @@ function parsePerson(rawPerson, options) {
|
|
|
1108
1108
|
periods: parsePeriodList(rawPerson.periods, options),
|
|
1109
1109
|
links: parseLinks(rawPerson.links, options),
|
|
1110
1110
|
notes: parseNotes(rawPerson.notes, options),
|
|
1111
|
-
properties: parseProperties(rawPerson.properties, options)
|
|
1111
|
+
properties: parseProperties(rawPerson.properties, options),
|
|
1112
|
+
bibliographies: parseBibliographyList(rawPerson.bibliographies, options)
|
|
1112
1113
|
};
|
|
1113
1114
|
}
|
|
1114
1115
|
function parsePropertyVariable(rawPropertyVariable, options) {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -95,7 +95,15 @@ type BelongsTo = {
|
|
|
95
95
|
uuid: string;
|
|
96
96
|
abbreviation: string;
|
|
97
97
|
};
|
|
98
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Parsed item payload context.
|
|
100
|
+
*
|
|
101
|
+
* Direct children of standalone non-Tree items are shallow. Items parsed from
|
|
102
|
+
* Trees still use "embedded" and can expose recursive descendants.
|
|
103
|
+
*/
|
|
104
|
+
type ItemPayloadKind = "topLevel" | "embedded" | "standaloneChild";
|
|
105
|
+
type RecursiveChildPayloadKind<U extends ItemPayloadKind> = U extends "topLevel" ? "standaloneChild" : "embedded";
|
|
106
|
+
type RecursiveItemChildren<U extends ItemPayloadKind, V> = U extends "standaloneChild" ? Array<never> : Array<V>;
|
|
99
107
|
type ItemEnvelopeFields<T extends LanguageCodes, U extends ItemPayloadKind> = U extends "topLevel" ? {
|
|
100
108
|
belongsTo: BelongsTo;
|
|
101
109
|
metadata: Metadata<T>;
|
|
@@ -528,6 +536,7 @@ type Person<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadKind =
|
|
|
528
536
|
links: ItemLinks<T>;
|
|
529
537
|
notes: Array<Note<T>>;
|
|
530
538
|
properties: Array<Property<T>>;
|
|
539
|
+
bibliographies: Array<Bibliography<T, "embedded">>;
|
|
531
540
|
}>;
|
|
532
541
|
/**
|
|
533
542
|
* Period in OCHRE
|
|
@@ -539,7 +548,7 @@ type Period<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadKind =
|
|
|
539
548
|
notes: Array<Note<T>>;
|
|
540
549
|
properties: Array<Property<T>>;
|
|
541
550
|
bibliographies: Array<Bibliography<T, "embedded">>;
|
|
542
|
-
items:
|
|
551
|
+
items: RecursiveItemChildren<U, Period<T, RecursiveChildPayloadKind<U>>>;
|
|
543
552
|
}>;
|
|
544
553
|
/**
|
|
545
554
|
* Bibliography in OCHRE
|
|
@@ -563,7 +572,7 @@ type Bibliography<T extends LanguageCodes = LanguageCodes, U extends ItemPayload
|
|
|
563
572
|
notes: Array<Note<T>>;
|
|
564
573
|
properties: Array<Property<T>>;
|
|
565
574
|
bibliographies: Array<Bibliography<T, "embedded">>;
|
|
566
|
-
items:
|
|
575
|
+
items: RecursiveItemChildren<U, Bibliography<T, RecursiveChildPayloadKind<U>>>;
|
|
567
576
|
} & ({
|
|
568
577
|
type: "zotero";
|
|
569
578
|
zoteroId: string;
|
|
@@ -578,7 +587,7 @@ type Concept<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadKind
|
|
|
578
587
|
image: Image<T> | null;
|
|
579
588
|
interpretations: Array<Interpretation<T>>;
|
|
580
589
|
coordinates: Array<Coordinates<T>>;
|
|
581
|
-
items:
|
|
590
|
+
items: RecursiveItemChildren<U, Concept<T, RecursiveChildPayloadKind<U>>>;
|
|
582
591
|
}>;
|
|
583
592
|
/**
|
|
584
593
|
* Interpretation in OCHRE
|
|
@@ -607,7 +616,7 @@ type SpatialUnit<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadK
|
|
|
607
616
|
} | null;
|
|
608
617
|
observations: Array<Observation<T>>;
|
|
609
618
|
bibliographies: Array<Bibliography<T, "embedded">>;
|
|
610
|
-
items:
|
|
619
|
+
items: RecursiveItemChildren<U, SpatialUnit<T, RecursiveChildPayloadKind<U>>>;
|
|
611
620
|
}>;
|
|
612
621
|
/**
|
|
613
622
|
* Observation in OCHRE
|
|
@@ -663,7 +672,7 @@ type Resource<T extends LanguageCodes = LanguageCodes, U extends ItemPayloadKind
|
|
|
663
672
|
notes: Array<Note<T>>;
|
|
664
673
|
properties: Array<Property<T>>;
|
|
665
674
|
bibliographies: Array<Bibliography<T, "embedded">>;
|
|
666
|
-
items:
|
|
675
|
+
items: RecursiveItemChildren<U, Resource<T, RecursiveChildPayloadKind<U>>>;
|
|
667
676
|
} & (U extends "topLevel" ? {
|
|
668
677
|
view: Webpage<T> | null;
|
|
669
678
|
} : unknown)>;
|
package/dist/xml/schemas.mjs
CHANGED
|
@@ -561,7 +561,8 @@ const XMLPerson = v.object({
|
|
|
561
561
|
periods: v.optional(v.object({ period: v.array(XMLPeriod) })),
|
|
562
562
|
links: v.optional(v.lazy(() => XMLLink)),
|
|
563
563
|
notes: v.optional(v.object({ note: v.array(XMLNote) })),
|
|
564
|
-
properties: v.optional(v.object({ property: v.array(XMLProperty) }))
|
|
564
|
+
properties: v.optional(v.object({ property: v.array(XMLProperty) })),
|
|
565
|
+
bibliographies: v.optional(v.object({ bibliography: v.array(XMLBibliography) }))
|
|
565
566
|
}, "XMLPerson: Shape error");
|
|
566
567
|
const XMLPropertyValue = v.object({
|
|
567
568
|
...XMLBaseItem.entries,
|
|
@@ -784,6 +785,25 @@ const XMLDataItem = v.union([
|
|
|
784
785
|
v.object({ text: v.array(XMLText) }, "XMLDataItem: text is array of XMLText"),
|
|
785
786
|
v.object({ set: v.array(XMLSet) }, "XMLDataItem: set is array of XMLSet")
|
|
786
787
|
], "XMLDataItem: Shape error");
|
|
788
|
+
const XMLTopLevelDataItem = v.pipe(XMLDataItem, v.check((dataItem) => {
|
|
789
|
+
if ("tree" in dataItem) return true;
|
|
790
|
+
if ("bibliography" in dataItem) {
|
|
791
|
+
for (const bibliography of dataItem.bibliography) for (const child of bibliography.bibliography ?? []) if ((child.bibliography?.length ?? 0) > 0) return false;
|
|
792
|
+
}
|
|
793
|
+
if ("concept" in dataItem) {
|
|
794
|
+
for (const concept of dataItem.concept) for (const child of concept.concept ?? []) if ((child.concept?.length ?? 0) > 0) return false;
|
|
795
|
+
}
|
|
796
|
+
if ("spatialUnit" in dataItem) {
|
|
797
|
+
for (const spatialUnit of dataItem.spatialUnit) for (const child of spatialUnit.spatialUnit ?? []) if ((child.spatialUnit?.length ?? 0) > 0) return false;
|
|
798
|
+
}
|
|
799
|
+
if ("period" in dataItem) {
|
|
800
|
+
for (const period of dataItem.period) for (const child of period.period ?? []) if ((child.period?.length ?? 0) > 0) return false;
|
|
801
|
+
}
|
|
802
|
+
if ("resource" in dataItem) {
|
|
803
|
+
for (const resource of dataItem.resource) for (const child of resource.resource ?? []) if ((child.resource?.length ?? 0) > 0) return false;
|
|
804
|
+
}
|
|
805
|
+
return true;
|
|
806
|
+
}, "XMLDataItem: standalone recursive item children cannot contain nested recursive children"));
|
|
787
807
|
const XMLItemLinks = v.object({
|
|
788
808
|
payload: v.optional(v.string("XMLItemLinks: payload is string and optional")),
|
|
789
809
|
tree: v.optional(v.array(XMLTree, "XMLItemLinks: tree is array of XMLTree")),
|
|
@@ -837,7 +857,7 @@ const XMLData = v.object({ result: v.object({ ochre: v.intersect([v.object({
|
|
|
837
857
|
metadata: XMLMetadata,
|
|
838
858
|
persistentUrl: v.optional(v.pipe(v.string("XMLData: persistentUrl is string and optional"), v.url("XMLData: persistentUrl is not a valid URL"))),
|
|
839
859
|
languages: v.optional(v.string("XMLData: languages is string and optional"))
|
|
840
|
-
}, "XMLData: ochre is object with uuid, belongsTo, uuidBelongsTo, publicationDateTime, metadata, and languages"),
|
|
860
|
+
}, "XMLData: ochre is object with uuid, belongsTo, uuidBelongsTo, publicationDateTime, metadata, and languages"), XMLTopLevelDataItem]) }) }, "XMLData: Shape error");
|
|
841
861
|
const XMLWebsiteData = v.object({ result: v.object({ ochre: v.object({
|
|
842
862
|
uuid: v.pipe(v.string("XMLWebsiteData: uuid is string and required"), v.check(isPseudoUuid, "XMLWebsiteData: uuid is not a valid pseudo-UUID")),
|
|
843
863
|
belongsTo: v.string("XMLWebsiteData: belongsTo is string and required"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"prettier": "^3.8.3",
|
|
82
82
|
"tsdown": "^0.22.1",
|
|
83
83
|
"typescript": "^6.0.3",
|
|
84
|
-
"vitest": "^4.1.
|
|
84
|
+
"vitest": "^4.1.8"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"dev": "tsdown src/index.ts --watch",
|