ochre-sdk 0.22.21 → 0.22.22
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/dist/index.d.mts +24 -1
- package/dist/index.mjs +94 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1288,6 +1288,29 @@ declare function fetchGallery(params: {
|
|
|
1288
1288
|
error: string;
|
|
1289
1289
|
}>;
|
|
1290
1290
|
//#endregion
|
|
1291
|
+
//#region src/utils/fetchers/item-links.d.ts
|
|
1292
|
+
/**
|
|
1293
|
+
* Fetches and parses an OCHRE item links from the OCHRE API
|
|
1294
|
+
*
|
|
1295
|
+
* @param uuid - The UUID of the OCHRE item to fetch
|
|
1296
|
+
* @param category - The category of the OCHRE item to fetch
|
|
1297
|
+
* @param itemCategories - The categories of the OCHRE linked items to fetch
|
|
1298
|
+
* @param options - The options for the fetch
|
|
1299
|
+
* @param options.fetch - The fetch function to use
|
|
1300
|
+
* @param options.version - The version of the OCHRE API to use
|
|
1301
|
+
* @returns Object containing the parsed OCHRE item links, or an error message if the fetch/parse fails
|
|
1302
|
+
*/
|
|
1303
|
+
declare function fetchItemLinks<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(uuid: string, category?: T, itemCategories?: U, options?: {
|
|
1304
|
+
fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
1305
|
+
version?: ApiVersion;
|
|
1306
|
+
}): Promise<{
|
|
1307
|
+
error: null;
|
|
1308
|
+
items: Array<Item<T, U>>;
|
|
1309
|
+
} | {
|
|
1310
|
+
error: string;
|
|
1311
|
+
items: never;
|
|
1312
|
+
}>;
|
|
1313
|
+
//#endregion
|
|
1291
1314
|
//#region src/utils/fetchers/item.d.ts
|
|
1292
1315
|
/**
|
|
1293
1316
|
* Fetches and parses an OCHRE item from the OCHRE API
|
|
@@ -1601,4 +1624,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
|
|
|
1601
1624
|
*/
|
|
1602
1625
|
declare function flattenItemProperties<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(item: Item<T, U>): Item<T, U>;
|
|
1603
1626
|
//#endregion
|
|
1604
|
-
export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValueContent, getPropertyByLabelAndValueContents, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValueContentByLabel, getPropertyValueContentByUuid, getPropertyValueContentsByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
|
1627
|
+
export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteType, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValueContent, getPropertyByLabelAndValueContents, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValueContentByLabel, getPropertyValueContentByUuid, getPropertyValueContentsByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
package/dist/index.mjs
CHANGED
|
@@ -2038,6 +2038,99 @@ async function fetchGallery(params, options) {
|
|
|
2038
2038
|
}
|
|
2039
2039
|
}
|
|
2040
2040
|
//#endregion
|
|
2041
|
+
//#region src/utils/fetchers/item-links.ts
|
|
2042
|
+
/**
|
|
2043
|
+
* Build an XQuery string to fetch item links from the OCHRE API
|
|
2044
|
+
* @param params - The parameters for the fetch
|
|
2045
|
+
* @param params.uuid - The UUID of the OCHRE item to fetch
|
|
2046
|
+
* @returns An XQuery string
|
|
2047
|
+
*/
|
|
2048
|
+
function buildXQuery$2(params) {
|
|
2049
|
+
const { uuid } = params;
|
|
2050
|
+
return `<ochre>{${`let $item-uuid := "${uuid}"
|
|
2051
|
+
|
|
2052
|
+
let $uuids :=
|
|
2053
|
+
distinct-values((
|
|
2054
|
+
|
|
2055
|
+
(: Direct links on most item categories :)
|
|
2056
|
+
fn:collection("ochre/resource")/ochre[@uuid = $item-uuid]/resource/links/*/@uuid/string(),
|
|
2057
|
+
fn:collection("ochre/bibliography")/ochre[@uuid = $item-uuid]/bibliography/links/*/@uuid/string(),
|
|
2058
|
+
fn:collection("ochre/period")/ochre[@uuid = $item-uuid]/period/links/*/@uuid/string(),
|
|
2059
|
+
fn:collection("ochre/person")/ochre[@uuid = $item-uuid]/person/links/*/@uuid/string(),
|
|
2060
|
+
fn:collection("ochre/propertyVariable")/ochre[@uuid = $item-uuid]/propertyVariable/links/*/@uuid/string(),
|
|
2061
|
+
fn:collection("ochre/propertyValue")/ochre[@uuid = $item-uuid]/propertyValue/links/*/@uuid/string(),
|
|
2062
|
+
fn:collection("ochre/text")/ochre[@uuid = $item-uuid]/text/links/*/@uuid/string(),
|
|
2063
|
+
fn:collection("ochre/tree")/ochre[@uuid = $item-uuid]/tree/links/*/@uuid/string(),
|
|
2064
|
+
fn:collection("ochre/set")/ochre[@uuid = $item-uuid]/set/links/*/@uuid/string(),
|
|
2065
|
+
|
|
2066
|
+
(: Special category structures :)
|
|
2067
|
+
fn:collection("ochre/spatialUnit")/ochre[@uuid = $item-uuid]/spatialUnit/observations/observation/links/*/@uuid/string(),
|
|
2068
|
+
fn:collection("ochre/concept")/ochre[@uuid = $item-uuid]/concept/interpretations/interpretation/links/*/@uuid/string()
|
|
2069
|
+
))
|
|
2070
|
+
|
|
2071
|
+
return
|
|
2072
|
+
<items>{(
|
|
2073
|
+
fn:collection("ochre/resource")/ochre/resource[@uuid = $uuids],
|
|
2074
|
+
fn:collection("ochre/bibliography")/ochre/bibliography[@uuid = $uuids],
|
|
2075
|
+
fn:collection("ochre/period")/ochre/period[@uuid = $uuids],
|
|
2076
|
+
fn:collection("ochre/person")/ochre/person[@uuid = $uuids],
|
|
2077
|
+
fn:collection("ochre/propertyVariable")/ochre/propertyVariable[@uuid = $uuids],
|
|
2078
|
+
fn:collection("ochre/propertyValue")/ochre/propertyValue[@uuid = $uuids],
|
|
2079
|
+
fn:collection("ochre/text")/ochre/text[@uuid = $uuids],
|
|
2080
|
+
fn:collection("ochre/tree")/ochre/tree[@uuid = $uuids],
|
|
2081
|
+
fn:collection("ochre/set")/ochre/set[@uuid = $uuids],
|
|
2082
|
+
fn:collection("ochre/spatialUnit")/ochre/spatialUnit[@uuid = $uuids],
|
|
2083
|
+
fn:collection("ochre/concept")/ochre/concept[@uuid = $uuids]
|
|
2084
|
+
)}</items>`}}</ochre>`;
|
|
2085
|
+
}
|
|
2086
|
+
/**
|
|
2087
|
+
* Fetches and parses an OCHRE item links from the OCHRE API
|
|
2088
|
+
*
|
|
2089
|
+
* @param uuid - The UUID of the OCHRE item to fetch
|
|
2090
|
+
* @param category - The category of the OCHRE item to fetch
|
|
2091
|
+
* @param itemCategories - The categories of the OCHRE linked items to fetch
|
|
2092
|
+
* @param options - The options for the fetch
|
|
2093
|
+
* @param options.fetch - The fetch function to use
|
|
2094
|
+
* @param options.version - The version of the OCHRE API to use
|
|
2095
|
+
* @returns Object containing the parsed OCHRE item links, or an error message if the fetch/parse fails
|
|
2096
|
+
*/
|
|
2097
|
+
async function fetchItemLinks(uuid, category, itemCategories, options) {
|
|
2098
|
+
try {
|
|
2099
|
+
if (options?.version != null && options.version !== 2) throw new Error("Set item queries only support API version 2");
|
|
2100
|
+
const xquery = buildXQuery$2({ uuid });
|
|
2101
|
+
const response = await (options?.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&format=json", {
|
|
2102
|
+
method: "POST",
|
|
2103
|
+
body: xquery,
|
|
2104
|
+
headers: { "Content-Type": "application/xquery" }
|
|
2105
|
+
});
|
|
2106
|
+
if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
|
|
2107
|
+
const data = await response.json();
|
|
2108
|
+
if (Array.isArray(data.result) || Object.keys(data.result).length === 0) throw new Error("Invalid OCHRE API response");
|
|
2109
|
+
const rawItems = data.result.ochre.items;
|
|
2110
|
+
const items = [];
|
|
2111
|
+
if (rawItems.resource != null) items.push(...parseResources(ensureArray(rawItems.resource)));
|
|
2112
|
+
if (rawItems.spatialUnit != null) items.push(...parseSpatialUnits(ensureArray(rawItems.spatialUnit)));
|
|
2113
|
+
if (rawItems.concept != null) items.push(...parseConcepts(ensureArray(rawItems.concept)));
|
|
2114
|
+
if (rawItems.period != null) items.push(...parsePeriods(ensureArray(rawItems.period)));
|
|
2115
|
+
if (rawItems.bibliography != null) items.push(...parseBibliographies(ensureArray(rawItems.bibliography)));
|
|
2116
|
+
if (rawItems.person != null) items.push(...parsePersons(ensureArray(rawItems.person)));
|
|
2117
|
+
if (rawItems.propertyVariable != null) items.push(...parsePropertyVariables(ensureArray(rawItems.propertyVariable)));
|
|
2118
|
+
if (rawItems.propertyValue != null) items.push(...parsePropertyValues(ensureArray(rawItems.propertyValue)));
|
|
2119
|
+
if (rawItems.text != null) items.push(...parseTexts(ensureArray(rawItems.text)));
|
|
2120
|
+
if (rawItems.set != null) for (const linkedSet of ensureArray(rawItems.set)) items.push(parseSet(linkedSet, itemCategories));
|
|
2121
|
+
if (rawItems.tree != null) for (const linkedTree of ensureArray(rawItems.tree)) items.push(parseTree(linkedTree, itemCategories));
|
|
2122
|
+
return {
|
|
2123
|
+
error: null,
|
|
2124
|
+
items
|
|
2125
|
+
};
|
|
2126
|
+
} catch (error) {
|
|
2127
|
+
return {
|
|
2128
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
2129
|
+
items: void 0
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
//#endregion
|
|
2041
2134
|
//#region src/utils/fetchers/uuid.ts
|
|
2042
2135
|
/**
|
|
2043
2136
|
* Fetches raw OCHRE data by UUID from the OCHRE API
|
|
@@ -5495,4 +5588,4 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
5495
5588
|
}
|
|
5496
5589
|
}
|
|
5497
5590
|
//#endregion
|
|
5498
|
-
export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValueContent, getPropertyByLabelAndValueContents, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValueContentByLabel, getPropertyValueContentByUuid, getPropertyValueContentsByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|
|
5591
|
+
export { DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValueContent, getPropertyByLabelAndValueContents, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValueContentByLabel, getPropertyValueContentByUuid, getPropertyValueContentsByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
|