ochre-sdk 1.0.76 → 1.0.78

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.
Files changed (42) hide show
  1. package/dist/constants.d.mts +13 -14
  2. package/dist/fetchers/gallery.d.mts +2 -3
  3. package/dist/fetchers/gallery.mjs +2 -1
  4. package/dist/fetchers/item-children.d.mts +3 -4
  5. package/dist/fetchers/item-children.mjs +2 -1
  6. package/dist/fetchers/item-links.d.mts +2 -3
  7. package/dist/fetchers/item-links.mjs +2 -1
  8. package/dist/fetchers/item-ocr-data.d.mts +2 -3
  9. package/dist/fetchers/item.d.mts +7 -8
  10. package/dist/fetchers/item.mjs +2 -1
  11. package/dist/fetchers/set/items.d.mts +2 -3
  12. package/dist/fetchers/set/items.mjs +2 -1
  13. package/dist/fetchers/set/property-values.d.mts +2 -3
  14. package/dist/fetchers/set/property-values.mjs +56 -49
  15. package/dist/fetchers/website-metadata.d.mts +2 -3
  16. package/dist/fetchers/website.d.mts +2 -3
  17. package/dist/getters.d.mts +40 -41
  18. package/dist/getters.mjs +6 -31
  19. package/dist/helpers.d.mts +3 -4
  20. package/dist/parsers/helpers.d.mts +16 -17
  21. package/dist/parsers/index.d.mts +19 -19
  22. package/dist/parsers/index.mjs +65 -48
  23. package/dist/parsers/mdx.d.mts +3 -4
  24. package/dist/parsers/multilingual.d.mts +9 -10
  25. package/dist/parsers/string.d.mts +5 -6
  26. package/dist/parsers/string.mjs +124 -146
  27. package/dist/parsers/website/index.d.mts +4 -5
  28. package/dist/parsers/website/index.mjs +598 -637
  29. package/dist/parsers/website/reader.d.mts +3 -4
  30. package/dist/query.d.mts +3 -4
  31. package/dist/schemas.d.mts +9 -10
  32. package/dist/types/index.d.mts +118 -119
  33. package/dist/types/website.d.mts +36 -38
  34. package/dist/utilities.d.mts +9 -10
  35. package/dist/utilities.mjs +28 -25
  36. package/dist/xml/dates.d.mts +13 -0
  37. package/dist/xml/dates.mjs +49 -0
  38. package/dist/xml/metadata.d.mts +3 -4
  39. package/dist/xml/schemas.d.mts +8 -9
  40. package/dist/xml/schemas.mjs +20 -27
  41. package/dist/xml/types.d.mts +129 -131
  42. package/package.json +13 -12
@@ -1,16 +1,15 @@
1
1
  import { X2jOptions } from "fast-xml-parser";
2
2
  //#region src/constants.d.ts
