ochre-sdk 1.0.0-beta.1 → 1.0.0-beta.2

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
@@ -228,9 +228,11 @@ type ItemLocation = "topLevel" | "nested";
228
228
  type ItemOrigin<T extends ReadonlyArray<string>, U extends ItemLocation> = U extends "topLevel" ? {
229
229
  belongsTo: BelongsTo;
230
230
  metadata: Metadata<T>;
231
+ persistentUrl: string | null;
231
232
  } : {
232
233
  belongsTo: null;
233
234
  metadata: null;
235
+ persistentUrl: null;
234
236
  };
235
237
  /**
236
238
  * License in OCHRE
package/dist/index.mjs CHANGED
@@ -725,7 +725,7 @@ function getLinkStringProperty(link, property) {
725
725
  case "width": return "width" in link && typeof link.width === "string" ? link.width : null;
726
726
  }
727
727
  }
728
- function transformPermanentIdentificationUrl$1(url) {
728
+ function transformPermanentIdentificationUrl(url) {
729
729
  return url.replace("https://pi.lib.uchicago.edu/1001/org/ochre/", "https://ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=");
730
730
  }
731
731
  /**
@@ -740,7 +740,7 @@ function parseEmail(string) {
740
740
  const splitString = string.split(" ");
741
741
  const returnSplitString = [];
742
742
  for (const string of splitString) {
743
- const cleanString = transformPermanentIdentificationUrl$1(string).replaceAll(EMAIL_BRACKET_CLEANUP_REGEX, "").replaceAll(EMAIL_PUNCTUATION_CLEANUP_REGEX, "").replace(EMAIL_TRAILING_PERIOD_REGEX, "");
743
+ const cleanString = transformPermanentIdentificationUrl(string).replaceAll(EMAIL_BRACKET_CLEANUP_REGEX, "").replaceAll(EMAIL_PUNCTUATION_CLEANUP_REGEX, "").replace(EMAIL_TRAILING_PERIOD_REGEX, "");
744
744
  const index = string.indexOf(cleanString);
745
745
  const { success } = v.safeParse(emailSchema, cleanString);
746
746
  if (success) {
@@ -852,7 +852,7 @@ function createMDXComponent(variant, properties) {
852
852
  returnString = `<InternalLink uuid="${uuid}"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</InternalLink>`;
853
853
  break;
854
854
  case "externalLink":
855
- returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl$1(href)}"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</ExternalLink>`;
855
+ returnString = `<ExternalLink href="${href == null ? "#" : transformPermanentIdentificationUrl(href)}"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</ExternalLink>`;
856
856
  break;
857
857
  case "documentLink":
858
858
  returnString = String.raw`<ExternalLink href="https:\/\/ochre.lib.uchicago.edu/ochre/v2/ochre.php?uuid=${uuid}&load"${content != null && content !== "" ? ` content="${content}"` : ""}>${text}</ExternalLink>`;
@@ -1426,6 +1426,7 @@ function parseBaseItem(category, rawItem, options) {
1426
1426
  category,
1427
1427
  belongsTo: null,
1428
1428
  metadata: null,
1429
+ persistentUrl: null,
1429
1430
  publicationDateTime: parseOptionalDate(rawItem.publicationDateTime),
1430
1431
  context: rawItem.context == null ? null : parseContext(rawItem.context),
1431
1432
  date: parseOptionalDateLike(rawItem.date),
@@ -1502,7 +1503,7 @@ function parseImage(rawImage, options) {
1502
1503
  return {
1503
1504
  publicationDateTime: parseOptionalDate(rawImage.publicationDateTime),
1504
1505
  identification: rawImage.identification == null ? null : parseIdentification(rawImage.identification, options),
1505
- href: rawImage.href ?? null,
1506
+ href: parseHref(rawImage.href),
1506
1507
  htmlImgSrcPrefix: rawImage.htmlImgSrcPrefix ?? null,
1507
1508
  height: parseNumber(rawImage.height),
1508
1509
  width: parseNumber(rawImage.width),
@@ -1510,6 +1511,9 @@ function parseImage(rawImage, options) {
1510
1511
  base64: rawImage.payload ?? null
1511
1512
  };
1512
1513
  }
1514
+ function parseHref(href) {
1515
+ return href == null ? null : transformPermanentIdentificationUrl(href);
1516
+ }
1513
1517
  function parseCoordinatesSource(source, options) {
1514
1518
  if (source == null) return null;
1515
1519
  switch (source.context) {
@@ -2439,7 +2443,8 @@ function parseItem(rawData, options) {
2439
2443
  uuid: rawOchre.uuidBelongsTo,
2440
2444
  abbreviation: rawOchre.belongsTo
2441
2445
  },
2442
- metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage)
2446
+ metadata: parseMetadata(rawOchre, parserOptions, defaultLanguage),
2447
+ persistentUrl: rawOchre.persistentUrl ?? null
2443
2448
  };
2444
2449
  }
2445
2450
  //#endregion
@@ -5572,15 +5577,7 @@ function parseStringContent(value, options = FALLBACK_WEBSITE_OPTIONS) {
5572
5577
  parseEmail: true
5573
5578
  });
5574
5579
  }
5575
- function parseFakeString(value) {
5576
- if (typeof value === "string") return value;
5577
- if (typeof value === "number" || typeof value === "boolean") return value.toString();
5578
- return "";
5579
- }
5580
- function parseFakeStringOrContent(value, options = FALLBACK_WEBSITE_OPTIONS) {
5581
- return parseStringContent(value, options);
5582
- }
5583
- function transformPermanentIdentificationUrl(url) {
5580
+ function transformPermanentIdentificationUrlToItemLink(url) {
5584
5581
  return url.replace("https://pi.lib.uchicago.edu/1001/org/ochre/", "/item/");
5585
5582
  }
5586
5583
  function parseLicense(availability) {
@@ -5609,7 +5606,7 @@ const TRAILING_SLASH_REGEX = /\/$/;
5609
5606
  function formatXMLWebsiteResourceMetadata(resource) {
5610
5607
  const metadata = [`label “${parseStringContent(resource.identification.label)}”`, `uuid “${resource.uuid}”`];
5611
5608
  if (resource.slug != null) metadata.push(`slug “${resource.slug}”`);
5612
- if (resource.identification.abbreviation != null) metadata.push(`abbreviation “${parseFakeStringOrContent(resource.identification.abbreviation)}”`);
5609
+ if (resource.identification.abbreviation != null) metadata.push(`abbreviation “${parseStringContent(resource.identification.abbreviation)}”`);
5613
5610
  return metadata.join(", ");
5614
5611
  }
5615
5612
  function formatComponentError(message, componentName, elementResource) {
@@ -5695,9 +5692,10 @@ function parseStylesheets(styles) {
5695
5692
  const defaultStyles = [];
5696
5693
  for (const [label, value] of Object.entries(style)) {
5697
5694
  if (label === "variableUuid" || label === "valueUuid" || label === "category" || label === "payload" || label === "content") continue;
5698
- defaultStyles.push({
5695
+ const valueString = value?.toString();
5696
+ if (valueString != null) defaultStyles.push({
5699
5697
  label,
5700
- value: parseFakeString(value)
5698
+ value: valueString
5701
5699
  });
5702
5700
  }
5703
5701
  const stylesByViewport = {
@@ -5756,7 +5754,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
5756
5754
  case "advanced-search": {
5757
5755
  const boundElementPropertyUuid = getPropertyByLabelName(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
5758
5756
  const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
5759
- const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
5757
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
5760
5758
  if (boundElementPropertyUuid == null && href == null) throw new Error(formatComponentError("Bound element or href not found", componentName, elementResource));
5761
5759
  properties = {
5762
5760
  component: "advanced-search",
@@ -5835,10 +5833,10 @@ function parseWebElementProperties(componentProperty, elementResource, options)
5835
5833
  variant ??= "default";
5836
5834
  let isExternal = false;
5837
5835
  const navigateToProperty = getPropertyByLabelName(componentProperty.properties, "navigate-to");
5838
- let href = navigateToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(navigateToProperty.values[0].href) : navigateToProperty?.values[0]?.slug ?? null;
5836
+ let href = navigateToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(navigateToProperty.values[0].href) : navigateToProperty?.values[0]?.slug ?? null;
5839
5837
  if (href === null) {
5840
5838
  const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
5841
- href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
5839
+ href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
5842
5840
  if (href === null) throw new Error(formatComponentError("Properties “navigate-to” or “link-to” not found", componentName, elementResource));
5843
5841
  else isExternal = true;
5844
5842
  }
@@ -5969,7 +5967,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
5969
5967
  const width = getPropertyValueContentByLabelName(componentProperty.properties, "width");
5970
5968
  properties = {
5971
5969
  component: "iframe",
5972
- href: transformPermanentIdentificationUrl(webpageLink.href),
5970
+ href: transformPermanentIdentificationUrlToItemLink(webpageLink.href),
5973
5971
  height: height?.toString() ?? null,
5974
5972
  width: width?.toString() ?? null
5975
5973
  };
@@ -6215,7 +6213,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
6215
6213
  queryVariant ??= "submit";
6216
6214
  const boundElementUuid = getPropertyByLabelName(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
6217
6215
  const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
6218
- const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrl(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
6216
+ const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
6219
6217
  if (!boundElementUuid && !href) throw new Error(formatComponentError("Bound element or href not found", componentName, elementResource));
6220
6218
  let placeholder = getPropertyValueContentByLabelName(componentProperty.properties, "placeholder-text");
6221
6219
  placeholder ??= null;
@@ -6472,7 +6470,7 @@ function parseWebSegment(segmentResource, options, slugPrefix) {
6472
6470
  const webpageProperties = segmentResource.properties ? parseProperties(segmentResource.properties, options) : [];
6473
6471
  if (webpageProperties.length === 0 || getPropertyValueContentByLabelName(webpageProperties, "presentation") !== "segment") return null;
6474
6472
  const identification = parseIdentification(segmentResource.identification, options);
6475
- const slug = segmentResource.identification.abbreviation != null ? parseFakeStringOrContent(segmentResource.identification.abbreviation, options) : null;
6473
+ const slug = segmentResource.identification.abbreviation != null ? parseStringContent(segmentResource.identification.abbreviation, options) : null;
6476
6474
  if (slug == null) throw new Error(`Slug not found for segment (${formatXMLWebsiteResourceMetadata(segmentResource)})`);
6477
6475
  const returnSegment = {
6478
6476
  uuid: segmentResource.uuid,
@@ -6509,7 +6507,7 @@ function parseWebSegmentItem(segmentItemResource, options, slugPrefix) {
6509
6507
  const webpageProperties = segmentItemResource.properties ? parseProperties(segmentItemResource.properties, options) : [];
6510
6508
  if (webpageProperties.length === 0 || getPropertyValueContentByLabelName(webpageProperties, "presentation") !== "segment-item") return null;
6511
6509
  const identification = parseIdentification(segmentItemResource.identification, options);
6512
- const slug = segmentItemResource.identification.abbreviation != null ? parseFakeStringOrContent(segmentItemResource.identification.abbreviation, options) : null;
6510
+ const slug = segmentItemResource.identification.abbreviation != null ? parseStringContent(segmentItemResource.identification.abbreviation, options) : null;
6513
6511
  if (slug == null) throw new Error(`Slug not found for segment item (${formatXMLWebsiteResourceMetadata(segmentItemResource)})`);
6514
6512
  const returnSegmentItem = {
6515
6513
  uuid: segmentItemResource.uuid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ochre-sdk",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
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",
@@ -50,11 +50,11 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@antfu/eslint-config": "^8.2.0",
53
- "@types/node": "^24.12.2",
54
- "bumpp": "^11.0.1",
53
+ "@types/node": "^24.12.3",
54
+ "bumpp": "^11.1.0",
55
55
  "eslint": "^10.3.0",
56
56
  "prettier": "^3.8.3",
57
- "tsdown": "^0.21.10",
57
+ "tsdown": "^0.22.0",
58
58
  "typescript": "^6.0.3",
59
59
  "vitest": "^4.1.5"
60
60
  },