ochre-sdk 1.0.53 → 1.0.55

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.
@@ -22,6 +22,7 @@ const XML_ARRAY_TAGS = [
22
22
  "author",
23
23
  "event",
24
24
  "interpretation",
25
+ "interpreter",
25
26
  "observation",
26
27
  "observer",
27
28
  "heading",
@@ -61,13 +62,12 @@ const XML_PARSER_OPTIONS = {
61
62
  textNodeName: "payload",
62
63
  stopNodes: ["*.referenceFormatDiv", "*.citationFormatSpan"],
63
64
  htmlEntities: true,
64
- isArray(tagName, jPath, isLeafNode, isAttribute) {
65
+ isArray(tagName, _, __, isAttribute) {
65
66
  if (isAttribute) return false;
66
- if (XML_ARRAY_TAGS.includes(tagName)) return true;
67
- return false;
67
+ return XML_ARRAY_TAGS.includes(tagName);
68
68
  },
69
- attributeValueProcessor: (attrName, attrValue) => {
70
- if (attrValue.startsWith("xs:")) return attrValue.replace("xs:", "");
69
+ attributeValueProcessor: (_, attributeValue) => {
70
+ if (attributeValue.startsWith("xs:")) return attributeValue.replace("xs:", "");
71
71
  return null;
72
72
  }
73
73
  };
@@ -5,17 +5,17 @@ import { FetchBaseOptions, FetchLanguages } from "../parsers/helpers.mjs";
5
5
  /**
6
6
  * Fetches and parses a gallery from the OCHRE API
7
7
  *
8
- * @param params - The parameters for the fetch
9
- * @param params.uuid - The UUID of the gallery
10
- * @param params.filter - The filter to apply to the gallery
11
- * @param params.page - The page number to fetch
12
- * @param params.perPage - The number of items per page
8
+ * @param parameters - The parameters for the fetch
9
+ * @param parameters.uuid - The UUID of the gallery
10
+ * @param parameters.filter - The filter to apply to the gallery
11
+ * @param parameters.page - The page number to fetch
12
+ * @param parameters.perPage - The number of items per page
13
13
  * @param options - The options for the fetch
14
14
  * @param options.languages - Language codes to parse. Inline arrays preserve literal types automatically.
15
15
  * @param options.fetch - The fetch function to use
16
16
  * @returns The parsed gallery or an error message if the fetch/parse fails
17
17
  */
18
- declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(params: {
18
+ declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
19
19
  uuid: string;
20
20
  filter?: string;
21
21
  page: number;
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utilities.mjs";
3
3
  import { gallerySchema, iso639_3Schema } from "../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
5
  import { parseGallery } from "../parsers/index.mjs";
@@ -8,9 +8,7 @@ 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
- const parsedLanguages = [];
12
- for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
13
- return parsedLanguages;
11
+ return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
14
12
  }
15
13
  function isRecord(value) {
16
14
  return typeof value === "object" && value !== null;
@@ -35,8 +33,8 @@ function resolveGalleryLanguages(data, requestedLanguages) {
35
33
  collectContentLanguages(data.result.ochre.gallery, languages);
36
34
  return languages.size > 0 ? [...languages] : [...DEFAULT_LANGUAGES];
37
35
  }
38
- function buildXQuery(params) {
39
- const { uuid, filter, page, perPage } = params;
36
+ function buildXQuery(parameters) {
37
+ const { uuid, filter, page, perPage } = parameters;
40
38
  const start = (page - 1) * perPage + 1;
41
39
  const filterLiteral = stringLiteral(filter?.trim() ?? "");
42
40
  return `<ochre>{
@@ -55,9 +53,9 @@ function buildXQuery(params) {
55
53
  }</gallery>
56
54
  }</ochre>`;
57
55
  }
58
- async function fetchGallery(params, options) {
56
+ async function fetchGallery(parameters, options) {
59
57
  try {
60
- const { uuid, filter, page, perPage } = v.parse(gallerySchema, params);
58
+ const { uuid, filter, page, perPage } = v.parse(gallerySchema, parameters);
61
59
  const requestedLanguages = options?.languages == null ? [] : parseLanguages(options.languages);
62
60
  const response = await (options?.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
63
61
  method: "POST",
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utilities.mjs";
3
3
  import { iso639_3Schema, uuidSchema } from "../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
5
  import { parseLinkedItems } from "../parsers/index.mjs";
@@ -21,9 +21,7 @@ const ITEM_COLLECTION_CATEGORIES = [
21
21
  "set"
22
22
  ];
23
23
  function parseLanguages(languages) {
24
- const parsedLanguages = [];
25
- for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
26
- return parsedLanguages;
24
+ return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
27
25
  }
28
26
  function isRecord(value) {
29
27
  return typeof value === "object" && value !== null;
@@ -50,8 +48,7 @@ function resolveItemChildrenLanguages(data, requestedLanguages) {
50
48
  }
51
49
  function buildXQuery(uuid, category) {
52
50
  const categories = category == null ? ITEM_COLLECTION_CATEGORIES : typeof category === "string" ? [category] : category;
53
- const collectionQueries = [];
54
- for (const possibleCategory of categories) collectionQueries.push(`cts:search(fn:collection("ochre/${possibleCategory}")/ochre, $uuid-query)`);
51
+ const collectionQueries = Array.from(categories, (possibleCategory) => `cts:search(fn:collection("ochre/${possibleCategory}")/ochre, $uuid-query)`);
55
52
  return `xquery version "1.0-ml";
56
53
 
57
54
  declare function local:item-children($nodes as node()*) as node()* {
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput } from "../utilities.mjs";
3
3
  import { iso639_3Schema, uuidSchema } from "../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
5
  import { parseLinkedItems } from "../parsers/index.mjs";
@@ -8,9 +8,7 @@ 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
- const parsedLanguages = [];
12
- for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
13
- return parsedLanguages;
11
+ return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
14
12
  }
15
13
  function isRecord(value) {
16
14
  return typeof value === "object" && value !== null;
@@ -1,5 +1,5 @@
1
1
  import { XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utilities.mjs";
3
3
  import { iso639_3Schema, uuidSchema } from "../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
5
  import { parseItem } from "../parsers/index.mjs";
@@ -12,7 +12,15 @@ function isItemContainerCategory(category) {
12
12
  return category === "tree" || category === "set";
13
13
  }
14
14
  function isItemCategoryWithEmbeddedItems(category) {
15
- return category === "tree" || category === "bibliography" || category === "concept" || category === "spatialUnit" || category === "period" || category === "resource" || category === "set";
15
+ return [
16
+ "tree",
17
+ "bibliography",
18
+ "concept",
19
+ "spatialUnit",
20
+ "period",
21
+ "resource",
22
+ "set"
23
+ ].includes(category);
16
24
  }
17
25
  function isItemWithEmbeddedItems(item) {
18
26
  return isItemCategoryWithEmbeddedItems(item.category);
@@ -35,8 +43,7 @@ function buildOmitEmbeddedItemsXQuery(uuid, category) {
35
43
  "set"
36
44
  ] : typeof category === "string" ? [category] : category;
37
45
  for (const possibleCategory of categories) if (!collectionCategories.includes(possibleCategory)) collectionCategories.push(possibleCategory);
38
- const collectionQueries = [];
39
- for (const collectionCategory of collectionCategories) collectionQueries.push(`cts:search(fn:collection("ochre/${collectionCategory}")/ochre, $uuid-query)`);
46
+ const collectionQueries = Array.from(collectionCategories, (collectionCategory) => `cts:search(fn:collection("ochre/${collectionCategory}")/ochre, $uuid-query)`);
40
47
  return `xquery version "1.0-ml";
41
48
 
42
49
  let $uuid := ${stringLiteral(uuid)}
@@ -73,9 +80,7 @@ function omitEmbeddedItems(item) {
73
80
  * Validate language codes while preserving literal tuple inference.
74
81
  */
75
82
  function parseLanguages(languages) {
76
- const parsedLanguages = [];
77
- for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
78
- return parsedLanguages;
83
+ return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
79
84
  }
80
85
  /**
81
86
  * Defines a reusable languages tuple with validation and literal type inference.
@@ -6,19 +6,19 @@ type FetchSetItemsCategory<TContainedItemCategories extends ReadonlyArray<SetIte
6
6
  /**
7
7
  * Fetches and parses Set items from the OCHRE API
8
8
  *
9
- * @param params - The parameters for the fetch
10
- * @param params.setScopeUuids - The Set scope UUIDs to filter by
11
- * @param params.queries - Recursive query tree used to filter matching items
12
- * @param params.sort - Optional sorting configuration applied before pagination.
9
+ * @param parameters - The parameters for the fetch
10
+ * @param parameters.setScopeUuids - The Set scope UUIDs to filter by
11
+ * @param parameters.queries - Recursive query tree used to filter matching items
12
+ * @param parameters.sort - Optional sorting configuration applied before pagination.
13
13
  * For propertyValue sorting, dataType is required and the sort key uses the first valid leaf value (value[not(@i)]).
14
- * @param params.page - The page number (1-indexed)
15
- * @param params.pageSize - The number of items per page
14
+ * @param parameters.page - The page number (1-indexed)
15
+ * @param parameters.pageSize - The number of items per page
16
16
  * @param containedItemCategories - The categories of the items to fetch
17
17
  * @param options - Options for the fetch
18
18
  * @param options.fetch - The fetch function to use
19
19
  * @returns The parsed Set items or null if the fetch/parse fails
20
20
  */
21
- declare function fetchSetItems<const TContainedItemCategories extends ReadonlyArray<SetItemCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(params: {
21
+ declare function fetchSetItems<const TContainedItemCategories extends ReadonlyArray<SetItemCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(parameters: {
22
22
  setScopeUuids: Array<string>;
23
23
  queries?: Query | null;
24
24
  sort?: SetItemsSort;
@@ -1,6 +1,6 @@
1
1
  import { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utils.mjs";
3
- import { iso639_3Schema, setItemsParamsSchema } from "../../schemas.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utilities.mjs";
3
+ import { iso639_3Schema, setItemsParametersSchema } from "../../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../../xml/metadata.mjs";
5
5
  import { parseSetItems } from "../../parsers/index.mjs";
6
6
  import { XMLSetItemsData } from "../../xml/schemas.mjs";
@@ -9,9 +9,7 @@ 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
- const parsedLanguages = [];
13
- for (const language of languages) parsedLanguages.push(v.parse(iso639_3Schema, language));
14
- return parsedLanguages;
12
+ return Array.from(languages, (language) => v.parse(iso639_3Schema, language));
15
13
  }
16
14
  function isRecord(value) {
17
15
  return typeof value === "object" && value !== null;
@@ -73,8 +71,8 @@ function buildPropertyValueStringSortKeyExpression(sort) {
73
71
  where string-length($candidate) gt 0
74
72
  return $candidate)[1])`;
75
73
  }
76
- function buildPropertyValueTypedSortKeyExpression(params) {
77
- const { sort, dataType } = params;
74
+ function buildPropertyValueTypedSortKeyExpression(parameters) {
75
+ const { sort, dataType } = parameters;
78
76
  const propertyValuePath = buildPropertyValueValuePath(sort);
79
77
  switch (dataType) {
80
78
  case "integer": return `(for $v in ${propertyValuePath}
@@ -100,9 +98,9 @@ function buildPropertyValueTypedSortKeyExpression(params) {
100
98
  return xs:dateTime($candidate))[1]`;
101
99
  }
102
100
  }
103
- function buildPropertyValueOrderByClause(params) {
104
- const { dataType, direction } = params;
105
- return dataType === "string" || dataType === "IDREF" ? buildStringOrderByClause(direction) : buildTypedOrderByClause(direction);
101
+ function buildPropertyValueOrderByClause(parameters) {
102
+ const { dataType, direction } = parameters;
103
+ return (dataType === "string" || dataType === "IDREF" ? buildStringOrderByClause : buildTypedOrderByClause)(direction);
106
104
  }
107
105
  function buildOrderedItemsClause(sort) {
108
106
  if (sort.target === "none") return "let $orderedItems := $items";
@@ -126,18 +124,18 @@ function buildOrderedItemsClause(sort) {
126
124
  }
127
125
  /**
128
126
  * Build an XQuery string to fetch Set items from the OCHRE API
129
- * @param params - The parameters for the fetch
130
- * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
131
- * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
132
- * @param params.queries - Recursive query tree used to filter matching items
133
- * @param params.sort - Optional sorting configuration applied before pagination.
127
+ * @param parameters - The parameters for the fetch
128
+ * @param parameters.setScopeUuids - An array of Set scope UUIDs to filter by
129
+ * @param parameters.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
130
+ * @param parameters.queries - Recursive query tree used to filter matching items
131
+ * @param parameters.sort - Optional sorting configuration applied before pagination.
134
132
  * For propertyValue sorting, dataType is required and the sort key uses the first valid leaf value (value[not(@i)]).
135
- * @param params.page - The page number (1-indexed)
136
- * @param params.pageSize - The number of items per page
133
+ * @param parameters.page - The page number (1-indexed)
134
+ * @param parameters.pageSize - The number of items per page
137
135
  * @returns An XQuery string
138
136
  */
139
- function buildXQuery(params) {
140
- const { queries, sort, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = params;
137
+ function buildXQuery(parameters) {
138
+ const { queries, sort, setScopeUuids, belongsToCollectionScopeUuids, page, pageSize } = parameters;
141
139
  const startPosition = (page - 1) * pageSize + 1;
142
140
  const setScopeDeclaration = `declare variable $setScopeUuids := (${setScopeUuids.map((uuid) => stringLiteral(uuid)).join(", ")});`;
143
141
  const baseItemsExpression = "doc()/ochre/set[@uuid = $setScopeUuids]/items/*";
@@ -165,9 +163,9 @@ ${itemsClause}
165
163
  }</items>
166
164
  }</ochre>`;
167
165
  }
168
- async function fetchSetItems(params, containedItemCategories, options) {
166
+ async function fetchSetItems(parameters, containedItemCategories, options) {
169
167
  try {
170
- const { setScopeUuids, belongsToCollectionScopeUuids, queries, sort, page, pageSize } = v.parse(setItemsParamsSchema, params);
168
+ const { setScopeUuids, belongsToCollectionScopeUuids, queries, sort, page, pageSize } = v.parse(setItemsParametersSchema, parameters);
171
169
  const requestedLanguages = options?.languages == null ? [] : parseLanguages(options.languages);
172
170
  const xquery = buildXQuery({
173
171
  setScopeUuids,
@@ -199,7 +197,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
199
197
  });
200
198
  const itemsByUuid = /* @__PURE__ */ new Map();
201
199
  for (const item of items) if (!itemsByUuid.has(item.uuid)) itemsByUuid.set(item.uuid, item);
202
- const uniqueItems = [...itemsByUuid.values()];
200
+ const uniqueItems = itemsByUuid.values().toArray();
203
201
  return {
204
202
  totalCount: output.result.ochre.items.totalCount,
205
203
  page: output.result.ochre.items.page,
@@ -4,19 +4,19 @@ import { PropertyValueQueryItem, Query, SetAttributeValueQueryItem } from "../..
4
4
  /**
5
5
  * Fetches and parses Set property values from the OCHRE API
6
6
  *
7
- * @param params - The parameters for the fetch
8
- * @param params.setScopeUuids - An array of set scope UUIDs to filter by
9
- * @param params.queries - Recursive query tree used to filter matching items
10
- * @param params.attributes - Whether to return values for bibliographies and periods
11
- * @param params.attributes.bibliographies - Whether to return values for bibliographies
12
- * @param params.attributes.periods - Whether to return values for periods
13
- * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
7
+ * @param parameters - The parameters for the fetch
8
+ * @param parameters.setScopeUuids - An array of set scope UUIDs to filter by
9
+ * @param parameters.queries - Recursive query tree used to filter matching items
10
+ * @param parameters.attributes - Whether to return values for bibliographies and periods
11
+ * @param parameters.attributes.bibliographies - Whether to return values for bibliographies
12
+ * @param parameters.attributes.periods - Whether to return values for periods
13
+ * @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
14
14
  * @param options - Options for the fetch
15
15
  * @param options.fetch - The fetch function to use
16
16
  * @returns Parsed Set property values and requested attribute values.
17
17
  * Returns empty arrays/objects when no matches are found, and null outputs on fetch/parse errors.
18
18
  */
19
- declare function fetchSetPropertyValues(params: {
19
+ declare function fetchSetPropertyValues(parameters: {
20
20
  setScopeUuids: Array<string>;
21
21
  queries?: Query | null;
22
22
  attributes?: {
@@ -1,7 +1,7 @@
1
1
  import { BELONGS_TO_COLLECTION_UUID, DEFAULT_LANGUAGES, XML_PARSER_OPTIONS } from "../../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../../utilities.mjs";
3
3
  import { MultilingualString } from "../../parsers/multilingual.mjs";
4
- import { setPropertyValuesParamsSchema } from "../../schemas.mjs";
4
+ import { setPropertyValuesParametersSchema } from "../../schemas.mjs";
5
5
  import { parseXMLContent } from "../../parsers/string.mjs";
6
6
  import { buildAndCtsQueryExpression, buildBelongsToCollectionQueryExpression, buildQueryPlan } from "../../query.mjs";
7
7
  import * as v from "valibot";
@@ -58,9 +58,9 @@ function sortAttributeValues(values) {
58
58
  return a.content.localeCompare(b.content);
59
59
  });
60
60
  }
61
- const countSchema = v.pipe(v.optional(v.union([v.number(), v.string()]), 1), v.transform((val) => {
62
- if (val === "") return 1;
63
- const count = Number(val);
61
+ const countSchema = v.pipe(v.optional(v.union([v.number(), v.string()]), 1), v.transform((value) => {
62
+ if (value === "") return 1;
63
+ const count = Number(value);
64
64
  return Number.isFinite(count) ? count : 1;
65
65
  }));
66
66
  const propertyValueLabelStringSchema = v.object({ payload: v.optional(v.string(), "") });
@@ -69,10 +69,12 @@ const propertyValueLabelContentSchema = v.object({
69
69
  string: v.array(propertyValueLabelStringSchema)
70
70
  });
71
71
  function getPropertyFacetSelectorsFromQueries(queries) {
72
- const propertyFacetSelectors = /* @__PURE__ */ new Map();
73
72
  if (queries == null) return [];
73
+ const propertyFacetSelectors = /* @__PURE__ */ new Map();
74
74
  const pendingQueries = [queries];
75
- for (const query of pendingQueries) {
75
+ while (pendingQueries.length > 0) {
76
+ const query = pendingQueries.shift();
77
+ if (query == null) continue;
76
78
  if ("target" in query) {
77
79
  if (query.target !== "property") continue;
78
80
  if (query.propertyVariable != null) {
@@ -86,7 +88,7 @@ function getPropertyFacetSelectorsFromQueries(queries) {
86
88
  }
87
89
  pendingQueries.push(..."and" in query ? query.and : query.or);
88
90
  }
89
- return [...propertyFacetSelectors.values()];
91
+ return propertyFacetSelectors.values().toArray();
90
92
  }
91
93
  function getItemFilterQueriesFromPropertyValueQueries(queries) {
92
94
  if (queries == null) return null;
@@ -118,37 +120,37 @@ const propertyValueQueryItemSchema = v.pipe(v.object({
118
120
  rawValue: v.optional(v.string()),
119
121
  payload: v.optional(v.string()),
120
122
  content: v.optional(v.array(propertyValueLabelContentSchema))
121
- }), v.transform((val) => {
122
- const dataType = normalizePropertyValueDataType(val.dataType);
123
- const label = parsePropertyValueLabel(val.content, val.payload);
123
+ }), v.transform((value) => {
124
+ const dataType = normalizePropertyValueDataType(value.dataType);
125
+ const label = parsePropertyValueLabel(value.content, value.payload);
124
126
  const returnValue = {
125
- uuid: val.uuid !== "" ? val.uuid : null,
126
- scope: val.scope,
127
- variableUuid: val.variableUuid != null && val.variableUuid !== "" ? val.variableUuid : null,
128
- count: val.count,
129
- globalCount: val.globalCount ?? null,
127
+ uuid: value.uuid !== "" ? value.uuid : null,
128
+ scope: value.scope,
129
+ variableUuid: value.variableUuid != null && value.variableUuid !== "" ? value.variableUuid : null,
130
+ count: value.count,
131
+ globalCount: value.globalCount ?? null,
130
132
  dataType,
131
133
  content: null,
132
134
  label
133
135
  };
134
136
  switch (dataType) {
135
137
  case "IDREF":
136
- returnValue.content = val.uuid !== "" ? val.uuid : null;
138
+ returnValue.content = value.uuid !== "" ? value.uuid : null;
137
139
  break;
138
140
  case "integer":
139
141
  case "decimal":
140
142
  case "time":
141
- if (val.rawValue != null && val.rawValue !== "") {
142
- const numericContent = Number(val.rawValue);
143
+ if (value.rawValue != null && value.rawValue !== "") {
144
+ const numericContent = Number(value.rawValue);
143
145
  returnValue.content = Number.isNaN(numericContent) ? null : numericContent;
144
146
  }
145
147
  break;
146
148
  case "boolean":
147
- returnValue.content = parsePropertyValueBooleanContent(val.rawValue);
149
+ returnValue.content = parsePropertyValueBooleanContent(value.rawValue);
148
150
  break;
149
151
  default: {
150
152
  const labelText = label?.getText() ?? null;
151
- returnValue.content = val.rawValue != null && val.rawValue !== "" ? val.rawValue.toString() : labelText;
153
+ returnValue.content = value.rawValue != null && value.rawValue !== "" ? value.rawValue : labelText;
152
154
  break;
153
155
  }
154
156
  }
@@ -159,10 +161,10 @@ const attributeValueQueryItemSchema = v.pipe(v.object({
159
161
  count: countSchema,
160
162
  content: v.optional(v.string()),
161
163
  payload: v.optional(v.string())
162
- }), v.transform((val) => ({
163
- attributeType: val.attributeType,
164
- count: val.count,
165
- content: val.content != null && val.content !== "" ? val.content : val.payload != null && val.payload !== "" ? val.payload : null
164
+ }), v.transform((value) => ({
165
+ attributeType: value.attributeType,
166
+ count: value.count,
167
+ content: value.content != null && value.content !== "" ? value.content : value.payload != null && value.payload !== "" ? value.payload : null
166
168
  })));
167
169
  /**
168
170
  * Schema for the property values OCHRE API response
@@ -174,19 +176,19 @@ const responseSchema = v.object({ result: v.object({ ochre: v.object({
174
176
  }) }) });
175
177
  /**
176
178
  * Build an XQuery string to fetch property values from the OCHRE API
177
- * @param params - The parameters for the fetch
178
- * @param params.setScopeUuids - An array of set scope UUIDs to filter by
179
- * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
180
- * @param params.queries - Recursive query tree used to filter matching items
181
- * @param params.propertyFacetSelectors - Property variable/relation selectors to aggregate, if any
182
- * @param params.attributes - Whether to return values for bibliographies and periods
183
- * @param params.attributes.bibliographies - Whether to return values for bibliographies
184
- * @param params.attributes.periods - Whether to return values for periods
185
- * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
179
+ * @param parameters - The parameters for the fetch
180
+ * @param parameters.setScopeUuids - An array of set scope UUIDs to filter by
181
+ * @param parameters.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
182
+ * @param parameters.queries - Recursive query tree used to filter matching items
183
+ * @param parameters.propertyFacetSelectors - Property variable/relation selectors to aggregate, if any
184
+ * @param parameters.attributes - Whether to return values for bibliographies and periods
185
+ * @param parameters.attributes.bibliographies - Whether to return values for bibliographies
186
+ * @param parameters.attributes.periods - Whether to return values for periods
187
+ * @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
186
188
  * @returns An XQuery string
187
189
  */
188
- function buildXQuery(params) {
189
- const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = params;
190
+ function buildXQuery(parameters) {
191
+ const { setScopeUuids, belongsToCollectionScopeUuids, queries, propertyFacetSelectors, attributes, isLimitedToLeafPropertyValues } = parameters;
190
192
  const setScopeDeclaration = `declare variable $setScopeUuids := (${setScopeUuids.map((uuid) => stringLiteral(uuid)).join(", ")});`;
191
193
  const baseItemsExpression = "doc()/ochre/set[@uuid = $setScopeUuids]/items/*";
192
194
  const compiledQueryPlan = buildQueryPlan({ queries: getItemFilterQueriesFromPropertyValueQueries(queries) });
@@ -416,21 +418,21 @@ return (${returnedSequences.join(", ")})
416
418
  /**
417
419
  * Fetches and parses Set property values from the OCHRE API
418
420
  *
419
- * @param params - The parameters for the fetch
420
- * @param params.setScopeUuids - An array of set scope UUIDs to filter by
421
- * @param params.queries - Recursive query tree used to filter matching items
422
- * @param params.attributes - Whether to return values for bibliographies and periods
423
- * @param params.attributes.bibliographies - Whether to return values for bibliographies
424
- * @param params.attributes.periods - Whether to return values for periods
425
- * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
421
+ * @param parameters - The parameters for the fetch
422
+ * @param parameters.setScopeUuids - An array of set scope UUIDs to filter by
423
+ * @param parameters.queries - Recursive query tree used to filter matching items
424
+ * @param parameters.attributes - Whether to return values for bibliographies and periods
425
+ * @param parameters.attributes.bibliographies - Whether to return values for bibliographies
426
+ * @param parameters.attributes.periods - Whether to return values for periods
427
+ * @param parameters.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
426
428
  * @param options - Options for the fetch
427
429
  * @param options.fetch - The fetch function to use
428
430
  * @returns Parsed Set property values and requested attribute values.
429
431
  * Returns empty arrays/objects when no matches are found, and null outputs on fetch/parse errors.
430
432
  */
431
- async function fetchSetPropertyValues(params, options) {
433
+ async function fetchSetPropertyValues(parameters, options) {
432
434
  try {
433
- const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = v.parse(setPropertyValuesParamsSchema, params);
435
+ const { setScopeUuids, belongsToCollectionScopeUuids, queries, attributes, isLimitedToLeafPropertyValues } = v.parse(setPropertyValuesParametersSchema, parameters);
434
436
  const propertyFacetSelectors = getPropertyFacetSelectorsFromQueries(queries);
435
437
  if (propertyFacetSelectors.length === 0 && !attributes.bibliographies && !attributes.periods) return {
436
438
  propertyValues: [],
@@ -505,7 +507,7 @@ async function fetchSetPropertyValues(params, options) {
505
507
  });
506
508
  }
507
509
  return {
508
- propertyValues: sortPropertyValues([...flattenedPropertyValuesByKey.values()]),
510
+ propertyValues: sortPropertyValues(flattenedPropertyValuesByKey.values().toArray()),
509
511
  propertyValuesByPropertyVariableUuid,
510
512
  attributeValues: {
511
513
  bibliographies: attributes.bibliographies ? sortAttributeValues(attributeValuesByType.bibliographies) : null,
@@ -1,5 +1,5 @@
1
1
  import { XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput, stringLiteral } from "../utilities.mjs";
3
3
  import { iso639_3Schema } from "../schemas.mjs";
4
4
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
5
5
  import { parseStringLike } from "../parsers/helpers.mjs";
@@ -34,7 +34,7 @@ function parseWebsiteMetadata(data, options) {
34
34
  } }
35
35
  };
36
36
  }
37
- function buildXQuery(params) {
37
+ function buildXQuery(parameters) {
38
38
  return String.raw`xquery version "1.0-ml";
39
39
 
40
40
  declare function local:resource-items($resources) {
@@ -118,8 +118,8 @@ declare function local:metadata-tree($tree, $target-slug, $slug-prefix) {
118
118
  }
119
119
  };
120
120
 
121
- let $website := collection("ochre/tree")/ochre[tree/identification/abbreviation/content/string = ${stringLiteral(params.abbreviation)}][1]
122
- let $target-slug := ${stringLiteral(params.slug)}
121
+ let $website := collection("ochre/tree")/ochre[tree/identification/abbreviation/content/string = ${stringLiteral(parameters.abbreviation)}][1]
122
+ let $target-slug := ${stringLiteral(parameters.slug)}
123
123
  return
124
124
  <ochre>{
125
125
  $website/@uuid,
@@ -133,11 +133,10 @@ return
133
133
  }
134
134
  async function fetchWebsiteMetadata(abbreviation, options) {
135
135
  try {
136
- const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
137
136
  if (options?.slug == null) throw new Error("Website metadata slug is required");
137
+ const cleanAbbreviation = abbreviation.trim().toLocaleLowerCase("en-US");
138
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));
139
+ const requestedLanguages = Array.from(options.languages ?? [], (language) => v.parse(iso639_3Schema, language));
141
140
  const response = await (options.fetch ?? fetch)("https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery&xsl=none&lang=\"*\"", {
142
141
  method: "POST",
143
142
  body: buildXQuery({
@@ -1,5 +1,5 @@
1
1
  import { XML_PARSER_OPTIONS } from "../constants.mjs";
2
- import { createSchemaValidationError, getErrorOutput } from "../utils.mjs";
2
+ import { createSchemaValidationError, getErrorOutput } from "../utilities.mjs";
3
3
  import { restoreXMLMetadata } from "../xml/metadata.mjs";
4
4
  import { XMLWebsiteData } from "../xml/schemas.mjs";
5
5
  import { parseWebsite } from "../parsers/website/index.mjs";