ochre-sdk 1.0.0-beta.1 → 1.0.0-beta.3
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 +2 -0
- package/dist/index.mjs +26 -25
- package/package.json +4 -4
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
@@ -3213,7 +3218,10 @@ const XMLItemLinks = v.object({
|
|
|
3213
3218
|
text: v.optional(v.array(XMLText, "XMLItemLinks: text is array of XMLText")),
|
|
3214
3219
|
set: v.optional(v.array(XMLSet, "XMLItemLinks: set is array of XMLSet"))
|
|
3215
3220
|
}, "XMLItemLinks: Shape error");
|
|
3216
|
-
const XMLItemLinksData = v.object({ result: v.object({ ochre: v.object({
|
|
3221
|
+
const XMLItemLinksData = v.object({ result: v.object({ ochre: v.object({
|
|
3222
|
+
payload: v.optional(v.string("XMLItemLinksData: payload is string and optional")),
|
|
3223
|
+
items: v.optional(XMLItemLinks)
|
|
3224
|
+
}, "XMLItemLinksData: ochre") }) }, "XMLItemLinksData: Shape error");
|
|
3217
3225
|
const XMLGallery = v.object({
|
|
3218
3226
|
payload: v.optional(v.string("XMLGallery: payload is string and optional")),
|
|
3219
3227
|
project: v.object({
|
|
@@ -5572,15 +5580,7 @@ function parseStringContent(value, options = FALLBACK_WEBSITE_OPTIONS) {
|
|
|
5572
5580
|
parseEmail: true
|
|
5573
5581
|
});
|
|
5574
5582
|
}
|
|
5575
|
-
function
|
|
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) {
|
|
5583
|
+
function transformPermanentIdentificationUrlToItemLink(url) {
|
|
5584
5584
|
return url.replace("https://pi.lib.uchicago.edu/1001/org/ochre/", "/item/");
|
|
5585
5585
|
}
|
|
5586
5586
|
function parseLicense(availability) {
|
|
@@ -5609,7 +5609,7 @@ const TRAILING_SLASH_REGEX = /\/$/;
|
|
|
5609
5609
|
function formatXMLWebsiteResourceMetadata(resource) {
|
|
5610
5610
|
const metadata = [`label “${parseStringContent(resource.identification.label)}”`, `uuid “${resource.uuid}”`];
|
|
5611
5611
|
if (resource.slug != null) metadata.push(`slug “${resource.slug}”`);
|
|
5612
|
-
if (resource.identification.abbreviation != null) metadata.push(`abbreviation “${
|
|
5612
|
+
if (resource.identification.abbreviation != null) metadata.push(`abbreviation “${parseStringContent(resource.identification.abbreviation)}”`);
|
|
5613
5613
|
return metadata.join(", ");
|
|
5614
5614
|
}
|
|
5615
5615
|
function formatComponentError(message, componentName, elementResource) {
|
|
@@ -5695,9 +5695,10 @@ function parseStylesheets(styles) {
|
|
|
5695
5695
|
const defaultStyles = [];
|
|
5696
5696
|
for (const [label, value] of Object.entries(style)) {
|
|
5697
5697
|
if (label === "variableUuid" || label === "valueUuid" || label === "category" || label === "payload" || label === "content") continue;
|
|
5698
|
-
|
|
5698
|
+
const valueString = value?.toString();
|
|
5699
|
+
if (valueString != null) defaultStyles.push({
|
|
5699
5700
|
label,
|
|
5700
|
-
value:
|
|
5701
|
+
value: valueString
|
|
5701
5702
|
});
|
|
5702
5703
|
}
|
|
5703
5704
|
const stylesByViewport = {
|
|
@@ -5756,7 +5757,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
5756
5757
|
case "advanced-search": {
|
|
5757
5758
|
const boundElementPropertyUuid = getPropertyByLabelName(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
|
|
5758
5759
|
const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
|
|
5759
|
-
const href = linkToProperty?.values[0]?.href != null ?
|
|
5760
|
+
const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
|
|
5760
5761
|
if (boundElementPropertyUuid == null && href == null) throw new Error(formatComponentError("Bound element or href not found", componentName, elementResource));
|
|
5761
5762
|
properties = {
|
|
5762
5763
|
component: "advanced-search",
|
|
@@ -5835,10 +5836,10 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
5835
5836
|
variant ??= "default";
|
|
5836
5837
|
let isExternal = false;
|
|
5837
5838
|
const navigateToProperty = getPropertyByLabelName(componentProperty.properties, "navigate-to");
|
|
5838
|
-
let href = navigateToProperty?.values[0]?.href != null ?
|
|
5839
|
+
let href = navigateToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(navigateToProperty.values[0].href) : navigateToProperty?.values[0]?.slug ?? null;
|
|
5839
5840
|
if (href === null) {
|
|
5840
5841
|
const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
|
|
5841
|
-
href = linkToProperty?.values[0]?.href != null ?
|
|
5842
|
+
href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
|
|
5842
5843
|
if (href === null) throw new Error(formatComponentError("Properties “navigate-to” or “link-to” not found", componentName, elementResource));
|
|
5843
5844
|
else isExternal = true;
|
|
5844
5845
|
}
|
|
@@ -5969,7 +5970,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
5969
5970
|
const width = getPropertyValueContentByLabelName(componentProperty.properties, "width");
|
|
5970
5971
|
properties = {
|
|
5971
5972
|
component: "iframe",
|
|
5972
|
-
href:
|
|
5973
|
+
href: transformPermanentIdentificationUrlToItemLink(webpageLink.href),
|
|
5973
5974
|
height: height?.toString() ?? null,
|
|
5974
5975
|
width: width?.toString() ?? null
|
|
5975
5976
|
};
|
|
@@ -6215,7 +6216,7 @@ function parseWebElementProperties(componentProperty, elementResource, options)
|
|
|
6215
6216
|
queryVariant ??= "submit";
|
|
6216
6217
|
const boundElementUuid = getPropertyByLabelName(componentProperty.properties, "bound-element")?.values[0]?.uuid ?? null;
|
|
6217
6218
|
const linkToProperty = getPropertyByLabelName(componentProperty.properties, "link-to");
|
|
6218
|
-
const href = linkToProperty?.values[0]?.href != null ?
|
|
6219
|
+
const href = linkToProperty?.values[0]?.href != null ? transformPermanentIdentificationUrlToItemLink(linkToProperty.values[0].href) : linkToProperty?.values[0]?.slug ?? null;
|
|
6219
6220
|
if (!boundElementUuid && !href) throw new Error(formatComponentError("Bound element or href not found", componentName, elementResource));
|
|
6220
6221
|
let placeholder = getPropertyValueContentByLabelName(componentProperty.properties, "placeholder-text");
|
|
6221
6222
|
placeholder ??= null;
|
|
@@ -6472,7 +6473,7 @@ function parseWebSegment(segmentResource, options, slugPrefix) {
|
|
|
6472
6473
|
const webpageProperties = segmentResource.properties ? parseProperties(segmentResource.properties, options) : [];
|
|
6473
6474
|
if (webpageProperties.length === 0 || getPropertyValueContentByLabelName(webpageProperties, "presentation") !== "segment") return null;
|
|
6474
6475
|
const identification = parseIdentification(segmentResource.identification, options);
|
|
6475
|
-
const slug = segmentResource.identification.abbreviation != null ?
|
|
6476
|
+
const slug = segmentResource.identification.abbreviation != null ? parseStringContent(segmentResource.identification.abbreviation, options) : null;
|
|
6476
6477
|
if (slug == null) throw new Error(`Slug not found for segment (${formatXMLWebsiteResourceMetadata(segmentResource)})`);
|
|
6477
6478
|
const returnSegment = {
|
|
6478
6479
|
uuid: segmentResource.uuid,
|
|
@@ -6509,7 +6510,7 @@ function parseWebSegmentItem(segmentItemResource, options, slugPrefix) {
|
|
|
6509
6510
|
const webpageProperties = segmentItemResource.properties ? parseProperties(segmentItemResource.properties, options) : [];
|
|
6510
6511
|
if (webpageProperties.length === 0 || getPropertyValueContentByLabelName(webpageProperties, "presentation") !== "segment-item") return null;
|
|
6511
6512
|
const identification = parseIdentification(segmentItemResource.identification, options);
|
|
6512
|
-
const slug = segmentItemResource.identification.abbreviation != null ?
|
|
6513
|
+
const slug = segmentItemResource.identification.abbreviation != null ? parseStringContent(segmentItemResource.identification.abbreviation, options) : null;
|
|
6513
6514
|
if (slug == null) throw new Error(`Slug not found for segment item (${formatXMLWebsiteResourceMetadata(segmentItemResource)})`);
|
|
6514
6515
|
const returnSegmentItem = {
|
|
6515
6516
|
uuid: segmentItemResource.uuid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ochre-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
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.
|
|
54
|
-
"bumpp": "^11.0
|
|
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.
|
|
57
|
+
"tsdown": "^0.22.0",
|
|
58
58
|
"typescript": "^6.0.3",
|
|
59
59
|
"vitest": "^4.1.5"
|
|
60
60
|
},
|