ochre-sdk 0.20.6 → 0.20.7

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
@@ -1231,6 +1231,12 @@ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategor
1231
1231
  }>;
1232
1232
  //#endregion
1233
1233
  //#region src/utils/fetchers/set/property-values-by-property-variables.d.ts
1234
+ type SetPropertyValuesByPropertyVariablesTitleQueryInput = {
1235
+ value: string;
1236
+ matchMode: "includes" | "exact";
1237
+ isCaseSensitive: boolean;
1238
+ language?: string;
1239
+ };
1234
1240
  /**
1235
1241
  * Fetches and parses Set property values by property variables from the OCHRE API
1236
1242
  *
@@ -1238,6 +1244,7 @@ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategor
1238
1244
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
1239
1245
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1240
1246
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
1247
+ * @param params.titleQuery - Title query to filter returned items by item title
1241
1248
  * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
1242
1249
  * @param options - Options for the fetch
1243
1250
  * @param options.fetch - The fetch function to use
@@ -1248,6 +1255,7 @@ declare function fetchSetPropertyValuesByPropertyVariables(params: {
1248
1255
  setScopeUuids: Array<string>;
1249
1256
  belongsToCollectionScopeUuids: Array<string>;
1250
1257
  propertyVariableUuids: Array<string>;
1258
+ titleQuery?: SetPropertyValuesByPropertyVariablesTitleQueryInput;
1251
1259
  isLimitedToLeafPropertyValues?: boolean;
1252
1260
  }, options?: {
1253
1261
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
package/dist/index.mjs CHANGED
@@ -767,6 +767,12 @@ 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
769
  propertyVariableUuids: z.array(uuidSchema).min(1, "At least one property variable UUID is required"),
770
+ titleQuery: z.object({
771
+ value: z.string(),
772
+ matchMode: z.enum(["includes", "exact"]),
773
+ isCaseSensitive: z.boolean(),
774
+ language: z.string().default("eng")
775
+ }).strict().optional(),
770
776
  isLimitedToLeafPropertyValues: z.boolean().default(false)
771
777
  });
772
778
  const setItemsParamsSchema = z.object({
@@ -2109,7 +2115,7 @@ async function fetchItem(uuid, category, itemCategories, options) {
2109
2115
  * @param params.isCaseSensitive - Whether to match case-sensitively
2110
2116
  * @returns The string match predicate
2111
2117
  */
2112
- function buildStringMatchPredicate(params) {
2118
+ function buildStringMatchPredicate$1(params) {
2113
2119
  const { path, value, matchMode, isCaseSensitive } = params;
2114
2120
  const comparedPath = isCaseSensitive ? path : `lower-case(${path})`;
2115
2121
  const comparedValueLiteral = stringLiteral(isCaseSensitive ? value : value.toLowerCase());
@@ -2138,7 +2144,7 @@ function buildPropertyValuePredicate(query) {
2138
2144
  to: query.to
2139
2145
  })}]`;
2140
2146
  if (query.dataType === "time" || query.dataType === "integer" || query.dataType === "decimal" || query.dataType === "boolean") return `.//properties//property[value[@rawValue=${stringLiteral(query.value)}]]`;
2141
- return `.//properties//property[${buildStringMatchPredicate({
2147
+ return `.//properties//property[${buildStringMatchPredicate$1({
2142
2148
  path: `string-join(value/content[@xml:lang="${query.language}"]/string, "")`,
2143
2149
  value: query.value,
2144
2150
  matchMode: query.matchMode,