3
- declare const XML_ARRAY_TAGS: ReadonlyArray<string>;
4
- declare const XML_PARSER_OPTIONS: X2jOptions;
5
- declare const DEFAULT_LANGUAGES: readonly ["eng"];
6
- declare const BELONGS_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
7
- declare const PRESENTATION_ITEM_UUID = "f1c131b6-1498-48a4-95bf-a9edae9fd518";
8
- declare const TEXT_ANNOTATION_UUID = "b9ca2732-78f4-416e-b77f-dae7647e68a9";
9
- declare const TEXT_ANNOTATION_HOVER_CARD_UUID = "c7f6a08a-f07b-49b6-bcb1-af485da3c58f";
10
- declare const TEXT_ANNOTATION_ITEM_PAGE_VARIANT_UUID = "bf4476ab-6bc8-40d0-a001-1446213c72ce";
11
- declare const TEXT_ANNOTATION_ENTRY_PAGE_VARIANT_UUID = "9d52db95-a9cf-45f7-a0bf-fc9ba9f0aae0";
12
- declare const TEXT_ANNOTATION_TEXT_STYLING_UUID = "3e6f86ab-df81-45ae-8257-e2867357df56";
13
- declare const TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID = "e1647bef-d801-4100-bdde-d081c422f763";
14
- declare const TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID = "d4266f0b-3f8d-4b32-8c15-4b229c8bb11e";
15
- //#endregion
16
- export { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, PRESENTATION_ITEM_UUID, TEXT_ANNOTATION_ENTRY_PAGE_VARIANT_UUID, TEXT_ANNOTATION_HOVER_CARD_UUID, TEXT_ANNOTATION_ITEM_PAGE_VARIANT_UUID, TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID, TEXT_ANNOTATION_TEXT_STYLING_UUID, TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID, TEXT_ANNOTATION_UUID, XML_ARRAY_TAGS, XML_PARSER_OPTIONS };
3
+ export declare const XML_ARRAY_TAGS: ReadonlyArray<string>;
4
+ export declare const XML_PARSER_OPTIONS: X2jOptions;
5
+ export declare const DEFAULT_LANGUAGES: readonly ["eng"];
6
+ export declare const BELONGS_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
7
+ export declare const PRESENTATION_ITEM_UUID = "f1c131b6-1498-48a4-95bf-a9edae9fd518";
8
+ export declare const TEXT_ANNOTATION_UUID = "b9ca2732-78f4-416e-b77f-dae7647e68a9";
9
+ export declare const TEXT_ANNOTATION_HOVER_CARD_UUID = "c7f6a08a-f07b-49b6-bcb1-af485da3c58f";
10
+ export declare const TEXT_ANNOTATION_ITEM_PAGE_VARIANT_UUID = "bf4476ab-6bc8-40d0-a001-1446213c72ce";
11
+ export declare const TEXT_ANNOTATION_ENTRY_PAGE_VARIANT_UUID = "9d52db95-a9cf-45f7-a0bf-fc9ba9f0aae0";
12
+ export declare const TEXT_ANNOTATION_TEXT_STYLING_UUID = "3e6f86ab-df81-45ae-8257-e2867357df56";
13
+ export declare const TEXT_ANNOTATION_TEXT_STYLING_VARIANT_UUID = "e1647bef-d801-4100-bdde-d081c422f763";
14
+ export declare const TEXT_ANNOTATION_TEXT_STYLING_HEADING_LEVEL_UUID = "d4266f0b-3f8d-4b32-8c15-4b229c8bb11e";
15
+ //#endregion
@@ -14,7 +14,7 @@ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
14
14
  * @param options.fetch - The fetch function to use
15
15
  * @returns The parsed gallery or an error message if the fetch/parse fails
16
16
  */
17
- declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
17
+ export declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
18
18
  uuid: string;
19
19
  filter?: string;
20
20
  page: number;
@@ -28,5 +28,4 @@ declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | u
28
28
  error: string;
29
29
  detailedError: string;
30
30
  }>;
31
- //#endregion
32
- export { fetchGallery };
31
+ //#endregion
@@ -8,7 +8,8 @@ import * as v from "valibot";
8
8
  import { XMLParser } from "fast-xml-parser";
9
9
  //#region src/fetchers/gallery.ts
10
10
  function parseLanguages(languages) {
11
- return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
11
+ for (const language of languages) v.parse(iso639_3Schema, language);
12
+ return languages;
12
13
  }
13
14
  function isRecord(value) {
14
15
  return typeof value === "object" && value !== null;
@@ -24,13 +24,12 @@ type ItemChildrenPayloadKind<U extends ItemCategory> = U extends "tree" | "set"
24
24
  * @param options.fetch - Custom fetch function to use instead of the default fetch
25
25
  * @returns An object containing parsed child items
26
26
  */
27
- declare function fetchItemChildren<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
27
+ export declare function fetchItemChildren<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
28
28
  category?: undefined;
29
29
  containedItemCategory?: TContainedItemCategory;
30
30
  }): FetchItemChildrenResult<Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, "embedded" | "standaloneChild">>>;
