ochre-sdk 1.0.16 → 1.0.18

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.
@@ -1,12 +1,7 @@
1
1
  import { Gallery } from "../types/index.mjs";
2
+ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
2
3
 
3
4
  //#region src/fetchers/gallery.d.ts
4
- type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
5
- type FetchGalleryBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
6
- languages?: TLanguages;
7
- fetch?: FetchFunction;
8
- };
9
- type FetchGalleryLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
10
5
  /**
11
6
  * Fetches and parses a gallery from the OCHRE API
12
7
  *
@@ -25,8 +20,8 @@ declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | u
25
20
  filter?: string;
26
21
  page: number;
27
22
  perPage: number;
28
- }, options?: FetchGalleryBaseOptions<TLanguages>): Promise<{
29
- gallery: Gallery<FetchGalleryLanguages<TLanguages>>;
23
+ }, options?: FetchBaseOptions<TLanguages>): Promise<{
24
+ gallery: Gallery<FetchLanguages<TLanguages>>;
30
25
  error: null;
31
26
  detailedError: null;
32
27
  } | {
@@ -1,12 +1,7 @@
1
1
  import { ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemContainerCategory } from "../types/index.mjs";
2
+ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
2
3
 
3
4
  //#region src/fetchers/item-links.d.ts
4
- type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
5
- type FetchItemLinksBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
6
- languages?: TLanguages;
7
- fetch?: FetchFunction;
8
- };
9
- type FetchItemLinksLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
10
5
  /**
11
6
  * Fetches linked OCHRE items by source-item UUID.
12
7
  *
@@ -17,10 +12,10 @@ type FetchItemLinksLanguages<TLanguages extends ReadonlyArray<string> | undefine
17
12
  * @param options.fetch - Custom fetch function to use instead of the default fetch
18
13
  * @returns An object containing parsed linked items
19
14
  */
20
- declare function fetchItemLinks<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchItemLinksBaseOptions<TLanguages> & {
15
+ declare function fetchItemLinks<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
21
16
  containedItemCategory?: TContainedItemCategory;
22
17
  }): Promise<{
23
- items: Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchItemLinksLanguages<TLanguages>, "embedded">>;
18
+ items: Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, "embedded">>;
24
19
  error: null;
25
20
  detailedError: null;
26
21
  } | {
@@ -1,26 +1,16 @@
1
1
  import { ContainedItemCategory, ContainedItemCategoryFromOption, ContainedItemCategoryOption, Item, ItemCategory, ItemContainerCategory, ItemWithoutEmbeddedItems } from "../types/index.mjs";
2
+ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
2
3
 
3
4
  //#region src/fetchers/item.d.ts
4
- type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
5
- type FetchItemBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
6
- languages?: TLanguages;
7
- fetch?: FetchFunction;
8
- };
9
- type FetchItemNoOmitEmbeddedItemsOption = {
10
- shouldOmitEmbeddedItems?: false;
11
- };
12
- type FetchItemLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
13
- type FetchItemSuccess<TItem> = {
5
+ type FetchItemResult<TItem> = Promise<{
14
6
  item: TItem;
15
7
  error: null;
16
8
  detailedError: null;
17
- };
18
- type FetchItemError = {
9
+ } | {
19
10
  item: null;
20
11
  error: string;
21
12
  detailedError: string;
22
- };
23
- type FetchItemResult<TItem> = Promise<FetchItemSuccess<TItem> | FetchItemError>;
13
+ }>;
24
14
  /**
25
15
  * Defines a reusable languages tuple with validation and literal type inference.
26
16
  *
@@ -48,27 +38,30 @@ declare function withLanguages<const TLanguages extends ReadonlyArray<string>>(l
48
38
  * @param options.fetch - Custom fetch function to use instead of the default fetch
49
39
  * @returns An object containing the parsed item
50
40
  */
51
- declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchItemBaseOptions<TLanguages> & FetchItemNoOmitEmbeddedItemsOption & {
41
+ declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
52
42
  category?: undefined;
53
43
  containedItemCategory?: TContainedItemCategory;
54
- }): FetchItemResult<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
55
- declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
44
+ shouldOmitEmbeddedItems?: false;
45
+ }): FetchItemResult<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
46
+ declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
56
47
  category?: undefined;
