ochre-sdk 1.3.0 → 1.3.1

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.
@@ -124,12 +124,13 @@ const propertyValueQueryItemSchema = v.pipe(v.object({
124
124
  const attributeValueQueryItemSchema = v.pipe(v.object({
125
125
  attributeType: v.picklist(["bibliographies", "periods"]),
126
126
  count: countSchema,
127
- content: v.optional(v.string()),
128
- payload: v.optional(v.string())
127
+ key: v.optional(v.string()),
128
+ content: v.optional(v.array(propertyValueLabelContentSchema))
129
129
  }), v.transform((value) => ({
130
130
  attributeType: value.attributeType,
131
131
  count: value.count,
132
- content: value.content != null && value.content !== "" ? value.content : value.payload != null && value.payload !== "" ? value.payload : null
132
+ content: value.key != null && value.key !== "" ? value.key : null,
133
+ label: parsePropertyValueLabel(value.content, value.key)
133
134
  })));
134
135
  /**
135
136
  * Schema for the property values OCHRE API response
@@ -327,45 +328,35 @@ let $property-values :=
327
328
  )`);
328
329
  returnedSequences.push("$property-values");
329
330
  }
330
- if (attributes.bibliographies) {
331
- queryBlocks.push(`let $bibliography-counts := map:map()
332
- let $_bibliography-aggregation := xdmp:eager(
331
+ for (const [attributeType, attributePath] of [["bibliographies", "bibliographies/bibliography"], ["periods", "periods/period"]]) {
332
+ if (!attributes[attributeType]) continue;
333
+ queryBlocks.push(`let $${attributeType}-counts := map:map()
334
+ let $${attributeType}-labels := map:map()
335
+ let $_${attributeType}-aggregation := xdmp:eager(
333
336
  for $item in ${items}
334
337
  let $seen := map:map()
335
338
  return
336
- for $bibliography in $item/bibliographies/bibliography${notSupplemental}
337
- let $label := string-join($bibliography/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
338
- where string-length($label) gt 0
339
- return local:add-attribute-facet($bibliography-counts, $seen, $label)
340
- )
341
-
342
- let $bibliography-values :=
343
- (
344
- $_bibliography-aggregation,
345
- for $label in map:keys($bibliography-counts)
346
- return <attributeValue attributeType="bibliographies" count="{map:get($bibliography-counts, $label)}" content="{$label}" />
347
- )`);
348
- returnedSequences.push("$bibliography-values");
349
- }
350
- if (attributes.periods) {
351
- queryBlocks.push(`let $period-counts := map:map()
352
- let $_period-aggregation := xdmp:eager(
353
- for $item in ${items}
354
- let $seen := map:map()
355
- return
356
- for $period in $item/periods/period${notSupplemental}
357
- let $label := string-join($period/identification/label/content[@xml:lang=${languageLiteral}]//text(), "")
358
- where string-length($label) gt 0
359
- return local:add-attribute-facet($period-counts, $seen, $label)
339
+ for $attribute in $item/${attributePath}${notSupplemental}
340
+ let $label := $attribute/identification/label
341
+ let $key := string-join($label/content[@xml:lang=${languageLiteral}]//text(), "")
342
+ where string-length($key) gt 0
343
+ return (
344
+ if (empty(map:get($${attributeType}-labels, $key)))
345
+ then map:put($${attributeType}-labels, $key, local:value-label-content($label))
346
+ else (),
347
+ local:add-attribute-facet($${attributeType}-counts, $seen, $key)
348
+ )
360
349
  )
361
350
 
362
- let $period-values :=
351
+ let $${attributeType}-values :=
363
352
  (
364
- $_period-aggregation,
365
- for $label in map:keys($period-counts)
366
- return <attributeValue attributeType="periods" count="{map:get($period-counts, $label)}" content="{$label}" />
353
+ $_${attributeType}-aggregation,
354
+ for $key in map:keys($${attributeType}-counts)
355
+ return <attributeValue attributeType="${attributeType}" count="{map:get($${attributeType}-counts, $key)}" key="{$key}">{
356
+ map:get($${attributeType}-labels, $key)
357
+ }</attributeValue>
367
358
  )`);
368
- returnedSequences.push("$period-values");
359
+ returnedSequences.push(`$${attributeType}-values`);
369
360
  }
370
361
  return queryBlocks;
371
362
  }
@@ -426,7 +417,8 @@ function collectAttributeValues(parsedAttributeValues) {
426
417
  if (attributeValue.content == null || attributeValue.content === "") continue;
427
418
  attributeValuesByType[attributeValue.attributeType].push({
428
419
  count: attributeValue.count,
429
- content: attributeValue.content
420
+ content: attributeValue.content,
421
+ label: attributeValue.label
430
422
  });
431
423
  }
432
424
  return attributeValuesByType;
@@ -794,10 +794,14 @@ export type PropertyValueQueryItem = {
794
794
  };
795
795
  /**
796
796
  * Represents a grouped Set attribute value query item
797
+ *
798
+ * `content` is the label in the requested language, which facet queries match
799
+ * on; `label` carries the label in every language for display.
797
800
  */
798
801
  export type SetAttributeValueQueryItem = {
799
802
  count: number;
800
803
  content: string;
804
+ label: MultilingualString | null;
801
805
  };
802
806
  /**
803
807
  * Represents sorting direction for Set items
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",