ochre-sdk 1.0.8 → 1.0.9
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 +7 -61
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -621,33 +621,6 @@ function createSchemaValidationError(message, issues) {
|
|
|
621
621
|
return new Error(message, { cause: issues });
|
|
622
622
|
}
|
|
623
623
|
/**
|
|
624
|
-
* Logs Valibot validation issues to the console with detailed formatting
|
|
625
|
-
* @param issues - The validation issues to log
|
|
626
|
-
* @param depth - The depth of the issues for indentation
|
|
627
|
-
* @internal
|
|
628
|
-
*/
|
|
629
|
-
function logIssues(issues, depth = 0) {
|
|
630
|
-
if (issues == null) return;
|
|
631
|
-
for (const issue of issues) {
|
|
632
|
-
const indent = " ".repeat(depth);
|
|
633
|
-
const prefix = depth === 0 ? "❌" : "└─";
|
|
634
|
-
const pathStr = issue.path != null && issue.path.length > 0 ? ` at ${v.getDotPath(issue)}` : "";
|
|
635
|
-
const typeInfo = `[${issue.kind}:${issue.type}]`;
|
|
636
|
-
console.error(`${indent}${prefix} ${typeInfo} ${issue.message}${pathStr}`);
|
|
637
|
-
if (issue.expected != null) {
|
|
638
|
-
console.error(`${indent} Expected: ${issue.expected}`);
|
|
639
|
-
console.error(`${indent} Received: ${issue.received}`);
|
|
640
|
-
}
|
|
641
|
-
if (issue.input !== void 0 && typeof issue.input !== "object") console.error(`${indent} Input: ${JSON.stringify(issue.input)}`);
|
|
642
|
-
if (issue.requirement !== void 0) console.error(`${indent} Requirement: ${JSON.stringify(issue.requirement)}`);
|
|
643
|
-
if (issue.issues != null && issue.issues.length > 0) {
|
|
644
|
-
console.error(`${indent} Nested issues:`);
|
|
645
|
-
logIssues(issue.issues, depth + 1);
|
|
646
|
-
}
|
|
647
|
-
if (depth === 0) console.error("");
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
624
|
* Validates a pseudo-UUID string
|
|
652
625
|
* @param value - The string to validate
|
|
653
626
|
* @returns True if the string is a valid pseudo-UUID, false otherwise
|
|
@@ -3766,10 +3739,7 @@ async function fetchGallery(params, options) {
|
|
|
3766
3739
|
const dataRaw = await response.text();
|
|
3767
3740
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3768
3741
|
const { success, issues, output } = v.safeParse(XMLGalleryData, data);
|
|
3769
|
-
if (!success)
|
|
3770
|
-
logIssues(issues);
|
|
3771
|
-
throw createSchemaValidationError("Failed to parse gallery XML", issues);
|
|
3772
|
-
}
|
|
3742
|
+
if (!success) throw createSchemaValidationError("Failed to parse gallery XML", issues);
|
|
3773
3743
|
restoreXMLMetadata(output, data);
|
|
3774
3744
|
return {
|
|
3775
3745
|
gallery: parseGallery(output, { languages: resolveGalleryLanguages(output, requestedLanguages) }),
|
|
@@ -3777,7 +3747,6 @@ async function fetchGallery(params, options) {
|
|
|
3777
3747
|
detailedError: null
|
|
3778
3748
|
};
|
|
3779
3749
|
} catch (error) {
|
|
3780
|
-
console.error(error);
|
|
3781
3750
|
return {
|
|
3782
3751
|
gallery: null,
|
|
3783
3752
|
...getErrorOutput(error, "Failed to fetch gallery")
|
|
@@ -3877,10 +3846,7 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3877
3846
|
const dataRaw = await response.text();
|
|
3878
3847
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3879
3848
|
const { success, issues, output } = v.safeParse(XMLItemLinksData, data);
|
|
3880
|
-
if (!success)
|
|
3881
|
-
logIssues(issues);
|
|
3882
|
-
throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
|
|
3883
|
-
}
|
|
3849
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
|
|
3884
3850
|
restoreXMLMetadata(output, data);
|
|
3885
3851
|
const languages = resolveItemLinksLanguages(output, requestedLanguages);
|
|
3886
3852
|
return {
|
|
@@ -3892,7 +3858,6 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3892
3858
|
detailedError: null
|
|
3893
3859
|
};
|
|
3894
3860
|
} catch (error) {
|
|
3895
|
-
console.error(error);
|
|
3896
3861
|
return {
|
|
3897
3862
|
items: null,
|
|
3898
3863
|
...getErrorOutput(error, "Unknown error")
|
|
@@ -3979,10 +3944,7 @@ async function fetchItem(uuid, options) {
|
|
|
3979
3944
|
const dataRaw = await response.text();
|
|
3980
3945
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3981
3946
|
const { success, issues, output } = v.safeParse(XMLData, data);
|
|
3982
|
-
if (!success)
|
|
3983
|
-
logIssues(issues);
|
|
3984
|
-
throw createSchemaValidationError("Failed to parse OCHRE data", issues);
|
|
3985
|
-
}
|
|
3947
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE data", issues);
|
|
3986
3948
|
restoreXMLMetadata(output, data);
|
|
3987
3949
|
const category = options?.category ?? inferFetchItemCategory(output.result.ochre);
|
|
3988
3950
|
assertItemCategoryAllowed(category, options?.containedItemCategory);
|
|
@@ -3996,7 +3958,6 @@ async function fetchItem(uuid, options) {
|
|
|
3996
3958
|
detailedError: null
|
|
3997
3959
|
};
|
|
3998
3960
|
} catch (error) {
|
|
3999
|
-
console.error(error);
|
|
4000
3961
|
return {
|
|
4001
3962
|
item: null,
|
|
4002
3963
|
...getErrorOutput(error, "Unknown error")
|
|
@@ -5054,10 +5015,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
5054
5015
|
const dataRaw = await response.text();
|
|
5055
5016
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
5056
5017
|
const { success, issues, output } = v.safeParse(XMLSetItemsData, data);
|
|
5057
|
-
if (!success)
|
|
5058
|
-
logIssues(issues);
|
|
5059
|
-
throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
|
|
5060
|
-
}
|
|
5018
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
|
|
5061
5019
|
restoreXMLMetadata(output, data);
|
|
5062
5020
|
if (containedItemCategories != null) {
|
|
5063
5021
|
const missingCategories = containedItemCategories.filter((category) => !hasSetItemsCategory(output.result.ochre.items, category));
|
|
@@ -5080,7 +5038,6 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
5080
5038
|
detailedError: null
|
|
5081
5039
|
};
|
|
5082
5040
|
} catch (error) {
|
|
5083
|
-
console.error(error);
|
|
5084
5041
|
return {
|
|
5085
5042
|
totalCount: null,
|
|
5086
5043
|
page: null,
|
|
@@ -5533,10 +5490,7 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5533
5490
|
const dataRaw = await response.text();
|
|
5534
5491
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
5535
5492
|
const { success, issues, output } = v.safeParse(responseSchema, data);
|
|
5536
|
-
if (!success)
|
|
5537
|
-
logIssues(issues);
|
|
5538
|
-
throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
|
|
5539
|
-
}
|
|
5493
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
|
|
5540
5494
|
const parsedPropertyValues = [];
|
|
5541
5495
|
const parsedAttributeValues = [];
|
|
5542
5496
|
if (output.result.ochre.propertyValue != null) parsedPropertyValues.push(...Array.isArray(output.result.ochre.propertyValue) ? output.result.ochre.propertyValue : [output.result.ochre.propertyValue]);
|
|
@@ -5590,7 +5544,6 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5590
5544
|
detailedError: null
|
|
5591
5545
|
};
|
|
5592
5546
|
} catch (error) {
|
|
5593
|
-
console.error(error);
|
|
5594
5547
|
return {
|
|
5595
5548
|
propertyValues: null,
|
|
5596
5549
|
propertyValuesByPropertyVariableUuid: null,
|
|
@@ -6677,11 +6630,8 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
6677
6630
|
};
|
|
6678
6631
|
break;
|
|
6679
6632
|
}
|
|
6680
|
-
default:
|
|
6681
|
-
console.warn(`Invalid or non-implemented component name “${unparsedComponentName.toString()}” for the following element: “${parseStringContent(elementResource.identification.label, options)}”`);
|
|
6682
|
-
break;
|
|
6633
|
+
default: throw new Error(`Invalid or non-implemented component name “${unparsedComponentName.toString()}” for the following element: “${parseStringContent(elementResource.identification.label, options)}”`);
|
|
6683
6634
|
}
|
|
6684
|
-
if (properties === null) throw new Error(formatComponentError("Properties not found", componentName, elementResource), { cause: componentProperty });
|
|
6685
6635
|
return properties;
|
|
6686
6636
|
}
|
|
6687
6637
|
function parseWebTitle(properties, identification, overrides) {
|
|
@@ -7262,10 +7212,7 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
7262
7212
|
const dataRaw = await response.text();
|
|
7263
7213
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
7264
7214
|
const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
|
|
7265
|
-
if (!success)
|
|
7266
|
-
logIssues(issues);
|
|
7267
|
-
throw createSchemaValidationError("Failed to parse website XML", issues);
|
|
7268
|
-
}
|
|
7215
|
+
if (!success) throw createSchemaValidationError("Failed to parse website XML", issues);
|
|
7269
7216
|
restoreXMLMetadata(output, data);
|
|
7270
7217
|
return {
|
|
7271
7218
|
website: parseWebsite(output, { languages: options?.languages }),
|
|
@@ -7273,7 +7220,6 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
7273
7220
|
detailedError: null
|
|
7274
7221
|
};
|
|
7275
7222
|
} catch (error) {
|
|
7276
|
-
console.error(error);
|
|
7277
7223
|
return {
|
|
7278
7224
|
website: null,
|
|
7279
7225
|
...getErrorOutput(error, "Unknown error")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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,7 +52,7 @@
|
|
|
52
52
|
"@antfu/eslint-config": "^9.0.0",
|
|
53
53
|
"@types/node": "^24.12.4",
|
|
54
54
|
"bumpp": "^11.1.0",
|
|
55
|
-
"eslint": "^10.
|
|
55
|
+
"eslint": "^10.4.0",
|
|
56
56
|
"prettier": "^3.8.3",
|
|
57
57
|
"tsdown": "^0.22.0",
|
|
58
58
|
"typescript": "^6.0.3",
|