57
48
  containedItemCategory?: TContainedItemCategory;
58
- shouldOmitEmbeddedItems: true;
59
- }): FetchItemResult<ItemWithoutEmbeddedItems<ItemContainerCategory, ContainedItemCategoryFromOption<ItemContainerCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
60
- 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 & {
49
+ shouldOmitEmbeddedItems?: true;
50
+ }): FetchItemResult<ItemWithoutEmbeddedItems<ItemContainerCategory, ContainedItemCategoryFromOption<ItemContainerCategory, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
51
+ declare function fetchItem<const TCategory extends ItemContainerCategory, const TContainedItemCategory extends ContainedItemCategoryOption<TCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
61
52
  category: TCategory;
62
53
  containedItemCategory?: TContainedItemCategory;
63
- }): FetchItemResult<Item<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
64
- 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> & {
54
+ shouldOmitEmbeddedItems?: false;
55
+ }): FetchItemResult<Item<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
56
+ declare function fetchItem<const TCategory extends ItemContainerCategory, const TContainedItemCategory extends ContainedItemCategoryOption<TCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
65
57
  category: TCategory;
66
58
  containedItemCategory?: TContainedItemCategory;
67
59
  shouldOmitEmbeddedItems: true;
68
- }): FetchItemResult<ItemWithoutEmbeddedItems<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>>;
69
- declare function fetchItem<const TCategory extends ItemCategory, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & FetchItemNoOmitEmbeddedItemsOption & {
60
+ }): FetchItemResult<ItemWithoutEmbeddedItems<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
61
+ declare function fetchItem<const TCategory extends ItemCategory, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
70
62
  category: TCategory;
71
63
  containedItemCategory?: never;
72
- }): FetchItemResult<Item<TCategory, ContainedItemCategory<TCategory>, FetchItemLanguages<TLanguages>>>;
64
+ shouldOmitEmbeddedItems?: false;
65
+ }): FetchItemResult<Item<TCategory, ContainedItemCategory<TCategory>, FetchLanguages<TLanguages>>>;
73
66
  //#endregion
74
67
  export { defineLanguages, fetchItem, withLanguages };
@@ -1,12 +1,7 @@
1
1
  import { Query, SetItem, SetItemCategory, SetItemsSort } from "../../types/index.mjs";
2
+ import { FetchBaseOptions, FetchLanguages } from "../../parsers/helpers.mjs";
2
3
 
3
4
  //#region src/fetchers/set/items.d.ts
4
- type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
5
- type FetchSetItemsBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
6
- languages?: TLanguages;
7
- fetch?: FetchFunction;
8
- };
9
- type FetchSetItemsLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
10
5
  type FetchSetItemsCategory<TContainedItemCategories extends ReadonlyArray<SetItemCategory> | undefined> = TContainedItemCategories extends ReadonlyArray<infer U> ? Extract<U, SetItemCategory> : SetItemCategory;
