ochre-sdk 1.0.11 → 1.0.13
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 -1
- package/dist/index.d.mts +36 -30
- package/dist/index.mjs +44 -7
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -47,7 +47,9 @@ present and `error` is `null`; on failure, the parsed value is `null` and
|
|
|
47
47
|
|
|
48
48
|
- `fetchItem(uuid, options)` fetches and parses a single OCHRE item. Passing
|
|
49
49
|
`category` narrows the returned TypeScript type, and `containedItemCategory`
|
|
50
|
-
controls how nested Tree or Set contents are parsed.
|
|
50
|
+
controls how nested Tree or Set contents are parsed. For large Trees or Sets,
|
|
51
|
+
pass `shouldOmitEmbeddedItems: true` to fetch the top-level item without its
|
|
52
|
+
embedded `<items>` payload.
|
|
51
53
|
- `fetchItemLinks(uuid, options)` fetches items linked from a source item and
|
|
52
54
|
parses them as embedded OCHRE items.
|
|
53
55
|
- `fetchGallery(params, options)` fetches paginated resource galleries with an
|
package/dist/index.d.mts
CHANGED
|
@@ -480,6 +480,7 @@ type WebElementComponent<T extends LanguageCodes = LanguageCodes> = {
|
|
|
480
480
|
paginationVariant: "default" | "numeric";
|
|
481
481
|
loadingVariant: "spinner" | "skeleton" | "animation" | "none";
|
|
482
482
|
imageLayout: "top" | "bottom" | "start" | "end" | null;
|
|
483
|
+
expectedItemCount: number | null;
|
|
483
484
|
isSortDisplayed: boolean;
|
|
484
485
|
isUsingQueryParams: boolean;
|
|
485
486
|
filter: {
|
|
@@ -1128,6 +1129,10 @@ type ItemLink<U extends ItemLinkCategory = ItemLinkCategory, T extends LanguageC
|
|
|
1128
1129
|
* An Item in OCHRE (can be a tree, set, bibliography, concept, spatial unit, period, person, property value, property variable, or resource)
|
|
1129
1130
|
*/
|
|
1130
1131
|
type Item<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes, W extends ItemPayloadKind = "topLevel"> = U extends ItemCategory ? U extends "tree" ? Tree<Extract<V, TreeItemCategory>, T, W> : U extends "set" ? Set<Extract<V, SetItemCategory>, T, W> : U extends "bibliography" ? Bibliography<T, W> : U extends "concept" ? Concept<T, W> : U extends "spatialUnit" ? SpatialUnit<T, W> : U extends "period" ? Period<T, W> : U extends "person" ? Person<T, W> : U extends "propertyVariable" ? PropertyVariable<T, W> : U extends "propertyValue" ? PropertyValue<T, W> : U extends "resource" ? Resource<T, W> : U extends "text" ? Text<T, W> : never : never;
|
|
1132
|
+
/**
|
|
1133
|
+
* A Tree or Set fetched without its embedded item hierarchy.
|
|
1134
|
+
*/
|
|
1135
|
+
type ItemWithoutEmbeddedItems<U extends ItemContainerCategory = ItemContainerCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes, W extends ItemPayloadKind = "topLevel"> = U extends ItemContainerCategory ? U extends "tree" ? Prettify<Omit<Tree<Extract<V, TreeItemCategory>, T, W>, "items">> : U extends "set" ? Prettify<Omit<Set<Extract<V, SetItemCategory>, T, W>, "items">> : never : never;
|
|
1131
1136
|
type TopLevelItem<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes> = Item<U, V, T, "topLevel">;
|
|
1132
1137
|
type EmbeddedItem<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes> = Item<U, V, T, "embedded">;
|
|
1133
1138
|
type AnyItem<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes> = Item<U, V, T, ItemPayloadKind>;
|
|
@@ -1584,7 +1589,21 @@ type FetchItemBaseOptions<TLanguages extends ReadonlyArray<string> | undefined =
|
|
|
1584
1589
|
languages?: TLanguages;
|
|
1585
1590
|
fetch?: FetchFunction$2;
|
|
1586
1591
|
};
|
|
1592
|
+
type FetchItemNoOmitEmbeddedItemsOption = {
|
|
1593
|
+
shouldOmitEmbeddedItems?: false;
|
|
1594
|
+
};
|
|
1587
1595
|
type FetchItemLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
|
|
1596
|
+
type FetchItemSuccess<TItem> = {
|
|
1597
|
+
item: TItem;
|
|
1598
|
+
error: null;
|
|
1599
|
+
detailedError: null;
|
|
1600
|
+
};
|
|
1601
|
+
type FetchItemError = {
|
|
1602
|
+
item: null;
|
|
1603
|
+
error: string;
|
|
1604
|
+
detailedError: string;
|
|
1605
|
+
};
|
|
1606
|
+
type FetchItemResult<TItem> = Promise<FetchItemSuccess<TItem> | FetchItemError>;
|
|
1588
1607
|
/**
|
|
1589
1608
|
* Defines a reusable languages tuple with validation and literal type inference.
|
|
1590
1609
|
*
|
|
@@ -1607,46 +1626,33 @@ declare function withLanguages<const TLanguages extends ReadonlyArray<string>>(l
|
|
|
1607
1626
|
* @param options - Required options object
|
|
1608
1627
|
* @param options.category - The category of the OCHRE item to fetch
|
|
1609
1628
|
* @param options.containedItemCategory - The category of items inside the OCHRE item to fetch. Only valid for Trees and Sets. Tree accepts one category; Set accepts one category or an array.
|
|
1629
|
+
* @param options.shouldOmitEmbeddedItems - Whether to omit the embedded `<items>` node when fetching a Tree or Set.
|
|
1610
1630
|
* @param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
|
|
1611
1631
|
* @param options.fetch - Custom fetch function to use instead of the default fetch
|
|
1612
1632
|
* @returns An object containing the parsed item
|
|
1613
1633
|
*/
|
|
1614
|
-
declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchItemBaseOptions<TLanguages> & {
|
|
1634
|
+
declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchItemBaseOptions<TLanguages> & FetchItemNoOmitEmbeddedItemsOption & {
|
|
1615
1635
|
category?: undefined;
|
|
1616
1636
|
containedItemCategory?: TContainedItemCategory;
|
|
1617
|
-
}):
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1637
|
+
}): FetchItemResult<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
|
|
1638
|
+
declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
|
|
1639
|
+
category?: undefined;
|
|
1640
|
+
containedItemCategory?: TContainedItemCategory;
|
|
1641
|
+
shouldOmitEmbeddedItems: true;
|
|
1642
|
+
}): FetchItemResult<ItemWithoutEmbeddedItems<ItemContainerCategory, ContainedItemCategoryFromOption<ItemContainerCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
|
|
1643
|
+
declare function fetchItem<const TCategory extends ItemContainerCategory, const TContainedItemCategory extends ContainedItemCategoryOption<TCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & FetchItemNoOmitEmbeddedItemsOption & {
|
|
1644
|
+
category: TCategory;
|
|
1645
|
+
containedItemCategory?: TContainedItemCategory;
|
|
1646
|
+
}): FetchItemResult<Item<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
|
|
1626
1647
|
declare function fetchItem<const TCategory extends ItemContainerCategory, const TContainedItemCategory extends ContainedItemCategoryOption<TCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
|
|
1627
1648
|
category: TCategory;
|
|
1628
1649
|
containedItemCategory?: TContainedItemCategory;
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
detailedError: null;
|
|
1633
|
-
} | {
|
|
1634
|
-
item: null;
|
|
1635
|
-
error: string;
|
|
1636
|
-
detailedError: string;
|
|
1637
|
-
}>;
|
|
1638
|
-
declare function fetchItem<const TCategory extends ItemCategory, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
|
|
1650
|
+
shouldOmitEmbeddedItems: true;
|
|
1651
|
+
}): FetchItemResult<ItemWithoutEmbeddedItems<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
|
|
1652
|
+
declare function fetchItem<const TCategory extends ItemCategory, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & FetchItemNoOmitEmbeddedItemsOption & {
|
|
1639
1653
|
category: TCategory;
|
|
1640
1654
|
containedItemCategory?: never;
|
|
1641
|
-
}):
|
|
1642
|
-
item: Item<TCategory, ContainedItemCategory<TCategory>, FetchItemLanguages<TLanguages>>;
|
|
1643
|
-
error: null;
|
|
1644
|
-
detailedError: null;
|
|
1645
|
-
} | {
|
|
1646
|
-
item: null;
|
|
1647
|
-
error: string;
|
|
1648
|
-
detailedError: string;
|
|
1649
|
-
}>;
|
|
1655
|
+
}): FetchItemResult<Item<TCategory, ContainedItemCategory<TCategory>, FetchItemLanguages<TLanguages>>>;
|
|
1650
1656
|
//#endregion
|
|
1651
1657
|
//#region src/fetchers/set/items.d.ts
|
|
1652
1658
|
type FetchFunction$1 = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
|
|
@@ -1962,4 +1968,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
|
|
|
1962
1968
|
*/
|
|
1963
1969
|
declare function flattenItemProperties<U extends ItemCategory = ItemCategory, V extends ContainedItemCategory<U> = ContainedItemCategory<U>, T extends LanguageCodes = LanguageCodes, W extends ItemPayloadKind = "topLevel">(item: Item<U, V, T, W>): FlattenedItem<Item<U, V, T, W>, T>;
|
|
1964
1970
|
//#endregion
|
|
1965
|
-
export { AccordionWebBlock, 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, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinates, CoordinatesSource, DEFAULT_PAGE_SIZE, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, LanguageCodes, License, Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyOptions, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Scope, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Style, StylesheetCategory, StylesheetItem, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
|
1971
|
+
export { AccordionWebBlock, 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, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Coordinates, CoordinatesSource, DEFAULT_PAGE_SIZE, DictionaryUnitItemLink, EmbeddedBibliography, EmbeddedConcept, EmbeddedItem, EmbeddedPeriod, EmbeddedPerson, EmbeddedPropertyValue, EmbeddedPropertyVariable, EmbeddedResource, EmbeddedSet, EmbeddedSpatialUnit, EmbeddedText, EmbeddedTree, Event, Gallery, Heading, HeadingItemCategory, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, ItemCategory, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, type MultilingualOptions, MultilingualString, type MultilingualStringEntries, type MultilingualStringEntry, type MultilingualStringInput, type MultilingualStringJSON, type MultilingualStringObject, type MultilingualStringText, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, PropertyOptions, PropertyValue, PropertyValueContent, PropertyValueDataType, PropertyValueItemLink, PropertyValueQueryItem, PropertyVariable, PropertyVariableItemLink, Query, QueryGroup, QueryLeaf, QueryablePropertyValueDataType, RecursiveItemCategory, Resource, ResourceItemLink, Scope, Section, Set, SetAttributeValueQueryItem, SetBibliography, SetConcept, SetItem, SetItemCategory, SetItemLink, SetItemProperty, SetItemSimplifiedProperty, SetItemsSort, SetItemsSortDirection, SetPeriod, SetResource, SetSpatialUnit, SetTree, SimplifiedProperty, SpatialUnit, SpatialUnitItemLink, Style, StylesheetCategory, StylesheetItem, Text, TextItemLink, TopLevelItem, Tree, TreeItemCategory, TreeItemLink, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType, defineLanguages, fetchGallery, fetchItem, fetchItemLinks, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels, withLanguages };
|
package/dist/index.mjs
CHANGED
|
@@ -4572,6 +4572,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
4572
4572
|
const variant = componentReader.valueOr("variant", "slide");
|
|
4573
4573
|
const paginationVariant = componentReader.valueOr("pagination-variant", "default");
|
|
4574
4574
|
const loadingVariant = componentReader.valueOr("loading-variant", "skeleton");
|
|
4575
|
+
const expectedItemCount = componentReader.valueOr("item-count", null);
|
|
4575
4576
|
const isUsingQueryParams = componentReader.valueOr("is-using-query-params", false);
|
|
4576
4577
|
const isFilterResultsBarDisplayed = componentReader.valueOr("filter-results-bar-displayed", false);
|
|
4577
4578
|
const isFilterInputDisplayed = componentReader.valueOr("filter-input-displayed", false);
|
|
@@ -4593,6 +4594,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
4593
4594
|
paginationVariant,
|
|
4594
4595
|
loadingVariant,
|
|
4595
4596
|
imageLayout,
|
|
4597
|
+
expectedItemCount,
|
|
4596
4598
|
isUsingQueryParams,
|
|
4597
4599
|
isSortDisplayed,
|
|
4598
4600
|
filter: {
|
|
@@ -5482,10 +5484,17 @@ function parseWebsite(data, options) {
|
|
|
5482
5484
|
function isItemContainerCategory(category) {
|
|
5483
5485
|
return category === "tree" || category === "set";
|
|
5484
5486
|
}
|
|
5487
|
+
function isItemContainer(item) {
|
|
5488
|
+
return isItemContainerCategory(item.category);
|
|
5489
|
+
}
|
|
5485
5490
|
function assertItemCategoryAllowed(category, containedItemCategory) {
|
|
5486
5491
|
if (category == null || containedItemCategory == null || isItemContainerCategory(category)) return;
|
|
5487
5492
|
throw new Error(`containedItemCategory can only be used when category is "tree" or "set"; received category "${category}"`);
|
|
5488
5493
|
}
|
|
5494
|
+
function assertShouldOmitEmbeddedItemsAllowed(category, shouldOmitEmbeddedItems) {
|
|
5495
|
+
if (!shouldOmitEmbeddedItems || category == null || isItemContainerCategory(category)) return;
|
|
5496
|
+
throw new Error(`shouldOmitEmbeddedItems can only be used when category is "tree" or "set"; received category "${category}"`);
|
|
5497
|
+
}
|
|
5489
5498
|
function normalizeFetchedCategory(category) {
|
|
5490
5499
|
switch (category) {
|
|
5491
5500
|
case "tree":
|
|
@@ -5520,6 +5529,25 @@ function inferFetchItemCategory(rawOchre) {
|
|
|
5520
5529
|
if ("set" in rawOchre) return "set";
|
|
5521
5530
|
throw new Error("Could not infer OCHRE item category", { cause: rawOchre });
|
|
5522
5531
|
}
|
|
5532
|
+
function buildOmitEmbeddedItemsXQuery(uuid) {
|
|
5533
|
+
return `xquery version "1.0-ml";
|
|
5534
|
+
|
|
5535
|
+
let $ochre := doc()/ochre[@uuid=${stringLiteral(uuid)}][1]
|
|
5536
|
+
return
|
|
5537
|
+
if (empty($ochre)) then ()
|
|
5538
|
+
else element ochre {
|
|
5539
|
+
$ochre/@*,
|
|
5540
|
+
for $node in $ochre/node()
|
|
5541
|
+
return
|
|
5542
|
+
if (local-name($node) = ("tree", "set"))
|
|
5543
|
+
then element { node-name($node) } { $node/@*, $node/node()[not(self::items)] }
|
|
5544
|
+
else $node
|
|
5545
|
+
}`;
|
|
5546
|
+
}
|
|
5547
|
+
function omitEmbeddedItems(item) {
|
|
5548
|
+
const { items: _items, ...itemWithoutEmbeddedItems } = item;
|
|
5549
|
+
return itemWithoutEmbeddedItems;
|
|
5550
|
+
}
|
|
5523
5551
|
/**
|
|
5524
5552
|
* Validate language codes while preserving literal tuple inference.
|
|
5525
5553
|
*/
|
|
@@ -5551,8 +5579,15 @@ async function fetchItem(uuid, options) {
|
|
|
5551
5579
|
try {
|
|
5552
5580
|
const parsedUuid = v.parse(uuidSchema, uuid);
|
|
5553
5581
|
assertItemCategoryAllowed(options?.category, options?.containedItemCategory);
|
|
5582
|
+
const shouldOmitEmbeddedItems = options?.shouldOmitEmbeddedItems === true;
|
|
5583
|
+
assertShouldOmitEmbeddedItemsAllowed(options?.category, shouldOmitEmbeddedItems);
|
|
5554
5584
|
const languages = options?.languages == null ? [] : parseLanguages$1(options.languages);
|
|
5555
|
-
const
|
|
5585
|
+
const fetcher = options?.fetch ?? fetch;
|
|
5586
|
+
const response = shouldOmitEmbeddedItems ? await fetcher("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
|
|
5587
|
+
method: "POST",
|
|
5588
|
+
body: buildOmitEmbeddedItemsXQuery(parsedUuid),
|
|
5589
|
+
headers: { "Content-Type": "application/xquery" }
|
|
5590
|
+
}) : await fetcher(`https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${parsedUuid}&xsl=none&lang="*"`);
|
|
5556
5591
|
if (!response.ok) throw new Error("Failed to fetch OCHRE data", { cause: response.statusText });
|
|
5557
5592
|
const dataRaw = await response.text();
|
|
5558
5593
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
@@ -5561,13 +5596,15 @@ async function fetchItem(uuid, options) {
|
|
|
5561
5596
|
restoreXMLMetadata(output, data);
|
|
5562
5597
|
const category = options?.category ?? inferFetchItemCategory(output.result.ochre);
|
|
5563
5598
|
assertItemCategoryAllowed(category, options?.containedItemCategory);
|
|
5599
|
+
assertShouldOmitEmbeddedItemsAllowed(category, shouldOmitEmbeddedItems);
|
|
5600
|
+
const parsedItem = parseItem(output, {
|
|
5601
|
+
category,
|
|
5602
|
+
containedItemCategory: options?.containedItemCategory,
|
|
5603
|
+
languages,
|
|
5604
|
+
parseResourceView: (view, context) => parseWebpageView(view, { languages: context.metadata.languages }, context)
|
|
5605
|
+
});
|
|
5564
5606
|
return {
|
|
5565
|
-
item:
|
|
5566
|
-
category,
|
|
5567
|
-
containedItemCategory: options?.containedItemCategory,
|
|
5568
|
-
languages,
|
|
5569
|
-
parseResourceView: (view, context) => parseWebpageView(view, { languages: context.metadata.languages }, context)
|
|
5570
|
-
}),
|
|
5607
|
+
item: shouldOmitEmbeddedItems && isItemContainer(parsedItem) ? omitEmbeddedItems(parsedItem) : parsedItem,
|
|
5571
5608
|
error: null,
|
|
5572
5609
|
detailedError: null
|
|
5573
5610
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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",
|
|
@@ -42,6 +42,17 @@
|
|
|
42
42
|
"files": [
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"dev": "tsdown src/index.ts --watch",
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"lint": "eslint .",
|
|
49
|
+
"lint:fix": "eslint . --fix",
|
|
50
|
+
"format": "prettier --check .",
|
|
51
|
+
"format:fix": "prettier --write --list-different .",
|
|
52
|
+
"check-types": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"release": "bumpp"
|
|
55
|
+
},
|
|
45
56
|
"dependencies": {
|
|
46
57
|
"date-fns": "^4.2.1",
|
|
47
58
|
"fast-equals": "^6.0.0",
|
|
@@ -56,17 +67,7 @@
|
|
|
56
67
|
"prettier": "^3.8.3",
|
|
57
68
|
"tsdown": "^0.22.0",
|
|
58
69
|
"typescript": "^6.0.3",
|
|
59
|
-
"vitest": "^4.1.
|
|
70
|
+
"vitest": "^4.1.7"
|
|
60
71
|
},
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
"build": "tsdown",
|
|
64
|
-
"lint": "eslint .",
|
|
65
|
-
"lint:fix": "eslint . --fix",
|
|
66
|
-
"format": "prettier --check .",
|
|
67
|
-
"format:fix": "prettier --write --list-different .",
|
|
68
|
-
"check-types": "tsc --noEmit",
|
|
69
|
-
"test": "vitest run",
|
|
70
|
-
"release": "bumpp"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
72
|
+
"packageManager": "pnpm@11.2.1"
|
|
73
|
+
}
|