ochre-sdk 1.0.6 → 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 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
@@ -488,6 +488,138 @@ var MultilingualString = class MultilingualString {
488
488
  //#endregion
489
489
  //#region src/utils.ts
490
490
  const PSEUDO_UUID_REGEX = /^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/i;
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;
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}`);
528
+ if (issue.issues != null && issue.issues.length > 0) {
529
+ lines.push(`${indent} Nested issues:`);
530
+ appendSchemaValidationIssues(lines, issue.issues, depth + 1, number);
531
+ }
532
+ }
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
+ }
491
623
  /**
492
624
  * Logs Valibot validation issues to the console with detailed formatting
493
625
  * @param issues - The validation issues to log
@@ -3636,18 +3768,19 @@ async function fetchGallery(params, options) {
3636
3768
  const { success, issues, output } = v.safeParse(XMLGalleryData, data);
3637
3769
  if (!success) {
3638
3770
  logIssues(issues);
3639
- throw new Error("Failed to parse gallery XML", { cause: issues });
3771
+ throw createSchemaValidationError("Failed to parse gallery XML", issues);
3640
3772
  }
3641
3773
  restoreXMLMetadata(output, data);
3642
3774
  return {
3643
3775
  gallery: parseGallery(output, { languages: resolveGalleryLanguages(output, requestedLanguages) }),
3644
- error: null
3776
+ error: null,
3777
+ detailedError: null
3645
3778
  };
3646
3779
  } catch (error) {
3647
3780
  console.error(error);
3648
3781
  return {
3649
3782
  gallery: null,
3650
- error: error instanceof Error ? error.message : "Failed to fetch gallery"
3783
+ ...getErrorOutput(error, "Failed to fetch gallery")
3651
3784
  };
3652
3785
  }
3653
3786
  }
@@ -3746,7 +3879,7 @@ async function fetchItemLinks(uuid, options) {
3746
3879
  const { success, issues, output } = v.safeParse(XMLItemLinksData, data);
3747
3880
  if (!success) {
3748
3881
  logIssues(issues);
3749
- throw new Error("Failed to parse OCHRE item links", { cause: issues });
3882
+ throw createSchemaValidationError("Failed to parse OCHRE item links", issues);
3750
3883
  }
3751
3884
  restoreXMLMetadata(output, data);
3752
3885
  const languages = resolveItemLinksLanguages(output, requestedLanguages);
@@ -3755,13 +3888,14 @@ async function fetchItemLinks(uuid, options) {
3755
3888
  containedItemCategory: options?.containedItemCategory,
3756
3889
  languages
3757
3890
  }),
3758
- error: null
3891
+ error: null,
3892
+ detailedError: null
3759
3893
  };
3760
3894
  } catch (error) {
3761
3895
  console.error(error);
3762
3896
  return {
3763
3897
  items: null,
3764
- error: error instanceof Error ? error.message : "Unknown error"
3898
+ ...getErrorOutput(error, "Unknown error")
3765
3899
  };
3766
3900
  }
3767
3901
  }
@@ -3847,7 +3981,7 @@ async function fetchItem(uuid, options) {
3847
3981
  const { success, issues, output } = v.safeParse(XMLData, data);
3848
3982
  if (!success) {
3849
3983
  logIssues(issues);
3850
- throw new Error("Failed to parse OCHRE data", { cause: issues });
3984
+ throw createSchemaValidationError("Failed to parse OCHRE data", issues);
3851
3985
  }
3852
3986
  restoreXMLMetadata(output, data);
3853
3987
  const category = options?.category ?? inferFetchItemCategory(output.result.ochre);
@@ -3858,13 +3992,14 @@ async function fetchItem(uuid, options) {
3858
3992
  containedItemCategory: options?.containedItemCategory,
3859
3993
  languages
3860
3994
  }),
3861
- error: null
3995
+ error: null,
3996
+ detailedError: null
3862
3997
  };
3863
3998
  } catch (error) {
3864
3999
  console.error(error);
3865
4000
  return {
3866
4001
  item: null,
3867
- error: error instanceof Error ? error.message : "Unknown error"
4002
+ ...getErrorOutput(error, "Unknown error")
3868
4003
  };
3869
4004
  }
3870
4005
  }
@@ -4921,7 +5056,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
4921
5056
  const { success, issues, output } = v.safeParse(XMLSetItemsData, data);
4922
5057
  if (!success) {
4923
5058
  logIssues(issues);
4924
- throw new Error("Failed to parse OCHRE Set items", { cause: issues });
5059
+ throw createSchemaValidationError("Failed to parse OCHRE Set items", issues);
4925
5060
  }
4926
5061
  restoreXMLMetadata(output, data);
4927
5062
  if (containedItemCategories != null) {
@@ -4941,7 +5076,8 @@ async function fetchSetItems(params, containedItemCategories, options) {
4941
5076
  page: output.result.ochre.items.page,
4942
5077
  pageSize: output.result.ochre.items.pageSize,
4943
5078
  items: uniqueItems,
4944
- error: null
5079
+ error: null,
5080
+ detailedError: null
4945
5081
  };
4946
5082
  } catch (error) {
4947
5083
  console.error(error);
@@ -4950,7 +5086,7 @@ async function fetchSetItems(params, containedItemCategories, options) {
4950
5086
  page: null,
4951
5087
  pageSize: null,
4952
5088
  items: null,
4953
- error: error instanceof Error ? error.message : "Failed to fetch Set items"
5089
+ ...getErrorOutput(error, "Failed to fetch Set items")
4954
5090
  };
4955
5091
  }
4956
5092
  }
@@ -5377,7 +5513,8 @@ async function fetchSetPropertyValues(params, options) {
5377
5513
  bibliographies: null,
5378
5514
  periods: null
5379
5515
  },
5380
- error: null
5516
+ error: null,
5517
+ detailedError: null
5381
5518
  };
5382
5519
  const xquery = buildXQuery({
5383
5520
  setScopeUuids,
@@ -5398,7 +5535,7 @@ async function fetchSetPropertyValues(params, options) {
5398
5535
  const { success, issues, output } = v.safeParse(responseSchema, data);
5399
5536
  if (!success) {
5400
5537
  logIssues(issues);
5401
- throw new Error("Failed to parse OCHRE Set property values", { cause: issues });
5538
+ throw createSchemaValidationError("Failed to parse OCHRE Set property values", issues);
5402
5539
  }
5403
5540
  const parsedPropertyValues = [];
5404
5541
  const parsedAttributeValues = [];
@@ -5449,7 +5586,8 @@ async function fetchSetPropertyValues(params, options) {
5449
5586
  bibliographies: attributes.bibliographies ? sortAttributeValues(attributeValuesByType.bibliographies) : null,
5450
5587
  periods: attributes.periods ? sortAttributeValues(attributeValuesByType.periods) : null
5451
5588
  },
5452
- error: null
5589
+ error: null,
5590
+ detailedError: null
5453
5591
  };
5454
5592
  } catch (error) {
5455
5593
  console.error(error);
@@ -5457,7 +5595,7 @@ async function fetchSetPropertyValues(params, options) {
5457
5595
  propertyValues: null,
5458
5596
  propertyValuesByPropertyVariableUuid: null,
5459
5597
  attributeValues: null,
5460
- error: error instanceof Error ? error.message : "Failed to fetch property values"
5598
+ ...getErrorOutput(error, "Failed to fetch property values")
5461
5599
  };
5462
5600
  }
5463
5601
  }
@@ -7126,18 +7264,19 @@ async function fetchWebsite(abbreviation, options) {
7126
7264
  const { success, issues, output } = v.safeParse(XMLWebsiteData, data);
7127
7265
  if (!success) {
7128
7266
  logIssues(issues);
7129
- throw new Error("Failed to parse website XML", { cause: issues });
7267
+ throw createSchemaValidationError("Failed to parse website XML", issues);
7130
7268
  }
7131
7269
  restoreXMLMetadata(output, data);
7132
7270
  return {
7133
7271
  website: parseWebsite(output, { languages: options?.languages }),
7134
- error: null
7272
+ error: null,
7273
+ detailedError: null
7135
7274
  };
7136
7275
  } catch (error) {
7137
7276
  console.error(error);
7138
7277
  return {
7139
7278
  website: null,
7140
- error: error instanceof Error ? error.message : "Unknown error"
7279
+ ...getErrorOutput(error, "Unknown error")
7141
7280
  };
7142
7281
  }
7143
7282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.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",