11
6
  /**
12
7
  * Fetches and parses Set items from the OCHRE API
@@ -29,11 +24,11 @@ declare function fetchSetItems<const TContainedItemCategories extends ReadonlyAr
29
24
  sort?: SetItemsSort;
30
25
  page: number;
31
26
  pageSize?: number;
32
- }, containedItemCategories?: TContainedItemCategories, options?: FetchSetItemsBaseOptions<TLanguages>): Promise<{
27
+ }, containedItemCategories?: TContainedItemCategories, options?: FetchBaseOptions<TLanguages>): Promise<{
33
28
  totalCount: number;
34
29
  page: number;
35
30
  pageSize: number;
36
- items: Array<SetItem<FetchSetItemsCategory<TContainedItemCategories>, FetchSetItemsLanguages<TLanguages>>>;
31
+ items: Array<SetItem<FetchSetItemsCategory<TContainedItemCategories>, FetchLanguages<TLanguages>>>;
37
32
  error: null;
38
33
  detailedError: null;
39
34
  } | {
@@ -0,0 +1,21 @@
1
+ import { WebsiteMetadata } from "../types/website.mjs";
2
+ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
3
+
4
+ //#region src/fetchers/website-metadata.d.ts
5
+ /**
6
+ * Fetches and parses a page-scoped website metadata projection from the OCHRE
7
+ * API.
8
+ */
9
+ declare function fetchWebsiteMetadata<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(abbreviation: string, options: FetchBaseOptions<TLanguages> & {
10
+ slug: string;
11
+ }): Promise<{
12
+ websiteMetadata: WebsiteMetadata<FetchLanguages<TLanguages>>;
13
+ error: null;
14
+ detailedError: null;
15
+ } | {
16
+ websiteMetadata: null;
17
+ error: string;
18
+ detailedError: string;
19
+ }>;
20
+ //#endregion
21
+ export { fetchWebsiteMetadata };
@@ -0,0 +1,168 @@
1
+ import { XML_PARSER_OPTIONS } from "../constants.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
3
+ import { iso639_3Schema } from "../schemas.mjs";
4
+ import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
+ import { parseStringLike } from "../parsers/helpers.mjs";
6
+ import { parseIdentification, parseMetadataLanguages, parseSimplifiedProperties, resolveLanguages } from "../parsers/index.mjs";
7
+ import { XMLWebsiteData } from "../xml/schemas.mjs";
8
+ import { websitePresentationReader } from "../parsers/website/reader.mjs";
9
+ import * as v from "valibot";
10
+ import { XMLParser } from "fast-xml-parser";
11
+ //#region src/fetchers/website-metadata.ts
12
+ function parseWebsiteMetadata(data, options) {
13
+ const rawOchre = data.result.ochre;
14
+ const websiteTree = rawOchre.tree[0];
15
+ if (websiteTree == null) throw new Error("Website tree not found", { cause: data });
16
+ const identification = parseIdentification(websiteTree.identification, options);
17
+ const websiteName = identification.label.getText().trim();
18
+ const metadataDescription = (parseStringLike(rawOchre.metadata.description) ?? "").trim();
19
+ const reader = websitePresentationReader(parseSimplifiedProperties(websiteTree.properties, options));
20
+ const webpage = websiteTree.items?.resource?.[0] ?? null;
21
+ const webpageTitle = webpage != null && "identification" in webpage ? parseIdentification(webpage.identification, options).label : null;
22
+ return {
23
+ uuid: websiteTree.uuid,
24
+ belongsTo: {
25
+ uuid: rawOchre.uuidBelongsTo,
26
+ abbreviation: rawOchre.belongsTo
27
+ },
28
+ identification,
29
+ description: websiteName === "" ? metadataDescription : metadataDescription !== "" && metadataDescription !== websiteName ? `${websiteName} - ${metadataDescription}` : websiteName,
30
+ webpageTitle,
31
+ properties: { icon: {
32
+ faviconUuid: reader.uuid("favicon-ico"),
33
+ appleTouchIconUuid: reader.uuid("favicon-img")
34
+ } }
35
+ };
36
+ }
37
+ function buildXQuery(params) {
38
+ return String.raw`xquery version "1.0-ml";
39
+
40
+ declare function local:resource-items($resources) {
41
+ for $resource in $resources
42
+ return
43
+ if ($resource/segments) then $resource
44
+ else if ($resource/identification) then $resource
45
+ else local:resource-items($resource/resource)
46
+ };
47
+
48
+ declare function local:presentation($resource) {
49
+ string(($resource/properties/property[label/string() = "presentation"]/value)[1])
50
+ };
51
+
52
+ declare function local:clean-slug($slug) {
53
+ replace(string($slug), "^\$[^-]*-", "")
54
+ };
55
+
56
+ declare function local:page-slug($resource, $slug-prefix) {
57
+ let $slug := local:clean-slug($resource/@slug)
58
+ return
59
+ if ($slug-prefix = "") then $slug
60
+ else if ($slug = "") then $slug-prefix
61
+ else concat($slug-prefix, "/", $slug)
62
+ };
63
+
64
+ declare function local:matches-page-slug($resource, $target-slug, $slug-prefix) {
65
+ local:page-slug($resource, $slug-prefix) = $target-slug
66
+ };
67
+
68
+ declare function local:page-child-slug-prefix($resource, $slug-prefix) {
69
+ if ($slug-prefix = "") then ""
70
+ else local:page-slug($resource, $slug-prefix)
71
+ };
72
+
73
+ declare function local:metadata-page($resource) {
74
+ element resource {
75
+ attribute uuid { string($resource/@uuid) },
76
+ $resource/identification
77
+ }
78
+ };
79
+
80
+ declare function local:matching-pages($resources, $target-slug, $slug-prefix) {
81
+ for $resource in $resources
82
+ let $children := local:resource-items($resource/resource)
83
+ let $page-slug := local:page-slug($resource, $slug-prefix)
84
+ let $child-slug-prefix := local:page-child-slug-prefix($resource, $slug-prefix)
85
+ return (
86
+ if (local:matches-page-slug($resource, $target-slug, $slug-prefix)) then
87
+ local:metadata-page($resource)
88
+ else (),
89
+ local:matching-pages(
90
+ $children[local:presentation(.) = "page"],
91
+ $target-slug,
92
+ $child-slug-prefix
93
+ ),
94
+ for $segment in $children[segments]/segments/tree
95
+ return local:matching-pages(
96
+ local:resource-items($segment/items/resource),
97
+ $target-slug,
98
+ $page-slug
99
+ )
100
+ )
101
+ };
102
+
103
+ declare function local:metadata-tree($tree, $target-slug, $slug-prefix) {
104
+ let $resources := local:resource-items($tree/items/resource)
105
+ let $icon-properties := $tree/properties/property[label/string() = "presentation"][value/string() = "website"]/property[label/string() = ("favicon-ico", "favicon-img")]
106
+ return
107
+ element tree {
108
+ attribute uuid { string($tree/@uuid) },
109
+ $tree/identification,
110
+ if (empty($icon-properties)) then () else element properties { $icon-properties },
111
+ element items {
112
+ local:matching-pages(
113
+ $resources[local:presentation(.) = "page"],
114
+ $target-slug,
115
+ $slug-prefix
116
+ )
117
+ }
118
+ }
119
+ };
120
+
121
+ let $website := collection("ochre/tree")/ochre[tree/identification/abbreviation/content/string = ${stringLiteral(params.abbreviation)}][1]
122
+ let $target-slug := ${stringLiteral(params.slug)}
123
+ return
124
+ <ochre>{
125
+ $website/@uuid,
126
+ $website/@uuidBelongsTo,
127
+ $website/@belongsTo,
128
+ $website/@publicationDateTime,
129
+ $website/@languages,
130
+ $website/metadata,
131
+ local:metadata-tree($website/tree[1], $target-slug, "")
132
+ }</ochre>`;
133
+ }
134
+ async function fetchWebsiteMetadata(abbreviation, options) {
135
+ try {
136
+ const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
137
+ if (options?.slug == null) throw new Error("Website metadata slug is required");
138
+ const slug = options.slug.trim().replaceAll(/^\/+|\/+$/g, "");
139
+ const requestedLanguages = [];
140
+ for (const language of options.languages ?? []) requestedLanguages.push(v.parse(iso639_3Schema, language));
141
+ const response = await (options.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
142
+ method: "POST",
143
+ body: buildXQuery({
144
+ abbreviation: cleanAbbreviation,
145
+ slug
146
+ }),
147
+ headers: { "Content-Type": "application/xquery" }
148
+ });
149
+ if (!response.ok) throw new Error("Failed to fetch website metadata", { cause: response.statusText });
150
+ const dataRaw = await response.text();
151
+ const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
152
+ const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
153
+ if (!success) throw createSchemaValidationError("Failed to parse website metadata XML", issues);
154
+ restoreXMLMetadata(output, data);
155
+ return {
156
+ websiteMetadata: parseWebsiteMetadata(output, { languages: resolveLanguages(requestedLanguages, parseMetadataLanguages(output.result.ochre)) }),
157
+ error: null,
158
+ detailedError: null
159
+ };
160
+ } catch (error) {
161
+ return {
162
+ websiteMetadata: null,
163
+ ...getErrorOutput(error, "Unknown error")
164
+ };
165
+ }
166
+ }
167
+ //#endregion
168
+ export { fetchWebsiteMetadata };
@@ -1,8 +1,8 @@
1
1
  import { Website } from "../types/website.mjs";
