ochre-sdk 1.0.7 → 1.0.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.d.mts +16 -0
- package/dist/index.mjs +143 -42
- package/package.json +1 -1
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,44 +487,138 @@ 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
|
|
491
|
+
function isRecord$5(value) {
|
|
492
|
+
return typeof value === "object" && value != null;
|
|
493
|
+
}
|
|
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";
|
|
497
|
+
}
|
|
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;
|
|
502
|
+
}
|
|
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;
|
|
514
|
+
}
|
|
515
|
+
function appendSchemaValidationIssues(lines, issues, depth = 0, prefix = "") {
|
|
516
|
+
let index = 0;
|
|
493
517
|
for (const issue of issues) {
|
|
518
|
+
index += 1;
|
|
519
|
+
const number = prefix.length > 0 ? `${prefix}.${index}` : String(index);
|
|
520
|
+
const indent = " ".repeat(depth);
|
|
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}`);
|
|
494
528
|
if (issue.issues != null && issue.issues.length > 0) {
|
|
495
|
-
|
|
496
|
-
|
|
529
|
+
lines.push(`${indent} Nested issues:`);
|
|
530
|
+
appendSchemaValidationIssues(lines, issue.issues, depth + 1, number);
|
|
497
531
|
}
|
|
498
|
-
leaves.push(issue);
|
|
499
532
|
}
|
|
500
|
-
return leaves;
|
|
501
533
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
|
|
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;
|
|
505
555
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
+
};
|
|
519
619
|
}
|
|
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
620
|
function createSchemaValidationError(message, issues) {
|
|
527
|
-
return new Error(
|
|
621
|
+
return new Error(message, { cause: issues });
|
|
528
622
|
}
|
|
529
623
|
/**
|
|
530
624
|
* Logs Valibot validation issues to the console with detailed formatting
|
|
@@ -3679,13 +3773,14 @@ async function fetchGallery(params, options) {
|
|
|
3679
3773
|
restoreXMLMetadata(output, data);
|
|
3680
3774
|
return {
|
|
3681
3775
|
gallery: parseGallery(output, { languages: resolveGalleryLanguages(output, requestedLanguages) }),
|
|
3682
|
-
error: null
|
|
3776
|
+
error: null,
|
|
3777
|
+
detailedError: null
|
|
3683
3778
|
};
|
|
3684
3779
|
} catch (error) {
|
|
3685
3780
|
console.error(error);
|
|
3686
3781
|
return {
|
|
3687
3782
|
gallery: null,
|
|
3688
|
-
error
|
|
3783
|
+
...getErrorOutput(error, "Failed to fetch gallery")
|
|
3689
3784
|
};
|
|
3690
3785
|
}
|
|
3691
3786
|
}
|
|
@@ -3793,13 +3888,14 @@ async function fetchItemLinks(uuid, options) {
|
|
|
3793
3888
|
containedItemCategory: options?.containedItemCategory,
|
|
3794
3889
|
languages
|
|
3795
3890
|
}),
|
|
3796
|
-
error: null
|
|
3891
|
+
error: null,
|
|
3892
|
+
detailedError: null
|
|
3797
3893
|
};
|
|
3798
3894
|
} catch (error) {
|
|
3799
3895
|
console.error(error);
|
|
3800
3896
|
return {
|
|
3801
3897
|
items: null,
|
|
3802
|
-
error
|
|
3898
|
+
...getErrorOutput(error, "Unknown error")
|
|
3803
3899
|
};
|
|
3804
3900
|
}
|
|
3805
3901
|
}
|
|
@@ -3896,13 +3992,14 @@ async function fetchItem(uuid, options) {
|
|
|
3896
3992
|
containedItemCategory: options?.containedItemCategory,
|
|
3897
3993
|
languages
|
|
3898
3994
|
}),
|
|
3899
|
-
error: null
|
|
3995
|
+
error: null,
|
|
3996
|
+
detailedError: null
|
|
3900
3997
|
};
|
|
3901
3998
|
} catch (error) {
|
|
3902
3999
|
console.error(error);
|
|
3903
4000
|
return {
|
|
3904
4001
|
item: null,
|
|
3905
|
-
error
|
|
4002
|
+
...getErrorOutput(error, "Unknown error")
|
|
3906
4003
|
};
|
|
3907
4004
|
}
|
|
3908
4005
|
}
|
|
@@ -4979,7 +5076,8 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
4979
5076
|
page: output.result.ochre.items.page,
|
|
4980
5077
|
pageSize: output.result.ochre.items.pageSize,
|
|
4981
5078
|
items: uniqueItems,
|
|
4982
|
-
error: null
|
|
5079
|
+
error: null,
|
|
5080
|
+
detailedError: null
|
|
4983
5081
|
};
|
|
4984
5082
|
} catch (error) {
|
|
4985
5083
|
console.error(error);
|
|
@@ -4988,7 +5086,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
|
|
|
4988
5086
|
page: null,
|
|
4989
5087
|
pageSize: null,
|
|
4990
5088
|
items: null,
|
|
4991
|
-
error
|
|
5089
|
+
...getErrorOutput(error, "Failed to fetch Set items")
|
|
4992
5090
|
};
|
|
4993
5091
|
}
|
|
4994
5092
|
}
|
|
@@ -5415,7 +5513,8 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5415
5513
|
bibliographies: null,
|
|
5416
5514
|
periods: null
|
|
5417
5515
|
},
|
|
5418
|
-
error: null
|
|
5516
|
+
error: null,
|
|
5517
|
+
detailedError: null
|
|
5419
5518
|
};
|
|
5420
5519
|
const xquery = buildXQuery({
|
|
5421
5520
|
setScopeUuids,
|
|
@@ -5487,7 +5586,8 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5487
5586
|
bibliographies: attributes.bibliographies ? sortAttributeValues(attributeValuesByType.bibliographies) : null,
|
|
5488
5587
|
periods: attributes.periods ? sortAttributeValues(attributeValuesByType.periods) : null
|
|
5489
5588
|
},
|
|
5490
|
-
error: null
|
|
5589
|
+
error: null,
|
|
5590
|
+
detailedError: null
|
|
5491
5591
|
};
|
|
5492
5592
|
} catch (error) {
|
|
5493
5593
|
console.error(error);
|
|
@@ -5495,7 +5595,7 @@ async function fetchSetPropertyValues(params, options) {
|
|
|
5495
5595
|
propertyValues: null,
|
|
5496
5596
|
propertyValuesByPropertyVariableUuid: null,
|
|
5497
5597
|
attributeValues: null,
|
|
5498
|
-
error
|
|
5598
|
+
...getErrorOutput(error, "Failed to fetch property values")
|
|
5499
5599
|
};
|
|
5500
5600
|
}
|
|
5501
5601
|
}
|
|
@@ -7169,13 +7269,14 @@ async function fetchWebsite(abbreviation, options) {
|
|
|
7169
7269
|
restoreXMLMetadata(output, data);
|
|
7170
7270
|
return {
|
|
7171
7271
|
website: parseWebsite(output, { languages: options?.languages }),
|
|
7172
|
-
error: null
|
|
7272
|
+
error: null,
|
|
7273
|
+
detailedError: null
|
|
7173
7274
|
};
|
|
7174
7275
|
} catch (error) {
|
|
7175
7276
|
console.error(error);
|
|
7176
7277
|
return {
|
|
7177
7278
|
website: null,
|
|
7178
|
-
error
|
|
7279
|
+
...getErrorOutput(error, "Unknown error")
|
|
7179
7280
|
};
|
|
7180
7281
|
}
|
|
7181
7282
|
}
|