ochre-sdk 1.3.18 → 1.3.20

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.
@@ -90,6 +90,16 @@ declare function local:matching-pages($resources, $target-slug, $slug-prefix) {
90
90
  )
91
91
  };
92
92
 
93
+ declare function local:oak-collection-pages($tree, $resources, $target-slug) {
94
+ if ($tree/properties/property[label/string() = "presentation"][value/string() = "website"]/property[label/string() = "webUI"]/value/string() = "oak") then
95
+ for $resource in $resources[local:presentation(.) = "element"]
96
+ let $slug := local:clean-slug($resource/@slug)
97
+ where string(($resource/properties/property[label/string() = "presentation"]/property[label/string() = "component"]/value)[1]) = "collection"
98
+ and (if ($slug != "") then $slug else string(($resource/identification/abbreviation/content/string)[1])) = $target-slug
99
+ return local:metadata-page($resource)
100
+ else ()
101
+ };
102
+
93
103
  declare function local:metadata-tree($tree, $target-slug, $slug-prefix) {
94
104
  let $resources := local:resource-items($tree/items/resource)
95
105
  let $presentation-properties := $tree/properties/property[label/string() = "presentation"][value/string() = "website"]/property[label/string() = (${Object.values(METADATA_PRESENTATION_LABELS).map((label) => stringLiteral(label)).join(", ")})]
@@ -103,7 +113,8 @@ declare function local:metadata-tree($tree, $target-slug, $slug-prefix) {
103
113
  $resources[local:presentation(.) = "page"],
104
114
  $target-slug,
105
115
  $slug-prefix
106
- )
116
+ ),
117
+ local:oak-collection-pages($tree, $resources, $target-slug)
107
118
  }
108
119
  }
109
120
  };