2
2
  import { LanguageCodes } from "../types/index.mjs";
3
+ import { FetchFunction } from "../parsers/helpers.mjs";
3
4
 
4
5
  //#region src/fetchers/website.d.ts
5
- type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
6
6
  /**
7
7
  * Fetches and parses a website configuration from the OCHRE API
8
8
  *
package/dist/index.d.mts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { MultilingualOptions, MultilingualString, MultilingualStringEntries, MultilingualStringEntry, MultilingualStringInput, MultilingualStringJSON, MultilingualStringObject, MultilingualStringText } from "./parsers/multilingual.mjs";
2
- import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType } from "./types/website.mjs";
2
+ import { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, 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, ItemContainerCategory, ItemLink, ItemLinkCategory, ItemLinks, ItemPayloadKind, ItemProperty, ItemWithoutEmbeddedItems, LanguageCodes, License, Metadata, Note, Observation, Period, PeriodItemLink, Person, PersonItemLink, Property, PropertyLike, 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
5
  import { fetchItemLinks } from "./fetchers/item-links.mjs";
6
6
  import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
7
7
  import { fetchSetItems } from "./fetchers/set/items.mjs";
8
8
  import { fetchSetPropertyValues } from "./fetchers/set/property-values.mjs";
9
+ import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
9
10
  import { fetchWebsite } from "./fetchers/website.mjs";
10
11
  import { PropertyOptions, filterProperties, getLeafPropertyValues, getPropertyByVariableLabel, getPropertyByVariableLabelAndValue, getPropertyByVariableLabelAndValueContent, getPropertyByVariableLabelAndValueContents, getPropertyByVariableLabelAndValues, getPropertyByVariableUuid, getPropertyValueByVariableLabel, getPropertyValueByVariableUuid, getPropertyValueContentByVariableLabel, getPropertyValueContentByVariableUuid, getPropertyValueContentsByVariableUuid, getPropertyValuesByVariableLabel, getPropertyValuesByVariableUuid, getUniqueProperties, getUniquePropertyVariableLabels } from "./getters.mjs";
11
12
  import { DEFAULT_PAGE_SIZE, flattenItemProperties } from "./helpers.mjs";
12
- 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 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 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 WebBlock, type WebBlockByLayout, type WebBlockLayout, type WebElement, type WebElementComponent, type WebElementComponentName, type WebElementComponentOf, type WebElementOf, type WebImage, type WebTitle, type Webpage, type Website, type WebsitePropertyQuery, type WebsitePropertyQueryNode, type WebsiteSegment, type 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 };
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 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 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 WebBlock, type WebBlockByLayout, 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 };
package/dist/index.mjs CHANGED
@@ -6,5 +6,6 @@ import { fetchItemLinks } from "./fetchers/item-links.mjs";
6
6
  import { defineLanguages, fetchItem, withLanguages } from "./fetchers/item.mjs";
7
7
  import { fetchSetItems } from "./fetchers/set/items.mjs";
8
8
  import { fetchSetPropertyValues } from "./fetchers/set/property-values.mjs";
9
+ import { fetchWebsiteMetadata } from "./fetchers/website-metadata.mjs";
9
10
  import { fetchWebsite } from "./fetchers/website.mjs";
10
- export { DEFAULT_PAGE_SIZE, MultilingualString, 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 };
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 };
@@ -3,6 +3,13 @@ import { License } from "../types/index.mjs";
3
3
  import { XMLContent, XMLString } from "../xml/types.mjs";
4
4
 
5
5
  //#region src/parsers/helpers.d.ts
6
+ type FetchFunction = (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
7
+ type FetchBaseOptions<TLanguages extends ReadonlyArray<string> | undefined = undefined> = {
8
+ languages?: TLanguages;
9
+ fetch?: FetchFunction;
10
+ };
11
+ type FetchRuntimeOptions = FetchBaseOptions<ReadonlyArray<string>>;
12
+ type FetchLanguages<TLanguages extends ReadonlyArray<string> | undefined> = TLanguages extends readonly [] ? ReadonlyArray<string> : TLanguages extends ReadonlyArray<string> ? TLanguages : ReadonlyArray<string>;
6
13
  type ParserOptions<T extends ReadonlyArray<string>> = {
7
14
  languages: T;
8
15
  };
@@ -24,4 +31,4 @@ declare function parseRequiredContentLike<T extends ReadonlyArray<string>>(value
24
31
  declare function parseContentLikeText<T extends ReadonlyArray<string>>(value: XMLContent | XMLString | undefined, options: ParserOptions<T>): string;
25
32
  declare function parseStringContent(value: XMLContent | XMLString | string | undefined, options?: ParserOptions<ReadonlyArray<string>>): string;
26
33
  //#endregion
27
- export { ParserOptions, cleanObject, getParserOptions, isXMLContent, multilingualFromText, parseContentLike, parseContentLikeText, parseLicense, parseRequiredContentLike, parseStringContent, parseStringLike };
34
+ export { FetchBaseOptions, FetchFunction, FetchLanguages, FetchRuntimeOptions, ParserOptions, cleanObject, getParserOptions, isXMLContent, multilingualFromText, parseContentLike, parseContentLikeText, parseLicense, parseRequiredContentLike, parseStringContent, parseStringLike };
@@ -1,4 +1,5 @@
1
1
  //#region src/parsers/mdx.d.ts
2
2
  declare function serializeMDXText(value: string): string;
3
+ declare function serializeMDXContent(value: string): string;
3
4
  //#endregion
4
- export { serializeMDXText };
5
+ export { serializeMDXContent, serializeMDXText };
@@ -1,9 +1,22 @@
1
1
  //#region src/parsers/mdx.ts
2
2
  const MDX_LITERAL_EXPRESSION_REGEX = /[!#*<>[\]_`{|}~]/;
3
3
  const MDX_LITERAL_BLOCK_REGEX = /(?:^|\n)[\t ]*(?:import|export|[+>-]|\d+[).])(?:[\t ]|$)/;
4
+ const MDX_MULTIPLE_SPACES_REGEX = / {2,}/g;
5
+ const MDX_INLINE_BOUNDARY_PATTERN = "(?:Annotation|ExternalLink|InlineImage|InternalLink|TooltipSpan|em|strong|u)";
6
+ const MDX_INLINE_BOUNDARY_SPACES_REGEX = new RegExp(String.raw`(\}|<\/${MDX_INLINE_BOUNDARY_PATTERN}>|\/>)([\t ]+)(?=\{|<\/?${MDX_INLINE_BOUNDARY_PATTERN}\b)`, "g");
7
+ const MDX_INLINE_BOUNDARY_REGEX = new RegExp(String.raw`(?:\}[\t ]*|<\/${MDX_INLINE_BOUNDARY_PATTERN}>|\/>)(?=\{|<\/?${MDX_INLINE_BOUNDARY_PATTERN}\b)`);
8
+ function preserveMultipleSpaces(value) {
9
+ return value.replaceAll(MDX_MULTIPLE_SPACES_REGEX, (spaces) => `${spaces.slice(0, 1)}${"\xA0".repeat(spaces.length - 1)}`);
10
+ }
4
11
  function serializeMDXText(value) {
5
- if (value === "" || !MDX_LITERAL_EXPRESSION_REGEX.test(value) && !MDX_LITERAL_BLOCK_REGEX.test(value)) return value;
6
- return `{${JSON.stringify(value)}}`;
12
+ const displaySafeValue = preserveMultipleSpaces(value);
13
+ if (displaySafeValue === "" || !(displaySafeValue !== value) && !MDX_LITERAL_EXPRESSION_REGEX.test(displaySafeValue) && !MDX_LITERAL_BLOCK_REGEX.test(displaySafeValue)) return displaySafeValue;
14
+ return `{${JSON.stringify(displaySafeValue)}}`;
15
+ }
16
+ function serializeMDXContent(value) {
17
+ const content = value.replaceAll(MDX_INLINE_BOUNDARY_SPACES_REGEX, (_, previousBoundary, spaces) => `${previousBoundary}{${JSON.stringify(preserveMultipleSpaces(spaces))}}`);
18
+ if (!MDX_INLINE_BOUNDARY_REGEX.test(content)) return content;
19
+ return content.endsWith("\n") ? `<>\n${content}</>` : `<>\n${content}\n</>`;
7
20
  }
8
21
  //#endregion
9
- export { serializeMDXText };
22
+ export { serializeMDXContent, serializeMDXText };
@@ -1,5 +1,5 @@
1
1
  import { TEXT_ANNOTATION_UUID } from "../constants.mjs";
2
- import { serializeMDXText } from "./mdx.mjs";
2
+ import { serializeMDXContent, serializeMDXText } from "./mdx.mjs";
3
3
  import { MultilingualString } from "./multilingual.mjs";
4
4
  import { renderOptionsSchema } from "../schemas.mjs";
5
5
  import { getXMLSourceIndex } from "../xml/metadata.mjs";
@@ -419,15 +419,16 @@ function parseXMLContent(item, options) {
419
419
  return MultilingualString.empty(languages, { aliases });
420
420
  }
421
421
  function parseXMLContentItem(contentItem, options) {
422
+ const richText = parseNestedStringItems(contentItem.string, contentItem, {
423
+ ...options,
424
+ rendering: "rich"
425
+ });
422
426
  return {
423
427
  text: parseNestedStringItems(contentItem.string, contentItem, {
424
428
  ...options,
425
429
  rendering: "plain"
426
430
  }),
427
- richText: parseNestedStringItems(contentItem.string, contentItem, {
428
- ...options,
429
- rendering: "rich"
430
- })
431
+ richText: serializeMDXContent(richText)
431
432
  };
432
433
  }
433
434
  /**
@@ -11,7 +11,7 @@ declare const uuidSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>,
11
11
  * Schema for validating language codes
12
12
  * @internal
13
13
  */
