@digitalculture/ochre-sdk 0.18.16 → 0.18.17

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.
package/dist/index.d.mts CHANGED
@@ -36,6 +36,7 @@ type Metadata = {
36
36
  identification: Identification & {
37
37
  website: string | null;
38
38
  };
39
+ dateFormat: string | null;
39
40
  } | null;
40
41
  collection: {
41
42
  identification: Identification;
@@ -260,8 +261,7 @@ type Observation = {
260
261
  * Represents an event with date, label and optional agent
261
262
  */
262
263
  type Event = {
263
- dateTime: Date | null;
264
- date: string | null;
264
+ dateTime: string | null;
265
265
  label: string;
266
266
  agent: {
267
267
  uuid: string;
package/dist/index.mjs CHANGED
@@ -548,7 +548,7 @@ function filterProperties(property, filter, options = DEFAULT_OPTIONS) {
548
548
 
549
549
  //#endregion
550
550
  //#region src/constants.ts
551
- const BELONG_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
551
+ const BELONGS_TO_COLLECTION_UUID = "30054cb2-909a-4f34-8db9-8fe7369d691d";
552
552
  const PRESENTATION_ITEM_UUID = "f1c131b6-1498-48a4-95bf-a9edae9fd518";
553
553
  const TEXT_ANNOTATION_UUID = "b9ca2732-78f4-416e-b77f-dae7647e68a9";
554
554
  const TEXT_ANNOTATION_HOVER_CARD_UUID = "c7f6a08a-f07b-49b6-bcb1-af485da3c58f";
@@ -1106,7 +1106,10 @@ function parseMetadata(metadata) {
1106
1106
  let collectionIdentification = null;
1107
1107
  if (metadata.collection) collectionIdentification = parseIdentification(metadata.collection.identification);
1108
1108
  return {
1109
- project: projectIdentification ? { identification: projectIdentification } : null,
1109
+ project: projectIdentification ? {
1110
+ identification: projectIdentification,
1111
+ dateFormat: metadata.project?.dateFormat ?? null
1112
+ } : null,
1110
1113
  collection: collectionIdentification ? { identification: collectionIdentification } : null,
1111
1114
  item: metadata.item ? {
1112
1115
  identification,
@@ -1438,8 +1441,7 @@ function parseObservations(observations) {
1438
1441
  function parseEvents(events) {
1439
1442
  const returnEvents = [];
1440
1443
  for (const event of events) returnEvents.push({
1441
- dateTime: event.dateTime != null ? parseISO(event.dateTime) : null,
1442
- date: event.partialDates?.year != null ? `${event.partialDates.year}-01-01/${event.partialDates.endYear ?? event.partialDates.year}-12-31` : null,
1444
+ dateTime: event.endDateTime != null ? `${event.dateTime}/${event.endDateTime}` : event.dateTime ?? null,
1443
1445
  label: parseStringContent(event.label),
1444
1446
  location: event.location ? {
1445
1447
  uuid: event.location.uuid,
@@ -1577,7 +1579,7 @@ function parseProperties(properties, language = "eng") {
1577
1579
  function parseInterpretations(interpretations) {
1578
1580
  const returnInterpretations = [];
1579
1581
  for (const interpretation of interpretations) returnInterpretations.push({
1580
- date: interpretation.date,
1582
+ date: interpretation.date ?? null,
1581
1583
  number: interpretation.interpretationNo,
1582
1584
  links: interpretation.links ? parseLinks(Array.isArray(interpretation.links) ? interpretation.links : [interpretation.links]) : [],
1583
1585
  properties: interpretation.properties ? parseProperties(Array.isArray(interpretation.properties.property) ? interpretation.properties.property : [interpretation.properties.property]) : [],
@@ -3584,7 +3586,7 @@ function buildXQuery$2(params, options) {
3584
3586
  const startPos = (page - 1) * pageSize + 1;
3585
3587
  const endPos = page * pageSize;
3586
3588
  let belongsToCollectionScopeFilter = "";
3587
- if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[.//properties[property[label/@uuid="${BELONG_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
3589
+ if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
3588
3590
  const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3589
3591
  const propertyValuesFilters = propertyValues.map(({ dataType, value }) => {
3590
3592
  if (dataType === "IDREF") return `value[@uuid="${value}"]`;
@@ -3733,7 +3735,7 @@ function buildXQuery$1(params, options) {
3733
3735
  const version = options?.version ?? DEFAULT_API_VERSION;
3734
3736
  const { projectScopeUuid, belongsToCollectionScopeUuids, itemCategory, itemUuids, linkUuids } = params;
3735
3737
  let belongsToCollectionScopeFilter = "";
3736
- if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]`;
3738
+ if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `properties/property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}"][value[${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]`;
3737
3739
  let itemCategoryFilter = "";
3738
3740
  const filterParts = [];
3739
3741
  if (itemUuids.length > 0) filterParts.push(itemUuids.map((uuid) => `@uuid="${uuid}"`).join(" or "));
@@ -3848,6 +3850,7 @@ async function fetchItemsByUuidsAndLinks(params, categoryParams, options) {
3848
3850
  */
3849
3851
  const propertyValueQueryItemSchema = z.object({
3850
3852
  uuid: z.string(),
3853
+ itemUuid: z.string().optional(),
3851
3854
  dataType: z.string(),
3852
3855
  rawValue: z.union([
3853
3856
  z.string(),
@@ -3863,6 +3866,7 @@ const propertyValueQueryItemSchema = z.object({
3863
3866
  ]).optional()
3864
3867
  }).transform((val) => {
3865
3868
  const returnValue = {
3869
+ itemUuid: val.itemUuid != null && val.itemUuid !== "" ? val.itemUuid : null,
3866
3870
  dataType: val.dataType,
3867
3871
  content: null,
3868
3872
  label: null
@@ -3907,16 +3911,17 @@ function buildXQuery(params, options) {
3907
3911
  const version = options?.version ?? DEFAULT_API_VERSION;
3908
3912
  const { projectScopeUuid, belongsToCollectionScopeUuids, propertyVariableUuids } = params;
3909
3913
  let collectionScopeFilter = "";
3910
- if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `//properties[property[label/@uuid="${BELONG_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
3914
+ if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
3911
3915
  const propertyVariableFilters = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3912
3916
  return `<ochre>{${`let $matching-props := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
3913
3917
  ${collectionScopeFilter}
3914
3918
  //property[label/(${propertyVariableFilters})]
3915
3919
 
3916
3920
  for $v in $matching-props/value
3917
- return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}">{
3918
- if ($v/content) then $v/content else $v/text()
3919
- }</propertyValue>`}}</ochre>`;
3921
+ let $item-uuid := $v/ancestor::*[parent::ochre]/@uuid
3922
+ return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}">{
3923
+ if ($v/content) then $v/content else $v/text()
3924
+ }</propertyValue>`}}</ochre>`;
3920
3925
  }
3921
3926
  /**
3922
3927
  * Fetches and parses property values by property variables from the OCHRE API
@@ -3945,15 +3950,24 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
3945
3950
  const parsedResultRaw = responseSchema.parse(data);
3946
3951
  if (Array.isArray(parsedResultRaw.result)) throw new TypeError("No items found");
3947
3952
  const parsedItems = Array.isArray(parsedResultRaw.result.ochre.propertyValue) ? parsedResultRaw.result.ochre.propertyValue : [parsedResultRaw.result.ochre.propertyValue];
3948
- const groupedItems = [];
3953
+ const groupedItemsMap = /* @__PURE__ */ new Map();
3949
3954
  for (const item of parsedItems) {
3950
- const existingItem = groupedItems.find((i) => i.content === item.content);
3951
- if (existingItem == null) groupedItems.push({
3952
- count: 1,
3953
- ...item
3955
+ const existing = groupedItemsMap.get(item.content);
3956
+ if (existing == null) groupedItemsMap.set(item.content, {
3957
+ dataType: item.dataType,
3958
+ content: item.content,
3959
+ label: item.label,
3960
+ itemUuids: new Set([item.itemUuid])
3954
3961
  });
3955
- else existingItem.count++;
3962
+ else existing.itemUuids.add(item.itemUuid);
3956
3963
  }
3964
+ const groupedItems = [];
3965
+ for (const group of groupedItemsMap.values()) groupedItems.push({
3966
+ count: group.itemUuids.size,
3967
+ dataType: group.dataType,
3968
+ content: group.content,
3969
+ label: group.label
3970
+ });
3957
3971
  return {
3958
3972
  items: groupedItems.toSorted((a, b) => {
3959
3973
  if (a.count !== b.count) return b.count - a.count;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.18.16",
3
+ "version": "0.18.17",
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",
@@ -46,11 +46,11 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@antfu/eslint-config": "^7.2.0",
49
- "@types/node": "^24.10.10",
50
- "bumpp": "^10.4.0",
49
+ "@types/node": "^24.10.11",
50
+ "bumpp": "^10.4.1",
51
51
  "eslint": "^9.39.2",
52
52
  "prettier": "^3.8.1",
53
- "tsdown": "^0.20.1",
53
+ "tsdown": "^0.20.3",
54
54
  "typescript": "^5.9.3",
55
55
  "vitest": "^4.0.18"
56
56
  },