ochre-sdk 1.0.7 → 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.d.mts +16 -0
- package/dist/index.mjs +149 -102
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1044,9 +1044,11 @@ declare function fetchGallery<const TLanguages extends ReadonlyArray<string> | u
|
|
|
1044
1044
|
}, options?: FetchGalleryBaseOptions<TLanguages>): Promise<{
|
|
1045
1045
|
gallery: Gallery<FetchGalleryLanguages<TLanguages>>;
|
|
1046
1046
|
error: null;
|
|
1047
|
+
detailedError: null;
|
|
1047
1048
|
} | {
|
|
1048
1049
|
gallery: null;
|
|
1049
1050
|
error: string;
|
|
1051
|
+
detailedError: string;
|
|
1050
1052
|
}>;
|
|
1051
1053
|
//#endregion
|
|
1052
1054
|
//#region src/fetchers/item-links.d.ts
|
|
@@ -1071,9 +1073,11 @@ declare function fetchItemLinks<const TContainedItemCategory extends ContainedIt
|
|
|
1071
1073
|
}): Promise<{
|
|
1072
1074
|
items: Array<Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchItemLinksLanguages<TLanguages>, "embedded">>;
|
|
1073
1075
|
error: null;
|
|
1076
|
+
detailedError: null;
|
|
1074
1077
|
} | {
|
|
1075
1078
|
items: null;
|
|
1076
1079
|
error: string;
|
|
1080
|
+
detailedError: string;
|
|
1077
1081
|
}>;
|
|
1078
1082
|
//#endregion
|
|
1079
1083
|
//#region src/fetchers/item.d.ts
|
|
@@ -1115,9 +1119,11 @@ declare function fetchItem<const TContainedItemCategory extends ContainedItemCat
|
|
|
1115
1119
|
}): Promise<{
|
|
1116
1120
|
item: Item<ItemCategory, ContainedItemCategoryFromOption<ItemCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>;
|
|
1117
1121
|
error: null;
|
|
1122
|
+
detailedError: null;
|
|
1118
1123
|
} | {
|
|
1119
1124
|
item: null;
|
|
1120
1125
|
error: string;
|
|
1126
|
+
detailedError: string;
|
|
1121
1127
|
}>;
|
|
1122
1128
|
declare function fetchItem<const TCategory extends ItemContainerCategory, const TContainedItemCategory extends ContainedItemCategoryOption<TCategory> | undefined = undefined, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
|
|
1123
1129
|
category: TCategory;
|
|
@@ -1125,9 +1131,11 @@ declare function fetchItem<const TCategory extends ItemContainerCategory, const
|
|
|
1125
1131
|
}): Promise<{
|
|
1126
1132
|
item: Item<TCategory, ContainedItemCategoryFromOption<TCategory, TContainedItemCategory>, FetchItemLanguages<TLanguages>>;
|
|
1127
1133
|
error: null;
|
|
1134
|
+
detailedError: null;
|
|
1128
1135
|
} | {
|
|
1129
1136
|
item: null;
|
|
1130
1137
|
error: string;
|
|
1138
|
+
detailedError: string;
|
|
1131
1139
|
}>;
|
|
1132
1140
|
declare function fetchItem<const TCategory extends ItemCategory, const TLanguages extends ReadonlyArray<string> | undefined = undefined>(uuid: string, options: FetchItemBaseOptions<TLanguages> & {
|
|
1133
1141
|
category: TCategory;
|
|
@@ -1135,9 +1143,11 @@ declare function fetchItem<const TCategory extends ItemCategory, const TLanguage
|
|
|
1135
1143
|
}): Promise<{
|
|
1136
1144
|
item: Item<TCategory, ContainedItemCategory<TCategory>, FetchItemLanguages<TLanguages>>;
|
|
1137
1145
|
error: null;
|
|
1146
|
+
detailedError: null;
|
|
1138
1147
|
} | {
|
|
1139
1148
|
item: null;
|
|
1140
1149
|
error: string;
|
|
1150
|
+
detailedError: string;
|
|
1141
1151
|
}>;
|
|
1142
1152
|
//#endregion
|
|
1143
1153
|
//#region src/fetchers/set/items.d.ts
|
|
@@ -1175,12 +1185,14 @@ declare function fetchSetItems<const TContainedItemCategories extends ReadonlyAr
|
|
|
1175
1185
|
pageSize: number;
|
|
1176
1186
|
items: Array<SetItem<FetchSetItemsCategory<TContainedItemCategories>, FetchSetItemsLanguages<TLanguages>>>;
|
|
1177
1187
|
error: null;
|
|
1188
|
+
detailedError: null;
|
|
1178
1189
|
} | {
|
|
1179
1190
|
totalCount: null;
|
|
1180
1191
|
page: null;
|
|
1181
1192
|
pageSize: null;
|
|
1182
1193
|
items: null;
|
|
1183
1194
|
error: string;
|
|
1195
|
+
detailedError: string;
|
|
1184
1196
|
}>;
|
|
1185
1197
|
//#endregion
|
|
1186
1198
|
//#region src/fetchers/set/property-values.d.ts
|
|
@@ -1217,11 +1229,13 @@ declare function fetchSetPropertyValues(params: {
|
|
|
1217
1229
|
periods: Array<SetAttributeValueQueryItem> | null;
|
|
1218
1230
|
};
|
|
1219
1231
|
error: null;
|
|
1232
|
+
detailedError: null;
|
|
1220
1233
|
} | {
|
|
1221
1234
|
propertyValues: null;
|
|
1222
1235
|
propertyValuesByPropertyVariableUuid: null;
|
|
1223
1236
|
attributeValues: null;
|
|
1224
1237
|
error: string;
|
|
1238
|
+
detailedError: string;
|
|
1225
1239
|
}>;
|
|
1226
1240
|
//#endregion
|
|
1227
1241
|
//#region src/types/website.d.ts
|
|
@@ -1734,9 +1748,11 @@ declare function fetchWebsite<const T extends LanguageCodes = LanguageCodes>(abb
|
|
|
1734
1748
|
}): Promise<{
|
|
1735
1749
|
website: Website<T>;
|
|
1736
1750
|
error: null;
|
|
1751
|
+
detailedError: null;
|
|
1737
1752
|
} | {
|
|
1738
1753
|
website: null;
|
|
1739
1754
|
error: string;
|
|
1755
|
+
detailedError: string;
|
|
1740
1756
|
}>;
|
|
1741
1757
|
//#endregion
|
|
1742
1758
|
//#region src/getters.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -487,72 +487,139 @@ var MultilingualString = class MultilingualString {
|
|
|
487
487
|
};
|
|
488
488
|
//#endregion
|
|
489
489
|
//#region src/utils.ts
|
|
490
|
-
const MAX_SCHEMA_VALIDATION_ISSUES = 3;
|
|
491
490
|
const PSEUDO_UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;
|
|
492
|
-
function
|
|
493
|
-
|
|
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;
|
|
491
|
+
function isRecord$5(value) {
|
|
492
|
+
return typeof value === "object" && value != null;
|
|
501
493
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
return
|
|
494
|
+
function isSchemaValidationIssue(value) {
|
|
495
|
+
if (!isRecord$5(value)) return false;
|
|
496
|
+
return typeof value.kind === "string" && typeof value.type === "string" && typeof value.message === "string";
|
|
505
497
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
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("; ")}`;
|
|
498
|
+
function isSchemaValidationIssues(value) {
|
|
499
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
500
|
+
for (const item of value) if (!isSchemaValidationIssue(item)) return false;
|
|
501
|
+
return true;
|
|
519
502
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
503
|
+
function getIssuePath(issue) {
|
|
504
|
+
const path = v.getDotPath(issue);
|
|
505
|
+
return path != null && path.length > 0 ? path : "(root)";
|
|
506
|
+
}
|
|
507
|
+
function formatPrimitiveValue(value) {
|
|
508
|
+
if (value == null) return String(value);
|
|
509
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
510
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || typeof value === "symbol") return String(value);
|
|
511
|
+
if (value instanceof Date) return value.toISOString();
|
|
512
|
+
if (value instanceof RegExp) return String(value);
|
|
513
|
+
return null;
|
|
528
514
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
* @param issues - The validation issues to log
|
|
532
|
-
* @param depth - The depth of the issues for indentation
|
|
533
|
-
* @internal
|
|
534
|
-
*/
|
|
535
|
-
function logIssues(issues, depth = 0) {
|
|
536
|
-
if (issues == null) return;
|
|
515
|
+
function appendSchemaValidationIssues(lines, issues, depth = 0, prefix = "") {
|
|
516
|
+
let index = 0;
|
|
537
517
|
for (const issue of issues) {
|
|
518
|
+
index += 1;
|
|
519
|
+
const number = prefix.length > 0 ? `${prefix}.${index}` : String(index);
|
|
538
520
|
const indent = " ".repeat(depth);
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
if (issue.input !== void 0 && typeof issue.input !== "object") console.error(`${indent} Input: ${JSON.stringify(issue.input)}`);
|
|
548
|
-
if (issue.requirement !== void 0) console.error(`${indent} Requirement: ${JSON.stringify(issue.requirement)}`);
|
|
521
|
+
lines.push(`${indent}${number}. ${getIssuePath(issue)}`, `${indent} Message: ${issue.message}`, `${indent} Type: ${issue.kind}:${issue.type}`);
|
|
522
|
+
if (issue.expected != null) lines.push(`${indent} Expected: ${issue.expected}`);
|
|
523
|
+
if (issue.received.length > 0) lines.push(`${indent} Received: ${issue.received}`);
|
|
524
|
+
const input = formatPrimitiveValue(issue.input);
|
|
525
|
+
if (input != null) lines.push(`${indent} Input: ${input}`);
|
|
526
|
+
const requirement = formatPrimitiveValue(issue.requirement);
|
|
527
|
+
if (requirement != null) lines.push(`${indent} Requirement: ${requirement}`);
|
|
549
528
|
if (issue.issues != null && issue.issues.length > 0) {
|
|
550
|
-
|
|
551
|
-
|
|
529
|
+
lines.push(`${indent} Nested issues:`);
|
|
530
|
+
appendSchemaValidationIssues(lines, issue.issues, depth + 1, number);
|
|
552
531
|
}
|
|
553
|
-
if (depth === 0) console.error("");
|
|
554
532
|
}
|
|
555
533
|
}
|
|
534
|
+
function formatCauseValue(value) {
|
|
535
|
+
if (typeof value === "string") return value.length > 0 ? value : null;
|
|
536
|
+
const primitiveValue = formatPrimitiveValue(value);
|
|
537
|
+
if (primitiveValue != null) return primitiveValue;
|
|
538
|
+
if (Array.isArray(value)) {
|
|
539
|
+
const values = [];
|
|
540
|
+
for (const item of value) {
|
|
541
|
+
const formattedItem = typeof item === "string" && item.length > 0 ? item : formatPrimitiveValue(item);
|
|
542
|
+
if (formattedItem != null && formattedItem.length > 0) values.push(formattedItem);
|
|
543
|
+
}
|
|
544
|
+
return values.length > 0 ? values.join(", ") : null;
|
|
545
|
+
}
|
|
546
|
+
if (isRecord$5(value)) {
|
|
547
|
+
const values = [];
|
|
548
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
549
|
+
const formattedEntryValue = formatPrimitiveValue(entryValue);
|
|
550
|
+
if (formattedEntryValue != null) values.push(`${key}: ${formattedEntryValue}`);
|
|
551
|
+
}
|
|
552
|
+
return values.length > 0 ? values.join("; ") : null;
|
|
553
|
+
}
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
function appendDetailedError(lines, error, fallbackMessage, depth, seenErrors) {
|
|
557
|
+
const indent = " ".repeat(depth);
|
|
558
|
+
if (error instanceof Error) {
|
|
559
|
+
if (seenErrors.has(error)) {
|
|
560
|
+
lines.push(`${indent}Error: [Circular cause]`);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
seenErrors.add(error);
|
|
564
|
+
lines.push(`${indent}Error`);
|
|
565
|
+
if (error.name !== "Error") lines.push(`${indent}Name: ${error.name}`);
|
|
566
|
+
lines.push(`${indent}Message: ${error.message}`);
|
|
567
|
+
if (error instanceof AggregateError && error.errors.length > 0) {
|
|
568
|
+
lines.push("", `${indent}Contained errors`);
|
|
569
|
+
let index = 0;
|
|
570
|
+
for (const containedError of error.errors) {
|
|
571
|
+
index += 1;
|
|
572
|
+
lines.push(`${indent}${index}.`);
|
|
573
|
+
appendDetailedError(lines, containedError, "Unknown error", depth + 1, seenErrors);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (error.cause != null) {
|
|
577
|
+
const causeLines = [];
|
|
578
|
+
if (appendDetailedCause(causeLines, error.cause, depth, seenErrors)) lines.push("", ...causeLines);
|
|
579
|
+
}
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
lines.push(`${indent}Error`, `${indent}Message: ${fallbackMessage}`);
|
|
583
|
+
const value = formatCauseValue(error);
|
|
584
|
+
if (value != null) lines.push(`${indent}Value: ${value}`);
|
|
585
|
+
}
|
|
586
|
+
function appendDetailedCause(lines, cause, depth, seenErrors) {
|
|
587
|
+
const indent = " ".repeat(depth);
|
|
588
|
+
if (isSchemaValidationIssues(cause)) {
|
|
589
|
+
lines.push(`${indent}Schema validation`);
|
|
590
|
+
appendSchemaValidationIssues(lines, cause, depth);
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
if (cause instanceof Error) {
|
|
594
|
+
lines.push(`${indent}Cause`);
|
|
595
|
+
appendDetailedError(lines, cause, cause.message, depth + 1, seenErrors);
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
const formattedCause = formatCauseValue(cause);
|
|
599
|
+
if (formattedCause != null) {
|
|
600
|
+
lines.push(`${indent}Cause`, `${indent}${formattedCause}`);
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
return false;
|
|
604
|
+
}
|
|
605
|
+
function getErrorMessage(error, fallbackMessage) {
|
|
606
|
+
return error instanceof Error ? error.message : fallbackMessage;
|
|
607
|
+
}
|
|
608
|
+
function getDetailedError(error, fallbackMessage = "Unknown error") {
|
|
609
|
+
const lines = [];
|
|
610
|
+
appendDetailedError(lines, error, fallbackMessage, 0, /* @__PURE__ */ new Set());
|
|
611
|
+
return lines.join("\n");
|
|
612
|
+
}
|
|
613
|
+
function getErrorOutput(error, fallbackMessage) {
|
|
614
|
+
const message = getErrorMessage(error, fallbackMessage);
|
|
615
|
+
return {
|
|
616
|
+
error: message,
|
|
617
|
+
detailedError: getDetailedError(error, message)
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function createSchemaValidationError(message, issues) {
|
|
621
|
+
return new Error(message, { cause: issues });
|
|
622
|
+
}
|
|
556
623
|
/**
|
|
557
624
|
* Validates a pseudo-UUID string
|
|
558
625
|
* @param value - The string to validate
|
|
@@ -3672,20 +3739,17 @@ async function fetchGallery(params, options) {
|
|
|
3672
3739
|
const dataRaw = await response.text();
|
|
3673
3740
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3674
3741
|
const { success, issues, output } = v.safeParse(XMLGalleryData, data);
|
|
3675
|
-
if (!success)
|
|
3676
|
-
logIssues(issues);
|
|
3677
|
-
throw createSchemaValidationError("Failed to parse gallery XML", issues);
|
|
3678
|
-
}
|
|
3742
|
+
if (!success) throw createSchemaValidationError("Failed to parse gallery XML", issues);
|
|
3679
3743
|
restoreXMLMetadata(output, data);
|
|
3680
3744
|
return {
|
|
3681
3745
|
gallery: parseGallery(output, { languages: resolveGalleryLanguages(output, requestedLanguages) }),
|
|
3682
|
-
error: null
|
|
3746
|
+
error: null,
|
|
3747
|
+
detailedError: null
|
|
3683
3748
|
};
|
|
3684
3749
|
} catch (error) {
|
|
3685
|
-
console.error(error);
|
|
3686
3750
|
return {
|
|
3687
3751
|
gallery: null,
|
|
3688
|
-
error
|
|
3752
|
+
...getErrorOutput(error, "Failed to fetch gallery")
|
|
3689
3753
|
};
|
|
3690
3754
|
}
|
|
3691
3755
|
}
|
|
@@ -3782,10 +3846,7 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3782
3846
|
const dataRaw = await response.text();
|
|
3783
3847
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3784
3848
|
const { success, issues, output } = v.safeParse(XMLItemLinksData, data);
|
|
3785
|
-
if (!success)
|
|
3786
|
-
logIssues(issues);
|
|
3787
|
-
throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
|
|
3788
|
-
}
|
|
3849
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
|
|
3789
3850
|
restoreXMLMetadata(output, data);
|
|
3790
3851
|
const languages = resolveItemLinksLanguages(output, requestedLanguages);
|
|
3791
3852
|
return {
|
|
@@ -3793,13 +3854,13 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3793
3854
|
containedItemCategory: options?.containedItemCategory,
|
|
3794
3855
|
languages
|
|
3795
3856
|
}),
|
|
3796
|
-
error: null
|
|
3857
|
+
error: null,
|
|
3858
|
+
detailedError: null
|
|
3797
3859
|
};
|
|
3798
3860
|
} catch (error) {
|
|
3799
|
-
console.error(error);
|
|
3800
3861
|
return {
|
|
3801
3862
|
items: null,
|
|
3802
|
-
error
|
|
3863
|
+
...getErrorOutput(error, "Unknown error")
|
|
3803
3864
|
};
|
|
3804
3865
|
}
|
|
3805
3866
|
}
|
|
@@ -3883,10 +3944,7 @@ async function fetchItem(uuid, options) {
|
|
|
3883
3944
|
const dataRaw = await response.text();
|
|
3884
3945
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
3885
3946
|
const { success, issues, output } = v.safeParse(XMLData, data);
|
|
3886
|
-
if (!success)
|
|
3887
|
-
logIssues(issues);
|
|
3888
|
-
throw createSchemaValidationError("Failed to parse OCHRE data", issues);
|
|
3889
|
-
}
|
|
3947
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE data", issues);
|
|
3890
3948
|
restoreXMLMetadata(output, data);
|
|
3891
3949
|
const category = options?.category ?? inferFetchItemCategory(output.result.ochre);
|
|
3892
3950
|
assertItemCategoryAllowed(category, options?.containedItemCategory);
|
|
@@ -3896,13 +3954,13 @@ async function fetchItem(uuid, options) {
|
|
|
3896
3954
|
containedItemCategory: options?.containedItemCategory,
|
|
3897
3955
|
languages
|
|
3898
3956
|
}),
|
|
3899
|
-
error: null
|
|
3957
|
+
error: null,
|
|
3958
|
+
detailedError: null
|
|
3900
3959
|
};
|
|
3901
3960
|
} catch (error) {
|
|
3902
|
-
console.error(error);
|
|
3903
3961
|
return {
|
|
3904
3962
|
item: null,
|
|
3905
|
-
error
|
|
3963
|
+
...getErrorOutput(error, "Unknown error")
|
|
3906
3964
|
};
|
|
3907
3965
|
}
|
|
3908
3966
|
}
|
|
@@ -4957,10 +5015,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
4957
5015
|
const dataRaw = await response.text();
|
|
4958
5016
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
4959
5017
|
const { success, issues, output } = v.safeParse(XMLSetItemsData, data);
|
|
4960
|
-
if (!success)
|
|
4961
|
-
logIssues(issues);
|
|
4962
|
-
throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
|
|
4963
|
-
}
|
|
5018
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
|
|
4964
5019
|
restoreXMLMetadata(output, data);
|
|
4965
5020
|
if (containedItemCategories != null) {
|
|
4966
5021
|
const missingCategories = containedItemCategories.filter((category) => !hasSetItemsCategory(output.result.ochre.items, category));
|
|
@@ -4979,16 +5034,16 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
4979
5034
|
page: output.result.ochre.items.page,
|
|
4980
5035
|
pageSize: output.result.ochre.items.pageSize,
|
|
4981
5036
|
items: uniqueItems,
|
|
4982
|
-
error: null
|
|
5037
|
+
error: null,
|
|
5038
|
+
detailedError: null
|
|
4983
5039
|
};
|
|
4984
5040
|
} catch (error) {
|
|
4985
|
-
console.error(error);
|
|
4986
5041
|
return {
|
|
4987
5042
|
totalCount: null,
|
|
4988
5043
|
page: null,
|
|
4989
5044
|
pageSize: null,
|
|
4990
5045
|
items: null,
|
|
4991
|
-
error
|
|
5046
|
+
...getErrorOutput(error, "Failed to fetch Set items")
|
|
4992
5047
|
};
|
|
4993
5048
|
}
|
|
4994
5049
|
}
|
|
@@ -5415,7 +5470,8 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5415
5470
|
bibliographies: null,
|
|
5416
5471
|
periods: null
|
|
5417
5472
|
},
|
|
5418
|
-
error: null
|
|
5473
|
+
error: null,
|
|
5474
|
+
detailedError: null
|
|
5419
5475
|
};
|
|
5420
5476
|
const xquery = buildXQuery({
|
|
5421
5477
|
setScopeUuids,
|
|
@@ -5434,10 +5490,7 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5434
5490
|
const dataRaw = await response.text();
|
|
5435
5491
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
5436
5492
|
const { success, issues, output } = v.safeParse(responseSchema, data);
|
|
5437
|
-
if (!success)
|
|
5438
|
-
logIssues(issues);
|
|
5439
|
-
throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
|
|
5440
|
-
}
|
|
5493
|
+
if (!success) throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
|
|
5441
5494
|
const parsedPropertyValues = [];
|
|
5442
5495
|
const parsedAttributeValues = [];
|
|
5443
5496
|
if (output.result.ochre.propertyValue != null) parsedPropertyValues.push(...Array.isArray(output.result.ochre.propertyValue) ? output.result.ochre.propertyValue : [output.result.ochre.propertyValue]);
|
|
@@ -5487,15 +5540,15 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5487
5540
|
bibliographies: attributes.bibliographies ? sortAttributeValues(attributeValuesByType.bibliographies) : null,
|
|
5488
5541
|
periods: attributes.periods ? sortAttributeValues(attributeValuesByType.periods) : null
|
|
5489
5542
|
},
|
|
5490
|
-
error: null
|
|
5543
|
+
error: null,
|
|
5544
|
+
detailedError: null
|
|
5491
5545
|
};
|
|
5492
5546
|
} catch (error) {
|
|
5493
|
-
console.error(error);
|
|
5494
5547
|
return {
|
|
5495
5548
|
propertyValues: null,
|
|
5496
5549
|
propertyValuesByPropertyVariableUuid: null,
|
|
5497
5550
|
attributeValues: null,
|
|
5498
|
-
error
|
|
5551
|
+
...getErrorOutput(error, "Failed to fetch property values")
|
|
5499
5552
|
};
|
|
5500
5553
|
}
|
|
5501
5554
|
}
|
|
@@ -6577,11 +6630,8 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
6577
6630
|
};
|
|
6578
6631
|
break;
|
|
6579
6632
|
}
|
|
6580
|
-
default:
|
|
6581
|
-
console.warn(`Invalid or non-implemented component name “${unparsedComponentName.toString()}” for the following element: “${parseStringContent(elementResource.identification.label, options)}”`);
|
|
6582
|
-
break;
|
|
6633
|
+
default: throw new Error(`Invalid or non-implemented component name “${unparsedComponentName.toString()}” for the following element: “${parseStringContent(elementResource.identification.label, options)}”`);
|
|
6583
6634
|
}
|
|
6584
|
-
if (properties === null) throw new Error(formatComponentError("Properties not found", componentName, elementResource), { cause: componentProperty });
|
|
6585
6635
|
return properties;
|
|
6586
6636
|
}
|
|
6587
6637
|
function parseWebTitle(properties, identification, overrides) {
|
|
@@ -7162,20 +7212,17 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
7162
7212
|
const dataRaw = await response.text();
|
|
7163
7213
|
const data = new XMLParser(XML_PARSER_OPTIONS).parse(dataRaw);
|
|
7164
7214
|
const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
|
|
7165
|
-
if (!success)
|
|
7166
|
-
logIssues(issues);
|
|
7167
|
-
throw createSchemaValidationError("Failed to parse website XML", issues);
|
|
7168
|
-
}
|
|
7215
|
+
if (!success) throw createSchemaValidationError("Failed to parse website XML", issues);
|
|
7169
7216
|
restoreXMLMetadata(output, data);
|
|
7170
7217
|
return {
|
|
7171
7218
|
website: parseWebsite(output, { languages: options?.languages }),
|
|
7172
|
-
error: null
|
|
7219
|
+
error: null,
|
|
7220
|
+
detailedError: null
|
|
7173
7221
|
};
|
|
7174
7222
|
} catch (error) {
|
|
7175
|
-
console.error(error);
|
|
7176
7223
|
return {
|
|
7177
7224
|
website: null,
|
|
7178
|
-
error
|
|
7225
|
+
...getErrorOutput(error, "Unknown error")
|
|
7179
7226
|
};
|
|
7180
7227
|
}
|
|
7181
7228
|
}
|
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",
|