@digitalculture/ochre-sdk 0.17.7 → 0.17.8

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
@@ -899,6 +899,7 @@ type WebElementComponent = {
899
899
  component: "network-graph";
900
900
  } | {
901
901
  component: "query";
902
+ itemCategory: "resource" | "spatialUnit" | "concept" | "text";
902
903
  queries: Array<{
903
904
  label: string;
904
905
  propertyUuids: Array<string>;
@@ -1096,28 +1097,31 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1096
1097
  itemCategories: never;
1097
1098
  }>;
1098
1099
  //#endregion
1099
- //#region src/utils/fetchers/items-by-property-value.d.ts
1100
+ //#region src/utils/fetchers/items-by-property-values.d.ts
1100
1101
  /**
1101
- * Fetches and parses items by property value from the OCHRE API
1102
+ * Fetches and parses items by property values from the OCHRE API
1102
1103
  *
1103
1104
  * @param params - The parameters for the fetch
1104
- * @param params.scopeUuids - The scope UUIDs to filter by
1105
1105
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1106
- * @param params.propertyValueUuids - The property value UUIDs to query by
1106
+ * @param params.propertyValues - The property values to query by
1107
1107
  * @param params.projectScopeUuid - The UUID of the project scope
1108
+ * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1108
1109
  * @param categoryParams - The category parameters for the fetch
1109
1110
  * @param categoryParams.category - The category of the items to fetch
1110
1111
  * @param categoryParams.itemCategories - The categories of the items to fetch
1111
1112
  * @param options - Options for the fetch
1112
1113
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
1113
1114
  * @param options.version - The version of the OCHRE API to use
1114
- * @returns The parsed items by property value or null if the fetch/parse fails
1115
+ * @returns The parsed items by property values or null if the fetch/parse fails
1115
1116
  */
1116
- declare function fetchItemsByPropertyValue<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(params: {
1117
- scopeUuids: Array<string>;
1117
+ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(params: {
1118
1118
  propertyVariableUuids: Array<string>;
1119
- propertyValueUuids: Array<string>;
1119
+ propertyValues: Array<{
1120
+ dataType: Exclude<PropertyValueContentType, "coordinate">;
1121
+ value: string;
1122
+ }>;
1120
1123
  projectScopeUuid: string;
1124
+ belongsToCollectionScopeUuids: Array<string>;
1121
1125
  }, categoryParams?: {
1122
1126
  category?: T;
1123
1127
  itemCategories?: U;
@@ -1132,9 +1136,9 @@ declare function fetchItemsByPropertyValue<T extends DataCategory = DataCategory
1132
1136
  error: string;
1133
1137
  }>;
1134
1138
  //#endregion
1135
- //#region src/utils/fetchers/property-query.d.ts
1139
+ //#region src/utils/fetchers/property-values-by-property-variables.d.ts
1136
1140
  /**
1137
- * Fetches and parses a property query from the OCHRE API
1141
+ * Fetches and parses property values by property variables from the OCHRE API
1138
1142
  *
1139
1143
  * @param params - The parameters for the fetch
1140
1144
  * @param params.scopeUuids - The scope UUIDs to filter by
@@ -1143,23 +1147,9 @@ declare function fetchItemsByPropertyValue<T extends DataCategory = DataCategory
1143
1147
  * @param options - Options for the fetch
1144
1148
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
1145
1149
  * @param options.version - The version of the OCHRE API to use
1146
- * @returns The parsed property query or null if the fetch/parse fails
1147
- *
1148
- * @example
1149
- * ```ts
1150
- * const propertyQuery = await fetchPropertyQuery(["0c0aae37-7246-495b-9547-e25dbf5b99a3"], ["9c4da06b-f15e-40af-a747-0933eaf3587e"]);
1151
- * if (propertyQuery === null) {
1152
- * console.error("Failed to fetch property query");
1153
- * return;
1154
- * }
1155
- * console.log(`Fetched property query: ${propertyQuery.item}`);
1156
- * ```
1157
- *
1158
- * @remarks
1159
- * The returned property query includes:
1160
- * - Property items
1150
+ * @returns The parsed property values by property variables or null if the fetch/parse fails
1161
1151
  */
1162
- declare function fetchPropertyQuery(params: {
1152
+ declare function fetchPropertyValuesByPropertyVariables(params: {
1163
1153
  scopeUuids: Array<string>;
1164
1154
  propertyUuids: Array<string>;
1165
1155
  projectScopeUuid: string;
@@ -1407,4 +1397,4 @@ declare const DEFAULT_API_VERSION = 2;
1407
1397
  */
1408
1398
  declare function flattenItemProperties<T extends DataCategory = DataCategory, U extends DataCategory | Array<DataCategory> = (T extends "tree" ? Exclude<DataCategory, "tree"> : T extends "set" ? Array<DataCategory> : never)>(item: Item<T, U>): Item<T, U>;
1409
1399
  //#endregion
1410
- export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValue, fetchPropertyQuery, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1400
+ export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyQueryItem, PropertyValue, PropertyValueContent, PropertyValueContentType, Resource, Scope, Section, Set, SpatialUnit, Style, Text, Tree, UuidMetadata, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebTitle, Webpage, Website, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -2519,6 +2519,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2519
2519
  case "network-graph": break;
2520
2520
  case "query": {
2521
2521
  const queries = [];
2522
+ const itemCategory = getPropertyValueByLabel(componentProperty.properties, "item-category");
2522
2523
  const queryProperties = componentProperty.properties;
2523
2524
  if (queryProperties.length === 0) throw new Error(`Query properties not found for the following component: “${componentName}”`);
2524
2525
  for (const query of queryProperties) {
@@ -2543,6 +2544,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
2543
2544
  paginationVariant ??= "default";
2544
2545
  let layout = getPropertyValueByLabel(componentProperty.properties, "layout");
2545
2546
  layout ??= "image-start";
2547
+ properties.itemCategory = itemCategory;
2546
2548
  properties.queries = queries;
2547
2549
  properties.displayedProperties = displayedProperties?.values.map((value) => ({
2548
2550
  uuid: value.uuid,
@@ -3476,24 +3478,36 @@ async function fetchItem(uuid, category, itemCategories, options) {
3476
3478
  }
3477
3479
 
3478
3480
  //#endregion
3479
- //#region src/utils/fetchers/items-by-property-value.ts
3481
+ //#region src/utils/fetchers/items-by-property-values.ts
3480
3482
  /**
3481
- * Build an XQuery string to fetch items by property value from the OCHRE API
3482
- * @param scopeUuids - An array of scope UUIDs to filter by
3483
- * @param propertyVariableUuids - An array of property variable UUIDs to fetch
3484
- * @param propertyValueUuids - An array of property value UUIDs to fetch
3485
- * @param projectScopeUuid - The UUID of the project scope
3483
+ * Build an XQuery string to fetch items by property values from the OCHRE API
3484
+ * @param params - The parameters for the fetch
3485
+ * @param params.projectScopeUuid - The UUID of the project scope
3486
+ * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
3487
+ * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
3488
+ * @param params.propertyValues - An array of property values to fetch
3489
+ * @param options - Options for the fetch
3490
+ * @param options.version - The version of the OCHRE API to use
3486
3491
  * @returns An XQuery string
3487
3492
  */
3488
- function buildXQuery$1(scopeUuids, propertyVariableUuids, propertyValueUuids, projectScopeUuid, options) {
3493
+ function buildXQuery$1(params, options) {
3489
3494
  const version = options?.version ?? DEFAULT_API_VERSION;
3490
- let collectionScopeFilter = "";
3491
- if (scopeUuids.length > 0) collectionScopeFilter = `[properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${scopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]]`;
3495
+ const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids } = params;
3496
+ let belongsToCollectionScopeFilter = "";
3497
+ if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]]`;
3492
3498
  const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3493
- const propertyValues = propertyValueUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3494
- return `<ochre>{${`for $q in ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${collectionScopeFilter}/properties//property[label[${propertyVariables}]][value[${propertyValues}]]
3499
+ const propertyValuesFilters = propertyValues.map(({ dataType, value }) => {
3500
+ if (dataType === "IDREF") return `value[@uuid="${value}"]`;
3501
+ if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value[@rawValue="${value}"]`;
3502
+ return `value="${value}"`;
3503
+ }).join(" or ");
3504
+ return `<ochre>{${`let $matches := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${belongsToCollectionScopeFilter}/properties//property[label[${propertyVariables}]][${propertyValuesFilters}]
3505
+
3506
+ let $items := $matches/ancestor::*[parent::ochre]
3507
+ let $unique-uuids := distinct-values($items/@uuid)
3495
3508
 
3496
- let $item := $q/ancestor::*[parent::ochre]
3509
+ for $uuid in $unique-uuids
3510
+ let $item := $items[@uuid = $uuid][1]
3497
3511
  let $category := local-name($item)
3498
3512
 
3499
3513
  return element { node-name($item) } {
@@ -3502,28 +3516,33 @@ return element { node-name($item) } {
3502
3516
  }`}}</ochre>`;
3503
3517
  }
3504
3518
  /**
3505
- * Fetches and parses items by property value from the OCHRE API
3519
+ * Fetches and parses items by property values from the OCHRE API
3506
3520
  *
3507
3521
  * @param params - The parameters for the fetch
3508
- * @param params.scopeUuids - The scope UUIDs to filter by
3509
3522
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
3510
- * @param params.propertyValueUuids - The property value UUIDs to query by
3523
+ * @param params.propertyValues - The property values to query by
3511
3524
  * @param params.projectScopeUuid - The UUID of the project scope
3525
+ * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
3512
3526
  * @param categoryParams - The category parameters for the fetch
3513
3527
  * @param categoryParams.category - The category of the items to fetch
3514
3528
  * @param categoryParams.itemCategories - The categories of the items to fetch
3515
3529
  * @param options - Options for the fetch
3516
3530
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
3517
3531
  * @param options.version - The version of the OCHRE API to use
3518
- * @returns The parsed items by property value or null if the fetch/parse fails
3532
+ * @returns The parsed items by property values or null if the fetch/parse fails
3519
3533
  */
3520
- async function fetchItemsByPropertyValue(params, categoryParams, options) {
3534
+ async function fetchItemsByPropertyValues(params, categoryParams, options) {
3521
3535
  try {
3522
3536
  const customFetch = options?.customFetch;
3523
3537
  const version = options?.version ?? DEFAULT_API_VERSION;
3524
- const { scopeUuids, propertyVariableUuids, propertyValueUuids, projectScopeUuid } = params;
3538
+ const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids } = params;
3525
3539
  const { category, itemCategories } = categoryParams ?? {};
3526
- const xquery = buildXQuery$1(scopeUuids, propertyVariableUuids, propertyValueUuids, projectScopeUuid, { version });
3540
+ const xquery = buildXQuery$1({
3541
+ projectScopeUuid,
3542
+ belongsToCollectionScopeUuids,
3543
+ propertyVariableUuids,
3544
+ propertyValues
3545
+ }, { version });
3527
3546
  const response = await (customFetch ?? fetch)(version === 2 ? `https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"` : `https://ochre.lib.uchicago.edu/ochre?xquery=${encodeURIComponent(xquery)}&format=json&lang="*"`);
3528
3547
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
3529
3548
  const data = await response.json();
@@ -3579,15 +3598,15 @@ async function fetchItemsByPropertyValue(params, categoryParams, options) {
3579
3598
  console.error(error);
3580
3599
  return {
3581
3600
  items: null,
3582
- error: error instanceof Error ? error.message : "Failed to fetch items by property value"
3601
+ error: error instanceof Error ? error.message : "Failed to fetch items by property values"
3583
3602
  };
3584
3603
  }
3585
3604
  }
3586
3605
 
3587
3606
  //#endregion
3588
- //#region src/utils/fetchers/property-query.ts
3607
+ //#region src/utils/fetchers/property-values-by-property-variables.ts
3589
3608
  /**
3590
- * Schema for a single item in the OCHRE API response
3609
+ * Schema for a single property value by property variable item in the OCHRE API response
3591
3610
  */
3592
3611
  const responseItemSchema = z.object({
3593
3612
  property: uuidSchema,
@@ -3606,11 +3625,11 @@ const responseItemSchema = z.object({
3606
3625
  })
3607
3626
  });
3608
3627
  /**
3609
- * Schema for the OCHRE API response
3628
+ * Schema for the property values by property variables OCHRE API response
3610
3629
  */
3611
3630
  const responseSchema = z.object({ result: z.object({ ochre: z.object({ item: z.union([responseItemSchema, z.array(responseItemSchema)]) }) }) });
3612
3631
  /**
3613
- * Build an XQuery string to fetch property query items from the OCHRE API
3632
+ * Build an XQuery string to fetch property values by property variables from the OCHRE API
3614
3633
  * @param scopeUuids - An array of scope UUIDs to filter by
3615
3634
  * @param propertyUuids - An array of property UUIDs to fetch
3616
3635
  * @param projectScopeUuid - The UUID of the project scope
@@ -3624,12 +3643,12 @@ function buildXQuery(scopeUuids, propertyUuids, projectScopeUuid, options) {
3624
3643
  return `<ochre>{${`for $q in ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${collectionScopeFilter}/properties//property[label[${propertyFilters}]]
3625
3644
  return <item>
3626
3645
  <property>{xs:string($q/label/@uuid)}</property>
3627
- <value> {$q/*[2]/@*} {$q/*[2]/content[1]/string/text()} </value>
3646
+ <value> {$q/*[2]/@*} {$q/*[2]/text()} {$q/*[2]/content} </value>
3628
3647
  <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
3629
3648
  </item>`}}</ochre>`;
3630
3649
  }
3631
3650
  /**
3632
- * Fetches and parses a property query from the OCHRE API
3651
+ * Fetches and parses property values by property variables from the OCHRE API
3633
3652
  *
3634
3653
  * @param params - The parameters for the fetch
3635
3654
  * @param params.scopeUuids - The scope UUIDs to filter by
@@ -3638,23 +3657,9 @@ return <item>
3638
3657
  * @param options - Options for the fetch
3639
3658
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
3640
3659
  * @param options.version - The version of the OCHRE API to use
3641
- * @returns The parsed property query or null if the fetch/parse fails
3642
- *
3643
- * @example
3644
- * ```ts
3645
- * const propertyQuery = await fetchPropertyQuery(["0c0aae37-7246-495b-9547-e25dbf5b99a3"], ["9c4da06b-f15e-40af-a747-0933eaf3587e"]);
3646
- * if (propertyQuery === null) {
3647
- * console.error("Failed to fetch property query");
3648
- * return;
3649
- * }
3650
- * console.log(`Fetched property query: ${propertyQuery.item}`);
3651
- * ```
3652
- *
3653
- * @remarks
3654
- * The returned property query includes:
3655
- * - Property items
3660
+ * @returns The parsed property values by property variables or null if the fetch/parse fails
3656
3661
  */
3657
- async function fetchPropertyQuery(params, options) {
3662
+ async function fetchPropertyValuesByPropertyVariables(params, options) {
3658
3663
  try {
3659
3664
  const customFetch = options?.customFetch;
3660
3665
  const version = options?.version ?? DEFAULT_API_VERSION;
@@ -3696,7 +3701,7 @@ async function fetchPropertyQuery(params, options) {
3696
3701
  console.error(error);
3697
3702
  return {
3698
3703
  items: null,
3699
- error: error instanceof Error ? error.message : "Failed to fetch property query"
3704
+ error: error instanceof Error ? error.message : "Failed to fetch property values by property variables"
3700
3705
  };
3701
3706
  }
3702
3707
  }
@@ -3842,4 +3847,4 @@ async function fetchWebsite(abbreviation, options) {
3842
3847
  }
3843
3848
 
3844
3849
  //#endregion
3845
- export { DEFAULT_API_VERSION, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValue, fetchPropertyQuery, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
3850
+ export { DEFAULT_API_VERSION, fetchByUuidMetadata, fetchGallery, fetchItem, fetchItemsByPropertyValues, fetchPropertyValuesByPropertyVariables, fetchWebsite, filterProperties, flattenItemProperties, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.17.7",
3
+ "version": "0.17.8",
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",