ochre-sdk 0.20.3 → 0.20.5

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
@@ -1238,6 +1238,7 @@ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategor
1238
1238
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
1239
1239
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1240
1240
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1241
+ * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
1241
1242
  * @param options - Options for the fetch
1242
1243
  * @param options.fetch - The fetch function to use
1243
1244
  * @param options.version - The version of the OCHRE API to use
@@ -1247,6 +1248,7 @@ declare function fetchSetPropertyValuesByPropertyVariables(params: {
1247
1248
  setScopeUuids: Array<string>;
1248
1249
  belongsToCollectionScopeUuids: Array<string>;
1249
1250
  propertyVariableUuids: Array<string>;
1251
+ isLimitedToLeafPropertyValues?: boolean;
1250
1252
  }, options?: {
1251
1253
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1252
1254
  version?: ApiVersion;
package/dist/index.mjs CHANGED
@@ -766,7 +766,8 @@ const boundsSchema = z.string().transform((str, ctx) => {
766
766
  const setPropertyValuesByPropertyVariablesParamsSchema = z.object({
767
767
  setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
768
768
  belongsToCollectionScopeUuids: z.array(uuidSchema).default([]),
769
- propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required")
769
+ propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required"),
770
+ isLimitedToLeafPropertyValues: z.boolean().default(false)
770
771
  });
771
772
  const setItemsParamsSchema = z.object({
772
773
  setScopeUuids: z.array(uuidSchema).min(1, "At least one set scope UUID is required"),
@@ -2394,13 +2395,14 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2394
2395
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2395
2396
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2396
2397
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2398
+ * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
2397
2399
  * @param options - Options for the fetch
2398
2400
  * @param options.version - The version of the OCHRE API to use
2399
2401
  * @returns An XQuery string
2400
2402
  */
2401
2403
  function buildXQuery(params, options) {
2402
2404
  const version = options?.version ?? DEFAULT_API_VERSION;
2403
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = params;
2405
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = params;
2404
2406
  let setScopeFilter = "";
2405
2407
  if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items`;
2406
2408
  let collectionScopeFilter = "";
@@ -2411,10 +2413,10 @@ function buildXQuery(params, options) {
2411
2413
  ${collectionScopeFilter}
2412
2414
  //property[label/(${propertyVariableFilters})]
2413
2415
 
2414
- for $v in $matching-props/value
2416
+ for $v in $matching-props/value${isLimitedToLeafPropertyValues ? "[not(@i)]" : ""}
2415
2417
  let $item-uuid := $v/ancestor::*[parent::items]/@uuid
2416
2418
  return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}">{
2417
- if ($v/content) then $v/content else $v/text()
2419
+ if ($v/content) then string-join($v/content[@xml:lang="eng"]/string, "") else $v/text()
2418
2420
  }</propertyValue>`}}</ochre>`;
2419
2421
  }
2420
2422
  /**
@@ -2424,6 +2426,7 @@ function buildXQuery(params, options) {
2424
2426
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2425
2427
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2426
2428
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2429
+ * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
2427
2430
  * @param options - Options for the fetch
2428
2431
  * @param options.fetch - The fetch function to use
2429
2432
  * @param options.version - The version of the OCHRE API to use
@@ -2432,11 +2435,12 @@ function buildXQuery(params, options) {
2432
2435
  async function fetchSetPropertyValuesByPropertyVariables(params, options) {
2433
2436
  try {
2434
2437
  const version = options?.version ?? DEFAULT_API_VERSION;
2435
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2438
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2436
2439
  const xquery = buildXQuery({
2437
2440
  setScopeUuids,
2438
2441
  belongsToCollectionScopeUuids,
2439
- propertyVariableUuids
2442
+ propertyVariableUuids,
2443
+ isLimitedToLeafPropertyValues
2440
2444
  }, { version });
2441
2445
  const response = await (options?.fetch ?? 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="*"`);
2442
2446
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.20.3",
3
+ "version": "0.20.5",
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",