@digitalculture/ochre-sdk 0.17.17 → 0.18.1

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
@@ -599,19 +599,13 @@ type Gallery = {
599
599
  maxLength: number;
600
600
  };
601
601
  /**
602
- * Represents a property query item with its item and value UUIDs
602
+ * Represents a property query item with its UUID, raw value, count, and content
603
603
  */
604
- type PropertyQueryItem = {
605
- value: {
606
- uuid: string | null;
607
- category: string | null;
608
- type: string | null;
609
- dataType: string | null;
610
- publicationDateTime: string | null;
611
- content: string;
612
- label: string | null;
613
- };
614
- resultUuids: Array<string>;
604
+ type PropertyValueQueryItem = {
605
+ uuid: string | null;
606
+ count: number;
607
+ label: string | null;
608
+ content: string | number | boolean | null;
615
609
  };
616
610
  /**
617
611
  * Represents a metadata object given a UUID
@@ -1114,10 +1108,11 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1114
1108
  * Fetches and parses items by property values from the OCHRE API
1115
1109
  *
1116
1110
  * @param params - The parameters for the fetch
1117
- * @param params.propertyVariableUuids - The property variable UUIDs to query by
1118
- * @param params.propertyValues - The property values to query by
1119
1111
  * @param params.projectScopeUuid - The UUID of the project scope
1120
1112
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1113
+ * @param params.propertyVariableUuids - The property variable UUIDs to query by
1114
+ * @param params.propertyValues - The property values to query by
1115
+ * @param params.itemCategory - The category of the items to fetch
1121
1116
  * @param categoryParams - The category parameters for the fetch
1122
1117
  * @param categoryParams.category - The category of the items to fetch
1123
1118
  * @param categoryParams.itemCategories - The categories of the items to fetch
@@ -1127,13 +1122,14 @@ declare function fetchItem<T extends DataCategory = DataCategory, U extends Data
1127
1122
  * @returns The parsed items by property values or null if the fetch/parse fails
1128
1123
  */
1129
1124
  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: {
1125
+ projectScopeUuid: string;
1126
+ belongsToCollectionScopeUuids: Array<string>;
1130
1127
  propertyVariableUuids: Array<string>;
1131
1128
  propertyValues: Array<{
1132
1129
  dataType: Exclude<PropertyValueContentType, "coordinate">;
1133
1130
  value: string;
1134
1131
  }>;
1135
- projectScopeUuid: string;
1136
- belongsToCollectionScopeUuids: Array<string>;
1132
+ itemCategory?: "resource" | "spatialUnit" | "concept" | "text";
1137
1133
  }, categoryParams?: {
1138
1134
  category?: T;
1139
1135
  itemCategories?: U;
@@ -1155,7 +1151,9 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1155
1151
  * @param params - The parameters for the fetch
1156
1152
  * @param params.projectScopeUuid - The UUID of the project scope
1157
1153
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
1158
- * @param params.propertyUuids - The property UUIDs to query by
1154
+ * @param params.propertyVariables - The property variables to query by
1155
+ * @param params.propertyVariables.dataType - The data type of the property variables
1156
+ * @param params.propertyVariables.uuids - The UUIDs of the property variables
1159
1157
  * @param options - Options for the fetch
1160
1158
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
1161
1159
  * @param options.version - The version of the OCHRE API to use
@@ -1164,12 +1162,15 @@ declare function fetchItemsByPropertyValues<T extends DataCategory = DataCategor
1164
1162
  declare function fetchPropertyValuesByPropertyVariables(params: {
1165
1163
  projectScopeUuid: string;
1166
1164
  belongsToCollectionScopeUuids: Array<string>;
1167
- propertyUuids: Array<string>;
1165
+ propertyVariables: {
1166
+ dataType: Exclude<PropertyValueContentType, "coordinate">;
1167
+ uuids: Array<string>;
1168
+ };
1168
1169
  }, options?: {
1169
1170
  customFetch?: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>;
1170
1171
  version: ApiVersion;
1171
1172
  }): Promise<{
1172
- items: Array<PropertyQueryItem> | null;
1173
+ items: Array<PropertyValueQueryItem> | null;
1173
1174
  error: null;
1174
1175
  } | {
1175
1176
  items: null;
@@ -1415,4 +1416,4 @@ declare function flattenItemProperties<T extends DataCategory = DataCategory, U
1415
1416
  */
1416
1417
  declare function getLeafPropertyValues<T extends PropertyValueContentType = PropertyValueContentType>(propertyValues: Array<PropertyValueContent<T>>): Array<PropertyValueContent<T>>;
1417
1418
  //#endregion
1418
- 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, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
1419
+ 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, PropertyValue, PropertyValueContent, PropertyValueContentType, PropertyValueQueryItem, 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, getLeafPropertyValues, getPropertyByLabel, getPropertyByUuid, getPropertyValueByLabel, getPropertyValueByUuid, getPropertyValuesByLabel, getPropertyValuesByUuid, getUniqueProperties, getUniquePropertyLabels };
package/dist/index.mjs CHANGED
@@ -95,6 +95,15 @@ const richTextStringSchema = z.object({
95
95
  lang: z.string().optional()
96
96
  });
97
97
  /**
98
+ * Schema for validating identification
99
+ * @internal
100
+ */
101
+ const identificationSchema = z.object({
102
+ label: z.object({ content: richTextStringSchema }),
103
+ abbreviation: z.object({ content: richTextStringSchema }).optional(),
104
+ code: z.string().optional()
105
+ });
106
+ /**
98
107
  * Schema for validating filters
99
108
  * @internal
100
109
  */
@@ -3562,43 +3571,54 @@ async function fetchItem(uuid, category, itemCategories, options) {
3562
3571
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
3563
3572
  * @param params.propertyVariableUuids - An array of property variable UUIDs to fetch
3564
3573
  * @param params.propertyValues - An array of property values to fetch
3574
+ * @param params.itemCategory - The category of the items to fetch
3565
3575
  * @param options - Options for the fetch
3566
3576
  * @param options.version - The version of the OCHRE API to use
3567
3577
  * @returns An XQuery string
3568
3578
  */
3569
3579
  function buildXQuery$1(params, options) {
3570
3580
  const version = options?.version ?? DEFAULT_API_VERSION;
3571
- const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids } = params;
3581
+ const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids, itemCategory } = params;
3572
3582
  let belongsToCollectionScopeFilter = "";
3573
3583
  if (belongsToCollectionScopeUuids.length > 0) belongsToCollectionScopeFilter = `[properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]]`;
3574
3584
  const propertyVariables = propertyVariableUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3575
3585
  const propertyValuesFilters = propertyValues.map(({ dataType, value }) => {
3576
- if (dataType === "IDREF") return `value[@uuid="${value}"]`;
3577
- if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value[@rawValue="${value}"]`;
3586
+ if (dataType === "IDREF") return `value/@uuid="${value}"`;
3587
+ if (dataType === "date" || dataType === "dateTime" || dataType === "time" || dataType === "integer" || dataType === "decimal" || dataType === "boolean") return `value/@rawValue="${value}"`;
3578
3588
  return `value="${value}"`;
3579
3589
  }).join(" or ");
3580
- return `<ochre>{${`let $matches := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${belongsToCollectionScopeFilter}/properties//property[label[${propertyVariables}]][${propertyValuesFilters}]
3590
+ return `<ochre>{${`let $match-uuids := distinct-values(
3591
+ ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
3592
+ /*${belongsToCollectionScopeFilter}
3593
+ [properties//property/label[${propertyVariables}]
3594
+ [${propertyValuesFilters}]]
3595
+ /@uuid
3596
+ )
3597
+
3598
+ let $items := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
3599
+ /${itemCategory ?? "*"}[@uuid = $match-uuids
3600
+ or bibliographies/bibliography/@uuid = $match-uuids]
3581
3601
 
3582
- let $items := $matches/ancestor::*[parent::ochre]
3583
- let $unique-uuids := distinct-values($items/@uuid)
3602
+ let $unique-uuids := distinct-values($items/@uuid)
3584
3603
 
3585
- for $uuid in $unique-uuids
3586
- let $item := $items[@uuid = $uuid][1]
3587
- let $category := local-name($item)
3604
+ for $uuid in $unique-uuids
3605
+ let $item := $items[@uuid = $uuid][1]
3606
+ let $category := local-name($item)
3588
3607
 
3589
- return element { node-name($item) } {
3590
- $item/@*,
3591
- $item/node()[not(local-name(.) = $category)]
3592
- }`}}</ochre>`;
3608
+ return element { node-name($item) } {
3609
+ $item/@*,
3610
+ $item/node()[not(local-name(.) = $category)]
3611
+ }`}}</ochre>`;
3593
3612
  }
3594
3613
  /**
3595
3614
  * Fetches and parses items by property values from the OCHRE API
3596
3615
  *
3597
3616
  * @param params - The parameters for the fetch
3598
- * @param params.propertyVariableUuids - The property variable UUIDs to query by
3599
- * @param params.propertyValues - The property values to query by
3600
3617
  * @param params.projectScopeUuid - The UUID of the project scope
3601
3618
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
3619
+ * @param params.propertyVariableUuids - The property variable UUIDs to query by
3620
+ * @param params.propertyValues - The property values to query by
3621
+ * @param params.itemCategory - The category of the items to fetch
3602
3622
  * @param categoryParams - The category parameters for the fetch
3603
3623
  * @param categoryParams.category - The category of the items to fetch
3604
3624
  * @param categoryParams.itemCategories - The categories of the items to fetch
@@ -3611,18 +3631,19 @@ async function fetchItemsByPropertyValues(params, categoryParams, options) {
3611
3631
  try {
3612
3632
  const customFetch = options?.customFetch;
3613
3633
  const version = options?.version ?? DEFAULT_API_VERSION;
3614
- const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids } = params;
3634
+ const { propertyVariableUuids, propertyValues, projectScopeUuid, belongsToCollectionScopeUuids, itemCategory } = params;
3615
3635
  const { category, itemCategories } = categoryParams ?? {};
3616
3636
  const xquery = buildXQuery$1({
3617
3637
  projectScopeUuid,
3618
3638
  belongsToCollectionScopeUuids,
3619
3639
  propertyVariableUuids,
3620
- propertyValues
3640
+ propertyValues,
3641
+ itemCategory
3621
3642
  }, { version });
3622
3643
  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="*"`);
3623
3644
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
3624
3645
  const data = await response.json();
3625
- if (Object.keys(data.result.ochre).length === 0) throw new Error("No items found");
3646
+ if (Array.isArray(data.result) || Object.keys(data.result.ochre).length === 0) throw new Error("No items found");
3626
3647
  if (category != null && data.result.ochre[category] == null) throw new Error(`No items found for category: ${category}`);
3627
3648
  if ((category === "set" || category === "tree") && itemCategories != null && "items" in data.result.ochre[category] && Array.isArray(data.result.ochre[category].items) && data.result.ochre[category].items.every((item) => item.category !== itemCategories)) throw new Error(`No items found for category: ${category} and item categories: ${itemCategories}`);
3628
3649
  const items = [];
@@ -3682,60 +3703,119 @@ async function fetchItemsByPropertyValues(params, categoryParams, options) {
3682
3703
  //#endregion
3683
3704
  //#region src/utils/fetchers/property-values-by-property-variables.ts
3684
3705
  /**
3685
- * Schema for a single property value by property variable item in the OCHRE API response
3686
- */
3687
- const responseItemSchema = z.object({
3688
- property: uuidSchema,
3689
- category: z.object({
3690
- uuid: uuidSchema,
3691
- content: z.string()
3692
- }),
3693
- value: z.object({
3694
- uuid: uuidSchema.optional(),
3695
- category: z.string().optional(),
3696
- type: z.string().optional(),
3697
- dataType: z.string().optional(),
3698
- publicationDateTime: z.string().optional(),
3699
- content: z.union([
3700
- z.string(),
3701
- z.number(),
3702
- z.boolean(),
3703
- richTextStringSchema,
3704
- z.array(richTextStringSchema)
3705
- ]).optional(),
3706
- rawValue: z.union([
3707
- z.string(),
3708
- z.number(),
3709
- z.boolean()
3710
- ]).optional()
3711
- })
3706
+ * Schema for a single property value query item in the OCHRE API response
3707
+ */
3708
+ const propertyValueQueryItemSchema = z.object({
3709
+ uuid: uuidSchema.optional().transform((val) => val ?? null),
3710
+ count: z.number(),
3711
+ dataType: z.string(),
3712
+ identification: identificationSchema.optional(),
3713
+ label: z.union([
3714
+ z.string(),
3715
+ z.number(),
3716
+ z.boolean()
3717
+ ]).optional().transform((val) => val?.toString() ?? null),
3718
+ content: z.union([
3719
+ z.string(),
3720
+ z.number(),
3721
+ z.boolean()
3722
+ ]).optional().transform((val) => val ?? null)
3723
+ }).transform((val) => {
3724
+ let value = val;
3725
+ switch (val.dataType) {
3726
+ case "IDREF":
3727
+ case "string":
3728
+ case "date":
3729
+ case "dateTime":
3730
+ value = {
3731
+ ...val,
3732
+ content: val.content?.toString() ?? null
3733
+ };
3734
+ break;
3735
+ case "integer":
3736
+ case "decimal":
3737
+ case "time":
3738
+ value = {
3739
+ ...val,
3740
+ content: val.content !== null ? Number(val.content) : null
3741
+ };
3742
+ break;
3743
+ case "boolean":
3744
+ value = {
3745
+ ...val,
3746
+ content: val.content !== null ? Boolean(val.content) : null
3747
+ };
3748
+ break;
3749
+ default:
3750
+ value = val;
3751
+ break;
3752
+ }
3753
+ if ("identification" in value && value.identification != null) {
3754
+ const { identification, ...rest } = value;
3755
+ value = {
3756
+ ...rest,
3757
+ content: parseStringContent({ content: identification.label.content })
3758
+ };
3759
+ }
3760
+ return value;
3712
3761
  });
3713
3762
  /**
3714
3763
  * Schema for the property values by property variables OCHRE API response
3715
3764
  */
3716
- const responseSchema = z.object({ result: z.object({ ochre: z.object({ item: z.union([responseItemSchema, z.array(responseItemSchema)]) }) }) });
3765
+ const responseSchema = z.object({ result: z.object({ ochre: z.object({ item: z.union([propertyValueQueryItemSchema, z.array(propertyValueQueryItemSchema)]) }) }) });
3717
3766
  /**
3718
3767
  * Build an XQuery string to fetch property values by property variables from the OCHRE API
3719
3768
  * @param params - The parameters for the fetch
3720
3769
  * @param params.projectScopeUuid - The UUID of the project scope
3721
3770
  * @param params.belongsToCollectionScopeUuids - An array of collection scope UUIDs to filter by
3722
- * @param params.propertyUuids - An array of property UUIDs to fetch
3771
+ * @param params.propertyVariables - An array of property variables to fetch
3772
+ * @param params.propertyVariables.dataType - The data type of the property variables
3773
+ * @param params.propertyVariables.uuids - The UUIDs of the property variables
3723
3774
  * @param options - Options for the fetch
3724
3775
  * @param options.version - The version of the OCHRE API to use
3725
3776
  * @returns An XQuery string
3726
3777
  */
3727
3778
  function buildXQuery(params, options) {
3728
3779
  const version = options?.version ?? DEFAULT_API_VERSION;
3729
- const { projectScopeUuid, belongsToCollectionScopeUuids, propertyUuids } = params;
3780
+ const { projectScopeUuid, belongsToCollectionScopeUuids, propertyVariables } = params;
3730
3781
  let collectionScopeFilter = "";
3731
3782
  if (belongsToCollectionScopeUuids.length > 0) collectionScopeFilter = `[properties/property[label/@uuid="${BELONG_TO_COLLECTION_UUID}"][value[${belongsToCollectionScopeUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ")}]]]`;
3732
- const propertyFilters = propertyUuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3733
- return `<ochre>{${`for $q in ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]/*${collectionScopeFilter}/properties//property[label[${propertyFilters}]]
3734
- return <item>
3735
- <property>{xs:string($q/label/@uuid)}</property>
3736
- <value> {$q/*[2]/@*} {$q/*[2]/text()} {$q/*[2]/content} </value>
3737
- <category> {$q/ancestor::node()[local-name(.)="properties"]/../@uuid} {local-name($q/ancestor::node()[local-name(.)="properties"]/../self::node())} </category>
3738
- </item>`}}</ochre>`;
3783
+ const propertyVariableFilters = propertyVariables.uuids.map((uuid) => `@uuid="${uuid}"`).join(" or ");
3784
+ const isIDREF = propertyVariables.dataType === "IDREF";
3785
+ return `<ochre>{${`let $matching-props := ${version === 2 ? "doc()" : "input()"}/ochre[@uuidBelongsTo="${projectScopeUuid}"]
3786
+ /*${collectionScopeFilter}
3787
+ /properties//property[label[${propertyVariableFilters}]]
3788
+
3789
+ let $pairs :=
3790
+ for $prop in $matching-props
3791
+ return <p
3792
+ v="{$prop/${isIDREF ? "value/@uuid" : propertyVariables.dataType === "date" || propertyVariables.dataType === "dateTime" || propertyVariables.dataType === "time" || propertyVariables.dataType === "integer" || propertyVariables.dataType === "decimal" || propertyVariables.dataType === "boolean" ? "value/@rawValue" : "value"}}"
3793
+ r="{$prop/value/@rawValue}"
3794
+ d="{$prop/value/@dataType}"
3795
+ i="{$prop/ancestor::*[parent::ochre]/@uuid}">
3796
+ ${isIDREF ? "{$prop/ancestor::*[parent::ochre]/identification}" : "{$prop/value/content/string()} {$prop/value/text()}"}
3797
+ </p>
3798
+
3799
+ let $distinct-vals := distinct-values($pairs/@v)
3800
+
3801
+ for $val in $distinct-vals
3802
+ let $matching := $pairs[@v = $val][1]
3803
+ let $count := count(distinct-values($pairs[@v = $val]/@i))
3804
+ let $rawValue := string($matching/@r)
3805
+ let $dataType := string($matching/@d)
3806
+ ${isIDREF ? `let $identification := $matching[1]/identification
3807
+ let $sortLabel := string($identification/label/content/string/text())
3808
+ order by $count descending, $sortLabel ascending
3809
+
3810
+ return
3811
+ <item count="{$count}" uuid="{$val}" dataType="IDREF">{$identification}</item>` : `let $content := $matching/text()
3812
+ order by $count descending, $content ascending
3813
+
3814
+ return
3815
+ if ($rawValue != "") then
3816
+ <item count="{$count}" label="{$content}" dataType="{$dataType}">{$rawValue}</item>
3817
+ else
3818
+ <item count="{$count}" dataType="{$dataType}">{$content}</item>`}`}}</ochre>`;
3739
3819
  }
3740
3820
  /**
3741
3821
  * Fetches and parses property values by property variables from the OCHRE API
@@ -3743,7 +3823,9 @@ return <item>
3743
3823
  * @param params - The parameters for the fetch
3744
3824
  * @param params.projectScopeUuid - The UUID of the project scope
3745
3825
  * @param params.belongsToCollectionScopeUuids - The collection scope UUIDs to filter by
3746
- * @param params.propertyUuids - The property UUIDs to query by
3826
+ * @param params.propertyVariables - The property variables to query by
3827
+ * @param params.propertyVariables.dataType - The data type of the property variables
3828
+ * @param params.propertyVariables.uuids - The UUIDs of the property variables
3747
3829
  * @param options - Options for the fetch
3748
3830
  * @param options.customFetch - A custom fetch function to use instead of the default fetch
3749
3831
  * @param options.version - The version of the OCHRE API to use
@@ -3753,42 +3835,18 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
3753
3835
  try {
3754
3836
  const customFetch = options?.customFetch;
3755
3837
  const version = options?.version ?? DEFAULT_API_VERSION;
3756
- const { belongsToCollectionScopeUuids, propertyUuids, projectScopeUuid } = params;
3838
+ const { belongsToCollectionScopeUuids, propertyVariables, projectScopeUuid } = params;
3757
3839
  const xquery = buildXQuery({
3758
3840
  projectScopeUuid,
3759
3841
  belongsToCollectionScopeUuids,
3760
- propertyUuids
3842
+ propertyVariables
3761
3843
  }, { version });
3762
3844
  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="*"`);
3763
3845
  if (!response.ok) throw new Error(`OCHRE API responded with status: ${response.status}`);
3764
3846
  const data = await response.json();
3765
3847
  const parsedResultRaw = responseSchema.parse(data);
3766
- const parsedItems = Array.isArray(parsedResultRaw.result.ochre.item) ? parsedResultRaw.result.ochre.item : [parsedResultRaw.result.ochre.item];
3767
- const items = {};
3768
- for (const item of parsedItems) {
3769
- const categoryUuid = item.category.uuid;
3770
- const valueUuid = item.value.uuid;
3771
- const valueContent = item.value.rawValue?.toString() ?? (typeof item.value.content === "string" || typeof item.value.content === "number" || typeof item.value.content === "boolean" ? parseFakeString(item.value.content) : item.value.content != null ? parseStringContent({ content: item.value.content }) : "");
3772
- if (valueContent in items) items[valueContent].resultUuids.push(categoryUuid);
3773
- else items[valueContent] = {
3774
- value: {
3775
- uuid: valueUuid ?? null,
3776
- category: item.value.category ?? null,
3777
- type: item.value.type ?? null,
3778
- dataType: item.value.dataType ?? null,
3779
- publicationDateTime: item.value.publicationDateTime ?? null,
3780
- content: valueContent,
3781
- label: item.value.rawValue != null && item.value.content != null ? typeof item.value.content === "string" || typeof item.value.content === "number" || typeof item.value.content === "boolean" ? item.value.content.toString() : Array.isArray(item.value.content) ? item.value.content.find((content) => content.lang === "eng")?.string.toString() ?? "" : item.value.content.string.toString() : null
3782
- },
3783
- resultUuids: [categoryUuid]
3784
- };
3785
- }
3786
3848
  return {
3787
- items: Object.values(items).toSorted((a, b) => {
3788
- const aValue = a.value.label ?? a.value.content;
3789
- const bValue = b.value.label ?? b.value.content;
3790
- return aValue.localeCompare(bValue, "en-US");
3791
- }).filter((item) => item.value.content !== ""),
3849
+ items: (Array.isArray(parsedResultRaw.result.ochre.item) ? parsedResultRaw.result.ochre.item : [parsedResultRaw.result.ochre.item]).filter((item) => String(item.content).trim() !== ""),
3792
3850
  error: null
3793
3851
  };
3794
3852
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.17.17",
3
+ "version": "0.18.1",
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",
@@ -57,10 +57,10 @@
57
57
  "scripts": {
58
58
  "dev": "tsdown src/index.ts --watch",
59
59
  "build": "tsdown",
60
- "lint": "eslint .",
61
- "lint:fix": "eslint . --fix",
62
- "format": "prettier --check .",
63
- "format:fix": "prettier --write --list-different .",
60
+ "lint": "eslint --cache .",
61
+ "lint:fix": "eslint --cache . --fix",
62
+ "format": "prettier --cache --check .",
63
+ "format:fix": "prettier --cache --write --list-different .",
64
64
  "check-types": "tsc --noEmit",
65
65
  "test": "vitest run",
66
66
  "release": "bumpp"