ochre-sdk 0.21.1 → 0.21.3

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
@@ -675,7 +675,7 @@ type SetItemsSort = {
675
675
  */
676
676
  type QueryLeaf = {
677
677
  target: "property";
678
- propertyVariables?: Array<string>;
678
+ propertyVariable?: string;
679
679
  dataType: Exclude<Exclude<PropertyValueContentType, "coordinate">, "date" | "dateTime">;
680
680
  propertyValues?: Array<string>;
681
681
  from?: never;
@@ -686,7 +686,7 @@ type QueryLeaf = {
686
686
  isNegated?: boolean;
687
687
  } | {
688
688
  target: "property";
689
- propertyVariables: Array<string>;
689
+ propertyVariable: string;
690
690
  dataType: "date" | "dateTime";
691
691
  propertyValues?: never;
692
692
  from: string;
@@ -697,7 +697,7 @@ type QueryLeaf = {
697
697
  isNegated?: boolean;
698
698
  } | {
699
699
  target: "property";
700
- propertyVariables: Array<string>;
700
+ propertyVariable: string;
701
701
  dataType: "date" | "dateTime";
702
702
  propertyValues?: never;
703
703
  from?: string;
@@ -793,6 +793,14 @@ type StylesheetItem = {
793
793
  mobile: Array<Style>;
794
794
  };
795
795
  };
796
+ type WebsitePropertyQueryNode = Query extends infer QueryNode ? QueryNode extends {
797
+ target: "property";
798
+ } ? Omit<QueryNode, "propertyValues" | "from" | "to" | "isNegated"> : never : never;
799
+ type WebsitePropertyQuery = WebsitePropertyQueryNode | {
800
+ and: Array<WebsitePropertyQuery>;
801
+ } | {
802
+ or: Array<WebsitePropertyQuery>;
803
+ };
796
804
  /**
797
805
  * Represents the OCHRE website type
798
806
  */
@@ -1089,9 +1097,9 @@ type WebElementComponent = {
1089
1097
  } | {
1090
1098
  component: "query";
1091
1099
  linkUuids: Array<string>;
1092
- queries: Array<{
1100
+ items: Array<{
1093
1101
  label: string;
1094
- propertyVariableUuids: Array<string>;
1102
+ queries: Array<WebsitePropertyQuery>;
1095
1103
  startIcon: string | null;
1096
1104
  endIcon: string | null;
1097
1105
  }>;
@@ -1503,4 +1511,4 @@ declare const DEFAULT_PAGE_SIZE = 48;
1503
1511
  */
1504
1512
  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>;
1505
1513
  //#endregion
1506
- export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1514
+ export { ApiVersion, Bibliography, Concept, Context, ContextItem, ContextNode, Coordinate, DEFAULT_API_VERSION, DEFAULT_PAGE_SIZE, Data, DataCategory, Event, FileFormat, Gallery, Identification, Image, ImageMap, ImageMapArea, Interpretation, Item, LevelContext, LevelContextItem, License, Link, Metadata, Note, Observation, Period, Person, Property, PropertyContexts, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, PropertyVariable, Query, QueryGroup, QueryLeaf, Resource, Scope, Section, Set, SetAttributeValueQueryItem, SetItemsSort, SetItemsSortDirection, SpatialUnit, Style, StylesheetCategory, StylesheetItem, Text, Tree, WebBlock, WebBlockLayout, WebElement, WebElementComponent, WebImage, WebSegment, WebSegmentItem, WebTitle, Webpage, Website, WebsitePropertyQuery, WebsitePropertyQueryNode, WebsiteType, fetchGallery, fetchItem, fetchSetItems, fetchSetPropertyValues, fetchWebsite, filterProperties, flattenItemProperties, getLeafPropertyValues, getPropertyByLabel, getPropertyByLabelAndValue, getPropertyByLabelAndValues, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -190,7 +190,7 @@ function extractAnnotationMetadata(item) {
190
190
  result.linkVariant = "entry-page";
191
191
  break;
192
192
  default: if (textAnnotationPropertyValueUuid === "3e6f86ab-df81-45ae-8257-e2867357df56" && textAnnotationProperty.property != null) {
193
- let textStylingVariant = "paragraph";
193
+ let textStylingVariant = "block";
194
194
  let textStylingSize = "md";
195
195
  let textStylingHeadingLevel = null;
196
196
  let textStylingCss = [];
@@ -371,7 +371,7 @@ function parseStringDocumentItem(item) {
371
371
  if (textAnnotationProperty != null) {
372
372
  if ((typeof textAnnotationProperty.value === "object" && "uuid" in textAnnotationProperty.value && textAnnotationProperty.value.uuid != null ? textAnnotationProperty.value.uuid : null) === "3e6f86ab-df81-45ae-8257-e2867357df56" && textAnnotationProperty.property != null) {
373
373
  const textStylingType = "text-styling";
374
- let textStylingVariant = "paragraph";
374
+ let textStylingVariant = "block";
375
375
  let textStylingSize = "md";
376
376
  let textStylingHeadingLevel = null;
377
377
  let textStylingCss = [];
@@ -759,7 +759,7 @@ const boundsSchema = z.string().transform((str, ctx) => {
759
759
  const setQueryLeafSchema = z.union([
760
760
  z.object({
761
761
  target: z.literal("property"),
762
- propertyVariables: z.array(uuidSchema).default([]),
762
+ propertyVariable: uuidSchema.optional(),
763
763
  dataType: z.enum([
764
764
  "string",
765
765
  "integer",
@@ -774,14 +774,14 @@ const setQueryLeafSchema = z.union([
774
774
  language: z.string().default("eng"),
775
775
  isNegated: z.boolean().optional().default(false)
776
776
  }).strict().superRefine((value, ctx) => {
777
- if (value.propertyVariables.length === 0 && value.propertyValues == null) ctx.addIssue({
777
+ if (value.propertyVariable == null && value.propertyValues == null) ctx.addIssue({
778
778
  code: "custom",
779
779
  message: "Property queries must include at least one propertyVariable or propertyValue"
780
780
  });
781
781
  }),
782
782
  z.object({
783
783
  target: z.literal("property"),
784
- propertyVariables: z.array(uuidSchema).min(1, "At least one property variable UUID is required"),
784
+ propertyVariable: uuidSchema,
785
785
  dataType: z.enum(["date", "dateTime"]),
786
786
  from: z.string(),
787
787
  to: z.string().optional(),
@@ -792,7 +792,7 @@ const setQueryLeafSchema = z.union([
792
792
  }).strict(),
793
793
  z.object({
794
794
  target: z.literal("property"),
795
- propertyVariables: z.array(uuidSchema).min(1, "At least one property variable UUID is required"),
795
+ propertyVariable: uuidSchema,
796
796
  dataType: z.enum(["date", "dateTime"]),
797
797
  from: z.string().optional(),
798
798
  to: z.string(),
@@ -854,11 +854,11 @@ const setItemsSortSchema = z.discriminatedUnion("target", [
854
854
  language: z.string().default("eng")
855
855
  }).strict()
856
856
  ]).default({ target: "none" });
857
- function hasPropertyQueryWithPropertyVariables(query) {
857
+ function hasPropertyQueryWithPropertyVariable(query) {
858
858
  if (query == null) return false;
859
- if ("target" in query) return query.target === "property" && (query.propertyVariables?.length ?? 0) > 0;
859
+ if ("target" in query) return query.target === "property" && query.propertyVariable != null;
860
860
  const groupQueries = "and" in query ? query.and : query.or;
861
- for (const groupQuery of groupQueries) if (hasPropertyQueryWithPropertyVariables(groupQuery)) return true;
861
+ for (const groupQuery of groupQueries) if (hasPropertyQueryWithPropertyVariable(groupQuery)) return true;
862
862
  return false;
863
863
  }
864
864
  /**
@@ -878,10 +878,10 @@ const setPropertyValuesParamsSchema = z.object({
878
878
  }),
879
879
  isLimitedToLeafPropertyValues: z.boolean().default(false)
880
880
  }).superRefine((value, ctx) => {
881
- if (!hasPropertyQueryWithPropertyVariables(value.queries)) ctx.addIssue({
881
+ if (!hasPropertyQueryWithPropertyVariable(value.queries)) ctx.addIssue({
882
882
  code: "custom",
883
883
  path: ["queries"],
884
- message: "At least one property query with propertyVariables is required"
884
+ message: "At least one property query with propertyVariable is required"
885
885
  });
886
886
  });
887
887
  const setItemsParamsSchema = z.object({
@@ -2393,10 +2393,8 @@ function buildDateRangePredicate(params) {
2393
2393
  /**
2394
2394
  * Build a property label predicate for an XQuery string.
2395
2395
  */
2396
- function buildPropertyLabelPredicate(propertyVariables) {
2397
- const labelPredicates = [];
2398
- for (const propertyVariable of propertyVariables) labelPredicates.push(`@uuid=${stringLiteral(propertyVariable)}`);
2399
- return `label[${buildOrPredicate(labelPredicates)}]`;
2396
+ function buildPropertyLabelPredicate(propertyVariable) {
2397
+ return `label[@uuid=${stringLiteral(propertyVariable)}]`;
2400
2398
  }
2401
2399
  function buildOrCtsQueryExpression(queries) {
2402
2400
  if (queries.length === 1) return queries[0] ?? "cts:false-query()";
@@ -2503,11 +2501,11 @@ function buildItemStringIncludesGroupMember(query) {
2503
2501
  };
2504
2502
  }
2505
2503
  function buildPropertyStringIncludesGroupMember(query) {
2506
- const propertyVariables = query.propertyVariables ?? [];
2504
+ const propertyVariable = query.propertyVariable;
2507
2505
  const predicateParts = [];
2508
2506
  const valueExpression = buildFlattenedContentValuesExpression(`value[not(@inherited="true")]/content[@xml:lang="${query.language}"]`);
2509
2507
  const propertyValue = query.propertyValues[0] ?? "";
2510
- if (propertyVariables.length > 0) predicateParts.push(buildPropertyLabelPredicate(propertyVariables));
2508
+ if (propertyVariable != null) predicateParts.push(buildPropertyLabelPredicate(propertyVariable));
2511
2509
  return {
2512
2510
  rawPredicate: buildPropertyPredicateExpression([...predicateParts, buildRawStringMatchPredicate({
2513
2511
  valueExpression,
@@ -2714,9 +2712,9 @@ function buildPropertyClause(params) {
2714
2712
  const { query, version, queryKey } = params;
2715
2713
  const predicateParts = [];
2716
2714
  const declarations = [];
2717
- const propertyVariables = query.propertyVariables ?? [];
2715
+ const propertyVariable = query.propertyVariable;
2718
2716
  let candidateQueryVar = null;
2719
- if (propertyVariables.length > 0) predicateParts.push(buildPropertyLabelPredicate(propertyVariables));
2717
+ if (propertyVariable != null) predicateParts.push(buildPropertyLabelPredicate(propertyVariable));
2720
2718
  if (query.dataType === "date" || query.dataType === "dateTime") predicateParts.push(buildDateRangePredicate({
2721
2719
  from: query.from,
2722
2720
  to: query.to
@@ -3257,7 +3255,7 @@ function getPropertyVariableUuidsFromQueries(queries) {
3257
3255
  for (const query of pendingQueries) {
3258
3256
  if ("target" in query) {
3259
3257
  if (query.target !== "property") continue;
3260
- for (const propertyVariableUuid of query.propertyVariables ?? []) propertyVariableUuids.add(propertyVariableUuid);
3258
+ if (query.propertyVariable != null) propertyVariableUuids.add(query.propertyVariable);
3261
3259
  continue;
3262
3260
  }
3263
3261
  pendingQueries.push(..."and" in query ? query.and : query.or);
@@ -4250,25 +4248,37 @@ function parseWebElementProperties(componentProperty, elementResource) {
4250
4248
  case "query": {
4251
4249
  const setLinks = links.filter((link) => link.category === "set");
4252
4250
  if (setLinks.every((link) => link.uuid === null)) throw new Error(`Set links not found for the following component: “${componentName}”`);
4253
- const queries = [];
4251
+ const items = [];
4254
4252
  if (componentProperty.properties.length === 0) throw new Error(`Query properties not found for the following component: “${componentName}”`);
4255
- for (const query of componentProperty.properties) {
4256
- const querySubProperties = query.properties;
4253
+ for (const queryItem of componentProperty.properties) {
4254
+ const querySubProperties = queryItem.properties;
4257
4255
  const label = getPropertyValueByLabel(querySubProperties, "query-prompt");
4258
4256
  if (label === null) continue;
4259
- const propertyVariableUuids = getPropertyByLabel(querySubProperties, "use-property")?.values.map((value) => value.uuid).filter((uuid) => uuid !== null) ?? [];
4257
+ const queries = (getPropertyByLabel(querySubProperties, "use-property")?.values.filter((value) => value.uuid !== null) ?? []).map((propertyVariable) => {
4258
+ if (propertyVariable.uuid === null) throw new Error(`Property variable UUID not found for the following component: “${componentName}”`);
4259
+ const dataType = propertyVariable.dataType;
4260
+ if (dataType === "coordinate") throw new Error(`Query prompts with data type "coordinate" are not supported for the following component: “${componentName}”`);
4261
+ return {
4262
+ target: "property",
4263
+ propertyVariable: propertyVariable.uuid,
4264
+ dataType,
4265
+ matchMode: "exact",
4266
+ isCaseSensitive: true,
4267
+ language: "eng"
4268
+ };
4269
+ });
4260
4270
  let startIcon = getPropertyValueByLabel(querySubProperties, "start-icon");
4261
4271
  startIcon ??= null;
4262
4272
  let endIcon = getPropertyValueByLabel(querySubProperties, "end-icon");
4263
4273
  endIcon ??= null;
4264
- queries.push({
4274
+ items.push({
4265
4275
  label,
4266
- propertyVariableUuids,
4276
+ queries,
4267
4277
  startIcon,
4268
4278
  endIcon
4269
4279
  });
4270
4280
  }
4271
- if (queries.length === 0) throw new Error(`No queries found for the following component: “${componentName}”`);
4281
+ if (items.length === 0) throw new Error(`No queries found for the following component: “${componentName}”`);
4272
4282
  const options = {
4273
4283
  attributeFilters: {
4274
4284
  bibliographies: elementResource.options?.filterBibliography ?? false,
@@ -4299,7 +4309,7 @@ function parseWebElementProperties(componentProperty, elementResource) {
4299
4309
  properties = {
4300
4310
  component: "query",
4301
4311
  linkUuids: setLinks.map((link) => link.uuid).filter((uuid) => uuid !== null),
4302
- queries,
4312
+ items,
4303
4313
  options,
4304
4314
  displayedProperties: displayedProperties?.values.filter((value) => value.uuid !== null).map((value) => ({
4305
4315
  uuid: value.uuid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "0.21.1",
3
+ "version": "0.21.3",
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",
@@ -51,7 +51,7 @@
51
51
  "bumpp": "^11.0.1",
52
52
  "eslint": "^10.1.0",
53
53
  "prettier": "^3.8.1",
54
- "tsdown": "^0.21.5",
54
+ "tsdown": "^0.21.6",
55
55
  "typescript": "^6.0.2"
56
56
  },
57
57
  "scripts": {