ochre-sdk 0.20.2 → 0.20.4

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
@@ -656,6 +656,7 @@ type Query = {
656
656
  isCaseSensitive: boolean;
657
657
  language: string;
658
658
  operator?: "AND" | "OR";
659
+ isNegated?: boolean;
659
660
  } | {
660
661
  target: "propertyValue";
661
662
  dataType: "date" | "dateTime";
@@ -666,6 +667,7 @@ type Query = {
666
667
  isCaseSensitive: boolean;
667
668
  language: string;
668
669
  operator?: "AND" | "OR";
670
+ isNegated?: boolean;
669
671
  } | {
670
672
  target: "propertyValue";
671
673
  dataType: "date" | "dateTime";
@@ -676,6 +678,7 @@ type Query = {
676
678
  isCaseSensitive: boolean;
677
679
  language: string;
678
680
  operator?: "AND" | "OR";
681
+ isNegated?: boolean;
679
682
  } | {
680
683
  target: "title" | "description" | "image" | "periods" | "bibliography";
681
684
  value: string;
@@ -683,6 +686,7 @@ type Query = {
683
686
  isCaseSensitive: boolean;
684
687
  language: string;
685
688
  operator?: "AND" | "OR";
689
+ isNegated?: boolean;
686
690
  };
687
691
  //#endregion
688
692
  //#region src/types/website.d.ts
@@ -1193,7 +1197,7 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1193
1197
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
1194
1198
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1195
1199
  * @param params.propertyVariableUuids - The property variable UUIDs to filter by
1196
- * @param params.queries - Ordered queries to combine with AND/OR
1200
+ * @param params.queries - Ordered queries to combine with AND/OR and optional NOT via negation
1197
1201
  * @param params.page - The page number (1-indexed)
1198
1202
  * @param params.pageSize - The number of items per page
1199
1203
  * @param itemCategories - The categories of the items to fetch
@@ -1234,6 +1238,7 @@ declare function fetchSetItems<U extends Array<DataCategory> = Array<DataCategor
1234
1238
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
1235
1239
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1236
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
1237
1242
  * @param options - Options for the fetch
1238
1243
  * @param options.fetch - The fetch function to use
1239
1244
  * @param options.version - The version of the OCHRE API to use
@@ -1243,6 +1248,7 @@ declare function fetchSetPropertyValuesByPropertyVariables(params: {
1243
1248
  setScopeUuids: Array<string>;
1244
1249
  belongsToCollectionScopeUuids: Array<string>;
1245
1250
  propertyVariableUuids: Array<string>;
1251
+ isLimitedToLeafPropertyValues?: boolean;
1246
1252
  }, options?: {
1247
1253
  fetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1248
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"),
@@ -787,7 +788,8 @@ const setItemsParamsSchema = z.object({
787
788
  matchMode: z.enum(["includes", "exact"]),
788
789
  isCaseSensitive: z.boolean(),
789
790
  language: z.string().default("eng"),
790
- operator: z.enum(["AND", "OR"]).optional()
791
+ operator: z.enum(["AND", "OR"]).optional(),
792
+ isNegated: z.boolean().optional().default(false)
791
793
  }).strict(),
792
794
  z.object({
793
795
  target: z.literal("propertyValue"),
@@ -798,7 +800,8 @@ const setItemsParamsSchema = z.object({
798
800
  matchMode: z.enum(["includes", "exact"]),
799
801
  isCaseSensitive: z.boolean(),
800
802
  language: z.string().default("eng"),
801
- operator: z.enum(["AND", "OR"]).optional()
803
+ operator: z.enum(["AND", "OR"]).optional(),
804
+ isNegated: z.boolean().optional().default(false)
802
805
  }).strict(),
803
806
  z.object({
804
807
  target: z.literal("propertyValue"),
@@ -809,7 +812,8 @@ const setItemsParamsSchema = z.object({
809
812
  matchMode: z.enum(["includes", "exact"]),
810
813
  isCaseSensitive: z.boolean(),
811
814
  language: z.string().default("eng"),
812
- operator: z.enum(["AND", "OR"]).optional()
815
+ operator: z.enum(["AND", "OR"]).optional(),
816
+ isNegated: z.boolean().optional().default(false)
813
817
  }).strict(),
814
818
  z.object({
815
819
  target: z.enum([
@@ -823,7 +827,8 @@ const setItemsParamsSchema = z.object({
823
827
  matchMode: z.enum(["includes", "exact"]),
824
828
  isCaseSensitive: z.boolean(),
825
829
  language: z.string().default("eng"),
826
- operator: z.enum(["AND", "OR"]).optional()
830
+ operator: z.enum(["AND", "OR"]).optional(),
831
+ isNegated: z.boolean().optional().default(false)
827
832
  }).strict()
828
833
  ])).default([]),
829
834
  page: z.number().min(1, "Page must be positive").default(1),
@@ -2181,12 +2186,19 @@ function buildQueryPredicate(query) {
2181
2186
  }
2182
2187
  }
2183
2188
  /**
2189
+ * Build a boolean query clause for an XQuery string.
2190
+ */
2191
+ function buildBooleanQueryClause(query) {
2192
+ const baseClause = `(${buildQueryPredicate(query)})`;
2193
+ return query.isNegated ? `not(${baseClause})` : baseClause;
2194
+ }
2195
+ /**
2184
2196
  * Build an XQuery string to fetch Set items from the OCHRE API
2185
2197
  * @param params - The parameters for the fetch
2186
2198
  * @param params.setScopeUuids - An array of Set scope UUIDs to filter by
2187
2199
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2188
2200
  * @param params.propertyVariableUuids - An array of property variable UUIDs to filter by
2189
- * @param params.queries - Ordered queries to combine with AND/OR
2201
+ * @param params.queries - Ordered queries to combine with AND/OR and optional NOT via negation
2190
2202
  * @param params.page - The page number (1-indexed)
2191
2203
  * @param params.pageSize - The number of items per page
2192
2204
  * @param options - Options for the fetch
@@ -2200,9 +2212,9 @@ function buildXQuery$1(params, options) {
2200
2212
  const endPosition = page * pageSize;
2201
2213
  const setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items/*`;
2202
2214
  const queryFilters = queries.map((query, index) => {
2203
- const predicate = `(${buildQueryPredicate(query)})`;
2204
- if (index === 0) return predicate;
2205
- return `${query.operator === "OR" ? "or" : "and"} ${predicate}`;
2215
+ const clause = buildBooleanQueryClause(query);
2216
+ if (index === 0) return clause;
2217
+ return `${query.operator === "OR" ? "or" : "and"} ${clause}`;
2206
2218
  }).join(" ");
2207
2219
  const filterPredicates = [];
2208
2220
  if (belongsToCollectionScopeUuids.length > 0) {
@@ -2235,7 +2247,7 @@ function buildXQuery$1(params, options) {
2235
2247
  * @param params.setScopeUuids - The Set scope UUIDs to filter by
2236
2248
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2237
2249
  * @param params.propertyVariableUuids - The property variable UUIDs to filter by
2238
- * @param params.queries - Ordered queries to combine with AND/OR
2250
+ * @param params.queries - Ordered queries to combine with AND/OR and optional NOT via negation
2239
2251
  * @param params.page - The page number (1-indexed)
2240
2252
  * @param params.pageSize - The number of items per page
2241
2253
  * @param itemCategories - The categories of the items to fetch
@@ -2383,13 +2395,14 @@ const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
2383
2395
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2384
2396
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
2385
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
2386
2399
  * @param options - Options for the fetch
2387
2400
  * @param options.version - The version of the OCHRE API to use
2388
2401
  * @returns An XQuery string
2389
2402
  */
2390
2403
  function buildXQuery(params, options) {
2391
2404
  const version = options?.version ?? DEFAULT_API_VERSION;
2392
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = params;
2405
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = params;
2393
2406
  let setScopeFilter = "";
2394
2407
  if (setScopeUuids.length > 0) setScopeFilter = `/set[(${setScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")})]/items`;
2395
2408
  let collectionScopeFilter = "";
@@ -2400,7 +2413,7 @@ function buildXQuery(params, options) {
2400
2413
  ${collectionScopeFilter}
2401
2414
  //property[label/(${propertyVariableFilters})]
2402
2415
 
2403
- for $v in $matching-props/value
2416
+ for $v in $matching-props/value${isLimitedToLeafPropertyValues ? "[not(@i)]" : ""}
2404
2417
  let $item-uuid := $v/ancestor::*[parent::items]/@uuid
2405
2418
  return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}" itemUuid="{$item-uuid}">{
2406
2419
  if ($v/content) then $v/content else $v/text()
@@ -2413,6 +2426,7 @@ function buildXQuery(params, options) {
2413
2426
  * @param params.setScopeUuids - An array of set scope UUIDs to filter by
2414
2427
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
2415
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
2416
2430
  * @param options - Options for the fetch
2417
2431
  * @param options.fetch - The fetch function to use
2418
2432
  * @param options.version - The version of the OCHRE API to use
@@ -2421,11 +2435,12 @@ function buildXQuery(params, options) {
2421
2435
  async function fetchSetPropertyValuesByPropertyVariables(params, options) {
2422
2436
  try {
2423
2437
  const version = options?.version ?? DEFAULT_API_VERSION;
2424
- const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2438
+ const { setScopeUuids, belongsToCollectionScopeUuids, propertyVariableUuids, isLimitedToLeafPropertyValues } = setPropertyValuesByPropertyVariablesParamsSchema.parse(params);
2425
2439
  const xquery = buildXQuery({
2426
2440
  setScopeUuids,
2427
2441
  belongsToCollectionScopeUuids,
2428
- propertyVariableUuids
2442
+ propertyVariableUuids,
2443
+ isLimitedToLeafPropertyValues
2429
2444
  }, { version });
2430
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="*"`);
2431
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.2",
3
+ "version": "0.20.4",
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",
@@ -52,8 +52,7 @@
52
52
  "eslint": "^10.0.2",
53
53
  "prettier": "^3.8.1",
54
54
  "tsdown": "^0.20.3",
55
- "typescript": "^5.9.3",
56
- "vitest": "^4.0.18"
55
+ "typescript": "^5.9.3"
57
56
  },
58
57
  "scripts": {
59
58
  "dev": "tsdown src/index.ts --watch",
@@ -65,7 +64,6 @@
65
64
  "format": "prettier --cache --check .",
66
65
  "format:fix": "prettier --cache --write --list-different .",
67
66
  "check-types": "tsc --noEmit",
68
- "test": "vitest run",
69
67
  "release": "bumpp"
70
68
  }
71
69
  }