14
- declare const iso639_3Schema: v.SchemaWithPipe<readonly [v.StringSchema<"Language code must be a string">, v.LengthAction<string, 3, "Language code must be exactly 3 characters">, v.RegexAction<string, "Language code must be exactly 3 lowercase letters">]>;
14
+ declare const iso639_3Schema: v.SchemaWithPipe<readonly [v.StringSchema<"Language code must be a string">, v.RegexAction<string, "Language code must be exactly 3 lowercase letters">]>;
15
15
  /**
16
16
  * Valid component types for web elements
17
17
  * @internal
package/dist/schemas.mjs CHANGED
@@ -15,7 +15,7 @@ const uuidSchema = v.pipe(v.string(), v.check(isPseudoUuid, "Invalid pseudo-UUID
15
15
  * Schema for validating language codes
16
16
  * @internal
17
17
  */
18
- const iso639_3Schema = v.pipe(v.string("Language code must be a string"), v.length(3, "Language code must be exactly 3 characters"), v.regex(/^[a-z]{3}$/, "Language code must be exactly 3 lowercase letters"));
18
+ const iso639_3Schema = v.pipe(v.string("Language code must be a string"), v.regex(/^[a-z]{3}$/, "Language code must be exactly 3 lowercase letters"));
19
19
  /**
20
20
  * Valid component types for web elements
21
21
  * @internal
@@ -497,5 +497,21 @@ type WebBlock<T extends LanguageCodes = LanguageCodes, U extends WebBlockLayout
497
497
  };
498
498
  type WebBlockByLayout<U extends WebBlockLayout = WebBlockLayout, T extends LanguageCodes = LanguageCodes> = WebBlock<T, U>;
499
499
  type AccordionWebBlock<T extends LanguageCodes = LanguageCodes> = WebBlock<T, "accordion">;
500
+ type WebsiteMetadata<T extends LanguageCodes = LanguageCodes> = {
501
+ uuid: string;
502
+ belongsTo: {
503
+ uuid: string;
504
+ abbreviation: string;
505
+ } | null;
506
+ identification: Identification<T>;
507
+ description: string;
508
+ webpageTitle: MultilingualString<T> | null;
509
+ properties: {
510
+ icon: {
511
+ faviconUuid: string | null;
512
+ appleTouchIconUuid: string | null;
513
+ };
514
+ };
515
+ };
500
516
  //#endregion
501
- export { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType };
517
+ export { AccordionWebBlock, ContextTree, ContextTreeFilterLevel, ContextTreeLevel, ContextTreeLevelItem, Scope, Style, StylesheetCategory, StylesheetItem, WebBlock, WebBlockByLayout, WebBlockLayout, WebElement, WebElementComponent, WebElementComponentName, WebElementComponentOf, WebElementOf, WebImage, WebTitle, Webpage, Website, WebsiteMetadata, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteSegment, WebsiteType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
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",