ochre-sdk 1.0.6 → 1.0.7
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 +44 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -487,7 +487,45 @@ var MultilingualString = class MultilingualString {
|
|
|
487
487
|
};
|
|
488
488
|
//#endregion
|
|
489
489
|
//#region src/utils.ts
|
|
490
|
+
const MAX_SCHEMA_VALIDATION_ISSUES = 3;
|
|
490
491
|
const PSEUDO_UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;
|
|
492
|
+
function getSchemaValidationLeafIssues(issues, leaves = []) {
|
|
493
|
+
for (const issue of issues) {
|
|
494
|
+
if (issue.issues != null && issue.issues.length > 0) {
|
|
495
|
+
getSchemaValidationLeafIssues(issue.issues, leaves);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
leaves.push(issue);
|
|
499
|
+
}
|
|
500
|
+
return leaves;
|
|
501
|
+
}
|
|
502
|
+
function formatSchemaValidationIssue(issue) {
|
|
503
|
+
const path = v.getDotPath(issue);
|
|
504
|
+
return `${path != null && path.length > 0 ? path : "(root)"}: ${issue.message}`;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Formats Valibot validation issues for compact error messages.
|
|
508
|
+
* @param issues - The validation issues to format
|
|
509
|
+
* @internal
|
|
510
|
+
*/
|
|
511
|
+
function formatSchemaValidationIssues(issues) {
|
|
512
|
+
const leafIssues = getSchemaValidationLeafIssues(issues);
|
|
513
|
+
const issuesToFormat = leafIssues.length > 0 ? leafIssues : issues;
|
|
514
|
+
const formattedIssues = [];
|
|
515
|
+
for (const issue of issuesToFormat.slice(0, MAX_SCHEMA_VALIDATION_ISSUES)) formattedIssues.push(formatSchemaValidationIssue(issue));
|
|
516
|
+
const hiddenIssueCount = issuesToFormat.length - formattedIssues.length;
|
|
517
|
+
if (hiddenIssueCount > 0) formattedIssues.push(`+${hiddenIssueCount.toLocaleString("en-US")} more`);
|
|
518
|
+
return `Schema validation failed: ${formattedIssues.join("; ")}`;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Creates an Error whose message includes compact schema-validation details.
|
|
522
|
+
* @param message - The base error message
|
|
523
|
+
* @param issues - The validation issues to include
|
|
524
|
+
* @internal
|
|
525
|
+
*/
|
|
526
|
+
function createSchemaValidationError(message, issues) {
|
|
527
|
+
return new Error(`${message}. ${formatSchemaValidationIssues(issues)}`, { cause: issues });
|
|
528
|
+
}
|
|
491
529
|
/**
|
|
492
530
|
* Logs Valibot validation issues to the console with detailed formatting
|
|
493
531
|
* @param issues - The validation issues to log
|
|
@@ -3636,7 +3674,7 @@ async function fetchGallery(params, options) {
|
|
|
3636
3674
|
const { success, issues, output } = v.safeParse(XMLGalleryData, data);
|
|
3637
3675
|
if (!success) {
|
|
3638
3676
|
logIssues(issues);
|
|
3639
|
-
throw
|
|
3677
|
+
throw createSchemaValidationError("Failed to parse gallery XML", issues);
|
|
3640
3678
|
}
|
|
3641
3679
|
restoreXMLMetadata(output, data);
|
|
3642
3680
|
return {
|
|
@@ -3746,7 +3784,7 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3746
3784
|
const { success, issues, output } = v.safeParse(XMLItemLinksData, data);
|
|
3747
3785
|
if (!success) {
|
|
3748
3786
|
logIssues(issues);
|
|
3749
|
-
throw
|
|
3787
|
+
throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
|
|
3750
3788
|
}
|
|
3751
3789
|
restoreXMLMetadata(output, data);
|
|
3752
3790
|
const languages = resolveItemLinksLanguages(output, requestedLanguages);
|
|
@@ -3847,7 +3885,7 @@ async function fetchItem(uuid, options) {
|
|
|
3847
3885
|
const { success, issues, output } = v.safeParse(XMLData, data);
|
|
3848
3886
|
if (!success) {
|
|
3849
3887
|
logIssues(issues);
|
|
3850
|
-
throw
|
|
3888
|
+
throw createSchemaValidationError("Failed to parse OCHRE data", issues);
|
|
3851
3889
|
}
|
|
3852
3890
|
restoreXMLMetadata(output, data);
|
|
3853
3891
|
const category = options?.category ?? inferFetchItemCategory(output.result.ochre);
|
|
@@ -4921,7 +4959,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
4921
4959
|
const { success, issues, output } = v.safeParse(XMLSetItemsData, data);
|
|
4922
4960
|
if (!success) {
|
|
4923
4961
|
logIssues(issues);
|
|
4924
|
-
throw
|
|
4962
|
+
throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
|
|
4925
4963
|
}
|
|
4926
4964
|
restoreXMLMetadata(output, data);
|
|
4927
4965
|
if (containedItemCategories != null) {
|
|
@@ -5398,7 +5436,7 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5398
5436
|
const { success, issues, output } = v.safeParse(responseSchema, data);
|
|
5399
5437
|
if (!success) {
|
|
5400
5438
|
logIssues(issues);
|
|
5401
|
-
throw
|
|
5439
|
+
throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
|
|
5402
5440
|
}
|
|
5403
5441
|
const parsedPropertyValues = [];
|
|
5404
5442
|
const parsedAttributeValues = [];
|
|
@@ -7126,7 +7164,7 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
7126
7164
|
const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
|
|
7127
7165
|
if (!success) {
|
|
7128
7166
|
logIssues(issues);
|
|
7129
|
-
throw
|
|
7167
|
+
throw createSchemaValidationError("Failed to parse website XML", issues);
|
|
7130
7168
|
}
|
|
7131
7169
|
restoreXMLMetadata(output, data);
|
|
7132
7170
|
return {
|