@@ -2152,31 +2158,31 @@ function buildPropertyValuePredicate(query) {
2152
2158
  */
2153
2159
  function buildQueryPredicate(query) {
2154
2160
  switch (query.target) {
2155
- case "title": return buildStringMatchPredicate({
2161
+ case "title": return buildStringMatchPredicate$1({
2156
2162
  path: `string-join(identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2157
2163
  value: query.value,
2158
2164
  matchMode: query.matchMode,
2159
2165
  isCaseSensitive: query.isCaseSensitive
2160
2166
  });
2161
- case "description": return buildStringMatchPredicate({
2167
+ case "description": return buildStringMatchPredicate$1({
2162
2168
  path: `string-join(description/content[@xml:lang="${query.language}"]/string, "")`,
2163
2169
  value: query.value,
2164
2170
  matchMode: query.matchMode,
2165
2171
  isCaseSensitive: query.isCaseSensitive
2166
2172
  });
2167
- case "periods": return buildStringMatchPredicate({
2173
+ case "periods": return buildStringMatchPredicate$1({
2168
2174
  path: `string-join(periods/period/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2169
2175
  value: query.value,
2170
2176
  matchMode: query.matchMode,
2171
2177
  isCaseSensitive: query.isCaseSensitive
2172
2178
  });
2173
- case "bibliography": return buildStringMatchPredicate({
2179
+ case "bibliography": return buildStringMatchPredicate$1({
2174
2180
  path: `string-join(bibliographies/bibliography/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2175
2181
  value: query.value,
2176
2182
  matchMode: query.matchMode,
2177
2183
  isCaseSensitive: query.isCaseSensitive
2178
2184
  });
2179
- case "image": return buildStringMatchPredicate({
2185
+ case "image": return buildStringMatchPredicate$1({
2180
2186
  path: `string-join(image/identification/label/content[@xml:lang="${query.language}"]/string, "")`,
2181
2187
  value: query.value,
2182
2188
  matchMode: query.matchMode,
@@ -2391,6 +2397,35 @@ function aggregatePropertyValues(values) {
2391
2397
  });
2392
2398
  }
2393
2399
  /**
2400
+ * Build a string match predicate for an XQuery string
2401
+ * @param params - The parameters for the predicate
2402
+ * @param params.path - The path to the string
2403
+ * @param params.value - The value to match
2404
+ * @param params.matchMode - The match mode (includes or exact)
2405
+ * @param params.isCaseSensitive - Whether to match case-sensitively
2406
+ * @returns The string match predicate
2407
+ */
2408
+ function buildStringMatchPredicate(params) {
2409
+ const { path, value, matchMode, isCaseSensitive } = params;
2410
+ const comparedPath = isCaseSensitive ? path : `lower-case(${path})`;
2411
+ const comparedValueLiteral = stringLiteral(isCaseSensitive ? value : value.toLowerCase());
2412
+ if (matchMode === "includes") return `contains(${comparedPath}, ${comparedValueLiteral})`;
2413
+ return `${comparedPath} = ${comparedValueLiteral}`;
2414
+ }
2415
+ /**
2416
+ * Build a title predicate for an XQuery string
2417
+ * @param titleQuery - The title query
2418
+ * @returns The title predicate
2419
+ */
2420
+ function buildTitlePredicate(titleQuery) {
2421
+ return buildStringMatchPredicate({
2422
+ path: `string-join(identification/label/content[@xml:lang="${titleQuery.language}"]/string, "")`,
2423
+ value: titleQuery.value,
2424
+ matchMode: titleQuery.matchMode,
2425
+ isCaseSensitive: titleQuery.isCaseSensitive
2426
+ });
2427
+ }
2428
+ /**
2394
2429
  * Schema for a single property value query item in the OCHRE API response
2395
2430
  */
2396
2431
  const propertyValueQueryItemSchema = z.object({
@@ -2447,6 +2482,7 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2447
2482
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2448
2483
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2449
2484
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
2485
+ * @param params.titleQuery - Title query to filter returned items by item title
2450
2486
  * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
2451
2487
  * @param options - Options for the fetch
2452
2488
  * @param options.version - The version of the OCHRE API to use
@@ -2454,16 +2490,22 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2454
2490
  */
2455
2491
  function buildXQuery(params, options) {
2456
2492
  const version = options?.version ?? DEFAULT_API_VERSION;
2457
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = params;
2458
- let setScopeFilter = "";
2459
- if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items`;
2460
- let collectionScopeFilter = "";
2461
- if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]]`;
2493
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, titleQuery, isLimitedToLeafPropertyValues } = params;
2494
+ let setScopeFilter = "/set/items/*";
2495
+ if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2462
2496
  const propertyVariableFilters = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2463
- return `<ochre>{${`let $matching-props := ${version === 2 ? "doc()" : "input()"}/ochre
2497
+ const filterPredicates = [];
2498
+ if (belongsToCollectionScopeUuids.length > 0) {
2499
+ const belongsToCollectionScopeValues = belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
2500
+ filterPredicates.push(`.//properties[property[label/@uuid="${BELONGS_TO_COLLECTION_UUID}" and value/(${belongsToCollectionScopeValues})]]`);
2501
+ }
2502
+ if (titleQuery != null) filterPredicates.push(buildTitlePredicate(titleQuery));
2503
+ const itemFilters = filterPredicates.length > 0 ? `[${filterPredicates.join(" and ")}]` : "";
2504
+ return `<ochre>{${`let $items := ${version === 2 ? "doc()" : "input()"}/ochre
2464
2505
  ${setScopeFilter}
2465
- ${collectionScopeFilter}
2466
- //property[label/(${propertyVariableFilters})]
2506
+ ${itemFilters}
2507
+
2508
+ let $matching-props := $items//property[label/(${propertyVariableFilters})]
2467
2509
 
2468
2510
  for $p in $matching-props
2469
2511
  for $v in $p/value${isLimitedToLeafPropertyValues ? "[not(@i)]" : ""}
@@ -2480,6 +2522,7 @@ function buildXQuery(params, options) {
2480
2522
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2481
2523
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2482
2524
  * @param params.propertyVariableUuids - The property variable UUIDs to query by
2525
+ * @param params.titleQuery - Title query to filter returned items by item title
2483
2526
  * @param params.isLimitedToLeafPropertyValues - Whether to limit the property values to leaf property values
2484
2527
  * @param options - Options for the fetch
2485
2528
  * @param options.fetch - The fetch function to use
@@ -2489,11 +2532,12 @@ function buildXQuery(params, options) {
2489
2532
  async function fetchSetPropertyValuesByPropertyVariables(params, options) {
2490
2533
  try {
2491
2534
  const version = options?.version ?? DEFAULT_API_VERSION;
2492
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2535
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, titleQuery, isLimitedToLeafPropertyValues } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2493
2536
  const xquery = buildXQuery({
2494
2537
  setScopeUuids,
2495
2538
  belongsToCollectionScopeUuids,
2496
2539
  propertyVariableUuids,
2540
+ titleQuery,
2497
2541
  isLimitedToLeafPropertyValues
2498
2542
  }, { version });
2499
2543
  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="*"`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.20.6",
3
+ "version": "0.20.7",
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",