31
- 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> & {
31
+ export 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> & {
32
32
  category: TCategory;
33
33
  containedItemCategory?: TContainedItemCategory;
34
34
  }): FetchItemChildrenResult<Array<Item<TChildCategory, ContainedItemCategoryFromOption<TChildCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, ItemChildrenPayloadKind<ItemCategoryFromOption<TCategory>>>>>;
35
- //#endregion
36
- export { fetchItemChildren };
35
+ //#endregion
@@ -21,7 +21,8 @@ const ITEM_COLLECTION_CATEGORIES = [
21
21
  "set"
22
22
  ];
23
23
  function parseLanguages(languages) {
24
- return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
24
+ for (const language of languages) v.parse(iso639_3Schema, language);
25
+ return languages;
25
26
  }
26
27
  function isRecord(value) {
27
28
  return typeof value === "object" && value !== null;
@@ -11,7 +11,7 @@ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
11
11
  * @param options.fetch - Custom fetch function to use instead of the default fetch
12
12
  * @returns An object containing parsed linked items
13
13
  */
14
- declare function fetchItemLinks<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
14
+ export declare function fetchItemLinks<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
15
15
  containedItemCategory?: TContainedItemCategory;
16
16
  }): Promise<{
17
17
  items: Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>, "embedded">>;
@@ -22,5 +22,4 @@ declare function fetchItemLinks<const TContainedItemCategory extends ContainedIt
22
22
  error: string;
23
23
  detailedError: string;
24
24
  }>;
25
- //#endregion
26
- export { fetchItemLinks };
25
+ //#endregion
@@ -8,7 +8,8 @@ import * as v from "valibot";
8
8
  import { XMLParser } from "fast-xml-parser";
9
9
  //#region src/fetchers/item-links.ts
10
10
  function parseLanguages(languages) {
11
- return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
11
+ for (const language of languages) v.parse(iso639_3Schema, language);
12
+ return languages;
12
13
  }
