@digitalculture/ochre-sdk 0.18.7 → 0.18.8
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.mjs +18 -23
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3851,18 +3851,19 @@ async function fetchItemsByUuidsAndLinks(params, categoryParams, options) {
|
|
|
3851
3851
|
* Schema for a single property value query item in the OCHRE API response
|
|
3852
3852
|
*/
|
|
3853
3853
|
const propertyValueQueryItemSchema = z.object({
|
|
3854
|
-
uuid: z.string()
|
|
3854
|
+
uuid: z.string(),
|
|
3855
3855
|
dataType: z.string(),
|
|
3856
|
-
identification: identificationSchema.optional(),
|
|
3857
3856
|
rawValue: z.union([
|
|
3858
3857
|
z.string(),
|
|
3859
3858
|
z.number(),
|
|
3860
3859
|
z.boolean()
|
|
3861
3860
|
]).optional(),
|
|
3862
|
-
|
|
3861
|
+
content: z.union([
|
|
3863
3862
|
z.string(),
|
|
3864
3863
|
z.number(),
|
|
3865
|
-
z.boolean()
|
|
3864
|
+
z.boolean(),
|
|
3865
|
+
richTextStringSchema,
|
|
3866
|
+
z.array(richTextStringSchema)
|
|
3866
3867
|
]).optional()
|
|
3867
3868
|
}).transform((val) => {
|
|
3868
3869
|
const returnValue = {
|
|
@@ -3872,28 +3873,22 @@ const propertyValueQueryItemSchema = z.object({
|
|
|
3872
3873
|
};
|
|
3873
3874
|
switch (val.dataType) {
|
|
3874
3875
|
case "IDREF":
|
|
3875
|
-
returnValue.content = val.uuid
|
|
3876
|
-
returnValue.label = val.
|
|
3877
|
-
break;
|
|
3878
|
-
case "string":
|
|
3879
|
-
case "date":
|
|
3880
|
-
case "dateTime":
|
|
3881
|
-
returnValue.content = val.rawValue?.toString() ?? null;
|
|
3882
|
-
returnValue.label = val.value?.toString() ?? null;
|
|
3876
|
+
returnValue.content = val.uuid !== "" ? val.uuid : null;
|
|
3877
|
+
returnValue.label = val.content != null && val.content !== "" ? typeof val.content === "object" ? parseStringContent({ content: val.content }) : parseFakeString(val.content) : null;
|
|
3883
3878
|
break;
|
|
3884
3879
|
case "integer":
|
|
3885
3880
|
case "decimal":
|
|
3886
3881
|
case "time":
|
|
3887
|
-
returnValue.content = val.rawValue != null ? Number(val.rawValue) : null;
|
|
3888
|
-
returnValue.label = val.
|
|
3882
|
+
returnValue.content = val.rawValue != null && val.rawValue !== "" ? Number(val.rawValue) : null;
|
|
3883
|
+
returnValue.label = val.content != null && val.content !== "" ? val.content.toString() : null;
|
|
3889
3884
|
break;
|
|
3890
3885
|
case "boolean":
|
|
3891
|
-
returnValue.content = val.rawValue != null ? Boolean(val.rawValue) : null;
|
|
3892
|
-
returnValue.label = val.
|
|
3886
|
+
returnValue.content = val.rawValue != null && val.rawValue !== "" ? Boolean(val.rawValue) : null;
|
|
3887
|
+
returnValue.label = val.content != null && val.content !== "" ? val.content.toString() : null;
|
|
3893
3888
|
break;
|
|
3894
3889
|
default:
|
|
3895
|
-
returnValue.content = val.rawValue
|
|
3896
|
-
returnValue.label = val.
|
|
3890
|
+
returnValue.content = val.rawValue != null && val.rawValue !== "" ? val.rawValue.toString() : null;
|
|
3891
|
+
returnValue.label = val.content != null && val.content !== "" ? val.content.toString() : null;
|
|
3897
3892
|
break;
|
|
3898
3893
|
}
|
|
3899
3894
|
return returnValue;
|
|
@@ -3901,7 +3896,7 @@ const propertyValueQueryItemSchema = z.object({
|
|
|
3901
3896
|
/**
|
|
3902
3897
|
* Schema for the property values by property variables OCHRE API response
|
|
3903
3898
|
*/
|
|
3904
|
-
const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({
|
|
3899
|
+
const responseSchema = z.object({ result: z.union([z.object({ ochre: z.object({ propertyValue: z.union([propertyValueQueryItemSchema, z.array(propertyValueQueryItemSchema)]) }) }), z.array(z.unknown()).length(0)]) });
|
|
3905
3900
|
/**
|
|
3906
3901
|
* Build an XQuery string to fetch property values by property variables from the OCHRE API
|
|
3907
3902
|
* @param params - The parameters for the fetch
|
|
@@ -3924,9 +3919,9 @@ function buildXQuery(params, options) {
|
|
|
3924
3919
|
/value
|
|
3925
3920
|
|
|
3926
3921
|
for $v in $values
|
|
3927
|
-
return <
|
|
3928
|
-
if (
|
|
3929
|
-
}</
|
|
3922
|
+
return <propertyValue uuid="{$v/@uuid}" rawValue="{$v/@rawValue}" dataType="{$v/@dataType}">{
|
|
3923
|
+
if ($v/content) then $v/content else $v/text()
|
|
3924
|
+
}</propertyValue>`}}</ochre>`;
|
|
3930
3925
|
}
|
|
3931
3926
|
/**
|
|
3932
3927
|
* Fetches and parses property values by property variables from the OCHRE API
|
|
@@ -3954,7 +3949,7 @@ async function fetchPropertyValuesByPropertyVariables(params, options) {
|
|
|
3954
3949
|
const data = await response.json();
|
|
3955
3950
|
const parsedResultRaw = responseSchema.parse(data);
|
|
3956
3951
|
if (Array.isArray(parsedResultRaw.result)) throw new TypeError("No items found");
|
|
3957
|
-
const parsedItems = Array.isArray(parsedResultRaw.result.ochre.
|
|
3952
|
+
const parsedItems = Array.isArray(parsedResultRaw.result.ochre.propertyValue) ? parsedResultRaw.result.ochre.propertyValue : [parsedResultRaw.result.ochre.propertyValue];
|
|
3958
3953
|
const groupedItems = [];
|
|
3959
3954
|
for (const item of parsedItems) {
|
|
3960
3955
|
const existingItem = groupedItems.find((i) => i.content === item.content);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.8",
|
|
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@antfu/eslint-config": "^7.2.0",
|
|
49
|
-
"@types/node": "^24.10.
|
|
49
|
+
"@types/node": "^24.10.10",
|
|
50
50
|
"bumpp": "^10.4.0",
|
|
51
51
|
"eslint": "^9.39.2",
|
|
52
52
|
"prettier": "^3.8.1",
|