@@ -65,7 +65,8 @@ function parseCollectionPropertyOverrides(reader) {
65
65
  read("isSortDisplayed", "sort-displayed");
66
66
  read("isUsingQueryParams", "is-using-query-params");
67
67
  read("isInteractive", "is-interactive");
68
- readImage("layout", "image-layout");
68
+ const imageLayout = reader.value("image-layout");
69
+ if (imageLayout != null) imageOverrides.layout = imageLayout === "suppress" ? null : imageLayout;
69
70
  readImage("fit", "image-fit");
70
71
  readImage("alignment", "image-alignment");
71
72
  readImage("isPlaceholderDisplayed", "image-placeholder-displayed");
@@ -456,7 +457,7 @@ function parseMapComponent(parameters) {
456
457
  const maximumBoundsProperty = componentReader.value("maximum-bounds");
457
458
  if (maximumBoundsProperty !== null) maximumBounds = parseBounds(String(maximumBoundsProperty));
458
459
  const layerSettings = [];
459
- for (const layerReader of componentReader.nestedAllByValue("customize-special", "arcgis-layer")) {
460
+ for (const layerReader of componentReader.nestedAllByValue("customize-special", "map-layer")) {
460
461
  const uuid = layerReader.uuid("use-layer");
461
462
  if (uuid == null) continue;
462
463
  const opacity = layerReader.value("opacity-percent");
@@ -1,9 +1,11 @@
1
- import { cleanObject, parseLicense, parseRequiredContentLike } from "../helpers.mjs";
1
+ import { cleanObject, parseLicense, parseRequiredContentLike, parseStringContent } from "../helpers.mjs";
2
2
  import { parseMetadataLanguages, resolveDefaultLanguage, resolveLanguages } from "../languages.mjs";
3
3
  import { parseIdentification, parseLinks, parseMetadata, parsePersonList, parseSimplifiedProperties } from "../index.mjs";
4
4
  import { findWebsiteLink, parseWebsiteLinkTarget, webImageFromLink } from "./links.mjs";
5
+ import { formatXMLWebsiteResourceMetadata } from "./messages.mjs";
5
6
  import { websitePresentationReader } from "./reader.mjs";
6
7
  import { emptyResponsiveStyles, parseResponsiveCssStyles } from "./styles.mjs";
8
+ import { cleanWebsitePageSlug } from "./slug.mjs";
7
9
  import { collectWebsitePageSlugs, normalizeWebsiteResources, readWebsitePages } from "./walk.mjs";
8
10
  import { parseWebElement, parseWebTitle } from "./components.mjs";
9
11
  import { parseWebsiteProperties } from "./properties.mjs";
@@ -53,23 +55,13 @@ function parseWebpageRedirect(redirectValue, context) {
53
55
  };
54
56
  return null;
55
57
  }
56
- /**
57
- * Parses a walked page node into a standardized Webpage structure
58
- *
59
- * @param page - The page node, with its slug and nesting already resolved
60
- * @returns Parsed Webpage object
61
- */
62
- function parseWebpage(page, options, context) {
63
- const webpageResource = page.resource;
64
- const webpageProperties = parseSimplifiedProperties(webpageResource.properties, options);
65
- const webpageReader = websitePresentationReader(webpageProperties);
66
- const identification = parseIdentification(webpageResource.identification, options);
67
- const returnWebpage = {
68
- uuid: webpageResource.uuid,
58
+ function createWebpage(resource, slug, options) {
59
+ return {
60
+ uuid: resource.uuid,
69
61
  type: "page",
70
- title: identification.label,
71
- slug: page.slug,
72
- publicationDateTime: webpageResource.publicationDateTime ?? null,
62
+ title: parseIdentification(resource.identification, options).label,
63
+ slug,
64
+ publicationDateTime: resource.publicationDateTime ?? null,
73
65
  items: [],
74
66
  segments: [],
75
67
  properties: {
@@ -86,6 +78,18 @@ function parseWebpage(page, options, context) {
86
78
  },
87
79
  webpages: []
88
80
  };
81
+ }
82
+ /**
83
+ * Parses a walked page node into a standardized Webpage structure
84
+ *
85
+ * @param page - The page node, with its slug and nesting already resolved
86
+ * @returns Parsed Webpage object
87
+ */
88
+ function parseWebpage(page, options, context) {
89
+ const webpageResource = page.resource;
90
+ const webpageProperties = parseSimplifiedProperties(webpageResource.properties, options);
91
+ const webpageReader = websitePresentationReader(webpageProperties);
92
+ const returnWebpage = createWebpage(webpageResource, page.slug, options);
89
93
  const websiteLinks = parseLinks(webpageResource.links, options);
90
94
  const imageLink = findWebsiteLink(websiteLinks, "resource", (link) => link.type === "image" || link.type === "IIIF");
91
95
  const webpageResources = normalizeWebsiteResources(webpageResource.resource);
@@ -265,6 +269,36 @@ function parseWebBlock(blockResource, options, context) {
265
269
  returnBlock.cssStyles = parseResponsiveCssStyles(blockProperties);
266
270
  return returnBlock;
267
271
  }
272
+ function parseOakWebsite(resources, webpages, options, context) {
273
+ const webpagesByUuid = new Map(webpages.map((webpage) => [webpage.uuid, webpage]));
274
+ const items = [];
275
+ let map = null;
276
+ for (const resource of resources) {
277
+ const webpage = webpagesByUuid.get(resource.uuid);
278
+ if (webpage != null) {
279
+ items.push(webpage);
280
+ continue;
281
+ }
282
+ const component = websitePresentationReader(parseSimplifiedProperties(resource.properties, options)).nestedByValue("presentation", "element").value("component");
283
+ if (component !== "map" && component !== "collection") continue;
284
+ const element = parseWebElement(resource, options, context.pageSlugsByUuid);
285
+ if (element.component === "map") {
286
+ map ??= element;
287
+ continue;
288
+ }
289
+ const resourceSlug = cleanWebsitePageSlug(resource.slug) ?? "";
290
+ const slug = resourceSlug === "" ? parseStringContent(resource.identification.abbreviation, options) : resourceSlug;
291
+ if (slug === "") throw new Error(`Slug not found for OAK collection (${formatXMLWebsiteResourceMetadata(resource)})`, { cause: resource });
292
+ const collectionPage = createWebpage(resource, slug, options);
293
+ collectionPage.items = [element];
294
+ collectionPage.properties.isDisplayedInNavbar = false;
295
+ items.push(collectionPage);
296
+ }
297
+ return {
298
+ items,
299
+ oak: { map }
300
+ };
301
+ }
268
302
  function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
269
303
  if (!websiteTree.properties) throw new Error(`Website properties not found (website uuid “${websiteTree.uuid}”)`, { cause: websiteTree });
270
304
  if (type === "website" && websiteTree.items?.resource == null) throw new Error(`Website pages not found (website uuid “${websiteTree.uuid}”)`, { cause: websiteTree });
@@ -278,6 +312,15 @@ function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
278
312
  const sidebar = parseSidebar(resources, options, treeContext);
279
313
  const properties = parseWebsiteProperties(websiteTree.properties.property, websiteTree, sidebar, options, context.parentProperties ?? null);
280
314
  const license = parseLicense(websiteTree.availability) ?? context.parentLicense ?? null;
315
+ const webpages = parseWebpages(pages, options, {
316
+ ...treeContext,
317
+ parentProperties: properties,
318
+ parentLicense: license
319
+ });
320
+ const { items, oak } = type === "website" && properties.type === "oak" ? parseOakWebsite(resources, webpages, options, treeContext) : {
321
+ items: webpages,
322
+ oak: null
323
+ };
281
324
  return {
282
325
  uuid: websiteTree.uuid,
283
326
  type,
@@ -287,12 +330,9 @@ function parseWebsiteTree(websiteTree, options, context, type, slugPrefix) {
287
330
  identification: parseIdentification(websiteTree.identification, options),
288
331
  creators: websiteTree.creators ? parsePersonList(websiteTree.creators.creator, options) : [],
289
332
  license,
290
- items: parseWebpages(pages, options, {
291
- ...treeContext,
292
- parentProperties: properties,
293
- parentLicense: license
294
- }),
295
- properties
333
+ items,
334
+ properties,
335
+ oak
296
336
  };
297
337
  }
298
338
  function parseWebsite(data, options) {
package/dist/query.mjs CHANGED
@@ -232,12 +232,12 @@ function buildPropertyLabelQuery(propertyVariable) {
232
232
  value: searchValue(propertyVariable)
233
233
  });
234
234
  }
235
- function buildValueNotIdReferenceQuery() {
236
- return buildNotCtsQueryExpression(buildPlainElementAttributeValueQueryExpression({
235
+ function buildValueIdReferenceQuery() {
236
+ return buildPlainElementAttributeValueQueryExpression({
237
237
  elementName: "value",
238
238
  attributeName: "dataType",
239
- value: searchValue("IDREF")
240
- }));
239
+ value: searchValue("xs:IDREF")
240
+ });
241
241
  }
242
242
  /**
243
243
  * Match a field's `content` in a language, falling back to another language
@@ -435,7 +435,6 @@ function buildPropertyAllQueryExpression(parameters) {
435
435
  return buildPropertyTextMatchQueryExpression({
436
436
  propertyVariable: query.propertyVariable,
437
437
  propertyRelation: query.propertyRelation,
438
- valueFilters: [buildValueNotIdReferenceQuery()],
439
438
  contentQueryExpression: buildRichTextContentQueryExpression({
440
439
  language: query.language,
441
440
  fallbackLanguage: query.fallbackLanguage,
@@ -467,6 +466,26 @@ function buildPropertyIdReferenceQueryExpression(parameters) {
467
466
  }))
468
467
  });
469
468
  }
469
+ function buildPropertyIdReferenceTextQueryExpression(parameters) {
470
+ const { propertyVariable, propertyRelation, value, matchMode, isCaseSensitive, language, fallbackLanguage } = parameters;
471
+ return buildPropertyTextMatchQueryExpression({
472
+ propertyVariable,
473
+ propertyRelation,
474
+ valueFilters: [buildValueIdReferenceQuery()],
475
+ contentQueryExpression: matchMode === "exact" ? buildValueContentExactInnerQuery({
476
+ language,
477
+ fallbackLanguage,
478
+ value,
479
+ isCaseSensitive
480
+ }) : buildRichTextContentQueryExpression({
481
+ language,
482
+ fallbackLanguage,
483
+ value,
484
+ matchMode,
485
+ isCaseSensitive
486
+ })
487
+ });
488
+ }
470
489
  function buildPropertyDateRangeQueryExpression(query) {
471
490
  const rangeQueryExpressions = [];
472
491
  if (query.from != null) rangeQueryExpressions.push(`cts:element-attribute-range-query(xs:QName("value"), xs:QName("rawValue"), ">=", ${stringLiteral(query.from)})`);
@@ -652,11 +671,21 @@ function buildLeafValueQueryExpression(parameters) {
652
671
  value,
653
672
  matchMode
654
673
  });
655
- case "IDREF": return buildPropertyIdReferenceQueryExpression({
656
- propertyVariable: query.propertyVariable,
657
- propertyRelation: query.propertyRelation,
658
- value
659
- });
674
+ case "IDREF":
675
+ if (query.matchMode === "exact") return buildPropertyIdReferenceQueryExpression({
676
+ propertyVariable: query.propertyVariable,
677
+ propertyRelation: query.propertyRelation,
678
+ value
679
+ });
680
+ return buildPropertyIdReferenceTextQueryExpression({
681
+ propertyVariable: query.propertyVariable,
682
+ propertyRelation: query.propertyRelation,
683
+ value,
684
+ matchMode,
685
+ isCaseSensitive: query.isCaseSensitive,
686
+ language: query.language,
687
+ fallbackLanguage: query.fallbackLanguage
688
+ });
660
689
  case "string": return buildPropertyStringQueryExpression({
661
690
  propertyVariable: query.propertyVariable,
662
691
  propertyRelation: query.propertyRelation,
@@ -749,7 +778,7 @@ function getLeafHelperKey(parameters) {
749
778
  "leaf",
750
779
  matchMode,
751
780
  query.target,
752
- query.dataType,
781
+ query.dataType === "IDREF" && query.matchMode !== "exact" ? "IDREF-text" : query.dataType,
753
782
  query.propertyVariable ?? "",
754
783
  query.propertyRelation ?? "",
755
784
  value,
@@ -868,18 +897,7 @@ function buildLeafQueryExpression(context, query) {
868
897
  }
869
898
  function getGroupableIncludesValue(query) {
870
899
  if (query.matchMode !== "includes" || query.isNegated === true) return null;
871
- switch (query.target) {
872
- case "string":
873
- case "title":
874
- case "description":
875
- case "image":
876
- case "periods":
877
- case "bibliography":
878
- case "notes": return query.value;
879
- case "property":
880
- if (!("value" in query) || query.value == null || query.dataType === "IDREF") return null;
881
- return query.value;
882
- }
900
+ return getLeafSearchValue(query);
883
901
  }
884
902
  function isQueryLeaf(query) {
885
903
  return "target" in query;
@@ -893,6 +893,11 @@ export type SetItemsSort = {
893
893
  * own word and `exact` matches the terms as an adjacent run of whole words. OCR
894
894
  * text carries no language, so `ocr` leaves take no `language`.
895
895
  *
896
+ * An `IDREF` property leaf matches by identity under `exact`, where `value` is
897
+ * the UUID of the linked item, and by the linked item's displayed name under
898
+ * `includes`, which OCHRE copies into the value's `content`. The `all` data
899
+ * type searches the text of every value, linked names included.
900
+ *
896
901
  * `fallbackLanguage` searches a field in that language only when the field has
897
902
  * no content in `language`, so a match follows the text a reader of `language`
898
903
  * is shown. Leave it unset to search `language` alone.
@@ -219,6 +219,14 @@ export type Website<T extends LanguageCodes = LanguageCodes> = {
219
219
  };
220
220
  }>;
221
221
  };
222
+ /**
223
+ * The bare Map element of an OAK website, null for every other design. Its
224
+ * bare Collection elements are in `items` as pages hidden from the navbar,
225
+ * in tree order.
226
+ */
227
+ oak: {
228
+ map: WebElementOf<"map", T> | null;
229
+ } | null;
222
230
  };
223
231
  export type WebsiteSegment<T extends LanguageCodes = LanguageCodes> = Website<T> & {
224
232
  type: "segment";
@@ -358,7 +366,7 @@ export type WebElementComponent<T extends LanguageCodes = LanguageCodes> = {
358
366
  paginationVariant: "default" | "numeric";
359
367
  loadingVariant: WebLoadingVariant;
360
368
  image: {
361
- layout: "top" | "bottom" | "start" | "end" | null;
369
+ layout: "top" | "bottom" | "start" | "end" | "thumbnail" | null;
362
370
  fit: "fill" | "fit";
363
371
  alignment: "top" | "center" | "bottom" | null;
364
372
  isPlaceholderDisplayed: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.3.18",
3
+ "version": "1.3.20",
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",