13
14
  function isRecord(value) {
14
15
  return typeof value === "object" && value !== null;
@@ -23,7 +23,7 @@ import { OcrString } from "../types/index.mjs";
23
23
  * @returns The matching OCR strings, an empty array when the item has no OCR
24
24
  * layer or nothing matches, and a null output on fetch/parse errors
25
25
  */
26
- declare function fetchItemOcrData(uuid: string, value: string, options?: {
26
+ export declare function fetchItemOcrData(uuid: string, value: string, options?: {
27
27
  matchMode?: "includes" | "exact";
28
28
  isCaseSensitive?: boolean;
29
29
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
@@ -36,5 +36,4 @@ declare function fetchItemOcrData(uuid: string, value: string, options?: {
36
36
  error: string;
37
37
  detailedError: string;
38
38
  }>;
39
- //#endregion
40
- export { fetchItemOcrData };
39
+ //#endregion
@@ -19,12 +19,12 @@ type FetchItemResult<TItem> = Promise<{
19
19
  * Use this helper when the language set is stored separately:
20
20
  * `const languages = defineLanguages("eng", "spa")`.
21
21
  */
22
- declare function defineLanguages<const TLanguages extends ReadonlyArray<string>>(...languages: TLanguages): TLanguages;
22
+ export declare function defineLanguages<const TLanguages extends ReadonlyArray<string>>(...languages: TLanguages): TLanguages;
23
23
  /**
24
24
  * @deprecated Pass inline language arrays directly to fetchItem, or use
25
25
  * defineLanguages("eng", "spa") for reusable language tuples.
26
26
  */
27
- declare function withLanguages<const TLanguages extends ReadonlyArray<string>>(languages: TLanguages): TLanguages;
27
+ export declare function withLanguages<const TLanguages extends ReadonlyArray<string>>(languages: TLanguages): TLanguages;
28
28
  /**
29
29
  * Fetches an OCHRE item by UUID from the OCHRE API
30
30
  *
@@ -39,25 +39,24 @@ declare function withLanguages<const TLanguages extends ReadonlyArray<string>>(l
39
39
  * @param options.fetch - Custom fetch function to use instead of the default fetch
40
40
  * @returns An object containing the parsed item
41
41
  */
42
- declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
42
+ export declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options?: FetchBaseOptions<TLanguages> & {
43
43
  category?: undefined;
44
44
  containedItemCategory?: TContainedItemCategory;
45
45
  shouldOmitEmbeddedItems?: false;
46
46
  }): FetchItemResult<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
47
- declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
47
+ export declare function fetchItem<const TContainedItemCategory extends ContainedItemCategoryOption<ItemContainerCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
48
48
  category?: undefined;
49
49
  containedItemCategory?: TContainedItemCategory;
50
50
  shouldOmitEmbeddedItems?: true;
51
51
  }): FetchItemResult<ItemWithoutEmbeddedItems<ItemCategoryWithEmbeddedItems, ContainedItemCategoryFromOption<ItemContainerCategory, TContainedItemCategory>, FetchLanguages<TLanguages>> | Item<Exclude<ItemCategory, ItemCategoryWithEmbeddedItems>, never, FetchLanguages<TLanguages>>>;
52
- declare function fetchItem<const TCategory extends ItemCategoryOption, const TContainedItemCategory extends ContainedItemCategoryOption<ItemCategoryFromOption<TCategory>> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
52
+ export declare function fetchItem<const TCategory extends ItemCategoryOption, const TContainedItemCategory extends ContainedItemCategoryOption<ItemCategoryFromOption<TCategory>> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
53
53
  category: TCategory;
54
54
  containedItemCategory?: TContainedItemCategory;
55
55
  shouldOmitEmbeddedItems?: false;
56
56
  }): FetchItemResult<Item<ItemCategoryFromOption<TCategory>, ContainedItemCategoryFromOption<ItemCategoryFromOption<TCategory>, TContainedItemCategory>, FetchLanguages<TLanguages>>>;
57
- declare function fetchItem<const TCategory extends ItemCategoryOption, const TContainedItemCategory extends ContainedItemCategoryOption<Extract<ItemCategoryFromOption<TCategory>, ItemCategoryWithEmbeddedItems>> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
57
+ export declare function fetchItem<const TCategory extends ItemCategoryOption, const TContainedItemCategory extends ContainedItemCategoryOption<Extract<ItemCategoryFromOption<TCategory>, ItemCategoryWithEmbeddedItems>> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchBaseOptions<TLanguages> & {
58
58
  category: TCategory;
59
59
  containedItemCategory?: TContainedItemCategory;
60
60
  shouldOmitEmbeddedItems: true;
61
61
  }): FetchItemResult<ItemWithoutEmbeddedItems<Extract<ItemCategoryFromOption<TCategory>, ItemCategoryWithEmbeddedItems>, ContainedItemCategoryFromOption<Extract<ItemCategoryFromOption<TCategory>, ItemCategoryWithEmbeddedItems>, TContainedItemCategory>, FetchLanguages<TLanguages>> | Item<Exclude<ItemCategoryFromOption<TCategory>, ItemCategoryWithEmbeddedItems>, never, FetchLanguages<TLanguages>>>;
62
- //#endregion
63
- export { defineLanguages, fetchItem, withLanguages };
62
+ //#endregion
@@ -85,7 +85,8 @@ function omitEmbeddedItems(item) {
85
85
  * Validate language codes while preserving literal tuple inference.
86
86
  */
87
87
  function parseLanguages(languages) {
88
- return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
88
+ for (const language of languages) v.parse(iso639_3Schema, language);
89
+ return languages;
89
90
  }
90
91
  /**
91
92
  * Defines a reusable languages tuple with validation and literal type inference.
@@ -17,7 +17,7 @@ type FetchSetItemsCategory<TContainedItemCategories extends ReadonlyArray<SetIte
17
17
  * @param options.fetch - The fetch function to use
18
18
  * @returns The parsed Set items or null if the fetch/parse fails
19
19
  */
20
- declare function fetchSetItems<const TContainedItemCategories extends ReadonlyArray<SetItemCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
20
+ export declare function fetchSetItems<const TContainedItemCategories extends ReadonlyArray<SetItemCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
21
21
  setScopeUuids: Array<string>;
22
22
  queries?: Query | null;
23
23
  sort?: SetItemsSort;
@@ -38,5 +38,4 @@ declare function fetchSetItems<const TContainedItemCategories extends ReadonlyAr
38
38
  error: string;
39
39
  detailedError: string;
40
40
  }>;
41
- //#endregion
42
- export { fetchSetItems };
41
+ //#endregion
@@ -9,7 +9,8 @@ import * as v from "valibot";
9
9
  import { XMLParser } from "fast-xml-parser";
10
10
  //#region src/fetchers/set/items.ts
11
11
  function parseLanguages(languages) {
12
- return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
12
+ for (const language of languages) v.parse(iso639_3Schema, language);
13
+ return languages;
13
14
  }
14
15
  function isRecord(value) {
15
16
  return typeof value === "object" && value !== null;
@@ -15,7 +15,7 @@ import { PropertyValueQueryItem, Query, SetAttributeValueQueryItem } from "../..
15
15
  * @returns Parsed Set property values and requested attribute values.
16
16
  * Returns empty arrays/objects when no matches are found, and null outputs on fetch/parse errors.
17
17
  */
18
- declare function fetchSetPropertyValues(parameters: {
18
+ export declare function fetchSetPropertyValues(parameters: {
19
19
  setScopeUuids: Array<string>;
20
20
  queries?: Query | null;
21
21
  attributes?: {
@@ -41,5 +41,4 @@ declare function fetchSetPropertyValues(parameters: {
41
41
  error: string;
42
42
  detailedError: string;
43
43
  }>;
44
- //#endregion
45
- export { fetchSetPropertyValues };
44
+ //#endregion
@@ -93,8 +93,7 @@ function getPropertyFacetSelectorsFromQueries(queries) {
93
93
  function getItemFilterQueriesFromPropertyValueQueries(queries) {
94
94
  if (queries == null) return null;
95
95
  if ("target" in queries) {
96
- if (queries.target !== "property") return queries;
97
- if (queries.dataType === "date" || queries.dataType === "dateTime") return queries;
96
+ if (queries.target !== "property" || queries.dataType === "date" || queries.dataType === "dateTime") return queries;
98
97
  return "value" in queries && queries.value != null ? queries : null;
99
98
  }
100
99
  const filteredChildren = [];
@@ -103,8 +102,7 @@ function getItemFilterQueriesFromPropertyValueQueries(queries) {
103
102
  const filteredChildQuery = getItemFilterQueriesFromPropertyValueQueries(childQuery);
104
103
  if (filteredChildQuery != null) filteredChildren.push(filteredChildQuery);
105
104
  }
106
- if (filteredChildren.length === 0) return null;
107
- if (filteredChildren.length === 1) return filteredChildren[0] ?? null;
105
+ if (filteredChildren.length <= 1) return filteredChildren[0] ?? null;
108
106
  return "and" in queries ? { and: filteredChildren } : { or: filteredChildren };
109
107
  }
110
108
  /**
@@ -411,6 +409,55 @@ ${queryBlocks.join("\n\n")}
411
409
  return (${returnedSequences.join(", ")})
412
410
  }</ochre>`;
413
411
  }
412
+ function collectPropertyValues(parsedPropertyValues) {
413
+ const propertyValuesByPropertyVariableUuid = {};
414
+ const flattenedPropertyValuesByKey = /* @__PURE__ */ new Map();
415
+ for (const propertyValue of parsedPropertyValues) {
416
+ if (propertyValue.content == null) continue;
417
+ const propertyValueItem = {
418
+ uuid: propertyValue.uuid,
419
+ count: propertyValue.count,
420
+ dataType: propertyValue.dataType,
421
+ content: propertyValue.content,
422
+ label: propertyValue.label
423
+ };
424
+ const globalPropertyValueItem = {
425
+ uuid: propertyValue.uuid,
426
+ count: propertyValue.globalCount ?? propertyValue.count,
427
+ dataType: propertyValue.dataType,
428
+ content: propertyValue.content,
429
+ label: propertyValue.label
430
+ };
431
+ const globalPropertyValueKey = getPropertyValueKey({
432
+ dataType: globalPropertyValueItem.dataType,
433
+ content: propertyValue.content
434
+ });
435
+ const existingGlobalPropertyValue = flattenedPropertyValuesByKey.get(globalPropertyValueKey);
436
+ if (existingGlobalPropertyValue == null) flattenedPropertyValuesByKey.set(globalPropertyValueKey, globalPropertyValueItem);
437
+ else if (existingGlobalPropertyValue.label == null && globalPropertyValueItem.label != null) existingGlobalPropertyValue.label = globalPropertyValueItem.label;
438
+ if (propertyValue.scope === "global") continue;
439
+ if (propertyValue.variableUuid != null) (propertyValuesByPropertyVariableUuid[propertyValue.variableUuid] ??= []).push(propertyValueItem);
440
+ }
441
+ for (const [propertyVariableUuid, values] of Object.entries(propertyValuesByPropertyVariableUuid)) propertyValuesByPropertyVariableUuid[propertyVariableUuid] = sortPropertyValues(values);
442
+ return {
443
+ propertyValuesByPropertyVariableUuid,
444
+ flattenedPropertyValues: sortPropertyValues(flattenedPropertyValuesByKey.values().toArray())
445
+ };
446
+ }
447
+ function collectAttributeValues(parsedAttributeValues) {
448
+ const attributeValuesByType = {
449
+ bibliographies: [],
450
+ periods: []
451
+ };
452
+ for (const attributeValue of parsedAttributeValues) {
453
+ if (attributeValue.content == null || attributeValue.content === "") continue;
454
+ attributeValuesByType[attributeValue.attributeType].push({
455
+ count: attributeValue.count,
456
+ content: attributeValue.content
457
+ });
458
+ }
459
+ return attributeValuesByType;
460
+ }
414
461
  /**
415
462
  * Fetches and parses Set property values from the OCHRE API
416
463
  *
@@ -458,52 +505,12 @@ async function fetchSetPropertyValues(parameters, options) {
458
505
  const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
459
506
  const { success, issues, output } = v.safeParse(responseSchema, data);
460
507
  if (!success) throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
461
- const parsedPropertyValues = [];
462
- const parsedAttributeValues = [];
463
- if (output.result.ochre.propertyValue != null) parsedPropertyValues.push(...Array.isArray(output.result.ochre.propertyValue) ? output.result.ochre.propertyValue : [output.result.ochre.propertyValue]);
464
- if (output.result.ochre.attributeValue != null) parsedAttributeValues.push(...Array.isArray(output.result.ochre.attributeValue) ? output.result.ochre.attributeValue : [output.result.ochre.attributeValue]);
465
- const propertyValuesByPropertyVariableUuid = {};
466
- const flattenedPropertyValuesByKey = /* @__PURE__ */ new Map();
467
- for (const propertyValue of parsedPropertyValues) {
468
- if (propertyValue.content == null) continue;
469
- const propertyValueItem = {
470
- uuid: propertyValue.uuid,
471
- count: propertyValue.count,
472
- dataType: propertyValue.dataType,
473
- content: propertyValue.content,
474
- label: propertyValue.label
475
- };
476
- const globalPropertyValueItem = {
477
- uuid: propertyValue.uuid,
478
- count: propertyValue.globalCount ?? propertyValue.count,
479
- dataType: propertyValue.dataType,
480
- content: propertyValue.content,
481
- label: propertyValue.label
482
- };
483
- const globalPropertyValueKey = getPropertyValueKey({
484
- dataType: globalPropertyValueItem.dataType,
485
- content: propertyValue.content
486
- });
487
- const existingGlobalPropertyValue = flattenedPropertyValuesByKey.get(globalPropertyValueKey);
488
- if (existingGlobalPropertyValue == null) flattenedPropertyValuesByKey.set(globalPropertyValueKey, globalPropertyValueItem);
489
- else if (existingGlobalPropertyValue.label == null && globalPropertyValueItem.label != null) existingGlobalPropertyValue.label = globalPropertyValueItem.label;
490
- if (propertyValue.scope === "global") continue;
491
- if (propertyValue.variableUuid != null) (propertyValuesByPropertyVariableUuid[propertyValue.variableUuid] ??= []).push(propertyValueItem);
492
- }
493
- for (const [propertyVariableUuid, values] of Object.entries(propertyValuesByPropertyVariableUuid)) propertyValuesByPropertyVariableUuid[propertyVariableUuid] = sortPropertyValues(values);
494
- const attributeValuesByType = {
495
- bibliographies: [],
496
- periods: []
497
- };
498
- for (const attributeValue of parsedAttributeValues) {
499
- if (attributeValue.content == null || attributeValue.content === "") continue;
500
- attributeValuesByType[attributeValue.attributeType].push({
501
- count: attributeValue.count,
502
- content: attributeValue.content
503
- });
504
- }
508
+ const parsedPropertyValues = [output.result.ochre.propertyValue ?? []].flat();
509
+ const parsedAttributeValues = [output.result.ochre.attributeValue ?? []].flat();
510
+ const { propertyValuesByPropertyVariableUuid, flattenedPropertyValues } = collectPropertyValues(parsedPropertyValues);
511
+ const attributeValuesByType = collectAttributeValues(parsedAttributeValues);
505
512
  return {
506
- propertyValues: sortPropertyValues(flattenedPropertyValuesByKey.values().toArray()),
513
+ propertyValues: flattenedPropertyValues,
507
514
  propertyValuesByPropertyVariableUuid,
508
515
  attributeValues: {
509
516
  bibliographies: attributes.bibliographies ? sortAttributeValues(attributeValuesByType.bibliographies) : null,
@@ -5,7 +5,7 @@ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
5
5
  * Fetches and parses a page-scoped website metadata projection from the OCHRE
6
6
  * API.
7
7
  */
8
- declare function fetchWebsiteMetadata<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(abbreviation: string, options: FetchBaseOptions<TLanguages> & {
8
+ export declare function fetchWebsiteMetadata<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(abbreviation: string, options: FetchBaseOptions<TLanguages> & {
9
9
  slug: string;
10
10
  }): Promise<{
11
11
  websiteMetadata: WebsiteMetadata<FetchLanguages<TLanguages>>;
@@ -16,5 +16,4 @@ declare function fetchWebsiteMetadata<const TLanguages extends ReadonlyArray<str
16
16
  error: string;
17
17
  detailedError: string;
18
18
  }>;
19
- //#endregion
20
- export { fetchWebsiteMetadata };
19
+ //#endregion
@@ -11,7 +11,7 @@ import { FetchFunction } from "../parsers/helpers.mjs";
11
11
  * `username` and `password` for OCHRE accounts) to authenticate and receive the full
12
12
  * website data.
13
13
  */
14
- declare function fetchWebsite<const T extends LanguageCodes = LanguageCodes>(abbreviation: string, options?: {
14
+ export declare function fetchWebsite<const T extends LanguageCodes = LanguageCodes>(abbreviation: string, options?: {
15
15
  fetch?: FetchFunction;
16
16
  languages?: T;
17
17
  credentials?: string | {
@@ -34,5 +34,4 @@ declare function fetchWebsite<const T extends LanguageCodes = LanguageCodes>(abb
34
34
  error: string;
35
35
  detailedError: string;
36
36
  }>;
37
- //#endregion
38
- export { fetchWebsite };
37
+ //#endregion